aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/protobuf
diff options
context:
space:
mode:
authorGravatar Jakob Buchgraber <buchgr@google.com>2017-04-12 14:30:38 +0200
committerGravatar Jakob Buchgraber <buchgr@google.com>2017-04-14 14:06:29 +0200
commit5235d06159ba6fee412bee261ea7867d061252b0 (patch)
treed502ed5c8d15f750c8ca1eccc2cb929862dd0947 /third_party/protobuf
parent5bf9e0f225b4c1636e24782ef9043e6201a65188 (diff)
protobuf: Update protobuf to @laszlocsomor's master at commit 421d909.
Update protobuf to @laszlocsomor's fork of protobuf. This is essentially the development version of protobuf 3.2.0 and windows specific fixes from laszlo. Those fixes will be merged into protobuf soon: https://github.com/google/protobuf/pull/2969). For instructions on how to update protobuf for bazel see README.bazel.md. Change-Id: Ic1daafe30270cb6bcc6231e6c94fb670af0475e7
Diffstat (limited to 'third_party/protobuf')
-rw-r--r--third_party/protobuf/3.0.0/BUILD328
-rw-r--r--third_party/protobuf/3.0.0/protobuf-java-3.0.0.jarbin1304430 -> 0 bytes
-rw-r--r--third_party/protobuf/3.0.0/protobuf-java-util-3.0.0.jarbin64530 -> 0 bytes
-rw-r--r--third_party/protobuf/3.0.0/src/google/protobuf/compiler/zip_writer.h93
-rw-r--r--third_party/protobuf/3.0.0/src/google/protobuf/io/io_win32.cc159
-rw-r--r--third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_macosx.h225
-rw-r--r--third_party/protobuf/BUILD831
-rw-r--r--third_party/protobuf/CHANGES.txt1486
-rw-r--r--third_party/protobuf/CONTRIBUTORS.txt102
-rw-r--r--third_party/protobuf/LICENSE13
-rw-r--r--third_party/protobuf/Makefile.am949
-rw-r--r--third_party/protobuf/Protobuf.podspec41
-rw-r--r--third_party/protobuf/README.bazel.md31
-rw-r--r--third_party/protobuf/README.md105
-rw-r--r--third_party/protobuf/WORKSPACE53
-rw-r--r--third_party/protobuf/appveyor.bat32
-rw-r--r--third_party/protobuf/appveyor.yml45
-rwxr-xr-xthird_party/protobuf/autogen.sh51
-rw-r--r--third_party/protobuf/benchmarks/Makefile.am78
-rw-r--r--third_party/protobuf/benchmarks/ProtoBench.java203
-rw-r--r--third_party/protobuf/benchmarks/README.md28
-rw-r--r--third_party/protobuf/benchmarks/benchmark_messages_proto2.proto143
-rw-r--r--third_party/protobuf/benchmarks/benchmark_messages_proto3.proto78
-rw-r--r--third_party/protobuf/benchmarks/benchmarks.proto63
-rw-r--r--third_party/protobuf/benchmarks/cpp_benchmark.cc242
-rw-r--r--third_party/protobuf/benchmarks/generate_datasets.cc117
-rw-r--r--third_party/protobuf/benchmarks/google_message1.datbin0 -> 228 bytes
-rw-r--r--third_party/protobuf/benchmarks/google_message2.datbin0 -> 84570 bytes
-rw-r--r--third_party/protobuf/benchmarks/google_size.proto138
-rw-r--r--third_party/protobuf/benchmarks/readme.txt46
-rw-r--r--third_party/protobuf/cmake/CMakeLists.txt183
-rw-r--r--third_party/protobuf/cmake/README.md336
-rw-r--r--third_party/protobuf/cmake/examples.cmake57
-rw-r--r--third_party/protobuf/cmake/extract_includes.bat.in127
-rw-r--r--third_party/protobuf/cmake/install.cmake117
-rw-r--r--third_party/protobuf/cmake/libprotobuf-lite.cmake38
-rw-r--r--third_party/protobuf/cmake/libprotobuf.cmake72
-rw-r--r--third_party/protobuf/cmake/libprotoc.cmake120
-rw-r--r--third_party/protobuf/cmake/protobuf-config-version.cmake.in58
-rw-r--r--third_party/protobuf/cmake/protobuf-config.cmake.in13
-rw-r--r--third_party/protobuf/cmake/protobuf-module.cmake.in233
-rw-r--r--third_party/protobuf/cmake/protobuf-options.cmake7
-rw-r--r--third_party/protobuf/cmake/protoc.cmake6
-rw-r--r--third_party/protobuf/cmake/tests.cmake221
-rw-r--r--third_party/protobuf/com_google_protobuf_java.BUILD (renamed from third_party/protobuf/3.0.0/com_google_protobuf_java.BUILD)2
-rw-r--r--third_party/protobuf/composer.json23
-rw-r--r--third_party/protobuf/configure.ac211
-rw-r--r--third_party/protobuf/conformance/ConformanceJava.java315
-rw-r--r--third_party/protobuf/conformance/ConformanceJavaLite.java125
-rw-r--r--third_party/protobuf/conformance/Makefile.am355
-rw-r--r--third_party/protobuf/conformance/README.md73
-rw-r--r--third_party/protobuf/conformance/conformance.proto114
-rw-r--r--third_party/protobuf/conformance/conformance_cpp.cc208
-rwxr-xr-xthird_party/protobuf/conformance/conformance_nodejs.js168
-rw-r--r--third_party/protobuf/conformance/conformance_objc.m180
-rwxr-xr-xthird_party/protobuf/conformance/conformance_php.php112
-rwxr-xr-xthird_party/protobuf/conformance/conformance_python.py135
-rwxr-xr-xthird_party/protobuf/conformance/conformance_ruby.rb124
-rw-r--r--third_party/protobuf/conformance/conformance_test.cc2406
-rw-r--r--third_party/protobuf/conformance/conformance_test.h242
-rw-r--r--third_party/protobuf/conformance/conformance_test_runner.cc326
-rw-r--r--third_party/protobuf/conformance/failure_list_cpp.txt46
-rw-r--r--[-rwxr-xr-x]third_party/protobuf/conformance/failure_list_csharp.txt (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/__init__.py)0
-rw-r--r--third_party/protobuf/conformance/failure_list_java.txt45
-rw-r--r--third_party/protobuf/conformance/failure_list_js.txt15
-rw-r--r--third_party/protobuf/conformance/failure_list_objc.txt4
-rw-r--r--third_party/protobuf/conformance/failure_list_php.txt611
-rw-r--r--third_party/protobuf/conformance/failure_list_php_c.txt235
-rw-r--r--third_party/protobuf/conformance/failure_list_python-post26.txt2
-rw-r--r--third_party/protobuf/conformance/failure_list_python.txt13
-rw-r--r--third_party/protobuf/conformance/failure_list_python_cpp.txt38
-rw-r--r--third_party/protobuf/conformance/failure_list_ruby.txt203
-rw-r--r--third_party/protobuf/conformance/third_party/jsoncpp/json.h2075
-rw-r--r--third_party/protobuf/conformance/third_party/jsoncpp/jsoncpp.cpp5192
-rwxr-xr-xthird_party/protobuf/conformance/update_failure_list.py73
-rw-r--r--third_party/protobuf/csharp/.gitignore31
-rw-r--r--third_party/protobuf/csharp/CHANGES.txt148
-rw-r--r--third_party/protobuf/csharp/Google.Protobuf.Tools.nuspec37
-rw-r--r--third_party/protobuf/csharp/README.md117
-rw-r--r--third_party/protobuf/csharp/build_packages.bat10
-rwxr-xr-xthird_party/protobuf/csharp/build_tools.sh52
-rwxr-xr-xthird_party/protobuf/csharp/buildall.sh16
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/csharp/protos/unittest_issues.proto126
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/map_unittest_proto3.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_unittest_proto3.proto)0
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/unittest_import_proto3.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_import_proto3.proto)0
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/unittest_import_public_proto3.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_import_public_proto3.proto)0
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/unittest_proto3.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_proto3.proto)0
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/unittest_well_known_types.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_well_known_types.proto)0
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/ByteStringTest.cs171
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedInputStreamExtensions.cs53
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedInputStreamTest.cs598
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedOutputStreamTest.cs419
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Collections/MapFieldTest.cs532
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs746
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Compatibility/PropertyInfoExtensionsTest.cs98
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs117
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/DeprecatedMemberTest.cs55
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/EqualityTester.cs64
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/FieldCodecTest.cs196
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/GeneratedMessageTest.cs723
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.xproj19
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/IssuesTest.cs82
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/JsonParserTest.cs939
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/JsonTokenizerTest.cs408
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs259
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs218
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Reflection/TypeRegistryTest.cs94
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/SampleEnum.cs42
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/SampleMessages.cs99
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/TestCornerCases.cs62
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/TestProtos/ForeignMessagePartial.cs45
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs116
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs132
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/FieldMaskTest.cs62
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/TimestampTest.cs115
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs421
-rw-r--r--third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/project.json44
-rwxr-xr-xthird_party/protobuf/csharp/compatibility_tests/v3.0.0/test.sh102
-rwxr-xr-xthird_party/protobuf/csharp/generate_protos.sh68
-rw-r--r--third_party/protobuf/csharp/keys/Google.Protobuf.public.snkbin0 -> 160 bytes
-rw-r--r--third_party/protobuf/csharp/keys/Google.Protobuf.snkbin0 -> 596 bytes
-rw-r--r--third_party/protobuf/csharp/keys/README.md9
-rw-r--r--third_party/protobuf/csharp/protos/unittest_custom_options_proto3.proto336
-rw-r--r--third_party/protobuf/csharp/protos/unittest_issues.proto126
-rw-r--r--third_party/protobuf/csharp/src/AddressBook/AddPerson.cs132
-rw-r--r--third_party/protobuf/csharp/src/AddressBook/AddressBook.xproj19
-rw-r--r--third_party/protobuf/csharp/src/AddressBook/Addressbook.cs518
-rw-r--r--third_party/protobuf/csharp/src/AddressBook/ListPeople.cs99
-rw-r--r--third_party/protobuf/csharp/src/AddressBook/Program.cs95
-rw-r--r--third_party/protobuf/csharp/src/AddressBook/SampleUsage.cs73
-rw-r--r--third_party/protobuf/csharp/src/AddressBook/project.json20
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Conformance/Conformance.cs606
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.xproj19
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Conformance/Program.cs142
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Conformance/project.json21
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.xproj19
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/Program.cs73
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/project.json19
-rwxr-xr-xthird_party/protobuf/csharp/src/Google.Protobuf.Test/ByteStringTest.cs237
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/CodedInputStreamExtensions.cs53
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs598
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs419
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs548
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs746
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/PropertyInfoExtensionsTest.cs98
-rwxr-xr-xthird_party/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/StreamExtensionsTest.cs67
-rwxr-xr-xthird_party/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs117
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/DeprecatedMemberTest.cs55
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/EqualityTester.cs64
-rwxr-xr-xthird_party/protobuf/csharp/src/Google.Protobuf.Test/FieldCodecTest.cs199
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs723
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.xproj21
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/IssuesTest.cs82
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs624
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/JsonParserTest.cs939
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs408
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs271
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs259
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs218
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/Reflection/TypeRegistryTest.cs94
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/SampleEnum.cs42
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/SampleMessages.cs99
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/TestCornerCases.cs62
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/ForeignMessagePartial.cs45
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs1599
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs3688
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs2625
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs174
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs160
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs1736
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs6766
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs2539
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs116
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs132
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/FieldMaskTest.cs62
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/TimestampTest.cs115
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs421
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.Test/project.json45
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf.sln45
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/ByteArray.cs79
-rwxr-xr-xthird_party/protobuf/csharp/src/Google.Protobuf/ByteString.cs401
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/CodedInputStream.cs1275
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/CodedOutputStream.ComputeSize.cs304
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/CodedOutputStream.cs761
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Collections/MapField.cs760
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Collections/ReadOnlyDictionary.cs147
-rwxr-xr-xthird_party/protobuf/csharp/src/Google.Protobuf/Collections/RepeatedField.cs594
-rwxr-xr-xthird_party/protobuf/csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs72
-rwxr-xr-xthird_party/protobuf/csharp/src/Google.Protobuf/Compatibility/StreamExtensions.cs66
-rwxr-xr-xthird_party/protobuf/csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs106
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/FieldCodec.cs474
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/FrameworkPortability.cs49
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Google.Protobuf.xproj19
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/ICustomDiagnosticMessage.cs69
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/IDeepCloneable.cs54
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/IMessage.cs87
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/InvalidJsonException.cs53
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs129
-rwxr-xr-xthird_party/protobuf/csharp/src/Google.Protobuf/JsonFormatter.cs902
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/JsonParser.cs1019
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/JsonToken.cs166
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/JsonTokenizer.cs738
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/LimitedInputStream.cs110
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/MessageExtensions.cs157
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/MessageParser.cs267
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs49
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/ProtoPreconditions.cs79
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/CustomOptions.cs390
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/Descriptor.cs6121
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorBase.cs85
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs368
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorUtil.cs64
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorValidationException.cs80
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs121
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs75
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/FieldAccessorBase.cs63
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs348
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/FieldType.cs113
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs338
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs103
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/IDescriptor.cs55
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs71
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/MapFieldAccessor.cs59
-rwxr-xr-xthird_party/protobuf/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs326
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs108
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/OneofAccessor.cs90
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs127
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/OriginalNameAttribute.cs65
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/PackageDescriptor.cs68
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/PartialClasses.cs59
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs107
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs60
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs94
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs81
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/Reflection/TypeRegistry.cs183
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs285
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs107
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs902
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs250
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/DurationPartial.cs270
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs144
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs359
-rwxr-xr-xthird_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs128
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs170
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs648
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/TimeExtensions.cs76
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs253
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs241
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs1444
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/ValuePartial.cs99
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs1182
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/WrappersPartial.cs42
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/WireFormat.cs104
-rw-r--r--third_party/protobuf/csharp/src/Google.Protobuf/project.json65
-rw-r--r--third_party/protobuf/csharp/src/global.json5
-rw-r--r--third_party/protobuf/csharp/src/packages/repositories.config4
-rw-r--r--third_party/protobuf/docs/third_party.md156
-rw-r--r--third_party/protobuf/editors/README.txt5
-rw-r--r--third_party/protobuf/editors/proto.vim105
-rw-r--r--third_party/protobuf/editors/protobuf-mode.el221
-rw-r--r--third_party/protobuf/examples/AddPerson.java95
-rw-r--r--third_party/protobuf/examples/CMakeLists.txt63
-rw-r--r--third_party/protobuf/examples/ListPeople.java50
-rw-r--r--third_party/protobuf/examples/Makefile79
-rw-r--r--third_party/protobuf/examples/README.txt54
-rw-r--r--third_party/protobuf/examples/add_person.cc95
-rw-r--r--third_party/protobuf/examples/add_person.go133
-rwxr-xr-xthird_party/protobuf/examples/add_person.py56
-rw-r--r--third_party/protobuf/examples/add_person_test.go58
-rw-r--r--third_party/protobuf/examples/addressbook.proto47
-rw-r--r--third_party/protobuf/examples/list_people.cc68
-rw-r--r--third_party/protobuf/examples/list_people.go61
-rwxr-xr-xthird_party/protobuf/examples/list_people.py37
-rw-r--r--third_party/protobuf/examples/list_people_test.go120
-rwxr-xr-xthird_party/protobuf/generate_changelog.py66
-rwxr-xr-xthird_party/protobuf/generate_descriptor_proto.sh111
-rw-r--r--third_party/protobuf/gmock.BUILD28
-rw-r--r--third_party/protobuf/java/README.md127
-rw-r--r--third_party/protobuf/java/compatibility_tests/README.md50
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/deps/pom.xml43
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/pom.xml69
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/multiple_files_test.proto71
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/nested_builders_test.proto53
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/nested_extension.proto45
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/nested_extension_lite.proto48
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/non_nested_extension.proto48
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/non_nested_extension_lite.proto50
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/test_bad_identifiers.proto108
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/descriptor.proto620
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest.proto719
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_custom_options.proto387
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_embed_optimize_for.proto50
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_empty.proto37
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_enormous_descriptor.proto1046
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_import.proto64
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_import_lite.proto51
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_import_public.proto40
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_import_public_lite.proto42
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_lite.proto360
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_lite_imports_nonlite.proto43
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_mset.proto72
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_no_generic_services.proto52
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_optimize_for.proto61
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/pom.xml30
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/pom.xml71
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/multiple_files_test.proto71
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/nested_builders_test.proto53
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/nested_extension.proto45
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/nested_extension_lite.proto48
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/non_nested_extension.proto48
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/non_nested_extension_lite.proto50
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/test_bad_identifiers.proto108
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/descriptor.proto620
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest.proto719
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_custom_options.proto387
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_embed_optimize_for.proto50
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_empty.proto37
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_enormous_descriptor.proto1046
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import.proto64
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import_lite.proto51
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import_public.proto40
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import_public_lite.proto42
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_lite.proto360
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_lite_imports_nonlite.proto43
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_mset.proto72
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_no_generic_services.proto52
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_optimize_for.proto61
-rwxr-xr-xthird_party/protobuf/java/compatibility_tests/v2.5.0/test.sh140
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/pom.xml73
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/AbstractMessageTest.java510
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/BoundedByteStringTest.java56
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ByteStringTest.java590
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/CodedInputStreamTest.java469
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/CodedOutputStreamTest.java318
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/DeprecatedFieldTest.java81
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/DescriptorsTest.java649
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/DynamicMessageTest.java265
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ForceFieldBuildersPreRun.java49
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/GeneratedMessageTest.java961
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/LazyStringArrayListTest.java163
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/LazyStringEndToEndTest.java108
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/LiteralByteStringTest.java344
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/MessageTest.java354
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/NestedBuildersTest.java186
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ParserTest.java278
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/RopeByteStringSubstringTest.java62
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/RopeByteStringTest.java84
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ServiceTest.java321
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/TestBadIdentifiers.java64
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/TestUtil.java3068
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/TextFormatTest.java536
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/UnknownFieldSetTest.java438
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/UnmodifiableLazyStringListTest.java153
-rw-r--r--third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/WireFormatTest.java465
-rw-r--r--third_party/protobuf/java/core/generate-sources-build.xml20
-rw-r--r--third_party/protobuf/java/core/generate-test-sources-build.xml43
-rw-r--r--third_party/protobuf/java/core/pom.xml144
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractMessage.java649
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java383
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractParser.java258
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractProtobufList.java180
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/BlockingRpcChannel.java51
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/BlockingService.java64
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java272
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteBufferWriter.java185
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteOutput.java116
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java1558
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/CodedInputStream.java2896
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java3001
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java2547
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java273
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/DynamicMessage.java684
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExperimentalApi.java66
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/Extension.java86
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionLite.java63
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionRegistry.java396
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionRegistryFactory.java95
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java227
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/FieldSet.java909
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/FloatArrayList.java272
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java3051
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java2421
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java2842
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/IntArrayList.java272
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/Internal.java751
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java146
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/LazyField.java154
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/LazyFieldLite.java437
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/LazyStringArrayList.java423
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/LazyStringList.java174
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/LongArrayList.java272
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/MapEntry.java451
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/MapEntryLite.java226
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/MapField.java625
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/MapFieldLite.java224
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/Message.java292
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageLite.java341
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java60
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageLiteToString.java239
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageOrBuilder.java143
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageReflection.java990
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/MutabilityOracle.java48
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/NioByteString.java291
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/Parser.java272
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java105
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/ProtocolMessageEnum.java59
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/ProtocolStringList.java48
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java708
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java708
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/RopeByteString.java897
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/RpcCallback.java47
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/RpcChannel.java71
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/RpcController.java118
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/RpcUtil.java136
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/Service.java117
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/ServiceException.java52
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java241
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java241
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/SmallSortedMap.java673
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormat.java2108
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormatEscaper.java137
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormatParseInfoTree.java226
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormatParseLocation.java104
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/UninitializedMessageException.java99
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java1042
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java432
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java210
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java120
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java295
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/Utf8.java1573
-rw-r--r--third_party/protobuf/java/core/src/main/java/com/google/protobuf/WireFormat.java260
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java549
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/AnyTest.java137
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java458
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/BoundedByteStringTest.java100
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/ByteBufferWriterTest.java80
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/ByteStringTest.java772
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/CheckUtf8Test.java141
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java971
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java795
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/DeprecatedFieldTest.java79
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java819
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java461
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java324
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/EnumTest.java76
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/ExtensionRegistryFactoryTest.java276
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java443
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java461
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java48
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java1674
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java461
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/IsValidUtf8Test.java186
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java448
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java246
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyFieldTest.java120
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyMessageLiteTest.java335
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java363
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java130
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java125
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/LiteTest.java2273
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java544
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/LongArrayListTest.java461
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/MapForProto2LiteTest.java796
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java1178
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/MapTest.java1495
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/MessageTest.java351
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/NestedBuildersTest.java183
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java619
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/ParseExceptionsTest.java271
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/ParserTest.java415
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java288
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/RepeatedFieldBuilderV3Test.java188
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java127
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java189
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/ServiceTest.java326
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java155
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/SmallSortedMapTest.java422
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java96
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/TestUtil.java3866
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/TestUtilLite.java559
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/TextFormatParseInfoTreeTest.java182
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/TextFormatParseLocationTest.java86
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/TextFormatTest.java1153
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnknownEnumValueTest.java255
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java334
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java652
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java226
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/WellKnownTypesTest.java65
-rw-r--r--third_party/protobuf/java/core/src/test/java/com/google/protobuf/WireFormatTest.java604
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/any_test.proto (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/any_test.proto)8
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/field_presence_test.proto94
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/lazy_fields_lite.proto71
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/lite_equals_and_hash.proto81
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto121
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/map_for_proto2_test.proto120
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/map_initialization_order_test.proto61
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/map_test.proto110
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/multiple_files_test.proto78
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/nested_builders_test.proto54
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/nested_extension.proto47
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/nested_extension_lite.proto49
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/non_nested_extension.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/arena_nc.cc)25
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/non_nested_extension_lite.proto51
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/outer_class_name_test.proto40
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/outer_class_name_test2.proto44
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/outer_class_name_test3.proto45
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto168
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_check_utf8.proto51
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_check_utf8_size.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/timestamp_duration.proto)27
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_custom_options.proto44
-rw-r--r--third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto61
-rw-r--r--third_party/protobuf/java/lite/generate-sources-build.xml20
-rw-r--r--third_party/protobuf/java/lite/generate-test-sources-build.xml43
-rw-r--r--third_party/protobuf/java/lite/pom.xml184
-rw-r--r--third_party/protobuf/java/pom.xml215
-rw-r--r--third_party/protobuf/java/util/pom.xml127
-rw-r--r--third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/Durations.java302
-rw-r--r--third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskTree.java287
-rw-r--r--third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java342
-rw-r--r--third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java1766
-rw-r--r--third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/TimeUtil.java400
-rw-r--r--third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/Timestamps.java397
-rw-r--r--third_party/protobuf/java/util/src/test/java/com/google/protobuf/util/FieldMaskTreeTest.java261
-rw-r--r--third_party/protobuf/java/util/src/test/java/com/google/protobuf/util/FieldMaskUtilTest.java213
-rw-r--r--third_party/protobuf/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java1454
-rw-r--r--third_party/protobuf/java/util/src/test/java/com/google/protobuf/util/TimeUtilTest.java498
-rw-r--r--third_party/protobuf/java/util/src/test/proto/com/google/protobuf/util/json_test.proto178
-rw-r--r--third_party/protobuf/javanano/README.md401
-rw-r--r--third_party/protobuf/javanano/pom.xml244
-rw-r--r--third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/CodedInputByteBufferNano.java683
-rw-r--r--third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java1214
-rw-r--r--third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java169
-rw-r--r--third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/Extension.java706
-rw-r--r--third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/FieldArray.java291
-rw-r--r--third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/FieldData.java240
-rw-r--r--third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/InternalNano.java547
-rw-r--r--third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/InvalidProtocolBufferNanoException.java93
-rw-r--r--third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/MapFactories.java67
-rw-r--r--third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/MessageNano.java198
-rw-r--r--third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/MessageNanoPrinter.java275
-rw-r--r--third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/UnknownFieldData.java88
-rw-r--r--third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/WireFormatNano.java124
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java4471
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/map_test.proto70
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_accessors_nano.proto118
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_enum_class_multiple_nano.proto48
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_enum_class_nano.proto48
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_enum_validity_nano.proto28
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_nano.proto37
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_packed_nano.proto29
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_repeated_nano.proto34
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_singular_nano.proto34
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_has_nano.proto82
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_import_nano.proto48
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_multiple_nameclash_nano.proto41
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_multiple_nano.proto63
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_nano.proto195
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_recursive_nano.proto49
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_reference_types_nano.proto116
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_repeated_merge_nano.proto47
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_repeated_packables_nano.proto95
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_simple_nano.proto54
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_single_nano.proto38
-rw-r--r--third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_stringutf8_nano.proto43
-rw-r--r--third_party/protobuf/jenkins/README.md6
-rwxr-xr-xthird_party/protobuf/jenkins/build_and_run_docker.sh57
-rw-r--r--third_party/protobuf/jenkins/buildcmds/README.md6
-rwxr-xr-xthird_party/protobuf/jenkins/buildcmds/pull_request.sh16
-rwxr-xr-xthird_party/protobuf/jenkins/buildcmds/pull_request_32.sh16
-rw-r--r--third_party/protobuf/jenkins/docker/Dockerfile207
-rw-r--r--third_party/protobuf/jenkins/docker32/Dockerfile111
-rw-r--r--third_party/protobuf/jenkins/make_test_output.py91
-rwxr-xr-xthird_party/protobuf/jenkins/pull_request_in_docker.sh66
-rw-r--r--third_party/protobuf/js/README.md158
-rw-r--r--third_party/protobuf/js/binary/arith.js413
-rw-r--r--third_party/protobuf/js/binary/arith_test.js355
-rw-r--r--third_party/protobuf/js/binary/constants.js360
-rw-r--r--third_party/protobuf/js/binary/decoder.js1066
-rw-r--r--third_party/protobuf/js/binary/decoder_test.js357
-rw-r--r--third_party/protobuf/js/binary/encoder.js490
-rw-r--r--third_party/protobuf/js/binary/message_test.js60
-rw-r--r--third_party/protobuf/js/binary/proto_test.js663
-rw-r--r--third_party/protobuf/js/binary/reader.js1219
-rw-r--r--third_party/protobuf/js/binary/reader_test.js922
-rw-r--r--third_party/protobuf/js/binary/utils.js989
-rw-r--r--third_party/protobuf/js/binary/utils_test.js668
-rw-r--r--third_party/protobuf/js/binary/writer.js1590
-rw-r--r--third_party/protobuf/js/binary/writer_test.js121
-rw-r--r--third_party/protobuf/js/commonjs/export.js31
-rw-r--r--third_party/protobuf/js/commonjs/export_asserts.js41
-rw-r--r--third_party/protobuf/js/commonjs/export_testdeps.js23
-rw-r--r--third_party/protobuf/js/commonjs/import_test.js52
-rw-r--r--third_party/protobuf/js/commonjs/jasmine.json9
-rw-r--r--third_party/protobuf/js/commonjs/rewrite_tests_for_commonjs.js97
-rw-r--r--third_party/protobuf/js/commonjs/test6/test6.proto40
-rw-r--r--third_party/protobuf/js/commonjs/test7/test7.proto42
-rw-r--r--third_party/protobuf/js/data.proto51
-rw-r--r--third_party/protobuf/js/debug.js141
-rw-r--r--third_party/protobuf/js/debug_test.js105
-rw-r--r--third_party/protobuf/js/gulpfile.js160
-rw-r--r--third_party/protobuf/js/jasmine.json15
-rw-r--r--third_party/protobuf/js/map.js531
-rwxr-xr-xthird_party/protobuf/js/maps_test.js350
-rw-r--r--third_party/protobuf/js/message.js1578
-rw-r--r--third_party/protobuf/js/message_test.js1055
-rw-r--r--third_party/protobuf/js/node_loader.js49
-rw-r--r--third_party/protobuf/js/package.json26
-rw-r--r--third_party/protobuf/js/proto3_test.js367
-rw-r--r--third_party/protobuf/js/proto3_test.proto89
-rw-r--r--third_party/protobuf/js/test.proto273
-rw-r--r--third_party/protobuf/js/test2.proto60
-rw-r--r--third_party/protobuf/js/test3.proto53
-rw-r--r--third_party/protobuf/js/test4.proto42
-rw-r--r--third_party/protobuf/js/test5.proto44
-rw-r--r--third_party/protobuf/js/test8.proto50
-rw-r--r--third_party/protobuf/js/test_bootstrap.js41
-rw-r--r--third_party/protobuf/js/testbinary.proto212
-rw-r--r--third_party/protobuf/js/testempty.proto34
-rw-r--r--third_party/protobuf/m4/ac_system_extensions.m437
-rw-r--r--third_party/protobuf/m4/acx_check_suncc.m470
-rw-r--r--third_party/protobuf/m4/acx_pthread.m4397
-rw-r--r--third_party/protobuf/m4/ax_cxx_compile_stdcxx.m4982
-rw-r--r--third_party/protobuf/m4/ax_prog_cc_for_build.m4125
-rw-r--r--third_party/protobuf/m4/ax_prog_cxx_for_build.m4110
-rw-r--r--third_party/protobuf/m4/stl_hash.m471
-rwxr-xr-xthird_party/protobuf/more_tests/Makefile41
-rw-r--r--third_party/protobuf/objectivec/.gitignore23
-rwxr-xr-xthird_party/protobuf/objectivec/DevTools/check_version_stamps.sh55
-rwxr-xr-xthird_party/protobuf/objectivec/DevTools/compile_testing_protos.sh149
-rwxr-xr-xthird_party/protobuf/objectivec/DevTools/full_mac_build.sh329
-rwxr-xr-xthird_party/protobuf/objectivec/DevTools/pddm.py686
-rwxr-xr-xthird_party/protobuf/objectivec/DevTools/pddm_tests.py515
-rw-r--r--third_party/protobuf/objectivec/GPBArray.h1967
-rw-r--r--third_party/protobuf/objectivec/GPBArray.m2551
-rw-r--r--third_party/protobuf/objectivec/GPBArray_PackagePrivate.h130
-rw-r--r--third_party/protobuf/objectivec/GPBBootstrap.h123
-rw-r--r--third_party/protobuf/objectivec/GPBCodedInputStream.h253
-rw-r--r--third_party/protobuf/objectivec/GPBCodedInputStream.m538
-rw-r--r--third_party/protobuf/objectivec/GPBCodedInputStream_PackagePrivate.h114
-rw-r--r--third_party/protobuf/objectivec/GPBCodedOutputStream.h739
-rw-r--r--third_party/protobuf/objectivec/GPBCodedOutputStream.m1202
-rw-r--r--third_party/protobuf/objectivec/GPBCodedOutputStream_PackagePrivate.h126
-rw-r--r--third_party/protobuf/objectivec/GPBDescriptor.h288
-rw-r--r--third_party/protobuf/objectivec/GPBDescriptor.m1104
-rw-r--r--third_party/protobuf/objectivec/GPBDescriptor_PackagePrivate.h329
-rw-r--r--third_party/protobuf/objectivec/GPBDictionary.h8570
-rw-r--r--third_party/protobuf/objectivec/GPBDictionary.m13627
-rw-r--r--third_party/protobuf/objectivec/GPBDictionary_PackagePrivate.h488
-rw-r--r--third_party/protobuf/objectivec/GPBExtensionInternals.h50
-rw-r--r--third_party/protobuf/objectivec/GPBExtensionInternals.m391
-rw-r--r--third_party/protobuf/objectivec/GPBExtensionRegistry.h87
-rw-r--r--third_party/protobuf/objectivec/GPBExtensionRegistry.m131
-rw-r--r--third_party/protobuf/objectivec/GPBMessage.h461
-rw-r--r--third_party/protobuf/objectivec/GPBMessage.m3243
-rw-r--r--third_party/protobuf/objectivec/GPBMessage_PackagePrivate.h150
-rw-r--r--third_party/protobuf/objectivec/GPBProtocolBuffers.h76
-rw-r--r--third_party/protobuf/objectivec/GPBProtocolBuffers.m66
-rw-r--r--third_party/protobuf/objectivec/GPBProtocolBuffers_RuntimeSupport.h40
-rw-r--r--third_party/protobuf/objectivec/GPBRootObject.h52
-rw-r--r--third_party/protobuf/objectivec/GPBRootObject.m237
-rw-r--r--third_party/protobuf/objectivec/GPBRootObject_PackagePrivate.h46
-rw-r--r--third_party/protobuf/objectivec/GPBRuntimeTypes.h144
-rw-r--r--third_party/protobuf/objectivec/GPBUnknownField.h96
-rw-r--r--third_party/protobuf/objectivec/GPBUnknownField.m334
-rw-r--r--third_party/protobuf/objectivec/GPBUnknownFieldSet.h82
-rw-r--r--third_party/protobuf/objectivec/GPBUnknownFieldSet.m395
-rw-r--r--third_party/protobuf/objectivec/GPBUnknownFieldSet_PackagePrivate.h61
-rw-r--r--third_party/protobuf/objectivec/GPBUnknownField_PackagePrivate.h49
-rw-r--r--third_party/protobuf/objectivec/GPBUtilities.h539
-rw-r--r--third_party/protobuf/objectivec/GPBUtilities.m1923
-rw-r--r--third_party/protobuf/objectivec/GPBUtilities_PackagePrivate.h350
-rw-r--r--third_party/protobuf/objectivec/GPBWellKnownTypes.h245
-rw-r--r--third_party/protobuf/objectivec/GPBWellKnownTypes.m272
-rw-r--r--third_party/protobuf/objectivec/GPBWireFormat.h73
-rw-r--r--third_party/protobuf/objectivec/GPBWireFormat.m85
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj994
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/contents.xcworkspacedata7
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings8
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme335
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme133
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj1167
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata7
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings8
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme345
-rw-r--r--third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme134
-rw-r--r--third_party/protobuf/objectivec/README.md188
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.pbxproj290
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata7
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/OSXCocoaPodsTester.xcscheme91
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.h37
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.m48
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json58
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Base.lproj/MainMenu.xib680
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Info.plist34
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/main.m35
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-framework10
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-static8
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/README.md9
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-framework10
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-static8
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.pbxproj309
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata7
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/iOSCocoaPodsTester.xcscheme91
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.h39
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.m67
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json68
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/LaunchScreen.storyboard27
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/Main.storyboard26
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Info.plist47
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.h37
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.m49
-rw-r--r--third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/main.m39
-rwxr-xr-xthird_party/protobuf/objectivec/Tests/CocoaPods/run_tests.sh150
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBARCUnittestProtos.m63
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBArrayTests.m3611
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBCodedInputStreamTests.m335
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBCodedOuputStreamTests.m426
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBConcurrencyTests.m206
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDescriptorTests.m256
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Bool.m2418
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Int32.m3647
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Int64.m3647
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDictionaryTests+String.m3359
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDictionaryTests+UInt32.m3647
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDictionaryTests+UInt64.m3646
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDictionaryTests.m186
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBDictionaryTests.pddm1047
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBMessageTests+Merge.m700
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBMessageTests+Runtime.m2515
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBMessageTests+Serialization.m1210
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBMessageTests.m2053
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBObjectiveCPlusPlusTest.mm69
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBPerfTests.m307
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBSwiftTests.swift460
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBTestUtilities.h100
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBTestUtilities.m2546
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBUnittestProtos.m75
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBUnittestProtos2.m34
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBUnknownFieldSetTest.m255
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBUtilitiesTests.m400
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBWellKnownTypesTest.m214
-rw-r--r--third_party/protobuf/objectivec/Tests/GPBWireFormatTests.m258
-rw-r--r--third_party/protobuf/objectivec/Tests/UnitTests-Bridging-Header.h6
-rw-r--r--third_party/protobuf/objectivec/Tests/UnitTests-Info.plist20
-rw-r--r--third_party/protobuf/objectivec/Tests/golden_messagebin0 -> 493 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/golden_packed_fields_messagebin0 -> 493 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/AppDelegate.m35
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/Contents.json116
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6.pngbin0 -> 8583 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6_2x.pngbin0 -> 17744 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7.pngbin0 -> 8969 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7_2x.pngbin0 -> 18788 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6.pngbin0 -> 7021 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6_2x.pngbin0 -> 13348 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_2x.pngbin0 -> 11128 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_3x.pngbin0 -> 21792 bytes
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/LaunchImage.launchimage/Contents.json49
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/Info.plist43
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/LaunchScreen.xib33
-rw-r--r--third_party/protobuf/objectivec/Tests/iOSTestHarness/en.lproj/InfoPlist.strings2
-rw-r--r--third_party/protobuf/objectivec/Tests/text_format_map_unittest_data.txt70
-rw-r--r--third_party/protobuf/objectivec/Tests/text_format_unittest_data.txt116
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_cycle.proto56
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_deprecated.proto95
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_deprecated_file.proto76
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_extension_chain_a.proto51
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_extension_chain_b.proto47
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_extension_chain_c.proto45
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_extension_chain_d.proto49
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_extension_chain_e.proto40
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_extension_chain_f.proto44
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_extension_chain_g.proto41
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_objc.proto467
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_objc_startup.proto49
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_runtime_proto2.proto128
-rw-r--r--third_party/protobuf/objectivec/Tests/unittest_runtime_proto3.proto121
-rwxr-xr-xthird_party/protobuf/objectivec/generate_well_known_types.sh76
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Any.pbobjc.h163
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Any.pbobjc.m112
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Api.pbobjc.h299
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Api.pbobjc.m356
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Duration.pbobjc.h128
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Duration.pbobjc.m107
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Empty.pbobjc.h70
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Empty.pbobjc.m83
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/FieldMask.pbobjc.h271
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/FieldMask.pbobjc.m96
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/SourceContext.pbobjc.h73
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/SourceContext.pbobjc.m96
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Struct.pbobjc.h200
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Struct.pbobjc.m293
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Timestamp.pbobjc.h132
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Timestamp.pbobjc.m107
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Type.pbobjc.h440
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Type.pbobjc.m701
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Wrappers.pbobjc.h215
-rw-r--r--third_party/protobuf/objectivec/google/protobuf/Wrappers.pbobjc.m439
-rw-r--r--third_party/protobuf/php/README.md97
-rw-r--r--third_party/protobuf/php/composer.json28
-rw-r--r--third_party/protobuf/php/ext/google/protobuf/array.c516
-rw-r--r--third_party/protobuf/php/ext/google/protobuf/config.m410
-rw-r--r--third_party/protobuf/php/ext/google/protobuf/def.c507
-rw-r--r--third_party/protobuf/php/ext/google/protobuf/encode_decode.c1356
-rw-r--r--third_party/protobuf/php/ext/google/protobuf/map.c487
-rw-r--r--third_party/protobuf/php/ext/google/protobuf/message.c345
-rw-r--r--third_party/protobuf/php/ext/google/protobuf/package.xml91
-rw-r--r--third_party/protobuf/php/ext/google/protobuf/protobuf.c176
-rw-r--r--third_party/protobuf/php/ext/google/protobuf/protobuf.h489
-rw-r--r--third_party/protobuf/php/ext/google/protobuf/storage.c835
-rw-r--r--third_party/protobuf/php/ext/google/protobuf/type_check.c532
-rw-r--r--third_party/protobuf/php/ext/google/protobuf/upb.c13847
-rw-r--r--third_party/protobuf/php/ext/google/protobuf/upb.h8875
-rw-r--r--third_party/protobuf/php/ext/google/protobuf/utf8.c68
-rw-r--r--third_party/protobuf/php/ext/google/protobuf/utf8.h36
-rwxr-xr-xthird_party/protobuf/php/generate_descriptor_protos.sh16
-rw-r--r--third_party/protobuf/php/phpunit.xml14
-rw-r--r--third_party/protobuf/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php261
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/DescriptorPool.php162
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/DescriptorProto.php325
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php82
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php112
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/EnumBuilderContext.php63
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php114
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/EnumOptions.php158
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php114
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/EnumValueOptions.php115
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php424
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/FieldDescriptorProto_Label.php29
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/FieldDescriptorProto_Type.php123
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/FieldOptions.php429
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/FieldOptions_CType.php29
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/FieldOptions_JSType.php37
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/FileDescriptorProto.php477
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/FileDescriptorSet.php59
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/FileOptions.php784
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/FileOptions_OptimizeMode.php41
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/GPBLabel.php40
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/GPBType.php55
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/GPBUtil.php245
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/GPBWire.php617
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php75
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php198
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/InputStream.php394
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/MapEntry.php57
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/MapField.php345
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/Message.php881
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/MessageBuilderContext.php120
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/MessageOptions.php334
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php237
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/MethodOptions.php143
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php39
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php86
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/OneofField.php77
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/OneofOptions.php66
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/OutputStream.php159
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/RepeatedField.php303
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php114
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/ServiceOptions.php115
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/SourceCodeInfo.php191
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php379
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/UninterpretedOption.php246
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php90
-rw-r--r--third_party/protobuf/php/src/Google/Protobuf/descriptor.php565
-rw-r--r--third_party/protobuf/php/src/phpdoc.dist.xml15
-rw-r--r--third_party/protobuf/php/tests/array_test.php939
-rwxr-xr-xthird_party/protobuf/php/tests/autoload.php25
-rw-r--r--third_party/protobuf/php/tests/encode_decode_test.php225
-rwxr-xr-xthird_party/protobuf/php/tests/gdb_test.sh12
-rw-r--r--third_party/protobuf/php/tests/generated_class_test.php855
-rw-r--r--third_party/protobuf/php/tests/map_field_test.php679
-rw-r--r--third_party/protobuf/php/tests/memory_leak_test.php89
-rw-r--r--third_party/protobuf/php/tests/php_implementation_test.php513
-rw-r--r--third_party/protobuf/php/tests/proto/test.proto149
-rw-r--r--third_party/protobuf/php/tests/proto/test_include.proto7
-rw-r--r--third_party/protobuf/php/tests/proto/test_no_namespace.proto10
-rw-r--r--third_party/protobuf/php/tests/proto/test_prefix.proto7
-rwxr-xr-xthird_party/protobuf/php/tests/test.sh27
-rw-r--r--third_party/protobuf/php/tests/test_base.php339
-rw-r--r--third_party/protobuf/php/tests/test_util.php528
-rw-r--r--third_party/protobuf/php/tests/well_known_test.php11
-rwxr-xr-xthird_party/protobuf/post_process_dist.sh64
-rw-r--r--third_party/protobuf/proto_alias.bzl18
-rw-r--r--third_party/protobuf/protobuf-java-3.2.0.jarbin0 -> 1347123 bytes
-rw-r--r--third_party/protobuf/protobuf-java-util-3.2.0.jarbin0 -> 67556 bytes
-rw-r--r--third_party/protobuf/protobuf-lite.pc.in11
-rw-r--r--third_party/protobuf/protobuf.bzl (renamed from third_party/protobuf/3.0.0/protobuf.bzl)132
-rw-r--r--third_party/protobuf/protobuf.pc.in12
-rw-r--r--third_party/protobuf/protoc-artifacts/Dockerfile40
-rw-r--r--third_party/protobuf/protoc-artifacts/README.md177
-rwxr-xr-xthird_party/protobuf/protoc-artifacts/build-protoc.sh236
-rwxr-xr-xthird_party/protobuf/protoc-artifacts/build-zip.sh108
-rw-r--r--third_party/protobuf/protoc-artifacts/pom.xml135
-rw-r--r--third_party/protobuf/python/MANIFEST.in14
-rw-r--r--third_party/protobuf/python/README.md127
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/factory_test1.proto55
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/factory_test2.proto77
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/more_extensions.proto58
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/more_extensions_dynamic.proto49
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/more_messages.proto51
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/test_bad_identifiers.proto52
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/descriptor.proto620
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest.proto719
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_custom_options.proto387
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import.proto64
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import_public.proto40
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_mset.proto72
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_no_generic_services.proto52
-rwxr-xr-xthird_party/protobuf/python/compatibility_tests/v2.5.0/setup.py87
-rwxr-xr-xthird_party/protobuf/python/compatibility_tests/v2.5.0/test.sh104
-rw-r--r--[-rwxr-xr-x]third_party/protobuf/python/compatibility_tests/v2.5.0/tests/__init__.py (renamed from third_party/protobuf/3.0.0/python/google/__init__.py)0
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/__init__.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/__init__.py)0
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/__init__.py4
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/__init__.py37
-rwxr-xr-xthird_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/descriptor_test.py613
-rwxr-xr-xthird_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/generator_test.py269
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/golden_messagebin0 -> 509 bytes
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/golden_packed_fields_message (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testdata/golden_packed_fields_message)bin142 -> 142 bytes
-rwxr-xr-xthird_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/message_test.py494
-rwxr-xr-xthird_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/service_reflection_test.py136
-rwxr-xr-xthird_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/test_util.py651
-rwxr-xr-xthird_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/text_format_test.py620
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/text_format_unittest_data.txt128
-rw-r--r--third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/text_format_unittest_extensions_data.txt128
-rwxr-xr-xthird_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/wire_format_test.py253
-rwxr-xr-xthird_party/protobuf/python/google/__init__.py4
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/__init__.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/__init__.py)2
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/descriptor.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/descriptor.py)49
-rw-r--r--third_party/protobuf/python/google/protobuf/descriptor_database.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/descriptor_database.py)0
-rw-r--r--third_party/protobuf/python/google/protobuf/descriptor_pool.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/descriptor_pool.py)237
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/__init__.py0
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/_parameterized.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/_parameterized.py)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/any_test.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/anys.proto)29
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/api_implementation.cc (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/api_implementation.cc)0
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/api_implementation.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/api_implementation.py)0
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/containers.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/containers.py)21
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/decoder.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/decoder.py)22
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/descriptor_database_test.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/descriptor_database_test.py)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/descriptor_pool_test.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/descriptor_pool_test.py)52
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/descriptor_pool_test1.proto (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/descriptor_pool_test1.proto)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/descriptor_pool_test2.proto (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/descriptor_pool_test2.proto)0
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/descriptor_test.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/descriptor_test.py)19
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/encoder.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/encoder.py)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/enum_type_wrapper.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/enum_type_wrapper.py)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/factory_test1.proto (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/factory_test1.proto)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/factory_test2.proto (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/factory_test2.proto)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/file_options_test.proto (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/file_options_test.proto)0
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/generator_test.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/generator_test.py)3
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/import_test_package/__init__.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/import_test_package/__init__.py)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/import_test_package/inner.proto (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/import_test_package/inner.proto)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/import_test_package/outer.proto (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/import_test_package/outer.proto)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/json_format_test.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/json_format_test.py)78
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/message_factory_test.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/message_factory_test.py)20
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/message_listener.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/message_listener.py)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/message_set_extensions.proto (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/message_set_extensions.proto)0
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/message_test.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/message_test.py)45
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/missing_enum_values.proto (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/missing_enum_values.proto)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/more_extensions.proto (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/more_extensions.proto)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/more_extensions_dynamic.proto (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/more_extensions_dynamic.proto)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/more_messages.proto (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/more_messages.proto)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/packed_field_test.proto (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/packed_field_test.proto)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/proto_builder_test.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/proto_builder_test.py)0
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/python_message.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/python_message.py)59
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/reflection_test.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/reflection_test.py)110
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/service_reflection_test.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/service_reflection_test.py)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/symbol_database_test.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/symbol_database_test.py)0
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/test_bad_identifiers.proto (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/test_bad_identifiers.proto)0
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/test_util.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/test_util.py)154
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/testing_refleaks.py126
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/text_encoding_test.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/text_encoding_test.py)0
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/text_format_test.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/text_format_test.py)53
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/type_checkers.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/type_checkers.py)15
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/unknown_fields_test.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/unknown_fields_test.py)107
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/well_known_types.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/well_known_types.py)75
-rw-r--r--third_party/protobuf/python/google/protobuf/internal/well_known_types_test.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/well_known_types_test.py)132
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/wire_format.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/wire_format.py)0
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/internal/wire_format_test.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/internal/wire_format_test.py)0
-rw-r--r--third_party/protobuf/python/google/protobuf/json_format.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/json_format.py)99
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/message.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/message.py)9
-rw-r--r--third_party/protobuf/python/google/protobuf/message_factory.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/message_factory.py)11
-rw-r--r--third_party/protobuf/python/google/protobuf/proto_builder.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/proto_builder.py)0
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/README (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/README)0
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/__init__.py4
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/cpp_message.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/cpp_message.py)0
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/descriptor.cc (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor.cc)22
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/descriptor.h (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor.h)0
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/descriptor_containers.cc (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_containers.cc)0
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/descriptor_containers.h (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_containers.h)0
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/descriptor_database.cc (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_database.cc)0
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/descriptor_database.h (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_database.h)0
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_pool.cc)126
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.h (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_pool.h)35
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/extension_dict.cc (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/extension_dict.cc)147
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/extension_dict.h (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/extension_dict.h)43
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/map_container.cc (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/map_container.cc)97
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/map_container.h (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/map_container.h)12
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/message.cc (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/message.cc)634
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/message.h (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/message.h)57
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/message_factory.cc280
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/message_factory.h103
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/message_module.cc (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/message_module.cc)0
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/proto2_api_test.proto (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/proto2_api_test.proto)0
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/python.proto (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/python.proto)0
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/python_protobuf.h (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/python_protobuf.h)0
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/repeated_composite_container.cc (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/repeated_composite_container.cc)2
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/repeated_composite_container.h (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/repeated_composite_container.h)0
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/repeated_scalar_container.cc)0
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.h (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/repeated_scalar_container.h)0
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/safe_numerics.h164
-rw-r--r--third_party/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h (renamed from third_party/protobuf/3.0.0/python/google/protobuf/pyext/scoped_pyobject_ptr.h)0
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/reflection.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/reflection.py)9
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/service.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/service.py)0
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/service_reflection.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/service_reflection.py)0
-rw-r--r--third_party/protobuf/python/google/protobuf/symbol_database.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/symbol_database.py)3
-rw-r--r--third_party/protobuf/python/google/protobuf/text_encoding.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/text_encoding.py)0
-rwxr-xr-xthird_party/protobuf/python/google/protobuf/text_format.py (renamed from third_party/protobuf/3.0.0/python/google/protobuf/text_format.py)16
-rwxr-xr-xthird_party/protobuf/python/mox.py1401
-rw-r--r--third_party/protobuf/python/setup.cfg2
-rwxr-xr-xthird_party/protobuf/python/setup.py261
-rwxr-xr-xthird_party/protobuf/python/stubout.py140
-rw-r--r--third_party/protobuf/python/tox.ini24
-rw-r--r--third_party/protobuf/ruby/.gitignore8
-rw-r--r--third_party/protobuf/ruby/Gemfile3
-rw-r--r--third_party/protobuf/ruby/README.md114
-rw-r--r--third_party/protobuf/ruby/Rakefile108
-rw-r--r--third_party/protobuf/ruby/compatibility_tests/v3.0.0/README.md5
-rw-r--r--third_party/protobuf/ruby/compatibility_tests/v3.0.0/Rakefile25
-rwxr-xr-xthird_party/protobuf/ruby/compatibility_tests/v3.0.0/test.sh17
-rw-r--r--third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/basic.rb1182
-rw-r--r--third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/generated_code.proto67
-rw-r--r--third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/generated_code_test.rb19
-rw-r--r--third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb640
-rw-r--r--third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/stress.rb38
-rw-r--r--third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/test_import.proto5
-rw-r--r--third_party/protobuf/ruby/ext/google/protobuf_c/defs.c1763
-rw-r--r--third_party/protobuf/ruby/ext/google/protobuf_c/encode_decode.c1310
-rw-r--r--third_party/protobuf/ruby/ext/google/protobuf_c/extconf.rb17
-rw-r--r--third_party/protobuf/ruby/ext/google/protobuf_c/map.c841
-rw-r--r--third_party/protobuf/ruby/ext/google/protobuf_c/message.c632
-rw-r--r--third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.c117
-rw-r--r--third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h543
-rw-r--r--third_party/protobuf/ruby/ext/google/protobuf_c/repeated_field.c654
-rw-r--r--third_party/protobuf/ruby/ext/google/protobuf_c/storage.c893
-rw-r--r--third_party/protobuf/ruby/ext/google/protobuf_c/upb.c13950
-rw-r--r--third_party/protobuf/ruby/ext/google/protobuf_c/upb.h8853
-rw-r--r--third_party/protobuf/ruby/ext/google/protobuf_c/wrap_memcpy.c51
-rw-r--r--third_party/protobuf/ruby/google-protobuf.gemspec26
-rw-r--r--third_party/protobuf/ruby/lib/google/protobuf.rb (renamed from third_party/protobuf/3.0.0/src/google/protobuf/arena_nc_test.py)61
-rw-r--r--third_party/protobuf/ruby/lib/google/protobuf/message_exts.rb53
-rw-r--r--third_party/protobuf/ruby/lib/google/protobuf/repeated_field.rb188
-rw-r--r--third_party/protobuf/ruby/lib/google/protobuf/well_known_types.rb212
-rw-r--r--third_party/protobuf/ruby/pom.xml92
-rw-r--r--third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyBuilder.java167
-rw-r--r--third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyDescriptor.java269
-rw-r--r--third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyDescriptorPool.java169
-rw-r--r--third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyEnum.java86
-rw-r--r--third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyEnumBuilderContext.java82
-rw-r--r--third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyEnumDescriptor.java185
-rw-r--r--third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyFieldDescriptor.java277
-rw-r--r--third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyMap.java434
-rw-r--r--third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java784
-rw-r--r--third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyMessageBuilderContext.java217
-rw-r--r--third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyOneofBuilderContext.java84
-rw-r--r--third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyOneofDescriptor.java124
-rw-r--r--third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyProtobuf.java68
-rw-r--r--third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyRepeatedField.java409
-rw-r--r--third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/SentinelOuterClass.java776
-rw-r--r--third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/Utils.java303
-rw-r--r--third_party/protobuf/ruby/src/main/java/google/ProtobufJavaService.java60
-rw-r--r--third_party/protobuf/ruby/src/main/sentinel.proto15
-rw-r--r--third_party/protobuf/ruby/tests/basic.rb1214
-rw-r--r--third_party/protobuf/ruby/tests/generated_code.proto67
-rw-r--r--third_party/protobuf/ruby/tests/generated_code_test.rb19
-rw-r--r--third_party/protobuf/ruby/tests/repeated_field_test.rb640
-rw-r--r--third_party/protobuf/ruby/tests/stress.rb38
-rw-r--r--third_party/protobuf/ruby/tests/test_import.proto5
-rw-r--r--third_party/protobuf/ruby/tests/well_known_types_test.rb122
-rwxr-xr-xthird_party/protobuf/ruby/travis-test.sh28
-rw-r--r--third_party/protobuf/six.BUILD13
-rw-r--r--third_party/protobuf/src/Makefile.am913
-rw-r--r--third_party/protobuf/src/README.md212
-rw-r--r--third_party/protobuf/src/google/protobuf/any.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/any.cc)8
-rw-r--r--third_party/protobuf/src/google/protobuf/any.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/any.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/any.pb.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/any.pb.cc)269
-rw-r--r--third_party/protobuf/src/google/protobuf/any.pb.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/any.pb.h)114
-rw-r--r--third_party/protobuf/src/google/protobuf/any.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/any.proto)1
-rw-r--r--third_party/protobuf/src/google/protobuf/any_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/any_test.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/any_test.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/any_test.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/api.pb.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/api.pb.cc)1014
-rw-r--r--third_party/protobuf/src/google/protobuf/api.pb.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/api.pb.h)432
-rw-r--r--third_party/protobuf/src/google/protobuf/api.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/api.proto)2
-rwxr-xr-xthird_party/protobuf/src/google/protobuf/arena.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/arena.cc)51
-rw-r--r--third_party/protobuf/src/google/protobuf/arena.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/arena.h)71
-rw-r--r--third_party/protobuf/src/google/protobuf/arena_test_util.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/arena_test_util.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/arena_test_util.h91
-rw-r--r--third_party/protobuf/src/google/protobuf/arena_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/arena_unittest.cc)55
-rw-r--r--third_party/protobuf/src/google/protobuf/arenastring.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/arenastring.cc)2
-rwxr-xr-xthird_party/protobuf/src/google/protobuf/arenastring.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/arenastring.h)42
-rw-r--r--third_party/protobuf/src/google/protobuf/arenastring_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/arenastring_unittest.cc)22
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/code_generator.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/code_generator.cc)44
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/code_generator.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/code_generator.h)52
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/command_line_interface.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/command_line_interface.cc)259
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/command_line_interface.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/command_line_interface.h)68
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/command_line_interface_unittest.cc)234
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc)3
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_enum.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_enum.cc)43
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_enum.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_enum.h)8
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_enum_field.cc)58
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_enum_field.h)6
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_extension.cc)36
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_extension.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_field.cc)4
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_field.h)21
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_file.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_file.cc)749
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_file.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_file.h)46
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_generator.cc)2
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_generator.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_helpers.cc)66
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_helpers.h)31
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_map_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_map_field.cc)39
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_map_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_map_field.h)5
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_message.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_message.cc)2793
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_message.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_message.h)63
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_message_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_message_field.cc)146
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_message_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_message_field.h)17
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_options.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_options.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc)106
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_primitive_field.h)6
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_service.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_service.cc)58
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_service.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_service.h)5
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_string_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_string_field.cc)786
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_string_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_string_field.h)11
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_unittest.cc)109
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_unittest.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_unittest.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/cpp/metadata_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/metadata_test.cc)6
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc197
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc)2
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_doc_comment.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_doc_comment.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_enum.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_enum.cc)21
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_enum.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_enum.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_enum_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_enum_field.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_enum_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_enum_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_field_base.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_field_base.cc)6
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_field_base.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_field_base.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_generator.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_generator.cc)3
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_generator.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_generator.h)8
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_helpers.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_helpers.cc)1
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_helpers.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_helpers.h)16
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_map_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_map_field.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_map_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_map_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_message.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_message.cc)31
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_message.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_message.h)2
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_message_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_message_field.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_message_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_message_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_names.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_names.h)9
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_options.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_options.h)9
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_primitive_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_primitive_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_reflection_class.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_reflection_class.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_source_generator_base.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_source_generator_base.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/importer.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/importer.cc)6
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/importer.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/importer.h)2
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/importer_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/importer_unittest.cc)2
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_context.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_context.cc)8
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_context.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_context.h)8
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_doc_comment.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_doc_comment.cc)2
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_doc_comment.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_doc_comment.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_enum.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum.cc)68
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_enum.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum.h)4
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_enum_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_field.cc)5
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_enum_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_field.h)4
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_enum_field_lite.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_field_lite.cc)6
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_enum_field_lite.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_field_lite.h)4
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_enum_lite.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_lite.cc)6
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_enum_lite.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_lite.h)4
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_extension.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_extension.cc)12
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_extension.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_extension.h)2
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_extension_lite.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_extension_lite.cc)2
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_extension_lite.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_extension_lite.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_field.cc)8
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_field.h)8
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_file.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_file.cc)14
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_file.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_file.h)4
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_generator.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_generator.cc)8
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_generator.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_generator.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_generator_factory.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_generator_factory.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_generator_factory.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_generator_factory.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_helpers.cc)9
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_helpers.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_lazy_message_field.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_lazy_message_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc)3
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field_lite.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_lazy_message_field_lite.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_map_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_map_field.cc)175
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_map_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_map_field.h)2
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_map_field_lite.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_map_field_lite.cc)8
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_map_field_lite.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_map_field_lite.h)2
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message.cc)51
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_message.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_message_builder.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_builder.cc)17
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_message_builder.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_builder.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_message_builder_lite.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_builder_lite.cc)2
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_message_builder_lite.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_builder_lite.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_message_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_field.cc)2
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_message_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_field.h)4
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_message_field_lite.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_field_lite.cc)4
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_message_field_lite.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_field_lite.h)4
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_message_lite.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_lite.cc)95
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_message_lite.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_lite.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_name_resolver.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_name_resolver.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_name_resolver.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_name_resolver.h)2
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_names.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_names.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_options.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_options.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_plugin_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_plugin_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_primitive_field.cc)31
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_primitive_field.h)4
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field_lite.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_primitive_field_lite.cc)6
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field_lite.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_primitive_field_lite.h)4
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_service.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_service.cc)34
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_service.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_service.h)3
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_shared_code_generator.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_shared_code_generator.cc)25
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_shared_code_generator.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_shared_code_generator.h)10
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_string_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_string_field.cc)5
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_string_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_string_field.h)4
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_string_field_lite.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_string_field_lite.cc)6
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/java/java_string_field_lite.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_string_field_lite.h)4
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_enum.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_enum.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_enum.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_enum.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_enum_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_enum_field.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_enum_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_enum_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_extension.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_extension.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_extension.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_extension.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_field.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_file.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_file.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_file.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_file.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_generator.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_generator.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_generator.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_generator.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_helpers.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_helpers.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_helpers.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_helpers.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_map_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_map_field.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_map_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_map_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_message.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_message.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_message.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_message.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_message_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_message_field.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_message_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_message_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_params.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_params.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_primitive_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_primitive_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/js/embed.cc112
-rwxr-xr-xthird_party/protobuf/src/google/protobuf/compiler/js/js_generator.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/js/js_generator.cc)1155
-rwxr-xr-xthird_party/protobuf/src/google/protobuf/compiler/js/js_generator.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/js/js_generator.h)120
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/js/well_known_types/any.js80
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/js/well_known_types/struct.js168
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/js/well_known_types/timestamp.js54
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/js/well_known_types_embed.h43
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/main.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/main.cc)28
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/mock_code_generator.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/mock_code_generator.cc)38
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/mock_code_generator.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/mock_code_generator.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_enum.cc)20
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_enum.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc)14
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_extension.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_extension.cc)9
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_extension.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_extension.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_field.cc)8
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_file.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_file.cc)469
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_file.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_file.h)15
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_generator.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_generator.cc)51
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_generator.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_generator.h)15
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc)412
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_helpers.h)145
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc)2
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_map_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_map_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_message.cc)39
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_message.h)1
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_message_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc)6
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_oneof.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_oneof.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/package_info.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/package_info.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/parser.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/parser.cc)14
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/parser.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/parser.h)10
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/parser_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/parser_unittest.cc)10
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/php/php_generator.cc1119
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/php/php_generator.h57
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/plugin.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/plugin.cc)67
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/plugin.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/plugin.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/plugin.pb.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/plugin.pb.cc)1684
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/plugin.pb.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/plugin.pb.h)764
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/plugin.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/plugin.proto)15
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/python/python_generator.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/python/python_generator.cc)76
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/python/python_generator.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/python/python_generator.h)4
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/python/python_plugin_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/python/python_plugin_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/ruby/ruby_generated_code.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code_pb.rb (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/ruby/ruby_generated_code_pb.rb)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/ruby/ruby_generator.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/ruby/ruby_generator.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/ruby/ruby_generator.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/ruby/ruby_generator.h)6
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/subprocess.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/subprocess.cc)11
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/subprocess.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/subprocess.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/test_plugin.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/test_plugin.cc)0
-rwxr-xr-xthird_party/protobuf/src/google/protobuf/compiler/zip_output_unittest.sh (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/zip_output_unittest.sh)0
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/zip_writer.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/compiler/zip_writer.cc)30
-rw-r--r--third_party/protobuf/src/google/protobuf/compiler/zip_writer.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/arena_test_util.h)41
-rw-r--r--third_party/protobuf/src/google/protobuf/descriptor.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/descriptor.cc)494
-rw-r--r--third_party/protobuf/src/google/protobuf/descriptor.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/descriptor.h)10
-rw-r--r--third_party/protobuf/src/google/protobuf/descriptor.pb.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/descriptor.pb.cc)8792
-rw-r--r--third_party/protobuf/src/google/protobuf/descriptor.pb.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/descriptor.pb.h)3184
-rw-r--r--third_party/protobuf/src/google/protobuf/descriptor.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/descriptor.proto)55
-rw-r--r--third_party/protobuf/src/google/protobuf/descriptor_database.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/descriptor_database.cc)47
-rw-r--r--third_party/protobuf/src/google/protobuf/descriptor_database.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/descriptor_database.h)34
-rw-r--r--third_party/protobuf/src/google/protobuf/descriptor_database_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/descriptor_database_unittest.cc)18
-rw-r--r--third_party/protobuf/src/google/protobuf/descriptor_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/descriptor_unittest.cc)237
-rw-r--r--third_party/protobuf/src/google/protobuf/drop_unknown_fields_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/drop_unknown_fields_test.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/duration.pb.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/duration.pb.cc)288
-rw-r--r--third_party/protobuf/src/google/protobuf/duration.pb.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/duration.pb.h)99
-rw-r--r--third_party/protobuf/src/google/protobuf/duration.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/duration.proto)8
-rw-r--r--third_party/protobuf/src/google/protobuf/dynamic_message.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/dynamic_message.cc)177
-rw-r--r--third_party/protobuf/src/google/protobuf/dynamic_message.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/dynamic_message.h)90
-rw-r--r--third_party/protobuf/src/google/protobuf/dynamic_message_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/dynamic_message_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/empty.pb.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/empty.pb.cc)191
-rw-r--r--third_party/protobuf/src/google/protobuf/empty.pb.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/empty.pb.h)82
-rw-r--r--third_party/protobuf/src/google/protobuf/empty.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/empty.proto)1
-rw-r--r--third_party/protobuf/src/google/protobuf/extension_set.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/extension_set.cc)25
-rw-r--r--third_party/protobuf/src/google/protobuf/extension_set.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/extension_set.h)8
-rw-r--r--third_party/protobuf/src/google/protobuf/extension_set_heavy.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/extension_set_heavy.cc)30
-rw-r--r--third_party/protobuf/src/google/protobuf/extension_set_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/extension_set_unittest.cc)12
-rw-r--r--third_party/protobuf/src/google/protobuf/field_mask.pb.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/field_mask.pb.cc)227
-rw-r--r--third_party/protobuf/src/google/protobuf/field_mask.pb.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/field_mask.pb.h)98
-rw-r--r--third_party/protobuf/src/google/protobuf/field_mask.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/field_mask.proto)8
-rw-r--r--third_party/protobuf/src/google/protobuf/generated_enum_reflection.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/generated_enum_reflection.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/generated_enum_util.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/generated_enum_util.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/generated_message_reflection.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/generated_message_reflection.cc)654
-rw-r--r--third_party/protobuf/src/google/protobuf/generated_message_reflection.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/generated_message_reflection.h)317
-rw-r--r--third_party/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/generated_message_reflection_unittest.cc)136
-rw-r--r--third_party/protobuf/src/google/protobuf/generated_message_util.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/generated_message_util.cc)14
-rw-r--r--third_party/protobuf/src/google/protobuf/generated_message_util.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/generated_message_util.h)84
-rw-r--r--third_party/protobuf/src/google/protobuf/has_bits.h103
-rw-r--r--third_party/protobuf/src/google/protobuf/io/coded_stream.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/coded_stream.cc)170
-rw-r--r--third_party/protobuf/src/google/protobuf/io/coded_stream.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/coded_stream.h)176
-rw-r--r--third_party/protobuf/src/google/protobuf/io/coded_stream_inl.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/coded_stream_inl.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/io/coded_stream_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/coded_stream_unittest.cc)83
-rw-r--r--third_party/protobuf/src/google/protobuf/io/gzip_stream.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/gzip_stream.cc)2
-rw-r--r--third_party/protobuf/src/google/protobuf/io/gzip_stream.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/gzip_stream.h)2
-rwxr-xr-xthird_party/protobuf/src/google/protobuf/io/gzip_stream_unittest.sh (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/gzip_stream_unittest.sh)0
-rw-r--r--third_party/protobuf/src/google/protobuf/io/package_info.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/package_info.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/io/printer.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/printer.cc)36
-rw-r--r--third_party/protobuf/src/google/protobuf/io/printer.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/printer.h)18
-rw-r--r--third_party/protobuf/src/google/protobuf/io/printer_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/printer_unittest.cc)30
-rw-r--r--third_party/protobuf/src/google/protobuf/io/strtod.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/strtod.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/io/strtod.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/strtod.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/io/tokenizer.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/tokenizer.cc)6
-rw-r--r--third_party/protobuf/src/google/protobuf/io/tokenizer.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/tokenizer.h)2
-rw-r--r--third_party/protobuf/src/google/protobuf/io/tokenizer_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/tokenizer_unittest.cc)17
-rw-r--r--third_party/protobuf/src/google/protobuf/io/zero_copy_stream.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/io/zero_copy_stream.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream_impl.cc)24
-rw-r--r--third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream_impl.h)12
-rw-r--r--third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream_impl_lite.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream_impl_lite.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/io/zero_copy_stream_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream_unittest.cc)6
-rw-r--r--third_party/protobuf/src/google/protobuf/lite_arena_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/lite_arena_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/lite_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/lite_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/map.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map.h)56
-rw-r--r--third_party/protobuf/src/google/protobuf/map_entry.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_entry.h)33
-rw-r--r--third_party/protobuf/src/google/protobuf/map_entry_lite.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_entry_lite.h)34
-rw-r--r--third_party/protobuf/src/google/protobuf/map_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_field.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/map_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_field.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/map_field_inl.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_field_inl.h)34
-rw-r--r--third_party/protobuf/src/google/protobuf/map_field_lite.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_field_lite.h)7
-rw-r--r--third_party/protobuf/src/google/protobuf/map_field_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_field_test.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/map_lite_test_util.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_lite_test_util.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/map_lite_test_util.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_lite_test_util.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/map_lite_unittest.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_lite_unittest.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/map_proto2_unittest.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_proto2_unittest.proto)2
-rw-r--r--third_party/protobuf/src/google/protobuf/map_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_test.cc)60
-rw-r--r--third_party/protobuf/src/google/protobuf/map_test_util.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_test_util.cc)6
-rw-r--r--third_party/protobuf/src/google/protobuf/map_test_util.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_test_util.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/map_test_util_impl.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_test_util_impl.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/map_type_handler.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_type_handler.h)24
-rw-r--r--third_party/protobuf/src/google/protobuf/map_unittest.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/map_unittest.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/map_unittest_proto3.proto120
-rw-r--r--third_party/protobuf/src/google/protobuf/message.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/message.cc)66
-rw-r--r--third_party/protobuf/src/google/protobuf/message.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/message.h)53
-rw-r--r--third_party/protobuf/src/google/protobuf/message_lite.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/message_lite.cc)41
-rw-r--r--third_party/protobuf/src/google/protobuf/message_lite.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/message_lite.h)22
-rw-r--r--third_party/protobuf/src/google/protobuf/message_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/message_unittest.cc)139
-rw-r--r--third_party/protobuf/src/google/protobuf/metadata.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/metadata.h)112
-rw-r--r--third_party/protobuf/src/google/protobuf/no_field_presence_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/no_field_presence_test.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/package_info.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/package_info.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/preserve_unknown_enum_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/preserve_unknown_enum_test.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/proto3_arena_lite_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/proto3_arena_lite_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/proto3_arena_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/proto3_arena_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/proto3_lite_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/proto3_lite_unittest.cc)0
-rwxr-xr-xthird_party/protobuf/src/google/protobuf/reflection.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/reflection.h)29
-rw-r--r--third_party/protobuf/src/google/protobuf/reflection_internal.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/reflection_internal.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/reflection_ops.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/reflection_ops.cc)12
-rw-r--r--third_party/protobuf/src/google/protobuf/reflection_ops.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/reflection_ops.h)2
-rw-r--r--third_party/protobuf/src/google/protobuf/reflection_ops_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/reflection_ops_unittest.cc)2
-rw-r--r--third_party/protobuf/src/google/protobuf/repeated_field.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/repeated_field.cc)18
-rw-r--r--third_party/protobuf/src/google/protobuf/repeated_field.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/repeated_field.h)154
-rw-r--r--third_party/protobuf/src/google/protobuf/repeated_field_reflection_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/repeated_field_reflection_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/repeated_field_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/repeated_field_unittest.cc)64
-rw-r--r--third_party/protobuf/src/google/protobuf/service.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/service.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/service.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/service.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/source_context.pb.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/source_context.pb.cc)222
-rw-r--r--third_party/protobuf/src/google/protobuf/source_context.pb.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/source_context.pb.h)97
-rw-r--r--third_party/protobuf/src/google/protobuf/source_context.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/source_context.proto)2
-rw-r--r--third_party/protobuf/src/google/protobuf/struct.pb.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/struct.pb.cc)942
-rw-r--r--third_party/protobuf/src/google/protobuf/struct.pb.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/struct.pb.h)433
-rw-r--r--third_party/protobuf/src/google/protobuf/struct.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/struct.proto)2
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/atomic_sequence_num.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomic_sequence_num.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/atomicops.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops.h)27
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_arm64_gcc.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_arm64_gcc.h)26
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_arm_gcc.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_arm_gcc.h)10
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_arm_qnx.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_arm_qnx.h)10
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_pnacl.h)16
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h)30
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_mips_gcc.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_mips_gcc.h)34
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_power.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_power.h)2
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_ppc_gcc.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_ppc_gcc.h)18
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_solaris.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_solaris.h)18
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_tsan.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_tsan.h)2
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h)12
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc)7
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_msvc.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_x86_msvc.h)4
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/bytestream.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/bytestream.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/bytestream.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/bytestream.h)2
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/bytestream_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/bytestream_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/callback.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/callback.h)34
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/casts.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/casts.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/common.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/common.cc)13
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/common.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/common.h)13
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/common_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/common_unittest.cc)2
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/fastmem.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/fastmem.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/hash.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/hash.h)16
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/int128.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/int128.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/int128.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/int128.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/int128_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/int128_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/io_win32.cc281
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/io_win32.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/io/io_win32.h)41
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/io_win32_unittest.cc268
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/logging.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/logging.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/macros.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/macros.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/map_util.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/map_util.h)7
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/mathlimits.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/mathlimits.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/mathlimits.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/mathlimits.h)39
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/mathutil.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/mathutil.h)23
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/mutex.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/mutex.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/once.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/once.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/once.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/once.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/once_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/once_unittest.cc)5
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/platform_macros.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/platform_macros.h)6
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/port.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/port.h)78
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/scoped_ptr.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/scoped_ptr.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/shared_ptr.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/shared_ptr.h)7
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/singleton.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/singleton.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/status.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/status.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/status.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/status.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/status_macros.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/status_macros.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/status_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/status_test.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/statusor.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/statusor.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/statusor.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/statusor.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/statusor_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/statusor_test.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/stl_util.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/stl_util.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/stringpiece.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringpiece.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/stringpiece.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringpiece.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/stringpiece_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringpiece_unittest.cc)2
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/stringprintf.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringprintf.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/stringprintf.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringprintf.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/stringprintf_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringprintf_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/structurally_valid.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/structurally_valid.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/structurally_valid_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/structurally_valid_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/strutil.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/strutil.cc)17
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/strutil.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/strutil.h)4
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/strutil_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/strutil_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/substitute.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/substitute.cc)4
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/substitute.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/substitute.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/template_util.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/template_util.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/template_util_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/template_util_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/time.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/time.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/time.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/time.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/time_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/time_test.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/type_traits.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/type_traits.h)2
-rw-r--r--third_party/protobuf/src/google/protobuf/stubs/type_traits_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/stubs/type_traits_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/test_messages_proto3.proto227
-rw-r--r--third_party/protobuf/src/google/protobuf/test_util.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/test_util.cc)10
-rw-r--r--third_party/protobuf/src/google/protobuf/test_util.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/test_util.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/test_util_lite.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/test_util_lite.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/test_util_lite.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/test_util_lite.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/testdata/bad_utf8_string (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testdata/bad_utf8_string)0
-rw-r--r--third_party/protobuf/src/google/protobuf/testdata/golden_message (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testdata/golden_message)bin531 -> 531 bytes
-rw-r--r--third_party/protobuf/src/google/protobuf/testdata/golden_message_maps (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testdata/golden_message_maps)bin13619 -> 13619 bytes
-rw-r--r--third_party/protobuf/src/google/protobuf/testdata/golden_message_oneof_implemented (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testdata/golden_message_oneof_implemented)bin515 -> 515 bytes
-rw-r--r--third_party/protobuf/src/google/protobuf/testdata/golden_message_proto3 (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testdata/golden_message_proto3)bin248 -> 248 bytes
-rw-r--r--third_party/protobuf/src/google/protobuf/testdata/golden_packed_fields_messagebin0 -> 142 bytes
-rw-r--r--third_party/protobuf/src/google/protobuf/testdata/map_test_data.txt (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testdata/map_test_data.txt)0
-rw-r--r--third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_data.txt (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_data.txt)0
-rw-r--r--third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_data_oneof_implemented.txt (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_data_oneof_implemented.txt)0
-rw-r--r--third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_data_pointy.txt (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_data_pointy.txt)0
-rw-r--r--third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_data_pointy_oneof.txt (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_data_pointy_oneof.txt)0
-rw-r--r--third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_extensions_data.txt (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_extensions_data.txt)0
-rw-r--r--third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_extensions_data_pointy.txt (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_extensions_data_pointy.txt)0
-rw-r--r--third_party/protobuf/src/google/protobuf/testing/file.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testing/file.cc)17
-rw-r--r--third_party/protobuf/src/google/protobuf/testing/file.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testing/file.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/testing/googletest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testing/googletest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/testing/googletest.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testing/googletest.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/testing/zcgunzip.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testing/zcgunzip.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/testing/zcgzip.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/testing/zcgzip.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/text_format.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/text_format.cc)127
-rw-r--r--third_party/protobuf/src/google/protobuf/text_format.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/text_format.h)12
-rw-r--r--third_party/protobuf/src/google/protobuf/text_format_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/text_format_unittest.cc)117
-rw-r--r--third_party/protobuf/src/google/protobuf/timestamp.pb.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/timestamp.pb.cc)268
-rw-r--r--third_party/protobuf/src/google/protobuf/timestamp.pb.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/timestamp.pb.h)90
-rw-r--r--third_party/protobuf/src/google/protobuf/timestamp.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/timestamp.proto)9
-rw-r--r--third_party/protobuf/src/google/protobuf/type.pb.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/type.pb.cc)2482
-rw-r--r--third_party/protobuf/src/google/protobuf/type.pb.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/type.pb.h)1063
-rw-r--r--third_party/protobuf/src/google/protobuf/type.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/type.proto)13
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest.proto)43
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_arena.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_arena.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_custom_options.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_custom_options.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_drop_unknown_fields.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_drop_unknown_fields.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_embed_optimize_for.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_embed_optimize_for.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_empty.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_empty.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_enormous_descriptor.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_enormous_descriptor.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_import.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_import.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_import_lite.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_import_lite.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_import_proto3.proto68
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_import_public.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_import_public.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_import_public_lite.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_import_public_lite.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_import_public_proto3.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/struct.proto)17
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_lite.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_lite.proto)34
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_lite_imports_nonlite.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_lite_imports_nonlite.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_mset.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_mset.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_mset_wire_format.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_mset_wire_format.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_no_arena.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_no_arena.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_no_arena_import.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_no_arena_import.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_no_arena_lite.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_no_arena_lite.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_no_field_presence.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_no_field_presence.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_no_generic_services.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_no_generic_services.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_optimize_for.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_optimize_for.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_preserve_unknown_enum.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_preserve_unknown_enum.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_preserve_unknown_enum2.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_preserve_unknown_enum2.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_proto3.proto391
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_proto3_arena.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_proto3_arena.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_proto3_arena_lite.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_proto3_arena_lite.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_proto3_lite.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unittest_proto3_lite.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/unittest_well_known_types.proto114
-rw-r--r--third_party/protobuf/src/google/protobuf/unknown_field_set.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unknown_field_set.cc)25
-rw-r--r--third_party/protobuf/src/google/protobuf/unknown_field_set.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unknown_field_set.h)16
-rw-r--r--third_party/protobuf/src/google/protobuf/unknown_field_set_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/unknown_field_set_unittest.cc)11
-rw-r--r--third_party/protobuf/src/google/protobuf/util/delimited_message_util.cc79
-rw-r--r--third_party/protobuf/src/google/protobuf/util/delimited_message_util.h66
-rw-r--r--third_party/protobuf/src/google/protobuf/util/delimited_message_util_test.cc57
-rw-r--r--third_party/protobuf/src/google/protobuf/util/field_comparator.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/field_comparator.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/field_comparator.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/field_comparator.h)4
-rw-r--r--third_party/protobuf/src/google/protobuf/util/field_comparator_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/field_comparator_test.cc)16
-rw-r--r--third_party/protobuf/src/google/protobuf/util/field_mask_util.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/field_mask_util.cc)37
-rw-r--r--third_party/protobuf/src/google/protobuf/util/field_mask_util.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/field_mask_util.h)18
-rw-r--r--third_party/protobuf/src/google/protobuf/util/field_mask_util_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/field_mask_util_test.cc)21
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/constants.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/constants.h)8
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/datapiece.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/datapiece.cc)72
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/datapiece.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/datapiece.h)33
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/default_value_objectwriter.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/default_value_objectwriter.cc)82
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/default_value_objectwriter.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/default_value_objectwriter.h)18
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/default_value_objectwriter_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/default_value_objectwriter_test.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/error_listener.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/error_listener.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/error_listener.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/error_listener.h)4
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/expecting_objectwriter.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/expecting_objectwriter.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/field_mask_utility.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/field_mask_utility.cc)2
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/field_mask_utility.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/field_mask_utility.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/json_escaping.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_escaping.cc)6
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/json_escaping.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_escaping.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/json_objectwriter.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_objectwriter.cc)21
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/json_objectwriter.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_objectwriter.h)20
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/json_objectwriter_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_objectwriter_test.cc)4
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/json_stream_parser.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_stream_parser.cc)74
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/json_stream_parser.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_stream_parser.h)11
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/json_stream_parser_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_stream_parser_test.cc)62
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/location_tracker.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/location_tracker.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/mock_error_listener.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/mock_error_listener.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/object_location_tracker.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/object_location_tracker.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/object_source.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/object_source.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/object_writer.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/object_writer.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/object_writer.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/object_writer.h)7
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/proto_writer.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/proto_writer.cc)11
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/proto_writer.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/proto_writer.h)8
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/protostream_objectsource.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectsource.cc)55
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/protostream_objectsource.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectsource.h)63
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/protostream_objectsource_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectsource_test.cc)92
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/protostream_objectwriter.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectwriter.cc)138
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/protostream_objectwriter.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectwriter.h)62
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/protostream_objectwriter_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectwriter_test.cc)499
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/structured_objectwriter.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/structured_objectwriter.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/testdata/anys.proto108
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/testdata/books.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/books.proto)14
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/testdata/default_value.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/default_value.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/testdata/default_value_test.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/default_value_test.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/testdata/field_mask.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/field_mask.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/testdata/maps.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/maps.proto)76
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/testdata/oneofs.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/oneofs.proto)31
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/testdata/proto3.proto42
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/testdata/struct.proto117
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/testdata/timestamp_duration.proto80
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/testdata/wrappers.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/wrappers.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/type_info.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/type_info.cc)40
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/type_info.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/type_info.h)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/type_info_test_helper.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/type_info_test_helper.cc)6
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/type_info_test_helper.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/type_info_test_helper.h)2
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/utility.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/utility.cc)65
-rw-r--r--third_party/protobuf/src/google/protobuf/util/internal/utility.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/internal/utility.h)11
-rw-r--r--third_party/protobuf/src/google/protobuf/util/json_format_proto3.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/json_format_proto3.proto)2
-rw-r--r--third_party/protobuf/src/google/protobuf/util/json_util.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/json_util.cc)34
-rw-r--r--third_party/protobuf/src/google/protobuf/util/json_util.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/json_util.h)14
-rw-r--r--third_party/protobuf/src/google/protobuf/util/json_util_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/json_util_test.cc)127
-rw-r--r--third_party/protobuf/src/google/protobuf/util/message_differencer.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/message_differencer.cc)153
-rw-r--r--third_party/protobuf/src/google/protobuf/util/message_differencer.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/message_differencer.h)127
-rwxr-xr-xthird_party/protobuf/src/google/protobuf/util/message_differencer_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/message_differencer_unittest.cc)65
-rw-r--r--third_party/protobuf/src/google/protobuf/util/message_differencer_unittest.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/message_differencer_unittest.proto)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/package_info.h46
-rw-r--r--third_party/protobuf/src/google/protobuf/util/time_util.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/time_util.cc)4
-rw-r--r--third_party/protobuf/src/google/protobuf/util/time_util.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/time_util.h)7
-rw-r--r--third_party/protobuf/src/google/protobuf/util/time_util_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/time_util_test.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/util/type_resolver.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/type_resolver.h)2
-rw-r--r--third_party/protobuf/src/google/protobuf/util/type_resolver_util.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/type_resolver_util.cc)56
-rw-r--r--third_party/protobuf/src/google/protobuf/util/type_resolver_util.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/type_resolver_util.h)2
-rw-r--r--third_party/protobuf/src/google/protobuf/util/type_resolver_util_test.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/util/type_resolver_util_test.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/well_known_types_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/well_known_types_unittest.cc)0
-rw-r--r--third_party/protobuf/src/google/protobuf/wire_format.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/wire_format.cc)72
-rw-r--r--third_party/protobuf/src/google/protobuf/wire_format.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/wire_format.h)20
-rw-r--r--third_party/protobuf/src/google/protobuf/wire_format_lite.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/wire_format_lite.cc)239
-rw-r--r--third_party/protobuf/src/google/protobuf/wire_format_lite.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/wire_format_lite.h)89
-rw-r--r--third_party/protobuf/src/google/protobuf/wire_format_lite_inl.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/wire_format_lite_inl.h)86
-rw-r--r--third_party/protobuf/src/google/protobuf/wire_format_unittest.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/wire_format_unittest.cc)146
-rw-r--r--third_party/protobuf/src/google/protobuf/wrappers.pb.cc (renamed from third_party/protobuf/3.0.0/src/google/protobuf/wrappers.pb.cc)1350
-rw-r--r--third_party/protobuf/src/google/protobuf/wrappers.pb.h (renamed from third_party/protobuf/3.0.0/src/google/protobuf/wrappers.pb.h)550
-rw-r--r--third_party/protobuf/src/google/protobuf/wrappers.proto (renamed from third_party/protobuf/3.0.0/src/google/protobuf/wrappers.proto)1
-rw-r--r--third_party/protobuf/src/libprotobuf-lite.map9
-rw-r--r--third_party/protobuf/src/libprotobuf.map9
-rw-r--r--third_party/protobuf/src/libprotoc.map9
-rw-r--r--third_party/protobuf/src/solaris/libstdc++.la51
-rwxr-xr-xthird_party/protobuf/tests.sh599
-rwxr-xr-xthird_party/protobuf/update_file_lists.sh191
-rw-r--r--third_party/protobuf/util/python/BUILD18
1665 files changed, 429164 insertions, 18962 deletions
diff --git a/third_party/protobuf/3.0.0/BUILD b/third_party/protobuf/3.0.0/BUILD
deleted file mode 100644
index 4b97838b55..0000000000
--- a/third_party/protobuf/3.0.0/BUILD
+++ /dev/null
@@ -1,328 +0,0 @@
-package(default_visibility = ["//visibility:public"])
-
-licenses(["notice"])
-
-load(":protobuf.bzl", "py_proto_library")
-
-filegroup(
- name = "srcs",
- srcs = glob(
- [
- "**",
- "protobuf.bzl",
- "python/google/protobuf/**/*.py",
- "src/google/protobuf/**/*.proto",
- ],
- ),
- visibility = ["//third_party/protobuf:__pkg__"],
-)
-
-java_import(
- name = "protobuf_java_util",
- jars = ["protobuf-java-util-3.0.0.jar"],
- exports = [
- "//third_party:gson",
- ],
-)
-
-java_import(
- name = "protobuf_java",
- jars = ["protobuf-java-3.0.0.jar"],
-)
-
-# For bootstrapping JavaBuilder
-filegroup(
- name = "protobuf-jars",
- srcs = ["protobuf-java-3.0.0.jar"],
-)
-
-################################################################################
-# The following rules are based on the build rules in protobuf's BUILD files.
-################################################################################
-
-py_library(
- name = "protobuf_python_srcs",
- srcs = glob(
- [
- "python/google/protobuf/*.py",
- "python/google/protobuf/**/*.py",
- ],
- exclude = [
- "python/google/protobuf/__init__.py",
- "python/google/protobuf/**/__init__.py",
- "python/google/protobuf/internal/*_test.py",
- "python/google/protobuf/internal/test_util.py",
- ],
- ),
- imports = ["python"],
- srcs_version = "PY2AND3",
-)
-
-py_proto_library(
- name = "protobuf_python",
- srcs = [
- "src/google/protobuf/any.proto",
- "src/google/protobuf/api.proto",
- "src/google/protobuf/compiler/plugin.proto",
- "src/google/protobuf/descriptor.proto",
- "src/google/protobuf/duration.proto",
- "src/google/protobuf/empty.proto",
- "src/google/protobuf/field_mask.proto",
- "src/google/protobuf/source_context.proto",
- "src/google/protobuf/struct.proto",
- "src/google/protobuf/timestamp.proto",
- "src/google/protobuf/type.proto",
- "src/google/protobuf/wrappers.proto",
- ],
- include = "src",
- default_runtime = "",
- protoc = ":protoc",
- py_libs = [
- ":protobuf_python_srcs",
- "//third_party/py/six",
- ],
- srcs_version = "PY2AND3",
-)
-
-COPTS = [
- "-DHAVE_PTHREAD",
- "-Wall",
- "-Wwrite-strings",
- "-Woverloaded-virtual",
- "-Wno-sign-compare",
- "-Wno-error=unused-function",
- "-Wno-error=unused-variable",
-]
-
-LINK_OPTS = select({
- ":freebsd": [
- "-lpthread",
- "-lm",
- ],
- "//conditions:default": ["-lpthread"],
-})
-
-config_setting(
- name = "freebsd",
- values = {"cpu": "freebsd"},
-)
-
-cc_library(
- name = "protobuf_lite",
- srcs = [
- # AUTOGEN(protobuf_lite_srcs)
- "src/google/protobuf/arena.cc",
- "src/google/protobuf/arenastring.cc",
- "src/google/protobuf/extension_set.cc",
- "src/google/protobuf/generated_message_util.cc",
- "src/google/protobuf/io/coded_stream.cc",
- "src/google/protobuf/io/io_win32.cc",
- "src/google/protobuf/io/zero_copy_stream.cc",
- "src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
- "src/google/protobuf/message_lite.cc",
- "src/google/protobuf/repeated_field.cc",
- "src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc",
- "src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc",
- "src/google/protobuf/stubs/bytestream.cc",
- "src/google/protobuf/stubs/common.cc",
- "src/google/protobuf/stubs/int128.cc",
- "src/google/protobuf/stubs/once.cc",
- "src/google/protobuf/stubs/status.cc",
- "src/google/protobuf/stubs/statusor.cc",
- "src/google/protobuf/stubs/stringpiece.cc",
- "src/google/protobuf/stubs/stringprintf.cc",
- "src/google/protobuf/stubs/structurally_valid.cc",
- "src/google/protobuf/stubs/strutil.cc",
- "src/google/protobuf/stubs/time.cc",
- "src/google/protobuf/wire_format_lite.cc",
- ],
- hdrs = glob(["src/google/protobuf/**/*.h"]),
- copts = COPTS,
- includes = ["src/"],
- linkopts = LINK_OPTS,
- visibility = ["//visibility:public"],
-)
-
-cc_library(
- name = "protobuf",
- srcs = [
- # AUTOGEN(protobuf_srcs)
- "src/google/protobuf/any.cc",
- "src/google/protobuf/any.pb.cc",
- "src/google/protobuf/api.pb.cc",
- "src/google/protobuf/compiler/importer.cc",
- "src/google/protobuf/compiler/parser.cc",
- "src/google/protobuf/descriptor.cc",
- "src/google/protobuf/descriptor.pb.cc",
- "src/google/protobuf/descriptor_database.cc",
- "src/google/protobuf/duration.pb.cc",
- "src/google/protobuf/dynamic_message.cc",
- "src/google/protobuf/empty.pb.cc",
- "src/google/protobuf/extension_set_heavy.cc",
- "src/google/protobuf/field_mask.pb.cc",
- "src/google/protobuf/generated_message_reflection.cc",
- "src/google/protobuf/io/gzip_stream.cc",
- "src/google/protobuf/io/io_win32.cc",
- "src/google/protobuf/io/printer.cc",
- "src/google/protobuf/io/strtod.cc",
- "src/google/protobuf/io/tokenizer.cc",
- "src/google/protobuf/io/zero_copy_stream_impl.cc",
- "src/google/protobuf/map_field.cc",
- "src/google/protobuf/message.cc",
- "src/google/protobuf/reflection_ops.cc",
- "src/google/protobuf/service.cc",
- "src/google/protobuf/source_context.pb.cc",
- "src/google/protobuf/struct.pb.cc",
- "src/google/protobuf/stubs/mathlimits.cc",
- "src/google/protobuf/stubs/substitute.cc",
- "src/google/protobuf/text_format.cc",
- "src/google/protobuf/timestamp.pb.cc",
- "src/google/protobuf/type.pb.cc",
- "src/google/protobuf/unknown_field_set.cc",
- "src/google/protobuf/util/field_comparator.cc",
- "src/google/protobuf/util/field_mask_util.cc",
- "src/google/protobuf/util/internal/datapiece.cc",
- "src/google/protobuf/util/internal/default_value_objectwriter.cc",
- "src/google/protobuf/util/internal/error_listener.cc",
- "src/google/protobuf/util/internal/field_mask_utility.cc",
- "src/google/protobuf/util/internal/json_escaping.cc",
- "src/google/protobuf/util/internal/json_objectwriter.cc",
- "src/google/protobuf/util/internal/json_stream_parser.cc",
- "src/google/protobuf/util/internal/object_writer.cc",
- "src/google/protobuf/util/internal/proto_writer.cc",
- "src/google/protobuf/util/internal/protostream_objectsource.cc",
- "src/google/protobuf/util/internal/protostream_objectwriter.cc",
- "src/google/protobuf/util/internal/type_info.cc",
- "src/google/protobuf/util/internal/type_info_test_helper.cc",
- "src/google/protobuf/util/internal/utility.cc",
- "src/google/protobuf/util/json_util.cc",
- "src/google/protobuf/util/message_differencer.cc",
- "src/google/protobuf/util/time_util.cc",
- "src/google/protobuf/util/type_resolver_util.cc",
- "src/google/protobuf/wire_format.cc",
- "src/google/protobuf/wrappers.pb.cc",
- ],
- hdrs = glob(["src/**/*.h"]),
- copts = COPTS,
- includes = ["src/"],
- linkopts = LINK_OPTS,
- visibility = ["//visibility:public"],
- deps = [":protobuf_lite"],
-)
-
-cc_library(
- name = "protoc_lib",
- srcs = [
- # AUTOGEN(protoc_lib_srcs)
- "src/google/protobuf/compiler/code_generator.cc",
- "src/google/protobuf/compiler/command_line_interface.cc",
- "src/google/protobuf/compiler/cpp/cpp_enum.cc",
- "src/google/protobuf/compiler/cpp/cpp_enum_field.cc",
- "src/google/protobuf/compiler/cpp/cpp_extension.cc",
- "src/google/protobuf/compiler/cpp/cpp_field.cc",
- "src/google/protobuf/compiler/cpp/cpp_file.cc",
- "src/google/protobuf/compiler/cpp/cpp_generator.cc",
- "src/google/protobuf/compiler/cpp/cpp_helpers.cc",
- "src/google/protobuf/compiler/cpp/cpp_map_field.cc",
- "src/google/protobuf/compiler/cpp/cpp_message.cc",
- "src/google/protobuf/compiler/cpp/cpp_message_field.cc",
- "src/google/protobuf/compiler/cpp/cpp_primitive_field.cc",
- "src/google/protobuf/compiler/cpp/cpp_service.cc",
- "src/google/protobuf/compiler/cpp/cpp_string_field.cc",
- "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
- "src/google/protobuf/compiler/csharp/csharp_enum.cc",
- "src/google/protobuf/compiler/csharp/csharp_enum_field.cc",
- "src/google/protobuf/compiler/csharp/csharp_field_base.cc",
- "src/google/protobuf/compiler/csharp/csharp_generator.cc",
- "src/google/protobuf/compiler/csharp/csharp_helpers.cc",
- "src/google/protobuf/compiler/csharp/csharp_map_field.cc",
- "src/google/protobuf/compiler/csharp/csharp_message.cc",
- "src/google/protobuf/compiler/csharp/csharp_message_field.cc",
- "src/google/protobuf/compiler/csharp/csharp_primitive_field.cc",
- "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
- "src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc",
- "src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc",
- "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc",
- "src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc",
- "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
- "src/google/protobuf/compiler/java/java_context.cc",
- "src/google/protobuf/compiler/java/java_doc_comment.cc",
- "src/google/protobuf/compiler/java/java_enum.cc",
- "src/google/protobuf/compiler/java/java_enum_field.cc",
- "src/google/protobuf/compiler/java/java_enum_field_lite.cc",
- "src/google/protobuf/compiler/java/java_enum_lite.cc",
- "src/google/protobuf/compiler/java/java_extension.cc",
- "src/google/protobuf/compiler/java/java_extension_lite.cc",
- "src/google/protobuf/compiler/java/java_field.cc",
- "src/google/protobuf/compiler/java/java_file.cc",
- "src/google/protobuf/compiler/java/java_generator.cc",
- "src/google/protobuf/compiler/java/java_generator_factory.cc",
- "src/google/protobuf/compiler/java/java_helpers.cc",
- "src/google/protobuf/compiler/java/java_lazy_message_field.cc",
- "src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc",
- "src/google/protobuf/compiler/java/java_map_field.cc",
- "src/google/protobuf/compiler/java/java_map_field_lite.cc",
- "src/google/protobuf/compiler/java/java_message.cc",
- "src/google/protobuf/compiler/java/java_message_builder.cc",
- "src/google/protobuf/compiler/java/java_message_builder_lite.cc",
- "src/google/protobuf/compiler/java/java_message_field.cc",
- "src/google/protobuf/compiler/java/java_message_field_lite.cc",
- "src/google/protobuf/compiler/java/java_message_lite.cc",
- "src/google/protobuf/compiler/java/java_name_resolver.cc",
- "src/google/protobuf/compiler/java/java_primitive_field.cc",
- "src/google/protobuf/compiler/java/java_primitive_field_lite.cc",
- "src/google/protobuf/compiler/java/java_service.cc",
- "src/google/protobuf/compiler/java/java_shared_code_generator.cc",
- "src/google/protobuf/compiler/java/java_string_field.cc",
- "src/google/protobuf/compiler/java/java_string_field_lite.cc",
- "src/google/protobuf/compiler/javanano/javanano_enum.cc",
- "src/google/protobuf/compiler/javanano/javanano_enum_field.cc",
- "src/google/protobuf/compiler/javanano/javanano_extension.cc",
- "src/google/protobuf/compiler/javanano/javanano_field.cc",
- "src/google/protobuf/compiler/javanano/javanano_file.cc",
- "src/google/protobuf/compiler/javanano/javanano_generator.cc",
- "src/google/protobuf/compiler/javanano/javanano_helpers.cc",
- "src/google/protobuf/compiler/javanano/javanano_map_field.cc",
- "src/google/protobuf/compiler/javanano/javanano_message.cc",
- "src/google/protobuf/compiler/javanano/javanano_message_field.cc",
- "src/google/protobuf/compiler/javanano/javanano_primitive_field.cc",
- "src/google/protobuf/compiler/js/js_generator.cc",
- "src/google/protobuf/compiler/objectivec/objectivec_enum.cc",
- "src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc",
- "src/google/protobuf/compiler/objectivec/objectivec_extension.cc",
- "src/google/protobuf/compiler/objectivec/objectivec_field.cc",
- "src/google/protobuf/compiler/objectivec/objectivec_file.cc",
- "src/google/protobuf/compiler/objectivec/objectivec_generator.cc",
- "src/google/protobuf/compiler/objectivec/objectivec_helpers.cc",
- "src/google/protobuf/compiler/objectivec/objectivec_map_field.cc",
- "src/google/protobuf/compiler/objectivec/objectivec_message.cc",
- "src/google/protobuf/compiler/objectivec/objectivec_message_field.cc",
- "src/google/protobuf/compiler/objectivec/objectivec_oneof.cc",
- "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc",
- "src/google/protobuf/compiler/plugin.cc",
- "src/google/protobuf/compiler/plugin.pb.cc",
- "src/google/protobuf/compiler/python/python_generator.cc",
- "src/google/protobuf/compiler/ruby/ruby_generator.cc",
- "src/google/protobuf/compiler/subprocess.cc",
- "src/google/protobuf/compiler/zip_writer.cc",
- ],
- copts = COPTS,
- includes = ["src/"],
- linkopts = LINK_OPTS,
- visibility = ["//visibility:public"],
- deps = [":protobuf"],
-)
-
-proto_lang_toolchain(
- name = "java_toolchain",
- command_line = "--java_out=shared,immutable:$(OUT)",
- runtime = ":protobuf",
-)
-
-cc_binary(
- name = "protoc",
- srcs = ["src/google/protobuf/compiler/main.cc"],
- linkopts = LINK_OPTS,
- visibility = ["//visibility:public"],
- deps = [":protoc_lib"],
-)
diff --git a/third_party/protobuf/3.0.0/protobuf-java-3.0.0.jar b/third_party/protobuf/3.0.0/protobuf-java-3.0.0.jar
deleted file mode 100644
index 7f36b33432..0000000000
--- a/third_party/protobuf/3.0.0/protobuf-java-3.0.0.jar
+++ /dev/null
Binary files differ
diff --git a/third_party/protobuf/3.0.0/protobuf-java-util-3.0.0.jar b/third_party/protobuf/3.0.0/protobuf-java-util-3.0.0.jar
deleted file mode 100644
index 8136316640..0000000000
--- a/third_party/protobuf/3.0.0/protobuf-java-util-3.0.0.jar
+++ /dev/null
Binary files differ
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/zip_writer.h b/third_party/protobuf/3.0.0/src/google/protobuf/compiler/zip_writer.h
deleted file mode 100644
index 602e508e2d..0000000000
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/zip_writer.h
+++ /dev/null
@@ -1,93 +0,0 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// 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.
-
-// Author: kenton@google.com (Kenton Varda)
-
-#include <vector>
-#include <google/protobuf/stubs/common.h>
-#include <google/protobuf/io/zero_copy_stream.h>
-
-namespace google {
-namespace protobuf {
-namespace compiler {
-
-class ZipWriter {
- public:
- ZipWriter(io::ZeroCopyOutputStream* raw_output);
- ~ZipWriter();
-
- bool Write(const string& filename, const string& contents);
- bool WriteDirectory();
-
- private:
- struct FileInfo {
- string name;
- uint32 offset;
- uint32 size;
- uint32 crc32;
- };
-
- io::ZeroCopyOutputStream* raw_output_;
- vector<FileInfo> files_;
-};
-
-} // namespace compiler
-} // namespace protobuf
-} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/io_win32.cc b/third_party/protobuf/3.0.0/src/google/protobuf/io/io_win32.cc
deleted file mode 100644
index d30bcf0bfe..0000000000
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/io_win32.cc
+++ /dev/null
@@ -1,159 +0,0 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// Author: laszlocsomor@google.com (Laszlo Csomor)
-//
-// Implementation for long-path-aware open/mkdir/access on Windows.
-//
-// These functions convert the input path to an absolute Windows path
-// with UNC prefix if necessary, then pass that to
-// _wopen/_wmkdir/_waccess (declared in <io.h>) respectively. This
-// allows working with files/directories whose paths is longer than
-// MAX_PATH (260 chars).
-//
-// This file is only used on Windows, it's empty on other platforms.
-
-#if defined(_WIN32)
-
-#include <Windows.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <io.h>
-
-#include <string>
-#include <memory>
-
-#include <google/protobuf/io/io_win32.h>
-
-namespace google {
-namespace protobuf {
-namespace io {
-namespace win32 {
-
-template <typename char_type>
-static bool has_unc_prefix(const std::basic_string<char_type>& path) {
- return path.size() > 4 && path[0] == '\\' && path[1] == '\\' &&
- path[2] == '?' && path[3] == '\\';
-}
-
-template <typename char_type>
-static bool is_path_absolute(const std::basic_string<char_type>& path) {
- return (path.size() > 2 && path[1] == ':') || has_unc_prefix(path);
-}
-
-template <typename char_type>
-static bool is_separator(char_type c) {
- return c == '/' || c == '\\';
-}
-
-static void replace_directory_separators(WCHAR* p) {
- for (; *p != L'\0'; ++p) {
- if (*p == L'/') {
- *p = L'\\';
- }
- }
-}
-
-static std::wstring get_cwd() {
- DWORD result = ::GetCurrentDirectoryW(0, NULL);
- std::unique_ptr<WCHAR[]> cwd(new WCHAR[result]);
- ::GetCurrentDirectoryW(result, cwd.get());
- cwd.get()[result - 1] = 0;
- replace_directory_separators(cwd.get());
- return std::move(std::wstring(cwd.get()));
-}
-
-static std::wstring join_paths(const std::wstring& path1,
- const std::wstring& path2) {
- if (path1.empty() || is_path_absolute(path2)) {
- return path2;
- }
- if (path2.empty()) {
- return path1;
- }
-
- if (is_separator(path1.back())) {
- return is_separator(path2.front())
- ? (path1 + path2.substr(1))
- : (path1 + path2);
- } else {
- return is_separator(path2.front())
- ? (path1 + path2)
- : (path1 + L'\\' + path2);
- }
-}
-
-static std::wstring as_wchar_path(const std::string& path) {
- int len = ::MultiByteToWideChar(CP_UTF8, 0, path.c_str(), path.size(),
- NULL, 0);
- std::unique_ptr<WCHAR[]> wbuf(new WCHAR[len + 1]);
- ::MultiByteToWideChar(CP_UTF8, 0, path.c_str(), path.size(),
- wbuf.get(), len + 1);
- wbuf.get()[len] = 0;
- replace_directory_separators(wbuf.get());
- return std::move(std::wstring(wbuf.get()));
-}
-
-static std::wstring as_windows_path(const std::string& path,
- size_t max_path) {
- std::wstring wpath(as_wchar_path(path));
- if (!is_path_absolute(path)) {
- wpath = join_paths(get_cwd(), wpath);
- }
- if (wpath.size() >= max_path && !has_unc_prefix(wpath)) {
- wpath = std::wstring(L"\\\\?\\") + wpath;
- }
- return wpath;
-}
-
-int open(const char* path, int flags, int mode) {
- return ::_wopen(as_windows_path(path, MAX_PATH).c_str(), flags, mode);
-}
-
-int mkdir(const char* name, int _mode) {
- // CreateDirectoryA's limit is 248 chars, see MSDN.
- // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx
- // This limit presumably includes the null-terminator, because other
- // functions that have the MAX_PATH limit, such as CreateFileA,
- // actually include it.
- return ::_wmkdir(as_windows_path(name, 248).c_str());
-}
-
-int access(const char* pathname, int mode) {
- return ::_waccess(as_windows_path(pathname, MAX_PATH).c_str(), mode);
-}
-
-} // namespace win32
-} // namespace io
-} // namespace protobuf
-} // namespace google
-
-#endif // defined(_WIN32)
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_macosx.h b/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_macosx.h
deleted file mode 100644
index 796332417f..0000000000
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_macosx.h
+++ /dev/null
@@ -1,225 +0,0 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2012 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.
-
-// This file is an internal atomic implementation, use atomicops.h instead.
-
-#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_MACOSX_H_
-#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_MACOSX_H_
-
-#include <libkern/OSAtomic.h>
-
-namespace google {
-namespace protobuf {
-namespace internal {
-
-inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
- Atomic32 old_value,
- Atomic32 new_value) {
- Atomic32 prev_value;
- do {
- if (OSAtomicCompareAndSwap32(old_value, new_value,
- const_cast<Atomic32*>(ptr))) {
- return old_value;
- }
- prev_value = *ptr;
- } while (prev_value == old_value);
- return prev_value;
-}
-
-inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr,
- Atomic32 new_value) {
- Atomic32 old_value;
- do {
- old_value = *ptr;
- } while (!OSAtomicCompareAndSwap32(old_value, new_value,
- const_cast<Atomic32*>(ptr)));
- return old_value;
-}
-
-inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
- Atomic32 increment) {
- return OSAtomicAdd32(increment, const_cast<Atomic32*>(ptr));
-}
-
-inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
- Atomic32 increment) {
- return OSAtomicAdd32Barrier(increment, const_cast<Atomic32*>(ptr));
-}
-
-inline void MemoryBarrier() {
- OSMemoryBarrier();
-}
-
-inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
- Atomic32 old_value,
- Atomic32 new_value) {
- Atomic32 prev_value;
- do {
- if (OSAtomicCompareAndSwap32Barrier(old_value, new_value,
- const_cast<Atomic32*>(ptr))) {
- return old_value;
- }
- prev_value = *ptr;
- } while (prev_value == old_value);
- return prev_value;
-}
-
-inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
- Atomic32 old_value,
- Atomic32 new_value) {
- return Acquire_CompareAndSwap(ptr, old_value, new_value);
-}
-
-inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
- *ptr = value;
-}
-
-inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
- *ptr = value;
- MemoryBarrier();
-}
-
-inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
- MemoryBarrier();
- *ptr = value;
-}
-
-inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
- return *ptr;
-}
-
-inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
- Atomic32 value = *ptr;
- MemoryBarrier();
- return value;
-}
-
-inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
- MemoryBarrier();
- return *ptr;
-}
-
-#ifdef __LP64__
-
-// 64-bit implementation on 64-bit platform
-
-inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
- Atomic64 old_value,
- Atomic64 new_value) {
- Atomic64 prev_value;
- do {
- if (OSAtomicCompareAndSwap64(old_value, new_value,
- reinterpret_cast<volatile int64_t*>(ptr))) {
- return old_value;
- }
- prev_value = *ptr;
- } while (prev_value == old_value);
- return prev_value;
-}
-
-inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr,
- Atomic64 new_value) {
- Atomic64 old_value;
- do {
- old_value = *ptr;
- } while (!OSAtomicCompareAndSwap64(old_value, new_value,
- reinterpret_cast<volatile int64_t*>(ptr)));
- return old_value;
-}
-
-inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr,
- Atomic64 increment) {
- return OSAtomicAdd64(increment, reinterpret_cast<volatile int64_t*>(ptr));
-}
-
-inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
- Atomic64 increment) {
- return OSAtomicAdd64Barrier(increment,
- reinterpret_cast<volatile int64_t*>(ptr));
-}
-
-inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
- Atomic64 old_value,
- Atomic64 new_value) {
- Atomic64 prev_value;
- do {
- if (OSAtomicCompareAndSwap64Barrier(
- old_value, new_value, reinterpret_cast<volatile int64_t*>(ptr))) {
- return old_value;
- }
- prev_value = *ptr;
- } while (prev_value == old_value);
- return prev_value;
-}
-
-inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
- Atomic64 old_value,
- Atomic64 new_value) {
- // The lib kern interface does not distinguish between
- // Acquire and Release memory barriers; they are equivalent.
- return Acquire_CompareAndSwap(ptr, old_value, new_value);
-}
-
-inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
- *ptr = value;
-}
-
-inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
- *ptr = value;
- MemoryBarrier();
-}
-
-inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
- MemoryBarrier();
- *ptr = value;
-}
-
-inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
- return *ptr;
-}
-
-inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
- Atomic64 value = *ptr;
- MemoryBarrier();
- return value;
-}
-
-inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
- MemoryBarrier();
- return *ptr;
-}
-
-#endif // defined(__LP64__)
-
-} // namespace internal
-} // namespace protobuf
-} // namespace google
-
-#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_MACOSX_H_
diff --git a/third_party/protobuf/BUILD b/third_party/protobuf/BUILD
index 60845b08a6..9fd91cb440 100644
--- a/third_party/protobuf/BUILD
+++ b/third_party/protobuf/BUILD
@@ -1,31 +1,834 @@
-package(default_visibility = ["//visibility:public"])
+# Bazel (http://bazel.io/) BUILD file for Protobuf.
licenses(["notice"])
-load(":proto_alias.bzl", "proto_alias")
+exports_files(["LICENSE"])
-PROTOBUF_VERSION = "3.0.0"
+################################################################################
+# Modifications made by bazel
+################################################################################
+
+load(":protobuf.bzl", "py_proto_library")
filegroup(
name = "srcs",
+ srcs = glob(
+ [
+ "**",
+ "protobuf.bzl",
+ "python/google/protobuf/**/*.py",
+ "src/google/protobuf/**/*.proto",
+ ],
+ ),
+ visibility = ["//visibility:public"],
+)
+
+java_import(
+ name = "protobuf_java_util",
+ jars = ["protobuf-java-util-3.2.0.jar"],
+ exports = [
+ "//third_party:gson",
+ ],
+ visibility = ["//visibility:public"],
+)
+
+java_import(
+ name = "protobuf_java",
+ jars = ["protobuf-java-3.2.0.jar"],
+ visibility = ["//visibility:public"],
+)
+
+# For bootstrapping JavaBuilder
+filegroup(
+ name = "protobuf-jars",
+ srcs = ["protobuf-java-3.2.0.jar"],
+ visibility = ["//visibility:public"],
+)
+
+################################################################################
+# The below build rules are a copy of the upstream protobuf BUILD file with
+# Java support removed.
+################################################################################
+
+################################################################################
+# Protobuf Runtime Library
+################################################################################
+
+COPTS = [
+ "-DHAVE_PTHREAD",
+ "-Wall",
+ "-Wwrite-strings",
+ "-Woverloaded-virtual",
+ "-Wno-sign-compare",
+ "-Wno-unused-function",
+]
+
+config_setting(
+ name = "android",
+ values = {
+ "crosstool_top": "//external:android/crosstool",
+ },
+)
+
+# Android builds do not need to link in a separate pthread library.
+LINK_OPTS = select({
+ ":android": [],
+ "//conditions:default": ["-lpthread", "-lm"],
+})
+
+load(
+ ":protobuf.bzl",
+ "cc_proto_library",
+ "py_proto_library",
+ "internal_copied_filegroup",
+ "internal_gen_well_known_protos_java",
+ "internal_protobuf_py_tests",
+)
+
+config_setting(
+ name = "ios_armv7",
+ values = {
+ "ios_cpu": "armv7",
+ },
+)
+
+config_setting(
+ name = "ios_armv7s",
+ values = {
+ "ios_cpu": "armv7s",
+ },
+)
+
+config_setting(
+ name = "ios_arm64",
+ values = {
+ "ios_cpu": "arm64",
+ },
+)
+
+IOS_ARM_COPTS = COPTS + [
+ "-DOS_IOS",
+ "-miphoneos-version-min=7.0",
+ "-arch armv7",
+ "-arch armv7s",
+ "-arch arm64",
+ "-D__thread=",
+ "-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.2.sdk/",
+]
+
+cc_library(
+ name = "protobuf_lite",
+ srcs = [
+ # AUTOGEN(protobuf_lite_srcs)
+ "src/google/protobuf/arena.cc",
+ "src/google/protobuf/arenastring.cc",
+ "src/google/protobuf/extension_set.cc",
+ "src/google/protobuf/generated_message_util.cc",
+ "src/google/protobuf/io/coded_stream.cc",
+ "src/google/protobuf/io/zero_copy_stream.cc",
+ "src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
+ "src/google/protobuf/message_lite.cc",
+ "src/google/protobuf/repeated_field.cc",
+ "src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc",
+ "src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc",
+ "src/google/protobuf/stubs/bytestream.cc",
+ "src/google/protobuf/stubs/common.cc",
+ "src/google/protobuf/stubs/int128.cc",
+ "src/google/protobuf/stubs/io_win32.cc",
+ "src/google/protobuf/stubs/once.cc",
+ "src/google/protobuf/stubs/status.cc",
+ "src/google/protobuf/stubs/statusor.cc",
+ "src/google/protobuf/stubs/stringpiece.cc",
+ "src/google/protobuf/stubs/stringprintf.cc",
+ "src/google/protobuf/stubs/structurally_valid.cc",
+ "src/google/protobuf/stubs/strutil.cc",
+ "src/google/protobuf/stubs/time.cc",
+ "src/google/protobuf/wire_format_lite.cc",
+ ],
+ hdrs = glob(["src/google/protobuf/**/*.h"]),
+ copts = select({
+ ":ios_armv7": IOS_ARM_COPTS,
+ ":ios_armv7s": IOS_ARM_COPTS,
+ ":ios_arm64": IOS_ARM_COPTS,
+ "//conditions:default": COPTS,
+ }),
+ includes = ["src/"],
+ linkopts = LINK_OPTS,
+ visibility = ["//visibility:public"],
+)
+
+cc_library(
+ name = "protobuf",
srcs = [
- "//third_party/protobuf/" + PROTOBUF_VERSION + ":srcs",
- ] + glob(["**"]), # glob everything to satisfy the compile.sh srcs test
- visibility = ["//third_party:__pkg__"],
+ # AUTOGEN(protobuf_srcs)
+ "src/google/protobuf/any.cc",
+ "src/google/protobuf/any.pb.cc",
+ "src/google/protobuf/api.pb.cc",
+ "src/google/protobuf/compiler/importer.cc",
+ "src/google/protobuf/compiler/parser.cc",
+ "src/google/protobuf/descriptor.cc",
+ "src/google/protobuf/descriptor.pb.cc",
+ "src/google/protobuf/descriptor_database.cc",
+ "src/google/protobuf/duration.pb.cc",
+ "src/google/protobuf/dynamic_message.cc",
+ "src/google/protobuf/empty.pb.cc",
+ "src/google/protobuf/extension_set_heavy.cc",
+ "src/google/protobuf/field_mask.pb.cc",
+ "src/google/protobuf/generated_message_reflection.cc",
+ "src/google/protobuf/io/gzip_stream.cc",
+ "src/google/protobuf/io/printer.cc",
+ "src/google/protobuf/io/strtod.cc",
+ "src/google/protobuf/io/tokenizer.cc",
+ "src/google/protobuf/io/zero_copy_stream_impl.cc",
+ "src/google/protobuf/map_field.cc",
+ "src/google/protobuf/message.cc",
+ "src/google/protobuf/reflection_ops.cc",
+ "src/google/protobuf/service.cc",
+ "src/google/protobuf/source_context.pb.cc",
+ "src/google/protobuf/struct.pb.cc",
+ "src/google/protobuf/stubs/io_win32.cc",
+ "src/google/protobuf/stubs/mathlimits.cc",
+ "src/google/protobuf/stubs/substitute.cc",
+ "src/google/protobuf/text_format.cc",
+ "src/google/protobuf/timestamp.pb.cc",
+ "src/google/protobuf/type.pb.cc",
+ "src/google/protobuf/unknown_field_set.cc",
+ "src/google/protobuf/util/delimited_message_util.cc",
+ "src/google/protobuf/util/field_comparator.cc",
+ "src/google/protobuf/util/field_mask_util.cc",
+ "src/google/protobuf/util/internal/datapiece.cc",
+ "src/google/protobuf/util/internal/default_value_objectwriter.cc",
+ "src/google/protobuf/util/internal/error_listener.cc",
+ "src/google/protobuf/util/internal/field_mask_utility.cc",
+ "src/google/protobuf/util/internal/json_escaping.cc",
+ "src/google/protobuf/util/internal/json_objectwriter.cc",
+ "src/google/protobuf/util/internal/json_stream_parser.cc",
+ "src/google/protobuf/util/internal/object_writer.cc",
+ "src/google/protobuf/util/internal/proto_writer.cc",
+ "src/google/protobuf/util/internal/protostream_objectsource.cc",
+ "src/google/protobuf/util/internal/protostream_objectwriter.cc",
+ "src/google/protobuf/util/internal/type_info.cc",
+ "src/google/protobuf/util/internal/type_info_test_helper.cc",
+ "src/google/protobuf/util/internal/utility.cc",
+ "src/google/protobuf/util/json_util.cc",
+ "src/google/protobuf/util/message_differencer.cc",
+ "src/google/protobuf/util/time_util.cc",
+ "src/google/protobuf/util/type_resolver_util.cc",
+ "src/google/protobuf/wire_format.cc",
+ "src/google/protobuf/wrappers.pb.cc",
+ ],
+ hdrs = glob(["src/**/*.h"]),
+ copts = select({
+ ":ios_armv7": IOS_ARM_COPTS,
+ ":ios_armv7s": IOS_ARM_COPTS,
+ ":ios_arm64": IOS_ARM_COPTS,
+ "//conditions:default": COPTS,
+ }),
+ includes = ["src/"],
+ linkopts = LINK_OPTS,
+ visibility = ["//visibility:public"],
+ deps = [":protobuf_lite"],
+)
+
+# This provides just the header files for use in projects that need to build
+# shared libraries for dynamic loading. This target is available until Bazel
+# adds native support for such use cases.
+# TODO(keveman): Remove this target once the support gets added to Bazel.
+cc_library(
+ name = "protobuf_headers",
+ hdrs = glob(["src/**/*.h"]),
+ includes = ["src/"],
+ visibility = ["//visibility:public"],
+)
+
+objc_library(
+ name = "protobuf_objc",
+ hdrs = ["objectivec/GPBProtocolBuffers.h"],
+ includes = ["objectivec"],
+ non_arc_srcs = ["objectivec/GPBProtocolBuffers.m"],
+ visibility = ["//visibility:public"],
)
-proto_alias("protoc", PROTOBUF_VERSION)
+RELATIVE_WELL_KNOWN_PROTOS = [
+ # AUTOGEN(well_known_protos)
+ "google/protobuf/any.proto",
+ "google/protobuf/api.proto",
+ "google/protobuf/compiler/plugin.proto",
+ "google/protobuf/descriptor.proto",
+ "google/protobuf/duration.proto",
+ "google/protobuf/empty.proto",
+ "google/protobuf/field_mask.proto",
+ "google/protobuf/source_context.proto",
+ "google/protobuf/struct.proto",
+ "google/protobuf/timestamp.proto",
+ "google/protobuf/type.proto",
+ "google/protobuf/wrappers.proto",
+]
-proto_alias("protobuf_java", PROTOBUF_VERSION)
+WELL_KNOWN_PROTOS = ["src/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]
-proto_alias("protobuf-jars", PROTOBUF_VERSION)
+filegroup(
+ name = "well_known_protos",
+ srcs = WELL_KNOWN_PROTOS,
+ visibility = ["//visibility:public"],
+)
-proto_alias("protobuf_java_util", PROTOBUF_VERSION)
+cc_proto_library(
+ name = "cc_wkt_protos",
+ srcs = WELL_KNOWN_PROTOS,
+ include = "src",
+ default_runtime = ":protobuf",
+ internal_bootstrap_hack = 1,
+ protoc = ":protoc",
+ visibility = ["//visibility:public"],
+)
+
+################################################################################
+# Protocol Buffers Compiler
+################################################################################
+
+cc_binary(
+ name = "js_embed",
+ srcs = ["src/google/protobuf/compiler/js/embed.cc"],
+ visibility = ["//visibility:public"],
+)
+
+genrule(
+ name = "generate_js_well_known_types_embed",
+ srcs = [
+ "src/google/protobuf/compiler/js/well_known_types/any.js",
+ "src/google/protobuf/compiler/js/well_known_types/struct.js",
+ "src/google/protobuf/compiler/js/well_known_types/timestamp.js",
+ ],
+ outs = ["src/google/protobuf/compiler/js/well_known_types_embed.cc"],
+ cmd = "$(location :js_embed) $(SRCS) > $@",
+ tools = [":js_embed"],
+)
+
+cc_library(
+ name = "protoc_lib",
+ srcs = [
+ # AUTOGEN(protoc_lib_srcs)
+ "src/google/protobuf/compiler/code_generator.cc",
+ "src/google/protobuf/compiler/command_line_interface.cc",
+ "src/google/protobuf/compiler/cpp/cpp_enum.cc",
+ "src/google/protobuf/compiler/cpp/cpp_enum_field.cc",
+ "src/google/protobuf/compiler/cpp/cpp_extension.cc",
+ "src/google/protobuf/compiler/cpp/cpp_field.cc",
+ "src/google/protobuf/compiler/cpp/cpp_file.cc",
+ "src/google/protobuf/compiler/cpp/cpp_generator.cc",
+ "src/google/protobuf/compiler/cpp/cpp_helpers.cc",
+ "src/google/protobuf/compiler/cpp/cpp_map_field.cc",
+ "src/google/protobuf/compiler/cpp/cpp_message.cc",
+ "src/google/protobuf/compiler/cpp/cpp_message_field.cc",
+ "src/google/protobuf/compiler/cpp/cpp_primitive_field.cc",
+ "src/google/protobuf/compiler/cpp/cpp_service.cc",
+ "src/google/protobuf/compiler/cpp/cpp_string_field.cc",
+ "src/google/protobuf/compiler/csharp/csharp_doc_comment.cc",
+ "src/google/protobuf/compiler/csharp/csharp_enum.cc",
+ "src/google/protobuf/compiler/csharp/csharp_enum_field.cc",
+ "src/google/protobuf/compiler/csharp/csharp_field_base.cc",
+ "src/google/protobuf/compiler/csharp/csharp_generator.cc",
+ "src/google/protobuf/compiler/csharp/csharp_helpers.cc",
+ "src/google/protobuf/compiler/csharp/csharp_map_field.cc",
+ "src/google/protobuf/compiler/csharp/csharp_message.cc",
+ "src/google/protobuf/compiler/csharp/csharp_message_field.cc",
+ "src/google/protobuf/compiler/csharp/csharp_primitive_field.cc",
+ "src/google/protobuf/compiler/csharp/csharp_reflection_class.cc",
+ "src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc",
+ "src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc",
+ "src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc",
+ "src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc",
+ "src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc",
+ "src/google/protobuf/compiler/java/java_context.cc",
+ "src/google/protobuf/compiler/java/java_doc_comment.cc",
+ "src/google/protobuf/compiler/java/java_enum.cc",
+ "src/google/protobuf/compiler/java/java_enum_field.cc",
+ "src/google/protobuf/compiler/java/java_enum_field_lite.cc",
+ "src/google/protobuf/compiler/java/java_enum_lite.cc",
+ "src/google/protobuf/compiler/java/java_extension.cc",
+ "src/google/protobuf/compiler/java/java_extension_lite.cc",
+ "src/google/protobuf/compiler/java/java_field.cc",
+ "src/google/protobuf/compiler/java/java_file.cc",
+ "src/google/protobuf/compiler/java/java_generator.cc",
+ "src/google/protobuf/compiler/java/java_generator_factory.cc",
+ "src/google/protobuf/compiler/java/java_helpers.cc",
+ "src/google/protobuf/compiler/java/java_lazy_message_field.cc",
+ "src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc",
+ "src/google/protobuf/compiler/java/java_map_field.cc",
+ "src/google/protobuf/compiler/java/java_map_field_lite.cc",
+ "src/google/protobuf/compiler/java/java_message.cc",
+ "src/google/protobuf/compiler/java/java_message_builder.cc",
+ "src/google/protobuf/compiler/java/java_message_builder_lite.cc",
+ "src/google/protobuf/compiler/java/java_message_field.cc",
+ "src/google/protobuf/compiler/java/java_message_field_lite.cc",
+ "src/google/protobuf/compiler/java/java_message_lite.cc",
+ "src/google/protobuf/compiler/java/java_name_resolver.cc",
+ "src/google/protobuf/compiler/java/java_primitive_field.cc",
+ "src/google/protobuf/compiler/java/java_primitive_field_lite.cc",
+ "src/google/protobuf/compiler/java/java_service.cc",
+ "src/google/protobuf/compiler/java/java_shared_code_generator.cc",
+ "src/google/protobuf/compiler/java/java_string_field.cc",
+ "src/google/protobuf/compiler/java/java_string_field_lite.cc",
+ "src/google/protobuf/compiler/javanano/javanano_enum.cc",
+ "src/google/protobuf/compiler/javanano/javanano_enum_field.cc",
+ "src/google/protobuf/compiler/javanano/javanano_extension.cc",
+ "src/google/protobuf/compiler/javanano/javanano_field.cc",
+ "src/google/protobuf/compiler/javanano/javanano_file.cc",
+ "src/google/protobuf/compiler/javanano/javanano_generator.cc",
+ "src/google/protobuf/compiler/javanano/javanano_helpers.cc",
+ "src/google/protobuf/compiler/javanano/javanano_map_field.cc",
+ "src/google/protobuf/compiler/javanano/javanano_message.cc",
+ "src/google/protobuf/compiler/javanano/javanano_message_field.cc",
+ "src/google/protobuf/compiler/javanano/javanano_primitive_field.cc",
+ "src/google/protobuf/compiler/js/js_generator.cc",
+ "src/google/protobuf/compiler/js/well_known_types_embed.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_enum.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_extension.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_field.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_file.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_generator.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_helpers.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_map_field.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_message.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_message_field.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_oneof.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc",
+ "src/google/protobuf/compiler/php/php_generator.cc",
+ "src/google/protobuf/compiler/plugin.cc",
+ "src/google/protobuf/compiler/plugin.pb.cc",
+ "src/google/protobuf/compiler/python/python_generator.cc",
+ "src/google/protobuf/compiler/ruby/ruby_generator.cc",
+ "src/google/protobuf/compiler/subprocess.cc",
+ "src/google/protobuf/compiler/zip_writer.cc",
+ ],
+ copts = COPTS,
+ includes = ["src/"],
+ linkopts = LINK_OPTS,
+ visibility = ["//visibility:public"],
+ deps = [":protobuf"],
+)
+
+cc_binary(
+ name = "protoc",
+ srcs = ["src/google/protobuf/compiler/main.cc"],
+ linkopts = LINK_OPTS,
+ visibility = ["//visibility:public"],
+ deps = [":protoc_lib"],
+)
-proto_alias("protobuf_python", PROTOBUF_VERSION)
+################################################################################
+# Tests
+################################################################################
-proto_alias("protobuf", PROTOBUF_VERSION)
+RELATIVE_LITE_TEST_PROTOS = [
+ # AUTOGEN(lite_test_protos)
+ "google/protobuf/map_lite_unittest.proto",
+ "google/protobuf/unittest_import_lite.proto",
+ "google/protobuf/unittest_import_public_lite.proto",
+ "google/protobuf/unittest_lite.proto",
+ "google/protobuf/unittest_no_arena_lite.proto",
+]
-proto_alias("protoc_lib", PROTOBUF_VERSION)
+LITE_TEST_PROTOS = ["src/" + s for s in RELATIVE_LITE_TEST_PROTOS]
-proto_alias("java_toolchain", PROTOBUF_VERSION)
+RELATIVE_TEST_PROTOS = [
+ # AUTOGEN(test_protos)
+ "google/protobuf/any_test.proto",
+ "google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto",
+ "google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto",
+ "google/protobuf/map_proto2_unittest.proto",
+ "google/protobuf/map_unittest.proto",
+ "google/protobuf/unittest.proto",
+ "google/protobuf/unittest_arena.proto",
+ "google/protobuf/unittest_custom_options.proto",
+ "google/protobuf/unittest_drop_unknown_fields.proto",
+ "google/protobuf/unittest_embed_optimize_for.proto",
+ "google/protobuf/unittest_empty.proto",
+ "google/protobuf/unittest_enormous_descriptor.proto",
+ "google/protobuf/unittest_import.proto",
+ "google/protobuf/unittest_import_public.proto",
+ "google/protobuf/unittest_lite_imports_nonlite.proto",
+ "google/protobuf/unittest_mset.proto",
+ "google/protobuf/unittest_mset_wire_format.proto",
+ "google/protobuf/unittest_no_arena.proto",
+ "google/protobuf/unittest_no_arena_import.proto",
+ "google/protobuf/unittest_no_field_presence.proto",
+ "google/protobuf/unittest_no_generic_services.proto",
+ "google/protobuf/unittest_optimize_for.proto",
+ "google/protobuf/unittest_preserve_unknown_enum.proto",
+ "google/protobuf/unittest_preserve_unknown_enum2.proto",
+ "google/protobuf/unittest_proto3_arena.proto",
+ "google/protobuf/unittest_proto3_arena_lite.proto",
+ "google/protobuf/unittest_proto3_lite.proto",
+ "google/protobuf/unittest_well_known_types.proto",
+ "google/protobuf/util/internal/testdata/anys.proto",
+ "google/protobuf/util/internal/testdata/books.proto",
+ "google/protobuf/util/internal/testdata/default_value.proto",
+ "google/protobuf/util/internal/testdata/default_value_test.proto",
+ "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",
+]
+
+TEST_PROTOS = ["src/" + s for s in RELATIVE_TEST_PROTOS]
+
+cc_proto_library(
+ name = "cc_test_protos",
+ srcs = LITE_TEST_PROTOS + TEST_PROTOS,
+ include = "src",
+ default_runtime = ":protobuf",
+ protoc = ":protoc",
+ deps = [":cc_wkt_protos"],
+)
+
+COMMON_TEST_SRCS = [
+ # AUTOGEN(common_test_srcs)
+ "src/google/protobuf/arena_test_util.cc",
+ "src/google/protobuf/map_test_util.cc",
+ "src/google/protobuf/test_util.cc",
+ "src/google/protobuf/testing/file.cc",
+ "src/google/protobuf/testing/googletest.cc",
+]
+
+cc_binary(
+ name = "test_plugin",
+ srcs = [
+ # AUTOGEN(test_plugin_srcs)
+ "src/google/protobuf/compiler/mock_code_generator.cc",
+ "src/google/protobuf/compiler/test_plugin.cc",
+ "src/google/protobuf/testing/file.cc",
+ ],
+ deps = [
+ ":protobuf",
+ ":protoc_lib",
+ "//external:gtest",
+ ],
+)
+
+cc_test(
+ name = "win32_test",
+ srcs = ["src/google/protobuf/stubs/io_win32_unittest.cc"],
+ deps = [
+ ":protobuf_lite",
+ "//external:gtest_main",
+ ],
+ tags = ["manual", "windows"],
+)
+
+cc_test(
+ name = "protobuf_test",
+ srcs = COMMON_TEST_SRCS + [
+ # AUTOGEN(test_srcs)
+ "src/google/protobuf/any_test.cc",
+ "src/google/protobuf/arena_unittest.cc",
+ "src/google/protobuf/arenastring_unittest.cc",
+ "src/google/protobuf/compiler/command_line_interface_unittest.cc",
+ "src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc",
+ "src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc",
+ "src/google/protobuf/compiler/cpp/cpp_unittest.cc",
+ "src/google/protobuf/compiler/cpp/metadata_test.cc",
+ "src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc",
+ "src/google/protobuf/compiler/importer_unittest.cc",
+ "src/google/protobuf/compiler/java/java_doc_comment_unittest.cc",
+ "src/google/protobuf/compiler/java/java_plugin_unittest.cc",
+ "src/google/protobuf/compiler/mock_code_generator.cc",
+ "src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc",
+ "src/google/protobuf/compiler/parser_unittest.cc",
+ "src/google/protobuf/compiler/python/python_plugin_unittest.cc",
+ "src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc",
+ "src/google/protobuf/descriptor_database_unittest.cc",
+ "src/google/protobuf/descriptor_unittest.cc",
+ "src/google/protobuf/drop_unknown_fields_test.cc",
+ "src/google/protobuf/dynamic_message_unittest.cc",
+ "src/google/protobuf/extension_set_unittest.cc",
+ "src/google/protobuf/generated_message_reflection_unittest.cc",
+ "src/google/protobuf/io/coded_stream_unittest.cc",
+ "src/google/protobuf/io/printer_unittest.cc",
+ "src/google/protobuf/io/tokenizer_unittest.cc",
+ "src/google/protobuf/io/zero_copy_stream_unittest.cc",
+ "src/google/protobuf/map_field_test.cc",
+ "src/google/protobuf/map_test.cc",
+ "src/google/protobuf/message_unittest.cc",
+ "src/google/protobuf/no_field_presence_test.cc",
+ "src/google/protobuf/preserve_unknown_enum_test.cc",
+ "src/google/protobuf/proto3_arena_lite_unittest.cc",
+ "src/google/protobuf/proto3_arena_unittest.cc",
+ "src/google/protobuf/proto3_lite_unittest.cc",
+ "src/google/protobuf/reflection_ops_unittest.cc",
+ "src/google/protobuf/repeated_field_reflection_unittest.cc",
+ "src/google/protobuf/repeated_field_unittest.cc",
+ "src/google/protobuf/stubs/bytestream_unittest.cc",
+ "src/google/protobuf/stubs/common_unittest.cc",
+ "src/google/protobuf/stubs/int128_unittest.cc",
+ "src/google/protobuf/stubs/io_win32_unittest.cc",
+ "src/google/protobuf/stubs/once_unittest.cc",
+ "src/google/protobuf/stubs/status_test.cc",
+ "src/google/protobuf/stubs/statusor_test.cc",
+ "src/google/protobuf/stubs/stringpiece_unittest.cc",
+ "src/google/protobuf/stubs/stringprintf_unittest.cc",
+ "src/google/protobuf/stubs/structurally_valid_unittest.cc",
+ "src/google/protobuf/stubs/strutil_unittest.cc",
+ "src/google/protobuf/stubs/template_util_unittest.cc",
+ "src/google/protobuf/stubs/time_test.cc",
+ "src/google/protobuf/stubs/type_traits_unittest.cc",
+ "src/google/protobuf/text_format_unittest.cc",
+ "src/google/protobuf/unknown_field_set_unittest.cc",
+ "src/google/protobuf/util/delimited_message_util_test.cc",
+ "src/google/protobuf/util/field_comparator_test.cc",
+ "src/google/protobuf/util/field_mask_util_test.cc",
+ "src/google/protobuf/util/internal/default_value_objectwriter_test.cc",
+ "src/google/protobuf/util/internal/json_objectwriter_test.cc",
+ "src/google/protobuf/util/internal/json_stream_parser_test.cc",
+ "src/google/protobuf/util/internal/protostream_objectsource_test.cc",
+ "src/google/protobuf/util/internal/protostream_objectwriter_test.cc",
+ "src/google/protobuf/util/internal/type_info_test_helper.cc",
+ "src/google/protobuf/util/json_util_test.cc",
+ "src/google/protobuf/util/message_differencer_unittest.cc",
+ "src/google/protobuf/util/time_util_test.cc",
+ "src/google/protobuf/util/type_resolver_util_test.cc",
+ "src/google/protobuf/well_known_types_unittest.cc",
+ "src/google/protobuf/wire_format_unittest.cc",
+ ],
+ copts = COPTS,
+ data = [
+ ":test_plugin",
+ ] + glob([
+ "src/google/protobuf/**/*",
+ ]),
+ includes = [
+ "src/",
+ ],
+ linkopts = LINK_OPTS,
+ deps = [
+ ":cc_test_protos",
+ ":protobuf",
+ ":protoc_lib",
+ "//external:gtest_main",
+ ],
+)
+
+################################################################################
+# Java support
+################################################################################
+internal_gen_well_known_protos_java(
+ srcs = WELL_KNOWN_PROTOS,
+)
+
+################################################################################
+# Python support
+################################################################################
+
+py_library(
+ name = "python_srcs",
+ srcs = glob(
+ [
+ "python/google/protobuf/*.py",
+ "python/google/protobuf/**/*.py",
+ ],
+ exclude = [
+ "python/google/protobuf/__init__.py",
+ "python/google/protobuf/**/__init__.py",
+ "python/google/protobuf/internal/*_test.py",
+ "python/google/protobuf/internal/test_util.py",
+ ],
+ ),
+ imports = ["python"],
+ srcs_version = "PY2AND3",
+)
+
+cc_binary(
+ name = "python/google/protobuf/internal/_api_implementation.so",
+ srcs = ["python/google/protobuf/internal/api_implementation.cc"],
+ copts = COPTS + [
+ "-DPYTHON_PROTO2_CPP_IMPL_V2",
+ ],
+ linkshared = 1,
+ linkstatic = 1,
+ deps = select({
+ "//conditions:default": [],
+ ":use_fast_cpp_protos": ["//external:python_headers"],
+ }),
+)
+
+cc_binary(
+ name = "python/google/protobuf/pyext/_message.so",
+ srcs = glob([
+ "python/google/protobuf/pyext/*.cc",
+ "python/google/protobuf/pyext/*.h",
+ ]),
+ copts = COPTS + [
+ "-DGOOGLE_PROTOBUF_HAS_ONEOF=1",
+ ] + select({
+ "//conditions:default": [],
+ ":allow_oversize_protos": ["-DPROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS=1"],
+ }),
+ includes = [
+ "python/",
+ "src/",
+ ],
+ linkshared = 1,
+ linkstatic = 1,
+ deps = [
+ ":protobuf",
+ ] + select({
+ "//conditions:default": [],
+ ":use_fast_cpp_protos": ["//external:python_headers"],
+ }),
+)
+
+config_setting(
+ name = "use_fast_cpp_protos",
+ values = {
+ "define": "use_fast_cpp_protos=true",
+ },
+)
+
+config_setting(
+ name = "allow_oversize_protos",
+ values = {
+ "define": "allow_oversize_protos=true",
+ },
+)
+
+# Copy the builtin proto files from src/google/protobuf to
+# python/google/protobuf. This way, the generated Python sources will be in the
+# same directory as the Python runtime sources. This is necessary for the
+# modules to be imported correctly since they are all part of the same Python
+# package.
+internal_copied_filegroup(
+ name = "protos_python",
+ srcs = WELL_KNOWN_PROTOS,
+ dest = "python",
+ strip_prefix = "src",
+)
+
+# TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
+# which case we can simply add :protos_python in srcs.
+COPIED_WELL_KNOWN_PROTOS = ["python/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]
+
+py_proto_library(
+ name = "protobuf_python",
+ srcs = COPIED_WELL_KNOWN_PROTOS,
+ include = "python",
+ data = select({
+ "//conditions:default": [],
+ ":use_fast_cpp_protos": [
+ ":python/google/protobuf/internal/_api_implementation.so",
+ ":python/google/protobuf/pyext/_message.so",
+ ],
+ }),
+ default_runtime = "",
+ protoc = ":protoc",
+ py_libs = [
+ ":python_srcs",
+ "//external:six",
+ ],
+ srcs_version = "PY2AND3",
+ visibility = ["//visibility:public"],
+)
+
+# Copy the test proto files from src/google/protobuf to
+# python/google/protobuf. This way, the generated Python sources will be in the
+# same directory as the Python runtime sources. This is necessary for the
+# modules to be imported correctly by the tests since they are all part of the
+# same Python package.
+internal_copied_filegroup(
+ name = "protos_python_test",
+ srcs = LITE_TEST_PROTOS + TEST_PROTOS,
+ dest = "python",
+ strip_prefix = "src",
+)
+
+# TODO(dzc): Remove this once py_proto_library can have labels in srcs, in
+# which case we can simply add :protos_python_test in srcs.
+COPIED_LITE_TEST_PROTOS = ["python/" + s for s in RELATIVE_LITE_TEST_PROTOS]
+
+COPIED_TEST_PROTOS = ["python/" + s for s in RELATIVE_TEST_PROTOS]
+
+py_proto_library(
+ name = "python_common_test_protos",
+ srcs = COPIED_LITE_TEST_PROTOS + COPIED_TEST_PROTOS,
+ include = "python",
+ default_runtime = "",
+ protoc = ":protoc",
+ srcs_version = "PY2AND3",
+ deps = [":protobuf_python"],
+)
+
+py_proto_library(
+ name = "python_specific_test_protos",
+ srcs = glob([
+ "python/google/protobuf/internal/*.proto",
+ "python/google/protobuf/internal/import_test_package/*.proto",
+ ]),
+ include = "python",
+ default_runtime = ":protobuf_python",
+ protoc = ":protoc",
+ srcs_version = "PY2AND3",
+ deps = [":python_common_test_protos"],
+)
+
+py_library(
+ name = "python_tests",
+ srcs = glob(
+ [
+ "python/google/protobuf/internal/*_test.py",
+ "python/google/protobuf/internal/test_util.py",
+ "python/google/protobuf/internal/import_test_package/__init__.py",
+ ],
+ ),
+ imports = ["python"],
+ srcs_version = "PY2AND3",
+ deps = [
+ ":protobuf_python",
+ ":python_common_test_protos",
+ ":python_specific_test_protos",
+ ],
+)
+
+internal_protobuf_py_tests(
+ name = "python_tests_batch",
+ data = glob([
+ "src/google/protobuf/**/*",
+ ]),
+ modules = [
+ "descriptor_database_test",
+ "descriptor_pool_test",
+ "descriptor_test",
+ "generator_test",
+ "json_format_test",
+ "message_factory_test",
+ "message_test",
+ "proto_builder_test",
+ "reflection_test",
+ "service_reflection_test",
+ "symbol_database_test",
+ "text_encoding_test",
+ "text_format_test",
+ "unknown_fields_test",
+ "wire_format_test",
+ ],
+ deps = [":python_tests"],
+)
+
+proto_lang_toolchain(
+ name = "cc_toolchain",
+ command_line = "--cpp_out=$(OUT)",
+ runtime = ":protobuf",
+ visibility = ["//visibility:public"],
+)
+
+proto_lang_toolchain(
+ name = "java_toolchain",
+ command_line = "--java_out=$(OUT)",
+ runtime = ":protobuf_java",
+ visibility = ["//visibility:public"],
+)
diff --git a/third_party/protobuf/CHANGES.txt b/third_party/protobuf/CHANGES.txt
new file mode 100644
index 0000000000..1164583645
--- /dev/null
+++ b/third_party/protobuf/CHANGES.txt
@@ -0,0 +1,1486 @@
+2017-01-23 version 3.2.0 (C++/Java/Python/PHP/Ruby/Objective-C/C#/JavaScript/Lite)
+ General
+ * Added protoc version number to protoc plugin protocol. It can be used by
+ protoc plugin to detect which version of protoc is used with the plugin and
+ mitigate known problems in certain version of protoc.
+
+ C++
+ * The default parsing byte size limit has been raised from 64MB to 2GB.
+ * Added rvalue setters for non-arena string fields.
+ * Enabled debug logging for Android.
+ * Fixed a double-free problem when using Reflection::SetAllocatedMessage()
+ with extension fields.
+ * Fixed several deterministic serialization bugs:
+ * MessageLite::SerializeAsString() now respects the global deterministic
+ serialization flag.
+ * Extension fields are serialized deterministically as well. Fixed protocol
+ compiler to correctly report importing-self as an error.
+ * Fixed FileDescriptor::DebugString() to print custom options correctly.
+ * Various performance/codesize optimizations and cleanups.
+
+ Java
+ * The default parsing byte size limit has been raised from 64MB to 2GB.
+ * Added recursion limit when parsing JSON.
+ * Fixed a bug that enumType.getDescriptor().getOptions() doesn't have custom
+ options.
+ * Fixed generated code to support field numbers up to 2^29-1.
+
+ Python
+ * You can now assign NumPy scalars/arrays (np.int32, np.int64) to protobuf
+ fields, and assigning other numeric types has been optimized for
+ performance.
+ * Pure-Python: message types are now garbage-collectable.
+ * Python/C++: a lot of internal cleanup/refactoring.
+
+ PHP (Alpha)
+ * For 64-bit integers type (int64/uint64/sfixed64/fixed64/sint64), use PHP
+ integer on 64-bit environment and PHP string on 32-bit environment.
+ * PHP generated code also conforms to PSR-4 now.
+ * Fixed ZTS build for c extension.
+ * Fixed c extension build on Mac.
+ * Fixed c extension build on 32-bit linux.
+ * Fixed the bug that message without namespace is not found in the descriptor
+ pool. (#2240)
+ * Fixed the bug that repeated field is not iterable in c extension.
+ * Message names Empty will be converted to GPBEmpty in generated code.
+ * Added phpdoc in generated files.
+ * The released API is almost stable. Unless there is large problem, we won't
+ change it. See
+ https://developers.google.com/protocol-buffers/docs/reference/php-generated
+ for more details.
+
+ Objective-C
+ * Added support for push/pop of the stream limit on CodedInputStream for
+ anyone doing manual parsing.
+
+ C#
+ * No changes.
+
+ Ruby
+ * Message objects now support #respond_to? for field getters/setters.
+ * You can now compare “message == non_message_object” and it will return false
+ instead of throwing an exception.
+ * JRuby: fixed #hashCode to properly reflect the values in the message.
+
+ Javascript
+ * Deserialization of repeated fields no longer has quadratic performance
+ behavior.
+ * UTF-8 encoding/decoding now properly supports high codepoints.
+ * Added convenience methods for some well-known types: Any, Struct, and
+ Timestamp. These make it easier to convert data between native JavaScript
+ types and the well-known protobuf types.
+
+2016-09-23 version 3.1.0 (C++/Java/Python/PHP/Ruby/Objective-C/C#/JavaScript/Lite)
+ General
+ * Proto3 support in PHP (alpha).
+ * Various bug fixes.
+
+ C++
+ * Added MessageLite::ByteSizeLong() that’s equivalent to
+ MessageLite::ByteSize() but returns the value in size_t. Useful to check
+ whether a message is over the 2G size limit that protobuf can support.
+ * Moved default_instances to global variables. This allows default_instance
+ addresses to be known at compile time.
+ * Adding missing generic gcc 64-bit atomicops.
+ * Restore New*Callback into google::protobuf namespace since these are used
+ by the service stubs code
+ * JSON support.
+ * Fixed some conformance issues.
+ * Fixed a JSON serialization bug for bytes fields.
+
+ Java
+ * Fixed a bug in TextFormat that doesn’t accept empty repeated fields (i.e.,
+ “field: [ ]”).
+ * JSON support
+ * Fixed JsonFormat to do correct snake_case-to-camelCase conversion for
+ non-style-conforming field names.
+ * Fixed JsonFormat to parse empty Any message correctly.
+ * Added an option to JsonFormat.Parser to ignore unknown fields.
+ * Experimental API
+ * Added UnsafeByteOperations.unsafeWrap(byte[]) to wrap a byte array into
+ ByteString without copy.
+
+ Python
+ * JSON support
+ * Fixed some conformance issues.
+
+ PHP (Alpha)
+ * We have added the proto3 support for PHP via both a pure PHP package and a
+ native c extension. The pure PHP package is intended to provide usability
+ to wider range of PHP platforms, while the c extension is intended to
+ provide higher performance. Both implementations provide the same runtime
+ APIs and share the same generated code. Users don’t need to re-generate
+ code for the same proto definition when they want to switch the
+ implementation later. The pure PHP package is included in the php/src
+ directory, and the c extension is included in the php/ext directory.
+
+ Both implementations provide idiomatic PHP APIs:
+ * All messages and enums are defined as PHP classes.
+ * All message fields can only be accessed via getter/setter.
+ * Both repeated field elements and map elements are stored in containers
+ that act like a normal PHP array.
+
+ Unlike several existing third-party PHP implementations for protobuf, our
+ implementations are built on a "strongly-typed" philosophy: message fields
+ and array/map containers will throw exceptions eagerly when values of the
+ incorrect type (not including those that can be type converted, e.g.,
+ double <-> integer <-> numeric string) are inserted.
+
+ Currently, pure PHP runtime supports php5.5, 5.6 and 7 on linux. C
+ extension runtime supports php5.5 and 5.6 on linux.
+
+ See php/README.md for more details about installment. See
+ https://developers.google.com/protocol-buffers/docs/phptutorial for more
+ details about APIs.
+
+ Objective-C
+ * Helpers are now provided for working the the Any well known type (see
+ GPBWellKnownTypes.h for the api additions).
+ * Some improvements in startup code (especially when extensions aren’t used).
+
+ Javascript
+ * Fixed missing import of jspb.Map
+ * Fixed valueWriterFn variable name
+
+ Ruby
+ * Fixed hash computation for JRuby's RubyMessage
+ * Make sure map parsing frames are GC-rooted.
+ * Added API support for well-known types.
+
+ C#
+ * Removed check on dependency in the C# reflection API.
+
+2016-09-06 version 3.0.2 (C++/Java/Python/Ruby/Objective-C/C#/JavaScript/Lite)
+ General
+ * Various bug fixes.
+
+ Objective C
+ * Fix for oneofs in proto3 syntax files where fields were set to the zero
+ value.
+ * Fix for embedded null character in strings.
+ * CocoaDocs support
+
+ Ruby
+ * Fixed memory corruption bug in parsing that could occur under GC pressure.
+
+ Javascript
+ * jspb.Map is now properly exported to CommonJS modules.
+
+ C#
+ * Removed legacy_enum_values flag.
+
+
+2016-07-27 version 3.0.0 (C++/Java/Python/Ruby/Objective-C/C#/JavaScript/Lite)
+ General
+ * This log only contains changes since the beta-4 release. Summarized change
+ log since the last stable release (v2.6.1) can be found in the github
+ release page.
+
+ Compatibility Notice
+ * v3.0.0 is the first API stable release of the v3.x series. We do not expect
+ any future API breaking changes.
+ * For C++, Java Lite and Objective-C, source level compatibility is
+ guaranteed. Upgrading from v3.0.0 to newer minor version releases will be
+ source compatible. For example, if your code compiles against protobuf
+ v3.0.0, it will continue to compile after you upgrade protobuf library to
+ v3.1.0.
+ * For other languages, both source level compatibility and binary level
+ compatibility are guaranteed. For example, if you have a Java binary built
+ against protobuf v3.0.0. After switching the protobuf runtime binary to
+ v3.1.0, your built binary should continue to work.
+ * Compatibility is only guaranteed for documented API and documented
+ behaviors. If you are using undocumented API (e.g., use anything in the C++
+ internal namespace), it can be broken by minor version releases in an
+ undetermined manner.
+
+ Ruby
+ * When you assign a string field `a.string_field = "X"`, we now call
+ #encode(UTF-8) on the string and freeze the copy. This saves you from
+ needing to ensure the string is already encoded as UTF-8. It also prevents
+ you from mutating the string after it has been assigned (this is how we
+ ensure it stays valid UTF-8).
+ * The generated file for `foo.proto` is now `foo_pb.rb` instead of just
+ `foo.rb`. This makes it easier to see which imports/requires are from
+ protobuf generated code, and also prevents conflicts with any `foo.rb` file
+ you might have written directly in Ruby. It is a backward-incompatible
+ change: you will need to update all of your `require` statements.
+ * For package names like `foo_bar`, we now translate this to the Ruby module
+ `FooBar`. This is more idiomatic Ruby than what we used to do (`Foo_bar`).
+
+ JavaScript
+ * Scalar fields like numbers and boolean now return defaults instead of
+ `undefined` or `null` when they are unset. You can test for presence
+ explicitly by calling `hasFoo()`, which we now generate for scalar fields.
+
+ Java Lite
+ * Java Lite is now implemented as a separate plugin, maintained in the
+ `javalite` branch. Both lite runtime and protoc artifacts will be available
+ in Maven.
+
+ C#
+ * Target platforms now .NET 4.5, selected portable subsets and .NET Core.
+ * legacy_enum_values option is no longer supported.
+
+2016-07-15 version 3.0.0-beta-4 (C++/Java/Python/Ruby/Objective-C/C#/JavaScript)
+ General
+ * Added a deterministic serialization API for C++. The deterministic
+ serialization guarantees that given a binary, equal messages will be
+ serialized to the same bytes. This allows applications like MapReduce to
+ group equal messages based on the serialized bytes. The deterministic
+ serialization is, however, NOT canonical across languages; it is also
+ unstable across different builds with schema changes due to unknown fields.
+ Users who need canonical serialization, e.g. persistent storage in a
+ canonical form, fingerprinting, etc, should define their own
+ canonicalization specification and implement the serializer using reflection
+ APIs rather than relying on this API.
+ * Added OneofOptions. You can now define custom options for oneof groups.
+ import "google/protobuf/descriptor.proto";
+ extend google.protobuf.OneofOptions {
+ optional int32 my_oneof_extension = 12345;
+ }
+ message Foo {
+ oneof oneof_group {
+ (my_oneof_extension) = 54321;
+ ...
+ }
+ }
+
+ C++ (beta)
+ * Introduced a deterministic serialization API in
+ CodedOutputStream::SetSerializationDeterministic(bool). See the notes about
+ deterministic serialization in the General section.
+ * Added google::protobuf::Map::swap() to swap two map fields.
+ * Fixed a memory leak when calling Reflection::ReleaseMessage() on a message
+ allocated on arena.
+ * Improved error reporting when parsing text format protos.
+ * JSON
+ - Added a new parser option to ignore unknown fields when parsing JSON.
+ - Added convenient methods for message to/from JSON conversion.
+ * Various performance optimizations.
+
+ Java (beta)
+ * File option "java_generate_equals_and_hash" is now deprecated. equals() and
+ hashCode() methods are generated by default.
+ * Added a new JSON printer option "omittingInsignificantWhitespace" to produce
+ a more compact JSON output. The printer will pretty-print by default.
+ * Updated Java runtime to be compatible with 2.5.0/2.6.1 generated protos.
+
+ Python (beta)
+ * Added support to pretty print Any messages in text format.
+ * Added a flag to ignore unknown fields when parsing JSON.
+ * Bugfix: "@type" field of a JSON Any message is now correctly put before
+ other fields.
+
+ Objective-C (beta)
+ * Updated the code to support compiling with more compiler warnings
+ enabled. (Issue 1616)
+ * Exposing more detailed errors for parsing failures. (PR 1623)
+ * Small (breaking) change to the naming of some methods on the support classes
+ for map<>. There were collisions with the system provided KVO support, so
+ the names were changed to avoid those issues. (PR 1699)
+ * Fixed for proper Swift bridging of error handling during parsing. (PR 1712)
+ * Complete support for generating sources that will go into a Framework and
+ depend on generated sources from other Frameworks. (Issue 1457)
+
+ C# (beta)
+ * RepeatedField optimizations.
+ * Support for .NET Core.
+ * Minor bug fixes.
+ * Ability to format a single value in JsonFormatter (advanced usage only).
+ * Modifications to attributes applied to generated code.
+
+ Javascript (alpha)
+ * Maps now have a real map API instead of being treated as repeated fields.
+ * Well-known types are now provided in the google-protobuf package, and the
+ code generator knows to require() them from that package.
+ * Bugfix: non-canonical varints are correctly decoded.
+
+ Ruby (alpha)
+ * Accessors for oneof fields now return default values instead of nil.
+
+ Java Lite
+ * Java lite support is removed from protocol compiler. It will be supported
+ as a protocol compiler plugin in a separate code branch.
+
+2016-05-16 version 3.0.0-beta-3 (C++/Java/Python/Ruby/Nano/Objective-C/C#/JavaScript)
+ General
+ * Supported Proto3 lite-runtime in C++/Java for mobile platforms.
+ * Any type now supports APIs to specify prefixes other than
+ type.googleapis.com
+ * Removed javanano_use_deprecated_package option; Nano will always has its own
+ ".nano" package.
+
+ C++ (Beta)
+ * Improved hash maps.
+ - Improved hash maps comments. In particular, please note that equal hash
+ maps will not necessarily have the same iteration order and
+ serialization.
+ - Added a new hash maps implementation that will become the default in a
+ later release.
+ * Arenas
+ - Several inlined methods in Arena were moved to out-of-line to improve
+ build performance and code size.
+ - Added SpaceAllocatedAndUsed() to report both space used and allocated
+ - Added convenient class UnsafeArenaAllocatedRepeatedPtrFieldBackInserter
+ * Any
+ - Allow custom type URL prefixes in Any packing.
+ - TextFormat now expand the Any type rather than printing bytes.
+ * Performance optimizations and various bug fixes.
+
+ Java (Beta)
+ * Introduced an ExperimentalApi annotation. Annotated APIs are experimental
+ and are subject to change in a backward incompatible way in future releases.
+ * Introduced zero-copy serialization as an ExperimentalApi
+ - Introduction of the `ByteOutput` interface. This is similar to
+ `OutputStream` but provides semantics for lazy writing (i.e. no
+ immediate copy required) of fields that are considered to be immutable.
+ - `ByteString` now supports writing to a `ByteOutput`, which will directly
+ expose the internals of the `ByteString` (i.e. `byte[]` or `ByteBuffer`)
+ to the `ByteOutput` without copying.
+ - `CodedOutputStream` now supports writing to a `ByteOutput`. `ByteString`
+ instances that are too large to fit in the internal buffer will be
+ (lazily) written to the `ByteOutput` directly.
+ - This allows applications using large `ByteString` fields to avoid
+ duplication of these fields entirely. Such an application can supply a
+ `ByteOutput` that chains together the chunks received from
+ `CodedOutputStream` before forwarding them onto the IO system.
+ * Other related changes to `CodedOutputStream`
+ - Additional use of `sun.misc.Unsafe` where possible to perform fast
+ access to `byte[]` and `ByteBuffer` values and avoiding unnecessary
+ range checking.
+ - `ByteBuffer`-backed `CodedOutputStream` now writes directly to the
+ `ByteBuffer` rather than to an intermediate array.
+ * Improved lite-runtime.
+ - Lite protos now implement deep equals/hashCode/toString
+ - Significantly improved the performance of Builder#mergeFrom() and
+ Builder#mergeDelimitedFrom()
+ * Various bug fixes and small feature enhancement.
+ - Fixed stack overflow when in hashCode() for infinite recursive oneofs.
+ - Fixed the lazy field parsing in lite to merge rather than overwrite.
+ - TextFormat now supports reporting line/column numbers on errors.
+ - Updated to add appropriate @Override for better compiler errors.
+
+ Python (Beta)
+ * Added JSON format for Any, Struct, Value and ListValue
+ * [ ] is now accepted for both repeated scalar fields and repeated message
+ fields in text format parser.
+ * Numerical field name is now supported in text format.
+ * Added DiscardUnknownFields API for python protobuf message.
+
+ Objective-C (Beta)
+ * Proto comments now come over as HeaderDoc comments in the generated sources
+ so Xcode can pick them up and display them.
+ * The library headers have been updated to use HeaderDoc comments so Xcode can
+ pick them up and display them.
+ * The per message and per field overhead in both generated code and runtime
+ object sizes was reduced.
+ * Generated code now include deprecated annotations when the proto file
+ included them.
+
+ C# (Beta)
+ In general: some changes are breaking, which require regenerating messages.
+ Most user-written code will not be impacted *except* for the renaming of enum
+ values.
+
+ * Allow custom type URL prefixes in `Any` packing, and ignore them when
+ unpacking
+ * `protoc` is now in a separate NuGet package (Google.Protobuf.Tools)
+ * New option: `internal_access` to generate internal classes
+ * Enum values are now PascalCased, and if there's a prefix which matches the
+ name of the enum, that is removed (so an enum `COLOR` with a value
+ `COLOR_BLUE` would generate a value of just `Blue`). An option
+ (`legacy_enum_values`) is temporarily available to disable this, but the
+ option will be removed for GA.
+ * `json_name` option is now honored
+ * If group tags are encountered when parsing, they are validated more
+ thoroughly (although we don't support actual groups)
+ * NuGet dependencies are better specified
+ * Breaking: `Preconditions` is renamed to `ProtoPreconditions`
+ * Breaking: `GeneratedCodeInfo` is renamed to `GeneratedClrTypeInfo`
+ * `JsonFormatter` now allows writing to a `TextWriter`
+ * New interface, `ICustomDiagnosticMessage` to allow more compact
+ representations from `ToString`
+ * `CodedInputStream` and `CodedOutputStream` now implement `IDisposable`,
+ which simply disposes of the streams they were constructed with
+ * Map fields no longer support null values (in line with other languages)
+ * Improvements in JSON formatting and parsing
+
+ Javascript (Alpha)
+ * Better support for "bytes" fields: bytes fields can be read as either a
+ base64 string or UInt8Array (in environments where TypedArray is supported).
+ * New support for CommonJS imports. This should make it easier to use the
+ JavaScript support in Node.js and tools like WebPack. See js/README.md for
+ more information.
+ * Some significant internal refactoring to simplify and modularize the code.
+
+ Ruby (Alpha)
+ * JSON serialization now properly uses camelCased names, with a runtime option
+ that will preserve original names from .proto files instead.
+ * Well-known types are now included in the distribution.
+ * Release now includes binary gems for Windows, Mac, and Linux instead of just
+ source gems.
+ * Bugfix for serializing oneofs.
+
+ C++/Java Lite (Alpha)
+ A new "lite" generator parameter was introduced in the protoc for C++ and
+ Java for Proto3 syntax messages. Example usage:
+
+ ./protoc --cpp_out=lite:$OUTPUT_PATH foo.proto
+
+ The protoc will treat the current input and all the transitive dependencies
+ as LITE. The same generator parameter must be used to generate the
+ dependencies.
+
+ In Proto3 syntax files, "optimized_for=LITE_RUNTIME" is no longer supported.
+
+
+2015-12-30 version 3.0.0-beta-2 (C++/Java/Python/Ruby/Nano/Objective-C/C#/JavaScript)
+ General
+ * Introduced a new language implementation: JavaScript.
+ * Added a new field option "json_name". By default proto field names are
+ converted to "lowerCamelCase" in proto3 JSON format. This option can be
+ used to override this behavior and specify a different JSON name for the
+ field.
+ * Added conformance tests to ensure implementations are following proto3 JSON
+ specification.
+
+ C++ (Beta)
+ * Various bug fixes and improvements to the JSON support utility:
+ - Duplicate map keys in JSON are now rejected (i.e., translation will
+ fail).
+ - Fixed wire-format for google.protobuf.Value/ListValue.
+ - Fixed precision loss when converting google.protobuf.Timestamp.
+ - Fixed a bug when parsing invalid UTF-8 code points.
+ - Fixed a memory leak.
+ - Reduced call stack usage.
+
+ Java (Beta)
+ * Cleaned up some unused methods on CodedOutputStream.
+ * Presized lists for packed fields during parsing in the lite runtime to
+ reduce allocations and improve performance.
+ * Improved the performance of unknown fields in the lite runtime.
+ * Introduced UnsafeByteStrings to support zero-copy ByteString creation.
+ * Various bug fixes and improvements to the JSON support utility:
+ - Fixed a thread-safety bug.
+ - Added a new option “preservingProtoFieldNames” to JsonFormat.
+ - Added a new option “includingDefaultValueFields” to JsonFormat.
+ - Updated the JSON utility to comply with proto3 JSON specification.
+
+ Python (Beta)
+ * Added proto3 JSON format utility. It includes support for all field types
+ and a few well-known types except for Any and Struct.
+ * Added runtime support for Any, Timestamp, Duration and FieldMask.
+ * [ ] is now accepted for repeated scalar fields in text format parser.
+ * Map fields now have proper O(1) performance for lookup/insert/delete
+ when using the Python/C++ implementation. They were previously using O(n)
+ search-based algorithms because the C++ reflection interface didn't
+ support true map operations.
+
+ Objective-C (Beta)
+ * Various bug-fixes and code tweaks to pass more strict compiler warnings.
+ * Now has conformance test coverage and is passing all tests.
+
+ C# (Beta)
+ * Various bug-fixes.
+ * Code generation: Files generated in directories based on namespace.
+ * Code generation: Include comments from .proto files in XML doc
+ comments (naively)
+ * Code generation: Change organization/naming of "reflection class" (access
+ to file descriptor)
+ * Code generation and library: Add Parser property to MessageDescriptor,
+ and introduce a non-generic parser type.
+ * Library: Added TypeRegistry to support JSON parsing/formatting of Any.
+ * Library: Added Any.Pack/Unpack support.
+ * Library: Implemented JSON parsing.
+
+ Javascript (Alpha)
+ * Added proto3 support for JavaScript. The runtime is written in pure
+ JavaScript and works in browsers and in Node.js. To generate JavaScript
+ code for your proto, invoke protoc with "--js_out". See js/README.md
+ for more build instructions.
+
+2015-08-26 version 3.0.0-beta-1 (C++/Java/Python/Ruby/Nano/Objective-C/C#)
+ About Beta
+ * This is the first beta release of protobuf v3.0.0. Not all languages
+ have reached beta stage. Languages not marked as beta are still in
+ alpha (i.e., be prepared for API breaking changes).
+
+ General
+ * Proto3 JSON is supported in several languages (fully supported in C++
+ and Java, partially supported in Ruby/C#). The JSON spec is defined in
+ the proto3 language guide:
+
+ https://developers.google.com/protocol-buffers/docs/proto3#json
+
+ We will publish a more detailed spec to define the exact behavior of
+ proto3-conformant JSON serializers and parsers. Until then, do not rely
+ on specific behaviors of the implementation if it’s not documented in
+ the above spec. More specifically, the behavior is not yet finalized for
+ the following:
+ - Parsing invalid JSON input (e.g., input with trailing commas).
+ - Non-camelCase names in JSON input.
+ - The same field appears multiple times in JSON input.
+ - JSON arrays contain “null” values.
+ - The message has unknown fields.
+
+ * Proto3 now enforces strict UTF-8 checking. Parsing will fail if a string
+ field contains non UTF-8 data.
+
+ C++ (Beta)
+ * Introduced new utility functions/classes in the google/protobuf/util
+ directory:
+ - MessageDifferencer: compare two proto messages and report their
+ differences.
+ - JsonUtil: support converting protobuf binary format to/from JSON.
+ - TimeUtil: utility functions to work with well-known types Timestamp
+ and Duration.
+ - FieldMaskUtil: utility functions to work with FieldMask.
+
+ * Performance optimization of arena construction and destruction.
+ * Bug fixes for arena and maps support.
+ * Changed to use cmake for Windows Visual Studio builds.
+ * Added Bazel support.
+
+ Java (Beta)
+ * Introduced a new util package that will be distributed as a separate
+ artifact in maven. It contains:
+ - JsonFormat: convert proto messages to/from JSON.
+ - TimeUtil: utility functions to work with Timestamp and Duration.
+ - FieldMaskUtil: utility functions to work with FieldMask.
+
+ * The static PARSER in each generated message is deprecated, and it will
+ be removed in a future release. A static parser() getter is generated
+ for each message type instead.
+ * Performance optimizations for String fields serialization.
+ * Performance optimizations for Lite runtime on Android:
+ - Reduced allocations
+ - Reduced method overhead after ProGuarding
+ - Reduced code size after ProGuarding
+
+ Python (Alpha)
+ * Removed legacy Python 2.5 support.
+ * Moved to a single Python 2.x/3.x-compatible codebase, instead of using 2to3.
+ * Fixed build/tests on Python 2.6, 2.7, 3.3, and 3.4.
+ - Pure-Python works on all four.
+ - Python/C++ implementation works on all but 3.4, due to changes in the
+ Python/C++ API in 3.4.
+ * Some preliminary work has been done to allow for multiple DescriptorPools
+ with Python/C++.
+
+ Ruby (Alpha)
+ * Many bugfixes:
+ - fixed parsing/serialization of bytes, sint, sfixed types
+ - other parser bugfixes
+ - fixed memory leak affecting Ruby 2.2
+
+ JavaNano (Alpha)
+ * JavaNano generated code now will be put in a nano package by default to
+ avoid conflicts with Java generated code.
+
+ Objective-C (Alpha)
+ * Added non-null markup to ObjC library. Requires SDK 8.4+ to build.
+ * Many bugfixes:
+ - Removed the class/enum filter.
+ - Renamed some internal types to avoid conflicts with the well-known types
+ protos.
+ - Added missing support for parsing repeated primitive fields in packed or
+ unpacked forms.
+ - Added *Count for repeated and map<> fields to avoid auto-create when
+ checking for them being set.
+
+ C# (Alpha)
+ * Namespace changed to Google.Protobuf (and NuGet package will be named
+ correspondingly).
+ * Target platforms now .NET 4.5 and selected portable subsets only.
+ * Removed lite runtime.
+ * Reimplementation to use mutable message types.
+ * Null references used to represent "no value" for message type fields.
+ * Proto3 semantics supported; proto2 files are prohibited for C# codegen.
+ Most proto3 features supported:
+ - JSON formatting (a.k.a. serialization to JSON), including well-known
+ types (except for Any).
+ - Wrapper types mapped to nullable value types (or string/ByteString
+ allowing nullability). JSON parsing is not supported yet.
+ - maps
+ - oneof
+ - enum unknown value preservation
+
+2015-05-25 version 3.0.0-alpha-3 (Objective-C/C#):
+ General
+ * Introduced two new language implementations (Objective-C, C#) to proto3.
+ * Explicit "optional" keyword are disallowed in proto3 syntax, as fields are
+ optional by default.
+ * Group fields are no longer supported in proto3 syntax.
+ * Changed repeated primitive fields to use packed serialization by default in
+ proto3 (implemented for C++, Java, Python in this release). The user can
+ still disable packed serialization by setting packed to false for now.
+ * Added well-known type protos (any.proto, empty.proto, timestamp.proto,
+ duration.proto, etc.). Users can import and use these protos just like
+ regular proto files. Additional runtime support will be added for them in
+ future releases (in the form of utility helper functions, or having them
+ replaced by language specific types in generated code).
+ * Added a "reserved" keyword in both proto2 and proto3 syntax. User can use
+ this keyword to declare reserved field numbers and names to prevent them
+ from being reused by other fields in the same message.
+
+ To reserve field numbers, add a reserved declaration in your message:
+
+ message TestMessage {
+ reserved 2, 15, 9 to 11, 3;
+ }
+
+ This reserves field numbers 2, 3, 9, 10, 11 and 15. If a user uses any of
+ these as field numbers, the protocol buffer compiler will report an error.
+
+ Field names can also be reserved:
+
+ message TestMessage {
+ reserved "foo", "bar";
+ }
+
+ * Various bug fixes since 3.0.0-alpha-2
+
+ Objective-C
+ Objective-C includes a code generator and a native objective-c runtime
+ library. By adding “--objc_out” to protoc, the code generator will generate
+ a header(*.pbobjc.h) and an implementation file(*.pbobjc.m) for each proto
+ file.
+
+ In this first release, the generated interface provides: enums, messages,
+ field support(single, repeated, map, oneof), proto2 and proto3 syntax
+ support, parsing and serialization. It’s compatible with ARC and non-ARC
+ usage. Besides, user can also access it via the swift bridging header.
+
+ See objectivec/README.md for details.
+
+ C#
+ * C# protobufs are based on project
+ https://github.com/jskeet/protobuf-csharp-port. The original project was
+ frozen and all the new development will happen here.
+ * Codegen plugin for C# was completely rewritten to C++ and is now an
+ integral part of protoc.
+ * Some refactorings and cleanup has been applied to the C# runtime library.
+ * Only proto2 is supported in C# at the moment, proto3 support is in
+ progress and will likely bring significant breaking changes to the API.
+
+ See csharp/README.md for details.
+
+ C++
+ * Added runtime support for Any type. To use Any in your proto file, first
+ import the definition of Any:
+
+ // foo.proto
+ import "google/protobuf/any.proto";
+ message Foo {
+ google.protobuf.Any any_field = 1;
+ }
+ message Bar {
+ int32 value = 1;
+ }
+
+ Then in C++ you can access the Any field using PackFrom()/UnpackTo()
+ methods:
+
+ Foo foo;
+ Bar bar = ...;
+ foo.mutable_any_field()->PackFrom(bar);
+ ...
+ if (foo.any_field().IsType<Bar>()) {
+ foo.any_field().UnpackTo(&bar);
+ ...
+ }
+ * In text format, entries of a map field will be sorted by key.
+
+ Java
+ * Continued optimizations on the lite runtime to improve performance for
+ Android.
+
+ Python
+ * Added map support.
+ - maps now have a dict-like interface (msg.map_field[key] = value)
+ - existing code that modifies maps via the repeated field interface
+ will need to be updated.
+
+ Ruby
+ * Improvements to RepeatedField's emulation of the Ruby Array API.
+ * Various speedups and internal cleanups.
+
+2015-02-26 version 3.0.0-alpha-2 (Python/Ruby/JavaNano):
+ General
+ * Introduced three new language implementations (Ruby, JavaNano, and
+ Python) to proto3.
+ * Various bug fixes since 3.0.0-alpha-1
+
+ Python:
+ Python has received several updates, most notably support for proto3
+ semantics in any .proto file that declares syntax="proto3".
+ Messages declared in proto3 files no longer represent field presence
+ for scalar fields (number, enums, booleans, or strings). You can
+ no longer call HasField() for such fields, and they are serialized
+ based on whether they have a non-zero/empty/false value.
+
+ One other notable change is in the C++-accelerated implementation.
+ Descriptor objects (which describe the protobuf schema and allow
+ reflection over it) are no longer duplicated between the Python
+ and C++ layers. The Python descriptors are now simple wrappers
+ around the C++ descriptors. This change should significantly
+ reduce the memory usage of programs that use a lot of message
+ types.
+
+ Ruby:
+ We have added proto3 support for Ruby via a native C extension.
+
+ The Ruby extension itself is included in the ruby/ directory, and details on
+ building and installing the extension are in ruby/README.md. The extension
+ will also be published as a Ruby gem. Code generator support is included as
+ part of `protoc` with the `--ruby_out` flag.
+
+ The Ruby extension implements a user-friendly DSL to define message types
+ (also generated by the code generator from `.proto` files). Once a message
+ type is defined, the user may create instances of the message that behave in
+ ways idiomatic to Ruby. For example:
+
+ - Message fields are present as ordinary Ruby properties (getter method
+ `foo` and setter method `foo=`).
+ - Repeated field elements are stored in a container that acts like a native
+ Ruby array, and map elements are stored in a container that acts like a
+ native Ruby hashmap.
+ - The usual well-known methods, such as `#to_s`, `#dup`, and the like, are
+ present.
+
+ Unlike several existing third-party Ruby extensions for protobuf, this
+ extension is built on a "strongly-typed" philosophy: message fields and
+ array/map containers will throw exceptions eagerly when values of the
+ incorrect type are inserted.
+
+ See ruby/README.md for details.
+
+ JavaNano:
+ JavaNano is a special code generator and runtime library designed especially
+ for resource-restricted systems, like Android. It is very resource-friendly
+ in both the amount of code and the runtime overhead. Here is an an overview
+ of JavaNano features compared with the official Java protobuf:
+
+ - No descriptors or message builders.
+ - All messages are mutable; fields are public Java fields.
+ - For optional fields only, encapsulation behind setter/getter/hazzer/
+ clearer functions is opt-in, which provide proper 'has' state support.
+ - For proto2, if not opted in, has state (field presence) is not available.
+ Serialization outputs all fields not equal to their defaults.
+ The behavior is consistent with proto3 semantics.
+ - Required fields (proto2 only) are always serialized.
+ - Enum constants are integers; protection against invalid values only
+ when parsing from the wire.
+ - Enum constants can be generated into container interfaces bearing
+ the enum's name (so the referencing code is in Java style).
+ - CodedInputByteBufferNano can only take byte[] (not InputStream).
+ - Similarly CodedOutputByteBufferNano can only write to byte[].
+ - Repeated fields are in arrays, not ArrayList or Vector. Null array
+ elements are allowed and silently ignored.
+ - Full support for serializing/deserializing repeated packed fields.
+ - Support extensions (in proto2).
+ - Unset messages/groups are null, not an immutable empty default
+ instance.
+ - toByteArray(...) and mergeFrom(...) are now static functions of
+ MessageNano.
+ - The 'bytes' type translates to the Java type byte[].
+
+ See javanano/README.txt for details.
+
+2014-12-01 version 3.0.0-alpha-1 (C++/Java):
+
+ General
+ * Introduced Protocol Buffers language version 3 (aka proto3).
+
+ When protobuf was initially opensourced it implemented Protocol Buffers
+ language version 2 (aka proto2), which is why the version number
+ started from v2.0.0. From v3.0.0, a new language version (proto3) is
+ introduced while the old version (proto2) will continue to be supported.
+
+ The main intent of introducing proto3 is to clean up protobuf before
+ pushing the language as the foundation of Google's new API platform.
+ In proto3, the language is simplified, both for ease of use and to
+ make it available in a wider range of programming languages. At the
+ same time a few features are added to better support common idioms
+ found in APIs.
+
+ The following are the main new features in language version 3:
+
+ 1. Removal of field presence logic for primitive value fields, removal
+ of required fields, and removal of default values. This makes proto3
+ significantly easier to implement with open struct representations,
+ as in languages like Android Java, Objective C, or Go.
+ 2. Removal of unknown fields.
+ 3. Removal of extensions, which are instead replaced by a new standard
+ type called Any.
+ 4. Fix semantics for unknown enum values.
+ 5. Addition of maps.
+ 6. Addition of a small set of standard types for representation of time,
+ dynamic data, etc.
+ 7. A well-defined encoding in JSON as an alternative to binary proto
+ encoding.
+
+ This release (v3.0.0-alpha-1) includes partial proto3 support for C++ and
+ Java. Items 6 (well-known types) and 7 (JSON format) in the above feature
+ list are not implemented.
+
+ A new notion "syntax" is introduced to specify whether a .proto file
+ uses proto2 or proto3:
+
+ // foo.proto
+ syntax = "proto3";
+ message Bar {...}
+
+ If omitted, the protocol compiler will generate a warning and "proto2" will
+ be used as the default. This warning will be turned into an error in a
+ future release.
+
+ We recommend that new Protocol Buffers users use proto3. However, we do not
+ generally recommend that existing users migrate from proto2 from proto3 due
+ to API incompatibility, and we will continue to support proto2 for a long
+ time.
+
+ * Added support for map fields (implemented in C++/Java for both proto2 and
+ proto3).
+
+ Map fields can be declared using the following syntax:
+
+ message Foo {
+ map<string, string> values = 1;
+ }
+
+ Data of a map field will be stored in memory as an unordered map and it
+ can be accessed through generated accessors.
+
+ C++
+ * Added arena allocation support (for both proto2 and proto3).
+
+ Profiling shows memory allocation and deallocation constitutes a significant
+ fraction of CPU-time spent in protobuf code and arena allocation is a
+ technique introduced to reduce this cost. With arena allocation, new
+ objects will be allocated from a large piece of preallocated memory and
+ deallocation of these objects is almost free. Early adoption shows 20% to
+ 50% improvement in some Google binaries.
+
+ To enable arena support, add the following option to your .proto file:
+
+ option cc_enable_arenas = true;
+
+ Protocol compiler will generate additional code to make the generated
+ message classes work with arenas. This does not change the existing API
+ of protobuf messages and does not affect wire format. Your existing code
+ should continue to work after adding this option. In the future we will
+ make this option enabled by default.
+
+ To actually take advantage of arena allocation, you need to use the arena
+ APIs when creating messages. A quick example of using the arena API:
+
+ {
+ google::protobuf::Arena arena;
+ // Allocate a protobuf message in the arena.
+ MyMessage* message = Arena::CreateMessage<MyMessage>(&arena);
+ // All submessages will be allocated in the same arena.
+ if (!message->ParseFromString(data)) {
+ // Deal with malformed input data.
+ }
+ // Must not delete the message here. It will be deleted automatically
+ // when the arena is destroyed.
+ }
+
+ Currently arena does not work with map fields. Enabling arena in a .proto
+ file containing map fields will result in compile errors in the generated
+ code. This will be addressed in a future release.
+
+2014-10-20 version 2.6.1:
+
+ C++
+ * Added atomicops support for Solaris.
+ * Released memory allocated by InitializeDefaultRepeatedFields() and
+ GetEmptyString(). Some memory sanitizers reported them as memory leaks.
+
+ Java
+ * Updated DynamicMessage.setField() to handle repeated enum values
+ correctly.
+ * Fixed a bug that caused NullPointerException to be thrown when
+ converting manually constructed FileDescriptorProto to
+ FileDescriptor.
+
+ Python
+ * Fixed WhichOneof() to work with de-serialized protobuf messages.
+ * Fixed a missing file problem of Python C++ implementation.
+
+2014-08-15 version 2.6.0:
+
+ General
+ * Added oneofs(unions) feature. Fields in the same oneof will share
+ memory and at most one field can be set at the same time. Use the
+ oneof keyword to define a oneof like:
+ message SampleMessage {
+ oneof test_oneof {
+ string name = 4;
+ YourMessage sub_message = 9;
+ }
+ }
+ * Files, services, enums, messages, methods and enum values can be marked
+ as deprecated now.
+ * Added Support for list values, including lists of messages, when
+ parsing text-formatted protos in C++ and Java.
+ For example: foo: [1, 2, 3]
+
+ C++
+ * Enhanced customization on TestFormat printing.
+ * Added SwapFields() in reflection API to swap a subset of fields.
+ Added SetAllocatedMessage() in reflection API.
+ * Repeated primitive extensions are now packable. The
+ [packed=true] option only affects serializers. Therefore, it is
+ possible to switch a repeated extension field to packed format
+ without breaking backwards-compatibility.
+ * Various speed optimizations.
+
+ Java
+ * writeTo() method in ByteString can now write a substring to an
+ output stream. Added endWith() method for ByteString.
+ * ByteString and ByteBuffer are now supported in CodedInputStream
+ and CodedOutputStream.
+ * java_generate_equals_and_hash can now be used with the LITE_RUNTIME.
+
+ Python
+ * A new C++-backed extension module (aka "cpp api v2") that replaces the
+ old ("cpp api v1") one. Much faster than the pure Python code. This one
+ resolves many bugs and is recommended for general use over the
+ pure Python when possible.
+ * Descriptors now have enum_types_by_name and extension_types_by_name dict
+ attributes.
+ * Support for Python 3.
+
+2013-02-27 version 2.5.0:
+
+ General
+ * New notion "import public" that allows a proto file to forward the content
+ it imports to its importers. For example,
+ // foo.proto
+ import public "bar.proto";
+ import "baz.proto";
+
+ // qux.proto
+ import "foo.proto";
+ // Stuff defined in bar.proto may be used in this file, but stuff from
+ // baz.proto may NOT be used without importing it explicitly.
+ This is useful for moving proto files. To move a proto file, just leave
+ a single "import public" in the old proto file.
+ * New enum option "allow_alias" that specifies whether different symbols can
+ be assigned the same numeric value. Default value is "true". Setting it to
+ false causes the compiler to reject enum definitions where multiple symbols
+ have the same numeric value.
+ Note: We plan to flip the default value to "false" in a future release.
+ Projects using enum aliases should set the option to "true" in their .proto
+ files.
+
+ C++
+ * New generated method set_allocated_foo(Type* foo) for message and string
+ fields. This method allows you to set the field to a pre-allocated object
+ and the containing message takes the ownership of that object.
+ * Added SetAllocatedExtension() and ReleaseExtension() to extensions API.
+ * Custom options are now formatted correctly when descriptors are printed in
+ text format.
+ * Various speed optimizations.
+
+ Java
+ * Comments in proto files are now collected and put into generated code as
+ comments for corresponding classes and data members.
+ * Added Parser to parse directly into messages without a Builder. For
+ example,
+ Foo foo = Foo.PARSER.ParseFrom(input);
+ Using Parser is ~25% faster than using Builder to parse messages.
+ * Added getters/setters to access the underlying ByteString of a string field
+ directly.
+ * ByteString now supports more operations: substring(), prepend(), and
+ append(). The implementation of ByteString uses a binary tree structure
+ to support these operations efficiently.
+ * New method findInitializationErrors() that lists all missing required
+ fields.
+ * Various code size and speed optimizations.
+
+ Python
+ * Added support for dynamic message creation. DescriptorDatabase,
+ DescriptorPool, and MessageFactory work like their C++ counterparts to
+ simplify Descriptor construction from *DescriptorProtos, and MessageFactory
+ provides a message instance from a Descriptor.
+ * Added pickle support for protobuf messages.
+ * Unknown fields are now preserved after parsing.
+ * Fixed bug where custom options were not correctly populated. Custom
+ options can be accessed now.
+ * Added EnumTypeWrapper that provides better accessibility to enum types.
+ * Added ParseMessage(descriptor, bytes) to generate a new Message instance
+ from a descriptor and a byte string.
+
+2011-05-01 version 2.4.1:
+
+ C++
+ * Fixed the friendship problem for old compilers to make the library now gcc 3
+ compatible again.
+ * Fixed vcprojects/extract_includes.bat to extract compiler/plugin.h.
+
+ Java
+ * Removed usages of JDK 1.6 only features to make the library now JDK 1.5
+ compatible again.
+ * Fixed a bug about negative enum values.
+ * serialVersionUID is now defined in generated messages for java serializing.
+ * Fixed protoc to use java.lang.Object, which makes "Object" now a valid
+ message name again.
+
+ Python
+ * Experimental C++ implementation now requires C++ protobuf library installed.
+ See the README.txt in the python directory for details.
+
+2011-02-02 version 2.4.0:
+
+ General
+ * The RPC (cc|java|py)_generic_services default value is now false instead of
+ true.
+ * Custom options can have aggregate types. For example,
+ message MyOption {
+ optional string comment = 1;
+ optional string author = 2;
+ }
+ extend google.protobuf.FieldOptions {
+ optional MyOption myoption = 12345;
+ }
+ This option can now be set as follows:
+ message SomeType {
+ optional int32 field = 1 [(myoption) = { comment:'x' author:'y' }];
+ }
+
+ C++
+ * Various speed and code size optimizations.
+ * Added a release_foo() method on string and message fields.
+ * Fixed gzip_output_stream sub-stream handling.
+
+ Java
+ * Builders now maintain sub-builders for sub-messages. Use getFooBuilder() to
+ get the builder for the sub-message "foo". This allows you to repeatedly
+ modify deeply-nested sub-messages without rebuilding them.
+ * Builder.build() no longer invalidates the Builder for generated messages
+ (You may continue to modify it and then build another message).
+ * Code generator will generate efficient equals() and hashCode()
+ implementations if new option java_generate_equals_and_hash is enabled.
+ (Otherwise, reflection-based implementations are used.)
+ * Generated messages now implement Serializable.
+ * Fields with [deprecated=true] will be marked with @Deprecated in Java.
+ * Added lazy conversion of UTF-8 encoded strings to String objects to improve
+ performance.
+ * Various optimizations.
+ * Enum value can be accessed directly, instead of calling getNumber() on the
+ enum member.
+ * For each enum value, an integer constant is also generated with the suffix
+ _VALUE.
+
+ Python
+ * Added an experimental C++ implementation for Python messages via a Python
+ extension. Implementation type is controlled by an environment variable
+ PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION (valid values: "cpp" and "python")
+ The default value is currently "python" but will be changed to "cpp" in
+ future release.
+ * Improved performance on message instantiation significantly.
+ Most of the work on message instantiation is done just once per message
+ class, instead of once per message instance.
+ * Improved performance on text message parsing.
+ * Allow add() to forward keyword arguments to the concrete class.
+ E.g. instead of
+ item = repeated_field.add()
+ item.foo = bar
+ item.baz = quux
+ You can do:
+ repeated_field.add(foo=bar, baz=quux)
+ * Added a sort() interface to the BaseContainer.
+ * Added an extend() method to repeated composite fields.
+ * Added UTF8 debug string support.
+
+2010-01-08 version 2.3.0:
+
+ General
+ * Parsers for repeated numeric fields now always accept both packed and
+ unpacked input. The [packed=true] option only affects serializers.
+ Therefore, it is possible to switch a field to packed format without
+ breaking backwards-compatibility -- as long as all parties are using
+ protobuf 2.3.0 or above, at least.
+ * The generic RPC service code generated by the C++, Java, and Python
+ generators can be disabled via file options:
+ option cc_generic_services = false;
+ option java_generic_services = false;
+ option py_generic_services = false;
+ This allows plugins to generate alternative code, possibly specific to some
+ particular RPC implementation.
+
+ protoc
+ * Now supports a plugin system for code generators. Plugins can generate
+ code for new languages or inject additional code into the output of other
+ code generators. Plugins are just binaries which accept a protocol buffer
+ on stdin and write a protocol buffer to stdout, so they may be written in
+ any language. See src/google/protobuf/compiler/plugin.proto.
+ **WARNING**: Plugins are experimental. The interface may change in a
+ future version.
+ * If the output location ends in .zip or .jar, protoc will write its output
+ to a zip/jar archive instead of a directory. For example:
+ protoc --java_out=myproto_srcs.jar --python_out=myproto.zip myproto.proto
+ Currently the archive contents are not compressed, though this could change
+ in the future.
+ * inf, -inf, and nan can now be used as default values for float and double
+ fields.
+
+ C++
+ * Various speed and code size optimizations.
+ * DynamicMessageFactory is now fully thread-safe.
+ * Message::Utf8DebugString() method is like DebugString() but avoids escaping
+ UTF-8 bytes.
+ * Compiled-in message types can now contain dynamic extensions, through use
+ of CodedInputStream::SetExtensionRegistry().
+ * Now compiles shared libraries (DLLs) by default on Cygwin and MinGW, to
+ match other platforms. Use --disable-shared to avoid this.
+
+ Java
+ * parseDelimitedFrom() and mergeDelimitedFrom() now detect EOF and return
+ false/null instead of throwing an exception.
+ * Fixed some initialization ordering bugs.
+ * Fixes for OpenJDK 7.
+
+ Python
+ * 10-25 times faster than 2.2.0, still pure-Python.
+ * Calling a mutating method on a sub-message always instantiates the message
+ in its parent even if the mutating method doesn't actually mutate anything
+ (e.g. parsing from an empty string).
+ * Expanded descriptors a bit.
+
+2009-08-11 version 2.2.0:
+
+ C++
+ * Lite mode: The "optimize_for = LITE_RUNTIME" option causes the compiler
+ to generate code which only depends libprotobuf-lite, which is much smaller
+ than libprotobuf but lacks descriptors, reflection, and some other features.
+ * Fixed bug where Message.Swap(Message) was only implemented for
+ optimize_for_speed. Swap now properly implemented in both modes
+ (Issue 91).
+ * Added RemoveLast and SwapElements(index1, index2) to Reflection
+ interface for repeated elements.
+ * Added Swap(Message) to Reflection interface.
+ * Floating-point literals in generated code that are intended to be
+ single-precision now explicitly have 'f' suffix to avoid pedantic warnings
+ produced by some compilers.
+ * The [deprecated=true] option now causes the C++ code generator to generate
+ a GCC-style deprecation annotation (no-op on other compilers).
+ * google::protobuf::GetEnumDescriptor<SomeGeneratedEnumType>() returns the
+ EnumDescriptor for that type -- useful for templates which cannot call
+ SomeGeneratedEnumType_descriptor().
+ * Various optimizations and obscure bug fixes.
+
+ Java
+ * Lite mode: The "optimize_for = LITE_RUNTIME" option causes the compiler
+ to generate code which only depends libprotobuf-lite, which is much smaller
+ than libprotobuf but lacks descriptors, reflection, and some other features.
+ * Lots of style cleanups.
+
+ Python
+ * Fixed endianness bug with floats and doubles.
+ * Text format parsing support.
+ * Fix bug with parsing packed repeated fields in embedded messages.
+ * Ability to initialize fields by passing keyword args to constructor.
+ * Support iterators in extend and __setslice__ for containers.
+
+2009-05-13 version 2.1.0:
+
+ General
+ * Repeated fields of primitive types (types other that string, group, and
+ nested messages) may now use the option [packed = true] to get a more
+ efficient encoding. In the new encoding, the entire list is written
+ as a single byte blob using the "length-delimited" wire type. Within
+ this blob, the individual values are encoded the same way they would
+ be normally except without a tag before each value (thus, they are
+ tightly "packed").
+ * For each field, the generated code contains an integer constant assigned
+ to the field number. For example, the .proto file:
+ message Foo { optional int bar_baz = 123; }
+ would generate the following constants, all with the integer value 123:
+ C++: Foo::kBarBazFieldNumber
+ Java: Foo.BAR_BAZ_FIELD_NUMBER
+ Python: Foo.BAR_BAZ_FIELD_NUMBER
+ Constants are also generated for extensions, with the same naming scheme.
+ These constants may be used as switch cases.
+ * Updated bundled Google Test to version 1.3.0. Google Test is now bundled
+ in its verbatim form as a nested autoconf package, so you can drop in any
+ other version of Google Test if needed.
+ * optimize_for = SPEED is now the default, by popular demand. Use
+ optimize_for = CODE_SIZE if code size is more important in your app.
+ * It is now an error to define a default value for a repeated field.
+ Previously, this was silently ignored (it had no effect on the generated
+ code).
+ * Fields can now be marked deprecated like:
+ optional int32 foo = 1 [deprecated = true];
+ Currently this does not have any actual effect, but in the future the code
+ generators may generate deprecation annotations in each language.
+ * Cross-compiling should now be possible using the --with-protoc option to
+ configure. See README.txt for more info.
+
+ protoc
+ * --error_format=msvs option causes errors to be printed in Visual Studio
+ format, which should allow them to be clicked on in the build log to go
+ directly to the error location.
+ * The type name resolver will no longer resolve type names to fields. For
+ example, this now works:
+ message Foo {}
+ message Bar {
+ optional int32 Foo = 1;
+ optional Foo baz = 2;
+ }
+ Previously, the type of "baz" would resolve to "Bar.Foo", and you'd get
+ an error because Bar.Foo is a field, not a type. Now the type of "baz"
+ resolves to the message type Foo. This change is unlikely to make a
+ difference to anyone who follows the Protocol Buffers style guide.
+
+ C++
+ * Several optimizations, including but not limited to:
+ - Serialization, especially to flat arrays, is 10%-50% faster, possibly
+ more for small objects.
+ - Several descriptor operations which previously required locking no longer
+ do.
+ - Descriptors are now constructed lazily on first use, rather than at
+ process startup time. This should save memory in programs which do not
+ use descriptors or reflection.
+ - UnknownFieldSet completely redesigned to be more efficient (especially in
+ terms of memory usage).
+ - Various optimizations to reduce code size (though the serialization speed
+ optimizations increased code size).
+ * Message interface has method ParseFromBoundedZeroCopyStream() which parses
+ a limited number of bytes from an input stream rather than parsing until
+ EOF.
+ * GzipInputStream and GzipOutputStream support reading/writing gzip- or
+ zlib-compressed streams if zlib is available.
+ (google/protobuf/io/gzip_stream.h)
+ * DescriptorPool::FindAllExtensions() and corresponding
+ DescriptorDatabase::FindAllExtensions() can be used to enumerate all
+ extensions of a given type.
+ * For each enum type Foo, protoc will generate functions:
+ const string& Foo_Name(Foo value);
+ bool Foo_Parse(const string& name, Foo* result);
+ The former returns the name of the enum constant corresponding to the given
+ value while the latter finds the value corresponding to a name.
+ * RepeatedField and RepeatedPtrField now have back-insertion iterators.
+ * String fields now have setters that take a char* and a size, in addition
+ to the existing ones that took char* or const string&.
+ * DescriptorPool::AllowUnknownDependencies() may be used to tell
+ DescriptorPool to create placeholder descriptors for unknown entities
+ referenced in a FileDescriptorProto. This can allow you to parse a .proto
+ file without having access to other .proto files that it imports, for
+ example.
+ * Updated gtest to latest version. The gtest package is now included as a
+ nested autoconf package, so it should be able to drop new versions into the
+ "gtest" subdirectory without modification.
+
+ Java
+ * Fixed bug where Message.mergeFrom(Message) failed to merge extensions.
+ * Message interface has new method toBuilder() which is equivalent to
+ newBuilderForType().mergeFrom(this).
+ * All enums now implement the ProtocolMessageEnum interface.
+ * Setting a field to null now throws NullPointerException.
+ * Fixed tendency for TextFormat's parsing to overflow the stack when
+ parsing large string values. The underlying problem is with Java's
+ regex implementation (which unfortunately uses recursive backtracking
+ rather than building an NFA). Worked around by making use of possessive
+ quantifiers.
+ * Generated service classes now also generate pure interfaces. For a service
+ Foo, Foo.Interface is a pure interface containing all of the service's
+ defined methods. Foo.newReflectiveService() can be called to wrap an
+ instance of this interface in a class that implements the generic
+ RpcService interface, which provides reflection support that is usually
+ needed by RPC server implementations.
+ * RPC interfaces now support blocking operation in addition to non-blocking.
+ The protocol compiler generates separate blocking and non-blocking stubs
+ which operate against separate blocking and non-blocking RPC interfaces.
+ RPC implementations will have to implement the new interfaces in order to
+ support blocking mode.
+ * New I/O methods parseDelimitedFrom(), mergeDelimitedFrom(), and
+ writeDelimitedTo() read and write "delimited" messages from/to a stream,
+ meaning that the message size precedes the data. This way, you can write
+ multiple messages to a stream without having to worry about delimiting
+ them yourself.
+ * Throw a more descriptive exception when build() is double-called.
+ * Add a method to query whether CodedInputStream is at the end of the input
+ stream.
+ * Add a method to reset a CodedInputStream's size counter; useful when
+ reading many messages with the same stream.
+ * equals() and hashCode() now account for unknown fields.
+
+ Python
+ * Added slicing support for repeated scalar fields. Added slice retrieval and
+ removal of repeated composite fields.
+ * Updated RPC interfaces to allow for blocking operation. A client may
+ now pass None for a callback when making an RPC, in which case the
+ call will block until the response is received, and the response
+ object will be returned directly to the caller. This interface change
+ cannot be used in practice until RPC implementations are updated to
+ implement it.
+ * Changes to input_stream.py should make protobuf compatible with appengine.
+
+2008-11-25 version 2.0.3:
+
+ protoc
+ * Enum values may now have custom options, using syntax similar to field
+ options.
+ * Fixed bug where .proto files which use custom options but don't actually
+ define them (i.e. they import another .proto file defining the options)
+ had to explicitly import descriptor.proto.
+ * Adjacent string literals in .proto files will now be concatenated, like in
+ C.
+ * If an input file is a Windows absolute path (e.g. "C:\foo\bar.proto") and
+ the import path only contains "." (or contains "." but does not contain
+ the file), protoc incorrectly thought that the file was under ".", because
+ it thought that the path was relative (since it didn't start with a slash).
+ This has been fixed.
+
+ C++
+ * Generated message classes now have a Swap() method which efficiently swaps
+ the contents of two objects.
+ * All message classes now have a SpaceUsed() method which returns an estimate
+ of the number of bytes of allocated memory currently owned by the object.
+ This is particularly useful when you are reusing a single message object
+ to improve performance but want to make sure it doesn't bloat up too large.
+ * New method Message::SerializeAsString() returns a string containing the
+ serialized data. May be more convenient than calling
+ SerializeToString(string*).
+ * In debug mode, log error messages when string-type fields are found to
+ contain bytes that are not valid UTF-8.
+ * Fixed bug where a message with multiple extension ranges couldn't parse
+ extensions.
+ * Fixed bug where MergeFrom(const Message&) didn't do anything if invoked on
+ a message that contained no fields (but possibly contained extensions).
+ * Fixed ShortDebugString() to not be O(n^2). Durr.
+ * Fixed crash in TextFormat parsing if the first token in the input caused a
+ tokenization error.
+ * Fixed obscure bugs in zero_copy_stream_impl.cc.
+ * Added support for HP C++ on Tru64.
+ * Only build tests on "make check", not "make".
+ * Fixed alignment issue that caused crashes when using DynamicMessage on
+ 64-bit Sparc machines.
+ * Simplify template usage to work with MSVC 2003.
+ * Work around GCC 4.3.x x86_64 compiler bug that caused crashes on startup.
+ (This affected Fedora 9 in particular.)
+ * Now works on "Solaris 10 using recent Sun Studio".
+
+ Java
+ * New overload of mergeFrom() which parses a slice of a byte array instead
+ of the whole thing.
+ * New method ByteString.asReadOnlyByteBuffer() does what it sounds like.
+ * Improved performance of isInitialized() when optimizing for code size.
+
+ Python
+ * Corrected ListFields() signature in Message base class to match what
+ subclasses actually implement.
+ * Some minor refactoring.
+ * Don't pass self as first argument to superclass constructor (no longer
+ allowed in Python 2.6).
+
+2008-09-29 version 2.0.2:
+
+ General
+ * License changed from Apache 2.0 to 3-Clause BSD.
+ * It is now possible to define custom "options", which are basically
+ annotations which may be placed on definitions in a .proto file.
+ For example, you might define a field option called "foo" like so:
+ import "google/protobuf/descriptor.proto"
+ extend google.protobuf.FieldOptions {
+ optional string foo = 12345;
+ }
+ Then you annotate a field using the "foo" option:
+ message MyMessage {
+ optional int32 some_field = 1 [(foo) = "bar"]
+ }
+ The value of this option is then visible via the message's
+ Descriptor:
+ const FieldDescriptor* field =
+ MyMessage::descriptor()->FindFieldByName("some_field");
+ assert(field->options().GetExtension(foo) == "bar");
+ This feature has been implemented and tested in C++ and Java.
+ Other languages may or may not need to do extra work to support
+ custom options, depending on how they construct descriptors.
+
+ C++
+ * Fixed some GCC warnings that only occur when using -pedantic.
+ * Improved static initialization code, making ordering more
+ predictable among other things.
+ * TextFormat will no longer accept messages which contain multiple
+ instances of a singular field. Previously, the latter instance
+ would overwrite the former.
+ * Now works on systems that don't have hash_map.
+
+ Java
+ * Print @Override annotation in generated code where appropriate.
+
+ Python
+ * Strings now use the "unicode" type rather than the "str" type.
+ String fields may still be assigned ASCII "str" values; they will
+ automatically be converted.
+ * Adding a property to an object representing a repeated field now
+ raises an exception. For example:
+ # No longer works (and never should have).
+ message.some_repeated_field.foo = 1
+
+ Windows
+ * We now build static libraries rather than DLLs by default on MSVC.
+ See vsprojects/readme.txt for more information.
+
+2008-08-15 version 2.0.1:
+
+ protoc
+ * New flags --encode and --decode can be used to convert between protobuf text
+ format and binary format from the command-line.
+ * New flag --descriptor_set_out can be used to write FileDescriptorProtos for
+ all parsed files directly into a single output file. This is particularly
+ useful if you wish to parse .proto files from programs written in languages
+ other than C++: just run protoc as a background process and have it output
+ a FileDescriptorList, then parse that natively.
+ * Improved error message when an enum value's name conflicts with another
+ symbol defined in the enum type's scope, e.g. if two enum types declared
+ in the same scope have values with the same name. This is disallowed for
+ compatibility with C++, but this wasn't clear from the error.
+ * Fixed absolute output paths on Windows.
+ * Allow trailing slashes in --proto_path mappings.
+
+ C++
+ * Reflection objects are now per-class rather than per-instance. To make this
+ possible, the Reflection interface had to be changed such that all methods
+ take the Message instance as a parameter. This change improves performance
+ significantly in memory-bandwidth-limited use cases, since it makes the
+ message objects smaller. Note that source-incompatible interface changes
+ like this will not be made again after the library leaves beta.
+ * Heuristically detect sub-messages when printing unknown fields.
+ * Fix static initialization ordering bug that caused crashes at startup when
+ compiling on Mac with static linking.
+ * Fixed TokenizerTest when compiling with -DNDEBUG on Linux.
+ * Fixed incorrect definition of kint32min.
+ * Fix bytes type setter to work with byte sequences with embedded NULLs.
+ * Other irrelevant tweaks.
+
+ Java
+ * Fixed UnknownFieldSet's parsing of varints larger than 32 bits.
+ * Fixed TextFormat's parsing of "inf" and "nan".
+ * Fixed TextFormat's parsing of comments.
+ * Added info to Java POM that will be required when we upload the
+ package to a Maven repo.
+
+ Python
+ * MergeFrom(message) and CopyFrom(message) are now implemented.
+ * SerializeToString() raises an exception if the message is missing required
+ fields.
+ * Code organization improvements.
+ * Fixed doc comments for RpcController and RpcChannel, which had somehow been
+ swapped.
+ * Fixed text_format_test on Windows where floating-point exponents sometimes
+ contain extra zeros.
+ * Fix Python service CallMethod() implementation.
+
+ Other
+ * Improved readmes.
+ * VIM syntax highlighting improvements.
+
+2008-07-07 version 2.0.0:
+
+ * First public release.
diff --git a/third_party/protobuf/CONTRIBUTORS.txt b/third_party/protobuf/CONTRIBUTORS.txt
new file mode 100644
index 0000000000..b8d97fc23d
--- /dev/null
+++ b/third_party/protobuf/CONTRIBUTORS.txt
@@ -0,0 +1,102 @@
+This file contains a list of people who have made large contributions
+to the public version of Protocol Buffers.
+
+Original Protocol Buffers design and implementation:
+ Sanjay Ghemawat <sanjay@google.com>
+ Jeff Dean <jeff@google.com>
+ Daniel Dulitz <daniel@google.com>
+ Craig Silverstein
+ Paul Haahr <haahr@google.com>
+ Corey Anderson <corin@google.com>
+ (and many others)
+
+Proto2 C++ and Java primary author:
+ Kenton Varda <kenton@google.com>
+
+Proto2 Python primary authors:
+ Will Robinson <robinson@google.com>
+ Petar Petrov <petar@google.com>
+
+Java Nano primary authors:
+ Brian Duff <bduff@google.com>
+ Tom Chao <chaot@google.com>
+ Max Cai <maxtroy@google.com>
+ Ulas Kirazci <ulas@google.com>
+
+Large code contributions:
+ Jason Hsueh <jasonh@google.com>
+ Joseph Schorr <jschorr@google.com>
+ Wenbo Zhu <wenboz@google.com>
+
+Large quantity of code reviews:
+ Scott Bruce <sbruce@google.com>
+ Frank Yellin
+ Neal Norwitz <nnorwitz@google.com>
+ Jeffrey Yasskin <jyasskin@google.com>
+ Ambrose Feinstein <ambrose@google.com>
+
+Documentation:
+ Lisa Carey <lcarey@google.com>
+
+Maven packaging:
+ Gregory Kick <gak@google.com>
+
+Patch contributors:
+ Kevin Ko <kevin.s.ko@gmail.com>
+ * Small patch to handle trailing slashes in --proto_path flag.
+ Johan Euphrosine <proppy@aminche.com>
+ * Small patch to fix Python CallMethod().
+ Ulrich Kunitz <kune@deine-taler.de>
+ * Small optimizations to Python serialization.
+ Leandro Lucarella <llucax@gmail.com>
+ * VI syntax highlighting tweaks.
+ * Fix compiler to not make output executable.
+ Dilip Joseph <dilip.antony.joseph@gmail.com>
+ * Heuristic detection of sub-messages when printing unknown fields in
+ text format.
+ Brian Atkinson <nairb774@gmail.com>
+ * Added @Override annotation to generated Java code where appropriate.
+ Vincent Choinière <Choiniere.Vincent@hydro.qc.ca>
+ * Tru64 support.
+ Monty Taylor <monty.taylor@gmail.com>
+ * Solaris 10 + Sun Studio fixes.
+ Alek Storm <alek.storm@gmail.com>
+ * Slicing support for repeated scalar fields for the Python API.
+ Oleg Smolsky <oleg.smolsky@gmail.com>
+ * MS Visual Studio error format option.
+ * Detect unordered_map in stl_hash.m4.
+ Brian Olson <brianolson@google.com>
+ * gzip/zlib I/O support.
+ Michael Poole <mdpoole@troilus.org>
+ * Fixed warnings about generated constructors not explicitly initializing
+ all fields (only present with certain compiler settings).
+ * Added generation of field number constants.
+ Wink Saville <wink@google.com>
+ * Fixed initialization ordering problem in logging code.
+ Will Pierce <willp@nuclei.com>
+ * Small patch improving performance of in Python serialization.
+ Alexandre Vassalotti <alexandre@peadrop.com>
+ * Emacs mode for Protocol Buffers (editors/protobuf-mode.el).
+ Scott Stafford <scott.stafford@gmail.com>
+ * Added Swap(), SwapElements(), and RemoveLast() to Reflection interface.
+ Alexander Melnikov <alm@sibmail.ru>
+ * HPUX support.
+ Oliver Jowett <oliver.jowett@gmail.com>
+ * Detect whether zlib is new enough in configure script.
+ * Fixes for Solaris 10 32/64-bit confusion.
+ Evan Jones <evanj@mit.edu>
+ * Optimize Java serialization code when writing a small message to a stream.
+ * Optimize Java serialization of strings so that UTF-8 encoding happens only
+ once per string per serialization call.
+ * Clean up some Java warnings.
+ * Fix bug with permanent callbacks that delete themselves when run.
+ Michael Kucharski <m.kucharski@gmail.com>
+ * Added CodedInputStream.getTotalBytesRead().
+ Kacper Kowalik <xarthisius.kk@gmail.com>
+ * Fixed m4/acx_pthread.m4 problem for some Linux distributions.
+ William Orr <will@worrbase.com>
+ * Fixed detection of sched_yield on Solaris.
+ * Added atomicops for Solaris
+ Andrew Paprocki <andrew@ishiboo.com>
+ * Fixed minor IBM xlC compiler build issues
+ * Added atomicops for AIX (POWER)
diff --git a/third_party/protobuf/LICENSE b/third_party/protobuf/LICENSE
index 705db579c9..f028c82324 100644
--- a/third_party/protobuf/LICENSE
+++ b/third_party/protobuf/LICENSE
@@ -1,5 +1,14 @@
-Copyright 2008, Google Inc.
-All rights reserved.
+This license applies to all parts of Protocol Buffers except the following:
+
+ - Atomicops support for generic gcc, located in
+ src/google/protobuf/stubs/atomicops_internals_generic_gcc.h.
+ This file is copyrighted by Red Hat Inc.
+
+ - Atomicops support for AIX/POWER, located in
+ src/google/protobuf/stubs/atomicops_internals_power.h.
+ This file is copyrighted by Bloomberg Finance LP.
+
+Copyright 2014, Google Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
diff --git a/third_party/protobuf/Makefile.am b/third_party/protobuf/Makefile.am
new file mode 100644
index 0000000000..0b2511f9ac
--- /dev/null
+++ b/third_party/protobuf/Makefile.am
@@ -0,0 +1,949 @@
+## Process this file with automake to produce Makefile.in
+
+ACLOCAL_AMFLAGS = -I m4
+
+AUTOMAKE_OPTIONS = foreign
+
+# Build . before src so that our all-local and clean-local hooks kicks in at
+# the right time.
+SUBDIRS = . src
+
+# Always include gmock in distributions.
+DIST_SUBDIRS = $(subdirs) src conformance benchmarks
+
+# Build gmock before we build protobuf tests. We don't add gmock to SUBDIRS
+# because then "make check" would also build and run all of gmock's own tests,
+# which takes a lot of time and is generally not useful to us. Also, we don't
+# want "make install" to recurse into gmock since we don't want to overwrite
+# the installed version of gmock if there is one.
+check-local:
+ @echo "Making lib/libgmock.a lib/libgmock_main.a in gmock"
+ @cd gmock && $(MAKE) $(AM_MAKEFLAGS) lib/libgmock.la lib/libgmock_main.la
+ @cd gmock/gtest && $(MAKE) $(AM_MAKEFLAGS) lib/libgtest.la lib/libgtest_main.la
+
+# We would like to clean gmock when "make clean" is invoked. But we have to
+# be careful because clean-local is also invoked during "make distclean", but
+# "make distclean" already recurses into gmock because it's listed among the
+# DIST_SUBDIRS. distclean will delete gmock/Makefile, so if we then try to
+# cd to the directory again and "make clean" it will fail. So, check that the
+# Makefile exists before recursing.
+clean-local:
+ @if test -e gmock/Makefile; then \
+ echo "Making clean in gmock"; \
+ cd gmock && $(MAKE) $(AM_MAKEFLAGS) clean; \
+ fi; \
+ if test -e conformance/Makefile; then \
+ echo "Making clean in conformance"; \
+ cd conformance && $(MAKE) $(AM_MAKEFLAGS) clean; \
+ fi; \
+ if test -e benchmarks/Makefile; then \
+ echo "Making clean in benchmarks"; \
+ cd benchmarks && $(MAKE) $(AM_MAKEFLAGS) clean; \
+ fi; \
+ if test -e objectivec/DevTools; then \
+ echo "Cleaning any ObjC pyc files"; \
+ rm -f objectivec/DevTools/*.pyc; \
+ fi
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = protobuf.pc protobuf-lite.pc
+
+csharp_EXTRA_DIST= \
+ csharp/.gitignore \
+ csharp/CHANGES.txt \
+ csharp/Google.Protobuf.Tools.nuspec \
+ csharp/README.md \
+ csharp/build_packages.bat \
+ csharp/build_tools.sh \
+ csharp/buildall.sh \
+ csharp/generate_protos.sh \
+ csharp/keys/Google.Protobuf.public.snk \
+ csharp/keys/Google.Protobuf.snk \
+ csharp/keys/README.md \
+ csharp/protos/unittest_custom_options_proto3.proto \
+ csharp/protos/unittest_issues.proto \
+ csharp/src/AddressBook/AddPerson.cs \
+ csharp/src/AddressBook/Addressbook.cs \
+ csharp/src/AddressBook/AddressBook.xproj \
+ csharp/src/AddressBook/ListPeople.cs \
+ csharp/src/AddressBook/Program.cs \
+ csharp/src/AddressBook/SampleUsage.cs \
+ csharp/src/AddressBook/project.json \
+ csharp/src/Google.Protobuf.Conformance/Conformance.cs \
+ csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.xproj \
+ csharp/src/Google.Protobuf.Conformance/Program.cs \
+ csharp/src/Google.Protobuf.Conformance/project.json \
+ csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.xproj \
+ csharp/src/Google.Protobuf.JsonDump/Program.cs \
+ csharp/src/Google.Protobuf.JsonDump/project.json \
+ csharp/src/Google.Protobuf.Test/ByteStringTest.cs \
+ csharp/src/Google.Protobuf.Test/CodedInputStreamExtensions.cs \
+ csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs \
+ csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs \
+ csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs \
+ csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs \
+ csharp/src/Google.Protobuf.Test/Compatibility/PropertyInfoExtensionsTest.cs \
+ csharp/src/Google.Protobuf.Test/Compatibility/StreamExtensionsTest.cs \
+ csharp/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs \
+ csharp/src/Google.Protobuf.Test/DeprecatedMemberTest.cs \
+ csharp/src/Google.Protobuf.Test/EqualityTester.cs \
+ csharp/src/Google.Protobuf.Test/FieldCodecTest.cs \
+ csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs \
+ csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.xproj \
+ csharp/src/Google.Protobuf.Test/IssuesTest.cs \
+ csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs \
+ csharp/src/Google.Protobuf.Test/JsonParserTest.cs \
+ csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs \
+ csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs \
+ csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs \
+ csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs \
+ csharp/src/Google.Protobuf.Test/Reflection/TypeRegistryTest.cs \
+ csharp/src/Google.Protobuf.Test/SampleEnum.cs \
+ csharp/src/Google.Protobuf.Test/SampleMessages.cs \
+ csharp/src/Google.Protobuf.Test/TestCornerCases.cs \
+ csharp/src/Google.Protobuf.Test/TestProtos/ForeignMessagePartial.cs \
+ csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs \
+ csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs \
+ csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs \
+ csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs \
+ csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs \
+ csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs \
+ csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs \
+ csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs \
+ csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs \
+ csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs \
+ csharp/src/Google.Protobuf.Test/WellKnownTypes/FieldMaskTest.cs \
+ csharp/src/Google.Protobuf.Test/WellKnownTypes/TimestampTest.cs \
+ csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs \
+ csharp/src/Google.Protobuf.Test/project.json \
+ csharp/src/Google.Protobuf.sln \
+ csharp/src/Google.Protobuf/ByteArray.cs \
+ csharp/src/Google.Protobuf/ByteString.cs \
+ csharp/src/Google.Protobuf/CodedInputStream.cs \
+ csharp/src/Google.Protobuf/CodedOutputStream.ComputeSize.cs \
+ csharp/src/Google.Protobuf/CodedOutputStream.cs \
+ csharp/src/Google.Protobuf/Collections/MapField.cs \
+ csharp/src/Google.Protobuf/Collections/ReadOnlyDictionary.cs \
+ csharp/src/Google.Protobuf/Collections/RepeatedField.cs \
+ csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs \
+ csharp/src/Google.Protobuf/Compatibility/StreamExtensions.cs \
+ csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs \
+ csharp/src/Google.Protobuf/FieldCodec.cs \
+ csharp/src/Google.Protobuf/FrameworkPortability.cs \
+ csharp/src/Google.Protobuf/Google.Protobuf.xproj \
+ csharp/src/Google.Protobuf/ICustomDiagnosticMessage.cs \
+ csharp/src/Google.Protobuf/IDeepCloneable.cs \
+ csharp/src/Google.Protobuf/IMessage.cs \
+ csharp/src/Google.Protobuf/InvalidJsonException.cs \
+ csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs \
+ csharp/src/Google.Protobuf/JsonFormatter.cs \
+ csharp/src/Google.Protobuf/JsonParser.cs \
+ csharp/src/Google.Protobuf/JsonToken.cs \
+ csharp/src/Google.Protobuf/JsonTokenizer.cs \
+ csharp/src/Google.Protobuf/LimitedInputStream.cs \
+ csharp/src/Google.Protobuf/MessageExtensions.cs \
+ csharp/src/Google.Protobuf/MessageParser.cs \
+ csharp/src/Google.Protobuf/ProtoPreconditions.cs \
+ csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs \
+ csharp/src/Google.Protobuf/Reflection/CustomOptions.cs \
+ csharp/src/Google.Protobuf/Reflection/Descriptor.cs \
+ csharp/src/Google.Protobuf/Reflection/DescriptorBase.cs \
+ csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs \
+ csharp/src/Google.Protobuf/Reflection/DescriptorUtil.cs \
+ csharp/src/Google.Protobuf/Reflection/DescriptorValidationException.cs \
+ csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs \
+ csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs \
+ csharp/src/Google.Protobuf/Reflection/FieldAccessorBase.cs \
+ csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs \
+ csharp/src/Google.Protobuf/Reflection/FieldType.cs \
+ csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs \
+ csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs \
+ csharp/src/Google.Protobuf/Reflection/IDescriptor.cs \
+ csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs \
+ csharp/src/Google.Protobuf/Reflection/MapFieldAccessor.cs \
+ csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs \
+ csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs \
+ csharp/src/Google.Protobuf/Reflection/OneofAccessor.cs \
+ csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs \
+ csharp/src/Google.Protobuf/Reflection/OriginalNameAttribute.cs \
+ csharp/src/Google.Protobuf/Reflection/PackageDescriptor.cs \
+ csharp/src/Google.Protobuf/Reflection/PartialClasses.cs \
+ csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs \
+ csharp/src/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs \
+ csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs \
+ csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs \
+ csharp/src/Google.Protobuf/Reflection/TypeRegistry.cs \
+ csharp/src/Google.Protobuf/WellKnownTypes/Any.cs \
+ csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs \
+ csharp/src/Google.Protobuf/WellKnownTypes/Api.cs \
+ csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs \
+ csharp/src/Google.Protobuf/WellKnownTypes/DurationPartial.cs \
+ csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs \
+ csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs \
+ csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs \
+ csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs \
+ csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs \
+ csharp/src/Google.Protobuf/WellKnownTypes/TimeExtensions.cs \
+ csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs \
+ csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs \
+ csharp/src/Google.Protobuf/WellKnownTypes/Type.cs \
+ csharp/src/Google.Protobuf/WellKnownTypes/ValuePartial.cs \
+ csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs \
+ csharp/src/Google.Protobuf/WellKnownTypes/WrappersPartial.cs \
+ csharp/src/Google.Protobuf/WireFormat.cs \
+ csharp/src/Google.Protobuf/project.json \
+ csharp/src/global.json \
+ csharp/src/packages/repositories.config
+
+java_EXTRA_DIST= \
+ java/README.md \
+ java/core/generate-sources-build.xml \
+ java/core/generate-test-sources-build.xml \
+ java/core/pom.xml \
+ java/core/src/main/java/com/google/protobuf/AbstractMessage.java \
+ java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java \
+ java/core/src/main/java/com/google/protobuf/AbstractParser.java \
+ java/core/src/main/java/com/google/protobuf/AbstractProtobufList.java \
+ java/core/src/main/java/com/google/protobuf/BlockingRpcChannel.java \
+ java/core/src/main/java/com/google/protobuf/BlockingService.java \
+ java/core/src/main/java/com/google/protobuf/BooleanArrayList.java \
+ java/core/src/main/java/com/google/protobuf/ByteBufferWriter.java \
+ java/core/src/main/java/com/google/protobuf/ByteOutput.java \
+ java/core/src/main/java/com/google/protobuf/ByteString.java \
+ java/core/src/main/java/com/google/protobuf/CodedInputStream.java \
+ java/core/src/main/java/com/google/protobuf/CodedOutputStream.java \
+ java/core/src/main/java/com/google/protobuf/Descriptors.java \
+ java/core/src/main/java/com/google/protobuf/DoubleArrayList.java \
+ java/core/src/main/java/com/google/protobuf/DynamicMessage.java \
+ java/core/src/main/java/com/google/protobuf/ExperimentalApi.java \
+ java/core/src/main/java/com/google/protobuf/Extension.java \
+ java/core/src/main/java/com/google/protobuf/ExtensionLite.java \
+ java/core/src/main/java/com/google/protobuf/ExtensionRegistry.java \
+ java/core/src/main/java/com/google/protobuf/ExtensionRegistryFactory.java \
+ java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java \
+ java/core/src/main/java/com/google/protobuf/FieldSet.java \
+ java/core/src/main/java/com/google/protobuf/FloatArrayList.java \
+ java/core/src/main/java/com/google/protobuf/GeneratedMessage.java \
+ java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java \
+ java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java \
+ java/core/src/main/java/com/google/protobuf/IntArrayList.java \
+ java/core/src/main/java/com/google/protobuf/Internal.java \
+ java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java \
+ java/core/src/main/java/com/google/protobuf/LazyField.java \
+ java/core/src/main/java/com/google/protobuf/LazyFieldLite.java \
+ java/core/src/main/java/com/google/protobuf/LazyStringArrayList.java \
+ java/core/src/main/java/com/google/protobuf/LazyStringList.java \
+ java/core/src/main/java/com/google/protobuf/LongArrayList.java \
+ java/core/src/main/java/com/google/protobuf/MapEntry.java \
+ java/core/src/main/java/com/google/protobuf/MapEntryLite.java \
+ java/core/src/main/java/com/google/protobuf/MapField.java \
+ java/core/src/main/java/com/google/protobuf/MapFieldLite.java \
+ java/core/src/main/java/com/google/protobuf/Message.java \
+ java/core/src/main/java/com/google/protobuf/MessageLite.java \
+ java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java \
+ java/core/src/main/java/com/google/protobuf/MessageLiteToString.java \
+ java/core/src/main/java/com/google/protobuf/MessageOrBuilder.java \
+ java/core/src/main/java/com/google/protobuf/MessageReflection.java \
+ java/core/src/main/java/com/google/protobuf/MutabilityOracle.java \
+ java/core/src/main/java/com/google/protobuf/NioByteString.java \
+ java/core/src/main/java/com/google/protobuf/Parser.java \
+ java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java \
+ java/core/src/main/java/com/google/protobuf/ProtocolMessageEnum.java \
+ java/core/src/main/java/com/google/protobuf/ProtocolStringList.java \
+ java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java \
+ java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java \
+ java/core/src/main/java/com/google/protobuf/RopeByteString.java \
+ java/core/src/main/java/com/google/protobuf/RpcCallback.java \
+ java/core/src/main/java/com/google/protobuf/RpcChannel.java \
+ java/core/src/main/java/com/google/protobuf/RpcController.java \
+ java/core/src/main/java/com/google/protobuf/RpcUtil.java \
+ java/core/src/main/java/com/google/protobuf/Service.java \
+ java/core/src/main/java/com/google/protobuf/ServiceException.java \
+ java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java \
+ java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java \
+ java/core/src/main/java/com/google/protobuf/SmallSortedMap.java \
+ java/core/src/main/java/com/google/protobuf/TextFormat.java \
+ java/core/src/main/java/com/google/protobuf/TextFormatEscaper.java \
+ java/core/src/main/java/com/google/protobuf/TextFormatParseInfoTree.java \
+ java/core/src/main/java/com/google/protobuf/TextFormatParseLocation.java \
+ java/core/src/main/java/com/google/protobuf/UninitializedMessageException.java \
+ java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java \
+ java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java \
+ java/core/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java \
+ java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java \
+ java/core/src/main/java/com/google/protobuf/UnsafeUtil.java \
+ java/core/src/main/java/com/google/protobuf/Utf8.java \
+ java/core/src/main/java/com/google/protobuf/WireFormat.java \
+ java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java \
+ java/core/src/test/java/com/google/protobuf/AnyTest.java \
+ java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java \
+ java/core/src/test/java/com/google/protobuf/BoundedByteStringTest.java \
+ java/core/src/test/java/com/google/protobuf/ByteBufferWriterTest.java \
+ java/core/src/test/java/com/google/protobuf/ByteStringTest.java \
+ java/core/src/test/java/com/google/protobuf/CheckUtf8Test.java \
+ java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java \
+ java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java \
+ java/core/src/test/java/com/google/protobuf/DeprecatedFieldTest.java \
+ java/core/src/test/java/com/google/protobuf/DescriptorsTest.java \
+ java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java \
+ java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java \
+ java/core/src/test/java/com/google/protobuf/EnumTest.java \
+ java/core/src/test/java/com/google/protobuf/ExtensionRegistryFactoryTest.java \
+ java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java \
+ java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java \
+ java/core/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java \
+ java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java \
+ java/core/src/test/java/com/google/protobuf/IntArrayListTest.java \
+ java/core/src/test/java/com/google/protobuf/IsValidUtf8Test.java \
+ java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java \
+ java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java \
+ java/core/src/test/java/com/google/protobuf/LazyFieldTest.java \
+ java/core/src/test/java/com/google/protobuf/LazyMessageLiteTest.java \
+ java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java \
+ java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java \
+ java/core/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java \
+ java/core/src/test/java/com/google/protobuf/LiteTest.java \
+ java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java \
+ java/core/src/test/java/com/google/protobuf/LongArrayListTest.java \
+ java/core/src/test/java/com/google/protobuf/MapForProto2LiteTest.java \
+ java/core/src/test/java/com/google/protobuf/MapForProto2Test.java \
+ java/core/src/test/java/com/google/protobuf/MapTest.java \
+ java/core/src/test/java/com/google/protobuf/MessageTest.java \
+ java/core/src/test/java/com/google/protobuf/NestedBuildersTest.java \
+ java/core/src/test/java/com/google/protobuf/NioByteStringTest.java \
+ java/core/src/test/java/com/google/protobuf/ParseExceptionsTest.java \
+ java/core/src/test/java/com/google/protobuf/ParserTest.java \
+ java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java \
+ java/core/src/test/java/com/google/protobuf/RepeatedFieldBuilderV3Test.java \
+ java/core/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java \
+ java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java \
+ java/core/src/test/java/com/google/protobuf/ServiceTest.java \
+ java/core/src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java \
+ java/core/src/test/java/com/google/protobuf/SmallSortedMapTest.java \
+ java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java \
+ java/core/src/test/java/com/google/protobuf/TestUtil.java \
+ java/core/src/test/java/com/google/protobuf/TestUtilLite.java \
+ java/core/src/test/java/com/google/protobuf/TextFormatParseInfoTreeTest.java \
+ java/core/src/test/java/com/google/protobuf/TextFormatParseLocationTest.java \
+ java/core/src/test/java/com/google/protobuf/TextFormatTest.java \
+ java/core/src/test/java/com/google/protobuf/UnknownEnumValueTest.java \
+ java/core/src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java \
+ java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java \
+ java/core/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java \
+ java/core/src/test/java/com/google/protobuf/WellKnownTypesTest.java \
+ java/core/src/test/java/com/google/protobuf/WireFormatTest.java \
+ java/core/src/test/proto/com/google/protobuf/any_test.proto \
+ java/core/src/test/proto/com/google/protobuf/field_presence_test.proto \
+ java/core/src/test/proto/com/google/protobuf/lazy_fields_lite.proto \
+ java/core/src/test/proto/com/google/protobuf/lite_equals_and_hash.proto \
+ java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto \
+ java/core/src/test/proto/com/google/protobuf/map_for_proto2_test.proto \
+ java/core/src/test/proto/com/google/protobuf/map_initialization_order_test.proto \
+ java/core/src/test/proto/com/google/protobuf/map_test.proto \
+ java/core/src/test/proto/com/google/protobuf/multiple_files_test.proto \
+ java/core/src/test/proto/com/google/protobuf/nested_builders_test.proto \
+ java/core/src/test/proto/com/google/protobuf/nested_extension.proto \
+ java/core/src/test/proto/com/google/protobuf/nested_extension_lite.proto \
+ java/core/src/test/proto/com/google/protobuf/non_nested_extension.proto \
+ java/core/src/test/proto/com/google/protobuf/non_nested_extension_lite.proto \
+ java/core/src/test/proto/com/google/protobuf/outer_class_name_test.proto \
+ java/core/src/test/proto/com/google/protobuf/outer_class_name_test2.proto \
+ java/core/src/test/proto/com/google/protobuf/outer_class_name_test3.proto \
+ java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto \
+ java/core/src/test/proto/com/google/protobuf/test_check_utf8.proto \
+ java/core/src/test/proto/com/google/protobuf/test_check_utf8_size.proto \
+ java/core/src/test/proto/com/google/protobuf/test_custom_options.proto \
+ java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto \
+ java/lite/generate-sources-build.xml \
+ java/lite/generate-test-sources-build.xml \
+ java/lite/pom.xml \
+ java/pom.xml \
+ java/util/pom.xml \
+ java/util/src/main/java/com/google/protobuf/util/Durations.java \
+ java/util/src/main/java/com/google/protobuf/util/FieldMaskTree.java \
+ java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java \
+ java/util/src/main/java/com/google/protobuf/util/JsonFormat.java \
+ java/util/src/main/java/com/google/protobuf/util/TimeUtil.java \
+ java/util/src/main/java/com/google/protobuf/util/Timestamps.java \
+ java/util/src/test/java/com/google/protobuf/util/FieldMaskTreeTest.java \
+ java/util/src/test/java/com/google/protobuf/util/FieldMaskUtilTest.java \
+ java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java \
+ java/util/src/test/java/com/google/protobuf/util/TimeUtilTest.java \
+ java/util/src/test/proto/com/google/protobuf/util/json_test.proto
+
+javanano_EXTRA_DIST= \
+ javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java \
+ javanano/src/main/java/com/google/protobuf/nano/FieldData.java \
+ javanano/src/main/java/com/google/protobuf/nano/FieldArray.java \
+ javanano/src/main/java/com/google/protobuf/nano/WireFormatNano.java \
+ javanano/src/main/java/com/google/protobuf/nano/Extension.java \
+ javanano/src/main/java/com/google/protobuf/nano/CodedInputByteBufferNano.java \
+ javanano/src/main/java/com/google/protobuf/nano/UnknownFieldData.java \
+ javanano/src/main/java/com/google/protobuf/nano/MessageNano.java \
+ javanano/src/main/java/com/google/protobuf/nano/InternalNano.java \
+ javanano/src/main/java/com/google/protobuf/nano/InvalidProtocolBufferNanoException.java \
+ javanano/src/main/java/com/google/protobuf/nano/MapFactories.java \
+ javanano/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java \
+ javanano/src/main/java/com/google/protobuf/nano/MessageNanoPrinter.java \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_accessors_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_enum_class_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_reference_types_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_extension_repeated_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_has_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_multiple_nameclash_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_single_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/NanoTest.java \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_simple_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_import_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_repeated_merge_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_extension_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_repeated_packables_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_extension_singular_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_recursive_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_extension_packed_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_enum_validity_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_stringutf8_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_multiple_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/unittest_enum_class_multiple_nano.proto \
+ javanano/src/test/java/com/google/protobuf/nano/map_test.proto \
+ javanano/README.md \
+ javanano/pom.xml
+
+objectivec_EXTRA_DIST= \
+ objectivec/DevTools/check_version_stamps.sh \
+ objectivec/DevTools/compile_testing_protos.sh \
+ objectivec/DevTools/full_mac_build.sh \
+ objectivec/DevTools/pddm.py \
+ objectivec/DevTools/pddm_tests.py \
+ objectivec/generate_well_known_types.sh \
+ objectivec/google/protobuf/Any.pbobjc.h \
+ objectivec/google/protobuf/Any.pbobjc.m \
+ objectivec/google/protobuf/Api.pbobjc.h \
+ objectivec/google/protobuf/Api.pbobjc.m \
+ objectivec/google/protobuf/Duration.pbobjc.h \
+ objectivec/google/protobuf/Duration.pbobjc.m \
+ objectivec/google/protobuf/Empty.pbobjc.h \
+ objectivec/google/protobuf/Empty.pbobjc.m \
+ objectivec/google/protobuf/FieldMask.pbobjc.h \
+ objectivec/google/protobuf/FieldMask.pbobjc.m \
+ objectivec/google/protobuf/SourceContext.pbobjc.h \
+ objectivec/google/protobuf/SourceContext.pbobjc.m \
+ objectivec/google/protobuf/Struct.pbobjc.h \
+ objectivec/google/protobuf/Struct.pbobjc.m \
+ objectivec/google/protobuf/Timestamp.pbobjc.h \
+ objectivec/google/protobuf/Timestamp.pbobjc.m \
+ objectivec/google/protobuf/Type.pbobjc.h \
+ objectivec/google/protobuf/Type.pbobjc.m \
+ objectivec/google/protobuf/Wrappers.pbobjc.h \
+ objectivec/google/protobuf/Wrappers.pbobjc.m \
+ objectivec/GPBArray.h \
+ objectivec/GPBArray.m \
+ objectivec/GPBArray_PackagePrivate.h \
+ objectivec/GPBBootstrap.h \
+ objectivec/GPBCodedInputStream.h \
+ objectivec/GPBCodedInputStream.m \
+ objectivec/GPBCodedInputStream_PackagePrivate.h \
+ objectivec/GPBCodedOutputStream.h \
+ objectivec/GPBCodedOutputStream.m \
+ objectivec/GPBCodedOutputStream_PackagePrivate.h \
+ objectivec/GPBDescriptor.h \
+ objectivec/GPBDescriptor.m \
+ objectivec/GPBDescriptor_PackagePrivate.h \
+ objectivec/GPBDictionary.h \
+ objectivec/GPBDictionary.m \
+ objectivec/GPBDictionary_PackagePrivate.h \
+ objectivec/GPBExtensionInternals.h \
+ objectivec/GPBExtensionInternals.m \
+ objectivec/GPBExtensionRegistry.h \
+ objectivec/GPBExtensionRegistry.m \
+ objectivec/GPBMessage.h \
+ objectivec/GPBMessage.m \
+ objectivec/GPBMessage_PackagePrivate.h \
+ objectivec/GPBProtocolBuffers.h \
+ objectivec/GPBProtocolBuffers.m \
+ objectivec/GPBProtocolBuffers_RuntimeSupport.h \
+ objectivec/GPBRootObject.h \
+ objectivec/GPBRootObject.m \
+ objectivec/GPBRootObject_PackagePrivate.h \
+ objectivec/GPBRuntimeTypes.h \
+ objectivec/GPBUnknownField.h \
+ objectivec/GPBUnknownField.m \
+ objectivec/GPBUnknownField_PackagePrivate.h \
+ objectivec/GPBUnknownFieldSet.h \
+ objectivec/GPBUnknownFieldSet.m \
+ objectivec/GPBUnknownFieldSet_PackagePrivate.h \
+ objectivec/GPBUtilities.h \
+ objectivec/GPBUtilities.m \
+ objectivec/GPBUtilities_PackagePrivate.h \
+ objectivec/GPBWellKnownTypes.h \
+ objectivec/GPBWellKnownTypes.m \
+ objectivec/GPBWireFormat.h \
+ objectivec/GPBWireFormat.m \
+ objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj \
+ objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata \
+ objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings \
+ objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme \
+ objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme \
+ objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj \
+ objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/contents.xcworkspacedata \
+ objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings \
+ objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme \
+ objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme \
+ objectivec/README.md \
+ objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.pbxproj \
+ objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata \
+ objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/OSXCocoaPodsTester.xcscheme \
+ objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.h \
+ objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.m \
+ objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json \
+ objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Base.lproj/MainMenu.xib \
+ objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Info.plist \
+ objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/main.m \
+ objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-framework \
+ objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-static \
+ objectivec/Tests/CocoaPods/README.md \
+ objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-framework \
+ objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-static \
+ objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.pbxproj \
+ objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata \
+ objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/iOSCocoaPodsTester.xcscheme \
+ objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.h \
+ objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.m \
+ objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json \
+ objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/LaunchScreen.storyboard \
+ objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/Main.storyboard \
+ objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Info.plist \
+ objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.h \
+ objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.m \
+ objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/main.m \
+ objectivec/Tests/CocoaPods/run_tests.sh \
+ objectivec/Tests/golden_message \
+ objectivec/Tests/golden_packed_fields_message \
+ objectivec/Tests/GPBARCUnittestProtos.m \
+ objectivec/Tests/GPBArrayTests.m \
+ objectivec/Tests/GPBCodedInputStreamTests.m \
+ objectivec/Tests/GPBCodedOuputStreamTests.m \
+ objectivec/Tests/GPBConcurrencyTests.m \
+ objectivec/Tests/GPBDescriptorTests.m \
+ objectivec/Tests/GPBDictionaryTests+Bool.m \
+ objectivec/Tests/GPBDictionaryTests+Int32.m \
+ objectivec/Tests/GPBDictionaryTests+Int64.m \
+ objectivec/Tests/GPBDictionaryTests+String.m \
+ objectivec/Tests/GPBDictionaryTests+UInt32.m \
+ objectivec/Tests/GPBDictionaryTests+UInt64.m \
+ objectivec/Tests/GPBDictionaryTests.m \
+ objectivec/Tests/GPBDictionaryTests.pddm \
+ objectivec/Tests/GPBMessageTests+Merge.m \
+ objectivec/Tests/GPBMessageTests+Runtime.m \
+ objectivec/Tests/GPBMessageTests+Serialization.m \
+ objectivec/Tests/GPBMessageTests.m \
+ objectivec/Tests/GPBObjectiveCPlusPlusTest.mm \
+ objectivec/Tests/GPBPerfTests.m \
+ objectivec/Tests/GPBSwiftTests.swift \
+ objectivec/Tests/GPBTestUtilities.h \
+ objectivec/Tests/GPBTestUtilities.m \
+ objectivec/Tests/GPBUnittestProtos.m \
+ objectivec/Tests/GPBUnittestProtos2.m \
+ objectivec/Tests/GPBUnknownFieldSetTest.m \
+ objectivec/Tests/GPBUtilitiesTests.m \
+ objectivec/Tests/GPBWellKnownTypesTest.m \
+ objectivec/Tests/GPBWireFormatTests.m \
+ objectivec/Tests/iOSTestHarness/AppDelegate.m \
+ objectivec/Tests/iOSTestHarness/en.lproj/InfoPlist.strings \
+ objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/Contents.json \
+ objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6.png \
+ objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6_2x.png \
+ objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7.png \
+ objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7_2x.png \
+ objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6.png \
+ objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6_2x.png \
+ objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_2x.png \
+ objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_3x.png \
+ objectivec/Tests/iOSTestHarness/Images.xcassets/LaunchImage.launchimage/Contents.json \
+ objectivec/Tests/iOSTestHarness/Info.plist \
+ objectivec/Tests/iOSTestHarness/LaunchScreen.xib \
+ objectivec/Tests/text_format_map_unittest_data.txt \
+ objectivec/Tests/text_format_unittest_data.txt \
+ objectivec/Tests/unittest_cycle.proto \
+ objectivec/Tests/unittest_deprecated.proto \
+ objectivec/Tests/unittest_deprecated_file.proto \
+ objectivec/Tests/unittest_extension_chain_a.proto \
+ objectivec/Tests/unittest_extension_chain_b.proto \
+ objectivec/Tests/unittest_extension_chain_c.proto \
+ objectivec/Tests/unittest_extension_chain_d.proto \
+ objectivec/Tests/unittest_extension_chain_e.proto \
+ objectivec/Tests/unittest_extension_chain_f.proto \
+ objectivec/Tests/unittest_extension_chain_g.proto \
+ objectivec/Tests/unittest_objc.proto \
+ objectivec/Tests/unittest_objc_startup.proto \
+ objectivec/Tests/unittest_runtime_proto2.proto \
+ objectivec/Tests/unittest_runtime_proto3.proto \
+ objectivec/Tests/UnitTests-Bridging-Header.h \
+ objectivec/Tests/UnitTests-Info.plist \
+ Protobuf.podspec
+
+php_EXTRA_DIST= \
+ php/ext/google/protobuf/utf8.h \
+ php/ext/google/protobuf/message.c \
+ php/ext/google/protobuf/utf8.c \
+ php/ext/google/protobuf/package.xml \
+ php/ext/google/protobuf/upb.h \
+ php/ext/google/protobuf/array.c \
+ php/ext/google/protobuf/encode_decode.c \
+ php/ext/google/protobuf/protobuf.h \
+ php/ext/google/protobuf/type_check.c \
+ php/ext/google/protobuf/def.c \
+ php/ext/google/protobuf/storage.c \
+ php/ext/google/protobuf/map.c \
+ php/ext/google/protobuf/config.m4 \
+ php/ext/google/protobuf/upb.c \
+ php/ext/google/protobuf/protobuf.c \
+ php/src/phpdoc.dist.xml \
+ php/src/Google/Protobuf/Internal/DescriptorPool.php \
+ php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php \
+ php/src/Google/Protobuf/Internal/OneofField.php \
+ php/src/Google/Protobuf/Internal/MessageOptions.php \
+ php/src/Google/Protobuf/Internal/FileDescriptorProto.php \
+ php/src/Google/Protobuf/Internal/MapEntry.php \
+ php/src/Google/Protobuf/Internal/FieldDescriptorProto.php \
+ php/src/Google/Protobuf/Internal/InputStream.php \
+ php/src/Google/Protobuf/Internal/UninterpretedOption.php \
+ php/src/Google/Protobuf/Internal/ServiceOptions.php \
+ php/src/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php \
+ php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php \
+ php/src/Google/Protobuf/Internal/OneofDescriptorProto.php \
+ php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php \
+ php/src/Google/Protobuf/Internal/OutputStream.php \
+ php/src/Google/Protobuf/Internal/MessageBuilderContext.php \
+ php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php \
+ php/src/Google/Protobuf/Internal/FileOptions_OptimizeMode.php \
+ php/src/Google/Protobuf/Internal/DescriptorProto.php \
+ php/src/Google/Protobuf/Internal/MapField.php \
+ php/src/Google/Protobuf/Internal/MethodDescriptorProto.php \
+ php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php \
+ php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php \
+ php/src/Google/Protobuf/Internal/RepeatedField.php \
+ php/src/Google/Protobuf/Internal/EnumValueOptions.php \
+ php/src/Google/Protobuf/Internal/MethodOptions.php \
+ php/src/Google/Protobuf/Internal/OneofOptions.php \
+ php/src/Google/Protobuf/Internal/Message.php \
+ php/src/Google/Protobuf/Internal/FileOptions.php \
+ php/src/Google/Protobuf/Internal/FileDescriptorSet.php \
+ php/src/Google/Protobuf/Internal/EnumDescriptorProto.php \
+ php/src/Google/Protobuf/Internal/GPBWire.php \
+ php/src/Google/Protobuf/Internal/FieldDescriptorProto_Label.php \
+ php/src/Google/Protobuf/Internal/FieldOptions.php \
+ php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php \
+ php/src/Google/Protobuf/Internal/FieldDescriptorProto_Type.php \
+ php/src/Google/Protobuf/Internal/GPBType.php \
+ php/src/Google/Protobuf/Internal/FieldOptions_JSType.php \
+ php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php \
+ php/src/Google/Protobuf/Internal/SourceCodeInfo.php \
+ php/src/Google/Protobuf/Internal/EnumOptions.php \
+ php/src/Google/Protobuf/Internal/GPBLabel.php \
+ php/src/Google/Protobuf/Internal/EnumBuilderContext.php \
+ php/src/Google/Protobuf/Internal/GPBUtil.php \
+ php/src/Google/Protobuf/Internal/FieldOptions_CType.php \
+ php/src/Google/Protobuf/descriptor.php \
+ php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php \
+ php/tests/array_test.php \
+ php/tests/autoload.php \
+ php/tests/encode_decode_test.php \
+ php/tests/gdb_test.sh \
+ php/tests/generated_class_test.php \
+ php/tests/map_field_test.php \
+ php/tests/memory_leak_test.php \
+ php/tests/php_implementation_test.php \
+ php/tests/proto/test_include.proto \
+ php/tests/proto/test.proto \
+ php/tests/proto/test_prefix.proto \
+ php/tests/proto/test_no_namespace.proto \
+ php/tests/test.sh \
+ php/tests/test_base.php \
+ php/tests/test_util.php \
+ php/tests/well_known_test.php \
+ php/README.md \
+ php/phpunit.xml \
+ php/composer.json \
+ php/generate_descriptor_protos.sh \
+ composer.json
+
+python_EXTRA_DIST= \
+ python/MANIFEST.in \
+ python/google/__init__.py \
+ python/google/protobuf/__init__.py \
+ python/google/protobuf/descriptor.py \
+ python/google/protobuf/descriptor_database.py \
+ python/google/protobuf/descriptor_pool.py \
+ python/google/protobuf/internal/__init__.py \
+ python/google/protobuf/internal/_parameterized.py \
+ python/google/protobuf/internal/any_test.proto \
+ python/google/protobuf/internal/any_test.proto \
+ python/google/protobuf/internal/api_implementation.cc \
+ python/google/protobuf/internal/api_implementation.py \
+ python/google/protobuf/internal/containers.py \
+ python/google/protobuf/internal/decoder.py \
+ python/google/protobuf/internal/descriptor_database_test.py \
+ python/google/protobuf/internal/descriptor_pool_test.py \
+ python/google/protobuf/internal/descriptor_pool_test1.proto \
+ python/google/protobuf/internal/descriptor_pool_test2.proto \
+ python/google/protobuf/internal/descriptor_test.py \
+ python/google/protobuf/internal/encoder.py \
+ python/google/protobuf/internal/enum_type_wrapper.py \
+ python/google/protobuf/internal/factory_test1.proto \
+ python/google/protobuf/internal/factory_test2.proto \
+ python/google/protobuf/internal/file_options_test.proto \
+ python/google/protobuf/internal/generator_test.py \
+ python/google/protobuf/internal/import_test_package/__init__.py \
+ python/google/protobuf/internal/import_test_package/inner.proto \
+ python/google/protobuf/internal/import_test_package/outer.proto \
+ python/google/protobuf/internal/json_format_test.py \
+ python/google/protobuf/internal/message_factory_test.py \
+ python/google/protobuf/internal/message_listener.py \
+ python/google/protobuf/internal/message_set_extensions.proto \
+ python/google/protobuf/internal/message_test.py \
+ python/google/protobuf/internal/missing_enum_values.proto \
+ python/google/protobuf/internal/more_extensions.proto \
+ python/google/protobuf/internal/more_extensions_dynamic.proto \
+ python/google/protobuf/internal/more_messages.proto \
+ python/google/protobuf/internal/packed_field_test.proto \
+ python/google/protobuf/internal/proto_builder_test.py \
+ python/google/protobuf/internal/python_message.py \
+ python/google/protobuf/internal/reflection_test.py \
+ python/google/protobuf/internal/service_reflection_test.py \
+ python/google/protobuf/internal/symbol_database_test.py \
+ python/google/protobuf/internal/test_bad_identifiers.proto \
+ python/google/protobuf/internal/test_util.py \
+ python/google/protobuf/internal/testing_refleaks.py \
+ python/google/protobuf/internal/text_encoding_test.py \
+ python/google/protobuf/internal/text_format_test.py \
+ python/google/protobuf/internal/type_checkers.py \
+ python/google/protobuf/internal/unknown_fields_test.py \
+ python/google/protobuf/internal/well_known_types.py \
+ python/google/protobuf/internal/well_known_types.py \
+ python/google/protobuf/internal/well_known_types_test.py \
+ python/google/protobuf/internal/well_known_types_test.py \
+ python/google/protobuf/internal/wire_format.py \
+ python/google/protobuf/internal/wire_format_test.py \
+ python/google/protobuf/json_format.py \
+ python/google/protobuf/message.py \
+ python/google/protobuf/message_factory.py \
+ python/google/protobuf/proto_builder.py \
+ python/google/protobuf/pyext/README \
+ python/google/protobuf/pyext/__init__.py \
+ python/google/protobuf/pyext/cpp_message.py \
+ python/google/protobuf/pyext/descriptor.cc \
+ python/google/protobuf/pyext/descriptor.h \
+ python/google/protobuf/pyext/descriptor_containers.cc \
+ python/google/protobuf/pyext/descriptor_containers.h \
+ python/google/protobuf/pyext/descriptor_database.cc \
+ python/google/protobuf/pyext/descriptor_database.h \
+ python/google/protobuf/pyext/descriptor_pool.cc \
+ python/google/protobuf/pyext/descriptor_pool.h \
+ python/google/protobuf/pyext/extension_dict.cc \
+ python/google/protobuf/pyext/extension_dict.h \
+ python/google/protobuf/pyext/map_container.cc \
+ python/google/protobuf/pyext/map_container.h \
+ python/google/protobuf/pyext/message.cc \
+ python/google/protobuf/pyext/message.h \
+ python/google/protobuf/pyext/message_factory.cc \
+ python/google/protobuf/pyext/message_factory.h \
+ python/google/protobuf/pyext/message_module.cc \
+ python/google/protobuf/pyext/proto2_api_test.proto \
+ python/google/protobuf/pyext/python.proto \
+ python/google/protobuf/pyext/python_protobuf.h \
+ python/google/protobuf/pyext/repeated_composite_container.cc \
+ python/google/protobuf/pyext/repeated_composite_container.h \
+ python/google/protobuf/pyext/repeated_scalar_container.cc \
+ python/google/protobuf/pyext/repeated_scalar_container.h \
+ python/google/protobuf/pyext/safe_numerics.h \
+ python/google/protobuf/pyext/scoped_pyobject_ptr.h \
+ python/google/protobuf/reflection.py \
+ python/google/protobuf/service.py \
+ python/google/protobuf/service_reflection.py \
+ python/google/protobuf/symbol_database.py \
+ python/google/protobuf/text_encoding.py \
+ python/google/protobuf/text_format.py \
+ python/mox.py \
+ python/setup.cfg \
+ python/setup.py \
+ python/stubout.py \
+ python/tox.ini \
+ python/README.md
+
+ruby_EXTRA_DIST= \
+ ruby/Gemfile \
+ ruby/.gitignore \
+ ruby/README.md \
+ ruby/Rakefile \
+ ruby/compatibility_tests/v3.0.0/tests/test_import.proto \
+ ruby/compatibility_tests/v3.0.0/tests/stress.rb \
+ ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb \
+ ruby/compatibility_tests/v3.0.0/tests/generated_code_test.rb \
+ ruby/compatibility_tests/v3.0.0/tests/generated_code.proto \
+ ruby/compatibility_tests/v3.0.0/tests/basic.rb \
+ ruby/compatibility_tests/v3.0.0/test.sh \
+ ruby/compatibility_tests/v3.0.0/Rakefile \
+ ruby/compatibility_tests/v3.0.0/README.md \
+ ruby/ext/google/protobuf_c/defs.c \
+ ruby/ext/google/protobuf_c/encode_decode.c \
+ ruby/ext/google/protobuf_c/extconf.rb \
+ ruby/ext/google/protobuf_c/map.c \
+ ruby/ext/google/protobuf_c/message.c \
+ ruby/ext/google/protobuf_c/protobuf.c \
+ ruby/ext/google/protobuf_c/protobuf.h \
+ ruby/ext/google/protobuf_c/repeated_field.c \
+ ruby/ext/google/protobuf_c/storage.c \
+ ruby/ext/google/protobuf_c/upb.c \
+ ruby/ext/google/protobuf_c/upb.h \
+ ruby/ext/google/protobuf_c/wrap_memcpy.c \
+ ruby/google-protobuf.gemspec \
+ ruby/lib/google/protobuf/message_exts.rb \
+ ruby/lib/google/protobuf/repeated_field.rb \
+ ruby/lib/google/protobuf/well_known_types.rb \
+ ruby/lib/google/protobuf.rb \
+ ruby/pom.xml \
+ ruby/src/main/java/com/google/protobuf/jruby/RubyBuilder.java \
+ ruby/src/main/java/com/google/protobuf/jruby/RubyDescriptor.java \
+ ruby/src/main/java/com/google/protobuf/jruby/RubyDescriptorPool.java \
+ ruby/src/main/java/com/google/protobuf/jruby/RubyEnumBuilderContext.java \
+ ruby/src/main/java/com/google/protobuf/jruby/RubyEnumDescriptor.java \
+ ruby/src/main/java/com/google/protobuf/jruby/RubyEnum.java \
+ ruby/src/main/java/com/google/protobuf/jruby/RubyFieldDescriptor.java \
+ ruby/src/main/java/com/google/protobuf/jruby/RubyMap.java \
+ ruby/src/main/java/com/google/protobuf/jruby/RubyMessageBuilderContext.java \
+ ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java \
+ ruby/src/main/java/com/google/protobuf/jruby/RubyOneofBuilderContext.java \
+ ruby/src/main/java/com/google/protobuf/jruby/RubyOneofDescriptor.java \
+ ruby/src/main/java/com/google/protobuf/jruby/RubyProtobuf.java \
+ ruby/src/main/java/com/google/protobuf/jruby/RubyRepeatedField.java \
+ ruby/src/main/java/com/google/protobuf/jruby/SentinelOuterClass.java \
+ ruby/src/main/java/com/google/protobuf/jruby/Utils.java \
+ ruby/src/main/java/google/ProtobufJavaService.java \
+ ruby/src/main/sentinel.proto \
+ ruby/tests/basic.rb \
+ ruby/tests/repeated_field_test.rb \
+ ruby/tests/stress.rb \
+ ruby/tests/generated_code.proto \
+ ruby/tests/test_import.proto \
+ ruby/tests/generated_code_test.rb \
+ ruby/tests/well_known_types_test.rb \
+ ruby/travis-test.sh
+
+js_EXTRA_DIST= \
+ js/README.md \
+ js/binary/arith.js \
+ js/binary/arith_test.js \
+ js/binary/constants.js \
+ js/binary/decoder.js \
+ js/binary/decoder_test.js \
+ js/binary/encoder.js \
+ js/binary/message_test.js \
+ js/binary/proto_test.js \
+ js/binary/reader.js \
+ js/binary/reader_test.js \
+ js/binary/utils.js \
+ js/binary/utils_test.js \
+ js/binary/writer.js \
+ js/binary/writer_test.js \
+ js/commonjs/export.js \
+ js/commonjs/export_asserts.js \
+ js/commonjs/export_testdeps.js \
+ js/commonjs/import_test.js \
+ js/commonjs/jasmine.json \
+ js/commonjs/rewrite_tests_for_commonjs.js \
+ js/commonjs/test6/test6.proto \
+ js/commonjs/test7/test7.proto \
+ js/data.proto \
+ js/debug.js \
+ js/debug_test.js \
+ js/gulpfile.js \
+ js/jasmine.json \
+ js/map.js \
+ js/maps_test.js \
+ js/message.js \
+ js/message_test.js \
+ js/node_loader.js \
+ js/package.json \
+ js/proto3_test.js \
+ js/proto3_test.proto \
+ js/test.proto \
+ js/test2.proto \
+ js/test3.proto \
+ js/test4.proto \
+ js/test5.proto \
+ js/test8.proto \
+ js/test_bootstrap.js \
+ js/testbinary.proto \
+ js/testempty.proto
+
+all_EXTRA_DIST=$(csharp_EXTRA_DIST) $(java_EXTRA_DIST) $(javanano_EXTRA_DIST) $(objectivec_EXTRA_DIST) $(php_EXTRA_DIST) $(python_EXTRA_DIST) $(ruby_EXTRA_DIST) $(js_EXTRA_DIST)
+
+EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \
+ autogen.sh \
+ generate_descriptor_proto.sh \
+ README.md \
+ LICENSE \
+ CONTRIBUTORS.txt \
+ CHANGES.txt \
+ update_file_lists.sh \
+ BUILD \
+ gmock.BUILD \
+ WORKSPACE \
+ cmake/CMakeLists.txt \
+ cmake/README.md \
+ cmake/examples.cmake \
+ cmake/extract_includes.bat.in \
+ cmake/install.cmake \
+ cmake/libprotobuf.cmake \
+ cmake/libprotobuf-lite.cmake \
+ cmake/libprotoc.cmake \
+ cmake/protobuf-config-version.cmake.in \
+ cmake/protobuf-config.cmake.in \
+ cmake/protobuf-module.cmake.in \
+ cmake/protobuf-options.cmake \
+ cmake/protoc.cmake \
+ cmake/tests.cmake \
+ editors/README.txt \
+ editors/proto.vim \
+ editors/protobuf-mode.el \
+ examples/CMakeLists.txt \
+ examples/README.txt \
+ examples/Makefile \
+ examples/addressbook.proto \
+ examples/add_person.cc \
+ examples/add_person.go \
+ examples/add_person_test.go \
+ examples/list_people.cc \
+ examples/list_people.go \
+ examples/AddPerson.java \
+ examples/CMakeLists.txt \
+ examples/ListPeople.java \
+ examples/add_person.py \
+ examples/list_people.py \
+ examples/list_people_test.go \
+ protobuf.bzl \
+ six.BUILD \
+ util/python/BUILD
+
+# Deletes all the files generated by autogen.sh.
+MAINTAINERCLEANFILES = \
+ aclocal.m4 \
+ ar-lib \
+ config.guess \
+ config.sub \
+ configure \
+ depcomp \
+ install-sh \
+ ltmain.sh \
+ Makefile.in \
+ missing \
+ mkinstalldirs \
+ config.h.in \
+ stamp.h.in \
+ m4/ltsugar.m4 \
+ m4/libtool.m4 \
+ m4/ltversion.m4 \
+ m4/lt~obsolete.m4 \
+ m4/ltoptions.m4
diff --git a/third_party/protobuf/Protobuf.podspec b/third_party/protobuf/Protobuf.podspec
new file mode 100644
index 0000000000..0db70650ef
--- /dev/null
+++ b/third_party/protobuf/Protobuf.podspec
@@ -0,0 +1,41 @@
+# This file describes to Cocoapods how to integrate the Objective-C runtime into a dependent
+# project.
+# Despite this file being specific to Objective-C, it needs to be on the root of the repository.
+# Otherwise, Cocoapods gives trouble like not picking up the license file correctly, or not letting
+# dependent projects use the :git notation to refer to the library.
+Pod::Spec.new do |s|
+ s.name = 'Protobuf'
+ s.version = '3.2.0'
+ s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.'
+ s.homepage = 'https://github.com/google/protobuf'
+ s.license = '3-Clause BSD License'
+ s.authors = { 'The Protocol Buffers contributors' => 'protobuf@googlegroups.com' }
+ s.cocoapods_version = '>= 1.0'
+
+ s.source = { :git => 'https://github.com/google/protobuf.git',
+ :tag => "v#{s.version}" }
+
+ s.source_files = 'objectivec/*.{h,m}',
+ 'objectivec/google/protobuf/Any.pbobjc.{h,m}',
+ 'objectivec/google/protobuf/Api.pbobjc.{h,m}',
+ 'objectivec/google/protobuf/Duration.pbobjc.{h,m}',
+ 'objectivec/google/protobuf/Empty.pbobjc.{h,m}',
+ 'objectivec/google/protobuf/FieldMask.pbobjc.{h,m}',
+ 'objectivec/google/protobuf/SourceContext.pbobjc.{h,m}',
+ 'objectivec/google/protobuf/Struct.pbobjc.{h,m}',
+ 'objectivec/google/protobuf/Timestamp.pbobjc.{h,m}',
+ 'objectivec/google/protobuf/Type.pbobjc.{h,m}',
+ 'objectivec/google/protobuf/Wrappers.pbobjc.{h,m}'
+ # The following would cause duplicate symbol definitions. GPBProtocolBuffers is expected to be
+ # left out, as it's an umbrella implementation file.
+ s.exclude_files = 'objectivec/GPBProtocolBuffers.m'
+
+ # Set a CPP symbol so the code knows to use framework imports.
+ s.user_target_xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1' }
+ s.pod_target_xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1' }
+
+ s.ios.deployment_target = '7.0'
+ s.osx.deployment_target = '10.9'
+ s.watchos.deployment_target = '2.0'
+ s.requires_arc = false
+end
diff --git a/third_party/protobuf/README.bazel.md b/third_party/protobuf/README.bazel.md
new file mode 100644
index 0000000000..beec722ee6
--- /dev/null
+++ b/third_party/protobuf/README.bazel.md
@@ -0,0 +1,31 @@
+# Updating protobuf
+
+1) Fetch the desired version from https://github.com/google/protobuf,
+ extract everything into a new directory and change into it.
+2) Bazel uses upstream protobuf from source, except for java, as we
+ currently don't build protobuf java when bootstrapping bazel. So
+ instead we use already build jars. Go to `search.maven.org` and
+ search for `com.google.protobuf` and download the jars for protobuf-java
+ and protobuf-java-util and place them in the new directory.
+3) Modify protobuf's `BUILD` file to not build java from source, but to use
+ the jars instead. To do that, in the BUILD file delete the rules listed
+ under `Java support`. Then, from the `third_party/protobuf/BUILD file`
+ copy the rules under "Modifications made by bazel" to the new BUILD file.
+ Those rules should have the same names as the ones you just deleted. You
+ will need to update the names of the jars in the rules sources to the
+ ones you just downloaded.
+4) Copy `third_party/protobuf/com_google_protobuf_java.BUILD` to the new
+ directory.
+5) Copy this file to the new directory and update it if you found the
+ instructions to be wrong or incomplete.
+6) Replace the contents in `third_party/protobuf` with the contents in this
+ directory.
+7) Delete this directory.
+
+# Current protobuf version
+
+The current version of protobuf was obtained from @laszlocsomor's protobuf fork
+`https://github.com/laszlocsomor/protobuf` at commit `421d90960d`. Once
+`https://github.com/google/protobuf/pull/2969` is merged into upstream
+protobuf, we no longer need to use @laszlocsomor's fork but can directly clone
+upstream.
diff --git a/third_party/protobuf/README.md b/third_party/protobuf/README.md
index 367d542d06..b26e5424af 100644
--- a/third_party/protobuf/README.md
+++ b/third_party/protobuf/README.md
@@ -1,28 +1,77 @@
-### Updating the jar binary
-
-1. Go to http://search.maven.org/
-2. Search for g:"com.google.protobuf"
-3. Download the "jar" link from protobuf-java and put them in `<Bazel tree>/third_party/protobuf/<version>`
-
-* * *
-### Updating `protobuf.bzl` and the `src/` directory:
-
-1. `git clone http://github.com/google/protobuf.git`
-2. `git checkout <tag or commithash>` (e.g. `v3.0.0` or `e8ae137`)
-3. `mkdir -p third_party/protobuf/<version>/src/google` in the root of the Bazel tree.
-4. `cp -R <root of protobuf tree>/src/google/protobuf third_party/protobuf/src/google`
-5. Update the rules in `third_party/protobuf/BUILD` with the rules in the protobuf repository.
-
-Finally, update the rules:
-
-1. Add a BUILD file to `third_party/protobuf/<version>/`. Use the BUILD file
- for the previous version as a template. Update the `cc_library` rules to
- match the rules in the BUILD file in the protobuf repository. Also copy
- `protobuf.bzl` from the protobuf repository into
- `third_party/protobuf/<version>/`.
-2. Modify `third_party/protobuf/BUILD` to point to the new rules.
-3. Delete the old version of protobuf.
-
-* * *
-### Updating anything else in the directory
-Follow usual procedure as described on https://www.bazel.build/contributing.html
+Protocol Buffers - Google's data interchange format
+===================================================
+
+[![Build Status](https://travis-ci.org/google/protobuf.svg?branch=master)](https://travis-ci.org/google/protobuf) [![Build status](https://ci.appveyor.com/api/projects/status/73ctee6ua4w2ruin?svg=true)](https://ci.appveyor.com/project/protobuf/protobuf) [![Build Status](https://grpc-testing.appspot.com/buildStatus/icon?job=protobuf_branch)](https://grpc-testing.appspot.com/job/protobuf_branch) [![Build Status](https://grpc-testing.appspot.com/job/protobuf_branch_32/badge/icon)](https://grpc-testing.appspot.com/job/protobuf_branch_32) [![Build Status](http://ci.bazel.io/buildStatus/icon?job=protobuf)](http://ci.bazel.io/job/protobuf/)
+
+Copyright 2008 Google Inc.
+
+https://developers.google.com/protocol-buffers/
+
+Overview
+--------
+
+Protocol Buffers (a.k.a., protobuf) are Google's language-neutral,
+platform-neutral, extensible mechanism for serializing structured data. You
+can find [protobuf's documentation on the Google Developers site](https://developers.google.com/protocol-buffers/).
+
+This README file contains protobuf installation instructions. To install
+protobuf, you need to install the protocol compiler (used to compile .proto
+files) and the protobuf runtime for your chosen programming language.
+
+Protocol Compiler Installation
+------------------------------
+
+The protocol compiler is written in C++. If you are using C++, please follow
+the [C++ Installation Instructions](src/README.md) to install protoc along
+with the C++ runtime.
+
+For non-C++ users, the simplest way to install the protocol compiler is to
+download a pre-built binary from our release page:
+
+ [https://github.com/google/protobuf/releases](https://github.com/google/protobuf/releases)
+
+In the downloads section of each release, you can find pre-built binaries in
+zip packages: protoc-$VERSION-$PLATFORM.zip. It contains the protoc binary
+as well as a set of standard .proto files distributed along with protobuf.
+
+If you are looking for an old version that is not available in the release
+page, check out the maven repo here:
+
+ [http://repo1.maven.org/maven2/com/google/protobuf/protoc/](http://repo1.maven.org/maven2/com/google/protobuf/protoc/)
+
+These pre-built binaries are only provided for released versions. If you want
+to use the github master version at HEAD, or you need to modify protobuf code,
+or you are using C++, it's recommended to build your own protoc binary from
+source.
+
+If you would like to build protoc binary from source, see the [C++ Installation
+Instructions](src/README.md).
+
+Protobuf Runtime Installation
+-----------------------------
+
+Protobuf supports several different programming languages. For each programming
+language, you can find instructions in the corresponding source directory about
+how to install protobuf runtime for that specific language:
+
+| Language | Source |
+|--------------------------------------|-------------------------------------------------------|
+| C++ (include C++ runtime and protoc) | [src](src) |
+| Java | [java](java) |
+| Python | [python](python) |
+| Objective-C | [objectivec](objectivec) |
+| C# | [csharp](csharp) |
+| JavaNano | [javanano](javanano) |
+| JavaScript | [js](js) |
+| Ruby | [ruby](ruby) |
+| Go | [golang/protobuf](https://github.com/golang/protobuf) |
+| PHP | [php](php) |
+
+
+Usage
+-----
+
+The complete documentation for Protocol Buffers is available via the
+web at:
+
+https://developers.google.com/protocol-buffers/
diff --git a/third_party/protobuf/WORKSPACE b/third_party/protobuf/WORKSPACE
new file mode 100644
index 0000000000..2a49e3723a
--- /dev/null
+++ b/third_party/protobuf/WORKSPACE
@@ -0,0 +1,53 @@
+new_git_repository(
+ name = "googletest",
+ build_file = "gmock.BUILD",
+ remote = "https://github.com/google/googletest",
+ tag = "release-1.8.0",
+)
+
+new_http_archive(
+ name = "six_archive",
+ build_file = "six.BUILD",
+ sha256 = "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a",
+ url = "https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz#md5=34eed507548117b2ab523ab14b2f8b55",
+)
+
+bind(
+ name = "python_headers",
+ actual = "//util/python:python_headers",
+)
+
+bind(
+ name = "gtest",
+ actual = "@googletest//:gtest",
+)
+
+bind(
+ name = "gtest_main",
+ actual = "@googletest//:gtest_main",
+)
+
+bind(
+ name = "six",
+ actual = "@six_archive//:six",
+)
+
+maven_jar(
+ name = "guava_maven",
+ artifact = "com.google.guava:guava:18.0",
+)
+
+bind(
+ name = "guava",
+ actual = "@guava_maven//jar",
+)
+
+maven_jar(
+ name = "gson_maven",
+ artifact = "com.google.code.gson:gson:2.7",
+)
+
+bind(
+ name = "gson",
+ actual = "@gson_maven//jar",
+)
diff --git a/third_party/protobuf/appveyor.bat b/third_party/protobuf/appveyor.bat
new file mode 100644
index 0000000000..916f4434fe
--- /dev/null
+++ b/third_party/protobuf/appveyor.bat
@@ -0,0 +1,32 @@
+setlocal
+
+IF %language%==cpp GOTO build_cpp
+IF %language%==csharp GOTO build_csharp
+
+echo Unsupported language %language%. Exiting.
+goto :error
+
+:build_cpp
+echo Building C++
+mkdir build_msvc
+cd build_msvc
+cmake -G "%generator%" -Dprotobuf_BUILD_SHARED_LIBS=%BUILD_DLL% -Dprotobuf_UNICODE=%UNICODE% ../cmake
+msbuild protobuf.sln /p:Platform=%vcplatform% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" || goto error
+cd %configuration%
+tests.exe || goto error
+goto :EOF
+
+:build_csharp
+echo Building C#
+cd csharp\src
+dotnet restore
+dotnet build -c %configuration% Google.Protobuf Google.Protobuf.Test Google.Protobuf.Conformance || goto error
+
+echo Testing C#
+dotnet test -c %configuration% Google.Protobuf.Test || goto error
+
+goto :EOF
+
+:error
+echo Failed!
+EXIT /b %ERRORLEVEL%
diff --git a/third_party/protobuf/appveyor.yml b/third_party/protobuf/appveyor.yml
new file mode 100644
index 0000000000..08d087b699
--- /dev/null
+++ b/third_party/protobuf/appveyor.yml
@@ -0,0 +1,45 @@
+# Only test one combination: "Visual Studio 12 + Win64 + Debug + DLL". We can
+# test more combinations but AppVeyor just takes too long to finish (each
+# combination takes ~15mins).
+platform:
+ - Win64
+
+configuration:
+ - Debug
+
+environment:
+ matrix:
+ - language: cpp
+ BUILD_DLL: ON
+ UNICODE: ON
+
+ - language: csharp
+
+# Our build scripts run tests automatically; we don't want AppVeyor
+# to try to detect them itself.
+test: off
+
+install:
+ - curl -L -o release-1.7.0.zip https://github.com/google/googlemock/archive/release-1.7.0.zip
+ - 7z x release-1.7.0.zip
+ - del /Q release-1.7.0.zip
+ - rename googlemock-release-1.7.0 gmock
+ - curl -L -o release-1.7.0.zip "https://github.com/google/googletest/archive/release-1.7.0.zip"
+ - 7z x release-1.7.0.zip
+ - del /Q release-1.7.0.zip
+ - rename googletest-release-1.7.0 gtest
+ - move gtest gmock
+ - curl -L -o dotnetsdk.exe "https://go.microsoft.com/fwlink/?LinkID=809122"
+ - dotnetsdk.exe /install /quiet /norestart
+
+before_build:
+ - if %platform%==Win32 set generator=Visual Studio 12
+ - if %platform%==Win64 set generator=Visual Studio 12 Win64
+ - if %platform%==Win32 set vcplatform=Win32
+ - if %platform%==Win64 set vcplatform=x64
+
+build_script:
+ - CALL appveyor.bat
+
+skip_commits:
+ message: /.*\[skip appveyor\].*/
diff --git a/third_party/protobuf/autogen.sh b/third_party/protobuf/autogen.sh
new file mode 100755
index 0000000000..9f26642585
--- /dev/null
+++ b/third_party/protobuf/autogen.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+# Run this script to generate the configure script and other files that will
+# be included in the distribution. These files are not checked in because they
+# are automatically generated.
+
+set -e
+
+if [ ! -z "$@" ]; then
+ for argument in "$@"; do
+ case $argument in
+ # make curl silent
+ "-s")
+ curlopts="-s"
+ ;;
+ esac
+ done
+fi
+
+
+# Check that we're being run from the right directory.
+if test ! -f src/google/protobuf/stubs/common.h; then
+ cat >&2 << __EOF__
+Could not find source code. Make sure you are running this script from the
+root of the distribution tree.
+__EOF__
+ exit 1
+fi
+
+# Check that gmock is present. Usually it is already there since the
+# directory is set up as an SVN external.
+if test ! -e gmock; then
+ echo "Google Mock not present. Fetching gmock-1.7.0 from the web..."
+ curl $curlopts -L -O https://github.com/google/googlemock/archive/release-1.7.0.zip
+ unzip -q release-1.7.0.zip
+ rm release-1.7.0.zip
+ mv googlemock-release-1.7.0 gmock
+
+ curl $curlopts -L -O https://github.com/google/googletest/archive/release-1.7.0.zip
+ unzip -q release-1.7.0.zip
+ rm release-1.7.0.zip
+ mv googletest-release-1.7.0 gmock/gtest
+fi
+
+set -ex
+
+# TODO(kenton): Remove the ",no-obsolete" part and fix the resulting warnings.
+autoreconf -f -i -Wall,no-obsolete
+
+rm -rf autom4te.cache config.h.in~
+exit 0
diff --git a/third_party/protobuf/benchmarks/Makefile.am b/third_party/protobuf/benchmarks/Makefile.am
new file mode 100644
index 0000000000..d98eae5ead
--- /dev/null
+++ b/third_party/protobuf/benchmarks/Makefile.am
@@ -0,0 +1,78 @@
+
+benchmarks_protoc_inputs = \
+ benchmarks.proto \
+ benchmark_messages_proto3.proto
+
+benchmarks_protoc_inputs_proto2 = \
+ benchmark_messages_proto2.proto
+
+benchmarks_protoc_outputs = \
+ benchmarks.pb.cc \
+ benchmarks.pb.h \
+ benchmark_messages_proto3.pb.cc \
+ benchmark_messages_proto3.pb.h
+
+benchmarks_protoc_outputs_proto2 = \
+ benchmark_messages_proto2.pb.cc \
+ benchmark_messages_proto2.pb.h
+
+AM_CXXFLAGS = $(NO_OPT_CXXFLAGS) $(PROTOBUF_OPT_FLAG) -Wall -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare
+
+bin_PROGRAMS = generate-datasets cpp-benchmark
+
+generate_datasets_LDADD = $(top_srcdir)/src/libprotobuf.la
+generate_datasets_SOURCES = generate_datasets.cc
+generate_datasets_CPPFLAGS = -I$(top_srcdir)/src -I$(srcdir)
+nodist_generate_datasets_SOURCES = \
+ $(benchmarks_protoc_outputs) \
+ $(benchmarks_protoc_outputs_proto2)
+
+# Explicit deps because BUILT_SOURCES are only done before a "make all/check"
+# so a direct "make test_cpp" could fail if parallel enough.
+# See: https://www.gnu.org/software/automake/manual/html_node/Built-Sources-Example.html#Recording-Dependencies-manually
+generate_datasets-generate_datasets.$(OBJEXT): benchmarks.pb.h
+
+cpp_benchmark_LDADD = $(top_srcdir)/src/libprotobuf.la $(top_srcdir)/third_party/benchmark/src/libbenchmark.a
+cpp_benchmark_SOURCES = cpp_benchmark.cc
+cpp_benchmark_CPPFLAGS = -I$(top_srcdir)/src -I$(srcdir) -I$(top_srcdir)/third_party/benchmark/include
+nodist_cpp_benchmark_SOURCES = \
+ $(benchmarks_protoc_outputs) \
+ $(benchmarks_protoc_outputs_proto2)
+
+$(benchmarks_protoc_outputs): protoc_middleman
+$(benchmarks_protoc_outputs_proto2): protoc_middleman2
+
+CLEANFILES = \
+ $(benchmarks_protoc_outputs) \
+ $(benchmarks_protoc_outputs_proto2) \
+ protoc_middleman \
+ protoc_middleman2 \
+ dataset.*
+
+MAINTAINERCLEANFILES = \
+ Makefile.in
+
+if USE_EXTERNAL_PROTOC
+
+protoc_middleman: $(benchmarks_protoc_inputs)
+ $(PROTOC) -I$(srcdir) -I$(top_srcdir) --cpp_out=. $(benchmarks_protoc_inputs)
+ touch protoc_middleman
+
+protoc_middleman2: $(benchmarks_protoc_inputs_proto2)
+ $(PROTOC) -I$(srcdir) -I$(top_srcdir) --cpp_out=. $(benchmarks_protoc_inputs_proto2)
+ touch protoc_middleman2
+
+else
+
+# We have to cd to $(srcdir) before executing protoc because $(protoc_inputs) is
+# relative to srcdir, which may not be the same as the current directory when
+# building out-of-tree.
+protoc_middleman: $(top_srcdir)/src/protoc$(EXEEXT) $(benchmarks_protoc_inputs) $(well_known_type_protoc_inputs)
+ oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --cpp_out=$$oldpwd $(benchmarks_protoc_inputs) )
+ touch protoc_middleman
+
+protoc_middleman2: $(top_srcdir)/src/protoc$(EXEEXT) $(benchmarks_protoc_inputs_proto2) $(well_known_type_protoc_inputs)
+ oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --cpp_out=$$oldpwd $(benchmarks_protoc_inputs_proto2) )
+ touch protoc_middleman
+
+endif
diff --git a/third_party/protobuf/benchmarks/ProtoBench.java b/third_party/protobuf/benchmarks/ProtoBench.java
new file mode 100644
index 0000000000..86d62feb67
--- /dev/null
+++ b/third_party/protobuf/benchmarks/ProtoBench.java
@@ -0,0 +1,203 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2009 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.protocolbuffers;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.lang.reflect.Method;
+
+import com.google.protobuf.ByteString;
+import com.google.protobuf.CodedInputStream;
+import com.google.protobuf.CodedOutputStream;
+import com.google.protobuf.Message;
+
+public class ProtoBench {
+
+ private static final long MIN_SAMPLE_TIME_MS = 2 * 1000;
+ private static final long TARGET_TIME_MS = 30 * 1000;
+
+ private ProtoBench() {
+ // Prevent instantiation
+ }
+
+ public static void main(String[] args) {
+ if (args.length < 2 || (args.length % 2) != 0) {
+ System.err.println("Usage: ProtoBench <descriptor type name> <input data>");
+ System.err.println("The descriptor type name is the fully-qualified message name,");
+ System.err.println("e.g. com.google.protocolbuffers.benchmark.Message1");
+ System.err.println("(You can specify multiple pairs of descriptor type name and input data.)");
+ System.exit(1);
+ }
+ boolean success = true;
+ for (int i = 0; i < args.length; i += 2) {
+ success &= runTest(args[i], args[i + 1]);
+ }
+ System.exit(success ? 0 : 1);
+ }
+
+ /**
+ * Runs a single test. Error messages are displayed to stderr, and the return value
+ * indicates general success/failure.
+ */
+ public static boolean runTest(String type, String file) {
+ System.out.println("Benchmarking " + type + " with file " + file);
+ final Message defaultMessage;
+ try {
+ Class<?> clazz = Class.forName(type);
+ Method method = clazz.getDeclaredMethod("getDefaultInstance");
+ defaultMessage = (Message) method.invoke(null);
+ } catch (Exception e) {
+ // We want to do the same thing with all exceptions. Not generally nice,
+ // but this is slightly different.
+ System.err.println("Unable to get default message for " + type);
+ return false;
+ }
+
+ try {
+ final byte[] inputData = readAllBytes(file);
+ final ByteArrayInputStream inputStream = new ByteArrayInputStream(inputData);
+ final ByteString inputString = ByteString.copyFrom(inputData);
+ final Message sampleMessage = defaultMessage.newBuilderForType().mergeFrom(inputString).build();
+ FileOutputStream devNullTemp = null;
+ CodedOutputStream reuseDevNullTemp = null;
+ try {
+ devNullTemp = new FileOutputStream("/dev/null");
+ reuseDevNullTemp = CodedOutputStream.newInstance(devNullTemp);
+ } catch (FileNotFoundException e) {
+ // ignore: this is probably Windows, where /dev/null does not exist
+ }
+ final FileOutputStream devNull = devNullTemp;
+ final CodedOutputStream reuseDevNull = reuseDevNullTemp;
+ benchmark("Serialize to byte string", inputData.length, new Action() {
+ public void execute() { sampleMessage.toByteString(); }
+ });
+ benchmark("Serialize to byte array", inputData.length, new Action() {
+ public void execute() { sampleMessage.toByteArray(); }
+ });
+ benchmark("Serialize to memory stream", inputData.length, new Action() {
+ public void execute() throws IOException {
+ sampleMessage.writeTo(new ByteArrayOutputStream());
+ }
+ });
+ if (devNull != null) {
+ benchmark("Serialize to /dev/null with FileOutputStream", inputData.length, new Action() {
+ public void execute() throws IOException {
+ sampleMessage.writeTo(devNull);
+ }
+ });
+ benchmark("Serialize to /dev/null reusing FileOutputStream", inputData.length, new Action() {
+ public void execute() throws IOException {
+ sampleMessage.writeTo(reuseDevNull);
+ reuseDevNull.flush(); // force the write to the OutputStream
+ }
+ });
+ }
+ benchmark("Deserialize from byte string", inputData.length, new Action() {
+ public void execute() throws IOException {
+ defaultMessage.newBuilderForType().mergeFrom(inputString).build();
+ }
+ });
+ benchmark("Deserialize from byte array", inputData.length, new Action() {
+ public void execute() throws IOException {
+ defaultMessage.newBuilderForType()
+ .mergeFrom(CodedInputStream.newInstance(inputData)).build();
+ }
+ });
+ benchmark("Deserialize from memory stream", inputData.length, new Action() {
+ public void execute() throws IOException {
+ defaultMessage.newBuilderForType()
+ .mergeFrom(CodedInputStream.newInstance(inputStream)).build();
+ inputStream.reset();
+ }
+ });
+ System.out.println();
+ return true;
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ System.err.println("Detailed exception information:");
+ e.printStackTrace(System.err);
+ return false;
+ }
+ }
+
+ private static void benchmark(String name, long dataSize, Action action) throws IOException {
+ // Make sure it's JITted "reasonably" hard before running the first progress test
+ for (int i=0; i < 100; i++) {
+ action.execute();
+ }
+
+ // Run it progressively more times until we've got a reasonable sample
+ int iterations = 1;
+ long elapsed = timeAction(action, iterations);
+ while (elapsed < MIN_SAMPLE_TIME_MS) {
+ iterations *= 2;
+ elapsed = timeAction(action, iterations);
+ }
+
+ // Upscale the sample to the target time. Do this in floating point arithmetic
+ // to avoid overflow issues.
+ iterations = (int) ((TARGET_TIME_MS / (double) elapsed) * iterations);
+ elapsed = timeAction(action, iterations);
+ System.out.println(name + ": " + iterations + " iterations in "
+ + (elapsed/1000f) + "s; "
+ + (iterations * dataSize) / (elapsed * 1024 * 1024 / 1000f)
+ + "MB/s");
+ }
+
+ private static long timeAction(Action action, int iterations) throws IOException {
+ System.gc();
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < iterations; i++) {
+ action.execute();
+ }
+ long end = System.currentTimeMillis();
+ return end - start;
+ }
+
+ private static byte[] readAllBytes(String filename) throws IOException {
+ RandomAccessFile file = new RandomAccessFile(new File(filename), "r");
+ byte[] content = new byte[(int) file.length()];
+ file.readFully(content);
+ return content;
+ }
+
+ /**
+ * Interface used to capture a single action to benchmark.
+ */
+ interface Action {
+ void execute() throws IOException;
+ }
+}
diff --git a/third_party/protobuf/benchmarks/README.md b/third_party/protobuf/benchmarks/README.md
new file mode 100644
index 0000000000..c902780582
--- /dev/null
+++ b/third_party/protobuf/benchmarks/README.md
@@ -0,0 +1,28 @@
+
+# Protocol Buffers Benchmarks
+
+This directory contains benchmarking schemas and data sets that you
+can use to test a variety of performance scenarios against your
+protobuf language runtime.
+
+The schema for the datasets is described in `benchmarks.proto`.
+
+Generate the data sets like so:
+
+```
+$ make
+$ ./generate-datasets
+Wrote dataset: dataset.google_message1_proto3.pb
+Wrote dataset: dataset.google_message1_proto2.pb
+Wrote dataset: dataset.google_message2.pb
+$
+```
+
+Each data set will be written to its own file. Benchmarks will
+likely want to run several benchmarks against each data set (parse,
+serialize, possibly JSON, possibly using different APIs, etc).
+
+We would like to add more data sets. In general we will favor data sets
+that make the overall suite diverse without being too large or having
+too many similar tests. Ideally everyone can run through the entire
+suite without the test run getting too long.
diff --git a/third_party/protobuf/benchmarks/benchmark_messages_proto2.proto b/third_party/protobuf/benchmarks/benchmark_messages_proto2.proto
new file mode 100644
index 0000000000..590855033c
--- /dev/null
+++ b/third_party/protobuf/benchmarks/benchmark_messages_proto2.proto
@@ -0,0 +1,143 @@
+// Benchmark messages for proto2.
+
+syntax = "proto2";
+
+package benchmarks.proto2;
+option java_package = "com.google.protobuf.benchmarks";
+
+// This is the default, but we specify it here explicitly.
+option optimize_for = SPEED;
+
+option cc_enable_arenas = true;
+
+message GoogleMessage1 {
+ required string field1 = 1;
+ optional string field9 = 9;
+ optional string field18 = 18;
+ optional bool field80 = 80 [default=false];
+ optional bool field81 = 81 [default=true];
+ required int32 field2 = 2;
+ required int32 field3 = 3;
+ optional int32 field280 = 280;
+ optional int32 field6 = 6 [default=0];
+ optional int64 field22 = 22;
+ optional string field4 = 4;
+ repeated fixed64 field5 = 5;
+ optional bool field59 = 59 [default=false];
+ optional string field7 = 7;
+ optional int32 field16 = 16;
+ optional int32 field130 = 130 [default=0];
+ optional bool field12 = 12 [default=true];
+ optional bool field17 = 17 [default=true];
+ optional bool field13 = 13 [default=true];
+ optional bool field14 = 14 [default=true];
+ optional int32 field104 = 104 [default=0];
+ optional int32 field100 = 100 [default=0];
+ optional int32 field101 = 101 [default=0];
+ optional string field102 = 102;
+ optional string field103 = 103;
+ optional int32 field29 = 29 [default=0];
+ optional bool field30 = 30 [default=false];
+ optional int32 field60 = 60 [default=-1];
+ optional int32 field271 = 271 [default=-1];
+ optional int32 field272 = 272 [default=-1];
+ optional int32 field150 = 150;
+ optional int32 field23 = 23 [default=0];
+ optional bool field24 = 24 [default=false];
+ optional int32 field25 = 25 [default=0];
+ optional GoogleMessage1SubMessage field15 = 15;
+ optional bool field78 = 78;
+ optional int32 field67 = 67 [default=0];
+ optional int32 field68 = 68;
+ optional int32 field128 = 128 [default=0];
+ optional string field129 = 129 [default="xxxxxxxxxxxxxxxxxxxxx"];
+ optional int32 field131 = 131 [default=0];
+}
+
+message GoogleMessage1SubMessage {
+ optional int32 field1 = 1 [default=0];
+ optional int32 field2 = 2 [default=0];
+ optional int32 field3 = 3 [default=0];
+ optional string field15 = 15;
+ optional bool field12 = 12 [default=true];
+ optional int64 field13 = 13;
+ optional int64 field14 = 14;
+ optional int32 field16 = 16;
+ optional int32 field19 = 19 [default=2];
+ optional bool field20 = 20 [default=true];
+ optional bool field28 = 28 [default=true];
+ optional fixed64 field21 = 21;
+ optional int32 field22 = 22;
+ optional bool field23 = 23 [ default=false ];
+ optional bool field206 = 206 [default=false];
+ optional fixed32 field203 = 203;
+ optional int32 field204 = 204;
+ optional string field205 = 205;
+ optional uint64 field207 = 207;
+ optional uint64 field300 = 300;
+}
+
+message GoogleMessage2 {
+ optional string field1 = 1;
+ optional int64 field3 = 3;
+ optional int64 field4 = 4;
+ optional int64 field30 = 30;
+ optional bool field75 = 75 [default=false];
+ optional string field6 = 6;
+ optional bytes field2 = 2;
+ optional int32 field21 = 21 [default=0];
+ optional int32 field71 = 71;
+ optional float field25 = 25;
+ optional int32 field109 = 109 [default=0];
+ optional int32 field210 = 210 [default=0];
+ optional int32 field211 = 211 [default=0];
+ optional int32 field212 = 212 [default=0];
+ optional int32 field213 = 213 [default=0];
+ optional int32 field216 = 216 [default=0];
+ optional int32 field217 = 217 [default=0];
+ optional int32 field218 = 218 [default=0];
+ optional int32 field220 = 220 [default=0];
+ optional int32 field221 = 221 [default=0];
+ optional float field222 = 222 [default=0.0];
+ optional int32 field63 = 63;
+
+ repeated group Group1 = 10 {
+ required float field11 = 11;
+ optional float field26 = 26;
+ optional string field12 = 12;
+ optional string field13 = 13;
+ repeated string field14 = 14;
+ required uint64 field15 = 15;
+ optional int32 field5 = 5;
+ optional string field27 = 27;
+ optional int32 field28 = 28;
+ optional string field29 = 29;
+ optional string field16 = 16;
+ repeated string field22 = 22;
+ repeated int32 field73 = 73;
+ optional int32 field20 = 20 [default=0];
+ optional string field24 = 24;
+ optional GoogleMessage2GroupedMessage field31 = 31;
+ }
+ repeated string field128 = 128;
+ optional int64 field131 = 131;
+ repeated string field127 = 127;
+ optional int32 field129 = 129;
+ repeated int64 field130 = 130;
+ optional bool field205 = 205 [default=false];
+ optional bool field206 = 206 [default=false];
+}
+
+message GoogleMessage2GroupedMessage {
+ optional float field1 = 1;
+ optional float field2 = 2;
+ optional float field3 = 3 [default=0.0];
+ optional bool field4 = 4;
+ optional bool field5 = 5;
+ optional bool field6 = 6 [default=true];
+ optional bool field7 = 7 [default=false];
+ optional float field8 = 8;
+ optional bool field9 = 9;
+ optional float field10 = 10;
+ optional int64 field11 = 11;
+}
diff --git a/third_party/protobuf/benchmarks/benchmark_messages_proto3.proto b/third_party/protobuf/benchmarks/benchmark_messages_proto3.proto
new file mode 100644
index 0000000000..090b554be9
--- /dev/null
+++ b/third_party/protobuf/benchmarks/benchmark_messages_proto3.proto
@@ -0,0 +1,78 @@
+// Benchmark messages for proto3.
+
+syntax = "proto3";
+
+package benchmarks.proto3;
+option java_package = "com.google.protobuf.benchmarks";
+
+// This is the default, but we specify it here explicitly.
+option optimize_for = SPEED;
+
+option cc_enable_arenas = true;
+
+message GoogleMessage1 {
+ string field1 = 1;
+ string field9 = 9;
+ string field18 = 18;
+ bool field80 = 80;
+ bool field81 = 81;
+ int32 field2 = 2;
+ int32 field3 = 3;
+ int32 field280 = 280;
+ int32 field6 = 6;
+ int64 field22 = 22;
+ string field4 = 4;
+ repeated fixed64 field5 = 5;
+ bool field59 = 59;
+ string field7 = 7;
+ int32 field16 = 16;
+ int32 field130 = 130;
+ bool field12 = 12;
+ bool field17 = 17;
+ bool field13 = 13;
+ bool field14 = 14;
+ int32 field104 = 104;
+ int32 field100 = 100;
+ int32 field101 = 101;
+ string field102 = 102;
+ string field103 = 103;
+ int32 field29 = 29;
+ bool field30 = 30;
+ int32 field60 = 60;
+ int32 field271 = 271;
+ int32 field272 = 272;
+ int32 field150 = 150;
+ int32 field23 = 23;
+ bool field24 = 24;
+ int32 field25 = 25;
+ GoogleMessage1SubMessage field15 = 15;
+ bool field78 = 78;
+ int32 field67 = 67;
+ int32 field68 = 68;
+ int32 field128 = 128;
+ string field129 = 129;
+ int32 field131 = 131;
+}
+
+message GoogleMessage1SubMessage {
+ int32 field1 = 1;
+ int32 field2 = 2;
+ int32 field3 = 3;
+ string field15 = 15;
+ bool field12 = 12;
+ int64 field13 = 13;
+ int64 field14 = 14;
+ int32 field16 = 16;
+ int32 field19 = 19;
+ bool field20 = 20;
+ bool field28 = 28;
+ fixed64 field21 = 21;
+ int32 field22 = 22;
+ bool field23 = 23;
+ bool field206 = 206;
+ fixed32 field203 = 203;
+ int32 field204 = 204;
+ string field205 = 205;
+ uint64 field207 = 207;
+ uint64 field300 = 300;
+}
diff --git a/third_party/protobuf/benchmarks/benchmarks.proto b/third_party/protobuf/benchmarks/benchmarks.proto
new file mode 100644
index 0000000000..51c0b54877
--- /dev/null
+++ b/third_party/protobuf/benchmarks/benchmarks.proto
@@ -0,0 +1,63 @@
+// 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.
+
+syntax = "proto3";
+package benchmarks;
+option java_package = "com.google.protobuf.benchmarks";
+
+message BenchmarkDataset {
+ // Name of the benchmark dataset. This should be unique across all datasets.
+ // Should only contain word characters: [a-zA-Z0-9_]
+ string name = 1;
+
+ // Fully-qualified name of the protobuf message for this dataset.
+ // It will be one of the messages defined benchmark_messages_proto2.proto
+ // or benchmark_messages_proto3.proto.
+ //
+ // Implementations that do not support reflection can implement this with
+ // an explicit "if/else" chain that lists every known message defined
+ // in those files.
+ string message_name = 2;
+
+ // The payload(s) for this dataset. They should be parsed or serialized
+ // in sequence, in a loop, ie.
+ //
+ // while (!benchmarkDone) { // Benchmark runner decides when to exit.
+ // for (i = 0; i < benchmark.payload.length; i++) {
+ // parse(benchmark.payload[i])
+ // }
+ // }
+ //
+ // This is intended to let datasets include a variety of data to provide
+ // potentially more realistic results than just parsing the same message
+ // over and over. A single message parsed repeatedly could yield unusually
+ // good branch prediction performance.
+ repeated bytes payload = 3;
+}
diff --git a/third_party/protobuf/benchmarks/cpp_benchmark.cc b/third_party/protobuf/benchmarks/cpp_benchmark.cc
new file mode 100644
index 0000000000..0e6febc2f1
--- /dev/null
+++ b/third_party/protobuf/benchmarks/cpp_benchmark.cc
@@ -0,0 +1,242 @@
+// 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 <glob.h>
+#include <iostream>
+#include <fstream>
+#include "benchmark/benchmark_api.h"
+#include "benchmarks.pb.h"
+#include "benchmark_messages_proto2.pb.h"
+#include "benchmark_messages_proto3.pb.h"
+
+#define PREFIX "dataset."
+#define SUFFIX ".pb"
+
+using benchmarks::BenchmarkDataset;
+using google::protobuf::Arena;
+using google::protobuf::Descriptor;
+using google::protobuf::DescriptorPool;
+using google::protobuf::Message;
+using google::protobuf::MessageFactory;
+
+class Fixture : public benchmark::Fixture {
+ public:
+ Fixture(const BenchmarkDataset& dataset, const std::string& suffix) {
+ for (int i = 0; i < dataset.payload_size(); i++) {
+ payloads_.push_back(dataset.payload(i));
+ }
+
+ const Descriptor* d =
+ DescriptorPool::generated_pool()->FindMessageTypeByName(
+ dataset.message_name());
+
+ if (!d) {
+ std::cerr << "Couldn't find message named '" << dataset.message_name()
+ << "\n";
+ }
+
+ prototype_ = MessageFactory::generated_factory()->GetPrototype(d);
+ SetName((dataset.name() + suffix).c_str());
+ }
+
+ protected:
+ std::vector<std::string> payloads_;
+ const Message* prototype_;
+};
+
+class WrappingCounter {
+ public:
+ WrappingCounter(size_t limit) : value_(0), limit_(limit) {}
+
+ size_t Next() {
+ size_t ret = value_;
+ if (++value_ == limit_) {
+ value_ = 0;
+ }
+ return ret;
+ }
+
+ private:
+ size_t value_;
+ size_t limit_;
+};
+
+template <class T>
+class ParseNewFixture : public Fixture {
+ public:
+ ParseNewFixture(const BenchmarkDataset& dataset)
+ : Fixture(dataset, "_parse_new") {}
+
+ virtual void BenchmarkCase(benchmark::State& state) {
+ WrappingCounter i(payloads_.size());
+ size_t total = 0;
+
+ while (state.KeepRunning()) {
+ T m;
+ const std::string& payload = payloads_[i.Next()];
+ total += payload.size();
+ m.ParseFromString(payload);
+ }
+
+ state.SetBytesProcessed(total);
+ }
+};
+
+template <class T>
+class ParseNewArenaFixture : public Fixture {
+ public:
+ ParseNewArenaFixture(const BenchmarkDataset& dataset)
+ : Fixture(dataset, "_parse_newarena") {}
+
+ virtual void BenchmarkCase(benchmark::State& state) {
+ WrappingCounter i(payloads_.size());
+ size_t total = 0;
+
+ while (state.KeepRunning()) {
+ Arena arena;
+ Message* m = Arena::CreateMessage<T>(&arena);
+ const std::string& payload = payloads_[i.Next()];
+ total += payload.size();
+ m->ParseFromString(payload);
+ }
+
+ state.SetBytesProcessed(total);
+ }
+};
+
+template <class T>
+class ParseReuseFixture : public Fixture {
+ public:
+ ParseReuseFixture(const BenchmarkDataset& dataset)
+ : Fixture(dataset, "_parse_reuse") {}
+
+ virtual void BenchmarkCase(benchmark::State& state) {
+ T m;
+ WrappingCounter i(payloads_.size());
+ size_t total = 0;
+
+ while (state.KeepRunning()) {
+ const std::string& payload = payloads_[i.Next()];
+ total += payload.size();
+ m.ParseFromString(payload);
+ }
+
+ state.SetBytesProcessed(total);
+ }
+};
+
+template <class T>
+class SerializeFixture : public Fixture {
+ public:
+ SerializeFixture(const BenchmarkDataset& dataset)
+ : Fixture(dataset, "_serialize") {
+ for (size_t i = 0; i < payloads_.size(); i++) {
+ message_.push_back(new T);
+ message_.back()->ParseFromString(payloads_[i]);
+ }
+ }
+
+ ~SerializeFixture() {
+ for (size_t i = 0; i < message_.size(); i++) {
+ delete message_[i];
+ }
+ }
+
+ virtual void BenchmarkCase(benchmark::State& state) {
+ size_t total = 0;
+ std::string str;
+ WrappingCounter i(payloads_.size());
+
+ while (state.KeepRunning()) {
+ str.clear();
+ message_[i.Next()]->SerializeToString(&str);
+ total += str.size();
+ }
+
+ state.SetBytesProcessed(total);
+ }
+
+ private:
+ std::vector<T*> message_;
+};
+
+std::string ReadFile(const std::string& name) {
+ std::ifstream file(name.c_str());
+ GOOGLE_CHECK(file.is_open()) << "Couldn't find file '" << name <<
+ "', please make sure you are running "
+ "this command from the benchmarks/ "
+ "directory.\n";
+ return std::string((std::istreambuf_iterator<char>(file)),
+ std::istreambuf_iterator<char>());
+}
+
+template <class T>
+void RegisterBenchmarksForType(const BenchmarkDataset& dataset) {
+ ::benchmark::internal::RegisterBenchmarkInternal(
+ new ParseNewFixture<T>(dataset));
+ ::benchmark::internal::RegisterBenchmarkInternal(
+ new ParseReuseFixture<T>(dataset));
+ ::benchmark::internal::RegisterBenchmarkInternal(
+ new ParseNewArenaFixture<T>(dataset));
+ ::benchmark::internal::RegisterBenchmarkInternal(
+ new SerializeFixture<T>(dataset));
+}
+
+void RegisterBenchmarks(const std::string& dataset_bytes) {
+ BenchmarkDataset dataset;
+ GOOGLE_CHECK(dataset.ParseFromString(dataset_bytes));
+
+ if (dataset.message_name() == "benchmarks.proto3.GoogleMessage1") {
+ RegisterBenchmarksForType<benchmarks::proto3::GoogleMessage1>(dataset);
+ } else if (dataset.message_name() == "benchmarks.proto2.GoogleMessage1") {
+ RegisterBenchmarksForType<benchmarks::proto2::GoogleMessage1>(dataset);
+ } else if (dataset.message_name() == "benchmarks.proto2.GoogleMessage2") {
+ RegisterBenchmarksForType<benchmarks::proto2::GoogleMessage2>(dataset);
+ } else {
+ std::cerr << "Unknown message type: " << dataset.message_name();
+ exit(1);
+ }
+}
+
+int main(int argc, char *argv[]) {
+ glob_t glob_result;
+ if (glob("dataset.*.pb", 0, NULL, &glob_result) != 0) {
+ fprintf(stderr, "No dataset files found.\n");
+ return 1;
+ }
+
+ for (size_t i = 0; i < glob_result.gl_pathc; i++) {
+ fprintf(stderr, "Found input dataset: %s\n", glob_result.gl_pathv[i]);
+ RegisterBenchmarks(ReadFile(glob_result.gl_pathv[i]));
+ }
+
+ ::benchmark::Initialize(&argc, argv);
+ ::benchmark::RunSpecifiedBenchmarks();
+}
diff --git a/third_party/protobuf/benchmarks/generate_datasets.cc b/third_party/protobuf/benchmarks/generate_datasets.cc
new file mode 100644
index 0000000000..61e7adf1ba
--- /dev/null
+++ b/third_party/protobuf/benchmarks/generate_datasets.cc
@@ -0,0 +1,117 @@
+// 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 <fstream>
+#include <iostream>
+#include "benchmarks.pb.h"
+
+using benchmarks::BenchmarkDataset;
+using google::protobuf::Descriptor;
+using google::protobuf::DescriptorPool;
+using google::protobuf::Message;
+using google::protobuf::MessageFactory;
+
+std::set<std::string> names;
+
+const char *file_prefix = "dataset.";
+const char *file_suffix = ".pb";
+
+void WriteFileWithPayloads(const std::string& name,
+ const std::string& message_name,
+ const std::vector<std::string>& payload) {
+ if (!names.insert(name).second) {
+ std::cerr << "Duplicate test name: " << name << "\n";
+ abort();
+ }
+
+ // First verify that this message name exists in our set of benchmark messages
+ // and that these payloads are valid for the given message.
+ const Descriptor* d =
+ DescriptorPool::generated_pool()->FindMessageTypeByName(message_name);
+
+ if (!d) {
+ std::cerr << "For dataset " << name << ", no such message: "
+ << message_name << "\n";
+ abort();
+ }
+
+ Message* m = MessageFactory::generated_factory()->GetPrototype(d)->New();
+
+ for (size_t i = 0; i < payload.size(); i++) {
+ if (!m->ParseFromString(payload[i])) {
+ std::cerr << "For dataset " << name << ", payload[" << i << "] fails "
+ << "to parse\n";
+ abort();
+ }
+ }
+
+ BenchmarkDataset dataset;
+ dataset.set_name(name);
+ dataset.set_message_name(message_name);
+ for (size_t i = 0; i < payload.size(); i++) {
+ dataset.add_payload()->assign(payload[i]);
+ }
+
+ std::ofstream writer;
+ std::string fname = file_prefix + name + file_suffix;
+ writer.open(fname.c_str());
+ dataset.SerializeToOstream(&writer);
+ writer.close();
+
+ std::cerr << "Wrote dataset: " << fname << "\n";
+}
+
+void WriteFile(const std::string& name, const std::string& message_name,
+ const std::string& payload) {
+ std::vector<std::string> payloads;
+ payloads.push_back(payload);
+ WriteFileWithPayloads(name, message_name, payloads);
+}
+
+std::string ReadFile(const std::string& name) {
+ std::ifstream file(name.c_str());
+ GOOGLE_CHECK(file.is_open()) << "Couldn't find file '" << name <<
+ "', please make sure you are running "
+ "this command from the benchmarks/ "
+ "directory.\n";
+ return std::string((std::istreambuf_iterator<char>(file)),
+ std::istreambuf_iterator<char>());
+}
+
+int main() {
+ WriteFile("google_message1_proto3", "benchmarks.proto3.GoogleMessage1",
+ ReadFile("google_message1.dat"));
+ WriteFile("google_message1_proto2", "benchmarks.proto2.GoogleMessage1",
+ ReadFile("google_message1.dat"));
+
+ // Not in proto3 because it has a group, which is not supported.
+ WriteFile("google_message2", "benchmarks.proto2.GoogleMessage2",
+ ReadFile("google_message2.dat"));
+}
diff --git a/third_party/protobuf/benchmarks/google_message1.dat b/third_party/protobuf/benchmarks/google_message1.dat
new file mode 100644
index 0000000000..bc0f064cc2
--- /dev/null
+++ b/third_party/protobuf/benchmarks/google_message1.dat
Binary files differ
diff --git a/third_party/protobuf/benchmarks/google_message2.dat b/third_party/protobuf/benchmarks/google_message2.dat
new file mode 100644
index 0000000000..06c09441b9
--- /dev/null
+++ b/third_party/protobuf/benchmarks/google_message2.dat
Binary files differ
diff --git a/third_party/protobuf/benchmarks/google_size.proto b/third_party/protobuf/benchmarks/google_size.proto
new file mode 100644
index 0000000000..d2d319f31c
--- /dev/null
+++ b/third_party/protobuf/benchmarks/google_size.proto
@@ -0,0 +1,138 @@
+syntax = "proto2";
+
+package benchmarks;
+
+option java_outer_classname = "GoogleSize";
+option optimize_for = CODE_SIZE;
+
+message SizeMessage1 {
+ required string field1 = 1;
+ optional string field9 = 9;
+ optional string field18 = 18;
+ optional bool field80 = 80 [default=false];
+ optional bool field81 = 81 [default=true];
+ required int32 field2 = 2;
+ required int32 field3 = 3;
+ optional int32 field280 = 280;
+ optional int32 field6 = 6 [default=0];
+ optional int64 field22 = 22;
+ optional string field4 = 4;
+ repeated fixed64 field5 = 5;
+ optional bool field59 = 59 [default=false];
+ optional string field7 = 7;
+ optional int32 field16 = 16;
+ optional int32 field130 = 130 [default=0];
+ optional bool field12 = 12 [default=true];
+ optional bool field17 = 17 [default=true];
+ optional bool field13 = 13 [default=true];
+ optional bool field14 = 14 [default=true];
+ optional int32 field104 = 104 [default=0];
+ optional int32 field100 = 100 [default=0];
+ optional int32 field101 = 101 [default=0];
+ optional string field102 = 102;
+ optional string field103 = 103;
+ optional int32 field29 = 29 [default=0];
+ optional bool field30 = 30 [default=false];
+ optional int32 field60 = 60 [default=-1];
+ optional int32 field271 = 271 [default=-1];
+ optional int32 field272 = 272 [default=-1];
+ optional int32 field150 = 150;
+ optional int32 field23 = 23 [default=0];
+ optional bool field24 = 24 [default=false];
+ optional int32 field25 = 25 [default=0];
+ optional SizeMessage1SubMessage field15 = 15;
+ optional bool field78 = 78;
+ optional int32 field67 = 67 [default=0];
+ optional int32 field68 = 68;
+ optional int32 field128 = 128 [default=0];
+ optional string field129 = 129 [default="xxxxxxxxxxxxxxxxxxxxx"];
+ optional int32 field131 = 131 [default=0];
+}
+
+message SizeMessage1SubMessage {
+ optional int32 field1 = 1 [default=0];
+ optional int32 field2 = 2 [default=0];
+ optional int32 field3 = 3 [default=0];
+ optional string field15 = 15;
+ optional bool field12 = 12 [default=true];
+ optional int64 field13 = 13;
+ optional int64 field14 = 14;
+ optional int32 field16 = 16;
+ optional int32 field19 = 19 [default=2];
+ optional bool field20 = 20 [default=true];
+ optional bool field28 = 28 [default=true];
+ optional fixed64 field21 = 21;
+ optional int32 field22 = 22;
+ optional bool field23 = 23 [ default=false ];
+ optional bool field206 = 206 [default=false];
+ optional fixed32 field203 = 203;
+ optional int32 field204 = 204;
+ optional string field205 = 205;
+ optional uint64 field207 = 207;
+ optional uint64 field300 = 300;
+}
+
+message SizeMessage2 {
+ optional string field1 = 1;
+ optional int64 field3 = 3;
+ optional int64 field4 = 4;
+ optional int64 field30 = 30;
+ optional bool field75 = 75 [default=false];
+ optional string field6 = 6;
+ optional bytes field2 = 2;
+ optional int32 field21 = 21 [default=0];
+ optional int32 field71 = 71;
+ optional float field25 = 25;
+ optional int32 field109 = 109 [default=0];
+ optional int32 field210 = 210 [default=0];
+ optional int32 field211 = 211 [default=0];
+ optional int32 field212 = 212 [default=0];
+ optional int32 field213 = 213 [default=0];
+ optional int32 field216 = 216 [default=0];
+ optional int32 field217 = 217 [default=0];
+ optional int32 field218 = 218 [default=0];
+ optional int32 field220 = 220 [default=0];
+ optional int32 field221 = 221 [default=0];
+ optional float field222 = 222 [default=0.0];
+ optional int32 field63 = 63;
+
+ repeated group Group1 = 10 {
+ required float field11 = 11;
+ optional float field26 = 26;
+ optional string field12 = 12;
+ optional string field13 = 13;
+ repeated string field14 = 14;
+ required uint64 field15 = 15;
+ optional int32 field5 = 5;
+ optional string field27 = 27;
+ optional int32 field28 = 28;
+ optional string field29 = 29;
+ optional string field16 = 16;
+ repeated string field22 = 22;
+ repeated int32 field73 = 73;
+ optional int32 field20 = 20 [default=0];
+ optional string field24 = 24;
+ optional SizeMessage2GroupedMessage field31 = 31;
+ }
+ repeated string field128 = 128;
+ optional int64 field131 = 131;
+ repeated string field127 = 127;
+ optional int32 field129 = 129;
+ repeated int64 field130 = 130;
+ optional bool field205 = 205 [default=false];
+ optional bool field206 = 206 [default=false];
+}
+
+message SizeMessage2GroupedMessage {
+ optional float field1 = 1;
+ optional float field2 = 2;
+ optional float field3 = 3 [default=0.0];
+ optional bool field4 = 4;
+ optional bool field5 = 5;
+ optional bool field6 = 6 [default=true];
+ optional bool field7 = 7 [default=false];
+ optional float field8 = 8;
+ optional bool field9 = 9;
+ optional float field10 = 10;
+ optional int64 field11 = 11;
+}
diff --git a/third_party/protobuf/benchmarks/readme.txt b/third_party/protobuf/benchmarks/readme.txt
new file mode 100644
index 0000000000..b08b8bc09c
--- /dev/null
+++ b/third_party/protobuf/benchmarks/readme.txt
@@ -0,0 +1,46 @@
+Contents
+--------
+
+This folder contains three kinds of file:
+
+- Code, such as ProtoBench.java, to build the benchmarking framework.
+- Protocol buffer definitions (.proto files)
+- Sample data files
+
+If we end up with a lot of different benchmarks it may be worth
+separating these out info different directories, but while there are
+so few they might as well all be together.
+
+Running a benchmark (Java)
+--------------------------
+
+1) Build protoc and the Java protocol buffer library. The examples
+ below assume a jar file (protobuf.jar) has been built and copied
+ into this directory.
+
+2) Build ProtoBench:
+ $ javac -d tmp -cp protobuf.jar ProtoBench.java
+
+3) Generate code for the relevant benchmark protocol buffer, e.g.
+ $ protoc --java_out=tmp google_size.proto
+
+4) Build the generated code, e.g.
+ $ javac -d tmp -cp protobuf.jar tmp/benchmarks/*.java
+
+5) Run the test. Arguments are given in pairs - the first argument
+ is the descriptor type; the second is the filename. For example:
+ $ java -cp tmp:protobuf.jar com.google.protocolbuffers.ProtoBench \
+ 'benchmarks.GoogleSize$SizeMessage1' google_message1.dat \
+ 'benchmarks.GoogleSize$SizeMessage2' google_message2.dat
+
+6) Wait! Each test runs for around 30 seconds, and there are 8 tests
+ per class/data combination. The above command would therefore take
+ about 8 minutes to run.
+
+
+Benchmarks available
+--------------------
+
+From Google:
+google_size.proto,
+messages google_message1.dat and google_message2.dat.
diff --git a/third_party/protobuf/cmake/CMakeLists.txt b/third_party/protobuf/cmake/CMakeLists.txt
new file mode 100644
index 0000000000..7618ba21a1
--- /dev/null
+++ b/third_party/protobuf/cmake/CMakeLists.txt
@@ -0,0 +1,183 @@
+# Minimum CMake required
+cmake_minimum_required(VERSION 2.8.12)
+
+if(protobuf_VERBOSE)
+ message(STATUS "Protocol Buffers Configuring...")
+endif()
+
+# CMake policies
+cmake_policy(SET CMP0022 NEW)
+
+# Project
+project(protobuf C CXX)
+
+# Options
+option(protobuf_BUILD_TESTS "Build tests" ON)
+option(protobuf_BUILD_EXAMPLES "Build examples" OFF)
+if (BUILD_SHARED_LIBS)
+ set(protobuf_BUILD_SHARED_LIBS_DEFAULT ON)
+else (BUILD_SHARED_LIBS)
+ set(protobuf_BUILD_SHARED_LIBS_DEFAULT OFF)
+endif (BUILD_SHARED_LIBS)
+option(protobuf_BUILD_SHARED_LIBS "Build Shared Libraries" ${protobuf_BUILD_SHARED_LIBS_DEFAULT})
+include(CMakeDependentOption)
+cmake_dependent_option(protobuf_MSVC_STATIC_RUNTIME "Link static runtime libraries" ON
+ "NOT protobuf_BUILD_SHARED_LIBS" OFF)
+if (MSVC)
+ set(protobuf_WITH_ZLIB_DEFAULT OFF)
+else (MSVC)
+ set(protobuf_WITH_ZLIB_DEFAULT ON)
+endif (MSVC)
+option(protobuf_WITH_ZLIB "Build with zlib support" ${protobuf_WITH_ZLIB_DEFAULT})
+set(protobuf_DEBUG_POSTFIX "d"
+ CACHE STRING "Default debug postfix")
+mark_as_advanced(protobuf_DEBUG_POSTFIX)
+# User options
+include(protobuf-options.cmake)
+
+# Path to main configure script
+set(protobuf_CONFIGURE_SCRIPT "../configure.ac")
+
+# Parse configure script
+set(protobuf_AC_INIT_REGEX
+ "^AC_INIT\\(\\[([^]]+)\\],\\[([^]]+)\\],\\[([^]]+)\\],\\[([^]]+)\\]\\)$")
+file(STRINGS "${protobuf_CONFIGURE_SCRIPT}" protobuf_AC_INIT_LINE
+ LIMIT_COUNT 1 REGEX "^AC_INIT")
+# Description
+string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\1"
+ protobuf_DESCRIPTION "${protobuf_AC_INIT_LINE}")
+# Version
+string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\2"
+ protobuf_VERSION_STRING "${protobuf_AC_INIT_LINE}")
+# Contact
+string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\3"
+ protobuf_CONTACT "${protobuf_AC_INIT_LINE}")
+# Parse version tweaks
+set(protobuf_VERSION_REGEX "^([0-9]+)\\.([0-9]+)\\.([0-9]+)-?(.*)$")
+string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\1"
+ protobuf_VERSION_MAJOR "${protobuf_VERSION_STRING}")
+string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\2"
+ protobuf_VERSION_MINOR "${protobuf_VERSION_STRING}")
+string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\3"
+ protobuf_VERSION_PATCH "${protobuf_VERSION_STRING}")
+string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\4"
+ protobuf_VERSION_PRERELEASE "${protobuf_VERSION_STRING}")
+
+# Package version
+set(protobuf_VERSION
+ "${protobuf_VERSION_MAJOR}.${protobuf_VERSION_MINOR}.${protobuf_VERSION_PATCH}")
+
+if(protobuf_VERSION_PRERELEASE)
+ set(protobuf_VERSION "${protobuf_VERSION}-${protobuf_VERSION_PRERELEASE}")
+endif()
+
+if(protobuf_VERBOSE)
+ message(STATUS "Configuration script parsing status [")
+ message(STATUS " Description : ${protobuf_DESCRIPTION}")
+ message(STATUS " Version : ${protobuf_VERSION} (${protobuf_VERSION_STRING})")
+ message(STATUS " Contact : ${protobuf_CONTACT}")
+ message(STATUS "]")
+endif()
+
+add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD)
+
+find_package(Threads REQUIRED)
+if (CMAKE_USE_PTHREADS_INIT)
+ add_definitions(-DHAVE_PTHREAD)
+endif (CMAKE_USE_PTHREADS_INIT)
+
+set(_protobuf_FIND_ZLIB)
+if (protobuf_WITH_ZLIB)
+ find_package(ZLIB)
+ if (ZLIB_FOUND)
+ set(HAVE_ZLIB 1)
+ # FindZLIB module define ZLIB_INCLUDE_DIRS variable
+ # Set ZLIB_INCLUDE_DIRECTORIES for compatible
+ set(ZLIB_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRECTORIES} ${ZLIB_INCLUDE_DIRS})
+ # Using imported target if exists
+ if (TARGET ZLIB::ZLIB)
+ set(ZLIB_LIBRARIES ZLIB::ZLIB)
+ set(_protobuf_FIND_ZLIB "if(NOT ZLIB_FOUND)\n find_package(ZLIB)\nendif()")
+ endif (TARGET ZLIB::ZLIB)
+ else (ZLIB_FOUND)
+ set(HAVE_ZLIB 0)
+ # Explicitly set these to empty (override NOT_FOUND) so cmake doesn't
+ # complain when we use them later.
+ set(ZLIB_INCLUDE_DIRECTORIES)
+ set(ZLIB_LIBRARIES)
+ endif (ZLIB_FOUND)
+endif (protobuf_WITH_ZLIB)
+
+if (HAVE_ZLIB)
+ add_definitions(-DHAVE_ZLIB)
+endif (HAVE_ZLIB)
+
+if (protobuf_BUILD_SHARED_LIBS)
+ set(protobuf_SHARED_OR_STATIC "SHARED")
+else (protobuf_BUILD_SHARED_LIBS)
+ set(protobuf_SHARED_OR_STATIC "STATIC")
+ # In case we are building static libraries, link also the runtime library statically
+ # so that MSVCR*.DLL is not required at runtime.
+ # https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
+ # This is achieved by replacing msvc option /MD with /MT and /MDd with /MTd
+ # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
+ if (MSVC AND protobuf_MSVC_STATIC_RUNTIME)
+ foreach(flag_var
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
+ if(${flag_var} MATCHES "/MD")
+ string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
+ endif(${flag_var} MATCHES "/MD")
+ endforeach(flag_var)
+ endif (MSVC AND protobuf_MSVC_STATIC_RUNTIME)
+endif (protobuf_BUILD_SHARED_LIBS)
+
+if (MSVC)
+ # Build with multiple processes
+ add_definitions(/MP)
+ add_definitions(/wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146 /wd4305 /wd4309)
+ # Allow big object
+ add_definitions(/bigobj)
+ string(REPLACE "/" "\\" PROTOBUF_SOURCE_WIN32_PATH ${protobuf_SOURCE_DIR})
+ string(REPLACE "/" "\\" PROTOBUF_BINARY_WIN32_PATH ${protobuf_BINARY_DIR})
+ configure_file(extract_includes.bat.in extract_includes.bat)
+endif (MSVC)
+
+get_filename_component(protobuf_source_dir ${protobuf_SOURCE_DIR} PATH)
+
+include_directories(
+ ${ZLIB_INCLUDE_DIRECTORIES}
+ ${protobuf_BINARY_DIR}
+ ${protobuf_source_dir}/src)
+
+if (MSVC)
+ # Add the "lib" prefix for generated .lib outputs.
+ set(LIB_PREFIX lib)
+else (MSVC)
+ # When building with "make", "lib" prefix will be added automatically by
+ # the build tool.
+ set(LIB_PREFIX)
+endif (MSVC)
+
+if (protobuf_UNICODE)
+ add_definitions(-DUNICODE -D_UNICODE)
+endif (protobuf_UNICODE)
+
+include(libprotobuf-lite.cmake)
+include(libprotobuf.cmake)
+include(libprotoc.cmake)
+include(protoc.cmake)
+
+if (protobuf_BUILD_TESTS)
+ include(tests.cmake)
+endif (protobuf_BUILD_TESTS)
+
+include(install.cmake)
+
+if (protobuf_BUILD_EXAMPLES)
+ include(examples.cmake)
+endif (protobuf_BUILD_EXAMPLES)
+
+if(protobuf_VERBOSE)
+ message(STATUS "Protocol Buffers Configuring done")
+endif()
diff --git a/third_party/protobuf/cmake/README.md b/third_party/protobuf/cmake/README.md
new file mode 100644
index 0000000000..1e7410d828
--- /dev/null
+++ b/third_party/protobuf/cmake/README.md
@@ -0,0 +1,336 @@
+This directory contains *CMake* files that can be used to build protobuf
+with *MSVC* on *Windows*. You can build the project from *Command Prompt*
+and using an *Visual Studio* IDE.
+
+You need to have [CMake](http://www.cmake.org), [Visual Studio](https://www.visualstudio.com)
+and optionally [Git](http://git-scm.com) installed on your computer before proceeding.
+
+Most of the instructions will be given to the *Сommand Prompt*, but the same
+actions can be performed using appropriate GUI tools.
+
+Environment Setup
+=================
+
+Open the appropriate *Command Prompt* from the *Start* menu.
+
+For example *VS2013 x64 Native Tools Command Prompt*:
+
+ C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64>
+
+Change to your working directory:
+
+ C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64>cd C:\Path\to
+ C:\Path\to>
+
+Where *C:\Path\to* is path to your real working directory.
+
+Create a folder where protobuf headers/libraries/binaries will be installed after built:
+
+ C:\Path\to>mkdir install
+
+If *cmake* command is not available from *Command Prompt*, add it to system *PATH* variable:
+
+ C:\Path\to>set PATH=%PATH%;C:\Program Files (x86)\CMake\bin
+
+If *git* command is not available from *Command Prompt*, add it to system *PATH* variable:
+
+ C:\Path\to>set PATH=%PATH%;C:\Program Files\Git\cmd
+
+Good. Now you are ready to continue.
+
+Getting Sources
+===============
+
+You can get the latest stable source packages from the
+[releases](https://github.com/google/protobuf/releases) page.
+Or you can type:
+
+ C:\Path\to> git clone -b [release_tag] https://github.com/google/protobuf.git
+
+Where *[release_tag]* is a git tag like *v3.0.0-beta-1* or a branch name like *master*
+if you want to get the latest code.
+
+Go to the project folder:
+
+ C:\Path\to>cd protobuf
+ C:\Path\to\protobuf>
+
+Protobuf unit-tests require gmock to build. If you download protobuf source code
+from the *releases* page, the *gmock* directory should already be there. If you checkout
+the code via `git clone`, this *gmock* directory won't exist and you will have to
+download it manually or skip building protobuf unit-tests.
+
+You can download gmock as follows:
+
+ C:\Path\to\protobuf>git clone -b release-1.7.0 https://github.com/google/googlemock.git gmock
+
+Then go to *gmock* folder and download gtest:
+
+ C:\Path\to\protobuf>cd gmock
+ C:\Path\to\protobuf\gmock>git clone -b release-1.7.0 https://github.com/google/googletest.git gtest
+
+If you absolutely don't want to build and run protobuf unit-tests, skip
+this steps and use protobuf at your own risk.
+
+Now go to *cmake* folder in protobuf sources:
+
+ C:\Path\to\protobuf\gmock>cd ..\cmake
+ C:\Path\to\protobuf\cmake>
+
+Good. Now you are ready to *CMake* configuration.
+
+CMake Configuration
+===================
+
+*CMake* supports a lot of different
+[generators](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html)
+for various native build systems.
+We are only interested in
+[Makefile](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#makefile-generators)
+and
+[Visual Studio](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators)
+generators.
+
+We will use shadow building to separate the temporary files from the protobuf source code.
+
+Create a temporary *build* folder and change your working directory to it:
+
+ C:\Path\to\protobuf\cmake>mkdir build & cd build
+ C:\Path\to\protobuf\cmake\build>
+
+The *Makefile* generator can build the project in only one configuration, so you need to build
+a separate folder for each configuration.
+
+To start using a *Release* configuration:
+
+ C:\Path\to\protobuf\cmake\build>mkdir release & cd release
+ C:\Path\to\protobuf\cmake\build\release>cmake -G "NMake Makefiles" ^
+ -DCMAKE_BUILD_TYPE=Release ^
+ -DCMAKE_INSTALL_PREFIX=../../../../install ^
+ ../..
+
+It will generate *nmake* *Makefile* in current directory.
+
+To use *Debug* configuration:
+
+ C:\Path\to\protobuf\cmake\build>mkdir debug & cd debug
+ C:\Path\to\protobuf\cmake\build\debug>cmake -G "NMake Makefiles" ^
+ -DCMAKE_BUILD_TYPE=Debug ^
+ -DCMAKE_INSTALL_PREFIX=../../../../install ^
+ ../..
+
+It will generate *nmake* *Makefile* in current directory.
+
+To create *Visual Studio* solution file:
+
+ C:\Path\to\protobuf\cmake\build>mkdir solution & cd solution
+ C:\Path\to\protobuf\cmake\build\solution>cmake -G "Visual Studio 12 2013 Win64" ^
+ -DCMAKE_INSTALL_PREFIX=../../../../install ^
+ ../..
+
+It will generate *Visual Studio* solution file *protobuf.sln* in current directory.
+
+If the *gmock* directory does not exist, and you do not want to build protobuf unit tests,
+you need to add *cmake* command argument `-Dprotobuf_BUILD_TESTS=OFF` to disable testing.
+
+Compiling
+=========
+
+To compile protobuf:
+
+ C:\Path\to\protobuf\cmake\build\release>nmake
+
+or
+
+ C:\Path\to\protobuf\cmake\build\debug>nmake
+
+And wait for the compilation to finish.
+
+If you prefer to use the IDE:
+
+ * Open the generated protobuf.sln file in Microsoft Visual Studio.
+ * Choose "Debug" or "Release" configuration as desired.
+ * From the Build menu, choose "Build Solution".
+
+And wait for the compilation to finish.
+
+Testing
+=======
+
+To run unit-tests, first you must compile protobuf as described above.
+Then run:
+
+ C:\Path\to\protobuf\cmake\build\release>nmake check
+
+or
+
+ C:\Path\to\protobuf\cmake\build\debug>nmake check
+
+You can also build project *check* from Visual Studio solution.
+Yes, it may sound strange, but it works.
+
+You should see output similar to:
+
+ Running main() from gmock_main.cc
+ [==========] Running 1546 tests from 165 test cases.
+
+ ...
+
+ [==========] 1546 tests from 165 test cases ran. (2529 ms total)
+ [ PASSED ] 1546 tests.
+
+To run specific tests:
+
+ C:\Path\to\protobuf>cmake\build\release\tests.exe --gtest_filter=AnyTest*
+ Running main() from gmock_main.cc
+ Note: Google Test filter = AnyTest*
+ [==========] Running 3 tests from 1 test case.
+ [----------] Global test environment set-up.
+ [----------] 3 tests from AnyTest
+ [ RUN ] AnyTest.TestPackAndUnpack
+ [ OK ] AnyTest.TestPackAndUnpack (0 ms)
+ [ RUN ] AnyTest.TestPackAndUnpackAny
+ [ OK ] AnyTest.TestPackAndUnpackAny (0 ms)
+ [ RUN ] AnyTest.TestIs
+ [ OK ] AnyTest.TestIs (0 ms)
+ [----------] 3 tests from AnyTest (1 ms total)
+
+ [----------] Global test environment tear-down
+ [==========] 3 tests from 1 test case ran. (2 ms total)
+ [ PASSED ] 3 tests.
+
+Note that the tests must be run from the source folder.
+
+If all tests are passed, safely continue.
+
+Installing
+==========
+
+To install protobuf to the specified *install* folder:
+
+ C:\Path\to\protobuf\cmake\build\release>nmake install
+
+or
+
+ C:\Path\to\protobuf\cmake\build\debug>nmake install
+
+You can also build project *INSTALL* from Visual Studio solution.
+It sounds not so strange and it works.
+
+This will create the following folders under the *install* location:
+ * bin - that contains protobuf *protoc.exe* compiler;
+ * include - that contains C++ headers and protobuf *.proto files;
+ * lib - that contains linking libraries and *CMake* configuration files for *protobuf* package.
+
+Now you can if needed:
+ * Copy the contents of the include directory to wherever you want to put headers.
+ * Copy protoc.exe wherever you put build tools (probably somewhere in your PATH).
+ * Copy linking libraries libprotobuf[d].lib, libprotobuf-lite[d].lib, and libprotoc[d].lib wherever you put libraries.
+
+To avoid conflicts between the MSVC debug and release runtime libraries, when
+compiling a debug build of your application, you may need to link against a
+debug build of libprotobufd.lib with "d" postfix. Similarly, release builds should link against
+release libprotobuf.lib library.
+
+DLLs vs. static linking
+=======================
+
+Static linking is now the default for the Protocol Buffer libraries. Due to
+issues with Win32's use of a separate heap for each DLL, as well as binary
+compatibility issues between different versions of MSVC's STL library, it is
+recommended that you use static linkage only. However, it is possible to
+build libprotobuf and libprotoc as DLLs if you really want. To do this,
+do the following:
+
+ * Add an additional flag `-Dprotobuf_BUILD_SHARED_LIBS=ON` when invoking cmake
+ * Follow the same steps as described in the above section.
+ * When compiling your project, make sure to `#define PROTOBUF_USE_DLLS`.
+
+When distributing your software to end users, we strongly recommend that you
+do NOT install libprotobuf.dll or libprotoc.dll to any shared location.
+Instead, keep these libraries next to your binaries, in your application's
+own install directory. C++ makes it very difficult to maintain binary
+compatibility between releases, so it is likely that future versions of these
+libraries will *not* be usable as drop-in replacements.
+
+If your project is itself a DLL intended for use by third-party software, we
+recommend that you do NOT expose protocol buffer objects in your library's
+public interface, and that you statically link protocol buffers into your
+library.
+
+ZLib support
+============
+
+If you want to include GzipInputStream and GzipOutputStream
+(google/protobuf/io/gzip_stream.h) in libprotobuf, you will need to do a few
+additional steps.
+
+Obtain a copy of the zlib library. The pre-compiled DLL at zlib.net works.
+You need prepare it:
+
+ * Make sure zlib's two headers are in your `C:\Path\to\install\include` path
+ * Make sure zlib's linking libraries (*.lib file) is in your
+ `C:\Path\to\install\lib` library path.
+
+You can also compile it from source by yourself.
+
+Getting sources:
+
+ C:\Path\to>git clone -b v1.2.8 https://github.com/madler/zlib.git
+ C:\Path\to>cd zlib
+
+Compiling and Installing:
+
+ C:\Path\to\zlib>mkdir build & cd build
+ C:\Path\to\zlib\build>mkdir release & cd release
+ C:\Path\to\zlib\build\release>cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release ^
+ -DCMAKE_INSTALL_PREFIX=../../../install ../..
+ C:\Path\to\zlib\build\release>nmake & nmake install
+
+You can make *debug* version or use *Visual Studio* generator also as before for the
+protobuf project.
+
+Now add *bin* folder from *install* to system *PATH*:
+
+ C:\Path\to>set PATH=%PATH%;C:\Path\to\install\bin
+
+You need reconfigure protobuf with flag `-Dprotobuf_WITH_ZLIB=ON` when invoking cmake.
+
+Note that if you have compiled ZLIB yourself, as stated above,
+further disable the option `-Dprotobuf_MSVC_STATIC_RUNTIME=OFF`.
+
+If it reports NOTFOUND for zlib_include or zlib_lib, you might haven't put
+the headers or the .lib file in the right directory.
+
+Build and testing protobuf as usual.
+
+Notes on Compiler Warnings
+==========================
+
+The following warnings have been disabled while building the protobuf libraries
+and compiler. You may have to disable some of them in your own project as
+well, or live with them.
+
+* C4018 - 'expression' : signed/unsigned mismatch
+* C4146 - unary minus operator applied to unsigned type, result still unsigned
+* C4244 - Conversion from 'type1' to 'type2', possible loss of data.
+* C4251 - 'identifier' : class 'type' needs to have dll-interface to be used by
+ clients of class 'type2'
+* C4267 - Conversion from 'size_t' to 'type', possible loss of data.
+* C4305 - 'identifier' : truncation from 'type1' to 'type2'
+* C4355 - 'this' : used in base member initializer list
+* C4800 - 'type' : forcing value to bool 'true' or 'false' (performance warning)
+* C4996 - 'function': was declared deprecated
+
+C4251 is of particular note, if you are compiling the Protocol Buffer library
+as a DLL (see previous section). The protocol buffer library uses templates in
+its public interfaces. MSVC does not provide any reasonable way to export
+template classes from a DLL. However, in practice, it appears that exporting
+templates is not necessary anyway. Since the complete definition of any
+template is available in the header files, anyone importing the DLL will just
+end up compiling instances of the templates into their own binary. The
+Protocol Buffer implementation does not rely on static template members being
+unique, so there should be no problem with this, but MSVC prints warning
+nevertheless. So, we disable it. Unfortunately, this warning will also be
+produced when compiling code which merely uses protocol buffers, meaning you
+may have to disable it in your code too.
diff --git a/third_party/protobuf/cmake/examples.cmake b/third_party/protobuf/cmake/examples.cmake
new file mode 100644
index 0000000000..e5cad63f67
--- /dev/null
+++ b/third_party/protobuf/cmake/examples.cmake
@@ -0,0 +1,57 @@
+if(protobuf_VERBOSE)
+ message(STATUS "Protocol Buffers Examples Configuring...")
+endif()
+
+get_filename_component(examples_dir "../examples" ABSOLUTE)
+
+if(protobuf_VERBOSE)
+ message(STATUS "Protocol Buffers Examples Configuring done")
+endif()
+include(ExternalProject)
+
+# Internal utility function: Create a custom target representing a build of examples with custom options.
+function(add_examples_build NAME)
+
+ ExternalProject_Add(${NAME}
+ PREFIX ${NAME}
+ SOURCE_DIR "${examples_dir}"
+ BINARY_DIR ${NAME}
+ STAMP_DIR ${NAME}/logs
+ INSTALL_COMMAND "" #Skip
+ LOG_CONFIGURE 1
+ CMAKE_CACHE_ARGS "-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}"
+ "-Dprotobuf_VERBOSE:BOOL=${protobuf_VERBOSE}"
+ ${ARGN}
+ )
+ set_property(TARGET ${NAME} PROPERTY FOLDER "Examples")
+ set_property(TARGET ${NAME} PROPERTY EXCLUDE_FROM_ALL TRUE)
+endfunction()
+
+# Add examples as an external project.
+# sub_directory cannot be used because the find_package(protobuf) call would cause failures with redefined targets.
+add_examples_build(examples "-Dprotobuf_DIR:PATH=${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}")
+add_dependencies(examples libprotobuf protoc)
+
+option(protobuf_BUILD_EXAMPLES_MULTITEST "Build Examples in multiple configurations. Useful for testing." OFF)
+mark_as_advanced(protobuf_BUILD_EXAMPLES_MULTITEST)
+if(protobuf_BUILD_EXAMPLES_MULTITEST)
+ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+
+ #Build using the legacy compatibility module.
+ add_examples_build(examples-legacy
+ "-Dprotobuf_DIR:PATH=${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}"
+ "-Dprotobuf_MODULE_COMPATIBLE:BOOL=TRUE"
+ )
+ add_dependencies(examples-legacy libprotobuf protoc)
+
+ #Build using the installed library.
+ add_examples_build(examples-installed
+ "-Dprotobuf_DIR:PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}"
+ )
+
+ #Build using the installed library in legacy compatibility mode.
+ add_examples_build(examples-installed-legacy
+ "-Dprotobuf_DIR:PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}"
+ "-Dprotobuf_MODULE_COMPATIBLE:BOOL=TRUE"
+ )
+endif()
diff --git a/third_party/protobuf/cmake/extract_includes.bat.in b/third_party/protobuf/cmake/extract_includes.bat.in
new file mode 100644
index 0000000000..a4fd762258
--- /dev/null
+++ b/third_party/protobuf/cmake/extract_includes.bat.in
@@ -0,0 +1,127 @@
+mkdir include
+mkdir include\google
+mkdir include\google\protobuf
+mkdir include\google\protobuf\compiler
+mkdir include\google\protobuf\compiler\cpp
+mkdir include\google\protobuf\compiler\csharp
+mkdir include\google\protobuf\compiler\java
+mkdir include\google\protobuf\compiler\javanano
+mkdir include\google\protobuf\compiler\js
+mkdir include\google\protobuf\compiler\objectivec
+mkdir include\google\protobuf\compiler\php
+mkdir include\google\protobuf\compiler\python
+mkdir include\google\protobuf\compiler\ruby
+mkdir include\google\protobuf\io
+mkdir include\google\protobuf\stubs
+mkdir include\google\protobuf\util
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\any.h" include\google\protobuf\any.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\any.pb.h" include\google\protobuf\any.pb.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\api.pb.h" include\google\protobuf\api.pb.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\arena.h" include\google\protobuf\arena.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\arenastring.h" include\google\protobuf\arenastring.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\code_generator.h" include\google\protobuf\compiler\code_generator.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\command_line_interface.h" include\google\protobuf\compiler\command_line_interface.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\cpp_generator.h" include\google\protobuf\compiler\cpp\cpp_generator.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_generator.h" include\google\protobuf\compiler\csharp\csharp_generator.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_names.h" include\google\protobuf\compiler\csharp\csharp_names.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\importer.h" include\google\protobuf\compiler\importer.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\java_generator.h" include\google\protobuf\compiler\java\java_generator.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\java_names.h" include\google\protobuf\compiler\java\java_names.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\javanano\javanano_generator.h" include\google\protobuf\compiler\javanano\javanano_generator.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\js\js_generator.h" include\google\protobuf\compiler\js\js_generator.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\js\well_known_types_embed.h" include\google\protobuf\compiler\js\well_known_types_embed.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\objectivec\objectivec_generator.h" include\google\protobuf\compiler\objectivec\objectivec_generator.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\objectivec\objectivec_helpers.h" include\google\protobuf\compiler\objectivec\objectivec_helpers.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\parser.h" include\google\protobuf\compiler\parser.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\php\php_generator.h" include\google\protobuf\compiler\php\php_generator.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\plugin.h" include\google\protobuf\compiler\plugin.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\plugin.pb.h" include\google\protobuf\compiler\plugin.pb.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\python\python_generator.h" include\google\protobuf\compiler\python\python_generator.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\ruby\ruby_generator.h" include\google\protobuf\compiler\ruby\ruby_generator.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor.h" include\google\protobuf\descriptor.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor.pb.h" include\google\protobuf\descriptor.pb.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor_database.h" include\google\protobuf\descriptor_database.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\duration.pb.h" include\google\protobuf\duration.pb.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\dynamic_message.h" include\google\protobuf\dynamic_message.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\empty.pb.h" include\google\protobuf\empty.pb.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\extension_set.h" include\google\protobuf\extension_set.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\field_mask.pb.h" include\google\protobuf\field_mask.pb.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_enum_reflection.h" include\google\protobuf\generated_enum_reflection.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_enum_util.h" include\google\protobuf\generated_enum_util.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_reflection.h" include\google\protobuf\generated_message_reflection.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_util.h" include\google\protobuf\generated_message_util.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\has_bits.h" include\google\protobuf\has_bits.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\coded_stream.h" include\google\protobuf\io\coded_stream.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\gzip_stream.h" include\google\protobuf\io\gzip_stream.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\printer.h" include\google\protobuf\io\printer.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\strtod.h" include\google\protobuf\io\strtod.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\tokenizer.h" include\google\protobuf\io\tokenizer.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\zero_copy_stream.h" include\google\protobuf\io\zero_copy_stream.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\zero_copy_stream_impl.h" include\google\protobuf\io\zero_copy_stream_impl.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\zero_copy_stream_impl_lite.h" include\google\protobuf\io\zero_copy_stream_impl_lite.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map.h" include\google\protobuf\map.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_entry.h" include\google\protobuf\map_entry.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_entry_lite.h" include\google\protobuf\map_entry_lite.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_field.h" include\google\protobuf\map_field.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_field_inl.h" include\google\protobuf\map_field_inl.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_field_lite.h" include\google\protobuf\map_field_lite.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_type_handler.h" include\google\protobuf\map_type_handler.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\message.h" include\google\protobuf\message.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\message_lite.h" include\google\protobuf\message_lite.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\metadata.h" include\google\protobuf\metadata.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\reflection.h" include\google\protobuf\reflection.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\reflection_ops.h" include\google\protobuf\reflection_ops.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\repeated_field.h" include\google\protobuf\repeated_field.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\service.h" include\google\protobuf\service.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\source_context.pb.h" include\google\protobuf\source_context.pb.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\struct.pb.h" include\google\protobuf\struct.pb.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomic_sequence_num.h" include\google\protobuf\stubs\atomic_sequence_num.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops.h" include\google\protobuf\stubs\atomicops.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_arm64_gcc.h" include\google\protobuf\stubs\atomicops_internals_arm64_gcc.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_arm_gcc.h" include\google\protobuf\stubs\atomicops_internals_arm_gcc.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_arm_qnx.h" include\google\protobuf\stubs\atomicops_internals_arm_qnx.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_atomicword_compat.h" include\google\protobuf\stubs\atomicops_internals_atomicword_compat.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_generic_c11_atomic.h" include\google\protobuf\stubs\atomicops_internals_generic_c11_atomic.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_generic_gcc.h" include\google\protobuf\stubs\atomicops_internals_generic_gcc.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_mips_gcc.h" include\google\protobuf\stubs\atomicops_internals_mips_gcc.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_power.h" include\google\protobuf\stubs\atomicops_internals_power.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_ppc_gcc.h" include\google\protobuf\stubs\atomicops_internals_ppc_gcc.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_solaris.h" include\google\protobuf\stubs\atomicops_internals_solaris.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_tsan.h" include\google\protobuf\stubs\atomicops_internals_tsan.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_x86_gcc.h" include\google\protobuf\stubs\atomicops_internals_x86_gcc.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_x86_msvc.h" include\google\protobuf\stubs\atomicops_internals_x86_msvc.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\bytestream.h" include\google\protobuf\stubs\bytestream.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\callback.h" include\google\protobuf\stubs\callback.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\casts.h" include\google\protobuf\stubs\casts.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\common.h" include\google\protobuf\stubs\common.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\fastmem.h" include\google\protobuf\stubs\fastmem.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\hash.h" include\google\protobuf\stubs\hash.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\logging.h" include\google\protobuf\stubs\logging.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\macros.h" include\google\protobuf\stubs\macros.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\mutex.h" include\google\protobuf\stubs\mutex.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\once.h" include\google\protobuf\stubs\once.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\platform_macros.h" include\google\protobuf\stubs\platform_macros.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\port.h" include\google\protobuf\stubs\port.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\scoped_ptr.h" include\google\protobuf\stubs\scoped_ptr.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\shared_ptr.h" include\google\protobuf\stubs\shared_ptr.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\singleton.h" include\google\protobuf\stubs\singleton.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\status.h" include\google\protobuf\stubs\status.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\stl_util.h" include\google\protobuf\stubs\stl_util.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\stringpiece.h" include\google\protobuf\stubs\stringpiece.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\template_util.h" include\google\protobuf\stubs\template_util.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\type_traits.h" include\google\protobuf\stubs\type_traits.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\text_format.h" include\google\protobuf\text_format.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\timestamp.pb.h" include\google\protobuf\timestamp.pb.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\type.pb.h" include\google\protobuf\type.pb.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\unknown_field_set.h" include\google\protobuf\unknown_field_set.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\field_comparator.h" include\google\protobuf\util\field_comparator.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\field_mask_util.h" include\google\protobuf\util\field_mask_util.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\json_util.h" include\google\protobuf\util\json_util.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\message_differencer.h" include\google\protobuf\util\message_differencer.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\time_util.h" include\google\protobuf\util\time_util.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\type_resolver.h" include\google\protobuf\util\type_resolver.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\type_resolver_util.h" include\google\protobuf\util\type_resolver_util.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wire_format.h" include\google\protobuf\wire_format.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wire_format_lite.h" include\google\protobuf\wire_format_lite.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wire_format_lite_inl.h" include\google\protobuf\wire_format_lite_inl.h
+copy "${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wrappers.pb.h" include\google\protobuf\wrappers.pb.h
diff --git a/third_party/protobuf/cmake/install.cmake b/third_party/protobuf/cmake/install.cmake
new file mode 100644
index 0000000000..28dc90dc3f
--- /dev/null
+++ b/third_party/protobuf/cmake/install.cmake
@@ -0,0 +1,117 @@
+include(GNUInstallDirs)
+
+foreach(_library
+ libprotobuf-lite
+ libprotobuf
+ libprotoc)
+ set_property(TARGET ${_library}
+ PROPERTY INTERFACE_INCLUDE_DIRECTORIES
+ $<BUILD_INTERFACE:${protobuf_source_dir}/src>
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
+ install(TARGETS ${_library} EXPORT protobuf-targets
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${_library}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library})
+endforeach()
+
+install(TARGETS protoc EXPORT protobuf-targets
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc)
+
+file(STRINGS extract_includes.bat.in _extract_strings
+ REGEX "^copy")
+foreach(_extract_string ${_extract_strings})
+ string(REGEX REPLACE "^.* .+ include\\\\(.+)$" "\\1"
+ _header ${_extract_string})
+ string(REPLACE "\\" "/" _header ${_header})
+ get_filename_component(_extract_from "${protobuf_SOURCE_DIR}/../src/${_header}" ABSOLUTE)
+ get_filename_component(_extract_name ${_header} NAME)
+ get_filename_component(_extract_to "${CMAKE_INSTALL_INCLUDEDIR}/${_header}" PATH)
+ if(EXISTS "${_extract_from}")
+ install(FILES "${_extract_from}"
+ DESTINATION "${_extract_to}"
+ COMPONENT protobuf-headers
+ RENAME "${_extract_name}")
+ else()
+ message(AUTHOR_WARNING "The file \"${_extract_from}\" is listed in "
+ "\"${protobuf_SOURCE_DIR}/cmake/extract_includes.bat.in\" "
+ "but there not exists. The file will not be installed.")
+ endif()
+endforeach()
+
+# Internal function for parsing auto tools scripts
+function(_protobuf_auto_list FILE_NAME VARIABLE)
+ file(STRINGS ${FILE_NAME} _strings)
+ set(_list)
+ foreach(_string ${_strings})
+ set(_found)
+ string(REGEX MATCH "^[ \t]*${VARIABLE}[ \t]*=[ \t]*" _found "${_string}")
+ if(_found)
+ string(LENGTH "${_found}" _length)
+ string(SUBSTRING "${_string}" ${_length} -1 _draft_list)
+ foreach(_item ${_draft_list})
+ string(STRIP "${_item}" _item)
+ list(APPEND _list "${_item}")
+ endforeach()
+ endif()
+ endforeach()
+ set(${VARIABLE} ${_list} PARENT_SCOPE)
+endfunction()
+
+# Install well-known type proto files
+_protobuf_auto_list("../src/Makefile.am" nobase_dist_proto_DATA)
+foreach(_file ${nobase_dist_proto_DATA})
+ get_filename_component(_file_from "../src/${_file}" ABSOLUTE)
+ get_filename_component(_file_name ${_file} NAME)
+ get_filename_component(_file_path ${_file} PATH)
+ if(EXISTS "${_file_from}")
+ install(FILES "${_file_from}"
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_file_path}"
+ COMPONENT protobuf-protos
+ RENAME "${_file_name}")
+ else()
+ message(AUTHOR_WARNING "The file \"${_file_from}\" is listed in "
+ "\"${protobuf_SOURCE_DIR}/../src/Makefile.am\" as nobase_dist_proto_DATA "
+ "but there not exists. The file will not be installed.")
+ endif()
+endforeach()
+
+# Install configuration
+set(_cmakedir_desc "Directory relative to CMAKE_INSTALL to install the cmake configuration files")
+if(NOT MSVC)
+ set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/protobuf" CACHE STRING "${_cmakedir_desc}")
+else()
+ set(CMAKE_INSTALL_CMAKEDIR "cmake" CACHE STRING "${_cmakedir_desc}")
+endif()
+mark_as_advanced(CMAKE_INSTALL_CMAKEDIR)
+
+configure_file(protobuf-config.cmake.in
+ ${CMAKE_INSTALL_CMAKEDIR}/protobuf-config.cmake @ONLY)
+configure_file(protobuf-config-version.cmake.in
+ ${CMAKE_INSTALL_CMAKEDIR}/protobuf-config-version.cmake @ONLY)
+configure_file(protobuf-module.cmake.in
+ ${CMAKE_INSTALL_CMAKEDIR}/protobuf-module.cmake @ONLY)
+configure_file(protobuf-options.cmake
+ ${CMAKE_INSTALL_CMAKEDIR}/protobuf-options.cmake @ONLY)
+
+# Allows the build directory to be used as a find directory.
+export(TARGETS libprotobuf-lite libprotobuf libprotoc protoc
+ NAMESPACE protobuf::
+ FILE ${CMAKE_INSTALL_CMAKEDIR}/protobuf-targets.cmake
+)
+
+install(EXPORT protobuf-targets
+ DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
+ NAMESPACE protobuf::
+ COMPONENT protobuf-export)
+
+install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/
+ DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
+ COMPONENT protobuf-export
+ PATTERN protobuf-targets.cmake EXCLUDE
+)
+
+option(protobuf_INSTALL_EXAMPLES "Install the examples folder" OFF)
+if(protobuf_INSTALL_EXAMPLES)
+ install(DIRECTORY ../examples/ DESTINATION examples
+ COMPONENT protobuf-examples)
+endif()
diff --git a/third_party/protobuf/cmake/libprotobuf-lite.cmake b/third_party/protobuf/cmake/libprotobuf-lite.cmake
new file mode 100644
index 0000000000..036b051707
--- /dev/null
+++ b/third_party/protobuf/cmake/libprotobuf-lite.cmake
@@ -0,0 +1,38 @@
+set(libprotobuf_lite_files
+ ${protobuf_source_dir}/src/google/protobuf/arena.cc
+ ${protobuf_source_dir}/src/google/protobuf/arenastring.cc
+ ${protobuf_source_dir}/src/google/protobuf/extension_set.cc
+ ${protobuf_source_dir}/src/google/protobuf/generated_message_util.cc
+ ${protobuf_source_dir}/src/google/protobuf/io/coded_stream.cc
+ ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.cc
+ ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.cc
+ ${protobuf_source_dir}/src/google/protobuf/message_lite.cc
+ ${protobuf_source_dir}/src/google/protobuf/repeated_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/bytestream.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/common.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/int128.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/once.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/status.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/statusor.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/stringpiece.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/stringprintf.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/structurally_valid.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/strutil.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/time.cc
+ ${protobuf_source_dir}/src/google/protobuf/wire_format_lite.cc
+)
+
+add_library(libprotobuf-lite ${protobuf_SHARED_OR_STATIC}
+ ${libprotobuf_lite_files})
+target_link_libraries(libprotobuf-lite ${CMAKE_THREAD_LIBS_INIT})
+target_include_directories(libprotobuf-lite PUBLIC ${protobuf_source_dir}/src)
+if(MSVC AND protobuf_BUILD_SHARED_LIBS)
+ target_compile_definitions(libprotobuf-lite
+ PUBLIC PROTOBUF_USE_DLLS
+ PRIVATE LIBPROTOBUF_EXPORTS)
+endif()
+set_target_properties(libprotobuf-lite PROPERTIES
+ OUTPUT_NAME ${LIB_PREFIX}protobuf-lite
+ DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}")
diff --git a/third_party/protobuf/cmake/libprotobuf.cmake b/third_party/protobuf/cmake/libprotobuf.cmake
new file mode 100644
index 0000000000..5313d39ef8
--- /dev/null
+++ b/third_party/protobuf/cmake/libprotobuf.cmake
@@ -0,0 +1,72 @@
+set(libprotobuf_files
+ ${protobuf_source_dir}/src/google/protobuf/any.cc
+ ${protobuf_source_dir}/src/google/protobuf/any.pb.cc
+ ${protobuf_source_dir}/src/google/protobuf/api.pb.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/importer.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/parser.cc
+ ${protobuf_source_dir}/src/google/protobuf/descriptor.cc
+ ${protobuf_source_dir}/src/google/protobuf/descriptor.pb.cc
+ ${protobuf_source_dir}/src/google/protobuf/descriptor_database.cc
+ ${protobuf_source_dir}/src/google/protobuf/duration.pb.cc
+ ${protobuf_source_dir}/src/google/protobuf/dynamic_message.cc
+ ${protobuf_source_dir}/src/google/protobuf/empty.pb.cc
+ ${protobuf_source_dir}/src/google/protobuf/extension_set_heavy.cc
+ ${protobuf_source_dir}/src/google/protobuf/field_mask.pb.cc
+ ${protobuf_source_dir}/src/google/protobuf/generated_message_reflection.cc
+ ${protobuf_source_dir}/src/google/protobuf/io/gzip_stream.cc
+ ${protobuf_source_dir}/src/google/protobuf/io/printer.cc
+ ${protobuf_source_dir}/src/google/protobuf/io/strtod.cc
+ ${protobuf_source_dir}/src/google/protobuf/io/tokenizer.cc
+ ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl.cc
+ ${protobuf_source_dir}/src/google/protobuf/map_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/message.cc
+ ${protobuf_source_dir}/src/google/protobuf/reflection_ops.cc
+ ${protobuf_source_dir}/src/google/protobuf/service.cc
+ ${protobuf_source_dir}/src/google/protobuf/source_context.pb.cc
+ ${protobuf_source_dir}/src/google/protobuf/struct.pb.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/mathlimits.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/substitute.cc
+ ${protobuf_source_dir}/src/google/protobuf/text_format.cc
+ ${protobuf_source_dir}/src/google/protobuf/timestamp.pb.cc
+ ${protobuf_source_dir}/src/google/protobuf/type.pb.cc
+ ${protobuf_source_dir}/src/google/protobuf/unknown_field_set.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/delimited_message_util.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/field_comparator.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/field_mask_util.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/datapiece.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/default_value_objectwriter.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/error_listener.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/field_mask_utility.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/json_escaping.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/json_objectwriter.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/json_stream_parser.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/object_writer.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/proto_writer.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectsource.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectwriter.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/type_info.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/type_info_test_helper.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/utility.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/json_util.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/message_differencer.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/time_util.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/type_resolver_util.cc
+ ${protobuf_source_dir}/src/google/protobuf/wire_format.cc
+ ${protobuf_source_dir}/src/google/protobuf/wrappers.pb.cc
+)
+
+add_library(libprotobuf ${protobuf_SHARED_OR_STATIC}
+ ${libprotobuf_lite_files} ${libprotobuf_files})
+target_link_libraries(libprotobuf ${CMAKE_THREAD_LIBS_INIT})
+if(protobuf_WITH_ZLIB)
+ target_link_libraries(libprotobuf ${ZLIB_LIBRARIES})
+endif()
+target_include_directories(libprotobuf PUBLIC ${protobuf_source_dir}/src)
+if(MSVC AND protobuf_BUILD_SHARED_LIBS)
+ target_compile_definitions(libprotobuf
+ PUBLIC PROTOBUF_USE_DLLS
+ PRIVATE LIBPROTOBUF_EXPORTS)
+endif()
+set_target_properties(libprotobuf PROPERTIES
+ OUTPUT_NAME ${LIB_PREFIX}protobuf
+ DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}")
diff --git a/third_party/protobuf/cmake/libprotoc.cmake b/third_party/protobuf/cmake/libprotoc.cmake
new file mode 100644
index 0000000000..29b3253873
--- /dev/null
+++ b/third_party/protobuf/cmake/libprotoc.cmake
@@ -0,0 +1,120 @@
+set(libprotoc_files
+ ${protobuf_source_dir}/src/google/protobuf/compiler/code_generator.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/command_line_interface.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_enum.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_extension.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_file.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_generator.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_helpers.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_map_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_message.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_message_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_service.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_string_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_enum.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_enum_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_field_base.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_generator.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_helpers.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_map_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_message.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_message_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_context.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_doc_comment.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_enum.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_enum_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_enum_field_lite.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_enum_lite.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_extension.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_extension_lite.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_file.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_generator.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_generator_factory.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_helpers.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_lazy_message_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_map_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_map_field_lite.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_builder.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_builder_lite.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_field_lite.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_lite.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_name_resolver.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_primitive_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_primitive_field_lite.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_service.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_shared_code_generator.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_string_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_string_field_lite.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_enum.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_enum_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_extension.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_file.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_generator.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_helpers.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_map_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_message.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_message_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/js/js_generator.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types_embed.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_enum.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_extension.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_file.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_generator.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_message.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/php/php_generator.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/plugin.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/plugin.pb.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/python/python_generator.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/ruby/ruby_generator.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/subprocess.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/zip_writer.cc
+)
+
+set(js_well_known_types_sources
+ ${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types/any.js
+ ${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types/struct.js
+ ${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types/timestamp.js
+)
+add_executable(js_embed ${protobuf_source_dir}/src/google/protobuf/compiler/js/embed.cc)
+add_custom_command(
+ OUTPUT ${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types_embed.cc
+ DEPENDS js_embed ${js_well_known_types_sources}
+ COMMAND js_embed ${js_well_known_types_sources} > ${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types_embed.cc
+)
+
+add_library(libprotoc ${protobuf_SHARED_OR_STATIC}
+ ${libprotoc_files})
+target_link_libraries(libprotoc libprotobuf)
+if(MSVC AND protobuf_BUILD_SHARED_LIBS)
+ target_compile_definitions(libprotoc
+ PUBLIC PROTOBUF_USE_DLLS
+ PRIVATE LIBPROTOC_EXPORTS)
+endif()
+set_target_properties(libprotoc PROPERTIES
+ COMPILE_DEFINITIONS LIBPROTOC_EXPORTS
+ OUTPUT_NAME ${LIB_PREFIX}protoc
+ DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}")
diff --git a/third_party/protobuf/cmake/protobuf-config-version.cmake.in b/third_party/protobuf/cmake/protobuf-config-version.cmake.in
new file mode 100644
index 0000000000..0036c9ef54
--- /dev/null
+++ b/third_party/protobuf/cmake/protobuf-config-version.cmake.in
@@ -0,0 +1,58 @@
+set(PACKAGE_VERSION "@protobuf_VERSION@")
+set(${PACKAGE_FIND_NAME}_VERSION_PRERELEASE "@protobuf_VERSION_PRERELEASE@" PARENT_SCOPE)
+
+# Prerelease versions cannot be passed in directly via the find_package command,
+# so we allow users to specify it in a variable
+if(NOT DEFINED "${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE")
+ set("${${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE}" "")
+else()
+ set(PACKAGE_FIND_VERSION ${PACKAGE_FIND_VERSION}-${${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE})
+endif()
+set(PACKAGE_FIND_VERSION_PRERELEASE "${${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE}")
+
+# VERSION_EQUAL ignores the prerelease strings, so we use STREQUAL.
+if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
+ set(PACKAGE_VERSION_EXACT TRUE)
+endif()
+
+set(PACKAGE_VERSION_COMPATIBLE TRUE) #Assume true until shown otherwise
+
+if(NOT PACKAGE_FIND_VERSION_MAJOR EQUAL "@protobuf_VERSION_MAJOR@")
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+elseif(PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION)
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+elseif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
+ # Do not match prerelease versions to non-prerelease version requests.
+ if(NOT "@protobuf_VERSION_PRERELEASE@" STREQUAL "" AND PACKAGE_FIND_VERSION_PRERELEASE STREQUAL "")
+ message(AUTHOR_WARNING "To use this prerelease version of ${PACKAGE_FIND_NAME}, set ${PACKAGE_FIND_NAME}_FIND_VERSION_PRERELEASE to '@protobuf_VERSION_PRERELEASE@' or greater.")
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+ endif()
+
+ # Not robustly SemVer compliant, but protobuf never uses '.' separated prerelease identifiers.
+ if(PACKAGE_FIND_VERSION_PRERELEASE STRGREATER "@protobuf_VERSION_PRERELEASE@")
+ set(PACKAGE_VERSION_COMPATIBLE FALSE)
+ endif()
+endif()
+
+# Check and save build options used to create this package
+macro(_check_and_save_build_option OPTION VALUE)
+ if(DEFINED ${PACKAGE_FIND_NAME}_${OPTION} AND
+ NOT ${PACKAGE_FIND_NAME}_${OPTION} EQUAL VALUE)
+ set(PACKAGE_VERSION_UNSUITABLE TRUE)
+ endif()
+ set(${PACKAGE_FIND_NAME}_${OPTION} ${VALUE})
+endmacro()
+_check_and_save_build_option(WITH_ZLIB @protobuf_WITH_ZLIB@)
+_check_and_save_build_option(MSVC_STATIC_RUNTIME @protobuf_MSVC_STATIC_RUNTIME@)
+_check_and_save_build_option(BUILD_SHARED_LIBS @protobuf_BUILD_SHARED_LIBS@)
+
+# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it:
+if(NOT "${CMAKE_SIZEOF_VOID_P}" STREQUAL "" AND NOT "@CMAKE_SIZEOF_VOID_P@" STREQUAL "")
+ # check that the installed version has the same 32/64bit-ness as the one which is currently searching:
+ if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "@CMAKE_SIZEOF_VOID_P@")
+ math(EXPR installedBits "@CMAKE_SIZEOF_VOID_P@ * 8")
+ set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)")
+ set(PACKAGE_VERSION_UNSUITABLE TRUE)
+ endif()
+endif()
+
diff --git a/third_party/protobuf/cmake/protobuf-config.cmake.in b/third_party/protobuf/cmake/protobuf-config.cmake.in
new file mode 100644
index 0000000000..a044fe5c67
--- /dev/null
+++ b/third_party/protobuf/cmake/protobuf-config.cmake.in
@@ -0,0 +1,13 @@
+# User options
+include("${CMAKE_CURRENT_LIST_DIR}/protobuf-options.cmake")
+
+# Depend packages
+@_protobuf_FIND_ZLIB@
+
+# Imported targets
+include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake")
+
+# CMake FindProtobuf module compatible file
+if(protobuf_MODULE_COMPATIBLE)
+ include("${CMAKE_CURRENT_LIST_DIR}/protobuf-module.cmake")
+endif()
diff --git a/third_party/protobuf/cmake/protobuf-module.cmake.in b/third_party/protobuf/cmake/protobuf-module.cmake.in
new file mode 100644
index 0000000000..614e4c0454
--- /dev/null
+++ b/third_party/protobuf/cmake/protobuf-module.cmake.in
@@ -0,0 +1,233 @@
+# Functions
+
+function(PROTOBUF_GENERATE_CPP SRCS HDRS)
+ if(NOT ARGN)
+ message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files")
+ return()
+ endif()
+
+ if(PROTOBUF_GENERATE_CPP_APPEND_PATH)
+ # Create an include path for each file specified
+ foreach(FIL ${ARGN})
+ get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
+ get_filename_component(ABS_PATH ${ABS_FIL} PATH)
+ list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
+ if(${_contains_already} EQUAL -1)
+ list(APPEND _protobuf_include_path -I ${ABS_PATH})
+ endif()
+ endforeach()
+ else()
+ set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})
+ endif()
+
+ if(DEFINED Protobuf_IMPORT_DIRS)
+ foreach(DIR ${Protobuf_IMPORT_DIRS})
+ get_filename_component(ABS_PATH ${DIR} ABSOLUTE)
+ list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
+ if(${_contains_already} EQUAL -1)
+ list(APPEND _protobuf_include_path -I ${ABS_PATH})
+ endif()
+ endforeach()
+ endif()
+
+ set(${SRCS})
+ set(${HDRS})
+ foreach(FIL ${ARGN})
+ get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
+ get_filename_component(FIL_WE ${FIL} NAME_WE)
+
+ list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
+ list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
+
+ add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
+ "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
+ COMMAND ${Protobuf_PROTOC_EXECUTABLE}
+ ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
+ DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE}
+ COMMENT "Running C++ protocol buffer compiler on ${FIL}"
+ VERBATIM )
+ endforeach()
+
+ set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
+ set(${SRCS} ${${SRCS}} PARENT_SCOPE)
+ set(${HDRS} ${${HDRS}} PARENT_SCOPE)
+endfunction()
+
+function(PROTOBUF_GENERATE_PYTHON SRCS)
+ if(NOT ARGN)
+ message(SEND_ERROR "Error: PROTOBUF_GENERATE_PYTHON() called without any proto files")
+ return()
+ endif()
+
+ if(PROTOBUF_GENERATE_CPP_APPEND_PATH)
+ # Create an include path for each file specified
+ foreach(FIL ${ARGN})
+ get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
+ get_filename_component(ABS_PATH ${ABS_FIL} PATH)
+ list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
+ if(${_contains_already} EQUAL -1)
+ list(APPEND _protobuf_include_path -I ${ABS_PATH})
+ endif()
+ endforeach()
+ else()
+ set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})
+ endif()
+
+ if(DEFINED Protobuf_IMPORT_DIRS)
+ foreach(DIR ${Protobuf_IMPORT_DIRS})
+ get_filename_component(ABS_PATH ${DIR} ABSOLUTE)
+ list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
+ if(${_contains_already} EQUAL -1)
+ list(APPEND _protobuf_include_path -I ${ABS_PATH})
+ endif()
+ endforeach()
+ endif()
+
+ set(${SRCS})
+ foreach(FIL ${ARGN})
+ get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
+ get_filename_component(FIL_WE ${FIL} NAME_WE)
+
+ list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2.py")
+ add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2.py"
+ COMMAND ${Protobuf_PROTOC_EXECUTABLE} --python_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
+ DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE}
+ COMMENT "Running Python protocol buffer compiler on ${FIL}"
+ VERBATIM )
+ endforeach()
+
+ set(${SRCS} ${${SRCS}} PARENT_SCOPE)
+endfunction()
+
+# Environment
+
+# Backwards compatibility
+# Define camel case versions of input variables
+foreach(UPPER
+ PROTOBUF_SRC_ROOT_FOLDER
+ PROTOBUF_IMPORT_DIRS
+ PROTOBUF_DEBUG
+ PROTOBUF_LIBRARY
+ PROTOBUF_PROTOC_LIBRARY
+ PROTOBUF_INCLUDE_DIR
+ PROTOBUF_PROTOC_EXECUTABLE
+ PROTOBUF_LIBRARY_DEBUG
+ PROTOBUF_PROTOC_LIBRARY_DEBUG
+ PROTOBUF_LITE_LIBRARY
+ PROTOBUF_LITE_LIBRARY_DEBUG
+ )
+ if (DEFINED ${UPPER})
+ string(REPLACE "PROTOBUF_" "Protobuf_" Camel ${UPPER})
+ if (NOT DEFINED ${Camel})
+ set(${Camel} ${${UPPER}})
+ endif()
+ endif()
+endforeach()
+
+if(DEFINED Protobuf_SRC_ROOT_FOLDER)
+ message(AUTHOR_WARNING "Variable Protobuf_SRC_ROOT_FOLDER defined, but not"
+ " used in CONFIG mode")
+endif()
+
+include(SelectLibraryConfigurations)
+
+# Internal function: search for normal library as well as a debug one
+# if the debug one is specified also include debug/optimized keywords
+# in *_LIBRARIES variable
+function(_protobuf_find_libraries name filename)
+ if(${name}_LIBRARIES)
+ # Use result recorded by a previous call.
+ elseif(${name}_LIBRARY)
+ # Honor cache entry used by CMake 3.5 and lower.
+ set(${name}_LIBRARIES "${${name}_LIBRARY}" PARENT_SCOPE)
+ else()
+ get_target_property(${name}_LIBRARY_RELEASE protobuf::lib${filename}
+ LOCATION_RELEASE)
+ get_target_property(${name}_LIBRARY_DEBUG protobuf::lib${filename}
+ LOCATION_DEBUG)
+
+ select_library_configurations(${name})
+ set(${name}_LIBRARY ${${name}_LIBRARY} PARENT_SCOPE)
+ set(${name}_LIBRARIES ${${name}_LIBRARIES} PARENT_SCOPE)
+ endif()
+endfunction()
+
+# Internal function: find threads library
+function(_protobuf_find_threads)
+ set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
+ find_package(Threads)
+ if(Threads_FOUND)
+ list(APPEND PROTOBUF_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
+ set(PROTOBUF_LIBRARIES "${PROTOBUF_LIBRARIES}" PARENT_SCOPE)
+ endif()
+endfunction()
+
+#
+# Main.
+#
+
+# By default have PROTOBUF_GENERATE_CPP macro pass -I to protoc
+# for each directory where a proto file is referenced.
+if(NOT DEFINED PROTOBUF_GENERATE_CPP_APPEND_PATH)
+ set(PROTOBUF_GENERATE_CPP_APPEND_PATH TRUE)
+endif()
+
+# The Protobuf library
+_protobuf_find_libraries(Protobuf protobuf)
+
+# The Protobuf Lite library
+_protobuf_find_libraries(Protobuf_LITE protobuf-lite)
+
+# The Protobuf Protoc Library
+_protobuf_find_libraries(Protobuf_PROTOC protoc)
+
+if(UNIX)
+ _protobuf_find_threads()
+endif()
+
+# Set the include directory
+get_target_property(Protobuf_INCLUDE_DIRS protobuf::libprotobuf
+ INTERFACE_INCLUDE_DIRECTORIES)
+
+# Set the protoc Executable
+get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
+ IMPORTED_LOCATION_RELEASE)
+if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
+ get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
+ IMPORTED_LOCATION_DEBUG)
+endif()
+
+# Version info variable
+set(Protobuf_VERSION "@protobuf_VERSION@")
+
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Protobuf
+ REQUIRED_VARS Protobuf_PROTOC_EXECUTABLE Protobuf_LIBRARIES Protobuf_INCLUDE_DIRS
+ VERSION_VAR Protobuf_VERSION
+)
+
+# Backwards compatibility
+# Define upper case versions of output variables
+foreach(Camel
+ Protobuf_VERSION
+ Protobuf_SRC_ROOT_FOLDER
+ Protobuf_IMPORT_DIRS
+ Protobuf_DEBUG
+ Protobuf_INCLUDE_DIRS
+ Protobuf_LIBRARIES
+ Protobuf_PROTOC_LIBRARIES
+ Protobuf_LITE_LIBRARIES
+ Protobuf_LIBRARY
+ Protobuf_PROTOC_LIBRARY
+ Protobuf_INCLUDE_DIR
+ Protobuf_PROTOC_EXECUTABLE
+ Protobuf_LIBRARY_DEBUG
+ Protobuf_PROTOC_LIBRARY_DEBUG
+ Protobuf_LITE_LIBRARY
+ Protobuf_LITE_LIBRARY_DEBUG
+ )
+ string(TOUPPER ${Camel} UPPER)
+ set(${UPPER} ${${Camel}})
+endforeach()
diff --git a/third_party/protobuf/cmake/protobuf-options.cmake b/third_party/protobuf/cmake/protobuf-options.cmake
new file mode 100644
index 0000000000..47fb158257
--- /dev/null
+++ b/third_party/protobuf/cmake/protobuf-options.cmake
@@ -0,0 +1,7 @@
+# Verbose output
+option(protobuf_VERBOSE "Enable for verbose output" OFF)
+mark_as_advanced(protobuf_VERBOSE)
+
+# FindProtobuf module compatibel
+option(protobuf_MODULE_COMPATIBLE "CMake build-in FindProtobuf.cmake module compatible" OFF)
+mark_as_advanced(protobuf_MODULE_COMPATIBLE)
diff --git a/third_party/protobuf/cmake/protoc.cmake b/third_party/protobuf/cmake/protoc.cmake
new file mode 100644
index 0000000000..4f07c389c9
--- /dev/null
+++ b/third_party/protobuf/cmake/protoc.cmake
@@ -0,0 +1,6 @@
+set(protoc_files
+ ${protobuf_source_dir}/src/google/protobuf/compiler/main.cc
+)
+
+add_executable(protoc ${protoc_files})
+target_link_libraries(protoc libprotobuf libprotoc)
diff --git a/third_party/protobuf/cmake/tests.cmake b/third_party/protobuf/cmake/tests.cmake
new file mode 100644
index 0000000000..1470e4b036
--- /dev/null
+++ b/third_party/protobuf/cmake/tests.cmake
@@ -0,0 +1,221 @@
+if (NOT EXISTS "${PROJECT_SOURCE_DIR}/../gmock/CMakeLists.txt")
+ message(FATAL_ERROR "Cannot find gmock directory.")
+endif()
+
+option(protobuf_ABSOLUTE_TEST_PLUGIN_PATH
+ "Using absolute test_plugin path in tests" ON)
+mark_as_advanced(protobuf_ABSOLUTE_TEST_PLUGIN_PATH)
+
+include_directories(
+ ${protobuf_source_dir}/gmock
+ ${protobuf_source_dir}/gmock/gtest
+ ${protobuf_source_dir}/gmock/gtest/include
+ ${protobuf_source_dir}/gmock/include
+)
+
+add_library(gmock STATIC
+ ${protobuf_source_dir}/gmock/src/gmock-all.cc
+ ${protobuf_source_dir}/gmock/gtest/src/gtest-all.cc
+)
+target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT})
+add_library(gmock_main STATIC ${protobuf_source_dir}/gmock/src/gmock_main.cc)
+target_link_libraries(gmock_main gmock)
+
+set(lite_test_protos
+ google/protobuf/map_lite_unittest.proto
+ google/protobuf/unittest_import_lite.proto
+ google/protobuf/unittest_import_public_lite.proto
+ google/protobuf/unittest_lite.proto
+ google/protobuf/unittest_no_arena_lite.proto
+)
+
+set(tests_protos
+ google/protobuf/any_test.proto
+ google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto
+ google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto
+ google/protobuf/map_proto2_unittest.proto
+ google/protobuf/map_unittest.proto
+ google/protobuf/unittest.proto
+ google/protobuf/unittest_arena.proto
+ google/protobuf/unittest_custom_options.proto
+ google/protobuf/unittest_drop_unknown_fields.proto
+ google/protobuf/unittest_embed_optimize_for.proto
+ google/protobuf/unittest_empty.proto
+ google/protobuf/unittest_import.proto
+ google/protobuf/unittest_import_public.proto
+ google/protobuf/unittest_lite_imports_nonlite.proto
+ google/protobuf/unittest_mset.proto
+ google/protobuf/unittest_mset_wire_format.proto
+ google/protobuf/unittest_no_arena.proto
+ google/protobuf/unittest_no_arena_import.proto
+ google/protobuf/unittest_no_field_presence.proto
+ google/protobuf/unittest_no_generic_services.proto
+ google/protobuf/unittest_optimize_for.proto
+ google/protobuf/unittest_preserve_unknown_enum.proto
+ google/protobuf/unittest_preserve_unknown_enum2.proto
+ google/protobuf/unittest_proto3_arena.proto
+ google/protobuf/unittest_proto3_arena_lite.proto
+ google/protobuf/unittest_proto3_lite.proto
+ google/protobuf/unittest_well_known_types.proto
+ google/protobuf/util/internal/testdata/anys.proto
+ google/protobuf/util/internal/testdata/books.proto
+ google/protobuf/util/internal/testdata/default_value.proto
+ google/protobuf/util/internal/testdata/default_value_test.proto
+ 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
+)
+
+macro(compile_proto_file filename)
+ get_filename_component(dirname ${filename} PATH)
+ get_filename_component(basename ${filename} NAME_WE)
+ add_custom_command(
+ OUTPUT ${protobuf_source_dir}/src/${dirname}/${basename}.pb.cc
+ DEPENDS protoc ${protobuf_source_dir}/src/${dirname}/${basename}.proto
+ COMMAND protoc ${protobuf_source_dir}/src/${dirname}/${basename}.proto
+ --proto_path=${protobuf_source_dir}/src
+ --cpp_out=${protobuf_source_dir}/src
+ )
+endmacro(compile_proto_file)
+
+set(lite_test_proto_files)
+foreach(proto_file ${lite_test_protos})
+ compile_proto_file(${proto_file})
+ string(REPLACE .proto .pb.cc pb_file ${proto_file})
+ set(lite_test_proto_files ${lite_test_proto_files}
+ ${protobuf_source_dir}/src/${pb_file})
+endforeach(proto_file)
+
+set(tests_proto_files)
+foreach(proto_file ${tests_protos})
+ compile_proto_file(${proto_file})
+ string(REPLACE .proto .pb.cc pb_file ${proto_file})
+ set(tests_proto_files ${tests_proto_files}
+ ${protobuf_source_dir}/src/${pb_file})
+endforeach(proto_file)
+
+set(common_test_files
+ ${protobuf_source_dir}/src/google/protobuf/arena_test_util.cc
+ ${protobuf_source_dir}/src/google/protobuf/map_test_util.cc
+ ${protobuf_source_dir}/src/google/protobuf/test_util.cc
+ ${protobuf_source_dir}/src/google/protobuf/testing/file.cc
+ ${protobuf_source_dir}/src/google/protobuf/testing/googletest.cc
+)
+
+set(common_lite_test_files
+ ${protobuf_source_dir}/src/google/protobuf/arena_test_util.cc
+ ${protobuf_source_dir}/src/google/protobuf/map_lite_test_util.cc
+ ${protobuf_source_dir}/src/google/protobuf/test_util_lite.cc
+)
+
+set(tests_files
+ ${protobuf_source_dir}/src/google/protobuf/any_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/arena_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/arenastring_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/command_line_interface_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/cpp/metadata_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/importer_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/java/java_plugin_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/parser_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/python/python_plugin_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/descriptor_database_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/descriptor_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/drop_unknown_fields_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/dynamic_message_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/extension_set_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/generated_message_reflection_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/io/coded_stream_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/io/printer_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/io/tokenizer_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/map_field_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/map_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/message_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/no_field_presence_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/preserve_unknown_enum_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/proto3_arena_lite_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/proto3_arena_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/proto3_lite_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/reflection_ops_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/repeated_field_reflection_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/repeated_field_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/bytestream_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/common_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/int128_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/once_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/status_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/statusor_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/stringpiece_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/stringprintf_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/structurally_valid_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/strutil_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/template_util_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/time_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/stubs/type_traits_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/text_format_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/unknown_field_set_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/delimited_message_util_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/field_comparator_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/field_mask_util_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/default_value_objectwriter_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/json_objectwriter_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/json_stream_parser_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectsource_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectwriter_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/internal/type_info_test_helper.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/json_util_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/message_differencer_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/time_util_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/util/type_resolver_util_test.cc
+ ${protobuf_source_dir}/src/google/protobuf/well_known_types_unittest.cc
+ ${protobuf_source_dir}/src/google/protobuf/wire_format_unittest.cc
+)
+
+if(protobuf_ABSOLUTE_TEST_PLUGIN_PATH)
+ add_compile_options(-DGOOGLE_PROTOBUF_TEST_PLUGIN_PATH="$<TARGET_FILE:test_plugin>")
+endif()
+
+add_executable(tests ${tests_files} ${common_test_files} ${tests_proto_files} ${lite_test_proto_files})
+target_link_libraries(tests libprotoc libprotobuf gmock_main)
+
+set(test_plugin_files
+ ${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc
+ ${protobuf_source_dir}/src/google/protobuf/testing/file.cc
+ ${protobuf_source_dir}/src/google/protobuf/testing/file.h
+ ${protobuf_source_dir}/src/google/protobuf/compiler/test_plugin.cc
+)
+
+add_executable(test_plugin ${test_plugin_files})
+target_link_libraries(test_plugin libprotoc libprotobuf gmock)
+
+set(lite_test_files
+ ${protobuf_source_dir}/src/google/protobuf/lite_unittest.cc
+)
+add_executable(lite-test ${lite_test_files} ${common_lite_test_files} ${lite_test_proto_files})
+target_link_libraries(lite-test libprotobuf-lite)
+
+set(lite_arena_test_files
+ ${protobuf_source_dir}/src/google/protobuf/lite_arena_unittest.cc
+)
+add_executable(lite-arena-test ${lite_arena_test_files} ${common_lite_test_files} ${lite_test_proto_files})
+target_link_libraries(lite-arena-test libprotobuf-lite gmock_main)
+
+add_custom_target(check
+ COMMAND tests
+ DEPENDS tests test_plugin
+ WORKING_DIRECTORY ${protobuf_source_dir})
diff --git a/third_party/protobuf/3.0.0/com_google_protobuf_java.BUILD b/third_party/protobuf/com_google_protobuf_java.BUILD
index fe8e3f0fcb..c507b8a4c6 100644
--- a/third_party/protobuf/3.0.0/com_google_protobuf_java.BUILD
+++ b/third_party/protobuf/com_google_protobuf_java.BUILD
@@ -1,6 +1,6 @@
java_import(
name = "protobuf",
- jars = ["protobuf-java-3.0.0.jar"],
+ jars = ["protobuf-java-3.2.0.jar"],
)
proto_lang_toolchain(
diff --git a/third_party/protobuf/composer.json b/third_party/protobuf/composer.json
new file mode 100644
index 0000000000..2b04e07934
--- /dev/null
+++ b/third_party/protobuf/composer.json
@@ -0,0 +1,23 @@
+{
+ "name": "google/protobuf",
+ "type": "library",
+ "description": "proto library for PHP",
+ "keywords": ["proto"],
+ "homepage": "https://developers.google.com/protocol-buffers/",
+ "license": "BSD-3-Clause",
+ "require": {
+ "php": ">=5.5.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": ">=4.8.0"
+ },
+ "autoload": {
+ "psr-4": {
+ "Google\\Protobuf\\Internal\\": "php/src/Google/Protobuf/Internal",
+ "GPBMetadata\\Google\\Protobuf\\Internal\\": "php/src/GPBMetadata/Google/Protobuf/Internal"
+ },
+ "files": [
+ "php/src/Google/Protobuf/descriptor.php"
+ ]
+ }
+}
diff --git a/third_party/protobuf/configure.ac b/third_party/protobuf/configure.ac
new file mode 100644
index 0000000000..531e25fbc8
--- /dev/null
+++ b/third_party/protobuf/configure.ac
@@ -0,0 +1,211 @@
+## Process this file with autoconf to produce configure.
+## In general, the safest way to proceed is to run ./autogen.sh
+
+AC_PREREQ(2.59)
+
+# Note: If you change the version, you must also update it in:
+# * Protobuf.podspec
+# * csharp/Google.Protobuf.Tools.nuspec
+# * csharp/src/*/AssemblyInfo.cs
+# * csharp/src/Google.Protobuf/Google.Protobuf.nuspec
+# * java/*/pom.xml
+# * python/google/protobuf/__init__.py
+# * protoc-artifacts/pom.xml
+# * src/google/protobuf/stubs/common.h
+# * src/Makefile.am (Update -version-info for LDFLAGS if needed)
+#
+# In the SVN trunk, the version should always be the next anticipated release
+# version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed
+# the size of one file name in the dist tarfile over the 99-char limit.)
+AC_INIT([Protocol Buffers],[3.2.0],[protobuf@googlegroups.com],[protobuf])
+
+AM_MAINTAINER_MODE([enable])
+
+AC_CONFIG_SRCDIR(src/google/protobuf/message.cc)
+# The config file is generated but not used by the source code, since we only
+# need very few of them, e.g. HAVE_PTHREAD and HAVE_ZLIB. Those macros are
+# passed down in CXXFLAGS manually in src/Makefile.am
+AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_MACRO_DIR([m4])
+
+AC_ARG_VAR(DIST_LANG, [language to include in the distribution package (i.e., make dist)])
+case "$DIST_LANG" in
+ "") DIST_LANG=all ;;
+ all | cpp | csharp | java | python | javanano | objectivec | ruby | js | php) ;;
+ *) AC_MSG_FAILURE([unknown language: $DIST_LANG]) ;;
+esac
+AC_SUBST(DIST_LANG)
+
+# autoconf's default CXXFLAGS are usually "-g -O2". These aren't necessarily
+# the best choice for libprotobuf.
+AS_IF([test "x${ac_cv_env_CFLAGS_set}" = "x"],
+ [CFLAGS=""])
+AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],
+ [CXXFLAGS=""])
+
+AC_CANONICAL_TARGET
+
+AM_INIT_AUTOMAKE([1.9 tar-ustar subdir-objects])
+
+AC_ARG_WITH([zlib],
+ [AS_HELP_STRING([--with-zlib],
+ [include classes for streaming compressed data in and out @<:@default=check@:>@])],
+ [],[with_zlib=check])
+
+AC_ARG_WITH([protoc],
+ [AS_HELP_STRING([--with-protoc=COMMAND],
+ [use the given protoc command instead of building a new one when building tests (useful for cross-compiling)])],
+ [],[with_protoc=no])
+
+# Checks for programs.
+AC_PROG_CC
+AC_PROG_CXX
+AC_PROG_CXX_FOR_BUILD
+AC_LANG([C++])
+ACX_USE_SYSTEM_EXTENSIONS
+m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
+AM_CONDITIONAL(GCC, test "$GCC" = yes) # let the Makefile know if we're gcc
+AC_PROG_OBJC
+
+# test_util.cc takes forever to compile with GCC and optimization turned on.
+AC_MSG_CHECKING([C++ compiler flags...])
+AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],[
+ AS_IF([test "$GCC" = "yes"],[
+ PROTOBUF_OPT_FLAG="-O2"
+ CXXFLAGS="${CXXFLAGS} -g"
+ ])
+
+ # Protocol Buffers contains several checks that are intended to be used only
+ # for debugging and which might hurt performance. Most users are probably
+ # end users who don't want these checks, so add -DNDEBUG by default.
+ CXXFLAGS="$CXXFLAGS -DNDEBUG"
+
+ AC_MSG_RESULT([use default: $PROTOBUF_OPT_FLAG $CXXFLAGS])
+],[
+ AC_MSG_RESULT([use user-supplied: $CXXFLAGS])
+])
+
+AC_SUBST(PROTOBUF_OPT_FLAG)
+
+ACX_CHECK_SUNCC
+
+# Have to do libtool after SUNCC, other wise it "helpfully" adds Crun Cstd
+# to the link
+AC_PROG_LIBTOOL
+
+# Check whether the linker supports version scripts
+AC_MSG_CHECKING([whether the linker supports version scripts])
+save_LDFLAGS=$LDFLAGS
+LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
+cat > conftest.map <<EOF
+{
+ global:
+ main;
+ local:
+ *;
+};
+EOF
+AC_LINK_IFELSE(
+ [AC_LANG_SOURCE([int main() { return 0; }])],
+ [have_ld_version_script=yes; AC_MSG_RESULT(yes)],
+ [have_ld_version_script=no; AC_MSG_RESULT(no)])
+LDFLAGS=$save_LDFLAGS
+AM_CONDITIONAL([HAVE_LD_VERSION_SCRIPT], [test "$have_ld_version_script" == "yes"])
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h stdlib.h unistd.h])
+
+# Checks for library functions.
+AC_FUNC_MEMCMP
+AC_FUNC_STRTOD
+AC_CHECK_FUNCS([ftruncate memset mkdir strchr strerror strtol])
+
+# Check for zlib.
+HAVE_ZLIB=0
+AS_IF([test "$with_zlib" != no], [
+ AC_MSG_CHECKING([zlib version])
+
+ # First check the zlib header version.
+ AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([[
+ #include <zlib.h>
+ #if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1204)
+ # error zlib version too old
+ #endif
+ ]], [])], [
+ AC_MSG_RESULT([ok (1.2.0.4 or later)])
+
+ # Also need to add -lz to the linker flags and make sure this succeeds.
+ AC_SEARCH_LIBS([zlibVersion], [z], [
+ AC_DEFINE([HAVE_ZLIB], [1], [Enable classes using zlib compression.])
+ HAVE_ZLIB=1
+ ], [
+ AS_IF([test "$with_zlib" != check], [
+ AC_MSG_FAILURE([--with-zlib was given, but no working zlib library was found])
+ ])
+ ])
+ ], [
+ AS_IF([test "$with_zlib" = check], [
+ AC_MSG_RESULT([headers missing or too old (requires 1.2.0.4)])
+ ], [
+ AC_MSG_FAILURE([--with-zlib was given, but zlib headers were not present or were too old (requires 1.2.0.4)])
+ ])
+ ])
+])
+AM_CONDITIONAL([HAVE_ZLIB], [test $HAVE_ZLIB = 1])
+
+AS_IF([test "$with_protoc" != "no"], [
+ PROTOC=$with_protoc
+ AS_IF([test "$with_protoc" = "yes"], [
+ # No argument given. Use system protoc.
+ PROTOC=protoc
+ ])
+ AS_IF([echo "$PROTOC" | grep -q '^@<:@^/@:>@.*/'], [
+ # Does not start with a slash, but contains a slash. So, it's a relative
+ # path (as opposed to an absolute path or an executable in $PATH).
+ # Since it will actually be executed from the src directory, prefix with
+ # the current directory. We also insert $ac_top_build_prefix in case this
+ # is a nested package and --with-protoc was actually given on the outer
+ # package's configure script.
+ PROTOC=`pwd`/${ac_top_build_prefix}$PROTOC
+ ])
+ AC_SUBST([PROTOC])
+])
+AM_CONDITIONAL([USE_EXTERNAL_PROTOC], [test "$with_protoc" != "no"])
+
+ACX_PTHREAD
+AM_CONDITIONAL([HAVE_PTHREAD], [test "x$acx_pthread_ok" = "xyes"])
+
+# We still keep this for improving pbconfig.h for unsupported platforms.
+AC_CXX_STL_HASH
+
+case "$target_os" in
+ mingw* | cygwin* | win*)
+ ;;
+ *)
+ # Need to link against rt on Solaris
+ AC_SEARCH_LIBS([sched_yield], [rt], [], [AC_MSG_FAILURE([sched_yield was not found on your system])])
+ ;;
+esac
+
+# Enable ObjC support for conformance directory on OS X.
+OBJC_CONFORMANCE_TEST=0
+case "$target_os" in
+ darwin*)
+ OBJC_CONFORMANCE_TEST=1
+ ;;
+esac
+AM_CONDITIONAL([OBJC_CONFORMANCE_TEST], [test $OBJC_CONFORMANCE_TEST = 1])
+
+AX_CXX_COMPILE_STDCXX([11], [noext], [optional])
+
+# HACK: Make gmock's configure script pick up our copy of CFLAGS and CXXFLAGS,
+# since the flags added by ACX_CHECK_SUNCC must be used when compiling gmock
+# too.
+export CFLAGS
+export CXXFLAGS
+AC_CONFIG_SUBDIRS([gmock])
+
+AC_CONFIG_FILES([Makefile src/Makefile benchmarks/Makefile conformance/Makefile protobuf.pc protobuf-lite.pc])
+AC_OUTPUT
diff --git a/third_party/protobuf/conformance/ConformanceJava.java b/third_party/protobuf/conformance/ConformanceJava.java
new file mode 100644
index 0000000000..7badf2a5f5
--- /dev/null
+++ b/third_party/protobuf/conformance/ConformanceJava.java
@@ -0,0 +1,315 @@
+import com.google.protobuf.ByteString;
+import com.google.protobuf.CodedInputStream;
+import com.google.protobuf.conformance.Conformance;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.google.protobuf_test_messages.proto3.TestMessagesProto3;
+import com.google.protobuf.util.JsonFormat;
+import com.google.protobuf.util.JsonFormat.TypeRegistry;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+class ConformanceJava {
+ private int testCount = 0;
+ private TypeRegistry typeRegistry;
+
+ private boolean readFromStdin(byte[] buf, int len) throws Exception {
+ int ofs = 0;
+ while (len > 0) {
+ int read = System.in.read(buf, ofs, len);
+ if (read == -1) {
+ return false; // EOF
+ }
+ ofs += read;
+ len -= read;
+ }
+
+ return true;
+ }
+
+ private void writeToStdout(byte[] buf) throws Exception {
+ System.out.write(buf);
+ }
+
+ // Returns -1 on EOF (the actual values will always be positive).
+ private int readLittleEndianIntFromStdin() throws Exception {
+ byte[] buf = new byte[4];
+ if (!readFromStdin(buf, 4)) {
+ return -1;
+ }
+ return (buf[0] & 0xff)
+ | ((buf[1] & 0xff) << 8)
+ | ((buf[2] & 0xff) << 16)
+ | ((buf[3] & 0xff) << 24);
+ }
+
+ private void writeLittleEndianIntToStdout(int val) throws Exception {
+ byte[] buf = new byte[4];
+ buf[0] = (byte)val;
+ buf[1] = (byte)(val >> 8);
+ buf[2] = (byte)(val >> 16);
+ buf[3] = (byte)(val >> 24);
+ writeToStdout(buf);
+ }
+
+ private enum BinaryDecoder {
+ BYTE_STRING_DECODER() {
+ @Override
+ public TestMessagesProto3.TestAllTypes parse(ByteString bytes)
+ throws InvalidProtocolBufferException {
+ return TestMessagesProto3.TestAllTypes.parseFrom(bytes);
+ }
+ },
+ BYTE_ARRAY_DECODER() {
+ @Override
+ public TestMessagesProto3.TestAllTypes parse(ByteString bytes)
+ throws InvalidProtocolBufferException {
+ return TestMessagesProto3.TestAllTypes.parseFrom(bytes.toByteArray());
+ }
+ },
+ ARRAY_BYTE_BUFFER_DECODER() {
+ @Override
+ public TestMessagesProto3.TestAllTypes parse(ByteString bytes)
+ throws InvalidProtocolBufferException {
+ ByteBuffer buffer = ByteBuffer.allocate(bytes.size());
+ bytes.copyTo(buffer);
+ buffer.flip();
+ try {
+ return TestMessagesProto3.TestAllTypes.parseFrom(CodedInputStream.newInstance(buffer));
+ } catch (InvalidProtocolBufferException e) {
+ throw e;
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "ByteString based ByteBuffer should not throw IOException.", e);
+ }
+ }
+ },
+ READONLY_ARRAY_BYTE_BUFFER_DECODER() {
+ @Override
+ public TestMessagesProto3.TestAllTypes parse(ByteString bytes)
+ throws InvalidProtocolBufferException {
+ try {
+ return TestMessagesProto3.TestAllTypes.parseFrom(
+ CodedInputStream.newInstance(bytes.asReadOnlyByteBuffer()));
+ } catch (InvalidProtocolBufferException e) {
+ throw e;
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "ByteString based ByteBuffer should not throw IOException.", e);
+ }
+ }
+ },
+ DIRECT_BYTE_BUFFER_DECODER() {
+ @Override
+ public TestMessagesProto3.TestAllTypes parse(ByteString bytes)
+ throws InvalidProtocolBufferException {
+ ByteBuffer buffer = ByteBuffer.allocateDirect(bytes.size());
+ bytes.copyTo(buffer);
+ buffer.flip();
+ try {
+ return TestMessagesProto3.TestAllTypes.parseFrom(CodedInputStream.newInstance(buffer));
+ } catch (InvalidProtocolBufferException e) {
+ throw e;
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "ByteString based ByteBuffer should not throw IOException.", e);
+ }
+ }
+ },
+ READONLY_DIRECT_BYTE_BUFFER_DECODER() {
+ @Override
+ public TestMessagesProto3.TestAllTypes parse(ByteString bytes)
+ throws InvalidProtocolBufferException {
+ ByteBuffer buffer = ByteBuffer.allocateDirect(bytes.size());
+ bytes.copyTo(buffer);
+ buffer.flip();
+ try {
+ return TestMessagesProto3.TestAllTypes.parseFrom(
+ CodedInputStream.newInstance(buffer.asReadOnlyBuffer()));
+ } catch (InvalidProtocolBufferException e) {
+ throw e;
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "ByteString based ByteBuffer should not throw IOException.", e);
+ }
+ }
+ },
+ INPUT_STREAM_DECODER() {
+ @Override
+ public TestMessagesProto3.TestAllTypes parse(ByteString bytes)
+ throws InvalidProtocolBufferException {
+ try {
+ return TestMessagesProto3.TestAllTypes.parseFrom(bytes.newInput());
+ } catch (InvalidProtocolBufferException e) {
+ throw e;
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "ByteString based InputStream should not throw IOException.", e);
+ }
+ }
+ };
+
+ public abstract TestMessagesProto3.TestAllTypes parse(ByteString bytes)
+ throws InvalidProtocolBufferException;
+ }
+
+ private TestMessagesProto3.TestAllTypes parseBinary(ByteString bytes)
+ throws InvalidProtocolBufferException {
+ TestMessagesProto3.TestAllTypes[] messages =
+ new TestMessagesProto3.TestAllTypes[BinaryDecoder.values().length];
+ InvalidProtocolBufferException[] exceptions =
+ new InvalidProtocolBufferException[BinaryDecoder.values().length];
+
+ boolean hasMessage = false;
+ boolean hasException = false;
+ for (int i = 0; i < BinaryDecoder.values().length; ++i) {
+ try {
+ messages[i] = BinaryDecoder.values()[i].parse(bytes);
+ hasMessage = true;
+ } catch (InvalidProtocolBufferException e) {
+ exceptions[i] = e;
+ hasException = true;
+ }
+ }
+
+ if (hasMessage && hasException) {
+ StringBuilder sb =
+ new StringBuilder("Binary decoders disagreed on whether the payload was valid.\n");
+ for (int i = 0; i < BinaryDecoder.values().length; ++i) {
+ sb.append(BinaryDecoder.values()[i].name());
+ if (messages[i] != null) {
+ sb.append(" accepted the payload.\n");
+ } else {
+ sb.append(" rejected the payload.\n");
+ }
+ }
+ throw new RuntimeException(sb.toString());
+ }
+
+ if (hasException) {
+ // We do not check if exceptions are equal. Different implementations may return different
+ // exception messages. Throw an arbitrary one out instead.
+ throw exceptions[0];
+ }
+
+ // Fast path comparing all the messages with the first message, assuming equality being
+ // symmetric and transitive.
+ boolean allEqual = true;
+ for (int i = 1; i < messages.length; ++i) {
+ if (!messages[0].equals(messages[i])) {
+ allEqual = false;
+ break;
+ }
+ }
+
+ // Slow path: compare and find out all unequal pairs.
+ if (!allEqual) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < messages.length - 1; ++i) {
+ for (int j = i + 1; j < messages.length; ++j) {
+ if (!messages[i].equals(messages[j])) {
+ sb.append(BinaryDecoder.values()[i].name())
+ .append(" and ")
+ .append(BinaryDecoder.values()[j].name())
+ .append(" parsed the payload differently.\n");
+ }
+ }
+ }
+ throw new RuntimeException(sb.toString());
+ }
+
+ return messages[0];
+ }
+
+ private Conformance.ConformanceResponse doTest(Conformance.ConformanceRequest request) {
+ TestMessagesProto3.TestAllTypes testMessage;
+
+ switch (request.getPayloadCase()) {
+ case PROTOBUF_PAYLOAD: {
+ try {
+ testMessage = parseBinary(request.getProtobufPayload());
+ } catch (InvalidProtocolBufferException e) {
+ return Conformance.ConformanceResponse.newBuilder().setParseError(e.getMessage()).build();
+ }
+ break;
+ }
+ case JSON_PAYLOAD: {
+ try {
+ TestMessagesProto3.TestAllTypes.Builder builder = TestMessagesProto3.TestAllTypes.newBuilder();
+ JsonFormat.parser().usingTypeRegistry(typeRegistry)
+ .merge(request.getJsonPayload(), builder);
+ testMessage = builder.build();
+ } catch (InvalidProtocolBufferException e) {
+ return Conformance.ConformanceResponse.newBuilder().setParseError(e.getMessage()).build();
+ }
+ break;
+ }
+ case PAYLOAD_NOT_SET: {
+ throw new RuntimeException("Request didn't have payload.");
+ }
+
+ default: {
+ throw new RuntimeException("Unexpected payload case.");
+ }
+ }
+
+ switch (request.getRequestedOutputFormat()) {
+ case UNSPECIFIED:
+ throw new RuntimeException("Unspecified output format.");
+
+ case PROTOBUF:
+ return Conformance.ConformanceResponse.newBuilder().setProtobufPayload(testMessage.toByteString()).build();
+
+ case JSON:
+ try {
+ return Conformance.ConformanceResponse.newBuilder().setJsonPayload(
+ JsonFormat.printer().usingTypeRegistry(typeRegistry).print(testMessage)).build();
+ } catch (InvalidProtocolBufferException | IllegalArgumentException e) {
+ return Conformance.ConformanceResponse.newBuilder().setSerializeError(
+ e.getMessage()).build();
+ }
+
+ default: {
+ throw new RuntimeException("Unexpected request output.");
+ }
+ }
+ }
+
+ private boolean doTestIo() throws Exception {
+ int bytes = readLittleEndianIntFromStdin();
+
+ if (bytes == -1) {
+ return false; // EOF
+ }
+
+ byte[] serializedInput = new byte[bytes];
+
+ if (!readFromStdin(serializedInput, bytes)) {
+ throw new RuntimeException("Unexpected EOF from test program.");
+ }
+
+ Conformance.ConformanceRequest request =
+ Conformance.ConformanceRequest.parseFrom(serializedInput);
+ Conformance.ConformanceResponse response = doTest(request);
+ byte[] serializedOutput = response.toByteArray();
+
+ writeLittleEndianIntToStdout(serializedOutput.length);
+ writeToStdout(serializedOutput);
+
+ return true;
+ }
+
+ public void run() throws Exception {
+ typeRegistry = TypeRegistry.newBuilder().add(
+ TestMessagesProto3.TestAllTypes.getDescriptor()).build();
+ while (doTestIo()) {
+ this.testCount++;
+ }
+
+ System.err.println("ConformanceJava: received EOF from test runner after " +
+ this.testCount + " tests");
+ }
+
+ public static void main(String[] args) throws Exception {
+ new ConformanceJava().run();
+ }
+}
diff --git a/third_party/protobuf/conformance/ConformanceJavaLite.java b/third_party/protobuf/conformance/ConformanceJavaLite.java
new file mode 100644
index 0000000000..016f79326f
--- /dev/null
+++ b/third_party/protobuf/conformance/ConformanceJavaLite.java
@@ -0,0 +1,125 @@
+
+import com.google.protobuf.conformance.Conformance;
+import com.google.protobuf.InvalidProtocolBufferException;
+
+class ConformanceJavaLite {
+ private int testCount = 0;
+
+ private boolean readFromStdin(byte[] buf, int len) throws Exception {
+ int ofs = 0;
+ while (len > 0) {
+ int read = System.in.read(buf, ofs, len);
+ if (read == -1) {
+ return false; // EOF
+ }
+ ofs += read;
+ len -= read;
+ }
+
+ return true;
+ }
+
+ private void writeToStdout(byte[] buf) throws Exception {
+ System.out.write(buf);
+ }
+
+ // Returns -1 on EOF (the actual values will always be positive).
+ private int readLittleEndianIntFromStdin() throws Exception {
+ byte[] buf = new byte[4];
+ if (!readFromStdin(buf, 4)) {
+ return -1;
+ }
+ return (buf[0] & 0xff)
+ | ((buf[1] & 0xff) << 8)
+ | ((buf[2] & 0xff) << 16)
+ | ((buf[3] & 0xff) << 24);
+ }
+
+ private void writeLittleEndianIntToStdout(int val) throws Exception {
+ byte[] buf = new byte[4];
+ buf[0] = (byte)val;
+ buf[1] = (byte)(val >> 8);
+ buf[2] = (byte)(val >> 16);
+ buf[3] = (byte)(val >> 24);
+ writeToStdout(buf);
+ }
+
+ private Conformance.ConformanceResponse doTest(Conformance.ConformanceRequest request) {
+ Conformance.TestAllTypes testMessage;
+
+ switch (request.getPayloadCase()) {
+ case PROTOBUF_PAYLOAD: {
+ try {
+ testMessage = Conformance.TestAllTypes.parseFrom(request.getProtobufPayload());
+ } catch (InvalidProtocolBufferException e) {
+ return Conformance.ConformanceResponse.newBuilder().setParseError(e.getMessage()).build();
+ }
+ break;
+ }
+ case JSON_PAYLOAD: {
+ return Conformance.ConformanceResponse.newBuilder().setSkipped(
+ "Lite runtime does not support JSON format.").build();
+ }
+ case PAYLOAD_NOT_SET: {
+ throw new RuntimeException("Request didn't have payload.");
+ }
+
+ default: {
+ throw new RuntimeException("Unexpected payload case.");
+ }
+ }
+
+ switch (request.getRequestedOutputFormat()) {
+ case UNSPECIFIED:
+ throw new RuntimeException("Unspecified output format.");
+
+ case PROTOBUF:
+ return Conformance.ConformanceResponse.newBuilder().setProtobufPayload(testMessage.toByteString()).build();
+
+ case JSON:
+ return Conformance.ConformanceResponse.newBuilder().setSkipped(
+ "Lite runtime does not support JSON format.").build();
+
+ default: {
+ throw new RuntimeException("Unexpected request output.");
+ }
+ }
+ }
+
+ private boolean doTestIo() throws Exception {
+ int bytes = readLittleEndianIntFromStdin();
+
+ if (bytes == -1) {
+ return false; // EOF
+ }
+
+ byte[] serializedInput = new byte[bytes];
+
+ if (!readFromStdin(serializedInput, bytes)) {
+ throw new RuntimeException("Unexpected EOF from test program.");
+ }
+
+ Conformance.ConformanceRequest request =
+ Conformance.ConformanceRequest.parseFrom(serializedInput);
+ Conformance.ConformanceResponse response = doTest(request);
+ byte[] serializedOutput = response.toByteArray();
+
+ writeLittleEndianIntToStdout(serializedOutput.length);
+ writeToStdout(serializedOutput);
+
+ return true;
+ }
+
+ public void run() throws Exception {
+ while (doTestIo()) {
+ this.testCount++;
+ }
+
+ System.err.println("ConformanceJavaLite: received EOF from test runner after " +
+ this.testCount + " tests");
+ }
+
+ public static void main(String[] args) throws Exception {
+ new ConformanceJavaLite().run();
+ }
+}
diff --git a/third_party/protobuf/conformance/Makefile.am b/third_party/protobuf/conformance/Makefile.am
new file mode 100644
index 0000000000..1a8b57485b
--- /dev/null
+++ b/third_party/protobuf/conformance/Makefile.am
@@ -0,0 +1,355 @@
+## Process this file with automake to produce Makefile.in
+
+conformance_protoc_inputs = \
+ conformance.proto \
+ $(top_srcdir)/src/google/protobuf/test_messages_proto3.proto
+
+well_known_type_protoc_inputs = \
+ $(top_srcdir)/src/google/protobuf/any.proto \
+ $(top_srcdir)/src/google/protobuf/duration.proto \
+ $(top_srcdir)/src/google/protobuf/field_mask.proto \
+ $(top_srcdir)/src/google/protobuf/struct.proto \
+ $(top_srcdir)/src/google/protobuf/timestamp.proto \
+ $(top_srcdir)/src/google/protobuf/wrappers.proto
+
+
+protoc_outputs = \
+ conformance.pb.cc \
+ conformance.pb.h
+
+other_language_protoc_outputs = \
+ conformance_pb2.py \
+ Conformance.pbobjc.h \
+ Conformance.pbobjc.m \
+ conformance_pb.js \
+ conformance_pb.rb \
+ com/google/protobuf/Any.java \
+ com/google/protobuf/AnyOrBuilder.java \
+ com/google/protobuf/AnyProto.java \
+ com/google/protobuf/BoolValue.java \
+ com/google/protobuf/BoolValueOrBuilder.java \
+ com/google/protobuf/BytesValue.java \
+ com/google/protobuf/BytesValueOrBuilder.java \
+ com/google/protobuf/conformance/Conformance.java \
+ com/google/protobuf/DoubleValue.java \
+ com/google/protobuf/DoubleValueOrBuilder.java \
+ com/google/protobuf/Duration.java \
+ com/google/protobuf/DurationOrBuilder.java \
+ com/google/protobuf/DurationProto.java \
+ com/google/protobuf/FieldMask.java \
+ com/google/protobuf/FieldMaskOrBuilder.java \
+ com/google/protobuf/FieldMaskProto.java \
+ com/google/protobuf/FloatValue.java \
+ com/google/protobuf/FloatValueOrBuilder.java \
+ com/google/protobuf/Int32Value.java \
+ com/google/protobuf/Int32ValueOrBuilder.java \
+ com/google/protobuf/Int64Value.java \
+ com/google/protobuf/Int64ValueOrBuilder.java \
+ com/google/protobuf/ListValue.java \
+ com/google/protobuf/ListValueOrBuilder.java \
+ com/google/protobuf/NullValue.java \
+ com/google/protobuf/StringValue.java \
+ com/google/protobuf/StringValueOrBuilder.java \
+ com/google/protobuf/Struct.java \
+ com/google/protobuf/StructOrBuilder.java \
+ com/google/protobuf/StructProto.java \
+ com/google/protobuf/Timestamp.java \
+ com/google/protobuf/TimestampOrBuilder.java \
+ com/google/protobuf/TimestampProto.java \
+ com/google/protobuf/UInt32Value.java \
+ com/google/protobuf/UInt32ValueOrBuilder.java \
+ com/google/protobuf/UInt64Value.java \
+ com/google/protobuf/UInt64ValueOrBuilder.java \
+ com/google/protobuf/Value.java \
+ com/google/protobuf/ValueOrBuilder.java \
+ com/google/protobuf/WrappersProto.java \
+ com/google/protobuf_test_messages/proto3/TestMessagesProto3.java \
+ google/protobuf/any.pb.cc \
+ google/protobuf/any.pb.h \
+ google/protobuf/any.rb \
+ google/protobuf/any_pb2.py \
+ google/protobuf/duration.pb.cc \
+ google/protobuf/duration.pb.h \
+ google/protobuf/duration.rb \
+ google/protobuf/duration_pb2.py \
+ google/protobuf/field_mask.pb.cc \
+ google/protobuf/field_mask.pb.h \
+ google/protobuf/field_mask.rb \
+ google/protobuf/field_mask_pb2.py \
+ google/protobuf/struct.pb.cc \
+ google/protobuf/struct.pb.h \
+ google/protobuf/struct.rb \
+ google/protobuf/struct_pb2.py \
+ google/protobuf/TestMessagesProto3.pbobjc.h \
+ google/protobuf/TestMessagesProto3.pbobjc.m \
+ google/protobuf/test_messages_proto3.pb.cc \
+ google/protobuf/test_messages_proto3.pb.h \
+ google/protobuf/test_messages_proto3_pb.rb \
+ google/protobuf/test_messages_proto3_pb2.py \
+ google/protobuf/timestamp.pb.cc \
+ google/protobuf/timestamp.pb.h \
+ google/protobuf/timestamp.rb \
+ google/protobuf/timestamp_pb2.py \
+ google/protobuf/wrappers.pb.cc \
+ google/protobuf/wrappers.pb.h \
+ google/protobuf/wrappers.rb \
+ google/protobuf/wrappers_pb2.py \
+ Conformance/ConformanceRequest.php \
+ Conformance/ConformanceResponse.php \
+ Conformance/WireFormat.php \
+ GPBMetadata/Conformance.php \
+ GPBMetadata/Google/Protobuf/Any.php \
+ GPBMetadata/Google/Protobuf/Duration.php \
+ GPBMetadata/Google/Protobuf/FieldMask.php \
+ GPBMetadata/Google/Protobuf/Struct.php \
+ GPBMetadata/Google/Protobuf/TestMessagesProto3.php \
+ GPBMetadata/Google/Protobuf/Timestamp.php \
+ GPBMetadata/Google/Protobuf/Wrappers.php \
+ Google/Protobuf/Any.php \
+ Google/Protobuf/BoolValue.php \
+ Google/Protobuf/BytesValue.php \
+ Google/Protobuf/DoubleValue.php \
+ Google/Protobuf/Duration.php \
+ Google/Protobuf/FieldMask.php \
+ Google/Protobuf/FloatValue.php \
+ Google/Protobuf/Int32Value.php \
+ Google/Protobuf/Int64Value.php \
+ Google/Protobuf/ListValue.php \
+ Google/Protobuf/NullValue.php \
+ Google/Protobuf/StringValue.php \
+ Google/Protobuf/Struct.php \
+ Google/Protobuf/Timestamp.php \
+ Google/Protobuf/UInt32Value.php \
+ Google/Protobuf/UInt64Value.php \
+ Google/Protobuf/Value.php \
+ Protobuf_test_messages/Proto3/ForeignEnum.php \
+ Protobuf_test_messages/Proto3/ForeignMessage.php \
+ Protobuf_test_messages/Proto3/TestAllTypes_NestedEnum.php \
+ Protobuf_test_messages/Proto3/TestAllTypes_NestedMessage.php \
+ Protobuf_test_messages/Proto3/TestAllTypes.php
+ # lite/com/google/protobuf/Any.java \
+ # lite/com/google/protobuf/AnyOrBuilder.java \
+ # lite/com/google/protobuf/AnyProto.java \
+ # lite/com/google/protobuf/BoolValue.java \
+ # lite/com/google/protobuf/BoolValueOrBuilder.java \
+ # lite/com/google/protobuf/BytesValue.java \
+ # lite/com/google/protobuf/BytesValueOrBuilder.java \
+ # lite/com/google/protobuf/conformance/Conformance.java \
+ # lite/com/google/protobuf/DoubleValue.java \
+ # lite/com/google/protobuf/DoubleValueOrBuilder.java \
+ # lite/com/google/protobuf/Duration.java \
+ # lite/com/google/protobuf/DurationOrBuilder.java \
+ # lite/com/google/protobuf/DurationProto.java \
+ # lite/com/google/protobuf/FieldMask.java \
+ # lite/com/google/protobuf/FieldMaskOrBuilder.java \
+ # lite/com/google/protobuf/FieldMaskProto.java \
+ # lite/com/google/protobuf/FloatValue.java \
+ # lite/com/google/protobuf/FloatValueOrBuilder.java \
+ # lite/com/google/protobuf/Int32Value.java \
+ # lite/com/google/protobuf/Int32ValueOrBuilder.java \
+ # lite/com/google/protobuf/Int64Value.java \
+ # lite/com/google/protobuf/Int64ValueOrBuilder.java \
+ # lite/com/google/protobuf/ListValue.java \
+ # lite/com/google/protobuf/ListValueOrBuilder.java \
+ # lite/com/google/protobuf/NullValue.java \
+ # lite/com/google/protobuf/StringValue.java \
+ # lite/com/google/protobuf/StringValueOrBuilder.java \
+ # lite/com/google/protobuf/Struct.java \
+ # lite/com/google/protobuf/StructOrBuilder.java \
+ # lite/com/google/protobuf/StructProto.java \
+ # lite/com/google/protobuf/Timestamp.java \
+ # lite/com/google/protobuf/TimestampOrBuilder.java \
+ # lite/com/google/protobuf/TimestampProto.java \
+ # lite/com/google/protobuf/UInt32Value.java \
+ # lite/com/google/protobuf/UInt32ValueOrBuilder.java \
+ # lite/com/google/protobuf/UInt64Value.java \
+ # lite/com/google/protobuf/UInt64ValueOrBuilder.java \
+ # lite/com/google/protobuf/Value.java \
+ # lite/com/google/protobuf/ValueOrBuilder.java \
+ # lite/com/google/protobuf/WrappersProto.java
+
+bin_PROGRAMS = conformance-test-runner conformance-cpp
+
+# All source files excepet C++/Objective-C ones should be explicitly listed
+# here because the autoconf tools don't include files of other languages
+# automatically.
+EXTRA_DIST = \
+ ConformanceJava.java \
+ ConformanceJavaLite.java \
+ README.md \
+ conformance.proto \
+ conformance_python.py \
+ conformance_ruby.rb \
+ conformance_php.php \
+ failure_list_cpp.txt \
+ failure_list_csharp.txt \
+ failure_list_java.txt \
+ failure_list_js.txt \
+ failure_list_objc.txt \
+ failure_list_python.txt \
+ failure_list_python_cpp.txt \
+ failure_list_python-post26.txt \
+ failure_list_ruby.txt \
+ failure_list_php.txt \
+ failure_list_php_c.txt
+
+conformance_test_runner_LDADD = $(top_srcdir)/src/libprotobuf.la
+conformance_test_runner_SOURCES = conformance_test.h conformance_test.cc \
+ conformance_test_runner.cc \
+ third_party/jsoncpp/json.h \
+ third_party/jsoncpp/jsoncpp.cpp
+nodist_conformance_test_runner_SOURCES = conformance.pb.cc google/protobuf/test_messages_proto3.pb.cc
+conformance_test_runner_CPPFLAGS = -I$(top_srcdir)/src -I$(srcdir)
+conformance_test_runner_CXXFLAGS = -std=c++11
+# Explicit deps beacuse BUILT_SOURCES are only done before a "make all/check"
+# so a direct "make test_cpp" could fail if parallel enough.
+conformance_test_runner-conformance_test.$(OBJEXT): conformance.pb.h
+conformance_test_runner-conformance_test_runner.$(OBJEXT): conformance.pb.h
+
+conformance_cpp_LDADD = $(top_srcdir)/src/libprotobuf.la
+conformance_cpp_SOURCES = conformance_cpp.cc
+nodist_conformance_cpp_SOURCES = conformance.pb.cc google/protobuf/test_messages_proto3.pb.cc
+conformance_cpp_CPPFLAGS = -I$(top_srcdir)/src
+# Explicit dep beacuse BUILT_SOURCES are only done before a "make all/check"
+# so a direct "make test_cpp" could fail if parallel enough.
+conformance_cpp-conformance_cpp.$(OBJEXT): conformance.pb.h
+
+if OBJC_CONFORMANCE_TEST
+
+bin_PROGRAMS += conformance-objc
+
+conformance_objc_SOURCES = conformance_objc.m ../objectivec/GPBProtocolBuffers.m
+nodist_conformance_objc_SOURCES = Conformance.pbobjc.m google/protobuf/TestMessagesProto3.pbobjc.m
+# On travis, the build fails without the isysroot because whatever system
+# headers are being found don't include generics support for
+# NSArray/NSDictionary, the only guess is their image at one time had an odd
+# setup for Xcode and old frameworks are being found.
+conformance_objc_CPPFLAGS = -I$(top_srcdir)/objectivec -isysroot `xcrun --sdk macosx --show-sdk-path`
+conformance_objc_LDFLAGS = -framework Foundation
+# Explicit dep beacuse BUILT_SOURCES are only done before a "make all/check"
+# so a direct "make test_objc" could fail if parallel enough.
+conformance_objc-conformance_objc.$(OBJEXT): Conformance.pbobjc.h google/protobuf/TestMessagesProto3.pbobjc.h
+
+endif
+
+# JavaScript well-known types are expected to be in a directory called
+# google-protobuf, because they are usually in the google-protobuf npm
+# package. But we want to use the sources from our tree, so we recreate
+# that directory structure here.
+google-protobuf:
+ mkdir google-protobuf
+
+if USE_EXTERNAL_PROTOC
+
+# Some implementations include pre-generated versions of well-known types.
+protoc_middleman: $(conformance_protoc_inputs) $(well_known_type_protoc_inputs) google-protobuf
+ $(PROTOC) -I$(srcdir) -I$(top_srcdir) --cpp_out=. --java_out=. --ruby_out=. --objc_out=. --python_out=. --php_out=. --js_out=import_style=commonjs,binary:. $(conformance_protoc_inputs)
+ $(PROTOC) -I$(srcdir) -I$(top_srcdir) --cpp_out=. --java_out=. --ruby_out=. --python_out=. --php_out=. --js_out=import_style=commonjs,binary:google-protobuf $(well_known_type_protoc_inputs)
+ ## $(PROTOC) -I$(srcdir) -I$(top_srcdir) --java_out=lite:lite $(conformance_protoc_inputs) $(well_known_type_protoc_inputs)
+ touch protoc_middleman
+
+else
+
+# We have to cd to $(srcdir) before executing protoc because $(protoc_inputs) is
+# relative to srcdir, which may not be the same as the current directory when
+# building out-of-tree.
+protoc_middleman: $(top_srcdir)/src/protoc$(EXEEXT) $(conformance_protoc_inputs) $(well_known_type_protoc_inputs) google-protobuf
+ oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --cpp_out=$$oldpwd --java_out=$$oldpwd --ruby_out=$$oldpwd --objc_out=$$oldpwd --python_out=$$oldpwd --php_out=$$oldpwd --js_out=import_style=commonjs,binary:$$oldpwd $(conformance_protoc_inputs) )
+ oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --cpp_out=$$oldpwd --java_out=$$oldpwd --ruby_out=$$oldpwd --python_out=$$oldpwd --php_out=$$oldpwd --js_out=import_style=commonjs,binary:$$oldpwd/google-protobuf $(well_known_type_protoc_inputs) )
+ ## @mkdir -p lite
+ ## oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. -I$(top_srcdir)/src --java_out=lite:$$oldpwd/lite $(conformance_protoc_inputs) $(well_known_type_protoc_inputs) )
+ touch protoc_middleman
+
+endif
+
+$(protoc_outputs): protoc_middleman
+
+$(other_language_protoc_outputs): protoc_middleman
+
+BUILT_SOURCES = $(protoc_outputs) $(other_language_protoc_outputs)
+
+CLEANFILES = $(protoc_outputs) protoc_middleman javac_middleman conformance-java javac_middleman_lite conformance-java-lite conformance-csharp conformance-php conformance-php-c $(other_language_protoc_outputs)
+
+MAINTAINERCLEANFILES = \
+ Makefile.in
+
+javac_middleman: ConformanceJava.java protoc_middleman $(other_language_protoc_outputs)
+ jar=`ls ../java/util/target/*jar-with-dependencies.jar` && javac -classpath ../java/target/classes:$$jar ConformanceJava.java com/google/protobuf/conformance/Conformance.java com/google/protobuf_test_messages/proto3/TestMessagesProto3.java
+ @touch javac_middleman
+
+conformance-java: javac_middleman
+ @echo "Writing shortcut script conformance-java..."
+ @echo '#! /bin/sh' > conformance-java
+ @jar=`ls ../java/util/target/*jar-with-dependencies.jar` && echo java -classpath .:../java/target/classes:$$jar ConformanceJava '$$@' >> conformance-java
+ @chmod +x conformance-java
+
+javac_middleman_lite: ConformanceJavaLite.java protoc_middleman $(other_language_protoc_outputs)
+ javac -classpath ../java/lite/target/classes:lite ConformanceJavaLite.java lite/com/google/protobuf/conformance/Conformance.java
+ @touch javac_middleman_lite
+
+conformance-java-lite: javac_middleman_lite
+ @echo "Writing shortcut script conformance-java-lite..."
+ @echo '#! /bin/sh' > conformance-java-lite
+ @echo java -classpath .:../java/lite/target/classes:lite ConformanceJavaLite '$$@' >> conformance-java-lite
+ @chmod +x conformance-java-lite
+
+# Currently the conformance code is alongside the rest of the C#
+# source, as it's easier to maintain there. We assume we've already
+# built that, so we just need a script to run it.
+conformance-csharp: $(other_language_protoc_outputs)
+ @echo "Writing shortcut script conformance-csharp..."
+ @echo '#! /bin/sh' > conformance-csharp
+ @echo 'dotnet ../csharp/src/Google.Protobuf.Conformance/bin/Release/netcoreapp1.0/Google.Protobuf.Conformance.dll "$$@"' >> conformance-csharp
+ @chmod +x conformance-csharp
+
+conformance-php:
+ @echo "Writing shortcut script conformance-php..."
+ @echo '#! /bin/sh' > conformance-php
+ @echo 'php ./conformance_php.php' >> conformance-php
+ @chmod +x conformance-php
+
+conformance-php-c:
+ @echo "Writing shortcut script conformance-php-c..."
+ @echo '#! /bin/sh' > conformance-php-c
+ @echo 'php -dextension=../php/ext/google/protobuf/modules/protobuf.so ./conformance_php.php' >> conformance-php-c
+ @chmod +x conformance-php-c
+
+# Targets for actually running tests.
+test_cpp: protoc_middleman conformance-test-runner 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 --enforce_recommended --failure_list failure_list_java.txt ./conformance-java
+
+test_java_lite: protoc_middleman 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 --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 --enforce_recommended --failure_list failure_list_ruby.txt ./conformance_ruby.rb
+
+test_php: protoc_middleman conformance-test-runner conformance-php $(other_language_protoc_outputs)
+ ./conformance-test-runner --enforce_recommended --failure_list failure_list_php.txt ./conformance-php
+
+test_php_c: protoc_middleman conformance-test-runner conformance-php-c $(other_language_protoc_outputs)
+ ./conformance-test-runner --enforce_recommended --failure_list failure_list_php_c.txt ./conformance-php-c
+
+# 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 --enforce_recommended --failure_list failure_list_python.txt ./conformance_python.py
+
+test_python_cpp: protoc_middleman conformance-test-runner
+ ./conformance-test-runner --enforce_recommended --failure_list failure_list_python_cpp.txt ./conformance_python.py
+
+test_nodejs: protoc_middleman conformance-test-runner $(other_language_protoc_outputs)
+ NODE_PATH=../js:. ./conformance-test-runner --enforce_recommended --failure_list failure_list_js.txt ./conformance_nodejs.js
+
+if OBJC_CONFORMANCE_TEST
+
+test_objc: protoc_middleman conformance-test-runner conformance-objc
+ ./conformance-test-runner --enforce_recommended --failure_list failure_list_objc.txt ./conformance-objc
+
+endif
diff --git a/third_party/protobuf/conformance/README.md b/third_party/protobuf/conformance/README.md
new file mode 100644
index 0000000000..971fe8f60d
--- /dev/null
+++ b/third_party/protobuf/conformance/README.md
@@ -0,0 +1,73 @@
+Protocol Buffers - Google's data interchange format
+===================================================
+
+[![Build Status](https://travis-ci.org/google/protobuf.svg?branch=master)](https://travis-ci.org/google/protobuf)
+
+Copyright 2008 Google Inc.
+
+This directory contains conformance tests for testing completeness and
+correctness of Protocol Buffers implementations. These tests are designed
+to be easy to run against any Protocol Buffers implementation.
+
+This directory contains the tester process `conformance-test`, which
+contains all of the tests themselves. Then separate programs written
+in whatever language you want to test communicate with the tester
+program over a pipe.
+
+Before running any of these tests, make sure you run `make` in the base
+directory to build `protoc`, since all the tests depend on it.
+
+ $ make
+
+Running the tests for C++
+-------------------------
+
+To run the tests against the C++ implementation, run:
+
+ $ cd conformance && make test_cpp
+
+Running the tests for JavaScript (Node.js)
+------------------------------------------
+
+To run the JavaScript tests against Node.js, make sure you have "node"
+on your path and then run:
+
+ $ cd conformance && make test_nodejs
+
+Running the tests for Ruby (MRI)
+--------------------------------
+
+To run the Ruby tests against MRI, first build the C extension:
+
+ $ cd ruby && rake
+
+Then run the tests like so:
+
+ $ cd conformance && make test_ruby
+
+Running the tests for other languages
+-------------------------------------
+
+Most of the languages in the Protobuf source tree are set up to run
+conformance tests. However some of them are more tricky to set up
+properly. See `tests.sh` in the base of the repository to see how
+Travis runs the tests.
+
+Testing other Protocol Buffer implementations
+---------------------------------------------
+
+To run these tests against a new Protocol Buffers implementation, write a
+program in your language that uses the protobuf implementation you want
+to test. This program should implement the testing protocol defined in
+[conformance.proto](https://github.com/google/protobuf/blob/master/conformance/conformance.proto).
+This is designed to be as easy as possible: the C++ version is only
+150 lines and is a good example for what this program should look like
+(see [conformance_cpp.cc](https://github.com/google/protobuf/blob/master/conformance/conformance_cpp.cc)).
+The program only needs to be able to read from stdin and write to stdout.
+
+Portability
+-----------
+
+Note that the test runner currently does not work on Windows. Patches
+to fix this are welcome! (But please get in touch first to settle on
+a general implementation strategy).
diff --git a/third_party/protobuf/conformance/conformance.proto b/third_party/protobuf/conformance/conformance.proto
new file mode 100644
index 0000000000..18e4b7bca6
--- /dev/null
+++ b/third_party/protobuf/conformance/conformance.proto
@@ -0,0 +1,114 @@
+// 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.
+
+syntax = "proto3";
+package conformance;
+option java_package = "com.google.protobuf.conformance";
+
+// This defines the conformance testing protocol. This protocol exists between
+// the conformance test suite itself and the code being tested. For each test,
+// the suite will send a ConformanceRequest message and expect a
+// ConformanceResponse message.
+//
+// You can either run the tests in two different ways:
+//
+// 1. in-process (using the interface in conformance_test.h).
+//
+// 2. as a sub-process communicating over a pipe. Information about how to
+// do this is in conformance_test_runner.cc.
+//
+// Pros/cons of the two approaches:
+//
+// - running as a sub-process is much simpler for languages other than C/C++.
+//
+// - running as a sub-process may be more tricky in unusual environments like
+// iOS apps, where fork/stdin/stdout are not available.
+
+enum WireFormat {
+ UNSPECIFIED = 0;
+ PROTOBUF = 1;
+ JSON = 2;
+}
+
+// Represents a single test case's input. The testee should:
+//
+// 1. parse this proto (which should always succeed)
+// 2. parse the protobuf or JSON payload in "payload" (which may fail)
+// 3. if the parse succeeded, serialize the message in the requested format.
+message ConformanceRequest {
+ // The payload (whether protobuf of JSON) is always for a
+ // protobuf_test_messages.proto3.TestAllTypes proto (as defined in
+ // src/google/protobuf/proto3_test_messages.proto).
+ //
+ // TODO(haberman): if/when we expand the conformance tests to support proto2,
+ // we will want to include a field that lets the payload/response be a
+ // protobuf_test_messages.proto2.TestAllTypes message instead.
+ oneof payload {
+ bytes protobuf_payload = 1;
+ string json_payload = 2;
+ }
+
+ // Which format should the testee serialize its message to?
+ WireFormat requested_output_format = 3;
+}
+
+// Represents a single test case's output.
+message ConformanceResponse {
+ oneof result {
+ // This string should be set to indicate parsing failed. The string can
+ // provide more information about the parse error if it is available.
+ //
+ // Setting this string does not necessarily mean the testee failed the
+ // test. Some of the test cases are intentionally invalid input.
+ string parse_error = 1;
+
+ // If the input was successfully parsed but errors occurred when
+ // serializing it to the requested output format, set the error message in
+ // this field.
+ string serialize_error = 6;
+
+ // This should be set if some other error occurred. This will always
+ // indicate that the test failed. The string can provide more information
+ // about the failure.
+ string runtime_error = 2;
+
+ // If the input was successfully parsed and the requested output was
+ // protobuf, serialize it to protobuf and set it in this field.
+ bytes protobuf_payload = 3;
+
+ // If the input was successfully parsed and the requested output was JSON,
+ // serialize to JSON and set it in this field.
+ string json_payload = 4;
+
+ // For when the testee skipped the test, likely because a certain feature
+ // wasn't supported, like JSON input/output.
+ string skipped = 5;
+ }
+}
diff --git a/third_party/protobuf/conformance/conformance_cpp.cc b/third_party/protobuf/conformance/conformance_cpp.cc
new file mode 100644
index 0000000000..b865cd93ed
--- /dev/null
+++ b/third_party/protobuf/conformance/conformance_cpp.cc
@@ -0,0 +1,208 @@
+// 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 <errno.h>
+#include <stdarg.h>
+#include <unistd.h>
+
+#include "conformance.pb.h"
+#include <google/protobuf/test_messages_proto3.pb.h>
+#include <google/protobuf/util/json_util.h>
+#include <google/protobuf/util/type_resolver_util.h>
+
+using conformance::ConformanceRequest;
+using conformance::ConformanceResponse;
+using google::protobuf::Descriptor;
+using google::protobuf::DescriptorPool;
+using google::protobuf::internal::scoped_ptr;
+using google::protobuf::util::BinaryToJsonString;
+using google::protobuf::util::JsonToBinaryString;
+using google::protobuf::util::NewTypeResolverForDescriptorPool;
+using google::protobuf::util::Status;
+using google::protobuf::util::TypeResolver;
+using protobuf_test_messages::proto3::TestAllTypes;
+using std::string;
+
+static const char kTypeUrlPrefix[] = "type.googleapis.com";
+
+static string GetTypeUrl(const Descriptor* message) {
+ return string(kTypeUrlPrefix) + "/" + message->full_name();
+}
+
+int test_count = 0;
+bool verbose = false;
+TypeResolver* type_resolver;
+string* type_url;
+
+
+bool CheckedRead(int fd, void *buf, size_t len) {
+ size_t ofs = 0;
+ while (len > 0) {
+ ssize_t bytes_read = read(fd, (char*)buf + ofs, len);
+
+ if (bytes_read == 0) return false;
+
+ if (bytes_read < 0) {
+ GOOGLE_LOG(FATAL) << "Error reading from test runner: " << strerror(errno);
+ }
+
+ len -= bytes_read;
+ ofs += bytes_read;
+ }
+
+ return true;
+}
+
+void CheckedWrite(int fd, const void *buf, size_t len) {
+ if (write(fd, buf, len) != len) {
+ GOOGLE_LOG(FATAL) << "Error writing to test runner: " << strerror(errno);
+ }
+}
+
+void DoTest(const ConformanceRequest& request, ConformanceResponse* response) {
+ TestAllTypes test_message;
+
+ switch (request.payload_case()) {
+ case ConformanceRequest::kProtobufPayload:
+ if (!test_message.ParseFromString(request.protobuf_payload())) {
+ // Getting parse details would involve something like:
+ // http://stackoverflow.com/questions/22121922/how-can-i-get-more-details-about-errors-generated-during-protobuf-parsing-c
+ response->set_parse_error("Parse error (no more details available).");
+ return;
+ }
+ break;
+
+ case ConformanceRequest::kJsonPayload: {
+ string proto_binary;
+ Status status = JsonToBinaryString(type_resolver, *type_url,
+ request.json_payload(), &proto_binary);
+ if (!status.ok()) {
+ response->set_parse_error(string("Parse error: ") +
+ status.error_message().as_string());
+ return;
+ }
+
+ if (!test_message.ParseFromString(proto_binary)) {
+ response->set_runtime_error(
+ "Parsing JSON generates invalid proto output.");
+ return;
+ }
+ break;
+ }
+
+ case ConformanceRequest::PAYLOAD_NOT_SET:
+ GOOGLE_LOG(FATAL) << "Request didn't have payload.";
+ break;
+ }
+
+ switch (request.requested_output_format()) {
+ case conformance::UNSPECIFIED:
+ GOOGLE_LOG(FATAL) << "Unspecified output format";
+ break;
+
+ case conformance::PROTOBUF:
+ GOOGLE_CHECK(
+ test_message.SerializeToString(response->mutable_protobuf_payload()));
+ break;
+
+ case conformance::JSON: {
+ string proto_binary;
+ GOOGLE_CHECK(test_message.SerializeToString(&proto_binary));
+ Status status = BinaryToJsonString(type_resolver, *type_url, proto_binary,
+ response->mutable_json_payload());
+ if (!status.ok()) {
+ response->set_serialize_error(
+ string("Failed to serialize JSON output: ") +
+ status.error_message().as_string());
+ return;
+ }
+ break;
+ }
+
+ default:
+ GOOGLE_LOG(FATAL) << "Unknown output format: "
+ << request.requested_output_format();
+ }
+}
+
+bool DoTestIo() {
+ string serialized_input;
+ string serialized_output;
+ ConformanceRequest request;
+ ConformanceResponse response;
+ uint32_t bytes;
+
+ if (!CheckedRead(STDIN_FILENO, &bytes, sizeof(uint32_t))) {
+ // EOF.
+ return false;
+ }
+
+ serialized_input.resize(bytes);
+
+ if (!CheckedRead(STDIN_FILENO, (char*)serialized_input.c_str(), bytes)) {
+ GOOGLE_LOG(ERROR) << "Unexpected EOF on stdin. " << strerror(errno);
+ }
+
+ if (!request.ParseFromString(serialized_input)) {
+ GOOGLE_LOG(FATAL) << "Parse of ConformanceRequest proto failed.";
+ return false;
+ }
+
+ DoTest(request, &response);
+
+ response.SerializeToString(&serialized_output);
+
+ bytes = serialized_output.size();
+ CheckedWrite(STDOUT_FILENO, &bytes, sizeof(uint32_t));
+ CheckedWrite(STDOUT_FILENO, serialized_output.c_str(), bytes);
+
+ if (verbose) {
+ fprintf(stderr, "conformance-cpp: request=%s, response=%s\n",
+ request.ShortDebugString().c_str(),
+ response.ShortDebugString().c_str());
+ }
+
+ test_count++;
+
+ return true;
+}
+
+int main() {
+ type_resolver = NewTypeResolverForDescriptorPool(
+ kTypeUrlPrefix, DescriptorPool::generated_pool());
+ type_url = new string(GetTypeUrl(TestAllTypes::descriptor()));
+ while (1) {
+ if (!DoTestIo()) {
+ fprintf(stderr, "conformance-cpp: received EOF from test runner "
+ "after %d tests, exiting\n", test_count);
+ return 0;
+ }
+ }
+}
diff --git a/third_party/protobuf/conformance/conformance_nodejs.js b/third_party/protobuf/conformance/conformance_nodejs.js
new file mode 100755
index 0000000000..5ee3726994
--- /dev/null
+++ b/third_party/protobuf/conformance/conformance_nodejs.js
@@ -0,0 +1,168 @@
+#!/usr/bin/env node
+
+/*
+ * 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.
+ */
+
+var conformance = require('conformance_pb');
+var test_messages_proto3 = require('google/protobuf/test_messages_proto3_pb');
+var fs = require('fs');
+
+var testCount = 0;
+
+function doTest(request) {
+ var testMessage;
+ var response = new conformance.ConformanceResponse();
+
+ try {
+ if (request.getRequestedOutputFormat() === conformance.WireFormat.JSON) {
+ response.setSkipped("JSON not supported.");
+ return response;
+ }
+
+ switch (request.getPayloadCase()) {
+ case conformance.ConformanceRequest.PayloadCase.PROTOBUF_PAYLOAD:
+ try {
+ testMessage = test_messages_proto3.TestAllTypes.deserializeBinary(
+ request.getProtobufPayload());
+ } catch (err) {
+ response.setParseError(err.toString());
+ return response;
+ }
+
+ case conformance.ConformanceRequest.PayloadCase.JSON_PAYLOAD:
+ response.setSkipped("JSON not supported.");
+ return response;
+
+ case conformance.ConformanceRequest.PayloadCase.PAYLOAD_NOT_SET:
+ response.setRuntimeError("Request didn't have payload");
+ return response;
+ }
+
+ switch (request.getRequestedOutputFormat()) {
+ case conformance.WireFormat.UNSPECIFIED:
+ response.setRuntimeError("Unspecified output format");
+ return response;
+
+ case conformance.WireFormat.PROTOBUF:
+ response.setProtobufPayload(testMessage.serializeBinary());
+
+ case conformance.WireFormat.JSON:
+ response.setSkipped("JSON not supported.");
+ return response;
+
+ default:
+ throw "Request didn't have requested output format";
+ }
+ } catch (err) {
+ response.setRuntimeError(err.toString());
+ }
+
+ return response;
+}
+
+function onEof(totalRead) {
+ if (totalRead == 0) {
+ return undefined;
+ } else {
+ throw "conformance_nodejs: premature EOF on stdin.";
+ }
+}
+
+// Utility function to read a buffer of N bytes.
+function readBuffer(bytes) {
+ var buf = new Buffer(bytes);
+ var totalRead = 0;
+ while (totalRead < bytes) {
+ var read = 0;
+ try {
+ read = fs.readSync(process.stdin.fd, buf, totalRead, bytes - totalRead);
+ } catch (e) {
+ if (e.code == 'EOF') {
+ return onEof(totalRead)
+ } else if (e.code == 'EAGAIN') {
+ } else {
+ throw "conformance_nodejs: Error reading from stdin." + e;
+ }
+ }
+
+ totalRead += read;
+ }
+
+ return buf;
+}
+
+function writeBuffer(buffer) {
+ var totalWritten = 0;
+ while (totalWritten < buffer.length) {
+ totalWritten += fs.writeSync(
+ process.stdout.fd, buffer, totalWritten, buffer.length - totalWritten);
+ }
+}
+
+// Returns true if the test ran successfully, false on legitimate EOF.
+// If EOF is encountered in an unexpected place, raises IOError.
+function doTestIo() {
+ var lengthBuf = readBuffer(4);
+ if (!lengthBuf) {
+ return false;
+ }
+
+ var length = lengthBuf.readInt32LE(0);
+ var serializedRequest = readBuffer(length);
+ if (!serializedRequest) {
+ throw "conformance_nodejs: Failed to read request.";
+ }
+
+ serializedRequest = new Uint8Array(serializedRequest);
+ var request =
+ conformance.ConformanceRequest.deserializeBinary(serializedRequest);
+ var response = doTest(request);
+
+ var serializedResponse = response.serializeBinary();
+
+ lengthBuf = new Buffer(4);
+ lengthBuf.writeInt32LE(serializedResponse.length, 0);
+ writeBuffer(lengthBuf);
+ writeBuffer(new Buffer(serializedResponse));
+
+ testCount += 1
+
+ return true;
+}
+
+while (true) {
+ if (!doTestIo()) {
+ console.error('conformance_nodejs: received EOF from test runner ' +
+ "after " + testCount + " tests, exiting")
+ break;
+ }
+}
diff --git a/third_party/protobuf/conformance/conformance_objc.m b/third_party/protobuf/conformance/conformance_objc.m
new file mode 100644
index 0000000000..ef037f8496
--- /dev/null
+++ b/third_party/protobuf/conformance/conformance_objc.m
@@ -0,0 +1,180 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "Conformance.pbobjc.h"
+#import "google/protobuf/TestMessagesProto3.pbobjc.h"
+
+static void Die(NSString *format, ...) __dead2;
+
+static BOOL verbose = NO;
+static int32_t testCount = 0;
+
+static void Die(NSString *format, ...) {
+ va_list args;
+ va_start(args, format);
+ NSString *msg = [[NSString alloc] initWithFormat:format arguments:args];
+ NSLog(@"%@", msg);
+ va_end(args);
+ [msg release];
+ exit(66);
+}
+
+static NSData *CheckedReadDataOfLength(NSFileHandle *handle, NSUInteger numBytes) {
+ NSData *data = [handle readDataOfLength:numBytes];
+ NSUInteger dataLen = data.length;
+ if (dataLen == 0) {
+ return nil; // EOF.
+ }
+ if (dataLen != numBytes) {
+ Die(@"Failed to read the request length (%d), only got: %@",
+ numBytes, data);
+ }
+ return data;
+}
+
+static ConformanceResponse *DoTest(ConformanceRequest *request) {
+ ConformanceResponse *response = [ConformanceResponse message];
+ TestAllTypes *testMessage = nil;
+
+ switch (request.payloadOneOfCase) {
+ case ConformanceRequest_Payload_OneOfCase_GPBUnsetOneOfCase:
+ Die(@"Request didn't have a payload: %@", request);
+ break;
+
+ case ConformanceRequest_Payload_OneOfCase_ProtobufPayload: {
+ NSError *error = nil;
+ testMessage = [TestAllTypes parseFromData:request.protobufPayload
+ error:&error];
+ if (!testMessage) {
+ response.parseError =
+ [NSString stringWithFormat:@"Parse error: %@", error];
+ }
+ break;
+ }
+
+ case ConformanceRequest_Payload_OneOfCase_JsonPayload:
+ response.skipped = @"ObjC doesn't support parsing JSON";
+ break;
+ }
+
+ if (testMessage) {
+ switch (request.requestedOutputFormat) {
+ case WireFormat_GPBUnrecognizedEnumeratorValue:
+ case WireFormat_Unspecified:
+ Die(@"Unrecognized/unspecified output format: %@", request);
+ break;
+
+ case WireFormat_Protobuf:
+ response.protobufPayload = testMessage.data;
+ if (!response.protobufPayload) {
+ response.serializeError =
+ [NSString stringWithFormat:@"Failed to make data from: %@", testMessage];
+ }
+ break;
+
+ case WireFormat_Json:
+ response.skipped = @"ObjC doesn't support generating JSON";
+ break;
+ }
+ }
+
+ return response;
+}
+
+static uint32_t UInt32FromLittleEndianData(NSData *data) {
+ if (data.length != sizeof(uint32_t)) {
+ Die(@"Data not the right size for uint32_t: %@", data);
+ }
+ uint32_t value;
+ memcpy(&value, data.bytes, sizeof(uint32_t));
+ return CFSwapInt32LittleToHost(value);
+}
+
+static NSData *UInt32ToLittleEndianData(uint32_t num) {
+ uint32_t value = CFSwapInt32HostToLittle(num);
+ return [NSData dataWithBytes:&value length:sizeof(uint32_t)];
+}
+
+static BOOL DoTestIo(NSFileHandle *input, NSFileHandle *output) {
+ // See conformance_test_runner.cc for the wire format.
+ NSData *data = CheckedReadDataOfLength(input, sizeof(uint32_t));
+ if (!data) {
+ // EOF.
+ return NO;
+ }
+ uint32_t numBytes = UInt32FromLittleEndianData(data);
+ data = CheckedReadDataOfLength(input, numBytes);
+ if (!data) {
+ Die(@"Failed to read request");
+ }
+
+ NSError *error = nil;
+ ConformanceRequest *request = [ConformanceRequest parseFromData:data
+ error:&error];
+ if (!request) {
+ Die(@"Failed to parse the message data: %@", error);
+ }
+
+ ConformanceResponse *response = DoTest(request);
+ if (!response) {
+ Die(@"Failed to make a reply from %@", request);
+ }
+
+ data = response.data;
+ [output writeData:UInt32ToLittleEndianData((int32_t)data.length)];
+ [output writeData:data];
+
+ if (verbose) {
+ NSLog(@"Request: %@", request);
+ NSLog(@"Response: %@", response);
+ }
+
+ ++testCount;
+ return YES;
+}
+
+int main(int argc, const char *argv[]) {
+ @autoreleasepool {
+ NSFileHandle *input = [[NSFileHandle fileHandleWithStandardInput] retain];
+ NSFileHandle *output = [[NSFileHandle fileHandleWithStandardOutput] retain];
+
+ BOOL notDone = YES;
+ while (notDone) {
+ @autoreleasepool {
+ notDone = DoTestIo(input, output);
+ }
+ }
+
+ NSLog(@"Received EOF from test runner after %d tests, exiting.", testCount);
+ }
+ return 0;
+}
diff --git a/third_party/protobuf/conformance/conformance_php.php b/third_party/protobuf/conformance/conformance_php.php
new file mode 100755
index 0000000000..20fb508277
--- /dev/null
+++ b/third_party/protobuf/conformance/conformance_php.php
@@ -0,0 +1,112 @@
+<?php
+
+require_once("Conformance/WireFormat.php");
+require_once("Conformance/ConformanceResponse.php");
+require_once("Conformance/ConformanceRequest.php");
+require_once("Google/Protobuf/Any.php");
+require_once("Google/Protobuf/Duration.php");
+require_once("Google/Protobuf/FieldMask.php");
+require_once("Google/Protobuf/Struct.php");
+require_once("Google/Protobuf/Value.php");
+require_once("Google/Protobuf/ListValue.php");
+require_once("Google/Protobuf/NullValue.php");
+require_once("Google/Protobuf/Timestamp.php");
+require_once("Google/Protobuf/DoubleValue.php");
+require_once("Google/Protobuf/BytesValue.php");
+require_once("Google/Protobuf/FloatValue.php");
+require_once("Google/Protobuf/Int64Value.php");
+require_once("Google/Protobuf/UInt32Value.php");
+require_once("Google/Protobuf/BoolValue.php");
+require_once("Google/Protobuf/DoubleValue.php");
+require_once("Google/Protobuf/Int32Value.php");
+require_once("Google/Protobuf/StringValue.php");
+require_once("Google/Protobuf/UInt64Value.php");
+require_once("Protobuf_test_messages/Proto3/ForeignMessage.php");
+require_once("Protobuf_test_messages/Proto3/ForeignEnum.php");
+require_once("Protobuf_test_messages/Proto3/TestAllTypes.php");
+require_once("Protobuf_test_messages/Proto3/TestAllTypes_NestedMessage.php");
+require_once("Protobuf_test_messages/Proto3/TestAllTypes_NestedEnum.php");
+
+require_once("GPBMetadata/Conformance.php");
+require_once("GPBMetadata/Google/Protobuf/Any.php");
+require_once("GPBMetadata/Google/Protobuf/Duration.php");
+require_once("GPBMetadata/Google/Protobuf/FieldMask.php");
+require_once("GPBMetadata/Google/Protobuf/Struct.php");
+require_once("GPBMetadata/Google/Protobuf/Timestamp.php");
+require_once("GPBMetadata/Google/Protobuf/Wrappers.php");
+require_once("GPBMetadata/Google/Protobuf/TestMessagesProto3.php");
+
+use \Conformance\WireFormat;
+
+$test_count = 0;
+
+function doTest($request)
+{
+ $test_message = new \Protobuf_test_messages\Proto3\TestAllTypes();
+ $response = new \Conformance\ConformanceResponse();
+ if ($request->getPayload() == "protobuf_payload") {
+ try {
+ $test_message->mergeFromString($request->getProtobufPayload());
+ } catch (Exception $e) {
+ $response->setParseError($e->getMessage());
+ return $response;
+ }
+ } elseif ($request->getPayload() == "json_payload") {
+ try {
+ $test_message->jsonDecode($request->getJsonPayload());
+ } catch (Exception $e) {
+ $response->setParseError($e->getMessage());
+ return $response;
+ }
+ } else {
+ trigger_error("Request didn't have payload.", E_USER_ERROR);
+ }
+
+ if ($request->getRequestedOutputFormat() == WireFormat::UNSPECIFIED) {
+ trigger_error("Unspecified output format.", E_USER_ERROR);
+ } elseif ($request->getRequestedOutputFormat() == WireFormat::PROTOBUF) {
+ $response->setProtobufPayload($test_message->serializeToString());
+ } elseif ($request->getRequestedOutputFormat() == WireFormat::JSON) {
+ $response->setJsonPayload($test_message->jsonEncode());
+ }
+
+ return $response;
+}
+
+function doTestIO()
+{
+ $length_bytes = fread(STDIN, 4);
+ if (strlen($length_bytes) == 0) {
+ return false; # EOF
+ } elseif (strlen($length_bytes) != 4) {
+ trigger_error("I/O error", E_USER_ERROR);
+ }
+
+ $length = unpack("V", $length_bytes)[1];
+ $serialized_request = fread(STDIN, $length);
+ if (strlen($serialized_request) != $length) {
+ trigger_error("I/O error", E_USER_ERROR);
+ }
+
+ $request = new \Conformance\ConformanceRequest();
+ $request->mergeFromString($serialized_request);
+
+ $response = doTest($request);
+
+ $serialized_response = $response->serializeToString();
+ fwrite(STDOUT, pack("V", strlen($serialized_response)));
+ fwrite(STDOUT, $serialized_response);
+
+ $GLOBALS['test_count'] += 1;
+
+ return true;
+}
+
+while(true){
+ if (!doTestIO()) {
+ fprintf(STDERR,
+ "conformance_php: received EOF from test runner " +
+ "after %d tests, exiting\n", $test_count);
+ exit;
+ }
+}
diff --git a/third_party/protobuf/conformance/conformance_python.py b/third_party/protobuf/conformance/conformance_python.py
new file mode 100755
index 0000000000..7ace9b1672
--- /dev/null
+++ b/third_party/protobuf/conformance/conformance_python.py
@@ -0,0 +1,135 @@
+#!/usr/bin/env python
+#
+# 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 conformance test implementation for the Python protobuf library.
+
+See conformance.proto for more information.
+"""
+
+import struct
+import sys
+import os
+from google.protobuf import json_format
+from google.protobuf import message
+from google.protobuf import test_messages_proto3_pb2
+import conformance_pb2
+
+sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0)
+sys.stdin = os.fdopen(sys.stdin.fileno(), 'rb', 0)
+
+test_count = 0
+verbose = False
+
+class ProtocolError(Exception):
+ pass
+
+def do_test(request):
+ test_message = test_messages_proto3_pb2.TestAllTypes()
+ response = conformance_pb2.ConformanceResponse()
+ test_message = test_messages_proto3_pb2.TestAllTypes()
+
+ try:
+ if request.WhichOneof('payload') == 'protobuf_payload':
+ try:
+ test_message.ParseFromString(request.protobuf_payload)
+ except message.DecodeError as e:
+ response.parse_error = str(e)
+ return response
+
+ elif request.WhichOneof('payload') == 'json_payload':
+ try:
+ json_format.Parse(request.json_payload, test_message)
+ except Exception as e:
+ response.parse_error = str(e)
+ return response
+
+ else:
+ raise ProtocolError("Request didn't have payload.")
+
+ if request.requested_output_format == conformance_pb2.UNSPECIFIED:
+ raise ProtocolError("Unspecified output format")
+
+ elif request.requested_output_format == conformance_pb2.PROTOBUF:
+ response.protobuf_payload = test_message.SerializeToString()
+
+ elif request.requested_output_format == conformance_pb2.JSON:
+ 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)
+
+ return response
+
+def do_test_io():
+ length_bytes = sys.stdin.read(4)
+ if len(length_bytes) == 0:
+ return False # EOF
+ elif len(length_bytes) != 4:
+ raise IOError("I/O error")
+
+ # "I" is "unsigned int", so this depends on running on a platform with
+ # 32-bit "unsigned int" type. The Python struct module unfortunately
+ # has no format specifier for uint32_t.
+ length = struct.unpack("<I", length_bytes)[0]
+ serialized_request = sys.stdin.read(length)
+ if len(serialized_request) != length:
+ raise IOError("I/O error")
+
+ request = conformance_pb2.ConformanceRequest()
+ request.ParseFromString(serialized_request)
+
+ response = do_test(request)
+
+ serialized_response = response.SerializeToString()
+ sys.stdout.write(struct.pack("<I", len(serialized_response)))
+ sys.stdout.write(serialized_response)
+ sys.stdout.flush()
+
+ if verbose:
+ sys.stderr.write("conformance_python: request=%s, response=%s\n" % (
+ request.ShortDebugString().c_str(),
+ response.ShortDebugString().c_str()))
+
+ global test_count
+ test_count += 1
+
+ return True
+
+while True:
+ if not do_test_io():
+ sys.stderr.write("conformance_python: received EOF from test runner " +
+ "after %s tests, exiting\n" % (test_count))
+ sys.exit(0)
diff --git a/third_party/protobuf/conformance/conformance_ruby.rb b/third_party/protobuf/conformance/conformance_ruby.rb
new file mode 100755
index 0000000000..b7b7cf1c6c
--- /dev/null
+++ b/third_party/protobuf/conformance/conformance_ruby.rb
@@ -0,0 +1,124 @@
+#!/usr/bin/env ruby
+#
+# 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.
+
+require 'conformance_pb'
+require 'google/protobuf/test_messages_proto3_pb'
+
+$test_count = 0
+$verbose = false
+
+def do_test(request)
+ test_message = ProtobufTestMessages::Proto3::TestAllTypes.new
+ response = Conformance::ConformanceResponse.new
+
+ begin
+ case request.payload
+ when :protobuf_payload
+ begin
+ test_message = ProtobufTestMessages::Proto3::TestAllTypes.decode(
+ request.protobuf_payload)
+ rescue Google::Protobuf::ParseError => err
+ response.parse_error = err.message.encode('utf-8')
+ return response
+ end
+
+ when :json_payload
+ begin
+ test_message = ProtobufTestMessages::Proto3::TestAllTypes.decode_json(
+ request.json_payload)
+ rescue Google::Protobuf::ParseError => err
+ response.parse_error = err.message.encode('utf-8')
+ return response
+ end
+
+ when nil
+ fail "Request didn't have payload"
+ end
+
+ case request.requested_output_format
+ when :UNSPECIFIED
+ fail 'Unspecified output format'
+
+ when :PROTOBUF
+ response.protobuf_payload = test_message.to_proto
+
+ when :JSON
+ response.json_payload = test_message.to_json
+
+ when nil
+ fail "Request didn't have requested output format"
+ end
+ rescue StandardError => err
+ response.runtime_error = err.message.encode('utf-8')
+ end
+
+ response
+end
+
+# Returns true if the test ran successfully, false on legitimate EOF.
+# If EOF is encountered in an unexpected place, raises IOError.
+def do_test_io
+ length_bytes = STDIN.read(4)
+ return false if length_bytes.nil?
+
+ length = length_bytes.unpack('V').first
+ serialized_request = STDIN.read(length)
+ if serialized_request.nil? || serialized_request.length != length
+ fail IOError
+ end
+
+ request = Conformance::ConformanceRequest.decode(serialized_request)
+
+ response = do_test(request)
+
+ serialized_response = Conformance::ConformanceResponse.encode(response)
+ STDOUT.write([serialized_response.length].pack('V'))
+ STDOUT.write(serialized_response)
+ STDOUT.flush
+
+ if $verbose
+ STDERR.puts("conformance_ruby: request=#{request.to_json}, " \
+ "response=#{response.to_json}\n")
+ end
+
+ $test_count += 1
+
+ true
+end
+
+loop do
+ unless do_test_io
+ STDERR.puts('conformance_ruby: received EOF from test runner ' \
+ "after #{$test_count} tests, exiting")
+ break
+ end
+end
diff --git a/third_party/protobuf/conformance/conformance_test.cc b/third_party/protobuf/conformance/conformance_test.cc
new file mode 100644
index 0000000000..1e5387a54c
--- /dev/null
+++ b/third_party/protobuf/conformance/conformance_test.cc
@@ -0,0 +1,2406 @@
+// 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 <stdarg.h>
+#include <string>
+#include <fstream>
+
+#include "conformance.pb.h"
+#include "conformance_test.h"
+#include <google/protobuf/test_messages_proto3.pb.h>
+
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/stringprintf.h>
+#include <google/protobuf/text_format.h>
+#include <google/protobuf/util/field_comparator.h>
+#include <google/protobuf/util/json_util.h>
+#include <google/protobuf/util/message_differencer.h>
+#include <google/protobuf/util/type_resolver_util.h>
+#include <google/protobuf/wire_format_lite.h>
+
+#include "third_party/jsoncpp/json.h"
+
+using conformance::ConformanceRequest;
+using conformance::ConformanceResponse;
+using conformance::WireFormat;
+using google::protobuf::Descriptor;
+using google::protobuf::FieldDescriptor;
+using google::protobuf::internal::WireFormatLite;
+using google::protobuf::TextFormat;
+using google::protobuf::util::DefaultFieldComparator;
+using google::protobuf::util::JsonToBinaryString;
+using google::protobuf::util::MessageDifferencer;
+using google::protobuf::util::NewTypeResolverForDescriptorPool;
+using google::protobuf::util::Status;
+using protobuf_test_messages::proto3::TestAllTypes;
+using std::string;
+
+namespace {
+
+static const char kTypeUrlPrefix[] = "type.googleapis.com";
+
+static string GetTypeUrl(const Descriptor* message) {
+ return string(kTypeUrlPrefix) + "/" + message->full_name();
+}
+
+/* Routines for building arbitrary protos *************************************/
+
+// We would use CodedOutputStream except that we want more freedom to build
+// arbitrary protos (even invalid ones).
+
+const string empty;
+
+string cat(const string& a, const string& b,
+ const string& c = empty,
+ const string& d = empty,
+ const string& e = empty,
+ const string& f = empty,
+ const string& g = empty,
+ const string& h = empty,
+ const string& i = empty,
+ const string& j = empty,
+ const string& k = empty,
+ const string& l = empty) {
+ string ret;
+ ret.reserve(a.size() + b.size() + c.size() + d.size() + e.size() + f.size() +
+ g.size() + h.size() + i.size() + j.size() + k.size() + l.size());
+ ret.append(a);
+ ret.append(b);
+ ret.append(c);
+ ret.append(d);
+ ret.append(e);
+ ret.append(f);
+ ret.append(g);
+ ret.append(h);
+ ret.append(i);
+ ret.append(j);
+ ret.append(k);
+ ret.append(l);
+ return ret;
+}
+
+// The maximum number of bytes that it takes to encode a 64-bit varint.
+#define VARINT_MAX_LEN 10
+
+size_t vencode64(uint64_t val, int over_encoded_bytes, char *buf) {
+ if (val == 0) { buf[0] = 0; return 1; }
+ size_t i = 0;
+ while (val) {
+ uint8_t byte = val & 0x7fU;
+ val >>= 7;
+ if (val || over_encoded_bytes) byte |= 0x80U;
+ buf[i++] = byte;
+ }
+ while (over_encoded_bytes--) {
+ assert(i < 10);
+ uint8_t byte = over_encoded_bytes ? 0x80 : 0;
+ buf[i++] = byte;
+ }
+ return i;
+}
+
+string varint(uint64_t x) {
+ char buf[VARINT_MAX_LEN];
+ size_t len = vencode64(x, 0, buf);
+ return string(buf, len);
+}
+
+// Encodes a varint that is |extra| bytes longer than it needs to be, but still
+// valid.
+string longvarint(uint64_t x, int extra) {
+ char buf[VARINT_MAX_LEN];
+ size_t len = vencode64(x, extra, buf);
+ return string(buf, len);
+}
+
+// TODO: proper byte-swapping for big-endian machines.
+string fixed32(void *data) { return string(static_cast<char*>(data), 4); }
+string fixed64(void *data) { return string(static_cast<char*>(data), 8); }
+
+string delim(const string& buf) { return cat(varint(buf.size()), buf); }
+string u32(uint32_t u32) { return fixed32(&u32); }
+string u64(uint64_t u64) { return fixed64(&u64); }
+string flt(float f) { return fixed32(&f); }
+string dbl(double d) { return fixed64(&d); }
+string zz32(int32_t x) { return varint(WireFormatLite::ZigZagEncode32(x)); }
+string zz64(int64_t x) { return varint(WireFormatLite::ZigZagEncode64(x)); }
+
+string tag(uint32_t fieldnum, char wire_type) {
+ return varint((fieldnum << 3) | wire_type);
+}
+
+string submsg(uint32_t fn, const string& buf) {
+ return cat( tag(fn, WireFormatLite::WIRETYPE_LENGTH_DELIMITED), delim(buf) );
+}
+
+#define UNKNOWN_FIELD 666
+
+const FieldDescriptor* GetFieldForType(FieldDescriptor::Type type,
+ bool repeated) {
+ const Descriptor* d = TestAllTypes().GetDescriptor();
+ for (int i = 0; i < d->field_count(); i++) {
+ const FieldDescriptor* f = d->field(i);
+ if (f->type() == type && f->is_repeated() == repeated) {
+ return f;
+ }
+ }
+ GOOGLE_LOG(FATAL) << "Couldn't find field with type " << (int)type;
+ return nullptr;
+}
+
+string UpperCase(string str) {
+ for (int i = 0; i < str.size(); i++) {
+ str[i] = toupper(str[i]);
+ }
+ return str;
+}
+
+} // anonymous namespace
+
+namespace google {
+namespace protobuf {
+
+void ConformanceTestSuite::ReportSuccess(const string& test_name) {
+ if (expected_to_fail_.erase(test_name) != 0) {
+ StringAppendF(&output_,
+ "ERROR: test %s is in the failure list, but test succeeded. "
+ "Remove it from the failure list.\n",
+ test_name.c_str());
+ unexpected_succeeding_tests_.insert(test_name);
+ }
+ successes_++;
+}
+
+void ConformanceTestSuite::ReportFailure(const string& test_name,
+ ConformanceLevel level,
+ const ConformanceRequest& request,
+ const ConformanceResponse& response,
+ const char* fmt, ...) {
+ if (expected_to_fail_.erase(test_name) == 1) {
+ 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);
+ }
+ va_list args;
+ va_start(args, fmt);
+ StringAppendV(&output_, fmt, args);
+ va_end(args);
+ StringAppendF(&output_, " request=%s, response=%s\n",
+ request.ShortDebugString().c_str(),
+ response.ShortDebugString().c_str());
+}
+
+void ConformanceTestSuite::ReportSkip(const string& test_name,
+ const ConformanceRequest& request,
+ const ConformanceResponse& response) {
+ if (verbose_) {
+ StringAppendF(&output_, "SKIPPED, test=%s request=%s, response=%s\n",
+ test_name.c_str(), request.ShortDebugString().c_str(),
+ response.ShortDebugString().c_str());
+ }
+ 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) {
+ if (test_names_.insert(test_name).second == false) {
+ GOOGLE_LOG(FATAL) << "Duplicated test name: " << test_name;
+ }
+
+ string serialized_request;
+ string serialized_response;
+ request.SerializeToString(&serialized_request);
+
+ runner_->RunTest(test_name, serialized_request, &serialized_response);
+
+ if (!response->ParseFromString(serialized_response)) {
+ response->Clear();
+ response->set_runtime_error("response proto could not be parsed.");
+ }
+
+ if (verbose_) {
+ StringAppendF(&output_, "conformance test: name=%s, request=%s, response=%s\n",
+ test_name.c_str(),
+ request.ShortDebugString().c_str(),
+ response->ShortDebugString().c_str());
+ }
+}
+
+void ConformanceTestSuite::RunValidInputTest(
+ 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))
+ << "Failed to parse data for test case: " << test_name
+ << ", data: " << equivalent_text_format;
+
+ ConformanceRequest request;
+ ConformanceResponse response;
+
+ switch (input_format) {
+ case conformance::PROTOBUF:
+ request.set_protobuf_payload(input);
+ break;
+
+ case conformance::JSON:
+ request.set_json_payload(input);
+ break;
+
+ default:
+ GOOGLE_LOG(FATAL) << "Unspecified input format";
+ }
+
+ request.set_requested_output_format(requested_output);
+
+ RunTest(test_name, request, &response);
+
+ TestAllTypes test_message;
+
+ switch (response.result_case()) {
+ case ConformanceResponse::RESULT_NOT_SET:
+ ReportFailure(test_name, level, request, response,
+ "Response didn't have any field in the Response.");
+ return;
+
+ case ConformanceResponse::kParseError:
+ case ConformanceResponse::kRuntimeError:
+ case ConformanceResponse::kSerializeError:
+ ReportFailure(test_name, level, request, response,
+ "Failed to parse input or produce output.");
+ return;
+
+ case ConformanceResponse::kSkipped:
+ ReportSkip(test_name, request, response);
+ return;
+
+ case ConformanceResponse::kJsonPayload: {
+ if (requested_output != conformance::JSON) {
+ ReportFailure(
+ test_name, level, request, response,
+ "Test was asked for protobuf output but provided JSON instead.");
+ return;
+ }
+ string binary_protobuf;
+ Status status =
+ JsonToBinaryString(type_resolver_.get(), type_url_,
+ response.json_payload(), &binary_protobuf);
+ if (!status.ok()) {
+ ReportFailure(test_name, level, request, response,
+ "JSON output we received from test was unparseable.");
+ return;
+ }
+
+ if (!test_message.ParseFromString(binary_protobuf)) {
+ ReportFailure(test_name, level, request, response,
+ "INTERNAL ERROR: internal JSON->protobuf transcode "
+ "yielded unparseable proto.");
+ return;
+ }
+
+ break;
+ }
+
+ case ConformanceResponse::kProtobufPayload: {
+ if (requested_output != conformance::PROTOBUF) {
+ ReportFailure(
+ 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, level, request, response,
+ "Protobuf output we received from test was unparseable.");
+ return;
+ }
+
+ break;
+ }
+
+ default:
+ GOOGLE_LOG(FATAL) << test_name << ": unknown payload type: "
+ << response.result_case();
+ }
+
+ MessageDifferencer differencer;
+ DefaultFieldComparator field_comparator;
+ field_comparator.set_treat_nan_as_equal(true);
+ differencer.set_field_comparator(&field_comparator);
+ string differences;
+ differencer.ReportDifferencesToString(&differences);
+
+ if (differencer.Compare(reference_message, test_message)) {
+ ReportSuccess(test_name);
+ } else {
+ ReportFailure(test_name, level, request, response,
+ "Output was not equivalent to reference message: %s.",
+ differences.c_str());
+ }
+}
+
+// Expect that this precise protobuf will cause a parse error.
+void ConformanceTestSuite::ExpectParseFailureForProto(
+ const string& proto, const string& test_name, ConformanceLevel level) {
+ ConformanceRequest request;
+ ConformanceResponse response;
+ request.set_protobuf_payload(proto);
+ 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.
+ request.set_requested_output_format(conformance::PROTOBUF);
+
+ RunTest(effective_test_name, request, &response);
+ if (response.result_case() == ConformanceResponse::kParseError) {
+ ReportSuccess(effective_test_name);
+ } else if (response.result_case() == ConformanceResponse::kSkipped) {
+ ReportSkip(effective_test_name, request, response);
+ } else {
+ ReportFailure(effective_test_name, level, request, response,
+ "Should have failed to parse, but didn't.");
+ }
+}
+
+// Expect that this protobuf will cause a parse error, even if it is followed
+// by valid protobuf data. We can try running this twice: once with this
+// data verbatim and once with this data followed by some valid data.
+//
+// TODO(haberman): implement the second of these.
+void ConformanceTestSuite::ExpectHardParseFailureForProto(
+ const string& proto, const string& test_name, ConformanceLevel level) {
+ return ExpectParseFailureForProto(proto, test_name, level);
+}
+
+void ConformanceTestSuite::RunValidJsonTest(
+ const string& test_name, ConformanceLevel level, const string& input_json,
+ const string& equivalent_text_format) {
+ 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, ConformanceLevel level, const TestAllTypes& input,
+ const string& equivalent_text_format) {
+ RunValidInputTest(
+ ConformanceLevelToString(level) + ".ProtobufInput." + test_name +
+ ".JsonOutput", level, input.SerializeAsString(), conformance::PROTOBUF,
+ equivalent_text_format, conformance::JSON);
+}
+
+void ConformanceTestSuite::RunValidProtobufTest(
+ const string& test_name, ConformanceLevel level,
+ const string& input_protobuf, const string& equivalent_text_format) {
+ RunValidInputTest(
+ ConformanceLevelToString(level) + ".ProtobufInput." + test_name +
+ ".ProtobufOutput", level, input_protobuf, conformance::PROTOBUF,
+ equivalent_text_format, conformance::PROTOBUF);
+ RunValidInputTest(
+ ConformanceLevelToString(level) + ".ProtobufInput." + test_name +
+ ".JsonOutput", level, input_protobuf, conformance::PROTOBUF,
+ equivalent_text_format, conformance::JSON);
+}
+
+void ConformanceTestSuite::RunValidProtobufTestWithMessage(
+ const string& test_name, ConformanceLevel level, const TestAllTypes& input,
+ const string& equivalent_text_format) {
+ RunValidProtobufTest(test_name, level, input.SerializeAsString(), equivalent_text_format);
+}
+
+// According to proto3 JSON specification, JSON serializers follow more strict
+// rules than parsers (e.g., a serializer must serialize int32 values as JSON
+// numbers while the parser is allowed to accept them as JSON strings). This
+// method allows strict checking on a proto3 JSON serializer by inspecting
+// the JSON output directly.
+void ConformanceTestSuite::RunValidJsonTestWithValidator(
+ 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 = ConformanceLevelToString(level) +
+ ".JsonInput." + test_name + ".Validator";
+
+ RunTest(effective_test_name, request, &response);
+
+ if (response.result_case() == ConformanceResponse::kSkipped) {
+ ReportSkip(effective_test_name, request, response);
+ return;
+ }
+
+ if (response.result_case() != ConformanceResponse::kJsonPayload) {
+ ReportFailure(effective_test_name, level, request, response,
+ "Expected JSON payload but got type %d.",
+ response.result_case());
+ return;
+ }
+ Json::Reader reader;
+ Json::Value value;
+ if (!reader.parse(response.json_payload(), value)) {
+ 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, level, request, response,
+ "JSON payload validation failed.");
+ return;
+ }
+ ReportSuccess(effective_test_name);
+}
+
+void ConformanceTestSuite::ExpectParseFailureForJson(
+ const string& test_name, ConformanceLevel level, const string& input_json) {
+ ConformanceRequest request;
+ ConformanceResponse response;
+ request.set_json_payload(input_json);
+ 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.
+ request.set_requested_output_format(conformance::JSON);
+
+ RunTest(effective_test_name, request, &response);
+ if (response.result_case() == ConformanceResponse::kParseError) {
+ ReportSuccess(effective_test_name);
+ } else if (response.result_case() == ConformanceResponse::kSkipped) {
+ ReportSkip(effective_test_name, request, response);
+ } else {
+ ReportFailure(effective_test_name, level, request, response,
+ "Should have failed to parse, but didn't.");
+ }
+}
+
+void ConformanceTestSuite::ExpectSerializeFailureForJson(
+ const string& test_name, ConformanceLevel level, const string& text_format) {
+ TestAllTypes payload_message;
+ GOOGLE_CHECK(
+ TextFormat::ParseFromString(text_format, &payload_message))
+ << "Failed to parse: " << text_format;
+
+ ConformanceRequest request;
+ ConformanceResponse response;
+ request.set_protobuf_payload(payload_message.SerializeAsString());
+ string effective_test_name =
+ ConformanceLevelToString(level) + "." + test_name + ".JsonOutput";
+ request.set_requested_output_format(conformance::JSON);
+
+ RunTest(effective_test_name, request, &response);
+ if (response.result_case() == ConformanceResponse::kSerializeError) {
+ ReportSuccess(effective_test_name);
+ } else if (response.result_case() == ConformanceResponse::kSkipped) {
+ ReportSkip(effective_test_name, request, response);
+ } else {
+ ReportFailure(effective_test_name, level, request, response,
+ "Should have failed to serialize, but didn't.");
+ }
+}
+
+void ConformanceTestSuite::TestPrematureEOFForType(FieldDescriptor::Type type) {
+ // Incomplete values for each wire type.
+ static const string incompletes[6] = {
+ string("\x80"), // VARINT
+ string("abcdefg"), // 64BIT
+ string("\x80"), // DELIMITED (partial length)
+ string(), // START_GROUP (no value required)
+ string(), // END_GROUP (no value required)
+ string("abc") // 32BIT
+ };
+
+ const FieldDescriptor* field = GetFieldForType(type, false);
+ const FieldDescriptor* rep_field = GetFieldForType(type, true);
+ WireFormatLite::WireType wire_type = WireFormatLite::WireTypeForFieldType(
+ static_cast<WireFormatLite::FieldType>(type));
+ const string& incomplete = incompletes[wire_type];
+ const string type_name =
+ UpperCase(string(".") + FieldDescriptor::TypeName(type));
+
+ ExpectParseFailureForProto(
+ tag(field->number(), wire_type),
+ "PrematureEofBeforeKnownNonRepeatedValue" + type_name, REQUIRED);
+
+ ExpectParseFailureForProto(
+ tag(rep_field->number(), wire_type),
+ "PrematureEofBeforeKnownRepeatedValue" + type_name, REQUIRED);
+
+ ExpectParseFailureForProto(
+ tag(UNKNOWN_FIELD, wire_type),
+ "PrematureEofBeforeUnknownValue" + type_name, REQUIRED);
+
+ ExpectParseFailureForProto(
+ cat( tag(field->number(), wire_type), incomplete ),
+ "PrematureEofInsideKnownNonRepeatedValue" + type_name, REQUIRED);
+
+ ExpectParseFailureForProto(
+ cat( tag(rep_field->number(), wire_type), incomplete ),
+ "PrematureEofInsideKnownRepeatedValue" + type_name, REQUIRED);
+
+ ExpectParseFailureForProto(
+ cat( tag(UNKNOWN_FIELD, wire_type), incomplete ),
+ "PrematureEofInsideUnknownValue" + type_name, REQUIRED);
+
+ if (wire_type == WireFormatLite::WIRETYPE_LENGTH_DELIMITED) {
+ ExpectParseFailureForProto(
+ cat( tag(field->number(), wire_type), varint(1) ),
+ "PrematureEofInDelimitedDataForKnownNonRepeatedValue" + type_name,
+ REQUIRED);
+
+ ExpectParseFailureForProto(
+ cat( tag(rep_field->number(), wire_type), varint(1) ),
+ "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, REQUIRED);
+
+ if (type == FieldDescriptor::TYPE_MESSAGE) {
+ // Submessage ends in the middle of a value.
+ string incomplete_submsg =
+ cat( tag(WireFormatLite::TYPE_INT32, WireFormatLite::WIRETYPE_VARINT),
+ incompletes[WireFormatLite::WIRETYPE_VARINT] );
+ ExpectHardParseFailureForProto(
+ cat( tag(field->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED),
+ varint(incomplete_submsg.size()),
+ incomplete_submsg ),
+ "PrematureEofInSubmessageValue" + type_name, REQUIRED);
+ }
+ } else if (type != FieldDescriptor::TYPE_GROUP) {
+ // Non-delimited, non-group: eligible for packing.
+
+ // Packed region ends in the middle of a value.
+ ExpectHardParseFailureForProto(
+ cat(tag(rep_field->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED),
+ varint(incomplete.size()), incomplete),
+ "PrematureEofInPackedFieldValue" + type_name, REQUIRED);
+
+ // EOF in the middle of packed region.
+ ExpectParseFailureForProto(
+ cat(tag(rep_field->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED),
+ varint(1)),
+ "PrematureEofInPackedField" + type_name, REQUIRED);
+ }
+}
+
+void ConformanceTestSuite::TestValidDataForType(
+ FieldDescriptor::Type type,
+ std::vector<std::pair<std::string, std::string>> values) {
+ const string type_name =
+ UpperCase(string(".") + FieldDescriptor::TypeName(type));
+ WireFormatLite::WireType wire_type = WireFormatLite::WireTypeForFieldType(
+ static_cast<WireFormatLite::FieldType>(type));
+ const FieldDescriptor* field = GetFieldForType(type, false);
+ const FieldDescriptor* rep_field = GetFieldForType(type, true);
+
+ RunValidProtobufTest("ValidDataScalar" + type_name, REQUIRED,
+ cat(tag(field->number(), wire_type), values[0].first),
+ field->name() + ": " + values[0].second);
+
+ string proto;
+ string text = field->name() + ": " + values.back().second;
+ for (size_t i = 0; i < values.size(); i++) {
+ proto += cat(tag(field->number(), wire_type), values[i].first);
+ }
+ RunValidProtobufTest("RepeatedScalarSelectsLast" + type_name, REQUIRED,
+ proto, text);
+
+ proto.clear();
+ text.clear();
+
+ for (size_t i = 0; i < values.size(); i++) {
+ proto += cat(tag(rep_field->number(), wire_type), values[i].first);
+ text += rep_field->name() + ": " + values[i].second + " ";
+ }
+ RunValidProtobufTest("ValidDataRepeated" + type_name, REQUIRED, proto, text);
+}
+
+void ConformanceTestSuite::SetFailureList(const string& filename,
+ const vector<string>& failure_list) {
+ failure_list_filename_ = filename;
+ expected_to_fail_.clear();
+ std::copy(failure_list.begin(), failure_list.end(),
+ std::inserter(expected_to_fail_, expected_to_fail_.end()));
+}
+
+bool ConformanceTestSuite::CheckSetEmpty(const set<string>& set_to_check,
+ const std::string& write_to_file,
+ const std::string& msg) {
+ if (set_to_check.empty()) {
+ return true;
+ } else {
+ StringAppendF(&output_, "\n");
+ StringAppendF(&output_, "%s\n\n", msg.c_str());
+ for (set<string>::const_iterator iter = set_to_check.begin();
+ iter != set_to_check.end(); ++iter) {
+ StringAppendF(&output_, " %s\n", iter->c_str());
+ }
+ StringAppendF(&output_, "\n");
+
+ if (!write_to_file.empty()) {
+ std::ofstream os(write_to_file);
+ if (os) {
+ for (set<string>::const_iterator iter = set_to_check.begin();
+ iter != set_to_check.end(); ++iter) {
+ os << *iter << "\n";
+ }
+ } else {
+ StringAppendF(&output_, "Failed to open file: %s\n",
+ write_to_file.c_str());
+ }
+ }
+
+ return false;
+ }
+}
+
+bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
+ std::string* output) {
+ runner_ = runner;
+ successes_ = 0;
+ expected_failures_ = 0;
+ skipped_.clear();
+ test_names_.clear();
+ unexpected_failing_tests_.clear();
+ unexpected_succeeding_tests_.clear();
+ type_resolver_.reset(NewTypeResolverForDescriptorPool(
+ kTypeUrlPrefix, DescriptorPool::generated_pool()));
+ type_url_ = GetTypeUrl(TestAllTypes::descriptor());
+
+ output_ = "\nCONFORMANCE TEST BEGIN ====================================\n\n";
+
+ for (int i = 1; i <= FieldDescriptor::MAX_TYPE; i++) {
+ if (i == FieldDescriptor::TYPE_GROUP) continue;
+ TestPrematureEOFForType(static_cast<FieldDescriptor::Type>(i));
+ }
+
+ int64 kInt64Min = -9223372036854775808ULL;
+ int64 kInt64Max = 9223372036854775807ULL;
+ uint64 kUint64Max = 18446744073709551615ULL;
+ int32 kInt32Max = 2147483647;
+ int32 kInt32Min = -2147483648;
+ uint32 kUint32Max = 4294967295UL;
+
+ TestValidDataForType(FieldDescriptor::TYPE_DOUBLE, {
+ {dbl(0.1), "0.1"},
+ {dbl(1.7976931348623157e+308), "1.7976931348623157e+308"},
+ {dbl(2.22507385850720138309e-308), "2.22507385850720138309e-308"}
+ });
+ TestValidDataForType(FieldDescriptor::TYPE_FLOAT, {
+ {flt(0.1), "0.1"},
+ {flt(3.402823e+38), "3.402823e+38"}, // 3.40282347e+38
+ {flt(1.17549435e-38f), "1.17549435e-38"}
+ });
+ TestValidDataForType(FieldDescriptor::TYPE_INT64, {
+ {varint(12345), "12345"},
+ {varint(kInt64Max), std::to_string(kInt64Max)},
+ {varint(kInt64Min), std::to_string(kInt64Min)}
+ });
+ TestValidDataForType(FieldDescriptor::TYPE_UINT64, {
+ {varint(12345), "12345"},
+ {varint(kUint64Max), std::to_string(kUint64Max)},
+ {varint(0), "0"}
+ });
+ TestValidDataForType(FieldDescriptor::TYPE_INT32, {
+ {varint(12345), "12345"},
+ {longvarint(12345, 2), "12345"},
+ {longvarint(12345, 7), "12345"},
+ {varint(kInt32Max), std::to_string(kInt32Max)},
+ {varint(kInt32Min), std::to_string(kInt32Min)},
+ {varint(1LL << 33), std::to_string(static_cast<int32>(1LL << 33))},
+ {varint((1LL << 33) - 1),
+ std::to_string(static_cast<int32>((1LL << 33) - 1))},
+ });
+ TestValidDataForType(FieldDescriptor::TYPE_UINT32, {
+ {varint(12345), "12345"},
+ {longvarint(12345, 2), "12345"},
+ {longvarint(12345, 7), "12345"},
+ {varint(kUint32Max), std::to_string(kUint32Max)}, // UINT32_MAX
+ {varint(0), "0"},
+ {varint(1LL << 33), std::to_string(static_cast<uint32>(1LL << 33))},
+ {varint((1LL << 33) - 1),
+ std::to_string(static_cast<uint32>((1LL << 33) - 1))},
+ });
+ TestValidDataForType(FieldDescriptor::TYPE_FIXED64, {
+ {u64(12345), "12345"},
+ {u64(kUint64Max), std::to_string(kUint64Max)},
+ {u64(0), "0"}
+ });
+ TestValidDataForType(FieldDescriptor::TYPE_FIXED32, {
+ {u32(12345), "12345"},
+ {u32(kUint32Max), std::to_string(kUint32Max)}, // UINT32_MAX
+ {u32(0), "0"}
+ });
+ TestValidDataForType(FieldDescriptor::TYPE_SFIXED64, {
+ {u64(12345), "12345"},
+ {u64(kInt64Max), std::to_string(kInt64Max)},
+ {u64(kInt64Min), std::to_string(kInt64Min)}
+ });
+ TestValidDataForType(FieldDescriptor::TYPE_SFIXED32, {
+ {u32(12345), "12345"},
+ {u32(kInt32Max), std::to_string(kInt32Max)},
+ {u32(kInt32Min), std::to_string(kInt32Min)}
+ });
+ TestValidDataForType(FieldDescriptor::TYPE_BOOL, {
+ {varint(1), "true"},
+ {varint(0), "false"},
+ {varint(12345678), "true"}
+ });
+ TestValidDataForType(FieldDescriptor::TYPE_SINT32, {
+ {zz32(12345), "12345"},
+ {zz32(kInt32Max), std::to_string(kInt32Max)},
+ {zz32(kInt32Min), std::to_string(kInt32Min)}
+ });
+ TestValidDataForType(FieldDescriptor::TYPE_SINT64, {
+ {zz64(12345), "12345"},
+ {zz64(kInt64Max), std::to_string(kInt64Max)},
+ {zz64(kInt64Min), std::to_string(kInt64Min)}
+ });
+
+ // TODO(haberman):
+ // TestValidDataForType(FieldDescriptor::TYPE_STRING
+ // TestValidDataForType(FieldDescriptor::TYPE_GROUP
+ // TestValidDataForType(FieldDescriptor::TYPE_MESSAGE
+ // TestValidDataForType(FieldDescriptor::TYPE_BYTES
+ // TestValidDataForType(FieldDescriptor::TYPE_ENUM
+
+ 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", REQUIRED,
+ R"({
+ "fieldname1": 1,
+ "fieldName2": 2,
+ "FieldName3": 3,
+ "fieldName4": 4
+ })",
+ R"(
+ fieldname1: 1
+ field_name2: 2
+ _field_name3: 3
+ field__name4_: 4
+ )");
+ RunValidJsonTest(
+ "FieldNameWithNumbers", REQUIRED,
+ R"({
+ "field0name5": 5,
+ "field0Name6": 6
+ })",
+ R"(
+ field0name5: 5
+ field_0_name6: 6
+ )");
+ RunValidJsonTest(
+ "FieldNameWithMixedCases", REQUIRED,
+ R"({
+ "fieldName7": 7,
+ "FieldName8": 8,
+ "fieldName9": 9,
+ "FieldName10": 10,
+ "FIELDNAME11": 11,
+ "FIELDName12": 12
+ })",
+ R"(
+ fieldName7: 7
+ FieldName8: 8
+ field_Name9: 9
+ Field_Name10: 10
+ FIELD_NAME11: 11
+ FIELD_name12: 12
+ )");
+ RunValidJsonTest(
+ "FieldNameWithDoubleUnderscores", RECOMMENDED,
+ R"({
+ "FieldName13": 13,
+ "FieldName14": 14,
+ "fieldName15": 15,
+ "fieldName16": 16,
+ "fieldName17": 17,
+ "FieldName18": 18
+ })",
+ R"(
+ __field_name13: 13
+ __Field_name14: 14
+ field__name15: 15
+ field__Name16: 16
+ field_name17__: 17
+ Field_name18__: 18
+ )");
+ // Using the original proto field name in JSON is also allowed.
+ RunValidJsonTest(
+ "OriginalProtoFieldName", REQUIRED,
+ R"({
+ "fieldname1": 1,
+ "field_name2": 2,
+ "_field_name3": 3,
+ "field__name4_": 4,
+ "field0name5": 5,
+ "field_0_name6": 6,
+ "fieldName7": 7,
+ "FieldName8": 8,
+ "field_Name9": 9,
+ "Field_Name10": 10,
+ "FIELD_NAME11": 11,
+ "FIELD_name12": 12,
+ "__field_name13": 13,
+ "__Field_name14": 14,
+ "field__name15": 15,
+ "field__Name16": 16,
+ "field_name17__": 17,
+ "Field_name18__": 18
+ })",
+ R"(
+ fieldname1: 1
+ field_name2: 2
+ _field_name3: 3
+ field__name4_: 4
+ field0name5: 5
+ field_0_name6: 6
+ fieldName7: 7
+ FieldName8: 8
+ field_Name9: 9
+ Field_Name10: 10
+ FIELD_NAME11: 11
+ FIELD_name12: 12
+ __field_name13: 13
+ __Field_name14: 14
+ field__name15: 15
+ field__Name16: 16
+ field_name17__: 17
+ Field_name18__: 18
+ )");
+ // Field names can be escaped.
+ RunValidJsonTest(
+ "FieldNameEscaped", REQUIRED,
+ R"({"fieldn\u0061me1": 1})",
+ "fieldname1: 1");
+ // String ends with escape character.
+ ExpectParseFailureForJson(
+ "StringEndsWithEscapeChar", RECOMMENDED,
+ "{\"optionalString\": \"abc\\");
+ // Field names must be quoted (or it's not valid JSON).
+ ExpectParseFailureForJson(
+ "FieldNameNotQuoted", RECOMMENDED,
+ "{fieldname1: 1}");
+ // Trailing comma is not allowed (not valid JSON).
+ ExpectParseFailureForJson(
+ "TrailingCommaInAnObject", RECOMMENDED,
+ R"({"fieldname1":1,})");
+ ExpectParseFailureForJson(
+ "TrailingCommaInAnObjectWithSpace", RECOMMENDED,
+ R"({"fieldname1":1 ,})");
+ ExpectParseFailureForJson(
+ "TrailingCommaInAnObjectWithSpaceCommaSpace", RECOMMENDED,
+ R"({"fieldname1":1 , })");
+ ExpectParseFailureForJson(
+ "TrailingCommaInAnObjectWithNewlines", RECOMMENDED,
+ R"({
+ "fieldname1":1,
+ })");
+ // JSON doesn't support comments.
+ ExpectParseFailureForJson(
+ "JsonWithComments", RECOMMENDED,
+ R"({
+ // This is a comment.
+ "fieldname1": 1
+ })");
+ // JSON spec says whitespace doesn't matter, so try a few spacings to be sure.
+ RunValidJsonTest(
+ "OneLineNoSpaces", RECOMMENDED,
+ "{\"optionalInt32\":1,\"optionalInt64\":2}",
+ R"(
+ optional_int32: 1
+ optional_int64: 2
+ )");
+ RunValidJsonTest(
+ "OneLineWithSpaces", RECOMMENDED,
+ "{ \"optionalInt32\" : 1 , \"optionalInt64\" : 2 }",
+ R"(
+ optional_int32: 1
+ optional_int64: 2
+ )");
+ RunValidJsonTest(
+ "MultilineNoSpaces", RECOMMENDED,
+ "{\n\"optionalInt32\"\n:\n1\n,\n\"optionalInt64\"\n:\n2\n}",
+ R"(
+ optional_int32: 1
+ optional_int64: 2
+ )");
+ RunValidJsonTest(
+ "MultilineWithSpaces", RECOMMENDED,
+ "{\n \"optionalInt32\" : 1\n ,\n \"optionalInt64\" : 2\n}\n",
+ R"(
+ optional_int32: 1
+ optional_int64: 2
+ )");
+ // Missing comma between key/value pairs.
+ ExpectParseFailureForJson(
+ "MissingCommaOneLine", RECOMMENDED,
+ "{ \"optionalInt32\": 1 \"optionalInt64\": 2 }");
+ ExpectParseFailureForJson(
+ "MissingCommaMultiline", RECOMMENDED,
+ "{\n \"optionalInt32\": 1\n \"optionalInt64\": 2\n}");
+ // Duplicated field names are not allowed.
+ ExpectParseFailureForJson(
+ "FieldNameDuplicate", RECOMMENDED,
+ R"({
+ "optionalNestedMessage": {a: 1},
+ "optionalNestedMessage": {}
+ })");
+ ExpectParseFailureForJson(
+ "FieldNameDuplicateDifferentCasing1", RECOMMENDED,
+ R"({
+ "optional_nested_message": {a: 1},
+ "optionalNestedMessage": {}
+ })");
+ ExpectParseFailureForJson(
+ "FieldNameDuplicateDifferentCasing2", RECOMMENDED,
+ R"({
+ "optionalNestedMessage": {a: 1},
+ "optional_nested_message": {}
+ })");
+ // Serializers should use lowerCamelCase by default.
+ RunValidJsonTestWithValidator(
+ "FieldNameInLowerCamelCase", REQUIRED,
+ R"({
+ "fieldname1": 1,
+ "fieldName2": 2,
+ "FieldName3": 3,
+ "fieldName4": 4
+ })",
+ [](const Json::Value& value) {
+ return value.isMember("fieldname1") &&
+ value.isMember("fieldName2") &&
+ value.isMember("FieldName3") &&
+ value.isMember("fieldName4");
+ });
+ RunValidJsonTestWithValidator(
+ "FieldNameWithNumbers", REQUIRED,
+ R"({
+ "field0name5": 5,
+ "field0Name6": 6
+ })",
+ [](const Json::Value& value) {
+ return value.isMember("field0name5") &&
+ value.isMember("field0Name6");
+ });
+ RunValidJsonTestWithValidator(
+ "FieldNameWithMixedCases", REQUIRED,
+ R"({
+ "fieldName7": 7,
+ "FieldName8": 8,
+ "fieldName9": 9,
+ "FieldName10": 10,
+ "FIELDNAME11": 11,
+ "FIELDName12": 12
+ })",
+ [](const Json::Value& value) {
+ return value.isMember("fieldName7") &&
+ value.isMember("FieldName8") &&
+ value.isMember("fieldName9") &&
+ value.isMember("FieldName10") &&
+ value.isMember("FIELDNAME11") &&
+ value.isMember("FIELDName12");
+ });
+ RunValidJsonTestWithValidator(
+ "FieldNameWithDoubleUnderscores", RECOMMENDED,
+ R"({
+ "FieldName13": 13,
+ "FieldName14": 14,
+ "fieldName15": 15,
+ "fieldName16": 16,
+ "fieldName17": 17,
+ "FieldName18": 18
+ })",
+ [](const Json::Value& value) {
+ return value.isMember("FieldName13") &&
+ value.isMember("FieldName14") &&
+ value.isMember("fieldName15") &&
+ value.isMember("fieldName16") &&
+ value.isMember("fieldName17") &&
+ value.isMember("FieldName18");
+ });
+
+ // Integer fields.
+ RunValidJsonTest(
+ "Int32FieldMaxValue", REQUIRED,
+ R"({"optionalInt32": 2147483647})",
+ "optional_int32: 2147483647");
+ RunValidJsonTest(
+ "Int32FieldMinValue", REQUIRED,
+ R"({"optionalInt32": -2147483648})",
+ "optional_int32: -2147483648");
+ RunValidJsonTest(
+ "Uint32FieldMaxValue", REQUIRED,
+ R"({"optionalUint32": 4294967295})",
+ "optional_uint32: 4294967295");
+ RunValidJsonTest(
+ "Int64FieldMaxValue", REQUIRED,
+ R"({"optionalInt64": "9223372036854775807"})",
+ "optional_int64: 9223372036854775807");
+ RunValidJsonTest(
+ "Int64FieldMinValue", REQUIRED,
+ R"({"optionalInt64": "-9223372036854775808"})",
+ "optional_int64: -9223372036854775808");
+ RunValidJsonTest(
+ "Uint64FieldMaxValue", REQUIRED,
+ R"({"optionalUint64": "18446744073709551615"})",
+ "optional_uint64: 18446744073709551615");
+ // While not the largest Int64, this is the largest
+ // Int64 which can be exactly represented within an
+ // IEEE-754 64-bit float, which is the expected level
+ // of interoperability guarantee. Larger values may
+ // work in some implementations, but should not be
+ // relied upon.
+ RunValidJsonTest(
+ "Int64FieldMaxValueNotQuoted", REQUIRED,
+ R"({"optionalInt64": 9223372036854774784})",
+ "optional_int64: 9223372036854774784");
+ RunValidJsonTest(
+ "Int64FieldMinValueNotQuoted", REQUIRED,
+ R"({"optionalInt64": -9223372036854775808})",
+ "optional_int64: -9223372036854775808");
+ // Largest interoperable Uint64; see comment above
+ // for Int64FieldMaxValueNotQuoted.
+ RunValidJsonTest(
+ "Uint64FieldMaxValueNotQuoted", REQUIRED,
+ R"({"optionalUint64": 18446744073709549568})",
+ "optional_uint64: 18446744073709549568");
+ // Values can be represented as JSON strings.
+ RunValidJsonTest(
+ "Int32FieldStringValue", REQUIRED,
+ R"({"optionalInt32": "2147483647"})",
+ "optional_int32: 2147483647");
+ RunValidJsonTest(
+ "Int32FieldStringValueEscaped", REQUIRED,
+ R"({"optionalInt32": "2\u003147483647"})",
+ "optional_int32: 2147483647");
+
+ // Parsers reject out-of-bound integer values.
+ ExpectParseFailureForJson(
+ "Int32FieldTooLarge", REQUIRED,
+ R"({"optionalInt32": 2147483648})");
+ ExpectParseFailureForJson(
+ "Int32FieldTooSmall", REQUIRED,
+ R"({"optionalInt32": -2147483649})");
+ ExpectParseFailureForJson(
+ "Uint32FieldTooLarge", REQUIRED,
+ R"({"optionalUint32": 4294967296})");
+ ExpectParseFailureForJson(
+ "Int64FieldTooLarge", REQUIRED,
+ R"({"optionalInt64": "9223372036854775808"})");
+ ExpectParseFailureForJson(
+ "Int64FieldTooSmall", REQUIRED,
+ R"({"optionalInt64": "-9223372036854775809"})");
+ ExpectParseFailureForJson(
+ "Uint64FieldTooLarge", REQUIRED,
+ R"({"optionalUint64": "18446744073709551616"})");
+ // Parser reject non-integer numeric values as well.
+ ExpectParseFailureForJson(
+ "Int32FieldNotInteger", REQUIRED,
+ R"({"optionalInt32": 0.5})");
+ ExpectParseFailureForJson(
+ "Uint32FieldNotInteger", REQUIRED,
+ R"({"optionalUint32": 0.5})");
+ ExpectParseFailureForJson(
+ "Int64FieldNotInteger", REQUIRED,
+ R"({"optionalInt64": "0.5"})");
+ ExpectParseFailureForJson(
+ "Uint64FieldNotInteger", REQUIRED,
+ R"({"optionalUint64": "0.5"})");
+
+ // Integers but represented as float values are accepted.
+ RunValidJsonTest(
+ "Int32FieldFloatTrailingZero", REQUIRED,
+ R"({"optionalInt32": 100000.000})",
+ "optional_int32: 100000");
+ RunValidJsonTest(
+ "Int32FieldExponentialFormat", REQUIRED,
+ R"({"optionalInt32": 1e5})",
+ "optional_int32: 100000");
+ RunValidJsonTest(
+ "Int32FieldMaxFloatValue", REQUIRED,
+ R"({"optionalInt32": 2.147483647e9})",
+ "optional_int32: 2147483647");
+ RunValidJsonTest(
+ "Int32FieldMinFloatValue", REQUIRED,
+ R"({"optionalInt32": -2.147483648e9})",
+ "optional_int32: -2147483648");
+ RunValidJsonTest(
+ "Uint32FieldMaxFloatValue", REQUIRED,
+ R"({"optionalUint32": 4.294967295e9})",
+ "optional_uint32: 4294967295");
+
+ // Parser reject non-numeric values.
+ ExpectParseFailureForJson(
+ "Int32FieldNotNumber", REQUIRED,
+ R"({"optionalInt32": "3x3"})");
+ ExpectParseFailureForJson(
+ "Uint32FieldNotNumber", REQUIRED,
+ R"({"optionalUint32": "3x3"})");
+ ExpectParseFailureForJson(
+ "Int64FieldNotNumber", REQUIRED,
+ R"({"optionalInt64": "3x3"})");
+ ExpectParseFailureForJson(
+ "Uint64FieldNotNumber", REQUIRED,
+ R"({"optionalUint64": "3x3"})");
+ // JSON does not allow "+" on numric values.
+ ExpectParseFailureForJson(
+ "Int32FieldPlusSign", REQUIRED,
+ R"({"optionalInt32": +1})");
+ // JSON doesn't allow leading 0s.
+ ExpectParseFailureForJson(
+ "Int32FieldLeadingZero", REQUIRED,
+ R"({"optionalInt32": 01})");
+ ExpectParseFailureForJson(
+ "Int32FieldNegativeWithLeadingZero", REQUIRED,
+ R"({"optionalInt32": -01})");
+ // String values must follow the same syntax rule. Specifically leading
+ // or traling spaces are not allowed.
+ ExpectParseFailureForJson(
+ "Int32FieldLeadingSpace", REQUIRED,
+ R"({"optionalInt32": " 1"})");
+ ExpectParseFailureForJson(
+ "Int32FieldTrailingSpace", REQUIRED,
+ R"({"optionalInt32": "1 "})");
+
+ // 64-bit values are serialized as strings.
+ RunValidJsonTestWithValidator(
+ "Int64FieldBeString", RECOMMENDED,
+ R"({"optionalInt64": 1})",
+ [](const Json::Value& value) {
+ return value["optionalInt64"].type() == Json::stringValue &&
+ value["optionalInt64"].asString() == "1";
+ });
+ RunValidJsonTestWithValidator(
+ "Uint64FieldBeString", RECOMMENDED,
+ R"({"optionalUint64": 1})",
+ [](const Json::Value& value) {
+ return value["optionalUint64"].type() == Json::stringValue &&
+ value["optionalUint64"].asString() == "1";
+ });
+
+ // Bool fields.
+ RunValidJsonTest(
+ "BoolFieldTrue", REQUIRED,
+ R"({"optionalBool":true})",
+ "optional_bool: true");
+ RunValidJsonTest(
+ "BoolFieldFalse", REQUIRED,
+ R"({"optionalBool":false})",
+ "optional_bool: false");
+
+ // Other forms are not allowed.
+ ExpectParseFailureForJson(
+ "BoolFieldIntegerZero", RECOMMENDED,
+ R"({"optionalBool":0})");
+ ExpectParseFailureForJson(
+ "BoolFieldIntegerOne", RECOMMENDED,
+ R"({"optionalBool":1})");
+ ExpectParseFailureForJson(
+ "BoolFieldCamelCaseTrue", RECOMMENDED,
+ R"({"optionalBool":True})");
+ ExpectParseFailureForJson(
+ "BoolFieldCamelCaseFalse", RECOMMENDED,
+ R"({"optionalBool":False})");
+ ExpectParseFailureForJson(
+ "BoolFieldAllCapitalTrue", RECOMMENDED,
+ R"({"optionalBool":TRUE})");
+ ExpectParseFailureForJson(
+ "BoolFieldAllCapitalFalse", RECOMMENDED,
+ R"({"optionalBool":FALSE})");
+ ExpectParseFailureForJson(
+ "BoolFieldDoubleQuotedTrue", RECOMMENDED,
+ R"({"optionalBool":"true"})");
+ ExpectParseFailureForJson(
+ "BoolFieldDoubleQuotedFalse", RECOMMENDED,
+ R"({"optionalBool":"false"})");
+
+ // Float fields.
+ RunValidJsonTest(
+ "FloatFieldMinPositiveValue", REQUIRED,
+ R"({"optionalFloat": 1.175494e-38})",
+ "optional_float: 1.175494e-38");
+ RunValidJsonTest(
+ "FloatFieldMaxNegativeValue", REQUIRED,
+ R"({"optionalFloat": -1.175494e-38})",
+ "optional_float: -1.175494e-38");
+ RunValidJsonTest(
+ "FloatFieldMaxPositiveValue", REQUIRED,
+ R"({"optionalFloat": 3.402823e+38})",
+ "optional_float: 3.402823e+38");
+ RunValidJsonTest(
+ "FloatFieldMinNegativeValue", REQUIRED,
+ R"({"optionalFloat": 3.402823e+38})",
+ "optional_float: 3.402823e+38");
+ // Values can be quoted.
+ RunValidJsonTest(
+ "FloatFieldQuotedValue", REQUIRED,
+ R"({"optionalFloat": "1"})",
+ "optional_float: 1");
+ // Special values.
+ RunValidJsonTest(
+ "FloatFieldNan", REQUIRED,
+ R"({"optionalFloat": "NaN"})",
+ "optional_float: nan");
+ RunValidJsonTest(
+ "FloatFieldInfinity", REQUIRED,
+ R"({"optionalFloat": "Infinity"})",
+ "optional_float: inf");
+ RunValidJsonTest(
+ "FloatFieldNegativeInfinity", REQUIRED,
+ R"({"optionalFloat": "-Infinity"})",
+ "optional_float: -inf");
+ // Non-cannonical Nan will be correctly normalized.
+ {
+ TestAllTypes message;
+ // IEEE floating-point standard 32-bit quiet NaN:
+ // 0111 1111 1xxx xxxx xxxx xxxx xxxx xxxx
+ message.set_optional_float(
+ WireFormatLite::DecodeFloat(0x7FA12345));
+ RunValidJsonTestWithProtobufInput(
+ "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", REQUIRED, message,
+ "optional_float: nan");
+ }
+
+ // Special values must be quoted.
+ ExpectParseFailureForJson(
+ "FloatFieldNanNotQuoted", RECOMMENDED,
+ R"({"optionalFloat": NaN})");
+ ExpectParseFailureForJson(
+ "FloatFieldInfinityNotQuoted", RECOMMENDED,
+ R"({"optionalFloat": Infinity})");
+ ExpectParseFailureForJson(
+ "FloatFieldNegativeInfinityNotQuoted", RECOMMENDED,
+ R"({"optionalFloat": -Infinity})");
+ // Parsers should reject out-of-bound values.
+ ExpectParseFailureForJson(
+ "FloatFieldTooSmall", REQUIRED,
+ R"({"optionalFloat": -3.502823e+38})");
+ ExpectParseFailureForJson(
+ "FloatFieldTooLarge", REQUIRED,
+ R"({"optionalFloat": 3.502823e+38})");
+
+ // Double fields.
+ RunValidJsonTest(
+ "DoubleFieldMinPositiveValue", REQUIRED,
+ R"({"optionalDouble": 2.22507e-308})",
+ "optional_double: 2.22507e-308");
+ RunValidJsonTest(
+ "DoubleFieldMaxNegativeValue", REQUIRED,
+ R"({"optionalDouble": -2.22507e-308})",
+ "optional_double: -2.22507e-308");
+ RunValidJsonTest(
+ "DoubleFieldMaxPositiveValue", REQUIRED,
+ R"({"optionalDouble": 1.79769e+308})",
+ "optional_double: 1.79769e+308");
+ RunValidJsonTest(
+ "DoubleFieldMinNegativeValue", REQUIRED,
+ R"({"optionalDouble": -1.79769e+308})",
+ "optional_double: -1.79769e+308");
+ // Values can be quoted.
+ RunValidJsonTest(
+ "DoubleFieldQuotedValue", REQUIRED,
+ R"({"optionalDouble": "1"})",
+ "optional_double: 1");
+ // Speical values.
+ RunValidJsonTest(
+ "DoubleFieldNan", REQUIRED,
+ R"({"optionalDouble": "NaN"})",
+ "optional_double: nan");
+ RunValidJsonTest(
+ "DoubleFieldInfinity", REQUIRED,
+ R"({"optionalDouble": "Infinity"})",
+ "optional_double: inf");
+ RunValidJsonTest(
+ "DoubleFieldNegativeInfinity", REQUIRED,
+ R"({"optionalDouble": "-Infinity"})",
+ "optional_double: -inf");
+ // Non-cannonical Nan will be correctly normalized.
+ {
+ TestAllTypes message;
+ message.set_optional_double(
+ WireFormatLite::DecodeDouble(0x7FFA123456789ABCLL));
+ RunValidJsonTestWithProtobufInput(
+ "DoubleFieldNormalizeQuietNan", REQUIRED, message,
+ "optional_double: nan");
+ message.set_optional_double(
+ WireFormatLite::DecodeDouble(0xFFFBCBA987654321LL));
+ RunValidJsonTestWithProtobufInput(
+ "DoubleFieldNormalizeSignalingNan", REQUIRED, message,
+ "optional_double: nan");
+ }
+
+ // Special values must be quoted.
+ ExpectParseFailureForJson(
+ "DoubleFieldNanNotQuoted", RECOMMENDED,
+ R"({"optionalDouble": NaN})");
+ ExpectParseFailureForJson(
+ "DoubleFieldInfinityNotQuoted", RECOMMENDED,
+ R"({"optionalDouble": Infinity})");
+ ExpectParseFailureForJson(
+ "DoubleFieldNegativeInfinityNotQuoted", RECOMMENDED,
+ R"({"optionalDouble": -Infinity})");
+
+ // Parsers should reject out-of-bound values.
+ ExpectParseFailureForJson(
+ "DoubleFieldTooSmall", REQUIRED,
+ R"({"optionalDouble": -1.89769e+308})");
+ ExpectParseFailureForJson(
+ "DoubleFieldTooLarge", REQUIRED,
+ R"({"optionalDouble": +1.89769e+308})");
+
+ // Enum fields.
+ RunValidJsonTest(
+ "EnumField", REQUIRED,
+ R"({"optionalNestedEnum": "FOO"})",
+ "optional_nested_enum: FOO");
+ // Enum values must be represented as strings.
+ ExpectParseFailureForJson(
+ "EnumFieldNotQuoted", REQUIRED,
+ R"({"optionalNestedEnum": FOO})");
+ // Numeric values are allowed.
+ RunValidJsonTest(
+ "EnumFieldNumericValueZero", REQUIRED,
+ R"({"optionalNestedEnum": 0})",
+ "optional_nested_enum: FOO");
+ RunValidJsonTest(
+ "EnumFieldNumericValueNonZero", REQUIRED,
+ R"({"optionalNestedEnum": 1})",
+ "optional_nested_enum: BAR");
+ // Unknown enum values are represented as numeric values.
+ RunValidJsonTestWithValidator(
+ "EnumFieldUnknownValue", REQUIRED,
+ R"({"optionalNestedEnum": 123})",
+ [](const Json::Value& value) {
+ return value["optionalNestedEnum"].type() == Json::intValue &&
+ value["optionalNestedEnum"].asInt() == 123;
+ });
+
+ // String fields.
+ RunValidJsonTest(
+ "StringField", REQUIRED,
+ R"({"optionalString": "Hello world!"})",
+ "optional_string: \"Hello world!\"");
+ RunValidJsonTest(
+ "StringFieldUnicode", REQUIRED,
+ // Google in Chinese.
+ R"({"optionalString": "谷歌"})",
+ R"(optional_string: "谷歌")");
+ RunValidJsonTest(
+ "StringFieldEscape", REQUIRED,
+ R"({"optionalString": "\"\\\/\b\f\n\r\t"})",
+ R"(optional_string: "\"\\/\b\f\n\r\t")");
+ RunValidJsonTest(
+ "StringFieldUnicodeEscape", REQUIRED,
+ R"({"optionalString": "\u8C37\u6B4C"})",
+ R"(optional_string: "谷歌")");
+ RunValidJsonTest(
+ "StringFieldUnicodeEscapeWithLowercaseHexLetters", REQUIRED,
+ R"({"optionalString": "\u8c37\u6b4c"})",
+ R"(optional_string: "谷歌")");
+ RunValidJsonTest(
+ "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", RECOMMENDED,
+ R"({"optionalString": "\U8C37\U6b4C"})");
+ ExpectParseFailureForJson(
+ "StringFieldInvalidEscape", RECOMMENDED,
+ R"({"optionalString": "\uXXXX\u6B4C"})");
+ ExpectParseFailureForJson(
+ "StringFieldUnterminatedEscape", RECOMMENDED,
+ R"({"optionalString": "\u8C3"})");
+ ExpectParseFailureForJson(
+ "StringFieldUnpairedHighSurrogate", RECOMMENDED,
+ R"({"optionalString": "\uD800"})");
+ ExpectParseFailureForJson(
+ "StringFieldUnpairedLowSurrogate", RECOMMENDED,
+ R"({"optionalString": "\uDC00"})");
+ ExpectParseFailureForJson(
+ "StringFieldSurrogateInWrongOrder", RECOMMENDED,
+ R"({"optionalString": "\uDE01\uD83D"})");
+ ExpectParseFailureForJson(
+ "StringFieldNotAString", REQUIRED,
+ R"({"optionalString": 12345})");
+
+ // Bytes fields.
+ RunValidJsonTest(
+ "BytesField", REQUIRED,
+ R"({"optionalBytes": "AQI="})",
+ R"(optional_bytes: "\x01\x02")");
+ ExpectParseFailureForJson(
+ "BytesFieldInvalidBase64Characters", REQUIRED,
+ R"({"optionalBytes": "-_=="})");
+
+ // Message fields.
+ RunValidJsonTest(
+ "MessageField", REQUIRED,
+ R"({"optionalNestedMessage": {"a": 1234}})",
+ "optional_nested_message: {a: 1234}");
+
+ // Oneof fields.
+ ExpectParseFailureForJson(
+ "OneofFieldDuplicate", REQUIRED,
+ R"({"oneofUint32": 1, "oneofString": "test"})");
+ // Ensure zero values for oneof make it out/backs.
+ {
+ TestAllTypes message;
+ message.set_oneof_uint32(0);
+ RunValidProtobufTestWithMessage(
+ "OneofZeroUint32", RECOMMENDED, message, "oneof_uint32: 0");
+ message.mutable_oneof_nested_message()->set_a(0);
+ RunValidProtobufTestWithMessage(
+ "OneofZeroMessage", RECOMMENDED, message, "oneof_nested_message: {}");
+ message.set_oneof_string("");
+ RunValidProtobufTestWithMessage(
+ "OneofZeroString", RECOMMENDED, message, "oneof_string: \"\"");
+ message.set_oneof_bytes("");
+ RunValidProtobufTestWithMessage(
+ "OneofZeroBytes", RECOMMENDED, message, "oneof_bytes: \"\"");
+ message.set_oneof_bool(false);
+ RunValidProtobufTestWithMessage(
+ "OneofZeroBool", RECOMMENDED, message, "oneof_bool: false");
+ message.set_oneof_uint64(0);
+ RunValidProtobufTestWithMessage(
+ "OneofZeroUint64", RECOMMENDED, message, "oneof_uint64: 0");
+ message.set_oneof_float(0.0f);
+ RunValidProtobufTestWithMessage(
+ "OneofZeroFloat", RECOMMENDED, message, "oneof_float: 0");
+ message.set_oneof_double(0.0);
+ RunValidProtobufTestWithMessage(
+ "OneofZeroDouble", RECOMMENDED, message, "oneof_double: 0");
+ message.set_oneof_enum(TestAllTypes::FOO);
+ RunValidProtobufTestWithMessage(
+ "OneofZeroEnum", RECOMMENDED, message, "oneof_enum: FOO");
+ }
+ RunValidJsonTest(
+ "OneofZeroUint32", RECOMMENDED,
+ R"({"oneofUint32": 0})", "oneof_uint32: 0");
+ RunValidJsonTest(
+ "OneofZeroMessage", RECOMMENDED,
+ R"({"oneofNestedMessage": {}})", "oneof_nested_message: {}");
+ RunValidJsonTest(
+ "OneofZeroString", RECOMMENDED,
+ R"({"oneofString": ""})", "oneof_string: \"\"");
+ RunValidJsonTest(
+ "OneofZeroBytes", RECOMMENDED,
+ R"({"oneofBytes": ""})", "oneof_bytes: \"\"");
+ RunValidJsonTest(
+ "OneofZeroBool", RECOMMENDED,
+ R"({"oneofBool": false})", "oneof_bool: false");
+ RunValidJsonTest(
+ "OneofZeroUint64", RECOMMENDED,
+ R"({"oneofUint64": 0})", "oneof_uint64: 0");
+ RunValidJsonTest(
+ "OneofZeroFloat", RECOMMENDED,
+ R"({"oneofFloat": 0.0})", "oneof_float: 0");
+ RunValidJsonTest(
+ "OneofZeroDouble", RECOMMENDED,
+ R"({"oneofDouble": 0.0})", "oneof_double: 0");
+ RunValidJsonTest(
+ "OneofZeroEnum", RECOMMENDED,
+ R"({"oneofEnum":"FOO"})", "oneof_enum: FOO");
+
+ // Repeated fields.
+ RunValidJsonTest(
+ "PrimitiveRepeatedField", REQUIRED,
+ R"({"repeatedInt32": [1, 2, 3, 4]})",
+ "repeated_int32: [1, 2, 3, 4]");
+ RunValidJsonTest(
+ "EnumRepeatedField", REQUIRED,
+ R"({"repeatedNestedEnum": ["FOO", "BAR", "BAZ"]})",
+ "repeated_nested_enum: [FOO, BAR, BAZ]");
+ RunValidJsonTest(
+ "StringRepeatedField", REQUIRED,
+ R"({"repeatedString": ["Hello", "world"]})",
+ R"(repeated_string: ["Hello", "world"])");
+ RunValidJsonTest(
+ "BytesRepeatedField", REQUIRED,
+ R"({"repeatedBytes": ["AAEC", "AQI="]})",
+ R"(repeated_bytes: ["\x00\x01\x02", "\x01\x02"])");
+ RunValidJsonTest(
+ "MessageRepeatedField", REQUIRED,
+ R"({"repeatedNestedMessage": [{"a": 1234}, {"a": 5678}]})",
+ "repeated_nested_message: {a: 1234}"
+ "repeated_nested_message: {a: 5678}");
+
+ // Repeated field elements are of incorrect type.
+ ExpectParseFailureForJson(
+ "RepeatedFieldWrongElementTypeExpectingIntegersGotBool", REQUIRED,
+ R"({"repeatedInt32": [1, false, 3, 4]})");
+ ExpectParseFailureForJson(
+ "RepeatedFieldWrongElementTypeExpectingIntegersGotString", REQUIRED,
+ R"({"repeatedInt32": [1, 2, "name", 4]})");
+ ExpectParseFailureForJson(
+ "RepeatedFieldWrongElementTypeExpectingIntegersGotMessage", REQUIRED,
+ R"({"repeatedInt32": [1, 2, 3, {"a": 4}]})");
+ ExpectParseFailureForJson(
+ "RepeatedFieldWrongElementTypeExpectingStringsGotInt", REQUIRED,
+ R"({"repeatedString": ["1", 2, "3", "4"]})");
+ ExpectParseFailureForJson(
+ "RepeatedFieldWrongElementTypeExpectingStringsGotBool", REQUIRED,
+ R"({"repeatedString": ["1", "2", false, "4"]})");
+ ExpectParseFailureForJson(
+ "RepeatedFieldWrongElementTypeExpectingStringsGotMessage", REQUIRED,
+ R"({"repeatedString": ["1", 2, "3", {"a": 4}]})");
+ ExpectParseFailureForJson(
+ "RepeatedFieldWrongElementTypeExpectingMessagesGotInt", REQUIRED,
+ R"({"repeatedNestedMessage": [{"a": 1}, 2]})");
+ ExpectParseFailureForJson(
+ "RepeatedFieldWrongElementTypeExpectingMessagesGotBool", REQUIRED,
+ R"({"repeatedNestedMessage": [{"a": 1}, false]})");
+ ExpectParseFailureForJson(
+ "RepeatedFieldWrongElementTypeExpectingMessagesGotString", REQUIRED,
+ R"({"repeatedNestedMessage": [{"a": 1}, "2"]})");
+ // Trailing comma in the repeated field is not allowed.
+ ExpectParseFailureForJson(
+ "RepeatedFieldTrailingComma", RECOMMENDED,
+ R"({"repeatedInt32": [1, 2, 3, 4,]})");
+ ExpectParseFailureForJson(
+ "RepeatedFieldTrailingCommaWithSpace", RECOMMENDED,
+ "{\"repeatedInt32\": [1, 2, 3, 4 ,]}");
+ ExpectParseFailureForJson(
+ "RepeatedFieldTrailingCommaWithSpaceCommaSpace", RECOMMENDED,
+ "{\"repeatedInt32\": [1, 2, 3, 4 , ]}");
+ ExpectParseFailureForJson(
+ "RepeatedFieldTrailingCommaWithNewlines", RECOMMENDED,
+ "{\"repeatedInt32\": [\n 1,\n 2,\n 3,\n 4,\n]}");
+
+ // Map fields.
+ RunValidJsonTest(
+ "Int32MapField", REQUIRED,
+ R"({"mapInt32Int32": {"1": 2, "3": 4}})",
+ "map_int32_int32: {key: 1 value: 2}"
+ "map_int32_int32: {key: 3 value: 4}");
+ ExpectParseFailureForJson(
+ "Int32MapFieldKeyNotQuoted", RECOMMENDED,
+ R"({"mapInt32Int32": {1: 2, 3: 4}})");
+ RunValidJsonTest(
+ "Uint32MapField", REQUIRED,
+ R"({"mapUint32Uint32": {"1": 2, "3": 4}})",
+ "map_uint32_uint32: {key: 1 value: 2}"
+ "map_uint32_uint32: {key: 3 value: 4}");
+ ExpectParseFailureForJson(
+ "Uint32MapFieldKeyNotQuoted", RECOMMENDED,
+ R"({"mapUint32Uint32": {1: 2, 3: 4}})");
+ RunValidJsonTest(
+ "Int64MapField", REQUIRED,
+ R"({"mapInt64Int64": {"1": 2, "3": 4}})",
+ "map_int64_int64: {key: 1 value: 2}"
+ "map_int64_int64: {key: 3 value: 4}");
+ ExpectParseFailureForJson(
+ "Int64MapFieldKeyNotQuoted", RECOMMENDED,
+ R"({"mapInt64Int64": {1: 2, 3: 4}})");
+ RunValidJsonTest(
+ "Uint64MapField", REQUIRED,
+ R"({"mapUint64Uint64": {"1": 2, "3": 4}})",
+ "map_uint64_uint64: {key: 1 value: 2}"
+ "map_uint64_uint64: {key: 3 value: 4}");
+ ExpectParseFailureForJson(
+ "Uint64MapFieldKeyNotQuoted", RECOMMENDED,
+ R"({"mapUint64Uint64": {1: 2, 3: 4}})");
+ RunValidJsonTest(
+ "BoolMapField", REQUIRED,
+ R"({"mapBoolBool": {"true": true, "false": false}})",
+ "map_bool_bool: {key: true value: true}"
+ "map_bool_bool: {key: false value: false}");
+ ExpectParseFailureForJson(
+ "BoolMapFieldKeyNotQuoted", RECOMMENDED,
+ R"({"mapBoolBool": {true: true, false: false}})");
+ RunValidJsonTest(
+ "MessageMapField", REQUIRED,
+ R"({
+ "mapStringNestedMessage": {
+ "hello": {"a": 1234},
+ "world": {"a": 5678}
+ }
+ })",
+ R"(
+ map_string_nested_message: {
+ key: "hello"
+ value: {a: 1234}
+ }
+ map_string_nested_message: {
+ key: "world"
+ value: {a: 5678}
+ }
+ )");
+ // Since Map keys are represented as JSON strings, escaping should be allowed.
+ RunValidJsonTest(
+ "Int32MapEscapedKey", REQUIRED,
+ R"({"mapInt32Int32": {"\u0031": 2}})",
+ "map_int32_int32: {key: 1 value: 2}");
+ RunValidJsonTest(
+ "Int64MapEscapedKey", REQUIRED,
+ R"({"mapInt64Int64": {"\u0031": 2}})",
+ "map_int64_int64: {key: 1 value: 2}");
+ RunValidJsonTest(
+ "BoolMapEscapedKey", REQUIRED,
+ R"({"mapBoolBool": {"tr\u0075e": true}})",
+ "map_bool_bool: {key: true value: true}");
+
+ // "null" is accepted for all fields types.
+ RunValidJsonTest(
+ "AllFieldAcceptNull", REQUIRED,
+ R"({
+ "optionalInt32": null,
+ "optionalInt64": null,
+ "optionalUint32": null,
+ "optionalUint64": null,
+ "optionalBool": null,
+ "optionalString": null,
+ "optionalBytes": null,
+ "optionalNestedEnum": null,
+ "optionalNestedMessage": null,
+ "repeatedInt32": null,
+ "repeatedInt64": null,
+ "repeatedUint32": null,
+ "repeatedUint64": null,
+ "repeatedBool": null,
+ "repeatedString": null,
+ "repeatedBytes": null,
+ "repeatedNestedEnum": null,
+ "repeatedNestedMessage": null,
+ "mapInt32Int32": null,
+ "mapBoolBool": null,
+ "mapStringNestedMessage": null
+ })",
+ "");
+
+ // Repeated field elements cannot be null.
+ ExpectParseFailureForJson(
+ "RepeatedFieldPrimitiveElementIsNull", RECOMMENDED,
+ R"({"repeatedInt32": [1, null, 2]})");
+ ExpectParseFailureForJson(
+ "RepeatedFieldMessageElementIsNull", RECOMMENDED,
+ R"({"repeatedNestedMessage": [{"a":1}, null, {"a":2}]})");
+ // Map field keys cannot be null.
+ ExpectParseFailureForJson(
+ "MapFieldKeyIsNull", RECOMMENDED,
+ R"({"mapInt32Int32": {null: 1}})");
+ // Map field values cannot be null.
+ ExpectParseFailureForJson(
+ "MapFieldValueIsNull", RECOMMENDED,
+ R"({"mapInt32Int32": {"0": null}})");
+
+ // http://www.rfc-editor.org/rfc/rfc7159.txt says strings have to use double
+ // quotes.
+ ExpectParseFailureForJson(
+ "StringFieldSingleQuoteKey", RECOMMENDED,
+ R"({'optionalString': "Hello world!"})");
+ ExpectParseFailureForJson(
+ "StringFieldSingleQuoteValue", RECOMMENDED,
+ R"({"optionalString": 'Hello world!'})");
+ ExpectParseFailureForJson(
+ "StringFieldSingleQuoteBoth", RECOMMENDED,
+ R"({'optionalString': 'Hello world!'})");
+
+ // Wrapper types.
+ RunValidJsonTest(
+ "OptionalBoolWrapper", REQUIRED,
+ R"({"optionalBoolWrapper": false})",
+ "optional_bool_wrapper: {value: false}");
+ RunValidJsonTest(
+ "OptionalInt32Wrapper", REQUIRED,
+ R"({"optionalInt32Wrapper": 0})",
+ "optional_int32_wrapper: {value: 0}");
+ RunValidJsonTest(
+ "OptionalUint32Wrapper", REQUIRED,
+ R"({"optionalUint32Wrapper": 0})",
+ "optional_uint32_wrapper: {value: 0}");
+ RunValidJsonTest(
+ "OptionalInt64Wrapper", REQUIRED,
+ R"({"optionalInt64Wrapper": 0})",
+ "optional_int64_wrapper: {value: 0}");
+ RunValidJsonTest(
+ "OptionalUint64Wrapper", REQUIRED,
+ R"({"optionalUint64Wrapper": 0})",
+ "optional_uint64_wrapper: {value: 0}");
+ RunValidJsonTest(
+ "OptionalFloatWrapper", REQUIRED,
+ R"({"optionalFloatWrapper": 0})",
+ "optional_float_wrapper: {value: 0}");
+ RunValidJsonTest(
+ "OptionalDoubleWrapper", REQUIRED,
+ R"({"optionalDoubleWrapper": 0})",
+ "optional_double_wrapper: {value: 0}");
+ RunValidJsonTest(
+ "OptionalStringWrapper", REQUIRED,
+ R"({"optionalStringWrapper": ""})",
+ R"(optional_string_wrapper: {value: ""})");
+ RunValidJsonTest(
+ "OptionalBytesWrapper", REQUIRED,
+ R"({"optionalBytesWrapper": ""})",
+ R"(optional_bytes_wrapper: {value: ""})");
+ RunValidJsonTest(
+ "OptionalWrapperTypesWithNonDefaultValue", REQUIRED,
+ R"({
+ "optionalBoolWrapper": true,
+ "optionalInt32Wrapper": 1,
+ "optionalUint32Wrapper": 1,
+ "optionalInt64Wrapper": "1",
+ "optionalUint64Wrapper": "1",
+ "optionalFloatWrapper": 1,
+ "optionalDoubleWrapper": 1,
+ "optionalStringWrapper": "1",
+ "optionalBytesWrapper": "AQI="
+ })",
+ R"(
+ optional_bool_wrapper: {value: true}
+ optional_int32_wrapper: {value: 1}
+ optional_uint32_wrapper: {value: 1}
+ optional_int64_wrapper: {value: 1}
+ optional_uint64_wrapper: {value: 1}
+ optional_float_wrapper: {value: 1}
+ optional_double_wrapper: {value: 1}
+ optional_string_wrapper: {value: "1"}
+ optional_bytes_wrapper: {value: "\x01\x02"}
+ )");
+ RunValidJsonTest(
+ "RepeatedBoolWrapper", REQUIRED,
+ R"({"repeatedBoolWrapper": [true, false]})",
+ "repeated_bool_wrapper: {value: true}"
+ "repeated_bool_wrapper: {value: false}");
+ RunValidJsonTest(
+ "RepeatedInt32Wrapper", REQUIRED,
+ R"({"repeatedInt32Wrapper": [0, 1]})",
+ "repeated_int32_wrapper: {value: 0}"
+ "repeated_int32_wrapper: {value: 1}");
+ RunValidJsonTest(
+ "RepeatedUint32Wrapper", REQUIRED,
+ R"({"repeatedUint32Wrapper": [0, 1]})",
+ "repeated_uint32_wrapper: {value: 0}"
+ "repeated_uint32_wrapper: {value: 1}");
+ RunValidJsonTest(
+ "RepeatedInt64Wrapper", REQUIRED,
+ R"({"repeatedInt64Wrapper": [0, 1]})",
+ "repeated_int64_wrapper: {value: 0}"
+ "repeated_int64_wrapper: {value: 1}");
+ RunValidJsonTest(
+ "RepeatedUint64Wrapper", REQUIRED,
+ R"({"repeatedUint64Wrapper": [0, 1]})",
+ "repeated_uint64_wrapper: {value: 0}"
+ "repeated_uint64_wrapper: {value: 1}");
+ RunValidJsonTest(
+ "RepeatedFloatWrapper", REQUIRED,
+ R"({"repeatedFloatWrapper": [0, 1]})",
+ "repeated_float_wrapper: {value: 0}"
+ "repeated_float_wrapper: {value: 1}");
+ RunValidJsonTest(
+ "RepeatedDoubleWrapper", REQUIRED,
+ R"({"repeatedDoubleWrapper": [0, 1]})",
+ "repeated_double_wrapper: {value: 0}"
+ "repeated_double_wrapper: {value: 1}");
+ RunValidJsonTest(
+ "RepeatedStringWrapper", REQUIRED,
+ R"({"repeatedStringWrapper": ["", "AQI="]})",
+ R"(
+ repeated_string_wrapper: {value: ""}
+ repeated_string_wrapper: {value: "AQI="}
+ )");
+ RunValidJsonTest(
+ "RepeatedBytesWrapper", REQUIRED,
+ R"({"repeatedBytesWrapper": ["", "AQI="]})",
+ R"(
+ repeated_bytes_wrapper: {value: ""}
+ repeated_bytes_wrapper: {value: "\x01\x02"}
+ )");
+ RunValidJsonTest(
+ "WrapperTypesWithNullValue", REQUIRED,
+ R"({
+ "optionalBoolWrapper": null,
+ "optionalInt32Wrapper": null,
+ "optionalUint32Wrapper": null,
+ "optionalInt64Wrapper": null,
+ "optionalUint64Wrapper": null,
+ "optionalFloatWrapper": null,
+ "optionalDoubleWrapper": null,
+ "optionalStringWrapper": null,
+ "optionalBytesWrapper": null,
+ "repeatedBoolWrapper": null,
+ "repeatedInt32Wrapper": null,
+ "repeatedUint32Wrapper": null,
+ "repeatedInt64Wrapper": null,
+ "repeatedUint64Wrapper": null,
+ "repeatedFloatWrapper": null,
+ "repeatedDoubleWrapper": null,
+ "repeatedStringWrapper": null,
+ "repeatedBytesWrapper": null
+ })",
+ "");
+
+ // Duration
+ RunValidJsonTest(
+ "DurationMinValue", REQUIRED,
+ R"({"optionalDuration": "-315576000000.999999999s"})",
+ "optional_duration: {seconds: -315576000000 nanos: -999999999}");
+ RunValidJsonTest(
+ "DurationMaxValue", REQUIRED,
+ R"({"optionalDuration": "315576000000.999999999s"})",
+ "optional_duration: {seconds: 315576000000 nanos: 999999999}");
+ RunValidJsonTest(
+ "DurationRepeatedValue", REQUIRED,
+ R"({"repeatedDuration": ["1.5s", "-1.5s"]})",
+ "repeated_duration: {seconds: 1 nanos: 500000000}"
+ "repeated_duration: {seconds: -1 nanos: -500000000}");
+
+ ExpectParseFailureForJson(
+ "DurationMissingS", REQUIRED,
+ R"({"optionalDuration": "1"})");
+ ExpectParseFailureForJson(
+ "DurationJsonInputTooSmall", REQUIRED,
+ R"({"optionalDuration": "-315576000001.000000000s"})");
+ ExpectParseFailureForJson(
+ "DurationJsonInputTooLarge", REQUIRED,
+ R"({"optionalDuration": "315576000001.000000000s"})");
+ ExpectSerializeFailureForJson(
+ "DurationProtoInputTooSmall", REQUIRED,
+ "optional_duration: {seconds: -315576000001 nanos: 0}");
+ ExpectSerializeFailureForJson(
+ "DurationProtoInputTooLarge", REQUIRED,
+ "optional_duration: {seconds: 315576000001 nanos: 0}");
+
+ RunValidJsonTestWithValidator(
+ "DurationHasZeroFractionalDigit", RECOMMENDED,
+ R"({"optionalDuration": "1.000000000s"})",
+ [](const Json::Value& value) {
+ return value["optionalDuration"].asString() == "1s";
+ });
+ RunValidJsonTestWithValidator(
+ "DurationHas3FractionalDigits", RECOMMENDED,
+ R"({"optionalDuration": "1.010000000s"})",
+ [](const Json::Value& value) {
+ return value["optionalDuration"].asString() == "1.010s";
+ });
+ RunValidJsonTestWithValidator(
+ "DurationHas6FractionalDigits", RECOMMENDED,
+ R"({"optionalDuration": "1.000010000s"})",
+ [](const Json::Value& value) {
+ return value["optionalDuration"].asString() == "1.000010s";
+ });
+ RunValidJsonTestWithValidator(
+ "DurationHas9FractionalDigits", RECOMMENDED,
+ R"({"optionalDuration": "1.000000010s"})",
+ [](const Json::Value& value) {
+ return value["optionalDuration"].asString() == "1.000000010s";
+ });
+
+ // Timestamp
+ RunValidJsonTest(
+ "TimestampMinValue", REQUIRED,
+ R"({"optionalTimestamp": "0001-01-01T00:00:00Z"})",
+ "optional_timestamp: {seconds: -62135596800}");
+ RunValidJsonTest(
+ "TimestampMaxValue", REQUIRED,
+ R"({"optionalTimestamp": "9999-12-31T23:59:59.999999999Z"})",
+ "optional_timestamp: {seconds: 253402300799 nanos: 999999999}");
+ RunValidJsonTest(
+ "TimestampRepeatedValue", REQUIRED,
+ R"({
+ "repeatedTimestamp": [
+ "0001-01-01T00:00:00Z",
+ "9999-12-31T23:59:59.999999999Z"
+ ]
+ })",
+ "repeated_timestamp: {seconds: -62135596800}"
+ "repeated_timestamp: {seconds: 253402300799 nanos: 999999999}");
+ RunValidJsonTest(
+ "TimestampWithPositiveOffset", REQUIRED,
+ R"({"optionalTimestamp": "1970-01-01T08:00:00+08:00"})",
+ "optional_timestamp: {seconds: 0}");
+ RunValidJsonTest(
+ "TimestampWithNegativeOffset", REQUIRED,
+ R"({"optionalTimestamp": "1969-12-31T16:00:00-08:00"})",
+ "optional_timestamp: {seconds: 0}");
+
+ ExpectParseFailureForJson(
+ "TimestampJsonInputTooSmall", REQUIRED,
+ R"({"optionalTimestamp": "0000-01-01T00:00:00Z"})");
+ ExpectParseFailureForJson(
+ "TimestampJsonInputTooLarge", REQUIRED,
+ R"({"optionalTimestamp": "10000-01-01T00:00:00Z"})");
+ ExpectParseFailureForJson(
+ "TimestampJsonInputMissingZ", REQUIRED,
+ R"({"optionalTimestamp": "0001-01-01T00:00:00"})");
+ ExpectParseFailureForJson(
+ "TimestampJsonInputMissingT", REQUIRED,
+ R"({"optionalTimestamp": "0001-01-01 00:00:00Z"})");
+ ExpectParseFailureForJson(
+ "TimestampJsonInputLowercaseZ", REQUIRED,
+ R"({"optionalTimestamp": "0001-01-01T00:00:00z"})");
+ ExpectParseFailureForJson(
+ "TimestampJsonInputLowercaseT", REQUIRED,
+ R"({"optionalTimestamp": "0001-01-01t00:00:00Z"})");
+ ExpectSerializeFailureForJson(
+ "TimestampProtoInputTooSmall", REQUIRED,
+ "optional_timestamp: {seconds: -62135596801}");
+ ExpectSerializeFailureForJson(
+ "TimestampProtoInputTooLarge", REQUIRED,
+ "optional_timestamp: {seconds: 253402300800}");
+ RunValidJsonTestWithValidator(
+ "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", RECOMMENDED,
+ R"({"optionalTimestamp": "1970-01-01T00:00:00.000000000Z"})",
+ [](const Json::Value& value) {
+ return value["optionalTimestamp"].asString() ==
+ "1970-01-01T00:00:00Z";
+ });
+ RunValidJsonTestWithValidator(
+ "TimestampHas3FractionalDigits", RECOMMENDED,
+ R"({"optionalTimestamp": "1970-01-01T00:00:00.010000000Z"})",
+ [](const Json::Value& value) {
+ return value["optionalTimestamp"].asString() ==
+ "1970-01-01T00:00:00.010Z";
+ });
+ RunValidJsonTestWithValidator(
+ "TimestampHas6FractionalDigits", RECOMMENDED,
+ R"({"optionalTimestamp": "1970-01-01T00:00:00.000010000Z"})",
+ [](const Json::Value& value) {
+ return value["optionalTimestamp"].asString() ==
+ "1970-01-01T00:00:00.000010Z";
+ });
+ RunValidJsonTestWithValidator(
+ "TimestampHas9FractionalDigits", RECOMMENDED,
+ R"({"optionalTimestamp": "1970-01-01T00:00:00.000000010Z"})",
+ [](const Json::Value& value) {
+ return value["optionalTimestamp"].asString() ==
+ "1970-01-01T00:00:00.000000010Z";
+ });
+
+ // FieldMask
+ RunValidJsonTest(
+ "FieldMask", REQUIRED,
+ R"({"optionalFieldMask": "foo,barBaz"})",
+ R"(optional_field_mask: {paths: "foo" paths: "bar_baz"})");
+ ExpectParseFailureForJson(
+ "FieldMaskInvalidCharacter", RECOMMENDED,
+ R"({"optionalFieldMask": "foo,bar_bar"})");
+ ExpectSerializeFailureForJson(
+ "FieldMaskPathsDontRoundTrip", RECOMMENDED,
+ R"(optional_field_mask: {paths: "fooBar"})");
+ ExpectSerializeFailureForJson(
+ "FieldMaskNumbersDontRoundTrip", RECOMMENDED,
+ R"(optional_field_mask: {paths: "foo_3_bar"})");
+ ExpectSerializeFailureForJson(
+ "FieldMaskTooManyUnderscore", RECOMMENDED,
+ R"(optional_field_mask: {paths: "foo__bar"})");
+
+ // Struct
+ RunValidJsonTest(
+ "Struct", REQUIRED,
+ R"({
+ "optionalStruct": {
+ "nullValue": null,
+ "intValue": 1234,
+ "boolValue": true,
+ "doubleValue": 1234.5678,
+ "stringValue": "Hello world!",
+ "listValue": [1234, "5678"],
+ "objectValue": {
+ "value": 0
+ }
+ }
+ })",
+ R"(
+ optional_struct: {
+ fields: {
+ key: "nullValue"
+ value: {null_value: NULL_VALUE}
+ }
+ fields: {
+ key: "intValue"
+ value: {number_value: 1234}
+ }
+ fields: {
+ key: "boolValue"
+ value: {bool_value: true}
+ }
+ fields: {
+ key: "doubleValue"
+ value: {number_value: 1234.5678}
+ }
+ fields: {
+ key: "stringValue"
+ value: {string_value: "Hello world!"}
+ }
+ fields: {
+ key: "listValue"
+ value: {
+ list_value: {
+ values: {
+ number_value: 1234
+ }
+ values: {
+ string_value: "5678"
+ }
+ }
+ }
+ }
+ fields: {
+ key: "objectValue"
+ value: {
+ struct_value: {
+ fields: {
+ key: "value"
+ value: {
+ number_value: 0
+ }
+ }
+ }
+ }
+ }
+ }
+ )");
+ // Value
+ RunValidJsonTest(
+ "ValueAcceptInteger", REQUIRED,
+ R"({"optionalValue": 1})",
+ "optional_value: { number_value: 1}");
+ RunValidJsonTest(
+ "ValueAcceptFloat", REQUIRED,
+ R"({"optionalValue": 1.5})",
+ "optional_value: { number_value: 1.5}");
+ RunValidJsonTest(
+ "ValueAcceptBool", REQUIRED,
+ R"({"optionalValue": false})",
+ "optional_value: { bool_value: false}");
+ RunValidJsonTest(
+ "ValueAcceptNull", REQUIRED,
+ R"({"optionalValue": null})",
+ "optional_value: { null_value: NULL_VALUE}");
+ RunValidJsonTest(
+ "ValueAcceptString", REQUIRED,
+ R"({"optionalValue": "hello"})",
+ R"(optional_value: { string_value: "hello"})");
+ RunValidJsonTest(
+ "ValueAcceptList", REQUIRED,
+ R"({"optionalValue": [0, "hello"]})",
+ R"(
+ optional_value: {
+ list_value: {
+ values: {
+ number_value: 0
+ }
+ values: {
+ string_value: "hello"
+ }
+ }
+ }
+ )");
+ RunValidJsonTest(
+ "ValueAcceptObject", REQUIRED,
+ R"({"optionalValue": {"value": 1}})",
+ R"(
+ optional_value: {
+ struct_value: {
+ fields: {
+ key: "value"
+ value: {
+ number_value: 1
+ }
+ }
+ }
+ }
+ )");
+
+ // Any
+ RunValidJsonTest(
+ "Any", REQUIRED,
+ R"({
+ "optionalAny": {
+ "@type": "type.googleapis.com/protobuf_test_messages.proto3.TestAllTypes",
+ "optionalInt32": 12345
+ }
+ })",
+ R"(
+ optional_any: {
+ [type.googleapis.com/protobuf_test_messages.proto3.TestAllTypes] {
+ optional_int32: 12345
+ }
+ }
+ )");
+ RunValidJsonTest(
+ "AnyNested", REQUIRED,
+ R"({
+ "optionalAny": {
+ "@type": "type.googleapis.com/google.protobuf.Any",
+ "value": {
+ "@type": "type.googleapis.com/protobuf_test_messages.proto3.TestAllTypes",
+ "optionalInt32": 12345
+ }
+ }
+ })",
+ R"(
+ optional_any: {
+ [type.googleapis.com/google.protobuf.Any] {
+ [type.googleapis.com/protobuf_test_messages.proto3.TestAllTypes] {
+ optional_int32: 12345
+ }
+ }
+ }
+ )");
+ // The special "@type" tag is not required to appear first.
+ RunValidJsonTest(
+ "AnyUnorderedTypeTag", REQUIRED,
+ R"({
+ "optionalAny": {
+ "optionalInt32": 12345,
+ "@type": "type.googleapis.com/protobuf_test_messages.proto3.TestAllTypes"
+ }
+ })",
+ R"(
+ optional_any: {
+ [type.googleapis.com/protobuf_test_messages.proto3.TestAllTypes] {
+ optional_int32: 12345
+ }
+ }
+ )");
+ // Well-known types in Any.
+ RunValidJsonTest(
+ "AnyWithInt32ValueWrapper", REQUIRED,
+ R"({
+ "optionalAny": {
+ "@type": "type.googleapis.com/google.protobuf.Int32Value",
+ "value": 12345
+ }
+ })",
+ R"(
+ optional_any: {
+ [type.googleapis.com/google.protobuf.Int32Value] {
+ value: 12345
+ }
+ }
+ )");
+ RunValidJsonTest(
+ "AnyWithDuration", REQUIRED,
+ R"({
+ "optionalAny": {
+ "@type": "type.googleapis.com/google.protobuf.Duration",
+ "value": "1.5s"
+ }
+ })",
+ R"(
+ optional_any: {
+ [type.googleapis.com/google.protobuf.Duration] {
+ seconds: 1
+ nanos: 500000000
+ }
+ }
+ )");
+ RunValidJsonTest(
+ "AnyWithTimestamp", REQUIRED,
+ R"({
+ "optionalAny": {
+ "@type": "type.googleapis.com/google.protobuf.Timestamp",
+ "value": "1970-01-01T00:00:00Z"
+ }
+ })",
+ R"(
+ optional_any: {
+ [type.googleapis.com/google.protobuf.Timestamp] {
+ seconds: 0
+ nanos: 0
+ }
+ }
+ )");
+ RunValidJsonTest(
+ "AnyWithFieldMask", REQUIRED,
+ R"({
+ "optionalAny": {
+ "@type": "type.googleapis.com/google.protobuf.FieldMask",
+ "value": "foo,barBaz"
+ }
+ })",
+ R"(
+ optional_any: {
+ [type.googleapis.com/google.protobuf.FieldMask] {
+ paths: ["foo", "bar_baz"]
+ }
+ }
+ )");
+ RunValidJsonTest(
+ "AnyWithStruct", REQUIRED,
+ R"({
+ "optionalAny": {
+ "@type": "type.googleapis.com/google.protobuf.Struct",
+ "value": {
+ "foo": 1
+ }
+ }
+ })",
+ R"(
+ optional_any: {
+ [type.googleapis.com/google.protobuf.Struct] {
+ fields: {
+ key: "foo"
+ value: {
+ number_value: 1
+ }
+ }
+ }
+ }
+ )");
+ RunValidJsonTest(
+ "AnyWithValueForJsonObject", REQUIRED,
+ R"({
+ "optionalAny": {
+ "@type": "type.googleapis.com/google.protobuf.Value",
+ "value": {
+ "foo": 1
+ }
+ }
+ })",
+ R"(
+ optional_any: {
+ [type.googleapis.com/google.protobuf.Value] {
+ struct_value: {
+ fields: {
+ key: "foo"
+ value: {
+ number_value: 1
+ }
+ }
+ }
+ }
+ }
+ )");
+ RunValidJsonTest(
+ "AnyWithValueForInteger", REQUIRED,
+ R"({
+ "optionalAny": {
+ "@type": "type.googleapis.com/google.protobuf.Value",
+ "value": 1
+ }
+ })",
+ R"(
+ optional_any: {
+ [type.googleapis.com/google.protobuf.Value] {
+ number_value: 1
+ }
+ }
+ )");
+
+ bool ok = true;
+ if (!CheckSetEmpty(expected_to_fail_, "nonexistent_tests.txt",
+ "These tests were listed in the failure list, but they "
+ "don't exist. Remove them from the failure list by "
+ "running:\n"
+ " ./update_failure_list.py " + failure_list_filename_ +
+ " --remove nonexistent_tests.txt")) {
+ ok = false;
+ }
+ if (!CheckSetEmpty(unexpected_failing_tests_, "failing_tests.txt",
+ "These tests failed. If they can't be fixed right now, "
+ "you can add them to the failure list so the overall "
+ "suite can succeed. Add them to the failure list by "
+ "running:\n"
+ " ./update_failure_list.py " + failure_list_filename_ +
+ " --add failing_tests.txt")) {
+ ok = false;
+ }
+ if (!CheckSetEmpty(unexpected_succeeding_tests_, "succeeding_tests.txt",
+ "These tests succeeded, even though they were listed in "
+ "the failure list. Remove them from the failure list "
+ "by running:\n"
+ " ./update_failure_list.py " + failure_list_filename_ +
+ " --remove succeeding_tests.txt")) {
+ ok = false;
+ }
+
+ if (verbose_) {
+ CheckSetEmpty(skipped_, "",
+ "These tests were skipped (probably because support for some "
+ "features is not implemented)");
+ }
+
+ StringAppendF(&output_,
+ "CONFORMANCE SUITE %s: %d successes, %d skipped, "
+ "%d expected failures, %d unexpected failures.\n",
+ ok ? "PASSED" : "FAILED", successes_, skipped_.size(),
+ expected_failures_, unexpected_failing_tests_.size());
+ StringAppendF(&output_, "\n");
+
+ output->assign(output_);
+
+ return ok;
+}
+
+} // namespace protobuf
+} // namespace google
diff --git a/third_party/protobuf/conformance/conformance_test.h b/third_party/protobuf/conformance/conformance_test.h
new file mode 100644
index 0000000000..5f05a25bcb
--- /dev/null
+++ b/third_party/protobuf/conformance/conformance_test.h
@@ -0,0 +1,242 @@
+// 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.
+
+
+// This file defines a protocol for running the conformance test suite
+// in-process. In other words, the suite itself will run in the same process as
+// the code under test.
+//
+// For pros and cons of this approach, please see conformance.proto.
+
+#ifndef CONFORMANCE_CONFORMANCE_TEST_H
+#define CONFORMANCE_CONFORMANCE_TEST_H
+
+#include <functional>
+#include <string>
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/util/type_resolver.h>
+#include <google/protobuf/wire_format_lite.h>
+
+#include "third_party/jsoncpp/json.h"
+
+namespace conformance {
+class ConformanceRequest;
+class ConformanceResponse;
+} // namespace conformance
+
+namespace protobuf_test_messages {
+namespace proto3 {
+class TestAllTypes;
+} // namespace proto3
+} // namespace protobuf_test_messages
+
+namespace google {
+namespace protobuf {
+
+class ConformanceTestRunner {
+ public:
+ virtual ~ConformanceTestRunner() {}
+
+ // Call to run a single conformance test.
+ //
+ // "input" is a serialized conformance.ConformanceRequest.
+ // "output" should be set to a serialized conformance.ConformanceResponse.
+ //
+ // If there is any error in running the test itself, set "runtime_error" in
+ // the response.
+ virtual void RunTest(const std::string& test_name,
+ const std::string& input,
+ std::string* output) = 0;
+};
+
+// Class representing the test suite itself. To run it, implement your own
+// class derived from ConformanceTestRunner and then write code like:
+//
+// class MyConformanceTestRunner : public ConformanceTestRunner {
+// public:
+// virtual void RunTest(...) {
+// // INSERT YOUR FRAMEWORK-SPECIFIC CODE HERE.
+// }
+// };
+//
+// int main() {
+// MyConformanceTestRunner runner;
+// google::protobuf::ConformanceTestSuite suite;
+//
+// std::string output;
+// suite.RunSuite(&runner, &output);
+// }
+//
+class ConformanceTestSuite {
+ public:
+ ConformanceTestSuite() : verbose_(false), enforce_recommended_(false) {}
+
+ void SetVerbose(bool verbose) { verbose_ = verbose; }
+
+ // Sets the list of tests that are expected to fail when RunSuite() is called.
+ // RunSuite() will fail unless the set of failing tests is exactly the same
+ // as this list.
+ //
+ // The filename here is *only* used to create/format useful error messages for
+ // how to update the failure list. We do NOT read this file at all.
+ void SetFailureList(const std::string& filename,
+ const std::vector<std::string>& 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".
+ //
+ // Returns true if the set of failing tests was exactly the same as the
+ // failure list. If SetFailureList() was not called, returns true if all
+ // tests passed.
+ 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, ...);
+ void ReportSkip(const string& test_name,
+ const conformance::ConformanceRequest& request,
+ const conformance::ConformanceResponse& response);
+ void RunTest(const std::string& test_name,
+ const conformance::ConformanceRequest& request,
+ conformance::ConformanceResponse* response);
+ 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,
+ ConformanceLevel level,
+ const string& input_json,
+ const string& equivalent_text_format);
+ void RunValidJsonTestWithProtobufInput(
+ const string& test_name,
+ ConformanceLevel level,
+ const protobuf_test_messages::proto3::TestAllTypes& input,
+ const string& equivalent_text_format);
+ void RunValidProtobufTest(const string& test_name, ConformanceLevel level,
+ const string& input_protobuf,
+ const string& equivalent_text_format);
+ void RunValidProtobufTestWithMessage(
+ const string& test_name, ConformanceLevel level,
+ const protobuf_test_messages::proto3::TestAllTypes& input,
+ const string& equivalent_text_format);
+
+ typedef std::function<bool(const Json::Value&)> 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,
+ ConformanceLevel level);
+ void ExpectHardParseFailureForProto(const std::string& proto,
+ const std::string& test_name,
+ ConformanceLevel level);
+ void TestPrematureEOFForType(google::protobuf::FieldDescriptor::Type type);
+ void TestValidDataForType(
+ google::protobuf::FieldDescriptor::Type,
+ std::vector<std::pair<std::string, std::string>> values);
+ bool CheckSetEmpty(const set<string>& set_to_check,
+ const std::string& write_to_file, const std::string& msg);
+ ConformanceTestRunner* runner_;
+ int successes_;
+ int expected_failures_;
+ bool verbose_;
+ bool enforce_recommended_;
+ std::string output_;
+ std::string failure_list_filename_;
+
+ // The set of test names that are expected to fail in this run, but haven't
+ // failed yet.
+ std::set<std::string> expected_to_fail_;
+
+ // The set of test names that have been run. Used to ensure that there are no
+ // duplicate names in the suite.
+ std::set<std::string> test_names_;
+
+ // The set of tests that failed, but weren't expected to.
+ std::set<std::string> unexpected_failing_tests_;
+
+ // The set of tests that succeeded, but weren't expected to.
+ std::set<std::string> unexpected_succeeding_tests_;
+
+ // The set of tests that the testee opted out of;
+ std::set<std::string> skipped_;
+
+ google::protobuf::internal::scoped_ptr<google::protobuf::util::TypeResolver>
+ type_resolver_;
+ std::string type_url_;
+};
+
+} // namespace protobuf
+} // namespace google
+
+#endif // CONFORMANCE_CONFORMANCE_TEST_H
diff --git a/third_party/protobuf/conformance/conformance_test_runner.cc b/third_party/protobuf/conformance/conformance_test_runner.cc
new file mode 100644
index 0000000000..7e91d388b0
--- /dev/null
+++ b/third_party/protobuf/conformance/conformance_test_runner.cc
@@ -0,0 +1,326 @@
+// 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.
+
+// This file contains a program for running the test suite in a separate
+// process. The other alternative is to run the suite in-process. See
+// conformance.proto for pros/cons of these two options.
+//
+// This program will fork the process under test and communicate with it over
+// its stdin/stdout:
+//
+// +--------+ pipe +----------+
+// | tester | <------> | testee |
+// | | | |
+// | C++ | | any lang |
+// +--------+ +----------+
+//
+// The tester contains all of the test cases and their expected output.
+// The testee is a simple program written in the target language that reads
+// each test case and attempts to produce acceptable output for it.
+//
+// Every test consists of a ConformanceRequest/ConformanceResponse
+// request/reply pair. The protocol on the pipe is simply:
+//
+// 1. tester sends 4-byte length N (little endian)
+// 2. tester sends N bytes representing a ConformanceRequest proto
+// 3. testee sends 4-byte length M (little endian)
+// 4. testee sends M bytes representing a ConformanceResponse proto
+
+#include <algorithm>
+#include <errno.h>
+#include <fstream>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <vector>
+
+#include <google/protobuf/stubs/stringprintf.h>
+
+#include "conformance.pb.h"
+#include "conformance_test.h"
+
+using conformance::ConformanceRequest;
+using conformance::ConformanceResponse;
+using google::protobuf::internal::scoped_array;
+using google::protobuf::StringAppendF;
+using std::string;
+using std::vector;
+
+#define STRINGIFY(x) #x
+#define TOSTRING(x) STRINGIFY(x)
+#define CHECK_SYSCALL(call) \
+ if (call < 0) { \
+ perror(#call " " __FILE__ ":" TOSTRING(__LINE__)); \
+ exit(1); \
+ }
+
+// Test runner that spawns the process being tested and communicates with it
+// over a pipe.
+class ForkPipeRunner : public google::protobuf::ConformanceTestRunner {
+ public:
+ ForkPipeRunner(const std::string &executable)
+ : child_pid_(-1), executable_(executable) {}
+
+ virtual ~ForkPipeRunner() {}
+
+ void RunTest(const std::string& test_name,
+ const std::string& request,
+ std::string* response) {
+ if (child_pid_ < 0) {
+ SpawnTestProgram();
+ }
+
+ current_test_name_ = test_name;
+
+ uint32_t len = request.size();
+ CheckedWrite(write_fd_, &len, sizeof(uint32_t));
+ CheckedWrite(write_fd_, request.c_str(), request.size());
+
+ if (!TryRead(read_fd_, &len, sizeof(uint32_t))) {
+ // We failed to read from the child, assume a crash and try to reap.
+ GOOGLE_LOG(INFO) << "Trying to reap child, pid=" << child_pid_;
+
+ int status;
+ waitpid(child_pid_, &status, WEXITED);
+
+ string error_msg;
+ if (WIFEXITED(status)) {
+ StringAppendF(&error_msg,
+ "child exited, status=%d", WEXITSTATUS(status));
+ } else if (WIFSIGNALED(status)) {
+ StringAppendF(&error_msg,
+ "child killed by signal %d", WTERMSIG(status));
+ }
+ GOOGLE_LOG(INFO) << error_msg;
+ child_pid_ = -1;
+
+ conformance::ConformanceResponse response_obj;
+ response_obj.set_runtime_error(error_msg);
+ response_obj.SerializeToString(response);
+ return;
+ }
+
+ response->resize(len);
+ CheckedRead(read_fd_, (void*)response->c_str(), len);
+ }
+
+ private:
+ // TODO(haberman): make this work on Windows, instead of using these
+ // UNIX-specific APIs.
+ //
+ // There is a platform-agnostic API in
+ // src/google/protobuf/compiler/subprocess.h
+ //
+ // However that API only supports sending a single message to the subprocess.
+ // We really want to be able to send messages and receive responses one at a
+ // time:
+ //
+ // 1. Spawning a new process for each test would take way too long for thousands
+ // of tests and subprocesses like java that can take 100ms or more to start
+ // up.
+ //
+ // 2. Sending all the tests in one big message and receiving all results in one
+ // big message would take away our visibility about which test(s) caused a
+ // crash or other fatal error. It would also give us only a single failure
+ // instead of all of them.
+ void SpawnTestProgram() {
+ int toproc_pipe_fd[2];
+ int fromproc_pipe_fd[2];
+ if (pipe(toproc_pipe_fd) < 0 || pipe(fromproc_pipe_fd) < 0) {
+ perror("pipe");
+ exit(1);
+ }
+
+ pid_t pid = fork();
+ if (pid < 0) {
+ perror("fork");
+ exit(1);
+ }
+
+ if (pid) {
+ // Parent.
+ CHECK_SYSCALL(close(toproc_pipe_fd[0]));
+ CHECK_SYSCALL(close(fromproc_pipe_fd[1]));
+ write_fd_ = toproc_pipe_fd[1];
+ read_fd_ = fromproc_pipe_fd[0];
+ child_pid_ = pid;
+ } else {
+ // Child.
+ CHECK_SYSCALL(close(STDIN_FILENO));
+ CHECK_SYSCALL(close(STDOUT_FILENO));
+ CHECK_SYSCALL(dup2(toproc_pipe_fd[0], STDIN_FILENO));
+ CHECK_SYSCALL(dup2(fromproc_pipe_fd[1], STDOUT_FILENO));
+
+ CHECK_SYSCALL(close(toproc_pipe_fd[0]));
+ CHECK_SYSCALL(close(fromproc_pipe_fd[1]));
+ CHECK_SYSCALL(close(toproc_pipe_fd[1]));
+ CHECK_SYSCALL(close(fromproc_pipe_fd[0]));
+
+ scoped_array<char> executable(new char[executable_.size() + 1]);
+ memcpy(executable.get(), executable_.c_str(), executable_.size());
+ executable[executable_.size()] = '\0';
+
+ char *const argv[] = {executable.get(), NULL};
+ CHECK_SYSCALL(execv(executable.get(), argv)); // Never returns.
+ }
+ }
+
+ void CheckedWrite(int fd, const void *buf, size_t len) {
+ if (write(fd, buf, len) != len) {
+ GOOGLE_LOG(FATAL) << current_test_name_
+ << ": error writing to test program: "
+ << strerror(errno);
+ }
+ }
+
+ bool TryRead(int fd, void *buf, size_t len) {
+ size_t ofs = 0;
+ while (len > 0) {
+ ssize_t bytes_read = read(fd, (char*)buf + ofs, len);
+
+ if (bytes_read == 0) {
+ GOOGLE_LOG(ERROR) << current_test_name_
+ << ": unexpected EOF from test program";
+ return false;
+ } else if (bytes_read < 0) {
+ GOOGLE_LOG(ERROR) << current_test_name_
+ << ": error reading from test program: "
+ << strerror(errno);
+ return false;
+ }
+
+ len -= bytes_read;
+ ofs += bytes_read;
+ }
+
+ return true;
+ }
+
+ void CheckedRead(int fd, void *buf, size_t len) {
+ if (!TryRead(fd, buf, len)) {
+ GOOGLE_LOG(FATAL) << current_test_name_
+ << ": error reading from test program: "
+ << strerror(errno);
+ }
+ }
+
+ int write_fd_;
+ int read_fd_;
+ pid_t child_pid_;
+ std::string executable_;
+ std::string current_test_name_;
+};
+
+void UsageError() {
+ fprintf(stderr,
+ "Usage: conformance-test-runner [options] <test-program>\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Options:\n");
+ fprintf(stderr,
+ " --failure_list <filename> Use to specify list of tests\n");
+ fprintf(stderr,
+ " that are expected to fail. File\n");
+ fprintf(stderr,
+ " 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);
+}
+
+void ParseFailureList(const char *filename, vector<string>* failure_list) {
+ std::ifstream infile(filename);
+
+ if (!infile.is_open()) {
+ fprintf(stderr, "Couldn't open failure list file: %s\n", filename);
+ exit(1);
+ }
+
+ for (string line; getline(infile, line);) {
+ // Remove whitespace.
+ line.erase(std::remove_if(line.begin(), line.end(), ::isspace),
+ line.end());
+
+ // Remove comments.
+ line = line.substr(0, line.find("#"));
+
+ if (!line.empty()) {
+ failure_list->push_back(line);
+ }
+ }
+}
+
+int main(int argc, char *argv[]) {
+ char *program;
+ google::protobuf::ConformanceTestSuite suite;
+
+ string failure_list_filename;
+ vector<string> failure_list;
+
+ for (int arg = 1; arg < argc; ++arg) {
+ if (strcmp(argv[arg], "--failure_list") == 0) {
+ if (++arg == argc) UsageError();
+ failure_list_filename = argv[arg];
+ 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();
+ } else {
+ if (arg != argc - 1) {
+ fprintf(stderr, "Too many arguments.\n");
+ UsageError();
+ }
+ program = argv[arg];
+ }
+ }
+
+ suite.SetFailureList(failure_list_filename, failure_list);
+ ForkPipeRunner runner(program);
+
+ std::string output;
+ bool ok = suite.RunSuite(&runner, &output);
+
+ fwrite(output.c_str(), 1, output.size(), stderr);
+
+ return ok ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/third_party/protobuf/conformance/failure_list_cpp.txt b/third_party/protobuf/conformance/failure_list_cpp.txt
new file mode 100644
index 0000000000..8cfd74da6e
--- /dev/null
+++ b/third_party/protobuf/conformance/failure_list_cpp.txt
@@ -0,0 +1,46 @@
+# This is the list of conformance tests that are known to fail for the C++
+# implementation right now. These should be fixed.
+#
+# 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.
+#
+# TODO(haberman): insert links to corresponding bugs tracking the issue.
+# Should we use GitHub issues or the Google-internal bug tracker?
+
+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.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/third_party/protobuf/3.0.0/python/google/protobuf/internal/__init__.py b/third_party/protobuf/conformance/failure_list_csharp.txt
index e69de29bb2..e69de29bb2 100755..100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/__init__.py
+++ b/third_party/protobuf/conformance/failure_list_csharp.txt
diff --git a/third_party/protobuf/conformance/failure_list_java.txt b/third_party/protobuf/conformance/failure_list_java.txt
new file mode 100644
index 0000000000..632940efc8
--- /dev/null
+++ b/third_party/protobuf/conformance/failure_list_java.txt
@@ -0,0 +1,45 @@
+# This is the list of conformance tests that are known to fail for the Java
+# implementation right now. These should be fixed.
+#
+# 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.
+
+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.FieldNameNotQuoted
+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.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
+Required.ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.MESSAGE
+Required.ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.MESSAGE
diff --git a/third_party/protobuf/conformance/failure_list_js.txt b/third_party/protobuf/conformance/failure_list_js.txt
new file mode 100644
index 0000000000..5414a2f985
--- /dev/null
+++ b/third_party/protobuf/conformance/failure_list_js.txt
@@ -0,0 +1,15 @@
+Required.ProtobufInput.RepeatedScalarSelectsLast.INT32.ProtobufOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.UINT32.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.BOOL.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.DOUBLE.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.FIXED32.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.FIXED64.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.FLOAT.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.INT32.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.INT64.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.SFIXED32.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.SFIXED64.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.SINT32.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.SINT64.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.UINT32.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.UINT64.ProtobufOutput
diff --git a/third_party/protobuf/conformance/failure_list_objc.txt b/third_party/protobuf/conformance/failure_list_objc.txt
new file mode 100644
index 0000000000..dd538c1036
--- /dev/null
+++ b/third_party/protobuf/conformance/failure_list_objc.txt
@@ -0,0 +1,4 @@
+# All tests currently passing.
+#
+# JSON input or output tests are skipped (in conformance_objc.m) as mobile
+# platforms don't support JSON wire format to avoid code bloat.
diff --git a/third_party/protobuf/conformance/failure_list_php.txt b/third_party/protobuf/conformance/failure_list_php.txt
new file mode 100644
index 0000000000..6dd93918f9
--- /dev/null
+++ b/third_party/protobuf/conformance/failure_list_php.txt
@@ -0,0 +1,611 @@
+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.BoolFieldIntegerOne
+Recommended.JsonInput.BoolFieldIntegerZero
+Recommended.JsonInput.BoolMapFieldKeyNotQuoted
+Recommended.JsonInput.DoubleFieldInfinityNotQuoted
+Recommended.JsonInput.DoubleFieldNanNotQuoted
+Recommended.JsonInput.DoubleFieldNegativeInfinityNotQuoted
+Recommended.JsonInput.DurationHas3FractionalDigits.Validator
+Recommended.JsonInput.DurationHas6FractionalDigits.Validator
+Recommended.JsonInput.DurationHas9FractionalDigits.Validator
+Recommended.JsonInput.DurationHasZeroFractionalDigit.Validator
+Recommended.JsonInput.FieldMaskInvalidCharacter
+Recommended.JsonInput.FieldNameDuplicate
+Recommended.JsonInput.FieldNameDuplicateDifferentCasing1
+Recommended.JsonInput.FieldNameDuplicateDifferentCasing2
+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.Int64FieldBeString.Validator
+Recommended.JsonInput.Int64MapFieldKeyNotQuoted
+Recommended.JsonInput.JsonWithComments
+Recommended.JsonInput.MapFieldKeyIsNull
+Recommended.JsonInput.MapFieldValueIsNull
+Recommended.JsonInput.MissingCommaMultiline
+Recommended.JsonInput.MissingCommaOneLine
+Recommended.JsonInput.MultilineNoSpaces.JsonOutput
+Recommended.JsonInput.MultilineNoSpaces.ProtobufOutput
+Recommended.JsonInput.MultilineWithSpaces.JsonOutput
+Recommended.JsonInput.MultilineWithSpaces.ProtobufOutput
+Recommended.JsonInput.OneLineNoSpaces.JsonOutput
+Recommended.JsonInput.OneLineNoSpaces.ProtobufOutput
+Recommended.JsonInput.OneLineWithSpaces.JsonOutput
+Recommended.JsonInput.OneLineWithSpaces.ProtobufOutput
+Recommended.JsonInput.OneofZeroBool.JsonOutput
+Recommended.JsonInput.OneofZeroBool.ProtobufOutput
+Recommended.JsonInput.OneofZeroBytes.JsonOutput
+Recommended.JsonInput.OneofZeroBytes.ProtobufOutput
+Recommended.JsonInput.OneofZeroDouble.JsonOutput
+Recommended.JsonInput.OneofZeroDouble.ProtobufOutput
+Recommended.JsonInput.OneofZeroEnum.JsonOutput
+Recommended.JsonInput.OneofZeroEnum.ProtobufOutput
+Recommended.JsonInput.OneofZeroFloat.JsonOutput
+Recommended.JsonInput.OneofZeroFloat.ProtobufOutput
+Recommended.JsonInput.OneofZeroMessage.JsonOutput
+Recommended.JsonInput.OneofZeroMessage.ProtobufOutput
+Recommended.JsonInput.OneofZeroString.JsonOutput
+Recommended.JsonInput.OneofZeroString.ProtobufOutput
+Recommended.JsonInput.OneofZeroUint32.JsonOutput
+Recommended.JsonInput.OneofZeroUint32.ProtobufOutput
+Recommended.JsonInput.OneofZeroUint64.JsonOutput
+Recommended.JsonInput.OneofZeroUint64.ProtobufOutput
+Recommended.JsonInput.RepeatedFieldMessageElementIsNull
+Recommended.JsonInput.RepeatedFieldPrimitiveElementIsNull
+Recommended.JsonInput.RepeatedFieldTrailingComma
+Recommended.JsonInput.RepeatedFieldTrailingCommaWithNewlines
+Recommended.JsonInput.RepeatedFieldTrailingCommaWithSpace
+Recommended.JsonInput.RepeatedFieldTrailingCommaWithSpaceCommaSpace
+Recommended.JsonInput.StringEndsWithEscapeChar
+Recommended.JsonInput.StringFieldInvalidEscape
+Recommended.JsonInput.StringFieldSingleQuoteBoth
+Recommended.JsonInput.StringFieldSingleQuoteKey
+Recommended.JsonInput.StringFieldSingleQuoteValue
+Recommended.JsonInput.StringFieldSurrogateInWrongOrder
+Recommended.JsonInput.StringFieldUnpairedHighSurrogate
+Recommended.JsonInput.StringFieldUnpairedLowSurrogate
+Recommended.JsonInput.StringFieldUnterminatedEscape
+Recommended.JsonInput.StringFieldUppercaseEscapeLetter
+Recommended.JsonInput.TimestampHas3FractionalDigits.Validator
+Recommended.JsonInput.TimestampHas6FractionalDigits.Validator
+Recommended.JsonInput.TimestampHas9FractionalDigits.Validator
+Recommended.JsonInput.TimestampHasZeroFractionalDigit.Validator
+Recommended.JsonInput.TimestampZeroNormalized.Validator
+Recommended.JsonInput.TrailingCommaInAnObject
+Recommended.JsonInput.TrailingCommaInAnObjectWithNewlines
+Recommended.JsonInput.TrailingCommaInAnObjectWithSpace
+Recommended.JsonInput.TrailingCommaInAnObjectWithSpaceCommaSpace
+Recommended.JsonInput.Uint32MapFieldKeyNotQuoted
+Recommended.JsonInput.Uint64FieldBeString.Validator
+Recommended.JsonInput.Uint64MapFieldKeyNotQuoted
+Recommended.ProtobufInput.OneofZeroBool.JsonOutput
+Recommended.ProtobufInput.OneofZeroBool.ProtobufOutput
+Recommended.ProtobufInput.OneofZeroBytes.JsonOutput
+Recommended.ProtobufInput.OneofZeroBytes.ProtobufOutput
+Recommended.ProtobufInput.OneofZeroDouble.JsonOutput
+Recommended.ProtobufInput.OneofZeroDouble.ProtobufOutput
+Recommended.ProtobufInput.OneofZeroEnum.JsonOutput
+Recommended.ProtobufInput.OneofZeroEnum.ProtobufOutput
+Recommended.ProtobufInput.OneofZeroFloat.JsonOutput
+Recommended.ProtobufInput.OneofZeroFloat.ProtobufOutput
+Recommended.ProtobufInput.OneofZeroMessage.JsonOutput
+Recommended.ProtobufInput.OneofZeroMessage.ProtobufOutput
+Recommended.ProtobufInput.OneofZeroString.JsonOutput
+Recommended.ProtobufInput.OneofZeroString.ProtobufOutput
+Recommended.ProtobufInput.OneofZeroUint32.JsonOutput
+Recommended.ProtobufInput.OneofZeroUint32.ProtobufOutput
+Recommended.ProtobufInput.OneofZeroUint64.JsonOutput
+Recommended.ProtobufInput.OneofZeroUint64.ProtobufOutput
+Required.DurationProtoInputTooLarge.JsonOutput
+Required.DurationProtoInputTooSmall.JsonOutput
+Required.JsonInput.AllFieldAcceptNull.JsonOutput
+Required.JsonInput.AllFieldAcceptNull.ProtobufOutput
+Required.JsonInput.Any.JsonOutput
+Required.JsonInput.Any.ProtobufOutput
+Required.JsonInput.AnyNested.JsonOutput
+Required.JsonInput.AnyNested.ProtobufOutput
+Required.JsonInput.AnyUnorderedTypeTag.JsonOutput
+Required.JsonInput.AnyUnorderedTypeTag.ProtobufOutput
+Required.JsonInput.AnyWithDuration.JsonOutput
+Required.JsonInput.AnyWithDuration.ProtobufOutput
+Required.JsonInput.AnyWithFieldMask.JsonOutput
+Required.JsonInput.AnyWithFieldMask.ProtobufOutput
+Required.JsonInput.AnyWithInt32ValueWrapper.JsonOutput
+Required.JsonInput.AnyWithInt32ValueWrapper.ProtobufOutput
+Required.JsonInput.AnyWithStruct.JsonOutput
+Required.JsonInput.AnyWithStruct.ProtobufOutput
+Required.JsonInput.AnyWithTimestamp.JsonOutput
+Required.JsonInput.AnyWithTimestamp.ProtobufOutput
+Required.JsonInput.AnyWithValueForInteger.JsonOutput
+Required.JsonInput.AnyWithValueForInteger.ProtobufOutput
+Required.JsonInput.AnyWithValueForJsonObject.JsonOutput
+Required.JsonInput.AnyWithValueForJsonObject.ProtobufOutput
+Required.JsonInput.BoolFieldFalse.JsonOutput
+Required.JsonInput.BoolFieldFalse.ProtobufOutput
+Required.JsonInput.BoolFieldTrue.JsonOutput
+Required.JsonInput.BoolFieldTrue.ProtobufOutput
+Required.JsonInput.BoolMapEscapedKey.JsonOutput
+Required.JsonInput.BoolMapEscapedKey.ProtobufOutput
+Required.JsonInput.BoolMapField.JsonOutput
+Required.JsonInput.BoolMapField.ProtobufOutput
+Required.JsonInput.BytesField.JsonOutput
+Required.JsonInput.BytesField.ProtobufOutput
+Required.JsonInput.BytesFieldInvalidBase64Characters
+Required.JsonInput.BytesRepeatedField.JsonOutput
+Required.JsonInput.BytesRepeatedField.ProtobufOutput
+Required.JsonInput.DoubleFieldInfinity.JsonOutput
+Required.JsonInput.DoubleFieldInfinity.ProtobufOutput
+Required.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput
+Required.JsonInput.DoubleFieldMaxNegativeValue.ProtobufOutput
+Required.JsonInput.DoubleFieldMaxPositiveValue.JsonOutput
+Required.JsonInput.DoubleFieldMaxPositiveValue.ProtobufOutput
+Required.JsonInput.DoubleFieldMinNegativeValue.JsonOutput
+Required.JsonInput.DoubleFieldMinNegativeValue.ProtobufOutput
+Required.JsonInput.DoubleFieldMinPositiveValue.JsonOutput
+Required.JsonInput.DoubleFieldMinPositiveValue.ProtobufOutput
+Required.JsonInput.DoubleFieldNan.JsonOutput
+Required.JsonInput.DoubleFieldNan.ProtobufOutput
+Required.JsonInput.DoubleFieldNegativeInfinity.JsonOutput
+Required.JsonInput.DoubleFieldNegativeInfinity.ProtobufOutput
+Required.JsonInput.DoubleFieldQuotedValue.JsonOutput
+Required.JsonInput.DoubleFieldQuotedValue.ProtobufOutput
+Required.JsonInput.DoubleFieldTooLarge
+Required.JsonInput.DoubleFieldTooSmall
+Required.JsonInput.DurationJsonInputTooLarge
+Required.JsonInput.DurationJsonInputTooSmall
+Required.JsonInput.DurationMaxValue.JsonOutput
+Required.JsonInput.DurationMaxValue.ProtobufOutput
+Required.JsonInput.DurationMinValue.JsonOutput
+Required.JsonInput.DurationMinValue.ProtobufOutput
+Required.JsonInput.DurationMissingS
+Required.JsonInput.DurationRepeatedValue.JsonOutput
+Required.JsonInput.DurationRepeatedValue.ProtobufOutput
+Required.JsonInput.EnumField.JsonOutput
+Required.JsonInput.EnumField.ProtobufOutput
+Required.JsonInput.EnumFieldNotQuoted
+Required.JsonInput.EnumFieldNumericValueNonZero.JsonOutput
+Required.JsonInput.EnumFieldNumericValueNonZero.ProtobufOutput
+Required.JsonInput.EnumFieldNumericValueZero.JsonOutput
+Required.JsonInput.EnumFieldNumericValueZero.ProtobufOutput
+Required.JsonInput.EnumFieldUnknownValue.Validator
+Required.JsonInput.EnumRepeatedField.JsonOutput
+Required.JsonInput.EnumRepeatedField.ProtobufOutput
+Required.JsonInput.FieldMask.JsonOutput
+Required.JsonInput.FieldMask.ProtobufOutput
+Required.JsonInput.FieldNameEscaped.JsonOutput
+Required.JsonInput.FieldNameEscaped.ProtobufOutput
+Required.JsonInput.FieldNameInLowerCamelCase.Validator
+Required.JsonInput.FieldNameInSnakeCase.JsonOutput
+Required.JsonInput.FieldNameInSnakeCase.ProtobufOutput
+Required.JsonInput.FieldNameWithMixedCases.JsonOutput
+Required.JsonInput.FieldNameWithMixedCases.ProtobufOutput
+Required.JsonInput.FieldNameWithMixedCases.Validator
+Required.JsonInput.FieldNameWithNumbers.JsonOutput
+Required.JsonInput.FieldNameWithNumbers.ProtobufOutput
+Required.JsonInput.FieldNameWithNumbers.Validator
+Required.JsonInput.FloatFieldInfinity.JsonOutput
+Required.JsonInput.FloatFieldInfinity.ProtobufOutput
+Required.JsonInput.FloatFieldMaxNegativeValue.JsonOutput
+Required.JsonInput.FloatFieldMaxNegativeValue.ProtobufOutput
+Required.JsonInput.FloatFieldMaxPositiveValue.JsonOutput
+Required.JsonInput.FloatFieldMaxPositiveValue.ProtobufOutput
+Required.JsonInput.FloatFieldMinNegativeValue.JsonOutput
+Required.JsonInput.FloatFieldMinNegativeValue.ProtobufOutput
+Required.JsonInput.FloatFieldMinPositiveValue.JsonOutput
+Required.JsonInput.FloatFieldMinPositiveValue.ProtobufOutput
+Required.JsonInput.FloatFieldNan.JsonOutput
+Required.JsonInput.FloatFieldNan.ProtobufOutput
+Required.JsonInput.FloatFieldNegativeInfinity.JsonOutput
+Required.JsonInput.FloatFieldNegativeInfinity.ProtobufOutput
+Required.JsonInput.FloatFieldQuotedValue.JsonOutput
+Required.JsonInput.FloatFieldQuotedValue.ProtobufOutput
+Required.JsonInput.FloatFieldTooLarge
+Required.JsonInput.FloatFieldTooSmall
+Required.JsonInput.HelloWorld.JsonOutput
+Required.JsonInput.HelloWorld.ProtobufOutput
+Required.JsonInput.Int32FieldExponentialFormat.JsonOutput
+Required.JsonInput.Int32FieldExponentialFormat.ProtobufOutput
+Required.JsonInput.Int32FieldFloatTrailingZero.JsonOutput
+Required.JsonInput.Int32FieldFloatTrailingZero.ProtobufOutput
+Required.JsonInput.Int32FieldLeadingSpace
+Required.JsonInput.Int32FieldLeadingZero
+Required.JsonInput.Int32FieldMaxFloatValue.JsonOutput
+Required.JsonInput.Int32FieldMaxFloatValue.ProtobufOutput
+Required.JsonInput.Int32FieldMaxValue.JsonOutput
+Required.JsonInput.Int32FieldMaxValue.ProtobufOutput
+Required.JsonInput.Int32FieldMinFloatValue.JsonOutput
+Required.JsonInput.Int32FieldMinFloatValue.ProtobufOutput
+Required.JsonInput.Int32FieldMinValue.JsonOutput
+Required.JsonInput.Int32FieldMinValue.ProtobufOutput
+Required.JsonInput.Int32FieldNegativeWithLeadingZero
+Required.JsonInput.Int32FieldNotInteger
+Required.JsonInput.Int32FieldNotNumber
+Required.JsonInput.Int32FieldPlusSign
+Required.JsonInput.Int32FieldStringValue.JsonOutput
+Required.JsonInput.Int32FieldStringValue.ProtobufOutput
+Required.JsonInput.Int32FieldStringValueEscaped.JsonOutput
+Required.JsonInput.Int32FieldStringValueEscaped.ProtobufOutput
+Required.JsonInput.Int32FieldTooLarge
+Required.JsonInput.Int32FieldTooSmall
+Required.JsonInput.Int32FieldTrailingSpace
+Required.JsonInput.Int32MapEscapedKey.JsonOutput
+Required.JsonInput.Int32MapEscapedKey.ProtobufOutput
+Required.JsonInput.Int32MapField.JsonOutput
+Required.JsonInput.Int32MapField.ProtobufOutput
+Required.JsonInput.Int64FieldMaxValue.JsonOutput
+Required.JsonInput.Int64FieldMaxValue.ProtobufOutput
+Required.JsonInput.Int64FieldMaxValueNotQuoted.JsonOutput
+Required.JsonInput.Int64FieldMaxValueNotQuoted.ProtobufOutput
+Required.JsonInput.Int64FieldMinValue.JsonOutput
+Required.JsonInput.Int64FieldMinValue.ProtobufOutput
+Required.JsonInput.Int64FieldMinValueNotQuoted.JsonOutput
+Required.JsonInput.Int64FieldMinValueNotQuoted.ProtobufOutput
+Required.JsonInput.Int64FieldNotInteger
+Required.JsonInput.Int64FieldNotNumber
+Required.JsonInput.Int64FieldTooLarge
+Required.JsonInput.Int64FieldTooSmall
+Required.JsonInput.Int64MapEscapedKey.JsonOutput
+Required.JsonInput.Int64MapEscapedKey.ProtobufOutput
+Required.JsonInput.Int64MapField.JsonOutput
+Required.JsonInput.Int64MapField.ProtobufOutput
+Required.JsonInput.MessageField.JsonOutput
+Required.JsonInput.MessageField.ProtobufOutput
+Required.JsonInput.MessageMapField.JsonOutput
+Required.JsonInput.MessageMapField.ProtobufOutput
+Required.JsonInput.MessageRepeatedField.JsonOutput
+Required.JsonInput.MessageRepeatedField.ProtobufOutput
+Required.JsonInput.OneofFieldDuplicate
+Required.JsonInput.OptionalBoolWrapper.JsonOutput
+Required.JsonInput.OptionalBoolWrapper.ProtobufOutput
+Required.JsonInput.OptionalBytesWrapper.JsonOutput
+Required.JsonInput.OptionalBytesWrapper.ProtobufOutput
+Required.JsonInput.OptionalDoubleWrapper.JsonOutput
+Required.JsonInput.OptionalDoubleWrapper.ProtobufOutput
+Required.JsonInput.OptionalFloatWrapper.JsonOutput
+Required.JsonInput.OptionalFloatWrapper.ProtobufOutput
+Required.JsonInput.OptionalInt32Wrapper.JsonOutput
+Required.JsonInput.OptionalInt32Wrapper.ProtobufOutput
+Required.JsonInput.OptionalInt64Wrapper.JsonOutput
+Required.JsonInput.OptionalInt64Wrapper.ProtobufOutput
+Required.JsonInput.OptionalStringWrapper.JsonOutput
+Required.JsonInput.OptionalStringWrapper.ProtobufOutput
+Required.JsonInput.OptionalUint32Wrapper.JsonOutput
+Required.JsonInput.OptionalUint32Wrapper.ProtobufOutput
+Required.JsonInput.OptionalUint64Wrapper.JsonOutput
+Required.JsonInput.OptionalUint64Wrapper.ProtobufOutput
+Required.JsonInput.OptionalWrapperTypesWithNonDefaultValue.JsonOutput
+Required.JsonInput.OptionalWrapperTypesWithNonDefaultValue.ProtobufOutput
+Required.JsonInput.OriginalProtoFieldName.JsonOutput
+Required.JsonInput.OriginalProtoFieldName.ProtobufOutput
+Required.JsonInput.PrimitiveRepeatedField.JsonOutput
+Required.JsonInput.PrimitiveRepeatedField.ProtobufOutput
+Required.JsonInput.RepeatedBoolWrapper.JsonOutput
+Required.JsonInput.RepeatedBoolWrapper.ProtobufOutput
+Required.JsonInput.RepeatedBytesWrapper.JsonOutput
+Required.JsonInput.RepeatedBytesWrapper.ProtobufOutput
+Required.JsonInput.RepeatedDoubleWrapper.JsonOutput
+Required.JsonInput.RepeatedDoubleWrapper.ProtobufOutput
+Required.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool
+Required.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotMessage
+Required.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotString
+Required.JsonInput.RepeatedFieldWrongElementTypeExpectingMessagesGotBool
+Required.JsonInput.RepeatedFieldWrongElementTypeExpectingMessagesGotInt
+Required.JsonInput.RepeatedFieldWrongElementTypeExpectingMessagesGotString
+Required.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotBool
+Required.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt
+Required.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotMessage
+Required.JsonInput.RepeatedFloatWrapper.JsonOutput
+Required.JsonInput.RepeatedFloatWrapper.ProtobufOutput
+Required.JsonInput.RepeatedInt32Wrapper.JsonOutput
+Required.JsonInput.RepeatedInt32Wrapper.ProtobufOutput
+Required.JsonInput.RepeatedInt64Wrapper.JsonOutput
+Required.JsonInput.RepeatedInt64Wrapper.ProtobufOutput
+Required.JsonInput.RepeatedStringWrapper.JsonOutput
+Required.JsonInput.RepeatedStringWrapper.ProtobufOutput
+Required.JsonInput.RepeatedUint32Wrapper.JsonOutput
+Required.JsonInput.RepeatedUint32Wrapper.ProtobufOutput
+Required.JsonInput.RepeatedUint64Wrapper.JsonOutput
+Required.JsonInput.RepeatedUint64Wrapper.ProtobufOutput
+Required.JsonInput.StringField.JsonOutput
+Required.JsonInput.StringField.ProtobufOutput
+Required.JsonInput.StringFieldEscape.JsonOutput
+Required.JsonInput.StringFieldEscape.ProtobufOutput
+Required.JsonInput.StringFieldNotAString
+Required.JsonInput.StringFieldSurrogatePair.JsonOutput
+Required.JsonInput.StringFieldSurrogatePair.ProtobufOutput
+Required.JsonInput.StringFieldUnicode.JsonOutput
+Required.JsonInput.StringFieldUnicode.ProtobufOutput
+Required.JsonInput.StringFieldUnicodeEscape.JsonOutput
+Required.JsonInput.StringFieldUnicodeEscape.ProtobufOutput
+Required.JsonInput.StringFieldUnicodeEscapeWithLowercaseHexLetters.JsonOutput
+Required.JsonInput.StringFieldUnicodeEscapeWithLowercaseHexLetters.ProtobufOutput
+Required.JsonInput.StringRepeatedField.JsonOutput
+Required.JsonInput.StringRepeatedField.ProtobufOutput
+Required.JsonInput.Struct.JsonOutput
+Required.JsonInput.Struct.ProtobufOutput
+Required.JsonInput.TimestampJsonInputLowercaseT
+Required.JsonInput.TimestampJsonInputLowercaseZ
+Required.JsonInput.TimestampJsonInputMissingT
+Required.JsonInput.TimestampJsonInputMissingZ
+Required.JsonInput.TimestampJsonInputTooLarge
+Required.JsonInput.TimestampJsonInputTooSmall
+Required.JsonInput.TimestampMaxValue.JsonOutput
+Required.JsonInput.TimestampMaxValue.ProtobufOutput
+Required.JsonInput.TimestampMinValue.JsonOutput
+Required.JsonInput.TimestampMinValue.ProtobufOutput
+Required.JsonInput.TimestampRepeatedValue.JsonOutput
+Required.JsonInput.TimestampRepeatedValue.ProtobufOutput
+Required.JsonInput.TimestampWithNegativeOffset.JsonOutput
+Required.JsonInput.TimestampWithNegativeOffset.ProtobufOutput
+Required.JsonInput.TimestampWithPositiveOffset.JsonOutput
+Required.JsonInput.TimestampWithPositiveOffset.ProtobufOutput
+Required.JsonInput.Uint32FieldMaxFloatValue.JsonOutput
+Required.JsonInput.Uint32FieldMaxFloatValue.ProtobufOutput
+Required.JsonInput.Uint32FieldMaxValue.JsonOutput
+Required.JsonInput.Uint32FieldMaxValue.ProtobufOutput
+Required.JsonInput.Uint32FieldNotInteger
+Required.JsonInput.Uint32FieldNotNumber
+Required.JsonInput.Uint32FieldTooLarge
+Required.JsonInput.Uint32MapField.JsonOutput
+Required.JsonInput.Uint32MapField.ProtobufOutput
+Required.JsonInput.Uint64FieldMaxValue.JsonOutput
+Required.JsonInput.Uint64FieldMaxValue.ProtobufOutput
+Required.JsonInput.Uint64FieldMaxValueNotQuoted.JsonOutput
+Required.JsonInput.Uint64FieldMaxValueNotQuoted.ProtobufOutput
+Required.JsonInput.Uint64FieldNotInteger
+Required.JsonInput.Uint64FieldNotNumber
+Required.JsonInput.Uint64FieldTooLarge
+Required.JsonInput.Uint64MapField.JsonOutput
+Required.JsonInput.Uint64MapField.ProtobufOutput
+Required.JsonInput.ValueAcceptBool.JsonOutput
+Required.JsonInput.ValueAcceptBool.ProtobufOutput
+Required.JsonInput.ValueAcceptFloat.JsonOutput
+Required.JsonInput.ValueAcceptFloat.ProtobufOutput
+Required.JsonInput.ValueAcceptInteger.JsonOutput
+Required.JsonInput.ValueAcceptInteger.ProtobufOutput
+Required.JsonInput.ValueAcceptList.JsonOutput
+Required.JsonInput.ValueAcceptList.ProtobufOutput
+Required.JsonInput.ValueAcceptNull.JsonOutput
+Required.JsonInput.ValueAcceptNull.ProtobufOutput
+Required.JsonInput.ValueAcceptObject.JsonOutput
+Required.JsonInput.ValueAcceptObject.ProtobufOutput
+Required.JsonInput.ValueAcceptString.JsonOutput
+Required.JsonInput.ValueAcceptString.ProtobufOutput
+Required.JsonInput.WrapperTypesWithNullValue.JsonOutput
+Required.JsonInput.WrapperTypesWithNullValue.ProtobufOutput
+Required.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput
+Required.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput
+Required.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput
+Required.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput
+Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.BOOL
+Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.BYTES
+Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.DOUBLE
+Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.ENUM
+Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.FIXED32
+Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.FIXED64
+Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.FLOAT
+Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.INT32
+Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.INT64
+Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.MESSAGE
+Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.SFIXED32
+Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.SFIXED64
+Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.SINT32
+Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.SINT64
+Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.STRING
+Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.UINT32
+Required.ProtobufInput.PrematureEofBeforeKnownNonRepeatedValue.UINT64
+Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.BOOL
+Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.BYTES
+Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.DOUBLE
+Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.ENUM
+Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.FIXED32
+Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.FIXED64
+Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.FLOAT
+Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.INT32
+Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.INT64
+Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.MESSAGE
+Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.SFIXED32
+Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.SFIXED64
+Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.SINT32
+Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.SINT64
+Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.STRING
+Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.UINT32
+Required.ProtobufInput.PrematureEofBeforeKnownRepeatedValue.UINT64
+Required.ProtobufInput.PrematureEofBeforeUnknownValue.BOOL
+Required.ProtobufInput.PrematureEofBeforeUnknownValue.BYTES
+Required.ProtobufInput.PrematureEofBeforeUnknownValue.DOUBLE
+Required.ProtobufInput.PrematureEofBeforeUnknownValue.ENUM
+Required.ProtobufInput.PrematureEofBeforeUnknownValue.FIXED32
+Required.ProtobufInput.PrematureEofBeforeUnknownValue.FIXED64
+Required.ProtobufInput.PrematureEofBeforeUnknownValue.FLOAT
+Required.ProtobufInput.PrematureEofBeforeUnknownValue.INT32
+Required.ProtobufInput.PrematureEofBeforeUnknownValue.INT64
+Required.ProtobufInput.PrematureEofBeforeUnknownValue.MESSAGE
+Required.ProtobufInput.PrematureEofBeforeUnknownValue.SFIXED32
+Required.ProtobufInput.PrematureEofBeforeUnknownValue.SFIXED64
+Required.ProtobufInput.PrematureEofBeforeUnknownValue.SINT32
+Required.ProtobufInput.PrematureEofBeforeUnknownValue.SINT64
+Required.ProtobufInput.PrematureEofBeforeUnknownValue.STRING
+Required.ProtobufInput.PrematureEofBeforeUnknownValue.UINT32
+Required.ProtobufInput.PrematureEofBeforeUnknownValue.UINT64
+Required.ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.BYTES
+Required.ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.MESSAGE
+Required.ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.STRING
+Required.ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.BYTES
+Required.ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.MESSAGE
+Required.ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.STRING
+Required.ProtobufInput.PrematureEofInDelimitedDataForUnknownValue.BYTES
+Required.ProtobufInput.PrematureEofInDelimitedDataForUnknownValue.MESSAGE
+Required.ProtobufInput.PrematureEofInDelimitedDataForUnknownValue.STRING
+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
+Required.ProtobufInput.PrematureEofInPackedFieldValue.BOOL
+Required.ProtobufInput.PrematureEofInPackedFieldValue.DOUBLE
+Required.ProtobufInput.PrematureEofInPackedFieldValue.ENUM
+Required.ProtobufInput.PrematureEofInPackedFieldValue.FIXED32
+Required.ProtobufInput.PrematureEofInPackedFieldValue.FIXED64
+Required.ProtobufInput.PrematureEofInPackedFieldValue.FLOAT
+Required.ProtobufInput.PrematureEofInPackedFieldValue.INT32
+Required.ProtobufInput.PrematureEofInPackedFieldValue.INT64
+Required.ProtobufInput.PrematureEofInPackedFieldValue.SFIXED32
+Required.ProtobufInput.PrematureEofInPackedFieldValue.SFIXED64
+Required.ProtobufInput.PrematureEofInPackedFieldValue.SINT32
+Required.ProtobufInput.PrematureEofInPackedFieldValue.SINT64
+Required.ProtobufInput.PrematureEofInPackedFieldValue.UINT32
+Required.ProtobufInput.PrematureEofInPackedFieldValue.UINT64
+Required.ProtobufInput.PrematureEofInSubmessageValue.MESSAGE
+Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.BOOL
+Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.BYTES
+Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.DOUBLE
+Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.ENUM
+Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.FIXED32
+Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.FIXED64
+Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.FLOAT
+Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.INT32
+Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.INT64
+Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.MESSAGE
+Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.SFIXED32
+Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.SFIXED64
+Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.SINT32
+Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.SINT64
+Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.STRING
+Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.UINT32
+Required.ProtobufInput.PrematureEofInsideKnownNonRepeatedValue.UINT64
+Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.BOOL
+Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.BYTES
+Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.DOUBLE
+Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.ENUM
+Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.FIXED32
+Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.FIXED64
+Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.FLOAT
+Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.INT32
+Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.INT64
+Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.MESSAGE
+Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.SFIXED32
+Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.SFIXED64
+Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.SINT32
+Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.SINT64
+Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.STRING
+Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.UINT32
+Required.ProtobufInput.PrematureEofInsideKnownRepeatedValue.UINT64
+Required.ProtobufInput.PrematureEofInsideUnknownValue.BOOL
+Required.ProtobufInput.PrematureEofInsideUnknownValue.BYTES
+Required.ProtobufInput.PrematureEofInsideUnknownValue.DOUBLE
+Required.ProtobufInput.PrematureEofInsideUnknownValue.ENUM
+Required.ProtobufInput.PrematureEofInsideUnknownValue.FIXED32
+Required.ProtobufInput.PrematureEofInsideUnknownValue.FIXED64
+Required.ProtobufInput.PrematureEofInsideUnknownValue.FLOAT
+Required.ProtobufInput.PrematureEofInsideUnknownValue.INT32
+Required.ProtobufInput.PrematureEofInsideUnknownValue.INT64
+Required.ProtobufInput.PrematureEofInsideUnknownValue.MESSAGE
+Required.ProtobufInput.PrematureEofInsideUnknownValue.SFIXED32
+Required.ProtobufInput.PrematureEofInsideUnknownValue.SFIXED64
+Required.ProtobufInput.PrematureEofInsideUnknownValue.SINT32
+Required.ProtobufInput.PrematureEofInsideUnknownValue.SINT64
+Required.ProtobufInput.PrematureEofInsideUnknownValue.STRING
+Required.ProtobufInput.PrematureEofInsideUnknownValue.UINT32
+Required.ProtobufInput.PrematureEofInsideUnknownValue.UINT64
+Required.ProtobufInput.RepeatedScalarSelectsLast.BOOL.JsonOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.BOOL.ProtobufOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.DOUBLE.JsonOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.DOUBLE.ProtobufOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.FIXED32.JsonOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.FIXED32.ProtobufOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.JsonOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.ProtobufOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.FLOAT.JsonOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.FLOAT.ProtobufOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.INT32.JsonOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.INT32.ProtobufOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.INT64.JsonOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.INT64.ProtobufOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.SFIXED32.JsonOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.SFIXED32.ProtobufOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.SFIXED64.JsonOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.SFIXED64.ProtobufOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.SINT32.JsonOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.SINT32.ProtobufOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.SINT64.JsonOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.SINT64.ProtobufOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.UINT32.JsonOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.UINT32.ProtobufOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.UINT64.JsonOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.UINT64.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.BOOL.JsonOutput
+Required.ProtobufInput.ValidDataRepeated.BOOL.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.DOUBLE.JsonOutput
+Required.ProtobufInput.ValidDataRepeated.DOUBLE.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.FIXED32.JsonOutput
+Required.ProtobufInput.ValidDataRepeated.FIXED32.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.FIXED64.JsonOutput
+Required.ProtobufInput.ValidDataRepeated.FIXED64.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.FLOAT.JsonOutput
+Required.ProtobufInput.ValidDataRepeated.FLOAT.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.INT32.JsonOutput
+Required.ProtobufInput.ValidDataRepeated.INT32.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.INT64.JsonOutput
+Required.ProtobufInput.ValidDataRepeated.INT64.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.SFIXED32.JsonOutput
+Required.ProtobufInput.ValidDataRepeated.SFIXED32.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.SFIXED64.JsonOutput
+Required.ProtobufInput.ValidDataRepeated.SFIXED64.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.SINT32.JsonOutput
+Required.ProtobufInput.ValidDataRepeated.SINT32.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.SINT64.JsonOutput
+Required.ProtobufInput.ValidDataRepeated.SINT64.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.UINT32.JsonOutput
+Required.ProtobufInput.ValidDataRepeated.UINT32.ProtobufOutput
+Required.ProtobufInput.ValidDataRepeated.UINT64.JsonOutput
+Required.ProtobufInput.ValidDataRepeated.UINT64.ProtobufOutput
+Required.ProtobufInput.ValidDataScalar.BOOL.JsonOutput
+Required.ProtobufInput.ValidDataScalar.BOOL.ProtobufOutput
+Required.ProtobufInput.ValidDataScalar.DOUBLE.JsonOutput
+Required.ProtobufInput.ValidDataScalar.DOUBLE.ProtobufOutput
+Required.ProtobufInput.ValidDataScalar.FIXED32.JsonOutput
+Required.ProtobufInput.ValidDataScalar.FIXED32.ProtobufOutput
+Required.ProtobufInput.ValidDataScalar.FIXED64.JsonOutput
+Required.ProtobufInput.ValidDataScalar.FIXED64.ProtobufOutput
+Required.ProtobufInput.ValidDataScalar.FLOAT.JsonOutput
+Required.ProtobufInput.ValidDataScalar.FLOAT.ProtobufOutput
+Required.ProtobufInput.ValidDataScalar.INT32.JsonOutput
+Required.ProtobufInput.ValidDataScalar.INT32.ProtobufOutput
+Required.ProtobufInput.ValidDataScalar.INT64.JsonOutput
+Required.ProtobufInput.ValidDataScalar.INT64.ProtobufOutput
+Required.ProtobufInput.ValidDataScalar.SFIXED32.JsonOutput
+Required.ProtobufInput.ValidDataScalar.SFIXED32.ProtobufOutput
+Required.ProtobufInput.ValidDataScalar.SFIXED64.JsonOutput
+Required.ProtobufInput.ValidDataScalar.SFIXED64.ProtobufOutput
+Required.ProtobufInput.ValidDataScalar.SINT32.JsonOutput
+Required.ProtobufInput.ValidDataScalar.SINT32.ProtobufOutput
+Required.ProtobufInput.ValidDataScalar.SINT64.JsonOutput
+Required.ProtobufInput.ValidDataScalar.SINT64.ProtobufOutput
+Required.ProtobufInput.ValidDataScalar.UINT32.JsonOutput
+Required.ProtobufInput.ValidDataScalar.UINT32.ProtobufOutput
+Required.ProtobufInput.ValidDataScalar.UINT64.JsonOutput
+Required.ProtobufInput.ValidDataScalar.UINT64.ProtobufOutput
+Required.TimestampProtoInputTooLarge.JsonOutput
+Required.TimestampProtoInputTooSmall.JsonOutput
diff --git a/third_party/protobuf/conformance/failure_list_php_c.txt b/third_party/protobuf/conformance/failure_list_php_c.txt
new file mode 100644
index 0000000000..05cb218a61
--- /dev/null
+++ b/third_party/protobuf/conformance/failure_list_php_c.txt
@@ -0,0 +1,235 @@
+Recommended.FieldMaskNumbersDontRoundTrip.JsonOutput
+Recommended.FieldMaskPathsDontRoundTrip.JsonOutput
+Recommended.FieldMaskTooManyUnderscore.JsonOutput
+Recommended.JsonInput.BoolFieldIntegerOne
+Recommended.JsonInput.BoolFieldIntegerZero
+Recommended.JsonInput.DurationHas3FractionalDigits.Validator
+Recommended.JsonInput.DurationHas6FractionalDigits.Validator
+Recommended.JsonInput.DurationHas9FractionalDigits.Validator
+Recommended.JsonInput.DurationHasZeroFractionalDigit.Validator
+Recommended.JsonInput.Int64FieldBeString.Validator
+Recommended.JsonInput.OneofZeroBool.JsonOutput
+Recommended.JsonInput.OneofZeroBool.ProtobufOutput
+Recommended.JsonInput.OneofZeroBytes.JsonOutput
+Recommended.JsonInput.OneofZeroBytes.ProtobufOutput
+Recommended.JsonInput.OneofZeroDouble.JsonOutput
+Recommended.JsonInput.OneofZeroDouble.ProtobufOutput
+Recommended.JsonInput.OneofZeroEnum.JsonOutput
+Recommended.JsonInput.OneofZeroEnum.ProtobufOutput
+Recommended.JsonInput.OneofZeroFloat.JsonOutput
+Recommended.JsonInput.OneofZeroFloat.ProtobufOutput
+Recommended.JsonInput.OneofZeroString.JsonOutput
+Recommended.JsonInput.OneofZeroString.ProtobufOutput
+Recommended.JsonInput.OneofZeroUint32.JsonOutput
+Recommended.JsonInput.OneofZeroUint32.ProtobufOutput
+Recommended.JsonInput.OneofZeroUint64.JsonOutput
+Recommended.JsonInput.OneofZeroUint64.ProtobufOutput
+Recommended.JsonInput.StringEndsWithEscapeChar
+Recommended.JsonInput.StringFieldSurrogateInWrongOrder
+Recommended.JsonInput.StringFieldUnpairedHighSurrogate
+Recommended.JsonInput.StringFieldUnpairedLowSurrogate
+Recommended.JsonInput.TimestampHas3FractionalDigits.Validator
+Recommended.JsonInput.TimestampHas6FractionalDigits.Validator
+Recommended.JsonInput.TimestampHas9FractionalDigits.Validator
+Recommended.JsonInput.TimestampHasZeroFractionalDigit.Validator
+Recommended.JsonInput.TimestampZeroNormalized.Validator
+Recommended.JsonInput.Uint64FieldBeString.Validator
+Recommended.ProtobufInput.OneofZeroBool.JsonOutput
+Recommended.ProtobufInput.OneofZeroBool.ProtobufOutput
+Recommended.ProtobufInput.OneofZeroBytes.JsonOutput
+Recommended.ProtobufInput.OneofZeroBytes.ProtobufOutput
+Recommended.ProtobufInput.OneofZeroDouble.JsonOutput
+Recommended.ProtobufInput.OneofZeroDouble.ProtobufOutput
+Recommended.ProtobufInput.OneofZeroEnum.JsonOutput
+Recommended.ProtobufInput.OneofZeroEnum.ProtobufOutput
+Recommended.ProtobufInput.OneofZeroFloat.JsonOutput
+Recommended.ProtobufInput.OneofZeroFloat.ProtobufOutput
+Recommended.ProtobufInput.OneofZeroString.JsonOutput
+Recommended.ProtobufInput.OneofZeroString.ProtobufOutput
+Recommended.ProtobufInput.OneofZeroUint32.JsonOutput
+Recommended.ProtobufInput.OneofZeroUint32.ProtobufOutput
+Recommended.ProtobufInput.OneofZeroUint64.JsonOutput
+Recommended.ProtobufInput.OneofZeroUint64.ProtobufOutput
+Required.DurationProtoInputTooLarge.JsonOutput
+Required.DurationProtoInputTooSmall.JsonOutput
+Required.JsonInput.AllFieldAcceptNull.ProtobufOutput
+Required.JsonInput.Any.JsonOutput
+Required.JsonInput.Any.ProtobufOutput
+Required.JsonInput.AnyNested.JsonOutput
+Required.JsonInput.AnyNested.ProtobufOutput
+Required.JsonInput.AnyUnorderedTypeTag.JsonOutput
+Required.JsonInput.AnyUnorderedTypeTag.ProtobufOutput
+Required.JsonInput.AnyWithDuration.JsonOutput
+Required.JsonInput.AnyWithDuration.ProtobufOutput
+Required.JsonInput.AnyWithFieldMask.JsonOutput
+Required.JsonInput.AnyWithFieldMask.ProtobufOutput
+Required.JsonInput.AnyWithInt32ValueWrapper.JsonOutput
+Required.JsonInput.AnyWithInt32ValueWrapper.ProtobufOutput
+Required.JsonInput.AnyWithStruct.JsonOutput
+Required.JsonInput.AnyWithStruct.ProtobufOutput
+Required.JsonInput.AnyWithTimestamp.JsonOutput
+Required.JsonInput.AnyWithTimestamp.ProtobufOutput
+Required.JsonInput.AnyWithValueForInteger.JsonOutput
+Required.JsonInput.AnyWithValueForInteger.ProtobufOutput
+Required.JsonInput.AnyWithValueForJsonObject.JsonOutput
+Required.JsonInput.AnyWithValueForJsonObject.ProtobufOutput
+Required.JsonInput.BoolFieldFalse.ProtobufOutput
+Required.JsonInput.BoolMapField.JsonOutput
+Required.JsonInput.DoubleFieldInfinity.JsonOutput
+Required.JsonInput.DoubleFieldInfinity.ProtobufOutput
+Required.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput
+Required.JsonInput.DoubleFieldMaxNegativeValue.ProtobufOutput
+Required.JsonInput.DoubleFieldMaxPositiveValue.JsonOutput
+Required.JsonInput.DoubleFieldMaxPositiveValue.ProtobufOutput
+Required.JsonInput.DoubleFieldMinNegativeValue.JsonOutput
+Required.JsonInput.DoubleFieldMinNegativeValue.ProtobufOutput
+Required.JsonInput.DoubleFieldMinPositiveValue.JsonOutput
+Required.JsonInput.DoubleFieldMinPositiveValue.ProtobufOutput
+Required.JsonInput.DoubleFieldNan.JsonOutput
+Required.JsonInput.DoubleFieldNan.ProtobufOutput
+Required.JsonInput.DoubleFieldNegativeInfinity.JsonOutput
+Required.JsonInput.DoubleFieldNegativeInfinity.ProtobufOutput
+Required.JsonInput.DoubleFieldQuotedValue.JsonOutput
+Required.JsonInput.DoubleFieldQuotedValue.ProtobufOutput
+Required.JsonInput.DurationMaxValue.JsonOutput
+Required.JsonInput.DurationMaxValue.ProtobufOutput
+Required.JsonInput.DurationMinValue.JsonOutput
+Required.JsonInput.DurationMinValue.ProtobufOutput
+Required.JsonInput.DurationRepeatedValue.JsonOutput
+Required.JsonInput.DurationRepeatedValue.ProtobufOutput
+Required.JsonInput.EnumField.ProtobufOutput
+Required.JsonInput.EnumFieldNumericValueNonZero.JsonOutput
+Required.JsonInput.EnumFieldNumericValueNonZero.ProtobufOutput
+Required.JsonInput.EnumFieldNumericValueZero.JsonOutput
+Required.JsonInput.EnumFieldNumericValueZero.ProtobufOutput
+Required.JsonInput.EnumFieldUnknownValue.Validator
+Required.JsonInput.FieldMask.JsonOutput
+Required.JsonInput.FieldMask.ProtobufOutput
+Required.JsonInput.FloatFieldInfinity.JsonOutput
+Required.JsonInput.FloatFieldInfinity.ProtobufOutput
+Required.JsonInput.FloatFieldNan.JsonOutput
+Required.JsonInput.FloatFieldNan.ProtobufOutput
+Required.JsonInput.FloatFieldNegativeInfinity.JsonOutput
+Required.JsonInput.FloatFieldNegativeInfinity.ProtobufOutput
+Required.JsonInput.FloatFieldQuotedValue.JsonOutput
+Required.JsonInput.FloatFieldQuotedValue.ProtobufOutput
+Required.JsonInput.FloatFieldTooLarge
+Required.JsonInput.FloatFieldTooSmall
+Required.JsonInput.Int32FieldExponentialFormat.JsonOutput
+Required.JsonInput.Int32FieldExponentialFormat.ProtobufOutput
+Required.JsonInput.Int32FieldFloatTrailingZero.JsonOutput
+Required.JsonInput.Int32FieldFloatTrailingZero.ProtobufOutput
+Required.JsonInput.Int32FieldMaxFloatValue.JsonOutput
+Required.JsonInput.Int32FieldMaxFloatValue.ProtobufOutput
+Required.JsonInput.Int32FieldMinFloatValue.JsonOutput
+Required.JsonInput.Int32FieldMinFloatValue.ProtobufOutput
+Required.JsonInput.Int32FieldStringValue.JsonOutput
+Required.JsonInput.Int32FieldStringValue.ProtobufOutput
+Required.JsonInput.Int32FieldStringValueEscaped.JsonOutput
+Required.JsonInput.Int32FieldStringValueEscaped.ProtobufOutput
+Required.JsonInput.Int32MapEscapedKey.JsonOutput
+Required.JsonInput.Int32MapEscapedKey.ProtobufOutput
+Required.JsonInput.Int32MapField.JsonOutput
+Required.JsonInput.Int32MapField.ProtobufOutput
+Required.JsonInput.Int64FieldMaxValue.JsonOutput
+Required.JsonInput.Int64FieldMaxValue.ProtobufOutput
+Required.JsonInput.Int64FieldMinValue.JsonOutput
+Required.JsonInput.Int64FieldMinValue.ProtobufOutput
+Required.JsonInput.Int64MapEscapedKey.JsonOutput
+Required.JsonInput.Int64MapEscapedKey.ProtobufOutput
+Required.JsonInput.Int64MapField.JsonOutput
+Required.JsonInput.Int64MapField.ProtobufOutput
+Required.JsonInput.MessageField.JsonOutput
+Required.JsonInput.MessageField.ProtobufOutput
+Required.JsonInput.MessageMapField.JsonOutput
+Required.JsonInput.MessageMapField.ProtobufOutput
+Required.JsonInput.MessageRepeatedField.JsonOutput
+Required.JsonInput.MessageRepeatedField.ProtobufOutput
+Required.JsonInput.OptionalBoolWrapper.JsonOutput
+Required.JsonInput.OptionalBoolWrapper.ProtobufOutput
+Required.JsonInput.OptionalBytesWrapper.JsonOutput
+Required.JsonInput.OptionalBytesWrapper.ProtobufOutput
+Required.JsonInput.OptionalDoubleWrapper.JsonOutput
+Required.JsonInput.OptionalDoubleWrapper.ProtobufOutput
+Required.JsonInput.OptionalFloatWrapper.JsonOutput
+Required.JsonInput.OptionalFloatWrapper.ProtobufOutput
+Required.JsonInput.OptionalInt32Wrapper.JsonOutput
+Required.JsonInput.OptionalInt32Wrapper.ProtobufOutput
+Required.JsonInput.OptionalInt64Wrapper.JsonOutput
+Required.JsonInput.OptionalInt64Wrapper.ProtobufOutput
+Required.JsonInput.OptionalStringWrapper.JsonOutput
+Required.JsonInput.OptionalStringWrapper.ProtobufOutput
+Required.JsonInput.OptionalUint32Wrapper.JsonOutput
+Required.JsonInput.OptionalUint32Wrapper.ProtobufOutput
+Required.JsonInput.OptionalUint64Wrapper.JsonOutput
+Required.JsonInput.OptionalUint64Wrapper.ProtobufOutput
+Required.JsonInput.OptionalWrapperTypesWithNonDefaultValue.JsonOutput
+Required.JsonInput.OptionalWrapperTypesWithNonDefaultValue.ProtobufOutput
+Required.JsonInput.PrimitiveRepeatedField.JsonOutput
+Required.JsonInput.PrimitiveRepeatedField.ProtobufOutput
+Required.JsonInput.RepeatedBoolWrapper.JsonOutput
+Required.JsonInput.RepeatedBoolWrapper.ProtobufOutput
+Required.JsonInput.RepeatedBytesWrapper.JsonOutput
+Required.JsonInput.RepeatedBytesWrapper.ProtobufOutput
+Required.JsonInput.RepeatedDoubleWrapper.JsonOutput
+Required.JsonInput.RepeatedDoubleWrapper.ProtobufOutput
+Required.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt
+Required.JsonInput.RepeatedFloatWrapper.JsonOutput
+Required.JsonInput.RepeatedFloatWrapper.ProtobufOutput
+Required.JsonInput.RepeatedInt32Wrapper.JsonOutput
+Required.JsonInput.RepeatedInt32Wrapper.ProtobufOutput
+Required.JsonInput.RepeatedInt64Wrapper.JsonOutput
+Required.JsonInput.RepeatedInt64Wrapper.ProtobufOutput
+Required.JsonInput.RepeatedStringWrapper.JsonOutput
+Required.JsonInput.RepeatedStringWrapper.ProtobufOutput
+Required.JsonInput.RepeatedUint32Wrapper.JsonOutput
+Required.JsonInput.RepeatedUint32Wrapper.ProtobufOutput
+Required.JsonInput.RepeatedUint64Wrapper.JsonOutput
+Required.JsonInput.RepeatedUint64Wrapper.ProtobufOutput
+Required.JsonInput.StringFieldNotAString
+Required.JsonInput.StringFieldSurrogatePair.JsonOutput
+Required.JsonInput.StringFieldSurrogatePair.ProtobufOutput
+Required.JsonInput.Struct.JsonOutput
+Required.JsonInput.Struct.ProtobufOutput
+Required.JsonInput.TimestampMaxValue.JsonOutput
+Required.JsonInput.TimestampMaxValue.ProtobufOutput
+Required.JsonInput.TimestampMinValue.JsonOutput
+Required.JsonInput.TimestampMinValue.ProtobufOutput
+Required.JsonInput.TimestampRepeatedValue.JsonOutput
+Required.JsonInput.TimestampRepeatedValue.ProtobufOutput
+Required.JsonInput.TimestampWithNegativeOffset.JsonOutput
+Required.JsonInput.TimestampWithNegativeOffset.ProtobufOutput
+Required.JsonInput.TimestampWithPositiveOffset.JsonOutput
+Required.JsonInput.TimestampWithPositiveOffset.ProtobufOutput
+Required.JsonInput.Uint32FieldMaxFloatValue.JsonOutput
+Required.JsonInput.Uint32FieldMaxFloatValue.ProtobufOutput
+Required.JsonInput.Uint32MapField.JsonOutput
+Required.JsonInput.Uint32MapField.ProtobufOutput
+Required.JsonInput.Uint64FieldMaxValue.JsonOutput
+Required.JsonInput.Uint64FieldMaxValue.ProtobufOutput
+Required.JsonInput.Uint64MapField.JsonOutput
+Required.JsonInput.Uint64MapField.ProtobufOutput
+Required.JsonInput.ValueAcceptBool.JsonOutput
+Required.JsonInput.ValueAcceptBool.ProtobufOutput
+Required.JsonInput.ValueAcceptFloat.JsonOutput
+Required.JsonInput.ValueAcceptFloat.ProtobufOutput
+Required.JsonInput.ValueAcceptInteger.JsonOutput
+Required.JsonInput.ValueAcceptInteger.ProtobufOutput
+Required.JsonInput.ValueAcceptList.JsonOutput
+Required.JsonInput.ValueAcceptList.ProtobufOutput
+Required.JsonInput.ValueAcceptNull.JsonOutput
+Required.JsonInput.ValueAcceptNull.ProtobufOutput
+Required.JsonInput.ValueAcceptObject.JsonOutput
+Required.JsonInput.ValueAcceptObject.ProtobufOutput
+Required.JsonInput.ValueAcceptString.JsonOutput
+Required.JsonInput.ValueAcceptString.ProtobufOutput
+Required.JsonInput.WrapperTypesWithNullValue.ProtobufOutput
+Required.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput
+Required.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput
+Required.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput
+Required.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.FIXED32.ProtobufOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.ProtobufOutput
+Required.ProtobufInput.RepeatedScalarSelectsLast.UINT64.ProtobufOutput
+Required.TimestampProtoInputTooLarge.JsonOutput
+Required.TimestampProtoInputTooSmall.JsonOutput
diff --git a/third_party/protobuf/conformance/failure_list_python-post26.txt b/third_party/protobuf/conformance/failure_list_python-post26.txt
new file mode 100644
index 0000000000..19d99b044a
--- /dev/null
+++ b/third_party/protobuf/conformance/failure_list_python-post26.txt
@@ -0,0 +1,2 @@
+JsonInput.StringFieldSurrogateInWrongOrder
+JsonInput.StringFieldUnpairedHighSurrogate
diff --git a/third_party/protobuf/conformance/failure_list_python.txt b/third_party/protobuf/conformance/failure_list_python.txt
new file mode 100644
index 0000000000..9d556a036b
--- /dev/null
+++ b/third_party/protobuf/conformance/failure_list_python.txt
@@ -0,0 +1,13 @@
+Recommended.JsonInput.DoubleFieldInfinityNotQuoted
+Recommended.JsonInput.DoubleFieldNanNotQuoted
+Recommended.JsonInput.DoubleFieldNegativeInfinityNotQuoted
+Recommended.JsonInput.FloatFieldInfinityNotQuoted
+Recommended.JsonInput.FloatFieldNanNotQuoted
+Recommended.JsonInput.FloatFieldNegativeInfinityNotQuoted
+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/third_party/protobuf/conformance/failure_list_python_cpp.txt b/third_party/protobuf/conformance/failure_list_python_cpp.txt
new file mode 100644
index 0000000000..92404d2f6a
--- /dev/null
+++ b/third_party/protobuf/conformance/failure_list_python_cpp.txt
@@ -0,0 +1,38 @@
+# This is the list of conformance tests that are known to fail for the
+# Python/C++ implementation right now. These should be fixed.
+#
+# 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.
+#
+# TODO(haberman): insert links to corresponding bugs tracking the issue.
+# Should we use GitHub issues or the Google-internal bug tracker?
+
+Recommended.JsonInput.DoubleFieldInfinityNotQuoted
+Recommended.JsonInput.DoubleFieldNanNotQuoted
+Recommended.JsonInput.DoubleFieldNegativeInfinityNotQuoted
+Recommended.JsonInput.FloatFieldInfinityNotQuoted
+Recommended.JsonInput.FloatFieldNanNotQuoted
+Recommended.JsonInput.FloatFieldNegativeInfinityNotQuoted
+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/third_party/protobuf/conformance/failure_list_ruby.txt b/third_party/protobuf/conformance/failure_list_ruby.txt
new file mode 100644
index 0000000000..1de6c4390c
--- /dev/null
+++ b/third_party/protobuf/conformance/failure_list_ruby.txt
@@ -0,0 +1,203 @@
+Recommended.FieldMaskNumbersDontRoundTrip.JsonOutput
+Recommended.FieldMaskPathsDontRoundTrip.JsonOutput
+Recommended.FieldMaskTooManyUnderscore.JsonOutput
+Recommended.JsonInput.BoolFieldIntegerOne
+Recommended.JsonInput.BoolFieldIntegerZero
+Recommended.JsonInput.DurationHas3FractionalDigits.Validator
+Recommended.JsonInput.DurationHas6FractionalDigits.Validator
+Recommended.JsonInput.DurationHas9FractionalDigits.Validator
+Recommended.JsonInput.DurationHasZeroFractionalDigit.Validator
+Recommended.JsonInput.Int64FieldBeString.Validator
+Recommended.JsonInput.OneofZeroDouble.JsonOutput
+Recommended.JsonInput.OneofZeroDouble.ProtobufOutput
+Recommended.JsonInput.OneofZeroFloat.JsonOutput
+Recommended.JsonInput.OneofZeroFloat.ProtobufOutput
+Recommended.JsonInput.OneofZeroUint32.JsonOutput
+Recommended.JsonInput.OneofZeroUint32.ProtobufOutput
+Recommended.JsonInput.OneofZeroUint64.JsonOutput
+Recommended.JsonInput.OneofZeroUint64.ProtobufOutput
+Recommended.JsonInput.StringEndsWithEscapeChar
+Recommended.JsonInput.StringFieldSurrogateInWrongOrder
+Recommended.JsonInput.StringFieldUnpairedHighSurrogate
+Recommended.JsonInput.StringFieldUnpairedLowSurrogate
+Recommended.JsonInput.TimestampHas3FractionalDigits.Validator
+Recommended.JsonInput.TimestampHas6FractionalDigits.Validator
+Recommended.JsonInput.TimestampHas9FractionalDigits.Validator
+Recommended.JsonInput.TimestampHasZeroFractionalDigit.Validator
+Recommended.JsonInput.TimestampZeroNormalized.Validator
+Recommended.JsonInput.Uint64FieldBeString.Validator
+Required.DurationProtoInputTooLarge.JsonOutput
+Required.DurationProtoInputTooSmall.JsonOutput
+Required.JsonInput.Any.JsonOutput
+Required.JsonInput.Any.ProtobufOutput
+Required.JsonInput.AnyNested.JsonOutput
+Required.JsonInput.AnyNested.ProtobufOutput
+Required.JsonInput.AnyUnorderedTypeTag.JsonOutput
+Required.JsonInput.AnyUnorderedTypeTag.ProtobufOutput
+Required.JsonInput.AnyWithDuration.JsonOutput
+Required.JsonInput.AnyWithDuration.ProtobufOutput
+Required.JsonInput.AnyWithFieldMask.JsonOutput
+Required.JsonInput.AnyWithFieldMask.ProtobufOutput
+Required.JsonInput.AnyWithInt32ValueWrapper.JsonOutput
+Required.JsonInput.AnyWithInt32ValueWrapper.ProtobufOutput
+Required.JsonInput.AnyWithStruct.JsonOutput
+Required.JsonInput.AnyWithStruct.ProtobufOutput
+Required.JsonInput.AnyWithTimestamp.JsonOutput
+Required.JsonInput.AnyWithTimestamp.ProtobufOutput
+Required.JsonInput.AnyWithValueForInteger.JsonOutput
+Required.JsonInput.AnyWithValueForInteger.ProtobufOutput
+Required.JsonInput.AnyWithValueForJsonObject.JsonOutput
+Required.JsonInput.AnyWithValueForJsonObject.ProtobufOutput
+Required.JsonInput.DoubleFieldInfinity.JsonOutput
+Required.JsonInput.DoubleFieldInfinity.ProtobufOutput
+Required.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput
+Required.JsonInput.DoubleFieldMaxNegativeValue.ProtobufOutput
+Required.JsonInput.DoubleFieldMaxPositiveValue.JsonOutput
+Required.JsonInput.DoubleFieldMaxPositiveValue.ProtobufOutput
+Required.JsonInput.DoubleFieldMinNegativeValue.JsonOutput
+Required.JsonInput.DoubleFieldMinNegativeValue.ProtobufOutput
+Required.JsonInput.DoubleFieldMinPositiveValue.JsonOutput
+Required.JsonInput.DoubleFieldMinPositiveValue.ProtobufOutput
+Required.JsonInput.DoubleFieldNan.JsonOutput
+Required.JsonInput.DoubleFieldNan.ProtobufOutput
+Required.JsonInput.DoubleFieldNegativeInfinity.JsonOutput
+Required.JsonInput.DoubleFieldNegativeInfinity.ProtobufOutput
+Required.JsonInput.DoubleFieldQuotedValue.JsonOutput
+Required.JsonInput.DoubleFieldQuotedValue.ProtobufOutput
+Required.JsonInput.DurationMaxValue.JsonOutput
+Required.JsonInput.DurationMaxValue.ProtobufOutput
+Required.JsonInput.DurationMinValue.JsonOutput
+Required.JsonInput.DurationMinValue.ProtobufOutput
+Required.JsonInput.DurationRepeatedValue.JsonOutput
+Required.JsonInput.DurationRepeatedValue.ProtobufOutput
+Required.JsonInput.EnumFieldNumericValueNonZero.JsonOutput
+Required.JsonInput.EnumFieldNumericValueNonZero.ProtobufOutput
+Required.JsonInput.EnumFieldNumericValueZero.JsonOutput
+Required.JsonInput.EnumFieldNumericValueZero.ProtobufOutput
+Required.JsonInput.EnumFieldUnknownValue.Validator
+Required.JsonInput.FieldMask.JsonOutput
+Required.JsonInput.FieldMask.ProtobufOutput
+Required.JsonInput.FloatFieldInfinity.JsonOutput
+Required.JsonInput.FloatFieldInfinity.ProtobufOutput
+Required.JsonInput.FloatFieldNan.JsonOutput
+Required.JsonInput.FloatFieldNan.ProtobufOutput
+Required.JsonInput.FloatFieldNegativeInfinity.JsonOutput
+Required.JsonInput.FloatFieldNegativeInfinity.ProtobufOutput
+Required.JsonInput.FloatFieldQuotedValue.JsonOutput
+Required.JsonInput.FloatFieldQuotedValue.ProtobufOutput
+Required.JsonInput.FloatFieldTooLarge
+Required.JsonInput.FloatFieldTooSmall
+Required.JsonInput.Int32FieldExponentialFormat.JsonOutput
+Required.JsonInput.Int32FieldExponentialFormat.ProtobufOutput
+Required.JsonInput.Int32FieldFloatTrailingZero.JsonOutput
+Required.JsonInput.Int32FieldFloatTrailingZero.ProtobufOutput
+Required.JsonInput.Int32FieldMaxFloatValue.JsonOutput
+Required.JsonInput.Int32FieldMaxFloatValue.ProtobufOutput
+Required.JsonInput.Int32FieldMinFloatValue.JsonOutput
+Required.JsonInput.Int32FieldMinFloatValue.ProtobufOutput
+Required.JsonInput.Int32FieldStringValue.JsonOutput
+Required.JsonInput.Int32FieldStringValue.ProtobufOutput
+Required.JsonInput.Int32FieldStringValueEscaped.JsonOutput
+Required.JsonInput.Int32FieldStringValueEscaped.ProtobufOutput
+Required.JsonInput.Int32MapEscapedKey.JsonOutput
+Required.JsonInput.Int32MapEscapedKey.ProtobufOutput
+Required.JsonInput.Int32MapField.JsonOutput
+Required.JsonInput.Int32MapField.ProtobufOutput
+Required.JsonInput.Int64FieldMaxValue.JsonOutput
+Required.JsonInput.Int64FieldMaxValue.ProtobufOutput
+Required.JsonInput.Int64FieldMinValue.JsonOutput
+Required.JsonInput.Int64FieldMinValue.ProtobufOutput
+Required.JsonInput.Int64MapEscapedKey.JsonOutput
+Required.JsonInput.Int64MapEscapedKey.ProtobufOutput
+Required.JsonInput.Int64MapField.JsonOutput
+Required.JsonInput.Int64MapField.ProtobufOutput
+Required.JsonInput.MessageField.JsonOutput
+Required.JsonInput.MessageField.ProtobufOutput
+Required.JsonInput.MessageMapField.JsonOutput
+Required.JsonInput.MessageMapField.ProtobufOutput
+Required.JsonInput.MessageRepeatedField.JsonOutput
+Required.JsonInput.MessageRepeatedField.ProtobufOutput
+Required.JsonInput.OptionalBoolWrapper.JsonOutput
+Required.JsonInput.OptionalBoolWrapper.ProtobufOutput
+Required.JsonInput.OptionalBytesWrapper.JsonOutput
+Required.JsonInput.OptionalBytesWrapper.ProtobufOutput
+Required.JsonInput.OptionalDoubleWrapper.JsonOutput
+Required.JsonInput.OptionalDoubleWrapper.ProtobufOutput
+Required.JsonInput.OptionalFloatWrapper.JsonOutput
+Required.JsonInput.OptionalFloatWrapper.ProtobufOutput
+Required.JsonInput.OptionalInt32Wrapper.JsonOutput
+Required.JsonInput.OptionalInt32Wrapper.ProtobufOutput
+Required.JsonInput.OptionalInt64Wrapper.JsonOutput
+Required.JsonInput.OptionalInt64Wrapper.ProtobufOutput
+Required.JsonInput.OptionalStringWrapper.JsonOutput
+Required.JsonInput.OptionalStringWrapper.ProtobufOutput
+Required.JsonInput.OptionalUint32Wrapper.JsonOutput
+Required.JsonInput.OptionalUint32Wrapper.ProtobufOutput
+Required.JsonInput.OptionalUint64Wrapper.JsonOutput
+Required.JsonInput.OptionalUint64Wrapper.ProtobufOutput
+Required.JsonInput.OptionalWrapperTypesWithNonDefaultValue.JsonOutput
+Required.JsonInput.OptionalWrapperTypesWithNonDefaultValue.ProtobufOutput
+Required.JsonInput.PrimitiveRepeatedField.JsonOutput
+Required.JsonInput.PrimitiveRepeatedField.ProtobufOutput
+Required.JsonInput.RepeatedBoolWrapper.JsonOutput
+Required.JsonInput.RepeatedBoolWrapper.ProtobufOutput
+Required.JsonInput.RepeatedBytesWrapper.JsonOutput
+Required.JsonInput.RepeatedBytesWrapper.ProtobufOutput
+Required.JsonInput.RepeatedDoubleWrapper.JsonOutput
+Required.JsonInput.RepeatedDoubleWrapper.ProtobufOutput
+Required.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt
+Required.JsonInput.RepeatedFloatWrapper.JsonOutput
+Required.JsonInput.RepeatedFloatWrapper.ProtobufOutput
+Required.JsonInput.RepeatedInt32Wrapper.JsonOutput
+Required.JsonInput.RepeatedInt32Wrapper.ProtobufOutput
+Required.JsonInput.RepeatedInt64Wrapper.JsonOutput
+Required.JsonInput.RepeatedInt64Wrapper.ProtobufOutput
+Required.JsonInput.RepeatedStringWrapper.JsonOutput
+Required.JsonInput.RepeatedStringWrapper.ProtobufOutput
+Required.JsonInput.RepeatedUint32Wrapper.JsonOutput
+Required.JsonInput.RepeatedUint32Wrapper.ProtobufOutput
+Required.JsonInput.RepeatedUint64Wrapper.JsonOutput
+Required.JsonInput.RepeatedUint64Wrapper.ProtobufOutput
+Required.JsonInput.StringFieldNotAString
+Required.JsonInput.StringFieldSurrogatePair.JsonOutput
+Required.JsonInput.StringFieldSurrogatePair.ProtobufOutput
+Required.JsonInput.Struct.JsonOutput
+Required.JsonInput.Struct.ProtobufOutput
+Required.JsonInput.TimestampMaxValue.JsonOutput
+Required.JsonInput.TimestampMaxValue.ProtobufOutput
+Required.JsonInput.TimestampMinValue.JsonOutput
+Required.JsonInput.TimestampMinValue.ProtobufOutput
+Required.JsonInput.TimestampRepeatedValue.JsonOutput
+Required.JsonInput.TimestampRepeatedValue.ProtobufOutput
+Required.JsonInput.TimestampWithNegativeOffset.JsonOutput
+Required.JsonInput.TimestampWithNegativeOffset.ProtobufOutput
+Required.JsonInput.TimestampWithPositiveOffset.JsonOutput
+Required.JsonInput.TimestampWithPositiveOffset.ProtobufOutput
+Required.JsonInput.Uint32FieldMaxFloatValue.JsonOutput
+Required.JsonInput.Uint32FieldMaxFloatValue.ProtobufOutput
+Required.JsonInput.Uint32MapField.JsonOutput
+Required.JsonInput.Uint32MapField.ProtobufOutput
+Required.JsonInput.Uint64FieldMaxValue.JsonOutput
+Required.JsonInput.Uint64FieldMaxValue.ProtobufOutput
+Required.JsonInput.Uint64MapField.JsonOutput
+Required.JsonInput.Uint64MapField.ProtobufOutput
+Required.JsonInput.ValueAcceptBool.JsonOutput
+Required.JsonInput.ValueAcceptBool.ProtobufOutput
+Required.JsonInput.ValueAcceptFloat.JsonOutput
+Required.JsonInput.ValueAcceptFloat.ProtobufOutput
+Required.JsonInput.ValueAcceptInteger.JsonOutput
+Required.JsonInput.ValueAcceptInteger.ProtobufOutput
+Required.JsonInput.ValueAcceptList.JsonOutput
+Required.JsonInput.ValueAcceptList.ProtobufOutput
+Required.JsonInput.ValueAcceptNull.JsonOutput
+Required.JsonInput.ValueAcceptNull.ProtobufOutput
+Required.JsonInput.ValueAcceptObject.JsonOutput
+Required.JsonInput.ValueAcceptObject.ProtobufOutput
+Required.JsonInput.ValueAcceptString.JsonOutput
+Required.JsonInput.ValueAcceptString.ProtobufOutput
+Required.ProtobufInput.DoubleFieldNormalizeQuietNan.JsonOutput
+Required.ProtobufInput.DoubleFieldNormalizeSignalingNan.JsonOutput
+Required.ProtobufInput.FloatFieldNormalizeQuietNan.JsonOutput
+Required.ProtobufInput.FloatFieldNormalizeSignalingNan.JsonOutput
+Required.TimestampProtoInputTooLarge.JsonOutput
+Required.TimestampProtoInputTooSmall.JsonOutput
diff --git a/third_party/protobuf/conformance/third_party/jsoncpp/json.h b/third_party/protobuf/conformance/third_party/jsoncpp/json.h
new file mode 100644
index 0000000000..42e7e7f4ad
--- /dev/null
+++ b/third_party/protobuf/conformance/third_party/jsoncpp/json.h
@@ -0,0 +1,2075 @@
+/// Json-cpp amalgated header (http://jsoncpp.sourceforge.net/).
+/// It is intended to be used with #include "json/json.h"
+
+// //////////////////////////////////////////////////////////////////////
+// Beginning of content of file: LICENSE
+// //////////////////////////////////////////////////////////////////////
+
+/*
+The JsonCpp library's source code, including accompanying documentation,
+tests and demonstration applications, are licensed under the following
+conditions...
+
+The author (Baptiste Lepilleur) explicitly disclaims copyright in all
+jurisdictions which recognize such a disclaimer. In such jurisdictions,
+this software is released into the Public Domain.
+
+In jurisdictions which do not recognize Public Domain property (e.g. Germany as of
+2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is
+released under the terms of the MIT License (see below).
+
+In jurisdictions which recognize Public Domain property, the user of this
+software may choose to accept it either as 1) Public Domain, 2) under the
+conditions of the MIT License (see below), or 3) under the terms of dual
+Public Domain/MIT License conditions described here, as they choose.
+
+The MIT License is about as close to Public Domain as a license can get, and is
+described in clear, concise terms at:
+
+ http://en.wikipedia.org/wiki/MIT_License
+
+The full text of the MIT License follows:
+
+========================================================================
+Copyright (c) 2007-2010 Baptiste Lepilleur
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use, copy,
+modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+========================================================================
+(END LICENSE TEXT)
+
+The MIT license is compatible with both the GPL and commercial
+software, affording one all of the rights of Public Domain with the
+minor nuisance of being required to keep the above copyright notice
+and license text in the source code. Note also that by accepting the
+Public Domain "license" you can re-license your copy using whatever
+license you like.
+
+*/
+
+// //////////////////////////////////////////////////////////////////////
+// End of content of file: LICENSE
+// //////////////////////////////////////////////////////////////////////
+
+
+
+
+
+#ifndef JSON_AMALGATED_H_INCLUDED
+# define JSON_AMALGATED_H_INCLUDED
+/// If defined, indicates that the source file is amalgated
+/// to prevent private header inclusion.
+#define JSON_IS_AMALGAMATION
+
+// //////////////////////////////////////////////////////////////////////
+// Beginning of content of file: include/json/version.h
+// //////////////////////////////////////////////////////////////////////
+
+// DO NOT EDIT. This file (and "version") is generated by CMake.
+// Run CMake configure step to update it.
+#ifndef JSON_VERSION_H_INCLUDED
+# define JSON_VERSION_H_INCLUDED
+
+# define JSONCPP_VERSION_STRING "1.6.5"
+# define JSONCPP_VERSION_MAJOR 1
+# define JSONCPP_VERSION_MINOR 6
+# define JSONCPP_VERSION_PATCH 5
+# define JSONCPP_VERSION_QUALIFIER
+# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))
+
+#endif // JSON_VERSION_H_INCLUDED
+
+// //////////////////////////////////////////////////////////////////////
+// End of content of file: include/json/version.h
+// //////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+// //////////////////////////////////////////////////////////////////////
+// Beginning of content of file: include/json/config.h
+// //////////////////////////////////////////////////////////////////////
+
+// Copyright 2007-2010 Baptiste Lepilleur
+// Distributed under MIT license, or public domain if desired and
+// recognized in your jurisdiction.
+// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
+
+#ifndef JSON_CONFIG_H_INCLUDED
+#define JSON_CONFIG_H_INCLUDED
+
+/// If defined, indicates that json library is embedded in CppTL library.
+//# define JSON_IN_CPPTL 1
+
+/// If defined, indicates that json may leverage CppTL library
+//# define JSON_USE_CPPTL 1
+/// If defined, indicates that cpptl vector based map should be used instead of
+/// std::map
+/// as Value container.
+//# define JSON_USE_CPPTL_SMALLMAP 1
+
+// If non-zero, the library uses exceptions to report bad input instead of C
+// assertion macros. The default is to use exceptions.
+#ifndef JSON_USE_EXCEPTION
+#define JSON_USE_EXCEPTION 1
+#endif
+
+/// If defined, indicates that the source file is amalgated
+/// to prevent private header inclusion.
+/// Remarks: it is automatically defined in the generated amalgated header.
+// #define JSON_IS_AMALGAMATION
+
+#ifdef JSON_IN_CPPTL
+#include <cpptl/config.h>
+#ifndef JSON_USE_CPPTL
+#define JSON_USE_CPPTL 1
+#endif
+#endif
+
+#ifdef JSON_IN_CPPTL
+#define JSON_API CPPTL_API
+#elif defined(JSON_DLL_BUILD)
+#if defined(_MSC_VER)
+#define JSON_API __declspec(dllexport)
+#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
+#endif // if defined(_MSC_VER)
+#elif defined(JSON_DLL)
+#if defined(_MSC_VER)
+#define JSON_API __declspec(dllimport)
+#define JSONCPP_DISABLE_DLL_INTERFACE_WARNING
+#endif // if defined(_MSC_VER)
+#endif // ifdef JSON_IN_CPPTL
+#if !defined(JSON_API)
+#define JSON_API
+#endif
+
+// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for
+// integer
+// Storages, and 64 bits integer support is disabled.
+// #define JSON_NO_INT64 1
+
+#if defined(_MSC_VER) // MSVC
+# if _MSC_VER <= 1200 // MSVC 6
+ // Microsoft Visual Studio 6 only support conversion from __int64 to double
+ // (no conversion from unsigned __int64).
+# define JSON_USE_INT64_DOUBLE_CONVERSION 1
+ // Disable warning 4786 for VS6 caused by STL (identifier was truncated to '255'
+ // characters in the debug information)
+ // All projects I've ever seen with VS6 were using this globally (not bothering
+ // with pragma push/pop).
+# pragma warning(disable : 4786)
+# endif // MSVC 6
+
+# if _MSC_VER >= 1500 // MSVC 2008
+ /// Indicates that the following function is deprecated.
+# define JSONCPP_DEPRECATED(message) __declspec(deprecated(message))
+# endif
+
+#endif // defined(_MSC_VER)
+
+
+#ifndef JSON_HAS_RVALUE_REFERENCES
+
+#if defined(_MSC_VER) && _MSC_VER >= 1600 // MSVC >= 2010
+#define JSON_HAS_RVALUE_REFERENCES 1
+#endif // MSVC >= 2010
+
+#ifdef __clang__
+#if __has_feature(cxx_rvalue_references)
+#define JSON_HAS_RVALUE_REFERENCES 1
+#endif // has_feature
+
+#elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)
+#if defined(__GXX_EXPERIMENTAL_CXX0X__) || (__cplusplus >= 201103L)
+#define JSON_HAS_RVALUE_REFERENCES 1
+#endif // GXX_EXPERIMENTAL
+
+#endif // __clang__ || __GNUC__
+
+#endif // not defined JSON_HAS_RVALUE_REFERENCES
+
+#ifndef JSON_HAS_RVALUE_REFERENCES
+#define JSON_HAS_RVALUE_REFERENCES 0
+#endif
+
+#ifdef __clang__
+#elif defined __GNUC__ // not clang (gcc comes later since clang emulates gcc)
+# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
+# define JSONCPP_DEPRECATED(message) __attribute__ ((deprecated(message)))
+# elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
+# define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__))
+# endif // GNUC version
+#endif // __clang__ || __GNUC__
+
+#if !defined(JSONCPP_DEPRECATED)
+#define JSONCPP_DEPRECATED(message)
+#endif // if !defined(JSONCPP_DEPRECATED)
+
+namespace Json {
+typedef int Int;
+typedef unsigned int UInt;
+#if defined(JSON_NO_INT64)
+typedef int LargestInt;
+typedef unsigned int LargestUInt;
+#undef JSON_HAS_INT64
+#else // if defined(JSON_NO_INT64)
+// For Microsoft Visual use specific types as long long is not supported
+#if defined(_MSC_VER) // Microsoft Visual Studio
+typedef __int64 Int64;
+typedef unsigned __int64 UInt64;
+#else // if defined(_MSC_VER) // Other platforms, use long long
+typedef long long int Int64;
+typedef unsigned long long int UInt64;
+#endif // if defined(_MSC_VER)
+typedef Int64 LargestInt;
+typedef UInt64 LargestUInt;
+#define JSON_HAS_INT64
+#endif // if defined(JSON_NO_INT64)
+} // end namespace Json
+
+#endif // JSON_CONFIG_H_INCLUDED
+
+// //////////////////////////////////////////////////////////////////////
+// End of content of file: include/json/config.h
+// //////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+// //////////////////////////////////////////////////////////////////////
+// Beginning of content of file: include/json/forwards.h
+// //////////////////////////////////////////////////////////////////////
+
+// Copyright 2007-2010 Baptiste Lepilleur
+// Distributed under MIT license, or public domain if desired and
+// recognized in your jurisdiction.
+// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
+
+#ifndef JSON_FORWARDS_H_INCLUDED
+#define JSON_FORWARDS_H_INCLUDED
+
+#if !defined(JSON_IS_AMALGAMATION)
+#include "config.h"
+#endif // if !defined(JSON_IS_AMALGAMATION)
+
+namespace Json {
+
+// writer.h
+class FastWriter;
+class StyledWriter;
+
+// reader.h
+class Reader;
+
+// features.h
+class Features;
+
+// value.h
+typedef unsigned int ArrayIndex;
+class StaticString;
+class Path;
+class PathArgument;
+class Value;
+class ValueIteratorBase;
+class ValueIterator;
+class ValueConstIterator;
+
+} // namespace Json
+
+#endif // JSON_FORWARDS_H_INCLUDED
+
+// //////////////////////////////////////////////////////////////////////
+// End of content of file: include/json/forwards.h
+// //////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+// //////////////////////////////////////////////////////////////////////
+// Beginning of content of file: include/json/features.h
+// //////////////////////////////////////////////////////////////////////
+
+// Copyright 2007-2010 Baptiste Lepilleur
+// Distributed under MIT license, or public domain if desired and
+// recognized in your jurisdiction.
+// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
+
+#ifndef CPPTL_JSON_FEATURES_H_INCLUDED
+#define CPPTL_JSON_FEATURES_H_INCLUDED
+
+#if !defined(JSON_IS_AMALGAMATION)
+#include "forwards.h"
+#endif // if !defined(JSON_IS_AMALGAMATION)
+
+namespace Json {
+
+/** \brief Configuration passed to reader and writer.
+ * This configuration object can be used to force the Reader or Writer
+ * to behave in a standard conforming way.
+ */
+class JSON_API Features {
+public:
+ /** \brief A configuration that allows all features and assumes all strings
+ * are UTF-8.
+ * - C & C++ comments are allowed
+ * - Root object can be any JSON value
+ * - Assumes Value strings are encoded in UTF-8
+ */
+ static Features all();
+
+ /** \brief A configuration that is strictly compatible with the JSON
+ * specification.
+ * - Comments are forbidden.
+ * - Root object must be either an array or an object value.
+ * - Assumes Value strings are encoded in UTF-8
+ */
+ static Features strictMode();
+
+ /** \brief Initialize the configuration like JsonConfig::allFeatures;
+ */
+ Features();
+
+ /// \c true if comments are allowed. Default: \c true.
+ bool allowComments_;
+
+ /// \c true if root must be either an array or an object value. Default: \c
+ /// false.
+ bool strictRoot_;
+
+ /// \c true if dropped null placeholders are allowed. Default: \c false.
+ bool allowDroppedNullPlaceholders_;
+
+ /// \c true if numeric object key are allowed. Default: \c false.
+ bool allowNumericKeys_;
+};
+
+} // namespace Json
+
+#endif // CPPTL_JSON_FEATURES_H_INCLUDED
+
+// //////////////////////////////////////////////////////////////////////
+// End of content of file: include/json/features.h
+// //////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+// //////////////////////////////////////////////////////////////////////
+// Beginning of content of file: include/json/value.h
+// //////////////////////////////////////////////////////////////////////
+
+// Copyright 2007-2010 Baptiste Lepilleur
+// Distributed under MIT license, or public domain if desired and
+// recognized in your jurisdiction.
+// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
+
+#ifndef CPPTL_JSON_H_INCLUDED
+#define CPPTL_JSON_H_INCLUDED
+
+#if !defined(JSON_IS_AMALGAMATION)
+#include "forwards.h"
+#endif // if !defined(JSON_IS_AMALGAMATION)
+#include <string>
+#include <vector>
+#include <exception>
+
+#ifndef JSON_USE_CPPTL_SMALLMAP
+#include <map>
+#else
+#include <cpptl/smallmap.h>
+#endif
+#ifdef JSON_USE_CPPTL
+#include <cpptl/forwards.h>
+#endif
+
+// Disable warning C4251: <data member>: <type> needs to have dll-interface to
+// be used by...
+#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
+#pragma warning(push)
+#pragma warning(disable : 4251)
+#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
+
+/** \brief JSON (JavaScript Object Notation).
+ */
+namespace Json {
+
+/** Base class for all exceptions we throw.
+ *
+ * We use nothing but these internally. Of course, STL can throw others.
+ */
+class JSON_API Exception : public std::exception {
+public:
+ Exception(std::string const& msg);
+ ~Exception() throw() override;
+ char const* what() const throw() override;
+protected:
+ std::string msg_;
+};
+
+/** Exceptions which the user cannot easily avoid.
+ *
+ * E.g. out-of-memory (when we use malloc), stack-overflow, malicious input
+ *
+ * \remark derived from Json::Exception
+ */
+class JSON_API RuntimeError : public Exception {
+public:
+ RuntimeError(std::string const& msg);
+};
+
+/** Exceptions thrown by JSON_ASSERT/JSON_FAIL macros.
+ *
+ * These are precondition-violations (user bugs) and internal errors (our bugs).
+ *
+ * \remark derived from Json::Exception
+ */
+class JSON_API LogicError : public Exception {
+public:
+ LogicError(std::string const& msg);
+};
+
+/// used internally
+void throwRuntimeError(std::string const& msg);
+/// used internally
+void throwLogicError(std::string const& msg);
+
+/** \brief Type of the value held by a Value object.
+ */
+enum ValueType {
+ nullValue = 0, ///< 'null' value
+ intValue, ///< signed integer value
+ uintValue, ///< unsigned integer value
+ realValue, ///< double value
+ stringValue, ///< UTF-8 string value
+ booleanValue, ///< bool value
+ arrayValue, ///< array value (ordered list)
+ objectValue ///< object value (collection of name/value pairs).
+};
+
+enum CommentPlacement {
+ commentBefore = 0, ///< a comment placed on the line before a value
+ commentAfterOnSameLine, ///< a comment just after a value on the same line
+ commentAfter, ///< a comment on the line after a value (only make sense for
+ /// root value)
+ numberOfCommentPlacement
+};
+
+//# ifdef JSON_USE_CPPTL
+// typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
+// typedef CppTL::AnyEnumerator<const Value &> EnumValues;
+//# endif
+
+/** \brief Lightweight wrapper to tag static string.
+ *
+ * Value constructor and objectValue member assignement takes advantage of the
+ * StaticString and avoid the cost of string duplication when storing the
+ * string or the member name.
+ *
+ * Example of usage:
+ * \code
+ * Json::Value aValue( StaticString("some text") );
+ * Json::Value object;
+ * static const StaticString code("code");
+ * object[code] = 1234;
+ * \endcode
+ */
+class JSON_API StaticString {
+public:
+ explicit StaticString(const char* czstring) : c_str_(czstring) {}
+
+ operator const char*() const { return c_str_; }
+
+ const char* c_str() const { return c_str_; }
+
+private:
+ const char* c_str_;
+};
+
+/** \brief Represents a <a HREF="http://www.json.org">JSON</a> value.
+ *
+ * This class is a discriminated union wrapper that can represents a:
+ * - signed integer [range: Value::minInt - Value::maxInt]
+ * - unsigned integer (range: 0 - Value::maxUInt)
+ * - double
+ * - UTF-8 string
+ * - boolean
+ * - 'null'
+ * - an ordered list of Value
+ * - collection of name/value pairs (javascript object)
+ *
+ * The type of the held value is represented by a #ValueType and
+ * can be obtained using type().
+ *
+ * Values of an #objectValue or #arrayValue can be accessed using operator[]()
+ * methods.
+ * Non-const methods will automatically create the a #nullValue element
+ * if it does not exist.
+ * The sequence of an #arrayValue will be automatically resized and initialized
+ * with #nullValue. resize() can be used to enlarge or truncate an #arrayValue.
+ *
+ * The get() methods can be used to obtain default value in the case the
+ * required element does not exist.
+ *
+ * It is possible to iterate over the list of a #objectValue values using
+ * the getMemberNames() method.
+ *
+ * \note #Value string-length fit in size_t, but keys must be < 2^30.
+ * (The reason is an implementation detail.) A #CharReader will raise an
+ * exception if a bound is exceeded to avoid security holes in your app,
+ * but the Value API does *not* check bounds. That is the responsibility
+ * of the caller.
+ */
+class JSON_API Value {
+ friend class ValueIteratorBase;
+public:
+ typedef std::vector<std::string> Members;
+ typedef ValueIterator iterator;
+ typedef ValueConstIterator const_iterator;
+ typedef Json::UInt UInt;
+ typedef Json::Int Int;
+#if defined(JSON_HAS_INT64)
+ typedef Json::UInt64 UInt64;
+ typedef Json::Int64 Int64;
+#endif // defined(JSON_HAS_INT64)
+ typedef Json::LargestInt LargestInt;
+ typedef Json::LargestUInt LargestUInt;
+ typedef Json::ArrayIndex ArrayIndex;
+
+ static const Value& null; ///< We regret this reference to a global instance; prefer the simpler Value().
+ static const Value& nullRef; ///< just a kludge for binary-compatibility; same as null
+ /// Minimum signed integer value that can be stored in a Json::Value.
+ static const LargestInt minLargestInt;
+ /// Maximum signed integer value that can be stored in a Json::Value.
+ static const LargestInt maxLargestInt;
+ /// Maximum unsigned integer value that can be stored in a Json::Value.
+ static const LargestUInt maxLargestUInt;
+
+ /// Minimum signed int value that can be stored in a Json::Value.
+ static const Int minInt;
+ /// Maximum signed int value that can be stored in a Json::Value.
+ static const Int maxInt;
+ /// Maximum unsigned int value that can be stored in a Json::Value.
+ static const UInt maxUInt;
+
+#if defined(JSON_HAS_INT64)
+ /// Minimum signed 64 bits int value that can be stored in a Json::Value.
+ static const Int64 minInt64;
+ /// Maximum signed 64 bits int value that can be stored in a Json::Value.
+ static const Int64 maxInt64;
+ /// Maximum unsigned 64 bits int value that can be stored in a Json::Value.
+ static const UInt64 maxUInt64;
+#endif // defined(JSON_HAS_INT64)
+
+private:
+#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
+ class CZString {
+ public:
+ enum DuplicationPolicy {
+ noDuplication = 0,
+ duplicate,
+ duplicateOnCopy
+ };
+ CZString(ArrayIndex index);
+ CZString(char const* str, unsigned length, DuplicationPolicy allocate);
+ CZString(CZString const& other);
+#if JSON_HAS_RVALUE_REFERENCES
+ CZString(CZString&& other);
+#endif
+ ~CZString();
+ CZString& operator=(CZString other);
+ bool operator<(CZString const& other) const;
+ bool operator==(CZString const& other) const;
+ ArrayIndex index() const;
+ //const char* c_str() const; ///< \deprecated
+ char const* data() const;
+ unsigned length() const;
+ bool isStaticString() const;
+
+ private:
+ void swap(CZString& other);
+
+ struct StringStorage {
+ unsigned policy_: 2;
+ unsigned length_: 30; // 1GB max
+ };
+
+ char const* cstr_; // actually, a prefixed string, unless policy is noDup
+ union {
+ ArrayIndex index_;
+ StringStorage storage_;
+ };
+ };
+
+public:
+#ifndef JSON_USE_CPPTL_SMALLMAP
+ typedef std::map<CZString, Value> ObjectValues;
+#else
+ typedef CppTL::SmallMap<CZString, Value> ObjectValues;
+#endif // ifndef JSON_USE_CPPTL_SMALLMAP
+#endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
+
+public:
+ /** \brief Create a default Value of the given type.
+
+ This is a very useful constructor.
+ To create an empty array, pass arrayValue.
+ To create an empty object, pass objectValue.
+ Another Value can then be set to this one by assignment.
+This is useful since clear() and resize() will not alter types.
+
+ Examples:
+\code
+Json::Value null_value; // null
+Json::Value arr_value(Json::arrayValue); // []
+Json::Value obj_value(Json::objectValue); // {}
+\endcode
+ */
+ Value(ValueType type = nullValue);
+ Value(Int value);
+ Value(UInt value);
+#if defined(JSON_HAS_INT64)
+ Value(Int64 value);
+ Value(UInt64 value);
+#endif // if defined(JSON_HAS_INT64)
+ Value(double value);
+ Value(const char* value); ///< Copy til first 0. (NULL causes to seg-fault.)
+ Value(const char* begin, const char* end); ///< Copy all, incl zeroes.
+ /** \brief Constructs a value from a static string.
+
+ * Like other value string constructor but do not duplicate the string for
+ * internal storage. The given string must remain alive after the call to this
+ * constructor.
+ * \note This works only for null-terminated strings. (We cannot change the
+ * size of this class, so we have nowhere to store the length,
+ * which might be computed later for various operations.)
+ *
+ * Example of usage:
+ * \code
+ * static StaticString foo("some text");
+ * Json::Value aValue(foo);
+ * \endcode
+ */
+ Value(const StaticString& value);
+ Value(const std::string& value); ///< Copy data() til size(). Embedded zeroes too.
+#ifdef JSON_USE_CPPTL
+ Value(const CppTL::ConstString& value);
+#endif
+ Value(bool value);
+ /// Deep copy.
+ Value(const Value& other);
+#if JSON_HAS_RVALUE_REFERENCES
+ /// Move constructor
+ Value(Value&& other);
+#endif
+ ~Value();
+
+ /// Deep copy, then swap(other).
+ /// \note Over-write existing comments. To preserve comments, use #swapPayload().
+ Value& operator=(Value other);
+ /// Swap everything.
+ void swap(Value& other);
+ /// Swap values but leave comments and source offsets in place.
+ void swapPayload(Value& other);
+
+ ValueType type() const;
+
+ /// Compare payload only, not comments etc.
+ bool operator<(const Value& other) const;
+ bool operator<=(const Value& other) const;
+ bool operator>=(const Value& other) const;
+ bool operator>(const Value& other) const;
+ bool operator==(const Value& other) const;
+ bool operator!=(const Value& other) const;
+ int compare(const Value& other) const;
+
+ const char* asCString() const; ///< Embedded zeroes could cause you trouble!
+ std::string asString() const; ///< Embedded zeroes are possible.
+ /** Get raw char* of string-value.
+ * \return false if !string. (Seg-fault if str or end are NULL.)
+ */
+ bool getString(
+ char const** begin, char const** end) const;
+#ifdef JSON_USE_CPPTL
+ CppTL::ConstString asConstString() const;
+#endif
+ Int asInt() const;
+ UInt asUInt() const;
+#if defined(JSON_HAS_INT64)
+ Int64 asInt64() const;
+ UInt64 asUInt64() const;
+#endif // if defined(JSON_HAS_INT64)
+ LargestInt asLargestInt() const;
+ LargestUInt asLargestUInt() const;
+ float asFloat() const;
+ double asDouble() const;
+ bool asBool() const;
+
+ bool isNull() const;
+ bool isBool() const;
+ bool isInt() const;
+ bool isInt64() const;
+ bool isUInt() const;
+ bool isUInt64() const;
+ bool isIntegral() const;
+ bool isDouble() const;
+ bool isNumeric() const;
+ bool isString() const;
+ bool isArray() const;
+ bool isObject() const;
+
+ bool isConvertibleTo(ValueType other) const;
+
+ /// Number of values in array or object
+ ArrayIndex size() const;
+
+ /// \brief Return true if empty array, empty object, or null;
+ /// otherwise, false.
+ bool empty() const;
+
+ /// Return isNull()
+ bool operator!() const;
+
+ /// Remove all object members and array elements.
+ /// \pre type() is arrayValue, objectValue, or nullValue
+ /// \post type() is unchanged
+ void clear();
+
+ /// Resize the array to size elements.
+ /// New elements are initialized to null.
+ /// May only be called on nullValue or arrayValue.
+ /// \pre type() is arrayValue or nullValue
+ /// \post type() is arrayValue
+ void resize(ArrayIndex size);
+
+ /// Access an array element (zero based index ).
+ /// If the array contains less than index element, then null value are
+ /// inserted
+ /// in the array so that its size is index+1.
+ /// (You may need to say 'value[0u]' to get your compiler to distinguish
+ /// this from the operator[] which takes a string.)
+ Value& operator[](ArrayIndex index);
+
+ /// Access an array element (zero based index ).
+ /// If the array contains less than index element, then null value are
+ /// inserted
+ /// in the array so that its size is index+1.
+ /// (You may need to say 'value[0u]' to get your compiler to distinguish
+ /// this from the operator[] which takes a string.)
+ Value& operator[](int index);
+
+ /// Access an array element (zero based index )
+ /// (You may need to say 'value[0u]' to get your compiler to distinguish
+ /// this from the operator[] which takes a string.)
+ const Value& operator[](ArrayIndex index) const;
+
+ /// Access an array element (zero based index )
+ /// (You may need to say 'value[0u]' to get your compiler to distinguish
+ /// this from the operator[] which takes a string.)
+ const Value& operator[](int index) const;
+
+ /// If the array contains at least index+1 elements, returns the element
+ /// value,
+ /// otherwise returns defaultValue.
+ Value get(ArrayIndex index, const Value& defaultValue) const;
+ /// Return true if index < size().
+ bool isValidIndex(ArrayIndex index) const;
+ /// \brief Append value to array at the end.
+ ///
+ /// Equivalent to jsonvalue[jsonvalue.size()] = value;
+ Value& append(const Value& value);
+
+ /// Access an object value by name, create a null member if it does not exist.
+ /// \note Because of our implementation, keys are limited to 2^30 -1 chars.
+ /// Exceeding that will cause an exception.
+ Value& operator[](const char* key);
+ /// Access an object value by name, returns null if there is no member with
+ /// that name.
+ const Value& operator[](const char* key) const;
+ /// Access an object value by name, create a null member if it does not exist.
+ /// \param key may contain embedded nulls.
+ Value& operator[](const std::string& key);
+ /// Access an object value by name, returns null if there is no member with
+ /// that name.
+ /// \param key may contain embedded nulls.
+ const Value& operator[](const std::string& key) const;
+ /** \brief Access an object value by name, create a null member if it does not
+ exist.
+
+ * If the object has no entry for that name, then the member name used to store
+ * the new entry is not duplicated.
+ * Example of use:
+ * \code
+ * Json::Value object;
+ * static const StaticString code("code");
+ * object[code] = 1234;
+ * \endcode
+ */
+ Value& operator[](const StaticString& key);
+#ifdef JSON_USE_CPPTL
+ /// Access an object value by name, create a null member if it does not exist.
+ Value& operator[](const CppTL::ConstString& key);
+ /// Access an object value by name, returns null if there is no member with
+ /// that name.
+ const Value& operator[](const CppTL::ConstString& key) const;
+#endif
+ /// Return the member named key if it exist, defaultValue otherwise.
+ /// \note deep copy
+ Value get(const char* key, const Value& defaultValue) const;
+ /// Return the member named key if it exist, defaultValue otherwise.
+ /// \note deep copy
+ /// \note key may contain embedded nulls.
+ Value get(const char* begin, const char* end, const Value& defaultValue) const;
+ /// Return the member named key if it exist, defaultValue otherwise.
+ /// \note deep copy
+ /// \param key may contain embedded nulls.
+ Value get(const std::string& key, const Value& defaultValue) const;
+#ifdef JSON_USE_CPPTL
+ /// Return the member named key if it exist, defaultValue otherwise.
+ /// \note deep copy
+ Value get(const CppTL::ConstString& key, const Value& defaultValue) const;
+#endif
+ /// Most general and efficient version of isMember()const, get()const,
+ /// and operator[]const
+ /// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30
+ Value const* find(char const* begin, char const* end) const;
+ /// Most general and efficient version of object-mutators.
+ /// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30
+ /// \return non-zero, but JSON_ASSERT if this is neither object nor nullValue.
+ Value const* demand(char const* begin, char const* end);
+ /// \brief Remove and return the named member.
+ ///
+ /// Do nothing if it did not exist.
+ /// \return the removed Value, or null.
+ /// \pre type() is objectValue or nullValue
+ /// \post type() is unchanged
+ /// \deprecated
+ Value removeMember(const char* key);
+ /// Same as removeMember(const char*)
+ /// \param key may contain embedded nulls.
+ /// \deprecated
+ Value removeMember(const std::string& key);
+ /// Same as removeMember(const char* begin, const char* end, Value* removed),
+ /// but 'key' is null-terminated.
+ bool removeMember(const char* key, Value* removed);
+ /** \brief Remove the named map member.
+
+ Update 'removed' iff removed.
+ \param key may contain embedded nulls.
+ \return true iff removed (no exceptions)
+ */
+ bool removeMember(std::string const& key, Value* removed);
+ /// Same as removeMember(std::string const& key, Value* removed)
+ bool removeMember(const char* begin, const char* end, Value* removed);
+ /** \brief Remove the indexed array element.
+
+ O(n) expensive operations.
+ Update 'removed' iff removed.
+ \return true iff removed (no exceptions)
+ */
+ bool removeIndex(ArrayIndex i, Value* removed);
+
+ /// Return true if the object has a member named key.
+ /// \note 'key' must be null-terminated.
+ bool isMember(const char* key) const;
+ /// Return true if the object has a member named key.
+ /// \param key may contain embedded nulls.
+ bool isMember(const std::string& key) const;
+ /// Same as isMember(std::string const& key)const
+ bool isMember(const char* begin, const char* end) const;
+#ifdef JSON_USE_CPPTL
+ /// Return true if the object has a member named key.
+ bool isMember(const CppTL::ConstString& key) const;
+#endif
+
+ /// \brief Return a list of the member names.
+ ///
+ /// If null, return an empty list.
+ /// \pre type() is objectValue or nullValue
+ /// \post if type() was nullValue, it remains nullValue
+ Members getMemberNames() const;
+
+ //# ifdef JSON_USE_CPPTL
+ // EnumMemberNames enumMemberNames() const;
+ // EnumValues enumValues() const;
+ //# endif
+
+ /// \deprecated Always pass len.
+ JSONCPP_DEPRECATED("Use setComment(std::string const&) instead.")
+ void setComment(const char* comment, CommentPlacement placement);
+ /// Comments must be //... or /* ... */
+ void setComment(const char* comment, size_t len, CommentPlacement placement);
+ /// Comments must be //... or /* ... */
+ void setComment(const std::string& comment, CommentPlacement placement);
+ bool hasComment(CommentPlacement placement) const;
+ /// Include delimiters and embedded newlines.
+ std::string getComment(CommentPlacement placement) const;
+
+ std::string toStyledString() const;
+
+ const_iterator begin() const;
+ const_iterator end() const;
+
+ iterator begin();
+ iterator end();
+
+ // Accessors for the [start, limit) range of bytes within the JSON text from
+ // which this value was parsed, if any.
+ void setOffsetStart(size_t start);
+ void setOffsetLimit(size_t limit);
+ size_t getOffsetStart() const;
+ size_t getOffsetLimit() const;
+
+private:
+ void initBasic(ValueType type, bool allocated = false);
+
+ Value& resolveReference(const char* key);
+ Value& resolveReference(const char* key, const char* end);
+
+ struct CommentInfo {
+ CommentInfo();
+ ~CommentInfo();
+
+ void setComment(const char* text, size_t len);
+
+ char* comment_;
+ };
+
+ // struct MemberNamesTransform
+ //{
+ // typedef const char *result_type;
+ // const char *operator()( const CZString &name ) const
+ // {
+ // return name.c_str();
+ // }
+ //};
+
+ union ValueHolder {
+ LargestInt int_;
+ LargestUInt uint_;
+ double real_;
+ bool bool_;
+ char* string_; // actually ptr to unsigned, followed by str, unless !allocated_
+ ObjectValues* map_;
+ } value_;
+ ValueType type_ : 8;
+ unsigned int allocated_ : 1; // Notes: if declared as bool, bitfield is useless.
+ // If not allocated_, string_ must be null-terminated.
+ CommentInfo* comments_;
+
+ // [start, limit) byte offsets in the source JSON text from which this Value
+ // was extracted.
+ size_t start_;
+ size_t limit_;
+};
+
+/** \brief Experimental and untested: represents an element of the "path" to
+ * access a node.
+ */
+class JSON_API PathArgument {
+public:
+ friend class Path;
+
+ PathArgument();
+ PathArgument(ArrayIndex index);
+ PathArgument(const char* key);
+ PathArgument(const std::string& key);
+
+private:
+ enum Kind {
+ kindNone = 0,
+ kindIndex,
+ kindKey
+ };
+ std::string key_;
+ ArrayIndex index_;
+ Kind kind_;
+};
+
+/** \brief Experimental and untested: represents a "path" to access a node.
+ *
+ * Syntax:
+ * - "." => root node
+ * - ".[n]" => elements at index 'n' of root node (an array value)
+ * - ".name" => member named 'name' of root node (an object value)
+ * - ".name1.name2.name3"
+ * - ".[0][1][2].name1[3]"
+ * - ".%" => member name is provided as parameter
+ * - ".[%]" => index is provied as parameter
+ */
+class JSON_API Path {
+public:
+ Path(const std::string& path,
+ const PathArgument& a1 = PathArgument(),
+ const PathArgument& a2 = PathArgument(),
+ const PathArgument& a3 = PathArgument(),
+ const PathArgument& a4 = PathArgument(),
+ const PathArgument& a5 = PathArgument());
+
+ const Value& resolve(const Value& root) const;
+ Value resolve(const Value& root, const Value& defaultValue) const;
+ /// Creates the "path" to access the specified node and returns a reference on
+ /// the node.
+ Value& make(Value& root) const;
+
+private:
+ typedef std::vector<const PathArgument*> InArgs;
+ typedef std::vector<PathArgument> Args;
+
+ void makePath(const std::string& path, const InArgs& in);
+ void addPathInArg(const std::string& path,
+ const InArgs& in,
+ InArgs::const_iterator& itInArg,
+ PathArgument::Kind kind);
+ void invalidPath(const std::string& path, int location);
+
+ Args args_;
+};
+
+/** \brief base class for Value iterators.
+ *
+ */
+class JSON_API ValueIteratorBase {
+public:
+ typedef std::bidirectional_iterator_tag iterator_category;
+ typedef unsigned int size_t;
+ typedef int difference_type;
+ typedef ValueIteratorBase SelfType;
+
+ bool operator==(const SelfType& other) const { return isEqual(other); }
+
+ bool operator!=(const SelfType& other) const { return !isEqual(other); }
+
+ difference_type operator-(const SelfType& other) const {
+ return other.computeDistance(*this);
+ }
+
+ /// Return either the index or the member name of the referenced value as a
+ /// Value.
+ Value key() const;
+
+ /// Return the index of the referenced Value, or -1 if it is not an arrayValue.
+ UInt index() const;
+
+ /// Return the member name of the referenced Value, or "" if it is not an
+ /// objectValue.
+ /// \note Avoid `c_str()` on result, as embedded zeroes are possible.
+ std::string name() const;
+
+ /// Return the member name of the referenced Value. "" if it is not an
+ /// objectValue.
+ /// \deprecated This cannot be used for UTF-8 strings, since there can be embedded nulls.
+ JSONCPP_DEPRECATED("Use `key = name();` instead.")
+ char const* memberName() const;
+ /// Return the member name of the referenced Value, or NULL if it is not an
+ /// objectValue.
+ /// \note Better version than memberName(). Allows embedded nulls.
+ char const* memberName(char const** end) const;
+
+protected:
+ Value& deref() const;
+
+ void increment();
+
+ void decrement();
+
+ difference_type computeDistance(const SelfType& other) const;
+
+ bool isEqual(const SelfType& other) const;
+
+ void copy(const SelfType& other);
+
+private:
+ Value::ObjectValues::iterator current_;
+ // Indicates that iterator is for a null value.
+ bool isNull_;
+
+public:
+ // For some reason, BORLAND needs these at the end, rather
+ // than earlier. No idea why.
+ ValueIteratorBase();
+ explicit ValueIteratorBase(const Value::ObjectValues::iterator& current);
+};
+
+/** \brief const iterator for object and array value.
+ *
+ */
+class JSON_API ValueConstIterator : public ValueIteratorBase {
+ friend class Value;
+
+public:
+ typedef const Value value_type;
+ //typedef unsigned int size_t;
+ //typedef int difference_type;
+ typedef const Value& reference;
+ typedef const Value* pointer;
+ typedef ValueConstIterator SelfType;
+
+ ValueConstIterator();
+ ValueConstIterator(ValueIterator const& other);
+
+private:
+/*! \internal Use by Value to create an iterator.
+ */
+ explicit ValueConstIterator(const Value::ObjectValues::iterator& current);
+public:
+ SelfType& operator=(const ValueIteratorBase& other);
+
+ SelfType operator++(int) {
+ SelfType temp(*this);
+ ++*this;
+ return temp;
+ }
+
+ SelfType operator--(int) {
+ SelfType temp(*this);
+ --*this;
+ return temp;
+ }
+
+ SelfType& operator--() {
+ decrement();
+ return *this;
+ }
+
+ SelfType& operator++() {
+ increment();
+ return *this;
+ }
+
+ reference operator*() const { return deref(); }
+
+ pointer operator->() const { return &deref(); }
+};
+
+/** \brief Iterator for object and array value.
+ */
+class JSON_API ValueIterator : public ValueIteratorBase {
+ friend class Value;
+
+public:
+ typedef Value value_type;
+ typedef unsigned int size_t;
+ typedef int difference_type;
+ typedef Value& reference;
+ typedef Value* pointer;
+ typedef ValueIterator SelfType;
+
+ ValueIterator();
+ explicit ValueIterator(const ValueConstIterator& other);
+ ValueIterator(const ValueIterator& other);
+
+private:
+/*! \internal Use by Value to create an iterator.
+ */
+ explicit ValueIterator(const Value::ObjectValues::iterator& current);
+public:
+ SelfType& operator=(const SelfType& other);
+
+ SelfType operator++(int) {
+ SelfType temp(*this);
+ ++*this;
+ return temp;
+ }
+
+ SelfType operator--(int) {
+ SelfType temp(*this);
+ --*this;
+ return temp;
+ }
+
+ SelfType& operator--() {
+ decrement();
+ return *this;
+ }
+
+ SelfType& operator++() {
+ increment();
+ return *this;
+ }
+
+ reference operator*() const { return deref(); }
+
+ pointer operator->() const { return &deref(); }
+};
+
+} // namespace Json
+
+
+namespace std {
+/// Specialize std::swap() for Json::Value.
+template<>
+inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); }
+}
+
+
+#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
+#pragma warning(pop)
+#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
+
+#endif // CPPTL_JSON_H_INCLUDED
+
+// //////////////////////////////////////////////////////////////////////
+// End of content of file: include/json/value.h
+// //////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+// //////////////////////////////////////////////////////////////////////
+// Beginning of content of file: include/json/reader.h
+// //////////////////////////////////////////////////////////////////////
+
+// Copyright 2007-2010 Baptiste Lepilleur
+// Distributed under MIT license, or public domain if desired and
+// recognized in your jurisdiction.
+// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
+
+#ifndef CPPTL_JSON_READER_H_INCLUDED
+#define CPPTL_JSON_READER_H_INCLUDED
+
+#if !defined(JSON_IS_AMALGAMATION)
+#include "features.h"
+#include "value.h"
+#endif // if !defined(JSON_IS_AMALGAMATION)
+#include <deque>
+#include <iosfwd>
+#include <stack>
+#include <string>
+#include <istream>
+
+// Disable warning C4251: <data member>: <type> needs to have dll-interface to
+// be used by...
+#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
+#pragma warning(push)
+#pragma warning(disable : 4251)
+#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
+
+namespace Json {
+
+/** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a
+ *Value.
+ *
+ * \deprecated Use CharReader and CharReaderBuilder.
+ */
+class JSON_API Reader {
+public:
+ typedef char Char;
+ typedef const Char* Location;
+
+ /** \brief An error tagged with where in the JSON text it was encountered.
+ *
+ * The offsets give the [start, limit) range of bytes within the text. Note
+ * that this is bytes, not codepoints.
+ *
+ */
+ struct StructuredError {
+ size_t offset_start;
+ size_t offset_limit;
+ std::string message;
+ };
+
+ /** \brief Constructs a Reader allowing all features
+ * for parsing.
+ */
+ Reader();
+
+ /** \brief Constructs a Reader allowing the specified feature set
+ * for parsing.
+ */
+ Reader(const Features& features);
+
+ /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
+ * document.
+ * \param document UTF-8 encoded string containing the document to read.
+ * \param root [out] Contains the root value of the document if it was
+ * successfully parsed.
+ * \param collectComments \c true to collect comment and allow writing them
+ * back during
+ * serialization, \c false to discard comments.
+ * This parameter is ignored if
+ * Features::allowComments_
+ * is \c false.
+ * \return \c true if the document was successfully parsed, \c false if an
+ * error occurred.
+ */
+ bool
+ parse(const std::string& document, Value& root, bool collectComments = true);
+
+ /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
+ document.
+ * \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the
+ document to read.
+ * \param endDoc Pointer on the end of the UTF-8 encoded string of the
+ document to read.
+ * Must be >= beginDoc.
+ * \param root [out] Contains the root value of the document if it was
+ * successfully parsed.
+ * \param collectComments \c true to collect comment and allow writing them
+ back during
+ * serialization, \c false to discard comments.
+ * This parameter is ignored if
+ Features::allowComments_
+ * is \c false.
+ * \return \c true if the document was successfully parsed, \c false if an
+ error occurred.
+ */
+ bool parse(const char* beginDoc,
+ const char* endDoc,
+ Value& root,
+ bool collectComments = true);
+
+ /// \brief Parse from input stream.
+ /// \see Json::operator>>(std::istream&, Json::Value&).
+ bool parse(std::istream& is, Value& root, bool collectComments = true);
+
+ /** \brief Returns a user friendly string that list errors in the parsed
+ * document.
+ * \return Formatted error message with the list of errors with their location
+ * in
+ * the parsed document. An empty string is returned if no error
+ * occurred
+ * during parsing.
+ * \deprecated Use getFormattedErrorMessages() instead (typo fix).
+ */
+ JSONCPP_DEPRECATED("Use getFormattedErrorMessages() instead.")
+ std::string getFormatedErrorMessages() const;
+
+ /** \brief Returns a user friendly string that list errors in the parsed
+ * document.
+ * \return Formatted error message with the list of errors with their location
+ * in
+ * the parsed document. An empty string is returned if no error
+ * occurred
+ * during parsing.
+ */
+ std::string getFormattedErrorMessages() const;
+
+ /** \brief Returns a vector of structured erros encounted while parsing.
+ * \return A (possibly empty) vector of StructuredError objects. Currently
+ * only one error can be returned, but the caller should tolerate
+ * multiple
+ * errors. This can occur if the parser recovers from a non-fatal
+ * parse error and then encounters additional errors.
+ */
+ std::vector<StructuredError> getStructuredErrors() const;
+
+ /** \brief Add a semantic error message.
+ * \param value JSON Value location associated with the error
+ * \param message The error message.
+ * \return \c true if the error was successfully added, \c false if the
+ * Value offset exceeds the document size.
+ */
+ bool pushError(const Value& value, const std::string& message);
+
+ /** \brief Add a semantic error message with extra context.
+ * \param value JSON Value location associated with the error
+ * \param message The error message.
+ * \param extra Additional JSON Value location to contextualize the error
+ * \return \c true if the error was successfully added, \c false if either
+ * Value offset exceeds the document size.
+ */
+ bool pushError(const Value& value, const std::string& message, const Value& extra);
+
+ /** \brief Return whether there are any errors.
+ * \return \c true if there are no errors to report \c false if
+ * errors have occurred.
+ */
+ bool good() const;
+
+private:
+ enum TokenType {
+ tokenEndOfStream = 0,
+ tokenObjectBegin,
+ tokenObjectEnd,
+ tokenArrayBegin,
+ tokenArrayEnd,
+ tokenString,
+ tokenNumber,
+ tokenTrue,
+ tokenFalse,
+ tokenNull,
+ tokenArraySeparator,
+ tokenMemberSeparator,
+ tokenComment,
+ tokenError
+ };
+
+ class Token {
+ public:
+ TokenType type_;
+ Location start_;
+ Location end_;
+ };
+
+ class ErrorInfo {
+ public:
+ Token token_;
+ std::string message_;
+ Location extra_;
+ };
+
+ typedef std::deque<ErrorInfo> Errors;
+
+ bool readToken(Token& token);
+ void skipSpaces();
+ bool match(Location pattern, int patternLength);
+ bool readComment();
+ bool readCStyleComment();
+ bool readCppStyleComment();
+ bool readString();
+ void readNumber();
+ bool readValue();
+ bool readObject(Token& token);
+ bool readArray(Token& token);
+ bool decodeNumber(Token& token);
+ bool decodeNumber(Token& token, Value& decoded);
+ bool decodeString(Token& token);
+ bool decodeString(Token& token, std::string& decoded);
+ bool decodeDouble(Token& token);
+ bool decodeDouble(Token& token, Value& decoded);
+ bool decodeUnicodeCodePoint(Token& token,
+ Location& current,
+ Location end,
+ unsigned int& unicode);
+ bool decodeUnicodeEscapeSequence(Token& token,
+ Location& current,
+ Location end,
+ unsigned int& unicode);
+ bool addError(const std::string& message, Token& token, Location extra = 0);
+ bool recoverFromError(TokenType skipUntilToken);
+ bool addErrorAndRecover(const std::string& message,
+ Token& token,
+ TokenType skipUntilToken);
+ void skipUntilSpace();
+ Value& currentValue();
+ Char getNextChar();
+ void
+ getLocationLineAndColumn(Location location, int& line, int& column) const;
+ std::string getLocationLineAndColumn(Location location) const;
+ void addComment(Location begin, Location end, CommentPlacement placement);
+ void skipCommentTokens(Token& token);
+
+ typedef std::stack<Value*> Nodes;
+ Nodes nodes_;
+ Errors errors_;
+ std::string document_;
+ Location begin_;
+ Location end_;
+ Location current_;
+ Location lastValueEnd_;
+ Value* lastValue_;
+ std::string commentsBefore_;
+ Features features_;
+ bool collectComments_;
+}; // Reader
+
+/** Interface for reading JSON from a char array.
+ */
+class JSON_API CharReader {
+public:
+ virtual ~CharReader() {}
+ /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a>
+ document.
+ * The document must be a UTF-8 encoded string containing the document to read.
+ *
+ * \param beginDoc Pointer on the beginning of the UTF-8 encoded string of the
+ document to read.
+ * \param endDoc Pointer on the end of the UTF-8 encoded string of the
+ document to read.
+ * Must be >= beginDoc.
+ * \param root [out] Contains the root value of the document if it was
+ * successfully parsed.
+ * \param errs [out] Formatted error messages (if not NULL)
+ * a user friendly string that lists errors in the parsed
+ * document.
+ * \return \c true if the document was successfully parsed, \c false if an
+ error occurred.
+ */
+ virtual bool parse(
+ char const* beginDoc, char const* endDoc,
+ Value* root, std::string* errs) = 0;
+
+ class JSON_API Factory {
+ public:
+ virtual ~Factory() {}
+ /** \brief Allocate a CharReader via operator new().
+ * \throw std::exception if something goes wrong (e.g. invalid settings)
+ */
+ virtual CharReader* newCharReader() const = 0;
+ }; // Factory
+}; // CharReader
+
+/** \brief Build a CharReader implementation.
+
+Usage:
+\code
+ using namespace Json;
+ CharReaderBuilder builder;
+ builder["collectComments"] = false;
+ Value value;
+ std::string errs;
+ bool ok = parseFromStream(builder, std::cin, &value, &errs);
+\endcode
+*/
+class JSON_API CharReaderBuilder : public CharReader::Factory {
+public:
+ // Note: We use a Json::Value so that we can add data-members to this class
+ // without a major version bump.
+ /** Configuration of this builder.
+ These are case-sensitive.
+ Available settings (case-sensitive):
+ - `"collectComments": false or true`
+ - true to collect comment and allow writing them
+ back during serialization, false to discard comments.
+ This parameter is ignored if allowComments is false.
+ - `"allowComments": false or true`
+ - true if comments are allowed.
+ - `"strictRoot": false or true`
+ - true if root must be either an array or an object value
+ - `"allowDroppedNullPlaceholders": false or true`
+ - true if dropped null placeholders are allowed. (See StreamWriterBuilder.)
+ - `"allowNumericKeys": false or true`
+ - true if numeric object keys are allowed.
+ - `"allowSingleQuotes": false or true`
+ - true if '' are allowed for strings (both keys and values)
+ - `"stackLimit": integer`
+ - Exceeding stackLimit (recursive depth of `readValue()`) will
+ cause an exception.
+ - This is a security issue (seg-faults caused by deeply nested JSON),
+ so the default is low.
+ - `"failIfExtra": false or true`
+ - If true, `parse()` returns false when extra non-whitespace trails
+ the JSON value in the input string.
+ - `"rejectDupKeys": false or true`
+ - If true, `parse()` returns false when a key is duplicated within an object.
+ - `"allowSpecialFloats": false or true`
+ - If true, special float values (NaNs and infinities) are allowed
+ and their values are lossfree restorable.
+
+ You can examine 'settings_` yourself
+ to see the defaults. You can also write and read them just like any
+ JSON Value.
+ \sa setDefaults()
+ */
+ Json::Value settings_;
+
+ CharReaderBuilder();
+ ~CharReaderBuilder() override;
+
+ CharReader* newCharReader() const override;
+
+ /** \return true if 'settings' are legal and consistent;
+ * otherwise, indicate bad settings via 'invalid'.
+ */
+ bool validate(Json::Value* invalid) const;
+
+ /** A simple way to update a specific setting.
+ */
+ Value& operator[](std::string key);
+
+ /** Called by ctor, but you can use this to reset settings_.
+ * \pre 'settings' != NULL (but Json::null is fine)
+ * \remark Defaults:
+ * \snippet src/lib_json/json_reader.cpp CharReaderBuilderDefaults
+ */
+ static void setDefaults(Json::Value* settings);
+ /** Same as old Features::strictMode().
+ * \pre 'settings' != NULL (but Json::null is fine)
+ * \remark Defaults:
+ * \snippet src/lib_json/json_reader.cpp CharReaderBuilderStrictMode
+ */
+ static void strictMode(Json::Value* settings);
+};
+
+/** Consume entire stream and use its begin/end.
+ * Someday we might have a real StreamReader, but for now this
+ * is convenient.
+ */
+bool JSON_API parseFromStream(
+ CharReader::Factory const&,
+ std::istream&,
+ Value* root, std::string* errs);
+
+/** \brief Read from 'sin' into 'root'.
+
+ Always keep comments from the input JSON.
+
+ This can be used to read a file into a particular sub-object.
+ For example:
+ \code
+ Json::Value root;
+ cin >> root["dir"]["file"];
+ cout << root;
+ \endcode
+ Result:
+ \verbatim
+ {
+ "dir": {
+ "file": {
+ // The input stream JSON would be nested here.
+ }
+ }
+ }
+ \endverbatim
+ \throw std::exception on parse error.
+ \see Json::operator<<()
+*/
+JSON_API std::istream& operator>>(std::istream&, Value&);
+
+} // namespace Json
+
+#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
+#pragma warning(pop)
+#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
+
+#endif // CPPTL_JSON_READER_H_INCLUDED
+
+// //////////////////////////////////////////////////////////////////////
+// End of content of file: include/json/reader.h
+// //////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+// //////////////////////////////////////////////////////////////////////
+// Beginning of content of file: include/json/writer.h
+// //////////////////////////////////////////////////////////////////////
+
+// Copyright 2007-2010 Baptiste Lepilleur
+// Distributed under MIT license, or public domain if desired and
+// recognized in your jurisdiction.
+// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
+
+#ifndef JSON_WRITER_H_INCLUDED
+#define JSON_WRITER_H_INCLUDED
+
+#if !defined(JSON_IS_AMALGAMATION)
+#include "value.h"
+#endif // if !defined(JSON_IS_AMALGAMATION)
+#include <vector>
+#include <string>
+#include <ostream>
+
+// Disable warning C4251: <data member>: <type> needs to have dll-interface to
+// be used by...
+#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
+#pragma warning(push)
+#pragma warning(disable : 4251)
+#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
+
+namespace Json {
+
+class Value;
+
+/**
+
+Usage:
+\code
+ using namespace Json;
+ void writeToStdout(StreamWriter::Factory const& factory, Value const& value) {
+ std::unique_ptr<StreamWriter> const writer(
+ factory.newStreamWriter());
+ writer->write(value, &std::cout);
+ std::cout << std::endl; // add lf and flush
+ }
+\endcode
+*/
+class JSON_API StreamWriter {
+protected:
+ std::ostream* sout_; // not owned; will not delete
+public:
+ StreamWriter();
+ virtual ~StreamWriter();
+ /** Write Value into document as configured in sub-class.
+ Do not take ownership of sout, but maintain a reference during function.
+ \pre sout != NULL
+ \return zero on success (For now, we always return zero, so check the stream instead.)
+ \throw std::exception possibly, depending on configuration
+ */
+ virtual int write(Value const& root, std::ostream* sout) = 0;
+
+ /** \brief A simple abstract factory.
+ */
+ class JSON_API Factory {
+ public:
+ virtual ~Factory();
+ /** \brief Allocate a CharReader via operator new().
+ * \throw std::exception if something goes wrong (e.g. invalid settings)
+ */
+ virtual StreamWriter* newStreamWriter() const = 0;
+ }; // Factory
+}; // StreamWriter
+
+/** \brief Write into stringstream, then return string, for convenience.
+ * A StreamWriter will be created from the factory, used, and then deleted.
+ */
+std::string JSON_API writeString(StreamWriter::Factory const& factory, Value const& root);
+
+
+/** \brief Build a StreamWriter implementation.
+
+Usage:
+\code
+ using namespace Json;
+ Value value = ...;
+ StreamWriterBuilder builder;
+ builder["commentStyle"] = "None";
+ builder["indentation"] = " "; // or whatever you like
+ std::unique_ptr<Json::StreamWriter> writer(
+ builder.newStreamWriter());
+ writer->write(value, &std::cout);
+ std::cout << std::endl; // add lf and flush
+\endcode
+*/
+class JSON_API StreamWriterBuilder : public StreamWriter::Factory {
+public:
+ // Note: We use a Json::Value so that we can add data-members to this class
+ // without a major version bump.
+ /** Configuration of this builder.
+ Available settings (case-sensitive):
+ - "commentStyle": "None" or "All"
+ - "indentation": "<anything>"
+ - "enableYAMLCompatibility": false or true
+ - slightly change the whitespace around colons
+ - "dropNullPlaceholders": false or true
+ - Drop the "null" string from the writer's output for nullValues.
+ Strictly speaking, this is not valid JSON. But when the output is being
+ fed to a browser's Javascript, it makes for smaller output and the
+ browser can handle the output just fine.
+ - "useSpecialFloats": false or true
+ - If true, outputs non-finite floating point values in the following way:
+ NaN values as "NaN", positive infinity as "Infinity", and negative infinity
+ as "-Infinity".
+
+ You can examine 'settings_` yourself
+ to see the defaults. You can also write and read them just like any
+ JSON Value.
+ \sa setDefaults()
+ */
+ Json::Value settings_;
+
+ StreamWriterBuilder();
+ ~StreamWriterBuilder() override;
+
+ /**
+ * \throw std::exception if something goes wrong (e.g. invalid settings)
+ */
+ StreamWriter* newStreamWriter() const override;
+
+ /** \return true if 'settings' are legal and consistent;
+ * otherwise, indicate bad settings via 'invalid'.
+ */
+ bool validate(Json::Value* invalid) const;
+ /** A simple way to update a specific setting.
+ */
+ Value& operator[](std::string key);
+
+ /** Called by ctor, but you can use this to reset settings_.
+ * \pre 'settings' != NULL (but Json::null is fine)
+ * \remark Defaults:
+ * \snippet src/lib_json/json_writer.cpp StreamWriterBuilderDefaults
+ */
+ static void setDefaults(Json::Value* settings);
+};
+
+/** \brief Abstract class for writers.
+ * \deprecated Use StreamWriter. (And really, this is an implementation detail.)
+ */
+class JSON_API Writer {
+public:
+ virtual ~Writer();
+
+ virtual std::string write(const Value& root) = 0;
+};
+
+/** \brief Outputs a Value in <a HREF="http://www.json.org">JSON</a> format
+ *without formatting (not human friendly).
+ *
+ * The JSON document is written in a single line. It is not intended for 'human'
+ *consumption,
+ * but may be usefull to support feature such as RPC where bandwith is limited.
+ * \sa Reader, Value
+ * \deprecated Use StreamWriterBuilder.
+ */
+class JSON_API FastWriter : public Writer {
+
+public:
+ FastWriter();
+ ~FastWriter() override {}
+
+ void enableYAMLCompatibility();
+
+ /** \brief Drop the "null" string from the writer's output for nullValues.
+ * Strictly speaking, this is not valid JSON. But when the output is being
+ * fed to a browser's Javascript, it makes for smaller output and the
+ * browser can handle the output just fine.
+ */
+ void dropNullPlaceholders();
+
+ void omitEndingLineFeed();
+
+public: // overridden from Writer
+ std::string write(const Value& root) override;
+
+private:
+ void writeValue(const Value& value);
+
+ std::string document_;
+ bool yamlCompatiblityEnabled_;
+ bool dropNullPlaceholders_;
+ bool omitEndingLineFeed_;
+};
+
+/** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a
+ *human friendly way.
+ *
+ * The rules for line break and indent are as follow:
+ * - Object value:
+ * - if empty then print {} without indent and line break
+ * - if not empty the print '{', line break & indent, print one value per
+ *line
+ * and then unindent and line break and print '}'.
+ * - Array value:
+ * - if empty then print [] without indent and line break
+ * - if the array contains no object value, empty array or some other value
+ *types,
+ * and all the values fit on one lines, then print the array on a single
+ *line.
+ * - otherwise, it the values do not fit on one line, or the array contains
+ * object or non empty array, then print one value per line.
+ *
+ * If the Value have comments then they are outputed according to their
+ *#CommentPlacement.
+ *
+ * \sa Reader, Value, Value::setComment()
+ * \deprecated Use StreamWriterBuilder.
+ */
+class JSON_API StyledWriter : public Writer {
+public:
+ StyledWriter();
+ ~StyledWriter() override {}
+
+public: // overridden from Writer
+ /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
+ * \param root Value to serialize.
+ * \return String containing the JSON document that represents the root value.
+ */
+ std::string write(const Value& root) override;
+
+private:
+ void writeValue(const Value& value);
+ void writeArrayValue(const Value& value);
+ bool isMultineArray(const Value& value);
+ void pushValue(const std::string& value);
+ void writeIndent();
+ void writeWithIndent(const std::string& value);
+ void indent();
+ void unindent();
+ void writeCommentBeforeValue(const Value& root);
+ void writeCommentAfterValueOnSameLine(const Value& root);
+ bool hasCommentForValue(const Value& value);
+ static std::string normalizeEOL(const std::string& text);
+
+ typedef std::vector<std::string> ChildValues;
+
+ ChildValues childValues_;
+ std::string document_;
+ std::string indentString_;
+ int rightMargin_;
+ int indentSize_;
+ bool addChildValues_;
+};
+
+/** \brief Writes a Value in <a HREF="http://www.json.org">JSON</a> format in a
+ human friendly way,
+ to a stream rather than to a string.
+ *
+ * The rules for line break and indent are as follow:
+ * - Object value:
+ * - if empty then print {} without indent and line break
+ * - if not empty the print '{', line break & indent, print one value per
+ line
+ * and then unindent and line break and print '}'.
+ * - Array value:
+ * - if empty then print [] without indent and line break
+ * - if the array contains no object value, empty array or some other value
+ types,
+ * and all the values fit on one lines, then print the array on a single
+ line.
+ * - otherwise, it the values do not fit on one line, or the array contains
+ * object or non empty array, then print one value per line.
+ *
+ * If the Value have comments then they are outputed according to their
+ #CommentPlacement.
+ *
+ * \param indentation Each level will be indented by this amount extra.
+ * \sa Reader, Value, Value::setComment()
+ * \deprecated Use StreamWriterBuilder.
+ */
+class JSON_API StyledStreamWriter {
+public:
+ StyledStreamWriter(std::string indentation = "\t");
+ ~StyledStreamWriter() {}
+
+public:
+ /** \brief Serialize a Value in <a HREF="http://www.json.org">JSON</a> format.
+ * \param out Stream to write to. (Can be ostringstream, e.g.)
+ * \param root Value to serialize.
+ * \note There is no point in deriving from Writer, since write() should not
+ * return a value.
+ */
+ void write(std::ostream& out, const Value& root);
+
+private:
+ void writeValue(const Value& value);
+ void writeArrayValue(const Value& value);
+ bool isMultineArray(const Value& value);
+ void pushValue(const std::string& value);
+ void writeIndent();
+ void writeWithIndent(const std::string& value);
+ void indent();
+ void unindent();
+ void writeCommentBeforeValue(const Value& root);
+ void writeCommentAfterValueOnSameLine(const Value& root);
+ bool hasCommentForValue(const Value& value);
+ static std::string normalizeEOL(const std::string& text);
+
+ typedef std::vector<std::string> ChildValues;
+
+ ChildValues childValues_;
+ std::ostream* document_;
+ std::string indentString_;
+ int rightMargin_;
+ std::string indentation_;
+ bool addChildValues_ : 1;
+ bool indented_ : 1;
+};
+
+#if defined(JSON_HAS_INT64)
+std::string JSON_API valueToString(Int value);
+std::string JSON_API valueToString(UInt value);
+#endif // if defined(JSON_HAS_INT64)
+std::string JSON_API valueToString(LargestInt value);
+std::string JSON_API valueToString(LargestUInt value);
+std::string JSON_API valueToString(double value);
+std::string JSON_API valueToString(bool value);
+std::string JSON_API valueToQuotedString(const char* value);
+
+/// \brief Output using the StyledStreamWriter.
+/// \see Json::operator>>()
+JSON_API std::ostream& operator<<(std::ostream&, const Value& root);
+
+} // namespace Json
+
+#if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
+#pragma warning(pop)
+#endif // if defined(JSONCPP_DISABLE_DLL_INTERFACE_WARNING)
+
+#endif // JSON_WRITER_H_INCLUDED
+
+// //////////////////////////////////////////////////////////////////////
+// End of content of file: include/json/writer.h
+// //////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+// //////////////////////////////////////////////////////////////////////
+// Beginning of content of file: include/json/assertions.h
+// //////////////////////////////////////////////////////////////////////
+
+// Copyright 2007-2010 Baptiste Lepilleur
+// Distributed under MIT license, or public domain if desired and
+// recognized in your jurisdiction.
+// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
+
+#ifndef CPPTL_JSON_ASSERTIONS_H_INCLUDED
+#define CPPTL_JSON_ASSERTIONS_H_INCLUDED
+
+#include <stdlib.h>
+#include <sstream>
+
+#if !defined(JSON_IS_AMALGAMATION)
+#include "config.h"
+#endif // if !defined(JSON_IS_AMALGAMATION)
+
+/** It should not be possible for a maliciously designed file to
+ * cause an abort() or seg-fault, so these macros are used only
+ * for pre-condition violations and internal logic errors.
+ */
+#if JSON_USE_EXCEPTION
+
+// @todo <= add detail about condition in exception
+# define JSON_ASSERT(condition) \
+ {if (!(condition)) {Json::throwLogicError( "assert json failed" );}}
+
+# define JSON_FAIL_MESSAGE(message) \
+ { \
+ std::ostringstream oss; oss << message; \
+ Json::throwLogicError(oss.str()); \
+ abort(); \
+ }
+
+#else // JSON_USE_EXCEPTION
+
+# define JSON_ASSERT(condition) assert(condition)
+
+// The call to assert() will show the failure message in debug builds. In
+// release builds we abort, for a core-dump or debugger.
+# define JSON_FAIL_MESSAGE(message) \
+ { \
+ std::ostringstream oss; oss << message; \
+ assert(false && oss.str().c_str()); \
+ abort(); \
+ }
+
+
+#endif
+
+#define JSON_ASSERT_MESSAGE(condition, message) \
+ if (!(condition)) { \
+ JSON_FAIL_MESSAGE(message); \
+ }
+
+#endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED
+
+// //////////////////////////////////////////////////////////////////////
+// End of content of file: include/json/assertions.h
+// //////////////////////////////////////////////////////////////////////
+
+
+
+
+
+#endif //ifndef JSON_AMALGATED_H_INCLUDED
diff --git a/third_party/protobuf/conformance/third_party/jsoncpp/jsoncpp.cpp b/third_party/protobuf/conformance/third_party/jsoncpp/jsoncpp.cpp
new file mode 100644
index 0000000000..f803962ade
--- /dev/null
+++ b/third_party/protobuf/conformance/third_party/jsoncpp/jsoncpp.cpp
@@ -0,0 +1,5192 @@
+/// Json-cpp amalgated source (http://jsoncpp.sourceforge.net/).
+/// It is intended to be used with #include "json/json.h"
+
+// //////////////////////////////////////////////////////////////////////
+// Beginning of content of file: LICENSE
+// //////////////////////////////////////////////////////////////////////
+
+/*
+The JsonCpp library's source code, including accompanying documentation,
+tests and demonstration applications, are licensed under the following
+conditions...
+
+The author (Baptiste Lepilleur) explicitly disclaims copyright in all
+jurisdictions which recognize such a disclaimer. In such jurisdictions,
+this software is released into the Public Domain.
+
+In jurisdictions which do not recognize Public Domain property (e.g. Germany as of
+2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur, and is
+released under the terms of the MIT License (see below).
+
+In jurisdictions which recognize Public Domain property, the user of this
+software may choose to accept it either as 1) Public Domain, 2) under the
+conditions of the MIT License (see below), or 3) under the terms of dual
+Public Domain/MIT License conditions described here, as they choose.
+
+The MIT License is about as close to Public Domain as a license can get, and is
+described in clear, concise terms at:
+
+ http://en.wikipedia.org/wiki/MIT_License
+
+The full text of the MIT License follows:
+
+========================================================================
+Copyright (c) 2007-2010 Baptiste Lepilleur
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use, copy,
+modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+========================================================================
+(END LICENSE TEXT)
+
+The MIT license is compatible with both the GPL and commercial
+software, affording one all of the rights of Public Domain with the
+minor nuisance of being required to keep the above copyright notice
+and license text in the source code. Note also that by accepting the
+Public Domain "license" you can re-license your copy using whatever
+license you like.
+
+*/
+
+// //////////////////////////////////////////////////////////////////////
+// End of content of file: LICENSE
+// //////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+#include "third_party/jsoncpp/json.h"
+
+#ifndef JSON_IS_AMALGAMATION
+#error "Compile with -I PATH_TO_JSON_DIRECTORY"
+#endif
+
+
+// //////////////////////////////////////////////////////////////////////
+// Beginning of content of file: src/lib_json/json_tool.h
+// //////////////////////////////////////////////////////////////////////
+
+// Copyright 2007-2010 Baptiste Lepilleur
+// Distributed under MIT license, or public domain if desired and
+// recognized in your jurisdiction.
+// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
+
+#ifndef LIB_JSONCPP_JSON_TOOL_H_INCLUDED
+#define LIB_JSONCPP_JSON_TOOL_H_INCLUDED
+
+/* This header provides common string manipulation support, such as UTF-8,
+ * portable conversion from/to string...
+ *
+ * It is an internal header that must not be exposed.
+ */
+
+namespace Json {
+
+/// Converts a unicode code-point to UTF-8.
+static inline std::string codePointToUTF8(unsigned int cp) {
+ std::string result;
+
+ // based on description from http://en.wikipedia.org/wiki/UTF-8
+
+ if (cp <= 0x7f) {
+ result.resize(1);
+ result[0] = static_cast<char>(cp);
+ } else if (cp <= 0x7FF) {
+ result.resize(2);
+ result[1] = static_cast<char>(0x80 | (0x3f & cp));
+ result[0] = static_cast<char>(0xC0 | (0x1f & (cp >> 6)));
+ } else if (cp <= 0xFFFF) {
+ result.resize(3);
+ result[2] = static_cast<char>(0x80 | (0x3f & cp));
+ result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
+ result[0] = static_cast<char>(0xE0 | (0xf & (cp >> 12)));
+ } else if (cp <= 0x10FFFF) {
+ result.resize(4);
+ result[3] = static_cast<char>(0x80 | (0x3f & cp));
+ result[2] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
+ result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 12)));
+ result[0] = static_cast<char>(0xF0 | (0x7 & (cp >> 18)));
+ }
+
+ return result;
+}
+
+/// Returns true if ch is a control character (in range [1,31]).
+static inline bool isControlCharacter(char ch) { return ch > 0 && ch <= 0x1F; }
+
+enum {
+ /// Constant that specify the size of the buffer that must be passed to
+ /// uintToString.
+ uintToStringBufferSize = 3 * sizeof(LargestUInt) + 1
+};
+
+// Defines a char buffer for use with uintToString().
+typedef char UIntToStringBuffer[uintToStringBufferSize];
+
+/** Converts an unsigned integer to string.
+ * @param value Unsigned interger to convert to string
+ * @param current Input/Output string buffer.
+ * Must have at least uintToStringBufferSize chars free.
+ */
+static inline void uintToString(LargestUInt value, char*& current) {
+ *--current = 0;
+ do {
+ *--current = static_cast<signed char>(value % 10U + static_cast<unsigned>('0'));
+ value /= 10;
+ } while (value != 0);
+}
+
+/** Change ',' to '.' everywhere in buffer.
+ *
+ * We had a sophisticated way, but it did not work in WinCE.
+ * @see https://github.com/open-source-parsers/jsoncpp/pull/9
+ */
+static inline void fixNumericLocale(char* begin, char* end) {
+ while (begin < end) {
+ if (*begin == ',') {
+ *begin = '.';
+ }
+ ++begin;
+ }
+}
+
+} // namespace Json {
+
+#endif // LIB_JSONCPP_JSON_TOOL_H_INCLUDED
+
+// //////////////////////////////////////////////////////////////////////
+// End of content of file: src/lib_json/json_tool.h
+// //////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+// //////////////////////////////////////////////////////////////////////
+// Beginning of content of file: src/lib_json/json_reader.cpp
+// //////////////////////////////////////////////////////////////////////
+
+// Copyright 2007-2011 Baptiste Lepilleur
+// Distributed under MIT license, or public domain if desired and
+// recognized in your jurisdiction.
+// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
+
+#if !defined(JSON_IS_AMALGAMATION)
+#include <json/assertions.h>
+#include <json/reader.h>
+#include <json/value.h>
+#include "json_tool.h"
+#endif // if !defined(JSON_IS_AMALGAMATION)
+#include <utility>
+#include <cstdio>
+#include <cassert>
+#include <cstring>
+#include <istream>
+#include <sstream>
+#include <memory>
+#include <set>
+#include <limits>
+
+#if defined(_MSC_VER)
+#if !defined(WINCE) && defined(__STDC_SECURE_LIB__) && _MSC_VER >= 1500 // VC++ 9.0 and above
+#define snprintf sprintf_s
+#elif _MSC_VER >= 1900 // VC++ 14.0 and above
+#define snprintf std::snprintf
+#else
+#define snprintf _snprintf
+#endif
+#elif defined(__ANDROID__) || defined(__QNXNTO__)
+#define snprintf snprintf
+#elif __cplusplus >= 201103L
+#define snprintf std::snprintf
+#endif
+
+#if defined(__QNXNTO__)
+#define sscanf std::sscanf
+#endif
+
+#if defined(_MSC_VER) && _MSC_VER >= 1400 // VC++ 8.0
+// Disable warning about strdup being deprecated.
+#pragma warning(disable : 4996)
+#endif
+
+static int const stackLimit_g = 1000;
+static int stackDepth_g = 0; // see readValue()
+
+namespace Json {
+
+#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
+typedef std::unique_ptr<CharReader> CharReaderPtr;
+#else
+typedef std::auto_ptr<CharReader> CharReaderPtr;
+#endif
+
+// Implementation of class Features
+// ////////////////////////////////
+
+Features::Features()
+ : allowComments_(true), strictRoot_(false),
+ allowDroppedNullPlaceholders_(false), allowNumericKeys_(false) {}
+
+Features Features::all() { return Features(); }
+
+Features Features::strictMode() {
+ Features features;
+ features.allowComments_ = false;
+ features.strictRoot_ = true;
+ features.allowDroppedNullPlaceholders_ = false;
+ features.allowNumericKeys_ = false;
+ return features;
+}
+
+// Implementation of class Reader
+// ////////////////////////////////
+
+static bool containsNewLine(Reader::Location begin, Reader::Location end) {
+ for (; begin < end; ++begin)
+ if (*begin == '\n' || *begin == '\r')
+ return true;
+ return false;
+}
+
+// Class Reader
+// //////////////////////////////////////////////////////////////////
+
+Reader::Reader()
+ : errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(),
+ lastValue_(), commentsBefore_(), features_(Features::all()),
+ collectComments_() {}
+
+Reader::Reader(const Features& features)
+ : errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(),
+ lastValue_(), commentsBefore_(), features_(features), collectComments_() {
+}
+
+bool
+Reader::parse(const std::string& document, Value& root, bool collectComments) {
+ document_ = document;
+ const char* begin = document_.c_str();
+ const char* end = begin + document_.length();
+ return parse(begin, end, root, collectComments);
+}
+
+bool Reader::parse(std::istream& sin, Value& root, bool collectComments) {
+ // std::istream_iterator<char> begin(sin);
+ // std::istream_iterator<char> end;
+ // Those would allow streamed input from a file, if parse() were a
+ // template function.
+
+ // Since std::string is reference-counted, this at least does not
+ // create an extra copy.
+ std::string doc;
+ std::getline(sin, doc, (char)EOF);
+ return parse(doc, root, collectComments);
+}
+
+bool Reader::parse(const char* beginDoc,
+ const char* endDoc,
+ Value& root,
+ bool collectComments) {
+ if (!features_.allowComments_) {
+ collectComments = false;
+ }
+
+ begin_ = beginDoc;
+ end_ = endDoc;
+ collectComments_ = collectComments;
+ current_ = begin_;
+ lastValueEnd_ = 0;
+ lastValue_ = 0;
+ commentsBefore_ = "";
+ errors_.clear();
+ while (!nodes_.empty())
+ nodes_.pop();
+ nodes_.push(&root);
+
+ stackDepth_g = 0; // Yes, this is bad coding, but options are limited.
+ bool successful = readValue();
+ Token token;
+ skipCommentTokens(token);
+ if (collectComments_ && !commentsBefore_.empty())
+ root.setComment(commentsBefore_, commentAfter);
+ if (features_.strictRoot_) {
+ if (!root.isArray() && !root.isObject()) {
+ // Set error location to start of doc, ideally should be first token found
+ // in doc
+ token.type_ = tokenError;
+ token.start_ = beginDoc;
+ token.end_ = endDoc;
+ addError(
+ "A valid JSON document must be either an array or an object value.",
+ token);
+ return false;
+ }
+ }
+ return successful;
+}
+
+bool Reader::readValue() {
+ // This is a non-reentrant way to support a stackLimit. Terrible!
+ // But this deprecated class has a security problem: Bad input can
+ // cause a seg-fault. This seems like a fair, binary-compatible way
+ // to prevent the problem.
+ if (stackDepth_g >= stackLimit_g) throwRuntimeError("Exceeded stackLimit in readValue().");
+ ++stackDepth_g;
+
+ Token token;
+ skipCommentTokens(token);
+ bool successful = true;
+
+ if (collectComments_ && !commentsBefore_.empty()) {
+ currentValue().setComment(commentsBefore_, commentBefore);
+ commentsBefore_ = "";
+ }
+
+ switch (token.type_) {
+ case tokenObjectBegin:
+ successful = readObject(token);
+ currentValue().setOffsetLimit(current_ - begin_);
+ break;
+ case tokenArrayBegin:
+ successful = readArray(token);
+ currentValue().setOffsetLimit(current_ - begin_);
+ break;
+ case tokenNumber:
+ successful = decodeNumber(token);
+ break;
+ case tokenString:
+ successful = decodeString(token);
+ break;
+ case tokenTrue:
+ {
+ Value v(true);
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ }
+ break;
+ case tokenFalse:
+ {
+ Value v(false);
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ }
+ break;
+ case tokenNull:
+ {
+ Value v;
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ }
+ break;
+ case tokenArraySeparator:
+ case tokenObjectEnd:
+ case tokenArrayEnd:
+ if (features_.allowDroppedNullPlaceholders_) {
+ // "Un-read" the current token and mark the current value as a null
+ // token.
+ current_--;
+ Value v;
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(current_ - begin_ - 1);
+ currentValue().setOffsetLimit(current_ - begin_);
+ break;
+ } // Else, fall through...
+ default:
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ return addError("Syntax error: value, object or array expected.", token);
+ }
+
+ if (collectComments_) {
+ lastValueEnd_ = current_;
+ lastValue_ = &currentValue();
+ }
+
+ --stackDepth_g;
+ return successful;
+}
+
+void Reader::skipCommentTokens(Token& token) {
+ if (features_.allowComments_) {
+ do {
+ readToken(token);
+ } while (token.type_ == tokenComment);
+ } else {
+ readToken(token);
+ }
+}
+
+bool Reader::readToken(Token& token) {
+ skipSpaces();
+ token.start_ = current_;
+ Char c = getNextChar();
+ bool ok = true;
+ switch (c) {
+ case '{':
+ token.type_ = tokenObjectBegin;
+ break;
+ case '}':
+ token.type_ = tokenObjectEnd;
+ break;
+ case '[':
+ token.type_ = tokenArrayBegin;
+ break;
+ case ']':
+ token.type_ = tokenArrayEnd;
+ break;
+ case '"':
+ token.type_ = tokenString;
+ ok = readString();
+ break;
+ case '/':
+ token.type_ = tokenComment;
+ ok = readComment();
+ break;
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ case '-':
+ token.type_ = tokenNumber;
+ readNumber();
+ break;
+ case 't':
+ token.type_ = tokenTrue;
+ ok = match("rue", 3);
+ break;
+ case 'f':
+ token.type_ = tokenFalse;
+ ok = match("alse", 4);
+ break;
+ case 'n':
+ token.type_ = tokenNull;
+ ok = match("ull", 3);
+ break;
+ case ',':
+ token.type_ = tokenArraySeparator;
+ break;
+ case ':':
+ token.type_ = tokenMemberSeparator;
+ break;
+ case 0:
+ token.type_ = tokenEndOfStream;
+ break;
+ default:
+ ok = false;
+ break;
+ }
+ if (!ok)
+ token.type_ = tokenError;
+ token.end_ = current_;
+ return true;
+}
+
+void Reader::skipSpaces() {
+ while (current_ != end_) {
+ Char c = *current_;
+ if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
+ ++current_;
+ else
+ break;
+ }
+}
+
+bool Reader::match(Location pattern, int patternLength) {
+ if (end_ - current_ < patternLength)
+ return false;
+ int index = patternLength;
+ while (index--)
+ if (current_[index] != pattern[index])
+ return false;
+ current_ += patternLength;
+ return true;
+}
+
+bool Reader::readComment() {
+ Location commentBegin = current_ - 1;
+ Char c = getNextChar();
+ bool successful = false;
+ if (c == '*')
+ successful = readCStyleComment();
+ else if (c == '/')
+ successful = readCppStyleComment();
+ if (!successful)
+ return false;
+
+ if (collectComments_) {
+ CommentPlacement placement = commentBefore;
+ if (lastValueEnd_ && !containsNewLine(lastValueEnd_, commentBegin)) {
+ if (c != '*' || !containsNewLine(commentBegin, current_))
+ placement = commentAfterOnSameLine;
+ }
+
+ addComment(commentBegin, current_, placement);
+ }
+ return true;
+}
+
+static std::string normalizeEOL(Reader::Location begin, Reader::Location end) {
+ std::string normalized;
+ normalized.reserve(end - begin);
+ Reader::Location current = begin;
+ while (current != end) {
+ char c = *current++;
+ if (c == '\r') {
+ if (current != end && *current == '\n')
+ // convert dos EOL
+ ++current;
+ // convert Mac EOL
+ normalized += '\n';
+ } else {
+ normalized += c;
+ }
+ }
+ return normalized;
+}
+
+void
+Reader::addComment(Location begin, Location end, CommentPlacement placement) {
+ assert(collectComments_);
+ const std::string& normalized = normalizeEOL(begin, end);
+ if (placement == commentAfterOnSameLine) {
+ assert(lastValue_ != 0);
+ lastValue_->setComment(normalized, placement);
+ } else {
+ commentsBefore_ += normalized;
+ }
+}
+
+bool Reader::readCStyleComment() {
+ while (current_ != end_) {
+ Char c = getNextChar();
+ if (c == '*' && *current_ == '/')
+ break;
+ }
+ return getNextChar() == '/';
+}
+
+bool Reader::readCppStyleComment() {
+ while (current_ != end_) {
+ Char c = getNextChar();
+ if (c == '\n')
+ break;
+ if (c == '\r') {
+ // Consume DOS EOL. It will be normalized in addComment.
+ if (current_ != end_ && *current_ == '\n')
+ getNextChar();
+ // Break on Moc OS 9 EOL.
+ break;
+ }
+ }
+ return true;
+}
+
+void Reader::readNumber() {
+ const char *p = current_;
+ char c = '0'; // stopgap for already consumed character
+ // integral part
+ while (c >= '0' && c <= '9')
+ c = (current_ = p) < end_ ? *p++ : 0;
+ // fractional part
+ if (c == '.') {
+ c = (current_ = p) < end_ ? *p++ : 0;
+ while (c >= '0' && c <= '9')
+ c = (current_ = p) < end_ ? *p++ : 0;
+ }
+ // exponential part
+ if (c == 'e' || c == 'E') {
+ c = (current_ = p) < end_ ? *p++ : 0;
+ if (c == '+' || c == '-')
+ c = (current_ = p) < end_ ? *p++ : 0;
+ while (c >= '0' && c <= '9')
+ c = (current_ = p) < end_ ? *p++ : 0;
+ }
+}
+
+bool Reader::readString() {
+ Char c = 0;
+ while (current_ != end_) {
+ c = getNextChar();
+ if (c == '\\')
+ getNextChar();
+ else if (c == '"')
+ break;
+ }
+ return c == '"';
+}
+
+bool Reader::readObject(Token& tokenStart) {
+ Token tokenName;
+ std::string name;
+ Value init(objectValue);
+ currentValue().swapPayload(init);
+ currentValue().setOffsetStart(tokenStart.start_ - begin_);
+ while (readToken(tokenName)) {
+ bool initialTokenOk = true;
+ while (tokenName.type_ == tokenComment && initialTokenOk)
+ initialTokenOk = readToken(tokenName);
+ if (!initialTokenOk)
+ break;
+ if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object
+ return true;
+ name = "";
+ if (tokenName.type_ == tokenString) {
+ if (!decodeString(tokenName, name))
+ return recoverFromError(tokenObjectEnd);
+ } else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) {
+ Value numberName;
+ if (!decodeNumber(tokenName, numberName))
+ return recoverFromError(tokenObjectEnd);
+ name = numberName.asString();
+ } else {
+ break;
+ }
+
+ Token colon;
+ if (!readToken(colon) || colon.type_ != tokenMemberSeparator) {
+ return addErrorAndRecover(
+ "Missing ':' after object member name", colon, tokenObjectEnd);
+ }
+ Value& value = currentValue()[name];
+ nodes_.push(&value);
+ bool ok = readValue();
+ nodes_.pop();
+ if (!ok) // error already set
+ return recoverFromError(tokenObjectEnd);
+
+ Token comma;
+ if (!readToken(comma) ||
+ (comma.type_ != tokenObjectEnd && comma.type_ != tokenArraySeparator &&
+ comma.type_ != tokenComment)) {
+ return addErrorAndRecover(
+ "Missing ',' or '}' in object declaration", comma, tokenObjectEnd);
+ }
+ bool finalizeTokenOk = true;
+ while (comma.type_ == tokenComment && finalizeTokenOk)
+ finalizeTokenOk = readToken(comma);
+ if (comma.type_ == tokenObjectEnd)
+ return true;
+ }
+ return addErrorAndRecover(
+ "Missing '}' or object member name", tokenName, tokenObjectEnd);
+}
+
+bool Reader::readArray(Token& tokenStart) {
+ Value init(arrayValue);
+ currentValue().swapPayload(init);
+ currentValue().setOffsetStart(tokenStart.start_ - begin_);
+ skipSpaces();
+ if (*current_ == ']') // empty array
+ {
+ Token endArray;
+ readToken(endArray);
+ return true;
+ }
+ int index = 0;
+ for (;;) {
+ Value& value = currentValue()[index++];
+ nodes_.push(&value);
+ bool ok = readValue();
+ nodes_.pop();
+ if (!ok) // error already set
+ return recoverFromError(tokenArrayEnd);
+
+ Token token;
+ // Accept Comment after last item in the array.
+ ok = readToken(token);
+ while (token.type_ == tokenComment && ok) {
+ ok = readToken(token);
+ }
+ bool badTokenType =
+ (token.type_ != tokenArraySeparator && token.type_ != tokenArrayEnd);
+ if (!ok || badTokenType) {
+ return addErrorAndRecover(
+ "Missing ',' or ']' in array declaration", token, tokenArrayEnd);
+ }
+ if (token.type_ == tokenArrayEnd)
+ break;
+ }
+ return true;
+}
+
+bool Reader::decodeNumber(Token& token) {
+ Value decoded;
+ if (!decodeNumber(token, decoded))
+ return false;
+ currentValue().swapPayload(decoded);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ return true;
+}
+
+bool Reader::decodeNumber(Token& token, Value& decoded) {
+ // Attempts to parse the number as an integer. If the number is
+ // larger than the maximum supported value of an integer then
+ // we decode the number as a double.
+ Location current = token.start_;
+ bool isNegative = *current == '-';
+ if (isNegative)
+ ++current;
+ // TODO: Help the compiler do the div and mod at compile time or get rid of them.
+ Value::LargestUInt maxIntegerValue =
+ isNegative ? Value::LargestUInt(Value::maxLargestInt) + 1
+ : Value::maxLargestUInt;
+ Value::LargestUInt threshold = maxIntegerValue / 10;
+ Value::LargestUInt value = 0;
+ while (current < token.end_) {
+ Char c = *current++;
+ if (c < '0' || c > '9')
+ return decodeDouble(token, decoded);
+ Value::UInt digit(c - '0');
+ if (value >= threshold) {
+ // We've hit or exceeded the max value divided by 10 (rounded down). If
+ // a) we've only just touched the limit, b) this is the last digit, and
+ // c) it's small enough to fit in that rounding delta, we're okay.
+ // Otherwise treat this number as a double to avoid overflow.
+ if (value > threshold || current != token.end_ ||
+ digit > maxIntegerValue % 10) {
+ return decodeDouble(token, decoded);
+ }
+ }
+ value = value * 10 + digit;
+ }
+ if (isNegative && value == maxIntegerValue)
+ decoded = Value::minLargestInt;
+ else if (isNegative)
+ decoded = -Value::LargestInt(value);
+ else if (value <= Value::LargestUInt(Value::maxInt))
+ decoded = Value::LargestInt(value);
+ else
+ decoded = value;
+ return true;
+}
+
+bool Reader::decodeDouble(Token& token) {
+ Value decoded;
+ if (!decodeDouble(token, decoded))
+ return false;
+ currentValue().swapPayload(decoded);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ return true;
+}
+
+bool Reader::decodeDouble(Token& token, Value& decoded) {
+ double value = 0;
+ std::string buffer(token.start_, token.end_);
+ std::istringstream is(buffer);
+ if (!(is >> value))
+ return addError("'" + std::string(token.start_, token.end_) +
+ "' is not a number.",
+ token);
+ decoded = value;
+ return true;
+}
+
+bool Reader::decodeString(Token& token) {
+ std::string decoded_string;
+ if (!decodeString(token, decoded_string))
+ return false;
+ Value decoded(decoded_string);
+ currentValue().swapPayload(decoded);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ return true;
+}
+
+bool Reader::decodeString(Token& token, std::string& decoded) {
+ decoded.reserve(token.end_ - token.start_ - 2);
+ Location current = token.start_ + 1; // skip '"'
+ Location end = token.end_ - 1; // do not include '"'
+ while (current != end) {
+ Char c = *current++;
+ if (c == '"')
+ break;
+ else if (c == '\\') {
+ if (current == end)
+ return addError("Empty escape sequence in string", token, current);
+ Char escape = *current++;
+ switch (escape) {
+ case '"':
+ decoded += '"';
+ break;
+ case '/':
+ decoded += '/';
+ break;
+ case '\\':
+ decoded += '\\';
+ break;
+ case 'b':
+ decoded += '\b';
+ break;
+ case 'f':
+ decoded += '\f';
+ break;
+ case 'n':
+ decoded += '\n';
+ break;
+ case 'r':
+ decoded += '\r';
+ break;
+ case 't':
+ decoded += '\t';
+ break;
+ case 'u': {
+ unsigned int unicode;
+ if (!decodeUnicodeCodePoint(token, current, end, unicode))
+ return false;
+ decoded += codePointToUTF8(unicode);
+ } break;
+ default:
+ return addError("Bad escape sequence in string", token, current);
+ }
+ } else {
+ decoded += c;
+ }
+ }
+ return true;
+}
+
+bool Reader::decodeUnicodeCodePoint(Token& token,
+ Location& current,
+ Location end,
+ unsigned int& unicode) {
+
+ if (!decodeUnicodeEscapeSequence(token, current, end, unicode))
+ return false;
+ if (unicode >= 0xD800 && unicode <= 0xDBFF) {
+ // surrogate pairs
+ if (end - current < 6)
+ return addError(
+ "additional six characters expected to parse unicode surrogate pair.",
+ token,
+ current);
+ unsigned int surrogatePair;
+ if (*(current++) == '\\' && *(current++) == 'u') {
+ if (decodeUnicodeEscapeSequence(token, current, end, surrogatePair)) {
+ unicode = 0x10000 + ((unicode & 0x3FF) << 10) + (surrogatePair & 0x3FF);
+ } else
+ return false;
+ } else
+ return addError("expecting another \\u token to begin the second half of "
+ "a unicode surrogate pair",
+ token,
+ current);
+ }
+ return true;
+}
+
+bool Reader::decodeUnicodeEscapeSequence(Token& token,
+ Location& current,
+ Location end,
+ unsigned int& unicode) {
+ if (end - current < 4)
+ return addError(
+ "Bad unicode escape sequence in string: four digits expected.",
+ token,
+ current);
+ unicode = 0;
+ for (int index = 0; index < 4; ++index) {
+ Char c = *current++;
+ unicode *= 16;
+ if (c >= '0' && c <= '9')
+ unicode += c - '0';
+ else if (c >= 'a' && c <= 'f')
+ unicode += c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ unicode += c - 'A' + 10;
+ else
+ return addError(
+ "Bad unicode escape sequence in string: hexadecimal digit expected.",
+ token,
+ current);
+ }
+ return true;
+}
+
+bool
+Reader::addError(const std::string& message, Token& token, Location extra) {
+ ErrorInfo info;
+ info.token_ = token;
+ info.message_ = message;
+ info.extra_ = extra;
+ errors_.push_back(info);
+ return false;
+}
+
+bool Reader::recoverFromError(TokenType skipUntilToken) {
+ int errorCount = int(errors_.size());
+ Token skip;
+ for (;;) {
+ if (!readToken(skip))
+ errors_.resize(errorCount); // discard errors caused by recovery
+ if (skip.type_ == skipUntilToken || skip.type_ == tokenEndOfStream)
+ break;
+ }
+ errors_.resize(errorCount);
+ return false;
+}
+
+bool Reader::addErrorAndRecover(const std::string& message,
+ Token& token,
+ TokenType skipUntilToken) {
+ addError(message, token);
+ return recoverFromError(skipUntilToken);
+}
+
+Value& Reader::currentValue() { return *(nodes_.top()); }
+
+Reader::Char Reader::getNextChar() {
+ if (current_ == end_)
+ return 0;
+ return *current_++;
+}
+
+void Reader::getLocationLineAndColumn(Location location,
+ int& line,
+ int& column) const {
+ Location current = begin_;
+ Location lastLineStart = current;
+ line = 0;
+ while (current < location && current != end_) {
+ Char c = *current++;
+ if (c == '\r') {
+ if (*current == '\n')
+ ++current;
+ lastLineStart = current;
+ ++line;
+ } else if (c == '\n') {
+ lastLineStart = current;
+ ++line;
+ }
+ }
+ // column & line start at 1
+ column = int(location - lastLineStart) + 1;
+ ++line;
+}
+
+std::string Reader::getLocationLineAndColumn(Location location) const {
+ int line, column;
+ getLocationLineAndColumn(location, line, column);
+ char buffer[18 + 16 + 16 + 1];
+ snprintf(buffer, sizeof(buffer), "Line %d, Column %d", line, column);
+ return buffer;
+}
+
+// Deprecated. Preserved for backward compatibility
+std::string Reader::getFormatedErrorMessages() const {
+ return getFormattedErrorMessages();
+}
+
+std::string Reader::getFormattedErrorMessages() const {
+ std::string formattedMessage;
+ for (Errors::const_iterator itError = errors_.begin();
+ itError != errors_.end();
+ ++itError) {
+ const ErrorInfo& error = *itError;
+ formattedMessage +=
+ "* " + getLocationLineAndColumn(error.token_.start_) + "\n";
+ formattedMessage += " " + error.message_ + "\n";
+ if (error.extra_)
+ formattedMessage +=
+ "See " + getLocationLineAndColumn(error.extra_) + " for detail.\n";
+ }
+ return formattedMessage;
+}
+
+std::vector<Reader::StructuredError> Reader::getStructuredErrors() const {
+ std::vector<Reader::StructuredError> allErrors;
+ for (Errors::const_iterator itError = errors_.begin();
+ itError != errors_.end();
+ ++itError) {
+ const ErrorInfo& error = *itError;
+ Reader::StructuredError structured;
+ structured.offset_start = error.token_.start_ - begin_;
+ structured.offset_limit = error.token_.end_ - begin_;
+ structured.message = error.message_;
+ allErrors.push_back(structured);
+ }
+ return allErrors;
+}
+
+bool Reader::pushError(const Value& value, const std::string& message) {
+ size_t length = end_ - begin_;
+ if(value.getOffsetStart() > length
+ || value.getOffsetLimit() > length)
+ return false;
+ Token token;
+ token.type_ = tokenError;
+ token.start_ = begin_ + value.getOffsetStart();
+ token.end_ = end_ + value.getOffsetLimit();
+ ErrorInfo info;
+ info.token_ = token;
+ info.message_ = message;
+ info.extra_ = 0;
+ errors_.push_back(info);
+ return true;
+}
+
+bool Reader::pushError(const Value& value, const std::string& message, const Value& extra) {
+ size_t length = end_ - begin_;
+ if(value.getOffsetStart() > length
+ || value.getOffsetLimit() > length
+ || extra.getOffsetLimit() > length)
+ return false;
+ Token token;
+ token.type_ = tokenError;
+ token.start_ = begin_ + value.getOffsetStart();
+ token.end_ = begin_ + value.getOffsetLimit();
+ ErrorInfo info;
+ info.token_ = token;
+ info.message_ = message;
+ info.extra_ = begin_ + extra.getOffsetStart();
+ errors_.push_back(info);
+ return true;
+}
+
+bool Reader::good() const {
+ return !errors_.size();
+}
+
+// exact copy of Features
+class OurFeatures {
+public:
+ static OurFeatures all();
+ bool allowComments_;
+ bool strictRoot_;
+ bool allowDroppedNullPlaceholders_;
+ bool allowNumericKeys_;
+ bool allowSingleQuotes_;
+ bool failIfExtra_;
+ bool rejectDupKeys_;
+ bool allowSpecialFloats_;
+ int stackLimit_;
+}; // OurFeatures
+
+// exact copy of Implementation of class Features
+// ////////////////////////////////
+
+OurFeatures OurFeatures::all() { return OurFeatures(); }
+
+// Implementation of class Reader
+// ////////////////////////////////
+
+// exact copy of Reader, renamed to OurReader
+class OurReader {
+public:
+ typedef char Char;
+ typedef const Char* Location;
+ struct StructuredError {
+ size_t offset_start;
+ size_t offset_limit;
+ std::string message;
+ };
+
+ OurReader(OurFeatures const& features);
+ bool parse(const char* beginDoc,
+ const char* endDoc,
+ Value& root,
+ bool collectComments = true);
+ std::string getFormattedErrorMessages() const;
+ std::vector<StructuredError> getStructuredErrors() const;
+ bool pushError(const Value& value, const std::string& message);
+ bool pushError(const Value& value, const std::string& message, const Value& extra);
+ bool good() const;
+
+private:
+ OurReader(OurReader const&); // no impl
+ void operator=(OurReader const&); // no impl
+
+ enum TokenType {
+ tokenEndOfStream = 0,
+ tokenObjectBegin,
+ tokenObjectEnd,
+ tokenArrayBegin,
+ tokenArrayEnd,
+ tokenString,
+ tokenNumber,
+ tokenTrue,
+ tokenFalse,
+ tokenNull,
+ tokenNaN,
+ tokenPosInf,
+ tokenNegInf,
+ tokenArraySeparator,
+ tokenMemberSeparator,
+ tokenComment,
+ tokenError
+ };
+
+ class Token {
+ public:
+ TokenType type_;
+ Location start_;
+ Location end_;
+ };
+
+ class ErrorInfo {
+ public:
+ Token token_;
+ std::string message_;
+ Location extra_;
+ };
+
+ typedef std::deque<ErrorInfo> Errors;
+
+ bool readToken(Token& token);
+ void skipSpaces();
+ bool match(Location pattern, int patternLength);
+ bool readComment();
+ bool readCStyleComment();
+ bool readCppStyleComment();
+ bool readString();
+ bool readStringSingleQuote();
+ bool readNumber(bool checkInf);
+ bool readValue();
+ bool readObject(Token& token);
+ bool readArray(Token& token);
+ bool decodeNumber(Token& token);
+ bool decodeNumber(Token& token, Value& decoded);
+ bool decodeString(Token& token);
+ bool decodeString(Token& token, std::string& decoded);
+ bool decodeDouble(Token& token);
+ bool decodeDouble(Token& token, Value& decoded);
+ bool decodeUnicodeCodePoint(Token& token,
+ Location& current,
+ Location end,
+ unsigned int& unicode);
+ bool decodeUnicodeEscapeSequence(Token& token,
+ Location& current,
+ Location end,
+ unsigned int& unicode);
+ bool addError(const std::string& message, Token& token, Location extra = 0);
+ bool recoverFromError(TokenType skipUntilToken);
+ bool addErrorAndRecover(const std::string& message,
+ Token& token,
+ TokenType skipUntilToken);
+ void skipUntilSpace();
+ Value& currentValue();
+ Char getNextChar();
+ void
+ getLocationLineAndColumn(Location location, int& line, int& column) const;
+ std::string getLocationLineAndColumn(Location location) const;
+ void addComment(Location begin, Location end, CommentPlacement placement);
+ void skipCommentTokens(Token& token);
+
+ typedef std::stack<Value*> Nodes;
+ Nodes nodes_;
+ Errors errors_;
+ std::string document_;
+ Location begin_;
+ Location end_;
+ Location current_;
+ Location lastValueEnd_;
+ Value* lastValue_;
+ std::string commentsBefore_;
+ int stackDepth_;
+
+ OurFeatures const features_;
+ bool collectComments_;
+}; // OurReader
+
+// complete copy of Read impl, for OurReader
+
+OurReader::OurReader(OurFeatures const& features)
+ : errors_(), document_(), begin_(), end_(), current_(), lastValueEnd_(),
+ lastValue_(), commentsBefore_(),
+ stackDepth_(0),
+ features_(features), collectComments_() {
+}
+
+bool OurReader::parse(const char* beginDoc,
+ const char* endDoc,
+ Value& root,
+ bool collectComments) {
+ if (!features_.allowComments_) {
+ collectComments = false;
+ }
+
+ begin_ = beginDoc;
+ end_ = endDoc;
+ collectComments_ = collectComments;
+ current_ = begin_;
+ lastValueEnd_ = 0;
+ lastValue_ = 0;
+ commentsBefore_ = "";
+ errors_.clear();
+ while (!nodes_.empty())
+ nodes_.pop();
+ nodes_.push(&root);
+
+ stackDepth_ = 0;
+ bool successful = readValue();
+ Token token;
+ skipCommentTokens(token);
+ if (features_.failIfExtra_) {
+ if (token.type_ != tokenError && token.type_ != tokenEndOfStream) {
+ addError("Extra non-whitespace after JSON value.", token);
+ return false;
+ }
+ }
+ if (collectComments_ && !commentsBefore_.empty())
+ root.setComment(commentsBefore_, commentAfter);
+ if (features_.strictRoot_) {
+ if (!root.isArray() && !root.isObject()) {
+ // Set error location to start of doc, ideally should be first token found
+ // in doc
+ token.type_ = tokenError;
+ token.start_ = beginDoc;
+ token.end_ = endDoc;
+ addError(
+ "A valid JSON document must be either an array or an object value.",
+ token);
+ return false;
+ }
+ }
+ return successful;
+}
+
+bool OurReader::readValue() {
+ if (stackDepth_ >= features_.stackLimit_) throwRuntimeError("Exceeded stackLimit in readValue().");
+ ++stackDepth_;
+ Token token;
+ skipCommentTokens(token);
+ bool successful = true;
+
+ if (collectComments_ && !commentsBefore_.empty()) {
+ currentValue().setComment(commentsBefore_, commentBefore);
+ commentsBefore_ = "";
+ }
+
+ switch (token.type_) {
+ case tokenObjectBegin:
+ successful = readObject(token);
+ currentValue().setOffsetLimit(current_ - begin_);
+ break;
+ case tokenArrayBegin:
+ successful = readArray(token);
+ currentValue().setOffsetLimit(current_ - begin_);
+ break;
+ case tokenNumber:
+ successful = decodeNumber(token);
+ break;
+ case tokenString:
+ successful = decodeString(token);
+ break;
+ case tokenTrue:
+ {
+ Value v(true);
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ }
+ break;
+ case tokenFalse:
+ {
+ Value v(false);
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ }
+ break;
+ case tokenNull:
+ {
+ Value v;
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ }
+ break;
+ case tokenNaN:
+ {
+ Value v(std::numeric_limits<double>::quiet_NaN());
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ }
+ break;
+ case tokenPosInf:
+ {
+ Value v(std::numeric_limits<double>::infinity());
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ }
+ break;
+ case tokenNegInf:
+ {
+ Value v(-std::numeric_limits<double>::infinity());
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ }
+ break;
+ case tokenArraySeparator:
+ case tokenObjectEnd:
+ case tokenArrayEnd:
+ if (features_.allowDroppedNullPlaceholders_) {
+ // "Un-read" the current token and mark the current value as a null
+ // token.
+ current_--;
+ Value v;
+ currentValue().swapPayload(v);
+ currentValue().setOffsetStart(current_ - begin_ - 1);
+ currentValue().setOffsetLimit(current_ - begin_);
+ break;
+ } // else, fall through ...
+ default:
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ return addError("Syntax error: value, object or array expected.", token);
+ }
+
+ if (collectComments_) {
+ lastValueEnd_ = current_;
+ lastValue_ = &currentValue();
+ }
+
+ --stackDepth_;
+ return successful;
+}
+
+void OurReader::skipCommentTokens(Token& token) {
+ if (features_.allowComments_) {
+ do {
+ readToken(token);
+ } while (token.type_ == tokenComment);
+ } else {
+ readToken(token);
+ }
+}
+
+bool OurReader::readToken(Token& token) {
+ skipSpaces();
+ token.start_ = current_;
+ Char c = getNextChar();
+ bool ok = true;
+ switch (c) {
+ case '{':
+ token.type_ = tokenObjectBegin;
+ break;
+ case '}':
+ token.type_ = tokenObjectEnd;
+ break;
+ case '[':
+ token.type_ = tokenArrayBegin;
+ break;
+ case ']':
+ token.type_ = tokenArrayEnd;
+ break;
+ case '"':
+ token.type_ = tokenString;
+ ok = readString();
+ break;
+ case '\'':
+ if (features_.allowSingleQuotes_) {
+ token.type_ = tokenString;
+ ok = readStringSingleQuote();
+ break;
+ } // else continue
+ case '/':
+ token.type_ = tokenComment;
+ ok = readComment();
+ break;
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ token.type_ = tokenNumber;
+ readNumber(false);
+ break;
+ case '-':
+ if (readNumber(true)) {
+ token.type_ = tokenNumber;
+ } else {
+ token.type_ = tokenNegInf;
+ ok = features_.allowSpecialFloats_ && match("nfinity", 7);
+ }
+ break;
+ case 't':
+ token.type_ = tokenTrue;
+ ok = match("rue", 3);
+ break;
+ case 'f':
+ token.type_ = tokenFalse;
+ ok = match("alse", 4);
+ break;
+ case 'n':
+ token.type_ = tokenNull;
+ ok = match("ull", 3);
+ break;
+ case 'N':
+ if (features_.allowSpecialFloats_) {
+ token.type_ = tokenNaN;
+ ok = match("aN", 2);
+ } else {
+ ok = false;
+ }
+ break;
+ case 'I':
+ if (features_.allowSpecialFloats_) {
+ token.type_ = tokenPosInf;
+ ok = match("nfinity", 7);
+ } else {
+ ok = false;
+ }
+ break;
+ case ',':
+ token.type_ = tokenArraySeparator;
+ break;
+ case ':':
+ token.type_ = tokenMemberSeparator;
+ break;
+ case 0:
+ token.type_ = tokenEndOfStream;
+ break;
+ default:
+ ok = false;
+ break;
+ }
+ if (!ok)
+ token.type_ = tokenError;
+ token.end_ = current_;
+ return true;
+}
+
+void OurReader::skipSpaces() {
+ while (current_ != end_) {
+ Char c = *current_;
+ if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
+ ++current_;
+ else
+ break;
+ }
+}
+
+bool OurReader::match(Location pattern, int patternLength) {
+ if (end_ - current_ < patternLength)
+ return false;
+ int index = patternLength;
+ while (index--)
+ if (current_[index] != pattern[index])
+ return false;
+ current_ += patternLength;
+ return true;
+}
+
+bool OurReader::readComment() {
+ Location commentBegin = current_ - 1;
+ Char c = getNextChar();
+ bool successful = false;
+ if (c == '*')
+ successful = readCStyleComment();
+ else if (c == '/')
+ successful = readCppStyleComment();
+ if (!successful)
+ return false;
+
+ if (collectComments_) {
+ CommentPlacement placement = commentBefore;
+ if (lastValueEnd_ && !containsNewLine(lastValueEnd_, commentBegin)) {
+ if (c != '*' || !containsNewLine(commentBegin, current_))
+ placement = commentAfterOnSameLine;
+ }
+
+ addComment(commentBegin, current_, placement);
+ }
+ return true;
+}
+
+void
+OurReader::addComment(Location begin, Location end, CommentPlacement placement) {
+ assert(collectComments_);
+ const std::string& normalized = normalizeEOL(begin, end);
+ if (placement == commentAfterOnSameLine) {
+ assert(lastValue_ != 0);
+ lastValue_->setComment(normalized, placement);
+ } else {
+ commentsBefore_ += normalized;
+ }
+}
+
+bool OurReader::readCStyleComment() {
+ while (current_ != end_) {
+ Char c = getNextChar();
+ if (c == '*' && *current_ == '/')
+ break;
+ }
+ return getNextChar() == '/';
+}
+
+bool OurReader::readCppStyleComment() {
+ while (current_ != end_) {
+ Char c = getNextChar();
+ if (c == '\n')
+ break;
+ if (c == '\r') {
+ // Consume DOS EOL. It will be normalized in addComment.
+ if (current_ != end_ && *current_ == '\n')
+ getNextChar();
+ // Break on Moc OS 9 EOL.
+ break;
+ }
+ }
+ return true;
+}
+
+bool OurReader::readNumber(bool checkInf) {
+ const char *p = current_;
+ if (checkInf && p != end_ && *p == 'I') {
+ current_ = ++p;
+ return false;
+ }
+ char c = '0'; // stopgap for already consumed character
+ // integral part
+ while (c >= '0' && c <= '9')
+ c = (current_ = p) < end_ ? *p++ : 0;
+ // fractional part
+ if (c == '.') {
+ c = (current_ = p) < end_ ? *p++ : 0;
+ while (c >= '0' && c <= '9')
+ c = (current_ = p) < end_ ? *p++ : 0;
+ }
+ // exponential part
+ if (c == 'e' || c == 'E') {
+ c = (current_ = p) < end_ ? *p++ : 0;
+ if (c == '+' || c == '-')
+ c = (current_ = p) < end_ ? *p++ : 0;
+ while (c >= '0' && c <= '9')
+ c = (current_ = p) < end_ ? *p++ : 0;
+ }
+ return true;
+}
+bool OurReader::readString() {
+ Char c = 0;
+ while (current_ != end_) {
+ c = getNextChar();
+ if (c == '\\')
+ getNextChar();
+ else if (c == '"')
+ break;
+ }
+ return c == '"';
+}
+
+
+bool OurReader::readStringSingleQuote() {
+ Char c = 0;
+ while (current_ != end_) {
+ c = getNextChar();
+ if (c == '\\')
+ getNextChar();
+ else if (c == '\'')
+ break;
+ }
+ return c == '\'';
+}
+
+bool OurReader::readObject(Token& tokenStart) {
+ Token tokenName;
+ std::string name;
+ Value init(objectValue);
+ currentValue().swapPayload(init);
+ currentValue().setOffsetStart(tokenStart.start_ - begin_);
+ while (readToken(tokenName)) {
+ bool initialTokenOk = true;
+ while (tokenName.type_ == tokenComment && initialTokenOk)
+ initialTokenOk = readToken(tokenName);
+ if (!initialTokenOk)
+ break;
+ if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object
+ return true;
+ name = "";
+ if (tokenName.type_ == tokenString) {
+ if (!decodeString(tokenName, name))
+ return recoverFromError(tokenObjectEnd);
+ } else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) {
+ Value numberName;
+ if (!decodeNumber(tokenName, numberName))
+ return recoverFromError(tokenObjectEnd);
+ name = numberName.asString();
+ } else {
+ break;
+ }
+
+ Token colon;
+ if (!readToken(colon) || colon.type_ != tokenMemberSeparator) {
+ return addErrorAndRecover(
+ "Missing ':' after object member name", colon, tokenObjectEnd);
+ }
+ if (name.length() >= (1U<<30)) throwRuntimeError("keylength >= 2^30");
+ if (features_.rejectDupKeys_ && currentValue().isMember(name)) {
+ std::string msg = "Duplicate key: '" + name + "'";
+ return addErrorAndRecover(
+ msg, tokenName, tokenObjectEnd);
+ }
+ Value& value = currentValue()[name];
+ nodes_.push(&value);
+ bool ok = readValue();
+ nodes_.pop();
+ if (!ok) // error already set
+ return recoverFromError(tokenObjectEnd);
+
+ Token comma;
+ if (!readToken(comma) ||
+ (comma.type_ != tokenObjectEnd && comma.type_ != tokenArraySeparator &&
+ comma.type_ != tokenComment)) {
+ return addErrorAndRecover(
+ "Missing ',' or '}' in object declaration", comma, tokenObjectEnd);
+ }
+ bool finalizeTokenOk = true;
+ while (comma.type_ == tokenComment && finalizeTokenOk)
+ finalizeTokenOk = readToken(comma);
+ if (comma.type_ == tokenObjectEnd)
+ return true;
+ }
+ return addErrorAndRecover(
+ "Missing '}' or object member name", tokenName, tokenObjectEnd);
+}
+
+bool OurReader::readArray(Token& tokenStart) {
+ Value init(arrayValue);
+ currentValue().swapPayload(init);
+ currentValue().setOffsetStart(tokenStart.start_ - begin_);
+ skipSpaces();
+ if (*current_ == ']') // empty array
+ {
+ Token endArray;
+ readToken(endArray);
+ return true;
+ }
+ int index = 0;
+ for (;;) {
+ Value& value = currentValue()[index++];
+ nodes_.push(&value);
+ bool ok = readValue();
+ nodes_.pop();
+ if (!ok) // error already set
+ return recoverFromError(tokenArrayEnd);
+
+ Token token;
+ // Accept Comment after last item in the array.
+ ok = readToken(token);
+ while (token.type_ == tokenComment && ok) {
+ ok = readToken(token);
+ }
+ bool badTokenType =
+ (token.type_ != tokenArraySeparator && token.type_ != tokenArrayEnd);
+ if (!ok || badTokenType) {
+ return addErrorAndRecover(
+ "Missing ',' or ']' in array declaration", token, tokenArrayEnd);
+ }
+ if (token.type_ == tokenArrayEnd)
+ break;
+ }
+ return true;
+}
+
+bool OurReader::decodeNumber(Token& token) {
+ Value decoded;
+ if (!decodeNumber(token, decoded))
+ return false;
+ currentValue().swapPayload(decoded);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ return true;
+}
+
+bool OurReader::decodeNumber(Token& token, Value& decoded) {
+ // Attempts to parse the number as an integer. If the number is
+ // larger than the maximum supported value of an integer then
+ // we decode the number as a double.
+ Location current = token.start_;
+ bool isNegative = *current == '-';
+ if (isNegative)
+ ++current;
+ // TODO: Help the compiler do the div and mod at compile time or get rid of them.
+ Value::LargestUInt maxIntegerValue =
+ isNegative ? Value::LargestUInt(-Value::minLargestInt)
+ : Value::maxLargestUInt;
+ Value::LargestUInt threshold = maxIntegerValue / 10;
+ Value::LargestUInt value = 0;
+ while (current < token.end_) {
+ Char c = *current++;
+ if (c < '0' || c > '9')
+ return decodeDouble(token, decoded);
+ Value::UInt digit(c - '0');
+ if (value >= threshold) {
+ // We've hit or exceeded the max value divided by 10 (rounded down). If
+ // a) we've only just touched the limit, b) this is the last digit, and
+ // c) it's small enough to fit in that rounding delta, we're okay.
+ // Otherwise treat this number as a double to avoid overflow.
+ if (value > threshold || current != token.end_ ||
+ digit > maxIntegerValue % 10) {
+ return decodeDouble(token, decoded);
+ }
+ }
+ value = value * 10 + digit;
+ }
+ if (isNegative)
+ decoded = -Value::LargestInt(value);
+ else if (value <= Value::LargestUInt(Value::maxInt))
+ decoded = Value::LargestInt(value);
+ else
+ decoded = value;
+ return true;
+}
+
+bool OurReader::decodeDouble(Token& token) {
+ Value decoded;
+ if (!decodeDouble(token, decoded))
+ return false;
+ currentValue().swapPayload(decoded);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ return true;
+}
+
+bool OurReader::decodeDouble(Token& token, Value& decoded) {
+ double value = 0;
+ const int bufferSize = 32;
+ int count;
+ int length = int(token.end_ - token.start_);
+
+ // Sanity check to avoid buffer overflow exploits.
+ if (length < 0) {
+ return addError("Unable to parse token length", token);
+ }
+
+ // Avoid using a string constant for the format control string given to
+ // sscanf, as this can cause hard to debug crashes on OS X. See here for more
+ // info:
+ //
+ // http://developer.apple.com/library/mac/#DOCUMENTATION/DeveloperTools/gcc-4.0.1/gcc/Incompatibilities.html
+ char format[] = "%lf";
+
+ if (length <= bufferSize) {
+ Char buffer[bufferSize + 1];
+ memcpy(buffer, token.start_, length);
+ buffer[length] = 0;
+ count = sscanf(buffer, format, &value);
+ } else {
+ std::string buffer(token.start_, token.end_);
+ count = sscanf(buffer.c_str(), format, &value);
+ }
+
+ if (count != 1)
+ return addError("'" + std::string(token.start_, token.end_) +
+ "' is not a number.",
+ token);
+ decoded = value;
+ return true;
+}
+
+bool OurReader::decodeString(Token& token) {
+ std::string decoded_string;
+ if (!decodeString(token, decoded_string))
+ return false;
+ Value decoded(decoded_string);
+ currentValue().swapPayload(decoded);
+ currentValue().setOffsetStart(token.start_ - begin_);
+ currentValue().setOffsetLimit(token.end_ - begin_);
+ return true;
+}
+
+bool OurReader::decodeString(Token& token, std::string& decoded) {
+ decoded.reserve(token.end_ - token.start_ - 2);
+ Location current = token.start_ + 1; // skip '"'
+ Location end = token.end_ - 1; // do not include '"'
+ while (current != end) {
+ Char c = *current++;
+ if (c == '"')
+ break;
+ else if (c == '\\') {
+ if (current == end)
+ return addError("Empty escape sequence in string", token, current);
+ Char escape = *current++;
+ switch (escape) {
+ case '"':
+ decoded += '"';
+ break;
+ case '/':
+ decoded += '/';
+ break;
+ case '\\':
+ decoded += '\\';
+ break;
+ case 'b':
+ decoded += '\b';
+ break;
+ case 'f':
+ decoded += '\f';
+ break;
+ case 'n':
+ decoded += '\n';
+ break;
+ case 'r':
+ decoded += '\r';
+ break;
+ case 't':
+ decoded += '\t';
+ break;
+ case 'u': {
+ unsigned int unicode;
+ if (!decodeUnicodeCodePoint(token, current, end, unicode))
+ return false;
+ decoded += codePointToUTF8(unicode);
+ } break;
+ default:
+ return addError("Bad escape sequence in string", token, current);
+ }
+ } else {
+ decoded += c;
+ }
+ }
+ return true;
+}
+
+bool OurReader::decodeUnicodeCodePoint(Token& token,
+ Location& current,
+ Location end,
+ unsigned int& unicode) {
+
+ if (!decodeUnicodeEscapeSequence(token, current, end, unicode))
+ return false;
+ if (unicode >= 0xD800 && unicode <= 0xDBFF) {
+ // surrogate pairs
+ if (end - current < 6)
+ return addError(
+ "additional six characters expected to parse unicode surrogate pair.",
+ token,
+ current);
+ unsigned int surrogatePair;
+ if (*(current++) == '\\' && *(current++) == 'u') {
+ if (decodeUnicodeEscapeSequence(token, current, end, surrogatePair)) {
+ unicode = 0x10000 + ((unicode & 0x3FF) << 10) + (surrogatePair & 0x3FF);
+ } else
+ return false;
+ } else
+ return addError("expecting another \\u token to begin the second half of "
+ "a unicode surrogate pair",
+ token,
+ current);
+ }
+ return true;
+}
+
+bool OurReader::decodeUnicodeEscapeSequence(Token& token,
+ Location& current,
+ Location end,
+ unsigned int& unicode) {
+ if (end - current < 4)
+ return addError(
+ "Bad unicode escape sequence in string: four digits expected.",
+ token,
+ current);
+ unicode = 0;
+ for (int index = 0; index < 4; ++index) {
+ Char c = *current++;
+ unicode *= 16;
+ if (c >= '0' && c <= '9')
+ unicode += c - '0';
+ else if (c >= 'a' && c <= 'f')
+ unicode += c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ unicode += c - 'A' + 10;
+ else
+ return addError(
+ "Bad unicode escape sequence in string: hexadecimal digit expected.",
+ token,
+ current);
+ }
+ return true;
+}
+
+bool
+OurReader::addError(const std::string& message, Token& token, Location extra) {
+ ErrorInfo info;
+ info.token_ = token;
+ info.message_ = message;
+ info.extra_ = extra;
+ errors_.push_back(info);
+ return false;
+}
+
+bool OurReader::recoverFromError(TokenType skipUntilToken) {
+ int errorCount = int(errors_.size());
+ Token skip;
+ for (;;) {
+ if (!readToken(skip))
+ errors_.resize(errorCount); // discard errors caused by recovery
+ if (skip.type_ == skipUntilToken || skip.type_ == tokenEndOfStream)
+ break;
+ }
+ errors_.resize(errorCount);
+ return false;
+}
+
+bool OurReader::addErrorAndRecover(const std::string& message,
+ Token& token,
+ TokenType skipUntilToken) {
+ addError(message, token);
+ return recoverFromError(skipUntilToken);
+}
+
+Value& OurReader::currentValue() { return *(nodes_.top()); }
+
+OurReader::Char OurReader::getNextChar() {
+ if (current_ == end_)
+ return 0;
+ return *current_++;
+}
+
+void OurReader::getLocationLineAndColumn(Location location,
+ int& line,
+ int& column) const {
+ Location current = begin_;
+ Location lastLineStart = current;
+ line = 0;
+ while (current < location && current != end_) {
+ Char c = *current++;
+ if (c == '\r') {
+ if (*current == '\n')
+ ++current;
+ lastLineStart = current;
+ ++line;
+ } else if (c == '\n') {
+ lastLineStart = current;
+ ++line;
+ }
+ }
+ // column & line start at 1
+ column = int(location - lastLineStart) + 1;
+ ++line;
+}
+
+std::string OurReader::getLocationLineAndColumn(Location location) const {
+ int line, column;
+ getLocationLineAndColumn(location, line, column);
+ char buffer[18 + 16 + 16 + 1];
+ snprintf(buffer, sizeof(buffer), "Line %d, Column %d", line, column);
+ return buffer;
+}
+
+std::string OurReader::getFormattedErrorMessages() const {
+ std::string formattedMessage;
+ for (Errors::const_iterator itError = errors_.begin();
+ itError != errors_.end();
+ ++itError) {
+ const ErrorInfo& error = *itError;
+ formattedMessage +=
+ "* " + getLocationLineAndColumn(error.token_.start_) + "\n";
+ formattedMessage += " " + error.message_ + "\n";
+ if (error.extra_)
+ formattedMessage +=
+ "See " + getLocationLineAndColumn(error.extra_) + " for detail.\n";
+ }
+ return formattedMessage;
+}
+
+std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
+ std::vector<OurReader::StructuredError> allErrors;
+ for (Errors::const_iterator itError = errors_.begin();
+ itError != errors_.end();
+ ++itError) {
+ const ErrorInfo& error = *itError;
+ OurReader::StructuredError structured;
+ structured.offset_start = error.token_.start_ - begin_;
+ structured.offset_limit = error.token_.end_ - begin_;
+ structured.message = error.message_;
+ allErrors.push_back(structured);
+ }
+ return allErrors;
+}
+
+bool OurReader::pushError(const Value& value, const std::string& message) {
+ size_t length = end_ - begin_;
+ if(value.getOffsetStart() > length
+ || value.getOffsetLimit() > length)
+ return false;
+ Token token;
+ token.type_ = tokenError;
+ token.start_ = begin_ + value.getOffsetStart();
+ token.end_ = end_ + value.getOffsetLimit();
+ ErrorInfo info;
+ info.token_ = token;
+ info.message_ = message;
+ info.extra_ = 0;
+ errors_.push_back(info);
+ return true;
+}
+
+bool OurReader::pushError(const Value& value, const std::string& message, const Value& extra) {
+ size_t length = end_ - begin_;
+ if(value.getOffsetStart() > length
+ || value.getOffsetLimit() > length
+ || extra.getOffsetLimit() > length)
+ return false;
+ Token token;
+ token.type_ = tokenError;
+ token.start_ = begin_ + value.getOffsetStart();
+ token.end_ = begin_ + value.getOffsetLimit();
+ ErrorInfo info;
+ info.token_ = token;
+ info.message_ = message;
+ info.extra_ = begin_ + extra.getOffsetStart();
+ errors_.push_back(info);
+ return true;
+}
+
+bool OurReader::good() const {
+ return !errors_.size();
+}
+
+
+class OurCharReader : public CharReader {
+ bool const collectComments_;
+ OurReader reader_;
+public:
+ OurCharReader(
+ bool collectComments,
+ OurFeatures const& features)
+ : collectComments_(collectComments)
+ , reader_(features)
+ {}
+ bool parse(
+ char const* beginDoc, char const* endDoc,
+ Value* root, std::string* errs) override {
+ bool ok = reader_.parse(beginDoc, endDoc, *root, collectComments_);
+ if (errs) {
+ *errs = reader_.getFormattedErrorMessages();
+ }
+ return ok;
+ }
+};
+
+CharReaderBuilder::CharReaderBuilder()
+{
+ setDefaults(&settings_);
+}
+CharReaderBuilder::~CharReaderBuilder()
+{}
+CharReader* CharReaderBuilder::newCharReader() const
+{
+ bool collectComments = settings_["collectComments"].asBool();
+ OurFeatures features = OurFeatures::all();
+ features.allowComments_ = settings_["allowComments"].asBool();
+ features.strictRoot_ = settings_["strictRoot"].asBool();
+ features.allowDroppedNullPlaceholders_ = settings_["allowDroppedNullPlaceholders"].asBool();
+ features.allowNumericKeys_ = settings_["allowNumericKeys"].asBool();
+ features.allowSingleQuotes_ = settings_["allowSingleQuotes"].asBool();
+ features.stackLimit_ = settings_["stackLimit"].asInt();
+ features.failIfExtra_ = settings_["failIfExtra"].asBool();
+ features.rejectDupKeys_ = settings_["rejectDupKeys"].asBool();
+ features.allowSpecialFloats_ = settings_["allowSpecialFloats"].asBool();
+ return new OurCharReader(collectComments, features);
+}
+static void getValidReaderKeys(std::set<std::string>* valid_keys)
+{
+ valid_keys->clear();
+ valid_keys->insert("collectComments");
+ valid_keys->insert("allowComments");
+ valid_keys->insert("strictRoot");
+ valid_keys->insert("allowDroppedNullPlaceholders");
+ valid_keys->insert("allowNumericKeys");
+ valid_keys->insert("allowSingleQuotes");
+ valid_keys->insert("stackLimit");
+ valid_keys->insert("failIfExtra");
+ valid_keys->insert("rejectDupKeys");
+ valid_keys->insert("allowSpecialFloats");
+}
+bool CharReaderBuilder::validate(Json::Value* invalid) const
+{
+ Json::Value my_invalid;
+ if (!invalid) invalid = &my_invalid; // so we do not need to test for NULL
+ Json::Value& inv = *invalid;
+ std::set<std::string> valid_keys;
+ getValidReaderKeys(&valid_keys);
+ Value::Members keys = settings_.getMemberNames();
+ size_t n = keys.size();
+ for (size_t i = 0; i < n; ++i) {
+ std::string const& key = keys[i];
+ if (valid_keys.find(key) == valid_keys.end()) {
+ inv[key] = settings_[key];
+ }
+ }
+ return 0u == inv.size();
+}
+Value& CharReaderBuilder::operator[](std::string key)
+{
+ return settings_[key];
+}
+// static
+void CharReaderBuilder::strictMode(Json::Value* settings)
+{
+//! [CharReaderBuilderStrictMode]
+ (*settings)["allowComments"] = false;
+ (*settings)["strictRoot"] = true;
+ (*settings)["allowDroppedNullPlaceholders"] = false;
+ (*settings)["allowNumericKeys"] = false;
+ (*settings)["allowSingleQuotes"] = false;
+ (*settings)["stackLimit"] = 1000;
+ (*settings)["failIfExtra"] = true;
+ (*settings)["rejectDupKeys"] = true;
+ (*settings)["allowSpecialFloats"] = false;
+//! [CharReaderBuilderStrictMode]
+}
+// static
+void CharReaderBuilder::setDefaults(Json::Value* settings)
+{
+//! [CharReaderBuilderDefaults]
+ (*settings)["collectComments"] = true;
+ (*settings)["allowComments"] = true;
+ (*settings)["strictRoot"] = false;
+ (*settings)["allowDroppedNullPlaceholders"] = false;
+ (*settings)["allowNumericKeys"] = false;
+ (*settings)["allowSingleQuotes"] = false;
+ (*settings)["stackLimit"] = 1000;
+ (*settings)["failIfExtra"] = false;
+ (*settings)["rejectDupKeys"] = false;
+ (*settings)["allowSpecialFloats"] = false;
+//! [CharReaderBuilderDefaults]
+}
+
+//////////////////////////////////
+// global functions
+
+bool parseFromStream(
+ CharReader::Factory const& fact, std::istream& sin,
+ Value* root, std::string* errs)
+{
+ std::ostringstream ssin;
+ ssin << sin.rdbuf();
+ std::string doc = ssin.str();
+ char const* begin = doc.data();
+ char const* end = begin + doc.size();
+ // Note that we do not actually need a null-terminator.
+ CharReaderPtr const reader(fact.newCharReader());
+ return reader->parse(begin, end, root, errs);
+}
+
+std::istream& operator>>(std::istream& sin, Value& root) {
+ CharReaderBuilder b;
+ std::string errs;
+ bool ok = parseFromStream(b, sin, &root, &errs);
+ if (!ok) {
+ fprintf(stderr,
+ "Error from reader: %s",
+ errs.c_str());
+
+ throwRuntimeError(errs);
+ }
+ return sin;
+}
+
+} // namespace Json
+
+// //////////////////////////////////////////////////////////////////////
+// End of content of file: src/lib_json/json_reader.cpp
+// //////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+// //////////////////////////////////////////////////////////////////////
+// Beginning of content of file: src/lib_json/json_valueiterator.inl
+// //////////////////////////////////////////////////////////////////////
+
+// Copyright 2007-2010 Baptiste Lepilleur
+// Distributed under MIT license, or public domain if desired and
+// recognized in your jurisdiction.
+// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
+
+// included by json_value.cpp
+
+namespace Json {
+
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// class ValueIteratorBase
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+
+ValueIteratorBase::ValueIteratorBase()
+ : current_(), isNull_(true) {
+}
+
+ValueIteratorBase::ValueIteratorBase(
+ const Value::ObjectValues::iterator& current)
+ : current_(current), isNull_(false) {}
+
+Value& ValueIteratorBase::deref() const {
+ return current_->second;
+}
+
+void ValueIteratorBase::increment() {
+ ++current_;
+}
+
+void ValueIteratorBase::decrement() {
+ --current_;
+}
+
+ValueIteratorBase::difference_type
+ValueIteratorBase::computeDistance(const SelfType& other) const {
+#ifdef JSON_USE_CPPTL_SMALLMAP
+ return other.current_ - current_;
+#else
+ // Iterator for null value are initialized using the default
+ // constructor, which initialize current_ to the default
+ // std::map::iterator. As begin() and end() are two instance
+ // of the default std::map::iterator, they can not be compared.
+ // To allow this, we handle this comparison specifically.
+ if (isNull_ && other.isNull_) {
+ return 0;
+ }
+
+ // Usage of std::distance is not portable (does not compile with Sun Studio 12
+ // RogueWave STL,
+ // which is the one used by default).
+ // Using a portable hand-made version for non random iterator instead:
+ // return difference_type( std::distance( current_, other.current_ ) );
+ difference_type myDistance = 0;
+ for (Value::ObjectValues::iterator it = current_; it != other.current_;
+ ++it) {
+ ++myDistance;
+ }
+ return myDistance;
+#endif
+}
+
+bool ValueIteratorBase::isEqual(const SelfType& other) const {
+ if (isNull_) {
+ return other.isNull_;
+ }
+ return current_ == other.current_;
+}
+
+void ValueIteratorBase::copy(const SelfType& other) {
+ current_ = other.current_;
+ isNull_ = other.isNull_;
+}
+
+Value ValueIteratorBase::key() const {
+ const Value::CZString czstring = (*current_).first;
+ if (czstring.data()) {
+ if (czstring.isStaticString())
+ return Value(StaticString(czstring.data()));
+ return Value(czstring.data(), czstring.data() + czstring.length());
+ }
+ return Value(czstring.index());
+}
+
+UInt ValueIteratorBase::index() const {
+ const Value::CZString czstring = (*current_).first;
+ if (!czstring.data())
+ return czstring.index();
+ return Value::UInt(-1);
+}
+
+std::string ValueIteratorBase::name() const {
+ char const* keey;
+ char const* end;
+ keey = memberName(&end);
+ if (!keey) return std::string();
+ return std::string(keey, end);
+}
+
+char const* ValueIteratorBase::memberName() const {
+ const char* cname = (*current_).first.data();
+ return cname ? cname : "";
+}
+
+char const* ValueIteratorBase::memberName(char const** end) const {
+ const char* cname = (*current_).first.data();
+ if (!cname) {
+ *end = NULL;
+ return NULL;
+ }
+ *end = cname + (*current_).first.length();
+ return cname;
+}
+
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// class ValueConstIterator
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+
+ValueConstIterator::ValueConstIterator() {}
+
+ValueConstIterator::ValueConstIterator(
+ const Value::ObjectValues::iterator& current)
+ : ValueIteratorBase(current) {}
+
+ValueConstIterator::ValueConstIterator(ValueIterator const& other)
+ : ValueIteratorBase(other) {}
+
+ValueConstIterator& ValueConstIterator::
+operator=(const ValueIteratorBase& other) {
+ copy(other);
+ return *this;
+}
+
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// class ValueIterator
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+
+ValueIterator::ValueIterator() {}
+
+ValueIterator::ValueIterator(const Value::ObjectValues::iterator& current)
+ : ValueIteratorBase(current) {}
+
+ValueIterator::ValueIterator(const ValueConstIterator& other)
+ : ValueIteratorBase(other) {
+ throwRuntimeError("ConstIterator to Iterator should never be allowed.");
+}
+
+ValueIterator::ValueIterator(const ValueIterator& other)
+ : ValueIteratorBase(other) {}
+
+ValueIterator& ValueIterator::operator=(const SelfType& other) {
+ copy(other);
+ return *this;
+}
+
+} // namespace Json
+
+// //////////////////////////////////////////////////////////////////////
+// End of content of file: src/lib_json/json_valueiterator.inl
+// //////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+// //////////////////////////////////////////////////////////////////////
+// Beginning of content of file: src/lib_json/json_value.cpp
+// //////////////////////////////////////////////////////////////////////
+
+// Copyright 2011 Baptiste Lepilleur
+// Distributed under MIT license, or public domain if desired and
+// recognized in your jurisdiction.
+// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
+
+#if !defined(JSON_IS_AMALGAMATION)
+#include <json/assertions.h>
+#include <json/value.h>
+#include <json/writer.h>
+#endif // if !defined(JSON_IS_AMALGAMATION)
+#include <math.h>
+#include <sstream>
+#include <utility>
+#include <cstring>
+#include <cassert>
+#ifdef JSON_USE_CPPTL
+#include <cpptl/conststring.h>
+#endif
+#include <cstddef> // size_t
+#include <algorithm> // min()
+
+#define JSON_ASSERT_UNREACHABLE assert(false)
+
+namespace Json {
+
+// This is a walkaround to avoid the static initialization of Value::null.
+// kNull must be word-aligned to avoid crashing on ARM. We use an alignment of
+// 8 (instead of 4) as a bit of future-proofing.
+#if defined(__ARMEL__)
+#define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment)))
+#else
+#define ALIGNAS(byte_alignment)
+#endif
+static const unsigned char ALIGNAS(8) kNull[sizeof(Value)] = { 0 };
+const unsigned char& kNullRef = kNull[0];
+const Value& Value::null = reinterpret_cast<const Value&>(kNullRef);
+const Value& Value::nullRef = null;
+
+const Int Value::minInt = Int(~(UInt(-1) / 2));
+const Int Value::maxInt = Int(UInt(-1) / 2);
+const UInt Value::maxUInt = UInt(-1);
+#if defined(JSON_HAS_INT64)
+const Int64 Value::minInt64 = Int64(~(UInt64(-1) / 2));
+const Int64 Value::maxInt64 = Int64(UInt64(-1) / 2);
+const UInt64 Value::maxUInt64 = UInt64(-1);
+// The constant is hard-coded because some compiler have trouble
+// converting Value::maxUInt64 to a double correctly (AIX/xlC).
+// Assumes that UInt64 is a 64 bits integer.
+static const double maxUInt64AsDouble = 18446744073709551615.0;
+#endif // defined(JSON_HAS_INT64)
+const LargestInt Value::minLargestInt = LargestInt(~(LargestUInt(-1) / 2));
+const LargestInt Value::maxLargestInt = LargestInt(LargestUInt(-1) / 2);
+const LargestUInt Value::maxLargestUInt = LargestUInt(-1);
+
+#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
+template <typename T, typename U>
+static inline bool InRange(double d, T min, U max) {
+ return d >= min && d <= max;
+}
+#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
+static inline double integerToDouble(Json::UInt64 value) {
+ return static_cast<double>(Int64(value / 2)) * 2.0 + Int64(value & 1);
+}
+
+template <typename T> static inline double integerToDouble(T value) {
+ return static_cast<double>(value);
+}
+
+template <typename T, typename U>
+static inline bool InRange(double d, T min, U max) {
+ return d >= integerToDouble(min) && d <= integerToDouble(max);
+}
+#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
+
+/** Duplicates the specified string value.
+ * @param value Pointer to the string to duplicate. Must be zero-terminated if
+ * length is "unknown".
+ * @param length Length of the value. if equals to unknown, then it will be
+ * computed using strlen(value).
+ * @return Pointer on the duplicate instance of string.
+ */
+static inline char* duplicateStringValue(const char* value,
+ size_t length) {
+ // Avoid an integer overflow in the call to malloc below by limiting length
+ // to a sane value.
+ if (length >= (size_t)Value::maxInt)
+ length = Value::maxInt - 1;
+
+ char* newString = static_cast<char*>(malloc(length + 1));
+ if (newString == NULL) {
+ throwRuntimeError(
+ "in Json::Value::duplicateStringValue(): "
+ "Failed to allocate string value buffer");
+ }
+ memcpy(newString, value, length);
+ newString[length] = 0;
+ return newString;
+}
+
+/* Record the length as a prefix.
+ */
+static inline char* duplicateAndPrefixStringValue(
+ const char* value,
+ unsigned int length)
+{
+ // Avoid an integer overflow in the call to malloc below by limiting length
+ // to a sane value.
+ JSON_ASSERT_MESSAGE(length <= (unsigned)Value::maxInt - sizeof(unsigned) - 1U,
+ "in Json::Value::duplicateAndPrefixStringValue(): "
+ "length too big for prefixing");
+ unsigned actualLength = length + static_cast<unsigned>(sizeof(unsigned)) + 1U;
+ char* newString = static_cast<char*>(malloc(actualLength));
+ if (newString == 0) {
+ throwRuntimeError(
+ "in Json::Value::duplicateAndPrefixStringValue(): "
+ "Failed to allocate string value buffer");
+ }
+ *reinterpret_cast<unsigned*>(newString) = length;
+ memcpy(newString + sizeof(unsigned), value, length);
+ newString[actualLength - 1U] = 0; // to avoid buffer over-run accidents by users later
+ return newString;
+}
+inline static void decodePrefixedString(
+ bool isPrefixed, char const* prefixed,
+ unsigned* length, char const** value)
+{
+ if (!isPrefixed) {
+ *length = static_cast<unsigned>(strlen(prefixed));
+ *value = prefixed;
+ } else {
+ *length = *reinterpret_cast<unsigned const*>(prefixed);
+ *value = prefixed + sizeof(unsigned);
+ }
+}
+/** Free the string duplicated by duplicateStringValue()/duplicateAndPrefixStringValue().
+ */
+static inline void releaseStringValue(char* value) { free(value); }
+
+} // namespace Json
+
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// ValueInternals...
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+#if !defined(JSON_IS_AMALGAMATION)
+
+#include "json_valueiterator.inl"
+#endif // if !defined(JSON_IS_AMALGAMATION)
+
+namespace Json {
+
+Exception::Exception(std::string const& msg)
+ : msg_(msg)
+{}
+Exception::~Exception() throw()
+{}
+char const* Exception::what() const throw()
+{
+ return msg_.c_str();
+}
+RuntimeError::RuntimeError(std::string const& msg)
+ : Exception(msg)
+{}
+LogicError::LogicError(std::string const& msg)
+ : Exception(msg)
+{}
+void throwRuntimeError(std::string const& msg)
+{
+ throw RuntimeError(msg);
+}
+void throwLogicError(std::string const& msg)
+{
+ throw LogicError(msg);
+}
+
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// class Value::CommentInfo
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+
+Value::CommentInfo::CommentInfo() : comment_(0) {}
+
+Value::CommentInfo::~CommentInfo() {
+ if (comment_)
+ releaseStringValue(comment_);
+}
+
+void Value::CommentInfo::setComment(const char* text, size_t len) {
+ if (comment_) {
+ releaseStringValue(comment_);
+ comment_ = 0;
+ }
+ JSON_ASSERT(text != 0);
+ JSON_ASSERT_MESSAGE(
+ text[0] == '\0' || text[0] == '/',
+ "in Json::Value::setComment(): Comments must start with /");
+ // It seems that /**/ style comments are acceptable as well.
+ comment_ = duplicateStringValue(text, len);
+}
+
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// class Value::CZString
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+
+// Notes: policy_ indicates if the string was allocated when
+// a string is stored.
+
+Value::CZString::CZString(ArrayIndex aindex) : cstr_(0), index_(aindex) {}
+
+Value::CZString::CZString(char const* str, unsigned ulength, DuplicationPolicy allocate)
+ : cstr_(str) {
+ // allocate != duplicate
+ storage_.policy_ = allocate & 0x3;
+ storage_.length_ = ulength & 0x3FFFFFFF;
+}
+
+Value::CZString::CZString(const CZString& other)
+ : cstr_(other.storage_.policy_ != noDuplication && other.cstr_ != 0
+ ? duplicateStringValue(other.cstr_, other.storage_.length_)
+ : other.cstr_) {
+ storage_.policy_ = (other.cstr_
+ ? (static_cast<DuplicationPolicy>(other.storage_.policy_) == noDuplication
+ ? noDuplication : duplicate)
+ : static_cast<DuplicationPolicy>(other.storage_.policy_));
+ storage_.length_ = other.storage_.length_;
+}
+
+#if JSON_HAS_RVALUE_REFERENCES
+Value::CZString::CZString(CZString&& other)
+ : cstr_(other.cstr_), index_(other.index_) {
+ other.cstr_ = nullptr;
+}
+#endif
+
+Value::CZString::~CZString() {
+ if (cstr_ && storage_.policy_ == duplicate)
+ releaseStringValue(const_cast<char*>(cstr_));
+}
+
+void Value::CZString::swap(CZString& other) {
+ std::swap(cstr_, other.cstr_);
+ std::swap(index_, other.index_);
+}
+
+Value::CZString& Value::CZString::operator=(CZString other) {
+ swap(other);
+ return *this;
+}
+
+bool Value::CZString::operator<(const CZString& other) const {
+ if (!cstr_) return index_ < other.index_;
+ //return strcmp(cstr_, other.cstr_) < 0;
+ // Assume both are strings.
+ unsigned this_len = this->storage_.length_;
+ unsigned other_len = other.storage_.length_;
+ unsigned min_len = std::min(this_len, other_len);
+ int comp = memcmp(this->cstr_, other.cstr_, min_len);
+ if (comp < 0) return true;
+ if (comp > 0) return false;
+ return (this_len < other_len);
+}
+
+bool Value::CZString::operator==(const CZString& other) const {
+ if (!cstr_) return index_ == other.index_;
+ //return strcmp(cstr_, other.cstr_) == 0;
+ // Assume both are strings.
+ unsigned this_len = this->storage_.length_;
+ unsigned other_len = other.storage_.length_;
+ if (this_len != other_len) return false;
+ int comp = memcmp(this->cstr_, other.cstr_, this_len);
+ return comp == 0;
+}
+
+ArrayIndex Value::CZString::index() const { return index_; }
+
+//const char* Value::CZString::c_str() const { return cstr_; }
+const char* Value::CZString::data() const { return cstr_; }
+unsigned Value::CZString::length() const { return storage_.length_; }
+bool Value::CZString::isStaticString() const { return storage_.policy_ == noDuplication; }
+
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// class Value::Value
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+// //////////////////////////////////////////////////////////////////
+
+/*! \internal Default constructor initialization must be equivalent to:
+ * memset( this, 0, sizeof(Value) )
+ * This optimization is used in ValueInternalMap fast allocator.
+ */
+Value::Value(ValueType vtype) {
+ initBasic(vtype);
+ switch (vtype) {
+ case nullValue:
+ break;
+ case intValue:
+ case uintValue:
+ value_.int_ = 0;
+ break;
+ case realValue:
+ value_.real_ = 0.0;
+ break;
+ case stringValue:
+ value_.string_ = 0;
+ break;
+ case arrayValue:
+ case objectValue:
+ value_.map_ = new ObjectValues();
+ break;
+ case booleanValue:
+ value_.bool_ = false;
+ break;
+ default:
+ JSON_ASSERT_UNREACHABLE;
+ }
+}
+
+Value::Value(Int value) {
+ initBasic(intValue);
+ value_.int_ = value;
+}
+
+Value::Value(UInt value) {
+ initBasic(uintValue);
+ value_.uint_ = value;
+}
+#if defined(JSON_HAS_INT64)
+Value::Value(Int64 value) {
+ initBasic(intValue);
+ value_.int_ = value;
+}
+Value::Value(UInt64 value) {
+ initBasic(uintValue);
+ value_.uint_ = value;
+}
+#endif // defined(JSON_HAS_INT64)
+
+Value::Value(double value) {
+ initBasic(realValue);
+ value_.real_ = value;
+}
+
+Value::Value(const char* value) {
+ initBasic(stringValue, true);
+ value_.string_ = duplicateAndPrefixStringValue(value, static_cast<unsigned>(strlen(value)));
+}
+
+Value::Value(const char* beginValue, const char* endValue) {
+ initBasic(stringValue, true);
+ value_.string_ =
+ duplicateAndPrefixStringValue(beginValue, static_cast<unsigned>(endValue - beginValue));
+}
+
+Value::Value(const std::string& value) {
+ initBasic(stringValue, true);
+ value_.string_ =
+ duplicateAndPrefixStringValue(value.data(), static_cast<unsigned>(value.length()));
+}
+
+Value::Value(const StaticString& value) {
+ initBasic(stringValue);
+ value_.string_ = const_cast<char*>(value.c_str());
+}
+
+#ifdef JSON_USE_CPPTL
+Value::Value(const CppTL::ConstString& value) {
+ initBasic(stringValue, true);
+ value_.string_ = duplicateAndPrefixStringValue(value, static_cast<unsigned>(value.length()));
+}
+#endif
+
+Value::Value(bool value) {
+ initBasic(booleanValue);
+ value_.bool_ = value;
+}
+
+Value::Value(Value const& other)
+ : type_(other.type_), allocated_(false)
+ ,
+ comments_(0), start_(other.start_), limit_(other.limit_)
+{
+ switch (type_) {
+ case nullValue:
+ case intValue:
+ case uintValue:
+ case realValue:
+ case booleanValue:
+ value_ = other.value_;
+ break;
+ case stringValue:
+ if (other.value_.string_ && other.allocated_) {
+ unsigned len;
+ char const* str;
+ decodePrefixedString(other.allocated_, other.value_.string_,
+ &len, &str);
+ value_.string_ = duplicateAndPrefixStringValue(str, len);
+ allocated_ = true;
+ } else {
+ value_.string_ = other.value_.string_;
+ allocated_ = false;
+ }
+ break;
+ case arrayValue:
+ case objectValue:
+ value_.map_ = new ObjectValues(*other.value_.map_);
+ break;
+ default:
+ JSON_ASSERT_UNREACHABLE;
+ }
+ if (other.comments_) {
+ comments_ = new CommentInfo[numberOfCommentPlacement];
+ for (int comment = 0; comment < numberOfCommentPlacement; ++comment) {
+ const CommentInfo& otherComment = other.comments_[comment];
+ if (otherComment.comment_)
+ comments_[comment].setComment(
+ otherComment.comment_, strlen(otherComment.comment_));
+ }
+ }
+}
+
+#if JSON_HAS_RVALUE_REFERENCES
+// Move constructor
+Value::Value(Value&& other) {
+ initBasic(nullValue);
+ swap(other);
+}
+#endif
+
+Value::~Value() {
+ switch (type_) {
+ case nullValue:
+ case intValue:
+ case uintValue:
+ case realValue:
+ case booleanValue:
+ break;
+ case stringValue:
+ if (allocated_)
+ releaseStringValue(value_.string_);
+ break;
+ case arrayValue:
+ case objectValue:
+ delete value_.map_;
+ break;
+ default:
+ JSON_ASSERT_UNREACHABLE;
+ }
+
+ if (comments_)
+ delete[] comments_;
+}
+
+Value& Value::operator=(Value other) {
+ swap(other);
+ return *this;
+}
+
+void Value::swapPayload(Value& other) {
+ ValueType temp = type_;
+ type_ = other.type_;
+ other.type_ = temp;
+ std::swap(value_, other.value_);
+ int temp2 = allocated_;
+ allocated_ = other.allocated_;
+ other.allocated_ = temp2 & 0x1;
+}
+
+void Value::swap(Value& other) {
+ swapPayload(other);
+ std::swap(comments_, other.comments_);
+ std::swap(start_, other.start_);
+ std::swap(limit_, other.limit_);
+}
+
+ValueType Value::type() const { return type_; }
+
+int Value::compare(const Value& other) const {
+ if (*this < other)
+ return -1;
+ if (*this > other)
+ return 1;
+ return 0;
+}
+
+bool Value::operator<(const Value& other) const {
+ int typeDelta = type_ - other.type_;
+ if (typeDelta)
+ return typeDelta < 0 ? true : false;
+ switch (type_) {
+ case nullValue:
+ return false;
+ case intValue:
+ return value_.int_ < other.value_.int_;
+ case uintValue:
+ return value_.uint_ < other.value_.uint_;
+ case realValue:
+ return value_.real_ < other.value_.real_;
+ case booleanValue:
+ return value_.bool_ < other.value_.bool_;
+ case stringValue:
+ {
+ if ((value_.string_ == 0) || (other.value_.string_ == 0)) {
+ if (other.value_.string_) return true;
+ else return false;
+ }
+ unsigned this_len;
+ unsigned other_len;
+ char const* this_str;
+ char const* other_str;
+ decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str);
+ decodePrefixedString(other.allocated_, other.value_.string_, &other_len, &other_str);
+ unsigned min_len = std::min(this_len, other_len);
+ int comp = memcmp(this_str, other_str, min_len);
+ if (comp < 0) return true;
+ if (comp > 0) return false;
+ return (this_len < other_len);
+ }
+ case arrayValue:
+ case objectValue: {
+ int delta = int(value_.map_->size() - other.value_.map_->size());
+ if (delta)
+ return delta < 0;
+ return (*value_.map_) < (*other.value_.map_);
+ }
+ default:
+ JSON_ASSERT_UNREACHABLE;
+ }
+ return false; // unreachable
+}
+
+bool Value::operator<=(const Value& other) const { return !(other < *this); }
+
+bool Value::operator>=(const Value& other) const { return !(*this < other); }
+
+bool Value::operator>(const Value& other) const { return other < *this; }
+
+bool Value::operator==(const Value& other) const {
+ // if ( type_ != other.type_ )
+ // GCC 2.95.3 says:
+ // attempt to take address of bit-field structure member `Json::Value::type_'
+ // Beats me, but a temp solves the problem.
+ int temp = other.type_;
+ if (type_ != temp)
+ return false;
+ switch (type_) {
+ case nullValue:
+ return true;
+ case intValue:
+ return value_.int_ == other.value_.int_;
+ case uintValue:
+ return value_.uint_ == other.value_.uint_;
+ case realValue:
+ return value_.real_ == other.value_.real_;
+ case booleanValue:
+ return value_.bool_ == other.value_.bool_;
+ case stringValue:
+ {
+ if ((value_.string_ == 0) || (other.value_.string_ == 0)) {
+ return (value_.string_ == other.value_.string_);
+ }
+ unsigned this_len;
+ unsigned other_len;
+ char const* this_str;
+ char const* other_str;
+ decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str);
+ decodePrefixedString(other.allocated_, other.value_.string_, &other_len, &other_str);
+ if (this_len != other_len) return false;
+ int comp = memcmp(this_str, other_str, this_len);
+ return comp == 0;
+ }
+ case arrayValue:
+ case objectValue:
+ return value_.map_->size() == other.value_.map_->size() &&
+ (*value_.map_) == (*other.value_.map_);
+ default:
+ JSON_ASSERT_UNREACHABLE;
+ }
+ return false; // unreachable
+}
+
+bool Value::operator!=(const Value& other) const { return !(*this == other); }
+
+const char* Value::asCString() const {
+ JSON_ASSERT_MESSAGE(type_ == stringValue,
+ "in Json::Value::asCString(): requires stringValue");
+ if (value_.string_ == 0) return 0;
+ unsigned this_len;
+ char const* this_str;
+ decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str);
+ return this_str;
+}
+
+bool Value::getString(char const** str, char const** cend) const {
+ if (type_ != stringValue) return false;
+ if (value_.string_ == 0) return false;
+ unsigned length;
+ decodePrefixedString(this->allocated_, this->value_.string_, &length, str);
+ *cend = *str + length;
+ return true;
+}
+
+std::string Value::asString() const {
+ switch (type_) {
+ case nullValue:
+ return "";
+ case stringValue:
+ {
+ if (value_.string_ == 0) return "";
+ unsigned this_len;
+ char const* this_str;
+ decodePrefixedString(this->allocated_, this->value_.string_, &this_len, &this_str);
+ return std::string(this_str, this_len);
+ }
+ case booleanValue:
+ return value_.bool_ ? "true" : "false";
+ case intValue:
+ return valueToString(value_.int_);
+ case uintValue:
+ return valueToString(value_.uint_);
+ case realValue:
+ return valueToString(value_.real_);
+ default:
+ JSON_FAIL_MESSAGE("Type is not convertible to string");
+ }
+}
+
+#ifdef JSON_USE_CPPTL
+CppTL::ConstString Value::asConstString() const {
+ unsigned len;
+ char const* str;
+ decodePrefixedString(allocated_, value_.string_,
+ &len, &str);
+ return CppTL::ConstString(str, len);
+}
+#endif
+
+Value::Int Value::asInt() const {
+ switch (type_) {
+ case intValue:
+ JSON_ASSERT_MESSAGE(isInt(), "LargestInt out of Int range");
+ return Int(value_.int_);
+ case uintValue:
+ JSON_ASSERT_MESSAGE(isInt(), "LargestUInt out of Int range");
+ return Int(value_.uint_);
+ case realValue:
+ JSON_ASSERT_MESSAGE(InRange(value_.real_, minInt, maxInt),
+ "double out of Int range");
+ return Int(value_.real_);
+ case nullValue:
+ return 0;
+ case booleanValue:
+ return value_.bool_ ? 1 : 0;
+ default:
+ break;
+ }
+ JSON_FAIL_MESSAGE("Value is not convertible to Int.");
+}
+
+Value::UInt Value::asUInt() const {
+ switch (type_) {
+ case intValue:
+ JSON_ASSERT_MESSAGE(isUInt(), "LargestInt out of UInt range");
+ return UInt(value_.int_);
+ case uintValue:
+ JSON_ASSERT_MESSAGE(isUInt(), "LargestUInt out of UInt range");
+ return UInt(value_.uint_);
+ case realValue:
+ JSON_ASSERT_MESSAGE(InRange(value_.real_, 0, maxUInt),
+ "double out of UInt range");
+ return UInt(value_.real_);
+ case nullValue:
+ return 0;
+ case booleanValue:
+ return value_.bool_ ? 1 : 0;
+ default:
+ break;
+ }
+ JSON_FAIL_MESSAGE("Value is not convertible to UInt.");
+}
+
+#if defined(JSON_HAS_INT64)
+
+Value::Int64 Value::asInt64() const {
+ switch (type_) {
+ case intValue:
+ return Int64(value_.int_);
+ case uintValue:
+ JSON_ASSERT_MESSAGE(isInt64(), "LargestUInt out of Int64 range");
+ return Int64(value_.uint_);
+ case realValue:
+ JSON_ASSERT_MESSAGE(InRange(value_.real_, minInt64, maxInt64),
+ "double out of Int64 range");
+ return Int64(value_.real_);
+ case nullValue:
+ return 0;
+ case booleanValue:
+ return value_.bool_ ? 1 : 0;
+ default:
+ break;
+ }
+ JSON_FAIL_MESSAGE("Value is not convertible to Int64.");
+}
+
+Value::UInt64 Value::asUInt64() const {
+ switch (type_) {
+ case intValue:
+ JSON_ASSERT_MESSAGE(isUInt64(), "LargestInt out of UInt64 range");
+ return UInt64(value_.int_);
+ case uintValue:
+ return UInt64(value_.uint_);
+ case realValue:
+ JSON_ASSERT_MESSAGE(InRange(value_.real_, 0, maxUInt64),
+ "double out of UInt64 range");
+ return UInt64(value_.real_);
+ case nullValue:
+ return 0;
+ case booleanValue:
+ return value_.bool_ ? 1 : 0;
+ default:
+ break;
+ }
+ JSON_FAIL_MESSAGE("Value is not convertible to UInt64.");
+}
+#endif // if defined(JSON_HAS_INT64)
+
+LargestInt Value::asLargestInt() const {
+#if defined(JSON_NO_INT64)
+ return asInt();
+#else
+ return asInt64();
+#endif
+}
+
+LargestUInt Value::asLargestUInt() const {
+#if defined(JSON_NO_INT64)
+ return asUInt();
+#else
+ return asUInt64();
+#endif
+}
+
+double Value::asDouble() const {
+ switch (type_) {
+ case intValue:
+ return static_cast<double>(value_.int_);
+ case uintValue:
+#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
+ return static_cast<double>(value_.uint_);
+#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
+ return integerToDouble(value_.uint_);
+#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
+ case realValue:
+ return value_.real_;
+ case nullValue:
+ return 0.0;
+ case booleanValue:
+ return value_.bool_ ? 1.0 : 0.0;
+ default:
+ break;
+ }
+ JSON_FAIL_MESSAGE("Value is not convertible to double.");
+}
+
+float Value::asFloat() const {
+ switch (type_) {
+ case intValue:
+ return static_cast<float>(value_.int_);
+ case uintValue:
+#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
+ return static_cast<float>(value_.uint_);
+#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
+ return integerToDouble(value_.uint_);
+#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
+ case realValue:
+ return static_cast<float>(value_.real_);
+ case nullValue:
+ return 0.0;
+ case booleanValue:
+ return value_.bool_ ? 1.0f : 0.0f;
+ default:
+ break;
+ }
+ JSON_FAIL_MESSAGE("Value is not convertible to float.");
+}
+
+bool Value::asBool() const {
+ switch (type_) {
+ case booleanValue:
+ return value_.bool_;
+ case nullValue:
+ return false;
+ case intValue:
+ return value_.int_ ? true : false;
+ case uintValue:
+ return value_.uint_ ? true : false;
+ case realValue:
+ // This is kind of strange. Not recommended.
+ return (value_.real_ != 0.0) ? true : false;
+ default:
+ break;
+ }
+ JSON_FAIL_MESSAGE("Value is not convertible to bool.");
+}
+
+bool Value::isConvertibleTo(ValueType other) const {
+ switch (other) {
+ case nullValue:
+ return (isNumeric() && asDouble() == 0.0) ||
+ (type_ == booleanValue && value_.bool_ == false) ||
+ (type_ == stringValue && asString() == "") ||
+ (type_ == arrayValue && value_.map_->size() == 0) ||
+ (type_ == objectValue && value_.map_->size() == 0) ||
+ type_ == nullValue;
+ case intValue:
+ return isInt() ||
+ (type_ == realValue && InRange(value_.real_, minInt, maxInt)) ||
+ type_ == booleanValue || type_ == nullValue;
+ case uintValue:
+ return isUInt() ||
+ (type_ == realValue && InRange(value_.real_, 0, maxUInt)) ||
+ type_ == booleanValue || type_ == nullValue;
+ case realValue:
+ return isNumeric() || type_ == booleanValue || type_ == nullValue;
+ case booleanValue:
+ return isNumeric() || type_ == booleanValue || type_ == nullValue;
+ case stringValue:
+ return isNumeric() || type_ == booleanValue || type_ == stringValue ||
+ type_ == nullValue;
+ case arrayValue:
+ return type_ == arrayValue || type_ == nullValue;
+ case objectValue:
+ return type_ == objectValue || type_ == nullValue;
+ }
+ JSON_ASSERT_UNREACHABLE;
+ return false;
+}
+
+/// Number of values in array or object
+ArrayIndex Value::size() const {
+ switch (type_) {
+ case nullValue:
+ case intValue:
+ case uintValue:
+ case realValue:
+ case booleanValue:
+ case stringValue:
+ return 0;
+ case arrayValue: // size of the array is highest index + 1
+ if (!value_.map_->empty()) {
+ ObjectValues::const_iterator itLast = value_.map_->end();
+ --itLast;
+ return (*itLast).first.index() + 1;
+ }
+ return 0;
+ case objectValue:
+ return ArrayIndex(value_.map_->size());
+ }
+ JSON_ASSERT_UNREACHABLE;
+ return 0; // unreachable;
+}
+
+bool Value::empty() const {
+ if (isNull() || isArray() || isObject())
+ return size() == 0u;
+ else
+ return false;
+}
+
+bool Value::operator!() const { return isNull(); }
+
+void Value::clear() {
+ JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == arrayValue ||
+ type_ == objectValue,
+ "in Json::Value::clear(): requires complex value");
+ start_ = 0;
+ limit_ = 0;
+ switch (type_) {
+ case arrayValue:
+ case objectValue:
+ value_.map_->clear();
+ break;
+ default:
+ break;
+ }
+}
+
+void Value::resize(ArrayIndex newSize) {
+ JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == arrayValue,
+ "in Json::Value::resize(): requires arrayValue");
+ if (type_ == nullValue)
+ *this = Value(arrayValue);
+ ArrayIndex oldSize = size();
+ if (newSize == 0)
+ clear();
+ else if (newSize > oldSize)
+ (*this)[newSize - 1];
+ else {
+ for (ArrayIndex index = newSize; index < oldSize; ++index) {
+ value_.map_->erase(index);
+ }
+ assert(size() == newSize);
+ }
+}
+
+Value& Value::operator[](ArrayIndex index) {
+ JSON_ASSERT_MESSAGE(
+ type_ == nullValue || type_ == arrayValue,
+ "in Json::Value::operator[](ArrayIndex): requires arrayValue");
+ if (type_ == nullValue)
+ *this = Value(arrayValue);
+ CZString key(index);
+ ObjectValues::iterator it = value_.map_->lower_bound(key);
+ if (it != value_.map_->end() && (*it).first == key)
+ return (*it).second;
+
+ ObjectValues::value_type defaultValue(key, nullRef);
+ it = value_.map_->insert(it, defaultValue);
+ return (*it).second;
+}
+
+Value& Value::operator[](int index) {
+ JSON_ASSERT_MESSAGE(
+ index >= 0,
+ "in Json::Value::operator[](int index): index cannot be negative");
+ return (*this)[ArrayIndex(index)];
+}
+
+const Value& Value::operator[](ArrayIndex index) const {
+ JSON_ASSERT_MESSAGE(
+ type_ == nullValue || type_ == arrayValue,
+ "in Json::Value::operator[](ArrayIndex)const: requires arrayValue");
+ if (type_ == nullValue)
+ return nullRef;
+ CZString key(index);
+ ObjectValues::const_iterator it = value_.map_->find(key);
+ if (it == value_.map_->end())
+ return nullRef;
+ return (*it).second;
+}
+
+const Value& Value::operator[](int index) const {
+ JSON_ASSERT_MESSAGE(
+ index >= 0,
+ "in Json::Value::operator[](int index) const: index cannot be negative");
+ return (*this)[ArrayIndex(index)];
+}
+
+void Value::initBasic(ValueType vtype, bool allocated) {
+ type_ = vtype;
+ allocated_ = allocated;
+ comments_ = 0;
+ start_ = 0;
+ limit_ = 0;
+}
+
+// Access an object value by name, create a null member if it does not exist.
+// @pre Type of '*this' is object or null.
+// @param key is null-terminated.
+Value& Value::resolveReference(const char* key) {
+ JSON_ASSERT_MESSAGE(
+ type_ == nullValue || type_ == objectValue,
+ "in Json::Value::resolveReference(): requires objectValue");
+ if (type_ == nullValue)
+ *this = Value(objectValue);
+ CZString actualKey(
+ key, static_cast<unsigned>(strlen(key)), CZString::noDuplication); // NOTE!
+ ObjectValues::iterator it = value_.map_->lower_bound(actualKey);
+ if (it != value_.map_->end() && (*it).first == actualKey)
+ return (*it).second;
+
+ ObjectValues::value_type defaultValue(actualKey, nullRef);
+ it = value_.map_->insert(it, defaultValue);
+ Value& value = (*it).second;
+ return value;
+}
+
+// @param key is not null-terminated.
+Value& Value::resolveReference(char const* key, char const* cend)
+{
+ JSON_ASSERT_MESSAGE(
+ type_ == nullValue || type_ == objectValue,
+ "in Json::Value::resolveReference(key, end): requires objectValue");
+ if (type_ == nullValue)
+ *this = Value(objectValue);
+ CZString actualKey(
+ key, static_cast<unsigned>(cend-key), CZString::duplicateOnCopy);
+ ObjectValues::iterator it = value_.map_->lower_bound(actualKey);
+ if (it != value_.map_->end() && (*it).first == actualKey)
+ return (*it).second;
+
+ ObjectValues::value_type defaultValue(actualKey, nullRef);
+ it = value_.map_->insert(it, defaultValue);
+ Value& value = (*it).second;
+ return value;
+}
+
+Value Value::get(ArrayIndex index, const Value& defaultValue) const {
+ const Value* value = &((*this)[index]);
+ return value == &nullRef ? defaultValue : *value;
+}
+
+bool Value::isValidIndex(ArrayIndex index) const { return index < size(); }
+
+Value const* Value::find(char const* key, char const* cend) const
+{
+ JSON_ASSERT_MESSAGE(
+ type_ == nullValue || type_ == objectValue,
+ "in Json::Value::find(key, end, found): requires objectValue or nullValue");
+ if (type_ == nullValue) return NULL;
+ CZString actualKey(key, static_cast<unsigned>(cend-key), CZString::noDuplication);
+ ObjectValues::const_iterator it = value_.map_->find(actualKey);
+ if (it == value_.map_->end()) return NULL;
+ return &(*it).second;
+}
+const Value& Value::operator[](const char* key) const
+{
+ Value const* found = find(key, key + strlen(key));
+ if (!found) return nullRef;
+ return *found;
+}
+Value const& Value::operator[](std::string const& key) const
+{
+ Value const* found = find(key.data(), key.data() + key.length());
+ if (!found) return nullRef;
+ return *found;
+}
+
+Value& Value::operator[](const char* key) {
+ return resolveReference(key, key + strlen(key));
+}
+
+Value& Value::operator[](const std::string& key) {
+ return resolveReference(key.data(), key.data() + key.length());
+}
+
+Value& Value::operator[](const StaticString& key) {
+ return resolveReference(key.c_str());
+}
+
+#ifdef JSON_USE_CPPTL
+Value& Value::operator[](const CppTL::ConstString& key) {
+ return resolveReference(key.c_str(), key.end_c_str());
+}
+Value const& Value::operator[](CppTL::ConstString const& key) const
+{
+ Value const* found = find(key.c_str(), key.end_c_str());
+ if (!found) return nullRef;
+ return *found;
+}
+#endif
+
+Value& Value::append(const Value& value) { return (*this)[size()] = value; }
+
+Value Value::get(char const* key, char const* cend, Value const& defaultValue) const
+{
+ Value const* found = find(key, cend);
+ return !found ? defaultValue : *found;
+}
+Value Value::get(char const* key, Value const& defaultValue) const
+{
+ return get(key, key + strlen(key), defaultValue);
+}
+Value Value::get(std::string const& key, Value const& defaultValue) const
+{
+ return get(key.data(), key.data() + key.length(), defaultValue);
+}
+
+
+bool Value::removeMember(const char* key, const char* cend, Value* removed)
+{
+ if (type_ != objectValue) {
+ return false;
+ }
+ CZString actualKey(key, static_cast<unsigned>(cend-key), CZString::noDuplication);
+ ObjectValues::iterator it = value_.map_->find(actualKey);
+ if (it == value_.map_->end())
+ return false;
+ *removed = it->second;
+ value_.map_->erase(it);
+ return true;
+}
+bool Value::removeMember(const char* key, Value* removed)
+{
+ return removeMember(key, key + strlen(key), removed);
+}
+bool Value::removeMember(std::string const& key, Value* removed)
+{
+ return removeMember(key.data(), key.data() + key.length(), removed);
+}
+Value Value::removeMember(const char* key)
+{
+ JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == objectValue,
+ "in Json::Value::removeMember(): requires objectValue");
+ if (type_ == nullValue)
+ return nullRef;
+
+ Value removed; // null
+ removeMember(key, key + strlen(key), &removed);
+ return removed; // still null if removeMember() did nothing
+}
+Value Value::removeMember(const std::string& key)
+{
+ return removeMember(key.c_str());
+}
+
+bool Value::removeIndex(ArrayIndex index, Value* removed) {
+ if (type_ != arrayValue) {
+ return false;
+ }
+ CZString key(index);
+ ObjectValues::iterator it = value_.map_->find(key);
+ if (it == value_.map_->end()) {
+ return false;
+ }
+ *removed = it->second;
+ ArrayIndex oldSize = size();
+ // shift left all items left, into the place of the "removed"
+ for (ArrayIndex i = index; i < (oldSize - 1); ++i){
+ CZString keey(i);
+ (*value_.map_)[keey] = (*this)[i + 1];
+ }
+ // erase the last one ("leftover")
+ CZString keyLast(oldSize - 1);
+ ObjectValues::iterator itLast = value_.map_->find(keyLast);
+ value_.map_->erase(itLast);
+ return true;
+}
+
+#ifdef JSON_USE_CPPTL
+Value Value::get(const CppTL::ConstString& key,
+ const Value& defaultValue) const {
+ return get(key.c_str(), key.end_c_str(), defaultValue);
+}
+#endif
+
+bool Value::isMember(char const* key, char const* cend) const
+{
+ Value const* value = find(key, cend);
+ return NULL != value;
+}
+bool Value::isMember(char const* key) const
+{
+ return isMember(key, key + strlen(key));
+}
+bool Value::isMember(std::string const& key) const
+{
+ return isMember(key.data(), key.data() + key.length());
+}
+
+#ifdef JSON_USE_CPPTL
+bool Value::isMember(const CppTL::ConstString& key) const {
+ return isMember(key.c_str(), key.end_c_str());
+}
+#endif
+
+Value::Members Value::getMemberNames() const {
+ JSON_ASSERT_MESSAGE(
+ type_ == nullValue || type_ == objectValue,
+ "in Json::Value::getMemberNames(), value must be objectValue");
+ if (type_ == nullValue)
+ return Value::Members();
+ Members members;
+ members.reserve(value_.map_->size());
+ ObjectValues::const_iterator it = value_.map_->begin();
+ ObjectValues::const_iterator itEnd = value_.map_->end();
+ for (; it != itEnd; ++it) {
+ members.push_back(std::string((*it).first.data(),
+ (*it).first.length()));
+ }
+ return members;
+}
+//
+//# ifdef JSON_USE_CPPTL
+// EnumMemberNames
+// Value::enumMemberNames() const
+//{
+// if ( type_ == objectValue )
+// {
+// return CppTL::Enum::any( CppTL::Enum::transform(
+// CppTL::Enum::keys( *(value_.map_), CppTL::Type<const CZString &>() ),
+// MemberNamesTransform() ) );
+// }
+// return EnumMemberNames();
+//}
+//
+//
+// EnumValues
+// Value::enumValues() const
+//{
+// if ( type_ == objectValue || type_ == arrayValue )
+// return CppTL::Enum::anyValues( *(value_.map_),
+// CppTL::Type<const Value &>() );
+// return EnumValues();
+//}
+//
+//# endif
+
+static bool IsIntegral(double d) {
+ double integral_part;
+ return modf(d, &integral_part) == 0.0;
+}
+
+bool Value::isNull() const { return type_ == nullValue; }
+
+bool Value::isBool() const { return type_ == booleanValue; }
+
+bool Value::isInt() const {
+ switch (type_) {
+ case intValue:
+ return value_.int_ >= minInt && value_.int_ <= maxInt;
+ case uintValue:
+ return value_.uint_ <= UInt(maxInt);
+ case realValue:
+ return value_.real_ >= minInt && value_.real_ <= maxInt &&
+ IsIntegral(value_.real_);
+ default:
+ break;
+ }
+ return false;
+}
+
+bool Value::isUInt() const {
+ switch (type_) {
+ case intValue:
+ return value_.int_ >= 0 && LargestUInt(value_.int_) <= LargestUInt(maxUInt);
+ case uintValue:
+ return value_.uint_ <= maxUInt;
+ case realValue:
+ return value_.real_ >= 0 && value_.real_ <= maxUInt &&
+ IsIntegral(value_.real_);
+ default:
+ break;
+ }
+ return false;
+}
+
+bool Value::isInt64() const {
+#if defined(JSON_HAS_INT64)
+ switch (type_) {
+ case intValue:
+ return true;
+ case uintValue:
+ return value_.uint_ <= UInt64(maxInt64);
+ case realValue:
+ // Note that maxInt64 (= 2^63 - 1) is not exactly representable as a
+ // double, so double(maxInt64) will be rounded up to 2^63. Therefore we
+ // require the value to be strictly less than the limit.
+ return value_.real_ >= double(minInt64) &&
+ value_.real_ < double(maxInt64) && IsIntegral(value_.real_);
+ default:
+ break;
+ }
+#endif // JSON_HAS_INT64
+ return false;
+}
+
+bool Value::isUInt64() const {
+#if defined(JSON_HAS_INT64)
+ switch (type_) {
+ case intValue:
+ return value_.int_ >= 0;
+ case uintValue:
+ return true;
+ case realValue:
+ // Note that maxUInt64 (= 2^64 - 1) is not exactly representable as a
+ // double, so double(maxUInt64) will be rounded up to 2^64. Therefore we
+ // require the value to be strictly less than the limit.
+ return value_.real_ >= 0 && value_.real_ < maxUInt64AsDouble &&
+ IsIntegral(value_.real_);
+ default:
+ break;
+ }
+#endif // JSON_HAS_INT64
+ return false;
+}
+
+bool Value::isIntegral() const {
+#if defined(JSON_HAS_INT64)
+ return isInt64() || isUInt64();
+#else
+ return isInt() || isUInt();
+#endif
+}
+
+bool Value::isDouble() const { return type_ == realValue || isIntegral(); }
+
+bool Value::isNumeric() const { return isIntegral() || isDouble(); }
+
+bool Value::isString() const { return type_ == stringValue; }
+
+bool Value::isArray() const { return type_ == arrayValue; }
+
+bool Value::isObject() const { return type_ == objectValue; }
+
+void Value::setComment(const char* comment, size_t len, CommentPlacement placement) {
+ if (!comments_)
+ comments_ = new CommentInfo[numberOfCommentPlacement];
+ if ((len > 0) && (comment[len-1] == '\n')) {
+ // Always discard trailing newline, to aid indentation.
+ len -= 1;
+ }
+ comments_[placement].setComment(comment, len);
+}
+
+void Value::setComment(const char* comment, CommentPlacement placement) {
+ setComment(comment, strlen(comment), placement);
+}
+
+void Value::setComment(const std::string& comment, CommentPlacement placement) {
+ setComment(comment.c_str(), comment.length(), placement);
+}
+
+bool Value::hasComment(CommentPlacement placement) const {
+ return comments_ != 0 && comments_[placement].comment_ != 0;
+}
+
+std::string Value::getComment(CommentPlacement placement) const {
+ if (hasComment(placement))
+ return comments_[placement].comment_;
+ return "";
+}
+
+void Value::setOffsetStart(size_t start) { start_ = start; }
+
+void Value::setOffsetLimit(size_t limit) { limit_ = limit; }
+
+size_t Value::getOffsetStart() const { return start_; }
+
+size_t Value::getOffsetLimit() const { return limit_; }
+
+std::string Value::toStyledString() const {
+ StyledWriter writer;
+ return writer.write(*this);
+}
+
+Value::const_iterator Value::begin() const {
+ switch (type_) {
+ case arrayValue:
+ case objectValue:
+ if (value_.map_)
+ return const_iterator(value_.map_->begin());
+ break;
+ default:
+ break;
+ }
+ return const_iterator();
+}
+
+Value::const_iterator Value::end() const {
+ switch (type_) {
+ case arrayValue:
+ case objectValue:
+ if (value_.map_)
+ return const_iterator(value_.map_->end());
+ break;
+ default:
+ break;
+ }
+ return const_iterator();
+}
+
+Value::iterator Value::begin() {
+ switch (type_) {
+ case arrayValue:
+ case objectValue:
+ if (value_.map_)
+ return iterator(value_.map_->begin());
+ break;
+ default:
+ break;
+ }
+ return iterator();
+}
+
+Value::iterator Value::end() {
+ switch (type_) {
+ case arrayValue:
+ case objectValue:
+ if (value_.map_)
+ return iterator(value_.map_->end());
+ break;
+ default:
+ break;
+ }
+ return iterator();
+}
+
+// class PathArgument
+// //////////////////////////////////////////////////////////////////
+
+PathArgument::PathArgument() : key_(), index_(), kind_(kindNone) {}
+
+PathArgument::PathArgument(ArrayIndex index)
+ : key_(), index_(index), kind_(kindIndex) {}
+
+PathArgument::PathArgument(const char* key)
+ : key_(key), index_(), kind_(kindKey) {}
+
+PathArgument::PathArgument(const std::string& key)
+ : key_(key.c_str()), index_(), kind_(kindKey) {}
+
+// class Path
+// //////////////////////////////////////////////////////////////////
+
+Path::Path(const std::string& path,
+ const PathArgument& a1,
+ const PathArgument& a2,
+ const PathArgument& a3,
+ const PathArgument& a4,
+ const PathArgument& a5) {
+ InArgs in;
+ in.push_back(&a1);
+ in.push_back(&a2);
+ in.push_back(&a3);
+ in.push_back(&a4);
+ in.push_back(&a5);
+ makePath(path, in);
+}
+
+void Path::makePath(const std::string& path, const InArgs& in) {
+ const char* current = path.c_str();
+ const char* end = current + path.length();
+ InArgs::const_iterator itInArg = in.begin();
+ while (current != end) {
+ if (*current == '[') {
+ ++current;
+ if (*current == '%')
+ addPathInArg(path, in, itInArg, PathArgument::kindIndex);
+ else {
+ ArrayIndex index = 0;
+ for (; current != end && *current >= '0' && *current <= '9'; ++current)
+ index = index * 10 + ArrayIndex(*current - '0');
+ args_.push_back(index);
+ }
+ if (current == end || *current++ != ']')
+ invalidPath(path, int(current - path.c_str()));
+ } else if (*current == '%') {
+ addPathInArg(path, in, itInArg, PathArgument::kindKey);
+ ++current;
+ } else if (*current == '.') {
+ ++current;
+ } else {
+ const char* beginName = current;
+ while (current != end && !strchr("[.", *current))
+ ++current;
+ args_.push_back(std::string(beginName, current));
+ }
+ }
+}
+
+void Path::addPathInArg(const std::string& /*path*/,
+ const InArgs& in,
+ InArgs::const_iterator& itInArg,
+ PathArgument::Kind kind) {
+ if (itInArg == in.end()) {
+ // Error: missing argument %d
+ } else if ((*itInArg)->kind_ != kind) {
+ // Error: bad argument type
+ } else {
+ args_.push_back(**itInArg);
+ }
+}
+
+void Path::invalidPath(const std::string& /*path*/, int /*location*/) {
+ // Error: invalid path.
+}
+
+const Value& Path::resolve(const Value& root) const {
+ const Value* node = &root;
+ for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
+ const PathArgument& arg = *it;
+ if (arg.kind_ == PathArgument::kindIndex) {
+ if (!node->isArray() || !node->isValidIndex(arg.index_)) {
+ // Error: unable to resolve path (array value expected at position...
+ }
+ node = &((*node)[arg.index_]);
+ } else if (arg.kind_ == PathArgument::kindKey) {
+ if (!node->isObject()) {
+ // Error: unable to resolve path (object value expected at position...)
+ }
+ node = &((*node)[arg.key_]);
+ if (node == &Value::nullRef) {
+ // Error: unable to resolve path (object has no member named '' at
+ // position...)
+ }
+ }
+ }
+ return *node;
+}
+
+Value Path::resolve(const Value& root, const Value& defaultValue) const {
+ const Value* node = &root;
+ for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
+ const PathArgument& arg = *it;
+ if (arg.kind_ == PathArgument::kindIndex) {
+ if (!node->isArray() || !node->isValidIndex(arg.index_))
+ return defaultValue;
+ node = &((*node)[arg.index_]);
+ } else if (arg.kind_ == PathArgument::kindKey) {
+ if (!node->isObject())
+ return defaultValue;
+ node = &((*node)[arg.key_]);
+ if (node == &Value::nullRef)
+ return defaultValue;
+ }
+ }
+ return *node;
+}
+
+Value& Path::make(Value& root) const {
+ Value* node = &root;
+ for (Args::const_iterator it = args_.begin(); it != args_.end(); ++it) {
+ const PathArgument& arg = *it;
+ if (arg.kind_ == PathArgument::kindIndex) {
+ if (!node->isArray()) {
+ // Error: node is not an array at position ...
+ }
+ node = &((*node)[arg.index_]);
+ } else if (arg.kind_ == PathArgument::kindKey) {
+ if (!node->isObject()) {
+ // Error: node is not an object at position...
+ }
+ node = &((*node)[arg.key_]);
+ }
+ }
+ return *node;
+}
+
+} // namespace Json
+
+// //////////////////////////////////////////////////////////////////////
+// End of content of file: src/lib_json/json_value.cpp
+// //////////////////////////////////////////////////////////////////////
+
+
+
+
+
+
+// //////////////////////////////////////////////////////////////////////
+// Beginning of content of file: src/lib_json/json_writer.cpp
+// //////////////////////////////////////////////////////////////////////
+
+// Copyright 2011 Baptiste Lepilleur
+// Distributed under MIT license, or public domain if desired and
+// recognized in your jurisdiction.
+// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
+
+#if !defined(JSON_IS_AMALGAMATION)
+#include <json/writer.h>
+#include "json_tool.h"
+#endif // if !defined(JSON_IS_AMALGAMATION)
+#include <iomanip>
+#include <memory>
+#include <sstream>
+#include <utility>
+#include <set>
+#include <cassert>
+#include <cstring>
+#include <cstdio>
+
+#if defined(_MSC_VER) && _MSC_VER >= 1200 && _MSC_VER < 1800 // Between VC++ 6.0 and VC++ 11.0
+#include <float.h>
+#define isfinite _finite
+#elif defined(__sun) && defined(__SVR4) //Solaris
+#if !defined(isfinite)
+#include <ieeefp.h>
+#define isfinite finite
+#endif
+#elif defined(_AIX)
+#if !defined(isfinite)
+#include <math.h>
+#define isfinite finite
+#endif
+#elif defined(__hpux)
+#if !defined(isfinite)
+#if defined(__ia64) && !defined(finite)
+#define isfinite(x) ((sizeof(x) == sizeof(float) ? \
+ _Isfinitef(x) : _IsFinite(x)))
+#else
+#include <math.h>
+#define isfinite finite
+#endif
+#endif
+#else
+#include <cmath>
+#if !(defined(__QNXNTO__)) // QNX already defines isfinite
+#define isfinite std::isfinite
+#endif
+#endif
+
+#if defined(_MSC_VER)
+#if !defined(WINCE) && defined(__STDC_SECURE_LIB__) && _MSC_VER >= 1500 // VC++ 9.0 and above
+#define snprintf sprintf_s
+#elif _MSC_VER >= 1900 // VC++ 14.0 and above
+#define snprintf std::snprintf
+#else
+#define snprintf _snprintf
+#endif
+#elif defined(__ANDROID__) || defined(__QNXNTO__)
+#define snprintf snprintf
+#elif __cplusplus >= 201103L
+#define snprintf std::snprintf
+#endif
+
+#if defined(__BORLANDC__)
+#include <float.h>
+#define isfinite _finite
+#define snprintf _snprintf
+#endif
+
+#if defined(_MSC_VER) && _MSC_VER >= 1400 // VC++ 8.0
+// Disable warning about strdup being deprecated.
+#pragma warning(disable : 4996)
+#endif
+
+namespace Json {
+
+#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
+typedef std::unique_ptr<StreamWriter> StreamWriterPtr;
+#else
+typedef std::auto_ptr<StreamWriter> StreamWriterPtr;
+#endif
+
+static bool containsControlCharacter(const char* str) {
+ while (*str) {
+ if (isControlCharacter(*(str++)))
+ return true;
+ }
+ return false;
+}
+
+static bool containsControlCharacter0(const char* str, unsigned len) {
+ char const* end = str + len;
+ while (end != str) {
+ if (isControlCharacter(*str) || 0==*str)
+ return true;
+ ++str;
+ }
+ return false;
+}
+
+std::string valueToString(LargestInt value) {
+ UIntToStringBuffer buffer;
+ char* current = buffer + sizeof(buffer);
+ if (value == Value::minLargestInt) {
+ uintToString(LargestUInt(Value::maxLargestInt) + 1, current);
+ *--current = '-';
+ } else if (value < 0) {
+ uintToString(LargestUInt(-value), current);
+ *--current = '-';
+ } else {
+ uintToString(LargestUInt(value), current);
+ }
+ assert(current >= buffer);
+ return current;
+}
+
+std::string valueToString(LargestUInt value) {
+ UIntToStringBuffer buffer;
+ char* current = buffer + sizeof(buffer);
+ uintToString(value, current);
+ assert(current >= buffer);
+ return current;
+}
+
+#if defined(JSON_HAS_INT64)
+
+std::string valueToString(Int value) {
+ return valueToString(LargestInt(value));
+}
+
+std::string valueToString(UInt value) {
+ return valueToString(LargestUInt(value));
+}
+
+#endif // # if defined(JSON_HAS_INT64)
+
+std::string valueToString(double value, bool useSpecialFloats, unsigned int precision) {
+ // Allocate a buffer that is more than large enough to store the 16 digits of
+ // precision requested below.
+ char buffer[32];
+ int len = -1;
+
+ char formatString[6];
+ sprintf(formatString, "%%.%dg", precision);
+
+ // Print into the buffer. We need not request the alternative representation
+ // that always has a decimal point because JSON doesn't distingish the
+ // concepts of reals and integers.
+ if (isfinite(value)) {
+ len = snprintf(buffer, sizeof(buffer), formatString, value);
+ } else {
+ // IEEE standard states that NaN values will not compare to themselves
+ if (value != value) {
+ len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "NaN" : "null");
+ } else if (value < 0) {
+ len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "-Infinity" : "-1e+9999");
+ } else {
+ len = snprintf(buffer, sizeof(buffer), useSpecialFloats ? "Infinity" : "1e+9999");
+ }
+ // For those, we do not need to call fixNumLoc, but it is fast.
+ }
+ assert(len >= 0);
+ fixNumericLocale(buffer, buffer + len);
+ return buffer;
+}
+
+std::string valueToString(double value) { return valueToString(value, false, 17); }
+
+std::string valueToString(bool value) { return value ? "true" : "false"; }
+
+std::string valueToQuotedString(const char* value) {
+ if (value == NULL)
+ return "";
+ // Not sure how to handle unicode...
+ if (strpbrk(value, "\"\\\b\f\n\r\t") == NULL &&
+ !containsControlCharacter(value))
+ return std::string("\"") + value + "\"";
+ // We have to walk value and escape any special characters.
+ // Appending to std::string is not efficient, but this should be rare.
+ // (Note: forward slashes are *not* rare, but I am not escaping them.)
+ std::string::size_type maxsize =
+ strlen(value) * 2 + 3; // allescaped+quotes+NULL
+ std::string result;
+ result.reserve(maxsize); // to avoid lots of mallocs
+ result += "\"";
+ for (const char* c = value; *c != 0; ++c) {
+ switch (*c) {
+ case '\"':
+ result += "\\\"";
+ break;
+ case '\\':
+ result += "\\\\";
+ break;
+ case '\b':
+ result += "\\b";
+ break;
+ case '\f':
+ result += "\\f";
+ break;
+ case '\n':
+ result += "\\n";
+ break;
+ case '\r':
+ result += "\\r";
+ break;
+ case '\t':
+ result += "\\t";
+ break;
+ // case '/':
+ // Even though \/ is considered a legal escape in JSON, a bare
+ // slash is also legal, so I see no reason to escape it.
+ // (I hope I am not misunderstanding something.
+ // blep notes: actually escaping \/ may be useful in javascript to avoid </
+ // sequence.
+ // Should add a flag to allow this compatibility mode and prevent this
+ // sequence from occurring.
+ default:
+ if (isControlCharacter(*c)) {
+ std::ostringstream oss;
+ oss << "\\u" << std::hex << std::uppercase << std::setfill('0')
+ << std::setw(4) << static_cast<int>(*c);
+ result += oss.str();
+ } else {
+ result += *c;
+ }
+ break;
+ }
+ }
+ result += "\"";
+ return result;
+}
+
+// https://github.com/upcaste/upcaste/blob/master/src/upcore/src/cstring/strnpbrk.cpp
+static char const* strnpbrk(char const* s, char const* accept, size_t n) {
+ assert((s || !n) && accept);
+
+ char const* const end = s + n;
+ for (char const* cur = s; cur < end; ++cur) {
+ int const c = *cur;
+ for (char const* a = accept; *a; ++a) {
+ if (*a == c) {
+ return cur;
+ }
+ }
+ }
+ return NULL;
+}
+static std::string valueToQuotedStringN(const char* value, unsigned length) {
+ if (value == NULL)
+ return "";
+ // Not sure how to handle unicode...
+ if (strnpbrk(value, "\"\\\b\f\n\r\t", length) == NULL &&
+ !containsControlCharacter0(value, length))
+ return std::string("\"") + value + "\"";
+ // We have to walk value and escape any special characters.
+ // Appending to std::string is not efficient, but this should be rare.
+ // (Note: forward slashes are *not* rare, but I am not escaping them.)
+ std::string::size_type maxsize =
+ length * 2 + 3; // allescaped+quotes+NULL
+ std::string result;
+ result.reserve(maxsize); // to avoid lots of mallocs
+ result += "\"";
+ char const* end = value + length;
+ for (const char* c = value; c != end; ++c) {
+ switch (*c) {
+ case '\"':
+ result += "\\\"";
+ break;
+ case '\\':
+ result += "\\\\";
+ break;
+ case '\b':
+ result += "\\b";
+ break;
+ case '\f':
+ result += "\\f";
+ break;
+ case '\n':
+ result += "\\n";
+ break;
+ case '\r':
+ result += "\\r";
+ break;
+ case '\t':
+ result += "\\t";
+ break;
+ // case '/':
+ // Even though \/ is considered a legal escape in JSON, a bare
+ // slash is also legal, so I see no reason to escape it.
+ // (I hope I am not misunderstanding something.)
+ // blep notes: actually escaping \/ may be useful in javascript to avoid </
+ // sequence.
+ // Should add a flag to allow this compatibility mode and prevent this
+ // sequence from occurring.
+ default:
+ if ((isControlCharacter(*c)) || (*c == 0)) {
+ std::ostringstream oss;
+ oss << "\\u" << std::hex << std::uppercase << std::setfill('0')
+ << std::setw(4) << static_cast<int>(*c);
+ result += oss.str();
+ } else {
+ result += *c;
+ }
+ break;
+ }
+ }
+ result += "\"";
+ return result;
+}
+
+// Class Writer
+// //////////////////////////////////////////////////////////////////
+Writer::~Writer() {}
+
+// Class FastWriter
+// //////////////////////////////////////////////////////////////////
+
+FastWriter::FastWriter()
+ : yamlCompatiblityEnabled_(false), dropNullPlaceholders_(false),
+ omitEndingLineFeed_(false) {}
+
+void FastWriter::enableYAMLCompatibility() { yamlCompatiblityEnabled_ = true; }
+
+void FastWriter::dropNullPlaceholders() { dropNullPlaceholders_ = true; }
+
+void FastWriter::omitEndingLineFeed() { omitEndingLineFeed_ = true; }
+
+std::string FastWriter::write(const Value& root) {
+ document_ = "";
+ writeValue(root);
+ if (!omitEndingLineFeed_)
+ document_ += "\n";
+ return document_;
+}
+
+void FastWriter::writeValue(const Value& value) {
+ switch (value.type()) {
+ case nullValue:
+ if (!dropNullPlaceholders_)
+ document_ += "null";
+ break;
+ case intValue:
+ document_ += valueToString(value.asLargestInt());
+ break;
+ case uintValue:
+ document_ += valueToString(value.asLargestUInt());
+ break;
+ case realValue:
+ document_ += valueToString(value.asDouble());
+ break;
+ case stringValue:
+ {
+ // Is NULL possible for value.string_?
+ char const* str;
+ char const* end;
+ bool ok = value.getString(&str, &end);
+ if (ok) document_ += valueToQuotedStringN(str, static_cast<unsigned>(end-str));
+ break;
+ }
+ case booleanValue:
+ document_ += valueToString(value.asBool());
+ break;
+ case arrayValue: {
+ document_ += '[';
+ int size = value.size();
+ for (int index = 0; index < size; ++index) {
+ if (index > 0)
+ document_ += ',';
+ writeValue(value[index]);
+ }
+ document_ += ']';
+ } break;
+ case objectValue: {
+ Value::Members members(value.getMemberNames());
+ document_ += '{';
+ for (Value::Members::iterator it = members.begin(); it != members.end();
+ ++it) {
+ const std::string& name = *it;
+ if (it != members.begin())
+ document_ += ',';
+ document_ += valueToQuotedStringN(name.data(), static_cast<unsigned>(name.length()));
+ document_ += yamlCompatiblityEnabled_ ? ": " : ":";
+ writeValue(value[name]);
+ }
+ document_ += '}';
+ } break;
+ }
+}
+
+// Class StyledWriter
+// //////////////////////////////////////////////////////////////////
+
+StyledWriter::StyledWriter()
+ : rightMargin_(74), indentSize_(3), addChildValues_() {}
+
+std::string StyledWriter::write(const Value& root) {
+ document_ = "";
+ addChildValues_ = false;
+ indentString_ = "";
+ writeCommentBeforeValue(root);
+ writeValue(root);
+ writeCommentAfterValueOnSameLine(root);
+ document_ += "\n";
+ return document_;
+}
+
+void StyledWriter::writeValue(const Value& value) {
+ switch (value.type()) {
+ case nullValue:
+ pushValue("null");
+ break;
+ case intValue:
+ pushValue(valueToString(value.asLargestInt()));
+ break;
+ case uintValue:
+ pushValue(valueToString(value.asLargestUInt()));
+ break;
+ case realValue:
+ pushValue(valueToString(value.asDouble()));
+ break;
+ case stringValue:
+ {
+ // Is NULL possible for value.string_?
+ char const* str;
+ char const* end;
+ bool ok = value.getString(&str, &end);
+ if (ok) pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end-str)));
+ else pushValue("");
+ break;
+ }
+ case booleanValue:
+ pushValue(valueToString(value.asBool()));
+ break;
+ case arrayValue:
+ writeArrayValue(value);
+ break;
+ case objectValue: {
+ Value::Members members(value.getMemberNames());
+ if (members.empty())
+ pushValue("{}");
+ else {
+ writeWithIndent("{");
+ indent();
+ Value::Members::iterator it = members.begin();
+ for (;;) {
+ const std::string& name = *it;
+ const Value& childValue = value[name];
+ writeCommentBeforeValue(childValue);
+ writeWithIndent(valueToQuotedString(name.c_str()));
+ document_ += " : ";
+ writeValue(childValue);
+ if (++it == members.end()) {
+ writeCommentAfterValueOnSameLine(childValue);
+ break;
+ }
+ document_ += ',';
+ writeCommentAfterValueOnSameLine(childValue);
+ }
+ unindent();
+ writeWithIndent("}");
+ }
+ } break;
+ }
+}
+
+void StyledWriter::writeArrayValue(const Value& value) {
+ unsigned size = value.size();
+ if (size == 0)
+ pushValue("[]");
+ else {
+ bool isArrayMultiLine = isMultineArray(value);
+ if (isArrayMultiLine) {
+ writeWithIndent("[");
+ indent();
+ bool hasChildValue = !childValues_.empty();
+ unsigned index = 0;
+ for (;;) {
+ const Value& childValue = value[index];
+ writeCommentBeforeValue(childValue);
+ if (hasChildValue)
+ writeWithIndent(childValues_[index]);
+ else {
+ writeIndent();
+ writeValue(childValue);
+ }
+ if (++index == size) {
+ writeCommentAfterValueOnSameLine(childValue);
+ break;
+ }
+ document_ += ',';
+ writeCommentAfterValueOnSameLine(childValue);
+ }
+ unindent();
+ writeWithIndent("]");
+ } else // output on a single line
+ {
+ assert(childValues_.size() == size);
+ document_ += "[ ";
+ for (unsigned index = 0; index < size; ++index) {
+ if (index > 0)
+ document_ += ", ";
+ document_ += childValues_[index];
+ }
+ document_ += " ]";
+ }
+ }
+}
+
+bool StyledWriter::isMultineArray(const Value& value) {
+ int size = value.size();
+ bool isMultiLine = size * 3 >= rightMargin_;
+ childValues_.clear();
+ for (int index = 0; index < size && !isMultiLine; ++index) {
+ const Value& childValue = value[index];
+ isMultiLine = ((childValue.isArray() || childValue.isObject()) &&
+ childValue.size() > 0);
+ }
+ if (!isMultiLine) // check if line length > max line length
+ {
+ childValues_.reserve(size);
+ addChildValues_ = true;
+ int lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]'
+ for (int index = 0; index < size; ++index) {
+ if (hasCommentForValue(value[index])) {
+ isMultiLine = true;
+ }
+ writeValue(value[index]);
+ lineLength += int(childValues_[index].length());
+ }
+ addChildValues_ = false;
+ isMultiLine = isMultiLine || lineLength >= rightMargin_;
+ }
+ return isMultiLine;
+}
+
+void StyledWriter::pushValue(const std::string& value) {
+ if (addChildValues_)
+ childValues_.push_back(value);
+ else
+ document_ += value;
+}
+
+void StyledWriter::writeIndent() {
+ if (!document_.empty()) {
+ char last = document_[document_.length() - 1];
+ if (last == ' ') // already indented
+ return;
+ if (last != '\n') // Comments may add new-line
+ document_ += '\n';
+ }
+ document_ += indentString_;
+}
+
+void StyledWriter::writeWithIndent(const std::string& value) {
+ writeIndent();
+ document_ += value;
+}
+
+void StyledWriter::indent() { indentString_ += std::string(indentSize_, ' '); }
+
+void StyledWriter::unindent() {
+ assert(int(indentString_.size()) >= indentSize_);
+ indentString_.resize(indentString_.size() - indentSize_);
+}
+
+void StyledWriter::writeCommentBeforeValue(const Value& root) {
+ if (!root.hasComment(commentBefore))
+ return;
+
+ document_ += "\n";
+ writeIndent();
+ const std::string& comment = root.getComment(commentBefore);
+ std::string::const_iterator iter = comment.begin();
+ while (iter != comment.end()) {
+ document_ += *iter;
+ if (*iter == '\n' &&
+ (iter != comment.end() && *(iter + 1) == '/'))
+ writeIndent();
+ ++iter;
+ }
+
+ // Comments are stripped of trailing newlines, so add one here
+ document_ += "\n";
+}
+
+void StyledWriter::writeCommentAfterValueOnSameLine(const Value& root) {
+ if (root.hasComment(commentAfterOnSameLine))
+ document_ += " " + root.getComment(commentAfterOnSameLine);
+
+ if (root.hasComment(commentAfter)) {
+ document_ += "\n";
+ document_ += root.getComment(commentAfter);
+ document_ += "\n";
+ }
+}
+
+bool StyledWriter::hasCommentForValue(const Value& value) {
+ return value.hasComment(commentBefore) ||
+ value.hasComment(commentAfterOnSameLine) ||
+ value.hasComment(commentAfter);
+}
+
+// Class StyledStreamWriter
+// //////////////////////////////////////////////////////////////////
+
+StyledStreamWriter::StyledStreamWriter(std::string indentation)
+ : document_(NULL), rightMargin_(74), indentation_(indentation),
+ addChildValues_() {}
+
+void StyledStreamWriter::write(std::ostream& out, const Value& root) {
+ document_ = &out;
+ addChildValues_ = false;
+ indentString_ = "";
+ indented_ = true;
+ writeCommentBeforeValue(root);
+ if (!indented_) writeIndent();
+ indented_ = true;
+ writeValue(root);
+ writeCommentAfterValueOnSameLine(root);
+ *document_ << "\n";
+ document_ = NULL; // Forget the stream, for safety.
+}
+
+void StyledStreamWriter::writeValue(const Value& value) {
+ switch (value.type()) {
+ case nullValue:
+ pushValue("null");
+ break;
+ case intValue:
+ pushValue(valueToString(value.asLargestInt()));
+ break;
+ case uintValue:
+ pushValue(valueToString(value.asLargestUInt()));
+ break;
+ case realValue:
+ pushValue(valueToString(value.asDouble()));
+ break;
+ case stringValue:
+ {
+ // Is NULL possible for value.string_?
+ char const* str;
+ char const* end;
+ bool ok = value.getString(&str, &end);
+ if (ok) pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end-str)));
+ else pushValue("");
+ break;
+ }
+ case booleanValue:
+ pushValue(valueToString(value.asBool()));
+ break;
+ case arrayValue:
+ writeArrayValue(value);
+ break;
+ case objectValue: {
+ Value::Members members(value.getMemberNames());
+ if (members.empty())
+ pushValue("{}");
+ else {
+ writeWithIndent("{");
+ indent();
+ Value::Members::iterator it = members.begin();
+ for (;;) {
+ const std::string& name = *it;
+ const Value& childValue = value[name];
+ writeCommentBeforeValue(childValue);
+ writeWithIndent(valueToQuotedString(name.c_str()));
+ *document_ << " : ";
+ writeValue(childValue);
+ if (++it == members.end()) {
+ writeCommentAfterValueOnSameLine(childValue);
+ break;
+ }
+ *document_ << ",";
+ writeCommentAfterValueOnSameLine(childValue);
+ }
+ unindent();
+ writeWithIndent("}");
+ }
+ } break;
+ }
+}
+
+void StyledStreamWriter::writeArrayValue(const Value& value) {
+ unsigned size = value.size();
+ if (size == 0)
+ pushValue("[]");
+ else {
+ bool isArrayMultiLine = isMultineArray(value);
+ if (isArrayMultiLine) {
+ writeWithIndent("[");
+ indent();
+ bool hasChildValue = !childValues_.empty();
+ unsigned index = 0;
+ for (;;) {
+ const Value& childValue = value[index];
+ writeCommentBeforeValue(childValue);
+ if (hasChildValue)
+ writeWithIndent(childValues_[index]);
+ else {
+ if (!indented_) writeIndent();
+ indented_ = true;
+ writeValue(childValue);
+ indented_ = false;
+ }
+ if (++index == size) {
+ writeCommentAfterValueOnSameLine(childValue);
+ break;
+ }
+ *document_ << ",";
+ writeCommentAfterValueOnSameLine(childValue);
+ }
+ unindent();
+ writeWithIndent("]");
+ } else // output on a single line
+ {
+ assert(childValues_.size() == size);
+ *document_ << "[ ";
+ for (unsigned index = 0; index < size; ++index) {
+ if (index > 0)
+ *document_ << ", ";
+ *document_ << childValues_[index];
+ }
+ *document_ << " ]";
+ }
+ }
+}
+
+bool StyledStreamWriter::isMultineArray(const Value& value) {
+ int size = value.size();
+ bool isMultiLine = size * 3 >= rightMargin_;
+ childValues_.clear();
+ for (int index = 0; index < size && !isMultiLine; ++index) {
+ const Value& childValue = value[index];
+ isMultiLine = ((childValue.isArray() || childValue.isObject()) &&
+ childValue.size() > 0);
+ }
+ if (!isMultiLine) // check if line length > max line length
+ {
+ childValues_.reserve(size);
+ addChildValues_ = true;
+ int lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]'
+ for (int index = 0; index < size; ++index) {
+ if (hasCommentForValue(value[index])) {
+ isMultiLine = true;
+ }
+ writeValue(value[index]);
+ lineLength += int(childValues_[index].length());
+ }
+ addChildValues_ = false;
+ isMultiLine = isMultiLine || lineLength >= rightMargin_;
+ }
+ return isMultiLine;
+}
+
+void StyledStreamWriter::pushValue(const std::string& value) {
+ if (addChildValues_)
+ childValues_.push_back(value);
+ else
+ *document_ << value;
+}
+
+void StyledStreamWriter::writeIndent() {
+ // blep intended this to look at the so-far-written string
+ // to determine whether we are already indented, but
+ // with a stream we cannot do that. So we rely on some saved state.
+ // The caller checks indented_.
+ *document_ << '\n' << indentString_;
+}
+
+void StyledStreamWriter::writeWithIndent(const std::string& value) {
+ if (!indented_) writeIndent();
+ *document_ << value;
+ indented_ = false;
+}
+
+void StyledStreamWriter::indent() { indentString_ += indentation_; }
+
+void StyledStreamWriter::unindent() {
+ assert(indentString_.size() >= indentation_.size());
+ indentString_.resize(indentString_.size() - indentation_.size());
+}
+
+void StyledStreamWriter::writeCommentBeforeValue(const Value& root) {
+ if (!root.hasComment(commentBefore))
+ return;
+
+ if (!indented_) writeIndent();
+ const std::string& comment = root.getComment(commentBefore);
+ std::string::const_iterator iter = comment.begin();
+ while (iter != comment.end()) {
+ *document_ << *iter;
+ if (*iter == '\n' &&
+ (iter != comment.end() && *(iter + 1) == '/'))
+ // writeIndent(); // would include newline
+ *document_ << indentString_;
+ ++iter;
+ }
+ indented_ = false;
+}
+
+void StyledStreamWriter::writeCommentAfterValueOnSameLine(const Value& root) {
+ if (root.hasComment(commentAfterOnSameLine))
+ *document_ << ' ' << root.getComment(commentAfterOnSameLine);
+
+ if (root.hasComment(commentAfter)) {
+ writeIndent();
+ *document_ << root.getComment(commentAfter);
+ }
+ indented_ = false;
+}
+
+bool StyledStreamWriter::hasCommentForValue(const Value& value) {
+ return value.hasComment(commentBefore) ||
+ value.hasComment(commentAfterOnSameLine) ||
+ value.hasComment(commentAfter);
+}
+
+//////////////////////////
+// BuiltStyledStreamWriter
+
+/// Scoped enums are not available until C++11.
+struct CommentStyle {
+ /// Decide whether to write comments.
+ enum Enum {
+ None, ///< Drop all comments.
+ Most, ///< Recover odd behavior of previous versions (not implemented yet).
+ All ///< Keep all comments.
+ };
+};
+
+struct BuiltStyledStreamWriter : public StreamWriter
+{
+ BuiltStyledStreamWriter(
+ std::string const& indentation,
+ CommentStyle::Enum cs,
+ std::string const& colonSymbol,
+ std::string const& nullSymbol,
+ std::string const& endingLineFeedSymbol,
+ bool useSpecialFloats,
+ unsigned int precision);
+ int write(Value const& root, std::ostream* sout) override;
+private:
+ void writeValue(Value const& value);
+ void writeArrayValue(Value const& value);
+ bool isMultineArray(Value const& value);
+ void pushValue(std::string const& value);
+ void writeIndent();
+ void writeWithIndent(std::string const& value);
+ void indent();
+ void unindent();
+ void writeCommentBeforeValue(Value const& root);
+ void writeCommentAfterValueOnSameLine(Value const& root);
+ static bool hasCommentForValue(const Value& value);
+
+ typedef std::vector<std::string> ChildValues;
+
+ ChildValues childValues_;
+ std::string indentString_;
+ int rightMargin_;
+ std::string indentation_;
+ CommentStyle::Enum cs_;
+ std::string colonSymbol_;
+ std::string nullSymbol_;
+ std::string endingLineFeedSymbol_;
+ bool addChildValues_ : 1;
+ bool indented_ : 1;
+ bool useSpecialFloats_ : 1;
+ unsigned int precision_;
+};
+BuiltStyledStreamWriter::BuiltStyledStreamWriter(
+ std::string const& indentation,
+ CommentStyle::Enum cs,
+ std::string const& colonSymbol,
+ std::string const& nullSymbol,
+ std::string const& endingLineFeedSymbol,
+ bool useSpecialFloats,
+ unsigned int precision)
+ : rightMargin_(74)
+ , indentation_(indentation)
+ , cs_(cs)
+ , colonSymbol_(colonSymbol)
+ , nullSymbol_(nullSymbol)
+ , endingLineFeedSymbol_(endingLineFeedSymbol)
+ , addChildValues_(false)
+ , indented_(false)
+ , useSpecialFloats_(useSpecialFloats)
+ , precision_(precision)
+{
+}
+int BuiltStyledStreamWriter::write(Value const& root, std::ostream* sout)
+{
+ sout_ = sout;
+ addChildValues_ = false;
+ indented_ = true;
+ indentString_ = "";
+ writeCommentBeforeValue(root);
+ if (!indented_) writeIndent();
+ indented_ = true;
+ writeValue(root);
+ writeCommentAfterValueOnSameLine(root);
+ *sout_ << endingLineFeedSymbol_;
+ sout_ = NULL;
+ return 0;
+}
+void BuiltStyledStreamWriter::writeValue(Value const& value) {
+ switch (value.type()) {
+ case nullValue:
+ pushValue(nullSymbol_);
+ break;
+ case intValue:
+ pushValue(valueToString(value.asLargestInt()));
+ break;
+ case uintValue:
+ pushValue(valueToString(value.asLargestUInt()));
+ break;
+ case realValue:
+ pushValue(valueToString(value.asDouble(), useSpecialFloats_, precision_));
+ break;
+ case stringValue:
+ {
+ // Is NULL is possible for value.string_?
+ char const* str;
+ char const* end;
+ bool ok = value.getString(&str, &end);
+ if (ok) pushValue(valueToQuotedStringN(str, static_cast<unsigned>(end-str)));
+ else pushValue("");
+ break;
+ }
+ case booleanValue:
+ pushValue(valueToString(value.asBool()));
+ break;
+ case arrayValue:
+ writeArrayValue(value);
+ break;
+ case objectValue: {
+ Value::Members members(value.getMemberNames());
+ if (members.empty())
+ pushValue("{}");
+ else {
+ writeWithIndent("{");
+ indent();
+ Value::Members::iterator it = members.begin();
+ for (;;) {
+ std::string const& name = *it;
+ Value const& childValue = value[name];
+ writeCommentBeforeValue(childValue);
+ writeWithIndent(valueToQuotedStringN(name.data(), static_cast<unsigned>(name.length())));
+ *sout_ << colonSymbol_;
+ writeValue(childValue);
+ if (++it == members.end()) {
+ writeCommentAfterValueOnSameLine(childValue);
+ break;
+ }
+ *sout_ << ",";
+ writeCommentAfterValueOnSameLine(childValue);
+ }
+ unindent();
+ writeWithIndent("}");
+ }
+ } break;
+ }
+}
+
+void BuiltStyledStreamWriter::writeArrayValue(Value const& value) {
+ unsigned size = value.size();
+ if (size == 0)
+ pushValue("[]");
+ else {
+ bool isMultiLine = (cs_ == CommentStyle::All) || isMultineArray(value);
+ if (isMultiLine) {
+ writeWithIndent("[");
+ indent();
+ bool hasChildValue = !childValues_.empty();
+ unsigned index = 0;
+ for (;;) {
+ Value const& childValue = value[index];
+ writeCommentBeforeValue(childValue);
+ if (hasChildValue)
+ writeWithIndent(childValues_[index]);
+ else {
+ if (!indented_) writeIndent();
+ indented_ = true;
+ writeValue(childValue);
+ indented_ = false;
+ }
+ if (++index == size) {
+ writeCommentAfterValueOnSameLine(childValue);
+ break;
+ }
+ *sout_ << ",";
+ writeCommentAfterValueOnSameLine(childValue);
+ }
+ unindent();
+ writeWithIndent("]");
+ } else // output on a single line
+ {
+ assert(childValues_.size() == size);
+ *sout_ << "[";
+ if (!indentation_.empty()) *sout_ << " ";
+ for (unsigned index = 0; index < size; ++index) {
+ if (index > 0)
+ *sout_ << ", ";
+ *sout_ << childValues_[index];
+ }
+ if (!indentation_.empty()) *sout_ << " ";
+ *sout_ << "]";
+ }
+ }
+}
+
+bool BuiltStyledStreamWriter::isMultineArray(Value const& value) {
+ int size = value.size();
+ bool isMultiLine = size * 3 >= rightMargin_;
+ childValues_.clear();
+ for (int index = 0; index < size && !isMultiLine; ++index) {
+ Value const& childValue = value[index];
+ isMultiLine = ((childValue.isArray() || childValue.isObject()) &&
+ childValue.size() > 0);
+ }
+ if (!isMultiLine) // check if line length > max line length
+ {
+ childValues_.reserve(size);
+ addChildValues_ = true;
+ int lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]'
+ for (int index = 0; index < size; ++index) {
+ if (hasCommentForValue(value[index])) {
+ isMultiLine = true;
+ }
+ writeValue(value[index]);
+ lineLength += int(childValues_[index].length());
+ }
+ addChildValues_ = false;
+ isMultiLine = isMultiLine || lineLength >= rightMargin_;
+ }
+ return isMultiLine;
+}
+
+void BuiltStyledStreamWriter::pushValue(std::string const& value) {
+ if (addChildValues_)
+ childValues_.push_back(value);
+ else
+ *sout_ << value;
+}
+
+void BuiltStyledStreamWriter::writeIndent() {
+ // blep intended this to look at the so-far-written string
+ // to determine whether we are already indented, but
+ // with a stream we cannot do that. So we rely on some saved state.
+ // The caller checks indented_.
+
+ if (!indentation_.empty()) {
+ // In this case, drop newlines too.
+ *sout_ << '\n' << indentString_;
+ }
+}
+
+void BuiltStyledStreamWriter::writeWithIndent(std::string const& value) {
+ if (!indented_) writeIndent();
+ *sout_ << value;
+ indented_ = false;
+}
+
+void BuiltStyledStreamWriter::indent() { indentString_ += indentation_; }
+
+void BuiltStyledStreamWriter::unindent() {
+ assert(indentString_.size() >= indentation_.size());
+ indentString_.resize(indentString_.size() - indentation_.size());
+}
+
+void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) {
+ if (cs_ == CommentStyle::None) return;
+ if (!root.hasComment(commentBefore))
+ return;
+
+ if (!indented_) writeIndent();
+ const std::string& comment = root.getComment(commentBefore);
+ std::string::const_iterator iter = comment.begin();
+ while (iter != comment.end()) {
+ *sout_ << *iter;
+ if (*iter == '\n' &&
+ (iter != comment.end() && *(iter + 1) == '/'))
+ // writeIndent(); // would write extra newline
+ *sout_ << indentString_;
+ ++iter;
+ }
+ indented_ = false;
+}
+
+void BuiltStyledStreamWriter::writeCommentAfterValueOnSameLine(Value const& root) {
+ if (cs_ == CommentStyle::None) return;
+ if (root.hasComment(commentAfterOnSameLine))
+ *sout_ << " " + root.getComment(commentAfterOnSameLine);
+
+ if (root.hasComment(commentAfter)) {
+ writeIndent();
+ *sout_ << root.getComment(commentAfter);
+ }
+}
+
+// static
+bool BuiltStyledStreamWriter::hasCommentForValue(const Value& value) {
+ return value.hasComment(commentBefore) ||
+ value.hasComment(commentAfterOnSameLine) ||
+ value.hasComment(commentAfter);
+}
+
+///////////////
+// StreamWriter
+
+StreamWriter::StreamWriter()
+ : sout_(NULL)
+{
+}
+StreamWriter::~StreamWriter()
+{
+}
+StreamWriter::Factory::~Factory()
+{}
+StreamWriterBuilder::StreamWriterBuilder()
+{
+ setDefaults(&settings_);
+}
+StreamWriterBuilder::~StreamWriterBuilder()
+{}
+StreamWriter* StreamWriterBuilder::newStreamWriter() const
+{
+ std::string indentation = settings_["indentation"].asString();
+ std::string cs_str = settings_["commentStyle"].asString();
+ bool eyc = settings_["enableYAMLCompatibility"].asBool();
+ bool dnp = settings_["dropNullPlaceholders"].asBool();
+ bool usf = settings_["useSpecialFloats"].asBool();
+ unsigned int pre = settings_["precision"].asUInt();
+ CommentStyle::Enum cs = CommentStyle::All;
+ if (cs_str == "All") {
+ cs = CommentStyle::All;
+ } else if (cs_str == "None") {
+ cs = CommentStyle::None;
+ } else {
+ throwRuntimeError("commentStyle must be 'All' or 'None'");
+ }
+ std::string colonSymbol = " : ";
+ if (eyc) {
+ colonSymbol = ": ";
+ } else if (indentation.empty()) {
+ colonSymbol = ":";
+ }
+ std::string nullSymbol = "null";
+ if (dnp) {
+ nullSymbol = "";
+ }
+ if (pre > 17) pre = 17;
+ std::string endingLineFeedSymbol = "";
+ return new BuiltStyledStreamWriter(
+ indentation, cs,
+ colonSymbol, nullSymbol, endingLineFeedSymbol, usf, pre);
+}
+static void getValidWriterKeys(std::set<std::string>* valid_keys)
+{
+ valid_keys->clear();
+ valid_keys->insert("indentation");
+ valid_keys->insert("commentStyle");
+ valid_keys->insert("enableYAMLCompatibility");
+ valid_keys->insert("dropNullPlaceholders");
+ valid_keys->insert("useSpecialFloats");
+ valid_keys->insert("precision");
+}
+bool StreamWriterBuilder::validate(Json::Value* invalid) const
+{
+ Json::Value my_invalid;
+ if (!invalid) invalid = &my_invalid; // so we do not need to test for NULL
+ Json::Value& inv = *invalid;
+ std::set<std::string> valid_keys;
+ getValidWriterKeys(&valid_keys);
+ Value::Members keys = settings_.getMemberNames();
+ size_t n = keys.size();
+ for (size_t i = 0; i < n; ++i) {
+ std::string const& key = keys[i];
+ if (valid_keys.find(key) == valid_keys.end()) {
+ inv[key] = settings_[key];
+ }
+ }
+ return 0u == inv.size();
+}
+Value& StreamWriterBuilder::operator[](std::string key)
+{
+ return settings_[key];
+}
+// static
+void StreamWriterBuilder::setDefaults(Json::Value* settings)
+{
+ //! [StreamWriterBuilderDefaults]
+ (*settings)["commentStyle"] = "All";
+ (*settings)["indentation"] = "\t";
+ (*settings)["enableYAMLCompatibility"] = false;
+ (*settings)["dropNullPlaceholders"] = false;
+ (*settings)["useSpecialFloats"] = false;
+ (*settings)["precision"] = 17;
+ //! [StreamWriterBuilderDefaults]
+}
+
+std::string writeString(StreamWriter::Factory const& builder, Value const& root) {
+ std::ostringstream sout;
+ StreamWriterPtr const writer(builder.newStreamWriter());
+ writer->write(root, &sout);
+ return sout.str();
+}
+
+std::ostream& operator<<(std::ostream& sout, Value const& root) {
+ StreamWriterBuilder builder;
+ StreamWriterPtr const writer(builder.newStreamWriter());
+ writer->write(root, &sout);
+ return sout;
+}
+
+} // namespace Json
+
+// //////////////////////////////////////////////////////////////////////
+// End of content of file: src/lib_json/json_writer.cpp
+// //////////////////////////////////////////////////////////////////////
+
+
+
+
+
diff --git a/third_party/protobuf/conformance/update_failure_list.py b/third_party/protobuf/conformance/update_failure_list.py
new file mode 100755
index 0000000000..63f453df1b
--- /dev/null
+++ b/third_party/protobuf/conformance/update_failure_list.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python
+# 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.
+
+"""Script to update a failure list file to add/remove failures.
+
+This is sort of like comm(1), except it recognizes comments and ignores them.
+"""
+
+import argparse
+import fileinput
+
+parser = argparse.ArgumentParser(
+ description='Adds/removes failures from the failure list.')
+parser.add_argument('filename', type=str, help='failure list file to update')
+parser.add_argument('--add', dest='add_list', action='append')
+parser.add_argument('--remove', dest='remove_list', action='append')
+
+args = parser.parse_args()
+
+add_set = set()
+remove_set = set()
+
+for add_file in (args.add_list or []):
+ with open(add_file) as f:
+ for line in f:
+ add_set.add(line)
+
+for remove_file in (args.remove_list or []):
+ with open(remove_file) as f:
+ for line in f:
+ if line in add_set:
+ raise Exception("Asked to both add and remove test: " + line)
+ remove_set.add(line.strip())
+
+add_list = sorted(add_set, reverse=True)
+
+existing_list = file(args.filename).read()
+
+with open(args.filename, "w") as f:
+ for line in existing_list.splitlines(True):
+ test = line.split("#")[0].strip()
+ while len(add_list) > 0 and test > add_list[-1]:
+ f.write(add_list.pop())
+ if test not in remove_set:
+ f.write(line)
diff --git a/third_party/protobuf/csharp/.gitignore b/third_party/protobuf/csharp/.gitignore
new file mode 100644
index 0000000000..8ba8849985
--- /dev/null
+++ b/third_party/protobuf/csharp/.gitignore
@@ -0,0 +1,31 @@
+# Output
+bin
+obj
+project.lock.json
+TestResult.xml
+
+# Possibly legacy now?
+mono/bin
+mono/tmp
+mono/protoc
+build_output
+build_temp
+build/msbuild*.log
+lib/Microsoft.Silverlight.Testing
+lib/NUnit
+
+#
+# Untracked files
+#
+.vs
+*.user
+*.suo
+*.nupkg
+_ReSharper.*
+*.sln.cache
+mono/TestResult.xml
+mono/.libs
+mono/*.exe
+mono/*.dll
+lib/protoc.exe
+*.ncrunch*
diff --git a/third_party/protobuf/csharp/CHANGES.txt b/third_party/protobuf/csharp/CHANGES.txt
new file mode 100644
index 0000000000..a87cd4d5df
--- /dev/null
+++ b/third_party/protobuf/csharp/CHANGES.txt
@@ -0,0 +1,148 @@
+===============================================================================
+Welcome to the C# port of Google Protocol Buffers, written by Jon Skeet
+(skeet@pobox.com) based on the work of many talented people.
+
+===============================================================================
+RELEASE NOTES - Code imported into Google's main protobuf repository
+===============================================================================
+
+Everything below note this represents history of protobuf-csharp-port project
+before the code was merged into csharp/ subtree of GitHub google/protobuf
+repository.
+Frozen legacy version of the original project is available in
+https://github.com/jskeet/protobuf-csharp-port.
+
+===============================================================================
+RELEASE NOTES - Version 2.4.1.555
+===============================================================================
+
+Changes:
+- Upgrade solution format to Visual Studio 2012.
+- Add the ability to print a builder (not just a message)
+- TextGenerator introduces a new overload of PrintTo
+- Munge protoc's error format into a VS-C#-compatible output format.
+- Work to make ProtoGen clone that acts as a protoc.exe plugin.
+- Added the AllowPartiallyTrustedCallers attribute
+- Optimized enum parsing.
+
+Fixes:
+- Fix for bug in limited input stream's Position, Introduced Position on
+ output stream
+- Fix for writing a character to a JSON output overflows allocated buffer
+- Optimize FromBase64String to return Empty when presented with empty string.
+- Use string.Concat instead of operator to avoid potential import problems
+- Issue 81: quoting for NUnit parameters.
+- Issue 56: NuGet package is noisy
+- Issue 70: Portable library project has some invalid Nunit-based code.
+- Issue 71: CodedInputStream.ReadBytes go to slow path unnecessarily
+- Issue 84: warning CS0219: The variable `size' is assigned but never used
+
+===============================================================================
+RELEASE NOTES - Version 2.4.1.521
+===============================================================================
+
+Changes:
+- Add generated_code_attributes option, defaulted to false
+- Added support for Portable library
+- Added 'Unsafe' static type in ByteString to allow direct buffer access
+
+Fixes:
+- Issue 50: The XML serializer will fail to deserialize a message with empty
+ child message
+- Issue 45: Use of 'item' as a field name causes AmbiguousMatchException
+- Issue 49: Generated nested static Types class should be partial
+- Issue 38: Disable CLSCompliant warnings (3021)
+- Issue 40: proto_path does not work for command-line file names
+- Issue 54: should retire all bytes in buffer (bufferSize)
+- Issue 43: Fix to correct identical 'umbrella_classname' options from trying
+ to write to the same filename.
+
+===============================================================================
+RELEASE NOTES - Version 2.4.1.473
+===============================================================================
+
+Features:
+- Added option service_generator_type to control service generation with
+ NONE, GENERIC, INTERFACE, or IRPCDISPATCH
+- Added interfaces IRpcDispatch and IRpcServerStub to provide for blocking
+ services and implementations.
+- Added ProtoGen.exe command-line argument "--protoc_dir=" to specify the
+ location of protoc.exe.
+- Extracted interfaces for ICodedInputStream and ICodedOutputStream to allow
+ custom implementation of writers with both speed and size optimizations.
+- Addition of the "Google.ProtoBuffers.Serialization" assembly to support
+ reading and writing messages to/from XML, JSON, IDictionary<,> and others.
+- Several performance related fixes and tweeks
+- Issue 3: Add option to mark generated code with attribute
+- Issue 20: Support for decorating classes [Serializable]
+- Issue 21: Decorate fields with [deprecated=true] as [System.Obsolete]
+- Issue 22: Reusable Builder classes
+- Issue 24: Support for using Json/Xml formats with ICodedInputStream
+- Issue 25: Added support for NuGet packages
+- Issue 31: Upgraded protoc.exe and descriptor to 2.4.1
+
+Fixes:
+- Issue 13: Message with Field same name as message causes uncompilable .cs
+- Issue 16: Does not integrate well with other tooling
+- Issue 19: Support for negative enum values
+- Issue 26: AddRange in GeneratedBuilder iterates twice.
+- Issue 27: Remove XML documentation output from test projects to clear
+ warnings/errors.
+- Issue 28: Circular message dependencies result in null default values for
+ Message fields.
+- Issue 29: Message classes generated have a public default constructor. You
+ can disable private ctor generation with the option generate_private_ctor.
+- Issue 35: Fixed a bug in ProtoGen handling of arguments with trailing \
+- Big-endian support for float, and double on Silverlight
+- Packed and Unpacked parsing allow for all repeated, as per version 2.3
+- Fix for leaving Builder a public ctor on internal classes for use with
+ generic "where T: new()" constraints.
+
+Other:
+- Changed the code signing key to a privately held key
+- Reformatted all code and line-endings to C# defaults
+- Reworking of performance benchmarks to produce reliable results, option /v2
+- Issue 34: Silverlight assemblies are now unit tested
+
+===============================================================================
+RELEASE NOTES - Version 2.3.0.277
+===============================================================================
+
+Features:
+- Added cls_compliance option to generate attributes indicating
+ non-CLS-compliance.
+- Added file_extension option to control the generated output file's extension.
+- Added umbrella_namespace option to place the umbrella class into a nested
+ namespace to address issues with proto files having the same name as a
+ message it contains.
+- Added output_directory option to set the output path for the source file(s).
+- Added ignore_google_protobuf option to avoid generating code for includes
+ from the google.protobuf package.
+- Added the LITE framework (Google.ProtoBuffersLite.dll) and the ability to
+ generate code with "option optimize_for = LITE_RUNTIME;".
+- Added ability to invoke protoc.exe from within ProtoGen.exe.
+- Upgraded to protoc.exe (2.3) compiler.
+
+Fixes:
+- Issue 9: Class cannot be static and sealed error
+- Issue 12: default value for enumerate fields must be filled out
+
+Other:
+- Rewrite of build using MSbuild instead of NAnt
+- Moved to NUnit Version 2.2.8.0
+- Changed to using secure .snk for releases
+
+===============================================================================
+RELEASE NOTES - Version 0.9.1
+===============================================================================
+
+Fixes:
+- issue 10: Incorrect encoding of packed fields when serialized
+
+===============================================================================
+RELEASE NOTES - Version 0.9.0
+===============================================================================
+
+- Initial release
+
+=============================================================================== \ No newline at end of file
diff --git a/third_party/protobuf/csharp/Google.Protobuf.Tools.nuspec b/third_party/protobuf/csharp/Google.Protobuf.Tools.nuspec
new file mode 100644
index 0000000000..0b9cbcf423
--- /dev/null
+++ b/third_party/protobuf/csharp/Google.Protobuf.Tools.nuspec
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<package>
+ <metadata>
+ <id>Google.Protobuf.Tools</id>
+ <title>Google Protocol Buffers tools</title>
+ <summary>Tools for Protocol Buffers - Google's data interchange format.</summary>
+ <description>See project site for more info.</description>
+ <version>3.2.0</version>
+ <authors>Google Inc.</authors>
+ <owners>protobuf-packages</owners>
+ <licenseUrl>https://github.com/google/protobuf/blob/master/LICENSE</licenseUrl>
+ <projectUrl>https://github.com/google/protobuf</projectUrl>
+ <requireLicenseAcceptance>false</requireLicenseAcceptance>
+ <releaseNotes>Tools for Protocol Buffers</releaseNotes>
+ <copyright>Copyright 2015, Google Inc.</copyright>
+ <tags>Protocol Buffers Binary Serialization Format Google proto proto3</tags>
+ </metadata>
+ <files>
+ <file src="protoc\windows_x86\protoc.exe" target="tools\windows_x86\protoc.exe" />
+ <file src="protoc\windows_x64\protoc.exe" target="tools\windows_x64\protoc.exe" />
+ <file src="protoc\linux_x86\protoc" target="tools\linux_x86\protoc" />
+ <file src="protoc\linux_x64\protoc" target="tools\linux_x64\protoc" />
+ <file src="protoc\macosx_x86\protoc" target="tools\macosx_x86\protoc" />
+ <file src="protoc\macosx_x64\protoc" target="tools\macosx_x64\protoc" />
+ <file src="..\src\google\protobuf\any.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\api.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\descriptor.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\duration.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\empty.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\field_mask.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\source_context.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\struct.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\timestamp.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\type.proto" target="tools\google\protobuf" />
+ <file src="..\src\google\protobuf\wrappers.proto" target="tools\google\protobuf" />
+ </files>
+</package>
diff --git a/third_party/protobuf/csharp/README.md b/third_party/protobuf/csharp/README.md
new file mode 100644
index 0000000000..65d2311fff
--- /dev/null
+++ b/third_party/protobuf/csharp/README.md
@@ -0,0 +1,117 @@
+This directory contains the C# Protocol Buffers runtime library.
+
+Usage
+=====
+
+The easiest way how to use C# protobufs is via the `Google.Protobuf`
+NuGet package. Just add the NuGet package to your VS project.
+
+You will also want to install the `Google.Protobuf.Tools` NuGet package, which
+contains precompiled version of `protoc.exe` and a copy of well known `.proto`
+files under the package's `tools` directory.
+
+To generate C# files from your `.proto` files, invoke `protoc` with the
+`--csharp_out` option.
+
+Supported platforms
+===================
+
+The runtime library is built as a portable class library, supporting:
+
+- .NET 4.5
+- Windows 8
+- Windows Phone Silverlight 8
+- Windows Phone 8.1
+- .NET Core
+
+You should be able to use Protocol Buffers in Visual Studio 2012 and
+all later versions. This includes all code generated by `protoc`,
+which only uses features from C# 3 and earlier.
+
+Building
+========
+
+Open the `src/Google.Protobuf.sln` solution in Visual Studio 2015 or
+later.
+
+Although *users* of this project are only expected to have Visual
+Studio 2012 or later, *developers* of the library are required to
+have Visual Studio 2015 or later, as the library uses C# 6 features
+in its implementation. These features have no impact when using the
+compiled code - they're only relevant when building the
+`Google.Protobuf` assembly.
+
+Testing
+=======
+
+The unit tests use [NUnit 3](https://github.com/nunit/nunit). Vanilla NUnit doesn't
+support .NET Core, so to run the tests you'll need to use
+[dotnet-test-nunit](https://github.com/nunit/dotnet-test-nunit).
+`dotnet-test-nunit` can also run tests for .NET 4.5+, so to run the tests
+for both .NET Core and .NET 4.5, you can simply open the
+`Package Manager Console` in Visual Studio and execute:
+```
+dotnet test Google.Protobuf.Test
+```
+
+.NET 3.5
+========
+
+We don't officially support .NET 3.5. However, there has been some effort
+to make enabling .NET 3.5 support relatively painless in case you require it.
+There's no guarantee that this will continue in the future, so rely on .NET
+3.5 support at your peril.
+
+To enable .NET 3.5 support:
+
+1. Modify [src/Google.Protobuf/project.json](src/Google.Protobuf/project.json) to add `"net35": {}` to `"frameworks"`.
+2. Modify [src/Google.Protobuf.Test/project.json](src/Google.Protobuf/project.json):
+ 1. Add `"net35": {}` to `"frameworks"`.
+ 2. `dotnet-test-nunit` doesn't support .NET 3.5, so remove it from
+ the project-wide `"dependencies"` and add it to the framework-specific
+ dependencies under `"net451"` and `"netcoreapp1.0"`.
+
+Note that `dotnet-test-nunit` doesn't support .NET 3.5. You can instead run the
+tests with [NUnit 3 console](https://github.com/nunit/nunit-console)
+by running something like:
+```
+nunit3-console.exe "Google.Protobuf.Test\bin\Debug\net35\win7-x64\Google.Protobuf.Test.dll" --inprocess
+```
+
+The exact path may differ depending on your environment (e.g., the `win7-x64`
+directory may be called something else). The `--inprocess` flag seems to be a
+necessary workaround for a bug in NUnit; otherwise, you'll receive
+an error "Exception has been thrown by the target of an invocation"
+([possibly related issue](https://github.com/nunit/nunit/issues/1480)).
+
+If you still want to run the .NET 4.5 and .NET Core tests, you can do so by
+specifying the framework when using `dotnet-test-nunit`, i.e. from
+`Package Manager Console` in Visual Studio:
+```
+dotnet test Google.Protobuf.Test --framework netcoreapp1.0
+dotnet test Google.Protobuf.Test --framework net451
+```
+
+History of C# protobufs
+=======================
+
+This subtree was originally imported from https://github.com/jskeet/protobuf-csharp-port
+and represents the latest development version of C# protobufs, that will now be developed
+and maintained by Google. All the development will be done in open, under this repository
+(https://github.com/google/protobuf).
+
+The previous project differs from this project in a number of ways:
+
+- The old code only supported proto2; the new code only supports
+proto3 (so no unknown fields, no required/optional distinction, no
+extensions)
+- The old code was based on immutable message types and builders for
+them
+- The old code did not support maps or `oneof`
+- The old code had its own JSON representation, whereas the new code
+uses the standard protobuf JSON representation
+- The old code had no notion of the "well-known types" which have
+special support in the new code
+- The old project supported some older platforms (such as older
+versions of Silverlight) which are not currently supported in the
+new project
diff --git a/third_party/protobuf/csharp/build_packages.bat b/third_party/protobuf/csharp/build_packages.bat
new file mode 100644
index 0000000000..37732e7c66
--- /dev/null
+++ b/third_party/protobuf/csharp/build_packages.bat
@@ -0,0 +1,10 @@
+@rem Builds Google.Protobuf NuGet packages
+
+dotnet restore src
+dotnet pack -c Release src\Google.Protobuf || goto :error
+
+goto :EOF
+
+:error
+echo Failed!
+exit /b %errorlevel%
diff --git a/third_party/protobuf/csharp/build_tools.sh b/third_party/protobuf/csharp/build_tools.sh
new file mode 100755
index 0000000000..182c5c5c82
--- /dev/null
+++ b/third_party/protobuf/csharp/build_tools.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+if [ $# -ne 1 ]; then
+ cat <<EOF
+Usage: $0 <VERSION_NUMBER>
+
+Example:
+ $ $0 3.0.0
+
+This script will download pre-built protoc binaries from maven repository and
+create the Google.Protobuf.Tools package. Well-known type .proto files will also
+be included.
+EOF
+ exit 1
+fi
+
+VERSION_NUMBER=$1
+# <directory name> <binary file name> pairs.
+declare -a FILE_NAMES=( \
+ windows_x86 windows-x86_32.exe \
+ windows_x64 windows-x86_64.exe \
+ macosx_x86 osx-x86_32.exe \
+ macosx_x64 osx-x86_64.exe \
+ linux_x86 linux-x86_32.exe \
+ linux_x64 linux-x86_64.exe \
+)
+
+set -e
+
+mkdir -p protoc
+# Create a zip file for each binary.
+for((i=0;i<${#FILE_NAMES[@]};i+=2));do
+ DIR_NAME=${FILE_NAMES[$i]}
+ mkdir -p protoc/$DIR_NAME
+
+ if [ ${DIR_NAME:0:3} = "win" ]; then
+ TARGET_BINARY="protoc.exe"
+ else
+ TARGET_BINARY="protoc"
+ fi
+
+ BINARY_NAME=${FILE_NAMES[$(($i+1))]}
+ BINARY_URL=http://repo1.maven.org/maven2/com/google/protobuf/protoc/${VERSION_NUMBER}/protoc-${VERSION_NUMBER}-${BINARY_NAME}
+
+ if ! wget ${BINARY_URL} -O protoc/$DIR_NAME/$TARGET_BINARY &> /dev/null; then
+ echo "[ERROR] Failed to download ${BINARY_URL}" >&2
+ echo "[ERROR] Skipped $protoc-${VERSION_NAME}-${DIR_NAME}" >&2
+ continue
+ fi
+done
+
+nuget pack Google.Protobuf.Tools.nuspec
diff --git a/third_party/protobuf/csharp/buildall.sh b/third_party/protobuf/csharp/buildall.sh
new file mode 100755
index 0000000000..cab3222992
--- /dev/null
+++ b/third_party/protobuf/csharp/buildall.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+CONFIG=Release
+SRC=$(dirname $0)/src
+
+set -ex
+
+echo Building relevant projects.
+dotnet build -c $CONFIG $SRC/Google.Protobuf $SRC/Google.Protobuf.Test $SRC/Google.Protobuf.Conformance
+
+echo Running tests.
+# Only test netcoreapp1.0, which uses the .NET Core runtime.
+# If we want to test the .NET 4.5 version separately, we could
+# run Mono explicitly. However, we don't have any differences between
+# the .NET 4.5 and netstandard1.0 assemblies.
+dotnet test -c $CONFIG -f netcoreapp1.0 $SRC/Google.Protobuf.Test
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/csharp/protos/unittest_issues.proto b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/csharp/protos/unittest_issues.proto
new file mode 100644
index 0000000000..6c9f76344a
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/csharp/protos/unittest_issues.proto
@@ -0,0 +1,126 @@
+syntax = "proto3";
+
+// These proto descriptors have at one time been reported as an issue or defect.
+// They are kept here to replicate the issue, and continue to verify the fix.
+
+// Issue: Non-"Google.Protobuffers" namespace will ensure that protobuffer library types are qualified
+option csharp_namespace = "UnitTest.Issues.TestProtos";
+
+package unittest_issues;
+option optimize_for = SPEED;
+
+// Issue 307: when generating doubly-nested types, any references
+// should be of the form A.Types.B.Types.C.
+message Issue307 {
+ message NestedOnce {
+ message NestedTwice {
+ }
+ }
+}
+
+// Old issue 13: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=13
+// New issue 309: https://github.com/google/protobuf/issues/309
+
+// message A {
+// optional int32 _A = 1;
+// }
+
+// message B {
+// optional int32 B_ = 1;
+// }
+
+//message AB {
+// optional int32 a_b = 1;
+//}
+
+// Similar issue with numeric names
+// Java code failed too, so probably best for this to be a restriction.
+// See https://github.com/google/protobuf/issues/308
+// message NumberField {
+// optional int32 _01 = 1;
+// }
+
+// issue 19 - negative enum values
+
+enum NegativeEnum {
+ NEGATIVE_ENUM_ZERO = 0;
+ FiveBelow = -5;
+ MinusOne = -1;
+}
+
+message NegativeEnumMessage {
+ NegativeEnum value = 1;
+ repeated NegativeEnum values = 2 [packed = false];
+ repeated NegativeEnum packed_values = 3 [packed=true];
+}
+
+// Issue 21: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=21
+// Decorate fields with [deprecated=true] as [System.Obsolete]
+
+message DeprecatedChild {
+}
+
+enum DeprecatedEnum {
+ DEPRECATED_ZERO = 0;
+ one = 1;
+}
+
+message DeprecatedFieldsMessage {
+ int32 PrimitiveValue = 1 [deprecated = true];
+ repeated int32 PrimitiveArray = 2 [deprecated = true];
+
+ DeprecatedChild MessageValue = 3 [deprecated = true];
+ repeated DeprecatedChild MessageArray = 4 [deprecated = true];
+
+ DeprecatedEnum EnumValue = 5 [deprecated = true];
+ repeated DeprecatedEnum EnumArray = 6 [deprecated = true];
+}
+
+// Issue 45: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=45
+message ItemField {
+ int32 item = 1;
+}
+
+message ReservedNames {
+ // Force a nested type called Types
+ message SomeNestedType {
+ }
+
+ int32 types = 1;
+ int32 descriptor = 2;
+}
+
+message TestJsonFieldOrdering {
+ // These fields are deliberately not declared in numeric
+ // order, and the oneof fields aren't contiguous either.
+ // This allows for reasonably robust tests of JSON output
+ // ordering.
+ // TestFieldOrderings in unittest_proto3.proto is similar,
+ // but doesn't include oneofs.
+ // TODO: Consider adding oneofs to TestFieldOrderings, although
+ // that will require fixing other tests in multiple platforms.
+ // Alternatively, consider just adding this to
+ // unittest_proto3.proto if multiple platforms want it.
+
+ int32 plain_int32 = 4;
+
+ oneof o1 {
+ string o1_string = 2;
+ int32 o1_int32 = 5;
+ }
+
+ string plain_string = 1;
+
+ oneof o2 {
+ int32 o2_int32 = 6;
+ string o2_string = 3;
+ }
+
+}
+
+message TestJsonName {
+ // Message for testing the effects for of the json_name option
+ string name = 1;
+ string description = 2 [json_name = "desc"];
+ string guid = 3 [json_name = "exid"];
+}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_unittest_proto3.proto b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/map_unittest_proto3.proto
index 16be277304..16be277304 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_unittest_proto3.proto
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/map_unittest_proto3.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_import_proto3.proto b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/unittest_import_proto3.proto
index 59673eaf9d..59673eaf9d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_import_proto3.proto
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/unittest_import_proto3.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_import_public_proto3.proto b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/unittest_import_public_proto3.proto
index d6f11e28bd..d6f11e28bd 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_import_public_proto3.proto
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/unittest_import_public_proto3.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_proto3.proto b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/unittest_proto3.proto
index f59d217864..f59d217864 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_proto3.proto
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/unittest_proto3.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_well_known_types.proto b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/unittest_well_known_types.proto
index c90752440b..c90752440b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_well_known_types.proto
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/protos/src/google/protobuf/unittest_well_known_types.proto
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/ByteStringTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/ByteStringTest.cs
new file mode 100644
index 0000000000..685e130a74
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/ByteStringTest.cs
@@ -0,0 +1,171 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.Text;
+using NUnit.Framework;
+
+namespace Google.Protobuf
+{
+ public class ByteStringTest
+ {
+ [Test]
+ public void Equality()
+ {
+ ByteString b1 = ByteString.CopyFrom(1, 2, 3);
+ ByteString b2 = ByteString.CopyFrom(1, 2, 3);
+ ByteString b3 = ByteString.CopyFrom(1, 2, 4);
+ ByteString b4 = ByteString.CopyFrom(1, 2, 3, 4);
+ EqualityTester.AssertEquality(b1, b1);
+ EqualityTester.AssertEquality(b1, b2);
+ EqualityTester.AssertInequality(b1, b3);
+ EqualityTester.AssertInequality(b1, b4);
+ EqualityTester.AssertInequality(b1, null);
+#pragma warning disable 1718 // Deliberately calling ==(b1, b1) and !=(b1, b1)
+ Assert.IsTrue(b1 == b1);
+ Assert.IsTrue(b1 == b2);
+ Assert.IsFalse(b1 == b3);
+ Assert.IsFalse(b1 == b4);
+ Assert.IsFalse(b1 == null);
+ Assert.IsTrue((ByteString) null == null);
+ Assert.IsFalse(b1 != b1);
+ Assert.IsFalse(b1 != b2);
+#pragma warning disable 1718
+ Assert.IsTrue(b1 != b3);
+ Assert.IsTrue(b1 != b4);
+ Assert.IsTrue(b1 != null);
+ Assert.IsFalse((ByteString) null != null);
+ }
+
+ [Test]
+ public void EmptyByteStringHasZeroSize()
+ {
+ Assert.AreEqual(0, ByteString.Empty.Length);
+ }
+
+ [Test]
+ public void CopyFromStringWithExplicitEncoding()
+ {
+ ByteString bs = ByteString.CopyFrom("AB", Encoding.Unicode);
+ Assert.AreEqual(4, bs.Length);
+ Assert.AreEqual(65, bs[0]);
+ Assert.AreEqual(0, bs[1]);
+ Assert.AreEqual(66, bs[2]);
+ Assert.AreEqual(0, bs[3]);
+ }
+
+ [Test]
+ public void IsEmptyWhenEmpty()
+ {
+ Assert.IsTrue(ByteString.CopyFromUtf8("").IsEmpty);
+ }
+
+ [Test]
+ public void IsEmptyWhenNotEmpty()
+ {
+ Assert.IsFalse(ByteString.CopyFromUtf8("X").IsEmpty);
+ }
+
+ [Test]
+ public void CopyFromByteArrayCopiesContents()
+ {
+ byte[] data = new byte[1];
+ data[0] = 10;
+ ByteString bs = ByteString.CopyFrom(data);
+ Assert.AreEqual(10, bs[0]);
+ data[0] = 5;
+ Assert.AreEqual(10, bs[0]);
+ }
+
+ [Test]
+ public void ToByteArrayCopiesContents()
+ {
+ ByteString bs = ByteString.CopyFromUtf8("Hello");
+ byte[] data = bs.ToByteArray();
+ Assert.AreEqual((byte)'H', data[0]);
+ Assert.AreEqual((byte)'H', bs[0]);
+ data[0] = 0;
+ Assert.AreEqual(0, data[0]);
+ Assert.AreEqual((byte)'H', bs[0]);
+ }
+
+ [Test]
+ public void CopyFromUtf8UsesUtf8()
+ {
+ ByteString bs = ByteString.CopyFromUtf8("\u20ac");
+ Assert.AreEqual(3, bs.Length);
+ Assert.AreEqual(0xe2, bs[0]);
+ Assert.AreEqual(0x82, bs[1]);
+ Assert.AreEqual(0xac, bs[2]);
+ }
+
+ [Test]
+ public void CopyFromPortion()
+ {
+ byte[] data = new byte[] {0, 1, 2, 3, 4, 5, 6};
+ ByteString bs = ByteString.CopyFrom(data, 2, 3);
+ Assert.AreEqual(3, bs.Length);
+ Assert.AreEqual(2, bs[0]);
+ Assert.AreEqual(3, bs[1]);
+ }
+
+ [Test]
+ public void ToStringUtf8()
+ {
+ ByteString bs = ByteString.CopyFromUtf8("\u20ac");
+ Assert.AreEqual("\u20ac", bs.ToStringUtf8());
+ }
+
+ [Test]
+ public void ToStringWithExplicitEncoding()
+ {
+ ByteString bs = ByteString.CopyFrom("\u20ac", Encoding.Unicode);
+ Assert.AreEqual("\u20ac", bs.ToString(Encoding.Unicode));
+ }
+
+ [Test]
+ public void FromBase64_WithText()
+ {
+ byte[] data = new byte[] {0, 1, 2, 3, 4, 5, 6};
+ string base64 = Convert.ToBase64String(data);
+ ByteString bs = ByteString.FromBase64(base64);
+ Assert.AreEqual(data, bs.ToByteArray());
+ }
+
+ [Test]
+ public void FromBase64_Empty()
+ {
+ // Optimization which also fixes issue 61.
+ Assert.AreSame(ByteString.Empty, ByteString.FromBase64(""));
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedInputStreamExtensions.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedInputStreamExtensions.cs
new file mode 100644
index 0000000000..23af28870a
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedInputStreamExtensions.cs
@@ -0,0 +1,53 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using NUnit.Framework;
+
+namespace Google.Protobuf
+{
+ internal static class CodedInputStreamExtensions
+ {
+ public static void AssertNextTag(this CodedInputStream input, uint expectedTag)
+ {
+ uint tag = input.ReadTag();
+ Assert.AreEqual(expectedTag, tag);
+ }
+
+ public static T ReadMessage<T>(this CodedInputStream stream, MessageParser<T> parser)
+ where T : IMessage<T>
+ {
+ var message = parser.CreateTemplate();
+ stream.ReadMessage(message);
+ return message;
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedInputStreamTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedInputStreamTest.cs
new file mode 100644
index 0000000000..c0a9ffd124
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedInputStreamTest.cs
@@ -0,0 +1,598 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.IO;
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+
+namespace Google.Protobuf
+{
+ public class CodedInputStreamTest
+ {
+ /// <summary>
+ /// 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.
+ /// </summary>
+ private static byte[] Bytes(params int[] bytesAsInts)
+ {
+ byte[] bytes = new byte[bytesAsInts.Length];
+ for (int i = 0; i < bytesAsInts.Length; i++)
+ {
+ bytes[i] = (byte) bytesAsInts[i];
+ }
+ return bytes;
+ }
+
+ /// <summary>
+ /// Parses the given bytes using ReadRawVarint32() and ReadRawVarint64()
+ /// </summary>
+ private static void AssertReadVarint(byte[] data, ulong value)
+ {
+ CodedInputStream input = new CodedInputStream(data);
+ Assert.AreEqual((uint) value, input.ReadRawVarint32());
+
+ input = new CodedInputStream(data);
+ Assert.AreEqual(value, input.ReadRawVarint64());
+ Assert.IsTrue(input.IsAtEnd);
+
+ // Try different block sizes.
+ for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2)
+ {
+ input = new CodedInputStream(new SmallBlockInputStream(data, bufferSize));
+ Assert.AreEqual((uint) value, input.ReadRawVarint32());
+
+ input = new CodedInputStream(new SmallBlockInputStream(data, bufferSize));
+ Assert.AreEqual(value, input.ReadRawVarint64());
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ // Try reading directly from a MemoryStream. We want to verify that it
+ // doesn't read past the end of the input, so write an extra byte - this
+ // lets us test the position at the end.
+ MemoryStream memoryStream = new MemoryStream();
+ memoryStream.Write(data, 0, data.Length);
+ memoryStream.WriteByte(0);
+ memoryStream.Position = 0;
+ Assert.AreEqual((uint) value, CodedInputStream.ReadRawVarint32(memoryStream));
+ Assert.AreEqual(data.Length, memoryStream.Position);
+ }
+
+ /// <summary>
+ /// Parses the given bytes using ReadRawVarint32() and ReadRawVarint64() and
+ /// expects them to fail with an InvalidProtocolBufferException whose
+ /// description matches the given one.
+ /// </summary>
+ private static void AssertReadVarintFailure(InvalidProtocolBufferException expected, byte[] data)
+ {
+ CodedInputStream input = new CodedInputStream(data);
+ var exception = Assert.Throws<InvalidProtocolBufferException>(() => input.ReadRawVarint32());
+ Assert.AreEqual(expected.Message, exception.Message);
+
+ input = new CodedInputStream(data);
+ exception = Assert.Throws<InvalidProtocolBufferException>(() => input.ReadRawVarint64());
+ Assert.AreEqual(expected.Message, exception.Message);
+
+ // Make sure we get the same error when reading directly from a Stream.
+ exception = Assert.Throws<InvalidProtocolBufferException>(() => CodedInputStream.ReadRawVarint32(new MemoryStream(data)));
+ Assert.AreEqual(expected.Message, exception.Message);
+ }
+
+ [Test]
+ public void ReadVarint()
+ {
+ AssertReadVarint(Bytes(0x00), 0);
+ AssertReadVarint(Bytes(0x01), 1);
+ AssertReadVarint(Bytes(0x7f), 127);
+ // 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));
+
+ // 64-bit
+ // 7256456126
+ 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));
+ // 11964378330978735131
+ AssertReadVarint(Bytes(0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85, 0xa6, 0x01),
+ (0x1b << 0) | (0x28 << 7) | (0x79 << 14) | (0x42 << 21) |
+ (0x3bUL << 28) | (0x56UL << 35) | (0x00UL << 42) |
+ (0x05UL << 49) | (0x26UL << 56) | (0x01UL << 63));
+
+ // Failures
+ AssertReadVarintFailure(
+ InvalidProtocolBufferException.MalformedVarint(),
+ Bytes(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+ 0x00));
+ AssertReadVarintFailure(
+ InvalidProtocolBufferException.TruncatedMessage(),
+ Bytes(0x80));
+ }
+
+ /// <summary>
+ /// Parses the given bytes using ReadRawLittleEndian32() and checks
+ /// that the result matches the given value.
+ /// </summary>
+ private static void AssertReadLittleEndian32(byte[] data, uint value)
+ {
+ CodedInputStream input = new CodedInputStream(data);
+ Assert.AreEqual(value, input.ReadRawLittleEndian32());
+ Assert.IsTrue(input.IsAtEnd);
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2)
+ {
+ input = new CodedInputStream(
+ new SmallBlockInputStream(data, blockSize));
+ Assert.AreEqual(value, input.ReadRawLittleEndian32());
+ Assert.IsTrue(input.IsAtEnd);
+ }
+ }
+
+ /// <summary>
+ /// Parses the given bytes using ReadRawLittleEndian64() and checks
+ /// that the result matches the given value.
+ /// </summary>
+ private static void AssertReadLittleEndian64(byte[] data, ulong value)
+ {
+ CodedInputStream input = new CodedInputStream(data);
+ Assert.AreEqual(value, input.ReadRawLittleEndian64());
+ Assert.IsTrue(input.IsAtEnd);
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2)
+ {
+ input = new CodedInputStream(
+ new SmallBlockInputStream(data, blockSize));
+ Assert.AreEqual(value, input.ReadRawLittleEndian64());
+ Assert.IsTrue(input.IsAtEnd);
+ }
+ }
+
+ [Test]
+ public void ReadLittleEndian()
+ {
+ AssertReadLittleEndian32(Bytes(0x78, 0x56, 0x34, 0x12), 0x12345678);
+ AssertReadLittleEndian32(Bytes(0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef0);
+
+ AssertReadLittleEndian64(Bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12),
+ 0x123456789abcdef0L);
+ AssertReadLittleEndian64(
+ Bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef012345678UL);
+ }
+
+ [Test]
+ public void DecodeZigZag32()
+ {
+ Assert.AreEqual(0, CodedInputStream.DecodeZigZag32(0));
+ Assert.AreEqual(-1, CodedInputStream.DecodeZigZag32(1));
+ Assert.AreEqual(1, CodedInputStream.DecodeZigZag32(2));
+ Assert.AreEqual(-2, CodedInputStream.DecodeZigZag32(3));
+ Assert.AreEqual(0x3FFFFFFF, CodedInputStream.DecodeZigZag32(0x7FFFFFFE));
+ Assert.AreEqual(unchecked((int) 0xC0000000), CodedInputStream.DecodeZigZag32(0x7FFFFFFF));
+ Assert.AreEqual(0x7FFFFFFF, CodedInputStream.DecodeZigZag32(0xFFFFFFFE));
+ Assert.AreEqual(unchecked((int) 0x80000000), CodedInputStream.DecodeZigZag32(0xFFFFFFFF));
+ }
+
+ [Test]
+ public void DecodeZigZag64()
+ {
+ Assert.AreEqual(0, CodedInputStream.DecodeZigZag64(0));
+ Assert.AreEqual(-1, CodedInputStream.DecodeZigZag64(1));
+ Assert.AreEqual(1, CodedInputStream.DecodeZigZag64(2));
+ Assert.AreEqual(-2, CodedInputStream.DecodeZigZag64(3));
+ Assert.AreEqual(0x000000003FFFFFFFL, CodedInputStream.DecodeZigZag64(0x000000007FFFFFFEL));
+ Assert.AreEqual(unchecked((long) 0xFFFFFFFFC0000000L), CodedInputStream.DecodeZigZag64(0x000000007FFFFFFFL));
+ Assert.AreEqual(0x000000007FFFFFFFL, CodedInputStream.DecodeZigZag64(0x00000000FFFFFFFEL));
+ Assert.AreEqual(unchecked((long) 0xFFFFFFFF80000000L), CodedInputStream.DecodeZigZag64(0x00000000FFFFFFFFL));
+ Assert.AreEqual(0x7FFFFFFFFFFFFFFFL, CodedInputStream.DecodeZigZag64(0xFFFFFFFFFFFFFFFEL));
+ Assert.AreEqual(unchecked((long) 0x8000000000000000L), CodedInputStream.DecodeZigZag64(0xFFFFFFFFFFFFFFFFL));
+ }
+
+ [Test]
+ public void ReadWholeMessage_VaryingBlockSizes()
+ {
+ TestAllTypes message = SampleMessages.CreateFullTestAllTypes();
+
+ byte[] rawBytes = message.ToByteArray();
+ Assert.AreEqual(rawBytes.Length, message.CalculateSize());
+ TestAllTypes message2 = TestAllTypes.Parser.ParseFrom(rawBytes);
+ Assert.AreEqual(message, message2);
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize < 256; blockSize *= 2)
+ {
+ message2 = TestAllTypes.Parser.ParseFrom(new SmallBlockInputStream(rawBytes, blockSize));
+ Assert.AreEqual(message, message2);
+ }
+ }
+
+ [Test]
+ public void ReadHugeBlob()
+ {
+ // Allocate and initialize a 1MB blob.
+ byte[] blob = new byte[1 << 20];
+ for (int i = 0; i < blob.Length; i++)
+ {
+ blob[i] = (byte) i;
+ }
+
+ // Make a message containing it.
+ var message = new TestAllTypes { SingleBytes = ByteString.CopyFrom(blob) };
+
+ // 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.Parser.ParseFrom(message.ToByteString());
+
+ Assert.AreEqual(message, message2);
+ }
+
+ [Test]
+ public void ReadMaliciouslyLargeBlob()
+ {
+ MemoryStream ms = new MemoryStream();
+ CodedOutputStream output = new CodedOutputStream(ms);
+
+ uint tag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited);
+ output.WriteRawVarint32(tag);
+ output.WriteRawVarint32(0x7FFFFFFF);
+ output.WriteRawBytes(new byte[32]); // Pad with a few random bytes.
+ output.Flush();
+ ms.Position = 0;
+
+ CodedInputStream input = new CodedInputStream(ms);
+ Assert.AreEqual(tag, input.ReadTag());
+
+ Assert.Throws<InvalidProtocolBufferException>(() => input.ReadBytes());
+ }
+
+ internal static TestRecursiveMessage MakeRecursiveMessage(int depth)
+ {
+ if (depth == 0)
+ {
+ return new TestRecursiveMessage { I = 5 };
+ }
+ else
+ {
+ return new TestRecursiveMessage { A = MakeRecursiveMessage(depth - 1) };
+ }
+ }
+
+ internal static void AssertMessageDepth(TestRecursiveMessage message, int depth)
+ {
+ if (depth == 0)
+ {
+ Assert.IsNull(message.A);
+ Assert.AreEqual(5, message.I);
+ }
+ else
+ {
+ Assert.IsNotNull(message.A);
+ AssertMessageDepth(message.A, depth - 1);
+ }
+ }
+
+ [Test]
+ public void MaliciousRecursion()
+ {
+ ByteString data64 = MakeRecursiveMessage(64).ToByteString();
+ ByteString data65 = MakeRecursiveMessage(65).ToByteString();
+
+ AssertMessageDepth(TestRecursiveMessage.Parser.ParseFrom(data64), 64);
+
+ Assert.Throws<InvalidProtocolBufferException>(() => TestRecursiveMessage.Parser.ParseFrom(data65));
+
+ CodedInputStream input = CodedInputStream.CreateWithLimits(new MemoryStream(data64.ToByteArray()), 1000000, 63);
+ Assert.Throws<InvalidProtocolBufferException>(() => TestRecursiveMessage.Parser.ParseFrom(input));
+ }
+
+ [Test]
+ public void SizeLimit()
+ {
+ // Have to use a Stream rather than ByteString.CreateCodedInput as SizeLimit doesn't
+ // apply to the latter case.
+ MemoryStream ms = new MemoryStream(SampleMessages.CreateFullTestAllTypes().ToByteArray());
+ CodedInputStream input = CodedInputStream.CreateWithLimits(ms, 16, 100);
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseFrom(input));
+ }
+
+ /// <summary>
+ /// Tests that if we read an string that contains invalid UTF-8, no exception
+ /// is thrown. Instead, the invalid bytes are replaced with the Unicode
+ /// "replacement character" U+FFFD.
+ /// </summary>
+ [Test]
+ public void ReadInvalidUtf8()
+ {
+ MemoryStream ms = new MemoryStream();
+ CodedOutputStream output = new CodedOutputStream(ms);
+
+ uint tag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited);
+ output.WriteRawVarint32(tag);
+ output.WriteRawVarint32(1);
+ output.WriteRawBytes(new byte[] {0x80});
+ output.Flush();
+ ms.Position = 0;
+
+ CodedInputStream input = new CodedInputStream(ms);
+
+ Assert.AreEqual(tag, input.ReadTag());
+ string text = input.ReadString();
+ Assert.AreEqual('\ufffd', text[0]);
+ }
+
+ /// <summary>
+ /// A stream 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.
+ /// </summary>
+ private sealed class SmallBlockInputStream : MemoryStream
+ {
+ private readonly int blockSize;
+
+ public SmallBlockInputStream(byte[] data, int blockSize)
+ : base(data)
+ {
+ this.blockSize = blockSize;
+ }
+
+ public override int Read(byte[] buffer, int offset, int count)
+ {
+ return base.Read(buffer, offset, Math.Min(count, blockSize));
+ }
+ }
+
+ [Test]
+ public void TestNegativeEnum()
+ {
+ byte[] bytes = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01 };
+ CodedInputStream input = new CodedInputStream(bytes);
+ Assert.AreEqual((int)SampleEnum.NegativeValue, input.ReadEnum());
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ //Issue 71: CodedInputStream.ReadBytes go to slow path unnecessarily
+ [Test]
+ public void TestSlowPathAvoidance()
+ {
+ using (var ms = new MemoryStream())
+ {
+ CodedOutputStream output = new CodedOutputStream(ms);
+ output.WriteTag(1, WireFormat.WireType.LengthDelimited);
+ output.WriteBytes(ByteString.CopyFrom(new byte[100]));
+ output.WriteTag(2, WireFormat.WireType.LengthDelimited);
+ output.WriteBytes(ByteString.CopyFrom(new byte[100]));
+ output.Flush();
+
+ ms.Position = 0;
+ CodedInputStream input = new CodedInputStream(ms, new byte[ms.Length / 2], 0, 0);
+
+ uint tag = input.ReadTag();
+ Assert.AreEqual(1, WireFormat.GetTagFieldNumber(tag));
+ Assert.AreEqual(100, input.ReadBytes().Length);
+
+ tag = input.ReadTag();
+ Assert.AreEqual(2, WireFormat.GetTagFieldNumber(tag));
+ Assert.AreEqual(100, input.ReadBytes().Length);
+ }
+ }
+
+ [Test]
+ public void Tag0Throws()
+ {
+ var input = new CodedInputStream(new byte[] { 0 });
+ Assert.Throws<InvalidProtocolBufferException>(() => input.ReadTag());
+ }
+
+ [Test]
+ public void SkipGroup()
+ {
+ // Create an output stream with a group in:
+ // Field 1: string "field 1"
+ // Field 2: group containing:
+ // Field 1: fixed int32 value 100
+ // Field 2: string "ignore me"
+ // Field 3: nested group containing
+ // Field 1: fixed int64 value 1000
+ // Field 3: string "field 3"
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ output.WriteTag(1, WireFormat.WireType.LengthDelimited);
+ output.WriteString("field 1");
+
+ // The outer group...
+ output.WriteTag(2, WireFormat.WireType.StartGroup);
+ output.WriteTag(1, WireFormat.WireType.Fixed32);
+ output.WriteFixed32(100);
+ output.WriteTag(2, WireFormat.WireType.LengthDelimited);
+ output.WriteString("ignore me");
+ // The nested group...
+ output.WriteTag(3, WireFormat.WireType.StartGroup);
+ output.WriteTag(1, WireFormat.WireType.Fixed64);
+ output.WriteFixed64(1000);
+ // Note: Not sure the field number is relevant for end group...
+ output.WriteTag(3, WireFormat.WireType.EndGroup);
+
+ // End the outer group
+ output.WriteTag(2, WireFormat.WireType.EndGroup);
+
+ output.WriteTag(3, WireFormat.WireType.LengthDelimited);
+ output.WriteString("field 3");
+ output.Flush();
+ stream.Position = 0;
+
+ // Now act like a generated client
+ var input = new CodedInputStream(stream);
+ Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited), input.ReadTag());
+ Assert.AreEqual("field 1", input.ReadString());
+ Assert.AreEqual(WireFormat.MakeTag(2, WireFormat.WireType.StartGroup), input.ReadTag());
+ input.SkipLastField(); // Should consume the whole group, including the nested one.
+ Assert.AreEqual(WireFormat.MakeTag(3, WireFormat.WireType.LengthDelimited), input.ReadTag());
+ Assert.AreEqual("field 3", input.ReadString());
+ }
+
+ [Test]
+ public void SkipGroup_WrongEndGroupTag()
+ {
+ // Create an output stream with:
+ // Field 1: string "field 1"
+ // Start group 2
+ // Field 3: fixed int32
+ // End group 4 (should give an error)
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ output.WriteTag(1, WireFormat.WireType.LengthDelimited);
+ output.WriteString("field 1");
+
+ // The outer group...
+ output.WriteTag(2, WireFormat.WireType.StartGroup);
+ output.WriteTag(3, WireFormat.WireType.Fixed32);
+ output.WriteFixed32(100);
+ output.WriteTag(4, WireFormat.WireType.EndGroup);
+ output.Flush();
+ stream.Position = 0;
+
+ // Now act like a generated client
+ var input = new CodedInputStream(stream);
+ Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited), input.ReadTag());
+ Assert.AreEqual("field 1", input.ReadString());
+ Assert.AreEqual(WireFormat.MakeTag(2, WireFormat.WireType.StartGroup), input.ReadTag());
+ Assert.Throws<InvalidProtocolBufferException>(input.SkipLastField);
+ }
+
+ [Test]
+ public void RogueEndGroupTag()
+ {
+ // If we have an end-group tag without a leading start-group tag, generated
+ // code will just call SkipLastField... so that should fail.
+
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ output.WriteTag(1, WireFormat.WireType.EndGroup);
+ output.Flush();
+ stream.Position = 0;
+
+ var input = new CodedInputStream(stream);
+ Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.EndGroup), input.ReadTag());
+ Assert.Throws<InvalidProtocolBufferException>(input.SkipLastField);
+ }
+
+ [Test]
+ public void EndOfStreamReachedWhileSkippingGroup()
+ {
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ output.WriteTag(1, WireFormat.WireType.StartGroup);
+ output.WriteTag(2, WireFormat.WireType.StartGroup);
+ output.WriteTag(2, WireFormat.WireType.EndGroup);
+
+ output.Flush();
+ stream.Position = 0;
+
+ // Now act like a generated client
+ var input = new CodedInputStream(stream);
+ input.ReadTag();
+ Assert.Throws<InvalidProtocolBufferException>(input.SkipLastField);
+ }
+
+ [Test]
+ public void RecursionLimitAppliedWhileSkippingGroup()
+ {
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ for (int i = 0; i < CodedInputStream.DefaultRecursionLimit + 1; i++)
+ {
+ output.WriteTag(1, WireFormat.WireType.StartGroup);
+ }
+ for (int i = 0; i < CodedInputStream.DefaultRecursionLimit + 1; i++)
+ {
+ output.WriteTag(1, WireFormat.WireType.EndGroup);
+ }
+ output.Flush();
+ stream.Position = 0;
+
+ // Now act like a generated client
+ var input = new CodedInputStream(stream);
+ Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.StartGroup), input.ReadTag());
+ Assert.Throws<InvalidProtocolBufferException>(input.SkipLastField);
+ }
+
+ [Test]
+ public void Construction_Invalid()
+ {
+ Assert.Throws<ArgumentNullException>(() => new CodedInputStream((byte[]) null));
+ Assert.Throws<ArgumentNullException>(() => new CodedInputStream(null, 0, 0));
+ Assert.Throws<ArgumentNullException>(() => new CodedInputStream((Stream) null));
+ Assert.Throws<ArgumentOutOfRangeException>(() => new CodedInputStream(new byte[10], 100, 0));
+ Assert.Throws<ArgumentOutOfRangeException>(() => new CodedInputStream(new byte[10], 5, 10));
+ }
+
+ [Test]
+ public void CreateWithLimits_InvalidLimits()
+ {
+ var stream = new MemoryStream();
+ Assert.Throws<ArgumentOutOfRangeException>(() => CodedInputStream.CreateWithLimits(stream, 0, 1));
+ Assert.Throws<ArgumentOutOfRangeException>(() => CodedInputStream.CreateWithLimits(stream, 1, 0));
+ }
+
+ [Test]
+ public void Dispose_DisposesUnderlyingStream()
+ {
+ var memoryStream = new MemoryStream();
+ Assert.IsTrue(memoryStream.CanRead);
+ using (var cis = new CodedInputStream(memoryStream))
+ {
+ }
+ Assert.IsFalse(memoryStream.CanRead); // Disposed
+ }
+
+ [Test]
+ public void Dispose_WithLeaveOpen()
+ {
+ var memoryStream = new MemoryStream();
+ Assert.IsTrue(memoryStream.CanRead);
+ using (var cis = new CodedInputStream(memoryStream, true))
+ {
+ }
+ Assert.IsTrue(memoryStream.CanRead); // We left the stream open
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedOutputStreamTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
new file mode 100644
index 0000000000..48bf6d6000
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
@@ -0,0 +1,419 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.IO;
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+
+namespace Google.Protobuf
+{
+ public class CodedOutputStreamTest
+ {
+ /// <summary>
+ /// Writes the given value using WriteRawVarint32() and WriteRawVarint64() and
+ /// checks that the result matches the given bytes
+ /// </summary>
+ private static void AssertWriteVarint(byte[] data, ulong value)
+ {
+ // Only do 32-bit write if the value fits in 32 bits.
+ if ((value >> 32) == 0)
+ {
+ MemoryStream rawOutput = new MemoryStream();
+ CodedOutputStream output = new CodedOutputStream(rawOutput);
+ output.WriteRawVarint32((uint) value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+ // Also try computing size.
+ Assert.AreEqual(data.Length, CodedOutputStream.ComputeRawVarint32Size((uint) value));
+ }
+
+ {
+ MemoryStream rawOutput = new MemoryStream();
+ CodedOutputStream output = new CodedOutputStream(rawOutput);
+ output.WriteRawVarint64(value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+
+ // Also try computing size.
+ Assert.AreEqual(data.Length, CodedOutputStream.ComputeRawVarint64Size(value));
+ }
+
+ // Try different buffer sizes.
+ for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2)
+ {
+ // Only do 32-bit write if the value fits in 32 bits.
+ if ((value >> 32) == 0)
+ {
+ MemoryStream rawOutput = new MemoryStream();
+ CodedOutputStream output =
+ new CodedOutputStream(rawOutput, bufferSize);
+ output.WriteRawVarint32((uint) value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+ }
+
+ {
+ MemoryStream rawOutput = new MemoryStream();
+ CodedOutputStream output = new CodedOutputStream(rawOutput, bufferSize);
+ output.WriteRawVarint64(value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+ }
+ }
+ }
+
+ /// <summary>
+ /// Tests WriteRawVarint32() and WriteRawVarint64()
+ /// </summary>
+ [Test]
+ public void WriteVarint()
+ {
+ AssertWriteVarint(new byte[] {0x00}, 0);
+ AssertWriteVarint(new byte[] {0x01}, 1);
+ AssertWriteVarint(new byte[] {0x7f}, 127);
+ // 14882
+ AssertWriteVarint(new byte[] {0xa2, 0x74}, (0x22 << 0) | (0x74 << 7));
+ // 2961488830
+ AssertWriteVarint(new byte[] {0xbe, 0xf7, 0x92, 0x84, 0x0b},
+ (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) |
+ (0x0bL << 28));
+
+ // 64-bit
+ // 7256456126
+ AssertWriteVarint(new byte[] {0xbe, 0xf7, 0x92, 0x84, 0x1b},
+ (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) |
+ (0x1bL << 28));
+ // 41256202580718336
+ AssertWriteVarint(
+ new byte[] {0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49},
+ (0x00 << 0) | (0x66 << 7) | (0x6b << 14) | (0x1c << 21) |
+ (0x43UL << 28) | (0x49L << 35) | (0x24UL << 42) | (0x49UL << 49));
+ // 11964378330978735131
+ AssertWriteVarint(
+ new byte[] {0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85, 0xa6, 0x01},
+ unchecked((ulong)
+ ((0x1b << 0) | (0x28 << 7) | (0x79 << 14) | (0x42 << 21) |
+ (0x3bL << 28) | (0x56L << 35) | (0x00L << 42) |
+ (0x05L << 49) | (0x26L << 56) | (0x01L << 63))));
+ }
+
+ /// <summary>
+ /// Parses the given bytes using WriteRawLittleEndian32() and checks
+ /// that the result matches the given value.
+ /// </summary>
+ private static void AssertWriteLittleEndian32(byte[] data, uint value)
+ {
+ MemoryStream rawOutput = new MemoryStream();
+ CodedOutputStream output = new CodedOutputStream(rawOutput);
+ output.WriteRawLittleEndian32(value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+
+ // Try different buffer sizes.
+ for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2)
+ {
+ rawOutput = new MemoryStream();
+ output = new CodedOutputStream(rawOutput, bufferSize);
+ output.WriteRawLittleEndian32(value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+ }
+ }
+
+ /// <summary>
+ /// Parses the given bytes using WriteRawLittleEndian64() and checks
+ /// that the result matches the given value.
+ /// </summary>
+ private static void AssertWriteLittleEndian64(byte[] data, ulong value)
+ {
+ MemoryStream rawOutput = new MemoryStream();
+ CodedOutputStream output = new CodedOutputStream(rawOutput);
+ output.WriteRawLittleEndian64(value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2)
+ {
+ rawOutput = new MemoryStream();
+ output = new CodedOutputStream(rawOutput, blockSize);
+ output.WriteRawLittleEndian64(value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+ }
+ }
+
+ /// <summary>
+ /// Tests writeRawLittleEndian32() and writeRawLittleEndian64().
+ /// </summary>
+ [Test]
+ public void WriteLittleEndian()
+ {
+ AssertWriteLittleEndian32(new byte[] {0x78, 0x56, 0x34, 0x12}, 0x12345678);
+ AssertWriteLittleEndian32(new byte[] {0xf0, 0xde, 0xbc, 0x9a}, 0x9abcdef0);
+
+ AssertWriteLittleEndian64(
+ new byte[] {0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12},
+ 0x123456789abcdef0L);
+ AssertWriteLittleEndian64(
+ new byte[] {0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a},
+ 0x9abcdef012345678UL);
+ }
+
+ [Test]
+ public void WriteWholeMessage_VaryingBlockSizes()
+ {
+ TestAllTypes message = SampleMessages.CreateFullTestAllTypes();
+
+ byte[] rawBytes = message.ToByteArray();
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize < 256; blockSize *= 2)
+ {
+ MemoryStream rawOutput = new MemoryStream();
+ CodedOutputStream output = new CodedOutputStream(rawOutput, blockSize);
+ message.WriteTo(output);
+ output.Flush();
+ Assert.AreEqual(rawBytes, rawOutput.ToArray());
+ }
+ }
+
+ [Test]
+ public void EncodeZigZag32()
+ {
+ Assert.AreEqual(0u, CodedOutputStream.EncodeZigZag32(0));
+ Assert.AreEqual(1u, CodedOutputStream.EncodeZigZag32(-1));
+ Assert.AreEqual(2u, CodedOutputStream.EncodeZigZag32(1));
+ Assert.AreEqual(3u, CodedOutputStream.EncodeZigZag32(-2));
+ Assert.AreEqual(0x7FFFFFFEu, CodedOutputStream.EncodeZigZag32(0x3FFFFFFF));
+ Assert.AreEqual(0x7FFFFFFFu, CodedOutputStream.EncodeZigZag32(unchecked((int) 0xC0000000)));
+ Assert.AreEqual(0xFFFFFFFEu, CodedOutputStream.EncodeZigZag32(0x7FFFFFFF));
+ Assert.AreEqual(0xFFFFFFFFu, CodedOutputStream.EncodeZigZag32(unchecked((int) 0x80000000)));
+ }
+
+ [Test]
+ public void EncodeZigZag64()
+ {
+ Assert.AreEqual(0u, CodedOutputStream.EncodeZigZag64(0));
+ Assert.AreEqual(1u, CodedOutputStream.EncodeZigZag64(-1));
+ Assert.AreEqual(2u, CodedOutputStream.EncodeZigZag64(1));
+ Assert.AreEqual(3u, CodedOutputStream.EncodeZigZag64(-2));
+ Assert.AreEqual(0x000000007FFFFFFEuL,
+ CodedOutputStream.EncodeZigZag64(unchecked((long) 0x000000003FFFFFFFUL)));
+ Assert.AreEqual(0x000000007FFFFFFFuL,
+ CodedOutputStream.EncodeZigZag64(unchecked((long) 0xFFFFFFFFC0000000UL)));
+ Assert.AreEqual(0x00000000FFFFFFFEuL,
+ CodedOutputStream.EncodeZigZag64(unchecked((long) 0x000000007FFFFFFFUL)));
+ Assert.AreEqual(0x00000000FFFFFFFFuL,
+ CodedOutputStream.EncodeZigZag64(unchecked((long) 0xFFFFFFFF80000000UL)));
+ Assert.AreEqual(0xFFFFFFFFFFFFFFFEL,
+ CodedOutputStream.EncodeZigZag64(unchecked((long) 0x7FFFFFFFFFFFFFFFUL)));
+ Assert.AreEqual(0xFFFFFFFFFFFFFFFFL,
+ CodedOutputStream.EncodeZigZag64(unchecked((long) 0x8000000000000000UL)));
+ }
+
+ [Test]
+ public void RoundTripZigZag32()
+ {
+ // Some easier-to-verify round-trip tests. The inputs (other than 0, 1, -1)
+ // were chosen semi-randomly via keyboard bashing.
+ Assert.AreEqual(0, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(0)));
+ Assert.AreEqual(1, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(1)));
+ Assert.AreEqual(-1, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-1)));
+ Assert.AreEqual(14927, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(14927)));
+ Assert.AreEqual(-3612, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-3612)));
+ }
+
+ [Test]
+ public void RoundTripZigZag64()
+ {
+ Assert.AreEqual(0, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(0)));
+ Assert.AreEqual(1, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(1)));
+ Assert.AreEqual(-1, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-1)));
+ Assert.AreEqual(14927, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(14927)));
+ Assert.AreEqual(-3612, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-3612)));
+
+ Assert.AreEqual(856912304801416L,
+ CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(856912304801416L)));
+ Assert.AreEqual(-75123905439571256L,
+ CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-75123905439571256L)));
+ }
+
+ [Test]
+ public void TestNegativeEnumNoTag()
+ {
+ Assert.AreEqual(10, CodedOutputStream.ComputeInt32Size(-2));
+ Assert.AreEqual(10, CodedOutputStream.ComputeEnumSize((int) SampleEnum.NegativeValue));
+
+ byte[] bytes = new byte[10];
+ CodedOutputStream output = new CodedOutputStream(bytes);
+ output.WriteEnum((int) SampleEnum.NegativeValue);
+
+ Assert.AreEqual(0, output.SpaceLeft);
+ Assert.AreEqual("FE-FF-FF-FF-FF-FF-FF-FF-FF-01", BitConverter.ToString(bytes));
+ }
+
+ [Test]
+ public void TestCodedInputOutputPosition()
+ {
+ byte[] content = new byte[110];
+ for (int i = 0; i < content.Length; i++)
+ content[i] = (byte)i;
+
+ byte[] child = new byte[120];
+ {
+ MemoryStream ms = new MemoryStream(child);
+ CodedOutputStream cout = new CodedOutputStream(ms, 20);
+ // Field 11: numeric value: 500
+ cout.WriteTag(11, WireFormat.WireType.Varint);
+ Assert.AreEqual(1, cout.Position);
+ cout.WriteInt32(500);
+ Assert.AreEqual(3, cout.Position);
+ //Field 12: length delimited 120 bytes
+ cout.WriteTag(12, WireFormat.WireType.LengthDelimited);
+ Assert.AreEqual(4, cout.Position);
+ cout.WriteBytes(ByteString.CopyFrom(content));
+ Assert.AreEqual(115, cout.Position);
+ // Field 13: fixed numeric value: 501
+ cout.WriteTag(13, WireFormat.WireType.Fixed32);
+ Assert.AreEqual(116, cout.Position);
+ cout.WriteSFixed32(501);
+ Assert.AreEqual(120, cout.Position);
+ cout.Flush();
+ }
+
+ byte[] bytes = new byte[130];
+ {
+ CodedOutputStream cout = new CodedOutputStream(bytes);
+ // Field 1: numeric value: 500
+ cout.WriteTag(1, WireFormat.WireType.Varint);
+ Assert.AreEqual(1, cout.Position);
+ cout.WriteInt32(500);
+ Assert.AreEqual(3, cout.Position);
+ //Field 2: length delimited 120 bytes
+ cout.WriteTag(2, WireFormat.WireType.LengthDelimited);
+ Assert.AreEqual(4, cout.Position);
+ cout.WriteBytes(ByteString.CopyFrom(child));
+ Assert.AreEqual(125, cout.Position);
+ // Field 3: fixed numeric value: 500
+ cout.WriteTag(3, WireFormat.WireType.Fixed32);
+ Assert.AreEqual(126, cout.Position);
+ cout.WriteSFixed32(501);
+ Assert.AreEqual(130, cout.Position);
+ cout.Flush();
+ }
+ // Now test Input stream:
+ {
+ CodedInputStream cin = new CodedInputStream(new MemoryStream(bytes), new byte[50], 0, 0);
+ Assert.AreEqual(0, cin.Position);
+ // Field 1:
+ uint tag = cin.ReadTag();
+ Assert.AreEqual(1, tag >> 3);
+ Assert.AreEqual(1, cin.Position);
+ Assert.AreEqual(500, cin.ReadInt32());
+ Assert.AreEqual(3, cin.Position);
+ //Field 2:
+ tag = cin.ReadTag();
+ Assert.AreEqual(2, tag >> 3);
+ Assert.AreEqual(4, cin.Position);
+ int childlen = cin.ReadLength();
+ Assert.AreEqual(120, childlen);
+ Assert.AreEqual(5, cin.Position);
+ int oldlimit = cin.PushLimit((int)childlen);
+ Assert.AreEqual(5, cin.Position);
+ // Now we are reading child message
+ {
+ // Field 11: numeric value: 500
+ tag = cin.ReadTag();
+ Assert.AreEqual(11, tag >> 3);
+ Assert.AreEqual(6, cin.Position);
+ Assert.AreEqual(500, cin.ReadInt32());
+ Assert.AreEqual(8, cin.Position);
+ //Field 12: length delimited 120 bytes
+ tag = cin.ReadTag();
+ Assert.AreEqual(12, tag >> 3);
+ Assert.AreEqual(9, cin.Position);
+ ByteString bstr = cin.ReadBytes();
+ Assert.AreEqual(110, bstr.Length);
+ Assert.AreEqual((byte) 109, bstr[109]);
+ Assert.AreEqual(120, cin.Position);
+ // Field 13: fixed numeric value: 501
+ tag = cin.ReadTag();
+ Assert.AreEqual(13, tag >> 3);
+ // ROK - Previously broken here, this returned 126 failing to account for bufferSizeAfterLimit
+ Assert.AreEqual(121, cin.Position);
+ Assert.AreEqual(501, cin.ReadSFixed32());
+ Assert.AreEqual(125, cin.Position);
+ Assert.IsTrue(cin.IsAtEnd);
+ }
+ cin.PopLimit(oldlimit);
+ Assert.AreEqual(125, cin.Position);
+ // Field 3: fixed numeric value: 501
+ tag = cin.ReadTag();
+ Assert.AreEqual(3, tag >> 3);
+ Assert.AreEqual(126, cin.Position);
+ Assert.AreEqual(501, cin.ReadSFixed32());
+ Assert.AreEqual(130, cin.Position);
+ Assert.IsTrue(cin.IsAtEnd);
+ }
+ }
+
+ [Test]
+ public void Dispose_DisposesUnderlyingStream()
+ {
+ var memoryStream = new MemoryStream();
+ Assert.IsTrue(memoryStream.CanWrite);
+ using (var cos = new CodedOutputStream(memoryStream))
+ {
+ cos.WriteRawByte(0);
+ Assert.AreEqual(0, memoryStream.Position); // Not flushed yet
+ }
+ Assert.AreEqual(1, memoryStream.ToArray().Length); // Flushed data from CodedOutputStream to MemoryStream
+ Assert.IsFalse(memoryStream.CanWrite); // Disposed
+ }
+
+ [Test]
+ public void Dispose_WithLeaveOpen()
+ {
+ var memoryStream = new MemoryStream();
+ Assert.IsTrue(memoryStream.CanWrite);
+ using (var cos = new CodedOutputStream(memoryStream, true))
+ {
+ cos.WriteRawByte(0);
+ Assert.AreEqual(0, memoryStream.Position); // Not flushed yet
+ }
+ Assert.AreEqual(1, memoryStream.Position); // Flushed data from CodedOutputStream to MemoryStream
+ Assert.IsTrue(memoryStream.CanWrite); // We left the stream open
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Collections/MapFieldTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Collections/MapFieldTest.cs
new file mode 100644
index 0000000000..9c8459073c
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Collections/MapFieldTest.cs
@@ -0,0 +1,532 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+using System.Collections;
+using System.Linq;
+
+namespace Google.Protobuf.Collections
+{
+ /// <summary>
+ /// Tests for MapField which aren't reliant on the encoded format -
+ /// tests for serialization/deserialization are part of GeneratedMessageTest.
+ /// </summary>
+ public class MapFieldTest
+ {
+ [Test]
+ public void Clone_ClonesMessages()
+ {
+ var message = new ForeignMessage { C = 20 };
+ var map = new MapField<string, ForeignMessage> { { "x", message } };
+ var clone = map.Clone();
+ map["x"].C = 30;
+ Assert.AreEqual(20, clone["x"].C);
+ }
+
+ [Test]
+ public void NullValuesProhibited()
+ {
+ TestNullValues<int?>(0);
+ TestNullValues("");
+ TestNullValues(new TestAllTypes());
+ }
+
+ private void TestNullValues<T>(T nonNullValue)
+ {
+ var map = new MapField<int, T>();
+ var nullValue = (T) (object) null;
+ Assert.Throws<ArgumentNullException>(() => map.Add(0, nullValue));
+ Assert.Throws<ArgumentNullException>(() => map[0] = nullValue);
+ map.Add(1, nonNullValue);
+ map[1] = nonNullValue;
+ }
+
+ [Test]
+ public void Add_ForbidsNullKeys()
+ {
+ var map = new MapField<string, ForeignMessage>();
+ Assert.Throws<ArgumentNullException>(() => map.Add(null, new ForeignMessage()));
+ }
+
+ [Test]
+ public void Indexer_ForbidsNullKeys()
+ {
+ var map = new MapField<string, ForeignMessage>();
+ Assert.Throws<ArgumentNullException>(() => map[null] = new ForeignMessage());
+ }
+
+ [Test]
+ public void AddPreservesInsertionOrder()
+ {
+ var map = new MapField<string, string>();
+ map.Add("a", "v1");
+ map.Add("b", "v2");
+ map.Add("c", "v3");
+ map.Remove("b");
+ map.Add("d", "v4");
+ CollectionAssert.AreEqual(new[] { "a", "c", "d" }, map.Keys);
+ CollectionAssert.AreEqual(new[] { "v1", "v3", "v4" }, map.Values);
+ }
+
+ [Test]
+ public void EqualityIsOrderInsensitive()
+ {
+ var map1 = new MapField<string, string>();
+ map1.Add("a", "v1");
+ map1.Add("b", "v2");
+
+ var map2 = new MapField<string, string>();
+ map2.Add("b", "v2");
+ map2.Add("a", "v1");
+
+ EqualityTester.AssertEquality(map1, map2);
+ }
+
+ [Test]
+ public void EqualityIsKeySensitive()
+ {
+ var map1 = new MapField<string, string>();
+ map1.Add("first key", "v1");
+ map1.Add("second key", "v2");
+
+ var map2 = new MapField<string, string>();
+ map2.Add("third key", "v1");
+ map2.Add("fourth key", "v2");
+
+ EqualityTester.AssertInequality(map1, map2);
+ }
+
+ [Test]
+ public void Equality_Simple()
+ {
+ var map = new MapField<string, string>();
+ EqualityTester.AssertEquality(map, map);
+ EqualityTester.AssertInequality(map, null);
+ Assert.IsFalse(map.Equals(new object()));
+ }
+
+ [Test]
+ public void EqualityIsValueSensitive()
+ {
+ // Note: Without some care, it's a little easier than one might
+ // hope to see hash collisions, but only in some environments...
+ var map1 = new MapField<string, string>();
+ map1.Add("a", "first value");
+ map1.Add("b", "second value");
+
+ var map2 = new MapField<string, string>();
+ map2.Add("a", "third value");
+ map2.Add("b", "fourth value");
+
+ EqualityTester.AssertInequality(map1, map2);
+ }
+
+ [Test]
+ public void Add_Dictionary()
+ {
+ var map1 = new MapField<string, string>
+ {
+ { "x", "y" },
+ { "a", "b" }
+ };
+ var map2 = new MapField<string, string>
+ {
+ { "before", "" },
+ map1,
+ { "after", "" }
+ };
+ var expected = new MapField<string, string>
+ {
+ { "before", "" },
+ { "x", "y" },
+ { "a", "b" },
+ { "after", "" }
+ };
+ Assert.AreEqual(expected, map2);
+ CollectionAssert.AreEqual(new[] { "before", "x", "a", "after" }, map2.Keys);
+ }
+
+ // General IDictionary<TKey, TValue> behavior tests
+ [Test]
+ public void Add_KeyAlreadyExists()
+ {
+ var map = new MapField<string, string>();
+ map.Add("foo", "bar");
+ Assert.Throws<ArgumentException>(() => map.Add("foo", "baz"));
+ }
+
+ [Test]
+ public void Add_Pair()
+ {
+ var map = new MapField<string, string>();
+ ICollection<KeyValuePair<string, string>> collection = map;
+ collection.Add(NewKeyValuePair("x", "y"));
+ Assert.AreEqual("y", map["x"]);
+ Assert.Throws<ArgumentException>(() => collection.Add(NewKeyValuePair("x", "z")));
+ }
+
+ [Test]
+ public void Contains_Pair()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ ICollection<KeyValuePair<string, string>> collection = map;
+ Assert.IsTrue(collection.Contains(NewKeyValuePair("x", "y")));
+ Assert.IsFalse(collection.Contains(NewKeyValuePair("x", "z")));
+ Assert.IsFalse(collection.Contains(NewKeyValuePair("z", "y")));
+ }
+
+ [Test]
+ public void Remove_Key()
+ {
+ var map = new MapField<string, string>();
+ map.Add("foo", "bar");
+ Assert.AreEqual(1, map.Count);
+ Assert.IsFalse(map.Remove("missing"));
+ Assert.AreEqual(1, map.Count);
+ Assert.IsTrue(map.Remove("foo"));
+ Assert.AreEqual(0, map.Count);
+ Assert.Throws<ArgumentNullException>(() => map.Remove(null));
+ }
+
+ [Test]
+ public void Remove_Pair()
+ {
+ var map = new MapField<string, string>();
+ map.Add("foo", "bar");
+ ICollection<KeyValuePair<string, string>> collection = map;
+ Assert.AreEqual(1, map.Count);
+ Assert.IsFalse(collection.Remove(NewKeyValuePair("wrong key", "bar")));
+ Assert.AreEqual(1, map.Count);
+ Assert.IsFalse(collection.Remove(NewKeyValuePair("foo", "wrong value")));
+ Assert.AreEqual(1, map.Count);
+ Assert.IsTrue(collection.Remove(NewKeyValuePair("foo", "bar")));
+ Assert.AreEqual(0, map.Count);
+ Assert.Throws<ArgumentException>(() => collection.Remove(new KeyValuePair<string, string>(null, "")));
+ }
+
+ [Test]
+ public void CopyTo_Pair()
+ {
+ var map = new MapField<string, string>();
+ map.Add("foo", "bar");
+ ICollection<KeyValuePair<string, string>> collection = map;
+ KeyValuePair<string, string>[] array = new KeyValuePair<string, string>[3];
+ collection.CopyTo(array, 1);
+ Assert.AreEqual(NewKeyValuePair("foo", "bar"), array[1]);
+ }
+
+ [Test]
+ public void Clear()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ Assert.AreEqual(1, map.Count);
+ map.Clear();
+ Assert.AreEqual(0, map.Count);
+ map.Add("x", "y");
+ Assert.AreEqual(1, map.Count);
+ }
+
+ [Test]
+ public void Indexer_Get()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ Assert.AreEqual("y", map["x"]);
+ Assert.Throws<KeyNotFoundException>(() => { var ignored = map["z"]; });
+ }
+
+ [Test]
+ public void Indexer_Set()
+ {
+ var map = new MapField<string, string>();
+ map["x"] = "y";
+ Assert.AreEqual("y", map["x"]);
+ map["x"] = "z"; // This won't throw, unlike Add.
+ Assert.AreEqual("z", map["x"]);
+ }
+
+ [Test]
+ public void GetEnumerator_NonGeneric()
+ {
+ IEnumerable map = new MapField<string, string> { { "x", "y" } };
+ CollectionAssert.AreEqual(new[] { new KeyValuePair<string, string>("x", "y") },
+ map.Cast<object>().ToList());
+ }
+
+ // Test for the explicitly-implemented non-generic IDictionary interface
+ [Test]
+ public void IDictionary_GetEnumerator()
+ {
+ IDictionary map = new MapField<string, string> { { "x", "y" } };
+ var enumerator = map.GetEnumerator();
+
+ // Commented assertions show an ideal situation - it looks like
+ // the LinkedList enumerator doesn't throw when you ask for the current entry
+ // at an inappropriate time; fixing this would be more work than it's worth.
+ // Assert.Throws<InvalidOperationException>(() => enumerator.Current.GetHashCode());
+ Assert.IsTrue(enumerator.MoveNext());
+ Assert.AreEqual("x", enumerator.Key);
+ Assert.AreEqual("y", enumerator.Value);
+ Assert.AreEqual(new DictionaryEntry("x", "y"), enumerator.Current);
+ Assert.AreEqual(new DictionaryEntry("x", "y"), enumerator.Entry);
+ Assert.IsFalse(enumerator.MoveNext());
+ // Assert.Throws<InvalidOperationException>(() => enumerator.Current.GetHashCode());
+ enumerator.Reset();
+ // Assert.Throws<InvalidOperationException>(() => enumerator.Current.GetHashCode());
+ Assert.IsTrue(enumerator.MoveNext());
+ Assert.AreEqual("x", enumerator.Key); // Assume the rest are okay
+ }
+
+ [Test]
+ public void IDictionary_Add()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ IDictionary dictionary = map;
+ dictionary.Add("a", "b");
+ Assert.AreEqual("b", map["a"]);
+ Assert.Throws<ArgumentException>(() => dictionary.Add("a", "duplicate"));
+ Assert.Throws<InvalidCastException>(() => dictionary.Add(new object(), "key is bad"));
+ Assert.Throws<InvalidCastException>(() => dictionary.Add("value is bad", new object()));
+ }
+
+ [Test]
+ public void IDictionary_Contains()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ IDictionary dictionary = map;
+
+ Assert.IsFalse(dictionary.Contains("a"));
+ Assert.IsFalse(dictionary.Contains(5));
+ // Surprising, but IDictionary.Contains is only about keys.
+ Assert.IsFalse(dictionary.Contains(new DictionaryEntry("x", "y")));
+ Assert.IsTrue(dictionary.Contains("x"));
+ }
+
+ [Test]
+ public void IDictionary_Remove()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ IDictionary dictionary = map;
+ dictionary.Remove("a");
+ Assert.AreEqual(1, dictionary.Count);
+ dictionary.Remove(5);
+ Assert.AreEqual(1, dictionary.Count);
+ dictionary.Remove(new DictionaryEntry("x", "y"));
+ Assert.AreEqual(1, dictionary.Count);
+ dictionary.Remove("x");
+ Assert.AreEqual(0, dictionary.Count);
+ Assert.Throws<ArgumentNullException>(() => dictionary.Remove(null));
+ }
+
+ [Test]
+ public void IDictionary_CopyTo()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ IDictionary dictionary = map;
+ var array = new DictionaryEntry[3];
+ dictionary.CopyTo(array, 1);
+ CollectionAssert.AreEqual(new[] { default(DictionaryEntry), new DictionaryEntry("x", "y"), default(DictionaryEntry) },
+ array);
+ var objectArray = new object[3];
+ dictionary.CopyTo(objectArray, 1);
+ CollectionAssert.AreEqual(new object[] { null, new DictionaryEntry("x", "y"), null },
+ objectArray);
+ }
+
+ [Test]
+ public void IDictionary_IsFixedSize()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ IDictionary dictionary = map;
+ Assert.IsFalse(dictionary.IsFixedSize);
+ }
+
+ [Test]
+ public void IDictionary_Keys()
+ {
+ IDictionary dictionary = new MapField<string, string> { { "x", "y" } };
+ CollectionAssert.AreEqual(new[] { "x" }, dictionary.Keys);
+ }
+
+ [Test]
+ public void IDictionary_Values()
+ {
+ IDictionary dictionary = new MapField<string, string> { { "x", "y" } };
+ CollectionAssert.AreEqual(new[] { "y" }, dictionary.Values);
+ }
+
+ [Test]
+ public void IDictionary_IsSynchronized()
+ {
+ IDictionary dictionary = new MapField<string, string> { { "x", "y" } };
+ Assert.IsFalse(dictionary.IsSynchronized);
+ }
+
+ [Test]
+ public void IDictionary_SyncRoot()
+ {
+ IDictionary dictionary = new MapField<string, string> { { "x", "y" } };
+ Assert.AreSame(dictionary, dictionary.SyncRoot);
+ }
+
+ [Test]
+ public void IDictionary_Indexer_Get()
+ {
+ IDictionary dictionary = new MapField<string, string> { { "x", "y" } };
+ Assert.AreEqual("y", dictionary["x"]);
+ Assert.IsNull(dictionary["a"]);
+ Assert.IsNull(dictionary[5]);
+ Assert.Throws<ArgumentNullException>(() => dictionary[null].GetHashCode());
+ }
+
+ [Test]
+ public void IDictionary_Indexer_Set()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ IDictionary dictionary = map;
+ map["a"] = "b";
+ Assert.AreEqual("b", map["a"]);
+ map["a"] = "c";
+ Assert.AreEqual("c", map["a"]);
+ Assert.Throws<InvalidCastException>(() => dictionary[5] = "x");
+ Assert.Throws<InvalidCastException>(() => dictionary["x"] = 5);
+ Assert.Throws<ArgumentNullException>(() => dictionary[null] = "z");
+ Assert.Throws<ArgumentNullException>(() => dictionary["x"] = null);
+ }
+
+ [Test]
+ public void KeysReturnsLiveView()
+ {
+ var map = new MapField<string, string>();
+ var keys = map.Keys;
+ CollectionAssert.AreEqual(new string[0], keys);
+ map["foo"] = "bar";
+ map["x"] = "y";
+ CollectionAssert.AreEqual(new[] { "foo", "x" }, keys);
+ }
+
+ [Test]
+ public void ValuesReturnsLiveView()
+ {
+ var map = new MapField<string, string>();
+ var values = map.Values;
+ CollectionAssert.AreEqual(new string[0], values);
+ map["foo"] = "bar";
+ map["x"] = "y";
+ CollectionAssert.AreEqual(new[] { "bar", "y" }, values);
+ }
+
+ // Just test keys - we know the implementation is the same for values
+ [Test]
+ public void ViewsAreReadOnly()
+ {
+ var map = new MapField<string, string>();
+ var keys = map.Keys;
+ Assert.IsTrue(keys.IsReadOnly);
+ Assert.Throws<NotSupportedException>(() => keys.Clear());
+ Assert.Throws<NotSupportedException>(() => keys.Remove("a"));
+ Assert.Throws<NotSupportedException>(() => keys.Add("a"));
+ }
+
+ // Just test keys - we know the implementation is the same for values
+ [Test]
+ public void ViewCopyTo()
+ {
+ var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
+ var keys = map.Keys;
+ var array = new string[4];
+ Assert.Throws<ArgumentException>(() => keys.CopyTo(array, 3));
+ Assert.Throws<ArgumentOutOfRangeException>(() => keys.CopyTo(array, -1));
+ keys.CopyTo(array, 1);
+ CollectionAssert.AreEqual(new[] { null, "foo", "x", null }, array);
+ }
+
+ // Just test keys - we know the implementation is the same for values
+ [Test]
+ public void NonGenericViewCopyTo()
+ {
+ IDictionary map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
+ ICollection keys = map.Keys;
+ // Note the use of the Array type here rather than string[]
+ Array array = new string[4];
+ Assert.Throws<ArgumentException>(() => keys.CopyTo(array, 3));
+ Assert.Throws<ArgumentOutOfRangeException>(() => keys.CopyTo(array, -1));
+ keys.CopyTo(array, 1);
+ CollectionAssert.AreEqual(new[] { null, "foo", "x", null }, array);
+ }
+
+ [Test]
+ public void KeysContains()
+ {
+ var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
+ var keys = map.Keys;
+ Assert.IsTrue(keys.Contains("foo"));
+ Assert.IsFalse(keys.Contains("bar")); // It's a value!
+ Assert.IsFalse(keys.Contains("1"));
+ // Keys can't be null, so we should prevent contains check
+ Assert.Throws<ArgumentNullException>(() => keys.Contains(null));
+ }
+
+ [Test]
+ public void ValuesContains()
+ {
+ var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
+ var values = map.Values;
+ Assert.IsTrue(values.Contains("bar"));
+ Assert.IsFalse(values.Contains("foo")); // It's a key!
+ Assert.IsFalse(values.Contains("1"));
+ // Values can be null, so this makes sense
+ Assert.IsFalse(values.Contains(null));
+ }
+
+ [Test]
+ public void ToString_StringToString()
+ {
+ var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
+ Assert.AreEqual("{ \"foo\": \"bar\", \"x\": \"y\" }", map.ToString());
+ }
+
+ [Test]
+ public void ToString_UnsupportedKeyType()
+ {
+ var map = new MapField<byte, string> { { 10, "foo" } };
+ Assert.Throws<ArgumentException>(() => map.ToString());
+ }
+
+ private static KeyValuePair<TKey, TValue> NewKeyValuePair<TKey, TValue>(TKey key, TValue value)
+ {
+ return new KeyValuePair<TKey, TValue>(key, value);
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs
new file mode 100644
index 0000000000..6852f75f8e
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs
@@ -0,0 +1,746 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using Google.Protobuf.TestProtos;
+using Google.Protobuf.WellKnownTypes;
+using NUnit.Framework;
+
+namespace Google.Protobuf.Collections
+{
+ public class RepeatedFieldTest
+ {
+ [Test]
+ public void NullValuesRejected()
+ {
+ var list = new RepeatedField<string>();
+ Assert.Throws<ArgumentNullException>(() => list.Add((string)null));
+ Assert.Throws<ArgumentNullException>(() => list.Add((IEnumerable<string>)null));
+ Assert.Throws<ArgumentNullException>(() => list.Add((RepeatedField<string>)null));
+ Assert.Throws<ArgumentNullException>(() => list.Contains(null));
+ Assert.Throws<ArgumentNullException>(() => list.IndexOf(null));
+ }
+
+ [Test]
+ public void Add_SingleItem()
+ {
+ var list = new RepeatedField<string>();
+ list.Add("foo");
+ Assert.AreEqual(1, list.Count);
+ Assert.AreEqual("foo", list[0]);
+ }
+
+ [Test]
+ public void Add_Sequence()
+ {
+ var list = new RepeatedField<string>();
+ list.Add(new[] { "foo", "bar" });
+ Assert.AreEqual(2, list.Count);
+ Assert.AreEqual("foo", list[0]);
+ Assert.AreEqual("bar", list[1]);
+ }
+
+ [Test]
+ public void AddRange_SlowPath()
+ {
+ var list = new RepeatedField<string>();
+ list.AddRange(new[] { "foo", "bar" }.Select(x => x));
+ Assert.AreEqual(2, list.Count);
+ Assert.AreEqual("foo", list[0]);
+ Assert.AreEqual("bar", list[1]);
+ }
+
+ [Test]
+ public void AddRange_SlowPath_NullsProhibited_ReferenceType()
+ {
+ var list = new RepeatedField<string>();
+ // It's okay for this to throw ArgumentNullException if necessary.
+ // It's not ideal, but not awful.
+ Assert.Catch<ArgumentException>(() => list.AddRange(new[] { "foo", null }.Select(x => x)));
+ }
+
+ [Test]
+ public void AddRange_SlowPath_NullsProhibited_NullableValueType()
+ {
+ var list = new RepeatedField<int?>();
+ // It's okay for this to throw ArgumentNullException if necessary.
+ // It's not ideal, but not awful.
+ Assert.Catch<ArgumentException>(() => list.AddRange(new[] { 20, (int?)null }.Select(x => x)));
+ }
+
+ [Test]
+ public void AddRange_Optimized_NonNullableValueType()
+ {
+ var list = new RepeatedField<int>();
+ list.AddRange(new List<int> { 20, 30 });
+ Assert.AreEqual(2, list.Count);
+ Assert.AreEqual(20, list[0]);
+ Assert.AreEqual(30, list[1]);
+ }
+
+ [Test]
+ public void AddRange_Optimized_ReferenceType()
+ {
+ var list = new RepeatedField<string>();
+ list.AddRange(new List<string> { "foo", "bar" });
+ Assert.AreEqual(2, list.Count);
+ Assert.AreEqual("foo", list[0]);
+ Assert.AreEqual("bar", list[1]);
+ }
+
+ [Test]
+ public void AddRange_Optimized_NullableValueType()
+ {
+ var list = new RepeatedField<int?>();
+ list.AddRange(new List<int?> { 20, 30 });
+ Assert.AreEqual(2, list.Count);
+ Assert.AreEqual((int?) 20, list[0]);
+ Assert.AreEqual((int?) 30, list[1]);
+ }
+
+ [Test]
+ public void AddRange_Optimized_NullsProhibited_ReferenceType()
+ {
+ // We don't just trust that a collection with a nullable element type doesn't contain nulls
+ var list = new RepeatedField<string>();
+ // It's okay for this to throw ArgumentNullException if necessary.
+ // It's not ideal, but not awful.
+ Assert.Catch<ArgumentException>(() => list.AddRange(new List<string> { "foo", null }));
+ }
+
+ [Test]
+ public void AddRange_Optimized_NullsProhibited_NullableValueType()
+ {
+ // We don't just trust that a collection with a nullable element type doesn't contain nulls
+ var list = new RepeatedField<int?>();
+ // It's okay for this to throw ArgumentNullException if necessary.
+ // It's not ideal, but not awful.
+ Assert.Catch<ArgumentException>(() => list.AddRange(new List<int?> { 20, null }));
+ }
+
+ [Test]
+ public void AddRange_AlreadyNotEmpty()
+ {
+ var list = new RepeatedField<int> { 1, 2, 3 };
+ list.AddRange(new List<int> { 4, 5, 6 });
+ CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5, 6 }, list);
+ }
+
+ [Test]
+ public void AddRange_RepeatedField()
+ {
+ var list = new RepeatedField<string> { "original" };
+ list.AddRange(new RepeatedField<string> { "foo", "bar" });
+ Assert.AreEqual(3, list.Count);
+ Assert.AreEqual("original", list[0]);
+ Assert.AreEqual("foo", list[1]);
+ Assert.AreEqual("bar", list[2]);
+ }
+
+ [Test]
+ public void RemoveAt_Valid()
+ {
+ var list = new RepeatedField<string> { "first", "second", "third" };
+ list.RemoveAt(1);
+ CollectionAssert.AreEqual(new[] { "first", "third" }, list);
+ // Just check that these don't throw...
+ list.RemoveAt(list.Count - 1); // Now the count will be 1...
+ list.RemoveAt(0);
+ Assert.AreEqual(0, list.Count);
+ }
+
+ [Test]
+ public void RemoveAt_Invalid()
+ {
+ var list = new RepeatedField<string> { "first", "second", "third" };
+ Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(-1));
+ Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(3));
+ }
+
+ [Test]
+ public void Insert_Valid()
+ {
+ var list = new RepeatedField<string> { "first", "second" };
+ list.Insert(1, "middle");
+ CollectionAssert.AreEqual(new[] { "first", "middle", "second" }, list);
+ list.Insert(3, "end");
+ CollectionAssert.AreEqual(new[] { "first", "middle", "second", "end" }, list);
+ list.Insert(0, "start");
+ CollectionAssert.AreEqual(new[] { "start", "first", "middle", "second", "end" }, list);
+ }
+
+ [Test]
+ public void Insert_Invalid()
+ {
+ var list = new RepeatedField<string> { "first", "second" };
+ Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(-1, "foo"));
+ Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(3, "foo"));
+ Assert.Throws<ArgumentNullException>(() => list.Insert(0, null));
+ }
+
+ [Test]
+ public void Equals_RepeatedField()
+ {
+ var list = new RepeatedField<string> { "first", "second" };
+ Assert.IsFalse(list.Equals((RepeatedField<string>) null));
+ Assert.IsTrue(list.Equals(list));
+ Assert.IsFalse(list.Equals(new RepeatedField<string> { "first", "third" }));
+ Assert.IsFalse(list.Equals(new RepeatedField<string> { "first" }));
+ Assert.IsTrue(list.Equals(new RepeatedField<string> { "first", "second" }));
+ }
+
+ [Test]
+ public void Equals_Object()
+ {
+ var list = new RepeatedField<string> { "first", "second" };
+ Assert.IsFalse(list.Equals((object) null));
+ Assert.IsTrue(list.Equals((object) list));
+ Assert.IsFalse(list.Equals((object) new RepeatedField<string> { "first", "third" }));
+ Assert.IsFalse(list.Equals((object) new RepeatedField<string> { "first" }));
+ Assert.IsTrue(list.Equals((object) new RepeatedField<string> { "first", "second" }));
+ Assert.IsFalse(list.Equals(new object()));
+ }
+
+ [Test]
+ public void GetEnumerator_GenericInterface()
+ {
+ IEnumerable<string> list = new RepeatedField<string> { "first", "second" };
+ // Select gets rid of the optimizations in ToList...
+ CollectionAssert.AreEqual(new[] { "first", "second" }, list.Select(x => x).ToList());
+ }
+
+ [Test]
+ public void GetEnumerator_NonGenericInterface()
+ {
+ IEnumerable list = new RepeatedField<string> { "first", "second" };
+ CollectionAssert.AreEqual(new[] { "first", "second" }, list.Cast<object>().ToList());
+ }
+
+ [Test]
+ public void CopyTo()
+ {
+ var list = new RepeatedField<string> { "first", "second" };
+ string[] stringArray = new string[4];
+ list.CopyTo(stringArray, 1);
+ CollectionAssert.AreEqual(new[] { null, "first", "second", null }, stringArray);
+ }
+
+ [Test]
+ public void Indexer_Get()
+ {
+ var list = new RepeatedField<string> { "first", "second" };
+ Assert.AreEqual("first", list[0]);
+ Assert.AreEqual("second", list[1]);
+ Assert.Throws<ArgumentOutOfRangeException>(() => list[-1].GetHashCode());
+ Assert.Throws<ArgumentOutOfRangeException>(() => list[2].GetHashCode());
+ }
+
+ [Test]
+ public void Indexer_Set()
+ {
+ var list = new RepeatedField<string> { "first", "second" };
+ list[0] = "changed";
+ Assert.AreEqual("changed", list[0]);
+ Assert.Throws<ArgumentNullException>(() => list[0] = null);
+ Assert.Throws<ArgumentOutOfRangeException>(() => list[-1] = "bad");
+ Assert.Throws<ArgumentOutOfRangeException>(() => list[2] = "bad");
+ }
+
+ [Test]
+ public void Clone_ReturnsMutable()
+ {
+ var list = new RepeatedField<int> { 0 };
+ var clone = list.Clone();
+ clone[0] = 1;
+ }
+
+ [Test]
+ public void Enumerator()
+ {
+ var list = new RepeatedField<string> { "first", "second" };
+ using (var enumerator = list.GetEnumerator())
+ {
+ Assert.IsTrue(enumerator.MoveNext());
+ Assert.AreEqual("first", enumerator.Current);
+ Assert.IsTrue(enumerator.MoveNext());
+ Assert.AreEqual("second", enumerator.Current);
+ Assert.IsFalse(enumerator.MoveNext());
+ Assert.IsFalse(enumerator.MoveNext());
+ }
+ }
+
+ [Test]
+ public void AddEntriesFrom_PackedInt32()
+ {
+ uint packedTag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ var length = CodedOutputStream.ComputeInt32Size(10)
+ + CodedOutputStream.ComputeInt32Size(999)
+ + CodedOutputStream.ComputeInt32Size(-1000);
+ output.WriteTag(packedTag);
+ output.WriteRawVarint32((uint) length);
+ output.WriteInt32(10);
+ output.WriteInt32(999);
+ output.WriteInt32(-1000);
+ output.Flush();
+ stream.Position = 0;
+
+ // Deliberately "expecting" a non-packed tag, but we detect that the data is
+ // actually packed.
+ uint nonPackedTag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
+ var field = new RepeatedField<int>();
+ var input = new CodedInputStream(stream);
+ input.AssertNextTag(packedTag);
+ field.AddEntriesFrom(input, FieldCodec.ForInt32(nonPackedTag));
+ CollectionAssert.AreEqual(new[] { 10, 999, -1000 }, field);
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ [Test]
+ public void AddEntriesFrom_NonPackedInt32()
+ {
+ uint nonPackedTag = WireFormat.MakeTag(10, WireFormat.WireType.Varint);
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ output.WriteTag(nonPackedTag);
+ output.WriteInt32(10);
+ output.WriteTag(nonPackedTag);
+ output.WriteInt32(999);
+ output.WriteTag(nonPackedTag);
+ output.WriteInt32(-1000); // Just for variety...
+ output.Flush();
+ stream.Position = 0;
+
+ // Deliberately "expecting" a packed tag, but we detect that the data is
+ // actually not packed.
+ uint packedTag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
+ var field = new RepeatedField<int>();
+ var input = new CodedInputStream(stream);
+ input.AssertNextTag(nonPackedTag);
+ field.AddEntriesFrom(input, FieldCodec.ForInt32(packedTag));
+ CollectionAssert.AreEqual(new[] { 10, 999, -1000 }, field);
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ [Test]
+ public void AddEntriesFrom_String()
+ {
+ uint tag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ output.WriteTag(tag);
+ output.WriteString("Foo");
+ output.WriteTag(tag);
+ output.WriteString("");
+ output.WriteTag(tag);
+ output.WriteString("Bar");
+ output.Flush();
+ stream.Position = 0;
+
+ var field = new RepeatedField<string>();
+ var input = new CodedInputStream(stream);
+ input.AssertNextTag(tag);
+ field.AddEntriesFrom(input, FieldCodec.ForString(tag));
+ CollectionAssert.AreEqual(new[] { "Foo", "", "Bar" }, field);
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ [Test]
+ public void AddEntriesFrom_Message()
+ {
+ var message1 = new ForeignMessage { C = 2000 };
+ var message2 = new ForeignMessage { C = -250 };
+
+ uint tag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ output.WriteTag(tag);
+ output.WriteMessage(message1);
+ output.WriteTag(tag);
+ output.WriteMessage(message2);
+ output.Flush();
+ stream.Position = 0;
+
+ var field = new RepeatedField<ForeignMessage>();
+ var input = new CodedInputStream(stream);
+ input.AssertNextTag(tag);
+ field.AddEntriesFrom(input, FieldCodec.ForMessage(tag, ForeignMessage.Parser));
+ CollectionAssert.AreEqual(new[] { message1, message2}, field);
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ [Test]
+ public void WriteTo_PackedInt32()
+ {
+ uint tag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
+ var field = new RepeatedField<int> { 10, 1000, 1000000 };
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ field.WriteTo(output, FieldCodec.ForInt32(tag));
+ output.Flush();
+ stream.Position = 0;
+
+ var input = new CodedInputStream(stream);
+ input.AssertNextTag(tag);
+ var length = input.ReadLength();
+ Assert.AreEqual(10, input.ReadInt32());
+ Assert.AreEqual(1000, input.ReadInt32());
+ Assert.AreEqual(1000000, input.ReadInt32());
+ Assert.IsTrue(input.IsAtEnd);
+ Assert.AreEqual(1 + CodedOutputStream.ComputeLengthSize(length) + length, stream.Length);
+ }
+
+ [Test]
+ public void WriteTo_NonPackedInt32()
+ {
+ uint tag = WireFormat.MakeTag(10, WireFormat.WireType.Varint);
+ var field = new RepeatedField<int> { 10, 1000, 1000000};
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ field.WriteTo(output, FieldCodec.ForInt32(tag));
+ output.Flush();
+ stream.Position = 0;
+
+ var input = new CodedInputStream(stream);
+ input.AssertNextTag(tag);
+ Assert.AreEqual(10, input.ReadInt32());
+ input.AssertNextTag(tag);
+ Assert.AreEqual(1000, input.ReadInt32());
+ input.AssertNextTag(tag);
+ Assert.AreEqual(1000000, input.ReadInt32());
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ [Test]
+ public void WriteTo_String()
+ {
+ uint tag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
+ var field = new RepeatedField<string> { "Foo", "", "Bar" };
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ field.WriteTo(output, FieldCodec.ForString(tag));
+ output.Flush();
+ stream.Position = 0;
+
+ var input = new CodedInputStream(stream);
+ input.AssertNextTag(tag);
+ Assert.AreEqual("Foo", input.ReadString());
+ input.AssertNextTag(tag);
+ Assert.AreEqual("", input.ReadString());
+ input.AssertNextTag(tag);
+ Assert.AreEqual("Bar", input.ReadString());
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ [Test]
+ public void WriteTo_Message()
+ {
+ var message1 = new ForeignMessage { C = 20 };
+ var message2 = new ForeignMessage { C = 25 };
+ uint tag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
+ var field = new RepeatedField<ForeignMessage> { message1, message2 };
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ field.WriteTo(output, FieldCodec.ForMessage(tag, ForeignMessage.Parser));
+ output.Flush();
+ stream.Position = 0;
+
+ var input = new CodedInputStream(stream);
+ input.AssertNextTag(tag);
+ Assert.AreEqual(message1, input.ReadMessage(ForeignMessage.Parser));
+ input.AssertNextTag(tag);
+ Assert.AreEqual(message2, input.ReadMessage(ForeignMessage.Parser));
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ [Test]
+ public void CalculateSize_VariableSizeNonPacked()
+ {
+ var list = new RepeatedField<int> { 1, 500, 1 };
+ var tag = WireFormat.MakeTag(1, WireFormat.WireType.Varint);
+ // 2 bytes for the first entry, 3 bytes for the second, 2 bytes for the third
+ Assert.AreEqual(7, list.CalculateSize(FieldCodec.ForInt32(tag)));
+ }
+
+ [Test]
+ public void CalculateSize_FixedSizeNonPacked()
+ {
+ var list = new RepeatedField<int> { 1, 500, 1 };
+ var tag = WireFormat.MakeTag(1, WireFormat.WireType.Fixed32);
+ // 5 bytes for the each entry
+ Assert.AreEqual(15, list.CalculateSize(FieldCodec.ForSFixed32(tag)));
+ }
+
+ [Test]
+ public void CalculateSize_VariableSizePacked()
+ {
+ var list = new RepeatedField<int> { 1, 500, 1};
+ var tag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited);
+ // 1 byte for the tag, 1 byte for the length,
+ // 1 byte for the first entry, 2 bytes for the second, 1 byte for the third
+ Assert.AreEqual(6, list.CalculateSize(FieldCodec.ForInt32(tag)));
+ }
+
+ [Test]
+ public void CalculateSize_FixedSizePacked()
+ {
+ var list = new RepeatedField<int> { 1, 500, 1 };
+ var tag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited);
+ // 1 byte for the tag, 1 byte for the length, 4 bytes per entry
+ Assert.AreEqual(14, list.CalculateSize(FieldCodec.ForSFixed32(tag)));
+ }
+
+ [Test]
+ public void TestNegativeEnumArray()
+ {
+ int arraySize = 1 + 1 + (11 * 5);
+ int msgSize = arraySize;
+ byte[] bytes = new byte[msgSize];
+ CodedOutputStream output = new CodedOutputStream(bytes);
+ uint tag = WireFormat.MakeTag(8, WireFormat.WireType.Varint);
+ for (int i = 0; i >= -5; i--)
+ {
+ output.WriteTag(tag);
+ output.WriteEnum(i);
+ }
+
+ Assert.AreEqual(0, output.SpaceLeft);
+
+ CodedInputStream input = new CodedInputStream(bytes);
+ tag = input.ReadTag();
+
+ RepeatedField<SampleEnum> values = new RepeatedField<SampleEnum>();
+ values.AddEntriesFrom(input, FieldCodec.ForEnum(tag, x => (int)x, x => (SampleEnum)x));
+
+ Assert.AreEqual(6, values.Count);
+ Assert.AreEqual(SampleEnum.None, values[0]);
+ Assert.AreEqual(((SampleEnum)(-1)), values[1]);
+ Assert.AreEqual(SampleEnum.NegativeValue, values[2]);
+ Assert.AreEqual(((SampleEnum)(-3)), values[3]);
+ Assert.AreEqual(((SampleEnum)(-4)), values[4]);
+ Assert.AreEqual(((SampleEnum)(-5)), values[5]);
+ }
+
+
+ [Test]
+ public void TestNegativeEnumPackedArray()
+ {
+ int arraySize = 1 + (10 * 5);
+ int msgSize = 1 + 1 + arraySize;
+ byte[] bytes = new byte[msgSize];
+ CodedOutputStream output = new CodedOutputStream(bytes);
+ // Length-delimited to show we want the packed representation
+ uint tag = WireFormat.MakeTag(8, WireFormat.WireType.LengthDelimited);
+ output.WriteTag(tag);
+ int size = 0;
+ for (int i = 0; i >= -5; i--)
+ {
+ size += CodedOutputStream.ComputeEnumSize(i);
+ }
+ output.WriteRawVarint32((uint)size);
+ for (int i = 0; i >= -5; i--)
+ {
+ output.WriteEnum(i);
+ }
+ Assert.AreEqual(0, output.SpaceLeft);
+
+ CodedInputStream input = new CodedInputStream(bytes);
+ tag = input.ReadTag();
+
+ RepeatedField<SampleEnum> values = new RepeatedField<SampleEnum>();
+ values.AddEntriesFrom(input, FieldCodec.ForEnum(tag, x => (int)x, x => (SampleEnum)x));
+
+ Assert.AreEqual(6, values.Count);
+ Assert.AreEqual(SampleEnum.None, values[0]);
+ Assert.AreEqual(((SampleEnum)(-1)), values[1]);
+ Assert.AreEqual(SampleEnum.NegativeValue, values[2]);
+ Assert.AreEqual(((SampleEnum)(-3)), values[3]);
+ Assert.AreEqual(((SampleEnum)(-4)), values[4]);
+ Assert.AreEqual(((SampleEnum)(-5)), values[5]);
+ }
+
+ // Fairly perfunctory tests for the non-generic IList implementation
+ [Test]
+ public void IList_Indexer()
+ {
+ var field = new RepeatedField<string> { "first", "second" };
+ IList list = field;
+ Assert.AreEqual("first", list[0]);
+ list[1] = "changed";
+ Assert.AreEqual("changed", field[1]);
+ }
+
+ [Test]
+ public void IList_Contains()
+ {
+ IList list = new RepeatedField<string> { "first", "second" };
+ Assert.IsTrue(list.Contains("second"));
+ Assert.IsFalse(list.Contains("third"));
+ Assert.IsFalse(list.Contains(new object()));
+ }
+
+ [Test]
+ public void IList_Add()
+ {
+ IList list = new RepeatedField<string> { "first", "second" };
+ list.Add("third");
+ CollectionAssert.AreEqual(new[] { "first", "second", "third" }, list);
+ }
+
+ [Test]
+ public void IList_Remove()
+ {
+ IList list = new RepeatedField<string> { "first", "second" };
+ list.Remove("third"); // No-op, no exception
+ list.Remove(new object()); // No-op, no exception
+ list.Remove("first");
+ CollectionAssert.AreEqual(new[] { "second" }, list);
+ }
+
+ [Test]
+ public void IList_IsFixedSize()
+ {
+ var field = new RepeatedField<string> { "first", "second" };
+ IList list = field;
+ Assert.IsFalse(list.IsFixedSize);
+ }
+
+ [Test]
+ public void IList_IndexOf()
+ {
+ IList list = new RepeatedField<string> { "first", "second" };
+ Assert.AreEqual(1, list.IndexOf("second"));
+ Assert.AreEqual(-1, list.IndexOf("third"));
+ Assert.AreEqual(-1, list.IndexOf(new object()));
+ }
+
+ [Test]
+ public void IList_SyncRoot()
+ {
+ IList list = new RepeatedField<string> { "first", "second" };
+ Assert.AreSame(list, list.SyncRoot);
+ }
+
+ [Test]
+ public void IList_CopyTo()
+ {
+ IList list = new RepeatedField<string> { "first", "second" };
+ string[] stringArray = new string[4];
+ list.CopyTo(stringArray, 1);
+ CollectionAssert.AreEqual(new[] { null, "first", "second", null }, stringArray);
+
+ object[] objectArray = new object[4];
+ list.CopyTo(objectArray, 1);
+ CollectionAssert.AreEqual(new[] { null, "first", "second", null }, objectArray);
+
+ Assert.Throws<ArrayTypeMismatchException>(() => list.CopyTo(new StringBuilder[4], 1));
+ Assert.Throws<ArrayTypeMismatchException>(() => list.CopyTo(new int[4], 1));
+ }
+
+ [Test]
+ public void IList_IsSynchronized()
+ {
+ IList list = new RepeatedField<string> { "first", "second" };
+ Assert.IsFalse(list.IsSynchronized);
+ }
+
+ [Test]
+ public void IList_Insert()
+ {
+ IList list = new RepeatedField<string> { "first", "second" };
+ list.Insert(1, "middle");
+ CollectionAssert.AreEqual(new[] { "first", "middle", "second" }, list);
+ }
+
+ [Test]
+ public void ToString_Integers()
+ {
+ var list = new RepeatedField<int> { 5, 10, 20 };
+ var text = list.ToString();
+ Assert.AreEqual("[ 5, 10, 20 ]", text);
+ }
+
+ [Test]
+ public void ToString_Strings()
+ {
+ var list = new RepeatedField<string> { "x", "y", "z" };
+ var text = list.ToString();
+ Assert.AreEqual("[ \"x\", \"y\", \"z\" ]", text);
+ }
+
+ [Test]
+ public void ToString_Messages()
+ {
+ var list = new RepeatedField<TestAllTypes> { new TestAllTypes { SingleDouble = 1.5 }, new TestAllTypes { SingleInt32 = 10 } };
+ var text = list.ToString();
+ Assert.AreEqual("[ { \"singleDouble\": 1.5 }, { \"singleInt32\": 10 } ]", text);
+ }
+
+ [Test]
+ public void ToString_Empty()
+ {
+ var list = new RepeatedField<TestAllTypes> { };
+ var text = list.ToString();
+ Assert.AreEqual("[ ]", text);
+ }
+
+ [Test]
+ public void ToString_InvalidElementType()
+ {
+ var list = new RepeatedField<decimal> { 15m };
+ Assert.Throws<ArgumentException>(() => list.ToString());
+ }
+
+ [Test]
+ public void ToString_Timestamp()
+ {
+ var list = new RepeatedField<Timestamp> { Timestamp.FromDateTime(new DateTime(2015, 10, 1, 12, 34, 56, DateTimeKind.Utc)) };
+ var text = list.ToString();
+ Assert.AreEqual("[ \"2015-10-01T12:34:56Z\" ]", text);
+ }
+
+ [Test]
+ public void ToString_Struct()
+ {
+ var message = new Struct { Fields = { { "foo", new Value { NumberValue = 20 } } } };
+ var list = new RepeatedField<Struct> { message };
+ var text = list.ToString();
+ Assert.AreEqual(text, "[ { \"foo\": 20 } ]", message.ToString());
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Compatibility/PropertyInfoExtensionsTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Compatibility/PropertyInfoExtensionsTest.cs
new file mode 100644
index 0000000000..df23a09cd4
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Compatibility/PropertyInfoExtensionsTest.cs
@@ -0,0 +1,98 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using NUnit.Framework;
+using System.Reflection;
+
+namespace Google.Protobuf.Compatibility
+{
+ public class PropertyInfoExtensionsTest
+ {
+ public string PublicReadWrite { get; set; }
+ private string PrivateReadWrite { get; set; }
+ public string PublicReadPrivateWrite { get; private set; }
+ public string PrivateReadPublicWrite { private get; set; }
+ public string PublicReadOnly { get { return null; } }
+ private string PrivateReadOnly { get { return null; } }
+ public string PublicWriteOnly { set { } }
+ private string PrivateWriteOnly { set { } }
+
+ [Test]
+ [TestCase("PublicReadWrite")]
+ [TestCase("PublicReadPrivateWrite")]
+ [TestCase("PublicReadOnly")]
+ public void GetGetMethod_Success(string name)
+ {
+ var propertyInfo = typeof(PropertyInfoExtensionsTest)
+ .GetProperty(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
+ Assert.IsNotNull(PropertyInfoExtensions.GetGetMethod(propertyInfo));
+ }
+
+ [Test]
+ [TestCase("PrivateReadWrite")]
+ [TestCase("PrivateReadPublicWrite")]
+ [TestCase("PrivateReadOnly")]
+ [TestCase("PublicWriteOnly")]
+ [TestCase("PrivateWriteOnly")]
+ public void GetGetMethod_NoAccessibleGetter(string name)
+ {
+ var propertyInfo = typeof(PropertyInfoExtensionsTest)
+ .GetProperty(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
+ Assert.IsNull(PropertyInfoExtensions.GetGetMethod(propertyInfo));
+ }
+
+ [Test]
+ [TestCase("PublicReadWrite")]
+ [TestCase("PrivateReadPublicWrite")]
+ [TestCase("PublicWriteOnly")]
+ public void GetSetMethod_Success(string name)
+ {
+ var propertyInfo = typeof(PropertyInfoExtensionsTest)
+ .GetProperty(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
+ Assert.IsNotNull(PropertyInfoExtensions.GetSetMethod(propertyInfo));
+ }
+
+ [Test]
+ [TestCase("PublicReadPrivateWrite")]
+ [TestCase("PrivateReadWrite")]
+ [TestCase("PrivateReadOnly")]
+ [TestCase("PublicReadOnly")]
+ [TestCase("PrivateWriteOnly")]
+ public void GetSetMethod_NoAccessibleGetter(string name)
+ {
+ var propertyInfo = typeof(PropertyInfoExtensionsTest)
+ .GetProperty(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
+ Assert.IsNull(PropertyInfoExtensions.GetSetMethod(propertyInfo));
+ }
+ }
+
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs
new file mode 100644
index 0000000000..f430b06bed
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs
@@ -0,0 +1,117 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+using NUnit.Framework;
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+
+#if !DOTNET35
+namespace Google.Protobuf.Compatibility
+{
+ public class TypeExtensionsTest
+ {
+ public class DerivedList : List<string> { }
+ public string PublicProperty { get; set; }
+ private string PrivateProperty { get; set; }
+
+ public void PublicMethod()
+ {
+ }
+
+ private void PrivateMethod()
+ {
+ }
+
+ [Test]
+ [TestCase(typeof(object), typeof(string), true)]
+ [TestCase(typeof(object), typeof(int), true)]
+ [TestCase(typeof(string), typeof(string), true)]
+ [TestCase(typeof(string), typeof(object), false)]
+ [TestCase(typeof(string), typeof(int), false)]
+ [TestCase(typeof(int), typeof(int), true)]
+ [TestCase(typeof(ValueType), typeof(int), true)]
+ [TestCase(typeof(long), typeof(int), false)] //
+ public void IsAssignableFrom(Type target, Type argument, bool expected)
+ {
+ Assert.AreEqual(expected, TypeExtensions.IsAssignableFrom(target, argument));
+ }
+
+ [Test]
+ [TestCase(typeof(DerivedList), "Count")] // Go up the type hierarchy
+ [TestCase(typeof(List<string>), "Count")]
+ [TestCase(typeof(List<>), "Count")]
+ [TestCase(typeof(TypeExtensionsTest), "PublicProperty")]
+ public void GetProperty_Success(Type type, string name)
+ {
+ var property = TypeExtensions.GetProperty(type, name);
+ Assert.IsNotNull(property);
+ Assert.AreEqual(name, property.Name);
+ }
+
+ [Test]
+ [TestCase(typeof(TypeExtensionsTest), "PrivateProperty")]
+ [TestCase(typeof(TypeExtensionsTest), "Garbage")]
+ public void GetProperty_NoSuchProperty(Type type, string name)
+ {
+ var property = TypeExtensions.GetProperty(type, name);
+ Assert.IsNull(property);
+ }
+
+ [Test]
+ [TestCase(typeof(DerivedList), "RemoveAt")] // Go up the type hierarchy
+ [TestCase(typeof(List<>), "RemoveAt")]
+ [TestCase(typeof(TypeExtensionsTest), "PublicMethod")]
+ public void GetMethod_Success(Type type, string name)
+ {
+ var method = TypeExtensions.GetMethod(type, name);
+ Assert.IsNotNull(method);
+ Assert.AreEqual(name, method.Name);
+ }
+
+ [Test]
+ [TestCase(typeof(TypeExtensionsTest), "PrivateMethod")]
+ [TestCase(typeof(TypeExtensionsTest), "GarbageMethod")]
+ public void GetMethod_NoSuchMethod(Type type, string name)
+ {
+ var method = TypeExtensions.GetMethod(type, name);
+ Assert.IsNull(method);
+ }
+
+ [Test]
+ [TestCase(typeof(List<string>), "IndexOf")]
+ public void GetMethod_Ambiguous(Type type, string name)
+ {
+ Assert.Throws<AmbiguousMatchException>(() => TypeExtensions.GetMethod(type, name));
+ }
+ }
+}
+#endif
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/DeprecatedMemberTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/DeprecatedMemberTest.cs
new file mode 100644
index 0000000000..34d5b9f98c
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/DeprecatedMemberTest.cs
@@ -0,0 +1,55 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.Reflection;
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+
+namespace Google.Protobuf
+{
+ public class DeprecatedMemberTest
+ {
+ private static void AssertIsDeprecated(MemberInfo member)
+ {
+ Assert.NotNull(member);
+ Assert.IsTrue(member.IsDefined(typeof(ObsoleteAttribute), false), "Member not obsolete: " + member);
+ }
+
+ [Test]
+ public void TestDepreatedPrimitiveValue()
+ {
+ AssertIsDeprecated(typeof(TestDeprecatedFields).GetProperty("DeprecatedInt32"));
+ }
+
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/EqualityTester.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/EqualityTester.cs
new file mode 100644
index 0000000000..a669baba17
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/EqualityTester.cs
@@ -0,0 +1,64 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using NUnit.Framework;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Helper methods when testing equality. NUnit's Assert.AreEqual and
+ /// Assert.AreNotEqual methods try to be clever with collections, which can
+ /// be annoying...
+ /// </summary>
+ internal static class EqualityTester
+ {
+ public static void AssertEquality<T>(T first, T second) where T : IEquatable<T>
+ {
+ Assert.IsTrue(first.Equals(second));
+ Assert.IsTrue(first.Equals((object) second));
+ Assert.AreEqual(first.GetHashCode(), second.GetHashCode());
+ }
+
+ public static void AssertInequality<T>(T first, T second) where T : IEquatable<T>
+ {
+ Assert.IsFalse(first.Equals(second));
+ Assert.IsFalse(first.Equals((object) second));
+ // While this isn't a requirement, the chances of this test failing due to
+ // coincidence rather than a bug are very small.
+ if (first != null && second != null)
+ {
+ Assert.AreNotEqual(first.GetHashCode(), second.GetHashCode());
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/FieldCodecTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/FieldCodecTest.cs
new file mode 100644
index 0000000000..0e2bad59e5
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/FieldCodecTest.cs
@@ -0,0 +1,196 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System.Collections.Generic;
+using System.IO;
+using System.Reflection;
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+
+namespace Google.Protobuf
+{
+ public class FieldCodecTest
+ {
+#pragma warning disable 0414 // Used by tests via reflection - do not remove!
+ private static readonly List<ICodecTestData> Codecs = new List<ICodecTestData>
+ {
+ new FieldCodecTestData<bool>(FieldCodec.ForBool(100), true, "Bool"),
+ new FieldCodecTestData<string>(FieldCodec.ForString(100), "sample", "String"),
+ new FieldCodecTestData<ByteString>(FieldCodec.ForBytes(100), ByteString.CopyFrom(1, 2, 3), "Bytes"),
+ new FieldCodecTestData<int>(FieldCodec.ForInt32(100), -1000, "Int32"),
+ new FieldCodecTestData<int>(FieldCodec.ForSInt32(100), -1000, "SInt32"),
+ new FieldCodecTestData<int>(FieldCodec.ForSFixed32(100), -1000, "SFixed32"),
+ new FieldCodecTestData<uint>(FieldCodec.ForUInt32(100), 1234, "UInt32"),
+ new FieldCodecTestData<uint>(FieldCodec.ForFixed32(100), 1234, "Fixed32"),
+ new FieldCodecTestData<long>(FieldCodec.ForInt64(100), -1000, "Int64"),
+ new FieldCodecTestData<long>(FieldCodec.ForSInt64(100), -1000, "SInt64"),
+ new FieldCodecTestData<long>(FieldCodec.ForSFixed64(100), -1000, "SFixed64"),
+ new FieldCodecTestData<ulong>(FieldCodec.ForUInt64(100), 1234, "UInt64"),
+ new FieldCodecTestData<ulong>(FieldCodec.ForFixed64(100), 1234, "Fixed64"),
+ new FieldCodecTestData<float>(FieldCodec.ForFloat(100), 1234.5f, "Float"),
+ new FieldCodecTestData<double>(FieldCodec.ForDouble(100), 1234567890.5d, "Double"),
+ new FieldCodecTestData<ForeignEnum>(
+ FieldCodec.ForEnum(100, t => (int) t, t => (ForeignEnum) t), ForeignEnum.ForeignBaz, "Enum"),
+ new FieldCodecTestData<ForeignMessage>(
+ FieldCodec.ForMessage(100, ForeignMessage.Parser), new ForeignMessage { C = 10 }, "Message"),
+ };
+#pragma warning restore 0414
+
+ [Test, TestCaseSource("Codecs")]
+ public void RoundTripWithTag(ICodecTestData codec)
+ {
+ codec.TestRoundTripWithTag();
+ }
+
+ [Test, TestCaseSource("Codecs")]
+ public void RoundTripRaw(ICodecTestData codec)
+ {
+ codec.TestRoundTripRaw();
+ }
+
+ [Test, TestCaseSource("Codecs")]
+ public void CalculateSize(ICodecTestData codec)
+ {
+ codec.TestCalculateSizeWithTag();
+ }
+
+ [Test, TestCaseSource("Codecs")]
+ public void DefaultValue(ICodecTestData codec)
+ {
+ codec.TestDefaultValue();
+ }
+
+ [Test, TestCaseSource("Codecs")]
+ public void FixedSize(ICodecTestData codec)
+ {
+ codec.TestFixedSize();
+ }
+
+ // This is ugly, but it means we can have a non-generic interface.
+ // It feels like NUnit should support this better, but I don't know
+ // of any better ways right now.
+ public interface ICodecTestData
+ {
+ void TestRoundTripRaw();
+ void TestRoundTripWithTag();
+ void TestCalculateSizeWithTag();
+ void TestDefaultValue();
+ void TestFixedSize();
+ }
+
+ public class FieldCodecTestData<T> : ICodecTestData
+ {
+ private readonly FieldCodec<T> codec;
+ private readonly T sampleValue;
+ private readonly string name;
+
+ public FieldCodecTestData(FieldCodec<T> codec, T sampleValue, string name)
+ {
+ this.codec = codec;
+ this.sampleValue = sampleValue;
+ this.name = name;
+ }
+
+ public void TestRoundTripRaw()
+ {
+ var stream = new MemoryStream();
+ var codedOutput = new CodedOutputStream(stream);
+ codec.ValueWriter(codedOutput, sampleValue);
+ codedOutput.Flush();
+ stream.Position = 0;
+ var codedInput = new CodedInputStream(stream);
+ Assert.AreEqual(sampleValue, codec.ValueReader(codedInput));
+ Assert.IsTrue(codedInput.IsAtEnd);
+ }
+
+ public void TestRoundTripWithTag()
+ {
+ var stream = new MemoryStream();
+ var codedOutput = new CodedOutputStream(stream);
+ codec.WriteTagAndValue(codedOutput, sampleValue);
+ codedOutput.Flush();
+ stream.Position = 0;
+ var codedInput = new CodedInputStream(stream);
+ codedInput.AssertNextTag(codec.Tag);
+ Assert.AreEqual(sampleValue, codec.Read(codedInput));
+ Assert.IsTrue(codedInput.IsAtEnd);
+ }
+
+ public void TestCalculateSizeWithTag()
+ {
+ var stream = new MemoryStream();
+ var codedOutput = new CodedOutputStream(stream);
+ codec.WriteTagAndValue(codedOutput, sampleValue);
+ codedOutput.Flush();
+ Assert.AreEqual(stream.Position, codec.CalculateSizeWithTag(sampleValue));
+ }
+
+ public void TestDefaultValue()
+ {
+ // WriteTagAndValue ignores default values
+ var stream = new MemoryStream();
+ var codedOutput = new CodedOutputStream(stream);
+ codec.WriteTagAndValue(codedOutput, codec.DefaultValue);
+ codedOutput.Flush();
+ Assert.AreEqual(0, stream.Position);
+ Assert.AreEqual(0, codec.CalculateSizeWithTag(codec.DefaultValue));
+ if (typeof(T).GetTypeInfo().IsValueType)
+ {
+ Assert.AreEqual(default(T), codec.DefaultValue);
+ }
+
+ // The plain ValueWriter/ValueReader delegates don't.
+ if (codec.DefaultValue != null) // This part isn't appropriate for message types.
+ {
+ codedOutput = new CodedOutputStream(stream);
+ codec.ValueWriter(codedOutput, codec.DefaultValue);
+ codedOutput.Flush();
+ Assert.AreNotEqual(0, stream.Position);
+ Assert.AreEqual(stream.Position, codec.ValueSizeCalculator(codec.DefaultValue));
+ stream.Position = 0;
+ var codedInput = new CodedInputStream(stream);
+ Assert.AreEqual(codec.DefaultValue, codec.ValueReader(codedInput));
+ }
+ }
+
+ public void TestFixedSize()
+ {
+ Assert.AreEqual(name.Contains("Fixed"), codec.FixedSize != 0);
+ }
+
+ public override string ToString()
+ {
+ return name;
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/GeneratedMessageTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/GeneratedMessageTest.cs
new file mode 100644
index 0000000000..8b153d691f
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/GeneratedMessageTest.cs
@@ -0,0 +1,723 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.IO;
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using Google.Protobuf.WellKnownTypes;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Tests around the generated TestAllTypes message.
+ /// </summary>
+ public class GeneratedMessageTest
+ {
+ [Test]
+ public void EmptyMessageFieldDistinctFromMissingMessageField()
+ {
+ // This demonstrates what we're really interested in...
+ var message1 = new TestAllTypes { SingleForeignMessage = new ForeignMessage() };
+ var message2 = new TestAllTypes(); // SingleForeignMessage is null
+ EqualityTester.AssertInequality(message1, message2);
+ }
+
+ [Test]
+ public void DefaultValues()
+ {
+ // Single fields
+ var message = new TestAllTypes();
+ Assert.AreEqual(false, message.SingleBool);
+ Assert.AreEqual(ByteString.Empty, message.SingleBytes);
+ Assert.AreEqual(0.0, message.SingleDouble);
+ Assert.AreEqual(0, message.SingleFixed32);
+ Assert.AreEqual(0L, message.SingleFixed64);
+ Assert.AreEqual(0.0f, message.SingleFloat);
+ Assert.AreEqual(ForeignEnum.ForeignUnspecified, message.SingleForeignEnum);
+ Assert.IsNull(message.SingleForeignMessage);
+ Assert.AreEqual(ImportEnum.Unspecified, message.SingleImportEnum);
+ Assert.IsNull(message.SingleImportMessage);
+ Assert.AreEqual(0, message.SingleInt32);
+ Assert.AreEqual(0L, message.SingleInt64);
+ Assert.AreEqual(TestAllTypes.Types.NestedEnum.Unspecified, message.SingleNestedEnum);
+ Assert.IsNull(message.SingleNestedMessage);
+ Assert.IsNull(message.SinglePublicImportMessage);
+ Assert.AreEqual(0, message.SingleSfixed32);
+ Assert.AreEqual(0L, message.SingleSfixed64);
+ Assert.AreEqual(0, message.SingleSint32);
+ Assert.AreEqual(0L, message.SingleSint64);
+ Assert.AreEqual("", message.SingleString);
+ Assert.AreEqual(0U, message.SingleUint32);
+ Assert.AreEqual(0UL, message.SingleUint64);
+
+ // Repeated fields
+ Assert.AreEqual(0, message.RepeatedBool.Count);
+ Assert.AreEqual(0, message.RepeatedBytes.Count);
+ Assert.AreEqual(0, message.RepeatedDouble.Count);
+ Assert.AreEqual(0, message.RepeatedFixed32.Count);
+ Assert.AreEqual(0, message.RepeatedFixed64.Count);
+ Assert.AreEqual(0, message.RepeatedFloat.Count);
+ Assert.AreEqual(0, message.RepeatedForeignEnum.Count);
+ Assert.AreEqual(0, message.RepeatedForeignMessage.Count);
+ Assert.AreEqual(0, message.RepeatedImportEnum.Count);
+ Assert.AreEqual(0, message.RepeatedImportMessage.Count);
+ Assert.AreEqual(0, message.RepeatedNestedEnum.Count);
+ Assert.AreEqual(0, message.RepeatedNestedMessage.Count);
+ Assert.AreEqual(0, message.RepeatedPublicImportMessage.Count);
+ Assert.AreEqual(0, message.RepeatedSfixed32.Count);
+ Assert.AreEqual(0, message.RepeatedSfixed64.Count);
+ Assert.AreEqual(0, message.RepeatedSint32.Count);
+ Assert.AreEqual(0, message.RepeatedSint64.Count);
+ Assert.AreEqual(0, message.RepeatedString.Count);
+ Assert.AreEqual(0, message.RepeatedUint32.Count);
+ Assert.AreEqual(0, message.RepeatedUint64.Count);
+
+ // Oneof fields
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase);
+ Assert.AreEqual(0, message.OneofUint32);
+ Assert.AreEqual("", message.OneofString);
+ Assert.AreEqual(ByteString.Empty, message.OneofBytes);
+ Assert.IsNull(message.OneofNestedMessage);
+ }
+
+ [Test]
+ public void NullStringAndBytesRejected()
+ {
+ var message = new TestAllTypes();
+ Assert.Throws<ArgumentNullException>(() => message.SingleString = null);
+ Assert.Throws<ArgumentNullException>(() => message.OneofString = null);
+ Assert.Throws<ArgumentNullException>(() => message.SingleBytes = null);
+ Assert.Throws<ArgumentNullException>(() => message.OneofBytes = null);
+ }
+
+ [Test]
+ public void RoundTrip_Empty()
+ {
+ var message = new TestAllTypes();
+ // Without setting any values, there's nothing to write.
+ byte[] bytes = message.ToByteArray();
+ Assert.AreEqual(0, bytes.Length);
+ TestAllTypes parsed = TestAllTypes.Parser.ParseFrom(bytes);
+ Assert.AreEqual(message, parsed);
+ }
+
+ [Test]
+ public void RoundTrip_SingleValues()
+ {
+ var message = new TestAllTypes
+ {
+ SingleBool = true,
+ SingleBytes = ByteString.CopyFrom(1, 2, 3, 4),
+ SingleDouble = 23.5,
+ SingleFixed32 = 23,
+ SingleFixed64 = 1234567890123,
+ SingleFloat = 12.25f,
+ SingleForeignEnum = ForeignEnum.ForeignBar,
+ SingleForeignMessage = new ForeignMessage { C = 10 },
+ SingleImportEnum = ImportEnum.ImportBaz,
+ SingleImportMessage = new ImportMessage { D = 20 },
+ SingleInt32 = 100,
+ SingleInt64 = 3210987654321,
+ SingleNestedEnum = TestAllTypes.Types.NestedEnum.Foo,
+ SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 35 },
+ SinglePublicImportMessage = new PublicImportMessage { E = 54 },
+ SingleSfixed32 = -123,
+ SingleSfixed64 = -12345678901234,
+ SingleSint32 = -456,
+ SingleSint64 = -12345678901235,
+ SingleString = "test",
+ SingleUint32 = uint.MaxValue,
+ SingleUint64 = ulong.MaxValue
+ };
+
+ byte[] bytes = message.ToByteArray();
+ TestAllTypes parsed = TestAllTypes.Parser.ParseFrom(bytes);
+ Assert.AreEqual(message, parsed);
+ }
+
+ [Test]
+ public void RoundTrip_RepeatedValues()
+ {
+ var message = new TestAllTypes
+ {
+ RepeatedBool = { true, false },
+ RepeatedBytes = { ByteString.CopyFrom(1, 2, 3, 4), ByteString.CopyFrom(5, 6) },
+ RepeatedDouble = { -12.25, 23.5 },
+ RepeatedFixed32 = { uint.MaxValue, 23 },
+ RepeatedFixed64 = { ulong.MaxValue, 1234567890123 },
+ RepeatedFloat = { 100f, 12.25f },
+ RepeatedForeignEnum = { ForeignEnum.ForeignFoo, ForeignEnum.ForeignBar },
+ RepeatedForeignMessage = { new ForeignMessage(), new ForeignMessage { C = 10 } },
+ RepeatedImportEnum = { ImportEnum.ImportBaz, ImportEnum.Unspecified },
+ RepeatedImportMessage = { new ImportMessage { D = 20 }, new ImportMessage { D = 25 } },
+ RepeatedInt32 = { 100, 200 },
+ RepeatedInt64 = { 3210987654321, long.MaxValue },
+ RepeatedNestedEnum = { TestAllTypes.Types.NestedEnum.Foo, TestAllTypes.Types.NestedEnum.Neg },
+ RepeatedNestedMessage = { new TestAllTypes.Types.NestedMessage { Bb = 35 }, new TestAllTypes.Types.NestedMessage { Bb = 10 } },
+ RepeatedPublicImportMessage = { new PublicImportMessage { E = 54 }, new PublicImportMessage { E = -1 } },
+ RepeatedSfixed32 = { -123, 123 },
+ RepeatedSfixed64 = { -12345678901234, 12345678901234 },
+ RepeatedSint32 = { -456, 100 },
+ RepeatedSint64 = { -12345678901235, 123 },
+ RepeatedString = { "foo", "bar" },
+ RepeatedUint32 = { uint.MaxValue, uint.MinValue },
+ RepeatedUint64 = { ulong.MaxValue, uint.MinValue }
+ };
+
+ byte[] bytes = message.ToByteArray();
+ TestAllTypes parsed = TestAllTypes.Parser.ParseFrom(bytes);
+ Assert.AreEqual(message, parsed);
+ }
+
+ // Note that not every map within map_unittest_proto3 is used. They all go through very
+ // similar code paths. The fact that all maps are present is validation that we have codecs
+ // for every type.
+ [Test]
+ public void RoundTrip_Maps()
+ {
+ var message = new TestMap
+ {
+ MapBoolBool = {
+ { false, true },
+ { true, false }
+ },
+ MapInt32Bytes = {
+ { 5, ByteString.CopyFrom(6, 7, 8) },
+ { 25, ByteString.CopyFrom(1, 2, 3, 4, 5) },
+ { 10, ByteString.Empty }
+ },
+ MapInt32ForeignMessage = {
+ { 0, new ForeignMessage { C = 10 } },
+ { 5, new ForeignMessage() },
+ },
+ MapInt32Enum = {
+ { 1, MapEnum.Bar },
+ { 2000, MapEnum.Foo }
+ }
+ };
+
+ byte[] bytes = message.ToByteArray();
+ TestMap parsed = TestMap.Parser.ParseFrom(bytes);
+ Assert.AreEqual(message, parsed);
+ }
+
+ [Test]
+ public void MapWithEmptyEntry()
+ {
+ var message = new TestMap
+ {
+ MapInt32Bytes = { { 0, ByteString.Empty } }
+ };
+
+ byte[] bytes = message.ToByteArray();
+ Assert.AreEqual(2, bytes.Length); // Tag for field entry (1 byte), length of entry (0; 1 byte)
+
+ var parsed = TestMap.Parser.ParseFrom(bytes);
+ Assert.AreEqual(1, parsed.MapInt32Bytes.Count);
+ Assert.AreEqual(ByteString.Empty, parsed.MapInt32Bytes[0]);
+ }
+
+ [Test]
+ public void MapWithOnlyValue()
+ {
+ // Hand-craft the stream to contain a single entry with just a value.
+ var memoryStream = new MemoryStream();
+ var output = new CodedOutputStream(memoryStream);
+ output.WriteTag(TestMap.MapInt32ForeignMessageFieldNumber, WireFormat.WireType.LengthDelimited);
+ var nestedMessage = new ForeignMessage { C = 20 };
+ // Size of the entry (tag, size written by WriteMessage, data written by WriteMessage)
+ output.WriteLength(2 + nestedMessage.CalculateSize());
+ output.WriteTag(2, WireFormat.WireType.LengthDelimited);
+ output.WriteMessage(nestedMessage);
+ output.Flush();
+
+ var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());
+ Assert.AreEqual(nestedMessage, parsed.MapInt32ForeignMessage[0]);
+ }
+
+ [Test]
+ public void MapWithOnlyKey_PrimitiveValue()
+ {
+ // Hand-craft the stream to contain a single entry with just a key.
+ var memoryStream = new MemoryStream();
+ var output = new CodedOutputStream(memoryStream);
+ output.WriteTag(TestMap.MapInt32DoubleFieldNumber, WireFormat.WireType.LengthDelimited);
+ int key = 10;
+ output.WriteLength(1 + CodedOutputStream.ComputeInt32Size(key));
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key);
+ output.Flush();
+
+ var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());
+ Assert.AreEqual(0.0, parsed.MapInt32Double[key]);
+ }
+
+ [Test]
+ public void MapWithOnlyKey_MessageValue()
+ {
+ // Hand-craft the stream to contain a single entry with just a key.
+ var memoryStream = new MemoryStream();
+ var output = new CodedOutputStream(memoryStream);
+ output.WriteTag(TestMap.MapInt32ForeignMessageFieldNumber, WireFormat.WireType.LengthDelimited);
+ int key = 10;
+ output.WriteLength(1 + CodedOutputStream.ComputeInt32Size(key));
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key);
+ output.Flush();
+
+ var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());
+ Assert.AreEqual(new ForeignMessage(), parsed.MapInt32ForeignMessage[key]);
+ }
+
+ [Test]
+ public void MapIgnoresExtraFieldsWithinEntryMessages()
+ {
+ // Hand-craft the stream to contain a single entry with three fields
+ var memoryStream = new MemoryStream();
+ var output = new CodedOutputStream(memoryStream);
+
+ output.WriteTag(TestMap.MapInt32Int32FieldNumber, WireFormat.WireType.LengthDelimited);
+
+ var key = 10; // Field 1
+ var value = 20; // Field 2
+ var extra = 30; // Field 3
+
+ // Each field can be represented in a single byte, with a single byte tag.
+ // Total message size: 6 bytes.
+ output.WriteLength(6);
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key);
+ output.WriteTag(2, WireFormat.WireType.Varint);
+ output.WriteInt32(value);
+ output.WriteTag(3, WireFormat.WireType.Varint);
+ output.WriteInt32(extra);
+ output.Flush();
+
+ var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());
+ Assert.AreEqual(value, parsed.MapInt32Int32[key]);
+ }
+
+ [Test]
+ public void MapFieldOrderIsIrrelevant()
+ {
+ var memoryStream = new MemoryStream();
+ var output = new CodedOutputStream(memoryStream);
+
+ output.WriteTag(TestMap.MapInt32Int32FieldNumber, WireFormat.WireType.LengthDelimited);
+
+ var key = 10;
+ var value = 20;
+
+ // Each field can be represented in a single byte, with a single byte tag.
+ // Total message size: 4 bytes.
+ output.WriteLength(4);
+ output.WriteTag(2, WireFormat.WireType.Varint);
+ output.WriteInt32(value);
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key);
+ output.Flush();
+
+ var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());
+ Assert.AreEqual(value, parsed.MapInt32Int32[key]);
+ }
+
+ [Test]
+ public void MapNonContiguousEntries()
+ {
+ var memoryStream = new MemoryStream();
+ var output = new CodedOutputStream(memoryStream);
+
+ // Message structure:
+ // Entry for MapInt32Int32
+ // Entry for MapStringString
+ // Entry for MapInt32Int32
+
+ // First entry
+ var key1 = 10;
+ var value1 = 20;
+ output.WriteTag(TestMap.MapInt32Int32FieldNumber, WireFormat.WireType.LengthDelimited);
+ output.WriteLength(4);
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key1);
+ output.WriteTag(2, WireFormat.WireType.Varint);
+ output.WriteInt32(value1);
+
+ // Second entry
+ var key2 = "a";
+ var value2 = "b";
+ output.WriteTag(TestMap.MapStringStringFieldNumber, WireFormat.WireType.LengthDelimited);
+ output.WriteLength(6); // 3 bytes per entry: tag, size, character
+ output.WriteTag(1, WireFormat.WireType.LengthDelimited);
+ output.WriteString(key2);
+ output.WriteTag(2, WireFormat.WireType.LengthDelimited);
+ output.WriteString(value2);
+
+ // Third entry
+ var key3 = 15;
+ var value3 = 25;
+ output.WriteTag(TestMap.MapInt32Int32FieldNumber, WireFormat.WireType.LengthDelimited);
+ output.WriteLength(4);
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key3);
+ output.WriteTag(2, WireFormat.WireType.Varint);
+ output.WriteInt32(value3);
+
+ output.Flush();
+ var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());
+ var expected = new TestMap
+ {
+ MapInt32Int32 = { { key1, value1 }, { key3, value3 } },
+ MapStringString = { { key2, value2 } }
+ };
+ Assert.AreEqual(expected, parsed);
+ }
+
+ [Test]
+ public void DuplicateKeys_LastEntryWins()
+ {
+ var memoryStream = new MemoryStream();
+ var output = new CodedOutputStream(memoryStream);
+
+ var key = 10;
+ var value1 = 20;
+ var value2 = 30;
+
+ // First entry
+ output.WriteTag(TestMap.MapInt32Int32FieldNumber, WireFormat.WireType.LengthDelimited);
+ output.WriteLength(4);
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key);
+ output.WriteTag(2, WireFormat.WireType.Varint);
+ output.WriteInt32(value1);
+
+ // Second entry - same key, different value
+ output.WriteTag(TestMap.MapInt32Int32FieldNumber, WireFormat.WireType.LengthDelimited);
+ output.WriteLength(4);
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key);
+ output.WriteTag(2, WireFormat.WireType.Varint);
+ output.WriteInt32(value2);
+ output.Flush();
+
+ var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());
+ Assert.AreEqual(value2, parsed.MapInt32Int32[key]);
+ }
+
+ [Test]
+ public void CloneSingleNonMessageValues()
+ {
+ var original = new TestAllTypes
+ {
+ SingleBool = true,
+ SingleBytes = ByteString.CopyFrom(1, 2, 3, 4),
+ SingleDouble = 23.5,
+ SingleFixed32 = 23,
+ SingleFixed64 = 1234567890123,
+ SingleFloat = 12.25f,
+ SingleInt32 = 100,
+ SingleInt64 = 3210987654321,
+ SingleNestedEnum = TestAllTypes.Types.NestedEnum.Foo,
+ SingleSfixed32 = -123,
+ SingleSfixed64 = -12345678901234,
+ SingleSint32 = -456,
+ SingleSint64 = -12345678901235,
+ SingleString = "test",
+ SingleUint32 = uint.MaxValue,
+ SingleUint64 = ulong.MaxValue
+ };
+ var clone = original.Clone();
+ Assert.AreNotSame(original, clone);
+ Assert.AreEqual(original, clone);
+ // Just as a single example
+ clone.SingleInt32 = 150;
+ Assert.AreNotEqual(original, clone);
+ }
+
+ [Test]
+ public void CloneRepeatedNonMessageValues()
+ {
+ var original = new TestAllTypes
+ {
+ RepeatedBool = { true, false },
+ RepeatedBytes = { ByteString.CopyFrom(1, 2, 3, 4), ByteString.CopyFrom(5, 6) },
+ RepeatedDouble = { -12.25, 23.5 },
+ RepeatedFixed32 = { uint.MaxValue, 23 },
+ RepeatedFixed64 = { ulong.MaxValue, 1234567890123 },
+ RepeatedFloat = { 100f, 12.25f },
+ RepeatedInt32 = { 100, 200 },
+ RepeatedInt64 = { 3210987654321, long.MaxValue },
+ RepeatedNestedEnum = { TestAllTypes.Types.NestedEnum.Foo, TestAllTypes.Types.NestedEnum.Neg },
+ RepeatedSfixed32 = { -123, 123 },
+ RepeatedSfixed64 = { -12345678901234, 12345678901234 },
+ RepeatedSint32 = { -456, 100 },
+ RepeatedSint64 = { -12345678901235, 123 },
+ RepeatedString = { "foo", "bar" },
+ RepeatedUint32 = { uint.MaxValue, uint.MinValue },
+ RepeatedUint64 = { ulong.MaxValue, uint.MinValue }
+ };
+
+ var clone = original.Clone();
+ Assert.AreNotSame(original, clone);
+ Assert.AreEqual(original, clone);
+ // Just as a single example
+ clone.RepeatedDouble.Add(25.5);
+ Assert.AreNotEqual(original, clone);
+ }
+
+ [Test]
+ public void CloneSingleMessageField()
+ {
+ var original = new TestAllTypes
+ {
+ SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 20 }
+ };
+
+ var clone = original.Clone();
+ Assert.AreNotSame(original, clone);
+ Assert.AreNotSame(original.SingleNestedMessage, clone.SingleNestedMessage);
+ Assert.AreEqual(original, clone);
+
+ clone.SingleNestedMessage.Bb = 30;
+ Assert.AreNotEqual(original, clone);
+ }
+
+ [Test]
+ public void CloneRepeatedMessageField()
+ {
+ var original = new TestAllTypes
+ {
+ RepeatedNestedMessage = { new TestAllTypes.Types.NestedMessage { Bb = 20 } }
+ };
+
+ var clone = original.Clone();
+ Assert.AreNotSame(original, clone);
+ Assert.AreNotSame(original.RepeatedNestedMessage, clone.RepeatedNestedMessage);
+ Assert.AreNotSame(original.RepeatedNestedMessage[0], clone.RepeatedNestedMessage[0]);
+ Assert.AreEqual(original, clone);
+
+ clone.RepeatedNestedMessage[0].Bb = 30;
+ Assert.AreNotEqual(original, clone);
+ }
+
+ [Test]
+ public void CloneOneofField()
+ {
+ var original = new TestAllTypes
+ {
+ OneofNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 20 }
+ };
+
+ var clone = original.Clone();
+ Assert.AreNotSame(original, clone);
+ Assert.AreEqual(original, clone);
+
+ // We should have cloned the message
+ original.OneofNestedMessage.Bb = 30;
+ Assert.AreNotEqual(original, clone);
+ }
+
+ [Test]
+ public void OneofProperties()
+ {
+ // Switch the oneof case between each of the different options, and check everything behaves
+ // as expected in each case.
+ var message = new TestAllTypes();
+ Assert.AreEqual("", message.OneofString);
+ Assert.AreEqual(0, message.OneofUint32);
+ Assert.AreEqual(ByteString.Empty, message.OneofBytes);
+ Assert.IsNull(message.OneofNestedMessage);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase);
+
+ message.OneofString = "sample";
+ Assert.AreEqual("sample", message.OneofString);
+ Assert.AreEqual(0, message.OneofUint32);
+ Assert.AreEqual(ByteString.Empty, message.OneofBytes);
+ Assert.IsNull(message.OneofNestedMessage);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofString, message.OneofFieldCase);
+
+ var bytes = ByteString.CopyFrom(1, 2, 3);
+ message.OneofBytes = bytes;
+ Assert.AreEqual("", message.OneofString);
+ Assert.AreEqual(0, message.OneofUint32);
+ Assert.AreEqual(bytes, message.OneofBytes);
+ Assert.IsNull(message.OneofNestedMessage);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofBytes, message.OneofFieldCase);
+
+ message.OneofUint32 = 20;
+ Assert.AreEqual("", message.OneofString);
+ Assert.AreEqual(20, message.OneofUint32);
+ Assert.AreEqual(ByteString.Empty, message.OneofBytes);
+ Assert.IsNull(message.OneofNestedMessage);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, message.OneofFieldCase);
+
+ var nestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 25 };
+ message.OneofNestedMessage = nestedMessage;
+ Assert.AreEqual("", message.OneofString);
+ Assert.AreEqual(0, message.OneofUint32);
+ Assert.AreEqual(ByteString.Empty, message.OneofBytes);
+ Assert.AreEqual(nestedMessage, message.OneofNestedMessage);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofNestedMessage, message.OneofFieldCase);
+
+ message.ClearOneofField();
+ Assert.AreEqual("", message.OneofString);
+ Assert.AreEqual(0, message.OneofUint32);
+ Assert.AreEqual(ByteString.Empty, message.OneofBytes);
+ Assert.IsNull(message.OneofNestedMessage);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase);
+ }
+
+ [Test]
+ public void Oneof_DefaultValuesNotEqual()
+ {
+ var message1 = new TestAllTypes { OneofString = "" };
+ var message2 = new TestAllTypes { OneofUint32 = 0 };
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofString, message1.OneofFieldCase);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, message2.OneofFieldCase);
+ Assert.AreNotEqual(message1, message2);
+ }
+
+ [Test]
+ public void OneofSerialization_NonDefaultValue()
+ {
+ var message = new TestAllTypes();
+ message.OneofString = "this would take a bit of space";
+ message.OneofUint32 = 10;
+ var bytes = message.ToByteArray();
+ Assert.AreEqual(3, bytes.Length); // 2 bytes for the tag + 1 for the value - no string!
+
+ var message2 = TestAllTypes.Parser.ParseFrom(bytes);
+ Assert.AreEqual(message, message2);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, message2.OneofFieldCase);
+ }
+
+ [Test]
+ public void OneofSerialization_DefaultValue()
+ {
+ var message = new TestAllTypes();
+ message.OneofString = "this would take a bit of space";
+ message.OneofUint32 = 0; // This is the default value for UInt32; normally wouldn't be serialized
+ var bytes = message.ToByteArray();
+ Assert.AreEqual(3, bytes.Length); // 2 bytes for the tag + 1 for the value - it's still serialized
+
+ var message2 = TestAllTypes.Parser.ParseFrom(bytes);
+ Assert.AreEqual(message, message2);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, message2.OneofFieldCase);
+ }
+
+ [Test]
+ public void IgnoreUnknownFields_RealDataStillRead()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ var unusedFieldNumber = 23456;
+ Assert.IsFalse(TestAllTypes.Descriptor.Fields.InDeclarationOrder().Select(x => x.FieldNumber).Contains(unusedFieldNumber));
+ output.WriteTag(unusedFieldNumber, WireFormat.WireType.LengthDelimited);
+ output.WriteString("ignore me");
+ message.WriteTo(output);
+ output.Flush();
+
+ stream.Position = 0;
+ var parsed = TestAllTypes.Parser.ParseFrom(stream);
+ Assert.AreEqual(message, parsed);
+ }
+
+ [Test]
+ public void IgnoreUnknownFields_AllTypes()
+ {
+ // Simple way of ensuring we can skip all kinds of fields.
+ var data = SampleMessages.CreateFullTestAllTypes().ToByteArray();
+ var empty = Empty.Parser.ParseFrom(data);
+ Assert.AreEqual(new Empty(), empty);
+ }
+
+ // This was originally seen as a conformance test failure.
+ [Test]
+ public void TruncatedMessageFieldThrows()
+ {
+ // 130, 3 is the message tag
+ // 1 is the data length - but there's no data.
+ var data = new byte[] { 130, 3, 1 };
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseFrom(data));
+ }
+
+ /// <summary>
+ /// Demonstrates current behaviour with an extraneous end group tag - see issue 688
+ /// for details; we may want to change this.
+ /// </summary>
+ [Test]
+ public void ExtraEndGroupThrows()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+
+ output.WriteTag(TestAllTypes.SingleFixed32FieldNumber, WireFormat.WireType.Fixed32);
+ output.WriteFixed32(123);
+ output.WriteTag(100, WireFormat.WireType.EndGroup);
+
+ output.Flush();
+
+ stream.Position = 0;
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseFrom(stream));
+ }
+
+ [Test]
+ public void CustomDiagnosticMessage_DirectToStringCall()
+ {
+ var message = new ForeignMessage { C = 31 };
+ Assert.AreEqual("{ \"c\": 31, \"@cInHex\": \"1f\" }", message.ToString());
+ Assert.AreEqual("{ \"c\": 31 }", JsonFormatter.Default.Format(message));
+ }
+
+ [Test]
+ public void CustomDiagnosticMessage_Nested()
+ {
+ var message = new TestAllTypes { SingleForeignMessage = new ForeignMessage { C = 16 } };
+ Assert.AreEqual("{ \"singleForeignMessage\": { \"c\": 16, \"@cInHex\": \"10\" } }", message.ToString());
+ Assert.AreEqual("{ \"singleForeignMessage\": { \"c\": 16 } }", JsonFormatter.Default.Format(message));
+ }
+
+ [Test]
+ public void CustomDiagnosticMessage_DirectToTextWriterCall()
+ {
+ var message = new ForeignMessage { C = 31 };
+ var writer = new StringWriter();
+ JsonFormatter.Default.Format(message, writer);
+ Assert.AreEqual("{ \"c\": 31 }", writer.ToString());
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.xproj b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.xproj
new file mode 100644
index 0000000000..a9a1cc0495
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.xproj
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>580eb013-d3c7-4578-b845-015f4a3b0591</ProjectGuid>
+ <RootNamespace>Google.Protobuf.Test</RootNamespace>
+ <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
+ <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <SchemaVersion>2.0</SchemaVersion>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
+</Project> \ No newline at end of file
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/IssuesTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/IssuesTest.cs
new file mode 100644
index 0000000000..a38d6b08b5
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/IssuesTest.cs
@@ -0,0 +1,82 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using Google.Protobuf.Reflection;
+using UnitTest.Issues.TestProtos;
+using NUnit.Framework;
+
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Tests for issues which aren't easily compartmentalized into other unit tests.
+ /// </summary>
+ public class IssuesTest
+ {
+ // Issue 45
+ [Test]
+ public void FieldCalledItem()
+ {
+ ItemField message = new ItemField { Item = 3 };
+ FieldDescriptor field = ItemField.Descriptor.FindFieldByName("item");
+ Assert.NotNull(field);
+ Assert.AreEqual(3, (int)field.Accessor.GetValue(message));
+ }
+
+ [Test]
+ public void ReservedNames()
+ {
+ var message = new ReservedNames { Types_ = 10, Descriptor_ = 20 };
+ // Underscores aren't reflected in the JSON.
+ Assert.AreEqual("{ \"types\": 10, \"descriptor\": 20 }", message.ToString());
+ }
+
+ [Test]
+ public void JsonNameParseTest()
+ {
+ var settings = new JsonParser.Settings(10, TypeRegistry.FromFiles(UnittestIssuesReflection.Descriptor));
+ var parser = new JsonParser(settings);
+
+ // It is safe to use either original field name or explicitly specified json_name
+ Assert.AreEqual(new TestJsonName { Name = "test", Description = "test2", Guid = "test3" },
+ parser.Parse<TestJsonName>("{ \"name\": \"test\", \"desc\": \"test2\", \"guid\": \"test3\" }"));
+ }
+
+ [Test]
+ public void JsonNameFormatTest()
+ {
+ var message = new TestJsonName { Name = "test", Description = "test2", Guid = "test3" };
+ Assert.AreEqual("{ \"name\": \"test\", \"desc\": \"test2\", \"exid\": \"test3\" }",
+ JsonFormatter.Default.Format(message));
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/JsonParserTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/JsonParserTest.cs
new file mode 100644
index 0000000000..f595455aa1
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/JsonParserTest.cs
@@ -0,0 +1,939 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using Google.Protobuf.Reflection;
+using Google.Protobuf.TestProtos;
+using Google.Protobuf.WellKnownTypes;
+using NUnit.Framework;
+using System;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Unit tests for JSON parsing.
+ /// </summary>
+ public class JsonParserTest
+ {
+ // Sanity smoke test
+ [Test]
+ public void AllTypesRoundtrip()
+ {
+ AssertRoundtrip(SampleMessages.CreateFullTestAllTypes());
+ }
+
+ [Test]
+ public void Maps()
+ {
+ AssertRoundtrip(new TestMap { MapStringString = { { "with spaces", "bar" }, { "a", "b" } } });
+ AssertRoundtrip(new TestMap { MapInt32Int32 = { { 0, 1 }, { 2, 3 } } });
+ AssertRoundtrip(new TestMap { MapBoolBool = { { false, true }, { true, false } } });
+ }
+
+ [Test]
+ [TestCase(" 1 ")]
+ [TestCase("+1")]
+ [TestCase("1,000")]
+ [TestCase("1.5")]
+ public void IntegerMapKeysAreStrict(string keyText)
+ {
+ // Test that integer parsing is strict. We assume that if this is correct for int32,
+ // it's correct for other numeric key types.
+ var json = "{ \"mapInt32Int32\": { \"" + keyText + "\" : \"1\" } }";
+ Assert.Throws<InvalidProtocolBufferException>(() => JsonParser.Default.Parse<TestMap>(json));
+ }
+
+ [Test]
+ public void OriginalFieldNameAccepted()
+ {
+ var json = "{ \"single_int32\": 10 }";
+ var expected = new TestAllTypes { SingleInt32 = 10 };
+ Assert.AreEqual(expected, TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void SourceContextRoundtrip()
+ {
+ AssertRoundtrip(new SourceContext { FileName = "foo.proto" });
+ }
+
+ [Test]
+ public void SingularWrappers_DefaultNonNullValues()
+ {
+ var message = new TestWellKnownTypes
+ {
+ StringField = "",
+ BytesField = ByteString.Empty,
+ BoolField = false,
+ FloatField = 0f,
+ DoubleField = 0d,
+ Int32Field = 0,
+ Int64Field = 0,
+ Uint32Field = 0,
+ Uint64Field = 0
+ };
+ AssertRoundtrip(message);
+ }
+
+ [Test]
+ public void SingularWrappers_NonDefaultValues()
+ {
+ var message = new TestWellKnownTypes
+ {
+ StringField = "x",
+ BytesField = ByteString.CopyFrom(1, 2, 3),
+ BoolField = true,
+ FloatField = 12.5f,
+ DoubleField = 12.25d,
+ Int32Field = 1,
+ Int64Field = 2,
+ Uint32Field = 3,
+ Uint64Field = 4
+ };
+ AssertRoundtrip(message);
+ }
+
+ [Test]
+ public void SingularWrappers_ExplicitNulls()
+ {
+ // When we parse the "valueField": null part, we remember it... basically, it's one case
+ // where explicit default values don't fully roundtrip.
+ var message = new TestWellKnownTypes { ValueField = Value.ForNull() };
+ var json = new JsonFormatter(new JsonFormatter.Settings(true)).Format(message);
+ var parsed = JsonParser.Default.Parse<TestWellKnownTypes>(json);
+ Assert.AreEqual(message, parsed);
+ }
+
+ [Test]
+ [TestCase(typeof(BoolValue), "true", true)]
+ [TestCase(typeof(Int32Value), "32", 32)]
+ [TestCase(typeof(Int64Value), "32", 32L)]
+ [TestCase(typeof(Int64Value), "\"32\"", 32L)]
+ [TestCase(typeof(UInt32Value), "32", 32U)]
+ [TestCase(typeof(UInt64Value), "\"32\"", 32UL)]
+ [TestCase(typeof(UInt64Value), "32", 32UL)]
+ [TestCase(typeof(StringValue), "\"foo\"", "foo")]
+ [TestCase(typeof(FloatValue), "1.5", 1.5f)]
+ [TestCase(typeof(DoubleValue), "1.5", 1.5d)]
+ public void Wrappers_Standalone(System.Type wrapperType, string json, object expectedValue)
+ {
+ IMessage parsed = (IMessage)Activator.CreateInstance(wrapperType);
+ IMessage expected = (IMessage)Activator.CreateInstance(wrapperType);
+ JsonParser.Default.Merge(parsed, "null");
+ Assert.AreEqual(expected, parsed);
+
+ JsonParser.Default.Merge(parsed, json);
+ expected.Descriptor.Fields[WrappersReflection.WrapperValueFieldNumber].Accessor.SetValue(expected, expectedValue);
+ Assert.AreEqual(expected, parsed);
+ }
+
+ [Test]
+ public void ExplicitNullValue()
+ {
+ string json = "{\"valueField\": null}";
+ var message = JsonParser.Default.Parse<TestWellKnownTypes>(json);
+ Assert.AreEqual(new TestWellKnownTypes { ValueField = Value.ForNull() }, message);
+ }
+
+ [Test]
+ public void BytesWrapper_Standalone()
+ {
+ ByteString data = ByteString.CopyFrom(1, 2, 3);
+ // Can't do this with attributes...
+ var parsed = JsonParser.Default.Parse<BytesValue>(WrapInQuotes(data.ToBase64()));
+ var expected = new BytesValue { Value = data };
+ Assert.AreEqual(expected, parsed);
+ }
+
+ [Test]
+ public void RepeatedWrappers()
+ {
+ var message = new RepeatedWellKnownTypes
+ {
+ BoolField = { true, false },
+ BytesField = { ByteString.CopyFrom(1, 2, 3), ByteString.CopyFrom(4, 5, 6), ByteString.Empty },
+ DoubleField = { 12.5, -1.5, 0d },
+ FloatField = { 123.25f, -20f, 0f },
+ Int32Field = { int.MaxValue, int.MinValue, 0 },
+ Int64Field = { long.MaxValue, long.MinValue, 0L },
+ StringField = { "First", "Second", "" },
+ Uint32Field = { uint.MaxValue, uint.MinValue, 0U },
+ Uint64Field = { ulong.MaxValue, ulong.MinValue, 0UL },
+ };
+ AssertRoundtrip(message);
+ }
+
+ [Test]
+ public void RepeatedField_NullElementProhibited()
+ {
+ string json = "{ \"repeated_foreign_message\": [null] }";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void RepeatedField_NullOverallValueAllowed()
+ {
+ string json = "{ \"repeated_foreign_message\": null }";
+ Assert.AreEqual(new TestAllTypes(), TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("{ \"mapInt32Int32\": { \"10\": null }")]
+ [TestCase("{ \"mapStringString\": { \"abc\": null }")]
+ [TestCase("{ \"mapInt32ForeignMessage\": { \"10\": null }")]
+ public void MapField_NullValueProhibited(string json)
+ {
+ Assert.Throws<InvalidProtocolBufferException>(() => TestMap.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void MapField_NullOverallValueAllowed()
+ {
+ string json = "{ \"mapInt32Int32\": null }";
+ Assert.AreEqual(new TestMap(), TestMap.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void IndividualWrapperTypes()
+ {
+ Assert.AreEqual(new StringValue { Value = "foo" }, StringValue.Parser.ParseJson("\"foo\""));
+ Assert.AreEqual(new Int32Value { Value = 1 }, Int32Value.Parser.ParseJson("1"));
+ // Can parse strings directly too
+ Assert.AreEqual(new Int32Value { Value = 1 }, Int32Value.Parser.ParseJson("\"1\""));
+ }
+
+ private static void AssertRoundtrip<T>(T message) where T : IMessage<T>, new()
+ {
+ var clone = message.Clone();
+ var json = JsonFormatter.Default.Format(message);
+ var parsed = JsonParser.Default.Parse<T>(json);
+ Assert.AreEqual(clone, parsed);
+ }
+
+ [Test]
+ [TestCase("0", 0)]
+ [TestCase("-0", 0)] // Not entirely clear whether we intend to allow this...
+ [TestCase("1", 1)]
+ [TestCase("-1", -1)]
+ [TestCase("2147483647", 2147483647)]
+ [TestCase("-2147483648", -2147483648)]
+ public void StringToInt32_Valid(string jsonValue, int expectedParsedValue)
+ {
+ string json = "{ \"singleInt32\": \"" + jsonValue + "\"}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleInt32);
+ }
+
+ [Test]
+ [TestCase("+0")]
+ [TestCase(" 1")]
+ [TestCase("1 ")]
+ [TestCase("00")]
+ [TestCase("-00")]
+ [TestCase("--1")]
+ [TestCase("+1")]
+ [TestCase("1.5")]
+ [TestCase("1e10")]
+ [TestCase("2147483648")]
+ [TestCase("-2147483649")]
+ public void StringToInt32_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleInt32\": \"" + jsonValue + "\"}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0U)]
+ [TestCase("1", 1U)]
+ [TestCase("4294967295", 4294967295U)]
+ public void StringToUInt32_Valid(string jsonValue, uint expectedParsedValue)
+ {
+ string json = "{ \"singleUint32\": \"" + jsonValue + "\"}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleUint32);
+ }
+
+ // Assume that anything non-bounds-related is covered in the Int32 case
+ [Test]
+ [TestCase("-1")]
+ [TestCase("4294967296")]
+ public void StringToUInt32_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleUint32\": \"" + jsonValue + "\"}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0L)]
+ [TestCase("1", 1L)]
+ [TestCase("-1", -1L)]
+ [TestCase("9223372036854775807", 9223372036854775807)]
+ [TestCase("-9223372036854775808", -9223372036854775808)]
+ public void StringToInt64_Valid(string jsonValue, long expectedParsedValue)
+ {
+ string json = "{ \"singleInt64\": \"" + jsonValue + "\"}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleInt64);
+ }
+
+ // Assume that anything non-bounds-related is covered in the Int32 case
+ [Test]
+ [TestCase("-9223372036854775809")]
+ [TestCase("9223372036854775808")]
+ public void StringToInt64_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleInt64\": \"" + jsonValue + "\"}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0UL)]
+ [TestCase("1", 1UL)]
+ [TestCase("18446744073709551615", 18446744073709551615)]
+ public void StringToUInt64_Valid(string jsonValue, ulong expectedParsedValue)
+ {
+ string json = "{ \"singleUint64\": \"" + jsonValue + "\"}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleUint64);
+ }
+
+ // Assume that anything non-bounds-related is covered in the Int32 case
+ [Test]
+ [TestCase("-1")]
+ [TestCase("18446744073709551616")]
+ public void StringToUInt64_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleUint64\": \"" + jsonValue + "\"}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0d)]
+ [TestCase("1", 1d)]
+ [TestCase("1.000000", 1d)]
+ [TestCase("1.0000000000000000000000001", 1d)] // We don't notice that we haven't preserved the exact value
+ [TestCase("-1", -1d)]
+ [TestCase("1e1", 10d)]
+ [TestCase("1e01", 10d)] // Leading decimals are allowed in exponents
+ [TestCase("1E1", 10d)] // Either case is fine
+ [TestCase("-1e1", -10d)]
+ [TestCase("1.5e1", 15d)]
+ [TestCase("-1.5e1", -15d)]
+ [TestCase("15e-1", 1.5d)]
+ [TestCase("-15e-1", -1.5d)]
+ [TestCase("1.79769e308", 1.79769e308)]
+ [TestCase("-1.79769e308", -1.79769e308)]
+ [TestCase("Infinity", double.PositiveInfinity)]
+ [TestCase("-Infinity", double.NegativeInfinity)]
+ [TestCase("NaN", double.NaN)]
+ public void StringToDouble_Valid(string jsonValue, double expectedParsedValue)
+ {
+ string json = "{ \"singleDouble\": \"" + jsonValue + "\"}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleDouble);
+ }
+
+ [Test]
+ [TestCase("1.7977e308")]
+ [TestCase("-1.7977e308")]
+ [TestCase("1e309")]
+ [TestCase("1,0")]
+ [TestCase("1.0.0")]
+ [TestCase("+1")]
+ [TestCase("00")]
+ [TestCase("01")]
+ [TestCase("-00")]
+ [TestCase("-01")]
+ [TestCase("--1")]
+ [TestCase(" Infinity")]
+ [TestCase(" -Infinity")]
+ [TestCase("NaN ")]
+ [TestCase("Infinity ")]
+ [TestCase("-Infinity ")]
+ [TestCase(" NaN")]
+ [TestCase("INFINITY")]
+ [TestCase("nan")]
+ [TestCase("\u00BD")] // 1/2 as a single Unicode character. Just sanity checking...
+ public void StringToDouble_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleDouble\": \"" + jsonValue + "\"}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0f)]
+ [TestCase("1", 1f)]
+ [TestCase("1.000000", 1f)]
+ [TestCase("-1", -1f)]
+ [TestCase("3.402823e38", 3.402823e38f)]
+ [TestCase("-3.402823e38", -3.402823e38f)]
+ [TestCase("1.5e1", 15f)]
+ [TestCase("15e-1", 1.5f)]
+ public void StringToFloat_Valid(string jsonValue, float expectedParsedValue)
+ {
+ string json = "{ \"singleFloat\": \"" + jsonValue + "\"}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleFloat);
+ }
+
+ [Test]
+ [TestCase("3.402824e38")]
+ [TestCase("-3.402824e38")]
+ [TestCase("1,0")]
+ [TestCase("1.0.0")]
+ [TestCase("+1")]
+ [TestCase("00")]
+ [TestCase("--1")]
+ public void StringToFloat_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleFloat\": \"" + jsonValue + "\"}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0)]
+ [TestCase("-0", 0)] // Not entirely clear whether we intend to allow this...
+ [TestCase("1", 1)]
+ [TestCase("-1", -1)]
+ [TestCase("2147483647", 2147483647)]
+ [TestCase("-2147483648", -2147483648)]
+ [TestCase("1e1", 10)]
+ [TestCase("-1e1", -10)]
+ [TestCase("10.00", 10)]
+ [TestCase("-10.00", -10)]
+ public void NumberToInt32_Valid(string jsonValue, int expectedParsedValue)
+ {
+ string json = "{ \"singleInt32\": " + jsonValue + "}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleInt32);
+ }
+
+ [Test]
+ [TestCase("+0", typeof(InvalidJsonException))]
+ [TestCase("00", typeof(InvalidJsonException))]
+ [TestCase("-00", typeof(InvalidJsonException))]
+ [TestCase("--1", typeof(InvalidJsonException))]
+ [TestCase("+1", typeof(InvalidJsonException))]
+ [TestCase("1.5", typeof(InvalidProtocolBufferException))]
+ // Value is out of range
+ [TestCase("1e10", typeof(InvalidProtocolBufferException))]
+ [TestCase("2147483648", typeof(InvalidProtocolBufferException))]
+ [TestCase("-2147483649", typeof(InvalidProtocolBufferException))]
+ public void NumberToInt32_Invalid(string jsonValue, System.Type expectedExceptionType)
+ {
+ string json = "{ \"singleInt32\": " + jsonValue + "}";
+ Assert.Throws(expectedExceptionType, () => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0U)]
+ [TestCase("1", 1U)]
+ [TestCase("4294967295", 4294967295U)]
+ public void NumberToUInt32_Valid(string jsonValue, uint expectedParsedValue)
+ {
+ string json = "{ \"singleUint32\": " + jsonValue + "}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleUint32);
+ }
+
+ // Assume that anything non-bounds-related is covered in the Int32 case
+ [Test]
+ [TestCase("-1")]
+ [TestCase("4294967296")]
+ public void NumberToUInt32_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleUint32\": " + jsonValue + "}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0L)]
+ [TestCase("1", 1L)]
+ [TestCase("-1", -1L)]
+ // long.MaxValue isn't actually representable as a double. This string value is the highest
+ // representable value which isn't greater than long.MaxValue.
+ [TestCase("9223372036854774784", 9223372036854774784)]
+ [TestCase("-9223372036854775808", -9223372036854775808)]
+ public void NumberToInt64_Valid(string jsonValue, long expectedParsedValue)
+ {
+ string json = "{ \"singleInt64\": " + jsonValue + "}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleInt64);
+ }
+
+ // Assume that anything non-bounds-related is covered in the Int32 case
+ [Test]
+ [TestCase("9223372036854775808")]
+ // Theoretical bound would be -9223372036854775809, but when that is parsed to a double
+ // we end up with the exact value of long.MinValue due to lack of precision. The value here
+ // is the "next double down".
+ [TestCase("-9223372036854780000")]
+ public void NumberToInt64_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleInt64\": " + jsonValue + "}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0UL)]
+ [TestCase("1", 1UL)]
+ // ulong.MaxValue isn't representable as a double. This value is the largest double within
+ // the range of ulong.
+ [TestCase("18446744073709549568", 18446744073709549568UL)]
+ public void NumberToUInt64_Valid(string jsonValue, ulong expectedParsedValue)
+ {
+ string json = "{ \"singleUint64\": " + jsonValue + "}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleUint64);
+ }
+
+ // Assume that anything non-bounds-related is covered in the Int32 case
+ [Test]
+ [TestCase("-1")]
+ [TestCase("18446744073709551616")]
+ public void NumberToUInt64_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleUint64\": " + jsonValue + "}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0d)]
+ [TestCase("1", 1d)]
+ [TestCase("1.000000", 1d)]
+ [TestCase("1.0000000000000000000000001", 1d)] // We don't notice that we haven't preserved the exact value
+ [TestCase("-1", -1d)]
+ [TestCase("1e1", 10d)]
+ [TestCase("1e01", 10d)] // Leading decimals are allowed in exponents
+ [TestCase("1E1", 10d)] // Either case is fine
+ [TestCase("-1e1", -10d)]
+ [TestCase("1.5e1", 15d)]
+ [TestCase("-1.5e1", -15d)]
+ [TestCase("15e-1", 1.5d)]
+ [TestCase("-15e-1", -1.5d)]
+ [TestCase("1.79769e308", 1.79769e308)]
+ [TestCase("-1.79769e308", -1.79769e308)]
+ public void NumberToDouble_Valid(string jsonValue, double expectedParsedValue)
+ {
+ string json = "{ \"singleDouble\": " + jsonValue + "}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleDouble);
+ }
+
+ [Test]
+ [TestCase("1.7977e308")]
+ [TestCase("-1.7977e308")]
+ [TestCase("1e309")]
+ [TestCase("1,0")]
+ [TestCase("1.0.0")]
+ [TestCase("+1")]
+ [TestCase("00")]
+ [TestCase("--1")]
+ [TestCase("\u00BD")] // 1/2 as a single Unicode character. Just sanity checking...
+ public void NumberToDouble_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleDouble\": " + jsonValue + "}";
+ Assert.Throws<InvalidJsonException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0f)]
+ [TestCase("1", 1f)]
+ [TestCase("1.000000", 1f)]
+ [TestCase("-1", -1f)]
+ [TestCase("3.402823e38", 3.402823e38f)]
+ [TestCase("-3.402823e38", -3.402823e38f)]
+ [TestCase("1.5e1", 15f)]
+ [TestCase("15e-1", 1.5f)]
+ public void NumberToFloat_Valid(string jsonValue, float expectedParsedValue)
+ {
+ string json = "{ \"singleFloat\": " + jsonValue + "}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleFloat);
+ }
+
+ [Test]
+ [TestCase("3.402824e38", typeof(InvalidProtocolBufferException))]
+ [TestCase("-3.402824e38", typeof(InvalidProtocolBufferException))]
+ [TestCase("1,0", typeof(InvalidJsonException))]
+ [TestCase("1.0.0", typeof(InvalidJsonException))]
+ [TestCase("+1", typeof(InvalidJsonException))]
+ [TestCase("00", typeof(InvalidJsonException))]
+ [TestCase("--1", typeof(InvalidJsonException))]
+ public void NumberToFloat_Invalid(string jsonValue, System.Type expectedExceptionType)
+ {
+ string json = "{ \"singleFloat\": " + jsonValue + "}";
+ Assert.Throws(expectedExceptionType, () => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ // The simplest way of testing that the value has parsed correctly is to reformat it,
+ // as we trust the formatting. In many cases that will give the same result as the input,
+ // so in those cases we accept an expectedFormatted value of null. Sometimes the results
+ // will be different though, due to a different number of digits being provided.
+ [Test]
+ // Z offset
+ [TestCase("2015-10-09T14:46:23.123456789Z", null)]
+ [TestCase("2015-10-09T14:46:23.123456Z", null)]
+ [TestCase("2015-10-09T14:46:23.123Z", null)]
+ [TestCase("2015-10-09T14:46:23Z", null)]
+ [TestCase("2015-10-09T14:46:23.123456000Z", "2015-10-09T14:46:23.123456Z")]
+ [TestCase("2015-10-09T14:46:23.1234560Z", "2015-10-09T14:46:23.123456Z")]
+ [TestCase("2015-10-09T14:46:23.123000000Z", "2015-10-09T14:46:23.123Z")]
+ [TestCase("2015-10-09T14:46:23.1230Z", "2015-10-09T14:46:23.123Z")]
+ [TestCase("2015-10-09T14:46:23.00Z", "2015-10-09T14:46:23Z")]
+
+ // +00:00 offset
+ [TestCase("2015-10-09T14:46:23.123456789+00:00", "2015-10-09T14:46:23.123456789Z")]
+ [TestCase("2015-10-09T14:46:23.123456+00:00", "2015-10-09T14:46:23.123456Z")]
+ [TestCase("2015-10-09T14:46:23.123+00:00", "2015-10-09T14:46:23.123Z")]
+ [TestCase("2015-10-09T14:46:23+00:00", "2015-10-09T14:46:23Z")]
+ [TestCase("2015-10-09T14:46:23.123456000+00:00", "2015-10-09T14:46:23.123456Z")]
+ [TestCase("2015-10-09T14:46:23.1234560+00:00", "2015-10-09T14:46:23.123456Z")]
+ [TestCase("2015-10-09T14:46:23.123000000+00:00", "2015-10-09T14:46:23.123Z")]
+ [TestCase("2015-10-09T14:46:23.1230+00:00", "2015-10-09T14:46:23.123Z")]
+ [TestCase("2015-10-09T14:46:23.00+00:00", "2015-10-09T14:46:23Z")]
+
+ // Other offsets (assume by now that the subsecond handling is okay)
+ [TestCase("2015-10-09T15:46:23.123456789+01:00", "2015-10-09T14:46:23.123456789Z")]
+ [TestCase("2015-10-09T13:46:23.123456789-01:00", "2015-10-09T14:46:23.123456789Z")]
+ [TestCase("2015-10-09T15:16:23.123456789+00:30", "2015-10-09T14:46:23.123456789Z")]
+ [TestCase("2015-10-09T14:16:23.123456789-00:30", "2015-10-09T14:46:23.123456789Z")]
+ [TestCase("2015-10-09T16:31:23.123456789+01:45", "2015-10-09T14:46:23.123456789Z")]
+ [TestCase("2015-10-09T13:01:23.123456789-01:45", "2015-10-09T14:46:23.123456789Z")]
+ [TestCase("2015-10-10T08:46:23.123456789+18:00", "2015-10-09T14:46:23.123456789Z")]
+ [TestCase("2015-10-08T20:46:23.123456789-18:00", "2015-10-09T14:46:23.123456789Z")]
+
+ // Leap years and min/max
+ [TestCase("2016-02-29T14:46:23.123456789Z", null)]
+ [TestCase("2000-02-29T14:46:23.123456789Z", null)]
+ [TestCase("0001-01-01T00:00:00Z", null)]
+ [TestCase("9999-12-31T23:59:59.999999999Z", null)]
+ public void Timestamp_Valid(string jsonValue, string expectedFormatted)
+ {
+ expectedFormatted = expectedFormatted ?? jsonValue;
+ string json = WrapInQuotes(jsonValue);
+ var parsed = Timestamp.Parser.ParseJson(json);
+ Assert.AreEqual(WrapInQuotes(expectedFormatted), parsed.ToString());
+ }
+
+ [Test]
+ [TestCase("2015-10-09 14:46:23.123456789Z", Description = "No T between date and time")]
+ [TestCase("2015/10/09T14:46:23.123456789Z", Description = "Wrong date separators")]
+ [TestCase("2015-10-09T14.46.23.123456789Z", Description = "Wrong time separators")]
+ [TestCase("2015-10-09T14:46:23,123456789Z", Description = "Wrong fractional second separators (valid ISO-8601 though)")]
+ [TestCase(" 2015-10-09T14:46:23.123456789Z", Description = "Whitespace at start")]
+ [TestCase("2015-10-09T14:46:23.123456789Z ", Description = "Whitespace at end")]
+ [TestCase("2015-10-09T14:46:23.1234567890", Description = "Too many digits")]
+ [TestCase("2015-10-09T14:46:23.123456789", Description = "No offset")]
+ [TestCase("2015-13-09T14:46:23.123456789Z", Description = "Invalid month")]
+ [TestCase("2015-10-32T14:46:23.123456789Z", Description = "Invalid day")]
+ [TestCase("2015-10-09T24:00:00.000000000Z", Description = "Invalid hour (valid ISO-8601 though)")]
+ [TestCase("2015-10-09T14:60:23.123456789Z", Description = "Invalid minutes")]
+ [TestCase("2015-10-09T14:46:60.123456789Z", Description = "Invalid seconds")]
+ [TestCase("2015-10-09T14:46:23.123456789+18:01", Description = "Offset too large (positive)")]
+ [TestCase("2015-10-09T14:46:23.123456789-18:01", Description = "Offset too large (negative)")]
+ [TestCase("2015-10-09T14:46:23.123456789-00:00", Description = "Local offset (-00:00) makes no sense here")]
+ [TestCase("0001-01-01T00:00:00+00:01", Description = "Value before earliest when offset applied")]
+ [TestCase("9999-12-31T23:59:59.999999999-00:01", Description = "Value after latest when offset applied")]
+ [TestCase("2100-02-29T14:46:23.123456789Z", Description = "Feb 29th on a non-leap-year")]
+ public void Timestamp_Invalid(string jsonValue)
+ {
+ string json = WrapInQuotes(jsonValue);
+ Assert.Throws<InvalidProtocolBufferException>(() => Timestamp.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void StructValue_Null()
+ {
+ Assert.AreEqual(new Value { NullValue = 0 }, Value.Parser.ParseJson("null"));
+ }
+
+ [Test]
+ public void StructValue_String()
+ {
+ Assert.AreEqual(new Value { StringValue = "hi" }, Value.Parser.ParseJson("\"hi\""));
+ }
+
+ [Test]
+ public void StructValue_Bool()
+ {
+ Assert.AreEqual(new Value { BoolValue = true }, Value.Parser.ParseJson("true"));
+ Assert.AreEqual(new Value { BoolValue = false }, Value.Parser.ParseJson("false"));
+ }
+
+ [Test]
+ public void StructValue_List()
+ {
+ Assert.AreEqual(Value.ForList(Value.ForNumber(1), Value.ForString("x")), Value.Parser.ParseJson("[1, \"x\"]"));
+ }
+
+ [Test]
+ public void ParseListValue()
+ {
+ Assert.AreEqual(new ListValue { Values = { Value.ForNumber(1), Value.ForString("x") } }, ListValue.Parser.ParseJson("[1, \"x\"]"));
+ }
+
+ [Test]
+ public void StructValue_Struct()
+ {
+ Assert.AreEqual(
+ Value.ForStruct(new Struct { Fields = { { "x", Value.ForNumber(1) }, { "y", Value.ForString("z") } } }),
+ Value.Parser.ParseJson("{ \"x\": 1, \"y\": \"z\" }"));
+ }
+
+ [Test]
+ public void ParseStruct()
+ {
+ Assert.AreEqual(new Struct { Fields = { { "x", Value.ForNumber(1) }, { "y", Value.ForString("z") } } },
+ Struct.Parser.ParseJson("{ \"x\": 1, \"y\": \"z\" }"));
+ }
+
+ // TODO for duration parsing: upper and lower bounds.
+ // +/- 315576000000 seconds
+
+ [Test]
+ [TestCase("1.123456789s", null)]
+ [TestCase("1.123456s", null)]
+ [TestCase("1.123s", null)]
+ [TestCase("1.12300s", "1.123s")]
+ [TestCase("1.12345s", "1.123450s")]
+ [TestCase("1s", null)]
+ [TestCase("-1.123456789s", null)]
+ [TestCase("-1.123456s", null)]
+ [TestCase("-1.123s", null)]
+ [TestCase("-1s", null)]
+ [TestCase("0.123s", null)]
+ [TestCase("-0.123s", null)]
+ [TestCase("123456.123s", null)]
+ [TestCase("-123456.123s", null)]
+ // Upper and lower bounds
+ [TestCase("315576000000s", null)]
+ [TestCase("-315576000000s", null)]
+ public void Duration_Valid(string jsonValue, string expectedFormatted)
+ {
+ expectedFormatted = expectedFormatted ?? jsonValue;
+ string json = WrapInQuotes(jsonValue);
+ var parsed = Duration.Parser.ParseJson(json);
+ Assert.AreEqual(WrapInQuotes(expectedFormatted), parsed.ToString());
+ }
+
+ // The simplest way of testing that the value has parsed correctly is to reformat it,
+ // as we trust the formatting. In many cases that will give the same result as the input,
+ // so in those cases we accept an expectedFormatted value of null. Sometimes the results
+ // will be different though, due to a different number of digits being provided.
+ [Test]
+ [TestCase("1.1234567890s", Description = "Too many digits")]
+ [TestCase("1.123456789", Description = "No suffix")]
+ [TestCase("1.123456789ss", Description = "Too much suffix")]
+ [TestCase("1.123456789S", Description = "Upper case suffix")]
+ [TestCase("+1.123456789s", Description = "Leading +")]
+ [TestCase(".123456789s", Description = "No integer before the fraction")]
+ [TestCase("1,123456789s", Description = "Comma as decimal separator")]
+ [TestCase("1x1.123456789s", Description = "Non-digit in integer part")]
+ [TestCase("1.1x3456789s", Description = "Non-digit in fractional part")]
+ [TestCase(" 1.123456789s", Description = "Whitespace before fraction")]
+ [TestCase("1.123456789s ", Description = "Whitespace after value")]
+ [TestCase("01.123456789s", Description = "Leading zero (positive)")]
+ [TestCase("-01.123456789s", Description = "Leading zero (negative)")]
+ [TestCase("--0.123456789s", Description = "Double minus sign")]
+ // Violate upper/lower bounds in various ways
+ [TestCase("315576000001s", Description = "Integer part too large")]
+ [TestCase("3155760000000s", Description = "Integer part too long (positive)")]
+ [TestCase("-3155760000000s", Description = "Integer part too long (negative)")]
+ public void Duration_Invalid(string jsonValue)
+ {
+ string json = WrapInQuotes(jsonValue);
+ Assert.Throws<InvalidProtocolBufferException>(() => Duration.Parser.ParseJson(json));
+ }
+
+ // Not as many tests for field masks as I'd like; more to be added when we have more
+ // detailed specifications.
+
+ [Test]
+ [TestCase("")]
+ [TestCase("foo", "foo")]
+ [TestCase("foo,bar", "foo", "bar")]
+ [TestCase("foo.bar", "foo.bar")]
+ [TestCase("fooBar", "foo_bar")]
+ [TestCase("fooBar.bazQux", "foo_bar.baz_qux")]
+ public void FieldMask_Valid(string jsonValue, params string[] expectedPaths)
+ {
+ string json = WrapInQuotes(jsonValue);
+ var parsed = FieldMask.Parser.ParseJson(json);
+ CollectionAssert.AreEqual(expectedPaths, parsed.Paths);
+ }
+
+ [Test]
+ [TestCase("foo_bar")]
+ public void FieldMask_Invalid(string jsonValue)
+ {
+ string json = WrapInQuotes(jsonValue);
+ Assert.Throws<InvalidProtocolBufferException>(() => FieldMask.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void Any_RegularMessage()
+ {
+ var registry = TypeRegistry.FromMessages(TestAllTypes.Descriptor);
+ var formatter = new JsonFormatter(new JsonFormatter.Settings(false, TypeRegistry.FromMessages(TestAllTypes.Descriptor)));
+ var message = new TestAllTypes { SingleInt32 = 10, SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 20 } };
+ var original = Any.Pack(message);
+ var json = formatter.Format(original); // This is tested in JsonFormatterTest
+ var parser = new JsonParser(new JsonParser.Settings(10, registry));
+ Assert.AreEqual(original, parser.Parse<Any>(json));
+ string valueFirstJson = "{ \"singleInt32\": 10, \"singleNestedMessage\": { \"bb\": 20 }, \"@type\": \"type.googleapis.com/protobuf_unittest.TestAllTypes\" }";
+ Assert.AreEqual(original, parser.Parse<Any>(valueFirstJson));
+ }
+
+ [Test]
+ public void Any_CustomPrefix()
+ {
+ var registry = TypeRegistry.FromMessages(TestAllTypes.Descriptor);
+ var message = new TestAllTypes { SingleInt32 = 10 };
+ var original = Any.Pack(message, "custom.prefix/middle-part");
+ var parser = new JsonParser(new JsonParser.Settings(10, registry));
+ string json = "{ \"@type\": \"custom.prefix/middle-part/protobuf_unittest.TestAllTypes\", \"singleInt32\": 10 }";
+ Assert.AreEqual(original, parser.Parse<Any>(json));
+ }
+
+ [Test]
+ public void Any_UnknownType()
+ {
+ string json = "{ \"@type\": \"type.googleapis.com/bogus\" }";
+ Assert.Throws<InvalidOperationException>(() => Any.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void Any_NoTypeUrl()
+ {
+ string json = "{ \"foo\": \"bar\" }";
+ Assert.Throws<InvalidProtocolBufferException>(() => Any.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void Any_WellKnownType()
+ {
+ var registry = TypeRegistry.FromMessages(Timestamp.Descriptor);
+ var formatter = new JsonFormatter(new JsonFormatter.Settings(false, registry));
+ var timestamp = new DateTime(1673, 6, 19, 12, 34, 56, DateTimeKind.Utc).ToTimestamp();
+ var original = Any.Pack(timestamp);
+ var json = formatter.Format(original); // This is tested in JsonFormatterTest
+ var parser = new JsonParser(new JsonParser.Settings(10, registry));
+ Assert.AreEqual(original, parser.Parse<Any>(json));
+ string valueFirstJson = "{ \"value\": \"1673-06-19T12:34:56Z\", \"@type\": \"type.googleapis.com/google.protobuf.Timestamp\" }";
+ Assert.AreEqual(original, parser.Parse<Any>(valueFirstJson));
+ }
+
+ [Test]
+ public void Any_Nested()
+ {
+ var registry = TypeRegistry.FromMessages(TestWellKnownTypes.Descriptor, TestAllTypes.Descriptor);
+ var formatter = new JsonFormatter(new JsonFormatter.Settings(false, registry));
+ var parser = new JsonParser(new JsonParser.Settings(10, registry));
+ var doubleNestedMessage = new TestAllTypes { SingleInt32 = 20 };
+ var nestedMessage = Any.Pack(doubleNestedMessage);
+ var message = new TestWellKnownTypes { AnyField = Any.Pack(nestedMessage) };
+ var json = formatter.Format(message);
+ // Use the descriptor-based parser just for a change.
+ Assert.AreEqual(message, parser.Parse(json, TestWellKnownTypes.Descriptor));
+ }
+
+ [Test]
+ public void DataAfterObject()
+ {
+ string json = "{} 10";
+ Assert.Throws<InvalidJsonException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ /// <summary>
+ /// JSON equivalent to <see cref="CodedInputStreamTest.MaliciousRecursion"/>
+ /// </summary>
+ [Test]
+ public void MaliciousRecursion()
+ {
+ string data64 = CodedInputStreamTest.MakeRecursiveMessage(64).ToString();
+ string data65 = CodedInputStreamTest.MakeRecursiveMessage(65).ToString();
+
+ var parser64 = new JsonParser(new JsonParser.Settings(64));
+ CodedInputStreamTest.AssertMessageDepth(parser64.Parse<TestRecursiveMessage>(data64), 64);
+ Assert.Throws<InvalidProtocolBufferException>(() => parser64.Parse<TestRecursiveMessage>(data65));
+
+ var parser63 = new JsonParser(new JsonParser.Settings(63));
+ Assert.Throws<InvalidProtocolBufferException>(() => parser63.Parse<TestRecursiveMessage>(data64));
+ }
+
+ [Test]
+ [TestCase("AQI")]
+ [TestCase("_-==")]
+ public void Bytes_InvalidBase64(string badBase64)
+ {
+ string json = "{ \"singleBytes\": \"" + badBase64 + "\" }";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("\"FOREIGN_BAR\"", ForeignEnum.ForeignBar)]
+ [TestCase("5", ForeignEnum.ForeignBar)]
+ [TestCase("100", (ForeignEnum)100)]
+ public void EnumValid(string value, ForeignEnum expectedValue)
+ {
+ string json = "{ \"singleForeignEnum\": " + value + " }";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(new TestAllTypes { SingleForeignEnum = expectedValue }, parsed);
+ }
+
+ [Test]
+ [TestCase("\"NOT_A_VALID_VALUE\"")]
+ [TestCase("5.5")]
+ public void Enum_Invalid(string value)
+ {
+ string json = "{ \"singleForeignEnum\": " + value + " }";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void OneofDuplicate_Invalid()
+ {
+ string json = "{ \"oneofString\": \"x\", \"oneofUint32\": 10 }";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ /// <summary>
+ /// Various tests use strings which have quotes round them for parsing or as the result
+ /// of formatting, but without those quotes being specified in the tests (for the sake of readability).
+ /// This method simply returns the input, wrapped in double quotes.
+ /// </summary>
+ internal static string WrapInQuotes(string text)
+ {
+ return '"' + text + '"';
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/JsonTokenizerTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/JsonTokenizerTest.cs
new file mode 100644
index 0000000000..527ab3361e
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/JsonTokenizerTest.cs
@@ -0,0 +1,408 @@
+#region Copyright notice and license
+// 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.
+#endregion
+using NUnit.Framework;
+using System;
+using System.IO;
+
+namespace Google.Protobuf
+{
+ public class JsonTokenizerTest
+ {
+ [Test]
+ public void EmptyObjectValue()
+ {
+ AssertTokens("{}", JsonToken.StartObject, JsonToken.EndObject);
+ }
+
+ [Test]
+ public void EmptyArrayValue()
+ {
+ AssertTokens("[]", JsonToken.StartArray, JsonToken.EndArray);
+ }
+
+ [Test]
+ [TestCase("foo", "foo")]
+ [TestCase("tab\\t", "tab\t")]
+ [TestCase("line\\nfeed", "line\nfeed")]
+ [TestCase("carriage\\rreturn", "carriage\rreturn")]
+ [TestCase("back\\bspace", "back\bspace")]
+ [TestCase("form\\ffeed", "form\ffeed")]
+ [TestCase("escaped\\/slash", "escaped/slash")]
+ [TestCase("escaped\\\\backslash", "escaped\\backslash")]
+ [TestCase("escaped\\\"quote", "escaped\"quote")]
+ [TestCase("foo {}[] bar", "foo {}[] bar")]
+ [TestCase("foo\\u09aFbar", "foo\u09afbar")] // Digits, upper hex, lower hex
+ [TestCase("ab\ud800\udc00cd", "ab\ud800\udc00cd")]
+ [TestCase("ab\\ud800\\udc00cd", "ab\ud800\udc00cd")]
+ public void StringValue(string json, string expectedValue)
+ {
+ AssertTokensNoReplacement("\"" + json + "\"", JsonToken.Value(expectedValue));
+ }
+
+ // Valid surrogate pairs, with mixed escaping. These test cases can't be expressed
+ // using TestCase as they have no valid UTF-8 representation.
+ // It's unclear exactly how we should handle a mixture of escaped or not: that can't
+ // come from UTF-8 text, but could come from a .NET string. For the moment,
+ // treat it as valid in the obvious way.
+ [Test]
+ public void MixedSurrogatePairs()
+ {
+ string expected = "\ud800\udc00";
+ AssertTokens("'\\ud800\udc00'", JsonToken.Value(expected));
+ AssertTokens("'\ud800\\udc00'", JsonToken.Value(expected));
+ }
+
+ [Test]
+ public void ObjectDepth()
+ {
+ string json = "{ \"foo\": { \"x\": 1, \"y\": [ 0 ] } }";
+ var tokenizer = JsonTokenizer.FromTextReader(new StringReader(json));
+ // If we had more tests like this, I'd introduce a helper method... but for one test, it's not worth it.
+ Assert.AreEqual(0, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.StartObject, tokenizer.Next());
+ Assert.AreEqual(1, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.Name("foo"), tokenizer.Next());
+ Assert.AreEqual(1, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.StartObject, tokenizer.Next());
+ Assert.AreEqual(2, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.Name("x"), tokenizer.Next());
+ Assert.AreEqual(2, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.Value(1), tokenizer.Next());
+ Assert.AreEqual(2, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.Name("y"), tokenizer.Next());
+ Assert.AreEqual(2, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.StartArray, tokenizer.Next());
+ Assert.AreEqual(2, tokenizer.ObjectDepth); // Depth hasn't changed in array
+ Assert.AreEqual(JsonToken.Value(0), tokenizer.Next());
+ Assert.AreEqual(2, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.EndArray, tokenizer.Next());
+ Assert.AreEqual(2, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.EndObject, tokenizer.Next());
+ Assert.AreEqual(1, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.EndObject, tokenizer.Next());
+ Assert.AreEqual(0, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.EndDocument, tokenizer.Next());
+ Assert.AreEqual(0, tokenizer.ObjectDepth);
+ }
+
+ [Test]
+ public void ObjectDepth_WithPushBack()
+ {
+ string json = "{}";
+ var tokenizer = JsonTokenizer.FromTextReader(new StringReader(json));
+ Assert.AreEqual(0, tokenizer.ObjectDepth);
+ var token = tokenizer.Next();
+ Assert.AreEqual(1, tokenizer.ObjectDepth);
+ // When we push back a "start object", we should effectively be back to the previous depth.
+ tokenizer.PushBack(token);
+ Assert.AreEqual(0, tokenizer.ObjectDepth);
+ // Read the same token again, and get back to depth 1
+ token = tokenizer.Next();
+ Assert.AreEqual(1, tokenizer.ObjectDepth);
+
+ // Now the same in reverse, with EndObject
+ token = tokenizer.Next();
+ Assert.AreEqual(0, tokenizer.ObjectDepth);
+ tokenizer.PushBack(token);
+ Assert.AreEqual(1, tokenizer.ObjectDepth);
+ tokenizer.Next();
+ Assert.AreEqual(0, tokenizer.ObjectDepth);
+ }
+
+ [Test]
+ [TestCase("embedded tab\t")]
+ [TestCase("embedded CR\r")]
+ [TestCase("embedded LF\n")]
+ [TestCase("embedded bell\u0007")]
+ [TestCase("bad escape\\a")]
+ [TestCase("incomplete escape\\")]
+ [TestCase("incomplete Unicode escape\\u000")]
+ [TestCase("invalid Unicode escape\\u000H")]
+ // Surrogate pair handling, both in raw .NET strings and escaped. We only need
+ // to detect this in strings, as non-ASCII characters anywhere other than in strings
+ // will already lead to parsing errors.
+ [TestCase("\\ud800")]
+ [TestCase("\\udc00")]
+ [TestCase("\\ud800x")]
+ [TestCase("\\udc00x")]
+ [TestCase("\\udc00\\ud800y")]
+ public void InvalidStringValue(string json)
+ {
+ AssertThrowsAfter("\"" + json + "\"");
+ }
+
+ // Tests for invalid strings that can't be expressed in attributes,
+ // as the constants can't be expressed as UTF-8 strings.
+ [Test]
+ public void InvalidSurrogatePairs()
+ {
+ AssertThrowsAfter("\"\ud800x\"");
+ AssertThrowsAfter("\"\udc00y\"");
+ AssertThrowsAfter("\"\udc00\ud800y\"");
+ }
+
+ [Test]
+ [TestCase("0", 0)]
+ [TestCase("-0", 0)] // We don't distinguish between positive and negative 0
+ [TestCase("1", 1)]
+ [TestCase("-1", -1)]
+ // From here on, assume leading sign is okay...
+ [TestCase("1.125", 1.125)]
+ [TestCase("1.0", 1)]
+ [TestCase("1e5", 100000)]
+ [TestCase("1e000000", 1)] // Weird, but not prohibited by the spec
+ [TestCase("1E5", 100000)]
+ [TestCase("1e+5", 100000)]
+ [TestCase("1E-5", 0.00001)]
+ [TestCase("123E-2", 1.23)]
+ [TestCase("123.45E3", 123450)]
+ [TestCase(" 1 ", 1)]
+ public void NumberValue(string json, double expectedValue)
+ {
+ AssertTokens(json, JsonToken.Value(expectedValue));
+ }
+
+ [Test]
+ [TestCase("00")]
+ [TestCase(".5")]
+ [TestCase("1.")]
+ [TestCase("1e")]
+ [TestCase("1e-")]
+ [TestCase("--")]
+ [TestCase("--1")]
+ [TestCase("-1.7977e308")]
+ [TestCase("1.7977e308")]
+ public void InvalidNumberValue(string json)
+ {
+ AssertThrowsAfter(json);
+ }
+
+ [Test]
+ [TestCase("nul")]
+ [TestCase("nothing")]
+ [TestCase("truth")]
+ [TestCase("fALSEhood")]
+ public void InvalidLiterals(string json)
+ {
+ AssertThrowsAfter(json);
+ }
+
+ [Test]
+ public void NullValue()
+ {
+ AssertTokens("null", JsonToken.Null);
+ }
+
+ [Test]
+ public void TrueValue()
+ {
+ AssertTokens("true", JsonToken.True);
+ }
+
+ [Test]
+ public void FalseValue()
+ {
+ AssertTokens("false", JsonToken.False);
+ }
+
+ [Test]
+ public void SimpleObject()
+ {
+ AssertTokens("{'x': 'y'}",
+ JsonToken.StartObject, JsonToken.Name("x"), JsonToken.Value("y"), JsonToken.EndObject);
+ }
+
+ [Test]
+ [TestCase("[10, 20", 3)]
+ [TestCase("[10,", 2)]
+ [TestCase("[10:20]", 2)]
+ [TestCase("[", 1)]
+ [TestCase("[,", 1)]
+ [TestCase("{", 1)]
+ [TestCase("{,", 1)]
+ [TestCase("{[", 1)]
+ [TestCase("{{", 1)]
+ [TestCase("{0", 1)]
+ [TestCase("{null", 1)]
+ [TestCase("{false", 1)]
+ [TestCase("{true", 1)]
+ [TestCase("}", 0)]
+ [TestCase("]", 0)]
+ [TestCase(",", 0)]
+ [TestCase("'foo' 'bar'", 1)]
+ [TestCase(":", 0)]
+ [TestCase("'foo", 0)] // Incomplete string
+ [TestCase("{ 'foo' }", 2)]
+ [TestCase("{ x:1", 1)] // Property names must be quoted
+ [TestCase("{]", 1)]
+ [TestCase("[}", 1)]
+ [TestCase("[1,", 2)]
+ [TestCase("{'x':0]", 3)]
+ [TestCase("{ 'foo': }", 2)]
+ [TestCase("{ 'foo':'bar', }", 3)]
+ public void InvalidStructure(string json, int expectedValidTokens)
+ {
+ // Note: we don't test that the earlier tokens are exactly as expected,
+ // partly because that's hard to parameterize.
+ var reader = new StringReader(json.Replace('\'', '"'));
+ var tokenizer = JsonTokenizer.FromTextReader(reader);
+ for (int i = 0; i < expectedValidTokens; i++)
+ {
+ Assert.IsNotNull(tokenizer.Next());
+ }
+ Assert.Throws<InvalidJsonException>(() => tokenizer.Next());
+ }
+
+ [Test]
+ public void ArrayMixedType()
+ {
+ AssertTokens("[1, 'foo', null, false, true, [2], {'x':'y' }]",
+ JsonToken.StartArray,
+ JsonToken.Value(1),
+ JsonToken.Value("foo"),
+ JsonToken.Null,
+ JsonToken.False,
+ JsonToken.True,
+ JsonToken.StartArray,
+ JsonToken.Value(2),
+ JsonToken.EndArray,
+ JsonToken.StartObject,
+ JsonToken.Name("x"),
+ JsonToken.Value("y"),
+ JsonToken.EndObject,
+ JsonToken.EndArray);
+ }
+
+ [Test]
+ public void ObjectMixedType()
+ {
+ AssertTokens(@"{'a': 1, 'b': 'bar', 'c': null, 'd': false, 'e': true,
+ 'f': [2], 'g': {'x':'y' }}",
+ JsonToken.StartObject,
+ JsonToken.Name("a"),
+ JsonToken.Value(1),
+ JsonToken.Name("b"),
+ JsonToken.Value("bar"),
+ JsonToken.Name("c"),
+ JsonToken.Null,
+ JsonToken.Name("d"),
+ JsonToken.False,
+ JsonToken.Name("e"),
+ JsonToken.True,
+ JsonToken.Name("f"),
+ JsonToken.StartArray,
+ JsonToken.Value(2),
+ JsonToken.EndArray,
+ JsonToken.Name("g"),
+ JsonToken.StartObject,
+ JsonToken.Name("x"),
+ JsonToken.Value("y"),
+ JsonToken.EndObject,
+ JsonToken.EndObject);
+ }
+
+ [Test]
+ public void NextAfterEndDocumentThrows()
+ {
+ var tokenizer = JsonTokenizer.FromTextReader(new StringReader("null"));
+ Assert.AreEqual(JsonToken.Null, tokenizer.Next());
+ Assert.AreEqual(JsonToken.EndDocument, tokenizer.Next());
+ Assert.Throws<InvalidOperationException>(() => tokenizer.Next());
+ }
+
+ [Test]
+ public void CanPushBackEndDocument()
+ {
+ var tokenizer = JsonTokenizer.FromTextReader(new StringReader("null"));
+ Assert.AreEqual(JsonToken.Null, tokenizer.Next());
+ Assert.AreEqual(JsonToken.EndDocument, tokenizer.Next());
+ tokenizer.PushBack(JsonToken.EndDocument);
+ Assert.AreEqual(JsonToken.EndDocument, tokenizer.Next());
+ Assert.Throws<InvalidOperationException>(() => tokenizer.Next());
+ }
+
+ /// <summary>
+ /// Asserts that the specified JSON is tokenized into the given sequence of tokens.
+ /// All apostrophes are first converted to double quotes, allowing any tests
+ /// that don't need to check actual apostrophe handling to use apostrophes in the JSON, avoiding
+ /// messy string literal escaping. The "end document" token is not specified in the list of
+ /// expected tokens, but is implicit.
+ /// </summary>
+ private static void AssertTokens(string json, params JsonToken[] expectedTokens)
+ {
+ AssertTokensNoReplacement(json.Replace('\'', '"'), expectedTokens);
+ }
+
+ /// <summary>
+ /// Asserts that the specified JSON is tokenized into the given sequence of tokens.
+ /// Unlike <see cref="AssertTokens(string, JsonToken[])"/>, this does not perform any character
+ /// replacement on the specified JSON, and should be used when the text contains apostrophes which
+ /// are expected to be used *as* apostrophes. The "end document" token is not specified in the list of
+ /// expected tokens, but is implicit.
+ /// </summary>
+ private static void AssertTokensNoReplacement(string json, params JsonToken[] expectedTokens)
+ {
+ var reader = new StringReader(json);
+ var tokenizer = JsonTokenizer.FromTextReader(reader);
+ for (int i = 0; i < expectedTokens.Length; i++)
+ {
+ var actualToken = tokenizer.Next();
+ if (actualToken == JsonToken.EndDocument)
+ {
+ Assert.Fail("Expected {0} but reached end of token stream", expectedTokens[i]);
+ }
+ Assert.AreEqual(expectedTokens[i], actualToken);
+ }
+ var finalToken = tokenizer.Next();
+ if (finalToken != JsonToken.EndDocument)
+ {
+ Assert.Fail("Expected token stream to be exhausted; received {0}", finalToken);
+ }
+ }
+
+ private static void AssertThrowsAfter(string json, params JsonToken[] expectedTokens)
+ {
+ var reader = new StringReader(json);
+ var tokenizer = JsonTokenizer.FromTextReader(reader);
+ for (int i = 0; i < expectedTokens.Length; i++)
+ {
+ var actualToken = tokenizer.Next();
+ if (actualToken == JsonToken.EndDocument)
+ {
+ Assert.Fail("Expected {0} but reached end of document", expectedTokens[i]);
+ }
+ Assert.AreEqual(expectedTokens[i], actualToken);
+ }
+ Assert.Throws<InvalidJsonException>(() => tokenizer.Next());
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
new file mode 100644
index 0000000000..52d5a67697
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
@@ -0,0 +1,259 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System.Linq;
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+using UnitTest.Issues.TestProtos;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Tests for descriptors. (Not in its own namespace or broken up into individual classes as the
+ /// size doesn't warrant it. On the other hand, this makes me feel a bit dirty...)
+ /// </summary>
+ public class DescriptorsTest
+ {
+ [Test]
+ public void FileDescriptor()
+ {
+ FileDescriptor file = UnittestProto3Reflection.Descriptor;
+
+ Assert.AreEqual("google/protobuf/unittest_proto3.proto", file.Name);
+ Assert.AreEqual("protobuf_unittest", file.Package);
+
+ Assert.AreEqual("UnittestProto", file.Proto.Options.JavaOuterClassname);
+ Assert.AreEqual("google/protobuf/unittest_proto3.proto", file.Proto.Name);
+
+ // unittest.proto doesn't have any public imports, but unittest_import.proto does.
+ Assert.AreEqual(0, file.PublicDependencies.Count);
+ Assert.AreEqual(1, UnittestImportProto3Reflection.Descriptor.PublicDependencies.Count);
+ Assert.AreEqual(UnittestImportPublicProto3Reflection.Descriptor, UnittestImportProto3Reflection.Descriptor.PublicDependencies[0]);
+
+ Assert.AreEqual(1, file.Dependencies.Count);
+ Assert.AreEqual(UnittestImportProto3Reflection.Descriptor, file.Dependencies[0]);
+
+ MessageDescriptor messageType = TestAllTypes.Descriptor;
+ Assert.AreSame(typeof(TestAllTypes), messageType.ClrType);
+ Assert.AreSame(TestAllTypes.Parser, messageType.Parser);
+ Assert.AreEqual(messageType, file.MessageTypes[0]);
+ Assert.AreEqual(messageType, file.FindTypeByName<MessageDescriptor>("TestAllTypes"));
+ Assert.Null(file.FindTypeByName<MessageDescriptor>("NoSuchType"));
+ Assert.Null(file.FindTypeByName<MessageDescriptor>("protobuf_unittest.TestAllTypes"));
+ for (int i = 0; i < file.MessageTypes.Count; i++)
+ {
+ Assert.AreEqual(i, file.MessageTypes[i].Index);
+ }
+
+ Assert.AreEqual(file.EnumTypes[0], file.FindTypeByName<EnumDescriptor>("ForeignEnum"));
+ Assert.Null(file.FindTypeByName<EnumDescriptor>("NoSuchType"));
+ Assert.Null(file.FindTypeByName<EnumDescriptor>("protobuf_unittest.ForeignEnum"));
+ Assert.AreEqual(1, UnittestImportProto3Reflection.Descriptor.EnumTypes.Count);
+ Assert.AreEqual("ImportEnum", UnittestImportProto3Reflection.Descriptor.EnumTypes[0].Name);
+ for (int i = 0; i < file.EnumTypes.Count; i++)
+ {
+ Assert.AreEqual(i, file.EnumTypes[i].Index);
+ }
+
+ Assert.AreEqual(10, file.SerializedData[0]);
+ }
+
+ [Test]
+ public void MessageDescriptor()
+ {
+ MessageDescriptor messageType = TestAllTypes.Descriptor;
+ MessageDescriptor nestedType = TestAllTypes.Types.NestedMessage.Descriptor;
+
+ Assert.AreEqual("TestAllTypes", messageType.Name);
+ Assert.AreEqual("protobuf_unittest.TestAllTypes", messageType.FullName);
+ Assert.AreEqual(UnittestProto3Reflection.Descriptor, messageType.File);
+ Assert.IsNull(messageType.ContainingType);
+ Assert.IsNull(messageType.Proto.Options);
+
+ Assert.AreEqual("TestAllTypes", messageType.Name);
+
+ Assert.AreEqual("NestedMessage", nestedType.Name);
+ Assert.AreEqual("protobuf_unittest.TestAllTypes.NestedMessage", nestedType.FullName);
+ Assert.AreEqual(UnittestProto3Reflection.Descriptor, nestedType.File);
+ Assert.AreEqual(messageType, nestedType.ContainingType);
+
+ FieldDescriptor field = messageType.Fields.InDeclarationOrder()[0];
+ Assert.AreEqual("single_int32", field.Name);
+ Assert.AreEqual(field, messageType.FindDescriptor<FieldDescriptor>("single_int32"));
+ Assert.Null(messageType.FindDescriptor<FieldDescriptor>("no_such_field"));
+ Assert.AreEqual(field, messageType.FindFieldByNumber(1));
+ Assert.Null(messageType.FindFieldByNumber(571283));
+ var fieldsInDeclarationOrder = messageType.Fields.InDeclarationOrder();
+ for (int i = 0; i < fieldsInDeclarationOrder.Count; i++)
+ {
+ Assert.AreEqual(i, fieldsInDeclarationOrder[i].Index);
+ }
+
+ Assert.AreEqual(nestedType, messageType.NestedTypes[0]);
+ Assert.AreEqual(nestedType, messageType.FindDescriptor<MessageDescriptor>("NestedMessage"));
+ Assert.Null(messageType.FindDescriptor<MessageDescriptor>("NoSuchType"));
+ for (int i = 0; i < messageType.NestedTypes.Count; i++)
+ {
+ Assert.AreEqual(i, messageType.NestedTypes[i].Index);
+ }
+
+ Assert.AreEqual(messageType.EnumTypes[0], messageType.FindDescriptor<EnumDescriptor>("NestedEnum"));
+ Assert.Null(messageType.FindDescriptor<EnumDescriptor>("NoSuchType"));
+ for (int i = 0; i < messageType.EnumTypes.Count; i++)
+ {
+ Assert.AreEqual(i, messageType.EnumTypes[i].Index);
+ }
+ }
+
+ [Test]
+ public void FieldDescriptor()
+ {
+ MessageDescriptor messageType = TestAllTypes.Descriptor;
+ FieldDescriptor primitiveField = messageType.FindDescriptor<FieldDescriptor>("single_int32");
+ FieldDescriptor enumField = messageType.FindDescriptor<FieldDescriptor>("single_nested_enum");
+ FieldDescriptor messageField = messageType.FindDescriptor<FieldDescriptor>("single_foreign_message");
+
+ Assert.AreEqual("single_int32", primitiveField.Name);
+ Assert.AreEqual("protobuf_unittest.TestAllTypes.single_int32",
+ primitiveField.FullName);
+ Assert.AreEqual(1, primitiveField.FieldNumber);
+ Assert.AreEqual(messageType, primitiveField.ContainingType);
+ Assert.AreEqual(UnittestProto3Reflection.Descriptor, primitiveField.File);
+ Assert.AreEqual(FieldType.Int32, primitiveField.FieldType);
+ Assert.IsNull(primitiveField.Proto.Options);
+
+ Assert.AreEqual("single_nested_enum", enumField.Name);
+ Assert.AreEqual(FieldType.Enum, enumField.FieldType);
+ // Assert.AreEqual(TestAllTypes.Types.NestedEnum.DescriptorProtoFile, enumField.EnumType);
+
+ Assert.AreEqual("single_foreign_message", messageField.Name);
+ Assert.AreEqual(FieldType.Message, messageField.FieldType);
+ Assert.AreEqual(ForeignMessage.Descriptor, messageField.MessageType);
+ }
+
+ [Test]
+ public void FieldDescriptorLabel()
+ {
+ FieldDescriptor singleField =
+ TestAllTypes.Descriptor.FindDescriptor<FieldDescriptor>("single_int32");
+ FieldDescriptor repeatedField =
+ TestAllTypes.Descriptor.FindDescriptor<FieldDescriptor>("repeated_int32");
+
+ Assert.IsFalse(singleField.IsRepeated);
+ Assert.IsTrue(repeatedField.IsRepeated);
+ }
+
+ [Test]
+ public void EnumDescriptor()
+ {
+ // Note: this test is a bit different to the Java version because there's no static way of getting to the descriptor
+ EnumDescriptor enumType = UnittestProto3Reflection.Descriptor.FindTypeByName<EnumDescriptor>("ForeignEnum");
+ EnumDescriptor nestedType = TestAllTypes.Descriptor.FindDescriptor<EnumDescriptor>("NestedEnum");
+
+ Assert.AreEqual("ForeignEnum", enumType.Name);
+ Assert.AreEqual("protobuf_unittest.ForeignEnum", enumType.FullName);
+ Assert.AreEqual(UnittestProto3Reflection.Descriptor, enumType.File);
+ Assert.Null(enumType.ContainingType);
+ Assert.Null(enumType.Proto.Options);
+
+ Assert.AreEqual("NestedEnum", nestedType.Name);
+ Assert.AreEqual("protobuf_unittest.TestAllTypes.NestedEnum",
+ nestedType.FullName);
+ Assert.AreEqual(UnittestProto3Reflection.Descriptor, nestedType.File);
+ Assert.AreEqual(TestAllTypes.Descriptor, nestedType.ContainingType);
+
+ EnumValueDescriptor value = enumType.FindValueByName("FOREIGN_FOO");
+ Assert.AreEqual(value, enumType.Values[1]);
+ Assert.AreEqual("FOREIGN_FOO", value.Name);
+ Assert.AreEqual(4, value.Number);
+ Assert.AreEqual((int) ForeignEnum.ForeignFoo, value.Number);
+ Assert.AreEqual(value, enumType.FindValueByNumber(4));
+ Assert.Null(enumType.FindValueByName("NO_SUCH_VALUE"));
+ for (int i = 0; i < enumType.Values.Count; i++)
+ {
+ Assert.AreEqual(i, enumType.Values[i].Index);
+ }
+ }
+
+ [Test]
+ public void OneofDescriptor()
+ {
+ OneofDescriptor descriptor = TestAllTypes.Descriptor.FindDescriptor<OneofDescriptor>("oneof_field");
+ Assert.AreEqual("oneof_field", descriptor.Name);
+ Assert.AreEqual("protobuf_unittest.TestAllTypes.oneof_field", descriptor.FullName);
+
+ var expectedFields = new[] {
+ TestAllTypes.OneofBytesFieldNumber,
+ TestAllTypes.OneofNestedMessageFieldNumber,
+ TestAllTypes.OneofStringFieldNumber,
+ TestAllTypes.OneofUint32FieldNumber }
+ .Select(fieldNumber => TestAllTypes.Descriptor.FindFieldByNumber(fieldNumber))
+ .ToList();
+ foreach (var field in expectedFields)
+ {
+ Assert.AreSame(descriptor, field.ContainingOneof);
+ }
+
+ CollectionAssert.AreEquivalent(expectedFields, descriptor.Fields);
+ }
+
+ [Test]
+ public void MapEntryMessageDescriptor()
+ {
+ var descriptor = MapWellKnownTypes.Descriptor.NestedTypes[0];
+ Assert.IsNull(descriptor.Parser);
+ Assert.IsNull(descriptor.ClrType);
+ Assert.IsNull(descriptor.Fields[1].Accessor);
+ }
+
+ // From TestFieldOrdering:
+ // string my_string = 11;
+ // int64 my_int = 1;
+ // float my_float = 101;
+ // NestedMessage single_nested_message = 200;
+ [Test]
+ public void FieldListOrderings()
+ {
+ var fields = TestFieldOrderings.Descriptor.Fields;
+ Assert.AreEqual(new[] { 11, 1, 101, 200 }, fields.InDeclarationOrder().Select(x => x.FieldNumber));
+ Assert.AreEqual(new[] { 1, 11, 101, 200 }, fields.InFieldNumberOrder().Select(x => x.FieldNumber));
+ }
+
+
+ [Test]
+ public void DescriptorProtoFileDescriptor()
+ {
+ var descriptor = Google.Protobuf.Reflection.FileDescriptor.DescriptorProtoFileDescriptor;
+ Assert.AreEqual("google/protobuf/descriptor.proto", descriptor.Name);
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs
new file mode 100644
index 0000000000..a488af30d4
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs
@@ -0,0 +1,218 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace Google.Protobuf.Reflection
+{
+ public class FieldAccessTest
+ {
+ [Test]
+ public void GetValue()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var fields = TestAllTypes.Descriptor.Fields;
+ Assert.AreEqual(message.SingleBool, fields[TestAllTypes.SingleBoolFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleBytes, fields[TestAllTypes.SingleBytesFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleDouble, fields[TestAllTypes.SingleDoubleFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleFixed32, fields[TestAllTypes.SingleFixed32FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleFixed64, fields[TestAllTypes.SingleFixed64FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleFloat, fields[TestAllTypes.SingleFloatFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleForeignEnum, fields[TestAllTypes.SingleForeignEnumFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleForeignMessage, fields[TestAllTypes.SingleForeignMessageFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleImportEnum, fields[TestAllTypes.SingleImportEnumFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleImportMessage, fields[TestAllTypes.SingleImportMessageFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleInt32, fields[TestAllTypes.SingleInt32FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleInt64, fields[TestAllTypes.SingleInt64FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleNestedEnum, fields[TestAllTypes.SingleNestedEnumFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleNestedMessage, fields[TestAllTypes.SingleNestedMessageFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SinglePublicImportMessage, fields[TestAllTypes.SinglePublicImportMessageFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleSint32, fields[TestAllTypes.SingleSint32FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleSint64, fields[TestAllTypes.SingleSint64FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleString, fields[TestAllTypes.SingleStringFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleSfixed32, fields[TestAllTypes.SingleSfixed32FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleSfixed64, fields[TestAllTypes.SingleSfixed64FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleUint32, fields[TestAllTypes.SingleUint32FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleUint64, fields[TestAllTypes.SingleUint64FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.OneofBytes, fields[TestAllTypes.OneofBytesFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.OneofString, fields[TestAllTypes.OneofStringFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.OneofNestedMessage, fields[TestAllTypes.OneofNestedMessageFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.OneofUint32, fields[TestAllTypes.OneofUint32FieldNumber].Accessor.GetValue(message));
+
+ // Just one example for repeated fields - they're all just returning the list
+ var list = (IList) fields[TestAllTypes.RepeatedInt32FieldNumber].Accessor.GetValue(message);
+ Assert.AreEqual(message.RepeatedInt32, list);
+ Assert.AreEqual(message.RepeatedInt32[0], list[0]); // Just in case there was any doubt...
+
+ // Just a single map field, for the same reason
+ var mapMessage = new TestMap { MapStringString = { { "key1", "value1" }, { "key2", "value2" } } };
+ fields = TestMap.Descriptor.Fields;
+ var dictionary = (IDictionary) fields[TestMap.MapStringStringFieldNumber].Accessor.GetValue(mapMessage);
+ Assert.AreEqual(mapMessage.MapStringString, dictionary);
+ Assert.AreEqual("value1", dictionary["key1"]);
+ }
+
+ [Test]
+ public void Clear()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var fields = TestAllTypes.Descriptor.Fields;
+ fields[TestAllTypes.SingleBoolFieldNumber].Accessor.Clear(message);
+ fields[TestAllTypes.SingleInt32FieldNumber].Accessor.Clear(message);
+ fields[TestAllTypes.SingleStringFieldNumber].Accessor.Clear(message);
+ fields[TestAllTypes.SingleBytesFieldNumber].Accessor.Clear(message);
+ fields[TestAllTypes.SingleForeignEnumFieldNumber].Accessor.Clear(message);
+ fields[TestAllTypes.SingleForeignMessageFieldNumber].Accessor.Clear(message);
+ fields[TestAllTypes.RepeatedDoubleFieldNumber].Accessor.Clear(message);
+
+ var expected = new TestAllTypes(SampleMessages.CreateFullTestAllTypes())
+ {
+ SingleBool = false,
+ SingleInt32 = 0,
+ SingleString = "",
+ SingleBytes = ByteString.Empty,
+ SingleForeignEnum = 0,
+ SingleForeignMessage = null,
+ };
+ expected.RepeatedDouble.Clear();
+
+ Assert.AreEqual(expected, message);
+
+ // Separately, maps.
+ var mapMessage = new TestMap { MapStringString = { { "key1", "value1" }, { "key2", "value2" } } };
+ fields = TestMap.Descriptor.Fields;
+ fields[TestMap.MapStringStringFieldNumber].Accessor.Clear(mapMessage);
+ Assert.AreEqual(0, mapMessage.MapStringString.Count);
+ }
+
+ [Test]
+ public void SetValue_SingleFields()
+ {
+ // Just a sample (primitives, messages, enums, strings, byte strings)
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var fields = TestAllTypes.Descriptor.Fields;
+ fields[TestAllTypes.SingleBoolFieldNumber].Accessor.SetValue(message, false);
+ fields[TestAllTypes.SingleInt32FieldNumber].Accessor.SetValue(message, 500);
+ fields[TestAllTypes.SingleStringFieldNumber].Accessor.SetValue(message, "It's a string");
+ fields[TestAllTypes.SingleBytesFieldNumber].Accessor.SetValue(message, ByteString.CopyFrom(99, 98, 97));
+ fields[TestAllTypes.SingleForeignEnumFieldNumber].Accessor.SetValue(message, ForeignEnum.ForeignFoo);
+ fields[TestAllTypes.SingleForeignMessageFieldNumber].Accessor.SetValue(message, new ForeignMessage { C = 12345 });
+ fields[TestAllTypes.SingleDoubleFieldNumber].Accessor.SetValue(message, 20150701.5);
+
+ var expected = new TestAllTypes(SampleMessages.CreateFullTestAllTypes())
+ {
+ SingleBool = false,
+ SingleInt32 = 500,
+ SingleString = "It's a string",
+ SingleBytes = ByteString.CopyFrom(99, 98, 97),
+ SingleForeignEnum = ForeignEnum.ForeignFoo,
+ SingleForeignMessage = new ForeignMessage { C = 12345 },
+ SingleDouble = 20150701.5
+ };
+
+ Assert.AreEqual(expected, message);
+ }
+
+ [Test]
+ public void SetValue_SingleFields_WrongType()
+ {
+ IMessage message = SampleMessages.CreateFullTestAllTypes();
+ var fields = message.Descriptor.Fields;
+ Assert.Throws<InvalidCastException>(() => fields[TestAllTypes.SingleBoolFieldNumber].Accessor.SetValue(message, "This isn't a bool"));
+ }
+
+ [Test]
+ public void SetValue_MapFields()
+ {
+ IMessage message = new TestMap();
+ var fields = message.Descriptor.Fields;
+ Assert.Throws<InvalidOperationException>(() => fields[TestMap.MapStringStringFieldNumber].Accessor.SetValue(message, new Dictionary<string, string>()));
+ }
+
+ [Test]
+ public void SetValue_RepeatedFields()
+ {
+ IMessage message = SampleMessages.CreateFullTestAllTypes();
+ var fields = message.Descriptor.Fields;
+ Assert.Throws<InvalidOperationException>(() => fields[TestAllTypes.RepeatedDoubleFieldNumber].Accessor.SetValue(message, new double[10]));
+ }
+
+ [Test]
+ public void GetValue_IncorrectType()
+ {
+ IMessage message = SampleMessages.CreateFullTestAllTypes();
+ var fields = message.Descriptor.Fields;
+ Assert.Throws<InvalidCastException>(() => fields[TestAllTypes.SingleBoolFieldNumber].Accessor.GetValue(new TestMap()));
+ }
+
+ [Test]
+ public void Oneof()
+ {
+ var message = new TestAllTypes();
+ var descriptor = TestAllTypes.Descriptor;
+ Assert.AreEqual(1, descriptor.Oneofs.Count);
+ var oneof = descriptor.Oneofs[0];
+ Assert.AreEqual("oneof_field", oneof.Name);
+ Assert.IsNull(oneof.Accessor.GetCaseFieldDescriptor(message));
+
+ message.OneofString = "foo";
+ Assert.AreSame(descriptor.Fields[TestAllTypes.OneofStringFieldNumber], oneof.Accessor.GetCaseFieldDescriptor(message));
+
+ message.OneofUint32 = 10;
+ Assert.AreSame(descriptor.Fields[TestAllTypes.OneofUint32FieldNumber], oneof.Accessor.GetCaseFieldDescriptor(message));
+
+ oneof.Accessor.Clear(message);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase);
+ }
+
+ [Test]
+ public void FieldDescriptor_ByName()
+ {
+ var descriptor = TestAllTypes.Descriptor;
+ Assert.AreSame(
+ descriptor.Fields[TestAllTypes.SingleBoolFieldNumber],
+ descriptor.Fields["single_bool"]);
+ }
+
+ [Test]
+ public void FieldDescriptor_NotFound()
+ {
+ var descriptor = TestAllTypes.Descriptor;
+ Assert.Throws<KeyNotFoundException>(() => descriptor.Fields[999999].ToString());
+ Assert.Throws<KeyNotFoundException>(() => descriptor.Fields["not found"].ToString());
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Reflection/TypeRegistryTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Reflection/TypeRegistryTest.cs
new file mode 100644
index 0000000000..5be7ca2361
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Reflection/TypeRegistryTest.cs
@@ -0,0 +1,94 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using Google.Protobuf.TestProtos;
+using Google.Protobuf.WellKnownTypes;
+using NUnit.Framework;
+
+namespace Google.Protobuf.Reflection
+{
+ public class TypeRegistryTest
+ {
+ // Most of our tests use messages. Simple test that we really can use files...
+ [Test]
+ public void CreateWithFileDescriptor()
+ {
+ var registry = TypeRegistry.FromFiles(DurationReflection.Descriptor, StructReflection.Descriptor);
+ AssertDescriptorPresent(registry, Duration.Descriptor);
+ AssertDescriptorPresent(registry, ListValue.Descriptor);
+ AssertDescriptorAbsent(registry, Timestamp.Descriptor);
+ }
+
+ [Test]
+ public void TypesFromSameFile()
+ {
+ // Just for kicks, let's start with a nested type
+ var registry = TypeRegistry.FromMessages(TestAllTypes.Types.NestedMessage.Descriptor);
+ // Top-level...
+ AssertDescriptorPresent(registry, TestFieldOrderings.Descriptor);
+ // ... and nested (not the same as the original NestedMessage!)
+ AssertDescriptorPresent(registry, TestFieldOrderings.Types.NestedMessage.Descriptor);
+ }
+
+ [Test]
+ public void DependenciesAreIncluded()
+ {
+ var registry = TypeRegistry.FromMessages(TestAllTypes.Descriptor);
+ // Direct dependencies
+ AssertDescriptorPresent(registry, ImportMessage.Descriptor);
+ // Public dependencies
+ AssertDescriptorPresent(registry, PublicImportMessage.Descriptor);
+ }
+
+ [Test]
+ public void DuplicateFiles()
+ {
+ // Duplicates via dependencies and simply via repetition
+ var registry = TypeRegistry.FromFiles(
+ UnittestProto3Reflection.Descriptor, UnittestImportProto3Reflection.Descriptor,
+ TimestampReflection.Descriptor, TimestampReflection.Descriptor);
+ AssertDescriptorPresent(registry, TestAllTypes.Descriptor);
+ AssertDescriptorPresent(registry, ImportMessage.Descriptor);
+ AssertDescriptorPresent(registry, Timestamp.Descriptor);
+ }
+
+ private static void AssertDescriptorPresent(TypeRegistry registry, MessageDescriptor descriptor)
+ {
+ Assert.AreSame(descriptor, registry.Find(descriptor.FullName));
+ }
+
+ private static void AssertDescriptorAbsent(TypeRegistry registry, MessageDescriptor descriptor)
+ {
+ Assert.IsNull(registry.Find(descriptor.FullName));
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/SampleEnum.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/SampleEnum.cs
new file mode 100644
index 0000000000..77447afa12
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/SampleEnum.cs
@@ -0,0 +1,42 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+namespace Google.Protobuf
+{
+ // Just a sample enum with positive and negative values to be used in tests.
+ internal enum SampleEnum
+ {
+ NegativeValue = -2,
+ None = 0,
+ PositiveValue = 3
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/SampleMessages.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/SampleMessages.cs
new file mode 100644
index 0000000000..ffa4e2a7c2
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/SampleMessages.cs
@@ -0,0 +1,99 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using Google.Protobuf.TestProtos;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Helper methods to create sample instances of types generated from unit test messages.
+ /// </summary>
+ public class SampleMessages
+ {
+ /// <summary>
+ /// Creates a new sample TestAllTypes message with all fields populated.
+ /// The "oneof" field is populated with the string property (OneofString).
+ /// </summary>
+ public static TestAllTypes CreateFullTestAllTypes()
+ {
+ return new TestAllTypes
+ {
+ SingleBool = true,
+ SingleBytes = ByteString.CopyFrom(1, 2, 3, 4),
+ SingleDouble = 23.5,
+ SingleFixed32 = 23,
+ SingleFixed64 = 1234567890123,
+ SingleFloat = 12.25f,
+ SingleForeignEnum = ForeignEnum.ForeignBar,
+ SingleForeignMessage = new ForeignMessage { C = 10 },
+ SingleImportEnum = ImportEnum.ImportBaz,
+ SingleImportMessage = new ImportMessage { D = 20 },
+ SingleInt32 = 100,
+ SingleInt64 = 3210987654321,
+ SingleNestedEnum = TestAllTypes.Types.NestedEnum.Foo,
+ SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 35 },
+ SinglePublicImportMessage = new PublicImportMessage { E = 54 },
+ SingleSfixed32 = -123,
+ SingleSfixed64 = -12345678901234,
+ SingleSint32 = -456,
+ SingleSint64 = -12345678901235,
+ SingleString = "test",
+ SingleUint32 = UInt32.MaxValue,
+ SingleUint64 = UInt64.MaxValue,
+ RepeatedBool = { true, false },
+ RepeatedBytes = { ByteString.CopyFrom(1, 2, 3, 4), ByteString.CopyFrom(5, 6), ByteString.CopyFrom(new byte[1000]) },
+ RepeatedDouble = { -12.25, 23.5 },
+ RepeatedFixed32 = { UInt32.MaxValue, 23 },
+ RepeatedFixed64 = { UInt64.MaxValue, 1234567890123 },
+ RepeatedFloat = { 100f, 12.25f },
+ RepeatedForeignEnum = { ForeignEnum.ForeignFoo, ForeignEnum.ForeignBar },
+ RepeatedForeignMessage = { new ForeignMessage(), new ForeignMessage { C = 10 } },
+ RepeatedImportEnum = { ImportEnum.ImportBaz, ImportEnum.Unspecified },
+ RepeatedImportMessage = { new ImportMessage { D = 20 }, new ImportMessage { D = 25 } },
+ RepeatedInt32 = { 100, 200 },
+ RepeatedInt64 = { 3210987654321, Int64.MaxValue },
+ RepeatedNestedEnum = { TestAllTypes.Types.NestedEnum.Foo, TestAllTypes.Types.NestedEnum.Neg },
+ RepeatedNestedMessage = { new TestAllTypes.Types.NestedMessage { Bb = 35 }, new TestAllTypes.Types.NestedMessage { Bb = 10 } },
+ RepeatedPublicImportMessage = { new PublicImportMessage { E = 54 }, new PublicImportMessage { E = -1 } },
+ RepeatedSfixed32 = { -123, 123 },
+ RepeatedSfixed64 = { -12345678901234, 12345678901234 },
+ RepeatedSint32 = { -456, 100 },
+ RepeatedSint64 = { -12345678901235, 123 },
+ RepeatedString = { "foo", "bar" },
+ RepeatedUint32 = { UInt32.MaxValue, UInt32.MinValue },
+ RepeatedUint64 = { UInt64.MaxValue, UInt32.MinValue },
+ OneofString = "Oneof string"
+ };
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/TestCornerCases.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/TestCornerCases.cs
new file mode 100644
index 0000000000..248f5fa913
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/TestCornerCases.cs
@@ -0,0 +1,62 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using UnitTest.Issues.TestProtos;
+using NUnit.Framework;
+
+namespace Google.Protobuf
+{
+ public class TestCornerCases
+ {
+ [Test]
+ public void TestRoundTripNegativeEnums()
+ {
+ NegativeEnumMessage msg = new NegativeEnumMessage
+ {
+ Value = NegativeEnum.MinusOne,
+ Values = { NegativeEnum.Zero, NegativeEnum.MinusOne, NegativeEnum.FiveBelow },
+ PackedValues = { NegativeEnum.Zero, NegativeEnum.MinusOne, NegativeEnum.FiveBelow }
+ };
+
+ Assert.AreEqual(58, msg.CalculateSize());
+
+ byte[] bytes = new byte[58];
+ CodedOutputStream output = new CodedOutputStream(bytes);
+
+ msg.WriteTo(output);
+ Assert.AreEqual(0, output.SpaceLeft);
+
+ NegativeEnumMessage copy = NegativeEnumMessage.Parser.ParseFrom(bytes);
+ Assert.AreEqual(msg, copy);
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/TestProtos/ForeignMessagePartial.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/TestProtos/ForeignMessagePartial.cs
new file mode 100644
index 0000000000..5663a69902
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/TestProtos/ForeignMessagePartial.cs
@@ -0,0 +1,45 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 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.
+#endregion
+
+namespace Google.Protobuf.TestProtos
+{
+ /// <summary>
+ /// A message with custom diagnostics (to test that they work).
+ /// </summary>
+ public partial class ForeignMessage : ICustomDiagnosticMessage
+ {
+ public string ToDiagnosticString()
+ {
+ return $"{{ \"c\": {C}, \"@cInHex\": \"{C:x}\" }}";
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs
new file mode 100644
index 0000000000..4aecc998de
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs
@@ -0,0 +1,116 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+
+namespace Google.Protobuf.WellKnownTypes
+{
+ public class AnyTest
+ {
+ [Test]
+ public void Pack()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var any = Any.Pack(message);
+ Assert.AreEqual("type.googleapis.com/protobuf_unittest.TestAllTypes", any.TypeUrl);
+ Assert.AreEqual(message.CalculateSize(), any.Value.Length);
+ }
+
+ [Test]
+ public void Pack_WithCustomPrefix()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var any = Any.Pack(message, "foo.bar/baz");
+ Assert.AreEqual("foo.bar/baz/protobuf_unittest.TestAllTypes", any.TypeUrl);
+ Assert.AreEqual(message.CalculateSize(), any.Value.Length);
+ }
+
+ [Test]
+ public void Pack_WithCustomPrefixTrailingSlash()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var any = Any.Pack(message, "foo.bar/baz/");
+ Assert.AreEqual("foo.bar/baz/protobuf_unittest.TestAllTypes", any.TypeUrl);
+ Assert.AreEqual(message.CalculateSize(), any.Value.Length);
+ }
+
+ [Test]
+ public void Unpack_WrongType()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var any = Any.Pack(message);
+ Assert.Throws<InvalidProtocolBufferException>(() => any.Unpack<TestOneof>());
+ }
+
+ [Test]
+ public void Unpack_Success()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var any = Any.Pack(message);
+ var unpacked = any.Unpack<TestAllTypes>();
+ Assert.AreEqual(message, unpacked);
+ }
+
+ [Test]
+ public void Unpack_CustomPrefix_Success()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var any = Any.Pack(message, "foo.bar/baz");
+ var unpacked = any.Unpack<TestAllTypes>();
+ Assert.AreEqual(message, unpacked);
+ }
+
+ [Test]
+ public void ToString_WithValues()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var any = Any.Pack(message);
+ var text = any.ToString();
+ Assert.That(text, Does.Contain("\"@value\": \"" + message.ToByteString().ToBase64() + "\""));
+ }
+
+ [Test]
+ public void ToString_Empty()
+ {
+ var any = new Any();
+ Assert.AreEqual("{ \"@type\": \"\", \"@value\": \"\" }", any.ToString());
+ }
+
+ [Test]
+ public void ToString_MessageContainingAny()
+ {
+ var message = new TestWellKnownTypes { AnyField = new Any() };
+ Assert.AreEqual("{ \"anyField\": { \"@type\": \"\", \"@value\": \"\" } }", message.ToString());
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs
new file mode 100644
index 0000000000..141faf80e0
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs
@@ -0,0 +1,132 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using NUnit.Framework;
+using System;
+
+namespace Google.Protobuf.WellKnownTypes
+{
+ public class DurationTest
+ {
+ [Test]
+ public void ToTimeSpan()
+ {
+ Assert.AreEqual(TimeSpan.FromSeconds(1), new Duration { Seconds = 1 }.ToTimeSpan());
+ Assert.AreEqual(TimeSpan.FromSeconds(-1), new Duration { Seconds = -1 }.ToTimeSpan());
+ Assert.AreEqual(TimeSpan.FromMilliseconds(1), new Duration { Nanos = 1000000 }.ToTimeSpan());
+ Assert.AreEqual(TimeSpan.FromMilliseconds(-1), new Duration { Nanos = -1000000 }.ToTimeSpan());
+ Assert.AreEqual(TimeSpan.FromTicks(1), new Duration { Nanos = 100 }.ToTimeSpan());
+ Assert.AreEqual(TimeSpan.FromTicks(-1), new Duration { Nanos = -100 }.ToTimeSpan());
+
+ // Rounding is towards 0
+ Assert.AreEqual(TimeSpan.FromTicks(2), new Duration { Nanos = 250 }.ToTimeSpan());
+ Assert.AreEqual(TimeSpan.FromTicks(-2), new Duration { Nanos = -250 }.ToTimeSpan());
+ }
+
+ [Test]
+ public void Addition()
+ {
+ Assert.AreEqual(new Duration { Seconds = 2, Nanos = 100000000 },
+ new Duration { Seconds = 1, Nanos = 600000000 } + new Duration { Nanos = 500000000 });
+ Assert.AreEqual(new Duration { Seconds = -2, Nanos = -100000000 },
+ new Duration { Seconds = -1, Nanos = -600000000 } + new Duration { Nanos = -500000000 });
+ Assert.AreEqual(new Duration { Seconds = 1, Nanos = 100000000 },
+ new Duration { Seconds = 1, Nanos = 600000000 } + new Duration { Nanos = -500000000 });
+
+ // Non-normalized durations, or non-normalized intermediate results
+ Assert.AreEqual(new Duration { Seconds = 1 },
+ new Duration { Seconds = 1, Nanos = -500000000 } + new Duration { Nanos = 500000000 });
+
+ Assert.AreEqual(new Duration { Nanos = -900000000 },
+ new Duration { Seconds = -1, Nanos = -100000000 } + new Duration { Nanos = 200000000 });
+ Assert.AreEqual(new Duration { Nanos = 900000000 },
+ new Duration { Seconds = 1, Nanos = 100000000 } + new Duration { Nanos = -200000000 });
+ }
+
+ [Test]
+ public void Subtraction()
+ {
+ Assert.AreEqual(new Duration { Seconds = 1, Nanos = 100000000 },
+ new Duration { Seconds = 1, Nanos = 600000000 } - new Duration { Nanos = 500000000 });
+ Assert.AreEqual(new Duration { Seconds = -1, Nanos = -100000000 },
+ new Duration { Seconds = -1, Nanos = -600000000 } - new Duration { Nanos = -500000000 });
+ Assert.AreEqual(new Duration { Seconds = 2, Nanos = 100000000 },
+ new Duration { Seconds = 1, Nanos = 600000000 } - new Duration { Nanos = -500000000 });
+
+ // Non-normalized durations
+ Assert.AreEqual(new Duration(),
+ new Duration { Seconds = 1, Nanos = -500000000 } - new Duration { Nanos = 500000000 });
+ Assert.AreEqual(new Duration { Seconds = 1 },
+ new Duration { Nanos = 2000000000 } - new Duration { Nanos = 1000000000 });
+ }
+
+ [Test]
+ public void FromTimeSpan()
+ {
+ Assert.AreEqual(new Duration { Seconds = 1 }, Duration.FromTimeSpan(TimeSpan.FromSeconds(1)));
+ Assert.AreEqual(new Duration { Nanos = Duration.NanosecondsPerTick }, Duration.FromTimeSpan(TimeSpan.FromTicks(1)));
+ }
+
+ [Test]
+ [TestCase(0, Duration.MaxNanoseconds + 1)]
+ [TestCase(0, Duration.MinNanoseconds - 1)]
+ [TestCase(Duration.MinSeconds - 1, 0)]
+ [TestCase(Duration.MaxSeconds + 1, 0)]
+ [TestCase(1, -1)]
+ [TestCase(-1, 1)]
+ public void ToTimeSpan_Invalid(long seconds, int nanoseconds)
+ {
+ var duration = new Duration { Seconds = seconds, Nanos = nanoseconds };
+ Assert.Throws<InvalidOperationException>(() => duration.ToTimeSpan());
+ }
+
+ [Test]
+ [TestCase(0, Duration.MaxNanoseconds)]
+ [TestCase(0, Duration.MinNanoseconds)]
+ [TestCase(Duration.MinSeconds, Duration.MinNanoseconds)]
+ [TestCase(Duration.MaxSeconds, Duration.MaxNanoseconds)]
+ public void ToTimeSpan_Valid(long seconds, int nanoseconds)
+ {
+ // Only testing that these values don't throw, unlike their similar tests in ToTimeSpan_Invalid
+ var duration = new Duration { Seconds = seconds, Nanos = nanoseconds };
+ duration.ToTimeSpan();
+ }
+
+ [Test]
+ public void ToString_NonNormalized()
+ {
+ // Just a single example should be sufficient...
+ var duration = new Duration { Seconds = 1, Nanos = -1 };
+ Assert.AreEqual("{ \"@warning\": \"Invalid Duration\", \"seconds\": \"1\", \"nanos\": -1 }", duration.ToString());
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/FieldMaskTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/FieldMaskTest.cs
new file mode 100644
index 0000000000..1d9908b4d3
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/FieldMaskTest.cs
@@ -0,0 +1,62 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 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.
+#endregion
+
+
+using NUnit.Framework;
+
+namespace Google.Protobuf.WellKnownTypes
+{
+ public class FieldMaskTest
+ {
+ [Test]
+ [TestCase("foo__bar")]
+ [TestCase("foo_3_ar")]
+ [TestCase("fooBar")]
+ public void ToString_Invalid(string input)
+ {
+ var mask = new FieldMask { Paths = { input } };
+ var text = mask.ToString();
+ // More specific test below
+ Assert.That(text, Does.Contain("@warning"));
+ Assert.That(text, Does.Contain(input));
+ }
+
+ [Test]
+ public void ToString_Invalid_Precise()
+ {
+ var mask = new FieldMask { Paths = { "x", "foo__bar", @"x\y" } };
+ Assert.AreEqual(
+ "{ \"@warning\": \"Invalid FieldMask\", \"paths\": [ \"x\", \"foo__bar\", \"x\\\\y\" ] }",
+ mask.ToString());
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/TimestampTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/TimestampTest.cs
new file mode 100644
index 0000000000..9ecd24c62a
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/TimestampTest.cs
@@ -0,0 +1,115 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using NUnit.Framework;
+using System;
+
+namespace Google.Protobuf.WellKnownTypes
+{
+ public class TimestampTest
+ {
+ [Test]
+ public void FromAndToDateTime()
+ {
+ DateTime utcMin = DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc);
+ DateTime utcMax = DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Utc);
+ AssertRoundtrip(new Timestamp { Seconds = -62135596800 }, utcMin);
+ AssertRoundtrip(new Timestamp { Seconds = 253402300799, Nanos = 999999900 }, utcMax);
+ AssertRoundtrip(new Timestamp(), new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc));
+ AssertRoundtrip(new Timestamp { Nanos = 1000000}, new DateTime(1970, 1, 1, 0, 0, 0, 1, DateTimeKind.Utc));
+ AssertRoundtrip(new Timestamp { Seconds = -1, Nanos = 999000000 }, new DateTime(1969, 12, 31, 23, 59, 59, 999, DateTimeKind.Utc));
+ AssertRoundtrip(new Timestamp { Seconds = 3600 }, new DateTime(1970, 1, 1, 1, 0, 0, DateTimeKind.Utc));
+ AssertRoundtrip(new Timestamp { Seconds = -3600 }, new DateTime(1969, 12, 31, 23, 0, 0, DateTimeKind.Utc));
+ }
+
+ [Test]
+ public void ToDateTimeTruncation()
+ {
+ var t1 = new Timestamp { Seconds = 1, Nanos = 1000000 + Duration.NanosecondsPerTick - 1 };
+ Assert.AreEqual(new DateTime(1970, 1, 1, 0, 0, 1, DateTimeKind.Utc).AddMilliseconds(1), t1.ToDateTime());
+
+ var t2 = new Timestamp { Seconds = -1, Nanos = 1000000 + Duration.NanosecondsPerTick - 1 };
+ Assert.AreEqual(new DateTime(1969, 12, 31, 23, 59, 59).AddMilliseconds(1), t2.ToDateTime());
+ }
+
+ [Test]
+ [TestCase(Timestamp.UnixSecondsAtBclMinValue - 1, Timestamp.MaxNanos)]
+ [TestCase(Timestamp.UnixSecondsAtBclMaxValue + 1, 0)]
+ [TestCase(0, -1)]
+ [TestCase(0, Timestamp.MaxNanos + 1)]
+ public void ToDateTime_OutOfRange(long seconds, int nanoseconds)
+ {
+ var value = new Timestamp { Seconds = seconds, Nanos = nanoseconds };
+ Assert.Throws<InvalidOperationException>(() => value.ToDateTime());
+ }
+
+ // 1ns larger or smaller than the above values
+ [Test]
+ [TestCase(Timestamp.UnixSecondsAtBclMinValue, 0)]
+ [TestCase(Timestamp.UnixSecondsAtBclMaxValue, Timestamp.MaxNanos)]
+ [TestCase(0, 0)]
+ [TestCase(0, Timestamp.MaxNanos)]
+ public void ToDateTime_ValidBoundaries(long seconds, int nanoseconds)
+ {
+ var value = new Timestamp { Seconds = seconds, Nanos = nanoseconds };
+ value.ToDateTime();
+ }
+
+ private static void AssertRoundtrip(Timestamp timestamp, DateTime dateTime)
+ {
+ Assert.AreEqual(timestamp, Timestamp.FromDateTime(dateTime));
+ Assert.AreEqual(dateTime, timestamp.ToDateTime());
+ Assert.AreEqual(DateTimeKind.Utc, timestamp.ToDateTime().Kind);
+ }
+
+ [Test]
+ public void Arithmetic()
+ {
+ Timestamp t1 = new Timestamp { Seconds = 10000, Nanos = 5000 };
+ Timestamp t2 = new Timestamp { Seconds = 8000, Nanos = 10000 };
+ Duration difference = new Duration { Seconds = 1999, Nanos = Duration.NanosecondsPerSecond - 5000 };
+ Assert.AreEqual(difference, t1 - t2);
+ Assert.AreEqual(-difference, t2 - t1);
+
+ Assert.AreEqual(t1, t2 + difference);
+ Assert.AreEqual(t2, t1 - difference);
+ }
+
+ [Test]
+ public void ToString_NonNormalized()
+ {
+ // Just a single example should be sufficient...
+ var duration = new Timestamp { Seconds = 1, Nanos = -1 };
+ Assert.AreEqual("{ \"@warning\": \"Invalid Timestamp\", \"seconds\": \"1\", \"nanos\": -1 }", duration.ToString());
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs
new file mode 100644
index 0000000000..5b7185dcd2
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs
@@ -0,0 +1,421 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+using System.Collections;
+using System.IO;
+
+namespace Google.Protobuf.WellKnownTypes
+{
+ public class WrappersTest
+ {
+ [Test]
+ public void NullIsDefault()
+ {
+ var message = new TestWellKnownTypes();
+ Assert.IsNull(message.StringField);
+ Assert.IsNull(message.BytesField);
+ Assert.IsNull(message.BoolField);
+ Assert.IsNull(message.FloatField);
+ Assert.IsNull(message.DoubleField);
+ Assert.IsNull(message.Int32Field);
+ Assert.IsNull(message.Int64Field);
+ Assert.IsNull(message.Uint32Field);
+ Assert.IsNull(message.Uint64Field);
+ }
+
+ [Test]
+ public void NonDefaultSingleValues()
+ {
+ var message = new TestWellKnownTypes
+ {
+ StringField = "x",
+ BytesField = ByteString.CopyFrom(1, 2, 3),
+ BoolField = true,
+ FloatField = 12.5f,
+ DoubleField = 12.25d,
+ Int32Field = 1,
+ Int64Field = 2,
+ Uint32Field = 3,
+ Uint64Field = 4
+ };
+
+ var bytes = message.ToByteArray();
+ var parsed = TestWellKnownTypes.Parser.ParseFrom(bytes);
+
+ Assert.AreEqual("x", parsed.StringField);
+ Assert.AreEqual(ByteString.CopyFrom(1, 2, 3), parsed.BytesField);
+ Assert.AreEqual(true, parsed.BoolField);
+ Assert.AreEqual(12.5f, parsed.FloatField);
+ Assert.AreEqual(12.25d, parsed.DoubleField);
+ Assert.AreEqual(1, parsed.Int32Field);
+ Assert.AreEqual(2L, parsed.Int64Field);
+ Assert.AreEqual(3U, parsed.Uint32Field);
+ Assert.AreEqual(4UL, parsed.Uint64Field);
+ }
+
+ [Test]
+ public void NonNullDefaultIsPreservedThroughSerialization()
+ {
+ var message = new TestWellKnownTypes
+ {
+ StringField = "",
+ BytesField = ByteString.Empty,
+ BoolField = false,
+ FloatField = 0f,
+ DoubleField = 0d,
+ Int32Field = 0,
+ Int64Field = 0,
+ Uint32Field = 0,
+ Uint64Field = 0
+ };
+
+ var bytes = message.ToByteArray();
+ var parsed = TestWellKnownTypes.Parser.ParseFrom(bytes);
+
+ Assert.AreEqual("", parsed.StringField);
+ Assert.AreEqual(ByteString.Empty, parsed.BytesField);
+ Assert.AreEqual(false, parsed.BoolField);
+ Assert.AreEqual(0f, parsed.FloatField);
+ Assert.AreEqual(0d, parsed.DoubleField);
+ Assert.AreEqual(0, parsed.Int32Field);
+ Assert.AreEqual(0L, parsed.Int64Field);
+ Assert.AreEqual(0U, parsed.Uint32Field);
+ Assert.AreEqual(0UL, parsed.Uint64Field);
+ }
+
+ [Test]
+ public void RepeatedWrappersProhibitNullItems()
+ {
+ var message = new RepeatedWellKnownTypes();
+ Assert.Throws<ArgumentNullException>(() => message.BoolField.Add((bool?) null));
+ Assert.Throws<ArgumentNullException>(() => message.Int32Field.Add((int?) null));
+ Assert.Throws<ArgumentNullException>(() => message.StringField.Add((string) null));
+ Assert.Throws<ArgumentNullException>(() => message.BytesField.Add((ByteString) null));
+ }
+
+ [Test]
+ public void RepeatedWrappersSerializeDeserialize()
+ {
+ var message = new RepeatedWellKnownTypes
+ {
+ BoolField = { true, false },
+ BytesField = { ByteString.CopyFrom(1, 2, 3), ByteString.CopyFrom(4, 5, 6), ByteString.Empty },
+ DoubleField = { 12.5, -1.5, 0d },
+ FloatField = { 123.25f, -20f, 0f },
+ Int32Field = { int.MaxValue, int.MinValue, 0 },
+ Int64Field = { long.MaxValue, long.MinValue, 0L },
+ StringField = { "First", "Second", "" },
+ Uint32Field = { uint.MaxValue, uint.MinValue, 0U },
+ Uint64Field = { ulong.MaxValue, ulong.MinValue, 0UL },
+ };
+ var bytes = message.ToByteArray();
+ var parsed = RepeatedWellKnownTypes.Parser.ParseFrom(bytes);
+
+ Assert.AreEqual(message, parsed);
+ // Just to test a single value for sanity...
+ Assert.AreEqual("Second", message.StringField[1]);
+ }
+
+ [Test]
+ public void RepeatedWrappersBinaryFormat()
+ {
+ // At one point we accidentally used a packed format for repeated wrappers, which is wrong (and weird).
+ // This test is just to prove that we use the right format.
+
+ var rawOutput = new MemoryStream();
+ var output = new CodedOutputStream(rawOutput);
+ // Write a value of 5
+ output.WriteTag(RepeatedWellKnownTypes.Int32FieldFieldNumber, WireFormat.WireType.LengthDelimited);
+ output.WriteLength(2);
+ output.WriteTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Varint);
+ output.WriteInt32(5);
+ // Write a value of 0 (empty message)
+ output.WriteTag(RepeatedWellKnownTypes.Int32FieldFieldNumber, WireFormat.WireType.LengthDelimited);
+ output.WriteLength(0);
+ output.Flush();
+ var expectedBytes = rawOutput.ToArray();
+
+ var message = new RepeatedWellKnownTypes { Int32Field = { 5, 0 } };
+ var actualBytes = message.ToByteArray();
+ Assert.AreEqual(expectedBytes, actualBytes);
+ }
+
+ [Test]
+ public void MapWrappersSerializeDeserialize()
+ {
+ // Note: no null values here, as they are prohibited in map fields
+ // (despite being representable).
+ var message = new MapWellKnownTypes
+ {
+ BoolField = { { 10, false }, { 20, true } },
+ BytesField = {
+ { -1, ByteString.CopyFrom(1, 2, 3) },
+ { 10, ByteString.CopyFrom(4, 5, 6) },
+ { 1000, ByteString.Empty },
+ },
+ DoubleField = { { 1, 12.5 }, { 10, -1.5 }, { 20, 0d } },
+ FloatField = { { 2, 123.25f }, { 3, -20f }, { 4, 0f } },
+ Int32Field = { { 5, int.MaxValue }, { 6, int.MinValue }, { 7, 0 } },
+ Int64Field = { { 8, long.MaxValue }, { 9, long.MinValue }, { 10, 0L } },
+ StringField = { { 11, "First" }, { 12, "Second" }, { 13, "" } },
+ Uint32Field = { { 15, uint.MaxValue }, { 16, uint.MinValue }, { 17, 0U } },
+ Uint64Field = { { 18, ulong.MaxValue }, { 19, ulong.MinValue }, { 20, 0UL } },
+ };
+
+ var bytes = message.ToByteArray();
+ var parsed = MapWellKnownTypes.Parser.ParseFrom(bytes);
+
+ Assert.AreEqual(message, parsed);
+ // Just to test a single value for sanity...
+ Assert.AreEqual("Second", message.StringField[12]);
+ }
+
+ [Test]
+ public void Reflection_SingleValues()
+ {
+ var message = new TestWellKnownTypes
+ {
+ StringField = "x",
+ BytesField = ByteString.CopyFrom(1, 2, 3),
+ BoolField = true,
+ FloatField = 12.5f,
+ DoubleField = 12.25d,
+ Int32Field = 1,
+ Int64Field = 2,
+ Uint32Field = 3,
+ Uint64Field = 4
+ };
+ var fields = TestWellKnownTypes.Descriptor.Fields;
+
+ Assert.AreEqual("x", fields[TestWellKnownTypes.StringFieldFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(ByteString.CopyFrom(1, 2, 3), fields[TestWellKnownTypes.BytesFieldFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(true, fields[TestWellKnownTypes.BoolFieldFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(12.5f, fields[TestWellKnownTypes.FloatFieldFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(12.25d, fields[TestWellKnownTypes.DoubleFieldFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(1, fields[TestWellKnownTypes.Int32FieldFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(2L, fields[TestWellKnownTypes.Int64FieldFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(3U, fields[TestWellKnownTypes.Uint32FieldFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(4UL, fields[TestWellKnownTypes.Uint64FieldFieldNumber].Accessor.GetValue(message));
+
+ // And a couple of null fields...
+ message.StringField = null;
+ message.FloatField = null;
+ Assert.IsNull(fields[TestWellKnownTypes.StringFieldFieldNumber].Accessor.GetValue(message));
+ Assert.IsNull(fields[TestWellKnownTypes.FloatFieldFieldNumber].Accessor.GetValue(message));
+ }
+
+ [Test]
+ public void Reflection_RepeatedFields()
+ {
+ // Just a single example... note that we can't have a null value here
+ var message = new RepeatedWellKnownTypes { Int32Field = { 1, 2 } };
+ var fields = RepeatedWellKnownTypes.Descriptor.Fields;
+ var list = (IList) fields[RepeatedWellKnownTypes.Int32FieldFieldNumber].Accessor.GetValue(message);
+ CollectionAssert.AreEqual(new[] { 1, 2 }, list);
+ }
+
+ [Test]
+ public void Reflection_MapFields()
+ {
+ // Just a single example... note that we can't have a null value here despite the value type being int?
+ var message = new MapWellKnownTypes { Int32Field = { { 1, 2 } } };
+ var fields = MapWellKnownTypes.Descriptor.Fields;
+ var dictionary = (IDictionary) fields[MapWellKnownTypes.Int32FieldFieldNumber].Accessor.GetValue(message);
+ Assert.AreEqual(2, dictionary[1]);
+ }
+
+ [Test]
+ public void Oneof()
+ {
+ var message = new OneofWellKnownTypes { EmptyField = new Empty() };
+ // Start off with a non-wrapper
+ Assert.AreEqual(OneofWellKnownTypes.OneofFieldOneofCase.EmptyField, message.OneofFieldCase);
+ AssertOneofRoundTrip(message);
+
+ message.StringField = "foo";
+ Assert.AreEqual(OneofWellKnownTypes.OneofFieldOneofCase.StringField, message.OneofFieldCase);
+ AssertOneofRoundTrip(message);
+
+ message.StringField = "foo";
+ Assert.AreEqual(OneofWellKnownTypes.OneofFieldOneofCase.StringField, message.OneofFieldCase);
+ AssertOneofRoundTrip(message);
+
+ message.DoubleField = 0.0f;
+ Assert.AreEqual(OneofWellKnownTypes.OneofFieldOneofCase.DoubleField, message.OneofFieldCase);
+ AssertOneofRoundTrip(message);
+
+ message.DoubleField = 1.0f;
+ Assert.AreEqual(OneofWellKnownTypes.OneofFieldOneofCase.DoubleField, message.OneofFieldCase);
+ AssertOneofRoundTrip(message);
+
+ message.ClearOneofField();
+ Assert.AreEqual(OneofWellKnownTypes.OneofFieldOneofCase.None, message.OneofFieldCase);
+ AssertOneofRoundTrip(message);
+ }
+
+ private void AssertOneofRoundTrip(OneofWellKnownTypes message)
+ {
+ // Normal roundtrip, but explicitly checking the case...
+ var bytes = message.ToByteArray();
+ var parsed = OneofWellKnownTypes.Parser.ParseFrom(bytes);
+ Assert.AreEqual(message, parsed);
+ Assert.AreEqual(message.OneofFieldCase, parsed.OneofFieldCase);
+ }
+
+ [Test]
+ [TestCase("x", "y", "y")]
+ [TestCase("x", "", "x")]
+ [TestCase("x", null, "x")]
+ [TestCase("", "y", "y")]
+ [TestCase("", "", "")]
+ [TestCase("", null, "")]
+ [TestCase(null, "y", "y")]
+ [TestCase(null, "", "")]
+ [TestCase(null, null, null)]
+ public void Merging(string original, string merged, string expected)
+ {
+ var originalMessage = new TestWellKnownTypes { StringField = original };
+ var mergingMessage = new TestWellKnownTypes { StringField = merged };
+ originalMessage.MergeFrom(mergingMessage);
+ Assert.AreEqual(expected, originalMessage.StringField);
+
+ // Try it using MergeFrom(CodedInputStream) too...
+ originalMessage = new TestWellKnownTypes { StringField = original };
+ originalMessage.MergeFrom(mergingMessage.ToByteArray());
+ Assert.AreEqual(expected, originalMessage.StringField);
+ }
+
+ // Merging is odd with wrapper types, due to the way that default values aren't emitted in
+ // the binary stream. In fact we cheat a little bit - a message with an explicitly present default
+ // value will have that default value ignored. See issue 615. Fixing this would require significant upheaval to
+ // the FieldCodec side of things.
+ [Test]
+ public void MergingStreamExplicitValue()
+ {
+ var message = new TestWellKnownTypes { Int32Field = 5 };
+
+ // Create a byte array which has the data of an Int32Value explicitly containing a value of 0.
+ // This wouldn't normally happen.
+ byte[] bytes;
+ var wrapperTag = WireFormat.MakeTag(TestWellKnownTypes.Int32FieldFieldNumber, WireFormat.WireType.LengthDelimited);
+ var valueTag = WireFormat.MakeTag(Int32Value.ValueFieldNumber, WireFormat.WireType.Varint);
+ using (var stream = new MemoryStream())
+ {
+ var coded = new CodedOutputStream(stream);
+ coded.WriteTag(wrapperTag);
+ coded.WriteLength(2); // valueTag + a value 0, each one byte
+ coded.WriteTag(valueTag);
+ coded.WriteInt32(0);
+ coded.Flush();
+ bytes = stream.ToArray();
+ }
+
+ message.MergeFrom(bytes);
+ // A normal implementation would have 0 now, as the explicit default would have been overwritten the 5.
+ // With the FieldCodec for Nullable<int>, we can't tell the difference between an implicit 0 and an explicit 0.
+ Assert.AreEqual(5, message.Int32Field);
+ }
+
+ [Test]
+ public void MergingStreamNoValue()
+ {
+ var message = new TestWellKnownTypes { Int32Field = 5 };
+
+ // Create a byte array which an Int32 field, but with no value.
+ var bytes = new TestWellKnownTypes { Int32Field = 0 }.ToByteArray();
+ Assert.AreEqual(2, bytes.Length); // The tag for Int32Field is a single byte, then a byte indicating a 0-length message.
+ message.MergeFrom(bytes);
+
+ // The "implicit" 0 did *not* overwrite the value.
+ // (This is the correct behaviour.)
+ Assert.AreEqual(5, message.Int32Field);
+ }
+
+ // All permutations of origin/merging value being null, zero (default) or non-default.
+ // As this is the in-memory version, we don't need to worry about the difference between implicit and explicit 0.
+ [Test]
+ [TestCase(null, null, null)]
+ [TestCase(null, 0, 0)]
+ [TestCase(null, 5, 5)]
+ [TestCase(0, null, 0)]
+ [TestCase(0, 0, 0)]
+ [TestCase(0, 5, 5)]
+ [TestCase(5, null, 5)]
+ [TestCase(5, 0, 5)]
+ [TestCase(5, 10, 10)]
+ public void MergingMessageWithZero(int? originValue, int? mergingValue, int? expectedResult)
+ {
+ // This differs from the MergingStreamCornerCase because when we merge message *objects*,
+ // we ignore default values from the "source".
+ var message1 = new TestWellKnownTypes { Int32Field = originValue };
+ var message2 = new TestWellKnownTypes { Int32Field = mergingValue };
+ message1.MergeFrom(message2);
+ Assert.AreEqual(expectedResult, message1.Int32Field);
+ }
+
+ [Test]
+ public void UnknownFieldInWrapper()
+ {
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ var wrapperTag = WireFormat.MakeTag(TestWellKnownTypes.Int32FieldFieldNumber, WireFormat.WireType.LengthDelimited);
+ var unknownTag = WireFormat.MakeTag(15, WireFormat.WireType.Varint);
+ var valueTag = WireFormat.MakeTag(Int32Value.ValueFieldNumber, WireFormat.WireType.Varint);
+
+ output.WriteTag(wrapperTag);
+ output.WriteLength(4); // unknownTag + value 5 + valueType + value 6, each 1 byte
+ output.WriteTag(unknownTag);
+ output.WriteInt32((int) valueTag); // Sneakily "pretend" it's a tag when it's really a value
+ output.WriteTag(valueTag);
+ output.WriteInt32(6);
+
+ output.Flush();
+ stream.Position = 0;
+
+ var message = TestWellKnownTypes.Parser.ParseFrom(stream);
+ Assert.AreEqual(6, message.Int32Field);
+ }
+
+ [Test]
+ public void ClearWithReflection()
+ {
+ // String and Bytes are the tricky ones here, as the CLR type of the property
+ // is the same between the wrapper and non-wrapper types.
+ var message = new TestWellKnownTypes { StringField = "foo" };
+ TestWellKnownTypes.Descriptor.Fields[TestWellKnownTypes.StringFieldFieldNumber].Accessor.Clear(message);
+ Assert.IsNull(message.StringField);
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/project.json b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/project.json
new file mode 100644
index 0000000000..87b732c9b5
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/project.json
@@ -0,0 +1,44 @@
+{
+ "buildOptions": {
+ "debugType": "portable",
+ "keyFile": "../../keys/Google.Protobuf.snk"
+ },
+
+ "configurations": {
+ "Debug": {
+ "buildOptions": {
+ "define": [ "DEBUG", "TRACE" ]
+ }
+ },
+ "Release": {
+ "buildOptions": {
+ "define": [ "RELEASE", "TRACE" ],
+ "optimize": true
+ }
+ }
+ },
+
+ "dependencies": {
+ "Google.Protobuf": { "target": "project" },
+ "NUnit": "3.4.0",
+ "dotnet-test-nunit": "3.4.0-alpha-2",
+ },
+
+ "testRunner": "nunit",
+
+ "frameworks": {
+ "netcoreapp1.0": {
+ "imports" : [ "dnxcore50", "netcoreapp1.0", "portable-net45+win8" ],
+ "buildOptions": {
+ "define": [ "PCL" ]
+ },
+ "dependencies": {
+ "Microsoft.NETCore.App": {
+ "version": "1.0.0",
+ "type": "platform"
+ },
+ "System.Console": "4.0.0"
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/compatibility_tests/v3.0.0/test.sh b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/test.sh
new file mode 100755
index 0000000000..bb04fc2c59
--- /dev/null
+++ b/third_party/protobuf/csharp/compatibility_tests/v3.0.0/test.sh
@@ -0,0 +1,102 @@
+#!/bin/bash
+
+function run_test() {
+ # Generate test proto files.
+ ./protoc_1 -Iprotos/src -I../../../src/ --csharp_out=src/Google.Protobuf.Test \
+ --csharp_opt=base_namespace=Google.Protobuf \
+ protos/src/google/protobuf/unittest_import_proto3.proto \
+ protos/src/google/protobuf/unittest_import_public_proto3.proto \
+ protos/src/google/protobuf/unittest_well_known_types.proto
+
+ ./protoc_1 -Iprotos/csharp --csharp_out=src/Google.Protobuf.Test \
+ --csharp_opt=base_namespace=UnitTest.Issues \
+ protos/csharp/protos/unittest_issues.proto
+
+ ./protoc_2 -Iprotos/src --csharp_out=src/Google.Protobuf.Test \
+ --csharp_opt=base_namespace=Google.Protobuf \
+ protos/src/google/protobuf/unittest_proto3.proto \
+ protos/src/google/protobuf/map_unittest_proto3.proto
+
+ # Build and test.
+ dotnet build -c release src/Google.Protobuf src/Google.Protobuf.Test
+ dotnet test -c release -f netcoreapp1.0 src/Google.Protobuf.Test
+}
+
+set -ex
+
+# Change to the script's directory.
+cd $(dirname $0)
+
+# Version of the tests (i.e., the version of protobuf from where we extracted
+# these tests).
+TEST_VERSION=3.0.0
+
+# The old version of protobuf that we are testing compatibility against. This
+# is usually the same as TEST_VERSION (i.e., we use the tests extracted from
+# that version to test compatibility of the newest runtime against it), but it
+# is also possible to use this same test set to test the compatibiilty of the
+# latest version against other versions.
+case "$1" in
+ ""|3.0.0)
+ OLD_VERSION=3.0.0
+ OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0/protoc-3.0.0-linux-x86_64.exe
+ ;;
+ 3.0.2)
+ OLD_VERSION=3.0.2
+ OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.2/protoc-3.0.2-linux-x86_64.exe
+ ;;
+ 3.1.0)
+ OLD_VERSION=3.1.0
+ OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.1.0/protoc-3.1.0-linux-x86_64.exe
+ ;;
+ *)
+ echo "[ERROR]: Unknown version number: $1"
+ exit 1
+ ;;
+esac
+
+echo "Running compatibility tests with $OLD_VERSION"
+
+# Check protoc
+[ -f ../../../src/protoc ] || {
+ echo "[ERROR]: Please build protoc first."
+ exit 1
+}
+
+# Download old version protoc compiler (for linux).
+wget $OLD_VERSION_PROTOC -O old_protoc
+chmod +x old_protoc
+
+# Test source compatibility. In these tests we recompile everything against
+# the new runtime (including old version generated code).
+# Copy the new runtime and keys.
+cp ../../src/Google.Protobuf src/Google.Protobuf -r
+cp ../../keys . -r
+dotnet restore
+
+# Test A.1:
+# proto set 1: use old version
+# proto set 2 which may import protos in set 1: use old version
+cp old_protoc protoc_1
+cp old_protoc protoc_2
+run_test
+
+# Test A.2:
+# proto set 1: use new version
+# proto set 2 which may import protos in set 1: use old version
+cp ../../../src/protoc protoc_1
+cp old_protoc protoc_2
+run_test
+
+# Test A.3:
+# proto set 1: use old version
+# proto set 2 which may import protos in set 1: use new version
+cp old_protoc protoc_1
+cp ../../../src/protoc protoc_2
+run_test
+
+rm protoc_1
+rm protoc_2
+rm old_protoc
+rm keys -r
+rm src/Google.Protobuf -r
diff --git a/third_party/protobuf/csharp/generate_protos.sh b/third_party/protobuf/csharp/generate_protos.sh
new file mode 100755
index 0000000000..d2f474796f
--- /dev/null
+++ b/third_party/protobuf/csharp/generate_protos.sh
@@ -0,0 +1,68 @@
+#!/bin/bash
+# Generates C# source files from .proto files.
+# You first need to make sure protoc has been built (see instructions on
+# building protoc in root of this repository)
+
+set -ex
+
+# cd to repository root
+pushd $(dirname $0)/..
+
+# Protocol buffer compiler to use. If the PROTOC variable is set,
+# use that. Otherwise, probe for expected locations under both
+# Windows and Unix.
+if [ -z "$PROTOC" ]; then
+ # TODO(jonskeet): Use an array and a for loop instead?
+ if [ -x cmake/build/Debug/protoc.exe ]; then
+ PROTOC=cmake/build/Debug/protoc.exe
+ elif [ -x cmake/build/Release/protoc.exe ]; then
+ PROTOC=cmake/build/Release/protoc.exe
+ elif [ -x src/protoc ]; then
+ PROTOC=src/protoc
+ else
+ echo "Unable to find protocol buffer compiler."
+ exit 1
+ fi
+fi
+
+# descriptor.proto and well-known types
+$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \
+ --csharp_opt=base_namespace=Google.Protobuf \
+ src/google/protobuf/descriptor.proto \
+ src/google/protobuf/any.proto \
+ src/google/protobuf/api.proto \
+ src/google/protobuf/duration.proto \
+ src/google/protobuf/empty.proto \
+ src/google/protobuf/field_mask.proto \
+ src/google/protobuf/source_context.proto \
+ src/google/protobuf/struct.proto \
+ src/google/protobuf/timestamp.proto \
+ src/google/protobuf/type.proto \
+ src/google/protobuf/wrappers.proto
+
+# Test protos where the namespace matches the target location
+$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf.Test \
+ --csharp_opt=base_namespace=Google.Protobuf \
+ src/google/protobuf/map_unittest_proto3.proto \
+ src/google/protobuf/unittest_proto3.proto \
+ src/google/protobuf/unittest_import_proto3.proto \
+ src/google/protobuf/unittest_import_public_proto3.proto \
+ src/google/protobuf/unittest_well_known_types.proto
+
+# Different base namespace to the protos above
+$PROTOC -Isrc -Icsharp/protos --csharp_out=csharp/src/Google.Protobuf.Test \
+ --csharp_opt=base_namespace=UnitTest.Issues \
+ csharp/protos/unittest_issues.proto \
+ csharp/protos/unittest_custom_options_proto3.proto
+
+# Don't specify a base namespace at all; we just want to make sure the
+# results end up in TestProtos.
+$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf.Test/TestProtos \
+ src/google/protobuf/test_messages_proto3.proto
+
+# AddressBook sample protos
+$PROTOC -Iexamples --csharp_out=csharp/src/AddressBook \
+ examples/addressbook.proto
+
+$PROTOC -Iconformance -Isrc --csharp_out=csharp/src/Google.Protobuf.Conformance \
+ conformance/conformance.proto
diff --git a/third_party/protobuf/csharp/keys/Google.Protobuf.public.snk b/third_party/protobuf/csharp/keys/Google.Protobuf.public.snk
new file mode 100644
index 0000000000..59cd36985f
--- /dev/null
+++ b/third_party/protobuf/csharp/keys/Google.Protobuf.public.snk
Binary files differ
diff --git a/third_party/protobuf/csharp/keys/Google.Protobuf.snk b/third_party/protobuf/csharp/keys/Google.Protobuf.snk
new file mode 100644
index 0000000000..7515443ca9
--- /dev/null
+++ b/third_party/protobuf/csharp/keys/Google.Protobuf.snk
Binary files differ
diff --git a/third_party/protobuf/csharp/keys/README.md b/third_party/protobuf/csharp/keys/README.md
new file mode 100644
index 0000000000..ede673573e
--- /dev/null
+++ b/third_party/protobuf/csharp/keys/README.md
@@ -0,0 +1,9 @@
+Contents
+--------
+
+- Google.Protobuf.public.snk:
+ Public key to verify strong name of Google.Protobuf assemblies.
+- Google.Protobuf.snk:
+ Signing key to provide strong name of Google.Protobuf assemblies.
+ As per [Microsoft guidance](https://msdn.microsoft.com/en-us/library/wd40t7ad(v=vs.110).aspx)
+ signing key should be checked into the repository.
diff --git a/third_party/protobuf/csharp/protos/unittest_custom_options_proto3.proto b/third_party/protobuf/csharp/protos/unittest_custom_options_proto3.proto
new file mode 100644
index 0000000000..87bd0f7a84
--- /dev/null
+++ b/third_party/protobuf/csharp/protos/unittest_custom_options_proto3.proto
@@ -0,0 +1,336 @@
+// 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.
+
+// Author: benjy@google.com (Benjy Weinberger)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file used to test the "custom options" feature of google.protobuf.
+
+// This file is based on unittest_custom_options.proto in
+// src/google/protobuf, but is modified for proto3. It could
+// potentially be moved into src/google/protobuf, but currently C#
+// is the only language that really needs it, as we don't support
+// proto2 syntax. It's cut down significantly as proto3 only supports
+// extensions for options.
+
+
+syntax = "proto3";
+
+// A custom file option (defined below).
+option (file_opt1) = 9876543210;
+
+import "google/protobuf/descriptor.proto";
+
+// We don't put this in a package within proto2 because we need to make sure
+// that the generated code doesn't depend on being in the proto2 namespace.
+package protobuf_unittest;
+option csharp_namespace = "UnitTest.Issues.TestProtos";
+
+// Some simple test custom options of various types.
+
+extend google.protobuf.FileOptions {
+ uint64 file_opt1 = 7736974;
+}
+
+extend google.protobuf.MessageOptions {
+ int32 message_opt1 = 7739036;
+}
+
+extend google.protobuf.FieldOptions {
+ fixed64 field_opt1 = 7740936;
+}
+
+extend google.protobuf.OneofOptions {
+ int32 oneof_opt1 = 7740111;
+}
+
+extend google.protobuf.EnumOptions {
+ sfixed32 enum_opt1 = 7753576;
+}
+
+extend google.protobuf.EnumValueOptions {
+ int32 enum_value_opt1 = 1560678;
+}
+
+extend google.protobuf.ServiceOptions {
+ sint64 service_opt1 = 7887650;
+}
+
+enum MethodOpt1 {
+ METHODOPT1_UNSPECIFIED = 0;
+ METHODOPT1_VAL1 = 1;
+ METHODOPT1_VAL2 = 2;
+}
+
+extend google.protobuf.MethodOptions {
+ MethodOpt1 method_opt1 = 7890860;
+}
+
+// A test message with custom options at all possible locations (and also some
+// regular options, to make sure they interact nicely).
+message TestMessageWithCustomOptions {
+ option message_set_wire_format = false;
+
+ option (message_opt1) = -56;
+
+ string field1 = 1 [ctype=CORD,
+ (field_opt1)=8765432109];
+
+ oneof AnOneof {
+ option (oneof_opt1) = -99;
+ int32 oneof_field = 2;
+ }
+
+ enum AnEnum {
+ option (enum_opt1) = -789;
+ ANENUM_UNSPECIFIED = 0;
+ ANENUM_VAL1 = 1;
+ ANENUM_VAL2 = 2 [(enum_value_opt1) = 123];
+ }
+}
+
+
+// A test RPC service with custom options at all possible locations (and also
+// some regular options, to make sure they interact nicely).
+message CustomOptionFooRequest {
+}
+
+message CustomOptionFooResponse {
+}
+
+message CustomOptionFooClientMessage {
+}
+
+message CustomOptionFooServerMessage {
+}
+
+service TestServiceWithCustomOptions {
+ option (service_opt1) = -9876543210;
+
+ rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
+ option (method_opt1) = METHODOPT1_VAL2;
+ }
+}
+
+
+
+// Options of every possible field type, so we can test them all exhaustively.
+
+message DummyMessageContainingEnum {
+ enum TestEnumType {
+ TEST_OPTION_ENUM_UNSPECIFIED = 0;
+ TEST_OPTION_ENUM_TYPE1 = 22;
+ TEST_OPTION_ENUM_TYPE2 = -23;
+ }
+}
+
+message DummyMessageInvalidAsOptionType {
+}
+
+extend google.protobuf.MessageOptions {
+ bool bool_opt = 7706090;
+ int32 int32_opt = 7705709;
+ int64 int64_opt = 7705542;
+ uint32 uint32_opt = 7704880;
+ uint64 uint64_opt = 7702367;
+ sint32 sint32_opt = 7701568;
+ sint64 sint64_opt = 7700863;
+ fixed32 fixed32_opt = 7700307;
+ fixed64 fixed64_opt = 7700194;
+ sfixed32 sfixed32_opt = 7698645;
+ sfixed64 sfixed64_opt = 7685475;
+ float float_opt = 7675390;
+ double double_opt = 7673293;
+ string string_opt = 7673285;
+ bytes bytes_opt = 7673238;
+ DummyMessageContainingEnum.TestEnumType enum_opt = 7673233;
+ DummyMessageInvalidAsOptionType message_type_opt = 7665967;
+}
+
+message CustomOptionMinIntegerValues {
+ option (bool_opt) = false;
+ option (int32_opt) = -0x80000000;
+ option (int64_opt) = -0x8000000000000000;
+ option (uint32_opt) = 0;
+ option (uint64_opt) = 0;
+ option (sint32_opt) = -0x80000000;
+ option (sint64_opt) = -0x8000000000000000;
+ option (fixed32_opt) = 0;
+ option (fixed64_opt) = 0;
+ option (sfixed32_opt) = -0x80000000;
+ option (sfixed64_opt) = -0x8000000000000000;
+}
+
+message CustomOptionMaxIntegerValues {
+ option (bool_opt) = true;
+ option (int32_opt) = 0x7FFFFFFF;
+ option (int64_opt) = 0x7FFFFFFFFFFFFFFF;
+ option (uint32_opt) = 0xFFFFFFFF;
+ option (uint64_opt) = 0xFFFFFFFFFFFFFFFF;
+ option (sint32_opt) = 0x7FFFFFFF;
+ option (sint64_opt) = 0x7FFFFFFFFFFFFFFF;
+ option (fixed32_opt) = 0xFFFFFFFF;
+ option (fixed64_opt) = 0xFFFFFFFFFFFFFFFF;
+ option (sfixed32_opt) = 0x7FFFFFFF;
+ option (sfixed64_opt) = 0x7FFFFFFFFFFFFFFF;
+}
+
+message CustomOptionOtherValues {
+ option (int32_opt) = -100; // To test sign-extension.
+ option (float_opt) = 12.3456789;
+ option (double_opt) = 1.234567890123456789;
+ option (string_opt) = "Hello, \"World\"";
+ option (bytes_opt) = "Hello\0World";
+ option (enum_opt) = TEST_OPTION_ENUM_TYPE2;
+}
+
+message SettingRealsFromPositiveInts {
+ option (float_opt) = 12;
+ option (double_opt) = 154;
+}
+
+message SettingRealsFromNegativeInts {
+ option (float_opt) = -12;
+ option (double_opt) = -154;
+}
+
+// Options of complex message types, themselves combined and extended in
+// various ways.
+
+message ComplexOptionType1 {
+ int32 foo = 1;
+ int32 foo2 = 2;
+ int32 foo3 = 3;
+ repeated int32 foo4 = 4;
+}
+
+message ComplexOptionType2 {
+ ComplexOptionType1 bar = 1;
+ int32 baz = 2;
+
+ message ComplexOptionType4 {
+ int32 waldo = 1;
+
+ extend google.protobuf.MessageOptions {
+ ComplexOptionType4 complex_opt4 = 7633546;
+ }
+ }
+
+ ComplexOptionType4 fred = 3;
+ repeated ComplexOptionType4 barney = 4;
+}
+
+message ComplexOptionType3 {
+ int32 qux = 1;
+}
+
+extend google.protobuf.MessageOptions {
+ protobuf_unittest.ComplexOptionType1 complex_opt1 = 7646756;
+ ComplexOptionType2 complex_opt2 = 7636949;
+ ComplexOptionType3 complex_opt3 = 7636463;
+}
+
+// Note that we try various different ways of naming the same extension.
+message VariousComplexOptions {
+ option (.protobuf_unittest.complex_opt1).foo = 42;
+ option (protobuf_unittest.complex_opt1).foo4 = 99;
+ option (protobuf_unittest.complex_opt1).foo4 = 88;
+ option (complex_opt2).baz = 987;
+ option (complex_opt2).bar.foo = 743;
+ option (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo = 1971;
+ option (complex_opt2).fred.waldo = 321;
+ option (complex_opt2).barney = { waldo: 101 };
+ option (complex_opt2).barney = { waldo: 212 };
+ option (protobuf_unittest.complex_opt3).qux = 9;
+}
+
+// ------------------------------------------------------
+// Definitions for testing aggregate option parsing.
+// See descriptor_unittest.cc.
+
+// A helper type used to test aggregate option parsing
+message Aggregate {
+ int32 i = 1;
+ string s = 2;
+
+ // A nested object
+ Aggregate sub = 3;
+}
+
+// Allow Aggregate to be used as an option at all possible locations
+// in the .proto grammer.
+extend google.protobuf.FileOptions { Aggregate fileopt = 15478479; }
+extend google.protobuf.MessageOptions { Aggregate msgopt = 15480088; }
+extend google.protobuf.FieldOptions { Aggregate fieldopt = 15481374; }
+extend google.protobuf.EnumOptions { Aggregate enumopt = 15483218; }
+extend google.protobuf.EnumValueOptions { Aggregate enumvalopt = 15486921; }
+extend google.protobuf.ServiceOptions { Aggregate serviceopt = 15497145; }
+extend google.protobuf.MethodOptions { Aggregate methodopt = 15512713; }
+
+// Try using AggregateOption at different points in the proto grammar
+option (fileopt) = {
+ s: 'FileAnnotation'
+ // Also test the handling of comments
+ /* of both types */ i: 100
+
+ sub { s: 'NestedFileAnnotation' }
+};
+
+message AggregateMessage {
+ option (msgopt) = { i:101 s:'MessageAnnotation' };
+ int32 fieldname = 1 [(fieldopt) = { s:'FieldAnnotation' }];
+}
+
+service AggregateService {
+ option (serviceopt) = { s:'ServiceAnnotation' };
+ rpc Method (AggregateMessage) returns (AggregateMessage) {
+ option (methodopt) = { s:'MethodAnnotation' };
+ }
+}
+
+enum AggregateEnum {
+ option (enumopt) = { s:'EnumAnnotation' };
+ UNSPECIFIED = 0;
+ VALUE = 1 [(enumvalopt) = { s:'EnumValueAnnotation' }];
+}
+
+// Test custom options for nested type.
+message NestedOptionType {
+ message NestedMessage {
+ option (message_opt1) = 1001;
+ int32 nested_field = 1 [(field_opt1) = 1002];
+ }
+ enum NestedEnum {
+ UNSPECIFIED = 0;
+ option (enum_opt1) = 1003;
+ NESTED_ENUM_VALUE = 1 [(enum_value_opt1) = 1004];
+ }
+}
diff --git a/third_party/protobuf/csharp/protos/unittest_issues.proto b/third_party/protobuf/csharp/protos/unittest_issues.proto
new file mode 100644
index 0000000000..6c9f76344a
--- /dev/null
+++ b/third_party/protobuf/csharp/protos/unittest_issues.proto
@@ -0,0 +1,126 @@
+syntax = "proto3";
+
+// These proto descriptors have at one time been reported as an issue or defect.
+// They are kept here to replicate the issue, and continue to verify the fix.
+
+// Issue: Non-"Google.Protobuffers" namespace will ensure that protobuffer library types are qualified
+option csharp_namespace = "UnitTest.Issues.TestProtos";
+
+package unittest_issues;
+option optimize_for = SPEED;
+
+// Issue 307: when generating doubly-nested types, any references
+// should be of the form A.Types.B.Types.C.
+message Issue307 {
+ message NestedOnce {
+ message NestedTwice {
+ }
+ }
+}
+
+// Old issue 13: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=13
+// New issue 309: https://github.com/google/protobuf/issues/309
+
+// message A {
+// optional int32 _A = 1;
+// }
+
+// message B {
+// optional int32 B_ = 1;
+// }
+
+//message AB {
+// optional int32 a_b = 1;
+//}
+
+// Similar issue with numeric names
+// Java code failed too, so probably best for this to be a restriction.
+// See https://github.com/google/protobuf/issues/308
+// message NumberField {
+// optional int32 _01 = 1;
+// }
+
+// issue 19 - negative enum values
+
+enum NegativeEnum {
+ NEGATIVE_ENUM_ZERO = 0;
+ FiveBelow = -5;
+ MinusOne = -1;
+}
+
+message NegativeEnumMessage {
+ NegativeEnum value = 1;
+ repeated NegativeEnum values = 2 [packed = false];
+ repeated NegativeEnum packed_values = 3 [packed=true];
+}
+
+// Issue 21: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=21
+// Decorate fields with [deprecated=true] as [System.Obsolete]
+
+message DeprecatedChild {
+}
+
+enum DeprecatedEnum {
+ DEPRECATED_ZERO = 0;
+ one = 1;
+}
+
+message DeprecatedFieldsMessage {
+ int32 PrimitiveValue = 1 [deprecated = true];
+ repeated int32 PrimitiveArray = 2 [deprecated = true];
+
+ DeprecatedChild MessageValue = 3 [deprecated = true];
+ repeated DeprecatedChild MessageArray = 4 [deprecated = true];
+
+ DeprecatedEnum EnumValue = 5 [deprecated = true];
+ repeated DeprecatedEnum EnumArray = 6 [deprecated = true];
+}
+
+// Issue 45: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=45
+message ItemField {
+ int32 item = 1;
+}
+
+message ReservedNames {
+ // Force a nested type called Types
+ message SomeNestedType {
+ }
+
+ int32 types = 1;
+ int32 descriptor = 2;
+}
+
+message TestJsonFieldOrdering {
+ // These fields are deliberately not declared in numeric
+ // order, and the oneof fields aren't contiguous either.
+ // This allows for reasonably robust tests of JSON output
+ // ordering.
+ // TestFieldOrderings in unittest_proto3.proto is similar,
+ // but doesn't include oneofs.
+ // TODO: Consider adding oneofs to TestFieldOrderings, although
+ // that will require fixing other tests in multiple platforms.
+ // Alternatively, consider just adding this to
+ // unittest_proto3.proto if multiple platforms want it.
+
+ int32 plain_int32 = 4;
+
+ oneof o1 {
+ string o1_string = 2;
+ int32 o1_int32 = 5;
+ }
+
+ string plain_string = 1;
+
+ oneof o2 {
+ int32 o2_int32 = 6;
+ string o2_string = 3;
+ }
+
+}
+
+message TestJsonName {
+ // Message for testing the effects for of the json_name option
+ string name = 1;
+ string description = 2 [json_name = "desc"];
+ string guid = 3 [json_name = "exid"];
+}
diff --git a/third_party/protobuf/csharp/src/AddressBook/AddPerson.cs b/third_party/protobuf/csharp/src/AddressBook/AddPerson.cs
new file mode 100644
index 0000000000..62d1788d55
--- /dev/null
+++ b/third_party/protobuf/csharp/src/AddressBook/AddPerson.cs
@@ -0,0 +1,132 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.IO;
+
+namespace Google.Protobuf.Examples.AddressBook
+{
+ internal class AddPerson
+ {
+ /// <summary>
+ /// Builds a person based on user input
+ /// </summary>
+ private static Person PromptForAddress(TextReader input, TextWriter output)
+ {
+ Person person = new Person();
+
+ output.Write("Enter person ID: ");
+ person.Id = int.Parse(input.ReadLine());
+
+ output.Write("Enter name: ");
+ person.Name = input.ReadLine();
+
+ output.Write("Enter email address (blank for none): ");
+ string email = input.ReadLine();
+ if (email.Length > 0)
+ {
+ person.Email = email;
+ }
+
+ while (true)
+ {
+ output.Write("Enter a phone number (or leave blank to finish): ");
+ string number = input.ReadLine();
+ if (number.Length == 0)
+ {
+ break;
+ }
+
+ Person.Types.PhoneNumber phoneNumber = new Person.Types.PhoneNumber { Number = number };
+
+ output.Write("Is this a mobile, home, or work phone? ");
+ String type = input.ReadLine();
+ switch (type)
+ {
+ case "mobile":
+ phoneNumber.Type = Person.Types.PhoneType.Mobile;
+ break;
+ case "home":
+ phoneNumber.Type = Person.Types.PhoneType.Home;
+ break;
+ case "work":
+ phoneNumber.Type = Person.Types.PhoneType.Work;
+ break;
+ default:
+ output.Write("Unknown phone type. Using default.");
+ break;
+ }
+
+ person.Phones.Add(phoneNumber);
+ }
+ return person;
+ }
+
+ /// <summary>
+ /// Entry point - loads an existing addressbook or creates a new one,
+ /// then writes it back to the file.
+ /// </summary>
+ public static int Main(string[] args)
+ {
+ if (args.Length != 1)
+ {
+ Console.Error.WriteLine("Usage: AddPerson ADDRESS_BOOK_FILE");
+ return -1;
+ }
+
+ AddressBook addressBook;
+
+ if (File.Exists(args[0]))
+ {
+ using (Stream file = File.OpenRead(args[0]))
+ {
+ addressBook = AddressBook.Parser.ParseFrom(file);
+ }
+ }
+ else
+ {
+ Console.WriteLine("{0}: File not found. Creating a new file.", args[0]);
+ addressBook = new AddressBook();
+ }
+
+ // Add an address.
+ addressBook.People.Add(PromptForAddress(Console.In, Console.Out));
+
+ // Write the new address book back to disk.
+ using (Stream output = File.OpenWrite(args[0]))
+ {
+ addressBook.WriteTo(output);
+ }
+ return 0;
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/AddressBook/AddressBook.xproj b/third_party/protobuf/csharp/src/AddressBook/AddressBook.xproj
new file mode 100644
index 0000000000..4c9925e83d
--- /dev/null
+++ b/third_party/protobuf/csharp/src/AddressBook/AddressBook.xproj
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>afb63919-1e05-43b4-802a-8fb8c9b2f463</ProjectGuid>
+ <RootNamespace>AddressBook</RootNamespace>
+ <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
+ <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <SchemaVersion>2.0</SchemaVersion>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
+</Project> \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/AddressBook/Addressbook.cs b/third_party/protobuf/csharp/src/AddressBook/Addressbook.cs
new file mode 100644
index 0000000000..75ed071b74
--- /dev/null
+++ b/third_party/protobuf/csharp/src/AddressBook/Addressbook.cs
@@ -0,0 +1,518 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: addressbook.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.Examples.AddressBook {
+
+ /// <summary>Holder for reflection information generated from addressbook.proto</summary>
+ public static partial class AddressbookReflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for addressbook.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static AddressbookReflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "ChFhZGRyZXNzYm9vay5wcm90bxIIdHV0b3JpYWwi1QEKBlBlcnNvbhIMCgRu",
+ "YW1lGAEgASgJEgoKAmlkGAIgASgFEg0KBWVtYWlsGAMgASgJEiwKBnBob25l",
+ "cxgEIAMoCzIcLnR1dG9yaWFsLlBlcnNvbi5QaG9uZU51bWJlchpHCgtQaG9u",
+ "ZU51bWJlchIOCgZudW1iZXIYASABKAkSKAoEdHlwZRgCIAEoDjIaLnR1dG9y",
+ "aWFsLlBlcnNvbi5QaG9uZVR5cGUiKwoJUGhvbmVUeXBlEgoKBk1PQklMRRAA",
+ "EggKBEhPTUUQARIICgRXT1JLEAIiLwoLQWRkcmVzc0Jvb2sSIAoGcGVvcGxl",
+ "GAEgAygLMhAudHV0b3JpYWwuUGVyc29uQlAKFGNvbS5leGFtcGxlLnR1dG9y",
+ "aWFsQhFBZGRyZXNzQm9va1Byb3Rvc6oCJEdvb2dsZS5Qcm90b2J1Zi5FeGFt",
+ "cGxlcy5BZGRyZXNzQm9va2IGcHJvdG8z"));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { },
+ new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Examples.AddressBook.Person), global::Google.Protobuf.Examples.AddressBook.Person.Parser, new[]{ "Name", "Id", "Email", "Phones" }, null, new[]{ typeof(global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType) }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber), global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber.Parser, new[]{ "Number", "Type" }, null, null, null)}),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Examples.AddressBook.AddressBook), global::Google.Protobuf.Examples.AddressBook.AddressBook.Parser, new[]{ "People" }, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Messages
+ /// <summary>
+ /// [START messages]
+ /// </summary>
+ public sealed partial class Person : pb::IMessage<Person> {
+ private static readonly pb::MessageParser<Person> _parser = new pb::MessageParser<Person>(() => new Person());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Person> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Examples.AddressBook.AddressbookReflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Person() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Person(Person other) : this() {
+ name_ = other.name_;
+ id_ = other.id_;
+ email_ = other.email_;
+ phones_ = other.phones_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Person Clone() {
+ return new Person(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "id" field.</summary>
+ public const int IdFieldNumber = 2;
+ private int id_;
+ /// <summary>
+ /// Unique ID number for this person.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Id {
+ get { return id_; }
+ set {
+ id_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "email" field.</summary>
+ public const int EmailFieldNumber = 3;
+ private string email_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Email {
+ get { return email_; }
+ set {
+ email_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "phones" field.</summary>
+ public const int PhonesFieldNumber = 4;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber> _repeated_phones_codec
+ = pb::FieldCodec.ForMessage(34, global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber> phones_ = new pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber> Phones {
+ get { return phones_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Person);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Person other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ if (Id != other.Id) return false;
+ if (Email != other.Email) return false;
+ if(!phones_.Equals(other.phones_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ if (Id != 0) hash ^= Id.GetHashCode();
+ if (Email.Length != 0) hash ^= Email.GetHashCode();
+ hash ^= phones_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ if (Id != 0) {
+ output.WriteRawTag(16);
+ output.WriteInt32(Id);
+ }
+ if (Email.Length != 0) {
+ output.WriteRawTag(26);
+ output.WriteString(Email);
+ }
+ phones_.WriteTo(output, _repeated_phones_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ if (Id != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Id);
+ }
+ if (Email.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Email);
+ }
+ size += phones_.CalculateSize(_repeated_phones_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Person other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ if (other.Id != 0) {
+ Id = other.Id;
+ }
+ if (other.Email.Length != 0) {
+ Email = other.Email;
+ }
+ phones_.Add(other.phones_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 16: {
+ Id = input.ReadInt32();
+ break;
+ }
+ case 26: {
+ Email = input.ReadString();
+ break;
+ }
+ case 34: {
+ phones_.AddEntriesFrom(input, _repeated_phones_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the Person message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ public enum PhoneType {
+ [pbr::OriginalName("MOBILE")] Mobile = 0,
+ [pbr::OriginalName("HOME")] Home = 1,
+ [pbr::OriginalName("WORK")] Work = 2,
+ }
+
+ public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
+ private static readonly pb::MessageParser<PhoneNumber> _parser = new pb::MessageParser<PhoneNumber>(() => new PhoneNumber());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<PhoneNumber> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Examples.AddressBook.Person.Descriptor.NestedTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public PhoneNumber() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public PhoneNumber(PhoneNumber other) : this() {
+ number_ = other.number_;
+ type_ = other.type_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public PhoneNumber Clone() {
+ return new PhoneNumber(this);
+ }
+
+ /// <summary>Field number for the "number" field.</summary>
+ public const int NumberFieldNumber = 1;
+ private string number_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Number {
+ get { return number_; }
+ set {
+ number_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "type" field.</summary>
+ public const int TypeFieldNumber = 2;
+ private global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType type_ = 0;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType Type {
+ get { return type_; }
+ set {
+ type_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as PhoneNumber);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(PhoneNumber other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Number != other.Number) return false;
+ if (Type != other.Type) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Number.Length != 0) hash ^= Number.GetHashCode();
+ if (Type != 0) hash ^= Type.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Number.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Number);
+ }
+ if (Type != 0) {
+ output.WriteRawTag(16);
+ output.WriteEnum((int) Type);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Number.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Number);
+ }
+ if (Type != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Type);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(PhoneNumber other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Number.Length != 0) {
+ Number = other.Number;
+ }
+ if (other.Type != 0) {
+ Type = other.Type;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Number = input.ReadString();
+ break;
+ }
+ case 16: {
+ type_ = (global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType) input.ReadEnum();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ }
+ #endregion
+
+ }
+
+ /// <summary>
+ /// Our address book file is just one of these.
+ /// </summary>
+ public sealed partial class AddressBook : pb::IMessage<AddressBook> {
+ private static readonly pb::MessageParser<AddressBook> _parser = new pb::MessageParser<AddressBook>(() => new AddressBook());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<AddressBook> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Examples.AddressBook.AddressbookReflection.Descriptor.MessageTypes[1]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public AddressBook() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public AddressBook(AddressBook other) : this() {
+ people_ = other.people_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public AddressBook Clone() {
+ return new AddressBook(this);
+ }
+
+ /// <summary>Field number for the "people" field.</summary>
+ public const int PeopleFieldNumber = 1;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Examples.AddressBook.Person> _repeated_people_codec
+ = pb::FieldCodec.ForMessage(10, global::Google.Protobuf.Examples.AddressBook.Person.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person> people_ = new pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person> People {
+ get { return people_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as AddressBook);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(AddressBook other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if(!people_.Equals(other.people_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= people_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ people_.WriteTo(output, _repeated_people_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += people_.CalculateSize(_repeated_people_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(AddressBook other) {
+ if (other == null) {
+ return;
+ }
+ people_.Add(other.people_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ people_.AddEntriesFrom(input, _repeated_people_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/AddressBook/ListPeople.cs b/third_party/protobuf/csharp/src/AddressBook/ListPeople.cs
new file mode 100644
index 0000000000..3758c1bce5
--- /dev/null
+++ b/third_party/protobuf/csharp/src/AddressBook/ListPeople.cs
@@ -0,0 +1,99 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.IO;
+
+namespace Google.Protobuf.Examples.AddressBook
+{
+ internal class ListPeople
+ {
+ /// <summary>
+ /// Iterates though all people in the AddressBook and prints info about them.
+ /// </summary>
+ private static void Print(AddressBook addressBook)
+ {
+ foreach (Person person in addressBook.People)
+ {
+ Console.WriteLine("Person ID: {0}", person.Id);
+ Console.WriteLine(" Name: {0}", person.Name);
+ if (person.Email != "")
+ {
+ Console.WriteLine(" E-mail address: {0}", person.Email);
+ }
+
+ foreach (Person.Types.PhoneNumber phoneNumber in person.Phones)
+ {
+ switch (phoneNumber.Type)
+ {
+ case Person.Types.PhoneType.Mobile:
+ Console.Write(" Mobile phone #: ");
+ break;
+ case Person.Types.PhoneType.Home:
+ Console.Write(" Home phone #: ");
+ break;
+ case Person.Types.PhoneType.Work:
+ Console.Write(" Work phone #: ");
+ break;
+ }
+ Console.WriteLine(phoneNumber.Number);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Entry point - loads the addressbook and then displays it.
+ /// </summary>
+ public static int Main(string[] args)
+ {
+ if (args.Length != 1)
+ {
+ Console.Error.WriteLine("Usage: ListPeople ADDRESS_BOOK_FILE");
+ return 1;
+ }
+
+ if (!File.Exists(args[0]))
+ {
+ Console.WriteLine("{0} doesn't exist. Add a person to create the file first.", args[0]);
+ return 0;
+ }
+
+ // Read the existing address book.
+ using (Stream stream = File.OpenRead(args[0]))
+ {
+ AddressBook addressBook = AddressBook.Parser.ParseFrom(stream);
+ Print(addressBook);
+ }
+ return 0;
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/AddressBook/Program.cs b/third_party/protobuf/csharp/src/AddressBook/Program.cs
new file mode 100644
index 0000000000..ff7b9c085e
--- /dev/null
+++ b/third_party/protobuf/csharp/src/AddressBook/Program.cs
@@ -0,0 +1,95 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+
+namespace Google.Protobuf.Examples.AddressBook
+{
+ /// <summary>
+ /// Entry point. Repeatedly prompts user for an action to take, delegating actual behaviour
+ /// to individual actions. Each action has its own Main method, so that it can be used as an
+ /// invidual complete program.
+ /// </summary>
+ internal class Program
+ {
+ private static int Main(string[] args)
+ {
+ if (args.Length > 1)
+ {
+ Console.Error.WriteLine("Usage: AddressBook [file]");
+ Console.Error.WriteLine("If the filename isn't specified, \"addressbook.data\" is used instead.");
+ return 1;
+ }
+ string addressBookFile = args.Length > 0 ? args[0] : "addressbook.data";
+
+ bool stopping = false;
+ while (!stopping)
+ {
+ Console.WriteLine("Options:");
+ Console.WriteLine(" L: List contents");
+ Console.WriteLine(" A: Add new person");
+ Console.WriteLine(" Q: Quit");
+ Console.Write("Action? ");
+ Console.Out.Flush();
+ char choice = Console.ReadKey().KeyChar;
+ Console.WriteLine();
+ try
+ {
+ switch (choice)
+ {
+ case 'A':
+ case 'a':
+ AddPerson.Main(new string[] {addressBookFile});
+ break;
+ case 'L':
+ case 'l':
+ ListPeople.Main(new string[] {addressBookFile});
+ break;
+ case 'Q':
+ case 'q':
+ stopping = true;
+ break;
+ default:
+ Console.WriteLine("Unknown option: {0}", choice);
+ break;
+ }
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("Exception executing action: {0}", e);
+ }
+ Console.WriteLine();
+ }
+ return 0;
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/AddressBook/SampleUsage.cs b/third_party/protobuf/csharp/src/AddressBook/SampleUsage.cs
new file mode 100644
index 0000000000..941d865aa4
--- /dev/null
+++ b/third_party/protobuf/csharp/src/AddressBook/SampleUsage.cs
@@ -0,0 +1,73 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.IO;
+
+namespace Google.Protobuf.Examples.AddressBook
+{
+ internal class SampleUsage
+ {
+ private static void Main()
+ {
+ byte[] bytes;
+ // Create a new person
+ Person person = new Person
+ {
+ Id = 1,
+ Name = "Foo",
+ Email = "foo@bar",
+ Phones = { new Person.Types.PhoneNumber { Number = "555-1212" } }
+ };
+ using (MemoryStream stream = new MemoryStream())
+ {
+ // Save the person to a stream
+ person.WriteTo(stream);
+ bytes = stream.ToArray();
+ }
+ Person copy = Person.Parser.ParseFrom(bytes);
+
+ AddressBook book = new AddressBook
+ {
+ People = { copy }
+ };
+ bytes = book.ToByteArray();
+ // And read the address book back again
+ AddressBook restored = AddressBook.Parser.ParseFrom(bytes);
+ // The message performs a deep-comparison on equality:
+ if (restored.People.Count != 1 || !person.Equals(restored.People[0]))
+ {
+ throw new Exception("There is a bad person in here!");
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/AddressBook/project.json b/third_party/protobuf/csharp/src/AddressBook/project.json
new file mode 100644
index 0000000000..c500bdc296
--- /dev/null
+++ b/third_party/protobuf/csharp/src/AddressBook/project.json
@@ -0,0 +1,20 @@
+{
+ "buildOptions": {
+ "debugType": "portable",
+ "emitEntryPoint": true,
+ "additionalArguments": [ "/main:Google.Protobuf.Examples.AddressBook.Program" ]
+ },
+ "dependencies": {
+ "Google.Protobuf": { "target": "project" }
+ },
+ "frameworks": {
+ "netcoreapp1.0": {
+ "dependencies": {
+ "Microsoft.NETCore.App": {
+ "type": "platform",
+ "version": "1.0.0"
+ }
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Conformance/Conformance.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Conformance/Conformance.cs
new file mode 100644
index 0000000000..1a835aef02
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Conformance/Conformance.cs
@@ -0,0 +1,606 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: conformance.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Conformance {
+
+ /// <summary>Holder for reflection information generated from conformance.proto</summary>
+ public static partial class ConformanceReflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for conformance.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static ConformanceReflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "ChFjb25mb3JtYW5jZS5wcm90bxILY29uZm9ybWFuY2UijQEKEkNvbmZvcm1h",
+ "bmNlUmVxdWVzdBIaChBwcm90b2J1Zl9wYXlsb2FkGAEgASgMSAASFgoManNv",
+ "bl9wYXlsb2FkGAIgASgJSAASOAoXcmVxdWVzdGVkX291dHB1dF9mb3JtYXQY",
+ "AyABKA4yFy5jb25mb3JtYW5jZS5XaXJlRm9ybWF0QgkKB3BheWxvYWQisQEK",
+ "E0NvbmZvcm1hbmNlUmVzcG9uc2USFQoLcGFyc2VfZXJyb3IYASABKAlIABIZ",
+ "Cg9zZXJpYWxpemVfZXJyb3IYBiABKAlIABIXCg1ydW50aW1lX2Vycm9yGAIg",
+ "ASgJSAASGgoQcHJvdG9idWZfcGF5bG9hZBgDIAEoDEgAEhYKDGpzb25fcGF5",
+ "bG9hZBgEIAEoCUgAEhEKB3NraXBwZWQYBSABKAlIAEIICgZyZXN1bHQqNQoK",
+ "V2lyZUZvcm1hdBIPCgtVTlNQRUNJRklFRBAAEgwKCFBST1RPQlVGEAESCAoE",
+ "SlNPThACQiEKH2NvbS5nb29nbGUucHJvdG9idWYuY29uZm9ybWFuY2ViBnBy",
+ "b3RvMw=="));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { },
+ new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Conformance.WireFormat), }, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceRequest), global::Conformance.ConformanceRequest.Parser, new[]{ "ProtobufPayload", "JsonPayload", "RequestedOutputFormat" }, new[]{ "Payload" }, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceResponse), global::Conformance.ConformanceResponse.Parser, new[]{ "ParseError", "SerializeError", "RuntimeError", "ProtobufPayload", "JsonPayload", "Skipped" }, new[]{ "Result" }, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Enums
+ public enum WireFormat {
+ [pbr::OriginalName("UNSPECIFIED")] Unspecified = 0,
+ [pbr::OriginalName("PROTOBUF")] Protobuf = 1,
+ [pbr::OriginalName("JSON")] Json = 2,
+ }
+
+ #endregion
+
+ #region Messages
+ /// <summary>
+ /// Represents a single test case's input. The testee should:
+ ///
+ /// 1. parse this proto (which should always succeed)
+ /// 2. parse the protobuf or JSON payload in "payload" (which may fail)
+ /// 3. if the parse succeeded, serialize the message in the requested format.
+ /// </summary>
+ public sealed partial class ConformanceRequest : pb::IMessage<ConformanceRequest> {
+ private static readonly pb::MessageParser<ConformanceRequest> _parser = new pb::MessageParser<ConformanceRequest>(() => new ConformanceRequest());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<ConformanceRequest> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Conformance.ConformanceReflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ConformanceRequest() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ConformanceRequest(ConformanceRequest other) : this() {
+ requestedOutputFormat_ = other.requestedOutputFormat_;
+ switch (other.PayloadCase) {
+ case PayloadOneofCase.ProtobufPayload:
+ ProtobufPayload = other.ProtobufPayload;
+ break;
+ case PayloadOneofCase.JsonPayload:
+ JsonPayload = other.JsonPayload;
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ConformanceRequest Clone() {
+ return new ConformanceRequest(this);
+ }
+
+ /// <summary>Field number for the "protobuf_payload" field.</summary>
+ public const int ProtobufPayloadFieldNumber = 1;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pb::ByteString ProtobufPayload {
+ get { return payloadCase_ == PayloadOneofCase.ProtobufPayload ? (pb::ByteString) payload_ : pb::ByteString.Empty; }
+ set {
+ payload_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ payloadCase_ = PayloadOneofCase.ProtobufPayload;
+ }
+ }
+
+ /// <summary>Field number for the "json_payload" field.</summary>
+ public const int JsonPayloadFieldNumber = 2;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string JsonPayload {
+ get { return payloadCase_ == PayloadOneofCase.JsonPayload ? (string) payload_ : ""; }
+ set {
+ payload_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ payloadCase_ = PayloadOneofCase.JsonPayload;
+ }
+ }
+
+ /// <summary>Field number for the "requested_output_format" field.</summary>
+ public const int RequestedOutputFormatFieldNumber = 3;
+ private global::Conformance.WireFormat requestedOutputFormat_ = 0;
+ /// <summary>
+ /// Which format should the testee serialize its message to?
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Conformance.WireFormat RequestedOutputFormat {
+ get { return requestedOutputFormat_; }
+ set {
+ requestedOutputFormat_ = value;
+ }
+ }
+
+ private object payload_;
+ /// <summary>Enum of possible cases for the "payload" oneof.</summary>
+ public enum PayloadOneofCase {
+ None = 0,
+ ProtobufPayload = 1,
+ JsonPayload = 2,
+ }
+ private PayloadOneofCase payloadCase_ = PayloadOneofCase.None;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public PayloadOneofCase PayloadCase {
+ get { return payloadCase_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearPayload() {
+ payloadCase_ = PayloadOneofCase.None;
+ payload_ = null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as ConformanceRequest);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(ConformanceRequest other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (ProtobufPayload != other.ProtobufPayload) return false;
+ if (JsonPayload != other.JsonPayload) return false;
+ if (RequestedOutputFormat != other.RequestedOutputFormat) return false;
+ if (PayloadCase != other.PayloadCase) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (payloadCase_ == PayloadOneofCase.ProtobufPayload) hash ^= ProtobufPayload.GetHashCode();
+ if (payloadCase_ == PayloadOneofCase.JsonPayload) hash ^= JsonPayload.GetHashCode();
+ if (RequestedOutputFormat != 0) hash ^= RequestedOutputFormat.GetHashCode();
+ hash ^= (int) payloadCase_;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (payloadCase_ == PayloadOneofCase.ProtobufPayload) {
+ output.WriteRawTag(10);
+ output.WriteBytes(ProtobufPayload);
+ }
+ if (payloadCase_ == PayloadOneofCase.JsonPayload) {
+ output.WriteRawTag(18);
+ output.WriteString(JsonPayload);
+ }
+ if (RequestedOutputFormat != 0) {
+ output.WriteRawTag(24);
+ output.WriteEnum((int) RequestedOutputFormat);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (payloadCase_ == PayloadOneofCase.ProtobufPayload) {
+ size += 1 + pb::CodedOutputStream.ComputeBytesSize(ProtobufPayload);
+ }
+ if (payloadCase_ == PayloadOneofCase.JsonPayload) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(JsonPayload);
+ }
+ if (RequestedOutputFormat != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) RequestedOutputFormat);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(ConformanceRequest other) {
+ if (other == null) {
+ return;
+ }
+ if (other.RequestedOutputFormat != 0) {
+ RequestedOutputFormat = other.RequestedOutputFormat;
+ }
+ switch (other.PayloadCase) {
+ case PayloadOneofCase.ProtobufPayload:
+ ProtobufPayload = other.ProtobufPayload;
+ break;
+ case PayloadOneofCase.JsonPayload:
+ JsonPayload = other.JsonPayload;
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ ProtobufPayload = input.ReadBytes();
+ break;
+ }
+ case 18: {
+ JsonPayload = input.ReadString();
+ break;
+ }
+ case 24: {
+ requestedOutputFormat_ = (global::Conformance.WireFormat) input.ReadEnum();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Represents a single test case's output.
+ /// </summary>
+ public sealed partial class ConformanceResponse : pb::IMessage<ConformanceResponse> {
+ private static readonly pb::MessageParser<ConformanceResponse> _parser = new pb::MessageParser<ConformanceResponse>(() => new ConformanceResponse());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<ConformanceResponse> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Conformance.ConformanceReflection.Descriptor.MessageTypes[1]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ConformanceResponse() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ConformanceResponse(ConformanceResponse other) : this() {
+ switch (other.ResultCase) {
+ case ResultOneofCase.ParseError:
+ ParseError = other.ParseError;
+ break;
+ case ResultOneofCase.SerializeError:
+ SerializeError = other.SerializeError;
+ break;
+ case ResultOneofCase.RuntimeError:
+ RuntimeError = other.RuntimeError;
+ break;
+ case ResultOneofCase.ProtobufPayload:
+ ProtobufPayload = other.ProtobufPayload;
+ break;
+ case ResultOneofCase.JsonPayload:
+ JsonPayload = other.JsonPayload;
+ break;
+ case ResultOneofCase.Skipped:
+ Skipped = other.Skipped;
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ConformanceResponse Clone() {
+ return new ConformanceResponse(this);
+ }
+
+ /// <summary>Field number for the "parse_error" field.</summary>
+ public const int ParseErrorFieldNumber = 1;
+ /// <summary>
+ /// This string should be set to indicate parsing failed. The string can
+ /// provide more information about the parse error if it is available.
+ ///
+ /// Setting this string does not necessarily mean the testee failed the
+ /// test. Some of the test cases are intentionally invalid input.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string ParseError {
+ get { return resultCase_ == ResultOneofCase.ParseError ? (string) result_ : ""; }
+ set {
+ result_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ resultCase_ = ResultOneofCase.ParseError;
+ }
+ }
+
+ /// <summary>Field number for the "serialize_error" field.</summary>
+ public const int SerializeErrorFieldNumber = 6;
+ /// <summary>
+ /// If the input was successfully parsed but errors occurred when
+ /// serializing it to the requested output format, set the error message in
+ /// this field.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string SerializeError {
+ get { return resultCase_ == ResultOneofCase.SerializeError ? (string) result_ : ""; }
+ set {
+ result_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ resultCase_ = ResultOneofCase.SerializeError;
+ }
+ }
+
+ /// <summary>Field number for the "runtime_error" field.</summary>
+ public const int RuntimeErrorFieldNumber = 2;
+ /// <summary>
+ /// This should be set if some other error occurred. This will always
+ /// indicate that the test failed. The string can provide more information
+ /// about the failure.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string RuntimeError {
+ get { return resultCase_ == ResultOneofCase.RuntimeError ? (string) result_ : ""; }
+ set {
+ result_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ resultCase_ = ResultOneofCase.RuntimeError;
+ }
+ }
+
+ /// <summary>Field number for the "protobuf_payload" field.</summary>
+ public const int ProtobufPayloadFieldNumber = 3;
+ /// <summary>
+ /// If the input was successfully parsed and the requested output was
+ /// protobuf, serialize it to protobuf and set it in this field.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pb::ByteString ProtobufPayload {
+ get { return resultCase_ == ResultOneofCase.ProtobufPayload ? (pb::ByteString) result_ : pb::ByteString.Empty; }
+ set {
+ result_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ resultCase_ = ResultOneofCase.ProtobufPayload;
+ }
+ }
+
+ /// <summary>Field number for the "json_payload" field.</summary>
+ public const int JsonPayloadFieldNumber = 4;
+ /// <summary>
+ /// If the input was successfully parsed and the requested output was JSON,
+ /// serialize to JSON and set it in this field.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string JsonPayload {
+ get { return resultCase_ == ResultOneofCase.JsonPayload ? (string) result_ : ""; }
+ set {
+ result_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ resultCase_ = ResultOneofCase.JsonPayload;
+ }
+ }
+
+ /// <summary>Field number for the "skipped" field.</summary>
+ public const int SkippedFieldNumber = 5;
+ /// <summary>
+ /// For when the testee skipped the test, likely because a certain feature
+ /// wasn't supported, like JSON input/output.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Skipped {
+ get { return resultCase_ == ResultOneofCase.Skipped ? (string) result_ : ""; }
+ set {
+ result_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ resultCase_ = ResultOneofCase.Skipped;
+ }
+ }
+
+ private object result_;
+ /// <summary>Enum of possible cases for the "result" oneof.</summary>
+ public enum ResultOneofCase {
+ None = 0,
+ ParseError = 1,
+ SerializeError = 6,
+ RuntimeError = 2,
+ ProtobufPayload = 3,
+ JsonPayload = 4,
+ Skipped = 5,
+ }
+ private ResultOneofCase resultCase_ = ResultOneofCase.None;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ResultOneofCase ResultCase {
+ get { return resultCase_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearResult() {
+ resultCase_ = ResultOneofCase.None;
+ result_ = null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as ConformanceResponse);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(ConformanceResponse other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (ParseError != other.ParseError) return false;
+ if (SerializeError != other.SerializeError) return false;
+ if (RuntimeError != other.RuntimeError) return false;
+ if (ProtobufPayload != other.ProtobufPayload) return false;
+ if (JsonPayload != other.JsonPayload) return false;
+ if (Skipped != other.Skipped) return false;
+ if (ResultCase != other.ResultCase) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (resultCase_ == ResultOneofCase.ParseError) hash ^= ParseError.GetHashCode();
+ if (resultCase_ == ResultOneofCase.SerializeError) hash ^= SerializeError.GetHashCode();
+ if (resultCase_ == ResultOneofCase.RuntimeError) hash ^= RuntimeError.GetHashCode();
+ if (resultCase_ == ResultOneofCase.ProtobufPayload) hash ^= ProtobufPayload.GetHashCode();
+ if (resultCase_ == ResultOneofCase.JsonPayload) hash ^= JsonPayload.GetHashCode();
+ if (resultCase_ == ResultOneofCase.Skipped) hash ^= Skipped.GetHashCode();
+ hash ^= (int) resultCase_;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (resultCase_ == ResultOneofCase.ParseError) {
+ output.WriteRawTag(10);
+ output.WriteString(ParseError);
+ }
+ if (resultCase_ == ResultOneofCase.RuntimeError) {
+ output.WriteRawTag(18);
+ output.WriteString(RuntimeError);
+ }
+ if (resultCase_ == ResultOneofCase.ProtobufPayload) {
+ output.WriteRawTag(26);
+ output.WriteBytes(ProtobufPayload);
+ }
+ if (resultCase_ == ResultOneofCase.JsonPayload) {
+ output.WriteRawTag(34);
+ output.WriteString(JsonPayload);
+ }
+ if (resultCase_ == ResultOneofCase.Skipped) {
+ output.WriteRawTag(42);
+ output.WriteString(Skipped);
+ }
+ if (resultCase_ == ResultOneofCase.SerializeError) {
+ output.WriteRawTag(50);
+ output.WriteString(SerializeError);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (resultCase_ == ResultOneofCase.ParseError) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(ParseError);
+ }
+ if (resultCase_ == ResultOneofCase.SerializeError) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(SerializeError);
+ }
+ if (resultCase_ == ResultOneofCase.RuntimeError) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(RuntimeError);
+ }
+ if (resultCase_ == ResultOneofCase.ProtobufPayload) {
+ size += 1 + pb::CodedOutputStream.ComputeBytesSize(ProtobufPayload);
+ }
+ if (resultCase_ == ResultOneofCase.JsonPayload) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(JsonPayload);
+ }
+ if (resultCase_ == ResultOneofCase.Skipped) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Skipped);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(ConformanceResponse other) {
+ if (other == null) {
+ return;
+ }
+ switch (other.ResultCase) {
+ case ResultOneofCase.ParseError:
+ ParseError = other.ParseError;
+ break;
+ case ResultOneofCase.SerializeError:
+ SerializeError = other.SerializeError;
+ break;
+ case ResultOneofCase.RuntimeError:
+ RuntimeError = other.RuntimeError;
+ break;
+ case ResultOneofCase.ProtobufPayload:
+ ProtobufPayload = other.ProtobufPayload;
+ break;
+ case ResultOneofCase.JsonPayload:
+ JsonPayload = other.JsonPayload;
+ break;
+ case ResultOneofCase.Skipped:
+ Skipped = other.Skipped;
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ ParseError = input.ReadString();
+ break;
+ }
+ case 18: {
+ RuntimeError = input.ReadString();
+ break;
+ }
+ case 26: {
+ ProtobufPayload = input.ReadBytes();
+ break;
+ }
+ case 34: {
+ JsonPayload = input.ReadString();
+ break;
+ }
+ case 42: {
+ Skipped = input.ReadString();
+ break;
+ }
+ case 50: {
+ SerializeError = input.ReadString();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.xproj b/third_party/protobuf/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.xproj
new file mode 100644
index 0000000000..99ff146538
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.xproj
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>dddc055b-e185-4181-bab0-072f0f984569</ProjectGuid>
+ <RootNamespace>Google.Protobuf.Conformance</RootNamespace>
+ <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
+ <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <SchemaVersion>2.0</SchemaVersion>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
+</Project> \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Conformance/Program.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Conformance/Program.cs
new file mode 100644
index 0000000000..00ee64f8a5
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Conformance/Program.cs
@@ -0,0 +1,142 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using Conformance;
+using Google.Protobuf.Reflection;
+using System;
+using System.IO;
+
+namespace Google.Protobuf.Conformance
+{
+ /// <summary>
+ /// Conformance tests. The test runner will provide JSON or proto data on stdin,
+ /// and this program will produce its output on stdout.
+ /// </summary>
+ class Program
+ {
+ private static void Main(string[] args)
+ {
+ // This way we get the binary streams instead of readers/writers.
+ var input = new BinaryReader(Console.OpenStandardInput());
+ var output = new BinaryWriter(Console.OpenStandardOutput());
+ var typeRegistry = TypeRegistry.FromMessages(ProtobufTestMessages.Proto3.TestAllTypes.Descriptor);
+
+ int count = 0;
+ while (RunTest(input, output, typeRegistry))
+ {
+ count++;
+ }
+ Console.Error.WriteLine("Received EOF after {0} tests", count);
+ }
+
+ private static bool RunTest(BinaryReader input, BinaryWriter output, TypeRegistry typeRegistry)
+ {
+ int? size = ReadInt32(input);
+ if (size == null)
+ {
+ return false;
+ }
+ byte[] inputData = input.ReadBytes(size.Value);
+ if (inputData.Length != size.Value)
+ {
+ throw new EndOfStreamException("Read " + inputData.Length + " bytes of data when expecting " + size);
+ }
+ ConformanceRequest request = ConformanceRequest.Parser.ParseFrom(inputData);
+ ConformanceResponse response = PerformRequest(request, typeRegistry);
+ byte[] outputData = response.ToByteArray();
+ output.Write(outputData.Length);
+ output.Write(outputData);
+ // Ready for another test...
+ return true;
+ }
+
+ private static ConformanceResponse PerformRequest(ConformanceRequest request, TypeRegistry typeRegistry)
+ {
+ ProtobufTestMessages.Proto3.TestAllTypes message;
+ try
+ {
+ switch (request.PayloadCase)
+ {
+ case ConformanceRequest.PayloadOneofCase.JsonPayload:
+ var parser = new JsonParser(new JsonParser.Settings(20, typeRegistry));
+ message = parser.Parse<ProtobufTestMessages.Proto3.TestAllTypes>(request.JsonPayload);
+ break;
+ case ConformanceRequest.PayloadOneofCase.ProtobufPayload:
+ message = ProtobufTestMessages.Proto3.TestAllTypes.Parser.ParseFrom(request.ProtobufPayload);
+ break;
+ default:
+ throw new Exception("Unsupported request payload: " + request.PayloadCase);
+ }
+ }
+ catch (InvalidProtocolBufferException e)
+ {
+ return new ConformanceResponse { ParseError = e.Message };
+ }
+ catch (InvalidJsonException e)
+ {
+ return new ConformanceResponse { ParseError = e.Message };
+ }
+ try
+ {
+ switch (request.RequestedOutputFormat)
+ {
+ case global::Conformance.WireFormat.Json:
+ var formatter = new JsonFormatter(new JsonFormatter.Settings(false, typeRegistry));
+ return new ConformanceResponse { JsonPayload = formatter.Format(message) };
+ case global::Conformance.WireFormat.Protobuf:
+ return new ConformanceResponse { ProtobufPayload = message.ToByteString() };
+ default:
+ throw new Exception("Unsupported request output format: " + request.PayloadCase);
+ }
+ }
+ catch (InvalidOperationException e)
+ {
+ return new ConformanceResponse { SerializeError = e.Message };
+ }
+ }
+
+ private static int? ReadInt32(BinaryReader input)
+ {
+ byte[] bytes = input.ReadBytes(4);
+ if (bytes.Length == 0)
+ {
+ // Cleanly reached the end of the stream
+ return null;
+ }
+ if (bytes.Length != 4)
+ {
+ throw new EndOfStreamException("Read " + bytes.Length + " bytes of size when expecting 4");
+ }
+ return bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Conformance/project.json b/third_party/protobuf/csharp/src/Google.Protobuf.Conformance/project.json
new file mode 100644
index 0000000000..4cf0523135
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Conformance/project.json
@@ -0,0 +1,21 @@
+{
+ "buildOptions": {
+ "debugType": "portable",
+ "emitEntryPoint": true
+ },
+ "dependencies": {
+ "Google.Protobuf": { "target": "project" },
+ "Google.Protobuf.Test": { "target": "project" }
+ },
+ "frameworks": {
+ "netcoreapp1.0": {
+ "imports": [ "dnxcore50", "netcoreapp1.0", "portable-net45+win8" ],
+ "dependencies": {
+ "Microsoft.NETCore.App": {
+ "type": "platform",
+ "version": "1.0.0"
+ }
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.xproj b/third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.xproj
new file mode 100644
index 0000000000..27095be5b3
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.xproj
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>9695e08f-9829-497d-b95c-b38f28d48690</ProjectGuid>
+ <RootNamespace>Google.Protobuf.JsonDump</RootNamespace>
+ <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
+ <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <SchemaVersion>2.0</SchemaVersion>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
+</Project> \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/Program.cs b/third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/Program.cs
new file mode 100644
index 0000000000..296b2f3f1e
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/Program.cs
@@ -0,0 +1,73 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.IO;
+using System.Reflection;
+
+namespace Google.Protobuf.ProtoDump
+{
+ /// <summary>
+ /// Small utility to load a binary message and dump it in JSON format.
+ /// </summary>
+ internal class Program
+ {
+ private static int Main(string[] args)
+ {
+ if (args.Length != 2)
+ {
+ Console.Error.WriteLine("Usage: Google.Protobuf.JsonDump <descriptor type name> <input data>");
+ Console.Error.WriteLine("The descriptor type name is the fully-qualified message name,");
+ Console.Error.WriteLine("including assembly e.g. ProjectNamespace.Message,Company.Project");
+ return 1;
+ }
+ Type type = Type.GetType(args[0]);
+ if (type == null)
+ {
+ Console.Error.WriteLine("Unable to load type {0}.", args[0]);
+ return 1;
+ }
+ if (!typeof(IMessage).GetTypeInfo().IsAssignableFrom(type))
+ {
+ Console.Error.WriteLine("Type {0} doesn't implement IMessage.", args[0]);
+ return 1;
+ }
+ IMessage message = (IMessage) Activator.CreateInstance(type);
+ using (var input = File.OpenRead(args[1]))
+ {
+ message.MergeFrom(input);
+ }
+ Console.WriteLine(message);
+ return 0;
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/project.json b/third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/project.json
new file mode 100644
index 0000000000..84b23c456d
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.JsonDump/project.json
@@ -0,0 +1,19 @@
+{
+ "buildOptions": {
+ "debugType": "portable",
+ "emitEntryPoint": true
+ },
+ "dependencies": {
+ "Google.Protobuf": { "target": "project" }
+ },
+ "frameworks": {
+ "netcoreapp1.0": {
+ "dependencies": {
+ "Microsoft.NETCore.App": {
+ "type": "platform",
+ "version": "1.0.0"
+ }
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/ByteStringTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/ByteStringTest.cs
new file mode 100755
index 0000000000..afdd491f36
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/ByteStringTest.cs
@@ -0,0 +1,237 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.Text;
+using NUnit.Framework;
+using System.IO;
+#if !NET35
+using System.Threading.Tasks;
+#endif
+
+namespace Google.Protobuf
+{
+ public class ByteStringTest
+ {
+ [Test]
+ public void Equality()
+ {
+ ByteString b1 = ByteString.CopyFrom(1, 2, 3);
+ ByteString b2 = ByteString.CopyFrom(1, 2, 3);
+ ByteString b3 = ByteString.CopyFrom(1, 2, 4);
+ ByteString b4 = ByteString.CopyFrom(1, 2, 3, 4);
+ EqualityTester.AssertEquality(b1, b1);
+ EqualityTester.AssertEquality(b1, b2);
+ EqualityTester.AssertInequality(b1, b3);
+ EqualityTester.AssertInequality(b1, b4);
+ EqualityTester.AssertInequality(b1, null);
+#pragma warning disable 1718 // Deliberately calling ==(b1, b1) and !=(b1, b1)
+ Assert.IsTrue(b1 == b1);
+ Assert.IsTrue(b1 == b2);
+ Assert.IsFalse(b1 == b3);
+ Assert.IsFalse(b1 == b4);
+ Assert.IsFalse(b1 == null);
+ Assert.IsTrue((ByteString) null == null);
+ Assert.IsFalse(b1 != b1);
+ Assert.IsFalse(b1 != b2);
+#pragma warning disable 1718
+ Assert.IsTrue(b1 != b3);
+ Assert.IsTrue(b1 != b4);
+ Assert.IsTrue(b1 != null);
+ Assert.IsFalse((ByteString) null != null);
+ }
+
+ [Test]
+ public void EmptyByteStringHasZeroSize()
+ {
+ Assert.AreEqual(0, ByteString.Empty.Length);
+ }
+
+ [Test]
+ public void CopyFromStringWithExplicitEncoding()
+ {
+ ByteString bs = ByteString.CopyFrom("AB", Encoding.Unicode);
+ Assert.AreEqual(4, bs.Length);
+ Assert.AreEqual(65, bs[0]);
+ Assert.AreEqual(0, bs[1]);
+ Assert.AreEqual(66, bs[2]);
+ Assert.AreEqual(0, bs[3]);
+ }
+
+ [Test]
+ public void IsEmptyWhenEmpty()
+ {
+ Assert.IsTrue(ByteString.CopyFromUtf8("").IsEmpty);
+ }
+
+ [Test]
+ public void IsEmptyWhenNotEmpty()
+ {
+ Assert.IsFalse(ByteString.CopyFromUtf8("X").IsEmpty);
+ }
+
+ [Test]
+ public void CopyFromByteArrayCopiesContents()
+ {
+ byte[] data = new byte[1];
+ data[0] = 10;
+ ByteString bs = ByteString.CopyFrom(data);
+ Assert.AreEqual(10, bs[0]);
+ data[0] = 5;
+ Assert.AreEqual(10, bs[0]);
+ }
+
+ [Test]
+ public void ToByteArrayCopiesContents()
+ {
+ ByteString bs = ByteString.CopyFromUtf8("Hello");
+ byte[] data = bs.ToByteArray();
+ Assert.AreEqual((byte)'H', data[0]);
+ Assert.AreEqual((byte)'H', bs[0]);
+ data[0] = 0;
+ Assert.AreEqual(0, data[0]);
+ Assert.AreEqual((byte)'H', bs[0]);
+ }
+
+ [Test]
+ public void CopyFromUtf8UsesUtf8()
+ {
+ ByteString bs = ByteString.CopyFromUtf8("\u20ac");
+ Assert.AreEqual(3, bs.Length);
+ Assert.AreEqual(0xe2, bs[0]);
+ Assert.AreEqual(0x82, bs[1]);
+ Assert.AreEqual(0xac, bs[2]);
+ }
+
+ [Test]
+ public void CopyFromPortion()
+ {
+ byte[] data = new byte[] {0, 1, 2, 3, 4, 5, 6};
+ ByteString bs = ByteString.CopyFrom(data, 2, 3);
+ Assert.AreEqual(3, bs.Length);
+ Assert.AreEqual(2, bs[0]);
+ Assert.AreEqual(3, bs[1]);
+ }
+
+ [Test]
+ public void ToStringUtf8()
+ {
+ ByteString bs = ByteString.CopyFromUtf8("\u20ac");
+ Assert.AreEqual("\u20ac", bs.ToStringUtf8());
+ }
+
+ [Test]
+ public void ToStringWithExplicitEncoding()
+ {
+ ByteString bs = ByteString.CopyFrom("\u20ac", Encoding.Unicode);
+ Assert.AreEqual("\u20ac", bs.ToString(Encoding.Unicode));
+ }
+
+ [Test]
+ public void FromBase64_WithText()
+ {
+ byte[] data = new byte[] {0, 1, 2, 3, 4, 5, 6};
+ string base64 = Convert.ToBase64String(data);
+ ByteString bs = ByteString.FromBase64(base64);
+ Assert.AreEqual(data, bs.ToByteArray());
+ }
+
+ [Test]
+ public void FromBase64_Empty()
+ {
+ // Optimization which also fixes issue 61.
+ Assert.AreSame(ByteString.Empty, ByteString.FromBase64(""));
+ }
+
+ [Test]
+ public void FromStream_Seekable()
+ {
+ var stream = new MemoryStream(new byte[] { 1, 2, 3, 4, 5 });
+ // Consume the first byte, just to test that it's "from current position"
+ stream.ReadByte();
+ var actual = ByteString.FromStream(stream);
+ ByteString expected = ByteString.CopyFrom(2, 3, 4, 5);
+ Assert.AreEqual(expected, actual, $"{expected.ToBase64()} != {actual.ToBase64()}");
+ }
+
+ [Test]
+ public void FromStream_NotSeekable()
+ {
+ var stream = new MemoryStream(new byte[] { 1, 2, 3, 4, 5 });
+ // Consume the first byte, just to test that it's "from current position"
+ stream.ReadByte();
+ // Wrap the original stream in LimitedInputStream, which has CanSeek=false
+ var limitedStream = new LimitedInputStream(stream, 3);
+ var actual = ByteString.FromStream(limitedStream);
+ ByteString expected = ByteString.CopyFrom(2, 3, 4);
+ Assert.AreEqual(expected, actual, $"{expected.ToBase64()} != {actual.ToBase64()}");
+ }
+
+#if !NET35
+ [Test]
+ public async Task FromStreamAsync_Seekable()
+ {
+ var stream = new MemoryStream(new byte[] { 1, 2, 3, 4, 5 });
+ // Consume the first byte, just to test that it's "from current position"
+ stream.ReadByte();
+ var actual = await ByteString.FromStreamAsync(stream);
+ ByteString expected = ByteString.CopyFrom(2, 3, 4, 5);
+ Assert.AreEqual(expected, actual, $"{expected.ToBase64()} != {actual.ToBase64()}");
+ }
+
+ [Test]
+ public async Task FromStreamAsync_NotSeekable()
+ {
+ var stream = new MemoryStream(new byte[] { 1, 2, 3, 4, 5 });
+ // Consume the first byte, just to test that it's "from current position"
+ stream.ReadByte();
+ // Wrap the original stream in LimitedInputStream, which has CanSeek=false
+ var limitedStream = new LimitedInputStream(stream, 3);
+ var actual = await ByteString.FromStreamAsync(limitedStream);
+ ByteString expected = ByteString.CopyFrom(2, 3, 4);
+ Assert.AreEqual(expected, actual, $"{expected.ToBase64()} != {actual.ToBase64()}");
+ }
+#endif
+
+ [Test]
+ public void GetHashCode_Regression()
+ {
+ // We used to have an awful hash algorithm where only the last four
+ // bytes were relevant. This is a regression test for
+ // https://github.com/google/protobuf/issues/2511
+
+ ByteString b1 = ByteString.CopyFrom(100, 1, 2, 3, 4);
+ ByteString b2 = ByteString.CopyFrom(200, 1, 2, 3, 4);
+ Assert.AreNotEqual(b1.GetHashCode(), b2.GetHashCode());
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/CodedInputStreamExtensions.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/CodedInputStreamExtensions.cs
new file mode 100644
index 0000000000..23af28870a
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/CodedInputStreamExtensions.cs
@@ -0,0 +1,53 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using NUnit.Framework;
+
+namespace Google.Protobuf
+{
+ internal static class CodedInputStreamExtensions
+ {
+ public static void AssertNextTag(this CodedInputStream input, uint expectedTag)
+ {
+ uint tag = input.ReadTag();
+ Assert.AreEqual(expectedTag, tag);
+ }
+
+ public static T ReadMessage<T>(this CodedInputStream stream, MessageParser<T> parser)
+ where T : IMessage<T>
+ {
+ var message = parser.CreateTemplate();
+ stream.ReadMessage(message);
+ return message;
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs
new file mode 100644
index 0000000000..c0a9ffd124
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs
@@ -0,0 +1,598 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.IO;
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+
+namespace Google.Protobuf
+{
+ public class CodedInputStreamTest
+ {
+ /// <summary>
+ /// 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.
+ /// </summary>
+ private static byte[] Bytes(params int[] bytesAsInts)
+ {
+ byte[] bytes = new byte[bytesAsInts.Length];
+ for (int i = 0; i < bytesAsInts.Length; i++)
+ {
+ bytes[i] = (byte) bytesAsInts[i];
+ }
+ return bytes;
+ }
+
+ /// <summary>
+ /// Parses the given bytes using ReadRawVarint32() and ReadRawVarint64()
+ /// </summary>
+ private static void AssertReadVarint(byte[] data, ulong value)
+ {
+ CodedInputStream input = new CodedInputStream(data);
+ Assert.AreEqual((uint) value, input.ReadRawVarint32());
+
+ input = new CodedInputStream(data);
+ Assert.AreEqual(value, input.ReadRawVarint64());
+ Assert.IsTrue(input.IsAtEnd);
+
+ // Try different block sizes.
+ for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2)
+ {
+ input = new CodedInputStream(new SmallBlockInputStream(data, bufferSize));
+ Assert.AreEqual((uint) value, input.ReadRawVarint32());
+
+ input = new CodedInputStream(new SmallBlockInputStream(data, bufferSize));
+ Assert.AreEqual(value, input.ReadRawVarint64());
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ // Try reading directly from a MemoryStream. We want to verify that it
+ // doesn't read past the end of the input, so write an extra byte - this
+ // lets us test the position at the end.
+ MemoryStream memoryStream = new MemoryStream();
+ memoryStream.Write(data, 0, data.Length);
+ memoryStream.WriteByte(0);
+ memoryStream.Position = 0;
+ Assert.AreEqual((uint) value, CodedInputStream.ReadRawVarint32(memoryStream));
+ Assert.AreEqual(data.Length, memoryStream.Position);
+ }
+
+ /// <summary>
+ /// Parses the given bytes using ReadRawVarint32() and ReadRawVarint64() and
+ /// expects them to fail with an InvalidProtocolBufferException whose
+ /// description matches the given one.
+ /// </summary>
+ private static void AssertReadVarintFailure(InvalidProtocolBufferException expected, byte[] data)
+ {
+ CodedInputStream input = new CodedInputStream(data);
+ var exception = Assert.Throws<InvalidProtocolBufferException>(() => input.ReadRawVarint32());
+ Assert.AreEqual(expected.Message, exception.Message);
+
+ input = new CodedInputStream(data);
+ exception = Assert.Throws<InvalidProtocolBufferException>(() => input.ReadRawVarint64());
+ Assert.AreEqual(expected.Message, exception.Message);
+
+ // Make sure we get the same error when reading directly from a Stream.
+ exception = Assert.Throws<InvalidProtocolBufferException>(() => CodedInputStream.ReadRawVarint32(new MemoryStream(data)));
+ Assert.AreEqual(expected.Message, exception.Message);
+ }
+
+ [Test]
+ public void ReadVarint()
+ {
+ AssertReadVarint(Bytes(0x00), 0);
+ AssertReadVarint(Bytes(0x01), 1);
+ AssertReadVarint(Bytes(0x7f), 127);
+ // 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));
+
+ // 64-bit
+ // 7256456126
+ 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));
+ // 11964378330978735131
+ AssertReadVarint(Bytes(0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85, 0xa6, 0x01),
+ (0x1b << 0) | (0x28 << 7) | (0x79 << 14) | (0x42 << 21) |
+ (0x3bUL << 28) | (0x56UL << 35) | (0x00UL << 42) |
+ (0x05UL << 49) | (0x26UL << 56) | (0x01UL << 63));
+
+ // Failures
+ AssertReadVarintFailure(
+ InvalidProtocolBufferException.MalformedVarint(),
+ Bytes(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+ 0x00));
+ AssertReadVarintFailure(
+ InvalidProtocolBufferException.TruncatedMessage(),
+ Bytes(0x80));
+ }
+
+ /// <summary>
+ /// Parses the given bytes using ReadRawLittleEndian32() and checks
+ /// that the result matches the given value.
+ /// </summary>
+ private static void AssertReadLittleEndian32(byte[] data, uint value)
+ {
+ CodedInputStream input = new CodedInputStream(data);
+ Assert.AreEqual(value, input.ReadRawLittleEndian32());
+ Assert.IsTrue(input.IsAtEnd);
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2)
+ {
+ input = new CodedInputStream(
+ new SmallBlockInputStream(data, blockSize));
+ Assert.AreEqual(value, input.ReadRawLittleEndian32());
+ Assert.IsTrue(input.IsAtEnd);
+ }
+ }
+
+ /// <summary>
+ /// Parses the given bytes using ReadRawLittleEndian64() and checks
+ /// that the result matches the given value.
+ /// </summary>
+ private static void AssertReadLittleEndian64(byte[] data, ulong value)
+ {
+ CodedInputStream input = new CodedInputStream(data);
+ Assert.AreEqual(value, input.ReadRawLittleEndian64());
+ Assert.IsTrue(input.IsAtEnd);
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2)
+ {
+ input = new CodedInputStream(
+ new SmallBlockInputStream(data, blockSize));
+ Assert.AreEqual(value, input.ReadRawLittleEndian64());
+ Assert.IsTrue(input.IsAtEnd);
+ }
+ }
+
+ [Test]
+ public void ReadLittleEndian()
+ {
+ AssertReadLittleEndian32(Bytes(0x78, 0x56, 0x34, 0x12), 0x12345678);
+ AssertReadLittleEndian32(Bytes(0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef0);
+
+ AssertReadLittleEndian64(Bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12),
+ 0x123456789abcdef0L);
+ AssertReadLittleEndian64(
+ Bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef012345678UL);
+ }
+
+ [Test]
+ public void DecodeZigZag32()
+ {
+ Assert.AreEqual(0, CodedInputStream.DecodeZigZag32(0));
+ Assert.AreEqual(-1, CodedInputStream.DecodeZigZag32(1));
+ Assert.AreEqual(1, CodedInputStream.DecodeZigZag32(2));
+ Assert.AreEqual(-2, CodedInputStream.DecodeZigZag32(3));
+ Assert.AreEqual(0x3FFFFFFF, CodedInputStream.DecodeZigZag32(0x7FFFFFFE));
+ Assert.AreEqual(unchecked((int) 0xC0000000), CodedInputStream.DecodeZigZag32(0x7FFFFFFF));
+ Assert.AreEqual(0x7FFFFFFF, CodedInputStream.DecodeZigZag32(0xFFFFFFFE));
+ Assert.AreEqual(unchecked((int) 0x80000000), CodedInputStream.DecodeZigZag32(0xFFFFFFFF));
+ }
+
+ [Test]
+ public void DecodeZigZag64()
+ {
+ Assert.AreEqual(0, CodedInputStream.DecodeZigZag64(0));
+ Assert.AreEqual(-1, CodedInputStream.DecodeZigZag64(1));
+ Assert.AreEqual(1, CodedInputStream.DecodeZigZag64(2));
+ Assert.AreEqual(-2, CodedInputStream.DecodeZigZag64(3));
+ Assert.AreEqual(0x000000003FFFFFFFL, CodedInputStream.DecodeZigZag64(0x000000007FFFFFFEL));
+ Assert.AreEqual(unchecked((long) 0xFFFFFFFFC0000000L), CodedInputStream.DecodeZigZag64(0x000000007FFFFFFFL));
+ Assert.AreEqual(0x000000007FFFFFFFL, CodedInputStream.DecodeZigZag64(0x00000000FFFFFFFEL));
+ Assert.AreEqual(unchecked((long) 0xFFFFFFFF80000000L), CodedInputStream.DecodeZigZag64(0x00000000FFFFFFFFL));
+ Assert.AreEqual(0x7FFFFFFFFFFFFFFFL, CodedInputStream.DecodeZigZag64(0xFFFFFFFFFFFFFFFEL));
+ Assert.AreEqual(unchecked((long) 0x8000000000000000L), CodedInputStream.DecodeZigZag64(0xFFFFFFFFFFFFFFFFL));
+ }
+
+ [Test]
+ public void ReadWholeMessage_VaryingBlockSizes()
+ {
+ TestAllTypes message = SampleMessages.CreateFullTestAllTypes();
+
+ byte[] rawBytes = message.ToByteArray();
+ Assert.AreEqual(rawBytes.Length, message.CalculateSize());
+ TestAllTypes message2 = TestAllTypes.Parser.ParseFrom(rawBytes);
+ Assert.AreEqual(message, message2);
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize < 256; blockSize *= 2)
+ {
+ message2 = TestAllTypes.Parser.ParseFrom(new SmallBlockInputStream(rawBytes, blockSize));
+ Assert.AreEqual(message, message2);
+ }
+ }
+
+ [Test]
+ public void ReadHugeBlob()
+ {
+ // Allocate and initialize a 1MB blob.
+ byte[] blob = new byte[1 << 20];
+ for (int i = 0; i < blob.Length; i++)
+ {
+ blob[i] = (byte) i;
+ }
+
+ // Make a message containing it.
+ var message = new TestAllTypes { SingleBytes = ByteString.CopyFrom(blob) };
+
+ // 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.Parser.ParseFrom(message.ToByteString());
+
+ Assert.AreEqual(message, message2);
+ }
+
+ [Test]
+ public void ReadMaliciouslyLargeBlob()
+ {
+ MemoryStream ms = new MemoryStream();
+ CodedOutputStream output = new CodedOutputStream(ms);
+
+ uint tag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited);
+ output.WriteRawVarint32(tag);
+ output.WriteRawVarint32(0x7FFFFFFF);
+ output.WriteRawBytes(new byte[32]); // Pad with a few random bytes.
+ output.Flush();
+ ms.Position = 0;
+
+ CodedInputStream input = new CodedInputStream(ms);
+ Assert.AreEqual(tag, input.ReadTag());
+
+ Assert.Throws<InvalidProtocolBufferException>(() => input.ReadBytes());
+ }
+
+ internal static TestRecursiveMessage MakeRecursiveMessage(int depth)
+ {
+ if (depth == 0)
+ {
+ return new TestRecursiveMessage { I = 5 };
+ }
+ else
+ {
+ return new TestRecursiveMessage { A = MakeRecursiveMessage(depth - 1) };
+ }
+ }
+
+ internal static void AssertMessageDepth(TestRecursiveMessage message, int depth)
+ {
+ if (depth == 0)
+ {
+ Assert.IsNull(message.A);
+ Assert.AreEqual(5, message.I);
+ }
+ else
+ {
+ Assert.IsNotNull(message.A);
+ AssertMessageDepth(message.A, depth - 1);
+ }
+ }
+
+ [Test]
+ public void MaliciousRecursion()
+ {
+ ByteString data64 = MakeRecursiveMessage(64).ToByteString();
+ ByteString data65 = MakeRecursiveMessage(65).ToByteString();
+
+ AssertMessageDepth(TestRecursiveMessage.Parser.ParseFrom(data64), 64);
+
+ Assert.Throws<InvalidProtocolBufferException>(() => TestRecursiveMessage.Parser.ParseFrom(data65));
+
+ CodedInputStream input = CodedInputStream.CreateWithLimits(new MemoryStream(data64.ToByteArray()), 1000000, 63);
+ Assert.Throws<InvalidProtocolBufferException>(() => TestRecursiveMessage.Parser.ParseFrom(input));
+ }
+
+ [Test]
+ public void SizeLimit()
+ {
+ // Have to use a Stream rather than ByteString.CreateCodedInput as SizeLimit doesn't
+ // apply to the latter case.
+ MemoryStream ms = new MemoryStream(SampleMessages.CreateFullTestAllTypes().ToByteArray());
+ CodedInputStream input = CodedInputStream.CreateWithLimits(ms, 16, 100);
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseFrom(input));
+ }
+
+ /// <summary>
+ /// Tests that if we read an string that contains invalid UTF-8, no exception
+ /// is thrown. Instead, the invalid bytes are replaced with the Unicode
+ /// "replacement character" U+FFFD.
+ /// </summary>
+ [Test]
+ public void ReadInvalidUtf8()
+ {
+ MemoryStream ms = new MemoryStream();
+ CodedOutputStream output = new CodedOutputStream(ms);
+
+ uint tag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited);
+ output.WriteRawVarint32(tag);
+ output.WriteRawVarint32(1);
+ output.WriteRawBytes(new byte[] {0x80});
+ output.Flush();
+ ms.Position = 0;
+
+ CodedInputStream input = new CodedInputStream(ms);
+
+ Assert.AreEqual(tag, input.ReadTag());
+ string text = input.ReadString();
+ Assert.AreEqual('\ufffd', text[0]);
+ }
+
+ /// <summary>
+ /// A stream 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.
+ /// </summary>
+ private sealed class SmallBlockInputStream : MemoryStream
+ {
+ private readonly int blockSize;
+
+ public SmallBlockInputStream(byte[] data, int blockSize)
+ : base(data)
+ {
+ this.blockSize = blockSize;
+ }
+
+ public override int Read(byte[] buffer, int offset, int count)
+ {
+ return base.Read(buffer, offset, Math.Min(count, blockSize));
+ }
+ }
+
+ [Test]
+ public void TestNegativeEnum()
+ {
+ byte[] bytes = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01 };
+ CodedInputStream input = new CodedInputStream(bytes);
+ Assert.AreEqual((int)SampleEnum.NegativeValue, input.ReadEnum());
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ //Issue 71: CodedInputStream.ReadBytes go to slow path unnecessarily
+ [Test]
+ public void TestSlowPathAvoidance()
+ {
+ using (var ms = new MemoryStream())
+ {
+ CodedOutputStream output = new CodedOutputStream(ms);
+ output.WriteTag(1, WireFormat.WireType.LengthDelimited);
+ output.WriteBytes(ByteString.CopyFrom(new byte[100]));
+ output.WriteTag(2, WireFormat.WireType.LengthDelimited);
+ output.WriteBytes(ByteString.CopyFrom(new byte[100]));
+ output.Flush();
+
+ ms.Position = 0;
+ CodedInputStream input = new CodedInputStream(ms, new byte[ms.Length / 2], 0, 0);
+
+ uint tag = input.ReadTag();
+ Assert.AreEqual(1, WireFormat.GetTagFieldNumber(tag));
+ Assert.AreEqual(100, input.ReadBytes().Length);
+
+ tag = input.ReadTag();
+ Assert.AreEqual(2, WireFormat.GetTagFieldNumber(tag));
+ Assert.AreEqual(100, input.ReadBytes().Length);
+ }
+ }
+
+ [Test]
+ public void Tag0Throws()
+ {
+ var input = new CodedInputStream(new byte[] { 0 });
+ Assert.Throws<InvalidProtocolBufferException>(() => input.ReadTag());
+ }
+
+ [Test]
+ public void SkipGroup()
+ {
+ // Create an output stream with a group in:
+ // Field 1: string "field 1"
+ // Field 2: group containing:
+ // Field 1: fixed int32 value 100
+ // Field 2: string "ignore me"
+ // Field 3: nested group containing
+ // Field 1: fixed int64 value 1000
+ // Field 3: string "field 3"
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ output.WriteTag(1, WireFormat.WireType.LengthDelimited);
+ output.WriteString("field 1");
+
+ // The outer group...
+ output.WriteTag(2, WireFormat.WireType.StartGroup);
+ output.WriteTag(1, WireFormat.WireType.Fixed32);
+ output.WriteFixed32(100);
+ output.WriteTag(2, WireFormat.WireType.LengthDelimited);
+ output.WriteString("ignore me");
+ // The nested group...
+ output.WriteTag(3, WireFormat.WireType.StartGroup);
+ output.WriteTag(1, WireFormat.WireType.Fixed64);
+ output.WriteFixed64(1000);
+ // Note: Not sure the field number is relevant for end group...
+ output.WriteTag(3, WireFormat.WireType.EndGroup);
+
+ // End the outer group
+ output.WriteTag(2, WireFormat.WireType.EndGroup);
+
+ output.WriteTag(3, WireFormat.WireType.LengthDelimited);
+ output.WriteString("field 3");
+ output.Flush();
+ stream.Position = 0;
+
+ // Now act like a generated client
+ var input = new CodedInputStream(stream);
+ Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited), input.ReadTag());
+ Assert.AreEqual("field 1", input.ReadString());
+ Assert.AreEqual(WireFormat.MakeTag(2, WireFormat.WireType.StartGroup), input.ReadTag());
+ input.SkipLastField(); // Should consume the whole group, including the nested one.
+ Assert.AreEqual(WireFormat.MakeTag(3, WireFormat.WireType.LengthDelimited), input.ReadTag());
+ Assert.AreEqual("field 3", input.ReadString());
+ }
+
+ [Test]
+ public void SkipGroup_WrongEndGroupTag()
+ {
+ // Create an output stream with:
+ // Field 1: string "field 1"
+ // Start group 2
+ // Field 3: fixed int32
+ // End group 4 (should give an error)
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ output.WriteTag(1, WireFormat.WireType.LengthDelimited);
+ output.WriteString("field 1");
+
+ // The outer group...
+ output.WriteTag(2, WireFormat.WireType.StartGroup);
+ output.WriteTag(3, WireFormat.WireType.Fixed32);
+ output.WriteFixed32(100);
+ output.WriteTag(4, WireFormat.WireType.EndGroup);
+ output.Flush();
+ stream.Position = 0;
+
+ // Now act like a generated client
+ var input = new CodedInputStream(stream);
+ Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited), input.ReadTag());
+ Assert.AreEqual("field 1", input.ReadString());
+ Assert.AreEqual(WireFormat.MakeTag(2, WireFormat.WireType.StartGroup), input.ReadTag());
+ Assert.Throws<InvalidProtocolBufferException>(input.SkipLastField);
+ }
+
+ [Test]
+ public void RogueEndGroupTag()
+ {
+ // If we have an end-group tag without a leading start-group tag, generated
+ // code will just call SkipLastField... so that should fail.
+
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ output.WriteTag(1, WireFormat.WireType.EndGroup);
+ output.Flush();
+ stream.Position = 0;
+
+ var input = new CodedInputStream(stream);
+ Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.EndGroup), input.ReadTag());
+ Assert.Throws<InvalidProtocolBufferException>(input.SkipLastField);
+ }
+
+ [Test]
+ public void EndOfStreamReachedWhileSkippingGroup()
+ {
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ output.WriteTag(1, WireFormat.WireType.StartGroup);
+ output.WriteTag(2, WireFormat.WireType.StartGroup);
+ output.WriteTag(2, WireFormat.WireType.EndGroup);
+
+ output.Flush();
+ stream.Position = 0;
+
+ // Now act like a generated client
+ var input = new CodedInputStream(stream);
+ input.ReadTag();
+ Assert.Throws<InvalidProtocolBufferException>(input.SkipLastField);
+ }
+
+ [Test]
+ public void RecursionLimitAppliedWhileSkippingGroup()
+ {
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ for (int i = 0; i < CodedInputStream.DefaultRecursionLimit + 1; i++)
+ {
+ output.WriteTag(1, WireFormat.WireType.StartGroup);
+ }
+ for (int i = 0; i < CodedInputStream.DefaultRecursionLimit + 1; i++)
+ {
+ output.WriteTag(1, WireFormat.WireType.EndGroup);
+ }
+ output.Flush();
+ stream.Position = 0;
+
+ // Now act like a generated client
+ var input = new CodedInputStream(stream);
+ Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.StartGroup), input.ReadTag());
+ Assert.Throws<InvalidProtocolBufferException>(input.SkipLastField);
+ }
+
+ [Test]
+ public void Construction_Invalid()
+ {
+ Assert.Throws<ArgumentNullException>(() => new CodedInputStream((byte[]) null));
+ Assert.Throws<ArgumentNullException>(() => new CodedInputStream(null, 0, 0));
+ Assert.Throws<ArgumentNullException>(() => new CodedInputStream((Stream) null));
+ Assert.Throws<ArgumentOutOfRangeException>(() => new CodedInputStream(new byte[10], 100, 0));
+ Assert.Throws<ArgumentOutOfRangeException>(() => new CodedInputStream(new byte[10], 5, 10));
+ }
+
+ [Test]
+ public void CreateWithLimits_InvalidLimits()
+ {
+ var stream = new MemoryStream();
+ Assert.Throws<ArgumentOutOfRangeException>(() => CodedInputStream.CreateWithLimits(stream, 0, 1));
+ Assert.Throws<ArgumentOutOfRangeException>(() => CodedInputStream.CreateWithLimits(stream, 1, 0));
+ }
+
+ [Test]
+ public void Dispose_DisposesUnderlyingStream()
+ {
+ var memoryStream = new MemoryStream();
+ Assert.IsTrue(memoryStream.CanRead);
+ using (var cis = new CodedInputStream(memoryStream))
+ {
+ }
+ Assert.IsFalse(memoryStream.CanRead); // Disposed
+ }
+
+ [Test]
+ public void Dispose_WithLeaveOpen()
+ {
+ var memoryStream = new MemoryStream();
+ Assert.IsTrue(memoryStream.CanRead);
+ using (var cis = new CodedInputStream(memoryStream, true))
+ {
+ }
+ Assert.IsTrue(memoryStream.CanRead); // We left the stream open
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
new file mode 100644
index 0000000000..48bf6d6000
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
@@ -0,0 +1,419 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.IO;
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+
+namespace Google.Protobuf
+{
+ public class CodedOutputStreamTest
+ {
+ /// <summary>
+ /// Writes the given value using WriteRawVarint32() and WriteRawVarint64() and
+ /// checks that the result matches the given bytes
+ /// </summary>
+ private static void AssertWriteVarint(byte[] data, ulong value)
+ {
+ // Only do 32-bit write if the value fits in 32 bits.
+ if ((value >> 32) == 0)
+ {
+ MemoryStream rawOutput = new MemoryStream();
+ CodedOutputStream output = new CodedOutputStream(rawOutput);
+ output.WriteRawVarint32((uint) value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+ // Also try computing size.
+ Assert.AreEqual(data.Length, CodedOutputStream.ComputeRawVarint32Size((uint) value));
+ }
+
+ {
+ MemoryStream rawOutput = new MemoryStream();
+ CodedOutputStream output = new CodedOutputStream(rawOutput);
+ output.WriteRawVarint64(value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+
+ // Also try computing size.
+ Assert.AreEqual(data.Length, CodedOutputStream.ComputeRawVarint64Size(value));
+ }
+
+ // Try different buffer sizes.
+ for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2)
+ {
+ // Only do 32-bit write if the value fits in 32 bits.
+ if ((value >> 32) == 0)
+ {
+ MemoryStream rawOutput = new MemoryStream();
+ CodedOutputStream output =
+ new CodedOutputStream(rawOutput, bufferSize);
+ output.WriteRawVarint32((uint) value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+ }
+
+ {
+ MemoryStream rawOutput = new MemoryStream();
+ CodedOutputStream output = new CodedOutputStream(rawOutput, bufferSize);
+ output.WriteRawVarint64(value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+ }
+ }
+ }
+
+ /// <summary>
+ /// Tests WriteRawVarint32() and WriteRawVarint64()
+ /// </summary>
+ [Test]
+ public void WriteVarint()
+ {
+ AssertWriteVarint(new byte[] {0x00}, 0);
+ AssertWriteVarint(new byte[] {0x01}, 1);
+ AssertWriteVarint(new byte[] {0x7f}, 127);
+ // 14882
+ AssertWriteVarint(new byte[] {0xa2, 0x74}, (0x22 << 0) | (0x74 << 7));
+ // 2961488830
+ AssertWriteVarint(new byte[] {0xbe, 0xf7, 0x92, 0x84, 0x0b},
+ (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) |
+ (0x0bL << 28));
+
+ // 64-bit
+ // 7256456126
+ AssertWriteVarint(new byte[] {0xbe, 0xf7, 0x92, 0x84, 0x1b},
+ (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) |
+ (0x1bL << 28));
+ // 41256202580718336
+ AssertWriteVarint(
+ new byte[] {0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49},
+ (0x00 << 0) | (0x66 << 7) | (0x6b << 14) | (0x1c << 21) |
+ (0x43UL << 28) | (0x49L << 35) | (0x24UL << 42) | (0x49UL << 49));
+ // 11964378330978735131
+ AssertWriteVarint(
+ new byte[] {0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85, 0xa6, 0x01},
+ unchecked((ulong)
+ ((0x1b << 0) | (0x28 << 7) | (0x79 << 14) | (0x42 << 21) |
+ (0x3bL << 28) | (0x56L << 35) | (0x00L << 42) |
+ (0x05L << 49) | (0x26L << 56) | (0x01L << 63))));
+ }
+
+ /// <summary>
+ /// Parses the given bytes using WriteRawLittleEndian32() and checks
+ /// that the result matches the given value.
+ /// </summary>
+ private static void AssertWriteLittleEndian32(byte[] data, uint value)
+ {
+ MemoryStream rawOutput = new MemoryStream();
+ CodedOutputStream output = new CodedOutputStream(rawOutput);
+ output.WriteRawLittleEndian32(value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+
+ // Try different buffer sizes.
+ for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2)
+ {
+ rawOutput = new MemoryStream();
+ output = new CodedOutputStream(rawOutput, bufferSize);
+ output.WriteRawLittleEndian32(value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+ }
+ }
+
+ /// <summary>
+ /// Parses the given bytes using WriteRawLittleEndian64() and checks
+ /// that the result matches the given value.
+ /// </summary>
+ private static void AssertWriteLittleEndian64(byte[] data, ulong value)
+ {
+ MemoryStream rawOutput = new MemoryStream();
+ CodedOutputStream output = new CodedOutputStream(rawOutput);
+ output.WriteRawLittleEndian64(value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2)
+ {
+ rawOutput = new MemoryStream();
+ output = new CodedOutputStream(rawOutput, blockSize);
+ output.WriteRawLittleEndian64(value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+ }
+ }
+
+ /// <summary>
+ /// Tests writeRawLittleEndian32() and writeRawLittleEndian64().
+ /// </summary>
+ [Test]
+ public void WriteLittleEndian()
+ {
+ AssertWriteLittleEndian32(new byte[] {0x78, 0x56, 0x34, 0x12}, 0x12345678);
+ AssertWriteLittleEndian32(new byte[] {0xf0, 0xde, 0xbc, 0x9a}, 0x9abcdef0);
+
+ AssertWriteLittleEndian64(
+ new byte[] {0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12},
+ 0x123456789abcdef0L);
+ AssertWriteLittleEndian64(
+ new byte[] {0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a},
+ 0x9abcdef012345678UL);
+ }
+
+ [Test]
+ public void WriteWholeMessage_VaryingBlockSizes()
+ {
+ TestAllTypes message = SampleMessages.CreateFullTestAllTypes();
+
+ byte[] rawBytes = message.ToByteArray();
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize < 256; blockSize *= 2)
+ {
+ MemoryStream rawOutput = new MemoryStream();
+ CodedOutputStream output = new CodedOutputStream(rawOutput, blockSize);
+ message.WriteTo(output);
+ output.Flush();
+ Assert.AreEqual(rawBytes, rawOutput.ToArray());
+ }
+ }
+
+ [Test]
+ public void EncodeZigZag32()
+ {
+ Assert.AreEqual(0u, CodedOutputStream.EncodeZigZag32(0));
+ Assert.AreEqual(1u, CodedOutputStream.EncodeZigZag32(-1));
+ Assert.AreEqual(2u, CodedOutputStream.EncodeZigZag32(1));
+ Assert.AreEqual(3u, CodedOutputStream.EncodeZigZag32(-2));
+ Assert.AreEqual(0x7FFFFFFEu, CodedOutputStream.EncodeZigZag32(0x3FFFFFFF));
+ Assert.AreEqual(0x7FFFFFFFu, CodedOutputStream.EncodeZigZag32(unchecked((int) 0xC0000000)));
+ Assert.AreEqual(0xFFFFFFFEu, CodedOutputStream.EncodeZigZag32(0x7FFFFFFF));
+ Assert.AreEqual(0xFFFFFFFFu, CodedOutputStream.EncodeZigZag32(unchecked((int) 0x80000000)));
+ }
+
+ [Test]
+ public void EncodeZigZag64()
+ {
+ Assert.AreEqual(0u, CodedOutputStream.EncodeZigZag64(0));
+ Assert.AreEqual(1u, CodedOutputStream.EncodeZigZag64(-1));
+ Assert.AreEqual(2u, CodedOutputStream.EncodeZigZag64(1));
+ Assert.AreEqual(3u, CodedOutputStream.EncodeZigZag64(-2));
+ Assert.AreEqual(0x000000007FFFFFFEuL,
+ CodedOutputStream.EncodeZigZag64(unchecked((long) 0x000000003FFFFFFFUL)));
+ Assert.AreEqual(0x000000007FFFFFFFuL,
+ CodedOutputStream.EncodeZigZag64(unchecked((long) 0xFFFFFFFFC0000000UL)));
+ Assert.AreEqual(0x00000000FFFFFFFEuL,
+ CodedOutputStream.EncodeZigZag64(unchecked((long) 0x000000007FFFFFFFUL)));
+ Assert.AreEqual(0x00000000FFFFFFFFuL,
+ CodedOutputStream.EncodeZigZag64(unchecked((long) 0xFFFFFFFF80000000UL)));
+ Assert.AreEqual(0xFFFFFFFFFFFFFFFEL,
+ CodedOutputStream.EncodeZigZag64(unchecked((long) 0x7FFFFFFFFFFFFFFFUL)));
+ Assert.AreEqual(0xFFFFFFFFFFFFFFFFL,
+ CodedOutputStream.EncodeZigZag64(unchecked((long) 0x8000000000000000UL)));
+ }
+
+ [Test]
+ public void RoundTripZigZag32()
+ {
+ // Some easier-to-verify round-trip tests. The inputs (other than 0, 1, -1)
+ // were chosen semi-randomly via keyboard bashing.
+ Assert.AreEqual(0, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(0)));
+ Assert.AreEqual(1, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(1)));
+ Assert.AreEqual(-1, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-1)));
+ Assert.AreEqual(14927, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(14927)));
+ Assert.AreEqual(-3612, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-3612)));
+ }
+
+ [Test]
+ public void RoundTripZigZag64()
+ {
+ Assert.AreEqual(0, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(0)));
+ Assert.AreEqual(1, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(1)));
+ Assert.AreEqual(-1, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-1)));
+ Assert.AreEqual(14927, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(14927)));
+ Assert.AreEqual(-3612, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-3612)));
+
+ Assert.AreEqual(856912304801416L,
+ CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(856912304801416L)));
+ Assert.AreEqual(-75123905439571256L,
+ CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-75123905439571256L)));
+ }
+
+ [Test]
+ public void TestNegativeEnumNoTag()
+ {
+ Assert.AreEqual(10, CodedOutputStream.ComputeInt32Size(-2));
+ Assert.AreEqual(10, CodedOutputStream.ComputeEnumSize((int) SampleEnum.NegativeValue));
+
+ byte[] bytes = new byte[10];
+ CodedOutputStream output = new CodedOutputStream(bytes);
+ output.WriteEnum((int) SampleEnum.NegativeValue);
+
+ Assert.AreEqual(0, output.SpaceLeft);
+ Assert.AreEqual("FE-FF-FF-FF-FF-FF-FF-FF-FF-01", BitConverter.ToString(bytes));
+ }
+
+ [Test]
+ public void TestCodedInputOutputPosition()
+ {
+ byte[] content = new byte[110];
+ for (int i = 0; i < content.Length; i++)
+ content[i] = (byte)i;
+
+ byte[] child = new byte[120];
+ {
+ MemoryStream ms = new MemoryStream(child);
+ CodedOutputStream cout = new CodedOutputStream(ms, 20);
+ // Field 11: numeric value: 500
+ cout.WriteTag(11, WireFormat.WireType.Varint);
+ Assert.AreEqual(1, cout.Position);
+ cout.WriteInt32(500);
+ Assert.AreEqual(3, cout.Position);
+ //Field 12: length delimited 120 bytes
+ cout.WriteTag(12, WireFormat.WireType.LengthDelimited);
+ Assert.AreEqual(4, cout.Position);
+ cout.WriteBytes(ByteString.CopyFrom(content));
+ Assert.AreEqual(115, cout.Position);
+ // Field 13: fixed numeric value: 501
+ cout.WriteTag(13, WireFormat.WireType.Fixed32);
+ Assert.AreEqual(116, cout.Position);
+ cout.WriteSFixed32(501);
+ Assert.AreEqual(120, cout.Position);
+ cout.Flush();
+ }
+
+ byte[] bytes = new byte[130];
+ {
+ CodedOutputStream cout = new CodedOutputStream(bytes);
+ // Field 1: numeric value: 500
+ cout.WriteTag(1, WireFormat.WireType.Varint);
+ Assert.AreEqual(1, cout.Position);
+ cout.WriteInt32(500);
+ Assert.AreEqual(3, cout.Position);
+ //Field 2: length delimited 120 bytes
+ cout.WriteTag(2, WireFormat.WireType.LengthDelimited);
+ Assert.AreEqual(4, cout.Position);
+ cout.WriteBytes(ByteString.CopyFrom(child));
+ Assert.AreEqual(125, cout.Position);
+ // Field 3: fixed numeric value: 500
+ cout.WriteTag(3, WireFormat.WireType.Fixed32);
+ Assert.AreEqual(126, cout.Position);
+ cout.WriteSFixed32(501);
+ Assert.AreEqual(130, cout.Position);
+ cout.Flush();
+ }
+ // Now test Input stream:
+ {
+ CodedInputStream cin = new CodedInputStream(new MemoryStream(bytes), new byte[50], 0, 0);
+ Assert.AreEqual(0, cin.Position);
+ // Field 1:
+ uint tag = cin.ReadTag();
+ Assert.AreEqual(1, tag >> 3);
+ Assert.AreEqual(1, cin.Position);
+ Assert.AreEqual(500, cin.ReadInt32());
+ Assert.AreEqual(3, cin.Position);
+ //Field 2:
+ tag = cin.ReadTag();
+ Assert.AreEqual(2, tag >> 3);
+ Assert.AreEqual(4, cin.Position);
+ int childlen = cin.ReadLength();
+ Assert.AreEqual(120, childlen);
+ Assert.AreEqual(5, cin.Position);
+ int oldlimit = cin.PushLimit((int)childlen);
+ Assert.AreEqual(5, cin.Position);
+ // Now we are reading child message
+ {
+ // Field 11: numeric value: 500
+ tag = cin.ReadTag();
+ Assert.AreEqual(11, tag >> 3);
+ Assert.AreEqual(6, cin.Position);
+ Assert.AreEqual(500, cin.ReadInt32());
+ Assert.AreEqual(8, cin.Position);
+ //Field 12: length delimited 120 bytes
+ tag = cin.ReadTag();
+ Assert.AreEqual(12, tag >> 3);
+ Assert.AreEqual(9, cin.Position);
+ ByteString bstr = cin.ReadBytes();
+ Assert.AreEqual(110, bstr.Length);
+ Assert.AreEqual((byte) 109, bstr[109]);
+ Assert.AreEqual(120, cin.Position);
+ // Field 13: fixed numeric value: 501
+ tag = cin.ReadTag();
+ Assert.AreEqual(13, tag >> 3);
+ // ROK - Previously broken here, this returned 126 failing to account for bufferSizeAfterLimit
+ Assert.AreEqual(121, cin.Position);
+ Assert.AreEqual(501, cin.ReadSFixed32());
+ Assert.AreEqual(125, cin.Position);
+ Assert.IsTrue(cin.IsAtEnd);
+ }
+ cin.PopLimit(oldlimit);
+ Assert.AreEqual(125, cin.Position);
+ // Field 3: fixed numeric value: 501
+ tag = cin.ReadTag();
+ Assert.AreEqual(3, tag >> 3);
+ Assert.AreEqual(126, cin.Position);
+ Assert.AreEqual(501, cin.ReadSFixed32());
+ Assert.AreEqual(130, cin.Position);
+ Assert.IsTrue(cin.IsAtEnd);
+ }
+ }
+
+ [Test]
+ public void Dispose_DisposesUnderlyingStream()
+ {
+ var memoryStream = new MemoryStream();
+ Assert.IsTrue(memoryStream.CanWrite);
+ using (var cos = new CodedOutputStream(memoryStream))
+ {
+ cos.WriteRawByte(0);
+ Assert.AreEqual(0, memoryStream.Position); // Not flushed yet
+ }
+ Assert.AreEqual(1, memoryStream.ToArray().Length); // Flushed data from CodedOutputStream to MemoryStream
+ Assert.IsFalse(memoryStream.CanWrite); // Disposed
+ }
+
+ [Test]
+ public void Dispose_WithLeaveOpen()
+ {
+ var memoryStream = new MemoryStream();
+ Assert.IsTrue(memoryStream.CanWrite);
+ using (var cos = new CodedOutputStream(memoryStream, true))
+ {
+ cos.WriteRawByte(0);
+ Assert.AreEqual(0, memoryStream.Position); // Not flushed yet
+ }
+ Assert.AreEqual(1, memoryStream.Position); // Flushed data from CodedOutputStream to MemoryStream
+ Assert.IsTrue(memoryStream.CanWrite); // We left the stream open
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs
new file mode 100644
index 0000000000..9d3d69afd2
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs
@@ -0,0 +1,548 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+using System.Collections;
+using System.Linq;
+
+namespace Google.Protobuf.Collections
+{
+ /// <summary>
+ /// Tests for MapField which aren't reliant on the encoded format -
+ /// tests for serialization/deserialization are part of GeneratedMessageTest.
+ /// </summary>
+ public class MapFieldTest
+ {
+ [Test]
+ public void Clone_ClonesMessages()
+ {
+ var message = new ForeignMessage { C = 20 };
+ var map = new MapField<string, ForeignMessage> { { "x", message } };
+ var clone = map.Clone();
+ map["x"].C = 30;
+ Assert.AreEqual(20, clone["x"].C);
+ }
+
+ [Test]
+ public void NullValuesProhibited()
+ {
+ TestNullValues<int?>(0);
+ TestNullValues("");
+ TestNullValues(new TestAllTypes());
+ }
+
+ private void TestNullValues<T>(T nonNullValue)
+ {
+ var map = new MapField<int, T>();
+ var nullValue = (T) (object) null;
+ Assert.Throws<ArgumentNullException>(() => map.Add(0, nullValue));
+ Assert.Throws<ArgumentNullException>(() => map[0] = nullValue);
+ map.Add(1, nonNullValue);
+ map[1] = nonNullValue;
+ }
+
+ [Test]
+ public void Add_ForbidsNullKeys()
+ {
+ var map = new MapField<string, ForeignMessage>();
+ Assert.Throws<ArgumentNullException>(() => map.Add(null, new ForeignMessage()));
+ }
+
+ [Test]
+ public void Indexer_ForbidsNullKeys()
+ {
+ var map = new MapField<string, ForeignMessage>();
+ Assert.Throws<ArgumentNullException>(() => map[null] = new ForeignMessage());
+ }
+
+ [Test]
+ public void AddPreservesInsertionOrder()
+ {
+ var map = new MapField<string, string>();
+ map.Add("a", "v1");
+ map.Add("b", "v2");
+ map.Add("c", "v3");
+ map.Remove("b");
+ map.Add("d", "v4");
+ CollectionAssert.AreEqual(new[] { "a", "c", "d" }, map.Keys);
+ CollectionAssert.AreEqual(new[] { "v1", "v3", "v4" }, map.Values);
+ }
+
+ [Test]
+ public void EqualityIsOrderInsensitive()
+ {
+ var map1 = new MapField<string, string>();
+ map1.Add("a", "v1");
+ map1.Add("b", "v2");
+
+ var map2 = new MapField<string, string>();
+ map2.Add("b", "v2");
+ map2.Add("a", "v1");
+
+ EqualityTester.AssertEquality(map1, map2);
+ }
+
+ [Test]
+ public void EqualityIsKeySensitive()
+ {
+ var map1 = new MapField<string, string>();
+ map1.Add("first key", "v1");
+ map1.Add("second key", "v2");
+
+ var map2 = new MapField<string, string>();
+ map2.Add("third key", "v1");
+ map2.Add("fourth key", "v2");
+
+ EqualityTester.AssertInequality(map1, map2);
+ }
+
+ [Test]
+ public void Equality_Simple()
+ {
+ var map = new MapField<string, string>();
+ EqualityTester.AssertEquality(map, map);
+ EqualityTester.AssertInequality(map, null);
+ Assert.IsFalse(map.Equals(new object()));
+ }
+
+ [Test]
+ public void EqualityIsValueSensitive()
+ {
+ // Note: Without some care, it's a little easier than one might
+ // hope to see hash collisions, but only in some environments...
+ var map1 = new MapField<string, string>();
+ map1.Add("a", "first value");
+ map1.Add("b", "second value");
+
+ var map2 = new MapField<string, string>();
+ map2.Add("a", "third value");
+ map2.Add("b", "fourth value");
+
+ EqualityTester.AssertInequality(map1, map2);
+ }
+
+ [Test]
+ public void Add_Dictionary()
+ {
+ var map1 = new MapField<string, string>
+ {
+ { "x", "y" },
+ { "a", "b" }
+ };
+ var map2 = new MapField<string, string>
+ {
+ { "before", "" },
+ map1,
+ { "after", "" }
+ };
+ var expected = new MapField<string, string>
+ {
+ { "before", "" },
+ { "x", "y" },
+ { "a", "b" },
+ { "after", "" }
+ };
+ Assert.AreEqual(expected, map2);
+ CollectionAssert.AreEqual(new[] { "before", "x", "a", "after" }, map2.Keys);
+ }
+
+ // General IDictionary<TKey, TValue> behavior tests
+ [Test]
+ public void Add_KeyAlreadyExists()
+ {
+ var map = new MapField<string, string>();
+ map.Add("foo", "bar");
+ Assert.Throws<ArgumentException>(() => map.Add("foo", "baz"));
+ }
+
+ [Test]
+ public void Add_Pair()
+ {
+ var map = new MapField<string, string>();
+ ICollection<KeyValuePair<string, string>> collection = map;
+ collection.Add(NewKeyValuePair("x", "y"));
+ Assert.AreEqual("y", map["x"]);
+ Assert.Throws<ArgumentException>(() => collection.Add(NewKeyValuePair("x", "z")));
+ }
+
+ [Test]
+ public void Contains_Pair()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ ICollection<KeyValuePair<string, string>> collection = map;
+ Assert.IsTrue(collection.Contains(NewKeyValuePair("x", "y")));
+ Assert.IsFalse(collection.Contains(NewKeyValuePair("x", "z")));
+ Assert.IsFalse(collection.Contains(NewKeyValuePair("z", "y")));
+ }
+
+ [Test]
+ public void Remove_Key()
+ {
+ var map = new MapField<string, string>();
+ map.Add("foo", "bar");
+ Assert.AreEqual(1, map.Count);
+ Assert.IsFalse(map.Remove("missing"));
+ Assert.AreEqual(1, map.Count);
+ Assert.IsTrue(map.Remove("foo"));
+ Assert.AreEqual(0, map.Count);
+ Assert.Throws<ArgumentNullException>(() => map.Remove(null));
+ }
+
+ [Test]
+ public void Remove_Pair()
+ {
+ var map = new MapField<string, string>();
+ map.Add("foo", "bar");
+ ICollection<KeyValuePair<string, string>> collection = map;
+ Assert.AreEqual(1, map.Count);
+ Assert.IsFalse(collection.Remove(NewKeyValuePair("wrong key", "bar")));
+ Assert.AreEqual(1, map.Count);
+ Assert.IsFalse(collection.Remove(NewKeyValuePair("foo", "wrong value")));
+ Assert.AreEqual(1, map.Count);
+ Assert.IsTrue(collection.Remove(NewKeyValuePair("foo", "bar")));
+ Assert.AreEqual(0, map.Count);
+ Assert.Throws<ArgumentException>(() => collection.Remove(new KeyValuePair<string, string>(null, "")));
+ }
+
+ [Test]
+ public void CopyTo_Pair()
+ {
+ var map = new MapField<string, string>();
+ map.Add("foo", "bar");
+ ICollection<KeyValuePair<string, string>> collection = map;
+ KeyValuePair<string, string>[] array = new KeyValuePair<string, string>[3];
+ collection.CopyTo(array, 1);
+ Assert.AreEqual(NewKeyValuePair("foo", "bar"), array[1]);
+ }
+
+ [Test]
+ public void Clear()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ Assert.AreEqual(1, map.Count);
+ map.Clear();
+ Assert.AreEqual(0, map.Count);
+ map.Add("x", "y");
+ Assert.AreEqual(1, map.Count);
+ }
+
+ [Test]
+ public void Indexer_Get()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ Assert.AreEqual("y", map["x"]);
+ Assert.Throws<KeyNotFoundException>(() => { var ignored = map["z"]; });
+ }
+
+ [Test]
+ public void Indexer_Set()
+ {
+ var map = new MapField<string, string>();
+ map["x"] = "y";
+ Assert.AreEqual("y", map["x"]);
+ map["x"] = "z"; // This won't throw, unlike Add.
+ Assert.AreEqual("z", map["x"]);
+ }
+
+ [Test]
+ public void GetEnumerator_NonGeneric()
+ {
+ IEnumerable map = new MapField<string, string> { { "x", "y" } };
+ CollectionAssert.AreEqual(new[] { new KeyValuePair<string, string>("x", "y") },
+ map.Cast<object>().ToList());
+ }
+
+ // Test for the explicitly-implemented non-generic IDictionary interface
+ [Test]
+ public void IDictionary_GetEnumerator()
+ {
+ IDictionary map = new MapField<string, string> { { "x", "y" } };
+ var enumerator = map.GetEnumerator();
+
+ // Commented assertions show an ideal situation - it looks like
+ // the LinkedList enumerator doesn't throw when you ask for the current entry
+ // at an inappropriate time; fixing this would be more work than it's worth.
+ // Assert.Throws<InvalidOperationException>(() => enumerator.Current.GetHashCode());
+ Assert.IsTrue(enumerator.MoveNext());
+ Assert.AreEqual("x", enumerator.Key);
+ Assert.AreEqual("y", enumerator.Value);
+ Assert.AreEqual(new DictionaryEntry("x", "y"), enumerator.Current);
+ Assert.AreEqual(new DictionaryEntry("x", "y"), enumerator.Entry);
+ Assert.IsFalse(enumerator.MoveNext());
+ // Assert.Throws<InvalidOperationException>(() => enumerator.Current.GetHashCode());
+ enumerator.Reset();
+ // Assert.Throws<InvalidOperationException>(() => enumerator.Current.GetHashCode());
+ Assert.IsTrue(enumerator.MoveNext());
+ Assert.AreEqual("x", enumerator.Key); // Assume the rest are okay
+ }
+
+ [Test]
+ public void IDictionary_Add()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ IDictionary dictionary = map;
+ dictionary.Add("a", "b");
+ Assert.AreEqual("b", map["a"]);
+ Assert.Throws<ArgumentException>(() => dictionary.Add("a", "duplicate"));
+ Assert.Throws<InvalidCastException>(() => dictionary.Add(new object(), "key is bad"));
+ Assert.Throws<InvalidCastException>(() => dictionary.Add("value is bad", new object()));
+ }
+
+ [Test]
+ public void IDictionary_Contains()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ IDictionary dictionary = map;
+
+ Assert.IsFalse(dictionary.Contains("a"));
+ Assert.IsFalse(dictionary.Contains(5));
+ // Surprising, but IDictionary.Contains is only about keys.
+ Assert.IsFalse(dictionary.Contains(new DictionaryEntry("x", "y")));
+ Assert.IsTrue(dictionary.Contains("x"));
+ }
+
+ [Test]
+ public void IDictionary_Remove()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ IDictionary dictionary = map;
+ dictionary.Remove("a");
+ Assert.AreEqual(1, dictionary.Count);
+ dictionary.Remove(5);
+ Assert.AreEqual(1, dictionary.Count);
+ dictionary.Remove(new DictionaryEntry("x", "y"));
+ Assert.AreEqual(1, dictionary.Count);
+ dictionary.Remove("x");
+ Assert.AreEqual(0, dictionary.Count);
+ Assert.Throws<ArgumentNullException>(() => dictionary.Remove(null));
+ }
+
+ [Test]
+ public void IDictionary_CopyTo()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ IDictionary dictionary = map;
+ var array = new DictionaryEntry[3];
+ dictionary.CopyTo(array, 1);
+ CollectionAssert.AreEqual(new[] { default(DictionaryEntry), new DictionaryEntry("x", "y"), default(DictionaryEntry) },
+ array);
+ var objectArray = new object[3];
+ dictionary.CopyTo(objectArray, 1);
+ CollectionAssert.AreEqual(new object[] { null, new DictionaryEntry("x", "y"), null },
+ objectArray);
+ }
+
+ [Test]
+ public void IDictionary_IsFixedSize()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ IDictionary dictionary = map;
+ Assert.IsFalse(dictionary.IsFixedSize);
+ }
+
+ [Test]
+ public void IDictionary_Keys()
+ {
+ IDictionary dictionary = new MapField<string, string> { { "x", "y" } };
+ CollectionAssert.AreEqual(new[] { "x" }, dictionary.Keys);
+ }
+
+ [Test]
+ public void IDictionary_Values()
+ {
+ IDictionary dictionary = new MapField<string, string> { { "x", "y" } };
+ CollectionAssert.AreEqual(new[] { "y" }, dictionary.Values);
+ }
+
+ [Test]
+ public void IDictionary_IsSynchronized()
+ {
+ IDictionary dictionary = new MapField<string, string> { { "x", "y" } };
+ Assert.IsFalse(dictionary.IsSynchronized);
+ }
+
+ [Test]
+ public void IDictionary_SyncRoot()
+ {
+ IDictionary dictionary = new MapField<string, string> { { "x", "y" } };
+ Assert.AreSame(dictionary, dictionary.SyncRoot);
+ }
+
+ [Test]
+ public void IDictionary_Indexer_Get()
+ {
+ IDictionary dictionary = new MapField<string, string> { { "x", "y" } };
+ Assert.AreEqual("y", dictionary["x"]);
+ Assert.IsNull(dictionary["a"]);
+ Assert.IsNull(dictionary[5]);
+ Assert.Throws<ArgumentNullException>(() => dictionary[null].GetHashCode());
+ }
+
+ [Test]
+ public void IDictionary_Indexer_Set()
+ {
+ var map = new MapField<string, string> { { "x", "y" } };
+ IDictionary dictionary = map;
+ map["a"] = "b";
+ Assert.AreEqual("b", map["a"]);
+ map["a"] = "c";
+ Assert.AreEqual("c", map["a"]);
+ Assert.Throws<InvalidCastException>(() => dictionary[5] = "x");
+ Assert.Throws<InvalidCastException>(() => dictionary["x"] = 5);
+ Assert.Throws<ArgumentNullException>(() => dictionary[null] = "z");
+ Assert.Throws<ArgumentNullException>(() => dictionary["x"] = null);
+ }
+
+ [Test]
+ public void KeysReturnsLiveView()
+ {
+ var map = new MapField<string, string>();
+ var keys = map.Keys;
+ CollectionAssert.AreEqual(new string[0], keys);
+ map["foo"] = "bar";
+ map["x"] = "y";
+ CollectionAssert.AreEqual(new[] { "foo", "x" }, keys);
+ }
+
+ [Test]
+ public void ValuesReturnsLiveView()
+ {
+ var map = new MapField<string, string>();
+ var values = map.Values;
+ CollectionAssert.AreEqual(new string[0], values);
+ map["foo"] = "bar";
+ map["x"] = "y";
+ CollectionAssert.AreEqual(new[] { "bar", "y" }, values);
+ }
+
+ // Just test keys - we know the implementation is the same for values
+ [Test]
+ public void ViewsAreReadOnly()
+ {
+ var map = new MapField<string, string>();
+ var keys = map.Keys;
+ Assert.IsTrue(keys.IsReadOnly);
+ Assert.Throws<NotSupportedException>(() => keys.Clear());
+ Assert.Throws<NotSupportedException>(() => keys.Remove("a"));
+ Assert.Throws<NotSupportedException>(() => keys.Add("a"));
+ }
+
+ // Just test keys - we know the implementation is the same for values
+ [Test]
+ public void ViewCopyTo()
+ {
+ var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
+ var keys = map.Keys;
+ var array = new string[4];
+ Assert.Throws<ArgumentException>(() => keys.CopyTo(array, 3));
+ Assert.Throws<ArgumentOutOfRangeException>(() => keys.CopyTo(array, -1));
+ keys.CopyTo(array, 1);
+ CollectionAssert.AreEqual(new[] { null, "foo", "x", null }, array);
+ }
+
+ // Just test keys - we know the implementation is the same for values
+ [Test]
+ public void NonGenericViewCopyTo()
+ {
+ IDictionary map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
+ ICollection keys = map.Keys;
+ // Note the use of the Array type here rather than string[]
+ Array array = new string[4];
+ Assert.Throws<ArgumentException>(() => keys.CopyTo(array, 3));
+ Assert.Throws<ArgumentOutOfRangeException>(() => keys.CopyTo(array, -1));
+ keys.CopyTo(array, 1);
+ CollectionAssert.AreEqual(new[] { null, "foo", "x", null }, array);
+ }
+
+ [Test]
+ public void KeysContains()
+ {
+ var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
+ var keys = map.Keys;
+ Assert.IsTrue(keys.Contains("foo"));
+ Assert.IsFalse(keys.Contains("bar")); // It's a value!
+ Assert.IsFalse(keys.Contains("1"));
+ // Keys can't be null, so we should prevent contains check
+ Assert.Throws<ArgumentNullException>(() => keys.Contains(null));
+ }
+
+ [Test]
+ public void KeysCopyTo()
+ {
+ var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
+ var keys = map.Keys.ToArray(); // Uses CopyTo internally
+ CollectionAssert.AreEquivalent(new[] { "foo", "x" }, keys);
+ }
+
+ [Test]
+ public void ValuesContains()
+ {
+ var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
+ var values = map.Values;
+ Assert.IsTrue(values.Contains("bar"));
+ Assert.IsFalse(values.Contains("foo")); // It's a key!
+ Assert.IsFalse(values.Contains("1"));
+ // Values can be null, so this makes sense
+ Assert.IsFalse(values.Contains(null));
+ }
+
+ [Test]
+ public void ValuesCopyTo()
+ {
+ var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
+ var values = map.Values.ToArray(); // Uses CopyTo internally
+ CollectionAssert.AreEquivalent(new[] { "bar", "y" }, values);
+ }
+
+ [Test]
+ public void ToString_StringToString()
+ {
+ var map = new MapField<string, string> { { "foo", "bar" }, { "x", "y" } };
+ Assert.AreEqual("{ \"foo\": \"bar\", \"x\": \"y\" }", map.ToString());
+ }
+
+ [Test]
+ public void ToString_UnsupportedKeyType()
+ {
+ var map = new MapField<byte, string> { { 10, "foo" } };
+ Assert.Throws<ArgumentException>(() => map.ToString());
+ }
+
+ private static KeyValuePair<TKey, TValue> NewKeyValuePair<TKey, TValue>(TKey key, TValue value)
+ {
+ return new KeyValuePair<TKey, TValue>(key, value);
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs
new file mode 100644
index 0000000000..6852f75f8e
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs
@@ -0,0 +1,746 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using Google.Protobuf.TestProtos;
+using Google.Protobuf.WellKnownTypes;
+using NUnit.Framework;
+
+namespace Google.Protobuf.Collections
+{
+ public class RepeatedFieldTest
+ {
+ [Test]
+ public void NullValuesRejected()
+ {
+ var list = new RepeatedField<string>();
+ Assert.Throws<ArgumentNullException>(() => list.Add((string)null));
+ Assert.Throws<ArgumentNullException>(() => list.Add((IEnumerable<string>)null));
+ Assert.Throws<ArgumentNullException>(() => list.Add((RepeatedField<string>)null));
+ Assert.Throws<ArgumentNullException>(() => list.Contains(null));
+ Assert.Throws<ArgumentNullException>(() => list.IndexOf(null));
+ }
+
+ [Test]
+ public void Add_SingleItem()
+ {
+ var list = new RepeatedField<string>();
+ list.Add("foo");
+ Assert.AreEqual(1, list.Count);
+ Assert.AreEqual("foo", list[0]);
+ }
+
+ [Test]
+ public void Add_Sequence()
+ {
+ var list = new RepeatedField<string>();
+ list.Add(new[] { "foo", "bar" });
+ Assert.AreEqual(2, list.Count);
+ Assert.AreEqual("foo", list[0]);
+ Assert.AreEqual("bar", list[1]);
+ }
+
+ [Test]
+ public void AddRange_SlowPath()
+ {
+ var list = new RepeatedField<string>();
+ list.AddRange(new[] { "foo", "bar" }.Select(x => x));
+ Assert.AreEqual(2, list.Count);
+ Assert.AreEqual("foo", list[0]);
+ Assert.AreEqual("bar", list[1]);
+ }
+
+ [Test]
+ public void AddRange_SlowPath_NullsProhibited_ReferenceType()
+ {
+ var list = new RepeatedField<string>();
+ // It's okay for this to throw ArgumentNullException if necessary.
+ // It's not ideal, but not awful.
+ Assert.Catch<ArgumentException>(() => list.AddRange(new[] { "foo", null }.Select(x => x)));
+ }
+
+ [Test]
+ public void AddRange_SlowPath_NullsProhibited_NullableValueType()
+ {
+ var list = new RepeatedField<int?>();
+ // It's okay for this to throw ArgumentNullException if necessary.
+ // It's not ideal, but not awful.
+ Assert.Catch<ArgumentException>(() => list.AddRange(new[] { 20, (int?)null }.Select(x => x)));
+ }
+
+ [Test]
+ public void AddRange_Optimized_NonNullableValueType()
+ {
+ var list = new RepeatedField<int>();
+ list.AddRange(new List<int> { 20, 30 });
+ Assert.AreEqual(2, list.Count);
+ Assert.AreEqual(20, list[0]);
+ Assert.AreEqual(30, list[1]);
+ }
+
+ [Test]
+ public void AddRange_Optimized_ReferenceType()
+ {
+ var list = new RepeatedField<string>();
+ list.AddRange(new List<string> { "foo", "bar" });
+ Assert.AreEqual(2, list.Count);
+ Assert.AreEqual("foo", list[0]);
+ Assert.AreEqual("bar", list[1]);
+ }
+
+ [Test]
+ public void AddRange_Optimized_NullableValueType()
+ {
+ var list = new RepeatedField<int?>();
+ list.AddRange(new List<int?> { 20, 30 });
+ Assert.AreEqual(2, list.Count);
+ Assert.AreEqual((int?) 20, list[0]);
+ Assert.AreEqual((int?) 30, list[1]);
+ }
+
+ [Test]
+ public void AddRange_Optimized_NullsProhibited_ReferenceType()
+ {
+ // We don't just trust that a collection with a nullable element type doesn't contain nulls
+ var list = new RepeatedField<string>();
+ // It's okay for this to throw ArgumentNullException if necessary.
+ // It's not ideal, but not awful.
+ Assert.Catch<ArgumentException>(() => list.AddRange(new List<string> { "foo", null }));
+ }
+
+ [Test]
+ public void AddRange_Optimized_NullsProhibited_NullableValueType()
+ {
+ // We don't just trust that a collection with a nullable element type doesn't contain nulls
+ var list = new RepeatedField<int?>();
+ // It's okay for this to throw ArgumentNullException if necessary.
+ // It's not ideal, but not awful.
+ Assert.Catch<ArgumentException>(() => list.AddRange(new List<int?> { 20, null }));
+ }
+
+ [Test]
+ public void AddRange_AlreadyNotEmpty()
+ {
+ var list = new RepeatedField<int> { 1, 2, 3 };
+ list.AddRange(new List<int> { 4, 5, 6 });
+ CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5, 6 }, list);
+ }
+
+ [Test]
+ public void AddRange_RepeatedField()
+ {
+ var list = new RepeatedField<string> { "original" };
+ list.AddRange(new RepeatedField<string> { "foo", "bar" });
+ Assert.AreEqual(3, list.Count);
+ Assert.AreEqual("original", list[0]);
+ Assert.AreEqual("foo", list[1]);
+ Assert.AreEqual("bar", list[2]);
+ }
+
+ [Test]
+ public void RemoveAt_Valid()
+ {
+ var list = new RepeatedField<string> { "first", "second", "third" };
+ list.RemoveAt(1);
+ CollectionAssert.AreEqual(new[] { "first", "third" }, list);
+ // Just check that these don't throw...
+ list.RemoveAt(list.Count - 1); // Now the count will be 1...
+ list.RemoveAt(0);
+ Assert.AreEqual(0, list.Count);
+ }
+
+ [Test]
+ public void RemoveAt_Invalid()
+ {
+ var list = new RepeatedField<string> { "first", "second", "third" };
+ Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(-1));
+ Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(3));
+ }
+
+ [Test]
+ public void Insert_Valid()
+ {
+ var list = new RepeatedField<string> { "first", "second" };
+ list.Insert(1, "middle");
+ CollectionAssert.AreEqual(new[] { "first", "middle", "second" }, list);
+ list.Insert(3, "end");
+ CollectionAssert.AreEqual(new[] { "first", "middle", "second", "end" }, list);
+ list.Insert(0, "start");
+ CollectionAssert.AreEqual(new[] { "start", "first", "middle", "second", "end" }, list);
+ }
+
+ [Test]
+ public void Insert_Invalid()
+ {
+ var list = new RepeatedField<string> { "first", "second" };
+ Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(-1, "foo"));
+ Assert.Throws<ArgumentOutOfRangeException>(() => list.Insert(3, "foo"));
+ Assert.Throws<ArgumentNullException>(() => list.Insert(0, null));
+ }
+
+ [Test]
+ public void Equals_RepeatedField()
+ {
+ var list = new RepeatedField<string> { "first", "second" };
+ Assert.IsFalse(list.Equals((RepeatedField<string>) null));
+ Assert.IsTrue(list.Equals(list));
+ Assert.IsFalse(list.Equals(new RepeatedField<string> { "first", "third" }));
+ Assert.IsFalse(list.Equals(new RepeatedField<string> { "first" }));
+ Assert.IsTrue(list.Equals(new RepeatedField<string> { "first", "second" }));
+ }
+
+ [Test]
+ public void Equals_Object()
+ {
+ var list = new RepeatedField<string> { "first", "second" };
+ Assert.IsFalse(list.Equals((object) null));
+ Assert.IsTrue(list.Equals((object) list));
+ Assert.IsFalse(list.Equals((object) new RepeatedField<string> { "first", "third" }));
+ Assert.IsFalse(list.Equals((object) new RepeatedField<string> { "first" }));
+ Assert.IsTrue(list.Equals((object) new RepeatedField<string> { "first", "second" }));
+ Assert.IsFalse(list.Equals(new object()));
+ }
+
+ [Test]
+ public void GetEnumerator_GenericInterface()
+ {
+ IEnumerable<string> list = new RepeatedField<string> { "first", "second" };
+ // Select gets rid of the optimizations in ToList...
+ CollectionAssert.AreEqual(new[] { "first", "second" }, list.Select(x => x).ToList());
+ }
+
+ [Test]
+ public void GetEnumerator_NonGenericInterface()
+ {
+ IEnumerable list = new RepeatedField<string> { "first", "second" };
+ CollectionAssert.AreEqual(new[] { "first", "second" }, list.Cast<object>().ToList());
+ }
+
+ [Test]
+ public void CopyTo()
+ {
+ var list = new RepeatedField<string> { "first", "second" };
+ string[] stringArray = new string[4];
+ list.CopyTo(stringArray, 1);
+ CollectionAssert.AreEqual(new[] { null, "first", "second", null }, stringArray);
+ }
+
+ [Test]
+ public void Indexer_Get()
+ {
+ var list = new RepeatedField<string> { "first", "second" };
+ Assert.AreEqual("first", list[0]);
+ Assert.AreEqual("second", list[1]);
+ Assert.Throws<ArgumentOutOfRangeException>(() => list[-1].GetHashCode());
+ Assert.Throws<ArgumentOutOfRangeException>(() => list[2].GetHashCode());
+ }
+
+ [Test]
+ public void Indexer_Set()
+ {
+ var list = new RepeatedField<string> { "first", "second" };
+ list[0] = "changed";
+ Assert.AreEqual("changed", list[0]);
+ Assert.Throws<ArgumentNullException>(() => list[0] = null);
+ Assert.Throws<ArgumentOutOfRangeException>(() => list[-1] = "bad");
+ Assert.Throws<ArgumentOutOfRangeException>(() => list[2] = "bad");
+ }
+
+ [Test]
+ public void Clone_ReturnsMutable()
+ {
+ var list = new RepeatedField<int> { 0 };
+ var clone = list.Clone();
+ clone[0] = 1;
+ }
+
+ [Test]
+ public void Enumerator()
+ {
+ var list = new RepeatedField<string> { "first", "second" };
+ using (var enumerator = list.GetEnumerator())
+ {
+ Assert.IsTrue(enumerator.MoveNext());
+ Assert.AreEqual("first", enumerator.Current);
+ Assert.IsTrue(enumerator.MoveNext());
+ Assert.AreEqual("second", enumerator.Current);
+ Assert.IsFalse(enumerator.MoveNext());
+ Assert.IsFalse(enumerator.MoveNext());
+ }
+ }
+
+ [Test]
+ public void AddEntriesFrom_PackedInt32()
+ {
+ uint packedTag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ var length = CodedOutputStream.ComputeInt32Size(10)
+ + CodedOutputStream.ComputeInt32Size(999)
+ + CodedOutputStream.ComputeInt32Size(-1000);
+ output.WriteTag(packedTag);
+ output.WriteRawVarint32((uint) length);
+ output.WriteInt32(10);
+ output.WriteInt32(999);
+ output.WriteInt32(-1000);
+ output.Flush();
+ stream.Position = 0;
+
+ // Deliberately "expecting" a non-packed tag, but we detect that the data is
+ // actually packed.
+ uint nonPackedTag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
+ var field = new RepeatedField<int>();
+ var input = new CodedInputStream(stream);
+ input.AssertNextTag(packedTag);
+ field.AddEntriesFrom(input, FieldCodec.ForInt32(nonPackedTag));
+ CollectionAssert.AreEqual(new[] { 10, 999, -1000 }, field);
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ [Test]
+ public void AddEntriesFrom_NonPackedInt32()
+ {
+ uint nonPackedTag = WireFormat.MakeTag(10, WireFormat.WireType.Varint);
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ output.WriteTag(nonPackedTag);
+ output.WriteInt32(10);
+ output.WriteTag(nonPackedTag);
+ output.WriteInt32(999);
+ output.WriteTag(nonPackedTag);
+ output.WriteInt32(-1000); // Just for variety...
+ output.Flush();
+ stream.Position = 0;
+
+ // Deliberately "expecting" a packed tag, but we detect that the data is
+ // actually not packed.
+ uint packedTag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
+ var field = new RepeatedField<int>();
+ var input = new CodedInputStream(stream);
+ input.AssertNextTag(nonPackedTag);
+ field.AddEntriesFrom(input, FieldCodec.ForInt32(packedTag));
+ CollectionAssert.AreEqual(new[] { 10, 999, -1000 }, field);
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ [Test]
+ public void AddEntriesFrom_String()
+ {
+ uint tag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ output.WriteTag(tag);
+ output.WriteString("Foo");
+ output.WriteTag(tag);
+ output.WriteString("");
+ output.WriteTag(tag);
+ output.WriteString("Bar");
+ output.Flush();
+ stream.Position = 0;
+
+ var field = new RepeatedField<string>();
+ var input = new CodedInputStream(stream);
+ input.AssertNextTag(tag);
+ field.AddEntriesFrom(input, FieldCodec.ForString(tag));
+ CollectionAssert.AreEqual(new[] { "Foo", "", "Bar" }, field);
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ [Test]
+ public void AddEntriesFrom_Message()
+ {
+ var message1 = new ForeignMessage { C = 2000 };
+ var message2 = new ForeignMessage { C = -250 };
+
+ uint tag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ output.WriteTag(tag);
+ output.WriteMessage(message1);
+ output.WriteTag(tag);
+ output.WriteMessage(message2);
+ output.Flush();
+ stream.Position = 0;
+
+ var field = new RepeatedField<ForeignMessage>();
+ var input = new CodedInputStream(stream);
+ input.AssertNextTag(tag);
+ field.AddEntriesFrom(input, FieldCodec.ForMessage(tag, ForeignMessage.Parser));
+ CollectionAssert.AreEqual(new[] { message1, message2}, field);
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ [Test]
+ public void WriteTo_PackedInt32()
+ {
+ uint tag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
+ var field = new RepeatedField<int> { 10, 1000, 1000000 };
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ field.WriteTo(output, FieldCodec.ForInt32(tag));
+ output.Flush();
+ stream.Position = 0;
+
+ var input = new CodedInputStream(stream);
+ input.AssertNextTag(tag);
+ var length = input.ReadLength();
+ Assert.AreEqual(10, input.ReadInt32());
+ Assert.AreEqual(1000, input.ReadInt32());
+ Assert.AreEqual(1000000, input.ReadInt32());
+ Assert.IsTrue(input.IsAtEnd);
+ Assert.AreEqual(1 + CodedOutputStream.ComputeLengthSize(length) + length, stream.Length);
+ }
+
+ [Test]
+ public void WriteTo_NonPackedInt32()
+ {
+ uint tag = WireFormat.MakeTag(10, WireFormat.WireType.Varint);
+ var field = new RepeatedField<int> { 10, 1000, 1000000};
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ field.WriteTo(output, FieldCodec.ForInt32(tag));
+ output.Flush();
+ stream.Position = 0;
+
+ var input = new CodedInputStream(stream);
+ input.AssertNextTag(tag);
+ Assert.AreEqual(10, input.ReadInt32());
+ input.AssertNextTag(tag);
+ Assert.AreEqual(1000, input.ReadInt32());
+ input.AssertNextTag(tag);
+ Assert.AreEqual(1000000, input.ReadInt32());
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ [Test]
+ public void WriteTo_String()
+ {
+ uint tag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
+ var field = new RepeatedField<string> { "Foo", "", "Bar" };
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ field.WriteTo(output, FieldCodec.ForString(tag));
+ output.Flush();
+ stream.Position = 0;
+
+ var input = new CodedInputStream(stream);
+ input.AssertNextTag(tag);
+ Assert.AreEqual("Foo", input.ReadString());
+ input.AssertNextTag(tag);
+ Assert.AreEqual("", input.ReadString());
+ input.AssertNextTag(tag);
+ Assert.AreEqual("Bar", input.ReadString());
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ [Test]
+ public void WriteTo_Message()
+ {
+ var message1 = new ForeignMessage { C = 20 };
+ var message2 = new ForeignMessage { C = 25 };
+ uint tag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
+ var field = new RepeatedField<ForeignMessage> { message1, message2 };
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ field.WriteTo(output, FieldCodec.ForMessage(tag, ForeignMessage.Parser));
+ output.Flush();
+ stream.Position = 0;
+
+ var input = new CodedInputStream(stream);
+ input.AssertNextTag(tag);
+ Assert.AreEqual(message1, input.ReadMessage(ForeignMessage.Parser));
+ input.AssertNextTag(tag);
+ Assert.AreEqual(message2, input.ReadMessage(ForeignMessage.Parser));
+ Assert.IsTrue(input.IsAtEnd);
+ }
+
+ [Test]
+ public void CalculateSize_VariableSizeNonPacked()
+ {
+ var list = new RepeatedField<int> { 1, 500, 1 };
+ var tag = WireFormat.MakeTag(1, WireFormat.WireType.Varint);
+ // 2 bytes for the first entry, 3 bytes for the second, 2 bytes for the third
+ Assert.AreEqual(7, list.CalculateSize(FieldCodec.ForInt32(tag)));
+ }
+
+ [Test]
+ public void CalculateSize_FixedSizeNonPacked()
+ {
+ var list = new RepeatedField<int> { 1, 500, 1 };
+ var tag = WireFormat.MakeTag(1, WireFormat.WireType.Fixed32);
+ // 5 bytes for the each entry
+ Assert.AreEqual(15, list.CalculateSize(FieldCodec.ForSFixed32(tag)));
+ }
+
+ [Test]
+ public void CalculateSize_VariableSizePacked()
+ {
+ var list = new RepeatedField<int> { 1, 500, 1};
+ var tag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited);
+ // 1 byte for the tag, 1 byte for the length,
+ // 1 byte for the first entry, 2 bytes for the second, 1 byte for the third
+ Assert.AreEqual(6, list.CalculateSize(FieldCodec.ForInt32(tag)));
+ }
+
+ [Test]
+ public void CalculateSize_FixedSizePacked()
+ {
+ var list = new RepeatedField<int> { 1, 500, 1 };
+ var tag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited);
+ // 1 byte for the tag, 1 byte for the length, 4 bytes per entry
+ Assert.AreEqual(14, list.CalculateSize(FieldCodec.ForSFixed32(tag)));
+ }
+
+ [Test]
+ public void TestNegativeEnumArray()
+ {
+ int arraySize = 1 + 1 + (11 * 5);
+ int msgSize = arraySize;
+ byte[] bytes = new byte[msgSize];
+ CodedOutputStream output = new CodedOutputStream(bytes);
+ uint tag = WireFormat.MakeTag(8, WireFormat.WireType.Varint);
+ for (int i = 0; i >= -5; i--)
+ {
+ output.WriteTag(tag);
+ output.WriteEnum(i);
+ }
+
+ Assert.AreEqual(0, output.SpaceLeft);
+
+ CodedInputStream input = new CodedInputStream(bytes);
+ tag = input.ReadTag();
+
+ RepeatedField<SampleEnum> values = new RepeatedField<SampleEnum>();
+ values.AddEntriesFrom(input, FieldCodec.ForEnum(tag, x => (int)x, x => (SampleEnum)x));
+
+ Assert.AreEqual(6, values.Count);
+ Assert.AreEqual(SampleEnum.None, values[0]);
+ Assert.AreEqual(((SampleEnum)(-1)), values[1]);
+ Assert.AreEqual(SampleEnum.NegativeValue, values[2]);
+ Assert.AreEqual(((SampleEnum)(-3)), values[3]);
+ Assert.AreEqual(((SampleEnum)(-4)), values[4]);
+ Assert.AreEqual(((SampleEnum)(-5)), values[5]);
+ }
+
+
+ [Test]
+ public void TestNegativeEnumPackedArray()
+ {
+ int arraySize = 1 + (10 * 5);
+ int msgSize = 1 + 1 + arraySize;
+ byte[] bytes = new byte[msgSize];
+ CodedOutputStream output = new CodedOutputStream(bytes);
+ // Length-delimited to show we want the packed representation
+ uint tag = WireFormat.MakeTag(8, WireFormat.WireType.LengthDelimited);
+ output.WriteTag(tag);
+ int size = 0;
+ for (int i = 0; i >= -5; i--)
+ {
+ size += CodedOutputStream.ComputeEnumSize(i);
+ }
+ output.WriteRawVarint32((uint)size);
+ for (int i = 0; i >= -5; i--)
+ {
+ output.WriteEnum(i);
+ }
+ Assert.AreEqual(0, output.SpaceLeft);
+
+ CodedInputStream input = new CodedInputStream(bytes);
+ tag = input.ReadTag();
+
+ RepeatedField<SampleEnum> values = new RepeatedField<SampleEnum>();
+ values.AddEntriesFrom(input, FieldCodec.ForEnum(tag, x => (int)x, x => (SampleEnum)x));
+
+ Assert.AreEqual(6, values.Count);
+ Assert.AreEqual(SampleEnum.None, values[0]);
+ Assert.AreEqual(((SampleEnum)(-1)), values[1]);
+ Assert.AreEqual(SampleEnum.NegativeValue, values[2]);
+ Assert.AreEqual(((SampleEnum)(-3)), values[3]);
+ Assert.AreEqual(((SampleEnum)(-4)), values[4]);
+ Assert.AreEqual(((SampleEnum)(-5)), values[5]);
+ }
+
+ // Fairly perfunctory tests for the non-generic IList implementation
+ [Test]
+ public void IList_Indexer()
+ {
+ var field = new RepeatedField<string> { "first", "second" };
+ IList list = field;
+ Assert.AreEqual("first", list[0]);
+ list[1] = "changed";
+ Assert.AreEqual("changed", field[1]);
+ }
+
+ [Test]
+ public void IList_Contains()
+ {
+ IList list = new RepeatedField<string> { "first", "second" };
+ Assert.IsTrue(list.Contains("second"));
+ Assert.IsFalse(list.Contains("third"));
+ Assert.IsFalse(list.Contains(new object()));
+ }
+
+ [Test]
+ public void IList_Add()
+ {
+ IList list = new RepeatedField<string> { "first", "second" };
+ list.Add("third");
+ CollectionAssert.AreEqual(new[] { "first", "second", "third" }, list);
+ }
+
+ [Test]
+ public void IList_Remove()
+ {
+ IList list = new RepeatedField<string> { "first", "second" };
+ list.Remove("third"); // No-op, no exception
+ list.Remove(new object()); // No-op, no exception
+ list.Remove("first");
+ CollectionAssert.AreEqual(new[] { "second" }, list);
+ }
+
+ [Test]
+ public void IList_IsFixedSize()
+ {
+ var field = new RepeatedField<string> { "first", "second" };
+ IList list = field;
+ Assert.IsFalse(list.IsFixedSize);
+ }
+
+ [Test]
+ public void IList_IndexOf()
+ {
+ IList list = new RepeatedField<string> { "first", "second" };
+ Assert.AreEqual(1, list.IndexOf("second"));
+ Assert.AreEqual(-1, list.IndexOf("third"));
+ Assert.AreEqual(-1, list.IndexOf(new object()));
+ }
+
+ [Test]
+ public void IList_SyncRoot()
+ {
+ IList list = new RepeatedField<string> { "first", "second" };
+ Assert.AreSame(list, list.SyncRoot);
+ }
+
+ [Test]
+ public void IList_CopyTo()
+ {
+ IList list = new RepeatedField<string> { "first", "second" };
+ string[] stringArray = new string[4];
+ list.CopyTo(stringArray, 1);
+ CollectionAssert.AreEqual(new[] { null, "first", "second", null }, stringArray);
+
+ object[] objectArray = new object[4];
+ list.CopyTo(objectArray, 1);
+ CollectionAssert.AreEqual(new[] { null, "first", "second", null }, objectArray);
+
+ Assert.Throws<ArrayTypeMismatchException>(() => list.CopyTo(new StringBuilder[4], 1));
+ Assert.Throws<ArrayTypeMismatchException>(() => list.CopyTo(new int[4], 1));
+ }
+
+ [Test]
+ public void IList_IsSynchronized()
+ {
+ IList list = new RepeatedField<string> { "first", "second" };
+ Assert.IsFalse(list.IsSynchronized);
+ }
+
+ [Test]
+ public void IList_Insert()
+ {
+ IList list = new RepeatedField<string> { "first", "second" };
+ list.Insert(1, "middle");
+ CollectionAssert.AreEqual(new[] { "first", "middle", "second" }, list);
+ }
+
+ [Test]
+ public void ToString_Integers()
+ {
+ var list = new RepeatedField<int> { 5, 10, 20 };
+ var text = list.ToString();
+ Assert.AreEqual("[ 5, 10, 20 ]", text);
+ }
+
+ [Test]
+ public void ToString_Strings()
+ {
+ var list = new RepeatedField<string> { "x", "y", "z" };
+ var text = list.ToString();
+ Assert.AreEqual("[ \"x\", \"y\", \"z\" ]", text);
+ }
+
+ [Test]
+ public void ToString_Messages()
+ {
+ var list = new RepeatedField<TestAllTypes> { new TestAllTypes { SingleDouble = 1.5 }, new TestAllTypes { SingleInt32 = 10 } };
+ var text = list.ToString();
+ Assert.AreEqual("[ { \"singleDouble\": 1.5 }, { \"singleInt32\": 10 } ]", text);
+ }
+
+ [Test]
+ public void ToString_Empty()
+ {
+ var list = new RepeatedField<TestAllTypes> { };
+ var text = list.ToString();
+ Assert.AreEqual("[ ]", text);
+ }
+
+ [Test]
+ public void ToString_InvalidElementType()
+ {
+ var list = new RepeatedField<decimal> { 15m };
+ Assert.Throws<ArgumentException>(() => list.ToString());
+ }
+
+ [Test]
+ public void ToString_Timestamp()
+ {
+ var list = new RepeatedField<Timestamp> { Timestamp.FromDateTime(new DateTime(2015, 10, 1, 12, 34, 56, DateTimeKind.Utc)) };
+ var text = list.ToString();
+ Assert.AreEqual("[ \"2015-10-01T12:34:56Z\" ]", text);
+ }
+
+ [Test]
+ public void ToString_Struct()
+ {
+ var message = new Struct { Fields = { { "foo", new Value { NumberValue = 20 } } } };
+ var list = new RepeatedField<Struct> { message };
+ var text = list.ToString();
+ Assert.AreEqual(text, "[ { \"foo\": 20 } ]", message.ToString());
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/PropertyInfoExtensionsTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/PropertyInfoExtensionsTest.cs
new file mode 100644
index 0000000000..df23a09cd4
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/PropertyInfoExtensionsTest.cs
@@ -0,0 +1,98 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using NUnit.Framework;
+using System.Reflection;
+
+namespace Google.Protobuf.Compatibility
+{
+ public class PropertyInfoExtensionsTest
+ {
+ public string PublicReadWrite { get; set; }
+ private string PrivateReadWrite { get; set; }
+ public string PublicReadPrivateWrite { get; private set; }
+ public string PrivateReadPublicWrite { private get; set; }
+ public string PublicReadOnly { get { return null; } }
+ private string PrivateReadOnly { get { return null; } }
+ public string PublicWriteOnly { set { } }
+ private string PrivateWriteOnly { set { } }
+
+ [Test]
+ [TestCase("PublicReadWrite")]
+ [TestCase("PublicReadPrivateWrite")]
+ [TestCase("PublicReadOnly")]
+ public void GetGetMethod_Success(string name)
+ {
+ var propertyInfo = typeof(PropertyInfoExtensionsTest)
+ .GetProperty(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
+ Assert.IsNotNull(PropertyInfoExtensions.GetGetMethod(propertyInfo));
+ }
+
+ [Test]
+ [TestCase("PrivateReadWrite")]
+ [TestCase("PrivateReadPublicWrite")]
+ [TestCase("PrivateReadOnly")]
+ [TestCase("PublicWriteOnly")]
+ [TestCase("PrivateWriteOnly")]
+ public void GetGetMethod_NoAccessibleGetter(string name)
+ {
+ var propertyInfo = typeof(PropertyInfoExtensionsTest)
+ .GetProperty(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
+ Assert.IsNull(PropertyInfoExtensions.GetGetMethod(propertyInfo));
+ }
+
+ [Test]
+ [TestCase("PublicReadWrite")]
+ [TestCase("PrivateReadPublicWrite")]
+ [TestCase("PublicWriteOnly")]
+ public void GetSetMethod_Success(string name)
+ {
+ var propertyInfo = typeof(PropertyInfoExtensionsTest)
+ .GetProperty(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
+ Assert.IsNotNull(PropertyInfoExtensions.GetSetMethod(propertyInfo));
+ }
+
+ [Test]
+ [TestCase("PublicReadPrivateWrite")]
+ [TestCase("PrivateReadWrite")]
+ [TestCase("PrivateReadOnly")]
+ [TestCase("PublicReadOnly")]
+ [TestCase("PrivateWriteOnly")]
+ public void GetSetMethod_NoAccessibleGetter(string name)
+ {
+ var propertyInfo = typeof(PropertyInfoExtensionsTest)
+ .GetProperty(name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
+ Assert.IsNull(PropertyInfoExtensions.GetSetMethod(propertyInfo));
+ }
+ }
+
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/StreamExtensionsTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/StreamExtensionsTest.cs
new file mode 100755
index 0000000000..48c0725fa6
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/StreamExtensionsTest.cs
@@ -0,0 +1,67 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+#if NET35
+using System;
+using System.IO;
+using NUnit.Framework;
+using Google.Protobuf.Compatibility;
+
+namespace Google.Protobuf.Test.Compatibility
+{
+ public class StreamExtensionsTest
+ {
+ [Test]
+ public void CopyToNullArgument()
+ {
+ var memoryStream = new MemoryStream();
+ Assert.Throws<ArgumentNullException>(() => memoryStream.CopyTo(null));
+ }
+
+ [Test]
+ public void CopyToTest()
+ {
+ byte[] bytesToStream = new byte[] { 0x31, 0x08, 0xFF, 0x00 };
+ Stream source = new MemoryStream(bytesToStream);
+ Stream destination = new MemoryStream((int)source.Length);
+ source.CopyTo(destination);
+ destination.Seek(0, SeekOrigin.Begin);
+
+ Assert.AreEqual(0x31, destination.ReadByte());
+ Assert.AreEqual(0x08, destination.ReadByte());
+ Assert.AreEqual(0xFF, destination.ReadByte());
+ Assert.AreEqual(0x00, destination.ReadByte());
+ Assert.AreEqual(-1, destination.ReadByte());
+ }
+ }
+}
+#endif
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs
new file mode 100755
index 0000000000..abbe3c955f
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Compatibility/TypeExtensionsTest.cs
@@ -0,0 +1,117 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+using NUnit.Framework;
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+
+#if !NET35
+namespace Google.Protobuf.Compatibility
+{
+ public class TypeExtensionsTest
+ {
+ public class DerivedList : List<string> { }
+ public string PublicProperty { get; set; }
+ private string PrivateProperty { get; set; }
+
+ public void PublicMethod()
+ {
+ }
+
+ private void PrivateMethod()
+ {
+ }
+
+ [Test]
+ [TestCase(typeof(object), typeof(string), true)]
+ [TestCase(typeof(object), typeof(int), true)]
+ [TestCase(typeof(string), typeof(string), true)]
+ [TestCase(typeof(string), typeof(object), false)]
+ [TestCase(typeof(string), typeof(int), false)]
+ [TestCase(typeof(int), typeof(int), true)]
+ [TestCase(typeof(ValueType), typeof(int), true)]
+ [TestCase(typeof(long), typeof(int), false)] //
+ public void IsAssignableFrom(Type target, Type argument, bool expected)
+ {
+ Assert.AreEqual(expected, TypeExtensions.IsAssignableFrom(target, argument));
+ }
+
+ [Test]
+ [TestCase(typeof(DerivedList), "Count")] // Go up the type hierarchy
+ [TestCase(typeof(List<string>), "Count")]
+ [TestCase(typeof(List<>), "Count")]
+ [TestCase(typeof(TypeExtensionsTest), "PublicProperty")]
+ public void GetProperty_Success(Type type, string name)
+ {
+ var property = TypeExtensions.GetProperty(type, name);
+ Assert.IsNotNull(property);
+ Assert.AreEqual(name, property.Name);
+ }
+
+ [Test]
+ [TestCase(typeof(TypeExtensionsTest), "PrivateProperty")]
+ [TestCase(typeof(TypeExtensionsTest), "Garbage")]
+ public void GetProperty_NoSuchProperty(Type type, string name)
+ {
+ var property = TypeExtensions.GetProperty(type, name);
+ Assert.IsNull(property);
+ }
+
+ [Test]
+ [TestCase(typeof(DerivedList), "RemoveAt")] // Go up the type hierarchy
+ [TestCase(typeof(List<>), "RemoveAt")]
+ [TestCase(typeof(TypeExtensionsTest), "PublicMethod")]
+ public void GetMethod_Success(Type type, string name)
+ {
+ var method = TypeExtensions.GetMethod(type, name);
+ Assert.IsNotNull(method);
+ Assert.AreEqual(name, method.Name);
+ }
+
+ [Test]
+ [TestCase(typeof(TypeExtensionsTest), "PrivateMethod")]
+ [TestCase(typeof(TypeExtensionsTest), "GarbageMethod")]
+ public void GetMethod_NoSuchMethod(Type type, string name)
+ {
+ var method = TypeExtensions.GetMethod(type, name);
+ Assert.IsNull(method);
+ }
+
+ [Test]
+ [TestCase(typeof(List<string>), "IndexOf")]
+ public void GetMethod_Ambiguous(Type type, string name)
+ {
+ Assert.Throws<AmbiguousMatchException>(() => TypeExtensions.GetMethod(type, name));
+ }
+ }
+}
+#endif
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/DeprecatedMemberTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/DeprecatedMemberTest.cs
new file mode 100644
index 0000000000..34d5b9f98c
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/DeprecatedMemberTest.cs
@@ -0,0 +1,55 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.Reflection;
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+
+namespace Google.Protobuf
+{
+ public class DeprecatedMemberTest
+ {
+ private static void AssertIsDeprecated(MemberInfo member)
+ {
+ Assert.NotNull(member);
+ Assert.IsTrue(member.IsDefined(typeof(ObsoleteAttribute), false), "Member not obsolete: " + member);
+ }
+
+ [Test]
+ public void TestDepreatedPrimitiveValue()
+ {
+ AssertIsDeprecated(typeof(TestDeprecatedFields).GetProperty("DeprecatedInt32"));
+ }
+
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/EqualityTester.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/EqualityTester.cs
new file mode 100644
index 0000000000..a669baba17
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/EqualityTester.cs
@@ -0,0 +1,64 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using NUnit.Framework;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Helper methods when testing equality. NUnit's Assert.AreEqual and
+ /// Assert.AreNotEqual methods try to be clever with collections, which can
+ /// be annoying...
+ /// </summary>
+ internal static class EqualityTester
+ {
+ public static void AssertEquality<T>(T first, T second) where T : IEquatable<T>
+ {
+ Assert.IsTrue(first.Equals(second));
+ Assert.IsTrue(first.Equals((object) second));
+ Assert.AreEqual(first.GetHashCode(), second.GetHashCode());
+ }
+
+ public static void AssertInequality<T>(T first, T second) where T : IEquatable<T>
+ {
+ Assert.IsFalse(first.Equals(second));
+ Assert.IsFalse(first.Equals((object) second));
+ // While this isn't a requirement, the chances of this test failing due to
+ // coincidence rather than a bug are very small.
+ if (first != null && second != null)
+ {
+ Assert.AreNotEqual(first.GetHashCode(), second.GetHashCode());
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/FieldCodecTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/FieldCodecTest.cs
new file mode 100755
index 0000000000..77641163c0
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/FieldCodecTest.cs
@@ -0,0 +1,199 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System.Collections.Generic;
+using System.IO;
+using System.Reflection;
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+
+namespace Google.Protobuf
+{
+ public class FieldCodecTest
+ {
+#pragma warning disable 0414 // Used by tests via reflection - do not remove!
+ private static readonly List<ICodecTestData> Codecs = new List<ICodecTestData>
+ {
+ new FieldCodecTestData<bool>(FieldCodec.ForBool(100), true, "Bool"),
+ new FieldCodecTestData<string>(FieldCodec.ForString(100), "sample", "String"),
+ new FieldCodecTestData<ByteString>(FieldCodec.ForBytes(100), ByteString.CopyFrom(1, 2, 3), "Bytes"),
+ new FieldCodecTestData<int>(FieldCodec.ForInt32(100), -1000, "Int32"),
+ new FieldCodecTestData<int>(FieldCodec.ForSInt32(100), -1000, "SInt32"),
+ new FieldCodecTestData<int>(FieldCodec.ForSFixed32(100), -1000, "SFixed32"),
+ new FieldCodecTestData<uint>(FieldCodec.ForUInt32(100), 1234, "UInt32"),
+ new FieldCodecTestData<uint>(FieldCodec.ForFixed32(100), 1234, "Fixed32"),
+ new FieldCodecTestData<long>(FieldCodec.ForInt64(100), -1000, "Int64"),
+ new FieldCodecTestData<long>(FieldCodec.ForSInt64(100), -1000, "SInt64"),
+ new FieldCodecTestData<long>(FieldCodec.ForSFixed64(100), -1000, "SFixed64"),
+ new FieldCodecTestData<ulong>(FieldCodec.ForUInt64(100), 1234, "UInt64"),
+ new FieldCodecTestData<ulong>(FieldCodec.ForFixed64(100), 1234, "Fixed64"),
+ new FieldCodecTestData<float>(FieldCodec.ForFloat(100), 1234.5f, "Float"),
+ new FieldCodecTestData<double>(FieldCodec.ForDouble(100), 1234567890.5d, "Double"),
+ new FieldCodecTestData<ForeignEnum>(
+ FieldCodec.ForEnum(100, t => (int) t, t => (ForeignEnum) t), ForeignEnum.ForeignBaz, "Enum"),
+ new FieldCodecTestData<ForeignMessage>(
+ FieldCodec.ForMessage(100, ForeignMessage.Parser), new ForeignMessage { C = 10 }, "Message"),
+ };
+#pragma warning restore 0414
+
+ [Test, TestCaseSource("Codecs")]
+ public void RoundTripWithTag(ICodecTestData codec)
+ {
+ codec.TestRoundTripWithTag();
+ }
+
+ [Test, TestCaseSource("Codecs")]
+ public void RoundTripRaw(ICodecTestData codec)
+ {
+ codec.TestRoundTripRaw();
+ }
+
+ [Test, TestCaseSource("Codecs")]
+ public void CalculateSize(ICodecTestData codec)
+ {
+ codec.TestCalculateSizeWithTag();
+ }
+
+ [Test, TestCaseSource("Codecs")]
+ public void DefaultValue(ICodecTestData codec)
+ {
+ codec.TestDefaultValue();
+ }
+
+ [Test, TestCaseSource("Codecs")]
+ public void FixedSize(ICodecTestData codec)
+ {
+ codec.TestFixedSize();
+ }
+
+ // This is ugly, but it means we can have a non-generic interface.
+ // It feels like NUnit should support this better, but I don't know
+ // of any better ways right now.
+ public interface ICodecTestData
+ {
+ void TestRoundTripRaw();
+ void TestRoundTripWithTag();
+ void TestCalculateSizeWithTag();
+ void TestDefaultValue();
+ void TestFixedSize();
+ }
+
+ public class FieldCodecTestData<T> : ICodecTestData
+ {
+ private readonly FieldCodec<T> codec;
+ private readonly T sampleValue;
+ private readonly string name;
+
+ public FieldCodecTestData(FieldCodec<T> codec, T sampleValue, string name)
+ {
+ this.codec = codec;
+ this.sampleValue = sampleValue;
+ this.name = name;
+ }
+
+ public void TestRoundTripRaw()
+ {
+ var stream = new MemoryStream();
+ var codedOutput = new CodedOutputStream(stream);
+ codec.ValueWriter(codedOutput, sampleValue);
+ codedOutput.Flush();
+ stream.Position = 0;
+ var codedInput = new CodedInputStream(stream);
+ Assert.AreEqual(sampleValue, codec.ValueReader(codedInput));
+ Assert.IsTrue(codedInput.IsAtEnd);
+ }
+
+ public void TestRoundTripWithTag()
+ {
+ var stream = new MemoryStream();
+ var codedOutput = new CodedOutputStream(stream);
+ codec.WriteTagAndValue(codedOutput, sampleValue);
+ codedOutput.Flush();
+ stream.Position = 0;
+ var codedInput = new CodedInputStream(stream);
+ codedInput.AssertNextTag(codec.Tag);
+ Assert.AreEqual(sampleValue, codec.Read(codedInput));
+ Assert.IsTrue(codedInput.IsAtEnd);
+ }
+
+ public void TestCalculateSizeWithTag()
+ {
+ var stream = new MemoryStream();
+ var codedOutput = new CodedOutputStream(stream);
+ codec.WriteTagAndValue(codedOutput, sampleValue);
+ codedOutput.Flush();
+ Assert.AreEqual(stream.Position, codec.CalculateSizeWithTag(sampleValue));
+ }
+
+ public void TestDefaultValue()
+ {
+ // WriteTagAndValue ignores default values
+ var stream = new MemoryStream();
+ CodedOutputStream codedOutput;
+#if !NET35
+ codedOutput = new CodedOutputStream(stream);
+ codec.WriteTagAndValue(codedOutput, codec.DefaultValue);
+ codedOutput.Flush();
+ Assert.AreEqual(0, stream.Position);
+ Assert.AreEqual(0, codec.CalculateSizeWithTag(codec.DefaultValue));
+ if (typeof(T).GetTypeInfo().IsValueType)
+ {
+ Assert.AreEqual(default(T), codec.DefaultValue);
+ }
+#endif
+
+ // The plain ValueWriter/ValueReader delegates don't.
+ if (codec.DefaultValue != null) // This part isn't appropriate for message types.
+ {
+ codedOutput = new CodedOutputStream(stream);
+ codec.ValueWriter(codedOutput, codec.DefaultValue);
+ codedOutput.Flush();
+ Assert.AreNotEqual(0, stream.Position);
+ Assert.AreEqual(stream.Position, codec.ValueSizeCalculator(codec.DefaultValue));
+ stream.Position = 0;
+ var codedInput = new CodedInputStream(stream);
+ Assert.AreEqual(codec.DefaultValue, codec.ValueReader(codedInput));
+ }
+ }
+
+ public void TestFixedSize()
+ {
+ Assert.AreEqual(name.Contains("Fixed"), codec.FixedSize != 0);
+ }
+
+ public override string ToString()
+ {
+ return name;
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
new file mode 100644
index 0000000000..8b153d691f
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
@@ -0,0 +1,723 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.IO;
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using Google.Protobuf.WellKnownTypes;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Tests around the generated TestAllTypes message.
+ /// </summary>
+ public class GeneratedMessageTest
+ {
+ [Test]
+ public void EmptyMessageFieldDistinctFromMissingMessageField()
+ {
+ // This demonstrates what we're really interested in...
+ var message1 = new TestAllTypes { SingleForeignMessage = new ForeignMessage() };
+ var message2 = new TestAllTypes(); // SingleForeignMessage is null
+ EqualityTester.AssertInequality(message1, message2);
+ }
+
+ [Test]
+ public void DefaultValues()
+ {
+ // Single fields
+ var message = new TestAllTypes();
+ Assert.AreEqual(false, message.SingleBool);
+ Assert.AreEqual(ByteString.Empty, message.SingleBytes);
+ Assert.AreEqual(0.0, message.SingleDouble);
+ Assert.AreEqual(0, message.SingleFixed32);
+ Assert.AreEqual(0L, message.SingleFixed64);
+ Assert.AreEqual(0.0f, message.SingleFloat);
+ Assert.AreEqual(ForeignEnum.ForeignUnspecified, message.SingleForeignEnum);
+ Assert.IsNull(message.SingleForeignMessage);
+ Assert.AreEqual(ImportEnum.Unspecified, message.SingleImportEnum);
+ Assert.IsNull(message.SingleImportMessage);
+ Assert.AreEqual(0, message.SingleInt32);
+ Assert.AreEqual(0L, message.SingleInt64);
+ Assert.AreEqual(TestAllTypes.Types.NestedEnum.Unspecified, message.SingleNestedEnum);
+ Assert.IsNull(message.SingleNestedMessage);
+ Assert.IsNull(message.SinglePublicImportMessage);
+ Assert.AreEqual(0, message.SingleSfixed32);
+ Assert.AreEqual(0L, message.SingleSfixed64);
+ Assert.AreEqual(0, message.SingleSint32);
+ Assert.AreEqual(0L, message.SingleSint64);
+ Assert.AreEqual("", message.SingleString);
+ Assert.AreEqual(0U, message.SingleUint32);
+ Assert.AreEqual(0UL, message.SingleUint64);
+
+ // Repeated fields
+ Assert.AreEqual(0, message.RepeatedBool.Count);
+ Assert.AreEqual(0, message.RepeatedBytes.Count);
+ Assert.AreEqual(0, message.RepeatedDouble.Count);
+ Assert.AreEqual(0, message.RepeatedFixed32.Count);
+ Assert.AreEqual(0, message.RepeatedFixed64.Count);
+ Assert.AreEqual(0, message.RepeatedFloat.Count);
+ Assert.AreEqual(0, message.RepeatedForeignEnum.Count);
+ Assert.AreEqual(0, message.RepeatedForeignMessage.Count);
+ Assert.AreEqual(0, message.RepeatedImportEnum.Count);
+ Assert.AreEqual(0, message.RepeatedImportMessage.Count);
+ Assert.AreEqual(0, message.RepeatedNestedEnum.Count);
+ Assert.AreEqual(0, message.RepeatedNestedMessage.Count);
+ Assert.AreEqual(0, message.RepeatedPublicImportMessage.Count);
+ Assert.AreEqual(0, message.RepeatedSfixed32.Count);
+ Assert.AreEqual(0, message.RepeatedSfixed64.Count);
+ Assert.AreEqual(0, message.RepeatedSint32.Count);
+ Assert.AreEqual(0, message.RepeatedSint64.Count);
+ Assert.AreEqual(0, message.RepeatedString.Count);
+ Assert.AreEqual(0, message.RepeatedUint32.Count);
+ Assert.AreEqual(0, message.RepeatedUint64.Count);
+
+ // Oneof fields
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase);
+ Assert.AreEqual(0, message.OneofUint32);
+ Assert.AreEqual("", message.OneofString);
+ Assert.AreEqual(ByteString.Empty, message.OneofBytes);
+ Assert.IsNull(message.OneofNestedMessage);
+ }
+
+ [Test]
+ public void NullStringAndBytesRejected()
+ {
+ var message = new TestAllTypes();
+ Assert.Throws<ArgumentNullException>(() => message.SingleString = null);
+ Assert.Throws<ArgumentNullException>(() => message.OneofString = null);
+ Assert.Throws<ArgumentNullException>(() => message.SingleBytes = null);
+ Assert.Throws<ArgumentNullException>(() => message.OneofBytes = null);
+ }
+
+ [Test]
+ public void RoundTrip_Empty()
+ {
+ var message = new TestAllTypes();
+ // Without setting any values, there's nothing to write.
+ byte[] bytes = message.ToByteArray();
+ Assert.AreEqual(0, bytes.Length);
+ TestAllTypes parsed = TestAllTypes.Parser.ParseFrom(bytes);
+ Assert.AreEqual(message, parsed);
+ }
+
+ [Test]
+ public void RoundTrip_SingleValues()
+ {
+ var message = new TestAllTypes
+ {
+ SingleBool = true,
+ SingleBytes = ByteString.CopyFrom(1, 2, 3, 4),
+ SingleDouble = 23.5,
+ SingleFixed32 = 23,
+ SingleFixed64 = 1234567890123,
+ SingleFloat = 12.25f,
+ SingleForeignEnum = ForeignEnum.ForeignBar,
+ SingleForeignMessage = new ForeignMessage { C = 10 },
+ SingleImportEnum = ImportEnum.ImportBaz,
+ SingleImportMessage = new ImportMessage { D = 20 },
+ SingleInt32 = 100,
+ SingleInt64 = 3210987654321,
+ SingleNestedEnum = TestAllTypes.Types.NestedEnum.Foo,
+ SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 35 },
+ SinglePublicImportMessage = new PublicImportMessage { E = 54 },
+ SingleSfixed32 = -123,
+ SingleSfixed64 = -12345678901234,
+ SingleSint32 = -456,
+ SingleSint64 = -12345678901235,
+ SingleString = "test",
+ SingleUint32 = uint.MaxValue,
+ SingleUint64 = ulong.MaxValue
+ };
+
+ byte[] bytes = message.ToByteArray();
+ TestAllTypes parsed = TestAllTypes.Parser.ParseFrom(bytes);
+ Assert.AreEqual(message, parsed);
+ }
+
+ [Test]
+ public void RoundTrip_RepeatedValues()
+ {
+ var message = new TestAllTypes
+ {
+ RepeatedBool = { true, false },
+ RepeatedBytes = { ByteString.CopyFrom(1, 2, 3, 4), ByteString.CopyFrom(5, 6) },
+ RepeatedDouble = { -12.25, 23.5 },
+ RepeatedFixed32 = { uint.MaxValue, 23 },
+ RepeatedFixed64 = { ulong.MaxValue, 1234567890123 },
+ RepeatedFloat = { 100f, 12.25f },
+ RepeatedForeignEnum = { ForeignEnum.ForeignFoo, ForeignEnum.ForeignBar },
+ RepeatedForeignMessage = { new ForeignMessage(), new ForeignMessage { C = 10 } },
+ RepeatedImportEnum = { ImportEnum.ImportBaz, ImportEnum.Unspecified },
+ RepeatedImportMessage = { new ImportMessage { D = 20 }, new ImportMessage { D = 25 } },
+ RepeatedInt32 = { 100, 200 },
+ RepeatedInt64 = { 3210987654321, long.MaxValue },
+ RepeatedNestedEnum = { TestAllTypes.Types.NestedEnum.Foo, TestAllTypes.Types.NestedEnum.Neg },
+ RepeatedNestedMessage = { new TestAllTypes.Types.NestedMessage { Bb = 35 }, new TestAllTypes.Types.NestedMessage { Bb = 10 } },
+ RepeatedPublicImportMessage = { new PublicImportMessage { E = 54 }, new PublicImportMessage { E = -1 } },
+ RepeatedSfixed32 = { -123, 123 },
+ RepeatedSfixed64 = { -12345678901234, 12345678901234 },
+ RepeatedSint32 = { -456, 100 },
+ RepeatedSint64 = { -12345678901235, 123 },
+ RepeatedString = { "foo", "bar" },
+ RepeatedUint32 = { uint.MaxValue, uint.MinValue },
+ RepeatedUint64 = { ulong.MaxValue, uint.MinValue }
+ };
+
+ byte[] bytes = message.ToByteArray();
+ TestAllTypes parsed = TestAllTypes.Parser.ParseFrom(bytes);
+ Assert.AreEqual(message, parsed);
+ }
+
+ // Note that not every map within map_unittest_proto3 is used. They all go through very
+ // similar code paths. The fact that all maps are present is validation that we have codecs
+ // for every type.
+ [Test]
+ public void RoundTrip_Maps()
+ {
+ var message = new TestMap
+ {
+ MapBoolBool = {
+ { false, true },
+ { true, false }
+ },
+ MapInt32Bytes = {
+ { 5, ByteString.CopyFrom(6, 7, 8) },
+ { 25, ByteString.CopyFrom(1, 2, 3, 4, 5) },
+ { 10, ByteString.Empty }
+ },
+ MapInt32ForeignMessage = {
+ { 0, new ForeignMessage { C = 10 } },
+ { 5, new ForeignMessage() },
+ },
+ MapInt32Enum = {
+ { 1, MapEnum.Bar },
+ { 2000, MapEnum.Foo }
+ }
+ };
+
+ byte[] bytes = message.ToByteArray();
+ TestMap parsed = TestMap.Parser.ParseFrom(bytes);
+ Assert.AreEqual(message, parsed);
+ }
+
+ [Test]
+ public void MapWithEmptyEntry()
+ {
+ var message = new TestMap
+ {
+ MapInt32Bytes = { { 0, ByteString.Empty } }
+ };
+
+ byte[] bytes = message.ToByteArray();
+ Assert.AreEqual(2, bytes.Length); // Tag for field entry (1 byte), length of entry (0; 1 byte)
+
+ var parsed = TestMap.Parser.ParseFrom(bytes);
+ Assert.AreEqual(1, parsed.MapInt32Bytes.Count);
+ Assert.AreEqual(ByteString.Empty, parsed.MapInt32Bytes[0]);
+ }
+
+ [Test]
+ public void MapWithOnlyValue()
+ {
+ // Hand-craft the stream to contain a single entry with just a value.
+ var memoryStream = new MemoryStream();
+ var output = new CodedOutputStream(memoryStream);
+ output.WriteTag(TestMap.MapInt32ForeignMessageFieldNumber, WireFormat.WireType.LengthDelimited);
+ var nestedMessage = new ForeignMessage { C = 20 };
+ // Size of the entry (tag, size written by WriteMessage, data written by WriteMessage)
+ output.WriteLength(2 + nestedMessage.CalculateSize());
+ output.WriteTag(2, WireFormat.WireType.LengthDelimited);
+ output.WriteMessage(nestedMessage);
+ output.Flush();
+
+ var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());
+ Assert.AreEqual(nestedMessage, parsed.MapInt32ForeignMessage[0]);
+ }
+
+ [Test]
+ public void MapWithOnlyKey_PrimitiveValue()
+ {
+ // Hand-craft the stream to contain a single entry with just a key.
+ var memoryStream = new MemoryStream();
+ var output = new CodedOutputStream(memoryStream);
+ output.WriteTag(TestMap.MapInt32DoubleFieldNumber, WireFormat.WireType.LengthDelimited);
+ int key = 10;
+ output.WriteLength(1 + CodedOutputStream.ComputeInt32Size(key));
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key);
+ output.Flush();
+
+ var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());
+ Assert.AreEqual(0.0, parsed.MapInt32Double[key]);
+ }
+
+ [Test]
+ public void MapWithOnlyKey_MessageValue()
+ {
+ // Hand-craft the stream to contain a single entry with just a key.
+ var memoryStream = new MemoryStream();
+ var output = new CodedOutputStream(memoryStream);
+ output.WriteTag(TestMap.MapInt32ForeignMessageFieldNumber, WireFormat.WireType.LengthDelimited);
+ int key = 10;
+ output.WriteLength(1 + CodedOutputStream.ComputeInt32Size(key));
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key);
+ output.Flush();
+
+ var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());
+ Assert.AreEqual(new ForeignMessage(), parsed.MapInt32ForeignMessage[key]);
+ }
+
+ [Test]
+ public void MapIgnoresExtraFieldsWithinEntryMessages()
+ {
+ // Hand-craft the stream to contain a single entry with three fields
+ var memoryStream = new MemoryStream();
+ var output = new CodedOutputStream(memoryStream);
+
+ output.WriteTag(TestMap.MapInt32Int32FieldNumber, WireFormat.WireType.LengthDelimited);
+
+ var key = 10; // Field 1
+ var value = 20; // Field 2
+ var extra = 30; // Field 3
+
+ // Each field can be represented in a single byte, with a single byte tag.
+ // Total message size: 6 bytes.
+ output.WriteLength(6);
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key);
+ output.WriteTag(2, WireFormat.WireType.Varint);
+ output.WriteInt32(value);
+ output.WriteTag(3, WireFormat.WireType.Varint);
+ output.WriteInt32(extra);
+ output.Flush();
+
+ var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());
+ Assert.AreEqual(value, parsed.MapInt32Int32[key]);
+ }
+
+ [Test]
+ public void MapFieldOrderIsIrrelevant()
+ {
+ var memoryStream = new MemoryStream();
+ var output = new CodedOutputStream(memoryStream);
+
+ output.WriteTag(TestMap.MapInt32Int32FieldNumber, WireFormat.WireType.LengthDelimited);
+
+ var key = 10;
+ var value = 20;
+
+ // Each field can be represented in a single byte, with a single byte tag.
+ // Total message size: 4 bytes.
+ output.WriteLength(4);
+ output.WriteTag(2, WireFormat.WireType.Varint);
+ output.WriteInt32(value);
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key);
+ output.Flush();
+
+ var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());
+ Assert.AreEqual(value, parsed.MapInt32Int32[key]);
+ }
+
+ [Test]
+ public void MapNonContiguousEntries()
+ {
+ var memoryStream = new MemoryStream();
+ var output = new CodedOutputStream(memoryStream);
+
+ // Message structure:
+ // Entry for MapInt32Int32
+ // Entry for MapStringString
+ // Entry for MapInt32Int32
+
+ // First entry
+ var key1 = 10;
+ var value1 = 20;
+ output.WriteTag(TestMap.MapInt32Int32FieldNumber, WireFormat.WireType.LengthDelimited);
+ output.WriteLength(4);
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key1);
+ output.WriteTag(2, WireFormat.WireType.Varint);
+ output.WriteInt32(value1);
+
+ // Second entry
+ var key2 = "a";
+ var value2 = "b";
+ output.WriteTag(TestMap.MapStringStringFieldNumber, WireFormat.WireType.LengthDelimited);
+ output.WriteLength(6); // 3 bytes per entry: tag, size, character
+ output.WriteTag(1, WireFormat.WireType.LengthDelimited);
+ output.WriteString(key2);
+ output.WriteTag(2, WireFormat.WireType.LengthDelimited);
+ output.WriteString(value2);
+
+ // Third entry
+ var key3 = 15;
+ var value3 = 25;
+ output.WriteTag(TestMap.MapInt32Int32FieldNumber, WireFormat.WireType.LengthDelimited);
+ output.WriteLength(4);
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key3);
+ output.WriteTag(2, WireFormat.WireType.Varint);
+ output.WriteInt32(value3);
+
+ output.Flush();
+ var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());
+ var expected = new TestMap
+ {
+ MapInt32Int32 = { { key1, value1 }, { key3, value3 } },
+ MapStringString = { { key2, value2 } }
+ };
+ Assert.AreEqual(expected, parsed);
+ }
+
+ [Test]
+ public void DuplicateKeys_LastEntryWins()
+ {
+ var memoryStream = new MemoryStream();
+ var output = new CodedOutputStream(memoryStream);
+
+ var key = 10;
+ var value1 = 20;
+ var value2 = 30;
+
+ // First entry
+ output.WriteTag(TestMap.MapInt32Int32FieldNumber, WireFormat.WireType.LengthDelimited);
+ output.WriteLength(4);
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key);
+ output.WriteTag(2, WireFormat.WireType.Varint);
+ output.WriteInt32(value1);
+
+ // Second entry - same key, different value
+ output.WriteTag(TestMap.MapInt32Int32FieldNumber, WireFormat.WireType.LengthDelimited);
+ output.WriteLength(4);
+ output.WriteTag(1, WireFormat.WireType.Varint);
+ output.WriteInt32(key);
+ output.WriteTag(2, WireFormat.WireType.Varint);
+ output.WriteInt32(value2);
+ output.Flush();
+
+ var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());
+ Assert.AreEqual(value2, parsed.MapInt32Int32[key]);
+ }
+
+ [Test]
+ public void CloneSingleNonMessageValues()
+ {
+ var original = new TestAllTypes
+ {
+ SingleBool = true,
+ SingleBytes = ByteString.CopyFrom(1, 2, 3, 4),
+ SingleDouble = 23.5,
+ SingleFixed32 = 23,
+ SingleFixed64 = 1234567890123,
+ SingleFloat = 12.25f,
+ SingleInt32 = 100,
+ SingleInt64 = 3210987654321,
+ SingleNestedEnum = TestAllTypes.Types.NestedEnum.Foo,
+ SingleSfixed32 = -123,
+ SingleSfixed64 = -12345678901234,
+ SingleSint32 = -456,
+ SingleSint64 = -12345678901235,
+ SingleString = "test",
+ SingleUint32 = uint.MaxValue,
+ SingleUint64 = ulong.MaxValue
+ };
+ var clone = original.Clone();
+ Assert.AreNotSame(original, clone);
+ Assert.AreEqual(original, clone);
+ // Just as a single example
+ clone.SingleInt32 = 150;
+ Assert.AreNotEqual(original, clone);
+ }
+
+ [Test]
+ public void CloneRepeatedNonMessageValues()
+ {
+ var original = new TestAllTypes
+ {
+ RepeatedBool = { true, false },
+ RepeatedBytes = { ByteString.CopyFrom(1, 2, 3, 4), ByteString.CopyFrom(5, 6) },
+ RepeatedDouble = { -12.25, 23.5 },
+ RepeatedFixed32 = { uint.MaxValue, 23 },
+ RepeatedFixed64 = { ulong.MaxValue, 1234567890123 },
+ RepeatedFloat = { 100f, 12.25f },
+ RepeatedInt32 = { 100, 200 },
+ RepeatedInt64 = { 3210987654321, long.MaxValue },
+ RepeatedNestedEnum = { TestAllTypes.Types.NestedEnum.Foo, TestAllTypes.Types.NestedEnum.Neg },
+ RepeatedSfixed32 = { -123, 123 },
+ RepeatedSfixed64 = { -12345678901234, 12345678901234 },
+ RepeatedSint32 = { -456, 100 },
+ RepeatedSint64 = { -12345678901235, 123 },
+ RepeatedString = { "foo", "bar" },
+ RepeatedUint32 = { uint.MaxValue, uint.MinValue },
+ RepeatedUint64 = { ulong.MaxValue, uint.MinValue }
+ };
+
+ var clone = original.Clone();
+ Assert.AreNotSame(original, clone);
+ Assert.AreEqual(original, clone);
+ // Just as a single example
+ clone.RepeatedDouble.Add(25.5);
+ Assert.AreNotEqual(original, clone);
+ }
+
+ [Test]
+ public void CloneSingleMessageField()
+ {
+ var original = new TestAllTypes
+ {
+ SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 20 }
+ };
+
+ var clone = original.Clone();
+ Assert.AreNotSame(original, clone);
+ Assert.AreNotSame(original.SingleNestedMessage, clone.SingleNestedMessage);
+ Assert.AreEqual(original, clone);
+
+ clone.SingleNestedMessage.Bb = 30;
+ Assert.AreNotEqual(original, clone);
+ }
+
+ [Test]
+ public void CloneRepeatedMessageField()
+ {
+ var original = new TestAllTypes
+ {
+ RepeatedNestedMessage = { new TestAllTypes.Types.NestedMessage { Bb = 20 } }
+ };
+
+ var clone = original.Clone();
+ Assert.AreNotSame(original, clone);
+ Assert.AreNotSame(original.RepeatedNestedMessage, clone.RepeatedNestedMessage);
+ Assert.AreNotSame(original.RepeatedNestedMessage[0], clone.RepeatedNestedMessage[0]);
+ Assert.AreEqual(original, clone);
+
+ clone.RepeatedNestedMessage[0].Bb = 30;
+ Assert.AreNotEqual(original, clone);
+ }
+
+ [Test]
+ public void CloneOneofField()
+ {
+ var original = new TestAllTypes
+ {
+ OneofNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 20 }
+ };
+
+ var clone = original.Clone();
+ Assert.AreNotSame(original, clone);
+ Assert.AreEqual(original, clone);
+
+ // We should have cloned the message
+ original.OneofNestedMessage.Bb = 30;
+ Assert.AreNotEqual(original, clone);
+ }
+
+ [Test]
+ public void OneofProperties()
+ {
+ // Switch the oneof case between each of the different options, and check everything behaves
+ // as expected in each case.
+ var message = new TestAllTypes();
+ Assert.AreEqual("", message.OneofString);
+ Assert.AreEqual(0, message.OneofUint32);
+ Assert.AreEqual(ByteString.Empty, message.OneofBytes);
+ Assert.IsNull(message.OneofNestedMessage);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase);
+
+ message.OneofString = "sample";
+ Assert.AreEqual("sample", message.OneofString);
+ Assert.AreEqual(0, message.OneofUint32);
+ Assert.AreEqual(ByteString.Empty, message.OneofBytes);
+ Assert.IsNull(message.OneofNestedMessage);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofString, message.OneofFieldCase);
+
+ var bytes = ByteString.CopyFrom(1, 2, 3);
+ message.OneofBytes = bytes;
+ Assert.AreEqual("", message.OneofString);
+ Assert.AreEqual(0, message.OneofUint32);
+ Assert.AreEqual(bytes, message.OneofBytes);
+ Assert.IsNull(message.OneofNestedMessage);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofBytes, message.OneofFieldCase);
+
+ message.OneofUint32 = 20;
+ Assert.AreEqual("", message.OneofString);
+ Assert.AreEqual(20, message.OneofUint32);
+ Assert.AreEqual(ByteString.Empty, message.OneofBytes);
+ Assert.IsNull(message.OneofNestedMessage);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, message.OneofFieldCase);
+
+ var nestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 25 };
+ message.OneofNestedMessage = nestedMessage;
+ Assert.AreEqual("", message.OneofString);
+ Assert.AreEqual(0, message.OneofUint32);
+ Assert.AreEqual(ByteString.Empty, message.OneofBytes);
+ Assert.AreEqual(nestedMessage, message.OneofNestedMessage);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofNestedMessage, message.OneofFieldCase);
+
+ message.ClearOneofField();
+ Assert.AreEqual("", message.OneofString);
+ Assert.AreEqual(0, message.OneofUint32);
+ Assert.AreEqual(ByteString.Empty, message.OneofBytes);
+ Assert.IsNull(message.OneofNestedMessage);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase);
+ }
+
+ [Test]
+ public void Oneof_DefaultValuesNotEqual()
+ {
+ var message1 = new TestAllTypes { OneofString = "" };
+ var message2 = new TestAllTypes { OneofUint32 = 0 };
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofString, message1.OneofFieldCase);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, message2.OneofFieldCase);
+ Assert.AreNotEqual(message1, message2);
+ }
+
+ [Test]
+ public void OneofSerialization_NonDefaultValue()
+ {
+ var message = new TestAllTypes();
+ message.OneofString = "this would take a bit of space";
+ message.OneofUint32 = 10;
+ var bytes = message.ToByteArray();
+ Assert.AreEqual(3, bytes.Length); // 2 bytes for the tag + 1 for the value - no string!
+
+ var message2 = TestAllTypes.Parser.ParseFrom(bytes);
+ Assert.AreEqual(message, message2);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, message2.OneofFieldCase);
+ }
+
+ [Test]
+ public void OneofSerialization_DefaultValue()
+ {
+ var message = new TestAllTypes();
+ message.OneofString = "this would take a bit of space";
+ message.OneofUint32 = 0; // This is the default value for UInt32; normally wouldn't be serialized
+ var bytes = message.ToByteArray();
+ Assert.AreEqual(3, bytes.Length); // 2 bytes for the tag + 1 for the value - it's still serialized
+
+ var message2 = TestAllTypes.Parser.ParseFrom(bytes);
+ Assert.AreEqual(message, message2);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, message2.OneofFieldCase);
+ }
+
+ [Test]
+ public void IgnoreUnknownFields_RealDataStillRead()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ var unusedFieldNumber = 23456;
+ Assert.IsFalse(TestAllTypes.Descriptor.Fields.InDeclarationOrder().Select(x => x.FieldNumber).Contains(unusedFieldNumber));
+ output.WriteTag(unusedFieldNumber, WireFormat.WireType.LengthDelimited);
+ output.WriteString("ignore me");
+ message.WriteTo(output);
+ output.Flush();
+
+ stream.Position = 0;
+ var parsed = TestAllTypes.Parser.ParseFrom(stream);
+ Assert.AreEqual(message, parsed);
+ }
+
+ [Test]
+ public void IgnoreUnknownFields_AllTypes()
+ {
+ // Simple way of ensuring we can skip all kinds of fields.
+ var data = SampleMessages.CreateFullTestAllTypes().ToByteArray();
+ var empty = Empty.Parser.ParseFrom(data);
+ Assert.AreEqual(new Empty(), empty);
+ }
+
+ // This was originally seen as a conformance test failure.
+ [Test]
+ public void TruncatedMessageFieldThrows()
+ {
+ // 130, 3 is the message tag
+ // 1 is the data length - but there's no data.
+ var data = new byte[] { 130, 3, 1 };
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseFrom(data));
+ }
+
+ /// <summary>
+ /// Demonstrates current behaviour with an extraneous end group tag - see issue 688
+ /// for details; we may want to change this.
+ /// </summary>
+ [Test]
+ public void ExtraEndGroupThrows()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+
+ output.WriteTag(TestAllTypes.SingleFixed32FieldNumber, WireFormat.WireType.Fixed32);
+ output.WriteFixed32(123);
+ output.WriteTag(100, WireFormat.WireType.EndGroup);
+
+ output.Flush();
+
+ stream.Position = 0;
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseFrom(stream));
+ }
+
+ [Test]
+ public void CustomDiagnosticMessage_DirectToStringCall()
+ {
+ var message = new ForeignMessage { C = 31 };
+ Assert.AreEqual("{ \"c\": 31, \"@cInHex\": \"1f\" }", message.ToString());
+ Assert.AreEqual("{ \"c\": 31 }", JsonFormatter.Default.Format(message));
+ }
+
+ [Test]
+ public void CustomDiagnosticMessage_Nested()
+ {
+ var message = new TestAllTypes { SingleForeignMessage = new ForeignMessage { C = 16 } };
+ Assert.AreEqual("{ \"singleForeignMessage\": { \"c\": 16, \"@cInHex\": \"10\" } }", message.ToString());
+ Assert.AreEqual("{ \"singleForeignMessage\": { \"c\": 16 } }", JsonFormatter.Default.Format(message));
+ }
+
+ [Test]
+ public void CustomDiagnosticMessage_DirectToTextWriterCall()
+ {
+ var message = new ForeignMessage { C = 31 };
+ var writer = new StringWriter();
+ JsonFormatter.Default.Format(message, writer);
+ Assert.AreEqual("{ \"c\": 31 }", writer.ToString());
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.xproj b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.xproj
new file mode 100644
index 0000000000..6370441ebb
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.xproj
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>580eb013-d3c7-4578-b845-015f4a3b0591</ProjectGuid>
+ <RootNamespace>Google.Protobuf.Test</RootNamespace>
+ <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
+ <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
+ </PropertyGroup>
+ <PropertyGroup>
+ <SchemaVersion>2.0</SchemaVersion>
+ </PropertyGroup>
+ <ItemGroup>
+ <Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
+ </ItemGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
+</Project> \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/IssuesTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/IssuesTest.cs
new file mode 100644
index 0000000000..a38d6b08b5
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/IssuesTest.cs
@@ -0,0 +1,82 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using Google.Protobuf.Reflection;
+using UnitTest.Issues.TestProtos;
+using NUnit.Framework;
+
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Tests for issues which aren't easily compartmentalized into other unit tests.
+ /// </summary>
+ public class IssuesTest
+ {
+ // Issue 45
+ [Test]
+ public void FieldCalledItem()
+ {
+ ItemField message = new ItemField { Item = 3 };
+ FieldDescriptor field = ItemField.Descriptor.FindFieldByName("item");
+ Assert.NotNull(field);
+ Assert.AreEqual(3, (int)field.Accessor.GetValue(message));
+ }
+
+ [Test]
+ public void ReservedNames()
+ {
+ var message = new ReservedNames { Types_ = 10, Descriptor_ = 20 };
+ // Underscores aren't reflected in the JSON.
+ Assert.AreEqual("{ \"types\": 10, \"descriptor\": 20 }", message.ToString());
+ }
+
+ [Test]
+ public void JsonNameParseTest()
+ {
+ var settings = new JsonParser.Settings(10, TypeRegistry.FromFiles(UnittestIssuesReflection.Descriptor));
+ var parser = new JsonParser(settings);
+
+ // It is safe to use either original field name or explicitly specified json_name
+ Assert.AreEqual(new TestJsonName { Name = "test", Description = "test2", Guid = "test3" },
+ parser.Parse<TestJsonName>("{ \"name\": \"test\", \"desc\": \"test2\", \"guid\": \"test3\" }"));
+ }
+
+ [Test]
+ public void JsonNameFormatTest()
+ {
+ var message = new TestJsonName { Name = "test", Description = "test2", Guid = "test3" };
+ Assert.AreEqual("{ \"name\": \"test\", \"desc\": \"test2\", \"exid\": \"test3\" }",
+ JsonFormatter.Default.Format(message));
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs
new file mode 100644
index 0000000000..53ac3dc9be
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs
@@ -0,0 +1,624 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+using UnitTest.Issues.TestProtos;
+using Google.Protobuf.WellKnownTypes;
+using Google.Protobuf.Reflection;
+
+using static Google.Protobuf.JsonParserTest; // For WrapInQuotes
+using System.IO;
+using Google.Protobuf.Collections;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Tests for the JSON formatter. Note that in these tests, double quotes are replaced with apostrophes
+ /// for the sake of readability (embedding \" everywhere is painful). See the AssertJson method for details.
+ /// </summary>
+ public class JsonFormatterTest
+ {
+ [Test]
+ public void DefaultValues_WhenOmitted()
+ {
+ var formatter = JsonFormatter.Default;
+
+ AssertJson("{ }", formatter.Format(new ForeignMessage()));
+ AssertJson("{ }", formatter.Format(new TestAllTypes()));
+ AssertJson("{ }", formatter.Format(new TestMap()));
+ }
+
+ [Test]
+ public void DefaultValues_WhenIncluded()
+ {
+ var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithFormatDefaultValues(true));
+ AssertJson("{ 'c': 0 }", formatter.Format(new ForeignMessage()));
+ }
+
+ [Test]
+ public void EnumAllowAlias()
+ {
+ var message = new TestEnumAllowAlias
+ {
+ Value = TestEnumWithDupValue.Foo2,
+ };
+ var actualText = JsonFormatter.Default.Format(message);
+ var expectedText = "{ 'value': 'FOO1' }";
+ AssertJson(expectedText, actualText);
+ }
+
+ [Test]
+ public void EnumAsInt()
+ {
+ var message = new TestAllTypes
+ {
+ SingleForeignEnum = ForeignEnum.ForeignBar,
+ RepeatedForeignEnum = { ForeignEnum.ForeignBaz, (ForeignEnum) 100, ForeignEnum.ForeignFoo }
+ };
+ var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithFormatEnumsAsIntegers(true));
+ var actualText = formatter.Format(message);
+ var expectedText = "{ " +
+ "'singleForeignEnum': 5, " +
+ "'repeatedForeignEnum': [ 6, 100, 4 ]" +
+ " }";
+ AssertJson(expectedText, actualText);
+ }
+
+ [Test]
+ public void AllSingleFields()
+ {
+ var message = new TestAllTypes
+ {
+ SingleBool = true,
+ SingleBytes = ByteString.CopyFrom(1, 2, 3, 4),
+ SingleDouble = 23.5,
+ SingleFixed32 = 23,
+ SingleFixed64 = 1234567890123,
+ SingleFloat = 12.25f,
+ SingleForeignEnum = ForeignEnum.ForeignBar,
+ SingleForeignMessage = new ForeignMessage { C = 10 },
+ SingleImportEnum = ImportEnum.ImportBaz,
+ SingleImportMessage = new ImportMessage { D = 20 },
+ SingleInt32 = 100,
+ SingleInt64 = 3210987654321,
+ SingleNestedEnum = TestAllTypes.Types.NestedEnum.Foo,
+ SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 35 },
+ SinglePublicImportMessage = new PublicImportMessage { E = 54 },
+ SingleSfixed32 = -123,
+ SingleSfixed64 = -12345678901234,
+ SingleSint32 = -456,
+ SingleSint64 = -12345678901235,
+ SingleString = "test\twith\ttabs",
+ SingleUint32 = uint.MaxValue,
+ SingleUint64 = ulong.MaxValue,
+ };
+ var actualText = JsonFormatter.Default.Format(message);
+
+ // Fields in numeric order
+ var expectedText = "{ " +
+ "'singleInt32': 100, " +
+ "'singleInt64': '3210987654321', " +
+ "'singleUint32': 4294967295, " +
+ "'singleUint64': '18446744073709551615', " +
+ "'singleSint32': -456, " +
+ "'singleSint64': '-12345678901235', " +
+ "'singleFixed32': 23, " +
+ "'singleFixed64': '1234567890123', " +
+ "'singleSfixed32': -123, " +
+ "'singleSfixed64': '-12345678901234', " +
+ "'singleFloat': 12.25, " +
+ "'singleDouble': 23.5, " +
+ "'singleBool': true, " +
+ "'singleString': 'test\\twith\\ttabs', " +
+ "'singleBytes': 'AQIDBA==', " +
+ "'singleNestedMessage': { 'bb': 35 }, " +
+ "'singleForeignMessage': { 'c': 10 }, " +
+ "'singleImportMessage': { 'd': 20 }, " +
+ "'singleNestedEnum': 'FOO', " +
+ "'singleForeignEnum': 'FOREIGN_BAR', " +
+ "'singleImportEnum': 'IMPORT_BAZ', " +
+ "'singlePublicImportMessage': { 'e': 54 }" +
+ " }";
+ AssertJson(expectedText, actualText);
+ }
+
+ [Test]
+ public void RepeatedField()
+ {
+ AssertJson("{ 'repeatedInt32': [ 1, 2, 3, 4, 5 ] }",
+ JsonFormatter.Default.Format(new TestAllTypes { RepeatedInt32 = { 1, 2, 3, 4, 5 } }));
+ }
+
+ [Test]
+ public void MapField_StringString()
+ {
+ AssertJson("{ 'mapStringString': { 'with spaces': 'bar', 'a': 'b' } }",
+ JsonFormatter.Default.Format(new TestMap { MapStringString = { { "with spaces", "bar" }, { "a", "b" } } }));
+ }
+
+ [Test]
+ public void MapField_Int32Int32()
+ {
+ // The keys are quoted, but the values aren't.
+ AssertJson("{ 'mapInt32Int32': { '0': 1, '2': 3 } }",
+ JsonFormatter.Default.Format(new TestMap { MapInt32Int32 = { { 0, 1 }, { 2, 3 } } }));
+ }
+
+ [Test]
+ public void MapField_BoolBool()
+ {
+ // The keys are quoted, but the values aren't.
+ AssertJson("{ 'mapBoolBool': { 'false': true, 'true': false } }",
+ JsonFormatter.Default.Format(new TestMap { MapBoolBool = { { false, true }, { true, false } } }));
+ }
+
+ [TestCase(1.0, "1")]
+ [TestCase(double.NaN, "'NaN'")]
+ [TestCase(double.PositiveInfinity, "'Infinity'")]
+ [TestCase(double.NegativeInfinity, "'-Infinity'")]
+ public void DoubleRepresentations(double value, string expectedValueText)
+ {
+ var message = new TestAllTypes { SingleDouble = value };
+ string actualText = JsonFormatter.Default.Format(message);
+ string expectedText = "{ 'singleDouble': " + expectedValueText + " }";
+ AssertJson(expectedText, actualText);
+ }
+
+ [Test]
+ public void UnknownEnumValueNumeric_SingleField()
+ {
+ var message = new TestAllTypes { SingleForeignEnum = (ForeignEnum) 100 };
+ AssertJson("{ 'singleForeignEnum': 100 }", JsonFormatter.Default.Format(message));
+ }
+
+ [Test]
+ public void UnknownEnumValueNumeric_RepeatedField()
+ {
+ var message = new TestAllTypes { RepeatedForeignEnum = { ForeignEnum.ForeignBaz, (ForeignEnum) 100, ForeignEnum.ForeignFoo } };
+ AssertJson("{ 'repeatedForeignEnum': [ 'FOREIGN_BAZ', 100, 'FOREIGN_FOO' ] }", JsonFormatter.Default.Format(message));
+ }
+
+ [Test]
+ public void UnknownEnumValueNumeric_MapField()
+ {
+ var message = new TestMap { MapInt32Enum = { { 1, MapEnum.Foo }, { 2, (MapEnum) 100 }, { 3, MapEnum.Bar } } };
+ AssertJson("{ 'mapInt32Enum': { '1': 'MAP_ENUM_FOO', '2': 100, '3': 'MAP_ENUM_BAR' } }", JsonFormatter.Default.Format(message));
+ }
+
+ [Test]
+ public void UnknownEnumValue_RepeatedField_AllEntriesUnknown()
+ {
+ var message = new TestAllTypes { RepeatedForeignEnum = { (ForeignEnum) 200, (ForeignEnum) 100 } };
+ AssertJson("{ 'repeatedForeignEnum': [ 200, 100 ] }", JsonFormatter.Default.Format(message));
+ }
+
+ [Test]
+ [TestCase("a\u17b4b", "a\\u17b4b")] // Explicit
+ [TestCase("a\u0601b", "a\\u0601b")] // Ranged
+ [TestCase("a\u0605b", "a\u0605b")] // Passthrough (note lack of double backslash...)
+ public void SimpleNonAscii(string text, string encoded)
+ {
+ var message = new TestAllTypes { SingleString = text };
+ AssertJson("{ 'singleString': '" + encoded + "' }", JsonFormatter.Default.Format(message));
+ }
+
+ [Test]
+ public void SurrogatePairEscaping()
+ {
+ var message = new TestAllTypes { SingleString = "a\uD801\uDC01b" };
+ AssertJson("{ 'singleString': 'a\\ud801\\udc01b' }", JsonFormatter.Default.Format(message));
+ }
+
+ [Test]
+ public void InvalidSurrogatePairsFail()
+ {
+ // Note: don't use TestCase for these, as the strings can't be reliably represented
+ // See http://codeblog.jonskeet.uk/2014/11/07/when-is-a-string-not-a-string/
+
+ // Lone low surrogate
+ var message = new TestAllTypes { SingleString = "a\uDC01b" };
+ Assert.Throws<ArgumentException>(() => JsonFormatter.Default.Format(message));
+
+ // Lone high surrogate
+ message = new TestAllTypes { SingleString = "a\uD801b" };
+ Assert.Throws<ArgumentException>(() => JsonFormatter.Default.Format(message));
+ }
+
+ [Test]
+ [TestCase("foo_bar", "fooBar")]
+ [TestCase("bananaBanana", "bananaBanana")]
+ [TestCase("BANANABanana", "BANANABanana")]
+ [TestCase("simple", "simple")]
+ [TestCase("ACTION_AND_ADVENTURE", "ACTIONANDADVENTURE")]
+ [TestCase("action_and_adventure", "actionAndAdventure")]
+ [TestCase("kFoo", "kFoo")]
+ [TestCase("HTTPServer", "HTTPServer")]
+ [TestCase("CLIENT", "CLIENT")]
+ public void ToJsonName(string original, string expected)
+ {
+ Assert.AreEqual(expected, JsonFormatter.ToJsonName(original));
+ }
+
+ [Test]
+ [TestCase(null, "{ }")]
+ [TestCase("x", "{ 'fooString': 'x' }")]
+ [TestCase("", "{ 'fooString': '' }")]
+ public void Oneof(string fooStringValue, string expectedJson)
+ {
+ var message = new TestOneof();
+ if (fooStringValue != null)
+ {
+ message.FooString = fooStringValue;
+ }
+
+ // We should get the same result both with and without "format default values".
+ var formatter = JsonFormatter.Default;
+ AssertJson(expectedJson, formatter.Format(message));
+ formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithFormatDefaultValues(true));
+ AssertJson(expectedJson, formatter.Format(message));
+ }
+
+ [Test]
+ public void WrapperFormatting_Single()
+ {
+ // Just a few examples, handling both classes and value types, and
+ // default vs non-default values
+ var message = new TestWellKnownTypes
+ {
+ Int64Field = 10,
+ Int32Field = 0,
+ BytesField = ByteString.FromBase64("ABCD"),
+ StringField = ""
+ };
+ var expectedJson = "{ 'int64Field': '10', 'int32Field': 0, 'stringField': '', 'bytesField': 'ABCD' }";
+ AssertJson(expectedJson, JsonFormatter.Default.Format(message));
+ }
+
+ [Test]
+ public void WrapperFormatting_Message()
+ {
+ Assert.AreEqual("\"\"", JsonFormatter.Default.Format(new StringValue()));
+ Assert.AreEqual("0", JsonFormatter.Default.Format(new Int32Value()));
+ }
+
+ [Test]
+ public void WrapperFormatting_IncludeNull()
+ {
+ // The actual JSON here is very large because there are lots of fields. Just test a couple of them.
+ var message = new TestWellKnownTypes { Int32Field = 10 };
+ var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithFormatDefaultValues(true));
+ var actualJson = formatter.Format(message);
+ Assert.IsTrue(actualJson.Contains("\"int64Field\": null"));
+ Assert.IsFalse(actualJson.Contains("\"int32Field\": null"));
+ }
+
+ [Test]
+ public void OutputIsInNumericFieldOrder_NoDefaults()
+ {
+ var formatter = JsonFormatter.Default;
+ var message = new TestJsonFieldOrdering { PlainString = "p1", PlainInt32 = 2 };
+ AssertJson("{ 'plainString': 'p1', 'plainInt32': 2 }", formatter.Format(message));
+ message = new TestJsonFieldOrdering { O1Int32 = 5, O2String = "o2", PlainInt32 = 10, PlainString = "plain" };
+ AssertJson("{ 'plainString': 'plain', 'o2String': 'o2', 'plainInt32': 10, 'o1Int32': 5 }", formatter.Format(message));
+ message = new TestJsonFieldOrdering { O1String = "", O2Int32 = 0, PlainInt32 = 10, PlainString = "plain" };
+ AssertJson("{ 'plainString': 'plain', 'o1String': '', 'plainInt32': 10, 'o2Int32': 0 }", formatter.Format(message));
+ }
+
+ [Test]
+ public void OutputIsInNumericFieldOrder_WithDefaults()
+ {
+ var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithFormatDefaultValues(true));
+ var message = new TestJsonFieldOrdering();
+ AssertJson("{ 'plainString': '', 'plainInt32': 0 }", formatter.Format(message));
+ message = new TestJsonFieldOrdering { O1Int32 = 5, O2String = "o2", PlainInt32 = 10, PlainString = "plain" };
+ AssertJson("{ 'plainString': 'plain', 'o2String': 'o2', 'plainInt32': 10, 'o1Int32': 5 }", formatter.Format(message));
+ message = new TestJsonFieldOrdering { O1String = "", O2Int32 = 0, PlainInt32 = 10, PlainString = "plain" };
+ AssertJson("{ 'plainString': 'plain', 'o1String': '', 'plainInt32': 10, 'o2Int32': 0 }", formatter.Format(message));
+ }
+
+ [Test]
+ [TestCase("1970-01-01T00:00:00Z", 0)]
+ [TestCase("1970-01-01T00:00:00.000000001Z", 1)]
+ [TestCase("1970-01-01T00:00:00.000000010Z", 10)]
+ [TestCase("1970-01-01T00:00:00.000000100Z", 100)]
+ [TestCase("1970-01-01T00:00:00.000001Z", 1000)]
+ [TestCase("1970-01-01T00:00:00.000010Z", 10000)]
+ [TestCase("1970-01-01T00:00:00.000100Z", 100000)]
+ [TestCase("1970-01-01T00:00:00.001Z", 1000000)]
+ [TestCase("1970-01-01T00:00:00.010Z", 10000000)]
+ [TestCase("1970-01-01T00:00:00.100Z", 100000000)]
+ [TestCase("1970-01-01T00:00:00.120Z", 120000000)]
+ [TestCase("1970-01-01T00:00:00.123Z", 123000000)]
+ [TestCase("1970-01-01T00:00:00.123400Z", 123400000)]
+ [TestCase("1970-01-01T00:00:00.123450Z", 123450000)]
+ [TestCase("1970-01-01T00:00:00.123456Z", 123456000)]
+ [TestCase("1970-01-01T00:00:00.123456700Z", 123456700)]
+ [TestCase("1970-01-01T00:00:00.123456780Z", 123456780)]
+ [TestCase("1970-01-01T00:00:00.123456789Z", 123456789)]
+ public void TimestampStandalone(string expected, int nanos)
+ {
+ Assert.AreEqual(WrapInQuotes(expected), new Timestamp { Nanos = nanos }.ToString());
+ }
+
+ [Test]
+ public void TimestampStandalone_FromDateTime()
+ {
+ // One before and one after the Unix epoch, more easily represented via DateTime.
+ Assert.AreEqual("\"1673-06-19T12:34:56Z\"",
+ new DateTime(1673, 6, 19, 12, 34, 56, DateTimeKind.Utc).ToTimestamp().ToString());
+ Assert.AreEqual("\"2015-07-31T10:29:34Z\"",
+ new DateTime(2015, 7, 31, 10, 29, 34, DateTimeKind.Utc).ToTimestamp().ToString());
+ }
+
+ [Test]
+ [TestCase(-1, -1)] // Would be valid as duration
+ [TestCase(1, Timestamp.MaxNanos + 1)]
+ [TestCase(Timestamp.UnixSecondsAtBclMaxValue + 1, 0)]
+ [TestCase(Timestamp.UnixSecondsAtBclMinValue - 1, 0)]
+ public void TimestampStandalone_NonNormalized(long seconds, int nanoseconds)
+ {
+ var timestamp = new Timestamp { Seconds = seconds, Nanos = nanoseconds };
+ Assert.Throws<InvalidOperationException>(() => JsonFormatter.Default.Format(timestamp));
+ }
+
+ [Test]
+ public void TimestampField()
+ {
+ var message = new TestWellKnownTypes { TimestampField = new Timestamp() };
+ AssertJson("{ 'timestampField': '1970-01-01T00:00:00Z' }", JsonFormatter.Default.Format(message));
+ }
+
+ [Test]
+ [TestCase(0, 0, "0s")]
+ [TestCase(1, 0, "1s")]
+ [TestCase(-1, 0, "-1s")]
+ [TestCase(0, 1, "0.000000001s")]
+ [TestCase(0, 10, "0.000000010s")]
+ [TestCase(0, 100, "0.000000100s")]
+ [TestCase(0, 1000, "0.000001s")]
+ [TestCase(0, 10000, "0.000010s")]
+ [TestCase(0, 100000, "0.000100s")]
+ [TestCase(0, 1000000, "0.001s")]
+ [TestCase(0, 10000000, "0.010s")]
+ [TestCase(0, 100000000, "0.100s")]
+ [TestCase(0, 120000000, "0.120s")]
+ [TestCase(0, 123000000, "0.123s")]
+ [TestCase(0, 123400000, "0.123400s")]
+ [TestCase(0, 123450000, "0.123450s")]
+ [TestCase(0, 123456000, "0.123456s")]
+ [TestCase(0, 123456700, "0.123456700s")]
+ [TestCase(0, 123456780, "0.123456780s")]
+ [TestCase(0, 123456789, "0.123456789s")]
+ [TestCase(0, -100000000, "-0.100s")]
+ [TestCase(1, 100000000, "1.100s")]
+ [TestCase(-1, -100000000, "-1.100s")]
+ public void DurationStandalone(long seconds, int nanoseconds, string expected)
+ {
+ var json = JsonFormatter.Default.Format(new Duration { Seconds = seconds, Nanos = nanoseconds });
+ Assert.AreEqual(WrapInQuotes(expected), json);
+ }
+
+ [Test]
+ [TestCase(1, 2123456789)]
+ [TestCase(1, -100000000)]
+ public void DurationStandalone_NonNormalized(long seconds, int nanoseconds)
+ {
+ var duration = new Duration { Seconds = seconds, Nanos = nanoseconds };
+ Assert.Throws<InvalidOperationException>(() => JsonFormatter.Default.Format(duration));
+ }
+
+ [Test]
+ public void DurationField()
+ {
+ var message = new TestWellKnownTypes { DurationField = new Duration() };
+ AssertJson("{ 'durationField': '0s' }", JsonFormatter.Default.Format(message));
+ }
+
+ [Test]
+ public void StructSample()
+ {
+ var message = new Struct
+ {
+ Fields =
+ {
+ { "a", Value.ForNull() },
+ { "b", Value.ForBool(false) },
+ { "c", Value.ForNumber(10.5) },
+ { "d", Value.ForString("text") },
+ { "e", Value.ForList(Value.ForString("t1"), Value.ForNumber(5)) },
+ { "f", Value.ForStruct(new Struct { Fields = { { "nested", Value.ForString("value") } } }) }
+ }
+ };
+ AssertJson("{ 'a': null, 'b': false, 'c': 10.5, 'd': 'text', 'e': [ 't1', 5 ], 'f': { 'nested': 'value' } }", message.ToString());
+ }
+
+ [Test]
+ [TestCase("foo__bar")]
+ [TestCase("foo_3_ar")]
+ [TestCase("fooBar")]
+ public void FieldMaskInvalid(string input)
+ {
+ var mask = new FieldMask { Paths = { input } };
+ Assert.Throws<InvalidOperationException>(() => JsonFormatter.Default.Format(mask));
+ }
+
+ [Test]
+ public void FieldMaskStandalone()
+ {
+ var fieldMask = new FieldMask { Paths = { "", "single", "with_underscore", "nested.field.name", "nested..double_dot" } };
+ Assert.AreEqual("\",single,withUnderscore,nested.field.name,nested..doubleDot\"", fieldMask.ToString());
+
+ // Invalid, but we shouldn't create broken JSON...
+ fieldMask = new FieldMask { Paths = { "x\\y" } };
+ Assert.AreEqual(@"""x\\y""", fieldMask.ToString());
+ }
+
+ [Test]
+ public void FieldMaskField()
+ {
+ var message = new TestWellKnownTypes { FieldMaskField = new FieldMask { Paths = { "user.display_name", "photo" } } };
+ AssertJson("{ 'fieldMaskField': 'user.displayName,photo' }", JsonFormatter.Default.Format(message));
+ }
+
+ // SourceContext is an example of a well-known type with no special JSON handling
+ [Test]
+ public void SourceContextStandalone()
+ {
+ var message = new SourceContext { FileName = "foo.proto" };
+ AssertJson("{ 'fileName': 'foo.proto' }", JsonFormatter.Default.Format(message));
+ }
+
+ [Test]
+ public void AnyWellKnownType()
+ {
+ var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithTypeRegistry(TypeRegistry.FromMessages(Timestamp.Descriptor)));
+ var timestamp = new DateTime(1673, 6, 19, 12, 34, 56, DateTimeKind.Utc).ToTimestamp();
+ var any = Any.Pack(timestamp);
+ AssertJson("{ '@type': 'type.googleapis.com/google.protobuf.Timestamp', 'value': '1673-06-19T12:34:56Z' }", formatter.Format(any));
+ }
+
+ [Test]
+ public void AnyMessageType()
+ {
+ var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithTypeRegistry(TypeRegistry.FromMessages(TestAllTypes.Descriptor)));
+ var message = new TestAllTypes { SingleInt32 = 10, SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 20 } };
+ var any = Any.Pack(message);
+ AssertJson("{ '@type': 'type.googleapis.com/protobuf_unittest.TestAllTypes', 'singleInt32': 10, 'singleNestedMessage': { 'bb': 20 } }", formatter.Format(any));
+ }
+
+ [Test]
+ public void AnyMessageType_CustomPrefix()
+ {
+ var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithTypeRegistry(TypeRegistry.FromMessages(TestAllTypes.Descriptor)));
+ var message = new TestAllTypes { SingleInt32 = 10 };
+ var any = Any.Pack(message, "foo.bar/baz");
+ AssertJson("{ '@type': 'foo.bar/baz/protobuf_unittest.TestAllTypes', 'singleInt32': 10 }", formatter.Format(any));
+ }
+
+ [Test]
+ public void AnyNested()
+ {
+ var registry = TypeRegistry.FromMessages(TestWellKnownTypes.Descriptor, TestAllTypes.Descriptor);
+ var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithTypeRegistry(registry));
+
+ // Nest an Any as the value of an Any.
+ var doubleNestedMessage = new TestAllTypes { SingleInt32 = 20 };
+ var nestedMessage = Any.Pack(doubleNestedMessage);
+ var message = new TestWellKnownTypes { AnyField = Any.Pack(nestedMessage) };
+ AssertJson("{ 'anyField': { '@type': 'type.googleapis.com/google.protobuf.Any', 'value': { '@type': 'type.googleapis.com/protobuf_unittest.TestAllTypes', 'singleInt32': 20 } } }",
+ formatter.Format(message));
+ }
+
+ [Test]
+ public void AnyUnknownType()
+ {
+ // The default type registry doesn't have any types in it.
+ var message = new TestAllTypes();
+ var any = Any.Pack(message);
+ Assert.Throws<InvalidOperationException>(() => JsonFormatter.Default.Format(any));
+ }
+
+ [Test]
+ [TestCase(typeof(BoolValue), true, "true")]
+ [TestCase(typeof(Int32Value), 32, "32")]
+ [TestCase(typeof(Int64Value), 32L, "\"32\"")]
+ [TestCase(typeof(UInt32Value), 32U, "32")]
+ [TestCase(typeof(UInt64Value), 32UL, "\"32\"")]
+ [TestCase(typeof(StringValue), "foo", "\"foo\"")]
+ [TestCase(typeof(FloatValue), 1.5f, "1.5")]
+ [TestCase(typeof(DoubleValue), 1.5d, "1.5")]
+ public void Wrappers_Standalone(System.Type wrapperType, object value, string expectedJson)
+ {
+ IMessage populated = (IMessage)Activator.CreateInstance(wrapperType);
+ populated.Descriptor.Fields[WrappersReflection.WrapperValueFieldNumber].Accessor.SetValue(populated, value);
+ Assert.AreEqual(expectedJson, JsonFormatter.Default.Format(populated));
+ }
+
+ // Sanity tests for WriteValue. Not particularly comprehensive, as it's all covered above already,
+ // as FormatMessage uses WriteValue.
+
+ [TestCase(null, "null")]
+ [TestCase(1, "1")]
+ [TestCase(1L, "'1'")]
+ [TestCase(0.5f, "0.5")]
+ [TestCase(0.5d, "0.5")]
+ [TestCase("text", "'text'")]
+ [TestCase("x\ny", @"'x\ny'")]
+ [TestCase(ForeignEnum.ForeignBar, "'FOREIGN_BAR'")]
+ public void WriteValue_Constant(object value, string expectedJson)
+ {
+ AssertWriteValue(value, expectedJson);
+ }
+
+ [Test]
+ public void WriteValue_Timestamp()
+ {
+ var value = new DateTime(1673, 6, 19, 12, 34, 56, DateTimeKind.Utc).ToTimestamp();
+ AssertWriteValue(value, "'1673-06-19T12:34:56Z'");
+ }
+
+ [Test]
+ public void WriteValue_Message()
+ {
+ var value = new TestAllTypes { SingleInt32 = 100, SingleInt64 = 3210987654321L };
+ AssertWriteValue(value, "{ 'singleInt32': 100, 'singleInt64': '3210987654321' }");
+ }
+
+ [Test]
+ public void WriteValue_List()
+ {
+ var value = new RepeatedField<int> { 1, 2, 3 };
+ AssertWriteValue(value, "[ 1, 2, 3 ]");
+ }
+
+ private static void AssertWriteValue(object value, string expectedJson)
+ {
+ var writer = new StringWriter();
+ JsonFormatter.Default.WriteValue(writer, value);
+ string actual = writer.ToString();
+ AssertJson(expectedJson, actual);
+ }
+
+ /// <summary>
+ /// Checks that the actual JSON is the same as the expected JSON - but after replacing
+ /// all apostrophes in the expected JSON with double quotes. This basically makes the tests easier
+ /// to read.
+ /// </summary>
+ private static void AssertJson(string expectedJsonWithApostrophes, string actualJson)
+ {
+ var expectedJson = expectedJsonWithApostrophes.Replace("'", "\"");
+ Assert.AreEqual(expectedJson, actualJson);
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/JsonParserTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/JsonParserTest.cs
new file mode 100644
index 0000000000..f595455aa1
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/JsonParserTest.cs
@@ -0,0 +1,939 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using Google.Protobuf.Reflection;
+using Google.Protobuf.TestProtos;
+using Google.Protobuf.WellKnownTypes;
+using NUnit.Framework;
+using System;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Unit tests for JSON parsing.
+ /// </summary>
+ public class JsonParserTest
+ {
+ // Sanity smoke test
+ [Test]
+ public void AllTypesRoundtrip()
+ {
+ AssertRoundtrip(SampleMessages.CreateFullTestAllTypes());
+ }
+
+ [Test]
+ public void Maps()
+ {
+ AssertRoundtrip(new TestMap { MapStringString = { { "with spaces", "bar" }, { "a", "b" } } });
+ AssertRoundtrip(new TestMap { MapInt32Int32 = { { 0, 1 }, { 2, 3 } } });
+ AssertRoundtrip(new TestMap { MapBoolBool = { { false, true }, { true, false } } });
+ }
+
+ [Test]
+ [TestCase(" 1 ")]
+ [TestCase("+1")]
+ [TestCase("1,000")]
+ [TestCase("1.5")]
+ public void IntegerMapKeysAreStrict(string keyText)
+ {
+ // Test that integer parsing is strict. We assume that if this is correct for int32,
+ // it's correct for other numeric key types.
+ var json = "{ \"mapInt32Int32\": { \"" + keyText + "\" : \"1\" } }";
+ Assert.Throws<InvalidProtocolBufferException>(() => JsonParser.Default.Parse<TestMap>(json));
+ }
+
+ [Test]
+ public void OriginalFieldNameAccepted()
+ {
+ var json = "{ \"single_int32\": 10 }";
+ var expected = new TestAllTypes { SingleInt32 = 10 };
+ Assert.AreEqual(expected, TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void SourceContextRoundtrip()
+ {
+ AssertRoundtrip(new SourceContext { FileName = "foo.proto" });
+ }
+
+ [Test]
+ public void SingularWrappers_DefaultNonNullValues()
+ {
+ var message = new TestWellKnownTypes
+ {
+ StringField = "",
+ BytesField = ByteString.Empty,
+ BoolField = false,
+ FloatField = 0f,
+ DoubleField = 0d,
+ Int32Field = 0,
+ Int64Field = 0,
+ Uint32Field = 0,
+ Uint64Field = 0
+ };
+ AssertRoundtrip(message);
+ }
+
+ [Test]
+ public void SingularWrappers_NonDefaultValues()
+ {
+ var message = new TestWellKnownTypes
+ {
+ StringField = "x",
+ BytesField = ByteString.CopyFrom(1, 2, 3),
+ BoolField = true,
+ FloatField = 12.5f,
+ DoubleField = 12.25d,
+ Int32Field = 1,
+ Int64Field = 2,
+ Uint32Field = 3,
+ Uint64Field = 4
+ };
+ AssertRoundtrip(message);
+ }
+
+ [Test]
+ public void SingularWrappers_ExplicitNulls()
+ {
+ // When we parse the "valueField": null part, we remember it... basically, it's one case
+ // where explicit default values don't fully roundtrip.
+ var message = new TestWellKnownTypes { ValueField = Value.ForNull() };
+ var json = new JsonFormatter(new JsonFormatter.Settings(true)).Format(message);
+ var parsed = JsonParser.Default.Parse<TestWellKnownTypes>(json);
+ Assert.AreEqual(message, parsed);
+ }
+
+ [Test]
+ [TestCase(typeof(BoolValue), "true", true)]
+ [TestCase(typeof(Int32Value), "32", 32)]
+ [TestCase(typeof(Int64Value), "32", 32L)]
+ [TestCase(typeof(Int64Value), "\"32\"", 32L)]
+ [TestCase(typeof(UInt32Value), "32", 32U)]
+ [TestCase(typeof(UInt64Value), "\"32\"", 32UL)]
+ [TestCase(typeof(UInt64Value), "32", 32UL)]
+ [TestCase(typeof(StringValue), "\"foo\"", "foo")]
+ [TestCase(typeof(FloatValue), "1.5", 1.5f)]
+ [TestCase(typeof(DoubleValue), "1.5", 1.5d)]
+ public void Wrappers_Standalone(System.Type wrapperType, string json, object expectedValue)
+ {
+ IMessage parsed = (IMessage)Activator.CreateInstance(wrapperType);
+ IMessage expected = (IMessage)Activator.CreateInstance(wrapperType);
+ JsonParser.Default.Merge(parsed, "null");
+ Assert.AreEqual(expected, parsed);
+
+ JsonParser.Default.Merge(parsed, json);
+ expected.Descriptor.Fields[WrappersReflection.WrapperValueFieldNumber].Accessor.SetValue(expected, expectedValue);
+ Assert.AreEqual(expected, parsed);
+ }
+
+ [Test]
+ public void ExplicitNullValue()
+ {
+ string json = "{\"valueField\": null}";
+ var message = JsonParser.Default.Parse<TestWellKnownTypes>(json);
+ Assert.AreEqual(new TestWellKnownTypes { ValueField = Value.ForNull() }, message);
+ }
+
+ [Test]
+ public void BytesWrapper_Standalone()
+ {
+ ByteString data = ByteString.CopyFrom(1, 2, 3);
+ // Can't do this with attributes...
+ var parsed = JsonParser.Default.Parse<BytesValue>(WrapInQuotes(data.ToBase64()));
+ var expected = new BytesValue { Value = data };
+ Assert.AreEqual(expected, parsed);
+ }
+
+ [Test]
+ public void RepeatedWrappers()
+ {
+ var message = new RepeatedWellKnownTypes
+ {
+ BoolField = { true, false },
+ BytesField = { ByteString.CopyFrom(1, 2, 3), ByteString.CopyFrom(4, 5, 6), ByteString.Empty },
+ DoubleField = { 12.5, -1.5, 0d },
+ FloatField = { 123.25f, -20f, 0f },
+ Int32Field = { int.MaxValue, int.MinValue, 0 },
+ Int64Field = { long.MaxValue, long.MinValue, 0L },
+ StringField = { "First", "Second", "" },
+ Uint32Field = { uint.MaxValue, uint.MinValue, 0U },
+ Uint64Field = { ulong.MaxValue, ulong.MinValue, 0UL },
+ };
+ AssertRoundtrip(message);
+ }
+
+ [Test]
+ public void RepeatedField_NullElementProhibited()
+ {
+ string json = "{ \"repeated_foreign_message\": [null] }";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void RepeatedField_NullOverallValueAllowed()
+ {
+ string json = "{ \"repeated_foreign_message\": null }";
+ Assert.AreEqual(new TestAllTypes(), TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("{ \"mapInt32Int32\": { \"10\": null }")]
+ [TestCase("{ \"mapStringString\": { \"abc\": null }")]
+ [TestCase("{ \"mapInt32ForeignMessage\": { \"10\": null }")]
+ public void MapField_NullValueProhibited(string json)
+ {
+ Assert.Throws<InvalidProtocolBufferException>(() => TestMap.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void MapField_NullOverallValueAllowed()
+ {
+ string json = "{ \"mapInt32Int32\": null }";
+ Assert.AreEqual(new TestMap(), TestMap.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void IndividualWrapperTypes()
+ {
+ Assert.AreEqual(new StringValue { Value = "foo" }, StringValue.Parser.ParseJson("\"foo\""));
+ Assert.AreEqual(new Int32Value { Value = 1 }, Int32Value.Parser.ParseJson("1"));
+ // Can parse strings directly too
+ Assert.AreEqual(new Int32Value { Value = 1 }, Int32Value.Parser.ParseJson("\"1\""));
+ }
+
+ private static void AssertRoundtrip<T>(T message) where T : IMessage<T>, new()
+ {
+ var clone = message.Clone();
+ var json = JsonFormatter.Default.Format(message);
+ var parsed = JsonParser.Default.Parse<T>(json);
+ Assert.AreEqual(clone, parsed);
+ }
+
+ [Test]
+ [TestCase("0", 0)]
+ [TestCase("-0", 0)] // Not entirely clear whether we intend to allow this...
+ [TestCase("1", 1)]
+ [TestCase("-1", -1)]
+ [TestCase("2147483647", 2147483647)]
+ [TestCase("-2147483648", -2147483648)]
+ public void StringToInt32_Valid(string jsonValue, int expectedParsedValue)
+ {
+ string json = "{ \"singleInt32\": \"" + jsonValue + "\"}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleInt32);
+ }
+
+ [Test]
+ [TestCase("+0")]
+ [TestCase(" 1")]
+ [TestCase("1 ")]
+ [TestCase("00")]
+ [TestCase("-00")]
+ [TestCase("--1")]
+ [TestCase("+1")]
+ [TestCase("1.5")]
+ [TestCase("1e10")]
+ [TestCase("2147483648")]
+ [TestCase("-2147483649")]
+ public void StringToInt32_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleInt32\": \"" + jsonValue + "\"}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0U)]
+ [TestCase("1", 1U)]
+ [TestCase("4294967295", 4294967295U)]
+ public void StringToUInt32_Valid(string jsonValue, uint expectedParsedValue)
+ {
+ string json = "{ \"singleUint32\": \"" + jsonValue + "\"}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleUint32);
+ }
+
+ // Assume that anything non-bounds-related is covered in the Int32 case
+ [Test]
+ [TestCase("-1")]
+ [TestCase("4294967296")]
+ public void StringToUInt32_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleUint32\": \"" + jsonValue + "\"}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0L)]
+ [TestCase("1", 1L)]
+ [TestCase("-1", -1L)]
+ [TestCase("9223372036854775807", 9223372036854775807)]
+ [TestCase("-9223372036854775808", -9223372036854775808)]
+ public void StringToInt64_Valid(string jsonValue, long expectedParsedValue)
+ {
+ string json = "{ \"singleInt64\": \"" + jsonValue + "\"}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleInt64);
+ }
+
+ // Assume that anything non-bounds-related is covered in the Int32 case
+ [Test]
+ [TestCase("-9223372036854775809")]
+ [TestCase("9223372036854775808")]
+ public void StringToInt64_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleInt64\": \"" + jsonValue + "\"}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0UL)]
+ [TestCase("1", 1UL)]
+ [TestCase("18446744073709551615", 18446744073709551615)]
+ public void StringToUInt64_Valid(string jsonValue, ulong expectedParsedValue)
+ {
+ string json = "{ \"singleUint64\": \"" + jsonValue + "\"}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleUint64);
+ }
+
+ // Assume that anything non-bounds-related is covered in the Int32 case
+ [Test]
+ [TestCase("-1")]
+ [TestCase("18446744073709551616")]
+ public void StringToUInt64_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleUint64\": \"" + jsonValue + "\"}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0d)]
+ [TestCase("1", 1d)]
+ [TestCase("1.000000", 1d)]
+ [TestCase("1.0000000000000000000000001", 1d)] // We don't notice that we haven't preserved the exact value
+ [TestCase("-1", -1d)]
+ [TestCase("1e1", 10d)]
+ [TestCase("1e01", 10d)] // Leading decimals are allowed in exponents
+ [TestCase("1E1", 10d)] // Either case is fine
+ [TestCase("-1e1", -10d)]
+ [TestCase("1.5e1", 15d)]
+ [TestCase("-1.5e1", -15d)]
+ [TestCase("15e-1", 1.5d)]
+ [TestCase("-15e-1", -1.5d)]
+ [TestCase("1.79769e308", 1.79769e308)]
+ [TestCase("-1.79769e308", -1.79769e308)]
+ [TestCase("Infinity", double.PositiveInfinity)]
+ [TestCase("-Infinity", double.NegativeInfinity)]
+ [TestCase("NaN", double.NaN)]
+ public void StringToDouble_Valid(string jsonValue, double expectedParsedValue)
+ {
+ string json = "{ \"singleDouble\": \"" + jsonValue + "\"}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleDouble);
+ }
+
+ [Test]
+ [TestCase("1.7977e308")]
+ [TestCase("-1.7977e308")]
+ [TestCase("1e309")]
+ [TestCase("1,0")]
+ [TestCase("1.0.0")]
+ [TestCase("+1")]
+ [TestCase("00")]
+ [TestCase("01")]
+ [TestCase("-00")]
+ [TestCase("-01")]
+ [TestCase("--1")]
+ [TestCase(" Infinity")]
+ [TestCase(" -Infinity")]
+ [TestCase("NaN ")]
+ [TestCase("Infinity ")]
+ [TestCase("-Infinity ")]
+ [TestCase(" NaN")]
+ [TestCase("INFINITY")]
+ [TestCase("nan")]
+ [TestCase("\u00BD")] // 1/2 as a single Unicode character. Just sanity checking...
+ public void StringToDouble_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleDouble\": \"" + jsonValue + "\"}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0f)]
+ [TestCase("1", 1f)]
+ [TestCase("1.000000", 1f)]
+ [TestCase("-1", -1f)]
+ [TestCase("3.402823e38", 3.402823e38f)]
+ [TestCase("-3.402823e38", -3.402823e38f)]
+ [TestCase("1.5e1", 15f)]
+ [TestCase("15e-1", 1.5f)]
+ public void StringToFloat_Valid(string jsonValue, float expectedParsedValue)
+ {
+ string json = "{ \"singleFloat\": \"" + jsonValue + "\"}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleFloat);
+ }
+
+ [Test]
+ [TestCase("3.402824e38")]
+ [TestCase("-3.402824e38")]
+ [TestCase("1,0")]
+ [TestCase("1.0.0")]
+ [TestCase("+1")]
+ [TestCase("00")]
+ [TestCase("--1")]
+ public void StringToFloat_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleFloat\": \"" + jsonValue + "\"}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0)]
+ [TestCase("-0", 0)] // Not entirely clear whether we intend to allow this...
+ [TestCase("1", 1)]
+ [TestCase("-1", -1)]
+ [TestCase("2147483647", 2147483647)]
+ [TestCase("-2147483648", -2147483648)]
+ [TestCase("1e1", 10)]
+ [TestCase("-1e1", -10)]
+ [TestCase("10.00", 10)]
+ [TestCase("-10.00", -10)]
+ public void NumberToInt32_Valid(string jsonValue, int expectedParsedValue)
+ {
+ string json = "{ \"singleInt32\": " + jsonValue + "}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleInt32);
+ }
+
+ [Test]
+ [TestCase("+0", typeof(InvalidJsonException))]
+ [TestCase("00", typeof(InvalidJsonException))]
+ [TestCase("-00", typeof(InvalidJsonException))]
+ [TestCase("--1", typeof(InvalidJsonException))]
+ [TestCase("+1", typeof(InvalidJsonException))]
+ [TestCase("1.5", typeof(InvalidProtocolBufferException))]
+ // Value is out of range
+ [TestCase("1e10", typeof(InvalidProtocolBufferException))]
+ [TestCase("2147483648", typeof(InvalidProtocolBufferException))]
+ [TestCase("-2147483649", typeof(InvalidProtocolBufferException))]
+ public void NumberToInt32_Invalid(string jsonValue, System.Type expectedExceptionType)
+ {
+ string json = "{ \"singleInt32\": " + jsonValue + "}";
+ Assert.Throws(expectedExceptionType, () => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0U)]
+ [TestCase("1", 1U)]
+ [TestCase("4294967295", 4294967295U)]
+ public void NumberToUInt32_Valid(string jsonValue, uint expectedParsedValue)
+ {
+ string json = "{ \"singleUint32\": " + jsonValue + "}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleUint32);
+ }
+
+ // Assume that anything non-bounds-related is covered in the Int32 case
+ [Test]
+ [TestCase("-1")]
+ [TestCase("4294967296")]
+ public void NumberToUInt32_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleUint32\": " + jsonValue + "}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0L)]
+ [TestCase("1", 1L)]
+ [TestCase("-1", -1L)]
+ // long.MaxValue isn't actually representable as a double. This string value is the highest
+ // representable value which isn't greater than long.MaxValue.
+ [TestCase("9223372036854774784", 9223372036854774784)]
+ [TestCase("-9223372036854775808", -9223372036854775808)]
+ public void NumberToInt64_Valid(string jsonValue, long expectedParsedValue)
+ {
+ string json = "{ \"singleInt64\": " + jsonValue + "}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleInt64);
+ }
+
+ // Assume that anything non-bounds-related is covered in the Int32 case
+ [Test]
+ [TestCase("9223372036854775808")]
+ // Theoretical bound would be -9223372036854775809, but when that is parsed to a double
+ // we end up with the exact value of long.MinValue due to lack of precision. The value here
+ // is the "next double down".
+ [TestCase("-9223372036854780000")]
+ public void NumberToInt64_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleInt64\": " + jsonValue + "}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0UL)]
+ [TestCase("1", 1UL)]
+ // ulong.MaxValue isn't representable as a double. This value is the largest double within
+ // the range of ulong.
+ [TestCase("18446744073709549568", 18446744073709549568UL)]
+ public void NumberToUInt64_Valid(string jsonValue, ulong expectedParsedValue)
+ {
+ string json = "{ \"singleUint64\": " + jsonValue + "}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleUint64);
+ }
+
+ // Assume that anything non-bounds-related is covered in the Int32 case
+ [Test]
+ [TestCase("-1")]
+ [TestCase("18446744073709551616")]
+ public void NumberToUInt64_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleUint64\": " + jsonValue + "}";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0d)]
+ [TestCase("1", 1d)]
+ [TestCase("1.000000", 1d)]
+ [TestCase("1.0000000000000000000000001", 1d)] // We don't notice that we haven't preserved the exact value
+ [TestCase("-1", -1d)]
+ [TestCase("1e1", 10d)]
+ [TestCase("1e01", 10d)] // Leading decimals are allowed in exponents
+ [TestCase("1E1", 10d)] // Either case is fine
+ [TestCase("-1e1", -10d)]
+ [TestCase("1.5e1", 15d)]
+ [TestCase("-1.5e1", -15d)]
+ [TestCase("15e-1", 1.5d)]
+ [TestCase("-15e-1", -1.5d)]
+ [TestCase("1.79769e308", 1.79769e308)]
+ [TestCase("-1.79769e308", -1.79769e308)]
+ public void NumberToDouble_Valid(string jsonValue, double expectedParsedValue)
+ {
+ string json = "{ \"singleDouble\": " + jsonValue + "}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleDouble);
+ }
+
+ [Test]
+ [TestCase("1.7977e308")]
+ [TestCase("-1.7977e308")]
+ [TestCase("1e309")]
+ [TestCase("1,0")]
+ [TestCase("1.0.0")]
+ [TestCase("+1")]
+ [TestCase("00")]
+ [TestCase("--1")]
+ [TestCase("\u00BD")] // 1/2 as a single Unicode character. Just sanity checking...
+ public void NumberToDouble_Invalid(string jsonValue)
+ {
+ string json = "{ \"singleDouble\": " + jsonValue + "}";
+ Assert.Throws<InvalidJsonException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("0", 0f)]
+ [TestCase("1", 1f)]
+ [TestCase("1.000000", 1f)]
+ [TestCase("-1", -1f)]
+ [TestCase("3.402823e38", 3.402823e38f)]
+ [TestCase("-3.402823e38", -3.402823e38f)]
+ [TestCase("1.5e1", 15f)]
+ [TestCase("15e-1", 1.5f)]
+ public void NumberToFloat_Valid(string jsonValue, float expectedParsedValue)
+ {
+ string json = "{ \"singleFloat\": " + jsonValue + "}";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(expectedParsedValue, parsed.SingleFloat);
+ }
+
+ [Test]
+ [TestCase("3.402824e38", typeof(InvalidProtocolBufferException))]
+ [TestCase("-3.402824e38", typeof(InvalidProtocolBufferException))]
+ [TestCase("1,0", typeof(InvalidJsonException))]
+ [TestCase("1.0.0", typeof(InvalidJsonException))]
+ [TestCase("+1", typeof(InvalidJsonException))]
+ [TestCase("00", typeof(InvalidJsonException))]
+ [TestCase("--1", typeof(InvalidJsonException))]
+ public void NumberToFloat_Invalid(string jsonValue, System.Type expectedExceptionType)
+ {
+ string json = "{ \"singleFloat\": " + jsonValue + "}";
+ Assert.Throws(expectedExceptionType, () => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ // The simplest way of testing that the value has parsed correctly is to reformat it,
+ // as we trust the formatting. In many cases that will give the same result as the input,
+ // so in those cases we accept an expectedFormatted value of null. Sometimes the results
+ // will be different though, due to a different number of digits being provided.
+ [Test]
+ // Z offset
+ [TestCase("2015-10-09T14:46:23.123456789Z", null)]
+ [TestCase("2015-10-09T14:46:23.123456Z", null)]
+ [TestCase("2015-10-09T14:46:23.123Z", null)]
+ [TestCase("2015-10-09T14:46:23Z", null)]
+ [TestCase("2015-10-09T14:46:23.123456000Z", "2015-10-09T14:46:23.123456Z")]
+ [TestCase("2015-10-09T14:46:23.1234560Z", "2015-10-09T14:46:23.123456Z")]
+ [TestCase("2015-10-09T14:46:23.123000000Z", "2015-10-09T14:46:23.123Z")]
+ [TestCase("2015-10-09T14:46:23.1230Z", "2015-10-09T14:46:23.123Z")]
+ [TestCase("2015-10-09T14:46:23.00Z", "2015-10-09T14:46:23Z")]
+
+ // +00:00 offset
+ [TestCase("2015-10-09T14:46:23.123456789+00:00", "2015-10-09T14:46:23.123456789Z")]
+ [TestCase("2015-10-09T14:46:23.123456+00:00", "2015-10-09T14:46:23.123456Z")]
+ [TestCase("2015-10-09T14:46:23.123+00:00", "2015-10-09T14:46:23.123Z")]
+ [TestCase("2015-10-09T14:46:23+00:00", "2015-10-09T14:46:23Z")]
+ [TestCase("2015-10-09T14:46:23.123456000+00:00", "2015-10-09T14:46:23.123456Z")]
+ [TestCase("2015-10-09T14:46:23.1234560+00:00", "2015-10-09T14:46:23.123456Z")]
+ [TestCase("2015-10-09T14:46:23.123000000+00:00", "2015-10-09T14:46:23.123Z")]
+ [TestCase("2015-10-09T14:46:23.1230+00:00", "2015-10-09T14:46:23.123Z")]
+ [TestCase("2015-10-09T14:46:23.00+00:00", "2015-10-09T14:46:23Z")]
+
+ // Other offsets (assume by now that the subsecond handling is okay)
+ [TestCase("2015-10-09T15:46:23.123456789+01:00", "2015-10-09T14:46:23.123456789Z")]
+ [TestCase("2015-10-09T13:46:23.123456789-01:00", "2015-10-09T14:46:23.123456789Z")]
+ [TestCase("2015-10-09T15:16:23.123456789+00:30", "2015-10-09T14:46:23.123456789Z")]
+ [TestCase("2015-10-09T14:16:23.123456789-00:30", "2015-10-09T14:46:23.123456789Z")]
+ [TestCase("2015-10-09T16:31:23.123456789+01:45", "2015-10-09T14:46:23.123456789Z")]
+ [TestCase("2015-10-09T13:01:23.123456789-01:45", "2015-10-09T14:46:23.123456789Z")]
+ [TestCase("2015-10-10T08:46:23.123456789+18:00", "2015-10-09T14:46:23.123456789Z")]
+ [TestCase("2015-10-08T20:46:23.123456789-18:00", "2015-10-09T14:46:23.123456789Z")]
+
+ // Leap years and min/max
+ [TestCase("2016-02-29T14:46:23.123456789Z", null)]
+ [TestCase("2000-02-29T14:46:23.123456789Z", null)]
+ [TestCase("0001-01-01T00:00:00Z", null)]
+ [TestCase("9999-12-31T23:59:59.999999999Z", null)]
+ public void Timestamp_Valid(string jsonValue, string expectedFormatted)
+ {
+ expectedFormatted = expectedFormatted ?? jsonValue;
+ string json = WrapInQuotes(jsonValue);
+ var parsed = Timestamp.Parser.ParseJson(json);
+ Assert.AreEqual(WrapInQuotes(expectedFormatted), parsed.ToString());
+ }
+
+ [Test]
+ [TestCase("2015-10-09 14:46:23.123456789Z", Description = "No T between date and time")]
+ [TestCase("2015/10/09T14:46:23.123456789Z", Description = "Wrong date separators")]
+ [TestCase("2015-10-09T14.46.23.123456789Z", Description = "Wrong time separators")]
+ [TestCase("2015-10-09T14:46:23,123456789Z", Description = "Wrong fractional second separators (valid ISO-8601 though)")]
+ [TestCase(" 2015-10-09T14:46:23.123456789Z", Description = "Whitespace at start")]
+ [TestCase("2015-10-09T14:46:23.123456789Z ", Description = "Whitespace at end")]
+ [TestCase("2015-10-09T14:46:23.1234567890", Description = "Too many digits")]
+ [TestCase("2015-10-09T14:46:23.123456789", Description = "No offset")]
+ [TestCase("2015-13-09T14:46:23.123456789Z", Description = "Invalid month")]
+ [TestCase("2015-10-32T14:46:23.123456789Z", Description = "Invalid day")]
+ [TestCase("2015-10-09T24:00:00.000000000Z", Description = "Invalid hour (valid ISO-8601 though)")]
+ [TestCase("2015-10-09T14:60:23.123456789Z", Description = "Invalid minutes")]
+ [TestCase("2015-10-09T14:46:60.123456789Z", Description = "Invalid seconds")]
+ [TestCase("2015-10-09T14:46:23.123456789+18:01", Description = "Offset too large (positive)")]
+ [TestCase("2015-10-09T14:46:23.123456789-18:01", Description = "Offset too large (negative)")]
+ [TestCase("2015-10-09T14:46:23.123456789-00:00", Description = "Local offset (-00:00) makes no sense here")]
+ [TestCase("0001-01-01T00:00:00+00:01", Description = "Value before earliest when offset applied")]
+ [TestCase("9999-12-31T23:59:59.999999999-00:01", Description = "Value after latest when offset applied")]
+ [TestCase("2100-02-29T14:46:23.123456789Z", Description = "Feb 29th on a non-leap-year")]
+ public void Timestamp_Invalid(string jsonValue)
+ {
+ string json = WrapInQuotes(jsonValue);
+ Assert.Throws<InvalidProtocolBufferException>(() => Timestamp.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void StructValue_Null()
+ {
+ Assert.AreEqual(new Value { NullValue = 0 }, Value.Parser.ParseJson("null"));
+ }
+
+ [Test]
+ public void StructValue_String()
+ {
+ Assert.AreEqual(new Value { StringValue = "hi" }, Value.Parser.ParseJson("\"hi\""));
+ }
+
+ [Test]
+ public void StructValue_Bool()
+ {
+ Assert.AreEqual(new Value { BoolValue = true }, Value.Parser.ParseJson("true"));
+ Assert.AreEqual(new Value { BoolValue = false }, Value.Parser.ParseJson("false"));
+ }
+
+ [Test]
+ public void StructValue_List()
+ {
+ Assert.AreEqual(Value.ForList(Value.ForNumber(1), Value.ForString("x")), Value.Parser.ParseJson("[1, \"x\"]"));
+ }
+
+ [Test]
+ public void ParseListValue()
+ {
+ Assert.AreEqual(new ListValue { Values = { Value.ForNumber(1), Value.ForString("x") } }, ListValue.Parser.ParseJson("[1, \"x\"]"));
+ }
+
+ [Test]
+ public void StructValue_Struct()
+ {
+ Assert.AreEqual(
+ Value.ForStruct(new Struct { Fields = { { "x", Value.ForNumber(1) }, { "y", Value.ForString("z") } } }),
+ Value.Parser.ParseJson("{ \"x\": 1, \"y\": \"z\" }"));
+ }
+
+ [Test]
+ public void ParseStruct()
+ {
+ Assert.AreEqual(new Struct { Fields = { { "x", Value.ForNumber(1) }, { "y", Value.ForString("z") } } },
+ Struct.Parser.ParseJson("{ \"x\": 1, \"y\": \"z\" }"));
+ }
+
+ // TODO for duration parsing: upper and lower bounds.
+ // +/- 315576000000 seconds
+
+ [Test]
+ [TestCase("1.123456789s", null)]
+ [TestCase("1.123456s", null)]
+ [TestCase("1.123s", null)]
+ [TestCase("1.12300s", "1.123s")]
+ [TestCase("1.12345s", "1.123450s")]
+ [TestCase("1s", null)]
+ [TestCase("-1.123456789s", null)]
+ [TestCase("-1.123456s", null)]
+ [TestCase("-1.123s", null)]
+ [TestCase("-1s", null)]
+ [TestCase("0.123s", null)]
+ [TestCase("-0.123s", null)]
+ [TestCase("123456.123s", null)]
+ [TestCase("-123456.123s", null)]
+ // Upper and lower bounds
+ [TestCase("315576000000s", null)]
+ [TestCase("-315576000000s", null)]
+ public void Duration_Valid(string jsonValue, string expectedFormatted)
+ {
+ expectedFormatted = expectedFormatted ?? jsonValue;
+ string json = WrapInQuotes(jsonValue);
+ var parsed = Duration.Parser.ParseJson(json);
+ Assert.AreEqual(WrapInQuotes(expectedFormatted), parsed.ToString());
+ }
+
+ // The simplest way of testing that the value has parsed correctly is to reformat it,
+ // as we trust the formatting. In many cases that will give the same result as the input,
+ // so in those cases we accept an expectedFormatted value of null. Sometimes the results
+ // will be different though, due to a different number of digits being provided.
+ [Test]
+ [TestCase("1.1234567890s", Description = "Too many digits")]
+ [TestCase("1.123456789", Description = "No suffix")]
+ [TestCase("1.123456789ss", Description = "Too much suffix")]
+ [TestCase("1.123456789S", Description = "Upper case suffix")]
+ [TestCase("+1.123456789s", Description = "Leading +")]
+ [TestCase(".123456789s", Description = "No integer before the fraction")]
+ [TestCase("1,123456789s", Description = "Comma as decimal separator")]
+ [TestCase("1x1.123456789s", Description = "Non-digit in integer part")]
+ [TestCase("1.1x3456789s", Description = "Non-digit in fractional part")]
+ [TestCase(" 1.123456789s", Description = "Whitespace before fraction")]
+ [TestCase("1.123456789s ", Description = "Whitespace after value")]
+ [TestCase("01.123456789s", Description = "Leading zero (positive)")]
+ [TestCase("-01.123456789s", Description = "Leading zero (negative)")]
+ [TestCase("--0.123456789s", Description = "Double minus sign")]
+ // Violate upper/lower bounds in various ways
+ [TestCase("315576000001s", Description = "Integer part too large")]
+ [TestCase("3155760000000s", Description = "Integer part too long (positive)")]
+ [TestCase("-3155760000000s", Description = "Integer part too long (negative)")]
+ public void Duration_Invalid(string jsonValue)
+ {
+ string json = WrapInQuotes(jsonValue);
+ Assert.Throws<InvalidProtocolBufferException>(() => Duration.Parser.ParseJson(json));
+ }
+
+ // Not as many tests for field masks as I'd like; more to be added when we have more
+ // detailed specifications.
+
+ [Test]
+ [TestCase("")]
+ [TestCase("foo", "foo")]
+ [TestCase("foo,bar", "foo", "bar")]
+ [TestCase("foo.bar", "foo.bar")]
+ [TestCase("fooBar", "foo_bar")]
+ [TestCase("fooBar.bazQux", "foo_bar.baz_qux")]
+ public void FieldMask_Valid(string jsonValue, params string[] expectedPaths)
+ {
+ string json = WrapInQuotes(jsonValue);
+ var parsed = FieldMask.Parser.ParseJson(json);
+ CollectionAssert.AreEqual(expectedPaths, parsed.Paths);
+ }
+
+ [Test]
+ [TestCase("foo_bar")]
+ public void FieldMask_Invalid(string jsonValue)
+ {
+ string json = WrapInQuotes(jsonValue);
+ Assert.Throws<InvalidProtocolBufferException>(() => FieldMask.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void Any_RegularMessage()
+ {
+ var registry = TypeRegistry.FromMessages(TestAllTypes.Descriptor);
+ var formatter = new JsonFormatter(new JsonFormatter.Settings(false, TypeRegistry.FromMessages(TestAllTypes.Descriptor)));
+ var message = new TestAllTypes { SingleInt32 = 10, SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 20 } };
+ var original = Any.Pack(message);
+ var json = formatter.Format(original); // This is tested in JsonFormatterTest
+ var parser = new JsonParser(new JsonParser.Settings(10, registry));
+ Assert.AreEqual(original, parser.Parse<Any>(json));
+ string valueFirstJson = "{ \"singleInt32\": 10, \"singleNestedMessage\": { \"bb\": 20 }, \"@type\": \"type.googleapis.com/protobuf_unittest.TestAllTypes\" }";
+ Assert.AreEqual(original, parser.Parse<Any>(valueFirstJson));
+ }
+
+ [Test]
+ public void Any_CustomPrefix()
+ {
+ var registry = TypeRegistry.FromMessages(TestAllTypes.Descriptor);
+ var message = new TestAllTypes { SingleInt32 = 10 };
+ var original = Any.Pack(message, "custom.prefix/middle-part");
+ var parser = new JsonParser(new JsonParser.Settings(10, registry));
+ string json = "{ \"@type\": \"custom.prefix/middle-part/protobuf_unittest.TestAllTypes\", \"singleInt32\": 10 }";
+ Assert.AreEqual(original, parser.Parse<Any>(json));
+ }
+
+ [Test]
+ public void Any_UnknownType()
+ {
+ string json = "{ \"@type\": \"type.googleapis.com/bogus\" }";
+ Assert.Throws<InvalidOperationException>(() => Any.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void Any_NoTypeUrl()
+ {
+ string json = "{ \"foo\": \"bar\" }";
+ Assert.Throws<InvalidProtocolBufferException>(() => Any.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void Any_WellKnownType()
+ {
+ var registry = TypeRegistry.FromMessages(Timestamp.Descriptor);
+ var formatter = new JsonFormatter(new JsonFormatter.Settings(false, registry));
+ var timestamp = new DateTime(1673, 6, 19, 12, 34, 56, DateTimeKind.Utc).ToTimestamp();
+ var original = Any.Pack(timestamp);
+ var json = formatter.Format(original); // This is tested in JsonFormatterTest
+ var parser = new JsonParser(new JsonParser.Settings(10, registry));
+ Assert.AreEqual(original, parser.Parse<Any>(json));
+ string valueFirstJson = "{ \"value\": \"1673-06-19T12:34:56Z\", \"@type\": \"type.googleapis.com/google.protobuf.Timestamp\" }";
+ Assert.AreEqual(original, parser.Parse<Any>(valueFirstJson));
+ }
+
+ [Test]
+ public void Any_Nested()
+ {
+ var registry = TypeRegistry.FromMessages(TestWellKnownTypes.Descriptor, TestAllTypes.Descriptor);
+ var formatter = new JsonFormatter(new JsonFormatter.Settings(false, registry));
+ var parser = new JsonParser(new JsonParser.Settings(10, registry));
+ var doubleNestedMessage = new TestAllTypes { SingleInt32 = 20 };
+ var nestedMessage = Any.Pack(doubleNestedMessage);
+ var message = new TestWellKnownTypes { AnyField = Any.Pack(nestedMessage) };
+ var json = formatter.Format(message);
+ // Use the descriptor-based parser just for a change.
+ Assert.AreEqual(message, parser.Parse(json, TestWellKnownTypes.Descriptor));
+ }
+
+ [Test]
+ public void DataAfterObject()
+ {
+ string json = "{} 10";
+ Assert.Throws<InvalidJsonException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ /// <summary>
+ /// JSON equivalent to <see cref="CodedInputStreamTest.MaliciousRecursion"/>
+ /// </summary>
+ [Test]
+ public void MaliciousRecursion()
+ {
+ string data64 = CodedInputStreamTest.MakeRecursiveMessage(64).ToString();
+ string data65 = CodedInputStreamTest.MakeRecursiveMessage(65).ToString();
+
+ var parser64 = new JsonParser(new JsonParser.Settings(64));
+ CodedInputStreamTest.AssertMessageDepth(parser64.Parse<TestRecursiveMessage>(data64), 64);
+ Assert.Throws<InvalidProtocolBufferException>(() => parser64.Parse<TestRecursiveMessage>(data65));
+
+ var parser63 = new JsonParser(new JsonParser.Settings(63));
+ Assert.Throws<InvalidProtocolBufferException>(() => parser63.Parse<TestRecursiveMessage>(data64));
+ }
+
+ [Test]
+ [TestCase("AQI")]
+ [TestCase("_-==")]
+ public void Bytes_InvalidBase64(string badBase64)
+ {
+ string json = "{ \"singleBytes\": \"" + badBase64 + "\" }";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ [TestCase("\"FOREIGN_BAR\"", ForeignEnum.ForeignBar)]
+ [TestCase("5", ForeignEnum.ForeignBar)]
+ [TestCase("100", (ForeignEnum)100)]
+ public void EnumValid(string value, ForeignEnum expectedValue)
+ {
+ string json = "{ \"singleForeignEnum\": " + value + " }";
+ var parsed = TestAllTypes.Parser.ParseJson(json);
+ Assert.AreEqual(new TestAllTypes { SingleForeignEnum = expectedValue }, parsed);
+ }
+
+ [Test]
+ [TestCase("\"NOT_A_VALID_VALUE\"")]
+ [TestCase("5.5")]
+ public void Enum_Invalid(string value)
+ {
+ string json = "{ \"singleForeignEnum\": " + value + " }";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ [Test]
+ public void OneofDuplicate_Invalid()
+ {
+ string json = "{ \"oneofString\": \"x\", \"oneofUint32\": 10 }";
+ Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseJson(json));
+ }
+
+ /// <summary>
+ /// Various tests use strings which have quotes round them for parsing or as the result
+ /// of formatting, but without those quotes being specified in the tests (for the sake of readability).
+ /// This method simply returns the input, wrapped in double quotes.
+ /// </summary>
+ internal static string WrapInQuotes(string text)
+ {
+ return '"' + text + '"';
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs
new file mode 100644
index 0000000000..527ab3361e
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs
@@ -0,0 +1,408 @@
+#region Copyright notice and license
+// 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.
+#endregion
+using NUnit.Framework;
+using System;
+using System.IO;
+
+namespace Google.Protobuf
+{
+ public class JsonTokenizerTest
+ {
+ [Test]
+ public void EmptyObjectValue()
+ {
+ AssertTokens("{}", JsonToken.StartObject, JsonToken.EndObject);
+ }
+
+ [Test]
+ public void EmptyArrayValue()
+ {
+ AssertTokens("[]", JsonToken.StartArray, JsonToken.EndArray);
+ }
+
+ [Test]
+ [TestCase("foo", "foo")]
+ [TestCase("tab\\t", "tab\t")]
+ [TestCase("line\\nfeed", "line\nfeed")]
+ [TestCase("carriage\\rreturn", "carriage\rreturn")]
+ [TestCase("back\\bspace", "back\bspace")]
+ [TestCase("form\\ffeed", "form\ffeed")]
+ [TestCase("escaped\\/slash", "escaped/slash")]
+ [TestCase("escaped\\\\backslash", "escaped\\backslash")]
+ [TestCase("escaped\\\"quote", "escaped\"quote")]
+ [TestCase("foo {}[] bar", "foo {}[] bar")]
+ [TestCase("foo\\u09aFbar", "foo\u09afbar")] // Digits, upper hex, lower hex
+ [TestCase("ab\ud800\udc00cd", "ab\ud800\udc00cd")]
+ [TestCase("ab\\ud800\\udc00cd", "ab\ud800\udc00cd")]
+ public void StringValue(string json, string expectedValue)
+ {
+ AssertTokensNoReplacement("\"" + json + "\"", JsonToken.Value(expectedValue));
+ }
+
+ // Valid surrogate pairs, with mixed escaping. These test cases can't be expressed
+ // using TestCase as they have no valid UTF-8 representation.
+ // It's unclear exactly how we should handle a mixture of escaped or not: that can't
+ // come from UTF-8 text, but could come from a .NET string. For the moment,
+ // treat it as valid in the obvious way.
+ [Test]
+ public void MixedSurrogatePairs()
+ {
+ string expected = "\ud800\udc00";
+ AssertTokens("'\\ud800\udc00'", JsonToken.Value(expected));
+ AssertTokens("'\ud800\\udc00'", JsonToken.Value(expected));
+ }
+
+ [Test]
+ public void ObjectDepth()
+ {
+ string json = "{ \"foo\": { \"x\": 1, \"y\": [ 0 ] } }";
+ var tokenizer = JsonTokenizer.FromTextReader(new StringReader(json));
+ // If we had more tests like this, I'd introduce a helper method... but for one test, it's not worth it.
+ Assert.AreEqual(0, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.StartObject, tokenizer.Next());
+ Assert.AreEqual(1, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.Name("foo"), tokenizer.Next());
+ Assert.AreEqual(1, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.StartObject, tokenizer.Next());
+ Assert.AreEqual(2, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.Name("x"), tokenizer.Next());
+ Assert.AreEqual(2, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.Value(1), tokenizer.Next());
+ Assert.AreEqual(2, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.Name("y"), tokenizer.Next());
+ Assert.AreEqual(2, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.StartArray, tokenizer.Next());
+ Assert.AreEqual(2, tokenizer.ObjectDepth); // Depth hasn't changed in array
+ Assert.AreEqual(JsonToken.Value(0), tokenizer.Next());
+ Assert.AreEqual(2, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.EndArray, tokenizer.Next());
+ Assert.AreEqual(2, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.EndObject, tokenizer.Next());
+ Assert.AreEqual(1, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.EndObject, tokenizer.Next());
+ Assert.AreEqual(0, tokenizer.ObjectDepth);
+ Assert.AreEqual(JsonToken.EndDocument, tokenizer.Next());
+ Assert.AreEqual(0, tokenizer.ObjectDepth);
+ }
+
+ [Test]
+ public void ObjectDepth_WithPushBack()
+ {
+ string json = "{}";
+ var tokenizer = JsonTokenizer.FromTextReader(new StringReader(json));
+ Assert.AreEqual(0, tokenizer.ObjectDepth);
+ var token = tokenizer.Next();
+ Assert.AreEqual(1, tokenizer.ObjectDepth);
+ // When we push back a "start object", we should effectively be back to the previous depth.
+ tokenizer.PushBack(token);
+ Assert.AreEqual(0, tokenizer.ObjectDepth);
+ // Read the same token again, and get back to depth 1
+ token = tokenizer.Next();
+ Assert.AreEqual(1, tokenizer.ObjectDepth);
+
+ // Now the same in reverse, with EndObject
+ token = tokenizer.Next();
+ Assert.AreEqual(0, tokenizer.ObjectDepth);
+ tokenizer.PushBack(token);
+ Assert.AreEqual(1, tokenizer.ObjectDepth);
+ tokenizer.Next();
+ Assert.AreEqual(0, tokenizer.ObjectDepth);
+ }
+
+ [Test]
+ [TestCase("embedded tab\t")]
+ [TestCase("embedded CR\r")]
+ [TestCase("embedded LF\n")]
+ [TestCase("embedded bell\u0007")]
+ [TestCase("bad escape\\a")]
+ [TestCase("incomplete escape\\")]
+ [TestCase("incomplete Unicode escape\\u000")]
+ [TestCase("invalid Unicode escape\\u000H")]
+ // Surrogate pair handling, both in raw .NET strings and escaped. We only need
+ // to detect this in strings, as non-ASCII characters anywhere other than in strings
+ // will already lead to parsing errors.
+ [TestCase("\\ud800")]
+ [TestCase("\\udc00")]
+ [TestCase("\\ud800x")]
+ [TestCase("\\udc00x")]
+ [TestCase("\\udc00\\ud800y")]
+ public void InvalidStringValue(string json)
+ {
+ AssertThrowsAfter("\"" + json + "\"");
+ }
+
+ // Tests for invalid strings that can't be expressed in attributes,
+ // as the constants can't be expressed as UTF-8 strings.
+ [Test]
+ public void InvalidSurrogatePairs()
+ {
+ AssertThrowsAfter("\"\ud800x\"");
+ AssertThrowsAfter("\"\udc00y\"");
+ AssertThrowsAfter("\"\udc00\ud800y\"");
+ }
+
+ [Test]
+ [TestCase("0", 0)]
+ [TestCase("-0", 0)] // We don't distinguish between positive and negative 0
+ [TestCase("1", 1)]
+ [TestCase("-1", -1)]
+ // From here on, assume leading sign is okay...
+ [TestCase("1.125", 1.125)]
+ [TestCase("1.0", 1)]
+ [TestCase("1e5", 100000)]
+ [TestCase("1e000000", 1)] // Weird, but not prohibited by the spec
+ [TestCase("1E5", 100000)]
+ [TestCase("1e+5", 100000)]
+ [TestCase("1E-5", 0.00001)]
+ [TestCase("123E-2", 1.23)]
+ [TestCase("123.45E3", 123450)]
+ [TestCase(" 1 ", 1)]
+ public void NumberValue(string json, double expectedValue)
+ {
+ AssertTokens(json, JsonToken.Value(expectedValue));
+ }
+
+ [Test]
+ [TestCase("00")]
+ [TestCase(".5")]
+ [TestCase("1.")]
+ [TestCase("1e")]
+ [TestCase("1e-")]
+ [TestCase("--")]
+ [TestCase("--1")]
+ [TestCase("-1.7977e308")]
+ [TestCase("1.7977e308")]
+ public void InvalidNumberValue(string json)
+ {
+ AssertThrowsAfter(json);
+ }
+
+ [Test]
+ [TestCase("nul")]
+ [TestCase("nothing")]
+ [TestCase("truth")]
+ [TestCase("fALSEhood")]
+ public void InvalidLiterals(string json)
+ {
+ AssertThrowsAfter(json);
+ }
+
+ [Test]
+ public void NullValue()
+ {
+ AssertTokens("null", JsonToken.Null);
+ }
+
+ [Test]
+ public void TrueValue()
+ {
+ AssertTokens("true", JsonToken.True);
+ }
+
+ [Test]
+ public void FalseValue()
+ {
+ AssertTokens("false", JsonToken.False);
+ }
+
+ [Test]
+ public void SimpleObject()
+ {
+ AssertTokens("{'x': 'y'}",
+ JsonToken.StartObject, JsonToken.Name("x"), JsonToken.Value("y"), JsonToken.EndObject);
+ }
+
+ [Test]
+ [TestCase("[10, 20", 3)]
+ [TestCase("[10,", 2)]
+ [TestCase("[10:20]", 2)]
+ [TestCase("[", 1)]
+ [TestCase("[,", 1)]
+ [TestCase("{", 1)]
+ [TestCase("{,", 1)]
+ [TestCase("{[", 1)]
+ [TestCase("{{", 1)]
+ [TestCase("{0", 1)]
+ [TestCase("{null", 1)]
+ [TestCase("{false", 1)]
+ [TestCase("{true", 1)]
+ [TestCase("}", 0)]
+ [TestCase("]", 0)]
+ [TestCase(",", 0)]
+ [TestCase("'foo' 'bar'", 1)]
+ [TestCase(":", 0)]
+ [TestCase("'foo", 0)] // Incomplete string
+ [TestCase("{ 'foo' }", 2)]
+ [TestCase("{ x:1", 1)] // Property names must be quoted
+ [TestCase("{]", 1)]
+ [TestCase("[}", 1)]
+ [TestCase("[1,", 2)]
+ [TestCase("{'x':0]", 3)]
+ [TestCase("{ 'foo': }", 2)]
+ [TestCase("{ 'foo':'bar', }", 3)]
+ public void InvalidStructure(string json, int expectedValidTokens)
+ {
+ // Note: we don't test that the earlier tokens are exactly as expected,
+ // partly because that's hard to parameterize.
+ var reader = new StringReader(json.Replace('\'', '"'));
+ var tokenizer = JsonTokenizer.FromTextReader(reader);
+ for (int i = 0; i < expectedValidTokens; i++)
+ {
+ Assert.IsNotNull(tokenizer.Next());
+ }
+ Assert.Throws<InvalidJsonException>(() => tokenizer.Next());
+ }
+
+ [Test]
+ public void ArrayMixedType()
+ {
+ AssertTokens("[1, 'foo', null, false, true, [2], {'x':'y' }]",
+ JsonToken.StartArray,
+ JsonToken.Value(1),
+ JsonToken.Value("foo"),
+ JsonToken.Null,
+ JsonToken.False,
+ JsonToken.True,
+ JsonToken.StartArray,
+ JsonToken.Value(2),
+ JsonToken.EndArray,
+ JsonToken.StartObject,
+ JsonToken.Name("x"),
+ JsonToken.Value("y"),
+ JsonToken.EndObject,
+ JsonToken.EndArray);
+ }
+
+ [Test]
+ public void ObjectMixedType()
+ {
+ AssertTokens(@"{'a': 1, 'b': 'bar', 'c': null, 'd': false, 'e': true,
+ 'f': [2], 'g': {'x':'y' }}",
+ JsonToken.StartObject,
+ JsonToken.Name("a"),
+ JsonToken.Value(1),
+ JsonToken.Name("b"),
+ JsonToken.Value("bar"),
+ JsonToken.Name("c"),
+ JsonToken.Null,
+ JsonToken.Name("d"),
+ JsonToken.False,
+ JsonToken.Name("e"),
+ JsonToken.True,
+ JsonToken.Name("f"),
+ JsonToken.StartArray,
+ JsonToken.Value(2),
+ JsonToken.EndArray,
+ JsonToken.Name("g"),
+ JsonToken.StartObject,
+ JsonToken.Name("x"),
+ JsonToken.Value("y"),
+ JsonToken.EndObject,
+ JsonToken.EndObject);
+ }
+
+ [Test]
+ public void NextAfterEndDocumentThrows()
+ {
+ var tokenizer = JsonTokenizer.FromTextReader(new StringReader("null"));
+ Assert.AreEqual(JsonToken.Null, tokenizer.Next());
+ Assert.AreEqual(JsonToken.EndDocument, tokenizer.Next());
+ Assert.Throws<InvalidOperationException>(() => tokenizer.Next());
+ }
+
+ [Test]
+ public void CanPushBackEndDocument()
+ {
+ var tokenizer = JsonTokenizer.FromTextReader(new StringReader("null"));
+ Assert.AreEqual(JsonToken.Null, tokenizer.Next());
+ Assert.AreEqual(JsonToken.EndDocument, tokenizer.Next());
+ tokenizer.PushBack(JsonToken.EndDocument);
+ Assert.AreEqual(JsonToken.EndDocument, tokenizer.Next());
+ Assert.Throws<InvalidOperationException>(() => tokenizer.Next());
+ }
+
+ /// <summary>
+ /// Asserts that the specified JSON is tokenized into the given sequence of tokens.
+ /// All apostrophes are first converted to double quotes, allowing any tests
+ /// that don't need to check actual apostrophe handling to use apostrophes in the JSON, avoiding
+ /// messy string literal escaping. The "end document" token is not specified in the list of
+ /// expected tokens, but is implicit.
+ /// </summary>
+ private static void AssertTokens(string json, params JsonToken[] expectedTokens)
+ {
+ AssertTokensNoReplacement(json.Replace('\'', '"'), expectedTokens);
+ }
+
+ /// <summary>
+ /// Asserts that the specified JSON is tokenized into the given sequence of tokens.
+ /// Unlike <see cref="AssertTokens(string, JsonToken[])"/>, this does not perform any character
+ /// replacement on the specified JSON, and should be used when the text contains apostrophes which
+ /// are expected to be used *as* apostrophes. The "end document" token is not specified in the list of
+ /// expected tokens, but is implicit.
+ /// </summary>
+ private static void AssertTokensNoReplacement(string json, params JsonToken[] expectedTokens)
+ {
+ var reader = new StringReader(json);
+ var tokenizer = JsonTokenizer.FromTextReader(reader);
+ for (int i = 0; i < expectedTokens.Length; i++)
+ {
+ var actualToken = tokenizer.Next();
+ if (actualToken == JsonToken.EndDocument)
+ {
+ Assert.Fail("Expected {0} but reached end of token stream", expectedTokens[i]);
+ }
+ Assert.AreEqual(expectedTokens[i], actualToken);
+ }
+ var finalToken = tokenizer.Next();
+ if (finalToken != JsonToken.EndDocument)
+ {
+ Assert.Fail("Expected token stream to be exhausted; received {0}", finalToken);
+ }
+ }
+
+ private static void AssertThrowsAfter(string json, params JsonToken[] expectedTokens)
+ {
+ var reader = new StringReader(json);
+ var tokenizer = JsonTokenizer.FromTextReader(reader);
+ for (int i = 0; i < expectedTokens.Length; i++)
+ {
+ var actualToken = tokenizer.Next();
+ if (actualToken == JsonToken.EndDocument)
+ {
+ Assert.Fail("Expected {0} but reached end of document", expectedTokens[i]);
+ }
+ Assert.AreEqual(expectedTokens[i], actualToken);
+ }
+ Assert.Throws<InvalidJsonException>(() => tokenizer.Next());
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs
new file mode 100644
index 0000000000..68b4d6af7c
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs
@@ -0,0 +1,271 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2017 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.
+#endregion
+
+using Google.Protobuf.Reflection;
+using Google.Protobuf.WellKnownTypes;
+using NUnit.Framework;
+using System.IO;
+using System.Linq;
+using UnitTest.Issues.TestProtos;
+using static Google.Protobuf.WireFormat;
+using static UnitTest.Issues.TestProtos.ComplexOptionType2.Types;
+using static UnitTest.Issues.TestProtos.DummyMessageContainingEnum.Types;
+using static Google.Protobuf.Test.Reflection.CustomOptionNumber;
+
+namespace Google.Protobuf.Test.Reflection
+{
+ // Internal enum to allow us to use "using static" for convenience.
+ // These are the options defined in unittest_custom_options_proto3.proto
+ internal enum CustomOptionNumber
+ {
+ FileOpt1 = 7736974,
+ MessageOpt1 = 7739036,
+ FieldOpt1 = 7740936,
+ OneofOpt1 = 7740111,
+ EnumOpt1 = 7753576,
+ EnumValueOpt1 = 1560678,
+ ServiceOpt1 = 7887650,
+ MethodOpt1 = 7890860,
+
+ // All message options...
+ BoolOpt = 7706090,
+ Int32Opt = 7705709,
+ Int64Opt = 7705542,
+ UInt32Opt = 7704880,
+ UInt64Opt = 7702367,
+ SInt32Opt = 7701568,
+ SInt64Opt = 7700863,
+ Fixed32Opt = 7700307,
+ Fixed64Opt = 7700194,
+ SFixed32Opt = 7698645,
+ SFixed64Opt = 7685475,
+ FloatOpt = 7675390,
+ DoubleOpt = 7673293,
+ StringOpt = 7673285,
+ BytesOpt = 7673238,
+ EnumOpt = 7673233,
+ MessageTypeOpt = 7665967,
+
+ // Miscellaneous
+ ComplexOpt4 = 7633546,
+ ComplexOpt1 = 7646756,
+ ComplexOpt2 = 7636949,
+ ComplexOpt3 = 7636463,
+
+ // Aggregates
+ AggregateFileOpt = 15478479,
+ AggregateMsgOpt = 15480088,
+ AggregateFieldOpt = 15481374,
+ AggregateEnumOpt = 15483218,
+ AggregateEnumValueOpt = 15486921,
+ AggregateServiceOpt = 15497145,
+ AggregateMethodOpt = 15512713,
+ }
+
+ /// <summary>
+ /// The majority of the testing here is done via parsed descriptors. That's simpler to
+ /// achieve (and more important) than constructing a CodedInputStream manually.
+ /// </summary>
+ public class CustomOptionsTest
+ {
+ delegate bool OptionFetcher<T>(int field, out T value);
+
+ [Test]
+ public void EmptyOptionsIsShared()
+ {
+ var structOptions = Struct.Descriptor.CustomOptions;
+ var timestampOptions = Struct.Descriptor.CustomOptions;
+ Assert.AreSame(structOptions, timestampOptions);
+ }
+
+ [Test]
+ public void SimpleIntegerTest()
+ {
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ output.WriteTag(MakeTag(1, WireType.Varint));
+ output.WriteInt32(1234567);
+ output.Flush();
+ stream.Position = 0;
+ var input = new CodedInputStream(stream);
+ input.ReadTag();
+
+ var options = CustomOptions.Empty;
+ options = options.ReadOrSkipUnknownField(input);
+
+ int intValue;
+ Assert.True(options.TryGetInt32(1, out intValue));
+ Assert.AreEqual(1234567, intValue);
+
+ string stringValue;
+ // No ByteString stored values
+ Assert.False(options.TryGetString(1, out stringValue));
+ // Nothing stored for field 2
+ Assert.False(options.TryGetInt32(2, out intValue));
+ }
+
+ [Test]
+ public void SimpleStringTest()
+ {
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ output.WriteTag(MakeTag(1, WireType.LengthDelimited));
+ output.WriteString("value");
+ output.Flush();
+ stream.Position = 0;
+ var input = new CodedInputStream(stream);
+ input.ReadTag();
+
+ var options = CustomOptions.Empty;
+ options = options.ReadOrSkipUnknownField(input);
+
+ string stringValue;
+ Assert.True(options.TryGetString(1, out stringValue));
+ Assert.AreEqual("value", stringValue);
+
+ int intValue;
+ // No numeric stored values
+ Assert.False(options.TryGetInt32(1, out intValue));
+ // Nothing stored for field 2
+ Assert.False(options.TryGetString(2, out stringValue));
+ }
+
+ [Test]
+ public void ScalarOptions()
+ {
+ var options = CustomOptionOtherValues.Descriptor.CustomOptions;
+ AssertOption(-100, options.TryGetInt32, Int32Opt);
+ AssertOption(12.3456789f, options.TryGetFloat, FloatOpt);
+ AssertOption(1.234567890123456789d, options.TryGetDouble, DoubleOpt);
+ AssertOption("Hello, \"World\"", options.TryGetString, StringOpt);
+ AssertOption(ByteString.CopyFromUtf8("Hello\0World"), options.TryGetBytes, BytesOpt);
+ AssertOption((int) TestEnumType.TestOptionEnumType2, options.TryGetInt32, EnumOpt);
+ }
+
+ [Test]
+ public void MessageOptions()
+ {
+ var options = VariousComplexOptions.Descriptor.CustomOptions;
+ AssertOption(new ComplexOptionType1 { Foo = 42, Foo4 = { 99, 88 } }, options.TryGetMessage, ComplexOpt1);
+ AssertOption(new ComplexOptionType2
+ {
+ Baz = 987, Bar = new ComplexOptionType1 { Foo = 743 },
+ Fred = new ComplexOptionType4 { Waldo = 321 },
+ Barney = { new ComplexOptionType4 { Waldo = 101 }, new ComplexOptionType4 { Waldo = 212 } }
+ },
+ options.TryGetMessage, ComplexOpt2);
+ AssertOption(new ComplexOptionType3 { Qux = 9 }, options.TryGetMessage, ComplexOpt3);
+ }
+
+ [Test]
+ public void OptionLocations()
+ {
+ var fileOptions = UnittestCustomOptionsProto3Reflection.Descriptor.CustomOptions;
+ AssertOption(9876543210UL, fileOptions.TryGetUInt64, FileOpt1);
+
+ var messageOptions = TestMessageWithCustomOptions.Descriptor.CustomOptions;
+ AssertOption(-56, messageOptions.TryGetInt32, MessageOpt1);
+
+ var fieldOptions = TestMessageWithCustomOptions.Descriptor.Fields["field1"] .CustomOptions;
+ AssertOption(8765432109UL, fieldOptions.TryGetFixed64, FieldOpt1);
+
+ var oneofOptions = TestMessageWithCustomOptions.Descriptor.Oneofs[0].CustomOptions;
+ AssertOption(-99, oneofOptions.TryGetInt32, OneofOpt1);
+
+ var enumOptions = TestMessageWithCustomOptions.Descriptor.EnumTypes[0].CustomOptions;
+ AssertOption(-789, enumOptions.TryGetSFixed32, EnumOpt1);
+
+ var enumValueOptions = TestMessageWithCustomOptions.Descriptor.EnumTypes[0].FindValueByNumber(2).CustomOptions;
+ AssertOption(123, enumValueOptions.TryGetInt32, EnumValueOpt1);
+
+ var service = UnittestCustomOptionsProto3Reflection.Descriptor.Services
+ .Single(s => s.Name == "TestServiceWithCustomOptions");
+ var serviceOptions = service.CustomOptions;
+ AssertOption(-9876543210, serviceOptions.TryGetSInt64, ServiceOpt1);
+
+ var methodOptions = service.Methods[0].CustomOptions;
+ AssertOption((int) UnitTest.Issues.TestProtos.MethodOpt1.Val2, methodOptions.TryGetInt32, CustomOptionNumber.MethodOpt1);
+ }
+
+ [Test]
+ public void MinValues()
+ {
+ var options = CustomOptionMinIntegerValues.Descriptor.CustomOptions;
+ AssertOption(false, options.TryGetBool, BoolOpt);
+ AssertOption(int.MinValue, options.TryGetInt32, Int32Opt);
+ AssertOption(long.MinValue, options.TryGetInt64, Int64Opt);
+ AssertOption(uint.MinValue, options.TryGetUInt32, UInt32Opt);
+ AssertOption(ulong.MinValue, options.TryGetUInt64, UInt64Opt);
+ AssertOption(int.MinValue, options.TryGetSInt32, SInt32Opt);
+ AssertOption(long.MinValue, options.TryGetSInt64, SInt64Opt);
+ AssertOption(uint.MinValue, options.TryGetUInt32, Fixed32Opt);
+ AssertOption(ulong.MinValue, options.TryGetUInt64, Fixed64Opt);
+ AssertOption(int.MinValue, options.TryGetInt32, SFixed32Opt);
+ AssertOption(long.MinValue, options.TryGetInt64, SFixed64Opt);
+ }
+
+ [Test]
+ public void MaxValues()
+ {
+ var options = CustomOptionMaxIntegerValues.Descriptor.CustomOptions;
+ AssertOption(true, options.TryGetBool, BoolOpt);
+ AssertOption(int.MaxValue, options.TryGetInt32, Int32Opt);
+ AssertOption(long.MaxValue, options.TryGetInt64, Int64Opt);
+ AssertOption(uint.MaxValue, options.TryGetUInt32, UInt32Opt);
+ AssertOption(ulong.MaxValue, options.TryGetUInt64, UInt64Opt);
+ AssertOption(int.MaxValue, options.TryGetSInt32, SInt32Opt);
+ AssertOption(long.MaxValue, options.TryGetSInt64, SInt64Opt);
+ AssertOption(uint.MaxValue, options.TryGetFixed32, Fixed32Opt);
+ AssertOption(ulong.MaxValue, options.TryGetFixed64, Fixed64Opt);
+ AssertOption(int.MaxValue, options.TryGetSFixed32, SFixed32Opt);
+ AssertOption(long.MaxValue, options.TryGetSFixed64, SFixed64Opt);
+ }
+
+ [Test]
+ public void AggregateOptions()
+ {
+ // Just two examples
+ var messageOptions = AggregateMessage.Descriptor.CustomOptions;
+ AssertOption(new Aggregate { I = 101, S = "MessageAnnotation" }, messageOptions.TryGetMessage, AggregateMsgOpt);
+
+ var fieldOptions = AggregateMessage.Descriptor.Fields["fieldname"].CustomOptions;
+ AssertOption(new Aggregate { S = "FieldAnnotation" }, fieldOptions.TryGetMessage, AggregateFieldOpt);
+ }
+
+ private void AssertOption<T>(T expected, OptionFetcher<T> fetcher, CustomOptionNumber field)
+ {
+ T actual;
+ Assert.IsTrue(fetcher((int) field, out actual));
+ Assert.AreEqual(expected, actual);
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
new file mode 100644
index 0000000000..52d5a67697
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
@@ -0,0 +1,259 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System.Linq;
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+using UnitTest.Issues.TestProtos;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Tests for descriptors. (Not in its own namespace or broken up into individual classes as the
+ /// size doesn't warrant it. On the other hand, this makes me feel a bit dirty...)
+ /// </summary>
+ public class DescriptorsTest
+ {
+ [Test]
+ public void FileDescriptor()
+ {
+ FileDescriptor file = UnittestProto3Reflection.Descriptor;
+
+ Assert.AreEqual("google/protobuf/unittest_proto3.proto", file.Name);
+ Assert.AreEqual("protobuf_unittest", file.Package);
+
+ Assert.AreEqual("UnittestProto", file.Proto.Options.JavaOuterClassname);
+ Assert.AreEqual("google/protobuf/unittest_proto3.proto", file.Proto.Name);
+
+ // unittest.proto doesn't have any public imports, but unittest_import.proto does.
+ Assert.AreEqual(0, file.PublicDependencies.Count);
+ Assert.AreEqual(1, UnittestImportProto3Reflection.Descriptor.PublicDependencies.Count);
+ Assert.AreEqual(UnittestImportPublicProto3Reflection.Descriptor, UnittestImportProto3Reflection.Descriptor.PublicDependencies[0]);
+
+ Assert.AreEqual(1, file.Dependencies.Count);
+ Assert.AreEqual(UnittestImportProto3Reflection.Descriptor, file.Dependencies[0]);
+
+ MessageDescriptor messageType = TestAllTypes.Descriptor;
+ Assert.AreSame(typeof(TestAllTypes), messageType.ClrType);
+ Assert.AreSame(TestAllTypes.Parser, messageType.Parser);
+ Assert.AreEqual(messageType, file.MessageTypes[0]);
+ Assert.AreEqual(messageType, file.FindTypeByName<MessageDescriptor>("TestAllTypes"));
+ Assert.Null(file.FindTypeByName<MessageDescriptor>("NoSuchType"));
+ Assert.Null(file.FindTypeByName<MessageDescriptor>("protobuf_unittest.TestAllTypes"));
+ for (int i = 0; i < file.MessageTypes.Count; i++)
+ {
+ Assert.AreEqual(i, file.MessageTypes[i].Index);
+ }
+
+ Assert.AreEqual(file.EnumTypes[0], file.FindTypeByName<EnumDescriptor>("ForeignEnum"));
+ Assert.Null(file.FindTypeByName<EnumDescriptor>("NoSuchType"));
+ Assert.Null(file.FindTypeByName<EnumDescriptor>("protobuf_unittest.ForeignEnum"));
+ Assert.AreEqual(1, UnittestImportProto3Reflection.Descriptor.EnumTypes.Count);
+ Assert.AreEqual("ImportEnum", UnittestImportProto3Reflection.Descriptor.EnumTypes[0].Name);
+ for (int i = 0; i < file.EnumTypes.Count; i++)
+ {
+ Assert.AreEqual(i, file.EnumTypes[i].Index);
+ }
+
+ Assert.AreEqual(10, file.SerializedData[0]);
+ }
+
+ [Test]
+ public void MessageDescriptor()
+ {
+ MessageDescriptor messageType = TestAllTypes.Descriptor;
+ MessageDescriptor nestedType = TestAllTypes.Types.NestedMessage.Descriptor;
+
+ Assert.AreEqual("TestAllTypes", messageType.Name);
+ Assert.AreEqual("protobuf_unittest.TestAllTypes", messageType.FullName);
+ Assert.AreEqual(UnittestProto3Reflection.Descriptor, messageType.File);
+ Assert.IsNull(messageType.ContainingType);
+ Assert.IsNull(messageType.Proto.Options);
+
+ Assert.AreEqual("TestAllTypes", messageType.Name);
+
+ Assert.AreEqual("NestedMessage", nestedType.Name);
+ Assert.AreEqual("protobuf_unittest.TestAllTypes.NestedMessage", nestedType.FullName);
+ Assert.AreEqual(UnittestProto3Reflection.Descriptor, nestedType.File);
+ Assert.AreEqual(messageType, nestedType.ContainingType);
+
+ FieldDescriptor field = messageType.Fields.InDeclarationOrder()[0];
+ Assert.AreEqual("single_int32", field.Name);
+ Assert.AreEqual(field, messageType.FindDescriptor<FieldDescriptor>("single_int32"));
+ Assert.Null(messageType.FindDescriptor<FieldDescriptor>("no_such_field"));
+ Assert.AreEqual(field, messageType.FindFieldByNumber(1));
+ Assert.Null(messageType.FindFieldByNumber(571283));
+ var fieldsInDeclarationOrder = messageType.Fields.InDeclarationOrder();
+ for (int i = 0; i < fieldsInDeclarationOrder.Count; i++)
+ {
+ Assert.AreEqual(i, fieldsInDeclarationOrder[i].Index);
+ }
+
+ Assert.AreEqual(nestedType, messageType.NestedTypes[0]);
+ Assert.AreEqual(nestedType, messageType.FindDescriptor<MessageDescriptor>("NestedMessage"));
+ Assert.Null(messageType.FindDescriptor<MessageDescriptor>("NoSuchType"));
+ for (int i = 0; i < messageType.NestedTypes.Count; i++)
+ {
+ Assert.AreEqual(i, messageType.NestedTypes[i].Index);
+ }
+
+ Assert.AreEqual(messageType.EnumTypes[0], messageType.FindDescriptor<EnumDescriptor>("NestedEnum"));
+ Assert.Null(messageType.FindDescriptor<EnumDescriptor>("NoSuchType"));
+ for (int i = 0; i < messageType.EnumTypes.Count; i++)
+ {
+ Assert.AreEqual(i, messageType.EnumTypes[i].Index);
+ }
+ }
+
+ [Test]
+ public void FieldDescriptor()
+ {
+ MessageDescriptor messageType = TestAllTypes.Descriptor;
+ FieldDescriptor primitiveField = messageType.FindDescriptor<FieldDescriptor>("single_int32");
+ FieldDescriptor enumField = messageType.FindDescriptor<FieldDescriptor>("single_nested_enum");
+ FieldDescriptor messageField = messageType.FindDescriptor<FieldDescriptor>("single_foreign_message");
+
+ Assert.AreEqual("single_int32", primitiveField.Name);
+ Assert.AreEqual("protobuf_unittest.TestAllTypes.single_int32",
+ primitiveField.FullName);
+ Assert.AreEqual(1, primitiveField.FieldNumber);
+ Assert.AreEqual(messageType, primitiveField.ContainingType);
+ Assert.AreEqual(UnittestProto3Reflection.Descriptor, primitiveField.File);
+ Assert.AreEqual(FieldType.Int32, primitiveField.FieldType);
+ Assert.IsNull(primitiveField.Proto.Options);
+
+ Assert.AreEqual("single_nested_enum", enumField.Name);
+ Assert.AreEqual(FieldType.Enum, enumField.FieldType);
+ // Assert.AreEqual(TestAllTypes.Types.NestedEnum.DescriptorProtoFile, enumField.EnumType);
+
+ Assert.AreEqual("single_foreign_message", messageField.Name);
+ Assert.AreEqual(FieldType.Message, messageField.FieldType);
+ Assert.AreEqual(ForeignMessage.Descriptor, messageField.MessageType);
+ }
+
+ [Test]
+ public void FieldDescriptorLabel()
+ {
+ FieldDescriptor singleField =
+ TestAllTypes.Descriptor.FindDescriptor<FieldDescriptor>("single_int32");
+ FieldDescriptor repeatedField =
+ TestAllTypes.Descriptor.FindDescriptor<FieldDescriptor>("repeated_int32");
+
+ Assert.IsFalse(singleField.IsRepeated);
+ Assert.IsTrue(repeatedField.IsRepeated);
+ }
+
+ [Test]
+ public void EnumDescriptor()
+ {
+ // Note: this test is a bit different to the Java version because there's no static way of getting to the descriptor
+ EnumDescriptor enumType = UnittestProto3Reflection.Descriptor.FindTypeByName<EnumDescriptor>("ForeignEnum");
+ EnumDescriptor nestedType = TestAllTypes.Descriptor.FindDescriptor<EnumDescriptor>("NestedEnum");
+
+ Assert.AreEqual("ForeignEnum", enumType.Name);
+ Assert.AreEqual("protobuf_unittest.ForeignEnum", enumType.FullName);
+ Assert.AreEqual(UnittestProto3Reflection.Descriptor, enumType.File);
+ Assert.Null(enumType.ContainingType);
+ Assert.Null(enumType.Proto.Options);
+
+ Assert.AreEqual("NestedEnum", nestedType.Name);
+ Assert.AreEqual("protobuf_unittest.TestAllTypes.NestedEnum",
+ nestedType.FullName);
+ Assert.AreEqual(UnittestProto3Reflection.Descriptor, nestedType.File);
+ Assert.AreEqual(TestAllTypes.Descriptor, nestedType.ContainingType);
+
+ EnumValueDescriptor value = enumType.FindValueByName("FOREIGN_FOO");
+ Assert.AreEqual(value, enumType.Values[1]);
+ Assert.AreEqual("FOREIGN_FOO", value.Name);
+ Assert.AreEqual(4, value.Number);
+ Assert.AreEqual((int) ForeignEnum.ForeignFoo, value.Number);
+ Assert.AreEqual(value, enumType.FindValueByNumber(4));
+ Assert.Null(enumType.FindValueByName("NO_SUCH_VALUE"));
+ for (int i = 0; i < enumType.Values.Count; i++)
+ {
+ Assert.AreEqual(i, enumType.Values[i].Index);
+ }
+ }
+
+ [Test]
+ public void OneofDescriptor()
+ {
+ OneofDescriptor descriptor = TestAllTypes.Descriptor.FindDescriptor<OneofDescriptor>("oneof_field");
+ Assert.AreEqual("oneof_field", descriptor.Name);
+ Assert.AreEqual("protobuf_unittest.TestAllTypes.oneof_field", descriptor.FullName);
+
+ var expectedFields = new[] {
+ TestAllTypes.OneofBytesFieldNumber,
+ TestAllTypes.OneofNestedMessageFieldNumber,
+ TestAllTypes.OneofStringFieldNumber,
+ TestAllTypes.OneofUint32FieldNumber }
+ .Select(fieldNumber => TestAllTypes.Descriptor.FindFieldByNumber(fieldNumber))
+ .ToList();
+ foreach (var field in expectedFields)
+ {
+ Assert.AreSame(descriptor, field.ContainingOneof);
+ }
+
+ CollectionAssert.AreEquivalent(expectedFields, descriptor.Fields);
+ }
+
+ [Test]
+ public void MapEntryMessageDescriptor()
+ {
+ var descriptor = MapWellKnownTypes.Descriptor.NestedTypes[0];
+ Assert.IsNull(descriptor.Parser);
+ Assert.IsNull(descriptor.ClrType);
+ Assert.IsNull(descriptor.Fields[1].Accessor);
+ }
+
+ // From TestFieldOrdering:
+ // string my_string = 11;
+ // int64 my_int = 1;
+ // float my_float = 101;
+ // NestedMessage single_nested_message = 200;
+ [Test]
+ public void FieldListOrderings()
+ {
+ var fields = TestFieldOrderings.Descriptor.Fields;
+ Assert.AreEqual(new[] { 11, 1, 101, 200 }, fields.InDeclarationOrder().Select(x => x.FieldNumber));
+ Assert.AreEqual(new[] { 1, 11, 101, 200 }, fields.InFieldNumberOrder().Select(x => x.FieldNumber));
+ }
+
+
+ [Test]
+ public void DescriptorProtoFileDescriptor()
+ {
+ var descriptor = Google.Protobuf.Reflection.FileDescriptor.DescriptorProtoFileDescriptor;
+ Assert.AreEqual("google/protobuf/descriptor.proto", descriptor.Name);
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs
new file mode 100644
index 0000000000..a488af30d4
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs
@@ -0,0 +1,218 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace Google.Protobuf.Reflection
+{
+ public class FieldAccessTest
+ {
+ [Test]
+ public void GetValue()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var fields = TestAllTypes.Descriptor.Fields;
+ Assert.AreEqual(message.SingleBool, fields[TestAllTypes.SingleBoolFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleBytes, fields[TestAllTypes.SingleBytesFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleDouble, fields[TestAllTypes.SingleDoubleFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleFixed32, fields[TestAllTypes.SingleFixed32FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleFixed64, fields[TestAllTypes.SingleFixed64FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleFloat, fields[TestAllTypes.SingleFloatFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleForeignEnum, fields[TestAllTypes.SingleForeignEnumFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleForeignMessage, fields[TestAllTypes.SingleForeignMessageFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleImportEnum, fields[TestAllTypes.SingleImportEnumFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleImportMessage, fields[TestAllTypes.SingleImportMessageFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleInt32, fields[TestAllTypes.SingleInt32FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleInt64, fields[TestAllTypes.SingleInt64FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleNestedEnum, fields[TestAllTypes.SingleNestedEnumFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleNestedMessage, fields[TestAllTypes.SingleNestedMessageFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SinglePublicImportMessage, fields[TestAllTypes.SinglePublicImportMessageFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleSint32, fields[TestAllTypes.SingleSint32FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleSint64, fields[TestAllTypes.SingleSint64FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleString, fields[TestAllTypes.SingleStringFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleSfixed32, fields[TestAllTypes.SingleSfixed32FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleSfixed64, fields[TestAllTypes.SingleSfixed64FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleUint32, fields[TestAllTypes.SingleUint32FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.SingleUint64, fields[TestAllTypes.SingleUint64FieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.OneofBytes, fields[TestAllTypes.OneofBytesFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.OneofString, fields[TestAllTypes.OneofStringFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.OneofNestedMessage, fields[TestAllTypes.OneofNestedMessageFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(message.OneofUint32, fields[TestAllTypes.OneofUint32FieldNumber].Accessor.GetValue(message));
+
+ // Just one example for repeated fields - they're all just returning the list
+ var list = (IList) fields[TestAllTypes.RepeatedInt32FieldNumber].Accessor.GetValue(message);
+ Assert.AreEqual(message.RepeatedInt32, list);
+ Assert.AreEqual(message.RepeatedInt32[0], list[0]); // Just in case there was any doubt...
+
+ // Just a single map field, for the same reason
+ var mapMessage = new TestMap { MapStringString = { { "key1", "value1" }, { "key2", "value2" } } };
+ fields = TestMap.Descriptor.Fields;
+ var dictionary = (IDictionary) fields[TestMap.MapStringStringFieldNumber].Accessor.GetValue(mapMessage);
+ Assert.AreEqual(mapMessage.MapStringString, dictionary);
+ Assert.AreEqual("value1", dictionary["key1"]);
+ }
+
+ [Test]
+ public void Clear()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var fields = TestAllTypes.Descriptor.Fields;
+ fields[TestAllTypes.SingleBoolFieldNumber].Accessor.Clear(message);
+ fields[TestAllTypes.SingleInt32FieldNumber].Accessor.Clear(message);
+ fields[TestAllTypes.SingleStringFieldNumber].Accessor.Clear(message);
+ fields[TestAllTypes.SingleBytesFieldNumber].Accessor.Clear(message);
+ fields[TestAllTypes.SingleForeignEnumFieldNumber].Accessor.Clear(message);
+ fields[TestAllTypes.SingleForeignMessageFieldNumber].Accessor.Clear(message);
+ fields[TestAllTypes.RepeatedDoubleFieldNumber].Accessor.Clear(message);
+
+ var expected = new TestAllTypes(SampleMessages.CreateFullTestAllTypes())
+ {
+ SingleBool = false,
+ SingleInt32 = 0,
+ SingleString = "",
+ SingleBytes = ByteString.Empty,
+ SingleForeignEnum = 0,
+ SingleForeignMessage = null,
+ };
+ expected.RepeatedDouble.Clear();
+
+ Assert.AreEqual(expected, message);
+
+ // Separately, maps.
+ var mapMessage = new TestMap { MapStringString = { { "key1", "value1" }, { "key2", "value2" } } };
+ fields = TestMap.Descriptor.Fields;
+ fields[TestMap.MapStringStringFieldNumber].Accessor.Clear(mapMessage);
+ Assert.AreEqual(0, mapMessage.MapStringString.Count);
+ }
+
+ [Test]
+ public void SetValue_SingleFields()
+ {
+ // Just a sample (primitives, messages, enums, strings, byte strings)
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var fields = TestAllTypes.Descriptor.Fields;
+ fields[TestAllTypes.SingleBoolFieldNumber].Accessor.SetValue(message, false);
+ fields[TestAllTypes.SingleInt32FieldNumber].Accessor.SetValue(message, 500);
+ fields[TestAllTypes.SingleStringFieldNumber].Accessor.SetValue(message, "It's a string");
+ fields[TestAllTypes.SingleBytesFieldNumber].Accessor.SetValue(message, ByteString.CopyFrom(99, 98, 97));
+ fields[TestAllTypes.SingleForeignEnumFieldNumber].Accessor.SetValue(message, ForeignEnum.ForeignFoo);
+ fields[TestAllTypes.SingleForeignMessageFieldNumber].Accessor.SetValue(message, new ForeignMessage { C = 12345 });
+ fields[TestAllTypes.SingleDoubleFieldNumber].Accessor.SetValue(message, 20150701.5);
+
+ var expected = new TestAllTypes(SampleMessages.CreateFullTestAllTypes())
+ {
+ SingleBool = false,
+ SingleInt32 = 500,
+ SingleString = "It's a string",
+ SingleBytes = ByteString.CopyFrom(99, 98, 97),
+ SingleForeignEnum = ForeignEnum.ForeignFoo,
+ SingleForeignMessage = new ForeignMessage { C = 12345 },
+ SingleDouble = 20150701.5
+ };
+
+ Assert.AreEqual(expected, message);
+ }
+
+ [Test]
+ public void SetValue_SingleFields_WrongType()
+ {
+ IMessage message = SampleMessages.CreateFullTestAllTypes();
+ var fields = message.Descriptor.Fields;
+ Assert.Throws<InvalidCastException>(() => fields[TestAllTypes.SingleBoolFieldNumber].Accessor.SetValue(message, "This isn't a bool"));
+ }
+
+ [Test]
+ public void SetValue_MapFields()
+ {
+ IMessage message = new TestMap();
+ var fields = message.Descriptor.Fields;
+ Assert.Throws<InvalidOperationException>(() => fields[TestMap.MapStringStringFieldNumber].Accessor.SetValue(message, new Dictionary<string, string>()));
+ }
+
+ [Test]
+ public void SetValue_RepeatedFields()
+ {
+ IMessage message = SampleMessages.CreateFullTestAllTypes();
+ var fields = message.Descriptor.Fields;
+ Assert.Throws<InvalidOperationException>(() => fields[TestAllTypes.RepeatedDoubleFieldNumber].Accessor.SetValue(message, new double[10]));
+ }
+
+ [Test]
+ public void GetValue_IncorrectType()
+ {
+ IMessage message = SampleMessages.CreateFullTestAllTypes();
+ var fields = message.Descriptor.Fields;
+ Assert.Throws<InvalidCastException>(() => fields[TestAllTypes.SingleBoolFieldNumber].Accessor.GetValue(new TestMap()));
+ }
+
+ [Test]
+ public void Oneof()
+ {
+ var message = new TestAllTypes();
+ var descriptor = TestAllTypes.Descriptor;
+ Assert.AreEqual(1, descriptor.Oneofs.Count);
+ var oneof = descriptor.Oneofs[0];
+ Assert.AreEqual("oneof_field", oneof.Name);
+ Assert.IsNull(oneof.Accessor.GetCaseFieldDescriptor(message));
+
+ message.OneofString = "foo";
+ Assert.AreSame(descriptor.Fields[TestAllTypes.OneofStringFieldNumber], oneof.Accessor.GetCaseFieldDescriptor(message));
+
+ message.OneofUint32 = 10;
+ Assert.AreSame(descriptor.Fields[TestAllTypes.OneofUint32FieldNumber], oneof.Accessor.GetCaseFieldDescriptor(message));
+
+ oneof.Accessor.Clear(message);
+ Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.None, message.OneofFieldCase);
+ }
+
+ [Test]
+ public void FieldDescriptor_ByName()
+ {
+ var descriptor = TestAllTypes.Descriptor;
+ Assert.AreSame(
+ descriptor.Fields[TestAllTypes.SingleBoolFieldNumber],
+ descriptor.Fields["single_bool"]);
+ }
+
+ [Test]
+ public void FieldDescriptor_NotFound()
+ {
+ var descriptor = TestAllTypes.Descriptor;
+ Assert.Throws<KeyNotFoundException>(() => descriptor.Fields[999999].ToString());
+ Assert.Throws<KeyNotFoundException>(() => descriptor.Fields["not found"].ToString());
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/Reflection/TypeRegistryTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Reflection/TypeRegistryTest.cs
new file mode 100644
index 0000000000..5be7ca2361
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/Reflection/TypeRegistryTest.cs
@@ -0,0 +1,94 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using Google.Protobuf.TestProtos;
+using Google.Protobuf.WellKnownTypes;
+using NUnit.Framework;
+
+namespace Google.Protobuf.Reflection
+{
+ public class TypeRegistryTest
+ {
+ // Most of our tests use messages. Simple test that we really can use files...
+ [Test]
+ public void CreateWithFileDescriptor()
+ {
+ var registry = TypeRegistry.FromFiles(DurationReflection.Descriptor, StructReflection.Descriptor);
+ AssertDescriptorPresent(registry, Duration.Descriptor);
+ AssertDescriptorPresent(registry, ListValue.Descriptor);
+ AssertDescriptorAbsent(registry, Timestamp.Descriptor);
+ }
+
+ [Test]
+ public void TypesFromSameFile()
+ {
+ // Just for kicks, let's start with a nested type
+ var registry = TypeRegistry.FromMessages(TestAllTypes.Types.NestedMessage.Descriptor);
+ // Top-level...
+ AssertDescriptorPresent(registry, TestFieldOrderings.Descriptor);
+ // ... and nested (not the same as the original NestedMessage!)
+ AssertDescriptorPresent(registry, TestFieldOrderings.Types.NestedMessage.Descriptor);
+ }
+
+ [Test]
+ public void DependenciesAreIncluded()
+ {
+ var registry = TypeRegistry.FromMessages(TestAllTypes.Descriptor);
+ // Direct dependencies
+ AssertDescriptorPresent(registry, ImportMessage.Descriptor);
+ // Public dependencies
+ AssertDescriptorPresent(registry, PublicImportMessage.Descriptor);
+ }
+
+ [Test]
+ public void DuplicateFiles()
+ {
+ // Duplicates via dependencies and simply via repetition
+ var registry = TypeRegistry.FromFiles(
+ UnittestProto3Reflection.Descriptor, UnittestImportProto3Reflection.Descriptor,
+ TimestampReflection.Descriptor, TimestampReflection.Descriptor);
+ AssertDescriptorPresent(registry, TestAllTypes.Descriptor);
+ AssertDescriptorPresent(registry, ImportMessage.Descriptor);
+ AssertDescriptorPresent(registry, Timestamp.Descriptor);
+ }
+
+ private static void AssertDescriptorPresent(TypeRegistry registry, MessageDescriptor descriptor)
+ {
+ Assert.AreSame(descriptor, registry.Find(descriptor.FullName));
+ }
+
+ private static void AssertDescriptorAbsent(TypeRegistry registry, MessageDescriptor descriptor)
+ {
+ Assert.IsNull(registry.Find(descriptor.FullName));
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/SampleEnum.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/SampleEnum.cs
new file mode 100644
index 0000000000..77447afa12
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/SampleEnum.cs
@@ -0,0 +1,42 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+namespace Google.Protobuf
+{
+ // Just a sample enum with positive and negative values to be used in tests.
+ internal enum SampleEnum
+ {
+ NegativeValue = -2,
+ None = 0,
+ PositiveValue = 3
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/SampleMessages.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/SampleMessages.cs
new file mode 100644
index 0000000000..ffa4e2a7c2
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/SampleMessages.cs
@@ -0,0 +1,99 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using Google.Protobuf.TestProtos;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Helper methods to create sample instances of types generated from unit test messages.
+ /// </summary>
+ public class SampleMessages
+ {
+ /// <summary>
+ /// Creates a new sample TestAllTypes message with all fields populated.
+ /// The "oneof" field is populated with the string property (OneofString).
+ /// </summary>
+ public static TestAllTypes CreateFullTestAllTypes()
+ {
+ return new TestAllTypes
+ {
+ SingleBool = true,
+ SingleBytes = ByteString.CopyFrom(1, 2, 3, 4),
+ SingleDouble = 23.5,
+ SingleFixed32 = 23,
+ SingleFixed64 = 1234567890123,
+ SingleFloat = 12.25f,
+ SingleForeignEnum = ForeignEnum.ForeignBar,
+ SingleForeignMessage = new ForeignMessage { C = 10 },
+ SingleImportEnum = ImportEnum.ImportBaz,
+ SingleImportMessage = new ImportMessage { D = 20 },
+ SingleInt32 = 100,
+ SingleInt64 = 3210987654321,
+ SingleNestedEnum = TestAllTypes.Types.NestedEnum.Foo,
+ SingleNestedMessage = new TestAllTypes.Types.NestedMessage { Bb = 35 },
+ SinglePublicImportMessage = new PublicImportMessage { E = 54 },
+ SingleSfixed32 = -123,
+ SingleSfixed64 = -12345678901234,
+ SingleSint32 = -456,
+ SingleSint64 = -12345678901235,
+ SingleString = "test",
+ SingleUint32 = UInt32.MaxValue,
+ SingleUint64 = UInt64.MaxValue,
+ RepeatedBool = { true, false },
+ RepeatedBytes = { ByteString.CopyFrom(1, 2, 3, 4), ByteString.CopyFrom(5, 6), ByteString.CopyFrom(new byte[1000]) },
+ RepeatedDouble = { -12.25, 23.5 },
+ RepeatedFixed32 = { UInt32.MaxValue, 23 },
+ RepeatedFixed64 = { UInt64.MaxValue, 1234567890123 },
+ RepeatedFloat = { 100f, 12.25f },
+ RepeatedForeignEnum = { ForeignEnum.ForeignFoo, ForeignEnum.ForeignBar },
+ RepeatedForeignMessage = { new ForeignMessage(), new ForeignMessage { C = 10 } },
+ RepeatedImportEnum = { ImportEnum.ImportBaz, ImportEnum.Unspecified },
+ RepeatedImportMessage = { new ImportMessage { D = 20 }, new ImportMessage { D = 25 } },
+ RepeatedInt32 = { 100, 200 },
+ RepeatedInt64 = { 3210987654321, Int64.MaxValue },
+ RepeatedNestedEnum = { TestAllTypes.Types.NestedEnum.Foo, TestAllTypes.Types.NestedEnum.Neg },
+ RepeatedNestedMessage = { new TestAllTypes.Types.NestedMessage { Bb = 35 }, new TestAllTypes.Types.NestedMessage { Bb = 10 } },
+ RepeatedPublicImportMessage = { new PublicImportMessage { E = 54 }, new PublicImportMessage { E = -1 } },
+ RepeatedSfixed32 = { -123, 123 },
+ RepeatedSfixed64 = { -12345678901234, 12345678901234 },
+ RepeatedSint32 = { -456, 100 },
+ RepeatedSint64 = { -12345678901235, 123 },
+ RepeatedString = { "foo", "bar" },
+ RepeatedUint32 = { UInt32.MaxValue, UInt32.MinValue },
+ RepeatedUint64 = { UInt64.MaxValue, UInt32.MinValue },
+ OneofString = "Oneof string"
+ };
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestCornerCases.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestCornerCases.cs
new file mode 100644
index 0000000000..248f5fa913
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestCornerCases.cs
@@ -0,0 +1,62 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using UnitTest.Issues.TestProtos;
+using NUnit.Framework;
+
+namespace Google.Protobuf
+{
+ public class TestCornerCases
+ {
+ [Test]
+ public void TestRoundTripNegativeEnums()
+ {
+ NegativeEnumMessage msg = new NegativeEnumMessage
+ {
+ Value = NegativeEnum.MinusOne,
+ Values = { NegativeEnum.Zero, NegativeEnum.MinusOne, NegativeEnum.FiveBelow },
+ PackedValues = { NegativeEnum.Zero, NegativeEnum.MinusOne, NegativeEnum.FiveBelow }
+ };
+
+ Assert.AreEqual(58, msg.CalculateSize());
+
+ byte[] bytes = new byte[58];
+ CodedOutputStream output = new CodedOutputStream(bytes);
+
+ msg.WriteTo(output);
+ Assert.AreEqual(0, output.SpaceLeft);
+
+ NegativeEnumMessage copy = NegativeEnumMessage.Parser.ParseFrom(bytes);
+ Assert.AreEqual(msg, copy);
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/ForeignMessagePartial.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/ForeignMessagePartial.cs
new file mode 100644
index 0000000000..5663a69902
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/ForeignMessagePartial.cs
@@ -0,0 +1,45 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 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.
+#endregion
+
+namespace Google.Protobuf.TestProtos
+{
+ /// <summary>
+ /// A message with custom diagnostics (to test that they work).
+ /// </summary>
+ public partial class ForeignMessage : ICustomDiagnosticMessage
+ {
+ public string ToDiagnosticString()
+ {
+ return $"{{ \"c\": {C}, \"@cInHex\": \"{C:x}\" }}";
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs
new file mode 100644
index 0000000000..9c0518a399
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/MapUnittestProto3.cs
@@ -0,0 +1,1599 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/map_unittest_proto3.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.TestProtos {
+
+ /// <summary>Holder for reflection information generated from google/protobuf/map_unittest_proto3.proto</summary>
+ public static partial class MapUnittestProto3Reflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for google/protobuf/map_unittest_proto3.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static MapUnittestProto3Reflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "Cilnb29nbGUvcHJvdG9idWYvbWFwX3VuaXR0ZXN0X3Byb3RvMy5wcm90bxIR",
+ "cHJvdG9idWZfdW5pdHRlc3QaJWdvb2dsZS9wcm90b2J1Zi91bml0dGVzdF9w",
+ "cm90bzMucHJvdG8ilhIKB1Rlc3RNYXASRgoPbWFwX2ludDMyX2ludDMyGAEg",
+ "AygLMi0ucHJvdG9idWZfdW5pdHRlc3QuVGVzdE1hcC5NYXBJbnQzMkludDMy",
+ "RW50cnkSRgoPbWFwX2ludDY0X2ludDY0GAIgAygLMi0ucHJvdG9idWZfdW5p",
+ "dHRlc3QuVGVzdE1hcC5NYXBJbnQ2NEludDY0RW50cnkSSgoRbWFwX3VpbnQz",
+ "Ml91aW50MzIYAyADKAsyLy5wcm90b2J1Zl91bml0dGVzdC5UZXN0TWFwLk1h",
+ "cFVpbnQzMlVpbnQzMkVudHJ5EkoKEW1hcF91aW50NjRfdWludDY0GAQgAygL",
+ "Mi8ucHJvdG9idWZfdW5pdHRlc3QuVGVzdE1hcC5NYXBVaW50NjRVaW50NjRF",
+ "bnRyeRJKChFtYXBfc2ludDMyX3NpbnQzMhgFIAMoCzIvLnByb3RvYnVmX3Vu",
+ "aXR0ZXN0LlRlc3RNYXAuTWFwU2ludDMyU2ludDMyRW50cnkSSgoRbWFwX3Np",
+ "bnQ2NF9zaW50NjQYBiADKAsyLy5wcm90b2J1Zl91bml0dGVzdC5UZXN0TWFw",
+ "Lk1hcFNpbnQ2NFNpbnQ2NEVudHJ5Ek4KE21hcF9maXhlZDMyX2ZpeGVkMzIY",
+ "ByADKAsyMS5wcm90b2J1Zl91bml0dGVzdC5UZXN0TWFwLk1hcEZpeGVkMzJG",
+ "aXhlZDMyRW50cnkSTgoTbWFwX2ZpeGVkNjRfZml4ZWQ2NBgIIAMoCzIxLnBy",
+ "b3RvYnVmX3VuaXR0ZXN0LlRlc3RNYXAuTWFwRml4ZWQ2NEZpeGVkNjRFbnRy",
+ "eRJSChVtYXBfc2ZpeGVkMzJfc2ZpeGVkMzIYCSADKAsyMy5wcm90b2J1Zl91",
+ "bml0dGVzdC5UZXN0TWFwLk1hcFNmaXhlZDMyU2ZpeGVkMzJFbnRyeRJSChVt",
+ "YXBfc2ZpeGVkNjRfc2ZpeGVkNjQYCiADKAsyMy5wcm90b2J1Zl91bml0dGVz",
+ "dC5UZXN0TWFwLk1hcFNmaXhlZDY0U2ZpeGVkNjRFbnRyeRJGCg9tYXBfaW50",
+ "MzJfZmxvYXQYCyADKAsyLS5wcm90b2J1Zl91bml0dGVzdC5UZXN0TWFwLk1h",
+ "cEludDMyRmxvYXRFbnRyeRJIChBtYXBfaW50MzJfZG91YmxlGAwgAygLMi4u",
+ "cHJvdG9idWZfdW5pdHRlc3QuVGVzdE1hcC5NYXBJbnQzMkRvdWJsZUVudHJ5",
+ "EkIKDW1hcF9ib29sX2Jvb2wYDSADKAsyKy5wcm90b2J1Zl91bml0dGVzdC5U",
+ "ZXN0TWFwLk1hcEJvb2xCb29sRW50cnkSSgoRbWFwX3N0cmluZ19zdHJpbmcY",
+ "DiADKAsyLy5wcm90b2J1Zl91bml0dGVzdC5UZXN0TWFwLk1hcFN0cmluZ1N0",
+ "cmluZ0VudHJ5EkYKD21hcF9pbnQzMl9ieXRlcxgPIAMoCzItLnByb3RvYnVm",
+ "X3VuaXR0ZXN0LlRlc3RNYXAuTWFwSW50MzJCeXRlc0VudHJ5EkQKDm1hcF9p",
+ "bnQzMl9lbnVtGBAgAygLMiwucHJvdG9idWZfdW5pdHRlc3QuVGVzdE1hcC5N",
+ "YXBJbnQzMkVudW1FbnRyeRJZChltYXBfaW50MzJfZm9yZWlnbl9tZXNzYWdl",
+ "GBEgAygLMjYucHJvdG9idWZfdW5pdHRlc3QuVGVzdE1hcC5NYXBJbnQzMkZv",
+ "cmVpZ25NZXNzYWdlRW50cnkaNAoSTWFwSW50MzJJbnQzMkVudHJ5EgsKA2tl",
+ "eRgBIAEoBRINCgV2YWx1ZRgCIAEoBToCOAEaNAoSTWFwSW50NjRJbnQ2NEVu",
+ "dHJ5EgsKA2tleRgBIAEoAxINCgV2YWx1ZRgCIAEoAzoCOAEaNgoUTWFwVWlu",
+ "dDMyVWludDMyRW50cnkSCwoDa2V5GAEgASgNEg0KBXZhbHVlGAIgASgNOgI4",
+ "ARo2ChRNYXBVaW50NjRVaW50NjRFbnRyeRILCgNrZXkYASABKAQSDQoFdmFs",
+ "dWUYAiABKAQ6AjgBGjYKFE1hcFNpbnQzMlNpbnQzMkVudHJ5EgsKA2tleRgB",
+ "IAEoERINCgV2YWx1ZRgCIAEoEToCOAEaNgoUTWFwU2ludDY0U2ludDY0RW50",
+ "cnkSCwoDa2V5GAEgASgSEg0KBXZhbHVlGAIgASgSOgI4ARo4ChZNYXBGaXhl",
+ "ZDMyRml4ZWQzMkVudHJ5EgsKA2tleRgBIAEoBxINCgV2YWx1ZRgCIAEoBzoC",
+ "OAEaOAoWTWFwRml4ZWQ2NEZpeGVkNjRFbnRyeRILCgNrZXkYASABKAYSDQoF",
+ "dmFsdWUYAiABKAY6AjgBGjoKGE1hcFNmaXhlZDMyU2ZpeGVkMzJFbnRyeRIL",
+ "CgNrZXkYASABKA8SDQoFdmFsdWUYAiABKA86AjgBGjoKGE1hcFNmaXhlZDY0",
+ "U2ZpeGVkNjRFbnRyeRILCgNrZXkYASABKBASDQoFdmFsdWUYAiABKBA6AjgB",
+ "GjQKEk1hcEludDMyRmxvYXRFbnRyeRILCgNrZXkYASABKAUSDQoFdmFsdWUY",
+ "AiABKAI6AjgBGjUKE01hcEludDMyRG91YmxlRW50cnkSCwoDa2V5GAEgASgF",
+ "Eg0KBXZhbHVlGAIgASgBOgI4ARoyChBNYXBCb29sQm9vbEVudHJ5EgsKA2tl",
+ "eRgBIAEoCBINCgV2YWx1ZRgCIAEoCDoCOAEaNgoUTWFwU3RyaW5nU3RyaW5n",
+ "RW50cnkSCwoDa2V5GAEgASgJEg0KBXZhbHVlGAIgASgJOgI4ARo0ChJNYXBJ",
+ "bnQzMkJ5dGVzRW50cnkSCwoDa2V5GAEgASgFEg0KBXZhbHVlGAIgASgMOgI4",
+ "ARpPChFNYXBJbnQzMkVudW1FbnRyeRILCgNrZXkYASABKAUSKQoFdmFsdWUY",
+ "AiABKA4yGi5wcm90b2J1Zl91bml0dGVzdC5NYXBFbnVtOgI4ARpgChtNYXBJ",
+ "bnQzMkZvcmVpZ25NZXNzYWdlRW50cnkSCwoDa2V5GAEgASgFEjAKBXZhbHVl",
+ "GAIgASgLMiEucHJvdG9idWZfdW5pdHRlc3QuRm9yZWlnbk1lc3NhZ2U6AjgB",
+ "IkEKEVRlc3RNYXBTdWJtZXNzYWdlEiwKCHRlc3RfbWFwGAEgASgLMhoucHJv",
+ "dG9idWZfdW5pdHRlc3QuVGVzdE1hcCK8AQoOVGVzdE1lc3NhZ2VNYXASUQoR",
+ "bWFwX2ludDMyX21lc3NhZ2UYASADKAsyNi5wcm90b2J1Zl91bml0dGVzdC5U",
+ "ZXN0TWVzc2FnZU1hcC5NYXBJbnQzMk1lc3NhZ2VFbnRyeRpXChRNYXBJbnQz",
+ "Mk1lc3NhZ2VFbnRyeRILCgNrZXkYASABKAUSLgoFdmFsdWUYAiABKAsyHy5w",
+ "cm90b2J1Zl91bml0dGVzdC5UZXN0QWxsVHlwZXM6AjgBIuMBCg9UZXN0U2Ft",
+ "ZVR5cGVNYXASOgoEbWFwMRgBIAMoCzIsLnByb3RvYnVmX3VuaXR0ZXN0LlRl",
+ "c3RTYW1lVHlwZU1hcC5NYXAxRW50cnkSOgoEbWFwMhgCIAMoCzIsLnByb3Rv",
+ "YnVmX3VuaXR0ZXN0LlRlc3RTYW1lVHlwZU1hcC5NYXAyRW50cnkaKwoJTWFw",
+ "MUVudHJ5EgsKA2tleRgBIAEoBRINCgV2YWx1ZRgCIAEoBToCOAEaKwoJTWFw",
+ "MkVudHJ5EgsKA2tleRgBIAEoBRINCgV2YWx1ZRgCIAEoBToCOAEi5BAKDFRl",
+ "c3RBcmVuYU1hcBJLCg9tYXBfaW50MzJfaW50MzIYASADKAsyMi5wcm90b2J1",
+ "Zl91bml0dGVzdC5UZXN0QXJlbmFNYXAuTWFwSW50MzJJbnQzMkVudHJ5EksK",
+ "D21hcF9pbnQ2NF9pbnQ2NBgCIAMoCzIyLnByb3RvYnVmX3VuaXR0ZXN0LlRl",
+ "c3RBcmVuYU1hcC5NYXBJbnQ2NEludDY0RW50cnkSTwoRbWFwX3VpbnQzMl91",
+ "aW50MzIYAyADKAsyNC5wcm90b2J1Zl91bml0dGVzdC5UZXN0QXJlbmFNYXAu",
+ "TWFwVWludDMyVWludDMyRW50cnkSTwoRbWFwX3VpbnQ2NF91aW50NjQYBCAD",
+ "KAsyNC5wcm90b2J1Zl91bml0dGVzdC5UZXN0QXJlbmFNYXAuTWFwVWludDY0",
+ "VWludDY0RW50cnkSTwoRbWFwX3NpbnQzMl9zaW50MzIYBSADKAsyNC5wcm90",
+ "b2J1Zl91bml0dGVzdC5UZXN0QXJlbmFNYXAuTWFwU2ludDMyU2ludDMyRW50",
+ "cnkSTwoRbWFwX3NpbnQ2NF9zaW50NjQYBiADKAsyNC5wcm90b2J1Zl91bml0",
+ "dGVzdC5UZXN0QXJlbmFNYXAuTWFwU2ludDY0U2ludDY0RW50cnkSUwoTbWFw",
+ "X2ZpeGVkMzJfZml4ZWQzMhgHIAMoCzI2LnByb3RvYnVmX3VuaXR0ZXN0LlRl",
+ "c3RBcmVuYU1hcC5NYXBGaXhlZDMyRml4ZWQzMkVudHJ5ElMKE21hcF9maXhl",
+ "ZDY0X2ZpeGVkNjQYCCADKAsyNi5wcm90b2J1Zl91bml0dGVzdC5UZXN0QXJl",
+ "bmFNYXAuTWFwRml4ZWQ2NEZpeGVkNjRFbnRyeRJXChVtYXBfc2ZpeGVkMzJf",
+ "c2ZpeGVkMzIYCSADKAsyOC5wcm90b2J1Zl91bml0dGVzdC5UZXN0QXJlbmFN",
+ "YXAuTWFwU2ZpeGVkMzJTZml4ZWQzMkVudHJ5ElcKFW1hcF9zZml4ZWQ2NF9z",
+ "Zml4ZWQ2NBgKIAMoCzI4LnByb3RvYnVmX3VuaXR0ZXN0LlRlc3RBcmVuYU1h",
+ "cC5NYXBTZml4ZWQ2NFNmaXhlZDY0RW50cnkSSwoPbWFwX2ludDMyX2Zsb2F0",
+ "GAsgAygLMjIucHJvdG9idWZfdW5pdHRlc3QuVGVzdEFyZW5hTWFwLk1hcElu",
+ "dDMyRmxvYXRFbnRyeRJNChBtYXBfaW50MzJfZG91YmxlGAwgAygLMjMucHJv",
+ "dG9idWZfdW5pdHRlc3QuVGVzdEFyZW5hTWFwLk1hcEludDMyRG91YmxlRW50",
+ "cnkSRwoNbWFwX2Jvb2xfYm9vbBgNIAMoCzIwLnByb3RvYnVmX3VuaXR0ZXN0",
+ "LlRlc3RBcmVuYU1hcC5NYXBCb29sQm9vbEVudHJ5EkkKDm1hcF9pbnQzMl9l",
+ "bnVtGA4gAygLMjEucHJvdG9idWZfdW5pdHRlc3QuVGVzdEFyZW5hTWFwLk1h",
+ "cEludDMyRW51bUVudHJ5El4KGW1hcF9pbnQzMl9mb3JlaWduX21lc3NhZ2UY",
+ "DyADKAsyOy5wcm90b2J1Zl91bml0dGVzdC5UZXN0QXJlbmFNYXAuTWFwSW50",
+ "MzJGb3JlaWduTWVzc2FnZUVudHJ5GjQKEk1hcEludDMySW50MzJFbnRyeRIL",
+ "CgNrZXkYASABKAUSDQoFdmFsdWUYAiABKAU6AjgBGjQKEk1hcEludDY0SW50",
+ "NjRFbnRyeRILCgNrZXkYASABKAMSDQoFdmFsdWUYAiABKAM6AjgBGjYKFE1h",
+ "cFVpbnQzMlVpbnQzMkVudHJ5EgsKA2tleRgBIAEoDRINCgV2YWx1ZRgCIAEo",
+ "DToCOAEaNgoUTWFwVWludDY0VWludDY0RW50cnkSCwoDa2V5GAEgASgEEg0K",
+ "BXZhbHVlGAIgASgEOgI4ARo2ChRNYXBTaW50MzJTaW50MzJFbnRyeRILCgNr",
+ "ZXkYASABKBESDQoFdmFsdWUYAiABKBE6AjgBGjYKFE1hcFNpbnQ2NFNpbnQ2",
+ "NEVudHJ5EgsKA2tleRgBIAEoEhINCgV2YWx1ZRgCIAEoEjoCOAEaOAoWTWFw",
+ "Rml4ZWQzMkZpeGVkMzJFbnRyeRILCgNrZXkYASABKAcSDQoFdmFsdWUYAiAB",
+ "KAc6AjgBGjgKFk1hcEZpeGVkNjRGaXhlZDY0RW50cnkSCwoDa2V5GAEgASgG",
+ "Eg0KBXZhbHVlGAIgASgGOgI4ARo6ChhNYXBTZml4ZWQzMlNmaXhlZDMyRW50",
+ "cnkSCwoDa2V5GAEgASgPEg0KBXZhbHVlGAIgASgPOgI4ARo6ChhNYXBTZml4",
+ "ZWQ2NFNmaXhlZDY0RW50cnkSCwoDa2V5GAEgASgQEg0KBXZhbHVlGAIgASgQ",
+ "OgI4ARo0ChJNYXBJbnQzMkZsb2F0RW50cnkSCwoDa2V5GAEgASgFEg0KBXZh",
+ "bHVlGAIgASgCOgI4ARo1ChNNYXBJbnQzMkRvdWJsZUVudHJ5EgsKA2tleRgB",
+ "IAEoBRINCgV2YWx1ZRgCIAEoAToCOAEaMgoQTWFwQm9vbEJvb2xFbnRyeRIL",
+ "CgNrZXkYASABKAgSDQoFdmFsdWUYAiABKAg6AjgBGk8KEU1hcEludDMyRW51",
+ "bUVudHJ5EgsKA2tleRgBIAEoBRIpCgV2YWx1ZRgCIAEoDjIaLnByb3RvYnVm",
+ "X3VuaXR0ZXN0Lk1hcEVudW06AjgBGmAKG01hcEludDMyRm9yZWlnbk1lc3Nh",
+ "Z2VFbnRyeRILCgNrZXkYASABKAUSMAoFdmFsdWUYAiABKAsyIS5wcm90b2J1",
+ "Zl91bml0dGVzdC5Gb3JlaWduTWVzc2FnZToCOAEi5AEKH01lc3NhZ2VDb250",
+ "YWluaW5nRW51bUNhbGxlZFR5cGUSSgoEdHlwZRgBIAMoCzI8LnByb3RvYnVm",
+ "X3VuaXR0ZXN0Lk1lc3NhZ2VDb250YWluaW5nRW51bUNhbGxlZFR5cGUuVHlw",
+ "ZUVudHJ5Gl8KCVR5cGVFbnRyeRILCgNrZXkYASABKAUSQQoFdmFsdWUYAiAB",
+ "KAsyMi5wcm90b2J1Zl91bml0dGVzdC5NZXNzYWdlQ29udGFpbmluZ0VudW1D",
+ "YWxsZWRUeXBlOgI4ASIUCgRUeXBlEgwKCFRZUEVfRk9PEAAinQEKH01lc3Nh",
+ "Z2VDb250YWluaW5nTWFwQ2FsbGVkRW50cnkSTAoFZW50cnkYASADKAsyPS5w",
+ "cm90b2J1Zl91bml0dGVzdC5NZXNzYWdlQ29udGFpbmluZ01hcENhbGxlZEVu",
+ "dHJ5LkVudHJ5RW50cnkaLAoKRW50cnlFbnRyeRILCgNrZXkYASABKAUSDQoF",
+ "dmFsdWUYAiABKAU6AjgBKj8KB01hcEVudW0SEAoMTUFQX0VOVU1fRk9PEAAS",
+ "EAoMTUFQX0VOVU1fQkFSEAESEAoMTUFQX0VOVU1fQkFaEAJCIPgBAaoCGkdv",
+ "b2dsZS5Qcm90b2J1Zi5UZXN0UHJvdG9zYgZwcm90bzM="));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor, },
+ new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Google.Protobuf.TestProtos.MapEnum), }, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestMap), global::Google.Protobuf.TestProtos.TestMap.Parser, new[]{ "MapInt32Int32", "MapInt64Int64", "MapUint32Uint32", "MapUint64Uint64", "MapSint32Sint32", "MapSint64Sint64", "MapFixed32Fixed32", "MapFixed64Fixed64", "MapSfixed32Sfixed32", "MapSfixed64Sfixed64", "MapInt32Float", "MapInt32Double", "MapBoolBool", "MapStringString", "MapInt32Bytes", "MapInt32Enum", "MapInt32ForeignMessage" }, null, null, new pbr::GeneratedClrTypeInfo[] { null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, }),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestMapSubmessage), global::Google.Protobuf.TestProtos.TestMapSubmessage.Parser, new[]{ "TestMap" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestMessageMap), global::Google.Protobuf.TestProtos.TestMessageMap.Parser, new[]{ "MapInt32Message" }, null, null, new pbr::GeneratedClrTypeInfo[] { null, }),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestSameTypeMap), global::Google.Protobuf.TestProtos.TestSameTypeMap.Parser, new[]{ "Map1", "Map2" }, null, null, new pbr::GeneratedClrTypeInfo[] { null, null, }),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestArenaMap), global::Google.Protobuf.TestProtos.TestArenaMap.Parser, new[]{ "MapInt32Int32", "MapInt64Int64", "MapUint32Uint32", "MapUint64Uint64", "MapSint32Sint32", "MapSint64Sint64", "MapFixed32Fixed32", "MapFixed64Fixed64", "MapSfixed32Sfixed32", "MapSfixed64Sfixed64", "MapInt32Float", "MapInt32Double", "MapBoolBool", "MapInt32Enum", "MapInt32ForeignMessage" }, null, null, new pbr::GeneratedClrTypeInfo[] { null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, }),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.MessageContainingEnumCalledType), global::Google.Protobuf.TestProtos.MessageContainingEnumCalledType.Parser, new[]{ "Type" }, null, new[]{ typeof(global::Google.Protobuf.TestProtos.MessageContainingEnumCalledType.Types.Type) }, new pbr::GeneratedClrTypeInfo[] { null, }),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.MessageContainingMapCalledEntry), global::Google.Protobuf.TestProtos.MessageContainingMapCalledEntry.Parser, new[]{ "Entry" }, null, null, new pbr::GeneratedClrTypeInfo[] { null, })
+ }));
+ }
+ #endregion
+
+ }
+ #region Enums
+ public enum MapEnum {
+ [pbr::OriginalName("MAP_ENUM_FOO")] Foo = 0,
+ [pbr::OriginalName("MAP_ENUM_BAR")] Bar = 1,
+ [pbr::OriginalName("MAP_ENUM_BAZ")] Baz = 2,
+ }
+
+ #endregion
+
+ #region Messages
+ /// <summary>
+ /// Tests maps.
+ /// </summary>
+ public sealed partial class TestMap : pb::IMessage<TestMap> {
+ private static readonly pb::MessageParser<TestMap> _parser = new pb::MessageParser<TestMap>(() => new TestMap());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestMap> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.MapUnittestProto3Reflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMap() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMap(TestMap other) : this() {
+ mapInt32Int32_ = other.mapInt32Int32_.Clone();
+ mapInt64Int64_ = other.mapInt64Int64_.Clone();
+ mapUint32Uint32_ = other.mapUint32Uint32_.Clone();
+ mapUint64Uint64_ = other.mapUint64Uint64_.Clone();
+ mapSint32Sint32_ = other.mapSint32Sint32_.Clone();
+ mapSint64Sint64_ = other.mapSint64Sint64_.Clone();
+ mapFixed32Fixed32_ = other.mapFixed32Fixed32_.Clone();
+ mapFixed64Fixed64_ = other.mapFixed64Fixed64_.Clone();
+ mapSfixed32Sfixed32_ = other.mapSfixed32Sfixed32_.Clone();
+ mapSfixed64Sfixed64_ = other.mapSfixed64Sfixed64_.Clone();
+ mapInt32Float_ = other.mapInt32Float_.Clone();
+ mapInt32Double_ = other.mapInt32Double_.Clone();
+ mapBoolBool_ = other.mapBoolBool_.Clone();
+ mapStringString_ = other.mapStringString_.Clone();
+ mapInt32Bytes_ = other.mapInt32Bytes_.Clone();
+ mapInt32Enum_ = other.mapInt32Enum_.Clone();
+ mapInt32ForeignMessage_ = other.mapInt32ForeignMessage_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMap Clone() {
+ return new TestMap(this);
+ }
+
+ /// <summary>Field number for the "map_int32_int32" field.</summary>
+ public const int MapInt32Int32FieldNumber = 1;
+ private static readonly pbc::MapField<int, int>.Codec _map_mapInt32Int32_codec
+ = new pbc::MapField<int, int>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForInt32(16), 10);
+ private readonly pbc::MapField<int, int> mapInt32Int32_ = new pbc::MapField<int, int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, int> MapInt32Int32 {
+ get { return mapInt32Int32_; }
+ }
+
+ /// <summary>Field number for the "map_int64_int64" field.</summary>
+ public const int MapInt64Int64FieldNumber = 2;
+ private static readonly pbc::MapField<long, long>.Codec _map_mapInt64Int64_codec
+ = new pbc::MapField<long, long>.Codec(pb::FieldCodec.ForInt64(8), pb::FieldCodec.ForInt64(16), 18);
+ private readonly pbc::MapField<long, long> mapInt64Int64_ = new pbc::MapField<long, long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<long, long> MapInt64Int64 {
+ get { return mapInt64Int64_; }
+ }
+
+ /// <summary>Field number for the "map_uint32_uint32" field.</summary>
+ public const int MapUint32Uint32FieldNumber = 3;
+ private static readonly pbc::MapField<uint, uint>.Codec _map_mapUint32Uint32_codec
+ = new pbc::MapField<uint, uint>.Codec(pb::FieldCodec.ForUInt32(8), pb::FieldCodec.ForUInt32(16), 26);
+ private readonly pbc::MapField<uint, uint> mapUint32Uint32_ = new pbc::MapField<uint, uint>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<uint, uint> MapUint32Uint32 {
+ get { return mapUint32Uint32_; }
+ }
+
+ /// <summary>Field number for the "map_uint64_uint64" field.</summary>
+ public const int MapUint64Uint64FieldNumber = 4;
+ private static readonly pbc::MapField<ulong, ulong>.Codec _map_mapUint64Uint64_codec
+ = new pbc::MapField<ulong, ulong>.Codec(pb::FieldCodec.ForUInt64(8), pb::FieldCodec.ForUInt64(16), 34);
+ private readonly pbc::MapField<ulong, ulong> mapUint64Uint64_ = new pbc::MapField<ulong, ulong>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<ulong, ulong> MapUint64Uint64 {
+ get { return mapUint64Uint64_; }
+ }
+
+ /// <summary>Field number for the "map_sint32_sint32" field.</summary>
+ public const int MapSint32Sint32FieldNumber = 5;
+ private static readonly pbc::MapField<int, int>.Codec _map_mapSint32Sint32_codec
+ = new pbc::MapField<int, int>.Codec(pb::FieldCodec.ForSInt32(8), pb::FieldCodec.ForSInt32(16), 42);
+ private readonly pbc::MapField<int, int> mapSint32Sint32_ = new pbc::MapField<int, int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, int> MapSint32Sint32 {
+ get { return mapSint32Sint32_; }
+ }
+
+ /// <summary>Field number for the "map_sint64_sint64" field.</summary>
+ public const int MapSint64Sint64FieldNumber = 6;
+ private static readonly pbc::MapField<long, long>.Codec _map_mapSint64Sint64_codec
+ = new pbc::MapField<long, long>.Codec(pb::FieldCodec.ForSInt64(8), pb::FieldCodec.ForSInt64(16), 50);
+ private readonly pbc::MapField<long, long> mapSint64Sint64_ = new pbc::MapField<long, long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<long, long> MapSint64Sint64 {
+ get { return mapSint64Sint64_; }
+ }
+
+ /// <summary>Field number for the "map_fixed32_fixed32" field.</summary>
+ public const int MapFixed32Fixed32FieldNumber = 7;
+ private static readonly pbc::MapField<uint, uint>.Codec _map_mapFixed32Fixed32_codec
+ = new pbc::MapField<uint, uint>.Codec(pb::FieldCodec.ForFixed32(13), pb::FieldCodec.ForFixed32(21), 58);
+ private readonly pbc::MapField<uint, uint> mapFixed32Fixed32_ = new pbc::MapField<uint, uint>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<uint, uint> MapFixed32Fixed32 {
+ get { return mapFixed32Fixed32_; }
+ }
+
+ /// <summary>Field number for the "map_fixed64_fixed64" field.</summary>
+ public const int MapFixed64Fixed64FieldNumber = 8;
+ private static readonly pbc::MapField<ulong, ulong>.Codec _map_mapFixed64Fixed64_codec
+ = new pbc::MapField<ulong, ulong>.Codec(pb::FieldCodec.ForFixed64(9), pb::FieldCodec.ForFixed64(17), 66);
+ private readonly pbc::MapField<ulong, ulong> mapFixed64Fixed64_ = new pbc::MapField<ulong, ulong>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<ulong, ulong> MapFixed64Fixed64 {
+ get { return mapFixed64Fixed64_; }
+ }
+
+ /// <summary>Field number for the "map_sfixed32_sfixed32" field.</summary>
+ public const int MapSfixed32Sfixed32FieldNumber = 9;
+ private static readonly pbc::MapField<int, int>.Codec _map_mapSfixed32Sfixed32_codec
+ = new pbc::MapField<int, int>.Codec(pb::FieldCodec.ForSFixed32(13), pb::FieldCodec.ForSFixed32(21), 74);
+ private readonly pbc::MapField<int, int> mapSfixed32Sfixed32_ = new pbc::MapField<int, int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, int> MapSfixed32Sfixed32 {
+ get { return mapSfixed32Sfixed32_; }
+ }
+
+ /// <summary>Field number for the "map_sfixed64_sfixed64" field.</summary>
+ public const int MapSfixed64Sfixed64FieldNumber = 10;
+ private static readonly pbc::MapField<long, long>.Codec _map_mapSfixed64Sfixed64_codec
+ = new pbc::MapField<long, long>.Codec(pb::FieldCodec.ForSFixed64(9), pb::FieldCodec.ForSFixed64(17), 82);
+ private readonly pbc::MapField<long, long> mapSfixed64Sfixed64_ = new pbc::MapField<long, long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<long, long> MapSfixed64Sfixed64 {
+ get { return mapSfixed64Sfixed64_; }
+ }
+
+ /// <summary>Field number for the "map_int32_float" field.</summary>
+ public const int MapInt32FloatFieldNumber = 11;
+ private static readonly pbc::MapField<int, float>.Codec _map_mapInt32Float_codec
+ = new pbc::MapField<int, float>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForFloat(21), 90);
+ private readonly pbc::MapField<int, float> mapInt32Float_ = new pbc::MapField<int, float>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, float> MapInt32Float {
+ get { return mapInt32Float_; }
+ }
+
+ /// <summary>Field number for the "map_int32_double" field.</summary>
+ public const int MapInt32DoubleFieldNumber = 12;
+ private static readonly pbc::MapField<int, double>.Codec _map_mapInt32Double_codec
+ = new pbc::MapField<int, double>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForDouble(17), 98);
+ private readonly pbc::MapField<int, double> mapInt32Double_ = new pbc::MapField<int, double>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, double> MapInt32Double {
+ get { return mapInt32Double_; }
+ }
+
+ /// <summary>Field number for the "map_bool_bool" field.</summary>
+ public const int MapBoolBoolFieldNumber = 13;
+ private static readonly pbc::MapField<bool, bool>.Codec _map_mapBoolBool_codec
+ = new pbc::MapField<bool, bool>.Codec(pb::FieldCodec.ForBool(8), pb::FieldCodec.ForBool(16), 106);
+ private readonly pbc::MapField<bool, bool> mapBoolBool_ = new pbc::MapField<bool, bool>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<bool, bool> MapBoolBool {
+ get { return mapBoolBool_; }
+ }
+
+ /// <summary>Field number for the "map_string_string" field.</summary>
+ public const int MapStringStringFieldNumber = 14;
+ private static readonly pbc::MapField<string, string>.Codec _map_mapStringString_codec
+ = new pbc::MapField<string, string>.Codec(pb::FieldCodec.ForString(10), pb::FieldCodec.ForString(18), 114);
+ private readonly pbc::MapField<string, string> mapStringString_ = new pbc::MapField<string, string>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<string, string> MapStringString {
+ get { return mapStringString_; }
+ }
+
+ /// <summary>Field number for the "map_int32_bytes" field.</summary>
+ public const int MapInt32BytesFieldNumber = 15;
+ private static readonly pbc::MapField<int, pb::ByteString>.Codec _map_mapInt32Bytes_codec
+ = new pbc::MapField<int, pb::ByteString>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForBytes(18), 122);
+ private readonly pbc::MapField<int, pb::ByteString> mapInt32Bytes_ = new pbc::MapField<int, pb::ByteString>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, pb::ByteString> MapInt32Bytes {
+ get { return mapInt32Bytes_; }
+ }
+
+ /// <summary>Field number for the "map_int32_enum" field.</summary>
+ public const int MapInt32EnumFieldNumber = 16;
+ private static readonly pbc::MapField<int, global::Google.Protobuf.TestProtos.MapEnum>.Codec _map_mapInt32Enum_codec
+ = new pbc::MapField<int, global::Google.Protobuf.TestProtos.MapEnum>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForEnum(16, x => (int) x, x => (global::Google.Protobuf.TestProtos.MapEnum) x), 130);
+ private readonly pbc::MapField<int, global::Google.Protobuf.TestProtos.MapEnum> mapInt32Enum_ = new pbc::MapField<int, global::Google.Protobuf.TestProtos.MapEnum>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, global::Google.Protobuf.TestProtos.MapEnum> MapInt32Enum {
+ get { return mapInt32Enum_; }
+ }
+
+ /// <summary>Field number for the "map_int32_foreign_message" field.</summary>
+ public const int MapInt32ForeignMessageFieldNumber = 17;
+ private static readonly pbc::MapField<int, global::Google.Protobuf.TestProtos.ForeignMessage>.Codec _map_mapInt32ForeignMessage_codec
+ = new pbc::MapField<int, global::Google.Protobuf.TestProtos.ForeignMessage>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.TestProtos.ForeignMessage.Parser), 138);
+ private readonly pbc::MapField<int, global::Google.Protobuf.TestProtos.ForeignMessage> mapInt32ForeignMessage_ = new pbc::MapField<int, global::Google.Protobuf.TestProtos.ForeignMessage>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, global::Google.Protobuf.TestProtos.ForeignMessage> MapInt32ForeignMessage {
+ get { return mapInt32ForeignMessage_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestMap);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestMap other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (!MapInt32Int32.Equals(other.MapInt32Int32)) return false;
+ if (!MapInt64Int64.Equals(other.MapInt64Int64)) return false;
+ if (!MapUint32Uint32.Equals(other.MapUint32Uint32)) return false;
+ if (!MapUint64Uint64.Equals(other.MapUint64Uint64)) return false;
+ if (!MapSint32Sint32.Equals(other.MapSint32Sint32)) return false;
+ if (!MapSint64Sint64.Equals(other.MapSint64Sint64)) return false;
+ if (!MapFixed32Fixed32.Equals(other.MapFixed32Fixed32)) return false;
+ if (!MapFixed64Fixed64.Equals(other.MapFixed64Fixed64)) return false;
+ if (!MapSfixed32Sfixed32.Equals(other.MapSfixed32Sfixed32)) return false;
+ if (!MapSfixed64Sfixed64.Equals(other.MapSfixed64Sfixed64)) return false;
+ if (!MapInt32Float.Equals(other.MapInt32Float)) return false;
+ if (!MapInt32Double.Equals(other.MapInt32Double)) return false;
+ if (!MapBoolBool.Equals(other.MapBoolBool)) return false;
+ if (!MapStringString.Equals(other.MapStringString)) return false;
+ if (!MapInt32Bytes.Equals(other.MapInt32Bytes)) return false;
+ if (!MapInt32Enum.Equals(other.MapInt32Enum)) return false;
+ if (!MapInt32ForeignMessage.Equals(other.MapInt32ForeignMessage)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= MapInt32Int32.GetHashCode();
+ hash ^= MapInt64Int64.GetHashCode();
+ hash ^= MapUint32Uint32.GetHashCode();
+ hash ^= MapUint64Uint64.GetHashCode();
+ hash ^= MapSint32Sint32.GetHashCode();
+ hash ^= MapSint64Sint64.GetHashCode();
+ hash ^= MapFixed32Fixed32.GetHashCode();
+ hash ^= MapFixed64Fixed64.GetHashCode();
+ hash ^= MapSfixed32Sfixed32.GetHashCode();
+ hash ^= MapSfixed64Sfixed64.GetHashCode();
+ hash ^= MapInt32Float.GetHashCode();
+ hash ^= MapInt32Double.GetHashCode();
+ hash ^= MapBoolBool.GetHashCode();
+ hash ^= MapStringString.GetHashCode();
+ hash ^= MapInt32Bytes.GetHashCode();
+ hash ^= MapInt32Enum.GetHashCode();
+ hash ^= MapInt32ForeignMessage.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ mapInt32Int32_.WriteTo(output, _map_mapInt32Int32_codec);
+ mapInt64Int64_.WriteTo(output, _map_mapInt64Int64_codec);
+ mapUint32Uint32_.WriteTo(output, _map_mapUint32Uint32_codec);
+ mapUint64Uint64_.WriteTo(output, _map_mapUint64Uint64_codec);
+ mapSint32Sint32_.WriteTo(output, _map_mapSint32Sint32_codec);
+ mapSint64Sint64_.WriteTo(output, _map_mapSint64Sint64_codec);
+ mapFixed32Fixed32_.WriteTo(output, _map_mapFixed32Fixed32_codec);
+ mapFixed64Fixed64_.WriteTo(output, _map_mapFixed64Fixed64_codec);
+ mapSfixed32Sfixed32_.WriteTo(output, _map_mapSfixed32Sfixed32_codec);
+ mapSfixed64Sfixed64_.WriteTo(output, _map_mapSfixed64Sfixed64_codec);
+ mapInt32Float_.WriteTo(output, _map_mapInt32Float_codec);
+ mapInt32Double_.WriteTo(output, _map_mapInt32Double_codec);
+ mapBoolBool_.WriteTo(output, _map_mapBoolBool_codec);
+ mapStringString_.WriteTo(output, _map_mapStringString_codec);
+ mapInt32Bytes_.WriteTo(output, _map_mapInt32Bytes_codec);
+ mapInt32Enum_.WriteTo(output, _map_mapInt32Enum_codec);
+ mapInt32ForeignMessage_.WriteTo(output, _map_mapInt32ForeignMessage_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += mapInt32Int32_.CalculateSize(_map_mapInt32Int32_codec);
+ size += mapInt64Int64_.CalculateSize(_map_mapInt64Int64_codec);
+ size += mapUint32Uint32_.CalculateSize(_map_mapUint32Uint32_codec);
+ size += mapUint64Uint64_.CalculateSize(_map_mapUint64Uint64_codec);
+ size += mapSint32Sint32_.CalculateSize(_map_mapSint32Sint32_codec);
+ size += mapSint64Sint64_.CalculateSize(_map_mapSint64Sint64_codec);
+ size += mapFixed32Fixed32_.CalculateSize(_map_mapFixed32Fixed32_codec);
+ size += mapFixed64Fixed64_.CalculateSize(_map_mapFixed64Fixed64_codec);
+ size += mapSfixed32Sfixed32_.CalculateSize(_map_mapSfixed32Sfixed32_codec);
+ size += mapSfixed64Sfixed64_.CalculateSize(_map_mapSfixed64Sfixed64_codec);
+ size += mapInt32Float_.CalculateSize(_map_mapInt32Float_codec);
+ size += mapInt32Double_.CalculateSize(_map_mapInt32Double_codec);
+ size += mapBoolBool_.CalculateSize(_map_mapBoolBool_codec);
+ size += mapStringString_.CalculateSize(_map_mapStringString_codec);
+ size += mapInt32Bytes_.CalculateSize(_map_mapInt32Bytes_codec);
+ size += mapInt32Enum_.CalculateSize(_map_mapInt32Enum_codec);
+ size += mapInt32ForeignMessage_.CalculateSize(_map_mapInt32ForeignMessage_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestMap other) {
+ if (other == null) {
+ return;
+ }
+ mapInt32Int32_.Add(other.mapInt32Int32_);
+ mapInt64Int64_.Add(other.mapInt64Int64_);
+ mapUint32Uint32_.Add(other.mapUint32Uint32_);
+ mapUint64Uint64_.Add(other.mapUint64Uint64_);
+ mapSint32Sint32_.Add(other.mapSint32Sint32_);
+ mapSint64Sint64_.Add(other.mapSint64Sint64_);
+ mapFixed32Fixed32_.Add(other.mapFixed32Fixed32_);
+ mapFixed64Fixed64_.Add(other.mapFixed64Fixed64_);
+ mapSfixed32Sfixed32_.Add(other.mapSfixed32Sfixed32_);
+ mapSfixed64Sfixed64_.Add(other.mapSfixed64Sfixed64_);
+ mapInt32Float_.Add(other.mapInt32Float_);
+ mapInt32Double_.Add(other.mapInt32Double_);
+ mapBoolBool_.Add(other.mapBoolBool_);
+ mapStringString_.Add(other.mapStringString_);
+ mapInt32Bytes_.Add(other.mapInt32Bytes_);
+ mapInt32Enum_.Add(other.mapInt32Enum_);
+ mapInt32ForeignMessage_.Add(other.mapInt32ForeignMessage_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ mapInt32Int32_.AddEntriesFrom(input, _map_mapInt32Int32_codec);
+ break;
+ }
+ case 18: {
+ mapInt64Int64_.AddEntriesFrom(input, _map_mapInt64Int64_codec);
+ break;
+ }
+ case 26: {
+ mapUint32Uint32_.AddEntriesFrom(input, _map_mapUint32Uint32_codec);
+ break;
+ }
+ case 34: {
+ mapUint64Uint64_.AddEntriesFrom(input, _map_mapUint64Uint64_codec);
+ break;
+ }
+ case 42: {
+ mapSint32Sint32_.AddEntriesFrom(input, _map_mapSint32Sint32_codec);
+ break;
+ }
+ case 50: {
+ mapSint64Sint64_.AddEntriesFrom(input, _map_mapSint64Sint64_codec);
+ break;
+ }
+ case 58: {
+ mapFixed32Fixed32_.AddEntriesFrom(input, _map_mapFixed32Fixed32_codec);
+ break;
+ }
+ case 66: {
+ mapFixed64Fixed64_.AddEntriesFrom(input, _map_mapFixed64Fixed64_codec);
+ break;
+ }
+ case 74: {
+ mapSfixed32Sfixed32_.AddEntriesFrom(input, _map_mapSfixed32Sfixed32_codec);
+ break;
+ }
+ case 82: {
+ mapSfixed64Sfixed64_.AddEntriesFrom(input, _map_mapSfixed64Sfixed64_codec);
+ break;
+ }
+ case 90: {
+ mapInt32Float_.AddEntriesFrom(input, _map_mapInt32Float_codec);
+ break;
+ }
+ case 98: {
+ mapInt32Double_.AddEntriesFrom(input, _map_mapInt32Double_codec);
+ break;
+ }
+ case 106: {
+ mapBoolBool_.AddEntriesFrom(input, _map_mapBoolBool_codec);
+ break;
+ }
+ case 114: {
+ mapStringString_.AddEntriesFrom(input, _map_mapStringString_codec);
+ break;
+ }
+ case 122: {
+ mapInt32Bytes_.AddEntriesFrom(input, _map_mapInt32Bytes_codec);
+ break;
+ }
+ case 130: {
+ mapInt32Enum_.AddEntriesFrom(input, _map_mapInt32Enum_codec);
+ break;
+ }
+ case 138: {
+ mapInt32ForeignMessage_.AddEntriesFrom(input, _map_mapInt32ForeignMessage_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class TestMapSubmessage : pb::IMessage<TestMapSubmessage> {
+ private static readonly pb::MessageParser<TestMapSubmessage> _parser = new pb::MessageParser<TestMapSubmessage>(() => new TestMapSubmessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestMapSubmessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.MapUnittestProto3Reflection.Descriptor.MessageTypes[1]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMapSubmessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMapSubmessage(TestMapSubmessage other) : this() {
+ TestMap = other.testMap_ != null ? other.TestMap.Clone() : null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMapSubmessage Clone() {
+ return new TestMapSubmessage(this);
+ }
+
+ /// <summary>Field number for the "test_map" field.</summary>
+ public const int TestMapFieldNumber = 1;
+ private global::Google.Protobuf.TestProtos.TestMap testMap_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.TestMap TestMap {
+ get { return testMap_; }
+ set {
+ testMap_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestMapSubmessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestMapSubmessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (!object.Equals(TestMap, other.TestMap)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (testMap_ != null) hash ^= TestMap.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (testMap_ != null) {
+ output.WriteRawTag(10);
+ output.WriteMessage(TestMap);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (testMap_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(TestMap);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestMapSubmessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.testMap_ != null) {
+ if (testMap_ == null) {
+ testMap_ = new global::Google.Protobuf.TestProtos.TestMap();
+ }
+ TestMap.MergeFrom(other.TestMap);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ if (testMap_ == null) {
+ testMap_ = new global::Google.Protobuf.TestProtos.TestMap();
+ }
+ input.ReadMessage(testMap_);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class TestMessageMap : pb::IMessage<TestMessageMap> {
+ private static readonly pb::MessageParser<TestMessageMap> _parser = new pb::MessageParser<TestMessageMap>(() => new TestMessageMap());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestMessageMap> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.MapUnittestProto3Reflection.Descriptor.MessageTypes[2]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMessageMap() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMessageMap(TestMessageMap other) : this() {
+ mapInt32Message_ = other.mapInt32Message_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMessageMap Clone() {
+ return new TestMessageMap(this);
+ }
+
+ /// <summary>Field number for the "map_int32_message" field.</summary>
+ public const int MapInt32MessageFieldNumber = 1;
+ private static readonly pbc::MapField<int, global::Google.Protobuf.TestProtos.TestAllTypes>.Codec _map_mapInt32Message_codec
+ = new pbc::MapField<int, global::Google.Protobuf.TestProtos.TestAllTypes>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.TestProtos.TestAllTypes.Parser), 10);
+ private readonly pbc::MapField<int, global::Google.Protobuf.TestProtos.TestAllTypes> mapInt32Message_ = new pbc::MapField<int, global::Google.Protobuf.TestProtos.TestAllTypes>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, global::Google.Protobuf.TestProtos.TestAllTypes> MapInt32Message {
+ get { return mapInt32Message_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestMessageMap);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestMessageMap other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (!MapInt32Message.Equals(other.MapInt32Message)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= MapInt32Message.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ mapInt32Message_.WriteTo(output, _map_mapInt32Message_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += mapInt32Message_.CalculateSize(_map_mapInt32Message_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestMessageMap other) {
+ if (other == null) {
+ return;
+ }
+ mapInt32Message_.Add(other.mapInt32Message_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ mapInt32Message_.AddEntriesFrom(input, _map_mapInt32Message_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Two map fields share the same entry default instance.
+ /// </summary>
+ public sealed partial class TestSameTypeMap : pb::IMessage<TestSameTypeMap> {
+ private static readonly pb::MessageParser<TestSameTypeMap> _parser = new pb::MessageParser<TestSameTypeMap>(() => new TestSameTypeMap());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestSameTypeMap> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.MapUnittestProto3Reflection.Descriptor.MessageTypes[3]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestSameTypeMap() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestSameTypeMap(TestSameTypeMap other) : this() {
+ map1_ = other.map1_.Clone();
+ map2_ = other.map2_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestSameTypeMap Clone() {
+ return new TestSameTypeMap(this);
+ }
+
+ /// <summary>Field number for the "map1" field.</summary>
+ public const int Map1FieldNumber = 1;
+ private static readonly pbc::MapField<int, int>.Codec _map_map1_codec
+ = new pbc::MapField<int, int>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForInt32(16), 10);
+ private readonly pbc::MapField<int, int> map1_ = new pbc::MapField<int, int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, int> Map1 {
+ get { return map1_; }
+ }
+
+ /// <summary>Field number for the "map2" field.</summary>
+ public const int Map2FieldNumber = 2;
+ private static readonly pbc::MapField<int, int>.Codec _map_map2_codec
+ = new pbc::MapField<int, int>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForInt32(16), 18);
+ private readonly pbc::MapField<int, int> map2_ = new pbc::MapField<int, int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, int> Map2 {
+ get { return map2_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestSameTypeMap);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestSameTypeMap other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (!Map1.Equals(other.Map1)) return false;
+ if (!Map2.Equals(other.Map2)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= Map1.GetHashCode();
+ hash ^= Map2.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ map1_.WriteTo(output, _map_map1_codec);
+ map2_.WriteTo(output, _map_map2_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += map1_.CalculateSize(_map_map1_codec);
+ size += map2_.CalculateSize(_map_map2_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestSameTypeMap other) {
+ if (other == null) {
+ return;
+ }
+ map1_.Add(other.map1_);
+ map2_.Add(other.map2_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ map1_.AddEntriesFrom(input, _map_map1_codec);
+ break;
+ }
+ case 18: {
+ map2_.AddEntriesFrom(input, _map_map2_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class TestArenaMap : pb::IMessage<TestArenaMap> {
+ private static readonly pb::MessageParser<TestArenaMap> _parser = new pb::MessageParser<TestArenaMap>(() => new TestArenaMap());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestArenaMap> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.MapUnittestProto3Reflection.Descriptor.MessageTypes[4]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestArenaMap() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestArenaMap(TestArenaMap other) : this() {
+ mapInt32Int32_ = other.mapInt32Int32_.Clone();
+ mapInt64Int64_ = other.mapInt64Int64_.Clone();
+ mapUint32Uint32_ = other.mapUint32Uint32_.Clone();
+ mapUint64Uint64_ = other.mapUint64Uint64_.Clone();
+ mapSint32Sint32_ = other.mapSint32Sint32_.Clone();
+ mapSint64Sint64_ = other.mapSint64Sint64_.Clone();
+ mapFixed32Fixed32_ = other.mapFixed32Fixed32_.Clone();
+ mapFixed64Fixed64_ = other.mapFixed64Fixed64_.Clone();
+ mapSfixed32Sfixed32_ = other.mapSfixed32Sfixed32_.Clone();
+ mapSfixed64Sfixed64_ = other.mapSfixed64Sfixed64_.Clone();
+ mapInt32Float_ = other.mapInt32Float_.Clone();
+ mapInt32Double_ = other.mapInt32Double_.Clone();
+ mapBoolBool_ = other.mapBoolBool_.Clone();
+ mapInt32Enum_ = other.mapInt32Enum_.Clone();
+ mapInt32ForeignMessage_ = other.mapInt32ForeignMessage_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestArenaMap Clone() {
+ return new TestArenaMap(this);
+ }
+
+ /// <summary>Field number for the "map_int32_int32" field.</summary>
+ public const int MapInt32Int32FieldNumber = 1;
+ private static readonly pbc::MapField<int, int>.Codec _map_mapInt32Int32_codec
+ = new pbc::MapField<int, int>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForInt32(16), 10);
+ private readonly pbc::MapField<int, int> mapInt32Int32_ = new pbc::MapField<int, int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, int> MapInt32Int32 {
+ get { return mapInt32Int32_; }
+ }
+
+ /// <summary>Field number for the "map_int64_int64" field.</summary>
+ public const int MapInt64Int64FieldNumber = 2;
+ private static readonly pbc::MapField<long, long>.Codec _map_mapInt64Int64_codec
+ = new pbc::MapField<long, long>.Codec(pb::FieldCodec.ForInt64(8), pb::FieldCodec.ForInt64(16), 18);
+ private readonly pbc::MapField<long, long> mapInt64Int64_ = new pbc::MapField<long, long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<long, long> MapInt64Int64 {
+ get { return mapInt64Int64_; }
+ }
+
+ /// <summary>Field number for the "map_uint32_uint32" field.</summary>
+ public const int MapUint32Uint32FieldNumber = 3;
+ private static readonly pbc::MapField<uint, uint>.Codec _map_mapUint32Uint32_codec
+ = new pbc::MapField<uint, uint>.Codec(pb::FieldCodec.ForUInt32(8), pb::FieldCodec.ForUInt32(16), 26);
+ private readonly pbc::MapField<uint, uint> mapUint32Uint32_ = new pbc::MapField<uint, uint>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<uint, uint> MapUint32Uint32 {
+ get { return mapUint32Uint32_; }
+ }
+
+ /// <summary>Field number for the "map_uint64_uint64" field.</summary>
+ public const int MapUint64Uint64FieldNumber = 4;
+ private static readonly pbc::MapField<ulong, ulong>.Codec _map_mapUint64Uint64_codec
+ = new pbc::MapField<ulong, ulong>.Codec(pb::FieldCodec.ForUInt64(8), pb::FieldCodec.ForUInt64(16), 34);
+ private readonly pbc::MapField<ulong, ulong> mapUint64Uint64_ = new pbc::MapField<ulong, ulong>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<ulong, ulong> MapUint64Uint64 {
+ get { return mapUint64Uint64_; }
+ }
+
+ /// <summary>Field number for the "map_sint32_sint32" field.</summary>
+ public const int MapSint32Sint32FieldNumber = 5;
+ private static readonly pbc::MapField<int, int>.Codec _map_mapSint32Sint32_codec
+ = new pbc::MapField<int, int>.Codec(pb::FieldCodec.ForSInt32(8), pb::FieldCodec.ForSInt32(16), 42);
+ private readonly pbc::MapField<int, int> mapSint32Sint32_ = new pbc::MapField<int, int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, int> MapSint32Sint32 {
+ get { return mapSint32Sint32_; }
+ }
+
+ /// <summary>Field number for the "map_sint64_sint64" field.</summary>
+ public const int MapSint64Sint64FieldNumber = 6;
+ private static readonly pbc::MapField<long, long>.Codec _map_mapSint64Sint64_codec
+ = new pbc::MapField<long, long>.Codec(pb::FieldCodec.ForSInt64(8), pb::FieldCodec.ForSInt64(16), 50);
+ private readonly pbc::MapField<long, long> mapSint64Sint64_ = new pbc::MapField<long, long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<long, long> MapSint64Sint64 {
+ get { return mapSint64Sint64_; }
+ }
+
+ /// <summary>Field number for the "map_fixed32_fixed32" field.</summary>
+ public const int MapFixed32Fixed32FieldNumber = 7;
+ private static readonly pbc::MapField<uint, uint>.Codec _map_mapFixed32Fixed32_codec
+ = new pbc::MapField<uint, uint>.Codec(pb::FieldCodec.ForFixed32(13), pb::FieldCodec.ForFixed32(21), 58);
+ private readonly pbc::MapField<uint, uint> mapFixed32Fixed32_ = new pbc::MapField<uint, uint>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<uint, uint> MapFixed32Fixed32 {
+ get { return mapFixed32Fixed32_; }
+ }
+
+ /// <summary>Field number for the "map_fixed64_fixed64" field.</summary>
+ public const int MapFixed64Fixed64FieldNumber = 8;
+ private static readonly pbc::MapField<ulong, ulong>.Codec _map_mapFixed64Fixed64_codec
+ = new pbc::MapField<ulong, ulong>.Codec(pb::FieldCodec.ForFixed64(9), pb::FieldCodec.ForFixed64(17), 66);
+ private readonly pbc::MapField<ulong, ulong> mapFixed64Fixed64_ = new pbc::MapField<ulong, ulong>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<ulong, ulong> MapFixed64Fixed64 {
+ get { return mapFixed64Fixed64_; }
+ }
+
+ /// <summary>Field number for the "map_sfixed32_sfixed32" field.</summary>
+ public const int MapSfixed32Sfixed32FieldNumber = 9;
+ private static readonly pbc::MapField<int, int>.Codec _map_mapSfixed32Sfixed32_codec
+ = new pbc::MapField<int, int>.Codec(pb::FieldCodec.ForSFixed32(13), pb::FieldCodec.ForSFixed32(21), 74);
+ private readonly pbc::MapField<int, int> mapSfixed32Sfixed32_ = new pbc::MapField<int, int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, int> MapSfixed32Sfixed32 {
+ get { return mapSfixed32Sfixed32_; }
+ }
+
+ /// <summary>Field number for the "map_sfixed64_sfixed64" field.</summary>
+ public const int MapSfixed64Sfixed64FieldNumber = 10;
+ private static readonly pbc::MapField<long, long>.Codec _map_mapSfixed64Sfixed64_codec
+ = new pbc::MapField<long, long>.Codec(pb::FieldCodec.ForSFixed64(9), pb::FieldCodec.ForSFixed64(17), 82);
+ private readonly pbc::MapField<long, long> mapSfixed64Sfixed64_ = new pbc::MapField<long, long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<long, long> MapSfixed64Sfixed64 {
+ get { return mapSfixed64Sfixed64_; }
+ }
+
+ /// <summary>Field number for the "map_int32_float" field.</summary>
+ public const int MapInt32FloatFieldNumber = 11;
+ private static readonly pbc::MapField<int, float>.Codec _map_mapInt32Float_codec
+ = new pbc::MapField<int, float>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForFloat(21), 90);
+ private readonly pbc::MapField<int, float> mapInt32Float_ = new pbc::MapField<int, float>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, float> MapInt32Float {
+ get { return mapInt32Float_; }
+ }
+
+ /// <summary>Field number for the "map_int32_double" field.</summary>
+ public const int MapInt32DoubleFieldNumber = 12;
+ private static readonly pbc::MapField<int, double>.Codec _map_mapInt32Double_codec
+ = new pbc::MapField<int, double>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForDouble(17), 98);
+ private readonly pbc::MapField<int, double> mapInt32Double_ = new pbc::MapField<int, double>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, double> MapInt32Double {
+ get { return mapInt32Double_; }
+ }
+
+ /// <summary>Field number for the "map_bool_bool" field.</summary>
+ public const int MapBoolBoolFieldNumber = 13;
+ private static readonly pbc::MapField<bool, bool>.Codec _map_mapBoolBool_codec
+ = new pbc::MapField<bool, bool>.Codec(pb::FieldCodec.ForBool(8), pb::FieldCodec.ForBool(16), 106);
+ private readonly pbc::MapField<bool, bool> mapBoolBool_ = new pbc::MapField<bool, bool>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<bool, bool> MapBoolBool {
+ get { return mapBoolBool_; }
+ }
+
+ /// <summary>Field number for the "map_int32_enum" field.</summary>
+ public const int MapInt32EnumFieldNumber = 14;
+ private static readonly pbc::MapField<int, global::Google.Protobuf.TestProtos.MapEnum>.Codec _map_mapInt32Enum_codec
+ = new pbc::MapField<int, global::Google.Protobuf.TestProtos.MapEnum>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForEnum(16, x => (int) x, x => (global::Google.Protobuf.TestProtos.MapEnum) x), 114);
+ private readonly pbc::MapField<int, global::Google.Protobuf.TestProtos.MapEnum> mapInt32Enum_ = new pbc::MapField<int, global::Google.Protobuf.TestProtos.MapEnum>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, global::Google.Protobuf.TestProtos.MapEnum> MapInt32Enum {
+ get { return mapInt32Enum_; }
+ }
+
+ /// <summary>Field number for the "map_int32_foreign_message" field.</summary>
+ public const int MapInt32ForeignMessageFieldNumber = 15;
+ private static readonly pbc::MapField<int, global::Google.Protobuf.TestProtos.ForeignMessage>.Codec _map_mapInt32ForeignMessage_codec
+ = new pbc::MapField<int, global::Google.Protobuf.TestProtos.ForeignMessage>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.TestProtos.ForeignMessage.Parser), 122);
+ private readonly pbc::MapField<int, global::Google.Protobuf.TestProtos.ForeignMessage> mapInt32ForeignMessage_ = new pbc::MapField<int, global::Google.Protobuf.TestProtos.ForeignMessage>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, global::Google.Protobuf.TestProtos.ForeignMessage> MapInt32ForeignMessage {
+ get { return mapInt32ForeignMessage_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestArenaMap);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestArenaMap other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (!MapInt32Int32.Equals(other.MapInt32Int32)) return false;
+ if (!MapInt64Int64.Equals(other.MapInt64Int64)) return false;
+ if (!MapUint32Uint32.Equals(other.MapUint32Uint32)) return false;
+ if (!MapUint64Uint64.Equals(other.MapUint64Uint64)) return false;
+ if (!MapSint32Sint32.Equals(other.MapSint32Sint32)) return false;
+ if (!MapSint64Sint64.Equals(other.MapSint64Sint64)) return false;
+ if (!MapFixed32Fixed32.Equals(other.MapFixed32Fixed32)) return false;
+ if (!MapFixed64Fixed64.Equals(other.MapFixed64Fixed64)) return false;
+ if (!MapSfixed32Sfixed32.Equals(other.MapSfixed32Sfixed32)) return false;
+ if (!MapSfixed64Sfixed64.Equals(other.MapSfixed64Sfixed64)) return false;
+ if (!MapInt32Float.Equals(other.MapInt32Float)) return false;
+ if (!MapInt32Double.Equals(other.MapInt32Double)) return false;
+ if (!MapBoolBool.Equals(other.MapBoolBool)) return false;
+ if (!MapInt32Enum.Equals(other.MapInt32Enum)) return false;
+ if (!MapInt32ForeignMessage.Equals(other.MapInt32ForeignMessage)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= MapInt32Int32.GetHashCode();
+ hash ^= MapInt64Int64.GetHashCode();
+ hash ^= MapUint32Uint32.GetHashCode();
+ hash ^= MapUint64Uint64.GetHashCode();
+ hash ^= MapSint32Sint32.GetHashCode();
+ hash ^= MapSint64Sint64.GetHashCode();
+ hash ^= MapFixed32Fixed32.GetHashCode();
+ hash ^= MapFixed64Fixed64.GetHashCode();
+ hash ^= MapSfixed32Sfixed32.GetHashCode();
+ hash ^= MapSfixed64Sfixed64.GetHashCode();
+ hash ^= MapInt32Float.GetHashCode();
+ hash ^= MapInt32Double.GetHashCode();
+ hash ^= MapBoolBool.GetHashCode();
+ hash ^= MapInt32Enum.GetHashCode();
+ hash ^= MapInt32ForeignMessage.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ mapInt32Int32_.WriteTo(output, _map_mapInt32Int32_codec);
+ mapInt64Int64_.WriteTo(output, _map_mapInt64Int64_codec);
+ mapUint32Uint32_.WriteTo(output, _map_mapUint32Uint32_codec);
+ mapUint64Uint64_.WriteTo(output, _map_mapUint64Uint64_codec);
+ mapSint32Sint32_.WriteTo(output, _map_mapSint32Sint32_codec);
+ mapSint64Sint64_.WriteTo(output, _map_mapSint64Sint64_codec);
+ mapFixed32Fixed32_.WriteTo(output, _map_mapFixed32Fixed32_codec);
+ mapFixed64Fixed64_.WriteTo(output, _map_mapFixed64Fixed64_codec);
+ mapSfixed32Sfixed32_.WriteTo(output, _map_mapSfixed32Sfixed32_codec);
+ mapSfixed64Sfixed64_.WriteTo(output, _map_mapSfixed64Sfixed64_codec);
+ mapInt32Float_.WriteTo(output, _map_mapInt32Float_codec);
+ mapInt32Double_.WriteTo(output, _map_mapInt32Double_codec);
+ mapBoolBool_.WriteTo(output, _map_mapBoolBool_codec);
+ mapInt32Enum_.WriteTo(output, _map_mapInt32Enum_codec);
+ mapInt32ForeignMessage_.WriteTo(output, _map_mapInt32ForeignMessage_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += mapInt32Int32_.CalculateSize(_map_mapInt32Int32_codec);
+ size += mapInt64Int64_.CalculateSize(_map_mapInt64Int64_codec);
+ size += mapUint32Uint32_.CalculateSize(_map_mapUint32Uint32_codec);
+ size += mapUint64Uint64_.CalculateSize(_map_mapUint64Uint64_codec);
+ size += mapSint32Sint32_.CalculateSize(_map_mapSint32Sint32_codec);
+ size += mapSint64Sint64_.CalculateSize(_map_mapSint64Sint64_codec);
+ size += mapFixed32Fixed32_.CalculateSize(_map_mapFixed32Fixed32_codec);
+ size += mapFixed64Fixed64_.CalculateSize(_map_mapFixed64Fixed64_codec);
+ size += mapSfixed32Sfixed32_.CalculateSize(_map_mapSfixed32Sfixed32_codec);
+ size += mapSfixed64Sfixed64_.CalculateSize(_map_mapSfixed64Sfixed64_codec);
+ size += mapInt32Float_.CalculateSize(_map_mapInt32Float_codec);
+ size += mapInt32Double_.CalculateSize(_map_mapInt32Double_codec);
+ size += mapBoolBool_.CalculateSize(_map_mapBoolBool_codec);
+ size += mapInt32Enum_.CalculateSize(_map_mapInt32Enum_codec);
+ size += mapInt32ForeignMessage_.CalculateSize(_map_mapInt32ForeignMessage_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestArenaMap other) {
+ if (other == null) {
+ return;
+ }
+ mapInt32Int32_.Add(other.mapInt32Int32_);
+ mapInt64Int64_.Add(other.mapInt64Int64_);
+ mapUint32Uint32_.Add(other.mapUint32Uint32_);
+ mapUint64Uint64_.Add(other.mapUint64Uint64_);
+ mapSint32Sint32_.Add(other.mapSint32Sint32_);
+ mapSint64Sint64_.Add(other.mapSint64Sint64_);
+ mapFixed32Fixed32_.Add(other.mapFixed32Fixed32_);
+ mapFixed64Fixed64_.Add(other.mapFixed64Fixed64_);
+ mapSfixed32Sfixed32_.Add(other.mapSfixed32Sfixed32_);
+ mapSfixed64Sfixed64_.Add(other.mapSfixed64Sfixed64_);
+ mapInt32Float_.Add(other.mapInt32Float_);
+ mapInt32Double_.Add(other.mapInt32Double_);
+ mapBoolBool_.Add(other.mapBoolBool_);
+ mapInt32Enum_.Add(other.mapInt32Enum_);
+ mapInt32ForeignMessage_.Add(other.mapInt32ForeignMessage_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ mapInt32Int32_.AddEntriesFrom(input, _map_mapInt32Int32_codec);
+ break;
+ }
+ case 18: {
+ mapInt64Int64_.AddEntriesFrom(input, _map_mapInt64Int64_codec);
+ break;
+ }
+ case 26: {
+ mapUint32Uint32_.AddEntriesFrom(input, _map_mapUint32Uint32_codec);
+ break;
+ }
+ case 34: {
+ mapUint64Uint64_.AddEntriesFrom(input, _map_mapUint64Uint64_codec);
+ break;
+ }
+ case 42: {
+ mapSint32Sint32_.AddEntriesFrom(input, _map_mapSint32Sint32_codec);
+ break;
+ }
+ case 50: {
+ mapSint64Sint64_.AddEntriesFrom(input, _map_mapSint64Sint64_codec);
+ break;
+ }
+ case 58: {
+ mapFixed32Fixed32_.AddEntriesFrom(input, _map_mapFixed32Fixed32_codec);
+ break;
+ }
+ case 66: {
+ mapFixed64Fixed64_.AddEntriesFrom(input, _map_mapFixed64Fixed64_codec);
+ break;
+ }
+ case 74: {
+ mapSfixed32Sfixed32_.AddEntriesFrom(input, _map_mapSfixed32Sfixed32_codec);
+ break;
+ }
+ case 82: {
+ mapSfixed64Sfixed64_.AddEntriesFrom(input, _map_mapSfixed64Sfixed64_codec);
+ break;
+ }
+ case 90: {
+ mapInt32Float_.AddEntriesFrom(input, _map_mapInt32Float_codec);
+ break;
+ }
+ case 98: {
+ mapInt32Double_.AddEntriesFrom(input, _map_mapInt32Double_codec);
+ break;
+ }
+ case 106: {
+ mapBoolBool_.AddEntriesFrom(input, _map_mapBoolBool_codec);
+ break;
+ }
+ case 114: {
+ mapInt32Enum_.AddEntriesFrom(input, _map_mapInt32Enum_codec);
+ break;
+ }
+ case 122: {
+ mapInt32ForeignMessage_.AddEntriesFrom(input, _map_mapInt32ForeignMessage_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Previously, message containing enum called Type cannot be used as value of
+ /// map field.
+ /// </summary>
+ public sealed partial class MessageContainingEnumCalledType : pb::IMessage<MessageContainingEnumCalledType> {
+ private static readonly pb::MessageParser<MessageContainingEnumCalledType> _parser = new pb::MessageParser<MessageContainingEnumCalledType>(() => new MessageContainingEnumCalledType());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<MessageContainingEnumCalledType> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.MapUnittestProto3Reflection.Descriptor.MessageTypes[5]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MessageContainingEnumCalledType() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MessageContainingEnumCalledType(MessageContainingEnumCalledType other) : this() {
+ type_ = other.type_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MessageContainingEnumCalledType Clone() {
+ return new MessageContainingEnumCalledType(this);
+ }
+
+ /// <summary>Field number for the "type" field.</summary>
+ public const int TypeFieldNumber = 1;
+ private static readonly pbc::MapField<int, global::Google.Protobuf.TestProtos.MessageContainingEnumCalledType>.Codec _map_type_codec
+ = new pbc::MapField<int, global::Google.Protobuf.TestProtos.MessageContainingEnumCalledType>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.TestProtos.MessageContainingEnumCalledType.Parser), 10);
+ private readonly pbc::MapField<int, global::Google.Protobuf.TestProtos.MessageContainingEnumCalledType> type_ = new pbc::MapField<int, global::Google.Protobuf.TestProtos.MessageContainingEnumCalledType>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, global::Google.Protobuf.TestProtos.MessageContainingEnumCalledType> Type {
+ get { return type_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as MessageContainingEnumCalledType);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(MessageContainingEnumCalledType other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (!Type.Equals(other.Type)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= Type.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ type_.WriteTo(output, _map_type_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += type_.CalculateSize(_map_type_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(MessageContainingEnumCalledType other) {
+ if (other == null) {
+ return;
+ }
+ type_.Add(other.type_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ type_.AddEntriesFrom(input, _map_type_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the MessageContainingEnumCalledType message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ public enum Type {
+ [pbr::OriginalName("TYPE_FOO")] Foo = 0,
+ }
+
+ }
+ #endregion
+
+ }
+
+ /// <summary>
+ /// Previously, message cannot contain map field called "entry".
+ /// </summary>
+ public sealed partial class MessageContainingMapCalledEntry : pb::IMessage<MessageContainingMapCalledEntry> {
+ private static readonly pb::MessageParser<MessageContainingMapCalledEntry> _parser = new pb::MessageParser<MessageContainingMapCalledEntry>(() => new MessageContainingMapCalledEntry());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<MessageContainingMapCalledEntry> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.MapUnittestProto3Reflection.Descriptor.MessageTypes[6]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MessageContainingMapCalledEntry() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MessageContainingMapCalledEntry(MessageContainingMapCalledEntry other) : this() {
+ entry_ = other.entry_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MessageContainingMapCalledEntry Clone() {
+ return new MessageContainingMapCalledEntry(this);
+ }
+
+ /// <summary>Field number for the "entry" field.</summary>
+ public const int EntryFieldNumber = 1;
+ private static readonly pbc::MapField<int, int>.Codec _map_entry_codec
+ = new pbc::MapField<int, int>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForInt32(16), 10);
+ private readonly pbc::MapField<int, int> entry_ = new pbc::MapField<int, int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, int> Entry {
+ get { return entry_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as MessageContainingMapCalledEntry);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(MessageContainingMapCalledEntry other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (!Entry.Equals(other.Entry)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= Entry.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ entry_.WriteTo(output, _map_entry_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += entry_.CalculateSize(_map_entry_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(MessageContainingMapCalledEntry other) {
+ if (other == null) {
+ return;
+ }
+ entry_.Add(other.entry_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ entry_.AddEntriesFrom(input, _map_entry_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs
new file mode 100644
index 0000000000..fbeb512ac7
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto3.cs
@@ -0,0 +1,3688 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/test_messages_proto3.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace ProtobufTestMessages.Proto3 {
+
+ /// <summary>Holder for reflection information generated from google/protobuf/test_messages_proto3.proto</summary>
+ public static partial class TestMessagesProto3Reflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for google/protobuf/test_messages_proto3.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static TestMessagesProto3Reflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "Cipnb29nbGUvcHJvdG9idWYvdGVzdF9tZXNzYWdlc19wcm90bzMucHJvdG8S",
+ "HXByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8zGhlnb29nbGUvcHJvdG9i",
+ "dWYvYW55LnByb3RvGh5nb29nbGUvcHJvdG9idWYvZHVyYXRpb24ucHJvdG8a",
+ "IGdvb2dsZS9wcm90b2J1Zi9maWVsZF9tYXNrLnByb3RvGhxnb29nbGUvcHJv",
+ "dG9idWYvc3RydWN0LnByb3RvGh9nb29nbGUvcHJvdG9idWYvdGltZXN0YW1w",
+ "LnByb3RvGh5nb29nbGUvcHJvdG9idWYvd3JhcHBlcnMucHJvdG8i+DkKDFRl",
+ "c3RBbGxUeXBlcxIWCg5vcHRpb25hbF9pbnQzMhgBIAEoBRIWCg5vcHRpb25h",
+ "bF9pbnQ2NBgCIAEoAxIXCg9vcHRpb25hbF91aW50MzIYAyABKA0SFwoPb3B0",
+ "aW9uYWxfdWludDY0GAQgASgEEhcKD29wdGlvbmFsX3NpbnQzMhgFIAEoERIX",
+ "Cg9vcHRpb25hbF9zaW50NjQYBiABKBISGAoQb3B0aW9uYWxfZml4ZWQzMhgH",
+ "IAEoBxIYChBvcHRpb25hbF9maXhlZDY0GAggASgGEhkKEW9wdGlvbmFsX3Nm",
+ "aXhlZDMyGAkgASgPEhkKEW9wdGlvbmFsX3NmaXhlZDY0GAogASgQEhYKDm9w",
+ "dGlvbmFsX2Zsb2F0GAsgASgCEhcKD29wdGlvbmFsX2RvdWJsZRgMIAEoARIV",
+ "Cg1vcHRpb25hbF9ib29sGA0gASgIEhcKD29wdGlvbmFsX3N0cmluZxgOIAEo",
+ "CRIWCg5vcHRpb25hbF9ieXRlcxgPIAEoDBJaChdvcHRpb25hbF9uZXN0ZWRf",
+ "bWVzc2FnZRgSIAEoCzI5LnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8z",
+ "LlRlc3RBbGxUeXBlcy5OZXN0ZWRNZXNzYWdlEk8KGG9wdGlvbmFsX2ZvcmVp",
+ "Z25fbWVzc2FnZRgTIAEoCzItLnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJv",
+ "dG8zLkZvcmVpZ25NZXNzYWdlElQKFG9wdGlvbmFsX25lc3RlZF9lbnVtGBUg",
+ "ASgOMjYucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5wcm90bzMuVGVzdEFsbFR5",
+ "cGVzLk5lc3RlZEVudW0SSQoVb3B0aW9uYWxfZm9yZWlnbl9lbnVtGBYgASgO",
+ "MioucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5wcm90bzMuRm9yZWlnbkVudW0S",
+ "IQoVb3B0aW9uYWxfc3RyaW5nX3BpZWNlGBggASgJQgIIAhIZCg1vcHRpb25h",
+ "bF9jb3JkGBkgASgJQgIIARJGChFyZWN1cnNpdmVfbWVzc2FnZRgbIAEoCzIr",
+ "LnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8zLlRlc3RBbGxUeXBlcxIW",
+ "Cg5yZXBlYXRlZF9pbnQzMhgfIAMoBRIWCg5yZXBlYXRlZF9pbnQ2NBggIAMo",
+ "AxIXCg9yZXBlYXRlZF91aW50MzIYISADKA0SFwoPcmVwZWF0ZWRfdWludDY0",
+ "GCIgAygEEhcKD3JlcGVhdGVkX3NpbnQzMhgjIAMoERIXCg9yZXBlYXRlZF9z",
+ "aW50NjQYJCADKBISGAoQcmVwZWF0ZWRfZml4ZWQzMhglIAMoBxIYChByZXBl",
+ "YXRlZF9maXhlZDY0GCYgAygGEhkKEXJlcGVhdGVkX3NmaXhlZDMyGCcgAygP",
+ "EhkKEXJlcGVhdGVkX3NmaXhlZDY0GCggAygQEhYKDnJlcGVhdGVkX2Zsb2F0",
+ "GCkgAygCEhcKD3JlcGVhdGVkX2RvdWJsZRgqIAMoARIVCg1yZXBlYXRlZF9i",
+ "b29sGCsgAygIEhcKD3JlcGVhdGVkX3N0cmluZxgsIAMoCRIWCg5yZXBlYXRl",
+ "ZF9ieXRlcxgtIAMoDBJaChdyZXBlYXRlZF9uZXN0ZWRfbWVzc2FnZRgwIAMo",
+ "CzI5LnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8zLlRlc3RBbGxUeXBl",
+ "cy5OZXN0ZWRNZXNzYWdlEk8KGHJlcGVhdGVkX2ZvcmVpZ25fbWVzc2FnZRgx",
+ "IAMoCzItLnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8zLkZvcmVpZ25N",
+ "ZXNzYWdlElQKFHJlcGVhdGVkX25lc3RlZF9lbnVtGDMgAygOMjYucHJvdG9i",
+ "dWZfdGVzdF9tZXNzYWdlcy5wcm90bzMuVGVzdEFsbFR5cGVzLk5lc3RlZEVu",
+ "dW0SSQoVcmVwZWF0ZWRfZm9yZWlnbl9lbnVtGDQgAygOMioucHJvdG9idWZf",
+ "dGVzdF9tZXNzYWdlcy5wcm90bzMuRm9yZWlnbkVudW0SIQoVcmVwZWF0ZWRf",
+ "c3RyaW5nX3BpZWNlGDYgAygJQgIIAhIZCg1yZXBlYXRlZF9jb3JkGDcgAygJ",
+ "QgIIARJXCg9tYXBfaW50MzJfaW50MzIYOCADKAsyPi5wcm90b2J1Zl90ZXN0",
+ "X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlwZXMuTWFwSW50MzJJbnQzMkVu",
+ "dHJ5ElcKD21hcF9pbnQ2NF9pbnQ2NBg5IAMoCzI+LnByb3RvYnVmX3Rlc3Rf",
+ "bWVzc2FnZXMucHJvdG8zLlRlc3RBbGxUeXBlcy5NYXBJbnQ2NEludDY0RW50",
+ "cnkSWwoRbWFwX3VpbnQzMl91aW50MzIYOiADKAsyQC5wcm90b2J1Zl90ZXN0",
+ "X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlwZXMuTWFwVWludDMyVWludDMy",
+ "RW50cnkSWwoRbWFwX3VpbnQ2NF91aW50NjQYOyADKAsyQC5wcm90b2J1Zl90",
+ "ZXN0X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlwZXMuTWFwVWludDY0VWlu",
+ "dDY0RW50cnkSWwoRbWFwX3NpbnQzMl9zaW50MzIYPCADKAsyQC5wcm90b2J1",
+ "Zl90ZXN0X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlwZXMuTWFwU2ludDMy",
+ "U2ludDMyRW50cnkSWwoRbWFwX3NpbnQ2NF9zaW50NjQYPSADKAsyQC5wcm90",
+ "b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlwZXMuTWFwU2lu",
+ "dDY0U2ludDY0RW50cnkSXwoTbWFwX2ZpeGVkMzJfZml4ZWQzMhg+IAMoCzJC",
+ "LnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8zLlRlc3RBbGxUeXBlcy5N",
+ "YXBGaXhlZDMyRml4ZWQzMkVudHJ5El8KE21hcF9maXhlZDY0X2ZpeGVkNjQY",
+ "PyADKAsyQi5wcm90b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxs",
+ "VHlwZXMuTWFwRml4ZWQ2NEZpeGVkNjRFbnRyeRJjChVtYXBfc2ZpeGVkMzJf",
+ "c2ZpeGVkMzIYQCADKAsyRC5wcm90b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3Rv",
+ "My5UZXN0QWxsVHlwZXMuTWFwU2ZpeGVkMzJTZml4ZWQzMkVudHJ5EmMKFW1h",
+ "cF9zZml4ZWQ2NF9zZml4ZWQ2NBhBIAMoCzJELnByb3RvYnVmX3Rlc3RfbWVz",
+ "c2FnZXMucHJvdG8zLlRlc3RBbGxUeXBlcy5NYXBTZml4ZWQ2NFNmaXhlZDY0",
+ "RW50cnkSVwoPbWFwX2ludDMyX2Zsb2F0GEIgAygLMj4ucHJvdG9idWZfdGVz",
+ "dF9tZXNzYWdlcy5wcm90bzMuVGVzdEFsbFR5cGVzLk1hcEludDMyRmxvYXRF",
+ "bnRyeRJZChBtYXBfaW50MzJfZG91YmxlGEMgAygLMj8ucHJvdG9idWZfdGVz",
+ "dF9tZXNzYWdlcy5wcm90bzMuVGVzdEFsbFR5cGVzLk1hcEludDMyRG91Ymxl",
+ "RW50cnkSUwoNbWFwX2Jvb2xfYm9vbBhEIAMoCzI8LnByb3RvYnVmX3Rlc3Rf",
+ "bWVzc2FnZXMucHJvdG8zLlRlc3RBbGxUeXBlcy5NYXBCb29sQm9vbEVudHJ5",
+ "ElsKEW1hcF9zdHJpbmdfc3RyaW5nGEUgAygLMkAucHJvdG9idWZfdGVzdF9t",
+ "ZXNzYWdlcy5wcm90bzMuVGVzdEFsbFR5cGVzLk1hcFN0cmluZ1N0cmluZ0Vu",
+ "dHJ5ElkKEG1hcF9zdHJpbmdfYnl0ZXMYRiADKAsyPy5wcm90b2J1Zl90ZXN0",
+ "X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlwZXMuTWFwU3RyaW5nQnl0ZXNF",
+ "bnRyeRJqChltYXBfc3RyaW5nX25lc3RlZF9tZXNzYWdlGEcgAygLMkcucHJv",
+ "dG9idWZfdGVzdF9tZXNzYWdlcy5wcm90bzMuVGVzdEFsbFR5cGVzLk1hcFN0",
+ "cmluZ05lc3RlZE1lc3NhZ2VFbnRyeRJsChptYXBfc3RyaW5nX2ZvcmVpZ25f",
+ "bWVzc2FnZRhIIAMoCzJILnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8z",
+ "LlRlc3RBbGxUeXBlcy5NYXBTdHJpbmdGb3JlaWduTWVzc2FnZUVudHJ5EmQK",
+ "Fm1hcF9zdHJpbmdfbmVzdGVkX2VudW0YSSADKAsyRC5wcm90b2J1Zl90ZXN0",
+ "X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlwZXMuTWFwU3RyaW5nTmVzdGVk",
+ "RW51bUVudHJ5EmYKF21hcF9zdHJpbmdfZm9yZWlnbl9lbnVtGEogAygLMkUu",
+ "cHJvdG9idWZfdGVzdF9tZXNzYWdlcy5wcm90bzMuVGVzdEFsbFR5cGVzLk1h",
+ "cFN0cmluZ0ZvcmVpZ25FbnVtRW50cnkSFgoMb25lb2ZfdWludDMyGG8gASgN",
+ "SAASWQoUb25lb2ZfbmVzdGVkX21lc3NhZ2UYcCABKAsyOS5wcm90b2J1Zl90",
+ "ZXN0X21lc3NhZ2VzLnByb3RvMy5UZXN0QWxsVHlwZXMuTmVzdGVkTWVzc2Fn",
+ "ZUgAEhYKDG9uZW9mX3N0cmluZxhxIAEoCUgAEhUKC29uZW9mX2J5dGVzGHIg",
+ "ASgMSAASFAoKb25lb2ZfYm9vbBhzIAEoCEgAEhYKDG9uZW9mX3VpbnQ2NBh0",
+ "IAEoBEgAEhUKC29uZW9mX2Zsb2F0GHUgASgCSAASFgoMb25lb2ZfZG91Ymxl",
+ "GHYgASgBSAASTAoKb25lb2ZfZW51bRh3IAEoDjI2LnByb3RvYnVmX3Rlc3Rf",
+ "bWVzc2FnZXMucHJvdG8zLlRlc3RBbGxUeXBlcy5OZXN0ZWRFbnVtSAASOgoV",
+ "b3B0aW9uYWxfYm9vbF93cmFwcGVyGMkBIAEoCzIaLmdvb2dsZS5wcm90b2J1",
+ "Zi5Cb29sVmFsdWUSPAoWb3B0aW9uYWxfaW50MzJfd3JhcHBlchjKASABKAsy",
+ "Gy5nb29nbGUucHJvdG9idWYuSW50MzJWYWx1ZRI8ChZvcHRpb25hbF9pbnQ2",
+ "NF93cmFwcGVyGMsBIAEoCzIbLmdvb2dsZS5wcm90b2J1Zi5JbnQ2NFZhbHVl",
+ "Ej4KF29wdGlvbmFsX3VpbnQzMl93cmFwcGVyGMwBIAEoCzIcLmdvb2dsZS5w",
+ "cm90b2J1Zi5VSW50MzJWYWx1ZRI+ChdvcHRpb25hbF91aW50NjRfd3JhcHBl",
+ "chjNASABKAsyHC5nb29nbGUucHJvdG9idWYuVUludDY0VmFsdWUSPAoWb3B0",
+ "aW9uYWxfZmxvYXRfd3JhcHBlchjOASABKAsyGy5nb29nbGUucHJvdG9idWYu",
+ "RmxvYXRWYWx1ZRI+ChdvcHRpb25hbF9kb3VibGVfd3JhcHBlchjPASABKAsy",
+ "HC5nb29nbGUucHJvdG9idWYuRG91YmxlVmFsdWUSPgoXb3B0aW9uYWxfc3Ry",
+ "aW5nX3dyYXBwZXIY0AEgASgLMhwuZ29vZ2xlLnByb3RvYnVmLlN0cmluZ1Zh",
+ "bHVlEjwKFm9wdGlvbmFsX2J5dGVzX3dyYXBwZXIY0QEgASgLMhsuZ29vZ2xl",
+ "LnByb3RvYnVmLkJ5dGVzVmFsdWUSOgoVcmVwZWF0ZWRfYm9vbF93cmFwcGVy",
+ "GNMBIAMoCzIaLmdvb2dsZS5wcm90b2J1Zi5Cb29sVmFsdWUSPAoWcmVwZWF0",
+ "ZWRfaW50MzJfd3JhcHBlchjUASADKAsyGy5nb29nbGUucHJvdG9idWYuSW50",
+ "MzJWYWx1ZRI8ChZyZXBlYXRlZF9pbnQ2NF93cmFwcGVyGNUBIAMoCzIbLmdv",
+ "b2dsZS5wcm90b2J1Zi5JbnQ2NFZhbHVlEj4KF3JlcGVhdGVkX3VpbnQzMl93",
+ "cmFwcGVyGNYBIAMoCzIcLmdvb2dsZS5wcm90b2J1Zi5VSW50MzJWYWx1ZRI+",
+ "ChdyZXBlYXRlZF91aW50NjRfd3JhcHBlchjXASADKAsyHC5nb29nbGUucHJv",
+ "dG9idWYuVUludDY0VmFsdWUSPAoWcmVwZWF0ZWRfZmxvYXRfd3JhcHBlchjY",
+ "ASADKAsyGy5nb29nbGUucHJvdG9idWYuRmxvYXRWYWx1ZRI+ChdyZXBlYXRl",
+ "ZF9kb3VibGVfd3JhcHBlchjZASADKAsyHC5nb29nbGUucHJvdG9idWYuRG91",
+ "YmxlVmFsdWUSPgoXcmVwZWF0ZWRfc3RyaW5nX3dyYXBwZXIY2gEgAygLMhwu",
+ "Z29vZ2xlLnByb3RvYnVmLlN0cmluZ1ZhbHVlEjwKFnJlcGVhdGVkX2J5dGVz",
+ "X3dyYXBwZXIY2wEgAygLMhsuZ29vZ2xlLnByb3RvYnVmLkJ5dGVzVmFsdWUS",
+ "NQoRb3B0aW9uYWxfZHVyYXRpb24YrQIgASgLMhkuZ29vZ2xlLnByb3RvYnVm",
+ "LkR1cmF0aW9uEjcKEm9wdGlvbmFsX3RpbWVzdGFtcBiuAiABKAsyGi5nb29n",
+ "bGUucHJvdG9idWYuVGltZXN0YW1wEjgKE29wdGlvbmFsX2ZpZWxkX21hc2sY",
+ "rwIgASgLMhouZ29vZ2xlLnByb3RvYnVmLkZpZWxkTWFzaxIxCg9vcHRpb25h",
+ "bF9zdHJ1Y3QYsAIgASgLMhcuZ29vZ2xlLnByb3RvYnVmLlN0cnVjdBIrCgxv",
+ "cHRpb25hbF9hbnkYsQIgASgLMhQuZ29vZ2xlLnByb3RvYnVmLkFueRIvCg5v",
+ "cHRpb25hbF92YWx1ZRiyAiABKAsyFi5nb29nbGUucHJvdG9idWYuVmFsdWUS",
+ "NQoRcmVwZWF0ZWRfZHVyYXRpb24YtwIgAygLMhkuZ29vZ2xlLnByb3RvYnVm",
+ "LkR1cmF0aW9uEjcKEnJlcGVhdGVkX3RpbWVzdGFtcBi4AiADKAsyGi5nb29n",
+ "bGUucHJvdG9idWYuVGltZXN0YW1wEjcKEnJlcGVhdGVkX2ZpZWxkbWFzaxi5",
+ "AiADKAsyGi5nb29nbGUucHJvdG9idWYuRmllbGRNYXNrEjEKD3JlcGVhdGVk",
+ "X3N0cnVjdBjEAiADKAsyFy5nb29nbGUucHJvdG9idWYuU3RydWN0EisKDHJl",
+ "cGVhdGVkX2FueRi7AiADKAsyFC5nb29nbGUucHJvdG9idWYuQW55Ei8KDnJl",
+ "cGVhdGVkX3ZhbHVlGLwCIAMoCzIWLmdvb2dsZS5wcm90b2J1Zi5WYWx1ZRIT",
+ "CgpmaWVsZG5hbWUxGJEDIAEoBRIUCgtmaWVsZF9uYW1lMhiSAyABKAUSFQoM",
+ "X2ZpZWxkX25hbWUzGJMDIAEoBRIWCg1maWVsZF9fbmFtZTRfGJQDIAEoBRIU",
+ "CgtmaWVsZDBuYW1lNRiVAyABKAUSFgoNZmllbGRfMF9uYW1lNhiWAyABKAUS",
+ "EwoKZmllbGROYW1lNxiXAyABKAUSEwoKRmllbGROYW1lOBiYAyABKAUSFAoL",
+ "ZmllbGRfTmFtZTkYmQMgASgFEhUKDEZpZWxkX05hbWUxMBiaAyABKAUSFQoM",
+ "RklFTERfTkFNRTExGJsDIAEoBRIVCgxGSUVMRF9uYW1lMTIYnAMgASgFEhcK",
+ "Dl9fZmllbGRfbmFtZTEzGJ0DIAEoBRIXCg5fX0ZpZWxkX25hbWUxNBieAyAB",
+ "KAUSFgoNZmllbGRfX25hbWUxNRifAyABKAUSFgoNZmllbGRfX05hbWUxNhig",
+ "AyABKAUSFwoOZmllbGRfbmFtZTE3X18YoQMgASgFEhcKDkZpZWxkX25hbWUx",
+ "OF9fGKIDIAEoBRpcCg1OZXN0ZWRNZXNzYWdlEgkKAWEYASABKAUSQAoLY29y",
+ "ZWN1cnNpdmUYAiABKAsyKy5wcm90b2J1Zl90ZXN0X21lc3NhZ2VzLnByb3Rv",
+ "My5UZXN0QWxsVHlwZXMaNAoSTWFwSW50MzJJbnQzMkVudHJ5EgsKA2tleRgB",
+ "IAEoBRINCgV2YWx1ZRgCIAEoBToCOAEaNAoSTWFwSW50NjRJbnQ2NEVudHJ5",
+ "EgsKA2tleRgBIAEoAxINCgV2YWx1ZRgCIAEoAzoCOAEaNgoUTWFwVWludDMy",
+ "VWludDMyRW50cnkSCwoDa2V5GAEgASgNEg0KBXZhbHVlGAIgASgNOgI4ARo2",
+ "ChRNYXBVaW50NjRVaW50NjRFbnRyeRILCgNrZXkYASABKAQSDQoFdmFsdWUY",
+ "AiABKAQ6AjgBGjYKFE1hcFNpbnQzMlNpbnQzMkVudHJ5EgsKA2tleRgBIAEo",
+ "ERINCgV2YWx1ZRgCIAEoEToCOAEaNgoUTWFwU2ludDY0U2ludDY0RW50cnkS",
+ "CwoDa2V5GAEgASgSEg0KBXZhbHVlGAIgASgSOgI4ARo4ChZNYXBGaXhlZDMy",
+ "Rml4ZWQzMkVudHJ5EgsKA2tleRgBIAEoBxINCgV2YWx1ZRgCIAEoBzoCOAEa",
+ "OAoWTWFwRml4ZWQ2NEZpeGVkNjRFbnRyeRILCgNrZXkYASABKAYSDQoFdmFs",
+ "dWUYAiABKAY6AjgBGjoKGE1hcFNmaXhlZDMyU2ZpeGVkMzJFbnRyeRILCgNr",
+ "ZXkYASABKA8SDQoFdmFsdWUYAiABKA86AjgBGjoKGE1hcFNmaXhlZDY0U2Zp",
+ "eGVkNjRFbnRyeRILCgNrZXkYASABKBASDQoFdmFsdWUYAiABKBA6AjgBGjQK",
+ "Ek1hcEludDMyRmxvYXRFbnRyeRILCgNrZXkYASABKAUSDQoFdmFsdWUYAiAB",
+ "KAI6AjgBGjUKE01hcEludDMyRG91YmxlRW50cnkSCwoDa2V5GAEgASgFEg0K",
+ "BXZhbHVlGAIgASgBOgI4ARoyChBNYXBCb29sQm9vbEVudHJ5EgsKA2tleRgB",
+ "IAEoCBINCgV2YWx1ZRgCIAEoCDoCOAEaNgoUTWFwU3RyaW5nU3RyaW5nRW50",
+ "cnkSCwoDa2V5GAEgASgJEg0KBXZhbHVlGAIgASgJOgI4ARo1ChNNYXBTdHJp",
+ "bmdCeXRlc0VudHJ5EgsKA2tleRgBIAEoCRINCgV2YWx1ZRgCIAEoDDoCOAEa",
+ "eAobTWFwU3RyaW5nTmVzdGVkTWVzc2FnZUVudHJ5EgsKA2tleRgBIAEoCRJI",
+ "CgV2YWx1ZRgCIAEoCzI5LnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8z",
+ "LlRlc3RBbGxUeXBlcy5OZXN0ZWRNZXNzYWdlOgI4ARptChxNYXBTdHJpbmdG",
+ "b3JlaWduTWVzc2FnZUVudHJ5EgsKA2tleRgBIAEoCRI8CgV2YWx1ZRgCIAEo",
+ "CzItLnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8zLkZvcmVpZ25NZXNz",
+ "YWdlOgI4ARpyChhNYXBTdHJpbmdOZXN0ZWRFbnVtRW50cnkSCwoDa2V5GAEg",
+ "ASgJEkUKBXZhbHVlGAIgASgOMjYucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5w",
+ "cm90bzMuVGVzdEFsbFR5cGVzLk5lc3RlZEVudW06AjgBGmcKGU1hcFN0cmlu",
+ "Z0ZvcmVpZ25FbnVtRW50cnkSCwoDa2V5GAEgASgJEjkKBXZhbHVlGAIgASgO",
+ "MioucHJvdG9idWZfdGVzdF9tZXNzYWdlcy5wcm90bzMuRm9yZWlnbkVudW06",
+ "AjgBIjkKCk5lc3RlZEVudW0SBwoDRk9PEAASBwoDQkFSEAESBwoDQkFaEAIS",
+ "EAoDTkVHEP///////////wFCDQoLb25lb2ZfZmllbGQiGwoORm9yZWlnbk1l",
+ "c3NhZ2USCQoBYxgBIAEoBSpACgtGb3JlaWduRW51bRIPCgtGT1JFSUdOX0ZP",
+ "TxAAEg8KC0ZPUkVJR05fQkFSEAESDwoLRk9SRUlHTl9CQVoQAkIvCihjb20u",
+ "Z29vZ2xlLnByb3RvYnVmX3Rlc3RfbWVzc2FnZXMucHJvdG8zSAH4AQFiBnBy",
+ "b3RvMw=="));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.AnyReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.DurationReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.FieldMaskReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.StructReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.TimestampReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor, },
+ new pbr::GeneratedClrTypeInfo(new[] {typeof(global::ProtobufTestMessages.Proto3.ForeignEnum), }, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufTestMessages.Proto3.TestAllTypes), global::ProtobufTestMessages.Proto3.TestAllTypes.Parser, new[]{ "OptionalInt32", "OptionalInt64", "OptionalUint32", "OptionalUint64", "OptionalSint32", "OptionalSint64", "OptionalFixed32", "OptionalFixed64", "OptionalSfixed32", "OptionalSfixed64", "OptionalFloat", "OptionalDouble", "OptionalBool", "OptionalString", "OptionalBytes", "OptionalNestedMessage", "OptionalForeignMessage", "OptionalNestedEnum", "OptionalForeignEnum", "OptionalStringPiece", "OptionalCord", "RecursiveMessage", "RepeatedInt32", "RepeatedInt64", "RepeatedUint32", "RepeatedUint64", "RepeatedSint32", "RepeatedSint64", "RepeatedFixed32", "RepeatedFixed64", "RepeatedSfixed32", "RepeatedSfixed64", "RepeatedFloat", "RepeatedDouble", "RepeatedBool", "RepeatedString", "RepeatedBytes", "RepeatedNestedMessage", "RepeatedForeignMessage", "RepeatedNestedEnum", "RepeatedForeignEnum", "RepeatedStringPiece", "RepeatedCord", "MapInt32Int32", "MapInt64Int64", "MapUint32Uint32", "MapUint64Uint64", "MapSint32Sint32", "MapSint64Sint64", "MapFixed32Fixed32", "MapFixed64Fixed64", "MapSfixed32Sfixed32", "MapSfixed64Sfixed64", "MapInt32Float", "MapInt32Double", "MapBoolBool", "MapStringString", "MapStringBytes", "MapStringNestedMessage", "MapStringForeignMessage", "MapStringNestedEnum", "MapStringForeignEnum", "OneofUint32", "OneofNestedMessage", "OneofString", "OneofBytes", "OneofBool", "OneofUint64", "OneofFloat", "OneofDouble", "OneofEnum", "OptionalBoolWrapper", "OptionalInt32Wrapper", "OptionalInt64Wrapper", "OptionalUint32Wrapper", "OptionalUint64Wrapper", "OptionalFloatWrapper", "OptionalDoubleWrapper", "OptionalStringWrapper", "OptionalBytesWrapper", "RepeatedBoolWrapper", "RepeatedInt32Wrapper", "RepeatedInt64Wrapper", "RepeatedUint32Wrapper", "RepeatedUint64Wrapper", "RepeatedFloatWrapper", "RepeatedDoubleWrapper", "RepeatedStringWrapper", "RepeatedBytesWrapper", "OptionalDuration", "OptionalTimestamp", "OptionalFieldMask", "OptionalStruct", "OptionalAny", "OptionalValue", "RepeatedDuration", "RepeatedTimestamp", "RepeatedFieldmask", "RepeatedStruct", "RepeatedAny", "RepeatedValue", "Fieldname1", "FieldName2", "FieldName3", "FieldName4", "Field0Name5", "Field0Name6", "FieldName7", "FieldName8", "FieldName9", "FieldName10", "FIELDNAME11", "FIELDName12", "FieldName13", "FieldName14", "FieldName15", "FieldName16", "FieldName17", "FieldName18" }, new[]{ "OneofField" }, new[]{ typeof(global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedEnum) }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage), global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage.Parser, new[]{ "A", "Corecursive" }, null, null, null),
+ null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, }),
+ new pbr::GeneratedClrTypeInfo(typeof(global::ProtobufTestMessages.Proto3.ForeignMessage), global::ProtobufTestMessages.Proto3.ForeignMessage.Parser, new[]{ "C" }, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Enums
+ public enum ForeignEnum {
+ [pbr::OriginalName("FOREIGN_FOO")] ForeignFoo = 0,
+ [pbr::OriginalName("FOREIGN_BAR")] ForeignBar = 1,
+ [pbr::OriginalName("FOREIGN_BAZ")] ForeignBaz = 2,
+ }
+
+ #endregion
+
+ #region Messages
+ /// <summary>
+ /// This proto includes every type of field in both singular and repeated
+ /// forms.
+ ///
+ /// Also, crucially, all messages and enums in this file are eventually
+ /// submessages of this message. So for example, a fuzz test of TestAllTypes
+ /// could trigger bugs that occur in any message type in this file. We verify
+ /// this stays true in a unit test.
+ /// </summary>
+ public sealed partial class TestAllTypes : pb::IMessage<TestAllTypes> {
+ private static readonly pb::MessageParser<TestAllTypes> _parser = new pb::MessageParser<TestAllTypes>(() => new TestAllTypes());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestAllTypes> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::ProtobufTestMessages.Proto3.TestMessagesProto3Reflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestAllTypes() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestAllTypes(TestAllTypes other) : this() {
+ optionalInt32_ = other.optionalInt32_;
+ optionalInt64_ = other.optionalInt64_;
+ optionalUint32_ = other.optionalUint32_;
+ optionalUint64_ = other.optionalUint64_;
+ optionalSint32_ = other.optionalSint32_;
+ optionalSint64_ = other.optionalSint64_;
+ optionalFixed32_ = other.optionalFixed32_;
+ optionalFixed64_ = other.optionalFixed64_;
+ optionalSfixed32_ = other.optionalSfixed32_;
+ optionalSfixed64_ = other.optionalSfixed64_;
+ optionalFloat_ = other.optionalFloat_;
+ optionalDouble_ = other.optionalDouble_;
+ optionalBool_ = other.optionalBool_;
+ optionalString_ = other.optionalString_;
+ optionalBytes_ = other.optionalBytes_;
+ OptionalNestedMessage = other.optionalNestedMessage_ != null ? other.OptionalNestedMessage.Clone() : null;
+ OptionalForeignMessage = other.optionalForeignMessage_ != null ? other.OptionalForeignMessage.Clone() : null;
+ optionalNestedEnum_ = other.optionalNestedEnum_;
+ optionalForeignEnum_ = other.optionalForeignEnum_;
+ optionalStringPiece_ = other.optionalStringPiece_;
+ optionalCord_ = other.optionalCord_;
+ RecursiveMessage = other.recursiveMessage_ != null ? other.RecursiveMessage.Clone() : null;
+ repeatedInt32_ = other.repeatedInt32_.Clone();
+ repeatedInt64_ = other.repeatedInt64_.Clone();
+ repeatedUint32_ = other.repeatedUint32_.Clone();
+ repeatedUint64_ = other.repeatedUint64_.Clone();
+ repeatedSint32_ = other.repeatedSint32_.Clone();
+ repeatedSint64_ = other.repeatedSint64_.Clone();
+ repeatedFixed32_ = other.repeatedFixed32_.Clone();
+ repeatedFixed64_ = other.repeatedFixed64_.Clone();
+ repeatedSfixed32_ = other.repeatedSfixed32_.Clone();
+ repeatedSfixed64_ = other.repeatedSfixed64_.Clone();
+ repeatedFloat_ = other.repeatedFloat_.Clone();
+ repeatedDouble_ = other.repeatedDouble_.Clone();
+ repeatedBool_ = other.repeatedBool_.Clone();
+ repeatedString_ = other.repeatedString_.Clone();
+ repeatedBytes_ = other.repeatedBytes_.Clone();
+ repeatedNestedMessage_ = other.repeatedNestedMessage_.Clone();
+ repeatedForeignMessage_ = other.repeatedForeignMessage_.Clone();
+ repeatedNestedEnum_ = other.repeatedNestedEnum_.Clone();
+ repeatedForeignEnum_ = other.repeatedForeignEnum_.Clone();
+ repeatedStringPiece_ = other.repeatedStringPiece_.Clone();
+ repeatedCord_ = other.repeatedCord_.Clone();
+ mapInt32Int32_ = other.mapInt32Int32_.Clone();
+ mapInt64Int64_ = other.mapInt64Int64_.Clone();
+ mapUint32Uint32_ = other.mapUint32Uint32_.Clone();
+ mapUint64Uint64_ = other.mapUint64Uint64_.Clone();
+ mapSint32Sint32_ = other.mapSint32Sint32_.Clone();
+ mapSint64Sint64_ = other.mapSint64Sint64_.Clone();
+ mapFixed32Fixed32_ = other.mapFixed32Fixed32_.Clone();
+ mapFixed64Fixed64_ = other.mapFixed64Fixed64_.Clone();
+ mapSfixed32Sfixed32_ = other.mapSfixed32Sfixed32_.Clone();
+ mapSfixed64Sfixed64_ = other.mapSfixed64Sfixed64_.Clone();
+ mapInt32Float_ = other.mapInt32Float_.Clone();
+ mapInt32Double_ = other.mapInt32Double_.Clone();
+ mapBoolBool_ = other.mapBoolBool_.Clone();
+ mapStringString_ = other.mapStringString_.Clone();
+ mapStringBytes_ = other.mapStringBytes_.Clone();
+ mapStringNestedMessage_ = other.mapStringNestedMessage_.Clone();
+ mapStringForeignMessage_ = other.mapStringForeignMessage_.Clone();
+ mapStringNestedEnum_ = other.mapStringNestedEnum_.Clone();
+ mapStringForeignEnum_ = other.mapStringForeignEnum_.Clone();
+ OptionalBoolWrapper = other.OptionalBoolWrapper;
+ OptionalInt32Wrapper = other.OptionalInt32Wrapper;
+ OptionalInt64Wrapper = other.OptionalInt64Wrapper;
+ OptionalUint32Wrapper = other.OptionalUint32Wrapper;
+ OptionalUint64Wrapper = other.OptionalUint64Wrapper;
+ OptionalFloatWrapper = other.OptionalFloatWrapper;
+ OptionalDoubleWrapper = other.OptionalDoubleWrapper;
+ OptionalStringWrapper = other.OptionalStringWrapper;
+ OptionalBytesWrapper = other.OptionalBytesWrapper;
+ repeatedBoolWrapper_ = other.repeatedBoolWrapper_.Clone();
+ repeatedInt32Wrapper_ = other.repeatedInt32Wrapper_.Clone();
+ repeatedInt64Wrapper_ = other.repeatedInt64Wrapper_.Clone();
+ repeatedUint32Wrapper_ = other.repeatedUint32Wrapper_.Clone();
+ repeatedUint64Wrapper_ = other.repeatedUint64Wrapper_.Clone();
+ repeatedFloatWrapper_ = other.repeatedFloatWrapper_.Clone();
+ repeatedDoubleWrapper_ = other.repeatedDoubleWrapper_.Clone();
+ repeatedStringWrapper_ = other.repeatedStringWrapper_.Clone();
+ repeatedBytesWrapper_ = other.repeatedBytesWrapper_.Clone();
+ OptionalDuration = other.optionalDuration_ != null ? other.OptionalDuration.Clone() : null;
+ OptionalTimestamp = other.optionalTimestamp_ != null ? other.OptionalTimestamp.Clone() : null;
+ OptionalFieldMask = other.optionalFieldMask_ != null ? other.OptionalFieldMask.Clone() : null;
+ OptionalStruct = other.optionalStruct_ != null ? other.OptionalStruct.Clone() : null;
+ OptionalAny = other.optionalAny_ != null ? other.OptionalAny.Clone() : null;
+ OptionalValue = other.optionalValue_ != null ? other.OptionalValue.Clone() : null;
+ repeatedDuration_ = other.repeatedDuration_.Clone();
+ repeatedTimestamp_ = other.repeatedTimestamp_.Clone();
+ repeatedFieldmask_ = other.repeatedFieldmask_.Clone();
+ repeatedStruct_ = other.repeatedStruct_.Clone();
+ repeatedAny_ = other.repeatedAny_.Clone();
+ repeatedValue_ = other.repeatedValue_.Clone();
+ fieldname1_ = other.fieldname1_;
+ fieldName2_ = other.fieldName2_;
+ FieldName3_ = other.FieldName3_;
+ fieldName4_ = other.fieldName4_;
+ field0Name5_ = other.field0Name5_;
+ field0Name6_ = other.field0Name6_;
+ fieldName7_ = other.fieldName7_;
+ fieldName8_ = other.fieldName8_;
+ fieldName9_ = other.fieldName9_;
+ fieldName10_ = other.fieldName10_;
+ fIELDNAME11_ = other.fIELDNAME11_;
+ fIELDName12_ = other.fIELDName12_;
+ FieldName13_ = other.FieldName13_;
+ FieldName14_ = other.FieldName14_;
+ fieldName15_ = other.fieldName15_;
+ fieldName16_ = other.fieldName16_;
+ fieldName17_ = other.fieldName17_;
+ fieldName18_ = other.fieldName18_;
+ switch (other.OneofFieldCase) {
+ case OneofFieldOneofCase.OneofUint32:
+ OneofUint32 = other.OneofUint32;
+ break;
+ case OneofFieldOneofCase.OneofNestedMessage:
+ OneofNestedMessage = other.OneofNestedMessage.Clone();
+ break;
+ case OneofFieldOneofCase.OneofString:
+ OneofString = other.OneofString;
+ break;
+ case OneofFieldOneofCase.OneofBytes:
+ OneofBytes = other.OneofBytes;
+ break;
+ case OneofFieldOneofCase.OneofBool:
+ OneofBool = other.OneofBool;
+ break;
+ case OneofFieldOneofCase.OneofUint64:
+ OneofUint64 = other.OneofUint64;
+ break;
+ case OneofFieldOneofCase.OneofFloat:
+ OneofFloat = other.OneofFloat;
+ break;
+ case OneofFieldOneofCase.OneofDouble:
+ OneofDouble = other.OneofDouble;
+ break;
+ case OneofFieldOneofCase.OneofEnum:
+ OneofEnum = other.OneofEnum;
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestAllTypes Clone() {
+ return new TestAllTypes(this);
+ }
+
+ /// <summary>Field number for the "optional_int32" field.</summary>
+ public const int OptionalInt32FieldNumber = 1;
+ private int optionalInt32_;
+ /// <summary>
+ /// Singular
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int OptionalInt32 {
+ get { return optionalInt32_; }
+ set {
+ optionalInt32_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_int64" field.</summary>
+ public const int OptionalInt64FieldNumber = 2;
+ private long optionalInt64_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public long OptionalInt64 {
+ get { return optionalInt64_; }
+ set {
+ optionalInt64_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_uint32" field.</summary>
+ public const int OptionalUint32FieldNumber = 3;
+ private uint optionalUint32_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public uint OptionalUint32 {
+ get { return optionalUint32_; }
+ set {
+ optionalUint32_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_uint64" field.</summary>
+ public const int OptionalUint64FieldNumber = 4;
+ private ulong optionalUint64_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ulong OptionalUint64 {
+ get { return optionalUint64_; }
+ set {
+ optionalUint64_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_sint32" field.</summary>
+ public const int OptionalSint32FieldNumber = 5;
+ private int optionalSint32_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int OptionalSint32 {
+ get { return optionalSint32_; }
+ set {
+ optionalSint32_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_sint64" field.</summary>
+ public const int OptionalSint64FieldNumber = 6;
+ private long optionalSint64_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public long OptionalSint64 {
+ get { return optionalSint64_; }
+ set {
+ optionalSint64_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_fixed32" field.</summary>
+ public const int OptionalFixed32FieldNumber = 7;
+ private uint optionalFixed32_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public uint OptionalFixed32 {
+ get { return optionalFixed32_; }
+ set {
+ optionalFixed32_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_fixed64" field.</summary>
+ public const int OptionalFixed64FieldNumber = 8;
+ private ulong optionalFixed64_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ulong OptionalFixed64 {
+ get { return optionalFixed64_; }
+ set {
+ optionalFixed64_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_sfixed32" field.</summary>
+ public const int OptionalSfixed32FieldNumber = 9;
+ private int optionalSfixed32_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int OptionalSfixed32 {
+ get { return optionalSfixed32_; }
+ set {
+ optionalSfixed32_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_sfixed64" field.</summary>
+ public const int OptionalSfixed64FieldNumber = 10;
+ private long optionalSfixed64_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public long OptionalSfixed64 {
+ get { return optionalSfixed64_; }
+ set {
+ optionalSfixed64_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_float" field.</summary>
+ public const int OptionalFloatFieldNumber = 11;
+ private float optionalFloat_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public float OptionalFloat {
+ get { return optionalFloat_; }
+ set {
+ optionalFloat_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_double" field.</summary>
+ public const int OptionalDoubleFieldNumber = 12;
+ private double optionalDouble_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public double OptionalDouble {
+ get { return optionalDouble_; }
+ set {
+ optionalDouble_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_bool" field.</summary>
+ public const int OptionalBoolFieldNumber = 13;
+ private bool optionalBool_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool OptionalBool {
+ get { return optionalBool_; }
+ set {
+ optionalBool_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_string" field.</summary>
+ public const int OptionalStringFieldNumber = 14;
+ private string optionalString_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string OptionalString {
+ get { return optionalString_; }
+ set {
+ optionalString_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "optional_bytes" field.</summary>
+ public const int OptionalBytesFieldNumber = 15;
+ private pb::ByteString optionalBytes_ = pb::ByteString.Empty;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pb::ByteString OptionalBytes {
+ get { return optionalBytes_; }
+ set {
+ optionalBytes_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "optional_nested_message" field.</summary>
+ public const int OptionalNestedMessageFieldNumber = 18;
+ private global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage optionalNestedMessage_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage OptionalNestedMessage {
+ get { return optionalNestedMessage_; }
+ set {
+ optionalNestedMessage_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_foreign_message" field.</summary>
+ public const int OptionalForeignMessageFieldNumber = 19;
+ private global::ProtobufTestMessages.Proto3.ForeignMessage optionalForeignMessage_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::ProtobufTestMessages.Proto3.ForeignMessage OptionalForeignMessage {
+ get { return optionalForeignMessage_; }
+ set {
+ optionalForeignMessage_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_nested_enum" field.</summary>
+ public const int OptionalNestedEnumFieldNumber = 21;
+ private global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedEnum optionalNestedEnum_ = 0;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedEnum OptionalNestedEnum {
+ get { return optionalNestedEnum_; }
+ set {
+ optionalNestedEnum_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_foreign_enum" field.</summary>
+ public const int OptionalForeignEnumFieldNumber = 22;
+ private global::ProtobufTestMessages.Proto3.ForeignEnum optionalForeignEnum_ = 0;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::ProtobufTestMessages.Proto3.ForeignEnum OptionalForeignEnum {
+ get { return optionalForeignEnum_; }
+ set {
+ optionalForeignEnum_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_string_piece" field.</summary>
+ public const int OptionalStringPieceFieldNumber = 24;
+ private string optionalStringPiece_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string OptionalStringPiece {
+ get { return optionalStringPiece_; }
+ set {
+ optionalStringPiece_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "optional_cord" field.</summary>
+ public const int OptionalCordFieldNumber = 25;
+ private string optionalCord_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string OptionalCord {
+ get { return optionalCord_; }
+ set {
+ optionalCord_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "recursive_message" field.</summary>
+ public const int RecursiveMessageFieldNumber = 27;
+ private global::ProtobufTestMessages.Proto3.TestAllTypes recursiveMessage_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::ProtobufTestMessages.Proto3.TestAllTypes RecursiveMessage {
+ get { return recursiveMessage_; }
+ set {
+ recursiveMessage_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "repeated_int32" field.</summary>
+ public const int RepeatedInt32FieldNumber = 31;
+ private static readonly pb::FieldCodec<int> _repeated_repeatedInt32_codec
+ = pb::FieldCodec.ForInt32(250);
+ private readonly pbc::RepeatedField<int> repeatedInt32_ = new pbc::RepeatedField<int>();
+ /// <summary>
+ /// Repeated
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> RepeatedInt32 {
+ get { return repeatedInt32_; }
+ }
+
+ /// <summary>Field number for the "repeated_int64" field.</summary>
+ public const int RepeatedInt64FieldNumber = 32;
+ private static readonly pb::FieldCodec<long> _repeated_repeatedInt64_codec
+ = pb::FieldCodec.ForInt64(258);
+ private readonly pbc::RepeatedField<long> repeatedInt64_ = new pbc::RepeatedField<long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<long> RepeatedInt64 {
+ get { return repeatedInt64_; }
+ }
+
+ /// <summary>Field number for the "repeated_uint32" field.</summary>
+ public const int RepeatedUint32FieldNumber = 33;
+ private static readonly pb::FieldCodec<uint> _repeated_repeatedUint32_codec
+ = pb::FieldCodec.ForUInt32(266);
+ private readonly pbc::RepeatedField<uint> repeatedUint32_ = new pbc::RepeatedField<uint>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<uint> RepeatedUint32 {
+ get { return repeatedUint32_; }
+ }
+
+ /// <summary>Field number for the "repeated_uint64" field.</summary>
+ public const int RepeatedUint64FieldNumber = 34;
+ private static readonly pb::FieldCodec<ulong> _repeated_repeatedUint64_codec
+ = pb::FieldCodec.ForUInt64(274);
+ private readonly pbc::RepeatedField<ulong> repeatedUint64_ = new pbc::RepeatedField<ulong>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<ulong> RepeatedUint64 {
+ get { return repeatedUint64_; }
+ }
+
+ /// <summary>Field number for the "repeated_sint32" field.</summary>
+ public const int RepeatedSint32FieldNumber = 35;
+ private static readonly pb::FieldCodec<int> _repeated_repeatedSint32_codec
+ = pb::FieldCodec.ForSInt32(282);
+ private readonly pbc::RepeatedField<int> repeatedSint32_ = new pbc::RepeatedField<int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> RepeatedSint32 {
+ get { return repeatedSint32_; }
+ }
+
+ /// <summary>Field number for the "repeated_sint64" field.</summary>
+ public const int RepeatedSint64FieldNumber = 36;
+ private static readonly pb::FieldCodec<long> _repeated_repeatedSint64_codec
+ = pb::FieldCodec.ForSInt64(290);
+ private readonly pbc::RepeatedField<long> repeatedSint64_ = new pbc::RepeatedField<long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<long> RepeatedSint64 {
+ get { return repeatedSint64_; }
+ }
+
+ /// <summary>Field number for the "repeated_fixed32" field.</summary>
+ public const int RepeatedFixed32FieldNumber = 37;
+ private static readonly pb::FieldCodec<uint> _repeated_repeatedFixed32_codec
+ = pb::FieldCodec.ForFixed32(298);
+ private readonly pbc::RepeatedField<uint> repeatedFixed32_ = new pbc::RepeatedField<uint>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<uint> RepeatedFixed32 {
+ get { return repeatedFixed32_; }
+ }
+
+ /// <summary>Field number for the "repeated_fixed64" field.</summary>
+ public const int RepeatedFixed64FieldNumber = 38;
+ private static readonly pb::FieldCodec<ulong> _repeated_repeatedFixed64_codec
+ = pb::FieldCodec.ForFixed64(306);
+ private readonly pbc::RepeatedField<ulong> repeatedFixed64_ = new pbc::RepeatedField<ulong>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<ulong> RepeatedFixed64 {
+ get { return repeatedFixed64_; }
+ }
+
+ /// <summary>Field number for the "repeated_sfixed32" field.</summary>
+ public const int RepeatedSfixed32FieldNumber = 39;
+ private static readonly pb::FieldCodec<int> _repeated_repeatedSfixed32_codec
+ = pb::FieldCodec.ForSFixed32(314);
+ private readonly pbc::RepeatedField<int> repeatedSfixed32_ = new pbc::RepeatedField<int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> RepeatedSfixed32 {
+ get { return repeatedSfixed32_; }
+ }
+
+ /// <summary>Field number for the "repeated_sfixed64" field.</summary>
+ public const int RepeatedSfixed64FieldNumber = 40;
+ private static readonly pb::FieldCodec<long> _repeated_repeatedSfixed64_codec
+ = pb::FieldCodec.ForSFixed64(322);
+ private readonly pbc::RepeatedField<long> repeatedSfixed64_ = new pbc::RepeatedField<long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<long> RepeatedSfixed64 {
+ get { return repeatedSfixed64_; }
+ }
+
+ /// <summary>Field number for the "repeated_float" field.</summary>
+ public const int RepeatedFloatFieldNumber = 41;
+ private static readonly pb::FieldCodec<float> _repeated_repeatedFloat_codec
+ = pb::FieldCodec.ForFloat(330);
+ private readonly pbc::RepeatedField<float> repeatedFloat_ = new pbc::RepeatedField<float>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<float> RepeatedFloat {
+ get { return repeatedFloat_; }
+ }
+
+ /// <summary>Field number for the "repeated_double" field.</summary>
+ public const int RepeatedDoubleFieldNumber = 42;
+ private static readonly pb::FieldCodec<double> _repeated_repeatedDouble_codec
+ = pb::FieldCodec.ForDouble(338);
+ private readonly pbc::RepeatedField<double> repeatedDouble_ = new pbc::RepeatedField<double>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<double> RepeatedDouble {
+ get { return repeatedDouble_; }
+ }
+
+ /// <summary>Field number for the "repeated_bool" field.</summary>
+ public const int RepeatedBoolFieldNumber = 43;
+ private static readonly pb::FieldCodec<bool> _repeated_repeatedBool_codec
+ = pb::FieldCodec.ForBool(346);
+ private readonly pbc::RepeatedField<bool> repeatedBool_ = new pbc::RepeatedField<bool>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<bool> RepeatedBool {
+ get { return repeatedBool_; }
+ }
+
+ /// <summary>Field number for the "repeated_string" field.</summary>
+ public const int RepeatedStringFieldNumber = 44;
+ private static readonly pb::FieldCodec<string> _repeated_repeatedString_codec
+ = pb::FieldCodec.ForString(354);
+ private readonly pbc::RepeatedField<string> repeatedString_ = new pbc::RepeatedField<string>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<string> RepeatedString {
+ get { return repeatedString_; }
+ }
+
+ /// <summary>Field number for the "repeated_bytes" field.</summary>
+ public const int RepeatedBytesFieldNumber = 45;
+ private static readonly pb::FieldCodec<pb::ByteString> _repeated_repeatedBytes_codec
+ = pb::FieldCodec.ForBytes(362);
+ private readonly pbc::RepeatedField<pb::ByteString> repeatedBytes_ = new pbc::RepeatedField<pb::ByteString>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<pb::ByteString> RepeatedBytes {
+ get { return repeatedBytes_; }
+ }
+
+ /// <summary>Field number for the "repeated_nested_message" field.</summary>
+ public const int RepeatedNestedMessageFieldNumber = 48;
+ private static readonly pb::FieldCodec<global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage> _repeated_repeatedNestedMessage_codec
+ = pb::FieldCodec.ForMessage(386, global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage.Parser);
+ private readonly pbc::RepeatedField<global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage> repeatedNestedMessage_ = new pbc::RepeatedField<global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage> RepeatedNestedMessage {
+ get { return repeatedNestedMessage_; }
+ }
+
+ /// <summary>Field number for the "repeated_foreign_message" field.</summary>
+ public const int RepeatedForeignMessageFieldNumber = 49;
+ private static readonly pb::FieldCodec<global::ProtobufTestMessages.Proto3.ForeignMessage> _repeated_repeatedForeignMessage_codec
+ = pb::FieldCodec.ForMessage(394, global::ProtobufTestMessages.Proto3.ForeignMessage.Parser);
+ private readonly pbc::RepeatedField<global::ProtobufTestMessages.Proto3.ForeignMessage> repeatedForeignMessage_ = new pbc::RepeatedField<global::ProtobufTestMessages.Proto3.ForeignMessage>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::ProtobufTestMessages.Proto3.ForeignMessage> RepeatedForeignMessage {
+ get { return repeatedForeignMessage_; }
+ }
+
+ /// <summary>Field number for the "repeated_nested_enum" field.</summary>
+ public const int RepeatedNestedEnumFieldNumber = 51;
+ private static readonly pb::FieldCodec<global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedEnum> _repeated_repeatedNestedEnum_codec
+ = pb::FieldCodec.ForEnum(410, x => (int) x, x => (global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedEnum) x);
+ private readonly pbc::RepeatedField<global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedEnum> repeatedNestedEnum_ = new pbc::RepeatedField<global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedEnum>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedEnum> RepeatedNestedEnum {
+ get { return repeatedNestedEnum_; }
+ }
+
+ /// <summary>Field number for the "repeated_foreign_enum" field.</summary>
+ public const int RepeatedForeignEnumFieldNumber = 52;
+ private static readonly pb::FieldCodec<global::ProtobufTestMessages.Proto3.ForeignEnum> _repeated_repeatedForeignEnum_codec
+ = pb::FieldCodec.ForEnum(418, x => (int) x, x => (global::ProtobufTestMessages.Proto3.ForeignEnum) x);
+ private readonly pbc::RepeatedField<global::ProtobufTestMessages.Proto3.ForeignEnum> repeatedForeignEnum_ = new pbc::RepeatedField<global::ProtobufTestMessages.Proto3.ForeignEnum>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::ProtobufTestMessages.Proto3.ForeignEnum> RepeatedForeignEnum {
+ get { return repeatedForeignEnum_; }
+ }
+
+ /// <summary>Field number for the "repeated_string_piece" field.</summary>
+ public const int RepeatedStringPieceFieldNumber = 54;
+ private static readonly pb::FieldCodec<string> _repeated_repeatedStringPiece_codec
+ = pb::FieldCodec.ForString(434);
+ private readonly pbc::RepeatedField<string> repeatedStringPiece_ = new pbc::RepeatedField<string>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<string> RepeatedStringPiece {
+ get { return repeatedStringPiece_; }
+ }
+
+ /// <summary>Field number for the "repeated_cord" field.</summary>
+ public const int RepeatedCordFieldNumber = 55;
+ private static readonly pb::FieldCodec<string> _repeated_repeatedCord_codec
+ = pb::FieldCodec.ForString(442);
+ private readonly pbc::RepeatedField<string> repeatedCord_ = new pbc::RepeatedField<string>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<string> RepeatedCord {
+ get { return repeatedCord_; }
+ }
+
+ /// <summary>Field number for the "map_int32_int32" field.</summary>
+ public const int MapInt32Int32FieldNumber = 56;
+ private static readonly pbc::MapField<int, int>.Codec _map_mapInt32Int32_codec
+ = new pbc::MapField<int, int>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForInt32(16), 450);
+ private readonly pbc::MapField<int, int> mapInt32Int32_ = new pbc::MapField<int, int>();
+ /// <summary>
+ /// Map
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, int> MapInt32Int32 {
+ get { return mapInt32Int32_; }
+ }
+
+ /// <summary>Field number for the "map_int64_int64" field.</summary>
+ public const int MapInt64Int64FieldNumber = 57;
+ private static readonly pbc::MapField<long, long>.Codec _map_mapInt64Int64_codec
+ = new pbc::MapField<long, long>.Codec(pb::FieldCodec.ForInt64(8), pb::FieldCodec.ForInt64(16), 458);
+ private readonly pbc::MapField<long, long> mapInt64Int64_ = new pbc::MapField<long, long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<long, long> MapInt64Int64 {
+ get { return mapInt64Int64_; }
+ }
+
+ /// <summary>Field number for the "map_uint32_uint32" field.</summary>
+ public const int MapUint32Uint32FieldNumber = 58;
+ private static readonly pbc::MapField<uint, uint>.Codec _map_mapUint32Uint32_codec
+ = new pbc::MapField<uint, uint>.Codec(pb::FieldCodec.ForUInt32(8), pb::FieldCodec.ForUInt32(16), 466);
+ private readonly pbc::MapField<uint, uint> mapUint32Uint32_ = new pbc::MapField<uint, uint>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<uint, uint> MapUint32Uint32 {
+ get { return mapUint32Uint32_; }
+ }
+
+ /// <summary>Field number for the "map_uint64_uint64" field.</summary>
+ public const int MapUint64Uint64FieldNumber = 59;
+ private static readonly pbc::MapField<ulong, ulong>.Codec _map_mapUint64Uint64_codec
+ = new pbc::MapField<ulong, ulong>.Codec(pb::FieldCodec.ForUInt64(8), pb::FieldCodec.ForUInt64(16), 474);
+ private readonly pbc::MapField<ulong, ulong> mapUint64Uint64_ = new pbc::MapField<ulong, ulong>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<ulong, ulong> MapUint64Uint64 {
+ get { return mapUint64Uint64_; }
+ }
+
+ /// <summary>Field number for the "map_sint32_sint32" field.</summary>
+ public const int MapSint32Sint32FieldNumber = 60;
+ private static readonly pbc::MapField<int, int>.Codec _map_mapSint32Sint32_codec
+ = new pbc::MapField<int, int>.Codec(pb::FieldCodec.ForSInt32(8), pb::FieldCodec.ForSInt32(16), 482);
+ private readonly pbc::MapField<int, int> mapSint32Sint32_ = new pbc::MapField<int, int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, int> MapSint32Sint32 {
+ get { return mapSint32Sint32_; }
+ }
+
+ /// <summary>Field number for the "map_sint64_sint64" field.</summary>
+ public const int MapSint64Sint64FieldNumber = 61;
+ private static readonly pbc::MapField<long, long>.Codec _map_mapSint64Sint64_codec
+ = new pbc::MapField<long, long>.Codec(pb::FieldCodec.ForSInt64(8), pb::FieldCodec.ForSInt64(16), 490);
+ private readonly pbc::MapField<long, long> mapSint64Sint64_ = new pbc::MapField<long, long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<long, long> MapSint64Sint64 {
+ get { return mapSint64Sint64_; }
+ }
+
+ /// <summary>Field number for the "map_fixed32_fixed32" field.</summary>
+ public const int MapFixed32Fixed32FieldNumber = 62;
+ private static readonly pbc::MapField<uint, uint>.Codec _map_mapFixed32Fixed32_codec
+ = new pbc::MapField<uint, uint>.Codec(pb::FieldCodec.ForFixed32(13), pb::FieldCodec.ForFixed32(21), 498);
+ private readonly pbc::MapField<uint, uint> mapFixed32Fixed32_ = new pbc::MapField<uint, uint>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<uint, uint> MapFixed32Fixed32 {
+ get { return mapFixed32Fixed32_; }
+ }
+
+ /// <summary>Field number for the "map_fixed64_fixed64" field.</summary>
+ public const int MapFixed64Fixed64FieldNumber = 63;
+ private static readonly pbc::MapField<ulong, ulong>.Codec _map_mapFixed64Fixed64_codec
+ = new pbc::MapField<ulong, ulong>.Codec(pb::FieldCodec.ForFixed64(9), pb::FieldCodec.ForFixed64(17), 506);
+ private readonly pbc::MapField<ulong, ulong> mapFixed64Fixed64_ = new pbc::MapField<ulong, ulong>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<ulong, ulong> MapFixed64Fixed64 {
+ get { return mapFixed64Fixed64_; }
+ }
+
+ /// <summary>Field number for the "map_sfixed32_sfixed32" field.</summary>
+ public const int MapSfixed32Sfixed32FieldNumber = 64;
+ private static readonly pbc::MapField<int, int>.Codec _map_mapSfixed32Sfixed32_codec
+ = new pbc::MapField<int, int>.Codec(pb::FieldCodec.ForSFixed32(13), pb::FieldCodec.ForSFixed32(21), 514);
+ private readonly pbc::MapField<int, int> mapSfixed32Sfixed32_ = new pbc::MapField<int, int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, int> MapSfixed32Sfixed32 {
+ get { return mapSfixed32Sfixed32_; }
+ }
+
+ /// <summary>Field number for the "map_sfixed64_sfixed64" field.</summary>
+ public const int MapSfixed64Sfixed64FieldNumber = 65;
+ private static readonly pbc::MapField<long, long>.Codec _map_mapSfixed64Sfixed64_codec
+ = new pbc::MapField<long, long>.Codec(pb::FieldCodec.ForSFixed64(9), pb::FieldCodec.ForSFixed64(17), 522);
+ private readonly pbc::MapField<long, long> mapSfixed64Sfixed64_ = new pbc::MapField<long, long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<long, long> MapSfixed64Sfixed64 {
+ get { return mapSfixed64Sfixed64_; }
+ }
+
+ /// <summary>Field number for the "map_int32_float" field.</summary>
+ public const int MapInt32FloatFieldNumber = 66;
+ private static readonly pbc::MapField<int, float>.Codec _map_mapInt32Float_codec
+ = new pbc::MapField<int, float>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForFloat(21), 530);
+ private readonly pbc::MapField<int, float> mapInt32Float_ = new pbc::MapField<int, float>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, float> MapInt32Float {
+ get { return mapInt32Float_; }
+ }
+
+ /// <summary>Field number for the "map_int32_double" field.</summary>
+ public const int MapInt32DoubleFieldNumber = 67;
+ private static readonly pbc::MapField<int, double>.Codec _map_mapInt32Double_codec
+ = new pbc::MapField<int, double>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForDouble(17), 538);
+ private readonly pbc::MapField<int, double> mapInt32Double_ = new pbc::MapField<int, double>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, double> MapInt32Double {
+ get { return mapInt32Double_; }
+ }
+
+ /// <summary>Field number for the "map_bool_bool" field.</summary>
+ public const int MapBoolBoolFieldNumber = 68;
+ private static readonly pbc::MapField<bool, bool>.Codec _map_mapBoolBool_codec
+ = new pbc::MapField<bool, bool>.Codec(pb::FieldCodec.ForBool(8), pb::FieldCodec.ForBool(16), 546);
+ private readonly pbc::MapField<bool, bool> mapBoolBool_ = new pbc::MapField<bool, bool>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<bool, bool> MapBoolBool {
+ get { return mapBoolBool_; }
+ }
+
+ /// <summary>Field number for the "map_string_string" field.</summary>
+ public const int MapStringStringFieldNumber = 69;
+ private static readonly pbc::MapField<string, string>.Codec _map_mapStringString_codec
+ = new pbc::MapField<string, string>.Codec(pb::FieldCodec.ForString(10), pb::FieldCodec.ForString(18), 554);
+ private readonly pbc::MapField<string, string> mapStringString_ = new pbc::MapField<string, string>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<string, string> MapStringString {
+ get { return mapStringString_; }
+ }
+
+ /// <summary>Field number for the "map_string_bytes" field.</summary>
+ public const int MapStringBytesFieldNumber = 70;
+ private static readonly pbc::MapField<string, pb::ByteString>.Codec _map_mapStringBytes_codec
+ = new pbc::MapField<string, pb::ByteString>.Codec(pb::FieldCodec.ForString(10), pb::FieldCodec.ForBytes(18), 562);
+ private readonly pbc::MapField<string, pb::ByteString> mapStringBytes_ = new pbc::MapField<string, pb::ByteString>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<string, pb::ByteString> MapStringBytes {
+ get { return mapStringBytes_; }
+ }
+
+ /// <summary>Field number for the "map_string_nested_message" field.</summary>
+ public const int MapStringNestedMessageFieldNumber = 71;
+ private static readonly pbc::MapField<string, global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage>.Codec _map_mapStringNestedMessage_codec
+ = new pbc::MapField<string, global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage>.Codec(pb::FieldCodec.ForString(10), pb::FieldCodec.ForMessage(18, global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage.Parser), 570);
+ private readonly pbc::MapField<string, global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage> mapStringNestedMessage_ = new pbc::MapField<string, global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<string, global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage> MapStringNestedMessage {
+ get { return mapStringNestedMessage_; }
+ }
+
+ /// <summary>Field number for the "map_string_foreign_message" field.</summary>
+ public const int MapStringForeignMessageFieldNumber = 72;
+ private static readonly pbc::MapField<string, global::ProtobufTestMessages.Proto3.ForeignMessage>.Codec _map_mapStringForeignMessage_codec
+ = new pbc::MapField<string, global::ProtobufTestMessages.Proto3.ForeignMessage>.Codec(pb::FieldCodec.ForString(10), pb::FieldCodec.ForMessage(18, global::ProtobufTestMessages.Proto3.ForeignMessage.Parser), 578);
+ private readonly pbc::MapField<string, global::ProtobufTestMessages.Proto3.ForeignMessage> mapStringForeignMessage_ = new pbc::MapField<string, global::ProtobufTestMessages.Proto3.ForeignMessage>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<string, global::ProtobufTestMessages.Proto3.ForeignMessage> MapStringForeignMessage {
+ get { return mapStringForeignMessage_; }
+ }
+
+ /// <summary>Field number for the "map_string_nested_enum" field.</summary>
+ public const int MapStringNestedEnumFieldNumber = 73;
+ private static readonly pbc::MapField<string, global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedEnum>.Codec _map_mapStringNestedEnum_codec
+ = new pbc::MapField<string, global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedEnum>.Codec(pb::FieldCodec.ForString(10), pb::FieldCodec.ForEnum(16, x => (int) x, x => (global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedEnum) x), 586);
+ private readonly pbc::MapField<string, global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedEnum> mapStringNestedEnum_ = new pbc::MapField<string, global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedEnum>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<string, global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedEnum> MapStringNestedEnum {
+ get { return mapStringNestedEnum_; }
+ }
+
+ /// <summary>Field number for the "map_string_foreign_enum" field.</summary>
+ public const int MapStringForeignEnumFieldNumber = 74;
+ private static readonly pbc::MapField<string, global::ProtobufTestMessages.Proto3.ForeignEnum>.Codec _map_mapStringForeignEnum_codec
+ = new pbc::MapField<string, global::ProtobufTestMessages.Proto3.ForeignEnum>.Codec(pb::FieldCodec.ForString(10), pb::FieldCodec.ForEnum(16, x => (int) x, x => (global::ProtobufTestMessages.Proto3.ForeignEnum) x), 594);
+ private readonly pbc::MapField<string, global::ProtobufTestMessages.Proto3.ForeignEnum> mapStringForeignEnum_ = new pbc::MapField<string, global::ProtobufTestMessages.Proto3.ForeignEnum>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<string, global::ProtobufTestMessages.Proto3.ForeignEnum> MapStringForeignEnum {
+ get { return mapStringForeignEnum_; }
+ }
+
+ /// <summary>Field number for the "oneof_uint32" field.</summary>
+ public const int OneofUint32FieldNumber = 111;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public uint OneofUint32 {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.OneofUint32 ? (uint) oneofField_ : 0; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = OneofFieldOneofCase.OneofUint32;
+ }
+ }
+
+ /// <summary>Field number for the "oneof_nested_message" field.</summary>
+ public const int OneofNestedMessageFieldNumber = 112;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage OneofNestedMessage {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage ? (global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage) oneofField_ : null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.OneofNestedMessage;
+ }
+ }
+
+ /// <summary>Field number for the "oneof_string" field.</summary>
+ public const int OneofStringFieldNumber = 113;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string OneofString {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.OneofString ? (string) oneofField_ : ""; }
+ set {
+ oneofField_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ oneofFieldCase_ = OneofFieldOneofCase.OneofString;
+ }
+ }
+
+ /// <summary>Field number for the "oneof_bytes" field.</summary>
+ public const int OneofBytesFieldNumber = 114;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pb::ByteString OneofBytes {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.OneofBytes ? (pb::ByteString) oneofField_ : pb::ByteString.Empty; }
+ set {
+ oneofField_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ oneofFieldCase_ = OneofFieldOneofCase.OneofBytes;
+ }
+ }
+
+ /// <summary>Field number for the "oneof_bool" field.</summary>
+ public const int OneofBoolFieldNumber = 115;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool OneofBool {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.OneofBool ? (bool) oneofField_ : false; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = OneofFieldOneofCase.OneofBool;
+ }
+ }
+
+ /// <summary>Field number for the "oneof_uint64" field.</summary>
+ public const int OneofUint64FieldNumber = 116;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ulong OneofUint64 {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.OneofUint64 ? (ulong) oneofField_ : 0UL; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = OneofFieldOneofCase.OneofUint64;
+ }
+ }
+
+ /// <summary>Field number for the "oneof_float" field.</summary>
+ public const int OneofFloatFieldNumber = 117;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public float OneofFloat {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.OneofFloat ? (float) oneofField_ : 0F; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = OneofFieldOneofCase.OneofFloat;
+ }
+ }
+
+ /// <summary>Field number for the "oneof_double" field.</summary>
+ public const int OneofDoubleFieldNumber = 118;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public double OneofDouble {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.OneofDouble ? (double) oneofField_ : 0D; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = OneofFieldOneofCase.OneofDouble;
+ }
+ }
+
+ /// <summary>Field number for the "oneof_enum" field.</summary>
+ public const int OneofEnumFieldNumber = 119;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedEnum OneofEnum {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.OneofEnum ? (global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedEnum) oneofField_ : 0; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = OneofFieldOneofCase.OneofEnum;
+ }
+ }
+
+ /// <summary>Field number for the "optional_bool_wrapper" field.</summary>
+ public const int OptionalBoolWrapperFieldNumber = 201;
+ private static readonly pb::FieldCodec<bool?> _single_optionalBoolWrapper_codec = pb::FieldCodec.ForStructWrapper<bool>(1610);
+ private bool? optionalBoolWrapper_;
+ /// <summary>
+ /// Well-known types
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool? OptionalBoolWrapper {
+ get { return optionalBoolWrapper_; }
+ set {
+ optionalBoolWrapper_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_int32_wrapper" field.</summary>
+ public const int OptionalInt32WrapperFieldNumber = 202;
+ private static readonly pb::FieldCodec<int?> _single_optionalInt32Wrapper_codec = pb::FieldCodec.ForStructWrapper<int>(1618);
+ private int? optionalInt32Wrapper_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int? OptionalInt32Wrapper {
+ get { return optionalInt32Wrapper_; }
+ set {
+ optionalInt32Wrapper_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_int64_wrapper" field.</summary>
+ public const int OptionalInt64WrapperFieldNumber = 203;
+ private static readonly pb::FieldCodec<long?> _single_optionalInt64Wrapper_codec = pb::FieldCodec.ForStructWrapper<long>(1626);
+ private long? optionalInt64Wrapper_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public long? OptionalInt64Wrapper {
+ get { return optionalInt64Wrapper_; }
+ set {
+ optionalInt64Wrapper_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_uint32_wrapper" field.</summary>
+ public const int OptionalUint32WrapperFieldNumber = 204;
+ private static readonly pb::FieldCodec<uint?> _single_optionalUint32Wrapper_codec = pb::FieldCodec.ForStructWrapper<uint>(1634);
+ private uint? optionalUint32Wrapper_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public uint? OptionalUint32Wrapper {
+ get { return optionalUint32Wrapper_; }
+ set {
+ optionalUint32Wrapper_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_uint64_wrapper" field.</summary>
+ public const int OptionalUint64WrapperFieldNumber = 205;
+ private static readonly pb::FieldCodec<ulong?> _single_optionalUint64Wrapper_codec = pb::FieldCodec.ForStructWrapper<ulong>(1642);
+ private ulong? optionalUint64Wrapper_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ulong? OptionalUint64Wrapper {
+ get { return optionalUint64Wrapper_; }
+ set {
+ optionalUint64Wrapper_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_float_wrapper" field.</summary>
+ public const int OptionalFloatWrapperFieldNumber = 206;
+ private static readonly pb::FieldCodec<float?> _single_optionalFloatWrapper_codec = pb::FieldCodec.ForStructWrapper<float>(1650);
+ private float? optionalFloatWrapper_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public float? OptionalFloatWrapper {
+ get { return optionalFloatWrapper_; }
+ set {
+ optionalFloatWrapper_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_double_wrapper" field.</summary>
+ public const int OptionalDoubleWrapperFieldNumber = 207;
+ private static readonly pb::FieldCodec<double?> _single_optionalDoubleWrapper_codec = pb::FieldCodec.ForStructWrapper<double>(1658);
+ private double? optionalDoubleWrapper_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public double? OptionalDoubleWrapper {
+ get { return optionalDoubleWrapper_; }
+ set {
+ optionalDoubleWrapper_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_string_wrapper" field.</summary>
+ public const int OptionalStringWrapperFieldNumber = 208;
+ private static readonly pb::FieldCodec<string> _single_optionalStringWrapper_codec = pb::FieldCodec.ForClassWrapper<string>(1666);
+ private string optionalStringWrapper_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string OptionalStringWrapper {
+ get { return optionalStringWrapper_; }
+ set {
+ optionalStringWrapper_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_bytes_wrapper" field.</summary>
+ public const int OptionalBytesWrapperFieldNumber = 209;
+ private static readonly pb::FieldCodec<pb::ByteString> _single_optionalBytesWrapper_codec = pb::FieldCodec.ForClassWrapper<pb::ByteString>(1674);
+ private pb::ByteString optionalBytesWrapper_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pb::ByteString OptionalBytesWrapper {
+ get { return optionalBytesWrapper_; }
+ set {
+ optionalBytesWrapper_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "repeated_bool_wrapper" field.</summary>
+ public const int RepeatedBoolWrapperFieldNumber = 211;
+ private static readonly pb::FieldCodec<bool?> _repeated_repeatedBoolWrapper_codec
+ = pb::FieldCodec.ForStructWrapper<bool>(1690);
+ private readonly pbc::RepeatedField<bool?> repeatedBoolWrapper_ = new pbc::RepeatedField<bool?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<bool?> RepeatedBoolWrapper {
+ get { return repeatedBoolWrapper_; }
+ }
+
+ /// <summary>Field number for the "repeated_int32_wrapper" field.</summary>
+ public const int RepeatedInt32WrapperFieldNumber = 212;
+ private static readonly pb::FieldCodec<int?> _repeated_repeatedInt32Wrapper_codec
+ = pb::FieldCodec.ForStructWrapper<int>(1698);
+ private readonly pbc::RepeatedField<int?> repeatedInt32Wrapper_ = new pbc::RepeatedField<int?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int?> RepeatedInt32Wrapper {
+ get { return repeatedInt32Wrapper_; }
+ }
+
+ /// <summary>Field number for the "repeated_int64_wrapper" field.</summary>
+ public const int RepeatedInt64WrapperFieldNumber = 213;
+ private static readonly pb::FieldCodec<long?> _repeated_repeatedInt64Wrapper_codec
+ = pb::FieldCodec.ForStructWrapper<long>(1706);
+ private readonly pbc::RepeatedField<long?> repeatedInt64Wrapper_ = new pbc::RepeatedField<long?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<long?> RepeatedInt64Wrapper {
+ get { return repeatedInt64Wrapper_; }
+ }
+
+ /// <summary>Field number for the "repeated_uint32_wrapper" field.</summary>
+ public const int RepeatedUint32WrapperFieldNumber = 214;
+ private static readonly pb::FieldCodec<uint?> _repeated_repeatedUint32Wrapper_codec
+ = pb::FieldCodec.ForStructWrapper<uint>(1714);
+ private readonly pbc::RepeatedField<uint?> repeatedUint32Wrapper_ = new pbc::RepeatedField<uint?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<uint?> RepeatedUint32Wrapper {
+ get { return repeatedUint32Wrapper_; }
+ }
+
+ /// <summary>Field number for the "repeated_uint64_wrapper" field.</summary>
+ public const int RepeatedUint64WrapperFieldNumber = 215;
+ private static readonly pb::FieldCodec<ulong?> _repeated_repeatedUint64Wrapper_codec
+ = pb::FieldCodec.ForStructWrapper<ulong>(1722);
+ private readonly pbc::RepeatedField<ulong?> repeatedUint64Wrapper_ = new pbc::RepeatedField<ulong?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<ulong?> RepeatedUint64Wrapper {
+ get { return repeatedUint64Wrapper_; }
+ }
+
+ /// <summary>Field number for the "repeated_float_wrapper" field.</summary>
+ public const int RepeatedFloatWrapperFieldNumber = 216;
+ private static readonly pb::FieldCodec<float?> _repeated_repeatedFloatWrapper_codec
+ = pb::FieldCodec.ForStructWrapper<float>(1730);
+ private readonly pbc::RepeatedField<float?> repeatedFloatWrapper_ = new pbc::RepeatedField<float?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<float?> RepeatedFloatWrapper {
+ get { return repeatedFloatWrapper_; }
+ }
+
+ /// <summary>Field number for the "repeated_double_wrapper" field.</summary>
+ public const int RepeatedDoubleWrapperFieldNumber = 217;
+ private static readonly pb::FieldCodec<double?> _repeated_repeatedDoubleWrapper_codec
+ = pb::FieldCodec.ForStructWrapper<double>(1738);
+ private readonly pbc::RepeatedField<double?> repeatedDoubleWrapper_ = new pbc::RepeatedField<double?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<double?> RepeatedDoubleWrapper {
+ get { return repeatedDoubleWrapper_; }
+ }
+
+ /// <summary>Field number for the "repeated_string_wrapper" field.</summary>
+ public const int RepeatedStringWrapperFieldNumber = 218;
+ private static readonly pb::FieldCodec<string> _repeated_repeatedStringWrapper_codec
+ = pb::FieldCodec.ForClassWrapper<string>(1746);
+ private readonly pbc::RepeatedField<string> repeatedStringWrapper_ = new pbc::RepeatedField<string>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<string> RepeatedStringWrapper {
+ get { return repeatedStringWrapper_; }
+ }
+
+ /// <summary>Field number for the "repeated_bytes_wrapper" field.</summary>
+ public const int RepeatedBytesWrapperFieldNumber = 219;
+ private static readonly pb::FieldCodec<pb::ByteString> _repeated_repeatedBytesWrapper_codec
+ = pb::FieldCodec.ForClassWrapper<pb::ByteString>(1754);
+ private readonly pbc::RepeatedField<pb::ByteString> repeatedBytesWrapper_ = new pbc::RepeatedField<pb::ByteString>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<pb::ByteString> RepeatedBytesWrapper {
+ get { return repeatedBytesWrapper_; }
+ }
+
+ /// <summary>Field number for the "optional_duration" field.</summary>
+ public const int OptionalDurationFieldNumber = 301;
+ private global::Google.Protobuf.WellKnownTypes.Duration optionalDuration_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Duration OptionalDuration {
+ get { return optionalDuration_; }
+ set {
+ optionalDuration_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_timestamp" field.</summary>
+ public const int OptionalTimestampFieldNumber = 302;
+ private global::Google.Protobuf.WellKnownTypes.Timestamp optionalTimestamp_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Timestamp OptionalTimestamp {
+ get { return optionalTimestamp_; }
+ set {
+ optionalTimestamp_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_field_mask" field.</summary>
+ public const int OptionalFieldMaskFieldNumber = 303;
+ private global::Google.Protobuf.WellKnownTypes.FieldMask optionalFieldMask_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.FieldMask OptionalFieldMask {
+ get { return optionalFieldMask_; }
+ set {
+ optionalFieldMask_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_struct" field.</summary>
+ public const int OptionalStructFieldNumber = 304;
+ private global::Google.Protobuf.WellKnownTypes.Struct optionalStruct_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Struct OptionalStruct {
+ get { return optionalStruct_; }
+ set {
+ optionalStruct_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_any" field.</summary>
+ public const int OptionalAnyFieldNumber = 305;
+ private global::Google.Protobuf.WellKnownTypes.Any optionalAny_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Any OptionalAny {
+ get { return optionalAny_; }
+ set {
+ optionalAny_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_value" field.</summary>
+ public const int OptionalValueFieldNumber = 306;
+ private global::Google.Protobuf.WellKnownTypes.Value optionalValue_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Value OptionalValue {
+ get { return optionalValue_; }
+ set {
+ optionalValue_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "repeated_duration" field.</summary>
+ public const int RepeatedDurationFieldNumber = 311;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Duration> _repeated_repeatedDuration_codec
+ = pb::FieldCodec.ForMessage(2490, global::Google.Protobuf.WellKnownTypes.Duration.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Duration> repeatedDuration_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Duration>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Duration> RepeatedDuration {
+ get { return repeatedDuration_; }
+ }
+
+ /// <summary>Field number for the "repeated_timestamp" field.</summary>
+ public const int RepeatedTimestampFieldNumber = 312;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Timestamp> _repeated_repeatedTimestamp_codec
+ = pb::FieldCodec.ForMessage(2498, global::Google.Protobuf.WellKnownTypes.Timestamp.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Timestamp> repeatedTimestamp_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Timestamp>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Timestamp> RepeatedTimestamp {
+ get { return repeatedTimestamp_; }
+ }
+
+ /// <summary>Field number for the "repeated_fieldmask" field.</summary>
+ public const int RepeatedFieldmaskFieldNumber = 313;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.FieldMask> _repeated_repeatedFieldmask_codec
+ = pb::FieldCodec.ForMessage(2506, global::Google.Protobuf.WellKnownTypes.FieldMask.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.FieldMask> repeatedFieldmask_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.FieldMask>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.FieldMask> RepeatedFieldmask {
+ get { return repeatedFieldmask_; }
+ }
+
+ /// <summary>Field number for the "repeated_struct" field.</summary>
+ public const int RepeatedStructFieldNumber = 324;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Struct> _repeated_repeatedStruct_codec
+ = pb::FieldCodec.ForMessage(2594, global::Google.Protobuf.WellKnownTypes.Struct.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Struct> repeatedStruct_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Struct>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Struct> RepeatedStruct {
+ get { return repeatedStruct_; }
+ }
+
+ /// <summary>Field number for the "repeated_any" field.</summary>
+ public const int RepeatedAnyFieldNumber = 315;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Any> _repeated_repeatedAny_codec
+ = pb::FieldCodec.ForMessage(2522, global::Google.Protobuf.WellKnownTypes.Any.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Any> repeatedAny_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Any>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Any> RepeatedAny {
+ get { return repeatedAny_; }
+ }
+
+ /// <summary>Field number for the "repeated_value" field.</summary>
+ public const int RepeatedValueFieldNumber = 316;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Value> _repeated_repeatedValue_codec
+ = pb::FieldCodec.ForMessage(2530, global::Google.Protobuf.WellKnownTypes.Value.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Value> repeatedValue_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Value>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Value> RepeatedValue {
+ get { return repeatedValue_; }
+ }
+
+ /// <summary>Field number for the "fieldname1" field.</summary>
+ public const int Fieldname1FieldNumber = 401;
+ private int fieldname1_;
+ /// <summary>
+ /// Test field-name-to-JSON-name convention.
+ /// (protobuf says names can be any valid C/C++ identifier.)
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Fieldname1 {
+ get { return fieldname1_; }
+ set {
+ fieldname1_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "field_name2" field.</summary>
+ public const int FieldName2FieldNumber = 402;
+ private int fieldName2_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int FieldName2 {
+ get { return fieldName2_; }
+ set {
+ fieldName2_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "_field_name3" field.</summary>
+ public const int FieldName3FieldNumber = 403;
+ private int FieldName3_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int FieldName3 {
+ get { return FieldName3_; }
+ set {
+ FieldName3_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "field__name4_" field.</summary>
+ public const int FieldName4FieldNumber = 404;
+ private int fieldName4_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int FieldName4 {
+ get { return fieldName4_; }
+ set {
+ fieldName4_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "field0name5" field.</summary>
+ public const int Field0Name5FieldNumber = 405;
+ private int field0Name5_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Field0Name5 {
+ get { return field0Name5_; }
+ set {
+ field0Name5_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "field_0_name6" field.</summary>
+ public const int Field0Name6FieldNumber = 406;
+ private int field0Name6_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Field0Name6 {
+ get { return field0Name6_; }
+ set {
+ field0Name6_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "fieldName7" field.</summary>
+ public const int FieldName7FieldNumber = 407;
+ private int fieldName7_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int FieldName7 {
+ get { return fieldName7_; }
+ set {
+ fieldName7_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "FieldName8" field.</summary>
+ public const int FieldName8FieldNumber = 408;
+ private int fieldName8_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int FieldName8 {
+ get { return fieldName8_; }
+ set {
+ fieldName8_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "field_Name9" field.</summary>
+ public const int FieldName9FieldNumber = 409;
+ private int fieldName9_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int FieldName9 {
+ get { return fieldName9_; }
+ set {
+ fieldName9_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "Field_Name10" field.</summary>
+ public const int FieldName10FieldNumber = 410;
+ private int fieldName10_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int FieldName10 {
+ get { return fieldName10_; }
+ set {
+ fieldName10_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "FIELD_NAME11" field.</summary>
+ public const int FIELDNAME11FieldNumber = 411;
+ private int fIELDNAME11_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int FIELDNAME11 {
+ get { return fIELDNAME11_; }
+ set {
+ fIELDNAME11_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "FIELD_name12" field.</summary>
+ public const int FIELDName12FieldNumber = 412;
+ private int fIELDName12_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int FIELDName12 {
+ get { return fIELDName12_; }
+ set {
+ fIELDName12_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "__field_name13" field.</summary>
+ public const int FieldName13FieldNumber = 413;
+ private int FieldName13_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int FieldName13 {
+ get { return FieldName13_; }
+ set {
+ FieldName13_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "__Field_name14" field.</summary>
+ public const int FieldName14FieldNumber = 414;
+ private int FieldName14_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int FieldName14 {
+ get { return FieldName14_; }
+ set {
+ FieldName14_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "field__name15" field.</summary>
+ public const int FieldName15FieldNumber = 415;
+ private int fieldName15_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int FieldName15 {
+ get { return fieldName15_; }
+ set {
+ fieldName15_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "field__Name16" field.</summary>
+ public const int FieldName16FieldNumber = 416;
+ private int fieldName16_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int FieldName16 {
+ get { return fieldName16_; }
+ set {
+ fieldName16_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "field_name17__" field.</summary>
+ public const int FieldName17FieldNumber = 417;
+ private int fieldName17_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int FieldName17 {
+ get { return fieldName17_; }
+ set {
+ fieldName17_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "Field_name18__" field.</summary>
+ public const int FieldName18FieldNumber = 418;
+ private int fieldName18_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int FieldName18 {
+ get { return fieldName18_; }
+ set {
+ fieldName18_ = value;
+ }
+ }
+
+ private object oneofField_;
+ /// <summary>Enum of possible cases for the "oneof_field" oneof.</summary>
+ public enum OneofFieldOneofCase {
+ None = 0,
+ OneofUint32 = 111,
+ OneofNestedMessage = 112,
+ OneofString = 113,
+ OneofBytes = 114,
+ OneofBool = 115,
+ OneofUint64 = 116,
+ OneofFloat = 117,
+ OneofDouble = 118,
+ OneofEnum = 119,
+ }
+ private OneofFieldOneofCase oneofFieldCase_ = OneofFieldOneofCase.None;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneofFieldOneofCase OneofFieldCase {
+ get { return oneofFieldCase_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearOneofField() {
+ oneofFieldCase_ = OneofFieldOneofCase.None;
+ oneofField_ = null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestAllTypes);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestAllTypes other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (OptionalInt32 != other.OptionalInt32) return false;
+ if (OptionalInt64 != other.OptionalInt64) return false;
+ if (OptionalUint32 != other.OptionalUint32) return false;
+ if (OptionalUint64 != other.OptionalUint64) return false;
+ if (OptionalSint32 != other.OptionalSint32) return false;
+ if (OptionalSint64 != other.OptionalSint64) return false;
+ if (OptionalFixed32 != other.OptionalFixed32) return false;
+ if (OptionalFixed64 != other.OptionalFixed64) return false;
+ if (OptionalSfixed32 != other.OptionalSfixed32) return false;
+ if (OptionalSfixed64 != other.OptionalSfixed64) return false;
+ if (OptionalFloat != other.OptionalFloat) return false;
+ if (OptionalDouble != other.OptionalDouble) return false;
+ if (OptionalBool != other.OptionalBool) return false;
+ if (OptionalString != other.OptionalString) return false;
+ if (OptionalBytes != other.OptionalBytes) return false;
+ if (!object.Equals(OptionalNestedMessage, other.OptionalNestedMessage)) return false;
+ if (!object.Equals(OptionalForeignMessage, other.OptionalForeignMessage)) return false;
+ if (OptionalNestedEnum != other.OptionalNestedEnum) return false;
+ if (OptionalForeignEnum != other.OptionalForeignEnum) return false;
+ if (OptionalStringPiece != other.OptionalStringPiece) return false;
+ if (OptionalCord != other.OptionalCord) return false;
+ if (!object.Equals(RecursiveMessage, other.RecursiveMessage)) return false;
+ if(!repeatedInt32_.Equals(other.repeatedInt32_)) return false;
+ if(!repeatedInt64_.Equals(other.repeatedInt64_)) return false;
+ if(!repeatedUint32_.Equals(other.repeatedUint32_)) return false;
+ if(!repeatedUint64_.Equals(other.repeatedUint64_)) return false;
+ if(!repeatedSint32_.Equals(other.repeatedSint32_)) return false;
+ if(!repeatedSint64_.Equals(other.repeatedSint64_)) return false;
+ if(!repeatedFixed32_.Equals(other.repeatedFixed32_)) return false;
+ if(!repeatedFixed64_.Equals(other.repeatedFixed64_)) return false;
+ if(!repeatedSfixed32_.Equals(other.repeatedSfixed32_)) return false;
+ if(!repeatedSfixed64_.Equals(other.repeatedSfixed64_)) return false;
+ if(!repeatedFloat_.Equals(other.repeatedFloat_)) return false;
+ if(!repeatedDouble_.Equals(other.repeatedDouble_)) return false;
+ if(!repeatedBool_.Equals(other.repeatedBool_)) return false;
+ if(!repeatedString_.Equals(other.repeatedString_)) return false;
+ if(!repeatedBytes_.Equals(other.repeatedBytes_)) return false;
+ if(!repeatedNestedMessage_.Equals(other.repeatedNestedMessage_)) return false;
+ if(!repeatedForeignMessage_.Equals(other.repeatedForeignMessage_)) return false;
+ if(!repeatedNestedEnum_.Equals(other.repeatedNestedEnum_)) return false;
+ if(!repeatedForeignEnum_.Equals(other.repeatedForeignEnum_)) return false;
+ if(!repeatedStringPiece_.Equals(other.repeatedStringPiece_)) return false;
+ if(!repeatedCord_.Equals(other.repeatedCord_)) return false;
+ if (!MapInt32Int32.Equals(other.MapInt32Int32)) return false;
+ if (!MapInt64Int64.Equals(other.MapInt64Int64)) return false;
+ if (!MapUint32Uint32.Equals(other.MapUint32Uint32)) return false;
+ if (!MapUint64Uint64.Equals(other.MapUint64Uint64)) return false;
+ if (!MapSint32Sint32.Equals(other.MapSint32Sint32)) return false;
+ if (!MapSint64Sint64.Equals(other.MapSint64Sint64)) return false;
+ if (!MapFixed32Fixed32.Equals(other.MapFixed32Fixed32)) return false;
+ if (!MapFixed64Fixed64.Equals(other.MapFixed64Fixed64)) return false;
+ if (!MapSfixed32Sfixed32.Equals(other.MapSfixed32Sfixed32)) return false;
+ if (!MapSfixed64Sfixed64.Equals(other.MapSfixed64Sfixed64)) return false;
+ if (!MapInt32Float.Equals(other.MapInt32Float)) return false;
+ if (!MapInt32Double.Equals(other.MapInt32Double)) return false;
+ if (!MapBoolBool.Equals(other.MapBoolBool)) return false;
+ if (!MapStringString.Equals(other.MapStringString)) return false;
+ if (!MapStringBytes.Equals(other.MapStringBytes)) return false;
+ if (!MapStringNestedMessage.Equals(other.MapStringNestedMessage)) return false;
+ if (!MapStringForeignMessage.Equals(other.MapStringForeignMessage)) return false;
+ if (!MapStringNestedEnum.Equals(other.MapStringNestedEnum)) return false;
+ if (!MapStringForeignEnum.Equals(other.MapStringForeignEnum)) return false;
+ if (OneofUint32 != other.OneofUint32) return false;
+ if (!object.Equals(OneofNestedMessage, other.OneofNestedMessage)) return false;
+ if (OneofString != other.OneofString) return false;
+ if (OneofBytes != other.OneofBytes) return false;
+ if (OneofBool != other.OneofBool) return false;
+ if (OneofUint64 != other.OneofUint64) return false;
+ if (OneofFloat != other.OneofFloat) return false;
+ if (OneofDouble != other.OneofDouble) return false;
+ if (OneofEnum != other.OneofEnum) return false;
+ if (OptionalBoolWrapper != other.OptionalBoolWrapper) return false;
+ if (OptionalInt32Wrapper != other.OptionalInt32Wrapper) return false;
+ if (OptionalInt64Wrapper != other.OptionalInt64Wrapper) return false;
+ if (OptionalUint32Wrapper != other.OptionalUint32Wrapper) return false;
+ if (OptionalUint64Wrapper != other.OptionalUint64Wrapper) return false;
+ if (OptionalFloatWrapper != other.OptionalFloatWrapper) return false;
+ if (OptionalDoubleWrapper != other.OptionalDoubleWrapper) return false;
+ if (OptionalStringWrapper != other.OptionalStringWrapper) return false;
+ if (OptionalBytesWrapper != other.OptionalBytesWrapper) return false;
+ if(!repeatedBoolWrapper_.Equals(other.repeatedBoolWrapper_)) return false;
+ if(!repeatedInt32Wrapper_.Equals(other.repeatedInt32Wrapper_)) return false;
+ if(!repeatedInt64Wrapper_.Equals(other.repeatedInt64Wrapper_)) return false;
+ if(!repeatedUint32Wrapper_.Equals(other.repeatedUint32Wrapper_)) return false;
+ if(!repeatedUint64Wrapper_.Equals(other.repeatedUint64Wrapper_)) return false;
+ if(!repeatedFloatWrapper_.Equals(other.repeatedFloatWrapper_)) return false;
+ if(!repeatedDoubleWrapper_.Equals(other.repeatedDoubleWrapper_)) return false;
+ if(!repeatedStringWrapper_.Equals(other.repeatedStringWrapper_)) return false;
+ if(!repeatedBytesWrapper_.Equals(other.repeatedBytesWrapper_)) return false;
+ if (!object.Equals(OptionalDuration, other.OptionalDuration)) return false;
+ if (!object.Equals(OptionalTimestamp, other.OptionalTimestamp)) return false;
+ if (!object.Equals(OptionalFieldMask, other.OptionalFieldMask)) return false;
+ if (!object.Equals(OptionalStruct, other.OptionalStruct)) return false;
+ if (!object.Equals(OptionalAny, other.OptionalAny)) return false;
+ if (!object.Equals(OptionalValue, other.OptionalValue)) return false;
+ if(!repeatedDuration_.Equals(other.repeatedDuration_)) return false;
+ if(!repeatedTimestamp_.Equals(other.repeatedTimestamp_)) return false;
+ if(!repeatedFieldmask_.Equals(other.repeatedFieldmask_)) return false;
+ if(!repeatedStruct_.Equals(other.repeatedStruct_)) return false;
+ if(!repeatedAny_.Equals(other.repeatedAny_)) return false;
+ if(!repeatedValue_.Equals(other.repeatedValue_)) return false;
+ if (Fieldname1 != other.Fieldname1) return false;
+ if (FieldName2 != other.FieldName2) return false;
+ if (FieldName3 != other.FieldName3) return false;
+ if (FieldName4 != other.FieldName4) return false;
+ if (Field0Name5 != other.Field0Name5) return false;
+ if (Field0Name6 != other.Field0Name6) return false;
+ if (FieldName7 != other.FieldName7) return false;
+ if (FieldName8 != other.FieldName8) return false;
+ if (FieldName9 != other.FieldName9) return false;
+ if (FieldName10 != other.FieldName10) return false;
+ if (FIELDNAME11 != other.FIELDNAME11) return false;
+ if (FIELDName12 != other.FIELDName12) return false;
+ if (FieldName13 != other.FieldName13) return false;
+ if (FieldName14 != other.FieldName14) return false;
+ if (FieldName15 != other.FieldName15) return false;
+ if (FieldName16 != other.FieldName16) return false;
+ if (FieldName17 != other.FieldName17) return false;
+ if (FieldName18 != other.FieldName18) return false;
+ if (OneofFieldCase != other.OneofFieldCase) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (OptionalInt32 != 0) hash ^= OptionalInt32.GetHashCode();
+ if (OptionalInt64 != 0L) hash ^= OptionalInt64.GetHashCode();
+ if (OptionalUint32 != 0) hash ^= OptionalUint32.GetHashCode();
+ if (OptionalUint64 != 0UL) hash ^= OptionalUint64.GetHashCode();
+ if (OptionalSint32 != 0) hash ^= OptionalSint32.GetHashCode();
+ if (OptionalSint64 != 0L) hash ^= OptionalSint64.GetHashCode();
+ if (OptionalFixed32 != 0) hash ^= OptionalFixed32.GetHashCode();
+ if (OptionalFixed64 != 0UL) hash ^= OptionalFixed64.GetHashCode();
+ if (OptionalSfixed32 != 0) hash ^= OptionalSfixed32.GetHashCode();
+ if (OptionalSfixed64 != 0L) hash ^= OptionalSfixed64.GetHashCode();
+ if (OptionalFloat != 0F) hash ^= OptionalFloat.GetHashCode();
+ if (OptionalDouble != 0D) hash ^= OptionalDouble.GetHashCode();
+ if (OptionalBool != false) hash ^= OptionalBool.GetHashCode();
+ if (OptionalString.Length != 0) hash ^= OptionalString.GetHashCode();
+ if (OptionalBytes.Length != 0) hash ^= OptionalBytes.GetHashCode();
+ if (optionalNestedMessage_ != null) hash ^= OptionalNestedMessage.GetHashCode();
+ if (optionalForeignMessage_ != null) hash ^= OptionalForeignMessage.GetHashCode();
+ if (OptionalNestedEnum != 0) hash ^= OptionalNestedEnum.GetHashCode();
+ if (OptionalForeignEnum != 0) hash ^= OptionalForeignEnum.GetHashCode();
+ if (OptionalStringPiece.Length != 0) hash ^= OptionalStringPiece.GetHashCode();
+ if (OptionalCord.Length != 0) hash ^= OptionalCord.GetHashCode();
+ if (recursiveMessage_ != null) hash ^= RecursiveMessage.GetHashCode();
+ hash ^= repeatedInt32_.GetHashCode();
+ hash ^= repeatedInt64_.GetHashCode();
+ hash ^= repeatedUint32_.GetHashCode();
+ hash ^= repeatedUint64_.GetHashCode();
+ hash ^= repeatedSint32_.GetHashCode();
+ hash ^= repeatedSint64_.GetHashCode();
+ hash ^= repeatedFixed32_.GetHashCode();
+ hash ^= repeatedFixed64_.GetHashCode();
+ hash ^= repeatedSfixed32_.GetHashCode();
+ hash ^= repeatedSfixed64_.GetHashCode();
+ hash ^= repeatedFloat_.GetHashCode();
+ hash ^= repeatedDouble_.GetHashCode();
+ hash ^= repeatedBool_.GetHashCode();
+ hash ^= repeatedString_.GetHashCode();
+ hash ^= repeatedBytes_.GetHashCode();
+ hash ^= repeatedNestedMessage_.GetHashCode();
+ hash ^= repeatedForeignMessage_.GetHashCode();
+ hash ^= repeatedNestedEnum_.GetHashCode();
+ hash ^= repeatedForeignEnum_.GetHashCode();
+ hash ^= repeatedStringPiece_.GetHashCode();
+ hash ^= repeatedCord_.GetHashCode();
+ hash ^= MapInt32Int32.GetHashCode();
+ hash ^= MapInt64Int64.GetHashCode();
+ hash ^= MapUint32Uint32.GetHashCode();
+ hash ^= MapUint64Uint64.GetHashCode();
+ hash ^= MapSint32Sint32.GetHashCode();
+ hash ^= MapSint64Sint64.GetHashCode();
+ hash ^= MapFixed32Fixed32.GetHashCode();
+ hash ^= MapFixed64Fixed64.GetHashCode();
+ hash ^= MapSfixed32Sfixed32.GetHashCode();
+ hash ^= MapSfixed64Sfixed64.GetHashCode();
+ hash ^= MapInt32Float.GetHashCode();
+ hash ^= MapInt32Double.GetHashCode();
+ hash ^= MapBoolBool.GetHashCode();
+ hash ^= MapStringString.GetHashCode();
+ hash ^= MapStringBytes.GetHashCode();
+ hash ^= MapStringNestedMessage.GetHashCode();
+ hash ^= MapStringForeignMessage.GetHashCode();
+ hash ^= MapStringNestedEnum.GetHashCode();
+ hash ^= MapStringForeignEnum.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint32) hash ^= OneofUint32.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) hash ^= OneofNestedMessage.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofString) hash ^= OneofString.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofBytes) hash ^= OneofBytes.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofBool) hash ^= OneofBool.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint64) hash ^= OneofUint64.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofFloat) hash ^= OneofFloat.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofDouble) hash ^= OneofDouble.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofEnum) hash ^= OneofEnum.GetHashCode();
+ if (optionalBoolWrapper_ != null) hash ^= OptionalBoolWrapper.GetHashCode();
+ if (optionalInt32Wrapper_ != null) hash ^= OptionalInt32Wrapper.GetHashCode();
+ if (optionalInt64Wrapper_ != null) hash ^= OptionalInt64Wrapper.GetHashCode();
+ if (optionalUint32Wrapper_ != null) hash ^= OptionalUint32Wrapper.GetHashCode();
+ if (optionalUint64Wrapper_ != null) hash ^= OptionalUint64Wrapper.GetHashCode();
+ if (optionalFloatWrapper_ != null) hash ^= OptionalFloatWrapper.GetHashCode();
+ if (optionalDoubleWrapper_ != null) hash ^= OptionalDoubleWrapper.GetHashCode();
+ if (optionalStringWrapper_ != null) hash ^= OptionalStringWrapper.GetHashCode();
+ if (optionalBytesWrapper_ != null) hash ^= OptionalBytesWrapper.GetHashCode();
+ hash ^= repeatedBoolWrapper_.GetHashCode();
+ hash ^= repeatedInt32Wrapper_.GetHashCode();
+ hash ^= repeatedInt64Wrapper_.GetHashCode();
+ hash ^= repeatedUint32Wrapper_.GetHashCode();
+ hash ^= repeatedUint64Wrapper_.GetHashCode();
+ hash ^= repeatedFloatWrapper_.GetHashCode();
+ hash ^= repeatedDoubleWrapper_.GetHashCode();
+ hash ^= repeatedStringWrapper_.GetHashCode();
+ hash ^= repeatedBytesWrapper_.GetHashCode();
+ if (optionalDuration_ != null) hash ^= OptionalDuration.GetHashCode();
+ if (optionalTimestamp_ != null) hash ^= OptionalTimestamp.GetHashCode();
+ if (optionalFieldMask_ != null) hash ^= OptionalFieldMask.GetHashCode();
+ if (optionalStruct_ != null) hash ^= OptionalStruct.GetHashCode();
+ if (optionalAny_ != null) hash ^= OptionalAny.GetHashCode();
+ if (optionalValue_ != null) hash ^= OptionalValue.GetHashCode();
+ hash ^= repeatedDuration_.GetHashCode();
+ hash ^= repeatedTimestamp_.GetHashCode();
+ hash ^= repeatedFieldmask_.GetHashCode();
+ hash ^= repeatedStruct_.GetHashCode();
+ hash ^= repeatedAny_.GetHashCode();
+ hash ^= repeatedValue_.GetHashCode();
+ if (Fieldname1 != 0) hash ^= Fieldname1.GetHashCode();
+ if (FieldName2 != 0) hash ^= FieldName2.GetHashCode();
+ if (FieldName3 != 0) hash ^= FieldName3.GetHashCode();
+ if (FieldName4 != 0) hash ^= FieldName4.GetHashCode();
+ if (Field0Name5 != 0) hash ^= Field0Name5.GetHashCode();
+ if (Field0Name6 != 0) hash ^= Field0Name6.GetHashCode();
+ if (FieldName7 != 0) hash ^= FieldName7.GetHashCode();
+ if (FieldName8 != 0) hash ^= FieldName8.GetHashCode();
+ if (FieldName9 != 0) hash ^= FieldName9.GetHashCode();
+ if (FieldName10 != 0) hash ^= FieldName10.GetHashCode();
+ if (FIELDNAME11 != 0) hash ^= FIELDNAME11.GetHashCode();
+ if (FIELDName12 != 0) hash ^= FIELDName12.GetHashCode();
+ if (FieldName13 != 0) hash ^= FieldName13.GetHashCode();
+ if (FieldName14 != 0) hash ^= FieldName14.GetHashCode();
+ if (FieldName15 != 0) hash ^= FieldName15.GetHashCode();
+ if (FieldName16 != 0) hash ^= FieldName16.GetHashCode();
+ if (FieldName17 != 0) hash ^= FieldName17.GetHashCode();
+ if (FieldName18 != 0) hash ^= FieldName18.GetHashCode();
+ hash ^= (int) oneofFieldCase_;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (OptionalInt32 != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(OptionalInt32);
+ }
+ if (OptionalInt64 != 0L) {
+ output.WriteRawTag(16);
+ output.WriteInt64(OptionalInt64);
+ }
+ if (OptionalUint32 != 0) {
+ output.WriteRawTag(24);
+ output.WriteUInt32(OptionalUint32);
+ }
+ if (OptionalUint64 != 0UL) {
+ output.WriteRawTag(32);
+ output.WriteUInt64(OptionalUint64);
+ }
+ if (OptionalSint32 != 0) {
+ output.WriteRawTag(40);
+ output.WriteSInt32(OptionalSint32);
+ }
+ if (OptionalSint64 != 0L) {
+ output.WriteRawTag(48);
+ output.WriteSInt64(OptionalSint64);
+ }
+ if (OptionalFixed32 != 0) {
+ output.WriteRawTag(61);
+ output.WriteFixed32(OptionalFixed32);
+ }
+ if (OptionalFixed64 != 0UL) {
+ output.WriteRawTag(65);
+ output.WriteFixed64(OptionalFixed64);
+ }
+ if (OptionalSfixed32 != 0) {
+ output.WriteRawTag(77);
+ output.WriteSFixed32(OptionalSfixed32);
+ }
+ if (OptionalSfixed64 != 0L) {
+ output.WriteRawTag(81);
+ output.WriteSFixed64(OptionalSfixed64);
+ }
+ if (OptionalFloat != 0F) {
+ output.WriteRawTag(93);
+ output.WriteFloat(OptionalFloat);
+ }
+ if (OptionalDouble != 0D) {
+ output.WriteRawTag(97);
+ output.WriteDouble(OptionalDouble);
+ }
+ if (OptionalBool != false) {
+ output.WriteRawTag(104);
+ output.WriteBool(OptionalBool);
+ }
+ if (OptionalString.Length != 0) {
+ output.WriteRawTag(114);
+ output.WriteString(OptionalString);
+ }
+ if (OptionalBytes.Length != 0) {
+ output.WriteRawTag(122);
+ output.WriteBytes(OptionalBytes);
+ }
+ if (optionalNestedMessage_ != null) {
+ output.WriteRawTag(146, 1);
+ output.WriteMessage(OptionalNestedMessage);
+ }
+ if (optionalForeignMessage_ != null) {
+ output.WriteRawTag(154, 1);
+ output.WriteMessage(OptionalForeignMessage);
+ }
+ if (OptionalNestedEnum != 0) {
+ output.WriteRawTag(168, 1);
+ output.WriteEnum((int) OptionalNestedEnum);
+ }
+ if (OptionalForeignEnum != 0) {
+ output.WriteRawTag(176, 1);
+ output.WriteEnum((int) OptionalForeignEnum);
+ }
+ if (OptionalStringPiece.Length != 0) {
+ output.WriteRawTag(194, 1);
+ output.WriteString(OptionalStringPiece);
+ }
+ if (OptionalCord.Length != 0) {
+ output.WriteRawTag(202, 1);
+ output.WriteString(OptionalCord);
+ }
+ if (recursiveMessage_ != null) {
+ output.WriteRawTag(218, 1);
+ output.WriteMessage(RecursiveMessage);
+ }
+ repeatedInt32_.WriteTo(output, _repeated_repeatedInt32_codec);
+ repeatedInt64_.WriteTo(output, _repeated_repeatedInt64_codec);
+ repeatedUint32_.WriteTo(output, _repeated_repeatedUint32_codec);
+ repeatedUint64_.WriteTo(output, _repeated_repeatedUint64_codec);
+ repeatedSint32_.WriteTo(output, _repeated_repeatedSint32_codec);
+ repeatedSint64_.WriteTo(output, _repeated_repeatedSint64_codec);
+ repeatedFixed32_.WriteTo(output, _repeated_repeatedFixed32_codec);
+ repeatedFixed64_.WriteTo(output, _repeated_repeatedFixed64_codec);
+ repeatedSfixed32_.WriteTo(output, _repeated_repeatedSfixed32_codec);
+ repeatedSfixed64_.WriteTo(output, _repeated_repeatedSfixed64_codec);
+ repeatedFloat_.WriteTo(output, _repeated_repeatedFloat_codec);
+ repeatedDouble_.WriteTo(output, _repeated_repeatedDouble_codec);
+ repeatedBool_.WriteTo(output, _repeated_repeatedBool_codec);
+ repeatedString_.WriteTo(output, _repeated_repeatedString_codec);
+ repeatedBytes_.WriteTo(output, _repeated_repeatedBytes_codec);
+ repeatedNestedMessage_.WriteTo(output, _repeated_repeatedNestedMessage_codec);
+ repeatedForeignMessage_.WriteTo(output, _repeated_repeatedForeignMessage_codec);
+ repeatedNestedEnum_.WriteTo(output, _repeated_repeatedNestedEnum_codec);
+ repeatedForeignEnum_.WriteTo(output, _repeated_repeatedForeignEnum_codec);
+ repeatedStringPiece_.WriteTo(output, _repeated_repeatedStringPiece_codec);
+ repeatedCord_.WriteTo(output, _repeated_repeatedCord_codec);
+ mapInt32Int32_.WriteTo(output, _map_mapInt32Int32_codec);
+ mapInt64Int64_.WriteTo(output, _map_mapInt64Int64_codec);
+ mapUint32Uint32_.WriteTo(output, _map_mapUint32Uint32_codec);
+ mapUint64Uint64_.WriteTo(output, _map_mapUint64Uint64_codec);
+ mapSint32Sint32_.WriteTo(output, _map_mapSint32Sint32_codec);
+ mapSint64Sint64_.WriteTo(output, _map_mapSint64Sint64_codec);
+ mapFixed32Fixed32_.WriteTo(output, _map_mapFixed32Fixed32_codec);
+ mapFixed64Fixed64_.WriteTo(output, _map_mapFixed64Fixed64_codec);
+ mapSfixed32Sfixed32_.WriteTo(output, _map_mapSfixed32Sfixed32_codec);
+ mapSfixed64Sfixed64_.WriteTo(output, _map_mapSfixed64Sfixed64_codec);
+ mapInt32Float_.WriteTo(output, _map_mapInt32Float_codec);
+ mapInt32Double_.WriteTo(output, _map_mapInt32Double_codec);
+ mapBoolBool_.WriteTo(output, _map_mapBoolBool_codec);
+ mapStringString_.WriteTo(output, _map_mapStringString_codec);
+ mapStringBytes_.WriteTo(output, _map_mapStringBytes_codec);
+ mapStringNestedMessage_.WriteTo(output, _map_mapStringNestedMessage_codec);
+ mapStringForeignMessage_.WriteTo(output, _map_mapStringForeignMessage_codec);
+ mapStringNestedEnum_.WriteTo(output, _map_mapStringNestedEnum_codec);
+ mapStringForeignEnum_.WriteTo(output, _map_mapStringForeignEnum_codec);
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint32) {
+ output.WriteRawTag(248, 6);
+ output.WriteUInt32(OneofUint32);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) {
+ output.WriteRawTag(130, 7);
+ output.WriteMessage(OneofNestedMessage);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofString) {
+ output.WriteRawTag(138, 7);
+ output.WriteString(OneofString);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofBytes) {
+ output.WriteRawTag(146, 7);
+ output.WriteBytes(OneofBytes);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofBool) {
+ output.WriteRawTag(152, 7);
+ output.WriteBool(OneofBool);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint64) {
+ output.WriteRawTag(160, 7);
+ output.WriteUInt64(OneofUint64);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofFloat) {
+ output.WriteRawTag(173, 7);
+ output.WriteFloat(OneofFloat);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofDouble) {
+ output.WriteRawTag(177, 7);
+ output.WriteDouble(OneofDouble);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofEnum) {
+ output.WriteRawTag(184, 7);
+ output.WriteEnum((int) OneofEnum);
+ }
+ if (optionalBoolWrapper_ != null) {
+ _single_optionalBoolWrapper_codec.WriteTagAndValue(output, OptionalBoolWrapper);
+ }
+ if (optionalInt32Wrapper_ != null) {
+ _single_optionalInt32Wrapper_codec.WriteTagAndValue(output, OptionalInt32Wrapper);
+ }
+ if (optionalInt64Wrapper_ != null) {
+ _single_optionalInt64Wrapper_codec.WriteTagAndValue(output, OptionalInt64Wrapper);
+ }
+ if (optionalUint32Wrapper_ != null) {
+ _single_optionalUint32Wrapper_codec.WriteTagAndValue(output, OptionalUint32Wrapper);
+ }
+ if (optionalUint64Wrapper_ != null) {
+ _single_optionalUint64Wrapper_codec.WriteTagAndValue(output, OptionalUint64Wrapper);
+ }
+ if (optionalFloatWrapper_ != null) {
+ _single_optionalFloatWrapper_codec.WriteTagAndValue(output, OptionalFloatWrapper);
+ }
+ if (optionalDoubleWrapper_ != null) {
+ _single_optionalDoubleWrapper_codec.WriteTagAndValue(output, OptionalDoubleWrapper);
+ }
+ if (optionalStringWrapper_ != null) {
+ _single_optionalStringWrapper_codec.WriteTagAndValue(output, OptionalStringWrapper);
+ }
+ if (optionalBytesWrapper_ != null) {
+ _single_optionalBytesWrapper_codec.WriteTagAndValue(output, OptionalBytesWrapper);
+ }
+ repeatedBoolWrapper_.WriteTo(output, _repeated_repeatedBoolWrapper_codec);
+ repeatedInt32Wrapper_.WriteTo(output, _repeated_repeatedInt32Wrapper_codec);
+ repeatedInt64Wrapper_.WriteTo(output, _repeated_repeatedInt64Wrapper_codec);
+ repeatedUint32Wrapper_.WriteTo(output, _repeated_repeatedUint32Wrapper_codec);
+ repeatedUint64Wrapper_.WriteTo(output, _repeated_repeatedUint64Wrapper_codec);
+ repeatedFloatWrapper_.WriteTo(output, _repeated_repeatedFloatWrapper_codec);
+ repeatedDoubleWrapper_.WriteTo(output, _repeated_repeatedDoubleWrapper_codec);
+ repeatedStringWrapper_.WriteTo(output, _repeated_repeatedStringWrapper_codec);
+ repeatedBytesWrapper_.WriteTo(output, _repeated_repeatedBytesWrapper_codec);
+ if (optionalDuration_ != null) {
+ output.WriteRawTag(234, 18);
+ output.WriteMessage(OptionalDuration);
+ }
+ if (optionalTimestamp_ != null) {
+ output.WriteRawTag(242, 18);
+ output.WriteMessage(OptionalTimestamp);
+ }
+ if (optionalFieldMask_ != null) {
+ output.WriteRawTag(250, 18);
+ output.WriteMessage(OptionalFieldMask);
+ }
+ if (optionalStruct_ != null) {
+ output.WriteRawTag(130, 19);
+ output.WriteMessage(OptionalStruct);
+ }
+ if (optionalAny_ != null) {
+ output.WriteRawTag(138, 19);
+ output.WriteMessage(OptionalAny);
+ }
+ if (optionalValue_ != null) {
+ output.WriteRawTag(146, 19);
+ output.WriteMessage(OptionalValue);
+ }
+ repeatedDuration_.WriteTo(output, _repeated_repeatedDuration_codec);
+ repeatedTimestamp_.WriteTo(output, _repeated_repeatedTimestamp_codec);
+ repeatedFieldmask_.WriteTo(output, _repeated_repeatedFieldmask_codec);
+ repeatedAny_.WriteTo(output, _repeated_repeatedAny_codec);
+ repeatedValue_.WriteTo(output, _repeated_repeatedValue_codec);
+ repeatedStruct_.WriteTo(output, _repeated_repeatedStruct_codec);
+ if (Fieldname1 != 0) {
+ output.WriteRawTag(136, 25);
+ output.WriteInt32(Fieldname1);
+ }
+ if (FieldName2 != 0) {
+ output.WriteRawTag(144, 25);
+ output.WriteInt32(FieldName2);
+ }
+ if (FieldName3 != 0) {
+ output.WriteRawTag(152, 25);
+ output.WriteInt32(FieldName3);
+ }
+ if (FieldName4 != 0) {
+ output.WriteRawTag(160, 25);
+ output.WriteInt32(FieldName4);
+ }
+ if (Field0Name5 != 0) {
+ output.WriteRawTag(168, 25);
+ output.WriteInt32(Field0Name5);
+ }
+ if (Field0Name6 != 0) {
+ output.WriteRawTag(176, 25);
+ output.WriteInt32(Field0Name6);
+ }
+ if (FieldName7 != 0) {
+ output.WriteRawTag(184, 25);
+ output.WriteInt32(FieldName7);
+ }
+ if (FieldName8 != 0) {
+ output.WriteRawTag(192, 25);
+ output.WriteInt32(FieldName8);
+ }
+ if (FieldName9 != 0) {
+ output.WriteRawTag(200, 25);
+ output.WriteInt32(FieldName9);
+ }
+ if (FieldName10 != 0) {
+ output.WriteRawTag(208, 25);
+ output.WriteInt32(FieldName10);
+ }
+ if (FIELDNAME11 != 0) {
+ output.WriteRawTag(216, 25);
+ output.WriteInt32(FIELDNAME11);
+ }
+ if (FIELDName12 != 0) {
+ output.WriteRawTag(224, 25);
+ output.WriteInt32(FIELDName12);
+ }
+ if (FieldName13 != 0) {
+ output.WriteRawTag(232, 25);
+ output.WriteInt32(FieldName13);
+ }
+ if (FieldName14 != 0) {
+ output.WriteRawTag(240, 25);
+ output.WriteInt32(FieldName14);
+ }
+ if (FieldName15 != 0) {
+ output.WriteRawTag(248, 25);
+ output.WriteInt32(FieldName15);
+ }
+ if (FieldName16 != 0) {
+ output.WriteRawTag(128, 26);
+ output.WriteInt32(FieldName16);
+ }
+ if (FieldName17 != 0) {
+ output.WriteRawTag(136, 26);
+ output.WriteInt32(FieldName17);
+ }
+ if (FieldName18 != 0) {
+ output.WriteRawTag(144, 26);
+ output.WriteInt32(FieldName18);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (OptionalInt32 != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(OptionalInt32);
+ }
+ if (OptionalInt64 != 0L) {
+ size += 1 + pb::CodedOutputStream.ComputeInt64Size(OptionalInt64);
+ }
+ if (OptionalUint32 != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeUInt32Size(OptionalUint32);
+ }
+ if (OptionalUint64 != 0UL) {
+ size += 1 + pb::CodedOutputStream.ComputeUInt64Size(OptionalUint64);
+ }
+ if (OptionalSint32 != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeSInt32Size(OptionalSint32);
+ }
+ if (OptionalSint64 != 0L) {
+ size += 1 + pb::CodedOutputStream.ComputeSInt64Size(OptionalSint64);
+ }
+ if (OptionalFixed32 != 0) {
+ size += 1 + 4;
+ }
+ if (OptionalFixed64 != 0UL) {
+ size += 1 + 8;
+ }
+ if (OptionalSfixed32 != 0) {
+ size += 1 + 4;
+ }
+ if (OptionalSfixed64 != 0L) {
+ size += 1 + 8;
+ }
+ if (OptionalFloat != 0F) {
+ size += 1 + 4;
+ }
+ if (OptionalDouble != 0D) {
+ size += 1 + 8;
+ }
+ if (OptionalBool != false) {
+ size += 1 + 1;
+ }
+ if (OptionalString.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(OptionalString);
+ }
+ if (OptionalBytes.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeBytesSize(OptionalBytes);
+ }
+ if (optionalNestedMessage_ != null) {
+ size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalNestedMessage);
+ }
+ if (optionalForeignMessage_ != null) {
+ size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalForeignMessage);
+ }
+ if (OptionalNestedEnum != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) OptionalNestedEnum);
+ }
+ if (OptionalForeignEnum != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) OptionalForeignEnum);
+ }
+ if (OptionalStringPiece.Length != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeStringSize(OptionalStringPiece);
+ }
+ if (OptionalCord.Length != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeStringSize(OptionalCord);
+ }
+ if (recursiveMessage_ != null) {
+ size += 2 + pb::CodedOutputStream.ComputeMessageSize(RecursiveMessage);
+ }
+ size += repeatedInt32_.CalculateSize(_repeated_repeatedInt32_codec);
+ size += repeatedInt64_.CalculateSize(_repeated_repeatedInt64_codec);
+ size += repeatedUint32_.CalculateSize(_repeated_repeatedUint32_codec);
+ size += repeatedUint64_.CalculateSize(_repeated_repeatedUint64_codec);
+ size += repeatedSint32_.CalculateSize(_repeated_repeatedSint32_codec);
+ size += repeatedSint64_.CalculateSize(_repeated_repeatedSint64_codec);
+ size += repeatedFixed32_.CalculateSize(_repeated_repeatedFixed32_codec);
+ size += repeatedFixed64_.CalculateSize(_repeated_repeatedFixed64_codec);
+ size += repeatedSfixed32_.CalculateSize(_repeated_repeatedSfixed32_codec);
+ size += repeatedSfixed64_.CalculateSize(_repeated_repeatedSfixed64_codec);
+ size += repeatedFloat_.CalculateSize(_repeated_repeatedFloat_codec);
+ size += repeatedDouble_.CalculateSize(_repeated_repeatedDouble_codec);
+ size += repeatedBool_.CalculateSize(_repeated_repeatedBool_codec);
+ size += repeatedString_.CalculateSize(_repeated_repeatedString_codec);
+ size += repeatedBytes_.CalculateSize(_repeated_repeatedBytes_codec);
+ size += repeatedNestedMessage_.CalculateSize(_repeated_repeatedNestedMessage_codec);
+ size += repeatedForeignMessage_.CalculateSize(_repeated_repeatedForeignMessage_codec);
+ size += repeatedNestedEnum_.CalculateSize(_repeated_repeatedNestedEnum_codec);
+ size += repeatedForeignEnum_.CalculateSize(_repeated_repeatedForeignEnum_codec);
+ size += repeatedStringPiece_.CalculateSize(_repeated_repeatedStringPiece_codec);
+ size += repeatedCord_.CalculateSize(_repeated_repeatedCord_codec);
+ size += mapInt32Int32_.CalculateSize(_map_mapInt32Int32_codec);
+ size += mapInt64Int64_.CalculateSize(_map_mapInt64Int64_codec);
+ size += mapUint32Uint32_.CalculateSize(_map_mapUint32Uint32_codec);
+ size += mapUint64Uint64_.CalculateSize(_map_mapUint64Uint64_codec);
+ size += mapSint32Sint32_.CalculateSize(_map_mapSint32Sint32_codec);
+ size += mapSint64Sint64_.CalculateSize(_map_mapSint64Sint64_codec);
+ size += mapFixed32Fixed32_.CalculateSize(_map_mapFixed32Fixed32_codec);
+ size += mapFixed64Fixed64_.CalculateSize(_map_mapFixed64Fixed64_codec);
+ size += mapSfixed32Sfixed32_.CalculateSize(_map_mapSfixed32Sfixed32_codec);
+ size += mapSfixed64Sfixed64_.CalculateSize(_map_mapSfixed64Sfixed64_codec);
+ size += mapInt32Float_.CalculateSize(_map_mapInt32Float_codec);
+ size += mapInt32Double_.CalculateSize(_map_mapInt32Double_codec);
+ size += mapBoolBool_.CalculateSize(_map_mapBoolBool_codec);
+ size += mapStringString_.CalculateSize(_map_mapStringString_codec);
+ size += mapStringBytes_.CalculateSize(_map_mapStringBytes_codec);
+ size += mapStringNestedMessage_.CalculateSize(_map_mapStringNestedMessage_codec);
+ size += mapStringForeignMessage_.CalculateSize(_map_mapStringForeignMessage_codec);
+ size += mapStringNestedEnum_.CalculateSize(_map_mapStringNestedEnum_codec);
+ size += mapStringForeignEnum_.CalculateSize(_map_mapStringForeignEnum_codec);
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint32) {
+ size += 2 + pb::CodedOutputStream.ComputeUInt32Size(OneofUint32);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) {
+ size += 2 + pb::CodedOutputStream.ComputeMessageSize(OneofNestedMessage);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofString) {
+ size += 2 + pb::CodedOutputStream.ComputeStringSize(OneofString);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofBytes) {
+ size += 2 + pb::CodedOutputStream.ComputeBytesSize(OneofBytes);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofBool) {
+ size += 2 + 1;
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint64) {
+ size += 2 + pb::CodedOutputStream.ComputeUInt64Size(OneofUint64);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofFloat) {
+ size += 2 + 4;
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofDouble) {
+ size += 2 + 8;
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofEnum) {
+ size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) OneofEnum);
+ }
+ if (optionalBoolWrapper_ != null) {
+ size += _single_optionalBoolWrapper_codec.CalculateSizeWithTag(OptionalBoolWrapper);
+ }
+ if (optionalInt32Wrapper_ != null) {
+ size += _single_optionalInt32Wrapper_codec.CalculateSizeWithTag(OptionalInt32Wrapper);
+ }
+ if (optionalInt64Wrapper_ != null) {
+ size += _single_optionalInt64Wrapper_codec.CalculateSizeWithTag(OptionalInt64Wrapper);
+ }
+ if (optionalUint32Wrapper_ != null) {
+ size += _single_optionalUint32Wrapper_codec.CalculateSizeWithTag(OptionalUint32Wrapper);
+ }
+ if (optionalUint64Wrapper_ != null) {
+ size += _single_optionalUint64Wrapper_codec.CalculateSizeWithTag(OptionalUint64Wrapper);
+ }
+ if (optionalFloatWrapper_ != null) {
+ size += _single_optionalFloatWrapper_codec.CalculateSizeWithTag(OptionalFloatWrapper);
+ }
+ if (optionalDoubleWrapper_ != null) {
+ size += _single_optionalDoubleWrapper_codec.CalculateSizeWithTag(OptionalDoubleWrapper);
+ }
+ if (optionalStringWrapper_ != null) {
+ size += _single_optionalStringWrapper_codec.CalculateSizeWithTag(OptionalStringWrapper);
+ }
+ if (optionalBytesWrapper_ != null) {
+ size += _single_optionalBytesWrapper_codec.CalculateSizeWithTag(OptionalBytesWrapper);
+ }
+ size += repeatedBoolWrapper_.CalculateSize(_repeated_repeatedBoolWrapper_codec);
+ size += repeatedInt32Wrapper_.CalculateSize(_repeated_repeatedInt32Wrapper_codec);
+ size += repeatedInt64Wrapper_.CalculateSize(_repeated_repeatedInt64Wrapper_codec);
+ size += repeatedUint32Wrapper_.CalculateSize(_repeated_repeatedUint32Wrapper_codec);
+ size += repeatedUint64Wrapper_.CalculateSize(_repeated_repeatedUint64Wrapper_codec);
+ size += repeatedFloatWrapper_.CalculateSize(_repeated_repeatedFloatWrapper_codec);
+ size += repeatedDoubleWrapper_.CalculateSize(_repeated_repeatedDoubleWrapper_codec);
+ size += repeatedStringWrapper_.CalculateSize(_repeated_repeatedStringWrapper_codec);
+ size += repeatedBytesWrapper_.CalculateSize(_repeated_repeatedBytesWrapper_codec);
+ if (optionalDuration_ != null) {
+ size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalDuration);
+ }
+ if (optionalTimestamp_ != null) {
+ size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalTimestamp);
+ }
+ if (optionalFieldMask_ != null) {
+ size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalFieldMask);
+ }
+ if (optionalStruct_ != null) {
+ size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalStruct);
+ }
+ if (optionalAny_ != null) {
+ size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalAny);
+ }
+ if (optionalValue_ != null) {
+ size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalValue);
+ }
+ size += repeatedDuration_.CalculateSize(_repeated_repeatedDuration_codec);
+ size += repeatedTimestamp_.CalculateSize(_repeated_repeatedTimestamp_codec);
+ size += repeatedFieldmask_.CalculateSize(_repeated_repeatedFieldmask_codec);
+ size += repeatedStruct_.CalculateSize(_repeated_repeatedStruct_codec);
+ size += repeatedAny_.CalculateSize(_repeated_repeatedAny_codec);
+ size += repeatedValue_.CalculateSize(_repeated_repeatedValue_codec);
+ if (Fieldname1 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(Fieldname1);
+ }
+ if (FieldName2 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(FieldName2);
+ }
+ if (FieldName3 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(FieldName3);
+ }
+ if (FieldName4 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(FieldName4);
+ }
+ if (Field0Name5 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field0Name5);
+ }
+ if (Field0Name6 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(Field0Name6);
+ }
+ if (FieldName7 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(FieldName7);
+ }
+ if (FieldName8 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(FieldName8);
+ }
+ if (FieldName9 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(FieldName9);
+ }
+ if (FieldName10 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(FieldName10);
+ }
+ if (FIELDNAME11 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(FIELDNAME11);
+ }
+ if (FIELDName12 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(FIELDName12);
+ }
+ if (FieldName13 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(FieldName13);
+ }
+ if (FieldName14 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(FieldName14);
+ }
+ if (FieldName15 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(FieldName15);
+ }
+ if (FieldName16 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(FieldName16);
+ }
+ if (FieldName17 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(FieldName17);
+ }
+ if (FieldName18 != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeInt32Size(FieldName18);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestAllTypes other) {
+ if (other == null) {
+ return;
+ }
+ if (other.OptionalInt32 != 0) {
+ OptionalInt32 = other.OptionalInt32;
+ }
+ if (other.OptionalInt64 != 0L) {
+ OptionalInt64 = other.OptionalInt64;
+ }
+ if (other.OptionalUint32 != 0) {
+ OptionalUint32 = other.OptionalUint32;
+ }
+ if (other.OptionalUint64 != 0UL) {
+ OptionalUint64 = other.OptionalUint64;
+ }
+ if (other.OptionalSint32 != 0) {
+ OptionalSint32 = other.OptionalSint32;
+ }
+ if (other.OptionalSint64 != 0L) {
+ OptionalSint64 = other.OptionalSint64;
+ }
+ if (other.OptionalFixed32 != 0) {
+ OptionalFixed32 = other.OptionalFixed32;
+ }
+ if (other.OptionalFixed64 != 0UL) {
+ OptionalFixed64 = other.OptionalFixed64;
+ }
+ if (other.OptionalSfixed32 != 0) {
+ OptionalSfixed32 = other.OptionalSfixed32;
+ }
+ if (other.OptionalSfixed64 != 0L) {
+ OptionalSfixed64 = other.OptionalSfixed64;
+ }
+ if (other.OptionalFloat != 0F) {
+ OptionalFloat = other.OptionalFloat;
+ }
+ if (other.OptionalDouble != 0D) {
+ OptionalDouble = other.OptionalDouble;
+ }
+ if (other.OptionalBool != false) {
+ OptionalBool = other.OptionalBool;
+ }
+ if (other.OptionalString.Length != 0) {
+ OptionalString = other.OptionalString;
+ }
+ if (other.OptionalBytes.Length != 0) {
+ OptionalBytes = other.OptionalBytes;
+ }
+ if (other.optionalNestedMessage_ != null) {
+ if (optionalNestedMessage_ == null) {
+ optionalNestedMessage_ = new global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage();
+ }
+ OptionalNestedMessage.MergeFrom(other.OptionalNestedMessage);
+ }
+ if (other.optionalForeignMessage_ != null) {
+ if (optionalForeignMessage_ == null) {
+ optionalForeignMessage_ = new global::ProtobufTestMessages.Proto3.ForeignMessage();
+ }
+ OptionalForeignMessage.MergeFrom(other.OptionalForeignMessage);
+ }
+ if (other.OptionalNestedEnum != 0) {
+ OptionalNestedEnum = other.OptionalNestedEnum;
+ }
+ if (other.OptionalForeignEnum != 0) {
+ OptionalForeignEnum = other.OptionalForeignEnum;
+ }
+ if (other.OptionalStringPiece.Length != 0) {
+ OptionalStringPiece = other.OptionalStringPiece;
+ }
+ if (other.OptionalCord.Length != 0) {
+ OptionalCord = other.OptionalCord;
+ }
+ if (other.recursiveMessage_ != null) {
+ if (recursiveMessage_ == null) {
+ recursiveMessage_ = new global::ProtobufTestMessages.Proto3.TestAllTypes();
+ }
+ RecursiveMessage.MergeFrom(other.RecursiveMessage);
+ }
+ repeatedInt32_.Add(other.repeatedInt32_);
+ repeatedInt64_.Add(other.repeatedInt64_);
+ repeatedUint32_.Add(other.repeatedUint32_);
+ repeatedUint64_.Add(other.repeatedUint64_);
+ repeatedSint32_.Add(other.repeatedSint32_);
+ repeatedSint64_.Add(other.repeatedSint64_);
+ repeatedFixed32_.Add(other.repeatedFixed32_);
+ repeatedFixed64_.Add(other.repeatedFixed64_);
+ repeatedSfixed32_.Add(other.repeatedSfixed32_);
+ repeatedSfixed64_.Add(other.repeatedSfixed64_);
+ repeatedFloat_.Add(other.repeatedFloat_);
+ repeatedDouble_.Add(other.repeatedDouble_);
+ repeatedBool_.Add(other.repeatedBool_);
+ repeatedString_.Add(other.repeatedString_);
+ repeatedBytes_.Add(other.repeatedBytes_);
+ repeatedNestedMessage_.Add(other.repeatedNestedMessage_);
+ repeatedForeignMessage_.Add(other.repeatedForeignMessage_);
+ repeatedNestedEnum_.Add(other.repeatedNestedEnum_);
+ repeatedForeignEnum_.Add(other.repeatedForeignEnum_);
+ repeatedStringPiece_.Add(other.repeatedStringPiece_);
+ repeatedCord_.Add(other.repeatedCord_);
+ mapInt32Int32_.Add(other.mapInt32Int32_);
+ mapInt64Int64_.Add(other.mapInt64Int64_);
+ mapUint32Uint32_.Add(other.mapUint32Uint32_);
+ mapUint64Uint64_.Add(other.mapUint64Uint64_);
+ mapSint32Sint32_.Add(other.mapSint32Sint32_);
+ mapSint64Sint64_.Add(other.mapSint64Sint64_);
+ mapFixed32Fixed32_.Add(other.mapFixed32Fixed32_);
+ mapFixed64Fixed64_.Add(other.mapFixed64Fixed64_);
+ mapSfixed32Sfixed32_.Add(other.mapSfixed32Sfixed32_);
+ mapSfixed64Sfixed64_.Add(other.mapSfixed64Sfixed64_);
+ mapInt32Float_.Add(other.mapInt32Float_);
+ mapInt32Double_.Add(other.mapInt32Double_);
+ mapBoolBool_.Add(other.mapBoolBool_);
+ mapStringString_.Add(other.mapStringString_);
+ mapStringBytes_.Add(other.mapStringBytes_);
+ mapStringNestedMessage_.Add(other.mapStringNestedMessage_);
+ mapStringForeignMessage_.Add(other.mapStringForeignMessage_);
+ mapStringNestedEnum_.Add(other.mapStringNestedEnum_);
+ mapStringForeignEnum_.Add(other.mapStringForeignEnum_);
+ if (other.optionalBoolWrapper_ != null) {
+ if (optionalBoolWrapper_ == null || other.OptionalBoolWrapper != false) {
+ OptionalBoolWrapper = other.OptionalBoolWrapper;
+ }
+ }
+ if (other.optionalInt32Wrapper_ != null) {
+ if (optionalInt32Wrapper_ == null || other.OptionalInt32Wrapper != 0) {
+ OptionalInt32Wrapper = other.OptionalInt32Wrapper;
+ }
+ }
+ if (other.optionalInt64Wrapper_ != null) {
+ if (optionalInt64Wrapper_ == null || other.OptionalInt64Wrapper != 0L) {
+ OptionalInt64Wrapper = other.OptionalInt64Wrapper;
+ }
+ }
+ if (other.optionalUint32Wrapper_ != null) {
+ if (optionalUint32Wrapper_ == null || other.OptionalUint32Wrapper != 0) {
+ OptionalUint32Wrapper = other.OptionalUint32Wrapper;
+ }
+ }
+ if (other.optionalUint64Wrapper_ != null) {
+ if (optionalUint64Wrapper_ == null || other.OptionalUint64Wrapper != 0UL) {
+ OptionalUint64Wrapper = other.OptionalUint64Wrapper;
+ }
+ }
+ if (other.optionalFloatWrapper_ != null) {
+ if (optionalFloatWrapper_ == null || other.OptionalFloatWrapper != 0F) {
+ OptionalFloatWrapper = other.OptionalFloatWrapper;
+ }
+ }
+ if (other.optionalDoubleWrapper_ != null) {
+ if (optionalDoubleWrapper_ == null || other.OptionalDoubleWrapper != 0D) {
+ OptionalDoubleWrapper = other.OptionalDoubleWrapper;
+ }
+ }
+ if (other.optionalStringWrapper_ != null) {
+ if (optionalStringWrapper_ == null || other.OptionalStringWrapper != "") {
+ OptionalStringWrapper = other.OptionalStringWrapper;
+ }
+ }
+ if (other.optionalBytesWrapper_ != null) {
+ if (optionalBytesWrapper_ == null || other.OptionalBytesWrapper != pb::ByteString.Empty) {
+ OptionalBytesWrapper = other.OptionalBytesWrapper;
+ }
+ }
+ repeatedBoolWrapper_.Add(other.repeatedBoolWrapper_);
+ repeatedInt32Wrapper_.Add(other.repeatedInt32Wrapper_);
+ repeatedInt64Wrapper_.Add(other.repeatedInt64Wrapper_);
+ repeatedUint32Wrapper_.Add(other.repeatedUint32Wrapper_);
+ repeatedUint64Wrapper_.Add(other.repeatedUint64Wrapper_);
+ repeatedFloatWrapper_.Add(other.repeatedFloatWrapper_);
+ repeatedDoubleWrapper_.Add(other.repeatedDoubleWrapper_);
+ repeatedStringWrapper_.Add(other.repeatedStringWrapper_);
+ repeatedBytesWrapper_.Add(other.repeatedBytesWrapper_);
+ if (other.optionalDuration_ != null) {
+ if (optionalDuration_ == null) {
+ optionalDuration_ = new global::Google.Protobuf.WellKnownTypes.Duration();
+ }
+ OptionalDuration.MergeFrom(other.OptionalDuration);
+ }
+ if (other.optionalTimestamp_ != null) {
+ if (optionalTimestamp_ == null) {
+ optionalTimestamp_ = new global::Google.Protobuf.WellKnownTypes.Timestamp();
+ }
+ OptionalTimestamp.MergeFrom(other.OptionalTimestamp);
+ }
+ if (other.optionalFieldMask_ != null) {
+ if (optionalFieldMask_ == null) {
+ optionalFieldMask_ = new global::Google.Protobuf.WellKnownTypes.FieldMask();
+ }
+ OptionalFieldMask.MergeFrom(other.OptionalFieldMask);
+ }
+ if (other.optionalStruct_ != null) {
+ if (optionalStruct_ == null) {
+ optionalStruct_ = new global::Google.Protobuf.WellKnownTypes.Struct();
+ }
+ OptionalStruct.MergeFrom(other.OptionalStruct);
+ }
+ if (other.optionalAny_ != null) {
+ if (optionalAny_ == null) {
+ optionalAny_ = new global::Google.Protobuf.WellKnownTypes.Any();
+ }
+ OptionalAny.MergeFrom(other.OptionalAny);
+ }
+ if (other.optionalValue_ != null) {
+ if (optionalValue_ == null) {
+ optionalValue_ = new global::Google.Protobuf.WellKnownTypes.Value();
+ }
+ OptionalValue.MergeFrom(other.OptionalValue);
+ }
+ repeatedDuration_.Add(other.repeatedDuration_);
+ repeatedTimestamp_.Add(other.repeatedTimestamp_);
+ repeatedFieldmask_.Add(other.repeatedFieldmask_);
+ repeatedStruct_.Add(other.repeatedStruct_);
+ repeatedAny_.Add(other.repeatedAny_);
+ repeatedValue_.Add(other.repeatedValue_);
+ if (other.Fieldname1 != 0) {
+ Fieldname1 = other.Fieldname1;
+ }
+ if (other.FieldName2 != 0) {
+ FieldName2 = other.FieldName2;
+ }
+ if (other.FieldName3 != 0) {
+ FieldName3 = other.FieldName3;
+ }
+ if (other.FieldName4 != 0) {
+ FieldName4 = other.FieldName4;
+ }
+ if (other.Field0Name5 != 0) {
+ Field0Name5 = other.Field0Name5;
+ }
+ if (other.Field0Name6 != 0) {
+ Field0Name6 = other.Field0Name6;
+ }
+ if (other.FieldName7 != 0) {
+ FieldName7 = other.FieldName7;
+ }
+ if (other.FieldName8 != 0) {
+ FieldName8 = other.FieldName8;
+ }
+ if (other.FieldName9 != 0) {
+ FieldName9 = other.FieldName9;
+ }
+ if (other.FieldName10 != 0) {
+ FieldName10 = other.FieldName10;
+ }
+ if (other.FIELDNAME11 != 0) {
+ FIELDNAME11 = other.FIELDNAME11;
+ }
+ if (other.FIELDName12 != 0) {
+ FIELDName12 = other.FIELDName12;
+ }
+ if (other.FieldName13 != 0) {
+ FieldName13 = other.FieldName13;
+ }
+ if (other.FieldName14 != 0) {
+ FieldName14 = other.FieldName14;
+ }
+ if (other.FieldName15 != 0) {
+ FieldName15 = other.FieldName15;
+ }
+ if (other.FieldName16 != 0) {
+ FieldName16 = other.FieldName16;
+ }
+ if (other.FieldName17 != 0) {
+ FieldName17 = other.FieldName17;
+ }
+ if (other.FieldName18 != 0) {
+ FieldName18 = other.FieldName18;
+ }
+ switch (other.OneofFieldCase) {
+ case OneofFieldOneofCase.OneofUint32:
+ OneofUint32 = other.OneofUint32;
+ break;
+ case OneofFieldOneofCase.OneofNestedMessage:
+ OneofNestedMessage = other.OneofNestedMessage;
+ break;
+ case OneofFieldOneofCase.OneofString:
+ OneofString = other.OneofString;
+ break;
+ case OneofFieldOneofCase.OneofBytes:
+ OneofBytes = other.OneofBytes;
+ break;
+ case OneofFieldOneofCase.OneofBool:
+ OneofBool = other.OneofBool;
+ break;
+ case OneofFieldOneofCase.OneofUint64:
+ OneofUint64 = other.OneofUint64;
+ break;
+ case OneofFieldOneofCase.OneofFloat:
+ OneofFloat = other.OneofFloat;
+ break;
+ case OneofFieldOneofCase.OneofDouble:
+ OneofDouble = other.OneofDouble;
+ break;
+ case OneofFieldOneofCase.OneofEnum:
+ OneofEnum = other.OneofEnum;
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ OptionalInt32 = input.ReadInt32();
+ break;
+ }
+ case 16: {
+ OptionalInt64 = input.ReadInt64();
+ break;
+ }
+ case 24: {
+ OptionalUint32 = input.ReadUInt32();
+ break;
+ }
+ case 32: {
+ OptionalUint64 = input.ReadUInt64();
+ break;
+ }
+ case 40: {
+ OptionalSint32 = input.ReadSInt32();
+ break;
+ }
+ case 48: {
+ OptionalSint64 = input.ReadSInt64();
+ break;
+ }
+ case 61: {
+ OptionalFixed32 = input.ReadFixed32();
+ break;
+ }
+ case 65: {
+ OptionalFixed64 = input.ReadFixed64();
+ break;
+ }
+ case 77: {
+ OptionalSfixed32 = input.ReadSFixed32();
+ break;
+ }
+ case 81: {
+ OptionalSfixed64 = input.ReadSFixed64();
+ break;
+ }
+ case 93: {
+ OptionalFloat = input.ReadFloat();
+ break;
+ }
+ case 97: {
+ OptionalDouble = input.ReadDouble();
+ break;
+ }
+ case 104: {
+ OptionalBool = input.ReadBool();
+ break;
+ }
+ case 114: {
+ OptionalString = input.ReadString();
+ break;
+ }
+ case 122: {
+ OptionalBytes = input.ReadBytes();
+ break;
+ }
+ case 146: {
+ if (optionalNestedMessage_ == null) {
+ optionalNestedMessage_ = new global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage();
+ }
+ input.ReadMessage(optionalNestedMessage_);
+ break;
+ }
+ case 154: {
+ if (optionalForeignMessage_ == null) {
+ optionalForeignMessage_ = new global::ProtobufTestMessages.Proto3.ForeignMessage();
+ }
+ input.ReadMessage(optionalForeignMessage_);
+ break;
+ }
+ case 168: {
+ optionalNestedEnum_ = (global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedEnum) input.ReadEnum();
+ break;
+ }
+ case 176: {
+ optionalForeignEnum_ = (global::ProtobufTestMessages.Proto3.ForeignEnum) input.ReadEnum();
+ break;
+ }
+ case 194: {
+ OptionalStringPiece = input.ReadString();
+ break;
+ }
+ case 202: {
+ OptionalCord = input.ReadString();
+ break;
+ }
+ case 218: {
+ if (recursiveMessage_ == null) {
+ recursiveMessage_ = new global::ProtobufTestMessages.Proto3.TestAllTypes();
+ }
+ input.ReadMessage(recursiveMessage_);
+ break;
+ }
+ case 250:
+ case 248: {
+ repeatedInt32_.AddEntriesFrom(input, _repeated_repeatedInt32_codec);
+ break;
+ }
+ case 258:
+ case 256: {
+ repeatedInt64_.AddEntriesFrom(input, _repeated_repeatedInt64_codec);
+ break;
+ }
+ case 266:
+ case 264: {
+ repeatedUint32_.AddEntriesFrom(input, _repeated_repeatedUint32_codec);
+ break;
+ }
+ case 274:
+ case 272: {
+ repeatedUint64_.AddEntriesFrom(input, _repeated_repeatedUint64_codec);
+ break;
+ }
+ case 282:
+ case 280: {
+ repeatedSint32_.AddEntriesFrom(input, _repeated_repeatedSint32_codec);
+ break;
+ }
+ case 290:
+ case 288: {
+ repeatedSint64_.AddEntriesFrom(input, _repeated_repeatedSint64_codec);
+ break;
+ }
+ case 298:
+ case 301: {
+ repeatedFixed32_.AddEntriesFrom(input, _repeated_repeatedFixed32_codec);
+ break;
+ }
+ case 306:
+ case 305: {
+ repeatedFixed64_.AddEntriesFrom(input, _repeated_repeatedFixed64_codec);
+ break;
+ }
+ case 314:
+ case 317: {
+ repeatedSfixed32_.AddEntriesFrom(input, _repeated_repeatedSfixed32_codec);
+ break;
+ }
+ case 322:
+ case 321: {
+ repeatedSfixed64_.AddEntriesFrom(input, _repeated_repeatedSfixed64_codec);
+ break;
+ }
+ case 330:
+ case 333: {
+ repeatedFloat_.AddEntriesFrom(input, _repeated_repeatedFloat_codec);
+ break;
+ }
+ case 338:
+ case 337: {
+ repeatedDouble_.AddEntriesFrom(input, _repeated_repeatedDouble_codec);
+ break;
+ }
+ case 346:
+ case 344: {
+ repeatedBool_.AddEntriesFrom(input, _repeated_repeatedBool_codec);
+ break;
+ }
+ case 354: {
+ repeatedString_.AddEntriesFrom(input, _repeated_repeatedString_codec);
+ break;
+ }
+ case 362: {
+ repeatedBytes_.AddEntriesFrom(input, _repeated_repeatedBytes_codec);
+ break;
+ }
+ case 386: {
+ repeatedNestedMessage_.AddEntriesFrom(input, _repeated_repeatedNestedMessage_codec);
+ break;
+ }
+ case 394: {
+ repeatedForeignMessage_.AddEntriesFrom(input, _repeated_repeatedForeignMessage_codec);
+ break;
+ }
+ case 410:
+ case 408: {
+ repeatedNestedEnum_.AddEntriesFrom(input, _repeated_repeatedNestedEnum_codec);
+ break;
+ }
+ case 418:
+ case 416: {
+ repeatedForeignEnum_.AddEntriesFrom(input, _repeated_repeatedForeignEnum_codec);
+ break;
+ }
+ case 434: {
+ repeatedStringPiece_.AddEntriesFrom(input, _repeated_repeatedStringPiece_codec);
+ break;
+ }
+ case 442: {
+ repeatedCord_.AddEntriesFrom(input, _repeated_repeatedCord_codec);
+ break;
+ }
+ case 450: {
+ mapInt32Int32_.AddEntriesFrom(input, _map_mapInt32Int32_codec);
+ break;
+ }
+ case 458: {
+ mapInt64Int64_.AddEntriesFrom(input, _map_mapInt64Int64_codec);
+ break;
+ }
+ case 466: {
+ mapUint32Uint32_.AddEntriesFrom(input, _map_mapUint32Uint32_codec);
+ break;
+ }
+ case 474: {
+ mapUint64Uint64_.AddEntriesFrom(input, _map_mapUint64Uint64_codec);
+ break;
+ }
+ case 482: {
+ mapSint32Sint32_.AddEntriesFrom(input, _map_mapSint32Sint32_codec);
+ break;
+ }
+ case 490: {
+ mapSint64Sint64_.AddEntriesFrom(input, _map_mapSint64Sint64_codec);
+ break;
+ }
+ case 498: {
+ mapFixed32Fixed32_.AddEntriesFrom(input, _map_mapFixed32Fixed32_codec);
+ break;
+ }
+ case 506: {
+ mapFixed64Fixed64_.AddEntriesFrom(input, _map_mapFixed64Fixed64_codec);
+ break;
+ }
+ case 514: {
+ mapSfixed32Sfixed32_.AddEntriesFrom(input, _map_mapSfixed32Sfixed32_codec);
+ break;
+ }
+ case 522: {
+ mapSfixed64Sfixed64_.AddEntriesFrom(input, _map_mapSfixed64Sfixed64_codec);
+ break;
+ }
+ case 530: {
+ mapInt32Float_.AddEntriesFrom(input, _map_mapInt32Float_codec);
+ break;
+ }
+ case 538: {
+ mapInt32Double_.AddEntriesFrom(input, _map_mapInt32Double_codec);
+ break;
+ }
+ case 546: {
+ mapBoolBool_.AddEntriesFrom(input, _map_mapBoolBool_codec);
+ break;
+ }
+ case 554: {
+ mapStringString_.AddEntriesFrom(input, _map_mapStringString_codec);
+ break;
+ }
+ case 562: {
+ mapStringBytes_.AddEntriesFrom(input, _map_mapStringBytes_codec);
+ break;
+ }
+ case 570: {
+ mapStringNestedMessage_.AddEntriesFrom(input, _map_mapStringNestedMessage_codec);
+ break;
+ }
+ case 578: {
+ mapStringForeignMessage_.AddEntriesFrom(input, _map_mapStringForeignMessage_codec);
+ break;
+ }
+ case 586: {
+ mapStringNestedEnum_.AddEntriesFrom(input, _map_mapStringNestedEnum_codec);
+ break;
+ }
+ case 594: {
+ mapStringForeignEnum_.AddEntriesFrom(input, _map_mapStringForeignEnum_codec);
+ break;
+ }
+ case 888: {
+ OneofUint32 = input.ReadUInt32();
+ break;
+ }
+ case 898: {
+ global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage subBuilder = new global::ProtobufTestMessages.Proto3.TestAllTypes.Types.NestedMessage();
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) {
+ subBuilder.MergeFrom(OneofNestedMessage);
+ }
+ input.ReadMessage(subBuilder);
+ OneofNestedMessage = subBuilder;
+ break;
+ }
+ case 906: {
+ OneofString = input.ReadString();
+ break;
+ }
+ case 914: {
+ OneofBytes = input.ReadBytes();
+ break;
+ }
+ case 920: {
+ OneofBool = input.ReadBool();
+ break;
+ }
+ case 928: {
+ OneofUint64 = input.ReadUInt64();
+ break;
+ }
+ case 941: {
+ OneofFloat = input.ReadFloat();
+ break;
+ }
+ case 945: {
+ OneofDouble = input.ReadDouble();
+ break;
+ }
+ case 952: {
+ oneofField_ = input.ReadEnum();
+ oneofFieldCase_ = OneofFieldOneofCase.OneofEnum;
+ break;
+ }
+ case 1610: {
+ bool? value = _single_optionalBoolWrapper_codec.Read(input);
+ if (optionalBoolWrapper_ == null || value != false) {
+ OptionalBoolWrapper = value;
+ }
+ break;
+ }
+ case 1618: {
+ int? value = _single_optionalInt32Wrapper_codec.Read(input);
+ if (optionalInt32Wrapper_ == null || value != 0) {
+ OptionalInt32Wrapper = value;
+ }
+ break;
+ }
+ case 1626: {
+ long? value = _single_optionalInt64Wrapper_codec.Read(input);
+ if (optionalInt64Wrapper_ == null || value != 0L) {
+ OptionalInt64Wrapper = value;
+ }
+ break;
+ }
+ case 1634: {
+ uint? value = _single_optionalUint32Wrapper_codec.Read(input);
+ if (optionalUint32Wrapper_ == null || value != 0) {
+ OptionalUint32Wrapper = value;
+ }
+ break;
+ }
+ case 1642: {
+ ulong? value = _single_optionalUint64Wrapper_codec.Read(input);
+ if (optionalUint64Wrapper_ == null || value != 0UL) {
+ OptionalUint64Wrapper = value;
+ }
+ break;
+ }
+ case 1650: {
+ float? value = _single_optionalFloatWrapper_codec.Read(input);
+ if (optionalFloatWrapper_ == null || value != 0F) {
+ OptionalFloatWrapper = value;
+ }
+ break;
+ }
+ case 1658: {
+ double? value = _single_optionalDoubleWrapper_codec.Read(input);
+ if (optionalDoubleWrapper_ == null || value != 0D) {
+ OptionalDoubleWrapper = value;
+ }
+ break;
+ }
+ case 1666: {
+ string value = _single_optionalStringWrapper_codec.Read(input);
+ if (optionalStringWrapper_ == null || value != "") {
+ OptionalStringWrapper = value;
+ }
+ break;
+ }
+ case 1674: {
+ pb::ByteString value = _single_optionalBytesWrapper_codec.Read(input);
+ if (optionalBytesWrapper_ == null || value != pb::ByteString.Empty) {
+ OptionalBytesWrapper = value;
+ }
+ break;
+ }
+ case 1690: {
+ repeatedBoolWrapper_.AddEntriesFrom(input, _repeated_repeatedBoolWrapper_codec);
+ break;
+ }
+ case 1698: {
+ repeatedInt32Wrapper_.AddEntriesFrom(input, _repeated_repeatedInt32Wrapper_codec);
+ break;
+ }
+ case 1706: {
+ repeatedInt64Wrapper_.AddEntriesFrom(input, _repeated_repeatedInt64Wrapper_codec);
+ break;
+ }
+ case 1714: {
+ repeatedUint32Wrapper_.AddEntriesFrom(input, _repeated_repeatedUint32Wrapper_codec);
+ break;
+ }
+ case 1722: {
+ repeatedUint64Wrapper_.AddEntriesFrom(input, _repeated_repeatedUint64Wrapper_codec);
+ break;
+ }
+ case 1730: {
+ repeatedFloatWrapper_.AddEntriesFrom(input, _repeated_repeatedFloatWrapper_codec);
+ break;
+ }
+ case 1738: {
+ repeatedDoubleWrapper_.AddEntriesFrom(input, _repeated_repeatedDoubleWrapper_codec);
+ break;
+ }
+ case 1746: {
+ repeatedStringWrapper_.AddEntriesFrom(input, _repeated_repeatedStringWrapper_codec);
+ break;
+ }
+ case 1754: {
+ repeatedBytesWrapper_.AddEntriesFrom(input, _repeated_repeatedBytesWrapper_codec);
+ break;
+ }
+ case 2410: {
+ if (optionalDuration_ == null) {
+ optionalDuration_ = new global::Google.Protobuf.WellKnownTypes.Duration();
+ }
+ input.ReadMessage(optionalDuration_);
+ break;
+ }
+ case 2418: {
+ if (optionalTimestamp_ == null) {
+ optionalTimestamp_ = new global::Google.Protobuf.WellKnownTypes.Timestamp();
+ }
+ input.ReadMessage(optionalTimestamp_);
+ break;
+ }
+ case 2426: {
+ if (optionalFieldMask_ == null) {
+ optionalFieldMask_ = new global::Google.Protobuf.WellKnownTypes.FieldMask();
+ }
+ input.ReadMessage(optionalFieldMask_);
+ break;
+ }
+ case 2434: {
+ if (optionalStruct_ == null) {
+ optionalStruct_ = new global::Google.Protobuf.WellKnownTypes.Struct();
+ }
+ input.ReadMessage(optionalStruct_);
+ break;
+ }
+ case 2442: {
+ if (optionalAny_ == null) {
+ optionalAny_ = new global::Google.Protobuf.WellKnownTypes.Any();
+ }
+ input.ReadMessage(optionalAny_);
+ break;
+ }
+ case 2450: {
+ if (optionalValue_ == null) {
+ optionalValue_ = new global::Google.Protobuf.WellKnownTypes.Value();
+ }
+ input.ReadMessage(optionalValue_);
+ break;
+ }
+ case 2490: {
+ repeatedDuration_.AddEntriesFrom(input, _repeated_repeatedDuration_codec);
+ break;
+ }
+ case 2498: {
+ repeatedTimestamp_.AddEntriesFrom(input, _repeated_repeatedTimestamp_codec);
+ break;
+ }
+ case 2506: {
+ repeatedFieldmask_.AddEntriesFrom(input, _repeated_repeatedFieldmask_codec);
+ break;
+ }
+ case 2522: {
+ repeatedAny_.AddEntriesFrom(input, _repeated_repeatedAny_codec);
+ break;
+ }
+ case 2530: {
+ repeatedValue_.AddEntriesFrom(input, _repeated_repeatedValue_codec);
+ break;
+ }
+ case 2594: {
+ repeatedStruct_.AddEntriesFrom(input, _repeated_repeatedStruct_codec);
+ break;
+ }
+ case 3208: {
+ Fieldname1 = input.ReadInt32();
+ break;
+ }
+ case 3216: {
+ FieldName2 = input.ReadInt32();
+ break;
+ }
+ case 3224: {
+ FieldName3 = input.ReadInt32();
+ break;
+ }
+ case 3232: {
+ FieldName4 = input.ReadInt32();
+ break;
+ }
+ case 3240: {
+ Field0Name5 = input.ReadInt32();
+ break;
+ }
+ case 3248: {
+ Field0Name6 = input.ReadInt32();
+ break;
+ }
+ case 3256: {
+ FieldName7 = input.ReadInt32();
+ break;
+ }
+ case 3264: {
+ FieldName8 = input.ReadInt32();
+ break;
+ }
+ case 3272: {
+ FieldName9 = input.ReadInt32();
+ break;
+ }
+ case 3280: {
+ FieldName10 = input.ReadInt32();
+ break;
+ }
+ case 3288: {
+ FIELDNAME11 = input.ReadInt32();
+ break;
+ }
+ case 3296: {
+ FIELDName12 = input.ReadInt32();
+ break;
+ }
+ case 3304: {
+ FieldName13 = input.ReadInt32();
+ break;
+ }
+ case 3312: {
+ FieldName14 = input.ReadInt32();
+ break;
+ }
+ case 3320: {
+ FieldName15 = input.ReadInt32();
+ break;
+ }
+ case 3328: {
+ FieldName16 = input.ReadInt32();
+ break;
+ }
+ case 3336: {
+ FieldName17 = input.ReadInt32();
+ break;
+ }
+ case 3344: {
+ FieldName18 = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the TestAllTypes message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ public enum NestedEnum {
+ [pbr::OriginalName("FOO")] Foo = 0,
+ [pbr::OriginalName("BAR")] Bar = 1,
+ [pbr::OriginalName("BAZ")] Baz = 2,
+ /// <summary>
+ /// Intentionally negative.
+ /// </summary>
+ [pbr::OriginalName("NEG")] Neg = -1,
+ }
+
+ public sealed partial class NestedMessage : pb::IMessage<NestedMessage> {
+ private static readonly pb::MessageParser<NestedMessage> _parser = new pb::MessageParser<NestedMessage>(() => new NestedMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<NestedMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::ProtobufTestMessages.Proto3.TestAllTypes.Descriptor.NestedTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedMessage(NestedMessage other) : this() {
+ a_ = other.a_;
+ Corecursive = other.corecursive_ != null ? other.Corecursive.Clone() : null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedMessage Clone() {
+ return new NestedMessage(this);
+ }
+
+ /// <summary>Field number for the "a" field.</summary>
+ public const int AFieldNumber = 1;
+ private int a_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int A {
+ get { return a_; }
+ set {
+ a_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "corecursive" field.</summary>
+ public const int CorecursiveFieldNumber = 2;
+ private global::ProtobufTestMessages.Proto3.TestAllTypes corecursive_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::ProtobufTestMessages.Proto3.TestAllTypes Corecursive {
+ get { return corecursive_; }
+ set {
+ corecursive_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as NestedMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(NestedMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (A != other.A) return false;
+ if (!object.Equals(Corecursive, other.Corecursive)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (A != 0) hash ^= A.GetHashCode();
+ if (corecursive_ != null) hash ^= Corecursive.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (A != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(A);
+ }
+ if (corecursive_ != null) {
+ output.WriteRawTag(18);
+ output.WriteMessage(Corecursive);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (A != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(A);
+ }
+ if (corecursive_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(Corecursive);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(NestedMessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.A != 0) {
+ A = other.A;
+ }
+ if (other.corecursive_ != null) {
+ if (corecursive_ == null) {
+ corecursive_ = new global::ProtobufTestMessages.Proto3.TestAllTypes();
+ }
+ Corecursive.MergeFrom(other.Corecursive);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ A = input.ReadInt32();
+ break;
+ }
+ case 18: {
+ if (corecursive_ == null) {
+ corecursive_ = new global::ProtobufTestMessages.Proto3.TestAllTypes();
+ }
+ input.ReadMessage(corecursive_);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ }
+ #endregion
+
+ }
+
+ public sealed partial class ForeignMessage : pb::IMessage<ForeignMessage> {
+ private static readonly pb::MessageParser<ForeignMessage> _parser = new pb::MessageParser<ForeignMessage>(() => new ForeignMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<ForeignMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::ProtobufTestMessages.Proto3.TestMessagesProto3Reflection.Descriptor.MessageTypes[1]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ForeignMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ForeignMessage(ForeignMessage other) : this() {
+ c_ = other.c_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ForeignMessage Clone() {
+ return new ForeignMessage(this);
+ }
+
+ /// <summary>Field number for the "c" field.</summary>
+ public const int CFieldNumber = 1;
+ private int c_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int C {
+ get { return c_; }
+ set {
+ c_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as ForeignMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(ForeignMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (C != other.C) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (C != 0) hash ^= C.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (C != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(C);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (C != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(C);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(ForeignMessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.C != 0) {
+ C = other.C;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ C = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs
new file mode 100644
index 0000000000..e21ede9c54
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestCustomOptionsProto3.cs
@@ -0,0 +1,2625 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: unittest_custom_options_proto3.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace UnitTest.Issues.TestProtos {
+
+ /// <summary>Holder for reflection information generated from unittest_custom_options_proto3.proto</summary>
+ public static partial class UnittestCustomOptionsProto3Reflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for unittest_custom_options_proto3.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static UnittestCustomOptionsProto3Reflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "CiR1bml0dGVzdF9jdXN0b21fb3B0aW9uc19wcm90bzMucHJvdG8SEXByb3Rv",
+ "YnVmX3VuaXR0ZXN0GiBnb29nbGUvcHJvdG9idWYvZGVzY3JpcHRvci5wcm90",
+ "byLXAQocVGVzdE1lc3NhZ2VXaXRoQ3VzdG9tT3B0aW9ucxIeCgZmaWVsZDEY",
+ "ASABKAlCDggBweDDHS3hdQoCAAAAEhUKC29uZW9mX2ZpZWxkGAIgASgFSAAi",
+ "UwoGQW5FbnVtEhYKEkFORU5VTV9VTlNQRUNJRklFRBAAEg8KC0FORU5VTV9W",
+ "QUwxEAESFgoLQU5FTlVNX1ZBTDIQAhoFsIb6BXsaCMX2yR3r/P//OhAIAODp",
+ "wh3I//////////8BQhkKB0FuT25lb2YSDviswx2d//////////8BIhgKFkN1",
+ "c3RvbU9wdGlvbkZvb1JlcXVlc3QiGQoXQ3VzdG9tT3B0aW9uRm9vUmVzcG9u",
+ "c2UiHgocQ3VzdG9tT3B0aW9uRm9vQ2xpZW50TWVzc2FnZSIeChxDdXN0b21P",
+ "cHRpb25Gb29TZXJ2ZXJNZXNzYWdlIo8BChpEdW1teU1lc3NhZ2VDb250YWlu",
+ "aW5nRW51bSJxCgxUZXN0RW51bVR5cGUSIAocVEVTVF9PUFRJT05fRU5VTV9V",
+ "TlNQRUNJRklFRBAAEhoKFlRFU1RfT1BUSU9OX0VOVU1fVFlQRTEQFhIjChZU",
+ "RVNUX09QVElPTl9FTlVNX1RZUEUyEOn//////////wEiIQofRHVtbXlNZXNz",
+ "YWdlSW52YWxpZEFzT3B0aW9uVHlwZSKKAQocQ3VzdG9tT3B0aW9uTWluSW50",
+ "ZWdlclZhbHVlczpq0N6yHQDoxrIdgICAgPj/////AbC8sh2AgICAgICAgIAB",
+ "gJOyHQD49bAdAIDEsB3/////D/iXsB3///////////8BnfWvHQAAAACR7q8d",
+ "AAAAAAAAAACtja8dAAAAgJnWqB0AAAAAAAAAgCKRAQocQ3VzdG9tT3B0aW9u",
+ "TWF4SW50ZWdlclZhbHVlczpx0N6yHQHoxrId/////wewvLId//////////9/",
+ "gJOyHf////8P+PWwHf///////////wGAxLAd/v///w/4l7Ad/v//////////",
+ "AZ31rx3/////ke6vHf//////////rY2vHf///3+Z1qgd/////////38ibgoX",
+ "Q3VzdG9tT3B0aW9uT3RoZXJWYWx1ZXM6U+jGsh2c//////////8B9d+jHeeH",
+ "RUHp3KId+1mMQsrA8z+q3KIdDkhlbGxvLCAiV29ybGQistmiHQtIZWxsbwBX",
+ "b3JsZIjZoh3p//////////8BIjQKHFNldHRpbmdSZWFsc0Zyb21Qb3NpdGl2",
+ "ZUludHM6FPXfox0AAEBB6dyiHQAAAAAAQGNAIjQKHFNldHRpbmdSZWFsc0Zy",
+ "b21OZWdhdGl2ZUludHM6FPXfox0AAEDB6dyiHQAAAAAAQGPAIksKEkNvbXBs",
+ "ZXhPcHRpb25UeXBlMRILCgNmb28YASABKAUSDAoEZm9vMhgCIAEoBRIMCgRm",
+ "b28zGAMgASgFEgwKBGZvbzQYBCADKAUigQMKEkNvbXBsZXhPcHRpb25UeXBl",
+ "MhIyCgNiYXIYASABKAsyJS5wcm90b2J1Zl91bml0dGVzdC5Db21wbGV4T3B0",
+ "aW9uVHlwZTESCwoDYmF6GAIgASgFEkYKBGZyZWQYAyABKAsyOC5wcm90b2J1",
+ "Zl91bml0dGVzdC5Db21wbGV4T3B0aW9uVHlwZTIuQ29tcGxleE9wdGlvblR5",
+ "cGU0EkgKBmJhcm5leRgEIAMoCzI4LnByb3RvYnVmX3VuaXR0ZXN0LkNvbXBs",
+ "ZXhPcHRpb25UeXBlMi5Db21wbGV4T3B0aW9uVHlwZTQalwEKEkNvbXBsZXhP",
+ "cHRpb25UeXBlNBINCgV3YWxkbxgBIAEoBTJyCgxjb21wbGV4X29wdDQSHy5n",
+ "b29nbGUucHJvdG9idWYuTWVzc2FnZU9wdGlvbnMYivXRAyABKAsyOC5wcm90",
+ "b2J1Zl91bml0dGVzdC5Db21wbGV4T3B0aW9uVHlwZTIuQ29tcGxleE9wdGlv",
+ "blR5cGU0IiEKEkNvbXBsZXhPcHRpb25UeXBlMxILCgNxdXgYASABKAUibAoV",
+ "VmFyaW91c0NvbXBsZXhPcHRpb25zOlOi4pUdAggqouKVHQIgY6LilR0CIFiq",
+ "/ZAdAxDbB6r9kB0FCgMI5wXSqI8dAwizD6r9kB0FGgMIwQKq/ZAdBCICCGWq",
+ "/ZAdBSIDCNQB+t6QHQIICSJMCglBZ2dyZWdhdGUSCQoBaRgBIAEoBRIJCgFz",
+ "GAIgASgJEikKA3N1YhgDIAEoCzIcLnByb3RvYnVmX3VuaXR0ZXN0LkFnZ3Jl",
+ "Z2F0ZSJZChBBZ2dyZWdhdGVNZXNzYWdlEikKCWZpZWxkbmFtZRgBIAEoBUIW",
+ "8qGHOxESD0ZpZWxkQW5ub3RhdGlvbjoawtGGOxUIZRIRTWVzc2FnZUFubm90",
+ "YXRpb24ilwEKEE5lc3RlZE9wdGlvblR5cGUaOwoNTmVzdGVkTWVzc2FnZRIi",
+ "CgxuZXN0ZWRfZmllbGQYASABKAVCDMHgwx3qAwAAAAAAADoG4OnCHekHIkYK",
+ "Ck5lc3RlZEVudW0SDwoLVU5TUEVDSUZJRUQQABIdChFORVNURURfRU5VTV9W",
+ "QUxVRRABGgawhvoF7AcaCMX2yR3rAwAAKlIKCk1ldGhvZE9wdDESGgoWTUVU",
+ "SE9ET1BUMV9VTlNQRUNJRklFRBAAEhMKD01FVEhPRE9QVDFfVkFMMRABEhMK",
+ "D01FVEhPRE9QVDFfVkFMMhACKl4KDUFnZ3JlZ2F0ZUVudW0SDwoLVU5TUEVD",
+ "SUZJRUQQABIlCgVWQUxVRRABGhrK/Ik7FRITRW51bVZhbHVlQW5ub3RhdGlv",
+ "bhoVkpWIOxASDkVudW1Bbm5vdGF0aW9uMo4BChxUZXN0U2VydmljZVdpdGhD",
+ "dXN0b21PcHRpb25zEmMKA0ZvbxIpLnByb3RvYnVmX3VuaXR0ZXN0LkN1c3Rv",
+ "bU9wdGlvbkZvb1JlcXVlc3QaKi5wcm90b2J1Zl91bml0dGVzdC5DdXN0b21P",
+ "cHRpb25Gb29SZXNwb25zZSIF4PqMHgIaCZCyix7T24DLSTKZAQoQQWdncmVn",
+ "YXRlU2VydmljZRJrCgZNZXRob2QSIy5wcm90b2J1Zl91bml0dGVzdC5BZ2dy",
+ "ZWdhdGVNZXNzYWdlGiMucHJvdG9idWZfdW5pdHRlc3QuQWdncmVnYXRlTWVz",
+ "c2FnZSIXysiWOxISEE1ldGhvZEFubm90YXRpb24aGMr7jjsTEhFTZXJ2aWNl",
+ "QW5ub3RhdGlvbjoyCglmaWxlX29wdDESHC5nb29nbGUucHJvdG9idWYuRmls",
+ "ZU9wdGlvbnMYjp3YAyABKAQ6OAoMbWVzc2FnZV9vcHQxEh8uZ29vZ2xlLnBy",
+ "b3RvYnVmLk1lc3NhZ2VPcHRpb25zGJyt2AMgASgFOjQKCmZpZWxkX29wdDES",
+ "HS5nb29nbGUucHJvdG9idWYuRmllbGRPcHRpb25zGIi82AMgASgGOjQKCm9u",
+ "ZW9mX29wdDESHS5nb29nbGUucHJvdG9idWYuT25lb2ZPcHRpb25zGM+12AMg",
+ "ASgFOjIKCWVudW1fb3B0MRIcLmdvb2dsZS5wcm90b2J1Zi5FbnVtT3B0aW9u",
+ "cxjontkDIAEoDzo8Cg9lbnVtX3ZhbHVlX29wdDESIS5nb29nbGUucHJvdG9i",
+ "dWYuRW51bVZhbHVlT3B0aW9ucxjmoF8gASgFOjgKDHNlcnZpY2Vfb3B0MRIf",
+ "Lmdvb2dsZS5wcm90b2J1Zi5TZXJ2aWNlT3B0aW9ucxiituEDIAEoEjpVCgtt",
+ "ZXRob2Rfb3B0MRIeLmdvb2dsZS5wcm90b2J1Zi5NZXRob2RPcHRpb25zGKzP",
+ "4QMgASgOMh0ucHJvdG9idWZfdW5pdHRlc3QuTWV0aG9kT3B0MTo0Cghib29s",
+ "X29wdBIfLmdvb2dsZS5wcm90b2J1Zi5NZXNzYWdlT3B0aW9ucxjqq9YDIAEo",
+ "CDo1CglpbnQzMl9vcHQSHy5nb29nbGUucHJvdG9idWYuTWVzc2FnZU9wdGlv",
+ "bnMY7ajWAyABKAU6NQoJaW50NjRfb3B0Eh8uZ29vZ2xlLnByb3RvYnVmLk1l",
+ "c3NhZ2VPcHRpb25zGMan1gMgASgDOjYKCnVpbnQzMl9vcHQSHy5nb29nbGUu",
+ "cHJvdG9idWYuTWVzc2FnZU9wdGlvbnMYsKLWAyABKA06NgoKdWludDY0X29w",
+ "dBIfLmdvb2dsZS5wcm90b2J1Zi5NZXNzYWdlT3B0aW9ucxjfjtYDIAEoBDo2",
+ "CgpzaW50MzJfb3B0Eh8uZ29vZ2xlLnByb3RvYnVmLk1lc3NhZ2VPcHRpb25z",
+ "GMCI1gMgASgROjYKCnNpbnQ2NF9vcHQSHy5nb29nbGUucHJvdG9idWYuTWVz",
+ "c2FnZU9wdGlvbnMY/4LWAyABKBI6NwoLZml4ZWQzMl9vcHQSHy5nb29nbGUu",
+ "cHJvdG9idWYuTWVzc2FnZU9wdGlvbnMY0/7VAyABKAc6NwoLZml4ZWQ2NF9v",
+ "cHQSHy5nb29nbGUucHJvdG9idWYuTWVzc2FnZU9wdGlvbnMY4v3VAyABKAY6",
+ "OAoMc2ZpeGVkMzJfb3B0Eh8uZ29vZ2xlLnByb3RvYnVmLk1lc3NhZ2VPcHRp",
+ "b25zGNXx1QMgASgPOjgKDHNmaXhlZDY0X29wdBIfLmdvb2dsZS5wcm90b2J1",
+ "Zi5NZXNzYWdlT3B0aW9ucxjjitUDIAEoEDo1CglmbG9hdF9vcHQSHy5nb29n",
+ "bGUucHJvdG9idWYuTWVzc2FnZU9wdGlvbnMY/rvUAyABKAI6NgoKZG91Ymxl",
+ "X29wdBIfLmdvb2dsZS5wcm90b2J1Zi5NZXNzYWdlT3B0aW9ucxjNq9QDIAEo",
+ "ATo2CgpzdHJpbmdfb3B0Eh8uZ29vZ2xlLnByb3RvYnVmLk1lc3NhZ2VPcHRp",
+ "b25zGMWr1AMgASgJOjUKCWJ5dGVzX29wdBIfLmdvb2dsZS5wcm90b2J1Zi5N",
+ "ZXNzYWdlT3B0aW9ucxiWq9QDIAEoDDpwCghlbnVtX29wdBIfLmdvb2dsZS5w",
+ "cm90b2J1Zi5NZXNzYWdlT3B0aW9ucxiRq9QDIAEoDjI6LnByb3RvYnVmX3Vu",
+ "aXR0ZXN0LkR1bW15TWVzc2FnZUNvbnRhaW5pbmdFbnVtLlRlc3RFbnVtVHlw",
+ "ZTpwChBtZXNzYWdlX3R5cGVfb3B0Eh8uZ29vZ2xlLnByb3RvYnVmLk1lc3Nh",
+ "Z2VPcHRpb25zGK/y0wMgASgLMjIucHJvdG9idWZfdW5pdHRlc3QuRHVtbXlN",
+ "ZXNzYWdlSW52YWxpZEFzT3B0aW9uVHlwZTpfCgxjb21wbGV4X29wdDESHy5n",
+ "b29nbGUucHJvdG9idWYuTWVzc2FnZU9wdGlvbnMYpNzSAyABKAsyJS5wcm90",
+ "b2J1Zl91bml0dGVzdC5Db21wbGV4T3B0aW9uVHlwZTE6XwoMY29tcGxleF9v",
+ "cHQyEh8uZ29vZ2xlLnByb3RvYnVmLk1lc3NhZ2VPcHRpb25zGNWP0gMgASgL",
+ "MiUucHJvdG9idWZfdW5pdHRlc3QuQ29tcGxleE9wdGlvblR5cGUyOl8KDGNv",
+ "bXBsZXhfb3B0MxIfLmdvb2dsZS5wcm90b2J1Zi5NZXNzYWdlT3B0aW9ucxjv",
+ "i9IDIAEoCzIlLnByb3RvYnVmX3VuaXR0ZXN0LkNvbXBsZXhPcHRpb25UeXBl",
+ "MzpOCgdmaWxlb3B0EhwuZ29vZ2xlLnByb3RvYnVmLkZpbGVPcHRpb25zGM/d",
+ "sAcgASgLMhwucHJvdG9idWZfdW5pdHRlc3QuQWdncmVnYXRlOlAKBm1zZ29w",
+ "dBIfLmdvb2dsZS5wcm90b2J1Zi5NZXNzYWdlT3B0aW9ucxiY6rAHIAEoCzIc",
+ "LnByb3RvYnVmX3VuaXR0ZXN0LkFnZ3JlZ2F0ZTpQCghmaWVsZG9wdBIdLmdv",
+ "b2dsZS5wcm90b2J1Zi5GaWVsZE9wdGlvbnMYnvSwByABKAsyHC5wcm90b2J1",
+ "Zl91bml0dGVzdC5BZ2dyZWdhdGU6TgoHZW51bW9wdBIcLmdvb2dsZS5wcm90",
+ "b2J1Zi5FbnVtT3B0aW9ucxjSgrEHIAEoCzIcLnByb3RvYnVmX3VuaXR0ZXN0",
+ "LkFnZ3JlZ2F0ZTpWCgplbnVtdmFsb3B0EiEuZ29vZ2xlLnByb3RvYnVmLkVu",
+ "dW1WYWx1ZU9wdGlvbnMYyZ+xByABKAsyHC5wcm90b2J1Zl91bml0dGVzdC5B",
+ "Z2dyZWdhdGU6VAoKc2VydmljZW9wdBIfLmdvb2dsZS5wcm90b2J1Zi5TZXJ2",
+ "aWNlT3B0aW9ucxi577EHIAEoCzIcLnByb3RvYnVmX3VuaXR0ZXN0LkFnZ3Jl",
+ "Z2F0ZTpSCgltZXRob2RvcHQSHi5nb29nbGUucHJvdG9idWYuTWV0aG9kT3B0",
+ "aW9ucxiJ6bIHIAEoCzIcLnByb3RvYnVmX3VuaXR0ZXN0LkFnZ3JlZ2F0ZUJV",
+ "qgIaVW5pdFRlc3QuSXNzdWVzLlRlc3RQcm90b3Pw6MEd6q3A5ST67IU7Kghk",
+ "Eg5GaWxlQW5ub3RhdGlvbhoWEhROZXN0ZWRGaWxlQW5ub3RhdGlvbmIGcHJv",
+ "dG8z"));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { pbr::FileDescriptor.DescriptorProtoFileDescriptor, },
+ new pbr::GeneratedClrTypeInfo(new[] {typeof(global::UnitTest.Issues.TestProtos.MethodOpt1), typeof(global::UnitTest.Issues.TestProtos.AggregateEnum), }, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.TestMessageWithCustomOptions), global::UnitTest.Issues.TestProtos.TestMessageWithCustomOptions.Parser, new[]{ "Field1", "OneofField" }, new[]{ "AnOneof" }, new[]{ typeof(global::UnitTest.Issues.TestProtos.TestMessageWithCustomOptions.Types.AnEnum) }, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.CustomOptionFooRequest), global::UnitTest.Issues.TestProtos.CustomOptionFooRequest.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.CustomOptionFooResponse), global::UnitTest.Issues.TestProtos.CustomOptionFooResponse.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.CustomOptionFooClientMessage), global::UnitTest.Issues.TestProtos.CustomOptionFooClientMessage.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.CustomOptionFooServerMessage), global::UnitTest.Issues.TestProtos.CustomOptionFooServerMessage.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.DummyMessageContainingEnum), global::UnitTest.Issues.TestProtos.DummyMessageContainingEnum.Parser, null, null, new[]{ typeof(global::UnitTest.Issues.TestProtos.DummyMessageContainingEnum.Types.TestEnumType) }, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.DummyMessageInvalidAsOptionType), global::UnitTest.Issues.TestProtos.DummyMessageInvalidAsOptionType.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.CustomOptionMinIntegerValues), global::UnitTest.Issues.TestProtos.CustomOptionMinIntegerValues.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.CustomOptionMaxIntegerValues), global::UnitTest.Issues.TestProtos.CustomOptionMaxIntegerValues.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.CustomOptionOtherValues), global::UnitTest.Issues.TestProtos.CustomOptionOtherValues.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.SettingRealsFromPositiveInts), global::UnitTest.Issues.TestProtos.SettingRealsFromPositiveInts.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.SettingRealsFromNegativeInts), global::UnitTest.Issues.TestProtos.SettingRealsFromNegativeInts.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.ComplexOptionType1), global::UnitTest.Issues.TestProtos.ComplexOptionType1.Parser, new[]{ "Foo", "Foo2", "Foo3", "Foo4" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.ComplexOptionType2), global::UnitTest.Issues.TestProtos.ComplexOptionType2.Parser, new[]{ "Bar", "Baz", "Fred", "Barney" }, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.ComplexOptionType2.Types.ComplexOptionType4), global::UnitTest.Issues.TestProtos.ComplexOptionType2.Types.ComplexOptionType4.Parser, new[]{ "Waldo" }, null, null, null)}),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.ComplexOptionType3), global::UnitTest.Issues.TestProtos.ComplexOptionType3.Parser, new[]{ "Qux" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.VariousComplexOptions), global::UnitTest.Issues.TestProtos.VariousComplexOptions.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.Aggregate), global::UnitTest.Issues.TestProtos.Aggregate.Parser, new[]{ "I", "S", "Sub" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.AggregateMessage), global::UnitTest.Issues.TestProtos.AggregateMessage.Parser, new[]{ "Fieldname" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.NestedOptionType), global::UnitTest.Issues.TestProtos.NestedOptionType.Parser, null, null, new[]{ typeof(global::UnitTest.Issues.TestProtos.NestedOptionType.Types.NestedEnum) }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.NestedOptionType.Types.NestedMessage), global::UnitTest.Issues.TestProtos.NestedOptionType.Types.NestedMessage.Parser, new[]{ "NestedField" }, null, null, null)})
+ }));
+ }
+ #endregion
+
+ }
+ #region Enums
+ public enum MethodOpt1 {
+ [pbr::OriginalName("METHODOPT1_UNSPECIFIED")] Unspecified = 0,
+ [pbr::OriginalName("METHODOPT1_VAL1")] Val1 = 1,
+ [pbr::OriginalName("METHODOPT1_VAL2")] Val2 = 2,
+ }
+
+ public enum AggregateEnum {
+ [pbr::OriginalName("UNSPECIFIED")] Unspecified = 0,
+ [pbr::OriginalName("VALUE")] Value = 1,
+ }
+
+ #endregion
+
+ #region Messages
+ /// <summary>
+ /// A test message with custom options at all possible locations (and also some
+ /// regular options, to make sure they interact nicely).
+ /// </summary>
+ public sealed partial class TestMessageWithCustomOptions : pb::IMessage<TestMessageWithCustomOptions> {
+ private static readonly pb::MessageParser<TestMessageWithCustomOptions> _parser = new pb::MessageParser<TestMessageWithCustomOptions>(() => new TestMessageWithCustomOptions());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestMessageWithCustomOptions> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMessageWithCustomOptions() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMessageWithCustomOptions(TestMessageWithCustomOptions other) : this() {
+ field1_ = other.field1_;
+ switch (other.AnOneofCase) {
+ case AnOneofOneofCase.OneofField:
+ OneofField = other.OneofField;
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMessageWithCustomOptions Clone() {
+ return new TestMessageWithCustomOptions(this);
+ }
+
+ /// <summary>Field number for the "field1" field.</summary>
+ public const int Field1FieldNumber = 1;
+ private string field1_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Field1 {
+ get { return field1_; }
+ set {
+ field1_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "oneof_field" field.</summary>
+ public const int OneofFieldFieldNumber = 2;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int OneofField {
+ get { return anOneofCase_ == AnOneofOneofCase.OneofField ? (int) anOneof_ : 0; }
+ set {
+ anOneof_ = value;
+ anOneofCase_ = AnOneofOneofCase.OneofField;
+ }
+ }
+
+ private object anOneof_;
+ /// <summary>Enum of possible cases for the "AnOneof" oneof.</summary>
+ public enum AnOneofOneofCase {
+ None = 0,
+ OneofField = 2,
+ }
+ private AnOneofOneofCase anOneofCase_ = AnOneofOneofCase.None;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public AnOneofOneofCase AnOneofCase {
+ get { return anOneofCase_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearAnOneof() {
+ anOneofCase_ = AnOneofOneofCase.None;
+ anOneof_ = null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestMessageWithCustomOptions);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestMessageWithCustomOptions other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Field1 != other.Field1) return false;
+ if (OneofField != other.OneofField) return false;
+ if (AnOneofCase != other.AnOneofCase) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Field1.Length != 0) hash ^= Field1.GetHashCode();
+ if (anOneofCase_ == AnOneofOneofCase.OneofField) hash ^= OneofField.GetHashCode();
+ hash ^= (int) anOneofCase_;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Field1.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Field1);
+ }
+ if (anOneofCase_ == AnOneofOneofCase.OneofField) {
+ output.WriteRawTag(16);
+ output.WriteInt32(OneofField);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Field1.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Field1);
+ }
+ if (anOneofCase_ == AnOneofOneofCase.OneofField) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(OneofField);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestMessageWithCustomOptions other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Field1.Length != 0) {
+ Field1 = other.Field1;
+ }
+ switch (other.AnOneofCase) {
+ case AnOneofOneofCase.OneofField:
+ OneofField = other.OneofField;
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Field1 = input.ReadString();
+ break;
+ }
+ case 16: {
+ OneofField = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the TestMessageWithCustomOptions message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ public enum AnEnum {
+ [pbr::OriginalName("ANENUM_UNSPECIFIED")] Unspecified = 0,
+ [pbr::OriginalName("ANENUM_VAL1")] Val1 = 1,
+ [pbr::OriginalName("ANENUM_VAL2")] Val2 = 2,
+ }
+
+ }
+ #endregion
+
+ }
+
+ /// <summary>
+ /// A test RPC service with custom options at all possible locations (and also
+ /// some regular options, to make sure they interact nicely).
+ /// </summary>
+ public sealed partial class CustomOptionFooRequest : pb::IMessage<CustomOptionFooRequest> {
+ private static readonly pb::MessageParser<CustomOptionFooRequest> _parser = new pb::MessageParser<CustomOptionFooRequest>(() => new CustomOptionFooRequest());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<CustomOptionFooRequest> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[1]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionFooRequest() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionFooRequest(CustomOptionFooRequest other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionFooRequest Clone() {
+ return new CustomOptionFooRequest(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as CustomOptionFooRequest);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(CustomOptionFooRequest other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(CustomOptionFooRequest other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class CustomOptionFooResponse : pb::IMessage<CustomOptionFooResponse> {
+ private static readonly pb::MessageParser<CustomOptionFooResponse> _parser = new pb::MessageParser<CustomOptionFooResponse>(() => new CustomOptionFooResponse());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<CustomOptionFooResponse> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[2]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionFooResponse() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionFooResponse(CustomOptionFooResponse other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionFooResponse Clone() {
+ return new CustomOptionFooResponse(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as CustomOptionFooResponse);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(CustomOptionFooResponse other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(CustomOptionFooResponse other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class CustomOptionFooClientMessage : pb::IMessage<CustomOptionFooClientMessage> {
+ private static readonly pb::MessageParser<CustomOptionFooClientMessage> _parser = new pb::MessageParser<CustomOptionFooClientMessage>(() => new CustomOptionFooClientMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<CustomOptionFooClientMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[3]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionFooClientMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionFooClientMessage(CustomOptionFooClientMessage other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionFooClientMessage Clone() {
+ return new CustomOptionFooClientMessage(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as CustomOptionFooClientMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(CustomOptionFooClientMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(CustomOptionFooClientMessage other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class CustomOptionFooServerMessage : pb::IMessage<CustomOptionFooServerMessage> {
+ private static readonly pb::MessageParser<CustomOptionFooServerMessage> _parser = new pb::MessageParser<CustomOptionFooServerMessage>(() => new CustomOptionFooServerMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<CustomOptionFooServerMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[4]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionFooServerMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionFooServerMessage(CustomOptionFooServerMessage other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionFooServerMessage Clone() {
+ return new CustomOptionFooServerMessage(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as CustomOptionFooServerMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(CustomOptionFooServerMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(CustomOptionFooServerMessage other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class DummyMessageContainingEnum : pb::IMessage<DummyMessageContainingEnum> {
+ private static readonly pb::MessageParser<DummyMessageContainingEnum> _parser = new pb::MessageParser<DummyMessageContainingEnum>(() => new DummyMessageContainingEnum());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<DummyMessageContainingEnum> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[5]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DummyMessageContainingEnum() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DummyMessageContainingEnum(DummyMessageContainingEnum other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DummyMessageContainingEnum Clone() {
+ return new DummyMessageContainingEnum(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as DummyMessageContainingEnum);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(DummyMessageContainingEnum other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(DummyMessageContainingEnum other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the DummyMessageContainingEnum message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ public enum TestEnumType {
+ [pbr::OriginalName("TEST_OPTION_ENUM_UNSPECIFIED")] TestOptionEnumUnspecified = 0,
+ [pbr::OriginalName("TEST_OPTION_ENUM_TYPE1")] TestOptionEnumType1 = 22,
+ [pbr::OriginalName("TEST_OPTION_ENUM_TYPE2")] TestOptionEnumType2 = -23,
+ }
+
+ }
+ #endregion
+
+ }
+
+ public sealed partial class DummyMessageInvalidAsOptionType : pb::IMessage<DummyMessageInvalidAsOptionType> {
+ private static readonly pb::MessageParser<DummyMessageInvalidAsOptionType> _parser = new pb::MessageParser<DummyMessageInvalidAsOptionType>(() => new DummyMessageInvalidAsOptionType());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<DummyMessageInvalidAsOptionType> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[6]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DummyMessageInvalidAsOptionType() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DummyMessageInvalidAsOptionType(DummyMessageInvalidAsOptionType other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DummyMessageInvalidAsOptionType Clone() {
+ return new DummyMessageInvalidAsOptionType(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as DummyMessageInvalidAsOptionType);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(DummyMessageInvalidAsOptionType other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(DummyMessageInvalidAsOptionType other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class CustomOptionMinIntegerValues : pb::IMessage<CustomOptionMinIntegerValues> {
+ private static readonly pb::MessageParser<CustomOptionMinIntegerValues> _parser = new pb::MessageParser<CustomOptionMinIntegerValues>(() => new CustomOptionMinIntegerValues());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<CustomOptionMinIntegerValues> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[7]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionMinIntegerValues() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionMinIntegerValues(CustomOptionMinIntegerValues other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionMinIntegerValues Clone() {
+ return new CustomOptionMinIntegerValues(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as CustomOptionMinIntegerValues);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(CustomOptionMinIntegerValues other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(CustomOptionMinIntegerValues other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class CustomOptionMaxIntegerValues : pb::IMessage<CustomOptionMaxIntegerValues> {
+ private static readonly pb::MessageParser<CustomOptionMaxIntegerValues> _parser = new pb::MessageParser<CustomOptionMaxIntegerValues>(() => new CustomOptionMaxIntegerValues());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<CustomOptionMaxIntegerValues> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[8]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionMaxIntegerValues() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionMaxIntegerValues(CustomOptionMaxIntegerValues other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionMaxIntegerValues Clone() {
+ return new CustomOptionMaxIntegerValues(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as CustomOptionMaxIntegerValues);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(CustomOptionMaxIntegerValues other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(CustomOptionMaxIntegerValues other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class CustomOptionOtherValues : pb::IMessage<CustomOptionOtherValues> {
+ private static readonly pb::MessageParser<CustomOptionOtherValues> _parser = new pb::MessageParser<CustomOptionOtherValues>(() => new CustomOptionOtherValues());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<CustomOptionOtherValues> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[9]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionOtherValues() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionOtherValues(CustomOptionOtherValues other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public CustomOptionOtherValues Clone() {
+ return new CustomOptionOtherValues(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as CustomOptionOtherValues);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(CustomOptionOtherValues other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(CustomOptionOtherValues other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class SettingRealsFromPositiveInts : pb::IMessage<SettingRealsFromPositiveInts> {
+ private static readonly pb::MessageParser<SettingRealsFromPositiveInts> _parser = new pb::MessageParser<SettingRealsFromPositiveInts>(() => new SettingRealsFromPositiveInts());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<SettingRealsFromPositiveInts> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[10]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SettingRealsFromPositiveInts() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SettingRealsFromPositiveInts(SettingRealsFromPositiveInts other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SettingRealsFromPositiveInts Clone() {
+ return new SettingRealsFromPositiveInts(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as SettingRealsFromPositiveInts);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(SettingRealsFromPositiveInts other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(SettingRealsFromPositiveInts other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class SettingRealsFromNegativeInts : pb::IMessage<SettingRealsFromNegativeInts> {
+ private static readonly pb::MessageParser<SettingRealsFromNegativeInts> _parser = new pb::MessageParser<SettingRealsFromNegativeInts>(() => new SettingRealsFromNegativeInts());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<SettingRealsFromNegativeInts> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[11]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SettingRealsFromNegativeInts() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SettingRealsFromNegativeInts(SettingRealsFromNegativeInts other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SettingRealsFromNegativeInts Clone() {
+ return new SettingRealsFromNegativeInts(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as SettingRealsFromNegativeInts);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(SettingRealsFromNegativeInts other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(SettingRealsFromNegativeInts other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class ComplexOptionType1 : pb::IMessage<ComplexOptionType1> {
+ private static readonly pb::MessageParser<ComplexOptionType1> _parser = new pb::MessageParser<ComplexOptionType1>(() => new ComplexOptionType1());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<ComplexOptionType1> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[12]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ComplexOptionType1() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ComplexOptionType1(ComplexOptionType1 other) : this() {
+ foo_ = other.foo_;
+ foo2_ = other.foo2_;
+ foo3_ = other.foo3_;
+ foo4_ = other.foo4_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ComplexOptionType1 Clone() {
+ return new ComplexOptionType1(this);
+ }
+
+ /// <summary>Field number for the "foo" field.</summary>
+ public const int FooFieldNumber = 1;
+ private int foo_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Foo {
+ get { return foo_; }
+ set {
+ foo_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "foo2" field.</summary>
+ public const int Foo2FieldNumber = 2;
+ private int foo2_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Foo2 {
+ get { return foo2_; }
+ set {
+ foo2_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "foo3" field.</summary>
+ public const int Foo3FieldNumber = 3;
+ private int foo3_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Foo3 {
+ get { return foo3_; }
+ set {
+ foo3_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "foo4" field.</summary>
+ public const int Foo4FieldNumber = 4;
+ private static readonly pb::FieldCodec<int> _repeated_foo4_codec
+ = pb::FieldCodec.ForInt32(34);
+ private readonly pbc::RepeatedField<int> foo4_ = new pbc::RepeatedField<int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> Foo4 {
+ get { return foo4_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as ComplexOptionType1);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(ComplexOptionType1 other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Foo != other.Foo) return false;
+ if (Foo2 != other.Foo2) return false;
+ if (Foo3 != other.Foo3) return false;
+ if(!foo4_.Equals(other.foo4_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Foo != 0) hash ^= Foo.GetHashCode();
+ if (Foo2 != 0) hash ^= Foo2.GetHashCode();
+ if (Foo3 != 0) hash ^= Foo3.GetHashCode();
+ hash ^= foo4_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Foo != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(Foo);
+ }
+ if (Foo2 != 0) {
+ output.WriteRawTag(16);
+ output.WriteInt32(Foo2);
+ }
+ if (Foo3 != 0) {
+ output.WriteRawTag(24);
+ output.WriteInt32(Foo3);
+ }
+ foo4_.WriteTo(output, _repeated_foo4_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Foo != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Foo);
+ }
+ if (Foo2 != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Foo2);
+ }
+ if (Foo3 != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Foo3);
+ }
+ size += foo4_.CalculateSize(_repeated_foo4_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(ComplexOptionType1 other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Foo != 0) {
+ Foo = other.Foo;
+ }
+ if (other.Foo2 != 0) {
+ Foo2 = other.Foo2;
+ }
+ if (other.Foo3 != 0) {
+ Foo3 = other.Foo3;
+ }
+ foo4_.Add(other.foo4_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Foo = input.ReadInt32();
+ break;
+ }
+ case 16: {
+ Foo2 = input.ReadInt32();
+ break;
+ }
+ case 24: {
+ Foo3 = input.ReadInt32();
+ break;
+ }
+ case 34:
+ case 32: {
+ foo4_.AddEntriesFrom(input, _repeated_foo4_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class ComplexOptionType2 : pb::IMessage<ComplexOptionType2> {
+ private static readonly pb::MessageParser<ComplexOptionType2> _parser = new pb::MessageParser<ComplexOptionType2>(() => new ComplexOptionType2());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<ComplexOptionType2> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[13]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ComplexOptionType2() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ComplexOptionType2(ComplexOptionType2 other) : this() {
+ Bar = other.bar_ != null ? other.Bar.Clone() : null;
+ baz_ = other.baz_;
+ Fred = other.fred_ != null ? other.Fred.Clone() : null;
+ barney_ = other.barney_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ComplexOptionType2 Clone() {
+ return new ComplexOptionType2(this);
+ }
+
+ /// <summary>Field number for the "bar" field.</summary>
+ public const int BarFieldNumber = 1;
+ private global::UnitTest.Issues.TestProtos.ComplexOptionType1 bar_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::UnitTest.Issues.TestProtos.ComplexOptionType1 Bar {
+ get { return bar_; }
+ set {
+ bar_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "baz" field.</summary>
+ public const int BazFieldNumber = 2;
+ private int baz_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Baz {
+ get { return baz_; }
+ set {
+ baz_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "fred" field.</summary>
+ public const int FredFieldNumber = 3;
+ private global::UnitTest.Issues.TestProtos.ComplexOptionType2.Types.ComplexOptionType4 fred_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::UnitTest.Issues.TestProtos.ComplexOptionType2.Types.ComplexOptionType4 Fred {
+ get { return fred_; }
+ set {
+ fred_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "barney" field.</summary>
+ public const int BarneyFieldNumber = 4;
+ private static readonly pb::FieldCodec<global::UnitTest.Issues.TestProtos.ComplexOptionType2.Types.ComplexOptionType4> _repeated_barney_codec
+ = pb::FieldCodec.ForMessage(34, global::UnitTest.Issues.TestProtos.ComplexOptionType2.Types.ComplexOptionType4.Parser);
+ private readonly pbc::RepeatedField<global::UnitTest.Issues.TestProtos.ComplexOptionType2.Types.ComplexOptionType4> barney_ = new pbc::RepeatedField<global::UnitTest.Issues.TestProtos.ComplexOptionType2.Types.ComplexOptionType4>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::UnitTest.Issues.TestProtos.ComplexOptionType2.Types.ComplexOptionType4> Barney {
+ get { return barney_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as ComplexOptionType2);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(ComplexOptionType2 other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (!object.Equals(Bar, other.Bar)) return false;
+ if (Baz != other.Baz) return false;
+ if (!object.Equals(Fred, other.Fred)) return false;
+ if(!barney_.Equals(other.barney_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (bar_ != null) hash ^= Bar.GetHashCode();
+ if (Baz != 0) hash ^= Baz.GetHashCode();
+ if (fred_ != null) hash ^= Fred.GetHashCode();
+ hash ^= barney_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (bar_ != null) {
+ output.WriteRawTag(10);
+ output.WriteMessage(Bar);
+ }
+ if (Baz != 0) {
+ output.WriteRawTag(16);
+ output.WriteInt32(Baz);
+ }
+ if (fred_ != null) {
+ output.WriteRawTag(26);
+ output.WriteMessage(Fred);
+ }
+ barney_.WriteTo(output, _repeated_barney_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (bar_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(Bar);
+ }
+ if (Baz != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Baz);
+ }
+ if (fred_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(Fred);
+ }
+ size += barney_.CalculateSize(_repeated_barney_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(ComplexOptionType2 other) {
+ if (other == null) {
+ return;
+ }
+ if (other.bar_ != null) {
+ if (bar_ == null) {
+ bar_ = new global::UnitTest.Issues.TestProtos.ComplexOptionType1();
+ }
+ Bar.MergeFrom(other.Bar);
+ }
+ if (other.Baz != 0) {
+ Baz = other.Baz;
+ }
+ if (other.fred_ != null) {
+ if (fred_ == null) {
+ fred_ = new global::UnitTest.Issues.TestProtos.ComplexOptionType2.Types.ComplexOptionType4();
+ }
+ Fred.MergeFrom(other.Fred);
+ }
+ barney_.Add(other.barney_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ if (bar_ == null) {
+ bar_ = new global::UnitTest.Issues.TestProtos.ComplexOptionType1();
+ }
+ input.ReadMessage(bar_);
+ break;
+ }
+ case 16: {
+ Baz = input.ReadInt32();
+ break;
+ }
+ case 26: {
+ if (fred_ == null) {
+ fred_ = new global::UnitTest.Issues.TestProtos.ComplexOptionType2.Types.ComplexOptionType4();
+ }
+ input.ReadMessage(fred_);
+ break;
+ }
+ case 34: {
+ barney_.AddEntriesFrom(input, _repeated_barney_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the ComplexOptionType2 message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ public sealed partial class ComplexOptionType4 : pb::IMessage<ComplexOptionType4> {
+ private static readonly pb::MessageParser<ComplexOptionType4> _parser = new pb::MessageParser<ComplexOptionType4>(() => new ComplexOptionType4());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<ComplexOptionType4> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.ComplexOptionType2.Descriptor.NestedTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ComplexOptionType4() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ComplexOptionType4(ComplexOptionType4 other) : this() {
+ waldo_ = other.waldo_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ComplexOptionType4 Clone() {
+ return new ComplexOptionType4(this);
+ }
+
+ /// <summary>Field number for the "waldo" field.</summary>
+ public const int WaldoFieldNumber = 1;
+ private int waldo_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Waldo {
+ get { return waldo_; }
+ set {
+ waldo_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as ComplexOptionType4);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(ComplexOptionType4 other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Waldo != other.Waldo) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Waldo != 0) hash ^= Waldo.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Waldo != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(Waldo);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Waldo != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Waldo);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(ComplexOptionType4 other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Waldo != 0) {
+ Waldo = other.Waldo;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Waldo = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ }
+ #endregion
+
+ }
+
+ public sealed partial class ComplexOptionType3 : pb::IMessage<ComplexOptionType3> {
+ private static readonly pb::MessageParser<ComplexOptionType3> _parser = new pb::MessageParser<ComplexOptionType3>(() => new ComplexOptionType3());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<ComplexOptionType3> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[14]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ComplexOptionType3() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ComplexOptionType3(ComplexOptionType3 other) : this() {
+ qux_ = other.qux_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ComplexOptionType3 Clone() {
+ return new ComplexOptionType3(this);
+ }
+
+ /// <summary>Field number for the "qux" field.</summary>
+ public const int QuxFieldNumber = 1;
+ private int qux_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Qux {
+ get { return qux_; }
+ set {
+ qux_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as ComplexOptionType3);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(ComplexOptionType3 other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Qux != other.Qux) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Qux != 0) hash ^= Qux.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Qux != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(Qux);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Qux != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Qux);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(ComplexOptionType3 other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Qux != 0) {
+ Qux = other.Qux;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Qux = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Note that we try various different ways of naming the same extension.
+ /// </summary>
+ public sealed partial class VariousComplexOptions : pb::IMessage<VariousComplexOptions> {
+ private static readonly pb::MessageParser<VariousComplexOptions> _parser = new pb::MessageParser<VariousComplexOptions>(() => new VariousComplexOptions());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<VariousComplexOptions> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[15]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public VariousComplexOptions() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public VariousComplexOptions(VariousComplexOptions other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public VariousComplexOptions Clone() {
+ return new VariousComplexOptions(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as VariousComplexOptions);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(VariousComplexOptions other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(VariousComplexOptions other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// A helper type used to test aggregate option parsing
+ /// </summary>
+ public sealed partial class Aggregate : pb::IMessage<Aggregate> {
+ private static readonly pb::MessageParser<Aggregate> _parser = new pb::MessageParser<Aggregate>(() => new Aggregate());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Aggregate> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[16]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Aggregate() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Aggregate(Aggregate other) : this() {
+ i_ = other.i_;
+ s_ = other.s_;
+ Sub = other.sub_ != null ? other.Sub.Clone() : null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Aggregate Clone() {
+ return new Aggregate(this);
+ }
+
+ /// <summary>Field number for the "i" field.</summary>
+ public const int IFieldNumber = 1;
+ private int i_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int I {
+ get { return i_; }
+ set {
+ i_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "s" field.</summary>
+ public const int SFieldNumber = 2;
+ private string s_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string S {
+ get { return s_; }
+ set {
+ s_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "sub" field.</summary>
+ public const int SubFieldNumber = 3;
+ private global::UnitTest.Issues.TestProtos.Aggregate sub_;
+ /// <summary>
+ /// A nested object
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::UnitTest.Issues.TestProtos.Aggregate Sub {
+ get { return sub_; }
+ set {
+ sub_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Aggregate);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Aggregate other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (I != other.I) return false;
+ if (S != other.S) return false;
+ if (!object.Equals(Sub, other.Sub)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (I != 0) hash ^= I.GetHashCode();
+ if (S.Length != 0) hash ^= S.GetHashCode();
+ if (sub_ != null) hash ^= Sub.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (I != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(I);
+ }
+ if (S.Length != 0) {
+ output.WriteRawTag(18);
+ output.WriteString(S);
+ }
+ if (sub_ != null) {
+ output.WriteRawTag(26);
+ output.WriteMessage(Sub);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (I != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(I);
+ }
+ if (S.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(S);
+ }
+ if (sub_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(Sub);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Aggregate other) {
+ if (other == null) {
+ return;
+ }
+ if (other.I != 0) {
+ I = other.I;
+ }
+ if (other.S.Length != 0) {
+ S = other.S;
+ }
+ if (other.sub_ != null) {
+ if (sub_ == null) {
+ sub_ = new global::UnitTest.Issues.TestProtos.Aggregate();
+ }
+ Sub.MergeFrom(other.Sub);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ I = input.ReadInt32();
+ break;
+ }
+ case 18: {
+ S = input.ReadString();
+ break;
+ }
+ case 26: {
+ if (sub_ == null) {
+ sub_ = new global::UnitTest.Issues.TestProtos.Aggregate();
+ }
+ input.ReadMessage(sub_);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class AggregateMessage : pb::IMessage<AggregateMessage> {
+ private static readonly pb::MessageParser<AggregateMessage> _parser = new pb::MessageParser<AggregateMessage>(() => new AggregateMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<AggregateMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[17]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public AggregateMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public AggregateMessage(AggregateMessage other) : this() {
+ fieldname_ = other.fieldname_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public AggregateMessage Clone() {
+ return new AggregateMessage(this);
+ }
+
+ /// <summary>Field number for the "fieldname" field.</summary>
+ public const int FieldnameFieldNumber = 1;
+ private int fieldname_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Fieldname {
+ get { return fieldname_; }
+ set {
+ fieldname_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as AggregateMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(AggregateMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Fieldname != other.Fieldname) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Fieldname != 0) hash ^= Fieldname.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Fieldname != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(Fieldname);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Fieldname != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Fieldname);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(AggregateMessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Fieldname != 0) {
+ Fieldname = other.Fieldname;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Fieldname = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Test custom options for nested type.
+ /// </summary>
+ public sealed partial class NestedOptionType : pb::IMessage<NestedOptionType> {
+ private static readonly pb::MessageParser<NestedOptionType> _parser = new pb::MessageParser<NestedOptionType>(() => new NestedOptionType());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<NestedOptionType> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestCustomOptionsProto3Reflection.Descriptor.MessageTypes[18]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedOptionType() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedOptionType(NestedOptionType other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedOptionType Clone() {
+ return new NestedOptionType(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as NestedOptionType);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(NestedOptionType other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(NestedOptionType other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the NestedOptionType message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ public enum NestedEnum {
+ [pbr::OriginalName("UNSPECIFIED")] Unspecified = 0,
+ [pbr::OriginalName("NESTED_ENUM_VALUE")] Value = 1,
+ }
+
+ public sealed partial class NestedMessage : pb::IMessage<NestedMessage> {
+ private static readonly pb::MessageParser<NestedMessage> _parser = new pb::MessageParser<NestedMessage>(() => new NestedMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<NestedMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.NestedOptionType.Descriptor.NestedTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedMessage(NestedMessage other) : this() {
+ nestedField_ = other.nestedField_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedMessage Clone() {
+ return new NestedMessage(this);
+ }
+
+ /// <summary>Field number for the "nested_field" field.</summary>
+ public const int NestedFieldFieldNumber = 1;
+ private int nestedField_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int NestedField {
+ get { return nestedField_; }
+ set {
+ nestedField_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as NestedMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(NestedMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (NestedField != other.NestedField) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (NestedField != 0) hash ^= NestedField.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (NestedField != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(NestedField);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (NestedField != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(NestedField);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(NestedMessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.NestedField != 0) {
+ NestedField = other.NestedField;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ NestedField = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ }
+ #endregion
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs
new file mode 100644
index 0000000000..f6df4e8726
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportProto3.cs
@@ -0,0 +1,174 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/unittest_import_proto3.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.TestProtos {
+
+ /// <summary>Holder for reflection information generated from google/protobuf/unittest_import_proto3.proto</summary>
+ public static partial class UnittestImportProto3Reflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for google/protobuf/unittest_import_proto3.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static UnittestImportProto3Reflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "Cixnb29nbGUvcHJvdG9idWYvdW5pdHRlc3RfaW1wb3J0X3Byb3RvMy5wcm90",
+ "bxIYcHJvdG9idWZfdW5pdHRlc3RfaW1wb3J0GjNnb29nbGUvcHJvdG9idWYv",
+ "dW5pdHRlc3RfaW1wb3J0X3B1YmxpY19wcm90bzMucHJvdG8iGgoNSW1wb3J0",
+ "TWVzc2FnZRIJCgFkGAEgASgFKlkKCkltcG9ydEVudW0SGwoXSU1QT1JUX0VO",
+ "VU1fVU5TUEVDSUZJRUQQABIOCgpJTVBPUlRfRk9PEAcSDgoKSU1QT1JUX0JB",
+ "UhAIEg4KCklNUE9SVF9CQVoQCUI8Chhjb20uZ29vZ2xlLnByb3RvYnVmLnRl",
+ "c3RIAfgBAaoCGkdvb2dsZS5Qcm90b2J1Zi5UZXN0UHJvdG9zUABiBnByb3Rv",
+ "Mw=="));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { global::Google.Protobuf.TestProtos.UnittestImportPublicProto3Reflection.Descriptor, },
+ new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Google.Protobuf.TestProtos.ImportEnum), }, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.ImportMessage), global::Google.Protobuf.TestProtos.ImportMessage.Parser, new[]{ "D" }, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Enums
+ public enum ImportEnum {
+ [pbr::OriginalName("IMPORT_ENUM_UNSPECIFIED")] Unspecified = 0,
+ [pbr::OriginalName("IMPORT_FOO")] ImportFoo = 7,
+ [pbr::OriginalName("IMPORT_BAR")] ImportBar = 8,
+ [pbr::OriginalName("IMPORT_BAZ")] ImportBaz = 9,
+ }
+
+ #endregion
+
+ #region Messages
+ public sealed partial class ImportMessage : pb::IMessage<ImportMessage> {
+ private static readonly pb::MessageParser<ImportMessage> _parser = new pb::MessageParser<ImportMessage>(() => new ImportMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<ImportMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestImportProto3Reflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ImportMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ImportMessage(ImportMessage other) : this() {
+ d_ = other.d_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ImportMessage Clone() {
+ return new ImportMessage(this);
+ }
+
+ /// <summary>Field number for the "d" field.</summary>
+ public const int DFieldNumber = 1;
+ private int d_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int D {
+ get { return d_; }
+ set {
+ d_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as ImportMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(ImportMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (D != other.D) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (D != 0) hash ^= D.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (D != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(D);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (D != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(D);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(ImportMessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.D != 0) {
+ D = other.D;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ D = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs
new file mode 100644
index 0000000000..67b8edf464
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestImportPublicProto3.cs
@@ -0,0 +1,160 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/unittest_import_public_proto3.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.TestProtos {
+
+ /// <summary>Holder for reflection information generated from google/protobuf/unittest_import_public_proto3.proto</summary>
+ public static partial class UnittestImportPublicProto3Reflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for google/protobuf/unittest_import_public_proto3.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static UnittestImportPublicProto3Reflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "CjNnb29nbGUvcHJvdG9idWYvdW5pdHRlc3RfaW1wb3J0X3B1YmxpY19wcm90",
+ "bzMucHJvdG8SGHByb3RvYnVmX3VuaXR0ZXN0X2ltcG9ydCIgChNQdWJsaWNJ",
+ "bXBvcnRNZXNzYWdlEgkKAWUYASABKAVCNwoYY29tLmdvb2dsZS5wcm90b2J1",
+ "Zi50ZXN0qgIaR29vZ2xlLlByb3RvYnVmLlRlc3RQcm90b3NiBnByb3RvMw=="));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { },
+ new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.PublicImportMessage), global::Google.Protobuf.TestProtos.PublicImportMessage.Parser, new[]{ "E" }, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Messages
+ public sealed partial class PublicImportMessage : pb::IMessage<PublicImportMessage> {
+ private static readonly pb::MessageParser<PublicImportMessage> _parser = new pb::MessageParser<PublicImportMessage>(() => new PublicImportMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<PublicImportMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestImportPublicProto3Reflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public PublicImportMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public PublicImportMessage(PublicImportMessage other) : this() {
+ e_ = other.e_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public PublicImportMessage Clone() {
+ return new PublicImportMessage(this);
+ }
+
+ /// <summary>Field number for the "e" field.</summary>
+ public const int EFieldNumber = 1;
+ private int e_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int E {
+ get { return e_; }
+ set {
+ e_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as PublicImportMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(PublicImportMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (E != other.E) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (E != 0) hash ^= E.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (E != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(E);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (E != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(E);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(PublicImportMessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.E != 0) {
+ E = other.E;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ E = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs
new file mode 100644
index 0000000000..7c0ba8a677
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestIssues.cs
@@ -0,0 +1,1736 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: unittest_issues.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace UnitTest.Issues.TestProtos {
+
+ /// <summary>Holder for reflection information generated from unittest_issues.proto</summary>
+ public static partial class UnittestIssuesReflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for unittest_issues.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static UnittestIssuesReflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "ChV1bml0dGVzdF9pc3N1ZXMucHJvdG8SD3VuaXR0ZXN0X2lzc3VlcyInCghJ",
+ "c3N1ZTMwNxobCgpOZXN0ZWRPbmNlGg0KC05lc3RlZFR3aWNlIrABChNOZWdh",
+ "dGl2ZUVudW1NZXNzYWdlEiwKBXZhbHVlGAEgASgOMh0udW5pdHRlc3RfaXNz",
+ "dWVzLk5lZ2F0aXZlRW51bRIxCgZ2YWx1ZXMYAiADKA4yHS51bml0dGVzdF9p",
+ "c3N1ZXMuTmVnYXRpdmVFbnVtQgIQABI4Cg1wYWNrZWRfdmFsdWVzGAMgAygO",
+ "Mh0udW5pdHRlc3RfaXNzdWVzLk5lZ2F0aXZlRW51bUICEAEiEQoPRGVwcmVj",
+ "YXRlZENoaWxkIrkCChdEZXByZWNhdGVkRmllbGRzTWVzc2FnZRIaCg5Qcmlt",
+ "aXRpdmVWYWx1ZRgBIAEoBUICGAESGgoOUHJpbWl0aXZlQXJyYXkYAiADKAVC",
+ "AhgBEjoKDE1lc3NhZ2VWYWx1ZRgDIAEoCzIgLnVuaXR0ZXN0X2lzc3Vlcy5E",
+ "ZXByZWNhdGVkQ2hpbGRCAhgBEjoKDE1lc3NhZ2VBcnJheRgEIAMoCzIgLnVu",
+ "aXR0ZXN0X2lzc3Vlcy5EZXByZWNhdGVkQ2hpbGRCAhgBEjYKCUVudW1WYWx1",
+ "ZRgFIAEoDjIfLnVuaXR0ZXN0X2lzc3Vlcy5EZXByZWNhdGVkRW51bUICGAES",
+ "NgoJRW51bUFycmF5GAYgAygOMh8udW5pdHRlc3RfaXNzdWVzLkRlcHJlY2F0",
+ "ZWRFbnVtQgIYASIZCglJdGVtRmllbGQSDAoEaXRlbRgBIAEoBSJECg1SZXNl",
+ "cnZlZE5hbWVzEg0KBXR5cGVzGAEgASgFEhIKCmRlc2NyaXB0b3IYAiABKAUa",
+ "EAoOU29tZU5lc3RlZFR5cGUioAEKFVRlc3RKc29uRmllbGRPcmRlcmluZxIT",
+ "CgtwbGFpbl9pbnQzMhgEIAEoBRITCglvMV9zdHJpbmcYAiABKAlIABISCghv",
+ "MV9pbnQzMhgFIAEoBUgAEhQKDHBsYWluX3N0cmluZxgBIAEoCRISCghvMl9p",
+ "bnQzMhgGIAEoBUgBEhMKCW8yX3N0cmluZxgDIAEoCUgBQgQKAm8xQgQKAm8y",
+ "IksKDFRlc3RKc29uTmFtZRIMCgRuYW1lGAEgASgJEhkKC2Rlc2NyaXB0aW9u",
+ "GAIgASgJUgRkZXNjEhIKBGd1aWQYAyABKAlSBGV4aWQqVQoMTmVnYXRpdmVF",
+ "bnVtEhYKEk5FR0FUSVZFX0VOVU1fWkVSTxAAEhYKCUZpdmVCZWxvdxD7////",
+ "//////8BEhUKCE1pbnVzT25lEP///////////wEqLgoORGVwcmVjYXRlZEVu",
+ "dW0SEwoPREVQUkVDQVRFRF9aRVJPEAASBwoDb25lEAFCH0gBqgIaVW5pdFRl",
+ "c3QuSXNzdWVzLlRlc3RQcm90b3NiBnByb3RvMw=="));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { },
+ new pbr::GeneratedClrTypeInfo(new[] {typeof(global::UnitTest.Issues.TestProtos.NegativeEnum), typeof(global::UnitTest.Issues.TestProtos.DeprecatedEnum), }, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.Issue307), global::UnitTest.Issues.TestProtos.Issue307.Parser, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.Issue307.Types.NestedOnce), global::UnitTest.Issues.TestProtos.Issue307.Types.NestedOnce.Parser, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.Issue307.Types.NestedOnce.Types.NestedTwice), global::UnitTest.Issues.TestProtos.Issue307.Types.NestedOnce.Types.NestedTwice.Parser, null, null, null, null)})}),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.NegativeEnumMessage), global::UnitTest.Issues.TestProtos.NegativeEnumMessage.Parser, new[]{ "Value", "Values", "PackedValues" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.DeprecatedChild), global::UnitTest.Issues.TestProtos.DeprecatedChild.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.DeprecatedFieldsMessage), global::UnitTest.Issues.TestProtos.DeprecatedFieldsMessage.Parser, new[]{ "PrimitiveValue", "PrimitiveArray", "MessageValue", "MessageArray", "EnumValue", "EnumArray" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.ItemField), global::UnitTest.Issues.TestProtos.ItemField.Parser, new[]{ "Item" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.ReservedNames), global::UnitTest.Issues.TestProtos.ReservedNames.Parser, new[]{ "Types_", "Descriptor_" }, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.ReservedNames.Types.SomeNestedType), global::UnitTest.Issues.TestProtos.ReservedNames.Types.SomeNestedType.Parser, null, null, null, null)}),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.TestJsonFieldOrdering), global::UnitTest.Issues.TestProtos.TestJsonFieldOrdering.Parser, new[]{ "PlainInt32", "O1String", "O1Int32", "PlainString", "O2Int32", "O2String" }, new[]{ "O1", "O2" }, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.TestJsonName), global::UnitTest.Issues.TestProtos.TestJsonName.Parser, new[]{ "Name", "Description", "Guid" }, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Enums
+ public enum NegativeEnum {
+ [pbr::OriginalName("NEGATIVE_ENUM_ZERO")] Zero = 0,
+ [pbr::OriginalName("FiveBelow")] FiveBelow = -5,
+ [pbr::OriginalName("MinusOne")] MinusOne = -1,
+ }
+
+ public enum DeprecatedEnum {
+ [pbr::OriginalName("DEPRECATED_ZERO")] DeprecatedZero = 0,
+ [pbr::OriginalName("one")] One = 1,
+ }
+
+ #endregion
+
+ #region Messages
+ /// <summary>
+ /// Issue 307: when generating doubly-nested types, any references
+ /// should be of the form A.Types.B.Types.C.
+ /// </summary>
+ public sealed partial class Issue307 : pb::IMessage<Issue307> {
+ private static readonly pb::MessageParser<Issue307> _parser = new pb::MessageParser<Issue307>(() => new Issue307());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Issue307> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestIssuesReflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Issue307() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Issue307(Issue307 other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Issue307 Clone() {
+ return new Issue307(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Issue307);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Issue307 other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Issue307 other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the Issue307 message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ public sealed partial class NestedOnce : pb::IMessage<NestedOnce> {
+ private static readonly pb::MessageParser<NestedOnce> _parser = new pb::MessageParser<NestedOnce>(() => new NestedOnce());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<NestedOnce> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.Issue307.Descriptor.NestedTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedOnce() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedOnce(NestedOnce other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedOnce Clone() {
+ return new NestedOnce(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as NestedOnce);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(NestedOnce other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(NestedOnce other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the NestedOnce message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ public sealed partial class NestedTwice : pb::IMessage<NestedTwice> {
+ private static readonly pb::MessageParser<NestedTwice> _parser = new pb::MessageParser<NestedTwice>(() => new NestedTwice());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<NestedTwice> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.Issue307.Types.NestedOnce.Descriptor.NestedTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedTwice() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedTwice(NestedTwice other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedTwice Clone() {
+ return new NestedTwice(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as NestedTwice);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(NestedTwice other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(NestedTwice other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ }
+ #endregion
+
+ }
+
+ }
+ #endregion
+
+ }
+
+ public sealed partial class NegativeEnumMessage : pb::IMessage<NegativeEnumMessage> {
+ private static readonly pb::MessageParser<NegativeEnumMessage> _parser = new pb::MessageParser<NegativeEnumMessage>(() => new NegativeEnumMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<NegativeEnumMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestIssuesReflection.Descriptor.MessageTypes[1]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NegativeEnumMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NegativeEnumMessage(NegativeEnumMessage other) : this() {
+ value_ = other.value_;
+ values_ = other.values_.Clone();
+ packedValues_ = other.packedValues_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NegativeEnumMessage Clone() {
+ return new NegativeEnumMessage(this);
+ }
+
+ /// <summary>Field number for the "value" field.</summary>
+ public const int ValueFieldNumber = 1;
+ private global::UnitTest.Issues.TestProtos.NegativeEnum value_ = 0;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::UnitTest.Issues.TestProtos.NegativeEnum Value {
+ get { return value_; }
+ set {
+ value_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "values" field.</summary>
+ public const int ValuesFieldNumber = 2;
+ private static readonly pb::FieldCodec<global::UnitTest.Issues.TestProtos.NegativeEnum> _repeated_values_codec
+ = pb::FieldCodec.ForEnum(16, x => (int) x, x => (global::UnitTest.Issues.TestProtos.NegativeEnum) x);
+ private readonly pbc::RepeatedField<global::UnitTest.Issues.TestProtos.NegativeEnum> values_ = new pbc::RepeatedField<global::UnitTest.Issues.TestProtos.NegativeEnum>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::UnitTest.Issues.TestProtos.NegativeEnum> Values {
+ get { return values_; }
+ }
+
+ /// <summary>Field number for the "packed_values" field.</summary>
+ public const int PackedValuesFieldNumber = 3;
+ private static readonly pb::FieldCodec<global::UnitTest.Issues.TestProtos.NegativeEnum> _repeated_packedValues_codec
+ = pb::FieldCodec.ForEnum(26, x => (int) x, x => (global::UnitTest.Issues.TestProtos.NegativeEnum) x);
+ private readonly pbc::RepeatedField<global::UnitTest.Issues.TestProtos.NegativeEnum> packedValues_ = new pbc::RepeatedField<global::UnitTest.Issues.TestProtos.NegativeEnum>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::UnitTest.Issues.TestProtos.NegativeEnum> PackedValues {
+ get { return packedValues_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as NegativeEnumMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(NegativeEnumMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Value != other.Value) return false;
+ if(!values_.Equals(other.values_)) return false;
+ if(!packedValues_.Equals(other.packedValues_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Value != 0) hash ^= Value.GetHashCode();
+ hash ^= values_.GetHashCode();
+ hash ^= packedValues_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Value != 0) {
+ output.WriteRawTag(8);
+ output.WriteEnum((int) Value);
+ }
+ values_.WriteTo(output, _repeated_values_codec);
+ packedValues_.WriteTo(output, _repeated_packedValues_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Value != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Value);
+ }
+ size += values_.CalculateSize(_repeated_values_codec);
+ size += packedValues_.CalculateSize(_repeated_packedValues_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(NegativeEnumMessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Value != 0) {
+ Value = other.Value;
+ }
+ values_.Add(other.values_);
+ packedValues_.Add(other.packedValues_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ value_ = (global::UnitTest.Issues.TestProtos.NegativeEnum) input.ReadEnum();
+ break;
+ }
+ case 18:
+ case 16: {
+ values_.AddEntriesFrom(input, _repeated_values_codec);
+ break;
+ }
+ case 26:
+ case 24: {
+ packedValues_.AddEntriesFrom(input, _repeated_packedValues_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class DeprecatedChild : pb::IMessage<DeprecatedChild> {
+ private static readonly pb::MessageParser<DeprecatedChild> _parser = new pb::MessageParser<DeprecatedChild>(() => new DeprecatedChild());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<DeprecatedChild> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestIssuesReflection.Descriptor.MessageTypes[2]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DeprecatedChild() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DeprecatedChild(DeprecatedChild other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DeprecatedChild Clone() {
+ return new DeprecatedChild(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as DeprecatedChild);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(DeprecatedChild other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(DeprecatedChild other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class DeprecatedFieldsMessage : pb::IMessage<DeprecatedFieldsMessage> {
+ private static readonly pb::MessageParser<DeprecatedFieldsMessage> _parser = new pb::MessageParser<DeprecatedFieldsMessage>(() => new DeprecatedFieldsMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<DeprecatedFieldsMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestIssuesReflection.Descriptor.MessageTypes[3]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DeprecatedFieldsMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DeprecatedFieldsMessage(DeprecatedFieldsMessage other) : this() {
+ primitiveValue_ = other.primitiveValue_;
+ primitiveArray_ = other.primitiveArray_.Clone();
+ MessageValue = other.messageValue_ != null ? other.MessageValue.Clone() : null;
+ messageArray_ = other.messageArray_.Clone();
+ enumValue_ = other.enumValue_;
+ enumArray_ = other.enumArray_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DeprecatedFieldsMessage Clone() {
+ return new DeprecatedFieldsMessage(this);
+ }
+
+ /// <summary>Field number for the "PrimitiveValue" field.</summary>
+ public const int PrimitiveValueFieldNumber = 1;
+ private int primitiveValue_;
+ [global::System.ObsoleteAttribute]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int PrimitiveValue {
+ get { return primitiveValue_; }
+ set {
+ primitiveValue_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "PrimitiveArray" field.</summary>
+ public const int PrimitiveArrayFieldNumber = 2;
+ private static readonly pb::FieldCodec<int> _repeated_primitiveArray_codec
+ = pb::FieldCodec.ForInt32(18);
+ private readonly pbc::RepeatedField<int> primitiveArray_ = new pbc::RepeatedField<int>();
+ [global::System.ObsoleteAttribute]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> PrimitiveArray {
+ get { return primitiveArray_; }
+ }
+
+ /// <summary>Field number for the "MessageValue" field.</summary>
+ public const int MessageValueFieldNumber = 3;
+ private global::UnitTest.Issues.TestProtos.DeprecatedChild messageValue_;
+ [global::System.ObsoleteAttribute]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::UnitTest.Issues.TestProtos.DeprecatedChild MessageValue {
+ get { return messageValue_; }
+ set {
+ messageValue_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "MessageArray" field.</summary>
+ public const int MessageArrayFieldNumber = 4;
+ private static readonly pb::FieldCodec<global::UnitTest.Issues.TestProtos.DeprecatedChild> _repeated_messageArray_codec
+ = pb::FieldCodec.ForMessage(34, global::UnitTest.Issues.TestProtos.DeprecatedChild.Parser);
+ private readonly pbc::RepeatedField<global::UnitTest.Issues.TestProtos.DeprecatedChild> messageArray_ = new pbc::RepeatedField<global::UnitTest.Issues.TestProtos.DeprecatedChild>();
+ [global::System.ObsoleteAttribute]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::UnitTest.Issues.TestProtos.DeprecatedChild> MessageArray {
+ get { return messageArray_; }
+ }
+
+ /// <summary>Field number for the "EnumValue" field.</summary>
+ public const int EnumValueFieldNumber = 5;
+ private global::UnitTest.Issues.TestProtos.DeprecatedEnum enumValue_ = 0;
+ [global::System.ObsoleteAttribute]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::UnitTest.Issues.TestProtos.DeprecatedEnum EnumValue {
+ get { return enumValue_; }
+ set {
+ enumValue_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "EnumArray" field.</summary>
+ public const int EnumArrayFieldNumber = 6;
+ private static readonly pb::FieldCodec<global::UnitTest.Issues.TestProtos.DeprecatedEnum> _repeated_enumArray_codec
+ = pb::FieldCodec.ForEnum(50, x => (int) x, x => (global::UnitTest.Issues.TestProtos.DeprecatedEnum) x);
+ private readonly pbc::RepeatedField<global::UnitTest.Issues.TestProtos.DeprecatedEnum> enumArray_ = new pbc::RepeatedField<global::UnitTest.Issues.TestProtos.DeprecatedEnum>();
+ [global::System.ObsoleteAttribute]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::UnitTest.Issues.TestProtos.DeprecatedEnum> EnumArray {
+ get { return enumArray_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as DeprecatedFieldsMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(DeprecatedFieldsMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (PrimitiveValue != other.PrimitiveValue) return false;
+ if(!primitiveArray_.Equals(other.primitiveArray_)) return false;
+ if (!object.Equals(MessageValue, other.MessageValue)) return false;
+ if(!messageArray_.Equals(other.messageArray_)) return false;
+ if (EnumValue != other.EnumValue) return false;
+ if(!enumArray_.Equals(other.enumArray_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (PrimitiveValue != 0) hash ^= PrimitiveValue.GetHashCode();
+ hash ^= primitiveArray_.GetHashCode();
+ if (messageValue_ != null) hash ^= MessageValue.GetHashCode();
+ hash ^= messageArray_.GetHashCode();
+ if (EnumValue != 0) hash ^= EnumValue.GetHashCode();
+ hash ^= enumArray_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (PrimitiveValue != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(PrimitiveValue);
+ }
+ primitiveArray_.WriteTo(output, _repeated_primitiveArray_codec);
+ if (messageValue_ != null) {
+ output.WriteRawTag(26);
+ output.WriteMessage(MessageValue);
+ }
+ messageArray_.WriteTo(output, _repeated_messageArray_codec);
+ if (EnumValue != 0) {
+ output.WriteRawTag(40);
+ output.WriteEnum((int) EnumValue);
+ }
+ enumArray_.WriteTo(output, _repeated_enumArray_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (PrimitiveValue != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(PrimitiveValue);
+ }
+ size += primitiveArray_.CalculateSize(_repeated_primitiveArray_codec);
+ if (messageValue_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(MessageValue);
+ }
+ size += messageArray_.CalculateSize(_repeated_messageArray_codec);
+ if (EnumValue != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) EnumValue);
+ }
+ size += enumArray_.CalculateSize(_repeated_enumArray_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(DeprecatedFieldsMessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.PrimitiveValue != 0) {
+ PrimitiveValue = other.PrimitiveValue;
+ }
+ primitiveArray_.Add(other.primitiveArray_);
+ if (other.messageValue_ != null) {
+ if (messageValue_ == null) {
+ messageValue_ = new global::UnitTest.Issues.TestProtos.DeprecatedChild();
+ }
+ MessageValue.MergeFrom(other.MessageValue);
+ }
+ messageArray_.Add(other.messageArray_);
+ if (other.EnumValue != 0) {
+ EnumValue = other.EnumValue;
+ }
+ enumArray_.Add(other.enumArray_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ PrimitiveValue = input.ReadInt32();
+ break;
+ }
+ case 18:
+ case 16: {
+ primitiveArray_.AddEntriesFrom(input, _repeated_primitiveArray_codec);
+ break;
+ }
+ case 26: {
+ if (messageValue_ == null) {
+ messageValue_ = new global::UnitTest.Issues.TestProtos.DeprecatedChild();
+ }
+ input.ReadMessage(messageValue_);
+ break;
+ }
+ case 34: {
+ messageArray_.AddEntriesFrom(input, _repeated_messageArray_codec);
+ break;
+ }
+ case 40: {
+ enumValue_ = (global::UnitTest.Issues.TestProtos.DeprecatedEnum) input.ReadEnum();
+ break;
+ }
+ case 50:
+ case 48: {
+ enumArray_.AddEntriesFrom(input, _repeated_enumArray_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Issue 45: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=45
+ /// </summary>
+ public sealed partial class ItemField : pb::IMessage<ItemField> {
+ private static readonly pb::MessageParser<ItemField> _parser = new pb::MessageParser<ItemField>(() => new ItemField());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<ItemField> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestIssuesReflection.Descriptor.MessageTypes[4]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ItemField() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ItemField(ItemField other) : this() {
+ item_ = other.item_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ItemField Clone() {
+ return new ItemField(this);
+ }
+
+ /// <summary>Field number for the "item" field.</summary>
+ public const int ItemFieldNumber = 1;
+ private int item_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Item {
+ get { return item_; }
+ set {
+ item_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as ItemField);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(ItemField other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Item != other.Item) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Item != 0) hash ^= Item.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Item != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(Item);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Item != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Item);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(ItemField other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Item != 0) {
+ Item = other.Item;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Item = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class ReservedNames : pb::IMessage<ReservedNames> {
+ private static readonly pb::MessageParser<ReservedNames> _parser = new pb::MessageParser<ReservedNames>(() => new ReservedNames());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<ReservedNames> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestIssuesReflection.Descriptor.MessageTypes[5]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ReservedNames() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ReservedNames(ReservedNames other) : this() {
+ types_ = other.types_;
+ descriptor_ = other.descriptor_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ReservedNames Clone() {
+ return new ReservedNames(this);
+ }
+
+ /// <summary>Field number for the "types" field.</summary>
+ public const int Types_FieldNumber = 1;
+ private int types_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Types_ {
+ get { return types_; }
+ set {
+ types_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "descriptor" field.</summary>
+ public const int Descriptor_FieldNumber = 2;
+ private int descriptor_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Descriptor_ {
+ get { return descriptor_; }
+ set {
+ descriptor_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as ReservedNames);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(ReservedNames other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Types_ != other.Types_) return false;
+ if (Descriptor_ != other.Descriptor_) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Types_ != 0) hash ^= Types_.GetHashCode();
+ if (Descriptor_ != 0) hash ^= Descriptor_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Types_ != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(Types_);
+ }
+ if (Descriptor_ != 0) {
+ output.WriteRawTag(16);
+ output.WriteInt32(Descriptor_);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Types_ != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Types_);
+ }
+ if (Descriptor_ != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Descriptor_);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(ReservedNames other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Types_ != 0) {
+ Types_ = other.Types_;
+ }
+ if (other.Descriptor_ != 0) {
+ Descriptor_ = other.Descriptor_;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Types_ = input.ReadInt32();
+ break;
+ }
+ case 16: {
+ Descriptor_ = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the ReservedNames message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ /// <summary>
+ /// Force a nested type called Types
+ /// </summary>
+ public sealed partial class SomeNestedType : pb::IMessage<SomeNestedType> {
+ private static readonly pb::MessageParser<SomeNestedType> _parser = new pb::MessageParser<SomeNestedType>(() => new SomeNestedType());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<SomeNestedType> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.ReservedNames.Descriptor.NestedTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SomeNestedType() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SomeNestedType(SomeNestedType other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SomeNestedType Clone() {
+ return new SomeNestedType(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as SomeNestedType);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(SomeNestedType other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(SomeNestedType other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ }
+ #endregion
+
+ }
+
+ /// <summary>
+ /// These fields are deliberately not declared in numeric
+ /// order, and the oneof fields aren't contiguous either.
+ /// This allows for reasonably robust tests of JSON output
+ /// ordering.
+ /// TestFieldOrderings in unittest_proto3.proto is similar,
+ /// but doesn't include oneofs.
+ /// TODO: Consider adding oneofs to TestFieldOrderings, although
+ /// that will require fixing other tests in multiple platforms.
+ /// Alternatively, consider just adding this to
+ /// unittest_proto3.proto if multiple platforms want it.
+ /// </summary>
+ public sealed partial class TestJsonFieldOrdering : pb::IMessage<TestJsonFieldOrdering> {
+ private static readonly pb::MessageParser<TestJsonFieldOrdering> _parser = new pb::MessageParser<TestJsonFieldOrdering>(() => new TestJsonFieldOrdering());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestJsonFieldOrdering> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestIssuesReflection.Descriptor.MessageTypes[6]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestJsonFieldOrdering() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestJsonFieldOrdering(TestJsonFieldOrdering other) : this() {
+ plainInt32_ = other.plainInt32_;
+ plainString_ = other.plainString_;
+ switch (other.O1Case) {
+ case O1OneofCase.O1String:
+ O1String = other.O1String;
+ break;
+ case O1OneofCase.O1Int32:
+ O1Int32 = other.O1Int32;
+ break;
+ }
+
+ switch (other.O2Case) {
+ case O2OneofCase.O2Int32:
+ O2Int32 = other.O2Int32;
+ break;
+ case O2OneofCase.O2String:
+ O2String = other.O2String;
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestJsonFieldOrdering Clone() {
+ return new TestJsonFieldOrdering(this);
+ }
+
+ /// <summary>Field number for the "plain_int32" field.</summary>
+ public const int PlainInt32FieldNumber = 4;
+ private int plainInt32_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int PlainInt32 {
+ get { return plainInt32_; }
+ set {
+ plainInt32_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "o1_string" field.</summary>
+ public const int O1StringFieldNumber = 2;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string O1String {
+ get { return o1Case_ == O1OneofCase.O1String ? (string) o1_ : ""; }
+ set {
+ o1_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ o1Case_ = O1OneofCase.O1String;
+ }
+ }
+
+ /// <summary>Field number for the "o1_int32" field.</summary>
+ public const int O1Int32FieldNumber = 5;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int O1Int32 {
+ get { return o1Case_ == O1OneofCase.O1Int32 ? (int) o1_ : 0; }
+ set {
+ o1_ = value;
+ o1Case_ = O1OneofCase.O1Int32;
+ }
+ }
+
+ /// <summary>Field number for the "plain_string" field.</summary>
+ public const int PlainStringFieldNumber = 1;
+ private string plainString_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string PlainString {
+ get { return plainString_; }
+ set {
+ plainString_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "o2_int32" field.</summary>
+ public const int O2Int32FieldNumber = 6;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int O2Int32 {
+ get { return o2Case_ == O2OneofCase.O2Int32 ? (int) o2_ : 0; }
+ set {
+ o2_ = value;
+ o2Case_ = O2OneofCase.O2Int32;
+ }
+ }
+
+ /// <summary>Field number for the "o2_string" field.</summary>
+ public const int O2StringFieldNumber = 3;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string O2String {
+ get { return o2Case_ == O2OneofCase.O2String ? (string) o2_ : ""; }
+ set {
+ o2_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ o2Case_ = O2OneofCase.O2String;
+ }
+ }
+
+ private object o1_;
+ /// <summary>Enum of possible cases for the "o1" oneof.</summary>
+ public enum O1OneofCase {
+ None = 0,
+ O1String = 2,
+ O1Int32 = 5,
+ }
+ private O1OneofCase o1Case_ = O1OneofCase.None;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public O1OneofCase O1Case {
+ get { return o1Case_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearO1() {
+ o1Case_ = O1OneofCase.None;
+ o1_ = null;
+ }
+
+ private object o2_;
+ /// <summary>Enum of possible cases for the "o2" oneof.</summary>
+ public enum O2OneofCase {
+ None = 0,
+ O2Int32 = 6,
+ O2String = 3,
+ }
+ private O2OneofCase o2Case_ = O2OneofCase.None;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public O2OneofCase O2Case {
+ get { return o2Case_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearO2() {
+ o2Case_ = O2OneofCase.None;
+ o2_ = null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestJsonFieldOrdering);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestJsonFieldOrdering other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (PlainInt32 != other.PlainInt32) return false;
+ if (O1String != other.O1String) return false;
+ if (O1Int32 != other.O1Int32) return false;
+ if (PlainString != other.PlainString) return false;
+ if (O2Int32 != other.O2Int32) return false;
+ if (O2String != other.O2String) return false;
+ if (O1Case != other.O1Case) return false;
+ if (O2Case != other.O2Case) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (PlainInt32 != 0) hash ^= PlainInt32.GetHashCode();
+ if (o1Case_ == O1OneofCase.O1String) hash ^= O1String.GetHashCode();
+ if (o1Case_ == O1OneofCase.O1Int32) hash ^= O1Int32.GetHashCode();
+ if (PlainString.Length != 0) hash ^= PlainString.GetHashCode();
+ if (o2Case_ == O2OneofCase.O2Int32) hash ^= O2Int32.GetHashCode();
+ if (o2Case_ == O2OneofCase.O2String) hash ^= O2String.GetHashCode();
+ hash ^= (int) o1Case_;
+ hash ^= (int) o2Case_;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (PlainString.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(PlainString);
+ }
+ if (o1Case_ == O1OneofCase.O1String) {
+ output.WriteRawTag(18);
+ output.WriteString(O1String);
+ }
+ if (o2Case_ == O2OneofCase.O2String) {
+ output.WriteRawTag(26);
+ output.WriteString(O2String);
+ }
+ if (PlainInt32 != 0) {
+ output.WriteRawTag(32);
+ output.WriteInt32(PlainInt32);
+ }
+ if (o1Case_ == O1OneofCase.O1Int32) {
+ output.WriteRawTag(40);
+ output.WriteInt32(O1Int32);
+ }
+ if (o2Case_ == O2OneofCase.O2Int32) {
+ output.WriteRawTag(48);
+ output.WriteInt32(O2Int32);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (PlainInt32 != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(PlainInt32);
+ }
+ if (o1Case_ == O1OneofCase.O1String) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(O1String);
+ }
+ if (o1Case_ == O1OneofCase.O1Int32) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(O1Int32);
+ }
+ if (PlainString.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(PlainString);
+ }
+ if (o2Case_ == O2OneofCase.O2Int32) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(O2Int32);
+ }
+ if (o2Case_ == O2OneofCase.O2String) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(O2String);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestJsonFieldOrdering other) {
+ if (other == null) {
+ return;
+ }
+ if (other.PlainInt32 != 0) {
+ PlainInt32 = other.PlainInt32;
+ }
+ if (other.PlainString.Length != 0) {
+ PlainString = other.PlainString;
+ }
+ switch (other.O1Case) {
+ case O1OneofCase.O1String:
+ O1String = other.O1String;
+ break;
+ case O1OneofCase.O1Int32:
+ O1Int32 = other.O1Int32;
+ break;
+ }
+
+ switch (other.O2Case) {
+ case O2OneofCase.O2Int32:
+ O2Int32 = other.O2Int32;
+ break;
+ case O2OneofCase.O2String:
+ O2String = other.O2String;
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ PlainString = input.ReadString();
+ break;
+ }
+ case 18: {
+ O1String = input.ReadString();
+ break;
+ }
+ case 26: {
+ O2String = input.ReadString();
+ break;
+ }
+ case 32: {
+ PlainInt32 = input.ReadInt32();
+ break;
+ }
+ case 40: {
+ O1Int32 = input.ReadInt32();
+ break;
+ }
+ case 48: {
+ O2Int32 = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class TestJsonName : pb::IMessage<TestJsonName> {
+ private static readonly pb::MessageParser<TestJsonName> _parser = new pb::MessageParser<TestJsonName>(() => new TestJsonName());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestJsonName> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::UnitTest.Issues.TestProtos.UnittestIssuesReflection.Descriptor.MessageTypes[7]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestJsonName() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestJsonName(TestJsonName other) : this() {
+ name_ = other.name_;
+ description_ = other.description_;
+ guid_ = other.guid_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestJsonName Clone() {
+ return new TestJsonName(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ /// <summary>
+ /// Message for testing the effects for of the json_name option
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "description" field.</summary>
+ public const int DescriptionFieldNumber = 2;
+ private string description_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Description {
+ get { return description_; }
+ set {
+ description_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "guid" field.</summary>
+ public const int GuidFieldNumber = 3;
+ private string guid_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Guid {
+ get { return guid_; }
+ set {
+ guid_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestJsonName);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestJsonName other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ if (Description != other.Description) return false;
+ if (Guid != other.Guid) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ if (Description.Length != 0) hash ^= Description.GetHashCode();
+ if (Guid.Length != 0) hash ^= Guid.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ if (Description.Length != 0) {
+ output.WriteRawTag(18);
+ output.WriteString(Description);
+ }
+ if (Guid.Length != 0) {
+ output.WriteRawTag(26);
+ output.WriteString(Guid);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ if (Description.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Description);
+ }
+ if (Guid.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Guid);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestJsonName other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ if (other.Description.Length != 0) {
+ Description = other.Description;
+ }
+ if (other.Guid.Length != 0) {
+ Guid = other.Guid;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 18: {
+ Description = input.ReadString();
+ break;
+ }
+ case 26: {
+ Guid = input.ReadString();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs
new file mode 100644
index 0000000000..c11ab84d01
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestProto3.cs
@@ -0,0 +1,6766 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/unittest_proto3.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.TestProtos {
+
+ /// <summary>Holder for reflection information generated from google/protobuf/unittest_proto3.proto</summary>
+ public static partial class UnittestProto3Reflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for google/protobuf/unittest_proto3.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static UnittestProto3Reflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "CiVnb29nbGUvcHJvdG9idWYvdW5pdHRlc3RfcHJvdG8zLnByb3RvEhFwcm90",
+ "b2J1Zl91bml0dGVzdBosZ29vZ2xlL3Byb3RvYnVmL3VuaXR0ZXN0X2ltcG9y",
+ "dF9wcm90bzMucHJvdG8i8A8KDFRlc3RBbGxUeXBlcxIUCgxzaW5nbGVfaW50",
+ "MzIYASABKAUSFAoMc2luZ2xlX2ludDY0GAIgASgDEhUKDXNpbmdsZV91aW50",
+ "MzIYAyABKA0SFQoNc2luZ2xlX3VpbnQ2NBgEIAEoBBIVCg1zaW5nbGVfc2lu",
+ "dDMyGAUgASgREhUKDXNpbmdsZV9zaW50NjQYBiABKBISFgoOc2luZ2xlX2Zp",
+ "eGVkMzIYByABKAcSFgoOc2luZ2xlX2ZpeGVkNjQYCCABKAYSFwoPc2luZ2xl",
+ "X3NmaXhlZDMyGAkgASgPEhcKD3NpbmdsZV9zZml4ZWQ2NBgKIAEoEBIUCgxz",
+ "aW5nbGVfZmxvYXQYCyABKAISFQoNc2luZ2xlX2RvdWJsZRgMIAEoARITCgtz",
+ "aW5nbGVfYm9vbBgNIAEoCBIVCg1zaW5nbGVfc3RyaW5nGA4gASgJEhQKDHNp",
+ "bmdsZV9ieXRlcxgPIAEoDBJMChVzaW5nbGVfbmVzdGVkX21lc3NhZ2UYEiAB",
+ "KAsyLS5wcm90b2J1Zl91bml0dGVzdC5UZXN0QWxsVHlwZXMuTmVzdGVkTWVz",
+ "c2FnZRJBChZzaW5nbGVfZm9yZWlnbl9tZXNzYWdlGBMgASgLMiEucHJvdG9i",
+ "dWZfdW5pdHRlc3QuRm9yZWlnbk1lc3NhZ2USRgoVc2luZ2xlX2ltcG9ydF9t",
+ "ZXNzYWdlGBQgASgLMicucHJvdG9idWZfdW5pdHRlc3RfaW1wb3J0LkltcG9y",
+ "dE1lc3NhZ2USRgoSc2luZ2xlX25lc3RlZF9lbnVtGBUgASgOMioucHJvdG9i",
+ "dWZfdW5pdHRlc3QuVGVzdEFsbFR5cGVzLk5lc3RlZEVudW0SOwoTc2luZ2xl",
+ "X2ZvcmVpZ25fZW51bRgWIAEoDjIeLnByb3RvYnVmX3VuaXR0ZXN0LkZvcmVp",
+ "Z25FbnVtEkAKEnNpbmdsZV9pbXBvcnRfZW51bRgXIAEoDjIkLnByb3RvYnVm",
+ "X3VuaXR0ZXN0X2ltcG9ydC5JbXBvcnRFbnVtElMKHHNpbmdsZV9wdWJsaWNf",
+ "aW1wb3J0X21lc3NhZ2UYGiABKAsyLS5wcm90b2J1Zl91bml0dGVzdF9pbXBv",
+ "cnQuUHVibGljSW1wb3J0TWVzc2FnZRIWCg5yZXBlYXRlZF9pbnQzMhgfIAMo",
+ "BRIWCg5yZXBlYXRlZF9pbnQ2NBggIAMoAxIXCg9yZXBlYXRlZF91aW50MzIY",
+ "ISADKA0SFwoPcmVwZWF0ZWRfdWludDY0GCIgAygEEhcKD3JlcGVhdGVkX3Np",
+ "bnQzMhgjIAMoERIXCg9yZXBlYXRlZF9zaW50NjQYJCADKBISGAoQcmVwZWF0",
+ "ZWRfZml4ZWQzMhglIAMoBxIYChByZXBlYXRlZF9maXhlZDY0GCYgAygGEhkK",
+ "EXJlcGVhdGVkX3NmaXhlZDMyGCcgAygPEhkKEXJlcGVhdGVkX3NmaXhlZDY0",
+ "GCggAygQEhYKDnJlcGVhdGVkX2Zsb2F0GCkgAygCEhcKD3JlcGVhdGVkX2Rv",
+ "dWJsZRgqIAMoARIVCg1yZXBlYXRlZF9ib29sGCsgAygIEhcKD3JlcGVhdGVk",
+ "X3N0cmluZxgsIAMoCRIWCg5yZXBlYXRlZF9ieXRlcxgtIAMoDBJOChdyZXBl",
+ "YXRlZF9uZXN0ZWRfbWVzc2FnZRgwIAMoCzItLnByb3RvYnVmX3VuaXR0ZXN0",
+ "LlRlc3RBbGxUeXBlcy5OZXN0ZWRNZXNzYWdlEkMKGHJlcGVhdGVkX2ZvcmVp",
+ "Z25fbWVzc2FnZRgxIAMoCzIhLnByb3RvYnVmX3VuaXR0ZXN0LkZvcmVpZ25N",
+ "ZXNzYWdlEkgKF3JlcGVhdGVkX2ltcG9ydF9tZXNzYWdlGDIgAygLMicucHJv",
+ "dG9idWZfdW5pdHRlc3RfaW1wb3J0LkltcG9ydE1lc3NhZ2USSAoUcmVwZWF0",
+ "ZWRfbmVzdGVkX2VudW0YMyADKA4yKi5wcm90b2J1Zl91bml0dGVzdC5UZXN0",
+ "QWxsVHlwZXMuTmVzdGVkRW51bRI9ChVyZXBlYXRlZF9mb3JlaWduX2VudW0Y",
+ "NCADKA4yHi5wcm90b2J1Zl91bml0dGVzdC5Gb3JlaWduRW51bRJCChRyZXBl",
+ "YXRlZF9pbXBvcnRfZW51bRg1IAMoDjIkLnByb3RvYnVmX3VuaXR0ZXN0X2lt",
+ "cG9ydC5JbXBvcnRFbnVtElUKHnJlcGVhdGVkX3B1YmxpY19pbXBvcnRfbWVz",
+ "c2FnZRg2IAMoCzItLnByb3RvYnVmX3VuaXR0ZXN0X2ltcG9ydC5QdWJsaWNJ",
+ "bXBvcnRNZXNzYWdlEhYKDG9uZW9mX3VpbnQzMhhvIAEoDUgAEk0KFG9uZW9m",
+ "X25lc3RlZF9tZXNzYWdlGHAgASgLMi0ucHJvdG9idWZfdW5pdHRlc3QuVGVz",
+ "dEFsbFR5cGVzLk5lc3RlZE1lc3NhZ2VIABIWCgxvbmVvZl9zdHJpbmcYcSAB",
+ "KAlIABIVCgtvbmVvZl9ieXRlcxhyIAEoDEgAGhsKDU5lc3RlZE1lc3NhZ2US",
+ "CgoCYmIYASABKAUiVgoKTmVzdGVkRW51bRIbChdORVNURURfRU5VTV9VTlNQ",
+ "RUNJRklFRBAAEgcKA0ZPTxABEgcKA0JBUhACEgcKA0JBWhADEhAKA05FRxD/",
+ "//////////8BQg0KC29uZW9mX2ZpZWxkIrsBChJOZXN0ZWRUZXN0QWxsVHlw",
+ "ZXMSNAoFY2hpbGQYASABKAsyJS5wcm90b2J1Zl91bml0dGVzdC5OZXN0ZWRU",
+ "ZXN0QWxsVHlwZXMSMAoHcGF5bG9hZBgCIAEoCzIfLnByb3RvYnVmX3VuaXR0",
+ "ZXN0LlRlc3RBbGxUeXBlcxI9Cg5yZXBlYXRlZF9jaGlsZBgDIAMoCzIlLnBy",
+ "b3RvYnVmX3VuaXR0ZXN0Lk5lc3RlZFRlc3RBbGxUeXBlcyI0ChRUZXN0RGVw",
+ "cmVjYXRlZEZpZWxkcxIcChBkZXByZWNhdGVkX2ludDMyGAEgASgFQgIYASIb",
+ "Cg5Gb3JlaWduTWVzc2FnZRIJCgFjGAEgASgFIjAKElRlc3RSZXNlcnZlZEZp",
+ "ZWxkc0oECAIQA0oECA8QEEoECAkQDFIDYmFyUgNiYXoiWgoRVGVzdEZvcmVp",
+ "Z25OZXN0ZWQSRQoOZm9yZWlnbl9uZXN0ZWQYASABKAsyLS5wcm90b2J1Zl91",
+ "bml0dGVzdC5UZXN0QWxsVHlwZXMuTmVzdGVkTWVzc2FnZSI0ChhUZXN0UmVh",
+ "bGx5TGFyZ2VUYWdOdW1iZXISCQoBYRgBIAEoBRINCgJiYhj///9/IAEoBSJV",
+ "ChRUZXN0UmVjdXJzaXZlTWVzc2FnZRIyCgFhGAEgASgLMicucHJvdG9idWZf",
+ "dW5pdHRlc3QuVGVzdFJlY3Vyc2l2ZU1lc3NhZ2USCQoBaRgCIAEoBSJLChRU",
+ "ZXN0TXV0dWFsUmVjdXJzaW9uQRIzCgJiYhgBIAEoCzInLnByb3RvYnVmX3Vu",
+ "aXR0ZXN0LlRlc3RNdXR1YWxSZWN1cnNpb25CImIKFFRlc3RNdXR1YWxSZWN1",
+ "cnNpb25CEjIKAWEYASABKAsyJy5wcm90b2J1Zl91bml0dGVzdC5UZXN0TXV0",
+ "dWFsUmVjdXJzaW9uQRIWCg5vcHRpb25hbF9pbnQzMhgCIAEoBSJMChJUZXN0",
+ "RW51bUFsbG93QWxpYXMSNgoFdmFsdWUYASABKA4yJy5wcm90b2J1Zl91bml0",
+ "dGVzdC5UZXN0RW51bVdpdGhEdXBWYWx1ZSLrAgoXVGVzdENhbWVsQ2FzZUZp",
+ "ZWxkTmFtZXMSFgoOUHJpbWl0aXZlRmllbGQYASABKAUSEwoLU3RyaW5nRmll",
+ "bGQYAiABKAkSMQoJRW51bUZpZWxkGAMgASgOMh4ucHJvdG9idWZfdW5pdHRl",
+ "c3QuRm9yZWlnbkVudW0SNwoMTWVzc2FnZUZpZWxkGAQgASgLMiEucHJvdG9i",
+ "dWZfdW5pdHRlc3QuRm9yZWlnbk1lc3NhZ2USHgoWUmVwZWF0ZWRQcmltaXRp",
+ "dmVGaWVsZBgHIAMoBRIbChNSZXBlYXRlZFN0cmluZ0ZpZWxkGAggAygJEjkK",
+ "EVJlcGVhdGVkRW51bUZpZWxkGAkgAygOMh4ucHJvdG9idWZfdW5pdHRlc3Qu",
+ "Rm9yZWlnbkVudW0SPwoUUmVwZWF0ZWRNZXNzYWdlRmllbGQYCiADKAsyIS5w",
+ "cm90b2J1Zl91bml0dGVzdC5Gb3JlaWduTWVzc2FnZSLHAQoSVGVzdEZpZWxk",
+ "T3JkZXJpbmdzEhEKCW15X3N0cmluZxgLIAEoCRIOCgZteV9pbnQYASABKAMS",
+ "EAoIbXlfZmxvYXQYZSABKAISUwoVc2luZ2xlX25lc3RlZF9tZXNzYWdlGMgB",
+ "IAEoCzIzLnByb3RvYnVmX3VuaXR0ZXN0LlRlc3RGaWVsZE9yZGVyaW5ncy5O",
+ "ZXN0ZWRNZXNzYWdlGicKDU5lc3RlZE1lc3NhZ2USCgoCb28YAiABKAMSCgoC",
+ "YmIYASABKAUiSwoRU3BhcnNlRW51bU1lc3NhZ2USNgoLc3BhcnNlX2VudW0Y",
+ "ASABKA4yIS5wcm90b2J1Zl91bml0dGVzdC5UZXN0U3BhcnNlRW51bSIZCglP",
+ "bmVTdHJpbmcSDAoEZGF0YRgBIAEoCSIaCgpNb3JlU3RyaW5nEgwKBGRhdGEY",
+ "ASADKAkiGAoIT25lQnl0ZXMSDAoEZGF0YRgBIAEoDCIZCglNb3JlQnl0ZXMS",
+ "DAoEZGF0YRgBIAEoDCIcCgxJbnQzMk1lc3NhZ2USDAoEZGF0YRgBIAEoBSId",
+ "Cg1VaW50MzJNZXNzYWdlEgwKBGRhdGEYASABKA0iHAoMSW50NjRNZXNzYWdl",
+ "EgwKBGRhdGEYASABKAMiHQoNVWludDY0TWVzc2FnZRIMCgRkYXRhGAEgASgE",
+ "IhsKC0Jvb2xNZXNzYWdlEgwKBGRhdGEYASABKAgicwoJVGVzdE9uZW9mEhEK",
+ "B2Zvb19pbnQYASABKAVIABIUCgpmb29fc3RyaW5nGAIgASgJSAASNgoLZm9v",
+ "X21lc3NhZ2UYAyABKAsyHy5wcm90b2J1Zl91bml0dGVzdC5UZXN0QWxsVHlw",
+ "ZXNIAEIFCgNmb28iqgMKD1Rlc3RQYWNrZWRUeXBlcxIYCgxwYWNrZWRfaW50",
+ "MzIYWiADKAVCAhABEhgKDHBhY2tlZF9pbnQ2NBhbIAMoA0ICEAESGQoNcGFj",
+ "a2VkX3VpbnQzMhhcIAMoDUICEAESGQoNcGFja2VkX3VpbnQ2NBhdIAMoBEIC",
+ "EAESGQoNcGFja2VkX3NpbnQzMhheIAMoEUICEAESGQoNcGFja2VkX3NpbnQ2",
+ "NBhfIAMoEkICEAESGgoOcGFja2VkX2ZpeGVkMzIYYCADKAdCAhABEhoKDnBh",
+ "Y2tlZF9maXhlZDY0GGEgAygGQgIQARIbCg9wYWNrZWRfc2ZpeGVkMzIYYiAD",
+ "KA9CAhABEhsKD3BhY2tlZF9zZml4ZWQ2NBhjIAMoEEICEAESGAoMcGFja2Vk",
+ "X2Zsb2F0GGQgAygCQgIQARIZCg1wYWNrZWRfZG91YmxlGGUgAygBQgIQARIX",
+ "CgtwYWNrZWRfYm9vbBhmIAMoCEICEAESNwoLcGFja2VkX2VudW0YZyADKA4y",
+ "Hi5wcm90b2J1Zl91bml0dGVzdC5Gb3JlaWduRW51bUICEAEiyAMKEVRlc3RV",
+ "bnBhY2tlZFR5cGVzEhoKDnVucGFja2VkX2ludDMyGFogAygFQgIQABIaCg51",
+ "bnBhY2tlZF9pbnQ2NBhbIAMoA0ICEAASGwoPdW5wYWNrZWRfdWludDMyGFwg",
+ "AygNQgIQABIbCg91bnBhY2tlZF91aW50NjQYXSADKARCAhAAEhsKD3VucGFj",
+ "a2VkX3NpbnQzMhheIAMoEUICEAASGwoPdW5wYWNrZWRfc2ludDY0GF8gAygS",
+ "QgIQABIcChB1bnBhY2tlZF9maXhlZDMyGGAgAygHQgIQABIcChB1bnBhY2tl",
+ "ZF9maXhlZDY0GGEgAygGQgIQABIdChF1bnBhY2tlZF9zZml4ZWQzMhhiIAMo",
+ "D0ICEAASHQoRdW5wYWNrZWRfc2ZpeGVkNjQYYyADKBBCAhAAEhoKDnVucGFj",
+ "a2VkX2Zsb2F0GGQgAygCQgIQABIbCg91bnBhY2tlZF9kb3VibGUYZSADKAFC",
+ "AhAAEhkKDXVucGFja2VkX2Jvb2wYZiADKAhCAhAAEjkKDXVucGFja2VkX2Vu",
+ "dW0YZyADKA4yHi5wcm90b2J1Zl91bml0dGVzdC5Gb3JlaWduRW51bUICEAAi",
+ "wAEKI1Rlc3RSZXBlYXRlZFNjYWxhckRpZmZlcmVudFRhZ1NpemVzEhgKEHJl",
+ "cGVhdGVkX2ZpeGVkMzIYDCADKAcSFgoOcmVwZWF0ZWRfaW50MzIYDSADKAUS",
+ "GQoQcmVwZWF0ZWRfZml4ZWQ2NBj+DyADKAYSFwoOcmVwZWF0ZWRfaW50NjQY",
+ "/w8gAygDEhgKDnJlcGVhdGVkX2Zsb2F0GP7/DyADKAISGQoPcmVwZWF0ZWRf",
+ "dWludDY0GP//DyADKAQiKAobVGVzdENvbW1lbnRJbmplY3Rpb25NZXNzYWdl",
+ "EgkKAWEYASABKAkiDAoKRm9vUmVxdWVzdCINCgtGb29SZXNwb25zZSISChBG",
+ "b29DbGllbnRNZXNzYWdlIhIKEEZvb1NlcnZlck1lc3NhZ2UiDAoKQmFyUmVx",
+ "dWVzdCINCgtCYXJSZXNwb25zZSpZCgtGb3JlaWduRW51bRIXChNGT1JFSUdO",
+ "X1VOU1BFQ0lGSUVEEAASDwoLRk9SRUlHTl9GT08QBBIPCgtGT1JFSUdOX0JB",
+ "UhAFEg8KC0ZPUkVJR05fQkFaEAYqdQoUVGVzdEVudW1XaXRoRHVwVmFsdWUS",
+ "KAokVEVTVF9FTlVNX1dJVEhfRFVQX1ZBTFVFX1VOU1BFQ0lGSUVEEAASCAoE",
+ "Rk9PMRABEggKBEJBUjEQAhIHCgNCQVoQAxIICgRGT08yEAESCAoEQkFSMhAC",
+ "GgIQASqdAQoOVGVzdFNwYXJzZUVudW0SIAocVEVTVF9TUEFSU0VfRU5VTV9V",
+ "TlNQRUNJRklFRBAAEgwKCFNQQVJTRV9BEHsSDgoIU1BBUlNFX0IQpucDEg8K",
+ "CFNQQVJTRV9DELKxgAYSFQoIU1BBUlNFX0QQ8f//////////ARIVCghTUEFS",
+ "U0VfRRC03vz///////8BEgwKCFNQQVJTRV9HEAIymQEKC1Rlc3RTZXJ2aWNl",
+ "EkQKA0ZvbxIdLnByb3RvYnVmX3VuaXR0ZXN0LkZvb1JlcXVlc3QaHi5wcm90",
+ "b2J1Zl91bml0dGVzdC5Gb29SZXNwb25zZRJECgNCYXISHS5wcm90b2J1Zl91",
+ "bml0dGVzdC5CYXJSZXF1ZXN0Gh4ucHJvdG9idWZfdW5pdHRlc3QuQmFyUmVz",
+ "cG9uc2VCOkINVW5pdHRlc3RQcm90b0gBgAEBiAEBkAEB+AEBqgIaR29vZ2xl",
+ "LlByb3RvYnVmLlRlc3RQcm90b3NiBnByb3RvMw=="));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { global::Google.Protobuf.TestProtos.UnittestImportProto3Reflection.Descriptor, },
+ new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Google.Protobuf.TestProtos.ForeignEnum), typeof(global::Google.Protobuf.TestProtos.TestEnumWithDupValue), typeof(global::Google.Protobuf.TestProtos.TestSparseEnum), }, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestAllTypes), global::Google.Protobuf.TestProtos.TestAllTypes.Parser, new[]{ "SingleInt32", "SingleInt64", "SingleUint32", "SingleUint64", "SingleSint32", "SingleSint64", "SingleFixed32", "SingleFixed64", "SingleSfixed32", "SingleSfixed64", "SingleFloat", "SingleDouble", "SingleBool", "SingleString", "SingleBytes", "SingleNestedMessage", "SingleForeignMessage", "SingleImportMessage", "SingleNestedEnum", "SingleForeignEnum", "SingleImportEnum", "SinglePublicImportMessage", "RepeatedInt32", "RepeatedInt64", "RepeatedUint32", "RepeatedUint64", "RepeatedSint32", "RepeatedSint64", "RepeatedFixed32", "RepeatedFixed64", "RepeatedSfixed32", "RepeatedSfixed64", "RepeatedFloat", "RepeatedDouble", "RepeatedBool", "RepeatedString", "RepeatedBytes", "RepeatedNestedMessage", "RepeatedForeignMessage", "RepeatedImportMessage", "RepeatedNestedEnum", "RepeatedForeignEnum", "RepeatedImportEnum", "RepeatedPublicImportMessage", "OneofUint32", "OneofNestedMessage", "OneofString", "OneofBytes" }, new[]{ "OneofField" }, new[]{ typeof(global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedEnum) }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage), global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage.Parser, new[]{ "Bb" }, null, null, null)}),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.NestedTestAllTypes), global::Google.Protobuf.TestProtos.NestedTestAllTypes.Parser, new[]{ "Child", "Payload", "RepeatedChild" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestDeprecatedFields), global::Google.Protobuf.TestProtos.TestDeprecatedFields.Parser, new[]{ "DeprecatedInt32" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.ForeignMessage), global::Google.Protobuf.TestProtos.ForeignMessage.Parser, new[]{ "C" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestReservedFields), global::Google.Protobuf.TestProtos.TestReservedFields.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestForeignNested), global::Google.Protobuf.TestProtos.TestForeignNested.Parser, new[]{ "ForeignNested" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestReallyLargeTagNumber), global::Google.Protobuf.TestProtos.TestReallyLargeTagNumber.Parser, new[]{ "A", "Bb" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestRecursiveMessage), global::Google.Protobuf.TestProtos.TestRecursiveMessage.Parser, new[]{ "A", "I" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestMutualRecursionA), global::Google.Protobuf.TestProtos.TestMutualRecursionA.Parser, new[]{ "Bb" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestMutualRecursionB), global::Google.Protobuf.TestProtos.TestMutualRecursionB.Parser, new[]{ "A", "OptionalInt32" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestEnumAllowAlias), global::Google.Protobuf.TestProtos.TestEnumAllowAlias.Parser, new[]{ "Value" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestCamelCaseFieldNames), global::Google.Protobuf.TestProtos.TestCamelCaseFieldNames.Parser, new[]{ "PrimitiveField", "StringField", "EnumField", "MessageField", "RepeatedPrimitiveField", "RepeatedStringField", "RepeatedEnumField", "RepeatedMessageField" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestFieldOrderings), global::Google.Protobuf.TestProtos.TestFieldOrderings.Parser, new[]{ "MyString", "MyInt", "MyFloat", "SingleNestedMessage" }, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestFieldOrderings.Types.NestedMessage), global::Google.Protobuf.TestProtos.TestFieldOrderings.Types.NestedMessage.Parser, new[]{ "Oo", "Bb" }, null, null, null)}),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.SparseEnumMessage), global::Google.Protobuf.TestProtos.SparseEnumMessage.Parser, new[]{ "SparseEnum" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.OneString), global::Google.Protobuf.TestProtos.OneString.Parser, new[]{ "Data" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.MoreString), global::Google.Protobuf.TestProtos.MoreString.Parser, new[]{ "Data" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.OneBytes), global::Google.Protobuf.TestProtos.OneBytes.Parser, new[]{ "Data" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.MoreBytes), global::Google.Protobuf.TestProtos.MoreBytes.Parser, new[]{ "Data" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Int32Message), global::Google.Protobuf.TestProtos.Int32Message.Parser, new[]{ "Data" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Uint32Message), global::Google.Protobuf.TestProtos.Uint32Message.Parser, new[]{ "Data" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Int64Message), global::Google.Protobuf.TestProtos.Int64Message.Parser, new[]{ "Data" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.Uint64Message), global::Google.Protobuf.TestProtos.Uint64Message.Parser, new[]{ "Data" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.BoolMessage), global::Google.Protobuf.TestProtos.BoolMessage.Parser, new[]{ "Data" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestOneof), global::Google.Protobuf.TestProtos.TestOneof.Parser, new[]{ "FooInt", "FooString", "FooMessage" }, new[]{ "Foo" }, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestPackedTypes), global::Google.Protobuf.TestProtos.TestPackedTypes.Parser, new[]{ "PackedInt32", "PackedInt64", "PackedUint32", "PackedUint64", "PackedSint32", "PackedSint64", "PackedFixed32", "PackedFixed64", "PackedSfixed32", "PackedSfixed64", "PackedFloat", "PackedDouble", "PackedBool", "PackedEnum" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestUnpackedTypes), global::Google.Protobuf.TestProtos.TestUnpackedTypes.Parser, new[]{ "UnpackedInt32", "UnpackedInt64", "UnpackedUint32", "UnpackedUint64", "UnpackedSint32", "UnpackedSint64", "UnpackedFixed32", "UnpackedFixed64", "UnpackedSfixed32", "UnpackedSfixed64", "UnpackedFloat", "UnpackedDouble", "UnpackedBool", "UnpackedEnum" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestRepeatedScalarDifferentTagSizes), global::Google.Protobuf.TestProtos.TestRepeatedScalarDifferentTagSizes.Parser, new[]{ "RepeatedFixed32", "RepeatedInt32", "RepeatedFixed64", "RepeatedInt64", "RepeatedFloat", "RepeatedUint64" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestCommentInjectionMessage), global::Google.Protobuf.TestProtos.TestCommentInjectionMessage.Parser, new[]{ "A" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.FooRequest), global::Google.Protobuf.TestProtos.FooRequest.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.FooResponse), global::Google.Protobuf.TestProtos.FooResponse.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.FooClientMessage), global::Google.Protobuf.TestProtos.FooClientMessage.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.FooServerMessage), global::Google.Protobuf.TestProtos.FooServerMessage.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.BarRequest), global::Google.Protobuf.TestProtos.BarRequest.Parser, null, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.BarResponse), global::Google.Protobuf.TestProtos.BarResponse.Parser, null, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Enums
+ public enum ForeignEnum {
+ [pbr::OriginalName("FOREIGN_UNSPECIFIED")] ForeignUnspecified = 0,
+ [pbr::OriginalName("FOREIGN_FOO")] ForeignFoo = 4,
+ [pbr::OriginalName("FOREIGN_BAR")] ForeignBar = 5,
+ [pbr::OriginalName("FOREIGN_BAZ")] ForeignBaz = 6,
+ }
+
+ /// <summary>
+ /// Test an enum that has multiple values with the same number.
+ /// </summary>
+ public enum TestEnumWithDupValue {
+ [pbr::OriginalName("TEST_ENUM_WITH_DUP_VALUE_UNSPECIFIED")] Unspecified = 0,
+ [pbr::OriginalName("FOO1")] Foo1 = 1,
+ [pbr::OriginalName("BAR1")] Bar1 = 2,
+ [pbr::OriginalName("BAZ")] Baz = 3,
+ [pbr::OriginalName("FOO2", PreferredAlias = false)] Foo2 = 1,
+ [pbr::OriginalName("BAR2", PreferredAlias = false)] Bar2 = 2,
+ }
+
+ /// <summary>
+ /// Test an enum with large, unordered values.
+ /// </summary>
+ public enum TestSparseEnum {
+ [pbr::OriginalName("TEST_SPARSE_ENUM_UNSPECIFIED")] Unspecified = 0,
+ [pbr::OriginalName("SPARSE_A")] SparseA = 123,
+ [pbr::OriginalName("SPARSE_B")] SparseB = 62374,
+ [pbr::OriginalName("SPARSE_C")] SparseC = 12589234,
+ [pbr::OriginalName("SPARSE_D")] SparseD = -15,
+ [pbr::OriginalName("SPARSE_E")] SparseE = -53452,
+ /// <summary>
+ /// In proto3, value 0 must be the first one specified
+ /// SPARSE_F = 0;
+ /// </summary>
+ [pbr::OriginalName("SPARSE_G")] SparseG = 2,
+ }
+
+ #endregion
+
+ #region Messages
+ /// <summary>
+ /// This proto includes every type of field in both singular and repeated
+ /// forms.
+ /// </summary>
+ public sealed partial class TestAllTypes : pb::IMessage<TestAllTypes> {
+ private static readonly pb::MessageParser<TestAllTypes> _parser = new pb::MessageParser<TestAllTypes>(() => new TestAllTypes());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestAllTypes> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestAllTypes() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestAllTypes(TestAllTypes other) : this() {
+ singleInt32_ = other.singleInt32_;
+ singleInt64_ = other.singleInt64_;
+ singleUint32_ = other.singleUint32_;
+ singleUint64_ = other.singleUint64_;
+ singleSint32_ = other.singleSint32_;
+ singleSint64_ = other.singleSint64_;
+ singleFixed32_ = other.singleFixed32_;
+ singleFixed64_ = other.singleFixed64_;
+ singleSfixed32_ = other.singleSfixed32_;
+ singleSfixed64_ = other.singleSfixed64_;
+ singleFloat_ = other.singleFloat_;
+ singleDouble_ = other.singleDouble_;
+ singleBool_ = other.singleBool_;
+ singleString_ = other.singleString_;
+ singleBytes_ = other.singleBytes_;
+ SingleNestedMessage = other.singleNestedMessage_ != null ? other.SingleNestedMessage.Clone() : null;
+ SingleForeignMessage = other.singleForeignMessage_ != null ? other.SingleForeignMessage.Clone() : null;
+ SingleImportMessage = other.singleImportMessage_ != null ? other.SingleImportMessage.Clone() : null;
+ singleNestedEnum_ = other.singleNestedEnum_;
+ singleForeignEnum_ = other.singleForeignEnum_;
+ singleImportEnum_ = other.singleImportEnum_;
+ SinglePublicImportMessage = other.singlePublicImportMessage_ != null ? other.SinglePublicImportMessage.Clone() : null;
+ repeatedInt32_ = other.repeatedInt32_.Clone();
+ repeatedInt64_ = other.repeatedInt64_.Clone();
+ repeatedUint32_ = other.repeatedUint32_.Clone();
+ repeatedUint64_ = other.repeatedUint64_.Clone();
+ repeatedSint32_ = other.repeatedSint32_.Clone();
+ repeatedSint64_ = other.repeatedSint64_.Clone();
+ repeatedFixed32_ = other.repeatedFixed32_.Clone();
+ repeatedFixed64_ = other.repeatedFixed64_.Clone();
+ repeatedSfixed32_ = other.repeatedSfixed32_.Clone();
+ repeatedSfixed64_ = other.repeatedSfixed64_.Clone();
+ repeatedFloat_ = other.repeatedFloat_.Clone();
+ repeatedDouble_ = other.repeatedDouble_.Clone();
+ repeatedBool_ = other.repeatedBool_.Clone();
+ repeatedString_ = other.repeatedString_.Clone();
+ repeatedBytes_ = other.repeatedBytes_.Clone();
+ repeatedNestedMessage_ = other.repeatedNestedMessage_.Clone();
+ repeatedForeignMessage_ = other.repeatedForeignMessage_.Clone();
+ repeatedImportMessage_ = other.repeatedImportMessage_.Clone();
+ repeatedNestedEnum_ = other.repeatedNestedEnum_.Clone();
+ repeatedForeignEnum_ = other.repeatedForeignEnum_.Clone();
+ repeatedImportEnum_ = other.repeatedImportEnum_.Clone();
+ repeatedPublicImportMessage_ = other.repeatedPublicImportMessage_.Clone();
+ switch (other.OneofFieldCase) {
+ case OneofFieldOneofCase.OneofUint32:
+ OneofUint32 = other.OneofUint32;
+ break;
+ case OneofFieldOneofCase.OneofNestedMessage:
+ OneofNestedMessage = other.OneofNestedMessage.Clone();
+ break;
+ case OneofFieldOneofCase.OneofString:
+ OneofString = other.OneofString;
+ break;
+ case OneofFieldOneofCase.OneofBytes:
+ OneofBytes = other.OneofBytes;
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestAllTypes Clone() {
+ return new TestAllTypes(this);
+ }
+
+ /// <summary>Field number for the "single_int32" field.</summary>
+ public const int SingleInt32FieldNumber = 1;
+ private int singleInt32_;
+ /// <summary>
+ /// Singular
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int SingleInt32 {
+ get { return singleInt32_; }
+ set {
+ singleInt32_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_int64" field.</summary>
+ public const int SingleInt64FieldNumber = 2;
+ private long singleInt64_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public long SingleInt64 {
+ get { return singleInt64_; }
+ set {
+ singleInt64_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_uint32" field.</summary>
+ public const int SingleUint32FieldNumber = 3;
+ private uint singleUint32_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public uint SingleUint32 {
+ get { return singleUint32_; }
+ set {
+ singleUint32_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_uint64" field.</summary>
+ public const int SingleUint64FieldNumber = 4;
+ private ulong singleUint64_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ulong SingleUint64 {
+ get { return singleUint64_; }
+ set {
+ singleUint64_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_sint32" field.</summary>
+ public const int SingleSint32FieldNumber = 5;
+ private int singleSint32_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int SingleSint32 {
+ get { return singleSint32_; }
+ set {
+ singleSint32_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_sint64" field.</summary>
+ public const int SingleSint64FieldNumber = 6;
+ private long singleSint64_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public long SingleSint64 {
+ get { return singleSint64_; }
+ set {
+ singleSint64_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_fixed32" field.</summary>
+ public const int SingleFixed32FieldNumber = 7;
+ private uint singleFixed32_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public uint SingleFixed32 {
+ get { return singleFixed32_; }
+ set {
+ singleFixed32_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_fixed64" field.</summary>
+ public const int SingleFixed64FieldNumber = 8;
+ private ulong singleFixed64_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ulong SingleFixed64 {
+ get { return singleFixed64_; }
+ set {
+ singleFixed64_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_sfixed32" field.</summary>
+ public const int SingleSfixed32FieldNumber = 9;
+ private int singleSfixed32_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int SingleSfixed32 {
+ get { return singleSfixed32_; }
+ set {
+ singleSfixed32_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_sfixed64" field.</summary>
+ public const int SingleSfixed64FieldNumber = 10;
+ private long singleSfixed64_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public long SingleSfixed64 {
+ get { return singleSfixed64_; }
+ set {
+ singleSfixed64_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_float" field.</summary>
+ public const int SingleFloatFieldNumber = 11;
+ private float singleFloat_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public float SingleFloat {
+ get { return singleFloat_; }
+ set {
+ singleFloat_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_double" field.</summary>
+ public const int SingleDoubleFieldNumber = 12;
+ private double singleDouble_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public double SingleDouble {
+ get { return singleDouble_; }
+ set {
+ singleDouble_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_bool" field.</summary>
+ public const int SingleBoolFieldNumber = 13;
+ private bool singleBool_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool SingleBool {
+ get { return singleBool_; }
+ set {
+ singleBool_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_string" field.</summary>
+ public const int SingleStringFieldNumber = 14;
+ private string singleString_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string SingleString {
+ get { return singleString_; }
+ set {
+ singleString_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "single_bytes" field.</summary>
+ public const int SingleBytesFieldNumber = 15;
+ private pb::ByteString singleBytes_ = pb::ByteString.Empty;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pb::ByteString SingleBytes {
+ get { return singleBytes_; }
+ set {
+ singleBytes_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "single_nested_message" field.</summary>
+ public const int SingleNestedMessageFieldNumber = 18;
+ private global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage singleNestedMessage_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage SingleNestedMessage {
+ get { return singleNestedMessage_; }
+ set {
+ singleNestedMessage_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_foreign_message" field.</summary>
+ public const int SingleForeignMessageFieldNumber = 19;
+ private global::Google.Protobuf.TestProtos.ForeignMessage singleForeignMessage_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.ForeignMessage SingleForeignMessage {
+ get { return singleForeignMessage_; }
+ set {
+ singleForeignMessage_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_import_message" field.</summary>
+ public const int SingleImportMessageFieldNumber = 20;
+ private global::Google.Protobuf.TestProtos.ImportMessage singleImportMessage_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.ImportMessage SingleImportMessage {
+ get { return singleImportMessage_; }
+ set {
+ singleImportMessage_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_nested_enum" field.</summary>
+ public const int SingleNestedEnumFieldNumber = 21;
+ private global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedEnum singleNestedEnum_ = 0;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedEnum SingleNestedEnum {
+ get { return singleNestedEnum_; }
+ set {
+ singleNestedEnum_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_foreign_enum" field.</summary>
+ public const int SingleForeignEnumFieldNumber = 22;
+ private global::Google.Protobuf.TestProtos.ForeignEnum singleForeignEnum_ = 0;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.ForeignEnum SingleForeignEnum {
+ get { return singleForeignEnum_; }
+ set {
+ singleForeignEnum_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_import_enum" field.</summary>
+ public const int SingleImportEnumFieldNumber = 23;
+ private global::Google.Protobuf.TestProtos.ImportEnum singleImportEnum_ = 0;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.ImportEnum SingleImportEnum {
+ get { return singleImportEnum_; }
+ set {
+ singleImportEnum_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_public_import_message" field.</summary>
+ public const int SinglePublicImportMessageFieldNumber = 26;
+ private global::Google.Protobuf.TestProtos.PublicImportMessage singlePublicImportMessage_;
+ /// <summary>
+ /// Defined in unittest_import_public.proto
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.PublicImportMessage SinglePublicImportMessage {
+ get { return singlePublicImportMessage_; }
+ set {
+ singlePublicImportMessage_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "repeated_int32" field.</summary>
+ public const int RepeatedInt32FieldNumber = 31;
+ private static readonly pb::FieldCodec<int> _repeated_repeatedInt32_codec
+ = pb::FieldCodec.ForInt32(250);
+ private readonly pbc::RepeatedField<int> repeatedInt32_ = new pbc::RepeatedField<int>();
+ /// <summary>
+ /// Repeated
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> RepeatedInt32 {
+ get { return repeatedInt32_; }
+ }
+
+ /// <summary>Field number for the "repeated_int64" field.</summary>
+ public const int RepeatedInt64FieldNumber = 32;
+ private static readonly pb::FieldCodec<long> _repeated_repeatedInt64_codec
+ = pb::FieldCodec.ForInt64(258);
+ private readonly pbc::RepeatedField<long> repeatedInt64_ = new pbc::RepeatedField<long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<long> RepeatedInt64 {
+ get { return repeatedInt64_; }
+ }
+
+ /// <summary>Field number for the "repeated_uint32" field.</summary>
+ public const int RepeatedUint32FieldNumber = 33;
+ private static readonly pb::FieldCodec<uint> _repeated_repeatedUint32_codec
+ = pb::FieldCodec.ForUInt32(266);
+ private readonly pbc::RepeatedField<uint> repeatedUint32_ = new pbc::RepeatedField<uint>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<uint> RepeatedUint32 {
+ get { return repeatedUint32_; }
+ }
+
+ /// <summary>Field number for the "repeated_uint64" field.</summary>
+ public const int RepeatedUint64FieldNumber = 34;
+ private static readonly pb::FieldCodec<ulong> _repeated_repeatedUint64_codec
+ = pb::FieldCodec.ForUInt64(274);
+ private readonly pbc::RepeatedField<ulong> repeatedUint64_ = new pbc::RepeatedField<ulong>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<ulong> RepeatedUint64 {
+ get { return repeatedUint64_; }
+ }
+
+ /// <summary>Field number for the "repeated_sint32" field.</summary>
+ public const int RepeatedSint32FieldNumber = 35;
+ private static readonly pb::FieldCodec<int> _repeated_repeatedSint32_codec
+ = pb::FieldCodec.ForSInt32(282);
+ private readonly pbc::RepeatedField<int> repeatedSint32_ = new pbc::RepeatedField<int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> RepeatedSint32 {
+ get { return repeatedSint32_; }
+ }
+
+ /// <summary>Field number for the "repeated_sint64" field.</summary>
+ public const int RepeatedSint64FieldNumber = 36;
+ private static readonly pb::FieldCodec<long> _repeated_repeatedSint64_codec
+ = pb::FieldCodec.ForSInt64(290);
+ private readonly pbc::RepeatedField<long> repeatedSint64_ = new pbc::RepeatedField<long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<long> RepeatedSint64 {
+ get { return repeatedSint64_; }
+ }
+
+ /// <summary>Field number for the "repeated_fixed32" field.</summary>
+ public const int RepeatedFixed32FieldNumber = 37;
+ private static readonly pb::FieldCodec<uint> _repeated_repeatedFixed32_codec
+ = pb::FieldCodec.ForFixed32(298);
+ private readonly pbc::RepeatedField<uint> repeatedFixed32_ = new pbc::RepeatedField<uint>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<uint> RepeatedFixed32 {
+ get { return repeatedFixed32_; }
+ }
+
+ /// <summary>Field number for the "repeated_fixed64" field.</summary>
+ public const int RepeatedFixed64FieldNumber = 38;
+ private static readonly pb::FieldCodec<ulong> _repeated_repeatedFixed64_codec
+ = pb::FieldCodec.ForFixed64(306);
+ private readonly pbc::RepeatedField<ulong> repeatedFixed64_ = new pbc::RepeatedField<ulong>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<ulong> RepeatedFixed64 {
+ get { return repeatedFixed64_; }
+ }
+
+ /// <summary>Field number for the "repeated_sfixed32" field.</summary>
+ public const int RepeatedSfixed32FieldNumber = 39;
+ private static readonly pb::FieldCodec<int> _repeated_repeatedSfixed32_codec
+ = pb::FieldCodec.ForSFixed32(314);
+ private readonly pbc::RepeatedField<int> repeatedSfixed32_ = new pbc::RepeatedField<int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> RepeatedSfixed32 {
+ get { return repeatedSfixed32_; }
+ }
+
+ /// <summary>Field number for the "repeated_sfixed64" field.</summary>
+ public const int RepeatedSfixed64FieldNumber = 40;
+ private static readonly pb::FieldCodec<long> _repeated_repeatedSfixed64_codec
+ = pb::FieldCodec.ForSFixed64(322);
+ private readonly pbc::RepeatedField<long> repeatedSfixed64_ = new pbc::RepeatedField<long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<long> RepeatedSfixed64 {
+ get { return repeatedSfixed64_; }
+ }
+
+ /// <summary>Field number for the "repeated_float" field.</summary>
+ public const int RepeatedFloatFieldNumber = 41;
+ private static readonly pb::FieldCodec<float> _repeated_repeatedFloat_codec
+ = pb::FieldCodec.ForFloat(330);
+ private readonly pbc::RepeatedField<float> repeatedFloat_ = new pbc::RepeatedField<float>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<float> RepeatedFloat {
+ get { return repeatedFloat_; }
+ }
+
+ /// <summary>Field number for the "repeated_double" field.</summary>
+ public const int RepeatedDoubleFieldNumber = 42;
+ private static readonly pb::FieldCodec<double> _repeated_repeatedDouble_codec
+ = pb::FieldCodec.ForDouble(338);
+ private readonly pbc::RepeatedField<double> repeatedDouble_ = new pbc::RepeatedField<double>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<double> RepeatedDouble {
+ get { return repeatedDouble_; }
+ }
+
+ /// <summary>Field number for the "repeated_bool" field.</summary>
+ public const int RepeatedBoolFieldNumber = 43;
+ private static readonly pb::FieldCodec<bool> _repeated_repeatedBool_codec
+ = pb::FieldCodec.ForBool(346);
+ private readonly pbc::RepeatedField<bool> repeatedBool_ = new pbc::RepeatedField<bool>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<bool> RepeatedBool {
+ get { return repeatedBool_; }
+ }
+
+ /// <summary>Field number for the "repeated_string" field.</summary>
+ public const int RepeatedStringFieldNumber = 44;
+ private static readonly pb::FieldCodec<string> _repeated_repeatedString_codec
+ = pb::FieldCodec.ForString(354);
+ private readonly pbc::RepeatedField<string> repeatedString_ = new pbc::RepeatedField<string>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<string> RepeatedString {
+ get { return repeatedString_; }
+ }
+
+ /// <summary>Field number for the "repeated_bytes" field.</summary>
+ public const int RepeatedBytesFieldNumber = 45;
+ private static readonly pb::FieldCodec<pb::ByteString> _repeated_repeatedBytes_codec
+ = pb::FieldCodec.ForBytes(362);
+ private readonly pbc::RepeatedField<pb::ByteString> repeatedBytes_ = new pbc::RepeatedField<pb::ByteString>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<pb::ByteString> RepeatedBytes {
+ get { return repeatedBytes_; }
+ }
+
+ /// <summary>Field number for the "repeated_nested_message" field.</summary>
+ public const int RepeatedNestedMessageFieldNumber = 48;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage> _repeated_repeatedNestedMessage_codec
+ = pb::FieldCodec.ForMessage(386, global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage> repeatedNestedMessage_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage> RepeatedNestedMessage {
+ get { return repeatedNestedMessage_; }
+ }
+
+ /// <summary>Field number for the "repeated_foreign_message" field.</summary>
+ public const int RepeatedForeignMessageFieldNumber = 49;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.ForeignMessage> _repeated_repeatedForeignMessage_codec
+ = pb::FieldCodec.ForMessage(394, global::Google.Protobuf.TestProtos.ForeignMessage.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignMessage> repeatedForeignMessage_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignMessage>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignMessage> RepeatedForeignMessage {
+ get { return repeatedForeignMessage_; }
+ }
+
+ /// <summary>Field number for the "repeated_import_message" field.</summary>
+ public const int RepeatedImportMessageFieldNumber = 50;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.ImportMessage> _repeated_repeatedImportMessage_codec
+ = pb::FieldCodec.ForMessage(402, global::Google.Protobuf.TestProtos.ImportMessage.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.ImportMessage> repeatedImportMessage_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.ImportMessage>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.TestProtos.ImportMessage> RepeatedImportMessage {
+ get { return repeatedImportMessage_; }
+ }
+
+ /// <summary>Field number for the "repeated_nested_enum" field.</summary>
+ public const int RepeatedNestedEnumFieldNumber = 51;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedEnum> _repeated_repeatedNestedEnum_codec
+ = pb::FieldCodec.ForEnum(410, x => (int) x, x => (global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedEnum) x);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedEnum> repeatedNestedEnum_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedEnum>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedEnum> RepeatedNestedEnum {
+ get { return repeatedNestedEnum_; }
+ }
+
+ /// <summary>Field number for the "repeated_foreign_enum" field.</summary>
+ public const int RepeatedForeignEnumFieldNumber = 52;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.ForeignEnum> _repeated_repeatedForeignEnum_codec
+ = pb::FieldCodec.ForEnum(418, x => (int) x, x => (global::Google.Protobuf.TestProtos.ForeignEnum) x);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignEnum> repeatedForeignEnum_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignEnum>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignEnum> RepeatedForeignEnum {
+ get { return repeatedForeignEnum_; }
+ }
+
+ /// <summary>Field number for the "repeated_import_enum" field.</summary>
+ public const int RepeatedImportEnumFieldNumber = 53;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.ImportEnum> _repeated_repeatedImportEnum_codec
+ = pb::FieldCodec.ForEnum(426, x => (int) x, x => (global::Google.Protobuf.TestProtos.ImportEnum) x);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.ImportEnum> repeatedImportEnum_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.ImportEnum>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.TestProtos.ImportEnum> RepeatedImportEnum {
+ get { return repeatedImportEnum_; }
+ }
+
+ /// <summary>Field number for the "repeated_public_import_message" field.</summary>
+ public const int RepeatedPublicImportMessageFieldNumber = 54;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.PublicImportMessage> _repeated_repeatedPublicImportMessage_codec
+ = pb::FieldCodec.ForMessage(434, global::Google.Protobuf.TestProtos.PublicImportMessage.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.PublicImportMessage> repeatedPublicImportMessage_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.PublicImportMessage>();
+ /// <summary>
+ /// Defined in unittest_import_public.proto
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.TestProtos.PublicImportMessage> RepeatedPublicImportMessage {
+ get { return repeatedPublicImportMessage_; }
+ }
+
+ /// <summary>Field number for the "oneof_uint32" field.</summary>
+ public const int OneofUint32FieldNumber = 111;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public uint OneofUint32 {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.OneofUint32 ? (uint) oneofField_ : 0; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = OneofFieldOneofCase.OneofUint32;
+ }
+ }
+
+ /// <summary>Field number for the "oneof_nested_message" field.</summary>
+ public const int OneofNestedMessageFieldNumber = 112;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage OneofNestedMessage {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage ? (global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage) oneofField_ : null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.OneofNestedMessage;
+ }
+ }
+
+ /// <summary>Field number for the "oneof_string" field.</summary>
+ public const int OneofStringFieldNumber = 113;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string OneofString {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.OneofString ? (string) oneofField_ : ""; }
+ set {
+ oneofField_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ oneofFieldCase_ = OneofFieldOneofCase.OneofString;
+ }
+ }
+
+ /// <summary>Field number for the "oneof_bytes" field.</summary>
+ public const int OneofBytesFieldNumber = 114;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pb::ByteString OneofBytes {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.OneofBytes ? (pb::ByteString) oneofField_ : pb::ByteString.Empty; }
+ set {
+ oneofField_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ oneofFieldCase_ = OneofFieldOneofCase.OneofBytes;
+ }
+ }
+
+ private object oneofField_;
+ /// <summary>Enum of possible cases for the "oneof_field" oneof.</summary>
+ public enum OneofFieldOneofCase {
+ None = 0,
+ OneofUint32 = 111,
+ OneofNestedMessage = 112,
+ OneofString = 113,
+ OneofBytes = 114,
+ }
+ private OneofFieldOneofCase oneofFieldCase_ = OneofFieldOneofCase.None;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneofFieldOneofCase OneofFieldCase {
+ get { return oneofFieldCase_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearOneofField() {
+ oneofFieldCase_ = OneofFieldOneofCase.None;
+ oneofField_ = null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestAllTypes);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestAllTypes other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (SingleInt32 != other.SingleInt32) return false;
+ if (SingleInt64 != other.SingleInt64) return false;
+ if (SingleUint32 != other.SingleUint32) return false;
+ if (SingleUint64 != other.SingleUint64) return false;
+ if (SingleSint32 != other.SingleSint32) return false;
+ if (SingleSint64 != other.SingleSint64) return false;
+ if (SingleFixed32 != other.SingleFixed32) return false;
+ if (SingleFixed64 != other.SingleFixed64) return false;
+ if (SingleSfixed32 != other.SingleSfixed32) return false;
+ if (SingleSfixed64 != other.SingleSfixed64) return false;
+ if (SingleFloat != other.SingleFloat) return false;
+ if (SingleDouble != other.SingleDouble) return false;
+ if (SingleBool != other.SingleBool) return false;
+ if (SingleString != other.SingleString) return false;
+ if (SingleBytes != other.SingleBytes) return false;
+ if (!object.Equals(SingleNestedMessage, other.SingleNestedMessage)) return false;
+ if (!object.Equals(SingleForeignMessage, other.SingleForeignMessage)) return false;
+ if (!object.Equals(SingleImportMessage, other.SingleImportMessage)) return false;
+ if (SingleNestedEnum != other.SingleNestedEnum) return false;
+ if (SingleForeignEnum != other.SingleForeignEnum) return false;
+ if (SingleImportEnum != other.SingleImportEnum) return false;
+ if (!object.Equals(SinglePublicImportMessage, other.SinglePublicImportMessage)) return false;
+ if(!repeatedInt32_.Equals(other.repeatedInt32_)) return false;
+ if(!repeatedInt64_.Equals(other.repeatedInt64_)) return false;
+ if(!repeatedUint32_.Equals(other.repeatedUint32_)) return false;
+ if(!repeatedUint64_.Equals(other.repeatedUint64_)) return false;
+ if(!repeatedSint32_.Equals(other.repeatedSint32_)) return false;
+ if(!repeatedSint64_.Equals(other.repeatedSint64_)) return false;
+ if(!repeatedFixed32_.Equals(other.repeatedFixed32_)) return false;
+ if(!repeatedFixed64_.Equals(other.repeatedFixed64_)) return false;
+ if(!repeatedSfixed32_.Equals(other.repeatedSfixed32_)) return false;
+ if(!repeatedSfixed64_.Equals(other.repeatedSfixed64_)) return false;
+ if(!repeatedFloat_.Equals(other.repeatedFloat_)) return false;
+ if(!repeatedDouble_.Equals(other.repeatedDouble_)) return false;
+ if(!repeatedBool_.Equals(other.repeatedBool_)) return false;
+ if(!repeatedString_.Equals(other.repeatedString_)) return false;
+ if(!repeatedBytes_.Equals(other.repeatedBytes_)) return false;
+ if(!repeatedNestedMessage_.Equals(other.repeatedNestedMessage_)) return false;
+ if(!repeatedForeignMessage_.Equals(other.repeatedForeignMessage_)) return false;
+ if(!repeatedImportMessage_.Equals(other.repeatedImportMessage_)) return false;
+ if(!repeatedNestedEnum_.Equals(other.repeatedNestedEnum_)) return false;
+ if(!repeatedForeignEnum_.Equals(other.repeatedForeignEnum_)) return false;
+ if(!repeatedImportEnum_.Equals(other.repeatedImportEnum_)) return false;
+ if(!repeatedPublicImportMessage_.Equals(other.repeatedPublicImportMessage_)) return false;
+ if (OneofUint32 != other.OneofUint32) return false;
+ if (!object.Equals(OneofNestedMessage, other.OneofNestedMessage)) return false;
+ if (OneofString != other.OneofString) return false;
+ if (OneofBytes != other.OneofBytes) return false;
+ if (OneofFieldCase != other.OneofFieldCase) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (SingleInt32 != 0) hash ^= SingleInt32.GetHashCode();
+ if (SingleInt64 != 0L) hash ^= SingleInt64.GetHashCode();
+ if (SingleUint32 != 0) hash ^= SingleUint32.GetHashCode();
+ if (SingleUint64 != 0UL) hash ^= SingleUint64.GetHashCode();
+ if (SingleSint32 != 0) hash ^= SingleSint32.GetHashCode();
+ if (SingleSint64 != 0L) hash ^= SingleSint64.GetHashCode();
+ if (SingleFixed32 != 0) hash ^= SingleFixed32.GetHashCode();
+ if (SingleFixed64 != 0UL) hash ^= SingleFixed64.GetHashCode();
+ if (SingleSfixed32 != 0) hash ^= SingleSfixed32.GetHashCode();
+ if (SingleSfixed64 != 0L) hash ^= SingleSfixed64.GetHashCode();
+ if (SingleFloat != 0F) hash ^= SingleFloat.GetHashCode();
+ if (SingleDouble != 0D) hash ^= SingleDouble.GetHashCode();
+ if (SingleBool != false) hash ^= SingleBool.GetHashCode();
+ if (SingleString.Length != 0) hash ^= SingleString.GetHashCode();
+ if (SingleBytes.Length != 0) hash ^= SingleBytes.GetHashCode();
+ if (singleNestedMessage_ != null) hash ^= SingleNestedMessage.GetHashCode();
+ if (singleForeignMessage_ != null) hash ^= SingleForeignMessage.GetHashCode();
+ if (singleImportMessage_ != null) hash ^= SingleImportMessage.GetHashCode();
+ if (SingleNestedEnum != 0) hash ^= SingleNestedEnum.GetHashCode();
+ if (SingleForeignEnum != 0) hash ^= SingleForeignEnum.GetHashCode();
+ if (SingleImportEnum != 0) hash ^= SingleImportEnum.GetHashCode();
+ if (singlePublicImportMessage_ != null) hash ^= SinglePublicImportMessage.GetHashCode();
+ hash ^= repeatedInt32_.GetHashCode();
+ hash ^= repeatedInt64_.GetHashCode();
+ hash ^= repeatedUint32_.GetHashCode();
+ hash ^= repeatedUint64_.GetHashCode();
+ hash ^= repeatedSint32_.GetHashCode();
+ hash ^= repeatedSint64_.GetHashCode();
+ hash ^= repeatedFixed32_.GetHashCode();
+ hash ^= repeatedFixed64_.GetHashCode();
+ hash ^= repeatedSfixed32_.GetHashCode();
+ hash ^= repeatedSfixed64_.GetHashCode();
+ hash ^= repeatedFloat_.GetHashCode();
+ hash ^= repeatedDouble_.GetHashCode();
+ hash ^= repeatedBool_.GetHashCode();
+ hash ^= repeatedString_.GetHashCode();
+ hash ^= repeatedBytes_.GetHashCode();
+ hash ^= repeatedNestedMessage_.GetHashCode();
+ hash ^= repeatedForeignMessage_.GetHashCode();
+ hash ^= repeatedImportMessage_.GetHashCode();
+ hash ^= repeatedNestedEnum_.GetHashCode();
+ hash ^= repeatedForeignEnum_.GetHashCode();
+ hash ^= repeatedImportEnum_.GetHashCode();
+ hash ^= repeatedPublicImportMessage_.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint32) hash ^= OneofUint32.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) hash ^= OneofNestedMessage.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofString) hash ^= OneofString.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofBytes) hash ^= OneofBytes.GetHashCode();
+ hash ^= (int) oneofFieldCase_;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (SingleInt32 != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(SingleInt32);
+ }
+ if (SingleInt64 != 0L) {
+ output.WriteRawTag(16);
+ output.WriteInt64(SingleInt64);
+ }
+ if (SingleUint32 != 0) {
+ output.WriteRawTag(24);
+ output.WriteUInt32(SingleUint32);
+ }
+ if (SingleUint64 != 0UL) {
+ output.WriteRawTag(32);
+ output.WriteUInt64(SingleUint64);
+ }
+ if (SingleSint32 != 0) {
+ output.WriteRawTag(40);
+ output.WriteSInt32(SingleSint32);
+ }
+ if (SingleSint64 != 0L) {
+ output.WriteRawTag(48);
+ output.WriteSInt64(SingleSint64);
+ }
+ if (SingleFixed32 != 0) {
+ output.WriteRawTag(61);
+ output.WriteFixed32(SingleFixed32);
+ }
+ if (SingleFixed64 != 0UL) {
+ output.WriteRawTag(65);
+ output.WriteFixed64(SingleFixed64);
+ }
+ if (SingleSfixed32 != 0) {
+ output.WriteRawTag(77);
+ output.WriteSFixed32(SingleSfixed32);
+ }
+ if (SingleSfixed64 != 0L) {
+ output.WriteRawTag(81);
+ output.WriteSFixed64(SingleSfixed64);
+ }
+ if (SingleFloat != 0F) {
+ output.WriteRawTag(93);
+ output.WriteFloat(SingleFloat);
+ }
+ if (SingleDouble != 0D) {
+ output.WriteRawTag(97);
+ output.WriteDouble(SingleDouble);
+ }
+ if (SingleBool != false) {
+ output.WriteRawTag(104);
+ output.WriteBool(SingleBool);
+ }
+ if (SingleString.Length != 0) {
+ output.WriteRawTag(114);
+ output.WriteString(SingleString);
+ }
+ if (SingleBytes.Length != 0) {
+ output.WriteRawTag(122);
+ output.WriteBytes(SingleBytes);
+ }
+ if (singleNestedMessage_ != null) {
+ output.WriteRawTag(146, 1);
+ output.WriteMessage(SingleNestedMessage);
+ }
+ if (singleForeignMessage_ != null) {
+ output.WriteRawTag(154, 1);
+ output.WriteMessage(SingleForeignMessage);
+ }
+ if (singleImportMessage_ != null) {
+ output.WriteRawTag(162, 1);
+ output.WriteMessage(SingleImportMessage);
+ }
+ if (SingleNestedEnum != 0) {
+ output.WriteRawTag(168, 1);
+ output.WriteEnum((int) SingleNestedEnum);
+ }
+ if (SingleForeignEnum != 0) {
+ output.WriteRawTag(176, 1);
+ output.WriteEnum((int) SingleForeignEnum);
+ }
+ if (SingleImportEnum != 0) {
+ output.WriteRawTag(184, 1);
+ output.WriteEnum((int) SingleImportEnum);
+ }
+ if (singlePublicImportMessage_ != null) {
+ output.WriteRawTag(210, 1);
+ output.WriteMessage(SinglePublicImportMessage);
+ }
+ repeatedInt32_.WriteTo(output, _repeated_repeatedInt32_codec);
+ repeatedInt64_.WriteTo(output, _repeated_repeatedInt64_codec);
+ repeatedUint32_.WriteTo(output, _repeated_repeatedUint32_codec);
+ repeatedUint64_.WriteTo(output, _repeated_repeatedUint64_codec);
+ repeatedSint32_.WriteTo(output, _repeated_repeatedSint32_codec);
+ repeatedSint64_.WriteTo(output, _repeated_repeatedSint64_codec);
+ repeatedFixed32_.WriteTo(output, _repeated_repeatedFixed32_codec);
+ repeatedFixed64_.WriteTo(output, _repeated_repeatedFixed64_codec);
+ repeatedSfixed32_.WriteTo(output, _repeated_repeatedSfixed32_codec);
+ repeatedSfixed64_.WriteTo(output, _repeated_repeatedSfixed64_codec);
+ repeatedFloat_.WriteTo(output, _repeated_repeatedFloat_codec);
+ repeatedDouble_.WriteTo(output, _repeated_repeatedDouble_codec);
+ repeatedBool_.WriteTo(output, _repeated_repeatedBool_codec);
+ repeatedString_.WriteTo(output, _repeated_repeatedString_codec);
+ repeatedBytes_.WriteTo(output, _repeated_repeatedBytes_codec);
+ repeatedNestedMessage_.WriteTo(output, _repeated_repeatedNestedMessage_codec);
+ repeatedForeignMessage_.WriteTo(output, _repeated_repeatedForeignMessage_codec);
+ repeatedImportMessage_.WriteTo(output, _repeated_repeatedImportMessage_codec);
+ repeatedNestedEnum_.WriteTo(output, _repeated_repeatedNestedEnum_codec);
+ repeatedForeignEnum_.WriteTo(output, _repeated_repeatedForeignEnum_codec);
+ repeatedImportEnum_.WriteTo(output, _repeated_repeatedImportEnum_codec);
+ repeatedPublicImportMessage_.WriteTo(output, _repeated_repeatedPublicImportMessage_codec);
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint32) {
+ output.WriteRawTag(248, 6);
+ output.WriteUInt32(OneofUint32);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) {
+ output.WriteRawTag(130, 7);
+ output.WriteMessage(OneofNestedMessage);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofString) {
+ output.WriteRawTag(138, 7);
+ output.WriteString(OneofString);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofBytes) {
+ output.WriteRawTag(146, 7);
+ output.WriteBytes(OneofBytes);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (SingleInt32 != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(SingleInt32);
+ }
+ if (SingleInt64 != 0L) {
+ size += 1 + pb::CodedOutputStream.ComputeInt64Size(SingleInt64);
+ }
+ if (SingleUint32 != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeUInt32Size(SingleUint32);
+ }
+ if (SingleUint64 != 0UL) {
+ size += 1 + pb::CodedOutputStream.ComputeUInt64Size(SingleUint64);
+ }
+ if (SingleSint32 != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeSInt32Size(SingleSint32);
+ }
+ if (SingleSint64 != 0L) {
+ size += 1 + pb::CodedOutputStream.ComputeSInt64Size(SingleSint64);
+ }
+ if (SingleFixed32 != 0) {
+ size += 1 + 4;
+ }
+ if (SingleFixed64 != 0UL) {
+ size += 1 + 8;
+ }
+ if (SingleSfixed32 != 0) {
+ size += 1 + 4;
+ }
+ if (SingleSfixed64 != 0L) {
+ size += 1 + 8;
+ }
+ if (SingleFloat != 0F) {
+ size += 1 + 4;
+ }
+ if (SingleDouble != 0D) {
+ size += 1 + 8;
+ }
+ if (SingleBool != false) {
+ size += 1 + 1;
+ }
+ if (SingleString.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(SingleString);
+ }
+ if (SingleBytes.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeBytesSize(SingleBytes);
+ }
+ if (singleNestedMessage_ != null) {
+ size += 2 + pb::CodedOutputStream.ComputeMessageSize(SingleNestedMessage);
+ }
+ if (singleForeignMessage_ != null) {
+ size += 2 + pb::CodedOutputStream.ComputeMessageSize(SingleForeignMessage);
+ }
+ if (singleImportMessage_ != null) {
+ size += 2 + pb::CodedOutputStream.ComputeMessageSize(SingleImportMessage);
+ }
+ if (SingleNestedEnum != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) SingleNestedEnum);
+ }
+ if (SingleForeignEnum != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) SingleForeignEnum);
+ }
+ if (SingleImportEnum != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) SingleImportEnum);
+ }
+ if (singlePublicImportMessage_ != null) {
+ size += 2 + pb::CodedOutputStream.ComputeMessageSize(SinglePublicImportMessage);
+ }
+ size += repeatedInt32_.CalculateSize(_repeated_repeatedInt32_codec);
+ size += repeatedInt64_.CalculateSize(_repeated_repeatedInt64_codec);
+ size += repeatedUint32_.CalculateSize(_repeated_repeatedUint32_codec);
+ size += repeatedUint64_.CalculateSize(_repeated_repeatedUint64_codec);
+ size += repeatedSint32_.CalculateSize(_repeated_repeatedSint32_codec);
+ size += repeatedSint64_.CalculateSize(_repeated_repeatedSint64_codec);
+ size += repeatedFixed32_.CalculateSize(_repeated_repeatedFixed32_codec);
+ size += repeatedFixed64_.CalculateSize(_repeated_repeatedFixed64_codec);
+ size += repeatedSfixed32_.CalculateSize(_repeated_repeatedSfixed32_codec);
+ size += repeatedSfixed64_.CalculateSize(_repeated_repeatedSfixed64_codec);
+ size += repeatedFloat_.CalculateSize(_repeated_repeatedFloat_codec);
+ size += repeatedDouble_.CalculateSize(_repeated_repeatedDouble_codec);
+ size += repeatedBool_.CalculateSize(_repeated_repeatedBool_codec);
+ size += repeatedString_.CalculateSize(_repeated_repeatedString_codec);
+ size += repeatedBytes_.CalculateSize(_repeated_repeatedBytes_codec);
+ size += repeatedNestedMessage_.CalculateSize(_repeated_repeatedNestedMessage_codec);
+ size += repeatedForeignMessage_.CalculateSize(_repeated_repeatedForeignMessage_codec);
+ size += repeatedImportMessage_.CalculateSize(_repeated_repeatedImportMessage_codec);
+ size += repeatedNestedEnum_.CalculateSize(_repeated_repeatedNestedEnum_codec);
+ size += repeatedForeignEnum_.CalculateSize(_repeated_repeatedForeignEnum_codec);
+ size += repeatedImportEnum_.CalculateSize(_repeated_repeatedImportEnum_codec);
+ size += repeatedPublicImportMessage_.CalculateSize(_repeated_repeatedPublicImportMessage_codec);
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint32) {
+ size += 2 + pb::CodedOutputStream.ComputeUInt32Size(OneofUint32);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) {
+ size += 2 + pb::CodedOutputStream.ComputeMessageSize(OneofNestedMessage);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofString) {
+ size += 2 + pb::CodedOutputStream.ComputeStringSize(OneofString);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofBytes) {
+ size += 2 + pb::CodedOutputStream.ComputeBytesSize(OneofBytes);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestAllTypes other) {
+ if (other == null) {
+ return;
+ }
+ if (other.SingleInt32 != 0) {
+ SingleInt32 = other.SingleInt32;
+ }
+ if (other.SingleInt64 != 0L) {
+ SingleInt64 = other.SingleInt64;
+ }
+ if (other.SingleUint32 != 0) {
+ SingleUint32 = other.SingleUint32;
+ }
+ if (other.SingleUint64 != 0UL) {
+ SingleUint64 = other.SingleUint64;
+ }
+ if (other.SingleSint32 != 0) {
+ SingleSint32 = other.SingleSint32;
+ }
+ if (other.SingleSint64 != 0L) {
+ SingleSint64 = other.SingleSint64;
+ }
+ if (other.SingleFixed32 != 0) {
+ SingleFixed32 = other.SingleFixed32;
+ }
+ if (other.SingleFixed64 != 0UL) {
+ SingleFixed64 = other.SingleFixed64;
+ }
+ if (other.SingleSfixed32 != 0) {
+ SingleSfixed32 = other.SingleSfixed32;
+ }
+ if (other.SingleSfixed64 != 0L) {
+ SingleSfixed64 = other.SingleSfixed64;
+ }
+ if (other.SingleFloat != 0F) {
+ SingleFloat = other.SingleFloat;
+ }
+ if (other.SingleDouble != 0D) {
+ SingleDouble = other.SingleDouble;
+ }
+ if (other.SingleBool != false) {
+ SingleBool = other.SingleBool;
+ }
+ if (other.SingleString.Length != 0) {
+ SingleString = other.SingleString;
+ }
+ if (other.SingleBytes.Length != 0) {
+ SingleBytes = other.SingleBytes;
+ }
+ if (other.singleNestedMessage_ != null) {
+ if (singleNestedMessage_ == null) {
+ singleNestedMessage_ = new global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage();
+ }
+ SingleNestedMessage.MergeFrom(other.SingleNestedMessage);
+ }
+ if (other.singleForeignMessage_ != null) {
+ if (singleForeignMessage_ == null) {
+ singleForeignMessage_ = new global::Google.Protobuf.TestProtos.ForeignMessage();
+ }
+ SingleForeignMessage.MergeFrom(other.SingleForeignMessage);
+ }
+ if (other.singleImportMessage_ != null) {
+ if (singleImportMessage_ == null) {
+ singleImportMessage_ = new global::Google.Protobuf.TestProtos.ImportMessage();
+ }
+ SingleImportMessage.MergeFrom(other.SingleImportMessage);
+ }
+ if (other.SingleNestedEnum != 0) {
+ SingleNestedEnum = other.SingleNestedEnum;
+ }
+ if (other.SingleForeignEnum != 0) {
+ SingleForeignEnum = other.SingleForeignEnum;
+ }
+ if (other.SingleImportEnum != 0) {
+ SingleImportEnum = other.SingleImportEnum;
+ }
+ if (other.singlePublicImportMessage_ != null) {
+ if (singlePublicImportMessage_ == null) {
+ singlePublicImportMessage_ = new global::Google.Protobuf.TestProtos.PublicImportMessage();
+ }
+ SinglePublicImportMessage.MergeFrom(other.SinglePublicImportMessage);
+ }
+ repeatedInt32_.Add(other.repeatedInt32_);
+ repeatedInt64_.Add(other.repeatedInt64_);
+ repeatedUint32_.Add(other.repeatedUint32_);
+ repeatedUint64_.Add(other.repeatedUint64_);
+ repeatedSint32_.Add(other.repeatedSint32_);
+ repeatedSint64_.Add(other.repeatedSint64_);
+ repeatedFixed32_.Add(other.repeatedFixed32_);
+ repeatedFixed64_.Add(other.repeatedFixed64_);
+ repeatedSfixed32_.Add(other.repeatedSfixed32_);
+ repeatedSfixed64_.Add(other.repeatedSfixed64_);
+ repeatedFloat_.Add(other.repeatedFloat_);
+ repeatedDouble_.Add(other.repeatedDouble_);
+ repeatedBool_.Add(other.repeatedBool_);
+ repeatedString_.Add(other.repeatedString_);
+ repeatedBytes_.Add(other.repeatedBytes_);
+ repeatedNestedMessage_.Add(other.repeatedNestedMessage_);
+ repeatedForeignMessage_.Add(other.repeatedForeignMessage_);
+ repeatedImportMessage_.Add(other.repeatedImportMessage_);
+ repeatedNestedEnum_.Add(other.repeatedNestedEnum_);
+ repeatedForeignEnum_.Add(other.repeatedForeignEnum_);
+ repeatedImportEnum_.Add(other.repeatedImportEnum_);
+ repeatedPublicImportMessage_.Add(other.repeatedPublicImportMessage_);
+ switch (other.OneofFieldCase) {
+ case OneofFieldOneofCase.OneofUint32:
+ OneofUint32 = other.OneofUint32;
+ break;
+ case OneofFieldOneofCase.OneofNestedMessage:
+ OneofNestedMessage = other.OneofNestedMessage;
+ break;
+ case OneofFieldOneofCase.OneofString:
+ OneofString = other.OneofString;
+ break;
+ case OneofFieldOneofCase.OneofBytes:
+ OneofBytes = other.OneofBytes;
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ SingleInt32 = input.ReadInt32();
+ break;
+ }
+ case 16: {
+ SingleInt64 = input.ReadInt64();
+ break;
+ }
+ case 24: {
+ SingleUint32 = input.ReadUInt32();
+ break;
+ }
+ case 32: {
+ SingleUint64 = input.ReadUInt64();
+ break;
+ }
+ case 40: {
+ SingleSint32 = input.ReadSInt32();
+ break;
+ }
+ case 48: {
+ SingleSint64 = input.ReadSInt64();
+ break;
+ }
+ case 61: {
+ SingleFixed32 = input.ReadFixed32();
+ break;
+ }
+ case 65: {
+ SingleFixed64 = input.ReadFixed64();
+ break;
+ }
+ case 77: {
+ SingleSfixed32 = input.ReadSFixed32();
+ break;
+ }
+ case 81: {
+ SingleSfixed64 = input.ReadSFixed64();
+ break;
+ }
+ case 93: {
+ SingleFloat = input.ReadFloat();
+ break;
+ }
+ case 97: {
+ SingleDouble = input.ReadDouble();
+ break;
+ }
+ case 104: {
+ SingleBool = input.ReadBool();
+ break;
+ }
+ case 114: {
+ SingleString = input.ReadString();
+ break;
+ }
+ case 122: {
+ SingleBytes = input.ReadBytes();
+ break;
+ }
+ case 146: {
+ if (singleNestedMessage_ == null) {
+ singleNestedMessage_ = new global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage();
+ }
+ input.ReadMessage(singleNestedMessage_);
+ break;
+ }
+ case 154: {
+ if (singleForeignMessage_ == null) {
+ singleForeignMessage_ = new global::Google.Protobuf.TestProtos.ForeignMessage();
+ }
+ input.ReadMessage(singleForeignMessage_);
+ break;
+ }
+ case 162: {
+ if (singleImportMessage_ == null) {
+ singleImportMessage_ = new global::Google.Protobuf.TestProtos.ImportMessage();
+ }
+ input.ReadMessage(singleImportMessage_);
+ break;
+ }
+ case 168: {
+ singleNestedEnum_ = (global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedEnum) input.ReadEnum();
+ break;
+ }
+ case 176: {
+ singleForeignEnum_ = (global::Google.Protobuf.TestProtos.ForeignEnum) input.ReadEnum();
+ break;
+ }
+ case 184: {
+ singleImportEnum_ = (global::Google.Protobuf.TestProtos.ImportEnum) input.ReadEnum();
+ break;
+ }
+ case 210: {
+ if (singlePublicImportMessage_ == null) {
+ singlePublicImportMessage_ = new global::Google.Protobuf.TestProtos.PublicImportMessage();
+ }
+ input.ReadMessage(singlePublicImportMessage_);
+ break;
+ }
+ case 250:
+ case 248: {
+ repeatedInt32_.AddEntriesFrom(input, _repeated_repeatedInt32_codec);
+ break;
+ }
+ case 258:
+ case 256: {
+ repeatedInt64_.AddEntriesFrom(input, _repeated_repeatedInt64_codec);
+ break;
+ }
+ case 266:
+ case 264: {
+ repeatedUint32_.AddEntriesFrom(input, _repeated_repeatedUint32_codec);
+ break;
+ }
+ case 274:
+ case 272: {
+ repeatedUint64_.AddEntriesFrom(input, _repeated_repeatedUint64_codec);
+ break;
+ }
+ case 282:
+ case 280: {
+ repeatedSint32_.AddEntriesFrom(input, _repeated_repeatedSint32_codec);
+ break;
+ }
+ case 290:
+ case 288: {
+ repeatedSint64_.AddEntriesFrom(input, _repeated_repeatedSint64_codec);
+ break;
+ }
+ case 298:
+ case 301: {
+ repeatedFixed32_.AddEntriesFrom(input, _repeated_repeatedFixed32_codec);
+ break;
+ }
+ case 306:
+ case 305: {
+ repeatedFixed64_.AddEntriesFrom(input, _repeated_repeatedFixed64_codec);
+ break;
+ }
+ case 314:
+ case 317: {
+ repeatedSfixed32_.AddEntriesFrom(input, _repeated_repeatedSfixed32_codec);
+ break;
+ }
+ case 322:
+ case 321: {
+ repeatedSfixed64_.AddEntriesFrom(input, _repeated_repeatedSfixed64_codec);
+ break;
+ }
+ case 330:
+ case 333: {
+ repeatedFloat_.AddEntriesFrom(input, _repeated_repeatedFloat_codec);
+ break;
+ }
+ case 338:
+ case 337: {
+ repeatedDouble_.AddEntriesFrom(input, _repeated_repeatedDouble_codec);
+ break;
+ }
+ case 346:
+ case 344: {
+ repeatedBool_.AddEntriesFrom(input, _repeated_repeatedBool_codec);
+ break;
+ }
+ case 354: {
+ repeatedString_.AddEntriesFrom(input, _repeated_repeatedString_codec);
+ break;
+ }
+ case 362: {
+ repeatedBytes_.AddEntriesFrom(input, _repeated_repeatedBytes_codec);
+ break;
+ }
+ case 386: {
+ repeatedNestedMessage_.AddEntriesFrom(input, _repeated_repeatedNestedMessage_codec);
+ break;
+ }
+ case 394: {
+ repeatedForeignMessage_.AddEntriesFrom(input, _repeated_repeatedForeignMessage_codec);
+ break;
+ }
+ case 402: {
+ repeatedImportMessage_.AddEntriesFrom(input, _repeated_repeatedImportMessage_codec);
+ break;
+ }
+ case 410:
+ case 408: {
+ repeatedNestedEnum_.AddEntriesFrom(input, _repeated_repeatedNestedEnum_codec);
+ break;
+ }
+ case 418:
+ case 416: {
+ repeatedForeignEnum_.AddEntriesFrom(input, _repeated_repeatedForeignEnum_codec);
+ break;
+ }
+ case 426:
+ case 424: {
+ repeatedImportEnum_.AddEntriesFrom(input, _repeated_repeatedImportEnum_codec);
+ break;
+ }
+ case 434: {
+ repeatedPublicImportMessage_.AddEntriesFrom(input, _repeated_repeatedPublicImportMessage_codec);
+ break;
+ }
+ case 888: {
+ OneofUint32 = input.ReadUInt32();
+ break;
+ }
+ case 898: {
+ global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage();
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) {
+ subBuilder.MergeFrom(OneofNestedMessage);
+ }
+ input.ReadMessage(subBuilder);
+ OneofNestedMessage = subBuilder;
+ break;
+ }
+ case 906: {
+ OneofString = input.ReadString();
+ break;
+ }
+ case 914: {
+ OneofBytes = input.ReadBytes();
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the TestAllTypes message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ public enum NestedEnum {
+ [pbr::OriginalName("NESTED_ENUM_UNSPECIFIED")] Unspecified = 0,
+ [pbr::OriginalName("FOO")] Foo = 1,
+ [pbr::OriginalName("BAR")] Bar = 2,
+ [pbr::OriginalName("BAZ")] Baz = 3,
+ /// <summary>
+ /// Intentionally negative.
+ /// </summary>
+ [pbr::OriginalName("NEG")] Neg = -1,
+ }
+
+ public sealed partial class NestedMessage : pb::IMessage<NestedMessage> {
+ private static readonly pb::MessageParser<NestedMessage> _parser = new pb::MessageParser<NestedMessage>(() => new NestedMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<NestedMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.TestAllTypes.Descriptor.NestedTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedMessage(NestedMessage other) : this() {
+ bb_ = other.bb_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedMessage Clone() {
+ return new NestedMessage(this);
+ }
+
+ /// <summary>Field number for the "bb" field.</summary>
+ public const int BbFieldNumber = 1;
+ private int bb_;
+ /// <summary>
+ /// The field name "b" fails to compile in proto1 because it conflicts with
+ /// a local variable named "b" in one of the generated methods. Doh.
+ /// This file needs to compile in proto1 to test backwards-compatibility.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Bb {
+ get { return bb_; }
+ set {
+ bb_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as NestedMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(NestedMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Bb != other.Bb) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Bb != 0) hash ^= Bb.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Bb != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(Bb);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Bb != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Bb);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(NestedMessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Bb != 0) {
+ Bb = other.Bb;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Bb = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ }
+ #endregion
+
+ }
+
+ /// <summary>
+ /// This proto includes a recusively nested message.
+ /// </summary>
+ public sealed partial class NestedTestAllTypes : pb::IMessage<NestedTestAllTypes> {
+ private static readonly pb::MessageParser<NestedTestAllTypes> _parser = new pb::MessageParser<NestedTestAllTypes>(() => new NestedTestAllTypes());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<NestedTestAllTypes> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[1]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedTestAllTypes() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedTestAllTypes(NestedTestAllTypes other) : this() {
+ Child = other.child_ != null ? other.Child.Clone() : null;
+ Payload = other.payload_ != null ? other.Payload.Clone() : null;
+ repeatedChild_ = other.repeatedChild_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedTestAllTypes Clone() {
+ return new NestedTestAllTypes(this);
+ }
+
+ /// <summary>Field number for the "child" field.</summary>
+ public const int ChildFieldNumber = 1;
+ private global::Google.Protobuf.TestProtos.NestedTestAllTypes child_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.NestedTestAllTypes Child {
+ get { return child_; }
+ set {
+ child_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "payload" field.</summary>
+ public const int PayloadFieldNumber = 2;
+ private global::Google.Protobuf.TestProtos.TestAllTypes payload_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.TestAllTypes Payload {
+ get { return payload_; }
+ set {
+ payload_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "repeated_child" field.</summary>
+ public const int RepeatedChildFieldNumber = 3;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.NestedTestAllTypes> _repeated_repeatedChild_codec
+ = pb::FieldCodec.ForMessage(26, global::Google.Protobuf.TestProtos.NestedTestAllTypes.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.NestedTestAllTypes> repeatedChild_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.NestedTestAllTypes>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.TestProtos.NestedTestAllTypes> RepeatedChild {
+ get { return repeatedChild_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as NestedTestAllTypes);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(NestedTestAllTypes other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (!object.Equals(Child, other.Child)) return false;
+ if (!object.Equals(Payload, other.Payload)) return false;
+ if(!repeatedChild_.Equals(other.repeatedChild_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (child_ != null) hash ^= Child.GetHashCode();
+ if (payload_ != null) hash ^= Payload.GetHashCode();
+ hash ^= repeatedChild_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (child_ != null) {
+ output.WriteRawTag(10);
+ output.WriteMessage(Child);
+ }
+ if (payload_ != null) {
+ output.WriteRawTag(18);
+ output.WriteMessage(Payload);
+ }
+ repeatedChild_.WriteTo(output, _repeated_repeatedChild_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (child_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(Child);
+ }
+ if (payload_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(Payload);
+ }
+ size += repeatedChild_.CalculateSize(_repeated_repeatedChild_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(NestedTestAllTypes other) {
+ if (other == null) {
+ return;
+ }
+ if (other.child_ != null) {
+ if (child_ == null) {
+ child_ = new global::Google.Protobuf.TestProtos.NestedTestAllTypes();
+ }
+ Child.MergeFrom(other.Child);
+ }
+ if (other.payload_ != null) {
+ if (payload_ == null) {
+ payload_ = new global::Google.Protobuf.TestProtos.TestAllTypes();
+ }
+ Payload.MergeFrom(other.Payload);
+ }
+ repeatedChild_.Add(other.repeatedChild_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ if (child_ == null) {
+ child_ = new global::Google.Protobuf.TestProtos.NestedTestAllTypes();
+ }
+ input.ReadMessage(child_);
+ break;
+ }
+ case 18: {
+ if (payload_ == null) {
+ payload_ = new global::Google.Protobuf.TestProtos.TestAllTypes();
+ }
+ input.ReadMessage(payload_);
+ break;
+ }
+ case 26: {
+ repeatedChild_.AddEntriesFrom(input, _repeated_repeatedChild_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class TestDeprecatedFields : pb::IMessage<TestDeprecatedFields> {
+ private static readonly pb::MessageParser<TestDeprecatedFields> _parser = new pb::MessageParser<TestDeprecatedFields>(() => new TestDeprecatedFields());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestDeprecatedFields> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[2]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestDeprecatedFields() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestDeprecatedFields(TestDeprecatedFields other) : this() {
+ deprecatedInt32_ = other.deprecatedInt32_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestDeprecatedFields Clone() {
+ return new TestDeprecatedFields(this);
+ }
+
+ /// <summary>Field number for the "deprecated_int32" field.</summary>
+ public const int DeprecatedInt32FieldNumber = 1;
+ private int deprecatedInt32_;
+ [global::System.ObsoleteAttribute]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int DeprecatedInt32 {
+ get { return deprecatedInt32_; }
+ set {
+ deprecatedInt32_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestDeprecatedFields);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestDeprecatedFields other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (DeprecatedInt32 != other.DeprecatedInt32) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (DeprecatedInt32 != 0) hash ^= DeprecatedInt32.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (DeprecatedInt32 != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(DeprecatedInt32);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (DeprecatedInt32 != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(DeprecatedInt32);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestDeprecatedFields other) {
+ if (other == null) {
+ return;
+ }
+ if (other.DeprecatedInt32 != 0) {
+ DeprecatedInt32 = other.DeprecatedInt32;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ DeprecatedInt32 = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Define these after TestAllTypes to make sure the compiler can handle
+ /// that.
+ /// </summary>
+ public sealed partial class ForeignMessage : pb::IMessage<ForeignMessage> {
+ private static readonly pb::MessageParser<ForeignMessage> _parser = new pb::MessageParser<ForeignMessage>(() => new ForeignMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<ForeignMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[3]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ForeignMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ForeignMessage(ForeignMessage other) : this() {
+ c_ = other.c_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ForeignMessage Clone() {
+ return new ForeignMessage(this);
+ }
+
+ /// <summary>Field number for the "c" field.</summary>
+ public const int CFieldNumber = 1;
+ private int c_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int C {
+ get { return c_; }
+ set {
+ c_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as ForeignMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(ForeignMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (C != other.C) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (C != 0) hash ^= C.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (C != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(C);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (C != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(C);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(ForeignMessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.C != 0) {
+ C = other.C;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ C = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class TestReservedFields : pb::IMessage<TestReservedFields> {
+ private static readonly pb::MessageParser<TestReservedFields> _parser = new pb::MessageParser<TestReservedFields>(() => new TestReservedFields());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestReservedFields> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[4]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestReservedFields() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestReservedFields(TestReservedFields other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestReservedFields Clone() {
+ return new TestReservedFields(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestReservedFields);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestReservedFields other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestReservedFields other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Test that we can use NestedMessage from outside TestAllTypes.
+ /// </summary>
+ public sealed partial class TestForeignNested : pb::IMessage<TestForeignNested> {
+ private static readonly pb::MessageParser<TestForeignNested> _parser = new pb::MessageParser<TestForeignNested>(() => new TestForeignNested());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestForeignNested> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[5]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestForeignNested() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestForeignNested(TestForeignNested other) : this() {
+ ForeignNested = other.foreignNested_ != null ? other.ForeignNested.Clone() : null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestForeignNested Clone() {
+ return new TestForeignNested(this);
+ }
+
+ /// <summary>Field number for the "foreign_nested" field.</summary>
+ public const int ForeignNestedFieldNumber = 1;
+ private global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage foreignNested_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage ForeignNested {
+ get { return foreignNested_; }
+ set {
+ foreignNested_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestForeignNested);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestForeignNested other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (!object.Equals(ForeignNested, other.ForeignNested)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (foreignNested_ != null) hash ^= ForeignNested.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (foreignNested_ != null) {
+ output.WriteRawTag(10);
+ output.WriteMessage(ForeignNested);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (foreignNested_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(ForeignNested);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestForeignNested other) {
+ if (other == null) {
+ return;
+ }
+ if (other.foreignNested_ != null) {
+ if (foreignNested_ == null) {
+ foreignNested_ = new global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage();
+ }
+ ForeignNested.MergeFrom(other.ForeignNested);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ if (foreignNested_ == null) {
+ foreignNested_ = new global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage();
+ }
+ input.ReadMessage(foreignNested_);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Test that really large tag numbers don't break anything.
+ /// </summary>
+ public sealed partial class TestReallyLargeTagNumber : pb::IMessage<TestReallyLargeTagNumber> {
+ private static readonly pb::MessageParser<TestReallyLargeTagNumber> _parser = new pb::MessageParser<TestReallyLargeTagNumber>(() => new TestReallyLargeTagNumber());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestReallyLargeTagNumber> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[6]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestReallyLargeTagNumber() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestReallyLargeTagNumber(TestReallyLargeTagNumber other) : this() {
+ a_ = other.a_;
+ bb_ = other.bb_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestReallyLargeTagNumber Clone() {
+ return new TestReallyLargeTagNumber(this);
+ }
+
+ /// <summary>Field number for the "a" field.</summary>
+ public const int AFieldNumber = 1;
+ private int a_;
+ /// <summary>
+ /// The largest possible tag number is 2^28 - 1, since the wire format uses
+ /// three bits to communicate wire type.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int A {
+ get { return a_; }
+ set {
+ a_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "bb" field.</summary>
+ public const int BbFieldNumber = 268435455;
+ private int bb_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Bb {
+ get { return bb_; }
+ set {
+ bb_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestReallyLargeTagNumber);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestReallyLargeTagNumber other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (A != other.A) return false;
+ if (Bb != other.Bb) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (A != 0) hash ^= A.GetHashCode();
+ if (Bb != 0) hash ^= Bb.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (A != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(A);
+ }
+ if (Bb != 0) {
+ output.WriteRawTag(248, 255, 255, 255, 7);
+ output.WriteInt32(Bb);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (A != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(A);
+ }
+ if (Bb != 0) {
+ size += 5 + pb::CodedOutputStream.ComputeInt32Size(Bb);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestReallyLargeTagNumber other) {
+ if (other == null) {
+ return;
+ }
+ if (other.A != 0) {
+ A = other.A;
+ }
+ if (other.Bb != 0) {
+ Bb = other.Bb;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ A = input.ReadInt32();
+ break;
+ }
+ case 2147483640: {
+ Bb = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class TestRecursiveMessage : pb::IMessage<TestRecursiveMessage> {
+ private static readonly pb::MessageParser<TestRecursiveMessage> _parser = new pb::MessageParser<TestRecursiveMessage>(() => new TestRecursiveMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestRecursiveMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[7]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestRecursiveMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestRecursiveMessage(TestRecursiveMessage other) : this() {
+ A = other.a_ != null ? other.A.Clone() : null;
+ i_ = other.i_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestRecursiveMessage Clone() {
+ return new TestRecursiveMessage(this);
+ }
+
+ /// <summary>Field number for the "a" field.</summary>
+ public const int AFieldNumber = 1;
+ private global::Google.Protobuf.TestProtos.TestRecursiveMessage a_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.TestRecursiveMessage A {
+ get { return a_; }
+ set {
+ a_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "i" field.</summary>
+ public const int IFieldNumber = 2;
+ private int i_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int I {
+ get { return i_; }
+ set {
+ i_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestRecursiveMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestRecursiveMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (!object.Equals(A, other.A)) return false;
+ if (I != other.I) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (a_ != null) hash ^= A.GetHashCode();
+ if (I != 0) hash ^= I.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (a_ != null) {
+ output.WriteRawTag(10);
+ output.WriteMessage(A);
+ }
+ if (I != 0) {
+ output.WriteRawTag(16);
+ output.WriteInt32(I);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (a_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(A);
+ }
+ if (I != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(I);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestRecursiveMessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.a_ != null) {
+ if (a_ == null) {
+ a_ = new global::Google.Protobuf.TestProtos.TestRecursiveMessage();
+ }
+ A.MergeFrom(other.A);
+ }
+ if (other.I != 0) {
+ I = other.I;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ if (a_ == null) {
+ a_ = new global::Google.Protobuf.TestProtos.TestRecursiveMessage();
+ }
+ input.ReadMessage(a_);
+ break;
+ }
+ case 16: {
+ I = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Test that mutual recursion works.
+ /// </summary>
+ public sealed partial class TestMutualRecursionA : pb::IMessage<TestMutualRecursionA> {
+ private static readonly pb::MessageParser<TestMutualRecursionA> _parser = new pb::MessageParser<TestMutualRecursionA>(() => new TestMutualRecursionA());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestMutualRecursionA> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[8]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMutualRecursionA() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMutualRecursionA(TestMutualRecursionA other) : this() {
+ Bb = other.bb_ != null ? other.Bb.Clone() : null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMutualRecursionA Clone() {
+ return new TestMutualRecursionA(this);
+ }
+
+ /// <summary>Field number for the "bb" field.</summary>
+ public const int BbFieldNumber = 1;
+ private global::Google.Protobuf.TestProtos.TestMutualRecursionB bb_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.TestMutualRecursionB Bb {
+ get { return bb_; }
+ set {
+ bb_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestMutualRecursionA);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestMutualRecursionA other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (!object.Equals(Bb, other.Bb)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (bb_ != null) hash ^= Bb.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (bb_ != null) {
+ output.WriteRawTag(10);
+ output.WriteMessage(Bb);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (bb_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(Bb);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestMutualRecursionA other) {
+ if (other == null) {
+ return;
+ }
+ if (other.bb_ != null) {
+ if (bb_ == null) {
+ bb_ = new global::Google.Protobuf.TestProtos.TestMutualRecursionB();
+ }
+ Bb.MergeFrom(other.Bb);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ if (bb_ == null) {
+ bb_ = new global::Google.Protobuf.TestProtos.TestMutualRecursionB();
+ }
+ input.ReadMessage(bb_);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class TestMutualRecursionB : pb::IMessage<TestMutualRecursionB> {
+ private static readonly pb::MessageParser<TestMutualRecursionB> _parser = new pb::MessageParser<TestMutualRecursionB>(() => new TestMutualRecursionB());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestMutualRecursionB> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[9]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMutualRecursionB() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMutualRecursionB(TestMutualRecursionB other) : this() {
+ A = other.a_ != null ? other.A.Clone() : null;
+ optionalInt32_ = other.optionalInt32_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestMutualRecursionB Clone() {
+ return new TestMutualRecursionB(this);
+ }
+
+ /// <summary>Field number for the "a" field.</summary>
+ public const int AFieldNumber = 1;
+ private global::Google.Protobuf.TestProtos.TestMutualRecursionA a_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.TestMutualRecursionA A {
+ get { return a_; }
+ set {
+ a_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optional_int32" field.</summary>
+ public const int OptionalInt32FieldNumber = 2;
+ private int optionalInt32_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int OptionalInt32 {
+ get { return optionalInt32_; }
+ set {
+ optionalInt32_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestMutualRecursionB);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestMutualRecursionB other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (!object.Equals(A, other.A)) return false;
+ if (OptionalInt32 != other.OptionalInt32) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (a_ != null) hash ^= A.GetHashCode();
+ if (OptionalInt32 != 0) hash ^= OptionalInt32.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (a_ != null) {
+ output.WriteRawTag(10);
+ output.WriteMessage(A);
+ }
+ if (OptionalInt32 != 0) {
+ output.WriteRawTag(16);
+ output.WriteInt32(OptionalInt32);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (a_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(A);
+ }
+ if (OptionalInt32 != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(OptionalInt32);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestMutualRecursionB other) {
+ if (other == null) {
+ return;
+ }
+ if (other.a_ != null) {
+ if (a_ == null) {
+ a_ = new global::Google.Protobuf.TestProtos.TestMutualRecursionA();
+ }
+ A.MergeFrom(other.A);
+ }
+ if (other.OptionalInt32 != 0) {
+ OptionalInt32 = other.OptionalInt32;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ if (a_ == null) {
+ a_ = new global::Google.Protobuf.TestProtos.TestMutualRecursionA();
+ }
+ input.ReadMessage(a_);
+ break;
+ }
+ case 16: {
+ OptionalInt32 = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class TestEnumAllowAlias : pb::IMessage<TestEnumAllowAlias> {
+ private static readonly pb::MessageParser<TestEnumAllowAlias> _parser = new pb::MessageParser<TestEnumAllowAlias>(() => new TestEnumAllowAlias());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestEnumAllowAlias> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[10]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestEnumAllowAlias() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestEnumAllowAlias(TestEnumAllowAlias other) : this() {
+ value_ = other.value_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestEnumAllowAlias Clone() {
+ return new TestEnumAllowAlias(this);
+ }
+
+ /// <summary>Field number for the "value" field.</summary>
+ public const int ValueFieldNumber = 1;
+ private global::Google.Protobuf.TestProtos.TestEnumWithDupValue value_ = 0;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.TestEnumWithDupValue Value {
+ get { return value_; }
+ set {
+ value_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestEnumAllowAlias);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestEnumAllowAlias other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Value != other.Value) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Value != 0) hash ^= Value.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Value != 0) {
+ output.WriteRawTag(8);
+ output.WriteEnum((int) Value);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Value != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Value);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestEnumAllowAlias other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Value != 0) {
+ Value = other.Value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ value_ = (global::Google.Protobuf.TestProtos.TestEnumWithDupValue) input.ReadEnum();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Test message with CamelCase field names. This violates Protocol Buffer
+ /// standard style.
+ /// </summary>
+ public sealed partial class TestCamelCaseFieldNames : pb::IMessage<TestCamelCaseFieldNames> {
+ private static readonly pb::MessageParser<TestCamelCaseFieldNames> _parser = new pb::MessageParser<TestCamelCaseFieldNames>(() => new TestCamelCaseFieldNames());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestCamelCaseFieldNames> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[11]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestCamelCaseFieldNames() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestCamelCaseFieldNames(TestCamelCaseFieldNames other) : this() {
+ primitiveField_ = other.primitiveField_;
+ stringField_ = other.stringField_;
+ enumField_ = other.enumField_;
+ MessageField = other.messageField_ != null ? other.MessageField.Clone() : null;
+ repeatedPrimitiveField_ = other.repeatedPrimitiveField_.Clone();
+ repeatedStringField_ = other.repeatedStringField_.Clone();
+ repeatedEnumField_ = other.repeatedEnumField_.Clone();
+ repeatedMessageField_ = other.repeatedMessageField_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestCamelCaseFieldNames Clone() {
+ return new TestCamelCaseFieldNames(this);
+ }
+
+ /// <summary>Field number for the "PrimitiveField" field.</summary>
+ public const int PrimitiveFieldFieldNumber = 1;
+ private int primitiveField_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int PrimitiveField {
+ get { return primitiveField_; }
+ set {
+ primitiveField_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "StringField" field.</summary>
+ public const int StringFieldFieldNumber = 2;
+ private string stringField_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string StringField {
+ get { return stringField_; }
+ set {
+ stringField_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "EnumField" field.</summary>
+ public const int EnumFieldFieldNumber = 3;
+ private global::Google.Protobuf.TestProtos.ForeignEnum enumField_ = 0;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.ForeignEnum EnumField {
+ get { return enumField_; }
+ set {
+ enumField_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "MessageField" field.</summary>
+ public const int MessageFieldFieldNumber = 4;
+ private global::Google.Protobuf.TestProtos.ForeignMessage messageField_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.ForeignMessage MessageField {
+ get { return messageField_; }
+ set {
+ messageField_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "RepeatedPrimitiveField" field.</summary>
+ public const int RepeatedPrimitiveFieldFieldNumber = 7;
+ private static readonly pb::FieldCodec<int> _repeated_repeatedPrimitiveField_codec
+ = pb::FieldCodec.ForInt32(58);
+ private readonly pbc::RepeatedField<int> repeatedPrimitiveField_ = new pbc::RepeatedField<int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> RepeatedPrimitiveField {
+ get { return repeatedPrimitiveField_; }
+ }
+
+ /// <summary>Field number for the "RepeatedStringField" field.</summary>
+ public const int RepeatedStringFieldFieldNumber = 8;
+ private static readonly pb::FieldCodec<string> _repeated_repeatedStringField_codec
+ = pb::FieldCodec.ForString(66);
+ private readonly pbc::RepeatedField<string> repeatedStringField_ = new pbc::RepeatedField<string>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<string> RepeatedStringField {
+ get { return repeatedStringField_; }
+ }
+
+ /// <summary>Field number for the "RepeatedEnumField" field.</summary>
+ public const int RepeatedEnumFieldFieldNumber = 9;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.ForeignEnum> _repeated_repeatedEnumField_codec
+ = pb::FieldCodec.ForEnum(74, x => (int) x, x => (global::Google.Protobuf.TestProtos.ForeignEnum) x);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignEnum> repeatedEnumField_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignEnum>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignEnum> RepeatedEnumField {
+ get { return repeatedEnumField_; }
+ }
+
+ /// <summary>Field number for the "RepeatedMessageField" field.</summary>
+ public const int RepeatedMessageFieldFieldNumber = 10;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.ForeignMessage> _repeated_repeatedMessageField_codec
+ = pb::FieldCodec.ForMessage(82, global::Google.Protobuf.TestProtos.ForeignMessage.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignMessage> repeatedMessageField_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignMessage>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignMessage> RepeatedMessageField {
+ get { return repeatedMessageField_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestCamelCaseFieldNames);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestCamelCaseFieldNames other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (PrimitiveField != other.PrimitiveField) return false;
+ if (StringField != other.StringField) return false;
+ if (EnumField != other.EnumField) return false;
+ if (!object.Equals(MessageField, other.MessageField)) return false;
+ if(!repeatedPrimitiveField_.Equals(other.repeatedPrimitiveField_)) return false;
+ if(!repeatedStringField_.Equals(other.repeatedStringField_)) return false;
+ if(!repeatedEnumField_.Equals(other.repeatedEnumField_)) return false;
+ if(!repeatedMessageField_.Equals(other.repeatedMessageField_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (PrimitiveField != 0) hash ^= PrimitiveField.GetHashCode();
+ if (StringField.Length != 0) hash ^= StringField.GetHashCode();
+ if (EnumField != 0) hash ^= EnumField.GetHashCode();
+ if (messageField_ != null) hash ^= MessageField.GetHashCode();
+ hash ^= repeatedPrimitiveField_.GetHashCode();
+ hash ^= repeatedStringField_.GetHashCode();
+ hash ^= repeatedEnumField_.GetHashCode();
+ hash ^= repeatedMessageField_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (PrimitiveField != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(PrimitiveField);
+ }
+ if (StringField.Length != 0) {
+ output.WriteRawTag(18);
+ output.WriteString(StringField);
+ }
+ if (EnumField != 0) {
+ output.WriteRawTag(24);
+ output.WriteEnum((int) EnumField);
+ }
+ if (messageField_ != null) {
+ output.WriteRawTag(34);
+ output.WriteMessage(MessageField);
+ }
+ repeatedPrimitiveField_.WriteTo(output, _repeated_repeatedPrimitiveField_codec);
+ repeatedStringField_.WriteTo(output, _repeated_repeatedStringField_codec);
+ repeatedEnumField_.WriteTo(output, _repeated_repeatedEnumField_codec);
+ repeatedMessageField_.WriteTo(output, _repeated_repeatedMessageField_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (PrimitiveField != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(PrimitiveField);
+ }
+ if (StringField.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(StringField);
+ }
+ if (EnumField != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) EnumField);
+ }
+ if (messageField_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(MessageField);
+ }
+ size += repeatedPrimitiveField_.CalculateSize(_repeated_repeatedPrimitiveField_codec);
+ size += repeatedStringField_.CalculateSize(_repeated_repeatedStringField_codec);
+ size += repeatedEnumField_.CalculateSize(_repeated_repeatedEnumField_codec);
+ size += repeatedMessageField_.CalculateSize(_repeated_repeatedMessageField_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestCamelCaseFieldNames other) {
+ if (other == null) {
+ return;
+ }
+ if (other.PrimitiveField != 0) {
+ PrimitiveField = other.PrimitiveField;
+ }
+ if (other.StringField.Length != 0) {
+ StringField = other.StringField;
+ }
+ if (other.EnumField != 0) {
+ EnumField = other.EnumField;
+ }
+ if (other.messageField_ != null) {
+ if (messageField_ == null) {
+ messageField_ = new global::Google.Protobuf.TestProtos.ForeignMessage();
+ }
+ MessageField.MergeFrom(other.MessageField);
+ }
+ repeatedPrimitiveField_.Add(other.repeatedPrimitiveField_);
+ repeatedStringField_.Add(other.repeatedStringField_);
+ repeatedEnumField_.Add(other.repeatedEnumField_);
+ repeatedMessageField_.Add(other.repeatedMessageField_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ PrimitiveField = input.ReadInt32();
+ break;
+ }
+ case 18: {
+ StringField = input.ReadString();
+ break;
+ }
+ case 24: {
+ enumField_ = (global::Google.Protobuf.TestProtos.ForeignEnum) input.ReadEnum();
+ break;
+ }
+ case 34: {
+ if (messageField_ == null) {
+ messageField_ = new global::Google.Protobuf.TestProtos.ForeignMessage();
+ }
+ input.ReadMessage(messageField_);
+ break;
+ }
+ case 58:
+ case 56: {
+ repeatedPrimitiveField_.AddEntriesFrom(input, _repeated_repeatedPrimitiveField_codec);
+ break;
+ }
+ case 66: {
+ repeatedStringField_.AddEntriesFrom(input, _repeated_repeatedStringField_codec);
+ break;
+ }
+ case 74:
+ case 72: {
+ repeatedEnumField_.AddEntriesFrom(input, _repeated_repeatedEnumField_codec);
+ break;
+ }
+ case 82: {
+ repeatedMessageField_.AddEntriesFrom(input, _repeated_repeatedMessageField_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// We list fields out of order, to ensure that we're using field number and not
+ /// field index to determine serialization order.
+ /// </summary>
+ public sealed partial class TestFieldOrderings : pb::IMessage<TestFieldOrderings> {
+ private static readonly pb::MessageParser<TestFieldOrderings> _parser = new pb::MessageParser<TestFieldOrderings>(() => new TestFieldOrderings());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestFieldOrderings> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[12]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestFieldOrderings() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestFieldOrderings(TestFieldOrderings other) : this() {
+ myString_ = other.myString_;
+ myInt_ = other.myInt_;
+ myFloat_ = other.myFloat_;
+ SingleNestedMessage = other.singleNestedMessage_ != null ? other.SingleNestedMessage.Clone() : null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestFieldOrderings Clone() {
+ return new TestFieldOrderings(this);
+ }
+
+ /// <summary>Field number for the "my_string" field.</summary>
+ public const int MyStringFieldNumber = 11;
+ private string myString_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string MyString {
+ get { return myString_; }
+ set {
+ myString_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "my_int" field.</summary>
+ public const int MyIntFieldNumber = 1;
+ private long myInt_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public long MyInt {
+ get { return myInt_; }
+ set {
+ myInt_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "my_float" field.</summary>
+ public const int MyFloatFieldNumber = 101;
+ private float myFloat_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public float MyFloat {
+ get { return myFloat_; }
+ set {
+ myFloat_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "single_nested_message" field.</summary>
+ public const int SingleNestedMessageFieldNumber = 200;
+ private global::Google.Protobuf.TestProtos.TestFieldOrderings.Types.NestedMessage singleNestedMessage_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.TestFieldOrderings.Types.NestedMessage SingleNestedMessage {
+ get { return singleNestedMessage_; }
+ set {
+ singleNestedMessage_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestFieldOrderings);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestFieldOrderings other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (MyString != other.MyString) return false;
+ if (MyInt != other.MyInt) return false;
+ if (MyFloat != other.MyFloat) return false;
+ if (!object.Equals(SingleNestedMessage, other.SingleNestedMessage)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (MyString.Length != 0) hash ^= MyString.GetHashCode();
+ if (MyInt != 0L) hash ^= MyInt.GetHashCode();
+ if (MyFloat != 0F) hash ^= MyFloat.GetHashCode();
+ if (singleNestedMessage_ != null) hash ^= SingleNestedMessage.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (MyInt != 0L) {
+ output.WriteRawTag(8);
+ output.WriteInt64(MyInt);
+ }
+ if (MyString.Length != 0) {
+ output.WriteRawTag(90);
+ output.WriteString(MyString);
+ }
+ if (MyFloat != 0F) {
+ output.WriteRawTag(173, 6);
+ output.WriteFloat(MyFloat);
+ }
+ if (singleNestedMessage_ != null) {
+ output.WriteRawTag(194, 12);
+ output.WriteMessage(SingleNestedMessage);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (MyString.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(MyString);
+ }
+ if (MyInt != 0L) {
+ size += 1 + pb::CodedOutputStream.ComputeInt64Size(MyInt);
+ }
+ if (MyFloat != 0F) {
+ size += 2 + 4;
+ }
+ if (singleNestedMessage_ != null) {
+ size += 2 + pb::CodedOutputStream.ComputeMessageSize(SingleNestedMessage);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestFieldOrderings other) {
+ if (other == null) {
+ return;
+ }
+ if (other.MyString.Length != 0) {
+ MyString = other.MyString;
+ }
+ if (other.MyInt != 0L) {
+ MyInt = other.MyInt;
+ }
+ if (other.MyFloat != 0F) {
+ MyFloat = other.MyFloat;
+ }
+ if (other.singleNestedMessage_ != null) {
+ if (singleNestedMessage_ == null) {
+ singleNestedMessage_ = new global::Google.Protobuf.TestProtos.TestFieldOrderings.Types.NestedMessage();
+ }
+ SingleNestedMessage.MergeFrom(other.SingleNestedMessage);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ MyInt = input.ReadInt64();
+ break;
+ }
+ case 90: {
+ MyString = input.ReadString();
+ break;
+ }
+ case 813: {
+ MyFloat = input.ReadFloat();
+ break;
+ }
+ case 1602: {
+ if (singleNestedMessage_ == null) {
+ singleNestedMessage_ = new global::Google.Protobuf.TestProtos.TestFieldOrderings.Types.NestedMessage();
+ }
+ input.ReadMessage(singleNestedMessage_);
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the TestFieldOrderings message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ public sealed partial class NestedMessage : pb::IMessage<NestedMessage> {
+ private static readonly pb::MessageParser<NestedMessage> _parser = new pb::MessageParser<NestedMessage>(() => new NestedMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<NestedMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.TestFieldOrderings.Descriptor.NestedTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedMessage(NestedMessage other) : this() {
+ oo_ = other.oo_;
+ bb_ = other.bb_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NestedMessage Clone() {
+ return new NestedMessage(this);
+ }
+
+ /// <summary>Field number for the "oo" field.</summary>
+ public const int OoFieldNumber = 2;
+ private long oo_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public long Oo {
+ get { return oo_; }
+ set {
+ oo_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "bb" field.</summary>
+ public const int BbFieldNumber = 1;
+ private int bb_;
+ /// <summary>
+ /// The field name "b" fails to compile in proto1 because it conflicts with
+ /// a local variable named "b" in one of the generated methods. Doh.
+ /// This file needs to compile in proto1 to test backwards-compatibility.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Bb {
+ get { return bb_; }
+ set {
+ bb_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as NestedMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(NestedMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Oo != other.Oo) return false;
+ if (Bb != other.Bb) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Oo != 0L) hash ^= Oo.GetHashCode();
+ if (Bb != 0) hash ^= Bb.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Bb != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(Bb);
+ }
+ if (Oo != 0L) {
+ output.WriteRawTag(16);
+ output.WriteInt64(Oo);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Oo != 0L) {
+ size += 1 + pb::CodedOutputStream.ComputeInt64Size(Oo);
+ }
+ if (Bb != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Bb);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(NestedMessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Oo != 0L) {
+ Oo = other.Oo;
+ }
+ if (other.Bb != 0) {
+ Bb = other.Bb;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Bb = input.ReadInt32();
+ break;
+ }
+ case 16: {
+ Oo = input.ReadInt64();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ }
+ #endregion
+
+ }
+
+ public sealed partial class SparseEnumMessage : pb::IMessage<SparseEnumMessage> {
+ private static readonly pb::MessageParser<SparseEnumMessage> _parser = new pb::MessageParser<SparseEnumMessage>(() => new SparseEnumMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<SparseEnumMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[13]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SparseEnumMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SparseEnumMessage(SparseEnumMessage other) : this() {
+ sparseEnum_ = other.sparseEnum_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SparseEnumMessage Clone() {
+ return new SparseEnumMessage(this);
+ }
+
+ /// <summary>Field number for the "sparse_enum" field.</summary>
+ public const int SparseEnumFieldNumber = 1;
+ private global::Google.Protobuf.TestProtos.TestSparseEnum sparseEnum_ = 0;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.TestSparseEnum SparseEnum {
+ get { return sparseEnum_; }
+ set {
+ sparseEnum_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as SparseEnumMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(SparseEnumMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (SparseEnum != other.SparseEnum) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (SparseEnum != 0) hash ^= SparseEnum.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (SparseEnum != 0) {
+ output.WriteRawTag(8);
+ output.WriteEnum((int) SparseEnum);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (SparseEnum != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) SparseEnum);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(SparseEnumMessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.SparseEnum != 0) {
+ SparseEnum = other.SparseEnum;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ sparseEnum_ = (global::Google.Protobuf.TestProtos.TestSparseEnum) input.ReadEnum();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Test String and Bytes: string is for valid UTF-8 strings
+ /// </summary>
+ public sealed partial class OneString : pb::IMessage<OneString> {
+ private static readonly pb::MessageParser<OneString> _parser = new pb::MessageParser<OneString>(() => new OneString());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<OneString> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[14]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneString() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneString(OneString other) : this() {
+ data_ = other.data_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneString Clone() {
+ return new OneString(this);
+ }
+
+ /// <summary>Field number for the "data" field.</summary>
+ public const int DataFieldNumber = 1;
+ private string data_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Data {
+ get { return data_; }
+ set {
+ data_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as OneString);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(OneString other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Data != other.Data) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Data.Length != 0) hash ^= Data.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Data.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Data);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Data.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Data);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(OneString other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Data.Length != 0) {
+ Data = other.Data;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Data = input.ReadString();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class MoreString : pb::IMessage<MoreString> {
+ private static readonly pb::MessageParser<MoreString> _parser = new pb::MessageParser<MoreString>(() => new MoreString());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<MoreString> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[15]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MoreString() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MoreString(MoreString other) : this() {
+ data_ = other.data_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MoreString Clone() {
+ return new MoreString(this);
+ }
+
+ /// <summary>Field number for the "data" field.</summary>
+ public const int DataFieldNumber = 1;
+ private static readonly pb::FieldCodec<string> _repeated_data_codec
+ = pb::FieldCodec.ForString(10);
+ private readonly pbc::RepeatedField<string> data_ = new pbc::RepeatedField<string>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<string> Data {
+ get { return data_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as MoreString);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(MoreString other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if(!data_.Equals(other.data_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= data_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ data_.WriteTo(output, _repeated_data_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += data_.CalculateSize(_repeated_data_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(MoreString other) {
+ if (other == null) {
+ return;
+ }
+ data_.Add(other.data_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ data_.AddEntriesFrom(input, _repeated_data_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class OneBytes : pb::IMessage<OneBytes> {
+ private static readonly pb::MessageParser<OneBytes> _parser = new pb::MessageParser<OneBytes>(() => new OneBytes());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<OneBytes> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[16]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneBytes() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneBytes(OneBytes other) : this() {
+ data_ = other.data_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneBytes Clone() {
+ return new OneBytes(this);
+ }
+
+ /// <summary>Field number for the "data" field.</summary>
+ public const int DataFieldNumber = 1;
+ private pb::ByteString data_ = pb::ByteString.Empty;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pb::ByteString Data {
+ get { return data_; }
+ set {
+ data_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as OneBytes);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(OneBytes other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Data != other.Data) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Data.Length != 0) hash ^= Data.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Data.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteBytes(Data);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Data.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeBytesSize(Data);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(OneBytes other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Data.Length != 0) {
+ Data = other.Data;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Data = input.ReadBytes();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class MoreBytes : pb::IMessage<MoreBytes> {
+ private static readonly pb::MessageParser<MoreBytes> _parser = new pb::MessageParser<MoreBytes>(() => new MoreBytes());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<MoreBytes> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[17]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MoreBytes() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MoreBytes(MoreBytes other) : this() {
+ data_ = other.data_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MoreBytes Clone() {
+ return new MoreBytes(this);
+ }
+
+ /// <summary>Field number for the "data" field.</summary>
+ public const int DataFieldNumber = 1;
+ private pb::ByteString data_ = pb::ByteString.Empty;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pb::ByteString Data {
+ get { return data_; }
+ set {
+ data_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as MoreBytes);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(MoreBytes other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Data != other.Data) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Data.Length != 0) hash ^= Data.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Data.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteBytes(Data);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Data.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeBytesSize(Data);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(MoreBytes other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Data.Length != 0) {
+ Data = other.Data;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Data = input.ReadBytes();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Test int32, uint32, int64, uint64, and bool are all compatible
+ /// </summary>
+ public sealed partial class Int32Message : pb::IMessage<Int32Message> {
+ private static readonly pb::MessageParser<Int32Message> _parser = new pb::MessageParser<Int32Message>(() => new Int32Message());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Int32Message> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[18]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Int32Message() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Int32Message(Int32Message other) : this() {
+ data_ = other.data_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Int32Message Clone() {
+ return new Int32Message(this);
+ }
+
+ /// <summary>Field number for the "data" field.</summary>
+ public const int DataFieldNumber = 1;
+ private int data_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Data {
+ get { return data_; }
+ set {
+ data_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Int32Message);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Int32Message other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Data != other.Data) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Data != 0) hash ^= Data.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Data != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(Data);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Data != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Data);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Int32Message other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Data != 0) {
+ Data = other.Data;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Data = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class Uint32Message : pb::IMessage<Uint32Message> {
+ private static readonly pb::MessageParser<Uint32Message> _parser = new pb::MessageParser<Uint32Message>(() => new Uint32Message());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Uint32Message> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[19]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Uint32Message() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Uint32Message(Uint32Message other) : this() {
+ data_ = other.data_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Uint32Message Clone() {
+ return new Uint32Message(this);
+ }
+
+ /// <summary>Field number for the "data" field.</summary>
+ public const int DataFieldNumber = 1;
+ private uint data_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public uint Data {
+ get { return data_; }
+ set {
+ data_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Uint32Message);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Uint32Message other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Data != other.Data) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Data != 0) hash ^= Data.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Data != 0) {
+ output.WriteRawTag(8);
+ output.WriteUInt32(Data);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Data != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeUInt32Size(Data);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Uint32Message other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Data != 0) {
+ Data = other.Data;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Data = input.ReadUInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class Int64Message : pb::IMessage<Int64Message> {
+ private static readonly pb::MessageParser<Int64Message> _parser = new pb::MessageParser<Int64Message>(() => new Int64Message());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Int64Message> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[20]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Int64Message() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Int64Message(Int64Message other) : this() {
+ data_ = other.data_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Int64Message Clone() {
+ return new Int64Message(this);
+ }
+
+ /// <summary>Field number for the "data" field.</summary>
+ public const int DataFieldNumber = 1;
+ private long data_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public long Data {
+ get { return data_; }
+ set {
+ data_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Int64Message);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Int64Message other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Data != other.Data) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Data != 0L) hash ^= Data.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Data != 0L) {
+ output.WriteRawTag(8);
+ output.WriteInt64(Data);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Data != 0L) {
+ size += 1 + pb::CodedOutputStream.ComputeInt64Size(Data);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Int64Message other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Data != 0L) {
+ Data = other.Data;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Data = input.ReadInt64();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class Uint64Message : pb::IMessage<Uint64Message> {
+ private static readonly pb::MessageParser<Uint64Message> _parser = new pb::MessageParser<Uint64Message>(() => new Uint64Message());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Uint64Message> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[21]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Uint64Message() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Uint64Message(Uint64Message other) : this() {
+ data_ = other.data_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Uint64Message Clone() {
+ return new Uint64Message(this);
+ }
+
+ /// <summary>Field number for the "data" field.</summary>
+ public const int DataFieldNumber = 1;
+ private ulong data_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ulong Data {
+ get { return data_; }
+ set {
+ data_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Uint64Message);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Uint64Message other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Data != other.Data) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Data != 0UL) hash ^= Data.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Data != 0UL) {
+ output.WriteRawTag(8);
+ output.WriteUInt64(Data);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Data != 0UL) {
+ size += 1 + pb::CodedOutputStream.ComputeUInt64Size(Data);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Uint64Message other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Data != 0UL) {
+ Data = other.Data;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Data = input.ReadUInt64();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class BoolMessage : pb::IMessage<BoolMessage> {
+ private static readonly pb::MessageParser<BoolMessage> _parser = new pb::MessageParser<BoolMessage>(() => new BoolMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<BoolMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[22]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public BoolMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public BoolMessage(BoolMessage other) : this() {
+ data_ = other.data_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public BoolMessage Clone() {
+ return new BoolMessage(this);
+ }
+
+ /// <summary>Field number for the "data" field.</summary>
+ public const int DataFieldNumber = 1;
+ private bool data_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Data {
+ get { return data_; }
+ set {
+ data_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as BoolMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(BoolMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Data != other.Data) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Data != false) hash ^= Data.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Data != false) {
+ output.WriteRawTag(8);
+ output.WriteBool(Data);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Data != false) {
+ size += 1 + 1;
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(BoolMessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Data != false) {
+ Data = other.Data;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Data = input.ReadBool();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Test oneofs.
+ /// </summary>
+ public sealed partial class TestOneof : pb::IMessage<TestOneof> {
+ private static readonly pb::MessageParser<TestOneof> _parser = new pb::MessageParser<TestOneof>(() => new TestOneof());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestOneof> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[23]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestOneof() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestOneof(TestOneof other) : this() {
+ switch (other.FooCase) {
+ case FooOneofCase.FooInt:
+ FooInt = other.FooInt;
+ break;
+ case FooOneofCase.FooString:
+ FooString = other.FooString;
+ break;
+ case FooOneofCase.FooMessage:
+ FooMessage = other.FooMessage.Clone();
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestOneof Clone() {
+ return new TestOneof(this);
+ }
+
+ /// <summary>Field number for the "foo_int" field.</summary>
+ public const int FooIntFieldNumber = 1;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int FooInt {
+ get { return fooCase_ == FooOneofCase.FooInt ? (int) foo_ : 0; }
+ set {
+ foo_ = value;
+ fooCase_ = FooOneofCase.FooInt;
+ }
+ }
+
+ /// <summary>Field number for the "foo_string" field.</summary>
+ public const int FooStringFieldNumber = 2;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string FooString {
+ get { return fooCase_ == FooOneofCase.FooString ? (string) foo_ : ""; }
+ set {
+ foo_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ fooCase_ = FooOneofCase.FooString;
+ }
+ }
+
+ /// <summary>Field number for the "foo_message" field.</summary>
+ public const int FooMessageFieldNumber = 3;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.TestProtos.TestAllTypes FooMessage {
+ get { return fooCase_ == FooOneofCase.FooMessage ? (global::Google.Protobuf.TestProtos.TestAllTypes) foo_ : null; }
+ set {
+ foo_ = value;
+ fooCase_ = value == null ? FooOneofCase.None : FooOneofCase.FooMessage;
+ }
+ }
+
+ private object foo_;
+ /// <summary>Enum of possible cases for the "foo" oneof.</summary>
+ public enum FooOneofCase {
+ None = 0,
+ FooInt = 1,
+ FooString = 2,
+ FooMessage = 3,
+ }
+ private FooOneofCase fooCase_ = FooOneofCase.None;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FooOneofCase FooCase {
+ get { return fooCase_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearFoo() {
+ fooCase_ = FooOneofCase.None;
+ foo_ = null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestOneof);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestOneof other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (FooInt != other.FooInt) return false;
+ if (FooString != other.FooString) return false;
+ if (!object.Equals(FooMessage, other.FooMessage)) return false;
+ if (FooCase != other.FooCase) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (fooCase_ == FooOneofCase.FooInt) hash ^= FooInt.GetHashCode();
+ if (fooCase_ == FooOneofCase.FooString) hash ^= FooString.GetHashCode();
+ if (fooCase_ == FooOneofCase.FooMessage) hash ^= FooMessage.GetHashCode();
+ hash ^= (int) fooCase_;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (fooCase_ == FooOneofCase.FooInt) {
+ output.WriteRawTag(8);
+ output.WriteInt32(FooInt);
+ }
+ if (fooCase_ == FooOneofCase.FooString) {
+ output.WriteRawTag(18);
+ output.WriteString(FooString);
+ }
+ if (fooCase_ == FooOneofCase.FooMessage) {
+ output.WriteRawTag(26);
+ output.WriteMessage(FooMessage);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (fooCase_ == FooOneofCase.FooInt) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(FooInt);
+ }
+ if (fooCase_ == FooOneofCase.FooString) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(FooString);
+ }
+ if (fooCase_ == FooOneofCase.FooMessage) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(FooMessage);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestOneof other) {
+ if (other == null) {
+ return;
+ }
+ switch (other.FooCase) {
+ case FooOneofCase.FooInt:
+ FooInt = other.FooInt;
+ break;
+ case FooOneofCase.FooString:
+ FooString = other.FooString;
+ break;
+ case FooOneofCase.FooMessage:
+ FooMessage = other.FooMessage;
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ FooInt = input.ReadInt32();
+ break;
+ }
+ case 18: {
+ FooString = input.ReadString();
+ break;
+ }
+ case 26: {
+ global::Google.Protobuf.TestProtos.TestAllTypes subBuilder = new global::Google.Protobuf.TestProtos.TestAllTypes();
+ if (fooCase_ == FooOneofCase.FooMessage) {
+ subBuilder.MergeFrom(FooMessage);
+ }
+ input.ReadMessage(subBuilder);
+ FooMessage = subBuilder;
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class TestPackedTypes : pb::IMessage<TestPackedTypes> {
+ private static readonly pb::MessageParser<TestPackedTypes> _parser = new pb::MessageParser<TestPackedTypes>(() => new TestPackedTypes());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestPackedTypes> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[24]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestPackedTypes() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestPackedTypes(TestPackedTypes other) : this() {
+ packedInt32_ = other.packedInt32_.Clone();
+ packedInt64_ = other.packedInt64_.Clone();
+ packedUint32_ = other.packedUint32_.Clone();
+ packedUint64_ = other.packedUint64_.Clone();
+ packedSint32_ = other.packedSint32_.Clone();
+ packedSint64_ = other.packedSint64_.Clone();
+ packedFixed32_ = other.packedFixed32_.Clone();
+ packedFixed64_ = other.packedFixed64_.Clone();
+ packedSfixed32_ = other.packedSfixed32_.Clone();
+ packedSfixed64_ = other.packedSfixed64_.Clone();
+ packedFloat_ = other.packedFloat_.Clone();
+ packedDouble_ = other.packedDouble_.Clone();
+ packedBool_ = other.packedBool_.Clone();
+ packedEnum_ = other.packedEnum_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestPackedTypes Clone() {
+ return new TestPackedTypes(this);
+ }
+
+ /// <summary>Field number for the "packed_int32" field.</summary>
+ public const int PackedInt32FieldNumber = 90;
+ private static readonly pb::FieldCodec<int> _repeated_packedInt32_codec
+ = pb::FieldCodec.ForInt32(722);
+ private readonly pbc::RepeatedField<int> packedInt32_ = new pbc::RepeatedField<int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> PackedInt32 {
+ get { return packedInt32_; }
+ }
+
+ /// <summary>Field number for the "packed_int64" field.</summary>
+ public const int PackedInt64FieldNumber = 91;
+ private static readonly pb::FieldCodec<long> _repeated_packedInt64_codec
+ = pb::FieldCodec.ForInt64(730);
+ private readonly pbc::RepeatedField<long> packedInt64_ = new pbc::RepeatedField<long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<long> PackedInt64 {
+ get { return packedInt64_; }
+ }
+
+ /// <summary>Field number for the "packed_uint32" field.</summary>
+ public const int PackedUint32FieldNumber = 92;
+ private static readonly pb::FieldCodec<uint> _repeated_packedUint32_codec
+ = pb::FieldCodec.ForUInt32(738);
+ private readonly pbc::RepeatedField<uint> packedUint32_ = new pbc::RepeatedField<uint>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<uint> PackedUint32 {
+ get { return packedUint32_; }
+ }
+
+ /// <summary>Field number for the "packed_uint64" field.</summary>
+ public const int PackedUint64FieldNumber = 93;
+ private static readonly pb::FieldCodec<ulong> _repeated_packedUint64_codec
+ = pb::FieldCodec.ForUInt64(746);
+ private readonly pbc::RepeatedField<ulong> packedUint64_ = new pbc::RepeatedField<ulong>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<ulong> PackedUint64 {
+ get { return packedUint64_; }
+ }
+
+ /// <summary>Field number for the "packed_sint32" field.</summary>
+ public const int PackedSint32FieldNumber = 94;
+ private static readonly pb::FieldCodec<int> _repeated_packedSint32_codec
+ = pb::FieldCodec.ForSInt32(754);
+ private readonly pbc::RepeatedField<int> packedSint32_ = new pbc::RepeatedField<int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> PackedSint32 {
+ get { return packedSint32_; }
+ }
+
+ /// <summary>Field number for the "packed_sint64" field.</summary>
+ public const int PackedSint64FieldNumber = 95;
+ private static readonly pb::FieldCodec<long> _repeated_packedSint64_codec
+ = pb::FieldCodec.ForSInt64(762);
+ private readonly pbc::RepeatedField<long> packedSint64_ = new pbc::RepeatedField<long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<long> PackedSint64 {
+ get { return packedSint64_; }
+ }
+
+ /// <summary>Field number for the "packed_fixed32" field.</summary>
+ public const int PackedFixed32FieldNumber = 96;
+ private static readonly pb::FieldCodec<uint> _repeated_packedFixed32_codec
+ = pb::FieldCodec.ForFixed32(770);
+ private readonly pbc::RepeatedField<uint> packedFixed32_ = new pbc::RepeatedField<uint>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<uint> PackedFixed32 {
+ get { return packedFixed32_; }
+ }
+
+ /// <summary>Field number for the "packed_fixed64" field.</summary>
+ public const int PackedFixed64FieldNumber = 97;
+ private static readonly pb::FieldCodec<ulong> _repeated_packedFixed64_codec
+ = pb::FieldCodec.ForFixed64(778);
+ private readonly pbc::RepeatedField<ulong> packedFixed64_ = new pbc::RepeatedField<ulong>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<ulong> PackedFixed64 {
+ get { return packedFixed64_; }
+ }
+
+ /// <summary>Field number for the "packed_sfixed32" field.</summary>
+ public const int PackedSfixed32FieldNumber = 98;
+ private static readonly pb::FieldCodec<int> _repeated_packedSfixed32_codec
+ = pb::FieldCodec.ForSFixed32(786);
+ private readonly pbc::RepeatedField<int> packedSfixed32_ = new pbc::RepeatedField<int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> PackedSfixed32 {
+ get { return packedSfixed32_; }
+ }
+
+ /// <summary>Field number for the "packed_sfixed64" field.</summary>
+ public const int PackedSfixed64FieldNumber = 99;
+ private static readonly pb::FieldCodec<long> _repeated_packedSfixed64_codec
+ = pb::FieldCodec.ForSFixed64(794);
+ private readonly pbc::RepeatedField<long> packedSfixed64_ = new pbc::RepeatedField<long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<long> PackedSfixed64 {
+ get { return packedSfixed64_; }
+ }
+
+ /// <summary>Field number for the "packed_float" field.</summary>
+ public const int PackedFloatFieldNumber = 100;
+ private static readonly pb::FieldCodec<float> _repeated_packedFloat_codec
+ = pb::FieldCodec.ForFloat(802);
+ private readonly pbc::RepeatedField<float> packedFloat_ = new pbc::RepeatedField<float>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<float> PackedFloat {
+ get { return packedFloat_; }
+ }
+
+ /// <summary>Field number for the "packed_double" field.</summary>
+ public const int PackedDoubleFieldNumber = 101;
+ private static readonly pb::FieldCodec<double> _repeated_packedDouble_codec
+ = pb::FieldCodec.ForDouble(810);
+ private readonly pbc::RepeatedField<double> packedDouble_ = new pbc::RepeatedField<double>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<double> PackedDouble {
+ get { return packedDouble_; }
+ }
+
+ /// <summary>Field number for the "packed_bool" field.</summary>
+ public const int PackedBoolFieldNumber = 102;
+ private static readonly pb::FieldCodec<bool> _repeated_packedBool_codec
+ = pb::FieldCodec.ForBool(818);
+ private readonly pbc::RepeatedField<bool> packedBool_ = new pbc::RepeatedField<bool>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<bool> PackedBool {
+ get { return packedBool_; }
+ }
+
+ /// <summary>Field number for the "packed_enum" field.</summary>
+ public const int PackedEnumFieldNumber = 103;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.ForeignEnum> _repeated_packedEnum_codec
+ = pb::FieldCodec.ForEnum(826, x => (int) x, x => (global::Google.Protobuf.TestProtos.ForeignEnum) x);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignEnum> packedEnum_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignEnum>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignEnum> PackedEnum {
+ get { return packedEnum_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestPackedTypes);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestPackedTypes other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if(!packedInt32_.Equals(other.packedInt32_)) return false;
+ if(!packedInt64_.Equals(other.packedInt64_)) return false;
+ if(!packedUint32_.Equals(other.packedUint32_)) return false;
+ if(!packedUint64_.Equals(other.packedUint64_)) return false;
+ if(!packedSint32_.Equals(other.packedSint32_)) return false;
+ if(!packedSint64_.Equals(other.packedSint64_)) return false;
+ if(!packedFixed32_.Equals(other.packedFixed32_)) return false;
+ if(!packedFixed64_.Equals(other.packedFixed64_)) return false;
+ if(!packedSfixed32_.Equals(other.packedSfixed32_)) return false;
+ if(!packedSfixed64_.Equals(other.packedSfixed64_)) return false;
+ if(!packedFloat_.Equals(other.packedFloat_)) return false;
+ if(!packedDouble_.Equals(other.packedDouble_)) return false;
+ if(!packedBool_.Equals(other.packedBool_)) return false;
+ if(!packedEnum_.Equals(other.packedEnum_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= packedInt32_.GetHashCode();
+ hash ^= packedInt64_.GetHashCode();
+ hash ^= packedUint32_.GetHashCode();
+ hash ^= packedUint64_.GetHashCode();
+ hash ^= packedSint32_.GetHashCode();
+ hash ^= packedSint64_.GetHashCode();
+ hash ^= packedFixed32_.GetHashCode();
+ hash ^= packedFixed64_.GetHashCode();
+ hash ^= packedSfixed32_.GetHashCode();
+ hash ^= packedSfixed64_.GetHashCode();
+ hash ^= packedFloat_.GetHashCode();
+ hash ^= packedDouble_.GetHashCode();
+ hash ^= packedBool_.GetHashCode();
+ hash ^= packedEnum_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ packedInt32_.WriteTo(output, _repeated_packedInt32_codec);
+ packedInt64_.WriteTo(output, _repeated_packedInt64_codec);
+ packedUint32_.WriteTo(output, _repeated_packedUint32_codec);
+ packedUint64_.WriteTo(output, _repeated_packedUint64_codec);
+ packedSint32_.WriteTo(output, _repeated_packedSint32_codec);
+ packedSint64_.WriteTo(output, _repeated_packedSint64_codec);
+ packedFixed32_.WriteTo(output, _repeated_packedFixed32_codec);
+ packedFixed64_.WriteTo(output, _repeated_packedFixed64_codec);
+ packedSfixed32_.WriteTo(output, _repeated_packedSfixed32_codec);
+ packedSfixed64_.WriteTo(output, _repeated_packedSfixed64_codec);
+ packedFloat_.WriteTo(output, _repeated_packedFloat_codec);
+ packedDouble_.WriteTo(output, _repeated_packedDouble_codec);
+ packedBool_.WriteTo(output, _repeated_packedBool_codec);
+ packedEnum_.WriteTo(output, _repeated_packedEnum_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += packedInt32_.CalculateSize(_repeated_packedInt32_codec);
+ size += packedInt64_.CalculateSize(_repeated_packedInt64_codec);
+ size += packedUint32_.CalculateSize(_repeated_packedUint32_codec);
+ size += packedUint64_.CalculateSize(_repeated_packedUint64_codec);
+ size += packedSint32_.CalculateSize(_repeated_packedSint32_codec);
+ size += packedSint64_.CalculateSize(_repeated_packedSint64_codec);
+ size += packedFixed32_.CalculateSize(_repeated_packedFixed32_codec);
+ size += packedFixed64_.CalculateSize(_repeated_packedFixed64_codec);
+ size += packedSfixed32_.CalculateSize(_repeated_packedSfixed32_codec);
+ size += packedSfixed64_.CalculateSize(_repeated_packedSfixed64_codec);
+ size += packedFloat_.CalculateSize(_repeated_packedFloat_codec);
+ size += packedDouble_.CalculateSize(_repeated_packedDouble_codec);
+ size += packedBool_.CalculateSize(_repeated_packedBool_codec);
+ size += packedEnum_.CalculateSize(_repeated_packedEnum_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestPackedTypes other) {
+ if (other == null) {
+ return;
+ }
+ packedInt32_.Add(other.packedInt32_);
+ packedInt64_.Add(other.packedInt64_);
+ packedUint32_.Add(other.packedUint32_);
+ packedUint64_.Add(other.packedUint64_);
+ packedSint32_.Add(other.packedSint32_);
+ packedSint64_.Add(other.packedSint64_);
+ packedFixed32_.Add(other.packedFixed32_);
+ packedFixed64_.Add(other.packedFixed64_);
+ packedSfixed32_.Add(other.packedSfixed32_);
+ packedSfixed64_.Add(other.packedSfixed64_);
+ packedFloat_.Add(other.packedFloat_);
+ packedDouble_.Add(other.packedDouble_);
+ packedBool_.Add(other.packedBool_);
+ packedEnum_.Add(other.packedEnum_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 722:
+ case 720: {
+ packedInt32_.AddEntriesFrom(input, _repeated_packedInt32_codec);
+ break;
+ }
+ case 730:
+ case 728: {
+ packedInt64_.AddEntriesFrom(input, _repeated_packedInt64_codec);
+ break;
+ }
+ case 738:
+ case 736: {
+ packedUint32_.AddEntriesFrom(input, _repeated_packedUint32_codec);
+ break;
+ }
+ case 746:
+ case 744: {
+ packedUint64_.AddEntriesFrom(input, _repeated_packedUint64_codec);
+ break;
+ }
+ case 754:
+ case 752: {
+ packedSint32_.AddEntriesFrom(input, _repeated_packedSint32_codec);
+ break;
+ }
+ case 762:
+ case 760: {
+ packedSint64_.AddEntriesFrom(input, _repeated_packedSint64_codec);
+ break;
+ }
+ case 770:
+ case 773: {
+ packedFixed32_.AddEntriesFrom(input, _repeated_packedFixed32_codec);
+ break;
+ }
+ case 778:
+ case 777: {
+ packedFixed64_.AddEntriesFrom(input, _repeated_packedFixed64_codec);
+ break;
+ }
+ case 786:
+ case 789: {
+ packedSfixed32_.AddEntriesFrom(input, _repeated_packedSfixed32_codec);
+ break;
+ }
+ case 794:
+ case 793: {
+ packedSfixed64_.AddEntriesFrom(input, _repeated_packedSfixed64_codec);
+ break;
+ }
+ case 802:
+ case 805: {
+ packedFloat_.AddEntriesFrom(input, _repeated_packedFloat_codec);
+ break;
+ }
+ case 810:
+ case 809: {
+ packedDouble_.AddEntriesFrom(input, _repeated_packedDouble_codec);
+ break;
+ }
+ case 818:
+ case 816: {
+ packedBool_.AddEntriesFrom(input, _repeated_packedBool_codec);
+ break;
+ }
+ case 826:
+ case 824: {
+ packedEnum_.AddEntriesFrom(input, _repeated_packedEnum_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// A message with the same fields as TestPackedTypes, but without packing. Used
+ /// to test packed &lt;-> unpacked wire compatibility.
+ /// </summary>
+ public sealed partial class TestUnpackedTypes : pb::IMessage<TestUnpackedTypes> {
+ private static readonly pb::MessageParser<TestUnpackedTypes> _parser = new pb::MessageParser<TestUnpackedTypes>(() => new TestUnpackedTypes());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestUnpackedTypes> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[25]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestUnpackedTypes() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestUnpackedTypes(TestUnpackedTypes other) : this() {
+ unpackedInt32_ = other.unpackedInt32_.Clone();
+ unpackedInt64_ = other.unpackedInt64_.Clone();
+ unpackedUint32_ = other.unpackedUint32_.Clone();
+ unpackedUint64_ = other.unpackedUint64_.Clone();
+ unpackedSint32_ = other.unpackedSint32_.Clone();
+ unpackedSint64_ = other.unpackedSint64_.Clone();
+ unpackedFixed32_ = other.unpackedFixed32_.Clone();
+ unpackedFixed64_ = other.unpackedFixed64_.Clone();
+ unpackedSfixed32_ = other.unpackedSfixed32_.Clone();
+ unpackedSfixed64_ = other.unpackedSfixed64_.Clone();
+ unpackedFloat_ = other.unpackedFloat_.Clone();
+ unpackedDouble_ = other.unpackedDouble_.Clone();
+ unpackedBool_ = other.unpackedBool_.Clone();
+ unpackedEnum_ = other.unpackedEnum_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestUnpackedTypes Clone() {
+ return new TestUnpackedTypes(this);
+ }
+
+ /// <summary>Field number for the "unpacked_int32" field.</summary>
+ public const int UnpackedInt32FieldNumber = 90;
+ private static readonly pb::FieldCodec<int> _repeated_unpackedInt32_codec
+ = pb::FieldCodec.ForInt32(720);
+ private readonly pbc::RepeatedField<int> unpackedInt32_ = new pbc::RepeatedField<int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> UnpackedInt32 {
+ get { return unpackedInt32_; }
+ }
+
+ /// <summary>Field number for the "unpacked_int64" field.</summary>
+ public const int UnpackedInt64FieldNumber = 91;
+ private static readonly pb::FieldCodec<long> _repeated_unpackedInt64_codec
+ = pb::FieldCodec.ForInt64(728);
+ private readonly pbc::RepeatedField<long> unpackedInt64_ = new pbc::RepeatedField<long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<long> UnpackedInt64 {
+ get { return unpackedInt64_; }
+ }
+
+ /// <summary>Field number for the "unpacked_uint32" field.</summary>
+ public const int UnpackedUint32FieldNumber = 92;
+ private static readonly pb::FieldCodec<uint> _repeated_unpackedUint32_codec
+ = pb::FieldCodec.ForUInt32(736);
+ private readonly pbc::RepeatedField<uint> unpackedUint32_ = new pbc::RepeatedField<uint>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<uint> UnpackedUint32 {
+ get { return unpackedUint32_; }
+ }
+
+ /// <summary>Field number for the "unpacked_uint64" field.</summary>
+ public const int UnpackedUint64FieldNumber = 93;
+ private static readonly pb::FieldCodec<ulong> _repeated_unpackedUint64_codec
+ = pb::FieldCodec.ForUInt64(744);
+ private readonly pbc::RepeatedField<ulong> unpackedUint64_ = new pbc::RepeatedField<ulong>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<ulong> UnpackedUint64 {
+ get { return unpackedUint64_; }
+ }
+
+ /// <summary>Field number for the "unpacked_sint32" field.</summary>
+ public const int UnpackedSint32FieldNumber = 94;
+ private static readonly pb::FieldCodec<int> _repeated_unpackedSint32_codec
+ = pb::FieldCodec.ForSInt32(752);
+ private readonly pbc::RepeatedField<int> unpackedSint32_ = new pbc::RepeatedField<int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> UnpackedSint32 {
+ get { return unpackedSint32_; }
+ }
+
+ /// <summary>Field number for the "unpacked_sint64" field.</summary>
+ public const int UnpackedSint64FieldNumber = 95;
+ private static readonly pb::FieldCodec<long> _repeated_unpackedSint64_codec
+ = pb::FieldCodec.ForSInt64(760);
+ private readonly pbc::RepeatedField<long> unpackedSint64_ = new pbc::RepeatedField<long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<long> UnpackedSint64 {
+ get { return unpackedSint64_; }
+ }
+
+ /// <summary>Field number for the "unpacked_fixed32" field.</summary>
+ public const int UnpackedFixed32FieldNumber = 96;
+ private static readonly pb::FieldCodec<uint> _repeated_unpackedFixed32_codec
+ = pb::FieldCodec.ForFixed32(773);
+ private readonly pbc::RepeatedField<uint> unpackedFixed32_ = new pbc::RepeatedField<uint>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<uint> UnpackedFixed32 {
+ get { return unpackedFixed32_; }
+ }
+
+ /// <summary>Field number for the "unpacked_fixed64" field.</summary>
+ public const int UnpackedFixed64FieldNumber = 97;
+ private static readonly pb::FieldCodec<ulong> _repeated_unpackedFixed64_codec
+ = pb::FieldCodec.ForFixed64(777);
+ private readonly pbc::RepeatedField<ulong> unpackedFixed64_ = new pbc::RepeatedField<ulong>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<ulong> UnpackedFixed64 {
+ get { return unpackedFixed64_; }
+ }
+
+ /// <summary>Field number for the "unpacked_sfixed32" field.</summary>
+ public const int UnpackedSfixed32FieldNumber = 98;
+ private static readonly pb::FieldCodec<int> _repeated_unpackedSfixed32_codec
+ = pb::FieldCodec.ForSFixed32(789);
+ private readonly pbc::RepeatedField<int> unpackedSfixed32_ = new pbc::RepeatedField<int>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> UnpackedSfixed32 {
+ get { return unpackedSfixed32_; }
+ }
+
+ /// <summary>Field number for the "unpacked_sfixed64" field.</summary>
+ public const int UnpackedSfixed64FieldNumber = 99;
+ private static readonly pb::FieldCodec<long> _repeated_unpackedSfixed64_codec
+ = pb::FieldCodec.ForSFixed64(793);
+ private readonly pbc::RepeatedField<long> unpackedSfixed64_ = new pbc::RepeatedField<long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<long> UnpackedSfixed64 {
+ get { return unpackedSfixed64_; }
+ }
+
+ /// <summary>Field number for the "unpacked_float" field.</summary>
+ public const int UnpackedFloatFieldNumber = 100;
+ private static readonly pb::FieldCodec<float> _repeated_unpackedFloat_codec
+ = pb::FieldCodec.ForFloat(805);
+ private readonly pbc::RepeatedField<float> unpackedFloat_ = new pbc::RepeatedField<float>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<float> UnpackedFloat {
+ get { return unpackedFloat_; }
+ }
+
+ /// <summary>Field number for the "unpacked_double" field.</summary>
+ public const int UnpackedDoubleFieldNumber = 101;
+ private static readonly pb::FieldCodec<double> _repeated_unpackedDouble_codec
+ = pb::FieldCodec.ForDouble(809);
+ private readonly pbc::RepeatedField<double> unpackedDouble_ = new pbc::RepeatedField<double>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<double> UnpackedDouble {
+ get { return unpackedDouble_; }
+ }
+
+ /// <summary>Field number for the "unpacked_bool" field.</summary>
+ public const int UnpackedBoolFieldNumber = 102;
+ private static readonly pb::FieldCodec<bool> _repeated_unpackedBool_codec
+ = pb::FieldCodec.ForBool(816);
+ private readonly pbc::RepeatedField<bool> unpackedBool_ = new pbc::RepeatedField<bool>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<bool> UnpackedBool {
+ get { return unpackedBool_; }
+ }
+
+ /// <summary>Field number for the "unpacked_enum" field.</summary>
+ public const int UnpackedEnumFieldNumber = 103;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.TestProtos.ForeignEnum> _repeated_unpackedEnum_codec
+ = pb::FieldCodec.ForEnum(824, x => (int) x, x => (global::Google.Protobuf.TestProtos.ForeignEnum) x);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignEnum> unpackedEnum_ = new pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignEnum>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.TestProtos.ForeignEnum> UnpackedEnum {
+ get { return unpackedEnum_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestUnpackedTypes);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestUnpackedTypes other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if(!unpackedInt32_.Equals(other.unpackedInt32_)) return false;
+ if(!unpackedInt64_.Equals(other.unpackedInt64_)) return false;
+ if(!unpackedUint32_.Equals(other.unpackedUint32_)) return false;
+ if(!unpackedUint64_.Equals(other.unpackedUint64_)) return false;
+ if(!unpackedSint32_.Equals(other.unpackedSint32_)) return false;
+ if(!unpackedSint64_.Equals(other.unpackedSint64_)) return false;
+ if(!unpackedFixed32_.Equals(other.unpackedFixed32_)) return false;
+ if(!unpackedFixed64_.Equals(other.unpackedFixed64_)) return false;
+ if(!unpackedSfixed32_.Equals(other.unpackedSfixed32_)) return false;
+ if(!unpackedSfixed64_.Equals(other.unpackedSfixed64_)) return false;
+ if(!unpackedFloat_.Equals(other.unpackedFloat_)) return false;
+ if(!unpackedDouble_.Equals(other.unpackedDouble_)) return false;
+ if(!unpackedBool_.Equals(other.unpackedBool_)) return false;
+ if(!unpackedEnum_.Equals(other.unpackedEnum_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= unpackedInt32_.GetHashCode();
+ hash ^= unpackedInt64_.GetHashCode();
+ hash ^= unpackedUint32_.GetHashCode();
+ hash ^= unpackedUint64_.GetHashCode();
+ hash ^= unpackedSint32_.GetHashCode();
+ hash ^= unpackedSint64_.GetHashCode();
+ hash ^= unpackedFixed32_.GetHashCode();
+ hash ^= unpackedFixed64_.GetHashCode();
+ hash ^= unpackedSfixed32_.GetHashCode();
+ hash ^= unpackedSfixed64_.GetHashCode();
+ hash ^= unpackedFloat_.GetHashCode();
+ hash ^= unpackedDouble_.GetHashCode();
+ hash ^= unpackedBool_.GetHashCode();
+ hash ^= unpackedEnum_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ unpackedInt32_.WriteTo(output, _repeated_unpackedInt32_codec);
+ unpackedInt64_.WriteTo(output, _repeated_unpackedInt64_codec);
+ unpackedUint32_.WriteTo(output, _repeated_unpackedUint32_codec);
+ unpackedUint64_.WriteTo(output, _repeated_unpackedUint64_codec);
+ unpackedSint32_.WriteTo(output, _repeated_unpackedSint32_codec);
+ unpackedSint64_.WriteTo(output, _repeated_unpackedSint64_codec);
+ unpackedFixed32_.WriteTo(output, _repeated_unpackedFixed32_codec);
+ unpackedFixed64_.WriteTo(output, _repeated_unpackedFixed64_codec);
+ unpackedSfixed32_.WriteTo(output, _repeated_unpackedSfixed32_codec);
+ unpackedSfixed64_.WriteTo(output, _repeated_unpackedSfixed64_codec);
+ unpackedFloat_.WriteTo(output, _repeated_unpackedFloat_codec);
+ unpackedDouble_.WriteTo(output, _repeated_unpackedDouble_codec);
+ unpackedBool_.WriteTo(output, _repeated_unpackedBool_codec);
+ unpackedEnum_.WriteTo(output, _repeated_unpackedEnum_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += unpackedInt32_.CalculateSize(_repeated_unpackedInt32_codec);
+ size += unpackedInt64_.CalculateSize(_repeated_unpackedInt64_codec);
+ size += unpackedUint32_.CalculateSize(_repeated_unpackedUint32_codec);
+ size += unpackedUint64_.CalculateSize(_repeated_unpackedUint64_codec);
+ size += unpackedSint32_.CalculateSize(_repeated_unpackedSint32_codec);
+ size += unpackedSint64_.CalculateSize(_repeated_unpackedSint64_codec);
+ size += unpackedFixed32_.CalculateSize(_repeated_unpackedFixed32_codec);
+ size += unpackedFixed64_.CalculateSize(_repeated_unpackedFixed64_codec);
+ size += unpackedSfixed32_.CalculateSize(_repeated_unpackedSfixed32_codec);
+ size += unpackedSfixed64_.CalculateSize(_repeated_unpackedSfixed64_codec);
+ size += unpackedFloat_.CalculateSize(_repeated_unpackedFloat_codec);
+ size += unpackedDouble_.CalculateSize(_repeated_unpackedDouble_codec);
+ size += unpackedBool_.CalculateSize(_repeated_unpackedBool_codec);
+ size += unpackedEnum_.CalculateSize(_repeated_unpackedEnum_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestUnpackedTypes other) {
+ if (other == null) {
+ return;
+ }
+ unpackedInt32_.Add(other.unpackedInt32_);
+ unpackedInt64_.Add(other.unpackedInt64_);
+ unpackedUint32_.Add(other.unpackedUint32_);
+ unpackedUint64_.Add(other.unpackedUint64_);
+ unpackedSint32_.Add(other.unpackedSint32_);
+ unpackedSint64_.Add(other.unpackedSint64_);
+ unpackedFixed32_.Add(other.unpackedFixed32_);
+ unpackedFixed64_.Add(other.unpackedFixed64_);
+ unpackedSfixed32_.Add(other.unpackedSfixed32_);
+ unpackedSfixed64_.Add(other.unpackedSfixed64_);
+ unpackedFloat_.Add(other.unpackedFloat_);
+ unpackedDouble_.Add(other.unpackedDouble_);
+ unpackedBool_.Add(other.unpackedBool_);
+ unpackedEnum_.Add(other.unpackedEnum_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 722:
+ case 720: {
+ unpackedInt32_.AddEntriesFrom(input, _repeated_unpackedInt32_codec);
+ break;
+ }
+ case 730:
+ case 728: {
+ unpackedInt64_.AddEntriesFrom(input, _repeated_unpackedInt64_codec);
+ break;
+ }
+ case 738:
+ case 736: {
+ unpackedUint32_.AddEntriesFrom(input, _repeated_unpackedUint32_codec);
+ break;
+ }
+ case 746:
+ case 744: {
+ unpackedUint64_.AddEntriesFrom(input, _repeated_unpackedUint64_codec);
+ break;
+ }
+ case 754:
+ case 752: {
+ unpackedSint32_.AddEntriesFrom(input, _repeated_unpackedSint32_codec);
+ break;
+ }
+ case 762:
+ case 760: {
+ unpackedSint64_.AddEntriesFrom(input, _repeated_unpackedSint64_codec);
+ break;
+ }
+ case 770:
+ case 773: {
+ unpackedFixed32_.AddEntriesFrom(input, _repeated_unpackedFixed32_codec);
+ break;
+ }
+ case 778:
+ case 777: {
+ unpackedFixed64_.AddEntriesFrom(input, _repeated_unpackedFixed64_codec);
+ break;
+ }
+ case 786:
+ case 789: {
+ unpackedSfixed32_.AddEntriesFrom(input, _repeated_unpackedSfixed32_codec);
+ break;
+ }
+ case 794:
+ case 793: {
+ unpackedSfixed64_.AddEntriesFrom(input, _repeated_unpackedSfixed64_codec);
+ break;
+ }
+ case 802:
+ case 805: {
+ unpackedFloat_.AddEntriesFrom(input, _repeated_unpackedFloat_codec);
+ break;
+ }
+ case 810:
+ case 809: {
+ unpackedDouble_.AddEntriesFrom(input, _repeated_unpackedDouble_codec);
+ break;
+ }
+ case 818:
+ case 816: {
+ unpackedBool_.AddEntriesFrom(input, _repeated_unpackedBool_codec);
+ break;
+ }
+ case 826:
+ case 824: {
+ unpackedEnum_.AddEntriesFrom(input, _repeated_unpackedEnum_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class TestRepeatedScalarDifferentTagSizes : pb::IMessage<TestRepeatedScalarDifferentTagSizes> {
+ private static readonly pb::MessageParser<TestRepeatedScalarDifferentTagSizes> _parser = new pb::MessageParser<TestRepeatedScalarDifferentTagSizes>(() => new TestRepeatedScalarDifferentTagSizes());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestRepeatedScalarDifferentTagSizes> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[26]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestRepeatedScalarDifferentTagSizes() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestRepeatedScalarDifferentTagSizes(TestRepeatedScalarDifferentTagSizes other) : this() {
+ repeatedFixed32_ = other.repeatedFixed32_.Clone();
+ repeatedInt32_ = other.repeatedInt32_.Clone();
+ repeatedFixed64_ = other.repeatedFixed64_.Clone();
+ repeatedInt64_ = other.repeatedInt64_.Clone();
+ repeatedFloat_ = other.repeatedFloat_.Clone();
+ repeatedUint64_ = other.repeatedUint64_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestRepeatedScalarDifferentTagSizes Clone() {
+ return new TestRepeatedScalarDifferentTagSizes(this);
+ }
+
+ /// <summary>Field number for the "repeated_fixed32" field.</summary>
+ public const int RepeatedFixed32FieldNumber = 12;
+ private static readonly pb::FieldCodec<uint> _repeated_repeatedFixed32_codec
+ = pb::FieldCodec.ForFixed32(98);
+ private readonly pbc::RepeatedField<uint> repeatedFixed32_ = new pbc::RepeatedField<uint>();
+ /// <summary>
+ /// Parsing repeated fixed size values used to fail. This message needs to be
+ /// used in order to get a tag of the right size; all of the repeated fields
+ /// in TestAllTypes didn't trigger the check.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<uint> RepeatedFixed32 {
+ get { return repeatedFixed32_; }
+ }
+
+ /// <summary>Field number for the "repeated_int32" field.</summary>
+ public const int RepeatedInt32FieldNumber = 13;
+ private static readonly pb::FieldCodec<int> _repeated_repeatedInt32_codec
+ = pb::FieldCodec.ForInt32(106);
+ private readonly pbc::RepeatedField<int> repeatedInt32_ = new pbc::RepeatedField<int>();
+ /// <summary>
+ /// Check for a varint type, just for good measure.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> RepeatedInt32 {
+ get { return repeatedInt32_; }
+ }
+
+ /// <summary>Field number for the "repeated_fixed64" field.</summary>
+ public const int RepeatedFixed64FieldNumber = 2046;
+ private static readonly pb::FieldCodec<ulong> _repeated_repeatedFixed64_codec
+ = pb::FieldCodec.ForFixed64(16370);
+ private readonly pbc::RepeatedField<ulong> repeatedFixed64_ = new pbc::RepeatedField<ulong>();
+ /// <summary>
+ /// These have two-byte tags.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<ulong> RepeatedFixed64 {
+ get { return repeatedFixed64_; }
+ }
+
+ /// <summary>Field number for the "repeated_int64" field.</summary>
+ public const int RepeatedInt64FieldNumber = 2047;
+ private static readonly pb::FieldCodec<long> _repeated_repeatedInt64_codec
+ = pb::FieldCodec.ForInt64(16378);
+ private readonly pbc::RepeatedField<long> repeatedInt64_ = new pbc::RepeatedField<long>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<long> RepeatedInt64 {
+ get { return repeatedInt64_; }
+ }
+
+ /// <summary>Field number for the "repeated_float" field.</summary>
+ public const int RepeatedFloatFieldNumber = 262142;
+ private static readonly pb::FieldCodec<float> _repeated_repeatedFloat_codec
+ = pb::FieldCodec.ForFloat(2097138);
+ private readonly pbc::RepeatedField<float> repeatedFloat_ = new pbc::RepeatedField<float>();
+ /// <summary>
+ /// Three byte tags.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<float> RepeatedFloat {
+ get { return repeatedFloat_; }
+ }
+
+ /// <summary>Field number for the "repeated_uint64" field.</summary>
+ public const int RepeatedUint64FieldNumber = 262143;
+ private static readonly pb::FieldCodec<ulong> _repeated_repeatedUint64_codec
+ = pb::FieldCodec.ForUInt64(2097146);
+ private readonly pbc::RepeatedField<ulong> repeatedUint64_ = new pbc::RepeatedField<ulong>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<ulong> RepeatedUint64 {
+ get { return repeatedUint64_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestRepeatedScalarDifferentTagSizes);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestRepeatedScalarDifferentTagSizes other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if(!repeatedFixed32_.Equals(other.repeatedFixed32_)) return false;
+ if(!repeatedInt32_.Equals(other.repeatedInt32_)) return false;
+ if(!repeatedFixed64_.Equals(other.repeatedFixed64_)) return false;
+ if(!repeatedInt64_.Equals(other.repeatedInt64_)) return false;
+ if(!repeatedFloat_.Equals(other.repeatedFloat_)) return false;
+ if(!repeatedUint64_.Equals(other.repeatedUint64_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= repeatedFixed32_.GetHashCode();
+ hash ^= repeatedInt32_.GetHashCode();
+ hash ^= repeatedFixed64_.GetHashCode();
+ hash ^= repeatedInt64_.GetHashCode();
+ hash ^= repeatedFloat_.GetHashCode();
+ hash ^= repeatedUint64_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ repeatedFixed32_.WriteTo(output, _repeated_repeatedFixed32_codec);
+ repeatedInt32_.WriteTo(output, _repeated_repeatedInt32_codec);
+ repeatedFixed64_.WriteTo(output, _repeated_repeatedFixed64_codec);
+ repeatedInt64_.WriteTo(output, _repeated_repeatedInt64_codec);
+ repeatedFloat_.WriteTo(output, _repeated_repeatedFloat_codec);
+ repeatedUint64_.WriteTo(output, _repeated_repeatedUint64_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += repeatedFixed32_.CalculateSize(_repeated_repeatedFixed32_codec);
+ size += repeatedInt32_.CalculateSize(_repeated_repeatedInt32_codec);
+ size += repeatedFixed64_.CalculateSize(_repeated_repeatedFixed64_codec);
+ size += repeatedInt64_.CalculateSize(_repeated_repeatedInt64_codec);
+ size += repeatedFloat_.CalculateSize(_repeated_repeatedFloat_codec);
+ size += repeatedUint64_.CalculateSize(_repeated_repeatedUint64_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestRepeatedScalarDifferentTagSizes other) {
+ if (other == null) {
+ return;
+ }
+ repeatedFixed32_.Add(other.repeatedFixed32_);
+ repeatedInt32_.Add(other.repeatedInt32_);
+ repeatedFixed64_.Add(other.repeatedFixed64_);
+ repeatedInt64_.Add(other.repeatedInt64_);
+ repeatedFloat_.Add(other.repeatedFloat_);
+ repeatedUint64_.Add(other.repeatedUint64_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 98:
+ case 101: {
+ repeatedFixed32_.AddEntriesFrom(input, _repeated_repeatedFixed32_codec);
+ break;
+ }
+ case 106:
+ case 104: {
+ repeatedInt32_.AddEntriesFrom(input, _repeated_repeatedInt32_codec);
+ break;
+ }
+ case 16370:
+ case 16369: {
+ repeatedFixed64_.AddEntriesFrom(input, _repeated_repeatedFixed64_codec);
+ break;
+ }
+ case 16378:
+ case 16376: {
+ repeatedInt64_.AddEntriesFrom(input, _repeated_repeatedInt64_codec);
+ break;
+ }
+ case 2097138:
+ case 2097141: {
+ repeatedFloat_.AddEntriesFrom(input, _repeated_repeatedFloat_codec);
+ break;
+ }
+ case 2097146:
+ case 2097144: {
+ repeatedUint64_.AddEntriesFrom(input, _repeated_repeatedUint64_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class TestCommentInjectionMessage : pb::IMessage<TestCommentInjectionMessage> {
+ private static readonly pb::MessageParser<TestCommentInjectionMessage> _parser = new pb::MessageParser<TestCommentInjectionMessage>(() => new TestCommentInjectionMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestCommentInjectionMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[27]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestCommentInjectionMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestCommentInjectionMessage(TestCommentInjectionMessage other) : this() {
+ a_ = other.a_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestCommentInjectionMessage Clone() {
+ return new TestCommentInjectionMessage(this);
+ }
+
+ /// <summary>Field number for the "a" field.</summary>
+ public const int AFieldNumber = 1;
+ private string a_ = "";
+ /// <summary>
+ /// */ &lt;- This should not close the generated doc comment
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string A {
+ get { return a_; }
+ set {
+ a_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestCommentInjectionMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestCommentInjectionMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (A != other.A) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (A.Length != 0) hash ^= A.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (A.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(A);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (A.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(A);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestCommentInjectionMessage other) {
+ if (other == null) {
+ return;
+ }
+ if (other.A.Length != 0) {
+ A = other.A;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ A = input.ReadString();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Test that RPC services work.
+ /// </summary>
+ public sealed partial class FooRequest : pb::IMessage<FooRequest> {
+ private static readonly pb::MessageParser<FooRequest> _parser = new pb::MessageParser<FooRequest>(() => new FooRequest());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<FooRequest> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[28]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FooRequest() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FooRequest(FooRequest other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FooRequest Clone() {
+ return new FooRequest(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as FooRequest);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(FooRequest other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(FooRequest other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class FooResponse : pb::IMessage<FooResponse> {
+ private static readonly pb::MessageParser<FooResponse> _parser = new pb::MessageParser<FooResponse>(() => new FooResponse());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<FooResponse> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[29]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FooResponse() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FooResponse(FooResponse other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FooResponse Clone() {
+ return new FooResponse(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as FooResponse);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(FooResponse other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(FooResponse other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class FooClientMessage : pb::IMessage<FooClientMessage> {
+ private static readonly pb::MessageParser<FooClientMessage> _parser = new pb::MessageParser<FooClientMessage>(() => new FooClientMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<FooClientMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[30]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FooClientMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FooClientMessage(FooClientMessage other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FooClientMessage Clone() {
+ return new FooClientMessage(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as FooClientMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(FooClientMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(FooClientMessage other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class FooServerMessage : pb::IMessage<FooServerMessage> {
+ private static readonly pb::MessageParser<FooServerMessage> _parser = new pb::MessageParser<FooServerMessage>(() => new FooServerMessage());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<FooServerMessage> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[31]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FooServerMessage() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FooServerMessage(FooServerMessage other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FooServerMessage Clone() {
+ return new FooServerMessage(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as FooServerMessage);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(FooServerMessage other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(FooServerMessage other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class BarRequest : pb::IMessage<BarRequest> {
+ private static readonly pb::MessageParser<BarRequest> _parser = new pb::MessageParser<BarRequest>(() => new BarRequest());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<BarRequest> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[32]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public BarRequest() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public BarRequest(BarRequest other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public BarRequest Clone() {
+ return new BarRequest(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as BarRequest);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(BarRequest other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(BarRequest other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class BarResponse : pb::IMessage<BarResponse> {
+ private static readonly pb::MessageParser<BarResponse> _parser = new pb::MessageParser<BarResponse>(() => new BarResponse());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<BarResponse> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestProto3Reflection.Descriptor.MessageTypes[33]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public BarResponse() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public BarResponse(BarResponse other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public BarResponse Clone() {
+ return new BarResponse(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as BarResponse);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(BarResponse other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(BarResponse other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs
new file mode 100644
index 0000000000..2c7f0e0e1e
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/TestProtos/UnittestWellKnownTypes.cs
@@ -0,0 +1,2539 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/unittest_well_known_types.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.TestProtos {
+
+ /// <summary>Holder for reflection information generated from google/protobuf/unittest_well_known_types.proto</summary>
+ public static partial class UnittestWellKnownTypesReflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for google/protobuf/unittest_well_known_types.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static UnittestWellKnownTypesReflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "Ci9nb29nbGUvcHJvdG9idWYvdW5pdHRlc3Rfd2VsbF9rbm93bl90eXBlcy5w",
+ "cm90bxIRcHJvdG9idWZfdW5pdHRlc3QaGWdvb2dsZS9wcm90b2J1Zi9hbnku",
+ "cHJvdG8aGWdvb2dsZS9wcm90b2J1Zi9hcGkucHJvdG8aHmdvb2dsZS9wcm90",
+ "b2J1Zi9kdXJhdGlvbi5wcm90bxobZ29vZ2xlL3Byb3RvYnVmL2VtcHR5LnBy",
+ "b3RvGiBnb29nbGUvcHJvdG9idWYvZmllbGRfbWFzay5wcm90bxokZ29vZ2xl",
+ "L3Byb3RvYnVmL3NvdXJjZV9jb250ZXh0LnByb3RvGhxnb29nbGUvcHJvdG9i",
+ "dWYvc3RydWN0LnByb3RvGh9nb29nbGUvcHJvdG9idWYvdGltZXN0YW1wLnBy",
+ "b3RvGhpnb29nbGUvcHJvdG9idWYvdHlwZS5wcm90bxoeZ29vZ2xlL3Byb3Rv",
+ "YnVmL3dyYXBwZXJzLnByb3RvIr4HChJUZXN0V2VsbEtub3duVHlwZXMSJwoJ",
+ "YW55X2ZpZWxkGAEgASgLMhQuZ29vZ2xlLnByb3RvYnVmLkFueRInCglhcGlf",
+ "ZmllbGQYAiABKAsyFC5nb29nbGUucHJvdG9idWYuQXBpEjEKDmR1cmF0aW9u",
+ "X2ZpZWxkGAMgASgLMhkuZ29vZ2xlLnByb3RvYnVmLkR1cmF0aW9uEisKC2Vt",
+ "cHR5X2ZpZWxkGAQgASgLMhYuZ29vZ2xlLnByb3RvYnVmLkVtcHR5EjQKEGZp",
+ "ZWxkX21hc2tfZmllbGQYBSABKAsyGi5nb29nbGUucHJvdG9idWYuRmllbGRN",
+ "YXNrEjwKFHNvdXJjZV9jb250ZXh0X2ZpZWxkGAYgASgLMh4uZ29vZ2xlLnBy",
+ "b3RvYnVmLlNvdXJjZUNvbnRleHQSLQoMc3RydWN0X2ZpZWxkGAcgASgLMhcu",
+ "Z29vZ2xlLnByb3RvYnVmLlN0cnVjdBIzCg90aW1lc3RhbXBfZmllbGQYCCAB",
+ "KAsyGi5nb29nbGUucHJvdG9idWYuVGltZXN0YW1wEikKCnR5cGVfZmllbGQY",
+ "CSABKAsyFS5nb29nbGUucHJvdG9idWYuVHlwZRIyCgxkb3VibGVfZmllbGQY",
+ "CiABKAsyHC5nb29nbGUucHJvdG9idWYuRG91YmxlVmFsdWUSMAoLZmxvYXRf",
+ "ZmllbGQYCyABKAsyGy5nb29nbGUucHJvdG9idWYuRmxvYXRWYWx1ZRIwCgtp",
+ "bnQ2NF9maWVsZBgMIAEoCzIbLmdvb2dsZS5wcm90b2J1Zi5JbnQ2NFZhbHVl",
+ "EjIKDHVpbnQ2NF9maWVsZBgNIAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5VSW50",
+ "NjRWYWx1ZRIwCgtpbnQzMl9maWVsZBgOIAEoCzIbLmdvb2dsZS5wcm90b2J1",
+ "Zi5JbnQzMlZhbHVlEjIKDHVpbnQzMl9maWVsZBgPIAEoCzIcLmdvb2dsZS5w",
+ "cm90b2J1Zi5VSW50MzJWYWx1ZRIuCgpib29sX2ZpZWxkGBAgASgLMhouZ29v",
+ "Z2xlLnByb3RvYnVmLkJvb2xWYWx1ZRIyCgxzdHJpbmdfZmllbGQYESABKAsy",
+ "HC5nb29nbGUucHJvdG9idWYuU3RyaW5nVmFsdWUSMAoLYnl0ZXNfZmllbGQY",
+ "EiABKAsyGy5nb29nbGUucHJvdG9idWYuQnl0ZXNWYWx1ZRIrCgt2YWx1ZV9m",
+ "aWVsZBgTIAEoCzIWLmdvb2dsZS5wcm90b2J1Zi5WYWx1ZSKVBwoWUmVwZWF0",
+ "ZWRXZWxsS25vd25UeXBlcxInCglhbnlfZmllbGQYASADKAsyFC5nb29nbGUu",
+ "cHJvdG9idWYuQW55EicKCWFwaV9maWVsZBgCIAMoCzIULmdvb2dsZS5wcm90",
+ "b2J1Zi5BcGkSMQoOZHVyYXRpb25fZmllbGQYAyADKAsyGS5nb29nbGUucHJv",
+ "dG9idWYuRHVyYXRpb24SKwoLZW1wdHlfZmllbGQYBCADKAsyFi5nb29nbGUu",
+ "cHJvdG9idWYuRW1wdHkSNAoQZmllbGRfbWFza19maWVsZBgFIAMoCzIaLmdv",
+ "b2dsZS5wcm90b2J1Zi5GaWVsZE1hc2sSPAoUc291cmNlX2NvbnRleHRfZmll",
+ "bGQYBiADKAsyHi5nb29nbGUucHJvdG9idWYuU291cmNlQ29udGV4dBItCgxz",
+ "dHJ1Y3RfZmllbGQYByADKAsyFy5nb29nbGUucHJvdG9idWYuU3RydWN0EjMK",
+ "D3RpbWVzdGFtcF9maWVsZBgIIAMoCzIaLmdvb2dsZS5wcm90b2J1Zi5UaW1l",
+ "c3RhbXASKQoKdHlwZV9maWVsZBgJIAMoCzIVLmdvb2dsZS5wcm90b2J1Zi5U",
+ "eXBlEjIKDGRvdWJsZV9maWVsZBgKIAMoCzIcLmdvb2dsZS5wcm90b2J1Zi5E",
+ "b3VibGVWYWx1ZRIwCgtmbG9hdF9maWVsZBgLIAMoCzIbLmdvb2dsZS5wcm90",
+ "b2J1Zi5GbG9hdFZhbHVlEjAKC2ludDY0X2ZpZWxkGAwgAygLMhsuZ29vZ2xl",
+ "LnByb3RvYnVmLkludDY0VmFsdWUSMgoMdWludDY0X2ZpZWxkGA0gAygLMhwu",
+ "Z29vZ2xlLnByb3RvYnVmLlVJbnQ2NFZhbHVlEjAKC2ludDMyX2ZpZWxkGA4g",
+ "AygLMhsuZ29vZ2xlLnByb3RvYnVmLkludDMyVmFsdWUSMgoMdWludDMyX2Zp",
+ "ZWxkGA8gAygLMhwuZ29vZ2xlLnByb3RvYnVmLlVJbnQzMlZhbHVlEi4KCmJv",
+ "b2xfZmllbGQYECADKAsyGi5nb29nbGUucHJvdG9idWYuQm9vbFZhbHVlEjIK",
+ "DHN0cmluZ19maWVsZBgRIAMoCzIcLmdvb2dsZS5wcm90b2J1Zi5TdHJpbmdW",
+ "YWx1ZRIwCgtieXRlc19maWVsZBgSIAMoCzIbLmdvb2dsZS5wcm90b2J1Zi5C",
+ "eXRlc1ZhbHVlIsUHChNPbmVvZldlbGxLbm93blR5cGVzEikKCWFueV9maWVs",
+ "ZBgBIAEoCzIULmdvb2dsZS5wcm90b2J1Zi5BbnlIABIpCglhcGlfZmllbGQY",
+ "AiABKAsyFC5nb29nbGUucHJvdG9idWYuQXBpSAASMwoOZHVyYXRpb25fZmll",
+ "bGQYAyABKAsyGS5nb29nbGUucHJvdG9idWYuRHVyYXRpb25IABItCgtlbXB0",
+ "eV9maWVsZBgEIAEoCzIWLmdvb2dsZS5wcm90b2J1Zi5FbXB0eUgAEjYKEGZp",
+ "ZWxkX21hc2tfZmllbGQYBSABKAsyGi5nb29nbGUucHJvdG9idWYuRmllbGRN",
+ "YXNrSAASPgoUc291cmNlX2NvbnRleHRfZmllbGQYBiABKAsyHi5nb29nbGUu",
+ "cHJvdG9idWYuU291cmNlQ29udGV4dEgAEi8KDHN0cnVjdF9maWVsZBgHIAEo",
+ "CzIXLmdvb2dsZS5wcm90b2J1Zi5TdHJ1Y3RIABI1Cg90aW1lc3RhbXBfZmll",
+ "bGQYCCABKAsyGi5nb29nbGUucHJvdG9idWYuVGltZXN0YW1wSAASKwoKdHlw",
+ "ZV9maWVsZBgJIAEoCzIVLmdvb2dsZS5wcm90b2J1Zi5UeXBlSAASNAoMZG91",
+ "YmxlX2ZpZWxkGAogASgLMhwuZ29vZ2xlLnByb3RvYnVmLkRvdWJsZVZhbHVl",
+ "SAASMgoLZmxvYXRfZmllbGQYCyABKAsyGy5nb29nbGUucHJvdG9idWYuRmxv",
+ "YXRWYWx1ZUgAEjIKC2ludDY0X2ZpZWxkGAwgASgLMhsuZ29vZ2xlLnByb3Rv",
+ "YnVmLkludDY0VmFsdWVIABI0Cgx1aW50NjRfZmllbGQYDSABKAsyHC5nb29n",
+ "bGUucHJvdG9idWYuVUludDY0VmFsdWVIABIyCgtpbnQzMl9maWVsZBgOIAEo",
+ "CzIbLmdvb2dsZS5wcm90b2J1Zi5JbnQzMlZhbHVlSAASNAoMdWludDMyX2Zp",
+ "ZWxkGA8gASgLMhwuZ29vZ2xlLnByb3RvYnVmLlVJbnQzMlZhbHVlSAASMAoK",
+ "Ym9vbF9maWVsZBgQIAEoCzIaLmdvb2dsZS5wcm90b2J1Zi5Cb29sVmFsdWVI",
+ "ABI0CgxzdHJpbmdfZmllbGQYESABKAsyHC5nb29nbGUucHJvdG9idWYuU3Ry",
+ "aW5nVmFsdWVIABIyCgtieXRlc19maWVsZBgSIAEoCzIbLmdvb2dsZS5wcm90",
+ "b2J1Zi5CeXRlc1ZhbHVlSABCDQoLb25lb2ZfZmllbGQilhYKEU1hcFdlbGxL",
+ "bm93blR5cGVzEkUKCWFueV9maWVsZBgBIAMoCzIyLnByb3RvYnVmX3VuaXR0",
+ "ZXN0Lk1hcFdlbGxLbm93blR5cGVzLkFueUZpZWxkRW50cnkSRQoJYXBpX2Zp",
+ "ZWxkGAIgAygLMjIucHJvdG9idWZfdW5pdHRlc3QuTWFwV2VsbEtub3duVHlw",
+ "ZXMuQXBpRmllbGRFbnRyeRJPCg5kdXJhdGlvbl9maWVsZBgDIAMoCzI3LnBy",
+ "b3RvYnVmX3VuaXR0ZXN0Lk1hcFdlbGxLbm93blR5cGVzLkR1cmF0aW9uRmll",
+ "bGRFbnRyeRJJCgtlbXB0eV9maWVsZBgEIAMoCzI0LnByb3RvYnVmX3VuaXR0",
+ "ZXN0Lk1hcFdlbGxLbm93blR5cGVzLkVtcHR5RmllbGRFbnRyeRJSChBmaWVs",
+ "ZF9tYXNrX2ZpZWxkGAUgAygLMjgucHJvdG9idWZfdW5pdHRlc3QuTWFwV2Vs",
+ "bEtub3duVHlwZXMuRmllbGRNYXNrRmllbGRFbnRyeRJaChRzb3VyY2VfY29u",
+ "dGV4dF9maWVsZBgGIAMoCzI8LnByb3RvYnVmX3VuaXR0ZXN0Lk1hcFdlbGxL",
+ "bm93blR5cGVzLlNvdXJjZUNvbnRleHRGaWVsZEVudHJ5EksKDHN0cnVjdF9m",
+ "aWVsZBgHIAMoCzI1LnByb3RvYnVmX3VuaXR0ZXN0Lk1hcFdlbGxLbm93blR5",
+ "cGVzLlN0cnVjdEZpZWxkRW50cnkSUQoPdGltZXN0YW1wX2ZpZWxkGAggAygL",
+ "MjgucHJvdG9idWZfdW5pdHRlc3QuTWFwV2VsbEtub3duVHlwZXMuVGltZXN0",
+ "YW1wRmllbGRFbnRyeRJHCgp0eXBlX2ZpZWxkGAkgAygLMjMucHJvdG9idWZf",
+ "dW5pdHRlc3QuTWFwV2VsbEtub3duVHlwZXMuVHlwZUZpZWxkRW50cnkSSwoM",
+ "ZG91YmxlX2ZpZWxkGAogAygLMjUucHJvdG9idWZfdW5pdHRlc3QuTWFwV2Vs",
+ "bEtub3duVHlwZXMuRG91YmxlRmllbGRFbnRyeRJJCgtmbG9hdF9maWVsZBgL",
+ "IAMoCzI0LnByb3RvYnVmX3VuaXR0ZXN0Lk1hcFdlbGxLbm93blR5cGVzLkZs",
+ "b2F0RmllbGRFbnRyeRJJCgtpbnQ2NF9maWVsZBgMIAMoCzI0LnByb3RvYnVm",
+ "X3VuaXR0ZXN0Lk1hcFdlbGxLbm93blR5cGVzLkludDY0RmllbGRFbnRyeRJL",
+ "Cgx1aW50NjRfZmllbGQYDSADKAsyNS5wcm90b2J1Zl91bml0dGVzdC5NYXBX",
+ "ZWxsS25vd25UeXBlcy5VaW50NjRGaWVsZEVudHJ5EkkKC2ludDMyX2ZpZWxk",
+ "GA4gAygLMjQucHJvdG9idWZfdW5pdHRlc3QuTWFwV2VsbEtub3duVHlwZXMu",
+ "SW50MzJGaWVsZEVudHJ5EksKDHVpbnQzMl9maWVsZBgPIAMoCzI1LnByb3Rv",
+ "YnVmX3VuaXR0ZXN0Lk1hcFdlbGxLbm93blR5cGVzLlVpbnQzMkZpZWxkRW50",
+ "cnkSRwoKYm9vbF9maWVsZBgQIAMoCzIzLnByb3RvYnVmX3VuaXR0ZXN0Lk1h",
+ "cFdlbGxLbm93blR5cGVzLkJvb2xGaWVsZEVudHJ5EksKDHN0cmluZ19maWVs",
+ "ZBgRIAMoCzI1LnByb3RvYnVmX3VuaXR0ZXN0Lk1hcFdlbGxLbm93blR5cGVz",
+ "LlN0cmluZ0ZpZWxkRW50cnkSSQoLYnl0ZXNfZmllbGQYEiADKAsyNC5wcm90",
+ "b2J1Zl91bml0dGVzdC5NYXBXZWxsS25vd25UeXBlcy5CeXRlc0ZpZWxkRW50",
+ "cnkaRQoNQW55RmllbGRFbnRyeRILCgNrZXkYASABKAUSIwoFdmFsdWUYAiAB",
+ "KAsyFC5nb29nbGUucHJvdG9idWYuQW55OgI4ARpFCg1BcGlGaWVsZEVudHJ5",
+ "EgsKA2tleRgBIAEoBRIjCgV2YWx1ZRgCIAEoCzIULmdvb2dsZS5wcm90b2J1",
+ "Zi5BcGk6AjgBGk8KEkR1cmF0aW9uRmllbGRFbnRyeRILCgNrZXkYASABKAUS",
+ "KAoFdmFsdWUYAiABKAsyGS5nb29nbGUucHJvdG9idWYuRHVyYXRpb246AjgB",
+ "GkkKD0VtcHR5RmllbGRFbnRyeRILCgNrZXkYASABKAUSJQoFdmFsdWUYAiAB",
+ "KAsyFi5nb29nbGUucHJvdG9idWYuRW1wdHk6AjgBGlEKE0ZpZWxkTWFza0Zp",
+ "ZWxkRW50cnkSCwoDa2V5GAEgASgFEikKBXZhbHVlGAIgASgLMhouZ29vZ2xl",
+ "LnByb3RvYnVmLkZpZWxkTWFzazoCOAEaWQoXU291cmNlQ29udGV4dEZpZWxk",
+ "RW50cnkSCwoDa2V5GAEgASgFEi0KBXZhbHVlGAIgASgLMh4uZ29vZ2xlLnBy",
+ "b3RvYnVmLlNvdXJjZUNvbnRleHQ6AjgBGksKEFN0cnVjdEZpZWxkRW50cnkS",
+ "CwoDa2V5GAEgASgFEiYKBXZhbHVlGAIgASgLMhcuZ29vZ2xlLnByb3RvYnVm",
+ "LlN0cnVjdDoCOAEaUQoTVGltZXN0YW1wRmllbGRFbnRyeRILCgNrZXkYASAB",
+ "KAUSKQoFdmFsdWUYAiABKAsyGi5nb29nbGUucHJvdG9idWYuVGltZXN0YW1w",
+ "OgI4ARpHCg5UeXBlRmllbGRFbnRyeRILCgNrZXkYASABKAUSJAoFdmFsdWUY",
+ "AiABKAsyFS5nb29nbGUucHJvdG9idWYuVHlwZToCOAEaUAoQRG91YmxlRmll",
+ "bGRFbnRyeRILCgNrZXkYASABKAUSKwoFdmFsdWUYAiABKAsyHC5nb29nbGUu",
+ "cHJvdG9idWYuRG91YmxlVmFsdWU6AjgBGk4KD0Zsb2F0RmllbGRFbnRyeRIL",
+ "CgNrZXkYASABKAUSKgoFdmFsdWUYAiABKAsyGy5nb29nbGUucHJvdG9idWYu",
+ "RmxvYXRWYWx1ZToCOAEaTgoPSW50NjRGaWVsZEVudHJ5EgsKA2tleRgBIAEo",
+ "BRIqCgV2YWx1ZRgCIAEoCzIbLmdvb2dsZS5wcm90b2J1Zi5JbnQ2NFZhbHVl",
+ "OgI4ARpQChBVaW50NjRGaWVsZEVudHJ5EgsKA2tleRgBIAEoBRIrCgV2YWx1",
+ "ZRgCIAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5VSW50NjRWYWx1ZToCOAEaTgoP",
+ "SW50MzJGaWVsZEVudHJ5EgsKA2tleRgBIAEoBRIqCgV2YWx1ZRgCIAEoCzIb",
+ "Lmdvb2dsZS5wcm90b2J1Zi5JbnQzMlZhbHVlOgI4ARpQChBVaW50MzJGaWVs",
+ "ZEVudHJ5EgsKA2tleRgBIAEoBRIrCgV2YWx1ZRgCIAEoCzIcLmdvb2dsZS5w",
+ "cm90b2J1Zi5VSW50MzJWYWx1ZToCOAEaTAoOQm9vbEZpZWxkRW50cnkSCwoD",
+ "a2V5GAEgASgFEikKBXZhbHVlGAIgASgLMhouZ29vZ2xlLnByb3RvYnVmLkJv",
+ "b2xWYWx1ZToCOAEaUAoQU3RyaW5nRmllbGRFbnRyeRILCgNrZXkYASABKAUS",
+ "KwoFdmFsdWUYAiABKAsyHC5nb29nbGUucHJvdG9idWYuU3RyaW5nVmFsdWU6",
+ "AjgBGk4KD0J5dGVzRmllbGRFbnRyeRILCgNrZXkYASABKAUSKgoFdmFsdWUY",
+ "AiABKAsyGy5nb29nbGUucHJvdG9idWYuQnl0ZXNWYWx1ZToCOAFCOQoYY29t",
+ "Lmdvb2dsZS5wcm90b2J1Zi50ZXN0UAGqAhpHb29nbGUuUHJvdG9idWYuVGVz",
+ "dFByb3Rvc2IGcHJvdG8z"));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.AnyReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.ApiReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.DurationReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.EmptyReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.FieldMaskReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.SourceContextReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.StructReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.TimestampReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.TypeReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor, },
+ new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.TestWellKnownTypes), global::Google.Protobuf.TestProtos.TestWellKnownTypes.Parser, new[]{ "AnyField", "ApiField", "DurationField", "EmptyField", "FieldMaskField", "SourceContextField", "StructField", "TimestampField", "TypeField", "DoubleField", "FloatField", "Int64Field", "Uint64Field", "Int32Field", "Uint32Field", "BoolField", "StringField", "BytesField", "ValueField" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.RepeatedWellKnownTypes), global::Google.Protobuf.TestProtos.RepeatedWellKnownTypes.Parser, new[]{ "AnyField", "ApiField", "DurationField", "EmptyField", "FieldMaskField", "SourceContextField", "StructField", "TimestampField", "TypeField", "DoubleField", "FloatField", "Int64Field", "Uint64Field", "Int32Field", "Uint32Field", "BoolField", "StringField", "BytesField" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.OneofWellKnownTypes), global::Google.Protobuf.TestProtos.OneofWellKnownTypes.Parser, new[]{ "AnyField", "ApiField", "DurationField", "EmptyField", "FieldMaskField", "SourceContextField", "StructField", "TimestampField", "TypeField", "DoubleField", "FloatField", "Int64Field", "Uint64Field", "Int32Field", "Uint32Field", "BoolField", "StringField", "BytesField" }, new[]{ "OneofField" }, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.TestProtos.MapWellKnownTypes), global::Google.Protobuf.TestProtos.MapWellKnownTypes.Parser, new[]{ "AnyField", "ApiField", "DurationField", "EmptyField", "FieldMaskField", "SourceContextField", "StructField", "TimestampField", "TypeField", "DoubleField", "FloatField", "Int64Field", "Uint64Field", "Int32Field", "Uint32Field", "BoolField", "StringField", "BytesField" }, null, null, new pbr::GeneratedClrTypeInfo[] { null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, })
+ }));
+ }
+ #endregion
+
+ }
+ #region Messages
+ /// <summary>
+ /// Test that we can include all well-known types.
+ /// Each wrapper type is included separately, as languages
+ /// map handle different wrappers in different ways.
+ /// </summary>
+ public sealed partial class TestWellKnownTypes : pb::IMessage<TestWellKnownTypes> {
+ private static readonly pb::MessageParser<TestWellKnownTypes> _parser = new pb::MessageParser<TestWellKnownTypes>(() => new TestWellKnownTypes());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<TestWellKnownTypes> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestWellKnownTypesReflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestWellKnownTypes() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestWellKnownTypes(TestWellKnownTypes other) : this() {
+ AnyField = other.anyField_ != null ? other.AnyField.Clone() : null;
+ ApiField = other.apiField_ != null ? other.ApiField.Clone() : null;
+ DurationField = other.durationField_ != null ? other.DurationField.Clone() : null;
+ EmptyField = other.emptyField_ != null ? other.EmptyField.Clone() : null;
+ FieldMaskField = other.fieldMaskField_ != null ? other.FieldMaskField.Clone() : null;
+ SourceContextField = other.sourceContextField_ != null ? other.SourceContextField.Clone() : null;
+ StructField = other.structField_ != null ? other.StructField.Clone() : null;
+ TimestampField = other.timestampField_ != null ? other.TimestampField.Clone() : null;
+ TypeField = other.typeField_ != null ? other.TypeField.Clone() : null;
+ DoubleField = other.DoubleField;
+ FloatField = other.FloatField;
+ Int64Field = other.Int64Field;
+ Uint64Field = other.Uint64Field;
+ Int32Field = other.Int32Field;
+ Uint32Field = other.Uint32Field;
+ BoolField = other.BoolField;
+ StringField = other.StringField;
+ BytesField = other.BytesField;
+ ValueField = other.valueField_ != null ? other.ValueField.Clone() : null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public TestWellKnownTypes Clone() {
+ return new TestWellKnownTypes(this);
+ }
+
+ /// <summary>Field number for the "any_field" field.</summary>
+ public const int AnyFieldFieldNumber = 1;
+ private global::Google.Protobuf.WellKnownTypes.Any anyField_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Any AnyField {
+ get { return anyField_; }
+ set {
+ anyField_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "api_field" field.</summary>
+ public const int ApiFieldFieldNumber = 2;
+ private global::Google.Protobuf.WellKnownTypes.Api apiField_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Api ApiField {
+ get { return apiField_; }
+ set {
+ apiField_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "duration_field" field.</summary>
+ public const int DurationFieldFieldNumber = 3;
+ private global::Google.Protobuf.WellKnownTypes.Duration durationField_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Duration DurationField {
+ get { return durationField_; }
+ set {
+ durationField_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "empty_field" field.</summary>
+ public const int EmptyFieldFieldNumber = 4;
+ private global::Google.Protobuf.WellKnownTypes.Empty emptyField_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Empty EmptyField {
+ get { return emptyField_; }
+ set {
+ emptyField_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "field_mask_field" field.</summary>
+ public const int FieldMaskFieldFieldNumber = 5;
+ private global::Google.Protobuf.WellKnownTypes.FieldMask fieldMaskField_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.FieldMask FieldMaskField {
+ get { return fieldMaskField_; }
+ set {
+ fieldMaskField_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "source_context_field" field.</summary>
+ public const int SourceContextFieldFieldNumber = 6;
+ private global::Google.Protobuf.WellKnownTypes.SourceContext sourceContextField_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.SourceContext SourceContextField {
+ get { return sourceContextField_; }
+ set {
+ sourceContextField_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "struct_field" field.</summary>
+ public const int StructFieldFieldNumber = 7;
+ private global::Google.Protobuf.WellKnownTypes.Struct structField_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Struct StructField {
+ get { return structField_; }
+ set {
+ structField_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "timestamp_field" field.</summary>
+ public const int TimestampFieldFieldNumber = 8;
+ private global::Google.Protobuf.WellKnownTypes.Timestamp timestampField_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Timestamp TimestampField {
+ get { return timestampField_; }
+ set {
+ timestampField_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "type_field" field.</summary>
+ public const int TypeFieldFieldNumber = 9;
+ private global::Google.Protobuf.WellKnownTypes.Type typeField_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Type TypeField {
+ get { return typeField_; }
+ set {
+ typeField_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "double_field" field.</summary>
+ public const int DoubleFieldFieldNumber = 10;
+ private static readonly pb::FieldCodec<double?> _single_doubleField_codec = pb::FieldCodec.ForStructWrapper<double>(82);
+ private double? doubleField_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public double? DoubleField {
+ get { return doubleField_; }
+ set {
+ doubleField_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "float_field" field.</summary>
+ public const int FloatFieldFieldNumber = 11;
+ private static readonly pb::FieldCodec<float?> _single_floatField_codec = pb::FieldCodec.ForStructWrapper<float>(90);
+ private float? floatField_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public float? FloatField {
+ get { return floatField_; }
+ set {
+ floatField_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "int64_field" field.</summary>
+ public const int Int64FieldFieldNumber = 12;
+ private static readonly pb::FieldCodec<long?> _single_int64Field_codec = pb::FieldCodec.ForStructWrapper<long>(98);
+ private long? int64Field_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public long? Int64Field {
+ get { return int64Field_; }
+ set {
+ int64Field_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "uint64_field" field.</summary>
+ public const int Uint64FieldFieldNumber = 13;
+ private static readonly pb::FieldCodec<ulong?> _single_uint64Field_codec = pb::FieldCodec.ForStructWrapper<ulong>(106);
+ private ulong? uint64Field_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ulong? Uint64Field {
+ get { return uint64Field_; }
+ set {
+ uint64Field_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "int32_field" field.</summary>
+ public const int Int32FieldFieldNumber = 14;
+ private static readonly pb::FieldCodec<int?> _single_int32Field_codec = pb::FieldCodec.ForStructWrapper<int>(114);
+ private int? int32Field_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int? Int32Field {
+ get { return int32Field_; }
+ set {
+ int32Field_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "uint32_field" field.</summary>
+ public const int Uint32FieldFieldNumber = 15;
+ private static readonly pb::FieldCodec<uint?> _single_uint32Field_codec = pb::FieldCodec.ForStructWrapper<uint>(122);
+ private uint? uint32Field_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public uint? Uint32Field {
+ get { return uint32Field_; }
+ set {
+ uint32Field_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "bool_field" field.</summary>
+ public const int BoolFieldFieldNumber = 16;
+ private static readonly pb::FieldCodec<bool?> _single_boolField_codec = pb::FieldCodec.ForStructWrapper<bool>(130);
+ private bool? boolField_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool? BoolField {
+ get { return boolField_; }
+ set {
+ boolField_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "string_field" field.</summary>
+ public const int StringFieldFieldNumber = 17;
+ private static readonly pb::FieldCodec<string> _single_stringField_codec = pb::FieldCodec.ForClassWrapper<string>(138);
+ private string stringField_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string StringField {
+ get { return stringField_; }
+ set {
+ stringField_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "bytes_field" field.</summary>
+ public const int BytesFieldFieldNumber = 18;
+ private static readonly pb::FieldCodec<pb::ByteString> _single_bytesField_codec = pb::FieldCodec.ForClassWrapper<pb::ByteString>(146);
+ private pb::ByteString bytesField_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pb::ByteString BytesField {
+ get { return bytesField_; }
+ set {
+ bytesField_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "value_field" field.</summary>
+ public const int ValueFieldFieldNumber = 19;
+ private global::Google.Protobuf.WellKnownTypes.Value valueField_;
+ /// <summary>
+ /// Part of struct, but useful to be able to test separately
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Value ValueField {
+ get { return valueField_; }
+ set {
+ valueField_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestWellKnownTypes);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestWellKnownTypes other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (!object.Equals(AnyField, other.AnyField)) return false;
+ if (!object.Equals(ApiField, other.ApiField)) return false;
+ if (!object.Equals(DurationField, other.DurationField)) return false;
+ if (!object.Equals(EmptyField, other.EmptyField)) return false;
+ if (!object.Equals(FieldMaskField, other.FieldMaskField)) return false;
+ if (!object.Equals(SourceContextField, other.SourceContextField)) return false;
+ if (!object.Equals(StructField, other.StructField)) return false;
+ if (!object.Equals(TimestampField, other.TimestampField)) return false;
+ if (!object.Equals(TypeField, other.TypeField)) return false;
+ if (DoubleField != other.DoubleField) return false;
+ if (FloatField != other.FloatField) return false;
+ if (Int64Field != other.Int64Field) return false;
+ if (Uint64Field != other.Uint64Field) return false;
+ if (Int32Field != other.Int32Field) return false;
+ if (Uint32Field != other.Uint32Field) return false;
+ if (BoolField != other.BoolField) return false;
+ if (StringField != other.StringField) return false;
+ if (BytesField != other.BytesField) return false;
+ if (!object.Equals(ValueField, other.ValueField)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (anyField_ != null) hash ^= AnyField.GetHashCode();
+ if (apiField_ != null) hash ^= ApiField.GetHashCode();
+ if (durationField_ != null) hash ^= DurationField.GetHashCode();
+ if (emptyField_ != null) hash ^= EmptyField.GetHashCode();
+ if (fieldMaskField_ != null) hash ^= FieldMaskField.GetHashCode();
+ if (sourceContextField_ != null) hash ^= SourceContextField.GetHashCode();
+ if (structField_ != null) hash ^= StructField.GetHashCode();
+ if (timestampField_ != null) hash ^= TimestampField.GetHashCode();
+ if (typeField_ != null) hash ^= TypeField.GetHashCode();
+ if (doubleField_ != null) hash ^= DoubleField.GetHashCode();
+ if (floatField_ != null) hash ^= FloatField.GetHashCode();
+ if (int64Field_ != null) hash ^= Int64Field.GetHashCode();
+ if (uint64Field_ != null) hash ^= Uint64Field.GetHashCode();
+ if (int32Field_ != null) hash ^= Int32Field.GetHashCode();
+ if (uint32Field_ != null) hash ^= Uint32Field.GetHashCode();
+ if (boolField_ != null) hash ^= BoolField.GetHashCode();
+ if (stringField_ != null) hash ^= StringField.GetHashCode();
+ if (bytesField_ != null) hash ^= BytesField.GetHashCode();
+ if (valueField_ != null) hash ^= ValueField.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (anyField_ != null) {
+ output.WriteRawTag(10);
+ output.WriteMessage(AnyField);
+ }
+ if (apiField_ != null) {
+ output.WriteRawTag(18);
+ output.WriteMessage(ApiField);
+ }
+ if (durationField_ != null) {
+ output.WriteRawTag(26);
+ output.WriteMessage(DurationField);
+ }
+ if (emptyField_ != null) {
+ output.WriteRawTag(34);
+ output.WriteMessage(EmptyField);
+ }
+ if (fieldMaskField_ != null) {
+ output.WriteRawTag(42);
+ output.WriteMessage(FieldMaskField);
+ }
+ if (sourceContextField_ != null) {
+ output.WriteRawTag(50);
+ output.WriteMessage(SourceContextField);
+ }
+ if (structField_ != null) {
+ output.WriteRawTag(58);
+ output.WriteMessage(StructField);
+ }
+ if (timestampField_ != null) {
+ output.WriteRawTag(66);
+ output.WriteMessage(TimestampField);
+ }
+ if (typeField_ != null) {
+ output.WriteRawTag(74);
+ output.WriteMessage(TypeField);
+ }
+ if (doubleField_ != null) {
+ _single_doubleField_codec.WriteTagAndValue(output, DoubleField);
+ }
+ if (floatField_ != null) {
+ _single_floatField_codec.WriteTagAndValue(output, FloatField);
+ }
+ if (int64Field_ != null) {
+ _single_int64Field_codec.WriteTagAndValue(output, Int64Field);
+ }
+ if (uint64Field_ != null) {
+ _single_uint64Field_codec.WriteTagAndValue(output, Uint64Field);
+ }
+ if (int32Field_ != null) {
+ _single_int32Field_codec.WriteTagAndValue(output, Int32Field);
+ }
+ if (uint32Field_ != null) {
+ _single_uint32Field_codec.WriteTagAndValue(output, Uint32Field);
+ }
+ if (boolField_ != null) {
+ _single_boolField_codec.WriteTagAndValue(output, BoolField);
+ }
+ if (stringField_ != null) {
+ _single_stringField_codec.WriteTagAndValue(output, StringField);
+ }
+ if (bytesField_ != null) {
+ _single_bytesField_codec.WriteTagAndValue(output, BytesField);
+ }
+ if (valueField_ != null) {
+ output.WriteRawTag(154, 1);
+ output.WriteMessage(ValueField);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (anyField_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(AnyField);
+ }
+ if (apiField_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(ApiField);
+ }
+ if (durationField_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(DurationField);
+ }
+ if (emptyField_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(EmptyField);
+ }
+ if (fieldMaskField_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(FieldMaskField);
+ }
+ if (sourceContextField_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(SourceContextField);
+ }
+ if (structField_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(StructField);
+ }
+ if (timestampField_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(TimestampField);
+ }
+ if (typeField_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(TypeField);
+ }
+ if (doubleField_ != null) {
+ size += _single_doubleField_codec.CalculateSizeWithTag(DoubleField);
+ }
+ if (floatField_ != null) {
+ size += _single_floatField_codec.CalculateSizeWithTag(FloatField);
+ }
+ if (int64Field_ != null) {
+ size += _single_int64Field_codec.CalculateSizeWithTag(Int64Field);
+ }
+ if (uint64Field_ != null) {
+ size += _single_uint64Field_codec.CalculateSizeWithTag(Uint64Field);
+ }
+ if (int32Field_ != null) {
+ size += _single_int32Field_codec.CalculateSizeWithTag(Int32Field);
+ }
+ if (uint32Field_ != null) {
+ size += _single_uint32Field_codec.CalculateSizeWithTag(Uint32Field);
+ }
+ if (boolField_ != null) {
+ size += _single_boolField_codec.CalculateSizeWithTag(BoolField);
+ }
+ if (stringField_ != null) {
+ size += _single_stringField_codec.CalculateSizeWithTag(StringField);
+ }
+ if (bytesField_ != null) {
+ size += _single_bytesField_codec.CalculateSizeWithTag(BytesField);
+ }
+ if (valueField_ != null) {
+ size += 2 + pb::CodedOutputStream.ComputeMessageSize(ValueField);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(TestWellKnownTypes other) {
+ if (other == null) {
+ return;
+ }
+ if (other.anyField_ != null) {
+ if (anyField_ == null) {
+ anyField_ = new global::Google.Protobuf.WellKnownTypes.Any();
+ }
+ AnyField.MergeFrom(other.AnyField);
+ }
+ if (other.apiField_ != null) {
+ if (apiField_ == null) {
+ apiField_ = new global::Google.Protobuf.WellKnownTypes.Api();
+ }
+ ApiField.MergeFrom(other.ApiField);
+ }
+ if (other.durationField_ != null) {
+ if (durationField_ == null) {
+ durationField_ = new global::Google.Protobuf.WellKnownTypes.Duration();
+ }
+ DurationField.MergeFrom(other.DurationField);
+ }
+ if (other.emptyField_ != null) {
+ if (emptyField_ == null) {
+ emptyField_ = new global::Google.Protobuf.WellKnownTypes.Empty();
+ }
+ EmptyField.MergeFrom(other.EmptyField);
+ }
+ if (other.fieldMaskField_ != null) {
+ if (fieldMaskField_ == null) {
+ fieldMaskField_ = new global::Google.Protobuf.WellKnownTypes.FieldMask();
+ }
+ FieldMaskField.MergeFrom(other.FieldMaskField);
+ }
+ if (other.sourceContextField_ != null) {
+ if (sourceContextField_ == null) {
+ sourceContextField_ = new global::Google.Protobuf.WellKnownTypes.SourceContext();
+ }
+ SourceContextField.MergeFrom(other.SourceContextField);
+ }
+ if (other.structField_ != null) {
+ if (structField_ == null) {
+ structField_ = new global::Google.Protobuf.WellKnownTypes.Struct();
+ }
+ StructField.MergeFrom(other.StructField);
+ }
+ if (other.timestampField_ != null) {
+ if (timestampField_ == null) {
+ timestampField_ = new global::Google.Protobuf.WellKnownTypes.Timestamp();
+ }
+ TimestampField.MergeFrom(other.TimestampField);
+ }
+ if (other.typeField_ != null) {
+ if (typeField_ == null) {
+ typeField_ = new global::Google.Protobuf.WellKnownTypes.Type();
+ }
+ TypeField.MergeFrom(other.TypeField);
+ }
+ if (other.doubleField_ != null) {
+ if (doubleField_ == null || other.DoubleField != 0D) {
+ DoubleField = other.DoubleField;
+ }
+ }
+ if (other.floatField_ != null) {
+ if (floatField_ == null || other.FloatField != 0F) {
+ FloatField = other.FloatField;
+ }
+ }
+ if (other.int64Field_ != null) {
+ if (int64Field_ == null || other.Int64Field != 0L) {
+ Int64Field = other.Int64Field;
+ }
+ }
+ if (other.uint64Field_ != null) {
+ if (uint64Field_ == null || other.Uint64Field != 0UL) {
+ Uint64Field = other.Uint64Field;
+ }
+ }
+ if (other.int32Field_ != null) {
+ if (int32Field_ == null || other.Int32Field != 0) {
+ Int32Field = other.Int32Field;
+ }
+ }
+ if (other.uint32Field_ != null) {
+ if (uint32Field_ == null || other.Uint32Field != 0) {
+ Uint32Field = other.Uint32Field;
+ }
+ }
+ if (other.boolField_ != null) {
+ if (boolField_ == null || other.BoolField != false) {
+ BoolField = other.BoolField;
+ }
+ }
+ if (other.stringField_ != null) {
+ if (stringField_ == null || other.StringField != "") {
+ StringField = other.StringField;
+ }
+ }
+ if (other.bytesField_ != null) {
+ if (bytesField_ == null || other.BytesField != pb::ByteString.Empty) {
+ BytesField = other.BytesField;
+ }
+ }
+ if (other.valueField_ != null) {
+ if (valueField_ == null) {
+ valueField_ = new global::Google.Protobuf.WellKnownTypes.Value();
+ }
+ ValueField.MergeFrom(other.ValueField);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ if (anyField_ == null) {
+ anyField_ = new global::Google.Protobuf.WellKnownTypes.Any();
+ }
+ input.ReadMessage(anyField_);
+ break;
+ }
+ case 18: {
+ if (apiField_ == null) {
+ apiField_ = new global::Google.Protobuf.WellKnownTypes.Api();
+ }
+ input.ReadMessage(apiField_);
+ break;
+ }
+ case 26: {
+ if (durationField_ == null) {
+ durationField_ = new global::Google.Protobuf.WellKnownTypes.Duration();
+ }
+ input.ReadMessage(durationField_);
+ break;
+ }
+ case 34: {
+ if (emptyField_ == null) {
+ emptyField_ = new global::Google.Protobuf.WellKnownTypes.Empty();
+ }
+ input.ReadMessage(emptyField_);
+ break;
+ }
+ case 42: {
+ if (fieldMaskField_ == null) {
+ fieldMaskField_ = new global::Google.Protobuf.WellKnownTypes.FieldMask();
+ }
+ input.ReadMessage(fieldMaskField_);
+ break;
+ }
+ case 50: {
+ if (sourceContextField_ == null) {
+ sourceContextField_ = new global::Google.Protobuf.WellKnownTypes.SourceContext();
+ }
+ input.ReadMessage(sourceContextField_);
+ break;
+ }
+ case 58: {
+ if (structField_ == null) {
+ structField_ = new global::Google.Protobuf.WellKnownTypes.Struct();
+ }
+ input.ReadMessage(structField_);
+ break;
+ }
+ case 66: {
+ if (timestampField_ == null) {
+ timestampField_ = new global::Google.Protobuf.WellKnownTypes.Timestamp();
+ }
+ input.ReadMessage(timestampField_);
+ break;
+ }
+ case 74: {
+ if (typeField_ == null) {
+ typeField_ = new global::Google.Protobuf.WellKnownTypes.Type();
+ }
+ input.ReadMessage(typeField_);
+ break;
+ }
+ case 82: {
+ double? value = _single_doubleField_codec.Read(input);
+ if (doubleField_ == null || value != 0D) {
+ DoubleField = value;
+ }
+ break;
+ }
+ case 90: {
+ float? value = _single_floatField_codec.Read(input);
+ if (floatField_ == null || value != 0F) {
+ FloatField = value;
+ }
+ break;
+ }
+ case 98: {
+ long? value = _single_int64Field_codec.Read(input);
+ if (int64Field_ == null || value != 0L) {
+ Int64Field = value;
+ }
+ break;
+ }
+ case 106: {
+ ulong? value = _single_uint64Field_codec.Read(input);
+ if (uint64Field_ == null || value != 0UL) {
+ Uint64Field = value;
+ }
+ break;
+ }
+ case 114: {
+ int? value = _single_int32Field_codec.Read(input);
+ if (int32Field_ == null || value != 0) {
+ Int32Field = value;
+ }
+ break;
+ }
+ case 122: {
+ uint? value = _single_uint32Field_codec.Read(input);
+ if (uint32Field_ == null || value != 0) {
+ Uint32Field = value;
+ }
+ break;
+ }
+ case 130: {
+ bool? value = _single_boolField_codec.Read(input);
+ if (boolField_ == null || value != false) {
+ BoolField = value;
+ }
+ break;
+ }
+ case 138: {
+ string value = _single_stringField_codec.Read(input);
+ if (stringField_ == null || value != "") {
+ StringField = value;
+ }
+ break;
+ }
+ case 146: {
+ pb::ByteString value = _single_bytesField_codec.Read(input);
+ if (bytesField_ == null || value != pb::ByteString.Empty) {
+ BytesField = value;
+ }
+ break;
+ }
+ case 154: {
+ if (valueField_ == null) {
+ valueField_ = new global::Google.Protobuf.WellKnownTypes.Value();
+ }
+ input.ReadMessage(valueField_);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// A repeated field for each well-known type.
+ /// </summary>
+ public sealed partial class RepeatedWellKnownTypes : pb::IMessage<RepeatedWellKnownTypes> {
+ private static readonly pb::MessageParser<RepeatedWellKnownTypes> _parser = new pb::MessageParser<RepeatedWellKnownTypes>(() => new RepeatedWellKnownTypes());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<RepeatedWellKnownTypes> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestWellKnownTypesReflection.Descriptor.MessageTypes[1]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public RepeatedWellKnownTypes() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public RepeatedWellKnownTypes(RepeatedWellKnownTypes other) : this() {
+ anyField_ = other.anyField_.Clone();
+ apiField_ = other.apiField_.Clone();
+ durationField_ = other.durationField_.Clone();
+ emptyField_ = other.emptyField_.Clone();
+ fieldMaskField_ = other.fieldMaskField_.Clone();
+ sourceContextField_ = other.sourceContextField_.Clone();
+ structField_ = other.structField_.Clone();
+ timestampField_ = other.timestampField_.Clone();
+ typeField_ = other.typeField_.Clone();
+ doubleField_ = other.doubleField_.Clone();
+ floatField_ = other.floatField_.Clone();
+ int64Field_ = other.int64Field_.Clone();
+ uint64Field_ = other.uint64Field_.Clone();
+ int32Field_ = other.int32Field_.Clone();
+ uint32Field_ = other.uint32Field_.Clone();
+ boolField_ = other.boolField_.Clone();
+ stringField_ = other.stringField_.Clone();
+ bytesField_ = other.bytesField_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public RepeatedWellKnownTypes Clone() {
+ return new RepeatedWellKnownTypes(this);
+ }
+
+ /// <summary>Field number for the "any_field" field.</summary>
+ public const int AnyFieldFieldNumber = 1;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Any> _repeated_anyField_codec
+ = pb::FieldCodec.ForMessage(10, global::Google.Protobuf.WellKnownTypes.Any.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Any> anyField_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Any>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Any> AnyField {
+ get { return anyField_; }
+ }
+
+ /// <summary>Field number for the "api_field" field.</summary>
+ public const int ApiFieldFieldNumber = 2;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Api> _repeated_apiField_codec
+ = pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Api.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Api> apiField_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Api>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Api> ApiField {
+ get { return apiField_; }
+ }
+
+ /// <summary>Field number for the "duration_field" field.</summary>
+ public const int DurationFieldFieldNumber = 3;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Duration> _repeated_durationField_codec
+ = pb::FieldCodec.ForMessage(26, global::Google.Protobuf.WellKnownTypes.Duration.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Duration> durationField_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Duration>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Duration> DurationField {
+ get { return durationField_; }
+ }
+
+ /// <summary>Field number for the "empty_field" field.</summary>
+ public const int EmptyFieldFieldNumber = 4;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Empty> _repeated_emptyField_codec
+ = pb::FieldCodec.ForMessage(34, global::Google.Protobuf.WellKnownTypes.Empty.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Empty> emptyField_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Empty>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Empty> EmptyField {
+ get { return emptyField_; }
+ }
+
+ /// <summary>Field number for the "field_mask_field" field.</summary>
+ public const int FieldMaskFieldFieldNumber = 5;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.FieldMask> _repeated_fieldMaskField_codec
+ = pb::FieldCodec.ForMessage(42, global::Google.Protobuf.WellKnownTypes.FieldMask.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.FieldMask> fieldMaskField_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.FieldMask>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.FieldMask> FieldMaskField {
+ get { return fieldMaskField_; }
+ }
+
+ /// <summary>Field number for the "source_context_field" field.</summary>
+ public const int SourceContextFieldFieldNumber = 6;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.SourceContext> _repeated_sourceContextField_codec
+ = pb::FieldCodec.ForMessage(50, global::Google.Protobuf.WellKnownTypes.SourceContext.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.SourceContext> sourceContextField_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.SourceContext>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.SourceContext> SourceContextField {
+ get { return sourceContextField_; }
+ }
+
+ /// <summary>Field number for the "struct_field" field.</summary>
+ public const int StructFieldFieldNumber = 7;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Struct> _repeated_structField_codec
+ = pb::FieldCodec.ForMessage(58, global::Google.Protobuf.WellKnownTypes.Struct.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Struct> structField_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Struct>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Struct> StructField {
+ get { return structField_; }
+ }
+
+ /// <summary>Field number for the "timestamp_field" field.</summary>
+ public const int TimestampFieldFieldNumber = 8;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Timestamp> _repeated_timestampField_codec
+ = pb::FieldCodec.ForMessage(66, global::Google.Protobuf.WellKnownTypes.Timestamp.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Timestamp> timestampField_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Timestamp>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Timestamp> TimestampField {
+ get { return timestampField_; }
+ }
+
+ /// <summary>Field number for the "type_field" field.</summary>
+ public const int TypeFieldFieldNumber = 9;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Type> _repeated_typeField_codec
+ = pb::FieldCodec.ForMessage(74, global::Google.Protobuf.WellKnownTypes.Type.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Type> typeField_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Type>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Type> TypeField {
+ get { return typeField_; }
+ }
+
+ /// <summary>Field number for the "double_field" field.</summary>
+ public const int DoubleFieldFieldNumber = 10;
+ private static readonly pb::FieldCodec<double?> _repeated_doubleField_codec
+ = pb::FieldCodec.ForStructWrapper<double>(82);
+ private readonly pbc::RepeatedField<double?> doubleField_ = new pbc::RepeatedField<double?>();
+ /// <summary>
+ /// These don't actually make a lot of sense, but they're not prohibited...
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<double?> DoubleField {
+ get { return doubleField_; }
+ }
+
+ /// <summary>Field number for the "float_field" field.</summary>
+ public const int FloatFieldFieldNumber = 11;
+ private static readonly pb::FieldCodec<float?> _repeated_floatField_codec
+ = pb::FieldCodec.ForStructWrapper<float>(90);
+ private readonly pbc::RepeatedField<float?> floatField_ = new pbc::RepeatedField<float?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<float?> FloatField {
+ get { return floatField_; }
+ }
+
+ /// <summary>Field number for the "int64_field" field.</summary>
+ public const int Int64FieldFieldNumber = 12;
+ private static readonly pb::FieldCodec<long?> _repeated_int64Field_codec
+ = pb::FieldCodec.ForStructWrapper<long>(98);
+ private readonly pbc::RepeatedField<long?> int64Field_ = new pbc::RepeatedField<long?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<long?> Int64Field {
+ get { return int64Field_; }
+ }
+
+ /// <summary>Field number for the "uint64_field" field.</summary>
+ public const int Uint64FieldFieldNumber = 13;
+ private static readonly pb::FieldCodec<ulong?> _repeated_uint64Field_codec
+ = pb::FieldCodec.ForStructWrapper<ulong>(106);
+ private readonly pbc::RepeatedField<ulong?> uint64Field_ = new pbc::RepeatedField<ulong?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<ulong?> Uint64Field {
+ get { return uint64Field_; }
+ }
+
+ /// <summary>Field number for the "int32_field" field.</summary>
+ public const int Int32FieldFieldNumber = 14;
+ private static readonly pb::FieldCodec<int?> _repeated_int32Field_codec
+ = pb::FieldCodec.ForStructWrapper<int>(114);
+ private readonly pbc::RepeatedField<int?> int32Field_ = new pbc::RepeatedField<int?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int?> Int32Field {
+ get { return int32Field_; }
+ }
+
+ /// <summary>Field number for the "uint32_field" field.</summary>
+ public const int Uint32FieldFieldNumber = 15;
+ private static readonly pb::FieldCodec<uint?> _repeated_uint32Field_codec
+ = pb::FieldCodec.ForStructWrapper<uint>(122);
+ private readonly pbc::RepeatedField<uint?> uint32Field_ = new pbc::RepeatedField<uint?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<uint?> Uint32Field {
+ get { return uint32Field_; }
+ }
+
+ /// <summary>Field number for the "bool_field" field.</summary>
+ public const int BoolFieldFieldNumber = 16;
+ private static readonly pb::FieldCodec<bool?> _repeated_boolField_codec
+ = pb::FieldCodec.ForStructWrapper<bool>(130);
+ private readonly pbc::RepeatedField<bool?> boolField_ = new pbc::RepeatedField<bool?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<bool?> BoolField {
+ get { return boolField_; }
+ }
+
+ /// <summary>Field number for the "string_field" field.</summary>
+ public const int StringFieldFieldNumber = 17;
+ private static readonly pb::FieldCodec<string> _repeated_stringField_codec
+ = pb::FieldCodec.ForClassWrapper<string>(138);
+ private readonly pbc::RepeatedField<string> stringField_ = new pbc::RepeatedField<string>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<string> StringField {
+ get { return stringField_; }
+ }
+
+ /// <summary>Field number for the "bytes_field" field.</summary>
+ public const int BytesFieldFieldNumber = 18;
+ private static readonly pb::FieldCodec<pb::ByteString> _repeated_bytesField_codec
+ = pb::FieldCodec.ForClassWrapper<pb::ByteString>(146);
+ private readonly pbc::RepeatedField<pb::ByteString> bytesField_ = new pbc::RepeatedField<pb::ByteString>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<pb::ByteString> BytesField {
+ get { return bytesField_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as RepeatedWellKnownTypes);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(RepeatedWellKnownTypes other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if(!anyField_.Equals(other.anyField_)) return false;
+ if(!apiField_.Equals(other.apiField_)) return false;
+ if(!durationField_.Equals(other.durationField_)) return false;
+ if(!emptyField_.Equals(other.emptyField_)) return false;
+ if(!fieldMaskField_.Equals(other.fieldMaskField_)) return false;
+ if(!sourceContextField_.Equals(other.sourceContextField_)) return false;
+ if(!structField_.Equals(other.structField_)) return false;
+ if(!timestampField_.Equals(other.timestampField_)) return false;
+ if(!typeField_.Equals(other.typeField_)) return false;
+ if(!doubleField_.Equals(other.doubleField_)) return false;
+ if(!floatField_.Equals(other.floatField_)) return false;
+ if(!int64Field_.Equals(other.int64Field_)) return false;
+ if(!uint64Field_.Equals(other.uint64Field_)) return false;
+ if(!int32Field_.Equals(other.int32Field_)) return false;
+ if(!uint32Field_.Equals(other.uint32Field_)) return false;
+ if(!boolField_.Equals(other.boolField_)) return false;
+ if(!stringField_.Equals(other.stringField_)) return false;
+ if(!bytesField_.Equals(other.bytesField_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= anyField_.GetHashCode();
+ hash ^= apiField_.GetHashCode();
+ hash ^= durationField_.GetHashCode();
+ hash ^= emptyField_.GetHashCode();
+ hash ^= fieldMaskField_.GetHashCode();
+ hash ^= sourceContextField_.GetHashCode();
+ hash ^= structField_.GetHashCode();
+ hash ^= timestampField_.GetHashCode();
+ hash ^= typeField_.GetHashCode();
+ hash ^= doubleField_.GetHashCode();
+ hash ^= floatField_.GetHashCode();
+ hash ^= int64Field_.GetHashCode();
+ hash ^= uint64Field_.GetHashCode();
+ hash ^= int32Field_.GetHashCode();
+ hash ^= uint32Field_.GetHashCode();
+ hash ^= boolField_.GetHashCode();
+ hash ^= stringField_.GetHashCode();
+ hash ^= bytesField_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ anyField_.WriteTo(output, _repeated_anyField_codec);
+ apiField_.WriteTo(output, _repeated_apiField_codec);
+ durationField_.WriteTo(output, _repeated_durationField_codec);
+ emptyField_.WriteTo(output, _repeated_emptyField_codec);
+ fieldMaskField_.WriteTo(output, _repeated_fieldMaskField_codec);
+ sourceContextField_.WriteTo(output, _repeated_sourceContextField_codec);
+ structField_.WriteTo(output, _repeated_structField_codec);
+ timestampField_.WriteTo(output, _repeated_timestampField_codec);
+ typeField_.WriteTo(output, _repeated_typeField_codec);
+ doubleField_.WriteTo(output, _repeated_doubleField_codec);
+ floatField_.WriteTo(output, _repeated_floatField_codec);
+ int64Field_.WriteTo(output, _repeated_int64Field_codec);
+ uint64Field_.WriteTo(output, _repeated_uint64Field_codec);
+ int32Field_.WriteTo(output, _repeated_int32Field_codec);
+ uint32Field_.WriteTo(output, _repeated_uint32Field_codec);
+ boolField_.WriteTo(output, _repeated_boolField_codec);
+ stringField_.WriteTo(output, _repeated_stringField_codec);
+ bytesField_.WriteTo(output, _repeated_bytesField_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += anyField_.CalculateSize(_repeated_anyField_codec);
+ size += apiField_.CalculateSize(_repeated_apiField_codec);
+ size += durationField_.CalculateSize(_repeated_durationField_codec);
+ size += emptyField_.CalculateSize(_repeated_emptyField_codec);
+ size += fieldMaskField_.CalculateSize(_repeated_fieldMaskField_codec);
+ size += sourceContextField_.CalculateSize(_repeated_sourceContextField_codec);
+ size += structField_.CalculateSize(_repeated_structField_codec);
+ size += timestampField_.CalculateSize(_repeated_timestampField_codec);
+ size += typeField_.CalculateSize(_repeated_typeField_codec);
+ size += doubleField_.CalculateSize(_repeated_doubleField_codec);
+ size += floatField_.CalculateSize(_repeated_floatField_codec);
+ size += int64Field_.CalculateSize(_repeated_int64Field_codec);
+ size += uint64Field_.CalculateSize(_repeated_uint64Field_codec);
+ size += int32Field_.CalculateSize(_repeated_int32Field_codec);
+ size += uint32Field_.CalculateSize(_repeated_uint32Field_codec);
+ size += boolField_.CalculateSize(_repeated_boolField_codec);
+ size += stringField_.CalculateSize(_repeated_stringField_codec);
+ size += bytesField_.CalculateSize(_repeated_bytesField_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(RepeatedWellKnownTypes other) {
+ if (other == null) {
+ return;
+ }
+ anyField_.Add(other.anyField_);
+ apiField_.Add(other.apiField_);
+ durationField_.Add(other.durationField_);
+ emptyField_.Add(other.emptyField_);
+ fieldMaskField_.Add(other.fieldMaskField_);
+ sourceContextField_.Add(other.sourceContextField_);
+ structField_.Add(other.structField_);
+ timestampField_.Add(other.timestampField_);
+ typeField_.Add(other.typeField_);
+ doubleField_.Add(other.doubleField_);
+ floatField_.Add(other.floatField_);
+ int64Field_.Add(other.int64Field_);
+ uint64Field_.Add(other.uint64Field_);
+ int32Field_.Add(other.int32Field_);
+ uint32Field_.Add(other.uint32Field_);
+ boolField_.Add(other.boolField_);
+ stringField_.Add(other.stringField_);
+ bytesField_.Add(other.bytesField_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ anyField_.AddEntriesFrom(input, _repeated_anyField_codec);
+ break;
+ }
+ case 18: {
+ apiField_.AddEntriesFrom(input, _repeated_apiField_codec);
+ break;
+ }
+ case 26: {
+ durationField_.AddEntriesFrom(input, _repeated_durationField_codec);
+ break;
+ }
+ case 34: {
+ emptyField_.AddEntriesFrom(input, _repeated_emptyField_codec);
+ break;
+ }
+ case 42: {
+ fieldMaskField_.AddEntriesFrom(input, _repeated_fieldMaskField_codec);
+ break;
+ }
+ case 50: {
+ sourceContextField_.AddEntriesFrom(input, _repeated_sourceContextField_codec);
+ break;
+ }
+ case 58: {
+ structField_.AddEntriesFrom(input, _repeated_structField_codec);
+ break;
+ }
+ case 66: {
+ timestampField_.AddEntriesFrom(input, _repeated_timestampField_codec);
+ break;
+ }
+ case 74: {
+ typeField_.AddEntriesFrom(input, _repeated_typeField_codec);
+ break;
+ }
+ case 82: {
+ doubleField_.AddEntriesFrom(input, _repeated_doubleField_codec);
+ break;
+ }
+ case 90: {
+ floatField_.AddEntriesFrom(input, _repeated_floatField_codec);
+ break;
+ }
+ case 98: {
+ int64Field_.AddEntriesFrom(input, _repeated_int64Field_codec);
+ break;
+ }
+ case 106: {
+ uint64Field_.AddEntriesFrom(input, _repeated_uint64Field_codec);
+ break;
+ }
+ case 114: {
+ int32Field_.AddEntriesFrom(input, _repeated_int32Field_codec);
+ break;
+ }
+ case 122: {
+ uint32Field_.AddEntriesFrom(input, _repeated_uint32Field_codec);
+ break;
+ }
+ case 130: {
+ boolField_.AddEntriesFrom(input, _repeated_boolField_codec);
+ break;
+ }
+ case 138: {
+ stringField_.AddEntriesFrom(input, _repeated_stringField_codec);
+ break;
+ }
+ case 146: {
+ bytesField_.AddEntriesFrom(input, _repeated_bytesField_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ public sealed partial class OneofWellKnownTypes : pb::IMessage<OneofWellKnownTypes> {
+ private static readonly pb::MessageParser<OneofWellKnownTypes> _parser = new pb::MessageParser<OneofWellKnownTypes>(() => new OneofWellKnownTypes());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<OneofWellKnownTypes> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestWellKnownTypesReflection.Descriptor.MessageTypes[2]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneofWellKnownTypes() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneofWellKnownTypes(OneofWellKnownTypes other) : this() {
+ switch (other.OneofFieldCase) {
+ case OneofFieldOneofCase.AnyField:
+ AnyField = other.AnyField.Clone();
+ break;
+ case OneofFieldOneofCase.ApiField:
+ ApiField = other.ApiField.Clone();
+ break;
+ case OneofFieldOneofCase.DurationField:
+ DurationField = other.DurationField.Clone();
+ break;
+ case OneofFieldOneofCase.EmptyField:
+ EmptyField = other.EmptyField.Clone();
+ break;
+ case OneofFieldOneofCase.FieldMaskField:
+ FieldMaskField = other.FieldMaskField.Clone();
+ break;
+ case OneofFieldOneofCase.SourceContextField:
+ SourceContextField = other.SourceContextField.Clone();
+ break;
+ case OneofFieldOneofCase.StructField:
+ StructField = other.StructField.Clone();
+ break;
+ case OneofFieldOneofCase.TimestampField:
+ TimestampField = other.TimestampField.Clone();
+ break;
+ case OneofFieldOneofCase.TypeField:
+ TypeField = other.TypeField.Clone();
+ break;
+ case OneofFieldOneofCase.DoubleField:
+ DoubleField = other.DoubleField;
+ break;
+ case OneofFieldOneofCase.FloatField:
+ FloatField = other.FloatField;
+ break;
+ case OneofFieldOneofCase.Int64Field:
+ Int64Field = other.Int64Field;
+ break;
+ case OneofFieldOneofCase.Uint64Field:
+ Uint64Field = other.Uint64Field;
+ break;
+ case OneofFieldOneofCase.Int32Field:
+ Int32Field = other.Int32Field;
+ break;
+ case OneofFieldOneofCase.Uint32Field:
+ Uint32Field = other.Uint32Field;
+ break;
+ case OneofFieldOneofCase.BoolField:
+ BoolField = other.BoolField;
+ break;
+ case OneofFieldOneofCase.StringField:
+ StringField = other.StringField;
+ break;
+ case OneofFieldOneofCase.BytesField:
+ BytesField = other.BytesField;
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneofWellKnownTypes Clone() {
+ return new OneofWellKnownTypes(this);
+ }
+
+ /// <summary>Field number for the "any_field" field.</summary>
+ public const int AnyFieldFieldNumber = 1;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Any AnyField {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.AnyField ? (global::Google.Protobuf.WellKnownTypes.Any) oneofField_ : null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.AnyField;
+ }
+ }
+
+ /// <summary>Field number for the "api_field" field.</summary>
+ public const int ApiFieldFieldNumber = 2;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Api ApiField {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.ApiField ? (global::Google.Protobuf.WellKnownTypes.Api) oneofField_ : null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.ApiField;
+ }
+ }
+
+ /// <summary>Field number for the "duration_field" field.</summary>
+ public const int DurationFieldFieldNumber = 3;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Duration DurationField {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.DurationField ? (global::Google.Protobuf.WellKnownTypes.Duration) oneofField_ : null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.DurationField;
+ }
+ }
+
+ /// <summary>Field number for the "empty_field" field.</summary>
+ public const int EmptyFieldFieldNumber = 4;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Empty EmptyField {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.EmptyField ? (global::Google.Protobuf.WellKnownTypes.Empty) oneofField_ : null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.EmptyField;
+ }
+ }
+
+ /// <summary>Field number for the "field_mask_field" field.</summary>
+ public const int FieldMaskFieldFieldNumber = 5;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.FieldMask FieldMaskField {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.FieldMaskField ? (global::Google.Protobuf.WellKnownTypes.FieldMask) oneofField_ : null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.FieldMaskField;
+ }
+ }
+
+ /// <summary>Field number for the "source_context_field" field.</summary>
+ public const int SourceContextFieldFieldNumber = 6;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.SourceContext SourceContextField {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.SourceContextField ? (global::Google.Protobuf.WellKnownTypes.SourceContext) oneofField_ : null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.SourceContextField;
+ }
+ }
+
+ /// <summary>Field number for the "struct_field" field.</summary>
+ public const int StructFieldFieldNumber = 7;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Struct StructField {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.StructField ? (global::Google.Protobuf.WellKnownTypes.Struct) oneofField_ : null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.StructField;
+ }
+ }
+
+ /// <summary>Field number for the "timestamp_field" field.</summary>
+ public const int TimestampFieldFieldNumber = 8;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Timestamp TimestampField {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.TimestampField ? (global::Google.Protobuf.WellKnownTypes.Timestamp) oneofField_ : null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.TimestampField;
+ }
+ }
+
+ /// <summary>Field number for the "type_field" field.</summary>
+ public const int TypeFieldFieldNumber = 9;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Type TypeField {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.TypeField ? (global::Google.Protobuf.WellKnownTypes.Type) oneofField_ : null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.TypeField;
+ }
+ }
+
+ /// <summary>Field number for the "double_field" field.</summary>
+ public const int DoubleFieldFieldNumber = 10;
+ private static readonly pb::FieldCodec<double?> _oneof_doubleField_codec = pb::FieldCodec.ForStructWrapper<double>(82);
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public double? DoubleField {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.DoubleField ? (double?) oneofField_ : (double?) null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.DoubleField;
+ }
+ }
+
+ /// <summary>Field number for the "float_field" field.</summary>
+ public const int FloatFieldFieldNumber = 11;
+ private static readonly pb::FieldCodec<float?> _oneof_floatField_codec = pb::FieldCodec.ForStructWrapper<float>(90);
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public float? FloatField {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.FloatField ? (float?) oneofField_ : (float?) null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.FloatField;
+ }
+ }
+
+ /// <summary>Field number for the "int64_field" field.</summary>
+ public const int Int64FieldFieldNumber = 12;
+ private static readonly pb::FieldCodec<long?> _oneof_int64Field_codec = pb::FieldCodec.ForStructWrapper<long>(98);
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public long? Int64Field {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.Int64Field ? (long?) oneofField_ : (long?) null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.Int64Field;
+ }
+ }
+
+ /// <summary>Field number for the "uint64_field" field.</summary>
+ public const int Uint64FieldFieldNumber = 13;
+ private static readonly pb::FieldCodec<ulong?> _oneof_uint64Field_codec = pb::FieldCodec.ForStructWrapper<ulong>(106);
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ulong? Uint64Field {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.Uint64Field ? (ulong?) oneofField_ : (ulong?) null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.Uint64Field;
+ }
+ }
+
+ /// <summary>Field number for the "int32_field" field.</summary>
+ public const int Int32FieldFieldNumber = 14;
+ private static readonly pb::FieldCodec<int?> _oneof_int32Field_codec = pb::FieldCodec.ForStructWrapper<int>(114);
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int? Int32Field {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.Int32Field ? (int?) oneofField_ : (int?) null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.Int32Field;
+ }
+ }
+
+ /// <summary>Field number for the "uint32_field" field.</summary>
+ public const int Uint32FieldFieldNumber = 15;
+ private static readonly pb::FieldCodec<uint?> _oneof_uint32Field_codec = pb::FieldCodec.ForStructWrapper<uint>(122);
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public uint? Uint32Field {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.Uint32Field ? (uint?) oneofField_ : (uint?) null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.Uint32Field;
+ }
+ }
+
+ /// <summary>Field number for the "bool_field" field.</summary>
+ public const int BoolFieldFieldNumber = 16;
+ private static readonly pb::FieldCodec<bool?> _oneof_boolField_codec = pb::FieldCodec.ForStructWrapper<bool>(130);
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool? BoolField {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.BoolField ? (bool?) oneofField_ : (bool?) null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.BoolField;
+ }
+ }
+
+ /// <summary>Field number for the "string_field" field.</summary>
+ public const int StringFieldFieldNumber = 17;
+ private static readonly pb::FieldCodec<string> _oneof_stringField_codec = pb::FieldCodec.ForClassWrapper<string>(138);
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string StringField {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.StringField ? (string) oneofField_ : (string) null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.StringField;
+ }
+ }
+
+ /// <summary>Field number for the "bytes_field" field.</summary>
+ public const int BytesFieldFieldNumber = 18;
+ private static readonly pb::FieldCodec<pb::ByteString> _oneof_bytesField_codec = pb::FieldCodec.ForClassWrapper<pb::ByteString>(146);
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pb::ByteString BytesField {
+ get { return oneofFieldCase_ == OneofFieldOneofCase.BytesField ? (pb::ByteString) oneofField_ : (pb::ByteString) null; }
+ set {
+ oneofField_ = value;
+ oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.BytesField;
+ }
+ }
+
+ private object oneofField_;
+ /// <summary>Enum of possible cases for the "oneof_field" oneof.</summary>
+ public enum OneofFieldOneofCase {
+ None = 0,
+ AnyField = 1,
+ ApiField = 2,
+ DurationField = 3,
+ EmptyField = 4,
+ FieldMaskField = 5,
+ SourceContextField = 6,
+ StructField = 7,
+ TimestampField = 8,
+ TypeField = 9,
+ DoubleField = 10,
+ FloatField = 11,
+ Int64Field = 12,
+ Uint64Field = 13,
+ Int32Field = 14,
+ Uint32Field = 15,
+ BoolField = 16,
+ StringField = 17,
+ BytesField = 18,
+ }
+ private OneofFieldOneofCase oneofFieldCase_ = OneofFieldOneofCase.None;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneofFieldOneofCase OneofFieldCase {
+ get { return oneofFieldCase_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearOneofField() {
+ oneofFieldCase_ = OneofFieldOneofCase.None;
+ oneofField_ = null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as OneofWellKnownTypes);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(OneofWellKnownTypes other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (!object.Equals(AnyField, other.AnyField)) return false;
+ if (!object.Equals(ApiField, other.ApiField)) return false;
+ if (!object.Equals(DurationField, other.DurationField)) return false;
+ if (!object.Equals(EmptyField, other.EmptyField)) return false;
+ if (!object.Equals(FieldMaskField, other.FieldMaskField)) return false;
+ if (!object.Equals(SourceContextField, other.SourceContextField)) return false;
+ if (!object.Equals(StructField, other.StructField)) return false;
+ if (!object.Equals(TimestampField, other.TimestampField)) return false;
+ if (!object.Equals(TypeField, other.TypeField)) return false;
+ if (DoubleField != other.DoubleField) return false;
+ if (FloatField != other.FloatField) return false;
+ if (Int64Field != other.Int64Field) return false;
+ if (Uint64Field != other.Uint64Field) return false;
+ if (Int32Field != other.Int32Field) return false;
+ if (Uint32Field != other.Uint32Field) return false;
+ if (BoolField != other.BoolField) return false;
+ if (StringField != other.StringField) return false;
+ if (BytesField != other.BytesField) return false;
+ if (OneofFieldCase != other.OneofFieldCase) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (oneofFieldCase_ == OneofFieldOneofCase.AnyField) hash ^= AnyField.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.ApiField) hash ^= ApiField.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.DurationField) hash ^= DurationField.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.EmptyField) hash ^= EmptyField.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.FieldMaskField) hash ^= FieldMaskField.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.SourceContextField) hash ^= SourceContextField.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.StructField) hash ^= StructField.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.TimestampField) hash ^= TimestampField.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.TypeField) hash ^= TypeField.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.DoubleField) hash ^= DoubleField.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.FloatField) hash ^= FloatField.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.Int64Field) hash ^= Int64Field.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.Uint64Field) hash ^= Uint64Field.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.Int32Field) hash ^= Int32Field.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.Uint32Field) hash ^= Uint32Field.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.BoolField) hash ^= BoolField.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.StringField) hash ^= StringField.GetHashCode();
+ if (oneofFieldCase_ == OneofFieldOneofCase.BytesField) hash ^= BytesField.GetHashCode();
+ hash ^= (int) oneofFieldCase_;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (oneofFieldCase_ == OneofFieldOneofCase.AnyField) {
+ output.WriteRawTag(10);
+ output.WriteMessage(AnyField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.ApiField) {
+ output.WriteRawTag(18);
+ output.WriteMessage(ApiField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.DurationField) {
+ output.WriteRawTag(26);
+ output.WriteMessage(DurationField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.EmptyField) {
+ output.WriteRawTag(34);
+ output.WriteMessage(EmptyField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.FieldMaskField) {
+ output.WriteRawTag(42);
+ output.WriteMessage(FieldMaskField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.SourceContextField) {
+ output.WriteRawTag(50);
+ output.WriteMessage(SourceContextField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.StructField) {
+ output.WriteRawTag(58);
+ output.WriteMessage(StructField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.TimestampField) {
+ output.WriteRawTag(66);
+ output.WriteMessage(TimestampField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.TypeField) {
+ output.WriteRawTag(74);
+ output.WriteMessage(TypeField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.DoubleField) {
+ _oneof_doubleField_codec.WriteTagAndValue(output, (double?) oneofField_);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.FloatField) {
+ _oneof_floatField_codec.WriteTagAndValue(output, (float?) oneofField_);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.Int64Field) {
+ _oneof_int64Field_codec.WriteTagAndValue(output, (long?) oneofField_);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.Uint64Field) {
+ _oneof_uint64Field_codec.WriteTagAndValue(output, (ulong?) oneofField_);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.Int32Field) {
+ _oneof_int32Field_codec.WriteTagAndValue(output, (int?) oneofField_);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.Uint32Field) {
+ _oneof_uint32Field_codec.WriteTagAndValue(output, (uint?) oneofField_);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.BoolField) {
+ _oneof_boolField_codec.WriteTagAndValue(output, (bool?) oneofField_);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.StringField) {
+ _oneof_stringField_codec.WriteTagAndValue(output, (string) oneofField_);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.BytesField) {
+ _oneof_bytesField_codec.WriteTagAndValue(output, (pb::ByteString) oneofField_);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (oneofFieldCase_ == OneofFieldOneofCase.AnyField) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(AnyField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.ApiField) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(ApiField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.DurationField) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(DurationField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.EmptyField) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(EmptyField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.FieldMaskField) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(FieldMaskField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.SourceContextField) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(SourceContextField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.StructField) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(StructField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.TimestampField) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(TimestampField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.TypeField) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(TypeField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.DoubleField) {
+ size += _oneof_doubleField_codec.CalculateSizeWithTag(DoubleField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.FloatField) {
+ size += _oneof_floatField_codec.CalculateSizeWithTag(FloatField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.Int64Field) {
+ size += _oneof_int64Field_codec.CalculateSizeWithTag(Int64Field);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.Uint64Field) {
+ size += _oneof_uint64Field_codec.CalculateSizeWithTag(Uint64Field);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.Int32Field) {
+ size += _oneof_int32Field_codec.CalculateSizeWithTag(Int32Field);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.Uint32Field) {
+ size += _oneof_uint32Field_codec.CalculateSizeWithTag(Uint32Field);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.BoolField) {
+ size += _oneof_boolField_codec.CalculateSizeWithTag(BoolField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.StringField) {
+ size += _oneof_stringField_codec.CalculateSizeWithTag(StringField);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.BytesField) {
+ size += _oneof_bytesField_codec.CalculateSizeWithTag(BytesField);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(OneofWellKnownTypes other) {
+ if (other == null) {
+ return;
+ }
+ switch (other.OneofFieldCase) {
+ case OneofFieldOneofCase.AnyField:
+ AnyField = other.AnyField;
+ break;
+ case OneofFieldOneofCase.ApiField:
+ ApiField = other.ApiField;
+ break;
+ case OneofFieldOneofCase.DurationField:
+ DurationField = other.DurationField;
+ break;
+ case OneofFieldOneofCase.EmptyField:
+ EmptyField = other.EmptyField;
+ break;
+ case OneofFieldOneofCase.FieldMaskField:
+ FieldMaskField = other.FieldMaskField;
+ break;
+ case OneofFieldOneofCase.SourceContextField:
+ SourceContextField = other.SourceContextField;
+ break;
+ case OneofFieldOneofCase.StructField:
+ StructField = other.StructField;
+ break;
+ case OneofFieldOneofCase.TimestampField:
+ TimestampField = other.TimestampField;
+ break;
+ case OneofFieldOneofCase.TypeField:
+ TypeField = other.TypeField;
+ break;
+ case OneofFieldOneofCase.DoubleField:
+ DoubleField = other.DoubleField;
+ break;
+ case OneofFieldOneofCase.FloatField:
+ FloatField = other.FloatField;
+ break;
+ case OneofFieldOneofCase.Int64Field:
+ Int64Field = other.Int64Field;
+ break;
+ case OneofFieldOneofCase.Uint64Field:
+ Uint64Field = other.Uint64Field;
+ break;
+ case OneofFieldOneofCase.Int32Field:
+ Int32Field = other.Int32Field;
+ break;
+ case OneofFieldOneofCase.Uint32Field:
+ Uint32Field = other.Uint32Field;
+ break;
+ case OneofFieldOneofCase.BoolField:
+ BoolField = other.BoolField;
+ break;
+ case OneofFieldOneofCase.StringField:
+ StringField = other.StringField;
+ break;
+ case OneofFieldOneofCase.BytesField:
+ BytesField = other.BytesField;
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ global::Google.Protobuf.WellKnownTypes.Any subBuilder = new global::Google.Protobuf.WellKnownTypes.Any();
+ if (oneofFieldCase_ == OneofFieldOneofCase.AnyField) {
+ subBuilder.MergeFrom(AnyField);
+ }
+ input.ReadMessage(subBuilder);
+ AnyField = subBuilder;
+ break;
+ }
+ case 18: {
+ global::Google.Protobuf.WellKnownTypes.Api subBuilder = new global::Google.Protobuf.WellKnownTypes.Api();
+ if (oneofFieldCase_ == OneofFieldOneofCase.ApiField) {
+ subBuilder.MergeFrom(ApiField);
+ }
+ input.ReadMessage(subBuilder);
+ ApiField = subBuilder;
+ break;
+ }
+ case 26: {
+ global::Google.Protobuf.WellKnownTypes.Duration subBuilder = new global::Google.Protobuf.WellKnownTypes.Duration();
+ if (oneofFieldCase_ == OneofFieldOneofCase.DurationField) {
+ subBuilder.MergeFrom(DurationField);
+ }
+ input.ReadMessage(subBuilder);
+ DurationField = subBuilder;
+ break;
+ }
+ case 34: {
+ global::Google.Protobuf.WellKnownTypes.Empty subBuilder = new global::Google.Protobuf.WellKnownTypes.Empty();
+ if (oneofFieldCase_ == OneofFieldOneofCase.EmptyField) {
+ subBuilder.MergeFrom(EmptyField);
+ }
+ input.ReadMessage(subBuilder);
+ EmptyField = subBuilder;
+ break;
+ }
+ case 42: {
+ global::Google.Protobuf.WellKnownTypes.FieldMask subBuilder = new global::Google.Protobuf.WellKnownTypes.FieldMask();
+ if (oneofFieldCase_ == OneofFieldOneofCase.FieldMaskField) {
+ subBuilder.MergeFrom(FieldMaskField);
+ }
+ input.ReadMessage(subBuilder);
+ FieldMaskField = subBuilder;
+ break;
+ }
+ case 50: {
+ global::Google.Protobuf.WellKnownTypes.SourceContext subBuilder = new global::Google.Protobuf.WellKnownTypes.SourceContext();
+ if (oneofFieldCase_ == OneofFieldOneofCase.SourceContextField) {
+ subBuilder.MergeFrom(SourceContextField);
+ }
+ input.ReadMessage(subBuilder);
+ SourceContextField = subBuilder;
+ break;
+ }
+ case 58: {
+ global::Google.Protobuf.WellKnownTypes.Struct subBuilder = new global::Google.Protobuf.WellKnownTypes.Struct();
+ if (oneofFieldCase_ == OneofFieldOneofCase.StructField) {
+ subBuilder.MergeFrom(StructField);
+ }
+ input.ReadMessage(subBuilder);
+ StructField = subBuilder;
+ break;
+ }
+ case 66: {
+ global::Google.Protobuf.WellKnownTypes.Timestamp subBuilder = new global::Google.Protobuf.WellKnownTypes.Timestamp();
+ if (oneofFieldCase_ == OneofFieldOneofCase.TimestampField) {
+ subBuilder.MergeFrom(TimestampField);
+ }
+ input.ReadMessage(subBuilder);
+ TimestampField = subBuilder;
+ break;
+ }
+ case 74: {
+ global::Google.Protobuf.WellKnownTypes.Type subBuilder = new global::Google.Protobuf.WellKnownTypes.Type();
+ if (oneofFieldCase_ == OneofFieldOneofCase.TypeField) {
+ subBuilder.MergeFrom(TypeField);
+ }
+ input.ReadMessage(subBuilder);
+ TypeField = subBuilder;
+ break;
+ }
+ case 82: {
+ DoubleField = _oneof_doubleField_codec.Read(input);
+ break;
+ }
+ case 90: {
+ FloatField = _oneof_floatField_codec.Read(input);
+ break;
+ }
+ case 98: {
+ Int64Field = _oneof_int64Field_codec.Read(input);
+ break;
+ }
+ case 106: {
+ Uint64Field = _oneof_uint64Field_codec.Read(input);
+ break;
+ }
+ case 114: {
+ Int32Field = _oneof_int32Field_codec.Read(input);
+ break;
+ }
+ case 122: {
+ Uint32Field = _oneof_uint32Field_codec.Read(input);
+ break;
+ }
+ case 130: {
+ BoolField = _oneof_boolField_codec.Read(input);
+ break;
+ }
+ case 138: {
+ StringField = _oneof_stringField_codec.Read(input);
+ break;
+ }
+ case 146: {
+ BytesField = _oneof_bytesField_codec.Read(input);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// A map field for each well-known type. We only
+ /// need to worry about the value part of the map being the
+ /// well-known types, as messages can't be map keys.
+ /// </summary>
+ public sealed partial class MapWellKnownTypes : pb::IMessage<MapWellKnownTypes> {
+ private static readonly pb::MessageParser<MapWellKnownTypes> _parser = new pb::MessageParser<MapWellKnownTypes>(() => new MapWellKnownTypes());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<MapWellKnownTypes> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.TestProtos.UnittestWellKnownTypesReflection.Descriptor.MessageTypes[3]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MapWellKnownTypes() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MapWellKnownTypes(MapWellKnownTypes other) : this() {
+ anyField_ = other.anyField_.Clone();
+ apiField_ = other.apiField_.Clone();
+ durationField_ = other.durationField_.Clone();
+ emptyField_ = other.emptyField_.Clone();
+ fieldMaskField_ = other.fieldMaskField_.Clone();
+ sourceContextField_ = other.sourceContextField_.Clone();
+ structField_ = other.structField_.Clone();
+ timestampField_ = other.timestampField_.Clone();
+ typeField_ = other.typeField_.Clone();
+ doubleField_ = other.doubleField_.Clone();
+ floatField_ = other.floatField_.Clone();
+ int64Field_ = other.int64Field_.Clone();
+ uint64Field_ = other.uint64Field_.Clone();
+ int32Field_ = other.int32Field_.Clone();
+ uint32Field_ = other.uint32Field_.Clone();
+ boolField_ = other.boolField_.Clone();
+ stringField_ = other.stringField_.Clone();
+ bytesField_ = other.bytesField_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MapWellKnownTypes Clone() {
+ return new MapWellKnownTypes(this);
+ }
+
+ /// <summary>Field number for the "any_field" field.</summary>
+ public const int AnyFieldFieldNumber = 1;
+ private static readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Any>.Codec _map_anyField_codec
+ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Any>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Any.Parser), 10);
+ private readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Any> anyField_ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Any>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Any> AnyField {
+ get { return anyField_; }
+ }
+
+ /// <summary>Field number for the "api_field" field.</summary>
+ public const int ApiFieldFieldNumber = 2;
+ private static readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Api>.Codec _map_apiField_codec
+ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Api>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Api.Parser), 18);
+ private readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Api> apiField_ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Api>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Api> ApiField {
+ get { return apiField_; }
+ }
+
+ /// <summary>Field number for the "duration_field" field.</summary>
+ public const int DurationFieldFieldNumber = 3;
+ private static readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Duration>.Codec _map_durationField_codec
+ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Duration>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Duration.Parser), 26);
+ private readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Duration> durationField_ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Duration>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Duration> DurationField {
+ get { return durationField_; }
+ }
+
+ /// <summary>Field number for the "empty_field" field.</summary>
+ public const int EmptyFieldFieldNumber = 4;
+ private static readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Empty>.Codec _map_emptyField_codec
+ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Empty>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Empty.Parser), 34);
+ private readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Empty> emptyField_ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Empty>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Empty> EmptyField {
+ get { return emptyField_; }
+ }
+
+ /// <summary>Field number for the "field_mask_field" field.</summary>
+ public const int FieldMaskFieldFieldNumber = 5;
+ private static readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.FieldMask>.Codec _map_fieldMaskField_codec
+ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.FieldMask>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.FieldMask.Parser), 42);
+ private readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.FieldMask> fieldMaskField_ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.FieldMask>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.FieldMask> FieldMaskField {
+ get { return fieldMaskField_; }
+ }
+
+ /// <summary>Field number for the "source_context_field" field.</summary>
+ public const int SourceContextFieldFieldNumber = 6;
+ private static readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.SourceContext>.Codec _map_sourceContextField_codec
+ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.SourceContext>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.SourceContext.Parser), 50);
+ private readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.SourceContext> sourceContextField_ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.SourceContext>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.SourceContext> SourceContextField {
+ get { return sourceContextField_; }
+ }
+
+ /// <summary>Field number for the "struct_field" field.</summary>
+ public const int StructFieldFieldNumber = 7;
+ private static readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Struct>.Codec _map_structField_codec
+ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Struct>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Struct.Parser), 58);
+ private readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Struct> structField_ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Struct>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Struct> StructField {
+ get { return structField_; }
+ }
+
+ /// <summary>Field number for the "timestamp_field" field.</summary>
+ public const int TimestampFieldFieldNumber = 8;
+ private static readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Timestamp>.Codec _map_timestampField_codec
+ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Timestamp>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Timestamp.Parser), 66);
+ private readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Timestamp> timestampField_ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Timestamp>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Timestamp> TimestampField {
+ get { return timestampField_; }
+ }
+
+ /// <summary>Field number for the "type_field" field.</summary>
+ public const int TypeFieldFieldNumber = 9;
+ private static readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Type>.Codec _map_typeField_codec
+ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Type>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Type.Parser), 74);
+ private readonly pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Type> typeField_ = new pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Type>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, global::Google.Protobuf.WellKnownTypes.Type> TypeField {
+ get { return typeField_; }
+ }
+
+ /// <summary>Field number for the "double_field" field.</summary>
+ public const int DoubleFieldFieldNumber = 10;
+ private static readonly pbc::MapField<int, double?>.Codec _map_doubleField_codec
+ = new pbc::MapField<int, double?>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForStructWrapper<double>(18), 82);
+ private readonly pbc::MapField<int, double?> doubleField_ = new pbc::MapField<int, double?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, double?> DoubleField {
+ get { return doubleField_; }
+ }
+
+ /// <summary>Field number for the "float_field" field.</summary>
+ public const int FloatFieldFieldNumber = 11;
+ private static readonly pbc::MapField<int, float?>.Codec _map_floatField_codec
+ = new pbc::MapField<int, float?>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForStructWrapper<float>(18), 90);
+ private readonly pbc::MapField<int, float?> floatField_ = new pbc::MapField<int, float?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, float?> FloatField {
+ get { return floatField_; }
+ }
+
+ /// <summary>Field number for the "int64_field" field.</summary>
+ public const int Int64FieldFieldNumber = 12;
+ private static readonly pbc::MapField<int, long?>.Codec _map_int64Field_codec
+ = new pbc::MapField<int, long?>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForStructWrapper<long>(18), 98);
+ private readonly pbc::MapField<int, long?> int64Field_ = new pbc::MapField<int, long?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, long?> Int64Field {
+ get { return int64Field_; }
+ }
+
+ /// <summary>Field number for the "uint64_field" field.</summary>
+ public const int Uint64FieldFieldNumber = 13;
+ private static readonly pbc::MapField<int, ulong?>.Codec _map_uint64Field_codec
+ = new pbc::MapField<int, ulong?>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForStructWrapper<ulong>(18), 106);
+ private readonly pbc::MapField<int, ulong?> uint64Field_ = new pbc::MapField<int, ulong?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, ulong?> Uint64Field {
+ get { return uint64Field_; }
+ }
+
+ /// <summary>Field number for the "int32_field" field.</summary>
+ public const int Int32FieldFieldNumber = 14;
+ private static readonly pbc::MapField<int, int?>.Codec _map_int32Field_codec
+ = new pbc::MapField<int, int?>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForStructWrapper<int>(18), 114);
+ private readonly pbc::MapField<int, int?> int32Field_ = new pbc::MapField<int, int?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, int?> Int32Field {
+ get { return int32Field_; }
+ }
+
+ /// <summary>Field number for the "uint32_field" field.</summary>
+ public const int Uint32FieldFieldNumber = 15;
+ private static readonly pbc::MapField<int, uint?>.Codec _map_uint32Field_codec
+ = new pbc::MapField<int, uint?>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForStructWrapper<uint>(18), 122);
+ private readonly pbc::MapField<int, uint?> uint32Field_ = new pbc::MapField<int, uint?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, uint?> Uint32Field {
+ get { return uint32Field_; }
+ }
+
+ /// <summary>Field number for the "bool_field" field.</summary>
+ public const int BoolFieldFieldNumber = 16;
+ private static readonly pbc::MapField<int, bool?>.Codec _map_boolField_codec
+ = new pbc::MapField<int, bool?>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForStructWrapper<bool>(18), 130);
+ private readonly pbc::MapField<int, bool?> boolField_ = new pbc::MapField<int, bool?>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, bool?> BoolField {
+ get { return boolField_; }
+ }
+
+ /// <summary>Field number for the "string_field" field.</summary>
+ public const int StringFieldFieldNumber = 17;
+ private static readonly pbc::MapField<int, string>.Codec _map_stringField_codec
+ = new pbc::MapField<int, string>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForClassWrapper<string>(18), 138);
+ private readonly pbc::MapField<int, string> stringField_ = new pbc::MapField<int, string>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, string> StringField {
+ get { return stringField_; }
+ }
+
+ /// <summary>Field number for the "bytes_field" field.</summary>
+ public const int BytesFieldFieldNumber = 18;
+ private static readonly pbc::MapField<int, pb::ByteString>.Codec _map_bytesField_codec
+ = new pbc::MapField<int, pb::ByteString>.Codec(pb::FieldCodec.ForInt32(8), pb::FieldCodec.ForClassWrapper<pb::ByteString>(18), 146);
+ private readonly pbc::MapField<int, pb::ByteString> bytesField_ = new pbc::MapField<int, pb::ByteString>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<int, pb::ByteString> BytesField {
+ get { return bytesField_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as MapWellKnownTypes);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(MapWellKnownTypes other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (!AnyField.Equals(other.AnyField)) return false;
+ if (!ApiField.Equals(other.ApiField)) return false;
+ if (!DurationField.Equals(other.DurationField)) return false;
+ if (!EmptyField.Equals(other.EmptyField)) return false;
+ if (!FieldMaskField.Equals(other.FieldMaskField)) return false;
+ if (!SourceContextField.Equals(other.SourceContextField)) return false;
+ if (!StructField.Equals(other.StructField)) return false;
+ if (!TimestampField.Equals(other.TimestampField)) return false;
+ if (!TypeField.Equals(other.TypeField)) return false;
+ if (!DoubleField.Equals(other.DoubleField)) return false;
+ if (!FloatField.Equals(other.FloatField)) return false;
+ if (!Int64Field.Equals(other.Int64Field)) return false;
+ if (!Uint64Field.Equals(other.Uint64Field)) return false;
+ if (!Int32Field.Equals(other.Int32Field)) return false;
+ if (!Uint32Field.Equals(other.Uint32Field)) return false;
+ if (!BoolField.Equals(other.BoolField)) return false;
+ if (!StringField.Equals(other.StringField)) return false;
+ if (!BytesField.Equals(other.BytesField)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= AnyField.GetHashCode();
+ hash ^= ApiField.GetHashCode();
+ hash ^= DurationField.GetHashCode();
+ hash ^= EmptyField.GetHashCode();
+ hash ^= FieldMaskField.GetHashCode();
+ hash ^= SourceContextField.GetHashCode();
+ hash ^= StructField.GetHashCode();
+ hash ^= TimestampField.GetHashCode();
+ hash ^= TypeField.GetHashCode();
+ hash ^= DoubleField.GetHashCode();
+ hash ^= FloatField.GetHashCode();
+ hash ^= Int64Field.GetHashCode();
+ hash ^= Uint64Field.GetHashCode();
+ hash ^= Int32Field.GetHashCode();
+ hash ^= Uint32Field.GetHashCode();
+ hash ^= BoolField.GetHashCode();
+ hash ^= StringField.GetHashCode();
+ hash ^= BytesField.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ anyField_.WriteTo(output, _map_anyField_codec);
+ apiField_.WriteTo(output, _map_apiField_codec);
+ durationField_.WriteTo(output, _map_durationField_codec);
+ emptyField_.WriteTo(output, _map_emptyField_codec);
+ fieldMaskField_.WriteTo(output, _map_fieldMaskField_codec);
+ sourceContextField_.WriteTo(output, _map_sourceContextField_codec);
+ structField_.WriteTo(output, _map_structField_codec);
+ timestampField_.WriteTo(output, _map_timestampField_codec);
+ typeField_.WriteTo(output, _map_typeField_codec);
+ doubleField_.WriteTo(output, _map_doubleField_codec);
+ floatField_.WriteTo(output, _map_floatField_codec);
+ int64Field_.WriteTo(output, _map_int64Field_codec);
+ uint64Field_.WriteTo(output, _map_uint64Field_codec);
+ int32Field_.WriteTo(output, _map_int32Field_codec);
+ uint32Field_.WriteTo(output, _map_uint32Field_codec);
+ boolField_.WriteTo(output, _map_boolField_codec);
+ stringField_.WriteTo(output, _map_stringField_codec);
+ bytesField_.WriteTo(output, _map_bytesField_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += anyField_.CalculateSize(_map_anyField_codec);
+ size += apiField_.CalculateSize(_map_apiField_codec);
+ size += durationField_.CalculateSize(_map_durationField_codec);
+ size += emptyField_.CalculateSize(_map_emptyField_codec);
+ size += fieldMaskField_.CalculateSize(_map_fieldMaskField_codec);
+ size += sourceContextField_.CalculateSize(_map_sourceContextField_codec);
+ size += structField_.CalculateSize(_map_structField_codec);
+ size += timestampField_.CalculateSize(_map_timestampField_codec);
+ size += typeField_.CalculateSize(_map_typeField_codec);
+ size += doubleField_.CalculateSize(_map_doubleField_codec);
+ size += floatField_.CalculateSize(_map_floatField_codec);
+ size += int64Field_.CalculateSize(_map_int64Field_codec);
+ size += uint64Field_.CalculateSize(_map_uint64Field_codec);
+ size += int32Field_.CalculateSize(_map_int32Field_codec);
+ size += uint32Field_.CalculateSize(_map_uint32Field_codec);
+ size += boolField_.CalculateSize(_map_boolField_codec);
+ size += stringField_.CalculateSize(_map_stringField_codec);
+ size += bytesField_.CalculateSize(_map_bytesField_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(MapWellKnownTypes other) {
+ if (other == null) {
+ return;
+ }
+ anyField_.Add(other.anyField_);
+ apiField_.Add(other.apiField_);
+ durationField_.Add(other.durationField_);
+ emptyField_.Add(other.emptyField_);
+ fieldMaskField_.Add(other.fieldMaskField_);
+ sourceContextField_.Add(other.sourceContextField_);
+ structField_.Add(other.structField_);
+ timestampField_.Add(other.timestampField_);
+ typeField_.Add(other.typeField_);
+ doubleField_.Add(other.doubleField_);
+ floatField_.Add(other.floatField_);
+ int64Field_.Add(other.int64Field_);
+ uint64Field_.Add(other.uint64Field_);
+ int32Field_.Add(other.int32Field_);
+ uint32Field_.Add(other.uint32Field_);
+ boolField_.Add(other.boolField_);
+ stringField_.Add(other.stringField_);
+ bytesField_.Add(other.bytesField_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ anyField_.AddEntriesFrom(input, _map_anyField_codec);
+ break;
+ }
+ case 18: {
+ apiField_.AddEntriesFrom(input, _map_apiField_codec);
+ break;
+ }
+ case 26: {
+ durationField_.AddEntriesFrom(input, _map_durationField_codec);
+ break;
+ }
+ case 34: {
+ emptyField_.AddEntriesFrom(input, _map_emptyField_codec);
+ break;
+ }
+ case 42: {
+ fieldMaskField_.AddEntriesFrom(input, _map_fieldMaskField_codec);
+ break;
+ }
+ case 50: {
+ sourceContextField_.AddEntriesFrom(input, _map_sourceContextField_codec);
+ break;
+ }
+ case 58: {
+ structField_.AddEntriesFrom(input, _map_structField_codec);
+ break;
+ }
+ case 66: {
+ timestampField_.AddEntriesFrom(input, _map_timestampField_codec);
+ break;
+ }
+ case 74: {
+ typeField_.AddEntriesFrom(input, _map_typeField_codec);
+ break;
+ }
+ case 82: {
+ doubleField_.AddEntriesFrom(input, _map_doubleField_codec);
+ break;
+ }
+ case 90: {
+ floatField_.AddEntriesFrom(input, _map_floatField_codec);
+ break;
+ }
+ case 98: {
+ int64Field_.AddEntriesFrom(input, _map_int64Field_codec);
+ break;
+ }
+ case 106: {
+ uint64Field_.AddEntriesFrom(input, _map_uint64Field_codec);
+ break;
+ }
+ case 114: {
+ int32Field_.AddEntriesFrom(input, _map_int32Field_codec);
+ break;
+ }
+ case 122: {
+ uint32Field_.AddEntriesFrom(input, _map_uint32Field_codec);
+ break;
+ }
+ case 130: {
+ boolField_.AddEntriesFrom(input, _map_boolField_codec);
+ break;
+ }
+ case 138: {
+ stringField_.AddEntriesFrom(input, _map_stringField_codec);
+ break;
+ }
+ case 146: {
+ bytesField_.AddEntriesFrom(input, _map_bytesField_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs
new file mode 100644
index 0000000000..4aecc998de
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs
@@ -0,0 +1,116 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+
+namespace Google.Protobuf.WellKnownTypes
+{
+ public class AnyTest
+ {
+ [Test]
+ public void Pack()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var any = Any.Pack(message);
+ Assert.AreEqual("type.googleapis.com/protobuf_unittest.TestAllTypes", any.TypeUrl);
+ Assert.AreEqual(message.CalculateSize(), any.Value.Length);
+ }
+
+ [Test]
+ public void Pack_WithCustomPrefix()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var any = Any.Pack(message, "foo.bar/baz");
+ Assert.AreEqual("foo.bar/baz/protobuf_unittest.TestAllTypes", any.TypeUrl);
+ Assert.AreEqual(message.CalculateSize(), any.Value.Length);
+ }
+
+ [Test]
+ public void Pack_WithCustomPrefixTrailingSlash()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var any = Any.Pack(message, "foo.bar/baz/");
+ Assert.AreEqual("foo.bar/baz/protobuf_unittest.TestAllTypes", any.TypeUrl);
+ Assert.AreEqual(message.CalculateSize(), any.Value.Length);
+ }
+
+ [Test]
+ public void Unpack_WrongType()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var any = Any.Pack(message);
+ Assert.Throws<InvalidProtocolBufferException>(() => any.Unpack<TestOneof>());
+ }
+
+ [Test]
+ public void Unpack_Success()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var any = Any.Pack(message);
+ var unpacked = any.Unpack<TestAllTypes>();
+ Assert.AreEqual(message, unpacked);
+ }
+
+ [Test]
+ public void Unpack_CustomPrefix_Success()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var any = Any.Pack(message, "foo.bar/baz");
+ var unpacked = any.Unpack<TestAllTypes>();
+ Assert.AreEqual(message, unpacked);
+ }
+
+ [Test]
+ public void ToString_WithValues()
+ {
+ var message = SampleMessages.CreateFullTestAllTypes();
+ var any = Any.Pack(message);
+ var text = any.ToString();
+ Assert.That(text, Does.Contain("\"@value\": \"" + message.ToByteString().ToBase64() + "\""));
+ }
+
+ [Test]
+ public void ToString_Empty()
+ {
+ var any = new Any();
+ Assert.AreEqual("{ \"@type\": \"\", \"@value\": \"\" }", any.ToString());
+ }
+
+ [Test]
+ public void ToString_MessageContainingAny()
+ {
+ var message = new TestWellKnownTypes { AnyField = new Any() };
+ Assert.AreEqual("{ \"anyField\": { \"@type\": \"\", \"@value\": \"\" } }", message.ToString());
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs
new file mode 100644
index 0000000000..141faf80e0
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/DurationTest.cs
@@ -0,0 +1,132 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using NUnit.Framework;
+using System;
+
+namespace Google.Protobuf.WellKnownTypes
+{
+ public class DurationTest
+ {
+ [Test]
+ public void ToTimeSpan()
+ {
+ Assert.AreEqual(TimeSpan.FromSeconds(1), new Duration { Seconds = 1 }.ToTimeSpan());
+ Assert.AreEqual(TimeSpan.FromSeconds(-1), new Duration { Seconds = -1 }.ToTimeSpan());
+ Assert.AreEqual(TimeSpan.FromMilliseconds(1), new Duration { Nanos = 1000000 }.ToTimeSpan());
+ Assert.AreEqual(TimeSpan.FromMilliseconds(-1), new Duration { Nanos = -1000000 }.ToTimeSpan());
+ Assert.AreEqual(TimeSpan.FromTicks(1), new Duration { Nanos = 100 }.ToTimeSpan());
+ Assert.AreEqual(TimeSpan.FromTicks(-1), new Duration { Nanos = -100 }.ToTimeSpan());
+
+ // Rounding is towards 0
+ Assert.AreEqual(TimeSpan.FromTicks(2), new Duration { Nanos = 250 }.ToTimeSpan());
+ Assert.AreEqual(TimeSpan.FromTicks(-2), new Duration { Nanos = -250 }.ToTimeSpan());
+ }
+
+ [Test]
+ public void Addition()
+ {
+ Assert.AreEqual(new Duration { Seconds = 2, Nanos = 100000000 },
+ new Duration { Seconds = 1, Nanos = 600000000 } + new Duration { Nanos = 500000000 });
+ Assert.AreEqual(new Duration { Seconds = -2, Nanos = -100000000 },
+ new Duration { Seconds = -1, Nanos = -600000000 } + new Duration { Nanos = -500000000 });
+ Assert.AreEqual(new Duration { Seconds = 1, Nanos = 100000000 },
+ new Duration { Seconds = 1, Nanos = 600000000 } + new Duration { Nanos = -500000000 });
+
+ // Non-normalized durations, or non-normalized intermediate results
+ Assert.AreEqual(new Duration { Seconds = 1 },
+ new Duration { Seconds = 1, Nanos = -500000000 } + new Duration { Nanos = 500000000 });
+
+ Assert.AreEqual(new Duration { Nanos = -900000000 },
+ new Duration { Seconds = -1, Nanos = -100000000 } + new Duration { Nanos = 200000000 });
+ Assert.AreEqual(new Duration { Nanos = 900000000 },
+ new Duration { Seconds = 1, Nanos = 100000000 } + new Duration { Nanos = -200000000 });
+ }
+
+ [Test]
+ public void Subtraction()
+ {
+ Assert.AreEqual(new Duration { Seconds = 1, Nanos = 100000000 },
+ new Duration { Seconds = 1, Nanos = 600000000 } - new Duration { Nanos = 500000000 });
+ Assert.AreEqual(new Duration { Seconds = -1, Nanos = -100000000 },
+ new Duration { Seconds = -1, Nanos = -600000000 } - new Duration { Nanos = -500000000 });
+ Assert.AreEqual(new Duration { Seconds = 2, Nanos = 100000000 },
+ new Duration { Seconds = 1, Nanos = 600000000 } - new Duration { Nanos = -500000000 });
+
+ // Non-normalized durations
+ Assert.AreEqual(new Duration(),
+ new Duration { Seconds = 1, Nanos = -500000000 } - new Duration { Nanos = 500000000 });
+ Assert.AreEqual(new Duration { Seconds = 1 },
+ new Duration { Nanos = 2000000000 } - new Duration { Nanos = 1000000000 });
+ }
+
+ [Test]
+ public void FromTimeSpan()
+ {
+ Assert.AreEqual(new Duration { Seconds = 1 }, Duration.FromTimeSpan(TimeSpan.FromSeconds(1)));
+ Assert.AreEqual(new Duration { Nanos = Duration.NanosecondsPerTick }, Duration.FromTimeSpan(TimeSpan.FromTicks(1)));
+ }
+
+ [Test]
+ [TestCase(0, Duration.MaxNanoseconds + 1)]
+ [TestCase(0, Duration.MinNanoseconds - 1)]
+ [TestCase(Duration.MinSeconds - 1, 0)]
+ [TestCase(Duration.MaxSeconds + 1, 0)]
+ [TestCase(1, -1)]
+ [TestCase(-1, 1)]
+ public void ToTimeSpan_Invalid(long seconds, int nanoseconds)
+ {
+ var duration = new Duration { Seconds = seconds, Nanos = nanoseconds };
+ Assert.Throws<InvalidOperationException>(() => duration.ToTimeSpan());
+ }
+
+ [Test]
+ [TestCase(0, Duration.MaxNanoseconds)]
+ [TestCase(0, Duration.MinNanoseconds)]
+ [TestCase(Duration.MinSeconds, Duration.MinNanoseconds)]
+ [TestCase(Duration.MaxSeconds, Duration.MaxNanoseconds)]
+ public void ToTimeSpan_Valid(long seconds, int nanoseconds)
+ {
+ // Only testing that these values don't throw, unlike their similar tests in ToTimeSpan_Invalid
+ var duration = new Duration { Seconds = seconds, Nanos = nanoseconds };
+ duration.ToTimeSpan();
+ }
+
+ [Test]
+ public void ToString_NonNormalized()
+ {
+ // Just a single example should be sufficient...
+ var duration = new Duration { Seconds = 1, Nanos = -1 };
+ Assert.AreEqual("{ \"@warning\": \"Invalid Duration\", \"seconds\": \"1\", \"nanos\": -1 }", duration.ToString());
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/FieldMaskTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/FieldMaskTest.cs
new file mode 100644
index 0000000000..1d9908b4d3
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/FieldMaskTest.cs
@@ -0,0 +1,62 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 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.
+#endregion
+
+
+using NUnit.Framework;
+
+namespace Google.Protobuf.WellKnownTypes
+{
+ public class FieldMaskTest
+ {
+ [Test]
+ [TestCase("foo__bar")]
+ [TestCase("foo_3_ar")]
+ [TestCase("fooBar")]
+ public void ToString_Invalid(string input)
+ {
+ var mask = new FieldMask { Paths = { input } };
+ var text = mask.ToString();
+ // More specific test below
+ Assert.That(text, Does.Contain("@warning"));
+ Assert.That(text, Does.Contain(input));
+ }
+
+ [Test]
+ public void ToString_Invalid_Precise()
+ {
+ var mask = new FieldMask { Paths = { "x", "foo__bar", @"x\y" } };
+ Assert.AreEqual(
+ "{ \"@warning\": \"Invalid FieldMask\", \"paths\": [ \"x\", \"foo__bar\", \"x\\\\y\" ] }",
+ mask.ToString());
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/TimestampTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/TimestampTest.cs
new file mode 100644
index 0000000000..9ecd24c62a
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/TimestampTest.cs
@@ -0,0 +1,115 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using NUnit.Framework;
+using System;
+
+namespace Google.Protobuf.WellKnownTypes
+{
+ public class TimestampTest
+ {
+ [Test]
+ public void FromAndToDateTime()
+ {
+ DateTime utcMin = DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc);
+ DateTime utcMax = DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Utc);
+ AssertRoundtrip(new Timestamp { Seconds = -62135596800 }, utcMin);
+ AssertRoundtrip(new Timestamp { Seconds = 253402300799, Nanos = 999999900 }, utcMax);
+ AssertRoundtrip(new Timestamp(), new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc));
+ AssertRoundtrip(new Timestamp { Nanos = 1000000}, new DateTime(1970, 1, 1, 0, 0, 0, 1, DateTimeKind.Utc));
+ AssertRoundtrip(new Timestamp { Seconds = -1, Nanos = 999000000 }, new DateTime(1969, 12, 31, 23, 59, 59, 999, DateTimeKind.Utc));
+ AssertRoundtrip(new Timestamp { Seconds = 3600 }, new DateTime(1970, 1, 1, 1, 0, 0, DateTimeKind.Utc));
+ AssertRoundtrip(new Timestamp { Seconds = -3600 }, new DateTime(1969, 12, 31, 23, 0, 0, DateTimeKind.Utc));
+ }
+
+ [Test]
+ public void ToDateTimeTruncation()
+ {
+ var t1 = new Timestamp { Seconds = 1, Nanos = 1000000 + Duration.NanosecondsPerTick - 1 };
+ Assert.AreEqual(new DateTime(1970, 1, 1, 0, 0, 1, DateTimeKind.Utc).AddMilliseconds(1), t1.ToDateTime());
+
+ var t2 = new Timestamp { Seconds = -1, Nanos = 1000000 + Duration.NanosecondsPerTick - 1 };
+ Assert.AreEqual(new DateTime(1969, 12, 31, 23, 59, 59).AddMilliseconds(1), t2.ToDateTime());
+ }
+
+ [Test]
+ [TestCase(Timestamp.UnixSecondsAtBclMinValue - 1, Timestamp.MaxNanos)]
+ [TestCase(Timestamp.UnixSecondsAtBclMaxValue + 1, 0)]
+ [TestCase(0, -1)]
+ [TestCase(0, Timestamp.MaxNanos + 1)]
+ public void ToDateTime_OutOfRange(long seconds, int nanoseconds)
+ {
+ var value = new Timestamp { Seconds = seconds, Nanos = nanoseconds };
+ Assert.Throws<InvalidOperationException>(() => value.ToDateTime());
+ }
+
+ // 1ns larger or smaller than the above values
+ [Test]
+ [TestCase(Timestamp.UnixSecondsAtBclMinValue, 0)]
+ [TestCase(Timestamp.UnixSecondsAtBclMaxValue, Timestamp.MaxNanos)]
+ [TestCase(0, 0)]
+ [TestCase(0, Timestamp.MaxNanos)]
+ public void ToDateTime_ValidBoundaries(long seconds, int nanoseconds)
+ {
+ var value = new Timestamp { Seconds = seconds, Nanos = nanoseconds };
+ value.ToDateTime();
+ }
+
+ private static void AssertRoundtrip(Timestamp timestamp, DateTime dateTime)
+ {
+ Assert.AreEqual(timestamp, Timestamp.FromDateTime(dateTime));
+ Assert.AreEqual(dateTime, timestamp.ToDateTime());
+ Assert.AreEqual(DateTimeKind.Utc, timestamp.ToDateTime().Kind);
+ }
+
+ [Test]
+ public void Arithmetic()
+ {
+ Timestamp t1 = new Timestamp { Seconds = 10000, Nanos = 5000 };
+ Timestamp t2 = new Timestamp { Seconds = 8000, Nanos = 10000 };
+ Duration difference = new Duration { Seconds = 1999, Nanos = Duration.NanosecondsPerSecond - 5000 };
+ Assert.AreEqual(difference, t1 - t2);
+ Assert.AreEqual(-difference, t2 - t1);
+
+ Assert.AreEqual(t1, t2 + difference);
+ Assert.AreEqual(t2, t1 - difference);
+ }
+
+ [Test]
+ public void ToString_NonNormalized()
+ {
+ // Just a single example should be sufficient...
+ var duration = new Timestamp { Seconds = 1, Nanos = -1 };
+ Assert.AreEqual("{ \"@warning\": \"Invalid Timestamp\", \"seconds\": \"1\", \"nanos\": -1 }", duration.ToString());
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs b/third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs
new file mode 100644
index 0000000000..5b7185dcd2
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs
@@ -0,0 +1,421 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using Google.Protobuf.TestProtos;
+using NUnit.Framework;
+using System.Collections;
+using System.IO;
+
+namespace Google.Protobuf.WellKnownTypes
+{
+ public class WrappersTest
+ {
+ [Test]
+ public void NullIsDefault()
+ {
+ var message = new TestWellKnownTypes();
+ Assert.IsNull(message.StringField);
+ Assert.IsNull(message.BytesField);
+ Assert.IsNull(message.BoolField);
+ Assert.IsNull(message.FloatField);
+ Assert.IsNull(message.DoubleField);
+ Assert.IsNull(message.Int32Field);
+ Assert.IsNull(message.Int64Field);
+ Assert.IsNull(message.Uint32Field);
+ Assert.IsNull(message.Uint64Field);
+ }
+
+ [Test]
+ public void NonDefaultSingleValues()
+ {
+ var message = new TestWellKnownTypes
+ {
+ StringField = "x",
+ BytesField = ByteString.CopyFrom(1, 2, 3),
+ BoolField = true,
+ FloatField = 12.5f,
+ DoubleField = 12.25d,
+ Int32Field = 1,
+ Int64Field = 2,
+ Uint32Field = 3,
+ Uint64Field = 4
+ };
+
+ var bytes = message.ToByteArray();
+ var parsed = TestWellKnownTypes.Parser.ParseFrom(bytes);
+
+ Assert.AreEqual("x", parsed.StringField);
+ Assert.AreEqual(ByteString.CopyFrom(1, 2, 3), parsed.BytesField);
+ Assert.AreEqual(true, parsed.BoolField);
+ Assert.AreEqual(12.5f, parsed.FloatField);
+ Assert.AreEqual(12.25d, parsed.DoubleField);
+ Assert.AreEqual(1, parsed.Int32Field);
+ Assert.AreEqual(2L, parsed.Int64Field);
+ Assert.AreEqual(3U, parsed.Uint32Field);
+ Assert.AreEqual(4UL, parsed.Uint64Field);
+ }
+
+ [Test]
+ public void NonNullDefaultIsPreservedThroughSerialization()
+ {
+ var message = new TestWellKnownTypes
+ {
+ StringField = "",
+ BytesField = ByteString.Empty,
+ BoolField = false,
+ FloatField = 0f,
+ DoubleField = 0d,
+ Int32Field = 0,
+ Int64Field = 0,
+ Uint32Field = 0,
+ Uint64Field = 0
+ };
+
+ var bytes = message.ToByteArray();
+ var parsed = TestWellKnownTypes.Parser.ParseFrom(bytes);
+
+ Assert.AreEqual("", parsed.StringField);
+ Assert.AreEqual(ByteString.Empty, parsed.BytesField);
+ Assert.AreEqual(false, parsed.BoolField);
+ Assert.AreEqual(0f, parsed.FloatField);
+ Assert.AreEqual(0d, parsed.DoubleField);
+ Assert.AreEqual(0, parsed.Int32Field);
+ Assert.AreEqual(0L, parsed.Int64Field);
+ Assert.AreEqual(0U, parsed.Uint32Field);
+ Assert.AreEqual(0UL, parsed.Uint64Field);
+ }
+
+ [Test]
+ public void RepeatedWrappersProhibitNullItems()
+ {
+ var message = new RepeatedWellKnownTypes();
+ Assert.Throws<ArgumentNullException>(() => message.BoolField.Add((bool?) null));
+ Assert.Throws<ArgumentNullException>(() => message.Int32Field.Add((int?) null));
+ Assert.Throws<ArgumentNullException>(() => message.StringField.Add((string) null));
+ Assert.Throws<ArgumentNullException>(() => message.BytesField.Add((ByteString) null));
+ }
+
+ [Test]
+ public void RepeatedWrappersSerializeDeserialize()
+ {
+ var message = new RepeatedWellKnownTypes
+ {
+ BoolField = { true, false },
+ BytesField = { ByteString.CopyFrom(1, 2, 3), ByteString.CopyFrom(4, 5, 6), ByteString.Empty },
+ DoubleField = { 12.5, -1.5, 0d },
+ FloatField = { 123.25f, -20f, 0f },
+ Int32Field = { int.MaxValue, int.MinValue, 0 },
+ Int64Field = { long.MaxValue, long.MinValue, 0L },
+ StringField = { "First", "Second", "" },
+ Uint32Field = { uint.MaxValue, uint.MinValue, 0U },
+ Uint64Field = { ulong.MaxValue, ulong.MinValue, 0UL },
+ };
+ var bytes = message.ToByteArray();
+ var parsed = RepeatedWellKnownTypes.Parser.ParseFrom(bytes);
+
+ Assert.AreEqual(message, parsed);
+ // Just to test a single value for sanity...
+ Assert.AreEqual("Second", message.StringField[1]);
+ }
+
+ [Test]
+ public void RepeatedWrappersBinaryFormat()
+ {
+ // At one point we accidentally used a packed format for repeated wrappers, which is wrong (and weird).
+ // This test is just to prove that we use the right format.
+
+ var rawOutput = new MemoryStream();
+ var output = new CodedOutputStream(rawOutput);
+ // Write a value of 5
+ output.WriteTag(RepeatedWellKnownTypes.Int32FieldFieldNumber, WireFormat.WireType.LengthDelimited);
+ output.WriteLength(2);
+ output.WriteTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Varint);
+ output.WriteInt32(5);
+ // Write a value of 0 (empty message)
+ output.WriteTag(RepeatedWellKnownTypes.Int32FieldFieldNumber, WireFormat.WireType.LengthDelimited);
+ output.WriteLength(0);
+ output.Flush();
+ var expectedBytes = rawOutput.ToArray();
+
+ var message = new RepeatedWellKnownTypes { Int32Field = { 5, 0 } };
+ var actualBytes = message.ToByteArray();
+ Assert.AreEqual(expectedBytes, actualBytes);
+ }
+
+ [Test]
+ public void MapWrappersSerializeDeserialize()
+ {
+ // Note: no null values here, as they are prohibited in map fields
+ // (despite being representable).
+ var message = new MapWellKnownTypes
+ {
+ BoolField = { { 10, false }, { 20, true } },
+ BytesField = {
+ { -1, ByteString.CopyFrom(1, 2, 3) },
+ { 10, ByteString.CopyFrom(4, 5, 6) },
+ { 1000, ByteString.Empty },
+ },
+ DoubleField = { { 1, 12.5 }, { 10, -1.5 }, { 20, 0d } },
+ FloatField = { { 2, 123.25f }, { 3, -20f }, { 4, 0f } },
+ Int32Field = { { 5, int.MaxValue }, { 6, int.MinValue }, { 7, 0 } },
+ Int64Field = { { 8, long.MaxValue }, { 9, long.MinValue }, { 10, 0L } },
+ StringField = { { 11, "First" }, { 12, "Second" }, { 13, "" } },
+ Uint32Field = { { 15, uint.MaxValue }, { 16, uint.MinValue }, { 17, 0U } },
+ Uint64Field = { { 18, ulong.MaxValue }, { 19, ulong.MinValue }, { 20, 0UL } },
+ };
+
+ var bytes = message.ToByteArray();
+ var parsed = MapWellKnownTypes.Parser.ParseFrom(bytes);
+
+ Assert.AreEqual(message, parsed);
+ // Just to test a single value for sanity...
+ Assert.AreEqual("Second", message.StringField[12]);
+ }
+
+ [Test]
+ public void Reflection_SingleValues()
+ {
+ var message = new TestWellKnownTypes
+ {
+ StringField = "x",
+ BytesField = ByteString.CopyFrom(1, 2, 3),
+ BoolField = true,
+ FloatField = 12.5f,
+ DoubleField = 12.25d,
+ Int32Field = 1,
+ Int64Field = 2,
+ Uint32Field = 3,
+ Uint64Field = 4
+ };
+ var fields = TestWellKnownTypes.Descriptor.Fields;
+
+ Assert.AreEqual("x", fields[TestWellKnownTypes.StringFieldFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(ByteString.CopyFrom(1, 2, 3), fields[TestWellKnownTypes.BytesFieldFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(true, fields[TestWellKnownTypes.BoolFieldFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(12.5f, fields[TestWellKnownTypes.FloatFieldFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(12.25d, fields[TestWellKnownTypes.DoubleFieldFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(1, fields[TestWellKnownTypes.Int32FieldFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(2L, fields[TestWellKnownTypes.Int64FieldFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(3U, fields[TestWellKnownTypes.Uint32FieldFieldNumber].Accessor.GetValue(message));
+ Assert.AreEqual(4UL, fields[TestWellKnownTypes.Uint64FieldFieldNumber].Accessor.GetValue(message));
+
+ // And a couple of null fields...
+ message.StringField = null;
+ message.FloatField = null;
+ Assert.IsNull(fields[TestWellKnownTypes.StringFieldFieldNumber].Accessor.GetValue(message));
+ Assert.IsNull(fields[TestWellKnownTypes.FloatFieldFieldNumber].Accessor.GetValue(message));
+ }
+
+ [Test]
+ public void Reflection_RepeatedFields()
+ {
+ // Just a single example... note that we can't have a null value here
+ var message = new RepeatedWellKnownTypes { Int32Field = { 1, 2 } };
+ var fields = RepeatedWellKnownTypes.Descriptor.Fields;
+ var list = (IList) fields[RepeatedWellKnownTypes.Int32FieldFieldNumber].Accessor.GetValue(message);
+ CollectionAssert.AreEqual(new[] { 1, 2 }, list);
+ }
+
+ [Test]
+ public void Reflection_MapFields()
+ {
+ // Just a single example... note that we can't have a null value here despite the value type being int?
+ var message = new MapWellKnownTypes { Int32Field = { { 1, 2 } } };
+ var fields = MapWellKnownTypes.Descriptor.Fields;
+ var dictionary = (IDictionary) fields[MapWellKnownTypes.Int32FieldFieldNumber].Accessor.GetValue(message);
+ Assert.AreEqual(2, dictionary[1]);
+ }
+
+ [Test]
+ public void Oneof()
+ {
+ var message = new OneofWellKnownTypes { EmptyField = new Empty() };
+ // Start off with a non-wrapper
+ Assert.AreEqual(OneofWellKnownTypes.OneofFieldOneofCase.EmptyField, message.OneofFieldCase);
+ AssertOneofRoundTrip(message);
+
+ message.StringField = "foo";
+ Assert.AreEqual(OneofWellKnownTypes.OneofFieldOneofCase.StringField, message.OneofFieldCase);
+ AssertOneofRoundTrip(message);
+
+ message.StringField = "foo";
+ Assert.AreEqual(OneofWellKnownTypes.OneofFieldOneofCase.StringField, message.OneofFieldCase);
+ AssertOneofRoundTrip(message);
+
+ message.DoubleField = 0.0f;
+ Assert.AreEqual(OneofWellKnownTypes.OneofFieldOneofCase.DoubleField, message.OneofFieldCase);
+ AssertOneofRoundTrip(message);
+
+ message.DoubleField = 1.0f;
+ Assert.AreEqual(OneofWellKnownTypes.OneofFieldOneofCase.DoubleField, message.OneofFieldCase);
+ AssertOneofRoundTrip(message);
+
+ message.ClearOneofField();
+ Assert.AreEqual(OneofWellKnownTypes.OneofFieldOneofCase.None, message.OneofFieldCase);
+ AssertOneofRoundTrip(message);
+ }
+
+ private void AssertOneofRoundTrip(OneofWellKnownTypes message)
+ {
+ // Normal roundtrip, but explicitly checking the case...
+ var bytes = message.ToByteArray();
+ var parsed = OneofWellKnownTypes.Parser.ParseFrom(bytes);
+ Assert.AreEqual(message, parsed);
+ Assert.AreEqual(message.OneofFieldCase, parsed.OneofFieldCase);
+ }
+
+ [Test]
+ [TestCase("x", "y", "y")]
+ [TestCase("x", "", "x")]
+ [TestCase("x", null, "x")]
+ [TestCase("", "y", "y")]
+ [TestCase("", "", "")]
+ [TestCase("", null, "")]
+ [TestCase(null, "y", "y")]
+ [TestCase(null, "", "")]
+ [TestCase(null, null, null)]
+ public void Merging(string original, string merged, string expected)
+ {
+ var originalMessage = new TestWellKnownTypes { StringField = original };
+ var mergingMessage = new TestWellKnownTypes { StringField = merged };
+ originalMessage.MergeFrom(mergingMessage);
+ Assert.AreEqual(expected, originalMessage.StringField);
+
+ // Try it using MergeFrom(CodedInputStream) too...
+ originalMessage = new TestWellKnownTypes { StringField = original };
+ originalMessage.MergeFrom(mergingMessage.ToByteArray());
+ Assert.AreEqual(expected, originalMessage.StringField);
+ }
+
+ // Merging is odd with wrapper types, due to the way that default values aren't emitted in
+ // the binary stream. In fact we cheat a little bit - a message with an explicitly present default
+ // value will have that default value ignored. See issue 615. Fixing this would require significant upheaval to
+ // the FieldCodec side of things.
+ [Test]
+ public void MergingStreamExplicitValue()
+ {
+ var message = new TestWellKnownTypes { Int32Field = 5 };
+
+ // Create a byte array which has the data of an Int32Value explicitly containing a value of 0.
+ // This wouldn't normally happen.
+ byte[] bytes;
+ var wrapperTag = WireFormat.MakeTag(TestWellKnownTypes.Int32FieldFieldNumber, WireFormat.WireType.LengthDelimited);
+ var valueTag = WireFormat.MakeTag(Int32Value.ValueFieldNumber, WireFormat.WireType.Varint);
+ using (var stream = new MemoryStream())
+ {
+ var coded = new CodedOutputStream(stream);
+ coded.WriteTag(wrapperTag);
+ coded.WriteLength(2); // valueTag + a value 0, each one byte
+ coded.WriteTag(valueTag);
+ coded.WriteInt32(0);
+ coded.Flush();
+ bytes = stream.ToArray();
+ }
+
+ message.MergeFrom(bytes);
+ // A normal implementation would have 0 now, as the explicit default would have been overwritten the 5.
+ // With the FieldCodec for Nullable<int>, we can't tell the difference between an implicit 0 and an explicit 0.
+ Assert.AreEqual(5, message.Int32Field);
+ }
+
+ [Test]
+ public void MergingStreamNoValue()
+ {
+ var message = new TestWellKnownTypes { Int32Field = 5 };
+
+ // Create a byte array which an Int32 field, but with no value.
+ var bytes = new TestWellKnownTypes { Int32Field = 0 }.ToByteArray();
+ Assert.AreEqual(2, bytes.Length); // The tag for Int32Field is a single byte, then a byte indicating a 0-length message.
+ message.MergeFrom(bytes);
+
+ // The "implicit" 0 did *not* overwrite the value.
+ // (This is the correct behaviour.)
+ Assert.AreEqual(5, message.Int32Field);
+ }
+
+ // All permutations of origin/merging value being null, zero (default) or non-default.
+ // As this is the in-memory version, we don't need to worry about the difference between implicit and explicit 0.
+ [Test]
+ [TestCase(null, null, null)]
+ [TestCase(null, 0, 0)]
+ [TestCase(null, 5, 5)]
+ [TestCase(0, null, 0)]
+ [TestCase(0, 0, 0)]
+ [TestCase(0, 5, 5)]
+ [TestCase(5, null, 5)]
+ [TestCase(5, 0, 5)]
+ [TestCase(5, 10, 10)]
+ public void MergingMessageWithZero(int? originValue, int? mergingValue, int? expectedResult)
+ {
+ // This differs from the MergingStreamCornerCase because when we merge message *objects*,
+ // we ignore default values from the "source".
+ var message1 = new TestWellKnownTypes { Int32Field = originValue };
+ var message2 = new TestWellKnownTypes { Int32Field = mergingValue };
+ message1.MergeFrom(message2);
+ Assert.AreEqual(expectedResult, message1.Int32Field);
+ }
+
+ [Test]
+ public void UnknownFieldInWrapper()
+ {
+ var stream = new MemoryStream();
+ var output = new CodedOutputStream(stream);
+ var wrapperTag = WireFormat.MakeTag(TestWellKnownTypes.Int32FieldFieldNumber, WireFormat.WireType.LengthDelimited);
+ var unknownTag = WireFormat.MakeTag(15, WireFormat.WireType.Varint);
+ var valueTag = WireFormat.MakeTag(Int32Value.ValueFieldNumber, WireFormat.WireType.Varint);
+
+ output.WriteTag(wrapperTag);
+ output.WriteLength(4); // unknownTag + value 5 + valueType + value 6, each 1 byte
+ output.WriteTag(unknownTag);
+ output.WriteInt32((int) valueTag); // Sneakily "pretend" it's a tag when it's really a value
+ output.WriteTag(valueTag);
+ output.WriteInt32(6);
+
+ output.Flush();
+ stream.Position = 0;
+
+ var message = TestWellKnownTypes.Parser.ParseFrom(stream);
+ Assert.AreEqual(6, message.Int32Field);
+ }
+
+ [Test]
+ public void ClearWithReflection()
+ {
+ // String and Bytes are the tricky ones here, as the CLR type of the property
+ // is the same between the wrapper and non-wrapper types.
+ var message = new TestWellKnownTypes { StringField = "foo" };
+ TestWellKnownTypes.Descriptor.Fields[TestWellKnownTypes.StringFieldFieldNumber].Accessor.Clear(message);
+ Assert.IsNull(message.StringField);
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.Test/project.json b/third_party/protobuf/csharp/src/Google.Protobuf.Test/project.json
new file mode 100644
index 0000000000..dff0ab7309
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.Test/project.json
@@ -0,0 +1,45 @@
+{
+ "buildOptions": {
+ "debugType": "portable",
+ "keyFile": "../../keys/Google.Protobuf.snk"
+ },
+
+ "configurations": {
+ "Debug": {
+ "buildOptions": {
+ "define": [ "DEBUG", "TRACE" ]
+ }
+ },
+ "Release": {
+ "buildOptions": {
+ "define": [ "RELEASE", "TRACE" ],
+ "optimize": true
+ }
+ }
+ },
+
+ "dependencies": {
+ "Google.Protobuf": { "target": "project" },
+ "dotnet-test-nunit": "3.4.0-beta-3",
+ "NUnit": "3.6.0"
+ },
+
+ "testRunner": "nunit",
+
+ "frameworks": {
+ "net451": {},
+ "netcoreapp1.0": {
+ "imports" : [ "dnxcore50", "netcoreapp1.0", "portable-net45+win8" ],
+ "buildOptions": {
+ "define": [ "PCL" ]
+ },
+ "dependencies": {
+ "Microsoft.NETCore.App": {
+ "version": "1.0.0",
+ "type": "platform"
+ },
+ "System.Console": "4.0.0"
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf.sln b/third_party/protobuf/csharp/src/Google.Protobuf.sln
new file mode 100644
index 0000000000..3c62bba334
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf.sln
@@ -0,0 +1,45 @@
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.25420.1
+MinimumVisualStudioVersion = 14.0.24720.0
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "AddressBook", "AddressBook\AddressBook.xproj", "{AFB63919-1E05-43B4-802A-8FB8C9B2F463}"
+EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Google.Protobuf", "Google.Protobuf\Google.Protobuf.xproj", "{9B576380-726D-4142-8238-60A43AB0E35A}"
+EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Google.Protobuf.Test", "Google.Protobuf.Test\Google.Protobuf.Test.xproj", "{580EB013-D3C7-4578-B845-015F4A3B0591}"
+EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Google.Protobuf.Conformance", "Google.Protobuf.Conformance\Google.Protobuf.Conformance.xproj", "{DDDC055B-E185-4181-BAB0-072F0F984569}"
+EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Google.Protobuf.JsonDump", "Google.Protobuf.JsonDump\Google.Protobuf.JsonDump.xproj", "{9695E08F-9829-497D-B95C-B38F28D48690}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {AFB63919-1E05-43B4-802A-8FB8C9B2F463}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {AFB63919-1E05-43B4-802A-8FB8C9B2F463}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {AFB63919-1E05-43B4-802A-8FB8C9B2F463}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {AFB63919-1E05-43B4-802A-8FB8C9B2F463}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9B576380-726D-4142-8238-60A43AB0E35A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9B576380-726D-4142-8238-60A43AB0E35A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9B576380-726D-4142-8238-60A43AB0E35A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9B576380-726D-4142-8238-60A43AB0E35A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {580EB013-D3C7-4578-B845-015F4A3B0591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {580EB013-D3C7-4578-B845-015F4A3B0591}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {580EB013-D3C7-4578-B845-015F4A3B0591}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {580EB013-D3C7-4578-B845-015F4A3B0591}.Release|Any CPU.Build.0 = Release|Any CPU
+ {DDDC055B-E185-4181-BAB0-072F0F984569}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {DDDC055B-E185-4181-BAB0-072F0F984569}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {DDDC055B-E185-4181-BAB0-072F0F984569}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {DDDC055B-E185-4181-BAB0-072F0F984569}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9695E08F-9829-497D-B95C-B38F28D48690}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9695E08F-9829-497D-B95C-B38F28D48690}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9695E08F-9829-497D-B95C-B38F28D48690}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9695E08F-9829-497D-B95C-B38F28D48690}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/ByteArray.cs b/third_party/protobuf/csharp/src/Google.Protobuf/ByteArray.cs
new file mode 100644
index 0000000000..69b6ef8d63
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/ByteArray.cs
@@ -0,0 +1,79 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Provides a utility routine to copy small arrays much more quickly than Buffer.BlockCopy
+ /// </summary>
+ internal static class ByteArray
+ {
+ /// <summary>
+ /// The threshold above which you should use Buffer.BlockCopy rather than ByteArray.Copy
+ /// </summary>
+ private const int CopyThreshold = 12;
+
+ /// <summary>
+ /// Determines which copy routine to use based on the number of bytes to be copied.
+ /// </summary>
+ internal static void Copy(byte[] src, int srcOffset, byte[] dst, int dstOffset, int count)
+ {
+ if (count > CopyThreshold)
+ {
+ Buffer.BlockCopy(src, srcOffset, dst, dstOffset, count);
+ }
+ else
+ {
+ int stop = srcOffset + count;
+ for (int i = srcOffset; i < stop; i++)
+ {
+ dst[dstOffset++] = src[i];
+ }
+ }
+ }
+
+ /// <summary>
+ /// Reverses the order of bytes in the array
+ /// </summary>
+ internal static void Reverse(byte[] bytes)
+ {
+ for (int first = 0, last = bytes.Length - 1; first < last; first++, last--)
+ {
+ byte temp = bytes[first];
+ bytes[first] = bytes[last];
+ bytes[last] = temp;
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/ByteString.cs b/third_party/protobuf/csharp/src/Google.Protobuf/ByteString.cs
new file mode 100755
index 0000000000..4abdb7182c
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/ByteString.cs
@@ -0,0 +1,401 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+#if !NET35
+using System.Threading;
+using System.Threading.Tasks;
+#endif
+#if NET35
+using Google.Protobuf.Compatibility;
+#endif
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Immutable array of bytes.
+ /// </summary>
+ public sealed class ByteString : IEnumerable<byte>, IEquatable<ByteString>
+ {
+ private static readonly ByteString empty = new ByteString(new byte[0]);
+
+ private readonly byte[] bytes;
+
+ /// <summary>
+ /// Unsafe operations that can cause IO Failure and/or other catestrophic side-effects.
+ /// </summary>
+ internal static class Unsafe
+ {
+ /// <summary>
+ /// Constructs a new ByteString from the given byte array. The array is
+ /// *not* copied, and must not be modified after this constructor is called.
+ /// </summary>
+ internal static ByteString FromBytes(byte[] bytes)
+ {
+ return new ByteString(bytes);
+ }
+
+ /// <summary>
+ /// Provides direct, unrestricted access to the bytes contained in this instance.
+ /// You must not modify or resize the byte array returned by this method.
+ /// </summary>
+ internal static byte[] GetBuffer(ByteString bytes)
+ {
+ return bytes.bytes;
+ }
+ }
+
+ /// <summary>
+ /// Internal use only. Ensure that the provided array is not mutated and belongs to this instance.
+ /// </summary>
+ internal static ByteString AttachBytes(byte[] bytes)
+ {
+ return new ByteString(bytes);
+ }
+
+ /// <summary>
+ /// Constructs a new ByteString from the given byte array. The array is
+ /// *not* copied, and must not be modified after this constructor is called.
+ /// </summary>
+ private ByteString(byte[] bytes)
+ {
+ this.bytes = bytes;
+ }
+
+ /// <summary>
+ /// Returns an empty ByteString.
+ /// </summary>
+ public static ByteString Empty
+ {
+ get { return empty; }
+ }
+
+ /// <summary>
+ /// Returns the length of this ByteString in bytes.
+ /// </summary>
+ public int Length
+ {
+ get { return bytes.Length; }
+ }
+
+ /// <summary>
+ /// Returns <c>true</c> if this byte string is empty, <c>false</c> otherwise.
+ /// </summary>
+ public bool IsEmpty
+ {
+ get { return Length == 0; }
+ }
+
+ /// <summary>
+ /// Converts this <see cref="ByteString"/> into a byte array.
+ /// </summary>
+ /// <remarks>The data is copied - changes to the returned array will not be reflected in this <c>ByteString</c>.</remarks>
+ /// <returns>A byte array with the same data as this <c>ByteString</c>.</returns>
+ public byte[] ToByteArray()
+ {
+ return (byte[]) bytes.Clone();
+ }
+
+ /// <summary>
+ /// Converts this <see cref="ByteString"/> into a standard base64 representation.
+ /// </summary>
+ /// <returns>A base64 representation of this <c>ByteString</c>.</returns>
+ public string ToBase64()
+ {
+ return Convert.ToBase64String(bytes);
+ }
+
+ /// <summary>
+ /// Constructs a <see cref="ByteString" /> from the Base64 Encoded String.
+ /// </summary>
+ public static ByteString FromBase64(string bytes)
+ {
+ // By handling the empty string explicitly, we not only optimize but we fix a
+ // problem on CF 2.0. See issue 61 for details.
+ return bytes == "" ? Empty : new ByteString(Convert.FromBase64String(bytes));
+ }
+
+ /// <summary>
+ /// Constructs a <see cref="ByteString"/> from data in the given stream, synchronously.
+ /// </summary>
+ /// <remarks>If successful, <paramref name="stream"/> will be read completely, from the position
+ /// at the start of the call.</remarks>
+ /// <param name="stream">The stream to copy into a ByteString.</param>
+ /// <returns>A ByteString with content read from the given stream.</returns>
+ public static ByteString FromStream(Stream stream)
+ {
+ ProtoPreconditions.CheckNotNull(stream, nameof(stream));
+ int capacity = stream.CanSeek ? checked((int) (stream.Length - stream.Position)) : 0;
+ var memoryStream = new MemoryStream(capacity);
+ stream.CopyTo(memoryStream);
+#if NETSTANDARD1_0
+ byte[] bytes = memoryStream.ToArray();
+#else
+ // Avoid an extra copy if we can.
+ byte[] bytes = memoryStream.Length == memoryStream.Capacity ? memoryStream.GetBuffer() : memoryStream.ToArray();
+#endif
+ return AttachBytes(bytes);
+ }
+
+#if !NET35
+ /// <summary>
+ /// Constructs a <see cref="ByteString"/> from data in the given stream, asynchronously.
+ /// </summary>
+ /// <remarks>If successful, <paramref name="stream"/> will be read completely, from the position
+ /// at the start of the call.</remarks>
+ /// <param name="stream">The stream to copy into a ByteString.</param>
+ /// <param name="cancellationToken">The cancellation token to use when reading from the stream, if any.</param>
+ /// <returns>A ByteString with content read from the given stream.</returns>
+ public async static Task<ByteString> FromStreamAsync(Stream stream, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ ProtoPreconditions.CheckNotNull(stream, nameof(stream));
+ int capacity = stream.CanSeek ? checked((int) (stream.Length - stream.Position)) : 0;
+ var memoryStream = new MemoryStream(capacity);
+ // We have to specify the buffer size here, as there's no overload accepting the cancellation token
+ // alone. But it's documented to use 81920 by default if not specified.
+ await stream.CopyToAsync(memoryStream, 81920, cancellationToken);
+#if NETSTANDARD1_0
+ byte[] bytes = memoryStream.ToArray();
+#else
+ // Avoid an extra copy if we can.
+ byte[] bytes = memoryStream.Length == memoryStream.Capacity ? memoryStream.GetBuffer() : memoryStream.ToArray();
+#endif
+ return AttachBytes(bytes);
+ }
+#endif
+
+ /// <summary>
+ /// Constructs a <see cref="ByteString" /> from the given array. The contents
+ /// are copied, so further modifications to the array will not
+ /// be reflected in the returned ByteString.
+ /// This method can also be invoked in <c>ByteString.CopyFrom(0xaa, 0xbb, ...)</c> form
+ /// which is primarily useful for testing.
+ /// </summary>
+ public static ByteString CopyFrom(params byte[] bytes)
+ {
+ return new ByteString((byte[]) bytes.Clone());
+ }
+
+ /// <summary>
+ /// Constructs a <see cref="ByteString" /> from a portion of a byte array.
+ /// </summary>
+ public static ByteString CopyFrom(byte[] bytes, int offset, int count)
+ {
+ byte[] portion = new byte[count];
+ ByteArray.Copy(bytes, offset, portion, 0, count);
+ return new ByteString(portion);
+ }
+
+ /// <summary>
+ /// Creates a new <see cref="ByteString" /> by encoding the specified text with
+ /// the given encoding.
+ /// </summary>
+ public static ByteString CopyFrom(string text, Encoding encoding)
+ {
+ return new ByteString(encoding.GetBytes(text));
+ }
+
+ /// <summary>
+ /// Creates a new <see cref="ByteString" /> by encoding the specified text in UTF-8.
+ /// </summary>
+ public static ByteString CopyFromUtf8(string text)
+ {
+ return CopyFrom(text, Encoding.UTF8);
+ }
+
+ /// <summary>
+ /// Retuns the byte at the given index.
+ /// </summary>
+ public byte this[int index]
+ {
+ get { return bytes[index]; }
+ }
+
+ /// <summary>
+ /// Converts this <see cref="ByteString"/> into a string by applying the given encoding.
+ /// </summary>
+ /// <remarks>
+ /// This method should only be used to convert binary data which was the result of encoding
+ /// text with the given encoding.
+ /// </remarks>
+ /// <param name="encoding">The encoding to use to decode the binary data into text.</param>
+ /// <returns>The result of decoding the binary data with the given decoding.</returns>
+ public string ToString(Encoding encoding)
+ {
+ return encoding.GetString(bytes, 0, bytes.Length);
+ }
+
+ /// <summary>
+ /// Converts this <see cref="ByteString"/> into a string by applying the UTF-8 encoding.
+ /// </summary>
+ /// <remarks>
+ /// This method should only be used to convert binary data which was the result of encoding
+ /// text with UTF-8.
+ /// </remarks>
+ /// <returns>The result of decoding the binary data with the given decoding.</returns>
+ public string ToStringUtf8()
+ {
+ return ToString(Encoding.UTF8);
+ }
+
+ /// <summary>
+ /// Returns an iterator over the bytes in this <see cref="ByteString"/>.
+ /// </summary>
+ /// <returns>An iterator over the bytes in this object.</returns>
+ public IEnumerator<byte> GetEnumerator()
+ {
+ return ((IEnumerable<byte>) bytes).GetEnumerator();
+ }
+
+ /// <summary>
+ /// Returns an iterator over the bytes in this <see cref="ByteString"/>.
+ /// </summary>
+ /// <returns>An iterator over the bytes in this object.</returns>
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ /// <summary>
+ /// Creates a CodedInputStream from this ByteString's data.
+ /// </summary>
+ public CodedInputStream CreateCodedInput()
+ {
+ // We trust CodedInputStream not to reveal the provided byte array or modify it
+ return new CodedInputStream(bytes);
+ }
+
+ /// <summary>
+ /// Compares two byte strings for equality.
+ /// </summary>
+ /// <param name="lhs">The first byte string to compare.</param>
+ /// <param name="rhs">The second byte string to compare.</param>
+ /// <returns><c>true</c> if the byte strings are equal; false otherwise.</returns>
+ public static bool operator ==(ByteString lhs, ByteString rhs)
+ {
+ if (ReferenceEquals(lhs, rhs))
+ {
+ return true;
+ }
+ if (ReferenceEquals(lhs, null) || ReferenceEquals(rhs, null))
+ {
+ return false;
+ }
+ if (lhs.bytes.Length != rhs.bytes.Length)
+ {
+ return false;
+ }
+ for (int i = 0; i < lhs.Length; i++)
+ {
+ if (rhs.bytes[i] != lhs.bytes[i])
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /// <summary>
+ /// Compares two byte strings for inequality.
+ /// </summary>
+ /// <param name="lhs">The first byte string to compare.</param>
+ /// <param name="rhs">The second byte string to compare.</param>
+ /// <returns><c>false</c> if the byte strings are equal; true otherwise.</returns>
+ public static bool operator !=(ByteString lhs, ByteString rhs)
+ {
+ return !(lhs == rhs);
+ }
+
+ /// <summary>
+ /// Compares this byte string with another object.
+ /// </summary>
+ /// <param name="obj">The object to compare this with.</param>
+ /// <returns><c>true</c> if <paramref name="obj"/> refers to an equal <see cref="ByteString"/>; <c>false</c> otherwise.</returns>
+ public override bool Equals(object obj)
+ {
+ return this == (obj as ByteString);
+ }
+
+ /// <summary>
+ /// Returns a hash code for this object. Two equal byte strings
+ /// will return the same hash code.
+ /// </summary>
+ /// <returns>A hash code for this object.</returns>
+ public override int GetHashCode()
+ {
+ int ret = 23;
+ foreach (byte b in bytes)
+ {
+ ret = (ret * 31) + b;
+ }
+ return ret;
+ }
+
+ /// <summary>
+ /// Compares this byte string with another.
+ /// </summary>
+ /// <param name="other">The <see cref="ByteString"/> to compare this with.</param>
+ /// <returns><c>true</c> if <paramref name="other"/> refers to an equal byte string; <c>false</c> otherwise.</returns>
+ public bool Equals(ByteString other)
+ {
+ return this == other;
+ }
+
+ /// <summary>
+ /// Used internally by CodedOutputStream to avoid creating a copy for the write
+ /// </summary>
+ internal void WriteRawBytesTo(CodedOutputStream outputStream)
+ {
+ outputStream.WriteRawBytes(bytes, 0, bytes.Length);
+ }
+
+ /// <summary>
+ /// Copies the entire byte array to the destination array provided at the offset specified.
+ /// </summary>
+ public void CopyTo(byte[] array, int position)
+ {
+ ByteArray.Copy(bytes, 0, array, position, bytes.Length);
+ }
+
+ /// <summary>
+ /// Writes the entire byte array to the provided stream
+ /// </summary>
+ public void WriteTo(Stream outputStream)
+ {
+ outputStream.Write(bytes, 0, bytes.Length);
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/CodedInputStream.cs b/third_party/protobuf/csharp/src/Google.Protobuf/CodedInputStream.cs
new file mode 100644
index 0000000000..072e2e17c9
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/CodedInputStream.cs
@@ -0,0 +1,1275 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using Google.Protobuf.Collections;
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Reads and decodes protocol message fields.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// This class is generally used by generated code to read appropriate
+ /// primitives from the stream. It effectively encapsulates the lowest
+ /// levels of protocol buffer format.
+ /// </para>
+ /// <para>
+ /// Repeated fields and map fields are not handled by this class; use <see cref="RepeatedField{T}"/>
+ /// and <see cref="MapField{TKey, TValue}"/> to serialize such fields.
+ /// </para>
+ /// </remarks>
+ public sealed class CodedInputStream : IDisposable
+ {
+ /// <summary>
+ /// Whether to leave the underlying stream open when disposing of this stream.
+ /// This is always true when there's no stream.
+ /// </summary>
+ private readonly bool leaveOpen;
+
+ /// <summary>
+ /// Buffer of data read from the stream or provided at construction time.
+ /// </summary>
+ private readonly byte[] buffer;
+
+ /// <summary>
+ /// The index of the buffer at which we need to refill from the stream (if there is one).
+ /// </summary>
+ private int bufferSize;
+
+ private int bufferSizeAfterLimit = 0;
+ /// <summary>
+ /// The position within the current buffer (i.e. the next byte to read)
+ /// </summary>
+ private int bufferPos = 0;
+
+ /// <summary>
+ /// The stream to read further input from, or null if the byte array buffer was provided
+ /// directly on construction, with no further data available.
+ /// </summary>
+ private readonly Stream input;
+
+ /// <summary>
+ /// The last tag we read. 0 indicates we've read to the end of the stream
+ /// (or haven't read anything yet).
+ /// </summary>
+ private uint lastTag = 0;
+
+ /// <summary>
+ /// The next tag, used to store the value read by PeekTag.
+ /// </summary>
+ private uint nextTag = 0;
+ private bool hasNextTag = false;
+
+ internal const int DefaultRecursionLimit = 64;
+ internal const int DefaultSizeLimit = 64 << 20; // 64MB
+ internal const int BufferSize = 4096;
+
+ /// <summary>
+ /// The total number of bytes read before the current buffer. The
+ /// total bytes read up to the current position can be computed as
+ /// totalBytesRetired + bufferPos.
+ /// </summary>
+ private int totalBytesRetired = 0;
+
+ /// <summary>
+ /// The absolute position of the end of the current message.
+ /// </summary>
+ private int currentLimit = int.MaxValue;
+
+ private int recursionDepth = 0;
+
+ private readonly int recursionLimit;
+ private readonly int sizeLimit;
+
+ #region Construction
+ // Note that the checks are performed such that we don't end up checking obviously-valid things
+ // like non-null references for arrays we've just created.
+
+ /// <summary>
+ /// Creates a new CodedInputStream reading data from the given byte array.
+ /// </summary>
+ public CodedInputStream(byte[] buffer) : this(null, ProtoPreconditions.CheckNotNull(buffer, "buffer"), 0, buffer.Length)
+ {
+ }
+
+ /// <summary>
+ /// Creates a new <see cref="CodedInputStream"/> that reads from the given byte array slice.
+ /// </summary>
+ public CodedInputStream(byte[] buffer, int offset, int length)
+ : this(null, ProtoPreconditions.CheckNotNull(buffer, "buffer"), offset, offset + length)
+ {
+ if (offset < 0 || offset > buffer.Length)
+ {
+ throw new ArgumentOutOfRangeException("offset", "Offset must be within the buffer");
+ }
+ if (length < 0 || offset + length > buffer.Length)
+ {
+ throw new ArgumentOutOfRangeException("length", "Length must be non-negative and within the buffer");
+ }
+ }
+
+ /// <summary>
+ /// Creates a new <see cref="CodedInputStream"/> reading data from the given stream, which will be disposed
+ /// when the returned object is disposed.
+ /// </summary>
+ /// <param name="input">The stream to read from.</param>
+ public CodedInputStream(Stream input) : this(input, false)
+ {
+ }
+
+ /// <summary>
+ /// Creates a new <see cref="CodedInputStream"/> reading data from the given stream.
+ /// </summary>
+ /// <param name="input">The stream to read from.</param>
+ /// <param name="leaveOpen"><c>true</c> to leave <paramref name="input"/> open when the returned
+ /// <c cref="CodedInputStream"/> is disposed; <c>false</c> to dispose of the given stream when the
+ /// returned object is disposed.</param>
+ public CodedInputStream(Stream input, bool leaveOpen)
+ : this(ProtoPreconditions.CheckNotNull(input, "input"), new byte[BufferSize], 0, 0)
+ {
+ this.leaveOpen = leaveOpen;
+ }
+
+ /// <summary>
+ /// Creates a new CodedInputStream reading data from the given
+ /// stream and buffer, using the default limits.
+ /// </summary>
+ internal CodedInputStream(Stream input, byte[] buffer, int bufferPos, int bufferSize)
+ {
+ this.input = input;
+ this.buffer = buffer;
+ this.bufferPos = bufferPos;
+ this.bufferSize = bufferSize;
+ this.sizeLimit = DefaultSizeLimit;
+ this.recursionLimit = DefaultRecursionLimit;
+ }
+
+ /// <summary>
+ /// Creates a new CodedInputStream reading data from the given
+ /// stream and buffer, using the specified limits.
+ /// </summary>
+ /// <remarks>
+ /// This chains to the version with the default limits instead of vice versa to avoid
+ /// having to check that the default values are valid every time.
+ /// </remarks>
+ internal CodedInputStream(Stream input, byte[] buffer, int bufferPos, int bufferSize, int sizeLimit, int recursionLimit)
+ : this(input, buffer, bufferPos, bufferSize)
+ {
+ if (sizeLimit <= 0)
+ {
+ throw new ArgumentOutOfRangeException("sizeLimit", "Size limit must be positive");
+ }
+ if (recursionLimit <= 0)
+ {
+ throw new ArgumentOutOfRangeException("recursionLimit!", "Recursion limit must be positive");
+ }
+ this.sizeLimit = sizeLimit;
+ this.recursionLimit = recursionLimit;
+ }
+ #endregion
+
+ /// <summary>
+ /// Creates a <see cref="CodedInputStream"/> with the specified size and recursion limits, reading
+ /// from an input stream.
+ /// </summary>
+ /// <remarks>
+ /// This method exists separately from the constructor to reduce the number of constructor overloads.
+ /// It is likely to be used considerably less frequently than the constructors, as the default limits
+ /// are suitable for most use cases.
+ /// </remarks>
+ /// <param name="input">The input stream to read from</param>
+ /// <param name="sizeLimit">The total limit of data to read from the stream.</param>
+ /// <param name="recursionLimit">The maximum recursion depth to allow while reading.</param>
+ /// <returns>A <c>CodedInputStream</c> reading from <paramref name="input"/> with the specified size
+ /// and recursion limits.</returns>
+ public static CodedInputStream CreateWithLimits(Stream input, int sizeLimit, int recursionLimit)
+ {
+ return new CodedInputStream(input, new byte[BufferSize], 0, 0, sizeLimit, recursionLimit);
+ }
+
+ /// <summary>
+ /// Returns the current position in the input stream, or the position in the input buffer
+ /// </summary>
+ public long Position
+ {
+ get
+ {
+ if (input != null)
+ {
+ return input.Position - ((bufferSize + bufferSizeAfterLimit) - bufferPos);
+ }
+ return bufferPos;
+ }
+ }
+
+ /// <summary>
+ /// Returns the last tag read, or 0 if no tags have been read or we've read beyond
+ /// the end of the stream.
+ /// </summary>
+ internal uint LastTag { get { return lastTag; } }
+
+ /// <summary>
+ /// Returns the size limit for this stream.
+ /// </summary>
+ /// <remarks>
+ /// This limit is applied when reading from the underlying stream, as a sanity check. It is
+ /// not applied when reading from a byte array data source without an underlying stream.
+ /// The default value is 64MB.
+ /// </remarks>
+ /// <value>
+ /// The size limit.
+ /// </value>
+ public int SizeLimit { get { return sizeLimit; } }
+
+ /// <summary>
+ /// Returns the recursion limit for this stream. This limit is applied whilst reading messages,
+ /// to avoid maliciously-recursive data.
+ /// </summary>
+ /// <remarks>
+ /// The default limit is 64.
+ /// </remarks>
+ /// <value>
+ /// The recursion limit for this stream.
+ /// </value>
+ public int RecursionLimit { get { return recursionLimit; } }
+
+ /// <summary>
+ /// Disposes of this instance, potentially closing any underlying stream.
+ /// </summary>
+ /// <remarks>
+ /// As there is no flushing to perform here, disposing of a <see cref="CodedInputStream"/> which
+ /// was constructed with the <c>leaveOpen</c> option parameter set to <c>true</c> (or one which
+ /// was constructed to read from a byte array) has no effect.
+ /// </remarks>
+ public void Dispose()
+ {
+ if (!leaveOpen)
+ {
+ input.Dispose();
+ }
+ }
+
+ #region Validation
+ /// <summary>
+ /// Verifies that the last call to ReadTag() returned tag 0 - in other words,
+ /// we've reached the end of the stream when we expected to.
+ /// </summary>
+ /// <exception cref="InvalidProtocolBufferException">The
+ /// tag read was not the one specified</exception>
+ internal void CheckReadEndOfStreamTag()
+ {
+ if (lastTag != 0)
+ {
+ throw InvalidProtocolBufferException.MoreDataAvailable();
+ }
+ }
+ #endregion
+
+ #region Reading of tags etc
+
+ /// <summary>
+ /// Peeks at the next field tag. This is like calling <see cref="ReadTag"/>, but the
+ /// tag is not consumed. (So a subsequent call to <see cref="ReadTag"/> will return the
+ /// same value.)
+ /// </summary>
+ public uint PeekTag()
+ {
+ if (hasNextTag)
+ {
+ return nextTag;
+ }
+
+ uint savedLast = lastTag;
+ nextTag = ReadTag();
+ hasNextTag = true;
+ lastTag = savedLast; // Undo the side effect of ReadTag
+ return nextTag;
+ }
+
+ /// <summary>
+ /// Reads a field tag, returning the tag of 0 for "end of stream".
+ /// </summary>
+ /// <remarks>
+ /// If this method returns 0, it doesn't necessarily mean the end of all
+ /// the data in this CodedInputStream; it may be the end of the logical stream
+ /// for an embedded message, for example.
+ /// </remarks>
+ /// <returns>The next field tag, or 0 for end of stream. (0 is never a valid tag.)</returns>
+ public uint ReadTag()
+ {
+ if (hasNextTag)
+ {
+ lastTag = nextTag;
+ hasNextTag = false;
+ return lastTag;
+ }
+
+ // Optimize for the incredibly common case of having at least two bytes left in the buffer,
+ // and those two bytes being enough to get the tag. This will be true for fields up to 4095.
+ if (bufferPos + 2 <= bufferSize)
+ {
+ int tmp = buffer[bufferPos++];
+ if (tmp < 128)
+ {
+ lastTag = (uint)tmp;
+ }
+ else
+ {
+ int result = tmp & 0x7f;
+ if ((tmp = buffer[bufferPos++]) < 128)
+ {
+ result |= tmp << 7;
+ lastTag = (uint) result;
+ }
+ else
+ {
+ // Nope, rewind and go the potentially slow route.
+ bufferPos -= 2;
+ lastTag = ReadRawVarint32();
+ }
+ }
+ }
+ else
+ {
+ if (IsAtEnd)
+ {
+ lastTag = 0;
+ return 0; // This is the only case in which we return 0.
+ }
+
+ lastTag = ReadRawVarint32();
+ }
+ if (lastTag == 0)
+ {
+ // If we actually read zero, that's not a valid tag.
+ throw InvalidProtocolBufferException.InvalidTag();
+ }
+ return lastTag;
+ }
+
+ /// <summary>
+ /// Skips the data for the field with the tag we've just read.
+ /// This should be called directly after <see cref="ReadTag"/>, when
+ /// the caller wishes to skip an unknown field.
+ /// </summary>
+ /// <remarks>
+ /// This method throws <see cref="InvalidProtocolBufferException"/> if the last-read tag was an end-group tag.
+ /// If a caller wishes to skip a group, they should skip the whole group, by calling this method after reading the
+ /// start-group tag. This behavior allows callers to call this method on any field they don't understand, correctly
+ /// resulting in an error if an end-group tag has not been paired with an earlier start-group tag.
+ /// </remarks>
+ /// <exception cref="InvalidProtocolBufferException">The last tag was an end-group tag</exception>
+ /// <exception cref="InvalidOperationException">The last read operation read to the end of the logical stream</exception>
+ public void SkipLastField()
+ {
+ if (lastTag == 0)
+ {
+ throw new InvalidOperationException("SkipLastField cannot be called at the end of a stream");
+ }
+ switch (WireFormat.GetTagWireType(lastTag))
+ {
+ case WireFormat.WireType.StartGroup:
+ SkipGroup(lastTag);
+ break;
+ case WireFormat.WireType.EndGroup:
+ throw new InvalidProtocolBufferException(
+ "SkipLastField called on an end-group tag, indicating that the corresponding start-group was missing");
+ case WireFormat.WireType.Fixed32:
+ ReadFixed32();
+ break;
+ case WireFormat.WireType.Fixed64:
+ ReadFixed64();
+ break;
+ case WireFormat.WireType.LengthDelimited:
+ var length = ReadLength();
+ SkipRawBytes(length);
+ break;
+ case WireFormat.WireType.Varint:
+ ReadRawVarint32();
+ break;
+ }
+ }
+
+ private void SkipGroup(uint startGroupTag)
+ {
+ // Note: Currently we expect this to be the way that groups are read. We could put the recursion
+ // depth changes into the ReadTag method instead, potentially...
+ recursionDepth++;
+ if (recursionDepth >= recursionLimit)
+ {
+ throw InvalidProtocolBufferException.RecursionLimitExceeded();
+ }
+ uint tag;
+ while (true)
+ {
+ tag = ReadTag();
+ if (tag == 0)
+ {
+ throw InvalidProtocolBufferException.TruncatedMessage();
+ }
+ // Can't call SkipLastField for this case- that would throw.
+ if (WireFormat.GetTagWireType(tag) == WireFormat.WireType.EndGroup)
+ {
+ break;
+ }
+ // This recursion will allow us to handle nested groups.
+ SkipLastField();
+ }
+ int startField = WireFormat.GetTagFieldNumber(startGroupTag);
+ int endField = WireFormat.GetTagFieldNumber(tag);
+ if (startField != endField)
+ {
+ throw new InvalidProtocolBufferException(
+ $"Mismatched end-group tag. Started with field {startField}; ended with field {endField}");
+ }
+ recursionDepth--;
+ }
+
+ /// <summary>
+ /// Reads a double field from the stream.
+ /// </summary>
+ public double ReadDouble()
+ {
+ return BitConverter.Int64BitsToDouble((long) ReadRawLittleEndian64());
+ }
+
+ /// <summary>
+ /// Reads a float field from the stream.
+ /// </summary>
+ public float ReadFloat()
+ {
+ if (BitConverter.IsLittleEndian && 4 <= bufferSize - bufferPos)
+ {
+ float ret = BitConverter.ToSingle(buffer, bufferPos);
+ bufferPos += 4;
+ return ret;
+ }
+ else
+ {
+ byte[] rawBytes = ReadRawBytes(4);
+ if (!BitConverter.IsLittleEndian)
+ {
+ ByteArray.Reverse(rawBytes);
+ }
+ return BitConverter.ToSingle(rawBytes, 0);
+ }
+ }
+
+ /// <summary>
+ /// Reads a uint64 field from the stream.
+ /// </summary>
+ public ulong ReadUInt64()
+ {
+ return ReadRawVarint64();
+ }
+
+ /// <summary>
+ /// Reads an int64 field from the stream.
+ /// </summary>
+ public long ReadInt64()
+ {
+ return (long) ReadRawVarint64();
+ }
+
+ /// <summary>
+ /// Reads an int32 field from the stream.
+ /// </summary>
+ public int ReadInt32()
+ {
+ return (int) ReadRawVarint32();
+ }
+
+ /// <summary>
+ /// Reads a fixed64 field from the stream.
+ /// </summary>
+ public ulong ReadFixed64()
+ {
+ return ReadRawLittleEndian64();
+ }
+
+ /// <summary>
+ /// Reads a fixed32 field from the stream.
+ /// </summary>
+ public uint ReadFixed32()
+ {
+ return ReadRawLittleEndian32();
+ }
+
+ /// <summary>
+ /// Reads a bool field from the stream.
+ /// </summary>
+ public bool ReadBool()
+ {
+ return ReadRawVarint32() != 0;
+ }
+
+ /// <summary>
+ /// Reads a string field from the stream.
+ /// </summary>
+ public string ReadString()
+ {
+ int length = ReadLength();
+ // No need to read any data for an empty string.
+ if (length == 0)
+ {
+ return "";
+ }
+ if (length <= bufferSize - bufferPos)
+ {
+ // Fast path: We already have the bytes in a contiguous buffer, so
+ // just copy directly from it.
+ String result = CodedOutputStream.Utf8Encoding.GetString(buffer, bufferPos, length);
+ bufferPos += length;
+ return result;
+ }
+ // Slow path: Build a byte array first then copy it.
+ return CodedOutputStream.Utf8Encoding.GetString(ReadRawBytes(length), 0, length);
+ }
+
+ /// <summary>
+ /// Reads an embedded message field value from the stream.
+ /// </summary>
+ public void ReadMessage(IMessage builder)
+ {
+ int length = ReadLength();
+ if (recursionDepth >= recursionLimit)
+ {
+ throw InvalidProtocolBufferException.RecursionLimitExceeded();
+ }
+ int oldLimit = PushLimit(length);
+ ++recursionDepth;
+ builder.MergeFrom(this);
+ CheckReadEndOfStreamTag();
+ // Check that we've read exactly as much data as expected.
+ if (!ReachedLimit)
+ {
+ throw InvalidProtocolBufferException.TruncatedMessage();
+ }
+ --recursionDepth;
+ PopLimit(oldLimit);
+ }
+
+ /// <summary>
+ /// Reads a bytes field value from the stream.
+ /// </summary>
+ public ByteString ReadBytes()
+ {
+ int length = ReadLength();
+ if (length <= bufferSize - bufferPos && length > 0)
+ {
+ // Fast path: We already have the bytes in a contiguous buffer, so
+ // just copy directly from it.
+ ByteString result = ByteString.CopyFrom(buffer, bufferPos, length);
+ bufferPos += length;
+ return result;
+ }
+ else
+ {
+ // Slow path: Build a byte array and attach it to a new ByteString.
+ return ByteString.AttachBytes(ReadRawBytes(length));
+ }
+ }
+
+ /// <summary>
+ /// Reads a uint32 field value from the stream.
+ /// </summary>
+ public uint ReadUInt32()
+ {
+ return ReadRawVarint32();
+ }
+
+ /// <summary>
+ /// Reads an enum field value from the stream.
+ /// </summary>
+ public int ReadEnum()
+ {
+ // Currently just a pass-through, but it's nice to separate it logically from WriteInt32.
+ return (int) ReadRawVarint32();
+ }
+
+ /// <summary>
+ /// Reads an sfixed32 field value from the stream.
+ /// </summary>
+ public int ReadSFixed32()
+ {
+ return (int) ReadRawLittleEndian32();
+ }
+
+ /// <summary>
+ /// Reads an sfixed64 field value from the stream.
+ /// </summary>
+ public long ReadSFixed64()
+ {
+ return (long) ReadRawLittleEndian64();
+ }
+
+ /// <summary>
+ /// Reads an sint32 field value from the stream.
+ /// </summary>
+ public int ReadSInt32()
+ {
+ return DecodeZigZag32(ReadRawVarint32());
+ }
+
+ /// <summary>
+ /// Reads an sint64 field value from the stream.
+ /// </summary>
+ public long ReadSInt64()
+ {
+ return DecodeZigZag64(ReadRawVarint64());
+ }
+
+ /// <summary>
+ /// Reads a length for length-delimited data.
+ /// </summary>
+ /// <remarks>
+ /// This is internally just reading a varint, but this method exists
+ /// to make the calling code clearer.
+ /// </remarks>
+ public int ReadLength()
+ {
+ return (int) ReadRawVarint32();
+ }
+
+ /// <summary>
+ /// Peeks at the next tag in the stream. If it matches <paramref name="tag"/>,
+ /// the tag is consumed and the method returns <c>true</c>; otherwise, the
+ /// stream is left in the original position and the method returns <c>false</c>.
+ /// </summary>
+ public bool MaybeConsumeTag(uint tag)
+ {
+ if (PeekTag() == tag)
+ {
+ hasNextTag = false;
+ return true;
+ }
+ return false;
+ }
+
+ #endregion
+
+ #region Underlying reading primitives
+
+ /// <summary>
+ /// Same code as ReadRawVarint32, but read each byte individually, checking for
+ /// buffer overflow.
+ /// </summary>
+ private uint SlowReadRawVarint32()
+ {
+ int tmp = ReadRawByte();
+ if (tmp < 128)
+ {
+ return (uint) tmp;
+ }
+ int result = tmp & 0x7f;
+ if ((tmp = ReadRawByte()) < 128)
+ {
+ result |= tmp << 7;
+ }
+ else
+ {
+ result |= (tmp & 0x7f) << 7;
+ if ((tmp = ReadRawByte()) < 128)
+ {
+ result |= tmp << 14;
+ }
+ else
+ {
+ result |= (tmp & 0x7f) << 14;
+ if ((tmp = ReadRawByte()) < 128)
+ {
+ result |= tmp << 21;
+ }
+ else
+ {
+ result |= (tmp & 0x7f) << 21;
+ result |= (tmp = ReadRawByte()) << 28;
+ if (tmp >= 128)
+ {
+ // Discard upper 32 bits.
+ for (int i = 0; i < 5; i++)
+ {
+ if (ReadRawByte() < 128)
+ {
+ return (uint) result;
+ }
+ }
+ throw InvalidProtocolBufferException.MalformedVarint();
+ }
+ }
+ }
+ }
+ return (uint) result;
+ }
+
+ /// <summary>
+ /// Reads a raw Varint from the stream. If larger than 32 bits, discard the upper bits.
+ /// This method is optimised for the case where we've got lots of data in the buffer.
+ /// That means we can check the size just once, then just read directly from the buffer
+ /// without constant rechecking of the buffer length.
+ /// </summary>
+ internal uint ReadRawVarint32()
+ {
+ if (bufferPos + 5 > bufferSize)
+ {
+ return SlowReadRawVarint32();
+ }
+
+ int tmp = buffer[bufferPos++];
+ if (tmp < 128)
+ {
+ return (uint) tmp;
+ }
+ int result = tmp & 0x7f;
+ if ((tmp = buffer[bufferPos++]) < 128)
+ {
+ result |= tmp << 7;
+ }
+ else
+ {
+ result |= (tmp & 0x7f) << 7;
+ if ((tmp = buffer[bufferPos++]) < 128)
+ {
+ result |= tmp << 14;
+ }
+ else
+ {
+ result |= (tmp & 0x7f) << 14;
+ if ((tmp = buffer[bufferPos++]) < 128)
+ {
+ result |= tmp << 21;
+ }
+ else
+ {
+ result |= (tmp & 0x7f) << 21;
+ result |= (tmp = buffer[bufferPos++]) << 28;
+ if (tmp >= 128)
+ {
+ // Discard upper 32 bits.
+ // Note that this has to use ReadRawByte() as we only ensure we've
+ // got at least 5 bytes at the start of the method. This lets us
+ // use the fast path in more cases, and we rarely hit this section of code.
+ for (int i = 0; i < 5; i++)
+ {
+ if (ReadRawByte() < 128)
+ {
+ return (uint) result;
+ }
+ }
+ throw InvalidProtocolBufferException.MalformedVarint();
+ }
+ }
+ }
+ }
+ return (uint) result;
+ }
+
+ /// <summary>
+ /// 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 ReadRawVarint32(Stream)
+ /// then you would probably end up reading past the end of the varint since
+ /// CodedInputStream buffers its input.
+ /// </summary>
+ /// <param name="input"></param>
+ /// <returns></returns>
+ internal static uint ReadRawVarint32(Stream input)
+ {
+ int result = 0;
+ int offset = 0;
+ for (; offset < 32; offset += 7)
+ {
+ int b = input.ReadByte();
+ if (b == -1)
+ {
+ throw InvalidProtocolBufferException.TruncatedMessage();
+ }
+ result |= (b & 0x7f) << offset;
+ if ((b & 0x80) == 0)
+ {
+ return (uint) result;
+ }
+ }
+ // Keep reading up to 64 bits.
+ for (; offset < 64; offset += 7)
+ {
+ int b = input.ReadByte();
+ if (b == -1)
+ {
+ throw InvalidProtocolBufferException.TruncatedMessage();
+ }
+ if ((b & 0x80) == 0)
+ {
+ return (uint) result;
+ }
+ }
+ throw InvalidProtocolBufferException.MalformedVarint();
+ }
+
+ /// <summary>
+ /// Reads a raw varint from the stream.
+ /// </summary>
+ internal ulong ReadRawVarint64()
+ {
+ int shift = 0;
+ ulong result = 0;
+ while (shift < 64)
+ {
+ byte b = ReadRawByte();
+ result |= (ulong) (b & 0x7F) << shift;
+ if ((b & 0x80) == 0)
+ {
+ return result;
+ }
+ shift += 7;
+ }
+ throw InvalidProtocolBufferException.MalformedVarint();
+ }
+
+ /// <summary>
+ /// Reads a 32-bit little-endian integer from the stream.
+ /// </summary>
+ internal uint ReadRawLittleEndian32()
+ {
+ uint b1 = ReadRawByte();
+ uint b2 = ReadRawByte();
+ uint b3 = ReadRawByte();
+ uint b4 = ReadRawByte();
+ return b1 | (b2 << 8) | (b3 << 16) | (b4 << 24);
+ }
+
+ /// <summary>
+ /// Reads a 64-bit little-endian integer from the stream.
+ /// </summary>
+ internal ulong ReadRawLittleEndian64()
+ {
+ ulong b1 = ReadRawByte();
+ ulong b2 = ReadRawByte();
+ ulong b3 = ReadRawByte();
+ ulong b4 = ReadRawByte();
+ ulong b5 = ReadRawByte();
+ ulong b6 = ReadRawByte();
+ ulong b7 = ReadRawByte();
+ ulong b8 = ReadRawByte();
+ return b1 | (b2 << 8) | (b3 << 16) | (b4 << 24)
+ | (b5 << 32) | (b6 << 40) | (b7 << 48) | (b8 << 56);
+ }
+
+ /// <summary>
+ /// Decode a 32-bit value with ZigZag encoding.
+ /// </summary>
+ /// <remarks>
+ /// 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.)
+ /// </remarks>
+ internal static int DecodeZigZag32(uint n)
+ {
+ return (int)(n >> 1) ^ -(int)(n & 1);
+ }
+
+ /// <summary>
+ /// Decode a 32-bit value with ZigZag encoding.
+ /// </summary>
+ /// <remarks>
+ /// 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.)
+ /// </remarks>
+ internal static long DecodeZigZag64(ulong n)
+ {
+ return (long)(n >> 1) ^ -(long)(n & 1);
+ }
+ #endregion
+
+ #region Internal reading and buffer management
+
+ /// <summary>
+ /// Sets currentLimit to (current position) + byteLimit. This is called
+ /// when descending into a length-delimited embedded message. The previous
+ /// limit is returned.
+ /// </summary>
+ /// <returns>The old limit.</returns>
+ internal int PushLimit(int byteLimit)
+ {
+ if (byteLimit < 0)
+ {
+ throw InvalidProtocolBufferException.NegativeSize();
+ }
+ byteLimit += totalBytesRetired + bufferPos;
+ int oldLimit = currentLimit;
+ if (byteLimit > oldLimit)
+ {
+ throw InvalidProtocolBufferException.TruncatedMessage();
+ }
+ currentLimit = byteLimit;
+
+ RecomputeBufferSizeAfterLimit();
+
+ return oldLimit;
+ }
+
+ private void RecomputeBufferSizeAfterLimit()
+ {
+ bufferSize += bufferSizeAfterLimit;
+ int bufferEnd = totalBytesRetired + bufferSize;
+ if (bufferEnd > currentLimit)
+ {
+ // Limit is in current buffer.
+ bufferSizeAfterLimit = bufferEnd - currentLimit;
+ bufferSize -= bufferSizeAfterLimit;
+ }
+ else
+ {
+ bufferSizeAfterLimit = 0;
+ }
+ }
+
+ /// <summary>
+ /// Discards the current limit, returning the previous limit.
+ /// </summary>
+ internal void PopLimit(int oldLimit)
+ {
+ currentLimit = oldLimit;
+ RecomputeBufferSizeAfterLimit();
+ }
+
+ /// <summary>
+ /// Returns whether or not all the data before the limit has been read.
+ /// </summary>
+ /// <returns></returns>
+ internal bool ReachedLimit
+ {
+ get
+ {
+ if (currentLimit == int.MaxValue)
+ {
+ return false;
+ }
+ int currentAbsolutePosition = totalBytesRetired + bufferPos;
+ return currentAbsolutePosition >= currentLimit;
+ }
+ }
+
+ /// <summary>
+ /// 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
+ /// the stream has reached a limit created using PushLimit.
+ /// </summary>
+ public bool IsAtEnd
+ {
+ get { return bufferPos == bufferSize && !RefillBuffer(false); }
+ }
+
+ /// <summary>
+ /// Called when buffer is empty to read more bytes from the
+ /// input. If <paramref name="mustSucceed"/> is true, RefillBuffer() gurantees that
+ /// either there will be at least one byte in the buffer when it returns
+ /// or it will throw an exception. If <paramref name="mustSucceed"/> is false,
+ /// RefillBuffer() returns false if no more bytes were available.
+ /// </summary>
+ /// <param name="mustSucceed"></param>
+ /// <returns></returns>
+ private bool RefillBuffer(bool mustSucceed)
+ {
+ if (bufferPos < bufferSize)
+ {
+ throw new InvalidOperationException("RefillBuffer() called when buffer wasn't empty.");
+ }
+
+ if (totalBytesRetired + bufferSize == currentLimit)
+ {
+ // Oops, we hit a limit.
+ if (mustSucceed)
+ {
+ throw InvalidProtocolBufferException.TruncatedMessage();
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ totalBytesRetired += bufferSize;
+
+ bufferPos = 0;
+ bufferSize = (input == null) ? 0 : input.Read(buffer, 0, buffer.Length);
+ if (bufferSize < 0)
+ {
+ throw new InvalidOperationException("Stream.Read returned a negative count");
+ }
+ if (bufferSize == 0)
+ {
+ if (mustSucceed)
+ {
+ throw InvalidProtocolBufferException.TruncatedMessage();
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ RecomputeBufferSizeAfterLimit();
+ int totalBytesRead =
+ totalBytesRetired + bufferSize + bufferSizeAfterLimit;
+ if (totalBytesRead > sizeLimit || totalBytesRead < 0)
+ {
+ throw InvalidProtocolBufferException.SizeLimitExceeded();
+ }
+ return true;
+ }
+ }
+
+ /// <summary>
+ /// Read one byte from the input.
+ /// </summary>
+ /// <exception cref="InvalidProtocolBufferException">
+ /// the end of the stream or the current limit was reached
+ /// </exception>
+ internal byte ReadRawByte()
+ {
+ if (bufferPos == bufferSize)
+ {
+ RefillBuffer(true);
+ }
+ return buffer[bufferPos++];
+ }
+
+ /// <summary>
+ /// Reads a fixed size of bytes from the input.
+ /// </summary>
+ /// <exception cref="InvalidProtocolBufferException">
+ /// the end of the stream or the current limit was reached
+ /// </exception>
+ internal byte[] ReadRawBytes(int size)
+ {
+ if (size < 0)
+ {
+ throw InvalidProtocolBufferException.NegativeSize();
+ }
+
+ if (totalBytesRetired + bufferPos + size > currentLimit)
+ {
+ // Read to the end of the stream (up to the current limit) anyway.
+ SkipRawBytes(currentLimit - totalBytesRetired - bufferPos);
+ // Then fail.
+ throw InvalidProtocolBufferException.TruncatedMessage();
+ }
+
+ if (size <= bufferSize - bufferPos)
+ {
+ // We have all the bytes we need already.
+ byte[] bytes = new byte[size];
+ ByteArray.Copy(buffer, bufferPos, bytes, 0, size);
+ bufferPos += size;
+ return bytes;
+ }
+ else if (size < buffer.Length)
+ {
+ // Reading more bytes than are in the buffer, but not an excessive number
+ // of bytes. We can safely allocate the resulting array ahead of time.
+
+ // First copy what we have.
+ byte[] bytes = new byte[size];
+ int pos = bufferSize - bufferPos;
+ ByteArray.Copy(buffer, bufferPos, bytes, 0, pos);
+ bufferPos = bufferSize;
+
+ // We want to use RefillBuffer() and then copy from the buffer into our
+ // byte array rather than reading directly into our byte array because
+ // the input may be unbuffered.
+ RefillBuffer(true);
+
+ while (size - pos > bufferSize)
+ {
+ Buffer.BlockCopy(buffer, 0, bytes, pos, bufferSize);
+ pos += bufferSize;
+ bufferPos = bufferSize;
+ RefillBuffer(true);
+ }
+
+ ByteArray.Copy(buffer, 0, bytes, pos, size - pos);
+ bufferPos = size - pos;
+
+ return bytes;
+ }
+ else
+ {
+ // 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.
+
+ // Remember the buffer markers since we'll have to copy the bytes out of
+ // it later.
+ int originalBufferPos = bufferPos;
+ int originalBufferSize = bufferSize;
+
+ // Mark the current buffer consumed.
+ totalBytesRetired += bufferSize;
+ bufferPos = 0;
+ bufferSize = 0;
+
+ // Read all the rest of the bytes we need.
+ int sizeLeft = size - (originalBufferSize - originalBufferPos);
+ List<byte[]> chunks = new List<byte[]>();
+
+ while (sizeLeft > 0)
+ {
+ byte[] chunk = new byte[Math.Min(sizeLeft, buffer.Length)];
+ int pos = 0;
+ while (pos < chunk.Length)
+ {
+ int n = (input == null) ? -1 : input.Read(chunk, pos, chunk.Length - pos);
+ if (n <= 0)
+ {
+ throw InvalidProtocolBufferException.TruncatedMessage();
+ }
+ totalBytesRetired += n;
+ pos += n;
+ }
+ sizeLeft -= chunk.Length;
+ chunks.Add(chunk);
+ }
+
+ // OK, got everything. Now concatenate it all into one buffer.
+ byte[] bytes = new byte[size];
+
+ // Start by copying the leftover bytes from this.buffer.
+ int newPos = originalBufferSize - originalBufferPos;
+ ByteArray.Copy(buffer, originalBufferPos, bytes, 0, newPos);
+
+ // And now all the chunks.
+ foreach (byte[] chunk in chunks)
+ {
+ Buffer.BlockCopy(chunk, 0, bytes, newPos, chunk.Length);
+ newPos += chunk.Length;
+ }
+
+ // Done.
+ return bytes;
+ }
+ }
+
+ /// <summary>
+ /// Reads and discards <paramref name="size"/> bytes.
+ /// </summary>
+ /// <exception cref="InvalidProtocolBufferException">the end of the stream
+ /// or the current limit was reached</exception>
+ private void SkipRawBytes(int size)
+ {
+ if (size < 0)
+ {
+ throw InvalidProtocolBufferException.NegativeSize();
+ }
+
+ if (totalBytesRetired + bufferPos + size > currentLimit)
+ {
+ // Read to the end of the stream anyway.
+ SkipRawBytes(currentLimit - totalBytesRetired - bufferPos);
+ // Then fail.
+ throw InvalidProtocolBufferException.TruncatedMessage();
+ }
+
+ if (size <= bufferSize - bufferPos)
+ {
+ // We have all the bytes we need already.
+ bufferPos += size;
+ }
+ else
+ {
+ // Skipping more bytes than are in the buffer. First skip what we have.
+ int pos = bufferSize - bufferPos;
+
+ // ROK 5/7/2013 Issue #54: should retire all bytes in buffer (bufferSize)
+ // totalBytesRetired += pos;
+ totalBytesRetired += bufferSize;
+
+ bufferPos = 0;
+ bufferSize = 0;
+
+ // Then skip directly from the InputStream for the rest.
+ if (pos < size)
+ {
+ if (input == null)
+ {
+ throw InvalidProtocolBufferException.TruncatedMessage();
+ }
+ SkipImpl(size - pos);
+ totalBytesRetired += size - pos;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Abstraction of skipping to cope with streams which can't really skip.
+ /// </summary>
+ private void SkipImpl(int amountToSkip)
+ {
+ if (input.CanSeek)
+ {
+ long previousPosition = input.Position;
+ input.Position += amountToSkip;
+ if (input.Position != previousPosition + amountToSkip)
+ {
+ throw InvalidProtocolBufferException.TruncatedMessage();
+ }
+ }
+ else
+ {
+ byte[] skipBuffer = new byte[Math.Min(1024, amountToSkip)];
+ while (amountToSkip > 0)
+ {
+ int bytesRead = input.Read(skipBuffer, 0, Math.Min(skipBuffer.Length, amountToSkip));
+ if (bytesRead <= 0)
+ {
+ throw InvalidProtocolBufferException.TruncatedMessage();
+ }
+ amountToSkip -= bytesRead;
+ }
+ }
+ }
+
+ #endregion
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/CodedOutputStream.ComputeSize.cs b/third_party/protobuf/csharp/src/Google.Protobuf/CodedOutputStream.ComputeSize.cs
new file mode 100644
index 0000000000..bf221c9c0a
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/CodedOutputStream.ComputeSize.cs
@@ -0,0 +1,304 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+
+namespace Google.Protobuf
+{
+ // This part of CodedOutputStream provides all the static entry points that are used
+ // by generated code and internally to compute the size of messages prior to being
+ // written to an instance of CodedOutputStream.
+ public sealed partial class CodedOutputStream
+ {
+ private const int LittleEndian64Size = 8;
+ private const int LittleEndian32Size = 4;
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode a
+ /// double field, including the tag.
+ /// </summary>
+ public static int ComputeDoubleSize(double value)
+ {
+ return LittleEndian64Size;
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode a
+ /// float field, including the tag.
+ /// </summary>
+ public static int ComputeFloatSize(float value)
+ {
+ return LittleEndian32Size;
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode a
+ /// uint64 field, including the tag.
+ /// </summary>
+ public static int ComputeUInt64Size(ulong value)
+ {
+ return ComputeRawVarint64Size(value);
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode an
+ /// int64 field, including the tag.
+ /// </summary>
+ public static int ComputeInt64Size(long value)
+ {
+ return ComputeRawVarint64Size((ulong) value);
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode an
+ /// int32 field, including the tag.
+ /// </summary>
+ public static int ComputeInt32Size(int value)
+ {
+ if (value >= 0)
+ {
+ return ComputeRawVarint32Size((uint) value);
+ }
+ else
+ {
+ // Must sign-extend.
+ return 10;
+ }
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode a
+ /// fixed64 field, including the tag.
+ /// </summary>
+ public static int ComputeFixed64Size(ulong value)
+ {
+ return LittleEndian64Size;
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode a
+ /// fixed32 field, including the tag.
+ /// </summary>
+ public static int ComputeFixed32Size(uint value)
+ {
+ return LittleEndian32Size;
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode a
+ /// bool field, including the tag.
+ /// </summary>
+ public static int ComputeBoolSize(bool value)
+ {
+ return 1;
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode a
+ /// string field, including the tag.
+ /// </summary>
+ public static int ComputeStringSize(String value)
+ {
+ int byteArraySize = Utf8Encoding.GetByteCount(value);
+ return ComputeLengthSize(byteArraySize) + byteArraySize;
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode a
+ /// group field, including the tag.
+ /// </summary>
+ public static int ComputeGroupSize(IMessage value)
+ {
+ return value.CalculateSize();
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode an
+ /// embedded message field, including the tag.
+ /// </summary>
+ public static int ComputeMessageSize(IMessage value)
+ {
+ int size = value.CalculateSize();
+ return ComputeLengthSize(size) + size;
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode a
+ /// bytes field, including the tag.
+ /// </summary>
+ public static int ComputeBytesSize(ByteString value)
+ {
+ return ComputeLengthSize(value.Length) + value.Length;
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode a
+ /// uint32 field, including the tag.
+ /// </summary>
+ public static int ComputeUInt32Size(uint value)
+ {
+ return ComputeRawVarint32Size(value);
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode a
+ /// enum field, including the tag. The caller is responsible for
+ /// converting the enum value to its numeric value.
+ /// </summary>
+ public static int ComputeEnumSize(int value)
+ {
+ // Currently just a pass-through, but it's nice to separate it logically.
+ return ComputeInt32Size(value);
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode an
+ /// sfixed32 field, including the tag.
+ /// </summary>
+ public static int ComputeSFixed32Size(int value)
+ {
+ return LittleEndian32Size;
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode an
+ /// sfixed64 field, including the tag.
+ /// </summary>
+ public static int ComputeSFixed64Size(long value)
+ {
+ return LittleEndian64Size;
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode an
+ /// sint32 field, including the tag.
+ /// </summary>
+ public static int ComputeSInt32Size(int value)
+ {
+ return ComputeRawVarint32Size(EncodeZigZag32(value));
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode an
+ /// sint64 field, including the tag.
+ /// </summary>
+ public static int ComputeSInt64Size(long value)
+ {
+ return ComputeRawVarint64Size(EncodeZigZag64(value));
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode a length,
+ /// as written by <see cref="WriteLength"/>.
+ /// </summary>
+ public static int ComputeLengthSize(int length)
+ {
+ return ComputeRawVarint32Size((uint) length);
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode a varint.
+ /// </summary>
+ public static int ComputeRawVarint32Size(uint value)
+ {
+ if ((value & (0xffffffff << 7)) == 0)
+ {
+ return 1;
+ }
+ if ((value & (0xffffffff << 14)) == 0)
+ {
+ return 2;
+ }
+ if ((value & (0xffffffff << 21)) == 0)
+ {
+ return 3;
+ }
+ if ((value & (0xffffffff << 28)) == 0)
+ {
+ return 4;
+ }
+ return 5;
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode a varint.
+ /// </summary>
+ public static int ComputeRawVarint64Size(ulong value)
+ {
+ if ((value & (0xffffffffffffffffL << 7)) == 0)
+ {
+ return 1;
+ }
+ if ((value & (0xffffffffffffffffL << 14)) == 0)
+ {
+ return 2;
+ }
+ if ((value & (0xffffffffffffffffL << 21)) == 0)
+ {
+ return 3;
+ }
+ if ((value & (0xffffffffffffffffL << 28)) == 0)
+ {
+ return 4;
+ }
+ if ((value & (0xffffffffffffffffL << 35)) == 0)
+ {
+ return 5;
+ }
+ if ((value & (0xffffffffffffffffL << 42)) == 0)
+ {
+ return 6;
+ }
+ if ((value & (0xffffffffffffffffL << 49)) == 0)
+ {
+ return 7;
+ }
+ if ((value & (0xffffffffffffffffL << 56)) == 0)
+ {
+ return 8;
+ }
+ if ((value & (0xffffffffffffffffL << 63)) == 0)
+ {
+ return 9;
+ }
+ return 10;
+ }
+
+ /// <summary>
+ /// Computes the number of bytes that would be needed to encode a tag.
+ /// </summary>
+ public static int ComputeTagSize(int fieldNumber)
+ {
+ return ComputeRawVarint32Size(WireFormat.MakeTag(fieldNumber, 0));
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/CodedOutputStream.cs b/third_party/protobuf/csharp/src/Google.Protobuf/CodedOutputStream.cs
new file mode 100644
index 0000000000..6211aac32c
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/CodedOutputStream.cs
@@ -0,0 +1,761 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using Google.Protobuf.Collections;
+using System;
+using System.IO;
+using System.Text;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Encodes and writes protocol message fields.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// This class is generally used by generated code to write appropriate
+ /// primitives to the stream. It effectively encapsulates the lowest
+ /// levels of protocol buffer format. Unlike some other implementations,
+ /// this does not include combined "write tag and value" methods. Generated
+ /// code knows the exact byte representations of the tags they're going to write,
+ /// so there's no need to re-encode them each time. Manually-written code calling
+ /// this class should just call one of the <c>WriteTag</c> overloads before each value.
+ /// </para>
+ /// <para>
+ /// Repeated fields and map fields are not handled by this class; use <c>RepeatedField&lt;T&gt;</c>
+ /// and <c>MapField&lt;TKey, TValue&gt;</c> to serialize such fields.
+ /// </para>
+ /// </remarks>
+ public sealed partial class CodedOutputStream : IDisposable
+ {
+ // "Local" copy of Encoding.UTF8, for efficiency. (Yes, it makes a difference.)
+ internal static readonly Encoding Utf8Encoding = Encoding.UTF8;
+
+ /// <summary>
+ /// The buffer size used by CreateInstance(Stream).
+ /// </summary>
+ public static readonly int DefaultBufferSize = 4096;
+
+ private readonly bool leaveOpen;
+ private readonly byte[] buffer;
+ private readonly int limit;
+ private int position;
+ private readonly Stream output;
+
+ #region Construction
+ /// <summary>
+ /// Creates a new CodedOutputStream that writes directly to the given
+ /// byte array. If more bytes are written than fit in the array,
+ /// OutOfSpaceException will be thrown.
+ /// </summary>
+ public CodedOutputStream(byte[] flatArray) : this(flatArray, 0, flatArray.Length)
+ {
+ }
+
+ /// <summary>
+ /// Creates a new CodedOutputStream that writes directly to the given
+ /// byte array slice. If more bytes are written than fit in the array,
+ /// OutOfSpaceException will be thrown.
+ /// </summary>
+ private CodedOutputStream(byte[] buffer, int offset, int length)
+ {
+ this.output = null;
+ this.buffer = buffer;
+ this.position = offset;
+ this.limit = offset + length;
+ leaveOpen = true; // Simple way of avoiding trying to dispose of a null reference
+ }
+
+ private CodedOutputStream(Stream output, byte[] buffer, bool leaveOpen)
+ {
+ this.output = ProtoPreconditions.CheckNotNull(output, nameof(output));
+ this.buffer = buffer;
+ this.position = 0;
+ this.limit = buffer.Length;
+ this.leaveOpen = leaveOpen;
+ }
+
+ /// <summary>
+ /// Creates a new <see cref="CodedOutputStream" /> which write to the given stream, and disposes of that
+ /// stream when the returned <c>CodedOutputStream</c> is disposed.
+ /// </summary>
+ /// <param name="output">The stream to write to. It will be disposed when the returned <c>CodedOutputStream is disposed.</c></param>
+ public CodedOutputStream(Stream output) : this(output, DefaultBufferSize, false)
+ {
+ }
+
+ /// <summary>
+ /// Creates a new CodedOutputStream which write to the given stream and uses
+ /// the specified buffer size.
+ /// </summary>
+ /// <param name="output">The stream to write to. It will be disposed when the returned <c>CodedOutputStream is disposed.</c></param>
+ /// <param name="bufferSize">The size of buffer to use internally.</param>
+ public CodedOutputStream(Stream output, int bufferSize) : this(output, new byte[bufferSize], false)
+ {
+ }
+
+ /// <summary>
+ /// Creates a new CodedOutputStream which write to the given stream.
+ /// </summary>
+ /// <param name="output">The stream to write to.</param>
+ /// <param name="leaveOpen">If <c>true</c>, <paramref name="output"/> is left open when the returned <c>CodedOutputStream</c> is disposed;
+ /// if <c>false</c>, the provided stream is disposed as well.</param>
+ public CodedOutputStream(Stream output, bool leaveOpen) : this(output, DefaultBufferSize, leaveOpen)
+ {
+ }
+
+ /// <summary>
+ /// Creates a new CodedOutputStream which write to the given stream and uses
+ /// the specified buffer size.
+ /// </summary>
+ /// <param name="output">The stream to write to.</param>
+ /// <param name="bufferSize">The size of buffer to use internally.</param>
+ /// <param name="leaveOpen">If <c>true</c>, <paramref name="output"/> is left open when the returned <c>CodedOutputStream</c> is disposed;
+ /// if <c>false</c>, the provided stream is disposed as well.</param>
+ public CodedOutputStream(Stream output, int bufferSize, bool leaveOpen) : this(output, new byte[bufferSize], leaveOpen)
+ {
+ }
+ #endregion
+
+ /// <summary>
+ /// Returns the current position in the stream, or the position in the output buffer
+ /// </summary>
+ public long Position
+ {
+ get
+ {
+ if (output != null)
+ {
+ return output.Position + position;
+ }
+ return position;
+ }
+ }
+
+ #region Writing of values (not including tags)
+
+ /// <summary>
+ /// Writes a double field value, without a tag, to the stream.
+ /// </summary>
+ /// <param name="value">The value to write</param>
+ public void WriteDouble(double value)
+ {
+ WriteRawLittleEndian64((ulong)BitConverter.DoubleToInt64Bits(value));
+ }
+
+ /// <summary>
+ /// Writes a float field value, without a tag, to the stream.
+ /// </summary>
+ /// <param name="value">The value to write</param>
+ public void WriteFloat(float value)
+ {
+ byte[] rawBytes = BitConverter.GetBytes(value);
+ if (!BitConverter.IsLittleEndian)
+ {
+ ByteArray.Reverse(rawBytes);
+ }
+
+ if (limit - position >= 4)
+ {
+ buffer[position++] = rawBytes[0];
+ buffer[position++] = rawBytes[1];
+ buffer[position++] = rawBytes[2];
+ buffer[position++] = rawBytes[3];
+ }
+ else
+ {
+ WriteRawBytes(rawBytes, 0, 4);
+ }
+ }
+
+ /// <summary>
+ /// Writes a uint64 field value, without a tag, to the stream.
+ /// </summary>
+ /// <param name="value">The value to write</param>
+ public void WriteUInt64(ulong value)
+ {
+ WriteRawVarint64(value);
+ }
+
+ /// <summary>
+ /// Writes an int64 field value, without a tag, to the stream.
+ /// </summary>
+ /// <param name="value">The value to write</param>
+ public void WriteInt64(long value)
+ {
+ WriteRawVarint64((ulong) value);
+ }
+
+ /// <summary>
+ /// Writes an int32 field value, without a tag, to the stream.
+ /// </summary>
+ /// <param name="value">The value to write</param>
+ public void WriteInt32(int value)
+ {
+ if (value >= 0)
+ {
+ WriteRawVarint32((uint) value);
+ }
+ else
+ {
+ // Must sign-extend.
+ WriteRawVarint64((ulong) value);
+ }
+ }
+
+ /// <summary>
+ /// Writes a fixed64 field value, without a tag, to the stream.
+ /// </summary>
+ /// <param name="value">The value to write</param>
+ public void WriteFixed64(ulong value)
+ {
+ WriteRawLittleEndian64(value);
+ }
+
+ /// <summary>
+ /// Writes a fixed32 field value, without a tag, to the stream.
+ /// </summary>
+ /// <param name="value">The value to write</param>
+ public void WriteFixed32(uint value)
+ {
+ WriteRawLittleEndian32(value);
+ }
+
+ /// <summary>
+ /// Writes a bool field value, without a tag, to the stream.
+ /// </summary>
+ /// <param name="value">The value to write</param>
+ public void WriteBool(bool value)
+ {
+ WriteRawByte(value ? (byte) 1 : (byte) 0);
+ }
+
+ /// <summary>
+ /// Writes a string field value, without a tag, to the stream.
+ /// The data is length-prefixed.
+ /// </summary>
+ /// <param name="value">The value to write</param>
+ public void WriteString(string value)
+ {
+ // Optimise the case where we have enough space to write
+ // the string directly to the buffer, which should be common.
+ int length = Utf8Encoding.GetByteCount(value);
+ WriteLength(length);
+ if (limit - position >= length)
+ {
+ if (length == value.Length) // Must be all ASCII...
+ {
+ for (int i = 0; i < length; i++)
+ {
+ buffer[position + i] = (byte)value[i];
+ }
+ }
+ else
+ {
+ Utf8Encoding.GetBytes(value, 0, value.Length, buffer, position);
+ }
+ position += length;
+ }
+ else
+ {
+ byte[] bytes = Utf8Encoding.GetBytes(value);
+ WriteRawBytes(bytes);
+ }
+ }
+
+ /// <summary>
+ /// Writes a message, without a tag, to the stream.
+ /// The data is length-prefixed.
+ /// </summary>
+ /// <param name="value">The value to write</param>
+ public void WriteMessage(IMessage value)
+ {
+ WriteLength(value.CalculateSize());
+ value.WriteTo(this);
+ }
+
+ /// <summary>
+ /// Write a byte string, without a tag, to the stream.
+ /// The data is length-prefixed.
+ /// </summary>
+ /// <param name="value">The value to write</param>
+ public void WriteBytes(ByteString value)
+ {
+ WriteLength(value.Length);
+ value.WriteRawBytesTo(this);
+ }
+
+ /// <summary>
+ /// Writes a uint32 value, without a tag, to the stream.
+ /// </summary>
+ /// <param name="value">The value to write</param>
+ public void WriteUInt32(uint value)
+ {
+ WriteRawVarint32(value);
+ }
+
+ /// <summary>
+ /// Writes an enum value, without a tag, to the stream.
+ /// </summary>
+ /// <param name="value">The value to write</param>
+ public void WriteEnum(int value)
+ {
+ WriteInt32(value);
+ }
+
+ /// <summary>
+ /// Writes an sfixed32 value, without a tag, to the stream.
+ /// </summary>
+ /// <param name="value">The value to write.</param>
+ public void WriteSFixed32(int value)
+ {
+ WriteRawLittleEndian32((uint) value);
+ }
+
+ /// <summary>
+ /// Writes an sfixed64 value, without a tag, to the stream.
+ /// </summary>
+ /// <param name="value">The value to write</param>
+ public void WriteSFixed64(long value)
+ {
+ WriteRawLittleEndian64((ulong) value);
+ }
+
+ /// <summary>
+ /// Writes an sint32 value, without a tag, to the stream.
+ /// </summary>
+ /// <param name="value">The value to write</param>
+ public void WriteSInt32(int value)
+ {
+ WriteRawVarint32(EncodeZigZag32(value));
+ }
+
+ /// <summary>
+ /// Writes an sint64 value, without a tag, to the stream.
+ /// </summary>
+ /// <param name="value">The value to write</param>
+ public void WriteSInt64(long value)
+ {
+ WriteRawVarint64(EncodeZigZag64(value));
+ }
+
+ /// <summary>
+ /// Writes a length (in bytes) for length-delimited data.
+ /// </summary>
+ /// <remarks>
+ /// This method simply writes a rawint, but exists for clarity in calling code.
+ /// </remarks>
+ /// <param name="length">Length value, in bytes.</param>
+ public void WriteLength(int length)
+ {
+ WriteRawVarint32((uint) length);
+ }
+
+ #endregion
+
+ #region Raw tag writing
+ /// <summary>
+ /// Encodes and writes a tag.
+ /// </summary>
+ /// <param name="fieldNumber">The number of the field to write the tag for</param>
+ /// <param name="type">The wire format type of the tag to write</param>
+ public void WriteTag(int fieldNumber, WireFormat.WireType type)
+ {
+ WriteRawVarint32(WireFormat.MakeTag(fieldNumber, type));
+ }
+
+ /// <summary>
+ /// Writes an already-encoded tag.
+ /// </summary>
+ /// <param name="tag">The encoded tag</param>
+ public void WriteTag(uint tag)
+ {
+ WriteRawVarint32(tag);
+ }
+
+ /// <summary>
+ /// Writes the given single-byte tag directly to the stream.
+ /// </summary>
+ /// <param name="b1">The encoded tag</param>
+ public void WriteRawTag(byte b1)
+ {
+ WriteRawByte(b1);
+ }
+
+ /// <summary>
+ /// Writes the given two-byte tag directly to the stream.
+ /// </summary>
+ /// <param name="b1">The first byte of the encoded tag</param>
+ /// <param name="b2">The second byte of the encoded tag</param>
+ public void WriteRawTag(byte b1, byte b2)
+ {
+ WriteRawByte(b1);
+ WriteRawByte(b2);
+ }
+
+ /// <summary>
+ /// Writes the given three-byte tag directly to the stream.
+ /// </summary>
+ /// <param name="b1">The first byte of the encoded tag</param>
+ /// <param name="b2">The second byte of the encoded tag</param>
+ /// <param name="b3">The third byte of the encoded tag</param>
+ public void WriteRawTag(byte b1, byte b2, byte b3)
+ {
+ WriteRawByte(b1);
+ WriteRawByte(b2);
+ WriteRawByte(b3);
+ }
+
+ /// <summary>
+ /// Writes the given four-byte tag directly to the stream.
+ /// </summary>
+ /// <param name="b1">The first byte of the encoded tag</param>
+ /// <param name="b2">The second byte of the encoded tag</param>
+ /// <param name="b3">The third byte of the encoded tag</param>
+ /// <param name="b4">The fourth byte of the encoded tag</param>
+ public void WriteRawTag(byte b1, byte b2, byte b3, byte b4)
+ {
+ WriteRawByte(b1);
+ WriteRawByte(b2);
+ WriteRawByte(b3);
+ WriteRawByte(b4);
+ }
+
+ /// <summary>
+ /// Writes the given five-byte tag directly to the stream.
+ /// </summary>
+ /// <param name="b1">The first byte of the encoded tag</param>
+ /// <param name="b2">The second byte of the encoded tag</param>
+ /// <param name="b3">The third byte of the encoded tag</param>
+ /// <param name="b4">The fourth byte of the encoded tag</param>
+ /// <param name="b5">The fifth byte of the encoded tag</param>
+ public void WriteRawTag(byte b1, byte b2, byte b3, byte b4, byte b5)
+ {
+ WriteRawByte(b1);
+ WriteRawByte(b2);
+ WriteRawByte(b3);
+ WriteRawByte(b4);
+ WriteRawByte(b5);
+ }
+ #endregion
+
+ #region Underlying writing primitives
+ /// <summary>
+ /// Writes a 32 bit value as a varint. The fast route is taken when
+ /// there's enough buffer space left to whizz through without checking
+ /// for each byte; otherwise, we resort to calling WriteRawByte each time.
+ /// </summary>
+ internal void WriteRawVarint32(uint value)
+ {
+ // Optimize for the common case of a single byte value
+ if (value < 128 && position < limit)
+ {
+ buffer[position++] = (byte)value;
+ return;
+ }
+
+ while (value > 127 && position < limit)
+ {
+ buffer[position++] = (byte) ((value & 0x7F) | 0x80);
+ value >>= 7;
+ }
+ while (value > 127)
+ {
+ WriteRawByte((byte) ((value & 0x7F) | 0x80));
+ value >>= 7;
+ }
+ if (position < limit)
+ {
+ buffer[position++] = (byte) value;
+ }
+ else
+ {
+ WriteRawByte((byte) value);
+ }
+ }
+
+ internal void WriteRawVarint64(ulong value)
+ {
+ while (value > 127 && position < limit)
+ {
+ buffer[position++] = (byte) ((value & 0x7F) | 0x80);
+ value >>= 7;
+ }
+ while (value > 127)
+ {
+ WriteRawByte((byte) ((value & 0x7F) | 0x80));
+ value >>= 7;
+ }
+ if (position < limit)
+ {
+ buffer[position++] = (byte) value;
+ }
+ else
+ {
+ WriteRawByte((byte) value);
+ }
+ }
+
+ internal void WriteRawLittleEndian32(uint value)
+ {
+ if (position + 4 > limit)
+ {
+ WriteRawByte((byte) value);
+ WriteRawByte((byte) (value >> 8));
+ WriteRawByte((byte) (value >> 16));
+ WriteRawByte((byte) (value >> 24));
+ }
+ else
+ {
+ buffer[position++] = ((byte) value);
+ buffer[position++] = ((byte) (value >> 8));
+ buffer[position++] = ((byte) (value >> 16));
+ buffer[position++] = ((byte) (value >> 24));
+ }
+ }
+
+ internal void WriteRawLittleEndian64(ulong value)
+ {
+ if (position + 8 > limit)
+ {
+ WriteRawByte((byte) value);
+ WriteRawByte((byte) (value >> 8));
+ WriteRawByte((byte) (value >> 16));
+ WriteRawByte((byte) (value >> 24));
+ WriteRawByte((byte) (value >> 32));
+ WriteRawByte((byte) (value >> 40));
+ WriteRawByte((byte) (value >> 48));
+ WriteRawByte((byte) (value >> 56));
+ }
+ else
+ {
+ buffer[position++] = ((byte) value);
+ buffer[position++] = ((byte) (value >> 8));
+ buffer[position++] = ((byte) (value >> 16));
+ buffer[position++] = ((byte) (value >> 24));
+ buffer[position++] = ((byte) (value >> 32));
+ buffer[position++] = ((byte) (value >> 40));
+ buffer[position++] = ((byte) (value >> 48));
+ buffer[position++] = ((byte) (value >> 56));
+ }
+ }
+
+ internal void WriteRawByte(byte value)
+ {
+ if (position == limit)
+ {
+ RefreshBuffer();
+ }
+
+ buffer[position++] = value;
+ }
+
+ internal void WriteRawByte(uint value)
+ {
+ WriteRawByte((byte) value);
+ }
+
+ /// <summary>
+ /// Writes out an array of bytes.
+ /// </summary>
+ internal void WriteRawBytes(byte[] value)
+ {
+ WriteRawBytes(value, 0, value.Length);
+ }
+
+ /// <summary>
+ /// Writes out part of an array of bytes.
+ /// </summary>
+ internal void WriteRawBytes(byte[] value, int offset, int length)
+ {
+ if (limit - position >= length)
+ {
+ ByteArray.Copy(value, offset, buffer, position, length);
+ // We have room in the current buffer.
+ position += length;
+ }
+ else
+ {
+ // Write extends past current buffer. Fill the rest of this buffer and
+ // flush.
+ int bytesWritten = limit - position;
+ ByteArray.Copy(value, offset, buffer, position, bytesWritten);
+ offset += bytesWritten;
+ length -= bytesWritten;
+ position = limit;
+ RefreshBuffer();
+
+ // Now deal with the rest.
+ // Since we have an output stream, this is our buffer
+ // and buffer offset == 0
+ if (length <= limit)
+ {
+ // Fits in new buffer.
+ ByteArray.Copy(value, offset, buffer, 0, length);
+ position = length;
+ }
+ else
+ {
+ // Write is very big. Let's do it all at once.
+ output.Write(value, offset, length);
+ }
+ }
+ }
+
+ #endregion
+
+ /// <summary>
+ /// Encode a 32-bit value with ZigZag encoding.
+ /// </summary>
+ /// <remarks>
+ /// 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.)
+ /// </remarks>
+ internal static uint EncodeZigZag32(int n)
+ {
+ // Note: the right-shift must be arithmetic
+ return (uint) ((n << 1) ^ (n >> 31));
+ }
+
+ /// <summary>
+ /// Encode a 64-bit value with ZigZag encoding.
+ /// </summary>
+ /// <remarks>
+ /// 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.)
+ /// </remarks>
+ internal static ulong EncodeZigZag64(long n)
+ {
+ return (ulong) ((n << 1) ^ (n >> 63));
+ }
+
+ private void RefreshBuffer()
+ {
+ if (output == null)
+ {
+ // We're writing to a single buffer.
+ throw new OutOfSpaceException();
+ }
+
+ // Since we have an output stream, this is our buffer
+ // and buffer offset == 0
+ output.Write(buffer, 0, position);
+ position = 0;
+ }
+
+ /// <summary>
+ /// Indicates that a CodedOutputStream wrapping a flat byte array
+ /// ran out of space.
+ /// </summary>
+ public sealed class OutOfSpaceException : IOException
+ {
+ internal OutOfSpaceException()
+ : base("CodedOutputStream was writing to a flat byte array and ran out of space.")
+ {
+ }
+ }
+
+ /// <summary>
+ /// Flushes any buffered data and optionally closes the underlying stream, if any.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// By default, any underlying stream is closed by this method. To configure this behaviour,
+ /// use a constructor overload with a <c>leaveOpen</c> parameter. If this instance does not
+ /// have an underlying stream, this method does nothing.
+ /// </para>
+ /// <para>
+ /// For the sake of efficiency, calling this method does not prevent future write calls - but
+ /// if a later write ends up writing to a stream which has been disposed, that is likely to
+ /// fail. It is recommend that you not call any other methods after this.
+ /// </para>
+ /// </remarks>
+ public void Dispose()
+ {
+ Flush();
+ if (!leaveOpen)
+ {
+ output.Dispose();
+ }
+ }
+
+ /// <summary>
+ /// Flushes any buffered data to the underlying stream (if there is one).
+ /// </summary>
+ public void Flush()
+ {
+ if (output != null)
+ {
+ RefreshBuffer();
+ }
+ }
+
+ /// <summary>
+ /// Verifies that SpaceLeft returns zero. It's common to create a byte array
+ /// that is exactly big enough to hold a message, then write to it with
+ /// a CodedOutputStream. Calling CheckNoSpaceLeft after writing verifies that
+ /// the message was actually as big as expected, which can help bugs.
+ /// </summary>
+ public void CheckNoSpaceLeft()
+ {
+ if (SpaceLeft != 0)
+ {
+ throw new InvalidOperationException("Did not write as much data as expected.");
+ }
+ }
+
+ /// <summary>
+ /// If writing to a flat array, returns the space left in the array. Otherwise,
+ /// throws an InvalidOperationException.
+ /// </summary>
+ public int SpaceLeft
+ {
+ get
+ {
+ if (output == null)
+ {
+ return limit - position;
+ }
+ else
+ {
+ throw new InvalidOperationException(
+ "SpaceLeft can only be called on CodedOutputStreams that are " +
+ "writing to a flat array.");
+ }
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Collections/MapField.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Collections/MapField.cs
new file mode 100644
index 0000000000..ef5651c905
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Collections/MapField.cs
@@ -0,0 +1,760 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using Google.Protobuf.Compatibility;
+using Google.Protobuf.Reflection;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+
+namespace Google.Protobuf.Collections
+{
+ /// <summary>
+ /// Representation of a map field in a Protocol Buffer message.
+ /// </summary>
+ /// <typeparam name="TKey">Key type in the map. Must be a type supported by Protocol Buffer map keys.</typeparam>
+ /// <typeparam name="TValue">Value type in the map. Must be a type supported by Protocol Buffers.</typeparam>
+ /// <remarks>
+ /// <para>
+ /// For string keys, the equality comparison is provided by <see cref="StringComparer.Ordinal" />.
+ /// </para>
+ /// <para>
+ /// Null values are not permitted in the map, either for wrapper types or regular messages.
+ /// If a map is deserialized from a data stream and the value is missing from an entry, a default value
+ /// is created instead. For primitive types, that is the regular default value (0, the empty string and so
+ /// on); for message types, an empty instance of the message is created, as if the map entry contained a 0-length
+ /// encoded value for the field.
+ /// </para>
+ /// <para>
+ /// This implementation does not generally prohibit the use of key/value types which are not
+ /// supported by Protocol Buffers (e.g. using a key type of <code>byte</code>) but nor does it guarantee
+ /// that all operations will work in such cases.
+ /// </para>
+ /// <para>
+ /// The order in which entries are returned when iterating over this object is undefined, and may change
+ /// in future versions.
+ /// </para>
+ /// </remarks>
+ public sealed class MapField<TKey, TValue> : IDeepCloneable<MapField<TKey, TValue>>, IDictionary<TKey, TValue>, IEquatable<MapField<TKey, TValue>>, IDictionary
+ {
+ // TODO: Don't create the map/list until we have an entry. (Assume many maps will be empty.)
+ private readonly Dictionary<TKey, LinkedListNode<KeyValuePair<TKey, TValue>>> map =
+ new Dictionary<TKey, LinkedListNode<KeyValuePair<TKey, TValue>>>();
+ private readonly LinkedList<KeyValuePair<TKey, TValue>> list = new LinkedList<KeyValuePair<TKey, TValue>>();
+
+ /// <summary>
+ /// Creates a deep clone of this object.
+ /// </summary>
+ /// <returns>
+ /// A deep clone of this object.
+ /// </returns>
+ public MapField<TKey, TValue> Clone()
+ {
+ var clone = new MapField<TKey, TValue>();
+ // Keys are never cloneable. Values might be.
+ if (typeof(IDeepCloneable<TValue>).IsAssignableFrom(typeof(TValue)))
+ {
+ foreach (var pair in list)
+ {
+ clone.Add(pair.Key, ((IDeepCloneable<TValue>)pair.Value).Clone());
+ }
+ }
+ else
+ {
+ // Nothing is cloneable, so we don't need to worry.
+ clone.Add(this);
+ }
+ return clone;
+ }
+
+ /// <summary>
+ /// Adds the specified key/value pair to the map.
+ /// </summary>
+ /// <remarks>
+ /// This operation fails if the key already exists in the map. To replace an existing entry, use the indexer.
+ /// </remarks>
+ /// <param name="key">The key to add</param>
+ /// <param name="value">The value to add.</param>
+ /// <exception cref="System.ArgumentException">The given key already exists in map.</exception>
+ public void Add(TKey key, TValue value)
+ {
+ // Validation of arguments happens in ContainsKey and the indexer
+ if (ContainsKey(key))
+ {
+ throw new ArgumentException("Key already exists in map", nameof(key));
+ }
+ this[key] = value;
+ }
+
+ /// <summary>
+ /// Determines whether the specified key is present in the map.
+ /// </summary>
+ /// <param name="key">The key to check.</param>
+ /// <returns><c>true</c> if the map contains the given key; <c>false</c> otherwise.</returns>
+ public bool ContainsKey(TKey key)
+ {
+ ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key));
+ return map.ContainsKey(key);
+ }
+
+ private bool ContainsValue(TValue value)
+ {
+ var comparer = EqualityComparer<TValue>.Default;
+ return list.Any(pair => comparer.Equals(pair.Value, value));
+ }
+
+ /// <summary>
+ /// Removes the entry identified by the given key from the map.
+ /// </summary>
+ /// <param name="key">The key indicating the entry to remove from the map.</param>
+ /// <returns><c>true</c> if the map contained the given key before the entry was removed; <c>false</c> otherwise.</returns>
+ public bool Remove(TKey key)
+ {
+ ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key));
+ LinkedListNode<KeyValuePair<TKey, TValue>> node;
+ if (map.TryGetValue(key, out node))
+ {
+ map.Remove(key);
+ node.List.Remove(node);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Gets the value associated with the specified key.
+ /// </summary>
+ /// <param name="key">The key whose value to get.</param>
+ /// <param name="value">When this method returns, the value associated with the specified key, if the key is found;
+ /// otherwise, the default value for the type of the <paramref name="value"/> parameter.
+ /// This parameter is passed uninitialized.</param>
+ /// <returns><c>true</c> if the map contains an element with the specified key; otherwise, <c>false</c>.</returns>
+ public bool TryGetValue(TKey key, out TValue value)
+ {
+ LinkedListNode<KeyValuePair<TKey, TValue>> node;
+ if (map.TryGetValue(key, out node))
+ {
+ value = node.Value.Value;
+ return true;
+ }
+ else
+ {
+ value = default(TValue);
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the value associated with the specified key.
+ /// </summary>
+ /// <param name="key">The key of the value to get or set.</param>
+ /// <exception cref="KeyNotFoundException">The property is retrieved and key does not exist in the collection.</exception>
+ /// <returns>The value associated with the specified key. If the specified key is not found,
+ /// a get operation throws a <see cref="KeyNotFoundException"/>, and a set operation creates a new element with the specified key.</returns>
+ public TValue this[TKey key]
+ {
+ get
+ {
+ ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key));
+ TValue value;
+ if (TryGetValue(key, out value))
+ {
+ return value;
+ }
+ throw new KeyNotFoundException();
+ }
+ set
+ {
+ ProtoPreconditions.CheckNotNullUnconstrained(key, nameof(key));
+ // value == null check here is redundant, but avoids boxing.
+ if (value == null)
+ {
+ ProtoPreconditions.CheckNotNullUnconstrained(value, nameof(value));
+ }
+ LinkedListNode<KeyValuePair<TKey, TValue>> node;
+ var pair = new KeyValuePair<TKey, TValue>(key, value);
+ if (map.TryGetValue(key, out node))
+ {
+ node.Value = pair;
+ }
+ else
+ {
+ node = list.AddLast(pair);
+ map[key] = node;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets a collection containing the keys in the map.
+ /// </summary>
+ public ICollection<TKey> Keys { get { return new MapView<TKey>(this, pair => pair.Key, ContainsKey); } }
+
+ /// <summary>
+ /// Gets a collection containing the values in the map.
+ /// </summary>
+ public ICollection<TValue> Values { get { return new MapView<TValue>(this, pair => pair.Value, ContainsValue); } }
+
+ /// <summary>
+ /// Adds the specified entries to the map. The keys and values are not automatically cloned.
+ /// </summary>
+ /// <param name="entries">The entries to add to the map.</param>
+ public void Add(IDictionary<TKey, TValue> entries)
+ {
+ ProtoPreconditions.CheckNotNull(entries, nameof(entries));
+ foreach (var pair in entries)
+ {
+ Add(pair.Key, pair.Value);
+ }
+ }
+
+ /// <summary>
+ /// Returns an enumerator that iterates through the collection.
+ /// </summary>
+ /// <returns>
+ /// An enumerator that can be used to iterate through the collection.
+ /// </returns>
+ public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
+ {
+ return list.GetEnumerator();
+ }
+
+ /// <summary>
+ /// Returns an enumerator that iterates through a collection.
+ /// </summary>
+ /// <returns>
+ /// An <see cref="T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection.
+ /// </returns>
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ /// <summary>
+ /// Adds the specified item to the map.
+ /// </summary>
+ /// <param name="item">The item to add to the map.</param>
+ void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item)
+ {
+ Add(item.Key, item.Value);
+ }
+
+ /// <summary>
+ /// Removes all items from the map.
+ /// </summary>
+ public void Clear()
+ {
+ list.Clear();
+ map.Clear();
+ }
+
+ /// <summary>
+ /// Determines whether map contains an entry equivalent to the given key/value pair.
+ /// </summary>
+ /// <param name="item">The key/value pair to find.</param>
+ /// <returns></returns>
+ bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue> item)
+ {
+ TValue value;
+ return TryGetValue(item.Key, out value)
+ && EqualityComparer<TValue>.Default.Equals(item.Value, value);
+ }
+
+ /// <summary>
+ /// Copies the key/value pairs in this map to an array.
+ /// </summary>
+ /// <param name="array">The array to copy the entries into.</param>
+ /// <param name="arrayIndex">The index of the array at which to start copying values.</param>
+ void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
+ {
+ list.CopyTo(array, arrayIndex);
+ }
+
+ /// <summary>
+ /// Removes the specified key/value pair from the map.
+ /// </summary>
+ /// <remarks>Both the key and the value must be found for the entry to be removed.</remarks>
+ /// <param name="item">The key/value pair to remove.</param>
+ /// <returns><c>true</c> if the key/value pair was found and removed; <c>false</c> otherwise.</returns>
+ bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item)
+ {
+ if (item.Key == null)
+ {
+ throw new ArgumentException("Key is null", nameof(item));
+ }
+ LinkedListNode<KeyValuePair<TKey, TValue>> node;
+ if (map.TryGetValue(item.Key, out node) &&
+ EqualityComparer<TValue>.Default.Equals(item.Value, node.Value.Value))
+ {
+ map.Remove(item.Key);
+ node.List.Remove(node);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Gets the number of elements contained in the map.
+ /// </summary>
+ public int Count { get { return list.Count; } }
+
+ /// <summary>
+ /// Gets a value indicating whether the map is read-only.
+ /// </summary>
+ public bool IsReadOnly { get { return false; } }
+
+ /// <summary>
+ /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
+ /// </summary>
+ /// <param name="other">The <see cref="System.Object" /> to compare with this instance.</param>
+ /// <returns>
+ /// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
+ /// </returns>
+ public override bool Equals(object other)
+ {
+ return Equals(other as MapField<TKey, TValue>);
+ }
+
+ /// <summary>
+ /// Returns a hash code for this instance.
+ /// </summary>
+ /// <returns>
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
+ /// </returns>
+ public override int GetHashCode()
+ {
+ var valueComparer = EqualityComparer<TValue>.Default;
+ int hash = 0;
+ foreach (var pair in list)
+ {
+ hash ^= pair.Key.GetHashCode() * 31 + valueComparer.GetHashCode(pair.Value);
+ }
+ return hash;
+ }
+
+ /// <summary>
+ /// Compares this map with another for equality.
+ /// </summary>
+ /// <remarks>
+ /// The order of the key/value pairs in the maps is not deemed significant in this comparison.
+ /// </remarks>
+ /// <param name="other">The map to compare this with.</param>
+ /// <returns><c>true</c> if <paramref name="other"/> refers to an equal map; <c>false</c> otherwise.</returns>
+ public bool Equals(MapField<TKey, TValue> other)
+ {
+ if (other == null)
+ {
+ return false;
+ }
+ if (other == this)
+ {
+ return true;
+ }
+ if (other.Count != this.Count)
+ {
+ return false;
+ }
+ var valueComparer = EqualityComparer<TValue>.Default;
+ foreach (var pair in this)
+ {
+ TValue value;
+ if (!other.TryGetValue(pair.Key, out value))
+ {
+ return false;
+ }
+ if (!valueComparer.Equals(value, pair.Value))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /// <summary>
+ /// Adds entries to the map from the given stream.
+ /// </summary>
+ /// <remarks>
+ /// It is assumed that the stream is initially positioned after the tag specified by the codec.
+ /// This method will continue reading entries from the stream until the end is reached, or
+ /// a different tag is encountered.
+ /// </remarks>
+ /// <param name="input">Stream to read from</param>
+ /// <param name="codec">Codec describing how the key/value pairs are encoded</param>
+ public void AddEntriesFrom(CodedInputStream input, Codec codec)
+ {
+ var adapter = new Codec.MessageAdapter(codec);
+ do
+ {
+ adapter.Reset();
+ input.ReadMessage(adapter);
+ this[adapter.Key] = adapter.Value;
+ } while (input.MaybeConsumeTag(codec.MapTag));
+ }
+
+ /// <summary>
+ /// Writes the contents of this map to the given coded output stream, using the specified codec
+ /// to encode each entry.
+ /// </summary>
+ /// <param name="output">The output stream to write to.</param>
+ /// <param name="codec">The codec to use for each entry.</param>
+ public void WriteTo(CodedOutputStream output, Codec codec)
+ {
+ var message = new Codec.MessageAdapter(codec);
+ foreach (var entry in list)
+ {
+ message.Key = entry.Key;
+ message.Value = entry.Value;
+ output.WriteTag(codec.MapTag);
+ output.WriteMessage(message);
+ }
+ }
+
+ /// <summary>
+ /// Calculates the size of this map based on the given entry codec.
+ /// </summary>
+ /// <param name="codec">The codec to use to encode each entry.</param>
+ /// <returns></returns>
+ public int CalculateSize(Codec codec)
+ {
+ if (Count == 0)
+ {
+ return 0;
+ }
+ var message = new Codec.MessageAdapter(codec);
+ int size = 0;
+ foreach (var entry in list)
+ {
+ message.Key = entry.Key;
+ message.Value = entry.Value;
+ size += CodedOutputStream.ComputeRawVarint32Size(codec.MapTag);
+ size += CodedOutputStream.ComputeMessageSize(message);
+ }
+ return size;
+ }
+
+ /// <summary>
+ /// Returns a string representation of this repeated field, in the same
+ /// way as it would be represented by the default JSON formatter.
+ /// </summary>
+ public override string ToString()
+ {
+ var writer = new StringWriter();
+ JsonFormatter.Default.WriteDictionary(writer, this);
+ return writer.ToString();
+ }
+
+ #region IDictionary explicit interface implementation
+ void IDictionary.Add(object key, object value)
+ {
+ Add((TKey)key, (TValue)value);
+ }
+
+ bool IDictionary.Contains(object key)
+ {
+ if (!(key is TKey))
+ {
+ return false;
+ }
+ return ContainsKey((TKey)key);
+ }
+
+ IDictionaryEnumerator IDictionary.GetEnumerator()
+ {
+ return new DictionaryEnumerator(GetEnumerator());
+ }
+
+ void IDictionary.Remove(object key)
+ {
+ ProtoPreconditions.CheckNotNull(key, nameof(key));
+ if (!(key is TKey))
+ {
+ return;
+ }
+ Remove((TKey)key);
+ }
+
+ void ICollection.CopyTo(Array array, int index)
+ {
+ // This is ugly and slow as heck, but with any luck it will never be used anyway.
+ ICollection temp = this.Select(pair => new DictionaryEntry(pair.Key, pair.Value)).ToList();
+ temp.CopyTo(array, index);
+ }
+
+ bool IDictionary.IsFixedSize { get { return false; } }
+
+ ICollection IDictionary.Keys { get { return (ICollection)Keys; } }
+
+ ICollection IDictionary.Values { get { return (ICollection)Values; } }
+
+ bool ICollection.IsSynchronized { get { return false; } }
+
+ object ICollection.SyncRoot { get { return this; } }
+
+ object IDictionary.this[object key]
+ {
+ get
+ {
+ ProtoPreconditions.CheckNotNull(key, nameof(key));
+ if (!(key is TKey))
+ {
+ return null;
+ }
+ TValue value;
+ TryGetValue((TKey)key, out value);
+ return value;
+ }
+
+ set
+ {
+ this[(TKey)key] = (TValue)value;
+ }
+ }
+ #endregion
+
+ private class DictionaryEnumerator : IDictionaryEnumerator
+ {
+ private readonly IEnumerator<KeyValuePair<TKey, TValue>> enumerator;
+
+ internal DictionaryEnumerator(IEnumerator<KeyValuePair<TKey, TValue>> enumerator)
+ {
+ this.enumerator = enumerator;
+ }
+
+ public bool MoveNext()
+ {
+ return enumerator.MoveNext();
+ }
+
+ public void Reset()
+ {
+ enumerator.Reset();
+ }
+
+ public object Current { get { return Entry; } }
+ public DictionaryEntry Entry { get { return new DictionaryEntry(Key, Value); } }
+ public object Key { get { return enumerator.Current.Key; } }
+ public object Value { get { return enumerator.Current.Value; } }
+ }
+
+ /// <summary>
+ /// A codec for a specific map field. This contains all the information required to encode and
+ /// decode the nested messages.
+ /// </summary>
+ public sealed class Codec
+ {
+ private readonly FieldCodec<TKey> keyCodec;
+ private readonly FieldCodec<TValue> valueCodec;
+ private readonly uint mapTag;
+
+ /// <summary>
+ /// Creates a new entry codec based on a separate key codec and value codec,
+ /// and the tag to use for each map entry.
+ /// </summary>
+ /// <param name="keyCodec">The key codec.</param>
+ /// <param name="valueCodec">The value codec.</param>
+ /// <param name="mapTag">The map tag to use to introduce each map entry.</param>
+ public Codec(FieldCodec<TKey> keyCodec, FieldCodec<TValue> valueCodec, uint mapTag)
+ {
+ this.keyCodec = keyCodec;
+ this.valueCodec = valueCodec;
+ this.mapTag = mapTag;
+ }
+
+ /// <summary>
+ /// The tag used in the enclosing message to indicate map entries.
+ /// </summary>
+ internal uint MapTag { get { return mapTag; } }
+
+ /// <summary>
+ /// A mutable message class, used for parsing and serializing. This
+ /// delegates the work to a codec, but implements the <see cref="IMessage"/> interface
+ /// for interop with <see cref="CodedInputStream"/> and <see cref="CodedOutputStream"/>.
+ /// This is nested inside Codec as it's tightly coupled to the associated codec,
+ /// and it's simpler if it has direct access to all its fields.
+ /// </summary>
+ internal class MessageAdapter : IMessage
+ {
+ private static readonly byte[] ZeroLengthMessageStreamData = new byte[] { 0 };
+
+ private readonly Codec codec;
+ internal TKey Key { get; set; }
+ internal TValue Value { get; set; }
+
+ internal MessageAdapter(Codec codec)
+ {
+ this.codec = codec;
+ }
+
+ internal void Reset()
+ {
+ Key = codec.keyCodec.DefaultValue;
+ Value = codec.valueCodec.DefaultValue;
+ }
+
+ public void MergeFrom(CodedInputStream input)
+ {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0)
+ {
+ if (tag == codec.keyCodec.Tag)
+ {
+ Key = codec.keyCodec.Read(input);
+ }
+ else if (tag == codec.valueCodec.Tag)
+ {
+ Value = codec.valueCodec.Read(input);
+ }
+ else
+ {
+ input.SkipLastField();
+ }
+ }
+
+ // Corner case: a map entry with a key but no value, where the value type is a message.
+ // Read it as if we'd seen an input stream with no data (i.e. create a "default" message).
+ if (Value == null)
+ {
+ Value = codec.valueCodec.Read(new CodedInputStream(ZeroLengthMessageStreamData));
+ }
+ }
+
+ public void WriteTo(CodedOutputStream output)
+ {
+ codec.keyCodec.WriteTagAndValue(output, Key);
+ codec.valueCodec.WriteTagAndValue(output, Value);
+ }
+
+ public int CalculateSize()
+ {
+ return codec.keyCodec.CalculateSizeWithTag(Key) + codec.valueCodec.CalculateSizeWithTag(Value);
+ }
+
+ MessageDescriptor IMessage.Descriptor { get { return null; } }
+ }
+ }
+
+ private class MapView<T> : ICollection<T>, ICollection
+ {
+ private readonly MapField<TKey, TValue> parent;
+ private readonly Func<KeyValuePair<TKey, TValue>, T> projection;
+ private readonly Func<T, bool> containsCheck;
+
+ internal MapView(
+ MapField<TKey, TValue> parent,
+ Func<KeyValuePair<TKey, TValue>, T> projection,
+ Func<T, bool> containsCheck)
+ {
+ this.parent = parent;
+ this.projection = projection;
+ this.containsCheck = containsCheck;
+ }
+
+ public int Count { get { return parent.Count; } }
+
+ public bool IsReadOnly { get { return true; } }
+
+ public bool IsSynchronized { get { return false; } }
+
+ public object SyncRoot { get { return parent; } }
+
+ public void Add(T item)
+ {
+ throw new NotSupportedException();
+ }
+
+ public void Clear()
+ {
+ throw new NotSupportedException();
+ }
+
+ public bool Contains(T item)
+ {
+ return containsCheck(item);
+ }
+
+ public void CopyTo(T[] array, int arrayIndex)
+ {
+ if (arrayIndex < 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(arrayIndex));
+ }
+ if (arrayIndex + Count > array.Length)
+ {
+ throw new ArgumentException("Not enough space in the array", nameof(array));
+ }
+ foreach (var item in this)
+ {
+ array[arrayIndex++] = item;
+ }
+ }
+
+ public IEnumerator<T> GetEnumerator()
+ {
+ return parent.list.Select(projection).GetEnumerator();
+ }
+
+ public bool Remove(T item)
+ {
+ throw new NotSupportedException();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ public void CopyTo(Array array, int index)
+ {
+ if (index < 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(index));
+ }
+ if (index + Count > array.Length)
+ {
+ throw new ArgumentException("Not enough space in the array", nameof(array));
+ }
+ foreach (var item in this)
+ {
+ array.SetValue(item, index++);
+ }
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Collections/ReadOnlyDictionary.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Collections/ReadOnlyDictionary.cs
new file mode 100644
index 0000000000..84360667d8
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Collections/ReadOnlyDictionary.cs
@@ -0,0 +1,147 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace Google.Protobuf.Collections
+{
+ /// <summary>
+ /// Read-only wrapper around another dictionary.
+ /// </summary>
+ internal sealed class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue>
+ {
+ private readonly IDictionary<TKey, TValue> wrapped;
+
+ public ReadOnlyDictionary(IDictionary<TKey, TValue> wrapped)
+ {
+ this.wrapped = wrapped;
+ }
+
+ public void Add(TKey key, TValue value)
+ {
+ throw new InvalidOperationException();
+ }
+
+ public bool ContainsKey(TKey key)
+ {
+ return wrapped.ContainsKey(key);
+ }
+
+ public ICollection<TKey> Keys
+ {
+ get { return wrapped.Keys; }
+ }
+
+ public bool Remove(TKey key)
+ {
+ throw new InvalidOperationException();
+ }
+
+ public bool TryGetValue(TKey key, out TValue value)
+ {
+ return wrapped.TryGetValue(key, out value);
+ }
+
+ public ICollection<TValue> Values
+ {
+ get { return wrapped.Values; }
+ }
+
+ public TValue this[TKey key]
+ {
+ get { return wrapped[key]; }
+ set { throw new InvalidOperationException(); }
+ }
+
+ public void Add(KeyValuePair<TKey, TValue> item)
+ {
+ throw new InvalidOperationException();
+ }
+
+ public void Clear()
+ {
+ throw new InvalidOperationException();
+ }
+
+ public bool Contains(KeyValuePair<TKey, TValue> item)
+ {
+ return wrapped.Contains(item);
+ }
+
+ public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
+ {
+ wrapped.CopyTo(array, arrayIndex);
+ }
+
+ public int Count
+ {
+ get { return wrapped.Count; }
+ }
+
+ public bool IsReadOnly
+ {
+ get { return true; }
+ }
+
+ public bool Remove(KeyValuePair<TKey, TValue> item)
+ {
+ throw new InvalidOperationException();
+ }
+
+ public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
+ {
+ return wrapped.GetEnumerator();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return ((IEnumerable) wrapped).GetEnumerator();
+ }
+
+ public override bool Equals(object obj)
+ {
+ return wrapped.Equals(obj);
+ }
+
+ public override int GetHashCode()
+ {
+ return wrapped.GetHashCode();
+ }
+
+ public override string ToString()
+ {
+ return wrapped.ToString();
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Collections/RepeatedField.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Collections/RepeatedField.cs
new file mode 100755
index 0000000000..6063ff6158
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Collections/RepeatedField.cs
@@ -0,0 +1,594 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+
+namespace Google.Protobuf.Collections
+{
+ /// <summary>
+ /// The contents of a repeated field: essentially, a collection with some extra
+ /// restrictions (no null values) and capabilities (deep cloning).
+ /// </summary>
+ /// <remarks>
+ /// This implementation does not generally prohibit the use of types which are not
+ /// supported by Protocol Buffers but nor does it guarantee that all operations will work in such cases.
+ /// </remarks>
+ /// <typeparam name="T">The element type of the repeated field.</typeparam>
+ public sealed class RepeatedField<T> : IList<T>, IList, IDeepCloneable<RepeatedField<T>>, IEquatable<RepeatedField<T>>
+#if !NET35
+ , IReadOnlyList<T>
+#endif
+ {
+ private static readonly T[] EmptyArray = new T[0];
+ private const int MinArraySize = 8;
+
+ private T[] array = EmptyArray;
+ private int count = 0;
+
+ /// <summary>
+ /// Creates a deep clone of this repeated field.
+ /// </summary>
+ /// <remarks>
+ /// If the field type is
+ /// a message type, each element is also cloned; otherwise, it is
+ /// assumed that the field type is primitive (including string and
+ /// bytes, both of which are immutable) and so a simple copy is
+ /// equivalent to a deep clone.
+ /// </remarks>
+ /// <returns>A deep clone of this repeated field.</returns>
+ public RepeatedField<T> Clone()
+ {
+ RepeatedField<T> clone = new RepeatedField<T>();
+ if (array != EmptyArray)
+ {
+ clone.array = (T[])array.Clone();
+ IDeepCloneable<T>[] cloneableArray = clone.array as IDeepCloneable<T>[];
+ if (cloneableArray != null)
+ {
+ for (int i = 0; i < count; i++)
+ {
+ clone.array[i] = cloneableArray[i].Clone();
+ }
+ }
+ }
+ clone.count = count;
+ return clone;
+ }
+
+ /// <summary>
+ /// Adds the entries from the given input stream, decoding them with the specified codec.
+ /// </summary>
+ /// <param name="input">The input stream to read from.</param>
+ /// <param name="codec">The codec to use in order to read each entry.</param>
+ public void AddEntriesFrom(CodedInputStream input, FieldCodec<T> codec)
+ {
+ // TODO: Inline some of the Add code, so we can avoid checking the size on every
+ // iteration.
+ uint tag = input.LastTag;
+ var reader = codec.ValueReader;
+ // Non-nullable value types can be packed or not.
+ if (FieldCodec<T>.IsPackedRepeatedField(tag))
+ {
+ int length = input.ReadLength();
+ if (length > 0)
+ {
+ int oldLimit = input.PushLimit(length);
+ while (!input.ReachedLimit)
+ {
+ Add(reader(input));
+ }
+ input.PopLimit(oldLimit);
+ }
+ // Empty packed field. Odd, but valid - just ignore.
+ }
+ else
+ {
+ // Not packed... (possibly not packable)
+ do
+ {
+ Add(reader(input));
+ } while (input.MaybeConsumeTag(tag));
+ }
+ }
+
+ /// <summary>
+ /// Calculates the size of this collection based on the given codec.
+ /// </summary>
+ /// <param name="codec">The codec to use when encoding each field.</param>
+ /// <returns>The number of bytes that would be written to a <see cref="CodedOutputStream"/> by <see cref="WriteTo"/>,
+ /// using the same codec.</returns>
+ public int CalculateSize(FieldCodec<T> codec)
+ {
+ if (count == 0)
+ {
+ return 0;
+ }
+ uint tag = codec.Tag;
+ if (codec.PackedRepeatedField)
+ {
+ int dataSize = CalculatePackedDataSize(codec);
+ return CodedOutputStream.ComputeRawVarint32Size(tag) +
+ CodedOutputStream.ComputeLengthSize(dataSize) +
+ dataSize;
+ }
+ else
+ {
+ var sizeCalculator = codec.ValueSizeCalculator;
+ int size = count * CodedOutputStream.ComputeRawVarint32Size(tag);
+ for (int i = 0; i < count; i++)
+ {
+ size += sizeCalculator(array[i]);
+ }
+ return size;
+ }
+ }
+
+ private int CalculatePackedDataSize(FieldCodec<T> codec)
+ {
+ int fixedSize = codec.FixedSize;
+ if (fixedSize == 0)
+ {
+ var calculator = codec.ValueSizeCalculator;
+ int tmp = 0;
+ for (int i = 0; i < count; i++)
+ {
+ tmp += calculator(array[i]);
+ }
+ return tmp;
+ }
+ else
+ {
+ return fixedSize * Count;
+ }
+ }
+
+ /// <summary>
+ /// Writes the contents of this collection to the given <see cref="CodedOutputStream"/>,
+ /// encoding each value using the specified codec.
+ /// </summary>
+ /// <param name="output">The output stream to write to.</param>
+ /// <param name="codec">The codec to use when encoding each value.</param>
+ public void WriteTo(CodedOutputStream output, FieldCodec<T> codec)
+ {
+ if (count == 0)
+ {
+ return;
+ }
+ var writer = codec.ValueWriter;
+ var tag = codec.Tag;
+ if (codec.PackedRepeatedField)
+ {
+ // Packed primitive type
+ uint size = (uint)CalculatePackedDataSize(codec);
+ output.WriteTag(tag);
+ output.WriteRawVarint32(size);
+ for (int i = 0; i < count; i++)
+ {
+ writer(output, array[i]);
+ }
+ }
+ else
+ {
+ // Not packed: a simple tag/value pair for each value.
+ // Can't use codec.WriteTagAndValue, as that omits default values.
+ for (int i = 0; i < count; i++)
+ {
+ output.WriteTag(tag);
+ writer(output, array[i]);
+ }
+ }
+ }
+
+ private void EnsureSize(int size)
+ {
+ if (array.Length < size)
+ {
+ size = Math.Max(size, MinArraySize);
+ int newSize = Math.Max(array.Length * 2, size);
+ var tmp = new T[newSize];
+ Array.Copy(array, 0, tmp, 0, array.Length);
+ array = tmp;
+ }
+ }
+
+ /// <summary>
+ /// Adds the specified item to the collection.
+ /// </summary>
+ /// <param name="item">The item to add.</param>
+ public void Add(T item)
+ {
+ ProtoPreconditions.CheckNotNullUnconstrained(item, nameof(item));
+ EnsureSize(count + 1);
+ array[count++] = item;
+ }
+
+ /// <summary>
+ /// Removes all items from the collection.
+ /// </summary>
+ public void Clear()
+ {
+ array = EmptyArray;
+ count = 0;
+ }
+
+ /// <summary>
+ /// Determines whether this collection contains the given item.
+ /// </summary>
+ /// <param name="item">The item to find.</param>
+ /// <returns><c>true</c> if this collection contains the given item; <c>false</c> otherwise.</returns>
+ public bool Contains(T item)
+ {
+ return IndexOf(item) != -1;
+ }
+
+ /// <summary>
+ /// Copies this collection to the given array.
+ /// </summary>
+ /// <param name="array">The array to copy to.</param>
+ /// <param name="arrayIndex">The first index of the array to copy to.</param>
+ public void CopyTo(T[] array, int arrayIndex)
+ {
+ Array.Copy(this.array, 0, array, arrayIndex, count);
+ }
+
+ /// <summary>
+ /// Removes the specified item from the collection
+ /// </summary>
+ /// <param name="item">The item to remove.</param>
+ /// <returns><c>true</c> if the item was found and removed; <c>false</c> otherwise.</returns>
+ public bool Remove(T item)
+ {
+ int index = IndexOf(item);
+ if (index == -1)
+ {
+ return false;
+ }
+ Array.Copy(array, index + 1, array, index, count - index - 1);
+ count--;
+ array[count] = default(T);
+ return true;
+ }
+
+ /// <summary>
+ /// Gets the number of elements contained in the collection.
+ /// </summary>
+ public int Count => count;
+
+ /// <summary>
+ /// Gets a value indicating whether the collection is read-only.
+ /// </summary>
+ public bool IsReadOnly => false;
+
+ /// <summary>
+ /// Adds all of the specified values into this collection.
+ /// </summary>
+ /// <param name="values">The values to add to this collection.</param>
+ public void AddRange(IEnumerable<T> values)
+ {
+ ProtoPreconditions.CheckNotNull(values, nameof(values));
+
+ // Optimization 1: If the collection we're adding is already a RepeatedField<T>,
+ // we know the values are valid.
+ var otherRepeatedField = values as RepeatedField<T>;
+ if (otherRepeatedField != null)
+ {
+ EnsureSize(count + otherRepeatedField.count);
+ Array.Copy(otherRepeatedField.array, 0, array, count, otherRepeatedField.count);
+ count += otherRepeatedField.count;
+ return;
+ }
+
+ // Optimization 2: The collection is an ICollection, so we can expand
+ // just once and ask the collection to copy itself into the array.
+ var collection = values as ICollection;
+ if (collection != null)
+ {
+ var extraCount = collection.Count;
+ // For reference types and nullable value types, we need to check that there are no nulls
+ // present. (This isn't a thread-safe approach, but we don't advertise this is thread-safe.)
+ // We expect the JITter to optimize this test to true/false, so it's effectively conditional
+ // specialization.
+ if (default(T) == null)
+ {
+ // TODO: Measure whether iterating once to check and then letting the collection copy
+ // itself is faster or slower than iterating and adding as we go. For large
+ // collections this will not be great in terms of cache usage... but the optimized
+ // copy may be significantly faster than doing it one at a time.
+ foreach (var item in collection)
+ {
+ if (item == null)
+ {
+ throw new ArgumentException("Sequence contained null element", nameof(values));
+ }
+ }
+ }
+ EnsureSize(count + extraCount);
+ collection.CopyTo(array, count);
+ count += extraCount;
+ return;
+ }
+
+ // We *could* check for ICollection<T> as well, but very very few collections implement
+ // ICollection<T> but not ICollection. (HashSet<T> does, for one...)
+
+ // Fall back to a slower path of adding items one at a time.
+ foreach (T item in values)
+ {
+ Add(item);
+ }
+ }
+
+ /// <summary>
+ /// Adds all of the specified values into this collection. This method is present to
+ /// allow repeated fields to be constructed from queries within collection initializers.
+ /// Within non-collection-initializer code, consider using the equivalent <see cref="AddRange"/>
+ /// method instead for clarity.
+ /// </summary>
+ /// <param name="values">The values to add to this collection.</param>
+ public void Add(IEnumerable<T> values)
+ {
+ AddRange(values);
+ }
+
+ /// <summary>
+ /// Returns an enumerator that iterates through the collection.
+ /// </summary>
+ /// <returns>
+ /// An enumerator that can be used to iterate through the collection.
+ /// </returns>
+ public IEnumerator<T> GetEnumerator()
+ {
+ for (int i = 0; i < count; i++)
+ {
+ yield return array[i];
+ }
+ }
+
+ /// <summary>
+ /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
+ /// </summary>
+ /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
+ /// <returns>
+ /// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
+ /// </returns>
+ public override bool Equals(object obj)
+ {
+ return Equals(obj as RepeatedField<T>);
+ }
+
+ /// <summary>
+ /// Returns an enumerator that iterates through a collection.
+ /// </summary>
+ /// <returns>
+ /// An <see cref="T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection.
+ /// </returns>
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ /// <summary>
+ /// Returns a hash code for this instance.
+ /// </summary>
+ /// <returns>
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
+ /// </returns>
+ public override int GetHashCode()
+ {
+ int hash = 0;
+ for (int i = 0; i < count; i++)
+ {
+ hash = hash * 31 + array[i].GetHashCode();
+ }
+ return hash;
+ }
+
+ /// <summary>
+ /// Compares this repeated field with another for equality.
+ /// </summary>
+ /// <param name="other">The repeated field to compare this with.</param>
+ /// <returns><c>true</c> if <paramref name="other"/> refers to an equal repeated field; <c>false</c> otherwise.</returns>
+ public bool Equals(RepeatedField<T> other)
+ {
+ if (ReferenceEquals(other, null))
+ {
+ return false;
+ }
+ if (ReferenceEquals(other, this))
+ {
+ return true;
+ }
+ if (other.Count != this.Count)
+ {
+ return false;
+ }
+ EqualityComparer<T> comparer = EqualityComparer<T>.Default;
+ for (int i = 0; i < count; i++)
+ {
+ if (!comparer.Equals(array[i], other.array[i]))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /// <summary>
+ /// Returns the index of the given item within the collection, or -1 if the item is not
+ /// present.
+ /// </summary>
+ /// <param name="item">The item to find in the collection.</param>
+ /// <returns>The zero-based index of the item, or -1 if it is not found.</returns>
+ public int IndexOf(T item)
+ {
+ ProtoPreconditions.CheckNotNullUnconstrained(item, nameof(item));
+ EqualityComparer<T> comparer = EqualityComparer<T>.Default;
+ for (int i = 0; i < count; i++)
+ {
+ if (comparer.Equals(array[i], item))
+ {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /// <summary>
+ /// Inserts the given item at the specified index.
+ /// </summary>
+ /// <param name="index">The index at which to insert the item.</param>
+ /// <param name="item">The item to insert.</param>
+ public void Insert(int index, T item)
+ {
+ ProtoPreconditions.CheckNotNullUnconstrained(item, nameof(item));
+ if (index < 0 || index > count)
+ {
+ throw new ArgumentOutOfRangeException(nameof(index));
+ }
+ EnsureSize(count + 1);
+ Array.Copy(array, index, array, index + 1, count - index);
+ array[index] = item;
+ count++;
+ }
+
+ /// <summary>
+ /// Removes the item at the given index.
+ /// </summary>
+ /// <param name="index">The zero-based index of the item to remove.</param>
+ public void RemoveAt(int index)
+ {
+ if (index < 0 || index >= count)
+ {
+ throw new ArgumentOutOfRangeException(nameof(index));
+ }
+ Array.Copy(array, index + 1, array, index, count - index - 1);
+ count--;
+ array[count] = default(T);
+ }
+
+ /// <summary>
+ /// Returns a string representation of this repeated field, in the same
+ /// way as it would be represented by the default JSON formatter.
+ /// </summary>
+ public override string ToString()
+ {
+ var writer = new StringWriter();
+ JsonFormatter.Default.WriteList(writer, this);
+ return writer.ToString();
+ }
+
+ /// <summary>
+ /// Gets or sets the item at the specified index.
+ /// </summary>
+ /// <value>
+ /// The element at the specified index.
+ /// </value>
+ /// <param name="index">The zero-based index of the element to get or set.</param>
+ /// <returns>The item at the specified index.</returns>
+ public T this[int index]
+ {
+ get
+ {
+ if (index < 0 || index >= count)
+ {
+ throw new ArgumentOutOfRangeException(nameof(index));
+ }
+ return array[index];
+ }
+ set
+ {
+ if (index < 0 || index >= count)
+ {
+ throw new ArgumentOutOfRangeException(nameof(index));
+ }
+ ProtoPreconditions.CheckNotNullUnconstrained(value, nameof(value));
+ array[index] = value;
+ }
+ }
+
+ #region Explicit interface implementation for IList and ICollection.
+ bool IList.IsFixedSize => false;
+
+ void ICollection.CopyTo(Array array, int index)
+ {
+ Array.Copy(this.array, 0, array, index, count);
+ }
+
+ bool ICollection.IsSynchronized => false;
+
+ object ICollection.SyncRoot => this;
+
+ object IList.this[int index]
+ {
+ get { return this[index]; }
+ set { this[index] = (T)value; }
+ }
+
+ int IList.Add(object value)
+ {
+ Add((T) value);
+ return count - 1;
+ }
+
+ bool IList.Contains(object value)
+ {
+ return (value is T && Contains((T)value));
+ }
+
+ int IList.IndexOf(object value)
+ {
+ if (!(value is T))
+ {
+ return -1;
+ }
+ return IndexOf((T)value);
+ }
+
+ void IList.Insert(int index, object value)
+ {
+ Insert(index, (T) value);
+ }
+
+ void IList.Remove(object value)
+ {
+ if (!(value is T))
+ {
+ return;
+ }
+ Remove((T)value);
+ }
+ #endregion
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs
new file mode 100755
index 0000000000..95a02c727f
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Compatibility/PropertyInfoExtensions.cs
@@ -0,0 +1,72 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System.Reflection;
+
+namespace Google.Protobuf.Compatibility
+{
+ /// <summary>
+ /// Extension methods for <see cref="PropertyInfo"/>, effectively providing
+ /// the familiar members from previous desktop framework versions while
+ /// targeting the newer releases, .NET Core etc.
+ /// </summary>
+ internal static class PropertyInfoExtensions
+ {
+ /// <summary>
+ /// Returns the public getter of a property, or null if there is no such getter
+ /// (either because it's read-only, or the getter isn't public).
+ /// </summary>
+ internal static MethodInfo GetGetMethod(this PropertyInfo target)
+ {
+#if NET35
+ var method = target.GetGetMethod();
+#else
+ var method = target.GetMethod;
+#endif
+ return method != null && method.IsPublic ? method : null;
+ }
+
+ /// <summary>
+ /// Returns the public setter of a property, or null if there is no such setter
+ /// (either because it's write-only, or the setter isn't public).
+ /// </summary>
+ internal static MethodInfo GetSetMethod(this PropertyInfo target)
+ {
+#if NET35
+ var method = target.GetSetMethod();
+#else
+ var method = target.SetMethod;
+#endif
+ return method != null && method.IsPublic ? method : null;
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Compatibility/StreamExtensions.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Compatibility/StreamExtensions.cs
new file mode 100755
index 0000000000..bf4bf22018
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Compatibility/StreamExtensions.cs
@@ -0,0 +1,66 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+#if NET35
+using System;
+using System.IO;
+
+namespace Google.Protobuf.Compatibility
+{
+ /// <summary>
+ /// Extension methods for <see cref="Stream"/> in order to provide
+ /// backwards compatibility with .NET 3.5
+ /// </summary>
+ public static class StreamExtensions
+ {
+ // 81920 seems to be the default buffer size used in .NET 4.5.1
+ private const int BUFFER_SIZE = 81920;
+
+ /// <summary>
+ /// Write the contents of the current stream to the destination stream
+ /// </summary>
+ public static void CopyTo(this Stream source, Stream destination)
+ {
+ if (destination == null)
+ {
+ throw new ArgumentNullException(nameof(destination));
+ }
+
+ byte[] buffer = new byte[BUFFER_SIZE];
+ int numBytesRead;
+ while ((numBytesRead = source.Read(buffer, 0, buffer.Length)) > 0) {
+ destination.Write(buffer, 0, numBytesRead);
+ }
+ }
+ }
+}
+#endif
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs
new file mode 100755
index 0000000000..2f23713819
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Compatibility/TypeExtensions.cs
@@ -0,0 +1,106 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.Reflection;
+
+#if !NET35
+namespace Google.Protobuf.Compatibility
+{
+ /// <summary>
+ /// Provides extension methods on Type that just proxy to TypeInfo.
+ /// These are used to support the new type system from .NET 4.5, without
+ /// having calls to GetTypeInfo all over the place. While the methods here are meant to be
+ /// broadly compatible with the desktop framework, there are some subtle differences in behaviour - but
+ /// they're not expected to affect our use cases. While the class is internal, that should be fine: we can
+ /// evaluate each new use appropriately.
+ /// </summary>
+ internal static class TypeExtensions
+ {
+ /// <summary>
+ /// See https://msdn.microsoft.com/en-us/library/system.type.isassignablefrom
+ /// </summary>
+ internal static bool IsAssignableFrom(this Type target, Type c)
+ {
+ return target.GetTypeInfo().IsAssignableFrom(c.GetTypeInfo());
+ }
+
+ /// <summary>
+ /// Returns a representation of the public property associated with the given name in the given type,
+ /// including inherited properties or null if there is no such public property.
+ /// Here, "public property" means a property where either the getter, or the setter, or both, is public.
+ /// </summary>
+ internal static PropertyInfo GetProperty(this Type target, string name)
+ {
+ // GetDeclaredProperty only returns properties declared in the given type, so we need to recurse.
+ while (target != null)
+ {
+ var typeInfo = target.GetTypeInfo();
+ var ret = typeInfo.GetDeclaredProperty(name);
+ if (ret != null && ((ret.CanRead && ret.GetMethod.IsPublic) || (ret.CanWrite && ret.SetMethod.IsPublic)))
+ {
+ return ret;
+ }
+ target = typeInfo.BaseType;
+ }
+ return null;
+ }
+
+ /// <summary>
+ /// Returns a representation of the public method associated with the given name in the given type,
+ /// including inherited methods.
+ /// </summary>
+ /// <remarks>
+ /// This has a few differences compared with Type.GetMethod in the desktop framework. It will throw
+ /// if there is an ambiguous match even between a private method and a public one, but it *won't* throw
+ /// if there are two overloads at different levels in the type hierarchy (e.g. class Base declares public void Foo(int) and
+ /// class Child : Base declares public void Foo(long)).
+ /// </remarks>
+ /// <exception cref="AmbiguousMatchException">One type in the hierarchy declared more than one method with the same name</exception>
+ internal static MethodInfo GetMethod(this Type target, string name)
+ {
+ // GetDeclaredMethod only returns methods declared in the given type, so we need to recurse.
+ while (target != null)
+ {
+ var typeInfo = target.GetTypeInfo();
+ var ret = typeInfo.GetDeclaredMethod(name);
+ if (ret != null && ret.IsPublic)
+ {
+ return ret;
+ }
+ target = typeInfo.BaseType;
+ }
+ return null;
+ }
+ }
+}
+#endif
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/FieldCodec.cs b/third_party/protobuf/csharp/src/Google.Protobuf/FieldCodec.cs
new file mode 100644
index 0000000000..c28b47e1eb
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/FieldCodec.cs
@@ -0,0 +1,474 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using Google.Protobuf.Compatibility;
+using Google.Protobuf.WellKnownTypes;
+using System;
+using System.Collections.Generic;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Factory methods for <see cref="FieldCodec{T}"/>.
+ /// </summary>
+ public static class FieldCodec
+ {
+ // TODO: Avoid the "dual hit" of lambda expressions: create open delegates instead. (At least test...)
+
+ /// <summary>
+ /// Retrieves a codec suitable for a string field with the given tag.
+ /// </summary>
+ /// <param name="tag">The tag.</param>
+ /// <returns>A codec for the given tag.</returns>
+ public static FieldCodec<string> ForString(uint tag)
+ {
+ return new FieldCodec<string>(input => input.ReadString(), (output, value) => output.WriteString(value), CodedOutputStream.ComputeStringSize, tag);
+ }
+
+ /// <summary>
+ /// Retrieves a codec suitable for a bytes field with the given tag.
+ /// </summary>
+ /// <param name="tag">The tag.</param>
+ /// <returns>A codec for the given tag.</returns>
+ public static FieldCodec<ByteString> ForBytes(uint tag)
+ {
+ return new FieldCodec<ByteString>(input => input.ReadBytes(), (output, value) => output.WriteBytes(value), CodedOutputStream.ComputeBytesSize, tag);
+ }
+
+ /// <summary>
+ /// Retrieves a codec suitable for a bool field with the given tag.
+ /// </summary>
+ /// <param name="tag">The tag.</param>
+ /// <returns>A codec for the given tag.</returns>
+ public static FieldCodec<bool> ForBool(uint tag)
+ {
+ return new FieldCodec<bool>(input => input.ReadBool(), (output, value) => output.WriteBool(value), CodedOutputStream.ComputeBoolSize, tag);
+ }
+
+ /// <summary>
+ /// Retrieves a codec suitable for an int32 field with the given tag.
+ /// </summary>
+ /// <param name="tag">The tag.</param>
+ /// <returns>A codec for the given tag.</returns>
+ public static FieldCodec<int> ForInt32(uint tag)
+ {
+ return new FieldCodec<int>(input => input.ReadInt32(), (output, value) => output.WriteInt32(value), CodedOutputStream.ComputeInt32Size, tag);
+ }
+
+ /// <summary>
+ /// Retrieves a codec suitable for an sint32 field with the given tag.
+ /// </summary>
+ /// <param name="tag">The tag.</param>
+ /// <returns>A codec for the given tag.</returns>
+ public static FieldCodec<int> ForSInt32(uint tag)
+ {
+ return new FieldCodec<int>(input => input.ReadSInt32(), (output, value) => output.WriteSInt32(value), CodedOutputStream.ComputeSInt32Size, tag);
+ }
+
+ /// <summary>
+ /// Retrieves a codec suitable for a fixed32 field with the given tag.
+ /// </summary>
+ /// <param name="tag">The tag.</param>
+ /// <returns>A codec for the given tag.</returns>
+ public static FieldCodec<uint> ForFixed32(uint tag)
+ {
+ return new FieldCodec<uint>(input => input.ReadFixed32(), (output, value) => output.WriteFixed32(value), 4, tag);
+ }
+
+ /// <summary>
+ /// Retrieves a codec suitable for an sfixed32 field with the given tag.
+ /// </summary>
+ /// <param name="tag">The tag.</param>
+ /// <returns>A codec for the given tag.</returns>
+ public static FieldCodec<int> ForSFixed32(uint tag)
+ {
+ return new FieldCodec<int>(input => input.ReadSFixed32(), (output, value) => output.WriteSFixed32(value), 4, tag);
+ }
+
+ /// <summary>
+ /// Retrieves a codec suitable for a uint32 field with the given tag.
+ /// </summary>
+ /// <param name="tag">The tag.</param>
+ /// <returns>A codec for the given tag.</returns>
+ public static FieldCodec<uint> ForUInt32(uint tag)
+ {
+ return new FieldCodec<uint>(input => input.ReadUInt32(), (output, value) => output.WriteUInt32(value), CodedOutputStream.ComputeUInt32Size, tag);
+ }
+
+ /// <summary>
+ /// Retrieves a codec suitable for an int64 field with the given tag.
+ /// </summary>
+ /// <param name="tag">The tag.</param>
+ /// <returns>A codec for the given tag.</returns>
+ public static FieldCodec<long> ForInt64(uint tag)
+ {
+ return new FieldCodec<long>(input => input.ReadInt64(), (output, value) => output.WriteInt64(value), CodedOutputStream.ComputeInt64Size, tag);
+ }
+
+ /// <summary>
+ /// Retrieves a codec suitable for an sint64 field with the given tag.
+ /// </summary>
+ /// <param name="tag">The tag.</param>
+ /// <returns>A codec for the given tag.</returns>
+ public static FieldCodec<long> ForSInt64(uint tag)
+ {
+ return new FieldCodec<long>(input => input.ReadSInt64(), (output, value) => output.WriteSInt64(value), CodedOutputStream.ComputeSInt64Size, tag);
+ }
+
+ /// <summary>
+ /// Retrieves a codec suitable for a fixed64 field with the given tag.
+ /// </summary>
+ /// <param name="tag">The tag.</param>
+ /// <returns>A codec for the given tag.</returns>
+ public static FieldCodec<ulong> ForFixed64(uint tag)
+ {
+ return new FieldCodec<ulong>(input => input.ReadFixed64(), (output, value) => output.WriteFixed64(value), 8, tag);
+ }
+
+ /// <summary>
+ /// Retrieves a codec suitable for an sfixed64 field with the given tag.
+ /// </summary>
+ /// <param name="tag">The tag.</param>
+ /// <returns>A codec for the given tag.</returns>
+ public static FieldCodec<long> ForSFixed64(uint tag)
+ {
+ return new FieldCodec<long>(input => input.ReadSFixed64(), (output, value) => output.WriteSFixed64(value), 8, tag);
+ }
+
+ /// <summary>
+ /// Retrieves a codec suitable for a uint64 field with the given tag.
+ /// </summary>
+ /// <param name="tag">The tag.</param>
+ /// <returns>A codec for the given tag.</returns>
+ public static FieldCodec<ulong> ForUInt64(uint tag)
+ {
+ return new FieldCodec<ulong>(input => input.ReadUInt64(), (output, value) => output.WriteUInt64(value), CodedOutputStream.ComputeUInt64Size, tag);
+ }
+
+ /// <summary>
+ /// Retrieves a codec suitable for a float field with the given tag.
+ /// </summary>
+ /// <param name="tag">The tag.</param>
+ /// <returns>A codec for the given tag.</returns>
+ public static FieldCodec<float> ForFloat(uint tag)
+ {
+ return new FieldCodec<float>(input => input.ReadFloat(), (output, value) => output.WriteFloat(value), CodedOutputStream.ComputeFloatSize, tag);
+ }
+
+ /// <summary>
+ /// Retrieves a codec suitable for a double field with the given tag.
+ /// </summary>
+ /// <param name="tag">The tag.</param>
+ /// <returns>A codec for the given tag.</returns>
+ public static FieldCodec<double> ForDouble(uint tag)
+ {
+ return new FieldCodec<double>(input => input.ReadDouble(), (output, value) => output.WriteDouble(value), CodedOutputStream.ComputeDoubleSize, tag);
+ }
+
+ // Enums are tricky. We can probably use expression trees to build these delegates automatically,
+ // but it's easy to generate the code for it.
+
+ /// <summary>
+ /// Retrieves a codec suitable for an enum field with the given tag.
+ /// </summary>
+ /// <param name="tag">The tag.</param>
+ /// <param name="toInt32">A conversion function from <see cref="Int32"/> to the enum type.</param>
+ /// <param name="fromInt32">A conversion function from the enum type to <see cref="Int32"/>.</param>
+ /// <returns>A codec for the given tag.</returns>
+ public static FieldCodec<T> ForEnum<T>(uint tag, Func<T, int> toInt32, Func<int, T> fromInt32)
+ {
+ return new FieldCodec<T>(input => fromInt32(
+ input.ReadEnum()),
+ (output, value) => output.WriteEnum(toInt32(value)),
+ value => CodedOutputStream.ComputeEnumSize(toInt32(value)), tag);
+ }
+
+ /// <summary>
+ /// Retrieves a codec suitable for a message field with the given tag.
+ /// </summary>
+ /// <param name="tag">The tag.</param>
+ /// <param name="parser">A parser to use for the message type.</param>
+ /// <returns>A codec for the given tag.</returns>
+ public static FieldCodec<T> ForMessage<T>(uint tag, MessageParser<T> parser) where T : IMessage<T>
+ {
+ return new FieldCodec<T>(input => { T message = parser.CreateTemplate(); input.ReadMessage(message); return message; },
+ (output, value) => output.WriteMessage(value), message => CodedOutputStream.ComputeMessageSize(message), tag);
+ }
+
+ /// <summary>
+ /// Creates a codec for a wrapper type of a class - which must be string or ByteString.
+ /// </summary>
+ public static FieldCodec<T> ForClassWrapper<T>(uint tag) where T : class
+ {
+ var nestedCodec = WrapperCodecs.GetCodec<T>();
+ return new FieldCodec<T>(
+ input => WrapperCodecs.Read<T>(input, nestedCodec),
+ (output, value) => WrapperCodecs.Write<T>(output, value, nestedCodec),
+ value => WrapperCodecs.CalculateSize<T>(value, nestedCodec),
+ tag,
+ null); // Default value for the wrapper
+ }
+
+ /// <summary>
+ /// Creates a codec for a wrapper type of a struct - which must be Int32, Int64, UInt32, UInt64,
+ /// Bool, Single or Double.
+ /// </summary>
+ public static FieldCodec<T?> ForStructWrapper<T>(uint tag) where T : struct
+ {
+ var nestedCodec = WrapperCodecs.GetCodec<T>();
+ return new FieldCodec<T?>(
+ input => WrapperCodecs.Read<T>(input, nestedCodec),
+ (output, value) => WrapperCodecs.Write<T>(output, value.Value, nestedCodec),
+ value => value == null ? 0 : WrapperCodecs.CalculateSize<T>(value.Value, nestedCodec),
+ tag,
+ null); // Default value for the wrapper
+ }
+
+ /// <summary>
+ /// Helper code to create codecs for wrapper types.
+ /// </summary>
+ /// <remarks>
+ /// Somewhat ugly with all the static methods, but the conversions involved to/from nullable types make it
+ /// slightly tricky to improve. So long as we keep the public API (ForClassWrapper, ForStructWrapper) in place,
+ /// we can refactor later if we come up with something cleaner.
+ /// </remarks>
+ private static class WrapperCodecs
+ {
+ private static readonly Dictionary<System.Type, object> Codecs = new Dictionary<System.Type, object>
+ {
+ { typeof(bool), ForBool(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Varint)) },
+ { typeof(int), ForInt32(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Varint)) },
+ { typeof(long), ForInt64(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Varint)) },
+ { typeof(uint), ForUInt32(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Varint)) },
+ { typeof(ulong), ForUInt64(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Varint)) },
+ { typeof(float), ForFloat(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Fixed32)) },
+ { typeof(double), ForDouble(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Fixed64)) },
+ { typeof(string), ForString(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.LengthDelimited)) },
+ { typeof(ByteString), ForBytes(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.LengthDelimited)) }
+ };
+
+ /// <summary>
+ /// Returns a field codec which effectively wraps a value of type T in a message.
+ ///
+ /// </summary>
+ internal static FieldCodec<T> GetCodec<T>()
+ {
+ object value;
+ if (!Codecs.TryGetValue(typeof(T), out value))
+ {
+ throw new InvalidOperationException("Invalid type argument requested for wrapper codec: " + typeof(T));
+ }
+ return (FieldCodec<T>) value;
+ }
+
+ internal static T Read<T>(CodedInputStream input, FieldCodec<T> codec)
+ {
+ int length = input.ReadLength();
+ int oldLimit = input.PushLimit(length);
+
+ uint tag;
+ T value = codec.DefaultValue;
+ while ((tag = input.ReadTag()) != 0)
+ {
+ if (tag == codec.Tag)
+ {
+ value = codec.Read(input);
+ }
+ else
+ {
+ input.SkipLastField();
+ }
+
+ }
+ input.CheckReadEndOfStreamTag();
+ input.PopLimit(oldLimit);
+
+ return value;
+ }
+
+ internal static void Write<T>(CodedOutputStream output, T value, FieldCodec<T> codec)
+ {
+ output.WriteLength(codec.CalculateSizeWithTag(value));
+ codec.WriteTagAndValue(output, value);
+ }
+
+ internal static int CalculateSize<T>(T value, FieldCodec<T> codec)
+ {
+ int fieldLength = codec.CalculateSizeWithTag(value);
+ return CodedOutputStream.ComputeLengthSize(fieldLength) + fieldLength;
+ }
+ }
+ }
+
+ /// <summary>
+ /// <para>
+ /// An encode/decode pair for a single field. This effectively encapsulates
+ /// all the information needed to read or write the field value from/to a coded
+ /// stream.
+ /// </para>
+ /// <para>
+ /// This class is public and has to be as it is used by generated code, but its public
+ /// API is very limited - just what the generated code needs to call directly.
+ /// </para>
+ /// </summary>
+ /// <remarks>
+ /// This never writes default values to the stream, and does not address "packedness"
+ /// in repeated fields itself, other than to know whether or not the field *should* be packed.
+ /// </remarks>
+ public sealed class FieldCodec<T>
+ {
+ private static readonly T DefaultDefault;
+ // Only non-nullable value types support packing. This is the simplest way of detecting that.
+ private static readonly bool TypeSupportsPacking = default(T) != null;
+
+ static FieldCodec()
+ {
+ if (typeof(T) == typeof(string))
+ {
+ DefaultDefault = (T)(object)"";
+ }
+ else if (typeof(T) == typeof(ByteString))
+ {
+ DefaultDefault = (T)(object)ByteString.Empty;
+ }
+ // Otherwise it's the default value of the CLR type
+ }
+
+ internal static bool IsPackedRepeatedField(uint tag) =>
+ TypeSupportsPacking && WireFormat.GetTagWireType(tag) == WireFormat.WireType.LengthDelimited;
+
+ internal bool PackedRepeatedField { get; }
+
+ /// <summary>
+ /// Returns a delegate to write a value (unconditionally) to a coded output stream.
+ /// </summary>
+ internal Action<CodedOutputStream, T> ValueWriter { get; }
+
+ /// <summary>
+ /// Returns the size calculator for just a value.
+ /// </summary>
+ internal Func<T, int> ValueSizeCalculator { get; }
+
+ /// <summary>
+ /// Returns a delegate to read a value from a coded input stream. It is assumed that
+ /// the stream is already positioned on the appropriate tag.
+ /// </summary>
+ internal Func<CodedInputStream, T> ValueReader { get; }
+
+ /// <summary>
+ /// Returns the fixed size for an entry, or 0 if sizes vary.
+ /// </summary>
+ internal int FixedSize { get; }
+
+ /// <summary>
+ /// Gets the tag of the codec.
+ /// </summary>
+ /// <value>
+ /// The tag of the codec.
+ /// </value>
+ internal uint Tag { get; }
+
+ /// <summary>
+ /// Default value for this codec. Usually the same for every instance of the same type, but
+ /// for string/ByteString wrapper fields the codec's default value is null, whereas for
+ /// other string/ByteString fields it's "" or ByteString.Empty.
+ /// </summary>
+ /// <value>
+ /// The default value of the codec's type.
+ /// </value>
+ internal T DefaultValue { get; }
+
+ private readonly int tagSize;
+
+ internal FieldCodec(
+ Func<CodedInputStream, T> reader,
+ Action<CodedOutputStream, T> writer,
+ int fixedSize,
+ uint tag) : this(reader, writer, _ => fixedSize, tag)
+ {
+ FixedSize = fixedSize;
+ }
+
+ internal FieldCodec(
+ Func<CodedInputStream, T> reader,
+ Action<CodedOutputStream, T> writer,
+ Func<T, int> sizeCalculator,
+ uint tag) : this(reader, writer, sizeCalculator, tag, DefaultDefault)
+ {
+ }
+
+ internal FieldCodec(
+ Func<CodedInputStream, T> reader,
+ Action<CodedOutputStream, T> writer,
+ Func<T, int> sizeCalculator,
+ uint tag,
+ T defaultValue)
+ {
+ ValueReader = reader;
+ ValueWriter = writer;
+ ValueSizeCalculator = sizeCalculator;
+ FixedSize = 0;
+ Tag = tag;
+ DefaultValue = defaultValue;
+ tagSize = CodedOutputStream.ComputeRawVarint32Size(tag);
+ // Detect packed-ness once, so we can check for it within RepeatedField<T>.
+ PackedRepeatedField = IsPackedRepeatedField(tag);
+ }
+
+ /// <summary>
+ /// Write a tag and the given value, *if* the value is not the default.
+ /// </summary>
+ public void WriteTagAndValue(CodedOutputStream output, T value)
+ {
+ if (!IsDefault(value))
+ {
+ output.WriteTag(Tag);
+ ValueWriter(output, value);
+ }
+ }
+
+ /// <summary>
+ /// Reads a value of the codec type from the given <see cref="CodedInputStream"/>.
+ /// </summary>
+ /// <param name="input">The input stream to read from.</param>
+ /// <returns>The value read from the stream.</returns>
+ public T Read(CodedInputStream input) => ValueReader(input);
+
+ /// <summary>
+ /// Calculates the size required to write the given value, with a tag,
+ /// if the value is not the default.
+ /// </summary>
+ public int CalculateSizeWithTag(T value) => IsDefault(value) ? 0 : ValueSizeCalculator(value) + tagSize;
+
+ private bool IsDefault(T value) => EqualityComparer<T>.Default.Equals(value, DefaultValue);
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/FrameworkPortability.cs b/third_party/protobuf/csharp/src/Google.Protobuf/FrameworkPortability.cs
new file mode 100644
index 0000000000..9498dbe4cc
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/FrameworkPortability.cs
@@ -0,0 +1,49 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.Text.RegularExpressions;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Class containing helpful workarounds for various platform compatibility
+ /// </summary>
+ internal static class FrameworkPortability
+ {
+ // The value of RegexOptions.Compiled is 8. We can test for the presence at
+ // execution time using Enum.IsDefined, so a single build will do the right thing
+ // on each platform. (RegexOptions.Compiled isn't supported by PCLs.)
+ internal static readonly RegexOptions CompiledRegexWhereAvailable =
+ Enum.IsDefined(typeof(RegexOptions), 8) ? (RegexOptions)8 : RegexOptions.None;
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Google.Protobuf.xproj b/third_party/protobuf/csharp/src/Google.Protobuf/Google.Protobuf.xproj
new file mode 100644
index 0000000000..c68e0db31a
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Google.Protobuf.xproj
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
+ <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>9b576380-726d-4142-8238-60a43ab0e35a</ProjectGuid>
+ <RootNamespace>Google.Protobuf</RootNamespace>
+ <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
+ <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <SchemaVersion>2.0</SchemaVersion>
+ </PropertyGroup>
+ <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
+</Project> \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/ICustomDiagnosticMessage.cs b/third_party/protobuf/csharp/src/Google.Protobuf/ICustomDiagnosticMessage.cs
new file mode 100644
index 0000000000..a0090569f1
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/ICustomDiagnosticMessage.cs
@@ -0,0 +1,69 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 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.
+#endregion
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// A message type that has a custom string format for diagnostic purposes.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// Calling <see cref="object.ToString"/> on a generated message type normally
+ /// returns the JSON representation. If a message type implements this interface,
+ /// then the <see cref="ToDiagnosticString"/> method will be called instead of the regular
+ /// JSON formatting code, but only when <c>ToString()</c> is called either on the message itself
+ /// or on another message which contains it. This does not affect the normal JSON formatting of
+ /// the message.
+ /// </para>
+ /// <para>
+ /// For example, if you create a proto message representing a GUID, the internal
+ /// representation may be a <c>bytes</c> field or four <c>fixed32</c> fields. However, when debugging
+ /// it may be more convenient to see a result in the same format as <see cref="System.Guid"/> provides.
+ /// </para>
+ /// <para>This interface extends <see cref="IMessage"/> to avoid it accidentally being implemented
+ /// on types other than messages, where it would not be used by anything in the framework.</para>
+ /// </remarks>
+ public interface ICustomDiagnosticMessage : IMessage
+ {
+ /// <summary>
+ /// Returns a string representation of this object, for diagnostic purposes.
+ /// </summary>
+ /// <remarks>
+ /// This method is called when a message is formatted as part of a <see cref="object.ToString"/>
+ /// call. It does not affect the JSON representation used by <see cref="JsonFormatter"/> other than
+ /// in calls to <see cref="JsonFormatter.ToDiagnosticString(IMessage)"/>. While it is recommended
+ /// that the result is valid JSON, this is never assumed by the Protobuf library.
+ /// </remarks>
+ /// <returns>A string representation of this object, for diagnostic purposes.</returns>
+ string ToDiagnosticString();
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/IDeepCloneable.cs b/third_party/protobuf/csharp/src/Google.Protobuf/IDeepCloneable.cs
new file mode 100644
index 0000000000..c9c71bbe2c
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/IDeepCloneable.cs
@@ -0,0 +1,54 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Generic interface for a deeply cloneable type.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// All generated messages implement this interface, but so do some non-message types.
+ /// Additionally, due to the type constraint on <c>T</c> in <see cref="IMessage{T}"/>,
+ /// it is simpler to keep this as a separate interface.
+ /// </para>
+ /// </remarks>
+ /// <typeparam name="T">The type itself, returned by the <see cref="Clone"/> method.</typeparam>
+ public interface IDeepCloneable<T>
+ {
+ /// <summary>
+ /// Creates a deep clone of this object.
+ /// </summary>
+ /// <returns>A deep clone of this object.</returns>
+ T Clone();
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/IMessage.cs b/third_party/protobuf/csharp/src/Google.Protobuf/IMessage.cs
new file mode 100644
index 0000000000..d089f94639
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/IMessage.cs
@@ -0,0 +1,87 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using Google.Protobuf.Reflection;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Interface for a Protocol Buffers message, supporting
+ /// basic operations required for serialization.
+ /// </summary>
+ public interface IMessage
+ {
+ /// <summary>
+ /// Merges the data from the specified coded input stream with the current message.
+ /// </summary>
+ /// <remarks>See the user guide for precise merge semantics.</remarks>
+ /// <param name="input"></param>
+ void MergeFrom(CodedInputStream input);
+
+ /// <summary>
+ /// Writes the data to the given coded output stream.
+ /// </summary>
+ /// <param name="output">Coded output stream to write the data to. Must not be null.</param>
+ void WriteTo(CodedOutputStream output);
+
+ /// <summary>
+ /// Calculates the size of this message in Protocol Buffer wire format, in bytes.
+ /// </summary>
+ /// <returns>The number of bytes required to write this message
+ /// to a coded output stream.</returns>
+ int CalculateSize();
+
+ /// <summary>
+ /// Descriptor for this message. All instances are expected to return the same descriptor,
+ /// and for generated types this will be an explicitly-implemented member, returning the
+ /// same value as the static property declared on the type.
+ /// </summary>
+ MessageDescriptor Descriptor { get; }
+ }
+
+ /// <summary>
+ /// Generic interface for a Protocol Buffers message,
+ /// where the type parameter is expected to be the same type as
+ /// the implementation class.
+ /// </summary>
+ /// <typeparam name="T">The message type.</typeparam>
+ public interface IMessage<T> : IMessage, IEquatable<T>, IDeepCloneable<T> where T : IMessage<T>
+ {
+ /// <summary>
+ /// Merges the given message into this one.
+ /// </summary>
+ /// <remarks>See the user guide for precise merge semantics.</remarks>
+ /// <param name="message">The message to merge with this one. Must not be null.</param>
+ void MergeFrom(T message);
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/InvalidJsonException.cs b/third_party/protobuf/csharp/src/Google.Protobuf/InvalidJsonException.cs
new file mode 100644
index 0000000000..b543420142
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/InvalidJsonException.cs
@@ -0,0 +1,53 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System.IO;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Thrown when an attempt is made to parse invalid JSON, e.g. using
+ /// a non-string property key, or including a redundant comma. Parsing a protocol buffer
+ /// message represented in JSON using <see cref="JsonParser"/> can throw both this
+ /// exception and <see cref="InvalidProtocolBufferException"/> depending on the situation. This
+ /// exception is only thrown for "pure JSON" errors, whereas <c>InvalidProtocolBufferException</c>
+ /// is thrown when the JSON may be valid in and of itself, but cannot be parsed as a protocol buffer
+ /// message.
+ /// </summary>
+ public sealed class InvalidJsonException : IOException
+ {
+ internal InvalidJsonException(string message)
+ : base(message)
+ {
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs b/third_party/protobuf/csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs
new file mode 100644
index 0000000000..0fbc530631
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/InvalidProtocolBufferException.cs
@@ -0,0 +1,129 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.IO;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Thrown when a protocol message being parsed is invalid in some way,
+ /// e.g. it contains a malformed varint or a negative byte length.
+ /// </summary>
+ public sealed class InvalidProtocolBufferException : IOException
+ {
+ internal InvalidProtocolBufferException(string message)
+ : base(message)
+ {
+ }
+
+ internal InvalidProtocolBufferException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+
+ internal static InvalidProtocolBufferException MoreDataAvailable()
+ {
+ return new InvalidProtocolBufferException(
+ "Completed reading a message while more data was available in the stream.");
+ }
+
+ internal static InvalidProtocolBufferException TruncatedMessage()
+ {
+ return new InvalidProtocolBufferException(
+ "While parsing a protocol message, the input ended unexpectedly " +
+ "in the middle of a field. This could mean either that the " +
+ "input has been truncated or that an embedded message " +
+ "misreported its own length.");
+ }
+
+ internal static InvalidProtocolBufferException NegativeSize()
+ {
+ return new InvalidProtocolBufferException(
+ "CodedInputStream encountered an embedded string or message " +
+ "which claimed to have negative size.");
+ }
+
+ internal static InvalidProtocolBufferException MalformedVarint()
+ {
+ return new InvalidProtocolBufferException(
+ "CodedInputStream encountered a malformed varint.");
+ }
+
+ /// <summary>
+ /// Creates an exception for an error condition of an invalid tag being encountered.
+ /// </summary>
+ internal static InvalidProtocolBufferException InvalidTag()
+ {
+ return new InvalidProtocolBufferException(
+ "Protocol message contained an invalid tag (zero).");
+ }
+
+ internal static InvalidProtocolBufferException InvalidBase64(Exception innerException)
+ {
+ return new InvalidProtocolBufferException("Invalid base64 data", innerException);
+ }
+
+ internal static InvalidProtocolBufferException InvalidEndTag()
+ {
+ return new InvalidProtocolBufferException(
+ "Protocol message end-group tag did not match expected tag.");
+ }
+
+ internal static InvalidProtocolBufferException RecursionLimitExceeded()
+ {
+ return new InvalidProtocolBufferException(
+ "Protocol message had too many levels of nesting. May be malicious. " +
+ "Use CodedInputStream.SetRecursionLimit() to increase the depth limit.");
+ }
+
+ internal static InvalidProtocolBufferException JsonRecursionLimitExceeded()
+ {
+ return new InvalidProtocolBufferException(
+ "Protocol message had too many levels of nesting. May be malicious. " +
+ "Use JsonParser.Settings to increase the depth limit.");
+ }
+
+ internal static InvalidProtocolBufferException SizeLimitExceeded()
+ {
+ return new InvalidProtocolBufferException(
+ "Protocol message was too large. May be malicious. " +
+ "Use CodedInputStream.SetSizeLimit() to increase the size limit.");
+ }
+
+ internal static InvalidProtocolBufferException InvalidMessageStreamTag()
+ {
+ return new InvalidProtocolBufferException(
+ "Stream of protocol messages had invalid tag. Expected tag is length-delimited field 1.");
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/JsonFormatter.cs b/third_party/protobuf/csharp/src/Google.Protobuf/JsonFormatter.cs
new file mode 100755
index 0000000000..4ae10d8b73
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/JsonFormatter.cs
@@ -0,0 +1,902 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.Collections;
+using System.Globalization;
+using System.Text;
+using Google.Protobuf.Reflection;
+using Google.Protobuf.WellKnownTypes;
+using System.IO;
+using System.Linq;
+using System.Collections.Generic;
+using System.Reflection;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Reflection-based converter from messages to JSON.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// Instances of this class are thread-safe, with no mutable state.
+ /// </para>
+ /// <para>
+ /// This is a simple start to get JSON formatting working. As it's reflection-based,
+ /// it's not as quick as baking calls into generated messages - but is a simpler implementation.
+ /// (This code is generally not heavily optimized.)
+ /// </para>
+ /// </remarks>
+ public sealed class JsonFormatter
+ {
+ internal const string AnyTypeUrlField = "@type";
+ internal const string AnyDiagnosticValueField = "@value";
+ internal const string AnyWellKnownTypeValueField = "value";
+ private const string TypeUrlPrefix = "type.googleapis.com";
+ private const string NameValueSeparator = ": ";
+ private const string PropertySeparator = ", ";
+
+ /// <summary>
+ /// Returns a formatter using the default settings.
+ /// </summary>
+ public static JsonFormatter Default { get; } = new JsonFormatter(Settings.Default);
+
+ // A JSON formatter which *only* exists
+ private static readonly JsonFormatter diagnosticFormatter = new JsonFormatter(Settings.Default);
+
+ /// <summary>
+ /// The JSON representation of the first 160 characters of Unicode.
+ /// Empty strings are replaced by the static constructor.
+ /// </summary>
+ private static readonly string[] CommonRepresentations = {
+ // C0 (ASCII and derivatives) control characters
+ "\\u0000", "\\u0001", "\\u0002", "\\u0003", // 0x00
+ "\\u0004", "\\u0005", "\\u0006", "\\u0007",
+ "\\b", "\\t", "\\n", "\\u000b",
+ "\\f", "\\r", "\\u000e", "\\u000f",
+ "\\u0010", "\\u0011", "\\u0012", "\\u0013", // 0x10
+ "\\u0014", "\\u0015", "\\u0016", "\\u0017",
+ "\\u0018", "\\u0019", "\\u001a", "\\u001b",
+ "\\u001c", "\\u001d", "\\u001e", "\\u001f",
+ // Escaping of " and \ are required by www.json.org string definition.
+ // Escaping of < and > are required for HTML security.
+ "", "", "\\\"", "", "", "", "", "", // 0x20
+ "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", // 0x30
+ "", "", "", "", "\\u003c", "", "\\u003e", "",
+ "", "", "", "", "", "", "", "", // 0x40
+ "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", // 0x50
+ "", "", "", "", "\\\\", "", "", "",
+ "", "", "", "", "", "", "", "", // 0x60
+ "", "", "", "", "", "", "", "",
+ "", "", "", "", "", "", "", "", // 0x70
+ "", "", "", "", "", "", "", "\\u007f",
+ // C1 (ISO 8859 and Unicode) extended control characters
+ "\\u0080", "\\u0081", "\\u0082", "\\u0083", // 0x80
+ "\\u0084", "\\u0085", "\\u0086", "\\u0087",
+ "\\u0088", "\\u0089", "\\u008a", "\\u008b",
+ "\\u008c", "\\u008d", "\\u008e", "\\u008f",
+ "\\u0090", "\\u0091", "\\u0092", "\\u0093", // 0x90
+ "\\u0094", "\\u0095", "\\u0096", "\\u0097",
+ "\\u0098", "\\u0099", "\\u009a", "\\u009b",
+ "\\u009c", "\\u009d", "\\u009e", "\\u009f"
+ };
+
+ static JsonFormatter()
+ {
+ for (int i = 0; i < CommonRepresentations.Length; i++)
+ {
+ if (CommonRepresentations[i] == "")
+ {
+ CommonRepresentations[i] = ((char) i).ToString();
+ }
+ }
+ }
+
+ private readonly Settings settings;
+
+ private bool DiagnosticOnly => ReferenceEquals(this, diagnosticFormatter);
+
+ /// <summary>
+ /// Creates a new formatted with the given settings.
+ /// </summary>
+ /// <param name="settings">The settings.</param>
+ public JsonFormatter(Settings settings)
+ {
+ this.settings = settings;
+ }
+
+ /// <summary>
+ /// Formats the specified message as JSON.
+ /// </summary>
+ /// <param name="message">The message to format.</param>
+ /// <returns>The formatted message.</returns>
+ public string Format(IMessage message)
+ {
+ var writer = new StringWriter();
+ Format(message, writer);
+ return writer.ToString();
+ }
+
+ /// <summary>
+ /// Formats the specified message as JSON.
+ /// </summary>
+ /// <param name="message">The message to format.</param>
+ /// <param name="writer">The TextWriter to write the formatted message to.</param>
+ /// <returns>The formatted message.</returns>
+ public void Format(IMessage message, TextWriter writer)
+ {
+ ProtoPreconditions.CheckNotNull(message, nameof(message));
+ ProtoPreconditions.CheckNotNull(writer, nameof(writer));
+
+ if (message.Descriptor.IsWellKnownType)
+ {
+ WriteWellKnownTypeValue(writer, message.Descriptor, message);
+ }
+ else
+ {
+ WriteMessage(writer, message);
+ }
+ }
+
+ /// <summary>
+ /// Converts a message to JSON for diagnostic purposes with no extra context.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// This differs from calling <see cref="Format(IMessage)"/> on the default JSON
+ /// formatter in its handling of <see cref="Any"/>. As no type registry is available
+ /// in <see cref="object.ToString"/> calls, the normal way of resolving the type of
+ /// an <c>Any</c> message cannot be applied. Instead, a JSON property named <c>@value</c>
+ /// is included with the base64 data from the <see cref="Any.Value"/> property of the message.
+ /// </para>
+ /// <para>The value returned by this method is only designed to be used for diagnostic
+ /// purposes. It may not be parsable by <see cref="JsonParser"/>, and may not be parsable
+ /// by other Protocol Buffer implementations.</para>
+ /// </remarks>
+ /// <param name="message">The message to format for diagnostic purposes.</param>
+ /// <returns>The diagnostic-only JSON representation of the message</returns>
+ public static string ToDiagnosticString(IMessage message)
+ {
+ ProtoPreconditions.CheckNotNull(message, nameof(message));
+ return diagnosticFormatter.Format(message);
+ }
+
+ private void WriteMessage(TextWriter writer, IMessage message)
+ {
+ if (message == null)
+ {
+ WriteNull(writer);
+ return;
+ }
+ if (DiagnosticOnly)
+ {
+ ICustomDiagnosticMessage customDiagnosticMessage = message as ICustomDiagnosticMessage;
+ if (customDiagnosticMessage != null)
+ {
+ writer.Write(customDiagnosticMessage.ToDiagnosticString());
+ return;
+ }
+ }
+ writer.Write("{ ");
+ bool writtenFields = WriteMessageFields(writer, message, false);
+ writer.Write(writtenFields ? " }" : "}");
+ }
+
+ private bool WriteMessageFields(TextWriter writer, IMessage message, bool assumeFirstFieldWritten)
+ {
+ var fields = message.Descriptor.Fields;
+ bool first = !assumeFirstFieldWritten;
+ // First non-oneof fields
+ foreach (var field in fields.InFieldNumberOrder())
+ {
+ var accessor = field.Accessor;
+ if (field.ContainingOneof != null && field.ContainingOneof.Accessor.GetCaseFieldDescriptor(message) != field)
+ {
+ continue;
+ }
+ // Omit default values unless we're asked to format them, or they're oneofs (where the default
+ // value is still formatted regardless, because that's how we preserve the oneof case).
+ object value = accessor.GetValue(message);
+ if (field.ContainingOneof == null && !settings.FormatDefaultValues && IsDefaultValue(accessor, value))
+ {
+ continue;
+ }
+
+ // Okay, all tests complete: let's write the field value...
+ if (!first)
+ {
+ writer.Write(PropertySeparator);
+ }
+
+ WriteString(writer, accessor.Descriptor.JsonName);
+ writer.Write(NameValueSeparator);
+ WriteValue(writer, value);
+
+ first = false;
+ }
+ return !first;
+ }
+
+ // Converted from java/core/src/main/java/com/google/protobuf/Descriptors.java
+ internal static string ToJsonName(string name)
+ {
+ StringBuilder result = new StringBuilder(name.Length);
+ bool isNextUpperCase = false;
+ foreach (char ch in name)
+ {
+ if (ch == '_')
+ {
+ isNextUpperCase = true;
+ }
+ else if (isNextUpperCase)
+ {
+ result.Append(char.ToUpperInvariant(ch));
+ isNextUpperCase = false;
+ }
+ else
+ {
+ result.Append(ch);
+ }
+ }
+ return result.ToString();
+ }
+
+ private static void WriteNull(TextWriter writer)
+ {
+ writer.Write("null");
+ }
+
+ private static bool IsDefaultValue(IFieldAccessor accessor, object value)
+ {
+ if (accessor.Descriptor.IsMap)
+ {
+ IDictionary dictionary = (IDictionary) value;
+ return dictionary.Count == 0;
+ }
+ if (accessor.Descriptor.IsRepeated)
+ {
+ IList list = (IList) value;
+ return list.Count == 0;
+ }
+ switch (accessor.Descriptor.FieldType)
+ {
+ case FieldType.Bool:
+ return (bool) value == false;
+ case FieldType.Bytes:
+ return (ByteString) value == ByteString.Empty;
+ case FieldType.String:
+ return (string) value == "";
+ case FieldType.Double:
+ return (double) value == 0.0;
+ case FieldType.SInt32:
+ case FieldType.Int32:
+ case FieldType.SFixed32:
+ case FieldType.Enum:
+ return (int) value == 0;
+ case FieldType.Fixed32:
+ case FieldType.UInt32:
+ return (uint) value == 0;
+ case FieldType.Fixed64:
+ case FieldType.UInt64:
+ return (ulong) value == 0;
+ case FieldType.SFixed64:
+ case FieldType.Int64:
+ case FieldType.SInt64:
+ return (long) value == 0;
+ case FieldType.Float:
+ return (float) value == 0f;
+ case FieldType.Message:
+ case FieldType.Group: // Never expect to get this, but...
+ return value == null;
+ default:
+ throw new ArgumentException("Invalid field type");
+ }
+ }
+
+ /// <summary>
+ /// Writes a single value to the given writer as JSON. Only types understood by
+ /// Protocol Buffers can be written in this way. This method is only exposed for
+ /// advanced use cases; most users should be using <see cref="Format(IMessage)"/>
+ /// or <see cref="Format(IMessage, TextWriter)"/>.
+ /// </summary>
+ /// <param name="writer">The writer to write the value to. Must not be null.</param>
+ /// <param name="value">The value to write. May be null.</param>
+ public void WriteValue(TextWriter writer, object value)
+ {
+ if (value == null)
+ {
+ WriteNull(writer);
+ }
+ else if (value is bool)
+ {
+ writer.Write((bool)value ? "true" : "false");
+ }
+ else if (value is ByteString)
+ {
+ // Nothing in Base64 needs escaping
+ writer.Write('"');
+ writer.Write(((ByteString)value).ToBase64());
+ writer.Write('"');
+ }
+ else if (value is string)
+ {
+ WriteString(writer, (string)value);
+ }
+ else if (value is IDictionary)
+ {
+ WriteDictionary(writer, (IDictionary)value);
+ }
+ else if (value is IList)
+ {
+ WriteList(writer, (IList)value);
+ }
+ else if (value is int || value is uint)
+ {
+ IFormattable formattable = (IFormattable) value;
+ writer.Write(formattable.ToString("d", CultureInfo.InvariantCulture));
+ }
+ else if (value is long || value is ulong)
+ {
+ writer.Write('"');
+ IFormattable formattable = (IFormattable) value;
+ writer.Write(formattable.ToString("d", CultureInfo.InvariantCulture));
+ writer.Write('"');
+ }
+ else if (value is System.Enum)
+ {
+ if (settings.FormatEnumsAsIntegers)
+ {
+ WriteValue(writer, (int)value);
+ }
+ else
+ {
+ string name = OriginalEnumValueHelper.GetOriginalName(value);
+ if (name != null)
+ {
+ WriteString(writer, name);
+ }
+ else
+ {
+ WriteValue(writer, (int)value);
+ }
+ }
+ }
+ else if (value is float || value is double)
+ {
+ string text = ((IFormattable) value).ToString("r", CultureInfo.InvariantCulture);
+ if (text == "NaN" || text == "Infinity" || text == "-Infinity")
+ {
+ writer.Write('"');
+ writer.Write(text);
+ writer.Write('"');
+ }
+ else
+ {
+ writer.Write(text);
+ }
+ }
+ else if (value is IMessage)
+ {
+ Format((IMessage)value, writer);
+ }
+ else
+ {
+ throw new ArgumentException("Unable to format value of type " + value.GetType());
+ }
+ }
+
+ /// <summary>
+ /// Central interception point for well-known type formatting. Any well-known types which
+ /// don't need special handling can fall back to WriteMessage. We avoid assuming that the
+ /// values are using the embedded well-known types, in order to allow for dynamic messages
+ /// in the future.
+ /// </summary>
+ private void WriteWellKnownTypeValue(TextWriter writer, MessageDescriptor descriptor, object value)
+ {
+ // Currently, we can never actually get here, because null values are always handled by the caller. But if we *could*,
+ // this would do the right thing.
+ if (value == null)
+ {
+ WriteNull(writer);
+ return;
+ }
+ // For wrapper types, the value will either be the (possibly boxed) "native" value,
+ // or the message itself if we're formatting it at the top level (e.g. just calling ToString on the object itself).
+ // If it's the message form, we can extract the value first, which *will* be the (possibly boxed) native value,
+ // and then proceed, writing it as if we were definitely in a field. (We never need to wrap it in an extra string...
+ // WriteValue will do the right thing.)
+ if (descriptor.IsWrapperType)
+ {
+ if (value is IMessage)
+ {
+ var message = (IMessage) value;
+ value = message.Descriptor.Fields[WrappersReflection.WrapperValueFieldNumber].Accessor.GetValue(message);
+ }
+ WriteValue(writer, value);
+ return;
+ }
+ if (descriptor.FullName == Timestamp.Descriptor.FullName)
+ {
+ WriteTimestamp(writer, (IMessage)value);
+ return;
+ }
+ if (descriptor.FullName == Duration.Descriptor.FullName)
+ {
+ WriteDuration(writer, (IMessage)value);
+ return;
+ }
+ if (descriptor.FullName == FieldMask.Descriptor.FullName)
+ {
+ WriteFieldMask(writer, (IMessage)value);
+ return;
+ }
+ if (descriptor.FullName == Struct.Descriptor.FullName)
+ {
+ WriteStruct(writer, (IMessage)value);
+ return;
+ }
+ if (descriptor.FullName == ListValue.Descriptor.FullName)
+ {
+ var fieldAccessor = descriptor.Fields[ListValue.ValuesFieldNumber].Accessor;
+ WriteList(writer, (IList)fieldAccessor.GetValue((IMessage)value));
+ return;
+ }
+ if (descriptor.FullName == Value.Descriptor.FullName)
+ {
+ WriteStructFieldValue(writer, (IMessage)value);
+ return;
+ }
+ if (descriptor.FullName == Any.Descriptor.FullName)
+ {
+ WriteAny(writer, (IMessage)value);
+ return;
+ }
+ WriteMessage(writer, (IMessage)value);
+ }
+
+ private void WriteTimestamp(TextWriter writer, IMessage value)
+ {
+ // TODO: In the common case where this *is* using the built-in Timestamp type, we could
+ // avoid all the reflection at this point, by casting to Timestamp. In the interests of
+ // avoiding subtle bugs, don't do that until we've implemented DynamicMessage so that we can prove
+ // it still works in that case.
+ int nanos = (int) value.Descriptor.Fields[Timestamp.NanosFieldNumber].Accessor.GetValue(value);
+ long seconds = (long) value.Descriptor.Fields[Timestamp.SecondsFieldNumber].Accessor.GetValue(value);
+ writer.Write(Timestamp.ToJson(seconds, nanos, DiagnosticOnly));
+ }
+
+ private void WriteDuration(TextWriter writer, IMessage value)
+ {
+ // TODO: Same as for WriteTimestamp
+ int nanos = (int) value.Descriptor.Fields[Duration.NanosFieldNumber].Accessor.GetValue(value);
+ long seconds = (long) value.Descriptor.Fields[Duration.SecondsFieldNumber].Accessor.GetValue(value);
+ writer.Write(Duration.ToJson(seconds, nanos, DiagnosticOnly));
+ }
+
+ private void WriteFieldMask(TextWriter writer, IMessage value)
+ {
+ var paths = (IList<string>) value.Descriptor.Fields[FieldMask.PathsFieldNumber].Accessor.GetValue(value);
+ writer.Write(FieldMask.ToJson(paths, DiagnosticOnly));
+ }
+
+ private void WriteAny(TextWriter writer, IMessage value)
+ {
+ if (DiagnosticOnly)
+ {
+ WriteDiagnosticOnlyAny(writer, value);
+ return;
+ }
+
+ string typeUrl = (string) value.Descriptor.Fields[Any.TypeUrlFieldNumber].Accessor.GetValue(value);
+ ByteString data = (ByteString) value.Descriptor.Fields[Any.ValueFieldNumber].Accessor.GetValue(value);
+ string typeName = Any.GetTypeName(typeUrl);
+ MessageDescriptor descriptor = settings.TypeRegistry.Find(typeName);
+ if (descriptor == null)
+ {
+ throw new InvalidOperationException($"Type registry has no descriptor for type name '{typeName}'");
+ }
+ IMessage message = descriptor.Parser.ParseFrom(data);
+ writer.Write("{ ");
+ WriteString(writer, AnyTypeUrlField);
+ writer.Write(NameValueSeparator);
+ WriteString(writer, typeUrl);
+
+ if (descriptor.IsWellKnownType)
+ {
+ writer.Write(PropertySeparator);
+ WriteString(writer, AnyWellKnownTypeValueField);
+ writer.Write(NameValueSeparator);
+ WriteWellKnownTypeValue(writer, descriptor, message);
+ }
+ else
+ {
+ WriteMessageFields(writer, message, true);
+ }
+ writer.Write(" }");
+ }
+
+ private void WriteDiagnosticOnlyAny(TextWriter writer, IMessage value)
+ {
+ string typeUrl = (string) value.Descriptor.Fields[Any.TypeUrlFieldNumber].Accessor.GetValue(value);
+ ByteString data = (ByteString) value.Descriptor.Fields[Any.ValueFieldNumber].Accessor.GetValue(value);
+ writer.Write("{ ");
+ WriteString(writer, AnyTypeUrlField);
+ writer.Write(NameValueSeparator);
+ WriteString(writer, typeUrl);
+ writer.Write(PropertySeparator);
+ WriteString(writer, AnyDiagnosticValueField);
+ writer.Write(NameValueSeparator);
+ writer.Write('"');
+ writer.Write(data.ToBase64());
+ writer.Write('"');
+ writer.Write(" }");
+ }
+
+ private void WriteStruct(TextWriter writer, IMessage message)
+ {
+ writer.Write("{ ");
+ IDictionary fields = (IDictionary) message.Descriptor.Fields[Struct.FieldsFieldNumber].Accessor.GetValue(message);
+ bool first = true;
+ foreach (DictionaryEntry entry in fields)
+ {
+ string key = (string) entry.Key;
+ IMessage value = (IMessage) entry.Value;
+ if (string.IsNullOrEmpty(key) || value == null)
+ {
+ throw new InvalidOperationException("Struct fields cannot have an empty key or a null value.");
+ }
+
+ if (!first)
+ {
+ writer.Write(PropertySeparator);
+ }
+ WriteString(writer, key);
+ writer.Write(NameValueSeparator);
+ WriteStructFieldValue(writer, value);
+ first = false;
+ }
+ writer.Write(first ? "}" : " }");
+ }
+
+ private void WriteStructFieldValue(TextWriter writer, IMessage message)
+ {
+ var specifiedField = message.Descriptor.Oneofs[0].Accessor.GetCaseFieldDescriptor(message);
+ if (specifiedField == null)
+ {
+ throw new InvalidOperationException("Value message must contain a value for the oneof.");
+ }
+
+ object value = specifiedField.Accessor.GetValue(message);
+
+ switch (specifiedField.FieldNumber)
+ {
+ case Value.BoolValueFieldNumber:
+ case Value.StringValueFieldNumber:
+ case Value.NumberValueFieldNumber:
+ WriteValue(writer, value);
+ return;
+ case Value.StructValueFieldNumber:
+ case Value.ListValueFieldNumber:
+ // Structs and ListValues are nested messages, and already well-known types.
+ var nestedMessage = (IMessage) specifiedField.Accessor.GetValue(message);
+ WriteWellKnownTypeValue(writer, nestedMessage.Descriptor, nestedMessage);
+ return;
+ case Value.NullValueFieldNumber:
+ WriteNull(writer);
+ return;
+ default:
+ throw new InvalidOperationException("Unexpected case in struct field: " + specifiedField.FieldNumber);
+ }
+ }
+
+ internal void WriteList(TextWriter writer, IList list)
+ {
+ writer.Write("[ ");
+ bool first = true;
+ foreach (var value in list)
+ {
+ if (!first)
+ {
+ writer.Write(PropertySeparator);
+ }
+ WriteValue(writer, value);
+ first = false;
+ }
+ writer.Write(first ? "]" : " ]");
+ }
+
+ internal void WriteDictionary(TextWriter writer, IDictionary dictionary)
+ {
+ writer.Write("{ ");
+ bool first = true;
+ // This will box each pair. Could use IDictionaryEnumerator, but that's ugly in terms of disposal.
+ foreach (DictionaryEntry pair in dictionary)
+ {
+ if (!first)
+ {
+ writer.Write(PropertySeparator);
+ }
+ string keyText;
+ if (pair.Key is string)
+ {
+ keyText = (string) pair.Key;
+ }
+ else if (pair.Key is bool)
+ {
+ keyText = (bool) pair.Key ? "true" : "false";
+ }
+ else if (pair.Key is int || pair.Key is uint | pair.Key is long || pair.Key is ulong)
+ {
+ keyText = ((IFormattable) pair.Key).ToString("d", CultureInfo.InvariantCulture);
+ }
+ else
+ {
+ if (pair.Key == null)
+ {
+ throw new ArgumentException("Dictionary has entry with null key");
+ }
+ throw new ArgumentException("Unhandled dictionary key type: " + pair.Key.GetType());
+ }
+ WriteString(writer, keyText);
+ writer.Write(NameValueSeparator);
+ WriteValue(writer, pair.Value);
+ first = false;
+ }
+ writer.Write(first ? "}" : " }");
+ }
+
+ /// <summary>
+ /// Writes a string (including leading and trailing double quotes) to a builder, escaping as required.
+ /// </summary>
+ /// <remarks>
+ /// Other than surrogate pair handling, this code is mostly taken from src/google/protobuf/util/internal/json_escaping.cc.
+ /// </remarks>
+ internal static void WriteString(TextWriter writer, string text)
+ {
+ writer.Write('"');
+ for (int i = 0; i < text.Length; i++)
+ {
+ char c = text[i];
+ if (c < 0xa0)
+ {
+ writer.Write(CommonRepresentations[c]);
+ continue;
+ }
+ if (char.IsHighSurrogate(c))
+ {
+ // Encountered first part of a surrogate pair.
+ // Check that we have the whole pair, and encode both parts as hex.
+ i++;
+ if (i == text.Length || !char.IsLowSurrogate(text[i]))
+ {
+ throw new ArgumentException("String contains low surrogate not followed by high surrogate");
+ }
+ HexEncodeUtf16CodeUnit(writer, c);
+ HexEncodeUtf16CodeUnit(writer, text[i]);
+ continue;
+ }
+ else if (char.IsLowSurrogate(c))
+ {
+ throw new ArgumentException("String contains high surrogate not preceded by low surrogate");
+ }
+ switch ((uint) c)
+ {
+ // These are not required by json spec
+ // but used to prevent security bugs in javascript.
+ case 0xfeff: // Zero width no-break space
+ case 0xfff9: // Interlinear annotation anchor
+ case 0xfffa: // Interlinear annotation separator
+ case 0xfffb: // Interlinear annotation terminator
+
+ case 0x00ad: // Soft-hyphen
+ case 0x06dd: // Arabic end of ayah
+ case 0x070f: // Syriac abbreviation mark
+ case 0x17b4: // Khmer vowel inherent Aq
+ case 0x17b5: // Khmer vowel inherent Aa
+ HexEncodeUtf16CodeUnit(writer, c);
+ break;
+
+ default:
+ if ((c >= 0x0600 && c <= 0x0603) || // Arabic signs
+ (c >= 0x200b && c <= 0x200f) || // Zero width etc.
+ (c >= 0x2028 && c <= 0x202e) || // Separators etc.
+ (c >= 0x2060 && c <= 0x2064) || // Invisible etc.
+ (c >= 0x206a && c <= 0x206f))
+ {
+ HexEncodeUtf16CodeUnit(writer, c);
+ }
+ else
+ {
+ // No handling of surrogates here - that's done earlier
+ writer.Write(c);
+ }
+ break;
+ }
+ }
+ writer.Write('"');
+ }
+
+ private const string Hex = "0123456789abcdef";
+ private static void HexEncodeUtf16CodeUnit(TextWriter writer, char c)
+ {
+ writer.Write("\\u");
+ writer.Write(Hex[(c >> 12) & 0xf]);
+ writer.Write(Hex[(c >> 8) & 0xf]);
+ writer.Write(Hex[(c >> 4) & 0xf]);
+ writer.Write(Hex[(c >> 0) & 0xf]);
+ }
+
+ /// <summary>
+ /// Settings controlling JSON formatting.
+ /// </summary>
+ public sealed class Settings
+ {
+ /// <summary>
+ /// Default settings, as used by <see cref="JsonFormatter.Default"/>
+ /// </summary>
+ public static Settings Default { get; }
+
+ // Workaround for the Mono compiler complaining about XML comments not being on
+ // valid language elements.
+ static Settings()
+ {
+ Default = new Settings(false);
+ }
+
+ /// <summary>
+ /// Whether fields whose values are the default for the field type (e.g. 0 for integers)
+ /// should be formatted (true) or omitted (false).
+ /// </summary>
+ public bool FormatDefaultValues { get; }
+
+ /// <summary>
+ /// The type registry used to format <see cref="Any"/> messages.
+ /// </summary>
+ public TypeRegistry TypeRegistry { get; }
+
+ /// <summary>
+ /// Whether to format enums as ints. Defaults to false.
+ /// </summary>
+ public bool FormatEnumsAsIntegers { get; }
+
+
+ /// <summary>
+ /// Creates a new <see cref="Settings"/> object with the specified formatting of default values
+ /// and an empty type registry.
+ /// </summary>
+ /// <param name="formatDefaultValues"><c>true</c> if default values (0, empty strings etc) should be formatted; <c>false</c> otherwise.</param>
+ public Settings(bool formatDefaultValues) : this(formatDefaultValues, TypeRegistry.Empty)
+ {
+ }
+
+ /// <summary>
+ /// Creates a new <see cref="Settings"/> object with the specified formatting of default values
+ /// and type registry.
+ /// </summary>
+ /// <param name="formatDefaultValues"><c>true</c> if default values (0, empty strings etc) should be formatted; <c>false</c> otherwise.</param>
+ /// <param name="typeRegistry">The <see cref="TypeRegistry"/> to use when formatting <see cref="Any"/> messages.</param>
+ public Settings(bool formatDefaultValues, TypeRegistry typeRegistry) : this(formatDefaultValues, typeRegistry, false)
+ {
+ }
+
+ /// <summary>
+ /// Creates a new <see cref="Settings"/> object with the specified parameters.
+ /// </summary>
+ /// <param name="formatDefaultValues"><c>true</c> if default values (0, empty strings etc) should be formatted; <c>false</c> otherwise.</param>
+ /// <param name="typeRegistry">The <see cref="TypeRegistry"/> to use when formatting <see cref="Any"/> messages. TypeRegistry.Empty will be used if it is null.</param>
+ /// <param name="formatEnumsAsIntegers"><c>true</c> to format the enums as integers; <c>false</c> to format enums as enum names.</param>
+ private Settings(bool formatDefaultValues,
+ TypeRegistry typeRegistry,
+ bool formatEnumsAsIntegers)
+ {
+ FormatDefaultValues = formatDefaultValues;
+ TypeRegistry = typeRegistry ?? TypeRegistry.Empty;
+ FormatEnumsAsIntegers = formatEnumsAsIntegers;
+ }
+
+ /// <summary>
+ /// Creates a new <see cref="Settings"/> object with the specified formatting of default values and the current settings.
+ /// </summary>
+ /// <param name="formatDefaultValues"><c>true</c> if default values (0, empty strings etc) should be formatted; <c>false</c> otherwise.</param>
+ public Settings WithFormatDefaultValues(bool formatDefaultValues) => new Settings(formatDefaultValues, TypeRegistry, FormatEnumsAsIntegers);
+
+ /// <summary>
+ /// Creates a new <see cref="Settings"/> object with the specified type registry and the current settings.
+ /// </summary>
+ /// <param name="typeRegistry">The <see cref="TypeRegistry"/> to use when formatting <see cref="Any"/> messages.</param>
+ public Settings WithTypeRegistry(TypeRegistry typeRegistry) => new Settings(FormatDefaultValues, typeRegistry, FormatEnumsAsIntegers);
+
+ /// <summary>
+ /// Creates a new <see cref="Settings"/> object with the specified enums formatting option and the current settings.
+ /// </summary>
+ /// <param name="formatEnumsAsIntegers"><c>true</c> to format the enums as integers; <c>false</c> to format enums as enum names.</param>
+ public Settings WithFormatEnumsAsIntegers(bool formatEnumsAsIntegers) => new Settings(FormatDefaultValues, TypeRegistry, formatEnumsAsIntegers);
+ }
+
+ // Effectively a cache of mapping from enum values to the original name as specified in the proto file,
+ // fetched by reflection.
+ // The need for this is unfortunate, as is its unbounded size, but realistically it shouldn't cause issues.
+ private static class OriginalEnumValueHelper
+ {
+ // TODO: In the future we might want to use ConcurrentDictionary, at the point where all
+ // the platforms we target have it.
+ private static readonly Dictionary<System.Type, Dictionary<object, string>> dictionaries
+ = new Dictionary<System.Type, Dictionary<object, string>>();
+
+ internal static string GetOriginalName(object value)
+ {
+ var enumType = value.GetType();
+ Dictionary<object, string> nameMapping;
+ lock (dictionaries)
+ {
+ if (!dictionaries.TryGetValue(enumType, out nameMapping))
+ {
+ nameMapping = GetNameMapping(enumType);
+ dictionaries[enumType] = nameMapping;
+ }
+ }
+
+ string originalName;
+ // If this returns false, originalName will be null, which is what we want.
+ nameMapping.TryGetValue(value, out originalName);
+ return originalName;
+ }
+
+#if NET35
+ // TODO: Consider adding functionality to TypeExtensions to avoid this difference.
+ private static Dictionary<object, string> GetNameMapping(System.Type enumType) =>
+ enumType.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static)
+ .Where(f => (f.GetCustomAttributes(typeof(OriginalNameAttribute), false)
+ .FirstOrDefault() as OriginalNameAttribute)
+ ?.PreferredAlias ?? true)
+ .ToDictionary(f => f.GetValue(null),
+ f => (f.GetCustomAttributes(typeof(OriginalNameAttribute), false)
+ .FirstOrDefault() as OriginalNameAttribute)
+ // If the attribute hasn't been applied, fall back to the name of the field.
+ ?.Name ?? f.Name);
+#else
+ private static Dictionary<object, string> GetNameMapping(System.Type enumType) =>
+ enumType.GetTypeInfo().DeclaredFields
+ .Where(f => f.IsStatic)
+ .Where(f => f.GetCustomAttributes<OriginalNameAttribute>()
+ .FirstOrDefault()?.PreferredAlias ?? true)
+ .ToDictionary(f => f.GetValue(null),
+ f => f.GetCustomAttributes<OriginalNameAttribute>()
+ .FirstOrDefault()
+ // If the attribute hasn't been applied, fall back to the name of the field.
+ ?.Name ?? f.Name);
+#endif
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/JsonParser.cs b/third_party/protobuf/csharp/src/Google.Protobuf/JsonParser.cs
new file mode 100644
index 0000000000..6b6f2d9ae2
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/JsonParser.cs
@@ -0,0 +1,1019 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using Google.Protobuf.Reflection;
+using Google.Protobuf.WellKnownTypes;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Text;
+using System.Text.RegularExpressions;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Reflection-based converter from JSON to messages.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// Instances of this class are thread-safe, with no mutable state.
+ /// </para>
+ /// <para>
+ /// This is a simple start to get JSON parsing working. As it's reflection-based,
+ /// it's not as quick as baking calls into generated messages - but is a simpler implementation.
+ /// (This code is generally not heavily optimized.)
+ /// </para>
+ /// </remarks>
+ public sealed class JsonParser
+ {
+ // Note: using 0-9 instead of \d to ensure no non-ASCII digits.
+ // This regex isn't a complete validator, but will remove *most* invalid input. We rely on parsing to do the rest.
+ private static readonly Regex TimestampRegex = new Regex(@"^(?<datetime>[0-9]{4}-[01][0-9]-[0-3][0-9]T[012][0-9]:[0-5][0-9]:[0-5][0-9])(?<subseconds>\.[0-9]{1,9})?(?<offset>(Z|[+-][0-1][0-9]:[0-5][0-9]))$", FrameworkPortability.CompiledRegexWhereAvailable);
+ private static readonly Regex DurationRegex = new Regex(@"^(?<sign>-)?(?<int>[0-9]{1,12})(?<subseconds>\.[0-9]{1,9})?s$", FrameworkPortability.CompiledRegexWhereAvailable);
+ private static readonly int[] SubsecondScalingFactors = { 0, 100000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1 };
+ private static readonly char[] FieldMaskPathSeparators = new[] { ',' };
+
+ private static readonly JsonParser defaultInstance = new JsonParser(Settings.Default);
+
+ // TODO: Consider introducing a class containing parse state of the parser, tokenizer and depth. That would simplify these handlers
+ // and the signatures of various methods.
+ private static readonly Dictionary<string, Action<JsonParser, IMessage, JsonTokenizer>>
+ WellKnownTypeHandlers = new Dictionary<string, Action<JsonParser, IMessage, JsonTokenizer>>
+ {
+ { Timestamp.Descriptor.FullName, (parser, message, tokenizer) => MergeTimestamp(message, tokenizer.Next()) },
+ { Duration.Descriptor.FullName, (parser, message, tokenizer) => MergeDuration(message, tokenizer.Next()) },
+ { Value.Descriptor.FullName, (parser, message, tokenizer) => parser.MergeStructValue(message, tokenizer) },
+ { ListValue.Descriptor.FullName, (parser, message, tokenizer) =>
+ parser.MergeRepeatedField(message, message.Descriptor.Fields[ListValue.ValuesFieldNumber], tokenizer) },
+ { Struct.Descriptor.FullName, (parser, message, tokenizer) => parser.MergeStruct(message, tokenizer) },
+ { Any.Descriptor.FullName, (parser, message, tokenizer) => parser.MergeAny(message, tokenizer) },
+ { FieldMask.Descriptor.FullName, (parser, message, tokenizer) => MergeFieldMask(message, tokenizer.Next()) },
+ { Int32Value.Descriptor.FullName, MergeWrapperField },
+ { Int64Value.Descriptor.FullName, MergeWrapperField },
+ { UInt32Value.Descriptor.FullName, MergeWrapperField },
+ { UInt64Value.Descriptor.FullName, MergeWrapperField },
+ { FloatValue.Descriptor.FullName, MergeWrapperField },
+ { DoubleValue.Descriptor.FullName, MergeWrapperField },
+ { BytesValue.Descriptor.FullName, MergeWrapperField },
+ { StringValue.Descriptor.FullName, MergeWrapperField },
+ { BoolValue.Descriptor.FullName, MergeWrapperField }
+ };
+
+ // Convenience method to avoid having to repeat the same code multiple times in the above
+ // dictionary initialization.
+ private static void MergeWrapperField(JsonParser parser, IMessage message, JsonTokenizer tokenizer)
+ {
+ parser.MergeField(message, message.Descriptor.Fields[WrappersReflection.WrapperValueFieldNumber], tokenizer);
+ }
+
+ /// <summary>
+ /// Returns a formatter using the default settings.
+ /// </summary>
+ public static JsonParser Default { get { return defaultInstance; } }
+
+ private readonly Settings settings;
+
+ /// <summary>
+ /// Creates a new formatted with the given settings.
+ /// </summary>
+ /// <param name="settings">The settings.</param>
+ public JsonParser(Settings settings)
+ {
+ this.settings = settings;
+ }
+
+ /// <summary>
+ /// Parses <paramref name="json"/> and merges the information into the given message.
+ /// </summary>
+ /// <param name="message">The message to merge the JSON information into.</param>
+ /// <param name="json">The JSON to parse.</param>
+ internal void Merge(IMessage message, string json)
+ {
+ Merge(message, new StringReader(json));
+ }
+
+ /// <summary>
+ /// Parses JSON read from <paramref name="jsonReader"/> and merges the information into the given message.
+ /// </summary>
+ /// <param name="message">The message to merge the JSON information into.</param>
+ /// <param name="jsonReader">Reader providing the JSON to parse.</param>
+ internal void Merge(IMessage message, TextReader jsonReader)
+ {
+ var tokenizer = JsonTokenizer.FromTextReader(jsonReader);
+ Merge(message, tokenizer);
+ var lastToken = tokenizer.Next();
+ if (lastToken != JsonToken.EndDocument)
+ {
+ throw new InvalidProtocolBufferException("Expected end of JSON after object");
+ }
+ }
+
+ /// <summary>
+ /// Merges the given message using data from the given tokenizer. In most cases, the next
+ /// token should be a "start object" token, but wrapper types and nullity can invalidate
+ /// that assumption. This is implemented as an LL(1) recursive descent parser over the stream
+ /// of tokens provided by the tokenizer. This token stream is assumed to be valid JSON, with the
+ /// tokenizer performing that validation - but not every token stream is valid "protobuf JSON".
+ /// </summary>
+ private void Merge(IMessage message, JsonTokenizer tokenizer)
+ {
+ if (tokenizer.ObjectDepth > settings.RecursionLimit)
+ {
+ throw InvalidProtocolBufferException.JsonRecursionLimitExceeded();
+ }
+ if (message.Descriptor.IsWellKnownType)
+ {
+ Action<JsonParser, IMessage, JsonTokenizer> handler;
+ if (WellKnownTypeHandlers.TryGetValue(message.Descriptor.FullName, out handler))
+ {
+ handler(this, message, tokenizer);
+ return;
+ }
+ // Well-known types with no special handling continue in the normal way.
+ }
+ var token = tokenizer.Next();
+ if (token.Type != JsonToken.TokenType.StartObject)
+ {
+ throw new InvalidProtocolBufferException("Expected an object");
+ }
+ var descriptor = message.Descriptor;
+ var jsonFieldMap = descriptor.Fields.ByJsonName();
+ // All the oneof fields we've already accounted for - we can only see each of them once.
+ // The set is created lazily to avoid the overhead of creating a set for every message
+ // we parsed, when oneofs are relatively rare.
+ HashSet<OneofDescriptor> seenOneofs = null;
+ while (true)
+ {
+ token = tokenizer.Next();
+ if (token.Type == JsonToken.TokenType.EndObject)
+ {
+ return;
+ }
+ if (token.Type != JsonToken.TokenType.Name)
+ {
+ throw new InvalidOperationException("Unexpected token type " + token.Type);
+ }
+ string name = token.StringValue;
+ FieldDescriptor field;
+ if (jsonFieldMap.TryGetValue(name, out field))
+ {
+ if (field.ContainingOneof != null)
+ {
+ if (seenOneofs == null)
+ {
+ seenOneofs = new HashSet<OneofDescriptor>();
+ }
+ if (!seenOneofs.Add(field.ContainingOneof))
+ {
+ throw new InvalidProtocolBufferException($"Multiple values specified for oneof {field.ContainingOneof.Name}");
+ }
+ }
+ MergeField(message, field, tokenizer);
+ }
+ else
+ {
+ // TODO: Is this what we want to do? If not, we'll need to skip the value,
+ // which may be an object or array. (We might want to put code in the tokenizer
+ // to do that.)
+ throw new InvalidProtocolBufferException("Unknown field: " + name);
+ }
+ }
+ }
+
+ private void MergeField(IMessage message, FieldDescriptor field, JsonTokenizer tokenizer)
+ {
+ var token = tokenizer.Next();
+ if (token.Type == JsonToken.TokenType.Null)
+ {
+ // Clear the field if we see a null token, unless it's for a singular field of type
+ // google.protobuf.Value.
+ // Note: different from Java API, which just ignores it.
+ // TODO: Bring it more in line? Discuss...
+ if (field.IsMap || field.IsRepeated || !IsGoogleProtobufValueField(field))
+ {
+ field.Accessor.Clear(message);
+ return;
+ }
+ }
+ tokenizer.PushBack(token);
+
+ if (field.IsMap)
+ {
+ MergeMapField(message, field, tokenizer);
+ }
+ else if (field.IsRepeated)
+ {
+ MergeRepeatedField(message, field, tokenizer);
+ }
+ else
+ {
+ var value = ParseSingleValue(field, tokenizer);
+ field.Accessor.SetValue(message, value);
+ }
+ }
+
+ private void MergeRepeatedField(IMessage message, FieldDescriptor field, JsonTokenizer tokenizer)
+ {
+ var token = tokenizer.Next();
+ if (token.Type != JsonToken.TokenType.StartArray)
+ {
+ throw new InvalidProtocolBufferException("Repeated field value was not an array. Token type: " + token.Type);
+ }
+
+ IList list = (IList) field.Accessor.GetValue(message);
+ while (true)
+ {
+ token = tokenizer.Next();
+ if (token.Type == JsonToken.TokenType.EndArray)
+ {
+ return;
+ }
+ tokenizer.PushBack(token);
+ if (token.Type == JsonToken.TokenType.Null)
+ {
+ throw new InvalidProtocolBufferException("Repeated field elements cannot be null");
+ }
+ list.Add(ParseSingleValue(field, tokenizer));
+ }
+ }
+
+ private void MergeMapField(IMessage message, FieldDescriptor field, JsonTokenizer tokenizer)
+ {
+ // Map fields are always objects, even if the values are well-known types: ParseSingleValue handles those.
+ var token = tokenizer.Next();
+ if (token.Type != JsonToken.TokenType.StartObject)
+ {
+ throw new InvalidProtocolBufferException("Expected an object to populate a map");
+ }
+
+ var type = field.MessageType;
+ var keyField = type.FindFieldByNumber(1);
+ var valueField = type.FindFieldByNumber(2);
+ if (keyField == null || valueField == null)
+ {
+ throw new InvalidProtocolBufferException("Invalid map field: " + field.FullName);
+ }
+ IDictionary dictionary = (IDictionary) field.Accessor.GetValue(message);
+
+ while (true)
+ {
+ token = tokenizer.Next();
+ if (token.Type == JsonToken.TokenType.EndObject)
+ {
+ return;
+ }
+ object key = ParseMapKey(keyField, token.StringValue);
+ object value = ParseSingleValue(valueField, tokenizer);
+ if (value == null)
+ {
+ throw new InvalidProtocolBufferException("Map values must not be null");
+ }
+ dictionary[key] = value;
+ }
+ }
+
+ private static bool IsGoogleProtobufValueField(FieldDescriptor field)
+ {
+ return field.FieldType == FieldType.Message &&
+ field.MessageType.FullName == Value.Descriptor.FullName;
+ }
+
+ private object ParseSingleValue(FieldDescriptor field, JsonTokenizer tokenizer)
+ {
+ var token = tokenizer.Next();
+ if (token.Type == JsonToken.TokenType.Null)
+ {
+ // TODO: In order to support dynamic messages, we should really build this up
+ // dynamically.
+ if (IsGoogleProtobufValueField(field))
+ {
+ return Value.ForNull();
+ }
+ return null;
+ }
+
+ var fieldType = field.FieldType;
+ if (fieldType == FieldType.Message)
+ {
+ // Parse wrapper types as their constituent types.
+ // TODO: What does this mean for null?
+ if (field.MessageType.IsWrapperType)
+ {
+ field = field.MessageType.Fields[WrappersReflection.WrapperValueFieldNumber];
+ fieldType = field.FieldType;
+ }
+ else
+ {
+ // TODO: Merge the current value in message? (Public API currently doesn't make this relevant as we don't expose merging.)
+ tokenizer.PushBack(token);
+ IMessage subMessage = NewMessageForField(field);
+ Merge(subMessage, tokenizer);
+ return subMessage;
+ }
+ }
+
+ switch (token.Type)
+ {
+ case JsonToken.TokenType.True:
+ case JsonToken.TokenType.False:
+ if (fieldType == FieldType.Bool)
+ {
+ return token.Type == JsonToken.TokenType.True;
+ }
+ // Fall through to "we don't support this type for this case"; could duplicate the behaviour of the default
+ // case instead, but this way we'd only need to change one place.
+ goto default;
+ case JsonToken.TokenType.StringValue:
+ return ParseSingleStringValue(field, token.StringValue);
+ // Note: not passing the number value itself here, as we may end up storing the string value in the token too.
+ case JsonToken.TokenType.Number:
+ return ParseSingleNumberValue(field, token);
+ case JsonToken.TokenType.Null:
+ throw new NotImplementedException("Haven't worked out what to do for null yet");
+ default:
+ throw new InvalidProtocolBufferException("Unsupported JSON token type " + token.Type + " for field type " + fieldType);
+ }
+ }
+
+ /// <summary>
+ /// Parses <paramref name="json"/> into a new message.
+ /// </summary>
+ /// <typeparam name="T">The type of message to create.</typeparam>
+ /// <param name="json">The JSON to parse.</param>
+ /// <exception cref="InvalidJsonException">The JSON does not comply with RFC 7159</exception>
+ /// <exception cref="InvalidProtocolBufferException">The JSON does not represent a Protocol Buffers message correctly</exception>
+ public T Parse<T>(string json) where T : IMessage, new()
+ {
+ ProtoPreconditions.CheckNotNull(json, nameof(json));
+ return Parse<T>(new StringReader(json));
+ }
+
+ /// <summary>
+ /// Parses JSON read from <paramref name="jsonReader"/> into a new message.
+ /// </summary>
+ /// <typeparam name="T">The type of message to create.</typeparam>
+ /// <param name="jsonReader">Reader providing the JSON to parse.</param>
+ /// <exception cref="InvalidJsonException">The JSON does not comply with RFC 7159</exception>
+ /// <exception cref="InvalidProtocolBufferException">The JSON does not represent a Protocol Buffers message correctly</exception>
+ public T Parse<T>(TextReader jsonReader) where T : IMessage, new()
+ {
+ ProtoPreconditions.CheckNotNull(jsonReader, nameof(jsonReader));
+ T message = new T();
+ Merge(message, jsonReader);
+ return message;
+ }
+
+ /// <summary>
+ /// Parses <paramref name="json"/> into a new message.
+ /// </summary>
+ /// <param name="json">The JSON to parse.</param>
+ /// <param name="descriptor">Descriptor of message type to parse.</param>
+ /// <exception cref="InvalidJsonException">The JSON does not comply with RFC 7159</exception>
+ /// <exception cref="InvalidProtocolBufferException">The JSON does not represent a Protocol Buffers message correctly</exception>
+ public IMessage Parse(string json, MessageDescriptor descriptor)
+ {
+ ProtoPreconditions.CheckNotNull(json, nameof(json));
+ ProtoPreconditions.CheckNotNull(descriptor, nameof(descriptor));
+ return Parse(new StringReader(json), descriptor);
+ }
+
+ /// <summary>
+ /// Parses JSON read from <paramref name="jsonReader"/> into a new message.
+ /// </summary>
+ /// <param name="jsonReader">Reader providing the JSON to parse.</param>
+ /// <param name="descriptor">Descriptor of message type to parse.</param>
+ /// <exception cref="InvalidJsonException">The JSON does not comply with RFC 7159</exception>
+ /// <exception cref="InvalidProtocolBufferException">The JSON does not represent a Protocol Buffers message correctly</exception>
+ public IMessage Parse(TextReader jsonReader, MessageDescriptor descriptor)
+ {
+ ProtoPreconditions.CheckNotNull(jsonReader, nameof(jsonReader));
+ ProtoPreconditions.CheckNotNull(descriptor, nameof(descriptor));
+ IMessage message = descriptor.Parser.CreateTemplate();
+ Merge(message, jsonReader);
+ return message;
+ }
+
+ private void MergeStructValue(IMessage message, JsonTokenizer tokenizer)
+ {
+ var firstToken = tokenizer.Next();
+ var fields = message.Descriptor.Fields;
+ switch (firstToken.Type)
+ {
+ case JsonToken.TokenType.Null:
+ fields[Value.NullValueFieldNumber].Accessor.SetValue(message, 0);
+ return;
+ case JsonToken.TokenType.StringValue:
+ fields[Value.StringValueFieldNumber].Accessor.SetValue(message, firstToken.StringValue);
+ return;
+ case JsonToken.TokenType.Number:
+ fields[Value.NumberValueFieldNumber].Accessor.SetValue(message, firstToken.NumberValue);
+ return;
+ case JsonToken.TokenType.False:
+ case JsonToken.TokenType.True:
+ fields[Value.BoolValueFieldNumber].Accessor.SetValue(message, firstToken.Type == JsonToken.TokenType.True);
+ return;
+ case JsonToken.TokenType.StartObject:
+ {
+ var field = fields[Value.StructValueFieldNumber];
+ var structMessage = NewMessageForField(field);
+ tokenizer.PushBack(firstToken);
+ Merge(structMessage, tokenizer);
+ field.Accessor.SetValue(message, structMessage);
+ return;
+ }
+ case JsonToken.TokenType.StartArray:
+ {
+ var field = fields[Value.ListValueFieldNumber];
+ var list = NewMessageForField(field);
+ tokenizer.PushBack(firstToken);
+ Merge(list, tokenizer);
+ field.Accessor.SetValue(message, list);
+ return;
+ }
+ default:
+ throw new InvalidOperationException("Unexpected token type: " + firstToken.Type);
+ }
+ }
+
+ private void MergeStruct(IMessage message, JsonTokenizer tokenizer)
+ {
+ var token = tokenizer.Next();
+ if (token.Type != JsonToken.TokenType.StartObject)
+ {
+ throw new InvalidProtocolBufferException("Expected object value for Struct");
+ }
+ tokenizer.PushBack(token);
+
+ var field = message.Descriptor.Fields[Struct.FieldsFieldNumber];
+ MergeMapField(message, field, tokenizer);
+ }
+
+ private void MergeAny(IMessage message, JsonTokenizer tokenizer)
+ {
+ // Record the token stream until we see the @type property. At that point, we can take the value, consult
+ // the type registry for the relevant message, and replay the stream, omitting the @type property.
+ var tokens = new List<JsonToken>();
+
+ var token = tokenizer.Next();
+ if (token.Type != JsonToken.TokenType.StartObject)
+ {
+ throw new InvalidProtocolBufferException("Expected object value for Any");
+ }
+ int typeUrlObjectDepth = tokenizer.ObjectDepth;
+
+ // The check for the property depth protects us from nested Any values which occur before the type URL
+ // for *this* Any.
+ while (token.Type != JsonToken.TokenType.Name ||
+ token.StringValue != JsonFormatter.AnyTypeUrlField ||
+ tokenizer.ObjectDepth != typeUrlObjectDepth)
+ {
+ tokens.Add(token);
+ token = tokenizer.Next();
+
+ if (tokenizer.ObjectDepth < typeUrlObjectDepth)
+ {
+ throw new InvalidProtocolBufferException("Any message with no @type");
+ }
+ }
+
+ // Don't add the @type property or its value to the recorded token list
+ token = tokenizer.Next();
+ if (token.Type != JsonToken.TokenType.StringValue)
+ {
+ throw new InvalidProtocolBufferException("Expected string value for Any.@type");
+ }
+ string typeUrl = token.StringValue;
+ string typeName = Any.GetTypeName(typeUrl);
+
+ MessageDescriptor descriptor = settings.TypeRegistry.Find(typeName);
+ if (descriptor == null)
+ {
+ throw new InvalidOperationException($"Type registry has no descriptor for type name '{typeName}'");
+ }
+
+ // Now replay the token stream we've already read and anything that remains of the object, just parsing it
+ // as normal. Our original tokenizer should end up at the end of the object.
+ var replay = JsonTokenizer.FromReplayedTokens(tokens, tokenizer);
+ var body = descriptor.Parser.CreateTemplate();
+ if (descriptor.IsWellKnownType)
+ {
+ MergeWellKnownTypeAnyBody(body, replay);
+ }
+ else
+ {
+ Merge(body, replay);
+ }
+ var data = body.ToByteString();
+
+ // Now that we have the message data, we can pack it into an Any (the message received as a parameter).
+ message.Descriptor.Fields[Any.TypeUrlFieldNumber].Accessor.SetValue(message, typeUrl);
+ message.Descriptor.Fields[Any.ValueFieldNumber].Accessor.SetValue(message, data);
+ }
+
+ // Well-known types end up in a property called "value" in the JSON. As there's no longer a @type property
+ // in the given JSON token stream, we should *only* have tokens of start-object, name("value"), the value
+ // itself, and then end-object.
+ private void MergeWellKnownTypeAnyBody(IMessage body, JsonTokenizer tokenizer)
+ {
+ var token = tokenizer.Next(); // Definitely start-object; checked in previous method
+ token = tokenizer.Next();
+ // TODO: What about an absent Int32Value, for example?
+ if (token.Type != JsonToken.TokenType.Name || token.StringValue != JsonFormatter.AnyWellKnownTypeValueField)
+ {
+ throw new InvalidProtocolBufferException($"Expected '{JsonFormatter.AnyWellKnownTypeValueField}' property for well-known type Any body");
+ }
+ Merge(body, tokenizer);
+ token = tokenizer.Next();
+ if (token.Type != JsonToken.TokenType.EndObject)
+ {
+ throw new InvalidProtocolBufferException($"Expected end-object token after @type/value for well-known type");
+ }
+ }
+
+ #region Utility methods which don't depend on the state (or settings) of the parser.
+ private static object ParseMapKey(FieldDescriptor field, string keyText)
+ {
+ switch (field.FieldType)
+ {
+ case FieldType.Bool:
+ if (keyText == "true")
+ {
+ return true;
+ }
+ if (keyText == "false")
+ {
+ return false;
+ }
+ throw new InvalidProtocolBufferException("Invalid string for bool map key: " + keyText);
+ case FieldType.String:
+ return keyText;
+ case FieldType.Int32:
+ case FieldType.SInt32:
+ case FieldType.SFixed32:
+ return ParseNumericString(keyText, int.Parse);
+ case FieldType.UInt32:
+ case FieldType.Fixed32:
+ return ParseNumericString(keyText, uint.Parse);
+ case FieldType.Int64:
+ case FieldType.SInt64:
+ case FieldType.SFixed64:
+ return ParseNumericString(keyText, long.Parse);
+ case FieldType.UInt64:
+ case FieldType.Fixed64:
+ return ParseNumericString(keyText, ulong.Parse);
+ default:
+ throw new InvalidProtocolBufferException("Invalid field type for map: " + field.FieldType);
+ }
+ }
+
+ private static object ParseSingleNumberValue(FieldDescriptor field, JsonToken token)
+ {
+ double value = token.NumberValue;
+ checked
+ {
+ try
+ {
+ switch (field.FieldType)
+ {
+ case FieldType.Int32:
+ case FieldType.SInt32:
+ case FieldType.SFixed32:
+ CheckInteger(value);
+ return (int) value;
+ case FieldType.UInt32:
+ case FieldType.Fixed32:
+ CheckInteger(value);
+ return (uint) value;
+ case FieldType.Int64:
+ case FieldType.SInt64:
+ case FieldType.SFixed64:
+ CheckInteger(value);
+ return (long) value;
+ case FieldType.UInt64:
+ case FieldType.Fixed64:
+ CheckInteger(value);
+ return (ulong) value;
+ case FieldType.Double:
+ return value;
+ case FieldType.Float:
+ if (double.IsNaN(value))
+ {
+ return float.NaN;
+ }
+ if (value > float.MaxValue || value < float.MinValue)
+ {
+ if (double.IsPositiveInfinity(value))
+ {
+ return float.PositiveInfinity;
+ }
+ if (double.IsNegativeInfinity(value))
+ {
+ return float.NegativeInfinity;
+ }
+ throw new InvalidProtocolBufferException($"Value out of range: {value}");
+ }
+ return (float) value;
+ case FieldType.Enum:
+ CheckInteger(value);
+ // Just return it as an int, and let the CLR convert it.
+ // Note that we deliberately don't check that it's a known value.
+ return (int) value;
+ default:
+ throw new InvalidProtocolBufferException($"Unsupported conversion from JSON number for field type {field.FieldType}");
+ }
+ }
+ catch (OverflowException)
+ {
+ throw new InvalidProtocolBufferException($"Value out of range: {value}");
+ }
+ }
+ }
+
+ private static void CheckInteger(double value)
+ {
+ if (double.IsInfinity(value) || double.IsNaN(value))
+ {
+ throw new InvalidProtocolBufferException($"Value not an integer: {value}");
+ }
+ if (value != Math.Floor(value))
+ {
+ throw new InvalidProtocolBufferException($"Value not an integer: {value}");
+ }
+ }
+
+ private static object ParseSingleStringValue(FieldDescriptor field, string text)
+ {
+ switch (field.FieldType)
+ {
+ case FieldType.String:
+ return text;
+ case FieldType.Bytes:
+ try
+ {
+ return ByteString.FromBase64(text);
+ }
+ catch (FormatException e)
+ {
+ throw InvalidProtocolBufferException.InvalidBase64(e);
+ }
+ case FieldType.Int32:
+ case FieldType.SInt32:
+ case FieldType.SFixed32:
+ return ParseNumericString(text, int.Parse);
+ case FieldType.UInt32:
+ case FieldType.Fixed32:
+ return ParseNumericString(text, uint.Parse);
+ case FieldType.Int64:
+ case FieldType.SInt64:
+ case FieldType.SFixed64:
+ return ParseNumericString(text, long.Parse);
+ case FieldType.UInt64:
+ case FieldType.Fixed64:
+ return ParseNumericString(text, ulong.Parse);
+ case FieldType.Double:
+ double d = ParseNumericString(text, double.Parse);
+ ValidateInfinityAndNan(text, double.IsPositiveInfinity(d), double.IsNegativeInfinity(d), double.IsNaN(d));
+ return d;
+ case FieldType.Float:
+ float f = ParseNumericString(text, float.Parse);
+ ValidateInfinityAndNan(text, float.IsPositiveInfinity(f), float.IsNegativeInfinity(f), float.IsNaN(f));
+ return f;
+ case FieldType.Enum:
+ var enumValue = field.EnumType.FindValueByName(text);
+ if (enumValue == null)
+ {
+ throw new InvalidProtocolBufferException($"Invalid enum value: {text} for enum type: {field.EnumType.FullName}");
+ }
+ // Just return it as an int, and let the CLR convert it.
+ return enumValue.Number;
+ default:
+ throw new InvalidProtocolBufferException($"Unsupported conversion from JSON string for field type {field.FieldType}");
+ }
+ }
+
+ /// <summary>
+ /// Creates a new instance of the message type for the given field.
+ /// </summary>
+ private static IMessage NewMessageForField(FieldDescriptor field)
+ {
+ return field.MessageType.Parser.CreateTemplate();
+ }
+
+ private static T ParseNumericString<T>(string text, Func<string, NumberStyles, IFormatProvider, T> parser)
+ {
+ // Can't prohibit this with NumberStyles.
+ if (text.StartsWith("+"))
+ {
+ throw new InvalidProtocolBufferException($"Invalid numeric value: {text}");
+ }
+ if (text.StartsWith("0") && text.Length > 1)
+ {
+ if (text[1] >= '0' && text[1] <= '9')
+ {
+ throw new InvalidProtocolBufferException($"Invalid numeric value: {text}");
+ }
+ }
+ else if (text.StartsWith("-0") && text.Length > 2)
+ {
+ if (text[2] >= '0' && text[2] <= '9')
+ {
+ throw new InvalidProtocolBufferException($"Invalid numeric value: {text}");
+ }
+ }
+ try
+ {
+ return parser(text, NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent, CultureInfo.InvariantCulture);
+ }
+ catch (FormatException)
+ {
+ throw new InvalidProtocolBufferException($"Invalid numeric value for type: {text}");
+ }
+ catch (OverflowException)
+ {
+ throw new InvalidProtocolBufferException($"Value out of range: {text}");
+ }
+ }
+
+ /// <summary>
+ /// Checks that any infinite/NaN values originated from the correct text.
+ /// This corrects the lenient whitespace handling of double.Parse/float.Parse, as well as the
+ /// way that Mono parses out-of-range values as infinity.
+ /// </summary>
+ private static void ValidateInfinityAndNan(string text, bool isPositiveInfinity, bool isNegativeInfinity, bool isNaN)
+ {
+ if ((isPositiveInfinity && text != "Infinity") ||
+ (isNegativeInfinity && text != "-Infinity") ||
+ (isNaN && text != "NaN"))
+ {
+ throw new InvalidProtocolBufferException($"Invalid numeric value: {text}");
+ }
+ }
+
+ private static void MergeTimestamp(IMessage message, JsonToken token)
+ {
+ if (token.Type != JsonToken.TokenType.StringValue)
+ {
+ throw new InvalidProtocolBufferException("Expected string value for Timestamp");
+ }
+ var match = TimestampRegex.Match(token.StringValue);
+ if (!match.Success)
+ {
+ throw new InvalidProtocolBufferException($"Invalid Timestamp value: {token.StringValue}");
+ }
+ var dateTime = match.Groups["datetime"].Value;
+ var subseconds = match.Groups["subseconds"].Value;
+ var offset = match.Groups["offset"].Value;
+
+ try
+ {
+ DateTime parsed = DateTime.ParseExact(
+ dateTime,
+ "yyyy-MM-dd'T'HH:mm:ss",
+ CultureInfo.InvariantCulture,
+ DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
+ // TODO: It would be nice not to have to create all these objects... easy to optimize later though.
+ Timestamp timestamp = Timestamp.FromDateTime(parsed);
+ int nanosToAdd = 0;
+ if (subseconds != "")
+ {
+ // This should always work, as we've got 1-9 digits.
+ int parsedFraction = int.Parse(subseconds.Substring(1), CultureInfo.InvariantCulture);
+ nanosToAdd = parsedFraction * SubsecondScalingFactors[subseconds.Length];
+ }
+ int secondsToAdd = 0;
+ if (offset != "Z")
+ {
+ // This is the amount we need to *subtract* from the local time to get to UTC - hence - => +1 and vice versa.
+ int sign = offset[0] == '-' ? 1 : -1;
+ int hours = int.Parse(offset.Substring(1, 2), CultureInfo.InvariantCulture);
+ int minutes = int.Parse(offset.Substring(4, 2));
+ int totalMinutes = hours * 60 + minutes;
+ if (totalMinutes > 18 * 60)
+ {
+ throw new InvalidProtocolBufferException("Invalid Timestamp value: " + token.StringValue);
+ }
+ if (totalMinutes == 0 && sign == 1)
+ {
+ // This is an offset of -00:00, which means "unknown local offset". It makes no sense for a timestamp.
+ throw new InvalidProtocolBufferException("Invalid Timestamp value: " + token.StringValue);
+ }
+ // We need to *subtract* the offset from local time to get UTC.
+ secondsToAdd = sign * totalMinutes * 60;
+ }
+ // Ensure we've got the right signs. Currently unnecessary, but easy to do.
+ if (secondsToAdd < 0 && nanosToAdd > 0)
+ {
+ secondsToAdd++;
+ nanosToAdd = nanosToAdd - Duration.NanosecondsPerSecond;
+ }
+ if (secondsToAdd != 0 || nanosToAdd != 0)
+ {
+ timestamp += new Duration { Nanos = nanosToAdd, Seconds = secondsToAdd };
+ // The resulting timestamp after offset change would be out of our expected range. Currently the Timestamp message doesn't validate this
+ // anywhere, but we shouldn't parse it.
+ if (timestamp.Seconds < Timestamp.UnixSecondsAtBclMinValue || timestamp.Seconds > Timestamp.UnixSecondsAtBclMaxValue)
+ {
+ throw new InvalidProtocolBufferException("Invalid Timestamp value: " + token.StringValue);
+ }
+ }
+ message.Descriptor.Fields[Timestamp.SecondsFieldNumber].Accessor.SetValue(message, timestamp.Seconds);
+ message.Descriptor.Fields[Timestamp.NanosFieldNumber].Accessor.SetValue(message, timestamp.Nanos);
+ }
+ catch (FormatException)
+ {
+ throw new InvalidProtocolBufferException("Invalid Timestamp value: " + token.StringValue);
+ }
+ }
+
+ private static void MergeDuration(IMessage message, JsonToken token)
+ {
+ if (token.Type != JsonToken.TokenType.StringValue)
+ {
+ throw new InvalidProtocolBufferException("Expected string value for Duration");
+ }
+ var match = DurationRegex.Match(token.StringValue);
+ if (!match.Success)
+ {
+ throw new InvalidProtocolBufferException("Invalid Duration value: " + token.StringValue);
+ }
+ var sign = match.Groups["sign"].Value;
+ var secondsText = match.Groups["int"].Value;
+ // Prohibit leading insignficant zeroes
+ if (secondsText[0] == '0' && secondsText.Length > 1)
+ {
+ throw new InvalidProtocolBufferException("Invalid Duration value: " + token.StringValue);
+ }
+ var subseconds = match.Groups["subseconds"].Value;
+ var multiplier = sign == "-" ? -1 : 1;
+
+ try
+ {
+ long seconds = long.Parse(secondsText, CultureInfo.InvariantCulture) * multiplier;
+ int nanos = 0;
+ if (subseconds != "")
+ {
+ // This should always work, as we've got 1-9 digits.
+ int parsedFraction = int.Parse(subseconds.Substring(1));
+ nanos = parsedFraction * SubsecondScalingFactors[subseconds.Length] * multiplier;
+ }
+ if (!Duration.IsNormalized(seconds, nanos))
+ {
+ throw new InvalidProtocolBufferException($"Invalid Duration value: {token.StringValue}");
+ }
+ message.Descriptor.Fields[Duration.SecondsFieldNumber].Accessor.SetValue(message, seconds);
+ message.Descriptor.Fields[Duration.NanosFieldNumber].Accessor.SetValue(message, nanos);
+ }
+ catch (FormatException)
+ {
+ throw new InvalidProtocolBufferException($"Invalid Duration value: {token.StringValue}");
+ }
+ }
+
+ private static void MergeFieldMask(IMessage message, JsonToken token)
+ {
+ if (token.Type != JsonToken.TokenType.StringValue)
+ {
+ throw new InvalidProtocolBufferException("Expected string value for FieldMask");
+ }
+ // TODO: Do we *want* to remove empty entries? Probably okay to treat "" as "no paths", but "foo,,bar"?
+ string[] jsonPaths = token.StringValue.Split(FieldMaskPathSeparators, StringSplitOptions.RemoveEmptyEntries);
+ IList messagePaths = (IList) message.Descriptor.Fields[FieldMask.PathsFieldNumber].Accessor.GetValue(message);
+ foreach (var path in jsonPaths)
+ {
+ messagePaths.Add(ToSnakeCase(path));
+ }
+ }
+
+ // Ported from src/google/protobuf/util/internal/utility.cc
+ private static string ToSnakeCase(string text)
+ {
+ var builder = new StringBuilder(text.Length * 2);
+ // Note: this is probably unnecessary now, but currently retained to be as close as possible to the
+ // C++, whilst still throwing an exception on underscores.
+ bool wasNotUnderscore = false; // Initialize to false for case 1 (below)
+ bool wasNotCap = false;
+
+ for (int i = 0; i < text.Length; i++)
+ {
+ char c = text[i];
+ if (c >= 'A' && c <= 'Z') // ascii_isupper
+ {
+ // Consider when the current character B is capitalized:
+ // 1) At beginning of input: "B..." => "b..."
+ // (e.g. "Biscuit" => "biscuit")
+ // 2) Following a lowercase: "...aB..." => "...a_b..."
+ // (e.g. "gBike" => "g_bike")
+ // 3) At the end of input: "...AB" => "...ab"
+ // (e.g. "GoogleLAB" => "google_lab")
+ // 4) Followed by a lowercase: "...ABc..." => "...a_bc..."
+ // (e.g. "GBike" => "g_bike")
+ if (wasNotUnderscore && // case 1 out
+ (wasNotCap || // case 2 in, case 3 out
+ (i + 1 < text.Length && // case 3 out
+ (text[i + 1] >= 'a' && text[i + 1] <= 'z')))) // ascii_islower(text[i + 1])
+ { // case 4 in
+ // We add an underscore for case 2 and case 4.
+ builder.Append('_');
+ }
+ // ascii_tolower, but we already know that c *is* an upper case ASCII character...
+ builder.Append((char) (c + 'a' - 'A'));
+ wasNotUnderscore = true;
+ wasNotCap = false;
+ }
+ else
+ {
+ builder.Append(c);
+ if (c == '_')
+ {
+ throw new InvalidProtocolBufferException($"Invalid field mask: {text}");
+ }
+ wasNotUnderscore = true;
+ wasNotCap = true;
+ }
+ }
+ return builder.ToString();
+ }
+ #endregion
+
+ /// <summary>
+ /// Settings controlling JSON parsing.
+ /// </summary>
+ public sealed class Settings
+ {
+ /// <summary>
+ /// Default settings, as used by <see cref="JsonParser.Default"/>. This has the same default
+ /// recursion limit as <see cref="CodedInputStream"/>, and an empty type registry.
+ /// </summary>
+ public static Settings Default { get; }
+
+ // Workaround for the Mono compiler complaining about XML comments not being on
+ // valid language elements.
+ static Settings()
+ {
+ Default = new Settings(CodedInputStream.DefaultRecursionLimit);
+ }
+
+ /// <summary>
+ /// The maximum depth of messages to parse. Note that this limit only applies to parsing
+ /// messages, not collections - so a message within a collection within a message only counts as
+ /// depth 2, not 3.
+ /// </summary>
+ public int RecursionLimit { get; }
+
+ /// <summary>
+ /// The type registry used to parse <see cref="Any"/> messages.
+ /// </summary>
+ public TypeRegistry TypeRegistry { get; }
+
+ /// <summary>
+ /// Creates a new <see cref="Settings"/> object with the specified recursion limit.
+ /// </summary>
+ /// <param name="recursionLimit">The maximum depth of messages to parse</param>
+ public Settings(int recursionLimit) : this(recursionLimit, TypeRegistry.Empty)
+ {
+ }
+
+ /// <summary>
+ /// Creates a new <see cref="Settings"/> object with the specified recursion limit and type registry.
+ /// </summary>
+ /// <param name="recursionLimit">The maximum depth of messages to parse</param>
+ /// <param name="typeRegistry">The type registry used to parse <see cref="Any"/> messages</param>
+ public Settings(int recursionLimit, TypeRegistry typeRegistry)
+ {
+ RecursionLimit = recursionLimit;
+ TypeRegistry = ProtoPreconditions.CheckNotNull(typeRegistry, nameof(typeRegistry));
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/JsonToken.cs b/third_party/protobuf/csharp/src/Google.Protobuf/JsonToken.cs
new file mode 100644
index 0000000000..6c0138ccb6
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/JsonToken.cs
@@ -0,0 +1,166 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+
+namespace Google.Protobuf
+{
+ internal sealed class JsonToken : IEquatable<JsonToken>
+ {
+ // Tokens with no value can be reused.
+ private static readonly JsonToken _true = new JsonToken(TokenType.True);
+ private static readonly JsonToken _false = new JsonToken(TokenType.False);
+ private static readonly JsonToken _null = new JsonToken(TokenType.Null);
+ private static readonly JsonToken startObject = new JsonToken(TokenType.StartObject);
+ private static readonly JsonToken endObject = new JsonToken(TokenType.EndObject);
+ private static readonly JsonToken startArray = new JsonToken(TokenType.StartArray);
+ private static readonly JsonToken endArray = new JsonToken(TokenType.EndArray);
+ private static readonly JsonToken endDocument = new JsonToken(TokenType.EndDocument);
+
+ internal static JsonToken Null { get { return _null; } }
+ internal static JsonToken False { get { return _false; } }
+ internal static JsonToken True { get { return _true; } }
+ internal static JsonToken StartObject{ get { return startObject; } }
+ internal static JsonToken EndObject { get { return endObject; } }
+ internal static JsonToken StartArray { get { return startArray; } }
+ internal static JsonToken EndArray { get { return endArray; } }
+ internal static JsonToken EndDocument { get { return endDocument; } }
+
+ internal static JsonToken Name(string name)
+ {
+ return new JsonToken(TokenType.Name, stringValue: name);
+ }
+
+ internal static JsonToken Value(string value)
+ {
+ return new JsonToken(TokenType.StringValue, stringValue: value);
+ }
+
+ internal static JsonToken Value(double value)
+ {
+ return new JsonToken(TokenType.Number, numberValue: value);
+ }
+
+ internal enum TokenType
+ {
+ Null,
+ False,
+ True,
+ StringValue,
+ Number,
+ Name,
+ StartObject,
+ EndObject,
+ StartArray,
+ EndArray,
+ EndDocument
+ }
+
+ // A value is a string, number, array, object, null, true or false
+ // Arrays and objects have start/end
+ // A document consists of a value
+ // Objects are name/value sequences.
+
+ private readonly TokenType type;
+ private readonly string stringValue;
+ private readonly double numberValue;
+
+ internal TokenType Type { get { return type; } }
+ internal string StringValue { get { return stringValue; } }
+ internal double NumberValue { get { return numberValue; } }
+
+ private JsonToken(TokenType type, string stringValue = null, double numberValue = 0)
+ {
+ this.type = type;
+ this.stringValue = stringValue;
+ this.numberValue = numberValue;
+ }
+
+ public override bool Equals(object obj)
+ {
+ return Equals(obj as JsonToken);
+ }
+
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ int hash = 17;
+ hash = hash * 31 + (int) type;
+ hash = hash * 31 + stringValue == null ? 0 : stringValue.GetHashCode();
+ hash = hash * 31 + numberValue.GetHashCode();
+ return hash;
+ }
+ }
+
+ public override string ToString()
+ {
+ switch (type)
+ {
+ case TokenType.Null:
+ return "null";
+ case TokenType.True:
+ return "true";
+ case TokenType.False:
+ return "false";
+ case TokenType.Name:
+ return "name (" + stringValue + ")";
+ case TokenType.StringValue:
+ return "value (" + stringValue + ")";
+ case TokenType.Number:
+ return "number (" + numberValue + ")";
+ case TokenType.StartObject:
+ return "start-object";
+ case TokenType.EndObject:
+ return "end-object";
+ case TokenType.StartArray:
+ return "start-array";
+ case TokenType.EndArray:
+ return "end-array";
+ case TokenType.EndDocument:
+ return "end-document";
+ default:
+ throw new InvalidOperationException("Token is of unknown type " + type);
+ }
+ }
+
+ public bool Equals(JsonToken other)
+ {
+ if (ReferenceEquals(other, null))
+ {
+ return false;
+ }
+ // Note use of other.numberValue.Equals rather than ==, so that NaN compares appropriately.
+ return other.type == type && other.stringValue == stringValue && other.numberValue.Equals(numberValue);
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/JsonTokenizer.cs b/third_party/protobuf/csharp/src/Google.Protobuf/JsonTokenizer.cs
new file mode 100644
index 0000000000..09a6d43b7b
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/JsonTokenizer.cs
@@ -0,0 +1,738 @@
+#region Copyright notice and license
+// 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.
+#endregion
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Text;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Simple but strict JSON tokenizer, rigidly following RFC 7159.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// This tokenizer is stateful, and only returns "useful" tokens - names, values etc.
+ /// It does not create tokens for the separator between names and values, or for the comma
+ /// between values. It validates the token stream as it goes - so callers can assume that the
+ /// tokens it produces are appropriate. For example, it would never produce "start object, end array."
+ /// </para>
+ /// <para>Implementation details: the base class handles single token push-back and </para>
+ /// <para>Not thread-safe.</para>
+ /// </remarks>
+ internal abstract class JsonTokenizer
+ {
+ private JsonToken bufferedToken;
+
+ /// <summary>
+ /// Creates a tokenizer that reads from the given text reader.
+ /// </summary>
+ internal static JsonTokenizer FromTextReader(TextReader reader)
+ {
+ return new JsonTextTokenizer(reader);
+ }
+
+ /// <summary>
+ /// Creates a tokenizer that first replays the given list of tokens, then continues reading
+ /// from another tokenizer. Note that if the returned tokenizer is "pushed back", that does not push back
+ /// on the continuation tokenizer, or vice versa. Care should be taken when using this method - it was
+ /// created for the sake of Any parsing.
+ /// </summary>
+ internal static JsonTokenizer FromReplayedTokens(IList<JsonToken> tokens, JsonTokenizer continuation)
+ {
+ return new JsonReplayTokenizer(tokens, continuation);
+ }
+
+ /// <summary>
+ /// Returns the depth of the stack, purely in objects (not collections).
+ /// Informally, this is the number of remaining unclosed '{' characters we have.
+ /// </summary>
+ internal int ObjectDepth { get; private set; }
+
+ // TODO: Why do we allow a different token to be pushed back? It might be better to always remember the previous
+ // token returned, and allow a parameterless Rewind() method (which could only be called once, just like the current PushBack).
+ internal void PushBack(JsonToken token)
+ {
+ if (bufferedToken != null)
+ {
+ throw new InvalidOperationException("Can't push back twice");
+ }
+ bufferedToken = token;
+ if (token.Type == JsonToken.TokenType.StartObject)
+ {
+ ObjectDepth--;
+ }
+ else if (token.Type == JsonToken.TokenType.EndObject)
+ {
+ ObjectDepth++;
+ }
+ }
+
+ /// <summary>
+ /// Returns the next JSON token in the stream. An EndDocument token is returned to indicate the end of the stream,
+ /// after which point <c>Next()</c> should not be called again.
+ /// </summary>
+ /// <remarks>This implementation provides single-token buffering, and calls <see cref="NextImpl"/> if there is no buffered token.</remarks>
+ /// <returns>The next token in the stream. This is never null.</returns>
+ /// <exception cref="InvalidOperationException">This method is called after an EndDocument token has been returned</exception>
+ /// <exception cref="InvalidJsonException">The input text does not comply with RFC 7159</exception>
+ internal JsonToken Next()
+ {
+ JsonToken tokenToReturn;
+ if (bufferedToken != null)
+ {
+ tokenToReturn = bufferedToken;
+ bufferedToken = null;
+ }
+ else
+ {
+ tokenToReturn = NextImpl();
+ }
+ if (tokenToReturn.Type == JsonToken.TokenType.StartObject)
+ {
+ ObjectDepth++;
+ }
+ else if (tokenToReturn.Type == JsonToken.TokenType.EndObject)
+ {
+ ObjectDepth--;
+ }
+ return tokenToReturn;
+ }
+
+ /// <summary>
+ /// Returns the next JSON token in the stream, when requested by the base class. (The <see cref="Next"/> method delegates
+ /// to this if it doesn't have a buffered token.)
+ /// </summary>
+ /// <exception cref="InvalidOperationException">This method is called after an EndDocument token has been returned</exception>
+ /// <exception cref="InvalidJsonException">The input text does not comply with RFC 7159</exception>
+ protected abstract JsonToken NextImpl();
+
+ /// <summary>
+ /// Tokenizer which first exhausts a list of tokens, then consults another tokenizer.
+ /// </summary>
+ private class JsonReplayTokenizer : JsonTokenizer
+ {
+ private readonly IList<JsonToken> tokens;
+ private readonly JsonTokenizer nextTokenizer;
+ private int nextTokenIndex;
+
+ internal JsonReplayTokenizer(IList<JsonToken> tokens, JsonTokenizer nextTokenizer)
+ {
+ this.tokens = tokens;
+ this.nextTokenizer = nextTokenizer;
+ }
+
+ // FIXME: Object depth not maintained...
+ protected override JsonToken NextImpl()
+ {
+ if (nextTokenIndex >= tokens.Count)
+ {
+ return nextTokenizer.Next();
+ }
+ return tokens[nextTokenIndex++];
+ }
+ }
+
+ /// <summary>
+ /// Tokenizer which does all the *real* work of parsing JSON.
+ /// </summary>
+ private sealed class JsonTextTokenizer : JsonTokenizer
+ {
+ // The set of states in which a value is valid next token.
+ private static readonly State ValueStates = State.ArrayStart | State.ArrayAfterComma | State.ObjectAfterColon | State.StartOfDocument;
+
+ private readonly Stack<ContainerType> containerStack = new Stack<ContainerType>();
+ private readonly PushBackReader reader;
+ private State state;
+
+ internal JsonTextTokenizer(TextReader reader)
+ {
+ this.reader = new PushBackReader(reader);
+ state = State.StartOfDocument;
+ containerStack.Push(ContainerType.Document);
+ }
+
+ /// <remarks>
+ /// This method essentially just loops through characters skipping whitespace, validating and
+ /// changing state (e.g. from ObjectBeforeColon to ObjectAfterColon)
+ /// until it reaches something which will be a genuine token (e.g. a start object, or a value) at which point
+ /// it returns the token. Although the method is large, it would be relatively hard to break down further... most
+ /// of it is the large switch statement, which sometimes returns and sometimes doesn't.
+ /// </remarks>
+ protected override JsonToken NextImpl()
+ {
+ if (state == State.ReaderExhausted)
+ {
+ throw new InvalidOperationException("Next() called after end of document");
+ }
+ while (true)
+ {
+ var next = reader.Read();
+ if (next == null)
+ {
+ ValidateState(State.ExpectedEndOfDocument, "Unexpected end of document in state: ");
+ state = State.ReaderExhausted;
+ return JsonToken.EndDocument;
+ }
+ switch (next.Value)
+ {
+ // Skip whitespace between tokens
+ case ' ':
+ case '\t':
+ case '\r':
+ case '\n':
+ break;
+ case ':':
+ ValidateState(State.ObjectBeforeColon, "Invalid state to read a colon: ");
+ state = State.ObjectAfterColon;
+ break;
+ case ',':
+ ValidateState(State.ObjectAfterProperty | State.ArrayAfterValue, "Invalid state to read a colon: ");
+ state = state == State.ObjectAfterProperty ? State.ObjectAfterComma : State.ArrayAfterComma;
+ break;
+ case '"':
+ string stringValue = ReadString();
+ if ((state & (State.ObjectStart | State.ObjectAfterComma)) != 0)
+ {
+ state = State.ObjectBeforeColon;
+ return JsonToken.Name(stringValue);
+ }
+ else
+ {
+ ValidateAndModifyStateForValue("Invalid state to read a double quote: ");
+ return JsonToken.Value(stringValue);
+ }
+ case '{':
+ ValidateState(ValueStates, "Invalid state to read an open brace: ");
+ state = State.ObjectStart;
+ containerStack.Push(ContainerType.Object);
+ return JsonToken.StartObject;
+ case '}':
+ ValidateState(State.ObjectAfterProperty | State.ObjectStart, "Invalid state to read a close brace: ");
+ PopContainer();
+ return JsonToken.EndObject;
+ case '[':
+ ValidateState(ValueStates, "Invalid state to read an open square bracket: ");
+ state = State.ArrayStart;
+ containerStack.Push(ContainerType.Array);
+ return JsonToken.StartArray;
+ case ']':
+ ValidateState(State.ArrayAfterValue | State.ArrayStart, "Invalid state to read a close square bracket: ");
+ PopContainer();
+ return JsonToken.EndArray;
+ case 'n': // Start of null
+ ConsumeLiteral("null");
+ ValidateAndModifyStateForValue("Invalid state to read a null literal: ");
+ return JsonToken.Null;
+ case 't': // Start of true
+ ConsumeLiteral("true");
+ ValidateAndModifyStateForValue("Invalid state to read a true literal: ");
+ return JsonToken.True;
+ case 'f': // Start of false
+ ConsumeLiteral("false");
+ ValidateAndModifyStateForValue("Invalid state to read a false literal: ");
+ return JsonToken.False;
+ case '-': // Start of a number
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ double number = ReadNumber(next.Value);
+ ValidateAndModifyStateForValue("Invalid state to read a number token: ");
+ return JsonToken.Value(number);
+ default:
+ throw new InvalidJsonException("Invalid first character of token: " + next.Value);
+ }
+ }
+ }
+
+ private void ValidateState(State validStates, string errorPrefix)
+ {
+ if ((validStates & state) == 0)
+ {
+ throw reader.CreateException(errorPrefix + state);
+ }
+ }
+
+ /// <summary>
+ /// Reads a string token. It is assumed that the opening " has already been read.
+ /// </summary>
+ private string ReadString()
+ {
+ var value = new StringBuilder();
+ bool haveHighSurrogate = false;
+ while (true)
+ {
+ char c = reader.ReadOrFail("Unexpected end of text while reading string");
+ if (c < ' ')
+ {
+ throw reader.CreateException(string.Format(CultureInfo.InvariantCulture, "Invalid character in string literal: U+{0:x4}", (int) c));
+ }
+ if (c == '"')
+ {
+ if (haveHighSurrogate)
+ {
+ throw reader.CreateException("Invalid use of surrogate pair code units");
+ }
+ return value.ToString();
+ }
+ if (c == '\\')
+ {
+ c = ReadEscapedCharacter();
+ }
+ // TODO: Consider only allowing surrogate pairs that are either both escaped,
+ // or both not escaped. It would be a very odd text stream that contained a "lone" high surrogate
+ // followed by an escaped low surrogate or vice versa... and that couldn't even be represented in UTF-8.
+ if (haveHighSurrogate != char.IsLowSurrogate(c))
+ {
+ throw reader.CreateException("Invalid use of surrogate pair code units");
+ }
+ haveHighSurrogate = char.IsHighSurrogate(c);
+ value.Append(c);
+ }
+ }
+
+ /// <summary>
+ /// Reads an escaped character. It is assumed that the leading backslash has already been read.
+ /// </summary>
+ private char ReadEscapedCharacter()
+ {
+ char c = reader.ReadOrFail("Unexpected end of text while reading character escape sequence");
+ switch (c)
+ {
+ case 'n':
+ return '\n';
+ case '\\':
+ return '\\';
+ case 'b':
+ return '\b';
+ case 'f':
+ return '\f';
+ case 'r':
+ return '\r';
+ case 't':
+ return '\t';
+ case '"':
+ return '"';
+ case '/':
+ return '/';
+ case 'u':
+ return ReadUnicodeEscape();
+ default:
+ throw reader.CreateException(string.Format(CultureInfo.InvariantCulture, "Invalid character in character escape sequence: U+{0:x4}", (int) c));
+ }
+ }
+
+ /// <summary>
+ /// Reads an escaped Unicode 4-nybble hex sequence. It is assumed that the leading \u has already been read.
+ /// </summary>
+ private char ReadUnicodeEscape()
+ {
+ int result = 0;
+ for (int i = 0; i < 4; i++)
+ {
+ char c = reader.ReadOrFail("Unexpected end of text while reading Unicode escape sequence");
+ int nybble;
+ if (c >= '0' && c <= '9')
+ {
+ nybble = c - '0';
+ }
+ else if (c >= 'a' && c <= 'f')
+ {
+ nybble = c - 'a' + 10;
+ }
+ else if (c >= 'A' && c <= 'F')
+ {
+ nybble = c - 'A' + 10;
+ }
+ else
+ {
+ throw reader.CreateException(string.Format(CultureInfo.InvariantCulture, "Invalid character in character escape sequence: U+{0:x4}", (int) c));
+ }
+ result = (result << 4) + nybble;
+ }
+ return (char) result;
+ }
+
+ /// <summary>
+ /// Consumes a text-only literal, throwing an exception if the read text doesn't match it.
+ /// It is assumed that the first letter of the literal has already been read.
+ /// </summary>
+ private void ConsumeLiteral(string text)
+ {
+ for (int i = 1; i < text.Length; i++)
+ {
+ char? next = reader.Read();
+ if (next == null)
+ {
+ throw reader.CreateException("Unexpected end of text while reading literal token " + text);
+ }
+ if (next.Value != text[i])
+ {
+ throw reader.CreateException("Unexpected character while reading literal token " + text);
+ }
+ }
+ }
+
+ private double ReadNumber(char initialCharacter)
+ {
+ StringBuilder builder = new StringBuilder();
+ if (initialCharacter == '-')
+ {
+ builder.Append("-");
+ }
+ else
+ {
+ reader.PushBack(initialCharacter);
+ }
+ // Each method returns the character it read that doesn't belong in that part,
+ // so we know what to do next, including pushing the character back at the end.
+ // null is returned for "end of text".
+ char? next = ReadInt(builder);
+ if (next == '.')
+ {
+ next = ReadFrac(builder);
+ }
+ if (next == 'e' || next == 'E')
+ {
+ next = ReadExp(builder);
+ }
+ // If we read a character which wasn't part of the number, push it back so we can read it again
+ // to parse the next token.
+ if (next != null)
+ {
+ reader.PushBack(next.Value);
+ }
+
+ // TODO: What exception should we throw if the value can't be represented as a double?
+ try
+ {
+ return double.Parse(builder.ToString(),
+ NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent,
+ CultureInfo.InvariantCulture);
+ }
+ catch (OverflowException)
+ {
+ throw reader.CreateException("Numeric value out of range: " + builder);
+ }
+ }
+
+ private char? ReadInt(StringBuilder builder)
+ {
+ char first = reader.ReadOrFail("Invalid numeric literal");
+ if (first < '0' || first > '9')
+ {
+ throw reader.CreateException("Invalid numeric literal");
+ }
+ builder.Append(first);
+ int digitCount;
+ char? next = ConsumeDigits(builder, out digitCount);
+ if (first == '0' && digitCount != 0)
+ {
+ throw reader.CreateException("Invalid numeric literal: leading 0 for non-zero value.");
+ }
+ return next;
+ }
+
+ private char? ReadFrac(StringBuilder builder)
+ {
+ builder.Append('.'); // Already consumed this
+ int digitCount;
+ char? next = ConsumeDigits(builder, out digitCount);
+ if (digitCount == 0)
+ {
+ throw reader.CreateException("Invalid numeric literal: fraction with no trailing digits");
+ }
+ return next;
+ }
+
+ private char? ReadExp(StringBuilder builder)
+ {
+ builder.Append('E'); // Already consumed this (or 'e')
+ char? next = reader.Read();
+ if (next == null)
+ {
+ throw reader.CreateException("Invalid numeric literal: exponent with no trailing digits");
+ }
+ if (next == '-' || next == '+')
+ {
+ builder.Append(next.Value);
+ }
+ else
+ {
+ reader.PushBack(next.Value);
+ }
+ int digitCount;
+ next = ConsumeDigits(builder, out digitCount);
+ if (digitCount == 0)
+ {
+ throw reader.CreateException("Invalid numeric literal: exponent without value");
+ }
+ return next;
+ }
+
+ private char? ConsumeDigits(StringBuilder builder, out int count)
+ {
+ count = 0;
+ while (true)
+ {
+ char? next = reader.Read();
+ if (next == null || next.Value < '0' || next.Value > '9')
+ {
+ return next;
+ }
+ count++;
+ builder.Append(next.Value);
+ }
+ }
+
+ /// <summary>
+ /// Validates that we're in a valid state to read a value (using the given error prefix if necessary)
+ /// and changes the state to the appropriate one, e.g. ObjectAfterColon to ObjectAfterProperty.
+ /// </summary>
+ private void ValidateAndModifyStateForValue(string errorPrefix)
+ {
+ ValidateState(ValueStates, errorPrefix);
+ switch (state)
+ {
+ case State.StartOfDocument:
+ state = State.ExpectedEndOfDocument;
+ return;
+ case State.ObjectAfterColon:
+ state = State.ObjectAfterProperty;
+ return;
+ case State.ArrayStart:
+ case State.ArrayAfterComma:
+ state = State.ArrayAfterValue;
+ return;
+ default:
+ throw new InvalidOperationException("ValidateAndModifyStateForValue does not handle all value states (and should)");
+ }
+ }
+
+ /// <summary>
+ /// Pops the top-most container, and sets the state to the appropriate one for the end of a value
+ /// in the parent container.
+ /// </summary>
+ private void PopContainer()
+ {
+ containerStack.Pop();
+ var parent = containerStack.Peek();
+ switch (parent)
+ {
+ case ContainerType.Object:
+ state = State.ObjectAfterProperty;
+ break;
+ case ContainerType.Array:
+ state = State.ArrayAfterValue;
+ break;
+ case ContainerType.Document:
+ state = State.ExpectedEndOfDocument;
+ break;
+ default:
+ throw new InvalidOperationException("Unexpected container type: " + parent);
+ }
+ }
+
+ private enum ContainerType
+ {
+ Document, Object, Array
+ }
+
+ /// <summary>
+ /// Possible states of the tokenizer.
+ /// </summary>
+ /// <remarks>
+ /// <para>This is a flags enum purely so we can simply and efficiently represent a set of valid states
+ /// for checking.</para>
+ /// <para>
+ /// Each is documented with an example,
+ /// where ^ represents the current position within the text stream. The examples all use string values,
+ /// but could be any value, including nested objects/arrays.
+ /// The complete state of the tokenizer also includes a stack to indicate the contexts (arrays/objects).
+ /// Any additional notional state of "AfterValue" indicates that a value has been completed, at which
+ /// point there's an immediate transition to ExpectedEndOfDocument, ObjectAfterProperty or ArrayAfterValue.
+ /// </para>
+ /// <para>
+ /// These states were derived manually by reading RFC 7159 carefully.
+ /// </para>
+ /// </remarks>
+ [Flags]
+ private enum State
+ {
+ /// <summary>
+ /// ^ { "foo": "bar" }
+ /// Before the value in a document. Next states: ObjectStart, ArrayStart, "AfterValue"
+ /// </summary>
+ StartOfDocument = 1 << 0,
+ /// <summary>
+ /// { "foo": "bar" } ^
+ /// After the value in a document. Next states: ReaderExhausted
+ /// </summary>
+ ExpectedEndOfDocument = 1 << 1,
+ /// <summary>
+ /// { "foo": "bar" } ^ (and already read to the end of the reader)
+ /// Terminal state.
+ /// </summary>
+ ReaderExhausted = 1 << 2,
+ /// <summary>
+ /// { ^ "foo": "bar" }
+ /// Before the *first* property in an object.
+ /// Next states:
+ /// "AfterValue" (empty object)
+ /// ObjectBeforeColon (read a name)
+ /// </summary>
+ ObjectStart = 1 << 3,
+ /// <summary>
+ /// { "foo" ^ : "bar", "x": "y" }
+ /// Next state: ObjectAfterColon
+ /// </summary>
+ ObjectBeforeColon = 1 << 4,
+ /// <summary>
+ /// { "foo" : ^ "bar", "x": "y" }
+ /// Before any property other than the first in an object.
+ /// (Equivalently: after any property in an object)
+ /// Next states:
+ /// "AfterValue" (value is simple)
+ /// ObjectStart (value is object)
+ /// ArrayStart (value is array)
+ /// </summary>
+ ObjectAfterColon = 1 << 5,
+ /// <summary>
+ /// { "foo" : "bar" ^ , "x" : "y" }
+ /// At the end of a property, so expecting either a comma or end-of-object
+ /// Next states: ObjectAfterComma or "AfterValue"
+ /// </summary>
+ ObjectAfterProperty = 1 << 6,
+ /// <summary>
+ /// { "foo":"bar", ^ "x":"y" }
+ /// Read the comma after the previous property, so expecting another property.
+ /// This is like ObjectStart, but closing brace isn't valid here
+ /// Next state: ObjectBeforeColon.
+ /// </summary>
+ ObjectAfterComma = 1 << 7,
+ /// <summary>
+ /// [ ^ "foo", "bar" ]
+ /// Before the *first* value in an array.
+ /// Next states:
+ /// "AfterValue" (read a value)
+ /// "AfterValue" (end of array; will pop stack)
+ /// </summary>
+ ArrayStart = 1 << 8,
+ /// <summary>
+ /// [ "foo" ^ , "bar" ]
+ /// After any value in an array, so expecting either a comma or end-of-array
+ /// Next states: ArrayAfterComma or "AfterValue"
+ /// </summary>
+ ArrayAfterValue = 1 << 9,
+ /// <summary>
+ /// [ "foo", ^ "bar" ]
+ /// After a comma in an array, so there *must* be another value (simple or complex).
+ /// Next states: "AfterValue" (simple value), StartObject, StartArray
+ /// </summary>
+ ArrayAfterComma = 1 << 10
+ }
+
+ /// <summary>
+ /// Wrapper around a text reader allowing small amounts of buffering and location handling.
+ /// </summary>
+ private class PushBackReader
+ {
+ // TODO: Add locations for errors etc.
+
+ private readonly TextReader reader;
+
+ internal PushBackReader(TextReader reader)
+ {
+ // TODO: Wrap the reader in a BufferedReader?
+ this.reader = reader;
+ }
+
+ /// <summary>
+ /// The buffered next character, if we have one.
+ /// </summary>
+ private char? nextChar;
+
+ /// <summary>
+ /// Returns the next character in the stream, or null if we have reached the end.
+ /// </summary>
+ /// <returns></returns>
+ internal char? Read()
+ {
+ if (nextChar != null)
+ {
+ char? tmp = nextChar;
+ nextChar = null;
+ return tmp;
+ }
+ int next = reader.Read();
+ return next == -1 ? null : (char?) next;
+ }
+
+ internal char ReadOrFail(string messageOnFailure)
+ {
+ char? next = Read();
+ if (next == null)
+ {
+ throw CreateException(messageOnFailure);
+ }
+ return next.Value;
+ }
+
+ internal void PushBack(char c)
+ {
+ if (nextChar != null)
+ {
+ throw new InvalidOperationException("Cannot push back when already buffering a character");
+ }
+ nextChar = c;
+ }
+
+ /// <summary>
+ /// Creates a new exception appropriate for the current state of the reader.
+ /// </summary>
+ internal InvalidJsonException CreateException(string message)
+ {
+ // TODO: Keep track of and use the location.
+ return new InvalidJsonException(message);
+ }
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/LimitedInputStream.cs b/third_party/protobuf/csharp/src/Google.Protobuf/LimitedInputStream.cs
new file mode 100644
index 0000000000..f11d19d944
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/LimitedInputStream.cs
@@ -0,0 +1,110 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.IO;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Stream implementation which proxies another stream, only allowing a certain amount
+ /// of data to be read. Note that this is only used to read delimited streams, so it
+ /// doesn't attempt to implement everything.
+ /// </summary>
+ internal sealed class LimitedInputStream : Stream
+ {
+ private readonly Stream proxied;
+ private int bytesLeft;
+
+ internal LimitedInputStream(Stream proxied, int size)
+ {
+ this.proxied = proxied;
+ bytesLeft = size;
+ }
+
+ public override bool CanRead
+ {
+ get { return true; }
+ }
+
+ public override bool CanSeek
+ {
+ get { return false; }
+ }
+
+ public override bool CanWrite
+ {
+ get { return false; }
+ }
+
+ public override void Flush()
+ {
+ }
+
+ public override long Length
+ {
+ get { throw new NotSupportedException(); }
+ }
+
+ public override long Position
+ {
+ get { throw new NotSupportedException(); }
+ set { throw new NotSupportedException(); }
+ }
+
+ public override int Read(byte[] buffer, int offset, int count)
+ {
+ if (bytesLeft > 0)
+ {
+ int bytesRead = proxied.Read(buffer, offset, Math.Min(bytesLeft, count));
+ bytesLeft -= bytesRead;
+ return bytesRead;
+ }
+ return 0;
+ }
+
+ public override long Seek(long offset, SeekOrigin origin)
+ {
+ throw new NotSupportedException();
+ }
+
+ public override void SetLength(long value)
+ {
+ throw new NotSupportedException();
+ }
+
+ public override void Write(byte[] buffer, int offset, int count)
+ {
+ throw new NotSupportedException();
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/MessageExtensions.cs b/third_party/protobuf/csharp/src/Google.Protobuf/MessageExtensions.cs
new file mode 100644
index 0000000000..047156c3ee
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/MessageExtensions.cs
@@ -0,0 +1,157 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System.IO;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Extension methods on <see cref="IMessage"/> and <see cref="IMessage{T}"/>.
+ /// </summary>
+ public static class MessageExtensions
+ {
+ /// <summary>
+ /// Merges data from the given byte array into an existing message.
+ /// </summary>
+ /// <param name="message">The message to merge the data into.</param>
+ /// <param name="data">The data to merge, which must be protobuf-encoded binary data.</param>
+ public static void MergeFrom(this IMessage message, byte[] data)
+ {
+ ProtoPreconditions.CheckNotNull(message, "message");
+ ProtoPreconditions.CheckNotNull(data, "data");
+ CodedInputStream input = new CodedInputStream(data);
+ message.MergeFrom(input);
+ input.CheckReadEndOfStreamTag();
+ }
+
+ /// <summary>
+ /// Merges data from the given byte string into an existing message.
+ /// </summary>
+ /// <param name="message">The message to merge the data into.</param>
+ /// <param name="data">The data to merge, which must be protobuf-encoded binary data.</param>
+ public static void MergeFrom(this IMessage message, ByteString data)
+ {
+ ProtoPreconditions.CheckNotNull(message, "message");
+ ProtoPreconditions.CheckNotNull(data, "data");
+ CodedInputStream input = data.CreateCodedInput();
+ message.MergeFrom(input);
+ input.CheckReadEndOfStreamTag();
+ }
+
+ /// <summary>
+ /// Merges data from the given stream into an existing message.
+ /// </summary>
+ /// <param name="message">The message to merge the data into.</param>
+ /// <param name="input">Stream containing the data to merge, which must be protobuf-encoded binary data.</param>
+ public static void MergeFrom(this IMessage message, Stream input)
+ {
+ ProtoPreconditions.CheckNotNull(message, "message");
+ ProtoPreconditions.CheckNotNull(input, "input");
+ CodedInputStream codedInput = new CodedInputStream(input);
+ message.MergeFrom(codedInput);
+ codedInput.CheckReadEndOfStreamTag();
+ }
+
+ /// <summary>
+ /// Merges length-delimited data from the given stream into an existing message.
+ /// </summary>
+ /// <remarks>
+ /// The stream is expected to contain a length and then the data. Only the amount of data
+ /// specified by the length will be consumed.
+ /// </remarks>
+ /// <param name="message">The message to merge the data into.</param>
+ /// <param name="input">Stream containing the data to merge, which must be protobuf-encoded binary data.</param>
+ public static void MergeDelimitedFrom(this IMessage message, Stream input)
+ {
+ ProtoPreconditions.CheckNotNull(message, "message");
+ ProtoPreconditions.CheckNotNull(input, "input");
+ int size = (int) CodedInputStream.ReadRawVarint32(input);
+ Stream limitedStream = new LimitedInputStream(input, size);
+ message.MergeFrom(limitedStream);
+ }
+
+ /// <summary>
+ /// Converts the given message into a byte array in protobuf encoding.
+ /// </summary>
+ /// <param name="message">The message to convert.</param>
+ /// <returns>The message data as a byte array.</returns>
+ public static byte[] ToByteArray(this IMessage message)
+ {
+ ProtoPreconditions.CheckNotNull(message, "message");
+ byte[] result = new byte[message.CalculateSize()];
+ CodedOutputStream output = new CodedOutputStream(result);
+ message.WriteTo(output);
+ output.CheckNoSpaceLeft();
+ return result;
+ }
+
+ /// <summary>
+ /// Writes the given message data to the given stream in protobuf encoding.
+ /// </summary>
+ /// <param name="message">The message to write to the stream.</param>
+ /// <param name="output">The stream to write to.</param>
+ public static void WriteTo(this IMessage message, Stream output)
+ {
+ ProtoPreconditions.CheckNotNull(message, "message");
+ ProtoPreconditions.CheckNotNull(output, "output");
+ CodedOutputStream codedOutput = new CodedOutputStream(output);
+ message.WriteTo(codedOutput);
+ codedOutput.Flush();
+ }
+
+ /// <summary>
+ /// Writes the length and then data of the given message to a stream.
+ /// </summary>
+ /// <param name="message">The message to write.</param>
+ /// <param name="output">The output stream to write to.</param>
+ public static void WriteDelimitedTo(this IMessage message, Stream output)
+ {
+ ProtoPreconditions.CheckNotNull(message, "message");
+ ProtoPreconditions.CheckNotNull(output, "output");
+ CodedOutputStream codedOutput = new CodedOutputStream(output);
+ codedOutput.WriteRawVarint32((uint)message.CalculateSize());
+ message.WriteTo(codedOutput);
+ codedOutput.Flush();
+ }
+
+ /// <summary>
+ /// Converts the given message into a byte string in protobuf encoding.
+ /// </summary>
+ /// <param name="message">The message to convert.</param>
+ /// <returns>The message data as a byte string.</returns>
+ public static ByteString ToByteString(this IMessage message)
+ {
+ ProtoPreconditions.CheckNotNull(message, "message");
+ return ByteString.AttachBytes(message.ToByteArray());
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/MessageParser.cs b/third_party/protobuf/csharp/src/Google.Protobuf/MessageParser.cs
new file mode 100644
index 0000000000..8889638b20
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/MessageParser.cs
@@ -0,0 +1,267 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.IO;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// A general message parser, typically used by reflection-based code as all the methods
+ /// return simple <see cref="IMessage"/>.
+ /// </summary>
+ public class MessageParser
+ {
+ private Func<IMessage> factory;
+
+ internal MessageParser(Func<IMessage> factory)
+ {
+ this.factory = factory;
+ }
+
+ /// <summary>
+ /// Creates a template instance ready for population.
+ /// </summary>
+ /// <returns>An empty message.</returns>
+ internal IMessage CreateTemplate()
+ {
+ return factory();
+ }
+
+ /// <summary>
+ /// Parses a message from a byte array.
+ /// </summary>
+ /// <param name="data">The byte array containing the message. Must not be null.</param>
+ /// <returns>The newly parsed message.</returns>
+ public IMessage ParseFrom(byte[] data)
+ {
+ ProtoPreconditions.CheckNotNull(data, "data");
+ IMessage message = factory();
+ message.MergeFrom(data);
+ return message;
+ }
+
+ /// <summary>
+ /// Parses a message from the given byte string.
+ /// </summary>
+ /// <param name="data">The data to parse.</param>
+ /// <returns>The parsed message.</returns>
+ public IMessage ParseFrom(ByteString data)
+ {
+ ProtoPreconditions.CheckNotNull(data, "data");
+ IMessage message = factory();
+ message.MergeFrom(data);
+ return message;
+ }
+
+ /// <summary>
+ /// Parses a message from the given stream.
+ /// </summary>
+ /// <param name="input">The stream to parse.</param>
+ /// <returns>The parsed message.</returns>
+ public IMessage ParseFrom(Stream input)
+ {
+ IMessage message = factory();
+ message.MergeFrom(input);
+ return message;
+ }
+
+ /// <summary>
+ /// Parses a length-delimited message from the given stream.
+ /// </summary>
+ /// <remarks>
+ /// The stream is expected to contain a length and then the data. Only the amount of data
+ /// specified by the length will be consumed.
+ /// </remarks>
+ /// <param name="input">The stream to parse.</param>
+ /// <returns>The parsed message.</returns>
+ public IMessage ParseDelimitedFrom(Stream input)
+ {
+ IMessage message = factory();
+ message.MergeDelimitedFrom(input);
+ return message;
+ }
+
+ /// <summary>
+ /// Parses a message from the given coded input stream.
+ /// </summary>
+ /// <param name="input">The stream to parse.</param>
+ /// <returns>The parsed message.</returns>
+ public IMessage ParseFrom(CodedInputStream input)
+ {
+ IMessage message = factory();
+ message.MergeFrom(input);
+ return message;
+ }
+
+ /// <summary>
+ /// Parses a message from the given JSON.
+ /// </summary>
+ /// <param name="json">The JSON to parse.</param>
+ /// <returns>The parsed message.</returns>
+ /// <exception cref="InvalidJsonException">The JSON does not comply with RFC 7159</exception>
+ /// <exception cref="InvalidProtocolBufferException">The JSON does not represent a Protocol Buffers message correctly</exception>
+ public IMessage ParseJson(string json)
+ {
+ IMessage message = factory();
+ JsonParser.Default.Merge(message, json);
+ return message;
+ }
+ }
+
+ /// <summary>
+ /// A parser for a specific message type.
+ /// </summary>
+ /// <remarks>
+ /// <p>
+ /// This delegates most behavior to the
+ /// <see cref="IMessage.MergeFrom"/> implementation within the original type, but
+ /// provides convenient overloads to parse from a variety of sources.
+ /// </p>
+ /// <p>
+ /// Most applications will never need to create their own instances of this type;
+ /// instead, use the static <c>Parser</c> property of a generated message type to obtain a
+ /// parser for that type.
+ /// </p>
+ /// </remarks>
+ /// <typeparam name="T">The type of message to be parsed.</typeparam>
+ public sealed class MessageParser<T> : MessageParser where T : IMessage<T>
+ {
+ // Implementation note: all the methods here *could* just delegate up to the base class and cast the result.
+ // The current implementation avoids a virtual method call and a cast, which *may* be significant in some cases.
+ // Benchmarking work is required to measure the significance - but it's only a few lines of code in any case.
+ // The API wouldn't change anyway - just the implementation - so this work can be deferred.
+ private readonly Func<T> factory;
+
+ /// <summary>
+ /// Creates a new parser.
+ /// </summary>
+ /// <remarks>
+ /// The factory method is effectively an optimization over using a generic constraint
+ /// to require a parameterless constructor: delegates are significantly faster to execute.
+ /// </remarks>
+ /// <param name="factory">Function to invoke when a new, empty message is required.</param>
+ public MessageParser(Func<T> factory) : base(() => factory())
+ {
+ this.factory = factory;
+ }
+
+ /// <summary>
+ /// Creates a template instance ready for population.
+ /// </summary>
+ /// <returns>An empty message.</returns>
+ internal new T CreateTemplate()
+ {
+ return factory();
+ }
+
+ /// <summary>
+ /// Parses a message from a byte array.
+ /// </summary>
+ /// <param name="data">The byte array containing the message. Must not be null.</param>
+ /// <returns>The newly parsed message.</returns>
+ public new T ParseFrom(byte[] data)
+ {
+ ProtoPreconditions.CheckNotNull(data, "data");
+ T message = factory();
+ message.MergeFrom(data);
+ return message;
+ }
+
+ /// <summary>
+ /// Parses a message from the given byte string.
+ /// </summary>
+ /// <param name="data">The data to parse.</param>
+ /// <returns>The parsed message.</returns>
+ public new T ParseFrom(ByteString data)
+ {
+ ProtoPreconditions.CheckNotNull(data, "data");
+ T message = factory();
+ message.MergeFrom(data);
+ return message;
+ }
+
+ /// <summary>
+ /// Parses a message from the given stream.
+ /// </summary>
+ /// <param name="input">The stream to parse.</param>
+ /// <returns>The parsed message.</returns>
+ public new T ParseFrom(Stream input)
+ {
+ T message = factory();
+ message.MergeFrom(input);
+ return message;
+ }
+
+ /// <summary>
+ /// Parses a length-delimited message from the given stream.
+ /// </summary>
+ /// <remarks>
+ /// The stream is expected to contain a length and then the data. Only the amount of data
+ /// specified by the length will be consumed.
+ /// </remarks>
+ /// <param name="input">The stream to parse.</param>
+ /// <returns>The parsed message.</returns>
+ public new T ParseDelimitedFrom(Stream input)
+ {
+ T message = factory();
+ message.MergeDelimitedFrom(input);
+ return message;
+ }
+
+ /// <summary>
+ /// Parses a message from the given coded input stream.
+ /// </summary>
+ /// <param name="input">The stream to parse.</param>
+ /// <returns>The parsed message.</returns>
+ public new T ParseFrom(CodedInputStream input)
+ {
+ T message = factory();
+ message.MergeFrom(input);
+ return message;
+ }
+
+ /// <summary>
+ /// Parses a message from the given JSON.
+ /// </summary>
+ /// <param name="json">The JSON to parse.</param>
+ /// <returns>The parsed message.</returns>
+ /// <exception cref="InvalidJsonException">The JSON does not comply with RFC 7159</exception>
+ /// <exception cref="InvalidProtocolBufferException">The JSON does not represent a Protocol Buffers message correctly</exception>
+ public new T ParseJson(string json)
+ {
+ T message = factory();
+ JsonParser.Default.Merge(message, json);
+ return message;
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000000..9b179bd7cd
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Properties/AssemblyInfo.cs
@@ -0,0 +1,49 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System.Runtime.CompilerServices;
+using System.Security;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+
+#if !NCRUNCH
+[assembly: AllowPartiallyTrustedCallers]
+#endif
+
+[assembly: InternalsVisibleTo("Google.Protobuf.Test, PublicKey=" +
+ "002400000480000094000000060200000024000052534131000400000100010025800fbcfc63a1" +
+ "7c66b303aae80b03a6beaa176bb6bef883be436f2a1579edd80ce23edf151a1f4ced97af83abcd" +
+ "981207041fd5b2da3b498346fcfcd94910d52f25537c4a43ce3fbe17dc7d43e6cbdb4d8f1242dc" +
+ "b6bd9b5906be74da8daa7d7280f97130f318a16c07baf118839b156299a48522f9fae2371c9665" +
+ "c5ae9cb6")]
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/ProtoPreconditions.cs b/third_party/protobuf/csharp/src/Google.Protobuf/ProtoPreconditions.cs
new file mode 100644
index 0000000000..abaeb9b481
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/ProtoPreconditions.cs
@@ -0,0 +1,79 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// Helper methods for throwing exceptions when preconditions are not met.
+ /// </summary>
+ /// <remarks>
+ /// This class is used internally and by generated code; it is not particularly
+ /// expected to be used from application code, although nothing prevents it
+ /// from being used that way.
+ /// </remarks>
+ public static class ProtoPreconditions
+ {
+ /// <summary>
+ /// Throws an ArgumentNullException if the given value is null, otherwise
+ /// return the value to the caller.
+ /// </summary>
+ public static T CheckNotNull<T>(T value, string name) where T : class
+ {
+ if (value == null)
+ {
+ throw new ArgumentNullException(name);
+ }
+ return value;
+ }
+
+ /// <summary>
+ /// Throws an ArgumentNullException if the given value is null, otherwise
+ /// return the value to the caller.
+ /// </summary>
+ /// <remarks>
+ /// This is equivalent to <see cref="CheckNotNull{T}(T, string)"/> but without the type parameter
+ /// constraint. In most cases, the constraint is useful to prevent you from calling CheckNotNull
+ /// with a value type - but it gets in the way if either you want to use it with a nullable
+ /// value type, or you want to use it with an unconstrained type parameter.
+ /// </remarks>
+ internal static T CheckNotNullUnconstrained<T>(T value, string name)
+ {
+ if (value == null)
+ {
+ throw new ArgumentNullException(name);
+ }
+ return value;
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/CustomOptions.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/CustomOptions.cs
new file mode 100644
index 0000000000..88b3ec000d
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/CustomOptions.cs
@@ -0,0 +1,390 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2017 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.
+#endregion
+
+using System;
+using System.Collections.Generic;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Container for a set of custom options specified within a message, field etc.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// This type is publicly immutable, but internally mutable. It is only populated
+ /// by the descriptor parsing code - by the time any user code is able to see an instance,
+ /// it will be fully initialized.
+ /// </para>
+ /// <para>
+ /// If an option is requested using the incorrect method, an answer may still be returned: all
+ /// of the numeric types are represented internally using 64-bit integers, for example. It is up to
+ /// the caller to ensure that they make the appropriate method call for the option they're interested in.
+ /// Note that enum options are simply stored as integers, so the value should be fetched using
+ /// <see cref="TryGetInt32(int, out int)"/> and then cast appropriately.
+ /// </para>
+ /// <para>
+ /// Repeated options are currently not supported. Asking for a single value of an option
+ /// which was actually repeated will return the last value, except for message types where
+ /// all the set values are merged together.
+ /// </para>
+ /// </remarks>
+ public sealed class CustomOptions
+ {
+ /// <summary>
+ /// Singleton for all descriptors with an empty set of options.
+ /// </summary>
+ internal static readonly CustomOptions Empty = new CustomOptions();
+
+ /// <summary>
+ /// A sequence of values per field. This needs to be per field rather than per tag to allow correct deserialization
+ /// of repeated fields which could be "int, ByteString, int" - unlikely as that is. The fact that values are boxed
+ /// is unfortunate; we might be able to use a struct instead, and we could combine uint and ulong values.
+ /// </summary>
+ private readonly Dictionary<int, List<FieldValue>> valuesByField = new Dictionary<int, List<FieldValue>>();
+
+ private CustomOptions() { }
+
+ /// <summary>
+ /// Retrieves a Boolean value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetBool(int field, out bool value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ value = tmp == 1UL;
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves a signed 32-bit integer value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetInt32(int field, out int value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ value = (int) tmp.GetValueOrDefault();
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves a signed 64-bit integer value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetInt64(int field, out long value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ value = (long) tmp.GetValueOrDefault();
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves an unsigned 32-bit integer value for the specified option field,
+ /// assuming a fixed-length representation.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetFixed32(int field, out uint value) => TryGetUInt32(field, out value);
+
+ /// <summary>
+ /// Retrieves an unsigned 64-bit integer value for the specified option field,
+ /// assuming a fixed-length representation.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetFixed64(int field, out ulong value) => TryGetUInt64(field, out value);
+
+ /// <summary>
+ /// Retrieves a signed 32-bit integer value for the specified option field,
+ /// assuming a fixed-length representation.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetSFixed32(int field, out int value) => TryGetInt32(field, out value);
+
+ /// <summary>
+ /// Retrieves a signed 64-bit integer value for the specified option field,
+ /// assuming a fixed-length representation.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetSFixed64(int field, out long value) => TryGetInt64(field, out value);
+
+ /// <summary>
+ /// Retrieves a signed 32-bit integer value for the specified option field,
+ /// assuming a zigzag encoding.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetSInt32(int field, out int value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ value = CodedInputStream.DecodeZigZag32((uint) tmp.GetValueOrDefault());
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves a signed 64-bit integer value for the specified option field,
+ /// assuming a zigzag encoding.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetSInt64(int field, out long value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ value = CodedInputStream.DecodeZigZag64(tmp.GetValueOrDefault());
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves an unsigned 32-bit integer value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetUInt32(int field, out uint value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ value = (uint) tmp.GetValueOrDefault();
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves an unsigned 64-bit integer value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetUInt64(int field, out ulong value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ value = tmp.GetValueOrDefault();
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves a 32-bit floating point value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetFloat(int field, out float value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ int int32 = (int) tmp.GetValueOrDefault();
+ byte[] bytes = BitConverter.GetBytes(int32);
+ value = BitConverter.ToSingle(bytes, 0);
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves a 64-bit floating point value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetDouble(int field, out double value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ value = BitConverter.Int64BitsToDouble((long) tmp.GetValueOrDefault());
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves a string value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetString(int field, out string value)
+ {
+ ByteString bytes = GetLastByteStringValue(field);
+ value = bytes?.ToStringUtf8();
+ return bytes != null;
+ }
+
+ /// <summary>
+ /// Retrieves a bytes value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetBytes(int field, out ByteString value)
+ {
+ ByteString bytes = GetLastByteStringValue(field);
+ value = bytes;
+ return bytes != null;
+ }
+
+ /// <summary>
+ /// Retrieves a message value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetMessage<T>(int field, out T value) where T : class, IMessage, new()
+ {
+ value = null;
+ List<FieldValue> values;
+ if (!valuesByField.TryGetValue(field, out values))
+ {
+ return false;
+ }
+ foreach (FieldValue fieldValue in values)
+ {
+ if (fieldValue.ByteString != null)
+ {
+ if (value == null)
+ {
+ value = new T();
+ }
+ value.MergeFrom(fieldValue.ByteString);
+ }
+ }
+ return value != null;
+ }
+
+ private ulong? GetLastNumericValue(int field)
+ {
+ List<FieldValue> values;
+ if (!valuesByField.TryGetValue(field, out values))
+ {
+ return null;
+ }
+ for (int i = values.Count - 1; i >= 0; i--)
+ {
+ // A non-bytestring value is a numeric value
+ if (values[i].ByteString == null)
+ {
+ return values[i].Number;
+ }
+ }
+ return null;
+ }
+
+ private ByteString GetLastByteStringValue(int field)
+ {
+ List<FieldValue> values;
+ if (!valuesByField.TryGetValue(field, out values))
+ {
+ return null;
+ }
+ for (int i = values.Count - 1; i >= 0; i--)
+ {
+ if (values[i].ByteString != null)
+ {
+ return values[i].ByteString;
+ }
+ }
+ return null;
+ }
+
+ /// <summary>
+ /// Reads an unknown field, either parsing it and storing it or skipping it.
+ /// </summary>
+ /// <remarks>
+ /// If the current set of options is empty and we manage to read a field, a new set of options
+ /// will be created and returned. Otherwise, the return value is <c>this</c>. This allows
+ /// us to start with a singleton empty set of options and just create new ones where necessary.
+ /// </remarks>
+ /// <param name="input">Input stream to read from. </param>
+ /// <returns>The resulting set of custom options, either <c>this</c> or a new set.</returns>
+ internal CustomOptions ReadOrSkipUnknownField(CodedInputStream input)
+ {
+ var tag = input.LastTag;
+ var field = WireFormat.GetTagFieldNumber(tag);
+ switch (WireFormat.GetTagWireType(tag))
+ {
+ case WireFormat.WireType.LengthDelimited:
+ return AddValue(field, new FieldValue(input.ReadBytes()));
+ case WireFormat.WireType.Fixed32:
+ return AddValue(field, new FieldValue(input.ReadFixed32()));
+ case WireFormat.WireType.Fixed64:
+ return AddValue(field, new FieldValue(input.ReadFixed64()));
+ case WireFormat.WireType.Varint:
+ return AddValue(field, new FieldValue(input.ReadRawVarint64()));
+ // For StartGroup, EndGroup or any wire format we don't understand,
+ // just use the normal behavior (call SkipLastField).
+ default:
+ input.SkipLastField();
+ return this;
+ }
+ }
+
+ private CustomOptions AddValue(int field, FieldValue value)
+ {
+ var ret = valuesByField.Count == 0 ? new CustomOptions() : this;
+ List<FieldValue> valuesForField;
+ if (!ret.valuesByField.TryGetValue(field, out valuesForField))
+ {
+ // Expect almost all
+ valuesForField = new List<FieldValue>(1);
+ ret.valuesByField[field] = valuesForField;
+ }
+ valuesForField.Add(value);
+ return ret;
+ }
+
+ /// <summary>
+ /// All field values can be stored as a byte string or a 64-bit integer.
+ /// This struct avoids unnecessary boxing.
+ /// </summary>
+ private struct FieldValue
+ {
+ internal ulong Number { get; }
+ internal ByteString ByteString { get; }
+
+ internal FieldValue(ulong number)
+ {
+ Number = number;
+ ByteString = null;
+ }
+
+ internal FieldValue(ByteString byteString)
+ {
+ Number = 0;
+ ByteString = byteString;
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/Descriptor.cs
new file mode 100644
index 0000000000..d4b78daec9
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/Descriptor.cs
@@ -0,0 +1,6121 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/descriptor.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.Reflection {
+
+ /// <summary>Holder for reflection information generated from google/protobuf/descriptor.proto</summary>
+ internal static partial class DescriptorReflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for google/protobuf/descriptor.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static DescriptorReflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "CiBnb29nbGUvcHJvdG9idWYvZGVzY3JpcHRvci5wcm90bxIPZ29vZ2xlLnBy",
+ "b3RvYnVmIkcKEUZpbGVEZXNjcmlwdG9yU2V0EjIKBGZpbGUYASADKAsyJC5n",
+ "b29nbGUucHJvdG9idWYuRmlsZURlc2NyaXB0b3JQcm90byLbAwoTRmlsZURl",
+ "c2NyaXB0b3JQcm90bxIMCgRuYW1lGAEgASgJEg8KB3BhY2thZ2UYAiABKAkS",
+ "EgoKZGVwZW5kZW5jeRgDIAMoCRIZChFwdWJsaWNfZGVwZW5kZW5jeRgKIAMo",
+ "BRIXCg93ZWFrX2RlcGVuZGVuY3kYCyADKAUSNgoMbWVzc2FnZV90eXBlGAQg",
+ "AygLMiAuZ29vZ2xlLnByb3RvYnVmLkRlc2NyaXB0b3JQcm90bxI3CgllbnVt",
+ "X3R5cGUYBSADKAsyJC5nb29nbGUucHJvdG9idWYuRW51bURlc2NyaXB0b3JQ",
+ "cm90bxI4CgdzZXJ2aWNlGAYgAygLMicuZ29vZ2xlLnByb3RvYnVmLlNlcnZp",
+ "Y2VEZXNjcmlwdG9yUHJvdG8SOAoJZXh0ZW5zaW9uGAcgAygLMiUuZ29vZ2xl",
+ "LnByb3RvYnVmLkZpZWxkRGVzY3JpcHRvclByb3RvEi0KB29wdGlvbnMYCCAB",
+ "KAsyHC5nb29nbGUucHJvdG9idWYuRmlsZU9wdGlvbnMSOQoQc291cmNlX2Nv",
+ "ZGVfaW5mbxgJIAEoCzIfLmdvb2dsZS5wcm90b2J1Zi5Tb3VyY2VDb2RlSW5m",
+ "bxIOCgZzeW50YXgYDCABKAki8AQKD0Rlc2NyaXB0b3JQcm90bxIMCgRuYW1l",
+ "GAEgASgJEjQKBWZpZWxkGAIgAygLMiUuZ29vZ2xlLnByb3RvYnVmLkZpZWxk",
+ "RGVzY3JpcHRvclByb3RvEjgKCWV4dGVuc2lvbhgGIAMoCzIlLmdvb2dsZS5w",
+ "cm90b2J1Zi5GaWVsZERlc2NyaXB0b3JQcm90bxI1CgtuZXN0ZWRfdHlwZRgD",
+ "IAMoCzIgLmdvb2dsZS5wcm90b2J1Zi5EZXNjcmlwdG9yUHJvdG8SNwoJZW51",
+ "bV90eXBlGAQgAygLMiQuZ29vZ2xlLnByb3RvYnVmLkVudW1EZXNjcmlwdG9y",
+ "UHJvdG8SSAoPZXh0ZW5zaW9uX3JhbmdlGAUgAygLMi8uZ29vZ2xlLnByb3Rv",
+ "YnVmLkRlc2NyaXB0b3JQcm90by5FeHRlbnNpb25SYW5nZRI5CgpvbmVvZl9k",
+ "ZWNsGAggAygLMiUuZ29vZ2xlLnByb3RvYnVmLk9uZW9mRGVzY3JpcHRvclBy",
+ "b3RvEjAKB29wdGlvbnMYByABKAsyHy5nb29nbGUucHJvdG9idWYuTWVzc2Fn",
+ "ZU9wdGlvbnMSRgoOcmVzZXJ2ZWRfcmFuZ2UYCSADKAsyLi5nb29nbGUucHJv",
+ "dG9idWYuRGVzY3JpcHRvclByb3RvLlJlc2VydmVkUmFuZ2USFQoNcmVzZXJ2",
+ "ZWRfbmFtZRgKIAMoCRosCg5FeHRlbnNpb25SYW5nZRINCgVzdGFydBgBIAEo",
+ "BRILCgNlbmQYAiABKAUaKwoNUmVzZXJ2ZWRSYW5nZRINCgVzdGFydBgBIAEo",
+ "BRILCgNlbmQYAiABKAUivAUKFEZpZWxkRGVzY3JpcHRvclByb3RvEgwKBG5h",
+ "bWUYASABKAkSDgoGbnVtYmVyGAMgASgFEjoKBWxhYmVsGAQgASgOMisuZ29v",
+ "Z2xlLnByb3RvYnVmLkZpZWxkRGVzY3JpcHRvclByb3RvLkxhYmVsEjgKBHR5",
+ "cGUYBSABKA4yKi5nb29nbGUucHJvdG9idWYuRmllbGREZXNjcmlwdG9yUHJv",
+ "dG8uVHlwZRIRCgl0eXBlX25hbWUYBiABKAkSEAoIZXh0ZW5kZWUYAiABKAkS",
+ "FQoNZGVmYXVsdF92YWx1ZRgHIAEoCRITCgtvbmVvZl9pbmRleBgJIAEoBRIR",
+ "Cglqc29uX25hbWUYCiABKAkSLgoHb3B0aW9ucxgIIAEoCzIdLmdvb2dsZS5w",
+ "cm90b2J1Zi5GaWVsZE9wdGlvbnMitgIKBFR5cGUSDwoLVFlQRV9ET1VCTEUQ",
+ "ARIOCgpUWVBFX0ZMT0FUEAISDgoKVFlQRV9JTlQ2NBADEg8KC1RZUEVfVUlO",
+ "VDY0EAQSDgoKVFlQRV9JTlQzMhAFEhAKDFRZUEVfRklYRUQ2NBAGEhAKDFRZ",
+ "UEVfRklYRUQzMhAHEg0KCVRZUEVfQk9PTBAIEg8KC1RZUEVfU1RSSU5HEAkS",
+ "DgoKVFlQRV9HUk9VUBAKEhAKDFRZUEVfTUVTU0FHRRALEg4KClRZUEVfQllU",
+ "RVMQDBIPCgtUWVBFX1VJTlQzMhANEg0KCVRZUEVfRU5VTRAOEhEKDVRZUEVf",
+ "U0ZJWEVEMzIQDxIRCg1UWVBFX1NGSVhFRDY0EBASDwoLVFlQRV9TSU5UMzIQ",
+ "ERIPCgtUWVBFX1NJTlQ2NBASIkMKBUxhYmVsEhIKDkxBQkVMX09QVElPTkFM",
+ "EAESEgoOTEFCRUxfUkVRVUlSRUQQAhISCg5MQUJFTF9SRVBFQVRFRBADIlQK",
+ "FE9uZW9mRGVzY3JpcHRvclByb3RvEgwKBG5hbWUYASABKAkSLgoHb3B0aW9u",
+ "cxgCIAEoCzIdLmdvb2dsZS5wcm90b2J1Zi5PbmVvZk9wdGlvbnMijAEKE0Vu",
+ "dW1EZXNjcmlwdG9yUHJvdG8SDAoEbmFtZRgBIAEoCRI4CgV2YWx1ZRgCIAMo",
+ "CzIpLmdvb2dsZS5wcm90b2J1Zi5FbnVtVmFsdWVEZXNjcmlwdG9yUHJvdG8S",
+ "LQoHb3B0aW9ucxgDIAEoCzIcLmdvb2dsZS5wcm90b2J1Zi5FbnVtT3B0aW9u",
+ "cyJsChhFbnVtVmFsdWVEZXNjcmlwdG9yUHJvdG8SDAoEbmFtZRgBIAEoCRIO",
+ "CgZudW1iZXIYAiABKAUSMgoHb3B0aW9ucxgDIAEoCzIhLmdvb2dsZS5wcm90",
+ "b2J1Zi5FbnVtVmFsdWVPcHRpb25zIpABChZTZXJ2aWNlRGVzY3JpcHRvclBy",
+ "b3RvEgwKBG5hbWUYASABKAkSNgoGbWV0aG9kGAIgAygLMiYuZ29vZ2xlLnBy",
+ "b3RvYnVmLk1ldGhvZERlc2NyaXB0b3JQcm90bxIwCgdvcHRpb25zGAMgASgL",
+ "Mh8uZ29vZ2xlLnByb3RvYnVmLlNlcnZpY2VPcHRpb25zIsEBChVNZXRob2RE",
+ "ZXNjcmlwdG9yUHJvdG8SDAoEbmFtZRgBIAEoCRISCgppbnB1dF90eXBlGAIg",
+ "ASgJEhMKC291dHB1dF90eXBlGAMgASgJEi8KB29wdGlvbnMYBCABKAsyHi5n",
+ "b29nbGUucHJvdG9idWYuTWV0aG9kT3B0aW9ucxIfChBjbGllbnRfc3RyZWFt",
+ "aW5nGAUgASgIOgVmYWxzZRIfChBzZXJ2ZXJfc3RyZWFtaW5nGAYgASgIOgVm",
+ "YWxzZSK0BQoLRmlsZU9wdGlvbnMSFAoMamF2YV9wYWNrYWdlGAEgASgJEhwK",
+ "FGphdmFfb3V0ZXJfY2xhc3NuYW1lGAggASgJEiIKE2phdmFfbXVsdGlwbGVf",
+ "ZmlsZXMYCiABKAg6BWZhbHNlEikKHWphdmFfZ2VuZXJhdGVfZXF1YWxzX2Fu",
+ "ZF9oYXNoGBQgASgIQgIYARIlChZqYXZhX3N0cmluZ19jaGVja191dGY4GBsg",
+ "ASgIOgVmYWxzZRJGCgxvcHRpbWl6ZV9mb3IYCSABKA4yKS5nb29nbGUucHJv",
+ "dG9idWYuRmlsZU9wdGlvbnMuT3B0aW1pemVNb2RlOgVTUEVFRBISCgpnb19w",
+ "YWNrYWdlGAsgASgJEiIKE2NjX2dlbmVyaWNfc2VydmljZXMYECABKAg6BWZh",
+ "bHNlEiQKFWphdmFfZ2VuZXJpY19zZXJ2aWNlcxgRIAEoCDoFZmFsc2USIgoT",
+ "cHlfZ2VuZXJpY19zZXJ2aWNlcxgSIAEoCDoFZmFsc2USGQoKZGVwcmVjYXRl",
+ "ZBgXIAEoCDoFZmFsc2USHwoQY2NfZW5hYmxlX2FyZW5hcxgfIAEoCDoFZmFs",
+ "c2USGQoRb2JqY19jbGFzc19wcmVmaXgYJCABKAkSGAoQY3NoYXJwX25hbWVz",
+ "cGFjZRglIAEoCRIUCgxzd2lmdF9wcmVmaXgYJyABKAkSGAoQcGhwX2NsYXNz",
+ "X3ByZWZpeBgoIAEoCRJDChR1bmludGVycHJldGVkX29wdGlvbhjnByADKAsy",
+ "JC5nb29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRlZE9wdGlvbiI6CgxPcHRp",
+ "bWl6ZU1vZGUSCQoFU1BFRUQQARINCglDT0RFX1NJWkUQAhIQCgxMSVRFX1JV",
+ "TlRJTUUQAyoJCOgHEICAgIACSgQIJhAnIuwBCg5NZXNzYWdlT3B0aW9ucxIm",
+ "ChdtZXNzYWdlX3NldF93aXJlX2Zvcm1hdBgBIAEoCDoFZmFsc2USLgofbm9f",
+ "c3RhbmRhcmRfZGVzY3JpcHRvcl9hY2Nlc3NvchgCIAEoCDoFZmFsc2USGQoK",
+ "ZGVwcmVjYXRlZBgDIAEoCDoFZmFsc2USEQoJbWFwX2VudHJ5GAcgASgIEkMK",
+ "FHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1",
+ "Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICAgAJKBAgIEAkingMKDEZp",
+ "ZWxkT3B0aW9ucxI6CgVjdHlwZRgBIAEoDjIjLmdvb2dsZS5wcm90b2J1Zi5G",
+ "aWVsZE9wdGlvbnMuQ1R5cGU6BlNUUklORxIOCgZwYWNrZWQYAiABKAgSPwoG",
+ "anN0eXBlGAYgASgOMiQuZ29vZ2xlLnByb3RvYnVmLkZpZWxkT3B0aW9ucy5K",
+ "U1R5cGU6CUpTX05PUk1BTBITCgRsYXp5GAUgASgIOgVmYWxzZRIZCgpkZXBy",
+ "ZWNhdGVkGAMgASgIOgVmYWxzZRITCgR3ZWFrGAogASgIOgVmYWxzZRJDChR1",
+ "bmludGVycHJldGVkX29wdGlvbhjnByADKAsyJC5nb29nbGUucHJvdG9idWYu",
+ "VW5pbnRlcnByZXRlZE9wdGlvbiIvCgVDVHlwZRIKCgZTVFJJTkcQABIICgRD",
+ "T1JEEAESEAoMU1RSSU5HX1BJRUNFEAIiNQoGSlNUeXBlEg0KCUpTX05PUk1B",
+ "TBAAEg0KCUpTX1NUUklORxABEg0KCUpTX05VTUJFUhACKgkI6AcQgICAgAJK",
+ "BAgEEAUiXgoMT25lb2ZPcHRpb25zEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9u",
+ "GOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9u",
+ "KgkI6AcQgICAgAIijQEKC0VudW1PcHRpb25zEhMKC2FsbG93X2FsaWFzGAIg",
+ "ASgIEhkKCmRlcHJlY2F0ZWQYAyABKAg6BWZhbHNlEkMKFHVuaW50ZXJwcmV0",
+ "ZWRfb3B0aW9uGOcHIAMoCzIkLmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJl",
+ "dGVkT3B0aW9uKgkI6AcQgICAgAIifQoQRW51bVZhbHVlT3B0aW9ucxIZCgpk",
+ "ZXByZWNhdGVkGAEgASgIOgVmYWxzZRJDChR1bmludGVycHJldGVkX29wdGlv",
+ "bhjnByADKAsyJC5nb29nbGUucHJvdG9idWYuVW5pbnRlcnByZXRlZE9wdGlv",
+ "bioJCOgHEICAgIACInsKDlNlcnZpY2VPcHRpb25zEhkKCmRlcHJlY2F0ZWQY",
+ "ISABKAg6BWZhbHNlEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIk",
+ "Lmdvb2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uKgkI6AcQgICA",
+ "gAIirQIKDU1ldGhvZE9wdGlvbnMSGQoKZGVwcmVjYXRlZBghIAEoCDoFZmFs",
+ "c2USXwoRaWRlbXBvdGVuY3lfbGV2ZWwYIiABKA4yLy5nb29nbGUucHJvdG9i",
+ "dWYuTWV0aG9kT3B0aW9ucy5JZGVtcG90ZW5jeUxldmVsOhNJREVNUE9URU5D",
+ "WV9VTktOT1dOEkMKFHVuaW50ZXJwcmV0ZWRfb3B0aW9uGOcHIAMoCzIkLmdv",
+ "b2dsZS5wcm90b2J1Zi5VbmludGVycHJldGVkT3B0aW9uIlAKEElkZW1wb3Rl",
+ "bmN5TGV2ZWwSFwoTSURFTVBPVEVOQ1lfVU5LTk9XThAAEhMKD05PX1NJREVf",
+ "RUZGRUNUUxABEg4KCklERU1QT1RFTlQQAioJCOgHEICAgIACIp4CChNVbmlu",
+ "dGVycHJldGVkT3B0aW9uEjsKBG5hbWUYAiADKAsyLS5nb29nbGUucHJvdG9i",
+ "dWYuVW5pbnRlcnByZXRlZE9wdGlvbi5OYW1lUGFydBIYChBpZGVudGlmaWVy",
+ "X3ZhbHVlGAMgASgJEhoKEnBvc2l0aXZlX2ludF92YWx1ZRgEIAEoBBIaChJu",
+ "ZWdhdGl2ZV9pbnRfdmFsdWUYBSABKAMSFAoMZG91YmxlX3ZhbHVlGAYgASgB",
+ "EhQKDHN0cmluZ192YWx1ZRgHIAEoDBIXCg9hZ2dyZWdhdGVfdmFsdWUYCCAB",
+ "KAkaMwoITmFtZVBhcnQSEQoJbmFtZV9wYXJ0GAEgAigJEhQKDGlzX2V4dGVu",
+ "c2lvbhgCIAIoCCLVAQoOU291cmNlQ29kZUluZm8SOgoIbG9jYXRpb24YASAD",
+ "KAsyKC5nb29nbGUucHJvdG9idWYuU291cmNlQ29kZUluZm8uTG9jYXRpb24a",
+ "hgEKCExvY2F0aW9uEhAKBHBhdGgYASADKAVCAhABEhAKBHNwYW4YAiADKAVC",
+ "AhABEhgKEGxlYWRpbmdfY29tbWVudHMYAyABKAkSGQoRdHJhaWxpbmdfY29t",
+ "bWVudHMYBCABKAkSIQoZbGVhZGluZ19kZXRhY2hlZF9jb21tZW50cxgGIAMo",
+ "CSKnAQoRR2VuZXJhdGVkQ29kZUluZm8SQQoKYW5ub3RhdGlvbhgBIAMoCzIt",
+ "Lmdvb2dsZS5wcm90b2J1Zi5HZW5lcmF0ZWRDb2RlSW5mby5Bbm5vdGF0aW9u",
+ "Gk8KCkFubm90YXRpb24SEAoEcGF0aBgBIAMoBUICEAESEwoLc291cmNlX2Zp",
+ "bGUYAiABKAkSDQoFYmVnaW4YAyABKAUSCwoDZW5kGAQgASgFQowBChNjb20u",
+ "Z29vZ2xlLnByb3RvYnVmQhBEZXNjcmlwdG9yUHJvdG9zSAFaPmdpdGh1Yi5j",
+ "b20vZ29sYW5nL3Byb3RvYnVmL3Byb3RvYy1nZW4tZ28vZGVzY3JpcHRvcjtk",
+ "ZXNjcmlwdG9yogIDR1BCqgIaR29vZ2xlLlByb3RvYnVmLlJlZmxlY3Rpb24="));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { },
+ new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.FileDescriptorSet), global::Google.Protobuf.Reflection.FileDescriptorSet.Parser, new[]{ "File" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.FileDescriptorProto), global::Google.Protobuf.Reflection.FileDescriptorProto.Parser, new[]{ "Name", "Package", "Dependency", "PublicDependency", "WeakDependency", "MessageType", "EnumType", "Service", "Extension", "Options", "SourceCodeInfo", "Syntax" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.DescriptorProto), global::Google.Protobuf.Reflection.DescriptorProto.Parser, new[]{ "Name", "Field", "Extension", "NestedType", "EnumType", "ExtensionRange", "OneofDecl", "Options", "ReservedRange", "ReservedName" }, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.DescriptorProto.Types.ExtensionRange), global::Google.Protobuf.Reflection.DescriptorProto.Types.ExtensionRange.Parser, new[]{ "Start", "End" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.DescriptorProto.Types.ReservedRange), global::Google.Protobuf.Reflection.DescriptorProto.Types.ReservedRange.Parser, new[]{ "Start", "End" }, null, null, null)}),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.FieldDescriptorProto), global::Google.Protobuf.Reflection.FieldDescriptorProto.Parser, new[]{ "Name", "Number", "Label", "Type", "TypeName", "Extendee", "DefaultValue", "OneofIndex", "JsonName", "Options" }, null, new[]{ typeof(global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type), typeof(global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label) }, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.OneofDescriptorProto), global::Google.Protobuf.Reflection.OneofDescriptorProto.Parser, new[]{ "Name", "Options" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.EnumDescriptorProto), global::Google.Protobuf.Reflection.EnumDescriptorProto.Parser, new[]{ "Name", "Value", "Options" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.EnumValueDescriptorProto), global::Google.Protobuf.Reflection.EnumValueDescriptorProto.Parser, new[]{ "Name", "Number", "Options" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.ServiceDescriptorProto), global::Google.Protobuf.Reflection.ServiceDescriptorProto.Parser, new[]{ "Name", "Method", "Options" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.MethodDescriptorProto), global::Google.Protobuf.Reflection.MethodDescriptorProto.Parser, new[]{ "Name", "InputType", "OutputType", "Options", "ClientStreaming", "ServerStreaming" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.FileOptions), global::Google.Protobuf.Reflection.FileOptions.Parser, new[]{ "JavaPackage", "JavaOuterClassname", "JavaMultipleFiles", "JavaGenerateEqualsAndHash", "JavaStringCheckUtf8", "OptimizeFor", "GoPackage", "CcGenericServices", "JavaGenericServices", "PyGenericServices", "Deprecated", "CcEnableArenas", "ObjcClassPrefix", "CsharpNamespace", "SwiftPrefix", "PhpClassPrefix", "UninterpretedOption" }, null, new[]{ typeof(global::Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode) }, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.MessageOptions), global::Google.Protobuf.Reflection.MessageOptions.Parser, new[]{ "MessageSetWireFormat", "NoStandardDescriptorAccessor", "Deprecated", "MapEntry", "UninterpretedOption" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.FieldOptions), global::Google.Protobuf.Reflection.FieldOptions.Parser, new[]{ "Ctype", "Packed", "Jstype", "Lazy", "Deprecated", "Weak", "UninterpretedOption" }, null, new[]{ typeof(global::Google.Protobuf.Reflection.FieldOptions.Types.CType), typeof(global::Google.Protobuf.Reflection.FieldOptions.Types.JSType) }, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.OneofOptions), global::Google.Protobuf.Reflection.OneofOptions.Parser, new[]{ "UninterpretedOption" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.EnumOptions), global::Google.Protobuf.Reflection.EnumOptions.Parser, new[]{ "AllowAlias", "Deprecated", "UninterpretedOption" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.EnumValueOptions), global::Google.Protobuf.Reflection.EnumValueOptions.Parser, new[]{ "Deprecated", "UninterpretedOption" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.ServiceOptions), global::Google.Protobuf.Reflection.ServiceOptions.Parser, new[]{ "Deprecated", "UninterpretedOption" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.MethodOptions), global::Google.Protobuf.Reflection.MethodOptions.Parser, new[]{ "Deprecated", "IdempotencyLevel", "UninterpretedOption" }, null, new[]{ typeof(global::Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel) }, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.UninterpretedOption), global::Google.Protobuf.Reflection.UninterpretedOption.Parser, new[]{ "Name", "IdentifierValue", "PositiveIntValue", "NegativeIntValue", "DoubleValue", "StringValue", "AggregateValue" }, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.UninterpretedOption.Types.NamePart), global::Google.Protobuf.Reflection.UninterpretedOption.Types.NamePart.Parser, new[]{ "NamePart_", "IsExtension" }, null, null, null)}),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.SourceCodeInfo), global::Google.Protobuf.Reflection.SourceCodeInfo.Parser, new[]{ "Location" }, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.SourceCodeInfo.Types.Location), global::Google.Protobuf.Reflection.SourceCodeInfo.Types.Location.Parser, new[]{ "Path", "Span", "LeadingComments", "TrailingComments", "LeadingDetachedComments" }, null, null, null)}),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.GeneratedCodeInfo), global::Google.Protobuf.Reflection.GeneratedCodeInfo.Parser, new[]{ "Annotation" }, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation), global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation.Parser, new[]{ "Path", "SourceFile", "Begin", "End" }, null, null, null)})
+ }));
+ }
+ #endregion
+
+ }
+ #region Messages
+ /// <summary>
+ /// The protocol compiler can output a FileDescriptorSet containing the .proto
+ /// files it parses.
+ /// </summary>
+ internal sealed partial class FileDescriptorSet : pb::IMessage<FileDescriptorSet> {
+ private static readonly pb::MessageParser<FileDescriptorSet> _parser = new pb::MessageParser<FileDescriptorSet>(() => new FileDescriptorSet());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<FileDescriptorSet> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FileDescriptorSet() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FileDescriptorSet(FileDescriptorSet other) : this() {
+ file_ = other.file_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FileDescriptorSet Clone() {
+ return new FileDescriptorSet(this);
+ }
+
+ /// <summary>Field number for the "file" field.</summary>
+ public const int FileFieldNumber = 1;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.FileDescriptorProto> _repeated_file_codec
+ = pb::FieldCodec.ForMessage(10, global::Google.Protobuf.Reflection.FileDescriptorProto.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.FileDescriptorProto> file_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.FileDescriptorProto>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.FileDescriptorProto> File {
+ get { return file_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as FileDescriptorSet);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(FileDescriptorSet other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if(!file_.Equals(other.file_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= file_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ file_.WriteTo(output, _repeated_file_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += file_.CalculateSize(_repeated_file_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(FileDescriptorSet other) {
+ if (other == null) {
+ return;
+ }
+ file_.Add(other.file_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ file_.AddEntriesFrom(input, _repeated_file_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Describes a complete .proto file.
+ /// </summary>
+ internal sealed partial class FileDescriptorProto : pb::IMessage<FileDescriptorProto> {
+ private static readonly pb::MessageParser<FileDescriptorProto> _parser = new pb::MessageParser<FileDescriptorProto>(() => new FileDescriptorProto());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<FileDescriptorProto> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[1]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FileDescriptorProto() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FileDescriptorProto(FileDescriptorProto other) : this() {
+ name_ = other.name_;
+ package_ = other.package_;
+ dependency_ = other.dependency_.Clone();
+ publicDependency_ = other.publicDependency_.Clone();
+ weakDependency_ = other.weakDependency_.Clone();
+ messageType_ = other.messageType_.Clone();
+ enumType_ = other.enumType_.Clone();
+ service_ = other.service_.Clone();
+ extension_ = other.extension_.Clone();
+ Options = other.options_ != null ? other.Options.Clone() : null;
+ SourceCodeInfo = other.sourceCodeInfo_ != null ? other.SourceCodeInfo.Clone() : null;
+ syntax_ = other.syntax_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FileDescriptorProto Clone() {
+ return new FileDescriptorProto(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ /// <summary>
+ /// file name, relative to root of source tree
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "package" field.</summary>
+ public const int PackageFieldNumber = 2;
+ private string package_ = "";
+ /// <summary>
+ /// e.g. "foo", "foo.bar", etc.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Package {
+ get { return package_; }
+ set {
+ package_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "dependency" field.</summary>
+ public const int DependencyFieldNumber = 3;
+ private static readonly pb::FieldCodec<string> _repeated_dependency_codec
+ = pb::FieldCodec.ForString(26);
+ private readonly pbc::RepeatedField<string> dependency_ = new pbc::RepeatedField<string>();
+ /// <summary>
+ /// Names of files imported by this file.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<string> Dependency {
+ get { return dependency_; }
+ }
+
+ /// <summary>Field number for the "public_dependency" field.</summary>
+ public const int PublicDependencyFieldNumber = 10;
+ private static readonly pb::FieldCodec<int> _repeated_publicDependency_codec
+ = pb::FieldCodec.ForInt32(80);
+ private readonly pbc::RepeatedField<int> publicDependency_ = new pbc::RepeatedField<int>();
+ /// <summary>
+ /// Indexes of the public imported files in the dependency list above.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> PublicDependency {
+ get { return publicDependency_; }
+ }
+
+ /// <summary>Field number for the "weak_dependency" field.</summary>
+ public const int WeakDependencyFieldNumber = 11;
+ private static readonly pb::FieldCodec<int> _repeated_weakDependency_codec
+ = pb::FieldCodec.ForInt32(88);
+ private readonly pbc::RepeatedField<int> weakDependency_ = new pbc::RepeatedField<int>();
+ /// <summary>
+ /// Indexes of the weak imported files in the dependency list.
+ /// For Google-internal migration only. Do not use.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> WeakDependency {
+ get { return weakDependency_; }
+ }
+
+ /// <summary>Field number for the "message_type" field.</summary>
+ public const int MessageTypeFieldNumber = 4;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.DescriptorProto> _repeated_messageType_codec
+ = pb::FieldCodec.ForMessage(34, global::Google.Protobuf.Reflection.DescriptorProto.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.DescriptorProto> messageType_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.DescriptorProto>();
+ /// <summary>
+ /// All top-level definitions in this file.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.DescriptorProto> MessageType {
+ get { return messageType_; }
+ }
+
+ /// <summary>Field number for the "enum_type" field.</summary>
+ public const int EnumTypeFieldNumber = 5;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.EnumDescriptorProto> _repeated_enumType_codec
+ = pb::FieldCodec.ForMessage(42, global::Google.Protobuf.Reflection.EnumDescriptorProto.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.EnumDescriptorProto> enumType_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.EnumDescriptorProto>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.EnumDescriptorProto> EnumType {
+ get { return enumType_; }
+ }
+
+ /// <summary>Field number for the "service" field.</summary>
+ public const int ServiceFieldNumber = 6;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.ServiceDescriptorProto> _repeated_service_codec
+ = pb::FieldCodec.ForMessage(50, global::Google.Protobuf.Reflection.ServiceDescriptorProto.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.ServiceDescriptorProto> service_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.ServiceDescriptorProto>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.ServiceDescriptorProto> Service {
+ get { return service_; }
+ }
+
+ /// <summary>Field number for the "extension" field.</summary>
+ public const int ExtensionFieldNumber = 7;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.FieldDescriptorProto> _repeated_extension_codec
+ = pb::FieldCodec.ForMessage(58, global::Google.Protobuf.Reflection.FieldDescriptorProto.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.FieldDescriptorProto> extension_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.FieldDescriptorProto>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.FieldDescriptorProto> Extension {
+ get { return extension_; }
+ }
+
+ /// <summary>Field number for the "options" field.</summary>
+ public const int OptionsFieldNumber = 8;
+ private global::Google.Protobuf.Reflection.FileOptions options_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.Reflection.FileOptions Options {
+ get { return options_; }
+ set {
+ options_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "source_code_info" field.</summary>
+ public const int SourceCodeInfoFieldNumber = 9;
+ private global::Google.Protobuf.Reflection.SourceCodeInfo sourceCodeInfo_;
+ /// <summary>
+ /// This field contains optional information about the original source code.
+ /// You may safely remove this entire field without harming runtime
+ /// functionality of the descriptors -- the information is needed only by
+ /// development tools.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.Reflection.SourceCodeInfo SourceCodeInfo {
+ get { return sourceCodeInfo_; }
+ set {
+ sourceCodeInfo_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "syntax" field.</summary>
+ public const int SyntaxFieldNumber = 12;
+ private string syntax_ = "";
+ /// <summary>
+ /// The syntax of the proto file.
+ /// The supported values are "proto2" and "proto3".
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Syntax {
+ get { return syntax_; }
+ set {
+ syntax_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as FileDescriptorProto);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(FileDescriptorProto other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ if (Package != other.Package) return false;
+ if(!dependency_.Equals(other.dependency_)) return false;
+ if(!publicDependency_.Equals(other.publicDependency_)) return false;
+ if(!weakDependency_.Equals(other.weakDependency_)) return false;
+ if(!messageType_.Equals(other.messageType_)) return false;
+ if(!enumType_.Equals(other.enumType_)) return false;
+ if(!service_.Equals(other.service_)) return false;
+ if(!extension_.Equals(other.extension_)) return false;
+ if (!object.Equals(Options, other.Options)) return false;
+ if (!object.Equals(SourceCodeInfo, other.SourceCodeInfo)) return false;
+ if (Syntax != other.Syntax) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ if (Package.Length != 0) hash ^= Package.GetHashCode();
+ hash ^= dependency_.GetHashCode();
+ hash ^= publicDependency_.GetHashCode();
+ hash ^= weakDependency_.GetHashCode();
+ hash ^= messageType_.GetHashCode();
+ hash ^= enumType_.GetHashCode();
+ hash ^= service_.GetHashCode();
+ hash ^= extension_.GetHashCode();
+ if (options_ != null) hash ^= Options.GetHashCode();
+ if (sourceCodeInfo_ != null) hash ^= SourceCodeInfo.GetHashCode();
+ if (Syntax.Length != 0) hash ^= Syntax.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ if (Package.Length != 0) {
+ output.WriteRawTag(18);
+ output.WriteString(Package);
+ }
+ dependency_.WriteTo(output, _repeated_dependency_codec);
+ messageType_.WriteTo(output, _repeated_messageType_codec);
+ enumType_.WriteTo(output, _repeated_enumType_codec);
+ service_.WriteTo(output, _repeated_service_codec);
+ extension_.WriteTo(output, _repeated_extension_codec);
+ if (options_ != null) {
+ output.WriteRawTag(66);
+ output.WriteMessage(Options);
+ }
+ if (sourceCodeInfo_ != null) {
+ output.WriteRawTag(74);
+ output.WriteMessage(SourceCodeInfo);
+ }
+ publicDependency_.WriteTo(output, _repeated_publicDependency_codec);
+ weakDependency_.WriteTo(output, _repeated_weakDependency_codec);
+ if (Syntax.Length != 0) {
+ output.WriteRawTag(98);
+ output.WriteString(Syntax);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ if (Package.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Package);
+ }
+ size += dependency_.CalculateSize(_repeated_dependency_codec);
+ size += publicDependency_.CalculateSize(_repeated_publicDependency_codec);
+ size += weakDependency_.CalculateSize(_repeated_weakDependency_codec);
+ size += messageType_.CalculateSize(_repeated_messageType_codec);
+ size += enumType_.CalculateSize(_repeated_enumType_codec);
+ size += service_.CalculateSize(_repeated_service_codec);
+ size += extension_.CalculateSize(_repeated_extension_codec);
+ if (options_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
+ }
+ if (sourceCodeInfo_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(SourceCodeInfo);
+ }
+ if (Syntax.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Syntax);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(FileDescriptorProto other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ if (other.Package.Length != 0) {
+ Package = other.Package;
+ }
+ dependency_.Add(other.dependency_);
+ publicDependency_.Add(other.publicDependency_);
+ weakDependency_.Add(other.weakDependency_);
+ messageType_.Add(other.messageType_);
+ enumType_.Add(other.enumType_);
+ service_.Add(other.service_);
+ extension_.Add(other.extension_);
+ if (other.options_ != null) {
+ if (options_ == null) {
+ options_ = new global::Google.Protobuf.Reflection.FileOptions();
+ }
+ Options.MergeFrom(other.Options);
+ }
+ if (other.sourceCodeInfo_ != null) {
+ if (sourceCodeInfo_ == null) {
+ sourceCodeInfo_ = new global::Google.Protobuf.Reflection.SourceCodeInfo();
+ }
+ SourceCodeInfo.MergeFrom(other.SourceCodeInfo);
+ }
+ if (other.Syntax.Length != 0) {
+ Syntax = other.Syntax;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 18: {
+ Package = input.ReadString();
+ break;
+ }
+ case 26: {
+ dependency_.AddEntriesFrom(input, _repeated_dependency_codec);
+ break;
+ }
+ case 34: {
+ messageType_.AddEntriesFrom(input, _repeated_messageType_codec);
+ break;
+ }
+ case 42: {
+ enumType_.AddEntriesFrom(input, _repeated_enumType_codec);
+ break;
+ }
+ case 50: {
+ service_.AddEntriesFrom(input, _repeated_service_codec);
+ break;
+ }
+ case 58: {
+ extension_.AddEntriesFrom(input, _repeated_extension_codec);
+ break;
+ }
+ case 66: {
+ if (options_ == null) {
+ options_ = new global::Google.Protobuf.Reflection.FileOptions();
+ }
+ input.ReadMessage(options_);
+ break;
+ }
+ case 74: {
+ if (sourceCodeInfo_ == null) {
+ sourceCodeInfo_ = new global::Google.Protobuf.Reflection.SourceCodeInfo();
+ }
+ input.ReadMessage(sourceCodeInfo_);
+ break;
+ }
+ case 82:
+ case 80: {
+ publicDependency_.AddEntriesFrom(input, _repeated_publicDependency_codec);
+ break;
+ }
+ case 90:
+ case 88: {
+ weakDependency_.AddEntriesFrom(input, _repeated_weakDependency_codec);
+ break;
+ }
+ case 98: {
+ Syntax = input.ReadString();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Describes a message type.
+ /// </summary>
+ internal sealed partial class DescriptorProto : pb::IMessage<DescriptorProto> {
+ private static readonly pb::MessageParser<DescriptorProto> _parser = new pb::MessageParser<DescriptorProto>(() => new DescriptorProto());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<DescriptorProto> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[2]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DescriptorProto() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DescriptorProto(DescriptorProto other) : this() {
+ name_ = other.name_;
+ field_ = other.field_.Clone();
+ extension_ = other.extension_.Clone();
+ nestedType_ = other.nestedType_.Clone();
+ enumType_ = other.enumType_.Clone();
+ extensionRange_ = other.extensionRange_.Clone();
+ oneofDecl_ = other.oneofDecl_.Clone();
+ Options = other.options_ != null ? other.Options.Clone() : null;
+ reservedRange_ = other.reservedRange_.Clone();
+ reservedName_ = other.reservedName_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DescriptorProto Clone() {
+ return new DescriptorProto(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "field" field.</summary>
+ public const int FieldFieldNumber = 2;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.FieldDescriptorProto> _repeated_field_codec
+ = pb::FieldCodec.ForMessage(18, global::Google.Protobuf.Reflection.FieldDescriptorProto.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.FieldDescriptorProto> field_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.FieldDescriptorProto>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.FieldDescriptorProto> Field {
+ get { return field_; }
+ }
+
+ /// <summary>Field number for the "extension" field.</summary>
+ public const int ExtensionFieldNumber = 6;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.FieldDescriptorProto> _repeated_extension_codec
+ = pb::FieldCodec.ForMessage(50, global::Google.Protobuf.Reflection.FieldDescriptorProto.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.FieldDescriptorProto> extension_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.FieldDescriptorProto>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.FieldDescriptorProto> Extension {
+ get { return extension_; }
+ }
+
+ /// <summary>Field number for the "nested_type" field.</summary>
+ public const int NestedTypeFieldNumber = 3;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.DescriptorProto> _repeated_nestedType_codec
+ = pb::FieldCodec.ForMessage(26, global::Google.Protobuf.Reflection.DescriptorProto.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.DescriptorProto> nestedType_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.DescriptorProto>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.DescriptorProto> NestedType {
+ get { return nestedType_; }
+ }
+
+ /// <summary>Field number for the "enum_type" field.</summary>
+ public const int EnumTypeFieldNumber = 4;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.EnumDescriptorProto> _repeated_enumType_codec
+ = pb::FieldCodec.ForMessage(34, global::Google.Protobuf.Reflection.EnumDescriptorProto.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.EnumDescriptorProto> enumType_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.EnumDescriptorProto>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.EnumDescriptorProto> EnumType {
+ get { return enumType_; }
+ }
+
+ /// <summary>Field number for the "extension_range" field.</summary>
+ public const int ExtensionRangeFieldNumber = 5;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.DescriptorProto.Types.ExtensionRange> _repeated_extensionRange_codec
+ = pb::FieldCodec.ForMessage(42, global::Google.Protobuf.Reflection.DescriptorProto.Types.ExtensionRange.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.DescriptorProto.Types.ExtensionRange> extensionRange_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.DescriptorProto.Types.ExtensionRange>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.DescriptorProto.Types.ExtensionRange> ExtensionRange {
+ get { return extensionRange_; }
+ }
+
+ /// <summary>Field number for the "oneof_decl" field.</summary>
+ public const int OneofDeclFieldNumber = 8;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.OneofDescriptorProto> _repeated_oneofDecl_codec
+ = pb::FieldCodec.ForMessage(66, global::Google.Protobuf.Reflection.OneofDescriptorProto.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.OneofDescriptorProto> oneofDecl_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.OneofDescriptorProto>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.OneofDescriptorProto> OneofDecl {
+ get { return oneofDecl_; }
+ }
+
+ /// <summary>Field number for the "options" field.</summary>
+ public const int OptionsFieldNumber = 7;
+ private global::Google.Protobuf.Reflection.MessageOptions options_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.Reflection.MessageOptions Options {
+ get { return options_; }
+ set {
+ options_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "reserved_range" field.</summary>
+ public const int ReservedRangeFieldNumber = 9;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.DescriptorProto.Types.ReservedRange> _repeated_reservedRange_codec
+ = pb::FieldCodec.ForMessage(74, global::Google.Protobuf.Reflection.DescriptorProto.Types.ReservedRange.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.DescriptorProto.Types.ReservedRange> reservedRange_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.DescriptorProto.Types.ReservedRange>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.DescriptorProto.Types.ReservedRange> ReservedRange {
+ get { return reservedRange_; }
+ }
+
+ /// <summary>Field number for the "reserved_name" field.</summary>
+ public const int ReservedNameFieldNumber = 10;
+ private static readonly pb::FieldCodec<string> _repeated_reservedName_codec
+ = pb::FieldCodec.ForString(82);
+ private readonly pbc::RepeatedField<string> reservedName_ = new pbc::RepeatedField<string>();
+ /// <summary>
+ /// Reserved field names, which may not be used by fields in the same message.
+ /// A given name may only be reserved once.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<string> ReservedName {
+ get { return reservedName_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as DescriptorProto);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(DescriptorProto other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ if(!field_.Equals(other.field_)) return false;
+ if(!extension_.Equals(other.extension_)) return false;
+ if(!nestedType_.Equals(other.nestedType_)) return false;
+ if(!enumType_.Equals(other.enumType_)) return false;
+ if(!extensionRange_.Equals(other.extensionRange_)) return false;
+ if(!oneofDecl_.Equals(other.oneofDecl_)) return false;
+ if (!object.Equals(Options, other.Options)) return false;
+ if(!reservedRange_.Equals(other.reservedRange_)) return false;
+ if(!reservedName_.Equals(other.reservedName_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ hash ^= field_.GetHashCode();
+ hash ^= extension_.GetHashCode();
+ hash ^= nestedType_.GetHashCode();
+ hash ^= enumType_.GetHashCode();
+ hash ^= extensionRange_.GetHashCode();
+ hash ^= oneofDecl_.GetHashCode();
+ if (options_ != null) hash ^= Options.GetHashCode();
+ hash ^= reservedRange_.GetHashCode();
+ hash ^= reservedName_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ field_.WriteTo(output, _repeated_field_codec);
+ nestedType_.WriteTo(output, _repeated_nestedType_codec);
+ enumType_.WriteTo(output, _repeated_enumType_codec);
+ extensionRange_.WriteTo(output, _repeated_extensionRange_codec);
+ extension_.WriteTo(output, _repeated_extension_codec);
+ if (options_ != null) {
+ output.WriteRawTag(58);
+ output.WriteMessage(Options);
+ }
+ oneofDecl_.WriteTo(output, _repeated_oneofDecl_codec);
+ reservedRange_.WriteTo(output, _repeated_reservedRange_codec);
+ reservedName_.WriteTo(output, _repeated_reservedName_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ size += field_.CalculateSize(_repeated_field_codec);
+ size += extension_.CalculateSize(_repeated_extension_codec);
+ size += nestedType_.CalculateSize(_repeated_nestedType_codec);
+ size += enumType_.CalculateSize(_repeated_enumType_codec);
+ size += extensionRange_.CalculateSize(_repeated_extensionRange_codec);
+ size += oneofDecl_.CalculateSize(_repeated_oneofDecl_codec);
+ if (options_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
+ }
+ size += reservedRange_.CalculateSize(_repeated_reservedRange_codec);
+ size += reservedName_.CalculateSize(_repeated_reservedName_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(DescriptorProto other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ field_.Add(other.field_);
+ extension_.Add(other.extension_);
+ nestedType_.Add(other.nestedType_);
+ enumType_.Add(other.enumType_);
+ extensionRange_.Add(other.extensionRange_);
+ oneofDecl_.Add(other.oneofDecl_);
+ if (other.options_ != null) {
+ if (options_ == null) {
+ options_ = new global::Google.Protobuf.Reflection.MessageOptions();
+ }
+ Options.MergeFrom(other.Options);
+ }
+ reservedRange_.Add(other.reservedRange_);
+ reservedName_.Add(other.reservedName_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 18: {
+ field_.AddEntriesFrom(input, _repeated_field_codec);
+ break;
+ }
+ case 26: {
+ nestedType_.AddEntriesFrom(input, _repeated_nestedType_codec);
+ break;
+ }
+ case 34: {
+ enumType_.AddEntriesFrom(input, _repeated_enumType_codec);
+ break;
+ }
+ case 42: {
+ extensionRange_.AddEntriesFrom(input, _repeated_extensionRange_codec);
+ break;
+ }
+ case 50: {
+ extension_.AddEntriesFrom(input, _repeated_extension_codec);
+ break;
+ }
+ case 58: {
+ if (options_ == null) {
+ options_ = new global::Google.Protobuf.Reflection.MessageOptions();
+ }
+ input.ReadMessage(options_);
+ break;
+ }
+ case 66: {
+ oneofDecl_.AddEntriesFrom(input, _repeated_oneofDecl_codec);
+ break;
+ }
+ case 74: {
+ reservedRange_.AddEntriesFrom(input, _repeated_reservedRange_codec);
+ break;
+ }
+ case 82: {
+ reservedName_.AddEntriesFrom(input, _repeated_reservedName_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the DescriptorProto message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ internal sealed partial class ExtensionRange : pb::IMessage<ExtensionRange> {
+ private static readonly pb::MessageParser<ExtensionRange> _parser = new pb::MessageParser<ExtensionRange>(() => new ExtensionRange());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<ExtensionRange> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorProto.Descriptor.NestedTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ExtensionRange() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ExtensionRange(ExtensionRange other) : this() {
+ start_ = other.start_;
+ end_ = other.end_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ExtensionRange Clone() {
+ return new ExtensionRange(this);
+ }
+
+ /// <summary>Field number for the "start" field.</summary>
+ public const int StartFieldNumber = 1;
+ private int start_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Start {
+ get { return start_; }
+ set {
+ start_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "end" field.</summary>
+ public const int EndFieldNumber = 2;
+ private int end_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int End {
+ get { return end_; }
+ set {
+ end_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as ExtensionRange);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(ExtensionRange other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Start != other.Start) return false;
+ if (End != other.End) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Start != 0) hash ^= Start.GetHashCode();
+ if (End != 0) hash ^= End.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Start != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(Start);
+ }
+ if (End != 0) {
+ output.WriteRawTag(16);
+ output.WriteInt32(End);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Start != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Start);
+ }
+ if (End != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(End);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(ExtensionRange other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Start != 0) {
+ Start = other.Start;
+ }
+ if (other.End != 0) {
+ End = other.End;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Start = input.ReadInt32();
+ break;
+ }
+ case 16: {
+ End = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Range of reserved tag numbers. Reserved tag numbers may not be used by
+ /// fields or extension ranges in the same message. Reserved ranges may
+ /// not overlap.
+ /// </summary>
+ internal sealed partial class ReservedRange : pb::IMessage<ReservedRange> {
+ private static readonly pb::MessageParser<ReservedRange> _parser = new pb::MessageParser<ReservedRange>(() => new ReservedRange());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<ReservedRange> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorProto.Descriptor.NestedTypes[1]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ReservedRange() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ReservedRange(ReservedRange other) : this() {
+ start_ = other.start_;
+ end_ = other.end_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ReservedRange Clone() {
+ return new ReservedRange(this);
+ }
+
+ /// <summary>Field number for the "start" field.</summary>
+ public const int StartFieldNumber = 1;
+ private int start_;
+ /// <summary>
+ /// Inclusive.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Start {
+ get { return start_; }
+ set {
+ start_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "end" field.</summary>
+ public const int EndFieldNumber = 2;
+ private int end_;
+ /// <summary>
+ /// Exclusive.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int End {
+ get { return end_; }
+ set {
+ end_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as ReservedRange);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(ReservedRange other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Start != other.Start) return false;
+ if (End != other.End) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Start != 0) hash ^= Start.GetHashCode();
+ if (End != 0) hash ^= End.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Start != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(Start);
+ }
+ if (End != 0) {
+ output.WriteRawTag(16);
+ output.WriteInt32(End);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Start != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Start);
+ }
+ if (End != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(End);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(ReservedRange other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Start != 0) {
+ Start = other.Start;
+ }
+ if (other.End != 0) {
+ End = other.End;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Start = input.ReadInt32();
+ break;
+ }
+ case 16: {
+ End = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ }
+ #endregion
+
+ }
+
+ /// <summary>
+ /// Describes a field within a message.
+ /// </summary>
+ internal sealed partial class FieldDescriptorProto : pb::IMessage<FieldDescriptorProto> {
+ private static readonly pb::MessageParser<FieldDescriptorProto> _parser = new pb::MessageParser<FieldDescriptorProto>(() => new FieldDescriptorProto());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<FieldDescriptorProto> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[3]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FieldDescriptorProto() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FieldDescriptorProto(FieldDescriptorProto other) : this() {
+ name_ = other.name_;
+ number_ = other.number_;
+ label_ = other.label_;
+ type_ = other.type_;
+ typeName_ = other.typeName_;
+ extendee_ = other.extendee_;
+ defaultValue_ = other.defaultValue_;
+ oneofIndex_ = other.oneofIndex_;
+ jsonName_ = other.jsonName_;
+ Options = other.options_ != null ? other.Options.Clone() : null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FieldDescriptorProto Clone() {
+ return new FieldDescriptorProto(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "number" field.</summary>
+ public const int NumberFieldNumber = 3;
+ private int number_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Number {
+ get { return number_; }
+ set {
+ number_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "label" field.</summary>
+ public const int LabelFieldNumber = 4;
+ private global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label label_ = 0;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label Label {
+ get { return label_; }
+ set {
+ label_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "type" field.</summary>
+ public const int TypeFieldNumber = 5;
+ private global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type type_ = 0;
+ /// <summary>
+ /// If type_name is set, this need not be set. If both this and type_name
+ /// are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type Type {
+ get { return type_; }
+ set {
+ type_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "type_name" field.</summary>
+ public const int TypeNameFieldNumber = 6;
+ private string typeName_ = "";
+ /// <summary>
+ /// For message and enum types, this is the name of the type. If the name
+ /// starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
+ /// rules are used to find the type (i.e. first the nested types within this
+ /// message are searched, then within the parent, on up to the root
+ /// namespace).
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string TypeName {
+ get { return typeName_; }
+ set {
+ typeName_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "extendee" field.</summary>
+ public const int ExtendeeFieldNumber = 2;
+ private string extendee_ = "";
+ /// <summary>
+ /// For extensions, this is the name of the type being extended. It is
+ /// resolved in the same manner as type_name.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Extendee {
+ get { return extendee_; }
+ set {
+ extendee_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "default_value" field.</summary>
+ public const int DefaultValueFieldNumber = 7;
+ private string defaultValue_ = "";
+ /// <summary>
+ /// For numeric types, contains the original text representation of the value.
+ /// For booleans, "true" or "false".
+ /// For strings, contains the default text contents (not escaped in any way).
+ /// For bytes, contains the C escaped value. All bytes >= 128 are escaped.
+ /// TODO(kenton): Base-64 encode?
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string DefaultValue {
+ get { return defaultValue_; }
+ set {
+ defaultValue_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "oneof_index" field.</summary>
+ public const int OneofIndexFieldNumber = 9;
+ private int oneofIndex_;
+ /// <summary>
+ /// If set, gives the index of a oneof in the containing type's oneof_decl
+ /// list. This field is a member of that oneof.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int OneofIndex {
+ get { return oneofIndex_; }
+ set {
+ oneofIndex_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "json_name" field.</summary>
+ public const int JsonNameFieldNumber = 10;
+ private string jsonName_ = "";
+ /// <summary>
+ /// JSON name of this field. The value is set by protocol compiler. If the
+ /// user has set a "json_name" option on this field, that option's value
+ /// will be used. Otherwise, it's deduced from the field's name by converting
+ /// it to camelCase.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string JsonName {
+ get { return jsonName_; }
+ set {
+ jsonName_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "options" field.</summary>
+ public const int OptionsFieldNumber = 8;
+ private global::Google.Protobuf.Reflection.FieldOptions options_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.Reflection.FieldOptions Options {
+ get { return options_; }
+ set {
+ options_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as FieldDescriptorProto);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(FieldDescriptorProto other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ if (Number != other.Number) return false;
+ if (Label != other.Label) return false;
+ if (Type != other.Type) return false;
+ if (TypeName != other.TypeName) return false;
+ if (Extendee != other.Extendee) return false;
+ if (DefaultValue != other.DefaultValue) return false;
+ if (OneofIndex != other.OneofIndex) return false;
+ if (JsonName != other.JsonName) return false;
+ if (!object.Equals(Options, other.Options)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ if (Number != 0) hash ^= Number.GetHashCode();
+ if (Label != 0) hash ^= Label.GetHashCode();
+ if (Type != 0) hash ^= Type.GetHashCode();
+ if (TypeName.Length != 0) hash ^= TypeName.GetHashCode();
+ if (Extendee.Length != 0) hash ^= Extendee.GetHashCode();
+ if (DefaultValue.Length != 0) hash ^= DefaultValue.GetHashCode();
+ if (OneofIndex != 0) hash ^= OneofIndex.GetHashCode();
+ if (JsonName.Length != 0) hash ^= JsonName.GetHashCode();
+ if (options_ != null) hash ^= Options.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ if (Extendee.Length != 0) {
+ output.WriteRawTag(18);
+ output.WriteString(Extendee);
+ }
+ if (Number != 0) {
+ output.WriteRawTag(24);
+ output.WriteInt32(Number);
+ }
+ if (Label != 0) {
+ output.WriteRawTag(32);
+ output.WriteEnum((int) Label);
+ }
+ if (Type != 0) {
+ output.WriteRawTag(40);
+ output.WriteEnum((int) Type);
+ }
+ if (TypeName.Length != 0) {
+ output.WriteRawTag(50);
+ output.WriteString(TypeName);
+ }
+ if (DefaultValue.Length != 0) {
+ output.WriteRawTag(58);
+ output.WriteString(DefaultValue);
+ }
+ if (options_ != null) {
+ output.WriteRawTag(66);
+ output.WriteMessage(Options);
+ }
+ if (OneofIndex != 0) {
+ output.WriteRawTag(72);
+ output.WriteInt32(OneofIndex);
+ }
+ if (JsonName.Length != 0) {
+ output.WriteRawTag(82);
+ output.WriteString(JsonName);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ if (Number != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Number);
+ }
+ if (Label != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Label);
+ }
+ if (Type != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Type);
+ }
+ if (TypeName.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(TypeName);
+ }
+ if (Extendee.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Extendee);
+ }
+ if (DefaultValue.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(DefaultValue);
+ }
+ if (OneofIndex != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(OneofIndex);
+ }
+ if (JsonName.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(JsonName);
+ }
+ if (options_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(FieldDescriptorProto other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ if (other.Number != 0) {
+ Number = other.Number;
+ }
+ if (other.Label != 0) {
+ Label = other.Label;
+ }
+ if (other.Type != 0) {
+ Type = other.Type;
+ }
+ if (other.TypeName.Length != 0) {
+ TypeName = other.TypeName;
+ }
+ if (other.Extendee.Length != 0) {
+ Extendee = other.Extendee;
+ }
+ if (other.DefaultValue.Length != 0) {
+ DefaultValue = other.DefaultValue;
+ }
+ if (other.OneofIndex != 0) {
+ OneofIndex = other.OneofIndex;
+ }
+ if (other.JsonName.Length != 0) {
+ JsonName = other.JsonName;
+ }
+ if (other.options_ != null) {
+ if (options_ == null) {
+ options_ = new global::Google.Protobuf.Reflection.FieldOptions();
+ }
+ Options.MergeFrom(other.Options);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 18: {
+ Extendee = input.ReadString();
+ break;
+ }
+ case 24: {
+ Number = input.ReadInt32();
+ break;
+ }
+ case 32: {
+ label_ = (global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label) input.ReadEnum();
+ break;
+ }
+ case 40: {
+ type_ = (global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type) input.ReadEnum();
+ break;
+ }
+ case 50: {
+ TypeName = input.ReadString();
+ break;
+ }
+ case 58: {
+ DefaultValue = input.ReadString();
+ break;
+ }
+ case 66: {
+ if (options_ == null) {
+ options_ = new global::Google.Protobuf.Reflection.FieldOptions();
+ }
+ input.ReadMessage(options_);
+ break;
+ }
+ case 72: {
+ OneofIndex = input.ReadInt32();
+ break;
+ }
+ case 82: {
+ JsonName = input.ReadString();
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the FieldDescriptorProto message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ internal enum Type {
+ /// <summary>
+ /// 0 is reserved for errors.
+ /// Order is weird for historical reasons.
+ /// </summary>
+ [pbr::OriginalName("TYPE_DOUBLE")] Double = 1,
+ [pbr::OriginalName("TYPE_FLOAT")] Float = 2,
+ /// <summary>
+ /// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
+ /// negative values are likely.
+ /// </summary>
+ [pbr::OriginalName("TYPE_INT64")] Int64 = 3,
+ [pbr::OriginalName("TYPE_UINT64")] Uint64 = 4,
+ /// <summary>
+ /// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
+ /// negative values are likely.
+ /// </summary>
+ [pbr::OriginalName("TYPE_INT32")] Int32 = 5,
+ [pbr::OriginalName("TYPE_FIXED64")] Fixed64 = 6,
+ [pbr::OriginalName("TYPE_FIXED32")] Fixed32 = 7,
+ [pbr::OriginalName("TYPE_BOOL")] Bool = 8,
+ [pbr::OriginalName("TYPE_STRING")] String = 9,
+ /// <summary>
+ /// Tag-delimited aggregate.
+ /// Group type is deprecated and not supported in proto3. However, Proto3
+ /// implementations should still be able to parse the group wire format and
+ /// treat group fields as unknown fields.
+ /// </summary>
+ [pbr::OriginalName("TYPE_GROUP")] Group = 10,
+ /// <summary>
+ /// Length-delimited aggregate.
+ /// </summary>
+ [pbr::OriginalName("TYPE_MESSAGE")] Message = 11,
+ /// <summary>
+ /// New in version 2.
+ /// </summary>
+ [pbr::OriginalName("TYPE_BYTES")] Bytes = 12,
+ [pbr::OriginalName("TYPE_UINT32")] Uint32 = 13,
+ [pbr::OriginalName("TYPE_ENUM")] Enum = 14,
+ [pbr::OriginalName("TYPE_SFIXED32")] Sfixed32 = 15,
+ [pbr::OriginalName("TYPE_SFIXED64")] Sfixed64 = 16,
+ /// <summary>
+ /// Uses ZigZag encoding.
+ /// </summary>
+ [pbr::OriginalName("TYPE_SINT32")] Sint32 = 17,
+ /// <summary>
+ /// Uses ZigZag encoding.
+ /// </summary>
+ [pbr::OriginalName("TYPE_SINT64")] Sint64 = 18,
+ }
+
+ internal enum Label {
+ /// <summary>
+ /// 0 is reserved for errors
+ /// </summary>
+ [pbr::OriginalName("LABEL_OPTIONAL")] Optional = 1,
+ [pbr::OriginalName("LABEL_REQUIRED")] Required = 2,
+ [pbr::OriginalName("LABEL_REPEATED")] Repeated = 3,
+ }
+
+ }
+ #endregion
+
+ }
+
+ /// <summary>
+ /// Describes a oneof.
+ /// </summary>
+ internal sealed partial class OneofDescriptorProto : pb::IMessage<OneofDescriptorProto> {
+ private static readonly pb::MessageParser<OneofDescriptorProto> _parser = new pb::MessageParser<OneofDescriptorProto>(() => new OneofDescriptorProto());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<OneofDescriptorProto> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[4]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneofDescriptorProto() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneofDescriptorProto(OneofDescriptorProto other) : this() {
+ name_ = other.name_;
+ Options = other.options_ != null ? other.Options.Clone() : null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneofDescriptorProto Clone() {
+ return new OneofDescriptorProto(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "options" field.</summary>
+ public const int OptionsFieldNumber = 2;
+ private global::Google.Protobuf.Reflection.OneofOptions options_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.Reflection.OneofOptions Options {
+ get { return options_; }
+ set {
+ options_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as OneofDescriptorProto);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(OneofDescriptorProto other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ if (!object.Equals(Options, other.Options)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ if (options_ != null) hash ^= Options.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ if (options_ != null) {
+ output.WriteRawTag(18);
+ output.WriteMessage(Options);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ if (options_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(OneofDescriptorProto other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ if (other.options_ != null) {
+ if (options_ == null) {
+ options_ = new global::Google.Protobuf.Reflection.OneofOptions();
+ }
+ Options.MergeFrom(other.Options);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 18: {
+ if (options_ == null) {
+ options_ = new global::Google.Protobuf.Reflection.OneofOptions();
+ }
+ input.ReadMessage(options_);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Describes an enum type.
+ /// </summary>
+ internal sealed partial class EnumDescriptorProto : pb::IMessage<EnumDescriptorProto> {
+ private static readonly pb::MessageParser<EnumDescriptorProto> _parser = new pb::MessageParser<EnumDescriptorProto>(() => new EnumDescriptorProto());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<EnumDescriptorProto> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[5]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public EnumDescriptorProto() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public EnumDescriptorProto(EnumDescriptorProto other) : this() {
+ name_ = other.name_;
+ value_ = other.value_.Clone();
+ Options = other.options_ != null ? other.Options.Clone() : null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public EnumDescriptorProto Clone() {
+ return new EnumDescriptorProto(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "value" field.</summary>
+ public const int ValueFieldNumber = 2;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.EnumValueDescriptorProto> _repeated_value_codec
+ = pb::FieldCodec.ForMessage(18, global::Google.Protobuf.Reflection.EnumValueDescriptorProto.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.EnumValueDescriptorProto> value_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.EnumValueDescriptorProto>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.EnumValueDescriptorProto> Value {
+ get { return value_; }
+ }
+
+ /// <summary>Field number for the "options" field.</summary>
+ public const int OptionsFieldNumber = 3;
+ private global::Google.Protobuf.Reflection.EnumOptions options_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.Reflection.EnumOptions Options {
+ get { return options_; }
+ set {
+ options_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as EnumDescriptorProto);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(EnumDescriptorProto other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ if(!value_.Equals(other.value_)) return false;
+ if (!object.Equals(Options, other.Options)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ hash ^= value_.GetHashCode();
+ if (options_ != null) hash ^= Options.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ value_.WriteTo(output, _repeated_value_codec);
+ if (options_ != null) {
+ output.WriteRawTag(26);
+ output.WriteMessage(Options);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ size += value_.CalculateSize(_repeated_value_codec);
+ if (options_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(EnumDescriptorProto other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ value_.Add(other.value_);
+ if (other.options_ != null) {
+ if (options_ == null) {
+ options_ = new global::Google.Protobuf.Reflection.EnumOptions();
+ }
+ Options.MergeFrom(other.Options);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 18: {
+ value_.AddEntriesFrom(input, _repeated_value_codec);
+ break;
+ }
+ case 26: {
+ if (options_ == null) {
+ options_ = new global::Google.Protobuf.Reflection.EnumOptions();
+ }
+ input.ReadMessage(options_);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Describes a value within an enum.
+ /// </summary>
+ internal sealed partial class EnumValueDescriptorProto : pb::IMessage<EnumValueDescriptorProto> {
+ private static readonly pb::MessageParser<EnumValueDescriptorProto> _parser = new pb::MessageParser<EnumValueDescriptorProto>(() => new EnumValueDescriptorProto());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<EnumValueDescriptorProto> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[6]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public EnumValueDescriptorProto() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public EnumValueDescriptorProto(EnumValueDescriptorProto other) : this() {
+ name_ = other.name_;
+ number_ = other.number_;
+ Options = other.options_ != null ? other.Options.Clone() : null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public EnumValueDescriptorProto Clone() {
+ return new EnumValueDescriptorProto(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "number" field.</summary>
+ public const int NumberFieldNumber = 2;
+ private int number_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Number {
+ get { return number_; }
+ set {
+ number_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "options" field.</summary>
+ public const int OptionsFieldNumber = 3;
+ private global::Google.Protobuf.Reflection.EnumValueOptions options_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.Reflection.EnumValueOptions Options {
+ get { return options_; }
+ set {
+ options_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as EnumValueDescriptorProto);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(EnumValueDescriptorProto other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ if (Number != other.Number) return false;
+ if (!object.Equals(Options, other.Options)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ if (Number != 0) hash ^= Number.GetHashCode();
+ if (options_ != null) hash ^= Options.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ if (Number != 0) {
+ output.WriteRawTag(16);
+ output.WriteInt32(Number);
+ }
+ if (options_ != null) {
+ output.WriteRawTag(26);
+ output.WriteMessage(Options);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ if (Number != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Number);
+ }
+ if (options_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(EnumValueDescriptorProto other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ if (other.Number != 0) {
+ Number = other.Number;
+ }
+ if (other.options_ != null) {
+ if (options_ == null) {
+ options_ = new global::Google.Protobuf.Reflection.EnumValueOptions();
+ }
+ Options.MergeFrom(other.Options);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 16: {
+ Number = input.ReadInt32();
+ break;
+ }
+ case 26: {
+ if (options_ == null) {
+ options_ = new global::Google.Protobuf.Reflection.EnumValueOptions();
+ }
+ input.ReadMessage(options_);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Describes a service.
+ /// </summary>
+ internal sealed partial class ServiceDescriptorProto : pb::IMessage<ServiceDescriptorProto> {
+ private static readonly pb::MessageParser<ServiceDescriptorProto> _parser = new pb::MessageParser<ServiceDescriptorProto>(() => new ServiceDescriptorProto());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<ServiceDescriptorProto> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[7]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ServiceDescriptorProto() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ServiceDescriptorProto(ServiceDescriptorProto other) : this() {
+ name_ = other.name_;
+ method_ = other.method_.Clone();
+ Options = other.options_ != null ? other.Options.Clone() : null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ServiceDescriptorProto Clone() {
+ return new ServiceDescriptorProto(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "method" field.</summary>
+ public const int MethodFieldNumber = 2;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.MethodDescriptorProto> _repeated_method_codec
+ = pb::FieldCodec.ForMessage(18, global::Google.Protobuf.Reflection.MethodDescriptorProto.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.MethodDescriptorProto> method_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.MethodDescriptorProto>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.MethodDescriptorProto> Method {
+ get { return method_; }
+ }
+
+ /// <summary>Field number for the "options" field.</summary>
+ public const int OptionsFieldNumber = 3;
+ private global::Google.Protobuf.Reflection.ServiceOptions options_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.Reflection.ServiceOptions Options {
+ get { return options_; }
+ set {
+ options_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as ServiceDescriptorProto);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(ServiceDescriptorProto other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ if(!method_.Equals(other.method_)) return false;
+ if (!object.Equals(Options, other.Options)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ hash ^= method_.GetHashCode();
+ if (options_ != null) hash ^= Options.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ method_.WriteTo(output, _repeated_method_codec);
+ if (options_ != null) {
+ output.WriteRawTag(26);
+ output.WriteMessage(Options);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ size += method_.CalculateSize(_repeated_method_codec);
+ if (options_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(ServiceDescriptorProto other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ method_.Add(other.method_);
+ if (other.options_ != null) {
+ if (options_ == null) {
+ options_ = new global::Google.Protobuf.Reflection.ServiceOptions();
+ }
+ Options.MergeFrom(other.Options);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 18: {
+ method_.AddEntriesFrom(input, _repeated_method_codec);
+ break;
+ }
+ case 26: {
+ if (options_ == null) {
+ options_ = new global::Google.Protobuf.Reflection.ServiceOptions();
+ }
+ input.ReadMessage(options_);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Describes a method of a service.
+ /// </summary>
+ internal sealed partial class MethodDescriptorProto : pb::IMessage<MethodDescriptorProto> {
+ private static readonly pb::MessageParser<MethodDescriptorProto> _parser = new pb::MessageParser<MethodDescriptorProto>(() => new MethodDescriptorProto());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<MethodDescriptorProto> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[8]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MethodDescriptorProto() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MethodDescriptorProto(MethodDescriptorProto other) : this() {
+ name_ = other.name_;
+ inputType_ = other.inputType_;
+ outputType_ = other.outputType_;
+ Options = other.options_ != null ? other.Options.Clone() : null;
+ clientStreaming_ = other.clientStreaming_;
+ serverStreaming_ = other.serverStreaming_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MethodDescriptorProto Clone() {
+ return new MethodDescriptorProto(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "input_type" field.</summary>
+ public const int InputTypeFieldNumber = 2;
+ private string inputType_ = "";
+ /// <summary>
+ /// Input and output type names. These are resolved in the same way as
+ /// FieldDescriptorProto.type_name, but must refer to a message type.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string InputType {
+ get { return inputType_; }
+ set {
+ inputType_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "output_type" field.</summary>
+ public const int OutputTypeFieldNumber = 3;
+ private string outputType_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string OutputType {
+ get { return outputType_; }
+ set {
+ outputType_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "options" field.</summary>
+ public const int OptionsFieldNumber = 4;
+ private global::Google.Protobuf.Reflection.MethodOptions options_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.Reflection.MethodOptions Options {
+ get { return options_; }
+ set {
+ options_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "client_streaming" field.</summary>
+ public const int ClientStreamingFieldNumber = 5;
+ private bool clientStreaming_;
+ /// <summary>
+ /// Identifies if client streams multiple client messages
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool ClientStreaming {
+ get { return clientStreaming_; }
+ set {
+ clientStreaming_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "server_streaming" field.</summary>
+ public const int ServerStreamingFieldNumber = 6;
+ private bool serverStreaming_;
+ /// <summary>
+ /// Identifies if server streams multiple server messages
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool ServerStreaming {
+ get { return serverStreaming_; }
+ set {
+ serverStreaming_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as MethodDescriptorProto);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(MethodDescriptorProto other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ if (InputType != other.InputType) return false;
+ if (OutputType != other.OutputType) return false;
+ if (!object.Equals(Options, other.Options)) return false;
+ if (ClientStreaming != other.ClientStreaming) return false;
+ if (ServerStreaming != other.ServerStreaming) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ if (InputType.Length != 0) hash ^= InputType.GetHashCode();
+ if (OutputType.Length != 0) hash ^= OutputType.GetHashCode();
+ if (options_ != null) hash ^= Options.GetHashCode();
+ if (ClientStreaming != false) hash ^= ClientStreaming.GetHashCode();
+ if (ServerStreaming != false) hash ^= ServerStreaming.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ if (InputType.Length != 0) {
+ output.WriteRawTag(18);
+ output.WriteString(InputType);
+ }
+ if (OutputType.Length != 0) {
+ output.WriteRawTag(26);
+ output.WriteString(OutputType);
+ }
+ if (options_ != null) {
+ output.WriteRawTag(34);
+ output.WriteMessage(Options);
+ }
+ if (ClientStreaming != false) {
+ output.WriteRawTag(40);
+ output.WriteBool(ClientStreaming);
+ }
+ if (ServerStreaming != false) {
+ output.WriteRawTag(48);
+ output.WriteBool(ServerStreaming);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ if (InputType.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(InputType);
+ }
+ if (OutputType.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(OutputType);
+ }
+ if (options_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
+ }
+ if (ClientStreaming != false) {
+ size += 1 + 1;
+ }
+ if (ServerStreaming != false) {
+ size += 1 + 1;
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(MethodDescriptorProto other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ if (other.InputType.Length != 0) {
+ InputType = other.InputType;
+ }
+ if (other.OutputType.Length != 0) {
+ OutputType = other.OutputType;
+ }
+ if (other.options_ != null) {
+ if (options_ == null) {
+ options_ = new global::Google.Protobuf.Reflection.MethodOptions();
+ }
+ Options.MergeFrom(other.Options);
+ }
+ if (other.ClientStreaming != false) {
+ ClientStreaming = other.ClientStreaming;
+ }
+ if (other.ServerStreaming != false) {
+ ServerStreaming = other.ServerStreaming;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 18: {
+ InputType = input.ReadString();
+ break;
+ }
+ case 26: {
+ OutputType = input.ReadString();
+ break;
+ }
+ case 34: {
+ if (options_ == null) {
+ options_ = new global::Google.Protobuf.Reflection.MethodOptions();
+ }
+ input.ReadMessage(options_);
+ break;
+ }
+ case 40: {
+ ClientStreaming = input.ReadBool();
+ break;
+ }
+ case 48: {
+ ServerStreaming = input.ReadBool();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ internal sealed partial class FileOptions : pb::IMessage<FileOptions> {
+ private static readonly pb::MessageParser<FileOptions> _parser = new pb::MessageParser<FileOptions>(() => new FileOptions());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<FileOptions> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[9]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ internal CustomOptions CustomOptions{ get; private set; } = CustomOptions.Empty;
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FileOptions() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FileOptions(FileOptions other) : this() {
+ javaPackage_ = other.javaPackage_;
+ javaOuterClassname_ = other.javaOuterClassname_;
+ javaMultipleFiles_ = other.javaMultipleFiles_;
+ javaGenerateEqualsAndHash_ = other.javaGenerateEqualsAndHash_;
+ javaStringCheckUtf8_ = other.javaStringCheckUtf8_;
+ optimizeFor_ = other.optimizeFor_;
+ goPackage_ = other.goPackage_;
+ ccGenericServices_ = other.ccGenericServices_;
+ javaGenericServices_ = other.javaGenericServices_;
+ pyGenericServices_ = other.pyGenericServices_;
+ deprecated_ = other.deprecated_;
+ ccEnableArenas_ = other.ccEnableArenas_;
+ objcClassPrefix_ = other.objcClassPrefix_;
+ csharpNamespace_ = other.csharpNamespace_;
+ swiftPrefix_ = other.swiftPrefix_;
+ phpClassPrefix_ = other.phpClassPrefix_;
+ uninterpretedOption_ = other.uninterpretedOption_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FileOptions Clone() {
+ return new FileOptions(this);
+ }
+
+ /// <summary>Field number for the "java_package" field.</summary>
+ public const int JavaPackageFieldNumber = 1;
+ private string javaPackage_ = "";
+ /// <summary>
+ /// Sets the Java package where classes generated from this .proto will be
+ /// placed. By default, the proto package is used, but this is often
+ /// inappropriate because proto packages do not normally start with backwards
+ /// domain names.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string JavaPackage {
+ get { return javaPackage_; }
+ set {
+ javaPackage_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "java_outer_classname" field.</summary>
+ public const int JavaOuterClassnameFieldNumber = 8;
+ private string javaOuterClassname_ = "";
+ /// <summary>
+ /// If set, all the classes from the .proto file are wrapped in a single
+ /// outer class with the given name. This applies to both Proto1
+ /// (equivalent to the old "--one_java_file" option) and Proto2 (where
+ /// a .proto always translates to a single class, but you may want to
+ /// explicitly choose the class name).
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string JavaOuterClassname {
+ get { return javaOuterClassname_; }
+ set {
+ javaOuterClassname_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "java_multiple_files" field.</summary>
+ public const int JavaMultipleFilesFieldNumber = 10;
+ private bool javaMultipleFiles_;
+ /// <summary>
+ /// If set true, then the Java code generator will generate a separate .java
+ /// file for each top-level message, enum, and service defined in the .proto
+ /// file. Thus, these types will *not* be nested inside the outer class
+ /// named by java_outer_classname. However, the outer class will still be
+ /// generated to contain the file's getDescriptor() method as well as any
+ /// top-level extensions defined in the file.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool JavaMultipleFiles {
+ get { return javaMultipleFiles_; }
+ set {
+ javaMultipleFiles_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "java_generate_equals_and_hash" field.</summary>
+ public const int JavaGenerateEqualsAndHashFieldNumber = 20;
+ private bool javaGenerateEqualsAndHash_;
+ /// <summary>
+ /// This option does nothing.
+ /// </summary>
+ [global::System.ObsoleteAttribute]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool JavaGenerateEqualsAndHash {
+ get { return javaGenerateEqualsAndHash_; }
+ set {
+ javaGenerateEqualsAndHash_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "java_string_check_utf8" field.</summary>
+ public const int JavaStringCheckUtf8FieldNumber = 27;
+ private bool javaStringCheckUtf8_;
+ /// <summary>
+ /// 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
+ /// byte sequence to a string field.
+ /// Message reflection will do the same.
+ /// However, an extension field still accepts non-UTF-8 byte sequences.
+ /// This option has no effect on when used with the lite runtime.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool JavaStringCheckUtf8 {
+ get { return javaStringCheckUtf8_; }
+ set {
+ javaStringCheckUtf8_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "optimize_for" field.</summary>
+ public const int OptimizeForFieldNumber = 9;
+ private global::Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode optimizeFor_ = 0;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode OptimizeFor {
+ get { return optimizeFor_; }
+ set {
+ optimizeFor_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "go_package" field.</summary>
+ public const int GoPackageFieldNumber = 11;
+ private string goPackage_ = "";
+ /// <summary>
+ /// Sets the Go package where structs generated from this .proto will be
+ /// placed. If omitted, the Go package will be derived from the following:
+ /// - The basename of the package import path, if provided.
+ /// - Otherwise, the package statement in the .proto file, if present.
+ /// - Otherwise, the basename of the .proto file, without extension.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string GoPackage {
+ get { return goPackage_; }
+ set {
+ goPackage_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "cc_generic_services" field.</summary>
+ public const int CcGenericServicesFieldNumber = 16;
+ private bool ccGenericServices_;
+ /// <summary>
+ /// Should generic services be generated in each language? "Generic" services
+ /// are not specific to any particular RPC system. They are generated by the
+ /// main code generators in each language (without additional plugins).
+ /// Generic services were the only kind of service generation supported by
+ /// early versions of google.protobuf.
+ ///
+ /// Generic services are now considered deprecated in favor of using plugins
+ /// that generate code specific to your particular RPC system. Therefore,
+ /// these default to false. Old code which depends on generic services should
+ /// explicitly set them to true.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool CcGenericServices {
+ get { return ccGenericServices_; }
+ set {
+ ccGenericServices_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "java_generic_services" field.</summary>
+ public const int JavaGenericServicesFieldNumber = 17;
+ private bool javaGenericServices_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool JavaGenericServices {
+ get { return javaGenericServices_; }
+ set {
+ javaGenericServices_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "py_generic_services" field.</summary>
+ public const int PyGenericServicesFieldNumber = 18;
+ private bool pyGenericServices_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool PyGenericServices {
+ get { return pyGenericServices_; }
+ set {
+ pyGenericServices_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "deprecated" field.</summary>
+ public const int DeprecatedFieldNumber = 23;
+ private bool deprecated_;
+ /// <summary>
+ /// Is this file deprecated?
+ /// Depending on the target platform, this can emit Deprecated annotations
+ /// for everything in the file, or it will be completely ignored; in the very
+ /// least, this is a formalization for deprecating files.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Deprecated {
+ get { return deprecated_; }
+ set {
+ deprecated_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "cc_enable_arenas" field.</summary>
+ public const int CcEnableArenasFieldNumber = 31;
+ private bool ccEnableArenas_;
+ /// <summary>
+ /// Enables the use of arenas for the proto messages in this file. This applies
+ /// only to generated classes for C++.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool CcEnableArenas {
+ get { return ccEnableArenas_; }
+ set {
+ ccEnableArenas_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "objc_class_prefix" field.</summary>
+ public const int ObjcClassPrefixFieldNumber = 36;
+ private string objcClassPrefix_ = "";
+ /// <summary>
+ /// Sets the objective c class prefix which is prepended to all objective c
+ /// generated classes from this .proto. There is no default.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string ObjcClassPrefix {
+ get { return objcClassPrefix_; }
+ set {
+ objcClassPrefix_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "csharp_namespace" field.</summary>
+ public const int CsharpNamespaceFieldNumber = 37;
+ private string csharpNamespace_ = "";
+ /// <summary>
+ /// Namespace for generated classes; defaults to the package.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string CsharpNamespace {
+ get { return csharpNamespace_; }
+ set {
+ csharpNamespace_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "swift_prefix" field.</summary>
+ public const int SwiftPrefixFieldNumber = 39;
+ private string swiftPrefix_ = "";
+ /// <summary>
+ /// By default Swift generators will take the proto package and CamelCase it
+ /// replacing '.' with underscore and use that to prefix the types/symbols
+ /// defined. When this options is provided, they will use this value instead
+ /// to prefix the types/symbols defined.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string SwiftPrefix {
+ get { return swiftPrefix_; }
+ set {
+ swiftPrefix_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "php_class_prefix" field.</summary>
+ public const int PhpClassPrefixFieldNumber = 40;
+ private string phpClassPrefix_ = "";
+ /// <summary>
+ /// Sets the php class prefix which is prepended to all php generated classes
+ /// from this .proto. Default is empty.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string PhpClassPrefix {
+ get { return phpClassPrefix_; }
+ set {
+ phpClassPrefix_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "uninterpreted_option" field.</summary>
+ public const int UninterpretedOptionFieldNumber = 999;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.UninterpretedOption> _repeated_uninterpretedOption_codec
+ = pb::FieldCodec.ForMessage(7994, global::Google.Protobuf.Reflection.UninterpretedOption.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> uninterpretedOption_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption>();
+ /// <summary>
+ /// The parser stores options it doesn't recognize here. See above.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> UninterpretedOption {
+ get { return uninterpretedOption_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as FileOptions);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(FileOptions other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (JavaPackage != other.JavaPackage) return false;
+ if (JavaOuterClassname != other.JavaOuterClassname) return false;
+ if (JavaMultipleFiles != other.JavaMultipleFiles) return false;
+ if (JavaGenerateEqualsAndHash != other.JavaGenerateEqualsAndHash) return false;
+ if (JavaStringCheckUtf8 != other.JavaStringCheckUtf8) return false;
+ if (OptimizeFor != other.OptimizeFor) return false;
+ if (GoPackage != other.GoPackage) return false;
+ if (CcGenericServices != other.CcGenericServices) return false;
+ if (JavaGenericServices != other.JavaGenericServices) return false;
+ if (PyGenericServices != other.PyGenericServices) return false;
+ if (Deprecated != other.Deprecated) return false;
+ if (CcEnableArenas != other.CcEnableArenas) return false;
+ if (ObjcClassPrefix != other.ObjcClassPrefix) return false;
+ if (CsharpNamespace != other.CsharpNamespace) return false;
+ if (SwiftPrefix != other.SwiftPrefix) return false;
+ if (PhpClassPrefix != other.PhpClassPrefix) return false;
+ if(!uninterpretedOption_.Equals(other.uninterpretedOption_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (JavaPackage.Length != 0) hash ^= JavaPackage.GetHashCode();
+ if (JavaOuterClassname.Length != 0) hash ^= JavaOuterClassname.GetHashCode();
+ if (JavaMultipleFiles != false) hash ^= JavaMultipleFiles.GetHashCode();
+ if (JavaGenerateEqualsAndHash != false) hash ^= JavaGenerateEqualsAndHash.GetHashCode();
+ if (JavaStringCheckUtf8 != false) hash ^= JavaStringCheckUtf8.GetHashCode();
+ if (OptimizeFor != 0) hash ^= OptimizeFor.GetHashCode();
+ if (GoPackage.Length != 0) hash ^= GoPackage.GetHashCode();
+ if (CcGenericServices != false) hash ^= CcGenericServices.GetHashCode();
+ if (JavaGenericServices != false) hash ^= JavaGenericServices.GetHashCode();
+ if (PyGenericServices != false) hash ^= PyGenericServices.GetHashCode();
+ if (Deprecated != false) hash ^= Deprecated.GetHashCode();
+ if (CcEnableArenas != false) hash ^= CcEnableArenas.GetHashCode();
+ if (ObjcClassPrefix.Length != 0) hash ^= ObjcClassPrefix.GetHashCode();
+ if (CsharpNamespace.Length != 0) hash ^= CsharpNamespace.GetHashCode();
+ if (SwiftPrefix.Length != 0) hash ^= SwiftPrefix.GetHashCode();
+ if (PhpClassPrefix.Length != 0) hash ^= PhpClassPrefix.GetHashCode();
+ hash ^= uninterpretedOption_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (JavaPackage.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(JavaPackage);
+ }
+ if (JavaOuterClassname.Length != 0) {
+ output.WriteRawTag(66);
+ output.WriteString(JavaOuterClassname);
+ }
+ if (OptimizeFor != 0) {
+ output.WriteRawTag(72);
+ output.WriteEnum((int) OptimizeFor);
+ }
+ if (JavaMultipleFiles != false) {
+ output.WriteRawTag(80);
+ output.WriteBool(JavaMultipleFiles);
+ }
+ if (GoPackage.Length != 0) {
+ output.WriteRawTag(90);
+ output.WriteString(GoPackage);
+ }
+ if (CcGenericServices != false) {
+ output.WriteRawTag(128, 1);
+ output.WriteBool(CcGenericServices);
+ }
+ if (JavaGenericServices != false) {
+ output.WriteRawTag(136, 1);
+ output.WriteBool(JavaGenericServices);
+ }
+ if (PyGenericServices != false) {
+ output.WriteRawTag(144, 1);
+ output.WriteBool(PyGenericServices);
+ }
+ if (JavaGenerateEqualsAndHash != false) {
+ output.WriteRawTag(160, 1);
+ output.WriteBool(JavaGenerateEqualsAndHash);
+ }
+ if (Deprecated != false) {
+ output.WriteRawTag(184, 1);
+ output.WriteBool(Deprecated);
+ }
+ if (JavaStringCheckUtf8 != false) {
+ output.WriteRawTag(216, 1);
+ output.WriteBool(JavaStringCheckUtf8);
+ }
+ if (CcEnableArenas != false) {
+ output.WriteRawTag(248, 1);
+ output.WriteBool(CcEnableArenas);
+ }
+ if (ObjcClassPrefix.Length != 0) {
+ output.WriteRawTag(162, 2);
+ output.WriteString(ObjcClassPrefix);
+ }
+ if (CsharpNamespace.Length != 0) {
+ output.WriteRawTag(170, 2);
+ output.WriteString(CsharpNamespace);
+ }
+ if (SwiftPrefix.Length != 0) {
+ output.WriteRawTag(186, 2);
+ output.WriteString(SwiftPrefix);
+ }
+ if (PhpClassPrefix.Length != 0) {
+ output.WriteRawTag(194, 2);
+ output.WriteString(PhpClassPrefix);
+ }
+ uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (JavaPackage.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(JavaPackage);
+ }
+ if (JavaOuterClassname.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(JavaOuterClassname);
+ }
+ if (JavaMultipleFiles != false) {
+ size += 1 + 1;
+ }
+ if (JavaGenerateEqualsAndHash != false) {
+ size += 2 + 1;
+ }
+ if (JavaStringCheckUtf8 != false) {
+ size += 2 + 1;
+ }
+ if (OptimizeFor != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) OptimizeFor);
+ }
+ if (GoPackage.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(GoPackage);
+ }
+ if (CcGenericServices != false) {
+ size += 2 + 1;
+ }
+ if (JavaGenericServices != false) {
+ size += 2 + 1;
+ }
+ if (PyGenericServices != false) {
+ size += 2 + 1;
+ }
+ if (Deprecated != false) {
+ size += 2 + 1;
+ }
+ if (CcEnableArenas != false) {
+ size += 2 + 1;
+ }
+ if (ObjcClassPrefix.Length != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeStringSize(ObjcClassPrefix);
+ }
+ if (CsharpNamespace.Length != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeStringSize(CsharpNamespace);
+ }
+ if (SwiftPrefix.Length != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeStringSize(SwiftPrefix);
+ }
+ if (PhpClassPrefix.Length != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeStringSize(PhpClassPrefix);
+ }
+ size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(FileOptions other) {
+ if (other == null) {
+ return;
+ }
+ if (other.JavaPackage.Length != 0) {
+ JavaPackage = other.JavaPackage;
+ }
+ if (other.JavaOuterClassname.Length != 0) {
+ JavaOuterClassname = other.JavaOuterClassname;
+ }
+ if (other.JavaMultipleFiles != false) {
+ JavaMultipleFiles = other.JavaMultipleFiles;
+ }
+ if (other.JavaGenerateEqualsAndHash != false) {
+ JavaGenerateEqualsAndHash = other.JavaGenerateEqualsAndHash;
+ }
+ if (other.JavaStringCheckUtf8 != false) {
+ JavaStringCheckUtf8 = other.JavaStringCheckUtf8;
+ }
+ if (other.OptimizeFor != 0) {
+ OptimizeFor = other.OptimizeFor;
+ }
+ if (other.GoPackage.Length != 0) {
+ GoPackage = other.GoPackage;
+ }
+ if (other.CcGenericServices != false) {
+ CcGenericServices = other.CcGenericServices;
+ }
+ if (other.JavaGenericServices != false) {
+ JavaGenericServices = other.JavaGenericServices;
+ }
+ if (other.PyGenericServices != false) {
+ PyGenericServices = other.PyGenericServices;
+ }
+ if (other.Deprecated != false) {
+ Deprecated = other.Deprecated;
+ }
+ if (other.CcEnableArenas != false) {
+ CcEnableArenas = other.CcEnableArenas;
+ }
+ if (other.ObjcClassPrefix.Length != 0) {
+ ObjcClassPrefix = other.ObjcClassPrefix;
+ }
+ if (other.CsharpNamespace.Length != 0) {
+ CsharpNamespace = other.CsharpNamespace;
+ }
+ if (other.SwiftPrefix.Length != 0) {
+ SwiftPrefix = other.SwiftPrefix;
+ }
+ if (other.PhpClassPrefix.Length != 0) {
+ PhpClassPrefix = other.PhpClassPrefix;
+ }
+ uninterpretedOption_.Add(other.uninterpretedOption_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);
+ break;
+ case 10: {
+ JavaPackage = input.ReadString();
+ break;
+ }
+ case 66: {
+ JavaOuterClassname = input.ReadString();
+ break;
+ }
+ case 72: {
+ optimizeFor_ = (global::Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode) input.ReadEnum();
+ break;
+ }
+ case 80: {
+ JavaMultipleFiles = input.ReadBool();
+ break;
+ }
+ case 90: {
+ GoPackage = input.ReadString();
+ break;
+ }
+ case 128: {
+ CcGenericServices = input.ReadBool();
+ break;
+ }
+ case 136: {
+ JavaGenericServices = input.ReadBool();
+ break;
+ }
+ case 144: {
+ PyGenericServices = input.ReadBool();
+ break;
+ }
+ case 160: {
+ JavaGenerateEqualsAndHash = input.ReadBool();
+ break;
+ }
+ case 184: {
+ Deprecated = input.ReadBool();
+ break;
+ }
+ case 216: {
+ JavaStringCheckUtf8 = input.ReadBool();
+ break;
+ }
+ case 248: {
+ CcEnableArenas = input.ReadBool();
+ break;
+ }
+ case 290: {
+ ObjcClassPrefix = input.ReadString();
+ break;
+ }
+ case 298: {
+ CsharpNamespace = input.ReadString();
+ break;
+ }
+ case 314: {
+ SwiftPrefix = input.ReadString();
+ break;
+ }
+ case 322: {
+ PhpClassPrefix = input.ReadString();
+ break;
+ }
+ case 7994: {
+ uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the FileOptions message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ /// <summary>
+ /// Generated classes can be optimized for speed or code size.
+ /// </summary>
+ internal enum OptimizeMode {
+ /// <summary>
+ /// Generate complete code for parsing, serialization,
+ /// </summary>
+ [pbr::OriginalName("SPEED")] Speed = 1,
+ /// <summary>
+ /// etc.
+ /// </summary>
+ [pbr::OriginalName("CODE_SIZE")] CodeSize = 2,
+ /// <summary>
+ /// Generate code using MessageLite and the lite runtime.
+ /// </summary>
+ [pbr::OriginalName("LITE_RUNTIME")] LiteRuntime = 3,
+ }
+
+ }
+ #endregion
+
+ }
+
+ internal sealed partial class MessageOptions : pb::IMessage<MessageOptions> {
+ private static readonly pb::MessageParser<MessageOptions> _parser = new pb::MessageParser<MessageOptions>(() => new MessageOptions());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<MessageOptions> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[10]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ internal CustomOptions CustomOptions{ get; private set; } = CustomOptions.Empty;
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MessageOptions() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MessageOptions(MessageOptions other) : this() {
+ messageSetWireFormat_ = other.messageSetWireFormat_;
+ noStandardDescriptorAccessor_ = other.noStandardDescriptorAccessor_;
+ deprecated_ = other.deprecated_;
+ mapEntry_ = other.mapEntry_;
+ uninterpretedOption_ = other.uninterpretedOption_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MessageOptions Clone() {
+ return new MessageOptions(this);
+ }
+
+ /// <summary>Field number for the "message_set_wire_format" field.</summary>
+ public const int MessageSetWireFormatFieldNumber = 1;
+ private bool messageSetWireFormat_;
+ /// <summary>
+ /// Set true to use the old proto1 MessageSet wire format for extensions.
+ /// This is provided for backwards-compatibility with the MessageSet wire
+ /// format. You should not use this for any other reason: It's less
+ /// efficient, has fewer features, and is more complicated.
+ ///
+ /// The message must be defined exactly as follows:
+ /// message Foo {
+ /// option message_set_wire_format = true;
+ /// extensions 4 to max;
+ /// }
+ /// Note that the message cannot have any defined fields; MessageSets only
+ /// have extensions.
+ ///
+ /// All extensions of your type must be singular messages; e.g. they cannot
+ /// be int32s, enums, or repeated messages.
+ ///
+ /// Because this is an option, the above two restrictions are not enforced by
+ /// the protocol compiler.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool MessageSetWireFormat {
+ get { return messageSetWireFormat_; }
+ set {
+ messageSetWireFormat_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "no_standard_descriptor_accessor" field.</summary>
+ public const int NoStandardDescriptorAccessorFieldNumber = 2;
+ private bool noStandardDescriptorAccessor_;
+ /// <summary>
+ /// Disables the generation of the standard "descriptor()" accessor, which can
+ /// conflict with a field of the same name. This is meant to make migration
+ /// from proto1 easier; new code should avoid fields named "descriptor".
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool NoStandardDescriptorAccessor {
+ get { return noStandardDescriptorAccessor_; }
+ set {
+ noStandardDescriptorAccessor_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "deprecated" field.</summary>
+ public const int DeprecatedFieldNumber = 3;
+ private bool deprecated_;
+ /// <summary>
+ /// Is this message deprecated?
+ /// Depending on the target platform, this can emit Deprecated annotations
+ /// for the message, or it will be completely ignored; in the very least,
+ /// this is a formalization for deprecating messages.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Deprecated {
+ get { return deprecated_; }
+ set {
+ deprecated_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "map_entry" field.</summary>
+ public const int MapEntryFieldNumber = 7;
+ private bool mapEntry_;
+ /// <summary>
+ /// Whether the message is an automatically generated map entry type for the
+ /// maps field.
+ ///
+ /// For maps fields:
+ /// map&lt;KeyType, ValueType> map_field = 1;
+ /// The parsed descriptor looks like:
+ /// message MapFieldEntry {
+ /// option map_entry = true;
+ /// optional KeyType key = 1;
+ /// optional ValueType value = 2;
+ /// }
+ /// repeated MapFieldEntry map_field = 1;
+ ///
+ /// Implementations may choose not to generate the map_entry=true message, but
+ /// use a native map in the target language to hold the keys and values.
+ /// The reflection APIs in such implementions still need to work as
+ /// if the field is a repeated message field.
+ ///
+ /// NOTE: Do not set the option in .proto files. Always use the maps syntax
+ /// instead. The option should only be implicitly set by the proto compiler
+ /// parser.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool MapEntry {
+ get { return mapEntry_; }
+ set {
+ mapEntry_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "uninterpreted_option" field.</summary>
+ public const int UninterpretedOptionFieldNumber = 999;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.UninterpretedOption> _repeated_uninterpretedOption_codec
+ = pb::FieldCodec.ForMessage(7994, global::Google.Protobuf.Reflection.UninterpretedOption.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> uninterpretedOption_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption>();
+ /// <summary>
+ /// The parser stores options it doesn't recognize here. See above.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> UninterpretedOption {
+ get { return uninterpretedOption_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as MessageOptions);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(MessageOptions other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (MessageSetWireFormat != other.MessageSetWireFormat) return false;
+ if (NoStandardDescriptorAccessor != other.NoStandardDescriptorAccessor) return false;
+ if (Deprecated != other.Deprecated) return false;
+ if (MapEntry != other.MapEntry) return false;
+ if(!uninterpretedOption_.Equals(other.uninterpretedOption_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (MessageSetWireFormat != false) hash ^= MessageSetWireFormat.GetHashCode();
+ if (NoStandardDescriptorAccessor != false) hash ^= NoStandardDescriptorAccessor.GetHashCode();
+ if (Deprecated != false) hash ^= Deprecated.GetHashCode();
+ if (MapEntry != false) hash ^= MapEntry.GetHashCode();
+ hash ^= uninterpretedOption_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (MessageSetWireFormat != false) {
+ output.WriteRawTag(8);
+ output.WriteBool(MessageSetWireFormat);
+ }
+ if (NoStandardDescriptorAccessor != false) {
+ output.WriteRawTag(16);
+ output.WriteBool(NoStandardDescriptorAccessor);
+ }
+ if (Deprecated != false) {
+ output.WriteRawTag(24);
+ output.WriteBool(Deprecated);
+ }
+ if (MapEntry != false) {
+ output.WriteRawTag(56);
+ output.WriteBool(MapEntry);
+ }
+ uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (MessageSetWireFormat != false) {
+ size += 1 + 1;
+ }
+ if (NoStandardDescriptorAccessor != false) {
+ size += 1 + 1;
+ }
+ if (Deprecated != false) {
+ size += 1 + 1;
+ }
+ if (MapEntry != false) {
+ size += 1 + 1;
+ }
+ size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(MessageOptions other) {
+ if (other == null) {
+ return;
+ }
+ if (other.MessageSetWireFormat != false) {
+ MessageSetWireFormat = other.MessageSetWireFormat;
+ }
+ if (other.NoStandardDescriptorAccessor != false) {
+ NoStandardDescriptorAccessor = other.NoStandardDescriptorAccessor;
+ }
+ if (other.Deprecated != false) {
+ Deprecated = other.Deprecated;
+ }
+ if (other.MapEntry != false) {
+ MapEntry = other.MapEntry;
+ }
+ uninterpretedOption_.Add(other.uninterpretedOption_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);
+ break;
+ case 8: {
+ MessageSetWireFormat = input.ReadBool();
+ break;
+ }
+ case 16: {
+ NoStandardDescriptorAccessor = input.ReadBool();
+ break;
+ }
+ case 24: {
+ Deprecated = input.ReadBool();
+ break;
+ }
+ case 56: {
+ MapEntry = input.ReadBool();
+ break;
+ }
+ case 7994: {
+ uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ internal sealed partial class FieldOptions : pb::IMessage<FieldOptions> {
+ private static readonly pb::MessageParser<FieldOptions> _parser = new pb::MessageParser<FieldOptions>(() => new FieldOptions());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<FieldOptions> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[11]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ internal CustomOptions CustomOptions{ get; private set; } = CustomOptions.Empty;
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FieldOptions() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FieldOptions(FieldOptions other) : this() {
+ ctype_ = other.ctype_;
+ packed_ = other.packed_;
+ jstype_ = other.jstype_;
+ lazy_ = other.lazy_;
+ deprecated_ = other.deprecated_;
+ weak_ = other.weak_;
+ uninterpretedOption_ = other.uninterpretedOption_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FieldOptions Clone() {
+ return new FieldOptions(this);
+ }
+
+ /// <summary>Field number for the "ctype" field.</summary>
+ public const int CtypeFieldNumber = 1;
+ private global::Google.Protobuf.Reflection.FieldOptions.Types.CType ctype_ = 0;
+ /// <summary>
+ /// The ctype option instructs the C++ code generator to use a different
+ /// representation of the field than it normally would. See the specific
+ /// options below. This option is not yet implemented in the open source
+ /// release -- sorry, we'll try to include it in a future version!
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.Reflection.FieldOptions.Types.CType Ctype {
+ get { return ctype_; }
+ set {
+ ctype_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "packed" field.</summary>
+ public const int PackedFieldNumber = 2;
+ private bool packed_;
+ /// <summary>
+ /// The packed option can be enabled for repeated primitive fields to enable
+ /// a more efficient representation on the wire. Rather than repeatedly
+ /// writing the tag and type for each element, the entire array is encoded as
+ /// a single length-delimited blob. In proto3, only explicit setting it to
+ /// false will avoid using packed encoding.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Packed {
+ get { return packed_; }
+ set {
+ packed_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "jstype" field.</summary>
+ public const int JstypeFieldNumber = 6;
+ private global::Google.Protobuf.Reflection.FieldOptions.Types.JSType jstype_ = 0;
+ /// <summary>
+ /// 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
+ /// represented as JavaScript strings. This avoids loss of precision that can
+ /// happen when a large value is converted to a floating point JavaScript
+ /// numbers. Specifying JS_NUMBER for the jstype causes the generated
+ /// JavaScript code to use the JavaScript "number" type instead of strings.
+ /// This option is an enum to permit additional types to be added,
+ /// e.g. goog.math.Integer.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.Reflection.FieldOptions.Types.JSType Jstype {
+ get { return jstype_; }
+ set {
+ jstype_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "lazy" field.</summary>
+ public const int LazyFieldNumber = 5;
+ private bool lazy_;
+ /// <summary>
+ /// Should this field be parsed lazily? Lazy applies only to message-type
+ /// fields. It means that when the outer message is initially parsed, the
+ /// inner message's contents will not be parsed but instead stored in encoded
+ /// form. The inner message will actually be parsed when it is first accessed.
+ ///
+ /// This is only a hint. Implementations are free to choose whether to use
+ /// eager or lazy parsing regardless of the value of this option. However,
+ /// setting this option true suggests that the protocol author believes that
+ /// using lazy parsing on this field is worth the additional bookkeeping
+ /// overhead typically needed to implement it.
+ ///
+ /// This option does not affect the public interface of any generated code;
+ /// all method signatures remain the same. Furthermore, thread-safety of the
+ /// interface is not affected by this option; const methods remain safe to
+ /// call from multiple threads concurrently, while non-const methods continue
+ /// to require exclusive access.
+ ///
+ /// Note that implementations may choose not to check required fields within
+ /// 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
+ /// parsing. An implementation which chooses not to check required fields
+ /// must be consistent about it. That is, for any particular sub-message, the
+ /// implementation must either *always* check its required fields, or *never*
+ /// check its required fields, regardless of whether or not the message has
+ /// been parsed.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Lazy {
+ get { return lazy_; }
+ set {
+ lazy_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "deprecated" field.</summary>
+ public const int DeprecatedFieldNumber = 3;
+ private bool deprecated_;
+ /// <summary>
+ /// Is this field deprecated?
+ /// Depending on the target platform, this can emit Deprecated annotations
+ /// for accessors, or it will be completely ignored; in the very least, this
+ /// is a formalization for deprecating fields.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Deprecated {
+ get { return deprecated_; }
+ set {
+ deprecated_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "weak" field.</summary>
+ public const int WeakFieldNumber = 10;
+ private bool weak_;
+ /// <summary>
+ /// For Google-internal migration only. Do not use.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Weak {
+ get { return weak_; }
+ set {
+ weak_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "uninterpreted_option" field.</summary>
+ public const int UninterpretedOptionFieldNumber = 999;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.UninterpretedOption> _repeated_uninterpretedOption_codec
+ = pb::FieldCodec.ForMessage(7994, global::Google.Protobuf.Reflection.UninterpretedOption.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> uninterpretedOption_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption>();
+ /// <summary>
+ /// The parser stores options it doesn't recognize here. See above.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> UninterpretedOption {
+ get { return uninterpretedOption_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as FieldOptions);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(FieldOptions other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Ctype != other.Ctype) return false;
+ if (Packed != other.Packed) return false;
+ if (Jstype != other.Jstype) return false;
+ if (Lazy != other.Lazy) return false;
+ if (Deprecated != other.Deprecated) return false;
+ if (Weak != other.Weak) return false;
+ if(!uninterpretedOption_.Equals(other.uninterpretedOption_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Ctype != 0) hash ^= Ctype.GetHashCode();
+ if (Packed != false) hash ^= Packed.GetHashCode();
+ if (Jstype != 0) hash ^= Jstype.GetHashCode();
+ if (Lazy != false) hash ^= Lazy.GetHashCode();
+ if (Deprecated != false) hash ^= Deprecated.GetHashCode();
+ if (Weak != false) hash ^= Weak.GetHashCode();
+ hash ^= uninterpretedOption_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Ctype != 0) {
+ output.WriteRawTag(8);
+ output.WriteEnum((int) Ctype);
+ }
+ if (Packed != false) {
+ output.WriteRawTag(16);
+ output.WriteBool(Packed);
+ }
+ if (Deprecated != false) {
+ output.WriteRawTag(24);
+ output.WriteBool(Deprecated);
+ }
+ if (Lazy != false) {
+ output.WriteRawTag(40);
+ output.WriteBool(Lazy);
+ }
+ if (Jstype != 0) {
+ output.WriteRawTag(48);
+ output.WriteEnum((int) Jstype);
+ }
+ if (Weak != false) {
+ output.WriteRawTag(80);
+ output.WriteBool(Weak);
+ }
+ uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Ctype != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Ctype);
+ }
+ if (Packed != false) {
+ size += 1 + 1;
+ }
+ if (Jstype != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Jstype);
+ }
+ if (Lazy != false) {
+ size += 1 + 1;
+ }
+ if (Deprecated != false) {
+ size += 1 + 1;
+ }
+ if (Weak != false) {
+ size += 1 + 1;
+ }
+ size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(FieldOptions other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Ctype != 0) {
+ Ctype = other.Ctype;
+ }
+ if (other.Packed != false) {
+ Packed = other.Packed;
+ }
+ if (other.Jstype != 0) {
+ Jstype = other.Jstype;
+ }
+ if (other.Lazy != false) {
+ Lazy = other.Lazy;
+ }
+ if (other.Deprecated != false) {
+ Deprecated = other.Deprecated;
+ }
+ if (other.Weak != false) {
+ Weak = other.Weak;
+ }
+ uninterpretedOption_.Add(other.uninterpretedOption_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);
+ break;
+ case 8: {
+ ctype_ = (global::Google.Protobuf.Reflection.FieldOptions.Types.CType) input.ReadEnum();
+ break;
+ }
+ case 16: {
+ Packed = input.ReadBool();
+ break;
+ }
+ case 24: {
+ Deprecated = input.ReadBool();
+ break;
+ }
+ case 40: {
+ Lazy = input.ReadBool();
+ break;
+ }
+ case 48: {
+ jstype_ = (global::Google.Protobuf.Reflection.FieldOptions.Types.JSType) input.ReadEnum();
+ break;
+ }
+ case 80: {
+ Weak = input.ReadBool();
+ break;
+ }
+ case 7994: {
+ uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the FieldOptions message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ internal enum CType {
+ /// <summary>
+ /// Default mode.
+ /// </summary>
+ [pbr::OriginalName("STRING")] String = 0,
+ [pbr::OriginalName("CORD")] Cord = 1,
+ [pbr::OriginalName("STRING_PIECE")] StringPiece = 2,
+ }
+
+ internal enum JSType {
+ /// <summary>
+ /// Use the default type.
+ /// </summary>
+ [pbr::OriginalName("JS_NORMAL")] JsNormal = 0,
+ /// <summary>
+ /// Use JavaScript strings.
+ /// </summary>
+ [pbr::OriginalName("JS_STRING")] JsString = 1,
+ /// <summary>
+ /// Use JavaScript numbers.
+ /// </summary>
+ [pbr::OriginalName("JS_NUMBER")] JsNumber = 2,
+ }
+
+ }
+ #endregion
+
+ }
+
+ internal sealed partial class OneofOptions : pb::IMessage<OneofOptions> {
+ private static readonly pb::MessageParser<OneofOptions> _parser = new pb::MessageParser<OneofOptions>(() => new OneofOptions());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<OneofOptions> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[12]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ internal CustomOptions CustomOptions{ get; private set; } = CustomOptions.Empty;
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneofOptions() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneofOptions(OneofOptions other) : this() {
+ uninterpretedOption_ = other.uninterpretedOption_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public OneofOptions Clone() {
+ return new OneofOptions(this);
+ }
+
+ /// <summary>Field number for the "uninterpreted_option" field.</summary>
+ public const int UninterpretedOptionFieldNumber = 999;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.UninterpretedOption> _repeated_uninterpretedOption_codec
+ = pb::FieldCodec.ForMessage(7994, global::Google.Protobuf.Reflection.UninterpretedOption.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> uninterpretedOption_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption>();
+ /// <summary>
+ /// The parser stores options it doesn't recognize here. See above.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> UninterpretedOption {
+ get { return uninterpretedOption_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as OneofOptions);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(OneofOptions other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if(!uninterpretedOption_.Equals(other.uninterpretedOption_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= uninterpretedOption_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(OneofOptions other) {
+ if (other == null) {
+ return;
+ }
+ uninterpretedOption_.Add(other.uninterpretedOption_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);
+ break;
+ case 7994: {
+ uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ internal sealed partial class EnumOptions : pb::IMessage<EnumOptions> {
+ private static readonly pb::MessageParser<EnumOptions> _parser = new pb::MessageParser<EnumOptions>(() => new EnumOptions());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<EnumOptions> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[13]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ internal CustomOptions CustomOptions{ get; private set; } = CustomOptions.Empty;
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public EnumOptions() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public EnumOptions(EnumOptions other) : this() {
+ allowAlias_ = other.allowAlias_;
+ deprecated_ = other.deprecated_;
+ uninterpretedOption_ = other.uninterpretedOption_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public EnumOptions Clone() {
+ return new EnumOptions(this);
+ }
+
+ /// <summary>Field number for the "allow_alias" field.</summary>
+ public const int AllowAliasFieldNumber = 2;
+ private bool allowAlias_;
+ /// <summary>
+ /// Set this option to true to allow mapping different tag names to the same
+ /// value.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool AllowAlias {
+ get { return allowAlias_; }
+ set {
+ allowAlias_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "deprecated" field.</summary>
+ public const int DeprecatedFieldNumber = 3;
+ private bool deprecated_;
+ /// <summary>
+ /// Is this enum deprecated?
+ /// Depending on the target platform, this can emit Deprecated annotations
+ /// for the enum, or it will be completely ignored; in the very least, this
+ /// is a formalization for deprecating enums.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Deprecated {
+ get { return deprecated_; }
+ set {
+ deprecated_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "uninterpreted_option" field.</summary>
+ public const int UninterpretedOptionFieldNumber = 999;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.UninterpretedOption> _repeated_uninterpretedOption_codec
+ = pb::FieldCodec.ForMessage(7994, global::Google.Protobuf.Reflection.UninterpretedOption.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> uninterpretedOption_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption>();
+ /// <summary>
+ /// The parser stores options it doesn't recognize here. See above.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> UninterpretedOption {
+ get { return uninterpretedOption_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as EnumOptions);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(EnumOptions other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (AllowAlias != other.AllowAlias) return false;
+ if (Deprecated != other.Deprecated) return false;
+ if(!uninterpretedOption_.Equals(other.uninterpretedOption_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (AllowAlias != false) hash ^= AllowAlias.GetHashCode();
+ if (Deprecated != false) hash ^= Deprecated.GetHashCode();
+ hash ^= uninterpretedOption_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (AllowAlias != false) {
+ output.WriteRawTag(16);
+ output.WriteBool(AllowAlias);
+ }
+ if (Deprecated != false) {
+ output.WriteRawTag(24);
+ output.WriteBool(Deprecated);
+ }
+ uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (AllowAlias != false) {
+ size += 1 + 1;
+ }
+ if (Deprecated != false) {
+ size += 1 + 1;
+ }
+ size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(EnumOptions other) {
+ if (other == null) {
+ return;
+ }
+ if (other.AllowAlias != false) {
+ AllowAlias = other.AllowAlias;
+ }
+ if (other.Deprecated != false) {
+ Deprecated = other.Deprecated;
+ }
+ uninterpretedOption_.Add(other.uninterpretedOption_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);
+ break;
+ case 16: {
+ AllowAlias = input.ReadBool();
+ break;
+ }
+ case 24: {
+ Deprecated = input.ReadBool();
+ break;
+ }
+ case 7994: {
+ uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ internal sealed partial class EnumValueOptions : pb::IMessage<EnumValueOptions> {
+ private static readonly pb::MessageParser<EnumValueOptions> _parser = new pb::MessageParser<EnumValueOptions>(() => new EnumValueOptions());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<EnumValueOptions> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[14]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ internal CustomOptions CustomOptions{ get; private set; } = CustomOptions.Empty;
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public EnumValueOptions() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public EnumValueOptions(EnumValueOptions other) : this() {
+ deprecated_ = other.deprecated_;
+ uninterpretedOption_ = other.uninterpretedOption_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public EnumValueOptions Clone() {
+ return new EnumValueOptions(this);
+ }
+
+ /// <summary>Field number for the "deprecated" field.</summary>
+ public const int DeprecatedFieldNumber = 1;
+ private bool deprecated_;
+ /// <summary>
+ /// Is this enum value deprecated?
+ /// Depending on the target platform, this can emit Deprecated annotations
+ /// for the enum value, or it will be completely ignored; in the very least,
+ /// this is a formalization for deprecating enum values.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Deprecated {
+ get { return deprecated_; }
+ set {
+ deprecated_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "uninterpreted_option" field.</summary>
+ public const int UninterpretedOptionFieldNumber = 999;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.UninterpretedOption> _repeated_uninterpretedOption_codec
+ = pb::FieldCodec.ForMessage(7994, global::Google.Protobuf.Reflection.UninterpretedOption.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> uninterpretedOption_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption>();
+ /// <summary>
+ /// The parser stores options it doesn't recognize here. See above.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> UninterpretedOption {
+ get { return uninterpretedOption_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as EnumValueOptions);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(EnumValueOptions other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Deprecated != other.Deprecated) return false;
+ if(!uninterpretedOption_.Equals(other.uninterpretedOption_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Deprecated != false) hash ^= Deprecated.GetHashCode();
+ hash ^= uninterpretedOption_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Deprecated != false) {
+ output.WriteRawTag(8);
+ output.WriteBool(Deprecated);
+ }
+ uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Deprecated != false) {
+ size += 1 + 1;
+ }
+ size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(EnumValueOptions other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Deprecated != false) {
+ Deprecated = other.Deprecated;
+ }
+ uninterpretedOption_.Add(other.uninterpretedOption_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);
+ break;
+ case 8: {
+ Deprecated = input.ReadBool();
+ break;
+ }
+ case 7994: {
+ uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ internal sealed partial class ServiceOptions : pb::IMessage<ServiceOptions> {
+ private static readonly pb::MessageParser<ServiceOptions> _parser = new pb::MessageParser<ServiceOptions>(() => new ServiceOptions());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<ServiceOptions> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[15]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ internal CustomOptions CustomOptions{ get; private set; } = CustomOptions.Empty;
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ServiceOptions() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ServiceOptions(ServiceOptions other) : this() {
+ deprecated_ = other.deprecated_;
+ uninterpretedOption_ = other.uninterpretedOption_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ServiceOptions Clone() {
+ return new ServiceOptions(this);
+ }
+
+ /// <summary>Field number for the "deprecated" field.</summary>
+ public const int DeprecatedFieldNumber = 33;
+ private bool deprecated_;
+ /// <summary>
+ /// Is this service deprecated?
+ /// Depending on the target platform, this can emit Deprecated annotations
+ /// for the service, or it will be completely ignored; in the very least,
+ /// this is a formalization for deprecating services.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Deprecated {
+ get { return deprecated_; }
+ set {
+ deprecated_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "uninterpreted_option" field.</summary>
+ public const int UninterpretedOptionFieldNumber = 999;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.UninterpretedOption> _repeated_uninterpretedOption_codec
+ = pb::FieldCodec.ForMessage(7994, global::Google.Protobuf.Reflection.UninterpretedOption.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> uninterpretedOption_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption>();
+ /// <summary>
+ /// The parser stores options it doesn't recognize here. See above.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> UninterpretedOption {
+ get { return uninterpretedOption_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as ServiceOptions);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(ServiceOptions other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Deprecated != other.Deprecated) return false;
+ if(!uninterpretedOption_.Equals(other.uninterpretedOption_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Deprecated != false) hash ^= Deprecated.GetHashCode();
+ hash ^= uninterpretedOption_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Deprecated != false) {
+ output.WriteRawTag(136, 2);
+ output.WriteBool(Deprecated);
+ }
+ uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Deprecated != false) {
+ size += 2 + 1;
+ }
+ size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(ServiceOptions other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Deprecated != false) {
+ Deprecated = other.Deprecated;
+ }
+ uninterpretedOption_.Add(other.uninterpretedOption_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);
+ break;
+ case 264: {
+ Deprecated = input.ReadBool();
+ break;
+ }
+ case 7994: {
+ uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ internal sealed partial class MethodOptions : pb::IMessage<MethodOptions> {
+ private static readonly pb::MessageParser<MethodOptions> _parser = new pb::MessageParser<MethodOptions>(() => new MethodOptions());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<MethodOptions> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[16]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ internal CustomOptions CustomOptions{ get; private set; } = CustomOptions.Empty;
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MethodOptions() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MethodOptions(MethodOptions other) : this() {
+ deprecated_ = other.deprecated_;
+ idempotencyLevel_ = other.idempotencyLevel_;
+ uninterpretedOption_ = other.uninterpretedOption_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public MethodOptions Clone() {
+ return new MethodOptions(this);
+ }
+
+ /// <summary>Field number for the "deprecated" field.</summary>
+ public const int DeprecatedFieldNumber = 33;
+ private bool deprecated_;
+ /// <summary>
+ /// Is this method deprecated?
+ /// Depending on the target platform, this can emit Deprecated annotations
+ /// for the method, or it will be completely ignored; in the very least,
+ /// this is a formalization for deprecating methods.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Deprecated {
+ get { return deprecated_; }
+ set {
+ deprecated_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "idempotency_level" field.</summary>
+ public const int IdempotencyLevelFieldNumber = 34;
+ private global::Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel idempotencyLevel_ = 0;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel IdempotencyLevel {
+ get { return idempotencyLevel_; }
+ set {
+ idempotencyLevel_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "uninterpreted_option" field.</summary>
+ public const int UninterpretedOptionFieldNumber = 999;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.UninterpretedOption> _repeated_uninterpretedOption_codec
+ = pb::FieldCodec.ForMessage(7994, global::Google.Protobuf.Reflection.UninterpretedOption.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> uninterpretedOption_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption>();
+ /// <summary>
+ /// The parser stores options it doesn't recognize here. See above.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption> UninterpretedOption {
+ get { return uninterpretedOption_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as MethodOptions);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(MethodOptions other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Deprecated != other.Deprecated) return false;
+ if (IdempotencyLevel != other.IdempotencyLevel) return false;
+ if(!uninterpretedOption_.Equals(other.uninterpretedOption_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Deprecated != false) hash ^= Deprecated.GetHashCode();
+ if (IdempotencyLevel != 0) hash ^= IdempotencyLevel.GetHashCode();
+ hash ^= uninterpretedOption_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Deprecated != false) {
+ output.WriteRawTag(136, 2);
+ output.WriteBool(Deprecated);
+ }
+ if (IdempotencyLevel != 0) {
+ output.WriteRawTag(144, 2);
+ output.WriteEnum((int) IdempotencyLevel);
+ }
+ uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Deprecated != false) {
+ size += 2 + 1;
+ }
+ if (IdempotencyLevel != 0) {
+ size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) IdempotencyLevel);
+ }
+ size += uninterpretedOption_.CalculateSize(_repeated_uninterpretedOption_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(MethodOptions other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Deprecated != false) {
+ Deprecated = other.Deprecated;
+ }
+ if (other.IdempotencyLevel != 0) {
+ IdempotencyLevel = other.IdempotencyLevel;
+ }
+ uninterpretedOption_.Add(other.uninterpretedOption_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);
+ break;
+ case 264: {
+ Deprecated = input.ReadBool();
+ break;
+ }
+ case 272: {
+ idempotencyLevel_ = (global::Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel) input.ReadEnum();
+ break;
+ }
+ case 7994: {
+ uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the MethodOptions message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ /// <summary>
+ /// Is this method side-effect-free (or safe in HTTP parlance), or idempotent,
+ /// or neither? HTTP based RPC implementation may choose GET verb for safe
+ /// methods, and PUT verb for idempotent methods instead of the default POST.
+ /// </summary>
+ internal enum IdempotencyLevel {
+ [pbr::OriginalName("IDEMPOTENCY_UNKNOWN")] IdempotencyUnknown = 0,
+ /// <summary>
+ /// implies idempotent
+ /// </summary>
+ [pbr::OriginalName("NO_SIDE_EFFECTS")] NoSideEffects = 1,
+ /// <summary>
+ /// idempotent, but may have side effects
+ /// </summary>
+ [pbr::OriginalName("IDEMPOTENT")] Idempotent = 2,
+ }
+
+ }
+ #endregion
+
+ }
+
+ /// <summary>
+ /// A message representing a option the parser does not recognize. This only
+ /// appears in options protos created by the compiler::Parser class.
+ /// DescriptorPool resolves these when building Descriptor objects. Therefore,
+ /// options protos in descriptor objects (e.g. returned by Descriptor::options(),
+ /// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
+ /// in them.
+ /// </summary>
+ internal sealed partial class UninterpretedOption : pb::IMessage<UninterpretedOption> {
+ private static readonly pb::MessageParser<UninterpretedOption> _parser = new pb::MessageParser<UninterpretedOption>(() => new UninterpretedOption());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<UninterpretedOption> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[17]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public UninterpretedOption() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public UninterpretedOption(UninterpretedOption other) : this() {
+ name_ = other.name_.Clone();
+ identifierValue_ = other.identifierValue_;
+ positiveIntValue_ = other.positiveIntValue_;
+ negativeIntValue_ = other.negativeIntValue_;
+ doubleValue_ = other.doubleValue_;
+ stringValue_ = other.stringValue_;
+ aggregateValue_ = other.aggregateValue_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public UninterpretedOption Clone() {
+ return new UninterpretedOption(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 2;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.UninterpretedOption.Types.NamePart> _repeated_name_codec
+ = pb::FieldCodec.ForMessage(18, global::Google.Protobuf.Reflection.UninterpretedOption.Types.NamePart.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption.Types.NamePart> name_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption.Types.NamePart>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.UninterpretedOption.Types.NamePart> Name {
+ get { return name_; }
+ }
+
+ /// <summary>Field number for the "identifier_value" field.</summary>
+ public const int IdentifierValueFieldNumber = 3;
+ private string identifierValue_ = "";
+ /// <summary>
+ /// The value of the uninterpreted option, in whatever type the tokenizer
+ /// identified it as during parsing. Exactly one of these should be set.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string IdentifierValue {
+ get { return identifierValue_; }
+ set {
+ identifierValue_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "positive_int_value" field.</summary>
+ public const int PositiveIntValueFieldNumber = 4;
+ private ulong positiveIntValue_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ulong PositiveIntValue {
+ get { return positiveIntValue_; }
+ set {
+ positiveIntValue_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "negative_int_value" field.</summary>
+ public const int NegativeIntValueFieldNumber = 5;
+ private long negativeIntValue_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public long NegativeIntValue {
+ get { return negativeIntValue_; }
+ set {
+ negativeIntValue_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "double_value" field.</summary>
+ public const int DoubleValueFieldNumber = 6;
+ private double doubleValue_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public double DoubleValue {
+ get { return doubleValue_; }
+ set {
+ doubleValue_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "string_value" field.</summary>
+ public const int StringValueFieldNumber = 7;
+ private pb::ByteString stringValue_ = pb::ByteString.Empty;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pb::ByteString StringValue {
+ get { return stringValue_; }
+ set {
+ stringValue_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "aggregate_value" field.</summary>
+ public const int AggregateValueFieldNumber = 8;
+ private string aggregateValue_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string AggregateValue {
+ get { return aggregateValue_; }
+ set {
+ aggregateValue_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as UninterpretedOption);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(UninterpretedOption other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if(!name_.Equals(other.name_)) return false;
+ if (IdentifierValue != other.IdentifierValue) return false;
+ if (PositiveIntValue != other.PositiveIntValue) return false;
+ if (NegativeIntValue != other.NegativeIntValue) return false;
+ if (DoubleValue != other.DoubleValue) return false;
+ if (StringValue != other.StringValue) return false;
+ if (AggregateValue != other.AggregateValue) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= name_.GetHashCode();
+ if (IdentifierValue.Length != 0) hash ^= IdentifierValue.GetHashCode();
+ if (PositiveIntValue != 0UL) hash ^= PositiveIntValue.GetHashCode();
+ if (NegativeIntValue != 0L) hash ^= NegativeIntValue.GetHashCode();
+ if (DoubleValue != 0D) hash ^= DoubleValue.GetHashCode();
+ if (StringValue.Length != 0) hash ^= StringValue.GetHashCode();
+ if (AggregateValue.Length != 0) hash ^= AggregateValue.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ name_.WriteTo(output, _repeated_name_codec);
+ if (IdentifierValue.Length != 0) {
+ output.WriteRawTag(26);
+ output.WriteString(IdentifierValue);
+ }
+ if (PositiveIntValue != 0UL) {
+ output.WriteRawTag(32);
+ output.WriteUInt64(PositiveIntValue);
+ }
+ if (NegativeIntValue != 0L) {
+ output.WriteRawTag(40);
+ output.WriteInt64(NegativeIntValue);
+ }
+ if (DoubleValue != 0D) {
+ output.WriteRawTag(49);
+ output.WriteDouble(DoubleValue);
+ }
+ if (StringValue.Length != 0) {
+ output.WriteRawTag(58);
+ output.WriteBytes(StringValue);
+ }
+ if (AggregateValue.Length != 0) {
+ output.WriteRawTag(66);
+ output.WriteString(AggregateValue);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += name_.CalculateSize(_repeated_name_codec);
+ if (IdentifierValue.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(IdentifierValue);
+ }
+ if (PositiveIntValue != 0UL) {
+ size += 1 + pb::CodedOutputStream.ComputeUInt64Size(PositiveIntValue);
+ }
+ if (NegativeIntValue != 0L) {
+ size += 1 + pb::CodedOutputStream.ComputeInt64Size(NegativeIntValue);
+ }
+ if (DoubleValue != 0D) {
+ size += 1 + 8;
+ }
+ if (StringValue.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeBytesSize(StringValue);
+ }
+ if (AggregateValue.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(AggregateValue);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(UninterpretedOption other) {
+ if (other == null) {
+ return;
+ }
+ name_.Add(other.name_);
+ if (other.IdentifierValue.Length != 0) {
+ IdentifierValue = other.IdentifierValue;
+ }
+ if (other.PositiveIntValue != 0UL) {
+ PositiveIntValue = other.PositiveIntValue;
+ }
+ if (other.NegativeIntValue != 0L) {
+ NegativeIntValue = other.NegativeIntValue;
+ }
+ if (other.DoubleValue != 0D) {
+ DoubleValue = other.DoubleValue;
+ }
+ if (other.StringValue.Length != 0) {
+ StringValue = other.StringValue;
+ }
+ if (other.AggregateValue.Length != 0) {
+ AggregateValue = other.AggregateValue;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 18: {
+ name_.AddEntriesFrom(input, _repeated_name_codec);
+ break;
+ }
+ case 26: {
+ IdentifierValue = input.ReadString();
+ break;
+ }
+ case 32: {
+ PositiveIntValue = input.ReadUInt64();
+ break;
+ }
+ case 40: {
+ NegativeIntValue = input.ReadInt64();
+ break;
+ }
+ case 49: {
+ DoubleValue = input.ReadDouble();
+ break;
+ }
+ case 58: {
+ StringValue = input.ReadBytes();
+ break;
+ }
+ case 66: {
+ AggregateValue = input.ReadString();
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the UninterpretedOption message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ /// <summary>
+ /// The name of the uninterpreted option. Each string represents a segment in
+ /// a dot-separated name. is_extension is true iff a segment represents an
+ /// extension (denoted with parentheses in options specs in .proto files).
+ /// E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
+ /// "foo.(bar.baz).qux".
+ /// </summary>
+ internal sealed partial class NamePart : pb::IMessage<NamePart> {
+ private static readonly pb::MessageParser<NamePart> _parser = new pb::MessageParser<NamePart>(() => new NamePart());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<NamePart> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.UninterpretedOption.Descriptor.NestedTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NamePart() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NamePart(NamePart other) : this() {
+ namePart_ = other.namePart_;
+ isExtension_ = other.isExtension_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NamePart Clone() {
+ return new NamePart(this);
+ }
+
+ /// <summary>Field number for the "name_part" field.</summary>
+ public const int NamePart_FieldNumber = 1;
+ private string namePart_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string NamePart_ {
+ get { return namePart_; }
+ set {
+ namePart_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "is_extension" field.</summary>
+ public const int IsExtensionFieldNumber = 2;
+ private bool isExtension_;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool IsExtension {
+ get { return isExtension_; }
+ set {
+ isExtension_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as NamePart);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(NamePart other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (NamePart_ != other.NamePart_) return false;
+ if (IsExtension != other.IsExtension) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (NamePart_.Length != 0) hash ^= NamePart_.GetHashCode();
+ if (IsExtension != false) hash ^= IsExtension.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (NamePart_.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(NamePart_);
+ }
+ if (IsExtension != false) {
+ output.WriteRawTag(16);
+ output.WriteBool(IsExtension);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (NamePart_.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(NamePart_);
+ }
+ if (IsExtension != false) {
+ size += 1 + 1;
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(NamePart other) {
+ if (other == null) {
+ return;
+ }
+ if (other.NamePart_.Length != 0) {
+ NamePart_ = other.NamePart_;
+ }
+ if (other.IsExtension != false) {
+ IsExtension = other.IsExtension;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ NamePart_ = input.ReadString();
+ break;
+ }
+ case 16: {
+ IsExtension = input.ReadBool();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ }
+ #endregion
+
+ }
+
+ /// <summary>
+ /// Encapsulates information about the original source file from which a
+ /// FileDescriptorProto was generated.
+ /// </summary>
+ internal sealed partial class SourceCodeInfo : pb::IMessage<SourceCodeInfo> {
+ private static readonly pb::MessageParser<SourceCodeInfo> _parser = new pb::MessageParser<SourceCodeInfo>(() => new SourceCodeInfo());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<SourceCodeInfo> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[18]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SourceCodeInfo() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SourceCodeInfo(SourceCodeInfo other) : this() {
+ location_ = other.location_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SourceCodeInfo Clone() {
+ return new SourceCodeInfo(this);
+ }
+
+ /// <summary>Field number for the "location" field.</summary>
+ public const int LocationFieldNumber = 1;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.SourceCodeInfo.Types.Location> _repeated_location_codec
+ = pb::FieldCodec.ForMessage(10, global::Google.Protobuf.Reflection.SourceCodeInfo.Types.Location.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.SourceCodeInfo.Types.Location> location_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.SourceCodeInfo.Types.Location>();
+ /// <summary>
+ /// A Location identifies a piece of source code in a .proto file which
+ /// corresponds to a particular definition. This information is intended
+ /// to be useful to IDEs, code indexers, documentation generators, and similar
+ /// tools.
+ ///
+ /// For example, say we have a file like:
+ /// message Foo {
+ /// optional string foo = 1;
+ /// }
+ /// Let's look at just the field definition:
+ /// optional string foo = 1;
+ /// ^ ^^ ^^ ^ ^^^
+ /// a bc de f ghi
+ /// We have the following locations:
+ /// span path represents
+ /// [a,i) [ 4, 0, 2, 0 ] The whole field definition.
+ /// [a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
+ /// [c,d) [ 4, 0, 2, 0, 5 ] The type (string).
+ /// [e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
+ /// [g,h) [ 4, 0, 2, 0, 3 ] The number (1).
+ ///
+ /// Notes:
+ /// - A location may refer to a repeated field itself (i.e. not to any
+ /// particular index within it). This is used whenever a set of elements are
+ /// logically enclosed in a single code segment. For example, an entire
+ /// extend block (possibly containing multiple extension definitions) will
+ /// have an outer location whose path refers to the "extensions" repeated
+ /// field without an index.
+ /// - Multiple locations may have the same path. This happens when a single
+ /// logical declaration is spread out across multiple places. The most
+ /// obvious example is the "extend" block again -- there may be multiple
+ /// extend blocks in the same scope, each of which will have the same path.
+ /// - A location's span is not always a subset of its parent's span. For
+ /// example, the "extendee" of an extension declaration appears at the
+ /// beginning of the "extend" block and is shared by all extensions within
+ /// the block.
+ /// - Just because a location's span is a subset of some other location's span
+ /// does not mean that it is a descendent. For example, a "group" defines
+ /// both a type and a field in a single declaration. Thus, the locations
+ /// corresponding to the type and field and their components will overlap.
+ /// - Code which tries to interpret locations should probably be designed to
+ /// ignore those that it doesn't understand, as more types of locations could
+ /// be recorded in the future.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.SourceCodeInfo.Types.Location> Location {
+ get { return location_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as SourceCodeInfo);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(SourceCodeInfo other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if(!location_.Equals(other.location_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= location_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ location_.WriteTo(output, _repeated_location_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += location_.CalculateSize(_repeated_location_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(SourceCodeInfo other) {
+ if (other == null) {
+ return;
+ }
+ location_.Add(other.location_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ location_.AddEntriesFrom(input, _repeated_location_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the SourceCodeInfo message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ internal sealed partial class Location : pb::IMessage<Location> {
+ private static readonly pb::MessageParser<Location> _parser = new pb::MessageParser<Location>(() => new Location());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Location> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.SourceCodeInfo.Descriptor.NestedTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Location() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Location(Location other) : this() {
+ path_ = other.path_.Clone();
+ span_ = other.span_.Clone();
+ leadingComments_ = other.leadingComments_;
+ trailingComments_ = other.trailingComments_;
+ leadingDetachedComments_ = other.leadingDetachedComments_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Location Clone() {
+ return new Location(this);
+ }
+
+ /// <summary>Field number for the "path" field.</summary>
+ public const int PathFieldNumber = 1;
+ private static readonly pb::FieldCodec<int> _repeated_path_codec
+ = pb::FieldCodec.ForInt32(10);
+ private readonly pbc::RepeatedField<int> path_ = new pbc::RepeatedField<int>();
+ /// <summary>
+ /// Identifies which part of the FileDescriptorProto was defined at this
+ /// location.
+ ///
+ /// Each element is a field number or an index. They form a path from
+ /// the root FileDescriptorProto to the place where the definition. For
+ /// example, this path:
+ /// [ 4, 3, 2, 7, 1 ]
+ /// refers to:
+ /// file.message_type(3) // 4, 3
+ /// .field(7) // 2, 7
+ /// .name() // 1
+ /// This is because FileDescriptorProto.message_type has field number 4:
+ /// repeated DescriptorProto message_type = 4;
+ /// and DescriptorProto.field has field number 2:
+ /// repeated FieldDescriptorProto field = 2;
+ /// and FieldDescriptorProto.name has field number 1:
+ /// optional string name = 1;
+ ///
+ /// Thus, the above path gives the location of a field name. If we removed
+ /// the last element:
+ /// [ 4, 3, 2, 7 ]
+ /// this path refers to the whole field declaration (from the beginning
+ /// of the label to the terminating semicolon).
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> Path {
+ get { return path_; }
+ }
+
+ /// <summary>Field number for the "span" field.</summary>
+ public const int SpanFieldNumber = 2;
+ private static readonly pb::FieldCodec<int> _repeated_span_codec
+ = pb::FieldCodec.ForInt32(18);
+ private readonly pbc::RepeatedField<int> span_ = new pbc::RepeatedField<int>();
+ /// <summary>
+ /// Always has exactly three or four elements: start line, start column,
+ /// end line (optional, otherwise assumed same as start line), end column.
+ /// These are packed into a single field for efficiency. Note that line
+ /// and column numbers are zero-based -- typically you will want to add
+ /// 1 to each before displaying to a user.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> Span {
+ get { return span_; }
+ }
+
+ /// <summary>Field number for the "leading_comments" field.</summary>
+ public const int LeadingCommentsFieldNumber = 3;
+ private string leadingComments_ = "";
+ /// <summary>
+ /// If this SourceCodeInfo represents a complete declaration, these are any
+ /// comments appearing before and after the declaration which appear to be
+ /// attached to the declaration.
+ ///
+ /// A series of line comments appearing on consecutive lines, with no other
+ /// tokens appearing on those lines, will be treated as a single comment.
+ ///
+ /// leading_detached_comments will keep paragraphs of comments that appear
+ /// before (but not connected to) the current element. Each paragraph,
+ /// separated by empty lines, will be one comment element in the repeated
+ /// field.
+ ///
+ /// Only the comment content is provided; comment markers (e.g. //) are
+ /// stripped out. For block comments, leading whitespace and an asterisk
+ /// will be stripped from the beginning of each line other than the first.
+ /// Newlines are included in the output.
+ ///
+ /// Examples:
+ ///
+ /// optional int32 foo = 1; // Comment attached to foo.
+ /// // Comment attached to bar.
+ /// optional int32 bar = 2;
+ ///
+ /// optional string baz = 3;
+ /// // Comment attached to baz.
+ /// // Another line attached to baz.
+ ///
+ /// // Comment attached to qux.
+ /// //
+ /// // Another line attached to qux.
+ /// optional double qux = 4;
+ ///
+ /// // Detached comment for corge. This is not leading or trailing comments
+ /// // to qux or corge because there are blank lines separating it from
+ /// // both.
+ ///
+ /// // Detached comment for corge paragraph 2.
+ ///
+ /// optional string corge = 5;
+ /// /* Block comment attached
+ /// * to corge. Leading asterisks
+ /// * will be removed. */
+ /// /* Block comment attached to
+ /// * grault. */
+ /// optional int32 grault = 6;
+ ///
+ /// // ignored detached comments.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string LeadingComments {
+ get { return leadingComments_; }
+ set {
+ leadingComments_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "trailing_comments" field.</summary>
+ public const int TrailingCommentsFieldNumber = 4;
+ private string trailingComments_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string TrailingComments {
+ get { return trailingComments_; }
+ set {
+ trailingComments_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "leading_detached_comments" field.</summary>
+ public const int LeadingDetachedCommentsFieldNumber = 6;
+ private static readonly pb::FieldCodec<string> _repeated_leadingDetachedComments_codec
+ = pb::FieldCodec.ForString(50);
+ private readonly pbc::RepeatedField<string> leadingDetachedComments_ = new pbc::RepeatedField<string>();
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<string> LeadingDetachedComments {
+ get { return leadingDetachedComments_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Location);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Location other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if(!path_.Equals(other.path_)) return false;
+ if(!span_.Equals(other.span_)) return false;
+ if (LeadingComments != other.LeadingComments) return false;
+ if (TrailingComments != other.TrailingComments) return false;
+ if(!leadingDetachedComments_.Equals(other.leadingDetachedComments_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= path_.GetHashCode();
+ hash ^= span_.GetHashCode();
+ if (LeadingComments.Length != 0) hash ^= LeadingComments.GetHashCode();
+ if (TrailingComments.Length != 0) hash ^= TrailingComments.GetHashCode();
+ hash ^= leadingDetachedComments_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ path_.WriteTo(output, _repeated_path_codec);
+ span_.WriteTo(output, _repeated_span_codec);
+ if (LeadingComments.Length != 0) {
+ output.WriteRawTag(26);
+ output.WriteString(LeadingComments);
+ }
+ if (TrailingComments.Length != 0) {
+ output.WriteRawTag(34);
+ output.WriteString(TrailingComments);
+ }
+ leadingDetachedComments_.WriteTo(output, _repeated_leadingDetachedComments_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += path_.CalculateSize(_repeated_path_codec);
+ size += span_.CalculateSize(_repeated_span_codec);
+ if (LeadingComments.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(LeadingComments);
+ }
+ if (TrailingComments.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(TrailingComments);
+ }
+ size += leadingDetachedComments_.CalculateSize(_repeated_leadingDetachedComments_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Location other) {
+ if (other == null) {
+ return;
+ }
+ path_.Add(other.path_);
+ span_.Add(other.span_);
+ if (other.LeadingComments.Length != 0) {
+ LeadingComments = other.LeadingComments;
+ }
+ if (other.TrailingComments.Length != 0) {
+ TrailingComments = other.TrailingComments;
+ }
+ leadingDetachedComments_.Add(other.leadingDetachedComments_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10:
+ case 8: {
+ path_.AddEntriesFrom(input, _repeated_path_codec);
+ break;
+ }
+ case 18:
+ case 16: {
+ span_.AddEntriesFrom(input, _repeated_span_codec);
+ break;
+ }
+ case 26: {
+ LeadingComments = input.ReadString();
+ break;
+ }
+ case 34: {
+ TrailingComments = input.ReadString();
+ break;
+ }
+ case 50: {
+ leadingDetachedComments_.AddEntriesFrom(input, _repeated_leadingDetachedComments_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ }
+ #endregion
+
+ }
+
+ /// <summary>
+ /// Describes the relationship between generated code and its original source
+ /// file. A GeneratedCodeInfo message is associated with only one generated
+ /// source file, but may contain references to different source .proto files.
+ /// </summary>
+ internal sealed partial class GeneratedCodeInfo : pb::IMessage<GeneratedCodeInfo> {
+ private static readonly pb::MessageParser<GeneratedCodeInfo> _parser = new pb::MessageParser<GeneratedCodeInfo>(() => new GeneratedCodeInfo());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<GeneratedCodeInfo> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.DescriptorReflection.Descriptor.MessageTypes[19]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public GeneratedCodeInfo() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public GeneratedCodeInfo(GeneratedCodeInfo other) : this() {
+ annotation_ = other.annotation_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public GeneratedCodeInfo Clone() {
+ return new GeneratedCodeInfo(this);
+ }
+
+ /// <summary>Field number for the "annotation" field.</summary>
+ public const int AnnotationFieldNumber = 1;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation> _repeated_annotation_codec
+ = pb::FieldCodec.ForMessage(10, global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation> annotation_ = new pbc::RepeatedField<global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation>();
+ /// <summary>
+ /// An Annotation connects some span of text in generated code to an element
+ /// of its generating .proto file.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.Reflection.GeneratedCodeInfo.Types.Annotation> Annotation {
+ get { return annotation_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as GeneratedCodeInfo);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(GeneratedCodeInfo other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if(!annotation_.Equals(other.annotation_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= annotation_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ annotation_.WriteTo(output, _repeated_annotation_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += annotation_.CalculateSize(_repeated_annotation_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(GeneratedCodeInfo other) {
+ if (other == null) {
+ return;
+ }
+ annotation_.Add(other.annotation_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ annotation_.AddEntriesFrom(input, _repeated_annotation_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the GeneratedCodeInfo message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ internal sealed partial class Annotation : pb::IMessage<Annotation> {
+ private static readonly pb::MessageParser<Annotation> _parser = new pb::MessageParser<Annotation>(() => new Annotation());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Annotation> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.Reflection.GeneratedCodeInfo.Descriptor.NestedTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Annotation() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Annotation(Annotation other) : this() {
+ path_ = other.path_.Clone();
+ sourceFile_ = other.sourceFile_;
+ begin_ = other.begin_;
+ end_ = other.end_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Annotation Clone() {
+ return new Annotation(this);
+ }
+
+ /// <summary>Field number for the "path" field.</summary>
+ public const int PathFieldNumber = 1;
+ private static readonly pb::FieldCodec<int> _repeated_path_codec
+ = pb::FieldCodec.ForInt32(10);
+ private readonly pbc::RepeatedField<int> path_ = new pbc::RepeatedField<int>();
+ /// <summary>
+ /// Identifies the element in the original source .proto file. This field
+ /// is formatted the same as SourceCodeInfo.Location.path.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<int> Path {
+ get { return path_; }
+ }
+
+ /// <summary>Field number for the "source_file" field.</summary>
+ public const int SourceFileFieldNumber = 2;
+ private string sourceFile_ = "";
+ /// <summary>
+ /// Identifies the filesystem path to the original source .proto.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string SourceFile {
+ get { return sourceFile_; }
+ set {
+ sourceFile_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "begin" field.</summary>
+ public const int BeginFieldNumber = 3;
+ private int begin_;
+ /// <summary>
+ /// Identifies the starting offset in bytes in the generated code
+ /// that relates to the identified object.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Begin {
+ get { return begin_; }
+ set {
+ begin_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "end" field.</summary>
+ public const int EndFieldNumber = 4;
+ private int end_;
+ /// <summary>
+ /// Identifies the ending offset in bytes in the generated code that
+ /// relates to the identified offset. The end offset should be one past
+ /// the last relevant byte (so the length of the text = end - begin).
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int End {
+ get { return end_; }
+ set {
+ end_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Annotation);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Annotation other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if(!path_.Equals(other.path_)) return false;
+ if (SourceFile != other.SourceFile) return false;
+ if (Begin != other.Begin) return false;
+ if (End != other.End) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= path_.GetHashCode();
+ if (SourceFile.Length != 0) hash ^= SourceFile.GetHashCode();
+ if (Begin != 0) hash ^= Begin.GetHashCode();
+ if (End != 0) hash ^= End.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ path_.WriteTo(output, _repeated_path_codec);
+ if (SourceFile.Length != 0) {
+ output.WriteRawTag(18);
+ output.WriteString(SourceFile);
+ }
+ if (Begin != 0) {
+ output.WriteRawTag(24);
+ output.WriteInt32(Begin);
+ }
+ if (End != 0) {
+ output.WriteRawTag(32);
+ output.WriteInt32(End);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += path_.CalculateSize(_repeated_path_codec);
+ if (SourceFile.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(SourceFile);
+ }
+ if (Begin != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Begin);
+ }
+ if (End != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(End);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Annotation other) {
+ if (other == null) {
+ return;
+ }
+ path_.Add(other.path_);
+ if (other.SourceFile.Length != 0) {
+ SourceFile = other.SourceFile;
+ }
+ if (other.Begin != 0) {
+ Begin = other.Begin;
+ }
+ if (other.End != 0) {
+ End = other.End;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10:
+ case 8: {
+ path_.AddEntriesFrom(input, _repeated_path_codec);
+ break;
+ }
+ case 18: {
+ SourceFile = input.ReadString();
+ break;
+ }
+ case 24: {
+ Begin = input.ReadInt32();
+ break;
+ }
+ case 32: {
+ End = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ }
+ #endregion
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorBase.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorBase.cs
new file mode 100644
index 0000000000..194041a889
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorBase.cs
@@ -0,0 +1,85 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Base class for nearly all descriptors, providing common functionality.
+ /// </summary>
+ public abstract class DescriptorBase : IDescriptor
+ {
+ private readonly FileDescriptor file;
+ private readonly string fullName;
+ private readonly int index;
+
+ internal DescriptorBase(FileDescriptor file, string fullName, int index)
+ {
+ this.file = file;
+ this.fullName = fullName;
+ this.index = index;
+ }
+
+ /// <value>
+ /// The index of this descriptor within its parent descriptor.
+ /// </value>
+ /// <remarks>
+ /// This returns the index of this descriptor within its parent, for
+ /// this descriptor's type. (There can be duplicate values for different
+ /// types, e.g. one enum type with index 0 and one message type with index 0.)
+ /// </remarks>
+ public int Index
+ {
+ get { return index; }
+ }
+
+ /// <summary>
+ /// Returns the name of the entity (field, message etc) being described.
+ /// </summary>
+ public abstract string Name { get; }
+
+ /// <summary>
+ /// The fully qualified name of the descriptor's target.
+ /// </summary>
+ public string FullName
+ {
+ get { return fullName; }
+ }
+
+ /// <value>
+ /// The file this descriptor was declared in.
+ /// </value>
+ public FileDescriptor File
+ {
+ get { return file; }
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs
new file mode 100644
index 0000000000..99ca4bf34f
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorPool.cs
@@ -0,0 +1,368 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Text.RegularExpressions;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Contains lookup tables containing all the descriptors defined in a particular file.
+ /// </summary>
+ internal sealed class DescriptorPool
+ {
+ private readonly IDictionary<string, IDescriptor> descriptorsByName =
+ new Dictionary<string, IDescriptor>();
+
+ private readonly IDictionary<DescriptorIntPair, FieldDescriptor> fieldsByNumber =
+ new Dictionary<DescriptorIntPair, FieldDescriptor>();
+
+ private readonly IDictionary<DescriptorIntPair, EnumValueDescriptor> enumValuesByNumber =
+ new Dictionary<DescriptorIntPair, EnumValueDescriptor>();
+
+ private readonly HashSet<FileDescriptor> dependencies;
+
+ internal DescriptorPool(FileDescriptor[] dependencyFiles)
+ {
+ dependencies = new HashSet<FileDescriptor>();
+ for (int i = 0; i < dependencyFiles.Length; i++)
+ {
+ dependencies.Add(dependencyFiles[i]);
+ ImportPublicDependencies(dependencyFiles[i]);
+ }
+
+ foreach (FileDescriptor dependency in dependencyFiles)
+ {
+ AddPackage(dependency.Package, dependency);
+ }
+ }
+
+ private void ImportPublicDependencies(FileDescriptor file)
+ {
+ foreach (FileDescriptor dependency in file.PublicDependencies)
+ {
+ if (dependencies.Add(dependency))
+ {
+ ImportPublicDependencies(dependency);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Finds a symbol of the given name within the pool.
+ /// </summary>
+ /// <typeparam name="T">The type of symbol to look for</typeparam>
+ /// <param name="fullName">Fully-qualified name to look up</param>
+ /// <returns>The symbol with the given name and type,
+ /// or null if the symbol doesn't exist or has the wrong type</returns>
+ internal T FindSymbol<T>(string fullName) where T : class
+ {
+ IDescriptor result;
+ descriptorsByName.TryGetValue(fullName, out result);
+ T descriptor = result as T;
+ if (descriptor != null)
+ {
+ return descriptor;
+ }
+
+ // dependencies contains direct dependencies and any *public* dependencies
+ // of those dependencies (transitively)... so we don't need to recurse here.
+ foreach (FileDescriptor dependency in dependencies)
+ {
+ dependency.DescriptorPool.descriptorsByName.TryGetValue(fullName, out result);
+ descriptor = result as T;
+ if (descriptor != null)
+ {
+ return descriptor;
+ }
+ }
+
+ return null;
+ }
+
+ /// <summary>
+ /// Adds a package to the symbol tables. If a package by the same name
+ /// already exists, that is fine, but if some other kind of symbol
+ /// exists under the same name, an exception is thrown. If the package
+ /// has multiple components, this also adds the parent package(s).
+ /// </summary>
+ internal void AddPackage(string fullName, FileDescriptor file)
+ {
+ int dotpos = fullName.LastIndexOf('.');
+ String name;
+ if (dotpos != -1)
+ {
+ AddPackage(fullName.Substring(0, dotpos), file);
+ name = fullName.Substring(dotpos + 1);
+ }
+ else
+ {
+ name = fullName;
+ }
+
+ IDescriptor old;
+ if (descriptorsByName.TryGetValue(fullName, out old))
+ {
+ if (!(old is PackageDescriptor))
+ {
+ throw new DescriptorValidationException(file,
+ "\"" + name +
+ "\" is already defined (as something other than a " +
+ "package) in file \"" + old.File.Name + "\".");
+ }
+ }
+ descriptorsByName[fullName] = new PackageDescriptor(name, fullName, file);
+ }
+
+ /// <summary>
+ /// Adds a symbol to the symbol table.
+ /// </summary>
+ /// <exception cref="DescriptorValidationException">The symbol already existed
+ /// in the symbol table.</exception>
+ internal void AddSymbol(IDescriptor descriptor)
+ {
+ ValidateSymbolName(descriptor);
+ String fullName = descriptor.FullName;
+
+ IDescriptor old;
+ if (descriptorsByName.TryGetValue(fullName, out old))
+ {
+ int dotPos = fullName.LastIndexOf('.');
+ string message;
+ if (descriptor.File == old.File)
+ {
+ if (dotPos == -1)
+ {
+ message = "\"" + fullName + "\" is already defined.";
+ }
+ else
+ {
+ message = "\"" + fullName.Substring(dotPos + 1) + "\" is already defined in \"" +
+ fullName.Substring(0, dotPos) + "\".";
+ }
+ }
+ else
+ {
+ message = "\"" + fullName + "\" is already defined in file \"" + old.File.Name + "\".";
+ }
+ throw new DescriptorValidationException(descriptor, message);
+ }
+ descriptorsByName[fullName] = descriptor;
+ }
+
+ private static readonly Regex ValidationRegex = new Regex("^[_A-Za-z][_A-Za-z0-9]*$",
+ FrameworkPortability.CompiledRegexWhereAvailable);
+
+ /// <summary>
+ /// Verifies that the descriptor's name is valid (i.e. it contains
+ /// only letters, digits and underscores, and does not start with a digit).
+ /// </summary>
+ /// <param name="descriptor"></param>
+ private static void ValidateSymbolName(IDescriptor descriptor)
+ {
+ if (descriptor.Name == "")
+ {
+ throw new DescriptorValidationException(descriptor, "Missing name.");
+ }
+ if (!ValidationRegex.IsMatch(descriptor.Name))
+ {
+ throw new DescriptorValidationException(descriptor,
+ "\"" + descriptor.Name + "\" is not a valid identifier.");
+ }
+ }
+
+ /// <summary>
+ /// Returns the field with the given number in the given descriptor,
+ /// or null if it can't be found.
+ /// </summary>
+ internal FieldDescriptor FindFieldByNumber(MessageDescriptor messageDescriptor, int number)
+ {
+ FieldDescriptor ret;
+ fieldsByNumber.TryGetValue(new DescriptorIntPair(messageDescriptor, number), out ret);
+ return ret;
+ }
+
+ internal EnumValueDescriptor FindEnumValueByNumber(EnumDescriptor enumDescriptor, int number)
+ {
+ EnumValueDescriptor ret;
+ enumValuesByNumber.TryGetValue(new DescriptorIntPair(enumDescriptor, number), out ret);
+ return ret;
+ }
+
+ /// <summary>
+ /// Adds a field to the fieldsByNumber table.
+ /// </summary>
+ /// <exception cref="DescriptorValidationException">A field with the same
+ /// containing type and number already exists.</exception>
+ internal void AddFieldByNumber(FieldDescriptor field)
+ {
+ DescriptorIntPair key = new DescriptorIntPair(field.ContainingType, field.FieldNumber);
+ FieldDescriptor old;
+ if (fieldsByNumber.TryGetValue(key, out old))
+ {
+ throw new DescriptorValidationException(field, "Field number " + field.FieldNumber +
+ "has already been used in \"" +
+ field.ContainingType.FullName +
+ "\" by field \"" + old.Name + "\".");
+ }
+ fieldsByNumber[key] = field;
+ }
+
+ /// <summary>
+ /// Adds an enum value to the enumValuesByNumber table. If an enum value
+ /// with the same type and number already exists, this method does nothing.
+ /// (This is allowed; the first value defined with the number takes precedence.)
+ /// </summary>
+ internal void AddEnumValueByNumber(EnumValueDescriptor enumValue)
+ {
+ DescriptorIntPair key = new DescriptorIntPair(enumValue.EnumDescriptor, enumValue.Number);
+ if (!enumValuesByNumber.ContainsKey(key))
+ {
+ enumValuesByNumber[key] = enumValue;
+ }
+ }
+
+ /// <summary>
+ /// Looks up a descriptor by name, relative to some other descriptor.
+ /// The name may be fully-qualified (with a leading '.'), partially-qualified,
+ /// or unqualified. C++-like name lookup semantics are used to search for the
+ /// matching descriptor.
+ /// </summary>
+ /// <remarks>
+ /// This isn't heavily optimized, but it's only used during cross linking anyway.
+ /// If it starts being used more widely, we should look at performance more carefully.
+ /// </remarks>
+ internal IDescriptor LookupSymbol(string name, IDescriptor relativeTo)
+ {
+ IDescriptor result;
+ if (name.StartsWith("."))
+ {
+ // Fully-qualified name.
+ result = FindSymbol<IDescriptor>(name.Substring(1));
+ }
+ else
+ {
+ // If "name" is a compound identifier, we want to search for the
+ // first component of it, then search within it for the rest.
+ int firstPartLength = name.IndexOf('.');
+ string firstPart = firstPartLength == -1 ? name : name.Substring(0, firstPartLength);
+
+ // We will search each parent scope of "relativeTo" looking for the
+ // symbol.
+ StringBuilder scopeToTry = new StringBuilder(relativeTo.FullName);
+
+ while (true)
+ {
+ // Chop off the last component of the scope.
+
+ int dotpos = scopeToTry.ToString().LastIndexOf(".");
+ if (dotpos == -1)
+ {
+ result = FindSymbol<IDescriptor>(name);
+ break;
+ }
+ else
+ {
+ scopeToTry.Length = dotpos + 1;
+
+ // Append firstPart and try to find.
+ scopeToTry.Append(firstPart);
+ result = FindSymbol<IDescriptor>(scopeToTry.ToString());
+
+ if (result != null)
+ {
+ if (firstPartLength != -1)
+ {
+ // We only found the first part of the symbol. Now look for
+ // the whole thing. If this fails, we *don't* want to keep
+ // searching parent scopes.
+ scopeToTry.Length = dotpos + 1;
+ scopeToTry.Append(name);
+ result = FindSymbol<IDescriptor>(scopeToTry.ToString());
+ }
+ break;
+ }
+
+ // Not found. Remove the name so we can try again.
+ scopeToTry.Length = dotpos;
+ }
+ }
+ }
+
+ if (result == null)
+ {
+ throw new DescriptorValidationException(relativeTo, "\"" + name + "\" is not defined.");
+ }
+ else
+ {
+ return result;
+ }
+ }
+
+ /// <summary>
+ /// Struct used to hold the keys for the fieldByNumber table.
+ /// </summary>
+ private struct DescriptorIntPair : IEquatable<DescriptorIntPair>
+ {
+ private readonly int number;
+ private readonly IDescriptor descriptor;
+
+ internal DescriptorIntPair(IDescriptor descriptor, int number)
+ {
+ this.number = number;
+ this.descriptor = descriptor;
+ }
+
+ public bool Equals(DescriptorIntPair other)
+ {
+ return descriptor == other.descriptor
+ && number == other.number;
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (obj is DescriptorIntPair)
+ {
+ return Equals((DescriptorIntPair) obj);
+ }
+ return false;
+ }
+
+ public override int GetHashCode()
+ {
+ return descriptor.GetHashCode()*((1 << 16) - 1) + number;
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorUtil.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorUtil.cs
new file mode 100644
index 0000000000..f5570fc40a
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorUtil.cs
@@ -0,0 +1,64 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Internal class containing utility methods when working with descriptors.
+ /// </summary>
+ internal static class DescriptorUtil
+ {
+ /// <summary>
+ /// Equivalent to Func[TInput, int, TOutput] but usable in .NET 2.0. Only used to convert
+ /// arrays.
+ /// </summary>
+ internal delegate TOutput IndexedConverter<TInput, TOutput>(TInput element, int index);
+
+ /// <summary>
+ /// Converts the given array into a read-only list, applying the specified conversion to
+ /// each input element.
+ /// </summary>
+ internal static IList<TOutput> ConvertAndMakeReadOnly<TInput, TOutput>
+ (IList<TInput> input, IndexedConverter<TInput, TOutput> converter)
+ {
+ TOutput[] array = new TOutput[input.Count];
+ for (int i = 0; i < array.Length; i++)
+ {
+ array[i] = converter(input[i], i);
+ }
+ return new ReadOnlyCollection<TOutput>(array);
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorValidationException.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorValidationException.cs
new file mode 100644
index 0000000000..143671dbd4
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/DescriptorValidationException.cs
@@ -0,0 +1,80 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Thrown when building descriptors fails because the source DescriptorProtos
+ /// are not valid.
+ /// </summary>
+ public sealed class DescriptorValidationException : Exception
+ {
+ private readonly String name;
+ private readonly string description;
+
+ /// <value>
+ /// The full name of the descriptor where the error occurred.
+ /// </value>
+ public String ProblemSymbolName
+ {
+ get { return name; }
+ }
+
+ /// <value>
+ /// A human-readable description of the error. (The Message property
+ /// is made up of the descriptor's name and this description.)
+ /// </value>
+ public string Description
+ {
+ get { return description; }
+ }
+
+ internal DescriptorValidationException(IDescriptor problemDescriptor, string description) :
+ base(problemDescriptor.FullName + ": " + description)
+ {
+ // Note that problemDescriptor may be partially uninitialized, so we
+ // don't want to expose it directly to the user. So, we only provide
+ // the name and the original proto.
+ name = problemDescriptor.FullName;
+ this.description = description;
+ }
+
+ internal DescriptorValidationException(IDescriptor problemDescriptor, string description, Exception cause) :
+ base(problemDescriptor.FullName + ": " + description, cause)
+ {
+ name = problemDescriptor.FullName;
+ this.description = description;
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs
new file mode 100644
index 0000000000..89c73a61b2
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs
@@ -0,0 +1,121 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.Collections.Generic;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Descriptor for an enum type in a .proto file.
+ /// </summary>
+ public sealed class EnumDescriptor : DescriptorBase
+ {
+ private readonly EnumDescriptorProto proto;
+ private readonly MessageDescriptor containingType;
+ private readonly IList<EnumValueDescriptor> values;
+ private readonly Type clrType;
+
+ internal EnumDescriptor(EnumDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, Type clrType)
+ : base(file, file.ComputeFullName(parent, proto.Name), index)
+ {
+ this.proto = proto;
+ this.clrType = clrType;
+ containingType = parent;
+
+ if (proto.Value.Count == 0)
+ {
+ // We cannot allow enums with no values because this would mean there
+ // would be no valid default value for fields of this type.
+ throw new DescriptorValidationException(this, "Enums must contain at least one value.");
+ }
+
+ values = DescriptorUtil.ConvertAndMakeReadOnly(proto.Value,
+ (value, i) => new EnumValueDescriptor(value, file, this, i));
+
+ File.DescriptorPool.AddSymbol(this);
+ }
+
+ internal EnumDescriptorProto Proto { get { return proto; } }
+
+ /// <summary>
+ /// The brief name of the descriptor's target.
+ /// </summary>
+ public override string Name { get { return proto.Name; } }
+
+ /// <summary>
+ /// The CLR type for this enum. For generated code, this will be a CLR enum type.
+ /// </summary>
+ public Type ClrType { get { return clrType; } }
+
+ /// <value>
+ /// If this is a nested type, get the outer descriptor, otherwise null.
+ /// </value>
+ public MessageDescriptor ContainingType
+ {
+ get { return containingType; }
+ }
+
+ /// <value>
+ /// An unmodifiable list of defined value descriptors for this enum.
+ /// </value>
+ public IList<EnumValueDescriptor> Values
+ {
+ get { return values; }
+ }
+
+ /// <summary>
+ /// Finds an enum value by number. If multiple enum values have the
+ /// same number, this returns the first defined value with that number.
+ /// If there is no value for the given number, this returns <c>null</c>.
+ /// </summary>
+ public EnumValueDescriptor FindValueByNumber(int number)
+ {
+ return File.DescriptorPool.FindEnumValueByNumber(this, number);
+ }
+
+ /// <summary>
+ /// Finds an enum value by name.
+ /// </summary>
+ /// <param name="name">The unqualified name of the value (e.g. "FOO").</param>
+ /// <returns>The value's descriptor, or null if not found.</returns>
+ public EnumValueDescriptor FindValueByName(string name)
+ {
+ return File.DescriptorPool.FindSymbol<EnumValueDescriptor>(FullName + "." + name);
+ }
+
+ /// <summary>
+ /// The (possibly empty) set of custom options for this enum.
+ /// </summary>
+ public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs
new file mode 100644
index 0000000000..8b838c68f0
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs
@@ -0,0 +1,75 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Descriptor for a single enum value within an enum in a .proto file.
+ /// </summary>
+ public sealed class EnumValueDescriptor : DescriptorBase
+ {
+ private readonly EnumDescriptor enumDescriptor;
+ private readonly EnumValueDescriptorProto proto;
+
+ internal EnumValueDescriptor(EnumValueDescriptorProto proto, FileDescriptor file,
+ EnumDescriptor parent, int index)
+ : base(file, parent.FullName + "." + proto.Name, index)
+ {
+ this.proto = proto;
+ enumDescriptor = parent;
+ file.DescriptorPool.AddSymbol(this);
+ file.DescriptorPool.AddEnumValueByNumber(this);
+ }
+
+ internal EnumValueDescriptorProto Proto { get { return proto; } }
+
+ /// <summary>
+ /// Returns the name of the enum value described by this object.
+ /// </summary>
+ public override string Name { get { return proto.Name; } }
+
+ /// <summary>
+ /// Returns the number associated with this enum value.
+ /// </summary>
+ public int Number { get { return Proto.Number; } }
+
+ /// <summary>
+ /// Returns the enum descriptor that this value is part of.
+ /// </summary>
+ public EnumDescriptor EnumDescriptor { get { return enumDescriptor; } }
+
+ /// <summary>
+ /// The (possibly empty) set of custom options for this enum value.
+ /// </summary>
+ public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/FieldAccessorBase.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/FieldAccessorBase.cs
new file mode 100644
index 0000000000..82ce50518d
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/FieldAccessorBase.cs
@@ -0,0 +1,63 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.Reflection;
+using Google.Protobuf.Compatibility;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Base class for field accessors.
+ /// </summary>
+ internal abstract class FieldAccessorBase : IFieldAccessor
+ {
+ private readonly Func<IMessage, object> getValueDelegate;
+ private readonly FieldDescriptor descriptor;
+
+ internal FieldAccessorBase(PropertyInfo property, FieldDescriptor descriptor)
+ {
+ this.descriptor = descriptor;
+ getValueDelegate = ReflectionUtil.CreateFuncIMessageObject(property.GetGetMethod());
+ }
+
+ public FieldDescriptor Descriptor { get { return descriptor; } }
+
+ public object GetValue(IMessage message)
+ {
+ return getValueDelegate(message);
+ }
+
+ public abstract void Clear(IMessage message);
+ public abstract void SetValue(IMessage message, object value);
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
new file mode 100644
index 0000000000..2a3d5c7a2d
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
@@ -0,0 +1,348 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using Google.Protobuf.Compatibility;
+using System;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Descriptor for a field or extension within a message in a .proto file.
+ /// </summary>
+ public sealed class FieldDescriptor : DescriptorBase, IComparable<FieldDescriptor>
+ {
+ private EnumDescriptor enumType;
+ private MessageDescriptor messageType;
+ private FieldType fieldType;
+ private readonly string propertyName; // Annoyingly, needed in Crosslink.
+ private IFieldAccessor accessor;
+
+ /// <summary>
+ /// Get the field's containing message type.
+ /// </summary>
+ public MessageDescriptor ContainingType { get; }
+
+ /// <summary>
+ /// Returns the oneof containing this field, or <c>null</c> if it is not part of a oneof.
+ /// </summary>
+ public OneofDescriptor ContainingOneof { get; }
+
+ /// <summary>
+ /// The effective JSON name for this field. This is usually the lower-camel-cased form of the field name,
+ /// but can be overridden using the <c>json_name</c> option in the .proto file.
+ /// </summary>
+ public string JsonName { get; }
+
+ internal FieldDescriptorProto Proto { get; }
+
+ internal FieldDescriptor(FieldDescriptorProto proto, FileDescriptor file,
+ MessageDescriptor parent, int index, string propertyName)
+ : base(file, file.ComputeFullName(parent, proto.Name), index)
+ {
+ Proto = proto;
+ if (proto.Type != 0)
+ {
+ fieldType = GetFieldTypeFromProtoType(proto.Type);
+ }
+
+ if (FieldNumber <= 0)
+ {
+ throw new DescriptorValidationException(this, "Field numbers must be positive integers.");
+ }
+ ContainingType = parent;
+ // OneofIndex "defaults" to -1 due to a hack in FieldDescriptor.OnConstruction.
+ if (proto.OneofIndex != -1)
+ {
+ if (proto.OneofIndex < 0 || proto.OneofIndex >= parent.Proto.OneofDecl.Count)
+ {
+ throw new DescriptorValidationException(this,
+ $"FieldDescriptorProto.oneof_index is out of range for type {parent.Name}");
+ }
+ ContainingOneof = parent.Oneofs[proto.OneofIndex];
+ }
+
+ file.DescriptorPool.AddSymbol(this);
+ // We can't create the accessor until we've cross-linked, unfortunately, as we
+ // may not know whether the type of the field is a map or not. Remember the property name
+ // for later.
+ // We could trust the generated code and check whether the type of the property is
+ // a MapField, but that feels a tad nasty.
+ this.propertyName = propertyName;
+ JsonName = Proto.JsonName == "" ? JsonFormatter.ToJsonName(Proto.Name) : Proto.JsonName;
+ }
+
+
+ /// <summary>
+ /// The brief name of the descriptor's target.
+ /// </summary>
+ public override string Name => Proto.Name;
+
+ /// <summary>
+ /// Returns the accessor for this field.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// While a <see cref="FieldDescriptor"/> describes the field, it does not provide
+ /// any way of obtaining or changing the value of the field within a specific message;
+ /// that is the responsibility of the accessor.
+ /// </para>
+ /// <para>
+ /// The value returned by this property will be non-null for all regular fields. However,
+ /// if a message containing a map field is introspected, the list of nested messages will include
+ /// an auto-generated nested key/value pair message for the field. This is not represented in any
+ /// generated type, and the value of the map field itself is represented by a dictionary in the
+ /// reflection API. There are never instances of those "hidden" messages, so no accessor is provided
+ /// and this property will return null.
+ /// </para>
+ /// </remarks>
+ public IFieldAccessor Accessor => accessor;
+
+ /// <summary>
+ /// Maps a field type as included in the .proto file to a FieldType.
+ /// </summary>
+ private static FieldType GetFieldTypeFromProtoType(FieldDescriptorProto.Types.Type type)
+ {
+ switch (type)
+ {
+ case FieldDescriptorProto.Types.Type.Double:
+ return FieldType.Double;
+ case FieldDescriptorProto.Types.Type.Float:
+ return FieldType.Float;
+ case FieldDescriptorProto.Types.Type.Int64:
+ return FieldType.Int64;
+ case FieldDescriptorProto.Types.Type.Uint64:
+ return FieldType.UInt64;
+ case FieldDescriptorProto.Types.Type.Int32:
+ return FieldType.Int32;
+ case FieldDescriptorProto.Types.Type.Fixed64:
+ return FieldType.Fixed64;
+ case FieldDescriptorProto.Types.Type.Fixed32:
+ return FieldType.Fixed32;
+ case FieldDescriptorProto.Types.Type.Bool:
+ return FieldType.Bool;
+ case FieldDescriptorProto.Types.Type.String:
+ return FieldType.String;
+ case FieldDescriptorProto.Types.Type.Group:
+ return FieldType.Group;
+ case FieldDescriptorProto.Types.Type.Message:
+ return FieldType.Message;
+ case FieldDescriptorProto.Types.Type.Bytes:
+ return FieldType.Bytes;
+ case FieldDescriptorProto.Types.Type.Uint32:
+ return FieldType.UInt32;
+ case FieldDescriptorProto.Types.Type.Enum:
+ return FieldType.Enum;
+ case FieldDescriptorProto.Types.Type.Sfixed32:
+ return FieldType.SFixed32;
+ case FieldDescriptorProto.Types.Type.Sfixed64:
+ return FieldType.SFixed64;
+ case FieldDescriptorProto.Types.Type.Sint32:
+ return FieldType.SInt32;
+ case FieldDescriptorProto.Types.Type.Sint64:
+ return FieldType.SInt64;
+ default:
+ throw new ArgumentException("Invalid type specified");
+ }
+ }
+
+ /// <summary>
+ /// Returns <c>true</c> if this field is a repeated field; <c>false</c> otherwise.
+ /// </summary>
+ public bool IsRepeated => Proto.Label == FieldDescriptorProto.Types.Label.Repeated;
+
+ /// <summary>
+ /// Returns <c>true</c> if this field is a map field; <c>false</c> otherwise.
+ /// </summary>
+ public bool IsMap => fieldType == FieldType.Message && messageType.Proto.Options != null && messageType.Proto.Options.MapEntry;
+
+ /// <summary>
+ /// Returns <c>true</c> if this field is a packed, repeated field; <c>false</c> otherwise.
+ /// </summary>
+ public bool IsPacked =>
+ // Note the || rather than && here - we're effectively defaulting to packed, because that *is*
+ // the default in proto3, which is all we support. We may give the wrong result for the protos
+ // within descriptor.proto, but that's okay, as they're never exposed and we don't use IsPacked
+ // within the runtime.
+ Proto.Options == null || Proto.Options.Packed;
+
+ /// <summary>
+ /// Returns the type of the field.
+ /// </summary>
+ public FieldType FieldType => fieldType;
+
+ /// <summary>
+ /// Returns the field number declared in the proto file.
+ /// </summary>
+ public int FieldNumber => Proto.Number;
+
+ /// <summary>
+ /// Compares this descriptor with another one, ordering in "canonical" order
+ /// which simply means ascending order by field number. <paramref name="other"/>
+ /// must be a field of the same type, i.e. the <see cref="ContainingType"/> of
+ /// both fields must be the same.
+ /// </summary>
+ public int CompareTo(FieldDescriptor other)
+ {
+ if (other.ContainingType != ContainingType)
+ {
+ throw new ArgumentException("FieldDescriptors can only be compared to other FieldDescriptors " +
+ "for fields of the same message type.");
+ }
+ return FieldNumber - other.FieldNumber;
+ }
+
+ /// <summary>
+ /// For enum fields, returns the field's type.
+ /// </summary>
+ public EnumDescriptor EnumType
+ {
+ get
+ {
+ if (fieldType != FieldType.Enum)
+ {
+ throw new InvalidOperationException("EnumType is only valid for enum fields.");
+ }
+ return enumType;
+ }
+ }
+
+ /// <summary>
+ /// For embedded message and group fields, returns the field's type.
+ /// </summary>
+ public MessageDescriptor MessageType
+ {
+ get
+ {
+ if (fieldType != FieldType.Message)
+ {
+ throw new InvalidOperationException("MessageType is only valid for message fields.");
+ }
+ return messageType;
+ }
+ }
+
+ /// <summary>
+ /// The (possibly empty) set of custom options for this field.
+ /// </summary>
+ public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
+
+ /// <summary>
+ /// Look up and cross-link all field types etc.
+ /// </summary>
+ internal void CrossLink()
+ {
+ if (Proto.TypeName != "")
+ {
+ IDescriptor typeDescriptor =
+ File.DescriptorPool.LookupSymbol(Proto.TypeName, this);
+
+ if (Proto.Type != 0)
+ {
+ // Choose field type based on symbol.
+ if (typeDescriptor is MessageDescriptor)
+ {
+ fieldType = FieldType.Message;
+ }
+ else if (typeDescriptor is EnumDescriptor)
+ {
+ fieldType = FieldType.Enum;
+ }
+ else
+ {
+ throw new DescriptorValidationException(this, $"\"{Proto.TypeName}\" is not a type.");
+ }
+ }
+
+ if (fieldType == FieldType.Message)
+ {
+ if (!(typeDescriptor is MessageDescriptor))
+ {
+ throw new DescriptorValidationException(this, $"\"{Proto.TypeName}\" is not a message type.");
+ }
+ messageType = (MessageDescriptor) typeDescriptor;
+
+ if (Proto.DefaultValue != "")
+ {
+ throw new DescriptorValidationException(this, "Messages can't have default values.");
+ }
+ }
+ else if (fieldType == FieldType.Enum)
+ {
+ if (!(typeDescriptor is EnumDescriptor))
+ {
+ throw new DescriptorValidationException(this, $"\"{Proto.TypeName}\" is not an enum type.");
+ }
+ enumType = (EnumDescriptor) typeDescriptor;
+ }
+ else
+ {
+ throw new DescriptorValidationException(this, "Field with primitive type has type_name.");
+ }
+ }
+ else
+ {
+ if (fieldType == FieldType.Message || fieldType == FieldType.Enum)
+ {
+ throw new DescriptorValidationException(this, "Field with message or enum type missing type_name.");
+ }
+ }
+
+ // Note: no attempt to perform any default value parsing
+
+ File.DescriptorPool.AddFieldByNumber(this);
+
+ if (ContainingType != null && ContainingType.Proto.Options != null && ContainingType.Proto.Options.MessageSetWireFormat)
+ {
+ throw new DescriptorValidationException(this, "MessageSet format is not supported.");
+ }
+ accessor = CreateAccessor();
+ }
+
+ private IFieldAccessor CreateAccessor()
+ {
+ // If we're given no property name, that's because we really don't want an accessor.
+ // (At the moment, that means it's a map entry message...)
+ if (propertyName == null)
+ {
+ return null;
+ }
+ var property = ContainingType.ClrType.GetProperty(propertyName);
+ if (property == null)
+ {
+ throw new DescriptorValidationException(this, $"Property {propertyName} not found in {ContainingType.ClrType}");
+ }
+ return IsMap ? new MapFieldAccessor(property, this)
+ : IsRepeated ? new RepeatedFieldAccessor(property, this)
+ : (IFieldAccessor) new SingleFieldAccessor(property, this);
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/FieldType.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/FieldType.cs
new file mode 100644
index 0000000000..1658e34cd1
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/FieldType.cs
@@ -0,0 +1,113 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Enumeration of all the possible field types.
+ /// </summary>
+ public enum FieldType
+ {
+ /// <summary>
+ /// The <c>double</c> field type.
+ /// </summary>
+ Double,
+ /// <summary>
+ /// The <c>float</c> field type.
+ /// </summary>
+ Float,
+ /// <summary>
+ /// The <c>int64</c> field type.
+ /// </summary>
+ Int64,
+ /// <summary>
+ /// The <c>uint64</c> field type.
+ /// </summary>
+ UInt64,
+ /// <summary>
+ /// The <c>int32</c> field type.
+ /// </summary>
+ Int32,
+ /// <summary>
+ /// The <c>fixed64</c> field type.
+ /// </summary>
+ Fixed64,
+ /// <summary>
+ /// The <c>fixed32</c> field type.
+ /// </summary>
+ Fixed32,
+ /// <summary>
+ /// The <c>bool</c> field type.
+ /// </summary>
+ Bool,
+ /// <summary>
+ /// The <c>string</c> field type.
+ /// </summary>
+ String,
+ /// <summary>
+ /// The field type used for groups (not supported in this implementation).
+ /// </summary>
+ Group,
+ /// <summary>
+ /// The field type used for message fields.
+ /// </summary>
+ Message,
+ /// <summary>
+ /// The <c>bytes</c> field type.
+ /// </summary>
+ Bytes,
+ /// <summary>
+ /// The <c>uint32</c> field type.
+ /// </summary>
+ UInt32,
+ /// <summary>
+ /// The <c>sfixed32</c> field type.
+ /// </summary>
+ SFixed32,
+ /// <summary>
+ /// The <c>sfixed64</c> field type.
+ /// </summary>
+ SFixed64,
+ /// <summary>
+ /// The <c>sint32</c> field type.
+ /// </summary>
+ SInt32,
+ /// <summary>
+ /// The <c>sint64</c> field type.
+ /// </summary>
+ SInt64,
+ /// <summary>
+ /// The field type used for enum fields.
+ /// </summary>
+ Enum
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
new file mode 100644
index 0000000000..9124beee04
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
@@ -0,0 +1,338 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Describes a .proto file, including everything defined within.
+ /// IDescriptor is implemented such that the File property returns this descriptor,
+ /// and the FullName is the same as the Name.
+ /// </summary>
+ public sealed class FileDescriptor : IDescriptor
+ {
+ private FileDescriptor(ByteString descriptorData, FileDescriptorProto proto, FileDescriptor[] dependencies, DescriptorPool pool, bool allowUnknownDependencies, GeneratedClrTypeInfo generatedCodeInfo)
+ {
+ SerializedData = descriptorData;
+ DescriptorPool = pool;
+ Proto = proto;
+ Dependencies = new ReadOnlyCollection<FileDescriptor>((FileDescriptor[]) dependencies.Clone());
+
+ PublicDependencies = DeterminePublicDependencies(this, proto, dependencies, allowUnknownDependencies);
+
+ pool.AddPackage(Package, this);
+
+ MessageTypes = DescriptorUtil.ConvertAndMakeReadOnly(proto.MessageType,
+ (message, index) =>
+ new MessageDescriptor(message, this, null, index, generatedCodeInfo.NestedTypes[index]));
+
+ EnumTypes = DescriptorUtil.ConvertAndMakeReadOnly(proto.EnumType,
+ (enumType, index) =>
+ new EnumDescriptor(enumType, this, null, index, generatedCodeInfo.NestedEnums[index]));
+
+ Services = DescriptorUtil.ConvertAndMakeReadOnly(proto.Service,
+ (service, index) =>
+ new ServiceDescriptor(service, this, index));
+ }
+
+ /// <summary>
+ /// Computes the full name of a descriptor within this file, with an optional parent message.
+ /// </summary>
+ internal string ComputeFullName(MessageDescriptor parent, string name)
+ {
+ if (parent != null)
+ {
+ return parent.FullName + "." + name;
+ }
+ if (Package.Length > 0)
+ {
+ return Package + "." + name;
+ }
+ return name;
+ }
+
+ /// <summary>
+ /// Extracts public dependencies from direct dependencies. This is a static method despite its
+ /// first parameter, as the value we're in the middle of constructing is only used for exceptions.
+ /// </summary>
+ private static IList<FileDescriptor> DeterminePublicDependencies(FileDescriptor @this, FileDescriptorProto proto, FileDescriptor[] dependencies, bool allowUnknownDependencies)
+ {
+ var nameToFileMap = new Dictionary<string, FileDescriptor>();
+ foreach (var file in dependencies)
+ {
+ nameToFileMap[file.Name] = file;
+ }
+ var publicDependencies = new List<FileDescriptor>();
+ for (int i = 0; i < proto.PublicDependency.Count; i++)
+ {
+ int index = proto.PublicDependency[i];
+ if (index < 0 || index >= proto.Dependency.Count)
+ {
+ throw new DescriptorValidationException(@this, "Invalid public dependency index.");
+ }
+ string name = proto.Dependency[index];
+ FileDescriptor file = nameToFileMap[name];
+ if (file == null)
+ {
+ if (!allowUnknownDependencies)
+ {
+ throw new DescriptorValidationException(@this, "Invalid public dependency: " + name);
+ }
+ // Ignore unknown dependencies.
+ }
+ else
+ {
+ publicDependencies.Add(file);
+ }
+ }
+ return new ReadOnlyCollection<FileDescriptor>(publicDependencies);
+ }
+
+ /// <value>
+ /// The descriptor in its protocol message representation.
+ /// </value>
+ internal FileDescriptorProto Proto { get; }
+
+ /// <value>
+ /// The file name.
+ /// </value>
+ public string Name => Proto.Name;
+
+ /// <summary>
+ /// The package as declared in the .proto file. This may or may not
+ /// be equivalent to the .NET namespace of the generated classes.
+ /// </summary>
+ public string Package => Proto.Package;
+
+ /// <value>
+ /// Unmodifiable list of top-level message types declared in this file.
+ /// </value>
+ public IList<MessageDescriptor> MessageTypes { get; }
+
+ /// <value>
+ /// Unmodifiable list of top-level enum types declared in this file.
+ /// </value>
+ public IList<EnumDescriptor> EnumTypes { get; }
+
+ /// <value>
+ /// Unmodifiable list of top-level services declared in this file.
+ /// </value>
+ public IList<ServiceDescriptor> Services { get; }
+
+ /// <value>
+ /// Unmodifiable list of this file's dependencies (imports).
+ /// </value>
+ public IList<FileDescriptor> Dependencies { get; }
+
+ /// <value>
+ /// Unmodifiable list of this file's public dependencies (public imports).
+ /// </value>
+ public IList<FileDescriptor> PublicDependencies { get; }
+
+ /// <value>
+ /// The original serialized binary form of this descriptor.
+ /// </value>
+ public ByteString SerializedData { get; }
+
+ /// <value>
+ /// Implementation of IDescriptor.FullName - just returns the same as Name.
+ /// </value>
+ string IDescriptor.FullName => Name;
+
+ /// <value>
+ /// Implementation of IDescriptor.File - just returns this descriptor.
+ /// </value>
+ FileDescriptor IDescriptor.File => this;
+
+ /// <value>
+ /// Pool containing symbol descriptors.
+ /// </value>
+ internal DescriptorPool DescriptorPool { get; }
+
+ /// <summary>
+ /// Finds a type (message, enum, service or extension) in the file by name. Does not find nested types.
+ /// </summary>
+ /// <param name="name">The unqualified type name to look for.</param>
+ /// <typeparam name="T">The type of descriptor to look for</typeparam>
+ /// <returns>The type's descriptor, or null if not found.</returns>
+ public T FindTypeByName<T>(String name)
+ where T : class, IDescriptor
+ {
+ // Don't allow looking up nested types. This will make optimization
+ // easier later.
+ if (name.IndexOf('.') != -1)
+ {
+ return null;
+ }
+ if (Package.Length > 0)
+ {
+ name = Package + "." + name;
+ }
+ T result = DescriptorPool.FindSymbol<T>(name);
+ if (result != null && result.File == this)
+ {
+ return result;
+ }
+ return null;
+ }
+
+ /// <summary>
+ /// Builds a FileDescriptor from its protocol buffer representation.
+ /// </summary>
+ /// <param name="descriptorData">The original serialized descriptor data.
+ /// We have only limited proto2 support, so serializing FileDescriptorProto
+ /// would not necessarily give us this.</param>
+ /// <param name="proto">The protocol message form of the FileDescriptor.</param>
+ /// <param name="dependencies">FileDescriptors corresponding to all of the
+ /// file's dependencies, in the exact order listed in the .proto file. May be null,
+ /// in which case it is treated as an empty array.</param>
+ /// <param name="allowUnknownDependencies">Whether unknown dependencies are ignored (true) or cause an exception to be thrown (false).</param>
+ /// <param name="generatedCodeInfo">Details about generated code, for the purposes of reflection.</param>
+ /// <exception cref="DescriptorValidationException">If <paramref name="proto"/> is not
+ /// a valid descriptor. This can occur for a number of reasons, such as a field
+ /// having an undefined type or because two messages were defined with the same name.</exception>
+ private static FileDescriptor BuildFrom(ByteString descriptorData, FileDescriptorProto proto, FileDescriptor[] dependencies, bool allowUnknownDependencies, GeneratedClrTypeInfo generatedCodeInfo)
+ {
+ // Building descriptors involves two steps: translating and linking.
+ // In the translation step (implemented by FileDescriptor's
+ // constructor), we build an object tree mirroring the
+ // FileDescriptorProto's tree and put all of the descriptors into the
+ // DescriptorPool's lookup tables. In the linking step, we look up all
+ // type references in the DescriptorPool, so that, for example, a
+ // FieldDescriptor for an embedded message contains a pointer directly
+ // to the Descriptor for that message's type. We also detect undefined
+ // types in the linking step.
+ if (dependencies == null)
+ {
+ dependencies = new FileDescriptor[0];
+ }
+
+ DescriptorPool pool = new DescriptorPool(dependencies);
+ FileDescriptor result = new FileDescriptor(descriptorData, proto, dependencies, pool, allowUnknownDependencies, generatedCodeInfo);
+
+ // Validate that the dependencies we've been passed (as FileDescriptors) are actually the ones we
+ // need.
+ if (dependencies.Length != proto.Dependency.Count)
+ {
+ throw new DescriptorValidationException(
+ result,
+ "Dependencies passed to FileDescriptor.BuildFrom() don't match " +
+ "those listed in the FileDescriptorProto.");
+ }
+
+ result.CrossLink();
+ return result;
+ }
+
+ private void CrossLink()
+ {
+ foreach (MessageDescriptor message in MessageTypes)
+ {
+ message.CrossLink();
+ }
+
+ foreach (ServiceDescriptor service in Services)
+ {
+ service.CrossLink();
+ }
+ }
+
+ /// <summary>
+ /// Creates a descriptor for generated code.
+ /// </summary>
+ /// <remarks>
+ /// This method is only designed to be used by the results of generating code with protoc,
+ /// which creates the appropriate dependencies etc. It has to be public because the generated
+ /// code is "external", but should not be called directly by end users.
+ /// </remarks>
+ public static FileDescriptor FromGeneratedCode(
+ byte[] descriptorData,
+ FileDescriptor[] dependencies,
+ GeneratedClrTypeInfo generatedCodeInfo)
+ {
+ FileDescriptorProto proto;
+ try
+ {
+ proto = FileDescriptorProto.Parser.ParseFrom(descriptorData);
+ }
+ catch (InvalidProtocolBufferException e)
+ {
+ throw new ArgumentException("Failed to parse protocol buffer descriptor for generated code.", e);
+ }
+
+ try
+ {
+ // When building descriptors for generated code, we allow unknown
+ // dependencies by default.
+ return BuildFrom(ByteString.CopyFrom(descriptorData), proto, dependencies, true, generatedCodeInfo);
+ }
+ catch (DescriptorValidationException e)
+ {
+ throw new ArgumentException($"Invalid embedded descriptor for \"{proto.Name}\".", e);
+ }
+ }
+
+ /// <summary>
+ /// Returns a <see cref="System.String" /> that represents this instance.
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.String" /> that represents this instance.
+ /// </returns>
+ public override string ToString()
+ {
+ return $"FileDescriptor for {Name}";
+ }
+
+ /// <summary>
+ /// Returns the file descriptor for descriptor.proto.
+ /// </summary>
+ /// <remarks>
+ /// This is used for protos which take a direct dependency on <c>descriptor.proto</c>, typically for
+ /// annotations. While <c>descriptor.proto</c> is a proto2 file, it is built into the Google.Protobuf
+ /// runtime for reflection purposes. The messages are internal to the runtime as they would require
+ /// proto2 semantics for full support, but the file descriptor is available via this property. The
+ /// C# codegen in protoc automatically uses this property when it detects a dependency on <c>descriptor.proto</c>.
+ /// </remarks>
+ /// <value>
+ /// The file descriptor for <c>descriptor.proto</c>.
+ /// </value>
+ public static FileDescriptor DescriptorProtoFileDescriptor { get { return DescriptorReflection.Descriptor; } }
+
+ /// <summary>
+ /// The (possibly empty) set of custom options for this file.
+ /// </summary>
+ public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs
new file mode 100644
index 0000000000..fe5db65656
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs
@@ -0,0 +1,103 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+using System;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Extra information provided by generated code when initializing a message or file descriptor.
+ /// These are constructed as required, and are not long-lived. Hand-written code should
+ /// never need to use this type.
+ /// </summary>
+ public sealed class GeneratedClrTypeInfo
+ {
+ private static readonly string[] EmptyNames = new string[0];
+ private static readonly GeneratedClrTypeInfo[] EmptyCodeInfo = new GeneratedClrTypeInfo[0];
+
+ /// <summary>
+ /// Irrelevant for file descriptors; the CLR type for the message for message descriptors.
+ /// </summary>
+ public Type ClrType { get; private set; }
+
+ /// <summary>
+ /// Irrelevant for file descriptors; the parser for message descriptors.
+ /// </summary>
+ public MessageParser Parser { get; }
+
+ /// <summary>
+ /// Irrelevant for file descriptors; the CLR property names (in message descriptor field order)
+ /// for fields in the message for message descriptors.
+ /// </summary>
+ public string[] PropertyNames { get; }
+
+ /// <summary>
+ /// Irrelevant for file descriptors; the CLR property "base" names (in message descriptor oneof order)
+ /// for oneofs in the message for message descriptors. It is expected that for a oneof name of "Foo",
+ /// there will be a "FooCase" property and a "ClearFoo" method.
+ /// </summary>
+ public string[] OneofNames { get; }
+
+ /// <summary>
+ /// The reflection information for types within this file/message descriptor. Elements may be null
+ /// if there is no corresponding generated type, e.g. for map entry types.
+ /// </summary>
+ public GeneratedClrTypeInfo[] NestedTypes { get; }
+
+ /// <summary>
+ /// The CLR types for enums within this file/message descriptor.
+ /// </summary>
+ public Type[] NestedEnums { get; }
+
+ /// <summary>
+ /// Creates a GeneratedClrTypeInfo for a message descriptor, with nested types, nested enums, the CLR type, property names and oneof names.
+ /// Each array parameter may be null, to indicate a lack of values.
+ /// The parameter order is designed to make it feasible to format the generated code readably.
+ /// </summary>
+ public GeneratedClrTypeInfo(Type clrType, MessageParser parser, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes)
+ {
+ NestedTypes = nestedTypes ?? EmptyCodeInfo;
+ NestedEnums = nestedEnums ?? ReflectionUtil.EmptyTypes;
+ ClrType = clrType;
+ Parser = parser;
+ PropertyNames = propertyNames ?? EmptyNames;
+ OneofNames = oneofNames ?? EmptyNames;
+ }
+
+ /// <summary>
+ /// Creates a GeneratedClrTypeInfo for a file descriptor, with only types and enums.
+ /// </summary>
+ public GeneratedClrTypeInfo(Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes)
+ : this(null, null, null, null, nestedEnums, nestedTypes)
+ {
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/IDescriptor.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/IDescriptor.cs
new file mode 100644
index 0000000000..318d58c968
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/IDescriptor.cs
@@ -0,0 +1,55 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Interface implemented by all descriptor types.
+ /// </summary>
+ public interface IDescriptor
+ {
+ /// <summary>
+ /// Returns the name of the entity (message, field etc) being described.
+ /// </summary>
+ string Name { get; }
+
+ /// <summary>
+ /// Returns the fully-qualified name of the entity being described.
+ /// </summary>
+ string FullName { get; }
+
+ /// <summary>
+ /// Returns the descriptor for the .proto file that this entity is part of.
+ /// </summary>
+ FileDescriptor File { get; }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs
new file mode 100644
index 0000000000..cfe56fde67
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs
@@ -0,0 +1,71 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.Collections;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Allows fields to be reflectively accessed.
+ /// </summary>
+ public interface IFieldAccessor
+ {
+ /// <summary>
+ /// Returns the descriptor associated with this field.
+ /// </summary>
+ FieldDescriptor Descriptor { get; }
+
+ /// <summary>
+ /// Clears the field in the specified message. (For repeated fields,
+ /// this clears the list.)
+ /// </summary>
+ void Clear(IMessage message);
+
+ /// <summary>
+ /// Fetches the field value. For repeated values, this will be an
+ /// <see cref="IList"/> implementation. For map values, this will be an
+ /// <see cref="IDictionary"/> implementation.
+ /// </summary>
+ object GetValue(IMessage message);
+
+ /// <summary>
+ /// Mutator for single "simple" fields only.
+ /// </summary>
+ /// <remarks>
+ /// Repeated fields are mutated by fetching the value and manipulating it as a list.
+ /// Map fields are mutated by fetching the value and manipulating it as a dictionary.
+ /// </remarks>
+ /// <exception cref="InvalidOperationException">The field is not a "simple" field.</exception>
+ void SetValue(IMessage message, object value);
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/MapFieldAccessor.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/MapFieldAccessor.cs
new file mode 100644
index 0000000000..9ed7f8c4df
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/MapFieldAccessor.cs
@@ -0,0 +1,59 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.Collections;
+using System.Reflection;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Accessor for map fields.
+ /// </summary>
+ internal sealed class MapFieldAccessor : FieldAccessorBase
+ {
+ internal MapFieldAccessor(PropertyInfo property, FieldDescriptor descriptor) : base(property, descriptor)
+ {
+ }
+
+ public override void Clear(IMessage message)
+ {
+ IDictionary list = (IDictionary) GetValue(message);
+ list.Clear();
+ }
+
+ public override void SetValue(IMessage message, object value)
+ {
+ throw new InvalidOperationException("SetValue is not implemented for map fields");
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
new file mode 100755
index 0000000000..86942acc02
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
@@ -0,0 +1,326 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+#if NET35
+// Needed for ReadOnlyDictionary, which does not exist in .NET 3.5
+using Google.Protobuf.Collections;
+#endif
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Describes a message type.
+ /// </summary>
+ public sealed class MessageDescriptor : DescriptorBase
+ {
+ private static readonly HashSet<string> WellKnownTypeNames = new HashSet<string>
+ {
+ "google/protobuf/any.proto",
+ "google/protobuf/api.proto",
+ "google/protobuf/duration.proto",
+ "google/protobuf/empty.proto",
+ "google/protobuf/wrappers.proto",
+ "google/protobuf/timestamp.proto",
+ "google/protobuf/field_mask.proto",
+ "google/protobuf/source_context.proto",
+ "google/protobuf/struct.proto",
+ "google/protobuf/type.proto",
+ };
+
+ private readonly IList<FieldDescriptor> fieldsInDeclarationOrder;
+ private readonly IList<FieldDescriptor> fieldsInNumberOrder;
+ private readonly IDictionary<string, FieldDescriptor> jsonFieldMap;
+
+ internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex, GeneratedClrTypeInfo generatedCodeInfo)
+ : base(file, file.ComputeFullName(parent, proto.Name), typeIndex)
+ {
+ Proto = proto;
+ Parser = generatedCodeInfo?.Parser;
+ ClrType = generatedCodeInfo?.ClrType;
+ ContainingType = parent;
+
+ // Note use of generatedCodeInfo. rather than generatedCodeInfo?. here... we don't expect
+ // to see any nested oneofs, types or enums in "not actually generated" code... we do
+ // expect fields though (for map entry messages).
+ Oneofs = DescriptorUtil.ConvertAndMakeReadOnly(
+ proto.OneofDecl,
+ (oneof, index) =>
+ new OneofDescriptor(oneof, file, this, index, generatedCodeInfo.OneofNames[index]));
+
+ NestedTypes = DescriptorUtil.ConvertAndMakeReadOnly(
+ proto.NestedType,
+ (type, index) =>
+ new MessageDescriptor(type, file, this, index, generatedCodeInfo.NestedTypes[index]));
+
+ EnumTypes = DescriptorUtil.ConvertAndMakeReadOnly(
+ proto.EnumType,
+ (type, index) =>
+ new EnumDescriptor(type, file, this, index, generatedCodeInfo.NestedEnums[index]));
+
+ fieldsInDeclarationOrder = DescriptorUtil.ConvertAndMakeReadOnly(
+ proto.Field,
+ (field, index) =>
+ new FieldDescriptor(field, file, this, index, generatedCodeInfo?.PropertyNames[index]));
+ fieldsInNumberOrder = new ReadOnlyCollection<FieldDescriptor>(fieldsInDeclarationOrder.OrderBy(field => field.FieldNumber).ToArray());
+ // TODO: Use field => field.Proto.JsonName when we're confident it's appropriate. (And then use it in the formatter, too.)
+ jsonFieldMap = CreateJsonFieldMap(fieldsInNumberOrder);
+ file.DescriptorPool.AddSymbol(this);
+ Fields = new FieldCollection(this);
+ }
+
+ private static ReadOnlyDictionary<string, FieldDescriptor> CreateJsonFieldMap(IList<FieldDescriptor> fields)
+ {
+ var map = new Dictionary<string, FieldDescriptor>();
+ foreach (var field in fields)
+ {
+ map[field.Name] = field;
+ map[field.JsonName] = field;
+ }
+ return new ReadOnlyDictionary<string, FieldDescriptor>(map);
+ }
+
+ /// <summary>
+ /// The brief name of the descriptor's target.
+ /// </summary>
+ public override string Name => Proto.Name;
+
+ internal DescriptorProto Proto { get; }
+
+ /// <summary>
+ /// The CLR type used to represent message instances from this descriptor.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// The value returned by this property will be non-null for all regular fields. However,
+ /// if a message containing a map field is introspected, the list of nested messages will include
+ /// an auto-generated nested key/value pair message for the field. This is not represented in any
+ /// generated type, so this property will return null in such cases.
+ /// </para>
+ /// <para>
+ /// For wrapper types (<see cref="Google.Protobuf.WellKnownTypes.StringValue"/> and the like), the type returned here
+ /// will be the generated message type, not the native type used by reflection for fields of those types. Code
+ /// using reflection should call <see cref="IsWrapperType"/> to determine whether a message descriptor represents
+ /// a wrapper type, and handle the result appropriately.
+ /// </para>
+ /// </remarks>
+ public Type ClrType { get; }
+
+ /// <summary>
+ /// A parser for this message type.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// As <see cref="MessageDescriptor"/> is not generic, this cannot be statically
+ /// typed to the relevant type, but it should produce objects of a type compatible with <see cref="ClrType"/>.
+ /// </para>
+ /// <para>
+ /// The value returned by this property will be non-null for all regular fields. However,
+ /// if a message containing a map field is introspected, the list of nested messages will include
+ /// an auto-generated nested key/value pair message for the field. No message parser object is created for
+ /// such messages, so this property will return null in such cases.
+ /// </para>
+ /// <para>
+ /// For wrapper types (<see cref="Google.Protobuf.WellKnownTypes.StringValue"/> and the like), the parser returned here
+ /// will be the generated message type, not the native type used by reflection for fields of those types. Code
+ /// using reflection should call <see cref="IsWrapperType"/> to determine whether a message descriptor represents
+ /// a wrapper type, and handle the result appropriately.
+ /// </para>
+ /// </remarks>
+ public MessageParser Parser { get; }
+
+ /// <summary>
+ /// Returns whether this message is one of the "well known types" which may have runtime/protoc support.
+ /// </summary>
+ internal bool IsWellKnownType => File.Package == "google.protobuf" && WellKnownTypeNames.Contains(File.Name);
+
+ /// <summary>
+ /// Returns whether this message is one of the "wrapper types" used for fields which represent primitive values
+ /// with the addition of presence.
+ /// </summary>
+ internal bool IsWrapperType => File.Package == "google.protobuf" && File.Name == "google/protobuf/wrappers.proto";
+
+ /// <value>
+ /// If this is a nested type, get the outer descriptor, otherwise null.
+ /// </value>
+ public MessageDescriptor ContainingType { get; }
+
+ /// <value>
+ /// A collection of fields, which can be retrieved by name or field number.
+ /// </value>
+ public FieldCollection Fields { get; }
+
+ /// <value>
+ /// An unmodifiable list of this message type's nested types.
+ /// </value>
+ public IList<MessageDescriptor> NestedTypes { get; }
+
+ /// <value>
+ /// An unmodifiable list of this message type's enum types.
+ /// </value>
+ public IList<EnumDescriptor> EnumTypes { get; }
+
+ /// <value>
+ /// An unmodifiable list of the "oneof" field collections in this message type.
+ /// </value>
+ public IList<OneofDescriptor> Oneofs { get; }
+
+ /// <summary>
+ /// Finds a field by field name.
+ /// </summary>
+ /// <param name="name">The unqualified name of the field (e.g. "foo").</param>
+ /// <returns>The field's descriptor, or null if not found.</returns>
+ public FieldDescriptor FindFieldByName(String name) => File.DescriptorPool.FindSymbol<FieldDescriptor>(FullName + "." + name);
+
+ /// <summary>
+ /// Finds a field by field number.
+ /// </summary>
+ /// <param name="number">The field number within this message type.</param>
+ /// <returns>The field's descriptor, or null if not found.</returns>
+ public FieldDescriptor FindFieldByNumber(int number) => File.DescriptorPool.FindFieldByNumber(this, number);
+
+ /// <summary>
+ /// Finds a nested descriptor by name. The is valid for fields, nested
+ /// message types, oneofs and enums.
+ /// </summary>
+ /// <param name="name">The unqualified name of the descriptor, e.g. "Foo"</param>
+ /// <returns>The descriptor, or null if not found.</returns>
+ public T FindDescriptor<T>(string name) where T : class, IDescriptor =>
+ File.DescriptorPool.FindSymbol<T>(FullName + "." + name);
+
+ /// <summary>
+ /// The (possibly empty) set of custom options for this message.
+ /// </summary>
+ public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
+
+ /// <summary>
+ /// Looks up and cross-links all fields and nested types.
+ /// </summary>
+ internal void CrossLink()
+ {
+ foreach (MessageDescriptor message in NestedTypes)
+ {
+ message.CrossLink();
+ }
+
+ foreach (FieldDescriptor field in fieldsInDeclarationOrder)
+ {
+ field.CrossLink();
+ }
+
+ foreach (OneofDescriptor oneof in Oneofs)
+ {
+ oneof.CrossLink();
+ }
+ }
+
+ /// <summary>
+ /// A collection to simplify retrieving the field accessor for a particular field.
+ /// </summary>
+ public sealed class FieldCollection
+ {
+ private readonly MessageDescriptor messageDescriptor;
+
+ internal FieldCollection(MessageDescriptor messageDescriptor)
+ {
+ this.messageDescriptor = messageDescriptor;
+ }
+
+ /// <value>
+ /// Returns the fields in the message as an immutable list, in the order in which they
+ /// are declared in the source .proto file.
+ /// </value>
+ public IList<FieldDescriptor> InDeclarationOrder() => messageDescriptor.fieldsInDeclarationOrder;
+
+ /// <value>
+ /// Returns the fields in the message as an immutable list, in ascending field number
+ /// order. Field numbers need not be contiguous, so there is no direct mapping from the
+ /// index in the list to the field number; to retrieve a field by field number, it is better
+ /// to use the <see cref="FieldCollection"/> indexer.
+ /// </value>
+ public IList<FieldDescriptor> InFieldNumberOrder() => messageDescriptor.fieldsInNumberOrder;
+
+ // TODO: consider making this public in the future. (Being conservative for now...)
+
+ /// <value>
+ /// Returns a read-only dictionary mapping the field names in this message as they're available
+ /// in the JSON representation to the field descriptors. For example, a field <c>foo_bar</c>
+ /// in the message would result two entries, one with a key <c>fooBar</c> and one with a key
+ /// <c>foo_bar</c>, both referring to the same field.
+ /// </value>
+ internal IDictionary<string, FieldDescriptor> ByJsonName() => messageDescriptor.jsonFieldMap;
+
+ /// <summary>
+ /// Retrieves the descriptor for the field with the given number.
+ /// </summary>
+ /// <param name="number">Number of the field to retrieve the descriptor for</param>
+ /// <returns>The accessor for the given field</returns>
+ /// <exception cref="KeyNotFoundException">The message descriptor does not contain a field
+ /// with the given number</exception>
+ public FieldDescriptor this[int number]
+ {
+ get
+ {
+ var fieldDescriptor = messageDescriptor.FindFieldByNumber(number);
+ if (fieldDescriptor == null)
+ {
+ throw new KeyNotFoundException("No such field number");
+ }
+ return fieldDescriptor;
+ }
+ }
+
+ /// <summary>
+ /// Retrieves the descriptor for the field with the given name.
+ /// </summary>
+ /// <param name="name">Name of the field to retrieve the descriptor for</param>
+ /// <returns>The descriptor for the given field</returns>
+ /// <exception cref="KeyNotFoundException">The message descriptor does not contain a field
+ /// with the given name</exception>
+ public FieldDescriptor this[string name]
+ {
+ get
+ {
+ var fieldDescriptor = messageDescriptor.FindFieldByName(name);
+ if (fieldDescriptor == null)
+ {
+ throw new KeyNotFoundException("No such field name");
+ }
+ return fieldDescriptor;
+ }
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs
new file mode 100644
index 0000000000..19d7f8a092
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs
@@ -0,0 +1,108 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Describes a single method in a service.
+ /// </summary>
+ public sealed class MethodDescriptor : DescriptorBase
+ {
+ private readonly MethodDescriptorProto proto;
+ private readonly ServiceDescriptor service;
+ private MessageDescriptor inputType;
+ private MessageDescriptor outputType;
+
+ /// <value>
+ /// The service this method belongs to.
+ /// </value>
+ public ServiceDescriptor Service { get { return service; } }
+
+ /// <value>
+ /// The method's input type.
+ /// </value>
+ public MessageDescriptor InputType { get { return inputType; } }
+
+ /// <value>
+ /// The method's input type.
+ /// </value>
+ public MessageDescriptor OutputType { get { return outputType; } }
+
+ /// <value>
+ /// Indicates if client streams multiple requests.
+ /// </value>
+ public bool IsClientStreaming { get { return proto.ClientStreaming; } }
+
+ /// <value>
+ /// Indicates if server streams multiple responses.
+ /// </value>
+ public bool IsServerStreaming { get { return proto.ServerStreaming; } }
+
+ /// <summary>
+ /// The (possibly empty) set of custom options for this method.
+ /// </summary>
+ public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
+
+ internal MethodDescriptor(MethodDescriptorProto proto, FileDescriptor file,
+ ServiceDescriptor parent, int index)
+ : base(file, parent.FullName + "." + proto.Name, index)
+ {
+ this.proto = proto;
+ service = parent;
+ file.DescriptorPool.AddSymbol(this);
+ }
+
+ internal MethodDescriptorProto Proto { get { return proto; } }
+
+ /// <summary>
+ /// The brief name of the descriptor's target.
+ /// </summary>
+ public override string Name { get { return proto.Name; } }
+
+ internal void CrossLink()
+ {
+ IDescriptor lookup = File.DescriptorPool.LookupSymbol(Proto.InputType, this);
+ if (!(lookup is MessageDescriptor))
+ {
+ throw new DescriptorValidationException(this, "\"" + Proto.InputType + "\" is not a message type.");
+ }
+ inputType = (MessageDescriptor) lookup;
+
+ lookup = File.DescriptorPool.LookupSymbol(Proto.OutputType, this);
+ if (!(lookup is MessageDescriptor))
+ {
+ throw new DescriptorValidationException(this, "\"" + Proto.OutputType + "\" is not a message type.");
+ }
+ outputType = (MessageDescriptor) lookup;
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/OneofAccessor.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/OneofAccessor.cs
new file mode 100644
index 0000000000..8714ab18ef
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/OneofAccessor.cs
@@ -0,0 +1,90 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.Reflection;
+using Google.Protobuf.Compatibility;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Reflection access for a oneof, allowing clear and "get case" actions.
+ /// </summary>
+ public sealed class OneofAccessor
+ {
+ private readonly Func<IMessage, int> caseDelegate;
+ private readonly Action<IMessage> clearDelegate;
+ private OneofDescriptor descriptor;
+
+ internal OneofAccessor(PropertyInfo caseProperty, MethodInfo clearMethod, OneofDescriptor descriptor)
+ {
+ if (!caseProperty.CanRead)
+ {
+ throw new ArgumentException("Cannot read from property");
+ }
+ this.descriptor = descriptor;
+ caseDelegate = ReflectionUtil.CreateFuncIMessageT<int>(caseProperty.GetGetMethod());
+
+ this.descriptor = descriptor;
+ clearDelegate = ReflectionUtil.CreateActionIMessage(clearMethod);
+ }
+
+ /// <summary>
+ /// Gets the descriptor for this oneof.
+ /// </summary>
+ /// <value>
+ /// The descriptor of the oneof.
+ /// </value>
+ public OneofDescriptor Descriptor { get { return descriptor; } }
+
+ /// <summary>
+ /// Clears the oneof in the specified message.
+ /// </summary>
+ public void Clear(IMessage message)
+ {
+ clearDelegate(message);
+ }
+
+ /// <summary>
+ /// Indicates which field in the oneof is set for specified message
+ /// </summary>
+ public FieldDescriptor GetCaseFieldDescriptor(IMessage message)
+ {
+ int fieldNumber = caseDelegate(message);
+ if (fieldNumber > 0)
+ {
+ return descriptor.ContainingType.FindFieldByNumber(fieldNumber);
+ }
+ return null;
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs
new file mode 100644
index 0000000000..5906c2e36d
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs
@@ -0,0 +1,127 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using Google.Protobuf.Compatibility;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Describes a "oneof" field collection in a message type: a set of
+ /// fields of which at most one can be set in any particular message.
+ /// </summary>
+ public sealed class OneofDescriptor : DescriptorBase
+ {
+ private readonly OneofDescriptorProto proto;
+ private MessageDescriptor containingType;
+ private IList<FieldDescriptor> fields;
+ private readonly OneofAccessor accessor;
+
+ internal OneofDescriptor(OneofDescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int index, string clrName)
+ : base(file, file.ComputeFullName(parent, proto.Name), index)
+ {
+ this.proto = proto;
+ containingType = parent;
+
+ file.DescriptorPool.AddSymbol(this);
+ accessor = CreateAccessor(clrName);
+ }
+
+ /// <summary>
+ /// The brief name of the descriptor's target.
+ /// </summary>
+ public override string Name { get { return proto.Name; } }
+
+ /// <summary>
+ /// Gets the message type containing this oneof.
+ /// </summary>
+ /// <value>
+ /// The message type containing this oneof.
+ /// </value>
+ public MessageDescriptor ContainingType
+ {
+ get { return containingType; }
+ }
+
+ /// <summary>
+ /// Gets the fields within this oneof, in declaration order.
+ /// </summary>
+ /// <value>
+ /// The fields within this oneof, in declaration order.
+ /// </value>
+ public IList<FieldDescriptor> Fields { get { return fields; } }
+
+ /// <summary>
+ /// Gets an accessor for reflective access to the values associated with the oneof
+ /// in a particular message.
+ /// </summary>
+ /// <value>
+ /// The accessor used for reflective access.
+ /// </value>
+ public OneofAccessor Accessor { get { return accessor; } }
+
+ /// <summary>
+ /// The (possibly empty) set of custom options for this oneof.
+ /// </summary>
+ public CustomOptions CustomOptions => proto.Options?.CustomOptions ?? CustomOptions.Empty;
+
+ internal void CrossLink()
+ {
+ List<FieldDescriptor> fieldCollection = new List<FieldDescriptor>();
+ foreach (var field in ContainingType.Fields.InDeclarationOrder())
+ {
+ if (field.ContainingOneof == this)
+ {
+ fieldCollection.Add(field);
+ }
+ }
+ fields = new ReadOnlyCollection<FieldDescriptor>(fieldCollection);
+ }
+
+ private OneofAccessor CreateAccessor(string clrName)
+ {
+ var caseProperty = containingType.ClrType.GetProperty(clrName + "Case");
+ if (caseProperty == null)
+ {
+ throw new DescriptorValidationException(this, $"Property {clrName}Case not found in {containingType.ClrType}");
+ }
+ var clearMethod = containingType.ClrType.GetMethod("Clear" + clrName);
+ if (clearMethod == null)
+ {
+ throw new DescriptorValidationException(this, $"Method Clear{clrName} not found in {containingType.ClrType}");
+ }
+
+ return new OneofAccessor(caseProperty, clearMethod, this);
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/OriginalNameAttribute.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/OriginalNameAttribute.cs
new file mode 100644
index 0000000000..07d0fd99af
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/OriginalNameAttribute.cs
@@ -0,0 +1,65 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Specifies the original name (in the .proto file) of a named element,
+ /// such as an enum value.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Field)]
+ public class OriginalNameAttribute : Attribute
+ {
+ /// <summary>
+ /// The name of the element in the .proto file.
+ /// </summary>
+ public string Name { get; set; }
+
+ /// <summary>
+ /// If the name is preferred in the .proto file.
+ /// </summary>
+ public bool PreferredAlias { get; set; }
+
+ /// <summary>
+ /// Constructs a new attribute instance for the given name.
+ /// </summary>
+ /// <param name="name">The name of the element in the .proto file.</param>
+ public OriginalNameAttribute(string name)
+ {
+ Name = ProtoPreconditions.CheckNotNull(name, nameof(name));
+ PreferredAlias = true;
+ }
+
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/PackageDescriptor.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/PackageDescriptor.cs
new file mode 100644
index 0000000000..e547d83498
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/PackageDescriptor.cs
@@ -0,0 +1,68 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Represents a package in the symbol table. We use PackageDescriptors
+ /// just as placeholders so that someone cannot define, say, a message type
+ /// that has the same name as an existing package.
+ /// </summary>
+ internal sealed class PackageDescriptor : IDescriptor
+ {
+ private readonly string name;
+ private readonly string fullName;
+ private readonly FileDescriptor file;
+
+ internal PackageDescriptor(string name, string fullName, FileDescriptor file)
+ {
+ this.file = file;
+ this.fullName = fullName;
+ this.name = name;
+ }
+
+ public string Name
+ {
+ get { return name; }
+ }
+
+ public string FullName
+ {
+ get { return fullName; }
+ }
+
+ public FileDescriptor File
+ {
+ get { return file; }
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/PartialClasses.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/PartialClasses.cs
new file mode 100644
index 0000000000..8c055d6d92
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/PartialClasses.cs
@@ -0,0 +1,59 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+// This file just contains partial classes for any autogenerated classes that need additional support.
+namespace Google.Protobuf.Reflection
+{
+ internal partial class FieldDescriptorProto
+ {
+ // We can't tell the difference between "explicitly set to 0" and "not set"
+ // in proto3, but we need to tell the difference for OneofIndex. descriptor.proto
+ // is really a proto2 file, but the runtime doesn't know about proto2 semantics...
+ // We fake it by defaulting to -1.
+ partial void OnConstruction()
+ {
+ OneofIndex = -1;
+ }
+ }
+
+ internal partial class FieldOptions
+ {
+ // We can't tell the difference between "explicitly set to false" and "not set"
+ // in proto3, but we need to tell the difference for FieldDescriptor.IsPacked.
+ // This won't work if we ever need to support proto2, but at that point we'll be
+ // able to remove this hack and use field presence instead.
+ partial void OnConstruction()
+ {
+ Packed = true;
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs
new file mode 100644
index 0000000000..df820ca36b
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs
@@ -0,0 +1,107 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq.Expressions;
+using System.Reflection;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// The methods in this class are somewhat evil, and should not be tampered with lightly.
+ /// Basically they allow the creation of relatively weakly typed delegates from MethodInfos
+ /// which are more strongly typed. They do this by creating an appropriate strongly typed
+ /// delegate from the MethodInfo, and then calling that within an anonymous method.
+ /// Mind-bending stuff (at least to your humble narrator) but the resulting delegates are
+ /// very fast compared with calling Invoke later on.
+ /// </summary>
+ internal static class ReflectionUtil
+ {
+ /// <summary>
+ /// Empty Type[] used when calling GetProperty to force property instead of indexer fetching.
+ /// </summary>
+ internal static readonly Type[] EmptyTypes = new Type[0];
+
+ /// <summary>
+ /// Creates a delegate which will cast the argument to the appropriate method target type,
+ /// call the method on it, then convert the result to object.
+ /// </summary>
+ internal static Func<IMessage, object> CreateFuncIMessageObject(MethodInfo method)
+ {
+ ParameterExpression parameter = Expression.Parameter(typeof(IMessage), "p");
+ Expression downcast = Expression.Convert(parameter, method.DeclaringType);
+ Expression call = Expression.Call(downcast, method);
+ Expression upcast = Expression.Convert(call, typeof(object));
+ return Expression.Lambda<Func<IMessage, object>>(upcast, parameter).Compile();
+ }
+
+ /// <summary>
+ /// Creates a delegate which will cast the argument to the appropriate method target type,
+ /// call the method on it, then convert the result to the specified type.
+ /// </summary>
+ internal static Func<IMessage, T> CreateFuncIMessageT<T>(MethodInfo method)
+ {
+ ParameterExpression parameter = Expression.Parameter(typeof(IMessage), "p");
+ Expression downcast = Expression.Convert(parameter, method.DeclaringType);
+ Expression call = Expression.Call(downcast, method);
+ Expression upcast = Expression.Convert(call, typeof(T));
+ return Expression.Lambda<Func<IMessage, T>>(upcast, parameter).Compile();
+ }
+
+ /// <summary>
+ /// Creates a delegate which will execute the given method after casting the first argument to
+ /// the target type of the method, and the second argument to the first parameter type of the method.
+ /// </summary>
+ internal static Action<IMessage, object> CreateActionIMessageObject(MethodInfo method)
+ {
+ ParameterExpression targetParameter = Expression.Parameter(typeof(IMessage), "target");
+ ParameterExpression argParameter = Expression.Parameter(typeof(object), "arg");
+ Expression castTarget = Expression.Convert(targetParameter, method.DeclaringType);
+ Expression castArgument = Expression.Convert(argParameter, method.GetParameters()[0].ParameterType);
+ Expression call = Expression.Call(castTarget, method, castArgument);
+ return Expression.Lambda<Action<IMessage, object>>(call, targetParameter, argParameter).Compile();
+ }
+
+ /// <summary>
+ /// Creates a delegate which will execute the given method after casting the first argument to
+ /// the target type of the method.
+ /// </summary>
+ internal static Action<IMessage> CreateActionIMessage(MethodInfo method)
+ {
+ ParameterExpression targetParameter = Expression.Parameter(typeof(IMessage), "target");
+ Expression castTarget = Expression.Convert(targetParameter, method.DeclaringType);
+ Expression call = Expression.Call(castTarget, method);
+ return Expression.Lambda<Action<IMessage>>(call, targetParameter).Compile();
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs
new file mode 100644
index 0000000000..bd40847092
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/RepeatedFieldAccessor.cs
@@ -0,0 +1,60 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.Collections;
+using System.Reflection;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Accessor for repeated fields.
+ /// </summary>
+ internal sealed class RepeatedFieldAccessor : FieldAccessorBase
+ {
+ internal RepeatedFieldAccessor(PropertyInfo property, FieldDescriptor descriptor) : base(property, descriptor)
+ {
+ }
+
+ public override void Clear(IMessage message)
+ {
+ IList list = (IList) GetValue(message);
+ list.Clear();
+ }
+
+ public override void SetValue(IMessage message, object value)
+ {
+ throw new InvalidOperationException("SetValue is not implemented for repeated fields");
+ }
+
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs
new file mode 100644
index 0000000000..fe5c072c8e
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs
@@ -0,0 +1,94 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+using System;
+using System.Collections.Generic;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Describes a service type.
+ /// </summary>
+ public sealed class ServiceDescriptor : DescriptorBase
+ {
+ private readonly ServiceDescriptorProto proto;
+ private readonly IList<MethodDescriptor> methods;
+
+ internal ServiceDescriptor(ServiceDescriptorProto proto, FileDescriptor file, int index)
+ : base(file, file.ComputeFullName(null, proto.Name), index)
+ {
+ this.proto = proto;
+ methods = DescriptorUtil.ConvertAndMakeReadOnly(proto.Method,
+ (method, i) => new MethodDescriptor(method, file, this, i));
+
+ file.DescriptorPool.AddSymbol(this);
+ }
+
+ /// <summary>
+ /// The brief name of the descriptor's target.
+ /// </summary>
+ public override string Name { get { return proto.Name; } }
+
+ internal ServiceDescriptorProto Proto { get { return proto; } }
+
+ /// <value>
+ /// An unmodifiable list of methods in this service.
+ /// </value>
+ public IList<MethodDescriptor> Methods
+ {
+ get { return methods; }
+ }
+
+ /// <summary>
+ /// Finds a method by name.
+ /// </summary>
+ /// <param name="name">The unqualified name of the method (e.g. "Foo").</param>
+ /// <returns>The method's decsriptor, or null if not found.</returns>
+ public MethodDescriptor FindMethodByName(String name)
+ {
+ return File.DescriptorPool.FindSymbol<MethodDescriptor>(FullName + "." + name);
+ }
+
+ /// <summary>
+ /// The (possibly empty) set of custom options for this service.
+ /// </summary>
+ public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
+
+ internal void CrossLink()
+ {
+ foreach (MethodDescriptor method in methods)
+ {
+ method.CrossLink();
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs
new file mode 100644
index 0000000000..bbac2173d4
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs
@@ -0,0 +1,81 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.Reflection;
+using Google.Protobuf.Compatibility;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Accessor for single fields.
+ /// </summary>
+ internal sealed class SingleFieldAccessor : FieldAccessorBase
+ {
+ // All the work here is actually done in the constructor - it creates the appropriate delegates.
+ // There are various cases to consider, based on the property type (message, string/bytes, or "genuine" primitive)
+ // and proto2 vs proto3 for non-message types, as proto3 doesn't support "full" presence detection or default
+ // values.
+
+ private readonly Action<IMessage, object> setValueDelegate;
+ private readonly Action<IMessage> clearDelegate;
+
+ internal SingleFieldAccessor(PropertyInfo property, FieldDescriptor descriptor) : base(property, descriptor)
+ {
+ if (!property.CanWrite)
+ {
+ throw new ArgumentException("Not all required properties/methods available");
+ }
+ setValueDelegate = ReflectionUtil.CreateActionIMessageObject(property.GetSetMethod());
+
+ var clrType = property.PropertyType;
+
+ // TODO: Validate that this is a reasonable single field? (Should be a value type, a message type, or string/ByteString.)
+ object defaultValue =
+ descriptor.FieldType == FieldType.Message ? null
+ : clrType == typeof(string) ? ""
+ : clrType == typeof(ByteString) ? ByteString.Empty
+ : Activator.CreateInstance(clrType);
+ clearDelegate = message => SetValue(message, defaultValue);
+ }
+
+ public override void Clear(IMessage message)
+ {
+ clearDelegate(message);
+ }
+
+ public override void SetValue(IMessage message, object value)
+ {
+ setValueDelegate(message, value);
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/TypeRegistry.cs b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/TypeRegistry.cs
new file mode 100644
index 0000000000..e94e3e6c60
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/Reflection/TypeRegistry.cs
@@ -0,0 +1,183 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// An immutable registry of types which can be looked up by their full name.
+ /// </summary>
+ public sealed class TypeRegistry
+ {
+ /// <summary>
+ /// An empty type registry, containing no types.
+ /// </summary>
+ public static TypeRegistry Empty { get; } = new TypeRegistry(new Dictionary<string, MessageDescriptor>());
+
+ private readonly Dictionary<string, MessageDescriptor> fullNameToMessageMap;
+
+ private TypeRegistry(Dictionary<string, MessageDescriptor> fullNameToMessageMap)
+ {
+ this.fullNameToMessageMap = fullNameToMessageMap;
+ }
+
+ /// <summary>
+ /// Attempts to find a message descriptor by its full name.
+ /// </summary>
+ /// <param name="fullName">The full name of the message, which is the dot-separated
+ /// combination of package, containing messages and message name</param>
+ /// <returns>The message descriptor corresponding to <paramref name="fullName"/> or null
+ /// if there is no such message descriptor.</returns>
+ public MessageDescriptor Find(string fullName)
+ {
+ MessageDescriptor ret;
+ // Ignore the return value as ret will end up with the right value either way.
+ fullNameToMessageMap.TryGetValue(fullName, out ret);
+ return ret;
+ }
+
+ /// <summary>
+ /// Creates a type registry from the specified set of file descriptors.
+ /// </summary>
+ /// <remarks>
+ /// This is a convenience overload for <see cref="FromFiles(IEnumerable{FileDescriptor})"/>
+ /// to allow calls such as <c>TypeRegistry.FromFiles(descriptor1, descriptor2)</c>.
+ /// </remarks>
+ /// <param name="fileDescriptors">The set of files to include in the registry. Must not contain null values.</param>
+ /// <returns>A type registry for the given files.</returns>
+ public static TypeRegistry FromFiles(params FileDescriptor[] fileDescriptors)
+ {
+ return FromFiles((IEnumerable<FileDescriptor>) fileDescriptors);
+ }
+
+ /// <summary>
+ /// Creates a type registry from the specified set of file descriptors.
+ /// </summary>
+ /// <remarks>
+ /// All message types within all the specified files are added to the registry, and
+ /// the dependencies of the specified files are also added, recursively.
+ /// </remarks>
+ /// <param name="fileDescriptors">The set of files to include in the registry. Must not contain null values.</param>
+ /// <returns>A type registry for the given files.</returns>
+ public static TypeRegistry FromFiles(IEnumerable<FileDescriptor> fileDescriptors)
+ {
+ ProtoPreconditions.CheckNotNull(fileDescriptors, nameof(fileDescriptors));
+ var builder = new Builder();
+ foreach (var file in fileDescriptors)
+ {
+ builder.AddFile(file);
+ }
+ return builder.Build();
+ }
+
+ /// <summary>
+ /// Creates a type registry from the file descriptor parents of the specified set of message descriptors.
+ /// </summary>
+ /// <remarks>
+ /// This is a convenience overload for <see cref="FromMessages(IEnumerable{MessageDescriptor})"/>
+ /// to allow calls such as <c>TypeRegistry.FromFiles(descriptor1, descriptor2)</c>.
+ /// </remarks>
+ /// <param name="messageDescriptors">The set of message descriptors to use to identify file descriptors to include in the registry.
+ /// Must not contain null values.</param>
+ /// <returns>A type registry for the given files.</returns>
+ public static TypeRegistry FromMessages(params MessageDescriptor[] messageDescriptors)
+ {
+ return FromMessages((IEnumerable<MessageDescriptor>) messageDescriptors);
+ }
+
+ /// <summary>
+ /// Creates a type registry from the file descriptor parents of the specified set of message descriptors.
+ /// </summary>
+ /// <remarks>
+ /// The specified message descriptors are only used to identify their file descriptors; the returned registry
+ /// contains all the types within the file descriptors which contain the specified message descriptors (and
+ /// the dependencies of those files), not just the specified messages.
+ /// </remarks>
+ /// <param name="messageDescriptors">The set of message descriptors to use to identify file descriptors to include in the registry.
+ /// Must not contain null values.</param>
+ /// <returns>A type registry for the given files.</returns>
+ public static TypeRegistry FromMessages(IEnumerable<MessageDescriptor> messageDescriptors)
+ {
+ ProtoPreconditions.CheckNotNull(messageDescriptors, nameof(messageDescriptors));
+ return FromFiles(messageDescriptors.Select(md => md.File));
+ }
+
+ /// <summary>
+ /// Builder class which isn't exposed, but acts as a convenient alternative to passing round two dictionaries in recursive calls.
+ /// </summary>
+ private class Builder
+ {
+ private readonly Dictionary<string, MessageDescriptor> types;
+ private readonly HashSet<string> fileDescriptorNames;
+
+ internal Builder()
+ {
+ types = new Dictionary<string, MessageDescriptor>();
+ fileDescriptorNames = new HashSet<string>();
+ }
+
+ internal void AddFile(FileDescriptor fileDescriptor)
+ {
+ if (!fileDescriptorNames.Add(fileDescriptor.Name))
+ {
+ return;
+ }
+ foreach (var dependency in fileDescriptor.Dependencies)
+ {
+ AddFile(dependency);
+ }
+ foreach (var message in fileDescriptor.MessageTypes)
+ {
+ AddMessage(message);
+ }
+ }
+
+ private void AddMessage(MessageDescriptor messageDescriptor)
+ {
+ foreach (var nestedType in messageDescriptor.NestedTypes)
+ {
+ AddMessage(nestedType);
+ }
+ // This will overwrite any previous entry. Given that each file should
+ // only be added once, this could be a problem such as package A.B with type C,
+ // and package A with type B.C... it's unclear what we should do in that case.
+ types[messageDescriptor.FullName] = messageDescriptor;
+ }
+
+ internal TypeRegistry Build()
+ {
+ return new TypeRegistry(types);
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs
new file mode 100644
index 0000000000..b90c9a2afd
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs
@@ -0,0 +1,285 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/any.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.WellKnownTypes {
+
+ /// <summary>Holder for reflection information generated from google/protobuf/any.proto</summary>
+ public static partial class AnyReflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for google/protobuf/any.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static AnyReflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "Chlnb29nbGUvcHJvdG9idWYvYW55LnByb3RvEg9nb29nbGUucHJvdG9idWYi",
+ "JgoDQW55EhAKCHR5cGVfdXJsGAEgASgJEg0KBXZhbHVlGAIgASgMQm8KE2Nv",
+ "bS5nb29nbGUucHJvdG9idWZCCEFueVByb3RvUAFaJWdpdGh1Yi5jb20vZ29s",
+ "YW5nL3Byb3RvYnVmL3B0eXBlcy9hbnmiAgNHUEKqAh5Hb29nbGUuUHJvdG9i",
+ "dWYuV2VsbEtub3duVHlwZXNiBnByb3RvMw=="));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { },
+ new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.Any), global::Google.Protobuf.WellKnownTypes.Any.Parser, new[]{ "TypeUrl", "Value" }, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Messages
+ /// <summary>
+ /// `Any` contains an arbitrary serialized protocol buffer message along with a
+ /// URL that describes the type of the serialized message.
+ ///
+ /// Protobuf library provides support to pack/unpack Any values in the form
+ /// of utility functions or additional generated methods of the Any type.
+ ///
+ /// Example 1: Pack and unpack a message in C++.
+ ///
+ /// Foo foo = ...;
+ /// Any any;
+ /// any.PackFrom(foo);
+ /// ...
+ /// if (any.UnpackTo(&amp;foo)) {
+ /// ...
+ /// }
+ ///
+ /// Example 2: Pack and unpack a message in Java.
+ ///
+ /// Foo foo = ...;
+ /// Any any = Any.pack(foo);
+ /// ...
+ /// if (any.is(Foo.class)) {
+ /// foo = any.unpack(Foo.class);
+ /// }
+ ///
+ /// Example 3: Pack and unpack a message in Python.
+ ///
+ /// foo = Foo(...)
+ /// any = Any()
+ /// any.Pack(foo)
+ /// ...
+ /// if any.Is(Foo.DESCRIPTOR):
+ /// any.Unpack(foo)
+ /// ...
+ ///
+ /// The pack methods provided by protobuf library will by default use
+ /// 'type.googleapis.com/full.type.name' as the type URL and the unpack
+ /// methods only use the fully qualified type name after the last '/'
+ /// in the type URL, for example "foo.bar.com/x/y.z" will yield type
+ /// name "y.z".
+ ///
+ /// JSON
+ /// ====
+ /// The JSON representation of an `Any` value uses the regular
+ /// representation of the deserialized, embedded message, with an
+ /// additional field `@type` which contains the type URL. Example:
+ ///
+ /// package google.profile;
+ /// message Person {
+ /// string first_name = 1;
+ /// string last_name = 2;
+ /// }
+ ///
+ /// {
+ /// "@type": "type.googleapis.com/google.profile.Person",
+ /// "firstName": &lt;string>,
+ /// "lastName": &lt;string>
+ /// }
+ ///
+ /// If the embedded message type is well-known and has a custom JSON
+ /// representation, that representation will be embedded adding a field
+ /// `value` which holds the custom JSON in addition to the `@type`
+ /// field. Example (for message [google.protobuf.Duration][]):
+ ///
+ /// {
+ /// "@type": "type.googleapis.com/google.protobuf.Duration",
+ /// "value": "1.212s"
+ /// }
+ /// </summary>
+ public sealed partial class Any : pb::IMessage<Any> {
+ private static readonly pb::MessageParser<Any> _parser = new pb::MessageParser<Any>(() => new Any());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Any> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.AnyReflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Any() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Any(Any other) : this() {
+ typeUrl_ = other.typeUrl_;
+ value_ = other.value_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Any Clone() {
+ return new Any(this);
+ }
+
+ /// <summary>Field number for the "type_url" field.</summary>
+ public const int TypeUrlFieldNumber = 1;
+ private string typeUrl_ = "";
+ /// <summary>
+ /// A URL/resource name whose content describes the type of the
+ /// serialized protocol buffer message.
+ ///
+ /// For URLs which use the scheme `http`, `https`, or no scheme, the
+ /// following restrictions and interpretations apply:
+ ///
+ /// * If no scheme is provided, `https` is assumed.
+ /// * The last segment of the URL's path must represent the fully
+ /// qualified name of the type (as in `path/google.protobuf.Duration`).
+ /// The name should be in a canonical form (e.g., leading "." is
+ /// not accepted).
+ /// * An HTTP GET on the URL must yield a [google.protobuf.Type][]
+ /// value in binary format, or produce an error.
+ /// * Applications are allowed to cache lookup results based on the
+ /// URL, or have them precompiled into a binary to avoid any
+ /// lookup. Therefore, binary compatibility needs to be preserved
+ /// on changes to types. (Use versioned type names to manage
+ /// breaking changes.)
+ ///
+ /// Schemes other than `http`, `https` (or the empty scheme) might be
+ /// used with implementation specific semantics.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string TypeUrl {
+ get { return typeUrl_; }
+ set {
+ typeUrl_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "value" field.</summary>
+ public const int ValueFieldNumber = 2;
+ private pb::ByteString value_ = pb::ByteString.Empty;
+ /// <summary>
+ /// Must be a valid serialized protocol buffer of the above specified type.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pb::ByteString Value {
+ get { return value_; }
+ set {
+ value_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Any);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Any other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (TypeUrl != other.TypeUrl) return false;
+ if (Value != other.Value) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (TypeUrl.Length != 0) hash ^= TypeUrl.GetHashCode();
+ if (Value.Length != 0) hash ^= Value.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (TypeUrl.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(TypeUrl);
+ }
+ if (Value.Length != 0) {
+ output.WriteRawTag(18);
+ output.WriteBytes(Value);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (TypeUrl.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(TypeUrl);
+ }
+ if (Value.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeBytesSize(Value);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Any other) {
+ if (other == null) {
+ return;
+ }
+ if (other.TypeUrl.Length != 0) {
+ TypeUrl = other.TypeUrl;
+ }
+ if (other.Value.Length != 0) {
+ Value = other.Value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ TypeUrl = input.ReadString();
+ break;
+ }
+ case 18: {
+ Value = input.ReadBytes();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs
new file mode 100644
index 0000000000..f4fac73865
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs
@@ -0,0 +1,107 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using Google.Protobuf.Reflection;
+
+namespace Google.Protobuf.WellKnownTypes
+{
+ public partial class Any
+ {
+ private const string DefaultPrefix = "type.googleapis.com";
+
+ // This could be moved to MessageDescriptor if we wanted to, but keeping it here means
+ // all the Any-specific code is in the same place.
+ private static string GetTypeUrl(MessageDescriptor descriptor, string prefix) =>
+ prefix.EndsWith("/") ? prefix + descriptor.FullName : prefix + "/" + descriptor.FullName;
+
+ /// <summary>
+ /// Retrieves the type name for a type URL. This is always just the last part of the URL,
+ /// after the trailing slash. No validation of anything before the trailing slash is performed.
+ /// If the type URL does not include a slash, an empty string is returned rather than an exception
+ /// being thrown; this won't match any types, and the calling code is probably in a better position
+ /// to give a meaningful error.
+ /// There is no handling of fragments or queries at the moment.
+ /// </summary>
+ /// <param name="typeUrl">The URL to extract the type name from</param>
+ /// <returns>The type name</returns>
+ internal static string GetTypeName(string typeUrl)
+ {
+ int lastSlash = typeUrl.LastIndexOf('/');
+ return lastSlash == -1 ? "" : typeUrl.Substring(lastSlash + 1);
+ }
+
+ /// <summary>
+ /// Unpacks the content of this Any message into the target message type,
+ /// which must match the type URL within this Any message.
+ /// </summary>
+ /// <typeparam name="T">The type of message to unpack the content into.</typeparam>
+ /// <returns>The unpacked message.</returns>
+ /// <exception cref="InvalidProtocolBufferException">The target message type doesn't match the type URL in this message</exception>
+ public T Unpack<T>() where T : IMessage, new()
+ {
+ // Note: this doesn't perform as well is it might. We could take a MessageParser<T> in an alternative overload,
+ // which would be expected to perform slightly better... although the difference is likely to be negligible.
+ T target = new T();
+ if (GetTypeName(TypeUrl) != target.Descriptor.FullName)
+ {
+ throw new InvalidProtocolBufferException(
+ $"Full type name for {target.Descriptor.Name} is {target.Descriptor.FullName}; Any message's type url is {TypeUrl}");
+ }
+ target.MergeFrom(Value);
+ return target;
+ }
+
+ /// <summary>
+ /// Packs the specified message into an Any message using a type URL prefix of "type.googleapis.com".
+ /// </summary>
+ /// <param name="message">The message to pack.</param>
+ /// <returns>An Any message with the content and type URL of <paramref name="message"/>.</returns>
+ public static Any Pack(IMessage message) => Pack(message, DefaultPrefix);
+
+ /// <summary>
+ /// Packs the specified message into an Any message using the specified type URL prefix.
+ /// </summary>
+ /// <param name="message">The message to pack.</param>
+ /// <param name="typeUrlPrefix">The prefix for the type URL.</param>
+ /// <returns>An Any message with the content and type URL of <paramref name="message"/>.</returns>
+ public static Any Pack(IMessage message, string typeUrlPrefix)
+ {
+ ProtoPreconditions.CheckNotNull(message, nameof(message));
+ ProtoPreconditions.CheckNotNull(typeUrlPrefix, nameof(typeUrlPrefix));
+ return new Any
+ {
+ TypeUrl = GetTypeUrl(message.Descriptor, typeUrlPrefix),
+ Value = message.ToByteString()
+ };
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs
new file mode 100644
index 0000000000..aeeb8e7392
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs
@@ -0,0 +1,902 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/api.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.WellKnownTypes {
+
+ /// <summary>Holder for reflection information generated from google/protobuf/api.proto</summary>
+ public static partial class ApiReflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for google/protobuf/api.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static ApiReflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "Chlnb29nbGUvcHJvdG9idWYvYXBpLnByb3RvEg9nb29nbGUucHJvdG9idWYa",
+ "JGdvb2dsZS9wcm90b2J1Zi9zb3VyY2VfY29udGV4dC5wcm90bxoaZ29vZ2xl",
+ "L3Byb3RvYnVmL3R5cGUucHJvdG8igQIKA0FwaRIMCgRuYW1lGAEgASgJEigK",
+ "B21ldGhvZHMYAiADKAsyFy5nb29nbGUucHJvdG9idWYuTWV0aG9kEigKB29w",
+ "dGlvbnMYAyADKAsyFy5nb29nbGUucHJvdG9idWYuT3B0aW9uEg8KB3ZlcnNp",
+ "b24YBCABKAkSNgoOc291cmNlX2NvbnRleHQYBSABKAsyHi5nb29nbGUucHJv",
+ "dG9idWYuU291cmNlQ29udGV4dBImCgZtaXhpbnMYBiADKAsyFi5nb29nbGUu",
+ "cHJvdG9idWYuTWl4aW4SJwoGc3ludGF4GAcgASgOMhcuZ29vZ2xlLnByb3Rv",
+ "YnVmLlN5bnRheCLVAQoGTWV0aG9kEgwKBG5hbWUYASABKAkSGAoQcmVxdWVz",
+ "dF90eXBlX3VybBgCIAEoCRIZChFyZXF1ZXN0X3N0cmVhbWluZxgDIAEoCBIZ",
+ "ChFyZXNwb25zZV90eXBlX3VybBgEIAEoCRIaChJyZXNwb25zZV9zdHJlYW1p",
+ "bmcYBSABKAgSKAoHb3B0aW9ucxgGIAMoCzIXLmdvb2dsZS5wcm90b2J1Zi5P",
+ "cHRpb24SJwoGc3ludGF4GAcgASgOMhcuZ29vZ2xlLnByb3RvYnVmLlN5bnRh",
+ "eCIjCgVNaXhpbhIMCgRuYW1lGAEgASgJEgwKBHJvb3QYAiABKAlCdQoTY29t",
+ "Lmdvb2dsZS5wcm90b2J1ZkIIQXBpUHJvdG9QAVorZ29vZ2xlLmdvbGFuZy5v",
+ "cmcvZ2VucHJvdG8vcHJvdG9idWYvYXBpO2FwaaICA0dQQqoCHkdvb2dsZS5Q",
+ "cm90b2J1Zi5XZWxsS25vd25UeXBlc2IGcHJvdG8z"));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.SourceContextReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.TypeReflection.Descriptor, },
+ new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.Api), global::Google.Protobuf.WellKnownTypes.Api.Parser, new[]{ "Name", "Methods", "Options", "Version", "SourceContext", "Mixins", "Syntax" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.Method), global::Google.Protobuf.WellKnownTypes.Method.Parser, new[]{ "Name", "RequestTypeUrl", "RequestStreaming", "ResponseTypeUrl", "ResponseStreaming", "Options", "Syntax" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.Mixin), global::Google.Protobuf.WellKnownTypes.Mixin.Parser, new[]{ "Name", "Root" }, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Messages
+ /// <summary>
+ /// Api is a light-weight descriptor for a protocol buffer service.
+ /// </summary>
+ public sealed partial class Api : pb::IMessage<Api> {
+ private static readonly pb::MessageParser<Api> _parser = new pb::MessageParser<Api>(() => new Api());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Api> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.ApiReflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Api() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Api(Api other) : this() {
+ name_ = other.name_;
+ methods_ = other.methods_.Clone();
+ options_ = other.options_.Clone();
+ version_ = other.version_;
+ SourceContext = other.sourceContext_ != null ? other.SourceContext.Clone() : null;
+ mixins_ = other.mixins_.Clone();
+ syntax_ = other.syntax_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Api Clone() {
+ return new Api(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ /// <summary>
+ /// The fully qualified name of this api, including package name
+ /// followed by the api's simple name.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "methods" field.</summary>
+ public const int MethodsFieldNumber = 2;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Method> _repeated_methods_codec
+ = pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Method.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Method> methods_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Method>();
+ /// <summary>
+ /// The methods of this api, in unspecified order.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Method> Methods {
+ get { return methods_; }
+ }
+
+ /// <summary>Field number for the "options" field.</summary>
+ public const int OptionsFieldNumber = 3;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Option> _repeated_options_codec
+ = pb::FieldCodec.ForMessage(26, global::Google.Protobuf.WellKnownTypes.Option.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option> options_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option>();
+ /// <summary>
+ /// Any metadata attached to the API.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option> Options {
+ get { return options_; }
+ }
+
+ /// <summary>Field number for the "version" field.</summary>
+ public const int VersionFieldNumber = 4;
+ private string version_ = "";
+ /// <summary>
+ /// A version string for this api. If specified, must have the form
+ /// `major-version.minor-version`, as in `1.10`. If the minor version
+ /// is omitted, it defaults to zero. If the entire version field is
+ /// empty, the major version is derived from the package name, as
+ /// outlined below. If the field is not empty, the version in the
+ /// package name will be verified to be consistent with what is
+ /// provided here.
+ ///
+ /// The versioning schema uses [semantic
+ /// versioning](http://semver.org) where the major version number
+ /// indicates a breaking change and the minor version an additive,
+ /// non-breaking change. Both version numbers are signals to users
+ /// what to expect from different versions, and should be carefully
+ /// chosen based on the product plan.
+ ///
+ /// The major version is also reflected in the package name of the
+ /// API, which must end in `v&lt;major-version>`, as in
+ /// `google.feature.v1`. For major versions 0 and 1, the suffix can
+ /// be omitted. Zero major versions must only be used for
+ /// experimental, none-GA apis.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Version {
+ get { return version_; }
+ set {
+ version_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "source_context" field.</summary>
+ public const int SourceContextFieldNumber = 5;
+ private global::Google.Protobuf.WellKnownTypes.SourceContext sourceContext_;
+ /// <summary>
+ /// Source context for the protocol buffer service represented by this
+ /// message.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.SourceContext SourceContext {
+ get { return sourceContext_; }
+ set {
+ sourceContext_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "mixins" field.</summary>
+ public const int MixinsFieldNumber = 6;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Mixin> _repeated_mixins_codec
+ = pb::FieldCodec.ForMessage(50, global::Google.Protobuf.WellKnownTypes.Mixin.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Mixin> mixins_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Mixin>();
+ /// <summary>
+ /// Included APIs. See [Mixin][].
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Mixin> Mixins {
+ get { return mixins_; }
+ }
+
+ /// <summary>Field number for the "syntax" field.</summary>
+ public const int SyntaxFieldNumber = 7;
+ private global::Google.Protobuf.WellKnownTypes.Syntax syntax_ = 0;
+ /// <summary>
+ /// The source syntax of the service.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Syntax Syntax {
+ get { return syntax_; }
+ set {
+ syntax_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Api);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Api other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ if(!methods_.Equals(other.methods_)) return false;
+ if(!options_.Equals(other.options_)) return false;
+ if (Version != other.Version) return false;
+ if (!object.Equals(SourceContext, other.SourceContext)) return false;
+ if(!mixins_.Equals(other.mixins_)) return false;
+ if (Syntax != other.Syntax) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ hash ^= methods_.GetHashCode();
+ hash ^= options_.GetHashCode();
+ if (Version.Length != 0) hash ^= Version.GetHashCode();
+ if (sourceContext_ != null) hash ^= SourceContext.GetHashCode();
+ hash ^= mixins_.GetHashCode();
+ if (Syntax != 0) hash ^= Syntax.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ methods_.WriteTo(output, _repeated_methods_codec);
+ options_.WriteTo(output, _repeated_options_codec);
+ if (Version.Length != 0) {
+ output.WriteRawTag(34);
+ output.WriteString(Version);
+ }
+ if (sourceContext_ != null) {
+ output.WriteRawTag(42);
+ output.WriteMessage(SourceContext);
+ }
+ mixins_.WriteTo(output, _repeated_mixins_codec);
+ if (Syntax != 0) {
+ output.WriteRawTag(56);
+ output.WriteEnum((int) Syntax);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ size += methods_.CalculateSize(_repeated_methods_codec);
+ size += options_.CalculateSize(_repeated_options_codec);
+ if (Version.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Version);
+ }
+ if (sourceContext_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(SourceContext);
+ }
+ size += mixins_.CalculateSize(_repeated_mixins_codec);
+ if (Syntax != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Syntax);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Api other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ methods_.Add(other.methods_);
+ options_.Add(other.options_);
+ if (other.Version.Length != 0) {
+ Version = other.Version;
+ }
+ if (other.sourceContext_ != null) {
+ if (sourceContext_ == null) {
+ sourceContext_ = new global::Google.Protobuf.WellKnownTypes.SourceContext();
+ }
+ SourceContext.MergeFrom(other.SourceContext);
+ }
+ mixins_.Add(other.mixins_);
+ if (other.Syntax != 0) {
+ Syntax = other.Syntax;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 18: {
+ methods_.AddEntriesFrom(input, _repeated_methods_codec);
+ break;
+ }
+ case 26: {
+ options_.AddEntriesFrom(input, _repeated_options_codec);
+ break;
+ }
+ case 34: {
+ Version = input.ReadString();
+ break;
+ }
+ case 42: {
+ if (sourceContext_ == null) {
+ sourceContext_ = new global::Google.Protobuf.WellKnownTypes.SourceContext();
+ }
+ input.ReadMessage(sourceContext_);
+ break;
+ }
+ case 50: {
+ mixins_.AddEntriesFrom(input, _repeated_mixins_codec);
+ break;
+ }
+ case 56: {
+ syntax_ = (global::Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Method represents a method of an api.
+ /// </summary>
+ public sealed partial class Method : pb::IMessage<Method> {
+ private static readonly pb::MessageParser<Method> _parser = new pb::MessageParser<Method>(() => new Method());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Method> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.ApiReflection.Descriptor.MessageTypes[1]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Method() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Method(Method other) : this() {
+ name_ = other.name_;
+ requestTypeUrl_ = other.requestTypeUrl_;
+ requestStreaming_ = other.requestStreaming_;
+ responseTypeUrl_ = other.responseTypeUrl_;
+ responseStreaming_ = other.responseStreaming_;
+ options_ = other.options_.Clone();
+ syntax_ = other.syntax_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Method Clone() {
+ return new Method(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ /// <summary>
+ /// The simple name of this method.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "request_type_url" field.</summary>
+ public const int RequestTypeUrlFieldNumber = 2;
+ private string requestTypeUrl_ = "";
+ /// <summary>
+ /// A URL of the input message type.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string RequestTypeUrl {
+ get { return requestTypeUrl_; }
+ set {
+ requestTypeUrl_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "request_streaming" field.</summary>
+ public const int RequestStreamingFieldNumber = 3;
+ private bool requestStreaming_;
+ /// <summary>
+ /// If true, the request is streamed.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool RequestStreaming {
+ get { return requestStreaming_; }
+ set {
+ requestStreaming_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "response_type_url" field.</summary>
+ public const int ResponseTypeUrlFieldNumber = 4;
+ private string responseTypeUrl_ = "";
+ /// <summary>
+ /// The URL of the output message type.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string ResponseTypeUrl {
+ get { return responseTypeUrl_; }
+ set {
+ responseTypeUrl_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "response_streaming" field.</summary>
+ public const int ResponseStreamingFieldNumber = 5;
+ private bool responseStreaming_;
+ /// <summary>
+ /// If true, the response is streamed.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool ResponseStreaming {
+ get { return responseStreaming_; }
+ set {
+ responseStreaming_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "options" field.</summary>
+ public const int OptionsFieldNumber = 6;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Option> _repeated_options_codec
+ = pb::FieldCodec.ForMessage(50, global::Google.Protobuf.WellKnownTypes.Option.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option> options_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option>();
+ /// <summary>
+ /// Any metadata attached to the method.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option> Options {
+ get { return options_; }
+ }
+
+ /// <summary>Field number for the "syntax" field.</summary>
+ public const int SyntaxFieldNumber = 7;
+ private global::Google.Protobuf.WellKnownTypes.Syntax syntax_ = 0;
+ /// <summary>
+ /// The source syntax of this method.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Syntax Syntax {
+ get { return syntax_; }
+ set {
+ syntax_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Method);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Method other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ if (RequestTypeUrl != other.RequestTypeUrl) return false;
+ if (RequestStreaming != other.RequestStreaming) return false;
+ if (ResponseTypeUrl != other.ResponseTypeUrl) return false;
+ if (ResponseStreaming != other.ResponseStreaming) return false;
+ if(!options_.Equals(other.options_)) return false;
+ if (Syntax != other.Syntax) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ if (RequestTypeUrl.Length != 0) hash ^= RequestTypeUrl.GetHashCode();
+ if (RequestStreaming != false) hash ^= RequestStreaming.GetHashCode();
+ if (ResponseTypeUrl.Length != 0) hash ^= ResponseTypeUrl.GetHashCode();
+ if (ResponseStreaming != false) hash ^= ResponseStreaming.GetHashCode();
+ hash ^= options_.GetHashCode();
+ if (Syntax != 0) hash ^= Syntax.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ if (RequestTypeUrl.Length != 0) {
+ output.WriteRawTag(18);
+ output.WriteString(RequestTypeUrl);
+ }
+ if (RequestStreaming != false) {
+ output.WriteRawTag(24);
+ output.WriteBool(RequestStreaming);
+ }
+ if (ResponseTypeUrl.Length != 0) {
+ output.WriteRawTag(34);
+ output.WriteString(ResponseTypeUrl);
+ }
+ if (ResponseStreaming != false) {
+ output.WriteRawTag(40);
+ output.WriteBool(ResponseStreaming);
+ }
+ options_.WriteTo(output, _repeated_options_codec);
+ if (Syntax != 0) {
+ output.WriteRawTag(56);
+ output.WriteEnum((int) Syntax);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ if (RequestTypeUrl.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(RequestTypeUrl);
+ }
+ if (RequestStreaming != false) {
+ size += 1 + 1;
+ }
+ if (ResponseTypeUrl.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(ResponseTypeUrl);
+ }
+ if (ResponseStreaming != false) {
+ size += 1 + 1;
+ }
+ size += options_.CalculateSize(_repeated_options_codec);
+ if (Syntax != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Syntax);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Method other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ if (other.RequestTypeUrl.Length != 0) {
+ RequestTypeUrl = other.RequestTypeUrl;
+ }
+ if (other.RequestStreaming != false) {
+ RequestStreaming = other.RequestStreaming;
+ }
+ if (other.ResponseTypeUrl.Length != 0) {
+ ResponseTypeUrl = other.ResponseTypeUrl;
+ }
+ if (other.ResponseStreaming != false) {
+ ResponseStreaming = other.ResponseStreaming;
+ }
+ options_.Add(other.options_);
+ if (other.Syntax != 0) {
+ Syntax = other.Syntax;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 18: {
+ RequestTypeUrl = input.ReadString();
+ break;
+ }
+ case 24: {
+ RequestStreaming = input.ReadBool();
+ break;
+ }
+ case 34: {
+ ResponseTypeUrl = input.ReadString();
+ break;
+ }
+ case 40: {
+ ResponseStreaming = input.ReadBool();
+ break;
+ }
+ case 50: {
+ options_.AddEntriesFrom(input, _repeated_options_codec);
+ break;
+ }
+ case 56: {
+ syntax_ = (global::Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Declares an API to be included in this API. The including API must
+ /// redeclare all the methods from the included API, but documentation
+ /// and options are inherited as follows:
+ ///
+ /// - If after comment and whitespace stripping, the documentation
+ /// string of the redeclared method is empty, it will be inherited
+ /// from the original method.
+ ///
+ /// - Each annotation belonging to the service config (http,
+ /// visibility) which is not set in the redeclared method will be
+ /// inherited.
+ ///
+ /// - If an http annotation is inherited, the path pattern will be
+ /// modified as follows. Any version prefix will be replaced by the
+ /// version of the including API plus the [root][] path if specified.
+ ///
+ /// Example of a simple mixin:
+ ///
+ /// package google.acl.v1;
+ /// service AccessControl {
+ /// // Get the underlying ACL object.
+ /// rpc GetAcl(GetAclRequest) returns (Acl) {
+ /// option (google.api.http).get = "/v1/{resource=**}:getAcl";
+ /// }
+ /// }
+ ///
+ /// package google.storage.v2;
+ /// service Storage {
+ /// rpc GetAcl(GetAclRequest) returns (Acl);
+ ///
+ /// // Get a data record.
+ /// rpc GetData(GetDataRequest) returns (Data) {
+ /// option (google.api.http).get = "/v2/{resource=**}";
+ /// }
+ /// }
+ ///
+ /// Example of a mixin configuration:
+ ///
+ /// apis:
+ /// - name: google.storage.v2.Storage
+ /// mixins:
+ /// - name: google.acl.v1.AccessControl
+ ///
+ /// The mixin construct implies that all methods in `AccessControl` are
+ /// also declared with same name and request/response types in
+ /// `Storage`. A documentation generator or annotation processor will
+ /// see the effective `Storage.GetAcl` method after inherting
+ /// documentation and annotations as follows:
+ ///
+ /// service Storage {
+ /// // Get the underlying ACL object.
+ /// rpc GetAcl(GetAclRequest) returns (Acl) {
+ /// option (google.api.http).get = "/v2/{resource=**}:getAcl";
+ /// }
+ /// ...
+ /// }
+ ///
+ /// Note how the version in the path pattern changed from `v1` to `v2`.
+ ///
+ /// If the `root` field in the mixin is specified, it should be a
+ /// relative path under which inherited HTTP paths are placed. Example:
+ ///
+ /// apis:
+ /// - name: google.storage.v2.Storage
+ /// mixins:
+ /// - name: google.acl.v1.AccessControl
+ /// root: acls
+ ///
+ /// This implies the following inherited HTTP annotation:
+ ///
+ /// service Storage {
+ /// // Get the underlying ACL object.
+ /// rpc GetAcl(GetAclRequest) returns (Acl) {
+ /// option (google.api.http).get = "/v2/acls/{resource=**}:getAcl";
+ /// }
+ /// ...
+ /// }
+ /// </summary>
+ public sealed partial class Mixin : pb::IMessage<Mixin> {
+ private static readonly pb::MessageParser<Mixin> _parser = new pb::MessageParser<Mixin>(() => new Mixin());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Mixin> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.ApiReflection.Descriptor.MessageTypes[2]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Mixin() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Mixin(Mixin other) : this() {
+ name_ = other.name_;
+ root_ = other.root_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Mixin Clone() {
+ return new Mixin(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ /// <summary>
+ /// The fully qualified name of the API which is included.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "root" field.</summary>
+ public const int RootFieldNumber = 2;
+ private string root_ = "";
+ /// <summary>
+ /// If non-empty specifies a path under which inherited HTTP paths
+ /// are rooted.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Root {
+ get { return root_; }
+ set {
+ root_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Mixin);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Mixin other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ if (Root != other.Root) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ if (Root.Length != 0) hash ^= Root.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ if (Root.Length != 0) {
+ output.WriteRawTag(18);
+ output.WriteString(Root);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ if (Root.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Root);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Mixin other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ if (other.Root.Length != 0) {
+ Root = other.Root;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 18: {
+ Root = input.ReadString();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs
new file mode 100644
index 0000000000..03b19c774c
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs
@@ -0,0 +1,250 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/duration.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.WellKnownTypes {
+
+ /// <summary>Holder for reflection information generated from google/protobuf/duration.proto</summary>
+ public static partial class DurationReflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for google/protobuf/duration.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static DurationReflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "Ch5nb29nbGUvcHJvdG9idWYvZHVyYXRpb24ucHJvdG8SD2dvb2dsZS5wcm90",
+ "b2J1ZiIqCghEdXJhdGlvbhIPCgdzZWNvbmRzGAEgASgDEg0KBW5hbm9zGAIg",
+ "ASgFQnwKE2NvbS5nb29nbGUucHJvdG9idWZCDUR1cmF0aW9uUHJvdG9QAVoq",
+ "Z2l0aHViLmNvbS9nb2xhbmcvcHJvdG9idWYvcHR5cGVzL2R1cmF0aW9u+AEB",
+ "ogIDR1BCqgIeR29vZ2xlLlByb3RvYnVmLldlbGxLbm93blR5cGVzYgZwcm90",
+ "bzM="));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { },
+ new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.Duration), global::Google.Protobuf.WellKnownTypes.Duration.Parser, new[]{ "Seconds", "Nanos" }, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Messages
+ /// <summary>
+ /// A Duration represents a signed, fixed-length span of time represented
+ /// as a count of seconds and fractions of seconds at nanosecond
+ /// resolution. It is independent of any calendar and concepts like "day"
+ /// or "month". It is related to Timestamp in that the difference between
+ /// two Timestamp values is a Duration and it can be added or subtracted
+ /// from a Timestamp. Range is approximately +-10,000 years.
+ ///
+ /// Example 1: Compute Duration from two Timestamps in pseudo code.
+ ///
+ /// Timestamp start = ...;
+ /// Timestamp end = ...;
+ /// Duration duration = ...;
+ ///
+ /// duration.seconds = end.seconds - start.seconds;
+ /// duration.nanos = end.nanos - start.nanos;
+ ///
+ /// if (duration.seconds &lt; 0 &amp;&amp; duration.nanos > 0) {
+ /// duration.seconds += 1;
+ /// duration.nanos -= 1000000000;
+ /// } else if (durations.seconds > 0 &amp;&amp; duration.nanos &lt; 0) {
+ /// duration.seconds -= 1;
+ /// duration.nanos += 1000000000;
+ /// }
+ ///
+ /// Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
+ ///
+ /// Timestamp start = ...;
+ /// Duration duration = ...;
+ /// Timestamp end = ...;
+ ///
+ /// end.seconds = start.seconds + duration.seconds;
+ /// end.nanos = start.nanos + duration.nanos;
+ ///
+ /// if (end.nanos &lt; 0) {
+ /// end.seconds -= 1;
+ /// end.nanos += 1000000000;
+ /// } else if (end.nanos >= 1000000000) {
+ /// 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)
+ /// </summary>
+ public sealed partial class Duration : pb::IMessage<Duration> {
+ private static readonly pb::MessageParser<Duration> _parser = new pb::MessageParser<Duration>(() => new Duration());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Duration> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.DurationReflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Duration() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Duration(Duration other) : this() {
+ seconds_ = other.seconds_;
+ nanos_ = other.nanos_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Duration Clone() {
+ return new Duration(this);
+ }
+
+ /// <summary>Field number for the "seconds" field.</summary>
+ public const int SecondsFieldNumber = 1;
+ private long seconds_;
+ /// <summary>
+ /// Signed seconds of the span of time. Must be from -315,576,000,000
+ /// to +315,576,000,000 inclusive.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public long Seconds {
+ get { return seconds_; }
+ set {
+ seconds_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "nanos" field.</summary>
+ public const int NanosFieldNumber = 2;
+ private int nanos_;
+ /// <summary>
+ /// Signed fractions of a second at nanosecond resolution of the span
+ /// of time. Durations less than one second are represented with a 0
+ /// `seconds` field and a positive or negative `nanos` field. For durations
+ /// of one second or more, a non-zero value for the `nanos` field must be
+ /// of the same sign as the `seconds` field. Must be from -999,999,999
+ /// to +999,999,999 inclusive.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Nanos {
+ get { return nanos_; }
+ set {
+ nanos_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Duration);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Duration other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Seconds != other.Seconds) return false;
+ if (Nanos != other.Nanos) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Seconds != 0L) hash ^= Seconds.GetHashCode();
+ if (Nanos != 0) hash ^= Nanos.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Seconds != 0L) {
+ output.WriteRawTag(8);
+ output.WriteInt64(Seconds);
+ }
+ if (Nanos != 0) {
+ output.WriteRawTag(16);
+ output.WriteInt32(Nanos);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Seconds != 0L) {
+ size += 1 + pb::CodedOutputStream.ComputeInt64Size(Seconds);
+ }
+ if (Nanos != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Nanos);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Duration other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Seconds != 0L) {
+ Seconds = other.Seconds;
+ }
+ if (other.Nanos != 0) {
+ Nanos = other.Nanos;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Seconds = input.ReadInt64();
+ break;
+ }
+ case 16: {
+ Nanos = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/DurationPartial.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/DurationPartial.cs
new file mode 100644
index 0000000000..f164bfd19d
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/DurationPartial.cs
@@ -0,0 +1,270 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.Globalization;
+using System.Text;
+
+namespace Google.Protobuf.WellKnownTypes
+{
+ // Manually-written partial class for the Duration well-known type,
+ // providing a conversion to TimeSpan and convenience operators.
+ public partial class Duration : ICustomDiagnosticMessage
+ {
+ /// <summary>
+ /// The number of nanoseconds in a second.
+ /// </summary>
+ public const int NanosecondsPerSecond = 1000000000;
+ /// <summary>
+ /// The number of nanoseconds in a BCL tick (as used by <see cref="TimeSpan"/> and <see cref="DateTime"/>).
+ /// </summary>
+ public const int NanosecondsPerTick = 100;
+
+ /// <summary>
+ /// The maximum permitted number of seconds.
+ /// </summary>
+ public const long MaxSeconds = 315576000000L;
+
+ /// <summary>
+ /// The minimum permitted number of seconds.
+ /// </summary>
+ public const long MinSeconds = -315576000000L;
+
+ internal const int MaxNanoseconds = NanosecondsPerSecond - 1;
+ internal const int MinNanoseconds = -NanosecondsPerSecond + 1;
+
+ internal static bool IsNormalized(long seconds, int nanoseconds)
+ {
+ // Simple boundaries
+ if (seconds < MinSeconds || seconds > MaxSeconds ||
+ nanoseconds < MinNanoseconds || nanoseconds > MaxNanoseconds)
+ {
+ return false;
+ }
+ // We only have a problem is one is strictly negative and the other is
+ // strictly positive.
+ return Math.Sign(seconds) * Math.Sign(nanoseconds) != -1;
+ }
+
+ /// <summary>
+ /// Converts this <see cref="Duration"/> to a <see cref="TimeSpan"/>.
+ /// </summary>
+ /// <remarks>If the duration is not a precise number of ticks, it is truncated towards 0.</remarks>
+ /// <returns>The value of this duration, as a <c>TimeSpan</c>.</returns>
+ /// <exception cref="InvalidOperationException">This value isn't a valid normalized duration, as
+ /// described in the documentation.</exception>
+ public TimeSpan ToTimeSpan()
+ {
+ checked
+ {
+ if (!IsNormalized(Seconds, Nanos))
+ {
+ throw new InvalidOperationException("Duration was not a valid normalized duration");
+ }
+ long ticks = Seconds * TimeSpan.TicksPerSecond + Nanos / NanosecondsPerTick;
+ return TimeSpan.FromTicks(ticks);
+ }
+ }
+
+ /// <summary>
+ /// Converts the given <see cref="TimeSpan"/> to a <see cref="Duration"/>.
+ /// </summary>
+ /// <param name="timeSpan">The <c>TimeSpan</c> to convert.</param>
+ /// <returns>The value of the given <c>TimeSpan</c>, as a <c>Duration</c>.</returns>
+ public static Duration FromTimeSpan(TimeSpan timeSpan)
+ {
+ checked
+ {
+ long ticks = timeSpan.Ticks;
+ long seconds = ticks / TimeSpan.TicksPerSecond;
+ int nanos = (int) (ticks % TimeSpan.TicksPerSecond) * NanosecondsPerTick;
+ return new Duration { Seconds = seconds, Nanos = nanos };
+ }
+ }
+
+ /// <summary>
+ /// Returns the result of negating the duration. For example, the negation of 5 minutes is -5 minutes.
+ /// </summary>
+ /// <param name="value">The duration to negate. Must not be null.</param>
+ /// <returns>The negated value of this duration.</returns>
+ public static Duration operator -(Duration value)
+ {
+ ProtoPreconditions.CheckNotNull(value, "value");
+ checked
+ {
+ return Normalize(-value.Seconds, -value.Nanos);
+ }
+ }
+
+ /// <summary>
+ /// Adds the two specified <see cref="Duration"/> values together.
+ /// </summary>
+ /// <param name="lhs">The first value to add. Must not be null.</param>
+ /// <param name="rhs">The second value to add. Must not be null.</param>
+ /// <returns></returns>
+ public static Duration operator +(Duration lhs, Duration rhs)
+ {
+ ProtoPreconditions.CheckNotNull(lhs, "lhs");
+ ProtoPreconditions.CheckNotNull(rhs, "rhs");
+ checked
+ {
+ return Normalize(lhs.Seconds + rhs.Seconds, lhs.Nanos + rhs.Nanos);
+ }
+ }
+
+ /// <summary>
+ /// Subtracts one <see cref="Duration"/> from another.
+ /// </summary>
+ /// <param name="lhs">The duration to subtract from. Must not be null.</param>
+ /// <param name="rhs">The duration to subtract. Must not be null.</param>
+ /// <returns>The difference between the two specified durations.</returns>
+ public static Duration operator -(Duration lhs, Duration rhs)
+ {
+ ProtoPreconditions.CheckNotNull(lhs, "lhs");
+ ProtoPreconditions.CheckNotNull(rhs, "rhs");
+ checked
+ {
+ return Normalize(lhs.Seconds - rhs.Seconds, lhs.Nanos - rhs.Nanos);
+ }
+ }
+
+ /// <summary>
+ /// Creates a duration with the normalized values from the given number of seconds and
+ /// nanoseconds, conforming with the description in the proto file.
+ /// </summary>
+ internal static Duration Normalize(long seconds, int nanoseconds)
+ {
+ // Ensure that nanoseconds is in the range (-1,000,000,000, +1,000,000,000)
+ int extraSeconds = nanoseconds / NanosecondsPerSecond;
+ seconds += extraSeconds;
+ nanoseconds -= extraSeconds * NanosecondsPerSecond;
+
+ // Now make sure that Sign(seconds) == Sign(nanoseconds) if Sign(seconds) != 0.
+ if (seconds < 0 && nanoseconds > 0)
+ {
+ seconds += 1;
+ nanoseconds -= NanosecondsPerSecond;
+ }
+ else if (seconds > 0 && nanoseconds < 0)
+ {
+ seconds -= 1;
+ nanoseconds += NanosecondsPerSecond;
+ }
+ return new Duration { Seconds = seconds, Nanos = nanoseconds };
+ }
+
+ /// <summary>
+ /// Converts a duration specified in seconds/nanoseconds to a string.
+ /// </summary>
+ /// <remarks>
+ /// If the value is a normalized duration in the range described in <c>duration.proto</c>,
+ /// <paramref name="diagnosticOnly"/> is ignored. Otherwise, if the parameter is <c>true</c>,
+ /// a JSON object with a warning is returned; if it is <c>false</c>, an <see cref="InvalidOperationException"/> is thrown.
+ /// </remarks>
+ /// <param name="seconds">Seconds portion of the duration.</param>
+ /// <param name="nanoseconds">Nanoseconds portion of the duration.</param>
+ /// <param name="diagnosticOnly">Determines the handling of non-normalized values</param>
+ /// <exception cref="InvalidOperationException">The represented duration is invalid, and <paramref name="diagnosticOnly"/> is <c>false</c>.</exception>
+ internal static string ToJson(long seconds, int nanoseconds, bool diagnosticOnly)
+ {
+ if (IsNormalized(seconds, nanoseconds))
+ {
+ var builder = new StringBuilder();
+ builder.Append('"');
+ // The seconds part will normally provide the minus sign if we need it, but not if it's 0...
+ if (seconds == 0 && nanoseconds < 0)
+ {
+ builder.Append('-');
+ }
+
+ builder.Append(seconds.ToString("d", CultureInfo.InvariantCulture));
+ AppendNanoseconds(builder, Math.Abs(nanoseconds));
+ builder.Append("s\"");
+ return builder.ToString();
+ }
+ if (diagnosticOnly)
+ {
+ // Note: the double braces here are escaping for braces in format strings.
+ return string.Format(CultureInfo.InvariantCulture,
+ "{{ \"@warning\": \"Invalid Duration\", \"seconds\": \"{0}\", \"nanos\": {1} }}",
+ seconds,
+ nanoseconds);
+ }
+ else
+ {
+ throw new InvalidOperationException("Non-normalized duration value");
+ }
+ }
+
+ /// <summary>
+ /// Returns a string representation of this <see cref="Duration"/> for diagnostic purposes.
+ /// </summary>
+ /// <remarks>
+ /// Normally the returned value will be a JSON string value (including leading and trailing quotes) but
+ /// when the value is non-normalized or out of range, a JSON object representation will be returned
+ /// instead, including a warning. This is to avoid exceptions being thrown when trying to
+ /// diagnose problems - the regular JSON formatter will still throw an exception for non-normalized
+ /// values.
+ /// </remarks>
+ /// <returns>A string representation of this value.</returns>
+ public string ToDiagnosticString()
+ {
+ return ToJson(Seconds, Nanos, true);
+ }
+
+ /// <summary>
+ /// Appends a number of nanoseconds to a StringBuilder. Either 0 digits are added (in which
+ /// case no "." is appended), or 3 6 or 9 digits. This is internal for use in Timestamp as well
+ /// as Duration.
+ /// </summary>
+ internal static void AppendNanoseconds(StringBuilder builder, int nanos)
+ {
+ if (nanos != 0)
+ {
+ builder.Append('.');
+ // Output to 3, 6 or 9 digits.
+ if (nanos % 1000000 == 0)
+ {
+ builder.Append((nanos / 1000000).ToString("d3", CultureInfo.InvariantCulture));
+ }
+ else if (nanos % 1000 == 0)
+ {
+ builder.Append((nanos / 1000).ToString("d6", CultureInfo.InvariantCulture));
+ }
+ else
+ {
+ builder.Append(nanos.ToString("d9", CultureInfo.InvariantCulture));
+ }
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs
new file mode 100644
index 0000000000..aa89e08f59
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs
@@ -0,0 +1,144 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/empty.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.WellKnownTypes {
+
+ /// <summary>Holder for reflection information generated from google/protobuf/empty.proto</summary>
+ public static partial class EmptyReflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for google/protobuf/empty.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static EmptyReflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "Chtnb29nbGUvcHJvdG9idWYvZW1wdHkucHJvdG8SD2dvb2dsZS5wcm90b2J1",
+ "ZiIHCgVFbXB0eUJ2ChNjb20uZ29vZ2xlLnByb3RvYnVmQgpFbXB0eVByb3Rv",
+ "UAFaJ2dpdGh1Yi5jb20vZ29sYW5nL3Byb3RvYnVmL3B0eXBlcy9lbXB0efgB",
+ "AaICA0dQQqoCHkdvb2dsZS5Qcm90b2J1Zi5XZWxsS25vd25UeXBlc2IGcHJv",
+ "dG8z"));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { },
+ new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.Empty), global::Google.Protobuf.WellKnownTypes.Empty.Parser, null, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Messages
+ /// <summary>
+ /// A generic empty message that you can re-use to avoid defining duplicated
+ /// empty messages in your APIs. A typical example is to use it as the request
+ /// or the response type of an API method. For instance:
+ ///
+ /// service Foo {
+ /// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
+ /// }
+ ///
+ /// The JSON representation for `Empty` is empty JSON object `{}`.
+ /// </summary>
+ public sealed partial class Empty : pb::IMessage<Empty> {
+ private static readonly pb::MessageParser<Empty> _parser = new pb::MessageParser<Empty>(() => new Empty());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Empty> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.EmptyReflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Empty() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Empty(Empty other) : this() {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Empty Clone() {
+ return new Empty(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Empty);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Empty other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Empty other) {
+ if (other == null) {
+ return;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs
new file mode 100644
index 0000000000..ef3bc10af7
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs
@@ -0,0 +1,359 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/field_mask.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.WellKnownTypes {
+
+ /// <summary>Holder for reflection information generated from google/protobuf/field_mask.proto</summary>
+ public static partial class FieldMaskReflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for google/protobuf/field_mask.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static FieldMaskReflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "CiBnb29nbGUvcHJvdG9idWYvZmllbGRfbWFzay5wcm90bxIPZ29vZ2xlLnBy",
+ "b3RvYnVmIhoKCUZpZWxkTWFzaxINCgVwYXRocxgBIAMoCUKJAQoTY29tLmdv",
+ "b2dsZS5wcm90b2J1ZkIORmllbGRNYXNrUHJvdG9QAVo5Z29vZ2xlLmdvbGFu",
+ "Zy5vcmcvZ2VucHJvdG8vcHJvdG9idWYvZmllbGRfbWFzaztmaWVsZF9tYXNr",
+ "ogIDR1BCqgIeR29vZ2xlLlByb3RvYnVmLldlbGxLbm93blR5cGVzYgZwcm90",
+ "bzM="));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { },
+ new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.FieldMask), global::Google.Protobuf.WellKnownTypes.FieldMask.Parser, new[]{ "Paths" }, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Messages
+ /// <summary>
+ /// `FieldMask` represents a set of symbolic field paths, for example:
+ ///
+ /// paths: "f.a"
+ /// paths: "f.b.d"
+ ///
+ /// Here `f` represents a field in some root message, `a` and `b`
+ /// fields in the message found in `f`, and `d` a field found in the
+ /// message in `f.b`.
+ ///
+ /// Field masks are used to specify a subset of fields that should be
+ /// returned by a get operation or modified by an update operation.
+ /// Field masks also have a custom JSON encoding (see below).
+ ///
+ /// # Field Masks in Projections
+ ///
+ /// When used in the context of a projection, a response message or
+ /// sub-message is filtered by the API to only contain those fields as
+ /// specified in the mask. For example, if the mask in the previous
+ /// example is applied to a response message as follows:
+ ///
+ /// f {
+ /// a : 22
+ /// b {
+ /// d : 1
+ /// x : 2
+ /// }
+ /// y : 13
+ /// }
+ /// z: 8
+ ///
+ /// The result will not contain specific values for fields x,y and z
+ /// (their value will be set to the default, and omitted in proto text
+ /// output):
+ ///
+ /// f {
+ /// a : 22
+ /// b {
+ /// d : 1
+ /// }
+ /// }
+ ///
+ /// A repeated field is not allowed except at the last position of a
+ /// 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
+ /// had been specified).
+ ///
+ /// Note that a field mask does not necessarily apply to the
+ /// top-level response message. In case of a REST get operation, the
+ /// field mask applies directly to the response, but in case of a REST
+ /// list operation, the mask instead applies to each individual message
+ /// in the returned resource list. In case of a REST custom method,
+ /// other definitions may be used. Where the mask applies will be
+ /// clearly documented together with its declaration in the API. In
+ /// any case, the effect on the returned resource/resources is required
+ /// behavior for APIs.
+ ///
+ /// # Field Masks in Update Operations
+ ///
+ /// A field mask in update operations specifies which fields of the
+ /// targeted resource are going to be updated. The API is required
+ /// to only change the values of the fields as specified in the mask
+ /// and leave the others untouched. If a resource is passed in to
+ /// describe the updated values, the API ignores the values of all
+ /// fields not covered by the mask.
+ ///
+ /// 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 `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
+ /// overwritten. Given the target message:
+ ///
+ /// f {
+ /// b {
+ /// d : 1
+ /// x : 2
+ /// }
+ /// c : 1
+ /// }
+ ///
+ /// And an update message:
+ ///
+ /// f {
+ /// b {
+ /// d : 10
+ /// }
+ /// }
+ ///
+ /// then if the field mask is:
+ ///
+ /// paths: "f.b"
+ ///
+ /// then the result will be:
+ ///
+ /// f {
+ /// b {
+ /// d : 10
+ /// }
+ /// c : 1
+ /// }
+ ///
+ /// However, if the update mask was:
+ ///
+ /// paths: "f.b.d"
+ ///
+ /// then the result would be:
+ ///
+ /// f {
+ /// b {
+ /// d : 10
+ /// x : 2
+ /// }
+ /// c : 1
+ /// }
+ ///
+ /// In order to reset a field's value to the default, the field must
+ /// be in the mask and set to the default value in the provided resource.
+ /// Hence, in order to reset all fields of a resource, provide a default
+ /// instance of the resource and set all fields in the mask, or do
+ /// not provide a mask as described below.
+ ///
+ /// If a field mask is not present on update, the operation applies to
+ /// all fields (as if a field mask of all fields has been specified).
+ /// Note that in the presence of schema evolution, this may mean that
+ /// fields the client does not know and has therefore not filled into
+ /// the request will be reset to their default. If this is unwanted
+ /// behavior, a specific service may require a client to always specify
+ /// a field mask, producing an error if not.
+ ///
+ /// As with get operations, the location of the resource which
+ /// describes the updated values in the request message depends on the
+ /// operation kind. In any case, the effect of the field mask is
+ /// required to be honored by the API.
+ ///
+ /// ## Considerations for HTTP REST
+ ///
+ /// The HTTP kind of an update operation which uses a field mask must
+ /// be set to PATCH instead of PUT in order to satisfy HTTP semantics
+ /// (PUT must only be used for full updates).
+ ///
+ /// # JSON Encoding of Field Masks
+ ///
+ /// In JSON, a field mask is encoded as a single string where paths are
+ /// separated by a comma. Fields name in each path are converted
+ /// to/from lower-camel naming conventions.
+ ///
+ /// As an example, consider the following message declarations:
+ ///
+ /// message Profile {
+ /// User user = 1;
+ /// Photo photo = 2;
+ /// }
+ /// message User {
+ /// string display_name = 1;
+ /// string address = 2;
+ /// }
+ ///
+ /// In proto a field mask for `Profile` may look as such:
+ ///
+ /// mask {
+ /// paths: "user.display_name"
+ /// paths: "photo"
+ /// }
+ ///
+ /// In JSON, the same mask is represented as below:
+ ///
+ /// {
+ /// mask: "user.displayName,photo"
+ /// }
+ ///
+ /// # Field Masks and Oneof Fields
+ ///
+ /// Field masks treat fields in oneofs just as regular fields. Consider the
+ /// following message:
+ ///
+ /// message SampleMessage {
+ /// oneof test_oneof {
+ /// string name = 4;
+ /// SubMessage sub_message = 9;
+ /// }
+ /// }
+ ///
+ /// The field mask can be:
+ ///
+ /// mask {
+ /// paths: "name"
+ /// }
+ ///
+ /// Or:
+ ///
+ /// mask {
+ /// paths: "sub_message"
+ /// }
+ ///
+ /// Note that oneof type names ("test_oneof" in this case) cannot be used in
+ /// paths.
+ /// </summary>
+ public sealed partial class FieldMask : pb::IMessage<FieldMask> {
+ private static readonly pb::MessageParser<FieldMask> _parser = new pb::MessageParser<FieldMask>(() => new FieldMask());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<FieldMask> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.FieldMaskReflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FieldMask() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FieldMask(FieldMask other) : this() {
+ paths_ = other.paths_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FieldMask Clone() {
+ return new FieldMask(this);
+ }
+
+ /// <summary>Field number for the "paths" field.</summary>
+ public const int PathsFieldNumber = 1;
+ private static readonly pb::FieldCodec<string> _repeated_paths_codec
+ = pb::FieldCodec.ForString(10);
+ private readonly pbc::RepeatedField<string> paths_ = new pbc::RepeatedField<string>();
+ /// <summary>
+ /// The set of field mask paths.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<string> Paths {
+ get { return paths_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as FieldMask);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(FieldMask other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if(!paths_.Equals(other.paths_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= paths_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ paths_.WriteTo(output, _repeated_paths_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += paths_.CalculateSize(_repeated_paths_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(FieldMask other) {
+ if (other == null) {
+ return;
+ }
+ paths_.Add(other.paths_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ paths_.AddEntriesFrom(input, _repeated_paths_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs
new file mode 100755
index 0000000000..4b0670f6fd
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/FieldMaskPartial.cs
@@ -0,0 +1,128 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 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.
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+namespace Google.Protobuf.WellKnownTypes
+{
+ // Manually-written partial class for the FieldMask well-known type.
+ public partial class FieldMask : ICustomDiagnosticMessage
+ {
+ /// <summary>
+ /// Converts a timestamp specified in seconds/nanoseconds to a string.
+ /// </summary>
+ /// <remarks>
+ /// If the value is a normalized duration in the range described in <c>field_mask.proto</c>,
+ /// <paramref name="diagnosticOnly"/> is ignored. Otherwise, if the parameter is <c>true</c>,
+ /// a JSON object with a warning is returned; if it is <c>false</c>, an <see cref="InvalidOperationException"/> is thrown.
+ /// </remarks>
+ /// <param name="paths">Paths in the field mask</param>
+ /// <param name="diagnosticOnly">Determines the handling of non-normalized values</param>
+ /// <exception cref="InvalidOperationException">The represented field mask is invalid, and <paramref name="diagnosticOnly"/> is <c>false</c>.</exception>
+ internal static string ToJson(IList<string> paths, bool diagnosticOnly)
+ {
+ var firstInvalid = paths.FirstOrDefault(p => !ValidatePath(p));
+ if (firstInvalid == null)
+ {
+ var writer = new StringWriter();
+#if NET35
+ var query = paths.Select(JsonFormatter.ToJsonName);
+ JsonFormatter.WriteString(writer, string.Join(",", query.ToArray()));
+#else
+ JsonFormatter.WriteString(writer, string.Join(",", paths.Select(JsonFormatter.ToJsonName)));
+#endif
+ return writer.ToString();
+ }
+ else
+ {
+ if (diagnosticOnly)
+ {
+ var writer = new StringWriter();
+ writer.Write("{ \"@warning\": \"Invalid FieldMask\", \"paths\": ");
+ JsonFormatter.Default.WriteList(writer, (IList)paths);
+ writer.Write(" }");
+ return writer.ToString();
+ }
+ else
+ {
+ throw new InvalidOperationException($"Invalid field mask to be converted to JSON: {firstInvalid}");
+ }
+ }
+ }
+
+ /// <summary>
+ /// Checks whether the given path is valid for a field mask.
+ /// </summary>
+ /// <returns>true if the path is valid; false otherwise</returns>
+ private static bool ValidatePath(string input)
+ {
+ for (int i = 0; i < input.Length; i++)
+ {
+ char c = input[i];
+ if (c >= 'A' && c <= 'Z')
+ {
+ return false;
+ }
+ if (c == '_' && i < input.Length - 1)
+ {
+ char next = input[i + 1];
+ if (next < 'a' || next > 'z')
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ /// <summary>
+ /// Returns a string representation of this <see cref="FieldMask"/> for diagnostic purposes.
+ /// </summary>
+ /// <remarks>
+ /// Normally the returned value will be a JSON string value (including leading and trailing quotes) but
+ /// when the value is non-normalized or out of range, a JSON object representation will be returned
+ /// instead, including a warning. This is to avoid exceptions being thrown when trying to
+ /// diagnose problems - the regular JSON formatter will still throw an exception for non-normalized
+ /// values.
+ /// </remarks>
+ /// <returns>A string representation of this value.</returns>
+ public string ToDiagnosticString()
+ {
+ return ToJson(Paths, true);
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs
new file mode 100644
index 0000000000..6ddadf19ae
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs
@@ -0,0 +1,170 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/source_context.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.WellKnownTypes {
+
+ /// <summary>Holder for reflection information generated from google/protobuf/source_context.proto</summary>
+ public static partial class SourceContextReflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for google/protobuf/source_context.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static SourceContextReflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "CiRnb29nbGUvcHJvdG9idWYvc291cmNlX2NvbnRleHQucHJvdG8SD2dvb2ds",
+ "ZS5wcm90b2J1ZiIiCg1Tb3VyY2VDb250ZXh0EhEKCWZpbGVfbmFtZRgBIAEo",
+ "CUKVAQoTY29tLmdvb2dsZS5wcm90b2J1ZkISU291cmNlQ29udGV4dFByb3Rv",
+ "UAFaQWdvb2dsZS5nb2xhbmcub3JnL2dlbnByb3RvL3Byb3RvYnVmL3NvdXJj",
+ "ZV9jb250ZXh0O3NvdXJjZV9jb250ZXh0ogIDR1BCqgIeR29vZ2xlLlByb3Rv",
+ "YnVmLldlbGxLbm93blR5cGVzYgZwcm90bzM="));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { },
+ new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.SourceContext), global::Google.Protobuf.WellKnownTypes.SourceContext.Parser, new[]{ "FileName" }, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Messages
+ /// <summary>
+ /// `SourceContext` represents information about the source of a
+ /// protobuf element, like the file in which it is defined.
+ /// </summary>
+ public sealed partial class SourceContext : pb::IMessage<SourceContext> {
+ private static readonly pb::MessageParser<SourceContext> _parser = new pb::MessageParser<SourceContext>(() => new SourceContext());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<SourceContext> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.SourceContextReflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SourceContext() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SourceContext(SourceContext other) : this() {
+ fileName_ = other.fileName_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public SourceContext Clone() {
+ return new SourceContext(this);
+ }
+
+ /// <summary>Field number for the "file_name" field.</summary>
+ public const int FileNameFieldNumber = 1;
+ private string fileName_ = "";
+ /// <summary>
+ /// The path-qualified name of the .proto file that contained the associated
+ /// protobuf element. For example: `"google/protobuf/source_context.proto"`.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string FileName {
+ get { return fileName_; }
+ set {
+ fileName_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as SourceContext);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(SourceContext other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (FileName != other.FileName) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (FileName.Length != 0) hash ^= FileName.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (FileName.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(FileName);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (FileName.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(FileName);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(SourceContext other) {
+ if (other == null) {
+ return;
+ }
+ if (other.FileName.Length != 0) {
+ FileName = other.FileName;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ FileName = input.ReadString();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs
new file mode 100644
index 0000000000..1fa3552155
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs
@@ -0,0 +1,648 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/struct.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.WellKnownTypes {
+
+ /// <summary>Holder for reflection information generated from google/protobuf/struct.proto</summary>
+ public static partial class StructReflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for google/protobuf/struct.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static StructReflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "Chxnb29nbGUvcHJvdG9idWYvc3RydWN0LnByb3RvEg9nb29nbGUucHJvdG9i",
+ "dWYihAEKBlN0cnVjdBIzCgZmaWVsZHMYASADKAsyIy5nb29nbGUucHJvdG9i",
+ "dWYuU3RydWN0LkZpZWxkc0VudHJ5GkUKC0ZpZWxkc0VudHJ5EgsKA2tleRgB",
+ "IAEoCRIlCgV2YWx1ZRgCIAEoCzIWLmdvb2dsZS5wcm90b2J1Zi5WYWx1ZToC",
+ "OAEi6gEKBVZhbHVlEjAKCm51bGxfdmFsdWUYASABKA4yGi5nb29nbGUucHJv",
+ "dG9idWYuTnVsbFZhbHVlSAASFgoMbnVtYmVyX3ZhbHVlGAIgASgBSAASFgoM",
+ "c3RyaW5nX3ZhbHVlGAMgASgJSAASFAoKYm9vbF92YWx1ZRgEIAEoCEgAEi8K",
+ "DHN0cnVjdF92YWx1ZRgFIAEoCzIXLmdvb2dsZS5wcm90b2J1Zi5TdHJ1Y3RI",
+ "ABIwCgpsaXN0X3ZhbHVlGAYgASgLMhouZ29vZ2xlLnByb3RvYnVmLkxpc3RW",
+ "YWx1ZUgAQgYKBGtpbmQiMwoJTGlzdFZhbHVlEiYKBnZhbHVlcxgBIAMoCzIW",
+ "Lmdvb2dsZS5wcm90b2J1Zi5WYWx1ZSobCglOdWxsVmFsdWUSDgoKTlVMTF9W",
+ "QUxVRRAAQoEBChNjb20uZ29vZ2xlLnByb3RvYnVmQgtTdHJ1Y3RQcm90b1AB",
+ "WjFnaXRodWIuY29tL2dvbGFuZy9wcm90b2J1Zi9wdHlwZXMvc3RydWN0O3N0",
+ "cnVjdHBi+AEBogIDR1BCqgIeR29vZ2xlLlByb3RvYnVmLldlbGxLbm93blR5",
+ "cGVzYgZwcm90bzM="));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { },
+ new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Google.Protobuf.WellKnownTypes.NullValue), }, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.Struct), global::Google.Protobuf.WellKnownTypes.Struct.Parser, new[]{ "Fields" }, null, null, new pbr::GeneratedClrTypeInfo[] { null, }),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.Value), global::Google.Protobuf.WellKnownTypes.Value.Parser, new[]{ "NullValue", "NumberValue", "StringValue", "BoolValue", "StructValue", "ListValue" }, new[]{ "Kind" }, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.ListValue), global::Google.Protobuf.WellKnownTypes.ListValue.Parser, new[]{ "Values" }, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Enums
+ /// <summary>
+ /// `NullValue` is a singleton enumeration to represent the null value for the
+ /// `Value` type union.
+ ///
+ /// The JSON representation for `NullValue` is JSON `null`.
+ /// </summary>
+ public enum NullValue {
+ /// <summary>
+ /// Null value.
+ /// </summary>
+ [pbr::OriginalName("NULL_VALUE")] NullValue = 0,
+ }
+
+ #endregion
+
+ #region Messages
+ /// <summary>
+ /// `Struct` represents a structured data value, consisting of fields
+ /// which map to dynamically typed values. In some languages, `Struct`
+ /// might be supported by a native representation. For example, in
+ /// scripting languages like JS a struct is represented as an
+ /// object. The details of that representation are described together
+ /// with the proto support for the language.
+ ///
+ /// The JSON representation for `Struct` is JSON object.
+ /// </summary>
+ public sealed partial class Struct : pb::IMessage<Struct> {
+ private static readonly pb::MessageParser<Struct> _parser = new pb::MessageParser<Struct>(() => new Struct());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Struct> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.StructReflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Struct() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Struct(Struct other) : this() {
+ fields_ = other.fields_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Struct Clone() {
+ return new Struct(this);
+ }
+
+ /// <summary>Field number for the "fields" field.</summary>
+ public const int FieldsFieldNumber = 1;
+ private static readonly pbc::MapField<string, global::Google.Protobuf.WellKnownTypes.Value>.Codec _map_fields_codec
+ = new pbc::MapField<string, global::Google.Protobuf.WellKnownTypes.Value>.Codec(pb::FieldCodec.ForString(10), pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Value.Parser), 10);
+ private readonly pbc::MapField<string, global::Google.Protobuf.WellKnownTypes.Value> fields_ = new pbc::MapField<string, global::Google.Protobuf.WellKnownTypes.Value>();
+ /// <summary>
+ /// Unordered map of dynamically typed values.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::MapField<string, global::Google.Protobuf.WellKnownTypes.Value> Fields {
+ get { return fields_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Struct);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Struct other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (!Fields.Equals(other.Fields)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= Fields.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ fields_.WriteTo(output, _map_fields_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += fields_.CalculateSize(_map_fields_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Struct other) {
+ if (other == null) {
+ return;
+ }
+ fields_.Add(other.fields_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ fields_.AddEntriesFrom(input, _map_fields_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// `Value` represents a dynamically typed value which can be either
+ /// null, a number, a string, a boolean, a recursive struct value, or a
+ /// list of values. A producer of value is expected to set one of that
+ /// variants, absence of any variant indicates an error.
+ ///
+ /// The JSON representation for `Value` is JSON value.
+ /// </summary>
+ public sealed partial class Value : pb::IMessage<Value> {
+ private static readonly pb::MessageParser<Value> _parser = new pb::MessageParser<Value>(() => new Value());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Value> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.StructReflection.Descriptor.MessageTypes[1]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Value() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Value(Value other) : this() {
+ switch (other.KindCase) {
+ case KindOneofCase.NullValue:
+ NullValue = other.NullValue;
+ break;
+ case KindOneofCase.NumberValue:
+ NumberValue = other.NumberValue;
+ break;
+ case KindOneofCase.StringValue:
+ StringValue = other.StringValue;
+ break;
+ case KindOneofCase.BoolValue:
+ BoolValue = other.BoolValue;
+ break;
+ case KindOneofCase.StructValue:
+ StructValue = other.StructValue.Clone();
+ break;
+ case KindOneofCase.ListValue:
+ ListValue = other.ListValue.Clone();
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Value Clone() {
+ return new Value(this);
+ }
+
+ /// <summary>Field number for the "null_value" field.</summary>
+ public const int NullValueFieldNumber = 1;
+ /// <summary>
+ /// Represents a null value.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.NullValue NullValue {
+ get { return kindCase_ == KindOneofCase.NullValue ? (global::Google.Protobuf.WellKnownTypes.NullValue) kind_ : 0; }
+ set {
+ kind_ = value;
+ kindCase_ = KindOneofCase.NullValue;
+ }
+ }
+
+ /// <summary>Field number for the "number_value" field.</summary>
+ public const int NumberValueFieldNumber = 2;
+ /// <summary>
+ /// Represents a double value.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public double NumberValue {
+ get { return kindCase_ == KindOneofCase.NumberValue ? (double) kind_ : 0D; }
+ set {
+ kind_ = value;
+ kindCase_ = KindOneofCase.NumberValue;
+ }
+ }
+
+ /// <summary>Field number for the "string_value" field.</summary>
+ public const int StringValueFieldNumber = 3;
+ /// <summary>
+ /// Represents a string value.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string StringValue {
+ get { return kindCase_ == KindOneofCase.StringValue ? (string) kind_ : ""; }
+ set {
+ kind_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ kindCase_ = KindOneofCase.StringValue;
+ }
+ }
+
+ /// <summary>Field number for the "bool_value" field.</summary>
+ public const int BoolValueFieldNumber = 4;
+ /// <summary>
+ /// Represents a boolean value.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool BoolValue {
+ get { return kindCase_ == KindOneofCase.BoolValue ? (bool) kind_ : false; }
+ set {
+ kind_ = value;
+ kindCase_ = KindOneofCase.BoolValue;
+ }
+ }
+
+ /// <summary>Field number for the "struct_value" field.</summary>
+ public const int StructValueFieldNumber = 5;
+ /// <summary>
+ /// Represents a structured value.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Struct StructValue {
+ get { return kindCase_ == KindOneofCase.StructValue ? (global::Google.Protobuf.WellKnownTypes.Struct) kind_ : null; }
+ set {
+ kind_ = value;
+ kindCase_ = value == null ? KindOneofCase.None : KindOneofCase.StructValue;
+ }
+ }
+
+ /// <summary>Field number for the "list_value" field.</summary>
+ public const int ListValueFieldNumber = 6;
+ /// <summary>
+ /// Represents a repeated `Value`.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.ListValue ListValue {
+ get { return kindCase_ == KindOneofCase.ListValue ? (global::Google.Protobuf.WellKnownTypes.ListValue) kind_ : null; }
+ set {
+ kind_ = value;
+ kindCase_ = value == null ? KindOneofCase.None : KindOneofCase.ListValue;
+ }
+ }
+
+ private object kind_;
+ /// <summary>Enum of possible cases for the "kind" oneof.</summary>
+ public enum KindOneofCase {
+ None = 0,
+ NullValue = 1,
+ NumberValue = 2,
+ StringValue = 3,
+ BoolValue = 4,
+ StructValue = 5,
+ ListValue = 6,
+ }
+ private KindOneofCase kindCase_ = KindOneofCase.None;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public KindOneofCase KindCase {
+ get { return kindCase_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearKind() {
+ kindCase_ = KindOneofCase.None;
+ kind_ = null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Value);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Value other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (NullValue != other.NullValue) return false;
+ if (NumberValue != other.NumberValue) return false;
+ if (StringValue != other.StringValue) return false;
+ if (BoolValue != other.BoolValue) return false;
+ if (!object.Equals(StructValue, other.StructValue)) return false;
+ if (!object.Equals(ListValue, other.ListValue)) return false;
+ if (KindCase != other.KindCase) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (kindCase_ == KindOneofCase.NullValue) hash ^= NullValue.GetHashCode();
+ if (kindCase_ == KindOneofCase.NumberValue) hash ^= NumberValue.GetHashCode();
+ if (kindCase_ == KindOneofCase.StringValue) hash ^= StringValue.GetHashCode();
+ if (kindCase_ == KindOneofCase.BoolValue) hash ^= BoolValue.GetHashCode();
+ if (kindCase_ == KindOneofCase.StructValue) hash ^= StructValue.GetHashCode();
+ if (kindCase_ == KindOneofCase.ListValue) hash ^= ListValue.GetHashCode();
+ hash ^= (int) kindCase_;
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (kindCase_ == KindOneofCase.NullValue) {
+ output.WriteRawTag(8);
+ output.WriteEnum((int) NullValue);
+ }
+ if (kindCase_ == KindOneofCase.NumberValue) {
+ output.WriteRawTag(17);
+ output.WriteDouble(NumberValue);
+ }
+ if (kindCase_ == KindOneofCase.StringValue) {
+ output.WriteRawTag(26);
+ output.WriteString(StringValue);
+ }
+ if (kindCase_ == KindOneofCase.BoolValue) {
+ output.WriteRawTag(32);
+ output.WriteBool(BoolValue);
+ }
+ if (kindCase_ == KindOneofCase.StructValue) {
+ output.WriteRawTag(42);
+ output.WriteMessage(StructValue);
+ }
+ if (kindCase_ == KindOneofCase.ListValue) {
+ output.WriteRawTag(50);
+ output.WriteMessage(ListValue);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (kindCase_ == KindOneofCase.NullValue) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) NullValue);
+ }
+ if (kindCase_ == KindOneofCase.NumberValue) {
+ size += 1 + 8;
+ }
+ if (kindCase_ == KindOneofCase.StringValue) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(StringValue);
+ }
+ if (kindCase_ == KindOneofCase.BoolValue) {
+ size += 1 + 1;
+ }
+ if (kindCase_ == KindOneofCase.StructValue) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(StructValue);
+ }
+ if (kindCase_ == KindOneofCase.ListValue) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(ListValue);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Value other) {
+ if (other == null) {
+ return;
+ }
+ switch (other.KindCase) {
+ case KindOneofCase.NullValue:
+ NullValue = other.NullValue;
+ break;
+ case KindOneofCase.NumberValue:
+ NumberValue = other.NumberValue;
+ break;
+ case KindOneofCase.StringValue:
+ StringValue = other.StringValue;
+ break;
+ case KindOneofCase.BoolValue:
+ BoolValue = other.BoolValue;
+ break;
+ case KindOneofCase.StructValue:
+ StructValue = other.StructValue;
+ break;
+ case KindOneofCase.ListValue:
+ ListValue = other.ListValue;
+ break;
+ }
+
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ kind_ = input.ReadEnum();
+ kindCase_ = KindOneofCase.NullValue;
+ break;
+ }
+ case 17: {
+ NumberValue = input.ReadDouble();
+ break;
+ }
+ case 26: {
+ StringValue = input.ReadString();
+ break;
+ }
+ case 32: {
+ BoolValue = input.ReadBool();
+ break;
+ }
+ case 42: {
+ global::Google.Protobuf.WellKnownTypes.Struct subBuilder = new global::Google.Protobuf.WellKnownTypes.Struct();
+ if (kindCase_ == KindOneofCase.StructValue) {
+ subBuilder.MergeFrom(StructValue);
+ }
+ input.ReadMessage(subBuilder);
+ StructValue = subBuilder;
+ break;
+ }
+ case 50: {
+ global::Google.Protobuf.WellKnownTypes.ListValue subBuilder = new global::Google.Protobuf.WellKnownTypes.ListValue();
+ if (kindCase_ == KindOneofCase.ListValue) {
+ subBuilder.MergeFrom(ListValue);
+ }
+ input.ReadMessage(subBuilder);
+ ListValue = subBuilder;
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// `ListValue` is a wrapper around a repeated field of values.
+ ///
+ /// The JSON representation for `ListValue` is JSON array.
+ /// </summary>
+ public sealed partial class ListValue : pb::IMessage<ListValue> {
+ private static readonly pb::MessageParser<ListValue> _parser = new pb::MessageParser<ListValue>(() => new ListValue());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<ListValue> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.StructReflection.Descriptor.MessageTypes[2]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ListValue() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ListValue(ListValue other) : this() {
+ values_ = other.values_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ListValue Clone() {
+ return new ListValue(this);
+ }
+
+ /// <summary>Field number for the "values" field.</summary>
+ public const int ValuesFieldNumber = 1;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Value> _repeated_values_codec
+ = pb::FieldCodec.ForMessage(10, global::Google.Protobuf.WellKnownTypes.Value.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Value> values_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Value>();
+ /// <summary>
+ /// Repeated field of dynamically typed values.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Value> Values {
+ get { return values_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as ListValue);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(ListValue other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if(!values_.Equals(other.values_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ hash ^= values_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ values_.WriteTo(output, _repeated_values_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ size += values_.CalculateSize(_repeated_values_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(ListValue other) {
+ if (other == null) {
+ return;
+ }
+ values_.Add(other.values_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ values_.AddEntriesFrom(input, _repeated_values_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/TimeExtensions.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/TimeExtensions.cs
new file mode 100644
index 0000000000..8b63d63035
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/TimeExtensions.cs
@@ -0,0 +1,76 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+
+namespace Google.Protobuf.WellKnownTypes
+{
+ /// <summary>
+ /// Extension methods on BCL time-related types, converting to protobuf types.
+ /// </summary>
+ public static class TimeExtensions
+ {
+ /// <summary>
+ /// Converts the given <see cref="DateTime"/> to a <see cref="Timestamp"/>.
+ /// </summary>
+ /// <param name="dateTime">The date and time to convert to a timestamp.</param>
+ /// <exception cref="ArgumentException">The <paramref name="dateTime"/> value has a <see cref="DateTime.Kind"/>other than <c>Utc</c>.</exception>
+ /// <returns>The converted timestamp.</returns>
+ public static Timestamp ToTimestamp(this DateTime dateTime)
+ {
+ return Timestamp.FromDateTime(dateTime);
+ }
+
+ /// <summary>
+ /// Converts the given <see cref="DateTimeOffset"/> to a <see cref="Timestamp"/>
+ /// </summary>
+ /// <remarks>The offset is taken into consideration when converting the value (so the same instant in time
+ /// is represented) but is not a separate part of the resulting value. In other words, there is no
+ /// roundtrip operation to retrieve the original <c>DateTimeOffset</c>.</remarks>
+ /// <param name="dateTimeOffset">The date and time (with UTC offset) to convert to a timestamp.</param>
+ /// <returns>The converted timestamp.</returns>
+ public static Timestamp ToTimestamp(this DateTimeOffset dateTimeOffset)
+ {
+ return Timestamp.FromDateTimeOffset(dateTimeOffset);
+ }
+
+ /// <summary>
+ /// Converts the given <see cref="TimeSpan"/> to a <see cref="Duration"/>.
+ /// </summary>
+ /// <param name="timeSpan">The time span to convert.</param>
+ /// <returns>The converted duration.</returns>
+ public static Duration ToDuration(this TimeSpan timeSpan)
+ {
+ return Duration.FromTimeSpan(timeSpan);
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs
new file mode 100644
index 0000000000..b789f6da7b
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs
@@ -0,0 +1,253 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/timestamp.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.WellKnownTypes {
+
+ /// <summary>Holder for reflection information generated from google/protobuf/timestamp.proto</summary>
+ public static partial class TimestampReflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for google/protobuf/timestamp.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static TimestampReflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "Ch9nb29nbGUvcHJvdG9idWYvdGltZXN0YW1wLnByb3RvEg9nb29nbGUucHJv",
+ "dG9idWYiKwoJVGltZXN0YW1wEg8KB3NlY29uZHMYASABKAMSDQoFbmFub3MY",
+ "AiABKAVCfgoTY29tLmdvb2dsZS5wcm90b2J1ZkIOVGltZXN0YW1wUHJvdG9Q",
+ "AVorZ2l0aHViLmNvbS9nb2xhbmcvcHJvdG9idWYvcHR5cGVzL3RpbWVzdGFt",
+ "cPgBAaICA0dQQqoCHkdvb2dsZS5Qcm90b2J1Zi5XZWxsS25vd25UeXBlc2IG",
+ "cHJvdG8z"));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { },
+ new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.Timestamp), global::Google.Protobuf.WellKnownTypes.Timestamp.Parser, new[]{ "Seconds", "Nanos" }, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Messages
+ /// <summary>
+ /// A Timestamp represents a point in time independent of any time zone
+ /// or calendar, represented as seconds and fractions of seconds at
+ /// nanosecond resolution in UTC Epoch time. It is encoded using the
+ /// Proleptic Gregorian Calendar which extends the Gregorian calendar
+ /// backwards to year one. It is encoded assuming all minutes are 60
+ /// seconds long, i.e. leap seconds are "smeared" so that no leap second
+ /// table is needed for interpretation. Range is from
+ /// 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.
+ /// By restricting to that range, we ensure that we can convert to
+ /// and from RFC 3339 date strings.
+ /// See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt).
+ ///
+ /// Example 1: Compute Timestamp from POSIX `time()`.
+ ///
+ /// Timestamp timestamp;
+ /// timestamp.set_seconds(time(NULL));
+ /// timestamp.set_nanos(0);
+ ///
+ /// Example 2: Compute Timestamp from POSIX `gettimeofday()`.
+ ///
+ /// struct timeval tv;
+ /// gettimeofday(&amp;tv, NULL);
+ ///
+ /// Timestamp timestamp;
+ /// timestamp.set_seconds(tv.tv_sec);
+ /// timestamp.set_nanos(tv.tv_usec * 1000);
+ ///
+ /// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
+ ///
+ /// FILETIME ft;
+ /// GetSystemTimeAsFileTime(&amp;ft);
+ /// UINT64 ticks = (((UINT64)ft.dwHighDateTime) &lt;&lt; 32) | ft.dwLowDateTime;
+ ///
+ /// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
+ /// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
+ /// Timestamp timestamp;
+ /// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
+ /// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
+ ///
+ /// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
+ ///
+ /// long millis = System.currentTimeMillis();
+ ///
+ /// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
+ /// .setNanos((int) ((millis % 1000) * 1000000)).build();
+ ///
+ /// Example 5: Compute Timestamp from current time in Python.
+ ///
+ /// timestamp = Timestamp()
+ /// timestamp.GetCurrentTime()
+ /// </summary>
+ public sealed partial class Timestamp : pb::IMessage<Timestamp> {
+ private static readonly pb::MessageParser<Timestamp> _parser = new pb::MessageParser<Timestamp>(() => new Timestamp());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Timestamp> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.TimestampReflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Timestamp() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Timestamp(Timestamp other) : this() {
+ seconds_ = other.seconds_;
+ nanos_ = other.nanos_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Timestamp Clone() {
+ return new Timestamp(this);
+ }
+
+ /// <summary>Field number for the "seconds" field.</summary>
+ public const int SecondsFieldNumber = 1;
+ private long seconds_;
+ /// <summary>
+ /// Represents seconds of UTC time since Unix epoch
+ /// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
+ /// 9999-12-31T23:59:59Z inclusive.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public long Seconds {
+ get { return seconds_; }
+ set {
+ seconds_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "nanos" field.</summary>
+ public const int NanosFieldNumber = 2;
+ private int nanos_;
+ /// <summary>
+ /// Non-negative fractions of a second at nanosecond resolution. Negative
+ /// second values with fractions must still have non-negative nanos values
+ /// that count forward in time. Must be from 0 to 999,999,999
+ /// inclusive.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Nanos {
+ get { return nanos_; }
+ set {
+ nanos_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Timestamp);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Timestamp other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Seconds != other.Seconds) return false;
+ if (Nanos != other.Nanos) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Seconds != 0L) hash ^= Seconds.GetHashCode();
+ if (Nanos != 0) hash ^= Nanos.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Seconds != 0L) {
+ output.WriteRawTag(8);
+ output.WriteInt64(Seconds);
+ }
+ if (Nanos != 0) {
+ output.WriteRawTag(16);
+ output.WriteInt32(Nanos);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Seconds != 0L) {
+ size += 1 + pb::CodedOutputStream.ComputeInt64Size(Seconds);
+ }
+ if (Nanos != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Nanos);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Timestamp other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Seconds != 0L) {
+ Seconds = other.Seconds;
+ }
+ if (other.Nanos != 0) {
+ Nanos = other.Nanos;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Seconds = input.ReadInt64();
+ break;
+ }
+ case 16: {
+ Nanos = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs
new file mode 100644
index 0000000000..aa40347342
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/TimestampPartial.cs
@@ -0,0 +1,241 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+#endregion
+
+using System;
+using System.Globalization;
+using System.Text;
+
+namespace Google.Protobuf.WellKnownTypes
+{
+ public partial class Timestamp : ICustomDiagnosticMessage
+ {
+ private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+ // Constants determined programmatically, but then hard-coded so they can be constant expressions.
+ private const long BclSecondsAtUnixEpoch = 62135596800;
+ internal const long UnixSecondsAtBclMaxValue = 253402300799;
+ internal const long UnixSecondsAtBclMinValue = -BclSecondsAtUnixEpoch;
+ internal const int MaxNanos = Duration.NanosecondsPerSecond - 1;
+
+ private static bool IsNormalized(long seconds, int nanoseconds) =>
+ nanoseconds >= 0 &&
+ nanoseconds <= MaxNanos &&
+ seconds >= UnixSecondsAtBclMinValue &&
+ seconds <= UnixSecondsAtBclMaxValue;
+
+ /// <summary>
+ /// Returns the difference between one <see cref="Timestamp"/> and another, as a <see cref="Duration"/>.
+ /// </summary>
+ /// <param name="lhs">The timestamp to subtract from. Must not be null.</param>
+ /// <param name="rhs">The timestamp to subtract. Must not be null.</param>
+ /// <returns>The difference between the two specified timestamps.</returns>
+ public static Duration operator -(Timestamp lhs, Timestamp rhs)
+ {
+ ProtoPreconditions.CheckNotNull(lhs, "lhs");
+ ProtoPreconditions.CheckNotNull(rhs, "rhs");
+ checked
+ {
+ return Duration.Normalize(lhs.Seconds - rhs.Seconds, lhs.Nanos - rhs.Nanos);
+ }
+ }
+
+ /// <summary>
+ /// Adds a <see cref="Duration"/> to a <see cref="Timestamp"/>, to obtain another <c>Timestamp</c>.
+ /// </summary>
+ /// <param name="lhs">The timestamp to add the duration to. Must not be null.</param>
+ /// <param name="rhs">The duration to add. Must not be null.</param>
+ /// <returns>The result of adding the duration to the timestamp.</returns>
+ public static Timestamp operator +(Timestamp lhs, Duration rhs)
+ {
+ ProtoPreconditions.CheckNotNull(lhs, "lhs");
+ ProtoPreconditions.CheckNotNull(rhs, "rhs");
+ checked
+ {
+ return Normalize(lhs.Seconds + rhs.Seconds, lhs.Nanos + rhs.Nanos);
+ }
+ }
+
+ /// <summary>
+ /// Subtracts a <see cref="Duration"/> from a <see cref="Timestamp"/>, to obtain another <c>Timestamp</c>.
+ /// </summary>
+ /// <param name="lhs">The timestamp to subtract the duration from. Must not be null.</param>
+ /// <param name="rhs">The duration to subtract.</param>
+ /// <returns>The result of subtracting the duration from the timestamp.</returns>
+ public static Timestamp operator -(Timestamp lhs, Duration rhs)
+ {
+ ProtoPreconditions.CheckNotNull(lhs, "lhs");
+ ProtoPreconditions.CheckNotNull(rhs, "rhs");
+ checked
+ {
+ return Normalize(lhs.Seconds - rhs.Seconds, lhs.Nanos - rhs.Nanos);
+ }
+ }
+
+ /// <summary>
+ /// Converts this timestamp into a <see cref="DateTime"/>.
+ /// </summary>
+ /// <remarks>
+ /// The resulting <c>DateTime</c> will always have a <c>Kind</c> of <c>Utc</c>.
+ /// If the timestamp is not a precise number of ticks, it will be truncated towards the start
+ /// of time. For example, a timestamp with a <see cref="Nanos"/> value of 99 will result in a
+ /// <see cref="DateTime"/> value precisely on a second.
+ /// </remarks>
+ /// <returns>This timestamp as a <c>DateTime</c>.</returns>
+ /// <exception cref="InvalidOperationException">The timestamp contains invalid values; either it is
+ /// incorrectly normalized or is outside the valid range.</exception>
+ public DateTime ToDateTime()
+ {
+ if (!IsNormalized(Seconds, Nanos))
+ {
+ throw new InvalidOperationException(@"Timestamp contains invalid values: Seconds={Seconds}; Nanos={Nanos}");
+ }
+ return UnixEpoch.AddSeconds(Seconds).AddTicks(Nanos / Duration.NanosecondsPerTick);
+ }
+
+ /// <summary>
+ /// Converts this timestamp into a <see cref="DateTimeOffset"/>.
+ /// </summary>
+ /// <remarks>
+ /// The resulting <c>DateTimeOffset</c> will always have an <c>Offset</c> of zero.
+ /// If the timestamp is not a precise number of ticks, it will be truncated towards the start
+ /// of time. For example, a timestamp with a <see cref="Nanos"/> value of 99 will result in a
+ /// <see cref="DateTimeOffset"/> value precisely on a second.
+ /// </remarks>
+ /// <returns>This timestamp as a <c>DateTimeOffset</c>.</returns>
+ /// <exception cref="InvalidOperationException">The timestamp contains invalid values; either it is
+ /// incorrectly normalized or is outside the valid range.</exception>
+ public DateTimeOffset ToDateTimeOffset()
+ {
+ return new DateTimeOffset(ToDateTime(), TimeSpan.Zero);
+ }
+
+ /// <summary>
+ /// Converts the specified <see cref="DateTime"/> to a <see cref="Timestamp"/>.
+ /// </summary>
+ /// <param name="dateTime"></param>
+ /// <exception cref="ArgumentException">The <c>Kind</c> of <paramref name="dateTime"/> is not <c>DateTimeKind.Utc</c>.</exception>
+ /// <returns>The converted timestamp.</returns>
+ public static Timestamp FromDateTime(DateTime dateTime)
+ {
+ if (dateTime.Kind != DateTimeKind.Utc)
+ {
+ throw new ArgumentException("Conversion from DateTime to Timestamp requires the DateTime kind to be Utc", "dateTime");
+ }
+ // Do the arithmetic using DateTime.Ticks, which is always non-negative, making things simpler.
+ long secondsSinceBclEpoch = dateTime.Ticks / TimeSpan.TicksPerSecond;
+ int nanoseconds = (int) (dateTime.Ticks % TimeSpan.TicksPerSecond) * Duration.NanosecondsPerTick;
+ return new Timestamp { Seconds = secondsSinceBclEpoch - BclSecondsAtUnixEpoch, Nanos = nanoseconds };
+ }
+
+ /// <summary>
+ /// Converts the given <see cref="DateTimeOffset"/> to a <see cref="Timestamp"/>
+ /// </summary>
+ /// <remarks>The offset is taken into consideration when converting the value (so the same instant in time
+ /// is represented) but is not a separate part of the resulting value. In other words, there is no
+ /// roundtrip operation to retrieve the original <c>DateTimeOffset</c>.</remarks>
+ /// <param name="dateTimeOffset">The date and time (with UTC offset) to convert to a timestamp.</param>
+ /// <returns>The converted timestamp.</returns>
+ public static Timestamp FromDateTimeOffset(DateTimeOffset dateTimeOffset)
+ {
+ // We don't need to worry about this having negative ticks: DateTimeOffset is constrained to handle
+ // values whose *UTC* value is in the range of DateTime.
+ return FromDateTime(dateTimeOffset.UtcDateTime);
+ }
+
+ internal static Timestamp Normalize(long seconds, int nanoseconds)
+ {
+ int extraSeconds = nanoseconds / Duration.NanosecondsPerSecond;
+ seconds += extraSeconds;
+ nanoseconds -= extraSeconds * Duration.NanosecondsPerSecond;
+
+ if (nanoseconds < 0)
+ {
+ nanoseconds += Duration.NanosecondsPerSecond;
+ seconds--;
+ }
+ return new Timestamp { Seconds = seconds, Nanos = nanoseconds };
+ }
+
+ /// <summary>
+ /// Converts a timestamp specified in seconds/nanoseconds to a string.
+ /// </summary>
+ /// <remarks>
+ /// If the value is a normalized duration in the range described in <c>timestamp.proto</c>,
+ /// <paramref name="diagnosticOnly"/> is ignored. Otherwise, if the parameter is <c>true</c>,
+ /// a JSON object with a warning is returned; if it is <c>false</c>, an <see cref="InvalidOperationException"/> is thrown.
+ /// </remarks>
+ /// <param name="seconds">Seconds portion of the duration.</param>
+ /// <param name="nanoseconds">Nanoseconds portion of the duration.</param>
+ /// <param name="diagnosticOnly">Determines the handling of non-normalized values</param>
+ /// <exception cref="InvalidOperationException">The represented duration is invalid, and <paramref name="diagnosticOnly"/> is <c>false</c>.</exception>
+ internal static string ToJson(long seconds, int nanoseconds, bool diagnosticOnly)
+ {
+ if (IsNormalized(seconds, nanoseconds))
+ {
+ // Use .NET's formatting for the value down to the second, including an opening double quote (as it's a string value)
+ DateTime dateTime = UnixEpoch.AddSeconds(seconds);
+ var builder = new StringBuilder();
+ builder.Append('"');
+ builder.Append(dateTime.ToString("yyyy'-'MM'-'dd'T'HH:mm:ss", CultureInfo.InvariantCulture));
+ Duration.AppendNanoseconds(builder, nanoseconds);
+ builder.Append("Z\"");
+ return builder.ToString();
+ }
+ if (diagnosticOnly)
+ {
+ return string.Format(CultureInfo.InvariantCulture,
+ "{{ \"@warning\": \"Invalid Timestamp\", \"seconds\": \"{0}\", \"nanos\": {1} }}",
+ seconds,
+ nanoseconds);
+ }
+ else
+ {
+ throw new InvalidOperationException("Non-normalized timestamp value");
+ }
+ }
+
+ /// <summary>
+ /// Returns a string representation of this <see cref="Timestamp"/> for diagnostic purposes.
+ /// </summary>
+ /// <remarks>
+ /// Normally the returned value will be a JSON string value (including leading and trailing quotes) but
+ /// when the value is non-normalized or out of range, a JSON object representation will be returned
+ /// instead, including a warning. This is to avoid exceptions being thrown when trying to
+ /// diagnose problems - the regular JSON formatter will still throw an exception for non-normalized
+ /// values.
+ /// </remarks>
+ /// <returns>A string representation of this value.</returns>
+ public string ToDiagnosticString()
+ {
+ return ToJson(Seconds, Nanos, true);
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs
new file mode 100644
index 0000000000..7375b6cb18
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs
@@ -0,0 +1,1444 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/type.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.WellKnownTypes {
+
+ /// <summary>Holder for reflection information generated from google/protobuf/type.proto</summary>
+ public static partial class TypeReflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for google/protobuf/type.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static TypeReflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "Chpnb29nbGUvcHJvdG9idWYvdHlwZS5wcm90bxIPZ29vZ2xlLnByb3RvYnVm",
+ "Ghlnb29nbGUvcHJvdG9idWYvYW55LnByb3RvGiRnb29nbGUvcHJvdG9idWYv",
+ "c291cmNlX2NvbnRleHQucHJvdG8i1wEKBFR5cGUSDAoEbmFtZRgBIAEoCRIm",
+ "CgZmaWVsZHMYAiADKAsyFi5nb29nbGUucHJvdG9idWYuRmllbGQSDgoGb25l",
+ "b2ZzGAMgAygJEigKB29wdGlvbnMYBCADKAsyFy5nb29nbGUucHJvdG9idWYu",
+ "T3B0aW9uEjYKDnNvdXJjZV9jb250ZXh0GAUgASgLMh4uZ29vZ2xlLnByb3Rv",
+ "YnVmLlNvdXJjZUNvbnRleHQSJwoGc3ludGF4GAYgASgOMhcuZ29vZ2xlLnBy",
+ "b3RvYnVmLlN5bnRheCLVBQoFRmllbGQSKQoEa2luZBgBIAEoDjIbLmdvb2ds",
+ "ZS5wcm90b2J1Zi5GaWVsZC5LaW5kEjcKC2NhcmRpbmFsaXR5GAIgASgOMiIu",
+ "Z29vZ2xlLnByb3RvYnVmLkZpZWxkLkNhcmRpbmFsaXR5Eg4KBm51bWJlchgD",
+ "IAEoBRIMCgRuYW1lGAQgASgJEhAKCHR5cGVfdXJsGAYgASgJEhMKC29uZW9m",
+ "X2luZGV4GAcgASgFEg4KBnBhY2tlZBgIIAEoCBIoCgdvcHRpb25zGAkgAygL",
+ "MhcuZ29vZ2xlLnByb3RvYnVmLk9wdGlvbhIRCglqc29uX25hbWUYCiABKAkS",
+ "FQoNZGVmYXVsdF92YWx1ZRgLIAEoCSLIAgoES2luZBIQCgxUWVBFX1VOS05P",
+ "V04QABIPCgtUWVBFX0RPVUJMRRABEg4KClRZUEVfRkxPQVQQAhIOCgpUWVBF",
+ "X0lOVDY0EAMSDwoLVFlQRV9VSU5UNjQQBBIOCgpUWVBFX0lOVDMyEAUSEAoM",
+ "VFlQRV9GSVhFRDY0EAYSEAoMVFlQRV9GSVhFRDMyEAcSDQoJVFlQRV9CT09M",
+ "EAgSDwoLVFlQRV9TVFJJTkcQCRIOCgpUWVBFX0dST1VQEAoSEAoMVFlQRV9N",
+ "RVNTQUdFEAsSDgoKVFlQRV9CWVRFUxAMEg8KC1RZUEVfVUlOVDMyEA0SDQoJ",
+ "VFlQRV9FTlVNEA4SEQoNVFlQRV9TRklYRUQzMhAPEhEKDVRZUEVfU0ZJWEVE",
+ "NjQQEBIPCgtUWVBFX1NJTlQzMhAREg8KC1RZUEVfU0lOVDY0EBIidAoLQ2Fy",
+ "ZGluYWxpdHkSFwoTQ0FSRElOQUxJVFlfVU5LTk9XThAAEhgKFENBUkRJTkFM",
+ "SVRZX09QVElPTkFMEAESGAoUQ0FSRElOQUxJVFlfUkVRVUlSRUQQAhIYChRD",
+ "QVJESU5BTElUWV9SRVBFQVRFRBADIs4BCgRFbnVtEgwKBG5hbWUYASABKAkS",
+ "LQoJZW51bXZhbHVlGAIgAygLMhouZ29vZ2xlLnByb3RvYnVmLkVudW1WYWx1",
+ "ZRIoCgdvcHRpb25zGAMgAygLMhcuZ29vZ2xlLnByb3RvYnVmLk9wdGlvbhI2",
+ "Cg5zb3VyY2VfY29udGV4dBgEIAEoCzIeLmdvb2dsZS5wcm90b2J1Zi5Tb3Vy",
+ "Y2VDb250ZXh0EicKBnN5bnRheBgFIAEoDjIXLmdvb2dsZS5wcm90b2J1Zi5T",
+ "eW50YXgiUwoJRW51bVZhbHVlEgwKBG5hbWUYASABKAkSDgoGbnVtYmVyGAIg",
+ "ASgFEigKB29wdGlvbnMYAyADKAsyFy5nb29nbGUucHJvdG9idWYuT3B0aW9u",
+ "IjsKBk9wdGlvbhIMCgRuYW1lGAEgASgJEiMKBXZhbHVlGAIgASgLMhQuZ29v",
+ "Z2xlLnByb3RvYnVmLkFueSouCgZTeW50YXgSEQoNU1lOVEFYX1BST1RPMhAA",
+ "EhEKDVNZTlRBWF9QUk9UTzMQAUJ9ChNjb20uZ29vZ2xlLnByb3RvYnVmQglU",
+ "eXBlUHJvdG9QAVovZ29vZ2xlLmdvbGFuZy5vcmcvZ2VucHJvdG8vcHJvdG9i",
+ "dWYvcHR5cGU7cHR5cGX4AQGiAgNHUEKqAh5Hb29nbGUuUHJvdG9idWYuV2Vs",
+ "bEtub3duVHlwZXNiBnByb3RvMw=="));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.AnyReflection.Descriptor, global::Google.Protobuf.WellKnownTypes.SourceContextReflection.Descriptor, },
+ new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Google.Protobuf.WellKnownTypes.Syntax), }, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.Type), global::Google.Protobuf.WellKnownTypes.Type.Parser, new[]{ "Name", "Fields", "Oneofs", "Options", "SourceContext", "Syntax" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.Field), global::Google.Protobuf.WellKnownTypes.Field.Parser, new[]{ "Kind", "Cardinality", "Number", "Name", "TypeUrl", "OneofIndex", "Packed", "Options", "JsonName", "DefaultValue" }, null, new[]{ typeof(global::Google.Protobuf.WellKnownTypes.Field.Types.Kind), typeof(global::Google.Protobuf.WellKnownTypes.Field.Types.Cardinality) }, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.Enum), global::Google.Protobuf.WellKnownTypes.Enum.Parser, new[]{ "Name", "Enumvalue", "Options", "SourceContext", "Syntax" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.EnumValue), global::Google.Protobuf.WellKnownTypes.EnumValue.Parser, new[]{ "Name", "Number", "Options" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.Option), global::Google.Protobuf.WellKnownTypes.Option.Parser, new[]{ "Name", "Value" }, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Enums
+ /// <summary>
+ /// The syntax in which a protocol buffer element is defined.
+ /// </summary>
+ public enum Syntax {
+ /// <summary>
+ /// Syntax `proto2`.
+ /// </summary>
+ [pbr::OriginalName("SYNTAX_PROTO2")] Proto2 = 0,
+ /// <summary>
+ /// Syntax `proto3`.
+ /// </summary>
+ [pbr::OriginalName("SYNTAX_PROTO3")] Proto3 = 1,
+ }
+
+ #endregion
+
+ #region Messages
+ /// <summary>
+ /// A protocol buffer message type.
+ /// </summary>
+ public sealed partial class Type : pb::IMessage<Type> {
+ private static readonly pb::MessageParser<Type> _parser = new pb::MessageParser<Type>(() => new Type());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Type> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.TypeReflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Type() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Type(Type other) : this() {
+ name_ = other.name_;
+ fields_ = other.fields_.Clone();
+ oneofs_ = other.oneofs_.Clone();
+ options_ = other.options_.Clone();
+ SourceContext = other.sourceContext_ != null ? other.SourceContext.Clone() : null;
+ syntax_ = other.syntax_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Type Clone() {
+ return new Type(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ /// <summary>
+ /// The fully qualified message name.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "fields" field.</summary>
+ public const int FieldsFieldNumber = 2;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Field> _repeated_fields_codec
+ = pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.Field.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Field> fields_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Field>();
+ /// <summary>
+ /// The list of fields.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Field> Fields {
+ get { return fields_; }
+ }
+
+ /// <summary>Field number for the "oneofs" field.</summary>
+ public const int OneofsFieldNumber = 3;
+ private static readonly pb::FieldCodec<string> _repeated_oneofs_codec
+ = pb::FieldCodec.ForString(26);
+ private readonly pbc::RepeatedField<string> oneofs_ = new pbc::RepeatedField<string>();
+ /// <summary>
+ /// The list of types appearing in `oneof` definitions in this type.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<string> Oneofs {
+ get { return oneofs_; }
+ }
+
+ /// <summary>Field number for the "options" field.</summary>
+ public const int OptionsFieldNumber = 4;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Option> _repeated_options_codec
+ = pb::FieldCodec.ForMessage(34, global::Google.Protobuf.WellKnownTypes.Option.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option> options_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option>();
+ /// <summary>
+ /// The protocol buffer options.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option> Options {
+ get { return options_; }
+ }
+
+ /// <summary>Field number for the "source_context" field.</summary>
+ public const int SourceContextFieldNumber = 5;
+ private global::Google.Protobuf.WellKnownTypes.SourceContext sourceContext_;
+ /// <summary>
+ /// The source context.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.SourceContext SourceContext {
+ get { return sourceContext_; }
+ set {
+ sourceContext_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "syntax" field.</summary>
+ public const int SyntaxFieldNumber = 6;
+ private global::Google.Protobuf.WellKnownTypes.Syntax syntax_ = 0;
+ /// <summary>
+ /// The source syntax.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Syntax Syntax {
+ get { return syntax_; }
+ set {
+ syntax_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Type);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Type other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ if(!fields_.Equals(other.fields_)) return false;
+ if(!oneofs_.Equals(other.oneofs_)) return false;
+ if(!options_.Equals(other.options_)) return false;
+ if (!object.Equals(SourceContext, other.SourceContext)) return false;
+ if (Syntax != other.Syntax) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ hash ^= fields_.GetHashCode();
+ hash ^= oneofs_.GetHashCode();
+ hash ^= options_.GetHashCode();
+ if (sourceContext_ != null) hash ^= SourceContext.GetHashCode();
+ if (Syntax != 0) hash ^= Syntax.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ fields_.WriteTo(output, _repeated_fields_codec);
+ oneofs_.WriteTo(output, _repeated_oneofs_codec);
+ options_.WriteTo(output, _repeated_options_codec);
+ if (sourceContext_ != null) {
+ output.WriteRawTag(42);
+ output.WriteMessage(SourceContext);
+ }
+ if (Syntax != 0) {
+ output.WriteRawTag(48);
+ output.WriteEnum((int) Syntax);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ size += fields_.CalculateSize(_repeated_fields_codec);
+ size += oneofs_.CalculateSize(_repeated_oneofs_codec);
+ size += options_.CalculateSize(_repeated_options_codec);
+ if (sourceContext_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(SourceContext);
+ }
+ if (Syntax != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Syntax);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Type other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ fields_.Add(other.fields_);
+ oneofs_.Add(other.oneofs_);
+ options_.Add(other.options_);
+ if (other.sourceContext_ != null) {
+ if (sourceContext_ == null) {
+ sourceContext_ = new global::Google.Protobuf.WellKnownTypes.SourceContext();
+ }
+ SourceContext.MergeFrom(other.SourceContext);
+ }
+ if (other.Syntax != 0) {
+ Syntax = other.Syntax;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 18: {
+ fields_.AddEntriesFrom(input, _repeated_fields_codec);
+ break;
+ }
+ case 26: {
+ oneofs_.AddEntriesFrom(input, _repeated_oneofs_codec);
+ break;
+ }
+ case 34: {
+ options_.AddEntriesFrom(input, _repeated_options_codec);
+ break;
+ }
+ case 42: {
+ if (sourceContext_ == null) {
+ sourceContext_ = new global::Google.Protobuf.WellKnownTypes.SourceContext();
+ }
+ input.ReadMessage(sourceContext_);
+ break;
+ }
+ case 48: {
+ syntax_ = (global::Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// A single field of a message type.
+ /// </summary>
+ public sealed partial class Field : pb::IMessage<Field> {
+ private static readonly pb::MessageParser<Field> _parser = new pb::MessageParser<Field>(() => new Field());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Field> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.TypeReflection.Descriptor.MessageTypes[1]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Field() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Field(Field other) : this() {
+ kind_ = other.kind_;
+ cardinality_ = other.cardinality_;
+ number_ = other.number_;
+ name_ = other.name_;
+ typeUrl_ = other.typeUrl_;
+ oneofIndex_ = other.oneofIndex_;
+ packed_ = other.packed_;
+ options_ = other.options_.Clone();
+ jsonName_ = other.jsonName_;
+ defaultValue_ = other.defaultValue_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Field Clone() {
+ return new Field(this);
+ }
+
+ /// <summary>Field number for the "kind" field.</summary>
+ public const int KindFieldNumber = 1;
+ private global::Google.Protobuf.WellKnownTypes.Field.Types.Kind kind_ = 0;
+ /// <summary>
+ /// The field type.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Field.Types.Kind Kind {
+ get { return kind_; }
+ set {
+ kind_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "cardinality" field.</summary>
+ public const int CardinalityFieldNumber = 2;
+ private global::Google.Protobuf.WellKnownTypes.Field.Types.Cardinality cardinality_ = 0;
+ /// <summary>
+ /// The field cardinality.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Field.Types.Cardinality Cardinality {
+ get { return cardinality_; }
+ set {
+ cardinality_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "number" field.</summary>
+ public const int NumberFieldNumber = 3;
+ private int number_;
+ /// <summary>
+ /// The field number.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Number {
+ get { return number_; }
+ set {
+ number_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 4;
+ private string name_ = "";
+ /// <summary>
+ /// The field name.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "type_url" field.</summary>
+ public const int TypeUrlFieldNumber = 6;
+ private string typeUrl_ = "";
+ /// <summary>
+ /// The field type URL, without the scheme, for message or enumeration
+ /// types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string TypeUrl {
+ get { return typeUrl_; }
+ set {
+ typeUrl_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "oneof_index" field.</summary>
+ public const int OneofIndexFieldNumber = 7;
+ private int oneofIndex_;
+ /// <summary>
+ /// The index of the field type in `Type.oneofs`, for message or enumeration
+ /// types. The first type has index 1; zero means the type is not in the list.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int OneofIndex {
+ get { return oneofIndex_; }
+ set {
+ oneofIndex_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "packed" field.</summary>
+ public const int PackedFieldNumber = 8;
+ private bool packed_;
+ /// <summary>
+ /// Whether to use alternative packed wire representation.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Packed {
+ get { return packed_; }
+ set {
+ packed_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "options" field.</summary>
+ public const int OptionsFieldNumber = 9;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Option> _repeated_options_codec
+ = pb::FieldCodec.ForMessage(74, global::Google.Protobuf.WellKnownTypes.Option.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option> options_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option>();
+ /// <summary>
+ /// The protocol buffer options.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option> Options {
+ get { return options_; }
+ }
+
+ /// <summary>Field number for the "json_name" field.</summary>
+ public const int JsonNameFieldNumber = 10;
+ private string jsonName_ = "";
+ /// <summary>
+ /// The field JSON name.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string JsonName {
+ get { return jsonName_; }
+ set {
+ jsonName_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "default_value" field.</summary>
+ public const int DefaultValueFieldNumber = 11;
+ private string defaultValue_ = "";
+ /// <summary>
+ /// The string value of the default value of this field. Proto2 syntax only.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string DefaultValue {
+ get { return defaultValue_; }
+ set {
+ defaultValue_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Field);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Field other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Kind != other.Kind) return false;
+ if (Cardinality != other.Cardinality) return false;
+ if (Number != other.Number) return false;
+ if (Name != other.Name) return false;
+ if (TypeUrl != other.TypeUrl) return false;
+ if (OneofIndex != other.OneofIndex) return false;
+ if (Packed != other.Packed) return false;
+ if(!options_.Equals(other.options_)) return false;
+ if (JsonName != other.JsonName) return false;
+ if (DefaultValue != other.DefaultValue) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Kind != 0) hash ^= Kind.GetHashCode();
+ if (Cardinality != 0) hash ^= Cardinality.GetHashCode();
+ if (Number != 0) hash ^= Number.GetHashCode();
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ if (TypeUrl.Length != 0) hash ^= TypeUrl.GetHashCode();
+ if (OneofIndex != 0) hash ^= OneofIndex.GetHashCode();
+ if (Packed != false) hash ^= Packed.GetHashCode();
+ hash ^= options_.GetHashCode();
+ if (JsonName.Length != 0) hash ^= JsonName.GetHashCode();
+ if (DefaultValue.Length != 0) hash ^= DefaultValue.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Kind != 0) {
+ output.WriteRawTag(8);
+ output.WriteEnum((int) Kind);
+ }
+ if (Cardinality != 0) {
+ output.WriteRawTag(16);
+ output.WriteEnum((int) Cardinality);
+ }
+ if (Number != 0) {
+ output.WriteRawTag(24);
+ output.WriteInt32(Number);
+ }
+ if (Name.Length != 0) {
+ output.WriteRawTag(34);
+ output.WriteString(Name);
+ }
+ if (TypeUrl.Length != 0) {
+ output.WriteRawTag(50);
+ output.WriteString(TypeUrl);
+ }
+ if (OneofIndex != 0) {
+ output.WriteRawTag(56);
+ output.WriteInt32(OneofIndex);
+ }
+ if (Packed != false) {
+ output.WriteRawTag(64);
+ output.WriteBool(Packed);
+ }
+ options_.WriteTo(output, _repeated_options_codec);
+ if (JsonName.Length != 0) {
+ output.WriteRawTag(82);
+ output.WriteString(JsonName);
+ }
+ if (DefaultValue.Length != 0) {
+ output.WriteRawTag(90);
+ output.WriteString(DefaultValue);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Kind != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Kind);
+ }
+ if (Cardinality != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Cardinality);
+ }
+ if (Number != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Number);
+ }
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ if (TypeUrl.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(TypeUrl);
+ }
+ if (OneofIndex != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(OneofIndex);
+ }
+ if (Packed != false) {
+ size += 1 + 1;
+ }
+ size += options_.CalculateSize(_repeated_options_codec);
+ if (JsonName.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(JsonName);
+ }
+ if (DefaultValue.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(DefaultValue);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Field other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Kind != 0) {
+ Kind = other.Kind;
+ }
+ if (other.Cardinality != 0) {
+ Cardinality = other.Cardinality;
+ }
+ if (other.Number != 0) {
+ Number = other.Number;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ if (other.TypeUrl.Length != 0) {
+ TypeUrl = other.TypeUrl;
+ }
+ if (other.OneofIndex != 0) {
+ OneofIndex = other.OneofIndex;
+ }
+ if (other.Packed != false) {
+ Packed = other.Packed;
+ }
+ options_.Add(other.options_);
+ if (other.JsonName.Length != 0) {
+ JsonName = other.JsonName;
+ }
+ if (other.DefaultValue.Length != 0) {
+ DefaultValue = other.DefaultValue;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ kind_ = (global::Google.Protobuf.WellKnownTypes.Field.Types.Kind) input.ReadEnum();
+ break;
+ }
+ case 16: {
+ cardinality_ = (global::Google.Protobuf.WellKnownTypes.Field.Types.Cardinality) input.ReadEnum();
+ break;
+ }
+ case 24: {
+ Number = input.ReadInt32();
+ break;
+ }
+ case 34: {
+ Name = input.ReadString();
+ break;
+ }
+ case 50: {
+ TypeUrl = input.ReadString();
+ break;
+ }
+ case 56: {
+ OneofIndex = input.ReadInt32();
+ break;
+ }
+ case 64: {
+ Packed = input.ReadBool();
+ break;
+ }
+ case 74: {
+ options_.AddEntriesFrom(input, _repeated_options_codec);
+ break;
+ }
+ case 82: {
+ JsonName = input.ReadString();
+ break;
+ }
+ case 90: {
+ DefaultValue = input.ReadString();
+ break;
+ }
+ }
+ }
+ }
+
+ #region Nested types
+ /// <summary>Container for nested types declared in the Field message type.</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static partial class Types {
+ /// <summary>
+ /// Basic field types.
+ /// </summary>
+ public enum Kind {
+ /// <summary>
+ /// Field type unknown.
+ /// </summary>
+ [pbr::OriginalName("TYPE_UNKNOWN")] TypeUnknown = 0,
+ /// <summary>
+ /// Field type double.
+ /// </summary>
+ [pbr::OriginalName("TYPE_DOUBLE")] TypeDouble = 1,
+ /// <summary>
+ /// Field type float.
+ /// </summary>
+ [pbr::OriginalName("TYPE_FLOAT")] TypeFloat = 2,
+ /// <summary>
+ /// Field type int64.
+ /// </summary>
+ [pbr::OriginalName("TYPE_INT64")] TypeInt64 = 3,
+ /// <summary>
+ /// Field type uint64.
+ /// </summary>
+ [pbr::OriginalName("TYPE_UINT64")] TypeUint64 = 4,
+ /// <summary>
+ /// Field type int32.
+ /// </summary>
+ [pbr::OriginalName("TYPE_INT32")] TypeInt32 = 5,
+ /// <summary>
+ /// Field type fixed64.
+ /// </summary>
+ [pbr::OriginalName("TYPE_FIXED64")] TypeFixed64 = 6,
+ /// <summary>
+ /// Field type fixed32.
+ /// </summary>
+ [pbr::OriginalName("TYPE_FIXED32")] TypeFixed32 = 7,
+ /// <summary>
+ /// Field type bool.
+ /// </summary>
+ [pbr::OriginalName("TYPE_BOOL")] TypeBool = 8,
+ /// <summary>
+ /// Field type string.
+ /// </summary>
+ [pbr::OriginalName("TYPE_STRING")] TypeString = 9,
+ /// <summary>
+ /// Field type group. Proto2 syntax only, and deprecated.
+ /// </summary>
+ [pbr::OriginalName("TYPE_GROUP")] TypeGroup = 10,
+ /// <summary>
+ /// Field type message.
+ /// </summary>
+ [pbr::OriginalName("TYPE_MESSAGE")] TypeMessage = 11,
+ /// <summary>
+ /// Field type bytes.
+ /// </summary>
+ [pbr::OriginalName("TYPE_BYTES")] TypeBytes = 12,
+ /// <summary>
+ /// Field type uint32.
+ /// </summary>
+ [pbr::OriginalName("TYPE_UINT32")] TypeUint32 = 13,
+ /// <summary>
+ /// Field type enum.
+ /// </summary>
+ [pbr::OriginalName("TYPE_ENUM")] TypeEnum = 14,
+ /// <summary>
+ /// Field type sfixed32.
+ /// </summary>
+ [pbr::OriginalName("TYPE_SFIXED32")] TypeSfixed32 = 15,
+ /// <summary>
+ /// Field type sfixed64.
+ /// </summary>
+ [pbr::OriginalName("TYPE_SFIXED64")] TypeSfixed64 = 16,
+ /// <summary>
+ /// Field type sint32.
+ /// </summary>
+ [pbr::OriginalName("TYPE_SINT32")] TypeSint32 = 17,
+ /// <summary>
+ /// Field type sint64.
+ /// </summary>
+ [pbr::OriginalName("TYPE_SINT64")] TypeSint64 = 18,
+ }
+
+ /// <summary>
+ /// Whether a field is optional, required, or repeated.
+ /// </summary>
+ public enum Cardinality {
+ /// <summary>
+ /// For fields with unknown cardinality.
+ /// </summary>
+ [pbr::OriginalName("CARDINALITY_UNKNOWN")] Unknown = 0,
+ /// <summary>
+ /// For optional fields.
+ /// </summary>
+ [pbr::OriginalName("CARDINALITY_OPTIONAL")] Optional = 1,
+ /// <summary>
+ /// For required fields. Proto2 syntax only.
+ /// </summary>
+ [pbr::OriginalName("CARDINALITY_REQUIRED")] Required = 2,
+ /// <summary>
+ /// For repeated fields.
+ /// </summary>
+ [pbr::OriginalName("CARDINALITY_REPEATED")] Repeated = 3,
+ }
+
+ }
+ #endregion
+
+ }
+
+ /// <summary>
+ /// Enum type definition.
+ /// </summary>
+ public sealed partial class Enum : pb::IMessage<Enum> {
+ private static readonly pb::MessageParser<Enum> _parser = new pb::MessageParser<Enum>(() => new Enum());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Enum> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.TypeReflection.Descriptor.MessageTypes[2]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Enum() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Enum(Enum other) : this() {
+ name_ = other.name_;
+ enumvalue_ = other.enumvalue_.Clone();
+ options_ = other.options_.Clone();
+ SourceContext = other.sourceContext_ != null ? other.SourceContext.Clone() : null;
+ syntax_ = other.syntax_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Enum Clone() {
+ return new Enum(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ /// <summary>
+ /// Enum type name.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "enumvalue" field.</summary>
+ public const int EnumvalueFieldNumber = 2;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.EnumValue> _repeated_enumvalue_codec
+ = pb::FieldCodec.ForMessage(18, global::Google.Protobuf.WellKnownTypes.EnumValue.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.EnumValue> enumvalue_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.EnumValue>();
+ /// <summary>
+ /// Enum value definitions.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.EnumValue> Enumvalue {
+ get { return enumvalue_; }
+ }
+
+ /// <summary>Field number for the "options" field.</summary>
+ public const int OptionsFieldNumber = 3;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Option> _repeated_options_codec
+ = pb::FieldCodec.ForMessage(26, global::Google.Protobuf.WellKnownTypes.Option.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option> options_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option>();
+ /// <summary>
+ /// Protocol buffer options.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option> Options {
+ get { return options_; }
+ }
+
+ /// <summary>Field number for the "source_context" field.</summary>
+ public const int SourceContextFieldNumber = 4;
+ private global::Google.Protobuf.WellKnownTypes.SourceContext sourceContext_;
+ /// <summary>
+ /// The source context.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.SourceContext SourceContext {
+ get { return sourceContext_; }
+ set {
+ sourceContext_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "syntax" field.</summary>
+ public const int SyntaxFieldNumber = 5;
+ private global::Google.Protobuf.WellKnownTypes.Syntax syntax_ = 0;
+ /// <summary>
+ /// The source syntax.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Syntax Syntax {
+ get { return syntax_; }
+ set {
+ syntax_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Enum);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Enum other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ if(!enumvalue_.Equals(other.enumvalue_)) return false;
+ if(!options_.Equals(other.options_)) return false;
+ if (!object.Equals(SourceContext, other.SourceContext)) return false;
+ if (Syntax != other.Syntax) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ hash ^= enumvalue_.GetHashCode();
+ hash ^= options_.GetHashCode();
+ if (sourceContext_ != null) hash ^= SourceContext.GetHashCode();
+ if (Syntax != 0) hash ^= Syntax.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ enumvalue_.WriteTo(output, _repeated_enumvalue_codec);
+ options_.WriteTo(output, _repeated_options_codec);
+ if (sourceContext_ != null) {
+ output.WriteRawTag(34);
+ output.WriteMessage(SourceContext);
+ }
+ if (Syntax != 0) {
+ output.WriteRawTag(40);
+ output.WriteEnum((int) Syntax);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ size += enumvalue_.CalculateSize(_repeated_enumvalue_codec);
+ size += options_.CalculateSize(_repeated_options_codec);
+ if (sourceContext_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(SourceContext);
+ }
+ if (Syntax != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Syntax);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Enum other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ enumvalue_.Add(other.enumvalue_);
+ options_.Add(other.options_);
+ if (other.sourceContext_ != null) {
+ if (sourceContext_ == null) {
+ sourceContext_ = new global::Google.Protobuf.WellKnownTypes.SourceContext();
+ }
+ SourceContext.MergeFrom(other.SourceContext);
+ }
+ if (other.Syntax != 0) {
+ Syntax = other.Syntax;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 18: {
+ enumvalue_.AddEntriesFrom(input, _repeated_enumvalue_codec);
+ break;
+ }
+ case 26: {
+ options_.AddEntriesFrom(input, _repeated_options_codec);
+ break;
+ }
+ case 34: {
+ if (sourceContext_ == null) {
+ sourceContext_ = new global::Google.Protobuf.WellKnownTypes.SourceContext();
+ }
+ input.ReadMessage(sourceContext_);
+ break;
+ }
+ case 40: {
+ syntax_ = (global::Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Enum value definition.
+ /// </summary>
+ public sealed partial class EnumValue : pb::IMessage<EnumValue> {
+ private static readonly pb::MessageParser<EnumValue> _parser = new pb::MessageParser<EnumValue>(() => new EnumValue());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<EnumValue> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.TypeReflection.Descriptor.MessageTypes[3]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public EnumValue() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public EnumValue(EnumValue other) : this() {
+ name_ = other.name_;
+ number_ = other.number_;
+ options_ = other.options_.Clone();
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public EnumValue Clone() {
+ return new EnumValue(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ /// <summary>
+ /// Enum value name.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "number" field.</summary>
+ public const int NumberFieldNumber = 2;
+ private int number_;
+ /// <summary>
+ /// Enum value number.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Number {
+ get { return number_; }
+ set {
+ number_ = value;
+ }
+ }
+
+ /// <summary>Field number for the "options" field.</summary>
+ public const int OptionsFieldNumber = 3;
+ private static readonly pb::FieldCodec<global::Google.Protobuf.WellKnownTypes.Option> _repeated_options_codec
+ = pb::FieldCodec.ForMessage(26, global::Google.Protobuf.WellKnownTypes.Option.Parser);
+ private readonly pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option> options_ = new pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option>();
+ /// <summary>
+ /// Protocol buffer options.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pbc::RepeatedField<global::Google.Protobuf.WellKnownTypes.Option> Options {
+ get { return options_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as EnumValue);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(EnumValue other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ if (Number != other.Number) return false;
+ if(!options_.Equals(other.options_)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ if (Number != 0) hash ^= Number.GetHashCode();
+ hash ^= options_.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ if (Number != 0) {
+ output.WriteRawTag(16);
+ output.WriteInt32(Number);
+ }
+ options_.WriteTo(output, _repeated_options_codec);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ if (Number != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Number);
+ }
+ size += options_.CalculateSize(_repeated_options_codec);
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(EnumValue other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ if (other.Number != 0) {
+ Number = other.Number;
+ }
+ options_.Add(other.options_);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 16: {
+ Number = input.ReadInt32();
+ break;
+ }
+ case 26: {
+ options_.AddEntriesFrom(input, _repeated_options_codec);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// A protocol buffer option, which can be attached to a message, field,
+ /// enumeration, etc.
+ /// </summary>
+ public sealed partial class Option : pb::IMessage<Option> {
+ private static readonly pb::MessageParser<Option> _parser = new pb::MessageParser<Option>(() => new Option());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Option> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.TypeReflection.Descriptor.MessageTypes[4]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Option() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Option(Option other) : this() {
+ name_ = other.name_;
+ Value = other.value_ != null ? other.Value.Clone() : null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Option Clone() {
+ return new Option(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ /// <summary>
+ /// The option's name. For protobuf built-in options (options defined in
+ /// descriptor.proto), this is the short name. For example, `"map_entry"`.
+ /// For custom options, it should be the fully-qualified name. For example,
+ /// `"google.api.http"`.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ /// <summary>Field number for the "value" field.</summary>
+ public const int ValueFieldNumber = 2;
+ private global::Google.Protobuf.WellKnownTypes.Any value_;
+ /// <summary>
+ /// The option's value packed in an Any message. If the value is a primitive,
+ /// the corresponding wrapper type defined in google/protobuf/wrappers.proto
+ /// should be used. If the value is an enum, it should be stored as an int32
+ /// value using the google.protobuf.Int32Value type.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.Any Value {
+ get { return value_; }
+ set {
+ value_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Option);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Option other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ if (!object.Equals(Value, other.Value)) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ if (value_ != null) hash ^= Value.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ if (value_ != null) {
+ output.WriteRawTag(18);
+ output.WriteMessage(Value);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ if (value_ != null) {
+ size += 1 + pb::CodedOutputStream.ComputeMessageSize(Value);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Option other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ if (other.value_ != null) {
+ if (value_ == null) {
+ value_ = new global::Google.Protobuf.WellKnownTypes.Any();
+ }
+ Value.MergeFrom(other.Value);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ case 18: {
+ if (value_ == null) {
+ value_ = new global::Google.Protobuf.WellKnownTypes.Any();
+ }
+ input.ReadMessage(value_);
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/ValuePartial.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/ValuePartial.cs
new file mode 100644
index 0000000000..d34b560de0
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/ValuePartial.cs
@@ -0,0 +1,99 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+namespace Google.Protobuf.WellKnownTypes
+{
+ public partial class Value
+ {
+ /// <summary>
+ /// Convenience method to create a Value message with a string value.
+ /// </summary>
+ /// <param name="value">Value to set for the StringValue property.</param>
+ /// <returns>A newly-created Value message with the given value.</returns>
+ public static Value ForString(string value)
+ {
+ ProtoPreconditions.CheckNotNull(value, "value");
+ return new Value { StringValue = value };
+ }
+
+ /// <summary>
+ /// Convenience method to create a Value message with a number value.
+ /// </summary>
+ /// <param name="value">Value to set for the NumberValue property.</param>
+ /// <returns>A newly-created Value message with the given value.</returns>
+ public static Value ForNumber(double value)
+ {
+ return new Value { NumberValue = value };
+ }
+
+ /// <summary>
+ /// Convenience method to create a Value message with a Boolean value.
+ /// </summary>
+ /// <param name="value">Value to set for the BoolValue property.</param>
+ /// <returns>A newly-created Value message with the given value.</returns>
+ public static Value ForBool(bool value)
+ {
+ return new Value { BoolValue = value };
+ }
+
+ /// <summary>
+ /// Convenience method to create a Value message with a null initial value.
+ /// </summary>
+ /// <returns>A newly-created Value message a null initial value.</returns>
+ public static Value ForNull()
+ {
+ return new Value { NullValue = 0 };
+ }
+
+ /// <summary>
+ /// Convenience method to create a Value message with an initial list of values.
+ /// </summary>
+ /// <remarks>The values provided are not cloned; the references are copied directly.</remarks>
+ /// <returns>A newly-created Value message an initial list value.</returns>
+ public static Value ForList(params Value[] values)
+ {
+ ProtoPreconditions.CheckNotNull(values, "values");
+ return new Value { ListValue = new ListValue { Values = { values } } };
+ }
+
+ /// <summary>
+ /// Convenience method to create a Value message with an initial struct value
+ /// </summary>
+ /// <remarks>The value provided is not cloned; the reference is copied directly.</remarks>
+ /// <returns>A newly-created Value message an initial struct value.</returns>
+ public static Value ForStruct(Struct value)
+ {
+ ProtoPreconditions.CheckNotNull(value, "value");
+ return new Value { StructValue = value };
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs
new file mode 100644
index 0000000000..9a5fb81ee9
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs
@@ -0,0 +1,1182 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/wrappers.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Google.Protobuf.WellKnownTypes {
+
+ /// <summary>Holder for reflection information generated from google/protobuf/wrappers.proto</summary>
+ public static partial class WrappersReflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for google/protobuf/wrappers.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static WrappersReflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "Ch5nb29nbGUvcHJvdG9idWYvd3JhcHBlcnMucHJvdG8SD2dvb2dsZS5wcm90",
+ "b2J1ZiIcCgtEb3VibGVWYWx1ZRINCgV2YWx1ZRgBIAEoASIbCgpGbG9hdFZh",
+ "bHVlEg0KBXZhbHVlGAEgASgCIhsKCkludDY0VmFsdWUSDQoFdmFsdWUYASAB",
+ "KAMiHAoLVUludDY0VmFsdWUSDQoFdmFsdWUYASABKAQiGwoKSW50MzJWYWx1",
+ "ZRINCgV2YWx1ZRgBIAEoBSIcCgtVSW50MzJWYWx1ZRINCgV2YWx1ZRgBIAEo",
+ "DSIaCglCb29sVmFsdWUSDQoFdmFsdWUYASABKAgiHAoLU3RyaW5nVmFsdWUS",
+ "DQoFdmFsdWUYASABKAkiGwoKQnl0ZXNWYWx1ZRINCgV2YWx1ZRgBIAEoDEJ8",
+ "ChNjb20uZ29vZ2xlLnByb3RvYnVmQg1XcmFwcGVyc1Byb3RvUAFaKmdpdGh1",
+ "Yi5jb20vZ29sYW5nL3Byb3RvYnVmL3B0eXBlcy93cmFwcGVyc/gBAaICA0dQ",
+ "QqoCHkdvb2dsZS5Qcm90b2J1Zi5XZWxsS25vd25UeXBlc2IGcHJvdG8z"));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { },
+ new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.DoubleValue), global::Google.Protobuf.WellKnownTypes.DoubleValue.Parser, new[]{ "Value" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.FloatValue), global::Google.Protobuf.WellKnownTypes.FloatValue.Parser, new[]{ "Value" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.Int64Value), global::Google.Protobuf.WellKnownTypes.Int64Value.Parser, new[]{ "Value" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.UInt64Value), global::Google.Protobuf.WellKnownTypes.UInt64Value.Parser, new[]{ "Value" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.Int32Value), global::Google.Protobuf.WellKnownTypes.Int32Value.Parser, new[]{ "Value" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.UInt32Value), global::Google.Protobuf.WellKnownTypes.UInt32Value.Parser, new[]{ "Value" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.BoolValue), global::Google.Protobuf.WellKnownTypes.BoolValue.Parser, new[]{ "Value" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.StringValue), global::Google.Protobuf.WellKnownTypes.StringValue.Parser, new[]{ "Value" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.WellKnownTypes.BytesValue), global::Google.Protobuf.WellKnownTypes.BytesValue.Parser, new[]{ "Value" }, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Messages
+ /// <summary>
+ /// Wrapper message for `double`.
+ ///
+ /// The JSON representation for `DoubleValue` is JSON number.
+ /// </summary>
+ public sealed partial class DoubleValue : pb::IMessage<DoubleValue> {
+ private static readonly pb::MessageParser<DoubleValue> _parser = new pb::MessageParser<DoubleValue>(() => new DoubleValue());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<DoubleValue> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor.MessageTypes[0]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DoubleValue() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DoubleValue(DoubleValue other) : this() {
+ value_ = other.value_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public DoubleValue Clone() {
+ return new DoubleValue(this);
+ }
+
+ /// <summary>Field number for the "value" field.</summary>
+ public const int ValueFieldNumber = 1;
+ private double value_;
+ /// <summary>
+ /// The double value.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public double Value {
+ get { return value_; }
+ set {
+ value_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as DoubleValue);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(DoubleValue other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Value != other.Value) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Value != 0D) hash ^= Value.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Value != 0D) {
+ output.WriteRawTag(9);
+ output.WriteDouble(Value);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Value != 0D) {
+ size += 1 + 8;
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(DoubleValue other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Value != 0D) {
+ Value = other.Value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 9: {
+ Value = input.ReadDouble();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Wrapper message for `float`.
+ ///
+ /// The JSON representation for `FloatValue` is JSON number.
+ /// </summary>
+ public sealed partial class FloatValue : pb::IMessage<FloatValue> {
+ private static readonly pb::MessageParser<FloatValue> _parser = new pb::MessageParser<FloatValue>(() => new FloatValue());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<FloatValue> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor.MessageTypes[1]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FloatValue() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FloatValue(FloatValue other) : this() {
+ value_ = other.value_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public FloatValue Clone() {
+ return new FloatValue(this);
+ }
+
+ /// <summary>Field number for the "value" field.</summary>
+ public const int ValueFieldNumber = 1;
+ private float value_;
+ /// <summary>
+ /// The float value.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public float Value {
+ get { return value_; }
+ set {
+ value_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as FloatValue);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(FloatValue other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Value != other.Value) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Value != 0F) hash ^= Value.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Value != 0F) {
+ output.WriteRawTag(13);
+ output.WriteFloat(Value);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Value != 0F) {
+ size += 1 + 4;
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(FloatValue other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Value != 0F) {
+ Value = other.Value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 13: {
+ Value = input.ReadFloat();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Wrapper message for `int64`.
+ ///
+ /// The JSON representation for `Int64Value` is JSON string.
+ /// </summary>
+ public sealed partial class Int64Value : pb::IMessage<Int64Value> {
+ private static readonly pb::MessageParser<Int64Value> _parser = new pb::MessageParser<Int64Value>(() => new Int64Value());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Int64Value> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor.MessageTypes[2]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Int64Value() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Int64Value(Int64Value other) : this() {
+ value_ = other.value_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Int64Value Clone() {
+ return new Int64Value(this);
+ }
+
+ /// <summary>Field number for the "value" field.</summary>
+ public const int ValueFieldNumber = 1;
+ private long value_;
+ /// <summary>
+ /// The int64 value.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public long Value {
+ get { return value_; }
+ set {
+ value_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Int64Value);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Int64Value other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Value != other.Value) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Value != 0L) hash ^= Value.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Value != 0L) {
+ output.WriteRawTag(8);
+ output.WriteInt64(Value);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Value != 0L) {
+ size += 1 + pb::CodedOutputStream.ComputeInt64Size(Value);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Int64Value other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Value != 0L) {
+ Value = other.Value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Value = input.ReadInt64();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Wrapper message for `uint64`.
+ ///
+ /// The JSON representation for `UInt64Value` is JSON string.
+ /// </summary>
+ public sealed partial class UInt64Value : pb::IMessage<UInt64Value> {
+ private static readonly pb::MessageParser<UInt64Value> _parser = new pb::MessageParser<UInt64Value>(() => new UInt64Value());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<UInt64Value> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor.MessageTypes[3]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public UInt64Value() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public UInt64Value(UInt64Value other) : this() {
+ value_ = other.value_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public UInt64Value Clone() {
+ return new UInt64Value(this);
+ }
+
+ /// <summary>Field number for the "value" field.</summary>
+ public const int ValueFieldNumber = 1;
+ private ulong value_;
+ /// <summary>
+ /// The uint64 value.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ulong Value {
+ get { return value_; }
+ set {
+ value_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as UInt64Value);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(UInt64Value other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Value != other.Value) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Value != 0UL) hash ^= Value.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Value != 0UL) {
+ output.WriteRawTag(8);
+ output.WriteUInt64(Value);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Value != 0UL) {
+ size += 1 + pb::CodedOutputStream.ComputeUInt64Size(Value);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(UInt64Value other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Value != 0UL) {
+ Value = other.Value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Value = input.ReadUInt64();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Wrapper message for `int32`.
+ ///
+ /// The JSON representation for `Int32Value` is JSON number.
+ /// </summary>
+ public sealed partial class Int32Value : pb::IMessage<Int32Value> {
+ private static readonly pb::MessageParser<Int32Value> _parser = new pb::MessageParser<Int32Value>(() => new Int32Value());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<Int32Value> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor.MessageTypes[4]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Int32Value() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Int32Value(Int32Value other) : this() {
+ value_ = other.value_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public Int32Value Clone() {
+ return new Int32Value(this);
+ }
+
+ /// <summary>Field number for the "value" field.</summary>
+ public const int ValueFieldNumber = 1;
+ private int value_;
+ /// <summary>
+ /// The int32 value.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int Value {
+ get { return value_; }
+ set {
+ value_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as Int32Value);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(Int32Value other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Value != other.Value) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Value != 0) hash ^= Value.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Value != 0) {
+ output.WriteRawTag(8);
+ output.WriteInt32(Value);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Value != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32Size(Value);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(Int32Value other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Value != 0) {
+ Value = other.Value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Value = input.ReadInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Wrapper message for `uint32`.
+ ///
+ /// The JSON representation for `UInt32Value` is JSON number.
+ /// </summary>
+ public sealed partial class UInt32Value : pb::IMessage<UInt32Value> {
+ private static readonly pb::MessageParser<UInt32Value> _parser = new pb::MessageParser<UInt32Value>(() => new UInt32Value());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<UInt32Value> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor.MessageTypes[5]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public UInt32Value() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public UInt32Value(UInt32Value other) : this() {
+ value_ = other.value_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public UInt32Value Clone() {
+ return new UInt32Value(this);
+ }
+
+ /// <summary>Field number for the "value" field.</summary>
+ public const int ValueFieldNumber = 1;
+ private uint value_;
+ /// <summary>
+ /// The uint32 value.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public uint Value {
+ get { return value_; }
+ set {
+ value_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as UInt32Value);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(UInt32Value other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Value != other.Value) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Value != 0) hash ^= Value.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Value != 0) {
+ output.WriteRawTag(8);
+ output.WriteUInt32(Value);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Value != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeUInt32Size(Value);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(UInt32Value other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Value != 0) {
+ Value = other.Value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Value = input.ReadUInt32();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Wrapper message for `bool`.
+ ///
+ /// The JSON representation for `BoolValue` is JSON `true` and `false`.
+ /// </summary>
+ public sealed partial class BoolValue : pb::IMessage<BoolValue> {
+ private static readonly pb::MessageParser<BoolValue> _parser = new pb::MessageParser<BoolValue>(() => new BoolValue());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<BoolValue> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor.MessageTypes[6]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public BoolValue() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public BoolValue(BoolValue other) : this() {
+ value_ = other.value_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public BoolValue Clone() {
+ return new BoolValue(this);
+ }
+
+ /// <summary>Field number for the "value" field.</summary>
+ public const int ValueFieldNumber = 1;
+ private bool value_;
+ /// <summary>
+ /// The bool value.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Value {
+ get { return value_; }
+ set {
+ value_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as BoolValue);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(BoolValue other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Value != other.Value) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Value != false) hash ^= Value.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Value != false) {
+ output.WriteRawTag(8);
+ output.WriteBool(Value);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Value != false) {
+ size += 1 + 1;
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(BoolValue other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Value != false) {
+ Value = other.Value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 8: {
+ Value = input.ReadBool();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Wrapper message for `string`.
+ ///
+ /// The JSON representation for `StringValue` is JSON string.
+ /// </summary>
+ public sealed partial class StringValue : pb::IMessage<StringValue> {
+ private static readonly pb::MessageParser<StringValue> _parser = new pb::MessageParser<StringValue>(() => new StringValue());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<StringValue> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor.MessageTypes[7]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public StringValue() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public StringValue(StringValue other) : this() {
+ value_ = other.value_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public StringValue Clone() {
+ return new StringValue(this);
+ }
+
+ /// <summary>Field number for the "value" field.</summary>
+ public const int ValueFieldNumber = 1;
+ private string value_ = "";
+ /// <summary>
+ /// The string value.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Value {
+ get { return value_; }
+ set {
+ value_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as StringValue);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(StringValue other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Value != other.Value) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Value.Length != 0) hash ^= Value.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Value.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Value);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Value.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Value);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(StringValue other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Value.Length != 0) {
+ Value = other.Value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Value = input.ReadString();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Wrapper message for `bytes`.
+ ///
+ /// The JSON representation for `BytesValue` is JSON string.
+ /// </summary>
+ public sealed partial class BytesValue : pb::IMessage<BytesValue> {
+ private static readonly pb::MessageParser<BytesValue> _parser = new pb::MessageParser<BytesValue>(() => new BytesValue());
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pb::MessageParser<BytesValue> Parser { get { return _parser; } }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor.MessageTypes[8]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public BytesValue() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public BytesValue(BytesValue other) : this() {
+ value_ = other.value_;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public BytesValue Clone() {
+ return new BytesValue(this);
+ }
+
+ /// <summary>Field number for the "value" field.</summary>
+ public const int ValueFieldNumber = 1;
+ private pb::ByteString value_ = pb::ByteString.Empty;
+ /// <summary>
+ /// The bytes value.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public pb::ByteString Value {
+ get { return value_; }
+ set {
+ value_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as BytesValue);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(BytesValue other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Value != other.Value) return false;
+ return true;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Value.Length != 0) hash ^= Value.GetHashCode();
+ return hash;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Value.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteBytes(Value);
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (Value.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeBytesSize(Value);
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(BytesValue other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Value.Length != 0) {
+ Value = other.Value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Value = input.ReadBytes();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/WrappersPartial.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/WrappersPartial.cs
new file mode 100644
index 0000000000..9f620eb401
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WellKnownTypes/WrappersPartial.cs
@@ -0,0 +1,42 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+namespace Google.Protobuf.WellKnownTypes
+{
+ public static partial class WrappersReflection
+ {
+ /// <summary>
+ /// Field number for the single "value" field in all wrapper types.
+ /// </summary>
+ internal const int WrapperValueFieldNumber = Int32Value.ValueFieldNumber;
+ }
+}
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/WireFormat.cs b/third_party/protobuf/csharp/src/Google.Protobuf/WireFormat.cs
new file mode 100644
index 0000000000..faf1e715ef
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/WireFormat.cs
@@ -0,0 +1,104 @@
+#region Copyright notice and license
+// 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.
+#endregion
+
+namespace Google.Protobuf
+{
+ /// <summary>
+ /// This class is used internally by the Protocol Buffer Library and generated
+ /// message implementations. It is public only for the sake of those generated
+ /// messages. Others should not use this class directly.
+ /// <para>
+ /// This class contains constants and helper functions useful for dealing with
+ /// the Protocol Buffer wire format.
+ /// </para>
+ /// </summary>
+ public static class WireFormat
+ {
+ /// <summary>
+ /// Wire types within protobuf encoding.
+ /// </summary>
+ public enum WireType : uint
+ {
+ /// <summary>
+ /// Variable-length integer.
+ /// </summary>
+ Varint = 0,
+ /// <summary>
+ /// A fixed-length 64-bit value.
+ /// </summary>
+ Fixed64 = 1,
+ /// <summary>
+ /// A length-delimited value, i.e. a length followed by that many bytes of data.
+ /// </summary>
+ LengthDelimited = 2,
+ /// <summary>
+ /// A "start group" value - not supported by this implementation.
+ /// </summary>
+ StartGroup = 3,
+ /// <summary>
+ /// An "end group" value - not supported by this implementation.
+ /// </summary>
+ EndGroup = 4,
+ /// <summary>
+ /// A fixed-length 32-bit value.
+ /// </summary>
+ Fixed32 = 5
+ }
+
+ private const int TagTypeBits = 3;
+ private const uint TagTypeMask = (1 << TagTypeBits) - 1;
+
+ /// <summary>
+ /// Given a tag value, determines the wire type (lower 3 bits).
+ /// </summary>
+ public static WireType GetTagWireType(uint tag)
+ {
+ return (WireType) (tag & TagTypeMask);
+ }
+
+ /// <summary>
+ /// Given a tag value, determines the field number (the upper 29 bits).
+ /// </summary>
+ public static int GetTagFieldNumber(uint tag)
+ {
+ return (int) tag >> TagTypeBits;
+ }
+
+ /// <summary>
+ /// Makes a tag value given a field number and wire type.
+ /// </summary>
+ public static uint MakeTag(int fieldNumber, WireType wireType)
+ {
+ return (uint) (fieldNumber << TagTypeBits) | (uint) wireType;
+ }
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/csharp/src/Google.Protobuf/project.json b/third_party/protobuf/csharp/src/Google.Protobuf/project.json
new file mode 100644
index 0000000000..961e037e18
--- /dev/null
+++ b/third_party/protobuf/csharp/src/Google.Protobuf/project.json
@@ -0,0 +1,65 @@
+{
+ "version": "3.2.0",
+ "title": "Google Protocol Buffers",
+ "description": "See project site for more info.",
+ "authors": [ "Google Inc." ],
+ "copyright": "Copyright 2015, Google Inc.",
+
+ "packOptions": {
+ "summary": "C# runtime library for Protocol Buffers - Google's data interchange format.",
+ "tags": [ "Protocol", "Buffers", "Binary", "Serialization", "Format", "Google", "proto", "proto3" ],
+ "owners": [ "protobuf-packages" ],
+ "licenseUrl": "https://github.com/google/protobuf/blob/master/LICENSE",
+ "projectUrl": "https://github.com/google/protobuf",
+ "releaseNotes": "C# proto3 support",
+ "requireLicenseAcceptance": false,
+ "repository": {
+ "url": "https://github.com/nodatime/nodatime.git"
+ }
+ },
+
+ "buildOptions": {
+ "debugType": "portable",
+ "keyFile": "../../keys/Google.Protobuf.snk",
+ "xmlDoc": true
+ },
+
+ "configurations": {
+ "Debug": {
+ "buildOptions": {
+ "define": [ "DEBUG", "TRACE" ]
+ }
+ },
+ "Release": {
+ "buildOptions": {
+ "define": [ "RELEASE", "TRACE" ],
+ "optimize": true
+ }
+ }
+ },
+
+ "frameworks": {
+ // This target allows the package to be installed in a .NET 4.5+
+ // project without asking for myriad other dependencies.
+ "net45": {
+ },
+ "netstandard1.0": {
+ "dependencies": {
+ "System.Collections": "4.0.11",
+ "System.Diagnostics.Debug": "4.0.11",
+ "System.Globalization": "4.0.11",
+ "System.IO": "4.1.0",
+ "System.Linq": "4.1.0",
+ "System.Linq.Expressions": "4.1.0",
+ "System.ObjectModel": "4.0.12",
+ "System.Reflection": "4.1.0",
+ "System.Reflection.Extensions": "4.0.1",
+ "System.Runtime": "4.1.0",
+ "System.Runtime.Extensions": "4.1.0",
+ "System.Text.Encoding": "4.0.11",
+ "System.Text.RegularExpressions": "4.1.0",
+ "System.Threading": "4.0.11"
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/csharp/src/global.json b/third_party/protobuf/csharp/src/global.json
new file mode 100644
index 0000000000..9d5558b1a3
--- /dev/null
+++ b/third_party/protobuf/csharp/src/global.json
@@ -0,0 +1,5 @@
+{
+ "sdk": {
+ "version": "1.0.0-preview2-003131"
+ }
+}
diff --git a/third_party/protobuf/csharp/src/packages/repositories.config b/third_party/protobuf/csharp/src/packages/repositories.config
new file mode 100644
index 0000000000..7037941299
--- /dev/null
+++ b/third_party/protobuf/csharp/src/packages/repositories.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<repositories>
+ <repository path="..\Google.Protobuf.Test\packages.config" />
+</repositories> \ No newline at end of file
diff --git a/third_party/protobuf/docs/third_party.md b/third_party/protobuf/docs/third_party.md
new file mode 100644
index 0000000000..a1f918a749
--- /dev/null
+++ b/third_party/protobuf/docs/third_party.md
@@ -0,0 +1,156 @@
+# Third-Party Add-ons for Protocol Buffers
+
+This page lists code related to Protocol Buffers which is developed and maintained by third parties. You may find this code useful, but note that **these projects are not affiliated with or endorsed by Google (unless explicitly marked)**; try them at your own risk. Also note that many projects here are in the early stages of development and not production-ready.
+
+If you have a project that should be listed here, please [send us a pull request](https://github.com/google/protobuf/pulls) to update this page.
+
+## Programming Languages
+
+These are projects we know about implementing Protocol Buffers for other programming languages:
+* Action Script: http://code.google.com/p/protobuf-actionscript3/
+* Action Script: https://code.google.com/p/protoc-gen-as3/
+* Action Script: https://github.com/matrix3d/JProtoc
+* Action Script: https://github.com/zhongfq/protobuf-as3/
+* C: https://github.com/protobuf-c/protobuf-c
+* C: http://koti.kapsi.fi/jpa/nanopb/
+* C: https://github.com/cloudwu/pbc/
+* C: https://github.com/haberman/upb/wiki
+* C: https://github.com/squidfunk/protobluff
+* C++: https://github.com/google/protobuf (Google-official implementation)
+* C/C++: http://spbc.sf.net/
+* C#: http://code.google.com/p/protobuf-csharp-port
+* C#: http://code.google.com/p/protosharp/
+* C#: https://silentorbit.com/protobuf/
+* C#/.NET/WCF/VB: http://code.google.com/p/protobuf-net/
+* Clojure: http://github.com/ninjudd/clojure-protobuf
+* Common Lisp: http://github.com/ndantam/s-protobuf
+* Common Lisp: http://github.com/brown/protobuf
+* D: https://github.com/msoucy/dproto
+* D: http://256.makerslocal.org/wiki/index.php/ProtocolBuffer
+* D: https://github.com/opticron/ProtocolBuffer
+* Dart: https://github.com/dart-lang/dart-protobuf (runtime) https://github.com/dart-lang/dart-protoc-plugin (code generator)
+* Delphi: http://sourceforge.net/projects/protobuf-delphi/
+* Delphi: http://fundementals.sourceforge.net/dl.html
+* Elixir: https://github.com/jeremyong/exprotoc
+* Elm: https://github.com/tiziano88/elm-protobuf
+* Erlang: http://github.com/ngerakines/erlang_protobuffs/tree/master
+* Erlang: http://piqi.org/
+* Erlang: https://code.google.com/p/protoc-gen-erl/
+* Erlang: https://github.com/basho/erlang_protobuffs
+* Erlang: https://github.com/tomas-abrahamsson/gpb
+* Go: https://github.com/golang/protobuf (Google-official implementation)
+* Go: http://code.google.com/p/goprotobuf/
+* Go: https://github.com/akunspy/gopbuf
+* Haskell: http://hackage.haskell.org/package/hprotoc
+* Haxe: https://github.com/Atry/protoc-gen-haxe
+* Java: https://github.com/google/protobuf (Google-official implementation)
+* Java/Android: https://github.com/square/wire
+* Java ME: http://code.google.com/p/protobuf-javame/
+* Java ME: http://swingme.sourceforge.net/encode.shtml
+* Java ME: http://code.google.com/p/protobuf-j2me/
+* Javascript: http://code.google.com/p/protobuf-js/
+* Javascript: http://github.com/sirikata/protojs
+* Javascript: https://github.com/dcodeIO/ProtoBuf.js
+* Javascript: http://code.google.com/p/protobuf-for-node/
+* Javascript: http://code.google.com/p/protostuff/
+* Julia: https://github.com/tanmaykm/ProtoBuf.jl
+* Lua: http://code.google.com/p/protoc-gen-lua/
+* Lua: http://github.com/indygreg/lua-protobuf
+* Lua: https://github.com/Neopallium/lua-pb
+* Matlab: http://code.google.com/p/protobuf-matlab/
+* Mercury: http://code.google.com/p/protobuf-mercury/
+* Objective C: http://code.google.com/p/protobuf-objc/
+* Objective C: https://github.com/alexeyxo/protobuf-objc
+* OCaml: http://piqi.org/
+* Perl: http://groups.google.com/group/protobuf-perl
+* Perl: http://search.cpan.org/perldoc?Google::ProtocolBuffers
+* Perl: https://metacpan.org/pod/Google::ProtocolBuffers::Dynamic
+* Perl/XS: http://code.google.com/p/protobuf-perlxs/
+* PHP: http://code.google.com/p/pb4php/
+* PHP: https://github.com/allegro/php-protobuf/
+* PHP: https://github.com/chobie/php-protocolbuffers
+* PHP: http://drslump.github.com/Protobuf-PHP
+* Prolog: http://www.swi-prolog.org/pldoc/package/protobufs.html
+* Python: https://github.com/google/protobuf (Google-official implementation)
+* Python: http://eigenein.github.com/protobuf/
+* R: http://cran.r-project.org/package=RProtoBuf
+* Ruby: http://code.google.com/p/ruby-protobuf/
+* Ruby: http://github.com/mozy/ruby-protocol-buffers
+* Ruby: https://github.com/bmizerany/beefcake/tree/master/lib/beefcake
+* Ruby: https://github.com/localshred/protobuf
+* Rust: https://github.com/stepancheg/rust-protobuf/
+* Scala: http://github.com/jeffplaisance/scala-protobuf
+* Scala: http://code.google.com/p/protobuf-scala
+* Scala: https://github.com/SandroGrzicic/ScalaBuff
+* Scala: http://trueaccord.github.io/ScalaPB/
+* Swift: https://github.com/alexeyxo/protobuf-swift
+* Swift: https://github.com/apple/swift-protobuf/
+* Vala: https://launchpad.net/protobuf-vala
+* Visual Basic: http://code.google.com/p/protobuf-net/
+
+## RPC Implementations
+
+GRPC (http://www.grpc.io/) is Google's RPC implementation for Protocol Buffers. There are other third-party RPC implementations as well. Some of these actually work with Protocol Buffers service definitions (defined using the `service` keyword in `.proto` files) while others just use Protocol Buffers message objects.
+
+* https://github.com/grpc/grpc (C++, Node.js, Python, Ruby, Objective-C, PHP, C#, Google-official implementation)
+* http://zeroc.com/ice.html (Multiple languages)
+* http://code.google.com/p/protobuf-net/ (C#/.NET/WCF/VB)
+* https://launchpad.net/txprotobuf/ (Python)
+* https://github.com/modeswitch/protobuf-rpc (Python)
+* http://code.google.com/p/protobuf-socket-rpc/ (Java, Python)
+* http://code.google.com/p/proto-streamer/ (Java)
+* http://code.google.com/p/server1/ (C++)
+* http://deltavsoft.com/RcfUserGuide/Protobufs (C++)
+* http://code.google.com/p/protobuf-mina-rpc/ (Python client, Java server)
+* http://code.google.com/p/casocklib/ (C++)
+* http://code.google.com/p/cxf-protobuf/ (Java)
+* http://code.google.com/p/protobuf-remote/ (C++/C#)
+* http://code.google.com/p/protobuf-rpc-pro/ (Java)
+* https://code.google.com/p/protorpc/ (Go/C++)
+* https://code.google.com/p/eneter-protobuf-serializer/ (Java/.NET)
+* http://www.deltavsoft.com/RCFProto.html (C++/Java/Python/C#)
+* https://github.com/robbinfan/claire-protorpc (C++)
+* https://github.com/BaiduPS/sofa-pbrpc (C++)
+* https://github.com/ebencheung/arab (C++)
+* http://code.google.com/p/protobuf-csharp-rpc/ (C#)
+* https://github.com/thesamet/rpcz (C++/Python, based on ZeroMQ)
+* https://github.com/w359405949/libmaid (C++, Python)
+* https://github.com/madwyn/libpbrpc (C++)
+
+## Other Utilities
+
+There are miscellaneous other things you may find useful as a Protocol Buffers developer.
+
+* [Bazel Build](https://bazel.build)
+ * [rules_closure](https://github.com/bazelbuild/rules_closure) `js-closure`
+ * [rules_go](https://github.com/bazelbuild/rules_go) `go`
+ * [rules_protobuf](https://github.com/pubref/rules_protobuf) `java` `c++` `c#` `go` `js-closure` `js-node` `python` `ruby`
+* [NetBeans IDE plugin](http://code.google.com/p/protobuf-netbeans-plugin/)
+* [Wireshark/Ethereal packet sniffer plugin](http://code.google.com/p/protobuf-wireshark/)
+* [Alternate encodings (JSON, XML, HTML) for Java protobufs](http://code.google.com/p/protobuf-java-format/)
+* [Another JSON encoder/decoder for Java](https://github.com/sijuv/protobuf-codec)
+* [Editor for serialized protobufs](http://code.google.com/p/protobufeditor/)
+* [Intellij IDEA plugin](http://github.com/nnmatveev/idea-plugin-protobuf)
+* [TextMate syntax highlighting](http://github.com/michaeledgar/protobuf-tmbundle)
+* [Oracle PL SQL plugin](http://code.google.com/p/protocol-buffer-plsql/)
+* [Eclipse editor for protobuf (from Google)](http://code.google.com/p/protobuf-dt/)
+* [C++ Builder compatible protobuf](https://github.com/saadware/protobuf-cppbuilder)
+* Maven Protobuf Compiler Plugin
+ * By xolstice.org ([Documentation](https://www.xolstice.org/protobuf-maven-plugin/)) ([Source](https://github.com/xolstice/protobuf-maven-plugin/)) [![Maven Central](https://img.shields.io/maven-central/v/org.xolstice.maven.plugins/protobuf-maven-plugin.svg)](https://repo1.maven.org/maven2/org/xolstice/maven/plugins/protobuf-maven-plugin/)
+ * http://igor-petruk.github.com/protobuf-maven-plugin/
+ * http://code.google.com/p/maven-protoc-plugin/
+ * https://github.com/os72/protoc-jar-maven-plugin
+* [Documentation generator plugin (Markdown/HTML/DocBook/...)](https://github.com/estan/protoc-gen-doc)
+* [DocBook generator for .proto files](http://code.google.com/p/protoc-gen-docbook/)
+* [Protobuf for nginx module](https://github.com/dbcode/protobuf-nginx/)
+* [RSpec matchers and Cucumber step defs for testing Protocol Buffers](https://github.com/connamara/protobuf_spec)
+* [Sbt plugin for Protocol Buffers](https://github.com/Atry/sbt-cppp)
+* [Gradle Protobuf Plugin](https://github.com/aantono/gradle-plugin-protobuf)
+* [Multi-platform executable JAR and Java API for protoc](https://github.com/os72/protoc-jar)
+* [Python scripts to convert between Protocol Buffers and JSON](https://github.com/NextTuesday/py-pb-converters)
+* [Visual Studio Language Service support for Protocol Buffers](http://visualstudiogallery.msdn.microsoft.com/4bc0f38c-b058-4e05-ae38-155e053c19c5)
+* [C++ library for serialization/de-serialization between Protocol Buffers and JSON.](https://github.com/yinqiwen/pbjson)
+* [ProtoBuf with Java EE7 Expression Language 3.0; pure Java ProtoBuf Parser and Builder.](https://github.com/protobufel/protobuf-el)
+* [Notepad++ Syntax Highlighting for .proto files](https://github.com/chai2010/notepadplus-protobuf)
+* [Linter for .proto files](https://github.com/ckaznocha/protoc-gen-lint)
+* [Protocol Buffers Dynamic Schema - create protobuf schemas programmatically (Java)] (https://github.com/os72/protobuf-dynamic)
diff --git a/third_party/protobuf/editors/README.txt b/third_party/protobuf/editors/README.txt
new file mode 100644
index 0000000000..3e9fc79e9c
--- /dev/null
+++ b/third_party/protobuf/editors/README.txt
@@ -0,0 +1,5 @@
+This directory contains syntax highlighting and configuration files for editors
+to properly display Protocol Buffer files.
+
+See each file's header comment for directions on how to use it with the
+appropriate editor.
diff --git a/third_party/protobuf/editors/proto.vim b/third_party/protobuf/editors/proto.vim
new file mode 100644
index 0000000000..7f1aeb730a
--- /dev/null
+++ b/third_party/protobuf/editors/proto.vim
@@ -0,0 +1,105 @@
+" 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.
+
+" This is the Vim syntax file for Google Protocol Buffers.
+"
+" Usage:
+"
+" 1. cp proto.vim ~/.vim/syntax/
+" 2. Add the following to ~/.vimrc:
+"
+" augroup filetype
+" au! BufRead,BufNewFile *.proto setfiletype proto
+" augroup end
+"
+" Or just create a new file called ~/.vim/ftdetect/proto.vim with the
+" previous lines on it.
+
+if version < 600
+ syntax clear
+elseif exists("b:current_syntax")
+ finish
+endif
+
+syn case match
+
+syn keyword pbTodo contained TODO FIXME XXX
+syn cluster pbCommentGrp contains=pbTodo
+
+syn keyword pbSyntax syntax import option
+syn keyword pbStructure package message group oneof
+syn keyword pbRepeat optional required repeated
+syn keyword pbDefault default
+syn keyword pbExtend extend extensions to max reserved
+syn keyword pbRPC service rpc returns
+
+syn keyword pbType int32 int64 uint32 uint64 sint32 sint64
+syn keyword pbType fixed32 fixed64 sfixed32 sfixed64
+syn keyword pbType float double bool string bytes
+syn keyword pbTypedef enum
+syn keyword pbBool true false
+
+syn match pbInt /-\?\<\d\+\>/
+syn match pbInt /\<0[xX]\x+\>/
+syn match pbFloat /\<-\?\d*\(\.\d*\)\?/
+syn region pbComment start="\/\*" end="\*\/" contains=@pbCommentGrp
+syn region pbComment start="//" skip="\\$" end="$" keepend contains=@pbCommentGrp
+syn region pbString start=/"/ skip=/\\./ end=/"/
+syn region pbString start=/'/ skip=/\\./ end=/'/
+
+if version >= 508 || !exists("did_proto_syn_inits")
+ if version < 508
+ let did_proto_syn_inits = 1
+ command -nargs=+ HiLink hi link <args>
+ else
+ command -nargs=+ HiLink hi def link <args>
+ endif
+
+ HiLink pbTodo Todo
+
+ HiLink pbSyntax Include
+ HiLink pbStructure Structure
+ HiLink pbRepeat Repeat
+ HiLink pbDefault Keyword
+ HiLink pbExtend Keyword
+ HiLink pbRPC Keyword
+ HiLink pbType Type
+ HiLink pbTypedef Typedef
+ HiLink pbBool Boolean
+
+ HiLink pbInt Number
+ HiLink pbFloat Float
+ HiLink pbComment Comment
+ HiLink pbString String
+
+ delcommand HiLink
+endif
+
+let b:current_syntax = "proto"
diff --git a/third_party/protobuf/editors/protobuf-mode.el b/third_party/protobuf/editors/protobuf-mode.el
new file mode 100644
index 0000000000..1cef413757
--- /dev/null
+++ b/third_party/protobuf/editors/protobuf-mode.el
@@ -0,0 +1,221 @@
+;;; protobuf-mode.el --- major mode for editing protocol buffers.
+
+;; Author: Alexandre Vassalotti <alexandre@peadrop.com>
+;; Created: 23-Apr-2009
+;; Version: 0.3
+;; Keywords: google protobuf languages
+
+;; 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.
+
+;;; Commentary:
+
+;; Installation:
+;; - Put `protobuf-mode.el' in your Emacs load-path.
+;; - Add this line to your .emacs file:
+;; (require 'protobuf-mode)
+;;
+;; You can customize this mode just like any mode derived from CC Mode. If
+;; you want to add customizations specific to protobuf-mode, you can use the
+;; `protobuf-mode-hook'. For example, the following would make protocol-mode
+;; use 2-space indentation:
+;;
+;; (defconst my-protobuf-style
+;; '((c-basic-offset . 2)
+;; (indent-tabs-mode . nil)))
+;;
+;; (add-hook 'protobuf-mode-hook
+;; (lambda () (c-add-style "my-style" my-protobuf-style t)))
+;;
+;; Refer to the documentation of CC Mode for more information about
+;; customization details and how to use this mode.
+;;
+;; TODO:
+;; - Make highlighting for enum values work properly.
+;; - Fix the parser to recognize extensions as identifiers and not
+;; as casts.
+;; - Improve the parsing of option assignment lists. For example:
+;; optional int32 foo = 1 [(my_field_option) = 4.5];
+;; - Add support for fully-qualified identifiers (e.g., with a leading ".").
+
+;;; Code:
+
+(require 'cc-mode)
+(require 'cl)
+
+(eval-when-compile
+ (require 'cc-langs)
+ (require 'cc-fonts))
+
+;; This mode does not inherit properties from other modes. So, we do not use
+;; the usual `c-add-language' function.
+(eval-and-compile
+ (put 'protobuf-mode 'c-mode-prefix "protobuf-"))
+
+;; The following code uses of the `c-lang-defconst' macro define syntactic
+;; features of protocol buffer language. Refer to the documentation in the
+;; cc-langs.el file for information about the meaning of the -kwds variables.
+
+(c-lang-defconst c-primitive-type-kwds
+ protobuf '("double" "float" "int32" "int64" "uint32" "uint64" "sint32"
+ "sint64" "fixed32" "fixed64" "sfixed32" "sfixed64" "bool"
+ "string" "bytes" "group"))
+
+(c-lang-defconst c-modifier-kwds
+ protobuf '("required" "optional" "repeated"))
+
+(c-lang-defconst c-class-decl-kwds
+ protobuf '("message" "enum" "service"))
+
+(c-lang-defconst c-constant-kwds
+ protobuf '("true" "false"))
+
+(c-lang-defconst c-other-decl-kwds
+ protobuf '("package" "import"))
+
+(c-lang-defconst c-other-kwds
+ protobuf '("default" "max"))
+
+(c-lang-defconst c-identifier-ops
+ ;; Handle extended identifiers like google.protobuf.MessageOptions
+ protobuf '((left-assoc ".")))
+
+;; The following keywords do not fit well in keyword classes defined by
+;; cc-mode. So, we approximate as best we can.
+
+(c-lang-defconst c-type-list-kwds
+ protobuf '("extensions" "to" "reserved"))
+
+(c-lang-defconst c-typeless-decl-kwds
+ protobuf '("extend" "rpc" "option" "returns"))
+
+
+;; Here we remove default syntax for loops, if-statements and other C
+;; syntactic features that are not supported by the protocol buffer language.
+
+(c-lang-defconst c-brace-list-decl-kwds
+ ;; Remove syntax for C-style enumerations.
+ protobuf nil)
+
+(c-lang-defconst c-block-stmt-1-kwds
+ ;; Remove syntax for "do" and "else" keywords.
+ protobuf nil)
+
+(c-lang-defconst c-block-stmt-2-kwds
+ ;; Remove syntax for "for", "if", "switch" and "while" keywords.
+ protobuf nil)
+
+(c-lang-defconst c-simple-stmt-kwds
+ ;; Remove syntax for "break", "continue", "goto" and "return" keywords.
+ protobuf nil)
+
+(c-lang-defconst c-paren-stmt-kwds
+ ;; Remove special case for the "(;;)" in for-loops.
+ protobuf nil)
+
+(c-lang-defconst c-label-kwds
+ ;; Remove case label syntax for the "case" and "default" keywords.
+ protobuf nil)
+
+(c-lang-defconst c-before-label-kwds
+ ;; Remove special case for the label in a goto statement.
+ protobuf nil)
+
+(c-lang-defconst c-cpp-matchers
+ ;; Disable all the C preprocessor syntax.
+ protobuf nil)
+
+(c-lang-defconst c-decl-prefix-re
+ ;; Same as for C, except it does not match "(". This is needed for disabling
+ ;; the syntax for casts.
+ protobuf "\\([\{\};,]+\\)")
+
+
+;; Add support for variable levels of syntax highlighting.
+
+(defconst protobuf-font-lock-keywords-1 (c-lang-const c-matchers-1 protobuf)
+ "Minimal highlighting for protobuf-mode.")
+
+(defconst protobuf-font-lock-keywords-2 (c-lang-const c-matchers-2 protobuf)
+ "Fast normal highlighting for protobuf-mode.")
+
+(defconst protobuf-font-lock-keywords-3 (c-lang-const c-matchers-3 protobuf)
+ "Accurate normal highlighting for protobuf-mode.")
+
+(defvar protobuf-font-lock-keywords protobuf-font-lock-keywords-3
+ "Default expressions to highlight in protobuf-mode.")
+
+;; Our syntax table is auto-generated from the keyword classes we defined
+;; previously with the `c-lang-const' macro.
+(defvar protobuf-mode-syntax-table nil
+ "Syntax table used in protobuf-mode buffers.")
+(or protobuf-mode-syntax-table
+ (setq protobuf-mode-syntax-table
+ (funcall (c-lang-const c-make-mode-syntax-table protobuf))))
+
+(defvar protobuf-mode-abbrev-table nil
+ "Abbreviation table used in protobuf-mode buffers.")
+
+(defvar protobuf-mode-map nil
+ "Keymap used in protobuf-mode buffers.")
+(or protobuf-mode-map
+ (setq protobuf-mode-map (c-make-inherited-keymap)))
+
+(easy-menu-define protobuf-menu protobuf-mode-map
+ "Protocol Buffers Mode Commands"
+ (cons "Protocol Buffers" (c-lang-const c-mode-menu protobuf)))
+
+;;;###autoload (add-to-list 'auto-mode-alist '("\\.proto\\'" . protobuf-mode))
+
+;;;###autoload
+(defun protobuf-mode ()
+ "Major mode for editing Protocol Buffers description language.
+
+The hook `c-mode-common-hook' is run with no argument at mode
+initialization, then `protobuf-mode-hook'.
+
+Key bindings:
+\\{protobuf-mode-map}"
+ (interactive)
+ (kill-all-local-variables)
+ (set-syntax-table protobuf-mode-syntax-table)
+ (setq major-mode 'protobuf-mode
+ mode-name "Protocol-Buffers"
+ local-abbrev-table protobuf-mode-abbrev-table
+ abbrev-mode t)
+ (use-local-map protobuf-mode-map)
+ (c-initialize-cc-mode t)
+ (if (fboundp 'c-make-emacs-variables-local)
+ (c-make-emacs-variables-local))
+ (c-init-language-vars protobuf-mode)
+ (c-common-init 'protobuf-mode)
+ (easy-menu-add protobuf-menu)
+ (c-run-mode-hooks 'c-mode-common-hook 'protobuf-mode-hook)
+ (c-update-modeline))
+
+(provide 'protobuf-mode)
+
+;;; protobuf-mode.el ends here
diff --git a/third_party/protobuf/examples/AddPerson.java b/third_party/protobuf/examples/AddPerson.java
new file mode 100644
index 0000000000..c262ab7e60
--- /dev/null
+++ b/third_party/protobuf/examples/AddPerson.java
@@ -0,0 +1,95 @@
+// See README.txt for information and build instructions.
+
+import com.example.tutorial.AddressBookProtos.AddressBook;
+import com.example.tutorial.AddressBookProtos.Person;
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.io.PrintStream;
+
+class AddPerson {
+ // This function fills in a Person message based on user input.
+ static Person PromptForAddress(BufferedReader stdin,
+ PrintStream stdout) throws IOException {
+ Person.Builder person = Person.newBuilder();
+
+ stdout.print("Enter person ID: ");
+ person.setId(Integer.valueOf(stdin.readLine()));
+
+ stdout.print("Enter name: ");
+ person.setName(stdin.readLine());
+
+ stdout.print("Enter email address (blank for none): ");
+ String email = stdin.readLine();
+ if (email.length() > 0) {
+ person.setEmail(email);
+ }
+
+ while (true) {
+ stdout.print("Enter a phone number (or leave blank to finish): ");
+ String number = stdin.readLine();
+ if (number.length() == 0) {
+ break;
+ }
+
+ Person.PhoneNumber.Builder phoneNumber =
+ Person.PhoneNumber.newBuilder().setNumber(number);
+
+ stdout.print("Is this a mobile, home, or work phone? ");
+ String type = stdin.readLine();
+ if (type.equals("mobile")) {
+ phoneNumber.setType(Person.PhoneType.MOBILE);
+ } else if (type.equals("home")) {
+ phoneNumber.setType(Person.PhoneType.HOME);
+ } else if (type.equals("work")) {
+ phoneNumber.setType(Person.PhoneType.WORK);
+ } else {
+ stdout.println("Unknown phone type. Using default.");
+ }
+
+ person.addPhones(phoneNumber);
+ }
+
+ return person.build();
+ }
+
+ // Main function: Reads the entire address book from a file,
+ // adds one person based on user input, then writes it back out to the same
+ // file.
+ public static void main(String[] args) throws Exception {
+ if (args.length != 1) {
+ System.err.println("Usage: AddPerson ADDRESS_BOOK_FILE");
+ System.exit(-1);
+ }
+
+ AddressBook.Builder addressBook = AddressBook.newBuilder();
+
+ // Read the existing address book.
+ try {
+ FileInputStream input = new FileInputStream(args[0]);
+ try {
+ addressBook.mergeFrom(input);
+ } finally {
+ try { input.close(); } catch (Throwable ignore) {}
+ }
+ } catch (FileNotFoundException e) {
+ System.out.println(args[0] + ": File not found. Creating a new file.");
+ }
+
+ // Add an address.
+ addressBook.addPeople(
+ PromptForAddress(new BufferedReader(new InputStreamReader(System.in)),
+ System.out));
+
+ // Write the new address book back to disk.
+ FileOutputStream output = new FileOutputStream(args[0]);
+ try {
+ addressBook.build().writeTo(output);
+ } finally {
+ output.close();
+ }
+ }
+}
diff --git a/third_party/protobuf/examples/CMakeLists.txt b/third_party/protobuf/examples/CMakeLists.txt
new file mode 100644
index 0000000000..2cd2acc013
--- /dev/null
+++ b/third_party/protobuf/examples/CMakeLists.txt
@@ -0,0 +1,63 @@
+# Minimum CMake required
+cmake_minimum_required(VERSION 2.8.12)
+
+# Project
+project(protobuf-examples)
+
+# Find required protobuf package
+find_package(protobuf CONFIG REQUIRED)
+
+if(protobuf_VERBOSE)
+ message(STATUS "Using Protocol Buffers ${Protobuf_VERSION}")
+endif()
+
+set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
+
+# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
+if(MSVC AND protobuf_MSVC_STATIC_RUNTIME)
+ foreach(flag_var
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
+ if(${flag_var} MATCHES "/MD")
+ string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
+ endif(${flag_var} MATCHES "/MD")
+ endforeach()
+endif()
+
+foreach(example add_person list_people)
+ set(${example}_SRCS ${example}.cc)
+ set(${example}_PROTOS addressbook.proto)
+
+ #Code Generation
+ if(protobuf_MODULE_COMPATIBLE) #Legacy Support
+ protobuf_generate_cpp(${example}_PROTO_SRCS ${example}_PROTO_HDRS ${${example}_PROTOS})
+ list(APPEND ${example}_SRCS ${${example}_PROTO_SRCS} ${${example}_PROTO_HDRS})
+ else()
+
+ foreach(proto_file ${${example}_PROTOS})
+ get_filename_component(proto_file_abs ${proto_file} ABSOLUTE)
+ get_filename_component(basename ${proto_file} NAME_WE)
+ set(generated_files ${basename}.pb.cc ${basename}.pb.h)
+ list(APPEND ${example}_SRCS ${generated_files})
+
+ add_custom_command(
+ OUTPUT ${generated_files}
+ COMMAND protobuf::protoc
+ ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I ${CMAKE_CURRENT_SOURCE_DIR} ${proto_file_abs}
+ COMMENT "Generating ${generated_files} from ${proto_file}"
+ VERBATIM
+ )
+ endforeach()
+ endif()
+
+ #Executable setup
+ set(executable_name ${example}_cpp)
+ add_executable(${executable_name} ${${example}_SRCS} ${${example}_PROTOS})
+ if(protobuf_MODULE_COMPATIBLE) #Legacy mode
+ target_include_directories(${executable_name} PUBLIC ${PROTOBUF_INCLUDE_DIRS})
+ target_link_libraries(${executable_name} ${PROTOBUF_LIBRARIES})
+ else()
+ target_link_libraries(${executable_name} protobuf::libprotobuf)
+ endif()
+
+endforeach()
diff --git a/third_party/protobuf/examples/ListPeople.java b/third_party/protobuf/examples/ListPeople.java
new file mode 100644
index 0000000000..7892430508
--- /dev/null
+++ b/third_party/protobuf/examples/ListPeople.java
@@ -0,0 +1,50 @@
+// See README.txt for information and build instructions.
+
+import com.example.tutorial.AddressBookProtos.AddressBook;
+import com.example.tutorial.AddressBookProtos.Person;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+
+class ListPeople {
+ // Iterates though all people in the AddressBook and prints info about them.
+ static void Print(AddressBook addressBook) {
+ for (Person person: addressBook.getPeopleList()) {
+ System.out.println("Person ID: " + person.getId());
+ System.out.println(" Name: " + person.getName());
+ if (!person.getEmail().isEmpty()) {
+ System.out.println(" E-mail address: " + person.getEmail());
+ }
+
+ for (Person.PhoneNumber phoneNumber : person.getPhonesList()) {
+ switch (phoneNumber.getType()) {
+ case MOBILE:
+ System.out.print(" Mobile phone #: ");
+ break;
+ case HOME:
+ System.out.print(" Home phone #: ");
+ break;
+ case WORK:
+ System.out.print(" Work phone #: ");
+ break;
+ }
+ System.out.println(phoneNumber.getNumber());
+ }
+ }
+ }
+
+ // Main function: Reads the entire address book from a file and prints all
+ // the information inside.
+ public static void main(String[] args) throws Exception {
+ if (args.length != 1) {
+ System.err.println("Usage: ListPeople ADDRESS_BOOK_FILE");
+ System.exit(-1);
+ }
+
+ // Read the existing address book.
+ AddressBook addressBook =
+ AddressBook.parseFrom(new FileInputStream(args[0]));
+
+ Print(addressBook);
+ }
+}
diff --git a/third_party/protobuf/examples/Makefile b/third_party/protobuf/examples/Makefile
new file mode 100644
index 0000000000..51f134267a
--- /dev/null
+++ b/third_party/protobuf/examples/Makefile
@@ -0,0 +1,79 @@
+# See README.txt.
+
+.PHONY: all cpp java python clean
+
+all: cpp java python
+
+cpp: add_person_cpp list_people_cpp
+go: add_person_go list_people_go
+gotest: add_person_gotest list_people_gotest
+java: add_person_java list_people_java
+python: add_person_python list_people_python
+
+clean:
+ rm -f add_person_cpp list_people_cpp add_person_java list_people_java add_person_python list_people_python
+ rm -f javac_middleman AddPerson*.class ListPeople*.class com/example/tutorial/*.class
+ rm -f protoc_middleman addressbook.pb.cc addressbook.pb.h addressbook_pb2.py com/example/tutorial/AddressBookProtos.java
+ rm -f *.pyc
+ rm -f protoc_middleman_go tutorial/*.pb.go add_person_go list_people_go
+ rmdir tutorial 2>/dev/null || true
+ rmdir com/example/tutorial 2>/dev/null || true
+ rmdir com/example 2>/dev/null || true
+ rmdir com 2>/dev/null || true
+
+protoc_middleman: addressbook.proto
+ protoc --cpp_out=. --java_out=. --python_out=. addressbook.proto
+ @touch protoc_middleman
+
+protoc_middleman_go: addressbook.proto
+ mkdir tutorial # make directory for go package
+ protoc --go_out=tutorial addressbook.proto
+ @touch protoc_middleman_go
+
+add_person_cpp: add_person.cc protoc_middleman
+ pkg-config --cflags protobuf # fails if protobuf is not installed
+ c++ add_person.cc addressbook.pb.cc -o add_person_cpp `pkg-config --cflags --libs protobuf`
+
+list_people_cpp: list_people.cc protoc_middleman
+ pkg-config --cflags protobuf # fails if protobuf is not installed
+ c++ list_people.cc addressbook.pb.cc -o list_people_cpp `pkg-config --cflags --libs protobuf`
+
+add_person_go: add_person.go protoc_middleman_go
+ go build -o add_person_go add_person.go
+
+add_person_gotest: add_person_test.go add_person_go
+ go test add_person.go add_person_test.go
+
+list_people_go: list_people.go protoc_middleman_go
+ go build -o list_people_go list_people.go
+
+list_people_gotest: list_people.go list_people_go
+ go test list_people.go list_people_test.go
+
+javac_middleman: AddPerson.java ListPeople.java protoc_middleman
+ javac AddPerson.java ListPeople.java com/example/tutorial/AddressBookProtos.java
+ @touch javac_middleman
+
+add_person_java: javac_middleman
+ @echo "Writing shortcut script add_person_java..."
+ @echo '#! /bin/sh' > add_person_java
+ @echo 'java -classpath .:$$CLASSPATH AddPerson "$$@"' >> add_person_java
+ @chmod +x add_person_java
+
+list_people_java: javac_middleman
+ @echo "Writing shortcut script list_people_java..."
+ @echo '#! /bin/sh' > list_people_java
+ @echo 'java -classpath .:$$CLASSPATH ListPeople "$$@"' >> list_people_java
+ @chmod +x list_people_java
+
+add_person_python: add_person.py protoc_middleman
+ @echo "Writing shortcut script add_person_python..."
+ @echo '#! /bin/sh' > add_person_python
+ @echo './add_person.py "$$@"' >> add_person_python
+ @chmod +x add_person_python
+
+list_people_python: list_people.py protoc_middleman
+ @echo "Writing shortcut script list_people_python..."
+ @echo '#! /bin/sh' > list_people_python
+ @echo './list_people.py "$$@"' >> list_people_python
+ @chmod +x list_people_python
diff --git a/third_party/protobuf/examples/README.txt b/third_party/protobuf/examples/README.txt
new file mode 100644
index 0000000000..b33f841417
--- /dev/null
+++ b/third_party/protobuf/examples/README.txt
@@ -0,0 +1,54 @@
+This directory contains example code that uses Protocol Buffers to manage an
+address book. Two programs are provided, each with three different
+implementations, one written in each of C++, Java, and Python. The add_person
+example adds a new person to an address book, prompting the user to input
+the person's information. The list_people example lists people already in the
+address book. The examples use the exact same format in all three languages,
+so you can, for example, use add_person_java to create an address book and then
+use list_people_python to read it.
+
+You must install the protobuf package before you can build these.
+
+To build all the examples (on a unix-like system), simply run "make". This
+creates the following executable files in the current directory:
+ add_person_cpp list_people_cpp
+ add_person_java list_people_java
+ add_person_python list_people_python
+
+If you only want to compile examples in one language, use "make cpp"*,
+"make java", or "make python".
+
+All of these programs simply take an address book file as their parameter.
+The add_person programs will create the file if it doesn't already exist.
+
+These examples are part of the Protocol Buffers tutorial, located at:
+ https://developers.google.com/protocol-buffers/docs/tutorials
+
+* Note that on some platforms you may have to edit the Makefile and remove
+"-lpthread" from the linker commands (perhaps replacing it with something else).
+We didn't do this automatically because we wanted to keep the example simple.
+
+## Go ##
+
+The Go example requires a plugin to the protocol buffer compiler, so it is not
+build with all the other examples. See:
+ https://github.com/golang/protobuf
+for more information about Go protocol buffer support.
+
+First, install the Protocol Buffers compiler (protoc).
+Then, install the Go Protocol Buffers plugin
+($GOPATH/bin must be in your $PATH for protoc to find it):
+ go get github.com/golang/protobuf/protoc-gen-go
+
+Build the Go samples in this directory with "make go". This creates the
+following executable files in the current directory:
+ add_person_go list_people_go
+To run the example:
+ ./add_person_go addressbook.data
+to add a person to the protocol buffer encoded file addressbook.data. The file
+is created if it does not exist. To view the data, run:
+ ./list_people_go addressbook.data
+
+Observe that the C++, Python, and Java examples in this directory run in a
+similar way and can view/modify files created by the Go example and vice
+versa.
diff --git a/third_party/protobuf/examples/add_person.cc b/third_party/protobuf/examples/add_person.cc
new file mode 100644
index 0000000000..9bec4b374d
--- /dev/null
+++ b/third_party/protobuf/examples/add_person.cc
@@ -0,0 +1,95 @@
+// See README.txt for information and build instructions.
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include "addressbook.pb.h"
+using namespace std;
+
+// This function fills in a Person message based on user input.
+void PromptForAddress(tutorial::Person* person) {
+ cout << "Enter person ID number: ";
+ int id;
+ cin >> id;
+ person->set_id(id);
+ cin.ignore(256, '\n');
+
+ cout << "Enter name: ";
+ getline(cin, *person->mutable_name());
+
+ cout << "Enter email address (blank for none): ";
+ string email;
+ getline(cin, email);
+ if (!email.empty()) {
+ person->set_email(email);
+ }
+
+ while (true) {
+ cout << "Enter a phone number (or leave blank to finish): ";
+ string number;
+ getline(cin, number);
+ if (number.empty()) {
+ break;
+ }
+
+ tutorial::Person::PhoneNumber* phone_number = person->add_phones();
+ phone_number->set_number(number);
+
+ cout << "Is this a mobile, home, or work phone? ";
+ string type;
+ getline(cin, type);
+ if (type == "mobile") {
+ phone_number->set_type(tutorial::Person::MOBILE);
+ } else if (type == "home") {
+ phone_number->set_type(tutorial::Person::HOME);
+ } else if (type == "work") {
+ phone_number->set_type(tutorial::Person::WORK);
+ } else {
+ cout << "Unknown phone type. Using default." << endl;
+ }
+ }
+}
+
+// Main function: Reads the entire address book from a file,
+// adds one person based on user input, then writes it back out to the same
+// file.
+int main(int argc, char* argv[]) {
+ // Verify that the version of the library that we linked against is
+ // compatible with the version of the headers we compiled against.
+ GOOGLE_PROTOBUF_VERIFY_VERSION;
+
+ if (argc != 2) {
+ cerr << "Usage: " << argv[0] << " ADDRESS_BOOK_FILE" << endl;
+ return -1;
+ }
+
+ tutorial::AddressBook address_book;
+
+ {
+ // Read the existing address book.
+ fstream input(argv[1], ios::in | ios::binary);
+ if (!input) {
+ cout << argv[1] << ": File not found. Creating a new file." << endl;
+ } else if (!address_book.ParseFromIstream(&input)) {
+ cerr << "Failed to parse address book." << endl;
+ return -1;
+ }
+ }
+
+ // Add an address.
+ PromptForAddress(address_book.add_people());
+
+ {
+ // Write the new address book back to disk.
+ fstream output(argv[1], ios::out | ios::trunc | ios::binary);
+ if (!address_book.SerializeToOstream(&output)) {
+ cerr << "Failed to write address book." << endl;
+ return -1;
+ }
+ }
+
+ // Optional: Delete all global objects allocated by libprotobuf.
+ google::protobuf::ShutdownProtobufLibrary();
+
+ return 0;
+}
diff --git a/third_party/protobuf/examples/add_person.go b/third_party/protobuf/examples/add_person.go
new file mode 100644
index 0000000000..4f2e7f7418
--- /dev/null
+++ b/third_party/protobuf/examples/add_person.go
@@ -0,0 +1,133 @@
+package main
+
+import (
+ "bufio"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "log"
+ "os"
+ "strings"
+
+ "github.com/golang/protobuf/proto"
+ pb "github.com/google/protobuf/examples/tutorial"
+)
+
+func promptForAddress(r io.Reader) (*pb.Person, error) {
+ // A protocol buffer can be created like any struct.
+ p := &pb.Person{}
+
+ rd := bufio.NewReader(r)
+ fmt.Print("Enter person ID number: ")
+ // An int32 field in the .proto file is represented as an int32 field
+ // in the generated Go struct.
+ if _, err := fmt.Fscanf(rd, "%d\n", &p.Id); err != nil {
+ return p, err
+ }
+
+ fmt.Print("Enter name: ")
+ name, err := rd.ReadString('\n')
+ if err != nil {
+ return p, err
+ }
+ // A string field in the .proto file results in a string field in Go.
+ // We trim the whitespace because rd.ReadString includes the trailing
+ // newline character in its output.
+ p.Name = strings.TrimSpace(name)
+
+ fmt.Print("Enter email address (blank for none): ")
+ email, err := rd.ReadString('\n')
+ if err != nil {
+ return p, err
+ }
+ p.Email = strings.TrimSpace(email)
+
+ for {
+ fmt.Print("Enter a phone number (or leave blank to finish): ")
+ phone, err := rd.ReadString('\n')
+ if err != nil {
+ return p, err
+ }
+ phone = strings.TrimSpace(phone)
+ if phone == "" {
+ break
+ }
+ // The PhoneNumber message type is nested within the Person
+ // message in the .proto file. This results in a Go struct
+ // named using the name of the parent prefixed to the name of
+ // the nested message. Just as with pb.Person, it can be
+ // created like any other struct.
+ pn := &pb.Person_PhoneNumber{
+ Number: phone,
+ }
+
+ fmt.Print("Is this a mobile, home, or work phone? ")
+ ptype, err := rd.ReadString('\n')
+ if err != nil {
+ return p, err
+ }
+ ptype = strings.TrimSpace(ptype)
+
+ // A proto enum results in a Go constant for each enum value.
+ switch ptype {
+ case "mobile":
+ pn.Type = pb.Person_MOBILE
+ case "home":
+ pn.Type = pb.Person_HOME
+ case "work":
+ pn.Type = pb.Person_WORK
+ default:
+ fmt.Printf("Unknown phone type %q. Using default.\n", ptype)
+ }
+
+ // A repeated proto field maps to a slice field in Go. We can
+ // append to it like any other slice.
+ p.Phones = append(p.Phones, pn)
+ }
+
+ return p, nil
+}
+
+// Main reads the entire address book from a file, adds one person based on
+// user input, then writes it back out to the same file.
+func main() {
+ if len(os.Args) != 2 {
+ log.Fatalf("Usage: %s ADDRESS_BOOK_FILE\n", os.Args[0])
+ }
+ fname := os.Args[1]
+
+ // Read the existing address book.
+ in, err := ioutil.ReadFile(fname)
+ if err != nil {
+ if os.IsNotExist(err) {
+ fmt.Printf("%s: File not found. Creating new file.\n", fname)
+ } else {
+ log.Fatalln("Error reading file:", err)
+ }
+ }
+
+ // [START marshal_proto]
+ book := &pb.AddressBook{}
+ // [START_EXCLUDE]
+ if err := proto.Unmarshal(in, book); err != nil {
+ log.Fatalln("Failed to parse address book:", err)
+ }
+
+ // Add an address.
+ addr, err := promptForAddress(os.Stdin)
+ if err != nil {
+ log.Fatalln("Error with address:", err)
+ }
+ book.People = append(book.People, addr)
+ // [END_EXCLUDE]
+
+ // Write the new address book back to disk.
+ out, err := proto.Marshal(book)
+ if err != nil {
+ log.Fatalln("Failed to encode address book:", err)
+ }
+ if err := ioutil.WriteFile(fname, out, 0644); err != nil {
+ log.Fatalln("Failed to write address book:", err)
+ }
+ // [END marshal_proto]
+}
diff --git a/third_party/protobuf/examples/add_person.py b/third_party/protobuf/examples/add_person.py
new file mode 100755
index 0000000000..0b6985792d
--- /dev/null
+++ b/third_party/protobuf/examples/add_person.py
@@ -0,0 +1,56 @@
+#! /usr/bin/env python
+
+# See README.txt for information and build instructions.
+
+import addressbook_pb2
+import sys
+
+# This function fills in a Person message based on user input.
+def PromptForAddress(person):
+ person.id = int(raw_input("Enter person ID number: "))
+ person.name = raw_input("Enter name: ")
+
+ email = raw_input("Enter email address (blank for none): ")
+ if email != "":
+ person.email = email
+
+ while True:
+ number = raw_input("Enter a phone number (or leave blank to finish): ")
+ if number == "":
+ break
+
+ phone_number = person.phones.add()
+ phone_number.number = number
+
+ type = raw_input("Is this a mobile, home, or work phone? ")
+ if type == "mobile":
+ phone_number.type = addressbook_pb2.Person.MOBILE
+ elif type == "home":
+ phone_number.type = addressbook_pb2.Person.HOME
+ elif type == "work":
+ phone_number.type = addressbook_pb2.Person.WORK
+ else:
+ print "Unknown phone type; leaving as default value."
+
+# Main procedure: Reads the entire address book from a file,
+# adds one person based on user input, then writes it back out to the same
+# file.
+if len(sys.argv) != 2:
+ print "Usage:", sys.argv[0], "ADDRESS_BOOK_FILE"
+ sys.exit(-1)
+
+address_book = addressbook_pb2.AddressBook()
+
+# Read the existing address book.
+try:
+ with open(sys.argv[1], "rb") as f:
+ address_book.ParseFromString(f.read())
+except IOError:
+ print sys.argv[1] + ": File not found. Creating a new file."
+
+# Add an address.
+PromptForAddress(address_book.people.add())
+
+# Write the new address book back to disk.
+with open(sys.argv[1], "wb") as f:
+ f.write(address_book.SerializeToString())
diff --git a/third_party/protobuf/examples/add_person_test.go b/third_party/protobuf/examples/add_person_test.go
new file mode 100644
index 0000000000..0507db6fc1
--- /dev/null
+++ b/third_party/protobuf/examples/add_person_test.go
@@ -0,0 +1,58 @@
+package main
+
+import (
+ "strings"
+ "testing"
+
+ "github.com/golang/protobuf/proto"
+ pb "github.com/google/protobuf/examples/tutorial"
+)
+
+func TestPromptForAddressReturnsAddress(t *testing.T) {
+ in := `12345
+Example Name
+name@example.com
+123-456-7890
+home
+222-222-2222
+mobile
+111-111-1111
+work
+777-777-7777
+unknown
+
+`
+ got, err := promptForAddress(strings.NewReader(in))
+ if err != nil {
+ t.Fatalf("promptForAddress(%q) had unexpected error: %s", in, err.Error())
+ }
+ if got.Id != 12345 {
+ t.Errorf("promptForAddress(%q) got %d, want ID %d", in, got.Id, 12345)
+ }
+ if got.Name != "Example Name" {
+ t.Errorf("promptForAddress(%q) => want name %q, got %q", "Example Name", got.Name)
+ }
+ if got.Email != "name@example.com" {
+ t.Errorf("promptForAddress(%q) => want email %q, got %q", "name@example.com", got.Email)
+ }
+
+ want := []*pb.Person_PhoneNumber{
+ {Number: "123-456-7890", Type: pb.Person_HOME},
+ {Number: "222-222-2222", Type: pb.Person_MOBILE},
+ {Number: "111-111-1111", Type: pb.Person_WORK},
+ {Number: "777-777-7777", Type: pb.Person_MOBILE},
+ }
+ if len(got.Phones) != len(want) {
+ t.Errorf("want %d phone numbers, got %d", len(want), len(got.Phones))
+ }
+ phones := len(got.Phones)
+ if phones > len(want) {
+ phones = len(want)
+ }
+ for i := 0; i < phones; i++ {
+ if !proto.Equal(got.Phones[i], want[i]) {
+ t.Errorf("want phone %q, got %q", *want[i], *got.Phones[i])
+ }
+
+ }
+}
diff --git a/third_party/protobuf/examples/addressbook.proto b/third_party/protobuf/examples/addressbook.proto
new file mode 100644
index 0000000000..23cc2f97e7
--- /dev/null
+++ b/third_party/protobuf/examples/addressbook.proto
@@ -0,0 +1,47 @@
+// See README.txt for information and build instructions.
+//
+// Note: START and END tags are used in comments to define sections used in
+// tutorials. They are not part of the syntax for Protocol Buffers.
+//
+// To get an in-depth walkthrough of this file and the related examples, see:
+// https://developers.google.com/protocol-buffers/docs/tutorials
+
+// [START declaration]
+syntax = "proto3";
+package tutorial;
+// [END declaration]
+
+// [START java_declaration]
+option java_package = "com.example.tutorial";
+option java_outer_classname = "AddressBookProtos";
+// [END java_declaration]
+
+// [START csharp_declaration]
+option csharp_namespace = "Google.Protobuf.Examples.AddressBook";
+// [END csharp_declaration]
+
+// [START messages]
+message Person {
+ string name = 1;
+ int32 id = 2; // Unique ID number for this person.
+ string email = 3;
+
+ enum PhoneType {
+ MOBILE = 0;
+ HOME = 1;
+ WORK = 2;
+ }
+
+ message PhoneNumber {
+ string number = 1;
+ PhoneType type = 2;
+ }
+
+ repeated PhoneNumber phones = 4;
+}
+
+// Our address book file is just one of these.
+message AddressBook {
+ repeated Person people = 1;
+}
+// [END messages]
diff --git a/third_party/protobuf/examples/list_people.cc b/third_party/protobuf/examples/list_people.cc
new file mode 100644
index 0000000000..68e5666d84
--- /dev/null
+++ b/third_party/protobuf/examples/list_people.cc
@@ -0,0 +1,68 @@
+// See README.txt for information and build instructions.
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include "addressbook.pb.h"
+using namespace std;
+
+// Iterates though all people in the AddressBook and prints info about them.
+void ListPeople(const tutorial::AddressBook& address_book) {
+ for (int i = 0; i < address_book.people_size(); i++) {
+ const tutorial::Person& person = address_book.people(i);
+
+ cout << "Person ID: " << person.id() << endl;
+ cout << " Name: " << person.name() << endl;
+ if (person.email() != "") {
+ cout << " E-mail address: " << person.email() << endl;
+ }
+
+ for (int j = 0; j < person.phones_size(); j++) {
+ const tutorial::Person::PhoneNumber& phone_number = person.phones(j);
+
+ switch (phone_number.type()) {
+ case tutorial::Person::MOBILE:
+ cout << " Mobile phone #: ";
+ break;
+ case tutorial::Person::HOME:
+ cout << " Home phone #: ";
+ break;
+ case tutorial::Person::WORK:
+ cout << " Work phone #: ";
+ break;
+ }
+ cout << phone_number.number() << endl;
+ }
+ }
+}
+
+// Main function: Reads the entire address book from a file and prints all
+// the information inside.
+int main(int argc, char* argv[]) {
+ // Verify that the version of the library that we linked against is
+ // compatible with the version of the headers we compiled against.
+ GOOGLE_PROTOBUF_VERIFY_VERSION;
+
+ if (argc != 2) {
+ cerr << "Usage: " << argv[0] << " ADDRESS_BOOK_FILE" << endl;
+ return -1;
+ }
+
+ tutorial::AddressBook address_book;
+
+ {
+ // Read the existing address book.
+ fstream input(argv[1], ios::in | ios::binary);
+ if (!address_book.ParseFromIstream(&input)) {
+ cerr << "Failed to parse address book." << endl;
+ return -1;
+ }
+ }
+
+ ListPeople(address_book);
+
+ // Optional: Delete all global objects allocated by libprotobuf.
+ google::protobuf::ShutdownProtobufLibrary();
+
+ return 0;
+}
diff --git a/third_party/protobuf/examples/list_people.go b/third_party/protobuf/examples/list_people.go
new file mode 100644
index 0000000000..70bc589efc
--- /dev/null
+++ b/third_party/protobuf/examples/list_people.go
@@ -0,0 +1,61 @@
+package main
+
+import (
+ "fmt"
+ "io"
+ "io/ioutil"
+ "log"
+ "os"
+
+ "github.com/golang/protobuf/proto"
+ pb "github.com/google/protobuf/examples/tutorial"
+)
+
+func writePerson(w io.Writer, p *pb.Person) {
+ fmt.Fprintln(w, "Person ID:", p.Id)
+ fmt.Fprintln(w, " Name:", p.Name)
+ if p.Email != "" {
+ fmt.Fprintln(w, " E-mail address:", p.Email)
+ }
+
+ for _, pn := range p.Phones {
+ switch pn.Type {
+ case pb.Person_MOBILE:
+ fmt.Fprint(w, " Mobile phone #: ")
+ case pb.Person_HOME:
+ fmt.Fprint(w, " Home phone #: ")
+ case pb.Person_WORK:
+ fmt.Fprint(w, " Work phone #: ")
+ }
+ fmt.Fprintln(w, pn.Number)
+ }
+}
+
+func listPeople(w io.Writer, book *pb.AddressBook) {
+ for _, p := range book.People {
+ writePerson(w, p)
+ }
+}
+
+// Main reads the entire address book from a file and prints all the
+// information inside.
+func main() {
+ if len(os.Args) != 2 {
+ log.Fatalf("Usage: %s ADDRESS_BOOK_FILE\n", os.Args[0])
+ }
+ fname := os.Args[1]
+
+ // [START unmarshal_proto]
+ // Read the existing address book.
+ in, err := ioutil.ReadFile(fname)
+ if err != nil {
+ log.Fatalln("Error reading file:", err)
+ }
+ book := &pb.AddressBook{}
+ if err := proto.Unmarshal(in, book); err != nil {
+ log.Fatalln("Failed to parse address book:", err)
+ }
+ // [END unmarshal_proto]
+
+ listPeople(os.Stdout, book)
+}
diff --git a/third_party/protobuf/examples/list_people.py b/third_party/protobuf/examples/list_people.py
new file mode 100755
index 0000000000..f131872d84
--- /dev/null
+++ b/third_party/protobuf/examples/list_people.py
@@ -0,0 +1,37 @@
+#! /usr/bin/env python
+
+# See README.txt for information and build instructions.
+
+import addressbook_pb2
+import sys
+
+# Iterates though all people in the AddressBook and prints info about them.
+def ListPeople(address_book):
+ for person in address_book.people:
+ print "Person ID:", person.id
+ print " Name:", person.name
+ if person.email != "":
+ print " E-mail address:", person.email
+
+ for phone_number in person.phones:
+ if phone_number.type == addressbook_pb2.Person.MOBILE:
+ print " Mobile phone #:",
+ elif phone_number.type == addressbook_pb2.Person.HOME:
+ print " Home phone #:",
+ elif phone_number.type == addressbook_pb2.Person.WORK:
+ print " Work phone #:",
+ print phone_number.number
+
+# Main procedure: Reads the entire address book from a file and prints all
+# the information inside.
+if len(sys.argv) != 2:
+ print "Usage:", sys.argv[0], "ADDRESS_BOOK_FILE"
+ sys.exit(-1)
+
+address_book = addressbook_pb2.AddressBook()
+
+# Read the existing address book.
+with open(sys.argv[1], "rb") as f:
+ address_book.ParseFromString(f.read())
+
+ListPeople(address_book)
diff --git a/third_party/protobuf/examples/list_people_test.go b/third_party/protobuf/examples/list_people_test.go
new file mode 100644
index 0000000000..87d6ad6ec6
--- /dev/null
+++ b/third_party/protobuf/examples/list_people_test.go
@@ -0,0 +1,120 @@
+package main
+
+import (
+ "bytes"
+ "strings"
+ "testing"
+
+ pb "github.com/google/protobuf/examples/tutorial"
+)
+
+func TestWritePersonWritesPerson(t *testing.T) {
+ buf := new(bytes.Buffer)
+ // [START populate_proto]
+ p := pb.Person{
+ Id: 1234,
+ Name: "John Doe",
+ Email: "jdoe@example.com",
+ Phones: []*pb.Person_PhoneNumber{
+ {Number: "555-4321", Type: pb.Person_HOME},
+ },
+ }
+ // [END populate_proto]
+ writePerson(buf, &p)
+ got := buf.String()
+ want := `Person ID: 1234
+ Name: John Doe
+ E-mail address: jdoe@example.com
+ Home phone #: 555-4321
+`
+ if got != want {
+ t.Errorf("writePerson(%s) =>\n\t%q, want %q", p.String(), got, want)
+ }
+}
+
+func TestListPeopleWritesList(t *testing.T) {
+ buf := new(bytes.Buffer)
+ in := pb.AddressBook{[]*pb.Person{
+ {
+ Name: "John Doe",
+ Id: 101,
+ Email: "john@example.com",
+ },
+ {
+ Name: "Jane Doe",
+ Id: 102,
+ },
+ {
+ Name: "Jack Doe",
+ Id: 201,
+ Email: "jack@example.com",
+ Phones: []*pb.Person_PhoneNumber{
+ {Number: "555-555-5555", Type: pb.Person_WORK},
+ },
+ },
+ {
+ Name: "Jack Buck",
+ Id: 301,
+ Email: "buck@example.com",
+ Phones: []*pb.Person_PhoneNumber{
+ {Number: "555-555-0000", Type: pb.Person_HOME},
+ {Number: "555-555-0001", Type: pb.Person_MOBILE},
+ {Number: "555-555-0002", Type: pb.Person_WORK},
+ },
+ },
+ {
+ Name: "Janet Doe",
+ Id: 1001,
+ Email: "janet@example.com",
+ Phones: []*pb.Person_PhoneNumber{
+ {Number: "555-777-0000"},
+ {Number: "555-777-0001", Type: pb.Person_HOME},
+ },
+ },
+ }}
+ listPeople(buf, &in)
+ want := strings.Split(`Person ID: 101
+ Name: John Doe
+ E-mail address: john@example.com
+Person ID: 102
+ Name: Jane Doe
+Person ID: 201
+ Name: Jack Doe
+ E-mail address: jack@example.com
+ Work phone #: 555-555-5555
+Person ID: 301
+ Name: Jack Buck
+ E-mail address: buck@example.com
+ Home phone #: 555-555-0000
+ Mobile phone #: 555-555-0001
+ Work phone #: 555-555-0002
+Person ID: 1001
+ Name: Janet Doe
+ E-mail address: janet@example.com
+ Mobile phone #: 555-777-0000
+ Home phone #: 555-777-0001
+`, "\n")
+ got := strings.Split(buf.String(), "\n")
+ if len(got) != len(want) {
+ t.Errorf(
+ "listPeople(%s) =>\n\t%q has %d lines, want %d",
+ in.String(),
+ buf.String(),
+ len(got),
+ len(want))
+ }
+ lines := len(got)
+ if lines > len(want) {
+ lines = len(want)
+ }
+ for i := 0; i < lines; i++ {
+ if got[i] != want[i] {
+ t.Errorf(
+ "listPeople(%s) =>\n\tline %d %q, want %q",
+ in.String(),
+ i,
+ got[i],
+ want[i])
+ }
+ }
+}
diff --git a/third_party/protobuf/generate_changelog.py b/third_party/protobuf/generate_changelog.py
new file mode 100755
index 0000000000..d90a9b7043
--- /dev/null
+++ b/third_party/protobuf/generate_changelog.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+
+"""Generates a friendly list of changes per language since the last release."""
+
+import sys
+import os
+
+class Language(object):
+ def __init__(self, name, pathspec):
+ self.name = name
+ self.pathspec = pathspec
+
+languages = [
+ Language("C++", [
+ "':(glob)src/google/protobuf/*'",
+ "src/google/protobuf/compiler/cpp",
+ "src/google/protobuf/io",
+ "src/google/protobuf/util",
+ "src/google/protobuf/stubs",
+ ]),
+ Language("Java", [
+ "java",
+ "javanano",
+ "src/google/protobuf/compiler/cpp",
+ ]),
+ Language("Python", [
+ "javanano",
+ "src/google/protobuf/compiler/python",
+ ]),
+ Language("JavaScript", [
+ "js",
+ "src/google/protobuf/compiler/js",
+ ]),
+ Language("PHP", [
+ "php",
+ "src/google/protobuf/compiler/php",
+ ]),
+ Language("Ruby", [
+ "ruby",
+ "src/google/protobuf/compiler/ruby",
+ ]),
+ Language("Csharp", [
+ "csharp",
+ "src/google/protobuf/compiler/csharp",
+ ]),
+ Language("Objective C", [
+ "objectivec",
+ "src/google/protobuf/compiler/objectivec",
+ ]),
+]
+
+if len(sys.argv) < 2:
+ print("Usage: generate_changelog.py <previous release>")
+ sys.exit(1)
+
+previous = sys.argv[1]
+
+for language in languages:
+ print(language.name)
+ sys.stdout.flush()
+ os.system(("git log --pretty=oneline --abbrev-commit %s...HEAD %s | " +
+ "sed -e 's/^/ - /'") % (previous, " ".join(language.pathspec)))
+ print("")
+
+print("To view a commit on GitHub: " +
+ "https://github.com/google/protobuf/commit/<commit id>")
diff --git a/third_party/protobuf/generate_descriptor_proto.sh b/third_party/protobuf/generate_descriptor_proto.sh
new file mode 100755
index 0000000000..809214cea5
--- /dev/null
+++ b/third_party/protobuf/generate_descriptor_proto.sh
@@ -0,0 +1,111 @@
+#!/usr/bin/env bash
+
+# Run this script to regenerate descriptor.pb.{h,cc} after the protocol
+# compiler changes. Since these files are compiled into the protocol compiler
+# itself, they cannot be generated automatically by a make rule. "make check"
+# will fail if these files do not match what the protocol compiler would
+# generate.
+#
+# HINT: Flags passed to generate_descriptor_proto.sh will be passed directly
+# to make when building protoc. This is particularly useful for passing
+# -j4 to run 4 jobs simultaneously.
+
+if test ! -e src/google/protobuf/stubs/common.h; then
+ cat >&2 << __EOF__
+Could not find source code. Make sure you are running this script from the
+root of the distribution tree.
+__EOF__
+ exit 1
+fi
+
+if test ! -e src/Makefile; then
+ cat >&2 << __EOF__
+Could not find src/Makefile. You must run ./configure (and perhaps
+./autogen.sh) first.
+__EOF__
+ exit 1
+fi
+
+cd src
+
+declare -a RUNTIME_PROTO_FILES=(\
+ google/protobuf/any.proto \
+ google/protobuf/api.proto \
+ google/protobuf/descriptor.proto \
+ google/protobuf/duration.proto \
+ google/protobuf/empty.proto \
+ google/protobuf/field_mask.proto \
+ google/protobuf/source_context.proto \
+ google/protobuf/struct.proto \
+ google/protobuf/timestamp.proto \
+ google/protobuf/type.proto \
+ google/protobuf/wrappers.proto)
+
+CORE_PROTO_IS_CORRECT=0
+PROCESS_ROUND=1
+TMP=$(mktemp -d)
+echo "Updating descriptor protos..."
+while [ $CORE_PROTO_IS_CORRECT -ne 1 ]
+do
+ echo "Round $PROCESS_ROUND"
+ CORE_PROTO_IS_CORRECT=1
+
+ make $@ protoc
+ if test $? -ne 0; then
+ echo "Failed to build protoc."
+ exit 1
+ fi
+
+ ./protoc --cpp_out=dllexport_decl=LIBPROTOBUF_EXPORT:$TMP ${RUNTIME_PROTO_FILES[@]} && \
+ ./protoc --cpp_out=dllexport_decl=LIBPROTOC_EXPORT:$TMP google/protobuf/compiler/plugin.proto
+
+ for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]}; do
+ BASE_NAME=${PROTO_FILE%.*}
+ diff ${BASE_NAME}.pb.h $TMP/${BASE_NAME}.pb.h > /dev/null
+ if test $? -ne 0; then
+ CORE_PROTO_IS_CORRECT=0
+ fi
+ diff ${BASE_NAME}.pb.cc $TMP/${BASE_NAME}.pb.cc > /dev/null
+ if test $? -ne 0; then
+ CORE_PROTO_IS_CORRECT=0
+ fi
+ done
+
+ diff google/protobuf/compiler/plugin.pb.h $TMP/google/protobuf/compiler/plugin.pb.h > /dev/null
+ if test $? -ne 0; then
+ CORE_PROTO_IS_CORRECT=0
+ fi
+ diff google/protobuf/compiler/plugin.pb.cc $TMP/google/protobuf/compiler/plugin.pb.cc > /dev/null
+ if test $? -ne 0; then
+ CORE_PROTO_IS_CORRECT=0
+ fi
+
+ # Only override the output if the files are different to avoid re-compilation
+ # of the protoc.
+ if [ $CORE_PROTO_IS_CORRECT -ne 1 ]; then
+ for PROTO_FILE in ${RUNTIME_PROTO_FILES[@]}; do
+ BASE_NAME=${PROTO_FILE%.*}
+ mv $TMP/${BASE_NAME}.pb.h ${BASE_NAME}.pb.h
+ mv $TMP/${BASE_NAME}.pb.cc ${BASE_NAME}.pb.cc
+ done
+ mv $TMP/google/protobuf/compiler/plugin.pb.* google/protobuf/compiler/
+ fi
+
+ PROCESS_ROUND=$((PROCESS_ROUND + 1))
+done
+cd ..
+
+if test -x objectivec/generate_well_known_types.sh; then
+ echo "Generating messages for objc."
+ objectivec/generate_well_known_types.sh $@
+fi
+
+if test -x csharp/generate_protos.sh; then
+ echo "Generating messages for C#."
+ csharp/generate_protos.sh $@
+fi
+
+if test -x php/generate_descriptor_protos.sh; then
+ echo "Generating messages for PHP."
+ php/generate_descriptor_protos.sh $@
+fi
diff --git a/third_party/protobuf/gmock.BUILD b/third_party/protobuf/gmock.BUILD
new file mode 100644
index 0000000000..b1ae15a919
--- /dev/null
+++ b/third_party/protobuf/gmock.BUILD
@@ -0,0 +1,28 @@
+cc_library(
+ name = "gtest",
+ srcs = [
+ "googletest/src/gtest-all.cc",
+ "googlemock/src/gmock-all.cc",
+ ],
+ hdrs = glob([
+ "**/*.h",
+ "googletest/src/*.cc",
+ "googlemock/src/*.cc",
+ ]),
+ includes = [
+ "googlemock",
+ "googletest",
+ "googletest/include",
+ "googlemock/include",
+ ],
+ linkopts = ["-pthread"],
+ visibility = ["//visibility:public"],
+)
+
+cc_library(
+ name = "gtest_main",
+ srcs = ["googlemock/src/gmock_main.cc"],
+ linkopts = ["-pthread"],
+ visibility = ["//visibility:public"],
+ deps = [":gtest"],
+)
diff --git a/third_party/protobuf/java/README.md b/third_party/protobuf/java/README.md
new file mode 100644
index 0000000000..0e0fba647a
--- /dev/null
+++ b/third_party/protobuf/java/README.md
@@ -0,0 +1,127 @@
+Protocol Buffers - Google's data interchange format
+===================================================
+
+[![Build Status](https://travis-ci.org/google/protobuf.svg?branch=master)](https://travis-ci.org/google/protobuf)
+
+Copyright 2008 Google Inc.
+
+This directory contains the Java Protocol Buffers runtime library.
+
+Installation - With Maven
+=========================
+
+The Protocol Buffers build is managed using Maven. If you would
+rather build without Maven, see below.
+
+1) Install Apache Maven if you don't have it:
+
+ http://maven.apache.org/
+
+2) Build the C++ code, or obtain a binary distribution of protoc (see
+ the toplevel [README.md](../README.md)). If you install a binary
+ distribution, make sure that it is the same version as this package.
+ If in doubt, run:
+
+ $ protoc --version
+
+ You will need to place the protoc executable in ../src. (If you
+ built it yourself, it should already be there.)
+
+3) Run the tests:
+
+ $ mvn test
+
+ If some tests fail, this library may not work correctly on your
+ system. Continue at your own risk.
+
+4) Install the library into your Maven repository:
+
+ $ mvn install
+
+5) If you do not use Maven to manage your own build, you can build a
+ .jar file to use:
+
+ $ mvn package
+
+ The .jar will be placed in the "target" directory.
+
+The above instructions will install 3 maven artifacts:
+
+ * protobuf-java: The core Java Protocol Buffers library. Most users only
+ need this artifact.
+ * protobuf-lite: The lite version of core Java Protobuf Buffers library. It
+ is a subset of the core library and is used together with
+ the 'lite' code generator flag to reduce generated code size
+ for mobile.
+ * protobuf-java-util: Utilities to work with protos. It contains JSON support
+ as well as utilities to work with proto3 well-known
+ types.
+
+Installation - Without Maven
+============================
+
+If you would rather not install Maven to build the library, you may
+follow these instructions instead. Note that these instructions skip
+running unit tests and only describes how to install the core protobuf
+library (without the util package).
+
+1) Build the C++ code, or obtain a binary distribution of protoc. If
+ you install a binary distribution, make sure that it is the same
+ version as this package. If in doubt, run:
+
+ $ protoc --version
+
+ If you built the C++ code without installing, the compiler binary
+ should be located in ../src.
+
+2) Invoke protoc to build DescriptorProtos.java:
+
+ $ protoc --java_out=core/src/main/java -I../src \
+ ../src/google/protobuf/descriptor.proto
+
+3) Compile the code in core/src/main/java using whatever means you prefer.
+
+4) Install the classes wherever you prefer.
+
+Compatibility Notice
+====================
+
+* Protobuf minor version releases are backwards-compatible. If your code
+ can build/run against the old version, it's expected to build/run against
+ the new version as well. Both binary compatibility and source compatibility
+ are guaranteed for minor version releases if the user follows the guideline
+ described in this section.
+
+* Protobuf major version releases may also be backwards-compatbile with the
+ last release of the previous major version. See the release notice for more
+ details.
+
+* APIs marked with the @ExperimentalApi annotation are subject to change. They
+ can be modified in any way, or even removed, at any time. Don't use them if
+ compatibility is needed. If your code is a library itself (i.e. it is used on
+ the CLASSPATH of users outside your own control), you should not use
+ experimental APIs, unless you repackage them (e.g. using ProGuard).
+
+* Deprecated non-experimental APIs will be removed two years after the release
+ in which they are first deprecated. You must fix your references before this
+ time. If you don't, any manner of breakage could result (you are not
+ guaranteed a compilation error).
+
+* Protobuf message interfaces/classes are designed to be subclassed by protobuf
+ generated code only. Do not subclass these message interfaces/classes
+ yourself. We may add new methods to the message interfaces/classes which will
+ break your own subclasses.
+
+* Don't use any method/class that is marked as "used by generated code only".
+ Such methods/classes are subject to change.
+
+* Protobuf LITE runtime APIs are not stable yet. They are subject to change even
+ in minor version releases.
+
+Documentation
+=============
+
+The complete documentation for Protocol Buffers is available via the
+web at:
+
+ https://developers.google.com/protocol-buffers/
diff --git a/third_party/protobuf/java/compatibility_tests/README.md b/third_party/protobuf/java/compatibility_tests/README.md
new file mode 100644
index 0000000000..72c6034c99
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/README.md
@@ -0,0 +1,50 @@
+# Protobuf Java Compatibility Tests
+
+This directory contains tests to ensure protobuf library is compatible with
+previously released versions.
+
+## Directory Layout
+
+For each released protobuf version we are testing compatibility with, there
+is a sub-directory with the following layout (take v2.5.0 as an example):
+
+ * v2.5.0
+ * test.sh
+ * pom.xml
+ * protos/ - unittest protos.
+ * more_protos/ - unittest protos that import the ones in "protos".
+ * tests/ - actual Java test classes.
+
+The testing code is extracted from regular protobuf unittests by removing:
+
+ * tests that access package private methods/classes.
+ * tests that are known to be broken by an intended behavior change (e.g., we
+ changed the parsing recursion limit from 64 to 100).
+ * all lite runtime tests.
+
+It's also divided into 3 submodule with tests depending on more_protos and
+more_protos depending on protos. This way we can test scenarios where only part
+of the dependency is upgraded to the new version.
+
+## How to Run The Tests
+
+We use a shell script to drive the test of different scenarios so the test
+will only run on unix-like environments. The script expects a few command
+line tools to be available on PATH: git, mvn, wget, grep, sed, java.
+
+Before running the tests, make sure you have already built the protoc binary
+following [the C++ installation instructions](../../src/README.md). The test
+scripts will use the built binary located at ${protobuf}/src/protoc.
+
+To start a test, simply run the test.sh script in each version directory. For
+example:
+
+ $ v2.5.0/test.sh
+
+For each version, the test script will test:
+
+ * only upgrading protos to the new version
+ * only upgrading more_protos to the new version
+
+and see whether everything builds/runs fine. Both source compatibility and
+binary compatibility will be tested.
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/deps/pom.xml b/third_party/protobuf/java/compatibility_tests/v2.5.0/deps/pom.xml
new file mode 100644
index 0000000000..7ceb96049d
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/deps/pom.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.google.protobuf.compatibility</groupId>
+ <artifactId>compatibility-test-deps</artifactId>
+ <version>2.5.0</version>
+
+ <name>Compatibility Test Dependencies</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.6</version>
+ <configuration>
+ <descriptorRefs>
+ <descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/pom.xml b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/pom.xml
new file mode 100644
index 0000000000..ff0c4133f0
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>com.google.protobuf.compatibility</groupId>
+ <artifactId>compatibility-test-suite</artifactId>
+ <version>2.5.0</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <groupId>com.google.protobuf.compatibility</groupId>
+ <artifactId>compatibility-more-protos</artifactId>
+ <version>2.5.0</version>
+
+ <name>More protos for Compatibility test</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.google.protobuf</groupId>
+ <artifactId>protobuf-java</artifactId>
+ <version>${more_protos.protobuf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.protobuf.compatibility</groupId>
+ <artifactId>compatibility-protos</artifactId>
+ <version>2.5.0</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.3</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-sources</id>
+ <phase>generate-sources</phase>
+ <configuration>
+ <tasks>
+ <mkdir dir="target/generated-sources" />
+ <exec executable="${more_protos.protoc.path}">
+ <arg value="--java_out=target/generated-sources" />
+ <arg value="--proto_path=src/proto" />
+ <arg value="src/proto/google/protobuf/unittest.proto" />
+ <arg value="src/proto/google/protobuf/unittest_optimize_for.proto" />
+ <arg value="src/proto/com/google/protobuf/multiple_files_test.proto" />
+ </exec>
+ </tasks>
+ <sourceRoot>target/generated-sources</sourceRoot>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/multiple_files_test.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/multiple_files_test.proto
new file mode 100644
index 0000000000..9a040145a6
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/multiple_files_test.proto
@@ -0,0 +1,71 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+//
+// A proto file which tests the java_multiple_files option.
+
+
+// Some generic_services option(s) added automatically.
+// See: http://go/proto2-generic-services-default
+option java_generic_services = true; // auto-added
+
+import "google/protobuf/unittest.proto";
+
+package protobuf_unittest;
+
+option java_multiple_files = true;
+option java_outer_classname = "MultipleFilesTestProto";
+
+message MessageWithNoOuter {
+ message NestedMessage {
+ optional int32 i = 1;
+ }
+ enum NestedEnum {
+ BAZ = 3;
+ }
+ optional NestedMessage nested = 1;
+ repeated TestAllTypes foreign = 2;
+ optional NestedEnum nested_enum = 3;
+ optional EnumWithNoOuter foreign_enum = 4;
+}
+
+enum EnumWithNoOuter {
+ FOO = 1;
+ BAR = 2;
+}
+
+service ServiceWithNoOuter {
+ rpc Foo(MessageWithNoOuter) returns(TestAllTypes);
+}
+
+extend TestAllExtensions {
+ optional int32 extension_with_outer = 1234567;
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/nested_builders_test.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/nested_builders_test.proto
new file mode 100644
index 0000000000..abffb9d2ba
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/nested_builders_test.proto
@@ -0,0 +1,53 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: jonp@google.com (Jon Perlow)
+//
+
+package protobuf_unittest;
+
+option java_multiple_files = true;
+option java_outer_classname = "NestedBuilders";
+
+
+message Vehicle {
+ optional Engine engine = 1;
+ repeated Wheel wheel = 2;
+}
+
+message Engine {
+ optional int32 cylinder = 1;
+ optional int32 liters = 2;
+}
+
+message Wheel {
+ optional int32 radius = 1;
+ optional int32 width = 2;
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/nested_extension.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/nested_extension.proto
new file mode 100644
index 0000000000..9fe5d560c9
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/nested_extension.proto
@@ -0,0 +1,45 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: Darick Tong (darick@google.com)
+//
+// A proto file with nested extensions. Note that this must be defined in
+// a separate file to properly test the initialization of the outer class.
+
+
+import "com/google/protobuf/non_nested_extension.proto";
+
+package protobuf_unittest;
+
+message MyNestedExtension {
+ extend MessageToBeExtended {
+ optional MessageToBeExtended recursiveExtension = 2;
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/nested_extension_lite.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/nested_extension_lite.proto
new file mode 100644
index 0000000000..16ee46e57d
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/nested_extension_lite.proto
@@ -0,0 +1,48 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: Darick Tong (darick@google.com)
+//
+// A proto file with nested extensions for a MessageLite messages. Note that
+// this must be defined in a separate file to properly test the initialization
+// of the outer class.
+
+
+package protobuf_unittest;
+
+option optimize_for = LITE_RUNTIME;
+
+import "com/google/protobuf/non_nested_extension_lite.proto";
+
+message MyNestedExtensionLite {
+ extend MessageLiteToBeExtended {
+ optional MessageLiteToBeExtended recursiveExtensionLite = 3;
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/non_nested_extension.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/non_nested_extension.proto
new file mode 100644
index 0000000000..f61b419bc2
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/non_nested_extension.proto
@@ -0,0 +1,48 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: Darick Tong (darick@google.com)
+//
+// A proto file with extensions.
+
+
+package protobuf_unittest;
+
+message MessageToBeExtended {
+ extensions 1 to max;
+}
+
+message MyNonNestedExtension {
+}
+
+extend MessageToBeExtended {
+ optional MyNonNestedExtension nonNestedExtension = 1;
+}
+
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/non_nested_extension_lite.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/non_nested_extension_lite.proto
new file mode 100644
index 0000000000..3c82659b5e
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/non_nested_extension_lite.proto
@@ -0,0 +1,50 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: Darick Tong (darick@google.com)
+//
+// A proto file with extensions for a MessageLite messages.
+
+
+package protobuf_unittest;
+
+option optimize_for = LITE_RUNTIME;
+
+message MessageLiteToBeExtended {
+ extensions 1 to max;
+}
+
+message MyNonNestedExtensionLite {
+}
+
+extend MessageLiteToBeExtended {
+ optional MyNonNestedExtensionLite nonNestedExtensionLite = 1;
+}
+
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/test_bad_identifiers.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/test_bad_identifiers.proto
new file mode 100644
index 0000000000..6e67d97a69
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/com/google/protobuf/test_bad_identifiers.proto
@@ -0,0 +1,108 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: jonp@google.com (Jon Perlow)
+
+// This file tests that various identifiers work as field and type names even
+// though the same identifiers are used internally by the java code generator.
+
+
+// Some generic_services option(s) added automatically.
+// See: http://go/proto2-generic-services-default
+option java_generic_services = true; // auto-added
+
+package io_protocol_tests;
+
+option java_package = "com.google.protobuf";
+option java_outer_classname = "TestBadIdentifiersProto";
+
+message TestMessage {
+}
+
+message Descriptor {
+ option no_standard_descriptor_accessor = true;
+ optional string descriptor = 1;
+ message NestedDescriptor {
+ option no_standard_descriptor_accessor = true;
+ optional string descriptor = 1;
+ }
+ optional NestedDescriptor nested_descriptor = 2;
+}
+
+message Parser {
+ enum ParserEnum {
+ PARSER = 1;
+ }
+ optional ParserEnum parser = 1;
+}
+
+message Deprecated {
+ enum TestEnum {
+ FOO = 1;
+ }
+
+ optional int32 field1 = 1 [deprecated=true];
+ optional TestEnum field2 = 2 [deprecated=true];
+ optional TestMessage field3 = 3 [deprecated=true];
+}
+
+message Override {
+ optional int32 override = 1;
+}
+
+message Object {
+ optional int32 object = 1;
+ optional string string_object = 2;
+}
+
+message String {
+ optional string string = 1;
+}
+
+message Integer {
+ optional int32 integer = 1;
+}
+
+message Long {
+ optional int32 long = 1;
+}
+
+message Float {
+ optional float float = 1;
+}
+
+message Double {
+ optional double double = 1;
+}
+
+service TestConflictingMethodNames {
+ rpc Override(TestMessage) returns (TestMessage);
+}
+
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/descriptor.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/descriptor.proto
new file mode 100644
index 0000000000..a785f79faf
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/descriptor.proto
@@ -0,0 +1,620 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// The messages in this file describe the definitions found in .proto files.
+// A valid .proto file can be translated directly to a FileDescriptorProto
+// without any other information (e.g. without reading its imports).
+
+
+
+package google.protobuf;
+option java_package = "com.google.protobuf";
+option java_outer_classname = "DescriptorProtos";
+
+// descriptor.proto must be optimized for speed because reflection-based
+// algorithms don't work during bootstrapping.
+option optimize_for = SPEED;
+
+// The protocol compiler can output a FileDescriptorSet containing the .proto
+// files it parses.
+message FileDescriptorSet {
+ repeated FileDescriptorProto file = 1;
+}
+
+// Describes a complete .proto file.
+message FileDescriptorProto {
+ optional string name = 1; // file name, relative to root of source tree
+ optional string package = 2; // e.g. "foo", "foo.bar", etc.
+
+ // Names of files imported by this file.
+ repeated string dependency = 3;
+ // Indexes of the public imported files in the dependency list above.
+ repeated int32 public_dependency = 10;
+ // Indexes of the weak imported files in the dependency list.
+ // For Google-internal migration only. Do not use.
+ repeated int32 weak_dependency = 11;
+
+ // All top-level definitions in this file.
+ repeated DescriptorProto message_type = 4;
+ repeated EnumDescriptorProto enum_type = 5;
+ repeated ServiceDescriptorProto service = 6;
+ repeated FieldDescriptorProto extension = 7;
+
+ optional FileOptions options = 8;
+
+ // This field contains optional information about the original source code.
+ // You may safely remove this entire field whithout harming runtime
+ // functionality of the descriptors -- the information is needed only by
+ // development tools.
+ optional SourceCodeInfo source_code_info = 9;
+}
+
+// Describes a message type.
+message DescriptorProto {
+ optional string name = 1;
+
+ repeated FieldDescriptorProto field = 2;
+ repeated FieldDescriptorProto extension = 6;
+
+ repeated DescriptorProto nested_type = 3;
+ repeated EnumDescriptorProto enum_type = 4;
+
+ message ExtensionRange {
+ optional int32 start = 1;
+ optional int32 end = 2;
+ }
+ repeated ExtensionRange extension_range = 5;
+
+ optional MessageOptions options = 7;
+}
+
+// Describes a field within a message.
+message FieldDescriptorProto {
+ enum Type {
+ // 0 is reserved for errors.
+ // Order is weird for historical reasons.
+ TYPE_DOUBLE = 1;
+ TYPE_FLOAT = 2;
+ // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
+ // negative values are likely.
+ TYPE_INT64 = 3;
+ TYPE_UINT64 = 4;
+ // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
+ // negative values are likely.
+ TYPE_INT32 = 5;
+ TYPE_FIXED64 = 6;
+ TYPE_FIXED32 = 7;
+ TYPE_BOOL = 8;
+ TYPE_STRING = 9;
+ TYPE_GROUP = 10; // Tag-delimited aggregate.
+ TYPE_MESSAGE = 11; // Length-delimited aggregate.
+
+ // New in version 2.
+ TYPE_BYTES = 12;
+ TYPE_UINT32 = 13;
+ TYPE_ENUM = 14;
+ TYPE_SFIXED32 = 15;
+ TYPE_SFIXED64 = 16;
+ TYPE_SINT32 = 17; // Uses ZigZag encoding.
+ TYPE_SINT64 = 18; // Uses ZigZag encoding.
+ };
+
+ enum Label {
+ // 0 is reserved for errors
+ LABEL_OPTIONAL = 1;
+ LABEL_REQUIRED = 2;
+ LABEL_REPEATED = 3;
+ // TODO(sanjay): Should we add LABEL_MAP?
+ };
+
+ optional string name = 1;
+ optional int32 number = 3;
+ optional Label label = 4;
+
+ // If type_name is set, this need not be set. If both this and type_name
+ // are set, this must be either TYPE_ENUM or TYPE_MESSAGE.
+ optional Type type = 5;
+
+ // For message and enum types, this is the name of the type. If the name
+ // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
+ // rules are used to find the type (i.e. first the nested types within this
+ // message are searched, then within the parent, on up to the root
+ // namespace).
+ optional string type_name = 6;
+
+ // For extensions, this is the name of the type being extended. It is
+ // resolved in the same manner as type_name.
+ optional string extendee = 2;
+
+ // For numeric types, contains the original text representation of the value.
+ // For booleans, "true" or "false".
+ // For strings, contains the default text contents (not escaped in any way).
+ // For bytes, contains the C escaped value. All bytes >= 128 are escaped.
+ // TODO(kenton): Base-64 encode?
+ optional string default_value = 7;
+
+ optional FieldOptions options = 8;
+}
+
+// Describes an enum type.
+message EnumDescriptorProto {
+ optional string name = 1;
+
+ repeated EnumValueDescriptorProto value = 2;
+
+ optional EnumOptions options = 3;
+}
+
+// Describes a value within an enum.
+message EnumValueDescriptorProto {
+ optional string name = 1;
+ optional int32 number = 2;
+
+ optional EnumValueOptions options = 3;
+}
+
+// Describes a service.
+message ServiceDescriptorProto {
+ optional string name = 1;
+ repeated MethodDescriptorProto method = 2;
+
+ optional ServiceOptions options = 3;
+}
+
+// Describes a method of a service.
+message MethodDescriptorProto {
+ optional string name = 1;
+
+ // Input and output type names. These are resolved in the same way as
+ // FieldDescriptorProto.type_name, but must refer to a message type.
+ optional string input_type = 2;
+ optional string output_type = 3;
+
+ optional MethodOptions options = 4;
+}
+
+
+// ===================================================================
+// Options
+
+// Each of the definitions above may have "options" attached. These are
+// just annotations which may cause code to be generated slightly differently
+// or may contain hints for code that manipulates protocol messages.
+//
+// Clients may define custom options as extensions of the *Options messages.
+// These extensions may not yet be known at parsing time, so the parser cannot
+// store the values in them. Instead it stores them in a field in the *Options
+// message called uninterpreted_option. This field must have the same name
+// across all *Options messages. We then use this field to populate the
+// extensions when we build a descriptor, at which point all protos have been
+// parsed and so all extensions are known.
+//
+// Extension numbers for custom options may be chosen as follows:
+// * For options which will only be used within a single application or
+// organization, or for experimental options, use field numbers 50000
+// through 99999. It is up to you to ensure that you do not use the
+// same number for multiple options.
+// * For options which will be published and used publicly by multiple
+// independent entities, e-mail protobuf-global-extension-registry@google.com
+// to reserve extension numbers. Simply provide your project name (e.g.
+// Object-C plugin) and your porject website (if available) -- there's no need
+// to explain how you intend to use them. Usually you only need one extension
+// number. You can declare multiple options with only one extension number by
+// putting them in a sub-message. See the Custom Options section of the docs
+// for examples:
+// http://code.google.com/apis/protocolbuffers/docs/proto.html#options
+// If this turns out to be popular, a web service will be set up
+// to automatically assign option numbers.
+
+
+message FileOptions {
+
+ // Sets the Java package where classes generated from this .proto will be
+ // placed. By default, the proto package is used, but this is often
+ // inappropriate because proto packages do not normally start with backwards
+ // domain names.
+ optional string java_package = 1;
+
+
+ // If set, all the classes from the .proto file are wrapped in a single
+ // outer class with the given name. This applies to both Proto1
+ // (equivalent to the old "--one_java_file" option) and Proto2 (where
+ // a .proto always translates to a single class, but you may want to
+ // explicitly choose the class name).
+ optional string java_outer_classname = 8;
+
+ // If set true, then the Java code generator will generate a separate .java
+ // file for each top-level message, enum, and service defined in the .proto
+ // file. Thus, these types will *not* be nested inside the outer class
+ // named by java_outer_classname. However, the outer class will still be
+ // generated to contain the file's getDescriptor() method as well as any
+ // 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 is
+ // purely a speed optimization, as the AbstractMessage base class includes
+ // reflection-based implementations of these methods.
+ optional bool java_generate_equals_and_hash = 20 [default=false];
+
+ // Generated classes can be optimized for speed or code size.
+ enum OptimizeMode {
+ SPEED = 1; // Generate complete code for parsing, serialization,
+ // etc.
+ CODE_SIZE = 2; // Use ReflectionOps to implement these methods.
+ LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime.
+ }
+ optional OptimizeMode optimize_for = 9 [default=SPEED];
+
+ // Sets the Go package where structs generated from this .proto will be
+ // placed. There is no default.
+ optional string go_package = 11;
+
+
+
+ // Should generic services be generated in each language? "Generic" services
+ // are not specific to any particular RPC system. They are generated by the
+ // main code generators in each language (without additional plugins).
+ // Generic services were the only kind of service generation supported by
+ // early versions of proto2.
+ //
+ // Generic services are now considered deprecated in favor of using plugins
+ // that generate code specific to your particular RPC system. Therefore,
+ // these default to false. Old code which depends on generic services should
+ // explicitly set them to true.
+ optional bool cc_generic_services = 16 [default=false];
+ optional bool java_generic_services = 17 [default=false];
+ optional bool py_generic_services = 18 [default=false];
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message MessageOptions {
+ // Set true to use the old proto1 MessageSet wire format for extensions.
+ // This is provided for backwards-compatibility with the MessageSet wire
+ // format. You should not use this for any other reason: It's less
+ // efficient, has fewer features, and is more complicated.
+ //
+ // The message must be defined exactly as follows:
+ // message Foo {
+ // option message_set_wire_format = true;
+ // extensions 4 to max;
+ // }
+ // Note that the message cannot have any defined fields; MessageSets only
+ // have extensions.
+ //
+ // All extensions of your type must be singular messages; e.g. they cannot
+ // be int32s, enums, or repeated messages.
+ //
+ // Because this is an option, the above two restrictions are not enforced by
+ // the protocol compiler.
+ optional bool message_set_wire_format = 1 [default=false];
+
+ // Disables the generation of the standard "descriptor()" accessor, which can
+ // conflict with a field of the same name. This is meant to make migration
+ // from proto1 easier; new code should avoid fields named "descriptor".
+ optional bool no_standard_descriptor_accessor = 2 [default=false];
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message FieldOptions {
+ // The ctype option instructs the C++ code generator to use a different
+ // representation of the field than it normally would. See the specific
+ // options below. This option is not yet implemented in the open source
+ // release -- sorry, we'll try to include it in a future version!
+ optional CType ctype = 1 [default = STRING];
+ enum CType {
+ // Default mode.
+ STRING = 0;
+
+ CORD = 1;
+
+ STRING_PIECE = 2;
+ }
+ // The packed option can be enabled for repeated primitive fields to enable
+ // a more efficient representation on the wire. Rather than repeatedly
+ // writing the tag and type for each element, the entire array is encoded as
+ // a single length-delimited blob.
+ optional bool packed = 2;
+
+
+
+ // Should this field be parsed lazily? Lazy applies only to message-type
+ // fields. It means that when the outer message is initially parsed, the
+ // inner message's contents will not be parsed but instead stored in encoded
+ // form. The inner message will actually be parsed when it is first accessed.
+ //
+ // This is only a hint. Implementations are free to choose whether to use
+ // eager or lazy parsing regardless of the value of this option. However,
+ // setting this option true suggests that the protocol author believes that
+ // using lazy parsing on this field is worth the additional bookkeeping
+ // overhead typically needed to implement it.
+ //
+ // This option does not affect the public interface of any generated code;
+ // all method signatures remain the same. Furthermore, thread-safety of the
+ // interface is not affected by this option; const methods remain safe to
+ // call from multiple threads concurrently, while non-const methods continue
+ // to require exclusive access.
+ //
+ //
+ // Note that implementations may choose not to check required fields within
+ // a lazy sub-message. That is, calling IsInitialized() on the outher 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
+ // parsing. An implementation which chooses not to check required fields
+ // must be consistent about it. That is, for any particular sub-message, the
+ // implementation must either *always* check its required fields, or *never*
+ // check its required fields, regardless of whether or not the message has
+ // been parsed.
+ optional bool lazy = 5 [default=false];
+
+ // Is this field deprecated?
+ // Depending on the target platform, this can emit Deprecated annotations
+ // for accessors, or it will be completely ignored; in the very least, this
+ // is a formalization for deprecating fields.
+ optional bool deprecated = 3 [default=false];
+
+ // EXPERIMENTAL. DO NOT USE.
+ // For "map" fields, the name of the field in the enclosed type that
+ // is the key for this map. For example, suppose we have:
+ // message Item {
+ // required string name = 1;
+ // required string value = 2;
+ // }
+ // message Config {
+ // repeated Item items = 1 [experimental_map_key="name"];
+ // }
+ // In this situation, the map key for Item will be set to "name".
+ // TODO: Fully-implement this, then remove the "experimental_" prefix.
+ optional string experimental_map_key = 9;
+
+ // For Google-internal migration only. Do not use.
+ optional bool weak = 10 [default=false];
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message EnumOptions {
+
+ // Set this option to false to disallow mapping different tag names to a same
+ // value.
+ optional bool allow_alias = 2 [default=true];
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message EnumValueOptions {
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message ServiceOptions {
+
+ // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
+ // framework. We apologize for hoarding these numbers to ourselves, but
+ // we were already using them long before we decided to release Protocol
+ // Buffers.
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message MethodOptions {
+
+ // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
+ // framework. We apologize for hoarding these numbers to ourselves, but
+ // we were already using them long before we decided to release Protocol
+ // Buffers.
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+
+// A message representing a option the parser does not recognize. This only
+// appears in options protos created by the compiler::Parser class.
+// DescriptorPool resolves these when building Descriptor objects. Therefore,
+// options protos in descriptor objects (e.g. returned by Descriptor::options(),
+// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
+// in them.
+message UninterpretedOption {
+ // The name of the uninterpreted option. Each string represents a segment in
+ // a dot-separated name. is_extension is true iff a segment represents an
+ // extension (denoted with parentheses in options specs in .proto files).
+ // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
+ // "foo.(bar.baz).qux".
+ message NamePart {
+ required string name_part = 1;
+ required bool is_extension = 2;
+ }
+ repeated NamePart name = 2;
+
+ // The value of the uninterpreted option, in whatever type the tokenizer
+ // identified it as during parsing. Exactly one of these should be set.
+ optional string identifier_value = 3;
+ optional uint64 positive_int_value = 4;
+ optional int64 negative_int_value = 5;
+ optional double double_value = 6;
+ optional bytes string_value = 7;
+ optional string aggregate_value = 8;
+}
+
+// ===================================================================
+// Optional source code info
+
+// Encapsulates information about the original source file from which a
+// FileDescriptorProto was generated.
+message SourceCodeInfo {
+ // A Location identifies a piece of source code in a .proto file which
+ // corresponds to a particular definition. This information is intended
+ // to be useful to IDEs, code indexers, documentation generators, and similar
+ // tools.
+ //
+ // For example, say we have a file like:
+ // message Foo {
+ // optional string foo = 1;
+ // }
+ // Let's look at just the field definition:
+ // optional string foo = 1;
+ // ^ ^^ ^^ ^ ^^^
+ // a bc de f ghi
+ // We have the following locations:
+ // span path represents
+ // [a,i) [ 4, 0, 2, 0 ] The whole field definition.
+ // [a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
+ // [c,d) [ 4, 0, 2, 0, 5 ] The type (string).
+ // [e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
+ // [g,h) [ 4, 0, 2, 0, 3 ] The number (1).
+ //
+ // Notes:
+ // - A location may refer to a repeated field itself (i.e. not to any
+ // particular index within it). This is used whenever a set of elements are
+ // logically enclosed in a single code segment. For example, an entire
+ // extend block (possibly containing multiple extension definitions) will
+ // have an outer location whose path refers to the "extensions" repeated
+ // field without an index.
+ // - Multiple locations may have the same path. This happens when a single
+ // logical declaration is spread out across multiple places. The most
+ // obvious example is the "extend" block again -- there may be multiple
+ // extend blocks in the same scope, each of which will have the same path.
+ // - A location's span is not always a subset of its parent's span. For
+ // example, the "extendee" of an extension declaration appears at the
+ // beginning of the "extend" block and is shared by all extensions within
+ // the block.
+ // - Just because a location's span is a subset of some other location's span
+ // does not mean that it is a descendent. For example, a "group" defines
+ // both a type and a field in a single declaration. Thus, the locations
+ // corresponding to the type and field and their components will overlap.
+ // - Code which tries to interpret locations should probably be designed to
+ // ignore those that it doesn't understand, as more types of locations could
+ // be recorded in the future.
+ repeated Location location = 1;
+ message Location {
+ // Identifies which part of the FileDescriptorProto was defined at this
+ // location.
+ //
+ // Each element is a field number or an index. They form a path from
+ // the root FileDescriptorProto to the place where the definition. For
+ // example, this path:
+ // [ 4, 3, 2, 7, 1 ]
+ // refers to:
+ // file.message_type(3) // 4, 3
+ // .field(7) // 2, 7
+ // .name() // 1
+ // This is because FileDescriptorProto.message_type has field number 4:
+ // repeated DescriptorProto message_type = 4;
+ // and DescriptorProto.field has field number 2:
+ // repeated FieldDescriptorProto field = 2;
+ // and FieldDescriptorProto.name has field number 1:
+ // optional string name = 1;
+ //
+ // Thus, the above path gives the location of a field name. If we removed
+ // the last element:
+ // [ 4, 3, 2, 7 ]
+ // this path refers to the whole field declaration (from the beginning
+ // of the label to the terminating semicolon).
+ repeated int32 path = 1 [packed=true];
+
+ // Always has exactly three or four elements: start line, start column,
+ // end line (optional, otherwise assumed same as start line), end column.
+ // These are packed into a single field for efficiency. Note that line
+ // and column numbers are zero-based -- typically you will want to add
+ // 1 to each before displaying to a user.
+ repeated int32 span = 2 [packed=true];
+
+ // If this SourceCodeInfo represents a complete declaration, these are any
+ // comments appearing before and after the declaration which appear to be
+ // attached to the declaration.
+ //
+ // A series of line comments appearing on consecutive lines, with no other
+ // tokens appearing on those lines, will be treated as a single comment.
+ //
+ // Only the comment content is provided; comment markers (e.g. //) are
+ // stripped out. For block comments, leading whitespace and an asterisk
+ // will be stripped from the beginning of each line other than the first.
+ // Newlines are included in the output.
+ //
+ // Examples:
+ //
+ // optional int32 foo = 1; // Comment attached to foo.
+ // // Comment attached to bar.
+ // optional int32 bar = 2;
+ //
+ // optional string baz = 3;
+ // // Comment attached to baz.
+ // // Another line attached to baz.
+ //
+ // // Comment attached to qux.
+ // //
+ // // Another line attached to qux.
+ // optional double qux = 4;
+ //
+ // optional string corge = 5;
+ // /* Block comment attached
+ // * to corge. Leading asterisks
+ // * will be removed. */
+ // /* Block comment attached to
+ // * grault. */
+ // optional int32 grault = 6;
+ optional string leading_comments = 3;
+ optional string trailing_comments = 4;
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest.proto
new file mode 100644
index 0000000000..6eb2d86f51
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest.proto
@@ -0,0 +1,719 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file we will use for unit testing.
+
+
+// Some generic_services option(s) added automatically.
+// See: http://go/proto2-generic-services-default
+option cc_generic_services = true; // auto-added
+option java_generic_services = true; // auto-added
+option py_generic_services = true; // auto-added
+
+import "google/protobuf/unittest_import.proto";
+
+// We don't put this in a package within proto2 because we need to make sure
+// that the generated code doesn't depend on being in the proto2 namespace.
+// In test_util.h we do "using namespace unittest = protobuf_unittest".
+package protobuf_unittest;
+
+// Protos optimized for SPEED use a strict superset of the generated code
+// of equivalent ones optimized for CODE_SIZE, so we should optimize all our
+// tests for speed unless explicitly testing code size optimization.
+option optimize_for = SPEED;
+
+option java_outer_classname = "UnittestProto";
+
+// This proto includes every type of field in both singular and repeated
+// forms.
+message TestAllTypes {
+ message NestedMessage {
+ // The field name "b" fails to compile in proto1 because it conflicts with
+ // a local variable named "b" in one of the generated methods. Doh.
+ // This file needs to compile in proto1 to test backwards-compatibility.
+ optional int32 bb = 1;
+ }
+
+ enum NestedEnum {
+ FOO = 1;
+ BAR = 2;
+ BAZ = 3;
+ }
+
+ // Singular
+ optional int32 optional_int32 = 1;
+ optional int64 optional_int64 = 2;
+ optional uint32 optional_uint32 = 3;
+ optional uint64 optional_uint64 = 4;
+ optional sint32 optional_sint32 = 5;
+ optional sint64 optional_sint64 = 6;
+ optional fixed32 optional_fixed32 = 7;
+ optional fixed64 optional_fixed64 = 8;
+ optional sfixed32 optional_sfixed32 = 9;
+ optional sfixed64 optional_sfixed64 = 10;
+ optional float optional_float = 11;
+ optional double optional_double = 12;
+ optional bool optional_bool = 13;
+ optional string optional_string = 14;
+ optional bytes optional_bytes = 15;
+
+ optional group OptionalGroup = 16 {
+ optional int32 a = 17;
+ }
+
+ optional NestedMessage optional_nested_message = 18;
+ optional ForeignMessage optional_foreign_message = 19;
+ optional protobuf_unittest_import.ImportMessage optional_import_message = 20;
+
+ optional NestedEnum optional_nested_enum = 21;
+ optional ForeignEnum optional_foreign_enum = 22;
+ optional protobuf_unittest_import.ImportEnum optional_import_enum = 23;
+
+ optional string optional_string_piece = 24 [ctype=STRING_PIECE];
+ optional string optional_cord = 25 [ctype=CORD];
+
+ // Defined in unittest_import_public.proto
+ optional protobuf_unittest_import.PublicImportMessage
+ optional_public_import_message = 26;
+
+ optional NestedMessage optional_lazy_message = 27 [lazy=true];
+
+ // Repeated
+ repeated int32 repeated_int32 = 31;
+ repeated int64 repeated_int64 = 32;
+ repeated uint32 repeated_uint32 = 33;
+ repeated uint64 repeated_uint64 = 34;
+ repeated sint32 repeated_sint32 = 35;
+ repeated sint64 repeated_sint64 = 36;
+ repeated fixed32 repeated_fixed32 = 37;
+ repeated fixed64 repeated_fixed64 = 38;
+ repeated sfixed32 repeated_sfixed32 = 39;
+ repeated sfixed64 repeated_sfixed64 = 40;
+ repeated float repeated_float = 41;
+ repeated double repeated_double = 42;
+ repeated bool repeated_bool = 43;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+
+ repeated group RepeatedGroup = 46 {
+ optional int32 a = 47;
+ }
+
+ repeated NestedMessage repeated_nested_message = 48;
+ repeated ForeignMessage repeated_foreign_message = 49;
+ repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50;
+
+ repeated NestedEnum repeated_nested_enum = 51;
+ repeated ForeignEnum repeated_foreign_enum = 52;
+ repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53;
+
+ repeated string repeated_string_piece = 54 [ctype=STRING_PIECE];
+ repeated string repeated_cord = 55 [ctype=CORD];
+
+ repeated NestedMessage repeated_lazy_message = 57 [lazy=true];
+
+ // Singular with defaults
+ optional int32 default_int32 = 61 [default = 41 ];
+ optional int64 default_int64 = 62 [default = 42 ];
+ optional uint32 default_uint32 = 63 [default = 43 ];
+ optional uint64 default_uint64 = 64 [default = 44 ];
+ optional sint32 default_sint32 = 65 [default = -45 ];
+ optional sint64 default_sint64 = 66 [default = 46 ];
+ optional fixed32 default_fixed32 = 67 [default = 47 ];
+ optional fixed64 default_fixed64 = 68 [default = 48 ];
+ optional sfixed32 default_sfixed32 = 69 [default = 49 ];
+ optional sfixed64 default_sfixed64 = 70 [default = -50 ];
+ optional float default_float = 71 [default = 51.5 ];
+ optional double default_double = 72 [default = 52e3 ];
+ optional bool default_bool = 73 [default = true ];
+ optional string default_string = 74 [default = "hello"];
+ optional bytes default_bytes = 75 [default = "world"];
+
+ optional NestedEnum default_nested_enum = 81 [default = BAR ];
+ optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR];
+ optional protobuf_unittest_import.ImportEnum
+ default_import_enum = 83 [default = IMPORT_BAR];
+
+ optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"];
+ optional string default_cord = 85 [ctype=CORD,default="123"];
+}
+
+message TestDeprecatedFields {
+ optional int32 deprecated_int32 = 1 [deprecated=true];
+}
+
+// Define these after TestAllTypes to make sure the compiler can handle
+// that.
+message ForeignMessage {
+ optional int32 c = 1;
+}
+
+enum ForeignEnum {
+ FOREIGN_FOO = 4;
+ FOREIGN_BAR = 5;
+ FOREIGN_BAZ = 6;
+}
+
+message TestAllExtensions {
+ extensions 1 to max;
+}
+
+extend TestAllExtensions {
+ // Singular
+ optional int32 optional_int32_extension = 1;
+ optional int64 optional_int64_extension = 2;
+ optional uint32 optional_uint32_extension = 3;
+ optional uint64 optional_uint64_extension = 4;
+ optional sint32 optional_sint32_extension = 5;
+ optional sint64 optional_sint64_extension = 6;
+ optional fixed32 optional_fixed32_extension = 7;
+ optional fixed64 optional_fixed64_extension = 8;
+ optional sfixed32 optional_sfixed32_extension = 9;
+ optional sfixed64 optional_sfixed64_extension = 10;
+ optional float optional_float_extension = 11;
+ optional double optional_double_extension = 12;
+ optional bool optional_bool_extension = 13;
+ optional string optional_string_extension = 14;
+ optional bytes optional_bytes_extension = 15;
+
+ optional group OptionalGroup_extension = 16 {
+ optional int32 a = 17;
+ }
+
+ optional TestAllTypes.NestedMessage optional_nested_message_extension = 18;
+ optional ForeignMessage optional_foreign_message_extension = 19;
+ optional protobuf_unittest_import.ImportMessage
+ optional_import_message_extension = 20;
+
+ optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21;
+ optional ForeignEnum optional_foreign_enum_extension = 22;
+ optional protobuf_unittest_import.ImportEnum
+ optional_import_enum_extension = 23;
+
+ optional string optional_string_piece_extension = 24 [ctype=STRING_PIECE];
+ optional string optional_cord_extension = 25 [ctype=CORD];
+
+ optional protobuf_unittest_import.PublicImportMessage
+ optional_public_import_message_extension = 26;
+
+ optional TestAllTypes.NestedMessage
+ optional_lazy_message_extension = 27 [lazy=true];
+
+ // Repeated
+ repeated int32 repeated_int32_extension = 31;
+ repeated int64 repeated_int64_extension = 32;
+ repeated uint32 repeated_uint32_extension = 33;
+ repeated uint64 repeated_uint64_extension = 34;
+ repeated sint32 repeated_sint32_extension = 35;
+ repeated sint64 repeated_sint64_extension = 36;
+ repeated fixed32 repeated_fixed32_extension = 37;
+ repeated fixed64 repeated_fixed64_extension = 38;
+ repeated sfixed32 repeated_sfixed32_extension = 39;
+ repeated sfixed64 repeated_sfixed64_extension = 40;
+ repeated float repeated_float_extension = 41;
+ repeated double repeated_double_extension = 42;
+ repeated bool repeated_bool_extension = 43;
+ repeated string repeated_string_extension = 44;
+ repeated bytes repeated_bytes_extension = 45;
+
+ repeated group RepeatedGroup_extension = 46 {
+ optional int32 a = 47;
+ }
+
+ repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48;
+ repeated ForeignMessage repeated_foreign_message_extension = 49;
+ repeated protobuf_unittest_import.ImportMessage
+ repeated_import_message_extension = 50;
+
+ repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51;
+ repeated ForeignEnum repeated_foreign_enum_extension = 52;
+ repeated protobuf_unittest_import.ImportEnum
+ repeated_import_enum_extension = 53;
+
+ repeated string repeated_string_piece_extension = 54 [ctype=STRING_PIECE];
+ repeated string repeated_cord_extension = 55 [ctype=CORD];
+
+ repeated TestAllTypes.NestedMessage
+ repeated_lazy_message_extension = 57 [lazy=true];
+
+ // Singular with defaults
+ optional int32 default_int32_extension = 61 [default = 41 ];
+ optional int64 default_int64_extension = 62 [default = 42 ];
+ optional uint32 default_uint32_extension = 63 [default = 43 ];
+ optional uint64 default_uint64_extension = 64 [default = 44 ];
+ optional sint32 default_sint32_extension = 65 [default = -45 ];
+ optional sint64 default_sint64_extension = 66 [default = 46 ];
+ optional fixed32 default_fixed32_extension = 67 [default = 47 ];
+ optional fixed64 default_fixed64_extension = 68 [default = 48 ];
+ optional sfixed32 default_sfixed32_extension = 69 [default = 49 ];
+ optional sfixed64 default_sfixed64_extension = 70 [default = -50 ];
+ optional float default_float_extension = 71 [default = 51.5 ];
+ optional double default_double_extension = 72 [default = 52e3 ];
+ optional bool default_bool_extension = 73 [default = true ];
+ optional string default_string_extension = 74 [default = "hello"];
+ optional bytes default_bytes_extension = 75 [default = "world"];
+
+ optional TestAllTypes.NestedEnum
+ default_nested_enum_extension = 81 [default = BAR];
+ optional ForeignEnum
+ default_foreign_enum_extension = 82 [default = FOREIGN_BAR];
+ optional protobuf_unittest_import.ImportEnum
+ default_import_enum_extension = 83 [default = IMPORT_BAR];
+
+ optional string default_string_piece_extension = 84 [ctype=STRING_PIECE,
+ default="abc"];
+ optional string default_cord_extension = 85 [ctype=CORD, default="123"];
+}
+
+message TestNestedExtension {
+ extend TestAllExtensions {
+ // Check for bug where string extensions declared in tested scope did not
+ // compile.
+ optional string test = 1002 [default="test"];
+ }
+}
+
+// We have separate messages for testing required fields because it's
+// annoying to have to fill in required fields in TestProto in order to
+// do anything with it. Note that we don't need to test every type of
+// required filed because the code output is basically identical to
+// optional fields for all types.
+message TestRequired {
+ required int32 a = 1;
+ optional int32 dummy2 = 2;
+ required int32 b = 3;
+
+ extend TestAllExtensions {
+ optional TestRequired single = 1000;
+ repeated TestRequired multi = 1001;
+ }
+
+ // Pad the field count to 32 so that we can test that IsInitialized()
+ // properly checks multiple elements of has_bits_.
+ optional int32 dummy4 = 4;
+ optional int32 dummy5 = 5;
+ optional int32 dummy6 = 6;
+ optional int32 dummy7 = 7;
+ optional int32 dummy8 = 8;
+ optional int32 dummy9 = 9;
+ optional int32 dummy10 = 10;
+ optional int32 dummy11 = 11;
+ optional int32 dummy12 = 12;
+ optional int32 dummy13 = 13;
+ optional int32 dummy14 = 14;
+ optional int32 dummy15 = 15;
+ optional int32 dummy16 = 16;
+ optional int32 dummy17 = 17;
+ optional int32 dummy18 = 18;
+ optional int32 dummy19 = 19;
+ optional int32 dummy20 = 20;
+ optional int32 dummy21 = 21;
+ optional int32 dummy22 = 22;
+ optional int32 dummy23 = 23;
+ optional int32 dummy24 = 24;
+ optional int32 dummy25 = 25;
+ optional int32 dummy26 = 26;
+ optional int32 dummy27 = 27;
+ optional int32 dummy28 = 28;
+ optional int32 dummy29 = 29;
+ optional int32 dummy30 = 30;
+ optional int32 dummy31 = 31;
+ optional int32 dummy32 = 32;
+
+ required int32 c = 33;
+}
+
+message TestRequiredForeign {
+ optional TestRequired optional_message = 1;
+ repeated TestRequired repeated_message = 2;
+ optional int32 dummy = 3;
+}
+
+// Test that we can use NestedMessage from outside TestAllTypes.
+message TestForeignNested {
+ optional TestAllTypes.NestedMessage foreign_nested = 1;
+}
+
+// TestEmptyMessage is used to test unknown field support.
+message TestEmptyMessage {
+}
+
+// Like above, but declare all field numbers as potential extensions. No
+// actual extensions should ever be defined for this type.
+message TestEmptyMessageWithExtensions {
+ extensions 1 to max;
+}
+
+message TestMultipleExtensionRanges {
+ extensions 42;
+ extensions 4143 to 4243;
+ extensions 65536 to max;
+}
+
+// Test that really large tag numbers don't break anything.
+message TestReallyLargeTagNumber {
+ // The largest possible tag number is 2^28 - 1, since the wire format uses
+ // three bits to communicate wire type.
+ optional int32 a = 1;
+ optional int32 bb = 268435455;
+}
+
+message TestRecursiveMessage {
+ optional TestRecursiveMessage a = 1;
+ optional int32 i = 2;
+}
+
+// Test that mutual recursion works.
+message TestMutualRecursionA {
+ optional TestMutualRecursionB bb = 1;
+}
+
+message TestMutualRecursionB {
+ optional TestMutualRecursionA a = 1;
+ optional int32 optional_int32 = 2;
+}
+
+// Test that groups have disjoint field numbers from their siblings and
+// parents. This is NOT possible in proto1; only proto2. When attempting
+// to compile with proto1, this will emit an error; so we only include it
+// in protobuf_unittest_proto.
+message TestDupFieldNumber { // NO_PROTO1
+ optional int32 a = 1; // NO_PROTO1
+ optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1
+ optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1
+} // NO_PROTO1
+
+// Additional messages for testing lazy fields.
+message TestEagerMessage {
+ optional TestAllTypes sub_message = 1 [lazy=false];
+}
+message TestLazyMessage {
+ optional TestAllTypes sub_message = 1 [lazy=true];
+}
+
+// Needed for a Python test.
+message TestNestedMessageHasBits {
+ message NestedMessage {
+ repeated int32 nestedmessage_repeated_int32 = 1;
+ repeated ForeignMessage nestedmessage_repeated_foreignmessage = 2;
+ }
+ optional NestedMessage optional_nested_message = 1;
+}
+
+
+// Test an enum that has multiple values with the same number.
+enum TestEnumWithDupValue {
+ option allow_alias = true;
+ FOO1 = 1;
+ BAR1 = 2;
+ BAZ = 3;
+ FOO2 = 1;
+ BAR2 = 2;
+}
+
+// Test an enum with large, unordered values.
+enum TestSparseEnum {
+ SPARSE_A = 123;
+ SPARSE_B = 62374;
+ SPARSE_C = 12589234;
+ SPARSE_D = -15;
+ SPARSE_E = -53452;
+ SPARSE_F = 0;
+ SPARSE_G = 2;
+}
+
+// Test message with CamelCase field names. This violates Protocol Buffer
+// standard style.
+message TestCamelCaseFieldNames {
+ optional int32 PrimitiveField = 1;
+ optional string StringField = 2;
+ optional ForeignEnum EnumField = 3;
+ optional ForeignMessage MessageField = 4;
+ optional string StringPieceField = 5 [ctype=STRING_PIECE];
+ optional string CordField = 6 [ctype=CORD];
+
+ repeated int32 RepeatedPrimitiveField = 7;
+ repeated string RepeatedStringField = 8;
+ repeated ForeignEnum RepeatedEnumField = 9;
+ repeated ForeignMessage RepeatedMessageField = 10;
+ repeated string RepeatedStringPieceField = 11 [ctype=STRING_PIECE];
+ repeated string RepeatedCordField = 12 [ctype=CORD];
+}
+
+
+// We list fields out of order, to ensure that we're using field number and not
+// field index to determine serialization order.
+message TestFieldOrderings {
+ optional string my_string = 11;
+ extensions 2 to 10;
+ optional int64 my_int = 1;
+ extensions 12 to 100;
+ optional float my_float = 101;
+}
+
+
+extend TestFieldOrderings {
+ optional string my_extension_string = 50;
+ optional int32 my_extension_int = 5;
+}
+
+
+message TestExtremeDefaultValues {
+ optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"];
+ optional uint32 large_uint32 = 2 [default = 0xFFFFFFFF];
+ optional uint64 large_uint64 = 3 [default = 0xFFFFFFFFFFFFFFFF];
+ optional int32 small_int32 = 4 [default = -0x7FFFFFFF];
+ optional int64 small_int64 = 5 [default = -0x7FFFFFFFFFFFFFFF];
+ optional int32 really_small_int32 = 21 [default = -0x80000000];
+ optional int64 really_small_int64 = 22 [default = -0x8000000000000000];
+
+ // The default value here is UTF-8 for "\u1234". (We could also just type
+ // the UTF-8 text directly into this text file rather than escape it, but
+ // lots of people use editors that would be confused by this.)
+ optional string utf8_string = 6 [default = "\341\210\264"];
+
+ // Tests for single-precision floating-point values.
+ optional float zero_float = 7 [default = 0];
+ optional float one_float = 8 [default = 1];
+ optional float small_float = 9 [default = 1.5];
+ optional float negative_one_float = 10 [default = -1];
+ optional float negative_float = 11 [default = -1.5];
+ // Using exponents
+ optional float large_float = 12 [default = 2E8];
+ optional float small_negative_float = 13 [default = -8e-28];
+
+ // Text for nonfinite floating-point values.
+ optional double inf_double = 14 [default = inf];
+ optional double neg_inf_double = 15 [default = -inf];
+ optional double nan_double = 16 [default = nan];
+ optional float inf_float = 17 [default = inf];
+ optional float neg_inf_float = 18 [default = -inf];
+ optional float nan_float = 19 [default = nan];
+
+ // Tests for C++ trigraphs.
+ // Trigraphs should be escaped in C++ generated files, but they should not be
+ // escaped for other languages.
+ // Note that in .proto file, "\?" is a valid way to escape ? in string
+ // literals.
+ optional string cpp_trigraph = 20 [default = "? \? ?? \?? \??? ??/ ?\?-"];
+
+ // String defaults containing the character '\000'
+ optional string string_with_zero = 23 [default = "hel\000lo"];
+ optional bytes bytes_with_zero = 24 [default = "wor\000ld"];
+ optional string string_piece_with_zero = 25 [ctype=STRING_PIECE,
+ default="ab\000c"];
+ optional string cord_with_zero = 26 [ctype=CORD,
+ default="12\0003"];
+}
+
+message SparseEnumMessage {
+ optional TestSparseEnum sparse_enum = 1;
+}
+
+// Test String and Bytes: string is for valid UTF-8 strings
+message OneString {
+ optional string data = 1;
+}
+
+message MoreString {
+ repeated string data = 1;
+}
+
+message OneBytes {
+ optional bytes data = 1;
+}
+
+message MoreBytes {
+ repeated bytes data = 1;
+}
+
+
+// Test messages for packed fields
+
+message TestPackedTypes {
+ repeated int32 packed_int32 = 90 [packed = true];
+ repeated int64 packed_int64 = 91 [packed = true];
+ repeated uint32 packed_uint32 = 92 [packed = true];
+ repeated uint64 packed_uint64 = 93 [packed = true];
+ repeated sint32 packed_sint32 = 94 [packed = true];
+ repeated sint64 packed_sint64 = 95 [packed = true];
+ repeated fixed32 packed_fixed32 = 96 [packed = true];
+ repeated fixed64 packed_fixed64 = 97 [packed = true];
+ repeated sfixed32 packed_sfixed32 = 98 [packed = true];
+ repeated sfixed64 packed_sfixed64 = 99 [packed = true];
+ repeated float packed_float = 100 [packed = true];
+ repeated double packed_double = 101 [packed = true];
+ repeated bool packed_bool = 102 [packed = true];
+ repeated ForeignEnum packed_enum = 103 [packed = true];
+}
+
+// A message with the same fields as TestPackedTypes, but without packing. Used
+// to test packed <-> unpacked wire compatibility.
+message TestUnpackedTypes {
+ repeated int32 unpacked_int32 = 90 [packed = false];
+ repeated int64 unpacked_int64 = 91 [packed = false];
+ repeated uint32 unpacked_uint32 = 92 [packed = false];
+ repeated uint64 unpacked_uint64 = 93 [packed = false];
+ repeated sint32 unpacked_sint32 = 94 [packed = false];
+ repeated sint64 unpacked_sint64 = 95 [packed = false];
+ repeated fixed32 unpacked_fixed32 = 96 [packed = false];
+ repeated fixed64 unpacked_fixed64 = 97 [packed = false];
+ repeated sfixed32 unpacked_sfixed32 = 98 [packed = false];
+ repeated sfixed64 unpacked_sfixed64 = 99 [packed = false];
+ repeated float unpacked_float = 100 [packed = false];
+ repeated double unpacked_double = 101 [packed = false];
+ repeated bool unpacked_bool = 102 [packed = false];
+ repeated ForeignEnum unpacked_enum = 103 [packed = false];
+}
+
+message TestPackedExtensions {
+ extensions 1 to max;
+}
+
+extend TestPackedExtensions {
+ repeated int32 packed_int32_extension = 90 [packed = true];
+ repeated int64 packed_int64_extension = 91 [packed = true];
+ repeated uint32 packed_uint32_extension = 92 [packed = true];
+ repeated uint64 packed_uint64_extension = 93 [packed = true];
+ repeated sint32 packed_sint32_extension = 94 [packed = true];
+ repeated sint64 packed_sint64_extension = 95 [packed = true];
+ repeated fixed32 packed_fixed32_extension = 96 [packed = true];
+ repeated fixed64 packed_fixed64_extension = 97 [packed = true];
+ repeated sfixed32 packed_sfixed32_extension = 98 [packed = true];
+ repeated sfixed64 packed_sfixed64_extension = 99 [packed = true];
+ repeated float packed_float_extension = 100 [packed = true];
+ repeated double packed_double_extension = 101 [packed = true];
+ repeated bool packed_bool_extension = 102 [packed = true];
+ repeated ForeignEnum packed_enum_extension = 103 [packed = true];
+}
+
+// Used by ExtensionSetTest/DynamicExtensions. The test actually builds
+// a set of extensions to TestAllExtensions dynamically, based on the fields
+// of this message type.
+message TestDynamicExtensions {
+ enum DynamicEnumType {
+ DYNAMIC_FOO = 2200;
+ DYNAMIC_BAR = 2201;
+ DYNAMIC_BAZ = 2202;
+ }
+ message DynamicMessageType {
+ optional int32 dynamic_field = 2100;
+ }
+
+ optional fixed32 scalar_extension = 2000;
+ optional ForeignEnum enum_extension = 2001;
+ optional DynamicEnumType dynamic_enum_extension = 2002;
+
+ optional ForeignMessage message_extension = 2003;
+ optional DynamicMessageType dynamic_message_extension = 2004;
+
+ repeated string repeated_extension = 2005;
+ repeated sint32 packed_extension = 2006 [packed = true];
+}
+
+message TestRepeatedScalarDifferentTagSizes {
+ // Parsing repeated fixed size values used to fail. This message needs to be
+ // used in order to get a tag of the right size; all of the repeated fields
+ // in TestAllTypes didn't trigger the check.
+ repeated fixed32 repeated_fixed32 = 12;
+ // Check for a varint type, just for good measure.
+ repeated int32 repeated_int32 = 13;
+
+ // These have two-byte tags.
+ repeated fixed64 repeated_fixed64 = 2046;
+ repeated int64 repeated_int64 = 2047;
+
+ // Three byte tags.
+ repeated float repeated_float = 262142;
+ repeated uint64 repeated_uint64 = 262143;
+}
+
+// Test that if an optional or required message/group field appears multiple
+// times in the input, they need to be merged.
+message TestParsingMerge {
+ // RepeatedFieldsGenerator defines matching field types as TestParsingMerge,
+ // except that all fields are repeated. In the tests, we will serialize the
+ // RepeatedFieldsGenerator to bytes, and parse the bytes to TestParsingMerge.
+ // Repeated fields in RepeatedFieldsGenerator are expected to be merged into
+ // the corresponding required/optional fields in TestParsingMerge.
+ message RepeatedFieldsGenerator {
+ repeated TestAllTypes field1 = 1;
+ repeated TestAllTypes field2 = 2;
+ repeated TestAllTypes field3 = 3;
+ repeated group Group1 = 10 {
+ optional TestAllTypes field1 = 11;
+ }
+ repeated group Group2 = 20 {
+ optional TestAllTypes field1 = 21;
+ }
+ repeated TestAllTypes ext1 = 1000;
+ repeated TestAllTypes ext2 = 1001;
+ }
+ required TestAllTypes required_all_types = 1;
+ optional TestAllTypes optional_all_types = 2;
+ repeated TestAllTypes repeated_all_types = 3;
+ optional group OptionalGroup = 10 {
+ optional TestAllTypes optional_group_all_types = 11;
+ }
+ repeated group RepeatedGroup = 20 {
+ optional TestAllTypes repeated_group_all_types = 21;
+ }
+ extensions 1000 to max;
+ extend TestParsingMerge {
+ optional TestAllTypes optional_ext = 1000;
+ repeated TestAllTypes repeated_ext = 1001;
+ }
+}
+
+message TestCommentInjectionMessage {
+ // */ <- This should not close the generated doc comment
+ optional string a = 1 [default="*/ <- Neither should this."];
+}
+
+
+// Test that RPC services work.
+message FooRequest {}
+message FooResponse {}
+
+message FooClientMessage {}
+message FooServerMessage{}
+
+service TestService {
+ rpc Foo(FooRequest) returns (FooResponse);
+ rpc Bar(BarRequest) returns (BarResponse);
+}
+
+
+message BarRequest {}
+message BarResponse {}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_custom_options.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_custom_options.proto
new file mode 100644
index 0000000000..e591d29447
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_custom_options.proto
@@ -0,0 +1,387 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: benjy@google.com (Benjy Weinberger)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file used to test the "custom options" feature of proto2.
+
+
+// Some generic_services option(s) added automatically.
+// See: http://go/proto2-generic-services-default
+option cc_generic_services = true; // auto-added
+option java_generic_services = true; // auto-added
+option py_generic_services = true;
+
+// A custom file option (defined below).
+option (file_opt1) = 9876543210;
+
+import "google/protobuf/descriptor.proto";
+
+// We don't put this in a package within proto2 because we need to make sure
+// that the generated code doesn't depend on being in the proto2 namespace.
+package protobuf_unittest;
+
+
+// Some simple test custom options of various types.
+
+extend google.protobuf.FileOptions {
+ optional uint64 file_opt1 = 7736974;
+}
+
+extend google.protobuf.MessageOptions {
+ optional int32 message_opt1 = 7739036;
+}
+
+extend google.protobuf.FieldOptions {
+ optional fixed64 field_opt1 = 7740936;
+ // This is useful for testing that we correctly register default values for
+ // extension options.
+ optional int32 field_opt2 = 7753913 [default=42];
+}
+
+extend google.protobuf.EnumOptions {
+ optional sfixed32 enum_opt1 = 7753576;
+}
+
+extend google.protobuf.EnumValueOptions {
+ optional int32 enum_value_opt1 = 1560678;
+}
+
+extend google.protobuf.ServiceOptions {
+ optional sint64 service_opt1 = 7887650;
+}
+
+enum MethodOpt1 {
+ METHODOPT1_VAL1 = 1;
+ METHODOPT1_VAL2 = 2;
+}
+
+extend google.protobuf.MethodOptions {
+ optional MethodOpt1 method_opt1 = 7890860;
+}
+
+// A test message with custom options at all possible locations (and also some
+// regular options, to make sure they interact nicely).
+message TestMessageWithCustomOptions {
+ option message_set_wire_format = false;
+
+ option (message_opt1) = -56;
+
+ optional string field1 = 1 [ctype=CORD,
+ (field_opt1)=8765432109];
+
+ enum AnEnum {
+ option (enum_opt1) = -789;
+
+ ANENUM_VAL1 = 1;
+ ANENUM_VAL2 = 2 [(enum_value_opt1) = 123];
+ }
+}
+
+
+// A test RPC service with custom options at all possible locations (and also
+// some regular options, to make sure they interact nicely).
+message CustomOptionFooRequest {
+}
+
+message CustomOptionFooResponse {
+}
+
+message CustomOptionFooClientMessage {
+}
+
+message CustomOptionFooServerMessage {
+}
+
+service TestServiceWithCustomOptions {
+ option (service_opt1) = -9876543210;
+
+ rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
+ option (method_opt1) = METHODOPT1_VAL2;
+ }
+}
+
+
+
+// Options of every possible field type, so we can test them all exhaustively.
+
+message DummyMessageContainingEnum {
+ enum TestEnumType {
+ TEST_OPTION_ENUM_TYPE1 = 22;
+ TEST_OPTION_ENUM_TYPE2 = -23;
+ }
+}
+
+message DummyMessageInvalidAsOptionType {
+}
+
+extend google.protobuf.MessageOptions {
+ optional bool bool_opt = 7706090;
+ optional int32 int32_opt = 7705709;
+ optional int64 int64_opt = 7705542;
+ optional uint32 uint32_opt = 7704880;
+ optional uint64 uint64_opt = 7702367;
+ optional sint32 sint32_opt = 7701568;
+ optional sint64 sint64_opt = 7700863;
+ optional fixed32 fixed32_opt = 7700307;
+ optional fixed64 fixed64_opt = 7700194;
+ optional sfixed32 sfixed32_opt = 7698645;
+ optional sfixed64 sfixed64_opt = 7685475;
+ optional float float_opt = 7675390;
+ optional double double_opt = 7673293;
+ optional string string_opt = 7673285;
+ optional bytes bytes_opt = 7673238;
+ optional DummyMessageContainingEnum.TestEnumType enum_opt = 7673233;
+ optional DummyMessageInvalidAsOptionType message_type_opt = 7665967;
+}
+
+message CustomOptionMinIntegerValues {
+ option (bool_opt) = false;
+ option (int32_opt) = -0x80000000;
+ option (int64_opt) = -0x8000000000000000;
+ option (uint32_opt) = 0;
+ option (uint64_opt) = 0;
+ option (sint32_opt) = -0x80000000;
+ option (sint64_opt) = -0x8000000000000000;
+ option (fixed32_opt) = 0;
+ option (fixed64_opt) = 0;
+ option (sfixed32_opt) = -0x80000000;
+ option (sfixed64_opt) = -0x8000000000000000;
+}
+
+message CustomOptionMaxIntegerValues {
+ option (bool_opt) = true;
+ option (int32_opt) = 0x7FFFFFFF;
+ option (int64_opt) = 0x7FFFFFFFFFFFFFFF;
+ option (uint32_opt) = 0xFFFFFFFF;
+ option (uint64_opt) = 0xFFFFFFFFFFFFFFFF;
+ option (sint32_opt) = 0x7FFFFFFF;
+ option (sint64_opt) = 0x7FFFFFFFFFFFFFFF;
+ option (fixed32_opt) = 0xFFFFFFFF;
+ option (fixed64_opt) = 0xFFFFFFFFFFFFFFFF;
+ option (sfixed32_opt) = 0x7FFFFFFF;
+ option (sfixed64_opt) = 0x7FFFFFFFFFFFFFFF;
+}
+
+message CustomOptionOtherValues {
+ option (int32_opt) = -100; // To test sign-extension.
+ option (float_opt) = 12.3456789;
+ option (double_opt) = 1.234567890123456789;
+ option (string_opt) = "Hello, \"World\"";
+ option (bytes_opt) = "Hello\0World";
+ option (enum_opt) = TEST_OPTION_ENUM_TYPE2;
+}
+
+message SettingRealsFromPositiveInts {
+ option (float_opt) = 12;
+ option (double_opt) = 154;
+}
+
+message SettingRealsFromNegativeInts {
+ option (float_opt) = -12;
+ option (double_opt) = -154;
+}
+
+// Options of complex message types, themselves combined and extended in
+// various ways.
+
+message ComplexOptionType1 {
+ optional int32 foo = 1;
+ optional int32 foo2 = 2;
+ optional int32 foo3 = 3;
+
+ extensions 100 to max;
+}
+
+message ComplexOptionType2 {
+ optional ComplexOptionType1 bar = 1;
+ optional int32 baz = 2;
+
+ message ComplexOptionType4 {
+ optional int32 waldo = 1;
+
+ extend google.protobuf.MessageOptions {
+ optional ComplexOptionType4 complex_opt4 = 7633546;
+ }
+ }
+
+ optional ComplexOptionType4 fred = 3;
+
+ extensions 100 to max;
+}
+
+message ComplexOptionType3 {
+ optional int32 qux = 1;
+
+ optional group ComplexOptionType5 = 2 {
+ optional int32 plugh = 3;
+ }
+}
+
+extend ComplexOptionType1 {
+ optional int32 quux = 7663707;
+ optional ComplexOptionType3 corge = 7663442;
+}
+
+extend ComplexOptionType2 {
+ optional int32 grault = 7650927;
+ optional ComplexOptionType1 garply = 7649992;
+}
+
+extend google.protobuf.MessageOptions {
+ optional protobuf_unittest.ComplexOptionType1 complex_opt1 = 7646756;
+ optional ComplexOptionType2 complex_opt2 = 7636949;
+ optional ComplexOptionType3 complex_opt3 = 7636463;
+ optional group ComplexOpt6 = 7595468 {
+ optional int32 xyzzy = 7593951;
+ }
+}
+
+// Note that we try various different ways of naming the same extension.
+message VariousComplexOptions {
+ option (.protobuf_unittest.complex_opt1).foo = 42;
+ option (protobuf_unittest.complex_opt1).(.protobuf_unittest.quux) = 324;
+ option (.protobuf_unittest.complex_opt1).(protobuf_unittest.corge).qux = 876;
+ option (complex_opt2).baz = 987;
+ option (complex_opt2).(grault) = 654;
+ option (complex_opt2).bar.foo = 743;
+ option (complex_opt2).bar.(quux) = 1999;
+ option (complex_opt2).bar.(protobuf_unittest.corge).qux = 2008;
+ option (complex_opt2).(garply).foo = 741;
+ option (complex_opt2).(garply).(.protobuf_unittest.quux) = 1998;
+ option (complex_opt2).(protobuf_unittest.garply).(corge).qux = 2121;
+ option (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo = 1971;
+ option (complex_opt2).fred.waldo = 321;
+ option (protobuf_unittest.complex_opt3).qux = 9;
+ option (complex_opt3).complexoptiontype5.plugh = 22;
+ option (complexopt6).xyzzy = 24;
+}
+
+// ------------------------------------------------------
+// Definitions for testing aggregate option parsing.
+// See descriptor_unittest.cc.
+
+message AggregateMessageSet {
+ option message_set_wire_format = true;
+ extensions 4 to max;
+}
+
+message AggregateMessageSetElement {
+ extend AggregateMessageSet {
+ optional AggregateMessageSetElement message_set_extension = 15447542;
+ }
+ optional string s = 1;
+}
+
+// A helper type used to test aggregate option parsing
+message Aggregate {
+ optional int32 i = 1;
+ optional string s = 2;
+
+ // A nested object
+ optional Aggregate sub = 3;
+
+ // To test the parsing of extensions inside aggregate values
+ optional google.protobuf.FileOptions file = 4;
+ extend google.protobuf.FileOptions {
+ optional Aggregate nested = 15476903;
+ }
+
+ // An embedded message set
+ optional AggregateMessageSet mset = 5;
+}
+
+// Allow Aggregate to be used as an option at all possible locations
+// in the .proto grammer.
+extend google.protobuf.FileOptions { optional Aggregate fileopt = 15478479; }
+extend google.protobuf.MessageOptions { optional Aggregate msgopt = 15480088; }
+extend google.protobuf.FieldOptions { optional Aggregate fieldopt = 15481374; }
+extend google.protobuf.EnumOptions { optional Aggregate enumopt = 15483218; }
+extend google.protobuf.EnumValueOptions { optional Aggregate enumvalopt = 15486921; }
+extend google.protobuf.ServiceOptions { optional Aggregate serviceopt = 15497145; }
+extend google.protobuf.MethodOptions { optional Aggregate methodopt = 15512713; }
+
+// Try using AggregateOption at different points in the proto grammar
+option (fileopt) = {
+ s: 'FileAnnotation'
+ // Also test the handling of comments
+ /* of both types */ i: 100
+
+ sub { s: 'NestedFileAnnotation' }
+
+ // Include a google.protobuf.FileOptions and recursively extend it with
+ // another fileopt.
+ file {
+ [protobuf_unittest.fileopt] {
+ s:'FileExtensionAnnotation'
+ }
+ }
+
+ // A message set inside an option value
+ mset {
+ [protobuf_unittest.AggregateMessageSetElement.message_set_extension] {
+ s: 'EmbeddedMessageSetElement'
+ }
+ }
+};
+
+message AggregateMessage {
+ option (msgopt) = { i:101 s:'MessageAnnotation' };
+ optional int32 fieldname = 1 [(fieldopt) = { s:'FieldAnnotation' }];
+}
+
+service AggregateService {
+ option (serviceopt) = { s:'ServiceAnnotation' };
+ rpc Method (AggregateMessage) returns (AggregateMessage) {
+ option (methodopt) = { s:'MethodAnnotation' };
+ }
+}
+
+enum AggregateEnum {
+ option (enumopt) = { s:'EnumAnnotation' };
+ VALUE = 1 [(enumvalopt) = { s:'EnumValueAnnotation' }];
+}
+
+// Test custom options for nested type.
+message NestedOptionType {
+ message NestedMessage {
+ option (message_opt1) = 1001;
+ optional int32 nested_field = 1 [(field_opt1) = 1002];
+ }
+ enum NestedEnum {
+ option (enum_opt1) = 1003;
+ NESTED_ENUM_VALUE = 1 [(enum_value_opt1) = 1004];
+ }
+ extend google.protobuf.FileOptions {
+ optional int32 nested_extension = 7912573 [(field_opt2) = 1005];
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_embed_optimize_for.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_embed_optimize_for.proto
new file mode 100644
index 0000000000..fa1762594e
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_embed_optimize_for.proto
@@ -0,0 +1,50 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file which imports a proto file that uses optimize_for = CODE_SIZE.
+
+import "google/protobuf/unittest_optimize_for.proto";
+
+package protobuf_unittest;
+
+// We optimize for speed here, but we are importing a proto that is optimized
+// for code size.
+option optimize_for = SPEED;
+
+message TestEmbedOptimizedForSize {
+ // Test that embedding a message which has optimize_for = CODE_SIZE into
+ // one optimized for speed works.
+ optional TestOptimizedForSize optional_message = 1;
+ repeated TestOptimizedForSize repeated_message = 2;
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_empty.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_empty.proto
new file mode 100644
index 0000000000..ab12d1fb9f
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_empty.proto
@@ -0,0 +1,37 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// This file intentionally left blank. (At one point this wouldn't compile
+// correctly.)
+
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_enormous_descriptor.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_enormous_descriptor.proto
new file mode 100644
index 0000000000..bc0b7c16a0
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_enormous_descriptor.proto
@@ -0,0 +1,1046 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file that has an extremely large descriptor. Used to test that
+// descriptors over 64k don't break the string literal length limit in Java.
+
+
+package google.protobuf;
+option java_package = "com.google.protobuf";
+
+// Avoid generating insanely long methods.
+option optimize_for = CODE_SIZE;
+
+message TestEnormousDescriptor {
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_1 = 1 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_2 = 2 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_3 = 3 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_4 = 4 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_5 = 5 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_6 = 6 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_7 = 7 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_8 = 8 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_9 = 9 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_10 = 10 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_11 = 11 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_12 = 12 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_13 = 13 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_14 = 14 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_15 = 15 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_16 = 16 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_17 = 17 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_18 = 18 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_19 = 19 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_20 = 20 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_21 = 21 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_22 = 22 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_23 = 23 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_24 = 24 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_25 = 25 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_26 = 26 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_27 = 27 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_28 = 28 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_29 = 29 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_30 = 30 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_31 = 31 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_32 = 32 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_33 = 33 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_34 = 34 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_35 = 35 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_36 = 36 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_37 = 37 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_38 = 38 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_39 = 39 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_40 = 40 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_41 = 41 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_42 = 42 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_43 = 43 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_44 = 44 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_45 = 45 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_46 = 46 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_47 = 47 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_48 = 48 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_49 = 49 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_50 = 50 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_51 = 51 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_52 = 52 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_53 = 53 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_54 = 54 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_55 = 55 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_56 = 56 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_57 = 57 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_58 = 58 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_59 = 59 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_60 = 60 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_61 = 61 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_62 = 62 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_63 = 63 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_64 = 64 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_65 = 65 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_66 = 66 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_67 = 67 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_68 = 68 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_69 = 69 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_70 = 70 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_71 = 71 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_72 = 72 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_73 = 73 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_74 = 74 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_75 = 75 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_76 = 76 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_77 = 77 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_78 = 78 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_79 = 79 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_80 = 80 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_81 = 81 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_82 = 82 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_83 = 83 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_84 = 84 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_85 = 85 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_86 = 86 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_87 = 87 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_88 = 88 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_89 = 89 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_90 = 90 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_91 = 91 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_92 = 92 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_93 = 93 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_94 = 94 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_95 = 95 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_96 = 96 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_97 = 97 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_98 = 98 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_99 = 99 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_100 = 100 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_101 = 101 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_102 = 102 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_103 = 103 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_104 = 104 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_105 = 105 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_106 = 106 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_107 = 107 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_108 = 108 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_109 = 109 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_110 = 110 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_111 = 111 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_112 = 112 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_113 = 113 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_114 = 114 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_115 = 115 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_116 = 116 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_117 = 117 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_118 = 118 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_119 = 119 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_120 = 120 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_121 = 121 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_122 = 122 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_123 = 123 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_124 = 124 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_125 = 125 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_126 = 126 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_127 = 127 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_128 = 128 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_129 = 129 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_130 = 130 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_131 = 131 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_132 = 132 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_133 = 133 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_134 = 134 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_135 = 135 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_136 = 136 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_137 = 137 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_138 = 138 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_139 = 139 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_140 = 140 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_141 = 141 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_142 = 142 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_143 = 143 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_144 = 144 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_145 = 145 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_146 = 146 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_147 = 147 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_148 = 148 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_149 = 149 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_150 = 150 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_151 = 151 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_152 = 152 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_153 = 153 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_154 = 154 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_155 = 155 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_156 = 156 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_157 = 157 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_158 = 158 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_159 = 159 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_160 = 160 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_161 = 161 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_162 = 162 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_163 = 163 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_164 = 164 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_165 = 165 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_166 = 166 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_167 = 167 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_168 = 168 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_169 = 169 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_170 = 170 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_171 = 171 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_172 = 172 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_173 = 173 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_174 = 174 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_175 = 175 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_176 = 176 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_177 = 177 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_178 = 178 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_179 = 179 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_180 = 180 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_181 = 181 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_182 = 182 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_183 = 183 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_184 = 184 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_185 = 185 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_186 = 186 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_187 = 187 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_188 = 188 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_189 = 189 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_190 = 190 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_191 = 191 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_192 = 192 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_193 = 193 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_194 = 194 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_195 = 195 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_196 = 196 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_197 = 197 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_198 = 198 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_199 = 199 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_200 = 200 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_201 = 201 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_202 = 202 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_203 = 203 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_204 = 204 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_205 = 205 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_206 = 206 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_207 = 207 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_208 = 208 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_209 = 209 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_210 = 210 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_211 = 211 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_212 = 212 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_213 = 213 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_214 = 214 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_215 = 215 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_216 = 216 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_217 = 217 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_218 = 218 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_219 = 219 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_220 = 220 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_221 = 221 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_222 = 222 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_223 = 223 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_224 = 224 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_225 = 225 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_226 = 226 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_227 = 227 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_228 = 228 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_229 = 229 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_230 = 230 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_231 = 231 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_232 = 232 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_233 = 233 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_234 = 234 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_235 = 235 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_236 = 236 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_237 = 237 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_238 = 238 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_239 = 239 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_240 = 240 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_241 = 241 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_242 = 242 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_243 = 243 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_244 = 244 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_245 = 245 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_246 = 246 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_247 = 247 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_248 = 248 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_249 = 249 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_250 = 250 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_251 = 251 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_252 = 252 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_253 = 253 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_254 = 254 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_255 = 255 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_256 = 256 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_257 = 257 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_258 = 258 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_259 = 259 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_260 = 260 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_261 = 261 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_262 = 262 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_263 = 263 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_264 = 264 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_265 = 265 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_266 = 266 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_267 = 267 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_268 = 268 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_269 = 269 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_270 = 270 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_271 = 271 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_272 = 272 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_273 = 273 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_274 = 274 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_275 = 275 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_276 = 276 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_277 = 277 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_278 = 278 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_279 = 279 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_280 = 280 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_281 = 281 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_282 = 282 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_283 = 283 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_284 = 284 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_285 = 285 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_286 = 286 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_287 = 287 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_288 = 288 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_289 = 289 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_290 = 290 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_291 = 291 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_292 = 292 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_293 = 293 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_294 = 294 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_295 = 295 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_296 = 296 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_297 = 297 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_298 = 298 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_299 = 299 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_300 = 300 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_301 = 301 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_302 = 302 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_303 = 303 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_304 = 304 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_305 = 305 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_306 = 306 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_307 = 307 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_308 = 308 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_309 = 309 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_310 = 310 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_311 = 311 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_312 = 312 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_313 = 313 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_314 = 314 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_315 = 315 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_316 = 316 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_317 = 317 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_318 = 318 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_319 = 319 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_320 = 320 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_321 = 321 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_322 = 322 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_323 = 323 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_324 = 324 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_325 = 325 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_326 = 326 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_327 = 327 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_328 = 328 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_329 = 329 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_330 = 330 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_331 = 331 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_332 = 332 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_333 = 333 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_334 = 334 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_335 = 335 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_336 = 336 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_337 = 337 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_338 = 338 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_339 = 339 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_340 = 340 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_341 = 341 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_342 = 342 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_343 = 343 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_344 = 344 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_345 = 345 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_346 = 346 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_347 = 347 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_348 = 348 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_349 = 349 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_350 = 350 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_351 = 351 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_352 = 352 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_353 = 353 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_354 = 354 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_355 = 355 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_356 = 356 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_357 = 357 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_358 = 358 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_359 = 359 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_360 = 360 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_361 = 361 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_362 = 362 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_363 = 363 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_364 = 364 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_365 = 365 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_366 = 366 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_367 = 367 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_368 = 368 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_369 = 369 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_370 = 370 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_371 = 371 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_372 = 372 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_373 = 373 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_374 = 374 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_375 = 375 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_376 = 376 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_377 = 377 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_378 = 378 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_379 = 379 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_380 = 380 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_381 = 381 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_382 = 382 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_383 = 383 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_384 = 384 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_385 = 385 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_386 = 386 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_387 = 387 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_388 = 388 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_389 = 389 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_390 = 390 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_391 = 391 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_392 = 392 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_393 = 393 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_394 = 394 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_395 = 395 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_396 = 396 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_397 = 397 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_398 = 398 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_399 = 399 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_400 = 400 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_401 = 401 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_402 = 402 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_403 = 403 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_404 = 404 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_405 = 405 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_406 = 406 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_407 = 407 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_408 = 408 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_409 = 409 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_410 = 410 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_411 = 411 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_412 = 412 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_413 = 413 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_414 = 414 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_415 = 415 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_416 = 416 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_417 = 417 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_418 = 418 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_419 = 419 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_420 = 420 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_421 = 421 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_422 = 422 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_423 = 423 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_424 = 424 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_425 = 425 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_426 = 426 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_427 = 427 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_428 = 428 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_429 = 429 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_430 = 430 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_431 = 431 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_432 = 432 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_433 = 433 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_434 = 434 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_435 = 435 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_436 = 436 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_437 = 437 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_438 = 438 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_439 = 439 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_440 = 440 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_441 = 441 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_442 = 442 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_443 = 443 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_444 = 444 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_445 = 445 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_446 = 446 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_447 = 447 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_448 = 448 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_449 = 449 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_450 = 450 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_451 = 451 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_452 = 452 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_453 = 453 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_454 = 454 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_455 = 455 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_456 = 456 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_457 = 457 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_458 = 458 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_459 = 459 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_460 = 460 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_461 = 461 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_462 = 462 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_463 = 463 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_464 = 464 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_465 = 465 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_466 = 466 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_467 = 467 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_468 = 468 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_469 = 469 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_470 = 470 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_471 = 471 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_472 = 472 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_473 = 473 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_474 = 474 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_475 = 475 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_476 = 476 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_477 = 477 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_478 = 478 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_479 = 479 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_480 = 480 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_481 = 481 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_482 = 482 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_483 = 483 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_484 = 484 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_485 = 485 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_486 = 486 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_487 = 487 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_488 = 488 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_489 = 489 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_490 = 490 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_491 = 491 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_492 = 492 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_493 = 493 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_494 = 494 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_495 = 495 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_496 = 496 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_497 = 497 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_498 = 498 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_499 = 499 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_500 = 500 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_501 = 501 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_502 = 502 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_503 = 503 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_504 = 504 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_505 = 505 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_506 = 506 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_507 = 507 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_508 = 508 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_509 = 509 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_510 = 510 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_511 = 511 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_512 = 512 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_513 = 513 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_514 = 514 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_515 = 515 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_516 = 516 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_517 = 517 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_518 = 518 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_519 = 519 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_520 = 520 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_521 = 521 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_522 = 522 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_523 = 523 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_524 = 524 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_525 = 525 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_526 = 526 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_527 = 527 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_528 = 528 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_529 = 529 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_530 = 530 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_531 = 531 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_532 = 532 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_533 = 533 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_534 = 534 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_535 = 535 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_536 = 536 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_537 = 537 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_538 = 538 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_539 = 539 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_540 = 540 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_541 = 541 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_542 = 542 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_543 = 543 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_544 = 544 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_545 = 545 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_546 = 546 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_547 = 547 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_548 = 548 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_549 = 549 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_550 = 550 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_551 = 551 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_552 = 552 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_553 = 553 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_554 = 554 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_555 = 555 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_556 = 556 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_557 = 557 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_558 = 558 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_559 = 559 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_560 = 560 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_561 = 561 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_562 = 562 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_563 = 563 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_564 = 564 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_565 = 565 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_566 = 566 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_567 = 567 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_568 = 568 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_569 = 569 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_570 = 570 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_571 = 571 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_572 = 572 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_573 = 573 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_574 = 574 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_575 = 575 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_576 = 576 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_577 = 577 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_578 = 578 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_579 = 579 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_580 = 580 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_581 = 581 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_582 = 582 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_583 = 583 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_584 = 584 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_585 = 585 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_586 = 586 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_587 = 587 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_588 = 588 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_589 = 589 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_590 = 590 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_591 = 591 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_592 = 592 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_593 = 593 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_594 = 594 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_595 = 595 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_596 = 596 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_597 = 597 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_598 = 598 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_599 = 599 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_600 = 600 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_601 = 601 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_602 = 602 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_603 = 603 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_604 = 604 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_605 = 605 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_606 = 606 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_607 = 607 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_608 = 608 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_609 = 609 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_610 = 610 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_611 = 611 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_612 = 612 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_613 = 613 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_614 = 614 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_615 = 615 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_616 = 616 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_617 = 617 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_618 = 618 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_619 = 619 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_620 = 620 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_621 = 621 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_622 = 622 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_623 = 623 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_624 = 624 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_625 = 625 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_626 = 626 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_627 = 627 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_628 = 628 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_629 = 629 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_630 = 630 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_631 = 631 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_632 = 632 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_633 = 633 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_634 = 634 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_635 = 635 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_636 = 636 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_637 = 637 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_638 = 638 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_639 = 639 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_640 = 640 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_641 = 641 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_642 = 642 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_643 = 643 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_644 = 644 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_645 = 645 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_646 = 646 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_647 = 647 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_648 = 648 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_649 = 649 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_650 = 650 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_651 = 651 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_652 = 652 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_653 = 653 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_654 = 654 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_655 = 655 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_656 = 656 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_657 = 657 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_658 = 658 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_659 = 659 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_660 = 660 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_661 = 661 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_662 = 662 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_663 = 663 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_664 = 664 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_665 = 665 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_666 = 666 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_667 = 667 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_668 = 668 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_669 = 669 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_670 = 670 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_671 = 671 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_672 = 672 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_673 = 673 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_674 = 674 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_675 = 675 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_676 = 676 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_677 = 677 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_678 = 678 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_679 = 679 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_680 = 680 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_681 = 681 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_682 = 682 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_683 = 683 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_684 = 684 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_685 = 685 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_686 = 686 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_687 = 687 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_688 = 688 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_689 = 689 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_690 = 690 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_691 = 691 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_692 = 692 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_693 = 693 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_694 = 694 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_695 = 695 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_696 = 696 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_697 = 697 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_698 = 698 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_699 = 699 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_700 = 700 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_701 = 701 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_702 = 702 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_703 = 703 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_704 = 704 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_705 = 705 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_706 = 706 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_707 = 707 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_708 = 708 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_709 = 709 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_710 = 710 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_711 = 711 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_712 = 712 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_713 = 713 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_714 = 714 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_715 = 715 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_716 = 716 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_717 = 717 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_718 = 718 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_719 = 719 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_720 = 720 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_721 = 721 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_722 = 722 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_723 = 723 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_724 = 724 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_725 = 725 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_726 = 726 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_727 = 727 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_728 = 728 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_729 = 729 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_730 = 730 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_731 = 731 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_732 = 732 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_733 = 733 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_734 = 734 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_735 = 735 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_736 = 736 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_737 = 737 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_738 = 738 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_739 = 739 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_740 = 740 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_741 = 741 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_742 = 742 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_743 = 743 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_744 = 744 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_745 = 745 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_746 = 746 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_747 = 747 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_748 = 748 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_749 = 749 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_750 = 750 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_751 = 751 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_752 = 752 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_753 = 753 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_754 = 754 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_755 = 755 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_756 = 756 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_757 = 757 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_758 = 758 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_759 = 759 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_760 = 760 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_761 = 761 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_762 = 762 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_763 = 763 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_764 = 764 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_765 = 765 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_766 = 766 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_767 = 767 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_768 = 768 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_769 = 769 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_770 = 770 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_771 = 771 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_772 = 772 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_773 = 773 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_774 = 774 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_775 = 775 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_776 = 776 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_777 = 777 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_778 = 778 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_779 = 779 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_780 = 780 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_781 = 781 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_782 = 782 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_783 = 783 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_784 = 784 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_785 = 785 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_786 = 786 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_787 = 787 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_788 = 788 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_789 = 789 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_790 = 790 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_791 = 791 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_792 = 792 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_793 = 793 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_794 = 794 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_795 = 795 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_796 = 796 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_797 = 797 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_798 = 798 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_799 = 799 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_800 = 800 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_801 = 801 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_802 = 802 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_803 = 803 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_804 = 804 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_805 = 805 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_806 = 806 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_807 = 807 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_808 = 808 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_809 = 809 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_810 = 810 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_811 = 811 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_812 = 812 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_813 = 813 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_814 = 814 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_815 = 815 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_816 = 816 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_817 = 817 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_818 = 818 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_819 = 819 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_820 = 820 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_821 = 821 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_822 = 822 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_823 = 823 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_824 = 824 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_825 = 825 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_826 = 826 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_827 = 827 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_828 = 828 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_829 = 829 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_830 = 830 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_831 = 831 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_832 = 832 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_833 = 833 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_834 = 834 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_835 = 835 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_836 = 836 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_837 = 837 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_838 = 838 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_839 = 839 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_840 = 840 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_841 = 841 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_842 = 842 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_843 = 843 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_844 = 844 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_845 = 845 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_846 = 846 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_847 = 847 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_848 = 848 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_849 = 849 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_850 = 850 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_851 = 851 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_852 = 852 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_853 = 853 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_854 = 854 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_855 = 855 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_856 = 856 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_857 = 857 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_858 = 858 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_859 = 859 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_860 = 860 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_861 = 861 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_862 = 862 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_863 = 863 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_864 = 864 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_865 = 865 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_866 = 866 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_867 = 867 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_868 = 868 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_869 = 869 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_870 = 870 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_871 = 871 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_872 = 872 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_873 = 873 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_874 = 874 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_875 = 875 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_876 = 876 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_877 = 877 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_878 = 878 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_879 = 879 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_880 = 880 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_881 = 881 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_882 = 882 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_883 = 883 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_884 = 884 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_885 = 885 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_886 = 886 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_887 = 887 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_888 = 888 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_889 = 889 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_890 = 890 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_891 = 891 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_892 = 892 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_893 = 893 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_894 = 894 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_895 = 895 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_896 = 896 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_897 = 897 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_898 = 898 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_899 = 899 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_900 = 900 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_901 = 901 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_902 = 902 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_903 = 903 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_904 = 904 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_905 = 905 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_906 = 906 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_907 = 907 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_908 = 908 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_909 = 909 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_910 = 910 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_911 = 911 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_912 = 912 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_913 = 913 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_914 = 914 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_915 = 915 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_916 = 916 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_917 = 917 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_918 = 918 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_919 = 919 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_920 = 920 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_921 = 921 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_922 = 922 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_923 = 923 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_924 = 924 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_925 = 925 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_926 = 926 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_927 = 927 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_928 = 928 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_929 = 929 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_930 = 930 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_931 = 931 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_932 = 932 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_933 = 933 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_934 = 934 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_935 = 935 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_936 = 936 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_937 = 937 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_938 = 938 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_939 = 939 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_940 = 940 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_941 = 941 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_942 = 942 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_943 = 943 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_944 = 944 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_945 = 945 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_946 = 946 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_947 = 947 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_948 = 948 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_949 = 949 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_950 = 950 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_951 = 951 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_952 = 952 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_953 = 953 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_954 = 954 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_955 = 955 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_956 = 956 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_957 = 957 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_958 = 958 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_959 = 959 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_960 = 960 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_961 = 961 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_962 = 962 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_963 = 963 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_964 = 964 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_965 = 965 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_966 = 966 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_967 = 967 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_968 = 968 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_969 = 969 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_970 = 970 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_971 = 971 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_972 = 972 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_973 = 973 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_974 = 974 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_975 = 975 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_976 = 976 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_977 = 977 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_978 = 978 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_979 = 979 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_980 = 980 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_981 = 981 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_982 = 982 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_983 = 983 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_984 = 984 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_985 = 985 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_986 = 986 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_987 = 987 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_988 = 988 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_989 = 989 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_990 = 990 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_991 = 991 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_992 = 992 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_993 = 993 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_994 = 994 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_995 = 995 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_996 = 996 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_997 = 997 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_998 = 998 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_999 = 999 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_1000 = 1000 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_import.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_import.proto
new file mode 100644
index 0000000000..c115b11171
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_import.proto
@@ -0,0 +1,64 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file which is imported by unittest.proto to test importing.
+
+
+// We don't put this in a package within proto2 because we need to make sure
+// that the generated code doesn't depend on being in the proto2 namespace.
+// In test_util.h we do
+// "using namespace unittest_import = protobuf_unittest_import".
+package protobuf_unittest_import;
+
+option optimize_for = SPEED;
+
+// Excercise the java_package option.
+option java_package = "com.google.protobuf.test";
+
+// Do not set a java_outer_classname here to verify that Proto2 works without
+// one.
+
+// Test public import
+import public "google/protobuf/unittest_import_public.proto";
+
+message ImportMessage {
+ optional int32 d = 1;
+}
+
+enum ImportEnum {
+ IMPORT_FOO = 7;
+ IMPORT_BAR = 8;
+ IMPORT_BAZ = 9;
+}
+
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_import_lite.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_import_lite.proto
new file mode 100644
index 0000000000..81b117fe84
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_import_lite.proto
@@ -0,0 +1,51 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+//
+// This is like unittest_import.proto but with optimize_for = LITE_RUNTIME.
+
+package protobuf_unittest_import;
+
+option optimize_for = LITE_RUNTIME;
+
+option java_package = "com.google.protobuf";
+
+import public "google/protobuf/unittest_import_public_lite.proto";
+
+message ImportMessageLite {
+ optional int32 d = 1;
+}
+
+enum ImportEnumLite {
+ IMPORT_LITE_FOO = 7;
+ IMPORT_LITE_BAR = 8;
+ IMPORT_LITE_BAZ = 9;
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_import_public.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_import_public.proto
new file mode 100644
index 0000000000..ea5d1b13fe
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_import_public.proto
@@ -0,0 +1,40 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: liujisi@google.com (Pherl Liu)
+
+
+package protobuf_unittest_import;
+
+option java_package = "com.google.protobuf.test";
+
+message PublicImportMessage {
+ optional int32 e = 1;
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_import_public_lite.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_import_public_lite.proto
new file mode 100644
index 0000000000..d077563cbd
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_import_public_lite.proto
@@ -0,0 +1,42 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: liujisi@google.com (Pherl Liu)
+
+
+package protobuf_unittest_import;
+
+option optimize_for = LITE_RUNTIME;
+
+option java_package = "com.google.protobuf";
+
+message PublicImportMessageLite {
+ optional int32 e = 1;
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_lite.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_lite.proto
new file mode 100644
index 0000000000..a1764aac8d
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_lite.proto
@@ -0,0 +1,360 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+//
+// This is like unittest.proto but with optimize_for = LITE_RUNTIME.
+
+package protobuf_unittest;
+
+import "google/protobuf/unittest_import_lite.proto";
+
+option optimize_for = LITE_RUNTIME;
+
+option java_package = "com.google.protobuf";
+
+// Same as TestAllTypes but with the lite runtime.
+message TestAllTypesLite {
+ message NestedMessage {
+ optional int32 bb = 1;
+ }
+
+ enum NestedEnum {
+ FOO = 1;
+ BAR = 2;
+ BAZ = 3;
+ }
+
+ // Singular
+ optional int32 optional_int32 = 1;
+ optional int64 optional_int64 = 2;
+ optional uint32 optional_uint32 = 3;
+ optional uint64 optional_uint64 = 4;
+ optional sint32 optional_sint32 = 5;
+ optional sint64 optional_sint64 = 6;
+ optional fixed32 optional_fixed32 = 7;
+ optional fixed64 optional_fixed64 = 8;
+ optional sfixed32 optional_sfixed32 = 9;
+ optional sfixed64 optional_sfixed64 = 10;
+ optional float optional_float = 11;
+ optional double optional_double = 12;
+ optional bool optional_bool = 13;
+ optional string optional_string = 14;
+ optional bytes optional_bytes = 15;
+
+ optional group OptionalGroup = 16 {
+ optional int32 a = 17;
+ }
+
+ optional NestedMessage optional_nested_message = 18;
+ optional ForeignMessageLite optional_foreign_message = 19;
+ optional protobuf_unittest_import.ImportMessageLite
+ optional_import_message = 20;
+
+ optional NestedEnum optional_nested_enum = 21;
+ optional ForeignEnumLite optional_foreign_enum = 22;
+ optional protobuf_unittest_import.ImportEnumLite optional_import_enum = 23;
+
+ optional string optional_string_piece = 24 [ctype=STRING_PIECE];
+ optional string optional_cord = 25 [ctype=CORD];
+
+ // Defined in unittest_import_public.proto
+ optional protobuf_unittest_import.PublicImportMessageLite
+ optional_public_import_message = 26;
+
+ optional NestedMessage optional_lazy_message = 27 [lazy=true];
+
+ // Repeated
+ repeated int32 repeated_int32 = 31;
+ repeated int64 repeated_int64 = 32;
+ repeated uint32 repeated_uint32 = 33;
+ repeated uint64 repeated_uint64 = 34;
+ repeated sint32 repeated_sint32 = 35;
+ repeated sint64 repeated_sint64 = 36;
+ repeated fixed32 repeated_fixed32 = 37;
+ repeated fixed64 repeated_fixed64 = 38;
+ repeated sfixed32 repeated_sfixed32 = 39;
+ repeated sfixed64 repeated_sfixed64 = 40;
+ repeated float repeated_float = 41;
+ repeated double repeated_double = 42;
+ repeated bool repeated_bool = 43;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+
+ repeated group RepeatedGroup = 46 {
+ optional int32 a = 47;
+ }
+
+ repeated NestedMessage repeated_nested_message = 48;
+ repeated ForeignMessageLite repeated_foreign_message = 49;
+ repeated protobuf_unittest_import.ImportMessageLite
+ repeated_import_message = 50;
+
+ repeated NestedEnum repeated_nested_enum = 51;
+ repeated ForeignEnumLite repeated_foreign_enum = 52;
+ repeated protobuf_unittest_import.ImportEnumLite repeated_import_enum = 53;
+
+ repeated string repeated_string_piece = 54 [ctype=STRING_PIECE];
+ repeated string repeated_cord = 55 [ctype=CORD];
+
+ repeated NestedMessage repeated_lazy_message = 57 [lazy=true];
+
+ // Singular with defaults
+ optional int32 default_int32 = 61 [default = 41 ];
+ optional int64 default_int64 = 62 [default = 42 ];
+ optional uint32 default_uint32 = 63 [default = 43 ];
+ optional uint64 default_uint64 = 64 [default = 44 ];
+ optional sint32 default_sint32 = 65 [default = -45 ];
+ optional sint64 default_sint64 = 66 [default = 46 ];
+ optional fixed32 default_fixed32 = 67 [default = 47 ];
+ optional fixed64 default_fixed64 = 68 [default = 48 ];
+ optional sfixed32 default_sfixed32 = 69 [default = 49 ];
+ optional sfixed64 default_sfixed64 = 70 [default = -50 ];
+ optional float default_float = 71 [default = 51.5 ];
+ optional double default_double = 72 [default = 52e3 ];
+ optional bool default_bool = 73 [default = true ];
+ optional string default_string = 74 [default = "hello"];
+ optional bytes default_bytes = 75 [default = "world"];
+
+ optional NestedEnum default_nested_enum = 81 [default = BAR];
+ optional ForeignEnumLite default_foreign_enum = 82
+ [default = FOREIGN_LITE_BAR];
+ optional protobuf_unittest_import.ImportEnumLite
+ default_import_enum = 83 [default = IMPORT_LITE_BAR];
+
+ optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"];
+ optional string default_cord = 85 [ctype=CORD,default="123"];
+}
+
+message ForeignMessageLite {
+ optional int32 c = 1;
+}
+
+enum ForeignEnumLite {
+ FOREIGN_LITE_FOO = 4;
+ FOREIGN_LITE_BAR = 5;
+ FOREIGN_LITE_BAZ = 6;
+}
+
+message TestPackedTypesLite {
+ repeated int32 packed_int32 = 90 [packed = true];
+ repeated int64 packed_int64 = 91 [packed = true];
+ repeated uint32 packed_uint32 = 92 [packed = true];
+ repeated uint64 packed_uint64 = 93 [packed = true];
+ repeated sint32 packed_sint32 = 94 [packed = true];
+ repeated sint64 packed_sint64 = 95 [packed = true];
+ repeated fixed32 packed_fixed32 = 96 [packed = true];
+ repeated fixed64 packed_fixed64 = 97 [packed = true];
+ repeated sfixed32 packed_sfixed32 = 98 [packed = true];
+ repeated sfixed64 packed_sfixed64 = 99 [packed = true];
+ repeated float packed_float = 100 [packed = true];
+ repeated double packed_double = 101 [packed = true];
+ repeated bool packed_bool = 102 [packed = true];
+ repeated ForeignEnumLite packed_enum = 103 [packed = true];
+}
+
+message TestAllExtensionsLite {
+ extensions 1 to max;
+}
+
+extend TestAllExtensionsLite {
+ // Singular
+ optional int32 optional_int32_extension_lite = 1;
+ optional int64 optional_int64_extension_lite = 2;
+ optional uint32 optional_uint32_extension_lite = 3;
+ optional uint64 optional_uint64_extension_lite = 4;
+ optional sint32 optional_sint32_extension_lite = 5;
+ optional sint64 optional_sint64_extension_lite = 6;
+ optional fixed32 optional_fixed32_extension_lite = 7;
+ optional fixed64 optional_fixed64_extension_lite = 8;
+ optional sfixed32 optional_sfixed32_extension_lite = 9;
+ optional sfixed64 optional_sfixed64_extension_lite = 10;
+ optional float optional_float_extension_lite = 11;
+ optional double optional_double_extension_lite = 12;
+ optional bool optional_bool_extension_lite = 13;
+ optional string optional_string_extension_lite = 14;
+ optional bytes optional_bytes_extension_lite = 15;
+
+ optional group OptionalGroup_extension_lite = 16 {
+ optional int32 a = 17;
+ }
+
+ optional TestAllTypesLite.NestedMessage optional_nested_message_extension_lite
+ = 18;
+ optional ForeignMessageLite optional_foreign_message_extension_lite = 19;
+ optional protobuf_unittest_import.ImportMessageLite
+ optional_import_message_extension_lite = 20;
+
+ optional TestAllTypesLite.NestedEnum optional_nested_enum_extension_lite = 21;
+ optional ForeignEnumLite optional_foreign_enum_extension_lite = 22;
+ optional protobuf_unittest_import.ImportEnumLite
+ optional_import_enum_extension_lite = 23;
+
+ optional string optional_string_piece_extension_lite = 24
+ [ctype=STRING_PIECE];
+ optional string optional_cord_extension_lite = 25 [ctype=CORD];
+
+ optional protobuf_unittest_import.PublicImportMessageLite
+ optional_public_import_message_extension_lite = 26;
+
+ optional TestAllTypesLite.NestedMessage
+ optional_lazy_message_extension_lite = 27 [lazy=true];
+
+ // Repeated
+ repeated int32 repeated_int32_extension_lite = 31;
+ repeated int64 repeated_int64_extension_lite = 32;
+ repeated uint32 repeated_uint32_extension_lite = 33;
+ repeated uint64 repeated_uint64_extension_lite = 34;
+ repeated sint32 repeated_sint32_extension_lite = 35;
+ repeated sint64 repeated_sint64_extension_lite = 36;
+ repeated fixed32 repeated_fixed32_extension_lite = 37;
+ repeated fixed64 repeated_fixed64_extension_lite = 38;
+ repeated sfixed32 repeated_sfixed32_extension_lite = 39;
+ repeated sfixed64 repeated_sfixed64_extension_lite = 40;
+ repeated float repeated_float_extension_lite = 41;
+ repeated double repeated_double_extension_lite = 42;
+ repeated bool repeated_bool_extension_lite = 43;
+ repeated string repeated_string_extension_lite = 44;
+ repeated bytes repeated_bytes_extension_lite = 45;
+
+ repeated group RepeatedGroup_extension_lite = 46 {
+ optional int32 a = 47;
+ }
+
+ repeated TestAllTypesLite.NestedMessage repeated_nested_message_extension_lite
+ = 48;
+ repeated ForeignMessageLite repeated_foreign_message_extension_lite = 49;
+ repeated protobuf_unittest_import.ImportMessageLite
+ repeated_import_message_extension_lite = 50;
+
+ repeated TestAllTypesLite.NestedEnum repeated_nested_enum_extension_lite = 51;
+ repeated ForeignEnumLite repeated_foreign_enum_extension_lite = 52;
+ repeated protobuf_unittest_import.ImportEnumLite
+ repeated_import_enum_extension_lite = 53;
+
+ repeated string repeated_string_piece_extension_lite = 54
+ [ctype=STRING_PIECE];
+ repeated string repeated_cord_extension_lite = 55 [ctype=CORD];
+
+ repeated TestAllTypesLite.NestedMessage
+ repeated_lazy_message_extension_lite = 57 [lazy=true];
+
+ // Singular with defaults
+ optional int32 default_int32_extension_lite = 61 [default = 41 ];
+ optional int64 default_int64_extension_lite = 62 [default = 42 ];
+ optional uint32 default_uint32_extension_lite = 63 [default = 43 ];
+ optional uint64 default_uint64_extension_lite = 64 [default = 44 ];
+ optional sint32 default_sint32_extension_lite = 65 [default = -45 ];
+ optional sint64 default_sint64_extension_lite = 66 [default = 46 ];
+ optional fixed32 default_fixed32_extension_lite = 67 [default = 47 ];
+ optional fixed64 default_fixed64_extension_lite = 68 [default = 48 ];
+ optional sfixed32 default_sfixed32_extension_lite = 69 [default = 49 ];
+ optional sfixed64 default_sfixed64_extension_lite = 70 [default = -50 ];
+ optional float default_float_extension_lite = 71 [default = 51.5 ];
+ optional double default_double_extension_lite = 72 [default = 52e3 ];
+ optional bool default_bool_extension_lite = 73 [default = true ];
+ optional string default_string_extension_lite = 74 [default = "hello"];
+ optional bytes default_bytes_extension_lite = 75 [default = "world"];
+
+ optional TestAllTypesLite.NestedEnum
+ default_nested_enum_extension_lite = 81 [default = BAR];
+ optional ForeignEnumLite
+ default_foreign_enum_extension_lite = 82 [default = FOREIGN_LITE_BAR];
+ optional protobuf_unittest_import.ImportEnumLite
+ default_import_enum_extension_lite = 83 [default = IMPORT_LITE_BAR];
+
+ optional string default_string_piece_extension_lite = 84 [ctype=STRING_PIECE,
+ default="abc"];
+ optional string default_cord_extension_lite = 85 [ctype=CORD, default="123"];
+}
+
+message TestPackedExtensionsLite {
+ extensions 1 to max;
+}
+
+extend TestPackedExtensionsLite {
+ repeated int32 packed_int32_extension_lite = 90 [packed = true];
+ repeated int64 packed_int64_extension_lite = 91 [packed = true];
+ repeated uint32 packed_uint32_extension_lite = 92 [packed = true];
+ repeated uint64 packed_uint64_extension_lite = 93 [packed = true];
+ repeated sint32 packed_sint32_extension_lite = 94 [packed = true];
+ repeated sint64 packed_sint64_extension_lite = 95 [packed = true];
+ repeated fixed32 packed_fixed32_extension_lite = 96 [packed = true];
+ repeated fixed64 packed_fixed64_extension_lite = 97 [packed = true];
+ repeated sfixed32 packed_sfixed32_extension_lite = 98 [packed = true];
+ repeated sfixed64 packed_sfixed64_extension_lite = 99 [packed = true];
+ repeated float packed_float_extension_lite = 100 [packed = true];
+ repeated double packed_double_extension_lite = 101 [packed = true];
+ repeated bool packed_bool_extension_lite = 102 [packed = true];
+ repeated ForeignEnumLite packed_enum_extension_lite = 103 [packed = true];
+}
+
+message TestNestedExtensionLite {
+ extend TestAllExtensionsLite {
+ optional int32 nested_extension = 12345;
+ }
+}
+
+// Test that deprecated fields work. We only verify that they compile (at one
+// point this failed).
+message TestDeprecatedLite {
+ optional int32 deprecated_field = 1 [deprecated = true];
+}
+
+// See the comments of the same type in unittest.proto.
+message TestParsingMergeLite {
+ message RepeatedFieldsGenerator {
+ repeated TestAllTypesLite field1 = 1;
+ repeated TestAllTypesLite field2 = 2;
+ repeated TestAllTypesLite field3 = 3;
+ repeated group Group1 = 10 {
+ optional TestAllTypesLite field1 = 11;
+ }
+ repeated group Group2 = 20 {
+ optional TestAllTypesLite field1 = 21;
+ }
+ repeated TestAllTypesLite ext1 = 1000;
+ repeated TestAllTypesLite ext2 = 1001;
+ }
+ required TestAllTypesLite required_all_types = 1;
+ optional TestAllTypesLite optional_all_types = 2;
+ repeated TestAllTypesLite repeated_all_types = 3;
+ optional group OptionalGroup = 10 {
+ optional TestAllTypesLite optional_group_all_types = 11;
+ }
+ repeated group RepeatedGroup = 20 {
+ optional TestAllTypesLite repeated_group_all_types = 21;
+ }
+ extensions 1000 to max;
+ extend TestParsingMergeLite {
+ optional TestAllTypesLite optional_ext = 1000;
+ repeated TestAllTypesLite repeated_ext = 1001;
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_lite_imports_nonlite.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_lite_imports_nonlite.proto
new file mode 100644
index 0000000000..d52cb8cc36
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_lite_imports_nonlite.proto
@@ -0,0 +1,43 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+//
+// Tests that a "lite" message can import a regular message.
+
+package protobuf_unittest;
+
+import "google/protobuf/unittest.proto";
+
+option optimize_for = LITE_RUNTIME;
+
+message TestLiteImportsNonlite {
+ optional TestAllTypes message = 1;
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_mset.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_mset.proto
new file mode 100644
index 0000000000..3497f09fa6
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_mset.proto
@@ -0,0 +1,72 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// This file contains messages for testing message_set_wire_format.
+
+package protobuf_unittest;
+
+option optimize_for = SPEED;
+
+// A message with message_set_wire_format.
+message TestMessageSet {
+ option message_set_wire_format = true;
+ extensions 4 to max;
+}
+
+message TestMessageSetContainer {
+ optional TestMessageSet message_set = 1;
+}
+
+message TestMessageSetExtension1 {
+ extend TestMessageSet {
+ optional TestMessageSetExtension1 message_set_extension = 1545008;
+ }
+ optional int32 i = 15;
+}
+
+message TestMessageSetExtension2 {
+ extend TestMessageSet {
+ optional TestMessageSetExtension2 message_set_extension = 1547769;
+ }
+ optional string str = 25;
+}
+
+// MessageSet wire format is equivalent to this.
+message RawMessageSet {
+ repeated group Item = 1 {
+ required int32 type_id = 2;
+ required bytes message = 3;
+ }
+}
+
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_no_generic_services.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_no_generic_services.proto
new file mode 100644
index 0000000000..cffb4122c5
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_no_generic_services.proto
@@ -0,0 +1,52 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+
+package google.protobuf.no_generic_services_test;
+
+// *_generic_services are false by default.
+
+message TestMessage {
+ optional int32 a = 1;
+ extensions 1000 to max;
+}
+
+enum TestEnum {
+ FOO = 1;
+}
+
+extend TestMessage {
+ optional int32 test_extension = 1000;
+}
+
+service TestService {
+ rpc Foo(TestMessage) returns(TestMessage);
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_optimize_for.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_optimize_for.proto
new file mode 100644
index 0000000000..feecbef8d4
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/more_protos/src/proto/google/protobuf/unittest_optimize_for.proto
@@ -0,0 +1,61 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file which uses optimize_for = CODE_SIZE.
+
+import "google/protobuf/unittest.proto";
+
+package protobuf_unittest;
+
+option optimize_for = CODE_SIZE;
+
+message TestOptimizedForSize {
+ optional int32 i = 1;
+ optional ForeignMessage msg = 19;
+
+ extensions 1000 to max;
+
+ extend TestOptimizedForSize {
+ optional int32 test_extension = 1234;
+ optional TestRequiredOptimizedForSize test_extension2 = 1235;
+ }
+}
+
+message TestRequiredOptimizedForSize {
+ required int32 x = 1;
+}
+
+message TestOptionalOptimizedForSize {
+ optional TestRequiredOptimizedForSize o = 1;
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/pom.xml b/third_party/protobuf/java/compatibility_tests/v2.5.0/pom.xml
new file mode 100644
index 0000000000..83a7563afd
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/pom.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.google.protobuf.compatibility</groupId>
+ <artifactId>compatibility-test-suite</artifactId>
+ <version>2.5.0</version>
+ <name>Protocol Buffer Java API compatibility tests</name>
+ <packaging>pom</packaging>
+ <modules>
+ <module>protos</module>
+ <module>more_protos</module>
+ <module>tests</module>
+ </modules>
+ <properties>
+ <protoc.path>protoc</protoc.path>
+ <protobuf.version>2.5.0</protobuf.version>
+
+ <protos.protoc.path>${protoc.path}</protos.protoc.path>
+ <protos.protobuf.version>${protobuf.version}</protos.protobuf.version>
+
+ <more_protos.protoc.path>${protoc.path}</more_protos.protoc.path>
+ <more_protos.protobuf.version>${protobuf.version}</more_protos.protobuf.version>
+
+ <tests.protobuf.version>${protobuf.version}</tests.protobuf.version>
+
+ <protobuf.test.source.path>.</protobuf.test.source.path>
+ </properties>
+</project>
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/pom.xml b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/pom.xml
new file mode 100644
index 0000000000..a22e91ed1d
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/pom.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>com.google.protobuf.compatibility</groupId>
+ <artifactId>compatibility-test-suite</artifactId>
+ <version>2.5.0</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <groupId>com.google.protobuf.compatibility</groupId>
+ <artifactId>compatibility-protos</artifactId>
+ <version>2.5.0</version>
+
+ <name>Protos for Compatibility test</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.google.protobuf</groupId>
+ <artifactId>protobuf-java</artifactId>
+ <version>${protos.protobuf.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.6.0</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-sources</id>
+ <phase>generate-sources</phase>
+ <configuration>
+ <tasks>
+ <mkdir dir="target/generated-sources" />
+ <exec executable="${protos.protoc.path}">
+ <arg value="--java_out=target/generated-sources" />
+ <arg value="--proto_path=src/proto" />
+ <arg value="src/proto/google/protobuf/unittest_custom_options.proto" />
+ <arg value="src/proto/google/protobuf/unittest_enormous_descriptor.proto" />
+ <arg value="src/proto/google/protobuf/unittest_import.proto" />
+ <arg value="src/proto/google/protobuf/unittest_import_public.proto" />
+ <arg value="src/proto/google/protobuf/unittest_mset.proto" />
+ <arg value="src/proto/google/protobuf/unittest_no_generic_services.proto" />
+ <arg value="src/proto/com/google/protobuf/nested_builders_test.proto" />
+ <arg value="src/proto/com/google/protobuf/nested_extension.proto" />
+ <arg value="src/proto/com/google/protobuf/non_nested_extension.proto" />
+ <arg value="src/proto/com/google/protobuf/test_bad_identifiers.proto" />
+ </exec>
+ </tasks>
+ <sourceRoot>target/generated-sources</sourceRoot>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/multiple_files_test.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/multiple_files_test.proto
new file mode 100644
index 0000000000..9a040145a6
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/multiple_files_test.proto
@@ -0,0 +1,71 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+//
+// A proto file which tests the java_multiple_files option.
+
+
+// Some generic_services option(s) added automatically.
+// See: http://go/proto2-generic-services-default
+option java_generic_services = true; // auto-added
+
+import "google/protobuf/unittest.proto";
+
+package protobuf_unittest;
+
+option java_multiple_files = true;
+option java_outer_classname = "MultipleFilesTestProto";
+
+message MessageWithNoOuter {
+ message NestedMessage {
+ optional int32 i = 1;
+ }
+ enum NestedEnum {
+ BAZ = 3;
+ }
+ optional NestedMessage nested = 1;
+ repeated TestAllTypes foreign = 2;
+ optional NestedEnum nested_enum = 3;
+ optional EnumWithNoOuter foreign_enum = 4;
+}
+
+enum EnumWithNoOuter {
+ FOO = 1;
+ BAR = 2;
+}
+
+service ServiceWithNoOuter {
+ rpc Foo(MessageWithNoOuter) returns(TestAllTypes);
+}
+
+extend TestAllExtensions {
+ optional int32 extension_with_outer = 1234567;
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/nested_builders_test.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/nested_builders_test.proto
new file mode 100644
index 0000000000..abffb9d2ba
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/nested_builders_test.proto
@@ -0,0 +1,53 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: jonp@google.com (Jon Perlow)
+//
+
+package protobuf_unittest;
+
+option java_multiple_files = true;
+option java_outer_classname = "NestedBuilders";
+
+
+message Vehicle {
+ optional Engine engine = 1;
+ repeated Wheel wheel = 2;
+}
+
+message Engine {
+ optional int32 cylinder = 1;
+ optional int32 liters = 2;
+}
+
+message Wheel {
+ optional int32 radius = 1;
+ optional int32 width = 2;
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/nested_extension.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/nested_extension.proto
new file mode 100644
index 0000000000..9fe5d560c9
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/nested_extension.proto
@@ -0,0 +1,45 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: Darick Tong (darick@google.com)
+//
+// A proto file with nested extensions. Note that this must be defined in
+// a separate file to properly test the initialization of the outer class.
+
+
+import "com/google/protobuf/non_nested_extension.proto";
+
+package protobuf_unittest;
+
+message MyNestedExtension {
+ extend MessageToBeExtended {
+ optional MessageToBeExtended recursiveExtension = 2;
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/nested_extension_lite.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/nested_extension_lite.proto
new file mode 100644
index 0000000000..16ee46e57d
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/nested_extension_lite.proto
@@ -0,0 +1,48 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: Darick Tong (darick@google.com)
+//
+// A proto file with nested extensions for a MessageLite messages. Note that
+// this must be defined in a separate file to properly test the initialization
+// of the outer class.
+
+
+package protobuf_unittest;
+
+option optimize_for = LITE_RUNTIME;
+
+import "com/google/protobuf/non_nested_extension_lite.proto";
+
+message MyNestedExtensionLite {
+ extend MessageLiteToBeExtended {
+ optional MessageLiteToBeExtended recursiveExtensionLite = 3;
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/non_nested_extension.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/non_nested_extension.proto
new file mode 100644
index 0000000000..f61b419bc2
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/non_nested_extension.proto
@@ -0,0 +1,48 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: Darick Tong (darick@google.com)
+//
+// A proto file with extensions.
+
+
+package protobuf_unittest;
+
+message MessageToBeExtended {
+ extensions 1 to max;
+}
+
+message MyNonNestedExtension {
+}
+
+extend MessageToBeExtended {
+ optional MyNonNestedExtension nonNestedExtension = 1;
+}
+
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/non_nested_extension_lite.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/non_nested_extension_lite.proto
new file mode 100644
index 0000000000..3c82659b5e
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/non_nested_extension_lite.proto
@@ -0,0 +1,50 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: Darick Tong (darick@google.com)
+//
+// A proto file with extensions for a MessageLite messages.
+
+
+package protobuf_unittest;
+
+option optimize_for = LITE_RUNTIME;
+
+message MessageLiteToBeExtended {
+ extensions 1 to max;
+}
+
+message MyNonNestedExtensionLite {
+}
+
+extend MessageLiteToBeExtended {
+ optional MyNonNestedExtensionLite nonNestedExtensionLite = 1;
+}
+
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/test_bad_identifiers.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/test_bad_identifiers.proto
new file mode 100644
index 0000000000..6e67d97a69
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/com/google/protobuf/test_bad_identifiers.proto
@@ -0,0 +1,108 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: jonp@google.com (Jon Perlow)
+
+// This file tests that various identifiers work as field and type names even
+// though the same identifiers are used internally by the java code generator.
+
+
+// Some generic_services option(s) added automatically.
+// See: http://go/proto2-generic-services-default
+option java_generic_services = true; // auto-added
+
+package io_protocol_tests;
+
+option java_package = "com.google.protobuf";
+option java_outer_classname = "TestBadIdentifiersProto";
+
+message TestMessage {
+}
+
+message Descriptor {
+ option no_standard_descriptor_accessor = true;
+ optional string descriptor = 1;
+ message NestedDescriptor {
+ option no_standard_descriptor_accessor = true;
+ optional string descriptor = 1;
+ }
+ optional NestedDescriptor nested_descriptor = 2;
+}
+
+message Parser {
+ enum ParserEnum {
+ PARSER = 1;
+ }
+ optional ParserEnum parser = 1;
+}
+
+message Deprecated {
+ enum TestEnum {
+ FOO = 1;
+ }
+
+ optional int32 field1 = 1 [deprecated=true];
+ optional TestEnum field2 = 2 [deprecated=true];
+ optional TestMessage field3 = 3 [deprecated=true];
+}
+
+message Override {
+ optional int32 override = 1;
+}
+
+message Object {
+ optional int32 object = 1;
+ optional string string_object = 2;
+}
+
+message String {
+ optional string string = 1;
+}
+
+message Integer {
+ optional int32 integer = 1;
+}
+
+message Long {
+ optional int32 long = 1;
+}
+
+message Float {
+ optional float float = 1;
+}
+
+message Double {
+ optional double double = 1;
+}
+
+service TestConflictingMethodNames {
+ rpc Override(TestMessage) returns (TestMessage);
+}
+
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/descriptor.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/descriptor.proto
new file mode 100644
index 0000000000..a785f79faf
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/descriptor.proto
@@ -0,0 +1,620 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// The messages in this file describe the definitions found in .proto files.
+// A valid .proto file can be translated directly to a FileDescriptorProto
+// without any other information (e.g. without reading its imports).
+
+
+
+package google.protobuf;
+option java_package = "com.google.protobuf";
+option java_outer_classname = "DescriptorProtos";
+
+// descriptor.proto must be optimized for speed because reflection-based
+// algorithms don't work during bootstrapping.
+option optimize_for = SPEED;
+
+// The protocol compiler can output a FileDescriptorSet containing the .proto
+// files it parses.
+message FileDescriptorSet {
+ repeated FileDescriptorProto file = 1;
+}
+
+// Describes a complete .proto file.
+message FileDescriptorProto {
+ optional string name = 1; // file name, relative to root of source tree
+ optional string package = 2; // e.g. "foo", "foo.bar", etc.
+
+ // Names of files imported by this file.
+ repeated string dependency = 3;
+ // Indexes of the public imported files in the dependency list above.
+ repeated int32 public_dependency = 10;
+ // Indexes of the weak imported files in the dependency list.
+ // For Google-internal migration only. Do not use.
+ repeated int32 weak_dependency = 11;
+
+ // All top-level definitions in this file.
+ repeated DescriptorProto message_type = 4;
+ repeated EnumDescriptorProto enum_type = 5;
+ repeated ServiceDescriptorProto service = 6;
+ repeated FieldDescriptorProto extension = 7;
+
+ optional FileOptions options = 8;
+
+ // This field contains optional information about the original source code.
+ // You may safely remove this entire field whithout harming runtime
+ // functionality of the descriptors -- the information is needed only by
+ // development tools.
+ optional SourceCodeInfo source_code_info = 9;
+}
+
+// Describes a message type.
+message DescriptorProto {
+ optional string name = 1;
+
+ repeated FieldDescriptorProto field = 2;
+ repeated FieldDescriptorProto extension = 6;
+
+ repeated DescriptorProto nested_type = 3;
+ repeated EnumDescriptorProto enum_type = 4;
+
+ message ExtensionRange {
+ optional int32 start = 1;
+ optional int32 end = 2;
+ }
+ repeated ExtensionRange extension_range = 5;
+
+ optional MessageOptions options = 7;
+}
+
+// Describes a field within a message.
+message FieldDescriptorProto {
+ enum Type {
+ // 0 is reserved for errors.
+ // Order is weird for historical reasons.
+ TYPE_DOUBLE = 1;
+ TYPE_FLOAT = 2;
+ // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
+ // negative values are likely.
+ TYPE_INT64 = 3;
+ TYPE_UINT64 = 4;
+ // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
+ // negative values are likely.
+ TYPE_INT32 = 5;
+ TYPE_FIXED64 = 6;
+ TYPE_FIXED32 = 7;
+ TYPE_BOOL = 8;
+ TYPE_STRING = 9;
+ TYPE_GROUP = 10; // Tag-delimited aggregate.
+ TYPE_MESSAGE = 11; // Length-delimited aggregate.
+
+ // New in version 2.
+ TYPE_BYTES = 12;
+ TYPE_UINT32 = 13;
+ TYPE_ENUM = 14;
+ TYPE_SFIXED32 = 15;
+ TYPE_SFIXED64 = 16;
+ TYPE_SINT32 = 17; // Uses ZigZag encoding.
+ TYPE_SINT64 = 18; // Uses ZigZag encoding.
+ };
+
+ enum Label {
+ // 0 is reserved for errors
+ LABEL_OPTIONAL = 1;
+ LABEL_REQUIRED = 2;
+ LABEL_REPEATED = 3;
+ // TODO(sanjay): Should we add LABEL_MAP?
+ };
+
+ optional string name = 1;
+ optional int32 number = 3;
+ optional Label label = 4;
+
+ // If type_name is set, this need not be set. If both this and type_name
+ // are set, this must be either TYPE_ENUM or TYPE_MESSAGE.
+ optional Type type = 5;
+
+ // For message and enum types, this is the name of the type. If the name
+ // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
+ // rules are used to find the type (i.e. first the nested types within this
+ // message are searched, then within the parent, on up to the root
+ // namespace).
+ optional string type_name = 6;
+
+ // For extensions, this is the name of the type being extended. It is
+ // resolved in the same manner as type_name.
+ optional string extendee = 2;
+
+ // For numeric types, contains the original text representation of the value.
+ // For booleans, "true" or "false".
+ // For strings, contains the default text contents (not escaped in any way).
+ // For bytes, contains the C escaped value. All bytes >= 128 are escaped.
+ // TODO(kenton): Base-64 encode?
+ optional string default_value = 7;
+
+ optional FieldOptions options = 8;
+}
+
+// Describes an enum type.
+message EnumDescriptorProto {
+ optional string name = 1;
+
+ repeated EnumValueDescriptorProto value = 2;
+
+ optional EnumOptions options = 3;
+}
+
+// Describes a value within an enum.
+message EnumValueDescriptorProto {
+ optional string name = 1;
+ optional int32 number = 2;
+
+ optional EnumValueOptions options = 3;
+}
+
+// Describes a service.
+message ServiceDescriptorProto {
+ optional string name = 1;
+ repeated MethodDescriptorProto method = 2;
+
+ optional ServiceOptions options = 3;
+}
+
+// Describes a method of a service.
+message MethodDescriptorProto {
+ optional string name = 1;
+
+ // Input and output type names. These are resolved in the same way as
+ // FieldDescriptorProto.type_name, but must refer to a message type.
+ optional string input_type = 2;
+ optional string output_type = 3;
+
+ optional MethodOptions options = 4;
+}
+
+
+// ===================================================================
+// Options
+
+// Each of the definitions above may have "options" attached. These are
+// just annotations which may cause code to be generated slightly differently
+// or may contain hints for code that manipulates protocol messages.
+//
+// Clients may define custom options as extensions of the *Options messages.
+// These extensions may not yet be known at parsing time, so the parser cannot
+// store the values in them. Instead it stores them in a field in the *Options
+// message called uninterpreted_option. This field must have the same name
+// across all *Options messages. We then use this field to populate the
+// extensions when we build a descriptor, at which point all protos have been
+// parsed and so all extensions are known.
+//
+// Extension numbers for custom options may be chosen as follows:
+// * For options which will only be used within a single application or
+// organization, or for experimental options, use field numbers 50000
+// through 99999. It is up to you to ensure that you do not use the
+// same number for multiple options.
+// * For options which will be published and used publicly by multiple
+// independent entities, e-mail protobuf-global-extension-registry@google.com
+// to reserve extension numbers. Simply provide your project name (e.g.
+// Object-C plugin) and your porject website (if available) -- there's no need
+// to explain how you intend to use them. Usually you only need one extension
+// number. You can declare multiple options with only one extension number by
+// putting them in a sub-message. See the Custom Options section of the docs
+// for examples:
+// http://code.google.com/apis/protocolbuffers/docs/proto.html#options
+// If this turns out to be popular, a web service will be set up
+// to automatically assign option numbers.
+
+
+message FileOptions {
+
+ // Sets the Java package where classes generated from this .proto will be
+ // placed. By default, the proto package is used, but this is often
+ // inappropriate because proto packages do not normally start with backwards
+ // domain names.
+ optional string java_package = 1;
+
+
+ // If set, all the classes from the .proto file are wrapped in a single
+ // outer class with the given name. This applies to both Proto1
+ // (equivalent to the old "--one_java_file" option) and Proto2 (where
+ // a .proto always translates to a single class, but you may want to
+ // explicitly choose the class name).
+ optional string java_outer_classname = 8;
+
+ // If set true, then the Java code generator will generate a separate .java
+ // file for each top-level message, enum, and service defined in the .proto
+ // file. Thus, these types will *not* be nested inside the outer class
+ // named by java_outer_classname. However, the outer class will still be
+ // generated to contain the file's getDescriptor() method as well as any
+ // 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 is
+ // purely a speed optimization, as the AbstractMessage base class includes
+ // reflection-based implementations of these methods.
+ optional bool java_generate_equals_and_hash = 20 [default=false];
+
+ // Generated classes can be optimized for speed or code size.
+ enum OptimizeMode {
+ SPEED = 1; // Generate complete code for parsing, serialization,
+ // etc.
+ CODE_SIZE = 2; // Use ReflectionOps to implement these methods.
+ LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime.
+ }
+ optional OptimizeMode optimize_for = 9 [default=SPEED];
+
+ // Sets the Go package where structs generated from this .proto will be
+ // placed. There is no default.
+ optional string go_package = 11;
+
+
+
+ // Should generic services be generated in each language? "Generic" services
+ // are not specific to any particular RPC system. They are generated by the
+ // main code generators in each language (without additional plugins).
+ // Generic services were the only kind of service generation supported by
+ // early versions of proto2.
+ //
+ // Generic services are now considered deprecated in favor of using plugins
+ // that generate code specific to your particular RPC system. Therefore,
+ // these default to false. Old code which depends on generic services should
+ // explicitly set them to true.
+ optional bool cc_generic_services = 16 [default=false];
+ optional bool java_generic_services = 17 [default=false];
+ optional bool py_generic_services = 18 [default=false];
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message MessageOptions {
+ // Set true to use the old proto1 MessageSet wire format for extensions.
+ // This is provided for backwards-compatibility with the MessageSet wire
+ // format. You should not use this for any other reason: It's less
+ // efficient, has fewer features, and is more complicated.
+ //
+ // The message must be defined exactly as follows:
+ // message Foo {
+ // option message_set_wire_format = true;
+ // extensions 4 to max;
+ // }
+ // Note that the message cannot have any defined fields; MessageSets only
+ // have extensions.
+ //
+ // All extensions of your type must be singular messages; e.g. they cannot
+ // be int32s, enums, or repeated messages.
+ //
+ // Because this is an option, the above two restrictions are not enforced by
+ // the protocol compiler.
+ optional bool message_set_wire_format = 1 [default=false];
+
+ // Disables the generation of the standard "descriptor()" accessor, which can
+ // conflict with a field of the same name. This is meant to make migration
+ // from proto1 easier; new code should avoid fields named "descriptor".
+ optional bool no_standard_descriptor_accessor = 2 [default=false];
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message FieldOptions {
+ // The ctype option instructs the C++ code generator to use a different
+ // representation of the field than it normally would. See the specific
+ // options below. This option is not yet implemented in the open source
+ // release -- sorry, we'll try to include it in a future version!
+ optional CType ctype = 1 [default = STRING];
+ enum CType {
+ // Default mode.
+ STRING = 0;
+
+ CORD = 1;
+
+ STRING_PIECE = 2;
+ }
+ // The packed option can be enabled for repeated primitive fields to enable
+ // a more efficient representation on the wire. Rather than repeatedly
+ // writing the tag and type for each element, the entire array is encoded as
+ // a single length-delimited blob.
+ optional bool packed = 2;
+
+
+
+ // Should this field be parsed lazily? Lazy applies only to message-type
+ // fields. It means that when the outer message is initially parsed, the
+ // inner message's contents will not be parsed but instead stored in encoded
+ // form. The inner message will actually be parsed when it is first accessed.
+ //
+ // This is only a hint. Implementations are free to choose whether to use
+ // eager or lazy parsing regardless of the value of this option. However,
+ // setting this option true suggests that the protocol author believes that
+ // using lazy parsing on this field is worth the additional bookkeeping
+ // overhead typically needed to implement it.
+ //
+ // This option does not affect the public interface of any generated code;
+ // all method signatures remain the same. Furthermore, thread-safety of the
+ // interface is not affected by this option; const methods remain safe to
+ // call from multiple threads concurrently, while non-const methods continue
+ // to require exclusive access.
+ //
+ //
+ // Note that implementations may choose not to check required fields within
+ // a lazy sub-message. That is, calling IsInitialized() on the outher 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
+ // parsing. An implementation which chooses not to check required fields
+ // must be consistent about it. That is, for any particular sub-message, the
+ // implementation must either *always* check its required fields, or *never*
+ // check its required fields, regardless of whether or not the message has
+ // been parsed.
+ optional bool lazy = 5 [default=false];
+
+ // Is this field deprecated?
+ // Depending on the target platform, this can emit Deprecated annotations
+ // for accessors, or it will be completely ignored; in the very least, this
+ // is a formalization for deprecating fields.
+ optional bool deprecated = 3 [default=false];
+
+ // EXPERIMENTAL. DO NOT USE.
+ // For "map" fields, the name of the field in the enclosed type that
+ // is the key for this map. For example, suppose we have:
+ // message Item {
+ // required string name = 1;
+ // required string value = 2;
+ // }
+ // message Config {
+ // repeated Item items = 1 [experimental_map_key="name"];
+ // }
+ // In this situation, the map key for Item will be set to "name".
+ // TODO: Fully-implement this, then remove the "experimental_" prefix.
+ optional string experimental_map_key = 9;
+
+ // For Google-internal migration only. Do not use.
+ optional bool weak = 10 [default=false];
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message EnumOptions {
+
+ // Set this option to false to disallow mapping different tag names to a same
+ // value.
+ optional bool allow_alias = 2 [default=true];
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message EnumValueOptions {
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message ServiceOptions {
+
+ // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
+ // framework. We apologize for hoarding these numbers to ourselves, but
+ // we were already using them long before we decided to release Protocol
+ // Buffers.
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message MethodOptions {
+
+ // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
+ // framework. We apologize for hoarding these numbers to ourselves, but
+ // we were already using them long before we decided to release Protocol
+ // Buffers.
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+
+// A message representing a option the parser does not recognize. This only
+// appears in options protos created by the compiler::Parser class.
+// DescriptorPool resolves these when building Descriptor objects. Therefore,
+// options protos in descriptor objects (e.g. returned by Descriptor::options(),
+// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
+// in them.
+message UninterpretedOption {
+ // The name of the uninterpreted option. Each string represents a segment in
+ // a dot-separated name. is_extension is true iff a segment represents an
+ // extension (denoted with parentheses in options specs in .proto files).
+ // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
+ // "foo.(bar.baz).qux".
+ message NamePart {
+ required string name_part = 1;
+ required bool is_extension = 2;
+ }
+ repeated NamePart name = 2;
+
+ // The value of the uninterpreted option, in whatever type the tokenizer
+ // identified it as during parsing. Exactly one of these should be set.
+ optional string identifier_value = 3;
+ optional uint64 positive_int_value = 4;
+ optional int64 negative_int_value = 5;
+ optional double double_value = 6;
+ optional bytes string_value = 7;
+ optional string aggregate_value = 8;
+}
+
+// ===================================================================
+// Optional source code info
+
+// Encapsulates information about the original source file from which a
+// FileDescriptorProto was generated.
+message SourceCodeInfo {
+ // A Location identifies a piece of source code in a .proto file which
+ // corresponds to a particular definition. This information is intended
+ // to be useful to IDEs, code indexers, documentation generators, and similar
+ // tools.
+ //
+ // For example, say we have a file like:
+ // message Foo {
+ // optional string foo = 1;
+ // }
+ // Let's look at just the field definition:
+ // optional string foo = 1;
+ // ^ ^^ ^^ ^ ^^^
+ // a bc de f ghi
+ // We have the following locations:
+ // span path represents
+ // [a,i) [ 4, 0, 2, 0 ] The whole field definition.
+ // [a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
+ // [c,d) [ 4, 0, 2, 0, 5 ] The type (string).
+ // [e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
+ // [g,h) [ 4, 0, 2, 0, 3 ] The number (1).
+ //
+ // Notes:
+ // - A location may refer to a repeated field itself (i.e. not to any
+ // particular index within it). This is used whenever a set of elements are
+ // logically enclosed in a single code segment. For example, an entire
+ // extend block (possibly containing multiple extension definitions) will
+ // have an outer location whose path refers to the "extensions" repeated
+ // field without an index.
+ // - Multiple locations may have the same path. This happens when a single
+ // logical declaration is spread out across multiple places. The most
+ // obvious example is the "extend" block again -- there may be multiple
+ // extend blocks in the same scope, each of which will have the same path.
+ // - A location's span is not always a subset of its parent's span. For
+ // example, the "extendee" of an extension declaration appears at the
+ // beginning of the "extend" block and is shared by all extensions within
+ // the block.
+ // - Just because a location's span is a subset of some other location's span
+ // does not mean that it is a descendent. For example, a "group" defines
+ // both a type and a field in a single declaration. Thus, the locations
+ // corresponding to the type and field and their components will overlap.
+ // - Code which tries to interpret locations should probably be designed to
+ // ignore those that it doesn't understand, as more types of locations could
+ // be recorded in the future.
+ repeated Location location = 1;
+ message Location {
+ // Identifies which part of the FileDescriptorProto was defined at this
+ // location.
+ //
+ // Each element is a field number or an index. They form a path from
+ // the root FileDescriptorProto to the place where the definition. For
+ // example, this path:
+ // [ 4, 3, 2, 7, 1 ]
+ // refers to:
+ // file.message_type(3) // 4, 3
+ // .field(7) // 2, 7
+ // .name() // 1
+ // This is because FileDescriptorProto.message_type has field number 4:
+ // repeated DescriptorProto message_type = 4;
+ // and DescriptorProto.field has field number 2:
+ // repeated FieldDescriptorProto field = 2;
+ // and FieldDescriptorProto.name has field number 1:
+ // optional string name = 1;
+ //
+ // Thus, the above path gives the location of a field name. If we removed
+ // the last element:
+ // [ 4, 3, 2, 7 ]
+ // this path refers to the whole field declaration (from the beginning
+ // of the label to the terminating semicolon).
+ repeated int32 path = 1 [packed=true];
+
+ // Always has exactly three or four elements: start line, start column,
+ // end line (optional, otherwise assumed same as start line), end column.
+ // These are packed into a single field for efficiency. Note that line
+ // and column numbers are zero-based -- typically you will want to add
+ // 1 to each before displaying to a user.
+ repeated int32 span = 2 [packed=true];
+
+ // If this SourceCodeInfo represents a complete declaration, these are any
+ // comments appearing before and after the declaration which appear to be
+ // attached to the declaration.
+ //
+ // A series of line comments appearing on consecutive lines, with no other
+ // tokens appearing on those lines, will be treated as a single comment.
+ //
+ // Only the comment content is provided; comment markers (e.g. //) are
+ // stripped out. For block comments, leading whitespace and an asterisk
+ // will be stripped from the beginning of each line other than the first.
+ // Newlines are included in the output.
+ //
+ // Examples:
+ //
+ // optional int32 foo = 1; // Comment attached to foo.
+ // // Comment attached to bar.
+ // optional int32 bar = 2;
+ //
+ // optional string baz = 3;
+ // // Comment attached to baz.
+ // // Another line attached to baz.
+ //
+ // // Comment attached to qux.
+ // //
+ // // Another line attached to qux.
+ // optional double qux = 4;
+ //
+ // optional string corge = 5;
+ // /* Block comment attached
+ // * to corge. Leading asterisks
+ // * will be removed. */
+ // /* Block comment attached to
+ // * grault. */
+ // optional int32 grault = 6;
+ optional string leading_comments = 3;
+ optional string trailing_comments = 4;
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest.proto
new file mode 100644
index 0000000000..6eb2d86f51
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest.proto
@@ -0,0 +1,719 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file we will use for unit testing.
+
+
+// Some generic_services option(s) added automatically.
+// See: http://go/proto2-generic-services-default
+option cc_generic_services = true; // auto-added
+option java_generic_services = true; // auto-added
+option py_generic_services = true; // auto-added
+
+import "google/protobuf/unittest_import.proto";
+
+// We don't put this in a package within proto2 because we need to make sure
+// that the generated code doesn't depend on being in the proto2 namespace.
+// In test_util.h we do "using namespace unittest = protobuf_unittest".
+package protobuf_unittest;
+
+// Protos optimized for SPEED use a strict superset of the generated code
+// of equivalent ones optimized for CODE_SIZE, so we should optimize all our
+// tests for speed unless explicitly testing code size optimization.
+option optimize_for = SPEED;
+
+option java_outer_classname = "UnittestProto";
+
+// This proto includes every type of field in both singular and repeated
+// forms.
+message TestAllTypes {
+ message NestedMessage {
+ // The field name "b" fails to compile in proto1 because it conflicts with
+ // a local variable named "b" in one of the generated methods. Doh.
+ // This file needs to compile in proto1 to test backwards-compatibility.
+ optional int32 bb = 1;
+ }
+
+ enum NestedEnum {
+ FOO = 1;
+ BAR = 2;
+ BAZ = 3;
+ }
+
+ // Singular
+ optional int32 optional_int32 = 1;
+ optional int64 optional_int64 = 2;
+ optional uint32 optional_uint32 = 3;
+ optional uint64 optional_uint64 = 4;
+ optional sint32 optional_sint32 = 5;
+ optional sint64 optional_sint64 = 6;
+ optional fixed32 optional_fixed32 = 7;
+ optional fixed64 optional_fixed64 = 8;
+ optional sfixed32 optional_sfixed32 = 9;
+ optional sfixed64 optional_sfixed64 = 10;
+ optional float optional_float = 11;
+ optional double optional_double = 12;
+ optional bool optional_bool = 13;
+ optional string optional_string = 14;
+ optional bytes optional_bytes = 15;
+
+ optional group OptionalGroup = 16 {
+ optional int32 a = 17;
+ }
+
+ optional NestedMessage optional_nested_message = 18;
+ optional ForeignMessage optional_foreign_message = 19;
+ optional protobuf_unittest_import.ImportMessage optional_import_message = 20;
+
+ optional NestedEnum optional_nested_enum = 21;
+ optional ForeignEnum optional_foreign_enum = 22;
+ optional protobuf_unittest_import.ImportEnum optional_import_enum = 23;
+
+ optional string optional_string_piece = 24 [ctype=STRING_PIECE];
+ optional string optional_cord = 25 [ctype=CORD];
+
+ // Defined in unittest_import_public.proto
+ optional protobuf_unittest_import.PublicImportMessage
+ optional_public_import_message = 26;
+
+ optional NestedMessage optional_lazy_message = 27 [lazy=true];
+
+ // Repeated
+ repeated int32 repeated_int32 = 31;
+ repeated int64 repeated_int64 = 32;
+ repeated uint32 repeated_uint32 = 33;
+ repeated uint64 repeated_uint64 = 34;
+ repeated sint32 repeated_sint32 = 35;
+ repeated sint64 repeated_sint64 = 36;
+ repeated fixed32 repeated_fixed32 = 37;
+ repeated fixed64 repeated_fixed64 = 38;
+ repeated sfixed32 repeated_sfixed32 = 39;
+ repeated sfixed64 repeated_sfixed64 = 40;
+ repeated float repeated_float = 41;
+ repeated double repeated_double = 42;
+ repeated bool repeated_bool = 43;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+
+ repeated group RepeatedGroup = 46 {
+ optional int32 a = 47;
+ }
+
+ repeated NestedMessage repeated_nested_message = 48;
+ repeated ForeignMessage repeated_foreign_message = 49;
+ repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50;
+
+ repeated NestedEnum repeated_nested_enum = 51;
+ repeated ForeignEnum repeated_foreign_enum = 52;
+ repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53;
+
+ repeated string repeated_string_piece = 54 [ctype=STRING_PIECE];
+ repeated string repeated_cord = 55 [ctype=CORD];
+
+ repeated NestedMessage repeated_lazy_message = 57 [lazy=true];
+
+ // Singular with defaults
+ optional int32 default_int32 = 61 [default = 41 ];
+ optional int64 default_int64 = 62 [default = 42 ];
+ optional uint32 default_uint32 = 63 [default = 43 ];
+ optional uint64 default_uint64 = 64 [default = 44 ];
+ optional sint32 default_sint32 = 65 [default = -45 ];
+ optional sint64 default_sint64 = 66 [default = 46 ];
+ optional fixed32 default_fixed32 = 67 [default = 47 ];
+ optional fixed64 default_fixed64 = 68 [default = 48 ];
+ optional sfixed32 default_sfixed32 = 69 [default = 49 ];
+ optional sfixed64 default_sfixed64 = 70 [default = -50 ];
+ optional float default_float = 71 [default = 51.5 ];
+ optional double default_double = 72 [default = 52e3 ];
+ optional bool default_bool = 73 [default = true ];
+ optional string default_string = 74 [default = "hello"];
+ optional bytes default_bytes = 75 [default = "world"];
+
+ optional NestedEnum default_nested_enum = 81 [default = BAR ];
+ optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR];
+ optional protobuf_unittest_import.ImportEnum
+ default_import_enum = 83 [default = IMPORT_BAR];
+
+ optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"];
+ optional string default_cord = 85 [ctype=CORD,default="123"];
+}
+
+message TestDeprecatedFields {
+ optional int32 deprecated_int32 = 1 [deprecated=true];
+}
+
+// Define these after TestAllTypes to make sure the compiler can handle
+// that.
+message ForeignMessage {
+ optional int32 c = 1;
+}
+
+enum ForeignEnum {
+ FOREIGN_FOO = 4;
+ FOREIGN_BAR = 5;
+ FOREIGN_BAZ = 6;
+}
+
+message TestAllExtensions {
+ extensions 1 to max;
+}
+
+extend TestAllExtensions {
+ // Singular
+ optional int32 optional_int32_extension = 1;
+ optional int64 optional_int64_extension = 2;
+ optional uint32 optional_uint32_extension = 3;
+ optional uint64 optional_uint64_extension = 4;
+ optional sint32 optional_sint32_extension = 5;
+ optional sint64 optional_sint64_extension = 6;
+ optional fixed32 optional_fixed32_extension = 7;
+ optional fixed64 optional_fixed64_extension = 8;
+ optional sfixed32 optional_sfixed32_extension = 9;
+ optional sfixed64 optional_sfixed64_extension = 10;
+ optional float optional_float_extension = 11;
+ optional double optional_double_extension = 12;
+ optional bool optional_bool_extension = 13;
+ optional string optional_string_extension = 14;
+ optional bytes optional_bytes_extension = 15;
+
+ optional group OptionalGroup_extension = 16 {
+ optional int32 a = 17;
+ }
+
+ optional TestAllTypes.NestedMessage optional_nested_message_extension = 18;
+ optional ForeignMessage optional_foreign_message_extension = 19;
+ optional protobuf_unittest_import.ImportMessage
+ optional_import_message_extension = 20;
+
+ optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21;
+ optional ForeignEnum optional_foreign_enum_extension = 22;
+ optional protobuf_unittest_import.ImportEnum
+ optional_import_enum_extension = 23;
+
+ optional string optional_string_piece_extension = 24 [ctype=STRING_PIECE];
+ optional string optional_cord_extension = 25 [ctype=CORD];
+
+ optional protobuf_unittest_import.PublicImportMessage
+ optional_public_import_message_extension = 26;
+
+ optional TestAllTypes.NestedMessage
+ optional_lazy_message_extension = 27 [lazy=true];
+
+ // Repeated
+ repeated int32 repeated_int32_extension = 31;
+ repeated int64 repeated_int64_extension = 32;
+ repeated uint32 repeated_uint32_extension = 33;
+ repeated uint64 repeated_uint64_extension = 34;
+ repeated sint32 repeated_sint32_extension = 35;
+ repeated sint64 repeated_sint64_extension = 36;
+ repeated fixed32 repeated_fixed32_extension = 37;
+ repeated fixed64 repeated_fixed64_extension = 38;
+ repeated sfixed32 repeated_sfixed32_extension = 39;
+ repeated sfixed64 repeated_sfixed64_extension = 40;
+ repeated float repeated_float_extension = 41;
+ repeated double repeated_double_extension = 42;
+ repeated bool repeated_bool_extension = 43;
+ repeated string repeated_string_extension = 44;
+ repeated bytes repeated_bytes_extension = 45;
+
+ repeated group RepeatedGroup_extension = 46 {
+ optional int32 a = 47;
+ }
+
+ repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48;
+ repeated ForeignMessage repeated_foreign_message_extension = 49;
+ repeated protobuf_unittest_import.ImportMessage
+ repeated_import_message_extension = 50;
+
+ repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51;
+ repeated ForeignEnum repeated_foreign_enum_extension = 52;
+ repeated protobuf_unittest_import.ImportEnum
+ repeated_import_enum_extension = 53;
+
+ repeated string repeated_string_piece_extension = 54 [ctype=STRING_PIECE];
+ repeated string repeated_cord_extension = 55 [ctype=CORD];
+
+ repeated TestAllTypes.NestedMessage
+ repeated_lazy_message_extension = 57 [lazy=true];
+
+ // Singular with defaults
+ optional int32 default_int32_extension = 61 [default = 41 ];
+ optional int64 default_int64_extension = 62 [default = 42 ];
+ optional uint32 default_uint32_extension = 63 [default = 43 ];
+ optional uint64 default_uint64_extension = 64 [default = 44 ];
+ optional sint32 default_sint32_extension = 65 [default = -45 ];
+ optional sint64 default_sint64_extension = 66 [default = 46 ];
+ optional fixed32 default_fixed32_extension = 67 [default = 47 ];
+ optional fixed64 default_fixed64_extension = 68 [default = 48 ];
+ optional sfixed32 default_sfixed32_extension = 69 [default = 49 ];
+ optional sfixed64 default_sfixed64_extension = 70 [default = -50 ];
+ optional float default_float_extension = 71 [default = 51.5 ];
+ optional double default_double_extension = 72 [default = 52e3 ];
+ optional bool default_bool_extension = 73 [default = true ];
+ optional string default_string_extension = 74 [default = "hello"];
+ optional bytes default_bytes_extension = 75 [default = "world"];
+
+ optional TestAllTypes.NestedEnum
+ default_nested_enum_extension = 81 [default = BAR];
+ optional ForeignEnum
+ default_foreign_enum_extension = 82 [default = FOREIGN_BAR];
+ optional protobuf_unittest_import.ImportEnum
+ default_import_enum_extension = 83 [default = IMPORT_BAR];
+
+ optional string default_string_piece_extension = 84 [ctype=STRING_PIECE,
+ default="abc"];
+ optional string default_cord_extension = 85 [ctype=CORD, default="123"];
+}
+
+message TestNestedExtension {
+ extend TestAllExtensions {
+ // Check for bug where string extensions declared in tested scope did not
+ // compile.
+ optional string test = 1002 [default="test"];
+ }
+}
+
+// We have separate messages for testing required fields because it's
+// annoying to have to fill in required fields in TestProto in order to
+// do anything with it. Note that we don't need to test every type of
+// required filed because the code output is basically identical to
+// optional fields for all types.
+message TestRequired {
+ required int32 a = 1;
+ optional int32 dummy2 = 2;
+ required int32 b = 3;
+
+ extend TestAllExtensions {
+ optional TestRequired single = 1000;
+ repeated TestRequired multi = 1001;
+ }
+
+ // Pad the field count to 32 so that we can test that IsInitialized()
+ // properly checks multiple elements of has_bits_.
+ optional int32 dummy4 = 4;
+ optional int32 dummy5 = 5;
+ optional int32 dummy6 = 6;
+ optional int32 dummy7 = 7;
+ optional int32 dummy8 = 8;
+ optional int32 dummy9 = 9;
+ optional int32 dummy10 = 10;
+ optional int32 dummy11 = 11;
+ optional int32 dummy12 = 12;
+ optional int32 dummy13 = 13;
+ optional int32 dummy14 = 14;
+ optional int32 dummy15 = 15;
+ optional int32 dummy16 = 16;
+ optional int32 dummy17 = 17;
+ optional int32 dummy18 = 18;
+ optional int32 dummy19 = 19;
+ optional int32 dummy20 = 20;
+ optional int32 dummy21 = 21;
+ optional int32 dummy22 = 22;
+ optional int32 dummy23 = 23;
+ optional int32 dummy24 = 24;
+ optional int32 dummy25 = 25;
+ optional int32 dummy26 = 26;
+ optional int32 dummy27 = 27;
+ optional int32 dummy28 = 28;
+ optional int32 dummy29 = 29;
+ optional int32 dummy30 = 30;
+ optional int32 dummy31 = 31;
+ optional int32 dummy32 = 32;
+
+ required int32 c = 33;
+}
+
+message TestRequiredForeign {
+ optional TestRequired optional_message = 1;
+ repeated TestRequired repeated_message = 2;
+ optional int32 dummy = 3;
+}
+
+// Test that we can use NestedMessage from outside TestAllTypes.
+message TestForeignNested {
+ optional TestAllTypes.NestedMessage foreign_nested = 1;
+}
+
+// TestEmptyMessage is used to test unknown field support.
+message TestEmptyMessage {
+}
+
+// Like above, but declare all field numbers as potential extensions. No
+// actual extensions should ever be defined for this type.
+message TestEmptyMessageWithExtensions {
+ extensions 1 to max;
+}
+
+message TestMultipleExtensionRanges {
+ extensions 42;
+ extensions 4143 to 4243;
+ extensions 65536 to max;
+}
+
+// Test that really large tag numbers don't break anything.
+message TestReallyLargeTagNumber {
+ // The largest possible tag number is 2^28 - 1, since the wire format uses
+ // three bits to communicate wire type.
+ optional int32 a = 1;
+ optional int32 bb = 268435455;
+}
+
+message TestRecursiveMessage {
+ optional TestRecursiveMessage a = 1;
+ optional int32 i = 2;
+}
+
+// Test that mutual recursion works.
+message TestMutualRecursionA {
+ optional TestMutualRecursionB bb = 1;
+}
+
+message TestMutualRecursionB {
+ optional TestMutualRecursionA a = 1;
+ optional int32 optional_int32 = 2;
+}
+
+// Test that groups have disjoint field numbers from their siblings and
+// parents. This is NOT possible in proto1; only proto2. When attempting
+// to compile with proto1, this will emit an error; so we only include it
+// in protobuf_unittest_proto.
+message TestDupFieldNumber { // NO_PROTO1
+ optional int32 a = 1; // NO_PROTO1
+ optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1
+ optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1
+} // NO_PROTO1
+
+// Additional messages for testing lazy fields.
+message TestEagerMessage {
+ optional TestAllTypes sub_message = 1 [lazy=false];
+}
+message TestLazyMessage {
+ optional TestAllTypes sub_message = 1 [lazy=true];
+}
+
+// Needed for a Python test.
+message TestNestedMessageHasBits {
+ message NestedMessage {
+ repeated int32 nestedmessage_repeated_int32 = 1;
+ repeated ForeignMessage nestedmessage_repeated_foreignmessage = 2;
+ }
+ optional NestedMessage optional_nested_message = 1;
+}
+
+
+// Test an enum that has multiple values with the same number.
+enum TestEnumWithDupValue {
+ option allow_alias = true;
+ FOO1 = 1;
+ BAR1 = 2;
+ BAZ = 3;
+ FOO2 = 1;
+ BAR2 = 2;
+}
+
+// Test an enum with large, unordered values.
+enum TestSparseEnum {
+ SPARSE_A = 123;
+ SPARSE_B = 62374;
+ SPARSE_C = 12589234;
+ SPARSE_D = -15;
+ SPARSE_E = -53452;
+ SPARSE_F = 0;
+ SPARSE_G = 2;
+}
+
+// Test message with CamelCase field names. This violates Protocol Buffer
+// standard style.
+message TestCamelCaseFieldNames {
+ optional int32 PrimitiveField = 1;
+ optional string StringField = 2;
+ optional ForeignEnum EnumField = 3;
+ optional ForeignMessage MessageField = 4;
+ optional string StringPieceField = 5 [ctype=STRING_PIECE];
+ optional string CordField = 6 [ctype=CORD];
+
+ repeated int32 RepeatedPrimitiveField = 7;
+ repeated string RepeatedStringField = 8;
+ repeated ForeignEnum RepeatedEnumField = 9;
+ repeated ForeignMessage RepeatedMessageField = 10;
+ repeated string RepeatedStringPieceField = 11 [ctype=STRING_PIECE];
+ repeated string RepeatedCordField = 12 [ctype=CORD];
+}
+
+
+// We list fields out of order, to ensure that we're using field number and not
+// field index to determine serialization order.
+message TestFieldOrderings {
+ optional string my_string = 11;
+ extensions 2 to 10;
+ optional int64 my_int = 1;
+ extensions 12 to 100;
+ optional float my_float = 101;
+}
+
+
+extend TestFieldOrderings {
+ optional string my_extension_string = 50;
+ optional int32 my_extension_int = 5;
+}
+
+
+message TestExtremeDefaultValues {
+ optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"];
+ optional uint32 large_uint32 = 2 [default = 0xFFFFFFFF];
+ optional uint64 large_uint64 = 3 [default = 0xFFFFFFFFFFFFFFFF];
+ optional int32 small_int32 = 4 [default = -0x7FFFFFFF];
+ optional int64 small_int64 = 5 [default = -0x7FFFFFFFFFFFFFFF];
+ optional int32 really_small_int32 = 21 [default = -0x80000000];
+ optional int64 really_small_int64 = 22 [default = -0x8000000000000000];
+
+ // The default value here is UTF-8 for "\u1234". (We could also just type
+ // the UTF-8 text directly into this text file rather than escape it, but
+ // lots of people use editors that would be confused by this.)
+ optional string utf8_string = 6 [default = "\341\210\264"];
+
+ // Tests for single-precision floating-point values.
+ optional float zero_float = 7 [default = 0];
+ optional float one_float = 8 [default = 1];
+ optional float small_float = 9 [default = 1.5];
+ optional float negative_one_float = 10 [default = -1];
+ optional float negative_float = 11 [default = -1.5];
+ // Using exponents
+ optional float large_float = 12 [default = 2E8];
+ optional float small_negative_float = 13 [default = -8e-28];
+
+ // Text for nonfinite floating-point values.
+ optional double inf_double = 14 [default = inf];
+ optional double neg_inf_double = 15 [default = -inf];
+ optional double nan_double = 16 [default = nan];
+ optional float inf_float = 17 [default = inf];
+ optional float neg_inf_float = 18 [default = -inf];
+ optional float nan_float = 19 [default = nan];
+
+ // Tests for C++ trigraphs.
+ // Trigraphs should be escaped in C++ generated files, but they should not be
+ // escaped for other languages.
+ // Note that in .proto file, "\?" is a valid way to escape ? in string
+ // literals.
+ optional string cpp_trigraph = 20 [default = "? \? ?? \?? \??? ??/ ?\?-"];
+
+ // String defaults containing the character '\000'
+ optional string string_with_zero = 23 [default = "hel\000lo"];
+ optional bytes bytes_with_zero = 24 [default = "wor\000ld"];
+ optional string string_piece_with_zero = 25 [ctype=STRING_PIECE,
+ default="ab\000c"];
+ optional string cord_with_zero = 26 [ctype=CORD,
+ default="12\0003"];
+}
+
+message SparseEnumMessage {
+ optional TestSparseEnum sparse_enum = 1;
+}
+
+// Test String and Bytes: string is for valid UTF-8 strings
+message OneString {
+ optional string data = 1;
+}
+
+message MoreString {
+ repeated string data = 1;
+}
+
+message OneBytes {
+ optional bytes data = 1;
+}
+
+message MoreBytes {
+ repeated bytes data = 1;
+}
+
+
+// Test messages for packed fields
+
+message TestPackedTypes {
+ repeated int32 packed_int32 = 90 [packed = true];
+ repeated int64 packed_int64 = 91 [packed = true];
+ repeated uint32 packed_uint32 = 92 [packed = true];
+ repeated uint64 packed_uint64 = 93 [packed = true];
+ repeated sint32 packed_sint32 = 94 [packed = true];
+ repeated sint64 packed_sint64 = 95 [packed = true];
+ repeated fixed32 packed_fixed32 = 96 [packed = true];
+ repeated fixed64 packed_fixed64 = 97 [packed = true];
+ repeated sfixed32 packed_sfixed32 = 98 [packed = true];
+ repeated sfixed64 packed_sfixed64 = 99 [packed = true];
+ repeated float packed_float = 100 [packed = true];
+ repeated double packed_double = 101 [packed = true];
+ repeated bool packed_bool = 102 [packed = true];
+ repeated ForeignEnum packed_enum = 103 [packed = true];
+}
+
+// A message with the same fields as TestPackedTypes, but without packing. Used
+// to test packed <-> unpacked wire compatibility.
+message TestUnpackedTypes {
+ repeated int32 unpacked_int32 = 90 [packed = false];
+ repeated int64 unpacked_int64 = 91 [packed = false];
+ repeated uint32 unpacked_uint32 = 92 [packed = false];
+ repeated uint64 unpacked_uint64 = 93 [packed = false];
+ repeated sint32 unpacked_sint32 = 94 [packed = false];
+ repeated sint64 unpacked_sint64 = 95 [packed = false];
+ repeated fixed32 unpacked_fixed32 = 96 [packed = false];
+ repeated fixed64 unpacked_fixed64 = 97 [packed = false];
+ repeated sfixed32 unpacked_sfixed32 = 98 [packed = false];
+ repeated sfixed64 unpacked_sfixed64 = 99 [packed = false];
+ repeated float unpacked_float = 100 [packed = false];
+ repeated double unpacked_double = 101 [packed = false];
+ repeated bool unpacked_bool = 102 [packed = false];
+ repeated ForeignEnum unpacked_enum = 103 [packed = false];
+}
+
+message TestPackedExtensions {
+ extensions 1 to max;
+}
+
+extend TestPackedExtensions {
+ repeated int32 packed_int32_extension = 90 [packed = true];
+ repeated int64 packed_int64_extension = 91 [packed = true];
+ repeated uint32 packed_uint32_extension = 92 [packed = true];
+ repeated uint64 packed_uint64_extension = 93 [packed = true];
+ repeated sint32 packed_sint32_extension = 94 [packed = true];
+ repeated sint64 packed_sint64_extension = 95 [packed = true];
+ repeated fixed32 packed_fixed32_extension = 96 [packed = true];
+ repeated fixed64 packed_fixed64_extension = 97 [packed = true];
+ repeated sfixed32 packed_sfixed32_extension = 98 [packed = true];
+ repeated sfixed64 packed_sfixed64_extension = 99 [packed = true];
+ repeated float packed_float_extension = 100 [packed = true];
+ repeated double packed_double_extension = 101 [packed = true];
+ repeated bool packed_bool_extension = 102 [packed = true];
+ repeated ForeignEnum packed_enum_extension = 103 [packed = true];
+}
+
+// Used by ExtensionSetTest/DynamicExtensions. The test actually builds
+// a set of extensions to TestAllExtensions dynamically, based on the fields
+// of this message type.
+message TestDynamicExtensions {
+ enum DynamicEnumType {
+ DYNAMIC_FOO = 2200;
+ DYNAMIC_BAR = 2201;
+ DYNAMIC_BAZ = 2202;
+ }
+ message DynamicMessageType {
+ optional int32 dynamic_field = 2100;
+ }
+
+ optional fixed32 scalar_extension = 2000;
+ optional ForeignEnum enum_extension = 2001;
+ optional DynamicEnumType dynamic_enum_extension = 2002;
+
+ optional ForeignMessage message_extension = 2003;
+ optional DynamicMessageType dynamic_message_extension = 2004;
+
+ repeated string repeated_extension = 2005;
+ repeated sint32 packed_extension = 2006 [packed = true];
+}
+
+message TestRepeatedScalarDifferentTagSizes {
+ // Parsing repeated fixed size values used to fail. This message needs to be
+ // used in order to get a tag of the right size; all of the repeated fields
+ // in TestAllTypes didn't trigger the check.
+ repeated fixed32 repeated_fixed32 = 12;
+ // Check for a varint type, just for good measure.
+ repeated int32 repeated_int32 = 13;
+
+ // These have two-byte tags.
+ repeated fixed64 repeated_fixed64 = 2046;
+ repeated int64 repeated_int64 = 2047;
+
+ // Three byte tags.
+ repeated float repeated_float = 262142;
+ repeated uint64 repeated_uint64 = 262143;
+}
+
+// Test that if an optional or required message/group field appears multiple
+// times in the input, they need to be merged.
+message TestParsingMerge {
+ // RepeatedFieldsGenerator defines matching field types as TestParsingMerge,
+ // except that all fields are repeated. In the tests, we will serialize the
+ // RepeatedFieldsGenerator to bytes, and parse the bytes to TestParsingMerge.
+ // Repeated fields in RepeatedFieldsGenerator are expected to be merged into
+ // the corresponding required/optional fields in TestParsingMerge.
+ message RepeatedFieldsGenerator {
+ repeated TestAllTypes field1 = 1;
+ repeated TestAllTypes field2 = 2;
+ repeated TestAllTypes field3 = 3;
+ repeated group Group1 = 10 {
+ optional TestAllTypes field1 = 11;
+ }
+ repeated group Group2 = 20 {
+ optional TestAllTypes field1 = 21;
+ }
+ repeated TestAllTypes ext1 = 1000;
+ repeated TestAllTypes ext2 = 1001;
+ }
+ required TestAllTypes required_all_types = 1;
+ optional TestAllTypes optional_all_types = 2;
+ repeated TestAllTypes repeated_all_types = 3;
+ optional group OptionalGroup = 10 {
+ optional TestAllTypes optional_group_all_types = 11;
+ }
+ repeated group RepeatedGroup = 20 {
+ optional TestAllTypes repeated_group_all_types = 21;
+ }
+ extensions 1000 to max;
+ extend TestParsingMerge {
+ optional TestAllTypes optional_ext = 1000;
+ repeated TestAllTypes repeated_ext = 1001;
+ }
+}
+
+message TestCommentInjectionMessage {
+ // */ <- This should not close the generated doc comment
+ optional string a = 1 [default="*/ <- Neither should this."];
+}
+
+
+// Test that RPC services work.
+message FooRequest {}
+message FooResponse {}
+
+message FooClientMessage {}
+message FooServerMessage{}
+
+service TestService {
+ rpc Foo(FooRequest) returns (FooResponse);
+ rpc Bar(BarRequest) returns (BarResponse);
+}
+
+
+message BarRequest {}
+message BarResponse {}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_custom_options.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_custom_options.proto
new file mode 100644
index 0000000000..e591d29447
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_custom_options.proto
@@ -0,0 +1,387 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: benjy@google.com (Benjy Weinberger)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file used to test the "custom options" feature of proto2.
+
+
+// Some generic_services option(s) added automatically.
+// See: http://go/proto2-generic-services-default
+option cc_generic_services = true; // auto-added
+option java_generic_services = true; // auto-added
+option py_generic_services = true;
+
+// A custom file option (defined below).
+option (file_opt1) = 9876543210;
+
+import "google/protobuf/descriptor.proto";
+
+// We don't put this in a package within proto2 because we need to make sure
+// that the generated code doesn't depend on being in the proto2 namespace.
+package protobuf_unittest;
+
+
+// Some simple test custom options of various types.
+
+extend google.protobuf.FileOptions {
+ optional uint64 file_opt1 = 7736974;
+}
+
+extend google.protobuf.MessageOptions {
+ optional int32 message_opt1 = 7739036;
+}
+
+extend google.protobuf.FieldOptions {
+ optional fixed64 field_opt1 = 7740936;
+ // This is useful for testing that we correctly register default values for
+ // extension options.
+ optional int32 field_opt2 = 7753913 [default=42];
+}
+
+extend google.protobuf.EnumOptions {
+ optional sfixed32 enum_opt1 = 7753576;
+}
+
+extend google.protobuf.EnumValueOptions {
+ optional int32 enum_value_opt1 = 1560678;
+}
+
+extend google.protobuf.ServiceOptions {
+ optional sint64 service_opt1 = 7887650;
+}
+
+enum MethodOpt1 {
+ METHODOPT1_VAL1 = 1;
+ METHODOPT1_VAL2 = 2;
+}
+
+extend google.protobuf.MethodOptions {
+ optional MethodOpt1 method_opt1 = 7890860;
+}
+
+// A test message with custom options at all possible locations (and also some
+// regular options, to make sure they interact nicely).
+message TestMessageWithCustomOptions {
+ option message_set_wire_format = false;
+
+ option (message_opt1) = -56;
+
+ optional string field1 = 1 [ctype=CORD,
+ (field_opt1)=8765432109];
+
+ enum AnEnum {
+ option (enum_opt1) = -789;
+
+ ANENUM_VAL1 = 1;
+ ANENUM_VAL2 = 2 [(enum_value_opt1) = 123];
+ }
+}
+
+
+// A test RPC service with custom options at all possible locations (and also
+// some regular options, to make sure they interact nicely).
+message CustomOptionFooRequest {
+}
+
+message CustomOptionFooResponse {
+}
+
+message CustomOptionFooClientMessage {
+}
+
+message CustomOptionFooServerMessage {
+}
+
+service TestServiceWithCustomOptions {
+ option (service_opt1) = -9876543210;
+
+ rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
+ option (method_opt1) = METHODOPT1_VAL2;
+ }
+}
+
+
+
+// Options of every possible field type, so we can test them all exhaustively.
+
+message DummyMessageContainingEnum {
+ enum TestEnumType {
+ TEST_OPTION_ENUM_TYPE1 = 22;
+ TEST_OPTION_ENUM_TYPE2 = -23;
+ }
+}
+
+message DummyMessageInvalidAsOptionType {
+}
+
+extend google.protobuf.MessageOptions {
+ optional bool bool_opt = 7706090;
+ optional int32 int32_opt = 7705709;
+ optional int64 int64_opt = 7705542;
+ optional uint32 uint32_opt = 7704880;
+ optional uint64 uint64_opt = 7702367;
+ optional sint32 sint32_opt = 7701568;
+ optional sint64 sint64_opt = 7700863;
+ optional fixed32 fixed32_opt = 7700307;
+ optional fixed64 fixed64_opt = 7700194;
+ optional sfixed32 sfixed32_opt = 7698645;
+ optional sfixed64 sfixed64_opt = 7685475;
+ optional float float_opt = 7675390;
+ optional double double_opt = 7673293;
+ optional string string_opt = 7673285;
+ optional bytes bytes_opt = 7673238;
+ optional DummyMessageContainingEnum.TestEnumType enum_opt = 7673233;
+ optional DummyMessageInvalidAsOptionType message_type_opt = 7665967;
+}
+
+message CustomOptionMinIntegerValues {
+ option (bool_opt) = false;
+ option (int32_opt) = -0x80000000;
+ option (int64_opt) = -0x8000000000000000;
+ option (uint32_opt) = 0;
+ option (uint64_opt) = 0;
+ option (sint32_opt) = -0x80000000;
+ option (sint64_opt) = -0x8000000000000000;
+ option (fixed32_opt) = 0;
+ option (fixed64_opt) = 0;
+ option (sfixed32_opt) = -0x80000000;
+ option (sfixed64_opt) = -0x8000000000000000;
+}
+
+message CustomOptionMaxIntegerValues {
+ option (bool_opt) = true;
+ option (int32_opt) = 0x7FFFFFFF;
+ option (int64_opt) = 0x7FFFFFFFFFFFFFFF;
+ option (uint32_opt) = 0xFFFFFFFF;
+ option (uint64_opt) = 0xFFFFFFFFFFFFFFFF;
+ option (sint32_opt) = 0x7FFFFFFF;
+ option (sint64_opt) = 0x7FFFFFFFFFFFFFFF;
+ option (fixed32_opt) = 0xFFFFFFFF;
+ option (fixed64_opt) = 0xFFFFFFFFFFFFFFFF;
+ option (sfixed32_opt) = 0x7FFFFFFF;
+ option (sfixed64_opt) = 0x7FFFFFFFFFFFFFFF;
+}
+
+message CustomOptionOtherValues {
+ option (int32_opt) = -100; // To test sign-extension.
+ option (float_opt) = 12.3456789;
+ option (double_opt) = 1.234567890123456789;
+ option (string_opt) = "Hello, \"World\"";
+ option (bytes_opt) = "Hello\0World";
+ option (enum_opt) = TEST_OPTION_ENUM_TYPE2;
+}
+
+message SettingRealsFromPositiveInts {
+ option (float_opt) = 12;
+ option (double_opt) = 154;
+}
+
+message SettingRealsFromNegativeInts {
+ option (float_opt) = -12;
+ option (double_opt) = -154;
+}
+
+// Options of complex message types, themselves combined and extended in
+// various ways.
+
+message ComplexOptionType1 {
+ optional int32 foo = 1;
+ optional int32 foo2 = 2;
+ optional int32 foo3 = 3;
+
+ extensions 100 to max;
+}
+
+message ComplexOptionType2 {
+ optional ComplexOptionType1 bar = 1;
+ optional int32 baz = 2;
+
+ message ComplexOptionType4 {
+ optional int32 waldo = 1;
+
+ extend google.protobuf.MessageOptions {
+ optional ComplexOptionType4 complex_opt4 = 7633546;
+ }
+ }
+
+ optional ComplexOptionType4 fred = 3;
+
+ extensions 100 to max;
+}
+
+message ComplexOptionType3 {
+ optional int32 qux = 1;
+
+ optional group ComplexOptionType5 = 2 {
+ optional int32 plugh = 3;
+ }
+}
+
+extend ComplexOptionType1 {
+ optional int32 quux = 7663707;
+ optional ComplexOptionType3 corge = 7663442;
+}
+
+extend ComplexOptionType2 {
+ optional int32 grault = 7650927;
+ optional ComplexOptionType1 garply = 7649992;
+}
+
+extend google.protobuf.MessageOptions {
+ optional protobuf_unittest.ComplexOptionType1 complex_opt1 = 7646756;
+ optional ComplexOptionType2 complex_opt2 = 7636949;
+ optional ComplexOptionType3 complex_opt3 = 7636463;
+ optional group ComplexOpt6 = 7595468 {
+ optional int32 xyzzy = 7593951;
+ }
+}
+
+// Note that we try various different ways of naming the same extension.
+message VariousComplexOptions {
+ option (.protobuf_unittest.complex_opt1).foo = 42;
+ option (protobuf_unittest.complex_opt1).(.protobuf_unittest.quux) = 324;
+ option (.protobuf_unittest.complex_opt1).(protobuf_unittest.corge).qux = 876;
+ option (complex_opt2).baz = 987;
+ option (complex_opt2).(grault) = 654;
+ option (complex_opt2).bar.foo = 743;
+ option (complex_opt2).bar.(quux) = 1999;
+ option (complex_opt2).bar.(protobuf_unittest.corge).qux = 2008;
+ option (complex_opt2).(garply).foo = 741;
+ option (complex_opt2).(garply).(.protobuf_unittest.quux) = 1998;
+ option (complex_opt2).(protobuf_unittest.garply).(corge).qux = 2121;
+ option (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo = 1971;
+ option (complex_opt2).fred.waldo = 321;
+ option (protobuf_unittest.complex_opt3).qux = 9;
+ option (complex_opt3).complexoptiontype5.plugh = 22;
+ option (complexopt6).xyzzy = 24;
+}
+
+// ------------------------------------------------------
+// Definitions for testing aggregate option parsing.
+// See descriptor_unittest.cc.
+
+message AggregateMessageSet {
+ option message_set_wire_format = true;
+ extensions 4 to max;
+}
+
+message AggregateMessageSetElement {
+ extend AggregateMessageSet {
+ optional AggregateMessageSetElement message_set_extension = 15447542;
+ }
+ optional string s = 1;
+}
+
+// A helper type used to test aggregate option parsing
+message Aggregate {
+ optional int32 i = 1;
+ optional string s = 2;
+
+ // A nested object
+ optional Aggregate sub = 3;
+
+ // To test the parsing of extensions inside aggregate values
+ optional google.protobuf.FileOptions file = 4;
+ extend google.protobuf.FileOptions {
+ optional Aggregate nested = 15476903;
+ }
+
+ // An embedded message set
+ optional AggregateMessageSet mset = 5;
+}
+
+// Allow Aggregate to be used as an option at all possible locations
+// in the .proto grammer.
+extend google.protobuf.FileOptions { optional Aggregate fileopt = 15478479; }
+extend google.protobuf.MessageOptions { optional Aggregate msgopt = 15480088; }
+extend google.protobuf.FieldOptions { optional Aggregate fieldopt = 15481374; }
+extend google.protobuf.EnumOptions { optional Aggregate enumopt = 15483218; }
+extend google.protobuf.EnumValueOptions { optional Aggregate enumvalopt = 15486921; }
+extend google.protobuf.ServiceOptions { optional Aggregate serviceopt = 15497145; }
+extend google.protobuf.MethodOptions { optional Aggregate methodopt = 15512713; }
+
+// Try using AggregateOption at different points in the proto grammar
+option (fileopt) = {
+ s: 'FileAnnotation'
+ // Also test the handling of comments
+ /* of both types */ i: 100
+
+ sub { s: 'NestedFileAnnotation' }
+
+ // Include a google.protobuf.FileOptions and recursively extend it with
+ // another fileopt.
+ file {
+ [protobuf_unittest.fileopt] {
+ s:'FileExtensionAnnotation'
+ }
+ }
+
+ // A message set inside an option value
+ mset {
+ [protobuf_unittest.AggregateMessageSetElement.message_set_extension] {
+ s: 'EmbeddedMessageSetElement'
+ }
+ }
+};
+
+message AggregateMessage {
+ option (msgopt) = { i:101 s:'MessageAnnotation' };
+ optional int32 fieldname = 1 [(fieldopt) = { s:'FieldAnnotation' }];
+}
+
+service AggregateService {
+ option (serviceopt) = { s:'ServiceAnnotation' };
+ rpc Method (AggregateMessage) returns (AggregateMessage) {
+ option (methodopt) = { s:'MethodAnnotation' };
+ }
+}
+
+enum AggregateEnum {
+ option (enumopt) = { s:'EnumAnnotation' };
+ VALUE = 1 [(enumvalopt) = { s:'EnumValueAnnotation' }];
+}
+
+// Test custom options for nested type.
+message NestedOptionType {
+ message NestedMessage {
+ option (message_opt1) = 1001;
+ optional int32 nested_field = 1 [(field_opt1) = 1002];
+ }
+ enum NestedEnum {
+ option (enum_opt1) = 1003;
+ NESTED_ENUM_VALUE = 1 [(enum_value_opt1) = 1004];
+ }
+ extend google.protobuf.FileOptions {
+ optional int32 nested_extension = 7912573 [(field_opt2) = 1005];
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_embed_optimize_for.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_embed_optimize_for.proto
new file mode 100644
index 0000000000..fa1762594e
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_embed_optimize_for.proto
@@ -0,0 +1,50 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file which imports a proto file that uses optimize_for = CODE_SIZE.
+
+import "google/protobuf/unittest_optimize_for.proto";
+
+package protobuf_unittest;
+
+// We optimize for speed here, but we are importing a proto that is optimized
+// for code size.
+option optimize_for = SPEED;
+
+message TestEmbedOptimizedForSize {
+ // Test that embedding a message which has optimize_for = CODE_SIZE into
+ // one optimized for speed works.
+ optional TestOptimizedForSize optional_message = 1;
+ repeated TestOptimizedForSize repeated_message = 2;
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_empty.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_empty.proto
new file mode 100644
index 0000000000..ab12d1fb9f
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_empty.proto
@@ -0,0 +1,37 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// This file intentionally left blank. (At one point this wouldn't compile
+// correctly.)
+
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_enormous_descriptor.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_enormous_descriptor.proto
new file mode 100644
index 0000000000..bc0b7c16a0
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_enormous_descriptor.proto
@@ -0,0 +1,1046 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file that has an extremely large descriptor. Used to test that
+// descriptors over 64k don't break the string literal length limit in Java.
+
+
+package google.protobuf;
+option java_package = "com.google.protobuf";
+
+// Avoid generating insanely long methods.
+option optimize_for = CODE_SIZE;
+
+message TestEnormousDescriptor {
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_1 = 1 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_2 = 2 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_3 = 3 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_4 = 4 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_5 = 5 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_6 = 6 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_7 = 7 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_8 = 8 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_9 = 9 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_10 = 10 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_11 = 11 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_12 = 12 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_13 = 13 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_14 = 14 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_15 = 15 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_16 = 16 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_17 = 17 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_18 = 18 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_19 = 19 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_20 = 20 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_21 = 21 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_22 = 22 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_23 = 23 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_24 = 24 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_25 = 25 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_26 = 26 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_27 = 27 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_28 = 28 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_29 = 29 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_30 = 30 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_31 = 31 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_32 = 32 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_33 = 33 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_34 = 34 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_35 = 35 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_36 = 36 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_37 = 37 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_38 = 38 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_39 = 39 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_40 = 40 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_41 = 41 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_42 = 42 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_43 = 43 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_44 = 44 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_45 = 45 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_46 = 46 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_47 = 47 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_48 = 48 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_49 = 49 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_50 = 50 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_51 = 51 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_52 = 52 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_53 = 53 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_54 = 54 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_55 = 55 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_56 = 56 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_57 = 57 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_58 = 58 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_59 = 59 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_60 = 60 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_61 = 61 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_62 = 62 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_63 = 63 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_64 = 64 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_65 = 65 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_66 = 66 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_67 = 67 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_68 = 68 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_69 = 69 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_70 = 70 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_71 = 71 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_72 = 72 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_73 = 73 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_74 = 74 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_75 = 75 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_76 = 76 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_77 = 77 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_78 = 78 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_79 = 79 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_80 = 80 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_81 = 81 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_82 = 82 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_83 = 83 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_84 = 84 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_85 = 85 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_86 = 86 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_87 = 87 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_88 = 88 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_89 = 89 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_90 = 90 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_91 = 91 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_92 = 92 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_93 = 93 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_94 = 94 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_95 = 95 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_96 = 96 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_97 = 97 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_98 = 98 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_99 = 99 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_100 = 100 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_101 = 101 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_102 = 102 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_103 = 103 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_104 = 104 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_105 = 105 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_106 = 106 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_107 = 107 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_108 = 108 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_109 = 109 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_110 = 110 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_111 = 111 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_112 = 112 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_113 = 113 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_114 = 114 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_115 = 115 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_116 = 116 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_117 = 117 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_118 = 118 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_119 = 119 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_120 = 120 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_121 = 121 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_122 = 122 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_123 = 123 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_124 = 124 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_125 = 125 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_126 = 126 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_127 = 127 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_128 = 128 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_129 = 129 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_130 = 130 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_131 = 131 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_132 = 132 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_133 = 133 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_134 = 134 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_135 = 135 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_136 = 136 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_137 = 137 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_138 = 138 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_139 = 139 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_140 = 140 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_141 = 141 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_142 = 142 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_143 = 143 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_144 = 144 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_145 = 145 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_146 = 146 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_147 = 147 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_148 = 148 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_149 = 149 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_150 = 150 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_151 = 151 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_152 = 152 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_153 = 153 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_154 = 154 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_155 = 155 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_156 = 156 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_157 = 157 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_158 = 158 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_159 = 159 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_160 = 160 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_161 = 161 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_162 = 162 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_163 = 163 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_164 = 164 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_165 = 165 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_166 = 166 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_167 = 167 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_168 = 168 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_169 = 169 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_170 = 170 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_171 = 171 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_172 = 172 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_173 = 173 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_174 = 174 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_175 = 175 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_176 = 176 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_177 = 177 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_178 = 178 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_179 = 179 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_180 = 180 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_181 = 181 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_182 = 182 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_183 = 183 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_184 = 184 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_185 = 185 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_186 = 186 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_187 = 187 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_188 = 188 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_189 = 189 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_190 = 190 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_191 = 191 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_192 = 192 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_193 = 193 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_194 = 194 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_195 = 195 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_196 = 196 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_197 = 197 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_198 = 198 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_199 = 199 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_200 = 200 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_201 = 201 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_202 = 202 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_203 = 203 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_204 = 204 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_205 = 205 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_206 = 206 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_207 = 207 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_208 = 208 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_209 = 209 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_210 = 210 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_211 = 211 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_212 = 212 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_213 = 213 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_214 = 214 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_215 = 215 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_216 = 216 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_217 = 217 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_218 = 218 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_219 = 219 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_220 = 220 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_221 = 221 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_222 = 222 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_223 = 223 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_224 = 224 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_225 = 225 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_226 = 226 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_227 = 227 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_228 = 228 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_229 = 229 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_230 = 230 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_231 = 231 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_232 = 232 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_233 = 233 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_234 = 234 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_235 = 235 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_236 = 236 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_237 = 237 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_238 = 238 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_239 = 239 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_240 = 240 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_241 = 241 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_242 = 242 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_243 = 243 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_244 = 244 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_245 = 245 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_246 = 246 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_247 = 247 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_248 = 248 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_249 = 249 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_250 = 250 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_251 = 251 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_252 = 252 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_253 = 253 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_254 = 254 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_255 = 255 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_256 = 256 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_257 = 257 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_258 = 258 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_259 = 259 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_260 = 260 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_261 = 261 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_262 = 262 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_263 = 263 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_264 = 264 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_265 = 265 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_266 = 266 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_267 = 267 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_268 = 268 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_269 = 269 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_270 = 270 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_271 = 271 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_272 = 272 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_273 = 273 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_274 = 274 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_275 = 275 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_276 = 276 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_277 = 277 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_278 = 278 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_279 = 279 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_280 = 280 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_281 = 281 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_282 = 282 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_283 = 283 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_284 = 284 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_285 = 285 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_286 = 286 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_287 = 287 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_288 = 288 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_289 = 289 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_290 = 290 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_291 = 291 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_292 = 292 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_293 = 293 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_294 = 294 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_295 = 295 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_296 = 296 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_297 = 297 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_298 = 298 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_299 = 299 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_300 = 300 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_301 = 301 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_302 = 302 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_303 = 303 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_304 = 304 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_305 = 305 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_306 = 306 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_307 = 307 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_308 = 308 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_309 = 309 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_310 = 310 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_311 = 311 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_312 = 312 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_313 = 313 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_314 = 314 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_315 = 315 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_316 = 316 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_317 = 317 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_318 = 318 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_319 = 319 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_320 = 320 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_321 = 321 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_322 = 322 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_323 = 323 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_324 = 324 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_325 = 325 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_326 = 326 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_327 = 327 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_328 = 328 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_329 = 329 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_330 = 330 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_331 = 331 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_332 = 332 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_333 = 333 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_334 = 334 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_335 = 335 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_336 = 336 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_337 = 337 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_338 = 338 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_339 = 339 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_340 = 340 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_341 = 341 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_342 = 342 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_343 = 343 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_344 = 344 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_345 = 345 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_346 = 346 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_347 = 347 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_348 = 348 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_349 = 349 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_350 = 350 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_351 = 351 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_352 = 352 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_353 = 353 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_354 = 354 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_355 = 355 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_356 = 356 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_357 = 357 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_358 = 358 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_359 = 359 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_360 = 360 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_361 = 361 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_362 = 362 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_363 = 363 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_364 = 364 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_365 = 365 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_366 = 366 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_367 = 367 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_368 = 368 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_369 = 369 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_370 = 370 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_371 = 371 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_372 = 372 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_373 = 373 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_374 = 374 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_375 = 375 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_376 = 376 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_377 = 377 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_378 = 378 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_379 = 379 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_380 = 380 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_381 = 381 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_382 = 382 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_383 = 383 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_384 = 384 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_385 = 385 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_386 = 386 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_387 = 387 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_388 = 388 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_389 = 389 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_390 = 390 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_391 = 391 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_392 = 392 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_393 = 393 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_394 = 394 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_395 = 395 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_396 = 396 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_397 = 397 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_398 = 398 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_399 = 399 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_400 = 400 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_401 = 401 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_402 = 402 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_403 = 403 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_404 = 404 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_405 = 405 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_406 = 406 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_407 = 407 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_408 = 408 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_409 = 409 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_410 = 410 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_411 = 411 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_412 = 412 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_413 = 413 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_414 = 414 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_415 = 415 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_416 = 416 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_417 = 417 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_418 = 418 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_419 = 419 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_420 = 420 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_421 = 421 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_422 = 422 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_423 = 423 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_424 = 424 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_425 = 425 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_426 = 426 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_427 = 427 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_428 = 428 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_429 = 429 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_430 = 430 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_431 = 431 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_432 = 432 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_433 = 433 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_434 = 434 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_435 = 435 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_436 = 436 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_437 = 437 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_438 = 438 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_439 = 439 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_440 = 440 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_441 = 441 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_442 = 442 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_443 = 443 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_444 = 444 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_445 = 445 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_446 = 446 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_447 = 447 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_448 = 448 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_449 = 449 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_450 = 450 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_451 = 451 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_452 = 452 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_453 = 453 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_454 = 454 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_455 = 455 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_456 = 456 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_457 = 457 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_458 = 458 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_459 = 459 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_460 = 460 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_461 = 461 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_462 = 462 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_463 = 463 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_464 = 464 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_465 = 465 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_466 = 466 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_467 = 467 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_468 = 468 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_469 = 469 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_470 = 470 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_471 = 471 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_472 = 472 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_473 = 473 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_474 = 474 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_475 = 475 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_476 = 476 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_477 = 477 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_478 = 478 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_479 = 479 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_480 = 480 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_481 = 481 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_482 = 482 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_483 = 483 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_484 = 484 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_485 = 485 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_486 = 486 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_487 = 487 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_488 = 488 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_489 = 489 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_490 = 490 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_491 = 491 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_492 = 492 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_493 = 493 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_494 = 494 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_495 = 495 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_496 = 496 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_497 = 497 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_498 = 498 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_499 = 499 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_500 = 500 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_501 = 501 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_502 = 502 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_503 = 503 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_504 = 504 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_505 = 505 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_506 = 506 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_507 = 507 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_508 = 508 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_509 = 509 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_510 = 510 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_511 = 511 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_512 = 512 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_513 = 513 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_514 = 514 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_515 = 515 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_516 = 516 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_517 = 517 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_518 = 518 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_519 = 519 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_520 = 520 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_521 = 521 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_522 = 522 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_523 = 523 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_524 = 524 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_525 = 525 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_526 = 526 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_527 = 527 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_528 = 528 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_529 = 529 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_530 = 530 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_531 = 531 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_532 = 532 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_533 = 533 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_534 = 534 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_535 = 535 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_536 = 536 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_537 = 537 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_538 = 538 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_539 = 539 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_540 = 540 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_541 = 541 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_542 = 542 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_543 = 543 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_544 = 544 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_545 = 545 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_546 = 546 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_547 = 547 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_548 = 548 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_549 = 549 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_550 = 550 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_551 = 551 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_552 = 552 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_553 = 553 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_554 = 554 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_555 = 555 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_556 = 556 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_557 = 557 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_558 = 558 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_559 = 559 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_560 = 560 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_561 = 561 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_562 = 562 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_563 = 563 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_564 = 564 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_565 = 565 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_566 = 566 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_567 = 567 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_568 = 568 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_569 = 569 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_570 = 570 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_571 = 571 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_572 = 572 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_573 = 573 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_574 = 574 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_575 = 575 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_576 = 576 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_577 = 577 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_578 = 578 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_579 = 579 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_580 = 580 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_581 = 581 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_582 = 582 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_583 = 583 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_584 = 584 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_585 = 585 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_586 = 586 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_587 = 587 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_588 = 588 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_589 = 589 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_590 = 590 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_591 = 591 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_592 = 592 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_593 = 593 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_594 = 594 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_595 = 595 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_596 = 596 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_597 = 597 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_598 = 598 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_599 = 599 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_600 = 600 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_601 = 601 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_602 = 602 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_603 = 603 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_604 = 604 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_605 = 605 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_606 = 606 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_607 = 607 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_608 = 608 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_609 = 609 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_610 = 610 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_611 = 611 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_612 = 612 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_613 = 613 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_614 = 614 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_615 = 615 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_616 = 616 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_617 = 617 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_618 = 618 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_619 = 619 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_620 = 620 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_621 = 621 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_622 = 622 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_623 = 623 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_624 = 624 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_625 = 625 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_626 = 626 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_627 = 627 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_628 = 628 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_629 = 629 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_630 = 630 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_631 = 631 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_632 = 632 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_633 = 633 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_634 = 634 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_635 = 635 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_636 = 636 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_637 = 637 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_638 = 638 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_639 = 639 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_640 = 640 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_641 = 641 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_642 = 642 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_643 = 643 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_644 = 644 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_645 = 645 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_646 = 646 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_647 = 647 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_648 = 648 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_649 = 649 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_650 = 650 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_651 = 651 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_652 = 652 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_653 = 653 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_654 = 654 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_655 = 655 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_656 = 656 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_657 = 657 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_658 = 658 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_659 = 659 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_660 = 660 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_661 = 661 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_662 = 662 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_663 = 663 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_664 = 664 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_665 = 665 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_666 = 666 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_667 = 667 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_668 = 668 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_669 = 669 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_670 = 670 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_671 = 671 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_672 = 672 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_673 = 673 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_674 = 674 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_675 = 675 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_676 = 676 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_677 = 677 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_678 = 678 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_679 = 679 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_680 = 680 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_681 = 681 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_682 = 682 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_683 = 683 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_684 = 684 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_685 = 685 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_686 = 686 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_687 = 687 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_688 = 688 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_689 = 689 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_690 = 690 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_691 = 691 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_692 = 692 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_693 = 693 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_694 = 694 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_695 = 695 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_696 = 696 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_697 = 697 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_698 = 698 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_699 = 699 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_700 = 700 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_701 = 701 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_702 = 702 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_703 = 703 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_704 = 704 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_705 = 705 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_706 = 706 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_707 = 707 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_708 = 708 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_709 = 709 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_710 = 710 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_711 = 711 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_712 = 712 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_713 = 713 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_714 = 714 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_715 = 715 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_716 = 716 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_717 = 717 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_718 = 718 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_719 = 719 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_720 = 720 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_721 = 721 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_722 = 722 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_723 = 723 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_724 = 724 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_725 = 725 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_726 = 726 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_727 = 727 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_728 = 728 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_729 = 729 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_730 = 730 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_731 = 731 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_732 = 732 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_733 = 733 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_734 = 734 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_735 = 735 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_736 = 736 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_737 = 737 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_738 = 738 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_739 = 739 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_740 = 740 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_741 = 741 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_742 = 742 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_743 = 743 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_744 = 744 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_745 = 745 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_746 = 746 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_747 = 747 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_748 = 748 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_749 = 749 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_750 = 750 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_751 = 751 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_752 = 752 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_753 = 753 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_754 = 754 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_755 = 755 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_756 = 756 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_757 = 757 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_758 = 758 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_759 = 759 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_760 = 760 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_761 = 761 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_762 = 762 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_763 = 763 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_764 = 764 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_765 = 765 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_766 = 766 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_767 = 767 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_768 = 768 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_769 = 769 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_770 = 770 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_771 = 771 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_772 = 772 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_773 = 773 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_774 = 774 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_775 = 775 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_776 = 776 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_777 = 777 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_778 = 778 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_779 = 779 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_780 = 780 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_781 = 781 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_782 = 782 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_783 = 783 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_784 = 784 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_785 = 785 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_786 = 786 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_787 = 787 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_788 = 788 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_789 = 789 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_790 = 790 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_791 = 791 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_792 = 792 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_793 = 793 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_794 = 794 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_795 = 795 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_796 = 796 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_797 = 797 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_798 = 798 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_799 = 799 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_800 = 800 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_801 = 801 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_802 = 802 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_803 = 803 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_804 = 804 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_805 = 805 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_806 = 806 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_807 = 807 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_808 = 808 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_809 = 809 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_810 = 810 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_811 = 811 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_812 = 812 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_813 = 813 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_814 = 814 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_815 = 815 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_816 = 816 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_817 = 817 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_818 = 818 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_819 = 819 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_820 = 820 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_821 = 821 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_822 = 822 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_823 = 823 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_824 = 824 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_825 = 825 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_826 = 826 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_827 = 827 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_828 = 828 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_829 = 829 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_830 = 830 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_831 = 831 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_832 = 832 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_833 = 833 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_834 = 834 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_835 = 835 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_836 = 836 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_837 = 837 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_838 = 838 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_839 = 839 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_840 = 840 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_841 = 841 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_842 = 842 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_843 = 843 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_844 = 844 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_845 = 845 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_846 = 846 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_847 = 847 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_848 = 848 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_849 = 849 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_850 = 850 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_851 = 851 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_852 = 852 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_853 = 853 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_854 = 854 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_855 = 855 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_856 = 856 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_857 = 857 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_858 = 858 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_859 = 859 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_860 = 860 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_861 = 861 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_862 = 862 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_863 = 863 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_864 = 864 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_865 = 865 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_866 = 866 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_867 = 867 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_868 = 868 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_869 = 869 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_870 = 870 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_871 = 871 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_872 = 872 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_873 = 873 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_874 = 874 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_875 = 875 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_876 = 876 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_877 = 877 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_878 = 878 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_879 = 879 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_880 = 880 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_881 = 881 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_882 = 882 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_883 = 883 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_884 = 884 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_885 = 885 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_886 = 886 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_887 = 887 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_888 = 888 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_889 = 889 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_890 = 890 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_891 = 891 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_892 = 892 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_893 = 893 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_894 = 894 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_895 = 895 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_896 = 896 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_897 = 897 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_898 = 898 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_899 = 899 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_900 = 900 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_901 = 901 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_902 = 902 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_903 = 903 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_904 = 904 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_905 = 905 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_906 = 906 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_907 = 907 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_908 = 908 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_909 = 909 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_910 = 910 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_911 = 911 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_912 = 912 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_913 = 913 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_914 = 914 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_915 = 915 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_916 = 916 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_917 = 917 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_918 = 918 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_919 = 919 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_920 = 920 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_921 = 921 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_922 = 922 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_923 = 923 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_924 = 924 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_925 = 925 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_926 = 926 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_927 = 927 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_928 = 928 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_929 = 929 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_930 = 930 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_931 = 931 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_932 = 932 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_933 = 933 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_934 = 934 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_935 = 935 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_936 = 936 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_937 = 937 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_938 = 938 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_939 = 939 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_940 = 940 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_941 = 941 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_942 = 942 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_943 = 943 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_944 = 944 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_945 = 945 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_946 = 946 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_947 = 947 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_948 = 948 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_949 = 949 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_950 = 950 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_951 = 951 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_952 = 952 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_953 = 953 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_954 = 954 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_955 = 955 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_956 = 956 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_957 = 957 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_958 = 958 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_959 = 959 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_960 = 960 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_961 = 961 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_962 = 962 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_963 = 963 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_964 = 964 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_965 = 965 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_966 = 966 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_967 = 967 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_968 = 968 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_969 = 969 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_970 = 970 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_971 = 971 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_972 = 972 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_973 = 973 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_974 = 974 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_975 = 975 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_976 = 976 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_977 = 977 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_978 = 978 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_979 = 979 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_980 = 980 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_981 = 981 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_982 = 982 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_983 = 983 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_984 = 984 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_985 = 985 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_986 = 986 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_987 = 987 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_988 = 988 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_989 = 989 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_990 = 990 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_991 = 991 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_992 = 992 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_993 = 993 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_994 = 994 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_995 = 995 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_996 = 996 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_997 = 997 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_998 = 998 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_999 = 999 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+ optional string long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_1000 = 1000 [default="long default value is also loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong"];
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import.proto
new file mode 100644
index 0000000000..c115b11171
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import.proto
@@ -0,0 +1,64 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file which is imported by unittest.proto to test importing.
+
+
+// We don't put this in a package within proto2 because we need to make sure
+// that the generated code doesn't depend on being in the proto2 namespace.
+// In test_util.h we do
+// "using namespace unittest_import = protobuf_unittest_import".
+package protobuf_unittest_import;
+
+option optimize_for = SPEED;
+
+// Excercise the java_package option.
+option java_package = "com.google.protobuf.test";
+
+// Do not set a java_outer_classname here to verify that Proto2 works without
+// one.
+
+// Test public import
+import public "google/protobuf/unittest_import_public.proto";
+
+message ImportMessage {
+ optional int32 d = 1;
+}
+
+enum ImportEnum {
+ IMPORT_FOO = 7;
+ IMPORT_BAR = 8;
+ IMPORT_BAZ = 9;
+}
+
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import_lite.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import_lite.proto
new file mode 100644
index 0000000000..81b117fe84
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import_lite.proto
@@ -0,0 +1,51 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+//
+// This is like unittest_import.proto but with optimize_for = LITE_RUNTIME.
+
+package protobuf_unittest_import;
+
+option optimize_for = LITE_RUNTIME;
+
+option java_package = "com.google.protobuf";
+
+import public "google/protobuf/unittest_import_public_lite.proto";
+
+message ImportMessageLite {
+ optional int32 d = 1;
+}
+
+enum ImportEnumLite {
+ IMPORT_LITE_FOO = 7;
+ IMPORT_LITE_BAR = 8;
+ IMPORT_LITE_BAZ = 9;
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import_public.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import_public.proto
new file mode 100644
index 0000000000..ea5d1b13fe
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import_public.proto
@@ -0,0 +1,40 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: liujisi@google.com (Pherl Liu)
+
+
+package protobuf_unittest_import;
+
+option java_package = "com.google.protobuf.test";
+
+message PublicImportMessage {
+ optional int32 e = 1;
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import_public_lite.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import_public_lite.proto
new file mode 100644
index 0000000000..d077563cbd
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import_public_lite.proto
@@ -0,0 +1,42 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: liujisi@google.com (Pherl Liu)
+
+
+package protobuf_unittest_import;
+
+option optimize_for = LITE_RUNTIME;
+
+option java_package = "com.google.protobuf";
+
+message PublicImportMessageLite {
+ optional int32 e = 1;
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_lite.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_lite.proto
new file mode 100644
index 0000000000..a1764aac8d
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_lite.proto
@@ -0,0 +1,360 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+//
+// This is like unittest.proto but with optimize_for = LITE_RUNTIME.
+
+package protobuf_unittest;
+
+import "google/protobuf/unittest_import_lite.proto";
+
+option optimize_for = LITE_RUNTIME;
+
+option java_package = "com.google.protobuf";
+
+// Same as TestAllTypes but with the lite runtime.
+message TestAllTypesLite {
+ message NestedMessage {
+ optional int32 bb = 1;
+ }
+
+ enum NestedEnum {
+ FOO = 1;
+ BAR = 2;
+ BAZ = 3;
+ }
+
+ // Singular
+ optional int32 optional_int32 = 1;
+ optional int64 optional_int64 = 2;
+ optional uint32 optional_uint32 = 3;
+ optional uint64 optional_uint64 = 4;
+ optional sint32 optional_sint32 = 5;
+ optional sint64 optional_sint64 = 6;
+ optional fixed32 optional_fixed32 = 7;
+ optional fixed64 optional_fixed64 = 8;
+ optional sfixed32 optional_sfixed32 = 9;
+ optional sfixed64 optional_sfixed64 = 10;
+ optional float optional_float = 11;
+ optional double optional_double = 12;
+ optional bool optional_bool = 13;
+ optional string optional_string = 14;
+ optional bytes optional_bytes = 15;
+
+ optional group OptionalGroup = 16 {
+ optional int32 a = 17;
+ }
+
+ optional NestedMessage optional_nested_message = 18;
+ optional ForeignMessageLite optional_foreign_message = 19;
+ optional protobuf_unittest_import.ImportMessageLite
+ optional_import_message = 20;
+
+ optional NestedEnum optional_nested_enum = 21;
+ optional ForeignEnumLite optional_foreign_enum = 22;
+ optional protobuf_unittest_import.ImportEnumLite optional_import_enum = 23;
+
+ optional string optional_string_piece = 24 [ctype=STRING_PIECE];
+ optional string optional_cord = 25 [ctype=CORD];
+
+ // Defined in unittest_import_public.proto
+ optional protobuf_unittest_import.PublicImportMessageLite
+ optional_public_import_message = 26;
+
+ optional NestedMessage optional_lazy_message = 27 [lazy=true];
+
+ // Repeated
+ repeated int32 repeated_int32 = 31;
+ repeated int64 repeated_int64 = 32;
+ repeated uint32 repeated_uint32 = 33;
+ repeated uint64 repeated_uint64 = 34;
+ repeated sint32 repeated_sint32 = 35;
+ repeated sint64 repeated_sint64 = 36;
+ repeated fixed32 repeated_fixed32 = 37;
+ repeated fixed64 repeated_fixed64 = 38;
+ repeated sfixed32 repeated_sfixed32 = 39;
+ repeated sfixed64 repeated_sfixed64 = 40;
+ repeated float repeated_float = 41;
+ repeated double repeated_double = 42;
+ repeated bool repeated_bool = 43;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+
+ repeated group RepeatedGroup = 46 {
+ optional int32 a = 47;
+ }
+
+ repeated NestedMessage repeated_nested_message = 48;
+ repeated ForeignMessageLite repeated_foreign_message = 49;
+ repeated protobuf_unittest_import.ImportMessageLite
+ repeated_import_message = 50;
+
+ repeated NestedEnum repeated_nested_enum = 51;
+ repeated ForeignEnumLite repeated_foreign_enum = 52;
+ repeated protobuf_unittest_import.ImportEnumLite repeated_import_enum = 53;
+
+ repeated string repeated_string_piece = 54 [ctype=STRING_PIECE];
+ repeated string repeated_cord = 55 [ctype=CORD];
+
+ repeated NestedMessage repeated_lazy_message = 57 [lazy=true];
+
+ // Singular with defaults
+ optional int32 default_int32 = 61 [default = 41 ];
+ optional int64 default_int64 = 62 [default = 42 ];
+ optional uint32 default_uint32 = 63 [default = 43 ];
+ optional uint64 default_uint64 = 64 [default = 44 ];
+ optional sint32 default_sint32 = 65 [default = -45 ];
+ optional sint64 default_sint64 = 66 [default = 46 ];
+ optional fixed32 default_fixed32 = 67 [default = 47 ];
+ optional fixed64 default_fixed64 = 68 [default = 48 ];
+ optional sfixed32 default_sfixed32 = 69 [default = 49 ];
+ optional sfixed64 default_sfixed64 = 70 [default = -50 ];
+ optional float default_float = 71 [default = 51.5 ];
+ optional double default_double = 72 [default = 52e3 ];
+ optional bool default_bool = 73 [default = true ];
+ optional string default_string = 74 [default = "hello"];
+ optional bytes default_bytes = 75 [default = "world"];
+
+ optional NestedEnum default_nested_enum = 81 [default = BAR];
+ optional ForeignEnumLite default_foreign_enum = 82
+ [default = FOREIGN_LITE_BAR];
+ optional protobuf_unittest_import.ImportEnumLite
+ default_import_enum = 83 [default = IMPORT_LITE_BAR];
+
+ optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"];
+ optional string default_cord = 85 [ctype=CORD,default="123"];
+}
+
+message ForeignMessageLite {
+ optional int32 c = 1;
+}
+
+enum ForeignEnumLite {
+ FOREIGN_LITE_FOO = 4;
+ FOREIGN_LITE_BAR = 5;
+ FOREIGN_LITE_BAZ = 6;
+}
+
+message TestPackedTypesLite {
+ repeated int32 packed_int32 = 90 [packed = true];
+ repeated int64 packed_int64 = 91 [packed = true];
+ repeated uint32 packed_uint32 = 92 [packed = true];
+ repeated uint64 packed_uint64 = 93 [packed = true];
+ repeated sint32 packed_sint32 = 94 [packed = true];
+ repeated sint64 packed_sint64 = 95 [packed = true];
+ repeated fixed32 packed_fixed32 = 96 [packed = true];
+ repeated fixed64 packed_fixed64 = 97 [packed = true];
+ repeated sfixed32 packed_sfixed32 = 98 [packed = true];
+ repeated sfixed64 packed_sfixed64 = 99 [packed = true];
+ repeated float packed_float = 100 [packed = true];
+ repeated double packed_double = 101 [packed = true];
+ repeated bool packed_bool = 102 [packed = true];
+ repeated ForeignEnumLite packed_enum = 103 [packed = true];
+}
+
+message TestAllExtensionsLite {
+ extensions 1 to max;
+}
+
+extend TestAllExtensionsLite {
+ // Singular
+ optional int32 optional_int32_extension_lite = 1;
+ optional int64 optional_int64_extension_lite = 2;
+ optional uint32 optional_uint32_extension_lite = 3;
+ optional uint64 optional_uint64_extension_lite = 4;
+ optional sint32 optional_sint32_extension_lite = 5;
+ optional sint64 optional_sint64_extension_lite = 6;
+ optional fixed32 optional_fixed32_extension_lite = 7;
+ optional fixed64 optional_fixed64_extension_lite = 8;
+ optional sfixed32 optional_sfixed32_extension_lite = 9;
+ optional sfixed64 optional_sfixed64_extension_lite = 10;
+ optional float optional_float_extension_lite = 11;
+ optional double optional_double_extension_lite = 12;
+ optional bool optional_bool_extension_lite = 13;
+ optional string optional_string_extension_lite = 14;
+ optional bytes optional_bytes_extension_lite = 15;
+
+ optional group OptionalGroup_extension_lite = 16 {
+ optional int32 a = 17;
+ }
+
+ optional TestAllTypesLite.NestedMessage optional_nested_message_extension_lite
+ = 18;
+ optional ForeignMessageLite optional_foreign_message_extension_lite = 19;
+ optional protobuf_unittest_import.ImportMessageLite
+ optional_import_message_extension_lite = 20;
+
+ optional TestAllTypesLite.NestedEnum optional_nested_enum_extension_lite = 21;
+ optional ForeignEnumLite optional_foreign_enum_extension_lite = 22;
+ optional protobuf_unittest_import.ImportEnumLite
+ optional_import_enum_extension_lite = 23;
+
+ optional string optional_string_piece_extension_lite = 24
+ [ctype=STRING_PIECE];
+ optional string optional_cord_extension_lite = 25 [ctype=CORD];
+
+ optional protobuf_unittest_import.PublicImportMessageLite
+ optional_public_import_message_extension_lite = 26;
+
+ optional TestAllTypesLite.NestedMessage
+ optional_lazy_message_extension_lite = 27 [lazy=true];
+
+ // Repeated
+ repeated int32 repeated_int32_extension_lite = 31;
+ repeated int64 repeated_int64_extension_lite = 32;
+ repeated uint32 repeated_uint32_extension_lite = 33;
+ repeated uint64 repeated_uint64_extension_lite = 34;
+ repeated sint32 repeated_sint32_extension_lite = 35;
+ repeated sint64 repeated_sint64_extension_lite = 36;
+ repeated fixed32 repeated_fixed32_extension_lite = 37;
+ repeated fixed64 repeated_fixed64_extension_lite = 38;
+ repeated sfixed32 repeated_sfixed32_extension_lite = 39;
+ repeated sfixed64 repeated_sfixed64_extension_lite = 40;
+ repeated float repeated_float_extension_lite = 41;
+ repeated double repeated_double_extension_lite = 42;
+ repeated bool repeated_bool_extension_lite = 43;
+ repeated string repeated_string_extension_lite = 44;
+ repeated bytes repeated_bytes_extension_lite = 45;
+
+ repeated group RepeatedGroup_extension_lite = 46 {
+ optional int32 a = 47;
+ }
+
+ repeated TestAllTypesLite.NestedMessage repeated_nested_message_extension_lite
+ = 48;
+ repeated ForeignMessageLite repeated_foreign_message_extension_lite = 49;
+ repeated protobuf_unittest_import.ImportMessageLite
+ repeated_import_message_extension_lite = 50;
+
+ repeated TestAllTypesLite.NestedEnum repeated_nested_enum_extension_lite = 51;
+ repeated ForeignEnumLite repeated_foreign_enum_extension_lite = 52;
+ repeated protobuf_unittest_import.ImportEnumLite
+ repeated_import_enum_extension_lite = 53;
+
+ repeated string repeated_string_piece_extension_lite = 54
+ [ctype=STRING_PIECE];
+ repeated string repeated_cord_extension_lite = 55 [ctype=CORD];
+
+ repeated TestAllTypesLite.NestedMessage
+ repeated_lazy_message_extension_lite = 57 [lazy=true];
+
+ // Singular with defaults
+ optional int32 default_int32_extension_lite = 61 [default = 41 ];
+ optional int64 default_int64_extension_lite = 62 [default = 42 ];
+ optional uint32 default_uint32_extension_lite = 63 [default = 43 ];
+ optional uint64 default_uint64_extension_lite = 64 [default = 44 ];
+ optional sint32 default_sint32_extension_lite = 65 [default = -45 ];
+ optional sint64 default_sint64_extension_lite = 66 [default = 46 ];
+ optional fixed32 default_fixed32_extension_lite = 67 [default = 47 ];
+ optional fixed64 default_fixed64_extension_lite = 68 [default = 48 ];
+ optional sfixed32 default_sfixed32_extension_lite = 69 [default = 49 ];
+ optional sfixed64 default_sfixed64_extension_lite = 70 [default = -50 ];
+ optional float default_float_extension_lite = 71 [default = 51.5 ];
+ optional double default_double_extension_lite = 72 [default = 52e3 ];
+ optional bool default_bool_extension_lite = 73 [default = true ];
+ optional string default_string_extension_lite = 74 [default = "hello"];
+ optional bytes default_bytes_extension_lite = 75 [default = "world"];
+
+ optional TestAllTypesLite.NestedEnum
+ default_nested_enum_extension_lite = 81 [default = BAR];
+ optional ForeignEnumLite
+ default_foreign_enum_extension_lite = 82 [default = FOREIGN_LITE_BAR];
+ optional protobuf_unittest_import.ImportEnumLite
+ default_import_enum_extension_lite = 83 [default = IMPORT_LITE_BAR];
+
+ optional string default_string_piece_extension_lite = 84 [ctype=STRING_PIECE,
+ default="abc"];
+ optional string default_cord_extension_lite = 85 [ctype=CORD, default="123"];
+}
+
+message TestPackedExtensionsLite {
+ extensions 1 to max;
+}
+
+extend TestPackedExtensionsLite {
+ repeated int32 packed_int32_extension_lite = 90 [packed = true];
+ repeated int64 packed_int64_extension_lite = 91 [packed = true];
+ repeated uint32 packed_uint32_extension_lite = 92 [packed = true];
+ repeated uint64 packed_uint64_extension_lite = 93 [packed = true];
+ repeated sint32 packed_sint32_extension_lite = 94 [packed = true];
+ repeated sint64 packed_sint64_extension_lite = 95 [packed = true];
+ repeated fixed32 packed_fixed32_extension_lite = 96 [packed = true];
+ repeated fixed64 packed_fixed64_extension_lite = 97 [packed = true];
+ repeated sfixed32 packed_sfixed32_extension_lite = 98 [packed = true];
+ repeated sfixed64 packed_sfixed64_extension_lite = 99 [packed = true];
+ repeated float packed_float_extension_lite = 100 [packed = true];
+ repeated double packed_double_extension_lite = 101 [packed = true];
+ repeated bool packed_bool_extension_lite = 102 [packed = true];
+ repeated ForeignEnumLite packed_enum_extension_lite = 103 [packed = true];
+}
+
+message TestNestedExtensionLite {
+ extend TestAllExtensionsLite {
+ optional int32 nested_extension = 12345;
+ }
+}
+
+// Test that deprecated fields work. We only verify that they compile (at one
+// point this failed).
+message TestDeprecatedLite {
+ optional int32 deprecated_field = 1 [deprecated = true];
+}
+
+// See the comments of the same type in unittest.proto.
+message TestParsingMergeLite {
+ message RepeatedFieldsGenerator {
+ repeated TestAllTypesLite field1 = 1;
+ repeated TestAllTypesLite field2 = 2;
+ repeated TestAllTypesLite field3 = 3;
+ repeated group Group1 = 10 {
+ optional TestAllTypesLite field1 = 11;
+ }
+ repeated group Group2 = 20 {
+ optional TestAllTypesLite field1 = 21;
+ }
+ repeated TestAllTypesLite ext1 = 1000;
+ repeated TestAllTypesLite ext2 = 1001;
+ }
+ required TestAllTypesLite required_all_types = 1;
+ optional TestAllTypesLite optional_all_types = 2;
+ repeated TestAllTypesLite repeated_all_types = 3;
+ optional group OptionalGroup = 10 {
+ optional TestAllTypesLite optional_group_all_types = 11;
+ }
+ repeated group RepeatedGroup = 20 {
+ optional TestAllTypesLite repeated_group_all_types = 21;
+ }
+ extensions 1000 to max;
+ extend TestParsingMergeLite {
+ optional TestAllTypesLite optional_ext = 1000;
+ repeated TestAllTypesLite repeated_ext = 1001;
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_lite_imports_nonlite.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_lite_imports_nonlite.proto
new file mode 100644
index 0000000000..d52cb8cc36
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_lite_imports_nonlite.proto
@@ -0,0 +1,43 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+//
+// Tests that a "lite" message can import a regular message.
+
+package protobuf_unittest;
+
+import "google/protobuf/unittest.proto";
+
+option optimize_for = LITE_RUNTIME;
+
+message TestLiteImportsNonlite {
+ optional TestAllTypes message = 1;
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_mset.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_mset.proto
new file mode 100644
index 0000000000..3497f09fa6
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_mset.proto
@@ -0,0 +1,72 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// This file contains messages for testing message_set_wire_format.
+
+package protobuf_unittest;
+
+option optimize_for = SPEED;
+
+// A message with message_set_wire_format.
+message TestMessageSet {
+ option message_set_wire_format = true;
+ extensions 4 to max;
+}
+
+message TestMessageSetContainer {
+ optional TestMessageSet message_set = 1;
+}
+
+message TestMessageSetExtension1 {
+ extend TestMessageSet {
+ optional TestMessageSetExtension1 message_set_extension = 1545008;
+ }
+ optional int32 i = 15;
+}
+
+message TestMessageSetExtension2 {
+ extend TestMessageSet {
+ optional TestMessageSetExtension2 message_set_extension = 1547769;
+ }
+ optional string str = 25;
+}
+
+// MessageSet wire format is equivalent to this.
+message RawMessageSet {
+ repeated group Item = 1 {
+ required int32 type_id = 2;
+ required bytes message = 3;
+ }
+}
+
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_no_generic_services.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_no_generic_services.proto
new file mode 100644
index 0000000000..cffb4122c5
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_no_generic_services.proto
@@ -0,0 +1,52 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+
+package google.protobuf.no_generic_services_test;
+
+// *_generic_services are false by default.
+
+message TestMessage {
+ optional int32 a = 1;
+ extensions 1000 to max;
+}
+
+enum TestEnum {
+ FOO = 1;
+}
+
+extend TestMessage {
+ optional int32 test_extension = 1000;
+}
+
+service TestService {
+ rpc Foo(TestMessage) returns(TestMessage);
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_optimize_for.proto b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_optimize_for.proto
new file mode 100644
index 0000000000..feecbef8d4
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_optimize_for.proto
@@ -0,0 +1,61 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file which uses optimize_for = CODE_SIZE.
+
+import "google/protobuf/unittest.proto";
+
+package protobuf_unittest;
+
+option optimize_for = CODE_SIZE;
+
+message TestOptimizedForSize {
+ optional int32 i = 1;
+ optional ForeignMessage msg = 19;
+
+ extensions 1000 to max;
+
+ extend TestOptimizedForSize {
+ optional int32 test_extension = 1234;
+ optional TestRequiredOptimizedForSize test_extension2 = 1235;
+ }
+}
+
+message TestRequiredOptimizedForSize {
+ required int32 x = 1;
+}
+
+message TestOptionalOptimizedForSize {
+ optional TestRequiredOptimizedForSize o = 1;
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/test.sh b/third_party/protobuf/java/compatibility_tests/v2.5.0/test.sh
new file mode 100755
index 0000000000..5d5e9ed439
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/test.sh
@@ -0,0 +1,140 @@
+#!/bin/bash
+
+set -ex
+
+# Change to the script's directory.
+cd $(dirname $0)
+
+# Version of the tests (i.e., the version of protobuf from where we extracted
+# these tests).
+TEST_VERSION=`grep "^ <version>.*</version>" pom.xml | sed "s| <version>\(.*\)</version>|\1|"`
+
+# The old version of protobuf that we are testing compatibility against. This
+# is usually the same as TEST_VERSION (i.e., we use the tests extracted from
+# that version to test compatibility of the newest runtime against it), but it
+# is also possible to use this same test set to test the compatibiilty of the
+# latest version against other versions.
+case "$1" in
+ ""|2.5.0)
+ OLD_VERSION=2.5.0
+ OLD_VERSION_PROTOC=https://github.com/xfxyjwf/protobuf-compiler-release/raw/master/v2.5.0/linux/protoc
+ ;;
+ 2.6.1)
+ OLD_VERSION=2.6.1
+ OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/2.6.1-build2/protoc-2.6.1-build2-linux-x86_64.exe
+ ;;
+ 3.0.0-beta-1)
+ OLD_VERSION=3.0.0-beta-1
+ OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-1/protoc-3.0.0-beta-1-linux-x86_64.exe
+ ;;
+ 3.0.0-beta-2)
+ OLD_VERSION=3.0.0-beta-2
+ OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-2/protoc-3.0.0-beta-2-linux-x86_64.exe
+ ;;
+ 3.0.0-beta-3)
+ OLD_VERSION=3.0.0-beta-3
+ OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-3/protoc-3.0.0-beta-3-linux-x86_64.exe
+ ;;
+ 3.0.0-beta-4)
+ OLD_VERSION=3.0.0-beta-4
+ OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-4/protoc-3.0.0-beta-4-linux-x86_64.exe
+ ;;
+ *)
+ echo "[ERROR]: Unknown version number: $1"
+ exit 1
+ ;;
+esac
+
+# Extract the latest protobuf version number.
+VERSION_NUMBER=`grep "^ <version>.*</version>" ../../pom.xml | sed "s| <version>\(.*\)</version>|\1|"`
+
+echo "Running compatibility tests between $VERSION_NUMBER and $OLD_VERSION"
+
+# Check protoc
+[ -f ../../../src/protoc ] || {
+ echo "[ERROR]: Please build protoc first."
+ exit 1
+}
+
+# Build and install protobuf-java-$VERSION_NUMBER.jar
+[ -f ../../core/target/protobuf-java-$VERSION_NUMBER.jar ] || {
+ pushd ../..
+ mvn install -Dmaven.test.skip=true
+ popd
+}
+
+# Download old version source for the compatibility test
+[ -d protobuf ] || {
+ git clone https://github.com/google/protobuf.git
+ cd protobuf
+ git reset --hard v$TEST_VERSION
+ cd ..
+}
+
+# Download old version protoc compiler (for linux)
+wget $OLD_VERSION_PROTOC -O protoc
+chmod +x protoc
+
+# Test source compatibility. In these tests we recompile everything against
+# the new runtime (including old version generated code).
+
+# Test A.1:
+# protos: use new version
+# more_protos: use old version
+mvn clean test \
+ -Dprotobuf.test.source.path=$(pwd)/protobuf \
+ -Dprotoc.path=$(pwd)/protoc \
+ -Dprotos.protoc.path=$(pwd)/../../../src/protoc \
+ -Dprotobuf.version=$VERSION_NUMBER
+
+# Test A.2:
+# protos: use old version
+# more_protos: use new version
+mvn clean test \
+ -Dprotobuf.test.source.path=$(pwd)/protobuf \
+ -Dprotoc.path=$(pwd)/protoc \
+ -Dmore_protos.protoc.path=$(pwd)/../../../src/protoc \
+ -Dprotobuf.version=$VERSION_NUMBER
+
+# Test binary compatibility. In these tests we run the old version compiled
+# jar against the new runtime directly without recompile.
+
+# Collect all test dependencies in a single jar file (except for protobuf) to
+# make it easier to run binary compatibility test (where we will need to run
+# the jar files directly).
+cd deps
+mvn assembly:single
+cd ..
+cp -f deps/target/compatibility-test-deps-${TEST_VERSION}-jar-with-dependencies.jar deps.jar
+
+# Build the old version of all 3 artifacts.
+mvn clean install -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/protoc -Dprotobuf.version=$OLD_VERSION
+cp -f protos/target/compatibility-protos-${TEST_VERSION}.jar protos.jar
+cp -f more_protos/target/compatibility-more-protos-${TEST_VERSION}.jar more_protos.jar
+cp -f tests/target/compatibility-tests-${TEST_VERSION}.jar tests.jar
+
+# Collect the list of tests we need to run.
+TESTS=`find tests -name "*Test.java" | sed "s|/|.|g;s/.java$//g;s/tests.src.main.java.//g"`
+
+# Test B.1: run all the old artifacts against the new runtime. Note that we
+# must run the test in the protobuf source tree because some of the tests need
+# to read golden test data files.
+cd protobuf
+java -cp ../../../core/target/protobuf-java-$VERSION_NUMBER.jar:../protos.jar:../more_protos.jar:../tests.jar:../deps.jar org.junit.runner.JUnitCore $TESTS
+cd ..
+
+# Test B.2: update protos.jar only.
+cd protos
+mvn clean package -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/../../../../src/protoc -Dprotobuf.version=$VERSION_NUMBER
+cd ..
+cd protobuf
+java -cp ../../../core/target/protobuf-java-$VERSION_NUMBER.jar:../protos/target/compatibility-protos-${TEST_VERSION}.jar:../more_protos.jar:../tests.jar:../deps.jar org.junit.runner.JUnitCore $TESTS
+cd ..
+
+# Test B.3: update more_protos.jar only.
+cd more_protos
+mvn clean package -Dmaven.test.skip=true -Dprotoc.path=$(pwd)/../../../../src/protoc -Dprotobuf.version=$VERSION_NUMBER
+cd ..
+cd protobuf
+java -cp ../../../core/target/protobuf-java-$VERSION_NUMBER.jar:../protos.jar:../more_protos/target/compatibility-more-protos-${TEST_VERSION}.jar:../tests.jar:../deps.jar org.junit.runner.JUnitCore $TESTS
+cd ..
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/pom.xml b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/pom.xml
new file mode 100644
index 0000000000..f1ce46e7ab
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/pom.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>com.google.protobuf.compatibility</groupId>
+ <artifactId>compatibility-test-suite</artifactId>
+ <version>2.5.0</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <groupId>com.google.protobuf.compatibility</groupId>
+ <artifactId>compatibility-tests</artifactId>
+ <version>2.5.0</version>
+
+ <name>Compatibility Tests</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <version>2.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.protobuf</groupId>
+ <artifactId>protobuf-java</artifactId>
+ <version>${tests.protobuf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.protobuf.compatibility</groupId>
+ <artifactId>compatibility-protos</artifactId>
+ <version>2.5.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.protobuf.compatibility</groupId>
+ <artifactId>compatibility-more-protos</artifactId>
+ <version>2.5.0</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <testSourceDirectory>${basedir}/src/main/java/</testSourceDirectory>
+ <testClassesDirectory>${project.build.directory}/classes/</testClassesDirectory>
+ <includes>
+ <include>**/*Test.java</include>
+ </includes>
+ <workingDirectory>${protobuf.test.source.path}</workingDirectory>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/AbstractMessageTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/AbstractMessageTest.java
new file mode 100644
index 0000000000..6789550c49
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/AbstractMessageTest.java
@@ -0,0 +1,510 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import com.google.protobuf.Descriptors.FieldDescriptor;
+import protobuf_unittest.UnittestOptimizeFor.TestOptimizedForSize;
+import protobuf_unittest.UnittestProto;
+import protobuf_unittest.UnittestProto.ForeignMessage;
+import protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+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;
+
+/**
+ * Unit test for {@link AbstractMessage}.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class AbstractMessageTest extends TestCase {
+ /**
+ * Extends AbstractMessage and wraps some other message object. The methods
+ * of the Message interface which aren't explicitly implemented by
+ * AbstractMessage are forwarded to the wrapped object. This allows us to
+ * test that AbstractMessage's implementations work even if the wrapped
+ * object does not use them.
+ */
+ private static class AbstractMessageWrapper extends AbstractMessage {
+ private final Message wrappedMessage;
+
+ public AbstractMessageWrapper(Message wrappedMessage) {
+ this.wrappedMessage = wrappedMessage;
+ }
+
+ public Descriptors.Descriptor getDescriptorForType() {
+ return wrappedMessage.getDescriptorForType();
+ }
+ public AbstractMessageWrapper getDefaultInstanceForType() {
+ return new AbstractMessageWrapper(
+ wrappedMessage.getDefaultInstanceForType());
+ }
+ public Map<Descriptors.FieldDescriptor, Object> getAllFields() {
+ return wrappedMessage.getAllFields();
+ }
+ public boolean hasField(Descriptors.FieldDescriptor field) {
+ return wrappedMessage.hasField(field);
+ }
+ public Object getField(Descriptors.FieldDescriptor field) {
+ return wrappedMessage.getField(field);
+ }
+ public int getRepeatedFieldCount(Descriptors.FieldDescriptor field) {
+ return wrappedMessage.getRepeatedFieldCount(field);
+ }
+ public Object getRepeatedField(
+ Descriptors.FieldDescriptor field, int index) {
+ return wrappedMessage.getRepeatedField(field, index);
+ }
+ public UnknownFieldSet getUnknownFields() {
+ return wrappedMessage.getUnknownFields();
+ }
+ public Builder newBuilderForType() {
+ return new Builder(wrappedMessage.newBuilderForType());
+ }
+ public Builder toBuilder() {
+ return new Builder(wrappedMessage.toBuilder());
+ }
+
+ static class Builder extends AbstractMessage.Builder<Builder> {
+ private final Message.Builder wrappedBuilder;
+
+ public Builder(Message.Builder wrappedBuilder) {
+ this.wrappedBuilder = wrappedBuilder;
+ }
+
+ public AbstractMessageWrapper build() {
+ return new AbstractMessageWrapper(wrappedBuilder.build());
+ }
+ public AbstractMessageWrapper buildPartial() {
+ return new AbstractMessageWrapper(wrappedBuilder.buildPartial());
+ }
+ public Builder clone() {
+ return new Builder(wrappedBuilder.clone());
+ }
+ public boolean isInitialized() {
+ return clone().buildPartial().isInitialized();
+ }
+ public Descriptors.Descriptor getDescriptorForType() {
+ return wrappedBuilder.getDescriptorForType();
+ }
+ public AbstractMessageWrapper getDefaultInstanceForType() {
+ return new AbstractMessageWrapper(
+ wrappedBuilder.getDefaultInstanceForType());
+ }
+ public Map<Descriptors.FieldDescriptor, Object> getAllFields() {
+ return wrappedBuilder.getAllFields();
+ }
+ public Builder newBuilderForField(Descriptors.FieldDescriptor field) {
+ return new Builder(wrappedBuilder.newBuilderForField(field));
+ }
+ public boolean hasField(Descriptors.FieldDescriptor field) {
+ return wrappedBuilder.hasField(field);
+ }
+ public Object getField(Descriptors.FieldDescriptor field) {
+ return wrappedBuilder.getField(field);
+ }
+ public Builder setField(Descriptors.FieldDescriptor field, Object value) {
+ wrappedBuilder.setField(field, value);
+ return this;
+ }
+ public Builder clearField(Descriptors.FieldDescriptor field) {
+ wrappedBuilder.clearField(field);
+ return this;
+ }
+ public int getRepeatedFieldCount(Descriptors.FieldDescriptor field) {
+ return wrappedBuilder.getRepeatedFieldCount(field);
+ }
+ public Object getRepeatedField(
+ Descriptors.FieldDescriptor field, int index) {
+ return wrappedBuilder.getRepeatedField(field, index);
+ }
+ public Builder setRepeatedField(Descriptors.FieldDescriptor field,
+ int index, Object value) {
+ wrappedBuilder.setRepeatedField(field, index, value);
+ return this;
+ }
+ public Builder addRepeatedField(
+ Descriptors.FieldDescriptor field, Object value) {
+ wrappedBuilder.addRepeatedField(field, value);
+ return this;
+ }
+ public UnknownFieldSet getUnknownFields() {
+ return wrappedBuilder.getUnknownFields();
+ }
+ public Builder setUnknownFields(UnknownFieldSet unknownFields) {
+ wrappedBuilder.setUnknownFields(unknownFields);
+ return this;
+ }
+ @Override
+ public Message.Builder getFieldBuilder(FieldDescriptor field) {
+ return wrappedBuilder.getFieldBuilder(field);
+ }
+ }
+ public Parser<? extends Message> getParserForType() {
+ return wrappedMessage.getParserForType();
+ }
+ }
+
+ // =================================================================
+
+ TestUtil.ReflectionTester reflectionTester =
+ new TestUtil.ReflectionTester(TestAllTypes.getDescriptor(), null);
+
+ TestUtil.ReflectionTester extensionsReflectionTester =
+ new TestUtil.ReflectionTester(TestAllExtensions.getDescriptor(),
+ TestUtil.getExtensionRegistry());
+
+ public void testClear() throws Exception {
+ AbstractMessageWrapper message =
+ new AbstractMessageWrapper.Builder(
+ TestAllTypes.newBuilder(TestUtil.getAllSet()))
+ .clear().build();
+ TestUtil.assertClear((TestAllTypes) message.wrappedMessage);
+ }
+
+ public void testCopy() throws Exception {
+ AbstractMessageWrapper message =
+ new AbstractMessageWrapper.Builder(TestAllTypes.newBuilder())
+ .mergeFrom(TestUtil.getAllSet()).build();
+ TestUtil.assertAllFieldsSet((TestAllTypes) message.wrappedMessage);
+ }
+
+ public void testSerializedSize() throws Exception {
+ TestAllTypes message = TestUtil.getAllSet();
+ Message abstractMessage = new AbstractMessageWrapper(TestUtil.getAllSet());
+
+ assertEquals(message.getSerializedSize(),
+ abstractMessage.getSerializedSize());
+ }
+
+ public void testSerialization() throws Exception {
+ Message abstractMessage = new AbstractMessageWrapper(TestUtil.getAllSet());
+
+ TestUtil.assertAllFieldsSet(
+ TestAllTypes.parseFrom(abstractMessage.toByteString()));
+
+ assertEquals(TestUtil.getAllSet().toByteString(),
+ abstractMessage.toByteString());
+ }
+
+ public void testParsing() throws Exception {
+ AbstractMessageWrapper.Builder builder =
+ new AbstractMessageWrapper.Builder(TestAllTypes.newBuilder());
+ AbstractMessageWrapper message =
+ builder.mergeFrom(TestUtil.getAllSet().toByteString()).build();
+ TestUtil.assertAllFieldsSet((TestAllTypes) message.wrappedMessage);
+ }
+
+ public void testParsingUninitialized() throws Exception {
+ TestRequiredForeign.Builder builder = TestRequiredForeign.newBuilder();
+ builder.getOptionalMessageBuilder().setDummy2(10);
+ ByteString bytes = builder.buildPartial().toByteString();
+ Message.Builder abstractMessageBuilder =
+ new AbstractMessageWrapper.Builder(TestRequiredForeign.newBuilder());
+ // mergeFrom() should not throw initialization error.
+ abstractMessageBuilder.mergeFrom(bytes).buildPartial();
+ try {
+ abstractMessageBuilder.mergeFrom(bytes).build();
+ fail();
+ } catch (UninitializedMessageException ex) {
+ // pass
+ }
+
+ // test DynamicMessage directly.
+ Message.Builder dynamicMessageBuilder = DynamicMessage.newBuilder(
+ TestRequiredForeign.getDescriptor());
+ // mergeFrom() should not throw initialization error.
+ dynamicMessageBuilder.mergeFrom(bytes).buildPartial();
+ try {
+ dynamicMessageBuilder.mergeFrom(bytes).build();
+ fail();
+ } catch (UninitializedMessageException ex) {
+ // pass
+ }
+ }
+
+ public void testPackedSerialization() throws Exception {
+ Message abstractMessage =
+ new AbstractMessageWrapper(TestUtil.getPackedSet());
+
+ TestUtil.assertPackedFieldsSet(
+ TestPackedTypes.parseFrom(abstractMessage.toByteString()));
+
+ assertEquals(TestUtil.getPackedSet().toByteString(),
+ abstractMessage.toByteString());
+ }
+
+ public void testPackedParsing() throws Exception {
+ AbstractMessageWrapper.Builder builder =
+ new AbstractMessageWrapper.Builder(TestPackedTypes.newBuilder());
+ AbstractMessageWrapper message =
+ builder.mergeFrom(TestUtil.getPackedSet().toByteString()).build();
+ TestUtil.assertPackedFieldsSet((TestPackedTypes) message.wrappedMessage);
+ }
+
+ public void testUnpackedSerialization() throws Exception {
+ Message abstractMessage =
+ new AbstractMessageWrapper(TestUtil.getUnpackedSet());
+
+ TestUtil.assertUnpackedFieldsSet(
+ TestUnpackedTypes.parseFrom(abstractMessage.toByteString()));
+
+ assertEquals(TestUtil.getUnpackedSet().toByteString(),
+ abstractMessage.toByteString());
+ }
+
+ public void testParsePackedToUnpacked() throws Exception {
+ AbstractMessageWrapper.Builder builder =
+ new AbstractMessageWrapper.Builder(TestUnpackedTypes.newBuilder());
+ AbstractMessageWrapper message =
+ builder.mergeFrom(TestUtil.getPackedSet().toByteString()).build();
+ TestUtil.assertUnpackedFieldsSet(
+ (TestUnpackedTypes) message.wrappedMessage);
+ }
+
+ public void testParseUnpackedToPacked() throws Exception {
+ AbstractMessageWrapper.Builder builder =
+ new AbstractMessageWrapper.Builder(TestPackedTypes.newBuilder());
+ AbstractMessageWrapper message =
+ builder.mergeFrom(TestUtil.getUnpackedSet().toByteString()).build();
+ TestUtil.assertPackedFieldsSet((TestPackedTypes) message.wrappedMessage);
+ }
+
+ public void testUnpackedParsing() throws Exception {
+ AbstractMessageWrapper.Builder builder =
+ new AbstractMessageWrapper.Builder(TestUnpackedTypes.newBuilder());
+ AbstractMessageWrapper message =
+ builder.mergeFrom(TestUtil.getUnpackedSet().toByteString()).build();
+ TestUtil.assertUnpackedFieldsSet(
+ (TestUnpackedTypes) message.wrappedMessage);
+ }
+
+ public void testOptimizedForSize() throws Exception {
+ // We're mostly only checking that this class was compiled successfully.
+ TestOptimizedForSize message =
+ TestOptimizedForSize.newBuilder().setI(1).build();
+ message = TestOptimizedForSize.parseFrom(message.toByteString());
+ assertEquals(2, message.getSerializedSize());
+ }
+
+ // -----------------------------------------------------------------
+ // Tests for isInitialized().
+
+ private static final TestRequired TEST_REQUIRED_UNINITIALIZED =
+ TestRequired.getDefaultInstance();
+ private static final TestRequired TEST_REQUIRED_INITIALIZED =
+ TestRequired.newBuilder().setA(1).setB(2).setC(3).build();
+
+ public void testIsInitialized() throws Exception {
+ TestRequired.Builder builder = TestRequired.newBuilder();
+ AbstractMessageWrapper.Builder abstractBuilder =
+ new AbstractMessageWrapper.Builder(builder);
+
+ assertFalse(abstractBuilder.isInitialized());
+ assertEquals("a, b, c", abstractBuilder.getInitializationErrorString());
+ builder.setA(1);
+ assertFalse(abstractBuilder.isInitialized());
+ assertEquals("b, c", abstractBuilder.getInitializationErrorString());
+ builder.setB(1);
+ assertFalse(abstractBuilder.isInitialized());
+ assertEquals("c", abstractBuilder.getInitializationErrorString());
+ builder.setC(1);
+ assertTrue(abstractBuilder.isInitialized());
+ assertEquals("", abstractBuilder.getInitializationErrorString());
+ }
+
+ public void testForeignIsInitialized() throws Exception {
+ TestRequiredForeign.Builder builder = TestRequiredForeign.newBuilder();
+ AbstractMessageWrapper.Builder abstractBuilder =
+ new AbstractMessageWrapper.Builder(builder);
+
+ assertTrue(abstractBuilder.isInitialized());
+ assertEquals("", abstractBuilder.getInitializationErrorString());
+
+ builder.setOptionalMessage(TEST_REQUIRED_UNINITIALIZED);
+ assertFalse(abstractBuilder.isInitialized());
+ assertEquals(
+ "optional_message.a, optional_message.b, optional_message.c",
+ abstractBuilder.getInitializationErrorString());
+
+ builder.setOptionalMessage(TEST_REQUIRED_INITIALIZED);
+ assertTrue(abstractBuilder.isInitialized());
+ assertEquals("", abstractBuilder.getInitializationErrorString());
+
+ builder.addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED);
+ assertFalse(abstractBuilder.isInitialized());
+ assertEquals(
+ "repeated_message[0].a, repeated_message[0].b, repeated_message[0].c",
+ abstractBuilder.getInitializationErrorString());
+
+ builder.setRepeatedMessage(0, TEST_REQUIRED_INITIALIZED);
+ assertTrue(abstractBuilder.isInitialized());
+ assertEquals("", abstractBuilder.getInitializationErrorString());
+ }
+
+ // -----------------------------------------------------------------
+ // Tests for mergeFrom
+
+ static final TestAllTypes MERGE_SOURCE =
+ TestAllTypes.newBuilder()
+ .setOptionalInt32(1)
+ .setOptionalString("foo")
+ .setOptionalForeignMessage(ForeignMessage.getDefaultInstance())
+ .addRepeatedString("bar")
+ .build();
+
+ static final TestAllTypes MERGE_DEST =
+ TestAllTypes.newBuilder()
+ .setOptionalInt64(2)
+ .setOptionalString("baz")
+ .setOptionalForeignMessage(ForeignMessage.newBuilder().setC(3).build())
+ .addRepeatedString("qux")
+ .build();
+
+ static final String MERGE_RESULT_TEXT =
+ "optional_int32: 1\n" +
+ "optional_int64: 2\n" +
+ "optional_string: \"foo\"\n" +
+ "optional_foreign_message {\n" +
+ " c: 3\n" +
+ "}\n" +
+ "repeated_string: \"qux\"\n" +
+ "repeated_string: \"bar\"\n";
+
+ public void testMergeFrom() throws Exception {
+ AbstractMessageWrapper result =
+ new AbstractMessageWrapper.Builder(
+ TestAllTypes.newBuilder(MERGE_DEST))
+ .mergeFrom(MERGE_SOURCE).build();
+
+ assertEquals(MERGE_RESULT_TEXT, result.toString());
+ }
+
+ // -----------------------------------------------------------------
+ // Tests for equals and hashCode
+
+ public void testEqualsAndHashCode() throws Exception {
+ TestAllTypes a = TestUtil.getAllSet();
+ TestAllTypes b = TestAllTypes.newBuilder().build();
+ TestAllTypes c = TestAllTypes.newBuilder(b).addRepeatedString("x").build();
+ TestAllTypes d = TestAllTypes.newBuilder(c).addRepeatedString("y").build();
+ TestAllExtensions e = TestUtil.getAllExtensionsSet();
+ TestAllExtensions f = TestAllExtensions.newBuilder(e)
+ .addExtension(UnittestProto.repeatedInt32Extension, 999).build();
+
+ checkEqualsIsConsistent(a);
+ checkEqualsIsConsistent(b);
+ checkEqualsIsConsistent(c);
+ checkEqualsIsConsistent(d);
+ checkEqualsIsConsistent(e);
+ checkEqualsIsConsistent(f);
+
+ checkNotEqual(a, b);
+ checkNotEqual(a, c);
+ checkNotEqual(a, d);
+ checkNotEqual(a, e);
+ checkNotEqual(a, f);
+
+ checkNotEqual(b, c);
+ checkNotEqual(b, d);
+ checkNotEqual(b, e);
+ checkNotEqual(b, f);
+
+ checkNotEqual(c, d);
+ checkNotEqual(c, e);
+ checkNotEqual(c, f);
+
+ checkNotEqual(d, e);
+ checkNotEqual(d, f);
+
+ checkNotEqual(e, f);
+
+ // Deserializing into the TestEmptyMessage such that every field
+ // is an {@link UnknownFieldSet.Field}.
+ UnittestProto.TestEmptyMessage eUnknownFields =
+ UnittestProto.TestEmptyMessage.parseFrom(e.toByteArray());
+ UnittestProto.TestEmptyMessage fUnknownFields =
+ UnittestProto.TestEmptyMessage.parseFrom(f.toByteArray());
+ checkNotEqual(eUnknownFields, fUnknownFields);
+ checkEqualsIsConsistent(eUnknownFields);
+ checkEqualsIsConsistent(fUnknownFields);
+
+ // Subsequent reconstitutions should be identical
+ UnittestProto.TestEmptyMessage eUnknownFields2 =
+ UnittestProto.TestEmptyMessage.parseFrom(e.toByteArray());
+ checkEqualsIsConsistent(eUnknownFields, eUnknownFields2);
+ }
+
+
+ /**
+ * Asserts that the given proto has symmetric equals and hashCode methods.
+ */
+ private void checkEqualsIsConsistent(Message message) {
+ // Object should be equal to itself.
+ assertEquals(message, message);
+
+ // Object should be equal to a dynamic copy of itself.
+ DynamicMessage dynamic = DynamicMessage.newBuilder(message).build();
+ checkEqualsIsConsistent(message, dynamic);
+ }
+
+ /**
+ * Asserts that the given protos are equal and have the same hash code.
+ */
+ private void checkEqualsIsConsistent(Message message1, Message message2) {
+ assertEquals(message1, message2);
+ assertEquals(message2, message1);
+ assertEquals(message2.hashCode(), message1.hashCode());
+ }
+
+ /**
+ * Asserts that the given protos are not equal and have different hash codes.
+ *
+ * @warning It's valid for non-equal objects to have the same hash code, so
+ * this test is stricter than it needs to be. However, this should happen
+ * relatively rarely.
+ */
+ private void checkNotEqual(Message m1, Message m2) {
+ String equalsError = String.format("%s should not be equal to %s", m1, m2);
+ assertFalse(equalsError, m1.equals(m2));
+ assertFalse(equalsError, m2.equals(m1));
+
+ assertFalse(
+ String.format("%s should have a different hash code from %s", m1, m2),
+ m1.hashCode() == m2.hashCode());
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/BoundedByteStringTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/BoundedByteStringTest.java
new file mode 100644
index 0000000000..c838274369
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/BoundedByteStringTest.java
@@ -0,0 +1,56 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import java.io.UnsupportedEncodingException;
+
+/**
+ * This class tests {@link BoundedByteString}, which extends {@link LiteralByteString},
+ * by inheriting the tests from {@link LiteralByteStringTest}. The only method which
+ * is strange enough that it needs to be overridden here is {@link #testToString()}.
+ *
+ * @author carlanton@google.com (Carl Haverl)
+ */
+public class BoundedByteStringTest extends LiteralByteStringTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ classUnderTest = "BoundedByteString";
+ byte[] sourceBytes = ByteStringTest.getTestBytes(2341, 11337766L);
+ int from = 100;
+ int to = sourceBytes.length - 100;
+ stringUnderTest = ByteString.copyFrom(sourceBytes).substring(from, to);
+ referenceBytes = new byte[to - from];
+ System.arraycopy(sourceBytes, from, referenceBytes, 0, to - from);
+ expectedHashCode = 727575887;
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ByteStringTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ByteStringTest.java
new file mode 100644
index 0000000000..8bb9f731d2
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ByteStringTest.java
@@ -0,0 +1,590 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import com.google.protobuf.ByteString.Output;
+
+import junit.framework.TestCase;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Random;
+
+/**
+ * Test methods with implementations in {@link ByteString}, plus do some top-level "integration"
+ * tests.
+ *
+ * @author carlanton@google.com (Carl Haverl)
+ */
+public class ByteStringTest extends TestCase {
+
+ private static final String UTF_16 = "UTF-16";
+
+ static byte[] getTestBytes(int size, long seed) {
+ Random random = new Random(seed);
+ byte[] result = new byte[size];
+ random.nextBytes(result);
+ return result;
+ }
+
+ private byte[] getTestBytes(int size) {
+ return getTestBytes(size, 445566L);
+ }
+
+ private byte[] getTestBytes() {
+ return getTestBytes(1000);
+ }
+
+ // Compare the entire left array with a subset of the right array.
+ private boolean isArrayRange(byte[] left, byte[] right, int rightOffset, int length) {
+ boolean stillEqual = (left.length == length);
+ for (int i = 0; (stillEqual && i < length); ++i) {
+ stillEqual = (left[i] == right[rightOffset + i]);
+ }
+ return stillEqual;
+ }
+
+ // Returns true only if the given two arrays have identical contents.
+ private boolean isArray(byte[] left, byte[] right) {
+ return left.length == right.length && isArrayRange(left, right, 0, left.length);
+ }
+
+ public void testSubstring_BeginIndex() {
+ byte[] bytes = getTestBytes();
+ ByteString substring = ByteString.copyFrom(bytes).substring(500);
+ assertTrue("substring must contain the tail of the string",
+ isArrayRange(substring.toByteArray(), bytes, 500, bytes.length - 500));
+ }
+
+ public void testCopyFrom_BytesOffsetSize() {
+ byte[] bytes = getTestBytes();
+ ByteString byteString = ByteString.copyFrom(bytes, 500, 200);
+ assertTrue("copyFrom sub-range must contain the expected bytes",
+ isArrayRange(byteString.toByteArray(), bytes, 500, 200));
+ }
+
+ public void testCopyFrom_Bytes() {
+ byte[] bytes = getTestBytes();
+ ByteString byteString = ByteString.copyFrom(bytes);
+ assertTrue("copyFrom must contain the expected bytes",
+ isArray(byteString.toByteArray(), bytes));
+ }
+
+ public void testCopyFrom_ByteBufferSize() {
+ byte[] bytes = getTestBytes();
+ ByteBuffer byteBuffer = ByteBuffer.allocate(bytes.length);
+ byteBuffer.put(bytes);
+ byteBuffer.position(500);
+ ByteString byteString = ByteString.copyFrom(byteBuffer, 200);
+ assertTrue("copyFrom byteBuffer sub-range must contain the expected bytes",
+ isArrayRange(byteString.toByteArray(), bytes, 500, 200));
+ }
+
+ public void testCopyFrom_ByteBuffer() {
+ byte[] bytes = getTestBytes();
+ ByteBuffer byteBuffer = ByteBuffer.allocate(bytes.length);
+ byteBuffer.put(bytes);
+ byteBuffer.position(500);
+ ByteString byteString = ByteString.copyFrom(byteBuffer);
+ assertTrue("copyFrom byteBuffer sub-range must contain the expected bytes",
+ isArrayRange(byteString.toByteArray(), bytes, 500, bytes.length - 500));
+ }
+
+ public void testCopyFrom_StringEncoding() throws UnsupportedEncodingException {
+ String testString = "I love unicode \u1234\u5678 characters";
+ ByteString byteString = ByteString.copyFrom(testString, UTF_16);
+ byte[] testBytes = testString.getBytes(UTF_16);
+ assertTrue("copyFrom string must respect the charset",
+ isArrayRange(byteString.toByteArray(), testBytes, 0, testBytes.length));
+ }
+
+ public void testCopyFrom_Utf8() throws UnsupportedEncodingException {
+ String testString = "I love unicode \u1234\u5678 characters";
+ ByteString byteString = ByteString.copyFromUtf8(testString);
+ byte[] testBytes = testString.getBytes("UTF-8");
+ assertTrue("copyFromUtf8 string must respect the charset",
+ isArrayRange(byteString.toByteArray(), testBytes, 0, testBytes.length));
+ }
+
+ public void testCopyFrom_Iterable() {
+ byte[] testBytes = getTestBytes(77777, 113344L);
+ final List<ByteString> pieces = makeConcretePieces(testBytes);
+ // Call copyFrom() on a Collection
+ ByteString byteString = ByteString.copyFrom(pieces);
+ assertTrue("copyFrom a List must contain the expected bytes",
+ isArrayRange(byteString.toByteArray(), testBytes, 0, testBytes.length));
+ // Call copyFrom on an iteration that's not a collection
+ ByteString byteStringAlt = ByteString.copyFrom(new Iterable<ByteString>() {
+ public Iterator<ByteString> iterator() {
+ return pieces.iterator();
+ }
+ });
+ assertEquals("copyFrom from an Iteration must contain the expected bytes",
+ byteString, byteStringAlt);
+ }
+
+ public void testCopyTo_TargetOffset() {
+ byte[] bytes = getTestBytes();
+ ByteString byteString = ByteString.copyFrom(bytes);
+ byte[] target = new byte[bytes.length + 1000];
+ byteString.copyTo(target, 400);
+ assertTrue("copyFrom byteBuffer sub-range must contain the expected bytes",
+ isArrayRange(bytes, target, 400, bytes.length));
+ }
+
+ public void testReadFrom_emptyStream() throws IOException {
+ ByteString byteString =
+ ByteString.readFrom(new ByteArrayInputStream(new byte[0]));
+ assertSame("reading an empty stream must result in the EMPTY constant "
+ + "byte string", ByteString.EMPTY, byteString);
+ }
+
+ public void testReadFrom_smallStream() throws IOException {
+ assertReadFrom(getTestBytes(10));
+ }
+
+ public void testReadFrom_mutating() throws IOException {
+ byte[] capturedArray = null;
+ EvilInputStream eis = new EvilInputStream();
+ ByteString byteString = ByteString.readFrom(eis);
+
+ capturedArray = eis.capturedArray;
+ byte[] originalValue = byteString.toByteArray();
+ for (int x = 0; x < capturedArray.length; ++x) {
+ capturedArray[x] = (byte) 0;
+ }
+
+ byte[] newValue = byteString.toByteArray();
+ assertTrue("copyFrom byteBuffer must not grant access to underlying array",
+ Arrays.equals(originalValue, newValue));
+ }
+
+ // Tests sizes that are over multi-segment rope threshold.
+ public void testReadFrom_largeStream() throws IOException {
+ assertReadFrom(getTestBytes(0x100));
+ assertReadFrom(getTestBytes(0x101));
+ assertReadFrom(getTestBytes(0x110));
+ assertReadFrom(getTestBytes(0x1000));
+ assertReadFrom(getTestBytes(0x1001));
+ assertReadFrom(getTestBytes(0x1010));
+ assertReadFrom(getTestBytes(0x10000));
+ assertReadFrom(getTestBytes(0x10001));
+ assertReadFrom(getTestBytes(0x10010));
+ }
+
+ // Tests that IOExceptions propagate through ByteString.readFrom().
+ public void testReadFrom_IOExceptions() {
+ try {
+ ByteString.readFrom(new FailStream());
+ fail("readFrom must throw the underlying IOException");
+
+ } catch (IOException e) {
+ assertEquals("readFrom must throw the expected exception",
+ "synthetic failure", e.getMessage());
+ }
+ }
+
+ // Tests that ByteString.readFrom works with streams that don't
+ // always fill their buffers.
+ public void testReadFrom_reluctantStream() throws IOException {
+ final byte[] data = getTestBytes(0x1000);
+
+ ByteString byteString = ByteString.readFrom(new ReluctantStream(data));
+ assertTrue("readFrom byte stream must contain the expected bytes",
+ isArray(byteString.toByteArray(), data));
+
+ // Same test as above, but with some specific chunk sizes.
+ assertReadFromReluctantStream(data, 100);
+ assertReadFromReluctantStream(data, 248);
+ assertReadFromReluctantStream(data, 249);
+ assertReadFromReluctantStream(data, 250);
+ assertReadFromReluctantStream(data, 251);
+ assertReadFromReluctantStream(data, 0x1000);
+ assertReadFromReluctantStream(data, 0x1001);
+ }
+
+ // Fails unless ByteString.readFrom reads the bytes correctly from a
+ // reluctant stream with the given chunkSize parameter.
+ private void assertReadFromReluctantStream(byte[] bytes, int chunkSize)
+ throws IOException {
+ ByteString b = ByteString.readFrom(new ReluctantStream(bytes), chunkSize);
+ assertTrue("readFrom byte stream must contain the expected bytes",
+ isArray(b.toByteArray(), bytes));
+ }
+
+ // Tests that ByteString.readFrom works with streams that implement
+ // available().
+ public void testReadFrom_available() throws IOException {
+ final byte[] data = getTestBytes(0x1001);
+
+ ByteString byteString = ByteString.readFrom(new AvailableStream(data));
+ assertTrue("readFrom byte stream must contain the expected bytes",
+ isArray(byteString.toByteArray(), data));
+ }
+
+ // Fails unless ByteString.readFrom reads the bytes correctly.
+ private void assertReadFrom(byte[] bytes) throws IOException {
+ ByteString byteString =
+ ByteString.readFrom(new ByteArrayInputStream(bytes));
+ assertTrue("readFrom byte stream must contain the expected bytes",
+ isArray(byteString.toByteArray(), bytes));
+ }
+
+ // A stream that fails when read.
+ private static final class FailStream extends InputStream {
+ @Override public int read() throws IOException {
+ throw new IOException("synthetic failure");
+ }
+ }
+
+ // A stream that simulates blocking by only producing 250 characters
+ // per call to read(byte[]).
+ private static class ReluctantStream extends InputStream {
+ protected final byte[] data;
+ protected int pos = 0;
+
+ public ReluctantStream(byte[] data) {
+ this.data = data;
+ }
+
+ @Override public int read() {
+ if (pos == data.length) {
+ return -1;
+ } else {
+ return data[pos++];
+ }
+ }
+
+ @Override public int read(byte[] buf) {
+ return read(buf, 0, buf.length);
+ }
+
+ @Override public int read(byte[] buf, int offset, int size) {
+ if (pos == data.length) {
+ return -1;
+ }
+ int count = Math.min(Math.min(size, data.length - pos), 250);
+ System.arraycopy(data, pos, buf, offset, count);
+ pos += count;
+ return count;
+ }
+ }
+
+ // Same as above, but also implements available().
+ private static final class AvailableStream extends ReluctantStream {
+ public AvailableStream(byte[] data) {
+ super(data);
+ }
+
+ @Override public int available() {
+ return Math.min(250, data.length - pos);
+ }
+ }
+
+ // A stream which exposes the byte array passed into read(byte[], int, int).
+ private static class EvilInputStream extends InputStream {
+ public byte[] capturedArray = null;
+
+ @Override
+ public int read(byte[] buf, int off, int len) {
+ if (capturedArray != null) {
+ return -1;
+ } else {
+ capturedArray = buf;
+ for (int x = 0; x < len; ++x) {
+ buf[x] = (byte) x;
+ }
+ return len;
+ }
+ }
+
+ @Override
+ public int read() {
+ // Purposefully do nothing.
+ return -1;
+ }
+ }
+
+ // A stream which exposes the byte array passed into write(byte[], int, int).
+ private static class EvilOutputStream extends OutputStream {
+ public byte[] capturedArray = null;
+
+ @Override
+ public void write(byte[] buf, int off, int len) {
+ if (capturedArray == null) {
+ capturedArray = buf;
+ }
+ }
+
+ @Override
+ public void write(int ignored) {
+ // Purposefully do nothing.
+ }
+ }
+
+ public void testToStringUtf8() throws UnsupportedEncodingException {
+ String testString = "I love unicode \u1234\u5678 characters";
+ byte[] testBytes = testString.getBytes("UTF-8");
+ ByteString byteString = ByteString.copyFrom(testBytes);
+ assertEquals("copyToStringUtf8 must respect the charset",
+ testString, byteString.toStringUtf8());
+ }
+
+ public void testNewOutput_InitialCapacity() throws IOException {
+ byte[] bytes = getTestBytes();
+ ByteString.Output output = ByteString.newOutput(bytes.length + 100);
+ output.write(bytes);
+ ByteString byteString = output.toByteString();
+ assertTrue(
+ "String built from newOutput(int) must contain the expected bytes",
+ isArrayRange(bytes, byteString.toByteArray(), 0, bytes.length));
+ }
+
+ // Test newOutput() using a variety of buffer sizes and a variety of (fixed)
+ // write sizes
+ public void testNewOutput_ArrayWrite() throws IOException {
+ byte[] bytes = getTestBytes();
+ int length = bytes.length;
+ int[] bufferSizes = {128, 256, length / 2, length - 1, length, length + 1,
+ 2 * length, 3 * length};
+ int[] writeSizes = {1, 4, 5, 7, 23, bytes.length};
+
+ for (int bufferSize : bufferSizes) {
+ for (int writeSize : writeSizes) {
+ // Test writing the entire output writeSize bytes at a time.
+ ByteString.Output output = ByteString.newOutput(bufferSize);
+ for (int i = 0; i < length; i += writeSize) {
+ output.write(bytes, i, Math.min(writeSize, length - i));
+ }
+ ByteString byteString = output.toByteString();
+ assertTrue("String built from newOutput() must contain the expected bytes",
+ isArrayRange(bytes, byteString.toByteArray(), 0, bytes.length));
+ }
+ }
+ }
+
+ // Test newOutput() using a variety of buffer sizes, but writing all the
+ // characters using write(byte);
+ public void testNewOutput_WriteChar() throws IOException {
+ byte[] bytes = getTestBytes();
+ int length = bytes.length;
+ int[] bufferSizes = {0, 1, 128, 256, length / 2,
+ length - 1, length, length + 1,
+ 2 * length, 3 * length};
+ for (int bufferSize : bufferSizes) {
+ ByteString.Output output = ByteString.newOutput(bufferSize);
+ for (byte byteValue : bytes) {
+ output.write(byteValue);
+ }
+ ByteString byteString = output.toByteString();
+ assertTrue("String built from newOutput() must contain the expected bytes",
+ isArrayRange(bytes, byteString.toByteArray(), 0, bytes.length));
+ }
+ }
+
+ // Test newOutput() in which we write the bytes using a variety of methods
+ // and sizes, and in which we repeatedly call toByteString() in the middle.
+ public void testNewOutput_Mixed() throws IOException {
+ Random rng = new Random(1);
+ byte[] bytes = getTestBytes();
+ int length = bytes.length;
+ int[] bufferSizes = {0, 1, 128, 256, length / 2,
+ length - 1, length, length + 1,
+ 2 * length, 3 * length};
+
+ for (int bufferSize : bufferSizes) {
+ // Test writing the entire output using a mixture of write sizes and
+ // methods;
+ ByteString.Output output = ByteString.newOutput(bufferSize);
+ int position = 0;
+ while (position < bytes.length) {
+ if (rng.nextBoolean()) {
+ int count = 1 + rng.nextInt(bytes.length - position);
+ output.write(bytes, position, count);
+ position += count;
+ } else {
+ output.write(bytes[position]);
+ position++;
+ }
+ assertEquals("size() returns the right value", position, output.size());
+ assertTrue("newOutput() substring must have correct bytes",
+ isArrayRange(output.toByteString().toByteArray(),
+ bytes, 0, position));
+ }
+ ByteString byteString = output.toByteString();
+ assertTrue("String built from newOutput() must contain the expected bytes",
+ isArrayRange(bytes, byteString.toByteArray(), 0, bytes.length));
+ }
+ }
+
+ public void testNewOutputEmpty() throws IOException {
+ // Make sure newOutput() correctly builds empty byte strings
+ ByteString byteString = ByteString.newOutput().toByteString();
+ assertEquals(ByteString.EMPTY, byteString);
+ }
+
+ public void testNewOutput_Mutating() throws IOException {
+ Output os = ByteString.newOutput(5);
+ os.write(new byte[] {1, 2, 3, 4, 5});
+ EvilOutputStream eos = new EvilOutputStream();
+ os.writeTo(eos);
+ byte[] capturedArray = eos.capturedArray;
+ ByteString byteString = os.toByteString();
+ byte[] oldValue = byteString.toByteArray();
+ Arrays.fill(capturedArray, (byte) 0);
+ byte[] newValue = byteString.toByteArray();
+ assertTrue("Output must not provide access to the underlying byte array",
+ Arrays.equals(oldValue, newValue));
+ }
+
+ public void testSubstringParity() {
+ byte[] bigBytes = getTestBytes(2048 * 1024, 113344L);
+ int start = 512 * 1024 - 3333;
+ int end = 512 * 1024 + 7777;
+ ByteString concreteSubstring = ByteString.copyFrom(bigBytes).substring(start, end);
+ boolean ok = true;
+ for (int i = start; ok && i < end; ++i) {
+ ok = (bigBytes[i] == concreteSubstring.byteAt(i - start));
+ }
+ assertTrue("Concrete substring didn't capture the right bytes", ok);
+
+ ByteString literalString = ByteString.copyFrom(bigBytes, start, end - start);
+ assertTrue("Substring must be equal to literal string",
+ concreteSubstring.equals(literalString));
+ assertEquals("Substring must have same hashcode as literal string",
+ literalString.hashCode(), concreteSubstring.hashCode());
+ }
+
+ public void testCompositeSubstring() {
+ byte[] referenceBytes = getTestBytes(77748, 113344L);
+
+ List<ByteString> pieces = makeConcretePieces(referenceBytes);
+ ByteString listString = ByteString.copyFrom(pieces);
+
+ int from = 1000;
+ int to = 40000;
+ ByteString compositeSubstring = listString.substring(from, to);
+ byte[] substringBytes = compositeSubstring.toByteArray();
+ boolean stillEqual = true;
+ for (int i = 0; stillEqual && i < to - from; ++i) {
+ stillEqual = referenceBytes[from + i] == substringBytes[i];
+ }
+ assertTrue("Substring must return correct bytes", stillEqual);
+
+ stillEqual = true;
+ for (int i = 0; stillEqual && i < to - from; ++i) {
+ stillEqual = referenceBytes[from + i] == compositeSubstring.byteAt(i);
+ }
+ assertTrue("Substring must support byteAt() correctly", stillEqual);
+
+ ByteString literalSubstring = ByteString.copyFrom(referenceBytes, from, to - from);
+ assertTrue("Composite substring must equal a literal substring over the same bytes",
+ compositeSubstring.equals(literalSubstring));
+ assertTrue("Literal substring must equal a composite substring over the same bytes",
+ literalSubstring.equals(compositeSubstring));
+
+ assertEquals("We must get the same hashcodes for composite and literal substrings",
+ literalSubstring.hashCode(), compositeSubstring.hashCode());
+
+ assertFalse("We can't be equal to a proper substring",
+ compositeSubstring.equals(literalSubstring.substring(0, literalSubstring.size() - 1)));
+ }
+
+ public void testCopyFromList() {
+ byte[] referenceBytes = getTestBytes(77748, 113344L);
+ ByteString literalString = ByteString.copyFrom(referenceBytes);
+
+ List<ByteString> pieces = makeConcretePieces(referenceBytes);
+ ByteString listString = ByteString.copyFrom(pieces);
+
+ assertTrue("Composite string must be equal to literal string",
+ listString.equals(literalString));
+ assertEquals("Composite string must have same hashcode as literal string",
+ literalString.hashCode(), listString.hashCode());
+ }
+
+ public void testConcat() {
+ byte[] referenceBytes = getTestBytes(77748, 113344L);
+ ByteString literalString = ByteString.copyFrom(referenceBytes);
+
+ List<ByteString> pieces = makeConcretePieces(referenceBytes);
+
+ Iterator<ByteString> iter = pieces.iterator();
+ ByteString concatenatedString = iter.next();
+ while (iter.hasNext()) {
+ concatenatedString = concatenatedString.concat(iter.next());
+ }
+
+ assertTrue("Concatenated string must be equal to literal string",
+ concatenatedString.equals(literalString));
+ assertEquals("Concatenated string must have same hashcode as literal string",
+ literalString.hashCode(), concatenatedString.hashCode());
+ }
+
+ public void testStartsWith() {
+ byte[] bytes = getTestBytes(1000, 1234L);
+ ByteString string = ByteString.copyFrom(bytes);
+ ByteString prefix = ByteString.copyFrom(bytes, 0, 500);
+ ByteString suffix = ByteString.copyFrom(bytes, 400, 600);
+ assertTrue(string.startsWith(ByteString.EMPTY));
+ assertTrue(string.startsWith(string));
+ assertTrue(string.startsWith(prefix));
+ assertFalse(string.startsWith(suffix));
+ assertFalse(prefix.startsWith(suffix));
+ assertFalse(suffix.startsWith(prefix));
+ assertFalse(ByteString.EMPTY.startsWith(prefix));
+ assertTrue(ByteString.EMPTY.startsWith(ByteString.EMPTY));
+ }
+
+ static List<ByteString> makeConcretePieces(byte[] referenceBytes) {
+ List<ByteString> pieces = new ArrayList<ByteString>();
+ // Starting length should be small enough that we'll do some concatenating by
+ // copying if we just concatenate all these pieces together.
+ for (int start = 0, length = 16; start < referenceBytes.length; start += length) {
+ length = (length << 1) - 1;
+ if (start + length > referenceBytes.length) {
+ length = referenceBytes.length - start;
+ }
+ pieces.add(ByteString.copyFrom(referenceBytes, start, length));
+ }
+ return pieces;
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/CodedInputStreamTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/CodedInputStreamTest.java
new file mode 100644
index 0000000000..7e67898ea4
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/CodedInputStreamTest.java
@@ -0,0 +1,469 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestRecursiveMessage;
+
+import junit.framework.TestCase;
+
+import java.io.ByteArrayInputStream;
+import java.io.FilterInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+
+/**
+ * Unit test for {@link CodedInputStream}.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class CodedInputStreamTest extends TestCase {
+ /**
+ * 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];
+ for (int i = 0; i < bytesAsInts.length; i++) {
+ bytes[i] = (byte) bytesAsInts[i];
+ }
+ return bytes;
+ }
+
+ /**
+ * 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);
+ this.blockSize = blockSize;
+ }
+
+ public int read(byte[] b) throws IOException {
+ return super.read(b, 0, Math.min(b.length, blockSize));
+ }
+
+ public int read(byte[] b, int off, int len) throws IOException {
+ return super.read(b, off, Math.min(len, blockSize));
+ }
+ }
+
+ /**
+ * 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());
+
+ input = CodedInputStream.newInstance(data);
+ assertEquals(value, input.readRawVarint64());
+ assertTrue(input.isAtEnd());
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2) {
+ input = CodedInputStream.newInstance(
+ new SmallBlockInputStream(data, blockSize));
+ assertEquals((int)value, input.readRawVarint32());
+
+ input = CodedInputStream.newInstance(
+ new SmallBlockInputStream(data, blockSize));
+ assertEquals(value, input.readRawVarint64());
+ assertTrue(input.isAtEnd());
+ }
+
+ // Try reading direct from an InputStream. We want to verify that it
+ // doesn't read past the end of the input, so we copy to a new, bigger
+ // array first.
+ byte[] longerData = new byte[data.length + 1];
+ System.arraycopy(data, 0, longerData, 0, data.length);
+ InputStream rawInput = new ByteArrayInputStream(longerData);
+ }
+
+ /**
+ * 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)
+ 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());
+ }
+ }
+
+ /** Tests readRawVarint32() and readRawVarint64(). */
+ public void testReadVarint() throws Exception {
+ assertReadVarint(bytes(0x00), 0);
+ assertReadVarint(bytes(0x01), 1);
+ assertReadVarint(bytes(0x7f), 127);
+ // 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));
+
+ // 64-bit
+ // 7256456126
+ 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));
+ // 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));
+ }
+
+ /**
+ * 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());
+ }
+ }
+
+ /**
+ * 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());
+ }
+ }
+
+ /** Tests readRawLittleEndian32() and readRawLittleEndian64(). */
+ public void testReadLittleEndian() throws Exception {
+ assertReadLittleEndian32(bytes(0x78, 0x56, 0x34, 0x12), 0x12345678);
+ assertReadLittleEndian32(bytes(0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef0);
+
+ assertReadLittleEndian64(
+ bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12),
+ 0x123456789abcdef0L);
+ assertReadLittleEndian64(
+ 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(-1, CodedInputStream.decodeZigZag32(1));
+ 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(-1, CodedInputStream.decodeZigZag64(1));
+ 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));
+ }
+
+ /** Tests reading and parsing a whole message with every field type. */
+ public void testReadWholeMessage() throws Exception {
+ TestAllTypes message = TestUtil.getAllSet();
+
+ 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);
+ }
+ }
+
+ /** Tests skipField(). */
+ public void testSkipWholeMessage() throws Exception {
+ 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);
+ UnknownFieldSet.Builder unknownFields = UnknownFieldSet.newBuilder();
+
+ while (true) {
+ int tag = input1.readTag();
+ assertEquals(tag, input2.readTag());
+ if (tag == 0) {
+ break;
+ }
+ unknownFields.mergeFieldFrom(tag, input1);
+ input2.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.
+ */
+ 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());
+ }
+
+ /**
+ * 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());
+ }
+
+ public void testReadHugeBlob() throws Exception {
+ // Allocate and initialize a 1MB blob.
+ byte[] blob = new byte[1 << 20];
+ for (int i = 0; i < blob.length; i++) {
+ blob[i] = (byte)i;
+ }
+
+ // Make a message containing it.
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ 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);
+ }
+
+ public int makeTag(int number, int tag) {
+ return (number << 3) + tag;
+ }
+
+ public void testReadMaliciouslyLargeBlob() throws Exception {
+ ByteString.Output rawOutput = ByteString.newOutput();
+ CodedOutputStream output = CodedOutputStream.newInstance(rawOutput);
+
+ int tag = makeTag(1, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ output.writeRawVarint32(tag);
+ output.writeRawVarint32(0x7FFFFFFF);
+ 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.
+ }
+ }
+
+ private TestRecursiveMessage makeRecursiveMessage(int depth) {
+ if (depth == 0) {
+ return TestRecursiveMessage.newBuilder().setI(5).build();
+ } else {
+ return TestRecursiveMessage.newBuilder()
+ .setA(makeRecursiveMessage(depth - 1)).build();
+ }
+ }
+
+ private void assertMessageDepth(TestRecursiveMessage message, int depth) {
+ if (depth == 0) {
+ assertFalse(message.hasA());
+ assertEquals(5, message.getI());
+ } else {
+ assertTrue(message.hasA());
+ assertMessageDepth(message.getA(), depth - 1);
+ }
+ }
+
+ public void testResetSizeCounter() throws Exception {
+ CodedInputStream input = CodedInputStream.newInstance(
+ new SmallBlockInputStream(new byte[256], 8));
+ input.setSizeLimit(16);
+ input.readRawBytes(16);
+ assertEquals(16, input.getTotalBytesRead());
+
+ try {
+ input.readRawByte();
+ fail("Should have thrown an exception!");
+ } catch (InvalidProtocolBufferException e) {
+ // success.
+ }
+
+ input.resetSizeCounter();
+ assertEquals(0, input.getTotalBytesRead());
+ input.readRawByte(); // No exception thrown.
+ input.resetSizeCounter();
+ assertEquals(0, input.getTotalBytesRead());
+ }
+
+ /**
+ * Tests that if we read an string that contains invalid UTF-8, no exception
+ * is thrown. Instead, the invalid bytes are replaced with the Unicode
+ * "replacement character" U+FFFD.
+ */
+ public void testReadInvalidUtf8() throws Exception {
+ ByteString.Output rawOutput = ByteString.newOutput();
+ CodedOutputStream output = CodedOutputStream.newInstance(rawOutput);
+
+ int tag = makeTag(1, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ output.writeRawVarint32(tag);
+ output.writeRawVarint32(1);
+ 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));
+ }
+
+ public void testReadFromSlice() throws Exception {
+ byte[] bytes = bytes(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
+ CodedInputStream in = CodedInputStream.newInstance(bytes, 3, 5);
+ assertEquals(0, in.getTotalBytesRead());
+ for (int i = 3; i < 8; i++) {
+ assertEquals(i, in.readRawByte());
+ assertEquals(i-2, in.getTotalBytesRead());
+ }
+ // eof
+ assertEquals(0, in.readTag());
+ assertEquals(5, in.getTotalBytesRead());
+ }
+
+ 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) {
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/CodedOutputStreamTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/CodedOutputStreamTest.java
new file mode 100644
index 0000000000..354d89d664
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/CodedOutputStreamTest.java
@@ -0,0 +1,318 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+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.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Unit test for {@link CodedOutputStream}.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class CodedOutputStreamTest extends TestCase {
+ /**
+ * 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];
+ for (int i = 0; i < bytesAsInts.length; i++) {
+ bytes[i] = (byte) bytesAsInts[i];
+ }
+ return bytes;
+ }
+
+ /** Arrays.asList() does not work with arrays of primitives. :( */
+ private List<Byte> toList(byte[] bytes) {
+ List<Byte> result = new ArrayList<Byte>();
+ for (byte b : bytes) {
+ result.add(b);
+ }
+ return result;
+ }
+
+ private void assertEqualBytes(byte[] a, byte[] b) {
+ assertEquals(toList(a), toList(b));
+ }
+
+ /**
+ * Writes the given value using writeRawVarint32() and writeRawVarint64() and
+ * checks that the result matches the given bytes.
+ */
+ private void assertWriteVarint(byte[] data, long value) throws Exception {
+ // Only do 32-bit write if the value fits in 32 bits.
+ if ((value >>> 32) == 0) {
+ ByteArrayOutputStream rawOutput = new ByteArrayOutputStream();
+ CodedOutputStream output = CodedOutputStream.newInstance(rawOutput);
+ output.writeRawVarint32((int) value);
+ output.flush();
+ assertEqualBytes(data, rawOutput.toByteArray());
+
+ // Also try computing size.
+ assertEquals(data.length,
+ CodedOutputStream.computeRawVarint32Size((int) value));
+ }
+
+ {
+ ByteArrayOutputStream rawOutput = new ByteArrayOutputStream();
+ CodedOutputStream output = CodedOutputStream.newInstance(rawOutput);
+ output.writeRawVarint64(value);
+ output.flush();
+ assertEqualBytes(data, rawOutput.toByteArray());
+
+ // Also try computing size.
+ assertEquals(data.length,
+ CodedOutputStream.computeRawVarint64Size(value));
+ }
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2) {
+ // Only do 32-bit write if the value fits in 32 bits.
+ if ((value >>> 32) == 0) {
+ ByteArrayOutputStream rawOutput = new ByteArrayOutputStream();
+ CodedOutputStream output =
+ CodedOutputStream.newInstance(rawOutput, blockSize);
+ output.writeRawVarint32((int) value);
+ output.flush();
+ assertEqualBytes(data, rawOutput.toByteArray());
+ }
+
+ {
+ ByteArrayOutputStream rawOutput = new ByteArrayOutputStream();
+ CodedOutputStream output =
+ CodedOutputStream.newInstance(rawOutput, blockSize);
+ output.writeRawVarint64(value);
+ output.flush();
+ assertEqualBytes(data, rawOutput.toByteArray());
+ }
+ }
+ }
+
+ /** Tests writeRawVarint32() and writeRawVarint64(). */
+ public void testWriteVarint() throws Exception {
+ assertWriteVarint(bytes(0x00), 0);
+ assertWriteVarint(bytes(0x01), 1);
+ assertWriteVarint(bytes(0x7f), 127);
+ // 14882
+ assertWriteVarint(bytes(0xa2, 0x74), (0x22 << 0) | (0x74 << 7));
+ // 2961488830
+ assertWriteVarint(bytes(0xbe, 0xf7, 0x92, 0x84, 0x0b),
+ (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) |
+ (0x0bL << 28));
+
+ // 64-bit
+ // 7256456126
+ assertWriteVarint(bytes(0xbe, 0xf7, 0x92, 0x84, 0x1b),
+ (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) |
+ (0x1bL << 28));
+ // 41256202580718336
+ assertWriteVarint(
+ 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
+ assertWriteVarint(
+ 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));
+ }
+
+ /**
+ * Parses the given bytes using writeRawLittleEndian32() and checks
+ * that the result matches the given value.
+ */
+ private void assertWriteLittleEndian32(byte[] data, int value)
+ throws Exception {
+ ByteArrayOutputStream rawOutput = new ByteArrayOutputStream();
+ CodedOutputStream output = CodedOutputStream.newInstance(rawOutput);
+ output.writeRawLittleEndian32(value);
+ output.flush();
+ assertEqualBytes(data, rawOutput.toByteArray());
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2) {
+ rawOutput = new ByteArrayOutputStream();
+ output = CodedOutputStream.newInstance(rawOutput, blockSize);
+ output.writeRawLittleEndian32(value);
+ output.flush();
+ assertEqualBytes(data, rawOutput.toByteArray());
+ }
+ }
+
+ /**
+ * Parses the given bytes using writeRawLittleEndian64() and checks
+ * that the result matches the given value.
+ */
+ private void assertWriteLittleEndian64(byte[] data, long value)
+ throws Exception {
+ ByteArrayOutputStream rawOutput = new ByteArrayOutputStream();
+ CodedOutputStream output = CodedOutputStream.newInstance(rawOutput);
+ output.writeRawLittleEndian64(value);
+ output.flush();
+ assertEqualBytes(data, rawOutput.toByteArray());
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2) {
+ rawOutput = new ByteArrayOutputStream();
+ output = CodedOutputStream.newInstance(rawOutput, blockSize);
+ output.writeRawLittleEndian64(value);
+ output.flush();
+ assertEqualBytes(data, rawOutput.toByteArray());
+ }
+ }
+
+ /** Tests writeRawLittleEndian32() and writeRawLittleEndian64(). */
+ public void testWriteLittleEndian() throws Exception {
+ assertWriteLittleEndian32(bytes(0x78, 0x56, 0x34, 0x12), 0x12345678);
+ assertWriteLittleEndian32(bytes(0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef0);
+
+ assertWriteLittleEndian64(
+ bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12),
+ 0x123456789abcdef0L);
+ assertWriteLittleEndian64(
+ bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a),
+ 0x9abcdef012345678L);
+ }
+
+ /** Test encodeZigZag32() and encodeZigZag64(). */
+ public void testEncodeZigZag() throws Exception {
+ assertEquals(0, CodedOutputStream.encodeZigZag32( 0));
+ assertEquals(1, CodedOutputStream.encodeZigZag32(-1));
+ assertEquals(2, CodedOutputStream.encodeZigZag32( 1));
+ assertEquals(3, CodedOutputStream.encodeZigZag32(-2));
+ assertEquals(0x7FFFFFFE, CodedOutputStream.encodeZigZag32(0x3FFFFFFF));
+ assertEquals(0x7FFFFFFF, CodedOutputStream.encodeZigZag32(0xC0000000));
+ assertEquals(0xFFFFFFFE, CodedOutputStream.encodeZigZag32(0x7FFFFFFF));
+ assertEquals(0xFFFFFFFF, CodedOutputStream.encodeZigZag32(0x80000000));
+
+ assertEquals(0, CodedOutputStream.encodeZigZag64( 0));
+ assertEquals(1, CodedOutputStream.encodeZigZag64(-1));
+ assertEquals(2, CodedOutputStream.encodeZigZag64( 1));
+ assertEquals(3, CodedOutputStream.encodeZigZag64(-2));
+ assertEquals(0x000000007FFFFFFEL,
+ CodedOutputStream.encodeZigZag64(0x000000003FFFFFFFL));
+ assertEquals(0x000000007FFFFFFFL,
+ CodedOutputStream.encodeZigZag64(0xFFFFFFFFC0000000L));
+ assertEquals(0x00000000FFFFFFFEL,
+ CodedOutputStream.encodeZigZag64(0x000000007FFFFFFFL));
+ assertEquals(0x00000000FFFFFFFFL,
+ CodedOutputStream.encodeZigZag64(0xFFFFFFFF80000000L));
+ assertEquals(0xFFFFFFFFFFFFFFFEL,
+ CodedOutputStream.encodeZigZag64(0x7FFFFFFFFFFFFFFFL));
+ assertEquals(0xFFFFFFFFFFFFFFFFL,
+ CodedOutputStream.encodeZigZag64(0x8000000000000000L));
+
+ // Some easier-to-verify round-trip tests. The inputs (other than 0, 1, -1)
+ // were chosen semi-randomly via keyboard bashing.
+ assertEquals(0,
+ CodedOutputStream.encodeZigZag32(CodedInputStream.decodeZigZag32(0)));
+ assertEquals(1,
+ CodedOutputStream.encodeZigZag32(CodedInputStream.decodeZigZag32(1)));
+ assertEquals(-1,
+ CodedOutputStream.encodeZigZag32(CodedInputStream.decodeZigZag32(-1)));
+ assertEquals(14927,
+ CodedOutputStream.encodeZigZag32(CodedInputStream.decodeZigZag32(14927)));
+ assertEquals(-3612,
+ CodedOutputStream.encodeZigZag32(CodedInputStream.decodeZigZag32(-3612)));
+
+ assertEquals(0,
+ CodedOutputStream.encodeZigZag64(CodedInputStream.decodeZigZag64(0)));
+ assertEquals(1,
+ CodedOutputStream.encodeZigZag64(CodedInputStream.decodeZigZag64(1)));
+ assertEquals(-1,
+ CodedOutputStream.encodeZigZag64(CodedInputStream.decodeZigZag64(-1)));
+ assertEquals(14927,
+ CodedOutputStream.encodeZigZag64(CodedInputStream.decodeZigZag64(14927)));
+ assertEquals(-3612,
+ CodedOutputStream.encodeZigZag64(CodedInputStream.decodeZigZag64(-3612)));
+
+ assertEquals(856912304801416L,
+ CodedOutputStream.encodeZigZag64(
+ CodedInputStream.decodeZigZag64(
+ 856912304801416L)));
+ assertEquals(-75123905439571256L,
+ CodedOutputStream.encodeZigZag64(
+ CodedInputStream.decodeZigZag64(
+ -75123905439571256L)));
+ }
+
+ /** Tests writing a whole message with every field type. */
+ public void testWriteWholeMessage() throws Exception {
+ TestAllTypes message = TestUtil.getAllSet();
+
+ byte[] rawBytes = message.toByteArray();
+ assertEqualBytes(TestUtil.getGoldenMessage().toByteArray(), rawBytes);
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize < 256; blockSize *= 2) {
+ ByteArrayOutputStream rawOutput = new ByteArrayOutputStream();
+ CodedOutputStream output =
+ CodedOutputStream.newInstance(rawOutput, blockSize);
+ message.writeTo(output);
+ output.flush();
+ assertEqualBytes(rawBytes, rawOutput.toByteArray());
+ }
+ }
+
+ /** Tests writing a whole message with every packed field type. Ensures the
+ * wire format of packed fields is compatible with C++. */
+ public void testWriteWholePackedFieldsMessage() throws Exception {
+ TestPackedTypes message = TestUtil.getPackedSet();
+
+ byte[] rawBytes = message.toByteArray();
+ assertEqualBytes(TestUtil.getGoldenPackedFieldsMessage().toByteArray(),
+ rawBytes);
+ }
+
+ /** Test writing a message containing a negative enum value. This used to
+ * fail because the size was not properly computed as a sign-extended varint.
+ */
+ public void testWriteMessageWithNegativeEnumValue() throws Exception {
+ SparseEnumMessage message = SparseEnumMessage.newBuilder()
+ .setSparseEnum(TestSparseEnum.SPARSE_E) .build();
+ assertTrue(message.getSparseEnum().getNumber() < 0);
+ byte[] rawBytes = message.toByteArray();
+ SparseEnumMessage message2 = SparseEnumMessage.parseFrom(rawBytes);
+ assertEquals(TestSparseEnum.SPARSE_E, message2.getSparseEnum());
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/DeprecatedFieldTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/DeprecatedFieldTest.java
new file mode 100644
index 0000000000..ee4e767520
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/DeprecatedFieldTest.java
@@ -0,0 +1,81 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import protobuf_unittest.UnittestProto.TestDeprecatedFields;
+
+import junit.framework.TestCase;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+/**
+ * Test field deprecation
+ *
+ * @author birdo@google.com (Roberto Scaramuzzi)
+ */
+public class DeprecatedFieldTest extends TestCase {
+ private String[] deprecatedGetterNames = {
+ "hasDeprecatedInt32",
+ "getDeprecatedInt32"};
+
+ private String[] deprecatedBuilderGetterNames = {
+ "hasDeprecatedInt32",
+ "getDeprecatedInt32",
+ "clearDeprecatedInt32"};
+
+ private String[] deprecatedBuilderSetterNames = {
+ "setDeprecatedInt32"};
+
+ public void testDeprecatedField() throws Exception {
+ Class<?> deprecatedFields = TestDeprecatedFields.class;
+ Class<?> deprecatedFieldsBuilder = TestDeprecatedFields.Builder.class;
+ for (String name : deprecatedGetterNames) {
+ Method method = deprecatedFields.getMethod(name);
+ assertTrue("Method " + name + " should be deprecated",
+ isDeprecated(method));
+ }
+ for (String name : deprecatedBuilderGetterNames) {
+ Method method = deprecatedFieldsBuilder.getMethod(name);
+ assertTrue("Method " + name + " should be deprecated",
+ isDeprecated(method));
+ }
+ for (String name : deprecatedBuilderSetterNames) {
+ Method method = deprecatedFieldsBuilder.getMethod(name, int.class);
+ assertTrue("Method " + name + " should be deprecated",
+ isDeprecated(method));
+ }
+ }
+
+ private boolean isDeprecated(AnnotatedElement annotated) {
+ return annotated.isAnnotationPresent(Deprecated.class);
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/DescriptorsTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/DescriptorsTest.java
new file mode 100644
index 0000000000..aabd7b4d73
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/DescriptorsTest.java
@@ -0,0 +1,649 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import com.google.protobuf.DescriptorProtos.DescriptorProto;
+import com.google.protobuf.DescriptorProtos.EnumDescriptorProto;
+import com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto;
+import com.google.protobuf.DescriptorProtos.FieldDescriptorProto;
+import com.google.protobuf.DescriptorProtos.FileDescriptorProto;
+import com.google.protobuf.Descriptors.DescriptorValidationException;
+import com.google.protobuf.Descriptors.FileDescriptor;
+import com.google.protobuf.Descriptors.Descriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+import com.google.protobuf.Descriptors.EnumDescriptor;
+import com.google.protobuf.Descriptors.EnumValueDescriptor;
+import com.google.protobuf.Descriptors.ServiceDescriptor;
+import com.google.protobuf.Descriptors.MethodDescriptor;
+
+import com.google.protobuf.test.UnittestImport;
+import com.google.protobuf.test.UnittestImport.ImportEnum;
+import com.google.protobuf.test.UnittestImport.ImportMessage;
+import protobuf_unittest.UnittestProto;
+import protobuf_unittest.UnittestProto.ForeignEnum;
+import protobuf_unittest.UnittestProto.ForeignMessage;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestExtremeDefaultValues;
+import protobuf_unittest.UnittestProto.TestRequired;
+import protobuf_unittest.UnittestProto.TestService;
+import protobuf_unittest.UnittestCustomOptions;
+
+
+import junit.framework.TestCase;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Unit test for {@link Descriptors}.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class DescriptorsTest extends TestCase {
+
+ // Regression test for bug where referencing a FieldDescriptor.Type value
+ // before a FieldDescriptorProto.Type value would yield a
+ // ExceptionInInitializerError.
+ @SuppressWarnings("unused")
+ private static final Object STATIC_INIT_TEST = FieldDescriptor.Type.BOOL;
+
+ public void testFieldTypeEnumMapping() throws Exception {
+ assertEquals(FieldDescriptor.Type.values().length,
+ FieldDescriptorProto.Type.values().length);
+ for (FieldDescriptor.Type type : FieldDescriptor.Type.values()) {
+ FieldDescriptorProto.Type protoType = type.toProto();
+ assertEquals("TYPE_" + type.name(), protoType.name());
+ assertEquals(type, FieldDescriptor.Type.valueOf(protoType));
+ }
+ }
+
+ public void testFileDescriptor() throws Exception {
+ FileDescriptor file = UnittestProto.getDescriptor();
+
+ assertEquals("google/protobuf/unittest.proto", file.getName());
+ assertEquals("protobuf_unittest", file.getPackage());
+
+ assertEquals("UnittestProto", file.getOptions().getJavaOuterClassname());
+ assertEquals("google/protobuf/unittest.proto",
+ file.toProto().getName());
+
+ assertEquals(Arrays.asList(UnittestImport.getDescriptor()),
+ file.getDependencies());
+
+ Descriptor messageType = TestAllTypes.getDescriptor();
+ assertEquals(messageType, file.getMessageTypes().get(0));
+ assertEquals(messageType, file.findMessageTypeByName("TestAllTypes"));
+ assertNull(file.findMessageTypeByName("NoSuchType"));
+ assertNull(file.findMessageTypeByName("protobuf_unittest.TestAllTypes"));
+ for (int i = 0; i < file.getMessageTypes().size(); i++) {
+ assertEquals(i, file.getMessageTypes().get(i).getIndex());
+ }
+
+ EnumDescriptor enumType = ForeignEnum.getDescriptor();
+ assertEquals(enumType, file.getEnumTypes().get(0));
+ assertEquals(enumType, file.findEnumTypeByName("ForeignEnum"));
+ assertNull(file.findEnumTypeByName("NoSuchType"));
+ assertNull(file.findEnumTypeByName("protobuf_unittest.ForeignEnum"));
+ assertEquals(Arrays.asList(ImportEnum.getDescriptor()),
+ UnittestImport.getDescriptor().getEnumTypes());
+ for (int i = 0; i < file.getEnumTypes().size(); i++) {
+ assertEquals(i, file.getEnumTypes().get(i).getIndex());
+ }
+
+ ServiceDescriptor service = TestService.getDescriptor();
+ assertEquals(service, file.getServices().get(0));
+ assertEquals(service, file.findServiceByName("TestService"));
+ assertNull(file.findServiceByName("NoSuchType"));
+ assertNull(file.findServiceByName("protobuf_unittest.TestService"));
+ assertEquals(Collections.emptyList(),
+ UnittestImport.getDescriptor().getServices());
+ for (int i = 0; i < file.getServices().size(); i++) {
+ assertEquals(i, file.getServices().get(i).getIndex());
+ }
+
+ FieldDescriptor extension =
+ UnittestProto.optionalInt32Extension.getDescriptor();
+ assertEquals(extension, file.getExtensions().get(0));
+ assertEquals(extension,
+ file.findExtensionByName("optional_int32_extension"));
+ assertNull(file.findExtensionByName("no_such_ext"));
+ assertNull(file.findExtensionByName(
+ "protobuf_unittest.optional_int32_extension"));
+ assertEquals(Collections.emptyList(),
+ UnittestImport.getDescriptor().getExtensions());
+ for (int i = 0; i < file.getExtensions().size(); i++) {
+ assertEquals(i, file.getExtensions().get(i).getIndex());
+ }
+ }
+
+ public void testDescriptor() throws Exception {
+ Descriptor messageType = TestAllTypes.getDescriptor();
+ Descriptor nestedType = TestAllTypes.NestedMessage.getDescriptor();
+
+ assertEquals("TestAllTypes", messageType.getName());
+ assertEquals("protobuf_unittest.TestAllTypes", messageType.getFullName());
+ assertEquals(UnittestProto.getDescriptor(), messageType.getFile());
+ assertNull(messageType.getContainingType());
+ assertEquals(DescriptorProtos.MessageOptions.getDefaultInstance(),
+ messageType.getOptions());
+ assertEquals("TestAllTypes", messageType.toProto().getName());
+
+ assertEquals("NestedMessage", nestedType.getName());
+ assertEquals("protobuf_unittest.TestAllTypes.NestedMessage",
+ nestedType.getFullName());
+ assertEquals(UnittestProto.getDescriptor(), nestedType.getFile());
+ assertEquals(messageType, nestedType.getContainingType());
+
+ FieldDescriptor field = messageType.getFields().get(0);
+ assertEquals("optional_int32", field.getName());
+ assertEquals(field, messageType.findFieldByName("optional_int32"));
+ assertNull(messageType.findFieldByName("no_such_field"));
+ assertEquals(field, messageType.findFieldByNumber(1));
+ assertNull(messageType.findFieldByNumber(571283));
+ for (int i = 0; i < messageType.getFields().size(); i++) {
+ assertEquals(i, messageType.getFields().get(i).getIndex());
+ }
+
+ assertEquals(nestedType, messageType.getNestedTypes().get(0));
+ assertEquals(nestedType, messageType.findNestedTypeByName("NestedMessage"));
+ assertNull(messageType.findNestedTypeByName("NoSuchType"));
+ for (int i = 0; i < messageType.getNestedTypes().size(); i++) {
+ assertEquals(i, messageType.getNestedTypes().get(i).getIndex());
+ }
+
+ EnumDescriptor enumType = TestAllTypes.NestedEnum.getDescriptor();
+ assertEquals(enumType, messageType.getEnumTypes().get(0));
+ assertEquals(enumType, messageType.findEnumTypeByName("NestedEnum"));
+ assertNull(messageType.findEnumTypeByName("NoSuchType"));
+ for (int i = 0; i < messageType.getEnumTypes().size(); i++) {
+ assertEquals(i, messageType.getEnumTypes().get(i).getIndex());
+ }
+ }
+
+ public void testFieldDescriptor() throws Exception {
+ Descriptor messageType = TestAllTypes.getDescriptor();
+ FieldDescriptor primitiveField =
+ messageType.findFieldByName("optional_int32");
+ FieldDescriptor enumField =
+ messageType.findFieldByName("optional_nested_enum");
+ FieldDescriptor messageField =
+ messageType.findFieldByName("optional_foreign_message");
+ FieldDescriptor cordField =
+ messageType.findFieldByName("optional_cord");
+ FieldDescriptor extension =
+ UnittestProto.optionalInt32Extension.getDescriptor();
+ FieldDescriptor nestedExtension = TestRequired.single.getDescriptor();
+
+ assertEquals("optional_int32", primitiveField.getName());
+ assertEquals("protobuf_unittest.TestAllTypes.optional_int32",
+ primitiveField.getFullName());
+ assertEquals(1, primitiveField.getNumber());
+ assertEquals(messageType, primitiveField.getContainingType());
+ assertEquals(UnittestProto.getDescriptor(), primitiveField.getFile());
+ assertEquals(FieldDescriptor.Type.INT32, primitiveField.getType());
+ assertEquals(FieldDescriptor.JavaType.INT, primitiveField.getJavaType());
+ assertEquals(DescriptorProtos.FieldOptions.getDefaultInstance(),
+ primitiveField.getOptions());
+ assertFalse(primitiveField.isExtension());
+ assertEquals("optional_int32", primitiveField.toProto().getName());
+
+ assertEquals("optional_nested_enum", enumField.getName());
+ assertEquals(FieldDescriptor.Type.ENUM, enumField.getType());
+ assertEquals(FieldDescriptor.JavaType.ENUM, enumField.getJavaType());
+ assertEquals(TestAllTypes.NestedEnum.getDescriptor(),
+ enumField.getEnumType());
+
+ assertEquals("optional_foreign_message", messageField.getName());
+ assertEquals(FieldDescriptor.Type.MESSAGE, messageField.getType());
+ assertEquals(FieldDescriptor.JavaType.MESSAGE, messageField.getJavaType());
+ assertEquals(ForeignMessage.getDescriptor(), messageField.getMessageType());
+
+ assertEquals("optional_cord", cordField.getName());
+ assertEquals(FieldDescriptor.Type.STRING, cordField.getType());
+ assertEquals(FieldDescriptor.JavaType.STRING, cordField.getJavaType());
+ assertEquals(DescriptorProtos.FieldOptions.CType.CORD,
+ cordField.getOptions().getCtype());
+
+ assertEquals("optional_int32_extension", extension.getName());
+ assertEquals("protobuf_unittest.optional_int32_extension",
+ extension.getFullName());
+ assertEquals(1, extension.getNumber());
+ assertEquals(TestAllExtensions.getDescriptor(),
+ extension.getContainingType());
+ assertEquals(UnittestProto.getDescriptor(), extension.getFile());
+ assertEquals(FieldDescriptor.Type.INT32, extension.getType());
+ assertEquals(FieldDescriptor.JavaType.INT, extension.getJavaType());
+ assertEquals(DescriptorProtos.FieldOptions.getDefaultInstance(),
+ extension.getOptions());
+ assertTrue(extension.isExtension());
+ assertEquals(null, extension.getExtensionScope());
+ assertEquals("optional_int32_extension", extension.toProto().getName());
+
+ assertEquals("single", nestedExtension.getName());
+ assertEquals("protobuf_unittest.TestRequired.single",
+ nestedExtension.getFullName());
+ assertEquals(TestRequired.getDescriptor(),
+ nestedExtension.getExtensionScope());
+ }
+
+ public void testFieldDescriptorLabel() throws Exception {
+ FieldDescriptor requiredField =
+ TestRequired.getDescriptor().findFieldByName("a");
+ FieldDescriptor optionalField =
+ TestAllTypes.getDescriptor().findFieldByName("optional_int32");
+ FieldDescriptor repeatedField =
+ TestAllTypes.getDescriptor().findFieldByName("repeated_int32");
+
+ assertTrue(requiredField.isRequired());
+ assertFalse(requiredField.isRepeated());
+ assertFalse(optionalField.isRequired());
+ assertFalse(optionalField.isRepeated());
+ assertFalse(repeatedField.isRequired());
+ assertTrue(repeatedField.isRepeated());
+ }
+
+ public void testFieldDescriptorDefault() throws Exception {
+ Descriptor d = TestAllTypes.getDescriptor();
+ assertFalse(d.findFieldByName("optional_int32").hasDefaultValue());
+ assertEquals(0, d.findFieldByName("optional_int32").getDefaultValue());
+ assertTrue(d.findFieldByName("default_int32").hasDefaultValue());
+ assertEquals(41, d.findFieldByName("default_int32").getDefaultValue());
+
+ d = TestExtremeDefaultValues.getDescriptor();
+ assertEquals(
+ ByteString.copyFrom(
+ "\0\001\007\b\f\n\r\t\013\\\'\"\u00fe".getBytes("ISO-8859-1")),
+ d.findFieldByName("escaped_bytes").getDefaultValue());
+ assertEquals(-1, d.findFieldByName("large_uint32").getDefaultValue());
+ assertEquals(-1L, d.findFieldByName("large_uint64").getDefaultValue());
+ }
+
+ public void testEnumDescriptor() throws Exception {
+ EnumDescriptor enumType = ForeignEnum.getDescriptor();
+ EnumDescriptor nestedType = TestAllTypes.NestedEnum.getDescriptor();
+
+ assertEquals("ForeignEnum", enumType.getName());
+ assertEquals("protobuf_unittest.ForeignEnum", enumType.getFullName());
+ assertEquals(UnittestProto.getDescriptor(), enumType.getFile());
+ assertNull(enumType.getContainingType());
+ assertEquals(DescriptorProtos.EnumOptions.getDefaultInstance(),
+ enumType.getOptions());
+
+ assertEquals("NestedEnum", nestedType.getName());
+ assertEquals("protobuf_unittest.TestAllTypes.NestedEnum",
+ nestedType.getFullName());
+ assertEquals(UnittestProto.getDescriptor(), nestedType.getFile());
+ assertEquals(TestAllTypes.getDescriptor(), nestedType.getContainingType());
+
+ EnumValueDescriptor value = ForeignEnum.FOREIGN_FOO.getValueDescriptor();
+ assertEquals(value, enumType.getValues().get(0));
+ assertEquals("FOREIGN_FOO", value.getName());
+ assertEquals(4, value.getNumber());
+ assertEquals(value, enumType.findValueByName("FOREIGN_FOO"));
+ assertEquals(value, enumType.findValueByNumber(4));
+ assertNull(enumType.findValueByName("NO_SUCH_VALUE"));
+ for (int i = 0; i < enumType.getValues().size(); i++) {
+ assertEquals(i, enumType.getValues().get(i).getIndex());
+ }
+ }
+
+ public void testServiceDescriptor() throws Exception {
+ ServiceDescriptor service = TestService.getDescriptor();
+
+ assertEquals("TestService", service.getName());
+ assertEquals("protobuf_unittest.TestService", service.getFullName());
+ assertEquals(UnittestProto.getDescriptor(), service.getFile());
+
+ assertEquals(2, service.getMethods().size());
+
+ MethodDescriptor fooMethod = service.getMethods().get(0);
+ assertEquals("Foo", fooMethod.getName());
+ assertEquals(UnittestProto.FooRequest.getDescriptor(),
+ fooMethod.getInputType());
+ assertEquals(UnittestProto.FooResponse.getDescriptor(),
+ fooMethod.getOutputType());
+ assertEquals(fooMethod, service.findMethodByName("Foo"));
+
+ MethodDescriptor barMethod = service.getMethods().get(1);
+ assertEquals("Bar", barMethod.getName());
+ assertEquals(UnittestProto.BarRequest.getDescriptor(),
+ barMethod.getInputType());
+ assertEquals(UnittestProto.BarResponse.getDescriptor(),
+ barMethod.getOutputType());
+ assertEquals(barMethod, service.findMethodByName("Bar"));
+
+ assertNull(service.findMethodByName("NoSuchMethod"));
+
+ for (int i = 0; i < service.getMethods().size(); i++) {
+ assertEquals(i, service.getMethods().get(i).getIndex());
+ }
+ }
+
+
+ public void testCustomOptions() throws Exception {
+ Descriptor descriptor =
+ UnittestCustomOptions.TestMessageWithCustomOptions.getDescriptor();
+
+ assertTrue(
+ descriptor.getOptions().hasExtension(UnittestCustomOptions.messageOpt1));
+ assertEquals(Integer.valueOf(-56),
+ descriptor.getOptions().getExtension(UnittestCustomOptions.messageOpt1));
+
+ FieldDescriptor field = descriptor.findFieldByName("field1");
+ assertNotNull(field);
+
+ assertTrue(
+ field.getOptions().hasExtension(UnittestCustomOptions.fieldOpt1));
+ assertEquals(Long.valueOf(8765432109L),
+ field.getOptions().getExtension(UnittestCustomOptions.fieldOpt1));
+
+ EnumDescriptor enumType =
+ UnittestCustomOptions.TestMessageWithCustomOptions.AnEnum.getDescriptor();
+
+ assertTrue(
+ enumType.getOptions().hasExtension(UnittestCustomOptions.enumOpt1));
+ assertEquals(Integer.valueOf(-789),
+ enumType.getOptions().getExtension(UnittestCustomOptions.enumOpt1));
+
+ ServiceDescriptor service =
+ UnittestCustomOptions.TestServiceWithCustomOptions.getDescriptor();
+
+ assertTrue(
+ service.getOptions().hasExtension(UnittestCustomOptions.serviceOpt1));
+ assertEquals(Long.valueOf(-9876543210L),
+ service.getOptions().getExtension(UnittestCustomOptions.serviceOpt1));
+
+ MethodDescriptor method = service.findMethodByName("Foo");
+ assertNotNull(method);
+
+ assertTrue(
+ method.getOptions().hasExtension(UnittestCustomOptions.methodOpt1));
+ assertEquals(UnittestCustomOptions.MethodOpt1.METHODOPT1_VAL2,
+ method.getOptions().getExtension(UnittestCustomOptions.methodOpt1));
+ }
+
+ /**
+ * Test that the FieldDescriptor.Type enum is the same as the
+ * WireFormat.FieldType enum.
+ */
+ public void testFieldTypeTablesMatch() throws Exception {
+ FieldDescriptor.Type[] values1 = FieldDescriptor.Type.values();
+ WireFormat.FieldType[] values2 = WireFormat.FieldType.values();
+
+ assertEquals(values1.length, values2.length);
+
+ for (int i = 0; i < values1.length; i++) {
+ assertEquals(values1[i].toString(), values2[i].toString());
+ }
+ }
+
+ /**
+ * Test that the FieldDescriptor.JavaType enum is the same as the
+ * WireFormat.JavaType enum.
+ */
+ public void testJavaTypeTablesMatch() throws Exception {
+ FieldDescriptor.JavaType[] values1 = FieldDescriptor.JavaType.values();
+ WireFormat.JavaType[] values2 = WireFormat.JavaType.values();
+
+ assertEquals(values1.length, values2.length);
+
+ for (int i = 0; i < values1.length; i++) {
+ assertEquals(values1[i].toString(), values2[i].toString());
+ }
+ }
+
+ public void testEnormousDescriptor() throws Exception {
+ // The descriptor for this file is larger than 64k, yet it did not cause
+ // a compiler error due to an over-long string literal.
+ assertTrue(
+ UnittestEnormousDescriptor.getDescriptor()
+ .toProto().getSerializedSize() > 65536);
+ }
+
+ /**
+ * Tests that the DescriptorValidationException works as intended.
+ */
+ public void testDescriptorValidatorException() throws Exception {
+ FileDescriptorProto fileDescriptorProto = FileDescriptorProto.newBuilder()
+ .setName("foo.proto")
+ .addMessageType(DescriptorProto.newBuilder()
+ .setName("Foo")
+ .addField(FieldDescriptorProto.newBuilder()
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
+ .setType(FieldDescriptorProto.Type.TYPE_INT32)
+ .setName("foo")
+ .setNumber(1)
+ .setDefaultValue("invalid")
+ .build())
+ .build())
+ .build();
+ try {
+ Descriptors.FileDescriptor.buildFrom(fileDescriptorProto,
+ new FileDescriptor[0]);
+ fail("DescriptorValidationException expected");
+ } catch (DescriptorValidationException e) {
+ // Expected; check that the error message contains some useful hints
+ assertTrue(e.getMessage().indexOf("foo") != -1);
+ assertTrue(e.getMessage().indexOf("Foo") != -1);
+ assertTrue(e.getMessage().indexOf("invalid") != -1);
+ assertTrue(e.getCause() instanceof NumberFormatException);
+ assertTrue(e.getCause().getMessage().indexOf("invalid") != -1);
+ }
+ }
+
+ /**
+ * Tests the translate/crosslink for an example where a message field's name
+ * and type name are the same.
+ */
+ public void testDescriptorComplexCrosslink() throws Exception {
+ FileDescriptorProto fileDescriptorProto = FileDescriptorProto.newBuilder()
+ .setName("foo.proto")
+ .addMessageType(DescriptorProto.newBuilder()
+ .setName("Foo")
+ .addField(FieldDescriptorProto.newBuilder()
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
+ .setType(FieldDescriptorProto.Type.TYPE_INT32)
+ .setName("foo")
+ .setNumber(1)
+ .build())
+ .build())
+ .addMessageType(DescriptorProto.newBuilder()
+ .setName("Bar")
+ .addField(FieldDescriptorProto.newBuilder()
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
+ .setTypeName("Foo")
+ .setName("Foo")
+ .setNumber(1)
+ .build())
+ .build())
+ .build();
+ // translate and crosslink
+ FileDescriptor file =
+ Descriptors.FileDescriptor.buildFrom(fileDescriptorProto,
+ new FileDescriptor[0]);
+ // verify resulting descriptors
+ assertNotNull(file);
+ List<Descriptor> msglist = file.getMessageTypes();
+ assertNotNull(msglist);
+ assertTrue(msglist.size() == 2);
+ boolean barFound = false;
+ for (Descriptor desc : msglist) {
+ if (desc.getName().equals("Bar")) {
+ barFound = true;
+ assertNotNull(desc.getFields());
+ List<FieldDescriptor> fieldlist = desc.getFields();
+ assertNotNull(fieldlist);
+ assertTrue(fieldlist.size() == 1);
+ assertTrue(fieldlist.get(0).getType() == FieldDescriptor.Type.MESSAGE);
+ assertTrue(fieldlist.get(0).getMessageType().getName().equals("Foo"));
+ }
+ }
+ assertTrue(barFound);
+ }
+
+ public void testInvalidPublicDependency() throws Exception {
+ FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
+ .setName("foo.proto") .build();
+ FileDescriptorProto barProto = FileDescriptorProto.newBuilder()
+ .setName("boo.proto")
+ .addDependency("foo.proto")
+ .addPublicDependency(1) // Error, should be 0.
+ .build();
+ FileDescriptor fooFile = Descriptors.FileDescriptor.buildFrom(fooProto,
+ new FileDescriptor[0]);
+ try {
+ Descriptors.FileDescriptor.buildFrom(barProto,
+ new FileDescriptor[] {fooFile});
+ fail("DescriptorValidationException expected");
+ } catch (DescriptorValidationException e) {
+ assertTrue(
+ e.getMessage().indexOf("Invalid public dependency index.") != -1);
+ }
+ }
+
+ public void testHiddenDependency() throws Exception {
+ FileDescriptorProto barProto = FileDescriptorProto.newBuilder()
+ .setName("bar.proto")
+ .addMessageType(DescriptorProto.newBuilder().setName("Bar"))
+ .build();
+ FileDescriptorProto forwardProto = FileDescriptorProto.newBuilder()
+ .setName("forward.proto")
+ .addDependency("bar.proto")
+ .build();
+ FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
+ .setName("foo.proto")
+ .addDependency("forward.proto")
+ .addMessageType(DescriptorProto.newBuilder()
+ .setName("Foo")
+ .addField(FieldDescriptorProto.newBuilder()
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
+ .setTypeName("Bar")
+ .setName("bar")
+ .setNumber(1)))
+ .build();
+ FileDescriptor barFile = Descriptors.FileDescriptor.buildFrom(
+ barProto, new FileDescriptor[0]);
+ FileDescriptor forwardFile = Descriptors.FileDescriptor.buildFrom(
+ forwardProto, new FileDescriptor[] {barFile});
+
+ try {
+ Descriptors.FileDescriptor.buildFrom(
+ fooProto, new FileDescriptor[] {forwardFile});
+ fail("DescriptorValidationException expected");
+ } catch (DescriptorValidationException e) {
+ assertTrue(e.getMessage().indexOf("Bar") != -1);
+ assertTrue(e.getMessage().indexOf("is not defined") != -1);
+ }
+ }
+
+ public void testPublicDependency() throws Exception {
+ FileDescriptorProto barProto = FileDescriptorProto.newBuilder()
+ .setName("bar.proto")
+ .addMessageType(DescriptorProto.newBuilder().setName("Bar"))
+ .build();
+ FileDescriptorProto forwardProto = FileDescriptorProto.newBuilder()
+ .setName("forward.proto")
+ .addDependency("bar.proto")
+ .addPublicDependency(0)
+ .build();
+ FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
+ .setName("foo.proto")
+ .addDependency("forward.proto")
+ .addMessageType(DescriptorProto.newBuilder()
+ .setName("Foo")
+ .addField(FieldDescriptorProto.newBuilder()
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
+ .setTypeName("Bar")
+ .setName("bar")
+ .setNumber(1)))
+ .build();
+ FileDescriptor barFile = Descriptors.FileDescriptor.buildFrom(
+ barProto, new FileDescriptor[0]);
+ FileDescriptor forwardFile = Descriptors.FileDescriptor.buildFrom(
+ forwardProto, new FileDescriptor[]{barFile});
+ Descriptors.FileDescriptor.buildFrom(
+ fooProto, new FileDescriptor[] {forwardFile});
+ }
+
+ /**
+ * Tests the translate/crosslink for an example with a more complex namespace
+ * referencing.
+ */
+ public void testComplexNamespacePublicDependency() throws Exception {
+ FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
+ .setName("bar.proto")
+ .setPackage("a.b.c.d.bar.shared")
+ .addEnumType(EnumDescriptorProto.newBuilder()
+ .setName("MyEnum")
+ .addValue(EnumValueDescriptorProto.newBuilder()
+ .setName("BLAH")
+ .setNumber(1)))
+ .build();
+ FileDescriptorProto barProto = FileDescriptorProto.newBuilder()
+ .setName("foo.proto")
+ .addDependency("bar.proto")
+ .setPackage("a.b.c.d.foo.shared")
+ .addMessageType(DescriptorProto.newBuilder()
+ .setName("MyMessage")
+ .addField(FieldDescriptorProto.newBuilder()
+ .setLabel(FieldDescriptorProto.Label.LABEL_REPEATED)
+ .setTypeName("bar.shared.MyEnum")
+ .setName("MyField")
+ .setNumber(1)))
+ .build();
+ // translate and crosslink
+ FileDescriptor fooFile = Descriptors.FileDescriptor.buildFrom(
+ fooProto, new FileDescriptor[0]);
+ FileDescriptor barFile = Descriptors.FileDescriptor.buildFrom(
+ barProto, new FileDescriptor[]{fooFile});
+ // verify resulting descriptors
+ assertNotNull(barFile);
+ List<Descriptor> msglist = barFile.getMessageTypes();
+ assertNotNull(msglist);
+ assertTrue(msglist.size() == 1);
+ Descriptor desc = msglist.get(0);
+ if (desc.getName().equals("MyMessage")) {
+ assertNotNull(desc.getFields());
+ List<FieldDescriptor> fieldlist = desc.getFields();
+ assertNotNull(fieldlist);
+ assertTrue(fieldlist.size() == 1);
+ FieldDescriptor field = fieldlist.get(0);
+ assertTrue(field.getType() == FieldDescriptor.Type.ENUM);
+ assertTrue(field.getEnumType().getName().equals("MyEnum"));
+ assertTrue(field.getEnumType().getFile().getName().equals("bar.proto"));
+ assertTrue(field.getEnumType().getFile().getPackage().equals(
+ "a.b.c.d.bar.shared"));
+ }
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/DynamicMessageTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/DynamicMessageTest.java
new file mode 100644
index 0000000000..00230678fb
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/DynamicMessageTest.java
@@ -0,0 +1,265 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+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;
+
+/**
+ * Unit test for {@link DynamicMessage}. See also {@link MessageTest}, which
+ * tests some {@link DynamicMessage} functionality.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class DynamicMessageTest extends TestCase {
+ TestUtil.ReflectionTester reflectionTester =
+ new TestUtil.ReflectionTester(TestAllTypes.getDescriptor(), null);
+
+ TestUtil.ReflectionTester extensionsReflectionTester =
+ new TestUtil.ReflectionTester(TestAllExtensions.getDescriptor(),
+ TestUtil.getExtensionRegistry());
+ TestUtil.ReflectionTester packedReflectionTester =
+ new TestUtil.ReflectionTester(TestPackedTypes.getDescriptor(), null);
+
+ public void testDynamicMessageAccessors() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ reflectionTester.setAllFieldsViaReflection(builder);
+ Message message = builder.build();
+ reflectionTester.assertAllFieldsSetViaReflection(message);
+ }
+
+ public void testSettersAfterBuild() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ Message firstMessage = builder.build();
+ // double build()
+ builder.build();
+ // clear() after build()
+ builder.clear();
+ // setters after build()
+ reflectionTester.setAllFieldsViaReflection(builder);
+ Message message = builder.build();
+ reflectionTester.assertAllFieldsSetViaReflection(message);
+ // repeated setters after build()
+ reflectionTester.modifyRepeatedFieldsViaReflection(builder);
+ message = builder.build();
+ reflectionTester.assertRepeatedFieldsModifiedViaReflection(message);
+ // firstMessage shouldn't have been modified.
+ reflectionTester.assertClearViaReflection(firstMessage);
+ }
+
+ public void testUnknownFields() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestEmptyMessage.getDescriptor());
+ builder.setUnknownFields(UnknownFieldSet.newBuilder()
+ .addField(1, UnknownFieldSet.Field.newBuilder().addVarint(1).build())
+ .addField(2, UnknownFieldSet.Field.newBuilder().addFixed32(1).build())
+ .build());
+ Message message = builder.build();
+ assertEquals(2, message.getUnknownFields().asMap().size());
+ // clone() with unknown fields
+ Message.Builder newBuilder = builder.clone();
+ assertEquals(2, newBuilder.getUnknownFields().asMap().size());
+ // clear() with unknown fields
+ newBuilder.clear();
+ assertTrue(newBuilder.getUnknownFields().asMap().isEmpty());
+ // serialize/parse with unknown fields
+ newBuilder.mergeFrom(message.toByteString());
+ assertEquals(2, newBuilder.getUnknownFields().asMap().size());
+ }
+
+ public void testDynamicMessageSettersRejectNull() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ reflectionTester.assertReflectionSettersRejectNull(builder);
+ }
+
+ public void testDynamicMessageExtensionAccessors() throws Exception {
+ // We don't need to extensively test DynamicMessage's handling of
+ // extensions because, frankly, it doesn't do anything special with them.
+ // It treats them just like any other fields.
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestAllExtensions.getDescriptor());
+ extensionsReflectionTester.setAllFieldsViaReflection(builder);
+ Message message = builder.build();
+ extensionsReflectionTester.assertAllFieldsSetViaReflection(message);
+ }
+
+ public void testDynamicMessageExtensionSettersRejectNull() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestAllExtensions.getDescriptor());
+ extensionsReflectionTester.assertReflectionSettersRejectNull(builder);
+ }
+
+ public void testDynamicMessageRepeatedSetters() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ reflectionTester.setAllFieldsViaReflection(builder);
+ reflectionTester.modifyRepeatedFieldsViaReflection(builder);
+ Message message = builder.build();
+ reflectionTester.assertRepeatedFieldsModifiedViaReflection(message);
+ }
+
+ public void testDynamicMessageRepeatedSettersRejectNull() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ reflectionTester.assertReflectionRepeatedSettersRejectNull(builder);
+ }
+
+ public void testDynamicMessageDefaults() throws Exception {
+ reflectionTester.assertClearViaReflection(
+ DynamicMessage.getDefaultInstance(TestAllTypes.getDescriptor()));
+ reflectionTester.assertClearViaReflection(
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor()).build());
+ }
+
+ public void testDynamicMessageSerializedSize() throws Exception {
+ TestAllTypes message = TestUtil.getAllSet();
+
+ Message.Builder dynamicBuilder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ reflectionTester.setAllFieldsViaReflection(dynamicBuilder);
+ Message dynamicMessage = dynamicBuilder.build();
+
+ assertEquals(message.getSerializedSize(),
+ dynamicMessage.getSerializedSize());
+ }
+
+ public void testDynamicMessageSerialization() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ reflectionTester.setAllFieldsViaReflection(builder);
+ Message message = builder.build();
+
+ ByteString rawBytes = message.toByteString();
+ TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
+
+ TestUtil.assertAllFieldsSet(message2);
+
+ // In fact, the serialized forms should be exactly the same, byte-for-byte.
+ assertEquals(TestUtil.getAllSet().toByteString(), rawBytes);
+ }
+
+ public void testDynamicMessageParsing() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ TestAllTypes message = builder.build();
+
+ ByteString rawBytes = message.toByteString();
+
+ Message message2 =
+ DynamicMessage.parseFrom(TestAllTypes.getDescriptor(), rawBytes);
+ reflectionTester.assertAllFieldsSetViaReflection(message2);
+
+ // Test Parser interface.
+ Message message3 = message2.getParserForType().parseFrom(rawBytes);
+ reflectionTester.assertAllFieldsSetViaReflection(message3);
+ }
+
+ public void testDynamicMessageExtensionParsing() throws Exception {
+ ByteString rawBytes = TestUtil.getAllExtensionsSet().toByteString();
+ Message message = DynamicMessage.parseFrom(
+ TestAllExtensions.getDescriptor(), rawBytes,
+ TestUtil.getExtensionRegistry());
+ extensionsReflectionTester.assertAllFieldsSetViaReflection(message);
+
+ // Test Parser interface.
+ Message message2 = message.getParserForType().parseFrom(
+ rawBytes, TestUtil.getExtensionRegistry());
+ extensionsReflectionTester.assertAllFieldsSetViaReflection(message2);
+ }
+
+ public void testDynamicMessagePackedSerialization() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestPackedTypes.getDescriptor());
+ packedReflectionTester.setPackedFieldsViaReflection(builder);
+ Message message = builder.build();
+
+ ByteString rawBytes = message.toByteString();
+ TestPackedTypes message2 = TestPackedTypes.parseFrom(rawBytes);
+
+ TestUtil.assertPackedFieldsSet(message2);
+
+ // In fact, the serialized forms should be exactly the same, byte-for-byte.
+ assertEquals(TestUtil.getPackedSet().toByteString(), rawBytes);
+ }
+
+ public void testDynamicMessagePackedParsing() throws Exception {
+ TestPackedTypes.Builder builder = TestPackedTypes.newBuilder();
+ TestUtil.setPackedFields(builder);
+ TestPackedTypes message = builder.build();
+
+ ByteString rawBytes = message.toByteString();
+
+ Message message2 =
+ DynamicMessage.parseFrom(TestPackedTypes.getDescriptor(), rawBytes);
+ packedReflectionTester.assertPackedFieldsSetViaReflection(message2);
+
+ // Test Parser interface.
+ Message message3 = message2.getParserForType().parseFrom(rawBytes);
+ packedReflectionTester.assertPackedFieldsSetViaReflection(message3);
+ }
+
+ public void testDynamicMessageCopy() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ TestAllTypes message = builder.build();
+
+ DynamicMessage copy = DynamicMessage.newBuilder(message).build();
+ reflectionTester.assertAllFieldsSetViaReflection(copy);
+ }
+
+ public void testToBuilder() throws Exception {
+ DynamicMessage.Builder builder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ reflectionTester.setAllFieldsViaReflection(builder);
+ int unknownFieldNum = 9;
+ long unknownFieldVal = 90;
+ builder.setUnknownFields(UnknownFieldSet.newBuilder()
+ .addField(unknownFieldNum,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(unknownFieldVal).build())
+ .build());
+ DynamicMessage message = builder.build();
+
+ DynamicMessage derived = message.toBuilder().build();
+ reflectionTester.assertAllFieldsSetViaReflection(derived);
+ assertEquals(Arrays.asList(unknownFieldVal),
+ derived.getUnknownFields().getField(unknownFieldNum).getVarintList());
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ForceFieldBuildersPreRun.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ForceFieldBuildersPreRun.java
new file mode 100644
index 0000000000..6a39500ead
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ForceFieldBuildersPreRun.java
@@ -0,0 +1,49 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+/**
+ * A prerun for a test suite that allows running the full protocol buffer
+ * tests in a mode that disables the optimization for not using
+ * {@link RepeatedFieldBuilder} and {@link SingleFieldBuilder} until they are
+ * requested. This allows us to run all the tests through both code paths
+ * and ensures that both code paths produce identical results.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class ForceFieldBuildersPreRun implements Runnable {
+
+ //@Override (Java 1.6 override semantics, but we must support 1.5)
+ public void run() {
+ // GeneratedMessage.enableAlwaysUseFieldBuildersForTesting();
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/GeneratedMessageTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/GeneratedMessageTest.java
new file mode 100644
index 0000000000..49f114643c
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/GeneratedMessageTest.java
@@ -0,0 +1,961 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import com.google.protobuf.Descriptors.Descriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+import com.google.protobuf.test.UnittestImport;
+import protobuf_unittest.EnumWithNoOuter;
+import protobuf_unittest.MessageWithNoOuter;
+import protobuf_unittest.MultipleFilesTestProto;
+import protobuf_unittest.NestedExtension.MyNestedExtension;
+import protobuf_unittest.NonNestedExtension;
+import protobuf_unittest.NonNestedExtension.MessageToBeExtended;
+import protobuf_unittest.NonNestedExtension.MyNonNestedExtension;
+import protobuf_unittest.ServiceWithNoOuter;
+import protobuf_unittest.UnittestOptimizeFor.TestOptimizedForSize;
+import protobuf_unittest.UnittestOptimizeFor.TestOptionalOptimizedForSize;
+import protobuf_unittest.UnittestOptimizeFor.TestRequiredOptimizedForSize;
+import protobuf_unittest.UnittestProto;
+import protobuf_unittest.UnittestProto.ForeignEnum;
+import protobuf_unittest.UnittestProto.ForeignMessage;
+import protobuf_unittest.UnittestProto.ForeignMessageOrBuilder;
+import protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestAllTypes.NestedMessage;
+import protobuf_unittest.UnittestProto.TestAllTypesOrBuilder;
+import protobuf_unittest.UnittestProto.TestExtremeDefaultValues;
+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;
+import java.io.ObjectOutputStream;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Unit test for generated messages and generated code. See also
+ * {@link MessageTest}, which tests some generated message functionality.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class GeneratedMessageTest extends TestCase {
+ TestUtil.ReflectionTester reflectionTester =
+ new TestUtil.ReflectionTester(TestAllTypes.getDescriptor(), null);
+
+ public void testDefaultInstance() throws Exception {
+ assertSame(TestAllTypes.getDefaultInstance(),
+ TestAllTypes.getDefaultInstance().getDefaultInstanceForType());
+ assertSame(TestAllTypes.getDefaultInstance(),
+ TestAllTypes.newBuilder().getDefaultInstanceForType());
+ }
+
+ public void testMessageOrBuilder() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ TestAllTypes message = builder.build();
+ TestUtil.assertAllFieldsSet(message);
+ }
+
+ public void testUsingBuilderMultipleTimes() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ // primitive field scalar and repeated
+ builder.setOptionalSfixed64(100);
+ builder.addRepeatedInt32(100);
+ // enum field scalar and repeated
+ builder.setOptionalImportEnum(UnittestImport.ImportEnum.IMPORT_BAR);
+ builder.addRepeatedImportEnum(UnittestImport.ImportEnum.IMPORT_BAR);
+ // proto field scalar and repeated
+ builder.setOptionalForeignMessage(ForeignMessage.newBuilder().setC(1));
+ builder.addRepeatedForeignMessage(ForeignMessage.newBuilder().setC(1));
+
+ TestAllTypes value1 = builder.build();
+
+ assertEquals(100, value1.getOptionalSfixed64());
+ assertEquals(100, value1.getRepeatedInt32(0));
+ assertEquals(UnittestImport.ImportEnum.IMPORT_BAR,
+ value1.getOptionalImportEnum());
+ assertEquals(UnittestImport.ImportEnum.IMPORT_BAR,
+ value1.getRepeatedImportEnum(0));
+ assertEquals(1, value1.getOptionalForeignMessage().getC());
+ assertEquals(1, value1.getRepeatedForeignMessage(0).getC());
+
+ // Make sure that builder didn't update previously created values
+ builder.setOptionalSfixed64(200);
+ builder.setRepeatedInt32(0, 200);
+ builder.setOptionalImportEnum(UnittestImport.ImportEnum.IMPORT_FOO);
+ builder.setRepeatedImportEnum(0, UnittestImport.ImportEnum.IMPORT_FOO);
+ builder.setOptionalForeignMessage(ForeignMessage.newBuilder().setC(2));
+ builder.setRepeatedForeignMessage(0, ForeignMessage.newBuilder().setC(2));
+
+ TestAllTypes value2 = builder.build();
+
+ // Make sure value1 didn't change.
+ assertEquals(100, value1.getOptionalSfixed64());
+ assertEquals(100, value1.getRepeatedInt32(0));
+ assertEquals(UnittestImport.ImportEnum.IMPORT_BAR,
+ value1.getOptionalImportEnum());
+ assertEquals(UnittestImport.ImportEnum.IMPORT_BAR,
+ value1.getRepeatedImportEnum(0));
+ assertEquals(1, value1.getOptionalForeignMessage().getC());
+ assertEquals(1, value1.getRepeatedForeignMessage(0).getC());
+
+ // Make sure value2 is correct
+ assertEquals(200, value2.getOptionalSfixed64());
+ assertEquals(200, value2.getRepeatedInt32(0));
+ assertEquals(UnittestImport.ImportEnum.IMPORT_FOO,
+ value2.getOptionalImportEnum());
+ assertEquals(UnittestImport.ImportEnum.IMPORT_FOO,
+ value2.getRepeatedImportEnum(0));
+ assertEquals(2, value2.getOptionalForeignMessage().getC());
+ assertEquals(2, value2.getRepeatedForeignMessage(0).getC());
+ }
+
+ public void testRepeatedArraysAreImmutable() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ builder.addRepeatedInt32(100);
+ builder.addRepeatedImportEnum(UnittestImport.ImportEnum.IMPORT_BAR);
+ builder.addRepeatedForeignMessage(ForeignMessage.getDefaultInstance());
+ assertIsUnmodifiable(builder.getRepeatedInt32List());
+ assertIsUnmodifiable(builder.getRepeatedImportEnumList());
+ assertIsUnmodifiable(builder.getRepeatedForeignMessageList());
+ assertIsUnmodifiable(builder.getRepeatedFloatList());
+
+
+ TestAllTypes value = builder.build();
+ assertIsUnmodifiable(value.getRepeatedInt32List());
+ assertIsUnmodifiable(value.getRepeatedImportEnumList());
+ assertIsUnmodifiable(value.getRepeatedForeignMessageList());
+ assertIsUnmodifiable(value.getRepeatedFloatList());
+ }
+
+ public void testParsedMessagesAreImmutable() throws Exception {
+ TestAllTypes value = TestAllTypes.PARSER.parseFrom(
+ TestUtil.getAllSet().toByteString());
+ assertIsUnmodifiable(value.getRepeatedInt32List());
+ assertIsUnmodifiable(value.getRepeatedInt64List());
+ assertIsUnmodifiable(value.getRepeatedUint32List());
+ assertIsUnmodifiable(value.getRepeatedUint64List());
+ assertIsUnmodifiable(value.getRepeatedSint32List());
+ assertIsUnmodifiable(value.getRepeatedSint64List());
+ assertIsUnmodifiable(value.getRepeatedFixed32List());
+ assertIsUnmodifiable(value.getRepeatedFixed64List());
+ assertIsUnmodifiable(value.getRepeatedSfixed32List());
+ assertIsUnmodifiable(value.getRepeatedSfixed64List());
+ assertIsUnmodifiable(value.getRepeatedFloatList());
+ assertIsUnmodifiable(value.getRepeatedDoubleList());
+ assertIsUnmodifiable(value.getRepeatedBoolList());
+ assertIsUnmodifiable(value.getRepeatedStringList());
+ assertIsUnmodifiable(value.getRepeatedBytesList());
+ assertIsUnmodifiable(value.getRepeatedGroupList());
+ assertIsUnmodifiable(value.getRepeatedNestedMessageList());
+ assertIsUnmodifiable(value.getRepeatedForeignMessageList());
+ assertIsUnmodifiable(value.getRepeatedImportMessageList());
+ assertIsUnmodifiable(value.getRepeatedNestedEnumList());
+ assertIsUnmodifiable(value.getRepeatedForeignEnumList());
+ assertIsUnmodifiable(value.getRepeatedImportEnumList());
+ }
+
+ private void assertIsUnmodifiable(List<?> list) {
+ if (list == Collections.emptyList()) {
+ // OKAY -- Need to check this b/c EmptyList allows you to call clear.
+ } else {
+ try {
+ list.clear();
+ fail("List wasn't immutable");
+ } catch (UnsupportedOperationException e) {
+ // good
+ }
+ }
+ }
+
+ public void testSettersRejectNull() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ try {
+ builder.setOptionalString(null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setOptionalBytes(null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setOptionalNestedMessage((TestAllTypes.NestedMessage) null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setOptionalNestedMessage(
+ (TestAllTypes.NestedMessage.Builder) null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setOptionalNestedEnum(null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.addRepeatedString(null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.addRepeatedBytes(null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.addRepeatedNestedMessage((TestAllTypes.NestedMessage) null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.addRepeatedNestedMessage(
+ (TestAllTypes.NestedMessage.Builder) null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.addRepeatedNestedEnum(null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ }
+
+ public void testRepeatedSetters() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ TestUtil.modifyRepeatedFields(builder);
+ TestAllTypes message = builder.build();
+ TestUtil.assertRepeatedFieldsModified(message);
+ }
+
+ public void testRepeatedSettersRejectNull() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+
+ builder.addRepeatedString("one");
+ builder.addRepeatedString("two");
+ try {
+ builder.setRepeatedString(1, null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ builder.addRepeatedBytes(TestUtil.toBytes("one"));
+ builder.addRepeatedBytes(TestUtil.toBytes("two"));
+ try {
+ builder.setRepeatedBytes(1, null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ builder.addRepeatedNestedMessage(
+ TestAllTypes.NestedMessage.newBuilder().setBb(218).build());
+ builder.addRepeatedNestedMessage(
+ TestAllTypes.NestedMessage.newBuilder().setBb(456).build());
+ try {
+ builder.setRepeatedNestedMessage(1, (TestAllTypes.NestedMessage) null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setRepeatedNestedMessage(
+ 1, (TestAllTypes.NestedMessage.Builder) null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ builder.addRepeatedNestedEnum(TestAllTypes.NestedEnum.FOO);
+ builder.addRepeatedNestedEnum(TestAllTypes.NestedEnum.BAR);
+ try {
+ builder.setRepeatedNestedEnum(1, null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ }
+
+ public void testRepeatedAppend() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+
+ builder.addAllRepeatedInt32(Arrays.asList(1, 2, 3, 4));
+ builder.addAllRepeatedForeignEnum(Arrays.asList(ForeignEnum.FOREIGN_BAZ));
+
+ ForeignMessage foreignMessage =
+ ForeignMessage.newBuilder().setC(12).build();
+ builder.addAllRepeatedForeignMessage(Arrays.asList(foreignMessage));
+
+ TestAllTypes message = builder.build();
+ assertEquals(message.getRepeatedInt32List(), Arrays.asList(1, 2, 3, 4));
+ assertEquals(message.getRepeatedForeignEnumList(),
+ Arrays.asList(ForeignEnum.FOREIGN_BAZ));
+ assertEquals(1, message.getRepeatedForeignMessageCount());
+ assertEquals(12, message.getRepeatedForeignMessage(0).getC());
+ }
+
+ public void testRepeatedAppendRejectsNull() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+
+ ForeignMessage foreignMessage =
+ ForeignMessage.newBuilder().setC(12).build();
+ try {
+ builder.addAllRepeatedForeignMessage(
+ Arrays.asList(foreignMessage, (ForeignMessage) null));
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ try {
+ builder.addAllRepeatedForeignEnum(
+ Arrays.asList(ForeignEnum.FOREIGN_BAZ, null));
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ try {
+ builder.addAllRepeatedString(Arrays.asList("one", null));
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ try {
+ builder.addAllRepeatedBytes(Arrays.asList(TestUtil.toBytes("one"), null));
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ }
+
+ public void testSettingForeignMessageUsingBuilder() throws Exception {
+ TestAllTypes message = TestAllTypes.newBuilder()
+ // Pass builder for foreign message instance.
+ .setOptionalForeignMessage(ForeignMessage.newBuilder().setC(123))
+ .build();
+ TestAllTypes expectedMessage = TestAllTypes.newBuilder()
+ // Create expected version passing foreign message instance explicitly.
+ .setOptionalForeignMessage(
+ ForeignMessage.newBuilder().setC(123).build())
+ .build();
+ // TODO(ngd): Upgrade to using real #equals method once implemented
+ assertEquals(expectedMessage.toString(), message.toString());
+ }
+
+ public void testSettingRepeatedForeignMessageUsingBuilder() throws Exception {
+ TestAllTypes message = TestAllTypes.newBuilder()
+ // Pass builder for foreign message instance.
+ .addRepeatedForeignMessage(ForeignMessage.newBuilder().setC(456))
+ .build();
+ TestAllTypes expectedMessage = TestAllTypes.newBuilder()
+ // Create expected version passing foreign message instance explicitly.
+ .addRepeatedForeignMessage(
+ ForeignMessage.newBuilder().setC(456).build())
+ .build();
+ assertEquals(expectedMessage.toString(), message.toString());
+ }
+
+ public void testDefaults() throws Exception {
+ TestUtil.assertClear(TestAllTypes.getDefaultInstance());
+ TestUtil.assertClear(TestAllTypes.newBuilder().build());
+
+ TestExtremeDefaultValues message =
+ TestExtremeDefaultValues.getDefaultInstance();
+ assertEquals("\u1234", message.getUtf8String());
+ assertEquals(Double.POSITIVE_INFINITY, message.getInfDouble());
+ assertEquals(Double.NEGATIVE_INFINITY, message.getNegInfDouble());
+ assertTrue(Double.isNaN(message.getNanDouble()));
+ assertEquals(Float.POSITIVE_INFINITY, message.getInfFloat());
+ assertEquals(Float.NEGATIVE_INFINITY, message.getNegInfFloat());
+ assertTrue(Float.isNaN(message.getNanFloat()));
+ assertEquals("? ? ?? ?? ??? ??/ ??-", message.getCppTrigraph());
+ }
+
+ public void testClear() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.assertClear(builder);
+ TestUtil.setAllFields(builder);
+ builder.clear();
+ TestUtil.assertClear(builder);
+ }
+
+ public void testReflectionGetters() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ reflectionTester.assertAllFieldsSetViaReflection(builder);
+
+ TestAllTypes message = builder.build();
+ reflectionTester.assertAllFieldsSetViaReflection(message);
+ }
+
+ public void testReflectionSetters() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ reflectionTester.setAllFieldsViaReflection(builder);
+ TestUtil.assertAllFieldsSet(builder);
+
+ TestAllTypes message = builder.build();
+ TestUtil.assertAllFieldsSet(message);
+ }
+
+ public void testReflectionSettersRejectNull() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ reflectionTester.assertReflectionSettersRejectNull(builder);
+ }
+
+ public void testReflectionRepeatedSetters() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ reflectionTester.setAllFieldsViaReflection(builder);
+ reflectionTester.modifyRepeatedFieldsViaReflection(builder);
+ TestUtil.assertRepeatedFieldsModified(builder);
+
+ TestAllTypes message = builder.build();
+ TestUtil.assertRepeatedFieldsModified(message);
+ }
+
+ public void testReflectionRepeatedSettersRejectNull() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ reflectionTester.assertReflectionRepeatedSettersRejectNull(builder);
+ }
+
+ public void testReflectionDefaults() throws Exception {
+ reflectionTester.assertClearViaReflection(
+ TestAllTypes.getDefaultInstance());
+ reflectionTester.assertClearViaReflection(
+ TestAllTypes.newBuilder().build());
+ }
+
+ public void testEnumInterface() throws Exception {
+ assertTrue(TestAllTypes.getDefaultInstance().getDefaultNestedEnum()
+ instanceof ProtocolMessageEnum);
+ }
+
+ public void testEnumMap() throws Exception {
+ Internal.EnumLiteMap<ForeignEnum> map = ForeignEnum.internalGetValueMap();
+
+ for (ForeignEnum value : ForeignEnum.values()) {
+ assertEquals(value, map.findValueByNumber(value.getNumber()));
+ }
+
+ assertTrue(map.findValueByNumber(12345) == null);
+ }
+
+ public void testParsePackedToUnpacked() throws Exception {
+ TestUnpackedTypes.Builder builder = TestUnpackedTypes.newBuilder();
+ TestUnpackedTypes message =
+ builder.mergeFrom(TestUtil.getPackedSet().toByteString()).build();
+ TestUtil.assertUnpackedFieldsSet(message);
+ }
+
+ public void testParseUnpackedToPacked() throws Exception {
+ TestPackedTypes.Builder builder = TestPackedTypes.newBuilder();
+ TestPackedTypes message =
+ builder.mergeFrom(TestUtil.getUnpackedSet().toByteString()).build();
+ TestUtil.assertPackedFieldsSet(message);
+ }
+
+ // =================================================================
+ // Extensions.
+
+ TestUtil.ReflectionTester extensionsReflectionTester =
+ new TestUtil.ReflectionTester(TestAllExtensions.getDescriptor(),
+ TestUtil.getExtensionRegistry());
+
+ public void testExtensionMessageOrBuilder() throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ TestUtil.setAllExtensions(builder);
+ TestAllExtensions message = builder.build();
+ TestUtil.assertAllExtensionsSet(message);
+ }
+
+ public void testExtensionRepeatedSetters() throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ TestUtil.setAllExtensions(builder);
+ TestUtil.modifyRepeatedExtensions(builder);
+ TestAllExtensions message = builder.build();
+ TestUtil.assertRepeatedExtensionsModified(message);
+ }
+
+ public void testExtensionDefaults() throws Exception {
+ TestUtil.assertExtensionsClear(TestAllExtensions.getDefaultInstance());
+ TestUtil.assertExtensionsClear(TestAllExtensions.newBuilder().build());
+ }
+
+ public void testExtensionReflectionGetters() throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ TestUtil.setAllExtensions(builder);
+ extensionsReflectionTester.assertAllFieldsSetViaReflection(builder);
+
+ TestAllExtensions message = builder.build();
+ extensionsReflectionTester.assertAllFieldsSetViaReflection(message);
+ }
+
+ public void testExtensionReflectionSetters() throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ extensionsReflectionTester.setAllFieldsViaReflection(builder);
+ TestUtil.assertAllExtensionsSet(builder);
+
+ TestAllExtensions message = builder.build();
+ TestUtil.assertAllExtensionsSet(message);
+ }
+
+ public void testExtensionReflectionSettersRejectNull() throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ extensionsReflectionTester.assertReflectionSettersRejectNull(builder);
+ }
+
+ public void testExtensionReflectionRepeatedSetters() throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ extensionsReflectionTester.setAllFieldsViaReflection(builder);
+ extensionsReflectionTester.modifyRepeatedFieldsViaReflection(builder);
+ TestUtil.assertRepeatedExtensionsModified(builder);
+
+ TestAllExtensions message = builder.build();
+ TestUtil.assertRepeatedExtensionsModified(message);
+ }
+
+ public void testExtensionReflectionRepeatedSettersRejectNull()
+ throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ extensionsReflectionTester.assertReflectionRepeatedSettersRejectNull(
+ builder);
+ }
+
+ public void testExtensionReflectionDefaults() throws Exception {
+ extensionsReflectionTester.assertClearViaReflection(
+ TestAllExtensions.getDefaultInstance());
+ extensionsReflectionTester.assertClearViaReflection(
+ TestAllExtensions.newBuilder().build());
+ }
+
+ public void testClearExtension() throws Exception {
+ // clearExtension() is not actually used in TestUtil, so try it manually.
+ assertFalse(
+ TestAllExtensions.newBuilder()
+ .setExtension(UnittestProto.optionalInt32Extension, 1)
+ .clearExtension(UnittestProto.optionalInt32Extension)
+ .hasExtension(UnittestProto.optionalInt32Extension));
+ assertEquals(0,
+ TestAllExtensions.newBuilder()
+ .addExtension(UnittestProto.repeatedInt32Extension, 1)
+ .clearExtension(UnittestProto.repeatedInt32Extension)
+ .getExtensionCount(UnittestProto.repeatedInt32Extension));
+ }
+
+ public void testExtensionCopy() throws Exception {
+ TestAllExtensions original = TestUtil.getAllExtensionsSet();
+ TestAllExtensions copy = TestAllExtensions.newBuilder(original).build();
+ TestUtil.assertAllExtensionsSet(copy);
+ }
+
+ public void testExtensionMergeFrom() throws Exception {
+ TestAllExtensions original =
+ TestAllExtensions.newBuilder()
+ .setExtension(UnittestProto.optionalInt32Extension, 1).build();
+ TestAllExtensions merged =
+ TestAllExtensions.newBuilder().mergeFrom(original).build();
+ assertTrue(merged.hasExtension(UnittestProto.optionalInt32Extension));
+ assertEquals(
+ 1, (int) merged.getExtension(UnittestProto.optionalInt32Extension));
+ }
+
+ // =================================================================
+ // multiple_files_test
+
+ public void testMultipleFilesOption() throws Exception {
+ // We mostly just want to check that things compile.
+ MessageWithNoOuter message =
+ MessageWithNoOuter.newBuilder()
+ .setNested(MessageWithNoOuter.NestedMessage.newBuilder().setI(1))
+ .addForeign(TestAllTypes.newBuilder().setOptionalInt32(1))
+ .setNestedEnum(MessageWithNoOuter.NestedEnum.BAZ)
+ .setForeignEnum(EnumWithNoOuter.BAR)
+ .build();
+ assertEquals(message, MessageWithNoOuter.parseFrom(message.toByteString()));
+
+ assertEquals(MultipleFilesTestProto.getDescriptor(),
+ MessageWithNoOuter.getDescriptor().getFile());
+
+ Descriptors.FieldDescriptor field =
+ MessageWithNoOuter.getDescriptor().findFieldByName("foreign_enum");
+ assertEquals(EnumWithNoOuter.BAR.getValueDescriptor(),
+ message.getField(field));
+
+ assertEquals(MultipleFilesTestProto.getDescriptor(),
+ ServiceWithNoOuter.getDescriptor().getFile());
+
+ assertFalse(
+ TestAllExtensions.getDefaultInstance().hasExtension(
+ MultipleFilesTestProto.extensionWithOuter));
+ }
+
+ public void testOptionalFieldWithRequiredSubfieldsOptimizedForSize()
+ throws Exception {
+ TestOptionalOptimizedForSize message =
+ TestOptionalOptimizedForSize.getDefaultInstance();
+ assertTrue(message.isInitialized());
+
+ message = TestOptionalOptimizedForSize.newBuilder().setO(
+ TestRequiredOptimizedForSize.newBuilder().buildPartial()
+ ).buildPartial();
+ assertFalse(message.isInitialized());
+
+ message = TestOptionalOptimizedForSize.newBuilder().setO(
+ TestRequiredOptimizedForSize.newBuilder().setX(5).buildPartial()
+ ).buildPartial();
+ assertTrue(message.isInitialized());
+ }
+
+ public void testUninitializedExtensionInOptimizedForSize()
+ throws Exception {
+ TestOptimizedForSize.Builder builder = TestOptimizedForSize.newBuilder();
+ builder.setExtension(TestOptimizedForSize.testExtension2,
+ TestRequiredOptimizedForSize.newBuilder().buildPartial());
+ assertFalse(builder.isInitialized());
+ assertFalse(builder.buildPartial().isInitialized());
+
+ builder = TestOptimizedForSize.newBuilder();
+ builder.setExtension(TestOptimizedForSize.testExtension2,
+ TestRequiredOptimizedForSize.newBuilder().setX(10).buildPartial());
+ assertTrue(builder.isInitialized());
+ assertTrue(builder.buildPartial().isInitialized());
+ }
+
+ public void testToBuilder() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ TestAllTypes message = builder.build();
+ TestUtil.assertAllFieldsSet(message);
+ TestUtil.assertAllFieldsSet(message.toBuilder().build());
+ }
+
+ public void testFieldConstantValues() throws Exception {
+ assertEquals(TestAllTypes.NestedMessage.BB_FIELD_NUMBER, 1);
+ assertEquals(TestAllTypes.OPTIONAL_INT32_FIELD_NUMBER, 1);
+ assertEquals(TestAllTypes.OPTIONALGROUP_FIELD_NUMBER, 16);
+ assertEquals(TestAllTypes.OPTIONAL_NESTED_MESSAGE_FIELD_NUMBER, 18);
+ assertEquals(TestAllTypes.OPTIONAL_NESTED_ENUM_FIELD_NUMBER, 21);
+ assertEquals(TestAllTypes.REPEATED_INT32_FIELD_NUMBER, 31);
+ assertEquals(TestAllTypes.REPEATEDGROUP_FIELD_NUMBER, 46);
+ assertEquals(TestAllTypes.REPEATED_NESTED_MESSAGE_FIELD_NUMBER, 48);
+ assertEquals(TestAllTypes.REPEATED_NESTED_ENUM_FIELD_NUMBER, 51);
+ }
+
+ public void testExtensionConstantValues() throws Exception {
+ assertEquals(UnittestProto.TestRequired.SINGLE_FIELD_NUMBER, 1000);
+ assertEquals(UnittestProto.TestRequired.MULTI_FIELD_NUMBER, 1001);
+ assertEquals(UnittestProto.OPTIONAL_INT32_EXTENSION_FIELD_NUMBER, 1);
+ assertEquals(UnittestProto.OPTIONALGROUP_EXTENSION_FIELD_NUMBER, 16);
+ assertEquals(
+ UnittestProto.OPTIONAL_NESTED_MESSAGE_EXTENSION_FIELD_NUMBER, 18);
+ assertEquals(UnittestProto.OPTIONAL_NESTED_ENUM_EXTENSION_FIELD_NUMBER, 21);
+ assertEquals(UnittestProto.REPEATED_INT32_EXTENSION_FIELD_NUMBER, 31);
+ assertEquals(UnittestProto.REPEATEDGROUP_EXTENSION_FIELD_NUMBER, 46);
+ assertEquals(
+ UnittestProto.REPEATED_NESTED_MESSAGE_EXTENSION_FIELD_NUMBER, 48);
+ assertEquals(UnittestProto.REPEATED_NESTED_ENUM_EXTENSION_FIELD_NUMBER, 51);
+ }
+
+ public void testRecursiveMessageDefaultInstance() throws Exception {
+ UnittestProto.TestRecursiveMessage message =
+ UnittestProto.TestRecursiveMessage.getDefaultInstance();
+ assertTrue(message != null);
+ assertTrue(message.getA() != null);
+ assertTrue(message.getA() == message);
+ }
+
+ public void testSerialize() throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ TestAllTypes expected = builder.build();
+ ObjectOutputStream out = new ObjectOutputStream(baos);
+ try {
+ out.writeObject(expected);
+ } finally {
+ out.close();
+ }
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream in = new ObjectInputStream(bais);
+ TestAllTypes actual = (TestAllTypes) in.readObject();
+ assertEquals(expected, actual);
+ }
+
+ public void testSerializePartial() throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestAllTypes expected = builder.buildPartial();
+ ObjectOutputStream out = new ObjectOutputStream(baos);
+ try {
+ out.writeObject(expected);
+ } finally {
+ out.close();
+ }
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream in = new ObjectInputStream(bais);
+ TestAllTypes actual = (TestAllTypes) in.readObject();
+ assertEquals(expected, actual);
+ }
+
+ public void testEnumValues() {
+ assertEquals(
+ TestAllTypes.NestedEnum.BAR.getNumber(),
+ TestAllTypes.NestedEnum.BAR_VALUE);
+ assertEquals(
+ TestAllTypes.NestedEnum.BAZ.getNumber(),
+ TestAllTypes.NestedEnum.BAZ_VALUE);
+ assertEquals(
+ TestAllTypes.NestedEnum.FOO.getNumber(),
+ TestAllTypes.NestedEnum.FOO_VALUE);
+ }
+
+ public void testNonNestedExtensionInitialization() {
+ assertTrue(NonNestedExtension.nonNestedExtension
+ .getMessageDefaultInstance() instanceof MyNonNestedExtension);
+ assertEquals("nonNestedExtension",
+ NonNestedExtension.nonNestedExtension.getDescriptor().getName());
+ }
+
+ public void testNestedExtensionInitialization() {
+ assertTrue(MyNestedExtension.recursiveExtension.getMessageDefaultInstance()
+ instanceof MessageToBeExtended);
+ assertEquals("recursiveExtension",
+ MyNestedExtension.recursiveExtension.getDescriptor().getName());
+ }
+
+
+ public void testBaseMessageOrBuilder() {
+ // Mostly just makes sure the base interface exists and has some methods.
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestAllTypes message = builder.buildPartial();
+ TestAllTypesOrBuilder builderAsInterface = (TestAllTypesOrBuilder) builder;
+ TestAllTypesOrBuilder messageAsInterface = (TestAllTypesOrBuilder) message;
+
+ assertEquals(
+ messageAsInterface.getDefaultBool(),
+ messageAsInterface.getDefaultBool());
+ assertEquals(
+ messageAsInterface.getOptionalDouble(),
+ messageAsInterface.getOptionalDouble());
+ }
+
+ public void testMessageOrBuilderGetters() {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+
+ // single fields
+ assertSame(ForeignMessage.getDefaultInstance(),
+ builder.getOptionalForeignMessageOrBuilder());
+ ForeignMessage.Builder subBuilder =
+ builder.getOptionalForeignMessageBuilder();
+ assertSame(subBuilder, builder.getOptionalForeignMessageOrBuilder());
+
+ // repeated fields
+ ForeignMessage m0 = ForeignMessage.newBuilder().buildPartial();
+ ForeignMessage m1 = ForeignMessage.newBuilder().buildPartial();
+ ForeignMessage m2 = ForeignMessage.newBuilder().buildPartial();
+ builder.addRepeatedForeignMessage(m0);
+ builder.addRepeatedForeignMessage(m1);
+ builder.addRepeatedForeignMessage(m2);
+ assertSame(m0, builder.getRepeatedForeignMessageOrBuilder(0));
+ assertSame(m1, builder.getRepeatedForeignMessageOrBuilder(1));
+ assertSame(m2, builder.getRepeatedForeignMessageOrBuilder(2));
+ ForeignMessage.Builder b0 = builder.getRepeatedForeignMessageBuilder(0);
+ ForeignMessage.Builder b1 = builder.getRepeatedForeignMessageBuilder(1);
+ assertSame(b0, builder.getRepeatedForeignMessageOrBuilder(0));
+ assertSame(b1, builder.getRepeatedForeignMessageOrBuilder(1));
+ assertSame(m2, builder.getRepeatedForeignMessageOrBuilder(2));
+
+ List<? extends ForeignMessageOrBuilder> messageOrBuilderList =
+ builder.getRepeatedForeignMessageOrBuilderList();
+ assertSame(b0, messageOrBuilderList.get(0));
+ assertSame(b1, messageOrBuilderList.get(1));
+ assertSame(m2, messageOrBuilderList.get(2));
+ }
+
+ public void testGetFieldBuilder() {
+ Descriptor descriptor = TestAllTypes.getDescriptor();
+
+ FieldDescriptor fieldDescriptor =
+ descriptor.findFieldByName("optional_nested_message");
+ FieldDescriptor foreignFieldDescriptor =
+ descriptor.findFieldByName("optional_foreign_message");
+ FieldDescriptor importFieldDescriptor =
+ descriptor.findFieldByName("optional_import_message");
+
+ // Mutate the message with new field builder
+ // Mutate nested message
+ TestAllTypes.Builder builder1 = TestAllTypes.newBuilder();
+ Message.Builder fieldBuilder1 = builder1.newBuilderForField(fieldDescriptor)
+ .mergeFrom((Message) builder1.getField(fieldDescriptor));
+ FieldDescriptor subFieldDescriptor1 =
+ fieldBuilder1.getDescriptorForType().findFieldByName("bb");
+ fieldBuilder1.setField(subFieldDescriptor1, 1);
+ builder1.setField(fieldDescriptor, fieldBuilder1.build());
+
+ // Mutate foreign message
+ Message.Builder foreignFieldBuilder1 = builder1.newBuilderForField(
+ foreignFieldDescriptor)
+ .mergeFrom((Message) builder1.getField(foreignFieldDescriptor));
+ FieldDescriptor subForeignFieldDescriptor1 =
+ foreignFieldBuilder1.getDescriptorForType().findFieldByName("c");
+ foreignFieldBuilder1.setField(subForeignFieldDescriptor1, 2);
+ builder1.setField(foreignFieldDescriptor, foreignFieldBuilder1.build());
+
+ // Mutate import message
+ Message.Builder importFieldBuilder1 = builder1.newBuilderForField(
+ importFieldDescriptor)
+ .mergeFrom((Message) builder1.getField(importFieldDescriptor));
+ FieldDescriptor subImportFieldDescriptor1 =
+ importFieldBuilder1.getDescriptorForType().findFieldByName("d");
+ importFieldBuilder1.setField(subImportFieldDescriptor1, 3);
+ builder1.setField(importFieldDescriptor, importFieldBuilder1.build());
+
+ Message newMessage1 = builder1.build();
+
+ // Mutate the message with existing field builder
+ // Mutate nested message
+ TestAllTypes.Builder builder2 = TestAllTypes.newBuilder();
+ Message.Builder fieldBuilder2 = builder2.getFieldBuilder(fieldDescriptor);
+ FieldDescriptor subFieldDescriptor2 =
+ fieldBuilder2.getDescriptorForType().findFieldByName("bb");
+ fieldBuilder2.setField(subFieldDescriptor2, 1);
+ builder2.setField(fieldDescriptor, fieldBuilder2.build());
+
+ // Mutate foreign message
+ Message.Builder foreignFieldBuilder2 = builder2.newBuilderForField(
+ foreignFieldDescriptor)
+ .mergeFrom((Message) builder2.getField(foreignFieldDescriptor));
+ FieldDescriptor subForeignFieldDescriptor2 =
+ foreignFieldBuilder2.getDescriptorForType().findFieldByName("c");
+ foreignFieldBuilder2.setField(subForeignFieldDescriptor2, 2);
+ builder2.setField(foreignFieldDescriptor, foreignFieldBuilder2.build());
+
+ // Mutate import message
+ Message.Builder importFieldBuilder2 = builder2.newBuilderForField(
+ importFieldDescriptor)
+ .mergeFrom((Message) builder2.getField(importFieldDescriptor));
+ FieldDescriptor subImportFieldDescriptor2 =
+ importFieldBuilder2.getDescriptorForType().findFieldByName("d");
+ importFieldBuilder2.setField(subImportFieldDescriptor2, 3);
+ builder2.setField(importFieldDescriptor, importFieldBuilder2.build());
+
+ Message newMessage2 = builder2.build();
+
+ // These two messages should be equal.
+ assertEquals(newMessage1, newMessage2);
+ }
+
+ public void testGetFieldBuilderWithInitializedValue() {
+ Descriptor descriptor = TestAllTypes.getDescriptor();
+ FieldDescriptor fieldDescriptor =
+ descriptor.findFieldByName("optional_nested_message");
+
+ // Before setting field, builder is initialized by default value.
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ NestedMessage.Builder fieldBuilder =
+ (NestedMessage.Builder) builder.getFieldBuilder(fieldDescriptor);
+ assertEquals(0, fieldBuilder.getBb());
+
+ // Setting field value with new field builder instance.
+ builder = TestAllTypes.newBuilder();
+ NestedMessage.Builder newFieldBuilder =
+ builder.getOptionalNestedMessageBuilder();
+ newFieldBuilder.setBb(2);
+ // Then get the field builder instance by getFieldBuilder().
+ fieldBuilder =
+ (NestedMessage.Builder) builder.getFieldBuilder(fieldDescriptor);
+ // It should contain new value.
+ assertEquals(2, fieldBuilder.getBb());
+ // These two builder should be equal.
+ assertSame(fieldBuilder, newFieldBuilder);
+ }
+
+ public void testGetFieldBuilderNotSupportedException() {
+ Descriptor descriptor = TestAllTypes.getDescriptor();
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ try {
+ builder.getFieldBuilder(descriptor.findFieldByName("optional_int32"));
+ fail("Exception was not thrown");
+ } catch (UnsupportedOperationException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.getFieldBuilder(
+ descriptor.findFieldByName("optional_nested_enum"));
+ fail("Exception was not thrown");
+ } catch (UnsupportedOperationException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.getFieldBuilder(descriptor.findFieldByName("repeated_int32"));
+ fail("Exception was not thrown");
+ } catch (UnsupportedOperationException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.getFieldBuilder(
+ descriptor.findFieldByName("repeated_nested_enum"));
+ fail("Exception was not thrown");
+ } catch (UnsupportedOperationException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.getFieldBuilder(
+ descriptor.findFieldByName("repeated_nested_message"));
+ fail("Exception was not thrown");
+ } catch (UnsupportedOperationException e) {
+ // We expect this exception.
+ }
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/LazyStringArrayListTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/LazyStringArrayListTest.java
new file mode 100644
index 0000000000..9bc94eef1d
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/LazyStringArrayListTest.java
@@ -0,0 +1,163 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import junit.framework.TestCase;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests for {@link LazyStringArrayList}.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class LazyStringArrayListTest extends TestCase {
+
+ private static String STRING_A = "A";
+ private static String STRING_B = "B";
+ private static String STRING_C = "C";
+
+ private static ByteString BYTE_STRING_A = ByteString.copyFromUtf8("A");
+ private static ByteString BYTE_STRING_B = ByteString.copyFromUtf8("B");
+ private static ByteString BYTE_STRING_C = ByteString.copyFromUtf8("C");
+
+ public void testJustStrings() {
+ LazyStringArrayList list = new LazyStringArrayList();
+ list.add(STRING_A);
+ list.add(STRING_B);
+ list.add(STRING_C);
+
+ assertEquals(3, list.size());
+ assertSame(STRING_A, list.get(0));
+ assertSame(STRING_B, list.get(1));
+ assertSame(STRING_C, list.get(2));
+
+ list.set(1, STRING_C);
+ assertSame(STRING_C, list.get(1));
+
+ list.remove(1);
+ assertSame(STRING_A, list.get(0));
+ assertSame(STRING_C, list.get(1));
+ }
+
+ public void testJustByteString() {
+ LazyStringArrayList list = new LazyStringArrayList();
+ list.add(BYTE_STRING_A);
+ list.add(BYTE_STRING_B);
+ list.add(BYTE_STRING_C);
+
+ assertEquals(3, list.size());
+ assertSame(BYTE_STRING_A, list.getByteString(0));
+ assertSame(BYTE_STRING_B, list.getByteString(1));
+ assertSame(BYTE_STRING_C, list.getByteString(2));
+
+ list.remove(1);
+ assertSame(BYTE_STRING_A, list.getByteString(0));
+ assertSame(BYTE_STRING_C, list.getByteString(1));
+ }
+
+ public void testConversionBackAndForth() {
+ LazyStringArrayList list = new LazyStringArrayList();
+ list.add(STRING_A);
+ list.add(BYTE_STRING_B);
+ list.add(BYTE_STRING_C);
+
+ // String a should be the same because it was originally a string
+ assertSame(STRING_A, list.get(0));
+
+ // String b and c should be different because the string has to be computed
+ // from the ByteString
+ String bPrime = list.get(1);
+ assertNotSame(STRING_B, bPrime);
+ assertEquals(STRING_B, bPrime);
+ String cPrime = list.get(2);
+ assertNotSame(STRING_C, cPrime);
+ assertEquals(STRING_C, cPrime);
+
+ // String c and c should stay the same once cached.
+ assertSame(bPrime, list.get(1));
+ assertSame(cPrime, list.get(2));
+
+ // ByteString needs to be computed from string for both a and b
+ ByteString aPrimeByteString = list.getByteString(0);
+ assertEquals(BYTE_STRING_A, aPrimeByteString);
+ ByteString bPrimeByteString = list.getByteString(1);
+ assertNotSame(BYTE_STRING_B, bPrimeByteString);
+ assertEquals(BYTE_STRING_B, list.getByteString(1));
+
+ // Once cached, ByteString should stay cached.
+ assertSame(aPrimeByteString, list.getByteString(0));
+ assertSame(bPrimeByteString, list.getByteString(1));
+ }
+
+ public void testCopyConstructorCopiesByReference() {
+ LazyStringArrayList list1 = new LazyStringArrayList();
+ list1.add(STRING_A);
+ list1.add(BYTE_STRING_B);
+ list1.add(BYTE_STRING_C);
+
+ LazyStringArrayList list2 = new LazyStringArrayList(list1);
+ assertEquals(3, list2.size());
+ assertSame(STRING_A, list2.get(0));
+ assertSame(BYTE_STRING_B, list2.getByteString(1));
+ assertSame(BYTE_STRING_C, list2.getByteString(2));
+ }
+
+ public void testListCopyConstructor() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add(STRING_A);
+ list1.add(STRING_B);
+ list1.add(STRING_C);
+
+ LazyStringArrayList list2 = new LazyStringArrayList(list1);
+ assertEquals(3, list2.size());
+ assertSame(STRING_A, list2.get(0));
+ assertSame(STRING_B, list2.get(1));
+ assertSame(STRING_C, list2.get(2));
+ }
+
+ public void testAddAllCopiesByReferenceIfPossible() {
+ LazyStringArrayList list1 = new LazyStringArrayList();
+ list1.add(STRING_A);
+ list1.add(BYTE_STRING_B);
+ list1.add(BYTE_STRING_C);
+
+ LazyStringArrayList list2 = new LazyStringArrayList();
+ list2.addAll(list1);
+
+ assertEquals(3, list2.size());
+ assertSame(STRING_A, list2.get(0));
+ assertSame(BYTE_STRING_B, list2.getByteString(1));
+ assertSame(BYTE_STRING_C, list2.getByteString(2));
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/LazyStringEndToEndTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/LazyStringEndToEndTest.java
new file mode 100644
index 0000000000..e21e038993
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/LazyStringEndToEndTest.java
@@ -0,0 +1,108 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+
+import protobuf_unittest.UnittestProto;
+
+import junit.framework.TestCase;
+
+import java.io.IOException;
+
+/**
+ * Tests to make sure the lazy conversion of UTF8-encoded byte arrays to
+ * strings works correctly.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class LazyStringEndToEndTest extends TestCase {
+
+ private static ByteString TEST_ALL_TYPES_SERIALIZED_WITH_ILLEGAL_UTF8 =
+ ByteString.copyFrom(new byte[] {
+ 114, 4, -1, 0, -1, 0, -30, 2, 4, -1,
+ 0, -1, 0, -30, 2, 4, -1, 0, -1, 0, });
+
+ private ByteString encodedTestAllTypes;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.encodedTestAllTypes = UnittestProto.TestAllTypes.newBuilder()
+ .setOptionalString("foo")
+ .addRepeatedString("bar")
+ .addRepeatedString("baz")
+ .build()
+ .toByteString();
+ }
+
+ /**
+ * Tests that an invalid UTF8 string will roundtrip through a parse
+ * and serialization.
+ */
+ public void testParseAndSerialize() throws InvalidProtocolBufferException {
+ UnittestProto.TestAllTypes tV2 = UnittestProto.TestAllTypes.parseFrom(
+ TEST_ALL_TYPES_SERIALIZED_WITH_ILLEGAL_UTF8);
+ ByteString bytes = tV2.toByteString();
+ assertEquals(TEST_ALL_TYPES_SERIALIZED_WITH_ILLEGAL_UTF8, bytes);
+
+ tV2.getOptionalString();
+ bytes = tV2.toByteString();
+ assertEquals(TEST_ALL_TYPES_SERIALIZED_WITH_ILLEGAL_UTF8, bytes);
+ }
+
+ public void testParseAndWrite() throws IOException {
+ UnittestProto.TestAllTypes tV2 = UnittestProto.TestAllTypes.parseFrom(
+ TEST_ALL_TYPES_SERIALIZED_WITH_ILLEGAL_UTF8);
+ byte[] sink = new byte[TEST_ALL_TYPES_SERIALIZED_WITH_ILLEGAL_UTF8.size()];
+ CodedOutputStream outputStream = CodedOutputStream.newInstance(sink);
+ tV2.writeTo(outputStream);
+ outputStream.flush();
+ assertEquals(
+ TEST_ALL_TYPES_SERIALIZED_WITH_ILLEGAL_UTF8,
+ ByteString.copyFrom(sink));
+ }
+
+ public void testNoStringCachingIfOnlyBytesAccessed() throws Exception {
+ UnittestProto.TestAllTypes proto =
+ UnittestProto.TestAllTypes.parseFrom(encodedTestAllTypes);
+ ByteString optional = proto.getOptionalStringBytes();
+ assertSame(optional, proto.getOptionalStringBytes());
+ assertSame(optional, proto.toBuilder().getOptionalStringBytes());
+
+ ByteString repeated0 = proto.getRepeatedStringBytes(0);
+ ByteString repeated1 = proto.getRepeatedStringBytes(1);
+ assertSame(repeated0, proto.getRepeatedStringBytes(0));
+ assertSame(repeated1, proto.getRepeatedStringBytes(1));
+ assertSame(repeated0, proto.toBuilder().getRepeatedStringBytes(0));
+ assertSame(repeated1, proto.toBuilder().getRepeatedStringBytes(1));
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/LiteralByteStringTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/LiteralByteStringTest.java
new file mode 100644
index 0000000000..b2dcc7e882
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/LiteralByteStringTest.java
@@ -0,0 +1,344 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import junit.framework.TestCase;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+/**
+ * Test {@link LiteralByteString} by setting up a reference string in {@link #setUp()}.
+ * This class is designed to be extended for testing extensions of {@link LiteralByteString}
+ * such as {@link BoundedByteString}, see {@link BoundedByteStringTest}.
+ *
+ * @author carlanton@google.com (Carl Haverl)
+ */
+public class LiteralByteStringTest extends TestCase {
+ protected static final String UTF_8 = "UTF-8";
+
+ protected String classUnderTest;
+ protected byte[] referenceBytes;
+ protected ByteString stringUnderTest;
+ protected int expectedHashCode;
+
+ @Override
+ protected void setUp() throws Exception {
+ classUnderTest = "LiteralByteString";
+ referenceBytes = ByteStringTest.getTestBytes(1234, 11337766L);
+ stringUnderTest = ByteString.copyFrom(referenceBytes);
+ expectedHashCode = 331161852;
+ }
+
+ protected String getActualClassName(Object object) {
+ String actualClassName = object.getClass().getName();
+ actualClassName = actualClassName.substring(actualClassName.lastIndexOf('.') + 1);
+ return actualClassName;
+ }
+
+ public void testByteAt() {
+ boolean stillEqual = true;
+ for (int i = 0; stillEqual && i < referenceBytes.length; ++i) {
+ stillEqual = (referenceBytes[i] == stringUnderTest.byteAt(i));
+ }
+ assertTrue(classUnderTest + " must capture the right bytes", stillEqual);
+ }
+
+ public void testByteIterator() {
+ boolean stillEqual = true;
+ ByteString.ByteIterator iter = stringUnderTest.iterator();
+ for (int i = 0; stillEqual && i < referenceBytes.length; ++i) {
+ stillEqual = (iter.hasNext() && referenceBytes[i] == iter.nextByte());
+ }
+ assertTrue(classUnderTest + " must capture the right bytes", stillEqual);
+ assertFalse(classUnderTest + " must have exhausted the itertor", iter.hasNext());
+
+ try {
+ iter.nextByte();
+ fail("Should have thrown an exception.");
+ } catch (NoSuchElementException e) {
+ // This is success
+ }
+ }
+
+ public void testByteIterable() {
+ boolean stillEqual = true;
+ int j = 0;
+ for (byte quantum : stringUnderTest) {
+ stillEqual = (referenceBytes[j] == quantum);
+ ++j;
+ }
+ assertTrue(classUnderTest + " must capture the right bytes as Bytes", stillEqual);
+ assertEquals(classUnderTest + " iterable character count", referenceBytes.length, j);
+ }
+
+ public void testSize() {
+ assertEquals(classUnderTest + " must have the expected size", referenceBytes.length,
+ stringUnderTest.size());
+ }
+
+ public void testCopyTo_ByteArrayOffsetLength() {
+ int destinationOffset = 50;
+ int length = 100;
+ byte[] destination = new byte[destinationOffset + length];
+ int sourceOffset = 213;
+ stringUnderTest.copyTo(destination, sourceOffset, destinationOffset, length);
+ boolean stillEqual = true;
+ for (int i = 0; stillEqual && i < length; ++i) {
+ stillEqual = referenceBytes[i + sourceOffset] == destination[i + destinationOffset];
+ }
+ assertTrue(classUnderTest + ".copyTo(4 arg) must give the expected bytes", stillEqual);
+ }
+
+ public void testCopyTo_ByteArrayOffsetLengthErrors() {
+ int destinationOffset = 50;
+ int length = 100;
+ byte[] destination = new byte[destinationOffset + length];
+
+ try {
+ // Copy one too many bytes
+ stringUnderTest.copyTo(destination, stringUnderTest.size() + 1 - length,
+ destinationOffset, length);
+ fail("Should have thrown an exception when copying too many bytes of a "
+ + classUnderTest);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+
+ try {
+ // Copy with illegal negative sourceOffset
+ stringUnderTest.copyTo(destination, -1, destinationOffset, length);
+ fail("Should have thrown an exception when given a negative sourceOffset in "
+ + classUnderTest);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+
+ try {
+ // Copy with illegal negative destinationOffset
+ stringUnderTest.copyTo(destination, 0, -1, length);
+ fail("Should have thrown an exception when given a negative destinationOffset in "
+ + classUnderTest);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+
+ try {
+ // Copy with illegal negative size
+ stringUnderTest.copyTo(destination, 0, 0, -1);
+ fail("Should have thrown an exception when given a negative size in "
+ + classUnderTest);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+
+ try {
+ // Copy with illegal too-large sourceOffset
+ stringUnderTest.copyTo(destination, 2 * stringUnderTest.size(), 0, length);
+ fail("Should have thrown an exception when the destinationOffset is too large in "
+ + classUnderTest);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+
+ try {
+ // Copy with illegal too-large destinationOffset
+ stringUnderTest.copyTo(destination, 0, 2 * destination.length, length);
+ fail("Should have thrown an exception when the destinationOffset is too large in "
+ + classUnderTest);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+ }
+
+ public void testCopyTo_ByteBuffer() {
+ ByteBuffer myBuffer = ByteBuffer.allocate(referenceBytes.length);
+ stringUnderTest.copyTo(myBuffer);
+ assertTrue(classUnderTest + ".copyTo(ByteBuffer) must give back the same bytes",
+ Arrays.equals(referenceBytes, myBuffer.array()));
+ }
+
+ public void testAsReadOnlyByteBuffer() {
+ ByteBuffer byteBuffer = stringUnderTest.asReadOnlyByteBuffer();
+ byte[] roundTripBytes = new byte[referenceBytes.length];
+ assertTrue(byteBuffer.remaining() == referenceBytes.length);
+ assertTrue(byteBuffer.isReadOnly());
+ byteBuffer.get(roundTripBytes);
+ assertTrue(classUnderTest + ".asReadOnlyByteBuffer() must give back the same bytes",
+ Arrays.equals(referenceBytes, roundTripBytes));
+ }
+
+ public void testAsReadOnlyByteBufferList() {
+ List<ByteBuffer> byteBuffers = stringUnderTest.asReadOnlyByteBufferList();
+ int bytesSeen = 0;
+ byte[] roundTripBytes = new byte[referenceBytes.length];
+ for (ByteBuffer byteBuffer : byteBuffers) {
+ int thisLength = byteBuffer.remaining();
+ assertTrue(byteBuffer.isReadOnly());
+ assertTrue(bytesSeen + thisLength <= referenceBytes.length);
+ byteBuffer.get(roundTripBytes, bytesSeen, thisLength);
+ bytesSeen += thisLength;
+ }
+ assertTrue(bytesSeen == referenceBytes.length);
+ assertTrue(classUnderTest + ".asReadOnlyByteBufferTest() must give back the same bytes",
+ Arrays.equals(referenceBytes, roundTripBytes));
+ }
+
+ public void testToByteArray() {
+ byte[] roundTripBytes = stringUnderTest.toByteArray();
+ assertTrue(classUnderTest + ".toByteArray() must give back the same bytes",
+ Arrays.equals(referenceBytes, roundTripBytes));
+ }
+
+ public void testWriteTo() throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ stringUnderTest.writeTo(bos);
+ byte[] roundTripBytes = bos.toByteArray();
+ assertTrue(classUnderTest + ".writeTo() must give back the same bytes",
+ Arrays.equals(referenceBytes, roundTripBytes));
+ }
+
+ public void testWriteTo_mutating() throws IOException {
+ OutputStream os = new OutputStream() {
+ @Override
+ public void write(byte[] b, int off, int len) {
+ for (int x = 0; x < len; ++x) {
+ b[off + x] = (byte) 0;
+ }
+ }
+
+ @Override
+ public void write(int b) {
+ // Purposefully left blank.
+ }
+ };
+
+ stringUnderTest.writeTo(os);
+ byte[] newBytes = stringUnderTest.toByteArray();
+ assertTrue(classUnderTest + ".writeTo() must not grant access to underlying array",
+ Arrays.equals(referenceBytes, newBytes));
+ }
+
+ public void testNewOutput() throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ByteString.Output output = ByteString.newOutput();
+ stringUnderTest.writeTo(output);
+ assertEquals("Output Size returns correct result",
+ output.size(), stringUnderTest.size());
+ output.writeTo(bos);
+ assertTrue("Output.writeTo() must give back the same bytes",
+ Arrays.equals(referenceBytes, bos.toByteArray()));
+
+ // write the output stream to itself! This should cause it to double
+ output.writeTo(output);
+ assertEquals("Writing an output stream to itself is successful",
+ stringUnderTest.concat(stringUnderTest), output.toByteString());
+
+ output.reset();
+ assertEquals("Output.reset() resets the output", 0, output.size());
+ assertEquals("Output.reset() resets the output",
+ ByteString.EMPTY, output.toByteString());
+
+ }
+
+ public void testHashCode() {
+ int hash = stringUnderTest.hashCode();
+ assertEquals(classUnderTest + " must have expected hashCode", expectedHashCode, hash);
+ }
+
+ public void testNewInput() throws IOException {
+ InputStream input = stringUnderTest.newInput();
+ assertEquals("InputStream.available() returns correct value",
+ stringUnderTest.size(), input.available());
+ boolean stillEqual = true;
+ for (byte referenceByte : referenceBytes) {
+ int expectedInt = (referenceByte & 0xFF);
+ stillEqual = (expectedInt == input.read());
+ }
+ assertEquals("InputStream.available() returns correct value",
+ 0, input.available());
+ assertTrue(classUnderTest + " must give the same bytes from the InputStream", stillEqual);
+ assertEquals(classUnderTest + " InputStream must now be exhausted", -1, input.read());
+ }
+
+ public void testNewInput_skip() throws IOException {
+ InputStream input = stringUnderTest.newInput();
+ int stringSize = stringUnderTest.size();
+ int nearEndIndex = stringSize * 2 / 3;
+ long skipped1 = input.skip(nearEndIndex);
+ assertEquals("InputStream.skip()", skipped1, nearEndIndex);
+ assertEquals("InputStream.available()",
+ stringSize - skipped1, input.available());
+ assertTrue("InputStream.mark() is available", input.markSupported());
+ input.mark(0);
+ assertEquals("InputStream.skip(), read()",
+ stringUnderTest.byteAt(nearEndIndex) & 0xFF, input.read());
+ assertEquals("InputStream.available()",
+ stringSize - skipped1 - 1, input.available());
+ long skipped2 = input.skip(stringSize);
+ assertEquals("InputStream.skip() incomplete",
+ skipped2, stringSize - skipped1 - 1);
+ assertEquals("InputStream.skip(), no more input", 0, input.available());
+ assertEquals("InputStream.skip(), no more input", -1, input.read());
+ input.reset();
+ assertEquals("InputStream.reset() succeded",
+ stringSize - skipped1, input.available());
+ assertEquals("InputStream.reset(), read()",
+ stringUnderTest.byteAt(nearEndIndex) & 0xFF, input.read());
+ }
+
+ public void testNewCodedInput() throws IOException {
+ CodedInputStream cis = stringUnderTest.newCodedInput();
+ byte[] roundTripBytes = cis.readRawBytes(referenceBytes.length);
+ assertTrue(classUnderTest + " must give the same bytes back from the CodedInputStream",
+ Arrays.equals(referenceBytes, roundTripBytes));
+ assertTrue(classUnderTest + " CodedInputStream must now be exhausted", cis.isAtEnd());
+ }
+
+ /**
+ * Make sure we keep things simple when concatenating with empty. See also
+ * {@link ByteStringTest#testConcat_empty()}.
+ */
+ public void testConcat_empty() {
+ assertSame(classUnderTest + " concatenated with empty must give " + classUnderTest,
+ stringUnderTest.concat(ByteString.EMPTY), stringUnderTest);
+ assertSame("empty concatenated with " + classUnderTest + " must give " + classUnderTest,
+ ByteString.EMPTY.concat(stringUnderTest), stringUnderTest);
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/MessageTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/MessageTest.java
new file mode 100644
index 0000000000..c8c95a87c7
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/MessageTest.java
@@ -0,0 +1,354 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestRequired;
+import protobuf_unittest.UnittestProto.TestRequiredForeign;
+import protobuf_unittest.UnittestProto.ForeignMessage;
+
+import junit.framework.TestCase;
+
+import java.util.List;
+
+/**
+ * Misc. unit tests for message operations that apply to both generated
+ * and dynamic messages.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class MessageTest extends TestCase {
+ // =================================================================
+ // Message-merging tests.
+
+ static final TestAllTypes MERGE_SOURCE =
+ TestAllTypes.newBuilder()
+ .setOptionalInt32(1)
+ .setOptionalString("foo")
+ .setOptionalForeignMessage(ForeignMessage.getDefaultInstance())
+ .addRepeatedString("bar")
+ .build();
+
+ static final TestAllTypes MERGE_DEST =
+ TestAllTypes.newBuilder()
+ .setOptionalInt64(2)
+ .setOptionalString("baz")
+ .setOptionalForeignMessage(ForeignMessage.newBuilder().setC(3).build())
+ .addRepeatedString("qux")
+ .build();
+
+ static final String MERGE_RESULT_TEXT =
+ "optional_int32: 1\n" +
+ "optional_int64: 2\n" +
+ "optional_string: \"foo\"\n" +
+ "optional_foreign_message {\n" +
+ " c: 3\n" +
+ "}\n" +
+ "repeated_string: \"qux\"\n" +
+ "repeated_string: \"bar\"\n";
+
+ public void testMergeFrom() throws Exception {
+ TestAllTypes result =
+ TestAllTypes.newBuilder(MERGE_DEST)
+ .mergeFrom(MERGE_SOURCE).build();
+
+ assertEquals(MERGE_RESULT_TEXT, result.toString());
+ }
+
+ /**
+ * Test merging a DynamicMessage into a GeneratedMessage. As long as they
+ * have the same descriptor, this should work, but it is an entirely different
+ * code path.
+ */
+ public void testMergeFromDynamic() throws Exception {
+ TestAllTypes result =
+ TestAllTypes.newBuilder(MERGE_DEST)
+ .mergeFrom(DynamicMessage.newBuilder(MERGE_SOURCE).build())
+ .build();
+
+ assertEquals(MERGE_RESULT_TEXT, result.toString());
+ }
+
+ /** Test merging two DynamicMessages. */
+ public void testDynamicMergeFrom() throws Exception {
+ DynamicMessage result =
+ DynamicMessage.newBuilder(MERGE_DEST)
+ .mergeFrom(DynamicMessage.newBuilder(MERGE_SOURCE).build())
+ .build();
+
+ assertEquals(MERGE_RESULT_TEXT, result.toString());
+ }
+
+ // =================================================================
+ // Required-field-related tests.
+
+ private static final TestRequired TEST_REQUIRED_UNINITIALIZED =
+ TestRequired.getDefaultInstance();
+ private static final TestRequired TEST_REQUIRED_INITIALIZED =
+ TestRequired.newBuilder().setA(1).setB(2).setC(3).build();
+
+ public void testRequired() throws Exception {
+ TestRequired.Builder builder = TestRequired.newBuilder();
+
+ assertFalse(builder.isInitialized());
+ builder.setA(1);
+ assertFalse(builder.isInitialized());
+ builder.setB(1);
+ assertFalse(builder.isInitialized());
+ builder.setC(1);
+ assertTrue(builder.isInitialized());
+ }
+
+ public void testRequiredForeign() throws Exception {
+ TestRequiredForeign.Builder builder = TestRequiredForeign.newBuilder();
+
+ assertTrue(builder.isInitialized());
+
+ builder.setOptionalMessage(TEST_REQUIRED_UNINITIALIZED);
+ assertFalse(builder.isInitialized());
+
+ builder.setOptionalMessage(TEST_REQUIRED_INITIALIZED);
+ assertTrue(builder.isInitialized());
+
+ builder.addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED);
+ assertFalse(builder.isInitialized());
+
+ builder.setRepeatedMessage(0, TEST_REQUIRED_INITIALIZED);
+ assertTrue(builder.isInitialized());
+ }
+
+ public void testRequiredExtension() throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+
+ assertTrue(builder.isInitialized());
+
+ builder.setExtension(TestRequired.single, TEST_REQUIRED_UNINITIALIZED);
+ assertFalse(builder.isInitialized());
+
+ builder.setExtension(TestRequired.single, TEST_REQUIRED_INITIALIZED);
+ assertTrue(builder.isInitialized());
+
+ builder.addExtension(TestRequired.multi, TEST_REQUIRED_UNINITIALIZED);
+ assertFalse(builder.isInitialized());
+
+ builder.setExtension(TestRequired.multi, 0, TEST_REQUIRED_INITIALIZED);
+ assertTrue(builder.isInitialized());
+ }
+
+ public void testRequiredDynamic() throws Exception {
+ Descriptors.Descriptor descriptor = TestRequired.getDescriptor();
+ DynamicMessage.Builder builder = DynamicMessage.newBuilder(descriptor);
+
+ assertFalse(builder.isInitialized());
+ builder.setField(descriptor.findFieldByName("a"), 1);
+ assertFalse(builder.isInitialized());
+ builder.setField(descriptor.findFieldByName("b"), 1);
+ assertFalse(builder.isInitialized());
+ builder.setField(descriptor.findFieldByName("c"), 1);
+ assertTrue(builder.isInitialized());
+ }
+
+ public void testRequiredDynamicForeign() throws Exception {
+ Descriptors.Descriptor descriptor = TestRequiredForeign.getDescriptor();
+ DynamicMessage.Builder builder = DynamicMessage.newBuilder(descriptor);
+
+ assertTrue(builder.isInitialized());
+
+ builder.setField(descriptor.findFieldByName("optional_message"),
+ TEST_REQUIRED_UNINITIALIZED);
+ assertFalse(builder.isInitialized());
+
+ builder.setField(descriptor.findFieldByName("optional_message"),
+ TEST_REQUIRED_INITIALIZED);
+ assertTrue(builder.isInitialized());
+
+ builder.addRepeatedField(descriptor.findFieldByName("repeated_message"),
+ TEST_REQUIRED_UNINITIALIZED);
+ assertFalse(builder.isInitialized());
+
+ builder.setRepeatedField(descriptor.findFieldByName("repeated_message"), 0,
+ TEST_REQUIRED_INITIALIZED);
+ assertTrue(builder.isInitialized());
+ }
+
+ public void testUninitializedException() throws Exception {
+ try {
+ TestRequired.newBuilder().build();
+ fail("Should have thrown an exception.");
+ } catch (UninitializedMessageException e) {
+ assertEquals("Message missing required fields: a, b, c", e.getMessage());
+ }
+ }
+
+ public void testBuildPartial() throws Exception {
+ // We're mostly testing that no exception is thrown.
+ TestRequired message = TestRequired.newBuilder().buildPartial();
+ assertFalse(message.isInitialized());
+ }
+
+ public void testNestedUninitializedException() throws Exception {
+ try {
+ TestRequiredForeign.newBuilder()
+ .setOptionalMessage(TEST_REQUIRED_UNINITIALIZED)
+ .addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED)
+ .addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED)
+ .build();
+ fail("Should have thrown an exception.");
+ } catch (UninitializedMessageException e) {
+ assertEquals(
+ "Message missing required fields: " +
+ "optional_message.a, " +
+ "optional_message.b, " +
+ "optional_message.c, " +
+ "repeated_message[0].a, " +
+ "repeated_message[0].b, " +
+ "repeated_message[0].c, " +
+ "repeated_message[1].a, " +
+ "repeated_message[1].b, " +
+ "repeated_message[1].c",
+ e.getMessage());
+ }
+ }
+
+ public void testBuildNestedPartial() throws Exception {
+ // We're mostly testing that no exception is thrown.
+ TestRequiredForeign message =
+ TestRequiredForeign.newBuilder()
+ .setOptionalMessage(TEST_REQUIRED_UNINITIALIZED)
+ .addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED)
+ .addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED)
+ .buildPartial();
+ assertFalse(message.isInitialized());
+ }
+
+ public void testParseUnititialized() throws Exception {
+ try {
+ TestRequired.parseFrom(ByteString.EMPTY);
+ fail("Should have thrown an exception.");
+ } catch (InvalidProtocolBufferException e) {
+ assertEquals("Message missing required fields: a, b, c", e.getMessage());
+ }
+ }
+
+ public void testParseNestedUnititialized() throws Exception {
+ ByteString data =
+ TestRequiredForeign.newBuilder()
+ .setOptionalMessage(TEST_REQUIRED_UNINITIALIZED)
+ .addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED)
+ .addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED)
+ .buildPartial().toByteString();
+
+ try {
+ TestRequiredForeign.parseFrom(data);
+ fail("Should have thrown an exception.");
+ } catch (InvalidProtocolBufferException e) {
+ assertEquals(
+ "Message missing required fields: " +
+ "optional_message.a, " +
+ "optional_message.b, " +
+ "optional_message.c, " +
+ "repeated_message[0].a, " +
+ "repeated_message[0].b, " +
+ "repeated_message[0].c, " +
+ "repeated_message[1].a, " +
+ "repeated_message[1].b, " +
+ "repeated_message[1].c",
+ e.getMessage());
+ }
+ }
+
+ public void testDynamicUninitializedException() throws Exception {
+ try {
+ DynamicMessage.newBuilder(TestRequired.getDescriptor()).build();
+ fail("Should have thrown an exception.");
+ } catch (UninitializedMessageException e) {
+ assertEquals("Message missing required fields: a, b, c", e.getMessage());
+ }
+ }
+
+ public void testDynamicBuildPartial() throws Exception {
+ // We're mostly testing that no exception is thrown.
+ DynamicMessage message =
+ DynamicMessage.newBuilder(TestRequired.getDescriptor())
+ .buildPartial();
+ assertFalse(message.isInitialized());
+ }
+
+ public void testDynamicParseUnititialized() throws Exception {
+ try {
+ Descriptors.Descriptor descriptor = TestRequired.getDescriptor();
+ DynamicMessage.parseFrom(descriptor, ByteString.EMPTY);
+ fail("Should have thrown an exception.");
+ } catch (InvalidProtocolBufferException e) {
+ assertEquals("Message missing required fields: a, b, c", e.getMessage());
+ }
+ }
+
+ /** Test reading unset repeated message from DynamicMessage. */
+ public void testDynamicRepeatedMessageNull() throws Exception {
+ Descriptors.Descriptor descriptor = TestRequired.getDescriptor();
+ DynamicMessage result =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor())
+ .mergeFrom(DynamicMessage.newBuilder(MERGE_SOURCE).build())
+ .build();
+
+ assertTrue(result.getField(result.getDescriptorForType()
+ .findFieldByName("repeated_foreign_message")) instanceof List<?>);
+ assertEquals(result.getRepeatedFieldCount(result.getDescriptorForType()
+ .findFieldByName("repeated_foreign_message")), 0);
+ }
+
+ /** Test reading repeated message from DynamicMessage. */
+ public void testDynamicRepeatedMessageNotNull() throws Exception {
+
+ TestAllTypes REPEATED_NESTED =
+ TestAllTypes.newBuilder()
+ .setOptionalInt32(1)
+ .setOptionalString("foo")
+ .setOptionalForeignMessage(ForeignMessage.getDefaultInstance())
+ .addRepeatedString("bar")
+ .addRepeatedForeignMessage(ForeignMessage.getDefaultInstance())
+ .addRepeatedForeignMessage(ForeignMessage.getDefaultInstance())
+ .build();
+ Descriptors.Descriptor descriptor = TestRequired.getDescriptor();
+ DynamicMessage result =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor())
+ .mergeFrom(DynamicMessage.newBuilder(REPEATED_NESTED).build())
+ .build();
+
+ assertTrue(result.getField(result.getDescriptorForType()
+ .findFieldByName("repeated_foreign_message")) instanceof List<?>);
+ assertEquals(result.getRepeatedFieldCount(result.getDescriptorForType()
+ .findFieldByName("repeated_foreign_message")), 2);
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/NestedBuildersTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/NestedBuildersTest.java
new file mode 100644
index 0000000000..68d70beca1
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/NestedBuildersTest.java
@@ -0,0 +1,186 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import protobuf_unittest.Vehicle;
+import protobuf_unittest.Wheel;
+
+import junit.framework.TestCase;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * Test cases that exercise end-to-end use cases involving
+ * {@link SingleFieldBuilder} and {@link RepeatedFieldBuilder}.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class NestedBuildersTest extends TestCase {
+
+ public void testMessagesAndBuilders() {
+ Vehicle.Builder vehicleBuilder = Vehicle.newBuilder();
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(4)
+ .setWidth(1);
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(4)
+ .setWidth(2);
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(4)
+ .setWidth(3);
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(4)
+ .setWidth(4);
+ vehicleBuilder.getEngineBuilder()
+ .setLiters(10);
+
+ Vehicle vehicle = vehicleBuilder.build();
+ assertEquals(4, vehicle.getWheelCount());
+ for (int i = 0; i < 4; i++) {
+ Wheel wheel = vehicle.getWheel(i);
+ assertEquals(4, wheel.getRadius());
+ assertEquals(i + 1, wheel.getWidth());
+ }
+ assertEquals(10, vehicle.getEngine().getLiters());
+
+ for (int i = 0; i < 4; i++) {
+ vehicleBuilder.getWheelBuilder(i)
+ .setRadius(5)
+ .setWidth(i + 10);
+ }
+ vehicleBuilder.getEngineBuilder().setLiters(20);
+
+ vehicle = vehicleBuilder.build();
+ for (int i = 0; i < 4; i++) {
+ Wheel wheel = vehicle.getWheel(i);
+ assertEquals(5, wheel.getRadius());
+ assertEquals(i + 10, wheel.getWidth());
+ }
+ assertEquals(20, vehicle.getEngine().getLiters());
+ assertTrue(vehicle.hasEngine());
+ }
+
+ public void testMessagesAreCached() {
+ Vehicle.Builder vehicleBuilder = Vehicle.newBuilder();
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(1)
+ .setWidth(2);
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(3)
+ .setWidth(4);
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(5)
+ .setWidth(6);
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(7)
+ .setWidth(8);
+
+ // Make sure messages are cached.
+ List<Wheel> wheels = new ArrayList<Wheel>(vehicleBuilder.getWheelList());
+ for (int i = 0; i < wheels.size(); i++) {
+ assertSame(wheels.get(i), vehicleBuilder.getWheel(i));
+ }
+
+ // Now get builders and check they didn't change.
+ for (int i = 0; i < wheels.size(); i++) {
+ vehicleBuilder.getWheel(i);
+ }
+ for (int i = 0; i < wheels.size(); i++) {
+ assertSame(wheels.get(i), vehicleBuilder.getWheel(i));
+ }
+
+ // Change just one
+ vehicleBuilder.getWheelBuilder(3)
+ .setRadius(20).setWidth(20);
+
+ // Now get wheels and check that only that one changed
+ for (int i = 0; i < wheels.size(); i++) {
+ if (i < 3) {
+ assertSame(wheels.get(i), vehicleBuilder.getWheel(i));
+ } else {
+ assertNotSame(wheels.get(i), vehicleBuilder.getWheel(i));
+ }
+ }
+ }
+
+ public void testRemove_WithNestedBuilders() {
+ Vehicle.Builder vehicleBuilder = Vehicle.newBuilder();
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(1)
+ .setWidth(1);
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(2)
+ .setWidth(2);
+ vehicleBuilder.removeWheel(0);
+
+ assertEquals(1, vehicleBuilder.getWheelCount());
+ assertEquals(2, vehicleBuilder.getWheel(0).getRadius());
+ }
+
+ public void testRemove_WithNestedMessages() {
+ Vehicle.Builder vehicleBuilder = Vehicle.newBuilder();
+ vehicleBuilder.addWheel(Wheel.newBuilder()
+ .setRadius(1)
+ .setWidth(1));
+ vehicleBuilder.addWheel(Wheel.newBuilder()
+ .setRadius(2)
+ .setWidth(2));
+ vehicleBuilder.removeWheel(0);
+
+ assertEquals(1, vehicleBuilder.getWheelCount());
+ assertEquals(2, vehicleBuilder.getWheel(0).getRadius());
+ }
+
+ public void testMerge() {
+ Vehicle vehicle1 = Vehicle.newBuilder()
+ .addWheel(Wheel.newBuilder().setRadius(1).build())
+ .addWheel(Wheel.newBuilder().setRadius(2).build())
+ .build();
+
+ Vehicle vehicle2 = Vehicle.newBuilder()
+ .mergeFrom(vehicle1)
+ .build();
+ // List should be the same -- no allocation
+ assertSame(vehicle1.getWheelList(), vehicle2.getWheelList());
+
+ Vehicle vehicle3 = vehicle1.toBuilder().build();
+ assertSame(vehicle1.getWheelList(), vehicle3.getWheelList());
+ }
+
+ public void testGettingBuilderMarksFieldAsHaving() {
+ Vehicle.Builder vehicleBuilder = Vehicle.newBuilder();
+ vehicleBuilder.getEngineBuilder();
+ Vehicle vehicle = vehicleBuilder.buildPartial();
+ assertTrue(vehicle.hasEngine());
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ParserTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ParserTest.java
new file mode 100644
index 0000000000..b35af689cd
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ParserTest.java
@@ -0,0 +1,278 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import protobuf_unittest.UnittestOptimizeFor.TestOptimizedForSize;
+import protobuf_unittest.UnittestOptimizeFor.TestRequiredOptimizedForSize;
+import protobuf_unittest.UnittestOptimizeFor;
+import protobuf_unittest.UnittestProto.ForeignMessage;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestEmptyMessage;
+import protobuf_unittest.UnittestProto.TestRequired;
+import protobuf_unittest.UnittestProto.TestParsingMerge;
+import protobuf_unittest.UnittestProto;
+
+import junit.framework.TestCase;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Unit test for {@link Parser}.
+ *
+ * @author liujisi@google.com (Pherl Liu)
+ */
+public class ParserTest extends TestCase {
+ public void testGeneratedMessageParserSingleton() throws Exception {
+ for (int i = 0; i < 10; i++) {
+ assertEquals(TestAllTypes.PARSER,
+ TestUtil.getAllSet().getParserForType());
+ }
+ }
+
+ private void assertRoundTripEquals(MessageLite message,
+ ExtensionRegistryLite registry)
+ throws Exception {
+ final byte[] data = message.toByteArray();
+ final int offset = 20;
+ final int length = data.length;
+ final int padding = 30;
+ Parser<? extends MessageLite> parser = message.getParserForType();
+ assertMessageEquals(message, parser.parseFrom(data, registry));
+ assertMessageEquals(message, parser.parseFrom(
+ generatePaddingArray(data, offset, padding),
+ offset, length, registry));
+ assertMessageEquals(message, parser.parseFrom(
+ message.toByteString(), registry));
+ assertMessageEquals(message, parser.parseFrom(
+ new ByteArrayInputStream(data), registry));
+ assertMessageEquals(message, parser.parseFrom(
+ CodedInputStream.newInstance(data), registry));
+ }
+
+ private void assertRoundTripEquals(MessageLite message) throws Exception {
+ final byte[] data = message.toByteArray();
+ final int offset = 20;
+ final int length = data.length;
+ final int padding = 30;
+ Parser<? extends MessageLite> parser = message.getParserForType();
+ assertMessageEquals(message, parser.parseFrom(data));
+ assertMessageEquals(message, parser.parseFrom(
+ generatePaddingArray(data, offset, padding),
+ offset, length));
+ assertMessageEquals(message, parser.parseFrom(message.toByteString()));
+ assertMessageEquals(message, parser.parseFrom(
+ new ByteArrayInputStream(data)));
+ assertMessageEquals(message, parser.parseFrom(
+ CodedInputStream.newInstance(data)));
+ }
+
+ private void assertMessageEquals(MessageLite expected, MessageLite actual)
+ throws Exception {
+ if (expected instanceof Message) {
+ assertEquals(expected, actual);
+ } else {
+ assertEquals(expected.toByteString(), actual.toByteString());
+ }
+ }
+
+ private byte[] generatePaddingArray(byte[] data, int offset, int padding) {
+ byte[] result = new byte[offset + data.length + padding];
+ System.arraycopy(data, 0, result, offset, data.length);
+ return result;
+ }
+
+ public void testNormalMessage() throws Exception {
+ assertRoundTripEquals(TestUtil.getAllSet());
+ }
+
+ public void testParsePartial() throws Exception {
+ Parser<TestRequired> parser = TestRequired.PARSER;
+ final String errorString =
+ "Should throw exceptions when the parsed message isn't initialized.";
+
+ // TestRequired.b and TestRequired.c are not set.
+ TestRequired partialMessage = TestRequired.newBuilder()
+ .setA(1).buildPartial();
+
+ // parsePartialFrom should pass.
+ byte[] data = partialMessage.toByteArray();
+ assertEquals(partialMessage, parser.parsePartialFrom(data));
+ assertEquals(partialMessage, parser.parsePartialFrom(
+ partialMessage.toByteString()));
+ assertEquals(partialMessage, parser.parsePartialFrom(
+ new ByteArrayInputStream(data)));
+ assertEquals(partialMessage, parser.parsePartialFrom(
+ CodedInputStream.newInstance(data)));
+
+ // parseFrom(ByteArray)
+ try {
+ parser.parseFrom(partialMessage.toByteArray());
+ fail(errorString);
+ } catch (InvalidProtocolBufferException e) {
+ // pass.
+ }
+
+ // parseFrom(ByteString)
+ try {
+ parser.parseFrom(partialMessage.toByteString());
+ fail(errorString);
+ } catch (InvalidProtocolBufferException e) {
+ // pass.
+ }
+
+ // parseFrom(InputStream)
+ try {
+ parser.parseFrom(new ByteArrayInputStream(partialMessage.toByteArray()));
+ fail(errorString);
+ } catch (IOException e) {
+ // pass.
+ }
+
+ // parseFrom(CodedInputStream)
+ try {
+ parser.parseFrom(CodedInputStream.newInstance(
+ partialMessage.toByteArray()));
+ fail(errorString);
+ } catch (IOException e) {
+ // pass.
+ }
+ }
+
+ public void testParseDelimitedTo() throws Exception {
+ // Write normal Message.
+ TestAllTypes normalMessage = TestUtil.getAllSet();
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ normalMessage.writeDelimitedTo(output);
+
+ InputStream input = new ByteArrayInputStream(output.toByteArray());
+ assertMessageEquals(
+ normalMessage,
+ normalMessage.getParserForType().parseDelimitedFrom(input));
+ }
+
+ public void testParseUnknownFields() throws Exception {
+ // All fields will be treated as unknown fields in emptyMessage.
+ TestEmptyMessage emptyMessage = TestEmptyMessage.PARSER.parseFrom(
+ TestUtil.getAllSet().toByteString());
+ assertEquals(
+ TestUtil.getAllSet().toByteString(),
+ emptyMessage.toByteString());
+ }
+
+ public void testOptimizeForSize() throws Exception {
+ TestOptimizedForSize.Builder builder = TestOptimizedForSize.newBuilder();
+ builder.setI(12).setMsg(ForeignMessage.newBuilder().setC(34).build());
+ builder.setExtension(TestOptimizedForSize.testExtension, 56);
+ builder.setExtension(TestOptimizedForSize.testExtension2,
+ TestRequiredOptimizedForSize.newBuilder().setX(78).build());
+
+ TestOptimizedForSize message = builder.build();
+ ExtensionRegistry registry = ExtensionRegistry.newInstance();
+ UnittestOptimizeFor.registerAllExtensions(registry);
+
+ assertRoundTripEquals(message, registry);
+ }
+
+ /** Helper method for {@link #testParsingMerge()}.*/
+ private void assertMessageMerged(TestAllTypes allTypes)
+ throws Exception {
+ assertEquals(3, allTypes.getOptionalInt32());
+ assertEquals(2, allTypes.getOptionalInt64());
+ assertEquals("hello", allTypes.getOptionalString());
+ }
+
+ public void testParsingMerge() throws Exception {
+ // Build messages.
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestAllTypes msg1 = builder.setOptionalInt32(1).build();
+ builder.clear();
+ TestAllTypes msg2 = builder.setOptionalInt64(2).build();
+ builder.clear();
+ TestAllTypes msg3 = builder.setOptionalInt32(3)
+ .setOptionalString("hello").build();
+
+ // Build groups.
+ TestParsingMerge.RepeatedFieldsGenerator.Group1 optionalG1 =
+ TestParsingMerge.RepeatedFieldsGenerator.Group1.newBuilder()
+ .setField1(msg1).build();
+ TestParsingMerge.RepeatedFieldsGenerator.Group1 optionalG2 =
+ TestParsingMerge.RepeatedFieldsGenerator.Group1.newBuilder()
+ .setField1(msg2).build();
+ TestParsingMerge.RepeatedFieldsGenerator.Group1 optionalG3 =
+ TestParsingMerge.RepeatedFieldsGenerator.Group1.newBuilder()
+ .setField1(msg3).build();
+ TestParsingMerge.RepeatedFieldsGenerator.Group2 repeatedG1 =
+ TestParsingMerge.RepeatedFieldsGenerator.Group2.newBuilder()
+ .setField1(msg1).build();
+ TestParsingMerge.RepeatedFieldsGenerator.Group2 repeatedG2 =
+ TestParsingMerge.RepeatedFieldsGenerator.Group2.newBuilder()
+ .setField1(msg2).build();
+ TestParsingMerge.RepeatedFieldsGenerator.Group2 repeatedG3 =
+ TestParsingMerge.RepeatedFieldsGenerator.Group2.newBuilder()
+ .setField1(msg3).build();
+
+ // Assign and serialize RepeatedFieldsGenerator.
+ ByteString data = TestParsingMerge.RepeatedFieldsGenerator.newBuilder()
+ .addField1(msg1).addField1(msg2).addField1(msg3)
+ .addField2(msg1).addField2(msg2).addField2(msg3)
+ .addField3(msg1).addField3(msg2).addField3(msg3)
+ .addGroup1(optionalG1).addGroup1(optionalG2).addGroup1(optionalG3)
+ .addGroup2(repeatedG1).addGroup2(repeatedG2).addGroup2(repeatedG3)
+ .addExt1(msg1).addExt1(msg2).addExt1(msg3)
+ .addExt2(msg1).addExt2(msg2).addExt2(msg3)
+ .build().toByteString();
+
+ // Parse TestParsingMerge.
+ ExtensionRegistry registry = ExtensionRegistry.newInstance();
+ UnittestProto.registerAllExtensions(registry);
+ TestParsingMerge parsingMerge =
+ TestParsingMerge.PARSER.parseFrom(data, registry);
+
+ // Required and optional fields should be merged.
+ assertMessageMerged(parsingMerge.getRequiredAllTypes());
+ assertMessageMerged(parsingMerge.getOptionalAllTypes());
+ assertMessageMerged(
+ parsingMerge.getOptionalGroup().getOptionalGroupAllTypes());
+ assertMessageMerged(parsingMerge.getExtension(
+ TestParsingMerge.optionalExt));
+
+ // Repeated fields should not be merged.
+ assertEquals(3, parsingMerge.getRepeatedAllTypesCount());
+ assertEquals(3, parsingMerge.getRepeatedGroupCount());
+ assertEquals(3, parsingMerge.getExtensionCount(
+ TestParsingMerge.repeatedExt));
+ }
+
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/RopeByteStringSubstringTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/RopeByteStringSubstringTest.java
new file mode 100644
index 0000000000..3c1f5035b7
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/RopeByteStringSubstringTest.java
@@ -0,0 +1,62 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Iterator;
+
+/**
+ * This class tests {@link RopeByteString#substring(int, int)} by inheriting the tests from
+ * {@link LiteralByteStringTest}. Only a couple of methods are overridden.
+ *
+ * @author carlanton@google.com (Carl Haverl)
+ */
+public class RopeByteStringSubstringTest extends LiteralByteStringTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ classUnderTest = "RopeByteString";
+ byte[] sourceBytes = ByteStringTest.getTestBytes(22341, 22337766L);
+ Iterator<ByteString> iter = ByteStringTest.makeConcretePieces(sourceBytes).iterator();
+ ByteString sourceString = iter.next();
+ while (iter.hasNext()) {
+ sourceString = sourceString.concat(iter.next());
+ }
+
+ int from = 1130;
+ int to = sourceBytes.length - 5555;
+ stringUnderTest = sourceString.substring(from, to);
+ referenceBytes = new byte[to - from];
+ System.arraycopy(sourceBytes, from, referenceBytes, 0, to - from);
+ expectedHashCode = -1259260680;
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/RopeByteStringTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/RopeByteStringTest.java
new file mode 100644
index 0000000000..8caeadd9a1
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/RopeByteStringTest.java
@@ -0,0 +1,84 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Iterator;
+
+/**
+ * This class tests {@link RopeByteString} by inheriting the tests from
+ * {@link LiteralByteStringTest}. Only a couple of methods are overridden.
+ *
+ * <p>A full test of the result of {@link RopeByteString#substring(int, int)} is found in the
+ * separate class {@link RopeByteStringSubstringTest}.
+ *
+ * @author carlanton@google.com (Carl Haverl)
+ */
+public class RopeByteStringTest extends LiteralByteStringTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ classUnderTest = "RopeByteString";
+ referenceBytes = ByteStringTest.getTestBytes(22341, 22337766L);
+ Iterator<ByteString> iter = ByteStringTest.makeConcretePieces(referenceBytes).iterator();
+ stringUnderTest = iter.next();
+ while (iter.hasNext()) {
+ stringUnderTest = stringUnderTest.concat(iter.next());
+ }
+ expectedHashCode = -1214197238;
+ }
+
+ public void testBalance() {
+ int numberOfPieces = 10000;
+ int pieceSize = 64;
+ byte[] testBytes = ByteStringTest.getTestBytes(numberOfPieces * pieceSize, 113377L);
+
+ // Build up a big ByteString from smaller pieces to force a rebalance
+ ByteString concatenated = ByteString.EMPTY;
+ for (int i = 0; i < numberOfPieces; ++i) {
+ concatenated = concatenated.concat(ByteString.copyFrom(testBytes, i * pieceSize, pieceSize));
+ }
+
+ assertEquals(classUnderTest + " from string must have the expected type",
+ classUnderTest, getActualClassName(concatenated));
+ assertTrue(classUnderTest + " underlying bytes must match after balancing",
+ Arrays.equals(testBytes, concatenated.toByteArray()));
+ ByteString testString = ByteString.copyFrom(testBytes);
+ assertTrue(classUnderTest + " balanced string must equal flat string",
+ concatenated.equals(testString));
+ assertTrue(classUnderTest + " flat string must equal balanced string",
+ testString.equals(concatenated));
+ assertEquals(classUnderTest + " balanced string must have same hash code as flat string",
+ testString.hashCode(), concatenated.hashCode());
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ServiceTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ServiceTest.java
new file mode 100644
index 0000000000..4c7f751c0a
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/ServiceTest.java
@@ -0,0 +1,321 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import com.google.protobuf.Descriptors.FileDescriptor;
+import com.google.protobuf.Descriptors.MethodDescriptor;
+import google.protobuf.no_generic_services_test.UnittestNoGenericServices;
+import protobuf_unittest.MessageWithNoOuter;
+import protobuf_unittest.ServiceWithNoOuter;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestService;
+import protobuf_unittest.UnittestProto.FooRequest;
+import protobuf_unittest.UnittestProto.FooResponse;
+import protobuf_unittest.UnittestProto.BarRequest;
+import protobuf_unittest.UnittestProto.BarResponse;
+
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+import org.easymock.IArgumentMatcher;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests services and stubs.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class ServiceTest extends TestCase {
+ private IMocksControl control;
+ private RpcController mockController;
+
+ private final Descriptors.MethodDescriptor fooDescriptor =
+ TestService.getDescriptor().getMethods().get(0);
+ private final Descriptors.MethodDescriptor barDescriptor =
+ TestService.getDescriptor().getMethods().get(1);
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ control = EasyMock.createStrictControl();
+ mockController = control.createMock(RpcController.class);
+ }
+
+ // =================================================================
+
+ /** Tests Service.callMethod(). */
+ public void testCallMethod() throws Exception {
+ FooRequest fooRequest = FooRequest.newBuilder().build();
+ BarRequest barRequest = BarRequest.newBuilder().build();
+ MockCallback<Message> fooCallback = new MockCallback<Message>();
+ MockCallback<Message> barCallback = new MockCallback<Message>();
+ TestService mockService = control.createMock(TestService.class);
+
+ mockService.foo(EasyMock.same(mockController), EasyMock.same(fooRequest),
+ this.<FooResponse>wrapsCallback(fooCallback));
+ mockService.bar(EasyMock.same(mockController), EasyMock.same(barRequest),
+ this.<BarResponse>wrapsCallback(barCallback));
+ control.replay();
+
+ mockService.callMethod(fooDescriptor, mockController,
+ fooRequest, fooCallback);
+ mockService.callMethod(barDescriptor, mockController,
+ barRequest, barCallback);
+ control.verify();
+ }
+
+ /** Tests Service.get{Request,Response}Prototype(). */
+ public void testGetPrototype() throws Exception {
+ TestService mockService = control.createMock(TestService.class);
+
+ assertSame(mockService.getRequestPrototype(fooDescriptor),
+ FooRequest.getDefaultInstance());
+ assertSame(mockService.getResponsePrototype(fooDescriptor),
+ FooResponse.getDefaultInstance());
+ assertSame(mockService.getRequestPrototype(barDescriptor),
+ BarRequest.getDefaultInstance());
+ assertSame(mockService.getResponsePrototype(barDescriptor),
+ BarResponse.getDefaultInstance());
+ }
+
+ /** Tests generated stubs. */
+ public void testStub() throws Exception {
+ FooRequest fooRequest = FooRequest.newBuilder().build();
+ BarRequest barRequest = BarRequest.newBuilder().build();
+ MockCallback<FooResponse> fooCallback = new MockCallback<FooResponse>();
+ MockCallback<BarResponse> barCallback = new MockCallback<BarResponse>();
+ RpcChannel mockChannel = control.createMock(RpcChannel.class);
+ TestService stub = TestService.newStub(mockChannel);
+
+ mockChannel.callMethod(
+ EasyMock.same(fooDescriptor),
+ EasyMock.same(mockController),
+ EasyMock.same(fooRequest),
+ EasyMock.same(FooResponse.getDefaultInstance()),
+ this.<Message>wrapsCallback(fooCallback));
+ mockChannel.callMethod(
+ EasyMock.same(barDescriptor),
+ EasyMock.same(mockController),
+ EasyMock.same(barRequest),
+ EasyMock.same(BarResponse.getDefaultInstance()),
+ this.<Message>wrapsCallback(barCallback));
+ control.replay();
+
+ stub.foo(mockController, fooRequest, fooCallback);
+ stub.bar(mockController, barRequest, barCallback);
+ control.verify();
+ }
+
+ /** Tests generated blocking stubs. */
+ public void testBlockingStub() throws Exception {
+ FooRequest fooRequest = FooRequest.newBuilder().build();
+ BarRequest barRequest = BarRequest.newBuilder().build();
+ BlockingRpcChannel mockChannel =
+ control.createMock(BlockingRpcChannel.class);
+ TestService.BlockingInterface stub =
+ TestService.newBlockingStub(mockChannel);
+
+ FooResponse fooResponse = FooResponse.newBuilder().build();
+ BarResponse barResponse = BarResponse.newBuilder().build();
+
+ EasyMock.expect(mockChannel.callBlockingMethod(
+ EasyMock.same(fooDescriptor),
+ EasyMock.same(mockController),
+ EasyMock.same(fooRequest),
+ EasyMock.same(FooResponse.getDefaultInstance()))).andReturn(fooResponse);
+ EasyMock.expect(mockChannel.callBlockingMethod(
+ EasyMock.same(barDescriptor),
+ EasyMock.same(mockController),
+ EasyMock.same(barRequest),
+ EasyMock.same(BarResponse.getDefaultInstance()))).andReturn(barResponse);
+ control.replay();
+
+ assertSame(fooResponse, stub.foo(mockController, fooRequest));
+ assertSame(barResponse, stub.bar(mockController, barRequest));
+ control.verify();
+ }
+
+ public void testNewReflectiveService() {
+ ServiceWithNoOuter.Interface impl =
+ control.createMock(ServiceWithNoOuter.Interface.class);
+ RpcController controller = control.createMock(RpcController.class);
+ Service service = ServiceWithNoOuter.newReflectiveService(impl);
+
+ MethodDescriptor fooMethod =
+ ServiceWithNoOuter.getDescriptor().findMethodByName("Foo");
+ MessageWithNoOuter request = MessageWithNoOuter.getDefaultInstance();
+ RpcCallback<Message> callback = new RpcCallback<Message>() {
+ public void run(Message parameter) {
+ // No reason this should be run.
+ fail();
+ }
+ };
+ RpcCallback<TestAllTypes> specializedCallback =
+ RpcUtil.specializeCallback(callback);
+
+ impl.foo(EasyMock.same(controller), EasyMock.same(request),
+ EasyMock.same(specializedCallback));
+ EasyMock.expectLastCall();
+
+ control.replay();
+
+ service.callMethod(fooMethod, controller, request, callback);
+
+ control.verify();
+ }
+
+ public void testNewReflectiveBlockingService() throws ServiceException {
+ ServiceWithNoOuter.BlockingInterface impl =
+ control.createMock(ServiceWithNoOuter.BlockingInterface.class);
+ RpcController controller = control.createMock(RpcController.class);
+ BlockingService service =
+ ServiceWithNoOuter.newReflectiveBlockingService(impl);
+
+ MethodDescriptor fooMethod =
+ ServiceWithNoOuter.getDescriptor().findMethodByName("Foo");
+ MessageWithNoOuter request = MessageWithNoOuter.getDefaultInstance();
+
+ TestAllTypes expectedResponse = TestAllTypes.getDefaultInstance();
+ EasyMock.expect(impl.foo(EasyMock.same(controller), EasyMock.same(request)))
+ .andReturn(expectedResponse);
+
+ control.replay();
+
+ Message response =
+ service.callBlockingMethod(fooMethod, controller, request);
+ assertEquals(expectedResponse, response);
+
+ control.verify();
+ }
+
+ public void testNoGenericServices() throws Exception {
+ // Non-services should be usable.
+ UnittestNoGenericServices.TestMessage message =
+ UnittestNoGenericServices.TestMessage.newBuilder()
+ .setA(123)
+ .setExtension(UnittestNoGenericServices.testExtension, 456)
+ .build();
+ assertEquals(123, message.getA());
+ assertEquals(1, UnittestNoGenericServices.TestEnum.FOO.getNumber());
+
+ // Build a list of the class names nested in UnittestNoGenericServices.
+ String outerName = "google.protobuf.no_generic_services_test." +
+ "UnittestNoGenericServices";
+ Class<?> outerClass = Class.forName(outerName);
+
+ Set<String> innerClassNames = new HashSet<String>();
+ for (Class<?> innerClass : outerClass.getClasses()) {
+ String fullName = innerClass.getName();
+ // Figure out the unqualified name of the inner class.
+ // Note: Surprisingly, the full name of an inner class will be separated
+ // from the outer class name by a '$' rather than a '.'. This is not
+ // mentioned in the documentation for java.lang.Class. I don't want to
+ // make assumptions, so I'm just going to accept any character as the
+ // separator.
+ assertTrue(fullName.startsWith(outerName));
+
+ if (!Service.class.isAssignableFrom(innerClass) &&
+ !Message.class.isAssignableFrom(innerClass) &&
+ !ProtocolMessageEnum.class.isAssignableFrom(innerClass)) {
+ // Ignore any classes not generated by the base code generator.
+ continue;
+ }
+
+ innerClassNames.add(fullName.substring(outerName.length() + 1));
+ }
+
+ // No service class should have been generated.
+ assertTrue(innerClassNames.contains("TestMessage"));
+ assertTrue(innerClassNames.contains("TestEnum"));
+ assertFalse(innerClassNames.contains("TestService"));
+
+ // But descriptors are there.
+ FileDescriptor file = UnittestNoGenericServices.getDescriptor();
+ assertEquals(1, file.getServices().size());
+ assertEquals("TestService", file.getServices().get(0).getName());
+ assertEquals(1, file.getServices().get(0).getMethods().size());
+ assertEquals("Foo",
+ file.getServices().get(0).getMethods().get(0).getName());
+ }
+
+ // =================================================================
+
+ /**
+ * wrapsCallback() is an EasyMock argument predicate. wrapsCallback(c)
+ * matches a callback if calling that callback causes c to be called.
+ * In other words, c wraps the given callback.
+ */
+ private <Type extends Message> RpcCallback<Type> wrapsCallback(
+ MockCallback<?> callback) {
+ EasyMock.reportMatcher(new WrapsCallback(callback));
+ return null;
+ }
+
+ /** The parameter to wrapsCallback() must be a MockCallback. */
+ private static class MockCallback<Type extends Message>
+ implements RpcCallback<Type> {
+ private boolean called = false;
+
+ public boolean isCalled() { return called; }
+
+ public void reset() { called = false; }
+ public void run(Type message) { called = true; }
+ }
+
+ /** Implementation of the wrapsCallback() argument matcher. */
+ private static class WrapsCallback implements IArgumentMatcher {
+ private MockCallback<?> callback;
+
+ public WrapsCallback(MockCallback<?> callback) {
+ this.callback = callback;
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean matches(Object actual) {
+ if (!(actual instanceof RpcCallback)) {
+ return false;
+ }
+ RpcCallback actualCallback = (RpcCallback)actual;
+
+ callback.reset();
+ actualCallback.run(null);
+ return callback.isCalled();
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("wrapsCallback(mockCallback)");
+ }
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/TestBadIdentifiers.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/TestBadIdentifiers.java
new file mode 100644
index 0000000000..5086732295
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/TestBadIdentifiers.java
@@ -0,0 +1,64 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests that proto2 api generation doesn't cause compile errors when
+ * compiling protocol buffers that have names that would otherwise conflict
+ * if not fully qualified (like @Deprecated and @Override).
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class TestBadIdentifiers extends TestCase {
+
+ public void testCompilation() {
+ // If this compiles, it means the generation was correct.
+ TestBadIdentifiersProto.Deprecated.newBuilder();
+ TestBadIdentifiersProto.Override.newBuilder();
+ }
+
+ public void testGetDescriptor() {
+ Descriptors.FileDescriptor fileDescriptor =
+ TestBadIdentifiersProto.getDescriptor();
+ String descriptorField = TestBadIdentifiersProto.Descriptor
+ .getDefaultInstance().getDescriptor();
+ Descriptors.Descriptor protoDescriptor = TestBadIdentifiersProto.Descriptor
+ .getDefaultInstance().getDescriptorForType();
+ String nestedDescriptorField = TestBadIdentifiersProto.Descriptor
+ .NestedDescriptor.getDefaultInstance().getDescriptor();
+ Descriptors.Descriptor nestedProtoDescriptor = TestBadIdentifiersProto
+ .Descriptor.NestedDescriptor.getDefaultInstance()
+ .getDescriptorForType();
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/TestUtil.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/TestUtil.java
new file mode 100644
index 0000000000..a92348303e
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/TestUtil.java
@@ -0,0 +1,3068 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import protobuf_unittest.UnittestProto;
+
+// The static imports are to avoid 100+ char lines. The following is roughly equivalent to
+// import static protobuf_unittest.UnittestProto.*;
+import static protobuf_unittest.UnittestProto.defaultInt32Extension;
+import static protobuf_unittest.UnittestProto.defaultInt64Extension;
+import static protobuf_unittest.UnittestProto.defaultUint32Extension;
+import static protobuf_unittest.UnittestProto.defaultUint64Extension;
+import static protobuf_unittest.UnittestProto.defaultSint32Extension;
+import static protobuf_unittest.UnittestProto.defaultSint64Extension;
+import static protobuf_unittest.UnittestProto.defaultFixed32Extension;
+import static protobuf_unittest.UnittestProto.defaultFixed64Extension;
+import static protobuf_unittest.UnittestProto.defaultSfixed32Extension;
+import static protobuf_unittest.UnittestProto.defaultSfixed64Extension;
+import static protobuf_unittest.UnittestProto.defaultFloatExtension;
+import static protobuf_unittest.UnittestProto.defaultDoubleExtension;
+import static protobuf_unittest.UnittestProto.defaultBoolExtension;
+import static protobuf_unittest.UnittestProto.defaultStringExtension;
+import static protobuf_unittest.UnittestProto.defaultBytesExtension;
+import static protobuf_unittest.UnittestProto.defaultNestedEnumExtension;
+import static protobuf_unittest.UnittestProto.defaultForeignEnumExtension;
+import static protobuf_unittest.UnittestProto.defaultImportEnumExtension;
+import static protobuf_unittest.UnittestProto.defaultStringPieceExtension;
+import static protobuf_unittest.UnittestProto.defaultCordExtension;
+
+import static protobuf_unittest.UnittestProto.optionalInt32Extension;
+import static protobuf_unittest.UnittestProto.optionalInt64Extension;
+import static protobuf_unittest.UnittestProto.optionalUint32Extension;
+import static protobuf_unittest.UnittestProto.optionalUint64Extension;
+import static protobuf_unittest.UnittestProto.optionalSint32Extension;
+import static protobuf_unittest.UnittestProto.optionalSint64Extension;
+import static protobuf_unittest.UnittestProto.optionalFixed32Extension;
+import static protobuf_unittest.UnittestProto.optionalFixed64Extension;
+import static protobuf_unittest.UnittestProto.optionalSfixed32Extension;
+import static protobuf_unittest.UnittestProto.optionalSfixed64Extension;
+import static protobuf_unittest.UnittestProto.optionalFloatExtension;
+import static protobuf_unittest.UnittestProto.optionalDoubleExtension;
+import static protobuf_unittest.UnittestProto.optionalBoolExtension;
+import static protobuf_unittest.UnittestProto.optionalStringExtension;
+import static protobuf_unittest.UnittestProto.optionalBytesExtension;
+import static protobuf_unittest.UnittestProto.optionalGroupExtension;
+import static protobuf_unittest.UnittestProto.optionalCordExtension;
+import static protobuf_unittest.UnittestProto.optionalForeignEnumExtension;
+import static protobuf_unittest.UnittestProto.optionalForeignMessageExtension;
+import static protobuf_unittest.UnittestProto.optionalImportEnumExtension;
+import static protobuf_unittest.UnittestProto.optionalImportMessageExtension;
+import static protobuf_unittest.UnittestProto.optionalNestedEnumExtension;
+import static protobuf_unittest.UnittestProto.optionalNestedMessageExtension;
+import static protobuf_unittest.UnittestProto.optionalPublicImportMessageExtension;
+import static protobuf_unittest.UnittestProto.optionalLazyMessageExtension;
+import static protobuf_unittest.UnittestProto.optionalStringPieceExtension;
+
+import static protobuf_unittest.UnittestProto.repeatedInt32Extension;
+import static protobuf_unittest.UnittestProto.repeatedInt64Extension;
+import static protobuf_unittest.UnittestProto.repeatedUint32Extension;
+import static protobuf_unittest.UnittestProto.repeatedUint64Extension;
+import static protobuf_unittest.UnittestProto.repeatedSint32Extension;
+import static protobuf_unittest.UnittestProto.repeatedSint64Extension;
+import static protobuf_unittest.UnittestProto.repeatedFixed32Extension;
+import static protobuf_unittest.UnittestProto.repeatedFixed64Extension;
+import static protobuf_unittest.UnittestProto.repeatedSfixed32Extension;
+import static protobuf_unittest.UnittestProto.repeatedSfixed64Extension;
+import static protobuf_unittest.UnittestProto.repeatedFloatExtension;
+import static protobuf_unittest.UnittestProto.repeatedDoubleExtension;
+import static protobuf_unittest.UnittestProto.repeatedBoolExtension;
+import static protobuf_unittest.UnittestProto.repeatedStringExtension;
+import static protobuf_unittest.UnittestProto.repeatedBytesExtension;
+import static protobuf_unittest.UnittestProto.repeatedGroupExtension;
+import static protobuf_unittest.UnittestProto.repeatedNestedMessageExtension;
+import static protobuf_unittest.UnittestProto.repeatedForeignMessageExtension;
+import static protobuf_unittest.UnittestProto.repeatedImportMessageExtension;
+import static protobuf_unittest.UnittestProto.repeatedLazyMessageExtension;
+import static protobuf_unittest.UnittestProto.repeatedNestedEnumExtension;
+import static protobuf_unittest.UnittestProto.repeatedForeignEnumExtension;
+import static protobuf_unittest.UnittestProto.repeatedImportEnumExtension;
+import static protobuf_unittest.UnittestProto.repeatedStringPieceExtension;
+import static protobuf_unittest.UnittestProto.repeatedCordExtension;
+
+import static protobuf_unittest.UnittestProto.OptionalGroup_extension;
+import static protobuf_unittest.UnittestProto.RepeatedGroup_extension;
+
+import static protobuf_unittest.UnittestProto.packedInt32Extension;
+import static protobuf_unittest.UnittestProto.packedInt64Extension;
+import static protobuf_unittest.UnittestProto.packedUint32Extension;
+import static protobuf_unittest.UnittestProto.packedUint64Extension;
+import static protobuf_unittest.UnittestProto.packedSint32Extension;
+import static protobuf_unittest.UnittestProto.packedSint64Extension;
+import static protobuf_unittest.UnittestProto.packedFixed32Extension;
+import static protobuf_unittest.UnittestProto.packedFixed64Extension;
+import static protobuf_unittest.UnittestProto.packedSfixed32Extension;
+import static protobuf_unittest.UnittestProto.packedSfixed64Extension;
+import static protobuf_unittest.UnittestProto.packedFloatExtension;
+import static protobuf_unittest.UnittestProto.packedDoubleExtension;
+import static protobuf_unittest.UnittestProto.packedBoolExtension;
+import static protobuf_unittest.UnittestProto.packedEnumExtension;
+
+
+import protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestAllExtensionsOrBuilder;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestAllTypesOrBuilder;
+import protobuf_unittest.UnittestProto.TestPackedExtensions;
+import protobuf_unittest.UnittestProto.TestPackedTypes;
+import protobuf_unittest.UnittestProto.TestUnpackedTypes;
+import protobuf_unittest.UnittestProto.ForeignMessage;
+import protobuf_unittest.UnittestProto.ForeignEnum;
+import com.google.protobuf.test.UnittestImport.ImportEnum;
+import com.google.protobuf.test.UnittestImport.ImportMessage;
+import com.google.protobuf.test.UnittestImportPublic.PublicImportMessage;
+
+import junit.framework.Assert;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+
+/**
+ * Contains methods for setting all fields of {@code TestAllTypes} to
+ * some values as well as checking that all the fields are set to those values.
+ * These are useful for testing various protocol message features, e.g.
+ * set all fields of a message, serialize it, parse it, and check that all
+ * fields are set.
+ *
+ * <p>This code is not to be used outside of {@code com.google.protobuf} and
+ * subpackages.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public final class TestUtil {
+ private TestUtil() {}
+
+ /** Helper to convert a String to ByteString. */
+ static ByteString toBytes(String str) {
+ try {
+ return ByteString.copyFrom(str.getBytes("UTF-8"));
+ } catch(java.io.UnsupportedEncodingException e) {
+ throw new RuntimeException("UTF-8 not supported.", e);
+ }
+ }
+
+ /**
+ * Get a {@code TestAllTypes} with all fields set as they would be by
+ * {@link #setAllFields(TestAllTypes.Builder)}.
+ */
+ public static TestAllTypes getAllSet() {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ setAllFields(builder);
+ return builder.build();
+ }
+
+ /**
+ * Get a {@code TestAllTypes.Builder} with all fields set as they would be by
+ * {@link #setAllFields(TestAllTypes.Builder)}.
+ */
+ public static TestAllTypes.Builder getAllSetBuilder() {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ setAllFields(builder);
+ return builder;
+ }
+
+ /**
+ * Get a {@code TestAllExtensions} with all fields set as they would be by
+ * {@link #setAllExtensions(TestAllExtensions.Builder)}.
+ */
+ public static TestAllExtensions getAllExtensionsSet() {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ setAllExtensions(builder);
+ return builder.build();
+ }
+
+ public static TestPackedTypes getPackedSet() {
+ TestPackedTypes.Builder builder = TestPackedTypes.newBuilder();
+ setPackedFields(builder);
+ return builder.build();
+ }
+
+ public static TestUnpackedTypes getUnpackedSet() {
+ TestUnpackedTypes.Builder builder = TestUnpackedTypes.newBuilder();
+ setUnpackedFields(builder);
+ return builder.build();
+ }
+
+ public static TestPackedExtensions getPackedExtensionsSet() {
+ TestPackedExtensions.Builder builder = TestPackedExtensions.newBuilder();
+ setPackedExtensions(builder);
+ return builder.build();
+ }
+
+ /**
+ * Set every field of {@code message} to the values expected by
+ * {@code assertAllFieldsSet()}.
+ */
+ public static void setAllFields(TestAllTypes.Builder message) {
+ message.setOptionalInt32 (101);
+ message.setOptionalInt64 (102);
+ message.setOptionalUint32 (103);
+ message.setOptionalUint64 (104);
+ message.setOptionalSint32 (105);
+ message.setOptionalSint64 (106);
+ message.setOptionalFixed32 (107);
+ message.setOptionalFixed64 (108);
+ message.setOptionalSfixed32(109);
+ message.setOptionalSfixed64(110);
+ message.setOptionalFloat (111);
+ message.setOptionalDouble (112);
+ message.setOptionalBool (true);
+ message.setOptionalString ("115");
+ message.setOptionalBytes (toBytes("116"));
+
+ message.setOptionalGroup(
+ TestAllTypes.OptionalGroup.newBuilder().setA(117).build());
+ message.setOptionalNestedMessage(
+ TestAllTypes.NestedMessage.newBuilder().setBb(118).build());
+ message.setOptionalForeignMessage(
+ ForeignMessage.newBuilder().setC(119).build());
+ message.setOptionalImportMessage(
+ ImportMessage.newBuilder().setD(120).build());
+ message.setOptionalPublicImportMessage(
+ PublicImportMessage.newBuilder().setE(126).build());
+ message.setOptionalLazyMessage(
+ TestAllTypes.NestedMessage.newBuilder().setBb(127).build());
+
+ message.setOptionalNestedEnum (TestAllTypes.NestedEnum.BAZ);
+ message.setOptionalForeignEnum(ForeignEnum.FOREIGN_BAZ);
+ message.setOptionalImportEnum (ImportEnum.IMPORT_BAZ);
+
+ message.setOptionalStringPiece("124");
+ message.setOptionalCord("125");
+
+ // -----------------------------------------------------------------
+
+ message.addRepeatedInt32 (201);
+ message.addRepeatedInt64 (202);
+ message.addRepeatedUint32 (203);
+ message.addRepeatedUint64 (204);
+ message.addRepeatedSint32 (205);
+ message.addRepeatedSint64 (206);
+ message.addRepeatedFixed32 (207);
+ message.addRepeatedFixed64 (208);
+ message.addRepeatedSfixed32(209);
+ message.addRepeatedSfixed64(210);
+ message.addRepeatedFloat (211);
+ message.addRepeatedDouble (212);
+ message.addRepeatedBool (true);
+ message.addRepeatedString ("215");
+ message.addRepeatedBytes (toBytes("216"));
+
+ message.addRepeatedGroup(
+ TestAllTypes.RepeatedGroup.newBuilder().setA(217).build());
+ message.addRepeatedNestedMessage(
+ TestAllTypes.NestedMessage.newBuilder().setBb(218).build());
+ message.addRepeatedForeignMessage(
+ ForeignMessage.newBuilder().setC(219).build());
+ message.addRepeatedImportMessage(
+ ImportMessage.newBuilder().setD(220).build());
+ message.addRepeatedLazyMessage(
+ TestAllTypes.NestedMessage.newBuilder().setBb(227).build());
+
+ message.addRepeatedNestedEnum (TestAllTypes.NestedEnum.BAR);
+ message.addRepeatedForeignEnum(ForeignEnum.FOREIGN_BAR);
+ message.addRepeatedImportEnum (ImportEnum.IMPORT_BAR);
+
+ message.addRepeatedStringPiece("224");
+ message.addRepeatedCord("225");
+
+ // Add a second one of each field.
+ message.addRepeatedInt32 (301);
+ message.addRepeatedInt64 (302);
+ message.addRepeatedUint32 (303);
+ message.addRepeatedUint64 (304);
+ message.addRepeatedSint32 (305);
+ message.addRepeatedSint64 (306);
+ message.addRepeatedFixed32 (307);
+ message.addRepeatedFixed64 (308);
+ message.addRepeatedSfixed32(309);
+ message.addRepeatedSfixed64(310);
+ message.addRepeatedFloat (311);
+ message.addRepeatedDouble (312);
+ message.addRepeatedBool (false);
+ message.addRepeatedString ("315");
+ message.addRepeatedBytes (toBytes("316"));
+
+ message.addRepeatedGroup(
+ TestAllTypes.RepeatedGroup.newBuilder().setA(317).build());
+ message.addRepeatedNestedMessage(
+ TestAllTypes.NestedMessage.newBuilder().setBb(318).build());
+ message.addRepeatedForeignMessage(
+ ForeignMessage.newBuilder().setC(319).build());
+ message.addRepeatedImportMessage(
+ ImportMessage.newBuilder().setD(320).build());
+ message.addRepeatedLazyMessage(
+ TestAllTypes.NestedMessage.newBuilder().setBb(327).build());
+
+ message.addRepeatedNestedEnum (TestAllTypes.NestedEnum.BAZ);
+ message.addRepeatedForeignEnum(ForeignEnum.FOREIGN_BAZ);
+ message.addRepeatedImportEnum (ImportEnum.IMPORT_BAZ);
+
+ message.addRepeatedStringPiece("324");
+ message.addRepeatedCord("325");
+
+ // -----------------------------------------------------------------
+
+ message.setDefaultInt32 (401);
+ message.setDefaultInt64 (402);
+ message.setDefaultUint32 (403);
+ message.setDefaultUint64 (404);
+ message.setDefaultSint32 (405);
+ message.setDefaultSint64 (406);
+ message.setDefaultFixed32 (407);
+ message.setDefaultFixed64 (408);
+ message.setDefaultSfixed32(409);
+ message.setDefaultSfixed64(410);
+ message.setDefaultFloat (411);
+ message.setDefaultDouble (412);
+ message.setDefaultBool (false);
+ message.setDefaultString ("415");
+ message.setDefaultBytes (toBytes("416"));
+
+ message.setDefaultNestedEnum (TestAllTypes.NestedEnum.FOO);
+ message.setDefaultForeignEnum(ForeignEnum.FOREIGN_FOO);
+ message.setDefaultImportEnum (ImportEnum.IMPORT_FOO);
+
+ message.setDefaultStringPiece("424");
+ message.setDefaultCord("425");
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Modify the repeated fields of {@code message} to contain the values
+ * expected by {@code assertRepeatedFieldsModified()}.
+ */
+ public static void modifyRepeatedFields(TestAllTypes.Builder message) {
+ message.setRepeatedInt32 (1, 501);
+ message.setRepeatedInt64 (1, 502);
+ message.setRepeatedUint32 (1, 503);
+ message.setRepeatedUint64 (1, 504);
+ message.setRepeatedSint32 (1, 505);
+ message.setRepeatedSint64 (1, 506);
+ message.setRepeatedFixed32 (1, 507);
+ message.setRepeatedFixed64 (1, 508);
+ message.setRepeatedSfixed32(1, 509);
+ message.setRepeatedSfixed64(1, 510);
+ message.setRepeatedFloat (1, 511);
+ message.setRepeatedDouble (1, 512);
+ message.setRepeatedBool (1, true);
+ message.setRepeatedString (1, "515");
+ message.setRepeatedBytes (1, toBytes("516"));
+
+ message.setRepeatedGroup(1,
+ TestAllTypes.RepeatedGroup.newBuilder().setA(517).build());
+ message.setRepeatedNestedMessage(1,
+ TestAllTypes.NestedMessage.newBuilder().setBb(518).build());
+ message.setRepeatedForeignMessage(1,
+ ForeignMessage.newBuilder().setC(519).build());
+ message.setRepeatedImportMessage(1,
+ ImportMessage.newBuilder().setD(520).build());
+ message.setRepeatedLazyMessage(1,
+ TestAllTypes.NestedMessage.newBuilder().setBb(527).build());
+
+ message.setRepeatedNestedEnum (1, TestAllTypes.NestedEnum.FOO);
+ message.setRepeatedForeignEnum(1, ForeignEnum.FOREIGN_FOO);
+ message.setRepeatedImportEnum (1, ImportEnum.IMPORT_FOO);
+
+ message.setRepeatedStringPiece(1, "524");
+ message.setRepeatedCord(1, "525");
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all fields of
+ * {@code message} are set to the values assigned by {@code setAllFields}.
+ */
+ public static void assertAllFieldsSet(TestAllTypesOrBuilder message) {
+ Assert.assertTrue(message.hasOptionalInt32 ());
+ Assert.assertTrue(message.hasOptionalInt64 ());
+ Assert.assertTrue(message.hasOptionalUint32 ());
+ Assert.assertTrue(message.hasOptionalUint64 ());
+ Assert.assertTrue(message.hasOptionalSint32 ());
+ Assert.assertTrue(message.hasOptionalSint64 ());
+ Assert.assertTrue(message.hasOptionalFixed32 ());
+ Assert.assertTrue(message.hasOptionalFixed64 ());
+ Assert.assertTrue(message.hasOptionalSfixed32());
+ Assert.assertTrue(message.hasOptionalSfixed64());
+ Assert.assertTrue(message.hasOptionalFloat ());
+ Assert.assertTrue(message.hasOptionalDouble ());
+ Assert.assertTrue(message.hasOptionalBool ());
+ Assert.assertTrue(message.hasOptionalString ());
+ Assert.assertTrue(message.hasOptionalBytes ());
+
+ Assert.assertTrue(message.hasOptionalGroup ());
+ Assert.assertTrue(message.hasOptionalNestedMessage ());
+ Assert.assertTrue(message.hasOptionalForeignMessage());
+ Assert.assertTrue(message.hasOptionalImportMessage ());
+
+ Assert.assertTrue(message.getOptionalGroup ().hasA());
+ Assert.assertTrue(message.getOptionalNestedMessage ().hasBb());
+ Assert.assertTrue(message.getOptionalForeignMessage().hasC());
+ Assert.assertTrue(message.getOptionalImportMessage ().hasD());
+
+ Assert.assertTrue(message.hasOptionalNestedEnum ());
+ Assert.assertTrue(message.hasOptionalForeignEnum());
+ Assert.assertTrue(message.hasOptionalImportEnum ());
+
+ Assert.assertTrue(message.hasOptionalStringPiece());
+ Assert.assertTrue(message.hasOptionalCord());
+
+ Assert.assertEquals(101 , message.getOptionalInt32 ());
+ Assert.assertEquals(102 , message.getOptionalInt64 ());
+ Assert.assertEquals(103 , message.getOptionalUint32 ());
+ Assert.assertEquals(104 , message.getOptionalUint64 ());
+ Assert.assertEquals(105 , message.getOptionalSint32 ());
+ Assert.assertEquals(106 , message.getOptionalSint64 ());
+ Assert.assertEquals(107 , message.getOptionalFixed32 ());
+ Assert.assertEquals(108 , message.getOptionalFixed64 ());
+ Assert.assertEquals(109 , message.getOptionalSfixed32());
+ Assert.assertEquals(110 , message.getOptionalSfixed64());
+ Assert.assertEquals(111 , message.getOptionalFloat (), 0.0);
+ Assert.assertEquals(112 , message.getOptionalDouble (), 0.0);
+ Assert.assertEquals(true , message.getOptionalBool ());
+ Assert.assertEquals("115", message.getOptionalString ());
+ Assert.assertEquals(toBytes("116"), message.getOptionalBytes());
+
+ Assert.assertEquals(117, message.getOptionalGroup ().getA());
+ Assert.assertEquals(118, message.getOptionalNestedMessage ().getBb());
+ Assert.assertEquals(119, message.getOptionalForeignMessage ().getC());
+ Assert.assertEquals(120, message.getOptionalImportMessage ().getD());
+ Assert.assertEquals(126, message.getOptionalPublicImportMessage().getE());
+ Assert.assertEquals(127, message.getOptionalLazyMessage ().getBb());
+
+ Assert.assertEquals(TestAllTypes.NestedEnum.BAZ, message.getOptionalNestedEnum());
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAZ, message.getOptionalForeignEnum());
+ Assert.assertEquals(ImportEnum.IMPORT_BAZ, message.getOptionalImportEnum());
+
+ Assert.assertEquals("124", message.getOptionalStringPiece());
+ Assert.assertEquals("125", message.getOptionalCord());
+
+ // -----------------------------------------------------------------
+
+ Assert.assertEquals(2, message.getRepeatedInt32Count ());
+ Assert.assertEquals(2, message.getRepeatedInt64Count ());
+ Assert.assertEquals(2, message.getRepeatedUint32Count ());
+ Assert.assertEquals(2, message.getRepeatedUint64Count ());
+ Assert.assertEquals(2, message.getRepeatedSint32Count ());
+ Assert.assertEquals(2, message.getRepeatedSint64Count ());
+ Assert.assertEquals(2, message.getRepeatedFixed32Count ());
+ Assert.assertEquals(2, message.getRepeatedFixed64Count ());
+ Assert.assertEquals(2, message.getRepeatedSfixed32Count());
+ Assert.assertEquals(2, message.getRepeatedSfixed64Count());
+ Assert.assertEquals(2, message.getRepeatedFloatCount ());
+ Assert.assertEquals(2, message.getRepeatedDoubleCount ());
+ Assert.assertEquals(2, message.getRepeatedBoolCount ());
+ Assert.assertEquals(2, message.getRepeatedStringCount ());
+ Assert.assertEquals(2, message.getRepeatedBytesCount ());
+
+ Assert.assertEquals(2, message.getRepeatedGroupCount ());
+ Assert.assertEquals(2, message.getRepeatedNestedMessageCount ());
+ Assert.assertEquals(2, message.getRepeatedForeignMessageCount());
+ Assert.assertEquals(2, message.getRepeatedImportMessageCount ());
+ Assert.assertEquals(2, message.getRepeatedLazyMessageCount ());
+ Assert.assertEquals(2, message.getRepeatedNestedEnumCount ());
+ Assert.assertEquals(2, message.getRepeatedForeignEnumCount ());
+ Assert.assertEquals(2, message.getRepeatedImportEnumCount ());
+
+ Assert.assertEquals(2, message.getRepeatedStringPieceCount());
+ Assert.assertEquals(2, message.getRepeatedCordCount());
+
+ Assert.assertEquals(201 , message.getRepeatedInt32 (0));
+ Assert.assertEquals(202 , message.getRepeatedInt64 (0));
+ Assert.assertEquals(203 , message.getRepeatedUint32 (0));
+ Assert.assertEquals(204 , message.getRepeatedUint64 (0));
+ Assert.assertEquals(205 , message.getRepeatedSint32 (0));
+ Assert.assertEquals(206 , message.getRepeatedSint64 (0));
+ Assert.assertEquals(207 , message.getRepeatedFixed32 (0));
+ Assert.assertEquals(208 , message.getRepeatedFixed64 (0));
+ Assert.assertEquals(209 , message.getRepeatedSfixed32(0));
+ Assert.assertEquals(210 , message.getRepeatedSfixed64(0));
+ Assert.assertEquals(211 , message.getRepeatedFloat (0), 0.0);
+ Assert.assertEquals(212 , message.getRepeatedDouble (0), 0.0);
+ Assert.assertEquals(true , message.getRepeatedBool (0));
+ Assert.assertEquals("215", message.getRepeatedString (0));
+ Assert.assertEquals(toBytes("216"), message.getRepeatedBytes(0));
+
+ Assert.assertEquals(217, message.getRepeatedGroup (0).getA());
+ Assert.assertEquals(218, message.getRepeatedNestedMessage (0).getBb());
+ Assert.assertEquals(219, message.getRepeatedForeignMessage(0).getC());
+ Assert.assertEquals(220, message.getRepeatedImportMessage (0).getD());
+ Assert.assertEquals(227, message.getRepeatedLazyMessage (0).getBb());
+
+ Assert.assertEquals(TestAllTypes.NestedEnum.BAR, message.getRepeatedNestedEnum (0));
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAR, message.getRepeatedForeignEnum(0));
+ Assert.assertEquals(ImportEnum.IMPORT_BAR, message.getRepeatedImportEnum(0));
+
+ Assert.assertEquals("224", message.getRepeatedStringPiece(0));
+ Assert.assertEquals("225", message.getRepeatedCord(0));
+
+ Assert.assertEquals(301 , message.getRepeatedInt32 (1));
+ Assert.assertEquals(302 , message.getRepeatedInt64 (1));
+ Assert.assertEquals(303 , message.getRepeatedUint32 (1));
+ Assert.assertEquals(304 , message.getRepeatedUint64 (1));
+ Assert.assertEquals(305 , message.getRepeatedSint32 (1));
+ Assert.assertEquals(306 , message.getRepeatedSint64 (1));
+ Assert.assertEquals(307 , message.getRepeatedFixed32 (1));
+ Assert.assertEquals(308 , message.getRepeatedFixed64 (1));
+ Assert.assertEquals(309 , message.getRepeatedSfixed32(1));
+ Assert.assertEquals(310 , message.getRepeatedSfixed64(1));
+ Assert.assertEquals(311 , message.getRepeatedFloat (1), 0.0);
+ Assert.assertEquals(312 , message.getRepeatedDouble (1), 0.0);
+ Assert.assertEquals(false, message.getRepeatedBool (1));
+ Assert.assertEquals("315", message.getRepeatedString (1));
+ Assert.assertEquals(toBytes("316"), message.getRepeatedBytes(1));
+
+ Assert.assertEquals(317, message.getRepeatedGroup (1).getA());
+ Assert.assertEquals(318, message.getRepeatedNestedMessage (1).getBb());
+ Assert.assertEquals(319, message.getRepeatedForeignMessage(1).getC());
+ Assert.assertEquals(320, message.getRepeatedImportMessage (1).getD());
+ Assert.assertEquals(327, message.getRepeatedLazyMessage (1).getBb());
+
+ Assert.assertEquals(TestAllTypes.NestedEnum.BAZ, message.getRepeatedNestedEnum (1));
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAZ, message.getRepeatedForeignEnum(1));
+ Assert.assertEquals(ImportEnum.IMPORT_BAZ, message.getRepeatedImportEnum(1));
+
+ Assert.assertEquals("324", message.getRepeatedStringPiece(1));
+ Assert.assertEquals("325", message.getRepeatedCord(1));
+
+ // -----------------------------------------------------------------
+
+ Assert.assertTrue(message.hasDefaultInt32 ());
+ Assert.assertTrue(message.hasDefaultInt64 ());
+ Assert.assertTrue(message.hasDefaultUint32 ());
+ Assert.assertTrue(message.hasDefaultUint64 ());
+ Assert.assertTrue(message.hasDefaultSint32 ());
+ Assert.assertTrue(message.hasDefaultSint64 ());
+ Assert.assertTrue(message.hasDefaultFixed32 ());
+ Assert.assertTrue(message.hasDefaultFixed64 ());
+ Assert.assertTrue(message.hasDefaultSfixed32());
+ Assert.assertTrue(message.hasDefaultSfixed64());
+ Assert.assertTrue(message.hasDefaultFloat ());
+ Assert.assertTrue(message.hasDefaultDouble ());
+ Assert.assertTrue(message.hasDefaultBool ());
+ Assert.assertTrue(message.hasDefaultString ());
+ Assert.assertTrue(message.hasDefaultBytes ());
+
+ Assert.assertTrue(message.hasDefaultNestedEnum ());
+ Assert.assertTrue(message.hasDefaultForeignEnum());
+ Assert.assertTrue(message.hasDefaultImportEnum ());
+
+ Assert.assertTrue(message.hasDefaultStringPiece());
+ Assert.assertTrue(message.hasDefaultCord());
+
+ Assert.assertEquals(401 , message.getDefaultInt32 ());
+ Assert.assertEquals(402 , message.getDefaultInt64 ());
+ Assert.assertEquals(403 , message.getDefaultUint32 ());
+ Assert.assertEquals(404 , message.getDefaultUint64 ());
+ Assert.assertEquals(405 , message.getDefaultSint32 ());
+ Assert.assertEquals(406 , message.getDefaultSint64 ());
+ Assert.assertEquals(407 , message.getDefaultFixed32 ());
+ Assert.assertEquals(408 , message.getDefaultFixed64 ());
+ Assert.assertEquals(409 , message.getDefaultSfixed32());
+ Assert.assertEquals(410 , message.getDefaultSfixed64());
+ Assert.assertEquals(411 , message.getDefaultFloat (), 0.0);
+ Assert.assertEquals(412 , message.getDefaultDouble (), 0.0);
+ Assert.assertEquals(false, message.getDefaultBool ());
+ Assert.assertEquals("415", message.getDefaultString ());
+ Assert.assertEquals(toBytes("416"), message.getDefaultBytes());
+
+ Assert.assertEquals(TestAllTypes.NestedEnum.FOO, message.getDefaultNestedEnum ());
+ Assert.assertEquals(ForeignEnum.FOREIGN_FOO, message.getDefaultForeignEnum());
+ Assert.assertEquals(ImportEnum.IMPORT_FOO, message.getDefaultImportEnum());
+
+ Assert.assertEquals("424", message.getDefaultStringPiece());
+ Assert.assertEquals("425", message.getDefaultCord());
+ }
+
+ // -------------------------------------------------------------------
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all fields of
+ * {@code message} are cleared, and that getting the fields returns their
+ * default values.
+ */
+ public static void assertClear(TestAllTypesOrBuilder message) {
+ // hasBlah() should initially be false for all optional fields.
+ Assert.assertFalse(message.hasOptionalInt32 ());
+ Assert.assertFalse(message.hasOptionalInt64 ());
+ Assert.assertFalse(message.hasOptionalUint32 ());
+ Assert.assertFalse(message.hasOptionalUint64 ());
+ Assert.assertFalse(message.hasOptionalSint32 ());
+ Assert.assertFalse(message.hasOptionalSint64 ());
+ Assert.assertFalse(message.hasOptionalFixed32 ());
+ Assert.assertFalse(message.hasOptionalFixed64 ());
+ Assert.assertFalse(message.hasOptionalSfixed32());
+ Assert.assertFalse(message.hasOptionalSfixed64());
+ Assert.assertFalse(message.hasOptionalFloat ());
+ Assert.assertFalse(message.hasOptionalDouble ());
+ Assert.assertFalse(message.hasOptionalBool ());
+ Assert.assertFalse(message.hasOptionalString ());
+ Assert.assertFalse(message.hasOptionalBytes ());
+
+ Assert.assertFalse(message.hasOptionalGroup ());
+ Assert.assertFalse(message.hasOptionalNestedMessage ());
+ Assert.assertFalse(message.hasOptionalForeignMessage());
+ Assert.assertFalse(message.hasOptionalImportMessage ());
+
+ Assert.assertFalse(message.hasOptionalNestedEnum ());
+ Assert.assertFalse(message.hasOptionalForeignEnum());
+ Assert.assertFalse(message.hasOptionalImportEnum ());
+
+ Assert.assertFalse(message.hasOptionalStringPiece());
+ Assert.assertFalse(message.hasOptionalCord());
+
+ // Optional fields without defaults are set to zero or something like it.
+ Assert.assertEquals(0 , message.getOptionalInt32 ());
+ Assert.assertEquals(0 , message.getOptionalInt64 ());
+ Assert.assertEquals(0 , message.getOptionalUint32 ());
+ Assert.assertEquals(0 , message.getOptionalUint64 ());
+ Assert.assertEquals(0 , message.getOptionalSint32 ());
+ Assert.assertEquals(0 , message.getOptionalSint64 ());
+ Assert.assertEquals(0 , message.getOptionalFixed32 ());
+ Assert.assertEquals(0 , message.getOptionalFixed64 ());
+ Assert.assertEquals(0 , message.getOptionalSfixed32());
+ Assert.assertEquals(0 , message.getOptionalSfixed64());
+ Assert.assertEquals(0 , message.getOptionalFloat (), 0.0);
+ Assert.assertEquals(0 , message.getOptionalDouble (), 0.0);
+ Assert.assertEquals(false, message.getOptionalBool ());
+ Assert.assertEquals("" , message.getOptionalString ());
+ Assert.assertEquals(ByteString.EMPTY, message.getOptionalBytes());
+
+ // Embedded messages should also be clear.
+ Assert.assertFalse(message.getOptionalGroup ().hasA());
+ Assert.assertFalse(message.getOptionalNestedMessage ().hasBb());
+ Assert.assertFalse(message.getOptionalForeignMessage ().hasC());
+ Assert.assertFalse(message.getOptionalImportMessage ().hasD());
+ Assert.assertFalse(message.getOptionalPublicImportMessage().hasE());
+ Assert.assertFalse(message.getOptionalLazyMessage ().hasBb());
+
+ Assert.assertEquals(0, message.getOptionalGroup ().getA());
+ Assert.assertEquals(0, message.getOptionalNestedMessage ().getBb());
+ Assert.assertEquals(0, message.getOptionalForeignMessage ().getC());
+ Assert.assertEquals(0, message.getOptionalImportMessage ().getD());
+ Assert.assertEquals(0, message.getOptionalPublicImportMessage().getE());
+ Assert.assertEquals(0, message.getOptionalLazyMessage ().getBb());
+
+ // Enums without defaults are set to the first value in the enum.
+ Assert.assertEquals(TestAllTypes.NestedEnum.FOO, message.getOptionalNestedEnum ());
+ Assert.assertEquals(ForeignEnum.FOREIGN_FOO, message.getOptionalForeignEnum());
+ Assert.assertEquals(ImportEnum.IMPORT_FOO, message.getOptionalImportEnum());
+
+ Assert.assertEquals("", message.getOptionalStringPiece());
+ Assert.assertEquals("", message.getOptionalCord());
+
+ // Repeated fields are empty.
+ Assert.assertEquals(0, message.getRepeatedInt32Count ());
+ Assert.assertEquals(0, message.getRepeatedInt64Count ());
+ Assert.assertEquals(0, message.getRepeatedUint32Count ());
+ Assert.assertEquals(0, message.getRepeatedUint64Count ());
+ Assert.assertEquals(0, message.getRepeatedSint32Count ());
+ Assert.assertEquals(0, message.getRepeatedSint64Count ());
+ Assert.assertEquals(0, message.getRepeatedFixed32Count ());
+ Assert.assertEquals(0, message.getRepeatedFixed64Count ());
+ Assert.assertEquals(0, message.getRepeatedSfixed32Count());
+ Assert.assertEquals(0, message.getRepeatedSfixed64Count());
+ Assert.assertEquals(0, message.getRepeatedFloatCount ());
+ Assert.assertEquals(0, message.getRepeatedDoubleCount ());
+ Assert.assertEquals(0, message.getRepeatedBoolCount ());
+ Assert.assertEquals(0, message.getRepeatedStringCount ());
+ Assert.assertEquals(0, message.getRepeatedBytesCount ());
+
+ Assert.assertEquals(0, message.getRepeatedGroupCount ());
+ Assert.assertEquals(0, message.getRepeatedNestedMessageCount ());
+ Assert.assertEquals(0, message.getRepeatedForeignMessageCount());
+ Assert.assertEquals(0, message.getRepeatedImportMessageCount ());
+ Assert.assertEquals(0, message.getRepeatedLazyMessageCount ());
+ Assert.assertEquals(0, message.getRepeatedNestedEnumCount ());
+ Assert.assertEquals(0, message.getRepeatedForeignEnumCount ());
+ Assert.assertEquals(0, message.getRepeatedImportEnumCount ());
+
+ Assert.assertEquals(0, message.getRepeatedStringPieceCount());
+ Assert.assertEquals(0, message.getRepeatedCordCount());
+
+ // hasBlah() should also be false for all default fields.
+ Assert.assertFalse(message.hasDefaultInt32 ());
+ Assert.assertFalse(message.hasDefaultInt64 ());
+ Assert.assertFalse(message.hasDefaultUint32 ());
+ Assert.assertFalse(message.hasDefaultUint64 ());
+ Assert.assertFalse(message.hasDefaultSint32 ());
+ Assert.assertFalse(message.hasDefaultSint64 ());
+ Assert.assertFalse(message.hasDefaultFixed32 ());
+ Assert.assertFalse(message.hasDefaultFixed64 ());
+ Assert.assertFalse(message.hasDefaultSfixed32());
+ Assert.assertFalse(message.hasDefaultSfixed64());
+ Assert.assertFalse(message.hasDefaultFloat ());
+ Assert.assertFalse(message.hasDefaultDouble ());
+ Assert.assertFalse(message.hasDefaultBool ());
+ Assert.assertFalse(message.hasDefaultString ());
+ Assert.assertFalse(message.hasDefaultBytes ());
+
+ Assert.assertFalse(message.hasDefaultNestedEnum ());
+ Assert.assertFalse(message.hasDefaultForeignEnum());
+ Assert.assertFalse(message.hasDefaultImportEnum ());
+
+ Assert.assertFalse(message.hasDefaultStringPiece());
+ Assert.assertFalse(message.hasDefaultCord());
+
+ // Fields with defaults have their default values (duh).
+ Assert.assertEquals( 41 , message.getDefaultInt32 ());
+ Assert.assertEquals( 42 , message.getDefaultInt64 ());
+ Assert.assertEquals( 43 , message.getDefaultUint32 ());
+ Assert.assertEquals( 44 , message.getDefaultUint64 ());
+ Assert.assertEquals(-45 , message.getDefaultSint32 ());
+ Assert.assertEquals( 46 , message.getDefaultSint64 ());
+ Assert.assertEquals( 47 , message.getDefaultFixed32 ());
+ Assert.assertEquals( 48 , message.getDefaultFixed64 ());
+ Assert.assertEquals( 49 , message.getDefaultSfixed32());
+ Assert.assertEquals(-50 , message.getDefaultSfixed64());
+ Assert.assertEquals( 51.5 , message.getDefaultFloat (), 0.0);
+ Assert.assertEquals( 52e3 , message.getDefaultDouble (), 0.0);
+ Assert.assertEquals(true , message.getDefaultBool ());
+ Assert.assertEquals("hello", message.getDefaultString ());
+ Assert.assertEquals(toBytes("world"), message.getDefaultBytes());
+
+ Assert.assertEquals(TestAllTypes.NestedEnum.BAR, message.getDefaultNestedEnum ());
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAR, message.getDefaultForeignEnum());
+ Assert.assertEquals(ImportEnum.IMPORT_BAR, message.getDefaultImportEnum());
+
+ Assert.assertEquals("abc", message.getDefaultStringPiece());
+ Assert.assertEquals("123", message.getDefaultCord());
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all fields of
+ * {@code message} are set to the values assigned by {@code setAllFields}
+ * followed by {@code modifyRepeatedFields}.
+ */
+ public static void assertRepeatedFieldsModified(
+ TestAllTypesOrBuilder message) {
+ // ModifyRepeatedFields only sets the second repeated element of each
+ // field. In addition to verifying this, we also verify that the first
+ // element and size were *not* modified.
+ Assert.assertEquals(2, message.getRepeatedInt32Count ());
+ Assert.assertEquals(2, message.getRepeatedInt64Count ());
+ Assert.assertEquals(2, message.getRepeatedUint32Count ());
+ Assert.assertEquals(2, message.getRepeatedUint64Count ());
+ Assert.assertEquals(2, message.getRepeatedSint32Count ());
+ Assert.assertEquals(2, message.getRepeatedSint64Count ());
+ Assert.assertEquals(2, message.getRepeatedFixed32Count ());
+ Assert.assertEquals(2, message.getRepeatedFixed64Count ());
+ Assert.assertEquals(2, message.getRepeatedSfixed32Count());
+ Assert.assertEquals(2, message.getRepeatedSfixed64Count());
+ Assert.assertEquals(2, message.getRepeatedFloatCount ());
+ Assert.assertEquals(2, message.getRepeatedDoubleCount ());
+ Assert.assertEquals(2, message.getRepeatedBoolCount ());
+ Assert.assertEquals(2, message.getRepeatedStringCount ());
+ Assert.assertEquals(2, message.getRepeatedBytesCount ());
+
+ Assert.assertEquals(2, message.getRepeatedGroupCount ());
+ Assert.assertEquals(2, message.getRepeatedNestedMessageCount ());
+ Assert.assertEquals(2, message.getRepeatedForeignMessageCount());
+ Assert.assertEquals(2, message.getRepeatedImportMessageCount ());
+ Assert.assertEquals(2, message.getRepeatedLazyMessageCount ());
+ Assert.assertEquals(2, message.getRepeatedNestedEnumCount ());
+ Assert.assertEquals(2, message.getRepeatedForeignEnumCount ());
+ Assert.assertEquals(2, message.getRepeatedImportEnumCount ());
+
+ Assert.assertEquals(2, message.getRepeatedStringPieceCount());
+ Assert.assertEquals(2, message.getRepeatedCordCount());
+
+ Assert.assertEquals(201 , message.getRepeatedInt32 (0));
+ Assert.assertEquals(202L , message.getRepeatedInt64 (0));
+ Assert.assertEquals(203 , message.getRepeatedUint32 (0));
+ Assert.assertEquals(204L , message.getRepeatedUint64 (0));
+ Assert.assertEquals(205 , message.getRepeatedSint32 (0));
+ Assert.assertEquals(206L , message.getRepeatedSint64 (0));
+ Assert.assertEquals(207 , message.getRepeatedFixed32 (0));
+ Assert.assertEquals(208L , message.getRepeatedFixed64 (0));
+ Assert.assertEquals(209 , message.getRepeatedSfixed32(0));
+ Assert.assertEquals(210L , message.getRepeatedSfixed64(0));
+ Assert.assertEquals(211F , message.getRepeatedFloat (0));
+ Assert.assertEquals(212D , message.getRepeatedDouble (0));
+ Assert.assertEquals(true , message.getRepeatedBool (0));
+ Assert.assertEquals("215", message.getRepeatedString (0));
+ Assert.assertEquals(toBytes("216"), message.getRepeatedBytes(0));
+
+ Assert.assertEquals(217, message.getRepeatedGroup (0).getA());
+ Assert.assertEquals(218, message.getRepeatedNestedMessage (0).getBb());
+ Assert.assertEquals(219, message.getRepeatedForeignMessage(0).getC());
+ Assert.assertEquals(220, message.getRepeatedImportMessage (0).getD());
+ Assert.assertEquals(227, message.getRepeatedLazyMessage (0).getBb());
+
+ Assert.assertEquals(TestAllTypes.NestedEnum.BAR, message.getRepeatedNestedEnum (0));
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAR, message.getRepeatedForeignEnum(0));
+ Assert.assertEquals(ImportEnum.IMPORT_BAR, message.getRepeatedImportEnum(0));
+
+ Assert.assertEquals("224", message.getRepeatedStringPiece(0));
+ Assert.assertEquals("225", message.getRepeatedCord(0));
+
+ // Actually verify the second (modified) elements now.
+ Assert.assertEquals(501 , message.getRepeatedInt32 (1));
+ Assert.assertEquals(502L , message.getRepeatedInt64 (1));
+ Assert.assertEquals(503 , message.getRepeatedUint32 (1));
+ Assert.assertEquals(504L , message.getRepeatedUint64 (1));
+ Assert.assertEquals(505 , message.getRepeatedSint32 (1));
+ Assert.assertEquals(506L , message.getRepeatedSint64 (1));
+ Assert.assertEquals(507 , message.getRepeatedFixed32 (1));
+ Assert.assertEquals(508L , message.getRepeatedFixed64 (1));
+ Assert.assertEquals(509 , message.getRepeatedSfixed32(1));
+ Assert.assertEquals(510L , message.getRepeatedSfixed64(1));
+ Assert.assertEquals(511F , message.getRepeatedFloat (1));
+ Assert.assertEquals(512D , message.getRepeatedDouble (1));
+ Assert.assertEquals(true , message.getRepeatedBool (1));
+ Assert.assertEquals("515", message.getRepeatedString (1));
+ Assert.assertEquals(toBytes("516"), message.getRepeatedBytes(1));
+
+ Assert.assertEquals(517, message.getRepeatedGroup (1).getA());
+ Assert.assertEquals(518, message.getRepeatedNestedMessage (1).getBb());
+ Assert.assertEquals(519, message.getRepeatedForeignMessage(1).getC());
+ Assert.assertEquals(520, message.getRepeatedImportMessage (1).getD());
+ Assert.assertEquals(527, message.getRepeatedLazyMessage (1).getBb());
+
+ Assert.assertEquals(TestAllTypes.NestedEnum.FOO, message.getRepeatedNestedEnum (1));
+ Assert.assertEquals(ForeignEnum.FOREIGN_FOO, message.getRepeatedForeignEnum(1));
+ Assert.assertEquals(ImportEnum.IMPORT_FOO, message.getRepeatedImportEnum(1));
+
+ Assert.assertEquals("524", message.getRepeatedStringPiece(1));
+ Assert.assertEquals("525", message.getRepeatedCord(1));
+ }
+
+ /**
+ * Set every field of {@code message} to a unique value.
+ */
+ public static void setPackedFields(TestPackedTypes.Builder message) {
+ message.addPackedInt32 (601);
+ message.addPackedInt64 (602);
+ message.addPackedUint32 (603);
+ message.addPackedUint64 (604);
+ message.addPackedSint32 (605);
+ message.addPackedSint64 (606);
+ message.addPackedFixed32 (607);
+ message.addPackedFixed64 (608);
+ message.addPackedSfixed32(609);
+ message.addPackedSfixed64(610);
+ message.addPackedFloat (611);
+ message.addPackedDouble (612);
+ message.addPackedBool (true);
+ message.addPackedEnum (ForeignEnum.FOREIGN_BAR);
+ // Add a second one of each field.
+ message.addPackedInt32 (701);
+ message.addPackedInt64 (702);
+ message.addPackedUint32 (703);
+ message.addPackedUint64 (704);
+ message.addPackedSint32 (705);
+ message.addPackedSint64 (706);
+ message.addPackedFixed32 (707);
+ message.addPackedFixed64 (708);
+ message.addPackedSfixed32(709);
+ message.addPackedSfixed64(710);
+ message.addPackedFloat (711);
+ message.addPackedDouble (712);
+ message.addPackedBool (false);
+ message.addPackedEnum (ForeignEnum.FOREIGN_BAZ);
+ }
+
+ /**
+ * Set every field of {@code message} to a unique value. Must correspond with
+ * the values applied by {@code setPackedFields}.
+ */
+ public static void setUnpackedFields(TestUnpackedTypes.Builder message) {
+ message.addUnpackedInt32 (601);
+ message.addUnpackedInt64 (602);
+ message.addUnpackedUint32 (603);
+ message.addUnpackedUint64 (604);
+ message.addUnpackedSint32 (605);
+ message.addUnpackedSint64 (606);
+ message.addUnpackedFixed32 (607);
+ message.addUnpackedFixed64 (608);
+ message.addUnpackedSfixed32(609);
+ message.addUnpackedSfixed64(610);
+ message.addUnpackedFloat (611);
+ message.addUnpackedDouble (612);
+ message.addUnpackedBool (true);
+ message.addUnpackedEnum (ForeignEnum.FOREIGN_BAR);
+ // Add a second one of each field.
+ message.addUnpackedInt32 (701);
+ message.addUnpackedInt64 (702);
+ message.addUnpackedUint32 (703);
+ message.addUnpackedUint64 (704);
+ message.addUnpackedSint32 (705);
+ message.addUnpackedSint64 (706);
+ message.addUnpackedFixed32 (707);
+ message.addUnpackedFixed64 (708);
+ message.addUnpackedSfixed32(709);
+ message.addUnpackedSfixed64(710);
+ message.addUnpackedFloat (711);
+ message.addUnpackedDouble (712);
+ message.addUnpackedBool (false);
+ message.addUnpackedEnum (ForeignEnum.FOREIGN_BAZ);
+ }
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all fields of
+ * {@code message} are set to the values assigned by {@code setPackedFields}.
+ */
+ public static void assertPackedFieldsSet(TestPackedTypes message) {
+ Assert.assertEquals(2, message.getPackedInt32Count ());
+ Assert.assertEquals(2, message.getPackedInt64Count ());
+ Assert.assertEquals(2, message.getPackedUint32Count ());
+ Assert.assertEquals(2, message.getPackedUint64Count ());
+ Assert.assertEquals(2, message.getPackedSint32Count ());
+ Assert.assertEquals(2, message.getPackedSint64Count ());
+ Assert.assertEquals(2, message.getPackedFixed32Count ());
+ Assert.assertEquals(2, message.getPackedFixed64Count ());
+ Assert.assertEquals(2, message.getPackedSfixed32Count());
+ Assert.assertEquals(2, message.getPackedSfixed64Count());
+ Assert.assertEquals(2, message.getPackedFloatCount ());
+ Assert.assertEquals(2, message.getPackedDoubleCount ());
+ Assert.assertEquals(2, message.getPackedBoolCount ());
+ Assert.assertEquals(2, message.getPackedEnumCount ());
+ Assert.assertEquals(601 , message.getPackedInt32 (0));
+ Assert.assertEquals(602 , message.getPackedInt64 (0));
+ Assert.assertEquals(603 , message.getPackedUint32 (0));
+ Assert.assertEquals(604 , message.getPackedUint64 (0));
+ Assert.assertEquals(605 , message.getPackedSint32 (0));
+ Assert.assertEquals(606 , message.getPackedSint64 (0));
+ Assert.assertEquals(607 , message.getPackedFixed32 (0));
+ Assert.assertEquals(608 , message.getPackedFixed64 (0));
+ Assert.assertEquals(609 , message.getPackedSfixed32(0));
+ Assert.assertEquals(610 , message.getPackedSfixed64(0));
+ Assert.assertEquals(611 , message.getPackedFloat (0), 0.0);
+ Assert.assertEquals(612 , message.getPackedDouble (0), 0.0);
+ Assert.assertEquals(true , message.getPackedBool (0));
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAR, message.getPackedEnum(0));
+ Assert.assertEquals(701 , message.getPackedInt32 (1));
+ Assert.assertEquals(702 , message.getPackedInt64 (1));
+ Assert.assertEquals(703 , message.getPackedUint32 (1));
+ Assert.assertEquals(704 , message.getPackedUint64 (1));
+ Assert.assertEquals(705 , message.getPackedSint32 (1));
+ Assert.assertEquals(706 , message.getPackedSint64 (1));
+ Assert.assertEquals(707 , message.getPackedFixed32 (1));
+ Assert.assertEquals(708 , message.getPackedFixed64 (1));
+ Assert.assertEquals(709 , message.getPackedSfixed32(1));
+ Assert.assertEquals(710 , message.getPackedSfixed64(1));
+ Assert.assertEquals(711 , message.getPackedFloat (1), 0.0);
+ Assert.assertEquals(712 , message.getPackedDouble (1), 0.0);
+ Assert.assertEquals(false, message.getPackedBool (1));
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAZ, message.getPackedEnum(1));
+ }
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all fields of
+ * {@code message} are set to the values assigned by {@code setUnpackedFields}.
+ */
+ public static void assertUnpackedFieldsSet(TestUnpackedTypes message) {
+ Assert.assertEquals(2, message.getUnpackedInt32Count ());
+ Assert.assertEquals(2, message.getUnpackedInt64Count ());
+ Assert.assertEquals(2, message.getUnpackedUint32Count ());
+ Assert.assertEquals(2, message.getUnpackedUint64Count ());
+ Assert.assertEquals(2, message.getUnpackedSint32Count ());
+ Assert.assertEquals(2, message.getUnpackedSint64Count ());
+ Assert.assertEquals(2, message.getUnpackedFixed32Count ());
+ Assert.assertEquals(2, message.getUnpackedFixed64Count ());
+ Assert.assertEquals(2, message.getUnpackedSfixed32Count());
+ Assert.assertEquals(2, message.getUnpackedSfixed64Count());
+ Assert.assertEquals(2, message.getUnpackedFloatCount ());
+ Assert.assertEquals(2, message.getUnpackedDoubleCount ());
+ Assert.assertEquals(2, message.getUnpackedBoolCount ());
+ Assert.assertEquals(2, message.getUnpackedEnumCount ());
+ Assert.assertEquals(601 , message.getUnpackedInt32 (0));
+ Assert.assertEquals(602 , message.getUnpackedInt64 (0));
+ Assert.assertEquals(603 , message.getUnpackedUint32 (0));
+ Assert.assertEquals(604 , message.getUnpackedUint64 (0));
+ Assert.assertEquals(605 , message.getUnpackedSint32 (0));
+ Assert.assertEquals(606 , message.getUnpackedSint64 (0));
+ Assert.assertEquals(607 , message.getUnpackedFixed32 (0));
+ Assert.assertEquals(608 , message.getUnpackedFixed64 (0));
+ Assert.assertEquals(609 , message.getUnpackedSfixed32(0));
+ Assert.assertEquals(610 , message.getUnpackedSfixed64(0));
+ Assert.assertEquals(611 , message.getUnpackedFloat (0), 0.0);
+ Assert.assertEquals(612 , message.getUnpackedDouble (0), 0.0);
+ Assert.assertEquals(true , message.getUnpackedBool (0));
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAR, message.getUnpackedEnum(0));
+ Assert.assertEquals(701 , message.getUnpackedInt32 (1));
+ Assert.assertEquals(702 , message.getUnpackedInt64 (1));
+ Assert.assertEquals(703 , message.getUnpackedUint32 (1));
+ Assert.assertEquals(704 , message.getUnpackedUint64 (1));
+ Assert.assertEquals(705 , message.getUnpackedSint32 (1));
+ Assert.assertEquals(706 , message.getUnpackedSint64 (1));
+ Assert.assertEquals(707 , message.getUnpackedFixed32 (1));
+ Assert.assertEquals(708 , message.getUnpackedFixed64 (1));
+ Assert.assertEquals(709 , message.getUnpackedSfixed32(1));
+ Assert.assertEquals(710 , message.getUnpackedSfixed64(1));
+ Assert.assertEquals(711 , message.getUnpackedFloat (1), 0.0);
+ Assert.assertEquals(712 , message.getUnpackedDouble (1), 0.0);
+ Assert.assertEquals(false, message.getUnpackedBool (1));
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAZ, message.getUnpackedEnum(1));
+ }
+
+ // ===================================================================
+ // Like above, but for extensions
+
+ // Java gets confused with things like assertEquals(int, Integer): it can't
+ // decide whether to call assertEquals(int, int) or assertEquals(Object,
+ // Object). So we define these methods to help it.
+ private static void assertEqualsExactType(int a, int b) {
+ Assert.assertEquals(a, b);
+ }
+ private static void assertEqualsExactType(long a, long b) {
+ Assert.assertEquals(a, b);
+ }
+ private static void assertEqualsExactType(float a, float b) {
+ Assert.assertEquals(a, b, 0.0);
+ }
+ private static void assertEqualsExactType(double a, double b) {
+ Assert.assertEquals(a, b, 0.0);
+ }
+ private static void assertEqualsExactType(boolean a, boolean b) {
+ Assert.assertEquals(a, b);
+ }
+ private static void assertEqualsExactType(String a, String b) {
+ Assert.assertEquals(a, b);
+ }
+ private static void assertEqualsExactType(ByteString a, ByteString b) {
+ Assert.assertEquals(a, b);
+ }
+ private static void assertEqualsExactType(TestAllTypes.NestedEnum a,
+ TestAllTypes.NestedEnum b) {
+ Assert.assertEquals(a, b);
+ }
+ private static void assertEqualsExactType(ForeignEnum a, ForeignEnum b) {
+ Assert.assertEquals(a, b);
+ }
+ private static void assertEqualsExactType(ImportEnum a, ImportEnum b) {
+ Assert.assertEquals(a, b);
+ }
+ /**
+ * Get an unmodifiable {@link ExtensionRegistry} containing all the
+ * extensions of {@code TestAllExtensions}.
+ */
+ public static ExtensionRegistry getExtensionRegistry() {
+ ExtensionRegistry registry = ExtensionRegistry.newInstance();
+ registerAllExtensions(registry);
+ return registry.getUnmodifiable();
+ }
+
+
+ /**
+ * Register all of {@code TestAllExtensions}'s extensions with the
+ * given {@link ExtensionRegistry}.
+ */
+ public static void registerAllExtensions(ExtensionRegistry registry) {
+ UnittestProto.registerAllExtensions(registry);
+ }
+
+
+ /**
+ * Set every field of {@code message} to the values expected by
+ * {@code assertAllExtensionsSet()}.
+ */
+ public static void setAllExtensions(TestAllExtensions.Builder message) {
+ message.setExtension(optionalInt32Extension , 101);
+ message.setExtension(optionalInt64Extension , 102L);
+ message.setExtension(optionalUint32Extension , 103);
+ message.setExtension(optionalUint64Extension , 104L);
+ message.setExtension(optionalSint32Extension , 105);
+ message.setExtension(optionalSint64Extension , 106L);
+ message.setExtension(optionalFixed32Extension , 107);
+ message.setExtension(optionalFixed64Extension , 108L);
+ message.setExtension(optionalSfixed32Extension, 109);
+ message.setExtension(optionalSfixed64Extension, 110L);
+ message.setExtension(optionalFloatExtension , 111F);
+ message.setExtension(optionalDoubleExtension , 112D);
+ message.setExtension(optionalBoolExtension , true);
+ message.setExtension(optionalStringExtension , "115");
+ message.setExtension(optionalBytesExtension , toBytes("116"));
+
+ message.setExtension(optionalGroupExtension,
+ OptionalGroup_extension.newBuilder().setA(117).build());
+ message.setExtension(optionalNestedMessageExtension,
+ TestAllTypes.NestedMessage.newBuilder().setBb(118).build());
+ message.setExtension(optionalForeignMessageExtension,
+ ForeignMessage.newBuilder().setC(119).build());
+ message.setExtension(optionalImportMessageExtension,
+ ImportMessage.newBuilder().setD(120).build());
+ message.setExtension(optionalPublicImportMessageExtension,
+ PublicImportMessage.newBuilder().setE(126).build());
+ message.setExtension(optionalLazyMessageExtension,
+ TestAllTypes.NestedMessage.newBuilder().setBb(127).build());
+
+ message.setExtension(optionalNestedEnumExtension, TestAllTypes.NestedEnum.BAZ);
+ message.setExtension(optionalForeignEnumExtension, ForeignEnum.FOREIGN_BAZ);
+ message.setExtension(optionalImportEnumExtension, ImportEnum.IMPORT_BAZ);
+
+ message.setExtension(optionalStringPieceExtension, "124");
+ message.setExtension(optionalCordExtension, "125");
+
+ // -----------------------------------------------------------------
+
+ message.addExtension(repeatedInt32Extension , 201);
+ message.addExtension(repeatedInt64Extension , 202L);
+ message.addExtension(repeatedUint32Extension , 203);
+ message.addExtension(repeatedUint64Extension , 204L);
+ message.addExtension(repeatedSint32Extension , 205);
+ message.addExtension(repeatedSint64Extension , 206L);
+ message.addExtension(repeatedFixed32Extension , 207);
+ message.addExtension(repeatedFixed64Extension , 208L);
+ message.addExtension(repeatedSfixed32Extension, 209);
+ message.addExtension(repeatedSfixed64Extension, 210L);
+ message.addExtension(repeatedFloatExtension , 211F);
+ message.addExtension(repeatedDoubleExtension , 212D);
+ message.addExtension(repeatedBoolExtension , true);
+ message.addExtension(repeatedStringExtension , "215");
+ message.addExtension(repeatedBytesExtension , toBytes("216"));
+
+ message.addExtension(repeatedGroupExtension,
+ RepeatedGroup_extension.newBuilder().setA(217).build());
+ message.addExtension(repeatedNestedMessageExtension,
+ TestAllTypes.NestedMessage.newBuilder().setBb(218).build());
+ message.addExtension(repeatedForeignMessageExtension,
+ ForeignMessage.newBuilder().setC(219).build());
+ message.addExtension(repeatedImportMessageExtension,
+ ImportMessage.newBuilder().setD(220).build());
+ message.addExtension(repeatedLazyMessageExtension,
+ TestAllTypes.NestedMessage.newBuilder().setBb(227).build());
+
+ message.addExtension(repeatedNestedEnumExtension, TestAllTypes.NestedEnum.BAR);
+ message.addExtension(repeatedForeignEnumExtension, ForeignEnum.FOREIGN_BAR);
+ message.addExtension(repeatedImportEnumExtension, ImportEnum.IMPORT_BAR);
+
+ message.addExtension(repeatedStringPieceExtension, "224");
+ message.addExtension(repeatedCordExtension, "225");
+
+ // Add a second one of each field.
+ message.addExtension(repeatedInt32Extension , 301);
+ message.addExtension(repeatedInt64Extension , 302L);
+ message.addExtension(repeatedUint32Extension , 303);
+ message.addExtension(repeatedUint64Extension , 304L);
+ message.addExtension(repeatedSint32Extension , 305);
+ message.addExtension(repeatedSint64Extension , 306L);
+ message.addExtension(repeatedFixed32Extension , 307);
+ message.addExtension(repeatedFixed64Extension , 308L);
+ message.addExtension(repeatedSfixed32Extension, 309);
+ message.addExtension(repeatedSfixed64Extension, 310L);
+ message.addExtension(repeatedFloatExtension , 311F);
+ message.addExtension(repeatedDoubleExtension , 312D);
+ message.addExtension(repeatedBoolExtension , false);
+ message.addExtension(repeatedStringExtension , "315");
+ message.addExtension(repeatedBytesExtension , toBytes("316"));
+
+ message.addExtension(repeatedGroupExtension,
+ RepeatedGroup_extension.newBuilder().setA(317).build());
+ message.addExtension(repeatedNestedMessageExtension,
+ TestAllTypes.NestedMessage.newBuilder().setBb(318).build());
+ message.addExtension(repeatedForeignMessageExtension,
+ ForeignMessage.newBuilder().setC(319).build());
+ message.addExtension(repeatedImportMessageExtension,
+ ImportMessage.newBuilder().setD(320).build());
+ message.addExtension(repeatedLazyMessageExtension,
+ TestAllTypes.NestedMessage.newBuilder().setBb(327).build());
+
+ message.addExtension(repeatedNestedEnumExtension, TestAllTypes.NestedEnum.BAZ);
+ message.addExtension(repeatedForeignEnumExtension, ForeignEnum.FOREIGN_BAZ);
+ message.addExtension(repeatedImportEnumExtension, ImportEnum.IMPORT_BAZ);
+
+ message.addExtension(repeatedStringPieceExtension, "324");
+ message.addExtension(repeatedCordExtension, "325");
+
+ // -----------------------------------------------------------------
+
+ message.setExtension(defaultInt32Extension , 401);
+ message.setExtension(defaultInt64Extension , 402L);
+ message.setExtension(defaultUint32Extension , 403);
+ message.setExtension(defaultUint64Extension , 404L);
+ message.setExtension(defaultSint32Extension , 405);
+ message.setExtension(defaultSint64Extension , 406L);
+ message.setExtension(defaultFixed32Extension , 407);
+ message.setExtension(defaultFixed64Extension , 408L);
+ message.setExtension(defaultSfixed32Extension, 409);
+ message.setExtension(defaultSfixed64Extension, 410L);
+ message.setExtension(defaultFloatExtension , 411F);
+ message.setExtension(defaultDoubleExtension , 412D);
+ message.setExtension(defaultBoolExtension , false);
+ message.setExtension(defaultStringExtension , "415");
+ message.setExtension(defaultBytesExtension , toBytes("416"));
+
+ message.setExtension(defaultNestedEnumExtension, TestAllTypes.NestedEnum.FOO);
+ message.setExtension(defaultForeignEnumExtension, ForeignEnum.FOREIGN_FOO);
+ message.setExtension(defaultImportEnumExtension, ImportEnum.IMPORT_FOO);
+
+ message.setExtension(defaultStringPieceExtension, "424");
+ message.setExtension(defaultCordExtension, "425");
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Modify the repeated extensions of {@code message} to contain the values
+ * expected by {@code assertRepeatedExtensionsModified()}.
+ */
+ public static void modifyRepeatedExtensions(
+ TestAllExtensions.Builder message) {
+ message.setExtension(repeatedInt32Extension , 1, 501);
+ message.setExtension(repeatedInt64Extension , 1, 502L);
+ message.setExtension(repeatedUint32Extension , 1, 503);
+ message.setExtension(repeatedUint64Extension , 1, 504L);
+ message.setExtension(repeatedSint32Extension , 1, 505);
+ message.setExtension(repeatedSint64Extension , 1, 506L);
+ message.setExtension(repeatedFixed32Extension , 1, 507);
+ message.setExtension(repeatedFixed64Extension , 1, 508L);
+ message.setExtension(repeatedSfixed32Extension, 1, 509);
+ message.setExtension(repeatedSfixed64Extension, 1, 510L);
+ message.setExtension(repeatedFloatExtension , 1, 511F);
+ message.setExtension(repeatedDoubleExtension , 1, 512D);
+ message.setExtension(repeatedBoolExtension , 1, true);
+ message.setExtension(repeatedStringExtension , 1, "515");
+ message.setExtension(repeatedBytesExtension , 1, toBytes("516"));
+
+ message.setExtension(repeatedGroupExtension, 1,
+ RepeatedGroup_extension.newBuilder().setA(517).build());
+ message.setExtension(repeatedNestedMessageExtension, 1,
+ TestAllTypes.NestedMessage.newBuilder().setBb(518).build());
+ message.setExtension(repeatedForeignMessageExtension, 1,
+ ForeignMessage.newBuilder().setC(519).build());
+ message.setExtension(repeatedImportMessageExtension, 1,
+ ImportMessage.newBuilder().setD(520).build());
+ message.setExtension(repeatedLazyMessageExtension, 1,
+ TestAllTypes.NestedMessage.newBuilder().setBb(527).build());
+
+ message.setExtension(repeatedNestedEnumExtension , 1, TestAllTypes.NestedEnum.FOO);
+ message.setExtension(repeatedForeignEnumExtension, 1, ForeignEnum.FOREIGN_FOO);
+ message.setExtension(repeatedImportEnumExtension , 1, ImportEnum.IMPORT_FOO);
+
+ message.setExtension(repeatedStringPieceExtension, 1, "524");
+ message.setExtension(repeatedCordExtension, 1, "525");
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all extensions of
+ * {@code message} are set to the values assigned by {@code setAllExtensions}.
+ */
+ public static void assertAllExtensionsSet(
+ TestAllExtensionsOrBuilder message) {
+ Assert.assertTrue(message.hasExtension(optionalInt32Extension ));
+ Assert.assertTrue(message.hasExtension(optionalInt64Extension ));
+ Assert.assertTrue(message.hasExtension(optionalUint32Extension ));
+ Assert.assertTrue(message.hasExtension(optionalUint64Extension ));
+ Assert.assertTrue(message.hasExtension(optionalSint32Extension ));
+ Assert.assertTrue(message.hasExtension(optionalSint64Extension ));
+ Assert.assertTrue(message.hasExtension(optionalFixed32Extension ));
+ Assert.assertTrue(message.hasExtension(optionalFixed64Extension ));
+ Assert.assertTrue(message.hasExtension(optionalSfixed32Extension));
+ Assert.assertTrue(message.hasExtension(optionalSfixed64Extension));
+ Assert.assertTrue(message.hasExtension(optionalFloatExtension ));
+ Assert.assertTrue(message.hasExtension(optionalDoubleExtension ));
+ Assert.assertTrue(message.hasExtension(optionalBoolExtension ));
+ Assert.assertTrue(message.hasExtension(optionalStringExtension ));
+ Assert.assertTrue(message.hasExtension(optionalBytesExtension ));
+
+ Assert.assertTrue(message.hasExtension(optionalGroupExtension ));
+ Assert.assertTrue(message.hasExtension(optionalNestedMessageExtension ));
+ Assert.assertTrue(message.hasExtension(optionalForeignMessageExtension));
+ Assert.assertTrue(message.hasExtension(optionalImportMessageExtension ));
+
+ Assert.assertTrue(message.getExtension(optionalGroupExtension ).hasA());
+ Assert.assertTrue(message.getExtension(optionalNestedMessageExtension ).hasBb());
+ Assert.assertTrue(message.getExtension(optionalForeignMessageExtension).hasC());
+ Assert.assertTrue(message.getExtension(optionalImportMessageExtension ).hasD());
+
+ Assert.assertTrue(message.hasExtension(optionalNestedEnumExtension ));
+ Assert.assertTrue(message.hasExtension(optionalForeignEnumExtension));
+ Assert.assertTrue(message.hasExtension(optionalImportEnumExtension ));
+
+ Assert.assertTrue(message.hasExtension(optionalStringPieceExtension));
+ Assert.assertTrue(message.hasExtension(optionalCordExtension));
+
+ assertEqualsExactType(101 , message.getExtension(optionalInt32Extension ));
+ assertEqualsExactType(102L , message.getExtension(optionalInt64Extension ));
+ assertEqualsExactType(103 , message.getExtension(optionalUint32Extension ));
+ assertEqualsExactType(104L , message.getExtension(optionalUint64Extension ));
+ assertEqualsExactType(105 , message.getExtension(optionalSint32Extension ));
+ assertEqualsExactType(106L , message.getExtension(optionalSint64Extension ));
+ assertEqualsExactType(107 , message.getExtension(optionalFixed32Extension ));
+ assertEqualsExactType(108L , message.getExtension(optionalFixed64Extension ));
+ assertEqualsExactType(109 , message.getExtension(optionalSfixed32Extension));
+ assertEqualsExactType(110L , message.getExtension(optionalSfixed64Extension));
+ assertEqualsExactType(111F , message.getExtension(optionalFloatExtension ));
+ assertEqualsExactType(112D , message.getExtension(optionalDoubleExtension ));
+ assertEqualsExactType(true , message.getExtension(optionalBoolExtension ));
+ assertEqualsExactType("115", message.getExtension(optionalStringExtension ));
+ assertEqualsExactType(toBytes("116"), message.getExtension(optionalBytesExtension));
+
+ assertEqualsExactType(117, message.getExtension(optionalGroupExtension ).getA());
+ assertEqualsExactType(118, message.getExtension(optionalNestedMessageExtension ).getBb());
+ assertEqualsExactType(119, message.getExtension(optionalForeignMessageExtension ).getC());
+ assertEqualsExactType(120, message.getExtension(optionalImportMessageExtension ).getD());
+ assertEqualsExactType(126, message.getExtension(optionalPublicImportMessageExtension).getE());
+ assertEqualsExactType(127, message.getExtension(optionalLazyMessageExtension ).getBb());
+
+ assertEqualsExactType(TestAllTypes.NestedEnum.BAZ,
+ message.getExtension(optionalNestedEnumExtension));
+ assertEqualsExactType(ForeignEnum.FOREIGN_BAZ,
+ message.getExtension(optionalForeignEnumExtension));
+ assertEqualsExactType(ImportEnum.IMPORT_BAZ,
+ message.getExtension(optionalImportEnumExtension));
+
+ assertEqualsExactType("124", message.getExtension(optionalStringPieceExtension));
+ assertEqualsExactType("125", message.getExtension(optionalCordExtension));
+
+ // -----------------------------------------------------------------
+
+ Assert.assertEquals(2, message.getExtensionCount(repeatedInt32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedInt64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedUint32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedUint64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSint32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSint64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFixed32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFixed64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSfixed32Extension));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSfixed64Extension));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFloatExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedDoubleExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedBoolExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedStringExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedBytesExtension ));
+
+ Assert.assertEquals(2, message.getExtensionCount(repeatedGroupExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedNestedMessageExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedForeignMessageExtension));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedImportMessageExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedLazyMessageExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedNestedEnumExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedForeignEnumExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedImportEnumExtension ));
+
+ Assert.assertEquals(2, message.getExtensionCount(repeatedStringPieceExtension));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedCordExtension));
+
+ assertEqualsExactType(201 , message.getExtension(repeatedInt32Extension , 0));
+ assertEqualsExactType(202L , message.getExtension(repeatedInt64Extension , 0));
+ assertEqualsExactType(203 , message.getExtension(repeatedUint32Extension , 0));
+ assertEqualsExactType(204L , message.getExtension(repeatedUint64Extension , 0));
+ assertEqualsExactType(205 , message.getExtension(repeatedSint32Extension , 0));
+ assertEqualsExactType(206L , message.getExtension(repeatedSint64Extension , 0));
+ assertEqualsExactType(207 , message.getExtension(repeatedFixed32Extension , 0));
+ assertEqualsExactType(208L , message.getExtension(repeatedFixed64Extension , 0));
+ assertEqualsExactType(209 , message.getExtension(repeatedSfixed32Extension, 0));
+ assertEqualsExactType(210L , message.getExtension(repeatedSfixed64Extension, 0));
+ assertEqualsExactType(211F , message.getExtension(repeatedFloatExtension , 0));
+ assertEqualsExactType(212D , message.getExtension(repeatedDoubleExtension , 0));
+ assertEqualsExactType(true , message.getExtension(repeatedBoolExtension , 0));
+ assertEqualsExactType("215", message.getExtension(repeatedStringExtension , 0));
+ assertEqualsExactType(toBytes("216"), message.getExtension(repeatedBytesExtension, 0));
+
+ assertEqualsExactType(217, message.getExtension(repeatedGroupExtension , 0).getA());
+ assertEqualsExactType(218, message.getExtension(repeatedNestedMessageExtension , 0).getBb());
+ assertEqualsExactType(219, message.getExtension(repeatedForeignMessageExtension, 0).getC());
+ assertEqualsExactType(220, message.getExtension(repeatedImportMessageExtension , 0).getD());
+ assertEqualsExactType(227, message.getExtension(repeatedLazyMessageExtension , 0).getBb());
+
+ assertEqualsExactType(TestAllTypes.NestedEnum.BAR,
+ message.getExtension(repeatedNestedEnumExtension, 0));
+ assertEqualsExactType(ForeignEnum.FOREIGN_BAR,
+ message.getExtension(repeatedForeignEnumExtension, 0));
+ assertEqualsExactType(ImportEnum.IMPORT_BAR,
+ message.getExtension(repeatedImportEnumExtension, 0));
+
+ assertEqualsExactType("224", message.getExtension(repeatedStringPieceExtension, 0));
+ assertEqualsExactType("225", message.getExtension(repeatedCordExtension, 0));
+
+ assertEqualsExactType(301 , message.getExtension(repeatedInt32Extension , 1));
+ assertEqualsExactType(302L , message.getExtension(repeatedInt64Extension , 1));
+ assertEqualsExactType(303 , message.getExtension(repeatedUint32Extension , 1));
+ assertEqualsExactType(304L , message.getExtension(repeatedUint64Extension , 1));
+ assertEqualsExactType(305 , message.getExtension(repeatedSint32Extension , 1));
+ assertEqualsExactType(306L , message.getExtension(repeatedSint64Extension , 1));
+ assertEqualsExactType(307 , message.getExtension(repeatedFixed32Extension , 1));
+ assertEqualsExactType(308L , message.getExtension(repeatedFixed64Extension , 1));
+ assertEqualsExactType(309 , message.getExtension(repeatedSfixed32Extension, 1));
+ assertEqualsExactType(310L , message.getExtension(repeatedSfixed64Extension, 1));
+ assertEqualsExactType(311F , message.getExtension(repeatedFloatExtension , 1));
+ assertEqualsExactType(312D , message.getExtension(repeatedDoubleExtension , 1));
+ assertEqualsExactType(false, message.getExtension(repeatedBoolExtension , 1));
+ assertEqualsExactType("315", message.getExtension(repeatedStringExtension , 1));
+ assertEqualsExactType(toBytes("316"), message.getExtension(repeatedBytesExtension, 1));
+
+ assertEqualsExactType(317, message.getExtension(repeatedGroupExtension , 1).getA());
+ assertEqualsExactType(318, message.getExtension(repeatedNestedMessageExtension , 1).getBb());
+ assertEqualsExactType(319, message.getExtension(repeatedForeignMessageExtension, 1).getC());
+ assertEqualsExactType(320, message.getExtension(repeatedImportMessageExtension , 1).getD());
+ assertEqualsExactType(327, message.getExtension(repeatedLazyMessageExtension , 1).getBb());
+
+ assertEqualsExactType(TestAllTypes.NestedEnum.BAZ,
+ message.getExtension(repeatedNestedEnumExtension, 1));
+ assertEqualsExactType(ForeignEnum.FOREIGN_BAZ,
+ message.getExtension(repeatedForeignEnumExtension, 1));
+ assertEqualsExactType(ImportEnum.IMPORT_BAZ,
+ message.getExtension(repeatedImportEnumExtension, 1));
+
+ assertEqualsExactType("324", message.getExtension(repeatedStringPieceExtension, 1));
+ assertEqualsExactType("325", message.getExtension(repeatedCordExtension, 1));
+
+ // -----------------------------------------------------------------
+
+ Assert.assertTrue(message.hasExtension(defaultInt32Extension ));
+ Assert.assertTrue(message.hasExtension(defaultInt64Extension ));
+ Assert.assertTrue(message.hasExtension(defaultUint32Extension ));
+ Assert.assertTrue(message.hasExtension(defaultUint64Extension ));
+ Assert.assertTrue(message.hasExtension(defaultSint32Extension ));
+ Assert.assertTrue(message.hasExtension(defaultSint64Extension ));
+ Assert.assertTrue(message.hasExtension(defaultFixed32Extension ));
+ Assert.assertTrue(message.hasExtension(defaultFixed64Extension ));
+ Assert.assertTrue(message.hasExtension(defaultSfixed32Extension));
+ Assert.assertTrue(message.hasExtension(defaultSfixed64Extension));
+ Assert.assertTrue(message.hasExtension(defaultFloatExtension ));
+ Assert.assertTrue(message.hasExtension(defaultDoubleExtension ));
+ Assert.assertTrue(message.hasExtension(defaultBoolExtension ));
+ Assert.assertTrue(message.hasExtension(defaultStringExtension ));
+ Assert.assertTrue(message.hasExtension(defaultBytesExtension ));
+
+ Assert.assertTrue(message.hasExtension(defaultNestedEnumExtension ));
+ Assert.assertTrue(message.hasExtension(defaultForeignEnumExtension));
+ Assert.assertTrue(message.hasExtension(defaultImportEnumExtension ));
+
+ Assert.assertTrue(message.hasExtension(defaultStringPieceExtension));
+ Assert.assertTrue(message.hasExtension(defaultCordExtension));
+
+ assertEqualsExactType(401 , message.getExtension(defaultInt32Extension ));
+ assertEqualsExactType(402L , message.getExtension(defaultInt64Extension ));
+ assertEqualsExactType(403 , message.getExtension(defaultUint32Extension ));
+ assertEqualsExactType(404L , message.getExtension(defaultUint64Extension ));
+ assertEqualsExactType(405 , message.getExtension(defaultSint32Extension ));
+ assertEqualsExactType(406L , message.getExtension(defaultSint64Extension ));
+ assertEqualsExactType(407 , message.getExtension(defaultFixed32Extension ));
+ assertEqualsExactType(408L , message.getExtension(defaultFixed64Extension ));
+ assertEqualsExactType(409 , message.getExtension(defaultSfixed32Extension));
+ assertEqualsExactType(410L , message.getExtension(defaultSfixed64Extension));
+ assertEqualsExactType(411F , message.getExtension(defaultFloatExtension ));
+ assertEqualsExactType(412D , message.getExtension(defaultDoubleExtension ));
+ assertEqualsExactType(false, message.getExtension(defaultBoolExtension ));
+ assertEqualsExactType("415", message.getExtension(defaultStringExtension ));
+ assertEqualsExactType(toBytes("416"), message.getExtension(defaultBytesExtension));
+
+ assertEqualsExactType(TestAllTypes.NestedEnum.FOO,
+ message.getExtension(defaultNestedEnumExtension ));
+ assertEqualsExactType(ForeignEnum.FOREIGN_FOO,
+ message.getExtension(defaultForeignEnumExtension));
+ assertEqualsExactType(ImportEnum.IMPORT_FOO,
+ message.getExtension(defaultImportEnumExtension));
+
+ assertEqualsExactType("424", message.getExtension(defaultStringPieceExtension));
+ assertEqualsExactType("425", message.getExtension(defaultCordExtension));
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all extensions of
+ * {@code message} are cleared, and that getting the extensions returns their
+ * default values.
+ */
+ public static void assertExtensionsClear(TestAllExtensionsOrBuilder message) {
+ // hasBlah() should initially be false for all optional fields.
+ Assert.assertFalse(message.hasExtension(optionalInt32Extension ));
+ Assert.assertFalse(message.hasExtension(optionalInt64Extension ));
+ Assert.assertFalse(message.hasExtension(optionalUint32Extension ));
+ Assert.assertFalse(message.hasExtension(optionalUint64Extension ));
+ Assert.assertFalse(message.hasExtension(optionalSint32Extension ));
+ Assert.assertFalse(message.hasExtension(optionalSint64Extension ));
+ Assert.assertFalse(message.hasExtension(optionalFixed32Extension ));
+ Assert.assertFalse(message.hasExtension(optionalFixed64Extension ));
+ Assert.assertFalse(message.hasExtension(optionalSfixed32Extension));
+ Assert.assertFalse(message.hasExtension(optionalSfixed64Extension));
+ Assert.assertFalse(message.hasExtension(optionalFloatExtension ));
+ Assert.assertFalse(message.hasExtension(optionalDoubleExtension ));
+ Assert.assertFalse(message.hasExtension(optionalBoolExtension ));
+ Assert.assertFalse(message.hasExtension(optionalStringExtension ));
+ Assert.assertFalse(message.hasExtension(optionalBytesExtension ));
+
+ Assert.assertFalse(message.hasExtension(optionalGroupExtension ));
+ Assert.assertFalse(message.hasExtension(optionalNestedMessageExtension ));
+ Assert.assertFalse(message.hasExtension(optionalForeignMessageExtension));
+ Assert.assertFalse(message.hasExtension(optionalImportMessageExtension ));
+
+ Assert.assertFalse(message.hasExtension(optionalNestedEnumExtension ));
+ Assert.assertFalse(message.hasExtension(optionalForeignEnumExtension));
+ Assert.assertFalse(message.hasExtension(optionalImportEnumExtension ));
+
+ Assert.assertFalse(message.hasExtension(optionalStringPieceExtension));
+ Assert.assertFalse(message.hasExtension(optionalCordExtension));
+
+ // Optional fields without defaults are set to zero or something like it.
+ assertEqualsExactType(0 , message.getExtension(optionalInt32Extension ));
+ assertEqualsExactType(0L , message.getExtension(optionalInt64Extension ));
+ assertEqualsExactType(0 , message.getExtension(optionalUint32Extension ));
+ assertEqualsExactType(0L , message.getExtension(optionalUint64Extension ));
+ assertEqualsExactType(0 , message.getExtension(optionalSint32Extension ));
+ assertEqualsExactType(0L , message.getExtension(optionalSint64Extension ));
+ assertEqualsExactType(0 , message.getExtension(optionalFixed32Extension ));
+ assertEqualsExactType(0L , message.getExtension(optionalFixed64Extension ));
+ assertEqualsExactType(0 , message.getExtension(optionalSfixed32Extension));
+ assertEqualsExactType(0L , message.getExtension(optionalSfixed64Extension));
+ assertEqualsExactType(0F , message.getExtension(optionalFloatExtension ));
+ assertEqualsExactType(0D , message.getExtension(optionalDoubleExtension ));
+ assertEqualsExactType(false, message.getExtension(optionalBoolExtension ));
+ assertEqualsExactType("" , message.getExtension(optionalStringExtension ));
+ assertEqualsExactType(ByteString.EMPTY, message.getExtension(optionalBytesExtension));
+
+ // Embedded messages should also be clear.
+ Assert.assertFalse(message.getExtension(optionalGroupExtension ).hasA());
+ Assert.assertFalse(message.getExtension(optionalNestedMessageExtension ).hasBb());
+ Assert.assertFalse(message.getExtension(optionalForeignMessageExtension).hasC());
+ Assert.assertFalse(message.getExtension(optionalImportMessageExtension ).hasD());
+
+ assertEqualsExactType(0, message.getExtension(optionalGroupExtension ).getA());
+ assertEqualsExactType(0, message.getExtension(optionalNestedMessageExtension ).getBb());
+ assertEqualsExactType(0, message.getExtension(optionalForeignMessageExtension).getC());
+ assertEqualsExactType(0, message.getExtension(optionalImportMessageExtension ).getD());
+
+ // Enums without defaults are set to the first value in the enum.
+ assertEqualsExactType(TestAllTypes.NestedEnum.FOO,
+ message.getExtension(optionalNestedEnumExtension ));
+ assertEqualsExactType(ForeignEnum.FOREIGN_FOO,
+ message.getExtension(optionalForeignEnumExtension));
+ assertEqualsExactType(ImportEnum.IMPORT_FOO,
+ message.getExtension(optionalImportEnumExtension));
+
+ assertEqualsExactType("", message.getExtension(optionalStringPieceExtension));
+ assertEqualsExactType("", message.getExtension(optionalCordExtension));
+
+ // Repeated fields are empty.
+ Assert.assertEquals(0, message.getExtensionCount(repeatedInt32Extension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedInt64Extension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedUint32Extension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedUint64Extension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedSint32Extension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedSint64Extension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedFixed32Extension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedFixed64Extension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedSfixed32Extension));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedSfixed64Extension));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedFloatExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedDoubleExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedBoolExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedStringExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedBytesExtension ));
+
+ Assert.assertEquals(0, message.getExtensionCount(repeatedGroupExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedNestedMessageExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedForeignMessageExtension));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedImportMessageExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedLazyMessageExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedNestedEnumExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedForeignEnumExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedImportEnumExtension ));
+
+ Assert.assertEquals(0, message.getExtensionCount(repeatedStringPieceExtension));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedCordExtension));
+
+ // Repeated fields are empty via getExtension().size().
+ Assert.assertEquals(0, message.getExtension(repeatedInt32Extension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedInt64Extension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedUint32Extension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedUint64Extension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedSint32Extension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedSint64Extension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedFixed32Extension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedFixed64Extension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedSfixed32Extension).size());
+ Assert.assertEquals(0, message.getExtension(repeatedSfixed64Extension).size());
+ Assert.assertEquals(0, message.getExtension(repeatedFloatExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedDoubleExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedBoolExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedStringExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedBytesExtension ).size());
+
+ Assert.assertEquals(0, message.getExtension(repeatedGroupExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedNestedMessageExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedForeignMessageExtension).size());
+ Assert.assertEquals(0, message.getExtension(repeatedImportMessageExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedLazyMessageExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedNestedEnumExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedForeignEnumExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedImportEnumExtension ).size());
+
+ Assert.assertEquals(0, message.getExtension(repeatedStringPieceExtension).size());
+ Assert.assertEquals(0, message.getExtension(repeatedCordExtension).size());
+
+ // hasBlah() should also be false for all default fields.
+ Assert.assertFalse(message.hasExtension(defaultInt32Extension ));
+ Assert.assertFalse(message.hasExtension(defaultInt64Extension ));
+ Assert.assertFalse(message.hasExtension(defaultUint32Extension ));
+ Assert.assertFalse(message.hasExtension(defaultUint64Extension ));
+ Assert.assertFalse(message.hasExtension(defaultSint32Extension ));
+ Assert.assertFalse(message.hasExtension(defaultSint64Extension ));
+ Assert.assertFalse(message.hasExtension(defaultFixed32Extension ));
+ Assert.assertFalse(message.hasExtension(defaultFixed64Extension ));
+ Assert.assertFalse(message.hasExtension(defaultSfixed32Extension));
+ Assert.assertFalse(message.hasExtension(defaultSfixed64Extension));
+ Assert.assertFalse(message.hasExtension(defaultFloatExtension ));
+ Assert.assertFalse(message.hasExtension(defaultDoubleExtension ));
+ Assert.assertFalse(message.hasExtension(defaultBoolExtension ));
+ Assert.assertFalse(message.hasExtension(defaultStringExtension ));
+ Assert.assertFalse(message.hasExtension(defaultBytesExtension ));
+
+ Assert.assertFalse(message.hasExtension(defaultNestedEnumExtension ));
+ Assert.assertFalse(message.hasExtension(defaultForeignEnumExtension));
+ Assert.assertFalse(message.hasExtension(defaultImportEnumExtension ));
+
+ Assert.assertFalse(message.hasExtension(defaultStringPieceExtension));
+ Assert.assertFalse(message.hasExtension(defaultCordExtension));
+
+ // Fields with defaults have their default values (duh).
+ assertEqualsExactType( 41 , message.getExtension(defaultInt32Extension ));
+ assertEqualsExactType( 42L , message.getExtension(defaultInt64Extension ));
+ assertEqualsExactType( 43 , message.getExtension(defaultUint32Extension ));
+ assertEqualsExactType( 44L , message.getExtension(defaultUint64Extension ));
+ assertEqualsExactType(-45 , message.getExtension(defaultSint32Extension ));
+ assertEqualsExactType( 46L , message.getExtension(defaultSint64Extension ));
+ assertEqualsExactType( 47 , message.getExtension(defaultFixed32Extension ));
+ assertEqualsExactType( 48L , message.getExtension(defaultFixed64Extension ));
+ assertEqualsExactType( 49 , message.getExtension(defaultSfixed32Extension));
+ assertEqualsExactType(-50L , message.getExtension(defaultSfixed64Extension));
+ assertEqualsExactType( 51.5F , message.getExtension(defaultFloatExtension ));
+ assertEqualsExactType( 52e3D , message.getExtension(defaultDoubleExtension ));
+ assertEqualsExactType(true , message.getExtension(defaultBoolExtension ));
+ assertEqualsExactType("hello", message.getExtension(defaultStringExtension ));
+ assertEqualsExactType(toBytes("world"), message.getExtension(defaultBytesExtension));
+
+ assertEqualsExactType(TestAllTypes.NestedEnum.BAR,
+ message.getExtension(defaultNestedEnumExtension ));
+ assertEqualsExactType(ForeignEnum.FOREIGN_BAR,
+ message.getExtension(defaultForeignEnumExtension));
+ assertEqualsExactType(ImportEnum.IMPORT_BAR,
+ message.getExtension(defaultImportEnumExtension));
+
+ assertEqualsExactType("abc", message.getExtension(defaultStringPieceExtension));
+ assertEqualsExactType("123", message.getExtension(defaultCordExtension));
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all extensions of
+ * {@code message} are set to the values assigned by {@code setAllExtensions}
+ * followed by {@code modifyRepeatedExtensions}.
+ */
+ public static void assertRepeatedExtensionsModified(
+ TestAllExtensionsOrBuilder message) {
+ // ModifyRepeatedFields only sets the second repeated element of each
+ // field. In addition to verifying this, we also verify that the first
+ // element and size were *not* modified.
+ Assert.assertEquals(2, message.getExtensionCount(repeatedInt32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedInt64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedUint32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedUint64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSint32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSint64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFixed32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFixed64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSfixed32Extension));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSfixed64Extension));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFloatExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedDoubleExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedBoolExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedStringExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedBytesExtension ));
+
+ Assert.assertEquals(2, message.getExtensionCount(repeatedGroupExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedNestedMessageExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedForeignMessageExtension));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedImportMessageExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedLazyMessageExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedNestedEnumExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedForeignEnumExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedImportEnumExtension ));
+
+ Assert.assertEquals(2, message.getExtensionCount(repeatedStringPieceExtension));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedCordExtension));
+
+ assertEqualsExactType(201 , message.getExtension(repeatedInt32Extension , 0));
+ assertEqualsExactType(202L , message.getExtension(repeatedInt64Extension , 0));
+ assertEqualsExactType(203 , message.getExtension(repeatedUint32Extension , 0));
+ assertEqualsExactType(204L , message.getExtension(repeatedUint64Extension , 0));
+ assertEqualsExactType(205 , message.getExtension(repeatedSint32Extension , 0));
+ assertEqualsExactType(206L , message.getExtension(repeatedSint64Extension , 0));
+ assertEqualsExactType(207 , message.getExtension(repeatedFixed32Extension , 0));
+ assertEqualsExactType(208L , message.getExtension(repeatedFixed64Extension , 0));
+ assertEqualsExactType(209 , message.getExtension(repeatedSfixed32Extension, 0));
+ assertEqualsExactType(210L , message.getExtension(repeatedSfixed64Extension, 0));
+ assertEqualsExactType(211F , message.getExtension(repeatedFloatExtension , 0));
+ assertEqualsExactType(212D , message.getExtension(repeatedDoubleExtension , 0));
+ assertEqualsExactType(true , message.getExtension(repeatedBoolExtension , 0));
+ assertEqualsExactType("215", message.getExtension(repeatedStringExtension , 0));
+ assertEqualsExactType(toBytes("216"), message.getExtension(repeatedBytesExtension, 0));
+
+ assertEqualsExactType(217, message.getExtension(repeatedGroupExtension , 0).getA());
+ assertEqualsExactType(218, message.getExtension(repeatedNestedMessageExtension , 0).getBb());
+ assertEqualsExactType(219, message.getExtension(repeatedForeignMessageExtension, 0).getC());
+ assertEqualsExactType(220, message.getExtension(repeatedImportMessageExtension , 0).getD());
+ assertEqualsExactType(227, message.getExtension(repeatedLazyMessageExtension , 0).getBb());
+
+ assertEqualsExactType(TestAllTypes.NestedEnum.BAR,
+ message.getExtension(repeatedNestedEnumExtension, 0));
+ assertEqualsExactType(ForeignEnum.FOREIGN_BAR,
+ message.getExtension(repeatedForeignEnumExtension, 0));
+ assertEqualsExactType(ImportEnum.IMPORT_BAR,
+ message.getExtension(repeatedImportEnumExtension, 0));
+
+ assertEqualsExactType("224", message.getExtension(repeatedStringPieceExtension, 0));
+ assertEqualsExactType("225", message.getExtension(repeatedCordExtension, 0));
+
+ // Actually verify the second (modified) elements now.
+ assertEqualsExactType(501 , message.getExtension(repeatedInt32Extension , 1));
+ assertEqualsExactType(502L , message.getExtension(repeatedInt64Extension , 1));
+ assertEqualsExactType(503 , message.getExtension(repeatedUint32Extension , 1));
+ assertEqualsExactType(504L , message.getExtension(repeatedUint64Extension , 1));
+ assertEqualsExactType(505 , message.getExtension(repeatedSint32Extension , 1));
+ assertEqualsExactType(506L , message.getExtension(repeatedSint64Extension , 1));
+ assertEqualsExactType(507 , message.getExtension(repeatedFixed32Extension , 1));
+ assertEqualsExactType(508L , message.getExtension(repeatedFixed64Extension , 1));
+ assertEqualsExactType(509 , message.getExtension(repeatedSfixed32Extension, 1));
+ assertEqualsExactType(510L , message.getExtension(repeatedSfixed64Extension, 1));
+ assertEqualsExactType(511F , message.getExtension(repeatedFloatExtension , 1));
+ assertEqualsExactType(512D , message.getExtension(repeatedDoubleExtension , 1));
+ assertEqualsExactType(true , message.getExtension(repeatedBoolExtension , 1));
+ assertEqualsExactType("515", message.getExtension(repeatedStringExtension , 1));
+ assertEqualsExactType(toBytes("516"), message.getExtension(repeatedBytesExtension, 1));
+
+ assertEqualsExactType(517, message.getExtension(repeatedGroupExtension , 1).getA());
+ assertEqualsExactType(518, message.getExtension(repeatedNestedMessageExtension , 1).getBb());
+ assertEqualsExactType(519, message.getExtension(repeatedForeignMessageExtension, 1).getC());
+ assertEqualsExactType(520, message.getExtension(repeatedImportMessageExtension , 1).getD());
+ assertEqualsExactType(527, message.getExtension(repeatedLazyMessageExtension , 1).getBb());
+
+ assertEqualsExactType(TestAllTypes.NestedEnum.FOO,
+ message.getExtension(repeatedNestedEnumExtension, 1));
+ assertEqualsExactType(ForeignEnum.FOREIGN_FOO,
+ message.getExtension(repeatedForeignEnumExtension, 1));
+ assertEqualsExactType(ImportEnum.IMPORT_FOO,
+ message.getExtension(repeatedImportEnumExtension, 1));
+
+ assertEqualsExactType("524", message.getExtension(repeatedStringPieceExtension, 1));
+ assertEqualsExactType("525", message.getExtension(repeatedCordExtension, 1));
+ }
+
+ public static void setPackedExtensions(TestPackedExtensions.Builder message) {
+ message.addExtension(packedInt32Extension , 601);
+ message.addExtension(packedInt64Extension , 602L);
+ message.addExtension(packedUint32Extension , 603);
+ message.addExtension(packedUint64Extension , 604L);
+ message.addExtension(packedSint32Extension , 605);
+ message.addExtension(packedSint64Extension , 606L);
+ message.addExtension(packedFixed32Extension , 607);
+ message.addExtension(packedFixed64Extension , 608L);
+ message.addExtension(packedSfixed32Extension, 609);
+ message.addExtension(packedSfixed64Extension, 610L);
+ message.addExtension(packedFloatExtension , 611F);
+ message.addExtension(packedDoubleExtension , 612D);
+ message.addExtension(packedBoolExtension , true);
+ message.addExtension(packedEnumExtension, ForeignEnum.FOREIGN_BAR);
+ // Add a second one of each field.
+ message.addExtension(packedInt32Extension , 701);
+ message.addExtension(packedInt64Extension , 702L);
+ message.addExtension(packedUint32Extension , 703);
+ message.addExtension(packedUint64Extension , 704L);
+ message.addExtension(packedSint32Extension , 705);
+ message.addExtension(packedSint64Extension , 706L);
+ message.addExtension(packedFixed32Extension , 707);
+ message.addExtension(packedFixed64Extension , 708L);
+ message.addExtension(packedSfixed32Extension, 709);
+ message.addExtension(packedSfixed64Extension, 710L);
+ message.addExtension(packedFloatExtension , 711F);
+ message.addExtension(packedDoubleExtension , 712D);
+ message.addExtension(packedBoolExtension , false);
+ message.addExtension(packedEnumExtension, ForeignEnum.FOREIGN_BAZ);
+ }
+
+ public static void assertPackedExtensionsSet(TestPackedExtensions message) {
+ Assert.assertEquals(2, message.getExtensionCount(packedInt32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedInt64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedUint32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedUint64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedSint32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedSint64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedFixed32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedFixed64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedSfixed32Extension));
+ Assert.assertEquals(2, message.getExtensionCount(packedSfixed64Extension));
+ Assert.assertEquals(2, message.getExtensionCount(packedFloatExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedDoubleExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedBoolExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedEnumExtension));
+ assertEqualsExactType(601 , message.getExtension(packedInt32Extension , 0));
+ assertEqualsExactType(602L , message.getExtension(packedInt64Extension , 0));
+ assertEqualsExactType(603 , message.getExtension(packedUint32Extension , 0));
+ assertEqualsExactType(604L , message.getExtension(packedUint64Extension , 0));
+ assertEqualsExactType(605 , message.getExtension(packedSint32Extension , 0));
+ assertEqualsExactType(606L , message.getExtension(packedSint64Extension , 0));
+ assertEqualsExactType(607 , message.getExtension(packedFixed32Extension , 0));
+ assertEqualsExactType(608L , message.getExtension(packedFixed64Extension , 0));
+ assertEqualsExactType(609 , message.getExtension(packedSfixed32Extension, 0));
+ assertEqualsExactType(610L , message.getExtension(packedSfixed64Extension, 0));
+ assertEqualsExactType(611F , message.getExtension(packedFloatExtension , 0));
+ assertEqualsExactType(612D , message.getExtension(packedDoubleExtension , 0));
+ assertEqualsExactType(true , message.getExtension(packedBoolExtension , 0));
+ assertEqualsExactType(ForeignEnum.FOREIGN_BAR,
+ message.getExtension(packedEnumExtension, 0));
+ assertEqualsExactType(701 , message.getExtension(packedInt32Extension , 1));
+ assertEqualsExactType(702L , message.getExtension(packedInt64Extension , 1));
+ assertEqualsExactType(703 , message.getExtension(packedUint32Extension , 1));
+ assertEqualsExactType(704L , message.getExtension(packedUint64Extension , 1));
+ assertEqualsExactType(705 , message.getExtension(packedSint32Extension , 1));
+ assertEqualsExactType(706L , message.getExtension(packedSint64Extension , 1));
+ assertEqualsExactType(707 , message.getExtension(packedFixed32Extension , 1));
+ assertEqualsExactType(708L , message.getExtension(packedFixed64Extension , 1));
+ assertEqualsExactType(709 , message.getExtension(packedSfixed32Extension, 1));
+ assertEqualsExactType(710L , message.getExtension(packedSfixed64Extension, 1));
+ assertEqualsExactType(711F , message.getExtension(packedFloatExtension , 1));
+ assertEqualsExactType(712D , message.getExtension(packedDoubleExtension , 1));
+ assertEqualsExactType(false, message.getExtension(packedBoolExtension , 1));
+ assertEqualsExactType(ForeignEnum.FOREIGN_BAZ,
+ message.getExtension(packedEnumExtension, 1));
+ }
+
+ // =================================================================
+
+ /**
+ * Performs the same things that the methods of {@code TestUtil} do, but
+ * via the reflection interface. This is its own class because it needs
+ * to know what descriptor to use.
+ */
+ public static class ReflectionTester {
+ private final Descriptors.Descriptor baseDescriptor;
+ private final ExtensionRegistry extensionRegistry;
+
+ private final Descriptors.FileDescriptor file;
+ private final Descriptors.FileDescriptor importFile;
+ private final Descriptors.FileDescriptor publicImportFile;
+
+ private final Descriptors.Descriptor optionalGroup;
+ private final Descriptors.Descriptor repeatedGroup;
+ private final Descriptors.Descriptor nestedMessage;
+ private final Descriptors.Descriptor foreignMessage;
+ private final Descriptors.Descriptor importMessage;
+ private final Descriptors.Descriptor publicImportMessage;
+
+ private final Descriptors.FieldDescriptor groupA;
+ private final Descriptors.FieldDescriptor repeatedGroupA;
+ private final Descriptors.FieldDescriptor nestedB;
+ private final Descriptors.FieldDescriptor foreignC;
+ private final Descriptors.FieldDescriptor importD;
+ private final Descriptors.FieldDescriptor importE;
+
+ private final Descriptors.EnumDescriptor nestedEnum;
+ private final Descriptors.EnumDescriptor foreignEnum;
+ private final Descriptors.EnumDescriptor importEnum;
+
+ private final Descriptors.EnumValueDescriptor nestedFoo;
+ private final Descriptors.EnumValueDescriptor nestedBar;
+ private final Descriptors.EnumValueDescriptor nestedBaz;
+ private final Descriptors.EnumValueDescriptor foreignFoo;
+ private final Descriptors.EnumValueDescriptor foreignBar;
+ private final Descriptors.EnumValueDescriptor foreignBaz;
+ private final Descriptors.EnumValueDescriptor importFoo;
+ private final Descriptors.EnumValueDescriptor importBar;
+ private final Descriptors.EnumValueDescriptor importBaz;
+
+ /**
+ * Construct a {@code ReflectionTester} that will expect messages using
+ * the given descriptor.
+ *
+ * Normally {@code baseDescriptor} should be a descriptor for the type
+ * {@code TestAllTypes}, defined in
+ * {@code google/protobuf/unittest.proto}. However, if
+ * {@code extensionRegistry} is non-null, then {@code baseDescriptor} should
+ * be for {@code TestAllExtensions} instead, and instead of reading and
+ * writing normal fields, the tester will read and write extensions.
+ * All of {@code TestAllExtensions}' extensions must be registered in the
+ * registry.
+ */
+ public ReflectionTester(Descriptors.Descriptor baseDescriptor,
+ ExtensionRegistry extensionRegistry) {
+ this.baseDescriptor = baseDescriptor;
+ this.extensionRegistry = extensionRegistry;
+
+ this.file = baseDescriptor.getFile();
+ Assert.assertEquals(1, file.getDependencies().size());
+ this.importFile = file.getDependencies().get(0);
+ this.publicImportFile = importFile.getDependencies().get(0);
+
+ Descriptors.Descriptor testAllTypes;
+ if (baseDescriptor.getName() == "TestAllTypes") {
+ testAllTypes = baseDescriptor;
+ } else {
+ testAllTypes = file.findMessageTypeByName("TestAllTypes");
+ Assert.assertNotNull(testAllTypes);
+ }
+
+ if (extensionRegistry == null) {
+ // Use testAllTypes, rather than baseDescriptor, to allow
+ // initialization using TestPackedTypes descriptors. These objects
+ // won't be used by the methods for packed fields.
+ this.optionalGroup =
+ testAllTypes.findNestedTypeByName("OptionalGroup");
+ this.repeatedGroup =
+ testAllTypes.findNestedTypeByName("RepeatedGroup");
+ } else {
+ this.optionalGroup =
+ file.findMessageTypeByName("OptionalGroup_extension");
+ this.repeatedGroup =
+ file.findMessageTypeByName("RepeatedGroup_extension");
+ }
+ this.nestedMessage = testAllTypes.findNestedTypeByName("NestedMessage");
+ this.foreignMessage = file.findMessageTypeByName("ForeignMessage");
+ this.importMessage = importFile.findMessageTypeByName("ImportMessage");
+ this.publicImportMessage = publicImportFile.findMessageTypeByName(
+ "PublicImportMessage");
+
+ this.nestedEnum = testAllTypes.findEnumTypeByName("NestedEnum");
+ this.foreignEnum = file.findEnumTypeByName("ForeignEnum");
+ this.importEnum = importFile.findEnumTypeByName("ImportEnum");
+
+ Assert.assertNotNull(optionalGroup );
+ Assert.assertNotNull(repeatedGroup );
+ Assert.assertNotNull(nestedMessage );
+ Assert.assertNotNull(foreignMessage);
+ Assert.assertNotNull(importMessage );
+ Assert.assertNotNull(nestedEnum );
+ Assert.assertNotNull(foreignEnum );
+ Assert.assertNotNull(importEnum );
+
+ this.nestedB = nestedMessage .findFieldByName("bb");
+ this.foreignC = foreignMessage.findFieldByName("c");
+ this.importD = importMessage .findFieldByName("d");
+ this.importE = publicImportMessage.findFieldByName("e");
+ this.nestedFoo = nestedEnum.findValueByName("FOO");
+ this.nestedBar = nestedEnum.findValueByName("BAR");
+ this.nestedBaz = nestedEnum.findValueByName("BAZ");
+ this.foreignFoo = foreignEnum.findValueByName("FOREIGN_FOO");
+ this.foreignBar = foreignEnum.findValueByName("FOREIGN_BAR");
+ this.foreignBaz = foreignEnum.findValueByName("FOREIGN_BAZ");
+ this.importFoo = importEnum.findValueByName("IMPORT_FOO");
+ this.importBar = importEnum.findValueByName("IMPORT_BAR");
+ this.importBaz = importEnum.findValueByName("IMPORT_BAZ");
+
+ this.groupA = optionalGroup.findFieldByName("a");
+ this.repeatedGroupA = repeatedGroup.findFieldByName("a");
+
+ Assert.assertNotNull(groupA );
+ Assert.assertNotNull(repeatedGroupA);
+ Assert.assertNotNull(nestedB );
+ Assert.assertNotNull(foreignC );
+ Assert.assertNotNull(importD );
+ Assert.assertNotNull(importE );
+ Assert.assertNotNull(nestedFoo );
+ Assert.assertNotNull(nestedBar );
+ Assert.assertNotNull(nestedBaz );
+ Assert.assertNotNull(foreignFoo );
+ Assert.assertNotNull(foreignBar );
+ Assert.assertNotNull(foreignBaz );
+ Assert.assertNotNull(importFoo );
+ Assert.assertNotNull(importBar );
+ Assert.assertNotNull(importBaz );
+ }
+
+ /**
+ * Shorthand to get a FieldDescriptor for a field of unittest::TestAllTypes.
+ */
+ private Descriptors.FieldDescriptor f(String name) {
+ Descriptors.FieldDescriptor result;
+ if (extensionRegistry == null) {
+ result = baseDescriptor.findFieldByName(name);
+ } else {
+ result = file.findExtensionByName(name + "_extension");
+ }
+ Assert.assertNotNull(result);
+ return result;
+ }
+
+ /**
+ * Calls {@code parent.newBuilderForField()} or uses the
+ * {@code ExtensionRegistry} to find an appropriate builder, depending
+ * on what type is being tested.
+ */
+ private Message.Builder newBuilderForField(
+ Message.Builder parent, Descriptors.FieldDescriptor field) {
+ if (extensionRegistry == null) {
+ return parent.newBuilderForField(field);
+ } else {
+ ExtensionRegistry.ExtensionInfo extension =
+ extensionRegistry.findExtensionByNumber(field.getContainingType(),
+ field.getNumber());
+ Assert.assertNotNull(extension);
+ Assert.assertNotNull(extension.defaultInstance);
+ return extension.defaultInstance.newBuilderForType();
+ }
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Set every field of {@code message} to the values expected by
+ * {@code assertAllFieldsSet()}, using the {@link Message.Builder}
+ * reflection interface.
+ */
+ void setAllFieldsViaReflection(Message.Builder message) {
+ message.setField(f("optional_int32" ), 101 );
+ message.setField(f("optional_int64" ), 102L);
+ message.setField(f("optional_uint32" ), 103 );
+ message.setField(f("optional_uint64" ), 104L);
+ message.setField(f("optional_sint32" ), 105 );
+ message.setField(f("optional_sint64" ), 106L);
+ message.setField(f("optional_fixed32" ), 107 );
+ message.setField(f("optional_fixed64" ), 108L);
+ message.setField(f("optional_sfixed32"), 109 );
+ message.setField(f("optional_sfixed64"), 110L);
+ message.setField(f("optional_float" ), 111F);
+ message.setField(f("optional_double" ), 112D);
+ message.setField(f("optional_bool" ), true);
+ message.setField(f("optional_string" ), "115");
+ message.setField(f("optional_bytes" ), toBytes("116"));
+
+ message.setField(f("optionalgroup"),
+ newBuilderForField(message, f("optionalgroup"))
+ .setField(groupA, 117).build());
+ message.setField(f("optional_nested_message"),
+ newBuilderForField(message, f("optional_nested_message"))
+ .setField(nestedB, 118).build());
+ message.setField(f("optional_foreign_message"),
+ newBuilderForField(message, f("optional_foreign_message"))
+ .setField(foreignC, 119).build());
+ message.setField(f("optional_import_message"),
+ newBuilderForField(message, f("optional_import_message"))
+ .setField(importD, 120).build());
+ message.setField(f("optional_public_import_message"),
+ newBuilderForField(message, f("optional_public_import_message"))
+ .setField(importE, 126).build());
+ message.setField(f("optional_lazy_message"),
+ newBuilderForField(message, f("optional_lazy_message"))
+ .setField(nestedB, 127).build());
+
+ message.setField(f("optional_nested_enum" ), nestedBaz);
+ message.setField(f("optional_foreign_enum"), foreignBaz);
+ message.setField(f("optional_import_enum" ), importBaz);
+
+ message.setField(f("optional_string_piece" ), "124");
+ message.setField(f("optional_cord" ), "125");
+
+ // -----------------------------------------------------------------
+
+ message.addRepeatedField(f("repeated_int32" ), 201 );
+ message.addRepeatedField(f("repeated_int64" ), 202L);
+ message.addRepeatedField(f("repeated_uint32" ), 203 );
+ message.addRepeatedField(f("repeated_uint64" ), 204L);
+ message.addRepeatedField(f("repeated_sint32" ), 205 );
+ message.addRepeatedField(f("repeated_sint64" ), 206L);
+ message.addRepeatedField(f("repeated_fixed32" ), 207 );
+ message.addRepeatedField(f("repeated_fixed64" ), 208L);
+ message.addRepeatedField(f("repeated_sfixed32"), 209 );
+ message.addRepeatedField(f("repeated_sfixed64"), 210L);
+ message.addRepeatedField(f("repeated_float" ), 211F);
+ message.addRepeatedField(f("repeated_double" ), 212D);
+ message.addRepeatedField(f("repeated_bool" ), true);
+ message.addRepeatedField(f("repeated_string" ), "215");
+ message.addRepeatedField(f("repeated_bytes" ), toBytes("216"));
+
+ message.addRepeatedField(f("repeatedgroup"),
+ newBuilderForField(message, f("repeatedgroup"))
+ .setField(repeatedGroupA, 217).build());
+ message.addRepeatedField(f("repeated_nested_message"),
+ newBuilderForField(message, f("repeated_nested_message"))
+ .setField(nestedB, 218).build());
+ message.addRepeatedField(f("repeated_foreign_message"),
+ newBuilderForField(message, f("repeated_foreign_message"))
+ .setField(foreignC, 219).build());
+ message.addRepeatedField(f("repeated_import_message"),
+ newBuilderForField(message, f("repeated_import_message"))
+ .setField(importD, 220).build());
+ message.addRepeatedField(f("repeated_lazy_message"),
+ newBuilderForField(message, f("repeated_lazy_message"))
+ .setField(nestedB, 227).build());
+
+ message.addRepeatedField(f("repeated_nested_enum" ), nestedBar);
+ message.addRepeatedField(f("repeated_foreign_enum"), foreignBar);
+ message.addRepeatedField(f("repeated_import_enum" ), importBar);
+
+ message.addRepeatedField(f("repeated_string_piece" ), "224");
+ message.addRepeatedField(f("repeated_cord" ), "225");
+
+ // Add a second one of each field.
+ message.addRepeatedField(f("repeated_int32" ), 301 );
+ message.addRepeatedField(f("repeated_int64" ), 302L);
+ message.addRepeatedField(f("repeated_uint32" ), 303 );
+ message.addRepeatedField(f("repeated_uint64" ), 304L);
+ message.addRepeatedField(f("repeated_sint32" ), 305 );
+ message.addRepeatedField(f("repeated_sint64" ), 306L);
+ message.addRepeatedField(f("repeated_fixed32" ), 307 );
+ message.addRepeatedField(f("repeated_fixed64" ), 308L);
+ message.addRepeatedField(f("repeated_sfixed32"), 309 );
+ message.addRepeatedField(f("repeated_sfixed64"), 310L);
+ message.addRepeatedField(f("repeated_float" ), 311F);
+ message.addRepeatedField(f("repeated_double" ), 312D);
+ message.addRepeatedField(f("repeated_bool" ), false);
+ message.addRepeatedField(f("repeated_string" ), "315");
+ message.addRepeatedField(f("repeated_bytes" ), toBytes("316"));
+
+ message.addRepeatedField(f("repeatedgroup"),
+ newBuilderForField(message, f("repeatedgroup"))
+ .setField(repeatedGroupA, 317).build());
+ message.addRepeatedField(f("repeated_nested_message"),
+ newBuilderForField(message, f("repeated_nested_message"))
+ .setField(nestedB, 318).build());
+ message.addRepeatedField(f("repeated_foreign_message"),
+ newBuilderForField(message, f("repeated_foreign_message"))
+ .setField(foreignC, 319).build());
+ message.addRepeatedField(f("repeated_import_message"),
+ newBuilderForField(message, f("repeated_import_message"))
+ .setField(importD, 320).build());
+ message.addRepeatedField(f("repeated_lazy_message"),
+ newBuilderForField(message, f("repeated_lazy_message"))
+ .setField(nestedB, 327).build());
+
+ message.addRepeatedField(f("repeated_nested_enum" ), nestedBaz);
+ message.addRepeatedField(f("repeated_foreign_enum"), foreignBaz);
+ message.addRepeatedField(f("repeated_import_enum" ), importBaz);
+
+ message.addRepeatedField(f("repeated_string_piece" ), "324");
+ message.addRepeatedField(f("repeated_cord" ), "325");
+
+ // -----------------------------------------------------------------
+
+ message.setField(f("default_int32" ), 401 );
+ message.setField(f("default_int64" ), 402L);
+ message.setField(f("default_uint32" ), 403 );
+ message.setField(f("default_uint64" ), 404L);
+ message.setField(f("default_sint32" ), 405 );
+ message.setField(f("default_sint64" ), 406L);
+ message.setField(f("default_fixed32" ), 407 );
+ message.setField(f("default_fixed64" ), 408L);
+ message.setField(f("default_sfixed32"), 409 );
+ message.setField(f("default_sfixed64"), 410L);
+ message.setField(f("default_float" ), 411F);
+ message.setField(f("default_double" ), 412D);
+ message.setField(f("default_bool" ), false);
+ message.setField(f("default_string" ), "415");
+ message.setField(f("default_bytes" ), toBytes("416"));
+
+ message.setField(f("default_nested_enum" ), nestedFoo);
+ message.setField(f("default_foreign_enum"), foreignFoo);
+ message.setField(f("default_import_enum" ), importFoo);
+
+ message.setField(f("default_string_piece" ), "424");
+ message.setField(f("default_cord" ), "425");
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Modify the repeated fields of {@code message} to contain the values
+ * expected by {@code assertRepeatedFieldsModified()}, using the
+ * {@link Message.Builder} reflection interface.
+ */
+ void modifyRepeatedFieldsViaReflection(Message.Builder message) {
+ message.setRepeatedField(f("repeated_int32" ), 1, 501 );
+ message.setRepeatedField(f("repeated_int64" ), 1, 502L);
+ message.setRepeatedField(f("repeated_uint32" ), 1, 503 );
+ message.setRepeatedField(f("repeated_uint64" ), 1, 504L);
+ message.setRepeatedField(f("repeated_sint32" ), 1, 505 );
+ message.setRepeatedField(f("repeated_sint64" ), 1, 506L);
+ message.setRepeatedField(f("repeated_fixed32" ), 1, 507 );
+ message.setRepeatedField(f("repeated_fixed64" ), 1, 508L);
+ message.setRepeatedField(f("repeated_sfixed32"), 1, 509 );
+ message.setRepeatedField(f("repeated_sfixed64"), 1, 510L);
+ message.setRepeatedField(f("repeated_float" ), 1, 511F);
+ message.setRepeatedField(f("repeated_double" ), 1, 512D);
+ message.setRepeatedField(f("repeated_bool" ), 1, true);
+ message.setRepeatedField(f("repeated_string" ), 1, "515");
+ message.setRepeatedField(f("repeated_bytes" ), 1, toBytes("516"));
+
+ message.setRepeatedField(f("repeatedgroup"), 1,
+ newBuilderForField(message, f("repeatedgroup"))
+ .setField(repeatedGroupA, 517).build());
+ message.setRepeatedField(f("repeated_nested_message"), 1,
+ newBuilderForField(message, f("repeated_nested_message"))
+ .setField(nestedB, 518).build());
+ message.setRepeatedField(f("repeated_foreign_message"), 1,
+ newBuilderForField(message, f("repeated_foreign_message"))
+ .setField(foreignC, 519).build());
+ message.setRepeatedField(f("repeated_import_message"), 1,
+ newBuilderForField(message, f("repeated_import_message"))
+ .setField(importD, 520).build());
+ message.setRepeatedField(f("repeated_lazy_message"), 1,
+ newBuilderForField(message, f("repeated_lazy_message"))
+ .setField(nestedB, 527).build());
+
+ message.setRepeatedField(f("repeated_nested_enum" ), 1, nestedFoo);
+ message.setRepeatedField(f("repeated_foreign_enum"), 1, foreignFoo);
+ message.setRepeatedField(f("repeated_import_enum" ), 1, importFoo);
+
+ message.setRepeatedField(f("repeated_string_piece"), 1, "524");
+ message.setRepeatedField(f("repeated_cord"), 1, "525");
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all fields of
+ * {@code message} are set to the values assigned by {@code setAllFields},
+ * using the {@link Message} reflection interface.
+ */
+ public void assertAllFieldsSetViaReflection(MessageOrBuilder message) {
+ Assert.assertTrue(message.hasField(f("optional_int32" )));
+ Assert.assertTrue(message.hasField(f("optional_int64" )));
+ Assert.assertTrue(message.hasField(f("optional_uint32" )));
+ Assert.assertTrue(message.hasField(f("optional_uint64" )));
+ Assert.assertTrue(message.hasField(f("optional_sint32" )));
+ Assert.assertTrue(message.hasField(f("optional_sint64" )));
+ Assert.assertTrue(message.hasField(f("optional_fixed32" )));
+ Assert.assertTrue(message.hasField(f("optional_fixed64" )));
+ Assert.assertTrue(message.hasField(f("optional_sfixed32")));
+ Assert.assertTrue(message.hasField(f("optional_sfixed64")));
+ Assert.assertTrue(message.hasField(f("optional_float" )));
+ Assert.assertTrue(message.hasField(f("optional_double" )));
+ Assert.assertTrue(message.hasField(f("optional_bool" )));
+ Assert.assertTrue(message.hasField(f("optional_string" )));
+ Assert.assertTrue(message.hasField(f("optional_bytes" )));
+
+ Assert.assertTrue(message.hasField(f("optionalgroup" )));
+ Assert.assertTrue(message.hasField(f("optional_nested_message" )));
+ Assert.assertTrue(message.hasField(f("optional_foreign_message")));
+ Assert.assertTrue(message.hasField(f("optional_import_message" )));
+
+ Assert.assertTrue(
+ ((Message)message.getField(f("optionalgroup"))).hasField(groupA));
+ Assert.assertTrue(
+ ((Message)message.getField(f("optional_nested_message")))
+ .hasField(nestedB));
+ Assert.assertTrue(
+ ((Message)message.getField(f("optional_foreign_message")))
+ .hasField(foreignC));
+ Assert.assertTrue(
+ ((Message)message.getField(f("optional_import_message")))
+ .hasField(importD));
+
+ Assert.assertTrue(message.hasField(f("optional_nested_enum" )));
+ Assert.assertTrue(message.hasField(f("optional_foreign_enum")));
+ Assert.assertTrue(message.hasField(f("optional_import_enum" )));
+
+ Assert.assertTrue(message.hasField(f("optional_string_piece")));
+ Assert.assertTrue(message.hasField(f("optional_cord")));
+
+ Assert.assertEquals(101 , message.getField(f("optional_int32" )));
+ Assert.assertEquals(102L , message.getField(f("optional_int64" )));
+ Assert.assertEquals(103 , message.getField(f("optional_uint32" )));
+ Assert.assertEquals(104L , message.getField(f("optional_uint64" )));
+ Assert.assertEquals(105 , message.getField(f("optional_sint32" )));
+ Assert.assertEquals(106L , message.getField(f("optional_sint64" )));
+ Assert.assertEquals(107 , message.getField(f("optional_fixed32" )));
+ Assert.assertEquals(108L , message.getField(f("optional_fixed64" )));
+ Assert.assertEquals(109 , message.getField(f("optional_sfixed32")));
+ Assert.assertEquals(110L , message.getField(f("optional_sfixed64")));
+ Assert.assertEquals(111F , message.getField(f("optional_float" )));
+ Assert.assertEquals(112D , message.getField(f("optional_double" )));
+ Assert.assertEquals(true , message.getField(f("optional_bool" )));
+ Assert.assertEquals("115", message.getField(f("optional_string" )));
+ Assert.assertEquals(toBytes("116"), message.getField(f("optional_bytes")));
+
+ Assert.assertEquals(117,
+ ((Message)message.getField(f("optionalgroup"))).getField(groupA));
+ Assert.assertEquals(118,
+ ((Message)message.getField(f("optional_nested_message")))
+ .getField(nestedB));
+ Assert.assertEquals(119,
+ ((Message)message.getField(f("optional_foreign_message")))
+ .getField(foreignC));
+ Assert.assertEquals(120,
+ ((Message)message.getField(f("optional_import_message")))
+ .getField(importD));
+ Assert.assertEquals(126,
+ ((Message)message.getField(f("optional_public_import_message")))
+ .getField(importE));
+ Assert.assertEquals(127,
+ ((Message)message.getField(f("optional_lazy_message")))
+ .getField(nestedB));
+
+ Assert.assertEquals( nestedBaz, message.getField(f("optional_nested_enum" )));
+ Assert.assertEquals(foreignBaz, message.getField(f("optional_foreign_enum")));
+ Assert.assertEquals( importBaz, message.getField(f("optional_import_enum" )));
+
+ Assert.assertEquals("124", message.getField(f("optional_string_piece")));
+ Assert.assertEquals("125", message.getField(f("optional_cord")));
+
+ // -----------------------------------------------------------------
+
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_int32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_int64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_uint32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_uint64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_sint32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_sint64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_fixed32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_fixed64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_sfixed32")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_sfixed64")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_float" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_double" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_bool" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_string" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_bytes" )));
+
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeatedgroup" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_nested_message" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_foreign_message")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_import_message" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_lazy_message" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_nested_enum" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_foreign_enum" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_import_enum" )));
+
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_string_piece")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_cord")));
+
+ Assert.assertEquals(201 , message.getRepeatedField(f("repeated_int32" ), 0));
+ Assert.assertEquals(202L , message.getRepeatedField(f("repeated_int64" ), 0));
+ Assert.assertEquals(203 , message.getRepeatedField(f("repeated_uint32" ), 0));
+ Assert.assertEquals(204L , message.getRepeatedField(f("repeated_uint64" ), 0));
+ Assert.assertEquals(205 , message.getRepeatedField(f("repeated_sint32" ), 0));
+ Assert.assertEquals(206L , message.getRepeatedField(f("repeated_sint64" ), 0));
+ Assert.assertEquals(207 , message.getRepeatedField(f("repeated_fixed32" ), 0));
+ Assert.assertEquals(208L , message.getRepeatedField(f("repeated_fixed64" ), 0));
+ Assert.assertEquals(209 , message.getRepeatedField(f("repeated_sfixed32"), 0));
+ Assert.assertEquals(210L , message.getRepeatedField(f("repeated_sfixed64"), 0));
+ Assert.assertEquals(211F , message.getRepeatedField(f("repeated_float" ), 0));
+ Assert.assertEquals(212D , message.getRepeatedField(f("repeated_double" ), 0));
+ Assert.assertEquals(true , message.getRepeatedField(f("repeated_bool" ), 0));
+ Assert.assertEquals("215", message.getRepeatedField(f("repeated_string" ), 0));
+ Assert.assertEquals(toBytes("216"), message.getRepeatedField(f("repeated_bytes"), 0));
+
+ Assert.assertEquals(217,
+ ((Message)message.getRepeatedField(f("repeatedgroup"), 0))
+ .getField(repeatedGroupA));
+ Assert.assertEquals(218,
+ ((Message)message.getRepeatedField(f("repeated_nested_message"), 0))
+ .getField(nestedB));
+ Assert.assertEquals(219,
+ ((Message)message.getRepeatedField(f("repeated_foreign_message"), 0))
+ .getField(foreignC));
+ Assert.assertEquals(220,
+ ((Message)message.getRepeatedField(f("repeated_import_message"), 0))
+ .getField(importD));
+ Assert.assertEquals(227,
+ ((Message)message.getRepeatedField(f("repeated_lazy_message"), 0))
+ .getField(nestedB));
+
+ Assert.assertEquals( nestedBar, message.getRepeatedField(f("repeated_nested_enum" ),0));
+ Assert.assertEquals(foreignBar, message.getRepeatedField(f("repeated_foreign_enum"),0));
+ Assert.assertEquals( importBar, message.getRepeatedField(f("repeated_import_enum" ),0));
+
+ Assert.assertEquals("224", message.getRepeatedField(f("repeated_string_piece"), 0));
+ Assert.assertEquals("225", message.getRepeatedField(f("repeated_cord"), 0));
+
+ Assert.assertEquals(301 , message.getRepeatedField(f("repeated_int32" ), 1));
+ Assert.assertEquals(302L , message.getRepeatedField(f("repeated_int64" ), 1));
+ Assert.assertEquals(303 , message.getRepeatedField(f("repeated_uint32" ), 1));
+ Assert.assertEquals(304L , message.getRepeatedField(f("repeated_uint64" ), 1));
+ Assert.assertEquals(305 , message.getRepeatedField(f("repeated_sint32" ), 1));
+ Assert.assertEquals(306L , message.getRepeatedField(f("repeated_sint64" ), 1));
+ Assert.assertEquals(307 , message.getRepeatedField(f("repeated_fixed32" ), 1));
+ Assert.assertEquals(308L , message.getRepeatedField(f("repeated_fixed64" ), 1));
+ Assert.assertEquals(309 , message.getRepeatedField(f("repeated_sfixed32"), 1));
+ Assert.assertEquals(310L , message.getRepeatedField(f("repeated_sfixed64"), 1));
+ Assert.assertEquals(311F , message.getRepeatedField(f("repeated_float" ), 1));
+ Assert.assertEquals(312D , message.getRepeatedField(f("repeated_double" ), 1));
+ Assert.assertEquals(false, message.getRepeatedField(f("repeated_bool" ), 1));
+ Assert.assertEquals("315", message.getRepeatedField(f("repeated_string" ), 1));
+ Assert.assertEquals(toBytes("316"), message.getRepeatedField(f("repeated_bytes"), 1));
+
+ Assert.assertEquals(317,
+ ((Message)message.getRepeatedField(f("repeatedgroup"), 1))
+ .getField(repeatedGroupA));
+ Assert.assertEquals(318,
+ ((Message)message.getRepeatedField(f("repeated_nested_message"), 1))
+ .getField(nestedB));
+ Assert.assertEquals(319,
+ ((Message)message.getRepeatedField(f("repeated_foreign_message"), 1))
+ .getField(foreignC));
+ Assert.assertEquals(320,
+ ((Message)message.getRepeatedField(f("repeated_import_message"), 1))
+ .getField(importD));
+ Assert.assertEquals(327,
+ ((Message)message.getRepeatedField(f("repeated_lazy_message"), 1))
+ .getField(nestedB));
+
+ Assert.assertEquals( nestedBaz, message.getRepeatedField(f("repeated_nested_enum" ),1));
+ Assert.assertEquals(foreignBaz, message.getRepeatedField(f("repeated_foreign_enum"),1));
+ Assert.assertEquals( importBaz, message.getRepeatedField(f("repeated_import_enum" ),1));
+
+ Assert.assertEquals("324", message.getRepeatedField(f("repeated_string_piece"), 1));
+ Assert.assertEquals("325", message.getRepeatedField(f("repeated_cord"), 1));
+
+ // -----------------------------------------------------------------
+
+ Assert.assertTrue(message.hasField(f("default_int32" )));
+ Assert.assertTrue(message.hasField(f("default_int64" )));
+ Assert.assertTrue(message.hasField(f("default_uint32" )));
+ Assert.assertTrue(message.hasField(f("default_uint64" )));
+ Assert.assertTrue(message.hasField(f("default_sint32" )));
+ Assert.assertTrue(message.hasField(f("default_sint64" )));
+ Assert.assertTrue(message.hasField(f("default_fixed32" )));
+ Assert.assertTrue(message.hasField(f("default_fixed64" )));
+ Assert.assertTrue(message.hasField(f("default_sfixed32")));
+ Assert.assertTrue(message.hasField(f("default_sfixed64")));
+ Assert.assertTrue(message.hasField(f("default_float" )));
+ Assert.assertTrue(message.hasField(f("default_double" )));
+ Assert.assertTrue(message.hasField(f("default_bool" )));
+ Assert.assertTrue(message.hasField(f("default_string" )));
+ Assert.assertTrue(message.hasField(f("default_bytes" )));
+
+ Assert.assertTrue(message.hasField(f("default_nested_enum" )));
+ Assert.assertTrue(message.hasField(f("default_foreign_enum")));
+ Assert.assertTrue(message.hasField(f("default_import_enum" )));
+
+ Assert.assertTrue(message.hasField(f("default_string_piece")));
+ Assert.assertTrue(message.hasField(f("default_cord")));
+
+ Assert.assertEquals(401 , message.getField(f("default_int32" )));
+ Assert.assertEquals(402L , message.getField(f("default_int64" )));
+ Assert.assertEquals(403 , message.getField(f("default_uint32" )));
+ Assert.assertEquals(404L , message.getField(f("default_uint64" )));
+ Assert.assertEquals(405 , message.getField(f("default_sint32" )));
+ Assert.assertEquals(406L , message.getField(f("default_sint64" )));
+ Assert.assertEquals(407 , message.getField(f("default_fixed32" )));
+ Assert.assertEquals(408L , message.getField(f("default_fixed64" )));
+ Assert.assertEquals(409 , message.getField(f("default_sfixed32")));
+ Assert.assertEquals(410L , message.getField(f("default_sfixed64")));
+ Assert.assertEquals(411F , message.getField(f("default_float" )));
+ Assert.assertEquals(412D , message.getField(f("default_double" )));
+ Assert.assertEquals(false, message.getField(f("default_bool" )));
+ Assert.assertEquals("415", message.getField(f("default_string" )));
+ Assert.assertEquals(toBytes("416"), message.getField(f("default_bytes")));
+
+ Assert.assertEquals( nestedFoo, message.getField(f("default_nested_enum" )));
+ Assert.assertEquals(foreignFoo, message.getField(f("default_foreign_enum")));
+ Assert.assertEquals( importFoo, message.getField(f("default_import_enum" )));
+
+ Assert.assertEquals("424", message.getField(f("default_string_piece")));
+ Assert.assertEquals("425", message.getField(f("default_cord")));
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all fields of
+ * {@code message} are cleared, and that getting the fields returns their
+ * default values, using the {@link Message} reflection interface.
+ */
+ public void assertClearViaReflection(MessageOrBuilder message) {
+ // has_blah() should initially be false for all optional fields.
+ Assert.assertFalse(message.hasField(f("optional_int32" )));
+ Assert.assertFalse(message.hasField(f("optional_int64" )));
+ Assert.assertFalse(message.hasField(f("optional_uint32" )));
+ Assert.assertFalse(message.hasField(f("optional_uint64" )));
+ Assert.assertFalse(message.hasField(f("optional_sint32" )));
+ Assert.assertFalse(message.hasField(f("optional_sint64" )));
+ Assert.assertFalse(message.hasField(f("optional_fixed32" )));
+ Assert.assertFalse(message.hasField(f("optional_fixed64" )));
+ Assert.assertFalse(message.hasField(f("optional_sfixed32")));
+ Assert.assertFalse(message.hasField(f("optional_sfixed64")));
+ Assert.assertFalse(message.hasField(f("optional_float" )));
+ Assert.assertFalse(message.hasField(f("optional_double" )));
+ Assert.assertFalse(message.hasField(f("optional_bool" )));
+ Assert.assertFalse(message.hasField(f("optional_string" )));
+ Assert.assertFalse(message.hasField(f("optional_bytes" )));
+
+ Assert.assertFalse(message.hasField(f("optionalgroup" )));
+ Assert.assertFalse(message.hasField(f("optional_nested_message" )));
+ Assert.assertFalse(message.hasField(f("optional_foreign_message")));
+ Assert.assertFalse(message.hasField(f("optional_import_message" )));
+
+ Assert.assertFalse(message.hasField(f("optional_nested_enum" )));
+ Assert.assertFalse(message.hasField(f("optional_foreign_enum")));
+ Assert.assertFalse(message.hasField(f("optional_import_enum" )));
+
+ Assert.assertFalse(message.hasField(f("optional_string_piece")));
+ Assert.assertFalse(message.hasField(f("optional_cord")));
+
+ // Optional fields without defaults are set to zero or something like it.
+ Assert.assertEquals(0 , message.getField(f("optional_int32" )));
+ Assert.assertEquals(0L , message.getField(f("optional_int64" )));
+ Assert.assertEquals(0 , message.getField(f("optional_uint32" )));
+ Assert.assertEquals(0L , message.getField(f("optional_uint64" )));
+ Assert.assertEquals(0 , message.getField(f("optional_sint32" )));
+ Assert.assertEquals(0L , message.getField(f("optional_sint64" )));
+ Assert.assertEquals(0 , message.getField(f("optional_fixed32" )));
+ Assert.assertEquals(0L , message.getField(f("optional_fixed64" )));
+ Assert.assertEquals(0 , message.getField(f("optional_sfixed32")));
+ Assert.assertEquals(0L , message.getField(f("optional_sfixed64")));
+ Assert.assertEquals(0F , message.getField(f("optional_float" )));
+ Assert.assertEquals(0D , message.getField(f("optional_double" )));
+ Assert.assertEquals(false, message.getField(f("optional_bool" )));
+ Assert.assertEquals("" , message.getField(f("optional_string" )));
+ Assert.assertEquals(ByteString.EMPTY, message.getField(f("optional_bytes")));
+
+ // Embedded messages should also be clear.
+ Assert.assertFalse(
+ ((Message)message.getField(f("optionalgroup"))).hasField(groupA));
+ Assert.assertFalse(
+ ((Message)message.getField(f("optional_nested_message")))
+ .hasField(nestedB));
+ Assert.assertFalse(
+ ((Message)message.getField(f("optional_foreign_message")))
+ .hasField(foreignC));
+ Assert.assertFalse(
+ ((Message)message.getField(f("optional_import_message")))
+ .hasField(importD));
+ Assert.assertFalse(
+ ((Message)message.getField(f("optional_public_import_message")))
+ .hasField(importE));
+ Assert.assertFalse(
+ ((Message)message.getField(f("optional_lazy_message")))
+ .hasField(nestedB));
+
+ Assert.assertEquals(0,
+ ((Message)message.getField(f("optionalgroup"))).getField(groupA));
+ Assert.assertEquals(0,
+ ((Message)message.getField(f("optional_nested_message")))
+ .getField(nestedB));
+ Assert.assertEquals(0,
+ ((Message)message.getField(f("optional_foreign_message")))
+ .getField(foreignC));
+ Assert.assertEquals(0,
+ ((Message)message.getField(f("optional_import_message")))
+ .getField(importD));
+ Assert.assertEquals(0,
+ ((Message)message.getField(f("optional_public_import_message")))
+ .getField(importE));
+ Assert.assertEquals(0,
+ ((Message)message.getField(f("optional_lazy_message")))
+ .getField(nestedB));
+
+ // Enums without defaults are set to the first value in the enum.
+ Assert.assertEquals( nestedFoo, message.getField(f("optional_nested_enum" )));
+ Assert.assertEquals(foreignFoo, message.getField(f("optional_foreign_enum")));
+ Assert.assertEquals( importFoo, message.getField(f("optional_import_enum" )));
+
+ Assert.assertEquals("", message.getField(f("optional_string_piece")));
+ Assert.assertEquals("", message.getField(f("optional_cord")));
+
+ // Repeated fields are empty.
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_int32" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_int64" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_uint32" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_uint64" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_sint32" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_sint64" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_fixed32" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_fixed64" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_sfixed32")));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_sfixed64")));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_float" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_double" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_bool" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_string" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_bytes" )));
+
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeatedgroup" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_nested_message" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_foreign_message")));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_import_message" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_lazy_message" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_nested_enum" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_foreign_enum" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_import_enum" )));
+
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_string_piece")));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_cord")));
+
+ // has_blah() should also be false for all default fields.
+ Assert.assertFalse(message.hasField(f("default_int32" )));
+ Assert.assertFalse(message.hasField(f("default_int64" )));
+ Assert.assertFalse(message.hasField(f("default_uint32" )));
+ Assert.assertFalse(message.hasField(f("default_uint64" )));
+ Assert.assertFalse(message.hasField(f("default_sint32" )));
+ Assert.assertFalse(message.hasField(f("default_sint64" )));
+ Assert.assertFalse(message.hasField(f("default_fixed32" )));
+ Assert.assertFalse(message.hasField(f("default_fixed64" )));
+ Assert.assertFalse(message.hasField(f("default_sfixed32")));
+ Assert.assertFalse(message.hasField(f("default_sfixed64")));
+ Assert.assertFalse(message.hasField(f("default_float" )));
+ Assert.assertFalse(message.hasField(f("default_double" )));
+ Assert.assertFalse(message.hasField(f("default_bool" )));
+ Assert.assertFalse(message.hasField(f("default_string" )));
+ Assert.assertFalse(message.hasField(f("default_bytes" )));
+
+ Assert.assertFalse(message.hasField(f("default_nested_enum" )));
+ Assert.assertFalse(message.hasField(f("default_foreign_enum")));
+ Assert.assertFalse(message.hasField(f("default_import_enum" )));
+
+ Assert.assertFalse(message.hasField(f("default_string_piece" )));
+ Assert.assertFalse(message.hasField(f("default_cord" )));
+
+ // Fields with defaults have their default values (duh).
+ Assert.assertEquals( 41 , message.getField(f("default_int32" )));
+ Assert.assertEquals( 42L , message.getField(f("default_int64" )));
+ Assert.assertEquals( 43 , message.getField(f("default_uint32" )));
+ Assert.assertEquals( 44L , message.getField(f("default_uint64" )));
+ Assert.assertEquals(-45 , message.getField(f("default_sint32" )));
+ Assert.assertEquals( 46L , message.getField(f("default_sint64" )));
+ Assert.assertEquals( 47 , message.getField(f("default_fixed32" )));
+ Assert.assertEquals( 48L , message.getField(f("default_fixed64" )));
+ Assert.assertEquals( 49 , message.getField(f("default_sfixed32")));
+ Assert.assertEquals(-50L , message.getField(f("default_sfixed64")));
+ Assert.assertEquals( 51.5F , message.getField(f("default_float" )));
+ Assert.assertEquals( 52e3D , message.getField(f("default_double" )));
+ Assert.assertEquals(true , message.getField(f("default_bool" )));
+ Assert.assertEquals("hello", message.getField(f("default_string" )));
+ Assert.assertEquals(toBytes("world"), message.getField(f("default_bytes")));
+
+ Assert.assertEquals( nestedBar, message.getField(f("default_nested_enum" )));
+ Assert.assertEquals(foreignBar, message.getField(f("default_foreign_enum")));
+ Assert.assertEquals( importBar, message.getField(f("default_import_enum" )));
+
+ Assert.assertEquals("abc", message.getField(f("default_string_piece")));
+ Assert.assertEquals("123", message.getField(f("default_cord")));
+ }
+
+
+ // ---------------------------------------------------------------
+
+ public void assertRepeatedFieldsModifiedViaReflection(
+ MessageOrBuilder message) {
+ // ModifyRepeatedFields only sets the second repeated element of each
+ // field. In addition to verifying this, we also verify that the first
+ // element and size were *not* modified.
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_int32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_int64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_uint32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_uint64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_sint32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_sint64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_fixed32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_fixed64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_sfixed32")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_sfixed64")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_float" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_double" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_bool" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_string" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_bytes" )));
+
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeatedgroup" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_nested_message" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_foreign_message")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_import_message" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_lazy_message" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_nested_enum" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_foreign_enum" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_import_enum" )));
+
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_string_piece")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_cord")));
+
+ Assert.assertEquals(201 , message.getRepeatedField(f("repeated_int32" ), 0));
+ Assert.assertEquals(202L , message.getRepeatedField(f("repeated_int64" ), 0));
+ Assert.assertEquals(203 , message.getRepeatedField(f("repeated_uint32" ), 0));
+ Assert.assertEquals(204L , message.getRepeatedField(f("repeated_uint64" ), 0));
+ Assert.assertEquals(205 , message.getRepeatedField(f("repeated_sint32" ), 0));
+ Assert.assertEquals(206L , message.getRepeatedField(f("repeated_sint64" ), 0));
+ Assert.assertEquals(207 , message.getRepeatedField(f("repeated_fixed32" ), 0));
+ Assert.assertEquals(208L , message.getRepeatedField(f("repeated_fixed64" ), 0));
+ Assert.assertEquals(209 , message.getRepeatedField(f("repeated_sfixed32"), 0));
+ Assert.assertEquals(210L , message.getRepeatedField(f("repeated_sfixed64"), 0));
+ Assert.assertEquals(211F , message.getRepeatedField(f("repeated_float" ), 0));
+ Assert.assertEquals(212D , message.getRepeatedField(f("repeated_double" ), 0));
+ Assert.assertEquals(true , message.getRepeatedField(f("repeated_bool" ), 0));
+ Assert.assertEquals("215", message.getRepeatedField(f("repeated_string" ), 0));
+ Assert.assertEquals(toBytes("216"), message.getRepeatedField(f("repeated_bytes"), 0));
+
+ Assert.assertEquals(217,
+ ((Message)message.getRepeatedField(f("repeatedgroup"), 0))
+ .getField(repeatedGroupA));
+ Assert.assertEquals(218,
+ ((Message)message.getRepeatedField(f("repeated_nested_message"), 0))
+ .getField(nestedB));
+ Assert.assertEquals(219,
+ ((Message)message.getRepeatedField(f("repeated_foreign_message"), 0))
+ .getField(foreignC));
+ Assert.assertEquals(220,
+ ((Message)message.getRepeatedField(f("repeated_import_message"), 0))
+ .getField(importD));
+ Assert.assertEquals(227,
+ ((Message)message.getRepeatedField(f("repeated_lazy_message"), 0))
+ .getField(nestedB));
+
+ Assert.assertEquals( nestedBar, message.getRepeatedField(f("repeated_nested_enum" ),0));
+ Assert.assertEquals(foreignBar, message.getRepeatedField(f("repeated_foreign_enum"),0));
+ Assert.assertEquals( importBar, message.getRepeatedField(f("repeated_import_enum" ),0));
+
+ Assert.assertEquals("224", message.getRepeatedField(f("repeated_string_piece"), 0));
+ Assert.assertEquals("225", message.getRepeatedField(f("repeated_cord"), 0));
+
+ Assert.assertEquals(501 , message.getRepeatedField(f("repeated_int32" ), 1));
+ Assert.assertEquals(502L , message.getRepeatedField(f("repeated_int64" ), 1));
+ Assert.assertEquals(503 , message.getRepeatedField(f("repeated_uint32" ), 1));
+ Assert.assertEquals(504L , message.getRepeatedField(f("repeated_uint64" ), 1));
+ Assert.assertEquals(505 , message.getRepeatedField(f("repeated_sint32" ), 1));
+ Assert.assertEquals(506L , message.getRepeatedField(f("repeated_sint64" ), 1));
+ Assert.assertEquals(507 , message.getRepeatedField(f("repeated_fixed32" ), 1));
+ Assert.assertEquals(508L , message.getRepeatedField(f("repeated_fixed64" ), 1));
+ Assert.assertEquals(509 , message.getRepeatedField(f("repeated_sfixed32"), 1));
+ Assert.assertEquals(510L , message.getRepeatedField(f("repeated_sfixed64"), 1));
+ Assert.assertEquals(511F , message.getRepeatedField(f("repeated_float" ), 1));
+ Assert.assertEquals(512D , message.getRepeatedField(f("repeated_double" ), 1));
+ Assert.assertEquals(true , message.getRepeatedField(f("repeated_bool" ), 1));
+ Assert.assertEquals("515", message.getRepeatedField(f("repeated_string" ), 1));
+ Assert.assertEquals(toBytes("516"), message.getRepeatedField(f("repeated_bytes"), 1));
+
+ Assert.assertEquals(517,
+ ((Message)message.getRepeatedField(f("repeatedgroup"), 1))
+ .getField(repeatedGroupA));
+ Assert.assertEquals(518,
+ ((Message)message.getRepeatedField(f("repeated_nested_message"), 1))
+ .getField(nestedB));
+ Assert.assertEquals(519,
+ ((Message)message.getRepeatedField(f("repeated_foreign_message"), 1))
+ .getField(foreignC));
+ Assert.assertEquals(520,
+ ((Message)message.getRepeatedField(f("repeated_import_message"), 1))
+ .getField(importD));
+ Assert.assertEquals(527,
+ ((Message)message.getRepeatedField(f("repeated_lazy_message"), 1))
+ .getField(nestedB));
+
+ Assert.assertEquals( nestedFoo, message.getRepeatedField(f("repeated_nested_enum" ),1));
+ Assert.assertEquals(foreignFoo, message.getRepeatedField(f("repeated_foreign_enum"),1));
+ Assert.assertEquals( importFoo, message.getRepeatedField(f("repeated_import_enum" ),1));
+
+ Assert.assertEquals("524", message.getRepeatedField(f("repeated_string_piece"), 1));
+ Assert.assertEquals("525", message.getRepeatedField(f("repeated_cord"), 1));
+ }
+
+ public void setPackedFieldsViaReflection(Message.Builder message) {
+ message.addRepeatedField(f("packed_int32" ), 601 );
+ message.addRepeatedField(f("packed_int64" ), 602L);
+ message.addRepeatedField(f("packed_uint32" ), 603 );
+ message.addRepeatedField(f("packed_uint64" ), 604L);
+ message.addRepeatedField(f("packed_sint32" ), 605 );
+ message.addRepeatedField(f("packed_sint64" ), 606L);
+ message.addRepeatedField(f("packed_fixed32" ), 607 );
+ message.addRepeatedField(f("packed_fixed64" ), 608L);
+ message.addRepeatedField(f("packed_sfixed32"), 609 );
+ message.addRepeatedField(f("packed_sfixed64"), 610L);
+ message.addRepeatedField(f("packed_float" ), 611F);
+ message.addRepeatedField(f("packed_double" ), 612D);
+ message.addRepeatedField(f("packed_bool" ), true);
+ message.addRepeatedField(f("packed_enum" ), foreignBar);
+ // Add a second one of each field.
+ message.addRepeatedField(f("packed_int32" ), 701 );
+ message.addRepeatedField(f("packed_int64" ), 702L);
+ message.addRepeatedField(f("packed_uint32" ), 703 );
+ message.addRepeatedField(f("packed_uint64" ), 704L);
+ message.addRepeatedField(f("packed_sint32" ), 705 );
+ message.addRepeatedField(f("packed_sint64" ), 706L);
+ message.addRepeatedField(f("packed_fixed32" ), 707 );
+ message.addRepeatedField(f("packed_fixed64" ), 708L);
+ message.addRepeatedField(f("packed_sfixed32"), 709 );
+ message.addRepeatedField(f("packed_sfixed64"), 710L);
+ message.addRepeatedField(f("packed_float" ), 711F);
+ message.addRepeatedField(f("packed_double" ), 712D);
+ message.addRepeatedField(f("packed_bool" ), false);
+ message.addRepeatedField(f("packed_enum" ), foreignBaz);
+ }
+
+ public void assertPackedFieldsSetViaReflection(MessageOrBuilder message) {
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_int32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_int64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_uint32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_uint64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_sint32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_sint64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_fixed32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_fixed64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_sfixed32")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_sfixed64")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_float" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_double" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_bool" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_enum" )));
+ Assert.assertEquals(601 , message.getRepeatedField(f("packed_int32" ), 0));
+ Assert.assertEquals(602L , message.getRepeatedField(f("packed_int64" ), 0));
+ Assert.assertEquals(603 , message.getRepeatedField(f("packed_uint32" ), 0));
+ Assert.assertEquals(604L , message.getRepeatedField(f("packed_uint64" ), 0));
+ Assert.assertEquals(605 , message.getRepeatedField(f("packed_sint32" ), 0));
+ Assert.assertEquals(606L , message.getRepeatedField(f("packed_sint64" ), 0));
+ Assert.assertEquals(607 , message.getRepeatedField(f("packed_fixed32" ), 0));
+ Assert.assertEquals(608L , message.getRepeatedField(f("packed_fixed64" ), 0));
+ Assert.assertEquals(609 , message.getRepeatedField(f("packed_sfixed32"), 0));
+ Assert.assertEquals(610L , message.getRepeatedField(f("packed_sfixed64"), 0));
+ Assert.assertEquals(611F , message.getRepeatedField(f("packed_float" ), 0));
+ Assert.assertEquals(612D , message.getRepeatedField(f("packed_double" ), 0));
+ Assert.assertEquals(true , message.getRepeatedField(f("packed_bool" ), 0));
+ Assert.assertEquals(foreignBar, message.getRepeatedField(f("packed_enum" ),0));
+ Assert.assertEquals(701 , message.getRepeatedField(f("packed_int32" ), 1));
+ Assert.assertEquals(702L , message.getRepeatedField(f("packed_int64" ), 1));
+ Assert.assertEquals(703 , message.getRepeatedField(f("packed_uint32" ), 1));
+ Assert.assertEquals(704L , message.getRepeatedField(f("packed_uint64" ), 1));
+ Assert.assertEquals(705 , message.getRepeatedField(f("packed_sint32" ), 1));
+ Assert.assertEquals(706L , message.getRepeatedField(f("packed_sint64" ), 1));
+ Assert.assertEquals(707 , message.getRepeatedField(f("packed_fixed32" ), 1));
+ Assert.assertEquals(708L , message.getRepeatedField(f("packed_fixed64" ), 1));
+ Assert.assertEquals(709 , message.getRepeatedField(f("packed_sfixed32"), 1));
+ Assert.assertEquals(710L , message.getRepeatedField(f("packed_sfixed64"), 1));
+ Assert.assertEquals(711F , message.getRepeatedField(f("packed_float" ), 1));
+ Assert.assertEquals(712D , message.getRepeatedField(f("packed_double" ), 1));
+ Assert.assertEquals(false, message.getRepeatedField(f("packed_bool" ), 1));
+ Assert.assertEquals(foreignBaz, message.getRepeatedField(f("packed_enum" ),1));
+ }
+
+ /**
+ * Verifies that the reflection setters for the given.Builder object throw a
+ * NullPointerException if they are passed a null value. Uses Assert to throw an
+ * appropriate assertion failure, if the condition is not verified.
+ */
+ public void assertReflectionSettersRejectNull(Message.Builder builder)
+ throws Exception {
+ try {
+ builder.setField(f("optional_string"), null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setField(f("optional_bytes"), null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setField(f("optional_nested_enum"), null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setField(f("optional_nested_message"),
+ (TestAllTypes.NestedMessage) null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setField(f("optional_nested_message"),
+ (TestAllTypes.NestedMessage.Builder) null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ try {
+ builder.addRepeatedField(f("repeated_string"), null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.addRepeatedField(f("repeated_bytes"), null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.addRepeatedField(f("repeated_nested_enum"), null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.addRepeatedField(f("repeated_nested_message"), null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ }
+
+ /**
+ * Verifies that the reflection repeated setters for the given Builder object throw a
+ * NullPointerException if they are passed a null value. Uses Assert to throw an appropriate
+ * assertion failure, if the condition is not verified.
+ */
+ public void assertReflectionRepeatedSettersRejectNull(Message.Builder builder)
+ throws Exception {
+ builder.addRepeatedField(f("repeated_string"), "one");
+ try {
+ builder.setRepeatedField(f("repeated_string"), 0, null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ builder.addRepeatedField(f("repeated_bytes"), toBytes("one"));
+ try {
+ builder.setRepeatedField(f("repeated_bytes"), 0, null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ builder.addRepeatedField(f("repeated_nested_enum"), nestedBaz);
+ try {
+ builder.setRepeatedField(f("repeated_nested_enum"), 0, null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ builder.addRepeatedField(
+ f("repeated_nested_message"),
+ TestAllTypes.NestedMessage.newBuilder().setBb(218).build());
+ try {
+ builder.setRepeatedField(f("repeated_nested_message"), 0, null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ }
+ }
+
+ /**
+ * @param filePath The path relative to
+ * {@link #getTestDataDir}.
+ */
+ public static String readTextFromFile(String filePath) {
+ return readBytesFromFile(filePath).toStringUtf8();
+ }
+
+ private static File getTestDataDir() {
+ // Search each parent directory looking for "src/google/protobuf".
+ File ancestor = new File(".");
+ try {
+ ancestor = ancestor.getCanonicalFile();
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "Couldn't get canonical name of working directory.", e);
+ }
+ while (ancestor != null && ancestor.exists()) {
+ if (new File(ancestor, "src/google/protobuf").exists()) {
+ return new File(ancestor, "src/google/protobuf/testdata");
+ }
+ ancestor = ancestor.getParentFile();
+ }
+
+ throw new RuntimeException(
+ "Could not find golden files. This test must be run from within the " +
+ "protobuf source package so that it can read test data files from the " +
+ "C++ source tree: " + new File(".").getAbsolutePath());
+ }
+
+ /**
+ * @param filename The path relative to
+ * {@link #getTestDataDir}.
+ */
+ public static ByteString readBytesFromFile(String filename) {
+ File fullPath = new File(getTestDataDir(), filename);
+ try {
+ RandomAccessFile file = new RandomAccessFile(fullPath, "r");
+ byte[] content = new byte[(int) file.length()];
+ file.readFully(content);
+ return ByteString.copyFrom(content);
+ } catch (IOException e) {
+ // Throw a RuntimeException here so that we can call this function from
+ // static initializers.
+ throw new IllegalArgumentException(
+ "Couldn't read file: " + fullPath.getPath(), e);
+ }
+ }
+
+ /**
+ * Get the bytes of the "golden message". This is a serialized TestAllTypes
+ * with all fields set as they would be by
+ * {@link #setAllFields(TestAllTypes.Builder)}, but it is loaded from a file
+ * on disk rather than generated dynamically. The file is actually generated
+ * by C++ code, so testing against it verifies compatibility with C++.
+ */
+ public static ByteString getGoldenMessage() {
+ if (goldenMessage == null) {
+ goldenMessage = readBytesFromFile("golden_message");
+ }
+ return goldenMessage;
+ }
+ private static ByteString goldenMessage = null;
+
+ /**
+ * Get the bytes of the "golden packed fields message". This is a serialized
+ * TestPackedTypes with all fields set as they would be by
+ * {@link #setPackedFields(TestPackedTypes.Builder)}, but it is loaded from a
+ * file on disk rather than generated dynamically. The file is actually
+ * generated by C++ code, so testing against it verifies compatibility with
+ * C++.
+ */
+ public static ByteString getGoldenPackedFieldsMessage() {
+ if (goldenPackedFieldsMessage == null) {
+ goldenPackedFieldsMessage =
+ readBytesFromFile("golden_packed_fields_message");
+ }
+ return goldenPackedFieldsMessage;
+ }
+ private static ByteString goldenPackedFieldsMessage = null;
+
+ public static abstract class HackMessage extends GeneratedMessage {
+ public interface MyInterface extends BuilderParent {
+ }
+ }
+ /**
+ * Mock implementation of {@link GeneratedMessage.BuilderParent} for testing.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+ public static class MockBuilderParent
+ implements HackMessage.MyInterface {
+
+ private int invalidations;
+
+ //@Override (Java 1.6 override semantics, but we must support 1.5)
+ public void markDirty() {
+ invalidations++;
+ }
+
+ public int getInvalidationCount() {
+ return invalidations;
+ }
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/TextFormatTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/TextFormatTest.java
new file mode 100644
index 0000000000..edcc8908a4
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/TextFormatTest.java
@@ -0,0 +1,536 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import com.google.protobuf.Descriptors.FieldDescriptor;
+import protobuf_unittest.UnittestMset.TestMessageSet;
+import protobuf_unittest.UnittestMset.TestMessageSetExtension1;
+import protobuf_unittest.UnittestMset.TestMessageSetExtension2;
+import protobuf_unittest.UnittestProto.OneString;
+import protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestAllTypes.NestedMessage;
+import protobuf_unittest.UnittestProto.TestEmptyMessage;
+
+import junit.framework.TestCase;
+
+import java.io.StringReader;
+
+/**
+ * Test case for {@link TextFormat}.
+ *
+ * TODO(wenboz): ExtensionTest and rest of text_format_unittest.cc.
+ *
+ * @author wenboz@google.com (Wenbo Zhu)
+ */
+public class TextFormatTest extends TestCase {
+
+ // A basic string with different escapable characters for testing.
+ private final static String kEscapeTestString =
+ "\"A string with ' characters \n and \r newlines and \t tabs and \001 "
+ + "slashes \\";
+
+ // A representation of the above string with all the characters escaped.
+ private final static String kEscapeTestStringEscaped =
+ "\\\"A string with \\' characters \\n and \\r newlines "
+ + "and \\t tabs and \\001 slashes \\\\";
+
+ private static String allFieldsSetText = TestUtil.readTextFromFile(
+ "text_format_unittest_data.txt");
+ private static String allExtensionsSetText = TestUtil.readTextFromFile(
+ "text_format_unittest_extensions_data.txt");
+
+ private static String exoticText =
+ "repeated_int32: -1\n" +
+ "repeated_int32: -2147483648\n" +
+ "repeated_int64: -1\n" +
+ "repeated_int64: -9223372036854775808\n" +
+ "repeated_uint32: 4294967295\n" +
+ "repeated_uint32: 2147483648\n" +
+ "repeated_uint64: 18446744073709551615\n" +
+ "repeated_uint64: 9223372036854775808\n" +
+ "repeated_double: 123.0\n" +
+ "repeated_double: 123.5\n" +
+ "repeated_double: 0.125\n" +
+ "repeated_double: .125\n" +
+ "repeated_double: -.125\n" +
+ "repeated_double: 1.23E17\n" +
+ "repeated_double: 1.23E+17\n" +
+ "repeated_double: -1.23e-17\n" +
+ "repeated_double: .23e+17\n" +
+ "repeated_double: -.23E17\n" +
+ "repeated_double: 1.235E22\n" +
+ "repeated_double: 1.235E-18\n" +
+ "repeated_double: 123.456789\n" +
+ "repeated_double: Infinity\n" +
+ "repeated_double: -Infinity\n" +
+ "repeated_double: NaN\n" +
+ "repeated_string: \"\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\"" +
+ "\\341\\210\\264\"\n" +
+ "repeated_bytes: \"\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\"\\376\"\n";
+
+ private static String canonicalExoticText =
+ exoticText.replace(": .", ": 0.").replace(": -.", ": -0.") // short-form double
+ .replace("23e", "23E").replace("E+", "E").replace("0.23E17", "2.3E16");
+
+ private String messageSetText =
+ "[protobuf_unittest.TestMessageSetExtension1] {\n" +
+ " i: 123\n" +
+ "}\n" +
+ "[protobuf_unittest.TestMessageSetExtension2] {\n" +
+ " str: \"foo\"\n" +
+ "}\n";
+
+ /** Print TestAllTypes and compare with golden file. */
+ public void testPrintMessage() throws Exception {
+ String javaText = TextFormat.printToString(TestUtil.getAllSet());
+
+ // Java likes to add a trailing ".0" to floats and doubles. C printf
+ // (with %g format) does not. Our golden files are used for both
+ // C++ and Java TextFormat classes, so we need to conform.
+ javaText = javaText.replace(".0\n", "\n");
+
+ assertEquals(allFieldsSetText, javaText);
+ }
+
+ /** Print TestAllTypes as Builder and compare with golden file. */
+ public void testPrintMessageBuilder() throws Exception {
+ String javaText = TextFormat.printToString(TestUtil.getAllSetBuilder());
+
+ // Java likes to add a trailing ".0" to floats and doubles. C printf
+ // (with %g format) does not. Our golden files are used for both
+ // C++ and Java TextFormat classes, so we need to conform.
+ javaText = javaText.replace(".0\n", "\n");
+
+ assertEquals(allFieldsSetText, javaText);
+ }
+
+ /** Print TestAllExtensions and compare with golden file. */
+ public void testPrintExtensions() throws Exception {
+ String javaText = TextFormat.printToString(TestUtil.getAllExtensionsSet());
+
+ // Java likes to add a trailing ".0" to floats and doubles. C printf
+ // (with %g format) does not. Our golden files are used for both
+ // C++ and Java TextFormat classes, so we need to conform.
+ javaText = javaText.replace(".0\n", "\n");
+
+ assertEquals(allExtensionsSetText, javaText);
+ }
+
+ // Creates an example unknown field set.
+ private UnknownFieldSet makeUnknownFieldSet() {
+ return UnknownFieldSet.newBuilder()
+ .addField(5,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(1)
+ .addFixed32(2)
+ .addFixed64(3)
+ .addLengthDelimited(ByteString.copyFromUtf8("4"))
+ .addGroup(
+ UnknownFieldSet.newBuilder()
+ .addField(10,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(5)
+ .build())
+ .build())
+ .build())
+ .addField(8,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(1)
+ .addVarint(2)
+ .addVarint(3)
+ .build())
+ .addField(15,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(0xABCDEF1234567890L)
+ .addFixed32(0xABCD1234)
+ .addFixed64(0xABCDEF1234567890L)
+ .build())
+ .build();
+ }
+
+ public void testPrintUnknownFields() throws Exception {
+ // Test printing of unknown fields in a message.
+
+ TestEmptyMessage message =
+ TestEmptyMessage.newBuilder()
+ .setUnknownFields(makeUnknownFieldSet())
+ .build();
+
+ assertEquals(
+ "5: 1\n" +
+ "5: 0x00000002\n" +
+ "5: 0x0000000000000003\n" +
+ "5: \"4\"\n" +
+ "5 {\n" +
+ " 10: 5\n" +
+ "}\n" +
+ "8: 1\n" +
+ "8: 2\n" +
+ "8: 3\n" +
+ "15: 12379813812177893520\n" +
+ "15: 0xabcd1234\n" +
+ "15: 0xabcdef1234567890\n",
+ TextFormat.printToString(message));
+ }
+
+ public void testPrintField() throws Exception {
+ final FieldDescriptor dataField =
+ OneString.getDescriptor().findFieldByName("data");
+ assertEquals(
+ "data: \"test data\"\n",
+ TextFormat.printFieldToString(dataField, "test data"));
+
+ final FieldDescriptor optionalField =
+ TestAllTypes.getDescriptor().findFieldByName("optional_nested_message");
+ final Object value = NestedMessage.newBuilder().setBb(42).build();
+
+ assertEquals(
+ "optional_nested_message {\n bb: 42\n}\n",
+ TextFormat.printFieldToString(optionalField, value));
+ }
+
+ /**
+ * Helper to construct a ByteString from a String containing only 8-bit
+ * characters. The characters are converted directly to bytes, *not*
+ * encoded using UTF-8.
+ */
+ private ByteString bytes(String str) throws Exception {
+ return ByteString.copyFrom(str.getBytes("ISO-8859-1"));
+ }
+
+ /**
+ * Helper to construct a ByteString 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 ByteString bytes(int... bytesAsInts) {
+ byte[] bytes = new byte[bytesAsInts.length];
+ for (int i = 0; i < bytesAsInts.length; i++) {
+ bytes[i] = (byte) bytesAsInts[i];
+ }
+ return ByteString.copyFrom(bytes);
+ }
+
+ public void testPrintExotic() throws Exception {
+ Message message = TestAllTypes.newBuilder()
+ // Signed vs. unsigned numbers.
+ .addRepeatedInt32 (-1)
+ .addRepeatedUint32(-1)
+ .addRepeatedInt64 (-1)
+ .addRepeatedUint64(-1)
+
+ .addRepeatedInt32 (1 << 31)
+ .addRepeatedUint32(1 << 31)
+ .addRepeatedInt64 (1l << 63)
+ .addRepeatedUint64(1l << 63)
+
+ // Floats of various precisions and exponents.
+ .addRepeatedDouble(123)
+ .addRepeatedDouble(123.5)
+ .addRepeatedDouble(0.125)
+ .addRepeatedDouble(.125)
+ .addRepeatedDouble(-.125)
+ .addRepeatedDouble(123e15)
+ .addRepeatedDouble(123e15)
+ .addRepeatedDouble(-1.23e-17)
+ .addRepeatedDouble(.23e17)
+ .addRepeatedDouble(-23e15)
+ .addRepeatedDouble(123.5e20)
+ .addRepeatedDouble(123.5e-20)
+ .addRepeatedDouble(123.456789)
+ .addRepeatedDouble(Double.POSITIVE_INFINITY)
+ .addRepeatedDouble(Double.NEGATIVE_INFINITY)
+ .addRepeatedDouble(Double.NaN)
+
+ // Strings and bytes that needing escaping.
+ .addRepeatedString("\0\001\007\b\f\n\r\t\013\\\'\"\u1234")
+ .addRepeatedBytes(bytes("\0\001\007\b\f\n\r\t\013\\\'\"\u00fe"))
+ .build();
+
+ assertEquals(canonicalExoticText, message.toString());
+ }
+
+ public void testPrintMessageSet() throws Exception {
+ TestMessageSet messageSet =
+ TestMessageSet.newBuilder()
+ .setExtension(
+ TestMessageSetExtension1.messageSetExtension,
+ TestMessageSetExtension1.newBuilder().setI(123).build())
+ .setExtension(
+ TestMessageSetExtension2.messageSetExtension,
+ TestMessageSetExtension2.newBuilder().setStr("foo").build())
+ .build();
+
+ assertEquals(messageSetText, messageSet.toString());
+ }
+
+ // =================================================================
+
+ public void testParse() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge(allFieldsSetText, builder);
+ TestUtil.assertAllFieldsSet(builder.build());
+ }
+
+ public void testParseReader() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge(new StringReader(allFieldsSetText), builder);
+ TestUtil.assertAllFieldsSet(builder.build());
+ }
+
+ public void testParseExtensions() throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ TextFormat.merge(allExtensionsSetText,
+ TestUtil.getExtensionRegistry(),
+ builder);
+ TestUtil.assertAllExtensionsSet(builder.build());
+ }
+
+ public void testParseCompatibility() throws Exception {
+ String original = "repeated_float: inf\n" +
+ "repeated_float: -inf\n" +
+ "repeated_float: nan\n" +
+ "repeated_float: inff\n" +
+ "repeated_float: -inff\n" +
+ "repeated_float: nanf\n" +
+ "repeated_float: 1.0f\n" +
+ "repeated_float: infinityf\n" +
+ "repeated_float: -Infinityf\n" +
+ "repeated_double: infinity\n" +
+ "repeated_double: -infinity\n" +
+ "repeated_double: nan\n";
+ String canonical = "repeated_float: Infinity\n" +
+ "repeated_float: -Infinity\n" +
+ "repeated_float: NaN\n" +
+ "repeated_float: Infinity\n" +
+ "repeated_float: -Infinity\n" +
+ "repeated_float: NaN\n" +
+ "repeated_float: 1.0\n" +
+ "repeated_float: Infinity\n" +
+ "repeated_float: -Infinity\n" +
+ "repeated_double: Infinity\n" +
+ "repeated_double: -Infinity\n" +
+ "repeated_double: NaN\n";
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge(original, builder);
+ assertEquals(canonical, builder.build().toString());
+ }
+
+ public void testParseExotic() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge(exoticText, builder);
+
+ // Too lazy to check things individually. Don't try to debug this
+ // if testPrintExotic() is failing.
+ assertEquals(canonicalExoticText, builder.build().toString());
+ }
+
+ public void testParseMessageSet() throws Exception {
+ ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance();
+ extensionRegistry.add(TestMessageSetExtension1.messageSetExtension);
+ extensionRegistry.add(TestMessageSetExtension2.messageSetExtension);
+
+ TestMessageSet.Builder builder = TestMessageSet.newBuilder();
+ TextFormat.merge(messageSetText, extensionRegistry, builder);
+ TestMessageSet messageSet = builder.build();
+
+ assertTrue(messageSet.hasExtension(
+ TestMessageSetExtension1.messageSetExtension));
+ assertEquals(123, messageSet.getExtension(
+ TestMessageSetExtension1.messageSetExtension).getI());
+ assertTrue(messageSet.hasExtension(
+ TestMessageSetExtension2.messageSetExtension));
+ assertEquals("foo", messageSet.getExtension(
+ TestMessageSetExtension2.messageSetExtension).getStr());
+ }
+
+ public void testParseNumericEnum() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge("optional_nested_enum: 2", builder);
+ assertEquals(TestAllTypes.NestedEnum.BAR, builder.getOptionalNestedEnum());
+ }
+
+ public void testParseAngleBrackets() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge("OptionalGroup: < a: 1 >", builder);
+ assertTrue(builder.hasOptionalGroup());
+ assertEquals(1, builder.getOptionalGroup().getA());
+ }
+
+ public void testParseComment() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge(
+ "# this is a comment\n" +
+ "optional_int32: 1 # another comment\n" +
+ "optional_int64: 2\n" +
+ "# EOF comment", builder);
+ assertEquals(1, builder.getOptionalInt32());
+ assertEquals(2, builder.getOptionalInt64());
+ }
+
+ // =================================================================
+
+ public void testParseString() throws Exception {
+ final String zh = "\u9999\u6e2f\u4e0a\u6d77\ud84f\udf80\u8c50\u9280\u884c";
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge("optional_string: \"" + zh + "\"", builder);
+ assertEquals(zh, builder.getOptionalString());
+ }
+
+ public void testParseLongString() throws Exception {
+ String longText =
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890";
+
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge("optional_string: \"" + longText + "\"", builder);
+ assertEquals(longText, builder.getOptionalString());
+ }
+
+ public void testParseBoolean() throws Exception {
+ String goodText =
+ "repeated_bool: t repeated_bool : 0\n" +
+ "repeated_bool :f repeated_bool:1";
+ String goodTextCanonical =
+ "repeated_bool: true\n" +
+ "repeated_bool: false\n" +
+ "repeated_bool: false\n" +
+ "repeated_bool: true\n";
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge(goodText, builder);
+ assertEquals(goodTextCanonical, builder.build().toString());
+
+ try {
+ TestAllTypes.Builder badBuilder = TestAllTypes.newBuilder();
+ TextFormat.merge("optional_bool:2", badBuilder);
+ fail("Should have thrown an exception.");
+ } catch (TextFormat.ParseException e) {
+ // success
+ }
+ try {
+ TestAllTypes.Builder badBuilder = TestAllTypes.newBuilder();
+ TextFormat.merge("optional_bool: foo", badBuilder);
+ fail("Should have thrown an exception.");
+ } catch (TextFormat.ParseException e) {
+ // success
+ }
+ }
+
+ public void testParseAdjacentStringLiterals() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge("optional_string: \"foo\" 'corge' \"grault\"", builder);
+ assertEquals("foocorgegrault", builder.getOptionalString());
+ }
+
+ public void testPrintFieldValue() throws Exception {
+ assertPrintFieldValue("\"Hello\"", "Hello", "repeated_string");
+ assertPrintFieldValue("123.0", 123f, "repeated_float");
+ assertPrintFieldValue("123.0", 123d, "repeated_double");
+ assertPrintFieldValue("123", 123, "repeated_int32");
+ assertPrintFieldValue("123", 123L, "repeated_int64");
+ assertPrintFieldValue("true", true, "repeated_bool");
+ assertPrintFieldValue("4294967295", 0xFFFFFFFF, "repeated_uint32");
+ assertPrintFieldValue("18446744073709551615", 0xFFFFFFFFFFFFFFFFL,
+ "repeated_uint64");
+ assertPrintFieldValue("\"\\001\\002\\003\"",
+ ByteString.copyFrom(new byte[] {1, 2, 3}), "repeated_bytes");
+ }
+
+ private void assertPrintFieldValue(String expect, Object value,
+ String fieldName) throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ StringBuilder sb = new StringBuilder();
+ TextFormat.printFieldValue(
+ TestAllTypes.getDescriptor().findFieldByName(fieldName),
+ value, sb);
+ assertEquals(expect, sb.toString());
+ }
+
+ public void testShortDebugString() {
+ assertEquals("optional_nested_message { bb: 42 } repeated_int32: 1"
+ + " repeated_uint32: 2",
+ TextFormat.shortDebugString(TestAllTypes.newBuilder()
+ .addRepeatedInt32(1)
+ .addRepeatedUint32(2)
+ .setOptionalNestedMessage(
+ NestedMessage.newBuilder().setBb(42).build())
+ .build()));
+ }
+
+ public void testShortDebugString_unknown() {
+ assertEquals("5: 1 5: 0x00000002 5: 0x0000000000000003 5: \"4\" 5 { 10: 5 }"
+ + " 8: 1 8: 2 8: 3 15: 12379813812177893520 15: 0xabcd1234 15:"
+ + " 0xabcdef1234567890",
+ TextFormat.shortDebugString(makeUnknownFieldSet()));
+ }
+
+ public void testPrintToUnicodeString() {
+ assertEquals(
+ "optional_string: \"abc\u3042efg\"\n" +
+ "optional_bytes: \"\\343\\201\\202\"\n" +
+ "repeated_string: \"\u3093XYZ\"\n",
+ TextFormat.printToUnicodeString(TestAllTypes.newBuilder()
+ .setOptionalString("abc\u3042efg")
+ .setOptionalBytes(bytes(0xe3, 0x81, 0x82))
+ .addRepeatedString("\u3093XYZ")
+ .build()));
+ }
+
+ public void testPrintToUnicodeString_unknown() {
+ assertEquals(
+ "1: \"\\343\\201\\202\"\n",
+ TextFormat.printToUnicodeString(UnknownFieldSet.newBuilder()
+ .addField(1,
+ UnknownFieldSet.Field.newBuilder()
+ .addLengthDelimited(bytes(0xe3, 0x81, 0x82)).build())
+ .build()));
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/UnknownFieldSetTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/UnknownFieldSetTest.java
new file mode 100644
index 0000000000..b9bfb691b1
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/UnknownFieldSetTest.java
@@ -0,0 +1,438 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import protobuf_unittest.UnittestProto;
+import protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestEmptyMessage;
+import protobuf_unittest.UnittestProto.TestEmptyMessageWithExtensions;
+
+import junit.framework.TestCase;
+
+import java.util.Arrays;
+import java.util.Map;
+
+/**
+ * Tests related to unknown field handling.
+ *
+ * @author kenton@google.com (Kenton Varda)
+ */
+public class UnknownFieldSetTest extends TestCase {
+ public void setUp() throws Exception {
+ descriptor = TestAllTypes.getDescriptor();
+ allFields = TestUtil.getAllSet();
+ allFieldsData = allFields.toByteString();
+ emptyMessage = TestEmptyMessage.parseFrom(allFieldsData);
+ unknownFields = emptyMessage.getUnknownFields();
+ }
+
+ UnknownFieldSet.Field getField(String name) {
+ Descriptors.FieldDescriptor field = descriptor.findFieldByName(name);
+ assertNotNull(field);
+ return unknownFields.getField(field.getNumber());
+ }
+
+ // Constructs a protocol buffer which contains fields with all the same
+ // numbers as allFieldsData except that each field is some other wire
+ // type.
+ ByteString getBizarroData() throws Exception {
+ UnknownFieldSet.Builder bizarroFields = UnknownFieldSet.newBuilder();
+
+ UnknownFieldSet.Field varintField =
+ UnknownFieldSet.Field.newBuilder().addVarint(1).build();
+ UnknownFieldSet.Field fixed32Field =
+ UnknownFieldSet.Field.newBuilder().addFixed32(1).build();
+
+ for (Map.Entry<Integer, UnknownFieldSet.Field> entry :
+ unknownFields.asMap().entrySet()) {
+ if (entry.getValue().getVarintList().isEmpty()) {
+ // Original field is not a varint, so use a varint.
+ bizarroFields.addField(entry.getKey(), varintField);
+ } else {
+ // Original field *is* a varint, so use something else.
+ bizarroFields.addField(entry.getKey(), fixed32Field);
+ }
+ }
+
+ return bizarroFields.build().toByteString();
+ }
+
+ Descriptors.Descriptor descriptor;
+ TestAllTypes allFields;
+ ByteString allFieldsData;
+
+ // An empty message that has been parsed from allFieldsData. So, it has
+ // unknown fields of every type.
+ TestEmptyMessage emptyMessage;
+ UnknownFieldSet unknownFields;
+
+ // =================================================================
+
+ public void testVarint() throws Exception {
+ UnknownFieldSet.Field field = getField("optional_int32");
+ assertEquals(1, field.getVarintList().size());
+ assertEquals(allFields.getOptionalInt32(),
+ (long) field.getVarintList().get(0));
+ }
+
+ public void testFixed32() throws Exception {
+ UnknownFieldSet.Field field = getField("optional_fixed32");
+ assertEquals(1, field.getFixed32List().size());
+ assertEquals(allFields.getOptionalFixed32(),
+ (int) field.getFixed32List().get(0));
+ }
+
+ public void testFixed64() throws Exception {
+ UnknownFieldSet.Field field = getField("optional_fixed64");
+ assertEquals(1, field.getFixed64List().size());
+ assertEquals(allFields.getOptionalFixed64(),
+ (long) field.getFixed64List().get(0));
+ }
+
+ public void testLengthDelimited() throws Exception {
+ UnknownFieldSet.Field field = getField("optional_bytes");
+ assertEquals(1, field.getLengthDelimitedList().size());
+ assertEquals(allFields.getOptionalBytes(),
+ field.getLengthDelimitedList().get(0));
+ }
+
+ public void testGroup() throws Exception {
+ Descriptors.FieldDescriptor nestedFieldDescriptor =
+ TestAllTypes.OptionalGroup.getDescriptor().findFieldByName("a");
+ assertNotNull(nestedFieldDescriptor);
+
+ UnknownFieldSet.Field field = getField("optionalgroup");
+ assertEquals(1, field.getGroupList().size());
+
+ UnknownFieldSet group = field.getGroupList().get(0);
+ assertEquals(1, group.asMap().size());
+ assertTrue(group.hasField(nestedFieldDescriptor.getNumber()));
+
+ UnknownFieldSet.Field nestedField =
+ group.getField(nestedFieldDescriptor.getNumber());
+ assertEquals(1, nestedField.getVarintList().size());
+ assertEquals(allFields.getOptionalGroup().getA(),
+ (long) nestedField.getVarintList().get(0));
+ }
+
+ public void testSerialize() throws Exception {
+ // Check that serializing the UnknownFieldSet produces the original data
+ // again.
+ ByteString data = emptyMessage.toByteString();
+ assertEquals(allFieldsData, data);
+ }
+
+ public void testCopyFrom() throws Exception {
+ TestEmptyMessage message =
+ TestEmptyMessage.newBuilder().mergeFrom(emptyMessage).build();
+
+ assertEquals(emptyMessage.toString(), message.toString());
+ }
+
+ public void testMergeFrom() throws Exception {
+ TestEmptyMessage source =
+ TestEmptyMessage.newBuilder()
+ .setUnknownFields(
+ UnknownFieldSet.newBuilder()
+ .addField(2,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(2).build())
+ .addField(3,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(4).build())
+ .build())
+ .build();
+ TestEmptyMessage destination =
+ TestEmptyMessage.newBuilder()
+ .setUnknownFields(
+ UnknownFieldSet.newBuilder()
+ .addField(1,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(1).build())
+ .addField(3,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(3).build())
+ .build())
+ .mergeFrom(source)
+ .build();
+
+ assertEquals(
+ "1: 1\n" +
+ "2: 2\n" +
+ "3: 3\n" +
+ "3: 4\n",
+ destination.toString());
+ }
+
+ public void testClear() throws Exception {
+ UnknownFieldSet fields =
+ UnknownFieldSet.newBuilder().mergeFrom(unknownFields).clear().build();
+ assertTrue(fields.asMap().isEmpty());
+ }
+
+ public void testClearMessage() throws Exception {
+ TestEmptyMessage message =
+ TestEmptyMessage.newBuilder().mergeFrom(emptyMessage).clear().build();
+ assertEquals(0, message.getSerializedSize());
+ }
+
+ public void testParseKnownAndUnknown() throws Exception {
+ // Test mixing known and unknown fields when parsing.
+
+ UnknownFieldSet fields =
+ UnknownFieldSet.newBuilder(unknownFields)
+ .addField(123456,
+ UnknownFieldSet.Field.newBuilder().addVarint(654321).build())
+ .build();
+
+ ByteString data = fields.toByteString();
+ TestAllTypes destination = TestAllTypes.parseFrom(data);
+
+ TestUtil.assertAllFieldsSet(destination);
+ assertEquals(1, destination.getUnknownFields().asMap().size());
+
+ UnknownFieldSet.Field field =
+ destination.getUnknownFields().getField(123456);
+ assertEquals(1, field.getVarintList().size());
+ assertEquals(654321, (long) field.getVarintList().get(0));
+ }
+
+ public void testWrongTypeTreatedAsUnknown() throws Exception {
+ // Test that fields of the wrong wire type are treated like unknown fields
+ // when parsing.
+
+ ByteString bizarroData = getBizarroData();
+ TestAllTypes allTypesMessage = TestAllTypes.parseFrom(bizarroData);
+ TestEmptyMessage emptyMessage = TestEmptyMessage.parseFrom(bizarroData);
+
+ // All fields should have been interpreted as unknown, so the debug strings
+ // should be the same.
+ assertEquals(emptyMessage.toString(), allTypesMessage.toString());
+ }
+
+ public void testUnknownExtensions() throws Exception {
+ // Make sure fields are properly parsed to the UnknownFieldSet even when
+ // they are declared as extension numbers.
+
+ TestEmptyMessageWithExtensions message =
+ TestEmptyMessageWithExtensions.parseFrom(allFieldsData);
+
+ assertEquals(unknownFields.asMap().size(),
+ message.getUnknownFields().asMap().size());
+ assertEquals(allFieldsData, message.toByteString());
+ }
+
+ public void testWrongExtensionTypeTreatedAsUnknown() throws Exception {
+ // Test that fields of the wrong wire type are treated like unknown fields
+ // when parsing extensions.
+
+ ByteString bizarroData = getBizarroData();
+ TestAllExtensions allExtensionsMessage =
+ TestAllExtensions.parseFrom(bizarroData);
+ TestEmptyMessage emptyMessage = TestEmptyMessage.parseFrom(bizarroData);
+
+ // All fields should have been interpreted as unknown, so the debug strings
+ // should be the same.
+ assertEquals(emptyMessage.toString(),
+ allExtensionsMessage.toString());
+ }
+
+ public void testParseUnknownEnumValue() throws Exception {
+ Descriptors.FieldDescriptor singularField =
+ TestAllTypes.getDescriptor().findFieldByName("optional_nested_enum");
+ Descriptors.FieldDescriptor repeatedField =
+ TestAllTypes.getDescriptor().findFieldByName("repeated_nested_enum");
+ assertNotNull(singularField);
+ assertNotNull(repeatedField);
+
+ ByteString data =
+ UnknownFieldSet.newBuilder()
+ .addField(singularField.getNumber(),
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(TestAllTypes.NestedEnum.BAR.getNumber())
+ .addVarint(5) // not valid
+ .build())
+ .addField(repeatedField.getNumber(),
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(TestAllTypes.NestedEnum.FOO.getNumber())
+ .addVarint(4) // not valid
+ .addVarint(TestAllTypes.NestedEnum.BAZ.getNumber())
+ .addVarint(6) // not valid
+ .build())
+ .build()
+ .toByteString();
+
+ {
+ TestAllTypes message = TestAllTypes.parseFrom(data);
+ assertEquals(TestAllTypes.NestedEnum.BAR,
+ message.getOptionalNestedEnum());
+ assertEquals(
+ Arrays.asList(TestAllTypes.NestedEnum.FOO, TestAllTypes.NestedEnum.BAZ),
+ message.getRepeatedNestedEnumList());
+ assertEquals(Arrays.asList(5L),
+ message.getUnknownFields()
+ .getField(singularField.getNumber())
+ .getVarintList());
+ assertEquals(Arrays.asList(4L, 6L),
+ message.getUnknownFields()
+ .getField(repeatedField.getNumber())
+ .getVarintList());
+ }
+
+ {
+ TestAllExtensions message =
+ TestAllExtensions.parseFrom(data, TestUtil.getExtensionRegistry());
+ assertEquals(TestAllTypes.NestedEnum.BAR,
+ message.getExtension(UnittestProto.optionalNestedEnumExtension));
+ assertEquals(
+ Arrays.asList(TestAllTypes.NestedEnum.FOO, TestAllTypes.NestedEnum.BAZ),
+ message.getExtension(UnittestProto.repeatedNestedEnumExtension));
+ assertEquals(Arrays.asList(5L),
+ message.getUnknownFields()
+ .getField(singularField.getNumber())
+ .getVarintList());
+ assertEquals(Arrays.asList(4L, 6L),
+ message.getUnknownFields()
+ .getField(repeatedField.getNumber())
+ .getVarintList());
+ }
+ }
+
+ public void testLargeVarint() throws Exception {
+ ByteString data =
+ UnknownFieldSet.newBuilder()
+ .addField(1,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(0x7FFFFFFFFFFFFFFFL)
+ .build())
+ .build()
+ .toByteString();
+ UnknownFieldSet parsed = UnknownFieldSet.parseFrom(data);
+ UnknownFieldSet.Field field = parsed.getField(1);
+ assertEquals(1, field.getVarintList().size());
+ assertEquals(0x7FFFFFFFFFFFFFFFL, (long)field.getVarintList().get(0));
+ }
+
+ public void testEqualsAndHashCode() {
+ UnknownFieldSet.Field fixed32Field =
+ UnknownFieldSet.Field.newBuilder()
+ .addFixed32(1)
+ .build();
+ UnknownFieldSet.Field fixed64Field =
+ UnknownFieldSet.Field.newBuilder()
+ .addFixed64(1)
+ .build();
+ UnknownFieldSet.Field varIntField =
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(1)
+ .build();
+ UnknownFieldSet.Field lengthDelimitedField =
+ UnknownFieldSet.Field.newBuilder()
+ .addLengthDelimited(ByteString.EMPTY)
+ .build();
+ UnknownFieldSet.Field groupField =
+ UnknownFieldSet.Field.newBuilder()
+ .addGroup(unknownFields)
+ .build();
+
+ UnknownFieldSet a =
+ UnknownFieldSet.newBuilder()
+ .addField(1, fixed32Field)
+ .build();
+ UnknownFieldSet b =
+ UnknownFieldSet.newBuilder()
+ .addField(1, fixed64Field)
+ .build();
+ UnknownFieldSet c =
+ UnknownFieldSet.newBuilder()
+ .addField(1, varIntField)
+ .build();
+ UnknownFieldSet d =
+ UnknownFieldSet.newBuilder()
+ .addField(1, lengthDelimitedField)
+ .build();
+ UnknownFieldSet e =
+ UnknownFieldSet.newBuilder()
+ .addField(1, groupField)
+ .build();
+
+ checkEqualsIsConsistent(a);
+ checkEqualsIsConsistent(b);
+ checkEqualsIsConsistent(c);
+ checkEqualsIsConsistent(d);
+ checkEqualsIsConsistent(e);
+
+ checkNotEqual(a, b);
+ checkNotEqual(a, c);
+ checkNotEqual(a, d);
+ checkNotEqual(a, e);
+ checkNotEqual(b, c);
+ checkNotEqual(b, d);
+ checkNotEqual(b, e);
+ checkNotEqual(c, d);
+ checkNotEqual(c, e);
+ checkNotEqual(d, e);
+ }
+
+ /**
+ * Asserts that the given field sets are not equal and have different
+ * hash codes.
+ *
+ * @warning It's valid for non-equal objects to have the same hash code, so
+ * this test is stricter than it needs to be. However, this should happen
+ * relatively rarely.
+ */
+ private void checkNotEqual(UnknownFieldSet s1, UnknownFieldSet s2) {
+ String equalsError = String.format("%s should not be equal to %s", s1, s2);
+ assertFalse(equalsError, s1.equals(s2));
+ assertFalse(equalsError, s2.equals(s1));
+
+ assertFalse(
+ String.format("%s should have a different hash code from %s", s1, s2),
+ s1.hashCode() == s2.hashCode());
+ }
+
+ /**
+ * Asserts that the given field sets are equal and have identical hash codes.
+ */
+ private void checkEqualsIsConsistent(UnknownFieldSet set) {
+ // Object should be equal to itself.
+ assertEquals(set, set);
+
+ // Object should be equal to a copy of itself.
+ UnknownFieldSet copy = UnknownFieldSet.newBuilder(set).build();
+ assertEquals(set, copy);
+ assertEquals(copy, set);
+ assertEquals(set.hashCode(), copy.hashCode());
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/UnmodifiableLazyStringListTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/UnmodifiableLazyStringListTest.java
new file mode 100644
index 0000000000..cb75d74b0c
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/UnmodifiableLazyStringListTest.java
@@ -0,0 +1,153 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import junit.framework.TestCase;
+
+import java.util.Iterator;
+import java.util.ListIterator;
+
+/**
+ * Tests for {@link UnmodifiableLazyStringList}.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class UnmodifiableLazyStringListTest extends TestCase {
+
+ private static String STRING_A = "A";
+ private static String STRING_B = "B";
+ private static String STRING_C = "C";
+
+ private static ByteString BYTE_STRING_A = ByteString.copyFromUtf8("A");
+ private static ByteString BYTE_STRING_B = ByteString.copyFromUtf8("B");
+ private static ByteString BYTE_STRING_C = ByteString.copyFromUtf8("C");
+
+ public void testReadOnlyMethods() {
+ LazyStringArrayList rawList = createSampleList();
+ UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
+ assertEquals(3, list.size());
+ assertSame(STRING_A, list.get(0));
+ assertSame(STRING_B, list.get(1));
+ assertSame(STRING_C, list.get(2));
+ assertEquals(BYTE_STRING_A, list.getByteString(0));
+ assertEquals(BYTE_STRING_B, list.getByteString(1));
+ assertEquals(BYTE_STRING_C, list.getByteString(2));
+ }
+
+ public void testModifyMethods() {
+ LazyStringArrayList rawList = createSampleList();
+ UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
+
+ try {
+ list.remove(0);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(3, list.size());
+
+ try {
+ list.add(STRING_B);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(3, list.size());
+
+ try {
+ list.set(1, STRING_B);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ public void testIterator() {
+ LazyStringArrayList rawList = createSampleList();
+ UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
+
+ Iterator<String> iter = list.iterator();
+ int count = 0;
+ while (iter.hasNext()) {
+ iter.next();
+ count++;
+ try {
+ iter.remove();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+ assertEquals(3, count);
+
+ }
+
+ public void testListIterator() {
+ LazyStringArrayList rawList = createSampleList();
+ UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
+
+ ListIterator<String> iter = list.listIterator();
+ int count = 0;
+ while (iter.hasNext()) {
+ iter.next();
+ count++;
+ try {
+ iter.remove();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ iter.set("bar");
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ iter.add("bar");
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+ assertEquals(3, count);
+
+ }
+
+ private LazyStringArrayList createSampleList() {
+ LazyStringArrayList rawList = new LazyStringArrayList();
+ rawList.add(STRING_A);
+ rawList.add(STRING_B);
+ rawList.add(STRING_C);
+ return rawList;
+ }
+}
diff --git a/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/WireFormatTest.java b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/WireFormatTest.java
new file mode 100644
index 0000000000..7452872620
--- /dev/null
+++ b/third_party/protobuf/java/compatibility_tests/v2.5.0/tests/src/main/java/com/google/protobuf/test/WireFormatTest.java
@@ -0,0 +1,465 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.test;
+import com.google.protobuf.*;
+
+import junit.framework.TestCase;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.List;
+
+import protobuf_unittest.UnittestProto;
+import protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestFieldOrderings;
+import protobuf_unittest.UnittestProto.TestPackedExtensions;
+import protobuf_unittest.UnittestProto.TestPackedTypes;
+import protobuf_unittest.UnittestMset.TestMessageSet;
+import protobuf_unittest.UnittestMset.RawMessageSet;
+import protobuf_unittest.UnittestMset.TestMessageSetExtension1;
+import protobuf_unittest.UnittestMset.TestMessageSetExtension2;
+
+/**
+ * Tests related to parsing and serialization.
+ *
+ * @author kenton@google.com (Kenton Varda)
+ */
+public class WireFormatTest extends TestCase {
+ public void testSerialization() throws Exception {
+ TestAllTypes message = TestUtil.getAllSet();
+
+ ByteString rawBytes = message.toByteString();
+ assertEquals(rawBytes.size(), message.getSerializedSize());
+
+ TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
+
+ TestUtil.assertAllFieldsSet(message2);
+ }
+
+ public void testSerializationPacked() throws Exception {
+ TestPackedTypes message = TestUtil.getPackedSet();
+
+ ByteString rawBytes = message.toByteString();
+ assertEquals(rawBytes.size(), message.getSerializedSize());
+
+ TestPackedTypes message2 = TestPackedTypes.parseFrom(rawBytes);
+
+ TestUtil.assertPackedFieldsSet(message2);
+ }
+
+ public void testSerializeExtensions() throws Exception {
+ // TestAllTypes and TestAllExtensions should have compatible wire formats,
+ // so if we serialize a TestAllExtensions then parse it as TestAllTypes
+ // it should work.
+
+ TestAllExtensions message = TestUtil.getAllExtensionsSet();
+ ByteString rawBytes = message.toByteString();
+ assertEquals(rawBytes.size(), message.getSerializedSize());
+
+ TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
+
+ TestUtil.assertAllFieldsSet(message2);
+ }
+
+ public void testSerializePackedExtensions() throws Exception {
+ // TestPackedTypes and TestPackedExtensions should have compatible wire
+ // formats; check that they serialize to the same string.
+ TestPackedExtensions message = TestUtil.getPackedExtensionsSet();
+ ByteString rawBytes = message.toByteString();
+
+ TestPackedTypes message2 = TestUtil.getPackedSet();
+ ByteString rawBytes2 = message2.toByteString();
+
+ assertEquals(rawBytes, rawBytes2);
+ }
+
+ public void testSerializationPackedWithoutGetSerializedSize()
+ throws Exception {
+ // Write directly to an OutputStream, without invoking getSerializedSize()
+ // This used to be a bug where the size of a packed field was incorrect,
+ // since getSerializedSize() was never invoked.
+ TestPackedTypes message = TestUtil.getPackedSet();
+
+ // Directly construct a CodedOutputStream around the actual OutputStream,
+ // in case writeTo(OutputStream output) invokes getSerializedSize();
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ CodedOutputStream codedOutput = CodedOutputStream.newInstance(outputStream);
+
+ message.writeTo(codedOutput);
+
+ codedOutput.flush();
+
+ TestPackedTypes message2 = TestPackedTypes.parseFrom(
+ outputStream.toByteArray());
+
+ TestUtil.assertPackedFieldsSet(message2);
+ }
+
+ public void testParseExtensions() throws Exception {
+ // TestAllTypes and TestAllExtensions should have compatible wire formats,
+ // so if we serialize a TestAllTypes then parse it as TestAllExtensions
+ // it should work.
+
+ TestAllTypes message = TestUtil.getAllSet();
+ ByteString rawBytes = message.toByteString();
+
+ ExtensionRegistry registry = TestUtil.getExtensionRegistry();
+
+ TestAllExtensions message2 =
+ TestAllExtensions.parseFrom(rawBytes, registry);
+
+ TestUtil.assertAllExtensionsSet(message2);
+ }
+
+ public void testParsePackedExtensions() throws Exception {
+ // Ensure that packed extensions can be properly parsed.
+ TestPackedExtensions message = TestUtil.getPackedExtensionsSet();
+ ByteString rawBytes = message.toByteString();
+
+ ExtensionRegistry registry = TestUtil.getExtensionRegistry();
+
+ TestPackedExtensions message2 =
+ TestPackedExtensions.parseFrom(rawBytes, registry);
+
+ TestUtil.assertPackedExtensionsSet(message2);
+ }
+
+ public void testExtensionsSerializedSize() throws Exception {
+ assertEquals(TestUtil.getAllSet().getSerializedSize(),
+ TestUtil.getAllExtensionsSet().getSerializedSize());
+ }
+
+ public void testSerializeDelimited() throws Exception {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ TestUtil.getAllSet().writeDelimitedTo(output);
+ output.write(12);
+ TestUtil.getPackedSet().writeDelimitedTo(output);
+ output.write(34);
+
+ ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
+
+ TestUtil.assertAllFieldsSet(TestAllTypes.parseDelimitedFrom(input));
+ assertEquals(12, input.read());
+ TestUtil.assertPackedFieldsSet(TestPackedTypes.parseDelimitedFrom(input));
+ assertEquals(34, input.read());
+ assertEquals(-1, input.read());
+
+ // We're at EOF, so parsing again should return null.
+ assertTrue(TestAllTypes.parseDelimitedFrom(input) == null);
+ }
+
+ private void assertFieldsInOrder(ByteString data) throws Exception {
+ CodedInputStream input = data.newCodedInput();
+ int previousTag = 0;
+
+ while (true) {
+ int tag = input.readTag();
+ if (tag == 0) {
+ break;
+ }
+
+ assertTrue(tag > previousTag);
+ previousTag = tag;
+ input.skipField(tag);
+ }
+ }
+
+ public void testInterleavedFieldsAndExtensions() throws Exception {
+ // Tests that fields are written in order even when extension ranges
+ // are interleaved with field numbers.
+ ByteString data =
+ TestFieldOrderings.newBuilder()
+ .setMyInt(1)
+ .setMyString("foo")
+ .setMyFloat(1.0F)
+ .setExtension(UnittestProto.myExtensionInt, 23)
+ .setExtension(UnittestProto.myExtensionString, "bar")
+ .build().toByteString();
+ assertFieldsInOrder(data);
+
+ Descriptors.Descriptor descriptor = TestFieldOrderings.getDescriptor();
+ ByteString dynamic_data =
+ DynamicMessage.newBuilder(TestFieldOrderings.getDescriptor())
+ .setField(descriptor.findFieldByName("my_int"), 1L)
+ .setField(descriptor.findFieldByName("my_string"), "foo")
+ .setField(descriptor.findFieldByName("my_float"), 1.0F)
+ .setField(UnittestProto.myExtensionInt.getDescriptor(), 23)
+ .setField(UnittestProto.myExtensionString.getDescriptor(), "bar")
+ .build().toByteString();
+ assertFieldsInOrder(dynamic_data);
+ }
+
+ private ExtensionRegistry getTestFieldOrderingsRegistry() {
+ ExtensionRegistry result = ExtensionRegistry.newInstance();
+ result.add(UnittestProto.myExtensionInt);
+ result.add(UnittestProto.myExtensionString);
+ return result;
+ }
+
+ public void testParseMultipleExtensionRanges() throws Exception {
+ // Make sure we can parse a message that contains multiple extensions
+ // ranges.
+ TestFieldOrderings source =
+ TestFieldOrderings.newBuilder()
+ .setMyInt(1)
+ .setMyString("foo")
+ .setMyFloat(1.0F)
+ .setExtension(UnittestProto.myExtensionInt, 23)
+ .setExtension(UnittestProto.myExtensionString, "bar")
+ .build();
+ TestFieldOrderings dest =
+ TestFieldOrderings.parseFrom(source.toByteString(),
+ getTestFieldOrderingsRegistry());
+ assertEquals(source, dest);
+ }
+
+ public void testParseMultipleExtensionRangesDynamic() throws Exception {
+ // Same as above except with DynamicMessage.
+ Descriptors.Descriptor descriptor = TestFieldOrderings.getDescriptor();
+ DynamicMessage source =
+ DynamicMessage.newBuilder(TestFieldOrderings.getDescriptor())
+ .setField(descriptor.findFieldByName("my_int"), 1L)
+ .setField(descriptor.findFieldByName("my_string"), "foo")
+ .setField(descriptor.findFieldByName("my_float"), 1.0F)
+ .setField(UnittestProto.myExtensionInt.getDescriptor(), 23)
+ .setField(UnittestProto.myExtensionString.getDescriptor(), "bar")
+ .build();
+ DynamicMessage dest =
+ DynamicMessage.parseFrom(descriptor, source.toByteString(),
+ getTestFieldOrderingsRegistry());
+ assertEquals(source, dest);
+ }
+
+ private static final int UNKNOWN_TYPE_ID = 1550055;
+ private static final int TYPE_ID_1 =
+ TestMessageSetExtension1.getDescriptor().getExtensions().get(0).getNumber();
+ private static final int TYPE_ID_2 =
+ TestMessageSetExtension2.getDescriptor().getExtensions().get(0).getNumber();
+
+ public void testSerializeMessageSetEagerly() throws Exception {
+ testSerializeMessageSetWithFlag(true);
+ }
+
+ public void testSerializeMessageSetNotEagerly() throws Exception {
+ testSerializeMessageSetWithFlag(false);
+ }
+
+ private void testSerializeMessageSetWithFlag(boolean eagerParsing)
+ throws Exception {
+ ExtensionRegistryLite.setEagerlyParseMessageSets(eagerParsing);
+ // Set up a TestMessageSet with two known messages and an unknown one.
+ TestMessageSet messageSet =
+ TestMessageSet.newBuilder()
+ .setExtension(
+ TestMessageSetExtension1.messageSetExtension,
+ TestMessageSetExtension1.newBuilder().setI(123).build())
+ .setExtension(
+ TestMessageSetExtension2.messageSetExtension,
+ TestMessageSetExtension2.newBuilder().setStr("foo").build())
+ .setUnknownFields(
+ UnknownFieldSet.newBuilder()
+ .addField(UNKNOWN_TYPE_ID,
+ UnknownFieldSet.Field.newBuilder()
+ .addLengthDelimited(ByteString.copyFromUtf8("bar"))
+ .build())
+ .build())
+ .build();
+
+ ByteString data = messageSet.toByteString();
+
+ // Parse back using RawMessageSet and check the contents.
+ RawMessageSet raw = RawMessageSet.parseFrom(data);
+
+ assertTrue(raw.getUnknownFields().asMap().isEmpty());
+
+ assertEquals(3, raw.getItemCount());
+ assertEquals(TYPE_ID_1, raw.getItem(0).getTypeId());
+ assertEquals(TYPE_ID_2, raw.getItem(1).getTypeId());
+ assertEquals(UNKNOWN_TYPE_ID, raw.getItem(2).getTypeId());
+
+ TestMessageSetExtension1 message1 =
+ TestMessageSetExtension1.parseFrom(
+ raw.getItem(0).getMessage().toByteArray());
+ assertEquals(123, message1.getI());
+
+ TestMessageSetExtension2 message2 =
+ TestMessageSetExtension2.parseFrom(
+ raw.getItem(1).getMessage().toByteArray());
+ assertEquals("foo", message2.getStr());
+
+ assertEquals("bar", raw.getItem(2).getMessage().toStringUtf8());
+ }
+
+ public void testParseMessageSetEagerly() throws Exception {
+ testParseMessageSetWithFlag(true);
+ }
+
+ public void testParseMessageSetNotEagerly()throws Exception {
+ testParseMessageSetWithFlag(false);
+ }
+
+ private void testParseMessageSetWithFlag(boolean eagerParsing)
+ throws Exception {
+ ExtensionRegistryLite.setEagerlyParseMessageSets(eagerParsing);
+ ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance();
+ extensionRegistry.add(TestMessageSetExtension1.messageSetExtension);
+ extensionRegistry.add(TestMessageSetExtension2.messageSetExtension);
+
+ // Set up a RawMessageSet with two known messages and an unknown one.
+ RawMessageSet raw =
+ RawMessageSet.newBuilder()
+ .addItem(
+ RawMessageSet.Item.newBuilder()
+ .setTypeId(TYPE_ID_1)
+ .setMessage(
+ TestMessageSetExtension1.newBuilder()
+ .setI(123)
+ .build().toByteString())
+ .build())
+ .addItem(
+ RawMessageSet.Item.newBuilder()
+ .setTypeId(TYPE_ID_2)
+ .setMessage(
+ TestMessageSetExtension2.newBuilder()
+ .setStr("foo")
+ .build().toByteString())
+ .build())
+ .addItem(
+ RawMessageSet.Item.newBuilder()
+ .setTypeId(UNKNOWN_TYPE_ID)
+ .setMessage(ByteString.copyFromUtf8("bar"))
+ .build())
+ .build();
+
+ ByteString data = raw.toByteString();
+
+ // Parse as a TestMessageSet and check the contents.
+ TestMessageSet messageSet =
+ TestMessageSet.parseFrom(data, extensionRegistry);
+
+ assertEquals(123, messageSet.getExtension(
+ TestMessageSetExtension1.messageSetExtension).getI());
+ assertEquals("foo", messageSet.getExtension(
+ TestMessageSetExtension2.messageSetExtension).getStr());
+
+ // Check for unknown field with type LENGTH_DELIMITED,
+ // number UNKNOWN_TYPE_ID, and contents "bar".
+ UnknownFieldSet unknownFields = messageSet.getUnknownFields();
+ assertEquals(1, unknownFields.asMap().size());
+ assertTrue(unknownFields.hasField(UNKNOWN_TYPE_ID));
+
+ UnknownFieldSet.Field field = unknownFields.getField(UNKNOWN_TYPE_ID);
+ assertEquals(1, field.getLengthDelimitedList().size());
+ assertEquals("bar", field.getLengthDelimitedList().get(0).toStringUtf8());
+ }
+
+ public void testParseMessageSetExtensionEagerly() throws Exception {
+ testParseMessageSetExtensionWithFlag(true);
+ }
+
+ public void testParseMessageSetExtensionNotEagerly() throws Exception {
+ testParseMessageSetExtensionWithFlag(false);
+ }
+
+ private void testParseMessageSetExtensionWithFlag(boolean eagerParsing)
+ throws Exception {
+ ExtensionRegistryLite.setEagerlyParseMessageSets(eagerParsing);
+ ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance();
+ extensionRegistry.add(TestMessageSetExtension1.messageSetExtension);
+
+ // Set up a RawMessageSet with a known messages.
+ int TYPE_ID_1 =
+ TestMessageSetExtension1
+ .getDescriptor().getExtensions().get(0).getNumber();
+ RawMessageSet raw =
+ RawMessageSet.newBuilder()
+ .addItem(
+ RawMessageSet.Item.newBuilder()
+ .setTypeId(TYPE_ID_1)
+ .setMessage(
+ TestMessageSetExtension1.newBuilder()
+ .setI(123)
+ .build().toByteString())
+ .build())
+ .build();
+
+ ByteString data = raw.toByteString();
+
+ // Parse as a TestMessageSet and check the contents.
+ TestMessageSet messageSet =
+ TestMessageSet.parseFrom(data, extensionRegistry);
+ assertEquals(123, messageSet.getExtension(
+ TestMessageSetExtension1.messageSetExtension).getI());
+ }
+
+ public void testMergeLazyMessageSetExtensionEagerly() throws Exception {
+ testMergeLazyMessageSetExtensionWithFlag(true);
+ }
+
+ public void testMergeLazyMessageSetExtensionNotEagerly() throws Exception {
+ testMergeLazyMessageSetExtensionWithFlag(false);
+ }
+
+ private void testMergeLazyMessageSetExtensionWithFlag(boolean eagerParsing)
+ throws Exception {
+ ExtensionRegistryLite.setEagerlyParseMessageSets(eagerParsing);
+ ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance();
+ extensionRegistry.add(TestMessageSetExtension1.messageSetExtension);
+
+ // Set up a RawMessageSet with a known messages.
+ int TYPE_ID_1 =
+ TestMessageSetExtension1
+ .getDescriptor().getExtensions().get(0).getNumber();
+ RawMessageSet raw =
+ RawMessageSet.newBuilder()
+ .addItem(
+ RawMessageSet.Item.newBuilder()
+ .setTypeId(TYPE_ID_1)
+ .setMessage(
+ TestMessageSetExtension1.newBuilder()
+ .setI(123)
+ .build().toByteString())
+ .build())
+ .build();
+
+ ByteString data = raw.toByteString();
+
+ // Parse as a TestMessageSet and store value into lazy field
+ TestMessageSet messageSet =
+ TestMessageSet.parseFrom(data, extensionRegistry);
+ // Merge lazy field check the contents.
+ messageSet =
+ messageSet.toBuilder().mergeFrom(data, extensionRegistry).build();
+ assertEquals(123, messageSet.getExtension(
+ TestMessageSetExtension1.messageSetExtension).getI());
+ }
+}
diff --git a/third_party/protobuf/java/core/generate-sources-build.xml b/third_party/protobuf/java/core/generate-sources-build.xml
new file mode 100644
index 0000000000..0996e5fff4
--- /dev/null
+++ b/third_party/protobuf/java/core/generate-sources-build.xml
@@ -0,0 +1,20 @@
+<project name="generate-sources">
+ <echo message="Running protoc ..."/>
+ <mkdir dir="${generated.sources.dir}"/>
+ <exec executable="${protoc}">
+ <arg value="--java_out=${generated.sources.dir}"/>
+ <arg value="--proto_path=${protobuf.source.dir}"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/any.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/api.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/descriptor.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/duration.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/empty.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/field_mask.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/source_context.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/struct.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/timestamp.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/type.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/wrappers.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/compiler/plugin.proto"/>
+ </exec>
+</project> \ No newline at end of file
diff --git a/third_party/protobuf/java/core/generate-test-sources-build.xml b/third_party/protobuf/java/core/generate-test-sources-build.xml
new file mode 100644
index 0000000000..ab415db688
--- /dev/null
+++ b/third_party/protobuf/java/core/generate-test-sources-build.xml
@@ -0,0 +1,43 @@
+<project name="generate-test-sources">
+ <mkdir dir="${generated.testsources.dir}"/>
+ <exec executable="${protoc}">
+ <arg value="--java_out=${generated.testsources.dir}"/>
+ <arg value="--proto_path=${protobuf.source.dir}"/>
+ <arg value="--proto_path=${test.proto.dir}"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_import.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_import_public.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_mset.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_mset_wire_format.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_optimize_for.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_custom_options.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_lite.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_import_lite.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_import_public_lite.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_lite_imports_nonlite.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_enormous_descriptor.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_no_generic_services.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_well_known_types.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/lazy_fields_lite.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/lite_equals_and_hash.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/multiple_files_test.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/nested_builders_test.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/nested_extension.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/nested_extension_lite.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/non_nested_extension.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/non_nested_extension_lite.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/outer_class_name_test.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/outer_class_name_test2.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/outer_class_name_test3.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/test_bad_identifiers.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/test_check_utf8.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/test_check_utf8_size.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/test_custom_options.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/any_test.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/field_presence_test.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/map_for_proto2_lite_test.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/map_for_proto2_test.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/map_test.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/map_initialization_order_test.proto"/>
+ </exec>
+</project> \ No newline at end of file
diff --git a/third_party/protobuf/java/core/pom.xml b/third_party/protobuf/java/core/pom.xml
new file mode 100644
index 0000000000..be0da5eade
--- /dev/null
+++ b/third_party/protobuf/java/core/pom.xml
@@ -0,0 +1,144 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>com.google.protobuf</groupId>
+ <artifactId>protobuf-parent</artifactId>
+ <version>3.2.0</version>
+ </parent>
+
+ <artifactId>protobuf-java</artifactId>
+ <packaging>bundle</packaging>
+
+ <name>Protocol Buffers [Core]</name>
+ <description>
+ Core Protocol Buffers library. Protocol Buffers are a way of encoding structured data in an
+ efficient yet extensible format.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <!-- Include core protos in the bundle as resources -->
+ <resources>
+ <resource>
+ <directory>${protobuf.source.dir}</directory>
+ <includes>
+ <include>google/protobuf/any.proto</include>
+ <include>google/protobuf/api.proto</include>
+ <include>google/protobuf/descriptor.proto</include>
+ <include>google/protobuf/duration.proto</include>
+ <include>google/protobuf/empty.proto</include>
+ <include>google/protobuf/field_mask.proto</include>
+ <include>google/protobuf/source_context.proto</include>
+ <include>google/protobuf/struct.proto</include>
+ <include>google/protobuf/timestamp.proto</include>
+ <include>google/protobuf/type.proto</include>
+ <include>google/protobuf/wrappers.proto</include>
+ <include>google/protobuf/compiler/plugin.proto</include>
+ </includes>
+ </resource>
+ </resources>
+
+ <plugins>
+ <!-- Use Antrun plugin to generate sources with protoc -->
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <!-- Generate core protos -->
+ <execution>
+ <id>generate-sources</id>
+ <phase>generate-sources</phase>
+ <configuration>
+ <target>
+ <ant antfile="generate-sources-build.xml"/>
+ </target>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+
+ <!-- Generate the test protos -->
+ <execution>
+ <id>generate-test-sources</id>
+ <phase>generate-test-sources</phase>
+ <configuration>
+ <target>
+ <ant antfile="generate-test-sources-build.xml"/>
+ </target>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- Add the generated sources to the build -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>add-generated-sources</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${generated.sources.dir}</source>
+ </sources>
+ </configuration>
+ </execution>
+ <execution>
+ <id>add-generated-test-sources</id>
+ <phase>generate-test-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${generated.testsources.dir}</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- OSGI bundle configuration -->
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-DocURL>https://developers.google.com/protocol-buffers/</Bundle-DocURL>
+ <Bundle-SymbolicName>com.google.protobuf</Bundle-SymbolicName>
+ <Export-Package>com.google.protobuf;version=${project.version}</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractMessage.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractMessage.java
new file mode 100644
index 0000000000..37180da857
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractMessage.java
@@ -0,0 +1,649 @@
+// 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.
+ * <br>
+ * 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<String> 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<FieldDescriptor, Object> a,
+ Map<FieldDescriptor, Object> 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<FieldDescriptor, Object> map) {
+ for (Map.Entry<FieldDescriptor, Object> 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<? extends EnumLite> list = (List<? extends EnumLite>) 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<BuilderType extends Builder<BuilderType>>
+ extends AbstractMessageLite.Builder
+ implements Message.Builder {
+ // The compiler produces an error if this is not declared explicitly.
+ // Method isn't abstract to bypass Java 1.6 compiler issue http://bugs.java.com/view_bug.do?bug_id=6908259
+ @Override
+ public BuilderType clone() {
+ throw new UnsupportedOperationException("clone() should be implemented in subclasses.");
+ }
+
+ /** 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<FieldDescriptor, Object> entry :
+ getAllFields().entrySet()) {
+ clearField(entry.getKey());
+ }
+ return (BuilderType) this;
+ }
+
+ @Override
+ public List<String> 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<FieldDescriptor, Object> 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<? extends EnumLite> list) {
+ int hash = 1;
+ for (EnumLite e : list) {
+ hash = 31 * hash + hashEnum(e);
+ }
+ return hash;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java
new file mode 100644
index 0000000000..4f691dfdfb
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractMessageLite.java
@@ -0,0 +1,383 @@
+// 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<MessageType, BuilderType>,
+ BuilderType extends AbstractMessageLite.Builder<MessageType, BuilderType>>
+ 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 <T> void addAll(final Iterable<T> values,
+ final Collection<? super T> 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<MessageType, BuilderType>,
+ BuilderType extends Builder<MessageType, BuilderType>>
+ 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 <T> void addAll(final Iterable<T> values,
+ final Collection<? super T> 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<T>) values);
+ } else if (values instanceof Collection) {
+ checkForNullValues(values);
+ list.addAll((Collection<T>) 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/third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractParser.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractParser.java
new file mode 100644
index 0000000000..7ff73ba4d1
--- /dev/null
+++ b/third_party/protobuf/java/core/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<MessageType extends MessageLite>
+ implements Parser<MessageType> {
+ /**
+ * 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);
+ }
+ 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/third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractProtobufList.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/AbstractProtobufList.java
new file mode 100644
index 0000000000..b17db6e0b3
--- /dev/null
+++ b/third_party/protobuf/java/core/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.
+ * <p>
+ * This implementation assumes all subclasses are array based, supporting random access.
+ */
+abstract class AbstractProtobufList<E> extends AbstractList<E> implements ProtobufList<E> {
+
+ 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<? extends E> c) {
+ ensureIsMutable();
+ return super.addAll(c);
+ }
+
+ @Override
+ public boolean addAll(int index, Collection<? extends E> 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/third_party/protobuf/java/core/src/main/java/com/google/protobuf/BlockingRpcChannel.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/BlockingRpcChannel.java
new file mode 100644
index 0000000000..d535efb9b6
--- /dev/null
+++ b/third_party/protobuf/java/core/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;
+
+/**
+ * <p>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/third_party/protobuf/java/core/src/main/java/com/google/protobuf/BlockingService.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/BlockingService.java
new file mode 100644
index 0000000000..d01f0b8ff0
--- /dev/null
+++ b/third_party/protobuf/java/core/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/third_party/protobuf/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java
new file mode 100644
index 0000000000..0d9f87ba01
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/BooleanArrayList.java
@@ -0,0 +1,272 @@
+// 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.BooleanList;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.RandomAccess;
+
+/**
+ * An implementation of {@link BooleanList} on top of a primitive array.
+ *
+ * @author dweis@google.com (Daniel Weis)
+ */
+final class BooleanArrayList
+ extends AbstractProtobufList<Boolean>
+ implements BooleanList, RandomAccess {
+
+ private static final BooleanArrayList EMPTY_LIST = new BooleanArrayList();
+ static {
+ EMPTY_LIST.makeImmutable();
+ }
+
+ public static BooleanArrayList emptyList() {
+ return EMPTY_LIST;
+ }
+
+ /**
+ * The backing store for the list.
+ */
+ private boolean[] array;
+
+ /**
+ * The size of the list distinct from the length of the array. That is, it is the number of
+ * elements set in the list.
+ */
+ private int size;
+
+ /**
+ * Constructs a new mutable {@code BooleanArrayList} with default capacity.
+ */
+ BooleanArrayList() {
+ this(new boolean[DEFAULT_CAPACITY], 0);
+ }
+
+ /**
+ * Constructs a new mutable {@code BooleanArrayList}
+ * containing the same elements as {@code other}.
+ */
+ private BooleanArrayList(boolean[] other, int size) {
+ array = other;
+ this.size = size;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof BooleanArrayList)) {
+ return super.equals(o);
+ }
+ BooleanArrayList other = (BooleanArrayList) o;
+ if (size != other.size) {
+ return false;
+ }
+
+ final boolean[] arr = other.array;
+ for (int i = 0; i < size; i++) {
+ if (array[i] != arr[i]) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 1;
+ for (int i = 0; i < size; i++) {
+ result = (31 * result) + Internal.hashBoolean(array[i]);
+ }
+ return result;
+ }
+
+ @Override
+ public BooleanList mutableCopyWithCapacity(int capacity) {
+ if (capacity < size) {
+ throw new IllegalArgumentException();
+ }
+ return new BooleanArrayList(Arrays.copyOf(array, capacity), size);
+ }
+
+ @Override
+ public Boolean get(int index) {
+ return getBoolean(index);
+ }
+
+ @Override
+ public boolean getBoolean(int index) {
+ ensureIndexInRange(index);
+ return array[index];
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public Boolean set(int index, Boolean element) {
+ return setBoolean(index, element);
+ }
+
+ @Override
+ public boolean setBoolean(int index, boolean element) {
+ ensureIsMutable();
+ ensureIndexInRange(index);
+ boolean previousValue = array[index];
+ array[index] = element;
+ return previousValue;
+ }
+
+ @Override
+ public void add(int index, Boolean element) {
+ addBoolean(index, element);
+ }
+
+ /**
+ * Like {@link #add(Boolean)} but more efficient in that it doesn't box the element.
+ */
+ @Override
+ public void addBoolean(boolean element) {
+ addBoolean(size, element);
+ }
+
+ /**
+ * Like {@link #add(int, Boolean)} but more efficient in that it doesn't box the element.
+ */
+ private void addBoolean(int index, boolean element) {
+ ensureIsMutable();
+ if (index < 0 || index > size) {
+ throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index));
+ }
+
+ if (size < array.length) {
+ // Shift everything over to make room
+ System.arraycopy(array, index, array, index + 1, size - index);
+ } else {
+ // Resize to 1.5x the size
+ int length = ((size * 3) / 2) + 1;
+ boolean[] newArray = new boolean[length];
+
+ // Copy the first part directly
+ System.arraycopy(array, 0, newArray, 0, index);
+
+ // Copy the rest shifted over by one to make room
+ System.arraycopy(array, index, newArray, index + 1, size - index);
+ array = newArray;
+ }
+
+ array[index] = element;
+ size++;
+ modCount++;
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends Boolean> collection) {
+ ensureIsMutable();
+
+ if (collection == null) {
+ throw new NullPointerException();
+ }
+
+ // We specialize when adding another BooleanArrayList to avoid boxing elements.
+ if (!(collection instanceof BooleanArrayList)) {
+ return super.addAll(collection);
+ }
+
+ BooleanArrayList list = (BooleanArrayList) collection;
+ if (list.size == 0) {
+ return false;
+ }
+
+ int overflow = Integer.MAX_VALUE - size;
+ if (overflow < list.size) {
+ // We can't actually represent a list this large.
+ throw new OutOfMemoryError();
+ }
+
+ int newSize = size + list.size;
+ if (newSize > array.length) {
+ array = Arrays.copyOf(array, newSize);
+ }
+
+ System.arraycopy(list.array, 0, array, size, list.size);
+ size = newSize;
+ modCount++;
+ return true;
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ ensureIsMutable();
+ for (int i = 0; i < size; i++) {
+ if (o.equals(array[i])) {
+ System.arraycopy(array, i + 1, array, i, size - i);
+ size--;
+ modCount++;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public Boolean remove(int index) {
+ ensureIsMutable();
+ ensureIndexInRange(index);
+ boolean value = array[index];
+ System.arraycopy(array, index + 1, array, index, size - index);
+ size--;
+ modCount++;
+ return value;
+ }
+
+ /**
+ * Ensures that the provided {@code index} is within the range of {@code [0, size]}. Throws an
+ * {@link IndexOutOfBoundsException} if it is not.
+ *
+ * @param index the index to verify is in range
+ */
+ private void ensureIndexInRange(int index) {
+ if (index < 0 || index >= size) {
+ throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index));
+ }
+ }
+
+ private String makeOutOfBoundsExceptionMessage(int index) {
+ return "Index:" + index + ", Size:" + size;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteBufferWriter.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteBufferWriter.java
new file mode 100644
index 0000000000..6157a52f50
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteBufferWriter.java
@@ -0,0 +1,185 @@
+// 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 static java.lang.Math.max;
+import static java.lang.Math.min;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.ref.SoftReference;
+import java.lang.reflect.Field;
+import java.nio.ByteBuffer;
+import java.nio.channels.WritableByteChannel;
+
+/**
+ * Utility class to provide efficient writing of {@link ByteBuffer}s to {@link OutputStream}s.
+ */
+final class ByteBufferWriter {
+ private ByteBufferWriter() {}
+
+ /**
+ * Minimum size for a cached buffer. This prevents us from allocating buffers that are too
+ * small to be easily reused.
+ */
+ // TODO(nathanmittler): tune this property or allow configuration?
+ private static final int MIN_CACHED_BUFFER_SIZE = 1024;
+
+ /**
+ * Maximum size for a cached buffer. If a larger buffer is required, it will be allocated
+ * but not cached.
+ */
+ // TODO(nathanmittler): tune this property or allow configuration?
+ private static final int MAX_CACHED_BUFFER_SIZE = 16 * 1024;
+
+ /**
+ * The fraction of the requested buffer size under which the buffer will be reallocated.
+ */
+ // TODO(nathanmittler): tune this property or allow configuration?
+ private static final float BUFFER_REALLOCATION_THRESHOLD = 0.5f;
+
+ /**
+ * Keeping a soft reference to a thread-local buffer. This buffer is used for writing a
+ * {@link ByteBuffer} to an {@link OutputStream} when no zero-copy alternative was available.
+ * Using a "soft" reference since VMs may keep this reference around longer than "weak"
+ * (e.g. HotSpot will maintain soft references until memory pressure warrants collection).
+ */
+ private static final ThreadLocal<SoftReference<byte[]>> BUFFER =
+ new ThreadLocal<SoftReference<byte[]>>();
+
+ /**
+ * This is a hack for GAE, where {@code FileOutputStream} is unavailable.
+ */
+ private static final Class<?> FILE_OUTPUT_STREAM_CLASS = safeGetClass("java.io.FileOutputStream");
+ private static final long CHANNEL_FIELD_OFFSET = getChannelFieldOffset(FILE_OUTPUT_STREAM_CLASS);
+
+ /**
+ * For testing purposes only. Clears the cached buffer to force a new allocation on the next
+ * invocation.
+ */
+ static void clearCachedBuffer() {
+ BUFFER.set(null);
+ }
+
+ /**
+ * Writes the remaining content of the buffer to the given stream. The buffer {@code position}
+ * will remain unchanged by this method.
+ */
+ static void write(ByteBuffer buffer, OutputStream output) throws IOException {
+ final int initialPos = buffer.position();
+ try {
+ if (buffer.hasArray()) {
+ // Optimized write for array-backed buffers.
+ // Note that we're taking the risk that a malicious OutputStream could modify the array.
+ output.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
+ } else if (!writeToChannel(buffer, output)){
+ // Read all of the data from the buffer to an array.
+ // TODO(nathanmittler): Consider performance improvements for other "known" stream types.
+ final byte[] array = getOrCreateBuffer(buffer.remaining());
+ while (buffer.hasRemaining()) {
+ int length = min(buffer.remaining(), array.length);
+ buffer.get(array, 0, length);
+ output.write(array, 0, length);
+ }
+ }
+ } finally {
+ // Restore the initial position.
+ buffer.position(initialPos);
+ }
+ }
+
+ private static byte[] getOrCreateBuffer(int requestedSize) {
+ requestedSize = max(requestedSize, MIN_CACHED_BUFFER_SIZE);
+
+ byte[] buffer = getBuffer();
+ // Only allocate if we need to.
+ if (buffer == null || needToReallocate(requestedSize, buffer.length)) {
+ buffer = new byte[requestedSize];
+
+ // Only cache the buffer if it's not too big.
+ if (requestedSize <= MAX_CACHED_BUFFER_SIZE) {
+ setBuffer(buffer);
+ }
+ }
+ return buffer;
+ }
+
+ private static boolean needToReallocate(int requestedSize, int bufferLength) {
+ // First check against just the requested length to avoid the multiply.
+ return bufferLength < requestedSize
+ && bufferLength < requestedSize * BUFFER_REALLOCATION_THRESHOLD;
+ }
+
+ private static byte[] getBuffer() {
+ SoftReference<byte[]> sr = BUFFER.get();
+ return sr == null ? null : sr.get();
+ }
+
+ private static void setBuffer(byte[] value) {
+ BUFFER.set(new SoftReference<byte[]>(value));
+ }
+
+ private static boolean writeToChannel(ByteBuffer buffer, OutputStream output) throws IOException {
+ if (CHANNEL_FIELD_OFFSET >= 0 && FILE_OUTPUT_STREAM_CLASS.isInstance(output)) {
+ // Use a channel to write out the ByteBuffer. This will automatically empty the buffer.
+ WritableByteChannel channel = null;
+ try {
+ channel = (WritableByteChannel) UnsafeUtil.getObject(output, CHANNEL_FIELD_OFFSET);
+ } catch (ClassCastException e) {
+ // Absorb.
+ }
+ if (channel != null) {
+ channel.write(buffer);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static Class<?> safeGetClass(String className) {
+ try {
+ return Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ return null;
+ }
+ }
+ private static long getChannelFieldOffset(Class<?> clazz) {
+ try {
+ if (clazz != null && UnsafeUtil.hasUnsafeArrayOperations()) {
+ Field field = clazz.getDeclaredField("channel");
+ return UnsafeUtil.objectFieldOffset(field);
+ }
+ } catch (Throwable e) {
+ // Absorb
+ }
+ return -1;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteOutput.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteOutput.java
new file mode 100644
index 0000000000..ee5887538f
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteOutput.java
@@ -0,0 +1,116 @@
+// 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.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * An output target for raw bytes. This interface provides semantics that support two types of
+ * writing:
+ *
+ * <p><b>Traditional write operations:</b>
+ * (as defined by {@link java.io.OutputStream}) where the target method is responsible for either
+ * copying the data or completing the write before returning from the method call.
+ *
+ * <p><b>Lazy write operations:</b> where the caller guarantees that it will never modify the
+ * provided buffer and it can therefore be considered immutable. The target method is free to
+ * maintain a reference to the buffer beyond the scope of the method call (e.g. until the write
+ * operation completes).
+ */
+@ExperimentalApi
+public abstract class ByteOutput {
+ /**
+ * Writes a single byte.
+ *
+ * @param value the byte to be written
+ * @throws IOException thrown if an error occurred while writing
+ */
+ public abstract void write(byte value) throws IOException;
+
+ /**
+ * Writes a sequence of bytes. The {@link ByteOutput} must copy {@code value} if it will
+ * not be processed prior to the return of this method call, since {@code value} may be
+ * reused/altered by the caller.
+ *
+ * <p>NOTE: This method <strong>MUST NOT</strong> modify the {@code value}. Doing so is a
+ * programming error and will lead to data corruption which will be difficult to debug.
+ *
+ * @param value the bytes to be written
+ * @param offset the offset of the start of the writable range
+ * @param length the number of bytes to write starting from {@code offset}
+ * @throws IOException thrown if an error occurred while writing
+ */
+ public abstract void write(byte[] value, int offset, int length) throws IOException;
+
+ /**
+ * Writes a sequence of bytes. The {@link ByteOutput} is free to retain a reference to the value
+ * beyond the scope of this method call (e.g. write later) since it is considered immutable and is
+ * guaranteed not to change by the caller.
+ *
+ * <p>NOTE: This method <strong>MUST NOT</strong> modify the {@code value}. Doing so is a
+ * programming error and will lead to data corruption which will be difficult to debug.
+ *
+ * @param value the bytes to be written
+ * @param offset the offset of the start of the writable range
+ * @param length the number of bytes to write starting from {@code offset}
+ * @throws IOException thrown if an error occurred while writing
+ */
+ public abstract void writeLazy(byte[] value, int offset, int length) throws IOException;
+
+ /**
+ * Writes a sequence of bytes. The {@link ByteOutput} must copy {@code value} if it will
+ * not be processed prior to the return of this method call, since {@code value} may be
+ * reused/altered by the caller.
+ *
+ * <p>NOTE: This method <strong>MUST NOT</strong> modify the {@code value}. Doing so is a
+ * programming error and will lead to data corruption which will be difficult to debug.
+ *
+ * @param value the bytes to be written. Upon returning from this call, the {@code position} of
+ * this buffer will be set to the {@code limit}
+ * @throws IOException thrown if an error occurred while writing
+ */
+ public abstract void write(ByteBuffer value) throws IOException;
+
+ /**
+ * Writes a sequence of bytes. The {@link ByteOutput} is free to retain a reference to the value
+ * beyond the scope of this method call (e.g. write later) since it is considered immutable and is
+ * guaranteed not to change by the caller.
+ *
+ * <p>NOTE: This method <strong>MUST NOT</strong> modify the {@code value}. Doing so is a
+ * programming error and will lead to data corruption which will be difficult to debug.
+ *
+ * @param value the bytes to be written. Upon returning from this call, the {@code position} of
+ * this buffer will be set to the {@code limit}
+ * @throws IOException thrown if an error occurred while writing
+ */
+ public abstract void writeLazy(ByteBuffer value) throws IOException;
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java
new file mode 100644
index 0000000000..99a312096d
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ByteString.java
@@ -0,0 +1,1558 @@
+// 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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.UnsupportedCharsetException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+/**
+ * Immutable sequence of bytes. Substring is supported by sharing the reference to the immutable
+ * underlying bytes. Concatenation is likewise supported without copying (long strings) by building
+ * a tree of pieces in {@link RopeByteString}.
+ *
+ * <p>Like {@link String}, the contents of a {@link ByteString} can never be observed to change, not
+ * even in the presence of a data race or incorrect API usage in the client code.
+ *
+ * @author crazybob@google.com Bob Lee
+ * @author kenton@google.com Kenton Varda
+ * @author carlanton@google.com Carl Haverl
+ * @author martinrb@google.com Martin Buchholz
+ */
+public abstract class ByteString implements Iterable<Byte>, Serializable {
+
+ /**
+ * When two strings to be concatenated have a combined length shorter than
+ * this, we just copy their bytes on {@link #concat(ByteString)}.
+ * The trade-off is copy size versus the overhead of creating tree nodes
+ * in {@link RopeByteString}.
+ */
+ static final int CONCATENATE_BY_COPY_SIZE = 128;
+
+ /**
+ * When copying an InputStream into a ByteString with .readFrom(),
+ * the chunks in the underlying rope start at 256 bytes, but double
+ * each iteration up to 8192 bytes.
+ */
+ static final int MIN_READ_FROM_CHUNK_SIZE = 0x100; // 256b
+ static final int MAX_READ_FROM_CHUNK_SIZE = 0x2000; // 8k
+
+ /**
+ * Empty {@code ByteString}.
+ */
+ public static final ByteString EMPTY = new LiteralByteString(Internal.EMPTY_BYTE_ARRAY);
+
+ /**
+ * An interface to efficiently copy {@code byte[]}.
+ *
+ * <p>One of the noticeable costs of copying a byte[] into a new array using
+ * {@code System.arraycopy} is nullification of a new buffer before the copy. It has been shown
+ * the Hotspot VM is capable to intrisicfy {@code Arrays.copyOfRange} operation to avoid this
+ * expensive nullification and provide substantial performance gain. Unfortunately this does not
+ * hold on Android runtimes and could make the copy slightly slower due to additional code in
+ * the {@code Arrays.copyOfRange}. Thus we provide two different implementation for array copier
+ * for Hotspot and Android runtimes.
+ */
+ private interface ByteArrayCopier {
+ /**
+ * Copies the specified range of the specified array into a new array
+ */
+ byte[] copyFrom(byte[] bytes, int offset, int size);
+ }
+
+ /** Implementation of {@code ByteArrayCopier} which uses {@link System#arraycopy}. */
+ private static final class SystemByteArrayCopier implements ByteArrayCopier {
+ @Override
+ public byte[] copyFrom(byte[] bytes, int offset, int size) {
+ byte[] copy = new byte[size];
+ System.arraycopy(bytes, offset, copy, 0, size);
+ return copy;
+ }
+ }
+
+ /** Implementation of {@code ByteArrayCopier} which uses {@link Arrays#copyOfRange}. */
+ private static final class ArraysByteArrayCopier implements ByteArrayCopier {
+ @Override
+ public byte[] copyFrom(byte[] bytes, int offset, int size) {
+ return Arrays.copyOfRange(bytes, offset, offset + size);
+ }
+ }
+
+ private static final ByteArrayCopier byteArrayCopier;
+ static {
+ boolean isAndroid = true;
+ try {
+ Class.forName("android.content.Context");
+ } catch (ClassNotFoundException e) {
+ isAndroid = false;
+ }
+
+ byteArrayCopier = isAndroid ? new SystemByteArrayCopier() : new ArraysByteArrayCopier();
+ }
+
+ /**
+ * Cached hash value. Intentionally accessed via a data race, which
+ * is safe because of the Java Memory Model's "no out-of-thin-air values"
+ * guarantees for ints. A value of 0 implies that the hash has not been set.
+ */
+ private int hash = 0;
+
+ // This constructor is here to prevent subclassing outside of this package,
+ ByteString() {}
+
+ /**
+ * Gets the byte at the given index. This method should be used only for
+ * random access to individual bytes. To access bytes sequentially, use the
+ * {@link ByteIterator} returned by {@link #iterator()}, and call {@link
+ * #substring(int, int)} first if necessary.
+ *
+ * @param index index of byte
+ * @return the value
+ * @throws IndexOutOfBoundsException {@code index < 0 or index >= size}
+ */
+ public abstract byte byteAt(int index);
+
+ /**
+ * Return a {@link ByteString.ByteIterator} over the bytes in the ByteString.
+ * To avoid auto-boxing, you may get the iterator manually and call
+ * {@link ByteIterator#nextByte()}.
+ *
+ * @return the iterator
+ */
+ @Override
+ public final ByteIterator iterator() {
+ return new ByteIterator() {
+ private int position = 0;
+ private final int limit = size();
+
+ @Override
+ public boolean hasNext() {
+ return position < limit;
+ }
+
+ @Override
+ public Byte next() {
+ // Boxing calls Byte.valueOf(byte), which does not instantiate.
+ return nextByte();
+ }
+
+ @Override
+ public byte nextByte() {
+ try {
+ return byteAt(position++);
+ } catch (IndexOutOfBoundsException e) {
+ throw new NoSuchElementException(e.getMessage());
+ }
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ /**
+ * This interface extends {@code Iterator<Byte>}, so that we can return an
+ * unboxed {@code byte}.
+ */
+ public interface ByteIterator extends Iterator<Byte> {
+ /**
+ * An alternative to {@link Iterator#next()} that returns an
+ * unboxed primitive {@code byte}.
+ *
+ * @return the next {@code byte} in the iteration
+ * @throws NoSuchElementException if the iteration has no more elements
+ */
+ byte nextByte();
+ }
+
+ /**
+ * Gets the number of bytes.
+ *
+ * @return size in bytes
+ */
+ public abstract int size();
+
+ /**
+ * Returns {@code true} if the size is {@code 0}, {@code false} otherwise.
+ *
+ * @return true if this is zero bytes long
+ */
+ public final boolean isEmpty() {
+ return size() == 0;
+ }
+
+ // =================================================================
+ // ByteString -> substring
+
+ /**
+ * Return the substring from {@code beginIndex}, inclusive, to the end of the
+ * string.
+ *
+ * @param beginIndex start at this index
+ * @return substring sharing underlying data
+ * @throws IndexOutOfBoundsException if {@code beginIndex < 0} or
+ * {@code beginIndex > size()}.
+ */
+ public final ByteString substring(int beginIndex) {
+ return substring(beginIndex, size());
+ }
+
+ /**
+ * Return the substring from {@code beginIndex}, inclusive, to {@code
+ * endIndex}, exclusive.
+ *
+ * @param beginIndex start at this index
+ * @param endIndex the last character is the one before this index
+ * @return substring sharing underlying data
+ * @throws IndexOutOfBoundsException if {@code beginIndex < 0},
+ * {@code endIndex > size()}, or {@code beginIndex > endIndex}.
+ */
+ public abstract ByteString substring(int beginIndex, int endIndex);
+
+ /**
+ * Tests if this bytestring starts with the specified prefix.
+ * Similar to {@link String#startsWith(String)}
+ *
+ * @param prefix the prefix.
+ * @return <code>true</code> if the byte sequence represented by the
+ * argument is a prefix of the byte sequence represented by
+ * this string; <code>false</code> otherwise.
+ */
+ public final boolean startsWith(ByteString prefix) {
+ return size() >= prefix.size() &&
+ substring(0, prefix.size()).equals(prefix);
+ }
+
+ /**
+ * Tests if this bytestring ends with the specified suffix.
+ * Similar to {@link String#endsWith(String)}
+ *
+ * @param suffix the suffix.
+ * @return <code>true</code> if the byte sequence represented by the
+ * argument is a suffix of the byte sequence represented by
+ * this string; <code>false</code> otherwise.
+ */
+ public final boolean endsWith(ByteString suffix) {
+ return size() >= suffix.size() &&
+ substring(size() - suffix.size()).equals(suffix);
+ }
+
+ // =================================================================
+ // byte[] -> ByteString
+
+ /**
+ * Copies the given bytes into a {@code ByteString}.
+ *
+ * @param bytes source array
+ * @param offset offset in source array
+ * @param size number of bytes to copy
+ * @return new {@code ByteString}
+ */
+ public static ByteString copyFrom(byte[] bytes, int offset, int size) {
+ return new LiteralByteString(byteArrayCopier.copyFrom(bytes, offset, size));
+ }
+
+ /**
+ * Copies the given bytes into a {@code ByteString}.
+ *
+ * @param bytes to copy
+ * @return new {@code ByteString}
+ */
+ public static ByteString copyFrom(byte[] bytes) {
+ 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.
+ */
+ static ByteString wrap(byte[] bytes) {
+ // TODO(dweis): Return EMPTY when bytes are empty to reduce allocations?
+ return new LiteralByteString(bytes);
+ }
+
+ /**
+ * Wraps the given bytes into a {@code ByteString}. Intended for internal only
+ * usage to force a classload of ByteString before BoundedByteString and
+ * LiteralByteString.
+ */
+ static ByteString wrap(byte[] bytes, int offset, int length) {
+ return new BoundedByteString(bytes, offset, length);
+ }
+
+ /**
+ * Copies the next {@code size} bytes from a {@code java.nio.ByteBuffer} into
+ * a {@code ByteString}.
+ *
+ * @param bytes source buffer
+ * @param size number of bytes to copy
+ * @return new {@code ByteString}
+ */
+ public static ByteString copyFrom(ByteBuffer bytes, int size) {
+ byte[] copy = new byte[size];
+ bytes.get(copy);
+ return new LiteralByteString(copy);
+ }
+
+ /**
+ * Copies the remaining bytes from a {@code java.nio.ByteBuffer} into
+ * a {@code ByteString}.
+ *
+ * @param bytes sourceBuffer
+ * @return new {@code ByteString}
+ */
+ public static ByteString copyFrom(ByteBuffer bytes) {
+ return copyFrom(bytes, bytes.remaining());
+ }
+
+ /**
+ * Encodes {@code text} into a sequence of bytes using the named charset
+ * and returns the result as a {@code ByteString}.
+ *
+ * @param text source string
+ * @param charsetName encoding to use
+ * @return new {@code ByteString}
+ * @throws UnsupportedEncodingException if the encoding isn't found
+ */
+ public static ByteString copyFrom(String text, String charsetName)
+ throws UnsupportedEncodingException {
+ return new LiteralByteString(text.getBytes(charsetName));
+ }
+
+ /**
+ * Encodes {@code text} into a sequence of bytes using the named charset
+ * and returns the result as a {@code ByteString}.
+ *
+ * @param text source string
+ * @param charset encode using this charset
+ * @return new {@code ByteString}
+ */
+ public static ByteString copyFrom(String text, Charset charset) {
+ return new LiteralByteString(text.getBytes(charset));
+ }
+
+ /**
+ * Encodes {@code text} into a sequence of UTF-8 bytes and returns the
+ * result as a {@code ByteString}.
+ *
+ * @param text source string
+ * @return new {@code ByteString}
+ */
+ public static ByteString copyFromUtf8(String text) {
+ return new LiteralByteString(text.getBytes(Internal.UTF_8));
+ }
+
+ // =================================================================
+ // InputStream -> ByteString
+
+ /**
+ * Completely reads the given stream's bytes into a
+ * {@code ByteString}, blocking if necessary until all bytes are
+ * read through to the end of the stream.
+ *
+ * <b>Performance notes:</b> The returned {@code ByteString} is an
+ * immutable tree of byte arrays ("chunks") of the stream data. The
+ * first chunk is small, with subsequent chunks each being double
+ * the size, up to 8K.
+ *
+ * <p>Each byte read from the input stream will be copied twice to ensure
+ * that the resulting ByteString is truly immutable.
+ *
+ * @param streamToDrain The source stream, which is read completely
+ * but not closed.
+ * @return A new {@code ByteString} which is made up of chunks of
+ * various sizes, depending on the behavior of the underlying
+ * stream.
+ * @throws IOException IOException is thrown if there is a problem
+ * reading the underlying stream.
+ */
+ public static ByteString readFrom(InputStream streamToDrain)
+ throws IOException {
+ return readFrom(streamToDrain, MIN_READ_FROM_CHUNK_SIZE, MAX_READ_FROM_CHUNK_SIZE);
+ }
+
+ /**
+ * Completely reads the given stream's bytes into a
+ * {@code ByteString}, blocking if necessary until all bytes are
+ * read through to the end of the stream.
+ *
+ * <b>Performance notes:</b> The returned {@code ByteString} is an
+ * immutable tree of byte arrays ("chunks") of the stream data. The
+ * chunkSize parameter sets the size of these byte arrays.
+ *
+ * <p>Each byte read from the input stream will be copied twice to ensure
+ * that the resulting ByteString is truly immutable.
+ *
+ * @param streamToDrain The source stream, which is read completely
+ * but not closed.
+ * @param chunkSize The size of the chunks in which to read the
+ * stream.
+ * @return A new {@code ByteString} which is made up of chunks of
+ * the given size.
+ * @throws IOException IOException is thrown if there is a problem
+ * reading the underlying stream.
+ */
+ public static ByteString readFrom(InputStream streamToDrain, int chunkSize)
+ throws IOException {
+ return readFrom(streamToDrain, chunkSize, chunkSize);
+ }
+
+ // Helper method that takes the chunk size range as a parameter.
+ public static ByteString readFrom(InputStream streamToDrain, int minChunkSize,
+ int maxChunkSize) throws IOException {
+ Collection<ByteString> results = new ArrayList<ByteString>();
+
+ // copy the inbound bytes into a list of chunks; the chunk size
+ // grows exponentially to support both short and long streams.
+ int chunkSize = minChunkSize;
+ while (true) {
+ ByteString chunk = readChunk(streamToDrain, chunkSize);
+ if (chunk == null) {
+ break;
+ }
+ results.add(chunk);
+ chunkSize = Math.min(chunkSize * 2, maxChunkSize);
+ }
+
+ return ByteString.copyFrom(results);
+ }
+
+ /**
+ * Blocks until a chunk of the given size can be made from the
+ * stream, or EOF is reached. Calls read() repeatedly in case the
+ * given stream implementation doesn't completely fill the given
+ * buffer in one read() call.
+ *
+ * @return A chunk of the desired size, or else a chunk as large as
+ * was available when end of stream was reached. Returns null if the
+ * given stream had no more data in it.
+ */
+ private static ByteString readChunk(InputStream in, final int chunkSize)
+ throws IOException {
+ final byte[] buf = new byte[chunkSize];
+ int bytesRead = 0;
+ while (bytesRead < chunkSize) {
+ final int count = in.read(buf, bytesRead, chunkSize - bytesRead);
+ if (count == -1) {
+ break;
+ }
+ bytesRead += count;
+ }
+
+ if (bytesRead == 0) {
+ return null;
+ }
+
+ // Always make a copy since InputStream could steal a reference to buf.
+ return ByteString.copyFrom(buf, 0, bytesRead);
+ }
+
+ // =================================================================
+ // Multiple ByteStrings -> One ByteString
+
+ /**
+ * Concatenate the given {@code ByteString} to this one. Short concatenations,
+ * of total size smaller than {@link ByteString#CONCATENATE_BY_COPY_SIZE}, are
+ * produced by copying the underlying bytes (as per Rope.java, <a
+ * href="http://www.cs.ubc.ca/local/reading/proceedings/spe91-95/spe/vol25/issue12/spe986.pdf">
+ * BAP95 </a>. In general, the concatenate involves no copying.
+ *
+ * @param other string to concatenate
+ * @return a new {@code ByteString} instance
+ */
+ public final ByteString concat(ByteString other) {
+ if (Integer.MAX_VALUE - size() < other.size()) {
+ throw new IllegalArgumentException("ByteString would be too long: " +
+ size() + "+" + other.size());
+ }
+
+ return RopeByteString.concatenate(this, other);
+ }
+
+ /**
+ * Concatenates all byte strings in the iterable and returns the result.
+ * This is designed to run in O(list size), not O(total bytes).
+ *
+ * <p>The returned {@code ByteString} is not necessarily a unique object.
+ * If the list is empty, the returned object is the singleton empty
+ * {@code ByteString}. If the list has only one element, that
+ * {@code ByteString} will be returned without copying.
+ *
+ * @param byteStrings strings to be concatenated
+ * @return new {@code ByteString}
+ */
+ public static ByteString copyFrom(Iterable<ByteString> byteStrings) {
+ // Determine the size;
+ final int size;
+ if (!(byteStrings instanceof Collection)) {
+ int tempSize = 0;
+ for (Iterator<ByteString> iter = byteStrings.iterator(); iter.hasNext();
+ iter.next(), ++tempSize) {
+ }
+ size = tempSize;
+ } else {
+ size = ((Collection<ByteString>) byteStrings).size();
+ }
+
+ if (size == 0) {
+ return EMPTY;
+ }
+
+ return balancedConcat(byteStrings.iterator(), size);
+ }
+
+ // Internal function used by copyFrom(Iterable<ByteString>).
+ // Create a balanced concatenation of the next "length" elements from the
+ // iterable.
+ private static ByteString balancedConcat(Iterator<ByteString> iterator, int length) {
+ if (length < 1) {
+ throw new IllegalArgumentException(String.format("length (%s) must be >= 1", length));
+ }
+ ByteString result;
+ if (length == 1) {
+ result = iterator.next();
+ } else {
+ int halfLength = length >>> 1;
+ ByteString left = balancedConcat(iterator, halfLength);
+ ByteString right = balancedConcat(iterator, length - halfLength);
+ result = left.concat(right);
+ }
+ return result;
+ }
+
+ // =================================================================
+ // ByteString -> byte[]
+
+ /**
+ * Copies bytes into a buffer at the given offset.
+ *
+ * @param target buffer to copy into
+ * @param offset in the target buffer
+ * @throws IndexOutOfBoundsException if the offset is negative or too large
+ */
+ public void copyTo(byte[] target, int offset) {
+ copyTo(target, 0, offset, size());
+ }
+
+ /**
+ * Copies bytes into a buffer.
+ *
+ * @param target buffer to copy into
+ * @param sourceOffset offset within these bytes
+ * @param targetOffset offset within the target buffer
+ * @param numberToCopy number of bytes to copy
+ * @throws IndexOutOfBoundsException if an offset or size is negative or too
+ * large
+ */
+ public final void copyTo(byte[] target, int sourceOffset, int targetOffset,
+ int numberToCopy) {
+ checkRange(sourceOffset, sourceOffset + numberToCopy, size());
+ checkRange(targetOffset, targetOffset + numberToCopy, target.length);
+ if (numberToCopy > 0) {
+ copyToInternal(target, sourceOffset, targetOffset, numberToCopy);
+ }
+ }
+
+ /**
+ * Internal (package private) implementation of
+ * {@link #copyTo(byte[],int,int,int)}.
+ * It assumes that all error checking has already been performed and that
+ * {@code numberToCopy > 0}.
+ */
+ protected abstract void copyToInternal(byte[] target, int sourceOffset,
+ int targetOffset, int numberToCopy);
+
+ /**
+ * Copies bytes into a ByteBuffer.
+ *
+ * @param target ByteBuffer to copy into.
+ * @throws java.nio.ReadOnlyBufferException if the {@code target} is read-only
+ * @throws java.nio.BufferOverflowException if the {@code target}'s
+ * remaining() space is not large enough to hold the data.
+ */
+ public abstract void copyTo(ByteBuffer target);
+
+ /**
+ * Copies bytes to a {@code byte[]}.
+ *
+ * @return copied bytes
+ */
+ public final byte[] toByteArray() {
+ final int size = size();
+ if (size == 0) {
+ return Internal.EMPTY_BYTE_ARRAY;
+ }
+ byte[] result = new byte[size];
+ copyToInternal(result, 0, 0, size);
+ return result;
+ }
+
+ /**
+ * Writes a copy of the contents of this byte string to the specified output stream argument.
+ *
+ * @param out the output stream to which to write the data.
+ * @throws IOException if an I/O error occurs.
+ */
+ public abstract void writeTo(OutputStream out) throws IOException;
+
+ /**
+ * Writes a specified part of this byte string to an output stream.
+ *
+ * @param out the output stream to which to write the data.
+ * @param sourceOffset offset within these bytes
+ * @param numberToWrite number of bytes to write
+ * @throws IOException if an I/O error occurs.
+ * @throws IndexOutOfBoundsException if an offset or size is negative or too large
+ */
+ final void writeTo(OutputStream out, int sourceOffset, int numberToWrite)
+ throws IOException {
+ checkRange(sourceOffset, sourceOffset + numberToWrite, size());
+ if (numberToWrite > 0) {
+ writeToInternal(out, sourceOffset, numberToWrite);
+ }
+ }
+
+ /**
+ * Internal version of {@link #writeTo(OutputStream,int,int)} that assumes
+ * all error checking has already been done.
+ */
+ abstract void writeToInternal(OutputStream out, int sourceOffset, int numberToWrite)
+ throws IOException;
+
+ /**
+ * Writes this {@link ByteString} to the provided {@link ByteOutput}. Calling
+ * this method may result in multiple operations on the target {@link ByteOutput}.
+ *
+ * <p>This method may expose internal backing buffers of the {@link ByteString} to the {@link
+ * ByteOutput} in order to avoid additional copying overhead. It would be possible for a malicious
+ * {@link ByteOutput} to corrupt the {@link ByteString}. Use with caution!
+ *
+ * @param byteOutput the output target to receive the bytes
+ * @throws IOException if an I/O error occurs
+ * @see UnsafeByteOperations#unsafeWriteTo(ByteString, ByteOutput)
+ */
+ 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.
+ * The result uses the same backing array as the byte string, if possible.
+ *
+ * @return wrapped bytes
+ */
+ public abstract ByteBuffer asReadOnlyByteBuffer();
+
+ /**
+ * Constructs a list of read-only {@code java.nio.ByteBuffer} objects
+ * such that the concatenation of their contents is equal to the contents
+ * of this byte string. The result uses the same backing arrays as the
+ * byte string.
+ * <p>
+ * By returning a list, implementations of this method may be able to avoid
+ * copying even when there are multiple backing arrays.
+ *
+ * @return a list of wrapped bytes
+ */
+ public abstract List<ByteBuffer> asReadOnlyByteBufferList();
+
+ /**
+ * Constructs a new {@code String} by decoding the bytes using the
+ * specified charset.
+ *
+ * @param charsetName encode using this charset
+ * @return new string
+ * @throws UnsupportedEncodingException if charset isn't recognized
+ */
+ public final String toString(String charsetName)
+ throws UnsupportedEncodingException {
+ try {
+ return toString(Charset.forName(charsetName));
+ } catch (UnsupportedCharsetException e) {
+ UnsupportedEncodingException exception = new UnsupportedEncodingException(charsetName);
+ exception.initCause(e);
+ throw exception;
+ }
+ }
+
+ /**
+ * Constructs a new {@code String} by decoding the bytes using the
+ * specified charset. Returns the same empty String if empty.
+ *
+ * @param charset encode using this charset
+ * @return new string
+ */
+ public final String toString(Charset charset) {
+ return size() == 0 ? "" : toStringInternal(charset);
+ }
+
+ /**
+ * Constructs a new {@code String} by decoding the bytes using the
+ * specified charset.
+ *
+ * @param charset encode using this charset
+ * @return new string
+ */
+ protected abstract String toStringInternal(Charset charset);
+
+ // =================================================================
+ // UTF-8 decoding
+
+ /**
+ * Constructs a new {@code String} by decoding the bytes as UTF-8.
+ *
+ * @return new string using UTF-8 encoding
+ */
+ public final String toStringUtf8() {
+ return toString(Internal.UTF_8);
+ }
+
+ /**
+ * Tells whether this {@code ByteString} represents a well-formed UTF-8
+ * byte sequence, such that the original bytes can be converted to a
+ * String object and then round tripped back to bytes without loss.
+ *
+ * <p>More precisely, returns {@code true} whenever: <pre> {@code
+ * Arrays.equals(byteString.toByteArray(),
+ * new String(byteString.toByteArray(), "UTF-8").getBytes("UTF-8"))
+ * }</pre>
+ *
+ * <p>This method returns {@code false} for "overlong" byte sequences,
+ * as well as for 3-byte sequences that would map to a surrogate
+ * character, in accordance with the restricted definition of UTF-8
+ * introduced in Unicode 3.1. Note that the UTF-8 decoder included in
+ * Oracle's JDK has been modified to also reject "overlong" byte
+ * sequences, but (as of 2011) still accepts 3-byte surrogate
+ * character byte sequences.
+ *
+ * <p>See the Unicode Standard,<br>
+ * Table 3-6. <em>UTF-8 Bit Distribution</em>,<br>
+ * Table 3-7. <em>Well Formed UTF-8 Byte Sequences</em>.
+ *
+ * @return whether the bytes in this {@code ByteString} are a
+ * well-formed UTF-8 byte sequence
+ */
+ public abstract boolean isValidUtf8();
+
+ /**
+ * Tells whether the given byte sequence is a well-formed, malformed, or
+ * incomplete UTF-8 byte sequence. This method accepts and returns a partial
+ * state result, allowing the bytes for a complete UTF-8 byte sequence to be
+ * composed from multiple {@code ByteString} segments.
+ *
+ * @param state either {@code 0} (if this is the initial decoding operation)
+ * or the value returned from a call to a partial decoding method for the
+ * previous bytes
+ * @param offset offset of the first byte to check
+ * @param length number of bytes to check
+ *
+ * @return {@code -1} if the partial byte sequence is definitely malformed,
+ * {@code 0} if it is well-formed (no additional input needed), or, if the
+ * byte sequence is "incomplete", i.e. apparently terminated in the middle of
+ * a character, an opaque integer "state" value containing enough information
+ * to decode the character when passed to a subsequent invocation of a
+ * partial decoding method.
+ */
+ protected abstract int partialIsValidUtf8(int state, int offset, int length);
+
+ // =================================================================
+ // equals() and hashCode()
+
+ @Override
+ public abstract boolean equals(Object o);
+
+ /**
+ * Base class for leaf {@link ByteString}s (i.e. non-ropes).
+ */
+ abstract static class LeafByteString extends ByteString {
+ @Override
+ protected final int getTreeDepth() {
+ return 0;
+ }
+
+ @Override
+ protected final boolean isBalanced() {
+ return true;
+ }
+
+
+ /**
+ * Check equality of the substring of given length of this object starting at
+ * zero with another {@code ByteString} substring starting at offset.
+ *
+ * @param other what to compare a substring in
+ * @param offset offset into other
+ * @param length number of bytes to compare
+ * @return true for equality of substrings, else false.
+ */
+ abstract boolean equalsRange(ByteString other, int offset, int length);
+ }
+
+ /**
+ * Compute the hashCode using the traditional algorithm from {@link
+ * ByteString}.
+ *
+ * @return hashCode value
+ */
+ @Override
+ public final int hashCode() {
+ int h = hash;
+
+ if (h == 0) {
+ int size = size();
+ h = partialHash(size, 0, size);
+ if (h == 0) {
+ h = 1;
+ }
+ hash = h;
+ }
+ return h;
+ }
+
+ // =================================================================
+ // Input stream
+
+ /**
+ * Creates an {@code InputStream} which can be used to read the bytes.
+ * <p>
+ * The {@link InputStream} returned by this method is guaranteed to be
+ * completely non-blocking. The method {@link InputStream#available()}
+ * returns the number of bytes remaining in the stream. The methods
+ * {@link InputStream#read(byte[])}, {@link InputStream#read(byte[],int,int)}
+ * and {@link InputStream#skip(long)} will read/skip as many bytes as are
+ * available. The method {@link InputStream#markSupported()} returns
+ * {@code true}.
+ * <p>
+ * The methods in the returned {@link InputStream} might <b>not</b> be
+ * thread safe.
+ *
+ * @return an input stream that returns the bytes of this byte string.
+ */
+ public abstract InputStream newInput();
+
+ /**
+ * Creates a {@link CodedInputStream} which can be used to read the bytes.
+ * Using this is often more efficient than creating a {@link CodedInputStream}
+ * that wraps the result of {@link #newInput()}.
+ *
+ * @return stream based on wrapped data
+ */
+ public abstract CodedInputStream newCodedInput();
+
+ // =================================================================
+ // Output stream
+
+ /**
+ * Creates a new {@link Output} with the given initial capacity. Call {@link
+ * Output#toByteString()} to create the {@code ByteString} instance.
+ * <p>
+ * A {@link ByteString.Output} offers the same functionality as a
+ * {@link ByteArrayOutputStream}, except that it returns a {@link ByteString}
+ * rather than a {@code byte} array.
+ *
+ * @param initialCapacity estimate of number of bytes to be written
+ * @return {@code OutputStream} for building a {@code ByteString}
+ */
+ public static Output newOutput(int initialCapacity) {
+ return new Output(initialCapacity);
+ }
+
+ /**
+ * Creates a new {@link Output}. Call {@link Output#toByteString()} to create
+ * the {@code ByteString} instance.
+ * <p>
+ * A {@link ByteString.Output} offers the same functionality as a
+ * {@link ByteArrayOutputStream}, except that it returns a {@link ByteString}
+ * rather than a {@code byte array}.
+ *
+ * @return {@code OutputStream} for building a {@code ByteString}
+ */
+ public static Output newOutput() {
+ return new Output(CONCATENATE_BY_COPY_SIZE);
+ }
+
+ /**
+ * Outputs to a {@code ByteString} instance. Call {@link #toByteString()} to
+ * create the {@code ByteString} instance.
+ */
+ public static final class Output extends OutputStream {
+ // Implementation note.
+ // The public methods of this class must be synchronized. ByteStrings
+ // are guaranteed to be immutable. Without some sort of locking, it could
+ // be possible for one thread to call toByteSring(), while another thread
+ // is still modifying the underlying byte array.
+
+ private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
+ // argument passed by user, indicating initial capacity.
+ private final int initialCapacity;
+ // ByteStrings to be concatenated to create the result
+ private final ArrayList<ByteString> flushedBuffers;
+ // Total number of bytes in the ByteStrings of flushedBuffers
+ private int flushedBuffersTotalBytes;
+ // Current buffer to which we are writing
+ private byte[] buffer;
+ // Location in buffer[] to which we write the next byte.
+ private int bufferPos;
+
+ /**
+ * Creates a new ByteString output stream with the specified
+ * initial capacity.
+ *
+ * @param initialCapacity the initial capacity of the output stream.
+ */
+ Output(int initialCapacity) {
+ if (initialCapacity < 0) {
+ throw new IllegalArgumentException("Buffer size < 0");
+ }
+ this.initialCapacity = initialCapacity;
+ this.flushedBuffers = new ArrayList<ByteString>();
+ this.buffer = new byte[initialCapacity];
+ }
+
+ @Override
+ public synchronized void write(int b) {
+ if (bufferPos == buffer.length) {
+ flushFullBuffer(1);
+ }
+ buffer[bufferPos++] = (byte)b;
+ }
+
+ @Override
+ public synchronized void write(byte[] b, int offset, int length) {
+ if (length <= buffer.length - bufferPos) {
+ // The bytes can fit into the current buffer.
+ System.arraycopy(b, offset, buffer, bufferPos, length);
+ bufferPos += length;
+ } else {
+ // Use up the current buffer
+ int copySize = buffer.length - bufferPos;
+ System.arraycopy(b, offset, buffer, bufferPos, copySize);
+ offset += copySize;
+ length -= copySize;
+ // Flush the buffer, and get a new buffer at least big enough to cover
+ // what we still need to output
+ flushFullBuffer(length);
+ System.arraycopy(b, offset, buffer, 0 /* count */, length);
+ bufferPos = length;
+ }
+ }
+
+ /**
+ * Creates a byte string. Its size is the current size of this output
+ * stream and its output has been copied to it.
+ *
+ * @return the current contents of this output stream, as a byte string.
+ */
+ public synchronized ByteString toByteString() {
+ flushLastBuffer();
+ return ByteString.copyFrom(flushedBuffers);
+ }
+
+ /**
+ * Implement java.util.Arrays.copyOf() for jdk 1.5.
+ */
+ private byte[] copyArray(byte[] buffer, int length) {
+ byte[] result = new byte[length];
+ System.arraycopy(buffer, 0, result, 0, Math.min(buffer.length, length));
+ return result;
+ }
+
+ /**
+ * Writes the complete contents of this byte array output stream to
+ * the specified output stream argument.
+ *
+ * @param out the output stream to which to write the data.
+ * @throws IOException if an I/O error occurs.
+ */
+ public void writeTo(OutputStream out) throws IOException {
+ ByteString[] cachedFlushBuffers;
+ byte[] cachedBuffer;
+ int cachedBufferPos;
+ synchronized (this) {
+ // Copy the information we need into local variables so as to hold
+ // the lock for as short a time as possible.
+ cachedFlushBuffers =
+ flushedBuffers.toArray(new ByteString[flushedBuffers.size()]);
+ cachedBuffer = buffer;
+ cachedBufferPos = bufferPos;
+ }
+ for (ByteString byteString : cachedFlushBuffers) {
+ byteString.writeTo(out);
+ }
+
+ out.write(copyArray(cachedBuffer, cachedBufferPos));
+ }
+
+ /**
+ * Returns the current size of the output stream.
+ *
+ * @return the current size of the output stream
+ */
+ public synchronized int size() {
+ return flushedBuffersTotalBytes + bufferPos;
+ }
+
+ /**
+ * Resets this stream, so that all currently accumulated output in the
+ * output stream is discarded. The output stream can be used again,
+ * reusing the already allocated buffer space.
+ */
+ public synchronized void reset() {
+ flushedBuffers.clear();
+ flushedBuffersTotalBytes = 0;
+ bufferPos = 0;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("<ByteString.Output@%s size=%d>",
+ Integer.toHexString(System.identityHashCode(this)), size());
+ }
+
+ /**
+ * Internal function used by writers. The current buffer is full, and the
+ * writer needs a new buffer whose size is at least the specified minimum
+ * size.
+ */
+ private void flushFullBuffer(int minSize) {
+ flushedBuffers.add(new LiteralByteString(buffer));
+ flushedBuffersTotalBytes += buffer.length;
+ // We want to increase our total capacity by 50%, but as a minimum,
+ // the new buffer should also at least be >= minSize and
+ // >= initial Capacity.
+ int newSize = Math.max(initialCapacity,
+ Math.max(minSize, flushedBuffersTotalBytes >>> 1));
+ buffer = new byte[newSize];
+ bufferPos = 0;
+ }
+
+ /**
+ * Internal function used by {@link #toByteString()}. The current buffer may
+ * or may not be full, but it needs to be flushed.
+ */
+ private void flushLastBuffer() {
+ if (bufferPos < buffer.length) {
+ if (bufferPos > 0) {
+ byte[] bufferCopy = copyArray(buffer, bufferPos);
+ flushedBuffers.add(new LiteralByteString(bufferCopy));
+ }
+ // We reuse this buffer for further writes.
+ } else {
+ // Buffer is completely full. Huzzah.
+ flushedBuffers.add(new LiteralByteString(buffer));
+ // 99% of the time, we're not going to use this OutputStream again.
+ // We set buffer to an empty byte stream so that we're handling this
+ // case without wasting space. In the rare case that more writes
+ // *do* occur, this empty buffer will be flushed and an appropriately
+ // sized new buffer will be created.
+ buffer = EMPTY_BYTE_ARRAY;
+ }
+ flushedBuffersTotalBytes += bufferPos;
+ bufferPos = 0;
+ }
+ }
+
+ /**
+ * Constructs a new {@code ByteString} builder, which allows you to
+ * efficiently construct a {@code ByteString} by writing to a {@link
+ * CodedOutputStream}. Using this is much more efficient than calling {@code
+ * newOutput()} and wrapping that in a {@code CodedOutputStream}.
+ *
+ * <p>This is package-private because it's a somewhat confusing interface.
+ * Users can call {@link Message#toByteString()} instead of calling this
+ * directly.
+ *
+ * @param size The target byte size of the {@code ByteString}. You must write
+ * exactly this many bytes before building the result.
+ * @return the builder
+ */
+ static CodedBuilder newCodedBuilder(int size) {
+ return new CodedBuilder(size);
+ }
+
+ /** See {@link ByteString#newCodedBuilder(int)}. */
+ static final class CodedBuilder {
+ private final CodedOutputStream output;
+ private final byte[] buffer;
+
+ private CodedBuilder(int size) {
+ buffer = new byte[size];
+ output = CodedOutputStream.newInstance(buffer);
+ }
+
+ public ByteString build() {
+ output.checkNoSpaceLeft();
+
+ // We can be confident that the CodedOutputStream will not modify the
+ // underlying bytes anymore because it already wrote all of them. So,
+ // no need to make a copy.
+ return new LiteralByteString(buffer);
+ }
+
+ public CodedOutputStream getCodedOutput() {
+ return output;
+ }
+ }
+
+ // =================================================================
+ // Methods {@link RopeByteString} needs on instances, which aren't part of the
+ // public API.
+
+ /**
+ * Return the depth of the tree representing this {@code ByteString}, if any,
+ * whose root is this node. If this is a leaf node, return 0.
+ *
+ * @return tree depth or zero
+ */
+ protected abstract int getTreeDepth();
+
+ /**
+ * Return {@code true} if this ByteString is literal (a leaf node) or a
+ * flat-enough tree in the sense of {@link RopeByteString}.
+ *
+ * @return true if the tree is flat enough
+ */
+ protected abstract boolean isBalanced();
+
+ /**
+ * Return the cached hash code if available.
+ *
+ * @return value of cached hash code or 0 if not computed yet
+ */
+ protected final int peekCachedHashCode() {
+ return hash;
+ }
+
+ /**
+ * Compute the hash across the value bytes starting with the given hash, and
+ * return the result. This is used to compute the hash across strings
+ * represented as a set of pieces by allowing the hash computation to be
+ * continued from piece to piece.
+ *
+ * @param h starting hash value
+ * @param offset offset into this value to start looking at data values
+ * @param length number of data values to include in the hash computation
+ * @return ending hash value
+ */
+ protected abstract int partialHash(int h, int offset, int length);
+
+ /**
+ * Checks that the given index falls within the specified array size.
+ *
+ * @param index the index position to be tested
+ * @param size the length of the array
+ * @throws IndexOutOfBoundsException if the index does not fall within the array.
+ */
+ static void checkIndex(int index, int size) {
+ if ((index | (size - (index + 1))) < 0) {
+ if (index < 0) {
+ throw new ArrayIndexOutOfBoundsException("Index < 0: " + index);
+ }
+ throw new ArrayIndexOutOfBoundsException("Index > length: " + index + ", " + size);
+ }
+ }
+
+ /**
+ * Checks that the given range falls within the bounds of an array
+ *
+ * @param startIndex the start index of the range (inclusive)
+ * @param endIndex the end index of the range (exclusive)
+ * @param size the size of the array.
+ * @return the length of the range.
+ * @throws IndexOutOfBoundsException some or all of the range falls outside of the array.
+ */
+ static int checkRange(int startIndex, int endIndex, int size) {
+ final int length = endIndex - startIndex;
+ if ((startIndex | endIndex | length | (size - endIndex)) < 0) {
+ if (startIndex < 0) {
+ throw new IndexOutOfBoundsException("Beginning index: " + startIndex + " < 0");
+ }
+ if (endIndex < startIndex) {
+ throw new IndexOutOfBoundsException(
+ "Beginning index larger than ending index: " + startIndex + ", " + endIndex);
+ }
+ // endIndex >= size
+ throw new IndexOutOfBoundsException("End index: " + endIndex + " >= " + size);
+ }
+ return length;
+ }
+
+ @Override
+ public final String toString() {
+ return String.format("<ByteString@%s size=%d>",
+ Integer.toHexString(System.identityHashCode(this)), size());
+ }
+
+ /**
+ * This class implements a {@link com.google.protobuf.ByteString} backed by a
+ * single array of bytes, contiguous in memory. It supports substring by
+ * pointing to only a sub-range of the underlying byte array, meaning that a
+ * substring will reference the full byte-array of the string it's made from,
+ * exactly as with {@link String}.
+ *
+ * @author carlanton@google.com (Carl Haverl)
+ */
+ // Keep this class private to avoid deadlocks in classloading across threads as ByteString's
+ // static initializer loads LiteralByteString and another thread loads LiteralByteString.
+ private static class LiteralByteString extends ByteString.LeafByteString {
+ private static final long serialVersionUID = 1L;
+
+ protected final byte[] bytes;
+
+ /**
+ * Creates a {@code LiteralByteString} backed by the given array, without
+ * copying.
+ *
+ * @param bytes array to wrap
+ */
+ LiteralByteString(byte[] bytes) {
+ this.bytes = bytes;
+ }
+
+ @Override
+ public byte byteAt(int index) {
+ // Unlike most methods in this class, this one is a direct implementation
+ // ignoring the potential offset because we need to do range-checking in the
+ // substring case anyway.
+ return bytes[index];
+ }
+
+ @Override
+ public int size() {
+ return bytes.length;
+ }
+
+ // =================================================================
+ // ByteString -> substring
+
+ @Override
+ public final ByteString substring(int beginIndex, int endIndex) {
+ final int length = checkRange(beginIndex, endIndex, size());
+
+ if (length == 0) {
+ return ByteString.EMPTY;
+ }
+
+ return new BoundedByteString(bytes, getOffsetIntoBytes() + beginIndex, length);
+ }
+
+ // =================================================================
+ // ByteString -> byte[]
+
+ @Override
+ protected void copyToInternal(
+ byte[] target, int sourceOffset, int targetOffset, int numberToCopy) {
+ // Optimized form, not for subclasses, since we don't call
+ // getOffsetIntoBytes() or check the 'numberToCopy' parameter.
+ // TODO(nathanmittler): Is not calling getOffsetIntoBytes really saving that much?
+ System.arraycopy(bytes, sourceOffset, target, targetOffset, numberToCopy);
+ }
+
+ @Override
+ public final void copyTo(ByteBuffer target) {
+ target.put(bytes, getOffsetIntoBytes(), size()); // Copies bytes
+ }
+
+ @Override
+ public final ByteBuffer asReadOnlyByteBuffer() {
+ return ByteBuffer.wrap(bytes, getOffsetIntoBytes(), size()).asReadOnlyBuffer();
+ }
+
+ @Override
+ public final List<ByteBuffer> asReadOnlyByteBufferList() {
+ return Collections.singletonList(asReadOnlyByteBuffer());
+ }
+
+ @Override
+ public final void writeTo(OutputStream outputStream) throws IOException {
+ outputStream.write(toByteArray());
+ }
+
+ @Override
+ final void writeToInternal(OutputStream outputStream, int sourceOffset, int numberToWrite)
+ throws IOException {
+ outputStream.write(bytes, getOffsetIntoBytes() + sourceOffset, numberToWrite);
+ }
+
+ @Override
+ final void writeTo(ByteOutput output) throws IOException {
+ output.writeLazy(bytes, getOffsetIntoBytes(), size());
+ }
+
+ @Override
+ protected final String toStringInternal(Charset charset) {
+ return new String(bytes, getOffsetIntoBytes(), size(), charset);
+ }
+
+ // =================================================================
+ // UTF-8 decoding
+
+ @Override
+ public final boolean isValidUtf8() {
+ int offset = getOffsetIntoBytes();
+ return Utf8.isValidUtf8(bytes, offset, offset + size());
+ }
+
+ @Override
+ protected final int partialIsValidUtf8(int state, int offset, int length) {
+ int index = getOffsetIntoBytes() + offset;
+ return Utf8.partialIsValidUtf8(state, bytes, index, index + length);
+ }
+
+ // =================================================================
+ // equals() and hashCode()
+
+ @Override
+ public final boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (!(other instanceof ByteString)) {
+ return false;
+ }
+
+ if (size() != ((ByteString) other).size()) {
+ return false;
+ }
+ if (size() == 0) {
+ return true;
+ }
+
+ if (other instanceof LiteralByteString) {
+ LiteralByteString otherAsLiteral = (LiteralByteString) other;
+ // If we know the hash codes and they are not equal, we know the byte
+ // strings are not equal.
+ int thisHash = peekCachedHashCode();
+ int thatHash = otherAsLiteral.peekCachedHashCode();
+ if (thisHash != 0 && thatHash != 0 && thisHash != thatHash) {
+ return false;
+ }
+
+ return equalsRange((LiteralByteString) other, 0, size());
+ } else {
+ // RopeByteString and NioByteString.
+ return other.equals(this);
+ }
+ }
+
+ /**
+ * Check equality of the substring of given length of this object starting at
+ * zero with another {@code LiteralByteString} substring starting at offset.
+ *
+ * @param other what to compare a substring in
+ * @param offset offset into other
+ * @param length number of bytes to compare
+ * @return true for equality of substrings, else false.
+ */
+ @Override
+ final boolean equalsRange(ByteString other, int offset, int length) {
+ if (length > other.size()) {
+ throw new IllegalArgumentException("Length too large: " + length + size());
+ }
+ if (offset + length > other.size()) {
+ throw new IllegalArgumentException(
+ "Ran off end of other: " + offset + ", " + length + ", " + other.size());
+ }
+
+ if (other instanceof LiteralByteString) {
+ LiteralByteString lbsOther = (LiteralByteString) other;
+ byte[] thisBytes = bytes;
+ byte[] otherBytes = lbsOther.bytes;
+ int thisLimit = getOffsetIntoBytes() + length;
+ for (
+ int thisIndex = getOffsetIntoBytes(),
+ otherIndex = lbsOther.getOffsetIntoBytes() + offset;
+ (thisIndex < thisLimit); ++thisIndex, ++otherIndex) {
+ if (thisBytes[thisIndex] != otherBytes[otherIndex]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ return other.substring(offset, offset + length).equals(substring(0, length));
+ }
+
+ @Override
+ protected final int partialHash(int h, int offset, int length) {
+ return Internal.partialHash(h, bytes, getOffsetIntoBytes() + offset, length);
+ }
+
+ // =================================================================
+ // Input stream
+
+ @Override
+ public final InputStream newInput() {
+ return new ByteArrayInputStream(bytes, getOffsetIntoBytes(), size()); // No copy
+ }
+
+ @Override
+ public final CodedInputStream newCodedInput() {
+ // We trust CodedInputStream not to modify the bytes, or to give anyone
+ // else access to them.
+ return CodedInputStream.newInstance(
+ bytes, getOffsetIntoBytes(), size(), true /* bufferIsImmutable */);
+ }
+
+ // =================================================================
+ // Internal methods
+
+ /**
+ * Offset into {@code bytes[]} to use, non-zero for substrings.
+ *
+ * @return always 0 for this class
+ */
+ protected int getOffsetIntoBytes() {
+ return 0;
+ }
+ }
+
+ /**
+ * This class is used to represent the substring of a {@link ByteString} over a
+ * single byte array. In terms of the public API of {@link ByteString}, you end
+ * up here by calling {@link ByteString#copyFrom(byte[])} followed by {@link
+ * ByteString#substring(int, int)}.
+ *
+ * <p>This class contains most of the overhead involved in creating a substring
+ * from a {@link LiteralByteString}. The overhead involves some range-checking
+ * and two extra fields.
+ *
+ * @author carlanton@google.com (Carl Haverl)
+ */
+ // Keep this class private to avoid deadlocks in classloading across threads as ByteString's
+ // static initializer loads LiteralByteString and another thread loads BoundedByteString.
+ private static final class BoundedByteString extends LiteralByteString {
+
+ private final int bytesOffset;
+ private final int bytesLength;
+
+ /**
+ * Creates a {@code BoundedByteString} backed by the sub-range of given array,
+ * without copying.
+ *
+ * @param bytes array to wrap
+ * @param offset index to first byte to use in bytes
+ * @param length number of bytes to use from bytes
+ * @throws IllegalArgumentException if {@code offset < 0}, {@code length < 0},
+ * or if {@code offset + length >
+ * bytes.length}.
+ */
+ BoundedByteString(byte[] bytes, int offset, int length) {
+ super(bytes);
+ checkRange(offset, offset + length, bytes.length);
+
+ this.bytesOffset = offset;
+ this.bytesLength = length;
+ }
+
+ /**
+ * Gets the byte at the given index.
+ * Throws {@link ArrayIndexOutOfBoundsException}
+ * for backwards-compatibility reasons although it would more properly be
+ * {@link IndexOutOfBoundsException}.
+ *
+ * @param index index of byte
+ * @return the value
+ * @throws ArrayIndexOutOfBoundsException {@code index} is < 0 or >= size
+ */
+ @Override
+ public byte byteAt(int index) {
+ // We must check the index ourselves as we cannot rely on Java array index
+ // checking for substrings.
+ checkIndex(index, size());
+ return bytes[bytesOffset + index];
+ }
+
+ @Override
+ public int size() {
+ return bytesLength;
+ }
+
+ @Override
+ protected int getOffsetIntoBytes() {
+ return bytesOffset;
+ }
+
+ // =================================================================
+ // ByteString -> byte[]
+
+ @Override
+ protected void copyToInternal(byte[] target, int sourceOffset, int targetOffset,
+ int numberToCopy) {
+ System.arraycopy(bytes, getOffsetIntoBytes() + sourceOffset, target,
+ targetOffset, numberToCopy);
+ }
+
+ // =================================================================
+ // Serializable
+
+ private static final long serialVersionUID = 1L;
+
+ Object writeReplace() {
+ return ByteString.wrap(toByteArray());
+ }
+
+ private void readObject(@SuppressWarnings("unused") ObjectInputStream in) throws IOException {
+ throw new InvalidObjectException(
+ "BoundedByteStream instances are not to be serialized directly");
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/CodedInputStream.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/CodedInputStream.java
new file mode 100644
index 0000000000..239798e440
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/CodedInputStream.java
@@ -0,0 +1,2896 @@
+// 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 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;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Reads and decodes protocol message fields.
+ *
+ * <p>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 abstract class CodedInputStream {
+ private static final int DEFAULT_BUFFER_SIZE = 4096;
+ private static final int DEFAULT_RECURSION_LIMIT = 100;
+ // Integer.MAX_VALUE == 0x7FFFFFF == INT_MAX from limits.h
+ private static final int DEFAULT_SIZE_LIMIT = Integer.MAX_VALUE;
+
+ /** 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 newInstance(input, DEFAULT_BUFFER_SIZE);
+ }
+
+ /** Create a new CodedInputStream wrapping the given InputStream. */
+ static CodedInputStream newInstance(final InputStream input, int 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. */
+ 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) {
+ return newInstance(buf, off, len, false /* bufferIsImmutable */);
+ }
+
+ /** 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) {
+ 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
+ // buffer as a limit, we allow them to get this information via
+ // getBytesUntilLimit(). Pushing a limit that we know is at the end of
+ // the stream can never hurt, since we can never past that point anyway.
+ result.pushLimit(len);
+ } catch (InvalidProtocolBufferException ex) {
+ // The only reason pushLimit() might throw an exception here is if len
+ // is negative. Normally pushLimit()'s parameter comes directly off the
+ // wire, so it's important to catch exceptions in case of corrupt or
+ // malicious data. However, in this case, we expect that len is not a
+ // user-supplied value, so we can assume that it being negative indicates
+ // a programming error. Therefore, throwing an unchecked exception is
+ // appropriate.
+ throw new IllegalArgumentException(ex);
+ }
+ return result;
+ }
+
+ /**
+ * 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(), 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.
+ */
+ 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.
+ *
+ * @throws InvalidProtocolBufferException {@code value} does not match the last tag.
+ */
+ public abstract void checkLastTagWas(final int value) throws InvalidProtocolBufferException;
+
+ 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}.
+ */
+ 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.
+ *
+ * @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.
+ */
+ @Deprecated
+ public abstract boolean skipField(final int tag, final CodedOutputStream output)
+ throws IOException;
+
+ /**
+ * Reads and discards an entire message. This will read either until EOF or until an endgroup tag,
+ * whichever comes first.
+ */
+ public abstract void skipMessage() 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, whichever comes first.
+ */
+ public abstract void skipMessage(CodedOutputStream output) throws IOException;
+
+
+ // -----------------------------------------------------------------
+
+ /** Read a {@code double} field value from the stream. */
+ public abstract double readDouble() throws IOException;
+
+ /** Read a {@code float} field value from the stream. */
+ public abstract float readFloat() throws IOException;
+
+ /** Read a {@code uint64} field value from the stream. */
+ public abstract long readUInt64() throws IOException;
+
+ /** Read an {@code int64} field value from the stream. */
+ public abstract long readInt64() throws IOException;
+
+ /** Read an {@code int32} field value from the stream. */
+ public abstract int readInt32() throws IOException;
+
+ /** Read a {@code fixed64} field value from the stream. */
+ public abstract long readFixed64() throws IOException;
+
+ /** Read a {@code fixed32} field value from the stream. */
+ public abstract int readFixed32() throws IOException;
+
+ /** Read a {@code bool} field value from the stream. */
+ public abstract boolean readBool() throws IOException;
+
+ /**
+ * 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 abstract String readString() throws IOException;
+
+ /**
+ * Read a {@code string} field value from the stream. If the stream contains malformed UTF-8,
+ * throw exception {@link InvalidProtocolBufferException}.
+ */
+ public abstract String readStringRequireUtf8() throws IOException;
+
+ /** Read a {@code group} field value from the stream. */
+ 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 abstract <T extends MessageLite> T readGroup(
+ final int fieldNumber, final Parser<T> parser, final ExtensionRegistryLite extensionRegistry)
+ throws IOException;
+
+ /**
+ * 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
+ public abstract void readUnknownGroup(final int fieldNumber, final MessageLite.Builder builder)
+ throws IOException;
+
+ /** Read an embedded message field value from the stream. */
+ public abstract void readMessage(
+ final MessageLite.Builder builder, final ExtensionRegistryLite extensionRegistry)
+ throws IOException;
+
+
+ /** Read an embedded message field value from the stream. */
+ public abstract <T extends MessageLite> T readMessage(
+ final Parser<T> parser, final ExtensionRegistryLite extensionRegistry) throws IOException;
+
+ /** Read a {@code bytes} field value from the stream. */
+ public abstract ByteString readBytes() throws IOException;
+
+ /** Read a {@code bytes} field value from the stream. */
+ public abstract byte[] readByteArray() throws IOException;
+
+ /** Read a {@code bytes} field value from the stream. */
+ public abstract ByteBuffer readByteBuffer() throws IOException;
+
+ /** Read a {@code uint32} field value from the stream. */
+ 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.
+ */
+ public abstract int readEnum() throws IOException;
+
+ /** Read an {@code sfixed32} field value from the stream. */
+ public abstract int readSFixed32() throws IOException;
+
+ /** Read an {@code sfixed64} field value from the stream. */
+ public abstract long readSFixed64() throws IOException;
+
+ /** Read an {@code sint32} field value from the stream. */
+ public abstract int readSInt32() throws IOException;
+
+ /** Read an {@code sint64} field value from the stream. */
+ public abstract long readSInt64() throws IOException;
+
+ // =================================================================
+
+ /** 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 abstract long readRawVarint64() throws IOException;
+
+ /** Variant of readRawVarint64 for when uncomfortably close to the limit. */
+ /* Visible for testing */
+ abstract long readRawVarint64SlowPath() throws IOException;
+
+ /** Read a 32-bit little-endian integer from the stream. */
+ public abstract int readRawLittleEndian32() throws IOException;
+
+ /** Read a 64-bit little-endian integer from the stream. */
+ public abstract long readRawLittleEndian64() throws IOException;
+
+ // -----------------------------------------------------------------
+
+ /**
+ * Enables {@link ByteString} aliasing of the underlying buffer, trading off on buffer pinning for
+ * data copies. Only valid for buffer-backed streams.
+ */
+ 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.
+ *
+ * @return the old limit.
+ */
+ public final int setRecursionLimit(final int limit) {
+ if (limit < 0) {
+ throw new IllegalArgumentException("Recursion limit cannot be negative: " + limit);
+ }
+ final int oldLimit = recursionLimit;
+ recursionLimit = limit;
+ return oldLimit;
+ }
+
+ /**
+ * Only valid for {@link InputStream}-backed streams.
+ *
+ * <p>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 {@code Integer.MAX_INT}. 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.
+ *
+ * <p>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 final int setSizeLimit(final int limit) {
+ if (limit < 0) {
+ throw new IllegalArgumentException("Size limit cannot be negative: " + limit);
+ }
+ final int oldLimit = sizeLimit;
+ sizeLimit = limit;
+ return oldLimit;
+ }
+
+ /**
+ * Resets the current size counter to zero (see {@link #setSizeLimit(int)}). Only valid for {@link
+ * InputStream}-backed streams.
+ */
+ public abstract void resetSizeCounter();
+
+ /**
+ * Sets {@code currentLimit} to (current position) + {@code byteLimit}. This is called when
+ * descending into a length-delimited embedded message.
+ *
+ * <p>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 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 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.
+ */
+ 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)}.
+ */
+ public abstract boolean isAtEnd() throws IOException;
+
+ /**
+ * The total bytes read up to the current position. Calling {@link #resetSizeCounter()} resets
+ * this value to zero.
+ */
+ public abstract int getTotalBytesRead();
+
+ /**
+ * 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;
+
+ /**
+ * 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 and discards {@code size} bytes.
+ *
+ * @throws InvalidProtocolBufferException The end of the stream or the current limit was reached.
+ */
+ 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);
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * 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();
+ }
+
+ /**
+ * 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);
+ }
+
+ /** 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;
+ }
+
+ @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 <= (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 "";
+ }
+ if (size < 0) {
+ throw InvalidProtocolBufferException.negativeSize();
+ }
+ throw InvalidProtocolBufferException.truncatedMessage();
+ }
+
+ @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);
+ }
+
+ 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 extends MessageLite> T readGroup(
+ final int fieldNumber,
+ final Parser<T> 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 extends MessageLite> T readMessage(
+ final Parser<T> 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));
+ }
+
+ @Override
+ public byte[] readByteArray() throws IOException {
+ final int size = readRawVarint32();
+ return readRawBytes(size);
+ }
+
+ @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();
+ }
+ 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:
+ {
+ 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();
+ }
+ }
+
+ 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 (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();
+ }
+
+ @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[]}
+ * <strong>may</strong> 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 extends MessageLite> T readGroup(
+ final int fieldNumber,
+ final Parser<T> 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 extends MessageLite> T readMessage(
+ final Parser<T> 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 extends MessageLite> T readGroup(
+ final int fieldNumber,
+ final Parser<T> 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 extends MessageLite> T readMessage(
+ final Parser<T> 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();
+ }
+
+ // Integer-overflow-conscious check that the message size so far has not exceeded sizeLimit.
+ int currentMessageSize = totalBytesRetired + pos + size;
+ if (currentMessageSize - sizeLimit > 0) {
+ 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<byte[]> chunks = new ArrayList<byte[]>();
+
+ 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/third_party/protobuf/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java
new file mode 100644
index 0000000000..3e32c2c536
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/CodedOutputStream.java
@@ -0,0 +1,3001 @@
+// 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 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;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Encodes and writes protocol message fields.
+ *
+ * <p>This class contains two kinds of methods: methods that write specific
+ * protocol message constructs and field types (e.g. {@link #writeTag} and
+ * {@link #writeInt32}) and methods that write low-level values (e.g.
+ * {@link #writeRawVarint32} and {@link #writeRawBytes}). If you are
+ * writing encoded protocol messages, you should use the former methods, but if
+ * you are writing some other format of your own design, use the latter.
+ *
+ * <p>This class is totally unsynchronized.
+ */
+public abstract class CodedOutputStream extends ByteOutput {
+ private static final Logger logger = Logger.getLogger(CodedOutputStream.class.getName());
+ private static final boolean HAS_UNSAFE_ARRAY_OPERATIONS = UnsafeUtil.hasUnsafeArrayOperations();
+ private static final long ARRAY_BASE_OFFSET = UnsafeUtil.getArrayBaseOffset();
+
+ /**
+ * @deprecated Use {@link #computeFixed32SizeNoTag(int)} instead.
+ */
+ @Deprecated
+ public static final int LITTLE_ENDIAN_32_SIZE = FIXED_32_SIZE;
+
+ /**
+ * The buffer size used in {@link #newInstance(OutputStream)}.
+ */
+ public static final int DEFAULT_BUFFER_SIZE = 4096;
+
+ /**
+ * Returns the buffer size to efficiently write dataLength bytes to this
+ * CodedOutputStream. Used by AbstractMessageLite.
+ *
+ * @return the buffer size to efficiently write dataLength bytes to this
+ * CodedOutputStream.
+ */
+ static int computePreferredBufferSize(int dataLength) {
+ if (dataLength > DEFAULT_BUFFER_SIZE) {
+ return DEFAULT_BUFFER_SIZE;
+ }
+ return dataLength;
+ }
+
+ /**
+ * Create a new {@code CodedOutputStream} wrapping the given {@code OutputStream}.
+ *
+ * <p> NOTE: The provided {@link OutputStream} <strong>MUST NOT</strong> retain access or
+ * modify the provided byte arrays. Doing so may result in corrupted data, which would be
+ * difficult to debug.
+ */
+ public static CodedOutputStream newInstance(final OutputStream output) {
+ return newInstance(output, DEFAULT_BUFFER_SIZE);
+ }
+
+ /**
+ * Create a new {@code CodedOutputStream} wrapping the given {@code OutputStream} with a given
+ * buffer size.
+ *
+ * <p> NOTE: The provided {@link OutputStream} <strong>MUST NOT</strong> retain access or
+ * modify the provided byte arrays. Doing so may result in corrupted data, which would be
+ * difficult to debug.
+ */
+ public static CodedOutputStream newInstance(final OutputStream output, final int bufferSize) {
+ return new OutputStreamEncoder(output, bufferSize);
+ }
+
+ /**
+ * Create a new {@code CodedOutputStream} that writes directly to the given
+ * byte array. If more bytes are written than fit in the array,
+ * {@link OutOfSpaceException} will be thrown. Writing directly to a flat
+ * array is faster than writing to an {@code OutputStream}. See also
+ * {@link ByteString#newCodedBuilder}.
+ */
+ public static CodedOutputStream newInstance(final byte[] flatArray) {
+ return newInstance(flatArray, 0, flatArray.length);
+ }
+
+ /**
+ * Create a new {@code CodedOutputStream} that writes directly to the given
+ * byte array slice. If more bytes are written than fit in the slice,
+ * {@link OutOfSpaceException} will be thrown. Writing directly to a flat
+ * array is faster than writing to an {@code OutputStream}. See also
+ * {@link ByteString#newCodedBuilder}.
+ */
+ public static CodedOutputStream newInstance(
+ final byte[] flatArray, final int offset, final int length) {
+ return new ArrayEncoder(flatArray, offset, length);
+ }
+
+ /** 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);
+ }
+ 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);
+ }
+
+ /**
+ * Configures serialization to be deterministic.
+ *
+ * <p>The deterministic serialization guarantees that for a given binary, equal (defined by the
+ * {@code equals()} methods in protos) messages will always be serialized to the same bytes. This
+ * implies:
+ *
+ * <ul>
+ * <li>repeated serialization of a message will return the same bytes
+ * <li>different processes of the same binary (which may be executing on different machines) will
+ * serialize equal messages to the same bytes.
+ * </ul>
+ *
+ * <p>Note the deterministic serialization is NOT canonical across languages; it is also unstable
+ * across different builds with schema changes due to unknown fields. Users who need canonical
+ * serialization, e.g. persistent storage in a canonical form, fingerprinting, etc, should define
+ * their own canonicalization specification and implement the serializer using reflection APIs
+ * rather than relying on this API.
+ *
+ * <p> Once set, the serializer will: (Note this is an implementation detail and may subject to
+ * change in the future)
+ *
+ * <ul>
+ * <li> sort map entries by keys in lexicographical order or numerical order. Note: For string
+ * keys, the order is based on comparing the Unicode value of each character in the strings.
+ * The order may be different from the deterministic serialization in other languages where
+ * maps are sorted on the lexicographical order of the UTF8 encoded keys.
+ * </ul>
+ */
+ void useDeterministicSerialization() {
+ serializationDeterministic = true;
+ }
+
+ boolean isSerializationDeterministic() {
+ return serializationDeterministic;
+ }
+ private boolean serializationDeterministic;
+
+ /**
+ * Create a new {@code CodedOutputStream} that writes to the given {@link ByteBuffer}.
+ *
+ * @deprecated the size parameter is no longer used since use of an internal buffer is useless
+ * (and wasteful) when writing to a {@link ByteBuffer}. Use {@link #newInstance(ByteBuffer)}
+ * instead.
+ */
+ @Deprecated
+ public static CodedOutputStream newInstance(ByteBuffer byteBuffer,
+ @SuppressWarnings("unused") int unused) {
+ return newInstance(byteBuffer);
+ }
+
+ /**
+ * Create a new {@code CodedOutputStream} that writes to the provided {@link ByteOutput}.
+ *
+ * <p> NOTE: The {@link ByteOutput} <strong>MUST NOT</strong> modify the provided buffers. Doing
+ * so may result in corrupted data, which would be difficult to debug.
+ *
+ * @param byteOutput the output target for encoded bytes.
+ * @param bufferSize the size of the internal scratch buffer to be used for string encoding.
+ * Setting this to {@code 0} will disable buffering, requiring an allocation for each encoded
+ * string.
+ */
+ static CodedOutputStream newInstance(ByteOutput byteOutput, int bufferSize) {
+ if (bufferSize < 0) {
+ throw new IllegalArgumentException("bufferSize must be positive");
+ }
+
+ return new ByteOutputEncoder(byteOutput, bufferSize);
+ }
+
+ // Disallow construction outside of this class.
+ private CodedOutputStream() {
+ }
+
+ // -----------------------------------------------------------------
+
+ /** Encode and write a tag. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeTag(int fieldNumber, int wireType) throws IOException;
+
+ /** Write an {@code int32} field, including tag, to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeInt32(int fieldNumber, int value) throws IOException;
+
+ /** Write a {@code uint32} field, including tag, to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeUInt32(int fieldNumber, int value) throws IOException;
+
+ /** Write a {@code sint32} field, including tag, to the stream. */
+ public final void writeSInt32(final int fieldNumber, final int value) throws IOException {
+ writeUInt32(fieldNumber, encodeZigZag32(value));
+ }
+
+ /** Write a {@code fixed32} field, including tag, to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeFixed32(int fieldNumber, int value) throws IOException;
+
+ /** Write an {@code sfixed32} field, including tag, to the stream. */
+ public final void writeSFixed32(final int fieldNumber, final int value) throws IOException {
+ writeFixed32(fieldNumber, value);
+ }
+
+ /** Write an {@code int64} field, including tag, to the stream. */
+ public final void writeInt64(final int fieldNumber, final long value) throws IOException {
+ writeUInt64(fieldNumber, value);
+ }
+
+ /** Write a {@code uint64} field, including tag, to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeUInt64(int fieldNumber, long value) throws IOException;
+
+ /** Write an {@code sint64} field, including tag, to the stream. */
+ public final void writeSInt64(final int fieldNumber, final long value) throws IOException {
+ writeUInt64(fieldNumber, encodeZigZag64(value));
+ }
+
+ /** Write a {@code fixed64} field, including tag, to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeFixed64(int fieldNumber, long value) throws IOException;
+
+ /** Write an {@code sfixed64} field, including tag, to the stream. */
+ public final void writeSFixed64(final int fieldNumber, final long value) throws IOException {
+ writeFixed64(fieldNumber, value);
+ }
+
+ /** Write a {@code float} field, including tag, to the stream. */
+ public final void writeFloat(final int fieldNumber, final float value) throws IOException {
+ writeFixed32(fieldNumber, Float.floatToRawIntBits(value));
+ }
+
+ /** Write a {@code double} field, including tag, to the stream. */
+ public final void writeDouble(final int fieldNumber, final double value) throws IOException {
+ writeFixed64(fieldNumber, Double.doubleToRawLongBits(value));
+ }
+
+ /** Write a {@code bool} field, including tag, to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeBool(int fieldNumber, boolean value) throws IOException;
+
+ /**
+ * Write an enum field, including tag, to the stream. The provided value is the numeric
+ * value used to represent the enum value on the wire (not the enum ordinal value).
+ */
+ public final void writeEnum(final int fieldNumber, final int value) throws IOException {
+ writeInt32(fieldNumber, value);
+ }
+
+ /** Write a {@code string} field, including tag, to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeString(int fieldNumber, String value) throws IOException;
+
+ /** Write a {@code bytes} field, including tag, to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeBytes(int fieldNumber, ByteString value) throws IOException;
+
+ /** Write a {@code bytes} field, including tag, to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeByteArray(int fieldNumber, byte[] value) throws IOException;
+
+ /** Write a {@code bytes} field, including tag, to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeByteArray(int fieldNumber, byte[] value, int offset, int length)
+ throws IOException;
+
+ /**
+ * Write a {@code bytes} field, including tag, to the stream.
+ * This method will write all content of the ByteBuffer regardless of the
+ * current position and limit (i.e., the number of bytes to be written is
+ * value.capacity(), not value.remaining()). Furthermore, this method doesn't
+ * alter the state of the passed-in ByteBuffer. Its position, limit, mark,
+ * etc. will remain unchanged. If you only want to write the remaining bytes
+ * of a ByteBuffer, you can call
+ * {@code writeByteBuffer(fieldNumber, byteBuffer.slice())}.
+ */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeByteBuffer(int fieldNumber, ByteBuffer value) throws IOException;
+
+ /**
+ * Write a single byte.
+ */
+ public final void writeRawByte(final byte value) throws IOException {
+ write(value);
+ }
+
+ /** Write a single byte, represented by an integer value. */
+ public final void writeRawByte(final int value) throws IOException {
+ write((byte) value);
+ }
+
+ /** Write an array of bytes. */
+ public final void writeRawBytes(final byte[] value) throws IOException {
+ write(value, 0, value.length);
+ }
+
+ /**
+ * Write part of an array of bytes.
+ */
+ public final void writeRawBytes(final byte[] value, int offset, int length) throws IOException {
+ write(value, offset, length);
+ }
+
+ /** Write a byte string. */
+ public final void writeRawBytes(final ByteString value) throws IOException {
+ value.writeTo(this);
+ }
+
+ /**
+ * Write a ByteBuffer. This method will write all content of the ByteBuffer
+ * regardless of the current position and limit (i.e., the number of bytes
+ * to be written is value.capacity(), not value.remaining()). Furthermore,
+ * this method doesn't alter the state of the passed-in ByteBuffer. Its
+ * position, limit, mark, etc. will remain unchanged. If you only want to
+ * write the remaining bytes of a ByteBuffer, you can call
+ * {@code writeRawBytes(byteBuffer.slice())}.
+ */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeRawBytes(final ByteBuffer value) throws IOException;
+
+ /** Write an embedded message field, including tag, to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeMessage(final int fieldNumber, final MessageLite value)
+ throws IOException;
+
+ /**
+ * Write a MessageSet extension field to the stream. For historical reasons,
+ * the wire format differs from normal fields.
+ */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeMessageSetExtension(final int fieldNumber, final MessageLite value)
+ throws IOException;
+
+ /**
+ * Write an unparsed MessageSet extension field to the stream. For
+ * historical reasons, the wire format differs from normal fields.
+ */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeRawMessageSetExtension(final int fieldNumber, final ByteString value)
+ throws IOException;
+
+ // -----------------------------------------------------------------
+
+ /** Write an {@code int32} field to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeInt32NoTag(final int value) throws IOException;
+
+ /** Write a {@code uint32} field to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeUInt32NoTag(int value) throws IOException;
+
+ /** Write a {@code sint32} field to the stream. */
+ public final void writeSInt32NoTag(final int value) throws IOException {
+ writeUInt32NoTag(encodeZigZag32(value));
+ }
+
+ /** Write a {@code fixed32} field to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeFixed32NoTag(int value) throws IOException;
+
+ /** Write a {@code sfixed32} field to the stream. */
+ public final void writeSFixed32NoTag(final int value) throws IOException {
+ writeFixed32NoTag(value);
+ }
+
+ /** Write an {@code int64} field to the stream. */
+ public final void writeInt64NoTag(final long value) throws IOException {
+ writeUInt64NoTag(value);
+ }
+
+ /** Write a {@code uint64} field to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeUInt64NoTag(long value) throws IOException;
+
+ /** Write a {@code sint64} field to the stream. */
+ public final void writeSInt64NoTag(final long value) throws IOException {
+ writeUInt64NoTag(encodeZigZag64(value));
+ }
+
+ /** Write a {@code fixed64} field to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeFixed64NoTag(long value) throws IOException;
+
+ /** Write a {@code sfixed64} field to the stream. */
+ public final void writeSFixed64NoTag(final long value) throws IOException {
+ writeFixed64NoTag(value);
+ }
+
+ /** Write a {@code float} field to the stream. */
+ public final void writeFloatNoTag(final float value) throws IOException {
+ writeFixed32NoTag(Float.floatToRawIntBits(value));
+ }
+
+ /** Write a {@code double} field to the stream. */
+ public final void writeDoubleNoTag(final double value) throws IOException {
+ writeFixed64NoTag(Double.doubleToRawLongBits(value));
+ }
+
+ /** Write a {@code bool} field to the stream. */
+ public final void writeBoolNoTag(final boolean value) throws IOException {
+ write((byte) (value ? 1 : 0));
+ }
+
+ /**
+ * Write an enum field to the stream. The provided value is the numeric
+ * value used to represent the enum value on the wire (not the enum ordinal value).
+ */
+ public final void writeEnumNoTag(final int value) throws IOException {
+ writeInt32NoTag(value);
+ }
+
+ /** Write a {@code string} field to the stream. */
+ // TODO(dweis): Document behavior on ill-formed UTF-16 input.
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeStringNoTag(String value) throws IOException;
+
+ /** Write a {@code bytes} field to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeBytesNoTag(final ByteString value) throws IOException;
+
+ /** Write a {@code bytes} field to the stream. */
+ public final void writeByteArrayNoTag(final byte[] value) throws IOException {
+ writeByteArrayNoTag(value, 0, value.length);
+ }
+
+ /** Write an embedded message field to the stream. */
+ // Abstract to avoid overhead of additional virtual method calls.
+ public abstract void writeMessageNoTag(final MessageLite value) throws IOException;
+
+ //=================================================================
+
+ @ExperimentalApi
+ @Override
+ public abstract void write(byte value) throws IOException;
+
+ @ExperimentalApi
+ @Override
+ public abstract void write(byte[] value, int offset, int length) throws IOException;
+
+ @ExperimentalApi
+ @Override
+ public abstract void writeLazy(byte[] value, int offset, int length) throws IOException;
+
+ @Override
+ public abstract void write(ByteBuffer value) throws IOException;
+
+ @ExperimentalApi
+ @Override
+ public abstract void writeLazy(ByteBuffer value) throws IOException;
+
+ // =================================================================
+ // =================================================================
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code int32} field, including tag.
+ */
+ public static int computeInt32Size(final int fieldNumber, final int value) {
+ return computeTagSize(fieldNumber) + computeInt32SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code uint32} field, including tag.
+ */
+ public static int computeUInt32Size(final int fieldNumber, final int value) {
+ return computeTagSize(fieldNumber) + computeUInt32SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sint32} field, including tag.
+ */
+ public static int computeSInt32Size(final int fieldNumber, final int value) {
+ return computeTagSize(fieldNumber) + computeSInt32SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code fixed32} field, including tag.
+ */
+ public static int computeFixed32Size(final int fieldNumber, final int value) {
+ return computeTagSize(fieldNumber) + computeFixed32SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sfixed32} field, including tag.
+ */
+ public static int computeSFixed32Size(final int fieldNumber, final int value) {
+ return computeTagSize(fieldNumber) + computeSFixed32SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code int64} field, including tag.
+ */
+ public static int computeInt64Size(final int fieldNumber, final long value) {
+ return computeTagSize(fieldNumber) + computeInt64SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code uint64} field, including tag.
+ */
+ public static int computeUInt64Size(final int fieldNumber, final long value) {
+ return computeTagSize(fieldNumber) + computeUInt64SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sint64} field, including tag.
+ */
+ public static int computeSInt64Size(final int fieldNumber, final long value) {
+ return computeTagSize(fieldNumber) + computeSInt64SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code fixed64} field, including tag.
+ */
+ public static int computeFixed64Size(final int fieldNumber, final long value) {
+ return computeTagSize(fieldNumber) + computeFixed64SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sfixed64} field, including tag.
+ */
+ public static int computeSFixed64Size(final int fieldNumber, final long value) {
+ return computeTagSize(fieldNumber) + computeSFixed64SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code float} field, including tag.
+ */
+ public static int computeFloatSize(final int fieldNumber, final float value) {
+ return computeTagSize(fieldNumber) + computeFloatSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code double} field, including tag.
+ */
+ public static int computeDoubleSize(final int fieldNumber, final double value) {
+ return computeTagSize(fieldNumber) + computeDoubleSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code bool} field, including tag.
+ */
+ public static int computeBoolSize(final int fieldNumber, final boolean value) {
+ return computeTagSize(fieldNumber) + computeBoolSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * enum field, including tag. The provided value is the numeric
+ * value used to represent the enum value on the wire (not the enum ordinal value).
+ */
+ public static int computeEnumSize(final int fieldNumber, final int value) {
+ return computeTagSize(fieldNumber) + computeEnumSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code string} field, including tag.
+ */
+ public static int computeStringSize(final int fieldNumber, final String value) {
+ return computeTagSize(fieldNumber) + computeStringSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code bytes} field, including tag.
+ */
+ public static int computeBytesSize(final int fieldNumber, final ByteString value) {
+ return computeTagSize(fieldNumber) + computeBytesSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code bytes} field, including tag.
+ */
+ public static int computeByteArraySize(final int fieldNumber, final byte[] value) {
+ return computeTagSize(fieldNumber) + computeByteArraySizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code bytes} field, including tag.
+ */
+ public static int computeByteBufferSize(final int fieldNumber, final ByteBuffer value) {
+ return computeTagSize(fieldNumber) + computeByteBufferSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * embedded message in lazy field, including tag.
+ */
+ public static int computeLazyFieldSize(final int fieldNumber, final LazyFieldLite value) {
+ return computeTagSize(fieldNumber) + computeLazyFieldSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * embedded message field, including tag.
+ */
+ public static int computeMessageSize(final int fieldNumber, final MessageLite value) {
+ return computeTagSize(fieldNumber) + computeMessageSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * MessageSet extension to the stream. For historical reasons,
+ * the wire format differs from normal fields.
+ */
+ public static int computeMessageSetExtensionSize(final int fieldNumber, final MessageLite value) {
+ return computeTagSize(WireFormat.MESSAGE_SET_ITEM) * 2
+ + computeUInt32Size(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber)
+ + computeMessageSize(WireFormat.MESSAGE_SET_MESSAGE, value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * unparsed MessageSet extension field to the stream. For
+ * historical reasons, the wire format differs from normal fields.
+ */
+ public static int computeRawMessageSetExtensionSize(
+ final int fieldNumber, final ByteString value) {
+ return computeTagSize(WireFormat.MESSAGE_SET_ITEM) * 2
+ + computeUInt32Size(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber)
+ + computeBytesSize(WireFormat.MESSAGE_SET_MESSAGE, value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * lazily parsed MessageSet extension field to the stream. For
+ * historical reasons, the wire format differs from normal fields.
+ */
+ public static int computeLazyFieldMessageSetExtensionSize(
+ final int fieldNumber, final LazyFieldLite value) {
+ return computeTagSize(WireFormat.MESSAGE_SET_ITEM) * 2
+ + computeUInt32Size(WireFormat.MESSAGE_SET_TYPE_ID, fieldNumber)
+ + computeLazyFieldSize(WireFormat.MESSAGE_SET_MESSAGE, value);
+ }
+
+ // -----------------------------------------------------------------
+
+ /** Compute the number of bytes that would be needed to encode a tag. */
+ public static int computeTagSize(final int fieldNumber) {
+ return computeUInt32SizeNoTag(WireFormat.makeTag(fieldNumber, 0));
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code int32} field, including tag.
+ */
+ public static int computeInt32SizeNoTag(final int value) {
+ if (value >= 0) {
+ return computeUInt32SizeNoTag(value);
+ } else {
+ // Must sign-extend.
+ return MAX_VARINT_SIZE;
+ }
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code uint32} field.
+ */
+ public static int computeUInt32SizeNoTag(final int value) {
+ if ((value & (~0 << 7)) == 0) {
+ return 1;
+ }
+ if ((value & (~0 << 14)) == 0) {
+ return 2;
+ }
+ if ((value & (~0 << 21)) == 0) {
+ return 3;
+ }
+ if ((value & (~0 << 28)) == 0) {
+ return 4;
+ }
+ return 5;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sint32} field.
+ */
+ public static int computeSInt32SizeNoTag(final int value) {
+ return computeUInt32SizeNoTag(encodeZigZag32(value));
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code fixed32} field.
+ */
+ public static int computeFixed32SizeNoTag(@SuppressWarnings("unused") final int unused) {
+ return FIXED_32_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sfixed32} field.
+ */
+ public static int computeSFixed32SizeNoTag(@SuppressWarnings("unused") final int unused) {
+ return FIXED_32_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code int64} field, including tag.
+ */
+ public static int computeInt64SizeNoTag(final long value) {
+ return computeUInt64SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code uint64} field, including tag.
+ */
+ public static int computeUInt64SizeNoTag(long value) {
+ // handle two popular special cases up front ...
+ if ((value & (~0L << 7)) == 0L) {
+ return 1;
+ }
+ if (value < 0L) {
+ return 10;
+ }
+ // ... leaving us with 8 remaining, which we can divide and conquer
+ int n = 2;
+ if ((value & (~0L << 35)) != 0L) {
+ n += 4; value >>>= 28;
+ }
+ if ((value & (~0L << 21)) != 0L) {
+ n += 2; value >>>= 14;
+ }
+ if ((value & (~0L << 14)) != 0L) {
+ n += 1;
+ }
+ return n;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sint64} field.
+ */
+ public static int computeSInt64SizeNoTag(final long value) {
+ return computeUInt64SizeNoTag(encodeZigZag64(value));
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code fixed64} field.
+ */
+ public static int computeFixed64SizeNoTag(@SuppressWarnings("unused") final long unused) {
+ return FIXED_64_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sfixed64} field.
+ */
+ public static int computeSFixed64SizeNoTag(@SuppressWarnings("unused") final long unused) {
+ return FIXED_64_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code float} field, including tag.
+ */
+ public static int computeFloatSizeNoTag(@SuppressWarnings("unused") final float unused) {
+ return FIXED_32_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code double} field, including tag.
+ */
+ public static int computeDoubleSizeNoTag(@SuppressWarnings("unused") final double unused) {
+ return FIXED_64_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code bool} field.
+ */
+ public static int computeBoolSizeNoTag(@SuppressWarnings("unused") final boolean unused) {
+ return 1;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an enum field.
+ * The provided value is the numeric value used to represent the enum value on the wire
+ * (not the enum ordinal value).
+ */
+ public static int computeEnumSizeNoTag(final int value) {
+ return computeInt32SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code string} field.
+ */
+ public static int computeStringSizeNoTag(final String value) {
+ int length;
+ try {
+ length = Utf8.encodedLength(value);
+ } catch (UnpairedSurrogateException e) {
+ // TODO(dweis): Consider using nio Charset methods instead.
+ final byte[] bytes = value.getBytes(Internal.UTF_8);
+ length = bytes.length;
+ }
+
+ return computeLengthDelimitedFieldSize(length);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an embedded
+ * message stored in lazy field.
+ */
+ public static int computeLazyFieldSizeNoTag(final LazyFieldLite value) {
+ return computeLengthDelimitedFieldSize(value.getSerializedSize());
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code bytes} field.
+ */
+ public static int computeBytesSizeNoTag(final ByteString value) {
+ return computeLengthDelimitedFieldSize(value.size());
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code bytes} field.
+ */
+ public static int computeByteArraySizeNoTag(final byte[] value) {
+ return computeLengthDelimitedFieldSize(value.length);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code bytes} field.
+ */
+ public static int computeByteBufferSizeNoTag(final ByteBuffer value) {
+ return computeLengthDelimitedFieldSize(value.capacity());
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an embedded
+ * message field.
+ */
+ public static int computeMessageSizeNoTag(final MessageLite value) {
+ return computeLengthDelimitedFieldSize(value.getSerializedSize());
+ }
+
+ static int computeLengthDelimitedFieldSize(int fieldLength) {
+ return computeUInt32SizeNoTag(fieldLength) + fieldLength;
+ }
+
+ /**
+ * Encode 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 A signed 32-bit integer.
+ * @return An unsigned 32-bit integer, stored in a signed int because
+ * Java has no explicit unsigned support.
+ */
+ public static int encodeZigZag32(final int n) {
+ // Note: the right-shift must be arithmetic
+ return (n << 1) ^ (n >> 31);
+ }
+
+ /**
+ * Encode 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 A signed 64-bit integer.
+ * @return An unsigned 64-bit integer, stored in a signed int because
+ * Java has no explicit unsigned support.
+ */
+ public static long encodeZigZag64(final long n) {
+ // Note: the right-shift must be arithmetic
+ return (n << 1) ^ (n >> 63);
+ }
+
+ // =================================================================
+
+ /**
+ * Flushes the stream and forces any buffered bytes to be written. This
+ * does not flush the underlying OutputStream.
+ */
+ public abstract void flush() throws IOException;
+
+ /**
+ * If writing to a flat array, return the space left in the array.
+ * Otherwise, throws {@code UnsupportedOperationException}.
+ */
+ public abstract int spaceLeft();
+
+ /**
+ * Verifies that {@link #spaceLeft()} returns zero. It's common to create
+ * a byte array that is exactly big enough to hold a message, then write to
+ * it with a {@code CodedOutputStream}. Calling {@code checkNoSpaceLeft()}
+ * after writing verifies that the message was actually as big as expected,
+ * which can help catch bugs.
+ */
+ public final void checkNoSpaceLeft() {
+ if (spaceLeft() != 0) {
+ throw new IllegalStateException("Did not write as much data as expected.");
+ }
+ }
+
+ /**
+ * If you create a CodedOutputStream around a simple flat array, you must
+ * not attempt to write more bytes than the array has space. Otherwise,
+ * this exception will be thrown.
+ */
+ public static class OutOfSpaceException extends IOException {
+ private static final long serialVersionUID = -6947486886997889499L;
+
+ private static final String MESSAGE =
+ "CodedOutputStream was writing to a flat byte array and ran out of space.";
+
+ OutOfSpaceException() {
+ super(MESSAGE);
+ }
+
+ OutOfSpaceException(String explanationMessage) {
+ super(MESSAGE + ": " + explanationMessage);
+ }
+
+ OutOfSpaceException(Throwable cause) {
+ super(MESSAGE, cause);
+ }
+
+ OutOfSpaceException(String explanationMessage, Throwable cause) {
+ super(MESSAGE + ": " + explanationMessage, cause);
+ }
+ }
+
+ /**
+ * Get the total number of bytes successfully written to this stream. The
+ * returned value is not guaranteed to be accurate if exceptions have been
+ * found in the middle of writing.
+ */
+ public abstract int getTotalBytesWritten();
+
+ // =================================================================
+
+ /** Write a {@code bytes} field to the stream. Visible for testing. */
+ abstract void writeByteArrayNoTag(final byte[] value, final int offset, final int length)
+ throws IOException;
+
+ final void inefficientWriteStringNoTag(String value, UnpairedSurrogateException cause)
+ throws IOException {
+ logger.log(Level.WARNING,
+ "Converting ill-formed UTF-16. Your Protocol Buffer will not round trip correctly!", cause);
+
+ // Unfortunately there does not appear to be any way to tell Java to encode
+ // UTF-8 directly into our buffer, so we have to let it create its own byte
+ // array and then copy.
+ // TODO(dweis): Consider using nio Charset methods instead.
+ final byte[] bytes = value.getBytes(Internal.UTF_8);
+ try {
+ writeUInt32NoTag(bytes.length);
+ writeLazy(bytes, 0, bytes.length);
+ } catch (IndexOutOfBoundsException e) {
+ throw new OutOfSpaceException(e);
+ } catch (OutOfSpaceException e) {
+ throw e;
+ }
+ }
+
+ // =================================================================
+
+ /**
+ * Write a {@code group} field, including tag, to the stream.
+ *
+ * @deprecated groups are deprecated.
+ */
+ @Deprecated
+ public final void writeGroup(final int fieldNumber, final MessageLite value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_START_GROUP);
+ writeGroupNoTag(value);
+ writeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP);
+ }
+
+ /**
+ * Write a {@code group} field to the stream.
+ *
+ * @deprecated groups are deprecated.
+ */
+ @Deprecated
+ public final void writeGroupNoTag(final MessageLite value) throws IOException {
+ value.writeTo(this);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code group} field, including tag.
+ *
+ * @deprecated groups are deprecated.
+ */
+ @Deprecated
+ public static int computeGroupSize(final int fieldNumber, final MessageLite value) {
+ return computeTagSize(fieldNumber) * 2 + computeGroupSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code group} field.
+ */
+ @Deprecated
+ public static int computeGroupSizeNoTag(final MessageLite value) {
+ return value.getSerializedSize();
+ }
+
+ /**
+ * Encode and write a varint. {@code value} is treated as
+ * unsigned, so it won't be sign-extended if negative.
+ *
+ * @deprecated use {@link #writeUInt32NoTag} instead.
+ */
+ @Deprecated
+ public final void writeRawVarint32(int value) throws IOException {
+ writeUInt32NoTag(value);
+ }
+
+ /**
+ * Encode and write a varint.
+ *
+ * @deprecated use {@link #writeUInt64NoTag} instead.
+ */
+ @Deprecated
+ public final void writeRawVarint64(long value) throws IOException {
+ writeUInt64NoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a varint.
+ * {@code value} is treated as unsigned, so it won't be sign-extended if
+ * negative.
+ *
+ * @deprecated use {@link #computeUInt32SizeNoTag(int)} instead.
+ */
+ @Deprecated
+ public static int computeRawVarint32Size(final int value) {
+ return computeUInt32SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a varint.
+ *
+ * @deprecated use {@link #computeUInt64SizeNoTag(long)} instead.
+ */
+ @Deprecated
+ public static int computeRawVarint64Size(long value) {
+ return computeUInt64SizeNoTag(value);
+ }
+
+ /**
+ * Write a little-endian 32-bit integer.
+ *
+ * @deprecated Use {@link #writeFixed32NoTag} instead.
+ */
+ @Deprecated
+ public final void writeRawLittleEndian32(final int value) throws IOException {
+ writeFixed32NoTag(value);
+ }
+
+ /**
+ * Write a little-endian 64-bit integer.
+ *
+ * @deprecated Use {@link #writeFixed64NoTag} instead.
+ */
+ @Deprecated
+ public final void writeRawLittleEndian64(final long value) throws IOException {
+ writeFixed64NoTag(value);
+ }
+
+ // =================================================================
+
+ /**
+ * A {@link CodedOutputStream} that writes directly to a byte array.
+ */
+ private static class ArrayEncoder extends CodedOutputStream {
+ private final byte[] buffer;
+ private final int offset;
+ private final int limit;
+ private int position;
+
+ ArrayEncoder(byte[] buffer, int offset, int length) {
+ if (buffer == null) {
+ throw new NullPointerException("buffer");
+ }
+ if ((offset | length | (buffer.length - (offset + length))) < 0) {
+ throw new IllegalArgumentException(String.format(
+ "Array range is invalid. Buffer.length=%d, offset=%d, length=%d",
+ buffer.length, offset, length));
+ }
+ this.buffer = buffer;
+ this.offset = offset;
+ position = offset;
+ limit = offset + length;
+ }
+
+ @Override
+ public final void writeTag(final int fieldNumber, final int wireType) throws IOException {
+ writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType));
+ }
+
+ @Override
+ public final void writeInt32(final int fieldNumber, final int value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeInt32NoTag(value);
+ }
+
+ @Override
+ public final void writeUInt32(final int fieldNumber, final int value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeUInt32NoTag(value);
+ }
+
+ @Override
+ public final void writeFixed32(final int fieldNumber, final int value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
+ writeFixed32NoTag(value);
+ }
+
+ @Override
+ public final void writeUInt64(final int fieldNumber, final long value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeUInt64NoTag(value);
+ }
+
+ @Override
+ public final void writeFixed64(final int fieldNumber, final long value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
+ writeFixed64NoTag(value);
+ }
+
+ @Override
+ public final void writeBool(final int fieldNumber, final boolean value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ write((byte) (value ? 1 : 0));
+ }
+
+ @Override
+ public final void writeString(final int fieldNumber, final String value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeStringNoTag(value);
+ }
+
+ @Override
+ public final void writeBytes(final int fieldNumber, final ByteString value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeBytesNoTag(value);
+ }
+
+ @Override
+ public final void writeByteArray(final int fieldNumber, final byte[] value) throws IOException {
+ writeByteArray(fieldNumber, value, 0, value.length);
+ }
+
+ @Override
+ public final void writeByteArray(
+ final int fieldNumber, final byte[] value, final int offset, final int length)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeByteArrayNoTag(value, offset, length);
+ }
+
+ @Override
+ public final void writeByteBuffer(final int fieldNumber, final ByteBuffer value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeUInt32NoTag(value.capacity());
+ writeRawBytes(value);
+ }
+
+ @Override
+ public final void writeBytesNoTag(final ByteString value) throws IOException {
+ writeUInt32NoTag(value.size());
+ value.writeTo(this);
+ }
+
+ @Override
+ public final void writeByteArrayNoTag(final byte[] value, int offset, int length)
+ throws IOException {
+ writeUInt32NoTag(length);
+ write(value, offset, length);
+ }
+
+ @Override
+ public final void writeRawBytes(final 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 final void writeMessage(final int fieldNumber, final MessageLite value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeMessageNoTag(value);
+ }
+
+ @Override
+ public final void writeMessageSetExtension(final int fieldNumber, final 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 final void writeRawMessageSetExtension(final int fieldNumber, final 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 final void writeMessageNoTag(final MessageLite value) throws IOException {
+ writeUInt32NoTag(value.getSerializedSize());
+ value.writeTo(this);
+ }
+
+ @Override
+ public final void write(byte value) throws IOException {
+ try {
+ buffer[position++] = value;
+ } catch (IndexOutOfBoundsException e) {
+ throw new OutOfSpaceException(
+ String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e);
+ }
+ }
+
+ @Override
+ public final void writeInt32NoTag(int value) throws IOException {
+ if (value >= 0) {
+ writeUInt32NoTag(value);
+ } else {
+ // Must sign-extend.
+ writeUInt64NoTag(value);
+ }
+ }
+
+ @Override
+ public final void writeUInt32NoTag(int value) throws IOException {
+ if (HAS_UNSAFE_ARRAY_OPERATIONS && spaceLeft() >= MAX_VARINT_SIZE) {
+ long pos = ARRAY_BASE_OFFSET + position;
+ while (true) {
+ if ((value & ~0x7F) == 0) {
+ UnsafeUtil.putByte(buffer, pos++, (byte) value);
+ position++;
+ return;
+ } else {
+ UnsafeUtil.putByte(buffer, pos++, (byte) ((value & 0x7F) | 0x80));
+ position++;
+ value >>>= 7;
+ }
+ }
+ } else {
+ try {
+ while (true) {
+ if ((value & ~0x7F) == 0) {
+ buffer[position++] = (byte) value;
+ return;
+ } else {
+ buffer[position++] = (byte) ((value & 0x7F) | 0x80);
+ value >>>= 7;
+ }
+ }
+ } catch (IndexOutOfBoundsException e) {
+ throw new OutOfSpaceException(
+ String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e);
+ }
+ }
+ }
+
+ @Override
+ public final void writeFixed32NoTag(int value) throws IOException {
+ try {
+ buffer[position++] = (byte) (value & 0xFF);
+ buffer[position++] = (byte) ((value >> 8) & 0xFF);
+ buffer[position++] = (byte) ((value >> 16) & 0xFF);
+ buffer[position++] = (byte) ((value >> 24) & 0xFF);
+ } catch (IndexOutOfBoundsException e) {
+ throw new OutOfSpaceException(
+ String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e);
+ }
+ }
+
+ @Override
+ public final void writeUInt64NoTag(long value) throws IOException {
+ if (HAS_UNSAFE_ARRAY_OPERATIONS && spaceLeft() >= MAX_VARINT_SIZE) {
+ long pos = ARRAY_BASE_OFFSET + position;
+ while (true) {
+ if ((value & ~0x7FL) == 0) {
+ UnsafeUtil.putByte(buffer, pos++, (byte) value);
+ position++;
+ return;
+ } else {
+ UnsafeUtil.putByte(buffer, pos++, (byte) (((int) value & 0x7F) | 0x80));
+ position++;
+ value >>>= 7;
+ }
+ }
+ } else {
+ try {
+ while (true) {
+ if ((value & ~0x7FL) == 0) {
+ buffer[position++] = (byte) value;
+ return;
+ } else {
+ buffer[position++] = (byte) (((int) value & 0x7F) | 0x80);
+ value >>>= 7;
+ }
+ }
+ } catch (IndexOutOfBoundsException e) {
+ throw new OutOfSpaceException(
+ String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e);
+ }
+ }
+ }
+
+ @Override
+ public final void writeFixed64NoTag(long value) throws IOException {
+ try {
+ buffer[position++] = (byte) ((int) (value) & 0xFF);
+ buffer[position++] = (byte) ((int) (value >> 8) & 0xFF);
+ buffer[position++] = (byte) ((int) (value >> 16) & 0xFF);
+ buffer[position++] = (byte) ((int) (value >> 24) & 0xFF);
+ buffer[position++] = (byte) ((int) (value >> 32) & 0xFF);
+ buffer[position++] = (byte) ((int) (value >> 40) & 0xFF);
+ buffer[position++] = (byte) ((int) (value >> 48) & 0xFF);
+ buffer[position++] = (byte) ((int) (value >> 56) & 0xFF);
+ } catch (IndexOutOfBoundsException e) {
+ throw new OutOfSpaceException(
+ String.format("Pos: %d, limit: %d, len: %d", position, limit, 1), e);
+ }
+ }
+
+ @Override
+ public final void write(byte[] value, int offset, int length) throws IOException {
+ try {
+ System.arraycopy(value, offset, buffer, position, length);
+ position += length;
+ } catch (IndexOutOfBoundsException e) {
+ throw new OutOfSpaceException(
+ String.format("Pos: %d, limit: %d, len: %d", position, limit, length), e);
+ }
+ }
+
+ @Override
+ public final void writeLazy(byte[] value, int offset, int length) throws IOException {
+ write(value, offset, length);
+ }
+
+ @Override
+ public final void write(ByteBuffer value) throws IOException {
+ final int length = value.remaining();
+ try {
+ value.get(buffer, position, length);
+ position += length;
+ } catch (IndexOutOfBoundsException e) {
+ throw new OutOfSpaceException(
+ String.format("Pos: %d, limit: %d, len: %d", position, limit, length), e);
+ }
+ }
+
+ @Override
+ public final void writeLazy(ByteBuffer value) throws IOException {
+ write(value);
+ }
+
+ @Override
+ public final void writeStringNoTag(String value) throws IOException {
+ final int oldPosition = 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.
+ final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR;
+ final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength);
+ final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length());
+ if (minLengthVarIntSize == maxLengthVarIntSize) {
+ position = oldPosition + minLengthVarIntSize;
+ int newPosition = Utf8.encode(value, buffer, position, spaceLeft());
+ // Since this class is stateful and tracks the position, we rewind and store the state,
+ // prepend the length, then reset it back to the end of the string.
+ position = oldPosition;
+ int length = newPosition - oldPosition - minLengthVarIntSize;
+ writeUInt32NoTag(length);
+ position = newPosition;
+ } else {
+ int length = Utf8.encodedLength(value);
+ writeUInt32NoTag(length);
+ position = Utf8.encode(value, buffer, position, spaceLeft());
+ }
+ } catch (UnpairedSurrogateException e) {
+ // Roll back the change - we fall back to inefficient path.
+ position = oldPosition;
+
+ // TODO(nathanmittler): We should throw an IOException here instead.
+ inefficientWriteStringNoTag(value, e);
+ } catch (IndexOutOfBoundsException e) {
+ throw new OutOfSpaceException(e);
+ }
+ }
+
+ @Override
+ public void flush() {
+ // Do nothing.
+ }
+
+ @Override
+ public final int spaceLeft() {
+ return limit - position;
+ }
+
+ @Override
+ public final int getTotalBytesWritten() {
+ return position - offset;
+ }
+ }
+
+ /**
+ * 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 HeapNioEncoder extends ArrayEncoder {
+ private final ByteBuffer byteBuffer;
+ private int initialPosition;
+
+ HeapNioEncoder(ByteBuffer byteBuffer) {
+ super(byteBuffer.array(), byteBuffer.arrayOffset() + byteBuffer.position(),
+ byteBuffer.remaining());
+ this.byteBuffer = byteBuffer;
+ this.initialPosition = byteBuffer.position();
+ }
+
+ @Override
+ public void flush() {
+ // Update the position on the buffer.
+ byteBuffer.position(initialPosition + getTotalBytesWritten());
+ }
+ }
+
+ /**
+ * A {@link CodedOutputStream} that writes directly to a direct {@link ByteBuffer}, using only
+ * safe operations..
+ */
+ private static final class SafeDirectNioEncoder extends CodedOutputStream {
+ private final ByteBuffer originalBuffer;
+ private final ByteBuffer buffer;
+ private final int initialPosition;
+
+ SafeDirectNioEncoder(ByteBuffer buffer) {
+ this.originalBuffer = buffer;
+ this.buffer = buffer.duplicate().order(ByteOrder.LITTLE_ENDIAN);
+ initialPosition = buffer.position();
+ }
+
+ @Override
+ public void writeTag(final int fieldNumber, final int wireType) throws IOException {
+ writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType));
+ }
+
+ @Override
+ public void writeInt32(final int fieldNumber, final int value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeInt32NoTag(value);
+ }
+
+ @Override
+ public void writeUInt32(final int fieldNumber, final int value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeUInt32NoTag(value);
+ }
+
+ @Override
+ public void writeFixed32(final int fieldNumber, final int value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
+ writeFixed32NoTag(value);
+ }
+
+ @Override
+ public void writeUInt64(final int fieldNumber, final long value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeUInt64NoTag(value);
+ }
+
+ @Override
+ public void writeFixed64(final int fieldNumber, final long value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
+ writeFixed64NoTag(value);
+ }
+
+ @Override
+ public void writeBool(final int fieldNumber, final boolean value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ write((byte) (value ? 1 : 0));
+ }
+
+ @Override
+ public void writeString(final int fieldNumber, final String value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeStringNoTag(value);
+ }
+
+ @Override
+ public void writeBytes(final int fieldNumber, final ByteString value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeBytesNoTag(value);
+ }
+
+ @Override
+ public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException {
+ writeByteArray(fieldNumber, value, 0, value.length);
+ }
+
+ @Override
+ public void writeByteArray(
+ final int fieldNumber, final byte[] value, final int offset, final int length)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeByteArrayNoTag(value, offset, length);
+ }
+
+ @Override
+ public void writeByteBuffer(final int fieldNumber, final ByteBuffer value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeUInt32NoTag(value.capacity());
+ writeRawBytes(value);
+ }
+
+ @Override
+ public void writeMessage(final int fieldNumber, final MessageLite value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeMessageNoTag(value);
+ }
+
+ @Override
+ public void writeMessageSetExtension(final int fieldNumber, final 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(final int fieldNumber, final 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(final MessageLite value) throws IOException {
+ writeUInt32NoTag(value.getSerializedSize());
+ value.writeTo(this);
+ }
+
+ @Override
+ public void write(byte value) throws IOException {
+ try {
+ buffer.put(value);
+ } catch (BufferOverflowException e) {
+ throw new OutOfSpaceException(e);
+ }
+ }
+
+ @Override
+ public void writeBytesNoTag(final ByteString value) throws IOException {
+ writeUInt32NoTag(value.size());
+ value.writeTo(this);
+ }
+
+ @Override
+ public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException {
+ writeUInt32NoTag(length);
+ write(value, offset, length);
+ }
+
+ @Override
+ public void writeRawBytes(final 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 {
+ try {
+ while (true) {
+ if ((value & ~0x7F) == 0) {
+ buffer.put((byte) value);
+ return;
+ } else {
+ buffer.put((byte) ((value & 0x7F) | 0x80));
+ value >>>= 7;
+ }
+ }
+ } catch (BufferOverflowException e) {
+ throw new OutOfSpaceException(e);
+ }
+ }
+
+ @Override
+ public void writeFixed32NoTag(int value) throws IOException {
+ try {
+ buffer.putInt(value);
+ } catch (BufferOverflowException e) {
+ throw new OutOfSpaceException(e);
+ }
+ }
+
+ @Override
+ public void writeUInt64NoTag(long value) throws IOException {
+ try {
+ while (true) {
+ if ((value & ~0x7FL) == 0) {
+ buffer.put((byte) value);
+ return;
+ } else {
+ buffer.put((byte) (((int) value & 0x7F) | 0x80));
+ value >>>= 7;
+ }
+ }
+ } catch (BufferOverflowException e) {
+ throw new OutOfSpaceException(e);
+ }
+ }
+
+ @Override
+ public void writeFixed64NoTag(long value) throws IOException {
+ try {
+ buffer.putLong(value);
+ } catch (BufferOverflowException e) {
+ throw new OutOfSpaceException(e);
+ }
+ }
+
+ @Override
+ public void write(byte[] value, int offset, int length) throws IOException {
+ try {
+ buffer.put(value, offset, length);
+ } catch (IndexOutOfBoundsException e) {
+ throw new OutOfSpaceException(e);
+ } catch (BufferOverflowException e) {
+ throw new OutOfSpaceException(e);
+ }
+ }
+
+ @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 {
+ buffer.put(value);
+ } 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 {
+ final int startPos = buffer.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.
+ final int maxEncodedSize = value.length() * Utf8.MAX_BYTES_PER_CHAR;
+ final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxEncodedSize);
+ final 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.
+ final int startOfBytes = buffer.position() + minLengthVarIntSize;
+ buffer.position(startOfBytes);
+
+ // Encode the string.
+ encode(value);
+
+ // Now go back to the beginning and write the length.
+ int endOfBytes = buffer.position();
+ buffer.position(startPos);
+ writeUInt32NoTag(endOfBytes - startOfBytes);
+
+ // Reposition the buffer past the written data.
+ buffer.position(endOfBytes);
+ } else {
+ final int length = Utf8.encodedLength(value);
+ writeUInt32NoTag(length);
+ encode(value);
+ }
+ } catch (UnpairedSurrogateException e) {
+ // Roll back the change and convert to an IOException.
+ buffer.position(startPos);
+
+ // 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);
+ }
+ }
+
+ @Override
+ public void flush() {
+ // Update the position of the original buffer.
+ originalBuffer.position(buffer.position());
+ }
+
+ @Override
+ public int spaceLeft() {
+ return buffer.remaining();
+ }
+
+ @Override
+ public int getTotalBytesWritten() {
+ return buffer.position() - initialPosition;
+ }
+
+ private void encode(String value) throws IOException {
+ try {
+ Utf8.encodeUtf8(value, buffer);
+ } catch (IndexOutOfBoundsException e) {
+ throw new OutOfSpaceException(e);
+ }
+ }
+ }
+
+ /**
+ * 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.
+ */
+ private abstract static class AbstractBufferedEncoder extends CodedOutputStream {
+ final byte[] buffer;
+ final int limit;
+ int position;
+ int totalBytesWritten;
+
+ AbstractBufferedEncoder(int bufferSize) {
+ if (bufferSize < 0) {
+ throw new IllegalArgumentException("bufferSize must be >= 0");
+ }
+ // As an optimization, we require that the buffer be able to store at least 2
+ // varints so that we can buffer any integer write (tag + value). This reduces the
+ // number of range checks for a single write to 1 (i.e. if there is not enough space
+ // to buffer the tag+value, flush and then buffer it).
+ this.buffer = new byte[max(bufferSize, MAX_VARINT_SIZE * 2)];
+ this.limit = buffer.length;
+ }
+
+ @Override
+ public final int spaceLeft() {
+ throw new UnsupportedOperationException(
+ "spaceLeft() can only be called on CodedOutputStreams that are "
+ + "writing to a flat array or ByteBuffer.");
+ }
+
+ @Override
+ public final int getTotalBytesWritten() {
+ return totalBytesWritten;
+ }
+
+ /**
+ * This method does not perform bounds checking on the array. Checking array bounds is the
+ * responsibility of the caller.
+ */
+ final void buffer(byte value) {
+ buffer[position++] = value;
+ totalBytesWritten++;
+ }
+
+ /**
+ * This method does not perform bounds checking on the array. Checking array bounds is the
+ * responsibility of the caller.
+ */
+ final void bufferTag(final int fieldNumber, final int wireType) {
+ bufferUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType));
+ }
+
+ /**
+ * This method does not perform bounds checking on the array. Checking array bounds is the
+ * responsibility of the caller.
+ */
+ final void bufferInt32NoTag(final int value) {
+ if (value >= 0) {
+ bufferUInt32NoTag(value);
+ } else {
+ // Must sign-extend.
+ bufferUInt64NoTag(value);
+ }
+ }
+
+ /**
+ * This method does not perform bounds checking on the array. Checking array bounds is the
+ * responsibility of the caller.
+ */
+ final void bufferUInt32NoTag(int value) {
+ if (HAS_UNSAFE_ARRAY_OPERATIONS) {
+ final long originalPos = ARRAY_BASE_OFFSET + position;
+ long pos = originalPos;
+ while (true) {
+ if ((value & ~0x7F) == 0) {
+ UnsafeUtil.putByte(buffer, pos++, (byte) value);
+ break;
+ } else {
+ UnsafeUtil.putByte(buffer, pos++, (byte) ((value & 0x7F) | 0x80));
+ value >>>= 7;
+ }
+ }
+ int delta = (int) (pos - originalPos);
+ position += delta;
+ totalBytesWritten += delta;
+ } else {
+ while (true) {
+ if ((value & ~0x7F) == 0) {
+ buffer[position++] = (byte) value;
+ totalBytesWritten++;
+ return;
+ } else {
+ buffer[position++] = (byte) ((value & 0x7F) | 0x80);
+ totalBytesWritten++;
+ value >>>= 7;
+ }
+ }
+ }
+ }
+
+ /**
+ * This method does not perform bounds checking on the array. Checking array bounds is the
+ * responsibility of the caller.
+ */
+ final void bufferUInt64NoTag(long value) {
+ if (HAS_UNSAFE_ARRAY_OPERATIONS) {
+ final long originalPos = ARRAY_BASE_OFFSET + position;
+ long pos = originalPos;
+ while (true) {
+ if ((value & ~0x7FL) == 0) {
+ UnsafeUtil.putByte(buffer, pos++, (byte) value);
+ break;
+ } else {
+ UnsafeUtil.putByte(buffer, pos++, (byte) (((int) value & 0x7F) | 0x80));
+ value >>>= 7;
+ }
+ }
+ int delta = (int) (pos - originalPos);
+ position += delta;
+ totalBytesWritten += delta;
+ } else {
+ while (true) {
+ if ((value & ~0x7FL) == 0) {
+ buffer[position++] = (byte) value;
+ totalBytesWritten++;
+ return;
+ } else {
+ buffer[position++] = (byte) (((int) value & 0x7F) | 0x80);
+ totalBytesWritten++;
+ value >>>= 7;
+ }
+ }
+ }
+ }
+
+ /**
+ * This method does not perform bounds checking on the array. Checking array bounds is the
+ * responsibility of the caller.
+ */
+ final void bufferFixed32NoTag(int value) {
+ buffer[position++] = (byte) (value & 0xFF);
+ buffer[position++] = (byte) ((value >> 8) & 0xFF);
+ buffer[position++] = (byte) ((value >> 16) & 0xFF);
+ buffer[position++] = (byte) ((value >> 24) & 0xFF);
+ totalBytesWritten += FIXED_32_SIZE;
+ }
+
+ /**
+ * This method does not perform bounds checking on the array. Checking array bounds is the
+ * responsibility of the caller.
+ */
+ final void bufferFixed64NoTag(long value) {
+ buffer[position++] = (byte) (value & 0xFF);
+ buffer[position++] = (byte) ((value >> 8) & 0xFF);
+ buffer[position++] = (byte) ((value >> 16) & 0xFF);
+ buffer[position++] = (byte) ((value >> 24) & 0xFF);
+ buffer[position++] = (byte) ((int) (value >> 32) & 0xFF);
+ buffer[position++] = (byte) ((int) (value >> 40) & 0xFF);
+ buffer[position++] = (byte) ((int) (value >> 48) & 0xFF);
+ buffer[position++] = (byte) ((int) (value >> 56) & 0xFF);
+ totalBytesWritten += FIXED_64_SIZE;
+ }
+ }
+
+ /**
+ * A {@link CodedOutputStream} that decorates a {@link ByteOutput}. It internal buffer only to
+ * support string encoding operations. All other writes are just passed through to the
+ * {@link ByteOutput}.
+ */
+ private static final class ByteOutputEncoder extends AbstractBufferedEncoder {
+ private final ByteOutput out;
+
+ ByteOutputEncoder(ByteOutput out, int bufferSize) {
+ super(bufferSize);
+ if (out == null) {
+ throw new NullPointerException("out");
+ }
+ this.out = out;
+ }
+
+ @Override
+ public void writeTag(final int fieldNumber, final int wireType) throws IOException {
+ writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType));
+ }
+
+ @Override
+ public void writeInt32(final int fieldNumber, final int value) throws IOException {
+ flushIfNotAvailable(MAX_VARINT_SIZE * 2);
+ bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ bufferInt32NoTag(value);
+ }
+
+ @Override
+ public void writeUInt32(final int fieldNumber, final int value) throws IOException {
+ flushIfNotAvailable(MAX_VARINT_SIZE * 2);
+ bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ bufferUInt32NoTag(value);
+ }
+
+ @Override
+ public void writeFixed32(final int fieldNumber, final int value) throws IOException {
+ flushIfNotAvailable(MAX_VARINT_SIZE + FIXED_32_SIZE);
+ bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
+ bufferFixed32NoTag(value);
+ }
+
+ @Override
+ public void writeUInt64(final int fieldNumber, final long value) throws IOException {
+ flushIfNotAvailable(MAX_VARINT_SIZE * 2);
+ bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ bufferUInt64NoTag(value);
+ }
+
+ @Override
+ public void writeFixed64(final int fieldNumber, final long value) throws IOException {
+ flushIfNotAvailable(MAX_VARINT_SIZE + FIXED_64_SIZE);
+ bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
+ bufferFixed64NoTag(value);
+ }
+
+ @Override
+ public void writeBool(final int fieldNumber, final boolean value) throws IOException {
+ flushIfNotAvailable(MAX_VARINT_SIZE + 1);
+ bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ buffer((byte) (value ? 1 : 0));
+ }
+
+ @Override
+ public void writeString(final int fieldNumber, final String value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeStringNoTag(value);
+ }
+
+ @Override
+ public void writeBytes(final int fieldNumber, final ByteString value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeBytesNoTag(value);
+ }
+
+ @Override
+ public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException {
+ writeByteArray(fieldNumber, value, 0, value.length);
+ }
+
+ @Override
+ public void writeByteArray(
+ final int fieldNumber, final byte[] value, final int offset, final int length)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeByteArrayNoTag(value, offset, length);
+ }
+
+ @Override
+ public void writeByteBuffer(final int fieldNumber, final ByteBuffer value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeUInt32NoTag(value.capacity());
+ writeRawBytes(value);
+ }
+
+ @Override
+ public void writeBytesNoTag(final ByteString value) throws IOException {
+ writeUInt32NoTag(value.size());
+ value.writeTo(this);
+ }
+
+ @Override
+ public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException {
+ writeUInt32NoTag(length);
+ write(value, offset, length);
+ }
+
+ @Override
+ public void writeRawBytes(final 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 writeMessage(final int fieldNumber, final MessageLite value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeMessageNoTag(value);
+ }
+
+ @Override
+ public void writeMessageSetExtension(final int fieldNumber, final 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(final int fieldNumber, final 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(final MessageLite value) throws IOException {
+ writeUInt32NoTag(value.getSerializedSize());
+ value.writeTo(this);
+ }
+
+ @Override
+ public void write(byte value) throws IOException {
+ if (position == limit) {
+ doFlush();
+ }
+
+ buffer(value);
+ }
+
+ @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 {
+ flushIfNotAvailable(MAX_VARINT_SIZE);
+ bufferUInt32NoTag(value);
+ }
+
+ @Override
+ public void writeFixed32NoTag(final int value) throws IOException {
+ flushIfNotAvailable(FIXED_32_SIZE);
+ bufferFixed32NoTag(value);
+ }
+
+ @Override
+ public void writeUInt64NoTag(long value) throws IOException {
+ flushIfNotAvailable(MAX_VARINT_SIZE);
+ bufferUInt64NoTag(value);
+ }
+
+ @Override
+ public void writeFixed64NoTag(final long value) throws IOException {
+ flushIfNotAvailable(FIXED_64_SIZE);
+ bufferFixed64NoTag(value);
+ }
+
+ @Override
+ public void writeStringNoTag(String value) throws IOException {
+ // 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.
+ final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR;
+ final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength);
+
+ // If we are streaming and the potential length is too big to fit in our buffer, we take the
+ // slower path.
+ if (maxLengthVarIntSize + maxLength > limit) {
+ // Allocate a byte[] that we know can fit the string and encode into it. String.getBytes()
+ // does the same internally and then does *another copy* to return a byte[] of exactly the
+ // right size. We can skip that copy and just writeRawBytes up to the actualLength of the
+ // UTF-8 encoded bytes.
+ final byte[] encodedBytes = new byte[maxLength];
+ int actualLength = Utf8.encode(value, encodedBytes, 0, maxLength);
+ writeUInt32NoTag(actualLength);
+ writeLazy(encodedBytes, 0, actualLength);
+ return;
+ }
+
+ // Fast path: we have enough space available in our buffer for the string...
+ if (maxLengthVarIntSize + maxLength > limit - position) {
+ // Flush to free up space.
+ doFlush();
+ }
+
+ final int oldPosition = position;
+ try {
+ // Optimize for the case where we know this length results in a constant varint length as
+ // this saves a pass for measuring the length of the string.
+ final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length());
+
+ if (minLengthVarIntSize == maxLengthVarIntSize) {
+ position = oldPosition + minLengthVarIntSize;
+ int newPosition = Utf8.encode(value, buffer, position, limit - position);
+ // Since this class is stateful and tracks the position, we rewind and store the state,
+ // prepend the length, then reset it back to the end of the string.
+ position = oldPosition;
+ int length = newPosition - oldPosition - minLengthVarIntSize;
+ bufferUInt32NoTag(length);
+ position = newPosition;
+ totalBytesWritten += length;
+ } else {
+ int length = Utf8.encodedLength(value);
+ bufferUInt32NoTag(length);
+ position = Utf8.encode(value, buffer, position, length);
+ totalBytesWritten += length;
+ }
+ } catch (UnpairedSurrogateException e) {
+ // Roll back the change and convert to an IOException.
+ totalBytesWritten -= position - oldPosition;
+ position = oldPosition;
+
+ // TODO(nathanmittler): We should throw an IOException here instead.
+ inefficientWriteStringNoTag(value, e);
+ } catch (IndexOutOfBoundsException e) {
+ throw new OutOfSpaceException(e);
+ }
+ }
+
+ @Override
+ public void flush() throws IOException {
+ if (position > 0) {
+ // Flush the buffer.
+ doFlush();
+ }
+ }
+
+ @Override
+ public void write(byte[] value, int offset, int length) throws IOException {
+ flush();
+ out.write(value, offset, length);
+ totalBytesWritten += length;
+ }
+
+ @Override
+ public void writeLazy(byte[] value, int offset, int length) throws IOException {
+ flush();
+ out.writeLazy(value, offset, length);
+ totalBytesWritten += length;
+ }
+
+ @Override
+ public void write(ByteBuffer value) throws IOException {
+ flush();
+ int length = value.remaining();
+ out.write(value);
+ totalBytesWritten += length;
+ }
+
+ @Override
+ public void writeLazy(ByteBuffer value) throws IOException {
+ flush();
+ int length = value.remaining();
+ out.writeLazy(value);
+ totalBytesWritten += length;
+ }
+
+ private void flushIfNotAvailable(int requiredSize) throws IOException {
+ if (limit - position < requiredSize) {
+ doFlush();
+ }
+ }
+
+ private void doFlush() throws IOException {
+ out.write(buffer, 0, position);
+ position = 0;
+ }
+ }
+
+ /**
+ * An {@link CodedOutputStream} that decorates an {@link OutputStream}. It performs internal
+ * buffering to optimize writes to the {@link OutputStream}.
+ */
+ private static final class OutputStreamEncoder extends AbstractBufferedEncoder {
+ private final OutputStream out;
+
+ OutputStreamEncoder(OutputStream out, int bufferSize) {
+ super(bufferSize);
+ if (out == null) {
+ throw new NullPointerException("out");
+ }
+ this.out = out;
+ }
+
+ @Override
+ public void writeTag(final int fieldNumber, final int wireType) throws IOException {
+ writeUInt32NoTag(WireFormat.makeTag(fieldNumber, wireType));
+ }
+
+ @Override
+ public void writeInt32(final int fieldNumber, final int value) throws IOException {
+ flushIfNotAvailable(MAX_VARINT_SIZE * 2);
+ bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ bufferInt32NoTag(value);
+ }
+
+ @Override
+ public void writeUInt32(final int fieldNumber, final int value) throws IOException {
+ flushIfNotAvailable(MAX_VARINT_SIZE * 2);
+ bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ bufferUInt32NoTag(value);
+ }
+
+ @Override
+ public void writeFixed32(final int fieldNumber, final int value) throws IOException {
+ flushIfNotAvailable(MAX_VARINT_SIZE + FIXED_32_SIZE);
+ bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
+ bufferFixed32NoTag(value);
+ }
+
+ @Override
+ public void writeUInt64(final int fieldNumber, final long value) throws IOException {
+ flushIfNotAvailable(MAX_VARINT_SIZE * 2);
+ bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ bufferUInt64NoTag(value);
+ }
+
+ @Override
+ public void writeFixed64(final int fieldNumber, final long value) throws IOException {
+ flushIfNotAvailable(MAX_VARINT_SIZE + FIXED_64_SIZE);
+ bufferTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
+ bufferFixed64NoTag(value);
+ }
+
+ @Override
+ public void writeBool(final int fieldNumber, final boolean value) throws IOException {
+ flushIfNotAvailable(MAX_VARINT_SIZE + 1);
+ bufferTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ buffer((byte) (value ? 1 : 0));
+ }
+
+ @Override
+ public void writeString(final int fieldNumber, final String value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeStringNoTag(value);
+ }
+
+ @Override
+ public void writeBytes(final int fieldNumber, final ByteString value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeBytesNoTag(value);
+ }
+
+ @Override
+ public void writeByteArray(final int fieldNumber, final byte[] value) throws IOException {
+ writeByteArray(fieldNumber, value, 0, value.length);
+ }
+
+ @Override
+ public void writeByteArray(
+ final int fieldNumber, final byte[] value, final int offset, final int length)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeByteArrayNoTag(value, offset, length);
+ }
+
+ @Override
+ public void writeByteBuffer(final int fieldNumber, final ByteBuffer value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeUInt32NoTag(value.capacity());
+ writeRawBytes(value);
+ }
+
+ @Override
+ public void writeBytesNoTag(final ByteString value) throws IOException {
+ writeUInt32NoTag(value.size());
+ value.writeTo(this);
+ }
+
+ @Override
+ public void writeByteArrayNoTag(final byte[] value, int offset, int length) throws IOException {
+ writeUInt32NoTag(length);
+ write(value, offset, length);
+ }
+
+ @Override
+ public void writeRawBytes(final 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 writeMessage(final int fieldNumber, final MessageLite value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeMessageNoTag(value);
+ }
+
+ @Override
+ public void writeMessageSetExtension(final int fieldNumber, final 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(final int fieldNumber, final 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(final MessageLite value) throws IOException {
+ writeUInt32NoTag(value.getSerializedSize());
+ value.writeTo(this);
+ }
+
+ @Override
+ public void write(byte value) throws IOException {
+ if (position == limit) {
+ doFlush();
+ }
+
+ buffer(value);
+ }
+
+ @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 {
+ flushIfNotAvailable(MAX_VARINT_SIZE);
+ bufferUInt32NoTag(value);
+ }
+
+ @Override
+ public void writeFixed32NoTag(final int value) throws IOException {
+ flushIfNotAvailable(FIXED_32_SIZE);
+ bufferFixed32NoTag(value);
+ }
+
+ @Override
+ public void writeUInt64NoTag(long value) throws IOException {
+ flushIfNotAvailable(MAX_VARINT_SIZE);
+ bufferUInt64NoTag(value);
+ }
+
+ @Override
+ public void writeFixed64NoTag(final long value) throws IOException {
+ flushIfNotAvailable(FIXED_64_SIZE);
+ bufferFixed64NoTag(value);
+ }
+
+ @Override
+ public void writeStringNoTag(String value) throws IOException {
+ 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.
+ final int maxLength = value.length() * Utf8.MAX_BYTES_PER_CHAR;
+ final int maxLengthVarIntSize = computeUInt32SizeNoTag(maxLength);
+
+ // If we are streaming and the potential length is too big to fit in our buffer, we take the
+ // slower path.
+ if (maxLengthVarIntSize + maxLength > limit) {
+ // Allocate a byte[] that we know can fit the string and encode into it. String.getBytes()
+ // does the same internally and then does *another copy* to return a byte[] of exactly the
+ // right size. We can skip that copy and just writeRawBytes up to the actualLength of the
+ // UTF-8 encoded bytes.
+ final byte[] encodedBytes = new byte[maxLength];
+ int actualLength = Utf8.encode(value, encodedBytes, 0, maxLength);
+ writeUInt32NoTag(actualLength);
+ writeLazy(encodedBytes, 0, actualLength);
+ return;
+ }
+
+ // Fast path: we have enough space available in our buffer for the string...
+ if (maxLengthVarIntSize + maxLength > limit - position) {
+ // Flush to free up space.
+ doFlush();
+ }
+
+ // Optimize for the case where we know this length results in a constant varint length as
+ // this saves a pass for measuring the length of the string.
+ final int minLengthVarIntSize = computeUInt32SizeNoTag(value.length());
+ int oldPosition = position;
+ final int length;
+ try {
+ if (minLengthVarIntSize == maxLengthVarIntSize) {
+ position = oldPosition + minLengthVarIntSize;
+ int newPosition = Utf8.encode(value, buffer, position, limit - position);
+ // Since this class is stateful and tracks the position, we rewind and store the
+ // state, prepend the length, then reset it back to the end of the string.
+ position = oldPosition;
+ length = newPosition - oldPosition - minLengthVarIntSize;
+ bufferUInt32NoTag(length);
+ position = newPosition;
+ } else {
+ length = Utf8.encodedLength(value);
+ bufferUInt32NoTag(length);
+ position = Utf8.encode(value, buffer, position, length);
+ }
+ totalBytesWritten += length;
+ } catch (UnpairedSurrogateException e) {
+ // Be extra careful and restore the original position for retrying the write with the
+ // less efficient path.
+ totalBytesWritten -= position - oldPosition;
+ position = oldPosition;
+ throw e;
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw new OutOfSpaceException(e);
+ }
+ } catch (UnpairedSurrogateException e) {
+ inefficientWriteStringNoTag(value, e);
+ }
+ }
+
+ @Override
+ public void flush() throws IOException {
+ if (position > 0) {
+ // Flush the buffer.
+ doFlush();
+ }
+ }
+
+ @Override
+ public void write(byte[] value, int offset, int length)
+ throws IOException {
+ if (limit - position >= length) {
+ // We have room in the current buffer.
+ System.arraycopy(value, offset, buffer, position, length);
+ position += length;
+ totalBytesWritten += length;
+ } else {
+ // Write extends past current buffer. Fill the rest of this buffer and
+ // flush.
+ final int bytesWritten = limit - position;
+ System.arraycopy(value, offset, buffer, position, bytesWritten);
+ offset += bytesWritten;
+ length -= bytesWritten;
+ position = limit;
+ totalBytesWritten += bytesWritten;
+ doFlush();
+
+ // Now deal with the rest.
+ // Since we have an output stream, this is our buffer
+ // and buffer offset == 0
+ if (length <= limit) {
+ // Fits in new buffer.
+ System.arraycopy(value, offset, buffer, 0, length);
+ position = length;
+ } else {
+ // Write is very big. Let's do it all at once.
+ out.write(value, offset, length);
+ }
+ totalBytesWritten += 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 {
+ int length = value.remaining();
+ if (limit - position >= length) {
+ // We have room in the current buffer.
+ value.get(buffer, position, length);
+ position += length;
+ totalBytesWritten += length;
+ } else {
+ // Write extends past current buffer. Fill the rest of this buffer and
+ // flush.
+ final int bytesWritten = limit - position;
+ value.get(buffer, position, bytesWritten);
+ length -= bytesWritten;
+ position = limit;
+ totalBytesWritten += bytesWritten;
+ doFlush();
+
+ // Now deal with the rest.
+ // Since we have an output stream, this is our buffer
+ // and buffer offset == 0
+ while (length > limit) {
+ // Copy data into the buffer before writing it to OutputStream.
+ value.get(buffer, 0, limit);
+ out.write(buffer, 0, limit);
+ length -= limit;
+ totalBytesWritten += limit;
+ }
+ value.get(buffer, 0, length);
+ position = length;
+ totalBytesWritten += length;
+ }
+ }
+
+ @Override
+ public void writeLazy(ByteBuffer value) throws IOException {
+ write(value);
+ }
+
+ private void flushIfNotAvailable(int requiredSize) throws IOException {
+ if (limit - position < requiredSize) {
+ doFlush();
+ }
+ }
+
+ private void doFlush() throws IOException {
+ out.write(buffer, 0, position);
+ position = 0;
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java
new file mode 100644
index 0000000000..38346f1559
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Descriptors.java
@@ -0,0 +1,2547 @@
+// 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.DescriptorProtos.*;
+import com.google.protobuf.Descriptors.FileDescriptor.Syntax;
+
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.logging.Logger;
+
+/**
+ * Contains a collection of classes which describe protocol message types.
+ *
+ * Every message type has a {@link Descriptor}, which lists all
+ * its fields and other information about a type. You can get a message
+ * type's descriptor by calling {@code MessageType.getDescriptor()}, or
+ * (given a message object of the type) {@code message.getDescriptorForType()}.
+ * Furthermore, each message is associated with a {@link FileDescriptor} for
+ * a relevant {@code .proto} file. You can obtain it by calling
+ * {@code Descriptor.getFile()}. A {@link FileDescriptor} contains descriptors
+ * for all the messages defined in that file, and file descriptors for all the
+ * imported {@code .proto} files.
+ *
+ * Descriptors are built from DescriptorProtos, as defined in
+ * {@code google/protobuf/descriptor.proto}.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public final class Descriptors {
+ private static final Logger logger =
+ Logger.getLogger(Descriptors.class.getName());
+ /**
+ * Describes a {@code .proto} file, including everything defined within.
+ * That includes, in particular, descriptors for all the messages and
+ * file descriptors for all other imported {@code .proto} files
+ * (dependencies).
+ */
+ public static final class FileDescriptor extends GenericDescriptor {
+ /** Convert the descriptor to its protocol message representation. */
+ @Override
+ public FileDescriptorProto toProto() {
+ return proto;
+ }
+
+ /** Get the file name. */
+ @Override
+ public String getName() {
+ return proto.getName();
+ }
+
+ /** Returns this object. */
+ @Override
+ public FileDescriptor getFile() {
+ return this;
+ }
+
+ /** Returns the same as getName(). */
+ @Override
+ public String getFullName() {
+ return proto.getName();
+ }
+
+ /**
+ * Get the proto package name. This is the package name given by the
+ * {@code package} statement in the {@code .proto} file, which differs
+ * from the Java package.
+ */
+ public String getPackage() { return proto.getPackage(); }
+
+ /** Get the {@code FileOptions}, defined in {@code descriptor.proto}. */
+ public FileOptions getOptions() { return proto.getOptions(); }
+
+ /** Get a list of top-level message types declared in this file. */
+ public List<Descriptor> getMessageTypes() {
+ return Collections.unmodifiableList(Arrays.asList(messageTypes));
+ }
+
+ /** Get a list of top-level enum types declared in this file. */
+ public List<EnumDescriptor> getEnumTypes() {
+ return Collections.unmodifiableList(Arrays.asList(enumTypes));
+ }
+
+ /** Get a list of top-level services declared in this file. */
+ public List<ServiceDescriptor> getServices() {
+ return Collections.unmodifiableList(Arrays.asList(services));
+ }
+
+ /** Get a list of top-level extensions declared in this file. */
+ public List<FieldDescriptor> getExtensions() {
+ return Collections.unmodifiableList(Arrays.asList(extensions));
+ }
+
+ /** Get a list of this file's dependencies (imports). */
+ public List<FileDescriptor> getDependencies() {
+ return Collections.unmodifiableList(Arrays.asList(dependencies));
+ }
+
+ /** Get a list of this file's public dependencies (public imports). */
+ public List<FileDescriptor> getPublicDependencies() {
+ return Collections.unmodifiableList(Arrays.asList(publicDependencies));
+ }
+
+ /** The syntax of the .proto file. */
+ public enum Syntax {
+ UNKNOWN("unknown"),
+ PROTO2("proto2"),
+ PROTO3("proto3");
+
+ Syntax(String name) {
+ this.name = name;
+ }
+ private final String name;
+ }
+
+ /** Get the syntax of the .proto file. */
+ public Syntax getSyntax() {
+ if (Syntax.PROTO3.name.equals(proto.getSyntax())) {
+ return Syntax.PROTO3;
+ }
+ return Syntax.PROTO2;
+ }
+
+ /**
+ * Find a message type in the file by name. Does not find nested types.
+ *
+ * @param name The unqualified type name to look for.
+ * @return The message type's descriptor, or {@code null} if not found.
+ */
+ public Descriptor findMessageTypeByName(String name) {
+ // Don't allow looking up nested types. This will make optimization
+ // easier later.
+ if (name.indexOf('.') != -1) {
+ return null;
+ }
+ if (getPackage().length() > 0) {
+ name = getPackage() + '.' + name;
+ }
+ final GenericDescriptor result = pool.findSymbol(name);
+ if (result != null && result instanceof Descriptor &&
+ result.getFile() == this) {
+ return (Descriptor)result;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Find an enum type in the file by name. Does not find nested types.
+ *
+ * @param name The unqualified type name to look for.
+ * @return The enum type's descriptor, or {@code null} if not found.
+ */
+ public EnumDescriptor findEnumTypeByName(String name) {
+ // Don't allow looking up nested types. This will make optimization
+ // easier later.
+ if (name.indexOf('.') != -1) {
+ return null;
+ }
+ if (getPackage().length() > 0) {
+ name = getPackage() + '.' + name;
+ }
+ final GenericDescriptor result = pool.findSymbol(name);
+ if (result != null && result instanceof EnumDescriptor &&
+ result.getFile() == this) {
+ return (EnumDescriptor)result;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Find a service type in the file by name.
+ *
+ * @param name The unqualified type name to look for.
+ * @return The service type's descriptor, or {@code null} if not found.
+ */
+ public ServiceDescriptor findServiceByName(String name) {
+ // Don't allow looking up nested types. This will make optimization
+ // easier later.
+ if (name.indexOf('.') != -1) {
+ return null;
+ }
+ if (getPackage().length() > 0) {
+ name = getPackage() + '.' + name;
+ }
+ final GenericDescriptor result = pool.findSymbol(name);
+ if (result != null && result instanceof ServiceDescriptor &&
+ result.getFile() == this) {
+ return (ServiceDescriptor)result;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Find an extension in the file by name. Does not find extensions nested
+ * inside message types.
+ *
+ * @param name The unqualified extension name to look for.
+ * @return The extension's descriptor, or {@code null} if not found.
+ */
+ public FieldDescriptor findExtensionByName(String name) {
+ if (name.indexOf('.') != -1) {
+ return null;
+ }
+ if (getPackage().length() > 0) {
+ name = getPackage() + '.' + name;
+ }
+ final GenericDescriptor result = pool.findSymbol(name);
+ if (result != null && result instanceof FieldDescriptor &&
+ result.getFile() == this) {
+ return (FieldDescriptor)result;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Construct a {@code FileDescriptor}.
+ *
+ * @param proto The protocol message form of the FileDescriptor.
+ * @param dependencies {@code FileDescriptor}s corresponding to all of
+ * the file's dependencies.
+ * @throws DescriptorValidationException {@code proto} is not a valid
+ * descriptor. This can occur for a number of reasons, e.g.
+ * because a field has an undefined type or because two messages
+ * were defined with the same name.
+ */
+ public static FileDescriptor buildFrom(final FileDescriptorProto proto,
+ final FileDescriptor[] dependencies)
+ throws DescriptorValidationException {
+ return buildFrom(proto, dependencies, false);
+ }
+
+
+ /**
+ * Construct a {@code FileDescriptor}.
+ *
+ * @param proto The protocol message form of the FileDescriptor.
+ * @param dependencies {@code FileDescriptor}s corresponding to all of
+ * the file's dependencies.
+ * @param allowUnknownDependencies If true, non-exist dependenncies will be
+ * ignored and undefined message types will be replaced with a
+ * placeholder type.
+ * @throws DescriptorValidationException {@code proto} is not a valid
+ * descriptor. This can occur for a number of reasons, e.g.
+ * because a field has an undefined type or because two messages
+ * were defined with the same name.
+ */
+ public static FileDescriptor buildFrom(
+ final FileDescriptorProto proto, final FileDescriptor[] dependencies,
+ final boolean allowUnknownDependencies)
+ throws DescriptorValidationException {
+ // Building descriptors involves two steps: translating and linking.
+ // In the translation step (implemented by FileDescriptor's
+ // constructor), we build an object tree mirroring the
+ // FileDescriptorProto's tree and put all of the descriptors into the
+ // DescriptorPool's lookup tables. In the linking step, we look up all
+ // type references in the DescriptorPool, so that, for example, a
+ // FieldDescriptor for an embedded message contains a pointer directly
+ // to the Descriptor for that message's type. We also detect undefined
+ // types in the linking step.
+ final DescriptorPool pool = new DescriptorPool(
+ dependencies, allowUnknownDependencies);
+ final FileDescriptor result = new FileDescriptor(
+ proto, dependencies, pool, allowUnknownDependencies);
+ result.crossLink();
+ return result;
+ }
+
+ /**
+ * This method is to be called by generated code only. It is equivalent
+ * to {@code buildFrom} except that the {@code FileDescriptorProto} is
+ * encoded in protocol buffer wire format.
+ */
+ public static void internalBuildGeneratedFileFrom(
+ final String[] descriptorDataParts,
+ final FileDescriptor[] dependencies,
+ final InternalDescriptorAssigner descriptorAssigner) {
+ // Hack: We can't embed a raw byte array inside generated Java code
+ // (at least, not efficiently), but we can embed Strings. So, the
+ // protocol compiler embeds the FileDescriptorProto as a giant
+ // string literal which is passed to this function to construct the
+ // file's FileDescriptor. The string literal contains only 8-bit
+ // characters, each one representing a byte of the FileDescriptorProto's
+ // serialized form. So, if we convert it to bytes in ISO-8859-1, we
+ // should get the original bytes that we want.
+
+ // descriptorData may contain multiple strings in order to get around the
+ // Java 64k string literal limit.
+ StringBuilder descriptorData = new StringBuilder();
+ for (String part : descriptorDataParts) {
+ descriptorData.append(part);
+ }
+
+ final byte[] descriptorBytes;
+ descriptorBytes = descriptorData.toString().getBytes(Internal.ISO_8859_1);
+
+ FileDescriptorProto proto;
+ try {
+ proto = FileDescriptorProto.parseFrom(descriptorBytes);
+ } catch (InvalidProtocolBufferException e) {
+ throw new IllegalArgumentException(
+ "Failed to parse protocol buffer descriptor for generated code.", e);
+ }
+
+ final FileDescriptor result;
+ try {
+ // When building descriptors for generated code, we allow unknown
+ // dependencies by default.
+ result = buildFrom(proto, dependencies, true);
+ } catch (DescriptorValidationException e) {
+ throw new IllegalArgumentException(
+ "Invalid embedded descriptor for \"" + proto.getName() + "\".", e);
+ }
+
+ final ExtensionRegistry registry =
+ descriptorAssigner.assignDescriptors(result);
+
+ if (registry != null) {
+ // We must re-parse the proto using the registry.
+ try {
+ proto = FileDescriptorProto.parseFrom(descriptorBytes, registry);
+ } catch (InvalidProtocolBufferException e) {
+ throw new IllegalArgumentException(
+ "Failed to parse protocol buffer descriptor for generated code.",
+ e);
+ }
+
+ result.setProto(proto);
+ }
+ }
+
+ /**
+ * This method is to be called by generated code only. It uses Java
+ * reflection to load the dependencies' descriptors.
+ */
+ public static void internalBuildGeneratedFileFrom(
+ final String[] descriptorDataParts,
+ final Class<?> descriptorOuterClass,
+ final String[] dependencies,
+ final String[] dependencyFileNames,
+ final InternalDescriptorAssigner descriptorAssigner) {
+ List<FileDescriptor> descriptors = new ArrayList<FileDescriptor>();
+ for (int i = 0; i < dependencies.length; i++) {
+ try {
+ Class<?> clazz =
+ descriptorOuterClass.getClassLoader().loadClass(dependencies[i]);
+ descriptors.add(
+ (FileDescriptor) clazz.getField("descriptor").get(null));
+ } catch (Exception e) {
+ // We allow unknown dependencies by default. If a dependency cannot
+ // be found we only generate a warning.
+ logger.warning("Descriptors for \"" + dependencyFileNames[i] +
+ "\" can not be found.");
+ }
+ }
+ FileDescriptor[] descriptorArray = new FileDescriptor[descriptors.size()];
+ descriptors.toArray(descriptorArray);
+ internalBuildGeneratedFileFrom(
+ descriptorDataParts, descriptorArray, descriptorAssigner);
+ }
+
+ /**
+ * This method is to be called by generated code only. It is used to
+ * update the FileDescriptorProto associated with the descriptor by
+ * parsing it again with the given ExtensionRegistry. This is needed to
+ * recognize custom options.
+ */
+ public static void internalUpdateFileDescriptor(
+ final FileDescriptor descriptor,
+ final ExtensionRegistry registry) {
+ ByteString bytes = descriptor.proto.toByteString();
+ FileDescriptorProto proto;
+ try {
+ proto = FileDescriptorProto.parseFrom(bytes, registry);
+ } catch (InvalidProtocolBufferException e) {
+ throw new IllegalArgumentException(
+ "Failed to parse protocol buffer descriptor for generated code.", e);
+ }
+ descriptor.setProto(proto);
+ }
+
+ /**
+ * This class should be used by generated code only. When calling
+ * {@link FileDescriptor#internalBuildGeneratedFileFrom}, the caller
+ * provides a callback implementing this interface. The callback is called
+ * after the FileDescriptor has been constructed, in order to assign all
+ * the global variables defined in the generated code which point at parts
+ * of the FileDescriptor. The callback returns an ExtensionRegistry which
+ * contains any extensions which might be used in the descriptor -- that
+ * is, extensions of the various "Options" messages defined in
+ * descriptor.proto. The callback may also return null to indicate that
+ * no extensions are used in the descriptor.
+ */
+ public interface InternalDescriptorAssigner {
+ ExtensionRegistry assignDescriptors(FileDescriptor root);
+ }
+
+ private FileDescriptorProto proto;
+ private final Descriptor[] messageTypes;
+ private final EnumDescriptor[] enumTypes;
+ private final ServiceDescriptor[] services;
+ private final FieldDescriptor[] extensions;
+ private final FileDescriptor[] dependencies;
+ private final FileDescriptor[] publicDependencies;
+ private final DescriptorPool pool;
+
+ private FileDescriptor(final FileDescriptorProto proto,
+ final FileDescriptor[] dependencies,
+ final DescriptorPool pool,
+ boolean allowUnknownDependencies)
+ throws DescriptorValidationException {
+ this.pool = pool;
+ this.proto = proto;
+ this.dependencies = dependencies.clone();
+ HashMap<String, FileDescriptor> nameToFileMap =
+ new HashMap<String, FileDescriptor>();
+ for (FileDescriptor file : dependencies) {
+ nameToFileMap.put(file.getName(), file);
+ }
+ List<FileDescriptor> publicDependencies = new ArrayList<FileDescriptor>();
+ for (int i = 0; i < proto.getPublicDependencyCount(); i++) {
+ int index = proto.getPublicDependency(i);
+ if (index < 0 || index >= proto.getDependencyCount()) {
+ throw new DescriptorValidationException(this,
+ "Invalid public dependency index.");
+ }
+ String name = proto.getDependency(index);
+ FileDescriptor file = nameToFileMap.get(name);
+ if (file == null) {
+ if (!allowUnknownDependencies) {
+ throw new DescriptorValidationException(this,
+ "Invalid public dependency: " + name);
+ }
+ // Ignore unknown dependencies.
+ } else {
+ publicDependencies.add(file);
+ }
+ }
+ this.publicDependencies = new FileDescriptor[publicDependencies.size()];
+ publicDependencies.toArray(this.publicDependencies);
+
+ pool.addPackage(getPackage(), this);
+
+ messageTypes = new Descriptor[proto.getMessageTypeCount()];
+ for (int i = 0; i < proto.getMessageTypeCount(); i++) {
+ messageTypes[i] =
+ new Descriptor(proto.getMessageType(i), this, null, i);
+ }
+
+ enumTypes = new EnumDescriptor[proto.getEnumTypeCount()];
+ for (int i = 0; i < proto.getEnumTypeCount(); i++) {
+ enumTypes[i] = new EnumDescriptor(proto.getEnumType(i), this, null, i);
+ }
+
+ services = new ServiceDescriptor[proto.getServiceCount()];
+ for (int i = 0; i < proto.getServiceCount(); i++) {
+ services[i] = new ServiceDescriptor(proto.getService(i), this, i);
+ }
+
+ extensions = new FieldDescriptor[proto.getExtensionCount()];
+ for (int i = 0; i < proto.getExtensionCount(); i++) {
+ extensions[i] = new FieldDescriptor(
+ proto.getExtension(i), this, null, i, true);
+ }
+ }
+
+ /**
+ * Create a placeholder FileDescriptor for a message Descriptor.
+ */
+ FileDescriptor(String packageName, Descriptor message)
+ throws DescriptorValidationException {
+ this.pool = new DescriptorPool(new FileDescriptor[0], true);
+ this.proto = FileDescriptorProto.newBuilder()
+ .setName(message.getFullName() + ".placeholder.proto")
+ .setPackage(packageName).addMessageType(message.toProto()).build();
+ this.dependencies = new FileDescriptor[0];
+ this.publicDependencies = new FileDescriptor[0];
+
+ messageTypes = new Descriptor[] {message};
+ enumTypes = new EnumDescriptor[0];
+ services = new ServiceDescriptor[0];
+ extensions = new FieldDescriptor[0];
+
+ pool.addPackage(packageName, this);
+ pool.addSymbol(message);
+ }
+
+ /** Look up and cross-link all field types, etc. */
+ private void crossLink() throws DescriptorValidationException {
+ for (final Descriptor messageType : messageTypes) {
+ messageType.crossLink();
+ }
+
+ for (final ServiceDescriptor service : services) {
+ service.crossLink();
+ }
+
+ for (final FieldDescriptor extension : extensions) {
+ extension.crossLink();
+ }
+ }
+
+ /**
+ * Replace our {@link FileDescriptorProto} with the given one, which is
+ * identical except that it might contain extensions that weren't present
+ * in the original. This method is needed for bootstrapping when a file
+ * defines custom options. The options may be defined in the file itself,
+ * so we can't actually parse them until we've constructed the descriptors,
+ * but to construct the descriptors we have to have parsed the descriptor
+ * protos. So, we have to parse the descriptor protos a second time after
+ * constructing the descriptors.
+ */
+ private void setProto(final FileDescriptorProto proto) {
+ this.proto = proto;
+
+ for (int i = 0; i < messageTypes.length; i++) {
+ messageTypes[i].setProto(proto.getMessageType(i));
+ }
+
+ for (int i = 0; i < enumTypes.length; i++) {
+ enumTypes[i].setProto(proto.getEnumType(i));
+ }
+
+ for (int i = 0; i < services.length; i++) {
+ services[i].setProto(proto.getService(i));
+ }
+
+ for (int i = 0; i < extensions.length; i++) {
+ extensions[i].setProto(proto.getExtension(i));
+ }
+ }
+
+ boolean supportsUnknownEnumValue() {
+ return getSyntax() == Syntax.PROTO3;
+ }
+ }
+
+ // =================================================================
+
+ /** Describes a message type. */
+ public static final class Descriptor extends GenericDescriptor {
+ /**
+ * Get the index of this descriptor within its parent. In other words,
+ * given a {@link FileDescriptor} {@code file}, the following is true:
+ * <pre>
+ * for all i in [0, file.getMessageTypeCount()):
+ * file.getMessageType(i).getIndex() == i
+ * </pre>
+ * Similarly, for a {@link Descriptor} {@code messageType}:
+ * <pre>
+ * for all i in [0, messageType.getNestedTypeCount()):
+ * messageType.getNestedType(i).getIndex() == i
+ * </pre>
+ */
+ public int getIndex() { return index; }
+
+ /** Convert the descriptor to its protocol message representation. */
+ @Override
+ public DescriptorProto toProto() {
+ return proto;
+ }
+
+ /** Get the type's unqualified name. */
+ @Override
+ public String getName() {
+ return proto.getName();
+ }
+
+ /**
+ * Get the type's fully-qualified name, within the proto language's
+ * namespace. This differs from the Java name. For example, given this
+ * {@code .proto}:
+ * <pre>
+ * package foo.bar;
+ * option java_package = "com.example.protos"
+ * message Baz {}
+ * </pre>
+ * {@code Baz}'s full name is "foo.bar.Baz".
+ */
+ @Override
+ public String getFullName() {
+ return fullName;
+ }
+
+ /** Get the {@link FileDescriptor} containing this descriptor. */
+ @Override
+ public FileDescriptor getFile() {
+ return file;
+ }
+
+ /** If this is a nested type, get the outer descriptor, otherwise null. */
+ public Descriptor getContainingType() { return containingType; }
+
+ /** Get the {@code MessageOptions}, defined in {@code descriptor.proto}. */
+ public MessageOptions getOptions() { return proto.getOptions(); }
+
+ /** Get a list of this message type's fields. */
+ public List<FieldDescriptor> getFields() {
+ return Collections.unmodifiableList(Arrays.asList(fields));
+ }
+
+ /** Get a list of this message type's oneofs. */
+ public List<OneofDescriptor> getOneofs() {
+ return Collections.unmodifiableList(Arrays.asList(oneofs));
+ }
+
+ /** Get a list of this message type's extensions. */
+ public List<FieldDescriptor> getExtensions() {
+ return Collections.unmodifiableList(Arrays.asList(extensions));
+ }
+
+ /** Get a list of message types nested within this one. */
+ public List<Descriptor> getNestedTypes() {
+ return Collections.unmodifiableList(Arrays.asList(nestedTypes));
+ }
+
+ /** Get a list of enum types nested within this one. */
+ public List<EnumDescriptor> getEnumTypes() {
+ return Collections.unmodifiableList(Arrays.asList(enumTypes));
+ }
+
+ /** Determines if the given field number is an extension. */
+ public boolean isExtensionNumber(final int number) {
+ for (final DescriptorProto.ExtensionRange range :
+ proto.getExtensionRangeList()) {
+ if (range.getStart() <= number && number < range.getEnd()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /** Determines if the given field number is reserved. */
+ public boolean isReservedNumber(final int number) {
+ for (final DescriptorProto.ReservedRange range :
+ proto.getReservedRangeList()) {
+ if (range.getStart() <= number && number < range.getEnd()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /** Determines if the given field name is reserved. */
+ public boolean isReservedName(final String name) {
+ if (name == null) {
+ throw new NullPointerException();
+ }
+ for (final String reservedName : proto.getReservedNameList()) {
+ if (reservedName.equals(name)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Indicates whether the message can be extended. That is, whether it has
+ * any "extensions x to y" ranges declared on it.
+ */
+ public boolean isExtendable() {
+ return proto.getExtensionRangeList().size() != 0;
+ }
+
+ /**
+ * Finds a field by name.
+ * @param name The unqualified name of the field (e.g. "foo").
+ * @return The field's descriptor, or {@code null} if not found.
+ */
+ public FieldDescriptor findFieldByName(final String name) {
+ final GenericDescriptor result =
+ file.pool.findSymbol(fullName + '.' + name);
+ if (result != null && result instanceof FieldDescriptor) {
+ return (FieldDescriptor)result;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Finds a field by field number.
+ * @param number The field number within this message type.
+ * @return The field's descriptor, or {@code null} if not found.
+ */
+ public FieldDescriptor findFieldByNumber(final int number) {
+ return file.pool.fieldsByNumber.get(
+ new DescriptorPool.DescriptorIntPair(this, number));
+ }
+
+ /**
+ * Finds a nested message type by name.
+ * @param name The unqualified name of the nested type (e.g. "Foo").
+ * @return The types's descriptor, or {@code null} if not found.
+ */
+ public Descriptor findNestedTypeByName(final String name) {
+ final GenericDescriptor result =
+ file.pool.findSymbol(fullName + '.' + name);
+ if (result != null && result instanceof Descriptor) {
+ return (Descriptor)result;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Finds a nested enum type by name.
+ * @param name The unqualified name of the nested type (e.g. "Foo").
+ * @return The types's descriptor, or {@code null} if not found.
+ */
+ public EnumDescriptor findEnumTypeByName(final String name) {
+ final GenericDescriptor result =
+ file.pool.findSymbol(fullName + '.' + name);
+ if (result != null && result instanceof EnumDescriptor) {
+ return (EnumDescriptor)result;
+ } else {
+ return null;
+ }
+ }
+
+ private final int index;
+ private DescriptorProto proto;
+ private final String fullName;
+ private final FileDescriptor file;
+ private final Descriptor containingType;
+ private final Descriptor[] nestedTypes;
+ private final EnumDescriptor[] enumTypes;
+ private final FieldDescriptor[] fields;
+ private final FieldDescriptor[] extensions;
+ private final OneofDescriptor[] oneofs;
+
+ // Used to create a placeholder when the type cannot be found.
+ Descriptor(final String fullname) throws DescriptorValidationException {
+ String name = fullname;
+ String packageName = "";
+ int pos = fullname.lastIndexOf('.');
+ if (pos != -1) {
+ name = fullname.substring(pos + 1);
+ packageName = fullname.substring(0, pos);
+ }
+ this.index = 0;
+ this.proto = DescriptorProto.newBuilder().setName(name).addExtensionRange(
+ DescriptorProto.ExtensionRange.newBuilder().setStart(1)
+ .setEnd(536870912).build()).build();
+ this.fullName = fullname;
+ this.containingType = null;
+
+ this.nestedTypes = new Descriptor[0];
+ this.enumTypes = new EnumDescriptor[0];
+ this.fields = new FieldDescriptor[0];
+ this.extensions = new FieldDescriptor[0];
+ this.oneofs = new OneofDescriptor[0];
+
+ // Create a placeholder FileDescriptor to hold this message.
+ this.file = new FileDescriptor(packageName, this);
+ }
+
+ private Descriptor(final DescriptorProto proto,
+ final FileDescriptor file,
+ final Descriptor parent,
+ final int index)
+ throws DescriptorValidationException {
+ this.index = index;
+ this.proto = proto;
+ fullName = computeFullName(file, parent, proto.getName());
+ this.file = file;
+ containingType = parent;
+
+ oneofs = new OneofDescriptor[proto.getOneofDeclCount()];
+ for (int i = 0; i < proto.getOneofDeclCount(); i++) {
+ oneofs[i] = new OneofDescriptor(
+ proto.getOneofDecl(i), file, this, i);
+ }
+
+ nestedTypes = new Descriptor[proto.getNestedTypeCount()];
+ for (int i = 0; i < proto.getNestedTypeCount(); i++) {
+ nestedTypes[i] = new Descriptor(
+ proto.getNestedType(i), file, this, i);
+ }
+
+ enumTypes = new EnumDescriptor[proto.getEnumTypeCount()];
+ for (int i = 0; i < proto.getEnumTypeCount(); i++) {
+ enumTypes[i] = new EnumDescriptor(
+ proto.getEnumType(i), file, this, i);
+ }
+
+ fields = new FieldDescriptor[proto.getFieldCount()];
+ for (int i = 0; i < proto.getFieldCount(); i++) {
+ fields[i] = new FieldDescriptor(
+ proto.getField(i), file, this, i, false);
+ }
+
+ extensions = new FieldDescriptor[proto.getExtensionCount()];
+ for (int i = 0; i < proto.getExtensionCount(); i++) {
+ extensions[i] = new FieldDescriptor(
+ proto.getExtension(i), file, this, i, true);
+ }
+
+ for (int i = 0; i < proto.getOneofDeclCount(); i++) {
+ oneofs[i].fields = new FieldDescriptor[oneofs[i].getFieldCount()];
+ oneofs[i].fieldCount = 0;
+ }
+ for (int i = 0; i < proto.getFieldCount(); i++) {
+ OneofDescriptor oneofDescriptor = fields[i].getContainingOneof();
+ if (oneofDescriptor != null) {
+ oneofDescriptor.fields[oneofDescriptor.fieldCount++] = fields[i];
+ }
+ }
+
+ file.pool.addSymbol(this);
+ }
+
+ /** Look up and cross-link all field types, etc. */
+ private void crossLink() throws DescriptorValidationException {
+ for (final Descriptor nestedType : nestedTypes) {
+ nestedType.crossLink();
+ }
+
+ for (final FieldDescriptor field : fields) {
+ field.crossLink();
+ }
+
+ for (final FieldDescriptor extension : extensions) {
+ extension.crossLink();
+ }
+ }
+
+ /** See {@link FileDescriptor#setProto}. */
+ private void setProto(final DescriptorProto proto) {
+ this.proto = proto;
+
+ for (int i = 0; i < nestedTypes.length; i++) {
+ nestedTypes[i].setProto(proto.getNestedType(i));
+ }
+
+ for (int i = 0; i < oneofs.length; i++) {
+ oneofs[i].setProto(proto.getOneofDecl(i));
+ }
+
+ for (int i = 0; i < enumTypes.length; i++) {
+ enumTypes[i].setProto(proto.getEnumType(i));
+ }
+
+ for (int i = 0; i < fields.length; i++) {
+ fields[i].setProto(proto.getField(i));
+ }
+
+ for (int i = 0; i < extensions.length; i++) {
+ extensions[i].setProto(proto.getExtension(i));
+ }
+ }
+ }
+
+ // =================================================================
+
+ /** Describes a field of a message type. */
+ public static final class FieldDescriptor
+ extends GenericDescriptor
+ implements Comparable<FieldDescriptor>,
+ FieldSet.FieldDescriptorLite<FieldDescriptor> {
+ /**
+ * Get the index of this descriptor within its parent.
+ * @see Descriptors.Descriptor#getIndex()
+ */
+ public int getIndex() { return index; }
+
+ /** Convert the descriptor to its protocol message representation. */
+ @Override
+ public FieldDescriptorProto toProto() {
+ return proto;
+ }
+
+ /** Get the field's unqualified name. */
+ @Override
+ public String getName() {
+ return proto.getName();
+ }
+
+ /** Get the field's number. */
+ @Override
+ public int getNumber() {
+ return proto.getNumber();
+ }
+
+ /**
+ * Get the field's fully-qualified name.
+ * @see Descriptors.Descriptor#getFullName()
+ */
+ @Override
+ public String getFullName() {
+ return fullName;
+ }
+
+ /** Get the JSON name of this field. */
+ public String getJsonName() {
+ return jsonName;
+ }
+
+ /**
+ * Get the field's java type. This is just for convenience. Every
+ * {@code FieldDescriptorProto.Type} maps to exactly one Java type.
+ */
+ public JavaType getJavaType() { return type.getJavaType(); }
+
+ /** For internal use only. */
+ @Override
+ public WireFormat.JavaType getLiteJavaType() {
+ return getLiteType().getJavaType();
+ }
+
+ /** Get the {@code FileDescriptor} containing this descriptor. */
+ @Override
+ public FileDescriptor getFile() {
+ return file;
+ }
+
+ /** Get the field's declared type. */
+ public Type getType() { return type; }
+
+ /** For internal use only. */
+ @Override
+ public WireFormat.FieldType getLiteType() {
+ return table[type.ordinal()];
+ }
+
+ /** For internal use only. */
+ public boolean needsUtf8Check() {
+ if (type != Type.STRING) {
+ return false;
+ }
+ if (getContainingType().getOptions().getMapEntry()) {
+ // Always enforce strict UTF-8 checking for map fields.
+ return true;
+ }
+ if (getFile().getSyntax() == Syntax.PROTO3) {
+ return true;
+ }
+ return getFile().getOptions().getJavaStringCheckUtf8();
+ }
+
+ public boolean isMapField() {
+ return getType() == Type.MESSAGE && isRepeated()
+ && getMessageType().getOptions().getMapEntry();
+ }
+
+ // I'm pretty sure values() constructs a new array every time, since there
+ // is nothing stopping the caller from mutating the array. Therefore we
+ // make a static copy here.
+ private static final WireFormat.FieldType[] table =
+ WireFormat.FieldType.values();
+
+ /** Is this field declared required? */
+ public boolean isRequired() {
+ return proto.getLabel() == FieldDescriptorProto.Label.LABEL_REQUIRED;
+ }
+
+ /** Is this field declared optional? */
+ public boolean isOptional() {
+ return proto.getLabel() == FieldDescriptorProto.Label.LABEL_OPTIONAL;
+ }
+
+ /** Is this field declared repeated? */
+ @Override
+ public boolean isRepeated() {
+ return proto.getLabel() == FieldDescriptorProto.Label.LABEL_REPEATED;
+ }
+
+ /** Does this field have the {@code [packed = true]} option or is this field
+ * packable in proto3 and not explicitly setted to unpacked?
+ */
+ @Override
+ public boolean isPacked() {
+ if (!isPackable()) {
+ return false;
+ }
+ if (getFile().getSyntax() == FileDescriptor.Syntax.PROTO2) {
+ return getOptions().getPacked();
+ } else {
+ return !getOptions().hasPacked() || getOptions().getPacked();
+ }
+ }
+
+ /** Can this field be packed? i.e. is it a repeated primitive field? */
+ public boolean isPackable() {
+ return isRepeated() && getLiteType().isPackable();
+ }
+
+ /** Returns true if the field had an explicitly-defined default value. */
+ public boolean hasDefaultValue() { return proto.hasDefaultValue(); }
+
+ /**
+ * Returns the field's default value. Valid for all types except for
+ * messages and groups. For all other types, the object returned is of
+ * the same class that would returned by Message.getField(this).
+ */
+ public Object getDefaultValue() {
+ if (getJavaType() == JavaType.MESSAGE) {
+ throw new UnsupportedOperationException(
+ "FieldDescriptor.getDefaultValue() called on an embedded message " +
+ "field.");
+ }
+ return defaultValue;
+ }
+
+ /** Get the {@code FieldOptions}, defined in {@code descriptor.proto}. */
+ public FieldOptions getOptions() { return proto.getOptions(); }
+
+ /** Is this field an extension? */
+ public boolean isExtension() { return proto.hasExtendee(); }
+
+ /**
+ * Get the field's containing type. For extensions, this is the type being
+ * extended, not the location where the extension was defined. See
+ * {@link #getExtensionScope()}.
+ */
+ public Descriptor getContainingType() { return containingType; }
+
+ /** Get the field's containing oneof. */
+ public OneofDescriptor getContainingOneof() { return containingOneof; }
+
+ /**
+ * For extensions defined nested within message types, gets the outer
+ * type. Not valid for non-extension fields. For example, consider
+ * this {@code .proto} file:
+ * <pre>
+ * message Foo {
+ * extensions 1000 to max;
+ * }
+ * extend Foo {
+ * optional int32 baz = 1234;
+ * }
+ * message Bar {
+ * extend Foo {
+ * optional int32 qux = 4321;
+ * }
+ * }
+ * </pre>
+ * Both {@code baz}'s and {@code qux}'s containing type is {@code Foo}.
+ * However, {@code baz}'s extension scope is {@code null} while
+ * {@code qux}'s extension scope is {@code Bar}.
+ */
+ public Descriptor getExtensionScope() {
+ if (!isExtension()) {
+ throw new UnsupportedOperationException(
+ "This field is not an extension.");
+ }
+ return extensionScope;
+ }
+
+ /** For embedded message and group fields, gets the field's type. */
+ public Descriptor getMessageType() {
+ if (getJavaType() != JavaType.MESSAGE) {
+ throw new UnsupportedOperationException(
+ "This field is not of message type.");
+ }
+ return messageType;
+ }
+
+ /** For enum fields, gets the field's type. */
+ @Override
+ public EnumDescriptor getEnumType() {
+ if (getJavaType() != JavaType.ENUM) {
+ throw new UnsupportedOperationException(
+ "This field is not of enum type.");
+ }
+ return enumType;
+ }
+
+ /**
+ * Compare with another {@code FieldDescriptor}. This orders fields in
+ * "canonical" order, which simply means ascending order by field number.
+ * {@code other} must be a field of the same type -- i.e.
+ * {@code getContainingType()} must return the same {@code Descriptor} for
+ * both fields.
+ *
+ * @return negative, zero, or positive if {@code this} is less than,
+ * equal to, or greater than {@code other}, respectively.
+ */
+ @Override
+ public int compareTo(final FieldDescriptor other) {
+ if (other.containingType != containingType) {
+ throw new IllegalArgumentException(
+ "FieldDescriptors can only be compared to other FieldDescriptors " +
+ "for fields of the same message type.");
+ }
+ return getNumber() - other.getNumber();
+ }
+
+ @Override
+ public String toString() {
+ return getFullName();
+ }
+
+ private final int index;
+
+ private FieldDescriptorProto proto;
+ private final String fullName;
+ private final String jsonName;
+ private final FileDescriptor file;
+ private final Descriptor extensionScope;
+
+ // Possibly initialized during cross-linking.
+ private Type type;
+ private Descriptor containingType;
+ private Descriptor messageType;
+ private OneofDescriptor containingOneof;
+ private EnumDescriptor enumType;
+ private Object defaultValue;
+
+ public enum Type {
+ DOUBLE (JavaType.DOUBLE ),
+ FLOAT (JavaType.FLOAT ),
+ INT64 (JavaType.LONG ),
+ UINT64 (JavaType.LONG ),
+ INT32 (JavaType.INT ),
+ FIXED64 (JavaType.LONG ),
+ FIXED32 (JavaType.INT ),
+ BOOL (JavaType.BOOLEAN ),
+ STRING (JavaType.STRING ),
+ GROUP (JavaType.MESSAGE ),
+ MESSAGE (JavaType.MESSAGE ),
+ BYTES (JavaType.BYTE_STRING),
+ UINT32 (JavaType.INT ),
+ ENUM (JavaType.ENUM ),
+ SFIXED32(JavaType.INT ),
+ SFIXED64(JavaType.LONG ),
+ SINT32 (JavaType.INT ),
+ SINT64 (JavaType.LONG );
+
+ Type(final JavaType javaType) {
+ this.javaType = javaType;
+ }
+
+ private JavaType javaType;
+
+ public FieldDescriptorProto.Type toProto() {
+ return FieldDescriptorProto.Type.forNumber(ordinal() + 1);
+ }
+ public JavaType getJavaType() { return javaType; }
+
+ public static Type valueOf(final FieldDescriptorProto.Type type) {
+ return values()[type.getNumber() - 1];
+ }
+ }
+
+ static {
+ // Refuse to init if someone added a new declared type.
+ if (Type.values().length != FieldDescriptorProto.Type.values().length) {
+ throw new RuntimeException(""
+ + "descriptor.proto has a new declared type but Descriptors.java "
+ + "wasn't updated.");
+ }
+ }
+
+ public enum JavaType {
+ INT(0),
+ LONG(0L),
+ FLOAT(0F),
+ DOUBLE(0D),
+ BOOLEAN(false),
+ STRING(""),
+ BYTE_STRING(ByteString.EMPTY),
+ ENUM(null),
+ MESSAGE(null);
+
+ JavaType(final Object defaultDefault) {
+ this.defaultDefault = defaultDefault;
+ }
+
+ /**
+ * The default default value for fields of this type, if it's a primitive
+ * type. This is meant for use inside this file only, hence is private.
+ */
+ private final Object defaultDefault;
+ }
+
+ // 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 (ch == '_') {
+ isNextUpperCase = true;
+ } else if (isNextUpperCase) {
+ result.append(Character.toUpperCase(ch));
+ isNextUpperCase = false;
+ } else {
+ result.append(ch);
+ }
+ }
+ return result.toString();
+ }
+
+ private FieldDescriptor(final FieldDescriptorProto proto,
+ final FileDescriptor file,
+ final Descriptor parent,
+ final int index,
+ final boolean isExtension)
+ throws DescriptorValidationException {
+ this.index = index;
+ this.proto = proto;
+ fullName = computeFullName(file, parent, proto.getName());
+ this.file = file;
+ if (proto.hasJsonName()) {
+ jsonName = proto.getJsonName();
+ } else {
+ jsonName = fieldNameToJsonName(proto.getName());
+ }
+
+ if (proto.hasType()) {
+ type = Type.valueOf(proto.getType());
+ }
+
+ if (getNumber() <= 0) {
+ throw new DescriptorValidationException(this,
+ "Field numbers must be positive integers.");
+ }
+
+ if (isExtension) {
+ if (!proto.hasExtendee()) {
+ throw new DescriptorValidationException(this,
+ "FieldDescriptorProto.extendee not set for extension field.");
+ }
+ containingType = null; // Will be filled in when cross-linking
+ if (parent != null) {
+ extensionScope = parent;
+ } else {
+ extensionScope = null;
+ }
+
+ if (proto.hasOneofIndex()) {
+ throw new DescriptorValidationException(this,
+ "FieldDescriptorProto.oneof_index set for extension field.");
+ }
+ containingOneof = null;
+ } else {
+ if (proto.hasExtendee()) {
+ throw new DescriptorValidationException(this,
+ "FieldDescriptorProto.extendee set for non-extension field.");
+ }
+ containingType = parent;
+
+ if (proto.hasOneofIndex()) {
+ if (proto.getOneofIndex() < 0 ||
+ proto.getOneofIndex() >= parent.toProto().getOneofDeclCount()) {
+ throw new DescriptorValidationException(this,
+ "FieldDescriptorProto.oneof_index is out of range for type "
+ + parent.getName());
+ }
+ containingOneof = parent.getOneofs().get(proto.getOneofIndex());
+ containingOneof.fieldCount++;
+ } else {
+ containingOneof = null;
+ }
+ extensionScope = null;
+ }
+
+ file.pool.addSymbol(this);
+ }
+
+ /** Look up and cross-link all field types, etc. */
+ private void crossLink() throws DescriptorValidationException {
+ if (proto.hasExtendee()) {
+ final GenericDescriptor extendee =
+ file.pool.lookupSymbol(proto.getExtendee(), this,
+ DescriptorPool.SearchFilter.TYPES_ONLY);
+ if (!(extendee instanceof Descriptor)) {
+ throw new DescriptorValidationException(this,
+ '\"' + proto.getExtendee() + "\" is not a message type.");
+ }
+ containingType = (Descriptor)extendee;
+
+ if (!getContainingType().isExtensionNumber(getNumber())) {
+ throw new DescriptorValidationException(this,
+ '\"' + getContainingType().getFullName() +
+ "\" does not declare " + getNumber() +
+ " as an extension number.");
+ }
+ }
+
+ if (proto.hasTypeName()) {
+ final GenericDescriptor typeDescriptor =
+ file.pool.lookupSymbol(proto.getTypeName(), this,
+ DescriptorPool.SearchFilter.TYPES_ONLY);
+
+ if (!proto.hasType()) {
+ // Choose field type based on symbol.
+ if (typeDescriptor instanceof Descriptor) {
+ type = Type.MESSAGE;
+ } else if (typeDescriptor instanceof EnumDescriptor) {
+ type = Type.ENUM;
+ } else {
+ throw new DescriptorValidationException(this,
+ '\"' + proto.getTypeName() + "\" is not a type.");
+ }
+ }
+
+ if (getJavaType() == JavaType.MESSAGE) {
+ if (!(typeDescriptor instanceof Descriptor)) {
+ throw new DescriptorValidationException(this,
+ '\"' + proto.getTypeName() + "\" is not a message type.");
+ }
+ messageType = (Descriptor)typeDescriptor;
+
+ if (proto.hasDefaultValue()) {
+ throw new DescriptorValidationException(this,
+ "Messages can't have default values.");
+ }
+ } else if (getJavaType() == JavaType.ENUM) {
+ if (!(typeDescriptor instanceof EnumDescriptor)) {
+ throw new DescriptorValidationException(this,
+ '\"' + proto.getTypeName() + "\" is not an enum type.");
+ }
+ enumType = (EnumDescriptor)typeDescriptor;
+ } else {
+ throw new DescriptorValidationException(this,
+ "Field with primitive type has type_name.");
+ }
+ } else {
+ if (getJavaType() == JavaType.MESSAGE ||
+ getJavaType() == JavaType.ENUM) {
+ throw new DescriptorValidationException(this,
+ "Field with message or enum type missing type_name.");
+ }
+ }
+
+ // Only repeated primitive fields may be packed.
+ if (proto.getOptions().getPacked() && !isPackable()) {
+ throw new DescriptorValidationException(this,
+ "[packed = true] can only be specified for repeated primitive " +
+ "fields.");
+ }
+
+ // We don't attempt to parse the default value until here because for
+ // enums we need the enum type's descriptor.
+ if (proto.hasDefaultValue()) {
+ if (isRepeated()) {
+ throw new DescriptorValidationException(this,
+ "Repeated fields cannot have default values.");
+ }
+
+ try {
+ switch (getType()) {
+ case INT32:
+ case SINT32:
+ case SFIXED32:
+ defaultValue = TextFormat.parseInt32(proto.getDefaultValue());
+ break;
+ case UINT32:
+ case FIXED32:
+ defaultValue = TextFormat.parseUInt32(proto.getDefaultValue());
+ break;
+ case INT64:
+ case SINT64:
+ case SFIXED64:
+ defaultValue = TextFormat.parseInt64(proto.getDefaultValue());
+ break;
+ case UINT64:
+ case FIXED64:
+ defaultValue = TextFormat.parseUInt64(proto.getDefaultValue());
+ break;
+ case FLOAT:
+ if (proto.getDefaultValue().equals("inf")) {
+ defaultValue = Float.POSITIVE_INFINITY;
+ } else if (proto.getDefaultValue().equals("-inf")) {
+ defaultValue = Float.NEGATIVE_INFINITY;
+ } else if (proto.getDefaultValue().equals("nan")) {
+ defaultValue = Float.NaN;
+ } else {
+ defaultValue = Float.valueOf(proto.getDefaultValue());
+ }
+ break;
+ case DOUBLE:
+ if (proto.getDefaultValue().equals("inf")) {
+ defaultValue = Double.POSITIVE_INFINITY;
+ } else if (proto.getDefaultValue().equals("-inf")) {
+ defaultValue = Double.NEGATIVE_INFINITY;
+ } else if (proto.getDefaultValue().equals("nan")) {
+ defaultValue = Double.NaN;
+ } else {
+ defaultValue = Double.valueOf(proto.getDefaultValue());
+ }
+ break;
+ case BOOL:
+ defaultValue = Boolean.valueOf(proto.getDefaultValue());
+ break;
+ case STRING:
+ defaultValue = proto.getDefaultValue();
+ break;
+ case BYTES:
+ try {
+ defaultValue =
+ TextFormat.unescapeBytes(proto.getDefaultValue());
+ } catch (TextFormat.InvalidEscapeSequenceException e) {
+ throw new DescriptorValidationException(this,
+ "Couldn't parse default value: " + e.getMessage(), e);
+ }
+ break;
+ case ENUM:
+ defaultValue = enumType.findValueByName(proto.getDefaultValue());
+ if (defaultValue == null) {
+ throw new DescriptorValidationException(this,
+ "Unknown enum default value: \"" +
+ proto.getDefaultValue() + '\"');
+ }
+ break;
+ case MESSAGE:
+ case GROUP:
+ throw new DescriptorValidationException(this,
+ "Message type had default value.");
+ }
+ } catch (NumberFormatException e) {
+ throw new DescriptorValidationException(this,
+ "Could not parse default value: \"" +
+ proto.getDefaultValue() + '\"', e);
+ }
+ } else {
+ // Determine the default default for this field.
+ if (isRepeated()) {
+ defaultValue = Collections.emptyList();
+ } else {
+ switch (getJavaType()) {
+ case ENUM:
+ // We guarantee elsewhere that an enum type always has at least
+ // one possible value.
+ defaultValue = enumType.getValues().get(0);
+ break;
+ case MESSAGE:
+ defaultValue = null;
+ break;
+ default:
+ defaultValue = getJavaType().defaultDefault;
+ break;
+ }
+ }
+ }
+
+ if (!isExtension()) {
+ file.pool.addFieldByNumber(this);
+ }
+
+ if (containingType != null &&
+ containingType.getOptions().getMessageSetWireFormat()) {
+ if (isExtension()) {
+ if (!isOptional() || getType() != Type.MESSAGE) {
+ throw new DescriptorValidationException(this,
+ "Extensions of MessageSets must be optional messages.");
+ }
+ } else {
+ throw new DescriptorValidationException(this,
+ "MessageSets cannot have fields, only extensions.");
+ }
+ }
+ }
+
+ /** See {@link FileDescriptor#setProto}. */
+ private void setProto(final FieldDescriptorProto proto) {
+ this.proto = proto;
+ }
+
+ /**
+ * For internal use only. This is to satisfy the FieldDescriptorLite
+ * interface.
+ */
+ @Override
+ public MessageLite.Builder internalMergeFrom(MessageLite.Builder to, MessageLite from) {
+ // FieldDescriptors are only used with non-lite messages so we can just
+ // down-cast and call mergeFrom directly.
+ return ((Message.Builder) to).mergeFrom((Message) from);
+ }
+
+ }
+
+ // =================================================================
+
+ /** Describes an enum type. */
+ public static final class EnumDescriptor extends GenericDescriptor
+ implements Internal.EnumLiteMap<EnumValueDescriptor> {
+ /**
+ * Get the index of this descriptor within its parent.
+ * @see Descriptors.Descriptor#getIndex()
+ */
+ public int getIndex() { return index; }
+
+ /** Convert the descriptor to its protocol message representation. */
+ @Override
+ public EnumDescriptorProto toProto() {
+ return proto;
+ }
+
+ /** Get the type's unqualified name. */
+ @Override
+ public String getName() {
+ return proto.getName();
+ }
+
+ /**
+ * Get the type's fully-qualified name.
+ * @see Descriptors.Descriptor#getFullName()
+ */
+ @Override
+ public String getFullName() {
+ return fullName;
+ }
+
+ /** Get the {@link FileDescriptor} containing this descriptor. */
+ @Override
+ public FileDescriptor getFile() {
+ return file;
+ }
+
+ /** If this is a nested type, get the outer descriptor, otherwise null. */
+ public Descriptor getContainingType() { return containingType; }
+
+ /** Get the {@code EnumOptions}, defined in {@code descriptor.proto}. */
+ public EnumOptions getOptions() { return proto.getOptions(); }
+
+ /** Get a list of defined values for this enum. */
+ public List<EnumValueDescriptor> getValues() {
+ return Collections.unmodifiableList(Arrays.asList(values));
+ }
+
+ /**
+ * Find an enum value by name.
+ * @param name The unqualified name of the value (e.g. "FOO").
+ * @return the value's descriptor, or {@code null} if not found.
+ */
+ public EnumValueDescriptor findValueByName(final String name) {
+ final GenericDescriptor result =
+ file.pool.findSymbol(fullName + '.' + name);
+ if (result != null && result instanceof EnumValueDescriptor) {
+ return (EnumValueDescriptor)result;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Find an enum value by number. If multiple enum values have the same
+ * number, this returns the first defined value with that number.
+ * @param number The value's number.
+ * @return the value's descriptor, or {@code null} if not found.
+ */
+ @Override
+ public EnumValueDescriptor findValueByNumber(final int number) {
+ return file.pool.enumValuesByNumber.get(
+ new DescriptorPool.DescriptorIntPair(this, number));
+ }
+
+ /**
+ * Get the enum value for a number. If no enum value has this number,
+ * construct an EnumValueDescriptor for it.
+ */
+ public EnumValueDescriptor findValueByNumberCreatingIfUnknown(final int number) {
+ EnumValueDescriptor result = findValueByNumber(number);
+ if (result != null) {
+ return result;
+ }
+ // The number represents an unknown enum value.
+ synchronized (this) {
+ // Descriptors are compared by object identity so for the same number
+ // we need to return the same EnumValueDescriptor object. This means
+ // we have to store created EnumValueDescriptors. However, as there
+ // are potentially 2G unknown enum values, storing all of these
+ // objects persistently will consume lots of memory for long-running
+ // services and it's also unnecessary as not many EnumValueDescriptors
+ // will be used at the same time.
+ //
+ // To solve the problem we take advantage of Java's weak references and
+ // rely on gc to release unused descriptors.
+ //
+ // Here is how it works:
+ // * We store unknown EnumValueDescriptors in a WeakHashMap with the
+ // value being a weak reference to the descriptor.
+ // * The descriptor holds a strong reference to the key so as long
+ // as the EnumValueDescriptor is in use, the key will be there
+ // and the corresponding map entry will be there. Following-up
+ // queries with the same number will return the same descriptor.
+ // * If the user no longer uses an unknown EnumValueDescriptor,
+ // it will be gc-ed since we only hold a weak reference to it in
+ // the map. The key in the corresponding map entry will also be
+ // gc-ed as the only strong reference to it is in the descriptor
+ // which is just gc-ed. With the key being gone WeakHashMap will
+ // then remove the whole entry. This way unknown descriptors will
+ // be freed automatically and we don't need to do anything to
+ // clean-up unused map entries.
+
+ // Note: We must use "new Integer(number)" here because we don't want
+ // these Integer objects to be cached.
+ Integer key = new Integer(number);
+ WeakReference<EnumValueDescriptor> reference = unknownValues.get(key);
+ if (reference != null) {
+ result = reference.get();
+ }
+ if (result == null) {
+ result = new EnumValueDescriptor(file, this, key);
+ unknownValues.put(key, new WeakReference<EnumValueDescriptor>(result));
+ }
+ }
+ return result;
+ }
+
+ // Used in tests only.
+ int getUnknownEnumValueDescriptorCount() {
+ return unknownValues.size();
+ }
+
+ private final int index;
+ private EnumDescriptorProto proto;
+ private final String fullName;
+ private final FileDescriptor file;
+ private final Descriptor containingType;
+ private EnumValueDescriptor[] values;
+ private final WeakHashMap<Integer, WeakReference<EnumValueDescriptor>> unknownValues =
+ new WeakHashMap<Integer, WeakReference<EnumValueDescriptor>>();
+
+ private EnumDescriptor(final EnumDescriptorProto proto,
+ final FileDescriptor file,
+ final Descriptor parent,
+ final int index)
+ throws DescriptorValidationException {
+ this.index = index;
+ this.proto = proto;
+ fullName = computeFullName(file, parent, proto.getName());
+ this.file = file;
+ containingType = parent;
+
+ if (proto.getValueCount() == 0) {
+ // We cannot allow enums with no values because this would mean there
+ // would be no valid default value for fields of this type.
+ throw new DescriptorValidationException(this,
+ "Enums must contain at least one value.");
+ }
+
+ values = new EnumValueDescriptor[proto.getValueCount()];
+ for (int i = 0; i < proto.getValueCount(); i++) {
+ values[i] = new EnumValueDescriptor(
+ proto.getValue(i), file, this, i);
+ }
+
+ file.pool.addSymbol(this);
+ }
+
+ /** See {@link FileDescriptor#setProto}. */
+ private void setProto(final EnumDescriptorProto proto) {
+ this.proto = proto;
+
+ for (int i = 0; i < values.length; i++) {
+ values[i].setProto(proto.getValue(i));
+ }
+ }
+ }
+
+ // =================================================================
+
+ /**
+ * Describes one value within an enum type. Note that multiple defined
+ * values may have the same number. In generated Java code, all values
+ * with the same number after the first become aliases of the first.
+ * However, they still have independent EnumValueDescriptors.
+ */
+ public static final class EnumValueDescriptor extends GenericDescriptor
+ implements Internal.EnumLite {
+ /**
+ * Get the index of this descriptor within its parent.
+ * @see Descriptors.Descriptor#getIndex()
+ */
+ public int getIndex() { return index; }
+
+ /** Convert the descriptor to its protocol message representation. */
+ @Override
+ public EnumValueDescriptorProto toProto() {
+ return proto;
+ }
+
+ /** Get the value's unqualified name. */
+ @Override
+ public String getName() {
+ return proto.getName();
+ }
+
+ /** Get the value's number. */
+ @Override
+ public int getNumber() {
+ return proto.getNumber();
+ }
+
+ @Override
+ public String toString() { return proto.getName(); }
+
+ /**
+ * Get the value's fully-qualified name.
+ * @see Descriptors.Descriptor#getFullName()
+ */
+ @Override
+ public String getFullName() {
+ return fullName;
+ }
+
+ /** Get the {@link FileDescriptor} containing this descriptor. */
+ @Override
+ public FileDescriptor getFile() {
+ return file;
+ }
+
+ /** Get the value's enum type. */
+ public EnumDescriptor getType() { return type; }
+
+ /**
+ * Get the {@code EnumValueOptions}, defined in {@code descriptor.proto}.
+ */
+ public EnumValueOptions getOptions() { return proto.getOptions(); }
+
+ private final int index;
+ private EnumValueDescriptorProto proto;
+ private final String fullName;
+ private final FileDescriptor file;
+ private final EnumDescriptor type;
+
+ private EnumValueDescriptor(final EnumValueDescriptorProto proto,
+ final FileDescriptor file,
+ final EnumDescriptor parent,
+ final int index)
+ throws DescriptorValidationException {
+ this.index = index;
+ this.proto = proto;
+ this.file = file;
+ type = parent;
+
+ fullName = parent.getFullName() + '.' + proto.getName();
+
+ file.pool.addSymbol(this);
+ file.pool.addEnumValueByNumber(this);
+ }
+
+ private Integer number;
+ // Create an unknown enum value.
+ private EnumValueDescriptor(
+ final FileDescriptor file,
+ final EnumDescriptor parent,
+ final Integer number) {
+ String name = "UNKNOWN_ENUM_VALUE_" + parent.getName() + "_" + number;
+ EnumValueDescriptorProto proto = EnumValueDescriptorProto
+ .newBuilder().setName(name).setNumber(number).build();
+ this.index = -1;
+ this.proto = proto;
+ this.file = file;
+ this.type = parent;
+ this.fullName = parent.getFullName() + '.' + proto.getName();
+ this.number = number;
+
+ // Don't add this descriptor into pool.
+ }
+
+ /** See {@link FileDescriptor#setProto}. */
+ private void setProto(final EnumValueDescriptorProto proto) {
+ this.proto = proto;
+ }
+ }
+
+ // =================================================================
+
+ /** Describes a service type. */
+ public static final class ServiceDescriptor extends GenericDescriptor {
+ /**
+ * Get the index of this descriptor within its parent.
+ * * @see Descriptors.Descriptor#getIndex()
+ */
+ public int getIndex() { return index; }
+
+ /** Convert the descriptor to its protocol message representation. */
+ @Override
+ public ServiceDescriptorProto toProto() {
+ return proto;
+ }
+
+ /** Get the type's unqualified name. */
+ @Override
+ public String getName() {
+ return proto.getName();
+ }
+
+ /**
+ * Get the type's fully-qualified name.
+ * @see Descriptors.Descriptor#getFullName()
+ */
+ @Override
+ public String getFullName() {
+ return fullName;
+ }
+
+ /** Get the {@link FileDescriptor} containing this descriptor. */
+ @Override
+ public FileDescriptor getFile() {
+ return file;
+ }
+
+ /** Get the {@code ServiceOptions}, defined in {@code descriptor.proto}. */
+ public ServiceOptions getOptions() { return proto.getOptions(); }
+
+ /** Get a list of methods for this service. */
+ public List<MethodDescriptor> getMethods() {
+ return Collections.unmodifiableList(Arrays.asList(methods));
+ }
+
+ /**
+ * Find a method by name.
+ * @param name The unqualified name of the method (e.g. "Foo").
+ * @return the method's descriptor, or {@code null} if not found.
+ */
+ public MethodDescriptor findMethodByName(final String name) {
+ final GenericDescriptor result =
+ file.pool.findSymbol(fullName + '.' + name);
+ if (result != null && result instanceof MethodDescriptor) {
+ return (MethodDescriptor)result;
+ } else {
+ return null;
+ }
+ }
+
+ private final int index;
+ private ServiceDescriptorProto proto;
+ private final String fullName;
+ private final FileDescriptor file;
+ private MethodDescriptor[] methods;
+
+ private ServiceDescriptor(final ServiceDescriptorProto proto,
+ final FileDescriptor file,
+ final int index)
+ throws DescriptorValidationException {
+ this.index = index;
+ this.proto = proto;
+ fullName = computeFullName(file, null, proto.getName());
+ this.file = file;
+
+ methods = new MethodDescriptor[proto.getMethodCount()];
+ for (int i = 0; i < proto.getMethodCount(); i++) {
+ methods[i] = new MethodDescriptor(
+ proto.getMethod(i), file, this, i);
+ }
+
+ file.pool.addSymbol(this);
+ }
+
+ private void crossLink() throws DescriptorValidationException {
+ for (final MethodDescriptor method : methods) {
+ method.crossLink();
+ }
+ }
+
+ /** See {@link FileDescriptor#setProto}. */
+ private void setProto(final ServiceDescriptorProto proto) {
+ this.proto = proto;
+
+ for (int i = 0; i < methods.length; i++) {
+ methods[i].setProto(proto.getMethod(i));
+ }
+ }
+ }
+
+ // =================================================================
+
+ /**
+ * Describes one method within a service type.
+ */
+ public static final class MethodDescriptor extends GenericDescriptor {
+ /**
+ * Get the index of this descriptor within its parent.
+ * * @see Descriptors.Descriptor#getIndex()
+ */
+ public int getIndex() { return index; }
+
+ /** Convert the descriptor to its protocol message representation. */
+ @Override
+ public MethodDescriptorProto toProto() {
+ return proto;
+ }
+
+ /** Get the method's unqualified name. */
+ @Override
+ public String getName() {
+ return proto.getName();
+ }
+
+ /**
+ * Get the method's fully-qualified name.
+ * @see Descriptors.Descriptor#getFullName()
+ */
+ @Override
+ public String getFullName() {
+ return fullName;
+ }
+
+ /** Get the {@link FileDescriptor} containing this descriptor. */
+ @Override
+ public FileDescriptor getFile() {
+ return file;
+ }
+
+ /** Get the method's service type. */
+ public ServiceDescriptor getService() { return service; }
+
+ /** Get the method's input type. */
+ public Descriptor getInputType() { return inputType; }
+
+ /** Get the method's output type. */
+ public Descriptor getOutputType() { return outputType; }
+
+ /**
+ * Get the {@code MethodOptions}, defined in {@code descriptor.proto}.
+ */
+ public MethodOptions getOptions() { return proto.getOptions(); }
+
+ private final int index;
+ private MethodDescriptorProto proto;
+ private final String fullName;
+ private final FileDescriptor file;
+ private final ServiceDescriptor service;
+
+ // Initialized during cross-linking.
+ private Descriptor inputType;
+ private Descriptor outputType;
+
+ private MethodDescriptor(final MethodDescriptorProto proto,
+ final FileDescriptor file,
+ final ServiceDescriptor parent,
+ final int index)
+ throws DescriptorValidationException {
+ this.index = index;
+ this.proto = proto;
+ this.file = file;
+ service = parent;
+
+ fullName = parent.getFullName() + '.' + proto.getName();
+
+ file.pool.addSymbol(this);
+ }
+
+ private void crossLink() throws DescriptorValidationException {
+ final GenericDescriptor input =
+ file.pool.lookupSymbol(proto.getInputType(), this,
+ DescriptorPool.SearchFilter.TYPES_ONLY);
+ if (!(input instanceof Descriptor)) {
+ throw new DescriptorValidationException(this,
+ '\"' + proto.getInputType() + "\" is not a message type.");
+ }
+ inputType = (Descriptor)input;
+
+ final GenericDescriptor output =
+ file.pool.lookupSymbol(proto.getOutputType(), this,
+ DescriptorPool.SearchFilter.TYPES_ONLY);
+ if (!(output instanceof Descriptor)) {
+ throw new DescriptorValidationException(this,
+ '\"' + proto.getOutputType() + "\" is not a message type.");
+ }
+ outputType = (Descriptor)output;
+ }
+
+ /** See {@link FileDescriptor#setProto}. */
+ private void setProto(final MethodDescriptorProto proto) {
+ this.proto = proto;
+ }
+ }
+
+ // =================================================================
+
+ private static String computeFullName(final FileDescriptor file,
+ final Descriptor parent,
+ final String name) {
+ if (parent != null) {
+ return parent.getFullName() + '.' + name;
+ } else if (file.getPackage().length() > 0) {
+ return file.getPackage() + '.' + name;
+ } else {
+ return name;
+ }
+ }
+
+ // =================================================================
+
+ /**
+ * All descriptors implement this to make it easier to implement tools like
+ * {@code DescriptorPool}.<p>
+ *
+ * This class is public so that the methods it exposes can be called from
+ * outside of this package. However, it should only be subclassed from
+ * nested classes of Descriptors.
+ */
+ public abstract static class GenericDescriptor {
+ public abstract Message toProto();
+ public abstract String getName();
+ public abstract String getFullName();
+ public abstract FileDescriptor getFile();
+ }
+
+ /**
+ * Thrown when building descriptors fails because the source DescriptorProtos
+ * are not valid.
+ */
+ public static class DescriptorValidationException extends Exception {
+ private static final long serialVersionUID = 5750205775490483148L;
+
+ /** Gets the full name of the descriptor where the error occurred. */
+ public String getProblemSymbolName() { return name; }
+
+ /**
+ * Gets the protocol message representation of the invalid descriptor.
+ */
+ public Message getProblemProto() { return proto; }
+
+ /**
+ * Gets a human-readable description of the error.
+ */
+ public String getDescription() { return description; }
+
+ private final String name;
+ private final Message proto;
+ private final String description;
+
+ private DescriptorValidationException(
+ final GenericDescriptor problemDescriptor,
+ final String description) {
+ super(problemDescriptor.getFullName() + ": " + description);
+
+ // Note that problemDescriptor may be partially uninitialized, so we
+ // don't want to expose it directly to the user. So, we only provide
+ // the name and the original proto.
+ name = problemDescriptor.getFullName();
+ proto = problemDescriptor.toProto();
+ this.description = description;
+ }
+
+ private DescriptorValidationException(
+ final GenericDescriptor problemDescriptor,
+ final String description,
+ final Throwable cause) {
+ this(problemDescriptor, description);
+ initCause(cause);
+ }
+
+ private DescriptorValidationException(
+ final FileDescriptor problemDescriptor,
+ final String description) {
+ super(problemDescriptor.getName() + ": " + description);
+
+ // Note that problemDescriptor may be partially uninitialized, so we
+ // don't want to expose it directly to the user. So, we only provide
+ // the name and the original proto.
+ name = problemDescriptor.getName();
+ proto = problemDescriptor.toProto();
+ this.description = description;
+ }
+ }
+
+ // =================================================================
+
+ /**
+ * A private helper class which contains lookup tables containing all the
+ * descriptors defined in a particular file.
+ */
+ private static final class DescriptorPool {
+
+ /** Defines what subclass of descriptors to search in the descriptor pool.
+ */
+ enum SearchFilter {
+ TYPES_ONLY, AGGREGATES_ONLY, ALL_SYMBOLS
+ }
+
+ DescriptorPool(final FileDescriptor[] dependencies,
+ boolean allowUnknownDependencies) {
+ this.dependencies = new HashSet<FileDescriptor>();
+ this.allowUnknownDependencies = allowUnknownDependencies;
+
+ for (int i = 0; i < dependencies.length; i++) {
+ this.dependencies.add(dependencies[i]);
+ importPublicDependencies(dependencies[i]);
+ }
+
+ for (final FileDescriptor dependency : this.dependencies) {
+ try {
+ addPackage(dependency.getPackage(), dependency);
+ } catch (DescriptorValidationException e) {
+ // Can't happen, because addPackage() only fails when the name
+ // conflicts with a non-package, but we have not yet added any
+ // non-packages at this point.
+ throw new AssertionError(e);
+ }
+ }
+ }
+
+ /** Find and put public dependencies of the file into dependencies set.*/
+ private void importPublicDependencies(final FileDescriptor file) {
+ for (FileDescriptor dependency : file.getPublicDependencies()) {
+ if (dependencies.add(dependency)) {
+ importPublicDependencies(dependency);
+ }
+ }
+ }
+
+ private final Set<FileDescriptor> dependencies;
+ private boolean allowUnknownDependencies;
+
+ private final Map<String, GenericDescriptor> descriptorsByName =
+ new HashMap<String, GenericDescriptor>();
+ private final Map<DescriptorIntPair, FieldDescriptor> fieldsByNumber =
+ new HashMap<DescriptorIntPair, FieldDescriptor>();
+ private final Map<DescriptorIntPair, EnumValueDescriptor> enumValuesByNumber
+ = new HashMap<DescriptorIntPair, EnumValueDescriptor>();
+
+ /** Find a generic descriptor by fully-qualified name. */
+ GenericDescriptor findSymbol(final String fullName) {
+ return findSymbol(fullName, SearchFilter.ALL_SYMBOLS);
+ }
+
+ /** Find a descriptor by fully-qualified name and given option to only
+ * search valid field type descriptors.
+ */
+ GenericDescriptor findSymbol(final String fullName,
+ final SearchFilter filter) {
+ GenericDescriptor result = descriptorsByName.get(fullName);
+ if (result != null) {
+ if ((filter==SearchFilter.ALL_SYMBOLS) ||
+ ((filter==SearchFilter.TYPES_ONLY) && isType(result)) ||
+ ((filter==SearchFilter.AGGREGATES_ONLY) && isAggregate(result))) {
+ return result;
+ }
+ }
+
+ for (final FileDescriptor dependency : dependencies) {
+ result = dependency.pool.descriptorsByName.get(fullName);
+ if (result != null) {
+ if ((filter==SearchFilter.ALL_SYMBOLS) ||
+ ((filter==SearchFilter.TYPES_ONLY) && isType(result)) ||
+ ((filter==SearchFilter.AGGREGATES_ONLY) && isAggregate(result))) {
+ return result;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /** Checks if the descriptor is a valid type for a message field. */
+ boolean isType(GenericDescriptor descriptor) {
+ return (descriptor instanceof Descriptor) ||
+ (descriptor instanceof EnumDescriptor);
+ }
+
+ /** Checks if the descriptor is a valid namespace type. */
+ boolean isAggregate(GenericDescriptor descriptor) {
+ return (descriptor instanceof Descriptor) ||
+ (descriptor instanceof EnumDescriptor) ||
+ (descriptor instanceof PackageDescriptor) ||
+ (descriptor instanceof ServiceDescriptor);
+ }
+
+ /**
+ * Look up a type descriptor by name, relative to some other descriptor.
+ * The name may be fully-qualified (with a leading '.'),
+ * partially-qualified, or unqualified. C++-like name lookup semantics
+ * are used to search for the matching descriptor.
+ */
+ GenericDescriptor lookupSymbol(final String name,
+ final GenericDescriptor relativeTo,
+ final DescriptorPool.SearchFilter filter)
+ throws DescriptorValidationException {
+ // TODO(kenton): This could be optimized in a number of ways.
+
+ GenericDescriptor result;
+ String fullname;
+ if (name.startsWith(".")) {
+ // Fully-qualified name.
+ fullname = name.substring(1);
+ result = findSymbol(fullname, filter);
+ } else {
+ // If "name" is a compound identifier, we want to search for the
+ // first component of it, then search within it for the rest.
+ // If name is something like "Foo.Bar.baz", and symbols named "Foo" are
+ // defined in multiple parent scopes, we only want to find "Bar.baz" in
+ // the innermost one. E.g., the following should produce an error:
+ // message Bar { message Baz {} }
+ // message Foo {
+ // message Bar {
+ // }
+ // optional Bar.Baz baz = 1;
+ // }
+ // So, we look for just "Foo" first, then look for "Bar.baz" within it
+ // if found.
+ final int firstPartLength = name.indexOf('.');
+ final String firstPart;
+ if (firstPartLength == -1) {
+ firstPart = name;
+ } else {
+ firstPart = name.substring(0, firstPartLength);
+ }
+
+ // We will search each parent scope of "relativeTo" looking for the
+ // symbol.
+ final StringBuilder scopeToTry =
+ new StringBuilder(relativeTo.getFullName());
+
+ while (true) {
+ // Chop off the last component of the scope.
+ final int dotpos = scopeToTry.lastIndexOf(".");
+ if (dotpos == -1) {
+ fullname = name;
+ result = findSymbol(name, filter);
+ break;
+ } else {
+ scopeToTry.setLength(dotpos + 1);
+
+ // Append firstPart and try to find
+ scopeToTry.append(firstPart);
+ result = findSymbol(scopeToTry.toString(),
+ DescriptorPool.SearchFilter.AGGREGATES_ONLY);
+
+ if (result != null) {
+ if (firstPartLength != -1) {
+ // We only found the first part of the symbol. Now look for
+ // the whole thing. If this fails, we *don't* want to keep
+ // searching parent scopes.
+ scopeToTry.setLength(dotpos + 1);
+ scopeToTry.append(name);
+ result = findSymbol(scopeToTry.toString(), filter);
+ }
+ fullname = scopeToTry.toString();
+ break;
+ }
+
+ // Not found. Remove the name so we can try again.
+ scopeToTry.setLength(dotpos);
+ }
+ }
+ }
+
+ if (result == null) {
+ if (allowUnknownDependencies && filter == SearchFilter.TYPES_ONLY) {
+ logger.warning("The descriptor for message type \"" + name +
+ "\" can not be found and a placeholder is created for it");
+ // We create a dummy message descriptor here regardless of the
+ // expected type. If the type should be message, this dummy
+ // descriptor will work well and if the type should be enum, a
+ // DescriptorValidationException will be thrown latter. In either
+ // case, the code works as expected: we allow unknown message types
+ // but not unknwon enum types.
+ result = new Descriptor(fullname);
+ // Add the placeholder file as a dependency so we can find the
+ // placeholder symbol when resolving other references.
+ this.dependencies.add(result.getFile());
+ return result;
+ } else {
+ throw new DescriptorValidationException(relativeTo,
+ '\"' + name + "\" is not defined.");
+ }
+ } else {
+ return result;
+ }
+ }
+
+ /**
+ * Adds a symbol to the symbol table. If a symbol with the same name
+ * already exists, throws an error.
+ */
+ void addSymbol(final GenericDescriptor descriptor)
+ throws DescriptorValidationException {
+ validateSymbolName(descriptor);
+
+ final String fullName = descriptor.getFullName();
+ final int dotpos = fullName.lastIndexOf('.');
+
+ final GenericDescriptor old = descriptorsByName.put(fullName, descriptor);
+ if (old != null) {
+ descriptorsByName.put(fullName, old);
+
+ if (descriptor.getFile() == old.getFile()) {
+ if (dotpos == -1) {
+ throw new DescriptorValidationException(descriptor,
+ '\"' + fullName + "\" is already defined.");
+ } else {
+ throw new DescriptorValidationException(descriptor,
+ '\"' + fullName.substring(dotpos + 1) +
+ "\" is already defined in \"" +
+ fullName.substring(0, dotpos) + "\".");
+ }
+ } else {
+ throw new DescriptorValidationException(descriptor,
+ '\"' + fullName + "\" is already defined in file \"" +
+ old.getFile().getName() + "\".");
+ }
+ }
+ }
+
+ /**
+ * Represents a package in the symbol table. We use PackageDescriptors
+ * just as placeholders so that someone cannot define, say, a message type
+ * that has the same name as an existing package.
+ */
+ private static final class PackageDescriptor extends GenericDescriptor {
+ @Override
+ public Message toProto() {
+ return file.toProto();
+ }
+ @Override
+ public String getName() {
+ return name;
+ }
+ @Override
+ public String getFullName() {
+ return fullName;
+ }
+ @Override
+ public FileDescriptor getFile() {
+ return file;
+ }
+
+ PackageDescriptor(final String name, final String fullName,
+ final FileDescriptor file) {
+ this.file = file;
+ this.fullName = fullName;
+ this.name = name;
+ }
+
+ private final String name;
+ private final String fullName;
+ private final FileDescriptor file;
+ }
+
+ /**
+ * Adds a package to the symbol tables. If a package by the same name
+ * already exists, that is fine, but if some other kind of symbol exists
+ * under the same name, an exception is thrown. If the package has
+ * multiple components, this also adds the parent package(s).
+ */
+ void addPackage(final String fullName, final FileDescriptor file)
+ throws DescriptorValidationException {
+ final int dotpos = fullName.lastIndexOf('.');
+ final String name;
+ if (dotpos == -1) {
+ name = fullName;
+ } else {
+ addPackage(fullName.substring(0, dotpos), file);
+ name = fullName.substring(dotpos + 1);
+ }
+
+ final GenericDescriptor old =
+ descriptorsByName.put(fullName,
+ new PackageDescriptor(name, fullName, file));
+ if (old != null) {
+ descriptorsByName.put(fullName, old);
+ if (!(old instanceof PackageDescriptor)) {
+ throw new DescriptorValidationException(file,
+ '\"' + name + "\" is already defined (as something other than a "
+ + "package) in file \"" + old.getFile().getName() + "\".");
+ }
+ }
+ }
+
+ /** A (GenericDescriptor, int) pair, used as a map key. */
+ private static final class DescriptorIntPair {
+ private final GenericDescriptor descriptor;
+ private final int number;
+
+ DescriptorIntPair(final GenericDescriptor descriptor, final int number) {
+ this.descriptor = descriptor;
+ this.number = number;
+ }
+
+ @Override
+ public int hashCode() {
+ return descriptor.hashCode() * ((1 << 16) - 1) + number;
+ }
+ @Override
+ public boolean equals(final Object obj) {
+ if (!(obj instanceof DescriptorIntPair)) {
+ return false;
+ }
+ final DescriptorIntPair other = (DescriptorIntPair)obj;
+ return descriptor == other.descriptor && number == other.number;
+ }
+ }
+
+ /**
+ * Adds a field to the fieldsByNumber table. Throws an exception if a
+ * field with the same containing type and number already exists.
+ */
+ void addFieldByNumber(final FieldDescriptor field)
+ throws DescriptorValidationException {
+ final DescriptorIntPair key =
+ new DescriptorIntPair(field.getContainingType(), field.getNumber());
+ final FieldDescriptor old = fieldsByNumber.put(key, field);
+ if (old != null) {
+ fieldsByNumber.put(key, old);
+ throw new DescriptorValidationException(field,
+ "Field number " + field.getNumber() +
+ " has already been used in \"" +
+ field.getContainingType().getFullName() +
+ "\" by field \"" + old.getName() + "\".");
+ }
+ }
+
+ /**
+ * Adds an enum value to the enumValuesByNumber table. If an enum value
+ * with the same type and number already exists, does nothing. (This is
+ * allowed; the first value define with the number takes precedence.)
+ */
+ void addEnumValueByNumber(final EnumValueDescriptor value) {
+ final DescriptorIntPair key =
+ new DescriptorIntPair(value.getType(), value.getNumber());
+ final EnumValueDescriptor old = enumValuesByNumber.put(key, value);
+ if (old != null) {
+ enumValuesByNumber.put(key, old);
+ // Not an error: Multiple enum values may have the same number, but
+ // we only want the first one in the map.
+ }
+ }
+
+ /**
+ * Verifies that the descriptor's name is valid (i.e. it contains only
+ * letters, digits, and underscores, and does not start with a digit).
+ */
+ static void validateSymbolName(final GenericDescriptor descriptor)
+ throws DescriptorValidationException {
+ final String name = descriptor.getName();
+ if (name.length() == 0) {
+ throw new DescriptorValidationException(descriptor, "Missing name.");
+ } else {
+ boolean valid = true;
+ for (int i = 0; i < name.length(); i++) {
+ final char c = name.charAt(i);
+ // Non-ASCII characters are not valid in protobuf identifiers, even
+ // if they are letters or digits.
+ if (c >= 128) {
+ valid = false;
+ }
+ // First character must be letter or _. Subsequent characters may
+ // be letters, numbers, or digits.
+ if (Character.isLetter(c) || c == '_' ||
+ (Character.isDigit(c) && i > 0)) {
+ // Valid
+ } else {
+ valid = false;
+ }
+ }
+ if (!valid) {
+ throw new DescriptorValidationException(descriptor,
+ '\"' + name + "\" is not a valid identifier.");
+ }
+ }
+ }
+ }
+
+ /** Describes an oneof of a message type. */
+ public static final class OneofDescriptor {
+ /** Get the index of this descriptor within its parent. */
+ public int getIndex() { return index; }
+
+ public String getName() { return proto.getName(); }
+
+ public FileDescriptor getFile() { return file; }
+
+ public String getFullName() { return fullName; }
+
+ public Descriptor getContainingType() { return containingType; }
+
+ public int getFieldCount() { return fieldCount; }
+
+ public OneofOptions getOptions() {
+ return proto.getOptions();
+ }
+
+ /** Get a list of this message type's fields. */
+ public List<FieldDescriptor> getFields() {
+ return Collections.unmodifiableList(Arrays.asList(fields));
+ }
+
+ public FieldDescriptor getField(int index) {
+ return fields[index];
+ }
+
+ private void setProto(final OneofDescriptorProto proto) {
+ this.proto = proto;
+ }
+
+ private OneofDescriptor(final OneofDescriptorProto proto,
+ final FileDescriptor file,
+ final Descriptor parent,
+ final int index)
+ throws DescriptorValidationException {
+ this.proto = proto;
+ fullName = computeFullName(file, parent, proto.getName());
+ this.file = file;
+ this.index = index;
+
+ containingType = parent;
+ fieldCount = 0;
+ }
+
+ private final int index;
+ private OneofDescriptorProto proto;
+ private final String fullName;
+ private final FileDescriptor file;
+
+ private Descriptor containingType;
+ private int fieldCount;
+ private FieldDescriptor[] fields;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java
new file mode 100644
index 0000000000..6177f3cab9
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/DoubleArrayList.java
@@ -0,0 +1,273 @@
+// 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.DoubleList;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.RandomAccess;
+
+/**
+ * An implementation of {@link DoubleList} on top of a primitive array.
+ *
+ * @author dweis@google.com (Daniel Weis)
+ */
+final class DoubleArrayList
+ extends AbstractProtobufList<Double>
+ implements DoubleList, RandomAccess {
+
+ private static final DoubleArrayList EMPTY_LIST = new DoubleArrayList();
+ static {
+ EMPTY_LIST.makeImmutable();
+ }
+
+ public static DoubleArrayList emptyList() {
+ return EMPTY_LIST;
+ }
+
+ /**
+ * The backing store for the list.
+ */
+ private double[] array;
+
+ /**
+ * The size of the list distinct from the length of the array. That is, it is the number of
+ * elements set in the list.
+ */
+ private int size;
+
+ /**
+ * Constructs a new mutable {@code DoubleArrayList} with default capacity.
+ */
+ DoubleArrayList() {
+ this(new double[DEFAULT_CAPACITY], 0);
+ }
+
+ /**
+ * Constructs a new mutable {@code DoubleArrayList}
+ * containing the same elements as {@code other}.
+ */
+ private DoubleArrayList(double[] other, int size) {
+ array = other;
+ this.size = size;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof DoubleArrayList)) {
+ return super.equals(o);
+ }
+ DoubleArrayList other = (DoubleArrayList) o;
+ if (size != other.size) {
+ return false;
+ }
+
+ final double[] arr = other.array;
+ for (int i = 0; i < size; i++) {
+ if (array[i] != arr[i]) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 1;
+ for (int i = 0; i < size; i++) {
+ long bits = Double.doubleToLongBits(array[i]);
+ result = (31 * result) + Internal.hashLong(bits);
+ }
+ return result;
+ }
+
+ @Override
+ public DoubleList mutableCopyWithCapacity(int capacity) {
+ if (capacity < size) {
+ throw new IllegalArgumentException();
+ }
+ return new DoubleArrayList(Arrays.copyOf(array, capacity), size);
+ }
+
+ @Override
+ public Double get(int index) {
+ return getDouble(index);
+ }
+
+ @Override
+ public double getDouble(int index) {
+ ensureIndexInRange(index);
+ return array[index];
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public Double set(int index, Double element) {
+ return setDouble(index, element);
+ }
+
+ @Override
+ public double setDouble(int index, double element) {
+ ensureIsMutable();
+ ensureIndexInRange(index);
+ double previousValue = array[index];
+ array[index] = element;
+ return previousValue;
+ }
+
+ @Override
+ public void add(int index, Double element) {
+ addDouble(index, element);
+ }
+
+ /**
+ * Like {@link #add(Double)} but more efficient in that it doesn't box the element.
+ */
+ @Override
+ public void addDouble(double element) {
+ addDouble(size, element);
+ }
+
+ /**
+ * Like {@link #add(int, Double)} but more efficient in that it doesn't box the element.
+ */
+ private void addDouble(int index, double element) {
+ ensureIsMutable();
+ if (index < 0 || index > size) {
+ throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index));
+ }
+
+ if (size < array.length) {
+ // Shift everything over to make room
+ System.arraycopy(array, index, array, index + 1, size - index);
+ } else {
+ // Resize to 1.5x the size
+ int length = ((size * 3) / 2) + 1;
+ double[] newArray = new double[length];
+
+ // Copy the first part directly
+ System.arraycopy(array, 0, newArray, 0, index);
+
+ // Copy the rest shifted over by one to make room
+ System.arraycopy(array, index, newArray, index + 1, size - index);
+ array = newArray;
+ }
+
+ array[index] = element;
+ size++;
+ modCount++;
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends Double> collection) {
+ ensureIsMutable();
+
+ if (collection == null) {
+ throw new NullPointerException();
+ }
+
+ // We specialize when adding another DoubleArrayList to avoid boxing elements.
+ if (!(collection instanceof DoubleArrayList)) {
+ return super.addAll(collection);
+ }
+
+ DoubleArrayList list = (DoubleArrayList) collection;
+ if (list.size == 0) {
+ return false;
+ }
+
+ int overflow = Integer.MAX_VALUE - size;
+ if (overflow < list.size) {
+ // We can't actually represent a list this large.
+ throw new OutOfMemoryError();
+ }
+
+ int newSize = size + list.size;
+ if (newSize > array.length) {
+ array = Arrays.copyOf(array, newSize);
+ }
+
+ System.arraycopy(list.array, 0, array, size, list.size);
+ size = newSize;
+ modCount++;
+ return true;
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ ensureIsMutable();
+ for (int i = 0; i < size; i++) {
+ if (o.equals(array[i])) {
+ System.arraycopy(array, i + 1, array, i, size - i);
+ size--;
+ modCount++;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public Double remove(int index) {
+ ensureIsMutable();
+ ensureIndexInRange(index);
+ double value = array[index];
+ System.arraycopy(array, index + 1, array, index, size - index);
+ size--;
+ modCount++;
+ return value;
+ }
+
+ /**
+ * Ensures that the provided {@code index} is within the range of {@code [0, size]}. Throws an
+ * {@link IndexOutOfBoundsException} if it is not.
+ *
+ * @param index the index to verify is in range
+ */
+ private void ensureIndexInRange(int index) {
+ if (index < 0 || index >= size) {
+ throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index));
+ }
+ }
+
+ private String makeOutOfBoundsExceptionMessage(int index) {
+ return "Index:" + index + ", Size:" + size;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/DynamicMessage.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/DynamicMessage.java
new file mode 100644
index 0000000000..e6358c3bae
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/DynamicMessage.java
@@ -0,0 +1,684 @@
+// 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.Descriptor;
+import com.google.protobuf.Descriptors.EnumValueDescriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+import com.google.protobuf.Descriptors.OneofDescriptor;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * An implementation of {@link Message} that can represent arbitrary types,
+ * given a {@link Descriptors.Descriptor}.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public final class DynamicMessage extends AbstractMessage {
+ private final Descriptor type;
+ private final FieldSet<FieldDescriptor> fields;
+ private final FieldDescriptor[] oneofCases;
+ private final UnknownFieldSet unknownFields;
+ private int memoizedSize = -1;
+
+ /**
+ * Construct a {@code DynamicMessage} using the given {@code FieldSet}.
+ * oneofCases stores the FieldDescriptor for each oneof to indicate
+ * which field is set. Caller should make sure the array is immutable.
+ *
+ * This constructor is package private and will be used in
+ * {@code DynamicMutableMessage} to convert a mutable message to an immutable
+ * message.
+ */
+ DynamicMessage(Descriptor type, FieldSet<FieldDescriptor> fields,
+ FieldDescriptor[] oneofCases,
+ UnknownFieldSet unknownFields) {
+ this.type = type;
+ this.fields = fields;
+ this.oneofCases = oneofCases;
+ this.unknownFields = unknownFields;
+ }
+
+ /**
+ * Get a {@code DynamicMessage} representing the default instance of the
+ * given type.
+ */
+ public static DynamicMessage getDefaultInstance(Descriptor type) {
+ int oneofDeclCount = type.toProto().getOneofDeclCount();
+ FieldDescriptor[] oneofCases = new FieldDescriptor[oneofDeclCount];
+ return new DynamicMessage(type, FieldSet.<FieldDescriptor>emptySet(),
+ oneofCases,
+ UnknownFieldSet.getDefaultInstance());
+ }
+
+
+ /** Parse a message of the given type from the given input stream. */
+ public static DynamicMessage parseFrom(Descriptor type,
+ CodedInputStream input)
+ throws IOException {
+ return newBuilder(type).mergeFrom(input).buildParsed();
+ }
+
+ /** Parse a message of the given type from the given input stream. */
+ public static DynamicMessage parseFrom(
+ Descriptor type,
+ CodedInputStream input,
+ ExtensionRegistry extensionRegistry)
+ throws IOException {
+ return newBuilder(type).mergeFrom(input, extensionRegistry).buildParsed();
+ }
+
+ /** Parse {@code data} as a message of the given type and return it. */
+ public static DynamicMessage parseFrom(Descriptor type, ByteString data)
+ throws InvalidProtocolBufferException {
+ return newBuilder(type).mergeFrom(data).buildParsed();
+ }
+
+ /** Parse {@code data} as a message of the given type and return it. */
+ public static DynamicMessage parseFrom(Descriptor type, ByteString data,
+ ExtensionRegistry extensionRegistry)
+ throws InvalidProtocolBufferException {
+ return newBuilder(type).mergeFrom(data, extensionRegistry).buildParsed();
+ }
+
+ /** Parse {@code data} as a message of the given type and return it. */
+ public static DynamicMessage parseFrom(Descriptor type, byte[] data)
+ throws InvalidProtocolBufferException {
+ return newBuilder(type).mergeFrom(data).buildParsed();
+ }
+
+ /** Parse {@code data} as a message of the given type and return it. */
+ public static DynamicMessage parseFrom(Descriptor type, byte[] data,
+ ExtensionRegistry extensionRegistry)
+ throws InvalidProtocolBufferException {
+ return newBuilder(type).mergeFrom(data, extensionRegistry).buildParsed();
+ }
+
+ /** Parse a message of the given type from {@code input} and return it. */
+ public static DynamicMessage parseFrom(Descriptor type, InputStream input)
+ throws IOException {
+ return newBuilder(type).mergeFrom(input).buildParsed();
+ }
+
+ /** Parse a message of the given type from {@code input} and return it. */
+ public static DynamicMessage parseFrom(Descriptor type, InputStream input,
+ ExtensionRegistry extensionRegistry)
+ throws IOException {
+ return newBuilder(type).mergeFrom(input, extensionRegistry).buildParsed();
+ }
+
+ /** Construct a {@link Message.Builder} for the given type. */
+ public static Builder newBuilder(Descriptor type) {
+ return new Builder(type);
+ }
+
+ /**
+ * Construct a {@link Message.Builder} for a message of the same type as
+ * {@code prototype}, and initialize it with {@code prototype}'s contents.
+ */
+ public static Builder newBuilder(Message prototype) {
+ return new Builder(prototype.getDescriptorForType()).mergeFrom(prototype);
+ }
+
+ // -----------------------------------------------------------------
+ // Implementation of Message interface.
+
+ @Override
+ public Descriptor getDescriptorForType() {
+ return type;
+ }
+
+ @Override
+ public DynamicMessage getDefaultInstanceForType() {
+ return getDefaultInstance(type);
+ }
+
+ @Override
+ public Map<FieldDescriptor, Object> getAllFields() {
+ return fields.getAllFields();
+ }
+
+ @Override
+ public boolean hasOneof(OneofDescriptor oneof) {
+ verifyOneofContainingType(oneof);
+ FieldDescriptor field = oneofCases[oneof.getIndex()];
+ if (field == null) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) {
+ verifyOneofContainingType(oneof);
+ return oneofCases[oneof.getIndex()];
+ }
+
+ @Override
+ public boolean hasField(FieldDescriptor field) {
+ verifyContainingType(field);
+ return fields.hasField(field);
+ }
+
+ @Override
+ public Object getField(FieldDescriptor field) {
+ verifyContainingType(field);
+ Object result = fields.getField(field);
+ if (result == null) {
+ if (field.isRepeated()) {
+ result = Collections.emptyList();
+ } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ result = getDefaultInstance(field.getMessageType());
+ } else {
+ result = field.getDefaultValue();
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public int getRepeatedFieldCount(FieldDescriptor field) {
+ verifyContainingType(field);
+ return fields.getRepeatedFieldCount(field);
+ }
+
+ @Override
+ public Object getRepeatedField(FieldDescriptor field, int index) {
+ verifyContainingType(field);
+ return fields.getRepeatedField(field, index);
+ }
+
+ @Override
+ public UnknownFieldSet getUnknownFields() {
+ return unknownFields;
+ }
+
+ static boolean isInitialized(Descriptor type,
+ FieldSet<FieldDescriptor> fields) {
+ // Check that all required fields are present.
+ for (final FieldDescriptor field : type.getFields()) {
+ if (field.isRequired()) {
+ if (!fields.hasField(field)) {
+ return false;
+ }
+ }
+ }
+
+ // Check that embedded messages are initialized.
+ return fields.isInitialized();
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return isInitialized(type, fields);
+ }
+
+ @Override
+ public void writeTo(CodedOutputStream output) throws IOException {
+ if (type.getOptions().getMessageSetWireFormat()) {
+ fields.writeMessageSetTo(output);
+ unknownFields.writeAsMessageSetTo(output);
+ } else {
+ fields.writeTo(output);
+ unknownFields.writeTo(output);
+ }
+ }
+
+ @Override
+ public int getSerializedSize() {
+ int size = memoizedSize;
+ if (size != -1) return size;
+
+ if (type.getOptions().getMessageSetWireFormat()) {
+ size = fields.getMessageSetSerializedSize();
+ size += unknownFields.getSerializedSizeAsMessageSet();
+ } else {
+ size = fields.getSerializedSize();
+ size += unknownFields.getSerializedSize();
+ }
+
+ memoizedSize = size;
+ return size;
+ }
+
+ @Override
+ public Builder newBuilderForType() {
+ return new Builder(type);
+ }
+
+ @Override
+ public Builder toBuilder() {
+ return newBuilderForType().mergeFrom(this);
+ }
+
+ @Override
+ public Parser<DynamicMessage> getParserForType() {
+ return new AbstractParser<DynamicMessage>() {
+ @Override
+ public DynamicMessage parsePartialFrom(
+ CodedInputStream input, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ Builder builder = newBuilder(type);
+ try {
+ builder.mergeFrom(input, extensionRegistry);
+ } catch (InvalidProtocolBufferException e) {
+ throw e.setUnfinishedMessage(builder.buildPartial());
+ } catch (IOException e) {
+ throw new InvalidProtocolBufferException(e)
+ .setUnfinishedMessage(builder.buildPartial());
+ }
+ return builder.buildPartial();
+ }
+ };
+ }
+
+ /** Verifies that the field is a field of this message. */
+ private void verifyContainingType(FieldDescriptor field) {
+ if (field.getContainingType() != type) {
+ throw new IllegalArgumentException(
+ "FieldDescriptor does not match message type.");
+ }
+ }
+
+ /** Verifies that the oneof is an oneof of this message. */
+ private void verifyOneofContainingType(OneofDescriptor oneof) {
+ if (oneof.getContainingType() != type) {
+ throw new IllegalArgumentException(
+ "OneofDescriptor does not match message type.");
+ }
+ }
+
+ // =================================================================
+
+ /**
+ * Builder for {@link DynamicMessage}s.
+ */
+ public static final class Builder extends AbstractMessage.Builder<Builder> {
+ private final Descriptor type;
+ private FieldSet<FieldDescriptor> fields;
+ private final FieldDescriptor[] oneofCases;
+ private UnknownFieldSet unknownFields;
+
+ /** Construct a {@code Builder} for the given type. */
+ private Builder(Descriptor type) {
+ this.type = type;
+ this.fields = FieldSet.newFieldSet();
+ this.unknownFields = UnknownFieldSet.getDefaultInstance();
+ this.oneofCases = new FieldDescriptor[type.toProto().getOneofDeclCount()];
+ }
+
+ // ---------------------------------------------------------------
+ // Implementation of Message.Builder interface.
+
+ @Override
+ public Builder clear() {
+ if (fields.isImmutable()) {
+ fields = FieldSet.newFieldSet();
+ } else {
+ fields.clear();
+ }
+ unknownFields = UnknownFieldSet.getDefaultInstance();
+ return this;
+ }
+
+ @Override
+ public Builder mergeFrom(Message other) {
+ if (other instanceof DynamicMessage) {
+ // This should be somewhat faster than calling super.mergeFrom().
+ DynamicMessage otherDynamicMessage = (DynamicMessage) other;
+ if (otherDynamicMessage.type != type) {
+ throw new IllegalArgumentException(
+ "mergeFrom(Message) can only merge messages of the same type.");
+ }
+ ensureIsMutable();
+ fields.mergeFrom(otherDynamicMessage.fields);
+ mergeUnknownFields(otherDynamicMessage.unknownFields);
+ for (int i = 0; i < oneofCases.length; i++) {
+ if (oneofCases[i] == null) {
+ oneofCases[i] = otherDynamicMessage.oneofCases[i];
+ } else {
+ if ((otherDynamicMessage.oneofCases[i] != null)
+ && (oneofCases[i] != otherDynamicMessage.oneofCases[i])) {
+ fields.clearField(oneofCases[i]);
+ oneofCases[i] = otherDynamicMessage.oneofCases[i];
+ }
+ }
+ }
+ return this;
+ } else {
+ return super.mergeFrom(other);
+ }
+ }
+
+ @Override
+ public DynamicMessage build() {
+ if (!isInitialized()) {
+ throw newUninitializedMessageException(
+ new DynamicMessage(type, fields,
+ java.util.Arrays.copyOf(oneofCases, oneofCases.length), unknownFields));
+ }
+ return buildPartial();
+ }
+
+ /**
+ * Helper for DynamicMessage.parseFrom() methods to call. Throws
+ * {@link InvalidProtocolBufferException} instead of
+ * {@link UninitializedMessageException}.
+ */
+ private DynamicMessage buildParsed() throws InvalidProtocolBufferException {
+ if (!isInitialized()) {
+ throw newUninitializedMessageException(
+ new DynamicMessage(type, fields,
+ java.util.Arrays.copyOf(oneofCases, oneofCases.length), unknownFields))
+ .asInvalidProtocolBufferException();
+ }
+ return buildPartial();
+ }
+
+ @Override
+ public DynamicMessage buildPartial() {
+ fields.makeImmutable();
+ DynamicMessage result =
+ new DynamicMessage(type, fields,
+ java.util.Arrays.copyOf(oneofCases, oneofCases.length), unknownFields);
+ return result;
+ }
+
+ @Override
+ public Builder clone() {
+ Builder result = new Builder(type);
+ result.fields.mergeFrom(fields);
+ result.mergeUnknownFields(unknownFields);
+ System.arraycopy(oneofCases, 0, result.oneofCases, 0 , oneofCases.length);
+ return result;
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return DynamicMessage.isInitialized(type, fields);
+ }
+
+ @Override
+ public Descriptor getDescriptorForType() {
+ return type;
+ }
+
+ @Override
+ public DynamicMessage getDefaultInstanceForType() {
+ return getDefaultInstance(type);
+ }
+
+ @Override
+ public Map<FieldDescriptor, Object> getAllFields() {
+ return fields.getAllFields();
+ }
+
+ @Override
+ public Builder newBuilderForField(FieldDescriptor field) {
+ verifyContainingType(field);
+
+ if (field.getJavaType() != FieldDescriptor.JavaType.MESSAGE) {
+ throw new IllegalArgumentException(
+ "newBuilderForField is only valid for fields with message type.");
+ }
+
+ return new Builder(field.getMessageType());
+ }
+
+ @Override
+ public boolean hasOneof(OneofDescriptor oneof) {
+ verifyOneofContainingType(oneof);
+ FieldDescriptor field = oneofCases[oneof.getIndex()];
+ if (field == null) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public FieldDescriptor getOneofFieldDescriptor(OneofDescriptor oneof) {
+ verifyOneofContainingType(oneof);
+ return oneofCases[oneof.getIndex()];
+ }
+
+ @Override
+ public Builder clearOneof(OneofDescriptor oneof) {
+ verifyOneofContainingType(oneof);
+ FieldDescriptor field = oneofCases[oneof.getIndex()];
+ if (field != null) {
+ clearField(field);
+ }
+ return this;
+ }
+
+ @Override
+ public boolean hasField(FieldDescriptor field) {
+ verifyContainingType(field);
+ return fields.hasField(field);
+ }
+
+ @Override
+ public Object getField(FieldDescriptor field) {
+ verifyContainingType(field);
+ Object result = fields.getField(field);
+ if (result == null) {
+ if (field.isRepeated()) {
+ result = Collections.emptyList();
+ } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ result = getDefaultInstance(field.getMessageType());
+ } else {
+ result = field.getDefaultValue();
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public Builder setField(FieldDescriptor field, Object value) {
+ verifyContainingType(field);
+ ensureIsMutable();
+ // TODO(xiaofeng): This check should really be put in FieldSet.setField()
+ // where all other such checks are done. However, currently
+ // FieldSet.setField() permits Integer value for enum fields probably
+ // because of some internal features we support. Should figure it out
+ // and move this check to a more appropriate place.
+ if (field.getType() == FieldDescriptor.Type.ENUM) {
+ ensureEnumValueDescriptor(field, value);
+ }
+ OneofDescriptor oneofDescriptor = field.getContainingOneof();
+ if (oneofDescriptor != null) {
+ int index = oneofDescriptor.getIndex();
+ FieldDescriptor oldField = oneofCases[index];
+ if ((oldField != null) && (oldField != field)) {
+ fields.clearField(oldField);
+ }
+ oneofCases[index] = field;
+ } else if (field.getFile().getSyntax() == Descriptors.FileDescriptor.Syntax.PROTO3) {
+ if (!field.isRepeated()
+ && field.getJavaType() != FieldDescriptor.JavaType.MESSAGE
+ && value.equals(field.getDefaultValue())) {
+ // In proto3, setting a field to its default value is equivalent to clearing the field.
+ fields.clearField(field);
+ return this;
+ }
+ }
+ fields.setField(field, value);
+ return this;
+ }
+
+ @Override
+ public Builder clearField(FieldDescriptor field) {
+ verifyContainingType(field);
+ ensureIsMutable();
+ OneofDescriptor oneofDescriptor = field.getContainingOneof();
+ if (oneofDescriptor != null) {
+ int index = oneofDescriptor.getIndex();
+ if (oneofCases[index] == field) {
+ oneofCases[index] = null;
+ }
+ }
+ fields.clearField(field);
+ return this;
+ }
+
+ @Override
+ public int getRepeatedFieldCount(FieldDescriptor field) {
+ verifyContainingType(field);
+ return fields.getRepeatedFieldCount(field);
+ }
+
+ @Override
+ public Object getRepeatedField(FieldDescriptor field, int index) {
+ verifyContainingType(field);
+ return fields.getRepeatedField(field, index);
+ }
+
+ @Override
+ public Builder setRepeatedField(FieldDescriptor field, int index, Object value) {
+ verifyContainingType(field);
+ ensureIsMutable();
+ fields.setRepeatedField(field, index, value);
+ return this;
+ }
+
+ @Override
+ public Builder addRepeatedField(FieldDescriptor field, Object value) {
+ verifyContainingType(field);
+ ensureIsMutable();
+ fields.addRepeatedField(field, value);
+ return this;
+ }
+
+ @Override
+ public UnknownFieldSet getUnknownFields() {
+ return unknownFields;
+ }
+
+ @Override
+ public Builder setUnknownFields(UnknownFieldSet unknownFields) {
+ if (getDescriptorForType().getFile().getSyntax()
+ == Descriptors.FileDescriptor.Syntax.PROTO3) {
+ // Proto3 discards unknown fields.
+ return this;
+ }
+ this.unknownFields = unknownFields;
+ return this;
+ }
+
+ @Override
+ public Builder mergeUnknownFields(UnknownFieldSet unknownFields) {
+ if (getDescriptorForType().getFile().getSyntax()
+ == Descriptors.FileDescriptor.Syntax.PROTO3) {
+ // Proto3 discards unknown fields.
+ return this;
+ }
+ this.unknownFields =
+ UnknownFieldSet.newBuilder(this.unknownFields)
+ .mergeFrom(unknownFields)
+ .build();
+ return this;
+ }
+
+ /** Verifies that the field is a field of this message. */
+ private void verifyContainingType(FieldDescriptor field) {
+ if (field.getContainingType() != type) {
+ throw new IllegalArgumentException(
+ "FieldDescriptor does not match message type.");
+ }
+ }
+
+ /** Verifies that the oneof is an oneof of this message. */
+ private void verifyOneofContainingType(OneofDescriptor oneof) {
+ if (oneof.getContainingType() != type) {
+ throw new IllegalArgumentException(
+ "OneofDescriptor does not match message type.");
+ }
+ }
+
+ /** Verifies that the value is EnumValueDescriptor and matches Enum Type. */
+ private void ensureSingularEnumValueDescriptor(
+ FieldDescriptor field, Object value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ if (!(value instanceof EnumValueDescriptor)) {
+ throw new IllegalArgumentException(
+ "DynamicMessage should use EnumValueDescriptor to set Enum Value.");
+ }
+ // TODO(xiaofeng): Re-enable this check after Orgstore is fixed to not
+ // set incorrect EnumValueDescriptors.
+ // EnumDescriptor fieldType = field.getEnumType();
+ // EnumDescriptor fieldValueType = ((EnumValueDescriptor) value).getType();
+ // if (fieldType != fieldValueType) {
+ // throw new IllegalArgumentException(String.format(
+ // "EnumDescriptor %s of field doesn't match EnumDescriptor %s of field value",
+ // fieldType.getFullName(), fieldValueType.getFullName()));
+ // }
+ }
+
+ /** Verifies the value for an enum field. */
+ private void ensureEnumValueDescriptor(
+ FieldDescriptor field, Object value) {
+ if (field.isRepeated()) {
+ for (Object item : (List) value) {
+ ensureSingularEnumValueDescriptor(field, item);
+ }
+ } else {
+ ensureSingularEnumValueDescriptor(field, value);
+ }
+ }
+
+ private void ensureIsMutable() {
+ if (fields.isImmutable()) {
+ fields = fields.clone();
+ }
+ }
+
+ @Override
+ public com.google.protobuf.Message.Builder getFieldBuilder(FieldDescriptor field) {
+ // TODO(xiangl): need implementation for dynamic message
+ throw new UnsupportedOperationException(
+ "getFieldBuilder() called on a dynamic message type.");
+ }
+
+ @Override
+ public com.google.protobuf.Message.Builder getRepeatedFieldBuilder(FieldDescriptor field,
+ int index) {
+ throw new UnsupportedOperationException(
+ "getRepeatedFieldBuilder() called on a dynamic message type.");
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExperimentalApi.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExperimentalApi.java
new file mode 100644
index 0000000000..3cd4c88492
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExperimentalApi.java
@@ -0,0 +1,66 @@
+// 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.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Indicates a public API that can change at any time, and has no guarantee of API stability and
+ * backward-compatibility.
+ *
+ * <p>Usage guidelines:
+ * <ol>
+ * <li>This annotation is used only on public API. Internal interfaces should not use it.</li>
+ * <li>This annotation should only be added to new APIs. Adding it to an existing API is
+ * considered API-breaking.</li>
+ * <li>Removing this annotation from an API gives it stable status.</li>
+ * </ol>
+ */
+@Retention(RetentionPolicy.SOURCE)
+@Target({
+ ElementType.ANNOTATION_TYPE,
+ ElementType.CONSTRUCTOR,
+ ElementType.FIELD,
+ ElementType.METHOD,
+ ElementType.PACKAGE,
+ ElementType.TYPE})
+@Documented
+public @interface ExperimentalApi {
+ /**
+ * Context information such as links to discussion thread, tracking issue etc.
+ */
+ String value() default "";
+}
+
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Extension.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Extension.java
new file mode 100644
index 0000000000..08ec5b4541
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Extension.java
@@ -0,0 +1,86 @@
+// 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;
+
+/**
+ * Interface that generated extensions implement.
+ *
+ * @author liujisi@google.com (Jisi Liu)
+ */
+public abstract class Extension<ContainingType extends MessageLite, Type>
+ extends ExtensionLite<ContainingType, Type> {
+
+ /** Returns the descriptor of the extension. */
+ public abstract Descriptors.FieldDescriptor getDescriptor();
+
+ /** Returns whether or not this extension is a Lite Extension. */
+ @Override
+ final boolean isLite() {
+ return false;
+ }
+
+ // All the methods below are extension implementation details.
+
+ /**
+ * The API type that the extension is used for.
+ */
+ protected enum ExtensionType {
+ IMMUTABLE,
+ MUTABLE,
+ PROTO1,
+ }
+
+ protected ExtensionType getExtensionType() {
+ // TODO(liujisi): make this abstract after we fix proto1.
+ return ExtensionType.IMMUTABLE;
+ }
+
+ /**
+ * Type of a message extension.
+ */
+ public enum MessageType {
+ PROTO1,
+ PROTO2,
+ }
+
+ /**
+ * If the extension is a message extension (i.e., getLiteType() == MESSAGE),
+ * returns the type of the message, otherwise undefined.
+ */
+ public MessageType getMessageType() {
+ return MessageType.PROTO2;
+ }
+
+ protected abstract Object fromReflectionType(Object value);
+ protected abstract Object singularFromReflectionType(Object value);
+ protected abstract Object toReflectionType(Object value);
+ protected abstract Object singularToReflectionType(Object value);
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionLite.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionLite.java
new file mode 100644
index 0000000000..f8f5bd2c4f
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionLite.java
@@ -0,0 +1,63 @@
+// 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;
+
+/**
+ * Lite interface that generated extensions implement.
+ * <p>
+ * Methods are for use by generated code only. You can hold a reference to
+ * extensions using this type name.
+ */
+public abstract class ExtensionLite<ContainingType extends MessageLite, Type> {
+
+ /** Returns the field number of the extension. */
+ public abstract int getNumber();
+
+ /** Returns the type of the field. */
+ public abstract WireFormat.FieldType getLiteType();
+
+ /** Returns whether it is a repeated field. */
+ public abstract boolean isRepeated();
+
+ /** Returns the default value of the extension field. */
+ public abstract Type getDefaultValue();
+
+ /**
+ * Returns the default instance of the extension field, if it's a message
+ * extension.
+ */
+ public abstract MessageLite getMessageDefaultInstance();
+
+ /** Returns whether or not this extension is a Lite Extension. */
+ boolean isLite() {
+ return true;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionRegistry.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionRegistry.java
new file mode 100644
index 0000000000..a22a74a03c
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionRegistry.java
@@ -0,0 +1,396 @@
+// 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.Descriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A table of known extensions, searchable by name or field number. When
+ * parsing a protocol message that might have extensions, you must provide
+ * an {@code ExtensionRegistry} in which you have registered any extensions
+ * that you want to be able to parse. Otherwise, those extensions will just
+ * be treated like unknown fields.
+ *
+ * <p>For example, if you had the {@code .proto} file:
+ *
+ * <pre>
+ * option java_class = "MyProto";
+ *
+ * message Foo {
+ * extensions 1000 to max;
+ * }
+ *
+ * extend Foo {
+ * optional int32 bar;
+ * }
+ * </pre>
+ *
+ * Then you might write code like:
+ *
+ * <pre>
+ * ExtensionRegistry registry = ExtensionRegistry.newInstance();
+ * registry.add(MyProto.bar);
+ * MyProto.Foo message = MyProto.Foo.parseFrom(input, registry);
+ * </pre>
+ *
+ * <p>Background:
+ *
+ * <p>You might wonder why this is necessary. Two alternatives might come to
+ * mind. First, you might imagine a system where generated extensions are
+ * automatically registered when their containing classes are loaded. This
+ * is a popular technique, but is bad design; among other things, it creates a
+ * situation where behavior can change depending on what classes happen to be
+ * loaded. It also introduces a security vulnerability, because an
+ * unprivileged class could cause its code to be called unexpectedly from a
+ * privileged class by registering itself as an extension of the right type.
+ *
+ * <p>Another option you might consider is lazy parsing: do not parse an
+ * extension until it is first requested, at which point the caller must
+ * provide a type to use. This introduces a different set of problems. First,
+ * it would require a mutex lock any time an extension was accessed, which
+ * would be slow. Second, corrupt data would not be detected until first
+ * access, at which point it would be much harder to deal with it. Third, it
+ * could violate the expectation that message objects are immutable, since the
+ * type provided could be any arbitrary message class. An unprivileged user
+ * could take advantage of this to inject a mutable object into a message
+ * belonging to privileged code and create mischief.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class ExtensionRegistry extends ExtensionRegistryLite {
+ /** Construct a new, empty instance. */
+ public static ExtensionRegistry newInstance() {
+ return new ExtensionRegistry();
+ }
+
+ /** Get the unmodifiable singleton empty instance. */
+ public static ExtensionRegistry getEmptyRegistry() {
+ return EMPTY_REGISTRY;
+ }
+
+
+ /** Returns an unmodifiable view of the registry. */
+ @Override
+ public ExtensionRegistry getUnmodifiable() {
+ return new ExtensionRegistry(this);
+ }
+
+ /** A (Descriptor, Message) pair, returned by lookup methods. */
+ public static final class ExtensionInfo {
+ /** The extension's descriptor. */
+ public final FieldDescriptor descriptor;
+
+ /**
+ * A default instance of the extension's type, if it has a message type.
+ * Otherwise, {@code null}.
+ */
+ public final Message defaultInstance;
+
+ private ExtensionInfo(final FieldDescriptor descriptor) {
+ this.descriptor = descriptor;
+ defaultInstance = null;
+ }
+ private ExtensionInfo(final FieldDescriptor descriptor,
+ final Message defaultInstance) {
+ this.descriptor = descriptor;
+ this.defaultInstance = defaultInstance;
+ }
+ }
+
+ /**
+ * Deprecated. Use {@link #findImmutableExtensionByName(String)} instead.
+ */
+ public ExtensionInfo findExtensionByName(final String fullName) {
+ return findImmutableExtensionByName(fullName);
+ }
+
+ /**
+ * Find an extension for immutable APIs by fully-qualified field name,
+ * in the proto namespace. i.e. {@code result.descriptor.fullName()} will
+ * match {@code fullName} if a match is found.
+ *
+ * @return Information about the extension if found, or {@code null}
+ * otherwise.
+ */
+ public ExtensionInfo findImmutableExtensionByName(final String fullName) {
+ return immutableExtensionsByName.get(fullName);
+ }
+
+ /**
+ * Find an extension for mutable APIs by fully-qualified field name,
+ * in the proto namespace. i.e. {@code result.descriptor.fullName()} will
+ * match {@code fullName} if a match is found.
+ *
+ * @return Information about the extension if found, or {@code null}
+ * otherwise.
+ */
+ public ExtensionInfo findMutableExtensionByName(final String fullName) {
+ return mutableExtensionsByName.get(fullName);
+ }
+
+ /**
+ * Deprecated. Use {@link #findImmutableExtensionByNumber(
+ * Descriptors.Descriptor, int)}
+ */
+ public ExtensionInfo findExtensionByNumber(
+ final Descriptor containingType, final int fieldNumber) {
+ return findImmutableExtensionByNumber(containingType, fieldNumber);
+ }
+
+ /**
+ * Find an extension by containing type and field number for immutable APIs.
+ *
+ * @return Information about the extension if found, or {@code null}
+ * otherwise.
+ */
+ public ExtensionInfo findImmutableExtensionByNumber(
+ final Descriptor containingType, final int fieldNumber) {
+ return immutableExtensionsByNumber.get(
+ new DescriptorIntPair(containingType, fieldNumber));
+ }
+
+ /**
+ * Find an extension by containing type and field number for mutable APIs.
+ *
+ * @return Information about the extension if found, or {@code null}
+ * otherwise.
+ */
+ public ExtensionInfo findMutableExtensionByNumber(
+ final Descriptor containingType, final int fieldNumber) {
+ return mutableExtensionsByNumber.get(
+ new DescriptorIntPair(containingType, fieldNumber));
+ }
+
+ /**
+ * Find all extensions for mutable APIs by fully-qualified name of
+ * extended class. Note that this method is more computationally expensive
+ * than getting a single extension by name or number.
+ *
+ * @return Information about the extensions found, or {@code null} if there
+ * are none.
+ */
+ public Set<ExtensionInfo> getAllMutableExtensionsByExtendedType(final String fullName) {
+ HashSet<ExtensionInfo> extensions = new HashSet<ExtensionInfo>();
+ for (DescriptorIntPair pair : mutableExtensionsByNumber.keySet()) {
+ if (pair.descriptor.getFullName().equals(fullName)) {
+ extensions.add(mutableExtensionsByNumber.get(pair));
+ }
+ }
+ return extensions;
+ }
+
+ /**
+ * Find all extensions for immutable APIs by fully-qualified name of
+ * extended class. Note that this method is more computationally expensive
+ * than getting a single extension by name or number.
+ *
+ * @return Information about the extensions found, or {@code null} if there
+ * are none.
+ */
+ public Set<ExtensionInfo> getAllImmutableExtensionsByExtendedType(final String fullName) {
+ HashSet<ExtensionInfo> extensions = new HashSet<ExtensionInfo>();
+ for (DescriptorIntPair pair : immutableExtensionsByNumber.keySet()) {
+ if (pair.descriptor.getFullName().equals(fullName)) {
+ extensions.add(immutableExtensionsByNumber.get(pair));
+ }
+ }
+ return extensions;
+ }
+
+ /** Add an extension from a generated file to the registry. */
+ public void add(final Extension<?, ?> extension) {
+ if (extension.getExtensionType() != Extension.ExtensionType.IMMUTABLE &&
+ extension.getExtensionType() != Extension.ExtensionType.MUTABLE) {
+ // do not support other extension types. ignore
+ return;
+ }
+ add(newExtensionInfo(extension), extension.getExtensionType());
+ }
+
+ /** Add an extension from a generated file to the registry. */
+ public void add(final GeneratedMessage.GeneratedExtension<?, ?> extension) {
+ add((Extension<?, ?>) extension);
+ }
+
+ static ExtensionInfo newExtensionInfo(final Extension<?, ?> extension) {
+ if (extension.getDescriptor().getJavaType() ==
+ FieldDescriptor.JavaType.MESSAGE) {
+ if (extension.getMessageDefaultInstance() == null) {
+ throw new IllegalStateException(
+ "Registered message-type extension had null default instance: " +
+ extension.getDescriptor().getFullName());
+ }
+ return new ExtensionInfo(extension.getDescriptor(),
+ (Message) extension.getMessageDefaultInstance());
+ } else {
+ return new ExtensionInfo(extension.getDescriptor(), null);
+ }
+ }
+
+ /** Add a non-message-type extension to the registry by descriptor. */
+ public void add(final FieldDescriptor type) {
+ if (type.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ throw new IllegalArgumentException(
+ "ExtensionRegistry.add() must be provided a default instance when " +
+ "adding an embedded message extension.");
+ }
+ ExtensionInfo info = new ExtensionInfo(type, null);
+ add(info, Extension.ExtensionType.IMMUTABLE);
+ add(info, Extension.ExtensionType.MUTABLE);
+ }
+
+ /** Add a message-type extension to the registry by descriptor. */
+ public void add(final FieldDescriptor type, final Message defaultInstance) {
+ if (type.getJavaType() != FieldDescriptor.JavaType.MESSAGE) {
+ throw new IllegalArgumentException(
+ "ExtensionRegistry.add() provided a default instance for a " +
+ "non-message extension.");
+ }
+ add(new ExtensionInfo(type, defaultInstance),
+ Extension.ExtensionType.IMMUTABLE);
+ }
+
+ // =================================================================
+ // Private stuff.
+
+ private ExtensionRegistry() {
+ this.immutableExtensionsByName = new HashMap<String, ExtensionInfo>();
+ this.mutableExtensionsByName = new HashMap<String, ExtensionInfo>();
+ this.immutableExtensionsByNumber =
+ new HashMap<DescriptorIntPair, ExtensionInfo>();
+ this.mutableExtensionsByNumber =
+ new HashMap<DescriptorIntPair, ExtensionInfo>();
+ }
+
+ private ExtensionRegistry(ExtensionRegistry other) {
+ super(other);
+ this.immutableExtensionsByName =
+ Collections.unmodifiableMap(other.immutableExtensionsByName);
+ this.mutableExtensionsByName =
+ Collections.unmodifiableMap(other.mutableExtensionsByName);
+ this.immutableExtensionsByNumber =
+ Collections.unmodifiableMap(other.immutableExtensionsByNumber);
+ this.mutableExtensionsByNumber =
+ Collections.unmodifiableMap(other.mutableExtensionsByNumber);
+ }
+
+ private final Map<String, ExtensionInfo> immutableExtensionsByName;
+ private final Map<String, ExtensionInfo> mutableExtensionsByName;
+ private final Map<DescriptorIntPair, ExtensionInfo> immutableExtensionsByNumber;
+ private final Map<DescriptorIntPair, ExtensionInfo> mutableExtensionsByNumber;
+
+ ExtensionRegistry(boolean empty) {
+ super(EMPTY_REGISTRY_LITE);
+ this.immutableExtensionsByName =
+ Collections.<String, ExtensionInfo>emptyMap();
+ this.mutableExtensionsByName =
+ Collections.<String, ExtensionInfo>emptyMap();
+ this.immutableExtensionsByNumber =
+ Collections.<DescriptorIntPair, ExtensionInfo>emptyMap();
+ this.mutableExtensionsByNumber =
+ Collections.<DescriptorIntPair, ExtensionInfo>emptyMap();
+ }
+ static final ExtensionRegistry EMPTY_REGISTRY = new ExtensionRegistry(true);
+
+ private void add(
+ final ExtensionInfo extension,
+ final Extension.ExtensionType extensionType) {
+ if (!extension.descriptor.isExtension()) {
+ throw new IllegalArgumentException(
+ "ExtensionRegistry.add() was given a FieldDescriptor for a regular " +
+ "(non-extension) field.");
+ }
+
+ Map<String, ExtensionInfo> extensionsByName;
+ Map<DescriptorIntPair, ExtensionInfo> extensionsByNumber;
+ switch (extensionType) {
+ case IMMUTABLE:
+ extensionsByName = immutableExtensionsByName;
+ extensionsByNumber = immutableExtensionsByNumber;
+ break;
+ case MUTABLE:
+ extensionsByName = mutableExtensionsByName;
+ extensionsByNumber = mutableExtensionsByNumber;
+ break;
+ default:
+ // Ignore the unknown supported type.
+ return;
+ }
+
+ extensionsByName.put(extension.descriptor.getFullName(), extension);
+ extensionsByNumber.put(
+ new DescriptorIntPair(extension.descriptor.getContainingType(),
+ extension.descriptor.getNumber()),
+ extension);
+
+ final FieldDescriptor field = extension.descriptor;
+ if (field.getContainingType().getOptions().getMessageSetWireFormat() &&
+ field.getType() == FieldDescriptor.Type.MESSAGE &&
+ field.isOptional() &&
+ field.getExtensionScope() == field.getMessageType()) {
+ // This is an extension of a MessageSet type defined within the extension
+ // type's own scope. For backwards-compatibility, allow it to be looked
+ // up by type name.
+ extensionsByName.put(field.getMessageType().getFullName(), extension);
+ }
+ }
+
+ /** A (GenericDescriptor, int) pair, used as a map key. */
+ private static final class DescriptorIntPair {
+ private final Descriptor descriptor;
+ private final int number;
+
+ DescriptorIntPair(final Descriptor descriptor, final int number) {
+ this.descriptor = descriptor;
+ this.number = number;
+ }
+
+ @Override
+ public int hashCode() {
+ return descriptor.hashCode() * ((1 << 16) - 1) + number;
+ }
+ @Override
+ public boolean equals(final Object obj) {
+ if (!(obj instanceof DescriptorIntPair)) {
+ return false;
+ }
+ final DescriptorIntPair other = (DescriptorIntPair)obj;
+ return descriptor == other.descriptor && number == other.number;
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionRegistryFactory.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionRegistryFactory.java
new file mode 100644
index 0000000000..23174e24c7
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionRegistryFactory.java
@@ -0,0 +1,95 @@
+// 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 static com.google.protobuf.ExtensionRegistryLite.EMPTY_REGISTRY_LITE;
+
+/**
+ * A factory object to create instances of {@link ExtensionRegistryLite}.
+ *
+ * <p>
+ * This factory detects (via reflection) if the full (non-Lite) protocol buffer libraries
+ * are available, and if so, the instances returned are actually {@link ExtensionRegistry}.
+ */
+final class ExtensionRegistryFactory {
+
+ static final String FULL_REGISTRY_CLASS_NAME = "com.google.protobuf.ExtensionRegistry";
+
+ /* Visible for Testing
+ @Nullable */
+ static final Class<?> EXTENSION_REGISTRY_CLASS = reflectExtensionRegistry();
+
+ /* @Nullable */
+ static Class<?> reflectExtensionRegistry() {
+ try {
+ return Class.forName(FULL_REGISTRY_CLASS_NAME);
+ } catch (ClassNotFoundException e) {
+ // The exception allocation is potentially expensive on Android (where it can be triggered
+ // many times at start up). Is there a way to ameliorate this?
+ return null;
+ }
+ }
+
+ /** Construct a new, empty instance. */
+ public static ExtensionRegistryLite create() {
+ if (EXTENSION_REGISTRY_CLASS != null) {
+ try {
+ return invokeSubclassFactory("newInstance");
+ } catch (Exception e) {
+ // return a Lite registry.
+ }
+ }
+ return new ExtensionRegistryLite();
+ }
+
+ /** Get the unmodifiable singleton empty instance. */
+ public static ExtensionRegistryLite createEmpty() {
+ if (EXTENSION_REGISTRY_CLASS != null) {
+ try {
+ return invokeSubclassFactory("getEmptyRegistry");
+ } catch (Exception e) {
+ // return a Lite registry.
+ }
+ }
+ return EMPTY_REGISTRY_LITE;
+ }
+
+ static boolean isFullRegistry(ExtensionRegistryLite registry) {
+ return EXTENSION_REGISTRY_CLASS != null
+ && EXTENSION_REGISTRY_CLASS.isAssignableFrom(registry.getClass());
+ }
+
+ private static final ExtensionRegistryLite invokeSubclassFactory(String methodName)
+ throws Exception {
+ return (ExtensionRegistryLite) EXTENSION_REGISTRY_CLASS
+ .getMethod(methodName).invoke(null);
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java
new file mode 100644
index 0000000000..f3d48d3af3
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ExtensionRegistryLite.java
@@ -0,0 +1,227 @@
+// 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.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Equivalent to {@link ExtensionRegistry} but supports only "lite" types.
+ * <p>
+ * If all of your types are lite types, then you only need to use
+ * {@code ExtensionRegistryLite}. Similarly, if all your types are regular
+ * types, then you only need {@link ExtensionRegistry}. Typically it does not
+ * make sense to mix the two, since if you have any regular types in your
+ * program, you then require the full runtime and lose all the benefits of
+ * the lite runtime, so you might as well make all your types be regular types.
+ * However, in some cases (e.g. when depending on multiple third-party libraries
+ * where one uses lite types and one uses regular), you may find yourself
+ * wanting to mix the two. In this case things get more complicated.
+ * <p>
+ * There are three factors to consider: Whether the type being extended is
+ * lite, whether the embedded type (in the case of a message-typed extension)
+ * is lite, and whether the extension itself is lite. Since all three are
+ * declared in different files, they could all be different. Here are all
+ * the combinations and which type of registry to use:
+ * <pre>
+ * Extended type Inner type Extension Use registry
+ * =======================================================================
+ * lite lite lite ExtensionRegistryLite
+ * lite regular lite ExtensionRegistry
+ * regular regular regular ExtensionRegistry
+ * all other combinations not supported
+ * </pre>
+ * <p>
+ * Note that just as regular types are not allowed to contain lite-type fields,
+ * they are also not allowed to contain lite-type extensions. This is because
+ * regular types must be fully accessible via reflection, which in turn means
+ * that all the inner messages must also support reflection. On the other hand,
+ * since regular types implement the entire lite interface, there is no problem
+ * with embedding regular types inside lite types.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class ExtensionRegistryLite {
+
+ // Set true to enable lazy parsing feature for MessageSet.
+ //
+ // TODO(xiangl): Now we use a global flag to control whether enable lazy
+ // parsing feature for MessageSet, which may be too crude for some
+ // applications. Need to support this feature on smaller granularity.
+ private static volatile boolean eagerlyParseMessageSets = false;
+
+ // Visible for testing.
+ static final String EXTENSION_CLASS_NAME = "com.google.protobuf.Extension";
+
+ /* @Nullable */
+ static Class<?> resolveExtensionClass() {
+ try {
+ return Class.forName(EXTENSION_CLASS_NAME);
+ } catch (ClassNotFoundException e) {
+ // See comment in ExtensionRegistryFactory on the potential expense of this.
+ return null;
+ }
+ }
+
+ /* @Nullable */
+ private static final Class<?> extensionClass = resolveExtensionClass();
+
+ public static boolean isEagerlyParseMessageSets() {
+ return eagerlyParseMessageSets;
+ }
+
+ public static void setEagerlyParseMessageSets(boolean isEagerlyParse) {
+ eagerlyParseMessageSets = isEagerlyParse;
+ }
+
+ /**
+ * Construct a new, empty instance.
+ *
+ * <p>This may be an {@code ExtensionRegistry} if the full (non-Lite) proto libraries are
+ * available.
+ */
+ public static ExtensionRegistryLite newInstance() {
+ return ExtensionRegistryFactory.create();
+ }
+
+ /**
+ * Get the unmodifiable singleton empty instance of either ExtensionRegistryLite or
+ * {@code ExtensionRegistry} (if the full (non-Lite) proto libraries are available).
+ */
+ public static ExtensionRegistryLite getEmptyRegistry() {
+ return ExtensionRegistryFactory.createEmpty();
+ }
+
+
+ /** Returns an unmodifiable view of the registry. */
+ public ExtensionRegistryLite getUnmodifiable() {
+ return new ExtensionRegistryLite(this);
+ }
+
+ /**
+ * Find an extension by containing type and field number.
+ *
+ * @return Information about the extension if found, or {@code null}
+ * otherwise.
+ */
+ @SuppressWarnings("unchecked")
+ public <ContainingType extends MessageLite>
+ GeneratedMessageLite.GeneratedExtension<ContainingType, ?>
+ findLiteExtensionByNumber(
+ final ContainingType containingTypeDefaultInstance,
+ final int fieldNumber) {
+ return (GeneratedMessageLite.GeneratedExtension<ContainingType, ?>)
+ extensionsByNumber.get(
+ new ObjectIntPair(containingTypeDefaultInstance, fieldNumber));
+ }
+
+ /** Add an extension from a lite generated file to the registry. */
+ public final void add(
+ final GeneratedMessageLite.GeneratedExtension<?, ?> extension) {
+ extensionsByNumber.put(
+ new ObjectIntPair(extension.getContainingTypeDefaultInstance(),
+ extension.getNumber()),
+ extension);
+ }
+
+ /**
+ * Add an extension from a lite generated file to the registry only if it is
+ * a non-lite extension i.e. {@link GeneratedMessageLite.GeneratedExtension}. */
+ public final void add(ExtensionLite<?, ?> extension) {
+ if (GeneratedMessageLite.GeneratedExtension.class.isAssignableFrom(extension.getClass())) {
+ add((GeneratedMessageLite.GeneratedExtension<?, ?>) extension);
+ }
+ if (ExtensionRegistryFactory.isFullRegistry(this)) {
+ try {
+ this.getClass().getMethod("add", extensionClass).invoke(this, extension);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(
+ String.format("Could not invoke ExtensionRegistry#add for %s", extension), e);
+ }
+ }
+ }
+
+ // =================================================================
+ // Private stuff.
+
+ // Constructors are package-private so that ExtensionRegistry can subclass
+ // this.
+
+ ExtensionRegistryLite() {
+ this.extensionsByNumber =
+ new HashMap<ObjectIntPair,
+ GeneratedMessageLite.GeneratedExtension<?, ?>>();
+ }
+ static final ExtensionRegistryLite EMPTY_REGISTRY_LITE =
+ new ExtensionRegistryLite(true);
+
+ ExtensionRegistryLite(ExtensionRegistryLite other) {
+ if (other == EMPTY_REGISTRY_LITE) {
+ this.extensionsByNumber = Collections.emptyMap();
+ } else {
+ this.extensionsByNumber =
+ Collections.unmodifiableMap(other.extensionsByNumber);
+ }
+ }
+
+ private final Map<ObjectIntPair,
+ GeneratedMessageLite.GeneratedExtension<?, ?>>
+ extensionsByNumber;
+
+ ExtensionRegistryLite(boolean empty) {
+ this.extensionsByNumber = Collections.emptyMap();
+ }
+
+ /** A (Object, int) pair, used as a map key. */
+ private static final class ObjectIntPair {
+ private final Object object;
+ private final int number;
+
+ ObjectIntPair(final Object object, final int number) {
+ this.object = object;
+ this.number = number;
+ }
+
+ @Override
+ public int hashCode() {
+ return System.identityHashCode(object) * ((1 << 16) - 1) + number;
+ }
+ @Override
+ public boolean equals(final Object obj) {
+ if (!(obj instanceof ObjectIntPair)) {
+ return false;
+ }
+ final ObjectIntPair other = (ObjectIntPair)obj;
+ return object == other.object && number == other.number;
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/FieldSet.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/FieldSet.java
new file mode 100644
index 0000000000..a828f30edb
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/FieldSet.java
@@ -0,0 +1,909 @@
+// 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.LazyField.LazyIterator;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A class which represents an arbitrary set of fields of some message type.
+ * This is used to implement {@link DynamicMessage}, and also to represent
+ * extensions in {@link GeneratedMessage}. This class is package-private,
+ * since outside users should probably be using {@link DynamicMessage}.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+final class FieldSet<FieldDescriptorType extends
+ FieldSet.FieldDescriptorLite<FieldDescriptorType>> {
+ /**
+ * Interface for a FieldDescriptor or lite extension descriptor. This
+ * prevents FieldSet from depending on {@link Descriptors.FieldDescriptor}.
+ */
+ public interface FieldDescriptorLite<T extends FieldDescriptorLite<T>>
+ extends Comparable<T> {
+ int getNumber();
+ WireFormat.FieldType getLiteType();
+ WireFormat.JavaType getLiteJavaType();
+ boolean isRepeated();
+ boolean isPacked();
+ Internal.EnumLiteMap<?> getEnumType();
+
+ // If getLiteJavaType() == MESSAGE, this merges a message object of the
+ // type into a builder of the type. Returns {@code to}.
+ MessageLite.Builder internalMergeFrom(
+ MessageLite.Builder to, MessageLite from);
+ }
+
+ private final SmallSortedMap<FieldDescriptorType, Object> fields;
+ private boolean isImmutable;
+ private boolean hasLazyField = false;
+
+ /** Construct a new FieldSet. */
+ private FieldSet() {
+ this.fields = SmallSortedMap.newFieldMap(16);
+ }
+
+ /**
+ * Construct an empty FieldSet. This is only used to initialize
+ * DEFAULT_INSTANCE.
+ */
+ private FieldSet(final boolean dummy) {
+ this.fields = SmallSortedMap.newFieldMap(0);
+ makeImmutable();
+ }
+
+ /** Construct a new FieldSet. */
+ public static <T extends FieldSet.FieldDescriptorLite<T>>
+ FieldSet<T> newFieldSet() {
+ return new FieldSet<T>();
+ }
+
+ /** Get an immutable empty FieldSet. */
+ @SuppressWarnings("unchecked")
+ public static <T extends FieldSet.FieldDescriptorLite<T>>
+ FieldSet<T> emptySet() {
+ return DEFAULT_INSTANCE;
+ }
+ @SuppressWarnings("rawtypes")
+ private static final FieldSet DEFAULT_INSTANCE = new FieldSet(true);
+
+ /** Make this FieldSet immutable from this point forward. */
+ @SuppressWarnings("unchecked")
+ public void makeImmutable() {
+ if (isImmutable) {
+ return;
+ }
+ fields.makeImmutable();
+ isImmutable = true;
+ }
+
+ /**
+ * Returns whether the FieldSet is immutable. This is true if it is the
+ * {@link #emptySet} or if {@link #makeImmutable} were called.
+ *
+ * @return whether the FieldSet is immutable.
+ */
+ public boolean isImmutable() {
+ return isImmutable;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+
+ if (!(o instanceof FieldSet)) {
+ return false;
+ }
+
+ FieldSet<?> other = (FieldSet<?>) o;
+ return fields.equals(other.fields);
+ }
+
+ @Override
+ public int hashCode() {
+ return fields.hashCode();
+ }
+
+ /**
+ * Clones the FieldSet. The returned FieldSet will be mutable even if the
+ * original FieldSet was immutable.
+ *
+ * @return the newly cloned FieldSet
+ */
+ @Override
+ public FieldSet<FieldDescriptorType> clone() {
+ // We can't just call fields.clone because List objects in the map
+ // should not be shared.
+ FieldSet<FieldDescriptorType> clone = FieldSet.newFieldSet();
+ for (int i = 0; i < fields.getNumArrayEntries(); i++) {
+ Map.Entry<FieldDescriptorType, Object> entry = fields.getArrayEntryAt(i);
+ FieldDescriptorType descriptor = entry.getKey();
+ clone.setField(descriptor, entry.getValue());
+ }
+ for (Map.Entry<FieldDescriptorType, Object> entry :
+ fields.getOverflowEntries()) {
+ FieldDescriptorType descriptor = entry.getKey();
+ clone.setField(descriptor, entry.getValue());
+ }
+ clone.hasLazyField = hasLazyField;
+ return clone;
+ }
+
+
+ // =================================================================
+
+ /** See {@link Message.Builder#clear()}. */
+ public void clear() {
+ fields.clear();
+ hasLazyField = false;
+ }
+
+ /**
+ * Get a simple map containing all the fields.
+ */
+ public Map<FieldDescriptorType, Object> getAllFields() {
+ if (hasLazyField) {
+ SmallSortedMap<FieldDescriptorType, Object> result =
+ SmallSortedMap.newFieldMap(16);
+ for (int i = 0; i < fields.getNumArrayEntries(); i++) {
+ cloneFieldEntry(result, fields.getArrayEntryAt(i));
+ }
+ for (Map.Entry<FieldDescriptorType, Object> entry :
+ fields.getOverflowEntries()) {
+ cloneFieldEntry(result, entry);
+ }
+ if (fields.isImmutable()) {
+ result.makeImmutable();
+ }
+ return result;
+ }
+ return fields.isImmutable() ? fields : Collections.unmodifiableMap(fields);
+ }
+
+ private void cloneFieldEntry(Map<FieldDescriptorType, Object> map,
+ Map.Entry<FieldDescriptorType, Object> entry) {
+ FieldDescriptorType key = entry.getKey();
+ Object value = entry.getValue();
+ if (value instanceof LazyField) {
+ map.put(key, ((LazyField) value).getValue());
+ } else {
+ map.put(key, value);
+ }
+ }
+
+ /**
+ * Get an iterator to the field map. This iterator should not be leaked out
+ * of the protobuf library as it is not protected from mutation when fields
+ * is not immutable.
+ */
+ public Iterator<Map.Entry<FieldDescriptorType, Object>> iterator() {
+ if (hasLazyField) {
+ return new LazyIterator<FieldDescriptorType>(
+ fields.entrySet().iterator());
+ }
+ return fields.entrySet().iterator();
+ }
+
+
+ /**
+ * Useful for implementing
+ * {@link Message#hasField(Descriptors.FieldDescriptor)}.
+ */
+ public boolean hasField(final FieldDescriptorType descriptor) {
+ if (descriptor.isRepeated()) {
+ throw new IllegalArgumentException(
+ "hasField() can only be called on non-repeated fields.");
+ }
+
+ return fields.get(descriptor) != null;
+ }
+
+ /**
+ * Useful for implementing
+ * {@link Message#getField(Descriptors.FieldDescriptor)}. This method
+ * returns {@code null} if the field is not set; in this case it is up
+ * to the caller to fetch the field's default value.
+ */
+ public Object getField(final FieldDescriptorType descriptor) {
+ Object o = fields.get(descriptor);
+ if (o instanceof LazyField) {
+ return ((LazyField) o).getValue();
+ }
+ return o;
+ }
+
+ /**
+ * Useful for implementing
+ * {@link Message.Builder#setField(Descriptors.FieldDescriptor,Object)}.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public void setField(final FieldDescriptorType descriptor,
+ Object value) {
+ if (descriptor.isRepeated()) {
+ if (!(value instanceof List)) {
+ throw new IllegalArgumentException(
+ "Wrong object type used with protocol message reflection.");
+ }
+
+ // Wrap the contents in a new list so that the caller cannot change
+ // the list's contents after setting it.
+ final List newList = new ArrayList();
+ newList.addAll((List) value);
+ for (final Object element : newList) {
+ verifyType(descriptor.getLiteType(), element);
+ }
+ value = newList;
+ } else {
+ verifyType(descriptor.getLiteType(), value);
+ }
+
+ if (value instanceof LazyField) {
+ hasLazyField = true;
+ }
+ fields.put(descriptor, value);
+ }
+
+ /**
+ * Useful for implementing
+ * {@link Message.Builder#clearField(Descriptors.FieldDescriptor)}.
+ */
+ public void clearField(final FieldDescriptorType descriptor) {
+ fields.remove(descriptor);
+ if (fields.isEmpty()) {
+ hasLazyField = false;
+ }
+ }
+
+ /**
+ * Useful for implementing
+ * {@link Message#getRepeatedFieldCount(Descriptors.FieldDescriptor)}.
+ */
+ public int getRepeatedFieldCount(final FieldDescriptorType descriptor) {
+ if (!descriptor.isRepeated()) {
+ throw new IllegalArgumentException(
+ "getRepeatedField() can only be called on repeated fields.");
+ }
+
+ final Object value = getField(descriptor);
+ if (value == null) {
+ return 0;
+ } else {
+ return ((List<?>) value).size();
+ }
+ }
+
+ /**
+ * Useful for implementing
+ * {@link Message#getRepeatedField(Descriptors.FieldDescriptor,int)}.
+ */
+ public Object getRepeatedField(final FieldDescriptorType descriptor,
+ final int index) {
+ if (!descriptor.isRepeated()) {
+ throw new IllegalArgumentException(
+ "getRepeatedField() can only be called on repeated fields.");
+ }
+
+ final Object value = getField(descriptor);
+
+ if (value == null) {
+ throw new IndexOutOfBoundsException();
+ } else {
+ return ((List<?>) value).get(index);
+ }
+ }
+
+ /**
+ * Useful for implementing
+ * {@link Message.Builder#setRepeatedField(Descriptors.FieldDescriptor,int,Object)}.
+ */
+ @SuppressWarnings("unchecked")
+ public void setRepeatedField(final FieldDescriptorType descriptor,
+ final int index,
+ final Object value) {
+ if (!descriptor.isRepeated()) {
+ throw new IllegalArgumentException(
+ "getRepeatedField() can only be called on repeated fields.");
+ }
+
+ final Object list = getField(descriptor);
+ if (list == null) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ verifyType(descriptor.getLiteType(), value);
+ ((List<Object>) list).set(index, value);
+ }
+
+ /**
+ * Useful for implementing
+ * {@link Message.Builder#addRepeatedField(Descriptors.FieldDescriptor,Object)}.
+ */
+ @SuppressWarnings("unchecked")
+ public void addRepeatedField(final FieldDescriptorType descriptor,
+ final Object value) {
+ if (!descriptor.isRepeated()) {
+ throw new IllegalArgumentException(
+ "addRepeatedField() can only be called on repeated fields.");
+ }
+
+ verifyType(descriptor.getLiteType(), value);
+
+ final Object existingValue = getField(descriptor);
+ List<Object> list;
+ if (existingValue == null) {
+ list = new ArrayList<Object>();
+ fields.put(descriptor, list);
+ } else {
+ list = (List<Object>) existingValue;
+ }
+
+ list.add(value);
+ }
+
+ /**
+ * Verifies that the given object is of the correct type to be a valid
+ * value for the given field. (For repeated fields, this checks if the
+ * object is the right type to be one element of the field.)
+ *
+ * @throws IllegalArgumentException The value is not of the right type.
+ */
+ private static void verifyType(final WireFormat.FieldType type,
+ final Object value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+
+ boolean isValid = false;
+ switch (type.getJavaType()) {
+ case INT: isValid = value instanceof Integer ; break;
+ case LONG: isValid = value instanceof Long ; break;
+ case FLOAT: isValid = value instanceof Float ; break;
+ case DOUBLE: isValid = value instanceof Double ; break;
+ case BOOLEAN: isValid = value instanceof Boolean ; break;
+ case STRING: isValid = value instanceof String ; break;
+ case BYTE_STRING:
+ isValid = value instanceof ByteString || value instanceof byte[];
+ break;
+ case ENUM:
+ // TODO(kenton): Caller must do type checking here, I guess.
+ isValid =
+ (value instanceof Integer || value instanceof Internal.EnumLite);
+ break;
+ case MESSAGE:
+ // TODO(kenton): Caller must do type checking here, I guess.
+ isValid =
+ (value instanceof MessageLite) || (value instanceof LazyField);
+ break;
+ }
+
+ if (!isValid) {
+ // TODO(kenton): When chaining calls to setField(), it can be hard to
+ // tell from the stack trace which exact call failed, since the whole
+ // chain is considered one line of code. It would be nice to print
+ // more information here, e.g. naming the field. We used to do that.
+ // But we can't now that FieldSet doesn't use descriptors. Maybe this
+ // isn't a big deal, though, since it would only really apply when using
+ // reflection and generally people don't chain reflection setters.
+ throw new IllegalArgumentException(
+ "Wrong object type used with protocol message reflection.");
+ }
+ }
+
+ // =================================================================
+ // Parsing and serialization
+
+ /**
+ * See {@link Message#isInitialized()}. Note: Since {@code FieldSet}
+ * itself does not have any way of knowing about required fields that
+ * aren't actually present in the set, it is up to the caller to check
+ * that all required fields are present.
+ */
+ public boolean isInitialized() {
+ for (int i = 0; i < fields.getNumArrayEntries(); i++) {
+ if (!isInitialized(fields.getArrayEntryAt(i))) {
+ return false;
+ }
+ }
+ for (final Map.Entry<FieldDescriptorType, Object> entry :
+ fields.getOverflowEntries()) {
+ if (!isInitialized(entry)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ private boolean isInitialized(
+ final Map.Entry<FieldDescriptorType, Object> entry) {
+ final FieldDescriptorType descriptor = entry.getKey();
+ if (descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE) {
+ if (descriptor.isRepeated()) {
+ for (final MessageLite element:
+ (List<MessageLite>) entry.getValue()) {
+ if (!element.isInitialized()) {
+ return false;
+ }
+ }
+ } else {
+ Object value = entry.getValue();
+ if (value instanceof MessageLite) {
+ if (!((MessageLite) value).isInitialized()) {
+ return false;
+ }
+ } else if (value instanceof LazyField) {
+ return true;
+ } else {
+ throw new IllegalArgumentException(
+ "Wrong object type used with protocol message reflection.");
+ }
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Given a field type, return the wire type.
+ *
+ * @returns One of the {@code WIRETYPE_} constants defined in
+ * {@link WireFormat}.
+ */
+ static int getWireFormatForFieldType(final WireFormat.FieldType type,
+ boolean isPacked) {
+ if (isPacked) {
+ return WireFormat.WIRETYPE_LENGTH_DELIMITED;
+ } else {
+ return type.getWireType();
+ }
+ }
+
+ /**
+ * Like {@link Message.Builder#mergeFrom(Message)}, but merges from another
+ * {@link FieldSet}.
+ */
+ public void mergeFrom(final FieldSet<FieldDescriptorType> other) {
+ for (int i = 0; i < other.fields.getNumArrayEntries(); i++) {
+ mergeFromField(other.fields.getArrayEntryAt(i));
+ }
+ for (final Map.Entry<FieldDescriptorType, Object> entry :
+ other.fields.getOverflowEntries()) {
+ mergeFromField(entry);
+ }
+ }
+
+ private Object cloneIfMutable(Object value) {
+ if (value instanceof byte[]) {
+ byte[] bytes = (byte[]) value;
+ byte[] copy = new byte[bytes.length];
+ System.arraycopy(bytes, 0, copy, 0, bytes.length);
+ return copy;
+ } else {
+ return value;
+ }
+ }
+
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ private void mergeFromField(
+ final Map.Entry<FieldDescriptorType, Object> entry) {
+ final FieldDescriptorType descriptor = entry.getKey();
+ Object otherValue = entry.getValue();
+ if (otherValue instanceof LazyField) {
+ otherValue = ((LazyField) otherValue).getValue();
+ }
+
+ if (descriptor.isRepeated()) {
+ Object value = getField(descriptor);
+ if (value == null) {
+ value = new ArrayList();
+ }
+ for (Object element : (List) otherValue) {
+ ((List) value).add(cloneIfMutable(element));
+ }
+ fields.put(descriptor, value);
+ } else if (descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE) {
+ Object value = getField(descriptor);
+ if (value == null) {
+ fields.put(descriptor, cloneIfMutable(otherValue));
+ } else {
+ // Merge the messages.
+ value = descriptor.internalMergeFrom(
+ ((MessageLite) value).toBuilder(), (MessageLite) otherValue)
+ .build();
+
+ fields.put(descriptor, value);
+ }
+ } else {
+ fields.put(descriptor, cloneIfMutable(otherValue));
+ }
+ }
+
+ // TODO(kenton): Move static parsing and serialization methods into some
+ // other class. Probably WireFormat.
+
+ /**
+ * Read a field of any primitive type for immutable messages from a
+ * CodedInputStream. Enums, groups, and embedded messages are not handled by
+ * this method.
+ *
+ * @param input The stream from which to read.
+ * @param type Declared type of the field.
+ * @param checkUtf8 When true, check that the input is valid utf8.
+ * @return An object representing the field's value, of the exact
+ * type which would be returned by
+ * {@link Message#getField(Descriptors.FieldDescriptor)} for
+ * this field.
+ */
+ public static Object readPrimitiveField(
+ CodedInputStream input,
+ final WireFormat.FieldType type,
+ boolean checkUtf8) throws IOException {
+ if (checkUtf8) {
+ return WireFormat.readPrimitiveField(input, type,
+ WireFormat.Utf8Validation.STRICT);
+ } else {
+ return WireFormat.readPrimitiveField(input, type,
+ WireFormat.Utf8Validation.LOOSE);
+ }
+ }
+
+
+ /** See {@link Message#writeTo(CodedOutputStream)}. */
+ public void writeTo(final CodedOutputStream output)
+ throws IOException {
+ for (int i = 0; i < fields.getNumArrayEntries(); i++) {
+ final Map.Entry<FieldDescriptorType, Object> entry =
+ fields.getArrayEntryAt(i);
+ writeField(entry.getKey(), entry.getValue(), output);
+ }
+ for (final Map.Entry<FieldDescriptorType, Object> entry :
+ fields.getOverflowEntries()) {
+ writeField(entry.getKey(), entry.getValue(), output);
+ }
+ }
+
+ /**
+ * Like {@link #writeTo} but uses MessageSet wire format.
+ */
+ public void writeMessageSetTo(final CodedOutputStream output)
+ throws IOException {
+ for (int i = 0; i < fields.getNumArrayEntries(); i++) {
+ writeMessageSetTo(fields.getArrayEntryAt(i), output);
+ }
+ for (final Map.Entry<FieldDescriptorType, Object> entry :
+ fields.getOverflowEntries()) {
+ writeMessageSetTo(entry, output);
+ }
+ }
+
+ private void writeMessageSetTo(
+ final Map.Entry<FieldDescriptorType, Object> entry,
+ final CodedOutputStream output) throws IOException {
+ final FieldDescriptorType descriptor = entry.getKey();
+ if (descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE &&
+ !descriptor.isRepeated() && !descriptor.isPacked()) {
+ Object value = entry.getValue();
+ if (value instanceof LazyField) {
+ value = ((LazyField) value).getValue();
+ }
+ output.writeMessageSetExtension(entry.getKey().getNumber(),
+ (MessageLite) value);
+ } else {
+ writeField(descriptor, entry.getValue(), output);
+ }
+ }
+
+ /**
+ * Write a single tag-value pair to the stream.
+ *
+ * @param output The output stream.
+ * @param type The field's type.
+ * @param number The field's number.
+ * @param value Object representing the field's value. Must be of the exact
+ * type which would be returned by
+ * {@link Message#getField(Descriptors.FieldDescriptor)} for
+ * this field.
+ */
+ static void writeElement(
+ final CodedOutputStream output,
+ final WireFormat.FieldType type,
+ final int number,
+ final Object value) throws IOException {
+ // Special case for groups, which need a start and end tag; other fields
+ // can just use writeTag() and writeFieldNoTag().
+ if (type == WireFormat.FieldType.GROUP) {
+ output.writeGroup(number, (MessageLite) value);
+ } else {
+ output.writeTag(number, getWireFormatForFieldType(type, false));
+ writeElementNoTag(output, type, value);
+ }
+ }
+
+ /**
+ * Write a field of arbitrary type, without its tag, to the stream.
+ *
+ * @param output The output stream.
+ * @param type The field's type.
+ * @param value Object representing the field's value. Must be of the exact
+ * type which would be returned by
+ * {@link Message#getField(Descriptors.FieldDescriptor)} for
+ * this field.
+ */
+ static void writeElementNoTag(
+ final CodedOutputStream output,
+ final WireFormat.FieldType type,
+ final Object value) throws IOException {
+ switch (type) {
+ case DOUBLE : output.writeDoubleNoTag ((Double ) value); break;
+ case FLOAT : output.writeFloatNoTag ((Float ) value); break;
+ case INT64 : output.writeInt64NoTag ((Long ) value); break;
+ case UINT64 : output.writeUInt64NoTag ((Long ) value); break;
+ case INT32 : output.writeInt32NoTag ((Integer ) value); break;
+ case FIXED64 : output.writeFixed64NoTag ((Long ) value); break;
+ case FIXED32 : output.writeFixed32NoTag ((Integer ) value); break;
+ case BOOL : output.writeBoolNoTag ((Boolean ) value); break;
+ case GROUP : output.writeGroupNoTag ((MessageLite) value); break;
+ case MESSAGE : output.writeMessageNoTag ((MessageLite) value); break;
+ case STRING:
+ if (value instanceof ByteString) {
+ output.writeBytesNoTag((ByteString) value);
+ } else {
+ output.writeStringNoTag((String) value);
+ }
+ break;
+ case BYTES:
+ if (value instanceof ByteString) {
+ output.writeBytesNoTag((ByteString) value);
+ } else {
+ output.writeByteArrayNoTag((byte[]) value);
+ }
+ break;
+ case UINT32 : output.writeUInt32NoTag ((Integer ) value); break;
+ case SFIXED32: output.writeSFixed32NoTag((Integer ) value); break;
+ case SFIXED64: output.writeSFixed64NoTag((Long ) value); break;
+ case SINT32 : output.writeSInt32NoTag ((Integer ) value); break;
+ case SINT64 : output.writeSInt64NoTag ((Long ) value); break;
+
+ case ENUM:
+ if (value instanceof Internal.EnumLite) {
+ output.writeEnumNoTag(((Internal.EnumLite) value).getNumber());
+ } else {
+ output.writeEnumNoTag(((Integer) value).intValue());
+ }
+ break;
+ }
+ }
+
+ /** Write a single field. */
+ public static void writeField(final FieldDescriptorLite<?> descriptor,
+ final Object value,
+ final CodedOutputStream output)
+ throws IOException {
+ WireFormat.FieldType type = descriptor.getLiteType();
+ int number = descriptor.getNumber();
+ if (descriptor.isRepeated()) {
+ final List<?> valueList = (List<?>)value;
+ if (descriptor.isPacked()) {
+ output.writeTag(number, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ // Compute the total data size so the length can be written.
+ int dataSize = 0;
+ for (final Object element : valueList) {
+ dataSize += computeElementSizeNoTag(type, element);
+ }
+ output.writeRawVarint32(dataSize);
+ // Write the data itself, without any tags.
+ for (final Object element : valueList) {
+ writeElementNoTag(output, type, element);
+ }
+ } else {
+ for (final Object element : valueList) {
+ writeElement(output, type, number, element);
+ }
+ }
+ } else {
+ if (value instanceof LazyField) {
+ writeElement(output, type, number, ((LazyField) value).getValue());
+ } else {
+ writeElement(output, type, number, value);
+ }
+ }
+ }
+
+ /**
+ * See {@link Message#getSerializedSize()}. It's up to the caller to cache
+ * the resulting size if desired.
+ */
+ public int getSerializedSize() {
+ int size = 0;
+ for (int i = 0; i < fields.getNumArrayEntries(); i++) {
+ final Map.Entry<FieldDescriptorType, Object> entry =
+ fields.getArrayEntryAt(i);
+ size += computeFieldSize(entry.getKey(), entry.getValue());
+ }
+ for (final Map.Entry<FieldDescriptorType, Object> entry :
+ fields.getOverflowEntries()) {
+ size += computeFieldSize(entry.getKey(), entry.getValue());
+ }
+ return size;
+ }
+
+ /**
+ * Like {@link #getSerializedSize} but uses MessageSet wire format.
+ */
+ public int getMessageSetSerializedSize() {
+ int size = 0;
+ for (int i = 0; i < fields.getNumArrayEntries(); i++) {
+ size += getMessageSetSerializedSize(fields.getArrayEntryAt(i));
+ }
+ for (final Map.Entry<FieldDescriptorType, Object> entry :
+ fields.getOverflowEntries()) {
+ size += getMessageSetSerializedSize(entry);
+ }
+ return size;
+ }
+
+ private int getMessageSetSerializedSize(
+ final Map.Entry<FieldDescriptorType, Object> entry) {
+ final FieldDescriptorType descriptor = entry.getKey();
+ Object value = entry.getValue();
+ if (descriptor.getLiteJavaType() == WireFormat.JavaType.MESSAGE
+ && !descriptor.isRepeated() && !descriptor.isPacked()) {
+ if (value instanceof LazyField) {
+ return CodedOutputStream.computeLazyFieldMessageSetExtensionSize(
+ entry.getKey().getNumber(), (LazyField) value);
+ } else {
+ return CodedOutputStream.computeMessageSetExtensionSize(
+ entry.getKey().getNumber(), (MessageLite) value);
+ }
+ } else {
+ return computeFieldSize(descriptor, value);
+ }
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * single tag/value pair of arbitrary type.
+ *
+ * @param type The field's type.
+ * @param number The field's number.
+ * @param value Object representing the field's value. Must be of the exact
+ * type which would be returned by
+ * {@link Message#getField(Descriptors.FieldDescriptor)} for
+ * this field.
+ */
+ static int computeElementSize(
+ final WireFormat.FieldType type, final int number, final Object value) {
+ int tagSize = CodedOutputStream.computeTagSize(number);
+ if (type == WireFormat.FieldType.GROUP) {
+ // Only count the end group tag for proto2 messages as for proto1 the end
+ // group tag will be counted as a part of getSerializedSize().
+ tagSize *= 2;
+ }
+ return tagSize + computeElementSizeNoTag(type, value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * particular value of arbitrary type, excluding tag.
+ *
+ * @param type The field's type.
+ * @param value Object representing the field's value. Must be of the exact
+ * type which would be returned by
+ * {@link Message#getField(Descriptors.FieldDescriptor)} for
+ * this field.
+ */
+ static int computeElementSizeNoTag(
+ final WireFormat.FieldType type, final Object value) {
+ switch (type) {
+ // Note: Minor violation of 80-char limit rule here because this would
+ // actually be harder to read if we wrapped the lines.
+ case DOUBLE : return CodedOutputStream.computeDoubleSizeNoTag ((Double )value);
+ case FLOAT : return CodedOutputStream.computeFloatSizeNoTag ((Float )value);
+ case INT64 : return CodedOutputStream.computeInt64SizeNoTag ((Long )value);
+ case UINT64 : return CodedOutputStream.computeUInt64SizeNoTag ((Long )value);
+ case INT32 : return CodedOutputStream.computeInt32SizeNoTag ((Integer )value);
+ case FIXED64 : return CodedOutputStream.computeFixed64SizeNoTag ((Long )value);
+ case FIXED32 : return CodedOutputStream.computeFixed32SizeNoTag ((Integer )value);
+ case BOOL : return CodedOutputStream.computeBoolSizeNoTag ((Boolean )value);
+ case GROUP : return CodedOutputStream.computeGroupSizeNoTag ((MessageLite)value);
+ case BYTES :
+ if (value instanceof ByteString) {
+ return CodedOutputStream.computeBytesSizeNoTag((ByteString) value);
+ } else {
+ return CodedOutputStream.computeByteArraySizeNoTag((byte[]) value);
+ }
+ case STRING :
+ if (value instanceof ByteString) {
+ return CodedOutputStream.computeBytesSizeNoTag((ByteString) value);
+ } else {
+ return CodedOutputStream.computeStringSizeNoTag((String) value);
+ }
+ case UINT32 : return CodedOutputStream.computeUInt32SizeNoTag ((Integer )value);
+ case SFIXED32: return CodedOutputStream.computeSFixed32SizeNoTag((Integer )value);
+ case SFIXED64: return CodedOutputStream.computeSFixed64SizeNoTag((Long )value);
+ case SINT32 : return CodedOutputStream.computeSInt32SizeNoTag ((Integer )value);
+ case SINT64 : return CodedOutputStream.computeSInt64SizeNoTag ((Long )value);
+
+ case MESSAGE:
+ if (value instanceof LazyField) {
+ return CodedOutputStream.computeLazyFieldSizeNoTag((LazyField) value);
+ } else {
+ return CodedOutputStream.computeMessageSizeNoTag((MessageLite) value);
+ }
+
+ case ENUM:
+ if (value instanceof Internal.EnumLite) {
+ return CodedOutputStream.computeEnumSizeNoTag(
+ ((Internal.EnumLite) value).getNumber());
+ } else {
+ return CodedOutputStream.computeEnumSizeNoTag((Integer) value);
+ }
+ }
+
+ throw new RuntimeException(
+ "There is no way to get here, but the compiler thinks otherwise.");
+ }
+
+ /**
+ * Compute the number of bytes needed to encode a particular field.
+ */
+ public static int computeFieldSize(final FieldDescriptorLite<?> descriptor,
+ final Object value) {
+ WireFormat.FieldType type = descriptor.getLiteType();
+ int number = descriptor.getNumber();
+ if (descriptor.isRepeated()) {
+ if (descriptor.isPacked()) {
+ int dataSize = 0;
+ for (final Object element : (List<?>)value) {
+ dataSize += computeElementSizeNoTag(type, element);
+ }
+ return dataSize +
+ CodedOutputStream.computeTagSize(number) +
+ CodedOutputStream.computeRawVarint32Size(dataSize);
+ } else {
+ int size = 0;
+ for (final Object element : (List<?>)value) {
+ size += computeElementSize(type, number, element);
+ }
+ return size;
+ }
+ } else {
+ return computeElementSize(type, number, value);
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/FloatArrayList.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/FloatArrayList.java
new file mode 100644
index 0000000000..90d6154b15
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/FloatArrayList.java
@@ -0,0 +1,272 @@
+// 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.FloatList;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.RandomAccess;
+
+/**
+ * An implementation of {@link FloatList} on top of a primitive array.
+ *
+ * @author dweis@google.com (Daniel Weis)
+ */
+final class FloatArrayList
+ extends AbstractProtobufList<Float>
+ implements FloatList, RandomAccess {
+
+ private static final FloatArrayList EMPTY_LIST = new FloatArrayList();
+ static {
+ EMPTY_LIST.makeImmutable();
+ }
+
+ public static FloatArrayList emptyList() {
+ return EMPTY_LIST;
+ }
+
+ /**
+ * The backing store for the list.
+ */
+ private float[] array;
+
+ /**
+ * The size of the list distinct from the length of the array. That is, it is the number of
+ * elements set in the list.
+ */
+ private int size;
+
+ /**
+ * Constructs a new mutable {@code FloatArrayList} with default capacity.
+ */
+ FloatArrayList() {
+ this(new float[DEFAULT_CAPACITY], 0);
+ }
+
+ /**
+ * Constructs a new mutable {@code FloatArrayList}
+ * containing the same elements as {@code other}.
+ */
+ private FloatArrayList(float[] other, int size) {
+ array = other;
+ this.size = size;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof FloatArrayList)) {
+ return super.equals(o);
+ }
+ FloatArrayList other = (FloatArrayList) o;
+ if (size != other.size) {
+ return false;
+ }
+
+ final float[] arr = other.array;
+ for (int i = 0; i < size; i++) {
+ if (array[i] != arr[i]) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 1;
+ for (int i = 0; i < size; i++) {
+ result = (31 * result) + Float.floatToIntBits(array[i]);
+ }
+ return result;
+ }
+
+ @Override
+ public FloatList mutableCopyWithCapacity(int capacity) {
+ if (capacity < size) {
+ throw new IllegalArgumentException();
+ }
+ return new FloatArrayList(Arrays.copyOf(array, capacity), size);
+ }
+
+ @Override
+ public Float get(int index) {
+ return getFloat(index);
+ }
+
+ @Override
+ public float getFloat(int index) {
+ ensureIndexInRange(index);
+ return array[index];
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public Float set(int index, Float element) {
+ return setFloat(index, element);
+ }
+
+ @Override
+ public float setFloat(int index, float element) {
+ ensureIsMutable();
+ ensureIndexInRange(index);
+ float previousValue = array[index];
+ array[index] = element;
+ return previousValue;
+ }
+
+ @Override
+ public void add(int index, Float element) {
+ addFloat(index, element);
+ }
+
+ /**
+ * Like {@link #add(Float)} but more efficient in that it doesn't box the element.
+ */
+ @Override
+ public void addFloat(float element) {
+ addFloat(size, element);
+ }
+
+ /**
+ * Like {@link #add(int, Float)} but more efficient in that it doesn't box the element.
+ */
+ private void addFloat(int index, float element) {
+ ensureIsMutable();
+ if (index < 0 || index > size) {
+ throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index));
+ }
+
+ if (size < array.length) {
+ // Shift everything over to make room
+ System.arraycopy(array, index, array, index + 1, size - index);
+ } else {
+ // Resize to 1.5x the size
+ int length = ((size * 3) / 2) + 1;
+ float[] newArray = new float[length];
+
+ // Copy the first part directly
+ System.arraycopy(array, 0, newArray, 0, index);
+
+ // Copy the rest shifted over by one to make room
+ System.arraycopy(array, index, newArray, index + 1, size - index);
+ array = newArray;
+ }
+
+ array[index] = element;
+ size++;
+ modCount++;
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends Float> collection) {
+ ensureIsMutable();
+
+ if (collection == null) {
+ throw new NullPointerException();
+ }
+
+ // We specialize when adding another FloatArrayList to avoid boxing elements.
+ if (!(collection instanceof FloatArrayList)) {
+ return super.addAll(collection);
+ }
+
+ FloatArrayList list = (FloatArrayList) collection;
+ if (list.size == 0) {
+ return false;
+ }
+
+ int overflow = Integer.MAX_VALUE - size;
+ if (overflow < list.size) {
+ // We can't actually represent a list this large.
+ throw new OutOfMemoryError();
+ }
+
+ int newSize = size + list.size;
+ if (newSize > array.length) {
+ array = Arrays.copyOf(array, newSize);
+ }
+
+ System.arraycopy(list.array, 0, array, size, list.size);
+ size = newSize;
+ modCount++;
+ return true;
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ ensureIsMutable();
+ for (int i = 0; i < size; i++) {
+ if (o.equals(array[i])) {
+ System.arraycopy(array, i + 1, array, i, size - i);
+ size--;
+ modCount++;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public Float remove(int index) {
+ ensureIsMutable();
+ ensureIndexInRange(index);
+ float value = array[index];
+ System.arraycopy(array, index + 1, array, index, size - index);
+ size--;
+ modCount++;
+ return value;
+ }
+
+ /**
+ * Ensures that the provided {@code index} is within the range of {@code [0, size]}. Throws an
+ * {@link IndexOutOfBoundsException} if it is not.
+ *
+ * @param index the index to verify is in range
+ */
+ private void ensureIndexInRange(int index) {
+ if (index < 0 || index >= size) {
+ throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index));
+ }
+ }
+
+ private String makeOutOfBoundsExceptionMessage(int index) {
+ return "Index:" + index + ", Size:" + size;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java
new file mode 100644
index 0000000000..60179e371d
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessage.java
@@ -0,0 +1,3051 @@
+// 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.Descriptor;
+import com.google.protobuf.Descriptors.EnumDescriptor;
+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 java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * All generated protocol message classes extend this class. This class
+ * implements most of the Message and Builder interfaces using Java reflection.
+ * Users can ignore this class and pretend that generated messages implement
+ * the Message interface directly.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public abstract class GeneratedMessage extends AbstractMessage
+ implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * For testing. Allows a test to disable the optimization that avoids using
+ * field builders for nested messages until they are requested. By disabling
+ * this optimization, existing tests can be reused to test the field builders.
+ */
+ protected static boolean alwaysUseFieldBuilders = false;
+
+ /** For use by generated code only. */
+ protected UnknownFieldSet unknownFields;
+
+ protected GeneratedMessage() {
+ unknownFields = UnknownFieldSet.getDefaultInstance();
+ }
+
+ protected GeneratedMessage(Builder<?> builder) {
+ unknownFields = builder.getUnknownFields();
+ }
+
+ @Override
+ public Parser<? extends GeneratedMessage> getParserForType() {
+ throw new UnsupportedOperationException(
+ "This is supposed to be overridden by subclasses.");
+ }
+
+ /**
+ * For testing. Allows a test to disable the optimization that avoids using
+ * field builders for nested messages until they are requested. By disabling
+ * this optimization, existing tests can be reused to test the field builders.
+ * See {@link RepeatedFieldBuilder} and {@link SingleFieldBuilder}.
+ */
+ static void enableAlwaysUseFieldBuildersForTesting() {
+ alwaysUseFieldBuilders = true;
+ }
+
+ /**
+ * Get the FieldAccessorTable for this type. We can't have the message
+ * class pass this in to the constructor because of bootstrapping trouble
+ * with DescriptorProtos.
+ */
+ protected abstract FieldAccessorTable internalGetFieldAccessorTable();
+
+ @Override
+ public Descriptor getDescriptorForType() {
+ return internalGetFieldAccessorTable().descriptor;
+ }
+
+ /**
+ * Internal helper to return a modifiable map containing all the fields.
+ * The returned Map is modifialbe so that the caller can add additional
+ * extension fields to implement {@link #getAllFields()}.
+ *
+ * @param getBytesForString whether to generate ByteString for string fields
+ */
+ private Map<FieldDescriptor, Object> getAllFieldsMutable(
+ boolean getBytesForString) {
+ final TreeMap<FieldDescriptor, Object> result =
+ new TreeMap<FieldDescriptor, Object>();
+ final Descriptor descriptor = internalGetFieldAccessorTable().descriptor;
+ final List<FieldDescriptor> fields = descriptor.getFields();
+
+ for (int i = 0; i < fields.size(); i++) {
+ FieldDescriptor field = fields.get(i);
+ final OneofDescriptor oneofDescriptor = field.getContainingOneof();
+
+ /*
+ * If the field is part of a Oneof, then at maximum one field in the Oneof is set
+ * and it is not repeated. There is no need to iterate through the others.
+ */
+ if (oneofDescriptor != null) {
+ // Skip other fields in the Oneof we know are not set
+ i += oneofDescriptor.getFieldCount() - 1;
+ if (!hasOneof(oneofDescriptor)) {
+ // If no field is set in the Oneof, skip all the fields in the Oneof
+ continue;
+ }
+ // Get the pointer to the only field which is set in the Oneof
+ field = getOneofFieldDescriptor(oneofDescriptor);
+ } else {
+ // If we are not in a Oneof, we need to check if the field is set and if it is repeated
+ if (field.isRepeated()) {
+ final List<?> value = (List<?>) getField(field);
+ if (!value.isEmpty()) {
+ result.put(field, value);
+ }
+ continue;
+ }
+ if (!hasField(field)) {
+ continue;
+ }
+ }
+ // Add the field to the map
+ if (getBytesForString && field.getJavaType() == FieldDescriptor.JavaType.STRING) {
+ result.put(field, getFieldRaw(field));
+ } else {
+ result.put(field, getField(field));
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public boolean isInitialized() {
+ for (final FieldDescriptor field : getDescriptorForType().getFields()) {
+ // Check that all required fields are present.
+ if (field.isRequired()) {
+ if (!hasField(field)) {
+ return false;
+ }
+ }
+ // Check that embedded messages are initialized.
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ if (field.isRepeated()) {
+ @SuppressWarnings("unchecked") final
+ List<Message> messageList = (List<Message>) getField(field);
+ for (final Message element : messageList) {
+ if (!element.isInitialized()) {
+ return false;
+ }
+ }
+ } else {
+ if (hasField(field) && !((Message) getField(field)).isInitialized()) {
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public Map<FieldDescriptor, Object> getAllFields() {
+ return Collections.unmodifiableMap(
+ getAllFieldsMutable(/* getBytesForString = */ false));
+ }
+
+ /**
+ * Returns a collection of all the fields in this message which are set
+ * and their corresponding values. A singular ("required" or "optional")
+ * field is set iff hasField() returns true for that field. A "repeated"
+ * field is set iff getRepeatedFieldCount() is greater than zero. The
+ * values are exactly what would be returned by calling
+ * {@link #getFieldRaw(Descriptors.FieldDescriptor)} for each field. The map
+ * is guaranteed to be a sorted map, so iterating over it will return fields
+ * in order by field number.
+ */
+ Map<FieldDescriptor, Object> getAllFieldsRaw() {
+ return Collections.unmodifiableMap(
+ getAllFieldsMutable(/* getBytesForString = */ true));
+ }
+
+ @Override
+ public boolean hasOneof(final OneofDescriptor oneof) {
+ return internalGetFieldAccessorTable().getOneof(oneof).has(this);
+ }
+
+ @Override
+ public FieldDescriptor getOneofFieldDescriptor(final OneofDescriptor oneof) {
+ return internalGetFieldAccessorTable().getOneof(oneof).get(this);
+ }
+
+ @Override
+ public boolean hasField(final FieldDescriptor field) {
+ return internalGetFieldAccessorTable().getField(field).has(this);
+ }
+
+ @Override
+ public Object getField(final FieldDescriptor field) {
+ return internalGetFieldAccessorTable().getField(field).get(this);
+ }
+
+ /**
+ * Obtains the value of the given field, or the default value if it is
+ * not set. For primitive fields, the boxed primitive value is returned.
+ * For enum fields, the EnumValueDescriptor for the value is returned. For
+ * embedded message fields, the sub-message is returned. For repeated
+ * fields, a java.util.List is returned. For present string fields, a
+ * ByteString is returned representing the bytes that the field contains.
+ */
+ Object getFieldRaw(final FieldDescriptor field) {
+ return internalGetFieldAccessorTable().getField(field).getRaw(this);
+ }
+
+ @Override
+ public int getRepeatedFieldCount(final FieldDescriptor field) {
+ return internalGetFieldAccessorTable().getField(field)
+ .getRepeatedCount(this);
+ }
+
+ @Override
+ public Object getRepeatedField(final FieldDescriptor field, final int index) {
+ return internalGetFieldAccessorTable().getField(field)
+ .getRepeated(this, index);
+ }
+
+ @Override
+ public UnknownFieldSet getUnknownFields() {
+ throw new UnsupportedOperationException(
+ "This is supposed to be overridden by subclasses.");
+ }
+
+ /**
+ * Called by subclasses to parse an unknown field.
+ * @return {@code true} unless the tag is an end-group tag.
+ */
+ protected boolean parseUnknownField(
+ CodedInputStream input,
+ UnknownFieldSet.Builder unknownFields,
+ ExtensionRegistryLite extensionRegistry,
+ int tag) throws IOException {
+ return unknownFields.mergeFieldFrom(tag, input);
+ }
+
+ protected static <M extends Message> M parseWithIOException(Parser<M> parser, InputStream input)
+ throws IOException {
+ try {
+ return parser.parseFrom(input);
+ } catch (InvalidProtocolBufferException e) {
+ throw e.unwrapIOException();
+ }
+ }
+
+ protected static <M extends Message> M parseWithIOException(Parser<M> parser, InputStream input,
+ ExtensionRegistryLite extensions) throws IOException {
+ try {
+ return parser.parseFrom(input, extensions);
+ } catch (InvalidProtocolBufferException e) {
+ throw e.unwrapIOException();
+ }
+ }
+
+ protected static <M extends Message> M parseWithIOException(Parser<M> parser,
+ CodedInputStream input) throws IOException {
+ try {
+ return parser.parseFrom(input);
+ } catch (InvalidProtocolBufferException e) {
+ throw e.unwrapIOException();
+ }
+ }
+
+ protected static <M extends Message> M parseWithIOException(Parser<M> parser,
+ CodedInputStream input, ExtensionRegistryLite extensions) throws IOException {
+ try {
+ return parser.parseFrom(input, extensions);
+ } catch (InvalidProtocolBufferException e) {
+ throw e.unwrapIOException();
+ }
+ }
+
+ protected static <M extends Message> M parseDelimitedWithIOException(Parser<M> parser,
+ InputStream input) throws IOException {
+ try {
+ return parser.parseDelimitedFrom(input);
+ } catch (InvalidProtocolBufferException e) {
+ throw e.unwrapIOException();
+ }
+ }
+
+ protected static <M extends Message> M parseDelimitedWithIOException(Parser<M> parser,
+ InputStream input, ExtensionRegistryLite extensions) throws IOException {
+ try {
+ return parser.parseDelimitedFrom(input, extensions);
+ } catch (InvalidProtocolBufferException e) {
+ throw e.unwrapIOException();
+ }
+ }
+
+ @Override
+ public void writeTo(final CodedOutputStream output) throws IOException {
+ MessageReflection.writeMessageTo(this, getAllFieldsRaw(), output, false);
+ }
+
+ @Override
+ public int getSerializedSize() {
+ int size = memoizedSize;
+ if (size != -1) {
+ return size;
+ }
+
+ memoizedSize = MessageReflection.getSerializedSize(
+ this, getAllFieldsRaw());
+ return memoizedSize;
+ }
+
+
+
+ /**
+ * Used by parsing constructors in generated classes.
+ */
+ protected void makeExtensionsImmutable() {
+ // Noop for messages without extensions.
+ }
+
+ /**
+ * TODO(xiaofeng): remove this after b/29368482 is fixed. We need to move this
+ * interface to AbstractMessage in order to versioning GeneratedMessage but
+ * this move breaks binary compatibility for AppEngine. After AppEngine is
+ * fixed we can exlude this from google3.
+ */
+ protected interface BuilderParent extends AbstractMessage.BuilderParent {}
+
+ /**
+ * TODO(xiaofeng): remove this together with GeneratedMessage.BuilderParent.
+ */
+ protected abstract Message.Builder newBuilderForType(BuilderParent parent);
+
+ @Override
+ protected Message.Builder newBuilderForType(final AbstractMessage.BuilderParent parent) {
+ return newBuilderForType(new BuilderParent() {
+ @Override
+ public void markDirty() {
+ parent.markDirty();
+ }
+ });
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public abstract static class Builder <BuilderType extends Builder<BuilderType>>
+ extends AbstractMessage.Builder<BuilderType> {
+
+ private BuilderParent builderParent;
+
+ private BuilderParentImpl meAsParent;
+
+ // Indicates that we've built a message and so we are now obligated
+ // to dispatch dirty invalidations. See GeneratedMessage.BuilderListener.
+ private boolean isClean;
+
+ private UnknownFieldSet unknownFields =
+ UnknownFieldSet.getDefaultInstance();
+
+ protected Builder() {
+ this(null);
+ }
+
+ protected Builder(BuilderParent builderParent) {
+ this.builderParent = builderParent;
+ }
+
+ @Override
+ void dispose() {
+ builderParent = null;
+ }
+
+ /**
+ * Called by the subclass when a message is built.
+ */
+ protected void onBuilt() {
+ if (builderParent != null) {
+ markClean();
+ }
+ }
+
+ /**
+ * Called by the subclass or a builder to notify us that a message was
+ * built and may be cached and therefore invalidations are needed.
+ */
+ @Override
+ protected void markClean() {
+ this.isClean = true;
+ }
+
+ /**
+ * Gets whether invalidations are needed
+ *
+ * @return whether invalidations are needed
+ */
+ protected boolean isClean() {
+ return isClean;
+ }
+
+ @Override
+ public BuilderType clone() {
+ BuilderType builder =
+ (BuilderType) getDefaultInstanceForType().newBuilderForType();
+ builder.mergeFrom(buildPartial());
+ return builder;
+ }
+
+ /**
+ * Called by the initialization and clear code paths to allow subclasses to
+ * reset any of their builtin fields back to the initial values.
+ */
+ @Override
+ public BuilderType clear() {
+ unknownFields = UnknownFieldSet.getDefaultInstance();
+ onChanged();
+ return (BuilderType) this;
+ }
+
+ /**
+ * Get the FieldAccessorTable for this type. We can't have the message
+ * class pass this in to the constructor because of bootstrapping trouble
+ * with DescriptorProtos.
+ */
+ protected abstract FieldAccessorTable internalGetFieldAccessorTable();
+
+ @Override
+ public Descriptor getDescriptorForType() {
+ return internalGetFieldAccessorTable().descriptor;
+ }
+
+ @Override
+ public Map<FieldDescriptor, Object> getAllFields() {
+ return Collections.unmodifiableMap(getAllFieldsMutable());
+ }
+
+ /** Internal helper which returns a mutable map. */
+ private Map<FieldDescriptor, Object> getAllFieldsMutable() {
+ final TreeMap<FieldDescriptor, Object> result =
+ new TreeMap<FieldDescriptor, Object>();
+ final Descriptor descriptor = internalGetFieldAccessorTable().descriptor;
+ final List<FieldDescriptor> fields = descriptor.getFields();
+
+ for (int i = 0; i < fields.size(); i++) {
+ FieldDescriptor field = fields.get(i);
+ final OneofDescriptor oneofDescriptor = field.getContainingOneof();
+
+ /*
+ * If the field is part of a Oneof, then at maximum one field in the Oneof is set
+ * and it is not repeated. There is no need to iterate through the others.
+ */
+ if (oneofDescriptor != null) {
+ // Skip other fields in the Oneof we know are not set
+ i += oneofDescriptor.getFieldCount() - 1;
+ if (!hasOneof(oneofDescriptor)) {
+ // If no field is set in the Oneof, skip all the fields in the Oneof
+ continue;
+ }
+ // Get the pointer to the only field which is set in the Oneof
+ field = getOneofFieldDescriptor(oneofDescriptor);
+ } else {
+ // If we are not in a Oneof, we need to check if the field is set and if it is repeated
+ if (field.isRepeated()) {
+ final List<?> value = (List<?>) getField(field);
+ if (!value.isEmpty()) {
+ result.put(field, value);
+ }
+ continue;
+ }
+ if (!hasField(field)) {
+ continue;
+ }
+ }
+ // Add the field to the map
+ result.put(field, getField(field));
+ }
+ return result;
+ }
+
+ @Override
+ public Message.Builder newBuilderForField(final FieldDescriptor field) {
+ return internalGetFieldAccessorTable().getField(field).newBuilder();
+ }
+
+ @Override
+ public Message.Builder getFieldBuilder(final FieldDescriptor field) {
+ return internalGetFieldAccessorTable().getField(field).getBuilder(this);
+ }
+
+ @Override
+ public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, int index) {
+ return internalGetFieldAccessorTable().getField(field).getRepeatedBuilder(
+ this, index);
+ }
+
+ @Override
+ public boolean hasOneof(final OneofDescriptor oneof) {
+ return internalGetFieldAccessorTable().getOneof(oneof).has(this);
+ }
+
+ @Override
+ public FieldDescriptor getOneofFieldDescriptor(final OneofDescriptor oneof) {
+ return internalGetFieldAccessorTable().getOneof(oneof).get(this);
+ }
+
+ @Override
+ public boolean hasField(final FieldDescriptor field) {
+ return internalGetFieldAccessorTable().getField(field).has(this);
+ }
+
+ @Override
+ public Object getField(final FieldDescriptor field) {
+ Object object = internalGetFieldAccessorTable().getField(field).get(this);
+ if (field.isRepeated()) {
+ // The underlying list object is still modifiable at this point.
+ // Make sure not to expose the modifiable list to the caller.
+ return Collections.unmodifiableList((List) object);
+ } else {
+ return object;
+ }
+ }
+
+ @Override
+ public BuilderType setField(final FieldDescriptor field, final Object value) {
+ internalGetFieldAccessorTable().getField(field).set(this, value);
+ return (BuilderType) this;
+ }
+
+ @Override
+ public BuilderType clearField(final FieldDescriptor field) {
+ internalGetFieldAccessorTable().getField(field).clear(this);
+ return (BuilderType) this;
+ }
+
+ @Override
+ public BuilderType clearOneof(final OneofDescriptor oneof) {
+ internalGetFieldAccessorTable().getOneof(oneof).clear(this);
+ return (BuilderType) this;
+ }
+
+ @Override
+ public int getRepeatedFieldCount(final FieldDescriptor field) {
+ return internalGetFieldAccessorTable().getField(field)
+ .getRepeatedCount(this);
+ }
+
+ @Override
+ public Object getRepeatedField(final FieldDescriptor field, final int index) {
+ return internalGetFieldAccessorTable().getField(field)
+ .getRepeated(this, index);
+ }
+
+ @Override
+ public BuilderType setRepeatedField(
+ final FieldDescriptor field, final int index, final Object value) {
+ internalGetFieldAccessorTable().getField(field)
+ .setRepeated(this, index, value);
+ return (BuilderType) this;
+ }
+
+ @Override
+ public BuilderType addRepeatedField(final FieldDescriptor field, final Object value) {
+ internalGetFieldAccessorTable().getField(field).addRepeated(this, value);
+ return (BuilderType) this;
+ }
+
+ @Override
+ public BuilderType setUnknownFields(final UnknownFieldSet unknownFields) {
+ this.unknownFields = unknownFields;
+ onChanged();
+ return (BuilderType) this;
+ }
+
+ @Override
+ public BuilderType mergeUnknownFields(
+ final UnknownFieldSet unknownFields) {
+ this.unknownFields =
+ UnknownFieldSet.newBuilder(this.unknownFields)
+ .mergeFrom(unknownFields)
+ .build();
+ onChanged();
+ return (BuilderType) this;
+ }
+
+ @Override
+ public boolean isInitialized() {
+ for (final FieldDescriptor field : getDescriptorForType().getFields()) {
+ // Check that all required fields are present.
+ if (field.isRequired()) {
+ if (!hasField(field)) {
+ return false;
+ }
+ }
+ // Check that embedded messages are initialized.
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ if (field.isRepeated()) {
+ @SuppressWarnings("unchecked") final
+ List<Message> messageList = (List<Message>) getField(field);
+ for (final Message element : messageList) {
+ if (!element.isInitialized()) {
+ return false;
+ }
+ }
+ } else {
+ if (hasField(field) &&
+ !((Message) getField(field)).isInitialized()) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public final UnknownFieldSet getUnknownFields() {
+ return unknownFields;
+ }
+
+ /**
+ * Called by subclasses to parse an unknown field.
+ * @return {@code true} unless the tag is an end-group tag.
+ */
+ protected boolean parseUnknownField(
+ final CodedInputStream input,
+ final UnknownFieldSet.Builder unknownFields,
+ final ExtensionRegistryLite extensionRegistry,
+ final int tag) throws IOException {
+ return unknownFields.mergeFieldFrom(tag, input);
+ }
+
+ /**
+ * Implementation of {@link BuilderParent} for giving to our children. This
+ * small inner class makes it so we don't publicly expose the BuilderParent
+ * methods.
+ */
+ private class BuilderParentImpl implements BuilderParent {
+
+ @Override
+ public void markDirty() {
+ onChanged();
+ }
+ }
+
+ /**
+ * Gets the {@link BuilderParent} for giving to our children.
+ * @return The builder parent for our children.
+ */
+ protected BuilderParent getParentForChildren() {
+ if (meAsParent == null) {
+ meAsParent = new BuilderParentImpl();
+ }
+ return meAsParent;
+ }
+
+ /**
+ * Called when a the builder or one of its nested children has changed
+ * and any parent should be notified of its invalidation.
+ */
+ protected final void onChanged() {
+ if (isClean && builderParent != null) {
+ builderParent.markDirty();
+
+ // Don't keep dispatching invalidations until build is called again.
+ isClean = false;
+ }
+ }
+
+ /**
+ * Gets the map field with the given field number. This method should be
+ * overridden in the generated message class if the message contains map
+ * fields.
+ *
+ * Unlike other field types, reflection support for map fields can't be
+ * implemented based on generated public API because we need to access a
+ * map field as a list in reflection API but the generated API only allows
+ * us to access it as a map. This method returns the underlying map field
+ * directly and thus enables us to access the map field as a list.
+ */
+ @SuppressWarnings({"unused", "rawtypes"})
+ protected MapField internalGetMapField(int fieldNumber) {
+ // Note that we can't use descriptor names here because this method will
+ // be called when descriptor is being initialized.
+ throw new RuntimeException(
+ "No map fields found in " + getClass().getName());
+ }
+
+ /** Like {@link #internalGetMapField} but return a mutable version. */
+ @SuppressWarnings({"unused", "rawtypes"})
+ protected MapField internalGetMutableMapField(int fieldNumber) {
+ // Note that we can't use descriptor names here because this method will
+ // be called when descriptor is being initialized.
+ throw new RuntimeException(
+ "No map fields found in " + getClass().getName());
+ }
+ }
+
+ // =================================================================
+ // Extensions-related stuff
+
+ public interface ExtendableMessageOrBuilder<
+ MessageType extends ExtendableMessage> extends MessageOrBuilder {
+ // Re-define for return type covariance.
+ @Override
+ Message getDefaultInstanceForType();
+
+ /** Check if a singular extension is present. */
+ <Type> boolean hasExtension(
+ ExtensionLite<MessageType, Type> extension);
+
+ /** Get the number of elements in a repeated extension. */
+ <Type> int getExtensionCount(
+ ExtensionLite<MessageType, List<Type>> extension);
+
+ /** Get the value of an extension. */
+ <Type> Type getExtension(
+ ExtensionLite<MessageType, Type> extension);
+
+ /** Get one element of a repeated extension. */
+ <Type> Type getExtension(
+ ExtensionLite<MessageType, List<Type>> extension,
+ int index);
+
+ /** Check if a singular extension is present. */
+ <Type> boolean hasExtension(
+ Extension<MessageType, Type> extension);
+ /** Check if a singular extension is present. */
+ <Type> boolean hasExtension(
+ GeneratedExtension<MessageType, Type> extension);
+ /** Get the number of elements in a repeated extension. */
+ <Type> int getExtensionCount(
+ Extension<MessageType, List<Type>> extension);
+ /** Get the number of elements in a repeated extension. */
+ <Type> int getExtensionCount(
+ GeneratedExtension<MessageType, List<Type>> extension);
+ /** Get the value of an extension. */
+ <Type> Type getExtension(
+ Extension<MessageType, Type> extension);
+ /** Get the value of an extension. */
+ <Type> Type getExtension(
+ GeneratedExtension<MessageType, Type> extension);
+ /** Get one element of a repeated extension. */
+ <Type> Type getExtension(
+ Extension<MessageType, List<Type>> extension,
+ int index);
+ /** Get one element of a repeated extension. */
+ <Type> Type getExtension(
+ GeneratedExtension<MessageType, List<Type>> extension,
+ int index);
+ }
+
+ /**
+ * Generated message classes for message types that contain extension ranges
+ * subclass this.
+ *
+ * <p>This class implements type-safe accessors for extensions. They
+ * implement all the same operations that you can do with normal fields --
+ * e.g. "has", "get", and "getCount" -- but for extensions. The extensions
+ * are identified using instances of the class {@link GeneratedExtension};
+ * the protocol compiler generates a static instance of this class for every
+ * extension in its input. Through the magic of generics, all is made
+ * type-safe.
+ *
+ * <p>For example, imagine you have the {@code .proto} file:
+ *
+ * <pre>
+ * option java_class = "MyProto";
+ *
+ * message Foo {
+ * extensions 1000 to max;
+ * }
+ *
+ * extend Foo {
+ * optional int32 bar;
+ * }
+ * </pre>
+ *
+ * <p>Then you might write code like:
+ *
+ * <pre>
+ * MyProto.Foo foo = getFoo();
+ * int i = foo.getExtension(MyProto.bar);
+ * </pre>
+ *
+ * <p>See also {@link ExtendableBuilder}.
+ */
+ public abstract static class ExtendableMessage<
+ MessageType extends ExtendableMessage>
+ extends GeneratedMessage
+ implements ExtendableMessageOrBuilder<MessageType> {
+
+ private static final long serialVersionUID = 1L;
+
+ private final FieldSet<FieldDescriptor> extensions;
+
+ protected ExtendableMessage() {
+ this.extensions = FieldSet.newFieldSet();
+ }
+
+ protected ExtendableMessage(
+ ExtendableBuilder<MessageType, ?> builder) {
+ super(builder);
+ this.extensions = builder.buildExtensions();
+ }
+
+ private void verifyExtensionContainingType(
+ final Extension<MessageType, ?> extension) {
+ if (extension.getDescriptor().getContainingType() !=
+ getDescriptorForType()) {
+ // This can only happen if someone uses unchecked operations.
+ throw new IllegalArgumentException(
+ "Extension is for type \"" +
+ extension.getDescriptor().getContainingType().getFullName() +
+ "\" which does not match message type \"" +
+ getDescriptorForType().getFullName() + "\".");
+ }
+ }
+
+ /** Check if a singular extension is present. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public final <Type> boolean hasExtension(final ExtensionLite<MessageType, Type> extensionLite) {
+ Extension<MessageType, Type> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ return extensions.hasField(extension.getDescriptor());
+ }
+
+ /** Get the number of elements in a repeated extension. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public final <Type> int getExtensionCount(
+ final ExtensionLite<MessageType, List<Type>> extensionLite) {
+ Extension<MessageType, List<Type>> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ final FieldDescriptor descriptor = extension.getDescriptor();
+ return extensions.getRepeatedFieldCount(descriptor);
+ }
+
+ /** Get the value of an extension. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public final <Type> Type getExtension(final ExtensionLite<MessageType, Type> extensionLite) {
+ Extension<MessageType, Type> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ FieldDescriptor descriptor = extension.getDescriptor();
+ final Object value = extensions.getField(descriptor);
+ if (value == null) {
+ if (descriptor.isRepeated()) {
+ return (Type) Collections.emptyList();
+ } else if (descriptor.getJavaType() ==
+ FieldDescriptor.JavaType.MESSAGE) {
+ return (Type) extension.getMessageDefaultInstance();
+ } else {
+ return (Type) extension.fromReflectionType(
+ descriptor.getDefaultValue());
+ }
+ } else {
+ return (Type) extension.fromReflectionType(value);
+ }
+ }
+
+ /** Get one element of a repeated extension. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public final <Type> Type getExtension(
+ final ExtensionLite<MessageType, List<Type>> extensionLite, final int index) {
+ Extension<MessageType, List<Type>> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ FieldDescriptor descriptor = extension.getDescriptor();
+ return (Type) extension.singularFromReflectionType(
+ extensions.getRepeatedField(descriptor, index));
+ }
+
+ /** Check if a singular extension is present. */
+ @Override
+ public final <Type> boolean hasExtension(final Extension<MessageType, Type> extension) {
+ return hasExtension((ExtensionLite<MessageType, Type>) extension);
+ }
+ /** Check if a singular extension is present. */
+ @Override
+ public final <Type> boolean hasExtension(
+ final GeneratedExtension<MessageType, Type> extension) {
+ return hasExtension((ExtensionLite<MessageType, Type>) extension);
+ }
+ /** Get the number of elements in a repeated extension. */
+ @Override
+ public final <Type> int getExtensionCount(
+ final Extension<MessageType, List<Type>> extension) {
+ return getExtensionCount((ExtensionLite<MessageType, List<Type>>) extension);
+ }
+ /** Get the number of elements in a repeated extension. */
+ @Override
+ public final <Type> int getExtensionCount(
+ final GeneratedExtension<MessageType, List<Type>> extension) {
+ return getExtensionCount((ExtensionLite<MessageType, List<Type>>) extension);
+ }
+ /** Get the value of an extension. */
+ @Override
+ public final <Type> Type getExtension(final Extension<MessageType, Type> extension) {
+ return getExtension((ExtensionLite<MessageType, Type>) extension);
+ }
+ /** Get the value of an extension. */
+ @Override
+ public final <Type> Type getExtension(
+ final GeneratedExtension<MessageType, Type> extension) {
+ return getExtension((ExtensionLite<MessageType, Type>) extension);
+ }
+ /** Get one element of a repeated extension. */
+ @Override
+ public final <Type> Type getExtension(
+ final Extension<MessageType, List<Type>> extension, final int index) {
+ return getExtension((ExtensionLite<MessageType, List<Type>>) extension, index);
+ }
+ /** Get one element of a repeated extension. */
+ @Override
+ public final <Type> Type getExtension(
+ final GeneratedExtension<MessageType, List<Type>> extension, final int index) {
+ return getExtension((ExtensionLite<MessageType, List<Type>>) extension, index);
+ }
+
+ /** Called by subclasses to check if all extensions are initialized. */
+ protected boolean extensionsAreInitialized() {
+ return extensions.isInitialized();
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return super.isInitialized() && extensionsAreInitialized();
+ }
+
+ @Override
+ protected boolean parseUnknownField(
+ CodedInputStream input,
+ UnknownFieldSet.Builder unknownFields,
+ ExtensionRegistryLite extensionRegistry,
+ int tag) throws IOException {
+ return MessageReflection.mergeFieldFrom(
+ input, unknownFields, extensionRegistry, getDescriptorForType(),
+ new MessageReflection.ExtensionAdapter(extensions), tag);
+ }
+
+
+ /**
+ * Used by parsing constructors in generated classes.
+ */
+ @Override
+ protected void makeExtensionsImmutable() {
+ extensions.makeImmutable();
+ }
+
+ /**
+ * Used by subclasses to serialize extensions. Extension ranges may be
+ * interleaved with field numbers, but we must write them in canonical
+ * (sorted by field number) order. ExtensionWriter helps us write
+ * individual ranges of extensions at once.
+ */
+ protected class ExtensionWriter {
+ // Imagine how much simpler this code would be if Java iterators had
+ // a way to get the next element without advancing the iterator.
+
+ private final Iterator<Map.Entry<FieldDescriptor, Object>> iter =
+ extensions.iterator();
+ private Map.Entry<FieldDescriptor, Object> next;
+ private final boolean messageSetWireFormat;
+
+ private ExtensionWriter(final boolean messageSetWireFormat) {
+ if (iter.hasNext()) {
+ next = iter.next();
+ }
+ this.messageSetWireFormat = messageSetWireFormat;
+ }
+
+ public void writeUntil(final int end, final CodedOutputStream output)
+ throws IOException {
+ while (next != null && next.getKey().getNumber() < end) {
+ FieldDescriptor descriptor = next.getKey();
+ if (messageSetWireFormat && descriptor.getLiteJavaType() ==
+ WireFormat.JavaType.MESSAGE &&
+ !descriptor.isRepeated()) {
+ if (next instanceof LazyField.LazyEntry<?>) {
+ output.writeRawMessageSetExtension(descriptor.getNumber(),
+ ((LazyField.LazyEntry<?>) next).getField().toByteString());
+ } else {
+ output.writeMessageSetExtension(descriptor.getNumber(),
+ (Message) next.getValue());
+ }
+ } else {
+ // TODO(xiangl): Taken care of following code, it may cause
+ // problem when we use LazyField for normal fields/extensions.
+ // Due to the optional field can be duplicated at the end of
+ // serialized bytes, which will make the serialized size change
+ // after lazy field parsed. So when we use LazyField globally,
+ // we need to change the following write method to write cached
+ // bytes directly rather than write the parsed message.
+ FieldSet.writeField(descriptor, next.getValue(), output);
+ }
+ if (iter.hasNext()) {
+ next = iter.next();
+ } else {
+ next = null;
+ }
+ }
+ }
+ }
+
+ protected ExtensionWriter newExtensionWriter() {
+ return new ExtensionWriter(false);
+ }
+ protected ExtensionWriter newMessageSetExtensionWriter() {
+ return new ExtensionWriter(true);
+ }
+
+ /** Called by subclasses to compute the size of extensions. */
+ protected int extensionsSerializedSize() {
+ return extensions.getSerializedSize();
+ }
+ protected int extensionsSerializedSizeAsMessageSet() {
+ return extensions.getMessageSetSerializedSize();
+ }
+
+ // ---------------------------------------------------------------
+ // Reflection
+
+ protected Map<FieldDescriptor, Object> getExtensionFields() {
+ return extensions.getAllFields();
+ }
+
+ @Override
+ public Map<FieldDescriptor, Object> getAllFields() {
+ final Map<FieldDescriptor, Object> result =
+ super.getAllFieldsMutable(/* getBytesForString = */ false);
+ result.putAll(getExtensionFields());
+ return Collections.unmodifiableMap(result);
+ }
+
+ @Override
+ public Map<FieldDescriptor, Object> getAllFieldsRaw() {
+ final Map<FieldDescriptor, Object> result =
+ super.getAllFieldsMutable(/* getBytesForString = */ false);
+ result.putAll(getExtensionFields());
+ return Collections.unmodifiableMap(result);
+ }
+
+ @Override
+ public boolean hasField(final FieldDescriptor field) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ return extensions.hasField(field);
+ } else {
+ return super.hasField(field);
+ }
+ }
+
+ @Override
+ public Object getField(final FieldDescriptor field) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ final Object value = extensions.getField(field);
+ if (value == null) {
+ if (field.isRepeated()) {
+ return Collections.emptyList();
+ } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ // Lacking an ExtensionRegistry, we have no way to determine the
+ // extension's real type, so we return a DynamicMessage.
+ return DynamicMessage.getDefaultInstance(field.getMessageType());
+ } else {
+ return field.getDefaultValue();
+ }
+ } else {
+ return value;
+ }
+ } else {
+ return super.getField(field);
+ }
+ }
+
+ @Override
+ public int getRepeatedFieldCount(final FieldDescriptor field) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ return extensions.getRepeatedFieldCount(field);
+ } else {
+ return super.getRepeatedFieldCount(field);
+ }
+ }
+
+ @Override
+ public Object getRepeatedField(final FieldDescriptor field,
+ final int index) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ return extensions.getRepeatedField(field, index);
+ } else {
+ return super.getRepeatedField(field, index);
+ }
+ }
+
+ private void verifyContainingType(final FieldDescriptor field) {
+ if (field.getContainingType() != getDescriptorForType()) {
+ throw new IllegalArgumentException(
+ "FieldDescriptor does not match message type.");
+ }
+ }
+ }
+
+ /**
+ * Generated message builders for message types that contain extension ranges
+ * subclass this.
+ *
+ * <p>This class implements type-safe accessors for extensions. They
+ * implement all the same operations that you can do with normal fields --
+ * e.g. "get", "set", and "add" -- but for extensions. The extensions are
+ * identified using instances of the class {@link GeneratedExtension}; the
+ * protocol compiler generates a static instance of this class for every
+ * extension in its input. Through the magic of generics, all is made
+ * type-safe.
+ *
+ * <p>For example, imagine you have the {@code .proto} file:
+ *
+ * <pre>
+ * option java_class = "MyProto";
+ *
+ * message Foo {
+ * extensions 1000 to max;
+ * }
+ *
+ * extend Foo {
+ * optional int32 bar;
+ * }
+ * </pre>
+ *
+ * <p>Then you might write code like:
+ *
+ * <pre>
+ * MyProto.Foo foo =
+ * MyProto.Foo.newBuilder()
+ * .setExtension(MyProto.bar, 123)
+ * .build();
+ * </pre>
+ *
+ * <p>See also {@link ExtendableMessage}.
+ */
+ @SuppressWarnings("unchecked")
+ public abstract static class ExtendableBuilder<
+ MessageType extends ExtendableMessage,
+ BuilderType extends ExtendableBuilder<MessageType, BuilderType>>
+ extends Builder<BuilderType>
+ implements ExtendableMessageOrBuilder<MessageType> {
+
+ private FieldSet<FieldDescriptor> extensions = FieldSet.emptySet();
+
+ protected ExtendableBuilder() {}
+
+ protected ExtendableBuilder(
+ BuilderParent parent) {
+ super(parent);
+ }
+
+ // For immutable message conversion.
+ void internalSetExtensionSet(FieldSet<FieldDescriptor> extensions) {
+ this.extensions = extensions;
+ }
+
+ @Override
+ public BuilderType clear() {
+ extensions = FieldSet.emptySet();
+ return super.clear();
+ }
+
+ // This is implemented here only to work around an apparent bug in the
+ // Java compiler and/or build system. See bug #1898463. The mere presence
+ // of this clone() implementation makes it go away.
+ @Override
+ public BuilderType clone() {
+ return super.clone();
+ }
+
+ private void ensureExtensionsIsMutable() {
+ if (extensions.isImmutable()) {
+ extensions = extensions.clone();
+ }
+ }
+
+ private void verifyExtensionContainingType(
+ final Extension<MessageType, ?> extension) {
+ if (extension.getDescriptor().getContainingType() !=
+ getDescriptorForType()) {
+ // This can only happen if someone uses unchecked operations.
+ throw new IllegalArgumentException(
+ "Extension is for type \"" +
+ extension.getDescriptor().getContainingType().getFullName() +
+ "\" which does not match message type \"" +
+ getDescriptorForType().getFullName() + "\".");
+ }
+ }
+
+ /** Check if a singular extension is present. */
+ @Override
+ public final <Type> boolean hasExtension(final ExtensionLite<MessageType, Type> extensionLite) {
+ Extension<MessageType, Type> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ return extensions.hasField(extension.getDescriptor());
+ }
+
+ /** Get the number of elements in a repeated extension. */
+ @Override
+ public final <Type> int getExtensionCount(
+ final ExtensionLite<MessageType, List<Type>> extensionLite) {
+ Extension<MessageType, List<Type>> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ final FieldDescriptor descriptor = extension.getDescriptor();
+ return extensions.getRepeatedFieldCount(descriptor);
+ }
+
+ /** Get the value of an extension. */
+ @Override
+ public final <Type> Type getExtension(final ExtensionLite<MessageType, Type> extensionLite) {
+ Extension<MessageType, Type> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ FieldDescriptor descriptor = extension.getDescriptor();
+ final Object value = extensions.getField(descriptor);
+ if (value == null) {
+ if (descriptor.isRepeated()) {
+ return (Type) Collections.emptyList();
+ } else if (descriptor.getJavaType() ==
+ FieldDescriptor.JavaType.MESSAGE) {
+ return (Type) extension.getMessageDefaultInstance();
+ } else {
+ return (Type) extension.fromReflectionType(
+ descriptor.getDefaultValue());
+ }
+ } else {
+ return (Type) extension.fromReflectionType(value);
+ }
+ }
+
+ /** Get one element of a repeated extension. */
+ @Override
+ public final <Type> Type getExtension(
+ final ExtensionLite<MessageType, List<Type>> extensionLite, final int index) {
+ Extension<MessageType, List<Type>> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ FieldDescriptor descriptor = extension.getDescriptor();
+ return (Type) extension.singularFromReflectionType(
+ extensions.getRepeatedField(descriptor, index));
+ }
+
+ /** Set the value of an extension. */
+ public final <Type> BuilderType setExtension(
+ final ExtensionLite<MessageType, Type> extensionLite,
+ final Type value) {
+ Extension<MessageType, Type> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ ensureExtensionsIsMutable();
+ final FieldDescriptor descriptor = extension.getDescriptor();
+ extensions.setField(descriptor, extension.toReflectionType(value));
+ onChanged();
+ return (BuilderType) this;
+ }
+
+ /** Set the value of one element of a repeated extension. */
+ public final <Type> BuilderType setExtension(
+ final ExtensionLite<MessageType, List<Type>> extensionLite,
+ final int index, final Type value) {
+ Extension<MessageType, List<Type>> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ ensureExtensionsIsMutable();
+ final FieldDescriptor descriptor = extension.getDescriptor();
+ extensions.setRepeatedField(
+ descriptor, index,
+ extension.singularToReflectionType(value));
+ onChanged();
+ return (BuilderType) this;
+ }
+
+ /** Append a value to a repeated extension. */
+ public final <Type> BuilderType addExtension(
+ final ExtensionLite<MessageType, List<Type>> extensionLite,
+ final Type value) {
+ Extension<MessageType, List<Type>> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ ensureExtensionsIsMutable();
+ final FieldDescriptor descriptor = extension.getDescriptor();
+ extensions.addRepeatedField(
+ descriptor, extension.singularToReflectionType(value));
+ onChanged();
+ return (BuilderType) this;
+ }
+
+ /** Clear an extension. */
+ public final <Type> BuilderType clearExtension(
+ final ExtensionLite<MessageType, ?> extensionLite) {
+ Extension<MessageType, ?> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ ensureExtensionsIsMutable();
+ extensions.clearField(extension.getDescriptor());
+ onChanged();
+ return (BuilderType) this;
+ }
+
+ /** Check if a singular extension is present. */
+ @Override
+ public final <Type> boolean hasExtension(final Extension<MessageType, Type> extension) {
+ return hasExtension((ExtensionLite<MessageType, Type>) extension);
+ }
+ /** Check if a singular extension is present. */
+ @Override
+ public final <Type> boolean hasExtension(
+ final GeneratedExtension<MessageType, Type> extension) {
+ return hasExtension((ExtensionLite<MessageType, Type>) extension);
+ }
+ /** Get the number of elements in a repeated extension. */
+ @Override
+ public final <Type> int getExtensionCount(
+ final Extension<MessageType, List<Type>> extension) {
+ return getExtensionCount((ExtensionLite<MessageType, List<Type>>) extension);
+ }
+ /** Get the number of elements in a repeated extension. */
+ @Override
+ public final <Type> int getExtensionCount(
+ final GeneratedExtension<MessageType, List<Type>> extension) {
+ return getExtensionCount((ExtensionLite<MessageType, List<Type>>) extension);
+ }
+ /** Get the value of an extension. */
+ @Override
+ public final <Type> Type getExtension(final Extension<MessageType, Type> extension) {
+ return getExtension((ExtensionLite<MessageType, Type>) extension);
+ }
+ /** Get the value of an extension. */
+ @Override
+ public final <Type> Type getExtension(
+ final GeneratedExtension<MessageType, Type> extension) {
+ return getExtension((ExtensionLite<MessageType, Type>) extension);
+ }
+ /** Get the value of an extension. */
+ @Override
+ public final <Type> Type getExtension(
+ final Extension<MessageType, List<Type>> extension, final int index) {
+ return getExtension((ExtensionLite<MessageType, List<Type>>) extension, index);
+ }
+ /** Get the value of an extension. */
+ @Override
+ public final <Type> Type getExtension(
+ final GeneratedExtension<MessageType, List<Type>> extension, final int index) {
+ return getExtension((ExtensionLite<MessageType, List<Type>>) extension, index);
+ }
+ /** Set the value of an extension. */
+ public final <Type> BuilderType setExtension(
+ final Extension<MessageType, Type> extension, final Type value) {
+ return setExtension((ExtensionLite<MessageType, Type>) extension, value);
+ }
+ /** Set the value of an extension. */
+ public <Type> BuilderType setExtension(
+ final GeneratedExtension<MessageType, Type> extension, final Type value) {
+ return setExtension((ExtensionLite<MessageType, Type>) extension, value);
+ }
+ /** Set the value of one element of a repeated extension. */
+ public final <Type> BuilderType setExtension(
+ final Extension<MessageType, List<Type>> extension,
+ final int index, final Type value) {
+ return setExtension((ExtensionLite<MessageType, List<Type>>) extension, index, value);
+ }
+ /** Set the value of one element of a repeated extension. */
+ public <Type> BuilderType setExtension(
+ final GeneratedExtension<MessageType, List<Type>> extension,
+ final int index, final Type value) {
+ return setExtension((ExtensionLite<MessageType, List<Type>>) extension, index, value);
+ }
+ /** Append a value to a repeated extension. */
+ public final <Type> BuilderType addExtension(
+ final Extension<MessageType, List<Type>> extension, final Type value) {
+ return addExtension((ExtensionLite<MessageType, List<Type>>) extension, value);
+ }
+ /** Append a value to a repeated extension. */
+ public <Type> BuilderType addExtension(
+ final GeneratedExtension<MessageType, List<Type>> extension, final Type value) {
+ return addExtension((ExtensionLite<MessageType, List<Type>>) extension, value);
+ }
+ /** Clear an extension. */
+ public final <Type> BuilderType clearExtension(
+ final Extension<MessageType, ?> extension) {
+ return clearExtension((ExtensionLite<MessageType, ?>) extension);
+ }
+ /** Clear an extension. */
+ public <Type> BuilderType clearExtension(
+ final GeneratedExtension<MessageType, ?> extension) {
+ return clearExtension((ExtensionLite<MessageType, ?>) extension);
+ }
+
+ /** Called by subclasses to check if all extensions are initialized. */
+ protected boolean extensionsAreInitialized() {
+ return extensions.isInitialized();
+ }
+
+ /**
+ * Called by the build code path to create a copy of the extensions for
+ * building the message.
+ */
+ private FieldSet<FieldDescriptor> buildExtensions() {
+ extensions.makeImmutable();
+ return extensions;
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return super.isInitialized() && extensionsAreInitialized();
+ }
+
+ /**
+ * Called by subclasses to parse an unknown field or an extension.
+ * @return {@code true} unless the tag is an end-group tag.
+ */
+ @Override
+ protected boolean parseUnknownField(
+ final CodedInputStream input,
+ final UnknownFieldSet.Builder unknownFields,
+ final ExtensionRegistryLite extensionRegistry,
+ final int tag) throws IOException {
+ return MessageReflection.mergeFieldFrom(
+ input, unknownFields, extensionRegistry, getDescriptorForType(),
+ new MessageReflection.BuilderAdapter(this), tag);
+ }
+
+ // ---------------------------------------------------------------
+ // Reflection
+
+ @Override
+ public Map<FieldDescriptor, Object> getAllFields() {
+ final Map<FieldDescriptor, Object> result = super.getAllFieldsMutable();
+ result.putAll(extensions.getAllFields());
+ return Collections.unmodifiableMap(result);
+ }
+
+ @Override
+ public Object getField(final FieldDescriptor field) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ final Object value = extensions.getField(field);
+ if (value == null) {
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ // Lacking an ExtensionRegistry, we have no way to determine the
+ // extension's real type, so we return a DynamicMessage.
+ return DynamicMessage.getDefaultInstance(field.getMessageType());
+ } else {
+ return field.getDefaultValue();
+ }
+ } else {
+ return value;
+ }
+ } else {
+ return super.getField(field);
+ }
+ }
+
+ @Override
+ public int getRepeatedFieldCount(final FieldDescriptor field) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ return extensions.getRepeatedFieldCount(field);
+ } else {
+ return super.getRepeatedFieldCount(field);
+ }
+ }
+
+ @Override
+ public Object getRepeatedField(final FieldDescriptor field,
+ final int index) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ return extensions.getRepeatedField(field, index);
+ } else {
+ return super.getRepeatedField(field, index);
+ }
+ }
+
+ @Override
+ public boolean hasField(final FieldDescriptor field) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ return extensions.hasField(field);
+ } else {
+ return super.hasField(field);
+ }
+ }
+
+ @Override
+ public BuilderType setField(final FieldDescriptor field,
+ final Object value) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ ensureExtensionsIsMutable();
+ extensions.setField(field, value);
+ onChanged();
+ return (BuilderType) this;
+ } else {
+ return super.setField(field, value);
+ }
+ }
+
+ @Override
+ public BuilderType clearField(final FieldDescriptor field) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ ensureExtensionsIsMutable();
+ extensions.clearField(field);
+ onChanged();
+ return (BuilderType) this;
+ } else {
+ return super.clearField(field);
+ }
+ }
+
+ @Override
+ public BuilderType setRepeatedField(final FieldDescriptor field,
+ final int index, final Object value) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ ensureExtensionsIsMutable();
+ extensions.setRepeatedField(field, index, value);
+ onChanged();
+ return (BuilderType) this;
+ } else {
+ return super.setRepeatedField(field, index, value);
+ }
+ }
+
+ @Override
+ public BuilderType addRepeatedField(final FieldDescriptor field,
+ final Object value) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ ensureExtensionsIsMutable();
+ extensions.addRepeatedField(field, value);
+ onChanged();
+ return (BuilderType) this;
+ } else {
+ return super.addRepeatedField(field, value);
+ }
+ }
+
+ protected final void mergeExtensionFields(final ExtendableMessage other) {
+ ensureExtensionsIsMutable();
+ extensions.mergeFrom(other.extensions);
+ onChanged();
+ }
+
+ private void verifyContainingType(final FieldDescriptor field) {
+ if (field.getContainingType() != getDescriptorForType()) {
+ throw new IllegalArgumentException(
+ "FieldDescriptor does not match message type.");
+ }
+ }
+ }
+
+ // -----------------------------------------------------------------
+
+ /**
+ * Gets the descriptor for an extension. The implementation depends on whether
+ * the extension is scoped in the top level of a file or scoped in a Message.
+ */
+ static interface ExtensionDescriptorRetriever {
+ FieldDescriptor getDescriptor();
+ }
+
+ /** For use by generated code only. */
+ public static <ContainingType extends Message, Type>
+ GeneratedExtension<ContainingType, Type>
+ 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<ContainingType, Type>(
+ 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 <ContainingType extends Message, Type>
+ GeneratedExtension<ContainingType, Type>
+ 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<ContainingType, Type>(
+ null, // ExtensionDescriptorRetriever is initialized in internalInit();
+ singularType,
+ defaultInstance,
+ Extension.ExtensionType.IMMUTABLE);
+ }
+
+ private abstract static class CachedDescriptorRetriever
+ implements ExtensionDescriptorRetriever {
+ private volatile FieldDescriptor descriptor;
+ protected abstract FieldDescriptor loadDescriptor();
+
+ @Override
+ public FieldDescriptor getDescriptor() {
+ if (descriptor == null) {
+ synchronized (this) {
+ if (descriptor == null) {
+ descriptor = loadDescriptor();
+ }
+ }
+ }
+ return descriptor;
+ }
+ }
+
+ /**
+ * 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 <ContainingType extends Message, Type>
+ GeneratedExtension<ContainingType, Type>
+ 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<ContainingType, Type>(
+ 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 <ContainingType extends Message, Type>
+ GeneratedExtension<ContainingType, Type>
+ 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<ContainingType, Type>(
+ 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.
+ *
+ * <p>For example, imagine you have the {@code .proto} file:
+ *
+ * <pre>
+ * option java_class = "MyProto";
+ *
+ * message Foo {
+ * extensions 1000 to max;
+ * }
+ *
+ * extend Foo {
+ * optional int32 bar;
+ * }
+ * </pre>
+ *
+ * <p>Then, {@code MyProto.Foo.bar} has type
+ * {@code GeneratedExtension<MyProto.Foo, Integer>}.
+ *
+ * <p>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<ContainingType, Type> {
+ // 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. */
+ @SuppressWarnings("unchecked")
+ private static Method getMethodOrDie(
+ final Class clazz, final String name, final Class... params) {
+ try {
+ return clazz.getMethod(name, params);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(
+ "Generated message class \"" + clazz.getName() +
+ "\" missing method \"" + name + "\".", e);
+ }
+ }
+
+ /** Calls invoke and throws a RuntimeException if it fails. */
+ private static Object invokeOrDie(
+ final Method method, final Object object, final Object... params) {
+ try {
+ return method.invoke(object, params);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(
+ "Couldn't use Java reflection to implement protocol message " +
+ "reflection.", e);
+ } catch (InvocationTargetException e) {
+ final Throwable cause = e.getCause();
+ if (cause instanceof RuntimeException) {
+ throw (RuntimeException) cause;
+ } else if (cause instanceof Error) {
+ throw (Error) cause;
+ } else {
+ throw new RuntimeException(
+ "Unexpected exception thrown by generated accessor method.", cause);
+ }
+ }
+ }
+
+ /**
+ * Gets the map field with the given field number. This method should be
+ * overridden in the generated message class if the message contains map
+ * fields.
+ *
+ * Unlike other field types, reflection support for map fields can't be
+ * implemented based on generated public API because we need to access a
+ * map field as a list in reflection API but the generated API only allows
+ * us to access it as a map. This method returns the underlying map field
+ * directly and thus enables us to access the map field as a list.
+ */
+ @SuppressWarnings({"rawtypes", "unused"})
+ protected MapField internalGetMapField(int fieldNumber) {
+ // Note that we can't use descriptor names here because this method will
+ // be called when descriptor is being initialized.
+ throw new RuntimeException(
+ "No map fields found in " + getClass().getName());
+ }
+
+ /**
+ * Users should ignore this class. This class provides the implementation
+ * with access to the fields of a message object using Java reflection.
+ */
+ public static final class FieldAccessorTable {
+
+ /**
+ * Construct a FieldAccessorTable for a particular message class. Only
+ * one FieldAccessorTable should ever be constructed per class.
+ *
+ * @param descriptor The type's descriptor.
+ * @param camelCaseNames The camelcase names of all fields in the message.
+ * These are used to derive the accessor method names.
+ * @param messageClass The message type.
+ * @param builderClass The builder type.
+ */
+ public FieldAccessorTable(
+ final Descriptor descriptor,
+ final String[] camelCaseNames,
+ final Class<? extends GeneratedMessage> messageClass,
+ final Class<? extends Builder> builderClass) {
+ this(descriptor, camelCaseNames);
+ ensureFieldAccessorsInitialized(messageClass, builderClass);
+ }
+
+ /**
+ * Construct a FieldAccessorTable for a particular message class without
+ * initializing FieldAccessors.
+ */
+ public FieldAccessorTable(
+ final Descriptor descriptor,
+ final String[] camelCaseNames) {
+ this.descriptor = descriptor;
+ this.camelCaseNames = camelCaseNames;
+ fields = new FieldAccessor[descriptor.getFields().size()];
+ oneofs = new OneofAccessor[descriptor.getOneofs().size()];
+ initialized = false;
+ }
+
+ private boolean isMapFieldEnabled(FieldDescriptor field) {
+ boolean result = true;
+ return result;
+ }
+
+ /**
+ * Ensures the field accessors are initialized. This method is thread-safe.
+ *
+ * @param messageClass The message type.
+ * @param builderClass The builder type.
+ * @return this
+ */
+ public FieldAccessorTable ensureFieldAccessorsInitialized(
+ Class<? extends GeneratedMessage> messageClass,
+ Class<? extends Builder> builderClass) {
+ if (initialized) { return this; }
+ synchronized (this) {
+ if (initialized) { return this; }
+ int fieldsSize = fields.length;
+ for (int i = 0; i < fieldsSize; i++) {
+ FieldDescriptor field = descriptor.getFields().get(i);
+ String containingOneofCamelCaseName = null;
+ if (field.getContainingOneof() != null) {
+ containingOneofCamelCaseName =
+ camelCaseNames[fieldsSize + field.getContainingOneof().getIndex()];
+ }
+ if (field.isRepeated()) {
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ if (field.isMapField() && isMapFieldEnabled(field)) {
+ fields[i] = new MapFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass);
+ } else {
+ fields[i] = new RepeatedMessageFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass);
+ }
+ } else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) {
+ fields[i] = new RepeatedEnumFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass);
+ } else {
+ fields[i] = new RepeatedFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass);
+ }
+ } else {
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ fields[i] = new SingularMessageFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass,
+ containingOneofCamelCaseName);
+ } else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) {
+ fields[i] = new SingularEnumFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass,
+ containingOneofCamelCaseName);
+ } else if (field.getJavaType() == FieldDescriptor.JavaType.STRING) {
+ fields[i] = new SingularStringFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass,
+ containingOneofCamelCaseName);
+ } else {
+ fields[i] = new SingularFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass,
+ containingOneofCamelCaseName);
+ }
+ }
+ }
+
+ int oneofsSize = oneofs.length;
+ for (int i = 0; i < oneofsSize; i++) {
+ oneofs[i] = new OneofAccessor(
+ descriptor, camelCaseNames[i + fieldsSize],
+ messageClass, builderClass);
+ }
+ initialized = true;
+ camelCaseNames = null;
+ return this;
+ }
+ }
+
+ private final Descriptor descriptor;
+ private final FieldAccessor[] fields;
+ private String[] camelCaseNames;
+ private final OneofAccessor[] oneofs;
+ private volatile boolean initialized;
+
+ /** Get the FieldAccessor for a particular field. */
+ private FieldAccessor getField(final FieldDescriptor field) {
+ if (field.getContainingType() != descriptor) {
+ throw new IllegalArgumentException(
+ "FieldDescriptor does not match message type.");
+ } else if (field.isExtension()) {
+ // If this type had extensions, it would subclass ExtendableMessage,
+ // which overrides the reflection interface to handle extensions.
+ throw new IllegalArgumentException(
+ "This type does not have extensions.");
+ }
+ return fields[field.getIndex()];
+ }
+
+ /** Get the OneofAccessor for a particular oneof. */
+ private OneofAccessor getOneof(final OneofDescriptor oneof) {
+ if (oneof.getContainingType() != descriptor) {
+ throw new IllegalArgumentException(
+ "OneofDescriptor does not match message type.");
+ }
+ return oneofs[oneof.getIndex()];
+ }
+
+ /**
+ * Abstract interface that provides access to a single field. This is
+ * implemented differently depending on the field type and cardinality.
+ */
+ private interface FieldAccessor {
+ Object get(GeneratedMessage message);
+ Object get(GeneratedMessage.Builder builder);
+ Object getRaw(GeneratedMessage message);
+ Object getRaw(GeneratedMessage.Builder builder);
+ void set(Builder builder, Object value);
+ Object getRepeated(GeneratedMessage message, int index);
+ Object getRepeated(GeneratedMessage.Builder builder, int index);
+ Object getRepeatedRaw(GeneratedMessage message, int index);
+ Object getRepeatedRaw(GeneratedMessage.Builder builder, int index);
+ void setRepeated(Builder builder,
+ int index, Object value);
+ void addRepeated(Builder builder, Object value);
+ boolean has(GeneratedMessage message);
+ boolean has(GeneratedMessage.Builder builder);
+ int getRepeatedCount(GeneratedMessage message);
+ int getRepeatedCount(GeneratedMessage.Builder builder);
+ void clear(Builder builder);
+ Message.Builder newBuilder();
+ Message.Builder getBuilder(GeneratedMessage.Builder builder);
+ Message.Builder getRepeatedBuilder(GeneratedMessage.Builder builder,
+ int index);
+ }
+
+ /** OneofAccessor provides access to a single oneof. */
+ private static class OneofAccessor {
+ OneofAccessor(
+ final Descriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessage> messageClass,
+ final Class<? extends Builder> builderClass) {
+ this.descriptor = descriptor;
+ caseMethod =
+ getMethodOrDie(messageClass, "get" + camelCaseName + "Case");
+ caseMethodBuilder =
+ getMethodOrDie(builderClass, "get" + camelCaseName + "Case");
+ clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName);
+ }
+
+ private final Descriptor descriptor;
+ private final Method caseMethod;
+ private final Method caseMethodBuilder;
+ private final Method clearMethod;
+
+ public boolean has(final GeneratedMessage message) {
+ if (((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber() == 0) {
+ return false;
+ }
+ return true;
+ }
+
+ public boolean has(GeneratedMessage.Builder builder) {
+ if (((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber() == 0) {
+ return false;
+ }
+ return true;
+ }
+
+ public FieldDescriptor get(final GeneratedMessage message) {
+ int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber();
+ if (fieldNumber > 0) {
+ return descriptor.findFieldByNumber(fieldNumber);
+ }
+ return null;
+ }
+
+ public FieldDescriptor get(GeneratedMessage.Builder builder) {
+ int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber();
+ if (fieldNumber > 0) {
+ return descriptor.findFieldByNumber(fieldNumber);
+ }
+ return null;
+ }
+
+ public void clear(final Builder builder) {
+ invokeOrDie(clearMethod, builder);
+ }
+ }
+
+ private static boolean supportFieldPresence(FileDescriptor file) {
+ return file.getSyntax() == FileDescriptor.Syntax.PROTO2;
+ }
+
+ // ---------------------------------------------------------------
+
+ private static class SingularFieldAccessor implements FieldAccessor {
+ SingularFieldAccessor(
+ final FieldDescriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessage> messageClass,
+ final Class<? extends Builder> builderClass,
+ final String containingOneofCamelCaseName) {
+ field = descriptor;
+ isOneofField = descriptor.getContainingOneof() != null;
+ hasHasMethod = supportFieldPresence(descriptor.getFile())
+ || (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE);
+ getMethod = getMethodOrDie(messageClass, "get" + camelCaseName);
+ getMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName);
+ type = getMethod.getReturnType();
+ setMethod = getMethodOrDie(builderClass, "set" + camelCaseName, type);
+ hasMethod =
+ hasHasMethod ? getMethodOrDie(messageClass, "has" + camelCaseName) : null;
+ hasMethodBuilder =
+ hasHasMethod ? getMethodOrDie(builderClass, "has" + camelCaseName) : null;
+ clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName);
+ caseMethod = isOneofField ? getMethodOrDie(
+ messageClass, "get" + containingOneofCamelCaseName + "Case") : null;
+ caseMethodBuilder = isOneofField ? getMethodOrDie(
+ builderClass, "get" + containingOneofCamelCaseName + "Case") : null;
+ }
+
+ // Note: We use Java reflection to call public methods rather than
+ // access private fields directly as this avoids runtime security
+ // checks.
+ protected final Class<?> type;
+ protected final Method getMethod;
+ protected final Method getMethodBuilder;
+ protected final Method setMethod;
+ protected final Method hasMethod;
+ protected final Method hasMethodBuilder;
+ protected final Method clearMethod;
+ protected final Method caseMethod;
+ protected final Method caseMethodBuilder;
+ protected final FieldDescriptor field;
+ protected final boolean isOneofField;
+ protected final boolean hasHasMethod;
+
+ private int getOneofFieldNumber(final GeneratedMessage message) {
+ return ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber();
+ }
+
+ private int getOneofFieldNumber(final GeneratedMessage.Builder builder) {
+ return ((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber();
+ }
+
+ @Override
+ public Object get(final GeneratedMessage message) {
+ return invokeOrDie(getMethod, message);
+ }
+ @Override
+ public Object get(GeneratedMessage.Builder builder) {
+ return invokeOrDie(getMethodBuilder, builder);
+ }
+ @Override
+ public Object getRaw(final GeneratedMessage message) {
+ return get(message);
+ }
+ @Override
+ public Object getRaw(GeneratedMessage.Builder builder) {
+ return get(builder);
+ }
+ @Override
+ public void set(final Builder builder, final Object value) {
+ invokeOrDie(setMethod, builder, value);
+ }
+ @Override
+ public Object getRepeated(final GeneratedMessage message, final int index) {
+ throw new UnsupportedOperationException(
+ "getRepeatedField() called on a singular field.");
+ }
+ @Override
+ public Object getRepeatedRaw(final GeneratedMessage message, final int index) {
+ throw new UnsupportedOperationException(
+ "getRepeatedFieldRaw() called on a singular field.");
+ }
+ @Override
+ public Object getRepeated(GeneratedMessage.Builder builder, int index) {
+ throw new UnsupportedOperationException(
+ "getRepeatedField() called on a singular field.");
+ }
+ @Override
+ public Object getRepeatedRaw(GeneratedMessage.Builder builder, int index) {
+ throw new UnsupportedOperationException(
+ "getRepeatedFieldRaw() called on a singular field.");
+ }
+ @Override
+ public void setRepeated(final Builder builder, final int index, final Object value) {
+ throw new UnsupportedOperationException(
+ "setRepeatedField() called on a singular field.");
+ }
+ @Override
+ public void addRepeated(final Builder builder, final Object value) {
+ throw new UnsupportedOperationException(
+ "addRepeatedField() called on a singular field.");
+ }
+ @Override
+ public boolean has(final GeneratedMessage message) {
+ if (!hasHasMethod) {
+ if (isOneofField) {
+ return getOneofFieldNumber(message) == field.getNumber();
+ }
+ return !get(message).equals(field.getDefaultValue());
+ }
+ return (Boolean) invokeOrDie(hasMethod, message);
+ }
+ @Override
+ public boolean has(GeneratedMessage.Builder builder) {
+ if (!hasHasMethod) {
+ if (isOneofField) {
+ return getOneofFieldNumber(builder) == field.getNumber();
+ }
+ return !get(builder).equals(field.getDefaultValue());
+ }
+ return (Boolean) invokeOrDie(hasMethodBuilder, builder);
+ }
+ @Override
+ public int getRepeatedCount(final GeneratedMessage message) {
+ throw new UnsupportedOperationException(
+ "getRepeatedFieldSize() called on a singular field.");
+ }
+ @Override
+ public int getRepeatedCount(GeneratedMessage.Builder builder) {
+ throw new UnsupportedOperationException(
+ "getRepeatedFieldSize() called on a singular field.");
+ }
+ @Override
+ public void clear(final Builder builder) {
+ invokeOrDie(clearMethod, builder);
+ }
+ @Override
+ public Message.Builder newBuilder() {
+ throw new UnsupportedOperationException(
+ "newBuilderForField() called on a non-Message type.");
+ }
+ @Override
+ public Message.Builder getBuilder(GeneratedMessage.Builder builder) {
+ throw new UnsupportedOperationException(
+ "getFieldBuilder() called on a non-Message type.");
+ }
+ @Override
+ public Message.Builder getRepeatedBuilder(GeneratedMessage.Builder builder, int index) {
+ throw new UnsupportedOperationException(
+ "getRepeatedFieldBuilder() called on a non-Message type.");
+ }
+ }
+
+ private static class RepeatedFieldAccessor implements FieldAccessor {
+ protected final Class type;
+ protected final Method getMethod;
+ protected final Method getMethodBuilder;
+ protected final Method getRepeatedMethod;
+ protected final Method getRepeatedMethodBuilder;
+ protected final Method setRepeatedMethod;
+ protected final Method addRepeatedMethod;
+ protected final Method getCountMethod;
+ protected final Method getCountMethodBuilder;
+ protected final Method clearMethod;
+
+ RepeatedFieldAccessor(
+ final FieldDescriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessage> messageClass,
+ final Class<? extends Builder> builderClass) {
+ getMethod = getMethodOrDie(messageClass,
+ "get" + camelCaseName + "List");
+ getMethodBuilder = getMethodOrDie(builderClass,
+ "get" + camelCaseName + "List");
+ getRepeatedMethod =
+ getMethodOrDie(messageClass, "get" + camelCaseName, Integer.TYPE);
+ getRepeatedMethodBuilder =
+ getMethodOrDie(builderClass, "get" + camelCaseName, Integer.TYPE);
+ type = getRepeatedMethod.getReturnType();
+ setRepeatedMethod =
+ getMethodOrDie(builderClass, "set" + camelCaseName,
+ Integer.TYPE, type);
+ addRepeatedMethod =
+ getMethodOrDie(builderClass, "add" + camelCaseName, type);
+ getCountMethod =
+ getMethodOrDie(messageClass, "get" + camelCaseName + "Count");
+ getCountMethodBuilder =
+ getMethodOrDie(builderClass, "get" + camelCaseName + "Count");
+
+ clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName);
+ }
+
+ @Override
+ public Object get(final GeneratedMessage message) {
+ return invokeOrDie(getMethod, message);
+ }
+ @Override
+ public Object get(GeneratedMessage.Builder builder) {
+ return invokeOrDie(getMethodBuilder, builder);
+ }
+ @Override
+ public Object getRaw(final GeneratedMessage message) {
+ return get(message);
+ }
+ @Override
+ public Object getRaw(GeneratedMessage.Builder builder) {
+ return get(builder);
+ }
+ @Override
+ public void set(final Builder builder, final Object value) {
+ // Add all the elements individually. This serves two purposes:
+ // 1) Verifies that each element has the correct type.
+ // 2) Insures that the caller cannot modify the list later on and
+ // have the modifications be reflected in the message.
+ clear(builder);
+ for (final Object element : (List<?>) value) {
+ addRepeated(builder, element);
+ }
+ }
+ @Override
+ public Object getRepeated(final GeneratedMessage message, final int index) {
+ return invokeOrDie(getRepeatedMethod, message, index);
+ }
+ @Override
+ public Object getRepeated(GeneratedMessage.Builder builder, int index) {
+ return invokeOrDie(getRepeatedMethodBuilder, builder, index);
+ }
+ @Override
+ public Object getRepeatedRaw(GeneratedMessage message, int index) {
+ return getRepeated(message, index);
+ }
+ @Override
+ public Object getRepeatedRaw(GeneratedMessage.Builder builder, int index) {
+ return getRepeated(builder, index);
+ }
+ @Override
+ public void setRepeated(final Builder builder, final int index, final Object value) {
+ invokeOrDie(setRepeatedMethod, builder, index, value);
+ }
+ @Override
+ public void addRepeated(final Builder builder, final Object value) {
+ invokeOrDie(addRepeatedMethod, builder, value);
+ }
+ @Override
+ public boolean has(final GeneratedMessage message) {
+ throw new UnsupportedOperationException(
+ "hasField() called on a repeated field.");
+ }
+ @Override
+ public boolean has(GeneratedMessage.Builder builder) {
+ throw new UnsupportedOperationException(
+ "hasField() called on a repeated field.");
+ }
+ @Override
+ public int getRepeatedCount(final GeneratedMessage message) {
+ return (Integer) invokeOrDie(getCountMethod, message);
+ }
+ @Override
+ public int getRepeatedCount(GeneratedMessage.Builder builder) {
+ return (Integer) invokeOrDie(getCountMethodBuilder, builder);
+ }
+ @Override
+ public void clear(final Builder builder) {
+ invokeOrDie(clearMethod, builder);
+ }
+ @Override
+ public Message.Builder newBuilder() {
+ throw new UnsupportedOperationException(
+ "newBuilderForField() called on a non-Message type.");
+ }
+ @Override
+ public Message.Builder getBuilder(GeneratedMessage.Builder builder) {
+ throw new UnsupportedOperationException(
+ "getFieldBuilder() called on a non-Message type.");
+ }
+ @Override
+ public Message.Builder getRepeatedBuilder(GeneratedMessage.Builder builder, int index) {
+ throw new UnsupportedOperationException(
+ "getRepeatedFieldBuilder() called on a non-Message type.");
+ }
+ }
+
+ private static class MapFieldAccessor implements FieldAccessor {
+ MapFieldAccessor(
+ final FieldDescriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessage> messageClass,
+ final Class<? extends Builder> builderClass) {
+ field = descriptor;
+ Method getDefaultInstanceMethod =
+ getMethodOrDie(messageClass, "getDefaultInstance");
+ MapField defaultMapField = getMapField(
+ (GeneratedMessage) invokeOrDie(getDefaultInstanceMethod, null));
+ mapEntryMessageDefaultInstance =
+ defaultMapField.getMapEntryMessageDefaultInstance();
+ }
+
+ private final FieldDescriptor field;
+ private final Message mapEntryMessageDefaultInstance;
+
+ private MapField<?, ?> getMapField(GeneratedMessage message) {
+ return (MapField<?, ?>) message.internalGetMapField(field.getNumber());
+ }
+
+ private MapField<?, ?> getMapField(GeneratedMessage.Builder builder) {
+ return (MapField<?, ?>) builder.internalGetMapField(field.getNumber());
+ }
+
+ private MapField<?, ?> getMutableMapField(
+ GeneratedMessage.Builder builder) {
+ return (MapField<?, ?>) builder.internalGetMutableMapField(
+ field.getNumber());
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object get(GeneratedMessage message) {
+ List result = new ArrayList();
+ for (int i = 0; i < getRepeatedCount(message); i++) {
+ result.add(getRepeated(message, i));
+ }
+ return Collections.unmodifiableList(result);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object get(Builder builder) {
+ List result = new ArrayList();
+ for (int i = 0; i < getRepeatedCount(builder); i++) {
+ result.add(getRepeated(builder, i));
+ }
+ return Collections.unmodifiableList(result);
+ }
+
+ @Override
+ public Object getRaw(GeneratedMessage message) {
+ return get(message);
+ }
+
+ @Override
+ public Object getRaw(GeneratedMessage.Builder builder) {
+ return get(builder);
+ }
+
+ @Override
+ public void set(Builder builder, Object value) {
+ clear(builder);
+ for (Object entry : (List) value) {
+ addRepeated(builder, entry);
+ }
+ }
+
+ @Override
+ public Object getRepeated(GeneratedMessage message, int index) {
+ return getMapField(message).getList().get(index);
+ }
+
+ @Override
+ public Object getRepeated(Builder builder, int index) {
+ return getMapField(builder).getList().get(index);
+ }
+
+ @Override
+ public Object getRepeatedRaw(GeneratedMessage message, int index) {
+ return getRepeated(message, index);
+ }
+
+ @Override
+ 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);
+ }
+
+ @Override
+ public void addRepeated(Builder builder, Object value) {
+ getMutableMapField(builder).getMutableList().add((Message) value);
+ }
+
+ @Override
+ public boolean has(GeneratedMessage message) {
+ throw new UnsupportedOperationException(
+ "hasField() is not supported for repeated fields.");
+ }
+
+ @Override
+ public boolean has(Builder builder) {
+ throw new UnsupportedOperationException(
+ "hasField() is not supported for repeated fields.");
+ }
+
+ @Override
+ public int getRepeatedCount(GeneratedMessage message) {
+ return getMapField(message).getList().size();
+ }
+
+ @Override
+ public int getRepeatedCount(Builder builder) {
+ return getMapField(builder).getList().size();
+ }
+
+ @Override
+ public void clear(Builder builder) {
+ getMutableMapField(builder).getMutableList().clear();
+ }
+
+ @Override
+ public com.google.protobuf.Message.Builder newBuilder() {
+ return mapEntryMessageDefaultInstance.newBuilderForType();
+ }
+
+ @Override
+ public com.google.protobuf.Message.Builder getBuilder(Builder builder) {
+ throw new UnsupportedOperationException(
+ "Nested builder not supported for map fields.");
+ }
+
+ @Override
+ public com.google.protobuf.Message.Builder getRepeatedBuilder(Builder builder, int index) {
+ throw new UnsupportedOperationException(
+ "Nested builder not supported for map fields.");
+ }
+ }
+
+ // ---------------------------------------------------------------
+
+ private static final class SingularEnumFieldAccessor
+ extends SingularFieldAccessor {
+ SingularEnumFieldAccessor(
+ final FieldDescriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessage> messageClass,
+ final Class<? extends Builder> builderClass,
+ final String containingOneofCamelCaseName) {
+ super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName);
+
+ enumDescriptor = descriptor.getEnumType();
+
+ valueOfMethod = getMethodOrDie(type, "valueOf",
+ EnumValueDescriptor.class);
+ getValueDescriptorMethod =
+ getMethodOrDie(type, "getValueDescriptor");
+
+ supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue();
+ if (supportUnknownEnumValue) {
+ getValueMethod =
+ getMethodOrDie(messageClass, "get" + camelCaseName + "Value");
+ getValueMethodBuilder =
+ getMethodOrDie(builderClass, "get" + camelCaseName + "Value");
+ setValueMethod =
+ getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class);
+ }
+ }
+
+ private EnumDescriptor enumDescriptor;
+
+ private Method valueOfMethod;
+ private Method getValueDescriptorMethod;
+
+ private boolean supportUnknownEnumValue;
+ private Method getValueMethod;
+ private Method getValueMethodBuilder;
+ private Method setValueMethod;
+
+ @Override
+ public Object get(final GeneratedMessage message) {
+ if (supportUnknownEnumValue) {
+ int value = (Integer) invokeOrDie(getValueMethod, message);
+ return enumDescriptor.findValueByNumberCreatingIfUnknown(value);
+ }
+ return invokeOrDie(getValueDescriptorMethod, super.get(message));
+ }
+
+ @Override
+ public Object get(final GeneratedMessage.Builder builder) {
+ if (supportUnknownEnumValue) {
+ int value = (Integer) invokeOrDie(getValueMethodBuilder, builder);
+ return enumDescriptor.findValueByNumberCreatingIfUnknown(value);
+ }
+ return invokeOrDie(getValueDescriptorMethod, super.get(builder));
+ }
+
+ @Override
+ public void set(final Builder builder, final Object value) {
+ if (supportUnknownEnumValue) {
+ invokeOrDie(setValueMethod, builder,
+ ((EnumValueDescriptor) value).getNumber());
+ return;
+ }
+ super.set(builder, invokeOrDie(valueOfMethod, null, value));
+ }
+ }
+
+ private static final class RepeatedEnumFieldAccessor
+ extends RepeatedFieldAccessor {
+ RepeatedEnumFieldAccessor(
+ final FieldDescriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessage> messageClass,
+ final Class<? extends Builder> builderClass) {
+ super(descriptor, camelCaseName, messageClass, builderClass);
+
+ enumDescriptor = descriptor.getEnumType();
+
+ valueOfMethod = getMethodOrDie(type, "valueOf",
+ EnumValueDescriptor.class);
+ getValueDescriptorMethod =
+ getMethodOrDie(type, "getValueDescriptor");
+
+ supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue();
+ if (supportUnknownEnumValue) {
+ getRepeatedValueMethod =
+ getMethodOrDie(messageClass, "get" + camelCaseName + "Value", int.class);
+ getRepeatedValueMethodBuilder =
+ getMethodOrDie(builderClass, "get" + camelCaseName + "Value", int.class);
+ setRepeatedValueMethod =
+ getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class, int.class);
+ addRepeatedValueMethod =
+ getMethodOrDie(builderClass, "add" + camelCaseName + "Value", int.class);
+ }
+ }
+ private EnumDescriptor enumDescriptor;
+
+ private final Method valueOfMethod;
+ private final Method getValueDescriptorMethod;
+
+ private boolean supportUnknownEnumValue;
+ private Method getRepeatedValueMethod;
+ private Method getRepeatedValueMethodBuilder;
+ private Method setRepeatedValueMethod;
+ private Method addRepeatedValueMethod;
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object get(final GeneratedMessage message) {
+ final List newList = new ArrayList();
+ final int size = getRepeatedCount(message);
+ for (int i = 0; i < size; i++) {
+ newList.add(getRepeated(message, i));
+ }
+ return Collections.unmodifiableList(newList);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object get(final GeneratedMessage.Builder builder) {
+ final List newList = new ArrayList();
+ final int size = getRepeatedCount(builder);
+ for (int i = 0; i < size; i++) {
+ newList.add(getRepeated(builder, i));
+ }
+ return Collections.unmodifiableList(newList);
+ }
+
+ @Override
+ public Object getRepeated(final GeneratedMessage message,
+ final int index) {
+ if (supportUnknownEnumValue) {
+ int value = (Integer) invokeOrDie(getRepeatedValueMethod, message, index);
+ return enumDescriptor.findValueByNumberCreatingIfUnknown(value);
+ }
+ return invokeOrDie(getValueDescriptorMethod,
+ super.getRepeated(message, index));
+ }
+ @Override
+ public Object getRepeated(final GeneratedMessage.Builder builder,
+ final int index) {
+ if (supportUnknownEnumValue) {
+ int value = (Integer) invokeOrDie(getRepeatedValueMethodBuilder, builder, index);
+ return enumDescriptor.findValueByNumberCreatingIfUnknown(value);
+ }
+ return invokeOrDie(getValueDescriptorMethod,
+ super.getRepeated(builder, index));
+ }
+ @Override
+ public void setRepeated(final Builder builder,
+ final int index, final Object value) {
+ if (supportUnknownEnumValue) {
+ invokeOrDie(setRepeatedValueMethod, builder, index,
+ ((EnumValueDescriptor) value).getNumber());
+ return;
+ }
+ super.setRepeated(builder, index, invokeOrDie(valueOfMethod, null,
+ value));
+ }
+ @Override
+ public void addRepeated(final Builder builder, final Object value) {
+ if (supportUnknownEnumValue) {
+ invokeOrDie(addRepeatedValueMethod, builder,
+ ((EnumValueDescriptor) value).getNumber());
+ return;
+ }
+ super.addRepeated(builder, invokeOrDie(valueOfMethod, null, value));
+ }
+ }
+
+ // ---------------------------------------------------------------
+
+ /**
+ * Field accessor for string fields.
+ *
+ * <p>This class makes getFooBytes() and setFooBytes() available for
+ * reflection API so that reflection based serialize/parse functions can
+ * access the raw bytes of the field to preserve non-UTF8 bytes in the
+ * string.
+ *
+ * <p>This ensures the serialize/parse round-trip safety, which is important
+ * for servers which forward messages.
+ */
+ private static final class SingularStringFieldAccessor
+ extends SingularFieldAccessor {
+ SingularStringFieldAccessor(
+ final FieldDescriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessage> messageClass,
+ final Class<? extends Builder> builderClass,
+ final String containingOneofCamelCaseName) {
+ super(descriptor, camelCaseName, messageClass, builderClass,
+ containingOneofCamelCaseName);
+ getBytesMethod = getMethodOrDie(messageClass,
+ "get" + camelCaseName + "Bytes");
+ getBytesMethodBuilder = getMethodOrDie(builderClass,
+ "get" + camelCaseName + "Bytes");
+ setBytesMethodBuilder = getMethodOrDie(builderClass,
+ "set" + camelCaseName + "Bytes", ByteString.class);
+ }
+
+ private final Method getBytesMethod;
+ private final Method getBytesMethodBuilder;
+ private final Method setBytesMethodBuilder;
+
+ @Override
+ public Object getRaw(final GeneratedMessage message) {
+ return invokeOrDie(getBytesMethod, message);
+ }
+
+ @Override
+ public Object getRaw(GeneratedMessage.Builder builder) {
+ return invokeOrDie(getBytesMethodBuilder, builder);
+ }
+
+ @Override
+ public void set(GeneratedMessage.Builder builder, Object value) {
+ if (value instanceof ByteString) {
+ invokeOrDie(setBytesMethodBuilder, builder, value);
+ } else {
+ super.set(builder, value);
+ }
+ }
+ }
+
+ // ---------------------------------------------------------------
+
+ private static final class SingularMessageFieldAccessor
+ extends SingularFieldAccessor {
+ SingularMessageFieldAccessor(
+ final FieldDescriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessage> messageClass,
+ final Class<? extends Builder> builderClass,
+ final String containingOneofCamelCaseName) {
+ super(descriptor, camelCaseName, messageClass, builderClass,
+ containingOneofCamelCaseName);
+
+ newBuilderMethod = getMethodOrDie(type, "newBuilder");
+ getBuilderMethodBuilder =
+ getMethodOrDie(builderClass, "get" + camelCaseName + "Builder");
+ }
+
+ private final Method newBuilderMethod;
+ private final Method getBuilderMethodBuilder;
+
+ private Object coerceType(final Object value) {
+ if (type.isInstance(value)) {
+ return value;
+ } else {
+ // 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 ((Message.Builder) invokeOrDie(newBuilderMethod, null))
+ .mergeFrom((Message) value).buildPartial();
+ }
+ }
+
+ @Override
+ public void set(final Builder builder, final Object value) {
+ super.set(builder, coerceType(value));
+ }
+ @Override
+ public Message.Builder newBuilder() {
+ return (Message.Builder) invokeOrDie(newBuilderMethod, null);
+ }
+ @Override
+ public Message.Builder getBuilder(GeneratedMessage.Builder builder) {
+ return (Message.Builder) invokeOrDie(getBuilderMethodBuilder, builder);
+ }
+ }
+
+ private static final class RepeatedMessageFieldAccessor
+ extends RepeatedFieldAccessor {
+ RepeatedMessageFieldAccessor(
+ final FieldDescriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessage> messageClass,
+ final Class<? extends Builder> builderClass) {
+ super(descriptor, camelCaseName, messageClass, builderClass);
+
+ newBuilderMethod = getMethodOrDie(type, "newBuilder");
+ getBuilderMethodBuilder = getMethodOrDie(builderClass,
+ "get" + camelCaseName + "Builder", Integer.TYPE);
+ }
+
+ private final Method newBuilderMethod;
+ private final Method getBuilderMethodBuilder;
+
+ private Object coerceType(final Object value) {
+ if (type.isInstance(value)) {
+ return value;
+ } else {
+ // 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 ((Message.Builder) invokeOrDie(newBuilderMethod, null))
+ .mergeFrom((Message) value).build();
+ }
+ }
+
+ @Override
+ public void setRepeated(final Builder builder,
+ final int index, final Object value) {
+ super.setRepeated(builder, index, coerceType(value));
+ }
+ @Override
+ public void addRepeated(final Builder builder, final Object value) {
+ super.addRepeated(builder, coerceType(value));
+ }
+ @Override
+ public Message.Builder newBuilder() {
+ return (Message.Builder) invokeOrDie(newBuilderMethod, null);
+ }
+ @Override
+ public Message.Builder getRepeatedBuilder(
+ final GeneratedMessage.Builder builder, final int index) {
+ return (Message.Builder) invokeOrDie(
+ getBuilderMethodBuilder, builder, index);
+ }
+ }
+ }
+
+ /**
+ * Replaces this object in the output stream with a serialized form.
+ * Part of Java's serialization magic. Generated sub-classes must override
+ * this method by calling {@code return super.writeReplace();}
+ * @return a SerializedForm of this message
+ */
+ protected Object writeReplace() throws ObjectStreamException {
+ return new GeneratedMessageLite.SerializedForm(this);
+ }
+
+ /**
+ * Checks that the {@link Extension} is non-Lite and returns it as a
+ * {@link GeneratedExtension}.
+ */
+ private static <MessageType extends ExtendableMessage<MessageType>, T>
+ Extension<MessageType, T> checkNotLite(
+ ExtensionLite<MessageType, T> extension) {
+ if (extension.isLite()) {
+ throw new IllegalArgumentException("Expected non-lite extension.");
+ }
+
+ return (Extension<MessageType, T>) extension;
+ }
+
+ protected static int computeStringSize(final int fieldNumber, final Object value) {
+ if (value instanceof String) {
+ return CodedOutputStream.computeStringSize(fieldNumber, (String) value);
+ } else {
+ return CodedOutputStream.computeBytesSize(fieldNumber, (ByteString) value);
+ }
+ }
+
+ protected static int computeStringSizeNoTag(final Object value) {
+ if (value instanceof String) {
+ return CodedOutputStream.computeStringSizeNoTag((String) value);
+ } else {
+ return CodedOutputStream.computeBytesSizeNoTag((ByteString) value);
+ }
+ }
+
+ protected static void writeString(
+ CodedOutputStream output, final int fieldNumber, final Object value) throws IOException {
+ if (value instanceof String) {
+ output.writeString(fieldNumber, (String) value);
+ } else {
+ output.writeBytes(fieldNumber, (ByteString) value);
+ }
+ }
+
+ protected static void writeStringNoTag(
+ CodedOutputStream output, final Object value) throws IOException {
+ if (value instanceof String) {
+ output.writeStringNoTag((String) value);
+ } else {
+ output.writeBytesNoTag((ByteString) value);
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java
new file mode 100644
index 0000000000..2d7fd33413
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageLite.java
@@ -0,0 +1,2421 @@
+// 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 com.google.protobuf.GeneratedMessageLite.EqualsVisitor.NotEqualsException;
+import com.google.protobuf.Internal.BooleanList;
+import com.google.protobuf.Internal.DoubleList;
+import com.google.protobuf.Internal.FloatList;
+import com.google.protobuf.Internal.IntList;
+import com.google.protobuf.Internal.LongList;
+import com.google.protobuf.Internal.ProtobufList;
+import com.google.protobuf.WireFormat.FieldType;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Lite version of {@link GeneratedMessage}.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public abstract class GeneratedMessageLite<
+ MessageType extends GeneratedMessageLite<MessageType, BuilderType>,
+ BuilderType extends GeneratedMessageLite.Builder<MessageType, BuilderType>>
+ extends AbstractMessageLite<MessageType, BuilderType> {
+
+ /** For use by generated code only. Lazily initialized to reduce allocations. */
+ protected UnknownFieldSetLite unknownFields = UnknownFieldSetLite.getDefaultInstance();
+
+ /** For use by generated code only. */
+ protected int memoizedSerializedSize = -1;
+
+ @Override
+ @SuppressWarnings("unchecked") // Guaranteed by runtime.
+ public final Parser<MessageType> getParserForType() {
+ return (Parser<MessageType>) dynamicMethod(MethodToInvoke.GET_PARSER);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked") // Guaranteed by runtime.
+ public final MessageType getDefaultInstanceForType() {
+ return (MessageType) dynamicMethod(MethodToInvoke.GET_DEFAULT_INSTANCE);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked") // Guaranteed by runtime.
+ public final BuilderType newBuilderForType() {
+ return (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER);
+ }
+
+ /**
+ * A reflective toString function. This is primarily intended as a developer aid, while keeping
+ * binary size down. The first line of the {@code toString()} representation includes a commented
+ * version of {@code super.toString()} to act as an indicator that this should not be relied on
+ * for comparisons.
+ * <p>
+ * NOTE: This method relies on the field getter methods not being stripped or renamed by proguard.
+ * If they are, the fields will not be included in the returned string representation.
+ * <p>
+ * NOTE: This implementation is liable to change in the future, and should not be relied on in
+ * code.
+ */
+ @Override
+ public String toString() {
+ return MessageLiteToString.toString(this, super.toString());
+ }
+
+ @SuppressWarnings("unchecked") // Guaranteed by runtime
+ @Override
+ public int hashCode() {
+ if (memoizedHashCode == 0) {
+ HashCodeVisitor visitor = new HashCodeVisitor();
+ visit(visitor, (MessageType) this);
+ memoizedHashCode = visitor.hashCode;
+ }
+ return memoizedHashCode;
+ }
+
+ @SuppressWarnings("unchecked") // Guaranteed by runtime
+ int hashCode(HashCodeVisitor visitor) {
+ if (memoizedHashCode == 0) {
+ int inProgressHashCode = visitor.hashCode;
+ visitor.hashCode = 0;
+ visit(visitor, (MessageType) this);
+ memoizedHashCode = visitor.hashCode;
+ visitor.hashCode = inProgressHashCode;
+ }
+ return memoizedHashCode;
+ }
+
+ @SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime
+ @Override
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+
+ if (!getDefaultInstanceForType().getClass().isInstance(other)) {
+ return false;
+ }
+
+ try {
+ visit(EqualsVisitor.INSTANCE, (MessageType) other);
+ } catch (NotEqualsException e) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Same as {@link #equals(Object)} but throws {@code NotEqualsException}.
+ */
+ @SuppressWarnings("unchecked") // Guaranteed by isInstance + runtime
+ boolean equals(EqualsVisitor visitor, MessageLite other) {
+ if (this == other) {
+ return true;
+ }
+
+ if (!getDefaultInstanceForType().getClass().isInstance(other)) {
+ return false;
+ }
+
+ visit(visitor, (MessageType) other);
+ return true;
+ }
+
+ // The general strategy for unknown fields is to use an UnknownFieldSetLite that is treated as
+ // mutable during the parsing constructor and immutable after. This allows us to avoid
+ // any unnecessary intermediary allocations while reducing the generated code size.
+
+ /**
+ * Lazily initializes unknown fields.
+ */
+ private final void ensureUnknownFieldsInitialized() {
+ if (unknownFields == UnknownFieldSetLite.getDefaultInstance()) {
+ unknownFields = UnknownFieldSetLite.newInstance();
+ }
+ }
+
+ /**
+ * Called by subclasses to parse an unknown field. For use by generated code only.
+ *
+ * @return {@code true} unless the tag is an end-group tag.
+ */
+ protected boolean parseUnknownField(int tag, CodedInputStream input) throws IOException {
+ // This will avoid the allocation of unknown fields when a group tag is encountered.
+ if (WireFormat.getTagWireType(tag) == WireFormat.WIRETYPE_END_GROUP) {
+ return false;
+ }
+
+ ensureUnknownFieldsInitialized();
+ return unknownFields.mergeFieldFrom(tag, input);
+ }
+
+ /**
+ * Called by subclasses to parse an unknown field. For use by generated code only.
+ */
+ protected void mergeVarintField(int tag, int value) {
+ ensureUnknownFieldsInitialized();
+ unknownFields.mergeVarintField(tag, value);
+ }
+
+ /**
+ * Called by subclasses to parse an unknown field. For use by generated code only.
+ */
+ protected void mergeLengthDelimitedField(int fieldNumber, ByteString value) {
+ ensureUnknownFieldsInitialized();
+ unknownFields.mergeLengthDelimitedField(fieldNumber, value);
+ }
+
+ /**
+ * Called by subclasses to complete parsing. For use by generated code only.
+ */
+ protected void makeImmutable() {
+ dynamicMethod(MethodToInvoke.MAKE_IMMUTABLE);
+
+ unknownFields.makeImmutable();
+ }
+
+ @Override
+ public final boolean isInitialized() {
+ return dynamicMethod(MethodToInvoke.IS_INITIALIZED, Boolean.TRUE) != null;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public final BuilderType toBuilder() {
+ BuilderType builder = (BuilderType) dynamicMethod(MethodToInvoke.NEW_BUILDER);
+ builder.mergeFrom((MessageType) this);
+ return builder;
+ }
+
+ /**
+ * Defines which method path to invoke in {@link GeneratedMessageLite
+ * #dynamicMethod(MethodToInvoke, Object...)}.
+ * <p>
+ * For use by generated code only.
+ */
+ public static enum MethodToInvoke {
+ // Rely on/modify instance state
+ IS_INITIALIZED,
+ VISIT,
+ MERGE_FROM_STREAM,
+ MAKE_IMMUTABLE,
+
+ // Rely on static state
+ NEW_MUTABLE_INSTANCE,
+ NEW_BUILDER,
+ GET_DEFAULT_INSTANCE,
+ GET_PARSER;
+ }
+
+ /**
+ * A method that implements different types of operations described in {@link MethodToInvoke}.
+ * Theses different kinds of operations are required to implement message-level operations for
+ * builders in the runtime. This method bundles those operations to reduce the generated methods
+ * count.
+ * <ul>
+ * <li>{@code MERGE_FROM_STREAM} is parameterized with an {@link CodedInputStream} and
+ * {@link ExtensionRegistryLite}. It consumes the input stream, parsing the contents into the
+ * returned protocol buffer. If parsing throws an {@link InvalidProtocolBufferException}, the
+ * implementation wraps it in a RuntimeException.
+ * <li>{@code NEW_INSTANCE} returns a new instance of the protocol buffer that has not yet been
+ * made immutable. See {@code MAKE_IMMUTABLE}.
+ * <li>{@code IS_INITIALIZED} is parameterized with a {@code Boolean} detailing whether to
+ * memoize. It returns {@code null} for false and the default instance for true. We optionally
+ * memoize to support the Builder case, where memoization is not desired.
+ * <li>{@code NEW_BUILDER} returns a {@code BuilderType} instance.
+ * <li>{@code VISIT} is parameterized with a {@code Visitor} and a {@code MessageType} and
+ * recursively iterates through the fields side by side between this and the instance.
+ * <li>{@code MAKE_IMMUTABLE} sets all internal fields to an immutable state.
+ * </ul>
+ * This method, plus the implementation of the Builder, enables the Builder class to be proguarded
+ * away entirely on Android.
+ * <p>
+ * For use by generated code only.
+ */
+ protected abstract Object dynamicMethod(MethodToInvoke method, Object arg0, Object arg1);
+
+ /**
+ * Same as {@link #dynamicMethod(MethodToInvoke, Object, Object)} with {@code null} padding.
+ */
+ protected Object dynamicMethod(MethodToInvoke method, Object arg0) {
+ return dynamicMethod(method, arg0, null);
+ }
+
+ /**
+ * Same as {@link #dynamicMethod(MethodToInvoke, Object, Object)} with {@code null} padding.
+ */
+ protected Object dynamicMethod(MethodToInvoke method) {
+ return dynamicMethod(method, null, null);
+ }
+
+ void visit(Visitor visitor, MessageType other) {
+ dynamicMethod(MethodToInvoke.VISIT, visitor, other);
+ unknownFields = visitor.visitUnknownFields(unknownFields, other.unknownFields);
+ }
+
+ /**
+ * Merge some unknown fields into the {@link UnknownFieldSetLite} for this
+ * message.
+ *
+ * <p>For use by generated code only.
+ */
+ protected final void mergeUnknownFields(UnknownFieldSetLite unknownFields) {
+ this.unknownFields = UnknownFieldSetLite.mutableCopyOf(this.unknownFields, unknownFields);
+ }
+
+ @SuppressWarnings("unchecked")
+ public abstract static class Builder<
+ MessageType extends GeneratedMessageLite<MessageType, BuilderType>,
+ BuilderType extends Builder<MessageType, BuilderType>>
+ extends AbstractMessageLite.Builder<MessageType, BuilderType> {
+
+ private final MessageType defaultInstance;
+ protected MessageType instance;
+ protected boolean isBuilt;
+
+ protected Builder(MessageType defaultInstance) {
+ this.defaultInstance = defaultInstance;
+ this.instance =
+ (MessageType) defaultInstance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE);
+ isBuilt = false;
+ }
+
+ /**
+ * Called before any method that would mutate the builder to ensure that it correctly copies
+ * any state before the write happens to preserve immutability guarantees.
+ */
+ protected void copyOnWrite() {
+ if (isBuilt) {
+ MessageType newInstance =
+ (MessageType) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE);
+ newInstance.visit(MergeFromVisitor.INSTANCE, instance);
+ instance = newInstance;
+ isBuilt = false;
+ }
+ }
+
+ @Override
+ public final boolean isInitialized() {
+ return GeneratedMessageLite.isInitialized(instance, false /* shouldMemoize */);
+ }
+
+ @Override
+ public final BuilderType clear() {
+ // No need to copy on write since we're dropping the instance anyways.
+ instance = (MessageType) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE);
+ return (BuilderType) this;
+ }
+
+ @Override
+ public BuilderType clone() {
+ BuilderType builder =
+ (BuilderType) getDefaultInstanceForType().newBuilderForType();
+ builder.mergeFrom(buildPartial());
+ return builder;
+ }
+
+ @Override
+ public MessageType buildPartial() {
+ if (isBuilt) {
+ return instance;
+ }
+
+ instance.makeImmutable();
+
+ isBuilt = true;
+ return instance;
+ }
+
+ @Override
+ public final MessageType build() {
+ MessageType result = buildPartial();
+ if (!result.isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return result;
+ }
+
+ @Override
+ protected BuilderType internalMergeFrom(MessageType message) {
+ return mergeFrom(message);
+ }
+
+ /** All subclasses implement this. */
+ public BuilderType mergeFrom(MessageType message) {
+ copyOnWrite();
+ instance.visit(MergeFromVisitor.INSTANCE, message);
+ return (BuilderType) this;
+ }
+
+ @Override
+ public MessageType getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ @Override
+ public BuilderType mergeFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws IOException {
+ copyOnWrite();
+ try {
+ instance.dynamicMethod(MethodToInvoke.MERGE_FROM_STREAM, input, extensionRegistry);
+ } catch (RuntimeException e) {
+ if (e.getCause() instanceof IOException) {
+ throw (IOException) e.getCause();
+ }
+ throw e;
+ }
+ return (BuilderType) this;
+ }
+ }
+
+
+ // =================================================================
+ // Extensions-related stuff
+
+ /**
+ * Lite equivalent of {@link com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder}.
+ */
+ public interface ExtendableMessageOrBuilder<
+ MessageType extends ExtendableMessage<MessageType, BuilderType>,
+ BuilderType extends ExtendableBuilder<MessageType, BuilderType>>
+ extends MessageLiteOrBuilder {
+
+ /** Check if a singular extension is present. */
+ <Type> boolean hasExtension(
+ ExtensionLite<MessageType, Type> extension);
+
+ /** Get the number of elements in a repeated extension. */
+ <Type> int getExtensionCount(
+ ExtensionLite<MessageType, List<Type>> extension);
+
+ /** Get the value of an extension. */
+ <Type> Type getExtension(ExtensionLite<MessageType, Type> extension);
+
+ /** Get one element of a repeated extension. */
+ <Type> Type getExtension(
+ ExtensionLite<MessageType, List<Type>> extension,
+ int index);
+ }
+
+ /**
+ * Lite equivalent of {@link GeneratedMessage.ExtendableMessage}.
+ */
+ public abstract static class ExtendableMessage<
+ MessageType extends ExtendableMessage<MessageType, BuilderType>,
+ BuilderType extends ExtendableBuilder<MessageType, BuilderType>>
+ extends GeneratedMessageLite<MessageType, BuilderType>
+ implements ExtendableMessageOrBuilder<MessageType, BuilderType> {
+
+ /**
+ * Represents the set of extensions on this message. For use by generated
+ * code only.
+ */
+ protected FieldSet<ExtensionDescriptor> extensions = FieldSet.newFieldSet();
+
+ @SuppressWarnings("unchecked")
+ protected final void mergeExtensionFields(final MessageType other) {
+ if (extensions.isImmutable()) {
+ extensions = extensions.clone();
+ }
+ extensions.mergeFrom(((ExtendableMessage) other).extensions);
+ }
+
+ @Override
+ final void visit(Visitor visitor, MessageType other) {
+ super.visit(visitor, other);
+ extensions = visitor.visitExtensions(extensions, other.extensions);
+ }
+
+ /**
+ * Parse an unknown field or an extension. For use by generated code only.
+ *
+ * <p>For use by generated code only.
+ *
+ * @return {@code true} unless the tag is an end-group tag.
+ */
+ protected <MessageType extends MessageLite> boolean parseUnknownField(
+ MessageType defaultInstance,
+ CodedInputStream input,
+ ExtensionRegistryLite extensionRegistry,
+ int tag) throws IOException {
+ int fieldNumber = WireFormat.getTagFieldNumber(tag);
+
+ // TODO(dweis): How much bytecode would be saved by not requiring the generated code to
+ // provide the default instance?
+ GeneratedExtension<MessageType, ?> extension = extensionRegistry.findLiteExtensionByNumber(
+ defaultInstance, fieldNumber);
+
+ return parseExtension(input, extensionRegistry, extension, tag, fieldNumber);
+ }
+
+ private boolean parseExtension(
+ CodedInputStream input,
+ ExtensionRegistryLite extensionRegistry,
+ GeneratedExtension<?, ?> extension,
+ int tag,
+ int fieldNumber)
+ throws IOException {
+ int wireType = WireFormat.getTagWireType(tag);
+ boolean unknown = false;
+ boolean packed = false;
+ if (extension == null) {
+ unknown = true; // Unknown field.
+ } else if (wireType == FieldSet.getWireFormatForFieldType(
+ extension.descriptor.getLiteType(),
+ false /* isPacked */)) {
+ packed = false; // Normal, unpacked value.
+ } else if (extension.descriptor.isRepeated &&
+ extension.descriptor.type.isPackable() &&
+ wireType == FieldSet.getWireFormatForFieldType(
+ extension.descriptor.getLiteType(),
+ true /* isPacked */)) {
+ packed = true; // Packed value.
+ } else {
+ unknown = true; // Wrong wire type.
+ }
+
+ if (unknown) { // Unknown field or wrong wire type. Skip.
+ return parseUnknownField(tag, input);
+ }
+
+ if (packed) {
+ int length = input.readRawVarint32();
+ int limit = input.pushLimit(length);
+ if (extension.descriptor.getLiteType() == WireFormat.FieldType.ENUM) {
+ while (input.getBytesUntilLimit() > 0) {
+ int rawValue = input.readEnum();
+ Object value =
+ extension.descriptor.getEnumType().findValueByNumber(rawValue);
+ if (value == null) {
+ // If the number isn't recognized as a valid value for this
+ // enum, drop it (don't even add it to unknownFields).
+ return true;
+ }
+ extensions.addRepeatedField(extension.descriptor,
+ extension.singularToFieldSetType(value));
+ }
+ } else {
+ while (input.getBytesUntilLimit() > 0) {
+ Object value =
+ FieldSet.readPrimitiveField(input,
+ extension.descriptor.getLiteType(),
+ /*checkUtf8=*/ false);
+ extensions.addRepeatedField(extension.descriptor, value);
+ }
+ }
+ input.popLimit(limit);
+ } else {
+ Object value;
+ switch (extension.descriptor.getLiteJavaType()) {
+ case MESSAGE: {
+ MessageLite.Builder subBuilder = null;
+ if (!extension.descriptor.isRepeated()) {
+ MessageLite existingValue =
+ (MessageLite) extensions.getField(extension.descriptor);
+ if (existingValue != null) {
+ subBuilder = existingValue.toBuilder();
+ }
+ }
+ if (subBuilder == null) {
+ subBuilder = extension.getMessageDefaultInstance()
+ .newBuilderForType();
+ }
+ if (extension.descriptor.getLiteType() ==
+ WireFormat.FieldType.GROUP) {
+ input.readGroup(extension.getNumber(),
+ subBuilder, extensionRegistry);
+ } else {
+ input.readMessage(subBuilder, extensionRegistry);
+ }
+ value = subBuilder.build();
+ break;
+ }
+ case ENUM:
+ int rawValue = input.readEnum();
+ value = extension.descriptor.getEnumType()
+ .findValueByNumber(rawValue);
+ // If the number isn't recognized as a valid value for this enum,
+ // write it to unknown fields object.
+ if (value == null) {
+ mergeVarintField(fieldNumber, rawValue);
+ return true;
+ }
+ break;
+ default:
+ value = FieldSet.readPrimitiveField(input,
+ extension.descriptor.getLiteType(),
+ /*checkUtf8=*/ false);
+ break;
+ }
+
+ if (extension.descriptor.isRepeated()) {
+ extensions.addRepeatedField(extension.descriptor,
+ extension.singularToFieldSetType(value));
+ } else {
+ extensions.setField(extension.descriptor,
+ extension.singularToFieldSetType(value));
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Parse an unknown field or an extension. For use by generated code only.
+ *
+ * <p>For use by generated code only.
+ *
+ * @return {@code true} unless the tag is an end-group tag.
+ */
+ protected <MessageType extends MessageLite> boolean parseUnknownFieldAsMessageSet(
+ MessageType defaultInstance,
+ CodedInputStream input,
+ ExtensionRegistryLite extensionRegistry,
+ int tag)
+ throws IOException {
+
+ if (tag == WireFormat.MESSAGE_SET_ITEM_TAG) {
+ mergeMessageSetExtensionFromCodedStream(defaultInstance, input, extensionRegistry);
+ return true;
+ }
+
+ // TODO(dweis): Do we really want to support non message set wire format in message sets?
+ // Full runtime does... So we do for now.
+ int wireType = WireFormat.getTagWireType(tag);
+ if (wireType == WireFormat.WIRETYPE_LENGTH_DELIMITED) {
+ return parseUnknownField(defaultInstance, input, extensionRegistry, tag);
+ } else {
+ // TODO(dweis): Should we throw on invalid input? Full runtime does not...
+ return input.skipField(tag);
+ }
+ }
+
+ /**
+ * Merges the message set from the input stream; requires message set wire format.
+ *
+ * @param defaultInstance the default instance of the containing message we are parsing in
+ * @param input the stream to parse from
+ * @param extensionRegistry the registry to use when parsing
+ */
+ private <MessageType extends MessageLite> void mergeMessageSetExtensionFromCodedStream(
+ MessageType defaultInstance,
+ CodedInputStream input,
+ ExtensionRegistryLite extensionRegistry)
+ throws IOException {
+ // The wire format for MessageSet is:
+ // message MessageSet {
+ // repeated group Item = 1 {
+ // required int32 typeId = 2;
+ // required bytes message = 3;
+ // }
+ // }
+ // "typeId" is the extension's field number. The extension can only be
+ // a message type, where "message" contains the encoded bytes of that
+ // message.
+ //
+ // In practice, we will probably never see a MessageSet item in which
+ // the message appears before the type ID, or where either field does not
+ // appear exactly once. However, in theory such cases are valid, so we
+ // should be prepared to accept them.
+
+ int typeId = 0;
+ ByteString rawBytes = null; // If we encounter "message" before "typeId"
+ GeneratedExtension<?, ?> extension = null;
+
+ // Read bytes from input, if we get it's type first then parse it eagerly,
+ // otherwise we store the raw bytes in a local variable.
+ while (true) {
+ final int tag = input.readTag();
+ if (tag == 0) {
+ break;
+ }
+
+ if (tag == WireFormat.MESSAGE_SET_TYPE_ID_TAG) {
+ typeId = input.readUInt32();
+ if (typeId != 0) {
+ extension = extensionRegistry.findLiteExtensionByNumber(defaultInstance, typeId);
+ }
+
+ } else if (tag == WireFormat.MESSAGE_SET_MESSAGE_TAG) {
+ if (typeId != 0) {
+ if (extension != null) {
+ // We already know the type, so we can parse directly from the
+ // input with no copying. Hooray!
+ eagerlyMergeMessageSetExtension(input, extension, extensionRegistry, typeId);
+ rawBytes = null;
+ continue;
+ }
+ }
+ // We haven't seen a type ID yet or we want parse message lazily.
+ rawBytes = input.readBytes();
+
+ } else { // Unknown tag. Skip it.
+ if (!input.skipField(tag)) {
+ break; // End of group
+ }
+ }
+ }
+ input.checkLastTagWas(WireFormat.MESSAGE_SET_ITEM_END_TAG);
+
+ // Process the raw bytes.
+ if (rawBytes != null && typeId != 0) { // Zero is not a valid type ID.
+ if (extension != null) { // We known the type
+ mergeMessageSetExtensionFromBytes(rawBytes, extensionRegistry, extension);
+ } else { // We don't know how to parse this. Ignore it.
+ if (rawBytes != null) {
+ mergeLengthDelimitedField(typeId, rawBytes);
+ }
+ }
+ }
+ }
+
+ private void eagerlyMergeMessageSetExtension(
+ CodedInputStream input,
+ GeneratedExtension<?, ?> extension,
+ ExtensionRegistryLite extensionRegistry,
+ int typeId)
+ throws IOException {
+ int fieldNumber = typeId;
+ int tag = WireFormat.makeTag(typeId, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ parseExtension(input, extensionRegistry, extension, tag, fieldNumber);
+ }
+
+ private void mergeMessageSetExtensionFromBytes(
+ ByteString rawBytes,
+ ExtensionRegistryLite extensionRegistry,
+ GeneratedExtension<?, ?> extension)
+ throws IOException {
+ MessageLite.Builder subBuilder = null;
+ MessageLite existingValue = (MessageLite) extensions.getField(extension.descriptor);
+ if (existingValue != null) {
+ subBuilder = existingValue.toBuilder();
+ }
+ if (subBuilder == null) {
+ subBuilder = extension.getMessageDefaultInstance().newBuilderForType();
+ }
+ rawBytes.newCodedInput().readMessage(subBuilder, extensionRegistry);
+ MessageLite value = subBuilder.build();
+
+ extensions.setField(extension.descriptor, extension.singularToFieldSetType(value));
+ }
+
+ private void verifyExtensionContainingType(
+ final GeneratedExtension<MessageType, ?> extension) {
+ if (extension.getContainingTypeDefaultInstance() !=
+ getDefaultInstanceForType()) {
+ // This can only happen if someone uses unchecked operations.
+ throw new IllegalArgumentException(
+ "This extension is for a different message type. Please make " +
+ "sure that you are not suppressing any generics type warnings.");
+ }
+ }
+
+ /** Check if a singular extension is present. */
+ @Override
+ public final <Type> boolean hasExtension(final ExtensionLite<MessageType, Type> extension) {
+ GeneratedExtension<MessageType, Type> extensionLite =
+ checkIsLite(extension);
+
+ verifyExtensionContainingType(extensionLite);
+ return extensions.hasField(extensionLite.descriptor);
+ }
+
+ /** Get the number of elements in a repeated extension. */
+ @Override
+ public final <Type> int getExtensionCount(
+ final ExtensionLite<MessageType, List<Type>> extension) {
+ GeneratedExtension<MessageType, List<Type>> extensionLite =
+ checkIsLite(extension);
+
+ verifyExtensionContainingType(extensionLite);
+ return extensions.getRepeatedFieldCount(extensionLite.descriptor);
+ }
+
+ /** Get the value of an extension. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public final <Type> Type getExtension(final ExtensionLite<MessageType, Type> extension) {
+ GeneratedExtension<MessageType, Type> extensionLite =
+ checkIsLite(extension);
+
+ verifyExtensionContainingType(extensionLite);
+ final Object value = extensions.getField(extensionLite.descriptor);
+ if (value == null) {
+ return extensionLite.defaultValue;
+ } else {
+ return (Type) extensionLite.fromFieldSetType(value);
+ }
+ }
+
+ /** Get one element of a repeated extension. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public final <Type> Type getExtension(
+ final ExtensionLite<MessageType, List<Type>> extension, final int index) {
+ GeneratedExtension<MessageType, List<Type>> extensionLite =
+ checkIsLite(extension);
+
+ verifyExtensionContainingType(extensionLite);
+ return (Type) extensionLite.singularFromFieldSetType(
+ extensions.getRepeatedField(extensionLite.descriptor, index));
+ }
+
+ /** Called by subclasses to check if all extensions are initialized. */
+ protected boolean extensionsAreInitialized() {
+ return extensions.isInitialized();
+ }
+
+ @Override
+ protected final void makeImmutable() {
+ super.makeImmutable();
+
+ extensions.makeImmutable();
+ }
+
+ /**
+ * Used by subclasses to serialize extensions. Extension ranges may be
+ * interleaved with field numbers, but we must write them in canonical
+ * (sorted by field number) order. ExtensionWriter helps us write
+ * individual ranges of extensions at once.
+ */
+ protected class ExtensionWriter {
+ // Imagine how much simpler this code would be if Java iterators had
+ // a way to get the next element without advancing the iterator.
+
+ private final Iterator<Map.Entry<ExtensionDescriptor, Object>> iter =
+ extensions.iterator();
+ private Map.Entry<ExtensionDescriptor, Object> next;
+ private final boolean messageSetWireFormat;
+
+ private ExtensionWriter(boolean messageSetWireFormat) {
+ if (iter.hasNext()) {
+ next = iter.next();
+ }
+ this.messageSetWireFormat = messageSetWireFormat;
+ }
+
+ public void writeUntil(final int end, final CodedOutputStream output)
+ throws IOException {
+ while (next != null && next.getKey().getNumber() < end) {
+ ExtensionDescriptor extension = next.getKey();
+ if (messageSetWireFormat && extension.getLiteJavaType() ==
+ WireFormat.JavaType.MESSAGE &&
+ !extension.isRepeated()) {
+ output.writeMessageSetExtension(extension.getNumber(),
+ (MessageLite) next.getValue());
+ } else {
+ FieldSet.writeField(extension, next.getValue(), output);
+ }
+ if (iter.hasNext()) {
+ next = iter.next();
+ } else {
+ next = null;
+ }
+ }
+ }
+ }
+
+ protected ExtensionWriter newExtensionWriter() {
+ return new ExtensionWriter(false);
+ }
+ protected ExtensionWriter newMessageSetExtensionWriter() {
+ return new ExtensionWriter(true);
+ }
+
+ /** Called by subclasses to compute the size of extensions. */
+ protected int extensionsSerializedSize() {
+ return extensions.getSerializedSize();
+ }
+ protected int extensionsSerializedSizeAsMessageSet() {
+ return extensions.getMessageSetSerializedSize();
+ }
+ }
+
+ /**
+ * Lite equivalent of {@link GeneratedMessage.ExtendableBuilder}.
+ */
+ @SuppressWarnings("unchecked")
+ public abstract static class ExtendableBuilder<
+ MessageType extends ExtendableMessage<MessageType, BuilderType>,
+ BuilderType extends ExtendableBuilder<MessageType, BuilderType>>
+ extends Builder<MessageType, BuilderType>
+ implements ExtendableMessageOrBuilder<MessageType, BuilderType> {
+ protected ExtendableBuilder(MessageType defaultInstance) {
+ super(defaultInstance);
+
+ // TODO(dweis): This is kind of an unnecessary clone since we construct a
+ // new instance in the parent constructor which makes the extensions
+ // immutable. This extra allocation shouldn't matter in practice
+ // though.
+ instance.extensions = instance.extensions.clone();
+ }
+
+ // For immutable message conversion.
+ void internalSetExtensionSet(FieldSet<ExtensionDescriptor> extensions) {
+ copyOnWrite();
+ instance.extensions = extensions;
+ }
+
+ @Override
+ protected void copyOnWrite() {
+ if (!isBuilt) {
+ return;
+ }
+
+ super.copyOnWrite();
+ instance.extensions = instance.extensions.clone();
+ }
+
+ @Override
+ public final MessageType buildPartial() {
+ if (isBuilt) {
+ return instance;
+ }
+
+ instance.extensions.makeImmutable();
+ return super.buildPartial();
+ }
+
+ private void verifyExtensionContainingType(
+ final GeneratedExtension<MessageType, ?> extension) {
+ if (extension.getContainingTypeDefaultInstance() !=
+ getDefaultInstanceForType()) {
+ // This can only happen if someone uses unchecked operations.
+ throw new IllegalArgumentException(
+ "This extension is for a different message type. Please make " +
+ "sure that you are not suppressing any generics type warnings.");
+ }
+ }
+
+ /** Check if a singular extension is present. */
+ @Override
+ public final <Type> boolean hasExtension(final ExtensionLite<MessageType, Type> extension) {
+ return instance.hasExtension(extension);
+ }
+
+ /** Get the number of elements in a repeated extension. */
+ @Override
+ public final <Type> int getExtensionCount(
+ final ExtensionLite<MessageType, List<Type>> extension) {
+ return instance.getExtensionCount(extension);
+ }
+
+ /** Get the value of an extension. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public final <Type> Type getExtension(final ExtensionLite<MessageType, Type> extension) {
+ return instance.getExtension(extension);
+ }
+
+ /** Get one element of a repeated extension. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public final <Type> Type getExtension(
+ final ExtensionLite<MessageType, List<Type>> extension, final int index) {
+ return instance.getExtension(extension, index);
+ }
+
+ /** Set the value of an extension. */
+ public final <Type> BuilderType setExtension(
+ final ExtensionLite<MessageType, Type> extension,
+ final Type value) {
+ GeneratedExtension<MessageType, Type> extensionLite =
+ checkIsLite(extension);
+
+ verifyExtensionContainingType(extensionLite);
+ copyOnWrite();
+ instance.extensions.setField(extensionLite.descriptor, extensionLite.toFieldSetType(value));
+ return (BuilderType) this;
+ }
+
+ /** Set the value of one element of a repeated extension. */
+ public final <Type> BuilderType setExtension(
+ final ExtensionLite<MessageType, List<Type>> extension,
+ final int index, final Type value) {
+ GeneratedExtension<MessageType, List<Type>> extensionLite =
+ checkIsLite(extension);
+
+ verifyExtensionContainingType(extensionLite);
+ copyOnWrite();
+ instance.extensions.setRepeatedField(
+ extensionLite.descriptor, index, extensionLite.singularToFieldSetType(value));
+ return (BuilderType) this;
+ }
+
+ /** Append a value to a repeated extension. */
+ public final <Type> BuilderType addExtension(
+ final ExtensionLite<MessageType, List<Type>> extension,
+ final Type value) {
+ GeneratedExtension<MessageType, List<Type>> extensionLite =
+ checkIsLite(extension);
+
+ verifyExtensionContainingType(extensionLite);
+ copyOnWrite();
+ instance.extensions.addRepeatedField(
+ extensionLite.descriptor, extensionLite.singularToFieldSetType(value));
+ return (BuilderType) this;
+ }
+
+ /** Clear an extension. */
+ public final <Type> BuilderType clearExtension(
+ final ExtensionLite<MessageType, ?> extension) {
+ GeneratedExtension<MessageType, ?> extensionLite = checkIsLite(extension);
+
+ verifyExtensionContainingType(extensionLite);
+ copyOnWrite();
+ instance.extensions.clearField(extensionLite.descriptor);
+ return (BuilderType) this;
+ }
+ }
+
+ // -----------------------------------------------------------------
+
+ /** For use by generated code only. */
+ public static <ContainingType extends MessageLite, Type>
+ GeneratedExtension<ContainingType, Type>
+ newSingularGeneratedExtension(
+ final ContainingType containingTypeDefaultInstance,
+ final Type defaultValue,
+ final MessageLite messageDefaultInstance,
+ final Internal.EnumLiteMap<?> enumTypeMap,
+ final int number,
+ final WireFormat.FieldType type,
+ final Class singularType) {
+ return new GeneratedExtension<ContainingType, Type>(
+ containingTypeDefaultInstance,
+ defaultValue,
+ messageDefaultInstance,
+ new ExtensionDescriptor(enumTypeMap, number, type,
+ false /* isRepeated */,
+ false /* isPacked */),
+ singularType);
+ }
+
+ /** For use by generated code only. */
+ public static <ContainingType extends MessageLite, Type>
+ GeneratedExtension<ContainingType, Type>
+ newRepeatedGeneratedExtension(
+ final ContainingType containingTypeDefaultInstance,
+ final MessageLite messageDefaultInstance,
+ final Internal.EnumLiteMap<?> enumTypeMap,
+ final int number,
+ final WireFormat.FieldType type,
+ final boolean isPacked,
+ final Class singularType) {
+ @SuppressWarnings("unchecked") // Subclasses ensure Type is a List
+ Type emptyList = (Type) Collections.emptyList();
+ return new GeneratedExtension<ContainingType, Type>(
+ containingTypeDefaultInstance,
+ emptyList,
+ messageDefaultInstance,
+ new ExtensionDescriptor(
+ enumTypeMap, number, type, true /* isRepeated */, isPacked),
+ singularType);
+ }
+
+ static final class ExtensionDescriptor
+ implements FieldSet.FieldDescriptorLite<
+ ExtensionDescriptor> {
+ ExtensionDescriptor(
+ final Internal.EnumLiteMap<?> enumTypeMap,
+ final int number,
+ final WireFormat.FieldType type,
+ final boolean isRepeated,
+ final boolean isPacked) {
+ this.enumTypeMap = enumTypeMap;
+ this.number = number;
+ this.type = type;
+ this.isRepeated = isRepeated;
+ this.isPacked = isPacked;
+ }
+
+ final Internal.EnumLiteMap<?> enumTypeMap;
+ final int number;
+ final WireFormat.FieldType type;
+ final boolean isRepeated;
+ final boolean isPacked;
+
+ @Override
+ public int getNumber() {
+ return number;
+ }
+
+ @Override
+ public WireFormat.FieldType getLiteType() {
+ return type;
+ }
+
+ @Override
+ public WireFormat.JavaType getLiteJavaType() {
+ return type.getJavaType();
+ }
+
+ @Override
+ public boolean isRepeated() {
+ return isRepeated;
+ }
+
+ @Override
+ public boolean isPacked() {
+ return isPacked;
+ }
+
+ @Override
+ public Internal.EnumLiteMap<?> getEnumType() {
+ return enumTypeMap;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public MessageLite.Builder internalMergeFrom(MessageLite.Builder to, MessageLite from) {
+ return ((Builder) to).mergeFrom((GeneratedMessageLite) from);
+ }
+
+
+ @Override
+ public int compareTo(ExtensionDescriptor other) {
+ return number - other.number;
+ }
+ }
+
+ // =================================================================
+
+ /** Calls Class.getMethod and throws a RuntimeException if it fails. */
+ @SuppressWarnings("unchecked")
+ static Method getMethodOrDie(Class clazz, String name, Class... params) {
+ try {
+ return clazz.getMethod(name, params);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(
+ "Generated message class \"" + clazz.getName() +
+ "\" missing method \"" + name + "\".", e);
+ }
+ }
+
+ /** Calls invoke and throws a RuntimeException if it fails. */
+ static Object invokeOrDie(Method method, Object object, Object... params) {
+ try {
+ return method.invoke(object, params);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(
+ "Couldn't use Java reflection to implement protocol message " +
+ "reflection.", e);
+ } catch (InvocationTargetException e) {
+ final Throwable cause = e.getCause();
+ if (cause instanceof RuntimeException) {
+ throw (RuntimeException) cause;
+ } else if (cause instanceof Error) {
+ throw (Error) cause;
+ } else {
+ throw new RuntimeException(
+ "Unexpected exception thrown by generated accessor method.", cause);
+ }
+ }
+ }
+
+ /**
+ * Lite equivalent to {@link GeneratedMessage.GeneratedExtension}.
+ *
+ * Users should ignore the contents of this class and only use objects of
+ * this type as parameters to extension accessors and ExtensionRegistry.add().
+ */
+ public static class GeneratedExtension<
+ ContainingType extends MessageLite, Type>
+ extends ExtensionLite<ContainingType, Type> {
+
+ /**
+ * Create a new instance with the given parameters.
+ *
+ * The last parameter {@code singularType} is only needed for enum types.
+ * We store integer values for enum types in a {@link ExtendableMessage}
+ * and use Java reflection to convert an integer value back into a concrete
+ * enum object.
+ */
+ GeneratedExtension(
+ final ContainingType containingTypeDefaultInstance,
+ final Type defaultValue,
+ final MessageLite messageDefaultInstance,
+ final ExtensionDescriptor descriptor,
+ final Class singularType) {
+ // Defensive checks to verify the correct initialization order of
+ // GeneratedExtensions and their related GeneratedMessages.
+ if (containingTypeDefaultInstance == null) {
+ throw new IllegalArgumentException(
+ "Null containingTypeDefaultInstance");
+ }
+ if (descriptor.getLiteType() == WireFormat.FieldType.MESSAGE &&
+ messageDefaultInstance == null) {
+ throw new IllegalArgumentException(
+ "Null messageDefaultInstance");
+ }
+ this.containingTypeDefaultInstance = containingTypeDefaultInstance;
+ this.defaultValue = defaultValue;
+ this.messageDefaultInstance = messageDefaultInstance;
+ this.descriptor = descriptor;
+ }
+
+ final ContainingType containingTypeDefaultInstance;
+ final Type defaultValue;
+ final MessageLite messageDefaultInstance;
+ final ExtensionDescriptor descriptor;
+
+ /**
+ * Default instance of the type being extended, used to identify that type.
+ */
+ public ContainingType getContainingTypeDefaultInstance() {
+ return containingTypeDefaultInstance;
+ }
+
+ /** Get the field number. */
+ @Override
+ public int getNumber() {
+ return descriptor.getNumber();
+ }
+
+
+ /**
+ * If the extension is an embedded message or group, returns the default
+ * instance of the message.
+ */
+ @Override
+ public MessageLite getMessageDefaultInstance() {
+ return messageDefaultInstance;
+ }
+
+ @SuppressWarnings("unchecked")
+ Object fromFieldSetType(final Object value) {
+ if (descriptor.isRepeated()) {
+ if (descriptor.getLiteJavaType() == WireFormat.JavaType.ENUM) {
+ final List result = new ArrayList();
+ for (final Object element : (List) value) {
+ result.add(singularFromFieldSetType(element));
+ }
+ return result;
+ } else {
+ return value;
+ }
+ } else {
+ return singularFromFieldSetType(value);
+ }
+ }
+
+ Object singularFromFieldSetType(final Object value) {
+ if (descriptor.getLiteJavaType() == WireFormat.JavaType.ENUM) {
+ return descriptor.enumTypeMap.findValueByNumber((Integer) value);
+ } else {
+ return value;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ Object toFieldSetType(final Object value) {
+ if (descriptor.isRepeated()) {
+ if (descriptor.getLiteJavaType() == WireFormat.JavaType.ENUM) {
+ final List result = new ArrayList();
+ for (final Object element : (List) value) {
+ result.add(singularToFieldSetType(element));
+ }
+ return result;
+ } else {
+ return value;
+ }
+ } else {
+ return singularToFieldSetType(value);
+ }
+ }
+
+ Object singularToFieldSetType(final Object value) {
+ if (descriptor.getLiteJavaType() == WireFormat.JavaType.ENUM) {
+ return ((Internal.EnumLite) value).getNumber();
+ } else {
+ return value;
+ }
+ }
+
+ @Override
+ public FieldType getLiteType() {
+ return descriptor.getLiteType();
+ }
+
+ @Override
+ public boolean isRepeated() {
+ return descriptor.isRepeated;
+ }
+
+ @Override
+ public Type getDefaultValue() {
+ return defaultValue;
+ }
+ }
+
+ /**
+ * A serialized (serializable) form of the generated message. Stores the
+ * message as a class name and a byte array.
+ */
+ protected static final class SerializedForm implements Serializable {
+
+ public static SerializedForm of(MessageLite message) {
+ return new SerializedForm(message);
+ }
+
+ private static final long serialVersionUID = 0L;
+
+ private final String messageClassName;
+ private final byte[] asBytes;
+
+ /**
+ * Creates the serialized form by calling {@link com.google.protobuf.MessageLite#toByteArray}.
+ * @param regularForm the message to serialize
+ */
+ SerializedForm(MessageLite regularForm) {
+ messageClassName = regularForm.getClass().getName();
+ asBytes = regularForm.toByteArray();
+ }
+
+ /**
+ * When read from an ObjectInputStream, this method converts this object
+ * back to the regular form. Part of Java's serialization magic.
+ * @return a GeneratedMessage of the type that was serialized
+ */
+ @SuppressWarnings("unchecked")
+ protected Object readResolve() throws ObjectStreamException {
+ try {
+ Class<?> messageClass = Class.forName(messageClassName);
+ java.lang.reflect.Field defaultInstanceField =
+ messageClass.getDeclaredField("DEFAULT_INSTANCE");
+ defaultInstanceField.setAccessible(true);
+ MessageLite defaultInstance = (MessageLite) defaultInstanceField.get(null);
+ return defaultInstance.newBuilderForType()
+ .mergeFrom(asBytes)
+ .buildPartial();
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Unable to find proto buffer class: " + messageClassName, e);
+ } catch (NoSuchFieldException e) {
+ return readResolveFallback();
+ } catch (SecurityException e) {
+ throw new RuntimeException("Unable to call DEFAULT_INSTANCE in " + messageClassName, e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("Unable to call parsePartialFrom", e);
+ } catch (InvalidProtocolBufferException e) {
+ throw new RuntimeException("Unable to understand proto buffer", e);
+ }
+ }
+
+ /**
+ * @deprecated from v3.0.0-beta-3+, for compatibility with v2.5.0 and v2.6.1 generated code.
+ */
+ @Deprecated
+ private Object readResolveFallback() throws ObjectStreamException {
+ try {
+ Class<?> messageClass = Class.forName(messageClassName);
+ java.lang.reflect.Field defaultInstanceField =
+ messageClass.getDeclaredField("defaultInstance");
+ defaultInstanceField.setAccessible(true);
+ MessageLite defaultInstance = (MessageLite) defaultInstanceField.get(null);
+ return defaultInstance.newBuilderForType()
+ .mergeFrom(asBytes)
+ .buildPartial();
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Unable to find proto buffer class: " + messageClassName, e);
+ } catch (NoSuchFieldException e) {
+ throw new RuntimeException("Unable to find defaultInstance in " + messageClassName, e);
+ } catch (SecurityException e) {
+ throw new RuntimeException("Unable to call defaultInstance in " + messageClassName, e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException("Unable to call parsePartialFrom", e);
+ } catch (InvalidProtocolBufferException e) {
+ throw new RuntimeException("Unable to understand proto buffer", e);
+ }
+ }
+ }
+
+ /**
+ * Checks that the {@link Extension} is Lite and returns it as a
+ * {@link GeneratedExtension}.
+ */
+ private static <
+ MessageType extends ExtendableMessage<MessageType, BuilderType>,
+ BuilderType extends ExtendableBuilder<MessageType, BuilderType>,
+ T>
+ GeneratedExtension<MessageType, T> checkIsLite(
+ ExtensionLite<MessageType, T> extension) {
+ if (!extension.isLite()) {
+ throw new IllegalArgumentException("Expected a lite extension.");
+ }
+
+ return (GeneratedExtension<MessageType, T>) extension;
+ }
+
+ /**
+ * A static helper method for checking if a message is initialized, optionally memoizing.
+ * <p>
+ * For use by generated code only.
+ */
+ protected static final <T extends GeneratedMessageLite<T, ?>> boolean isInitialized(
+ T message, boolean shouldMemoize) {
+ return message.dynamicMethod(MethodToInvoke.IS_INITIALIZED, shouldMemoize) != null;
+ }
+
+ protected static final <T extends GeneratedMessageLite<T, ?>> void makeImmutable(T message) {
+ message.dynamicMethod(MethodToInvoke.MAKE_IMMUTABLE);
+ }
+
+ protected static IntList emptyIntList() {
+ return IntArrayList.emptyList();
+ }
+
+ protected static IntList mutableCopy(IntList list) {
+ int size = list.size();
+ return list.mutableCopyWithCapacity(
+ size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2);
+ }
+
+ protected static LongList emptyLongList() {
+ return LongArrayList.emptyList();
+ }
+
+ protected static LongList mutableCopy(LongList list) {
+ int size = list.size();
+ return list.mutableCopyWithCapacity(
+ size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2);
+ }
+
+ protected static FloatList emptyFloatList() {
+ return FloatArrayList.emptyList();
+ }
+
+ protected static FloatList mutableCopy(FloatList list) {
+ int size = list.size();
+ return list.mutableCopyWithCapacity(
+ size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2);
+ }
+
+ protected static DoubleList emptyDoubleList() {
+ return DoubleArrayList.emptyList();
+ }
+
+ protected static DoubleList mutableCopy(DoubleList list) {
+ int size = list.size();
+ return list.mutableCopyWithCapacity(
+ size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2);
+ }
+
+ protected static BooleanList emptyBooleanList() {
+ return BooleanArrayList.emptyList();
+ }
+
+ protected static BooleanList mutableCopy(BooleanList list) {
+ int size = list.size();
+ return list.mutableCopyWithCapacity(
+ size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2);
+ }
+
+ protected static <E> ProtobufList<E> emptyProtobufList() {
+ return ProtobufArrayList.emptyList();
+ }
+
+ protected static <E> ProtobufList<E> mutableCopy(ProtobufList<E> list) {
+ int size = list.size();
+ return list.mutableCopyWithCapacity(
+ size == 0 ? AbstractProtobufList.DEFAULT_CAPACITY : size * 2);
+ }
+
+ /**
+ * A {@link Parser} implementation that delegates to the default instance.
+ * <p>
+ * For use by generated code only.
+ */
+ protected static class DefaultInstanceBasedParser<T extends GeneratedMessageLite<T, ?>>
+ extends AbstractParser<T> {
+
+ private T defaultInstance;
+
+ public DefaultInstanceBasedParser(T defaultInstance) {
+ this.defaultInstance = defaultInstance;
+ }
+
+ @Override
+ public T parsePartialFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ return GeneratedMessageLite.parsePartialFrom(defaultInstance, input, extensionRegistry);
+ }
+ }
+
+ /**
+ * A static helper method for parsing a partial from input using the extension registry and the
+ * instance.
+ */
+ // TODO(dweis): Should this verify that the last tag was 0?
+ static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom(
+ T instance, CodedInputStream input, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ @SuppressWarnings("unchecked") // Guaranteed by protoc
+ T result = (T) instance.dynamicMethod(MethodToInvoke.NEW_MUTABLE_INSTANCE);
+ try {
+ result.dynamicMethod(MethodToInvoke.MERGE_FROM_STREAM, input, extensionRegistry);
+ result.makeImmutable();
+ } catch (RuntimeException e) {
+ if (e.getCause() instanceof InvalidProtocolBufferException) {
+ throw (InvalidProtocolBufferException) e.getCause();
+ }
+ throw e;
+ }
+ return result;
+ }
+
+ protected static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom(
+ T defaultInstance,
+ CodedInputStream input)
+ throws InvalidProtocolBufferException {
+ return parsePartialFrom(defaultInstance, input, ExtensionRegistryLite.getEmptyRegistry());
+ }
+
+ /**
+ * Helper method to check if message is initialized.
+ *
+ * @throws InvalidProtocolBufferException if it is not initialized.
+ * @return The message to check.
+ */
+ private static <T extends GeneratedMessageLite<T, ?>> T checkMessageInitialized(T message)
+ throws InvalidProtocolBufferException {
+ if (message != null && !message.isInitialized()) {
+ throw message.newUninitializedMessageException()
+ .asInvalidProtocolBufferException()
+ .setUnfinishedMessage(message);
+ }
+ return message;
+ }
+
+ // Validates last tag.
+ protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
+ T defaultInstance, ByteString data)
+ throws InvalidProtocolBufferException {
+ return checkMessageInitialized(
+ parseFrom(defaultInstance, data, ExtensionRegistryLite.getEmptyRegistry()));
+ }
+
+ // Validates last tag.
+ protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
+ T defaultInstance, ByteString data, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ return checkMessageInitialized(parsePartialFrom(defaultInstance, data, extensionRegistry));
+ }
+
+ // This is a special case since we want to verify that the last tag is 0. We assume we exhaust the
+ // ByteString.
+ private static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom(
+ T defaultInstance, ByteString data, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ T message;
+ try {
+ CodedInputStream input = data.newCodedInput();
+ message = parsePartialFrom(defaultInstance, input, extensionRegistry);
+ try {
+ input.checkLastTagWas(0);
+ } catch (InvalidProtocolBufferException e) {
+ throw e.setUnfinishedMessage(message);
+ }
+ return message;
+ } catch (InvalidProtocolBufferException e) {
+ throw e;
+ }
+ }
+
+ // This is a special case since we want to verify that the last tag is 0. We assume we exhaust the
+ // ByteString.
+ private static <T extends GeneratedMessageLite<T, ?>> T parsePartialFrom(
+ T defaultInstance, byte[] data, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ T message;
+ try {
+ CodedInputStream input = CodedInputStream.newInstance(data);
+ message = parsePartialFrom(defaultInstance, input, extensionRegistry);
+ try {
+ input.checkLastTagWas(0);
+ } catch (InvalidProtocolBufferException e) {
+ throw e.setUnfinishedMessage(message);
+ }
+ return message;
+ } catch (InvalidProtocolBufferException e) {
+ throw e;
+ }
+ }
+
+ // Validates last tag.
+ protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
+ T defaultInstance, byte[] data)
+ throws InvalidProtocolBufferException {
+ return checkMessageInitialized(
+ parsePartialFrom(defaultInstance, data, ExtensionRegistryLite.getEmptyRegistry()));
+ }
+
+ // Validates last tag.
+ protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
+ T defaultInstance, byte[] data, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ return checkMessageInitialized(parsePartialFrom(defaultInstance, data, extensionRegistry));
+ }
+
+ // Does not validate last tag.
+ protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
+ T defaultInstance, InputStream input)
+ throws InvalidProtocolBufferException {
+ return checkMessageInitialized(
+ parsePartialFrom(defaultInstance, CodedInputStream.newInstance(input),
+ ExtensionRegistryLite.getEmptyRegistry()));
+ }
+
+ // Does not validate last tag.
+ protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
+ T defaultInstance, InputStream input, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ return checkMessageInitialized(
+ parsePartialFrom(defaultInstance, CodedInputStream.newInstance(input), extensionRegistry));
+ }
+
+ // Does not validate last tag.
+ protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
+ T defaultInstance, CodedInputStream input)
+ throws InvalidProtocolBufferException {
+ return parseFrom(defaultInstance, input, ExtensionRegistryLite.getEmptyRegistry());
+ }
+
+ // Does not validate last tag.
+ protected static <T extends GeneratedMessageLite<T, ?>> T parseFrom(
+ T defaultInstance, CodedInputStream input, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ return checkMessageInitialized(
+ parsePartialFrom(defaultInstance, input, extensionRegistry));
+ }
+
+ // Validates last tag.
+ protected static <T extends GeneratedMessageLite<T, ?>> T parseDelimitedFrom(
+ T defaultInstance, InputStream input)
+ throws InvalidProtocolBufferException {
+ return checkMessageInitialized(
+ parsePartialDelimitedFrom(defaultInstance, input,
+ ExtensionRegistryLite.getEmptyRegistry()));
+ }
+
+ // Validates last tag.
+ protected static <T extends GeneratedMessageLite<T, ?>> T parseDelimitedFrom(
+ T defaultInstance, InputStream input, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ return checkMessageInitialized(
+ parsePartialDelimitedFrom(defaultInstance, input, extensionRegistry));
+ }
+
+ private static <T extends GeneratedMessageLite<T, ?>> T parsePartialDelimitedFrom(
+ T defaultInstance,
+ 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);
+ CodedInputStream codedInput = CodedInputStream.newInstance(limitedInput);
+ T message = parsePartialFrom(defaultInstance, codedInput, extensionRegistry);
+ try {
+ codedInput.checkLastTagWas(0);
+ } catch (InvalidProtocolBufferException e) {
+ throw e.setUnfinishedMessage(message);
+ }
+ return message;
+ }
+
+ /**
+ * An abstract visitor that the generated code calls into that we use to implement various
+ * features. Fields that are not members of oneofs are always visited. Members of a oneof are only
+ * visited when they are the set oneof case value on the "other" proto. The visitOneofNotSet
+ * method is invoked if other's oneof case is not set.
+ */
+ protected interface Visitor {
+ boolean visitBoolean(boolean minePresent, boolean mine, boolean otherPresent, boolean other);
+ int visitInt(boolean minePresent, int mine, boolean otherPresent, int other);
+ double visitDouble(boolean minePresent, double mine, boolean otherPresent, double other);
+ float visitFloat(boolean minePresent, float mine, boolean otherPresent, float other);
+ long visitLong(boolean minePresent, long mine, boolean otherPresent, long other);
+ String visitString(boolean minePresent, String mine, boolean otherPresent, String other);
+ ByteString visitByteString(
+ boolean minePresent, ByteString mine, boolean otherPresent, ByteString other);
+
+ Object visitOneofBoolean(boolean minePresent, Object mine, Object other);
+ Object visitOneofInt(boolean minePresent, Object mine, Object other);
+ Object visitOneofDouble(boolean minePresent, Object mine, Object other);
+ Object visitOneofFloat(boolean minePresent, Object mine, Object other);
+ Object visitOneofLong(boolean minePresent, Object mine, Object other);
+ Object visitOneofString(boolean minePresent, Object mine, Object other);
+ Object visitOneofByteString(boolean minePresent, Object mine, Object other);
+ Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other);
+ Object visitOneofMessage(boolean minePresent, Object mine, Object other);
+ void visitOneofNotSet(boolean minePresent);
+
+ /**
+ * Message fields use null sentinals.
+ */
+ <T extends MessageLite> T visitMessage(T mine, T other);
+ LazyFieldLite visitLazyMessage(LazyFieldLite mine, LazyFieldLite other);
+
+ <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> other);
+ BooleanList visitBooleanList(BooleanList mine, BooleanList other);
+ IntList visitIntList(IntList mine, IntList other);
+ DoubleList visitDoubleList(DoubleList mine, DoubleList other);
+ FloatList visitFloatList(FloatList mine, FloatList other);
+ LongList visitLongList(LongList mine, LongList other);
+ FieldSet<ExtensionDescriptor> visitExtensions(
+ FieldSet<ExtensionDescriptor> mine, FieldSet<ExtensionDescriptor> other);
+ UnknownFieldSetLite visitUnknownFields(UnknownFieldSetLite mine, UnknownFieldSetLite other);
+ <K, V> MapFieldLite<K, V> visitMap(MapFieldLite<K, V> mine, MapFieldLite<K, V> other);
+ }
+
+ /**
+ * Implements equals. Throws a {@link NotEqualsException} when not equal.
+ */
+ static class EqualsVisitor implements Visitor {
+
+ static final class NotEqualsException extends RuntimeException {}
+
+ static final EqualsVisitor INSTANCE = new EqualsVisitor();
+
+ static final NotEqualsException NOT_EQUALS = new NotEqualsException();
+
+ private EqualsVisitor() {}
+
+ @Override
+ public boolean visitBoolean(
+ boolean minePresent, boolean mine, boolean otherPresent, boolean other) {
+ if (minePresent != otherPresent || mine != other) {
+ throw NOT_EQUALS;
+ }
+ return mine;
+ }
+
+ @Override
+ public int visitInt(boolean minePresent, int mine, boolean otherPresent, int other) {
+ if (minePresent != otherPresent || mine != other) {
+ throw NOT_EQUALS;
+ }
+ return mine;
+ }
+
+ @Override
+ public double visitDouble(
+ boolean minePresent, double mine, boolean otherPresent, double other) {
+ if (minePresent != otherPresent || mine != other) {
+ throw NOT_EQUALS;
+ }
+ return mine;
+ }
+
+ @Override
+ public float visitFloat(boolean minePresent, float mine, boolean otherPresent, float other) {
+ if (minePresent != otherPresent || mine != other) {
+ throw NOT_EQUALS;
+ }
+ return mine;
+ }
+
+ @Override
+ public long visitLong(boolean minePresent, long mine, boolean otherPresent, long other) {
+ if (minePresent != otherPresent || mine != other) {
+ throw NOT_EQUALS;
+ }
+ return mine;
+ }
+
+ @Override
+ public String visitString(
+ boolean minePresent, String mine, boolean otherPresent, String other) {
+ if (minePresent != otherPresent || !mine.equals(other)) {
+ throw NOT_EQUALS;
+ }
+ return mine;
+ }
+
+ @Override
+ public ByteString visitByteString(
+ boolean minePresent, ByteString mine, boolean otherPresent, ByteString other) {
+ if (minePresent != otherPresent || !mine.equals(other)) {
+ throw NOT_EQUALS;
+ }
+ return mine;
+ }
+
+ @Override
+ public Object visitOneofBoolean(boolean minePresent, Object mine, Object other) {
+ if (minePresent && mine.equals(other)) {
+ return mine;
+ }
+ throw NOT_EQUALS;
+ }
+
+ @Override
+ public Object visitOneofInt(boolean minePresent, Object mine, Object other) {
+ if (minePresent && mine.equals(other)) {
+ return mine;
+ }
+ throw NOT_EQUALS;
+ }
+
+ @Override
+ public Object visitOneofDouble(boolean minePresent, Object mine, Object other) {
+ if (minePresent && mine.equals(other)) {
+ return mine;
+ }
+ throw NOT_EQUALS;
+ }
+
+ @Override
+ public Object visitOneofFloat(boolean minePresent, Object mine, Object other) {
+ if (minePresent && mine.equals(other)) {
+ return mine;
+ }
+ throw NOT_EQUALS;
+ }
+
+ @Override
+ public Object visitOneofLong(boolean minePresent, Object mine, Object other) {
+ if (minePresent && mine.equals(other)) {
+ return mine;
+ }
+ throw NOT_EQUALS;
+ }
+
+ @Override
+ public Object visitOneofString(boolean minePresent, Object mine, Object other) {
+ if (minePresent && mine.equals(other)) {
+ return mine;
+ }
+ throw NOT_EQUALS;
+ }
+
+ @Override
+ public Object visitOneofByteString(boolean minePresent, Object mine, Object other) {
+ if (minePresent && mine.equals(other)) {
+ return mine;
+ }
+ throw NOT_EQUALS;
+ }
+
+ @Override
+ public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other) {
+ if (minePresent && mine.equals(other)) {
+ return mine;
+ }
+ throw NOT_EQUALS;
+ }
+
+ @Override
+ public Object visitOneofMessage(boolean minePresent, Object mine, Object other) {
+ if (minePresent && ((GeneratedMessageLite<?, ?>) mine).equals(this, (MessageLite) other)) {
+ return mine;
+ }
+ throw NOT_EQUALS;
+ }
+
+ @Override
+ public void visitOneofNotSet(boolean minePresent) {
+ if (minePresent) {
+ throw NOT_EQUALS;
+ }
+ }
+
+ @Override
+ public <T extends MessageLite> T visitMessage(T mine, T other) {
+ if (mine == null && other == null) {
+ return null;
+ }
+
+ if (mine == null || other == null) {
+ throw NOT_EQUALS;
+ }
+
+ ((GeneratedMessageLite<?, ?>) mine).equals(this, other);
+
+ return mine;
+ }
+
+ @Override
+ public LazyFieldLite visitLazyMessage(
+ LazyFieldLite mine, LazyFieldLite other) {
+ if (mine == null && other == null) {
+ return null;
+ }
+ if (mine == null || other == null) {
+ throw NOT_EQUALS;
+ }
+ if (mine.equals(other)) {
+ return mine;
+ }
+ throw NOT_EQUALS;
+ }
+
+ @Override
+ public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> other) {
+ if (!mine.equals(other)) {
+ throw NOT_EQUALS;
+ }
+ return mine;
+ }
+
+ @Override
+ public BooleanList visitBooleanList(BooleanList mine, BooleanList other) {
+ if (!mine.equals(other)) {
+ throw NOT_EQUALS;
+ }
+ return mine;
+ }
+
+ @Override
+ public IntList visitIntList(IntList mine, IntList other) {
+ if (!mine.equals(other)) {
+ throw NOT_EQUALS;
+ }
+ return mine;
+ }
+
+ @Override
+ public DoubleList visitDoubleList(DoubleList mine, DoubleList other) {
+ if (!mine.equals(other)) {
+ throw NOT_EQUALS;
+ }
+ return mine;
+ }
+
+ @Override
+ public FloatList visitFloatList(FloatList mine, FloatList other) {
+ if (!mine.equals(other)) {
+ throw NOT_EQUALS;
+ }
+ return mine;
+ }
+
+ @Override
+ public LongList visitLongList(LongList mine, LongList other) {
+ if (!mine.equals(other)) {
+ throw NOT_EQUALS;
+ }
+ return mine;
+ }
+
+ @Override
+ public FieldSet<ExtensionDescriptor> visitExtensions(
+ FieldSet<ExtensionDescriptor> mine,
+ FieldSet<ExtensionDescriptor> other) {
+ if (!mine.equals(other)) {
+ throw NOT_EQUALS;
+ }
+ return mine;
+ }
+
+ @Override
+ public UnknownFieldSetLite visitUnknownFields(
+ UnknownFieldSetLite mine,
+ UnknownFieldSetLite other) {
+ if (!mine.equals(other)) {
+ throw NOT_EQUALS;
+ }
+ return mine;
+ }
+
+ @Override
+ public <K, V> MapFieldLite<K, V> visitMap(MapFieldLite<K, V> mine, MapFieldLite<K, V> other) {
+ if (!mine.equals(other)) {
+ throw NOT_EQUALS;
+ }
+ return mine;
+ }
+ }
+
+ /**
+ * Implements hashCode by accumulating state.
+ */
+ private static class HashCodeVisitor implements Visitor {
+
+ // The caller must ensure that the visitor is invoked parameterized with this and this such that
+ // other is this. This is required due to how oneof cases are handled. See the class comment
+ // on Visitor for more information.
+
+ private int hashCode = 0;
+
+ @Override
+ public boolean visitBoolean(
+ boolean minePresent, boolean mine, boolean otherPresent, boolean other) {
+ hashCode = (53 * hashCode) + Internal.hashBoolean(mine);
+ return mine;
+ }
+
+ @Override
+ public int visitInt(boolean minePresent, int mine, boolean otherPresent, int other) {
+ hashCode = (53 * hashCode) + mine;
+ return mine;
+ }
+
+ @Override
+ public double visitDouble(
+ boolean minePresent, double mine, boolean otherPresent, double other) {
+ hashCode = (53 * hashCode) + Internal.hashLong(Double.doubleToLongBits(mine));
+ return mine;
+ }
+
+ @Override
+ public float visitFloat(boolean minePresent, float mine, boolean otherPresent, float other) {
+ hashCode = (53 * hashCode) + Float.floatToIntBits(mine);
+ return mine;
+ }
+
+ @Override
+ public long visitLong(boolean minePresent, long mine, boolean otherPresent, long other) {
+ hashCode = (53 * hashCode) + Internal.hashLong(mine);
+ return mine;
+ }
+
+ @Override
+ public String visitString(
+ boolean minePresent, String mine, boolean otherPresent, String other) {
+ hashCode = (53 * hashCode) + mine.hashCode();
+ return mine;
+ }
+
+ @Override
+ public ByteString visitByteString(
+ boolean minePresent, ByteString mine, boolean otherPresent, ByteString other) {
+ hashCode = (53 * hashCode) + mine.hashCode();
+ return mine;
+ }
+
+ @Override
+ public Object visitOneofBoolean(boolean minePresent, Object mine, Object other) {
+ hashCode = (53 * hashCode) + Internal.hashBoolean(((Boolean) mine));
+ return mine;
+ }
+
+ @Override
+ public Object visitOneofInt(boolean minePresent, Object mine, Object other) {
+ hashCode = (53 * hashCode) + (Integer) mine;
+ return mine;
+ }
+
+ @Override
+ public Object visitOneofDouble(boolean minePresent, Object mine, Object other) {
+ hashCode = (53 * hashCode) + Internal.hashLong(Double.doubleToLongBits((Double) mine));
+ return mine;
+ }
+
+ @Override
+ public Object visitOneofFloat(boolean minePresent, Object mine, Object other) {
+ hashCode = (53 * hashCode) + Float.floatToIntBits((Float) mine);
+ return mine;
+ }
+
+ @Override
+ public Object visitOneofLong(boolean minePresent, Object mine, Object other) {
+ hashCode = (53 * hashCode) + Internal.hashLong((Long) mine);
+ return mine;
+ }
+
+ @Override
+ public Object visitOneofString(boolean minePresent, Object mine, Object other) {
+ hashCode = (53 * hashCode) + mine.hashCode();
+ return mine;
+ }
+
+ @Override
+ public Object visitOneofByteString(boolean minePresent, Object mine, Object other) {
+ hashCode = (53 * hashCode) + mine.hashCode();
+ return mine;
+ }
+
+ @Override
+ public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other) {
+ hashCode = (53 * hashCode) + mine.hashCode();
+ return mine;
+ }
+
+ @Override
+ public Object visitOneofMessage(boolean minePresent, Object mine, Object other) {
+ return visitMessage((MessageLite) mine, (MessageLite) other);
+ }
+
+ @Override
+ public void visitOneofNotSet(boolean minePresent) {
+ if (minePresent) {
+ throw new IllegalStateException(); // Can't happen if other == this.
+ }
+ }
+
+ @Override
+ public <T extends MessageLite> T visitMessage(T mine, T other) {
+ final int protoHash;
+ if (mine != null) {
+ if (mine instanceof GeneratedMessageLite) {
+ protoHash = ((GeneratedMessageLite) mine).hashCode(this);
+ } else {
+ protoHash = mine.hashCode();
+ }
+ } else {
+ protoHash = 37;
+ }
+ hashCode = (53 * hashCode) + protoHash;
+ return mine;
+ }
+
+ @Override
+ public LazyFieldLite visitLazyMessage(LazyFieldLite mine, LazyFieldLite other) {
+ final int protoHash;
+ if (mine != null) {
+ protoHash = mine.hashCode();
+ } else {
+ protoHash = 37;
+ }
+ hashCode = (53 * hashCode) + protoHash;
+ return mine;
+ }
+
+ @Override
+ public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> other) {
+ hashCode = (53 * hashCode) + mine.hashCode();
+ return mine;
+ }
+
+ @Override
+ public BooleanList visitBooleanList(BooleanList mine, BooleanList other) {
+ hashCode = (53 * hashCode) + mine.hashCode();
+ return mine;
+ }
+
+ @Override
+ public IntList visitIntList(IntList mine, IntList other) {
+ hashCode = (53 * hashCode) + mine.hashCode();
+ return mine;
+ }
+
+ @Override
+ public DoubleList visitDoubleList(DoubleList mine, DoubleList other) {
+ hashCode = (53 * hashCode) + mine.hashCode();
+ return mine;
+ }
+
+ @Override
+ public FloatList visitFloatList(FloatList mine, FloatList other) {
+ hashCode = (53 * hashCode) + mine.hashCode();
+ return mine;
+ }
+
+ @Override
+ public LongList visitLongList(LongList mine, LongList other) {
+ hashCode = (53 * hashCode) + mine.hashCode();
+ return mine;
+ }
+
+ @Override
+ public FieldSet<ExtensionDescriptor> visitExtensions(
+ FieldSet<ExtensionDescriptor> mine,
+ FieldSet<ExtensionDescriptor> other) {
+ hashCode = (53 * hashCode) + mine.hashCode();
+ return mine;
+ }
+
+ @Override
+ public UnknownFieldSetLite visitUnknownFields(
+ UnknownFieldSetLite mine,
+ UnknownFieldSetLite other) {
+ hashCode = (53 * hashCode) + mine.hashCode();
+ return mine;
+ }
+
+ @Override
+ public <K, V> MapFieldLite<K, V> visitMap(MapFieldLite<K, V> mine, MapFieldLite<K, V> other) {
+ hashCode = (53 * hashCode) + mine.hashCode();
+ return mine;
+ }
+ }
+
+ /**
+ * Implements field merging semantics over the visitor interface.
+ */
+ protected static class MergeFromVisitor implements Visitor {
+
+ public static final MergeFromVisitor INSTANCE = new MergeFromVisitor();
+
+ private MergeFromVisitor() {}
+
+ @Override
+ public boolean visitBoolean(
+ boolean minePresent, boolean mine, boolean otherPresent, boolean other) {
+ return otherPresent ? other : mine;
+ }
+
+ @Override
+ public int visitInt(boolean minePresent, int mine, boolean otherPresent, int other) {
+ return otherPresent ? other : mine;
+ }
+
+ @Override
+ public double visitDouble(
+ boolean minePresent, double mine, boolean otherPresent, double other) {
+ return otherPresent ? other : mine;
+ }
+
+ @Override
+ public float visitFloat(boolean minePresent, float mine, boolean otherPresent, float other) {
+ return otherPresent ? other : mine;
+ }
+
+ @Override
+ public long visitLong(boolean minePresent, long mine, boolean otherPresent, long other) {
+ return otherPresent ? other : mine;
+ }
+
+ @Override
+ public String visitString(
+ boolean minePresent, String mine, boolean otherPresent, String other) {
+ return otherPresent ? other : mine;
+ }
+
+ @Override
+ public ByteString visitByteString(
+ boolean minePresent, ByteString mine, boolean otherPresent, ByteString other) {
+ return otherPresent ? other : mine;
+ }
+
+ @Override
+ public Object visitOneofBoolean(boolean minePresent, Object mine, Object other) {
+ return other;
+ }
+
+ @Override
+ public Object visitOneofInt(boolean minePresent, Object mine, Object other) {
+ return other;
+ }
+
+ @Override
+ public Object visitOneofDouble(boolean minePresent, Object mine, Object other) {
+ return other;
+ }
+
+ @Override
+ public Object visitOneofFloat(boolean minePresent, Object mine, Object other) {
+ return other;
+ }
+
+ @Override
+ public Object visitOneofLong(boolean minePresent, Object mine, Object other) {
+ return other;
+ }
+
+ @Override
+ public Object visitOneofString(boolean minePresent, Object mine, Object other) {
+ return other;
+ }
+
+ @Override
+ public Object visitOneofByteString(boolean minePresent, Object mine, Object other) {
+ return other;
+ }
+
+ @Override
+ public Object visitOneofLazyMessage(boolean minePresent, Object mine, Object other) {
+ LazyFieldLite lazy = minePresent ? (LazyFieldLite) mine : new LazyFieldLite();
+ lazy.merge((LazyFieldLite) other);
+ return lazy;
+ }
+
+ @Override
+ public Object visitOneofMessage(boolean minePresent, Object mine, Object other) {
+ if (minePresent) {
+ return visitMessage((MessageLite) mine, (MessageLite) other);
+ }
+ return other;
+ }
+
+ @Override
+ public void visitOneofNotSet(boolean minePresent) {
+ return;
+ }
+
+ @SuppressWarnings("unchecked") // Guaranteed by runtime.
+ @Override
+ public <T extends MessageLite> T visitMessage(T mine, T other) {
+ if (mine != null && other != null) {
+ return (T) mine.toBuilder().mergeFrom(other).build();
+ }
+
+ return mine != null ? mine : other;
+ }
+
+ @Override
+ public LazyFieldLite visitLazyMessage(LazyFieldLite mine, LazyFieldLite other) {
+ if (other != null) {
+ if (mine == null) {
+ mine = new LazyFieldLite();
+ }
+ mine.merge(other);
+ }
+ return mine;
+ }
+
+ @Override
+ public <T> ProtobufList<T> visitList(ProtobufList<T> mine, ProtobufList<T> other) {
+ int size = mine.size();
+ int otherSize = other.size();
+ if (size > 0 && otherSize > 0) {
+ if (!mine.isModifiable()) {
+ mine = mine.mutableCopyWithCapacity(size + otherSize);
+ }
+ mine.addAll(other);
+ }
+
+ return size > 0 ? mine : other;
+ }
+
+ @Override
+ public BooleanList visitBooleanList(BooleanList mine, BooleanList other) {
+ int size = mine.size();
+ int otherSize = other.size();
+ if (size > 0 && otherSize > 0) {
+ if (!mine.isModifiable()) {
+ mine = mine.mutableCopyWithCapacity(size + otherSize);
+ }
+ mine.addAll(other);
+ }
+
+ return size > 0 ? mine : other;
+ }
+
+ @Override
+ public IntList visitIntList(IntList mine, IntList other) {
+ int size = mine.size();
+ int otherSize = other.size();
+ if (size > 0 && otherSize > 0) {
+ if (!mine.isModifiable()) {
+ mine = mine.mutableCopyWithCapacity(size + otherSize);
+ }
+ mine.addAll(other);
+ }
+
+ return size > 0 ? mine : other;
+ }
+
+ @Override
+ public DoubleList visitDoubleList(DoubleList mine, DoubleList other) {
+ int size = mine.size();
+ int otherSize = other.size();
+ if (size > 0 && otherSize > 0) {
+ if (!mine.isModifiable()) {
+ mine = mine.mutableCopyWithCapacity(size + otherSize);
+ }
+ mine.addAll(other);
+ }
+
+ return size > 0 ? mine : other;
+ }
+
+ @Override
+ public FloatList visitFloatList(FloatList mine, FloatList other) {
+ int size = mine.size();
+ int otherSize = other.size();
+ if (size > 0 && otherSize > 0) {
+ if (!mine.isModifiable()) {
+ mine = mine.mutableCopyWithCapacity(size + otherSize);
+ }
+ mine.addAll(other);
+ }
+
+ return size > 0 ? mine : other;
+ }
+
+ @Override
+ public LongList visitLongList(LongList mine, LongList other) {
+ int size = mine.size();
+ int otherSize = other.size();
+ if (size > 0 && otherSize > 0) {
+ if (!mine.isModifiable()) {
+ mine = mine.mutableCopyWithCapacity(size + otherSize);
+ }
+ mine.addAll(other);
+ }
+
+ return size > 0 ? mine : other;
+ }
+
+ @Override
+ public FieldSet<ExtensionDescriptor> visitExtensions(
+ FieldSet<ExtensionDescriptor> mine,
+ FieldSet<ExtensionDescriptor> other) {
+ if (mine.isImmutable()) {
+ mine = mine.clone();
+ }
+ mine.mergeFrom(other);
+ return mine;
+ }
+
+ @Override
+ public UnknownFieldSetLite visitUnknownFields(
+ UnknownFieldSetLite mine,
+ UnknownFieldSetLite other) {
+ return other == UnknownFieldSetLite.getDefaultInstance()
+ ? mine : UnknownFieldSetLite.mutableCopyOf(mine, other);
+ }
+
+ @Override
+ public <K, V> MapFieldLite<K, V> visitMap(MapFieldLite<K, V> mine, MapFieldLite<K, V> other) {
+ if (!other.isEmpty()) {
+ if (!mine.isMutable()) {
+ mine = mine.mutableCopy();
+ }
+ mine.mergeFrom(other);
+ }
+ return mine;
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java
new file mode 100644
index 0000000000..fd051e751d
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java
@@ -0,0 +1,2842 @@
+// 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.Descriptor;
+import com.google.protobuf.Descriptors.EnumDescriptor;
+import com.google.protobuf.Descriptors.EnumValueDescriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+import com.google.protobuf.Descriptors.FileDescriptor;
+import com.google.protobuf.Descriptors.OneofDescriptor;
+// In opensource protobuf, we have versioned this GeneratedMessageV3 class to GeneratedMessageV3V3 and
+// in the future may have GeneratedMessageV3V4 etc. This allows us to change some aspects of this
+// class without breaking binary compatibility with old generated code that still subclasses
+// the old GeneratedMessageV3 class. To allow these different GeneratedMessageV3V? classes to
+// interoperate (e.g., a GeneratedMessageV3V3 object has a message extension field whose class
+// type is GeneratedMessageV3V4), these classes still share a common parent class AbstarctMessage
+// and are using the same GeneratedMessage.GeneratedExtension class for extension definitions.
+// Since this class becomes GeneratedMessageV3V? in opensource, we have to add an import here
+// to be able to use GeneratedMessage.GeneratedExtension. The GeneratedExtension definition in
+// this file is also excluded from opensource to avoid conflict.
+import com.google.protobuf.GeneratedMessage.GeneratedExtension;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectStreamException;
+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;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * All generated protocol message classes extend this class. This class
+ * implements most of the Message and Builder interfaces using Java reflection.
+ * Users can ignore this class and pretend that generated messages implement
+ * the Message interface directly.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public abstract class GeneratedMessageV3 extends AbstractMessage
+ implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * For testing. Allows a test to disable the optimization that avoids using
+ * field builders for nested messages until they are requested. By disabling
+ * this optimization, existing tests can be reused to test the field builders.
+ */
+ protected static boolean alwaysUseFieldBuilders = false;
+
+ /** For use by generated code only. */
+ protected UnknownFieldSet unknownFields;
+
+ protected GeneratedMessageV3() {
+ unknownFields = UnknownFieldSet.getDefaultInstance();
+ }
+
+ protected GeneratedMessageV3(Builder<?> builder) {
+ unknownFields = builder.getUnknownFields();
+ }
+
+ @Override
+ public Parser<? extends GeneratedMessageV3> getParserForType() {
+ throw new UnsupportedOperationException(
+ "This is supposed to be overridden by subclasses.");
+ }
+
+ /**
+ * For testing. Allows a test to disable the optimization that avoids using
+ * field builders for nested messages until they are requested. By disabling
+ * this optimization, existing tests can be reused to test the field builders.
+ * See {@link RepeatedFieldBuilder} and {@link SingleFieldBuilder}.
+ */
+ static void enableAlwaysUseFieldBuildersForTesting() {
+ alwaysUseFieldBuilders = true;
+ }
+
+ /**
+ * Get the FieldAccessorTable for this type. We can't have the message
+ * class pass this in to the constructor because of bootstrapping trouble
+ * with DescriptorProtos.
+ */
+ protected abstract FieldAccessorTable internalGetFieldAccessorTable();
+
+ @Override
+ public Descriptor getDescriptorForType() {
+ return internalGetFieldAccessorTable().descriptor;
+ }
+
+ /**
+ * Internal helper to return a modifiable map containing all the fields.
+ * The returned Map is modifialbe so that the caller can add additional
+ * extension fields to implement {@link #getAllFields()}.
+ *
+ * @param getBytesForString whether to generate ByteString for string fields
+ */
+ private Map<FieldDescriptor, Object> getAllFieldsMutable(
+ boolean getBytesForString) {
+ final TreeMap<FieldDescriptor, Object> result =
+ new TreeMap<FieldDescriptor, Object>();
+ final Descriptor descriptor = internalGetFieldAccessorTable().descriptor;
+ final List<FieldDescriptor> fields = descriptor.getFields();
+
+ for (int i = 0; i < fields.size(); i++) {
+ FieldDescriptor field = fields.get(i);
+ final OneofDescriptor oneofDescriptor = field.getContainingOneof();
+
+ /*
+ * If the field is part of a Oneof, then at maximum one field in the Oneof is set
+ * and it is not repeated. There is no need to iterate through the others.
+ */
+ if (oneofDescriptor != null) {
+ // Skip other fields in the Oneof we know are not set
+ i += oneofDescriptor.getFieldCount() - 1;
+ if (!hasOneof(oneofDescriptor)) {
+ // If no field is set in the Oneof, skip all the fields in the Oneof
+ continue;
+ }
+ // Get the pointer to the only field which is set in the Oneof
+ field = getOneofFieldDescriptor(oneofDescriptor);
+ } else {
+ // If we are not in a Oneof, we need to check if the field is set and if it is repeated
+ if (field.isRepeated()) {
+ final List<?> value = (List<?>) getField(field);
+ if (!value.isEmpty()) {
+ result.put(field, value);
+ }
+ continue;
+ }
+ if (!hasField(field)) {
+ continue;
+ }
+ }
+ // Add the field to the map
+ if (getBytesForString && field.getJavaType() == FieldDescriptor.JavaType.STRING) {
+ result.put(field, getFieldRaw(field));
+ } else {
+ result.put(field, getField(field));
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public boolean isInitialized() {
+ for (final FieldDescriptor field : getDescriptorForType().getFields()) {
+ // Check that all required fields are present.
+ if (field.isRequired()) {
+ if (!hasField(field)) {
+ return false;
+ }
+ }
+ // Check that embedded messages are initialized.
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ if (field.isRepeated()) {
+ @SuppressWarnings("unchecked") final
+ List<Message> messageList = (List<Message>) getField(field);
+ for (final Message element : messageList) {
+ if (!element.isInitialized()) {
+ return false;
+ }
+ }
+ } else {
+ if (hasField(field) && !((Message) getField(field)).isInitialized()) {
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public Map<FieldDescriptor, Object> getAllFields() {
+ return Collections.unmodifiableMap(
+ getAllFieldsMutable(/* getBytesForString = */ false));
+ }
+
+ /**
+ * Returns a collection of all the fields in this message which are set
+ * and their corresponding values. A singular ("required" or "optional")
+ * field is set iff hasField() returns true for that field. A "repeated"
+ * field is set iff getRepeatedFieldCount() is greater than zero. The
+ * values are exactly what would be returned by calling
+ * {@link #getFieldRaw(Descriptors.FieldDescriptor)} for each field. The map
+ * is guaranteed to be a sorted map, so iterating over it will return fields
+ * in order by field number.
+ */
+ Map<FieldDescriptor, Object> getAllFieldsRaw() {
+ return Collections.unmodifiableMap(
+ getAllFieldsMutable(/* getBytesForString = */ true));
+ }
+
+ @Override
+ public boolean hasOneof(final OneofDescriptor oneof) {
+ return internalGetFieldAccessorTable().getOneof(oneof).has(this);
+ }
+
+ @Override
+ public FieldDescriptor getOneofFieldDescriptor(final OneofDescriptor oneof) {
+ return internalGetFieldAccessorTable().getOneof(oneof).get(this);
+ }
+
+ @Override
+ public boolean hasField(final FieldDescriptor field) {
+ return internalGetFieldAccessorTable().getField(field).has(this);
+ }
+
+ @Override
+ public Object getField(final FieldDescriptor field) {
+ return internalGetFieldAccessorTable().getField(field).get(this);
+ }
+
+ /**
+ * Obtains the value of the given field, or the default value if it is
+ * not set. For primitive fields, the boxed primitive value is returned.
+ * For enum fields, the EnumValueDescriptor for the value is returned. For
+ * embedded message fields, the sub-message is returned. For repeated
+ * fields, a java.util.List is returned. For present string fields, a
+ * ByteString is returned representing the bytes that the field contains.
+ */
+ Object getFieldRaw(final FieldDescriptor field) {
+ return internalGetFieldAccessorTable().getField(field).getRaw(this);
+ }
+
+ @Override
+ public int getRepeatedFieldCount(final FieldDescriptor field) {
+ return internalGetFieldAccessorTable().getField(field)
+ .getRepeatedCount(this);
+ }
+
+ @Override
+ public Object getRepeatedField(final FieldDescriptor field, final int index) {
+ return internalGetFieldAccessorTable().getField(field)
+ .getRepeated(this, index);
+ }
+
+ @Override
+ public UnknownFieldSet getUnknownFields() {
+ throw new UnsupportedOperationException(
+ "This is supposed to be overridden by subclasses.");
+ }
+
+ /**
+ * Called by subclasses to parse an unknown field.
+ * @return {@code true} unless the tag is an end-group tag.
+ */
+ protected boolean parseUnknownField(
+ CodedInputStream input,
+ UnknownFieldSet.Builder unknownFields,
+ ExtensionRegistryLite extensionRegistry,
+ int tag) throws IOException {
+ return unknownFields.mergeFieldFrom(tag, input);
+ }
+
+ protected static <M extends Message> M parseWithIOException(Parser<M> parser, InputStream input)
+ throws IOException {
+ try {
+ return parser.parseFrom(input);
+ } catch (InvalidProtocolBufferException e) {
+ throw e.unwrapIOException();
+ }
+ }
+
+ protected static <M extends Message> M parseWithIOException(Parser<M> parser, InputStream input,
+ ExtensionRegistryLite extensions) throws IOException {
+ try {
+ return parser.parseFrom(input, extensions);
+ } catch (InvalidProtocolBufferException e) {
+ throw e.unwrapIOException();
+ }
+ }
+
+ protected static <M extends Message> M parseWithIOException(Parser<M> parser,
+ CodedInputStream input) throws IOException {
+ try {
+ return parser.parseFrom(input);
+ } catch (InvalidProtocolBufferException e) {
+ throw e.unwrapIOException();
+ }
+ }
+
+ protected static <M extends Message> M parseWithIOException(Parser<M> parser,
+ CodedInputStream input, ExtensionRegistryLite extensions) throws IOException {
+ try {
+ return parser.parseFrom(input, extensions);
+ } catch (InvalidProtocolBufferException e) {
+ throw e.unwrapIOException();
+ }
+ }
+
+ protected static <M extends Message> M parseDelimitedWithIOException(Parser<M> parser,
+ InputStream input) throws IOException {
+ try {
+ return parser.parseDelimitedFrom(input);
+ } catch (InvalidProtocolBufferException e) {
+ throw e.unwrapIOException();
+ }
+ }
+
+ protected static <M extends Message> M parseDelimitedWithIOException(Parser<M> parser,
+ InputStream input, ExtensionRegistryLite extensions) throws IOException {
+ try {
+ return parser.parseDelimitedFrom(input, extensions);
+ } catch (InvalidProtocolBufferException e) {
+ throw e.unwrapIOException();
+ }
+ }
+
+ @Override
+ public void writeTo(final CodedOutputStream output) throws IOException {
+ MessageReflection.writeMessageTo(this, getAllFieldsRaw(), output, false);
+ }
+
+ @Override
+ public int getSerializedSize() {
+ int size = memoizedSize;
+ if (size != -1) {
+ return size;
+ }
+
+ memoizedSize = MessageReflection.getSerializedSize(
+ this, getAllFieldsRaw());
+ return memoizedSize;
+ }
+
+
+
+ /**
+ * Used by parsing constructors in generated classes.
+ */
+ protected void makeExtensionsImmutable() {
+ // Noop for messages without extensions.
+ }
+
+ /**
+ * TODO(xiaofeng): remove this after b/29368482 is fixed. We need to move this
+ * interface to AbstractMessage in order to versioning GeneratedMessageV3 but
+ * this move breaks binary compatibility for AppEngine. After AppEngine is
+ * fixed we can exlude this from google3.
+ */
+ protected interface BuilderParent extends AbstractMessage.BuilderParent {}
+
+ /**
+ * TODO(xiaofeng): remove this together with GeneratedMessageV3.BuilderParent.
+ */
+ protected abstract Message.Builder newBuilderForType(BuilderParent parent);
+
+ @Override
+ protected Message.Builder newBuilderForType(final AbstractMessage.BuilderParent parent) {
+ return newBuilderForType(new BuilderParent() {
+ @Override
+ public void markDirty() {
+ parent.markDirty();
+ }
+ });
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public abstract static class Builder <BuilderType extends Builder<BuilderType>>
+ extends AbstractMessage.Builder<BuilderType> {
+
+ private BuilderParent builderParent;
+
+ private BuilderParentImpl meAsParent;
+
+ // Indicates that we've built a message and so we are now obligated
+ // to dispatch dirty invalidations. See GeneratedMessageV3.BuilderListener.
+ private boolean isClean;
+
+ private UnknownFieldSet unknownFields =
+ UnknownFieldSet.getDefaultInstance();
+
+ protected Builder() {
+ this(null);
+ }
+
+ protected Builder(BuilderParent builderParent) {
+ this.builderParent = builderParent;
+ }
+
+ @Override
+ void dispose() {
+ builderParent = null;
+ }
+
+ /**
+ * Called by the subclass when a message is built.
+ */
+ protected void onBuilt() {
+ if (builderParent != null) {
+ markClean();
+ }
+ }
+
+ /**
+ * Called by the subclass or a builder to notify us that a message was
+ * built and may be cached and therefore invalidations are needed.
+ */
+ @Override
+ protected void markClean() {
+ this.isClean = true;
+ }
+
+ /**
+ * Gets whether invalidations are needed
+ *
+ * @return whether invalidations are needed
+ */
+ protected boolean isClean() {
+ return isClean;
+ }
+
+ @Override
+ public BuilderType clone() {
+ BuilderType builder =
+ (BuilderType) getDefaultInstanceForType().newBuilderForType();
+ builder.mergeFrom(buildPartial());
+ return builder;
+ }
+
+ /**
+ * Called by the initialization and clear code paths to allow subclasses to
+ * reset any of their builtin fields back to the initial values.
+ */
+ @Override
+ public BuilderType clear() {
+ unknownFields = UnknownFieldSet.getDefaultInstance();
+ onChanged();
+ return (BuilderType) this;
+ }
+
+ /**
+ * Get the FieldAccessorTable for this type. We can't have the message
+ * class pass this in to the constructor because of bootstrapping trouble
+ * with DescriptorProtos.
+ */
+ protected abstract FieldAccessorTable internalGetFieldAccessorTable();
+
+ @Override
+ public Descriptor getDescriptorForType() {
+ return internalGetFieldAccessorTable().descriptor;
+ }
+
+ @Override
+ public Map<FieldDescriptor, Object> getAllFields() {
+ return Collections.unmodifiableMap(getAllFieldsMutable());
+ }
+
+ /** Internal helper which returns a mutable map. */
+ private Map<FieldDescriptor, Object> getAllFieldsMutable() {
+ final TreeMap<FieldDescriptor, Object> result =
+ new TreeMap<FieldDescriptor, Object>();
+ final Descriptor descriptor = internalGetFieldAccessorTable().descriptor;
+ final List<FieldDescriptor> fields = descriptor.getFields();
+
+ for (int i = 0; i < fields.size(); i++) {
+ FieldDescriptor field = fields.get(i);
+ final OneofDescriptor oneofDescriptor = field.getContainingOneof();
+
+ /*
+ * If the field is part of a Oneof, then at maximum one field in the Oneof is set
+ * and it is not repeated. There is no need to iterate through the others.
+ */
+ if (oneofDescriptor != null) {
+ // Skip other fields in the Oneof we know are not set
+ i += oneofDescriptor.getFieldCount() - 1;
+ if (!hasOneof(oneofDescriptor)) {
+ // If no field is set in the Oneof, skip all the fields in the Oneof
+ continue;
+ }
+ // Get the pointer to the only field which is set in the Oneof
+ field = getOneofFieldDescriptor(oneofDescriptor);
+ } else {
+ // If we are not in a Oneof, we need to check if the field is set and if it is repeated
+ if (field.isRepeated()) {
+ final List<?> value = (List<?>) getField(field);
+ if (!value.isEmpty()) {
+ result.put(field, value);
+ }
+ continue;
+ }
+ if (!hasField(field)) {
+ continue;
+ }
+ }
+ // Add the field to the map
+ result.put(field, getField(field));
+ }
+ return result;
+ }
+
+ @Override
+ public Message.Builder newBuilderForField(final FieldDescriptor field) {
+ return internalGetFieldAccessorTable().getField(field).newBuilder();
+ }
+
+ @Override
+ public Message.Builder getFieldBuilder(final FieldDescriptor field) {
+ return internalGetFieldAccessorTable().getField(field).getBuilder(this);
+ }
+
+ @Override
+ public Message.Builder getRepeatedFieldBuilder(final FieldDescriptor field, int index) {
+ return internalGetFieldAccessorTable().getField(field).getRepeatedBuilder(
+ this, index);
+ }
+
+ @Override
+ public boolean hasOneof(final OneofDescriptor oneof) {
+ return internalGetFieldAccessorTable().getOneof(oneof).has(this);
+ }
+
+ @Override
+ public FieldDescriptor getOneofFieldDescriptor(final OneofDescriptor oneof) {
+ return internalGetFieldAccessorTable().getOneof(oneof).get(this);
+ }
+
+ @Override
+ public boolean hasField(final FieldDescriptor field) {
+ return internalGetFieldAccessorTable().getField(field).has(this);
+ }
+
+ @Override
+ public Object getField(final FieldDescriptor field) {
+ Object object = internalGetFieldAccessorTable().getField(field).get(this);
+ if (field.isRepeated()) {
+ // The underlying list object is still modifiable at this point.
+ // Make sure not to expose the modifiable list to the caller.
+ return Collections.unmodifiableList((List) object);
+ } else {
+ return object;
+ }
+ }
+
+ @Override
+ public BuilderType setField(final FieldDescriptor field, final Object value) {
+ internalGetFieldAccessorTable().getField(field).set(this, value);
+ return (BuilderType) this;
+ }
+
+ @Override
+ public BuilderType clearField(final FieldDescriptor field) {
+ internalGetFieldAccessorTable().getField(field).clear(this);
+ return (BuilderType) this;
+ }
+
+ @Override
+ public BuilderType clearOneof(final OneofDescriptor oneof) {
+ internalGetFieldAccessorTable().getOneof(oneof).clear(this);
+ return (BuilderType) this;
+ }
+
+ @Override
+ public int getRepeatedFieldCount(final FieldDescriptor field) {
+ return internalGetFieldAccessorTable().getField(field)
+ .getRepeatedCount(this);
+ }
+
+ @Override
+ public Object getRepeatedField(final FieldDescriptor field, final int index) {
+ return internalGetFieldAccessorTable().getField(field)
+ .getRepeated(this, index);
+ }
+
+ @Override
+ public BuilderType setRepeatedField(
+ final FieldDescriptor field, final int index, final Object value) {
+ internalGetFieldAccessorTable().getField(field)
+ .setRepeated(this, index, value);
+ return (BuilderType) this;
+ }
+
+ @Override
+ public BuilderType addRepeatedField(final FieldDescriptor field, final Object value) {
+ internalGetFieldAccessorTable().getField(field).addRepeated(this, value);
+ return (BuilderType) this;
+ }
+
+ @Override
+ public BuilderType setUnknownFields(final UnknownFieldSet unknownFields) {
+ this.unknownFields = unknownFields;
+ onChanged();
+ return (BuilderType) this;
+ }
+
+ @Override
+ public BuilderType mergeUnknownFields(
+ final UnknownFieldSet unknownFields) {
+ this.unknownFields =
+ UnknownFieldSet.newBuilder(this.unknownFields)
+ .mergeFrom(unknownFields)
+ .build();
+ onChanged();
+ return (BuilderType) this;
+ }
+
+ @Override
+ public boolean isInitialized() {
+ for (final FieldDescriptor field : getDescriptorForType().getFields()) {
+ // Check that all required fields are present.
+ if (field.isRequired()) {
+ if (!hasField(field)) {
+ return false;
+ }
+ }
+ // Check that embedded messages are initialized.
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ if (field.isRepeated()) {
+ @SuppressWarnings("unchecked") final
+ List<Message> messageList = (List<Message>) getField(field);
+ for (final Message element : messageList) {
+ if (!element.isInitialized()) {
+ return false;
+ }
+ }
+ } else {
+ if (hasField(field) &&
+ !((Message) getField(field)).isInitialized()) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public final UnknownFieldSet getUnknownFields() {
+ return unknownFields;
+ }
+
+ /**
+ * Called by subclasses to parse an unknown field.
+ * @return {@code true} unless the tag is an end-group tag.
+ */
+ protected boolean parseUnknownField(
+ final CodedInputStream input,
+ final UnknownFieldSet.Builder unknownFields,
+ final ExtensionRegistryLite extensionRegistry,
+ final int tag) throws IOException {
+ return unknownFields.mergeFieldFrom(tag, input);
+ }
+
+ /**
+ * Implementation of {@link BuilderParent} for giving to our children. This
+ * small inner class makes it so we don't publicly expose the BuilderParent
+ * methods.
+ */
+ private class BuilderParentImpl implements BuilderParent {
+
+ @Override
+ public void markDirty() {
+ onChanged();
+ }
+ }
+
+ /**
+ * Gets the {@link BuilderParent} for giving to our children.
+ * @return The builder parent for our children.
+ */
+ protected BuilderParent getParentForChildren() {
+ if (meAsParent == null) {
+ meAsParent = new BuilderParentImpl();
+ }
+ return meAsParent;
+ }
+
+ /**
+ * Called when a the builder or one of its nested children has changed
+ * and any parent should be notified of its invalidation.
+ */
+ protected final void onChanged() {
+ if (isClean && builderParent != null) {
+ builderParent.markDirty();
+
+ // Don't keep dispatching invalidations until build is called again.
+ isClean = false;
+ }
+ }
+
+ /**
+ * Gets the map field with the given field number. This method should be
+ * overridden in the generated message class if the message contains map
+ * fields.
+ *
+ * Unlike other field types, reflection support for map fields can't be
+ * implemented based on generated public API because we need to access a
+ * map field as a list in reflection API but the generated API only allows
+ * us to access it as a map. This method returns the underlying map field
+ * directly and thus enables us to access the map field as a list.
+ */
+ @SuppressWarnings({"unused", "rawtypes"})
+ protected MapField internalGetMapField(int fieldNumber) {
+ // Note that we can't use descriptor names here because this method will
+ // be called when descriptor is being initialized.
+ throw new RuntimeException(
+ "No map fields found in " + getClass().getName());
+ }
+
+ /** Like {@link #internalGetMapField} but return a mutable version. */
+ @SuppressWarnings({"unused", "rawtypes"})
+ protected MapField internalGetMutableMapField(int fieldNumber) {
+ // Note that we can't use descriptor names here because this method will
+ // be called when descriptor is being initialized.
+ throw new RuntimeException(
+ "No map fields found in " + getClass().getName());
+ }
+ }
+
+ // =================================================================
+ // Extensions-related stuff
+
+ public interface ExtendableMessageOrBuilder<
+ MessageType extends ExtendableMessage> extends MessageOrBuilder {
+ // Re-define for return type covariance.
+ @Override
+ Message getDefaultInstanceForType();
+
+ /** Check if a singular extension is present. */
+ <Type> boolean hasExtension(
+ ExtensionLite<MessageType, Type> extension);
+
+ /** Get the number of elements in a repeated extension. */
+ <Type> int getExtensionCount(
+ ExtensionLite<MessageType, List<Type>> extension);
+
+ /** Get the value of an extension. */
+ <Type> Type getExtension(
+ ExtensionLite<MessageType, Type> extension);
+
+ /** Get one element of a repeated extension. */
+ <Type> Type getExtension(
+ ExtensionLite<MessageType, List<Type>> extension,
+ int index);
+
+ /** Check if a singular extension is present. */
+ <Type> boolean hasExtension(
+ Extension<MessageType, Type> extension);
+ /** Check if a singular extension is present. */
+ <Type> boolean hasExtension(
+ GeneratedExtension<MessageType, Type> extension);
+ /** Get the number of elements in a repeated extension. */
+ <Type> int getExtensionCount(
+ Extension<MessageType, List<Type>> extension);
+ /** Get the number of elements in a repeated extension. */
+ <Type> int getExtensionCount(
+ GeneratedExtension<MessageType, List<Type>> extension);
+ /** Get the value of an extension. */
+ <Type> Type getExtension(
+ Extension<MessageType, Type> extension);
+ /** Get the value of an extension. */
+ <Type> Type getExtension(
+ GeneratedExtension<MessageType, Type> extension);
+ /** Get one element of a repeated extension. */
+ <Type> Type getExtension(
+ Extension<MessageType, List<Type>> extension,
+ int index);
+ /** Get one element of a repeated extension. */
+ <Type> Type getExtension(
+ GeneratedExtension<MessageType, List<Type>> extension,
+ int index);
+ }
+
+ /**
+ * Generated message classes for message types that contain extension ranges
+ * subclass this.
+ *
+ * <p>This class implements type-safe accessors for extensions. They
+ * implement all the same operations that you can do with normal fields --
+ * e.g. "has", "get", and "getCount" -- but for extensions. The extensions
+ * are identified using instances of the class {@link GeneratedExtension};
+ * the protocol compiler generates a static instance of this class for every
+ * extension in its input. Through the magic of generics, all is made
+ * type-safe.
+ *
+ * <p>For example, imagine you have the {@code .proto} file:
+ *
+ * <pre>
+ * option java_class = "MyProto";
+ *
+ * message Foo {
+ * extensions 1000 to max;
+ * }
+ *
+ * extend Foo {
+ * optional int32 bar;
+ * }
+ * </pre>
+ *
+ * <p>Then you might write code like:
+ *
+ * <pre>
+ * MyProto.Foo foo = getFoo();
+ * int i = foo.getExtension(MyProto.bar);
+ * </pre>
+ *
+ * <p>See also {@link ExtendableBuilder}.
+ */
+ public abstract static class ExtendableMessage<
+ MessageType extends ExtendableMessage>
+ extends GeneratedMessageV3
+ implements ExtendableMessageOrBuilder<MessageType> {
+
+ private static final long serialVersionUID = 1L;
+
+ private final FieldSet<FieldDescriptor> extensions;
+
+ protected ExtendableMessage() {
+ this.extensions = FieldSet.newFieldSet();
+ }
+
+ protected ExtendableMessage(
+ ExtendableBuilder<MessageType, ?> builder) {
+ super(builder);
+ this.extensions = builder.buildExtensions();
+ }
+
+ private void verifyExtensionContainingType(
+ final Extension<MessageType, ?> extension) {
+ if (extension.getDescriptor().getContainingType() !=
+ getDescriptorForType()) {
+ // This can only happen if someone uses unchecked operations.
+ throw new IllegalArgumentException(
+ "Extension is for type \"" +
+ extension.getDescriptor().getContainingType().getFullName() +
+ "\" which does not match message type \"" +
+ getDescriptorForType().getFullName() + "\".");
+ }
+ }
+
+ /** Check if a singular extension is present. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public final <Type> boolean hasExtension(final ExtensionLite<MessageType, Type> extensionLite) {
+ Extension<MessageType, Type> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ return extensions.hasField(extension.getDescriptor());
+ }
+
+ /** Get the number of elements in a repeated extension. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public final <Type> int getExtensionCount(
+ final ExtensionLite<MessageType, List<Type>> extensionLite) {
+ Extension<MessageType, List<Type>> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ final FieldDescriptor descriptor = extension.getDescriptor();
+ return extensions.getRepeatedFieldCount(descriptor);
+ }
+
+ /** Get the value of an extension. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public final <Type> Type getExtension(final ExtensionLite<MessageType, Type> extensionLite) {
+ Extension<MessageType, Type> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ FieldDescriptor descriptor = extension.getDescriptor();
+ final Object value = extensions.getField(descriptor);
+ if (value == null) {
+ if (descriptor.isRepeated()) {
+ return (Type) Collections.emptyList();
+ } else if (descriptor.getJavaType() ==
+ FieldDescriptor.JavaType.MESSAGE) {
+ return (Type) extension.getMessageDefaultInstance();
+ } else {
+ return (Type) extension.fromReflectionType(
+ descriptor.getDefaultValue());
+ }
+ } else {
+ return (Type) extension.fromReflectionType(value);
+ }
+ }
+
+ /** Get one element of a repeated extension. */
+ @Override
+ @SuppressWarnings("unchecked")
+ public final <Type> Type getExtension(
+ final ExtensionLite<MessageType, List<Type>> extensionLite, final int index) {
+ Extension<MessageType, List<Type>> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ FieldDescriptor descriptor = extension.getDescriptor();
+ return (Type) extension.singularFromReflectionType(
+ extensions.getRepeatedField(descriptor, index));
+ }
+
+ /** Check if a singular extension is present. */
+ @Override
+ public final <Type> boolean hasExtension(final Extension<MessageType, Type> extension) {
+ return hasExtension((ExtensionLite<MessageType, Type>) extension);
+ }
+ /** Check if a singular extension is present. */
+ @Override
+ public final <Type> boolean hasExtension(
+ final GeneratedExtension<MessageType, Type> extension) {
+ return hasExtension((ExtensionLite<MessageType, Type>) extension);
+ }
+ /** Get the number of elements in a repeated extension. */
+ @Override
+ public final <Type> int getExtensionCount(
+ final Extension<MessageType, List<Type>> extension) {
+ return getExtensionCount((ExtensionLite<MessageType, List<Type>>) extension);
+ }
+ /** Get the number of elements in a repeated extension. */
+ @Override
+ public final <Type> int getExtensionCount(
+ final GeneratedExtension<MessageType, List<Type>> extension) {
+ return getExtensionCount((ExtensionLite<MessageType, List<Type>>) extension);
+ }
+ /** Get the value of an extension. */
+ @Override
+ public final <Type> Type getExtension(final Extension<MessageType, Type> extension) {
+ return getExtension((ExtensionLite<MessageType, Type>) extension);
+ }
+ /** Get the value of an extension. */
+ @Override
+ public final <Type> Type getExtension(
+ final GeneratedExtension<MessageType, Type> extension) {
+ return getExtension((ExtensionLite<MessageType, Type>) extension);
+ }
+ /** Get one element of a repeated extension. */
+ @Override
+ public final <Type> Type getExtension(
+ final Extension<MessageType, List<Type>> extension, final int index) {
+ return getExtension((ExtensionLite<MessageType, List<Type>>) extension, index);
+ }
+ /** Get one element of a repeated extension. */
+ @Override
+ public final <Type> Type getExtension(
+ final GeneratedExtension<MessageType, List<Type>> extension, final int index) {
+ return getExtension((ExtensionLite<MessageType, List<Type>>) extension, index);
+ }
+
+ /** Called by subclasses to check if all extensions are initialized. */
+ protected boolean extensionsAreInitialized() {
+ return extensions.isInitialized();
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return super.isInitialized() && extensionsAreInitialized();
+ }
+
+ @Override
+ protected boolean parseUnknownField(
+ CodedInputStream input,
+ UnknownFieldSet.Builder unknownFields,
+ ExtensionRegistryLite extensionRegistry,
+ int tag) throws IOException {
+ return MessageReflection.mergeFieldFrom(
+ input, unknownFields, extensionRegistry, getDescriptorForType(),
+ new MessageReflection.ExtensionAdapter(extensions), tag);
+ }
+
+
+ /**
+ * Used by parsing constructors in generated classes.
+ */
+ @Override
+ protected void makeExtensionsImmutable() {
+ extensions.makeImmutable();
+ }
+
+ /**
+ * Used by subclasses to serialize extensions. Extension ranges may be
+ * interleaved with field numbers, but we must write them in canonical
+ * (sorted by field number) order. ExtensionWriter helps us write
+ * individual ranges of extensions at once.
+ */
+ protected class ExtensionWriter {
+ // Imagine how much simpler this code would be if Java iterators had
+ // a way to get the next element without advancing the iterator.
+
+ private final Iterator<Map.Entry<FieldDescriptor, Object>> iter =
+ extensions.iterator();
+ private Map.Entry<FieldDescriptor, Object> next;
+ private final boolean messageSetWireFormat;
+
+ private ExtensionWriter(final boolean messageSetWireFormat) {
+ if (iter.hasNext()) {
+ next = iter.next();
+ }
+ this.messageSetWireFormat = messageSetWireFormat;
+ }
+
+ public void writeUntil(final int end, final CodedOutputStream output)
+ throws IOException {
+ while (next != null && next.getKey().getNumber() < end) {
+ FieldDescriptor descriptor = next.getKey();
+ if (messageSetWireFormat && descriptor.getLiteJavaType() ==
+ WireFormat.JavaType.MESSAGE &&
+ !descriptor.isRepeated()) {
+ if (next instanceof LazyField.LazyEntry<?>) {
+ output.writeRawMessageSetExtension(descriptor.getNumber(),
+ ((LazyField.LazyEntry<?>) next).getField().toByteString());
+ } else {
+ output.writeMessageSetExtension(descriptor.getNumber(),
+ (Message) next.getValue());
+ }
+ } else {
+ // TODO(xiangl): Taken care of following code, it may cause
+ // problem when we use LazyField for normal fields/extensions.
+ // Due to the optional field can be duplicated at the end of
+ // serialized bytes, which will make the serialized size change
+ // after lazy field parsed. So when we use LazyField globally,
+ // we need to change the following write method to write cached
+ // bytes directly rather than write the parsed message.
+ FieldSet.writeField(descriptor, next.getValue(), output);
+ }
+ if (iter.hasNext()) {
+ next = iter.next();
+ } else {
+ next = null;
+ }
+ }
+ }
+ }
+
+ protected ExtensionWriter newExtensionWriter() {
+ return new ExtensionWriter(false);
+ }
+ protected ExtensionWriter newMessageSetExtensionWriter() {
+ return new ExtensionWriter(true);
+ }
+
+ /** Called by subclasses to compute the size of extensions. */
+ protected int extensionsSerializedSize() {
+ return extensions.getSerializedSize();
+ }
+ protected int extensionsSerializedSizeAsMessageSet() {
+ return extensions.getMessageSetSerializedSize();
+ }
+
+ // ---------------------------------------------------------------
+ // Reflection
+
+ protected Map<FieldDescriptor, Object> getExtensionFields() {
+ return extensions.getAllFields();
+ }
+
+ @Override
+ public Map<FieldDescriptor, Object> getAllFields() {
+ final Map<FieldDescriptor, Object> result =
+ super.getAllFieldsMutable(/* getBytesForString = */ false);
+ result.putAll(getExtensionFields());
+ return Collections.unmodifiableMap(result);
+ }
+
+ @Override
+ public Map<FieldDescriptor, Object> getAllFieldsRaw() {
+ final Map<FieldDescriptor, Object> result =
+ super.getAllFieldsMutable(/* getBytesForString = */ false);
+ result.putAll(getExtensionFields());
+ return Collections.unmodifiableMap(result);
+ }
+
+ @Override
+ public boolean hasField(final FieldDescriptor field) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ return extensions.hasField(field);
+ } else {
+ return super.hasField(field);
+ }
+ }
+
+ @Override
+ public Object getField(final FieldDescriptor field) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ final Object value = extensions.getField(field);
+ if (value == null) {
+ if (field.isRepeated()) {
+ return Collections.emptyList();
+ } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ // Lacking an ExtensionRegistry, we have no way to determine the
+ // extension's real type, so we return a DynamicMessage.
+ return DynamicMessage.getDefaultInstance(field.getMessageType());
+ } else {
+ return field.getDefaultValue();
+ }
+ } else {
+ return value;
+ }
+ } else {
+ return super.getField(field);
+ }
+ }
+
+ @Override
+ public int getRepeatedFieldCount(final FieldDescriptor field) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ return extensions.getRepeatedFieldCount(field);
+ } else {
+ return super.getRepeatedFieldCount(field);
+ }
+ }
+
+ @Override
+ public Object getRepeatedField(final FieldDescriptor field,
+ final int index) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ return extensions.getRepeatedField(field, index);
+ } else {
+ return super.getRepeatedField(field, index);
+ }
+ }
+
+ private void verifyContainingType(final FieldDescriptor field) {
+ if (field.getContainingType() != getDescriptorForType()) {
+ throw new IllegalArgumentException(
+ "FieldDescriptor does not match message type.");
+ }
+ }
+ }
+
+ /**
+ * Generated message builders for message types that contain extension ranges
+ * subclass this.
+ *
+ * <p>This class implements type-safe accessors for extensions. They
+ * implement all the same operations that you can do with normal fields --
+ * e.g. "get", "set", and "add" -- but for extensions. The extensions are
+ * identified using instances of the class {@link GeneratedExtension}; the
+ * protocol compiler generates a static instance of this class for every
+ * extension in its input. Through the magic of generics, all is made
+ * type-safe.
+ *
+ * <p>For example, imagine you have the {@code .proto} file:
+ *
+ * <pre>
+ * option java_class = "MyProto";
+ *
+ * message Foo {
+ * extensions 1000 to max;
+ * }
+ *
+ * extend Foo {
+ * optional int32 bar;
+ * }
+ * </pre>
+ *
+ * <p>Then you might write code like:
+ *
+ * <pre>
+ * MyProto.Foo foo =
+ * MyProto.Foo.newBuilder()
+ * .setExtension(MyProto.bar, 123)
+ * .build();
+ * </pre>
+ *
+ * <p>See also {@link ExtendableMessage}.
+ */
+ @SuppressWarnings("unchecked")
+ public abstract static class ExtendableBuilder<
+ MessageType extends ExtendableMessage,
+ BuilderType extends ExtendableBuilder<MessageType, BuilderType>>
+ extends Builder<BuilderType>
+ implements ExtendableMessageOrBuilder<MessageType> {
+
+ private FieldSet<FieldDescriptor> extensions = FieldSet.emptySet();
+
+ protected ExtendableBuilder() {}
+
+ protected ExtendableBuilder(
+ BuilderParent parent) {
+ super(parent);
+ }
+
+ // For immutable message conversion.
+ void internalSetExtensionSet(FieldSet<FieldDescriptor> extensions) {
+ this.extensions = extensions;
+ }
+
+ @Override
+ public BuilderType clear() {
+ extensions = FieldSet.emptySet();
+ return super.clear();
+ }
+
+ private void ensureExtensionsIsMutable() {
+ if (extensions.isImmutable()) {
+ extensions = extensions.clone();
+ }
+ }
+
+ private void verifyExtensionContainingType(
+ final Extension<MessageType, ?> extension) {
+ if (extension.getDescriptor().getContainingType() !=
+ getDescriptorForType()) {
+ // This can only happen if someone uses unchecked operations.
+ throw new IllegalArgumentException(
+ "Extension is for type \"" +
+ extension.getDescriptor().getContainingType().getFullName() +
+ "\" which does not match message type \"" +
+ getDescriptorForType().getFullName() + "\".");
+ }
+ }
+
+ /** Check if a singular extension is present. */
+ @Override
+ public final <Type> boolean hasExtension(final ExtensionLite<MessageType, Type> extensionLite) {
+ Extension<MessageType, Type> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ return extensions.hasField(extension.getDescriptor());
+ }
+
+ /** Get the number of elements in a repeated extension. */
+ @Override
+ public final <Type> int getExtensionCount(
+ final ExtensionLite<MessageType, List<Type>> extensionLite) {
+ Extension<MessageType, List<Type>> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ final FieldDescriptor descriptor = extension.getDescriptor();
+ return extensions.getRepeatedFieldCount(descriptor);
+ }
+
+ /** Get the value of an extension. */
+ @Override
+ public final <Type> Type getExtension(final ExtensionLite<MessageType, Type> extensionLite) {
+ Extension<MessageType, Type> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ FieldDescriptor descriptor = extension.getDescriptor();
+ final Object value = extensions.getField(descriptor);
+ if (value == null) {
+ if (descriptor.isRepeated()) {
+ return (Type) Collections.emptyList();
+ } else if (descriptor.getJavaType() ==
+ FieldDescriptor.JavaType.MESSAGE) {
+ return (Type) extension.getMessageDefaultInstance();
+ } else {
+ return (Type) extension.fromReflectionType(
+ descriptor.getDefaultValue());
+ }
+ } else {
+ return (Type) extension.fromReflectionType(value);
+ }
+ }
+
+ /** Get one element of a repeated extension. */
+ @Override
+ public final <Type> Type getExtension(
+ final ExtensionLite<MessageType, List<Type>> extensionLite, final int index) {
+ Extension<MessageType, List<Type>> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ FieldDescriptor descriptor = extension.getDescriptor();
+ return (Type) extension.singularFromReflectionType(
+ extensions.getRepeatedField(descriptor, index));
+ }
+
+ /** Set the value of an extension. */
+ public final <Type> BuilderType setExtension(
+ final ExtensionLite<MessageType, Type> extensionLite,
+ final Type value) {
+ Extension<MessageType, Type> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ ensureExtensionsIsMutable();
+ final FieldDescriptor descriptor = extension.getDescriptor();
+ extensions.setField(descriptor, extension.toReflectionType(value));
+ onChanged();
+ return (BuilderType) this;
+ }
+
+ /** Set the value of one element of a repeated extension. */
+ public final <Type> BuilderType setExtension(
+ final ExtensionLite<MessageType, List<Type>> extensionLite,
+ final int index, final Type value) {
+ Extension<MessageType, List<Type>> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ ensureExtensionsIsMutable();
+ final FieldDescriptor descriptor = extension.getDescriptor();
+ extensions.setRepeatedField(
+ descriptor, index,
+ extension.singularToReflectionType(value));
+ onChanged();
+ return (BuilderType) this;
+ }
+
+ /** Append a value to a repeated extension. */
+ public final <Type> BuilderType addExtension(
+ final ExtensionLite<MessageType, List<Type>> extensionLite,
+ final Type value) {
+ Extension<MessageType, List<Type>> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ ensureExtensionsIsMutable();
+ final FieldDescriptor descriptor = extension.getDescriptor();
+ extensions.addRepeatedField(
+ descriptor, extension.singularToReflectionType(value));
+ onChanged();
+ return (BuilderType) this;
+ }
+
+ /** Clear an extension. */
+ public final <Type> BuilderType clearExtension(
+ final ExtensionLite<MessageType, ?> extensionLite) {
+ Extension<MessageType, ?> extension = checkNotLite(extensionLite);
+
+ verifyExtensionContainingType(extension);
+ ensureExtensionsIsMutable();
+ extensions.clearField(extension.getDescriptor());
+ onChanged();
+ return (BuilderType) this;
+ }
+
+ /** Check if a singular extension is present. */
+ @Override
+ public final <Type> boolean hasExtension(final Extension<MessageType, Type> extension) {
+ return hasExtension((ExtensionLite<MessageType, Type>) extension);
+ }
+ /** Check if a singular extension is present. */
+ @Override
+ public final <Type> boolean hasExtension(
+ final GeneratedExtension<MessageType, Type> extension) {
+ return hasExtension((ExtensionLite<MessageType, Type>) extension);
+ }
+ /** Get the number of elements in a repeated extension. */
+ @Override
+ public final <Type> int getExtensionCount(
+ final Extension<MessageType, List<Type>> extension) {
+ return getExtensionCount((ExtensionLite<MessageType, List<Type>>) extension);
+ }
+ /** Get the number of elements in a repeated extension. */
+ @Override
+ public final <Type> int getExtensionCount(
+ final GeneratedExtension<MessageType, List<Type>> extension) {
+ return getExtensionCount((ExtensionLite<MessageType, List<Type>>) extension);
+ }
+ /** Get the value of an extension. */
+ @Override
+ public final <Type> Type getExtension(final Extension<MessageType, Type> extension) {
+ return getExtension((ExtensionLite<MessageType, Type>) extension);
+ }
+ /** Get the value of an extension. */
+ @Override
+ public final <Type> Type getExtension(
+ final GeneratedExtension<MessageType, Type> extension) {
+ return getExtension((ExtensionLite<MessageType, Type>) extension);
+ }
+ /** Get the value of an extension. */
+ @Override
+ public final <Type> Type getExtension(
+ final Extension<MessageType, List<Type>> extension, final int index) {
+ return getExtension((ExtensionLite<MessageType, List<Type>>) extension, index);
+ }
+ /** Get the value of an extension. */
+ @Override
+ public final <Type> Type getExtension(
+ final GeneratedExtension<MessageType, List<Type>> extension, final int index) {
+ return getExtension((ExtensionLite<MessageType, List<Type>>) extension, index);
+ }
+ /** Set the value of an extension. */
+ public final <Type> BuilderType setExtension(
+ final Extension<MessageType, Type> extension, final Type value) {
+ return setExtension((ExtensionLite<MessageType, Type>) extension, value);
+ }
+ /** Set the value of an extension. */
+ public <Type> BuilderType setExtension(
+ final GeneratedExtension<MessageType, Type> extension, final Type value) {
+ return setExtension((ExtensionLite<MessageType, Type>) extension, value);
+ }
+ /** Set the value of one element of a repeated extension. */
+ public final <Type> BuilderType setExtension(
+ final Extension<MessageType, List<Type>> extension,
+ final int index, final Type value) {
+ return setExtension((ExtensionLite<MessageType, List<Type>>) extension, index, value);
+ }
+ /** Set the value of one element of a repeated extension. */
+ public <Type> BuilderType setExtension(
+ final GeneratedExtension<MessageType, List<Type>> extension,
+ final int index, final Type value) {
+ return setExtension((ExtensionLite<MessageType, List<Type>>) extension, index, value);
+ }
+ /** Append a value to a repeated extension. */
+ public final <Type> BuilderType addExtension(
+ final Extension<MessageType, List<Type>> extension, final Type value) {
+ return addExtension((ExtensionLite<MessageType, List<Type>>) extension, value);
+ }
+ /** Append a value to a repeated extension. */
+ public <Type> BuilderType addExtension(
+ final GeneratedExtension<MessageType, List<Type>> extension, final Type value) {
+ return addExtension((ExtensionLite<MessageType, List<Type>>) extension, value);
+ }
+ /** Clear an extension. */
+ public final <Type> BuilderType clearExtension(
+ final Extension<MessageType, ?> extension) {
+ return clearExtension((ExtensionLite<MessageType, ?>) extension);
+ }
+ /** Clear an extension. */
+ public <Type> BuilderType clearExtension(
+ final GeneratedExtension<MessageType, ?> extension) {
+ return clearExtension((ExtensionLite<MessageType, ?>) extension);
+ }
+
+ /** Called by subclasses to check if all extensions are initialized. */
+ protected boolean extensionsAreInitialized() {
+ return extensions.isInitialized();
+ }
+
+ /**
+ * Called by the build code path to create a copy of the extensions for
+ * building the message.
+ */
+ private FieldSet<FieldDescriptor> buildExtensions() {
+ extensions.makeImmutable();
+ return extensions;
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return super.isInitialized() && extensionsAreInitialized();
+ }
+
+ /**
+ * Called by subclasses to parse an unknown field or an extension.
+ * @return {@code true} unless the tag is an end-group tag.
+ */
+ @Override
+ protected boolean parseUnknownField(
+ final CodedInputStream input,
+ final UnknownFieldSet.Builder unknownFields,
+ final ExtensionRegistryLite extensionRegistry,
+ final int tag) throws IOException {
+ return MessageReflection.mergeFieldFrom(
+ input, unknownFields, extensionRegistry, getDescriptorForType(),
+ new MessageReflection.BuilderAdapter(this), tag);
+ }
+
+ // ---------------------------------------------------------------
+ // Reflection
+
+ @Override
+ public Map<FieldDescriptor, Object> getAllFields() {
+ final Map<FieldDescriptor, Object> result = super.getAllFieldsMutable();
+ result.putAll(extensions.getAllFields());
+ return Collections.unmodifiableMap(result);
+ }
+
+ @Override
+ public Object getField(final FieldDescriptor field) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ final Object value = extensions.getField(field);
+ if (value == null) {
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ // Lacking an ExtensionRegistry, we have no way to determine the
+ // extension's real type, so we return a DynamicMessage.
+ return DynamicMessage.getDefaultInstance(field.getMessageType());
+ } else {
+ return field.getDefaultValue();
+ }
+ } else {
+ return value;
+ }
+ } else {
+ return super.getField(field);
+ }
+ }
+
+ @Override
+ public int getRepeatedFieldCount(final FieldDescriptor field) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ return extensions.getRepeatedFieldCount(field);
+ } else {
+ return super.getRepeatedFieldCount(field);
+ }
+ }
+
+ @Override
+ public Object getRepeatedField(final FieldDescriptor field,
+ final int index) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ return extensions.getRepeatedField(field, index);
+ } else {
+ return super.getRepeatedField(field, index);
+ }
+ }
+
+ @Override
+ public boolean hasField(final FieldDescriptor field) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ return extensions.hasField(field);
+ } else {
+ return super.hasField(field);
+ }
+ }
+
+ @Override
+ public BuilderType setField(final FieldDescriptor field,
+ final Object value) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ ensureExtensionsIsMutable();
+ extensions.setField(field, value);
+ onChanged();
+ return (BuilderType) this;
+ } else {
+ return super.setField(field, value);
+ }
+ }
+
+ @Override
+ public BuilderType clearField(final FieldDescriptor field) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ ensureExtensionsIsMutable();
+ extensions.clearField(field);
+ onChanged();
+ return (BuilderType) this;
+ } else {
+ return super.clearField(field);
+ }
+ }
+
+ @Override
+ public BuilderType setRepeatedField(final FieldDescriptor field,
+ final int index, final Object value) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ ensureExtensionsIsMutable();
+ extensions.setRepeatedField(field, index, value);
+ onChanged();
+ return (BuilderType) this;
+ } else {
+ return super.setRepeatedField(field, index, value);
+ }
+ }
+
+ @Override
+ public BuilderType addRepeatedField(final FieldDescriptor field,
+ final Object value) {
+ if (field.isExtension()) {
+ verifyContainingType(field);
+ ensureExtensionsIsMutable();
+ extensions.addRepeatedField(field, value);
+ onChanged();
+ return (BuilderType) this;
+ } else {
+ return super.addRepeatedField(field, value);
+ }
+ }
+
+ protected final void mergeExtensionFields(final ExtendableMessage other) {
+ ensureExtensionsIsMutable();
+ extensions.mergeFrom(other.extensions);
+ onChanged();
+ }
+
+ private void verifyContainingType(final FieldDescriptor field) {
+ if (field.getContainingType() != getDescriptorForType()) {
+ throw new IllegalArgumentException(
+ "FieldDescriptor does not match message type.");
+ }
+ }
+ }
+
+ // -----------------------------------------------------------------
+
+ /**
+ * Gets the descriptor for an extension. The implementation depends on whether
+ * the extension is scoped in the top level of a file or scoped in a Message.
+ */
+ static interface ExtensionDescriptorRetriever {
+ FieldDescriptor getDescriptor();
+ }
+
+
+ // =================================================================
+
+ /** Calls Class.getMethod and throws a RuntimeException if it fails. */
+ @SuppressWarnings("unchecked")
+ private static Method getMethodOrDie(
+ final Class clazz, final String name, final Class... params) {
+ try {
+ return clazz.getMethod(name, params);
+ } catch (NoSuchMethodException e) {
+ throw new RuntimeException(
+ "Generated message class \"" + clazz.getName() +
+ "\" missing method \"" + name + "\".", e);
+ }
+ }
+
+ /** Calls invoke and throws a RuntimeException if it fails. */
+ private static Object invokeOrDie(
+ final Method method, final Object object, final Object... params) {
+ try {
+ return method.invoke(object, params);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(
+ "Couldn't use Java reflection to implement protocol message " +
+ "reflection.", e);
+ } catch (InvocationTargetException e) {
+ final Throwable cause = e.getCause();
+ if (cause instanceof RuntimeException) {
+ throw (RuntimeException) cause;
+ } else if (cause instanceof Error) {
+ throw (Error) cause;
+ } else {
+ throw new RuntimeException(
+ "Unexpected exception thrown by generated accessor method.", cause);
+ }
+ }
+ }
+
+ /**
+ * Gets the map field with the given field number. This method should be
+ * overridden in the generated message class if the message contains map
+ * fields.
+ *
+ * Unlike other field types, reflection support for map fields can't be
+ * implemented based on generated public API because we need to access a
+ * map field as a list in reflection API but the generated API only allows
+ * us to access it as a map. This method returns the underlying map field
+ * directly and thus enables us to access the map field as a list.
+ */
+ @SuppressWarnings({"rawtypes", "unused"})
+ protected MapField internalGetMapField(int fieldNumber) {
+ // Note that we can't use descriptor names here because this method will
+ // be called when descriptor is being initialized.
+ throw new RuntimeException(
+ "No map fields found in " + getClass().getName());
+ }
+
+ /**
+ * Users should ignore this class. This class provides the implementation
+ * with access to the fields of a message object using Java reflection.
+ */
+ public static final class FieldAccessorTable {
+
+ /**
+ * Construct a FieldAccessorTable for a particular message class. Only
+ * one FieldAccessorTable should ever be constructed per class.
+ *
+ * @param descriptor The type's descriptor.
+ * @param camelCaseNames The camelcase names of all fields in the message.
+ * These are used to derive the accessor method names.
+ * @param messageClass The message type.
+ * @param builderClass The builder type.
+ */
+ public FieldAccessorTable(
+ final Descriptor descriptor,
+ final String[] camelCaseNames,
+ final Class<? extends GeneratedMessageV3> messageClass,
+ final Class<? extends Builder> builderClass) {
+ this(descriptor, camelCaseNames);
+ ensureFieldAccessorsInitialized(messageClass, builderClass);
+ }
+
+ /**
+ * Construct a FieldAccessorTable for a particular message class without
+ * initializing FieldAccessors.
+ */
+ public FieldAccessorTable(
+ final Descriptor descriptor,
+ final String[] camelCaseNames) {
+ this.descriptor = descriptor;
+ this.camelCaseNames = camelCaseNames;
+ fields = new FieldAccessor[descriptor.getFields().size()];
+ oneofs = new OneofAccessor[descriptor.getOneofs().size()];
+ initialized = false;
+ }
+
+ /**
+ * Ensures the field accessors are initialized. This method is thread-safe.
+ *
+ * @param messageClass The message type.
+ * @param builderClass The builder type.
+ * @return this
+ */
+ public FieldAccessorTable ensureFieldAccessorsInitialized(
+ Class<? extends GeneratedMessageV3> messageClass,
+ Class<? extends Builder> builderClass) {
+ if (initialized) { return this; }
+ synchronized (this) {
+ if (initialized) { return this; }
+ int fieldsSize = fields.length;
+ for (int i = 0; i < fieldsSize; i++) {
+ FieldDescriptor field = descriptor.getFields().get(i);
+ String containingOneofCamelCaseName = null;
+ if (field.getContainingOneof() != null) {
+ containingOneofCamelCaseName =
+ camelCaseNames[fieldsSize + field.getContainingOneof().getIndex()];
+ }
+ if (field.isRepeated()) {
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ if (field.isMapField()) {
+ fields[i] = new MapFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass);
+ } else {
+ fields[i] = new RepeatedMessageFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass);
+ }
+ } else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) {
+ fields[i] = new RepeatedEnumFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass);
+ } else {
+ fields[i] = new RepeatedFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass);
+ }
+ } else {
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ fields[i] = new SingularMessageFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass,
+ containingOneofCamelCaseName);
+ } else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM) {
+ fields[i] = new SingularEnumFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass,
+ containingOneofCamelCaseName);
+ } else if (field.getJavaType() == FieldDescriptor.JavaType.STRING) {
+ fields[i] = new SingularStringFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass,
+ containingOneofCamelCaseName);
+ } else {
+ fields[i] = new SingularFieldAccessor(
+ field, camelCaseNames[i], messageClass, builderClass,
+ containingOneofCamelCaseName);
+ }
+ }
+ }
+
+ int oneofsSize = oneofs.length;
+ for (int i = 0; i < oneofsSize; i++) {
+ oneofs[i] = new OneofAccessor(
+ descriptor, camelCaseNames[i + fieldsSize],
+ messageClass, builderClass);
+ }
+ initialized = true;
+ camelCaseNames = null;
+ return this;
+ }
+ }
+
+ private final Descriptor descriptor;
+ private final FieldAccessor[] fields;
+ private String[] camelCaseNames;
+ private final OneofAccessor[] oneofs;
+ private volatile boolean initialized;
+
+ /** Get the FieldAccessor for a particular field. */
+ private FieldAccessor getField(final FieldDescriptor field) {
+ if (field.getContainingType() != descriptor) {
+ throw new IllegalArgumentException(
+ "FieldDescriptor does not match message type.");
+ } else if (field.isExtension()) {
+ // If this type had extensions, it would subclass ExtendableMessage,
+ // which overrides the reflection interface to handle extensions.
+ throw new IllegalArgumentException(
+ "This type does not have extensions.");
+ }
+ return fields[field.getIndex()];
+ }
+
+ /** Get the OneofAccessor for a particular oneof. */
+ private OneofAccessor getOneof(final OneofDescriptor oneof) {
+ if (oneof.getContainingType() != descriptor) {
+ throw new IllegalArgumentException(
+ "OneofDescriptor does not match message type.");
+ }
+ return oneofs[oneof.getIndex()];
+ }
+
+ /**
+ * Abstract interface that provides access to a single field. This is
+ * implemented differently depending on the field type and cardinality.
+ */
+ private interface FieldAccessor {
+ Object get(GeneratedMessageV3 message);
+ Object get(GeneratedMessageV3.Builder builder);
+ Object getRaw(GeneratedMessageV3 message);
+ Object getRaw(GeneratedMessageV3.Builder builder);
+ void set(Builder builder, Object value);
+ Object getRepeated(GeneratedMessageV3 message, int index);
+ Object getRepeated(GeneratedMessageV3.Builder builder, int index);
+ Object getRepeatedRaw(GeneratedMessageV3 message, int index);
+ Object getRepeatedRaw(GeneratedMessageV3.Builder builder, int index);
+ void setRepeated(Builder builder,
+ int index, Object value);
+ void addRepeated(Builder builder, Object value);
+ boolean has(GeneratedMessageV3 message);
+ boolean has(GeneratedMessageV3.Builder builder);
+ int getRepeatedCount(GeneratedMessageV3 message);
+ int getRepeatedCount(GeneratedMessageV3.Builder builder);
+ void clear(Builder builder);
+ Message.Builder newBuilder();
+ Message.Builder getBuilder(GeneratedMessageV3.Builder builder);
+ Message.Builder getRepeatedBuilder(GeneratedMessageV3.Builder builder,
+ int index);
+ }
+
+ /** OneofAccessor provides access to a single oneof. */
+ private static class OneofAccessor {
+ OneofAccessor(
+ final Descriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessageV3> messageClass,
+ final Class<? extends Builder> builderClass) {
+ this.descriptor = descriptor;
+ caseMethod =
+ getMethodOrDie(messageClass, "get" + camelCaseName + "Case");
+ caseMethodBuilder =
+ getMethodOrDie(builderClass, "get" + camelCaseName + "Case");
+ clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName);
+ }
+
+ private final Descriptor descriptor;
+ private final Method caseMethod;
+ private final Method caseMethodBuilder;
+ private final Method clearMethod;
+
+ public boolean has(final GeneratedMessageV3 message) {
+ if (((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber() == 0) {
+ return false;
+ }
+ return true;
+ }
+
+ public boolean has(GeneratedMessageV3.Builder builder) {
+ if (((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber() == 0) {
+ return false;
+ }
+ return true;
+ }
+
+ public FieldDescriptor get(final GeneratedMessageV3 message) {
+ int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber();
+ if (fieldNumber > 0) {
+ return descriptor.findFieldByNumber(fieldNumber);
+ }
+ return null;
+ }
+
+ public FieldDescriptor get(GeneratedMessageV3.Builder builder) {
+ int fieldNumber = ((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber();
+ if (fieldNumber > 0) {
+ return descriptor.findFieldByNumber(fieldNumber);
+ }
+ return null;
+ }
+
+ public void clear(final Builder builder) {
+ invokeOrDie(clearMethod, builder);
+ }
+ }
+
+ private static boolean supportFieldPresence(FileDescriptor file) {
+ return file.getSyntax() == FileDescriptor.Syntax.PROTO2;
+ }
+
+ // ---------------------------------------------------------------
+
+ private static class SingularFieldAccessor implements FieldAccessor {
+ SingularFieldAccessor(
+ final FieldDescriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessageV3> messageClass,
+ final Class<? extends Builder> builderClass,
+ final String containingOneofCamelCaseName) {
+ field = descriptor;
+ isOneofField = descriptor.getContainingOneof() != null;
+ hasHasMethod = supportFieldPresence(descriptor.getFile())
+ || (!isOneofField && descriptor.getJavaType() == FieldDescriptor.JavaType.MESSAGE);
+ getMethod = getMethodOrDie(messageClass, "get" + camelCaseName);
+ getMethodBuilder = getMethodOrDie(builderClass, "get" + camelCaseName);
+ type = getMethod.getReturnType();
+ setMethod = getMethodOrDie(builderClass, "set" + camelCaseName, type);
+ hasMethod =
+ hasHasMethod ? getMethodOrDie(messageClass, "has" + camelCaseName) : null;
+ hasMethodBuilder =
+ hasHasMethod ? getMethodOrDie(builderClass, "has" + camelCaseName) : null;
+ clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName);
+ caseMethod = isOneofField ? getMethodOrDie(
+ messageClass, "get" + containingOneofCamelCaseName + "Case") : null;
+ caseMethodBuilder = isOneofField ? getMethodOrDie(
+ builderClass, "get" + containingOneofCamelCaseName + "Case") : null;
+ }
+
+ // Note: We use Java reflection to call public methods rather than
+ // access private fields directly as this avoids runtime security
+ // checks.
+ protected final Class<?> type;
+ protected final Method getMethod;
+ protected final Method getMethodBuilder;
+ protected final Method setMethod;
+ protected final Method hasMethod;
+ protected final Method hasMethodBuilder;
+ protected final Method clearMethod;
+ protected final Method caseMethod;
+ protected final Method caseMethodBuilder;
+ protected final FieldDescriptor field;
+ protected final boolean isOneofField;
+ protected final boolean hasHasMethod;
+
+ private int getOneofFieldNumber(final GeneratedMessageV3 message) {
+ return ((Internal.EnumLite) invokeOrDie(caseMethod, message)).getNumber();
+ }
+
+ private int getOneofFieldNumber(final GeneratedMessageV3.Builder builder) {
+ return ((Internal.EnumLite) invokeOrDie(caseMethodBuilder, builder)).getNumber();
+ }
+
+ @Override
+ public Object get(final GeneratedMessageV3 message) {
+ return invokeOrDie(getMethod, message);
+ }
+ @Override
+ public Object get(GeneratedMessageV3.Builder builder) {
+ return invokeOrDie(getMethodBuilder, builder);
+ }
+ @Override
+ public Object getRaw(final GeneratedMessageV3 message) {
+ return get(message);
+ }
+ @Override
+ public Object getRaw(GeneratedMessageV3.Builder builder) {
+ return get(builder);
+ }
+ @Override
+ public void set(final Builder builder, final Object value) {
+ invokeOrDie(setMethod, builder, value);
+ }
+ @Override
+ public Object getRepeated(final GeneratedMessageV3 message, final int index) {
+ throw new UnsupportedOperationException(
+ "getRepeatedField() called on a singular field.");
+ }
+ @Override
+ public Object getRepeatedRaw(final GeneratedMessageV3 message, final int index) {
+ throw new UnsupportedOperationException(
+ "getRepeatedFieldRaw() called on a singular field.");
+ }
+ @Override
+ public Object getRepeated(GeneratedMessageV3.Builder builder, int index) {
+ throw new UnsupportedOperationException(
+ "getRepeatedField() called on a singular field.");
+ }
+ @Override
+ public Object getRepeatedRaw(GeneratedMessageV3.Builder builder, int index) {
+ throw new UnsupportedOperationException(
+ "getRepeatedFieldRaw() called on a singular field.");
+ }
+ @Override
+ public void setRepeated(final Builder builder, final int index, final Object value) {
+ throw new UnsupportedOperationException(
+ "setRepeatedField() called on a singular field.");
+ }
+ @Override
+ public void addRepeated(final Builder builder, final Object value) {
+ throw new UnsupportedOperationException(
+ "addRepeatedField() called on a singular field.");
+ }
+ @Override
+ public boolean has(final GeneratedMessageV3 message) {
+ if (!hasHasMethod) {
+ if (isOneofField) {
+ return getOneofFieldNumber(message) == field.getNumber();
+ }
+ return !get(message).equals(field.getDefaultValue());
+ }
+ return (Boolean) invokeOrDie(hasMethod, message);
+ }
+ @Override
+ public boolean has(GeneratedMessageV3.Builder builder) {
+ if (!hasHasMethod) {
+ if (isOneofField) {
+ return getOneofFieldNumber(builder) == field.getNumber();
+ }
+ return !get(builder).equals(field.getDefaultValue());
+ }
+ return (Boolean) invokeOrDie(hasMethodBuilder, builder);
+ }
+ @Override
+ public int getRepeatedCount(final GeneratedMessageV3 message) {
+ throw new UnsupportedOperationException(
+ "getRepeatedFieldSize() called on a singular field.");
+ }
+ @Override
+ public int getRepeatedCount(GeneratedMessageV3.Builder builder) {
+ throw new UnsupportedOperationException(
+ "getRepeatedFieldSize() called on a singular field.");
+ }
+ @Override
+ public void clear(final Builder builder) {
+ invokeOrDie(clearMethod, builder);
+ }
+ @Override
+ public Message.Builder newBuilder() {
+ throw new UnsupportedOperationException(
+ "newBuilderForField() called on a non-Message type.");
+ }
+ @Override
+ public Message.Builder getBuilder(GeneratedMessageV3.Builder builder) {
+ throw new UnsupportedOperationException(
+ "getFieldBuilder() called on a non-Message type.");
+ }
+ @Override
+ public Message.Builder getRepeatedBuilder(GeneratedMessageV3.Builder builder, int index) {
+ throw new UnsupportedOperationException(
+ "getRepeatedFieldBuilder() called on a non-Message type.");
+ }
+ }
+
+ private static class RepeatedFieldAccessor implements FieldAccessor {
+ protected final Class type;
+ protected final Method getMethod;
+ protected final Method getMethodBuilder;
+ protected final Method getRepeatedMethod;
+ protected final Method getRepeatedMethodBuilder;
+ protected final Method setRepeatedMethod;
+ protected final Method addRepeatedMethod;
+ protected final Method getCountMethod;
+ protected final Method getCountMethodBuilder;
+ protected final Method clearMethod;
+
+ RepeatedFieldAccessor(
+ final FieldDescriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessageV3> messageClass,
+ final Class<? extends Builder> builderClass) {
+ getMethod = getMethodOrDie(messageClass,
+ "get" + camelCaseName + "List");
+ getMethodBuilder = getMethodOrDie(builderClass,
+ "get" + camelCaseName + "List");
+ getRepeatedMethod =
+ getMethodOrDie(messageClass, "get" + camelCaseName, Integer.TYPE);
+ getRepeatedMethodBuilder =
+ getMethodOrDie(builderClass, "get" + camelCaseName, Integer.TYPE);
+ type = getRepeatedMethod.getReturnType();
+ setRepeatedMethod =
+ getMethodOrDie(builderClass, "set" + camelCaseName,
+ Integer.TYPE, type);
+ addRepeatedMethod =
+ getMethodOrDie(builderClass, "add" + camelCaseName, type);
+ getCountMethod =
+ getMethodOrDie(messageClass, "get" + camelCaseName + "Count");
+ getCountMethodBuilder =
+ getMethodOrDie(builderClass, "get" + camelCaseName + "Count");
+
+ clearMethod = getMethodOrDie(builderClass, "clear" + camelCaseName);
+ }
+
+ @Override
+ public Object get(final GeneratedMessageV3 message) {
+ return invokeOrDie(getMethod, message);
+ }
+ @Override
+ public Object get(GeneratedMessageV3.Builder builder) {
+ return invokeOrDie(getMethodBuilder, builder);
+ }
+ @Override
+ public Object getRaw(final GeneratedMessageV3 message) {
+ return get(message);
+ }
+ @Override
+ public Object getRaw(GeneratedMessageV3.Builder builder) {
+ return get(builder);
+ }
+ @Override
+ public void set(final Builder builder, final Object value) {
+ // Add all the elements individually. This serves two purposes:
+ // 1) Verifies that each element has the correct type.
+ // 2) Insures that the caller cannot modify the list later on and
+ // have the modifications be reflected in the message.
+ clear(builder);
+ for (final Object element : (List<?>) value) {
+ addRepeated(builder, element);
+ }
+ }
+ @Override
+ public Object getRepeated(final GeneratedMessageV3 message, final int index) {
+ return invokeOrDie(getRepeatedMethod, message, index);
+ }
+ @Override
+ public Object getRepeated(GeneratedMessageV3.Builder builder, int index) {
+ return invokeOrDie(getRepeatedMethodBuilder, builder, index);
+ }
+ @Override
+ public Object getRepeatedRaw(GeneratedMessageV3 message, int index) {
+ return getRepeated(message, index);
+ }
+ @Override
+ public Object getRepeatedRaw(GeneratedMessageV3.Builder builder, int index) {
+ return getRepeated(builder, index);
+ }
+ @Override
+ public void setRepeated(final Builder builder, final int index, final Object value) {
+ invokeOrDie(setRepeatedMethod, builder, index, value);
+ }
+ @Override
+ public void addRepeated(final Builder builder, final Object value) {
+ invokeOrDie(addRepeatedMethod, builder, value);
+ }
+ @Override
+ public boolean has(final GeneratedMessageV3 message) {
+ throw new UnsupportedOperationException(
+ "hasField() called on a repeated field.");
+ }
+ @Override
+ public boolean has(GeneratedMessageV3.Builder builder) {
+ throw new UnsupportedOperationException(
+ "hasField() called on a repeated field.");
+ }
+ @Override
+ public int getRepeatedCount(final GeneratedMessageV3 message) {
+ return (Integer) invokeOrDie(getCountMethod, message);
+ }
+ @Override
+ public int getRepeatedCount(GeneratedMessageV3.Builder builder) {
+ return (Integer) invokeOrDie(getCountMethodBuilder, builder);
+ }
+ @Override
+ public void clear(final Builder builder) {
+ invokeOrDie(clearMethod, builder);
+ }
+ @Override
+ public Message.Builder newBuilder() {
+ throw new UnsupportedOperationException(
+ "newBuilderForField() called on a non-Message type.");
+ }
+ @Override
+ public Message.Builder getBuilder(GeneratedMessageV3.Builder builder) {
+ throw new UnsupportedOperationException(
+ "getFieldBuilder() called on a non-Message type.");
+ }
+ @Override
+ public Message.Builder getRepeatedBuilder(GeneratedMessageV3.Builder builder, int index) {
+ throw new UnsupportedOperationException(
+ "getRepeatedFieldBuilder() called on a non-Message type.");
+ }
+ }
+
+ private static class MapFieldAccessor implements FieldAccessor {
+ MapFieldAccessor(
+ final FieldDescriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessageV3> messageClass,
+ final Class<? extends Builder> builderClass) {
+ field = descriptor;
+ Method getDefaultInstanceMethod =
+ getMethodOrDie(messageClass, "getDefaultInstance");
+ MapField defaultMapField = getMapField(
+ (GeneratedMessageV3) invokeOrDie(getDefaultInstanceMethod, null));
+ mapEntryMessageDefaultInstance =
+ defaultMapField.getMapEntryMessageDefaultInstance();
+ }
+
+ private final FieldDescriptor field;
+ private final Message mapEntryMessageDefaultInstance;
+
+ private MapField<?, ?> getMapField(GeneratedMessageV3 message) {
+ return (MapField<?, ?>) message.internalGetMapField(field.getNumber());
+ }
+
+ private MapField<?, ?> getMapField(GeneratedMessageV3.Builder builder) {
+ return (MapField<?, ?>) builder.internalGetMapField(field.getNumber());
+ }
+
+ private MapField<?, ?> getMutableMapField(
+ GeneratedMessageV3.Builder builder) {
+ return (MapField<?, ?>) builder.internalGetMutableMapField(
+ 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
+ @SuppressWarnings("unchecked")
+ public Object get(GeneratedMessageV3 message) {
+ List result = new ArrayList();
+ for (int i = 0; i < getRepeatedCount(message); i++) {
+ result.add(getRepeated(message, i));
+ }
+ return Collections.unmodifiableList(result);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object get(Builder builder) {
+ List result = new ArrayList();
+ for (int i = 0; i < getRepeatedCount(builder); i++) {
+ result.add(getRepeated(builder, i));
+ }
+ return Collections.unmodifiableList(result);
+ }
+
+ @Override
+ public Object getRaw(GeneratedMessageV3 message) {
+ return get(message);
+ }
+
+ @Override
+ public Object getRaw(GeneratedMessageV3.Builder builder) {
+ return get(builder);
+ }
+
+ @Override
+ public void set(Builder builder, Object value) {
+ clear(builder);
+ for (Object entry : (List) value) {
+ addRepeated(builder, entry);
+ }
+ }
+
+ @Override
+ public Object getRepeated(GeneratedMessageV3 message, int index) {
+ return getMapField(message).getList().get(index);
+ }
+
+ @Override
+ public Object getRepeated(Builder builder, int index) {
+ return getMapField(builder).getList().get(index);
+ }
+
+ @Override
+ public Object getRepeatedRaw(GeneratedMessageV3 message, int index) {
+ return getRepeated(message, index);
+ }
+
+ @Override
+ 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, coerceType((Message) value));
+ }
+
+ @Override
+ public void addRepeated(Builder builder, Object value) {
+ getMutableMapField(builder).getMutableList().add(coerceType((Message) value));
+ }
+
+ @Override
+ public boolean has(GeneratedMessageV3 message) {
+ throw new UnsupportedOperationException(
+ "hasField() is not supported for repeated fields.");
+ }
+
+ @Override
+ public boolean has(Builder builder) {
+ throw new UnsupportedOperationException(
+ "hasField() is not supported for repeated fields.");
+ }
+
+ @Override
+ public int getRepeatedCount(GeneratedMessageV3 message) {
+ return getMapField(message).getList().size();
+ }
+
+ @Override
+ public int getRepeatedCount(Builder builder) {
+ return getMapField(builder).getList().size();
+ }
+
+ @Override
+ public void clear(Builder builder) {
+ getMutableMapField(builder).getMutableList().clear();
+ }
+
+ @Override
+ public com.google.protobuf.Message.Builder newBuilder() {
+ return mapEntryMessageDefaultInstance.newBuilderForType();
+ }
+
+ @Override
+ public com.google.protobuf.Message.Builder getBuilder(Builder builder) {
+ throw new UnsupportedOperationException(
+ "Nested builder not supported for map fields.");
+ }
+
+ @Override
+ public com.google.protobuf.Message.Builder getRepeatedBuilder(Builder builder, int index) {
+ throw new UnsupportedOperationException(
+ "Nested builder not supported for map fields.");
+ }
+ }
+
+ // ---------------------------------------------------------------
+
+ private static final class SingularEnumFieldAccessor
+ extends SingularFieldAccessor {
+ SingularEnumFieldAccessor(
+ final FieldDescriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessageV3> messageClass,
+ final Class<? extends Builder> builderClass,
+ final String containingOneofCamelCaseName) {
+ super(descriptor, camelCaseName, messageClass, builderClass, containingOneofCamelCaseName);
+
+ enumDescriptor = descriptor.getEnumType();
+
+ valueOfMethod = getMethodOrDie(type, "valueOf",
+ EnumValueDescriptor.class);
+ getValueDescriptorMethod =
+ getMethodOrDie(type, "getValueDescriptor");
+
+ supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue();
+ if (supportUnknownEnumValue) {
+ getValueMethod =
+ getMethodOrDie(messageClass, "get" + camelCaseName + "Value");
+ getValueMethodBuilder =
+ getMethodOrDie(builderClass, "get" + camelCaseName + "Value");
+ setValueMethod =
+ getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class);
+ }
+ }
+
+ private EnumDescriptor enumDescriptor;
+
+ private Method valueOfMethod;
+ private Method getValueDescriptorMethod;
+
+ private boolean supportUnknownEnumValue;
+ private Method getValueMethod;
+ private Method getValueMethodBuilder;
+ private Method setValueMethod;
+
+ @Override
+ public Object get(final GeneratedMessageV3 message) {
+ if (supportUnknownEnumValue) {
+ int value = (Integer) invokeOrDie(getValueMethod, message);
+ return enumDescriptor.findValueByNumberCreatingIfUnknown(value);
+ }
+ return invokeOrDie(getValueDescriptorMethod, super.get(message));
+ }
+
+ @Override
+ public Object get(final GeneratedMessageV3.Builder builder) {
+ if (supportUnknownEnumValue) {
+ int value = (Integer) invokeOrDie(getValueMethodBuilder, builder);
+ return enumDescriptor.findValueByNumberCreatingIfUnknown(value);
+ }
+ return invokeOrDie(getValueDescriptorMethod, super.get(builder));
+ }
+
+ @Override
+ public void set(final Builder builder, final Object value) {
+ if (supportUnknownEnumValue) {
+ invokeOrDie(setValueMethod, builder,
+ ((EnumValueDescriptor) value).getNumber());
+ return;
+ }
+ super.set(builder, invokeOrDie(valueOfMethod, null, value));
+ }
+ }
+
+ private static final class RepeatedEnumFieldAccessor
+ extends RepeatedFieldAccessor {
+ RepeatedEnumFieldAccessor(
+ final FieldDescriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessageV3> messageClass,
+ final Class<? extends Builder> builderClass) {
+ super(descriptor, camelCaseName, messageClass, builderClass);
+
+ enumDescriptor = descriptor.getEnumType();
+
+ valueOfMethod = getMethodOrDie(type, "valueOf",
+ EnumValueDescriptor.class);
+ getValueDescriptorMethod =
+ getMethodOrDie(type, "getValueDescriptor");
+
+ supportUnknownEnumValue = descriptor.getFile().supportsUnknownEnumValue();
+ if (supportUnknownEnumValue) {
+ getRepeatedValueMethod =
+ getMethodOrDie(messageClass, "get" + camelCaseName + "Value", int.class);
+ getRepeatedValueMethodBuilder =
+ getMethodOrDie(builderClass, "get" + camelCaseName + "Value", int.class);
+ setRepeatedValueMethod =
+ getMethodOrDie(builderClass, "set" + camelCaseName + "Value", int.class, int.class);
+ addRepeatedValueMethod =
+ getMethodOrDie(builderClass, "add" + camelCaseName + "Value", int.class);
+ }
+ }
+ private EnumDescriptor enumDescriptor;
+
+ private final Method valueOfMethod;
+ private final Method getValueDescriptorMethod;
+
+ private boolean supportUnknownEnumValue;
+ private Method getRepeatedValueMethod;
+ private Method getRepeatedValueMethodBuilder;
+ private Method setRepeatedValueMethod;
+ private Method addRepeatedValueMethod;
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object get(final GeneratedMessageV3 message) {
+ final List newList = new ArrayList();
+ final int size = getRepeatedCount(message);
+ for (int i = 0; i < size; i++) {
+ newList.add(getRepeated(message, i));
+ }
+ return Collections.unmodifiableList(newList);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object get(final GeneratedMessageV3.Builder builder) {
+ final List newList = new ArrayList();
+ final int size = getRepeatedCount(builder);
+ for (int i = 0; i < size; i++) {
+ newList.add(getRepeated(builder, i));
+ }
+ return Collections.unmodifiableList(newList);
+ }
+
+ @Override
+ public Object getRepeated(final GeneratedMessageV3 message,
+ final int index) {
+ if (supportUnknownEnumValue) {
+ int value = (Integer) invokeOrDie(getRepeatedValueMethod, message, index);
+ return enumDescriptor.findValueByNumberCreatingIfUnknown(value);
+ }
+ return invokeOrDie(getValueDescriptorMethod,
+ super.getRepeated(message, index));
+ }
+ @Override
+ public Object getRepeated(final GeneratedMessageV3.Builder builder,
+ final int index) {
+ if (supportUnknownEnumValue) {
+ int value = (Integer) invokeOrDie(getRepeatedValueMethodBuilder, builder, index);
+ return enumDescriptor.findValueByNumberCreatingIfUnknown(value);
+ }
+ return invokeOrDie(getValueDescriptorMethod,
+ super.getRepeated(builder, index));
+ }
+ @Override
+ public void setRepeated(final Builder builder,
+ final int index, final Object value) {
+ if (supportUnknownEnumValue) {
+ invokeOrDie(setRepeatedValueMethod, builder, index,
+ ((EnumValueDescriptor) value).getNumber());
+ return;
+ }
+ super.setRepeated(builder, index, invokeOrDie(valueOfMethod, null,
+ value));
+ }
+ @Override
+ public void addRepeated(final Builder builder, final Object value) {
+ if (supportUnknownEnumValue) {
+ invokeOrDie(addRepeatedValueMethod, builder,
+ ((EnumValueDescriptor) value).getNumber());
+ return;
+ }
+ super.addRepeated(builder, invokeOrDie(valueOfMethod, null, value));
+ }
+ }
+
+ // ---------------------------------------------------------------
+
+ /**
+ * Field accessor for string fields.
+ *
+ * <p>This class makes getFooBytes() and setFooBytes() available for
+ * reflection API so that reflection based serialize/parse functions can
+ * access the raw bytes of the field to preserve non-UTF8 bytes in the
+ * string.
+ *
+ * <p>This ensures the serialize/parse round-trip safety, which is important
+ * for servers which forward messages.
+ */
+ private static final class SingularStringFieldAccessor
+ extends SingularFieldAccessor {
+ SingularStringFieldAccessor(
+ final FieldDescriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessageV3> messageClass,
+ final Class<? extends Builder> builderClass,
+ final String containingOneofCamelCaseName) {
+ super(descriptor, camelCaseName, messageClass, builderClass,
+ containingOneofCamelCaseName);
+ getBytesMethod = getMethodOrDie(messageClass,
+ "get" + camelCaseName + "Bytes");
+ getBytesMethodBuilder = getMethodOrDie(builderClass,
+ "get" + camelCaseName + "Bytes");
+ setBytesMethodBuilder = getMethodOrDie(builderClass,
+ "set" + camelCaseName + "Bytes", ByteString.class);
+ }
+
+ private final Method getBytesMethod;
+ private final Method getBytesMethodBuilder;
+ private final Method setBytesMethodBuilder;
+
+ @Override
+ public Object getRaw(final GeneratedMessageV3 message) {
+ return invokeOrDie(getBytesMethod, message);
+ }
+
+ @Override
+ public Object getRaw(GeneratedMessageV3.Builder builder) {
+ return invokeOrDie(getBytesMethodBuilder, builder);
+ }
+
+ @Override
+ public void set(GeneratedMessageV3.Builder builder, Object value) {
+ if (value instanceof ByteString) {
+ invokeOrDie(setBytesMethodBuilder, builder, value);
+ } else {
+ super.set(builder, value);
+ }
+ }
+ }
+
+ // ---------------------------------------------------------------
+
+ private static final class SingularMessageFieldAccessor
+ extends SingularFieldAccessor {
+ SingularMessageFieldAccessor(
+ final FieldDescriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessageV3> messageClass,
+ final Class<? extends Builder> builderClass,
+ final String containingOneofCamelCaseName) {
+ super(descriptor, camelCaseName, messageClass, builderClass,
+ containingOneofCamelCaseName);
+
+ newBuilderMethod = getMethodOrDie(type, "newBuilder");
+ getBuilderMethodBuilder =
+ getMethodOrDie(builderClass, "get" + camelCaseName + "Builder");
+ }
+
+ private final Method newBuilderMethod;
+ private final Method getBuilderMethodBuilder;
+
+ private Object coerceType(final Object value) {
+ if (type.isInstance(value)) {
+ return value;
+ } else {
+ // 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 ((Message.Builder) invokeOrDie(newBuilderMethod, null))
+ .mergeFrom((Message) value).buildPartial();
+ }
+ }
+
+ @Override
+ public void set(final Builder builder, final Object value) {
+ super.set(builder, coerceType(value));
+ }
+ @Override
+ public Message.Builder newBuilder() {
+ return (Message.Builder) invokeOrDie(newBuilderMethod, null);
+ }
+ @Override
+ public Message.Builder getBuilder(GeneratedMessageV3.Builder builder) {
+ return (Message.Builder) invokeOrDie(getBuilderMethodBuilder, builder);
+ }
+ }
+
+ private static final class RepeatedMessageFieldAccessor
+ extends RepeatedFieldAccessor {
+ RepeatedMessageFieldAccessor(
+ final FieldDescriptor descriptor, final String camelCaseName,
+ final Class<? extends GeneratedMessageV3> messageClass,
+ final Class<? extends Builder> builderClass) {
+ super(descriptor, camelCaseName, messageClass, builderClass);
+
+ newBuilderMethod = getMethodOrDie(type, "newBuilder");
+ getBuilderMethodBuilder = getMethodOrDie(builderClass,
+ "get" + camelCaseName + "Builder", Integer.TYPE);
+ }
+
+ private final Method newBuilderMethod;
+ private final Method getBuilderMethodBuilder;
+
+ private Object coerceType(final Object value) {
+ if (type.isInstance(value)) {
+ return value;
+ } else {
+ // 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 ((Message.Builder) invokeOrDie(newBuilderMethod, null))
+ .mergeFrom((Message) value).build();
+ }
+ }
+
+ @Override
+ public void setRepeated(final Builder builder,
+ final int index, final Object value) {
+ super.setRepeated(builder, index, coerceType(value));
+ }
+ @Override
+ public void addRepeated(final Builder builder, final Object value) {
+ super.addRepeated(builder, coerceType(value));
+ }
+ @Override
+ public Message.Builder newBuilder() {
+ return (Message.Builder) invokeOrDie(newBuilderMethod, null);
+ }
+ @Override
+ public Message.Builder getRepeatedBuilder(
+ final GeneratedMessageV3.Builder builder, final int index) {
+ return (Message.Builder) invokeOrDie(
+ getBuilderMethodBuilder, builder, index);
+ }
+ }
+ }
+
+ /**
+ * Replaces this object in the output stream with a serialized form.
+ * Part of Java's serialization magic. Generated sub-classes must override
+ * this method by calling {@code return super.writeReplace();}
+ * @return a SerializedForm of this message
+ */
+ protected Object writeReplace() throws ObjectStreamException {
+ return new GeneratedMessageLite.SerializedForm(this);
+ }
+
+ /**
+ * Checks that the {@link Extension} is non-Lite and returns it as a
+ * {@link GeneratedExtension}.
+ */
+ private static <MessageType extends ExtendableMessage<MessageType>, T>
+ Extension<MessageType, T> checkNotLite(
+ ExtensionLite<MessageType, T> extension) {
+ if (extension.isLite()) {
+ throw new IllegalArgumentException("Expected non-lite extension.");
+ }
+
+ return (Extension<MessageType, T>) extension;
+ }
+
+ protected static int computeStringSize(final int fieldNumber, final Object value) {
+ if (value instanceof String) {
+ return CodedOutputStream.computeStringSize(fieldNumber, (String) value);
+ } else {
+ return CodedOutputStream.computeBytesSize(fieldNumber, (ByteString) value);
+ }
+ }
+
+ protected static int computeStringSizeNoTag(final Object value) {
+ if (value instanceof String) {
+ return CodedOutputStream.computeStringSizeNoTag((String) value);
+ } else {
+ return CodedOutputStream.computeBytesSizeNoTag((ByteString) value);
+ }
+ }
+
+ protected static void writeString(
+ CodedOutputStream output, final int fieldNumber, final Object value) throws IOException {
+ if (value instanceof String) {
+ output.writeString(fieldNumber, (String) value);
+ } else {
+ output.writeBytes(fieldNumber, (ByteString) value);
+ }
+ }
+
+ protected static void writeStringNoTag(
+ CodedOutputStream output, final Object value) throws IOException {
+ if (value instanceof String) {
+ output.writeStringNoTag((String) value);
+ } else {
+ output.writeBytesNoTag((ByteString) value);
+ }
+ }
+
+ protected static <V> void serializeIntegerMapTo(
+ CodedOutputStream out,
+ MapField<Integer, V> field,
+ MapEntry<Integer, V> defaultEntry,
+ int fieldNumber) throws IOException {
+ Map<Integer, V> 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 <V> void serializeLongMapTo(
+ CodedOutputStream out,
+ MapField<Long, V> field,
+ MapEntry<Long, V> defaultEntry,
+ int fieldNumber)
+ throws IOException {
+ Map<Long, V> 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 <V> void serializeStringMapTo(
+ CodedOutputStream out,
+ MapField<String, V> field,
+ MapEntry<String, V> defaultEntry,
+ int fieldNumber)
+ throws IOException {
+ Map<String, V> 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 <V> void serializeBooleanMapTo(
+ CodedOutputStream out,
+ MapField<Boolean, V> field,
+ MapEntry<Boolean, V> defaultEntry,
+ int fieldNumber)
+ throws IOException {
+ Map<Boolean, V> 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 <V> void maybeSerializeBooleanEntryTo(
+ CodedOutputStream out,
+ Map<Boolean, V> m,
+ MapEntry<Boolean, V> 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 <K, V> void serializeMapTo(
+ CodedOutputStream out,
+ Map<K, V> m,
+ MapEntry<K, V> defaultEntry,
+ int fieldNumber)
+ throws IOException {
+ for (Map.Entry<K, V> entry : m.entrySet()) {
+ out.writeMessage(fieldNumber,
+ defaultEntry.newBuilderForType()
+ .setKey(entry.getKey())
+ .setValue(entry.getValue())
+ .build());
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/IntArrayList.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/IntArrayList.java
new file mode 100644
index 0000000000..2f526e3fd8
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/IntArrayList.java
@@ -0,0 +1,272 @@
+// 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.IntList;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.RandomAccess;
+
+/**
+ * An implementation of {@link IntList} on top of a primitive array.
+ *
+ * @author dweis@google.com (Daniel Weis)
+ */
+final class IntArrayList
+ extends AbstractProtobufList<Integer>
+ implements IntList, RandomAccess {
+
+ private static final IntArrayList EMPTY_LIST = new IntArrayList();
+ static {
+ EMPTY_LIST.makeImmutable();
+ }
+
+ public static IntArrayList emptyList() {
+ return EMPTY_LIST;
+ }
+
+ /**
+ * The backing store for the list.
+ */
+ private int[] array;
+
+ /**
+ * The size of the list distinct from the length of the array. That is, it is the number of
+ * elements set in the list.
+ */
+ private int size;
+
+ /**
+ * Constructs a new mutable {@code IntArrayList} with default capacity.
+ */
+ IntArrayList() {
+ this(new int[DEFAULT_CAPACITY], 0);
+ }
+
+ /**
+ * Constructs a new mutable {@code IntArrayList}
+ * containing the same elements as {@code other}.
+ */
+ private IntArrayList(int[] other, int size) {
+ array = other;
+ this.size = size;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof IntArrayList)) {
+ return super.equals(o);
+ }
+ IntArrayList other = (IntArrayList) o;
+ if (size != other.size) {
+ return false;
+ }
+
+ final int[] arr = other.array;
+ for (int i = 0; i < size; i++) {
+ if (array[i] != arr[i]) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 1;
+ for (int i = 0; i < size; i++) {
+ result = (31 * result) + array[i];
+ }
+ return result;
+ }
+
+ @Override
+ public IntList mutableCopyWithCapacity(int capacity) {
+ if (capacity < size) {
+ throw new IllegalArgumentException();
+ }
+ return new IntArrayList(Arrays.copyOf(array, capacity), size);
+ }
+
+ @Override
+ public Integer get(int index) {
+ return getInt(index);
+ }
+
+ @Override
+ public int getInt(int index) {
+ ensureIndexInRange(index);
+ return array[index];
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public Integer set(int index, Integer element) {
+ return setInt(index, element);
+ }
+
+ @Override
+ public int setInt(int index, int element) {
+ ensureIsMutable();
+ ensureIndexInRange(index);
+ int previousValue = array[index];
+ array[index] = element;
+ return previousValue;
+ }
+
+ @Override
+ public void add(int index, Integer element) {
+ addInt(index, element);
+ }
+
+ /**
+ * Like {@link #add(Integer)} but more efficient in that it doesn't box the element.
+ */
+ @Override
+ public void addInt(int element) {
+ addInt(size, element);
+ }
+
+ /**
+ * Like {@link #add(int, Integer)} but more efficient in that it doesn't box the element.
+ */
+ private void addInt(int index, int element) {
+ ensureIsMutable();
+ if (index < 0 || index > size) {
+ throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index));
+ }
+
+ if (size < array.length) {
+ // Shift everything over to make room
+ System.arraycopy(array, index, array, index + 1, size - index);
+ } else {
+ // Resize to 1.5x the size
+ int length = ((size * 3) / 2) + 1;
+ int[] newArray = new int[length];
+
+ // Copy the first part directly
+ System.arraycopy(array, 0, newArray, 0, index);
+
+ // Copy the rest shifted over by one to make room
+ System.arraycopy(array, index, newArray, index + 1, size - index);
+ array = newArray;
+ }
+
+ array[index] = element;
+ size++;
+ modCount++;
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends Integer> collection) {
+ ensureIsMutable();
+
+ if (collection == null) {
+ throw new NullPointerException();
+ }
+
+ // We specialize when adding another IntArrayList to avoid boxing elements.
+ if (!(collection instanceof IntArrayList)) {
+ return super.addAll(collection);
+ }
+
+ IntArrayList list = (IntArrayList) collection;
+ if (list.size == 0) {
+ return false;
+ }
+
+ int overflow = Integer.MAX_VALUE - size;
+ if (overflow < list.size) {
+ // We can't actually represent a list this large.
+ throw new OutOfMemoryError();
+ }
+
+ int newSize = size + list.size;
+ if (newSize > array.length) {
+ array = Arrays.copyOf(array, newSize);
+ }
+
+ System.arraycopy(list.array, 0, array, size, list.size);
+ size = newSize;
+ modCount++;
+ return true;
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ ensureIsMutable();
+ for (int i = 0; i < size; i++) {
+ if (o.equals(array[i])) {
+ System.arraycopy(array, i + 1, array, i, size - i);
+ size--;
+ modCount++;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public Integer remove(int index) {
+ ensureIsMutable();
+ ensureIndexInRange(index);
+ int value = array[index];
+ System.arraycopy(array, index + 1, array, index, size - index);
+ size--;
+ modCount++;
+ return value;
+ }
+
+ /**
+ * Ensures that the provided {@code index} is within the range of {@code [0, size]}. Throws an
+ * {@link IndexOutOfBoundsException} if it is not.
+ *
+ * @param index the index to verify is in range
+ */
+ private void ensureIndexInRange(int index) {
+ if (index < 0 || index >= size) {
+ throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index));
+ }
+ }
+
+ private String makeOutOfBoundsExceptionMessage(int index) {
+ return "Index:" + index + ", Size:" + size;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Internal.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Internal.java
new file mode 100644
index 0000000000..c234559ce3
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Internal.java
@@ -0,0 +1,751 @@
+// 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.IOException;
+import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.util.AbstractList;
+import java.util.AbstractMap;
+import java.util.AbstractSet;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.RandomAccess;
+import java.util.Set;
+
+/**
+ * The classes contained within are used internally by the Protocol Buffer
+ * library and generated message implementations. They are public only because
+ * those generated messages do not reside in the {@code protobuf} package.
+ * Others should not use this class directly.
+ *
+ * @author kenton@google.com (Kenton Varda)
+ */
+public final class Internal {
+
+ private 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> 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.
+ * <p>
+ * The protocol compiler does not actually contain a UTF-8 decoder -- it
+ * just pushes UTF-8-encoded text around without touching it. The one place
+ * where this presents a problem is when generating Java string literals.
+ * Unicode characters in the string literal would normally need to be encoded
+ * using a Unicode escape sequence, which would require decoding them.
+ * To get around this, protoc instead embeds the UTF-8 bytes into the
+ * generated code and leaves it to the runtime library to decode them.
+ * <p>
+ * It gets worse, though. If protoc just generated a byte array, like:
+ * new byte[] {0x12, 0x34, 0x56, 0x78}
+ * Java actually generates *code* which allocates an array and then fills
+ * in each value. This is much less efficient than just embedding the bytes
+ * directly into the bytecode. To get around this, we need another
+ * work-around. String literals are embedded directly, so protoc actually
+ * generates a string literal corresponding to the bytes. The easiest way
+ * to do this is to use the ISO-8859-1 character set, which corresponds to
+ * the first 256 characters of the Unicode range. Protoc can then use
+ * good old CEscape to generate the string.
+ * <p>
+ * So we have a string literal which represents a set of bytes which
+ * represents another string. This function -- stringDefaultValue --
+ * converts from the generated string to the string we actually want. The
+ * generated code calls this automatically.
+ */
+ public static String stringDefaultValue(String bytes) {
+ return new String(bytes.getBytes(ISO_8859_1), UTF_8);
+ }
+
+ /**
+ * Helper called by generated code to construct default values for bytes
+ * fields.
+ * <p>
+ * This is a lot like {@link #stringDefaultValue}, but for bytes fields.
+ * In this case we only need the second of the two hacks -- allowing us to
+ * embed raw bytes as a string literal with ISO-8859-1 encoding.
+ */
+ public static ByteString bytesDefaultValue(String bytes) {
+ return ByteString.copyFrom(bytes.getBytes(ISO_8859_1));
+ }
+ /**
+ * Helper called by generated code to construct default values for bytes
+ * fields.
+ * <p>
+ * This is like {@link #bytesDefaultValue}, but returns a byte array.
+ */
+ public static byte[] byteArrayDefaultValue(String bytes) {
+ return bytes.getBytes(ISO_8859_1);
+ }
+
+ /**
+ * Helper called by generated code to construct default values for bytes
+ * fields.
+ * <p>
+ * This is like {@link #bytesDefaultValue}, but returns a ByteBuffer.
+ */
+ public static ByteBuffer byteBufferDefaultValue(String bytes) {
+ return ByteBuffer.wrap(byteArrayDefaultValue(bytes));
+ }
+
+ /**
+ * Create a new ByteBuffer and copy all the content of {@code source}
+ * ByteBuffer to the new ByteBuffer. The new ByteBuffer's limit and
+ * capacity will be source.capacity(), and its position will be 0.
+ * Note that the state of {@code source} ByteBuffer won't be changed.
+ */
+ public static ByteBuffer copyByteBuffer(ByteBuffer source) {
+ // Make a duplicate of the source ByteBuffer and read data from the
+ // duplicate. This is to avoid affecting the source ByteBuffer's state.
+ ByteBuffer temp = source.duplicate();
+ // We want to copy all the data in the source ByteBuffer, not just the
+ // remaining bytes.
+ temp.clear();
+ ByteBuffer result = ByteBuffer.allocate(temp.capacity());
+ result.put(temp);
+ result.clear();
+ return result;
+ }
+
+ /**
+ * Helper called by generated code to determine if a byte array is a valid
+ * UTF-8 encoded string such that the original bytes can be converted to
+ * a String object and then back to a byte array round tripping the bytes
+ * without loss. More precisely, returns {@code true} whenever:
+ * <pre> {@code
+ * Arrays.equals(byteString.toByteArray(),
+ * new String(byteString.toByteArray(), "UTF-8").getBytes("UTF-8"))
+ * }</pre>
+ *
+ * <p>This method rejects "overlong" byte sequences, as well as
+ * 3-byte sequences that would map to a surrogate character, in
+ * accordance with the restricted definition of UTF-8 introduced in
+ * Unicode 3.1. Note that the UTF-8 decoder included in Oracle's
+ * JDK has been modified to also reject "overlong" byte sequences,
+ * but currently (2011) still accepts 3-byte surrogate character
+ * byte sequences.
+ *
+ * <p>See the Unicode Standard,<br>
+ * Table 3-6. <em>UTF-8 Bit Distribution</em>,<br>
+ * Table 3-7. <em>Well Formed UTF-8 Byte Sequences</em>.
+ *
+ * <p>As of 2011-02, this method simply returns the result of {@link
+ * ByteString#isValidUtf8()}. Calling that method directly is preferred.
+ *
+ * @param byteString the string to check
+ * @return whether the byte array is round trippable
+ */
+ public static boolean isValidUtf8(ByteString byteString) {
+ return byteString.isValidUtf8();
+ }
+
+ /**
+ * Like {@link #isValidUtf8(ByteString)} but for byte arrays.
+ */
+ public static boolean isValidUtf8(byte[] byteArray) {
+ return Utf8.isValidUtf8(byteArray);
+ }
+
+ /**
+ * Helper method to get the UTF-8 bytes of a string.
+ */
+ public static byte[] toByteArray(String value) {
+ return value.getBytes(UTF_8);
+ }
+
+ /**
+ * Helper method to convert a byte array to a string using UTF-8 encoding.
+ */
+ public static String toStringUtf8(byte[] bytes) {
+ return new String(bytes, UTF_8);
+ }
+
+ /**
+ * Interface for an enum value or value descriptor, to be used in FieldSet.
+ * The lite library stores enum values directly in FieldSets but the full
+ * library stores EnumValueDescriptors in order to better support reflection.
+ */
+ public interface EnumLite {
+ int getNumber();
+ }
+
+ /**
+ * Interface for an object which maps integers to {@link EnumLite}s.
+ * {@link Descriptors.EnumDescriptor} implements this interface by mapping
+ * numbers to {@link Descriptors.EnumValueDescriptor}s. Additionally,
+ * every generated enum type has a static method internalGetValueMap() which
+ * returns an implementation of this type that maps numbers to enum values.
+ */
+ public interface EnumLiteMap<T extends EnumLite> {
+ T findValueByNumber(int number);
+ }
+
+ /**
+ * Helper method for implementing {@link Message#hashCode()} for longs.
+ * @see Long#hashCode()
+ */
+ public static int hashLong(long n) {
+ return (int) (n ^ (n >>> 32));
+ }
+
+ /**
+ * Helper method for implementing {@link Message#hashCode()} for
+ * booleans.
+ * @see Boolean#hashCode()
+ */
+ public static int hashBoolean(boolean b) {
+ return b ? 1231 : 1237;
+ }
+
+ /**
+ * Helper method for implementing {@link Message#hashCode()} for enums.
+ * <p>
+ * This is needed because {@link java.lang.Enum#hashCode()} is final, but we
+ * need to use the field number as the hash code to ensure compatibility
+ * between statically and dynamically generated enum objects.
+ */
+ public static int hashEnum(EnumLite e) {
+ return e.getNumber();
+ }
+
+ /**
+ * Helper method for implementing {@link Message#hashCode()} for
+ * enum lists.
+ */
+ public static int hashEnumList(List<? extends EnumLite> list) {
+ int hash = 1;
+ for (EnumLite e : list) {
+ hash = 31 * hash + hashEnum(e);
+ }
+ return hash;
+ }
+
+ /**
+ * Helper method for implementing {@link Message#equals(Object)} for bytes field.
+ */
+ public static boolean equals(List<byte[]> a, List<byte[]> b) {
+ if (a.size() != b.size()) return false;
+ for (int i = 0; i < a.size(); ++i) {
+ if (!Arrays.equals(a.get(i), b.get(i))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Helper method for implementing {@link Message#hashCode()} for bytes field.
+ */
+ public static int hashCode(List<byte[]> list) {
+ int hash = 1;
+ for (byte[] bytes : list) {
+ hash = 31 * hash + hashCode(bytes);
+ }
+ return hash;
+ }
+
+ /**
+ * Helper method for implementing {@link Message#hashCode()} for bytes field.
+ */
+ public static int hashCode(byte[] bytes) {
+ // The hash code for a byte array should be the same as the hash code for a
+ // ByteString with the same content. This is to ensure that the generated
+ // hashCode() method will return the same value as the pure reflection
+ // based hashCode() method.
+ return Internal.hashCode(bytes, 0, bytes.length);
+ }
+
+ /**
+ * Helper method for implementing {@link LiteralByteString#hashCode()}.
+ */
+ static int hashCode(byte[] bytes, int offset, int length) {
+ // The hash code for a byte array should be the same as the hash code for a
+ // ByteString with the same content. This is to ensure that the generated
+ // hashCode() method will return the same value as the pure reflection
+ // based hashCode() method.
+ int h = Internal.partialHash(length, bytes, offset, length);
+ return h == 0 ? 1 : h;
+ }
+
+ /**
+ * Helper method for continuously hashing bytes.
+ */
+ static int partialHash(int h, byte[] bytes, int offset, int length) {
+ for (int i = offset; i < offset + length; i++) {
+ h = h * 31 + bytes[i];
+ }
+ return h;
+ }
+
+ /**
+ * Helper method for implementing {@link Message#equals(Object)} for bytes
+ * field.
+ */
+ public static boolean equalsByteBuffer(ByteBuffer a, ByteBuffer b) {
+ if (a.capacity() != b.capacity()) {
+ return false;
+ }
+ // ByteBuffer.equals() will only compare the remaining bytes, but we want to
+ // compare all the content.
+ return a.duplicate().clear().equals(b.duplicate().clear());
+ }
+
+ /**
+ * Helper method for implementing {@link Message#equals(Object)} for bytes
+ * field.
+ */
+ public static boolean equalsByteBuffer(
+ List<ByteBuffer> a, List<ByteBuffer> b) {
+ if (a.size() != b.size()) {
+ return false;
+ }
+ for (int i = 0; i < a.size(); ++i) {
+ if (!equalsByteBuffer(a.get(i), b.get(i))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Helper method for implementing {@link Message#hashCode()} for bytes
+ * field.
+ */
+ public static int hashCodeByteBuffer(List<ByteBuffer> list) {
+ int hash = 1;
+ for (ByteBuffer bytes : list) {
+ hash = 31 * hash + hashCodeByteBuffer(bytes);
+ }
+ return hash;
+ }
+
+ private static final int DEFAULT_BUFFER_SIZE = 4096;
+
+ /**
+ * Helper method for implementing {@link Message#hashCode()} for bytes
+ * field.
+ */
+ public static int hashCodeByteBuffer(ByteBuffer bytes) {
+ if (bytes.hasArray()) {
+ // Fast path.
+ int h = partialHash(bytes.capacity(), bytes.array(), bytes.arrayOffset(), bytes.capacity());
+ return h == 0 ? 1 : h;
+ } else {
+ // Read the data into a temporary byte array before calculating the
+ // hash value.
+ final int bufferSize = bytes.capacity() > DEFAULT_BUFFER_SIZE
+ ? DEFAULT_BUFFER_SIZE : bytes.capacity();
+ final byte[] buffer = new byte[bufferSize];
+ final ByteBuffer duplicated = bytes.duplicate();
+ duplicated.clear();
+ int h = bytes.capacity();
+ while (duplicated.remaining() > 0) {
+ final int length = duplicated.remaining() <= bufferSize ?
+ duplicated.remaining() : bufferSize;
+ duplicated.get(buffer, 0, length);
+ h = partialHash(h, buffer, 0, length);
+ }
+ return h == 0 ? 1 : h;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T extends MessageLite> T getDefaultInstance(Class<T> clazz) {
+ try {
+ Method method = clazz.getMethod("getDefaultInstance");
+ return (T) method.invoke(method);
+ } catch (Exception e) {
+ throw new RuntimeException(
+ "Failed to get default instance for " + clazz, e);
+ }
+ }
+
+ /**
+ * An empty byte array constant used in generated code.
+ */
+ public static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
+
+ /**
+ * An empty byte array constant used in generated code.
+ */
+ public static final ByteBuffer EMPTY_BYTE_BUFFER =
+ ByteBuffer.wrap(EMPTY_BYTE_ARRAY);
+
+ /** An empty coded input stream constant used in generated code. */
+ public static final CodedInputStream EMPTY_CODED_INPUT_STREAM =
+ CodedInputStream.newInstance(EMPTY_BYTE_ARRAY);
+
+
+ /**
+ * Provides an immutable view of {@code List<T>} around a {@code List<F>}.
+ *
+ * Protobuf internal. Used in protobuf generated code only.
+ */
+ public static class ListAdapter<F, T> extends AbstractList<T> {
+ /**
+ * Convert individual elements of the List from F to T.
+ */
+ public interface Converter<F, T> {
+ T convert(F from);
+ }
+
+ private final List<F> fromList;
+ private final Converter<F, T> converter;
+
+ public ListAdapter(List<F> fromList, Converter<F, T> converter) {
+ this.fromList = fromList;
+ this.converter = converter;
+ }
+
+ @Override
+ public T get(int index) {
+ return converter.convert(fromList.get(index));
+ }
+
+ @Override
+ public int size() {
+ return fromList.size();
+ }
+ }
+
+ /**
+ * Wrap around a {@code Map<K, RealValue>} and provide a {@code Map<K, V>}
+ * interface.
+ */
+ public static class MapAdapter<K, V, RealValue> extends AbstractMap<K, V> {
+ /**
+ * An interface used to convert between two types.
+ */
+ public interface Converter<A, B> {
+ B doForward(A object);
+ A doBackward(B object);
+ }
+
+ public static <T extends EnumLite> Converter<Integer, T> newEnumConverter(
+ final EnumLiteMap<T> enumMap, final T unrecognizedValue) {
+ return new Converter<Integer, T>() {
+ @Override
+ public T doForward(Integer value) {
+ T result = enumMap.findValueByNumber(value);
+ return result == null ? unrecognizedValue : result;
+ }
+
+ @Override
+ public Integer doBackward(T value) {
+ return value.getNumber();
+ }
+ };
+ }
+
+ private final Map<K, RealValue> realMap;
+ private final Converter<RealValue, V> valueConverter;
+
+ public MapAdapter(Map<K, RealValue> realMap,
+ Converter<RealValue, V> valueConverter) {
+ this.realMap = realMap;
+ this.valueConverter = valueConverter;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public V get(Object key) {
+ RealValue result = realMap.get(key);
+ if (result == null) {
+ return null;
+ }
+ return valueConverter.doForward(result);
+ }
+
+ @Override
+ public V put(K key, V value) {
+ RealValue oldValue = realMap.put(key, valueConverter.doBackward(value));
+ if (oldValue == null) {
+ return null;
+ }
+ return valueConverter.doForward(oldValue);
+ }
+
+ @Override
+ public Set<java.util.Map.Entry<K, V>> entrySet() {
+ return new SetAdapter(realMap.entrySet());
+ }
+
+ private class SetAdapter extends AbstractSet<Map.Entry<K, V>> {
+ private final Set<Map.Entry<K, RealValue>> realSet;
+ public SetAdapter(Set<Map.Entry<K, RealValue>> realSet) {
+ this.realSet = realSet;
+ }
+
+ @Override
+ public Iterator<java.util.Map.Entry<K, V>> iterator() {
+ return new IteratorAdapter(realSet.iterator());
+ }
+
+ @Override
+ public int size() {
+ return realSet.size();
+ }
+ }
+
+ private class IteratorAdapter implements Iterator<Map.Entry<K, V>> {
+ private final Iterator<Map.Entry<K, RealValue>> realIterator;
+
+ public IteratorAdapter(
+ Iterator<Map.Entry<K, RealValue>> realIterator) {
+ this.realIterator = realIterator;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return realIterator.hasNext();
+ }
+
+ @Override
+ public java.util.Map.Entry<K, V> next() {
+ return new EntryAdapter(realIterator.next());
+ }
+
+ @Override
+ public void remove() {
+ realIterator.remove();
+ }
+ }
+
+ private class EntryAdapter implements Map.Entry<K, V> {
+ private final Map.Entry<K, RealValue> realEntry;
+
+ public EntryAdapter(Map.Entry<K, RealValue> realEntry) {
+ this.realEntry = realEntry;
+ }
+
+ @Override
+ public K getKey() {
+ return realEntry.getKey();
+ }
+
+ @Override
+ public V getValue() {
+ return valueConverter.doForward(realEntry.getValue());
+ }
+
+ @Override
+ public V setValue(V value) {
+ RealValue oldValue = realEntry.setValue(
+ valueConverter.doBackward(value));
+ if (oldValue == null) {
+ return null;
+ }
+ return valueConverter.doForward(oldValue);
+ }
+ }
+ }
+
+ /**
+ * Extends {@link List} to add the capability to make the list immutable and inspect if it is
+ * modifiable.
+ * <p>
+ * All implementations must support efficient random access.
+ */
+ public static interface ProtobufList<E> extends List<E>, RandomAccess {
+
+ /**
+ * Makes this list immutable. All subsequent modifications will throw an
+ * {@link UnsupportedOperationException}.
+ */
+ void makeImmutable();
+
+ /**
+ * Returns whether this list can be modified via the publicly accessible {@link List} methods.
+ */
+ boolean isModifiable();
+
+ /**
+ * Returns a mutable clone of this list with the specified capacity.
+ */
+ ProtobufList<E> mutableCopyWithCapacity(int capacity);
+ }
+
+ /**
+ * A {@link java.util.List} implementation that avoids boxing the elements into Integers if
+ * possible. Does not support null elements.
+ */
+ public static interface IntList extends ProtobufList<Integer> {
+
+ /**
+ * Like {@link #get(int)} but more efficient in that it doesn't box the returned value.
+ */
+ int getInt(int index);
+
+ /**
+ * Like {@link #add(Object)} but more efficient in that it doesn't box the element.
+ */
+ void addInt(int element);
+
+ /**
+ * Like {@link #set(int, Object)} but more efficient in that it doesn't box the element.
+ */
+ int setInt(int index, int element);
+
+ /**
+ * Returns a mutable clone of this list with the specified capacity.
+ */
+ @Override
+ IntList mutableCopyWithCapacity(int capacity);
+ }
+
+ /**
+ * A {@link java.util.List} implementation that avoids boxing the elements into Booleans if
+ * possible. Does not support null elements.
+ */
+ public static interface BooleanList extends ProtobufList<Boolean> {
+
+ /**
+ * Like {@link #get(int)} but more efficient in that it doesn't box the returned value.
+ */
+ boolean getBoolean(int index);
+
+ /**
+ * Like {@link #add(Object)} but more efficient in that it doesn't box the element.
+ */
+ void addBoolean(boolean element);
+
+ /**
+ * Like {@link #set(int, Object)} but more efficient in that it doesn't box the element.
+ */
+ boolean setBoolean(int index, boolean element);
+
+ /**
+ * Returns a mutable clone of this list with the specified capacity.
+ */
+ @Override
+ BooleanList mutableCopyWithCapacity(int capacity);
+ }
+
+ /**
+ * A {@link java.util.List} implementation that avoids boxing the elements into Longs if
+ * possible. Does not support null elements.
+ */
+ public static interface LongList extends ProtobufList<Long> {
+
+ /**
+ * Like {@link #get(int)} but more efficient in that it doesn't box the returned value.
+ */
+ long getLong(int index);
+
+ /**
+ * Like {@link #add(Object)} but more efficient in that it doesn't box the element.
+ */
+ void addLong(long element);
+
+ /**
+ * Like {@link #set(int, Object)} but more efficient in that it doesn't box the element.
+ */
+ long setLong(int index, long element);
+
+ /**
+ * Returns a mutable clone of this list with the specified capacity.
+ */
+ @Override
+ LongList mutableCopyWithCapacity(int capacity);
+ }
+
+ /**
+ * A {@link java.util.List} implementation that avoids boxing the elements into Doubles if
+ * possible. Does not support null elements.
+ */
+ public static interface DoubleList extends ProtobufList<Double> {
+
+ /**
+ * Like {@link #get(int)} but more efficient in that it doesn't box the returned value.
+ */
+ double getDouble(int index);
+
+ /**
+ * Like {@link #add(Object)} but more efficient in that it doesn't box the element.
+ */
+ void addDouble(double element);
+
+ /**
+ * Like {@link #set(int, Object)} but more efficient in that it doesn't box the element.
+ */
+ double setDouble(int index, double element);
+
+ /**
+ * Returns a mutable clone of this list with the specified capacity.
+ */
+ @Override
+ DoubleList mutableCopyWithCapacity(int capacity);
+ }
+
+ /**
+ * A {@link java.util.List} implementation that avoids boxing the elements into Floats if
+ * possible. Does not support null elements.
+ */
+ public static interface FloatList extends ProtobufList<Float> {
+
+ /**
+ * Like {@link #get(int)} but more efficient in that it doesn't box the returned value.
+ */
+ float getFloat(int index);
+
+ /**
+ * Like {@link #add(Object)} but more efficient in that it doesn't box the element.
+ */
+ void addFloat(float element);
+
+ /**
+ * Like {@link #set(int, Object)} but more efficient in that it doesn't box the element.
+ */
+ float setFloat(int index, float element);
+
+ /**
+ * Returns a mutable clone of this list with the specified capacity.
+ */
+ @Override
+ FloatList mutableCopyWithCapacity(int capacity);
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java
new file mode 100644
index 0000000000..55e33d21d0
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java
@@ -0,0 +1,146 @@
+// 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.IOException;
+
+/**
+ * Thrown when a protocol message being parsed is invalid in some way,
+ * e.g. it contains a malformed varint or a negative byte length.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class InvalidProtocolBufferException extends IOException {
+ private static final long serialVersionUID = -1616151763072450476L;
+ private MessageLite unfinishedMessage = null;
+
+ public InvalidProtocolBufferException(final String description) {
+ super(description);
+ }
+
+ public InvalidProtocolBufferException(IOException e) {
+ super(e.getMessage(), e);
+ }
+
+ /**
+ * Attaches an unfinished message to the exception to support best-effort
+ * parsing in {@code Parser} interface.
+ *
+ * @return this
+ */
+ public InvalidProtocolBufferException setUnfinishedMessage(
+ MessageLite unfinishedMessage) {
+ this.unfinishedMessage = unfinishedMessage;
+ return this;
+ }
+
+ /**
+ * Returns the unfinished message attached to the exception, or null if
+ * no message is attached.
+ */
+ public MessageLite getUnfinishedMessage() {
+ return unfinishedMessage;
+ }
+
+ /**
+ * Unwraps the underlying {@link IOException} if this exception was caused by an I/O
+ * problem. Otherwise, returns {@code this}.
+ */
+ public IOException unwrapIOException() {
+ return getCause() instanceof IOException ? (IOException) getCause() : this;
+ }
+
+ static InvalidProtocolBufferException truncatedMessage() {
+ return new InvalidProtocolBufferException(
+ "While parsing a protocol message, the input ended unexpectedly " +
+ "in the middle of a field. This could mean either that the " +
+ "input has been truncated or that an embedded message " +
+ "misreported its own length.");
+ }
+
+ static InvalidProtocolBufferException negativeSize() {
+ return new InvalidProtocolBufferException(
+ "CodedInputStream encountered an embedded string or message " +
+ "which claimed to have negative size.");
+ }
+
+ static InvalidProtocolBufferException malformedVarint() {
+ return new InvalidProtocolBufferException(
+ "CodedInputStream encountered a malformed varint.");
+ }
+
+ static InvalidProtocolBufferException invalidTag() {
+ return new InvalidProtocolBufferException(
+ "Protocol message contained an invalid tag (zero).");
+ }
+
+ static InvalidProtocolBufferException invalidEndTag() {
+ return new InvalidProtocolBufferException(
+ "Protocol message end-group tag did not match expected tag.");
+ }
+
+ 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. " +
+ "Use CodedInputStream.setRecursionLimit() to increase the depth limit.");
+ }
+
+ static InvalidProtocolBufferException sizeLimitExceeded() {
+ return new InvalidProtocolBufferException(
+ "Protocol message was too large. May be malicious. " +
+ "Use CodedInputStream.setSizeLimit() to increase the size limit.");
+ }
+
+ static InvalidProtocolBufferException parseFailure() {
+ return new InvalidProtocolBufferException("Failed to parse the message.");
+ }
+
+ static InvalidProtocolBufferException invalidUtf8() {
+ return new InvalidProtocolBufferException("Protocol message had invalid UTF-8.");
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/LazyField.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/LazyField.java
new file mode 100644
index 0000000000..98e13ca199
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/LazyField.java
@@ -0,0 +1,154 @@
+// 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.util.Iterator;
+import java.util.Map.Entry;
+
+/**
+ * LazyField encapsulates the logic of lazily parsing message fields. It stores
+ * the message in a ByteString initially and then parse it on-demand.
+ *
+ * Most of key methods are implemented in {@link LazyFieldLite} but this class
+ * can contain default instance of the message to provide {@code hashCode()},
+ * {@code euqals()} and {@code toString()}.
+ *
+ * @author xiangl@google.com (Xiang Li)
+ */
+public class LazyField extends LazyFieldLite {
+
+ /**
+ * Carry a message's default instance which is used by {@code hashCode()}, {@code euqals()} and
+ * {@code toString()}.
+ */
+ private final MessageLite defaultInstance;
+
+ public LazyField(MessageLite defaultInstance,
+ ExtensionRegistryLite extensionRegistry, ByteString bytes) {
+ super(extensionRegistry, bytes);
+
+ this.defaultInstance = defaultInstance;
+ }
+
+ @Override
+ public boolean containsDefaultInstance() {
+ return super.containsDefaultInstance() || value == defaultInstance;
+ }
+
+ public MessageLite getValue() {
+ return getValue(defaultInstance);
+ }
+
+ @Override
+ public int hashCode() {
+ return getValue().hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return getValue().equals(obj);
+ }
+
+ @Override
+ public String toString() {
+ return getValue().toString();
+ }
+
+ // ====================================================
+
+ /**
+ * LazyEntry and LazyIterator are used to encapsulate the LazyField, when
+ * users iterate all fields from FieldSet.
+ */
+ static class LazyEntry<K> implements Entry<K, Object> {
+ private Entry<K, LazyField> entry;
+
+ private LazyEntry(Entry<K, LazyField> entry) {
+ this.entry = entry;
+ }
+
+ @Override
+ public K getKey() {
+ return entry.getKey();
+ }
+
+ @Override
+ public Object getValue() {
+ LazyField field = entry.getValue();
+ if (field == null) {
+ return null;
+ }
+ return field.getValue();
+ }
+
+ public LazyField getField() {
+ return entry.getValue();
+ }
+
+ @Override
+ public Object setValue(Object value) {
+ if (!(value instanceof MessageLite)) {
+ throw new IllegalArgumentException(
+ "LazyField now only used for MessageSet, "
+ + "and the value of MessageSet must be an instance of MessageLite");
+ }
+ return entry.getValue().setValue((MessageLite) value);
+ }
+ }
+
+ static class LazyIterator<K> implements Iterator<Entry<K, Object>> {
+ private Iterator<Entry<K, Object>> iterator;
+
+ public LazyIterator(Iterator<Entry<K, Object>> iterator) {
+ this.iterator = iterator;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Entry<K, Object> next() {
+ Entry<K, ?> entry = iterator.next();
+ if (entry.getValue() instanceof LazyField) {
+ return new LazyEntry<K>((Entry<K, LazyField>) entry);
+ }
+ return (Entry<K, Object>) entry;
+ }
+
+ @Override
+ public void remove() {
+ iterator.remove();
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/LazyFieldLite.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/LazyFieldLite.java
new file mode 100644
index 0000000000..4b0ba0fd6b
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/LazyFieldLite.java
@@ -0,0 +1,437 @@
+// 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.IOException;
+
+/**
+ * LazyFieldLite encapsulates the logic of lazily parsing message fields. It stores
+ * the message in a ByteString initially and then parses it on-demand.
+ *
+ * LazyFieldLite is thread-compatible: concurrent reads are safe once the proto that this
+ * LazyFieldLite is a part of is no longer being mutated by its Builder. However, explicit
+ * synchronization is needed under read/write situations.
+ *
+ * When a LazyFieldLite is used in the context of a MessageLite object, its behavior is considered
+ * to be immutable and none of the setter methods in its API are expected to be invoked. All of the
+ * getters are expected to be thread-safe. When used in the context of a MessageLite.Builder,
+ * setters can be invoked, but there is no guarantee of thread safety.
+ *
+ * TODO(yatin,dweis): Consider splitting this class's functionality and put the mutable methods
+ * into a separate builder class to allow us to give stronger compile-time guarantees.
+ *
+ * This class is internal implementation detail of the protobuf library, so you don't need to use it
+ * directly.
+ *
+ * @author xiangl@google.com (Xiang Li)
+ */
+public class LazyFieldLite {
+ private static final ExtensionRegistryLite EMPTY_REGISTRY =
+ ExtensionRegistryLite.getEmptyRegistry();
+
+ /**
+ * The value associated with the LazyFieldLite object is stored in one or more of the following
+ * three fields (delayedBytes, value, memoizedBytes). They should together be interpreted as
+ * follows.
+ * 1) delayedBytes can be non-null, while value and memoizedBytes is null. The object will be in
+ * this state while the value for the object has not yet been parsed.
+ * 2) Both delayedBytes and value are non-null. The object transitions to this state as soon as
+ * some caller needs to access the value (by invoking getValue()).
+ * 3) memoizedBytes is merely an optimization for calls to LazyFieldLite.toByteString() to avoid
+ * recomputing the ByteString representation on each call. Instead, when the value is parsed
+ * from delayedBytes, we will also assign the contents of delayedBytes to memoizedBytes (since
+ * that is the ByteString representation of value).
+ * 4) Finally, if the LazyFieldLite was created directly with a parsed MessageLite value, then
+ * delayedBytes will be null, and memoizedBytes will be initialized only upon the first call to
+ * LazyFieldLite.toByteString().
+ *
+ * Given the above conditions, any caller that needs a serialized representation of this object
+ * must first check if the memoizedBytes or delayedBytes ByteString is non-null and use it
+ * directly; if both of those are null, it can look at the parsed value field. Similarly, any
+ * caller that needs a parsed value must first check if the value field is already non-null, if
+ * not it must parse the value from delayedBytes.
+ */
+
+ /**
+ * A delayed-parsed version of the contents of this field. When this field is non-null, then the
+ * "value" field is allowed to be null until the time that the value needs to be read.
+ *
+ * When delayedBytes is non-null then {@code extensionRegistry} is required to also be non-null.
+ * {@code value} and {@code memoizedBytes} will be initialized lazily.
+ */
+ private ByteString delayedBytes;
+
+ /**
+ * An {@code ExtensionRegistryLite} for parsing bytes. It is non-null on a best-effort basis. It
+ * is only guaranteed to be non-null if this message was initialized using bytes and an
+ * {@code ExtensionRegistry}. If it directly had a value set then it will be null, unless it has
+ * been merged with another {@code LazyFieldLite} that had an {@code ExtensionRegistry}.
+ */
+ private ExtensionRegistryLite extensionRegistry;
+
+ /**
+ * The parsed value. When this is null and a caller needs access to the MessageLite value, then
+ * {@code delayedBytes} will be parsed lazily at that time.
+ */
+ protected volatile MessageLite value;
+
+ /**
+ * The memoized bytes for {@code value}. This is an optimization for the toByteString() method to
+ * not have to recompute its return-value on each invocation.
+ * TODO(yatin): Figure out whether this optimization is actually necessary.
+ */
+ private volatile ByteString memoizedBytes;
+
+ /**
+ * Constructs a LazyFieldLite with bytes that will be parsed lazily.
+ */
+ public LazyFieldLite(ExtensionRegistryLite extensionRegistry, ByteString bytes) {
+ checkArguments(extensionRegistry, bytes);
+ this.extensionRegistry = extensionRegistry;
+ this.delayedBytes = bytes;
+ }
+
+ /**
+ * Constructs a LazyFieldLite with no contents, and no ability to parse extensions.
+ */
+ public LazyFieldLite() {
+ }
+
+ /**
+ * Constructs a LazyFieldLite instance with a value. The LazyFieldLite may not be able to parse
+ * the extensions in the value as it has no ExtensionRegistry.
+ */
+ public static LazyFieldLite fromValue(MessageLite value) {
+ LazyFieldLite lf = new LazyFieldLite();
+ lf.setValue(value);
+ return lf;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+
+ if (!(o instanceof LazyFieldLite)) {
+ return false;
+ }
+
+ LazyFieldLite other = (LazyFieldLite) o;
+
+ // Lazy fields do not work well with equals... If both are delayedBytes, we do not have a
+ // mechanism to deserialize them so we rely on bytes equality. Otherwise we coerce into an
+ // actual message (if necessary) and call equals on the message itself. This implies that two
+ // messages can by unequal but then be turned equal simply be invoking a getter on a lazy field.
+ MessageLite value1 = value;
+ MessageLite value2 = other.value;
+ if (value1 == null && value2 == null) {
+ return toByteString().equals(other.toByteString());
+ } else if (value1 != null && value2 != null) {
+ return value1.equals(value2);
+ } else if (value1 != null) {
+ return value1.equals(other.getValue(value1.getDefaultInstanceForType()));
+ } else {
+ return getValue(value2.getDefaultInstanceForType()).equals(value2);
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ // We can't provide a memoizable hash code for lazy fields. The byte strings may have different
+ // hash codes but evaluate to equivalent messages. And we have no facility for constructing
+ // a message here if we were not already holding a value.
+ return 1;
+ }
+
+ /**
+ * Determines whether this LazyFieldLite instance represents the default instance of this type.
+ */
+ public boolean containsDefaultInstance() {
+ return memoizedBytes == ByteString.EMPTY
+ || value == null && (delayedBytes == null || delayedBytes == ByteString.EMPTY);
+ }
+
+ /**
+ * Clears the value state of this instance.
+ *
+ * <p>LazyField is not thread-safe for write access. Synchronizations are needed
+ * under read/write situations.
+ */
+ public void clear() {
+ // Don't clear the ExtensionRegistry. It might prove useful later on when merging in another
+ // value, but there is no guarantee that it will contain all extensions that were directly set
+ // on the values that need to be merged.
+ delayedBytes = null;
+ value = null;
+ memoizedBytes = null;
+ }
+
+ /**
+ * Overrides the contents of this LazyField.
+ *
+ * <p>LazyField is not thread-safe for write access. Synchronizations are needed
+ * under read/write situations.
+ */
+ public void set(LazyFieldLite other) {
+ this.delayedBytes = other.delayedBytes;
+ this.value = other.value;
+ this.memoizedBytes = other.memoizedBytes;
+ // If the other LazyFieldLite was created by directly setting the value rather than first by
+ // parsing, then it will not have an extensionRegistry. In this case we hold on to the existing
+ // extensionRegistry, which has no guarantees that it has all the extensions that will be
+ // directly set on the value.
+ if (other.extensionRegistry != null) {
+ this.extensionRegistry = other.extensionRegistry;
+ }
+ }
+
+ /**
+ * Returns message instance. It may do some thread-safe delayed parsing of bytes.
+ *
+ * @param defaultInstance its message's default instance. It's also used to get parser for the
+ * message type.
+ */
+ public MessageLite getValue(MessageLite defaultInstance) {
+ ensureInitialized(defaultInstance);
+ return value;
+ }
+
+ /**
+ * Sets the value of the instance and returns the old value without delay parsing anything.
+ *
+ * <p>LazyField is not thread-safe for write access. Synchronizations are needed
+ * under read/write situations.
+ */
+ public MessageLite setValue(MessageLite value) {
+ MessageLite originalValue = this.value;
+ this.delayedBytes = null;
+ this.memoizedBytes = null;
+ this.value = value;
+ return originalValue;
+ }
+
+ /**
+ * Merges another instance's contents. In some cases may drop some extensions if both fields
+ * contain data. If the other field has an {@code ExtensionRegistry} but this does not, then this
+ * field will copy over that {@code ExtensionRegistry}.
+ *
+ * <p>LazyField is not thread-safe for write access. Synchronizations are needed
+ * under read/write situations.
+ */
+ public void merge(LazyFieldLite other) {
+ if (other.containsDefaultInstance()) {
+ return;
+ }
+
+ if (this.containsDefaultInstance()) {
+ set(other);
+ return;
+ }
+
+ // If the other field has an extension registry but this does not, copy over the other extension
+ // registry.
+ if (this.extensionRegistry == null) {
+ this.extensionRegistry = other.extensionRegistry;
+ }
+
+ // In the case that both of them are not parsed we simply concatenate the bytes to save time. In
+ // the (probably rare) case that they have different extension registries there is a chance that
+ // some of the extensions may be dropped, but the tradeoff of making this operation fast seems
+ // to outway the benefits of combining the extension registries, which is not normally done for
+ // lite protos anyways.
+ if (this.delayedBytes != null && other.delayedBytes != null) {
+ this.delayedBytes = this.delayedBytes.concat(other.delayedBytes);
+ return;
+ }
+
+ // At least one is parsed and both contain data. We won't drop any extensions here directly, but
+ // in the case that the extension registries are not the same then we might in the future if we
+ // need to serialze and parse a message again.
+ if (this.value == null && other.value != null) {
+ setValue(mergeValueAndBytes(other.value, this.delayedBytes, this.extensionRegistry));
+ return;
+ } else if (this.value != null && other.value == null) {
+ setValue(mergeValueAndBytes(this.value, other.delayedBytes, other.extensionRegistry));
+ return;
+ }
+
+ // At this point we have two fully parsed messages.
+ setValue(this.value.toBuilder().mergeFrom(other.value).build());
+ }
+
+ /**
+ * Merges another instance's contents from a stream.
+ *
+ * <p>LazyField is not thread-safe for write access. Synchronizations are needed
+ * under read/write situations.
+ */
+ public void mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry)
+ throws IOException {
+ if (this.containsDefaultInstance()) {
+ setByteString(input.readBytes(), extensionRegistry);
+ return;
+ }
+
+ // If the other field has an extension registry but this does not, copy over the other extension
+ // registry.
+ if (this.extensionRegistry == null) {
+ this.extensionRegistry = extensionRegistry;
+ }
+
+ // In the case that both of them are not parsed we simply concatenate the bytes to save time. In
+ // the (probably rare) case that they have different extension registries there is a chance that
+ // some of the extensions may be dropped, but the tradeoff of making this operation fast seems
+ // to outway the benefits of combining the extension registries, which is not normally done for
+ // lite protos anyways.
+ if (this.delayedBytes != null) {
+ setByteString(this.delayedBytes.concat(input.readBytes()), this.extensionRegistry);
+ return;
+ }
+
+ // We are parsed and both contain data. We won't drop any extensions here directly, but in the
+ // case that the extension registries are not the same then we might in the future if we
+ // need to serialize and parse a message again.
+ try {
+ setValue(value.toBuilder().mergeFrom(input, extensionRegistry).build());
+ } catch (InvalidProtocolBufferException e) {
+ // Nothing is logged and no exceptions are thrown. Clients will be unaware that a proto
+ // was invalid.
+ }
+ }
+
+ private static MessageLite mergeValueAndBytes(
+ MessageLite value, ByteString otherBytes, ExtensionRegistryLite extensionRegistry) {
+ try {
+ return value.toBuilder().mergeFrom(otherBytes, extensionRegistry).build();
+ } catch (InvalidProtocolBufferException e) {
+ // Nothing is logged and no exceptions are thrown. Clients will be unaware that a proto
+ // was invalid.
+ return value;
+ }
+ }
+
+ /**
+ * Sets this field with bytes to delay-parse.
+ */
+ public void setByteString(ByteString bytes, ExtensionRegistryLite extensionRegistry) {
+ checkArguments(extensionRegistry, bytes);
+ this.delayedBytes = bytes;
+ this.extensionRegistry = extensionRegistry;
+ this.value = null;
+ this.memoizedBytes = null;
+ }
+
+ /**
+ * Due to the optional field can be duplicated at the end of serialized
+ * bytes, which will make the serialized size changed after LazyField
+ * parsed. Be careful when using this method.
+ */
+ public int getSerializedSize() {
+ // We *must* return delayed bytes size if it was ever set because the dependent messages may
+ // have memoized serialized size based off of it.
+ if (memoizedBytes != null) {
+ return memoizedBytes.size();
+ } else if (delayedBytes != null) {
+ return delayedBytes.size();
+ } else if (value != null) {
+ return value.getSerializedSize();
+ } else {
+ return 0;
+ }
+ }
+
+ /**
+ * Returns a BytesString for this field in a thread-safe way.
+ */
+ public ByteString toByteString() {
+ if (memoizedBytes != null) {
+ return memoizedBytes;
+ }
+ // We *must* return delayed bytes if it was set because the dependent messages may have
+ // memoized serialized size based off of it.
+ if (delayedBytes != null) {
+ return delayedBytes;
+ }
+ synchronized (this) {
+ if (memoizedBytes != null) {
+ return memoizedBytes;
+ }
+ if (value == null) {
+ memoizedBytes = ByteString.EMPTY;
+ } else {
+ memoizedBytes = value.toByteString();
+ }
+ return memoizedBytes;
+ }
+ }
+
+ /**
+ * Might lazily parse the bytes that were previously passed in. Is thread-safe.
+ */
+ protected void ensureInitialized(MessageLite defaultInstance) {
+ if (value != null) {
+ return;
+ }
+ synchronized (this) {
+ if (value != null) {
+ return;
+ }
+ try {
+ if (delayedBytes != null) {
+ // The extensionRegistry shouldn't be null here since we have delayedBytes.
+ MessageLite parsedValue = defaultInstance.getParserForType()
+ .parseFrom(delayedBytes, extensionRegistry);
+ this.value = parsedValue;
+ this.memoizedBytes = delayedBytes;
+ } else {
+ this.value = defaultInstance;
+ this.memoizedBytes = ByteString.EMPTY;
+ }
+ } catch (InvalidProtocolBufferException e) {
+ // Nothing is logged and no exceptions are thrown. Clients will be unaware that this proto
+ // was invalid.
+ this.value = defaultInstance;
+ this.memoizedBytes = ByteString.EMPTY;
+ }
+ }
+ }
+
+
+ private static void checkArguments(ExtensionRegistryLite extensionRegistry, ByteString bytes) {
+ if (extensionRegistry == null) {
+ throw new NullPointerException("found null ExtensionRegistry");
+ }
+ if (bytes == null) {
+ throw new NullPointerException("found null ByteString");
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/LazyStringArrayList.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/LazyStringArrayList.java
new file mode 100644
index 0000000000..d474c51ef1
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/LazyStringArrayList.java
@@ -0,0 +1,423 @@
+// 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.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.RandomAccess;
+
+/**
+ * An implementation of {@link LazyStringList} that wraps an ArrayList. Each
+ * element is one of String, ByteString, or byte[]. It caches the last one
+ * requested which is most likely the one needed next. This minimizes memory
+ * usage while satisfying the most common use cases.
+ * <p>
+ * <strong>Note that this implementation is not synchronized.</strong>
+ * If multiple threads access an <tt>ArrayList</tt> instance concurrently,
+ * and at least one of the threads modifies the list structurally, it
+ * <i>must</i> be synchronized externally. (A structural modification is
+ * any operation that adds or deletes one or more elements, or explicitly
+ * resizes the backing array; merely setting the value of an element is not
+ * a structural modification.) This is typically accomplished by
+ * synchronizing on some object that naturally encapsulates the list.
+ * <p>
+ * If the implementation is accessed via concurrent reads, this is thread safe.
+ * Conversions are done in a thread safe manner. It's possible that the
+ * conversion may happen more than once if two threads attempt to access the
+ * same element and the modifications were not visible to each other, but this
+ * will not result in any corruption of the list or change in behavior other
+ * than performance.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class LazyStringArrayList extends AbstractProtobufList<String>
+ implements LazyStringList, RandomAccess {
+
+ private static final LazyStringArrayList EMPTY_LIST = new LazyStringArrayList();
+ static {
+ EMPTY_LIST.makeImmutable();
+ }
+
+ static LazyStringArrayList emptyList() {
+ return EMPTY_LIST;
+ }
+
+ // For compatibility with older runtimes.
+ public static final LazyStringList EMPTY = EMPTY_LIST;
+
+ private final List<Object> list;
+
+ public LazyStringArrayList() {
+ this(DEFAULT_CAPACITY);
+ }
+
+ public LazyStringArrayList(int intialCapacity) {
+ this(new ArrayList<Object>(intialCapacity));
+ }
+
+ public LazyStringArrayList(LazyStringList from) {
+ list = new ArrayList<Object>(from.size());
+ addAll(from);
+ }
+
+ public LazyStringArrayList(List<String> from) {
+ this(new ArrayList<Object>(from));
+ }
+
+ private LazyStringArrayList(ArrayList<Object> list) {
+ this.list = list;
+ }
+
+ @Override
+ public LazyStringArrayList mutableCopyWithCapacity(int capacity) {
+ if (capacity < size()) {
+ throw new IllegalArgumentException();
+ }
+ ArrayList<Object> newList = new ArrayList<Object>(capacity);
+ newList.addAll(list);
+ return new LazyStringArrayList(newList);
+ }
+
+ @Override
+ public String get(int index) {
+ Object o = list.get(index);
+ if (o instanceof String) {
+ return (String) o;
+ } else if (o instanceof ByteString) {
+ ByteString bs = (ByteString) o;
+ String s = bs.toStringUtf8();
+ if (bs.isValidUtf8()) {
+ list.set(index, s);
+ }
+ return s;
+ } else {
+ byte[] ba = (byte[]) o;
+ String s = Internal.toStringUtf8(ba);
+ if (Internal.isValidUtf8(ba)) {
+ list.set(index, s);
+ }
+ return s;
+ }
+ }
+
+ @Override
+ public int size() {
+ return list.size();
+ }
+
+ @Override
+ public String set(int index, String s) {
+ ensureIsMutable();
+ Object o = list.set(index, s);
+ return asString(o);
+ }
+
+ @Override
+ public void add(int index, String element) {
+ ensureIsMutable();
+ list.add(index, element);
+ modCount++;
+ }
+
+ private void add(int index, ByteString element) {
+ ensureIsMutable();
+ list.add(index, element);
+ modCount++;
+ }
+
+ private void add(int index, byte[] element) {
+ ensureIsMutable();
+ list.add(index, element);
+ modCount++;
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends String> c) {
+ // The default implementation of AbstractCollection.addAll(Collection)
+ // delegates to add(Object). This implementation instead delegates to
+ // addAll(int, Collection), which makes a special case for Collections
+ // which are instances of LazyStringList.
+ return addAll(size(), c);
+ }
+
+ @Override
+ public boolean addAll(int index, Collection<? extends String> c) {
+ ensureIsMutable();
+ // When copying from another LazyStringList, directly copy the underlying
+ // elements rather than forcing each element to be decoded to a String.
+ Collection<?> collection = c instanceof LazyStringList
+ ? ((LazyStringList) c).getUnderlyingElements() : c;
+ boolean ret = list.addAll(index, collection);
+ modCount++;
+ return ret;
+ }
+
+ @Override
+ public boolean addAllByteString(Collection<? extends ByteString> values) {
+ ensureIsMutable();
+ boolean ret = list.addAll(values);
+ modCount++;
+ return ret;
+ }
+
+ @Override
+ public boolean addAllByteArray(Collection<byte[]> c) {
+ ensureIsMutable();
+ boolean ret = list.addAll(c);
+ modCount++;
+ return ret;
+ }
+
+ @Override
+ public String remove(int index) {
+ ensureIsMutable();
+ Object o = list.remove(index);
+ modCount++;
+ return asString(o);
+ }
+
+ @Override
+ public void clear() {
+ ensureIsMutable();
+ list.clear();
+ modCount++;
+ }
+
+ @Override
+ public void add(ByteString element) {
+ ensureIsMutable();
+ list.add(element);
+ modCount++;
+ }
+
+ @Override
+ public void add(byte[] element) {
+ ensureIsMutable();
+ list.add(element);
+ modCount++;
+ }
+
+ @Override
+ public Object getRaw(int index) {
+ return list.get(index);
+ }
+
+ @Override
+ public ByteString getByteString(int index) {
+ Object o = list.get(index);
+ ByteString b = asByteString(o);
+ if (b != o) {
+ list.set(index, b);
+ }
+ return b;
+ }
+
+ @Override
+ public byte[] getByteArray(int index) {
+ Object o = list.get(index);
+ byte[] b = asByteArray(o);
+ if (b != o) {
+ list.set(index, b);
+ }
+ return b;
+ }
+
+ @Override
+ public void set(int index, ByteString s) {
+ setAndReturn(index, s);
+ }
+
+ private Object setAndReturn(int index, ByteString s) {
+ ensureIsMutable();
+ return list.set(index, s);
+ }
+
+ @Override
+ public void set(int index, byte[] s) {
+ setAndReturn(index, s);
+ }
+
+ private Object setAndReturn(int index, byte[] s) {
+ ensureIsMutable();
+ return list.set(index, s);
+ }
+
+ private static String asString(Object o) {
+ if (o instanceof String) {
+ return (String) o;
+ } else if (o instanceof ByteString) {
+ return ((ByteString) o).toStringUtf8();
+ } else {
+ return Internal.toStringUtf8((byte[]) o);
+ }
+ }
+
+ private static ByteString asByteString(Object o) {
+ if (o instanceof ByteString) {
+ return (ByteString) o;
+ } else if (o instanceof String) {
+ return ByteString.copyFromUtf8((String) o);
+ } else {
+ return ByteString.copyFrom((byte[]) o);
+ }
+ }
+
+ private static byte[] asByteArray(Object o) {
+ if (o instanceof byte[]) {
+ return (byte[]) o;
+ } else if (o instanceof String) {
+ return Internal.toByteArray((String) o);
+ } else {
+ return ((ByteString) o).toByteArray();
+ }
+ }
+
+ @Override
+ public List<?> getUnderlyingElements() {
+ return Collections.unmodifiableList(list);
+ }
+
+ @Override
+ public void mergeFrom(LazyStringList other) {
+ ensureIsMutable();
+ for (Object o : other.getUnderlyingElements()) {
+ if (o instanceof byte[]) {
+ byte[] b = (byte[]) o;
+ // Byte array's content is mutable so they should be copied rather than
+ // shared when merging from one message to another.
+ list.add(Arrays.copyOf(b, b.length));
+ } else {
+ list.add(o);
+ }
+ }
+ }
+
+ private static class ByteArrayListView extends AbstractList<byte[]>
+ implements RandomAccess {
+ private final LazyStringArrayList list;
+
+ ByteArrayListView(LazyStringArrayList list) {
+ this.list = list;
+ }
+
+ @Override
+ public byte[] get(int index) {
+ return list.getByteArray(index);
+ }
+
+ @Override
+ public int size() {
+ return list.size();
+ }
+
+ @Override
+ public byte[] set(int index, byte[] s) {
+ Object o = list.setAndReturn(index, s);
+ modCount++;
+ return asByteArray(o);
+ }
+
+ @Override
+ public void add(int index, byte[] s) {
+ list.add(index, s);
+ modCount++;
+ }
+
+ @Override
+ public byte[] remove(int index) {
+ Object o = list.remove(index);
+ modCount++;
+ return asByteArray(o);
+ }
+ }
+
+ @Override
+ public List<byte[]> asByteArrayList() {
+ return new ByteArrayListView(this);
+ }
+
+ private static class ByteStringListView extends AbstractList<ByteString>
+ implements RandomAccess {
+ private final LazyStringArrayList list;
+
+ ByteStringListView(LazyStringArrayList list) {
+ this.list = list;
+ }
+
+ @Override
+ public ByteString get(int index) {
+ return list.getByteString(index);
+ }
+
+ @Override
+ public int size() {
+ return list.size();
+ }
+
+ @Override
+ public ByteString set(int index, ByteString s) {
+ Object o = list.setAndReturn(index, s);
+ modCount++;
+ return asByteString(o);
+ }
+
+ @Override
+ public void add(int index, ByteString s) {
+ list.add(index, s);
+ modCount++;
+ }
+
+ @Override
+ public ByteString remove(int index) {
+ Object o = list.remove(index);
+ modCount++;
+ return asByteString(o);
+ }
+ }
+
+ @Override
+ public List<ByteString> asByteStringList() {
+ return new ByteStringListView(this);
+ }
+
+ @Override
+ public LazyStringList getUnmodifiableView() {
+ if (isModifiable()) {
+ return new UnmodifiableLazyStringList(this);
+ }
+ return this;
+ }
+
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/LazyStringList.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/LazyStringList.java
new file mode 100644
index 0000000000..3eeedca1d3
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/LazyStringList.java
@@ -0,0 +1,174 @@
+// 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.util.Collection;
+import java.util.List;
+
+/**
+ * An interface extending {@code List<String>} that also provides access to the
+ * items of the list as UTF8-encoded ByteString or byte[] objects. This is
+ * used by the protocol buffer implementation to support lazily converting bytes
+ * parsed over the wire to String objects until needed and also increases the
+ * efficiency of serialization if the String was never requested as the
+ * ByteString or byte[] is already cached. The ByteString methods are used in
+ * immutable API only and byte[] methods used in mutable API only for they use
+ * different representations for string/bytes fields.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public interface LazyStringList extends ProtocolStringList {
+
+ /**
+ * Returns the element at the specified position in this list as a ByteString.
+ *
+ * @param index index of the element to return
+ * @return the element at the specified position in this list
+ * @throws IndexOutOfBoundsException if the index is out of range
+ * ({@code index < 0 || index >= size()})
+ */
+ ByteString getByteString(int index);
+
+ /**
+ * Returns the element at the specified position in this list as an Object
+ * that will either be a String or a ByteString.
+ *
+ * @param index index of the element to return
+ * @return the element at the specified position in this list
+ * @throws IndexOutOfBoundsException if the index is out of range
+ * ({@code index < 0 || index >= size()})
+ */
+ Object getRaw(int index);
+
+ /**
+ * Returns the element at the specified position in this list as byte[].
+ *
+ * @param index index of the element to return
+ * @return the element at the specified position in this list
+ * @throws IndexOutOfBoundsException if the index is out of range
+ * ({@code index < 0 || index >= size()})
+ */
+ byte[] getByteArray(int index);
+
+ /**
+ * Appends the specified element to the end of this list (optional
+ * operation).
+ *
+ * @param element element to be appended to this list
+ * @throws UnsupportedOperationException if the <tt>add</tt> operation
+ * is not supported by this list
+ */
+ void add(ByteString element);
+
+ /**
+ * Appends the specified element to the end of this list (optional
+ * operation).
+ *
+ * @param element element to be appended to this list
+ * @throws UnsupportedOperationException if the <tt>add</tt> operation
+ * is not supported by this list
+ */
+ void add(byte[] element);
+
+ /**
+ * Replaces the element at the specified position in this list with the
+ * specified element (optional operation).
+ *
+ * @param index index of the element to replace
+ * @param element the element to be stored at the specified position
+ * @throws UnsupportedOperationException if the <tt>set</tt> operation
+ * is not supported by this list
+ * IndexOutOfBoundsException if the index is out of range
+ * ({@code index < 0 || index >= size()})
+ */
+ void set(int index, ByteString element);
+
+ /**
+ * Replaces the element at the specified position in this list with the
+ * specified element (optional operation).
+ *
+ * @param index index of the element to replace
+ * @param element the element to be stored at the specified position
+ * @throws UnsupportedOperationException if the <tt>set</tt> operation
+ * is not supported by this list
+ * IndexOutOfBoundsException if the index is out of range
+ * ({@code index < 0 || index >= size()})
+ */
+ void set(int index, byte[] element);
+
+ /**
+ * Appends all elements in the specified ByteString collection to the end of
+ * this list.
+ *
+ * @param c collection whose elements are to be added to this list
+ * @return true if this list changed as a result of the call
+ * @throws UnsupportedOperationException if the <tt>addAllByteString</tt>
+ * operation is not supported by this list
+ */
+ boolean addAllByteString(Collection<? extends ByteString> c);
+
+ /**
+ * Appends all elements in the specified byte[] collection to the end of
+ * this list.
+ *
+ * @param c collection whose elements are to be added to this list
+ * @return true if this list changed as a result of the call
+ * @throws UnsupportedOperationException if the <tt>addAllByteArray</tt>
+ * operation is not supported by this list
+ */
+ boolean addAllByteArray(Collection<byte[]> c);
+
+ /**
+ * Returns an unmodifiable List of the underlying elements, each of which is
+ * either a {@code String} or its equivalent UTF-8 encoded {@code ByteString}
+ * or byte[]. It is an error for the caller to modify the returned
+ * List, and attempting to do so will result in an
+ * {@link UnsupportedOperationException}.
+ */
+ List<?> getUnderlyingElements();
+
+ /**
+ * Merges all elements from another LazyStringList into this one. This method
+ * differs from {@link #addAll(Collection)} on that underlying byte arrays are
+ * copied instead of reference shared. Immutable API doesn't need to use this
+ * method as byte[] is not used there at all.
+ */
+ void mergeFrom(LazyStringList other);
+
+ /**
+ * Returns a mutable view of this list. Changes to the view will be made into
+ * the original list. This method is used in mutable API only.
+ */
+ List<byte[]> asByteArrayList();
+
+ /** Returns an unmodifiable view of the list. */
+ LazyStringList getUnmodifiableView();
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/LongArrayList.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/LongArrayList.java
new file mode 100644
index 0000000000..5a772e3aa8
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/LongArrayList.java
@@ -0,0 +1,272 @@
+// 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.LongList;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.RandomAccess;
+
+/**
+ * An implementation of {@link LongList} on top of a primitive array.
+ *
+ * @author dweis@google.com (Daniel Weis)
+ */
+final class LongArrayList
+ extends AbstractProtobufList<Long>
+ implements LongList, RandomAccess {
+
+ private static final LongArrayList EMPTY_LIST = new LongArrayList();
+ static {
+ EMPTY_LIST.makeImmutable();
+ }
+
+ public static LongArrayList emptyList() {
+ return EMPTY_LIST;
+ }
+
+ /**
+ * The backing store for the list.
+ */
+ private long[] array;
+
+ /**
+ * The size of the list distinct from the length of the array. That is, it is the number of
+ * elements set in the list.
+ */
+ private int size;
+
+ /**
+ * Constructs a new mutable {@code LongArrayList} with default capacity.
+ */
+ LongArrayList() {
+ this(new long[DEFAULT_CAPACITY], 0);
+ }
+
+ /**
+ * Constructs a new mutable {@code LongArrayList}
+ * containing the same elements as {@code other}.
+ */
+ private LongArrayList(long[] other, int size) {
+ array = other;
+ this.size = size;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof LongArrayList)) {
+ return super.equals(o);
+ }
+ LongArrayList other = (LongArrayList) o;
+ if (size != other.size) {
+ return false;
+ }
+
+ final long[] arr = other.array;
+ for (int i = 0; i < size; i++) {
+ if (array[i] != arr[i]) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 1;
+ for (int i = 0; i < size; i++) {
+ result = (31 * result) + Internal.hashLong(array[i]);
+ }
+ return result;
+ }
+
+ @Override
+ public LongList mutableCopyWithCapacity(int capacity) {
+ if (capacity < size) {
+ throw new IllegalArgumentException();
+ }
+ return new LongArrayList(Arrays.copyOf(array, capacity), size);
+ }
+
+ @Override
+ public Long get(int index) {
+ return getLong(index);
+ }
+
+ @Override
+ public long getLong(int index) {
+ ensureIndexInRange(index);
+ return array[index];
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public Long set(int index, Long element) {
+ return setLong(index, element);
+ }
+
+ @Override
+ public long setLong(int index, long element) {
+ ensureIsMutable();
+ ensureIndexInRange(index);
+ long previousValue = array[index];
+ array[index] = element;
+ return previousValue;
+ }
+
+ @Override
+ public void add(int index, Long element) {
+ addLong(index, element);
+ }
+
+ /**
+ * Like {@link #add(Long)} but more efficient in that it doesn't box the element.
+ */
+ @Override
+ public void addLong(long element) {
+ addLong(size, element);
+ }
+
+ /**
+ * Like {@link #add(int, Long)} but more efficient in that it doesn't box the element.
+ */
+ private void addLong(int index, long element) {
+ ensureIsMutable();
+ if (index < 0 || index > size) {
+ throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index));
+ }
+
+ if (size < array.length) {
+ // Shift everything over to make room
+ System.arraycopy(array, index, array, index + 1, size - index);
+ } else {
+ // Resize to 1.5x the size
+ int length = ((size * 3) / 2) + 1;
+ long[] newArray = new long[length];
+
+ // Copy the first part directly
+ System.arraycopy(array, 0, newArray, 0, index);
+
+ // Copy the rest shifted over by one to make room
+ System.arraycopy(array, index, newArray, index + 1, size - index);
+ array = newArray;
+ }
+
+ array[index] = element;
+ size++;
+ modCount++;
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends Long> collection) {
+ ensureIsMutable();
+
+ if (collection == null) {
+ throw new NullPointerException();
+ }
+
+ // We specialize when adding another LongArrayList to avoid boxing elements.
+ if (!(collection instanceof LongArrayList)) {
+ return super.addAll(collection);
+ }
+
+ LongArrayList list = (LongArrayList) collection;
+ if (list.size == 0) {
+ return false;
+ }
+
+ int overflow = Integer.MAX_VALUE - size;
+ if (overflow < list.size) {
+ // We can't actually represent a list this large.
+ throw new OutOfMemoryError();
+ }
+
+ int newSize = size + list.size;
+ if (newSize > array.length) {
+ array = Arrays.copyOf(array, newSize);
+ }
+
+ System.arraycopy(list.array, 0, array, size, list.size);
+ size = newSize;
+ modCount++;
+ return true;
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ ensureIsMutable();
+ for (int i = 0; i < size; i++) {
+ if (o.equals(array[i])) {
+ System.arraycopy(array, i + 1, array, i, size - i);
+ size--;
+ modCount++;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public Long remove(int index) {
+ ensureIsMutable();
+ ensureIndexInRange(index);
+ long value = array[index];
+ System.arraycopy(array, index + 1, array, index, size - index);
+ size--;
+ modCount++;
+ return value;
+ }
+
+ /**
+ * Ensures that the provided {@code index} is within the range of {@code [0, size]}. Throws an
+ * {@link IndexOutOfBoundsException} if it is not.
+ *
+ * @param index the index to verify is in range
+ */
+ private void ensureIndexInRange(int index) {
+ if (index < 0 || index >= size) {
+ throw new IndexOutOfBoundsException(makeOutOfBoundsExceptionMessage(index));
+ }
+ }
+
+ private String makeOutOfBoundsExceptionMessage(int index) {
+ return "Index:" + index + ", Size:" + size;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MapEntry.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MapEntry.java
new file mode 100644
index 0000000000..7e8e9aad54
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MapEntry.java
@@ -0,0 +1,451 @@
+// 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.Descriptor;
+import com.google.protobuf.Descriptors.EnumValueDescriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * Implements MapEntry messages.
+ *
+ * In reflection API, map fields will be treated as repeated message fields and
+ * each map entry is accessed as a message. This MapEntry class is used to
+ * represent these map entry messages in reflection API.
+ *
+ * Protobuf internal. Users shouldn't use this class.
+ */
+public final class MapEntry<K, V> extends AbstractMessage {
+
+ private static final class Metadata<K, V> extends MapEntryLite.Metadata<K, V> {
+
+ public final Descriptor descriptor;
+ public final Parser<MapEntry<K, V>> parser;
+
+ public Metadata(
+ Descriptor descriptor,
+ MapEntry<K, V> defaultInstance,
+ WireFormat.FieldType keyType,
+ WireFormat.FieldType valueType) {
+ super(keyType, defaultInstance.key, valueType, defaultInstance.value);
+ this.descriptor = descriptor;
+ this.parser = new AbstractParser<MapEntry<K, V>>() {
+
+ @Override
+ public MapEntry<K, V> parsePartialFrom(
+ CodedInputStream input, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ return new MapEntry<K, V>(Metadata.this, input, extensionRegistry);
+ }
+ };
+ }
+ }
+
+ private final K key;
+ private final V value;
+ private final Metadata<K, V> metadata;
+
+ /** Create a default MapEntry instance. */
+ private MapEntry(
+ Descriptor descriptor,
+ WireFormat.FieldType keyType, K defaultKey,
+ WireFormat.FieldType valueType, V defaultValue) {
+ this.key = defaultKey;
+ this.value = defaultValue;
+ this.metadata = new Metadata<K, V>(descriptor, this, keyType, valueType);
+ }
+
+ /** Create a MapEntry with the provided key and value. */
+ @SuppressWarnings("unchecked")
+ private MapEntry(Metadata metadata, K key, V value) {
+ this.key = key;
+ this.value = value;
+ this.metadata = metadata;
+ }
+
+ /** Parsing constructor. */
+ private MapEntry(
+ Metadata<K, V> metadata,
+ CodedInputStream input,
+ ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ try {
+ this.metadata = metadata;
+ Map.Entry<K, V> entry = MapEntryLite.parseEntry(input, metadata, extensionRegistry);
+ this.key = entry.getKey();
+ this.value = entry.getValue();
+ } catch (InvalidProtocolBufferException e) {
+ throw e.setUnfinishedMessage(this);
+ } catch (IOException e) {
+ throw new InvalidProtocolBufferException(e).setUnfinishedMessage(this);
+ }
+ }
+
+ /**
+ * Create a default MapEntry instance. A default MapEntry instance should be
+ * created only once for each map entry message type. Generated code should
+ * store the created default instance and use it later to create new MapEntry
+ * messages of the same type.
+ */
+ public static <K, V> MapEntry<K, V> newDefaultInstance(
+ Descriptor descriptor,
+ WireFormat.FieldType keyType, K defaultKey,
+ WireFormat.FieldType valueType, V defaultValue) {
+ return new MapEntry<K, V>(
+ descriptor, keyType, defaultKey, valueType, defaultValue);
+ }
+
+ public K getKey() {
+ return key;
+ }
+
+ public V getValue() {
+ return value;
+ }
+
+ private volatile int cachedSerializedSize = -1;
+
+ @Override
+ public int getSerializedSize() {
+ if (cachedSerializedSize != -1) {
+ return cachedSerializedSize;
+ }
+
+ int size = MapEntryLite.computeSerializedSize(metadata, key, value);
+ cachedSerializedSize = size;
+ return size;
+ }
+
+ @Override
+ public void writeTo(CodedOutputStream output) throws IOException {
+ MapEntryLite.writeTo(output, metadata, key, value);
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return isInitialized(metadata, value);
+ }
+
+ @Override
+ public Parser<MapEntry<K, V>> getParserForType() {
+ return metadata.parser;
+ }
+
+ @Override
+ public Builder<K, V> newBuilderForType() {
+ return new Builder<K, V>(metadata);
+ }
+
+ @Override
+ public Builder<K, V> toBuilder() {
+ return new Builder<K, V>(metadata, key, value);
+ }
+
+ @Override
+ public MapEntry<K, V> getDefaultInstanceForType() {
+ return new MapEntry<K, V>(metadata, metadata.defaultKey, metadata.defaultValue);
+ }
+
+ @Override
+ public Descriptor getDescriptorForType() {
+ return metadata.descriptor;
+ }
+
+ @Override
+ public Map<FieldDescriptor, Object> getAllFields() {
+ TreeMap<FieldDescriptor, Object> result = new TreeMap<FieldDescriptor, Object>();
+ for (final FieldDescriptor field : metadata.descriptor.getFields()) {
+ if (hasField(field)) {
+ result.put(field, getField(field));
+ }
+ }
+ return Collections.unmodifiableMap(result);
+ }
+
+ private void checkFieldDescriptor(FieldDescriptor field) {
+ if (field.getContainingType() != metadata.descriptor) {
+ throw new RuntimeException(
+ "Wrong FieldDescriptor \"" + field.getFullName()
+ + "\" used in message \"" + metadata.descriptor.getFullName());
+ }
+ }
+
+ @Override
+ public boolean hasField(FieldDescriptor field) {
+ checkFieldDescriptor(field);;
+ // A MapEntry always contains two fields.
+ return true;
+ }
+
+ @Override
+ public Object getField(FieldDescriptor field) {
+ checkFieldDescriptor(field);
+ Object result = field.getNumber() == 1 ? getKey() : getValue();
+ // Convert enums to EnumValueDescriptor.
+ if (field.getType() == FieldDescriptor.Type.ENUM) {
+ result = field.getEnumType().findValueByNumberCreatingIfUnknown(
+ (java.lang.Integer) result);
+ }
+ return result;
+ }
+
+ @Override
+ public int getRepeatedFieldCount(FieldDescriptor field) {
+ throw new RuntimeException(
+ "There is no repeated field in a map entry message.");
+ }
+
+ @Override
+ public Object getRepeatedField(FieldDescriptor field, int index) {
+ throw new RuntimeException(
+ "There is no repeated field in a map entry message.");
+ }
+
+ @Override
+ public UnknownFieldSet getUnknownFields() {
+ return UnknownFieldSet.getDefaultInstance();
+ }
+
+ /**
+ * Builder to create {@link MapEntry} messages.
+ */
+ public static class Builder<K, V>
+ extends AbstractMessage.Builder<Builder<K, V>> {
+ private final Metadata<K, V> metadata;
+ private K key;
+ private V value;
+
+ private Builder(Metadata<K, V> metadata) {
+ this(metadata, metadata.defaultKey, metadata.defaultValue);
+ }
+
+ private Builder(Metadata<K, V> metadata, K key, V value) {
+ this.metadata = metadata;
+ this.key = key;
+ this.value = value;
+ }
+
+ public K getKey() {
+ return key;
+ }
+
+ public V getValue() {
+ return value;
+ }
+
+ public Builder<K, V> setKey(K key) {
+ this.key = key;
+ return this;
+ }
+
+ public Builder<K, V> clearKey() {
+ this.key = metadata.defaultKey;
+ return this;
+ }
+
+ public Builder<K, V> setValue(V value) {
+ this.value = value;
+ return this;
+ }
+
+ public Builder<K, V> clearValue() {
+ this.value = metadata.defaultValue;
+ return this;
+ }
+
+ @Override
+ public MapEntry<K, V> build() {
+ MapEntry<K, V> result = buildPartial();
+ if (!result.isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return result;
+ }
+
+ @Override
+ public MapEntry<K, V> buildPartial() {
+ return new MapEntry<K, V>(metadata, key, value);
+ }
+
+ @Override
+ public Descriptor getDescriptorForType() {
+ return metadata.descriptor;
+ }
+
+ private void checkFieldDescriptor(FieldDescriptor field) {
+ if (field.getContainingType() != metadata.descriptor) {
+ throw new RuntimeException(
+ "Wrong FieldDescriptor \"" + field.getFullName()
+ + "\" used in message \"" + metadata.descriptor.getFullName());
+ }
+ }
+
+ @Override
+ public Message.Builder newBuilderForField(FieldDescriptor field) {
+ checkFieldDescriptor(field);;
+ // This method should be called for message fields and in a MapEntry
+ // message only the value field can possibly be a message field.
+ if (field.getNumber() != 2
+ || field.getJavaType() != FieldDescriptor.JavaType.MESSAGE) {
+ throw new RuntimeException(
+ "\"" + field.getFullName() + "\" is not a message value field.");
+ }
+ return ((Message) value).newBuilderForType();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Builder<K, V> setField(FieldDescriptor field, Object value) {
+ checkFieldDescriptor(field);
+ if (field.getNumber() == 1) {
+ setKey((K) value);
+ } 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);
+ }
+ return this;
+ }
+
+ @Override
+ public Builder<K, V> clearField(FieldDescriptor field) {
+ checkFieldDescriptor(field);
+ if (field.getNumber() == 1) {
+ clearKey();
+ } else {
+ clearValue();
+ }
+ return this;
+ }
+
+ @Override
+ public Builder<K, V> setRepeatedField(FieldDescriptor field, int index,
+ Object value) {
+ throw new RuntimeException(
+ "There is no repeated field in a map entry message.");
+ }
+
+ @Override
+ public Builder<K, V> addRepeatedField(FieldDescriptor field, Object value) {
+ throw new RuntimeException(
+ "There is no repeated field in a map entry message.");
+ }
+
+ @Override
+ public Builder<K, V> setUnknownFields(UnknownFieldSet unknownFields) {
+ // Unknown fields are discarded for MapEntry message.
+ return this;
+ }
+
+ @Override
+ public MapEntry<K, V> getDefaultInstanceForType() {
+ return new MapEntry<K, V>(metadata, metadata.defaultKey, metadata.defaultValue);
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return MapEntry.isInitialized(metadata, value);
+ }
+
+ @Override
+ public Map<FieldDescriptor, Object> getAllFields() {
+ final TreeMap<FieldDescriptor, Object> result = new TreeMap<FieldDescriptor, Object>();
+ for (final FieldDescriptor field : metadata.descriptor.getFields()) {
+ if (hasField(field)) {
+ result.put(field, getField(field));
+ }
+ }
+ return Collections.unmodifiableMap(result);
+ }
+
+ @Override
+ public boolean hasField(FieldDescriptor field) {
+ checkFieldDescriptor(field);
+ return true;
+ }
+
+ @Override
+ public Object getField(FieldDescriptor field) {
+ checkFieldDescriptor(field);
+ Object result = field.getNumber() == 1 ? getKey() : getValue();
+ // Convert enums to EnumValueDescriptor.
+ if (field.getType() == FieldDescriptor.Type.ENUM) {
+ result = field.getEnumType().findValueByNumberCreatingIfUnknown((Integer) result);
+ }
+ return result;
+ }
+
+ @Override
+ public int getRepeatedFieldCount(FieldDescriptor field) {
+ throw new RuntimeException(
+ "There is no repeated field in a map entry message.");
+ }
+
+ @Override
+ public Object getRepeatedField(FieldDescriptor field, int index) {
+ throw new RuntimeException(
+ "There is no repeated field in a map entry message.");
+ }
+
+ @Override
+ public UnknownFieldSet getUnknownFields() {
+ return UnknownFieldSet.getDefaultInstance();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Builder<K, V> clone() {
+ return new Builder(metadata, key, value);
+ }
+ }
+
+ private static <V> boolean isInitialized(Metadata metadata, V value) {
+ if (metadata.valueType.getJavaType() == WireFormat.JavaType.MESSAGE) {
+ return ((MessageLite) value).isInitialized();
+ }
+ return true;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MapEntryLite.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MapEntryLite.java
new file mode 100644
index 0000000000..22aef8f93d
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MapEntryLite.java
@@ -0,0 +1,226 @@
+// 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.IOException;
+import java.util.AbstractMap;
+import java.util.Map;
+
+/**
+ * Implements the lite version of map entry messages.
+ *
+ * This class serves as an utility class to help do serialization/parsing of
+ * map entries. It's used in generated code and also in the full version
+ * MapEntry message.
+ *
+ * Protobuf internal. Users shouldn't use.
+ */
+public class MapEntryLite<K, V> {
+
+ static class Metadata<K, V> {
+ public final WireFormat.FieldType keyType;
+ public final K defaultKey;
+ public final WireFormat.FieldType valueType;
+ public final V defaultValue;
+
+ public Metadata(
+ WireFormat.FieldType keyType, K defaultKey,
+ WireFormat.FieldType valueType, V defaultValue) {
+ this.keyType = keyType;
+ this.defaultKey = defaultKey;
+ this.valueType = valueType;
+ this.defaultValue = defaultValue;
+ }
+ }
+
+ private static final int KEY_FIELD_NUMBER = 1;
+ private static final int VALUE_FIELD_NUMBER = 2;
+
+ private final Metadata<K, V> metadata;
+ private final K key;
+ private final V value;
+
+ /** Creates a default MapEntryLite message instance. */
+ private MapEntryLite(
+ WireFormat.FieldType keyType, K defaultKey,
+ WireFormat.FieldType valueType, V defaultValue) {
+ this.metadata = new Metadata<K, V>(keyType, defaultKey, valueType, defaultValue);
+ this.key = defaultKey;
+ this.value = defaultValue;
+ }
+
+ /** Creates a new MapEntryLite message. */
+ private MapEntryLite(Metadata<K, V> metadata, K key, V value) {
+ this.metadata = metadata;
+ this.key = key;
+ this.value = value;
+ }
+
+ public K getKey() {
+ return key;
+ }
+
+ public V getValue() {
+ return value;
+ }
+
+ /**
+ * Creates a default MapEntryLite message instance.
+ *
+ * This method is used by generated code to create the default instance for
+ * a map entry message. The created default instance should be used to create
+ * new map entry messages of the same type. For each map entry message, only
+ * one default instance should be created.
+ */
+ public static <K, V> MapEntryLite<K, V> newDefaultInstance(
+ WireFormat.FieldType keyType, K defaultKey,
+ WireFormat.FieldType valueType, V defaultValue) {
+ return new MapEntryLite<K, V>(
+ keyType, defaultKey, valueType, defaultValue);
+ }
+
+ static <K, V> void writeTo(CodedOutputStream output, Metadata<K, V> metadata, K key, V value)
+ throws IOException {
+ FieldSet.writeElement(output, metadata.keyType, KEY_FIELD_NUMBER, key);
+ FieldSet.writeElement(output, metadata.valueType, VALUE_FIELD_NUMBER, value);
+ }
+
+ static <K, V> int computeSerializedSize(Metadata<K, V> metadata, K key, V value) {
+ return FieldSet.computeElementSize(metadata.keyType, KEY_FIELD_NUMBER, key)
+ + FieldSet.computeElementSize(metadata.valueType, VALUE_FIELD_NUMBER, value);
+ }
+
+ @SuppressWarnings("unchecked")
+ static <T> T parseField(
+ CodedInputStream input, ExtensionRegistryLite extensionRegistry,
+ WireFormat.FieldType type, T value) throws IOException {
+ switch (type) {
+ case MESSAGE:
+ MessageLite.Builder subBuilder = ((MessageLite) value).toBuilder();
+ input.readMessage(subBuilder, extensionRegistry);
+ return (T) subBuilder.buildPartial();
+ case ENUM:
+ return (T) (java.lang.Integer) input.readEnum();
+ case GROUP:
+ throw new RuntimeException("Groups are not allowed in maps.");
+ default:
+ return (T) FieldSet.readPrimitiveField(input, type, true);
+ }
+ }
+
+ /**
+ * Serializes the provided key and value as though they were wrapped by a {@link MapEntryLite}
+ * to the output stream. This helper method avoids allocation of a {@link MapEntryLite}
+ * built with a key and value and is called from generated code directly.
+ */
+ public void serializeTo(CodedOutputStream output, int fieldNumber, K key, V value)
+ throws IOException {
+ output.writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ output.writeUInt32NoTag(computeSerializedSize(metadata, key, value));
+ writeTo(output, metadata, key, value);
+ }
+
+ /**
+ * Computes the message size for the provided key and value as though they were wrapped
+ * by a {@link MapEntryLite}. This helper method avoids allocation of a {@link MapEntryLite}
+ * built with a key and value and is called from generated code directly.
+ */
+ public int computeMessageSize(int fieldNumber, K key, V value) {
+ return CodedOutputStream.computeTagSize(fieldNumber)
+ + CodedOutputStream.computeLengthDelimitedFieldSize(
+ computeSerializedSize(metadata, key, value));
+ }
+
+ /**
+ * Parses an entry off of the input as a {@link Map.Entry}. This helper requires an allocation
+ * so using {@link #parseInto} is preferred if possible.
+ */
+ public Map.Entry<K, V> parseEntry(ByteString bytes, ExtensionRegistryLite extensionRegistry)
+ throws IOException {
+ return parseEntry(bytes.newCodedInput(), metadata, extensionRegistry);
+ }
+
+ static <K, V> Map.Entry<K, V> parseEntry(
+ CodedInputStream input, Metadata<K, V> metadata, ExtensionRegistryLite extensionRegistry)
+ throws IOException{
+ K key = metadata.defaultKey;
+ V value = metadata.defaultValue;
+ while (true) {
+ int tag = input.readTag();
+ if (tag == 0) {
+ break;
+ }
+ if (tag == WireFormat.makeTag(KEY_FIELD_NUMBER, metadata.keyType.getWireType())) {
+ key = parseField(input, extensionRegistry, metadata.keyType, key);
+ } else if (tag == WireFormat.makeTag(VALUE_FIELD_NUMBER, metadata.valueType.getWireType())) {
+ value = parseField(input, extensionRegistry, metadata.valueType, value);
+ } else {
+ if (!input.skipField(tag)) {
+ break;
+ }
+ }
+ }
+ return new AbstractMap.SimpleImmutableEntry<K, V>(key, value);
+ }
+
+ /**
+ * Parses an entry off of the input into the map. This helper avoids allocaton of a
+ * {@link MapEntryLite} by parsing directly into the provided {@link MapFieldLite}.
+ */
+ public void parseInto(
+ MapFieldLite<K, V> map, CodedInputStream input, ExtensionRegistryLite extensionRegistry)
+ throws IOException {
+ int length = input.readRawVarint32();
+ final int oldLimit = input.pushLimit(length);
+ K key = metadata.defaultKey;
+ V value = metadata.defaultValue;
+
+ while (true) {
+ int tag = input.readTag();
+ if (tag == 0) {
+ break;
+ }
+ if (tag == WireFormat.makeTag(KEY_FIELD_NUMBER, metadata.keyType.getWireType())) {
+ key = parseField(input, extensionRegistry, metadata.keyType, key);
+ } else if (tag == WireFormat.makeTag(VALUE_FIELD_NUMBER, metadata.valueType.getWireType())) {
+ value = parseField(input, extensionRegistry, metadata.valueType, value);
+ } else {
+ if (!input.skipField(tag)) {
+ break;
+ }
+ }
+ }
+
+ input.checkLastTagWas(0);
+ input.popLimit(oldLimit);
+ map.put(key, value);
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MapField.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MapField.java
new file mode 100644
index 0000000000..805defe29f
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MapField.java
@@ -0,0 +1,625 @@
+// 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.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Internal representation of map fields in generated messages.
+ *
+ * This class supports accessing the map field as a {@link Map} to be used in
+ * generated API and also supports accessing the field as a {@link List} to be
+ * used in reflection API. It keeps track of where the data is currently stored
+ * and do necessary conversions between map and list.
+ *
+ * This class is a protobuf implementation detail. Users shouldn't use this
+ * class directly.
+ *
+ * THREAD-SAFETY NOTE: Read-only access is thread-safe. Users can call getMap()
+ * and getList() concurrently in multiple threads. If write-access is needed,
+ * all access must be synchronized.
+ */
+public class MapField<K, V> implements MutabilityOracle {
+ /**
+ * Indicates where the data of this map field is currently stored.
+ *
+ * MAP: Data is stored in mapData.
+ * LIST: Data is stored in listData.
+ * BOTH: mapData and listData have the same data.
+ *
+ * When the map field is accessed (through generated API or reflection API),
+ * it will shift between these 3 modes:
+ *
+ * getMap() getList() getMutableMap() getMutableList()
+ * MAP MAP BOTH MAP LIST
+ * LIST BOTH LIST MAP LIST
+ * BOTH BOTH BOTH MAP LIST
+ *
+ * As the map field changes its mode, the list/map reference returned in a
+ * previous method call may be invalidated.
+ */
+ private enum StorageMode {MAP, LIST, BOTH}
+
+ private volatile boolean isMutable;
+ private volatile StorageMode mode;
+ private MutatabilityAwareMap<K, V> mapData;
+ private List<Message> listData;
+
+ // Convert between a map entry Message and a key-value pair.
+ private static interface Converter<K, V> {
+ Message convertKeyAndValueToMessage(K key, V value);
+ void convertMessageToKeyAndValue(Message message, Map<K, V> map);
+
+ Message getMessageDefaultInstance();
+ }
+
+ private static class ImmutableMessageConverter<K, V> implements Converter<K, V> {
+ private final MapEntry<K, V> defaultEntry;
+ public ImmutableMessageConverter(MapEntry<K, V> defaultEntry) {
+ this.defaultEntry = defaultEntry;
+ }
+
+ @Override
+ public Message convertKeyAndValueToMessage(K key, V value) {
+ return defaultEntry.newBuilderForType().setKey(key).setValue(value).buildPartial();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void convertMessageToKeyAndValue(Message message, Map<K, V> map) {
+ MapEntry<K, V> entry = (MapEntry<K, V>) message;
+ map.put(entry.getKey(), entry.getValue());
+ }
+
+ @Override
+ public Message getMessageDefaultInstance() {
+ return defaultEntry;
+ }
+ }
+
+
+ private final Converter<K, V> converter;
+
+ private MapField(
+ Converter<K, V> converter,
+ StorageMode mode,
+ Map<K, V> mapData) {
+ this.converter = converter;
+ this.isMutable = true;
+ this.mode = mode;
+ this.mapData = new MutatabilityAwareMap<K, V>(this, mapData);
+ this.listData = null;
+ }
+
+ private MapField(
+ MapEntry<K, V> defaultEntry,
+ StorageMode mode,
+ Map<K, V> mapData) {
+ this(new ImmutableMessageConverter<K, V>(defaultEntry), mode, mapData);
+ }
+
+
+ /** Returns an immutable empty MapField. */
+ public static <K, V> MapField<K, V> emptyMapField(
+ MapEntry<K, V> defaultEntry) {
+ return new MapField<K, V>(
+ defaultEntry, StorageMode.MAP, Collections.<K, V>emptyMap());
+ }
+
+
+ /** Creates a new mutable empty MapField. */
+ public static <K, V> MapField<K, V> newMapField(MapEntry<K, V> defaultEntry) {
+ return new MapField<K, V>(
+ defaultEntry, StorageMode.MAP, new LinkedHashMap<K, V>());
+ }
+
+
+ private Message convertKeyAndValueToMessage(K key, V value) {
+ return converter.convertKeyAndValueToMessage(key, value);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void convertMessageToKeyAndValue(Message message, Map<K, V> map) {
+ converter.convertMessageToKeyAndValue(message, map);
+ }
+
+ private List<Message> convertMapToList(MutatabilityAwareMap<K, V> mapData) {
+ List<Message> listData = new ArrayList<Message>();
+ for (Map.Entry<K, V> entry : mapData.entrySet()) {
+ listData.add(
+ convertKeyAndValueToMessage(
+ entry.getKey(), entry.getValue()));
+ }
+ return listData;
+ }
+
+ private MutatabilityAwareMap<K, V> convertListToMap(List<Message> listData) {
+ Map<K, V> mapData = new LinkedHashMap<K, V>();
+ for (Message item : listData) {
+ convertMessageToKeyAndValue(item, mapData);
+ }
+ return new MutatabilityAwareMap<K, V>(this, mapData);
+ }
+
+ /** Returns the content of this MapField as a read-only Map. */
+ public Map<K, V> getMap() {
+ if (mode == StorageMode.LIST) {
+ synchronized (this) {
+ if (mode == StorageMode.LIST) {
+ mapData = convertListToMap(listData);
+ mode = StorageMode.BOTH;
+ }
+ }
+ }
+ return Collections.unmodifiableMap(mapData);
+ }
+
+ /** Gets a mutable Map view of this MapField. */
+ public Map<K, V> getMutableMap() {
+ if (mode != StorageMode.MAP) {
+ if (mode == StorageMode.LIST) {
+ mapData = convertListToMap(listData);
+ }
+ listData = null;
+ mode = StorageMode.MAP;
+ }
+ return mapData;
+ }
+
+ public void mergeFrom(MapField<K, V> other) {
+ getMutableMap().putAll(MapFieldLite.copy(other.getMap()));
+ }
+
+ public void clear() {
+ mapData = new MutatabilityAwareMap<K, V>(this, new LinkedHashMap<K, V>());
+ mode = StorageMode.MAP;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public boolean equals(Object object) {
+ if (!(object instanceof MapField)) {
+ return false;
+ }
+ MapField<K, V> other = (MapField<K, V>) object;
+ return MapFieldLite.<K, V>equals(getMap(), other.getMap());
+ }
+
+ @Override
+ public int hashCode() {
+ return MapFieldLite.<K, V>calculateHashCodeForMap(getMap());
+ }
+
+ /** Returns a deep copy of this MapField. */
+ public MapField<K, V> copy() {
+ return new MapField<K, V>(
+ converter, StorageMode.MAP, MapFieldLite.copy(getMap()));
+ }
+
+ /** Gets the content of this MapField as a read-only List. */
+ List<Message> getList() {
+ if (mode == StorageMode.MAP) {
+ synchronized (this) {
+ if (mode == StorageMode.MAP) {
+ listData = convertMapToList(mapData);
+ mode = StorageMode.BOTH;
+ }
+ }
+ }
+ return Collections.unmodifiableList(listData);
+ }
+
+ /** Gets a mutable List view of this MapField. */
+ List<Message> getMutableList() {
+ if (mode != StorageMode.LIST) {
+ if (mode == StorageMode.MAP) {
+ listData = convertMapToList(mapData);
+ }
+ mapData = null;
+ mode = StorageMode.LIST;
+ }
+ return listData;
+ }
+
+ /**
+ * Gets the default instance of the message stored in the list view of this
+ * map field.
+ */
+ Message getMapEntryMessageDefaultInstance() {
+ return converter.getMessageDefaultInstance();
+ }
+
+ /**
+ * Makes this list immutable. All subsequent modifications will throw an
+ * {@link UnsupportedOperationException}.
+ */
+ public void makeImmutable() {
+ isMutable = false;
+ }
+
+ /**
+ * Returns whether this field can be modified.
+ */
+ public boolean isMutable() {
+ return isMutable;
+ }
+
+ /* (non-Javadoc)
+ * @see com.google.protobuf.MutabilityOracle#ensureMutable()
+ */
+ @Override
+ public void ensureMutable() {
+ if (!isMutable()) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ /**
+ * An internal map that checks for mutability before delegating.
+ */
+ private static class MutatabilityAwareMap<K, V> implements Map<K, V> {
+ private final MutabilityOracle mutabilityOracle;
+ private final Map<K, V> delegate;
+
+ MutatabilityAwareMap(MutabilityOracle mutabilityOracle, Map<K, V> delegate) {
+ this.mutabilityOracle = mutabilityOracle;
+ this.delegate = delegate;
+ }
+
+ @Override
+ public int size() {
+ return delegate.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return delegate.isEmpty();
+ }
+
+ @Override
+ public boolean containsKey(Object key) {
+ return delegate.containsKey(key);
+ }
+
+ @Override
+ public boolean containsValue(Object value) {
+ return delegate.containsValue(value);
+ }
+
+ @Override
+ public V get(Object key) {
+ return delegate.get(key);
+ }
+
+ @Override
+ public V put(K key, V value) {
+ mutabilityOracle.ensureMutable();
+ return delegate.put(key, value);
+ }
+
+ @Override
+ public V remove(Object key) {
+ mutabilityOracle.ensureMutable();
+ return delegate.remove(key);
+ }
+
+ @Override
+ public void putAll(Map<? extends K, ? extends V> m) {
+ mutabilityOracle.ensureMutable();
+ delegate.putAll(m);
+ }
+
+ @Override
+ public void clear() {
+ mutabilityOracle.ensureMutable();
+ delegate.clear();
+ }
+
+ @Override
+ public Set<K> keySet() {
+ return new MutatabilityAwareSet<K>(mutabilityOracle, delegate.keySet());
+ }
+
+ @Override
+ public Collection<V> values() {
+ return new MutatabilityAwareCollection<V>(mutabilityOracle, delegate.values());
+ }
+
+ @Override
+ public Set<java.util.Map.Entry<K, V>> entrySet() {
+ return new MutatabilityAwareSet<Entry<K, V>>(mutabilityOracle, delegate.entrySet());
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return delegate.equals(o);
+ }
+
+ @Override
+ public int hashCode() {
+ return delegate.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return delegate.toString();
+ }
+
+ /**
+ * An internal collection that checks for mutability before delegating.
+ */
+ private static class MutatabilityAwareCollection<E> implements Collection<E> {
+ private final MutabilityOracle mutabilityOracle;
+ private final Collection<E> delegate;
+
+ MutatabilityAwareCollection(MutabilityOracle mutabilityOracle, Collection<E> delegate) {
+ this.mutabilityOracle = mutabilityOracle;
+ this.delegate = delegate;
+ }
+
+ @Override
+ public int size() {
+ return delegate.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return delegate.isEmpty();
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ return delegate.contains(o);
+ }
+
+ @Override
+ public Iterator<E> iterator() {
+ return new MutatabilityAwareIterator<E>(mutabilityOracle, delegate.iterator());
+ }
+
+ @Override
+ public Object[] toArray() {
+ return delegate.toArray();
+ }
+
+ @Override
+ public <T> T[] toArray(T[] a) {
+ return delegate.toArray(a);
+ }
+
+ @Override
+ public boolean add(E e) {
+ // Unsupported operation in the delegate.
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ mutabilityOracle.ensureMutable();
+ return delegate.remove(o);
+ }
+
+ @Override
+ public boolean containsAll(Collection<?> c) {
+ return delegate.containsAll(c);
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends E> c) {
+ // Unsupported operation in the delegate.
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> c) {
+ mutabilityOracle.ensureMutable();
+ return delegate.removeAll(c);
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> c) {
+ mutabilityOracle.ensureMutable();
+ return delegate.retainAll(c);
+ }
+
+ @Override
+ public void clear() {
+ mutabilityOracle.ensureMutable();
+ delegate.clear();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return delegate.equals(o);
+ }
+
+ @Override
+ public int hashCode() {
+ return delegate.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return delegate.toString();
+ }
+ }
+
+ /**
+ * An internal set that checks for mutability before delegating.
+ */
+ private static class MutatabilityAwareSet<E> implements Set<E> {
+ private final MutabilityOracle mutabilityOracle;
+ private final Set<E> delegate;
+
+ MutatabilityAwareSet(MutabilityOracle mutabilityOracle, Set<E> delegate) {
+ this.mutabilityOracle = mutabilityOracle;
+ this.delegate = delegate;
+ }
+
+ @Override
+ public int size() {
+ return delegate.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return delegate.isEmpty();
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ return delegate.contains(o);
+ }
+
+ @Override
+ public Iterator<E> iterator() {
+ return new MutatabilityAwareIterator<E>(mutabilityOracle, delegate.iterator());
+ }
+
+ @Override
+ public Object[] toArray() {
+ return delegate.toArray();
+ }
+
+ @Override
+ public <T> T[] toArray(T[] a) {
+ return delegate.toArray(a);
+ }
+
+ @Override
+ public boolean add(E e) {
+ mutabilityOracle.ensureMutable();
+ return delegate.add(e);
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ mutabilityOracle.ensureMutable();
+ return delegate.remove(o);
+ }
+
+ @Override
+ public boolean containsAll(Collection<?> c) {
+ return delegate.containsAll(c);
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends E> c) {
+ mutabilityOracle.ensureMutable();
+ return delegate.addAll(c);
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> c) {
+ mutabilityOracle.ensureMutable();
+ return delegate.retainAll(c);
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> c) {
+ mutabilityOracle.ensureMutable();
+ return delegate.removeAll(c);
+ }
+
+ @Override
+ public void clear() {
+ mutabilityOracle.ensureMutable();
+ delegate.clear();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return delegate.equals(o);
+ }
+
+ @Override
+ public int hashCode() {
+ return delegate.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return delegate.toString();
+ }
+ }
+
+ /**
+ * An internal iterator that checks for mutability before delegating.
+ */
+ private static class MutatabilityAwareIterator<E> implements Iterator<E> {
+ private final MutabilityOracle mutabilityOracle;
+ private final Iterator<E> delegate;
+
+ MutatabilityAwareIterator(MutabilityOracle mutabilityOracle, Iterator<E> delegate) {
+ this.mutabilityOracle = mutabilityOracle;
+ this.delegate = delegate;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return delegate.hasNext();
+ }
+
+ @Override
+ public E next() {
+ return delegate.next();
+ }
+
+ @Override
+ public void remove() {
+ mutabilityOracle.ensureMutable();
+ delegate.remove();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return delegate.equals(obj);
+ }
+
+ @Override
+ public int hashCode() {
+ return delegate.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return delegate.toString();
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MapFieldLite.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MapFieldLite.java
new file mode 100644
index 0000000000..4264027911
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MapFieldLite.java
@@ -0,0 +1,224 @@
+// 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.EnumLite;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Internal representation of map fields in generated lite-runtime messages.
+ *
+ * This class is a protobuf implementation detail. Users shouldn't use this
+ * class directly.
+ */
+public final class MapFieldLite<K, V> extends LinkedHashMap<K, V> {
+
+ private boolean isMutable;
+
+ private MapFieldLite() {
+ this.isMutable = true;
+ }
+
+ private MapFieldLite(Map<K, V> mapData) {
+ super(mapData);
+ this.isMutable = true;
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ private static final MapFieldLite EMPTY_MAP_FIELD = new MapFieldLite();
+ static {
+ EMPTY_MAP_FIELD.makeImmutable();
+ }
+
+ /** Returns an singleton immutable empty MapFieldLite instance. */
+ @SuppressWarnings({"unchecked", "cast"})
+ public static <K, V> MapFieldLite<K, V> emptyMapField() {
+ return (MapFieldLite<K, V>) EMPTY_MAP_FIELD;
+ }
+
+ public void mergeFrom(MapFieldLite<K, V> other) {
+ ensureMutable();
+ if (!other.isEmpty()) {
+ putAll(other);
+ }
+ }
+
+ @SuppressWarnings({"unchecked", "cast"})
+ @Override public Set<Map.Entry<K, V>> entrySet() {
+ return isEmpty() ? Collections.<Map.Entry<K, V>>emptySet() : super.entrySet();
+ }
+
+ @Override public void clear() {
+ ensureMutable();
+ super.clear();
+ }
+
+ @Override public V put(K key, V value) {
+ ensureMutable();
+ return super.put(key, value);
+ }
+
+ public V put(Map.Entry<K, V> entry) {
+ return put(entry.getKey(), entry.getValue());
+ }
+
+ @Override public void putAll(Map<? extends K, ? extends V> m) {
+ ensureMutable();
+ super.putAll(m);
+ }
+
+ @Override public V remove(Object key) {
+ ensureMutable();
+ return super.remove(key);
+ }
+
+ private static boolean equals(Object a, Object b) {
+ if (a instanceof byte[] && b instanceof byte[]) {
+ return Arrays.equals((byte[]) a, (byte[]) b);
+ }
+ return a.equals(b);
+ }
+
+ /**
+ * Checks whether two {@link Map}s are equal. We don't use the default equals
+ * method of {@link Map} because it compares by identity not by content for
+ * byte arrays.
+ */
+ static <K, V> boolean equals(Map<K, V> a, Map<K, V> b) {
+ if (a == b) {
+ return true;
+ }
+ if (a.size() != b.size()) {
+ return false;
+ }
+ for (Map.Entry<K, V> entry : a.entrySet()) {
+ if (!b.containsKey(entry.getKey())) {
+ return false;
+ }
+ if (!equals(entry.getValue(), b.get(entry.getKey()))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Checks whether two map fields are equal.
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public boolean equals(Object object) {
+ return (object instanceof Map) && equals(this, (Map<K, V>) object);
+ }
+
+ private static int calculateHashCodeForObject(Object a) {
+ if (a instanceof byte[]) {
+ return Internal.hashCode((byte[]) a);
+ }
+ // Enums should be stored as integers internally.
+ if (a instanceof EnumLite) {
+ throw new UnsupportedOperationException();
+ }
+ return a.hashCode();
+ }
+
+ /**
+ * Calculates the hash code for a {@link Map}. We don't use the default hash
+ * code method of {@link Map} because for byte arrays and protobuf enums it
+ * use {@link Object#hashCode()}.
+ */
+ static <K, V> int calculateHashCodeForMap(Map<K, V> a) {
+ int result = 0;
+ for (Map.Entry<K, V> entry : a.entrySet()) {
+ result += calculateHashCodeForObject(entry.getKey())
+ ^ calculateHashCodeForObject(entry.getValue());
+ }
+ return result;
+ }
+
+ @Override
+ public int hashCode() {
+ return calculateHashCodeForMap(this);
+ }
+
+ private static Object copy(Object object) {
+ if (object instanceof byte[]) {
+ byte[] data = (byte[]) object;
+ return Arrays.copyOf(data, data.length);
+ }
+ return object;
+ }
+
+ /**
+ * Makes a deep copy of a {@link Map}. Immutable objects in the map will be
+ * shared (e.g., integers, strings, immutable messages) and mutable ones will
+ * have a copy (e.g., byte arrays, mutable messages).
+ */
+ @SuppressWarnings("unchecked")
+ static <K, V> Map<K, V> copy(Map<K, V> map) {
+ Map<K, V> result = new LinkedHashMap<K, V>();
+ for (Map.Entry<K, V> entry : map.entrySet()) {
+ result.put(entry.getKey(), (V) copy(entry.getValue()));
+ }
+ return result;
+ }
+
+ /** Returns a deep copy of this map field. */
+ public MapFieldLite<K, V> mutableCopy() {
+ return isEmpty() ? new MapFieldLite<K, V>() : new MapFieldLite<K, V>(this);
+ }
+
+ /**
+ * Makes this field immutable. All subsequent modifications will throw an
+ * {@link UnsupportedOperationException}.
+ */
+ public void makeImmutable() {
+ isMutable = false;
+ }
+
+ /**
+ * Returns whether this field can be modified.
+ */
+ public boolean isMutable() {
+ return isMutable;
+ }
+
+ private void ensureMutable() {
+ if (!isMutable()) {
+ throw new UnsupportedOperationException();
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Message.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Message.java
new file mode 100644
index 0000000000..94590fb91b
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Message.java
@@ -0,0 +1,292 @@
+// 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.
+
+// TODO(kenton): Use generics? E.g. Builder<BuilderType extends Builder>, then
+// mergeFrom*() could return BuilderType for better type-safety.
+
+package com.google.protobuf;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+/**
+ * Abstract interface implemented by Protocol Message objects.
+ * <p>
+ * See also {@link MessageLite}, which defines most of the methods that typical
+ * users care about. {@link Message} adds to it methods that are not available
+ * in the "lite" runtime. The biggest added features are introspection and
+ * reflection -- i.e., getting descriptors for the message type and accessing
+ * the field values dynamically.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public interface Message extends MessageLite, MessageOrBuilder {
+
+ // (From MessageLite, re-declared here only for return type covariance.)
+ @Override
+ Parser<? extends Message> getParserForType();
+
+
+ // -----------------------------------------------------------------
+ // Comparison and hashing
+
+ /**
+ * Compares the specified object with this message for equality. Returns
+ * {@code true} if the given object is a message of the same type (as
+ * defined by {@code getDescriptorForType()}) and has identical values for
+ * all of its fields. Subclasses must implement this; inheriting
+ * {@code Object.equals()} is incorrect.
+ *
+ * @param other object to be compared for equality with this message
+ * @return {@code true} if the specified object is equal to this message
+ */
+ @Override
+ boolean equals(Object other);
+
+ /**
+ * Returns the hash code value for this message. The hash code of a message
+ * should mix the message's type (object identity of the descriptor) with its
+ * contents (known and unknown field values). Subclasses must implement this;
+ * inheriting {@code Object.hashCode()} is incorrect.
+ *
+ * @return the hash code value for this message
+ * @see Map#hashCode()
+ */
+ @Override
+ int hashCode();
+
+ // -----------------------------------------------------------------
+ // Convenience methods.
+
+ /**
+ * Converts the message to a string in protocol buffer text format. This is
+ * just a trivial wrapper around {@link
+ * TextFormat#printToString(MessageOrBuilder)}.
+ */
+ @Override
+ String toString();
+
+ // =================================================================
+ // Builders
+
+ // (From MessageLite, re-declared here only for return type covariance.)
+ @Override
+ Builder newBuilderForType();
+
+ @Override
+ Builder toBuilder();
+
+ /**
+ * Abstract interface implemented by Protocol Message builders.
+ */
+ interface Builder extends MessageLite.Builder, MessageOrBuilder {
+ // (From MessageLite.Builder, re-declared here only for return type
+ // covariance.)
+ @Override
+ Builder clear();
+
+ /**
+ * Merge {@code other} into the message being built. {@code other} must
+ * have the exact same type as {@code this} (i.e.
+ * {@code getDescriptorForType() == other.getDescriptorForType()}).
+ *
+ * Merging occurs as follows. For each field:<br>
+ * * For singular primitive fields, if the field is set in {@code other},
+ * then {@code other}'s value overwrites the value in this message.<br>
+ * * For singular message fields, if the field is set in {@code other},
+ * it is merged into the corresponding sub-message of this message
+ * using the same merging rules.<br>
+ * * For repeated fields, the elements in {@code other} are concatenated
+ * with the elements in this message.
+ * * For oneof groups, if the other message has one of the fields set,
+ * the group of this message is cleared and replaced by the field
+ * of the other message, so that the oneof constraint is preserved.
+ *
+ * This is equivalent to the {@code Message::MergeFrom} method in C++.
+ */
+ Builder mergeFrom(Message other);
+
+ // (From MessageLite.Builder, re-declared here only for return type
+ // covariance.)
+ @Override
+ Message build();
+
+ @Override
+ Message buildPartial();
+
+ @Override
+ Builder clone();
+
+ @Override
+ Builder mergeFrom(CodedInputStream input) throws IOException;
+
+ @Override
+ Builder mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry)
+ throws IOException;
+
+ /**
+ * Get the message's type's descriptor.
+ * See {@link Message#getDescriptorForType()}.
+ */
+ @Override
+ Descriptors.Descriptor getDescriptorForType();
+
+ /**
+ * Create a Builder for messages of the appropriate type for the given
+ * field. Messages built with this can then be passed to setField(),
+ * setRepeatedField(), or addRepeatedField().
+ */
+ Builder newBuilderForField(Descriptors.FieldDescriptor field);
+
+ /**
+ * Get a nested builder instance for the given field.
+ * <p>
+ * Normally, we hold a reference to the immutable message object for the
+ * message type field. Some implementations(the generated message builders),
+ * however, can also hold a reference to the builder object (a nested
+ * builder) for the field.
+ * <p>
+ * If the field is already backed up by a nested builder, the nested builder
+ * will be returned. Otherwise, a new field builder will be created and
+ * returned. The original message field (if exist) will be merged into the
+ * field builder, which will then be nested into its parent builder.
+ * <p>
+ * NOTE: implementations that do not support nested builders will throw
+ * <code>UnsupportedOperationException</code>.
+ */
+ Builder getFieldBuilder(Descriptors.FieldDescriptor field);
+
+ /**
+ * Get a nested builder instance for the given repeated field instance.
+ * <p>
+ * Normally, we hold a reference to the immutable message object for the
+ * message type field. Some implementations(the generated message builders),
+ * however, can also hold a reference to the builder object (a nested
+ * builder) for the field.
+ * <p>
+ * If the field is already backed up by a nested builder, the nested builder
+ * will be returned. Otherwise, a new field builder will be created and
+ * returned. The original message field (if exist) will be merged into the
+ * field builder, which will then be nested into its parent builder.
+ * <p>
+ * NOTE: implementations that do not support nested builders will throw
+ * <code>UnsupportedOperationException</code>.
+ */
+ Builder getRepeatedFieldBuilder(Descriptors.FieldDescriptor field,
+ int index);
+
+ /**
+ * Sets a field to the given value. The value must be of the correct type
+ * for this field, i.e. the same type that
+ * {@link Message#getField(Descriptors.FieldDescriptor)} would return.
+ */
+ Builder setField(Descriptors.FieldDescriptor field, Object value);
+
+ /**
+ * Clears the field. This is exactly equivalent to calling the generated
+ * "clear" accessor method corresponding to the field.
+ */
+ Builder clearField(Descriptors.FieldDescriptor field);
+
+ /**
+ * Clears the oneof. This is exactly equivalent to calling the generated
+ * "clear" accessor method corresponding to the oneof.
+ */
+ Builder clearOneof(Descriptors.OneofDescriptor oneof);
+
+ /**
+ * Sets an element of a repeated field to the given value. The value must
+ * be of the correct type for this field, i.e. the same type that
+ * {@link Message#getRepeatedField(Descriptors.FieldDescriptor,int)} would
+ * return.
+ * @throws IllegalArgumentException The field is not a repeated field, or
+ * {@code field.getContainingType() != getDescriptorForType()}.
+ */
+ Builder setRepeatedField(Descriptors.FieldDescriptor field,
+ int index, Object value);
+
+ /**
+ * Like {@code setRepeatedField}, but appends the value as a new element.
+ * @throws IllegalArgumentException The field is not a repeated field, or
+ * {@code field.getContainingType() != getDescriptorForType()}.
+ */
+ Builder addRepeatedField(Descriptors.FieldDescriptor field, Object value);
+
+ /** Set the {@link UnknownFieldSet} for this message. */
+ Builder setUnknownFields(UnknownFieldSet unknownFields);
+
+ /**
+ * Merge some unknown fields into the {@link UnknownFieldSet} for this
+ * message.
+ */
+ Builder mergeUnknownFields(UnknownFieldSet unknownFields);
+
+ // ---------------------------------------------------------------
+ // Convenience methods.
+
+ // (From MessageLite.Builder, re-declared here only for return type
+ // covariance.)
+ @Override
+ Builder mergeFrom(ByteString data) throws InvalidProtocolBufferException;
+
+ @Override
+ Builder mergeFrom(ByteString data, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+
+ @Override
+ Builder mergeFrom(byte[] data) throws InvalidProtocolBufferException;
+
+ @Override
+ Builder mergeFrom(byte[] data, int off, int len) throws InvalidProtocolBufferException;
+
+ @Override
+ Builder mergeFrom(byte[] data, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+
+ @Override
+ Builder mergeFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+
+ @Override
+ Builder mergeFrom(InputStream input) throws IOException;
+
+ @Override
+ Builder mergeFrom(InputStream input, ExtensionRegistryLite extensionRegistry)
+ throws IOException;
+
+ @Override
+ boolean mergeDelimitedFrom(InputStream input) throws IOException;
+
+ @Override
+ boolean mergeDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry)
+ throws IOException;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageLite.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageLite.java
new file mode 100644
index 0000000000..88f531df3e
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageLite.java
@@ -0,0 +1,341 @@
+// 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.
+
+// TODO(kenton): Use generics? E.g. Builder<BuilderType extends Builder>, then
+// mergeFrom*() could return BuilderType for better type-safety.
+
+package com.google.protobuf;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Abstract interface implemented by Protocol Message objects.
+ *
+ * <p>This interface is implemented by all protocol message objects. Non-lite
+ * messages additionally implement the Message interface, which is a subclass
+ * of MessageLite. Use MessageLite instead when you only need the subset of
+ * features which it supports -- namely, nothing that uses descriptors or
+ * reflection. You can instruct the protocol compiler to generate classes
+ * which implement only MessageLite, not the full Message interface, by adding
+ * the follow line to the .proto file:
+ * <pre>
+ * option optimize_for = LITE_RUNTIME;
+ * </pre>
+ *
+ * <p>This is particularly useful on resource-constrained systems where the
+ * full protocol buffers runtime library is too big.
+ *
+ * <p>Note that on non-constrained systems (e.g. servers) when you need to link
+ * in lots of protocol definitions, a better way to reduce total code footprint
+ * is to use {@code optimize_for = CODE_SIZE}. This will make the generated
+ * code smaller while still supporting all the same features (at the expense of
+ * speed). {@code optimize_for = LITE_RUNTIME} is best when you only have a
+ * small number of message types linked into your binary, in which case the
+ * size of the protocol buffers runtime itself is the biggest problem.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public interface MessageLite extends MessageLiteOrBuilder {
+
+
+ /**
+ * Serializes the message and writes it to {@code output}. This does not
+ * flush or close the stream.
+ */
+ void writeTo(CodedOutputStream output) throws IOException;
+
+ /**
+ * Get the number of bytes required to encode this message. The result
+ * is only computed on the first call and memoized after that.
+ */
+ int getSerializedSize();
+
+
+ /**
+ * Gets the parser for a message of the same type as this message.
+ */
+ Parser<? extends MessageLite> getParserForType();
+
+ // -----------------------------------------------------------------
+ // Convenience methods.
+
+ /**
+ * Serializes the message to a {@code ByteString} and returns it. This is
+ * just a trivial wrapper around
+ * {@link #writeTo(CodedOutputStream)}.
+ */
+ ByteString toByteString();
+
+ /**
+ * Serializes the message to a {@code byte} array and returns it. This is
+ * just a trivial wrapper around
+ * {@link #writeTo(CodedOutputStream)}.
+ */
+ byte[] toByteArray();
+
+ /**
+ * Serializes the message and writes it to {@code output}. This is just a
+ * trivial wrapper around {@link #writeTo(CodedOutputStream)}. This does
+ * not flush or close the stream.
+ * <p>
+ * NOTE: Protocol Buffers are not self-delimiting. Therefore, if you write
+ * any more data to the stream after the message, you must somehow ensure
+ * that the parser on the receiving end does not interpret this as being
+ * part of the protocol message. This can be done e.g. by writing the size
+ * of the message before the data, then making sure to limit the input to
+ * that size on the receiving end (e.g. by wrapping the InputStream in one
+ * which limits the input). Alternatively, just use
+ * {@link #writeDelimitedTo(OutputStream)}.
+ */
+ void writeTo(OutputStream output) throws IOException;
+
+ /**
+ * Like {@link #writeTo(OutputStream)}, but writes the size of the message
+ * as a varint before writing the data. This allows more data to be written
+ * to the stream after the message without the need to delimit the message
+ * data yourself. Use {@link Builder#mergeDelimitedFrom(InputStream)} (or
+ * the static method {@code YourMessageType.parseDelimitedFrom(InputStream)})
+ * to parse messages written by this method.
+ */
+ void writeDelimitedTo(OutputStream output) throws IOException;
+
+
+ // =================================================================
+ // Builders
+
+ /**
+ * Constructs a new builder for a message of the same type as this message.
+ */
+ Builder newBuilderForType();
+
+ /**
+ * Constructs a builder initialized with the current message. Use this to
+ * derive a new message from the current one.
+ */
+ Builder toBuilder();
+
+ /**
+ * Abstract interface implemented by Protocol Message builders.
+ */
+ interface Builder extends MessageLiteOrBuilder, Cloneable {
+ /** Resets all fields to their default values. */
+ Builder clear();
+
+ /**
+ * Constructs the message based on the state of the Builder. Subsequent
+ * changes to the Builder will not affect the returned message.
+ * @throws UninitializedMessageException The message is missing one or more
+ * required fields (i.e. {@link #isInitialized()} returns false).
+ * Use {@link #buildPartial()} to bypass this check.
+ */
+ MessageLite build();
+
+ /**
+ * Like {@link #build()}, but does not throw an exception if the message
+ * is missing required fields. Instead, a partial message is returned.
+ * Subsequent changes to the Builder will not affect the returned message.
+ */
+ MessageLite buildPartial();
+
+ /**
+ * Clones the Builder.
+ * @see Object#clone()
+ */
+ Builder clone();
+
+ /**
+ * Parses a message of this type from the input and merges it with this
+ * message.
+ *
+ * <p>Warning: This does not verify that all required fields are present in
+ * the input message. If you call {@link #build()} without setting all
+ * required fields, it will throw an {@link UninitializedMessageException},
+ * which is a {@code RuntimeException} and thus might not be caught. There
+ * are a few good ways to deal with this:
+ * <ul>
+ * <li>Call {@link #isInitialized()} to verify that all required fields
+ * are set before building.
+ * <li>Use {@code buildPartial()} to build, which ignores missing
+ * required fields.
+ * </ul>
+ *
+ * <p>Note: The caller should call
+ * {@link CodedInputStream#checkLastTagWas(int)} after calling this to
+ * verify that the last tag seen was the appropriate end-group tag,
+ * or zero for EOF.
+ */
+ Builder mergeFrom(CodedInputStream input) throws IOException;
+
+ /**
+ * Like {@link Builder#mergeFrom(CodedInputStream)}, but also
+ * parses extensions. The extensions that you want to be able to parse
+ * must be registered in {@code extensionRegistry}. Extensions not in
+ * the registry will be treated as unknown fields.
+ */
+ Builder mergeFrom(CodedInputStream input,
+ ExtensionRegistryLite extensionRegistry)
+ throws IOException;
+
+ // ---------------------------------------------------------------
+ // Convenience methods.
+
+ /**
+ * Parse {@code data} as a message of this type and merge it with the
+ * message being built. This is just a small wrapper around
+ * {@link #mergeFrom(CodedInputStream)}.
+ *
+ * @return this
+ */
+ Builder mergeFrom(ByteString data) throws InvalidProtocolBufferException;
+
+ /**
+ * Parse {@code data} as a message of this type and merge it with the
+ * message being built. This is just a small wrapper around
+ * {@link #mergeFrom(CodedInputStream,ExtensionRegistryLite)}.
+ *
+ * @return this
+ */
+ Builder mergeFrom(ByteString data,
+ ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Parse {@code data} as a message of this type and merge it with the
+ * message being built. This is just a small wrapper around
+ * {@link #mergeFrom(CodedInputStream)}.
+ *
+ * @return this
+ */
+ Builder mergeFrom(byte[] data) throws InvalidProtocolBufferException;
+
+ /**
+ * Parse {@code data} as a message of this type and merge it with the
+ * message being built. This is just a small wrapper around
+ * {@link #mergeFrom(CodedInputStream)}.
+ *
+ * @return this
+ */
+ Builder mergeFrom(byte[] data, int off, int len)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Parse {@code data} as a message of this type and merge it with the
+ * message being built. This is just a small wrapper around
+ * {@link #mergeFrom(CodedInputStream,ExtensionRegistryLite)}.
+ *
+ * @return this
+ */
+ Builder mergeFrom(byte[] data,
+ ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Parse {@code data} as a message of this type and merge it with the
+ * message being built. This is just a small wrapper around
+ * {@link #mergeFrom(CodedInputStream,ExtensionRegistryLite)}.
+ *
+ * @return this
+ */
+ Builder mergeFrom(byte[] data, int off, int len,
+ ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Parse a message of this type from {@code input} and merge it with the
+ * message being built. This is just a small wrapper around
+ * {@link #mergeFrom(CodedInputStream)}. Note that this method always
+ * reads the <i>entire</i> input (unless it throws an exception). If you
+ * want it to stop earlier, you will need to wrap your input in some
+ * wrapper stream that limits reading. Or, use
+ * {@link MessageLite#writeDelimitedTo(OutputStream)} to write your message
+ * and {@link #mergeDelimitedFrom(InputStream)} to read it.
+ * <p>
+ * Despite usually reading the entire input, this does not close the stream.
+ *
+ * @return this
+ */
+ Builder mergeFrom(InputStream input) throws IOException;
+
+ /**
+ * Parse a message of this type from {@code input} and merge it with the
+ * message being built. This is just a small wrapper around
+ * {@link #mergeFrom(CodedInputStream,ExtensionRegistryLite)}.
+ *
+ * @return this
+ */
+ Builder mergeFrom(InputStream input,
+ ExtensionRegistryLite extensionRegistry)
+ throws IOException;
+
+ /**
+ * Merge {@code other} into the message being built. {@code other} must
+ * have the exact same type as {@code this} (i.e.
+ * {@code getClass().equals(getDefaultInstanceForType().getClass())}).
+ *
+ * Merging occurs as follows. For each field:<br>
+ * * For singular primitive fields, if the field is set in {@code other},
+ * then {@code other}'s value overwrites the value in this message.<br>
+ * * For singular message fields, if the field is set in {@code other},
+ * it is merged into the corresponding sub-message of this message
+ * using the same merging rules.<br>
+ * * For repeated fields, the elements in {@code other} are concatenated
+ * with the elements in this message.
+ * * For oneof groups, if the other message has one of the fields set,
+ * the group of this message is cleared and replaced by the field
+ * of the other message, so that the oneof constraint is preserved.
+ *
+ * This is equivalent to the {@code Message::MergeFrom} method in C++.
+ */
+ Builder mergeFrom(MessageLite other);
+
+ /**
+ * Like {@link #mergeFrom(InputStream)}, but does not read until EOF.
+ * Instead, the size of the message (encoded as a varint) is read first,
+ * then the message data. Use
+ * {@link MessageLite#writeDelimitedTo(OutputStream)} to write messages in
+ * this format.
+ *
+ * @return True if successful, or false if the stream is at EOF when the
+ * method starts. Any other error (including reaching EOF during
+ * parsing) will cause an exception to be thrown.
+ */
+ boolean mergeDelimitedFrom(InputStream input)
+ throws IOException;
+
+ /**
+ * Like {@link #mergeDelimitedFrom(InputStream)} but supporting extensions.
+ */
+ boolean mergeDelimitedFrom(InputStream input,
+ ExtensionRegistryLite extensionRegistry)
+ throws IOException;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java
new file mode 100644
index 0000000000..818386ce58
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java
@@ -0,0 +1,60 @@
+// 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;
+
+/**
+ * Base interface for methods common to {@link MessageLite}
+ * and {@link MessageLite.Builder} to provide type equivalency.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public interface MessageLiteOrBuilder {
+ /**
+ * Get an instance of the type with no fields set. Because no fields are set,
+ * all getters for singular fields will return default values and repeated
+ * fields will appear empty.
+ * This may or may not be a singleton. This differs from the
+ * {@code getDefaultInstance()} method of generated message classes in that
+ * this method is an abstract method of the {@code MessageLite} interface
+ * whereas {@code getDefaultInstance()} is a static method of a specific
+ * class. They return the same thing.
+ */
+ MessageLite getDefaultInstanceForType();
+
+ /**
+ * Returns true if all required fields in the message and all embedded
+ * messages are set, false otherwise.
+ *
+ * <p>See also: {@link MessageOrBuilder#getInitializationErrorString()}
+ */
+ boolean isInitialized();
+
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageLiteToString.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageLiteToString.java
new file mode 100644
index 0000000000..23373ef4cd
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageLiteToString.java
@@ -0,0 +1,239 @@
+// 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.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ * Helps generate {@link String} representations of {@link MessageLite} protos.
+ */
+// TODO(dweis): Fix map fields.
+final class MessageLiteToString {
+
+ private static final String LIST_SUFFIX = "List";
+ private static final String BUILDER_LIST_SUFFIX = "OrBuilderList";
+ private static final String BYTES_SUFFIX = "Bytes";
+
+ /**
+ * Returns a {@link String} representation of the {@link MessageLite} object. The first line of
+ * the {@code String} representation representation includes a comment string to uniquely identify
+ * the objcet instance. This acts as an indicator that this should not be relied on for
+ * comparisons.
+ *
+ * <p>For use by generated code only.
+ */
+ static String toString(MessageLite messageLite, String commentString) {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("# ").append(commentString);
+ reflectivePrintWithIndent(messageLite, buffer, 0);
+ return buffer.toString();
+ }
+
+ /**
+ * Reflectively prints the {@link MessageLite} to the buffer at given {@code indent} level.
+ *
+ * @param buffer the buffer to write to
+ * @param indent the number of spaces to indent the proto by
+ */
+ private static void reflectivePrintWithIndent(
+ MessageLite messageLite, StringBuilder buffer, int indent) {
+ // Build a map of method name to method. We're looking for methods like getFoo(), hasFoo(), and
+ // getFooList() which might be useful for building an object's string representation.
+ Map<String, Method> nameToNoArgMethod = new HashMap<String, Method>();
+ Map<String, Method> nameToMethod = new HashMap<String, Method>();
+ Set<String> getters = new TreeSet<String>();
+ for (Method method : messageLite.getClass().getDeclaredMethods()) {
+ nameToMethod.put(method.getName(), method);
+ if (method.getParameterTypes().length == 0) {
+ nameToNoArgMethod.put(method.getName(), method);
+
+ if (method.getName().startsWith("get")) {
+ getters.add(method.getName());
+ }
+ }
+ }
+
+ for (String getter : getters) {
+ String suffix = getter.replaceFirst("get", "");
+ if (suffix.endsWith(LIST_SUFFIX) && !suffix.endsWith(BUILDER_LIST_SUFFIX)) {
+ String camelCase = suffix.substring(0, 1).toLowerCase()
+ + suffix.substring(1, suffix.length() - LIST_SUFFIX.length());
+ // Try to reflectively get the value and toString() the field as if it were repeated. This
+ // only works if the method names have not be proguarded out or renamed.
+ Method listMethod = nameToNoArgMethod.get("get" + suffix);
+ if (listMethod != null && listMethod.getReturnType().equals(List.class)) {
+ printField(
+ buffer,
+ indent,
+ camelCaseToSnakeCase(camelCase),
+ GeneratedMessageLite.invokeOrDie(listMethod, messageLite));
+ continue;
+ }
+ }
+
+ Method setter = nameToMethod.get("set" + suffix);
+ if (setter == null) {
+ continue;
+ }
+ if (suffix.endsWith(BYTES_SUFFIX)
+ && nameToNoArgMethod.containsKey(
+ "get" + suffix.substring(0, suffix.length() - "Bytes".length()))) {
+ // Heuristic to skip bytes based accessors for string fields.
+ continue;
+ }
+
+ String camelCase = suffix.substring(0, 1).toLowerCase() + suffix.substring(1);
+
+ // Try to reflectively get the value and toString() the field as if it were optional. This
+ // only works if the method names have not be proguarded out or renamed.
+ Method getMethod = nameToNoArgMethod.get("get" + suffix);
+ Method hasMethod = nameToNoArgMethod.get("has" + suffix);
+ // TODO(dweis): Fix proto3 semantics.
+ if (getMethod != null) {
+ Object value = GeneratedMessageLite.invokeOrDie(getMethod, messageLite);
+ final boolean hasValue = hasMethod == null
+ ? !isDefaultValue(value)
+ : (Boolean) GeneratedMessageLite.invokeOrDie(hasMethod, messageLite);
+ // TODO(dweis): This doesn't stop printing oneof case twice: value and enum style.
+ if (hasValue) {
+ printField(
+ buffer,
+ indent,
+ camelCaseToSnakeCase(camelCase),
+ value);
+ }
+ continue;
+ }
+ }
+
+ if (messageLite instanceof GeneratedMessageLite.ExtendableMessage) {
+ Iterator<Map.Entry<GeneratedMessageLite.ExtensionDescriptor, Object>> iter =
+ ((GeneratedMessageLite.ExtendableMessage<?, ?>) messageLite).extensions.iterator();
+ while (iter.hasNext()) {
+ Map.Entry<GeneratedMessageLite.ExtensionDescriptor, Object> entry = iter.next();
+ printField(buffer, indent, "[" + entry.getKey().getNumber() + "]", entry.getValue());
+ }
+ }
+
+ if (((GeneratedMessageLite<?, ?>) messageLite).unknownFields != null) {
+ ((GeneratedMessageLite<?, ?>) messageLite).unknownFields.printWithIndent(buffer, indent);
+ }
+ }
+
+ private static boolean isDefaultValue(Object o) {
+ if (o instanceof Boolean) {
+ return !((Boolean) o);
+ }
+ if (o instanceof Integer) {
+ return ((Integer) o) == 0;
+ }
+ if (o instanceof Float) {
+ return ((Float) o) == 0f;
+ }
+ if (o instanceof Double) {
+ return ((Double) o) == 0d;
+ }
+ if (o instanceof String) {
+ return o.equals("");
+ }
+ if (o instanceof ByteString) {
+ return o.equals(ByteString.EMPTY);
+ }
+ if (o instanceof MessageLite) { // Can happen in oneofs.
+ return o == ((MessageLite) o).getDefaultInstanceForType();
+ }
+ if (o instanceof java.lang.Enum<?>) { // Catches oneof enums.
+ return ((java.lang.Enum<?>) o).ordinal() == 0;
+ }
+
+ return false;
+ }
+
+ /**
+ * Formats a text proto field.
+ *
+ * <p>For use by generated code only.
+ *
+ * @param buffer the buffer to write to
+ * @param indent the number of spaces the proto should be indented by
+ * @param name the field name (in lower underscore case)
+ * @param object the object value of the field
+ */
+ static final void printField(StringBuilder buffer, int indent, String name, Object object) {
+ if (object instanceof List<?>) {
+ List<?> list = (List<?>) object;
+ for (Object entry : list) {
+ printField(buffer, indent, name, entry);
+ }
+ return;
+ }
+
+ buffer.append('\n');
+ for (int i = 0; i < indent; i++) {
+ buffer.append(' ');
+ }
+ buffer.append(name);
+
+ if (object instanceof String) {
+ buffer.append(": \"").append(TextFormatEscaper.escapeText((String) object)).append('"');
+ } else if (object instanceof ByteString) {
+ buffer.append(": \"").append(TextFormatEscaper.escapeBytes((ByteString) object)).append('"');
+ } else if (object instanceof GeneratedMessageLite) {
+ buffer.append(" {");
+ reflectivePrintWithIndent((GeneratedMessageLite<?, ?>) object, buffer, indent + 2);
+ buffer.append("\n");
+ for (int i = 0; i < indent; i++) {
+ buffer.append(' ');
+ }
+ buffer.append("}");
+ } else {
+ buffer.append(": ").append(object.toString());
+ }
+ }
+
+ private static final String camelCaseToSnakeCase(String camelCase) {
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < camelCase.length(); i++) {
+ char ch = camelCase.charAt(i);
+ if (Character.isUpperCase(ch)) {
+ builder.append("_");
+ }
+ builder.append(Character.toLowerCase(ch));
+ }
+ return builder.toString();
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageOrBuilder.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageOrBuilder.java
new file mode 100644
index 0000000000..5e7d782132
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageOrBuilder.java
@@ -0,0 +1,143 @@
+// 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.util.List;
+import java.util.Map;
+
+/**
+ * Base interface for methods common to {@link Message} and
+ * {@link Message.Builder} to provide type equivalency.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public interface MessageOrBuilder extends MessageLiteOrBuilder {
+
+ // (From MessageLite, re-declared here only for return type covariance.)
+ @Override
+ Message getDefaultInstanceForType();
+
+ /**
+ * Returns a list of field paths (e.g. "foo.bar.baz") of required fields
+ * which are not set in this message. You should call
+ * {@link MessageLiteOrBuilder#isInitialized()} first to check if there
+ * are any missing fields, as that method is likely to be much faster
+ * than this one even when the message is fully-initialized.
+ */
+ List<String> findInitializationErrors();
+
+ /**
+ * Returns a comma-delimited list of required fields which are not set
+ * in this message object. You should call
+ * {@link MessageLiteOrBuilder#isInitialized()} first to check if there
+ * are any missing fields, as that method is likely to be much faster
+ * than this one even when the message is fully-initialized.
+ */
+ String getInitializationErrorString();
+
+ /**
+ * Get the message's type's descriptor. This differs from the
+ * {@code getDescriptor()} method of generated message classes in that
+ * this method is an abstract method of the {@code Message} interface
+ * whereas {@code getDescriptor()} is a static method of a specific class.
+ * They return the same thing.
+ */
+ Descriptors.Descriptor getDescriptorForType();
+
+ /**
+ * Returns a collection of all the fields in this message which are set
+ * and their corresponding values. A singular ("required" or "optional")
+ * field is set iff hasField() returns true for that field. A "repeated"
+ * field is set iff getRepeatedFieldCount() is greater than zero. The
+ * values are exactly what would be returned by calling
+ * {@link #getField(Descriptors.FieldDescriptor)} for each field. The map
+ * is guaranteed to be a sorted map, so iterating over it will return fields
+ * in order by field number.
+ * <br>
+ * If this is for a builder, the returned map may or may not reflect future
+ * changes to the builder. Either way, the returned map is itself
+ * unmodifiable.
+ */
+ Map<Descriptors.FieldDescriptor, Object> getAllFields();
+
+ /**
+ * Returns true if the given oneof is set.
+ * @throws IllegalArgumentException if
+ * {@code oneof.getContainingType() != getDescriptorForType()}.
+ */
+ boolean hasOneof(Descriptors.OneofDescriptor oneof);
+
+ /**
+ * Obtains the FieldDescriptor if the given oneof is set. Returns null
+ * if no field is set.
+ */
+ Descriptors.FieldDescriptor getOneofFieldDescriptor(
+ Descriptors.OneofDescriptor oneof);
+
+ /**
+ * Returns true if the given field is set. This is exactly equivalent to
+ * calling the generated "has" accessor method corresponding to the field.
+ * @throws IllegalArgumentException The field is a repeated field, or
+ * {@code field.getContainingType() != getDescriptorForType()}.
+ */
+ boolean hasField(Descriptors.FieldDescriptor field);
+
+ /**
+ * Obtains the value of the given field, or the default value if it is
+ * not set. For primitive fields, the boxed primitive value is returned.
+ * For enum fields, the EnumValueDescriptor for the value is returned. For
+ * embedded message fields, the sub-message is returned. For repeated
+ * fields, a java.util.List is returned.
+ */
+ Object getField(Descriptors.FieldDescriptor field);
+
+ /**
+ * Gets the number of elements of a repeated field. This is exactly
+ * equivalent to calling the generated "Count" accessor method corresponding
+ * to the field.
+ * @throws IllegalArgumentException The field is not a repeated field, or
+ * {@code field.getContainingType() != getDescriptorForType()}.
+ */
+ int getRepeatedFieldCount(Descriptors.FieldDescriptor field);
+
+ /**
+ * Gets an element of a repeated field. For primitive fields, the boxed
+ * primitive value is returned. For enum fields, the EnumValueDescriptor
+ * for the value is returned. For embedded message fields, the sub-message
+ * is returned.
+ * @throws IllegalArgumentException The field is not a repeated field, or
+ * {@code field.getContainingType() != getDescriptorForType()}.
+ */
+ Object getRepeatedField(Descriptors.FieldDescriptor field, int index);
+
+ /** Get the {@link UnknownFieldSet} for this message. */
+ UnknownFieldSet getUnknownFields();
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageReflection.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageReflection.java
new file mode 100644
index 0000000000..3d73efb3a0
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MessageReflection.java
@@ -0,0 +1,990 @@
+// 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.FieldDescriptor;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * Reflection utility methods shared by both mutable and immutable messages.
+ *
+ * @author liujisi@google.com (Pherl Liu)
+ */
+class MessageReflection {
+
+ static void writeMessageTo(
+ Message message,
+ Map<FieldDescriptor, Object> fields,
+ CodedOutputStream output,
+ boolean alwaysWriteRequiredFields)
+ throws IOException {
+ final boolean isMessageSet =
+ message.getDescriptorForType().getOptions().getMessageSetWireFormat();
+ if (alwaysWriteRequiredFields) {
+ fields = new TreeMap<FieldDescriptor, Object>(fields);
+ for (final FieldDescriptor field :
+ message.getDescriptorForType().getFields()) {
+ if (field.isRequired() && !fields.containsKey(field)) {
+ fields.put(field, message.getField(field));
+ }
+ }
+ }
+ for (final Map.Entry<Descriptors.FieldDescriptor, Object> entry :
+ fields.entrySet()) {
+ final Descriptors.FieldDescriptor field = entry.getKey();
+ final Object value = entry.getValue();
+ if (isMessageSet && field.isExtension() &&
+ field.getType() == Descriptors.FieldDescriptor.Type.MESSAGE &&
+ !field.isRepeated()) {
+ output.writeMessageSetExtension(field.getNumber(), (Message) value);
+ } else {
+ FieldSet.writeField(field, value, output);
+ }
+ }
+
+ final UnknownFieldSet unknownFields = message.getUnknownFields();
+ if (isMessageSet) {
+ unknownFields.writeAsMessageSetTo(output);
+ } else {
+ unknownFields.writeTo(output);
+ }
+ }
+
+ static int getSerializedSize(
+ Message message,
+ Map<FieldDescriptor, Object> fields) {
+ int size = 0;
+ final boolean isMessageSet =
+ message.getDescriptorForType().getOptions().getMessageSetWireFormat();
+
+ for (final Map.Entry<Descriptors.FieldDescriptor, Object> entry :
+ fields.entrySet()) {
+ final Descriptors.FieldDescriptor field = entry.getKey();
+ final Object value = entry.getValue();
+ if (isMessageSet && field.isExtension() &&
+ field.getType() == Descriptors.FieldDescriptor.Type.MESSAGE &&
+ !field.isRepeated()) {
+ size += CodedOutputStream.computeMessageSetExtensionSize(
+ field.getNumber(), (Message) value);
+ } else {
+ size += FieldSet.computeFieldSize(field, value);
+ }
+ }
+
+ final UnknownFieldSet unknownFields = message.getUnknownFields();
+ if (isMessageSet) {
+ size += unknownFields.getSerializedSizeAsMessageSet();
+ } else {
+ size += unknownFields.getSerializedSize();
+ }
+ return size;
+ }
+
+ static String delimitWithCommas(List<String> parts) {
+ StringBuilder result = new StringBuilder();
+ for (String part : parts) {
+ if (result.length() > 0) {
+ result.append(", ");
+ }
+ result.append(part);
+ }
+ return result.toString();
+ }
+
+ @SuppressWarnings("unchecked")
+ static boolean isInitialized(MessageOrBuilder message) {
+ // Check that all required fields are present.
+ for (final Descriptors.FieldDescriptor field : message
+ .getDescriptorForType()
+ .getFields()) {
+ if (field.isRequired()) {
+ if (!message.hasField(field)) {
+ return false;
+ }
+ }
+ }
+
+ // Check that embedded messages are initialized.
+ for (final Map.Entry<Descriptors.FieldDescriptor, Object> entry :
+ message.getAllFields().entrySet()) {
+ final Descriptors.FieldDescriptor field = entry.getKey();
+ if (field.getJavaType() == Descriptors.FieldDescriptor.JavaType.MESSAGE) {
+ if (field.isRepeated()) {
+ for (final Message element
+ : (List<Message>) entry.getValue()) {
+ if (!element.isInitialized()) {
+ return false;
+ }
+ }
+ } else {
+ if (!((Message) entry.getValue()).isInitialized()) {
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
+ private static String subMessagePrefix(final String prefix,
+ final Descriptors.FieldDescriptor field,
+ final int index) {
+ final StringBuilder result = new StringBuilder(prefix);
+ if (field.isExtension()) {
+ result.append('(')
+ .append(field.getFullName())
+ .append(')');
+ } else {
+ result.append(field.getName());
+ }
+ if (index != -1) {
+ result.append('[')
+ .append(index)
+ .append(']');
+ }
+ result.append('.');
+ return result.toString();
+ }
+
+ private static void findMissingFields(final MessageOrBuilder message,
+ final String prefix,
+ final List<String> results) {
+ for (final Descriptors.FieldDescriptor field :
+ message.getDescriptorForType().getFields()) {
+ if (field.isRequired() && !message.hasField(field)) {
+ results.add(prefix + field.getName());
+ }
+ }
+
+ for (final Map.Entry<Descriptors.FieldDescriptor, Object> entry :
+ message.getAllFields().entrySet()) {
+ final Descriptors.FieldDescriptor field = entry.getKey();
+ final Object value = entry.getValue();
+
+ if (field.getJavaType() == Descriptors.FieldDescriptor.JavaType.MESSAGE) {
+ if (field.isRepeated()) {
+ int i = 0;
+ for (final Object element : (List) value) {
+ findMissingFields((MessageOrBuilder) element,
+ subMessagePrefix(prefix, field, i++),
+ results);
+ }
+ } else {
+ if (message.hasField(field)) {
+ findMissingFields((MessageOrBuilder) value,
+ subMessagePrefix(prefix, field, -1),
+ results);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Populates {@code this.missingFields} with the full "path" of each missing
+ * required field in the given message.
+ */
+ static List<String> findMissingFields(
+ final MessageOrBuilder message) {
+ final List<String> results = new ArrayList<String>();
+ findMissingFields(message, "", results);
+ return results;
+ }
+
+ static interface MergeTarget {
+ enum ContainerType {
+ MESSAGE, EXTENSION_SET
+ }
+
+ /**
+ * Returns the descriptor for the target.
+ */
+ public Descriptors.Descriptor getDescriptorForType();
+
+ public ContainerType getContainerType();
+
+ public ExtensionRegistry.ExtensionInfo findExtensionByName(
+ ExtensionRegistry registry, String name);
+
+ public ExtensionRegistry.ExtensionInfo findExtensionByNumber(
+ ExtensionRegistry registry, Descriptors.Descriptor containingType,
+ int fieldNumber);
+
+ /**
+ * Obtains the value of the given field, or the default value if it is not
+ * set. For primitive fields, the boxed primitive value is returned. For
+ * enum fields, the EnumValueDescriptor for the value is returned. For
+ * embedded message fields, the sub-message is returned. For repeated
+ * fields, a java.util.List is returned.
+ */
+ public Object getField(Descriptors.FieldDescriptor field);
+
+ /**
+ * Returns true if the given field is set. This is exactly equivalent to
+ * calling the generated "has" accessor method corresponding to the field.
+ *
+ * @throws IllegalArgumentException The field is a repeated field, or {@code
+ * field.getContainingType() != getDescriptorForType()}.
+ */
+ boolean hasField(Descriptors.FieldDescriptor field);
+
+ /**
+ * Sets a field to the given value. The value must be of the correct type
+ * for this field, i.e. the same type that
+ * {@link Message#getField(Descriptors.FieldDescriptor)}
+ * would return.
+ */
+ MergeTarget setField(Descriptors.FieldDescriptor field, Object value);
+
+ /**
+ * Clears the field. This is exactly equivalent to calling the generated
+ * "clear" accessor method corresponding to the field.
+ */
+ MergeTarget clearField(Descriptors.FieldDescriptor field);
+
+ /**
+ * Sets an element of a repeated field to the given value. The value must
+ * be of the correct type for this field, i.e. the same type that {@link
+ * Message#getRepeatedField(Descriptors.FieldDescriptor, int)} would return.
+ *
+ * @throws IllegalArgumentException The field is not a repeated field, or
+ * {@code field.getContainingType() !=
+ * getDescriptorForType()}.
+ */
+ MergeTarget setRepeatedField(Descriptors.FieldDescriptor field,
+ int index, Object value);
+
+ /**
+ * Like {@code setRepeatedField}, but appends the value as a new element.
+ *
+ * @throws IllegalArgumentException The field is not a repeated field, or
+ * {@code field.getContainingType() !=
+ * getDescriptorForType()}.
+ */
+ MergeTarget addRepeatedField(Descriptors.FieldDescriptor field,
+ Object value);
+
+ /**
+ * Returns true if the given oneof is set.
+ *
+ * @throws IllegalArgumentException if
+ * {@code oneof.getContainingType() != getDescriptorForType()}.
+ */
+ boolean hasOneof(Descriptors.OneofDescriptor oneof);
+
+ /**
+ * Clears the oneof. This is exactly equivalent to calling the generated
+ * "clear" accessor method corresponding to the oneof.
+ */
+ MergeTarget clearOneof(Descriptors.OneofDescriptor oneof);
+
+ /**
+ * Obtains the FieldDescriptor if the given oneof is set. Returns null
+ * if no field is set.
+ */
+ Descriptors.FieldDescriptor getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof);
+
+ /**
+ * Parse the input stream into a sub field group defined based on either
+ * FieldDescriptor or the default instance.
+ */
+ Object parseGroup(CodedInputStream input, ExtensionRegistryLite registry,
+ Descriptors.FieldDescriptor descriptor, Message defaultInstance)
+ throws IOException;
+
+ /**
+ * Parse the input stream into a sub field message defined based on either
+ * FieldDescriptor or the default instance.
+ */
+ Object parseMessage(CodedInputStream input, ExtensionRegistryLite registry,
+ Descriptors.FieldDescriptor descriptor, Message defaultInstance)
+ throws IOException;
+
+ /**
+ * Parse from a ByteString into a sub field message defined based on either
+ * FieldDescriptor or the default instance. There isn't a varint indicating
+ * the length of the message at the beginning of the input ByteString.
+ */
+ Object parseMessageFromBytes(
+ ByteString bytes, ExtensionRegistryLite registry,
+ Descriptors.FieldDescriptor descriptor, Message defaultInstance)
+ throws IOException;
+
+ /**
+ * Returns the UTF8 validation level for the field.
+ */
+ WireFormat.Utf8Validation getUtf8Validation(Descriptors.FieldDescriptor
+ descriptor);
+
+ /**
+ * Returns a new merge target for a sub-field. When defaultInstance is
+ * provided, it indicates the descriptor is for an extension type, and
+ * implementations should create a new instance from the defaultInstance
+ * prototype directly.
+ */
+ MergeTarget newMergeTargetForField(
+ Descriptors.FieldDescriptor descriptor,
+ Message defaultInstance);
+
+ /**
+ * Finishes the merge and returns the underlying object.
+ */
+ Object finish();
+ }
+
+ static class BuilderAdapter implements MergeTarget {
+
+ private final Message.Builder builder;
+
+ @Override
+ public Descriptors.Descriptor getDescriptorForType() {
+ return builder.getDescriptorForType();
+ }
+
+ public BuilderAdapter(Message.Builder builder) {
+ this.builder = builder;
+ }
+
+ @Override
+ public Object getField(Descriptors.FieldDescriptor field) {
+ return builder.getField(field);
+ }
+
+ @Override
+ public boolean hasField(Descriptors.FieldDescriptor field) {
+ return builder.hasField(field);
+ }
+
+ @Override
+ public MergeTarget setField(Descriptors.FieldDescriptor field, Object value) {
+ builder.setField(field, value);
+ return this;
+ }
+
+ @Override
+ public MergeTarget clearField(Descriptors.FieldDescriptor field) {
+ builder.clearField(field);
+ return this;
+ }
+
+ @Override
+ public MergeTarget setRepeatedField(
+ Descriptors.FieldDescriptor field, int index, Object value) {
+ builder.setRepeatedField(field, index, value);
+ return this;
+ }
+
+ @Override
+ public MergeTarget addRepeatedField(Descriptors.FieldDescriptor field, Object value) {
+ builder.addRepeatedField(field, value);
+ return this;
+ }
+
+ @Override
+ public boolean hasOneof(Descriptors.OneofDescriptor oneof) {
+ return builder.hasOneof(oneof);
+ }
+
+ @Override
+ public MergeTarget clearOneof(Descriptors.OneofDescriptor oneof) {
+ builder.clearOneof(oneof);
+ return this;
+ }
+
+ @Override
+ public Descriptors.FieldDescriptor getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof) {
+ return builder.getOneofFieldDescriptor(oneof);
+ }
+
+ @Override
+ public ContainerType getContainerType() {
+ return ContainerType.MESSAGE;
+ }
+
+ @Override
+ public ExtensionRegistry.ExtensionInfo findExtensionByName(
+ ExtensionRegistry registry, String name) {
+ return registry.findImmutableExtensionByName(name);
+ }
+
+ @Override
+ public ExtensionRegistry.ExtensionInfo findExtensionByNumber(
+ ExtensionRegistry registry, Descriptors.Descriptor containingType, int fieldNumber) {
+ return registry.findImmutableExtensionByNumber(containingType,
+ fieldNumber);
+ }
+
+ @Override
+ public Object parseGroup(
+ CodedInputStream input,
+ ExtensionRegistryLite extensionRegistry,
+ Descriptors.FieldDescriptor field,
+ Message defaultInstance)
+ throws IOException {
+ Message.Builder subBuilder;
+ // When default instance is not null. The field is an extension field.
+ if (defaultInstance != null) {
+ subBuilder = defaultInstance.newBuilderForType();
+ } else {
+ subBuilder = builder.newBuilderForField(field);
+ }
+ if (!field.isRepeated()) {
+ Message originalMessage = (Message) getField(field);
+ if (originalMessage != null) {
+ subBuilder.mergeFrom(originalMessage);
+ }
+ }
+ input.readGroup(field.getNumber(), subBuilder, extensionRegistry);
+ return subBuilder.buildPartial();
+ }
+
+ @Override
+ public Object parseMessage(
+ CodedInputStream input,
+ ExtensionRegistryLite extensionRegistry,
+ Descriptors.FieldDescriptor field,
+ Message defaultInstance)
+ throws IOException {
+ Message.Builder subBuilder;
+ // When default instance is not null. The field is an extension field.
+ if (defaultInstance != null) {
+ subBuilder = defaultInstance.newBuilderForType();
+ } else {
+ subBuilder = builder.newBuilderForField(field);
+ }
+ if (!field.isRepeated()) {
+ Message originalMessage = (Message) getField(field);
+ if (originalMessage != null) {
+ subBuilder.mergeFrom(originalMessage);
+ }
+ }
+ input.readMessage(subBuilder, extensionRegistry);
+ return subBuilder.buildPartial();
+ }
+
+ @Override
+ public Object parseMessageFromBytes(
+ ByteString bytes,
+ ExtensionRegistryLite extensionRegistry,
+ Descriptors.FieldDescriptor field,
+ Message defaultInstance)
+ throws IOException {
+ Message.Builder subBuilder;
+ // When default instance is not null. The field is an extension field.
+ if (defaultInstance != null) {
+ subBuilder = defaultInstance.newBuilderForType();
+ } else {
+ subBuilder = builder.newBuilderForField(field);
+ }
+ if (!field.isRepeated()) {
+ Message originalMessage = (Message) getField(field);
+ if (originalMessage != null) {
+ subBuilder.mergeFrom(originalMessage);
+ }
+ }
+ subBuilder.mergeFrom(bytes, extensionRegistry);
+ return subBuilder.buildPartial();
+ }
+
+ @Override
+ public MergeTarget newMergeTargetForField(
+ Descriptors.FieldDescriptor field, Message defaultInstance) {
+ if (defaultInstance != null) {
+ return new BuilderAdapter(
+ defaultInstance.newBuilderForType());
+ } else {
+ return new BuilderAdapter(builder.newBuilderForField(field));
+ }
+ }
+
+ @Override
+ public WireFormat.Utf8Validation getUtf8Validation(Descriptors.FieldDescriptor descriptor) {
+ if (descriptor.needsUtf8Check()) {
+ return WireFormat.Utf8Validation.STRICT;
+ }
+ // TODO(liujisi): support lazy strings for repeated fields.
+ if (!descriptor.isRepeated()
+ && builder instanceof GeneratedMessage.Builder) {
+ return WireFormat.Utf8Validation.LAZY;
+ }
+ return WireFormat.Utf8Validation.LOOSE;
+ }
+
+ @Override
+ public Object finish() {
+ return builder.buildPartial();
+ }
+ }
+
+
+ static class ExtensionAdapter implements MergeTarget {
+
+ private final FieldSet<Descriptors.FieldDescriptor> extensions;
+
+ ExtensionAdapter(FieldSet<Descriptors.FieldDescriptor> extensions) {
+ this.extensions = extensions;
+ }
+
+ @Override
+ public Descriptors.Descriptor getDescriptorForType() {
+ throw new UnsupportedOperationException(
+ "getDescriptorForType() called on FieldSet object");
+ }
+
+ @Override
+ public Object getField(Descriptors.FieldDescriptor field) {
+ return extensions.getField(field);
+ }
+
+ @Override
+ public boolean hasField(Descriptors.FieldDescriptor field) {
+ return extensions.hasField(field);
+ }
+
+ @Override
+ public MergeTarget setField(Descriptors.FieldDescriptor field, Object value) {
+ extensions.setField(field, value);
+ return this;
+ }
+
+ @Override
+ public MergeTarget clearField(Descriptors.FieldDescriptor field) {
+ extensions.clearField(field);
+ return this;
+ }
+
+ @Override
+ public MergeTarget setRepeatedField(
+ Descriptors.FieldDescriptor field, int index, Object value) {
+ extensions.setRepeatedField(field, index, value);
+ return this;
+ }
+
+ @Override
+ public MergeTarget addRepeatedField(Descriptors.FieldDescriptor field, Object value) {
+ extensions.addRepeatedField(field, value);
+ return this;
+ }
+
+ @Override
+ public boolean hasOneof(Descriptors.OneofDescriptor oneof) {
+ return false;
+ }
+
+ @Override
+ public MergeTarget clearOneof(Descriptors.OneofDescriptor oneof) {
+ // Nothing to clear.
+ return this;
+ }
+
+ @Override
+ public Descriptors.FieldDescriptor getOneofFieldDescriptor(Descriptors.OneofDescriptor oneof) {
+ return null;
+ }
+
+ @Override
+ public ContainerType getContainerType() {
+ return ContainerType.EXTENSION_SET;
+ }
+
+ @Override
+ public ExtensionRegistry.ExtensionInfo findExtensionByName(
+ ExtensionRegistry registry, String name) {
+ return registry.findImmutableExtensionByName(name);
+ }
+
+ @Override
+ public ExtensionRegistry.ExtensionInfo findExtensionByNumber(
+ ExtensionRegistry registry, Descriptors.Descriptor containingType, int fieldNumber) {
+ return registry.findImmutableExtensionByNumber(containingType,
+ fieldNumber);
+ }
+
+ @Override
+ public Object parseGroup(
+ CodedInputStream input,
+ ExtensionRegistryLite registry,
+ Descriptors.FieldDescriptor field,
+ Message defaultInstance)
+ throws IOException {
+ Message.Builder subBuilder =
+ defaultInstance.newBuilderForType();
+ if (!field.isRepeated()) {
+ Message originalMessage = (Message) getField(field);
+ if (originalMessage != null) {
+ subBuilder.mergeFrom(originalMessage);
+ }
+ }
+ input.readGroup(field.getNumber(), subBuilder, registry);
+ return subBuilder.buildPartial();
+ }
+
+ @Override
+ public Object parseMessage(
+ CodedInputStream input,
+ ExtensionRegistryLite registry,
+ Descriptors.FieldDescriptor field,
+ Message defaultInstance)
+ throws IOException {
+ Message.Builder subBuilder =
+ defaultInstance.newBuilderForType();
+ if (!field.isRepeated()) {
+ Message originalMessage = (Message) getField(field);
+ if (originalMessage != null) {
+ subBuilder.mergeFrom(originalMessage);
+ }
+ }
+ input.readMessage(subBuilder, registry);
+ return subBuilder.buildPartial();
+ }
+
+ @Override
+ public Object parseMessageFromBytes(
+ ByteString bytes,
+ ExtensionRegistryLite registry,
+ Descriptors.FieldDescriptor field,
+ Message defaultInstance)
+ throws IOException {
+ Message.Builder subBuilder = defaultInstance.newBuilderForType();
+ if (!field.isRepeated()) {
+ Message originalMessage = (Message) getField(field);
+ if (originalMessage != null) {
+ subBuilder.mergeFrom(originalMessage);
+ }
+ }
+ subBuilder.mergeFrom(bytes, registry);
+ return subBuilder.buildPartial();
+ }
+
+ @Override
+ public MergeTarget newMergeTargetForField(
+ Descriptors.FieldDescriptor descriptor, Message defaultInstance) {
+ throw new UnsupportedOperationException(
+ "newMergeTargetForField() called on FieldSet object");
+ }
+
+ @Override
+ public WireFormat.Utf8Validation getUtf8Validation(Descriptors.FieldDescriptor descriptor) {
+ if (descriptor.needsUtf8Check()) {
+ return WireFormat.Utf8Validation.STRICT;
+ }
+ // TODO(liujisi): support lazy strings for ExtesnsionSet.
+ return WireFormat.Utf8Validation.LOOSE;
+ }
+
+ @Override
+ public Object finish() {
+ throw new UnsupportedOperationException(
+ "finish() called on FieldSet object");
+ }
+ }
+
+ /**
+ * Parses a single field into MergeTarget. The target can be Message.Builder,
+ * FieldSet or MutableMessage.
+ *
+ * Package-private because it is used by GeneratedMessage.ExtendableMessage.
+ *
+ * @param tag The tag, which should have already been read.
+ * @return {@code true} unless the tag is an end-group tag.
+ */
+ static boolean mergeFieldFrom(
+ CodedInputStream input,
+ UnknownFieldSet.Builder unknownFields,
+ ExtensionRegistryLite extensionRegistry,
+ Descriptors.Descriptor type,
+ MergeTarget target,
+ int tag) throws IOException {
+ if (type.getOptions().getMessageSetWireFormat() &&
+ tag == WireFormat.MESSAGE_SET_ITEM_TAG) {
+ mergeMessageSetExtensionFromCodedStream(
+ input, unknownFields, extensionRegistry, type, target);
+ return true;
+ }
+
+ final int wireType = WireFormat.getTagWireType(tag);
+ final int fieldNumber = WireFormat.getTagFieldNumber(tag);
+
+ final Descriptors.FieldDescriptor field;
+ Message defaultInstance = null;
+
+ if (type.isExtensionNumber(fieldNumber)) {
+ // extensionRegistry may be either ExtensionRegistry or
+ // ExtensionRegistryLite. Since the type we are parsing is a full
+ // message, only a full ExtensionRegistry could possibly contain
+ // extensions of it. Otherwise we will treat the registry as if it
+ // were empty.
+ if (extensionRegistry instanceof ExtensionRegistry) {
+ final ExtensionRegistry.ExtensionInfo extension =
+ target.findExtensionByNumber((ExtensionRegistry) extensionRegistry,
+ type, fieldNumber);
+ if (extension == null) {
+ field = null;
+ } else {
+ field = extension.descriptor;
+ defaultInstance = extension.defaultInstance;
+ if (defaultInstance == null &&
+ field.getJavaType()
+ == Descriptors.FieldDescriptor.JavaType.MESSAGE) {
+ throw new IllegalStateException(
+ "Message-typed extension lacked default instance: " +
+ field.getFullName());
+ }
+ }
+ } else {
+ field = null;
+ }
+ } else if (target.getContainerType() == MergeTarget.ContainerType.MESSAGE) {
+ field = type.findFieldByNumber(fieldNumber);
+ } else {
+ field = null;
+ }
+
+ boolean unknown = false;
+ boolean packed = false;
+ if (field == null) {
+ unknown = true; // Unknown field.
+ } else if (wireType == FieldSet.getWireFormatForFieldType(
+ field.getLiteType(),
+ false /* isPacked */)) {
+ packed = false;
+ } else if (field.isPackable() &&
+ wireType == FieldSet.getWireFormatForFieldType(
+ field.getLiteType(),
+ true /* isPacked */)) {
+ packed = true;
+ } else {
+ unknown = true; // Unknown wire type.
+ }
+
+ if (unknown) { // Unknown field or wrong wire type. Skip.
+ return unknownFields.mergeFieldFrom(tag, input);
+ }
+
+ if (packed) {
+ final int length = input.readRawVarint32();
+ final int limit = input.pushLimit(length);
+ if (field.getLiteType() == WireFormat.FieldType.ENUM) {
+ while (input.getBytesUntilLimit() > 0) {
+ final int rawValue = input.readEnum();
+ if (field.getFile().supportsUnknownEnumValue()) {
+ target.addRepeatedField(field,
+ field.getEnumType().findValueByNumberCreatingIfUnknown(rawValue));
+ } else {
+ final Object value = field.getEnumType().findValueByNumber(rawValue);
+ if (value == null) {
+ // If the number isn't recognized as a valid value for this
+ // enum, drop it (don't even add it to unknownFields).
+ return true;
+ }
+ target.addRepeatedField(field, value);
+ }
+ }
+ } else {
+ while (input.getBytesUntilLimit() > 0) {
+ final Object value = WireFormat.readPrimitiveField(
+ input, field.getLiteType(), target.getUtf8Validation(field));
+ target.addRepeatedField(field, value);
+ }
+ }
+ input.popLimit(limit);
+ } else {
+ final Object value;
+ switch (field.getType()) {
+ case GROUP: {
+ value = target
+ .parseGroup(input, extensionRegistry, field, defaultInstance);
+ break;
+ }
+ case MESSAGE: {
+ value = target
+ .parseMessage(input, extensionRegistry, field, defaultInstance);
+ break;
+ }
+ case ENUM:
+ final int rawValue = input.readEnum();
+ if (field.getFile().supportsUnknownEnumValue()) {
+ value = field.getEnumType().findValueByNumberCreatingIfUnknown(rawValue);
+ } else {
+ value = field.getEnumType().findValueByNumber(rawValue);
+ // If the number isn't recognized as a valid value for this enum,
+ // drop it.
+ if (value == null) {
+ unknownFields.mergeVarintField(fieldNumber, rawValue);
+ return true;
+ }
+ }
+ break;
+ default:
+ value = WireFormat.readPrimitiveField(
+ input, field.getLiteType(), target.getUtf8Validation(field));
+ break;
+ }
+
+ if (field.isRepeated()) {
+ target.addRepeatedField(field, value);
+ } else {
+ target.setField(field, value);
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Called by {@code #mergeFieldFrom()} to parse a MessageSet extension into
+ * MergeTarget.
+ */
+ private static void mergeMessageSetExtensionFromCodedStream(
+ CodedInputStream input,
+ UnknownFieldSet.Builder unknownFields,
+ ExtensionRegistryLite extensionRegistry,
+ Descriptors.Descriptor type,
+ MergeTarget target) throws IOException {
+
+ // The wire format for MessageSet is:
+ // message MessageSet {
+ // repeated group Item = 1 {
+ // required int32 typeId = 2;
+ // required bytes message = 3;
+ // }
+ // }
+ // "typeId" is the extension's field number. The extension can only be
+ // a message type, where "message" contains the encoded bytes of that
+ // message.
+ //
+ // In practice, we will probably never see a MessageSet item in which
+ // the message appears before the type ID, or where either field does not
+ // appear exactly once. However, in theory such cases are valid, so we
+ // should be prepared to accept them.
+
+ int typeId = 0;
+ ByteString rawBytes = null; // If we encounter "message" before "typeId"
+ ExtensionRegistry.ExtensionInfo extension = null;
+
+ // Read bytes from input, if we get it's type first then parse it eagerly,
+ // otherwise we store the raw bytes in a local variable.
+ while (true) {
+ final int tag = input.readTag();
+ if (tag == 0) {
+ break;
+ }
+
+ if (tag == WireFormat.MESSAGE_SET_TYPE_ID_TAG) {
+ typeId = input.readUInt32();
+ if (typeId != 0) {
+ // extensionRegistry may be either ExtensionRegistry or
+ // ExtensionRegistryLite. Since the type we are parsing is a full
+ // message, only a full ExtensionRegistry could possibly contain
+ // extensions of it. Otherwise we will treat the registry as if it
+ // were empty.
+ if (extensionRegistry instanceof ExtensionRegistry) {
+ extension = target.findExtensionByNumber(
+ (ExtensionRegistry) extensionRegistry, type, typeId);
+ }
+ }
+
+ } else if (tag == WireFormat.MESSAGE_SET_MESSAGE_TAG) {
+ if (typeId != 0) {
+ if (extension != null &&
+ ExtensionRegistryLite.isEagerlyParseMessageSets()) {
+ // We already know the type, so we can parse directly from the
+ // input with no copying. Hooray!
+ eagerlyMergeMessageSetExtension(
+ input, extension, extensionRegistry, target);
+ rawBytes = null;
+ continue;
+ }
+ }
+ // We haven't seen a type ID yet or we want parse message lazily.
+ rawBytes = input.readBytes();
+
+ } else { // Unknown tag. Skip it.
+ if (!input.skipField(tag)) {
+ break; // End of group
+ }
+ }
+ }
+ input.checkLastTagWas(WireFormat.MESSAGE_SET_ITEM_END_TAG);
+
+ // Process the raw bytes.
+ if (rawBytes != null && typeId != 0) { // Zero is not a valid type ID.
+ if (extension != null) { // We known the type
+ mergeMessageSetExtensionFromBytes(
+ rawBytes, extension, extensionRegistry, target);
+ } else { // We don't know how to parse this. Ignore it.
+ if (rawBytes != null) {
+ unknownFields.mergeField(typeId, UnknownFieldSet.Field.newBuilder()
+ .addLengthDelimited(rawBytes).build());
+ }
+ }
+ }
+ }
+
+ private static void mergeMessageSetExtensionFromBytes(
+ ByteString rawBytes,
+ ExtensionRegistry.ExtensionInfo extension,
+ ExtensionRegistryLite extensionRegistry,
+ MergeTarget target) throws IOException {
+
+ Descriptors.FieldDescriptor field = extension.descriptor;
+ boolean hasOriginalValue = target.hasField(field);
+
+ if (hasOriginalValue || ExtensionRegistryLite.isEagerlyParseMessageSets()) {
+ // If the field already exists, we just parse the field.
+ Object value = target.parseMessageFromBytes(
+ rawBytes, extensionRegistry,field, extension.defaultInstance);
+ target.setField(field, value);
+ } else {
+ // Use LazyField to load MessageSet lazily.
+ LazyField lazyField = new LazyField(
+ extension.defaultInstance, extensionRegistry, rawBytes);
+ target.setField(field, lazyField);
+ }
+ }
+
+ private static void eagerlyMergeMessageSetExtension(
+ CodedInputStream input,
+ ExtensionRegistry.ExtensionInfo extension,
+ ExtensionRegistryLite extensionRegistry,
+ MergeTarget target) throws IOException {
+ Descriptors.FieldDescriptor field = extension.descriptor;
+ Object value = target.parseMessage(input, extensionRegistry, field,
+ extension.defaultInstance);
+ target.setField(field, value);
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MutabilityOracle.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MutabilityOracle.java
new file mode 100644
index 0000000000..82b723c95d
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/MutabilityOracle.java
@@ -0,0 +1,48 @@
+// 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;
+
+/**
+ * Verifies that an object is mutable, throwing if not.
+ */
+interface MutabilityOracle {
+ static final MutabilityOracle IMMUTABLE = new MutabilityOracle() {
+ @Override
+ public void ensureMutable() {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+ /**
+ * Throws an {@link UnsupportedOperationException} if not mutable.
+ */
+ void ensureMutable();
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/NioByteString.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/NioByteString.java
new file mode 100644
index 0000000000..76594809e8
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/NioByteString.java
@@ -0,0 +1,291 @@
+// 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 static com.google.protobuf.Internal.checkNotNull;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.InvalidMarkException;
+import java.nio.charset.Charset;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * A {@link ByteString} that wraps around a {@link ByteBuffer}.
+ */
+final class NioByteString extends ByteString.LeafByteString {
+ private final ByteBuffer buffer;
+
+ NioByteString(ByteBuffer buffer) {
+ checkNotNull(buffer, "buffer");
+
+ // Use native byte order for fast fixed32/64 operations.
+ this.buffer = buffer.slice().order(ByteOrder.nativeOrder());
+ }
+
+ // =================================================================
+ // Serializable
+
+ /**
+ * Magic method that lets us override serialization behavior.
+ */
+ private Object writeReplace() {
+ return ByteString.copyFrom(buffer.slice());
+ }
+
+ /**
+ * Magic method that lets us override deserialization behavior.
+ */
+ private void readObject(@SuppressWarnings("unused") ObjectInputStream in) throws IOException {
+ throw new InvalidObjectException("NioByteString instances are not to be serialized directly");
+ }
+
+ // =================================================================
+
+ @Override
+ public byte byteAt(int index) {
+ try {
+ return buffer.get(index);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw e;
+ } catch (IndexOutOfBoundsException e) {
+ throw new ArrayIndexOutOfBoundsException(e.getMessage());
+ }
+ }
+
+ @Override
+ public int size() {
+ return buffer.remaining();
+ }
+
+ @Override
+ public ByteString substring(int beginIndex, int endIndex) {
+ try {
+ ByteBuffer slice = slice(beginIndex, endIndex);
+ return new NioByteString(slice);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw e;
+ } catch (IndexOutOfBoundsException e) {
+ throw new ArrayIndexOutOfBoundsException(e.getMessage());
+ }
+ }
+
+ @Override
+ protected void copyToInternal(
+ byte[] target, int sourceOffset, int targetOffset, int numberToCopy) {
+ ByteBuffer slice = buffer.slice();
+ slice.position(sourceOffset);
+ slice.get(target, targetOffset, numberToCopy);
+ }
+
+ @Override
+ public void copyTo(ByteBuffer target) {
+ target.put(buffer.slice());
+ }
+
+ @Override
+ public void writeTo(OutputStream out) throws IOException {
+ out.write(toByteArray());
+ }
+
+ @Override
+ boolean equalsRange(ByteString other, int offset, int length) {
+ return substring(0, length).equals(other.substring(offset, offset + length));
+ }
+
+ @Override
+ void writeToInternal(OutputStream out, int sourceOffset, int numberToWrite) throws IOException {
+ if (buffer.hasArray()) {
+ // Optimized write for array-backed buffers.
+ // Note that we're taking the risk that a malicious OutputStream could modify the array.
+ int bufferOffset = buffer.arrayOffset() + buffer.position() + sourceOffset;
+ out.write(buffer.array(), bufferOffset, numberToWrite);
+ return;
+ }
+
+ ByteBufferWriter.write(slice(sourceOffset, sourceOffset + numberToWrite), out);
+ }
+
+ @Override
+ void writeTo(ByteOutput output) throws IOException {
+ output.writeLazy(buffer.slice());
+ }
+
+ @Override
+ public ByteBuffer asReadOnlyByteBuffer() {
+ return buffer.asReadOnlyBuffer();
+ }
+
+ @Override
+ public List<ByteBuffer> asReadOnlyByteBufferList() {
+ return Collections.singletonList(asReadOnlyByteBuffer());
+ }
+
+ @Override
+ protected String toStringInternal(Charset charset) {
+ final byte[] bytes;
+ final int offset;
+ final int length;
+ if (buffer.hasArray()) {
+ bytes = buffer.array();
+ offset = buffer.arrayOffset() + buffer.position();
+ length = buffer.remaining();
+ } else {
+ // TODO(nathanmittler): Can we optimize this?
+ bytes = toByteArray();
+ offset = 0;
+ length = bytes.length;
+ }
+ return new String(bytes, offset, length, charset);
+ }
+
+ @Override
+ public boolean isValidUtf8() {
+ return Utf8.isValidUtf8(buffer);
+ }
+
+ @Override
+ protected int partialIsValidUtf8(int state, int offset, int length) {
+ return Utf8.partialIsValidUtf8(state, buffer, offset, offset + length);
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (!(other instanceof ByteString)) {
+ return false;
+ }
+ ByteString otherString = ((ByteString) other);
+ if (size() != otherString.size()) {
+ return false;
+ }
+ if (size() == 0) {
+ return true;
+ }
+ if (other instanceof NioByteString) {
+ return buffer.equals(((NioByteString) other).buffer);
+ }
+ if (other instanceof RopeByteString) {
+ return other.equals(this);
+ }
+ return buffer.equals(otherString.asReadOnlyByteBuffer());
+ }
+
+ @Override
+ protected int partialHash(int h, int offset, int length) {
+ for (int i = offset; i < offset + length; i++) {
+ h = h * 31 + buffer.get(i);
+ }
+ return h;
+ }
+
+ @Override
+ public InputStream newInput() {
+ return new InputStream() {
+ private final ByteBuffer buf = buffer.slice();
+
+ @Override
+ public void mark(int readlimit) {
+ buf.mark();
+ }
+
+ @Override
+ public boolean markSupported() {
+ return true;
+ }
+
+ @Override
+ public void reset() throws IOException {
+ try {
+ buf.reset();
+ } catch (InvalidMarkException e) {
+ throw new IOException(e);
+ }
+ }
+
+ @Override
+ public int available() throws IOException {
+ return buf.remaining();
+ }
+
+ @Override
+ public int read() throws IOException {
+ if (!buf.hasRemaining()) {
+ return -1;
+ }
+ return buf.get() & 0xFF;
+ }
+
+ @Override
+ public int read(byte[] bytes, int off, int len) throws IOException {
+ if (!buf.hasRemaining()) {
+ return -1;
+ }
+
+ len = Math.min(len, buf.remaining());
+ buf.get(bytes, off, len);
+ return len;
+ }
+ };
+ }
+
+ @Override
+ public CodedInputStream newCodedInput() {
+ return CodedInputStream.newInstance(buffer, true);
+ }
+
+ /**
+ * Creates a slice of a range of this buffer.
+ *
+ * @param beginIndex the beginning index of the slice (inclusive).
+ * @param endIndex the end index of the slice (exclusive).
+ * @return the requested slice.
+ */
+ private ByteBuffer slice(int beginIndex, int endIndex) {
+ if (beginIndex < buffer.position() || endIndex > buffer.limit() || beginIndex > endIndex) {
+ throw new IllegalArgumentException(
+ String.format("Invalid indices [%d, %d]", beginIndex, endIndex));
+ }
+
+ ByteBuffer slice = buffer.slice();
+ slice.position(beginIndex - buffer.position());
+ slice.limit(endIndex - buffer.position());
+ return slice;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Parser.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Parser.java
new file mode 100644
index 0000000000..cfbcb44257
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Parser.java
@@ -0,0 +1,272 @@
+// 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.InputStream;
+
+/**
+ * Abstract interface for parsing Protocol Messages.
+ *
+ * The implementation should be stateless and thread-safe.
+ *
+ * <p>All methods may throw {@link InvalidProtocolBufferException}. In the event of invalid data,
+ * like an encoding error, the cause of the thrown exception will be {@code null}. However, if an
+ * I/O problem occurs, an exception is thrown with an {@link java.io.IOException} cause.
+ *
+ * @author liujisi@google.com (Pherl Liu)
+ */
+public interface Parser<MessageType> {
+
+ // NB(jh): Other parts of the protobuf API that parse messages distinguish between an I/O problem
+ // (like failure reading bytes from a socket) and invalid data (encoding error) via the type of
+ // thrown exception. But it would be source-incompatible to make the methods in this interface do
+ // so since they were originally spec'ed to only throw InvalidProtocolBufferException. So callers
+ // must inspect the cause of the exception to distinguish these two cases.
+
+ /**
+ * Parses a message of {@code MessageType} from the input.
+ *
+ * <p>Note: The caller should call
+ * {@link CodedInputStream#checkLastTagWas(int)} after calling this to
+ * verify that the last tag seen was the appropriate end-group tag,
+ * or zero for EOF.
+ */
+ public MessageType parseFrom(CodedInputStream input)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Like {@link #parseFrom(CodedInputStream)}, but also parses extensions.
+ * The extensions that you want to be able to parse must be registered in
+ * {@code extensionRegistry}. Extensions not in the registry will be treated
+ * as unknown fields.
+ */
+ public MessageType parseFrom(CodedInputStream input,
+ ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Like {@link #parseFrom(CodedInputStream)}, but does not throw an
+ * exception if the message is missing required fields. Instead, a partial
+ * message is returned.
+ */
+ public MessageType parsePartialFrom(CodedInputStream input)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Like {@link #parseFrom(CodedInputStream input, ExtensionRegistryLite)},
+ * but does not throw an exception if the message is missing required fields.
+ * Instead, a partial message is returned.
+ */
+ public MessageType parsePartialFrom(CodedInputStream input,
+ ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+
+ // ---------------------------------------------------------------
+ // Convenience methods.
+
+ /**
+ * Parses {@code data} as a message of {@code MessageType}.
+ * This is just a small wrapper around {@link #parseFrom(CodedInputStream)}.
+ */
+ public MessageType parseFrom(ByteString data)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Parses {@code data} as a message of {@code MessageType}.
+ * This is just a small wrapper around
+ * {@link #parseFrom(CodedInputStream, ExtensionRegistryLite)}.
+ */
+ public MessageType parseFrom(ByteString data,
+ ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Like {@link #parseFrom(ByteString)}, but does not throw an
+ * exception if the message is missing required fields. Instead, a partial
+ * message is returned.
+ */
+ public MessageType parsePartialFrom(ByteString data)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Like {@link #parseFrom(ByteString, ExtensionRegistryLite)},
+ * but does not throw an exception if the message is missing required fields.
+ * Instead, a partial message is returned.
+ */
+ public MessageType parsePartialFrom(ByteString data,
+ ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Parses {@code data} as a message of {@code MessageType}.
+ * This is just a small wrapper around {@link #parseFrom(CodedInputStream)}.
+ */
+ public MessageType parseFrom(byte[] data, int off, int len)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Parses {@code data} as a message of {@code MessageType}.
+ * This is just a small wrapper around
+ * {@link #parseFrom(CodedInputStream, ExtensionRegistryLite)}.
+ */
+ public MessageType parseFrom(byte[] data, int off, int len,
+ ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Parses {@code data} as a message of {@code MessageType}.
+ * This is just a small wrapper around {@link #parseFrom(CodedInputStream)}.
+ */
+ public MessageType parseFrom(byte[] data)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Parses {@code data} as a message of {@code MessageType}.
+ * This is just a small wrapper around
+ * {@link #parseFrom(CodedInputStream, ExtensionRegistryLite)}.
+ */
+ public MessageType parseFrom(byte[] data,
+ ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Like {@link #parseFrom(byte[], int, int)}, but does not throw an
+ * exception if the message is missing required fields. Instead, a partial
+ * message is returned.
+ */
+ public MessageType parsePartialFrom(byte[] data, int off, int len)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Like {@link #parseFrom(ByteString, ExtensionRegistryLite)},
+ * but does not throw an exception if the message is missing required fields.
+ * Instead, a partial message is returned.
+ */
+ public MessageType parsePartialFrom(byte[] data, int off, int len,
+ ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Like {@link #parseFrom(byte[])}, but does not throw an
+ * exception if the message is missing required fields. Instead, a partial
+ * message is returned.
+ */
+ public MessageType parsePartialFrom(byte[] data)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Like {@link #parseFrom(byte[], ExtensionRegistryLite)},
+ * but does not throw an exception if the message is missing required fields.
+ * Instead, a partial message is returned.
+ */
+ public MessageType parsePartialFrom(byte[] data,
+ ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Parse a message of {@code MessageType} from {@code input}.
+ * This is just a small wrapper around {@link #parseFrom(CodedInputStream)}.
+ * Note that this method always reads the <i>entire</i> input (unless it
+ * throws an exception). If you want it to stop earlier, you will need to
+ * wrap your input in some wrapper stream that limits reading. Or, use
+ * {@link MessageLite#writeDelimitedTo(java.io.OutputStream)} to write your
+ * message and {@link #parseDelimitedFrom(InputStream)} to read it.
+ * <p>
+ * Despite usually reading the entire input, this does not close the stream.
+ */
+ public MessageType parseFrom(InputStream input)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Parses a message of {@code MessageType} from {@code input}.
+ * This is just a small wrapper around
+ * {@link #parseFrom(CodedInputStream, ExtensionRegistryLite)}.
+ */
+ public MessageType parseFrom(InputStream input,
+ ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Like {@link #parseFrom(InputStream)}, but does not throw an
+ * exception if the message is missing required fields. Instead, a partial
+ * message is returned.
+ */
+ public MessageType parsePartialFrom(InputStream input)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Like {@link #parseFrom(InputStream, ExtensionRegistryLite)},
+ * but does not throw an exception if the message is missing required fields.
+ * Instead, a partial message is returned.
+ */
+ public MessageType parsePartialFrom(InputStream input,
+ ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Like {@link #parseFrom(InputStream)}, but does not read util EOF.
+ * Instead, the size of message (encoded as a varint) is read first,
+ * then the message data. Use
+ * {@link MessageLite#writeDelimitedTo(java.io.OutputStream)} to write
+ * messages in this format.
+ *
+ * @return Parsed message if successful, or null if the stream is at EOF when
+ * the method starts. Any other error (including reaching EOF during
+ * parsing) will cause an exception to be thrown.
+ */
+ public MessageType parseDelimitedFrom(InputStream input)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Like {@link #parseDelimitedFrom(InputStream)} but supporting extensions.
+ */
+ public MessageType parseDelimitedFrom(InputStream input,
+ ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Like {@link #parseDelimitedFrom(InputStream)}, but does not throw an
+ * exception if the message is missing required fields. Instead, a partial
+ * message is returned.
+ */
+ public MessageType parsePartialDelimitedFrom(InputStream input)
+ throws InvalidProtocolBufferException;
+
+ /**
+ * Like {@link #parseDelimitedFrom(InputStream, ExtensionRegistryLite)},
+ * but does not throw an exception if the message is missing required fields.
+ * Instead, a partial message is returned.
+ */
+ public MessageType parsePartialDelimitedFrom(
+ InputStream input,
+ ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException;
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java
new file mode 100644
index 0000000000..81255ec291
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ProtobufArrayList.java
@@ -0,0 +1,105 @@
+// 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.ArrayList;
+import java.util.List;
+
+/**
+ * Implements {@link ProtobufList} for non-primitive and {@link String} types.
+ */
+final class ProtobufArrayList<E> extends AbstractProtobufList<E> {
+
+ private static final ProtobufArrayList<Object> EMPTY_LIST = new ProtobufArrayList<Object>();
+ static {
+ EMPTY_LIST.makeImmutable();
+ }
+
+ @SuppressWarnings("unchecked") // Guaranteed safe by runtime.
+ public static <E> ProtobufArrayList<E> emptyList() {
+ return (ProtobufArrayList<E>) EMPTY_LIST;
+ }
+
+ private final List<E> list;
+
+ ProtobufArrayList() {
+ this(new ArrayList<E>(DEFAULT_CAPACITY));
+ }
+
+ private ProtobufArrayList(List<E> list) {
+ this.list = list;
+ }
+
+ @Override
+ public ProtobufArrayList<E> mutableCopyWithCapacity(int capacity) {
+ if (capacity < size()) {
+ throw new IllegalArgumentException();
+ }
+ List<E> newList = new ArrayList<E>(capacity);
+ newList.addAll(list);
+ return new ProtobufArrayList<E>(newList);
+ }
+
+ @Override
+ public void add(int index, E element) {
+ ensureIsMutable();
+ list.add(index, element);
+ modCount++;
+ }
+
+ @Override
+ public E get(int index) {
+ return list.get(index);
+ }
+
+ @Override
+ public E remove(int index) {
+ ensureIsMutable();
+ E toReturn = list.remove(index);
+ modCount++;
+ return toReturn;
+ }
+
+ @Override
+ public E set(int index, E element) {
+ ensureIsMutable();
+ E toReturn = list.set(index, element);
+ modCount++;
+ return toReturn;
+ }
+
+ @Override
+ public int size() {
+ return list.size();
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ProtocolMessageEnum.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ProtocolMessageEnum.java
new file mode 100644
index 0000000000..a596d30190
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ProtocolMessageEnum.java
@@ -0,0 +1,59 @@
+// 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.EnumDescriptor;
+import com.google.protobuf.Descriptors.EnumValueDescriptor;
+
+/**
+ * Interface of useful methods added to all enums generated by the protocol
+ * compiler.
+ */
+public interface ProtocolMessageEnum extends Internal.EnumLite {
+
+ /**
+ * Return the value's numeric value as defined in the .proto file.
+ */
+ @Override
+ int getNumber();
+
+ /**
+ * Return the value's descriptor, which contains information such as
+ * value name, number, and type.
+ */
+ EnumValueDescriptor getValueDescriptor();
+
+ /**
+ * Return the enum type's descriptor, which contains information
+ * about each defined value, etc.
+ */
+ EnumDescriptor getDescriptorForType();
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ProtocolStringList.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ProtocolStringList.java
new file mode 100644
index 0000000000..d553b41e52
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ProtocolStringList.java
@@ -0,0 +1,48 @@
+// 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.util.List;
+
+/**
+ * An interface extending {@code List<String>} used for repeated string fields
+ * to provide optional access to the data as a list of ByteStrings. The
+ * underlying implementation stores values as either ByteStrings or Strings
+ * (see {@link LazyStringArrayList}) depending on how the value was initialized
+ * or last read, and it is often more efficient to deal with lists of
+ * ByteStrings when handling protos that have been deserialized from bytes.
+ */
+public interface ProtocolStringList extends List<String> {
+
+ /** Returns a view of the data as a list of ByteStrings. */
+ List<ByteString> asByteStringList();
+
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java
new file mode 100644
index 0000000000..29f567dcde
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java
@@ -0,0 +1,708 @@
+// 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.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * {@code RepeatedFieldBuilder} implements a structure that a protocol
+ * message uses to hold a repeated field of other protocol messages. It supports
+ * the classical use case of adding immutable {@link Message}'s to the
+ * repeated field and is highly optimized around this (no extra memory
+ * allocations and sharing of immutable arrays).
+ * <br>
+ * It also supports the additional use case of adding a {@link Message.Builder}
+ * to the repeated field and deferring conversion of that {@code Builder}
+ * to an immutable {@code Message}. In this way, it's possible to maintain
+ * a tree of {@code Builder}'s that acts as a fully read/write data
+ * structure.
+ * <br>
+ * Logically, one can think of a tree of builders as converting the entire tree
+ * to messages when build is called on the root or when any method is called
+ * that desires a Message instead of a Builder. In terms of the implementation,
+ * the {@code SingleFieldBuilder} and {@code RepeatedFieldBuilder}
+ * classes cache messages that were created so that messages only need to be
+ * created when some change occurred in its builder or a builder for one of its
+ * descendants.
+ *
+ * @param <MType> the type of message for the field
+ * @param <BType> the type of builder for the field
+ * @param <IType> the common interface for the message and the builder
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class RepeatedFieldBuilder
+ <MType extends GeneratedMessage,
+ BType extends GeneratedMessage.Builder,
+ IType extends MessageOrBuilder>
+ implements GeneratedMessage.BuilderParent {
+
+ // Parent to send changes to.
+ private GeneratedMessage.BuilderParent parent;
+
+ // List of messages. Never null. It may be immutable, in which case
+ // isMessagesListMutable will be false. See note below.
+ private List<MType> messages;
+
+ // Whether messages is an mutable array that can be modified.
+ private boolean isMessagesListMutable;
+
+ // List of builders. May be null, in which case, no nested builders were
+ // created. If not null, entries represent the builder for that index.
+ private List<SingleFieldBuilder<MType, BType, IType>> builders;
+
+ // Here are the invariants for messages and builders:
+ // 1. messages is never null and its count corresponds to the number of items
+ // in the repeated field.
+ // 2. If builders is non-null, messages and builders MUST always
+ // contain the same number of items.
+ // 3. Entries in either array can be null, but for any index, there MUST be
+ // either a Message in messages or a builder in builders.
+ // 4. If the builder at an index is non-null, the builder is
+ // authoritative. This is the case where a Builder was set on the index.
+ // Any message in the messages array MUST be ignored.
+ // t. If the builder at an index is null, the message in the messages
+ // list is authoritative. This is the case where a Message (not a Builder)
+ // was set directly for an index.
+
+ // Indicates that we've built a message and so we are now obligated
+ // to dispatch dirty invalidations. See GeneratedMessage.BuilderListener.
+ private boolean isClean;
+
+ // A view of this builder that exposes a List interface of messages. This is
+ // initialized on demand. This is fully backed by this object and all changes
+ // are reflected in it. Access to any item converts it to a message if it
+ // was a builder.
+ private MessageExternalList<MType, BType, IType> externalMessageList;
+
+ // A view of this builder that exposes a List interface of builders. This is
+ // initialized on demand. This is fully backed by this object and all changes
+ // are reflected in it. Access to any item converts it to a builder if it
+ // was a message.
+ private BuilderExternalList<MType, BType, IType> externalBuilderList;
+
+ // A view of this builder that exposes a List interface of the interface
+ // implemented by messages and builders. This is initialized on demand. This
+ // is fully backed by this object and all changes are reflected in it.
+ // Access to any item returns either a builder or message depending on
+ // what is most efficient.
+ private MessageOrBuilderExternalList<MType, BType, IType>
+ externalMessageOrBuilderList;
+
+ /**
+ * Constructs a new builder with an empty list of messages.
+ *
+ * @param messages the current list of messages
+ * @param isMessagesListMutable Whether the messages list is mutable
+ * @param parent a listener to notify of changes
+ * @param isClean whether the builder is initially marked clean
+ */
+ public RepeatedFieldBuilder(
+ List<MType> messages,
+ boolean isMessagesListMutable,
+ GeneratedMessage.BuilderParent parent,
+ boolean isClean) {
+ this.messages = messages;
+ this.isMessagesListMutable = isMessagesListMutable;
+ this.parent = parent;
+ this.isClean = isClean;
+ }
+
+ public void dispose() {
+ // Null out parent so we stop sending it invalidations.
+ parent = null;
+ }
+
+ /**
+ * Ensures that the list of messages is mutable so it can be updated. If it's
+ * immutable, a copy is made.
+ */
+ private void ensureMutableMessageList() {
+ if (!isMessagesListMutable) {
+ messages = new ArrayList<MType>(messages);
+ isMessagesListMutable = true;
+ }
+ }
+
+ /**
+ * Ensures that the list of builders is not null. If it's null, the list is
+ * created and initialized to be the same size as the messages list with
+ * null entries.
+ */
+ private void ensureBuilders() {
+ if (this.builders == null) {
+ this.builders =
+ new ArrayList<SingleFieldBuilder<MType, BType, IType>>(
+ messages.size());
+ for (int i = 0; i < messages.size(); i++) {
+ builders.add(null);
+ }
+ }
+ }
+
+ /**
+ * Gets the count of items in the list.
+ *
+ * @return the count of items in the list.
+ */
+ public int getCount() {
+ return messages.size();
+ }
+
+ /**
+ * Gets whether the list is empty.
+ *
+ * @return whether the list is empty
+ */
+ public boolean isEmpty() {
+ return messages.isEmpty();
+ }
+
+ /**
+ * Get the message at the specified index. If the message is currently stored
+ * as a {@code Builder}, it is converted to a {@code Message} by
+ * calling {@link Message.Builder#buildPartial} on it.
+ *
+ * @param index the index of the message to get
+ * @return the message for the specified index
+ */
+ public MType getMessage(int index) {
+ return getMessage(index, false);
+ }
+
+ /**
+ * Get the message at the specified index. If the message is currently stored
+ * as a {@code Builder}, it is converted to a {@code Message} by
+ * calling {@link Message.Builder#buildPartial} on it.
+ *
+ * @param index the index of the message to get
+ * @param forBuild this is being called for build so we want to make sure
+ * we SingleFieldBuilder.build to send dirty invalidations
+ * @return the message for the specified index
+ */
+ private MType getMessage(int index, boolean forBuild) {
+ if (this.builders == null) {
+ // We don't have any builders -- return the current Message.
+ // This is the case where no builder was created, so we MUST have a
+ // Message.
+ return messages.get(index);
+ }
+
+ SingleFieldBuilder<MType, BType, IType> builder = builders.get(index);
+ if (builder == null) {
+ // We don't have a builder -- return the current message.
+ // This is the case where no builder was created for the entry at index,
+ // so we MUST have a message.
+ return messages.get(index);
+
+ } else {
+ return forBuild ? builder.build() : builder.getMessage();
+ }
+ }
+
+ /**
+ * Gets a builder for the specified index. If no builder has been created for
+ * that index, a builder is created on demand by calling
+ * {@link Message#toBuilder}.
+ *
+ * @param index the index of the message to get
+ * @return The builder for that index
+ */
+ public BType getBuilder(int index) {
+ ensureBuilders();
+ SingleFieldBuilder<MType, BType, IType> builder = builders.get(index);
+ if (builder == null) {
+ MType message = messages.get(index);
+ builder = new SingleFieldBuilder<MType, BType, IType>(
+ message, this, isClean);
+ builders.set(index, builder);
+ }
+ return builder.getBuilder();
+ }
+
+ /**
+ * Gets the base class interface for the specified index. This may either be
+ * a builder or a message. It will return whatever is more efficient.
+ *
+ * @param index the index of the message to get
+ * @return the message or builder for the index as the base class interface
+ */
+ @SuppressWarnings("unchecked")
+ public IType getMessageOrBuilder(int index) {
+ if (this.builders == null) {
+ // We don't have any builders -- return the current Message.
+ // This is the case where no builder was created, so we MUST have a
+ // Message.
+ return (IType) messages.get(index);
+ }
+
+ SingleFieldBuilder<MType, BType, IType> builder = builders.get(index);
+ if (builder == null) {
+ // We don't have a builder -- return the current message.
+ // This is the case where no builder was created for the entry at index,
+ // so we MUST have a message.
+ return (IType) messages.get(index);
+
+ } else {
+ return builder.getMessageOrBuilder();
+ }
+ }
+
+ /**
+ * Sets a message at the specified index replacing the existing item at
+ * that index.
+ *
+ * @param index the index to set.
+ * @param message the message to set
+ * @return the builder
+ */
+ public RepeatedFieldBuilder<MType, BType, IType> setMessage(
+ int index, MType message) {
+ if (message == null) {
+ throw new NullPointerException();
+ }
+ ensureMutableMessageList();
+ messages.set(index, message);
+ if (builders != null) {
+ SingleFieldBuilder<MType, BType, IType> entry =
+ builders.set(index, null);
+ if (entry != null) {
+ entry.dispose();
+ }
+ }
+ onChanged();
+ incrementModCounts();
+ return this;
+ }
+
+ /**
+ * Appends the specified element to the end of this list.
+ *
+ * @param message the message to add
+ * @return the builder
+ */
+ public RepeatedFieldBuilder<MType, BType, IType> addMessage(
+ MType message) {
+ if (message == null) {
+ throw new NullPointerException();
+ }
+ ensureMutableMessageList();
+ messages.add(message);
+ if (builders != null) {
+ builders.add(null);
+ }
+ onChanged();
+ incrementModCounts();
+ return this;
+ }
+
+ /**
+ * Inserts the specified message at the specified position in this list.
+ * Shifts the element currently at that position (if any) and any subsequent
+ * elements to the right (adds one to their indices).
+ *
+ * @param index the index at which to insert the message
+ * @param message the message to add
+ * @return the builder
+ */
+ public RepeatedFieldBuilder<MType, BType, IType> addMessage(
+ int index, MType message) {
+ if (message == null) {
+ throw new NullPointerException();
+ }
+ ensureMutableMessageList();
+ messages.add(index, message);
+ if (builders != null) {
+ builders.add(index, null);
+ }
+ onChanged();
+ incrementModCounts();
+ return this;
+ }
+
+ /**
+ * Appends all of the messages in the specified collection to the end of
+ * this list, in the order that they are returned by the specified
+ * collection's iterator.
+ *
+ * @param values the messages to add
+ * @return the builder
+ */
+ public RepeatedFieldBuilder<MType, BType, IType> addAllMessages(
+ Iterable<? extends MType> values) {
+ for (final MType value : values) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ }
+
+ // If we can inspect the size, we can more efficiently add messages.
+ int size = -1;
+ if (values instanceof Collection) {
+ @SuppressWarnings("unchecked") final
+ Collection<MType> collection = (Collection<MType>) values;
+ if (collection.size() == 0) {
+ return this;
+ }
+ size = collection.size();
+ }
+ ensureMutableMessageList();
+
+ if (size >= 0 && messages instanceof ArrayList) {
+ ((ArrayList<MType>) messages)
+ .ensureCapacity(messages.size() + size);
+ }
+
+ for (MType value : values) {
+ addMessage(value);
+ }
+
+ onChanged();
+ incrementModCounts();
+ return this;
+ }
+
+ /**
+ * Appends a new builder to the end of this list and returns the builder.
+ *
+ * @param message the message to add which is the basis of the builder
+ * @return the new builder
+ */
+ public BType addBuilder(MType message) {
+ ensureMutableMessageList();
+ ensureBuilders();
+ SingleFieldBuilder<MType, BType, IType> builder =
+ new SingleFieldBuilder<MType, BType, IType>(
+ message, this, isClean);
+ messages.add(null);
+ builders.add(builder);
+ onChanged();
+ incrementModCounts();
+ return builder.getBuilder();
+ }
+
+ /**
+ * Inserts a new builder at the specified position in this list.
+ * Shifts the element currently at that position (if any) and any subsequent
+ * elements to the right (adds one to their indices).
+ *
+ * @param index the index at which to insert the builder
+ * @param message the message to add which is the basis of the builder
+ * @return the builder
+ */
+ public BType addBuilder(int index, MType message) {
+ ensureMutableMessageList();
+ ensureBuilders();
+ SingleFieldBuilder<MType, BType, IType> builder =
+ new SingleFieldBuilder<MType, BType, IType>(
+ message, this, isClean);
+ messages.add(index, null);
+ builders.add(index, builder);
+ onChanged();
+ incrementModCounts();
+ return builder.getBuilder();
+ }
+
+ /**
+ * Removes the element at the specified position in this list. Shifts any
+ * subsequent elements to the left (subtracts one from their indices).
+ * Returns the element that was removed from the list.
+ *
+ * @param index the index at which to remove the message
+ */
+ public void remove(int index) {
+ ensureMutableMessageList();
+ messages.remove(index);
+ if (builders != null) {
+ SingleFieldBuilder<MType, BType, IType> entry =
+ builders.remove(index);
+ if (entry != null) {
+ entry.dispose();
+ }
+ }
+ onChanged();
+ incrementModCounts();
+ }
+
+ /**
+ * Removes all of the elements from this list.
+ * The list will be empty after this call returns.
+ */
+ public void clear() {
+ messages = Collections.emptyList();
+ isMessagesListMutable = false;
+ if (builders != null) {
+ for (SingleFieldBuilder<MType, BType, IType> entry :
+ builders) {
+ if (entry != null) {
+ entry.dispose();
+ }
+ }
+ builders = null;
+ }
+ onChanged();
+ incrementModCounts();
+ }
+
+ /**
+ * Builds the list of messages from the builder and returns them.
+ *
+ * @return an immutable list of messages
+ */
+ public List<MType> build() {
+ // Now that build has been called, we are required to dispatch
+ // invalidations.
+ isClean = true;
+
+ if (!isMessagesListMutable && builders == null) {
+ // We still have an immutable list and we never created a builder.
+ return messages;
+ }
+
+ boolean allMessagesInSync = true;
+ if (!isMessagesListMutable) {
+ // We still have an immutable list. Let's see if any of them are out
+ // of sync with their builders.
+ for (int i = 0; i < messages.size(); i++) {
+ Message message = messages.get(i);
+ SingleFieldBuilder<MType, BType, IType> builder = builders.get(i);
+ if (builder != null) {
+ if (builder.build() != message) {
+ allMessagesInSync = false;
+ break;
+ }
+ }
+ }
+ if (allMessagesInSync) {
+ // Immutable list is still in sync.
+ return messages;
+ }
+ }
+
+ // Need to make sure messages is up to date
+ ensureMutableMessageList();
+ for (int i = 0; i < messages.size(); i++) {
+ messages.set(i, getMessage(i, true));
+ }
+
+ // We're going to return our list as immutable so we mark that we can
+ // no longer update it.
+ messages = Collections.unmodifiableList(messages);
+ isMessagesListMutable = false;
+ return messages;
+ }
+
+ /**
+ * Gets a view of the builder as a list of messages. The returned list is live
+ * and will reflect any changes to the underlying builder.
+ *
+ * @return the messages in the list
+ */
+ public List<MType> getMessageList() {
+ if (externalMessageList == null) {
+ externalMessageList =
+ new MessageExternalList<MType, BType, IType>(this);
+ }
+ return externalMessageList;
+ }
+
+ /**
+ * Gets a view of the builder as a list of builders. This returned list is
+ * live and will reflect any changes to the underlying builder.
+ *
+ * @return the builders in the list
+ */
+ public List<BType> getBuilderList() {
+ if (externalBuilderList == null) {
+ externalBuilderList =
+ new BuilderExternalList<MType, BType, IType>(this);
+ }
+ return externalBuilderList;
+ }
+
+ /**
+ * Gets a view of the builder as a list of MessageOrBuilders. This returned
+ * list is live and will reflect any changes to the underlying builder.
+ *
+ * @return the builders in the list
+ */
+ public List<IType> getMessageOrBuilderList() {
+ if (externalMessageOrBuilderList == null) {
+ externalMessageOrBuilderList =
+ new MessageOrBuilderExternalList<MType, BType, IType>(this);
+ }
+ return externalMessageOrBuilderList;
+ }
+
+ /**
+ * Called when a the builder or one of its nested children has changed
+ * and any parent should be notified of its invalidation.
+ */
+ private void onChanged() {
+ if (isClean && parent != null) {
+ parent.markDirty();
+
+ // Don't keep dispatching invalidations until build is called again.
+ isClean = false;
+ }
+ }
+
+ @Override
+ public void markDirty() {
+ onChanged();
+ }
+
+ /**
+ * Increments the mod counts so that an ConcurrentModificationException can
+ * be thrown if calling code tries to modify the builder while its iterating
+ * the list.
+ */
+ private void incrementModCounts() {
+ if (externalMessageList != null) {
+ externalMessageList.incrementModCount();
+ }
+ if (externalBuilderList != null) {
+ externalBuilderList.incrementModCount();
+ }
+ if (externalMessageOrBuilderList != null) {
+ externalMessageOrBuilderList.incrementModCount();
+ }
+ }
+
+ /**
+ * Provides a live view of the builder as a list of messages.
+ *
+ * @param <MType> the type of message for the field
+ * @param <BType> the type of builder for the field
+ * @param <IType> the common interface for the message and the builder
+ */
+ private static class MessageExternalList<
+ MType extends GeneratedMessage,
+ BType extends GeneratedMessage.Builder,
+ IType extends MessageOrBuilder>
+ extends AbstractList<MType> implements List<MType> {
+
+ RepeatedFieldBuilder<MType, BType, IType> builder;
+
+ MessageExternalList(
+ RepeatedFieldBuilder<MType, BType, IType> builder) {
+ this.builder = builder;
+ }
+
+ @Override
+ public int size() {
+ return this.builder.getCount();
+ }
+
+ @Override
+ public MType get(int index) {
+ return builder.getMessage(index);
+ }
+
+ void incrementModCount() {
+ modCount++;
+ }
+ }
+
+ /**
+ * Provides a live view of the builder as a list of builders.
+ *
+ * @param <MType> the type of message for the field
+ * @param <BType> the type of builder for the field
+ * @param <IType> the common interface for the message and the builder
+ */
+ private static class BuilderExternalList<
+ MType extends GeneratedMessage,
+ BType extends GeneratedMessage.Builder,
+ IType extends MessageOrBuilder>
+ extends AbstractList<BType> implements List<BType> {
+
+ RepeatedFieldBuilder<MType, BType, IType> builder;
+
+ BuilderExternalList(
+ RepeatedFieldBuilder<MType, BType, IType> builder) {
+ this.builder = builder;
+ }
+
+ @Override
+ public int size() {
+ return this.builder.getCount();
+ }
+
+ @Override
+ public BType get(int index) {
+ return builder.getBuilder(index);
+ }
+
+ void incrementModCount() {
+ modCount++;
+ }
+ }
+
+ /**
+ * Provides a live view of the builder as a list of builders.
+ *
+ * @param <MType> the type of message for the field
+ * @param <BType> the type of builder for the field
+ * @param <IType> the common interface for the message and the builder
+ */
+ private static class MessageOrBuilderExternalList<
+ MType extends GeneratedMessage,
+ BType extends GeneratedMessage.Builder,
+ IType extends MessageOrBuilder>
+ extends AbstractList<IType> implements List<IType> {
+
+ RepeatedFieldBuilder<MType, BType, IType> builder;
+
+ MessageOrBuilderExternalList(
+ RepeatedFieldBuilder<MType, BType, IType> builder) {
+ this.builder = builder;
+ }
+
+ @Override
+ public int size() {
+ return this.builder.getCount();
+ }
+
+ @Override
+ public IType get(int index) {
+ return builder.getMessageOrBuilder(index);
+ }
+
+ void incrementModCount() {
+ modCount++;
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java
new file mode 100644
index 0000000000..77b61b5f3c
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java
@@ -0,0 +1,708 @@
+// 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.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * {@code RepeatedFieldBuilderV3} implements a structure that a protocol
+ * message uses to hold a repeated field of other protocol messages. It supports
+ * the classical use case of adding immutable {@link Message}'s to the
+ * repeated field and is highly optimized around this (no extra memory
+ * allocations and sharing of immutable arrays).
+ * <br>
+ * It also supports the additional use case of adding a {@link Message.Builder}
+ * to the repeated field and deferring conversion of that {@code Builder}
+ * to an immutable {@code Message}. In this way, it's possible to maintain
+ * a tree of {@code Builder}'s that acts as a fully read/write data
+ * structure.
+ * <br>
+ * Logically, one can think of a tree of builders as converting the entire tree
+ * to messages when build is called on the root or when any method is called
+ * that desires a Message instead of a Builder. In terms of the implementation,
+ * the {@code SingleFieldBuilderV3} and {@code RepeatedFieldBuilderV3}
+ * classes cache messages that were created so that messages only need to be
+ * created when some change occurred in its builder or a builder for one of its
+ * descendants.
+ *
+ * @param <MType> the type of message for the field
+ * @param <BType> the type of builder for the field
+ * @param <IType> the common interface for the message and the builder
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class RepeatedFieldBuilderV3
+ <MType extends AbstractMessage,
+ BType extends AbstractMessage.Builder,
+ IType extends MessageOrBuilder>
+ implements AbstractMessage.BuilderParent {
+
+ // Parent to send changes to.
+ private AbstractMessage.BuilderParent parent;
+
+ // List of messages. Never null. It may be immutable, in which case
+ // isMessagesListMutable will be false. See note below.
+ private List<MType> messages;
+
+ // Whether messages is an mutable array that can be modified.
+ private boolean isMessagesListMutable;
+
+ // List of builders. May be null, in which case, no nested builders were
+ // created. If not null, entries represent the builder for that index.
+ private List<SingleFieldBuilderV3<MType, BType, IType>> builders;
+
+ // Here are the invariants for messages and builders:
+ // 1. messages is never null and its count corresponds to the number of items
+ // in the repeated field.
+ // 2. If builders is non-null, messages and builders MUST always
+ // contain the same number of items.
+ // 3. Entries in either array can be null, but for any index, there MUST be
+ // either a Message in messages or a builder in builders.
+ // 4. If the builder at an index is non-null, the builder is
+ // authoritative. This is the case where a Builder was set on the index.
+ // Any message in the messages array MUST be ignored.
+ // t. If the builder at an index is null, the message in the messages
+ // list is authoritative. This is the case where a Message (not a Builder)
+ // was set directly for an index.
+
+ // Indicates that we've built a message and so we are now obligated
+ // to dispatch dirty invalidations. See AbstractMessage.BuilderListener.
+ private boolean isClean;
+
+ // A view of this builder that exposes a List interface of messages. This is
+ // initialized on demand. This is fully backed by this object and all changes
+ // are reflected in it. Access to any item converts it to a message if it
+ // was a builder.
+ private MessageExternalList<MType, BType, IType> externalMessageList;
+
+ // A view of this builder that exposes a List interface of builders. This is
+ // initialized on demand. This is fully backed by this object and all changes
+ // are reflected in it. Access to any item converts it to a builder if it
+ // was a message.
+ private BuilderExternalList<MType, BType, IType> externalBuilderList;
+
+ // A view of this builder that exposes a List interface of the interface
+ // implemented by messages and builders. This is initialized on demand. This
+ // is fully backed by this object and all changes are reflected in it.
+ // Access to any item returns either a builder or message depending on
+ // what is most efficient.
+ private MessageOrBuilderExternalList<MType, BType, IType>
+ externalMessageOrBuilderList;
+
+ /**
+ * Constructs a new builder with an empty list of messages.
+ *
+ * @param messages the current list of messages
+ * @param isMessagesListMutable Whether the messages list is mutable
+ * @param parent a listener to notify of changes
+ * @param isClean whether the builder is initially marked clean
+ */
+ public RepeatedFieldBuilderV3(
+ List<MType> messages,
+ boolean isMessagesListMutable,
+ AbstractMessage.BuilderParent parent,
+ boolean isClean) {
+ this.messages = messages;
+ this.isMessagesListMutable = isMessagesListMutable;
+ this.parent = parent;
+ this.isClean = isClean;
+ }
+
+ public void dispose() {
+ // Null out parent so we stop sending it invalidations.
+ parent = null;
+ }
+
+ /**
+ * Ensures that the list of messages is mutable so it can be updated. If it's
+ * immutable, a copy is made.
+ */
+ private void ensureMutableMessageList() {
+ if (!isMessagesListMutable) {
+ messages = new ArrayList<MType>(messages);
+ isMessagesListMutable = true;
+ }
+ }
+
+ /**
+ * Ensures that the list of builders is not null. If it's null, the list is
+ * created and initialized to be the same size as the messages list with
+ * null entries.
+ */
+ private void ensureBuilders() {
+ if (this.builders == null) {
+ this.builders =
+ new ArrayList<SingleFieldBuilderV3<MType, BType, IType>>(
+ messages.size());
+ for (int i = 0; i < messages.size(); i++) {
+ builders.add(null);
+ }
+ }
+ }
+
+ /**
+ * Gets the count of items in the list.
+ *
+ * @return the count of items in the list.
+ */
+ public int getCount() {
+ return messages.size();
+ }
+
+ /**
+ * Gets whether the list is empty.
+ *
+ * @return whether the list is empty
+ */
+ public boolean isEmpty() {
+ return messages.isEmpty();
+ }
+
+ /**
+ * Get the message at the specified index. If the message is currently stored
+ * as a {@code Builder}, it is converted to a {@code Message} by
+ * calling {@link Message.Builder#buildPartial} on it.
+ *
+ * @param index the index of the message to get
+ * @return the message for the specified index
+ */
+ public MType getMessage(int index) {
+ return getMessage(index, false);
+ }
+
+ /**
+ * Get the message at the specified index. If the message is currently stored
+ * as a {@code Builder}, it is converted to a {@code Message} by
+ * calling {@link Message.Builder#buildPartial} on it.
+ *
+ * @param index the index of the message to get
+ * @param forBuild this is being called for build so we want to make sure
+ * we SingleFieldBuilderV3.build to send dirty invalidations
+ * @return the message for the specified index
+ */
+ private MType getMessage(int index, boolean forBuild) {
+ if (this.builders == null) {
+ // We don't have any builders -- return the current Message.
+ // This is the case where no builder was created, so we MUST have a
+ // Message.
+ return messages.get(index);
+ }
+
+ SingleFieldBuilderV3<MType, BType, IType> builder = builders.get(index);
+ if (builder == null) {
+ // We don't have a builder -- return the current message.
+ // This is the case where no builder was created for the entry at index,
+ // so we MUST have a message.
+ return messages.get(index);
+
+ } else {
+ return forBuild ? builder.build() : builder.getMessage();
+ }
+ }
+
+ /**
+ * Gets a builder for the specified index. If no builder has been created for
+ * that index, a builder is created on demand by calling
+ * {@link Message#toBuilder}.
+ *
+ * @param index the index of the message to get
+ * @return The builder for that index
+ */
+ public BType getBuilder(int index) {
+ ensureBuilders();
+ SingleFieldBuilderV3<MType, BType, IType> builder = builders.get(index);
+ if (builder == null) {
+ MType message = messages.get(index);
+ builder = new SingleFieldBuilderV3<MType, BType, IType>(
+ message, this, isClean);
+ builders.set(index, builder);
+ }
+ return builder.getBuilder();
+ }
+
+ /**
+ * Gets the base class interface for the specified index. This may either be
+ * a builder or a message. It will return whatever is more efficient.
+ *
+ * @param index the index of the message to get
+ * @return the message or builder for the index as the base class interface
+ */
+ @SuppressWarnings("unchecked")
+ public IType getMessageOrBuilder(int index) {
+ if (this.builders == null) {
+ // We don't have any builders -- return the current Message.
+ // This is the case where no builder was created, so we MUST have a
+ // Message.
+ return (IType) messages.get(index);
+ }
+
+ SingleFieldBuilderV3<MType, BType, IType> builder = builders.get(index);
+ if (builder == null) {
+ // We don't have a builder -- return the current message.
+ // This is the case where no builder was created for the entry at index,
+ // so we MUST have a message.
+ return (IType) messages.get(index);
+
+ } else {
+ return builder.getMessageOrBuilder();
+ }
+ }
+
+ /**
+ * Sets a message at the specified index replacing the existing item at
+ * that index.
+ *
+ * @param index the index to set.
+ * @param message the message to set
+ * @return the builder
+ */
+ public RepeatedFieldBuilderV3<MType, BType, IType> setMessage(
+ int index, MType message) {
+ if (message == null) {
+ throw new NullPointerException();
+ }
+ ensureMutableMessageList();
+ messages.set(index, message);
+ if (builders != null) {
+ SingleFieldBuilderV3<MType, BType, IType> entry =
+ builders.set(index, null);
+ if (entry != null) {
+ entry.dispose();
+ }
+ }
+ onChanged();
+ incrementModCounts();
+ return this;
+ }
+
+ /**
+ * Appends the specified element to the end of this list.
+ *
+ * @param message the message to add
+ * @return the builder
+ */
+ public RepeatedFieldBuilderV3<MType, BType, IType> addMessage(
+ MType message) {
+ if (message == null) {
+ throw new NullPointerException();
+ }
+ ensureMutableMessageList();
+ messages.add(message);
+ if (builders != null) {
+ builders.add(null);
+ }
+ onChanged();
+ incrementModCounts();
+ return this;
+ }
+
+ /**
+ * Inserts the specified message at the specified position in this list.
+ * Shifts the element currently at that position (if any) and any subsequent
+ * elements to the right (adds one to their indices).
+ *
+ * @param index the index at which to insert the message
+ * @param message the message to add
+ * @return the builder
+ */
+ public RepeatedFieldBuilderV3<MType, BType, IType> addMessage(
+ int index, MType message) {
+ if (message == null) {
+ throw new NullPointerException();
+ }
+ ensureMutableMessageList();
+ messages.add(index, message);
+ if (builders != null) {
+ builders.add(index, null);
+ }
+ onChanged();
+ incrementModCounts();
+ return this;
+ }
+
+ /**
+ * Appends all of the messages in the specified collection to the end of
+ * this list, in the order that they are returned by the specified
+ * collection's iterator.
+ *
+ * @param values the messages to add
+ * @return the builder
+ */
+ public RepeatedFieldBuilderV3<MType, BType, IType> addAllMessages(
+ Iterable<? extends MType> values) {
+ for (final MType value : values) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ }
+
+ // If we can inspect the size, we can more efficiently add messages.
+ int size = -1;
+ if (values instanceof Collection) {
+ @SuppressWarnings("unchecked") final
+ Collection<MType> collection = (Collection<MType>) values;
+ if (collection.size() == 0) {
+ return this;
+ }
+ size = collection.size();
+ }
+ ensureMutableMessageList();
+
+ if (size >= 0 && messages instanceof ArrayList) {
+ ((ArrayList<MType>) messages)
+ .ensureCapacity(messages.size() + size);
+ }
+
+ for (MType value : values) {
+ addMessage(value);
+ }
+
+ onChanged();
+ incrementModCounts();
+ return this;
+ }
+
+ /**
+ * Appends a new builder to the end of this list and returns the builder.
+ *
+ * @param message the message to add which is the basis of the builder
+ * @return the new builder
+ */
+ public BType addBuilder(MType message) {
+ ensureMutableMessageList();
+ ensureBuilders();
+ SingleFieldBuilderV3<MType, BType, IType> builder =
+ new SingleFieldBuilderV3<MType, BType, IType>(
+ message, this, isClean);
+ messages.add(null);
+ builders.add(builder);
+ onChanged();
+ incrementModCounts();
+ return builder.getBuilder();
+ }
+
+ /**
+ * Inserts a new builder at the specified position in this list.
+ * Shifts the element currently at that position (if any) and any subsequent
+ * elements to the right (adds one to their indices).
+ *
+ * @param index the index at which to insert the builder
+ * @param message the message to add which is the basis of the builder
+ * @return the builder
+ */
+ public BType addBuilder(int index, MType message) {
+ ensureMutableMessageList();
+ ensureBuilders();
+ SingleFieldBuilderV3<MType, BType, IType> builder =
+ new SingleFieldBuilderV3<MType, BType, IType>(
+ message, this, isClean);
+ messages.add(index, null);
+ builders.add(index, builder);
+ onChanged();
+ incrementModCounts();
+ return builder.getBuilder();
+ }
+
+ /**
+ * Removes the element at the specified position in this list. Shifts any
+ * subsequent elements to the left (subtracts one from their indices).
+ * Returns the element that was removed from the list.
+ *
+ * @param index the index at which to remove the message
+ */
+ public void remove(int index) {
+ ensureMutableMessageList();
+ messages.remove(index);
+ if (builders != null) {
+ SingleFieldBuilderV3<MType, BType, IType> entry =
+ builders.remove(index);
+ if (entry != null) {
+ entry.dispose();
+ }
+ }
+ onChanged();
+ incrementModCounts();
+ }
+
+ /**
+ * Removes all of the elements from this list.
+ * The list will be empty after this call returns.
+ */
+ public void clear() {
+ messages = Collections.emptyList();
+ isMessagesListMutable = false;
+ if (builders != null) {
+ for (SingleFieldBuilderV3<MType, BType, IType> entry :
+ builders) {
+ if (entry != null) {
+ entry.dispose();
+ }
+ }
+ builders = null;
+ }
+ onChanged();
+ incrementModCounts();
+ }
+
+ /**
+ * Builds the list of messages from the builder and returns them.
+ *
+ * @return an immutable list of messages
+ */
+ public List<MType> build() {
+ // Now that build has been called, we are required to dispatch
+ // invalidations.
+ isClean = true;
+
+ if (!isMessagesListMutable && builders == null) {
+ // We still have an immutable list and we never created a builder.
+ return messages;
+ }
+
+ boolean allMessagesInSync = true;
+ if (!isMessagesListMutable) {
+ // We still have an immutable list. Let's see if any of them are out
+ // of sync with their builders.
+ for (int i = 0; i < messages.size(); i++) {
+ Message message = messages.get(i);
+ SingleFieldBuilderV3<MType, BType, IType> builder = builders.get(i);
+ if (builder != null) {
+ if (builder.build() != message) {
+ allMessagesInSync = false;
+ break;
+ }
+ }
+ }
+ if (allMessagesInSync) {
+ // Immutable list is still in sync.
+ return messages;
+ }
+ }
+
+ // Need to make sure messages is up to date
+ ensureMutableMessageList();
+ for (int i = 0; i < messages.size(); i++) {
+ messages.set(i, getMessage(i, true));
+ }
+
+ // We're going to return our list as immutable so we mark that we can
+ // no longer update it.
+ messages = Collections.unmodifiableList(messages);
+ isMessagesListMutable = false;
+ return messages;
+ }
+
+ /**
+ * Gets a view of the builder as a list of messages. The returned list is live
+ * and will reflect any changes to the underlying builder.
+ *
+ * @return the messages in the list
+ */
+ public List<MType> getMessageList() {
+ if (externalMessageList == null) {
+ externalMessageList =
+ new MessageExternalList<MType, BType, IType>(this);
+ }
+ return externalMessageList;
+ }
+
+ /**
+ * Gets a view of the builder as a list of builders. This returned list is
+ * live and will reflect any changes to the underlying builder.
+ *
+ * @return the builders in the list
+ */
+ public List<BType> getBuilderList() {
+ if (externalBuilderList == null) {
+ externalBuilderList =
+ new BuilderExternalList<MType, BType, IType>(this);
+ }
+ return externalBuilderList;
+ }
+
+ /**
+ * Gets a view of the builder as a list of MessageOrBuilders. This returned
+ * list is live and will reflect any changes to the underlying builder.
+ *
+ * @return the builders in the list
+ */
+ public List<IType> getMessageOrBuilderList() {
+ if (externalMessageOrBuilderList == null) {
+ externalMessageOrBuilderList =
+ new MessageOrBuilderExternalList<MType, BType, IType>(this);
+ }
+ return externalMessageOrBuilderList;
+ }
+
+ /**
+ * Called when a the builder or one of its nested children has changed
+ * and any parent should be notified of its invalidation.
+ */
+ private void onChanged() {
+ if (isClean && parent != null) {
+ parent.markDirty();
+
+ // Don't keep dispatching invalidations until build is called again.
+ isClean = false;
+ }
+ }
+
+ @Override
+ public void markDirty() {
+ onChanged();
+ }
+
+ /**
+ * Increments the mod counts so that an ConcurrentModificationException can
+ * be thrown if calling code tries to modify the builder while its iterating
+ * the list.
+ */
+ private void incrementModCounts() {
+ if (externalMessageList != null) {
+ externalMessageList.incrementModCount();
+ }
+ if (externalBuilderList != null) {
+ externalBuilderList.incrementModCount();
+ }
+ if (externalMessageOrBuilderList != null) {
+ externalMessageOrBuilderList.incrementModCount();
+ }
+ }
+
+ /**
+ * Provides a live view of the builder as a list of messages.
+ *
+ * @param <MType> the type of message for the field
+ * @param <BType> the type of builder for the field
+ * @param <IType> the common interface for the message and the builder
+ */
+ private static class MessageExternalList<
+ MType extends AbstractMessage,
+ BType extends AbstractMessage.Builder,
+ IType extends MessageOrBuilder>
+ extends AbstractList<MType> implements List<MType> {
+
+ RepeatedFieldBuilderV3<MType, BType, IType> builder;
+
+ MessageExternalList(
+ RepeatedFieldBuilderV3<MType, BType, IType> builder) {
+ this.builder = builder;
+ }
+
+ @Override
+ public int size() {
+ return this.builder.getCount();
+ }
+
+ @Override
+ public MType get(int index) {
+ return builder.getMessage(index);
+ }
+
+ void incrementModCount() {
+ modCount++;
+ }
+ }
+
+ /**
+ * Provides a live view of the builder as a list of builders.
+ *
+ * @param <MType> the type of message for the field
+ * @param <BType> the type of builder for the field
+ * @param <IType> the common interface for the message and the builder
+ */
+ private static class BuilderExternalList<
+ MType extends AbstractMessage,
+ BType extends AbstractMessage.Builder,
+ IType extends MessageOrBuilder>
+ extends AbstractList<BType> implements List<BType> {
+
+ RepeatedFieldBuilderV3<MType, BType, IType> builder;
+
+ BuilderExternalList(
+ RepeatedFieldBuilderV3<MType, BType, IType> builder) {
+ this.builder = builder;
+ }
+
+ @Override
+ public int size() {
+ return this.builder.getCount();
+ }
+
+ @Override
+ public BType get(int index) {
+ return builder.getBuilder(index);
+ }
+
+ void incrementModCount() {
+ modCount++;
+ }
+ }
+
+ /**
+ * Provides a live view of the builder as a list of builders.
+ *
+ * @param <MType> the type of message for the field
+ * @param <BType> the type of builder for the field
+ * @param <IType> the common interface for the message and the builder
+ */
+ private static class MessageOrBuilderExternalList<
+ MType extends AbstractMessage,
+ BType extends AbstractMessage.Builder,
+ IType extends MessageOrBuilder>
+ extends AbstractList<IType> implements List<IType> {
+
+ RepeatedFieldBuilderV3<MType, BType, IType> builder;
+
+ MessageOrBuilderExternalList(
+ RepeatedFieldBuilderV3<MType, BType, IType> builder) {
+ this.builder = builder;
+ }
+
+ @Override
+ public int size() {
+ return this.builder.getCount();
+ }
+
+ @Override
+ public IType get(int index) {
+ return builder.getMessageOrBuilder(index);
+ }
+
+ void incrementModCount() {
+ modCount++;
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RopeByteString.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RopeByteString.java
new file mode 100644
index 0000000000..6fa555df15
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RopeByteString.java
@@ -0,0 +1,897 @@
+// 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.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Stack;
+
+/**
+ * Class to represent {@code ByteStrings} formed by concatenation of other
+ * ByteStrings, without copying the data in the pieces. The concatenation is
+ * represented as a tree whose leaf nodes are each a
+ * {@link com.google.protobuf.ByteString.LeafByteString}.
+ *
+ * <p>Most of the operation here is inspired by the now-famous paper <a
+ * href="https://web.archive.org/web/20060202015456/http://www.cs.ubc.ca/local/reading/proceedings/spe91-95/spe/vol25/issue12/spe986.pdf">
+ * BAP95 </a> Ropes: an Alternative to Strings hans-j. boehm, russ atkinson and
+ * michael plass
+ *
+ * <p>The algorithms described in the paper have been implemented for character
+ * strings in {@code com.google.common.string.Rope} and in the c++ class {@code
+ * cord.cc}.
+ *
+ * <p>Fundamentally the Rope algorithm represents the collection of pieces as a
+ * binary tree. BAP95 uses a Fibonacci bound relating depth to a minimum
+ * sequence length, sequences that are too short relative to their depth cause a
+ * tree rebalance. More precisely, a tree of depth d is "balanced" in the
+ * terminology of BAP95 if its length is at least F(d+2), where F(n) is the
+ * n-the Fibonacci number. Thus for depths 0, 1, 2, 3, 4, 5,... we have minimum
+ * lengths 1, 2, 3, 5, 8, 13,...
+ *
+ * @author carlanton@google.com (Carl Haverl)
+ */
+final class RopeByteString extends ByteString {
+
+ /**
+ * BAP95. Let Fn be the nth Fibonacci number. A {@link RopeByteString} of
+ * depth n is "balanced", i.e flat enough, if its length is at least Fn+2,
+ * e.g. a "balanced" {@link RopeByteString} of depth 1 must have length at
+ * least 2, of depth 4 must have length >= 8, etc.
+ *
+ * <p>There's nothing special about using the Fibonacci numbers for this, but
+ * they are a reasonable sequence for encapsulating the idea that we are OK
+ * with longer strings being encoded in deeper binary trees.
+ *
+ * <p>For 32-bit integers, this array has length 46.
+ */
+ private static final int[] minLengthByDepth;
+
+ static {
+ // Dynamically generate the list of Fibonacci numbers the first time this
+ // class is accessed.
+ List<Integer> numbers = new ArrayList<Integer>();
+
+ // we skip the first Fibonacci number (1). So instead of: 1 1 2 3 5 8 ...
+ // we have: 1 2 3 5 8 ...
+ int f1 = 1;
+ int f2 = 1;
+
+ // get all the values until we roll over.
+ while (f2 > 0) {
+ numbers.add(f2);
+ int temp = f1 + f2;
+ f1 = f2;
+ f2 = temp;
+ }
+
+ // we include this here so that we can index this array to [x + 1] in the
+ // loops below.
+ numbers.add(Integer.MAX_VALUE);
+ minLengthByDepth = new int[numbers.size()];
+ for (int i = 0; i < minLengthByDepth.length; i++) {
+ // unbox all the values
+ minLengthByDepth[i] = numbers.get(i);
+ }
+ }
+
+ private final int totalLength;
+ private final ByteString left;
+ private final ByteString right;
+ private final int leftLength;
+ private final int treeDepth;
+
+ /**
+ * Create a new RopeByteString, which can be thought of as a new tree node, by
+ * recording references to the two given strings.
+ *
+ * @param left string on the left of this node, should have {@code size() >
+ * 0}
+ * @param right string on the right of this node, should have {@code size() >
+ * 0}
+ */
+ private RopeByteString(ByteString left, ByteString right) {
+ this.left = left;
+ this.right = right;
+ leftLength = left.size();
+ totalLength = leftLength + right.size();
+ treeDepth = Math.max(left.getTreeDepth(), right.getTreeDepth()) + 1;
+ }
+
+ /**
+ * Concatenate the given strings while performing various optimizations to
+ * slow the growth rate of tree depth and tree node count. The result is
+ * either a {@link com.google.protobuf.ByteString.LeafByteString} or a
+ * {@link RopeByteString} depending on which optimizations, if any, were
+ * applied.
+ *
+ * <p>Small pieces of length less than {@link
+ * ByteString#CONCATENATE_BY_COPY_SIZE} may be copied by value here, as in
+ * BAP95. Large pieces are referenced without copy.
+ *
+ * @param left string on the left
+ * @param right string on the right
+ * @return concatenation representing the same sequence as the given strings
+ */
+ static ByteString concatenate(ByteString left, ByteString right) {
+ if (right.size() == 0) {
+ return left;
+ }
+
+ if (left.size() == 0) {
+ return right;
+ }
+
+ final int newLength = left.size() + right.size();
+ if (newLength < ByteString.CONCATENATE_BY_COPY_SIZE) {
+ // Optimization from BAP95: For short (leaves in paper, but just short
+ // here) total length, do a copy of data to a new leaf.
+ return concatenateBytes(left, right);
+ }
+
+ if (left instanceof RopeByteString) {
+ final RopeByteString leftRope = (RopeByteString) left;
+ if (leftRope.right.size() + right.size() < CONCATENATE_BY_COPY_SIZE) {
+ // Optimization from BAP95: As an optimization of the case where the
+ // ByteString is constructed by repeated concatenate, recognize the case
+ // where a short string is concatenated to a left-hand node whose
+ // right-hand branch is short. In the paper this applies to leaves, but
+ // we just look at the length here. This has the advantage of shedding
+ // references to unneeded data when substrings have been taken.
+ //
+ // When we recognize this case, we do a copy of the data and create a
+ // new parent node so that the depth of the result is the same as the
+ // given left tree.
+ ByteString newRight = concatenateBytes(leftRope.right, right);
+ return new RopeByteString(leftRope.left, newRight);
+ }
+
+ if (leftRope.left.getTreeDepth() > leftRope.right.getTreeDepth()
+ && leftRope.getTreeDepth() > right.getTreeDepth()) {
+ // Typically for concatenate-built strings the left-side is deeper than
+ // the right. This is our final attempt to concatenate without
+ // increasing the tree depth. We'll redo the node on the RHS. This
+ // is yet another optimization for building the string by repeatedly
+ // concatenating on the right.
+ ByteString newRight = new RopeByteString(leftRope.right, right);
+ return new RopeByteString(leftRope.left, newRight);
+ }
+ }
+
+ // Fine, we'll add a node and increase the tree depth--unless we rebalance ;^)
+ int newDepth = Math.max(left.getTreeDepth(), right.getTreeDepth()) + 1;
+ if (newLength >= minLengthByDepth[newDepth]) {
+ // The tree is shallow enough, so don't rebalance
+ return new RopeByteString(left, right);
+ }
+
+ return new Balancer().balance(left, right);
+ }
+
+ /**
+ * Concatenates two strings by copying data values. This is called in a few
+ * cases in order to reduce the growth of the number of tree nodes.
+ *
+ * @param left string on the left
+ * @param right string on the right
+ * @return string formed by copying data bytes
+ */
+ private static ByteString concatenateBytes(ByteString left,
+ ByteString right) {
+ int leftSize = left.size();
+ int rightSize = right.size();
+ byte[] bytes = new byte[leftSize + rightSize];
+ left.copyTo(bytes, 0, 0, leftSize);
+ right.copyTo(bytes, 0, leftSize, rightSize);
+ return ByteString.wrap(bytes); // Constructor wraps bytes
+ }
+
+ /**
+ * Create a new RopeByteString for testing only while bypassing all the
+ * defenses of {@link #concatenate(ByteString, ByteString)}. This allows
+ * testing trees of specific structure. We are also able to insert empty
+ * leaves, though these are dis-allowed, so that we can make sure the
+ * implementation can withstand their presence.
+ *
+ * @param left string on the left of this node
+ * @param right string on the right of this node
+ * @return an unsafe instance for testing only
+ */
+ static RopeByteString newInstanceForTest(ByteString left, ByteString right) {
+ return new RopeByteString(left, right);
+ }
+
+ /**
+ * Gets the byte at the given index.
+ * Throws {@link ArrayIndexOutOfBoundsException} for backwards-compatibility
+ * reasons although it would more properly be {@link
+ * IndexOutOfBoundsException}.
+ *
+ * @param index index of byte
+ * @return the value
+ * @throws ArrayIndexOutOfBoundsException {@code index} is < 0 or >= size
+ */
+ @Override
+ public byte byteAt(int index) {
+ checkIndex(index, totalLength);
+
+ // Find the relevant piece by recursive descent
+ if (index < leftLength) {
+ return left.byteAt(index);
+ }
+
+ return right.byteAt(index - leftLength);
+ }
+
+ @Override
+ public int size() {
+ return totalLength;
+ }
+
+ // =================================================================
+ // Pieces
+
+ @Override
+ protected int getTreeDepth() {
+ return treeDepth;
+ }
+
+ /**
+ * Determines if the tree is balanced according to BAP95, which means the tree
+ * is flat-enough with respect to the bounds. Note that this definition of
+ * balanced is one where sub-trees of balanced trees are not necessarily
+ * balanced.
+ *
+ * @return true if the tree is balanced
+ */
+ @Override
+ protected boolean isBalanced() {
+ return totalLength >= minLengthByDepth[treeDepth];
+ }
+
+ /**
+ * Takes a substring of this one. This involves recursive descent along the
+ * left and right edges of the substring, and referencing any wholly contained
+ * segments in between. Any leaf nodes entirely uninvolved in the substring
+ * will not be referenced by the substring.
+ *
+ * <p>Substrings of {@code length < 2} should result in at most a single
+ * recursive call chain, terminating at a leaf node. Thus the result will be a
+ * {@link com.google.protobuf.ByteString.LeafByteString}.
+ *
+ * @param beginIndex start at this index
+ * @param endIndex the last character is the one before this index
+ * @return substring leaf node or tree
+ */
+ @Override
+ public ByteString substring(int beginIndex, int endIndex) {
+ final int length = checkRange(beginIndex, endIndex, totalLength);
+
+ if (length == 0) {
+ // Empty substring
+ return ByteString.EMPTY;
+ }
+
+ if (length == totalLength) {
+ // The whole string
+ return this;
+ }
+
+ // Proper substring
+ if (endIndex <= leftLength) {
+ // Substring on the left
+ return left.substring(beginIndex, endIndex);
+ }
+
+ if (beginIndex >= leftLength) {
+ // Substring on the right
+ return right.substring(beginIndex - leftLength, endIndex - leftLength);
+ }
+
+ // Split substring
+ ByteString leftSub = left.substring(beginIndex);
+ ByteString rightSub = right.substring(0, endIndex - leftLength);
+ // Intentionally not rebalancing, since in many cases these two
+ // substrings will already be less deep than the top-level
+ // RopeByteString we're taking a substring of.
+ return new RopeByteString(leftSub, rightSub);
+ }
+
+ // =================================================================
+ // ByteString -> byte[]
+
+ @Override
+ protected void copyToInternal(byte[] target, int sourceOffset,
+ int targetOffset, int numberToCopy) {
+ if (sourceOffset + numberToCopy <= leftLength) {
+ left.copyToInternal(target, sourceOffset, targetOffset, numberToCopy);
+ } else if (sourceOffset >= leftLength) {
+ right.copyToInternal(target, sourceOffset - leftLength, targetOffset,
+ numberToCopy);
+ } else {
+ int leftLength = this.leftLength - sourceOffset;
+ left.copyToInternal(target, sourceOffset, targetOffset, leftLength);
+ right.copyToInternal(target, 0, targetOffset + leftLength,
+ numberToCopy - leftLength);
+ }
+ }
+
+ @Override
+ public void copyTo(ByteBuffer target) {
+ left.copyTo(target);
+ right.copyTo(target);
+ }
+
+ @Override
+ public ByteBuffer asReadOnlyByteBuffer() {
+ ByteBuffer byteBuffer = ByteBuffer.wrap(toByteArray());
+ return byteBuffer.asReadOnlyBuffer();
+ }
+
+ @Override
+ public List<ByteBuffer> asReadOnlyByteBufferList() {
+ // Walk through the list of LeafByteString's that make up this
+ // rope, and add each one as a read-only ByteBuffer.
+ List<ByteBuffer> result = new ArrayList<ByteBuffer>();
+ PieceIterator pieces = new PieceIterator(this);
+ while (pieces.hasNext()) {
+ LeafByteString byteString = pieces.next();
+ result.add(byteString.asReadOnlyByteBuffer());
+ }
+ return result;
+ }
+
+ @Override
+ public void writeTo(OutputStream outputStream) throws IOException {
+ left.writeTo(outputStream);
+ right.writeTo(outputStream);
+ }
+
+ @Override
+ void writeToInternal(OutputStream out, int sourceOffset,
+ int numberToWrite) throws IOException {
+ if (sourceOffset + numberToWrite <= leftLength) {
+ left.writeToInternal(out, sourceOffset, numberToWrite);
+ } else if (sourceOffset >= leftLength) {
+ right.writeToInternal(out, sourceOffset - leftLength, numberToWrite);
+ } else {
+ int numberToWriteInLeft = leftLength - sourceOffset;
+ left.writeToInternal(out, sourceOffset, numberToWriteInLeft);
+ right.writeToInternal(out, 0, numberToWrite - numberToWriteInLeft);
+ }
+ }
+
+ @Override
+ void writeTo(ByteOutput output) throws IOException {
+ left.writeTo(output);
+ right.writeTo(output);
+ }
+
+
+ @Override
+ protected String toStringInternal(Charset charset) {
+ return new String(toByteArray(), charset);
+ }
+
+ // =================================================================
+ // UTF-8 decoding
+
+ @Override
+ public boolean isValidUtf8() {
+ int leftPartial = left.partialIsValidUtf8(Utf8.COMPLETE, 0, leftLength);
+ int state = right.partialIsValidUtf8(leftPartial, 0, right.size());
+ return state == Utf8.COMPLETE;
+ }
+
+ @Override
+ protected int partialIsValidUtf8(int state, int offset, int length) {
+ int toIndex = offset + length;
+ if (toIndex <= leftLength) {
+ return left.partialIsValidUtf8(state, offset, length);
+ } else if (offset >= leftLength) {
+ return right.partialIsValidUtf8(state, offset - leftLength, length);
+ } else {
+ int leftLength = this.leftLength - offset;
+ int leftPartial = left.partialIsValidUtf8(state, offset, leftLength);
+ return right.partialIsValidUtf8(leftPartial, 0, length - leftLength);
+ }
+ }
+
+ // =================================================================
+ // equals() and hashCode()
+
+ @Override
+ public boolean equals(Object other) {
+ if (other == this) {
+ return true;
+ }
+ if (!(other instanceof ByteString)) {
+ return false;
+ }
+
+ ByteString otherByteString = (ByteString) other;
+ if (totalLength != otherByteString.size()) {
+ return false;
+ }
+ if (totalLength == 0) {
+ return true;
+ }
+
+ // You don't really want to be calling equals on long strings, but since
+ // we cache the hashCode, we effectively cache inequality. We use the cached
+ // hashCode if it's already computed. It's arguable we should compute the
+ // hashCode here, and if we're going to be testing a bunch of byteStrings,
+ // it might even make sense.
+ int thisHash = peekCachedHashCode();
+ int thatHash = otherByteString.peekCachedHashCode();
+ if (thisHash != 0 && thatHash != 0 && thisHash != thatHash) {
+ return false;
+ }
+
+ return equalsFragments(otherByteString);
+ }
+
+ /**
+ * Determines if this string is equal to another of the same length by
+ * iterating over the leaf nodes. On each step of the iteration, the
+ * overlapping segments of the leaves are compared.
+ *
+ * @param other string of the same length as this one
+ * @return true if the values of this string equals the value of the given
+ * one
+ */
+ private boolean equalsFragments(ByteString other) {
+ int thisOffset = 0;
+ Iterator<LeafByteString> thisIter = new PieceIterator(this);
+ LeafByteString thisString = thisIter.next();
+
+ int thatOffset = 0;
+ Iterator<LeafByteString> thatIter = new PieceIterator(other);
+ LeafByteString thatString = thatIter.next();
+
+ int pos = 0;
+ while (true) {
+ int thisRemaining = thisString.size() - thisOffset;
+ int thatRemaining = thatString.size() - thatOffset;
+ int bytesToCompare = Math.min(thisRemaining, thatRemaining);
+
+ // At least one of the offsets will be zero
+ boolean stillEqual = (thisOffset == 0)
+ ? thisString.equalsRange(thatString, thatOffset, bytesToCompare)
+ : thatString.equalsRange(thisString, thisOffset, bytesToCompare);
+ if (!stillEqual) {
+ return false;
+ }
+
+ pos += bytesToCompare;
+ if (pos >= totalLength) {
+ if (pos == totalLength) {
+ return true;
+ }
+ throw new IllegalStateException();
+ }
+ // We always get to the end of at least one of the pieces
+ if (bytesToCompare == thisRemaining) { // If reached end of this
+ thisOffset = 0;
+ thisString = thisIter.next();
+ } else {
+ thisOffset += bytesToCompare;
+ }
+ if (bytesToCompare == thatRemaining) { // If reached end of that
+ thatOffset = 0;
+ thatString = thatIter.next();
+ } else {
+ thatOffset += bytesToCompare;
+ }
+ }
+ }
+
+ @Override
+ protected int partialHash(int h, int offset, int length) {
+ int toIndex = offset + length;
+ if (toIndex <= leftLength) {
+ return left.partialHash(h, offset, length);
+ } else if (offset >= leftLength) {
+ return right.partialHash(h, offset - leftLength, length);
+ } else {
+ int leftLength = this.leftLength - offset;
+ int leftPartial = left.partialHash(h, offset, leftLength);
+ return right.partialHash(leftPartial, 0, length - leftLength);
+ }
+ }
+
+ // =================================================================
+ // Input stream
+
+ @Override
+ public CodedInputStream newCodedInput() {
+ return CodedInputStream.newInstance(new RopeInputStream());
+ }
+
+ @Override
+ public InputStream newInput() {
+ return new RopeInputStream();
+ }
+
+ /**
+ * This class implements the balancing algorithm of BAP95. In the paper the
+ * authors use an array to keep track of pieces, while here we use a stack.
+ * The tree is balanced by traversing subtrees in left to right order, and the
+ * stack always contains the part of the string we've traversed so far.
+ *
+ * <p>One surprising aspect of the algorithm is the result of balancing is not
+ * necessarily balanced, though it is nearly balanced. For details, see
+ * BAP95.
+ */
+ private static class Balancer {
+ // Stack containing the part of the string, starting from the left, that
+ // we've already traversed. The final string should be the equivalent of
+ // concatenating the strings on the stack from bottom to top.
+ private final Stack<ByteString> prefixesStack = new Stack<ByteString>();
+
+ private ByteString balance(ByteString left, ByteString right) {
+ doBalance(left);
+ doBalance(right);
+
+ // Sweep stack to gather the result
+ ByteString partialString = prefixesStack.pop();
+ while (!prefixesStack.isEmpty()) {
+ ByteString newLeft = prefixesStack.pop();
+ partialString = new RopeByteString(newLeft, partialString);
+ }
+ // We should end up with a RopeByteString since at a minimum we will
+ // create one from concatenating left and right
+ return partialString;
+ }
+
+ private void doBalance(ByteString root) {
+ // BAP95: Insert balanced subtrees whole. This means the result might not
+ // be balanced, leading to repeated rebalancings on concatenate. However,
+ // these rebalancings are shallow due to ignoring balanced subtrees, and
+ // relatively few calls to insert() result.
+ if (root.isBalanced()) {
+ insert(root);
+ } else if (root instanceof RopeByteString) {
+ RopeByteString rbs = (RopeByteString) root;
+ doBalance(rbs.left);
+ doBalance(rbs.right);
+ } else {
+ throw new IllegalArgumentException(
+ "Has a new type of ByteString been created? Found " +
+ root.getClass());
+ }
+ }
+
+ /**
+ * Push a string on the balance stack (BAP95). BAP95 uses an array and
+ * calls the elements in the array 'bins'. We instead use a stack, so the
+ * 'bins' of lengths are represented by differences between the elements of
+ * minLengthByDepth.
+ *
+ * <p>If the length bin for our string, and all shorter length bins, are
+ * empty, we just push it on the stack. Otherwise, we need to start
+ * concatenating, putting the given string in the "middle" and continuing
+ * until we land in an empty length bin that matches the length of our
+ * concatenation.
+ *
+ * @param byteString string to place on the balance stack
+ */
+ private void insert(ByteString byteString) {
+ int depthBin = getDepthBinForLength(byteString.size());
+ int binEnd = minLengthByDepth[depthBin + 1];
+
+ // BAP95: Concatenate all trees occupying bins representing the length of
+ // our new piece or of shorter pieces, to the extent that is possible.
+ // The goal is to clear the bin which our piece belongs in, but that may
+ // not be entirely possible if there aren't enough longer bins occupied.
+ if (prefixesStack.isEmpty() || prefixesStack.peek().size() >= binEnd) {
+ prefixesStack.push(byteString);
+ } else {
+ int binStart = minLengthByDepth[depthBin];
+
+ // Concatenate the subtrees of shorter length
+ ByteString newTree = prefixesStack.pop();
+ while (!prefixesStack.isEmpty()
+ && prefixesStack.peek().size() < binStart) {
+ ByteString left = prefixesStack.pop();
+ newTree = new RopeByteString(left, newTree);
+ }
+
+ // Concatenate the given string
+ newTree = new RopeByteString(newTree, byteString);
+
+ // Continue concatenating until we land in an empty bin
+ while (!prefixesStack.isEmpty()) {
+ depthBin = getDepthBinForLength(newTree.size());
+ binEnd = minLengthByDepth[depthBin + 1];
+ if (prefixesStack.peek().size() < binEnd) {
+ ByteString left = prefixesStack.pop();
+ newTree = new RopeByteString(left, newTree);
+ } else {
+ break;
+ }
+ }
+ prefixesStack.push(newTree);
+ }
+ }
+
+ private int getDepthBinForLength(int length) {
+ int depth = Arrays.binarySearch(minLengthByDepth, length);
+ if (depth < 0) {
+ // It wasn't an exact match, so convert to the index of the containing
+ // fragment, which is one less even than the insertion point.
+ int insertionPoint = -(depth + 1);
+ depth = insertionPoint - 1;
+ }
+
+ return depth;
+ }
+ }
+
+ /**
+ * This class is a continuable tree traversal, which keeps the state
+ * information which would exist on the stack in a recursive traversal instead
+ * on a stack of "Bread Crumbs". The maximum depth of the stack in this
+ * iterator is the same as the depth of the tree being traversed.
+ *
+ * <p>This iterator is used to implement
+ * {@link RopeByteString#equalsFragments(ByteString)}.
+ */
+ private static class PieceIterator implements Iterator<LeafByteString> {
+
+ private final Stack<RopeByteString> breadCrumbs =
+ new Stack<RopeByteString>();
+ private LeafByteString next;
+
+ private PieceIterator(ByteString root) {
+ next = getLeafByLeft(root);
+ }
+
+ private LeafByteString getLeafByLeft(ByteString root) {
+ ByteString pos = root;
+ while (pos instanceof RopeByteString) {
+ RopeByteString rbs = (RopeByteString) pos;
+ breadCrumbs.push(rbs);
+ pos = rbs.left;
+ }
+ return (LeafByteString) pos;
+ }
+
+ private LeafByteString getNextNonEmptyLeaf() {
+ while (true) {
+ // Almost always, we go through this loop exactly once. However, if
+ // we discover an empty string in the rope, we toss it and try again.
+ if (breadCrumbs.isEmpty()) {
+ return null;
+ } else {
+ LeafByteString result = getLeafByLeft(breadCrumbs.pop().right);
+ if (!result.isEmpty()) {
+ return result;
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean hasNext() {
+ return next != null;
+ }
+
+ /**
+ * Returns the next item and advances one
+ * {@link com.google.protobuf.ByteString.LeafByteString}.
+ *
+ * @return next non-empty LeafByteString or {@code null}
+ */
+ @Override
+ public LeafByteString next() {
+ if (next == null) {
+ throw new NoSuchElementException();
+ }
+ LeafByteString result = next;
+ next = getNextNonEmptyLeaf();
+ return result;
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ // =================================================================
+ // Serializable
+
+ private static final long serialVersionUID = 1L;
+
+ Object writeReplace() {
+ return ByteString.wrap(toByteArray());
+ }
+
+ private void readObject(@SuppressWarnings("unused") ObjectInputStream in) throws IOException {
+ throw new InvalidObjectException(
+ "RopeByteStream instances are not to be serialized directly");
+ }
+
+ /**
+ * This class is the {@link RopeByteString} equivalent for
+ * {@link ByteArrayInputStream}.
+ */
+ private class RopeInputStream extends InputStream {
+ // Iterates through the pieces of the rope
+ private PieceIterator pieceIterator;
+ // The current piece
+ private LeafByteString currentPiece;
+ // The size of the current piece
+ private int currentPieceSize;
+ // The index of the next byte to read in the current piece
+ private int currentPieceIndex;
+ // The offset of the start of the current piece in the rope byte string
+ private int currentPieceOffsetInRope;
+ // Offset in the buffer at which user called mark();
+ private int mark;
+
+ public RopeInputStream() {
+ initialize();
+ }
+
+ @Override
+ public int read(byte b[], int offset, int length) {
+ if (b == null) {
+ throw new NullPointerException();
+ } else if (offset < 0 || length < 0 || length > b.length - offset) {
+ throw new IndexOutOfBoundsException();
+ }
+ return readSkipInternal(b, offset, length);
+ }
+
+ @Override
+ public long skip(long length) {
+ if (length < 0) {
+ throw new IndexOutOfBoundsException();
+ } else if (length > Integer.MAX_VALUE) {
+ length = Integer.MAX_VALUE;
+ }
+ return readSkipInternal(null, 0, (int) length);
+ }
+
+ /**
+ * Internal implementation of read and skip. If b != null, then read the
+ * next {@code length} bytes into the buffer {@code b} at
+ * offset {@code offset}. If b == null, then skip the next {@code length}
+ * bytes.
+ * <p>
+ * This method assumes that all error checking has already happened.
+ * <p>
+ * Returns the actual number of bytes read or skipped.
+ */
+ private int readSkipInternal(byte b[], int offset, int length) {
+ int bytesRemaining = length;
+ while (bytesRemaining > 0) {
+ advanceIfCurrentPieceFullyRead();
+ if (currentPiece == null) {
+ if (bytesRemaining == length) {
+ // We didn't manage to read anything
+ return -1;
+ }
+ break;
+ } else {
+ // Copy the bytes from this piece.
+ int currentPieceRemaining = currentPieceSize - currentPieceIndex;
+ int count = Math.min(currentPieceRemaining, bytesRemaining);
+ if (b != null) {
+ currentPiece.copyTo(b, currentPieceIndex, offset, count);
+ offset += count;
+ }
+ currentPieceIndex += count;
+ bytesRemaining -= count;
+ }
+ }
+ // Return the number of bytes read.
+ return length - bytesRemaining;
+ }
+
+ @Override
+ public int read() throws IOException {
+ advanceIfCurrentPieceFullyRead();
+ if (currentPiece == null) {
+ return -1;
+ } else {
+ return currentPiece.byteAt(currentPieceIndex++) & 0xFF;
+ }
+ }
+
+ @Override
+ public int available() throws IOException {
+ int bytesRead = currentPieceOffsetInRope + currentPieceIndex;
+ return RopeByteString.this.size() - bytesRead;
+ }
+
+ @Override
+ public boolean markSupported() {
+ return true;
+ }
+
+ @Override
+ public void mark(int readAheadLimit) {
+ // Set the mark to our position in the byte string
+ mark = currentPieceOffsetInRope + currentPieceIndex;
+ }
+
+ @Override
+ public synchronized void reset() {
+ // Just reinitialize and skip the specified number of bytes.
+ initialize();
+ readSkipInternal(null, 0, mark);
+ }
+
+ /** Common initialization code used by both the constructor and reset() */
+ private void initialize() {
+ pieceIterator = new PieceIterator(RopeByteString.this);
+ currentPiece = pieceIterator.next();
+ currentPieceSize = currentPiece.size();
+ currentPieceIndex = 0;
+ currentPieceOffsetInRope = 0;
+ }
+
+ /**
+ * Skips to the next piece if we have read all the data in the current
+ * piece. Sets currentPiece to null if we have reached the end of the
+ * input.
+ */
+ private void advanceIfCurrentPieceFullyRead() {
+ if (currentPiece != null && currentPieceIndex == currentPieceSize) {
+ // Generally, we can only go through this loop at most once, since
+ // empty strings can't end up in a rope. But better to test.
+ currentPieceOffsetInRope += currentPieceSize;
+ currentPieceIndex = 0;
+ if (pieceIterator.hasNext()) {
+ currentPiece = pieceIterator.next();
+ currentPieceSize = currentPiece.size();
+ } else {
+ currentPiece = null;
+ currentPieceSize = 0;
+ }
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RpcCallback.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RpcCallback.java
new file mode 100644
index 0000000000..10752968e2
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RpcCallback.java
@@ -0,0 +1,47 @@
+// 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;
+
+/**
+ * Interface for an RPC callback, normally called when an RPC completes.
+ * {@code ParameterType} is normally the method's response message type.
+ *
+ * <p>Starting with version 2.3.0, RPC implementations should not try to build
+ * on this, but should instead provide code generator plugins which generate
+ * code specific to the particular RPC implementation. This way the generated
+ * code can be more appropriate for the implementation in use and can avoid
+ * unnecessary layers of indirection.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public interface RpcCallback<ParameterType> {
+ void run(ParameterType parameter);
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RpcChannel.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RpcChannel.java
new file mode 100644
index 0000000000..f272f4ad72
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RpcChannel.java
@@ -0,0 +1,71 @@
+// 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;
+
+/**
+ * <p>Abstract interface for an RPC channel. An {@code RpcChannel} represents a
+ * communication line to a {@link Service} which can be used to call that
+ * {@link Service}'s methods. The {@link Service} may be running on another
+ * machine. Normally, you should not call an {@code RpcChannel} directly, but
+ * instead construct a stub {@link Service} wrapping it. Example:
+ *
+ * <pre>
+ * RpcChannel channel = rpcImpl.newChannel("remotehost.example.com:1234");
+ * RpcController controller = rpcImpl.newController();
+ * MyService service = MyService.newStub(channel);
+ * service.myMethod(controller, request, callback);
+ * </pre>
+ *
+ * <p>Starting with version 2.3.0, RPC implementations should not try to build
+ * on this, but should instead provide code generator plugins which generate
+ * code specific to the particular RPC implementation. This way the generated
+ * code can be more appropriate for the implementation in use and can avoid
+ * unnecessary layers of indirection.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public interface RpcChannel {
+ /**
+ * Call the given method of the remote service. This method is similar to
+ * {@code Service.callMethod()} with one important difference: the caller
+ * decides the types of the {@code Message} objects, not the callee. The
+ * request may be of any type as long as
+ * {@code request.getDescriptor() == method.getInputType()}.
+ * The response passed to the callback will be of the same type as
+ * {@code responsePrototype} (which must have
+ * {@code getDescriptor() == method.getOutputType()}).
+ */
+ void callMethod(Descriptors.MethodDescriptor method,
+ RpcController controller,
+ Message request,
+ Message responsePrototype,
+ RpcCallback<Message> done);
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RpcController.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RpcController.java
new file mode 100644
index 0000000000..a92dd7be6d
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RpcController.java
@@ -0,0 +1,118 @@
+// 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;
+
+/**
+ * <p>An {@code RpcController} mediates a single method call. The primary
+ * purpose of the controller is to provide a way to manipulate settings
+ * specific to the RPC implementation and to find out about RPC-level errors.
+ *
+ * <p>Starting with version 2.3.0, RPC implementations should not try to build
+ * on this, but should instead provide code generator plugins which generate
+ * code specific to the particular RPC implementation. This way the generated
+ * code can be more appropriate for the implementation in use and can avoid
+ * unnecessary layers of indirection.
+ *
+ * <p>The methods provided by the {@code RpcController} interface are intended
+ * to be a "least common denominator" set of features which we expect all
+ * implementations to support. Specific implementations may provide more
+ * advanced features (e.g. deadline propagation).
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public interface RpcController {
+ // -----------------------------------------------------------------
+ // These calls may be made from the client side only. Their results
+ // are undefined on the server side (may throw RuntimeExceptions).
+
+ /**
+ * Resets the RpcController to its initial state so that it may be reused in
+ * a new call. This can be called from the client side only. It must not
+ * be called while an RPC is in progress.
+ */
+ void reset();
+
+ /**
+ * After a call has finished, returns true if the call failed. The possible
+ * reasons for failure depend on the RPC implementation. {@code failed()}
+ * most only be called on the client side, and must not be called before a
+ * call has finished.
+ */
+ boolean failed();
+
+ /**
+ * If {@code failed()} is {@code true}, returns a human-readable description
+ * of the error.
+ */
+ String errorText();
+
+ /**
+ * Advises the RPC system that the caller desires that the RPC call be
+ * canceled. The RPC system may cancel it immediately, may wait awhile and
+ * then cancel it, or may not even cancel the call at all. If the call is
+ * canceled, the "done" callback will still be called and the RpcController
+ * will indicate that the call failed at that time.
+ */
+ void startCancel();
+
+ // -----------------------------------------------------------------
+ // These calls may be made from the server side only. Their results
+ // are undefined on the client side (may throw RuntimeExceptions).
+
+ /**
+ * Causes {@code failed()} to return true on the client side. {@code reason}
+ * will be incorporated into the message returned by {@code errorText()}.
+ * If you find you need to return machine-readable information about
+ * failures, you should incorporate it into your response protocol buffer
+ * and should NOT call {@code setFailed()}.
+ */
+ void setFailed(String reason);
+
+ /**
+ * If {@code true}, indicates that the client canceled the RPC, so the server
+ * may as well give up on replying to it. This method must be called on the
+ * server side only. The server should still call the final "done" callback.
+ */
+ boolean isCanceled();
+
+ /**
+ * Asks that the given callback be called when the RPC is canceled. The
+ * parameter passed to the callback will always be {@code null}. The
+ * callback will always be called exactly once. If the RPC completes without
+ * being canceled, the callback will be called after completion. If the RPC
+ * has already been canceled when NotifyOnCancel() is called, the callback
+ * will be called immediately.
+ *
+ * <p>{@code notifyOnCancel()} must be called no more than once per request.
+ * It must be called on the server side only.
+ */
+ void notifyOnCancel(RpcCallback<Object> callback);
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RpcUtil.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RpcUtil.java
new file mode 100644
index 0000000000..f7d555ae15
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/RpcUtil.java
@@ -0,0 +1,136 @@
+// 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;
+
+/**
+ * Grab-bag of utility functions useful when dealing with RPCs.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public final class RpcUtil {
+ private RpcUtil() {}
+
+ /**
+ * Take an {@code RpcCallback<Message>} and convert it to an
+ * {@code RpcCallback} accepting a specific message type. This is always
+ * type-safe (parameter type contravariance).
+ */
+ @SuppressWarnings("unchecked")
+ public static <Type extends Message> RpcCallback<Type>
+ specializeCallback(final RpcCallback<Message> originalCallback) {
+ return (RpcCallback<Type>)originalCallback;
+ // The above cast works, but only due to technical details of the Java
+ // implementation. A more theoretically correct -- but less efficient --
+ // implementation would be as follows:
+ // return new RpcCallback<Type>() {
+ // public void run(Type parameter) {
+ // originalCallback.run(parameter);
+ // }
+ // };
+ }
+
+ /**
+ * Take an {@code RpcCallback} accepting a specific message type and convert
+ * it to an {@code RpcCallback<Message>}. The generalized callback will
+ * accept any message object which has the same descriptor, and will convert
+ * it to the correct class before calling the original callback. However,
+ * if the generalized callback is given a message with a different descriptor,
+ * an exception will be thrown.
+ */
+ public static <Type extends Message>
+ RpcCallback<Message> generalizeCallback(
+ final RpcCallback<Type> originalCallback,
+ final Class<Type> originalClass,
+ final Type defaultInstance) {
+ return new RpcCallback<Message>() {
+ @Override
+ public void run(final Message parameter) {
+ Type typedParameter;
+ try {
+ typedParameter = originalClass.cast(parameter);
+ } catch (ClassCastException ignored) {
+ typedParameter = copyAsType(defaultInstance, parameter);
+ }
+ originalCallback.run(typedParameter);
+ }
+ };
+ }
+
+ /**
+ * Creates a new message of type "Type" which is a copy of "source". "source"
+ * must have the same descriptor but may be a different class (e.g.
+ * DynamicMessage).
+ */
+ @SuppressWarnings("unchecked")
+ private static <Type extends Message> Type copyAsType(
+ final Type typeDefaultInstance, final Message source) {
+ return (Type) typeDefaultInstance
+ .newBuilderForType().mergeFrom(source).build();
+ }
+
+ /**
+ * Creates a callback which can only be called once. This may be useful for
+ * security, when passing a callback to untrusted code: most callbacks do
+ * not expect to be called more than once, so doing so may expose bugs if it
+ * is not prevented.
+ */
+ public static <ParameterType>
+ RpcCallback<ParameterType> newOneTimeCallback(
+ final RpcCallback<ParameterType> originalCallback) {
+ return new RpcCallback<ParameterType>() {
+ private boolean alreadyCalled = false;
+
+ @Override
+ public void run(final ParameterType parameter) {
+ synchronized (this) {
+ if (alreadyCalled) {
+ throw new AlreadyCalledException();
+ }
+ alreadyCalled = true;
+ }
+
+ originalCallback.run(parameter);
+ }
+ };
+ }
+
+ /**
+ * Exception thrown when a one-time callback is called more than once.
+ */
+ public static final class AlreadyCalledException extends RuntimeException {
+ private static final long serialVersionUID = 5469741279507848266L;
+
+ public AlreadyCalledException() {
+ super("This RpcCallback was already called and cannot be called " +
+ "multiple times.");
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Service.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Service.java
new file mode 100644
index 0000000000..ba7b033ed4
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Service.java
@@ -0,0 +1,117 @@
+// 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 base interface for protocol-buffer-based RPC services. Services
+ * themselves are abstract classes (implemented either by servers or as
+ * stubs), but they subclass this base interface. The methods of this
+ * interface can be used to call the methods of the service without knowing
+ * its exact type at compile time (analogous to the Message interface).
+ *
+ * <p>Starting with version 2.3.0, RPC implementations should not try to build
+ * on this, but should instead provide code generator plugins which generate
+ * code specific to the particular RPC implementation. This way the generated
+ * code can be more appropriate for the implementation in use and can avoid
+ * unnecessary layers of indirection.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public interface Service {
+ /**
+ * Get the {@code ServiceDescriptor} describing this service and its methods.
+ */
+ Descriptors.ServiceDescriptor getDescriptorForType();
+
+ /**
+ * <p>Call a method of the service specified by MethodDescriptor. This is
+ * normally implemented as a simple {@code switch()} that calls the standard
+ * definitions of the service's methods.
+ *
+ * <p>Preconditions:
+ * <ul>
+ * <li>{@code method.getService() == getDescriptorForType()}
+ * <li>{@code request} is of the exact same class as the object returned by
+ * {@code getRequestPrototype(method)}.
+ * <li>{@code controller} is of the correct type for the RPC implementation
+ * being used by this Service. For stubs, the "correct type" depends
+ * on the RpcChannel which the stub is using. Server-side Service
+ * implementations are expected to accept whatever type of
+ * {@code RpcController} the server-side RPC implementation uses.
+ * </ul>
+ *
+ * <p>Postconditions:
+ * <ul>
+ * <li>{@code done} will be called when the method is complete. This may be
+ * before {@code callMethod()} returns or it may be at some point in
+ * the future.
+ * <li>The parameter to {@code done} is the response. It must be of the
+ * exact same type as would be returned by
+ * {@code getResponsePrototype(method)}.
+ * <li>If the RPC failed, the parameter to {@code done} will be
+ * {@code null}. Further details about the failure can be found by
+ * querying {@code controller}.
+ * </ul>
+ */
+ void callMethod(Descriptors.MethodDescriptor method,
+ RpcController controller,
+ Message request,
+ RpcCallback<Message> done);
+
+ /**
+ * <p>{@code callMethod()} requires that the request passed in is of a
+ * particular subclass of {@code Message}. {@code getRequestPrototype()}
+ * gets the default instances of this type for a given method. You can then
+ * call {@code Message.newBuilderForType()} on this instance to
+ * construct a builder to build an object which you can then pass to
+ * {@code callMethod()}.
+ *
+ * <p>Example:
+ * <pre>
+ * MethodDescriptor method =
+ * service.getDescriptorForType().findMethodByName("Foo");
+ * Message request =
+ * stub.getRequestPrototype(method).newBuilderForType()
+ * .mergeFrom(input).build();
+ * service.callMethod(method, request, callback);
+ * </pre>
+ */
+ Message getRequestPrototype(Descriptors.MethodDescriptor method);
+
+ /**
+ * Like {@code getRequestPrototype()}, but gets a prototype of the response
+ * message. {@code getResponsePrototype()} is generally not needed because
+ * the {@code Service} implementation constructs the response message itself,
+ * but it may be useful in some cases to know ahead of time what type of
+ * object will be returned.
+ */
+ Message getResponsePrototype(Descriptors.MethodDescriptor method);
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ServiceException.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ServiceException.java
new file mode 100644
index 0000000000..00d5707523
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/ServiceException.java
@@ -0,0 +1,52 @@
+// 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;
+
+/**
+ * Thrown by blocking RPC methods when a failure occurs.
+ *
+ * @author cpovirk@google.com (Chris Povirk)
+ */
+public class ServiceException extends Exception {
+ private static final long serialVersionUID = -1219262335729891920L;
+
+ public ServiceException(final String message) {
+ super(message);
+ }
+
+ public ServiceException(final Throwable cause) {
+ super(cause);
+ }
+
+ public ServiceException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java
new file mode 100644
index 0000000000..941b5defc9
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/SingleFieldBuilder.java
@@ -0,0 +1,241 @@
+// 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;
+
+/**
+ * {@code SingleFieldBuilder} implements a structure that a protocol
+ * message uses to hold a single field of another protocol message. It supports
+ * the classical use case of setting an immutable {@link Message} as the value
+ * of the field and is highly optimized around this.
+ * <br>
+ * It also supports the additional use case of setting a {@link Message.Builder}
+ * as the field and deferring conversion of that {@code Builder}
+ * to an immutable {@code Message}. In this way, it's possible to maintain
+ * a tree of {@code Builder}'s that acts as a fully read/write data
+ * structure.
+ * <br>
+ * Logically, one can think of a tree of builders as converting the entire tree
+ * to messages when build is called on the root or when any method is called
+ * that desires a Message instead of a Builder. In terms of the implementation,
+ * the {@code SingleFieldBuilder} and {@code RepeatedFieldBuilder}
+ * classes cache messages that were created so that messages only need to be
+ * created when some change occurred in its builder or a builder for one of its
+ * descendants.
+ *
+ * @param <MType> the type of message for the field
+ * @param <BType> the type of builder for the field
+ * @param <IType> the common interface for the message and the builder
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class SingleFieldBuilder
+ <MType extends GeneratedMessage,
+ BType extends GeneratedMessage.Builder,
+ IType extends MessageOrBuilder>
+ implements GeneratedMessage.BuilderParent {
+
+ // Parent to send changes to.
+ private GeneratedMessage.BuilderParent parent;
+
+ // Invariant: one of builder or message fields must be non-null.
+
+ // If set, this is the case where we are backed by a builder. In this case,
+ // message field represents a cached message for the builder (or null if
+ // there is no cached message).
+ private BType builder;
+
+ // If builder is non-null, this represents a cached message from the builder.
+ // If builder is null, this is the authoritative message for the field.
+ private MType message;
+
+ // Indicates that we've built a message and so we are now obligated
+ // to dispatch dirty invalidations. See GeneratedMessage.BuilderListener.
+ private boolean isClean;
+
+ public SingleFieldBuilder(
+ MType message,
+ GeneratedMessage.BuilderParent parent,
+ boolean isClean) {
+ if (message == null) {
+ throw new NullPointerException();
+ }
+ this.message = message;
+ this.parent = parent;
+ this.isClean = isClean;
+ }
+
+ public void dispose() {
+ // Null out parent so we stop sending it invalidations.
+ parent = null;
+ }
+
+ /**
+ * Get the message for the field. If the message is currently stored
+ * as a {@code Builder}, it is converted to a {@code Message} by
+ * calling {@link Message.Builder#buildPartial} on it. If no message has
+ * been set, returns the default instance of the message.
+ *
+ * @return the message for the field
+ */
+ @SuppressWarnings("unchecked")
+ public MType getMessage() {
+ if (message == null) {
+ // If message is null, the invariant is that we must be have a builder.
+ message = (MType) builder.buildPartial();
+ }
+ return message;
+ }
+
+ /**
+ * Builds the message and returns it.
+ *
+ * @return the message
+ */
+ public MType build() {
+ // Now that build has been called, we are required to dispatch
+ // invalidations.
+ isClean = true;
+ return getMessage();
+ }
+
+ /**
+ * Gets a builder for the field. If no builder has been created yet, a
+ * builder is created on demand by calling {@link Message#toBuilder}.
+ *
+ * @return The builder for the field
+ */
+ @SuppressWarnings("unchecked")
+ public BType getBuilder() {
+ if (builder == null) {
+ // builder.mergeFrom() on a fresh builder
+ // does not create any sub-objects with independent clean/dirty states,
+ // therefore setting the builder itself to clean without actually calling
+ // build() cannot break any invariants.
+ builder = (BType) message.newBuilderForType(this);
+ builder.mergeFrom(message); // no-op if message is the default message
+ builder.markClean();
+ }
+ return builder;
+ }
+
+ /**
+ * Gets the base class interface for the field. This may either be a builder
+ * or a message. It will return whatever is more efficient.
+ *
+ * @return the message or builder for the field as the base class interface
+ */
+ @SuppressWarnings("unchecked")
+ public IType getMessageOrBuilder() {
+ if (builder != null) {
+ return (IType) builder;
+ } else {
+ return (IType) message;
+ }
+ }
+
+ /**
+ * Sets a message for the field replacing any existing value.
+ *
+ * @param message the message to set
+ * @return the builder
+ */
+ public SingleFieldBuilder<MType, BType, IType> setMessage(
+ MType message) {
+ if (message == null) {
+ throw new NullPointerException();
+ }
+ this.message = message;
+ if (builder != null) {
+ builder.dispose();
+ builder = null;
+ }
+ onChanged();
+ return this;
+ }
+
+ /**
+ * Merges the field from another field.
+ *
+ * @param value the value to merge from
+ * @return the builder
+ */
+ public SingleFieldBuilder<MType, BType, IType> mergeFrom(
+ MType value) {
+ if (builder == null && message == message.getDefaultInstanceForType()) {
+ message = value;
+ } else {
+ getBuilder().mergeFrom(value);
+ }
+ onChanged();
+ return this;
+ }
+
+ /**
+ * Clears the value of the field.
+ *
+ * @return the builder
+ */
+ @SuppressWarnings("unchecked")
+ public SingleFieldBuilder<MType, BType, IType> clear() {
+ message = (MType) (message != null ?
+ message.getDefaultInstanceForType() :
+ builder.getDefaultInstanceForType());
+ if (builder != null) {
+ builder.dispose();
+ builder = null;
+ }
+ onChanged();
+ return this;
+ }
+
+ /**
+ * Called when a the builder or one of its nested children has changed
+ * and any parent should be notified of its invalidation.
+ */
+ private void onChanged() {
+ // If builder is null, this is the case where onChanged is being called
+ // from setMessage or clear.
+ if (builder != null) {
+ message = null;
+ }
+ if (isClean && parent != null) {
+ parent.markDirty();
+
+ // Don't keep dispatching invalidations until build is called again.
+ isClean = false;
+ }
+ }
+
+ @Override
+ public void markDirty() {
+ onChanged();
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java
new file mode 100644
index 0000000000..fb1f76a731
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java
@@ -0,0 +1,241 @@
+// 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;
+
+/**
+ * {@code SingleFieldBuilderV3} implements a structure that a protocol
+ * message uses to hold a single field of another protocol message. It supports
+ * the classical use case of setting an immutable {@link Message} as the value
+ * of the field and is highly optimized around this.
+ * <br>
+ * It also supports the additional use case of setting a {@link Message.Builder}
+ * as the field and deferring conversion of that {@code Builder}
+ * to an immutable {@code Message}. In this way, it's possible to maintain
+ * a tree of {@code Builder}'s that acts as a fully read/write data
+ * structure.
+ * <br>
+ * Logically, one can think of a tree of builders as converting the entire tree
+ * to messages when build is called on the root or when any method is called
+ * that desires a Message instead of a Builder. In terms of the implementation,
+ * the {@code SingleFieldBuilderV3} and {@code RepeatedFieldBuilderV3}
+ * classes cache messages that were created so that messages only need to be
+ * created when some change occurred in its builder or a builder for one of its
+ * descendants.
+ *
+ * @param <MType> the type of message for the field
+ * @param <BType> the type of builder for the field
+ * @param <IType> the common interface for the message and the builder
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class SingleFieldBuilderV3
+ <MType extends AbstractMessage,
+ BType extends AbstractMessage.Builder,
+ IType extends MessageOrBuilder>
+ implements AbstractMessage.BuilderParent {
+
+ // Parent to send changes to.
+ private AbstractMessage.BuilderParent parent;
+
+ // Invariant: one of builder or message fields must be non-null.
+
+ // If set, this is the case where we are backed by a builder. In this case,
+ // message field represents a cached message for the builder (or null if
+ // there is no cached message).
+ private BType builder;
+
+ // If builder is non-null, this represents a cached message from the builder.
+ // If builder is null, this is the authoritative message for the field.
+ private MType message;
+
+ // Indicates that we've built a message and so we are now obligated
+ // to dispatch dirty invalidations. See AbstractMessage.BuilderListener.
+ private boolean isClean;
+
+ public SingleFieldBuilderV3(
+ MType message,
+ AbstractMessage.BuilderParent parent,
+ boolean isClean) {
+ if (message == null) {
+ throw new NullPointerException();
+ }
+ this.message = message;
+ this.parent = parent;
+ this.isClean = isClean;
+ }
+
+ public void dispose() {
+ // Null out parent so we stop sending it invalidations.
+ parent = null;
+ }
+
+ /**
+ * Get the message for the field. If the message is currently stored
+ * as a {@code Builder}, it is converted to a {@code Message} by
+ * calling {@link Message.Builder#buildPartial} on it. If no message has
+ * been set, returns the default instance of the message.
+ *
+ * @return the message for the field
+ */
+ @SuppressWarnings("unchecked")
+ public MType getMessage() {
+ if (message == null) {
+ // If message is null, the invariant is that we must be have a builder.
+ message = (MType) builder.buildPartial();
+ }
+ return message;
+ }
+
+ /**
+ * Builds the message and returns it.
+ *
+ * @return the message
+ */
+ public MType build() {
+ // Now that build has been called, we are required to dispatch
+ // invalidations.
+ isClean = true;
+ return getMessage();
+ }
+
+ /**
+ * Gets a builder for the field. If no builder has been created yet, a
+ * builder is created on demand by calling {@link Message#toBuilder}.
+ *
+ * @return The builder for the field
+ */
+ @SuppressWarnings("unchecked")
+ public BType getBuilder() {
+ if (builder == null) {
+ // builder.mergeFrom() on a fresh builder
+ // does not create any sub-objects with independent clean/dirty states,
+ // therefore setting the builder itself to clean without actually calling
+ // build() cannot break any invariants.
+ builder = (BType) message.newBuilderForType(this);
+ builder.mergeFrom(message); // no-op if message is the default message
+ builder.markClean();
+ }
+ return builder;
+ }
+
+ /**
+ * Gets the base class interface for the field. This may either be a builder
+ * or a message. It will return whatever is more efficient.
+ *
+ * @return the message or builder for the field as the base class interface
+ */
+ @SuppressWarnings("unchecked")
+ public IType getMessageOrBuilder() {
+ if (builder != null) {
+ return (IType) builder;
+ } else {
+ return (IType) message;
+ }
+ }
+
+ /**
+ * Sets a message for the field replacing any existing value.
+ *
+ * @param message the message to set
+ * @return the builder
+ */
+ public SingleFieldBuilderV3<MType, BType, IType> setMessage(
+ MType message) {
+ if (message == null) {
+ throw new NullPointerException();
+ }
+ this.message = message;
+ if (builder != null) {
+ builder.dispose();
+ builder = null;
+ }
+ onChanged();
+ return this;
+ }
+
+ /**
+ * Merges the field from another field.
+ *
+ * @param value the value to merge from
+ * @return the builder
+ */
+ public SingleFieldBuilderV3<MType, BType, IType> mergeFrom(
+ MType value) {
+ if (builder == null && message == message.getDefaultInstanceForType()) {
+ message = value;
+ } else {
+ getBuilder().mergeFrom(value);
+ }
+ onChanged();
+ return this;
+ }
+
+ /**
+ * Clears the value of the field.
+ *
+ * @return the builder
+ */
+ @SuppressWarnings("unchecked")
+ public SingleFieldBuilderV3<MType, BType, IType> clear() {
+ message = (MType) (message != null ?
+ message.getDefaultInstanceForType() :
+ builder.getDefaultInstanceForType());
+ if (builder != null) {
+ builder.dispose();
+ builder = null;
+ }
+ onChanged();
+ return this;
+ }
+
+ /**
+ * Called when a the builder or one of its nested children has changed
+ * and any parent should be notified of its invalidation.
+ */
+ private void onChanged() {
+ // If builder is null, this is the case where onChanged is being called
+ // from setMessage or clear.
+ if (builder != null) {
+ message = null;
+ }
+ if (isClean && parent != null) {
+ parent.markDirty();
+
+ // Don't keep dispatching invalidations until build is called again.
+ isClean = false;
+ }
+ }
+
+ @Override
+ public void markDirty() {
+ onChanged();
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/SmallSortedMap.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/SmallSortedMap.java
new file mode 100644
index 0000000000..66033f58e5
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/SmallSortedMap.java
@@ -0,0 +1,673 @@
+// 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.util.AbstractMap;
+import java.util.AbstractSet;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+/**
+ * A custom map implementation from FieldDescriptor to Object optimized to
+ * minimize the number of memory allocations for instances with a small number
+ * of mappings. The implementation stores the first {@code k} mappings in an
+ * array for a configurable value of {@code k}, allowing direct access to the
+ * corresponding {@code Entry}s without the need to create an Iterator. The
+ * remaining entries are stored in an overflow map. Iteration over the entries
+ * in the map should be done as follows:
+ *
+ * <pre> {@code
+ * for (int i = 0; i < fieldMap.getNumArrayEntries(); i++) {
+ * process(fieldMap.getArrayEntryAt(i));
+ * }
+ * for (Map.Entry<K, V> entry : fieldMap.getOverflowEntries()) {
+ * process(entry);
+ * }
+ * }</pre>
+ *
+ * The resulting iteration is in order of ascending field tag number. The
+ * object returned by {@link #entrySet()} adheres to the same contract but is
+ * less efficient as it necessarily involves creating an object for iteration.
+ * <p>
+ * The tradeoff for this memory efficiency is that the worst case running time
+ * of the {@code put()} operation is {@code O(k + lg n)}, which happens when
+ * entries are added in descending order. {@code k} should be chosen such that
+ * it covers enough common cases without adversely affecting larger maps. In
+ * practice, the worst case scenario does not happen for extensions because
+ * extension fields are serialized and deserialized in order of ascending tag
+ * number, but the worst case scenario can happen for DynamicMessages.
+ * <p>
+ * The running time for all other operations is similar to that of
+ * {@code TreeMap}.
+ * <p>
+ * Instances are not thread-safe until {@link #makeImmutable()} is called,
+ * after which any modifying operation will result in an
+ * {@link UnsupportedOperationException}.
+ *
+ * @author darick@google.com Darick Tong
+ */
+// This class is final for all intents and purposes because the constructor is
+// private. However, the FieldDescriptor-specific logic is encapsulated in
+// a subclass to aid testability of the core logic.
+class SmallSortedMap<K extends Comparable<K>, V> extends AbstractMap<K, V> {
+
+ /**
+ * Creates a new instance for mapping FieldDescriptors to their values.
+ * The {@link #makeImmutable()} implementation will convert the List values
+ * of any repeated fields to unmodifiable lists.
+ *
+ * @param arraySize The size of the entry array containing the
+ * lexicographically smallest mappings.
+ */
+ static <FieldDescriptorType extends
+ FieldSet.FieldDescriptorLite<FieldDescriptorType>>
+ SmallSortedMap<FieldDescriptorType, Object> newFieldMap(int arraySize) {
+ return new SmallSortedMap<FieldDescriptorType, Object>(arraySize) {
+ @Override
+ @SuppressWarnings("unchecked")
+ public void makeImmutable() {
+ if (!isImmutable()) {
+ for (int i = 0; i < getNumArrayEntries(); i++) {
+ final Map.Entry<FieldDescriptorType, Object> entry =
+ getArrayEntryAt(i);
+ if (entry.getKey().isRepeated()) {
+ final List value = (List) entry.getValue();
+ entry.setValue(Collections.unmodifiableList(value));
+ }
+ }
+ for (Map.Entry<FieldDescriptorType, Object> entry :
+ getOverflowEntries()) {
+ if (entry.getKey().isRepeated()) {
+ final List value = (List) entry.getValue();
+ entry.setValue(Collections.unmodifiableList(value));
+ }
+ }
+ }
+ super.makeImmutable();
+ }
+ };
+ }
+
+ /**
+ * Creates a new instance for testing.
+ *
+ * @param arraySize The size of the entry array containing the
+ * lexicographically smallest mappings.
+ */
+ static <K extends Comparable<K>, V> SmallSortedMap<K, V> newInstanceForTest(
+ int arraySize) {
+ return new SmallSortedMap<K, V>(arraySize);
+ }
+
+ private final int maxArraySize;
+ // The "entry array" is actually a List because generic arrays are not
+ // allowed. ArrayList also nicely handles the entry shifting on inserts and
+ // removes.
+ private List<Entry> entryList;
+ private Map<K, V> overflowEntries;
+ private boolean isImmutable;
+ // The EntrySet is a stateless view of the Map. It's initialized the first
+ // time it is requested and reused henceforth.
+ private volatile EntrySet lazyEntrySet;
+
+ /**
+ * @code arraySize Size of the array in which the lexicographically smallest
+ * mappings are stored. (i.e. the {@code k} referred to in the class
+ * documentation).
+ */
+ private SmallSortedMap(int arraySize) {
+ this.maxArraySize = arraySize;
+ this.entryList = Collections.emptyList();
+ this.overflowEntries = Collections.emptyMap();
+ }
+
+ /** Make this map immutable from this point forward. */
+ public void makeImmutable() {
+ if (!isImmutable) {
+ // Note: There's no need to wrap the entryList in an unmodifiableList
+ // because none of the list's accessors are exposed. The iterator() of
+ // overflowEntries, on the other hand, is exposed so it must be made
+ // unmodifiable.
+ overflowEntries = overflowEntries.isEmpty() ?
+ Collections.<K, V>emptyMap() :
+ Collections.unmodifiableMap(overflowEntries);
+ isImmutable = true;
+ }
+ }
+
+ /** @return Whether {@link #makeImmutable()} has been called. */
+ public boolean isImmutable() {
+ return isImmutable;
+ }
+
+ /** @return The number of entries in the entry array. */
+ public int getNumArrayEntries() {
+ return entryList.size();
+ }
+
+ /** @return The array entry at the given {@code index}. */
+ public Map.Entry<K, V> getArrayEntryAt(int index) {
+ return entryList.get(index);
+ }
+
+ /** @return There number of overflow entries. */
+ public int getNumOverflowEntries() {
+ return overflowEntries.size();
+ }
+
+ /** @return An iterable over the overflow entries. */
+ public Iterable<Map.Entry<K, V>> getOverflowEntries() {
+ return overflowEntries.isEmpty() ?
+ EmptySet.<Map.Entry<K, V>>iterable() :
+ overflowEntries.entrySet();
+ }
+
+
+ @Override
+ public int size() {
+ return entryList.size() + overflowEntries.size();
+ }
+
+ /**
+ * The implementation throws a {@code ClassCastException} if o is not an
+ * object of type {@code K}.
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean containsKey(Object o) {
+ @SuppressWarnings("unchecked")
+ final K key = (K) o;
+ return binarySearchInArray(key) >= 0 || overflowEntries.containsKey(key);
+ }
+
+ /**
+ * The implementation throws a {@code ClassCastException} if o is not an
+ * object of type {@code K}.
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public V get(Object o) {
+ @SuppressWarnings("unchecked")
+ final K key = (K) o;
+ final int index = binarySearchInArray(key);
+ if (index >= 0) {
+ return entryList.get(index).getValue();
+ }
+ return overflowEntries.get(key);
+ }
+
+ @Override
+ public V put(K key, V value) {
+ checkMutable();
+ final int index = binarySearchInArray(key);
+ if (index >= 0) {
+ // Replace existing array entry.
+ return entryList.get(index).setValue(value);
+ }
+ ensureEntryArrayMutable();
+ final int insertionPoint = -(index + 1);
+ if (insertionPoint >= maxArraySize) {
+ // Put directly in overflow.
+ return getOverflowEntriesMutable().put(key, value);
+ }
+ // Insert new Entry in array.
+ if (entryList.size() == maxArraySize) {
+ // Shift the last array entry into overflow.
+ final Entry lastEntryInArray = entryList.remove(maxArraySize - 1);
+ getOverflowEntriesMutable().put(lastEntryInArray.getKey(),
+ lastEntryInArray.getValue());
+ }
+ entryList.add(insertionPoint, new Entry(key, value));
+ return null;
+ }
+
+ @Override
+ public void clear() {
+ checkMutable();
+ if (!entryList.isEmpty()) {
+ entryList.clear();
+ }
+ if (!overflowEntries.isEmpty()) {
+ overflowEntries.clear();
+ }
+ }
+
+ /**
+ * The implementation throws a {@code ClassCastException} if o is not an
+ * object of type {@code K}.
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public V remove(Object o) {
+ checkMutable();
+ @SuppressWarnings("unchecked")
+ final K key = (K) o;
+ final int index = binarySearchInArray(key);
+ if (index >= 0) {
+ return removeArrayEntryAt(index);
+ }
+ // overflowEntries might be Collections.unmodifiableMap(), so only
+ // call remove() if it is non-empty.
+ if (overflowEntries.isEmpty()) {
+ return null;
+ } else {
+ return overflowEntries.remove(key);
+ }
+ }
+
+ private V removeArrayEntryAt(int index) {
+ checkMutable();
+ final V removed = entryList.remove(index).getValue();
+ if (!overflowEntries.isEmpty()) {
+ // Shift the first entry in the overflow to be the last entry in the
+ // array.
+ final Iterator<Map.Entry<K, V>> iterator =
+ getOverflowEntriesMutable().entrySet().iterator();
+ entryList.add(new Entry(iterator.next()));
+ iterator.remove();
+ }
+ return removed;
+ }
+
+ /**
+ * @param key The key to find in the entry array.
+ * @return The returned integer position follows the same semantics as the
+ * value returned by {@link java.util.Arrays#binarySearch()}.
+ */
+ private int binarySearchInArray(K key) {
+ int left = 0;
+ int right = entryList.size() - 1;
+
+ // Optimization: For the common case in which entries are added in
+ // ascending tag order, check the largest element in the array before
+ // doing a full binary search.
+ if (right >= 0) {
+ int cmp = key.compareTo(entryList.get(right).getKey());
+ if (cmp > 0) {
+ return -(right + 2); // Insert point is after "right".
+ } else if (cmp == 0) {
+ return right;
+ }
+ }
+
+ while (left <= right) {
+ int mid = (left + right) / 2;
+ int cmp = key.compareTo(entryList.get(mid).getKey());
+ if (cmp < 0) {
+ right = mid - 1;
+ } else if (cmp > 0) {
+ left = mid + 1;
+ } else {
+ return mid;
+ }
+ }
+ return -(left + 1);
+ }
+
+ /**
+ * Similar to the AbstractMap implementation of {@code keySet()} and
+ * {@code values()}, the entry set is created the first time this method is
+ * called, and returned in response to all subsequent calls.
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Set<Map.Entry<K, V>> entrySet() {
+ if (lazyEntrySet == null) {
+ lazyEntrySet = new EntrySet();
+ }
+ return lazyEntrySet;
+ }
+
+
+ /**
+ * @throws UnsupportedOperationException if {@link #makeImmutable()} has
+ * has been called.
+ */
+ private void checkMutable() {
+ if (isImmutable) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ /**
+ * @return a {@link SortedMap} to which overflow entries mappings can be
+ * added or removed.
+ * @throws UnsupportedOperationException if {@link #makeImmutable()} has been
+ * called.
+ */
+ @SuppressWarnings("unchecked")
+ private SortedMap<K, V> getOverflowEntriesMutable() {
+ checkMutable();
+ if (overflowEntries.isEmpty() && !(overflowEntries instanceof TreeMap)) {
+ overflowEntries = new TreeMap<K, V>();
+ }
+ return (SortedMap<K, V>) overflowEntries;
+ }
+
+ /**
+ * Lazily creates the entry list. Any code that adds to the list must first
+ * call this method.
+ */
+ private void ensureEntryArrayMutable() {
+ checkMutable();
+ if (entryList.isEmpty() && !(entryList instanceof ArrayList)) {
+ entryList = new ArrayList<Entry>(maxArraySize);
+ }
+ }
+
+ /**
+ * Entry implementation that implements Comparable in order to support
+ * binary search within the entry array. Also checks mutability in
+ * {@link #setValue()}.
+ */
+ private class Entry implements Map.Entry<K, V>, Comparable<Entry> {
+
+ private final K key;
+ private V value;
+
+ Entry(Map.Entry<K, V> copy) {
+ this(copy.getKey(), copy.getValue());
+ }
+
+ Entry(K key, V value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ @Override
+ public K getKey() {
+ return key;
+ }
+
+ @Override
+ public V getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(Entry other) {
+ return getKey().compareTo(other.getKey());
+ }
+
+ @Override
+ public V setValue(V newValue) {
+ checkMutable();
+ final V oldValue = this.value;
+ this.value = newValue;
+ return oldValue;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) {
+ return true;
+ }
+ if (!(o instanceof Map.Entry)) {
+ return false;
+ }
+ @SuppressWarnings("unchecked")
+ Map.Entry<?, ?> other = (Map.Entry<?, ?>) o;
+ return equals(key, other.getKey()) && equals(value, other.getValue());
+ }
+
+ @Override
+ public int hashCode() {
+ return (key == null ? 0 : key.hashCode()) ^
+ (value == null ? 0 : value.hashCode());
+ }
+
+ @Override
+ public String toString() {
+ return key + "=" + value;
+ }
+
+ /** equals() that handles null values. */
+ private boolean equals(Object o1, Object o2) {
+ return o1 == null ? o2 == null : o1.equals(o2);
+ }
+ }
+
+ /**
+ * Stateless view of the entries in the field map.
+ */
+ private class EntrySet extends AbstractSet<Map.Entry<K, V>> {
+
+ @Override
+ public Iterator<Map.Entry<K, V>> iterator() {
+ return new EntryIterator();
+ }
+
+ @Override
+ public int size() {
+ return SmallSortedMap.this.size();
+ }
+
+ /**
+ * Throws a {@link ClassCastException} if o is not of the expected type.
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean contains(Object o) {
+ @SuppressWarnings("unchecked")
+ final Map.Entry<K, V> entry = (Map.Entry<K, V>) o;
+ final V existing = get(entry.getKey());
+ final V value = entry.getValue();
+ return existing == value ||
+ (existing != null && existing.equals(value));
+ }
+
+ @Override
+ public boolean add(Map.Entry<K, V> entry) {
+ if (!contains(entry)) {
+ put(entry.getKey(), entry.getValue());
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Throws a {@link ClassCastException} if o is not of the expected type.
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean remove(Object o) {
+ @SuppressWarnings("unchecked")
+ final Map.Entry<K, V> entry = (Map.Entry<K, V>) o;
+ if (contains(entry)) {
+ SmallSortedMap.this.remove(entry.getKey());
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void clear() {
+ SmallSortedMap.this.clear();
+ }
+ }
+
+
+ /**
+ * Iterator implementation that switches from the entry array to the overflow
+ * entries appropriately.
+ */
+ private class EntryIterator implements Iterator<Map.Entry<K, V>> {
+
+ private int pos = -1;
+ private boolean nextCalledBeforeRemove;
+ private Iterator<Map.Entry<K, V>> lazyOverflowIterator;
+
+ @Override
+ public boolean hasNext() {
+ return (pos + 1) < entryList.size() ||
+ getOverflowIterator().hasNext();
+ }
+
+ @Override
+ public Map.Entry<K, V> next() {
+ nextCalledBeforeRemove = true;
+ // Always increment pos so that we know whether the last returned value
+ // was from the array or from overflow.
+ if (++pos < entryList.size()) {
+ return entryList.get(pos);
+ }
+ return getOverflowIterator().next();
+ }
+
+ @Override
+ public void remove() {
+ if (!nextCalledBeforeRemove) {
+ throw new IllegalStateException("remove() was called before next()");
+ }
+ nextCalledBeforeRemove = false;
+ checkMutable();
+
+ if (pos < entryList.size()) {
+ removeArrayEntryAt(pos--);
+ } else {
+ getOverflowIterator().remove();
+ }
+ }
+
+ /**
+ * It is important to create the overflow iterator only after the array
+ * entries have been iterated over because the overflow entry set changes
+ * when the client calls remove() on the array entries, which invalidates
+ * any existing iterators.
+ */
+ private Iterator<Map.Entry<K, V>> getOverflowIterator() {
+ if (lazyOverflowIterator == null) {
+ lazyOverflowIterator = overflowEntries.entrySet().iterator();
+ }
+ return lazyOverflowIterator;
+ }
+ }
+
+ /**
+ * Helper class that holds immutable instances of an Iterable/Iterator that
+ * we return when the overflow entries is empty. This eliminates the creation
+ * of an Iterator object when there is nothing to iterate over.
+ */
+ private static class EmptySet {
+
+ private static final Iterator<Object> ITERATOR =
+ new Iterator<Object>() {
+ @Override
+ public boolean hasNext() {
+ return false;
+ }
+ @Override
+ public Object next() {
+ throw new NoSuchElementException();
+ }
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+ private static final Iterable<Object> ITERABLE =
+ new Iterable<Object>() {
+ @Override
+ public Iterator<Object> iterator() {
+ return ITERATOR;
+ }
+ };
+
+ @SuppressWarnings("unchecked")
+ static <T> Iterable<T> iterable() {
+ return (Iterable<T>) ITERABLE;
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+
+ if (!(o instanceof SmallSortedMap)) {
+ return super.equals(o);
+ }
+
+ SmallSortedMap<?, ?> other = (SmallSortedMap<?, ?>) o;
+ final int size = size();
+ if (size != other.size()) {
+ return false;
+ }
+
+ // Best effort try to avoid allocating an entry set.
+ final int numArrayEntries = getNumArrayEntries();
+ if (numArrayEntries != other.getNumArrayEntries()) {
+ return entrySet().equals(other.entrySet());
+ }
+
+ for (int i = 0; i < numArrayEntries; i++) {
+ if (!getArrayEntryAt(i).equals(other.getArrayEntryAt(i))) {
+ return false;
+ }
+ }
+
+ if (numArrayEntries != size) {
+ return overflowEntries.equals(other.overflowEntries);
+ }
+
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int h = 0;
+ final int listSize = getNumArrayEntries();
+ for (int i = 0; i < listSize; i++) {
+ h += entryList.get(i).hashCode();
+ }
+ // Avoid the iterator allocation if possible.
+ if (getNumOverflowEntries() > 0) {
+ h += overflowEntries.hashCode();
+ }
+ return h;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormat.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormat.java
new file mode 100644
index 0000000000..4970824215
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormat.java
@@ -0,0 +1,2108 @@
+// 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.Descriptor;
+import com.google.protobuf.Descriptors.EnumDescriptor;
+import com.google.protobuf.Descriptors.EnumValueDescriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.nio.CharBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Provide text parsing and formatting support for proto2 instances.
+ * The implementation largely follows google/protobuf/text_format.cc.
+ *
+ * @author wenboz@google.com Wenbo Zhu
+ * @author kenton@google.com Kenton Varda
+ */
+public final class TextFormat {
+ private TextFormat() {}
+
+ private static final Logger logger =
+ Logger.getLogger(TextFormat.class.getName());
+
+ private static final Printer DEFAULT_PRINTER = new Printer();
+ private static final Printer SINGLE_LINE_PRINTER =
+ (new Printer()).setSingleLineMode(true);
+ private static final Printer UNICODE_PRINTER =
+ (new Printer()).setEscapeNonAscii(false);
+
+ /**
+ * Outputs a textual representation of the Protocol Message supplied into
+ * the parameter output. (This representation is the new version of the
+ * classic "ProtocolPrinter" output from the original Protocol Buffer system)
+ */
+ public static void print(
+ final MessageOrBuilder message, final Appendable output)
+ throws IOException {
+ DEFAULT_PRINTER.print(message, new TextGenerator(output));
+ }
+
+ /** Outputs a textual representation of {@code fields} to {@code output}. */
+ public static void print(final UnknownFieldSet fields,
+ final Appendable output)
+ throws IOException {
+ DEFAULT_PRINTER.printUnknownFields(fields, new TextGenerator(output));
+ }
+
+ /**
+ * Same as {@code print()}, except that non-ASCII characters are not
+ * escaped.
+ */
+ public static void printUnicode(
+ final MessageOrBuilder message, final Appendable output)
+ throws IOException {
+ UNICODE_PRINTER.print(message, new TextGenerator(output));
+ }
+
+ /**
+ * Same as {@code print()}, except that non-ASCII characters are not
+ * escaped.
+ */
+ public static void printUnicode(final UnknownFieldSet fields,
+ final Appendable output)
+ throws IOException {
+ UNICODE_PRINTER.printUnknownFields(fields, new TextGenerator(output));
+ }
+
+ /**
+ * Generates a human readable form of this message, useful for debugging and
+ * other purposes, with no newline characters.
+ */
+ public static String shortDebugString(final MessageOrBuilder message) {
+ try {
+ final StringBuilder sb = new StringBuilder();
+ SINGLE_LINE_PRINTER.print(message, new TextGenerator(sb));
+ // Single line mode currently might have an extra space at the end.
+ return sb.toString().trim();
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Generates a human readable form of the field, useful for debugging
+ * and other purposes, with no newline characters.
+ */
+ public static String shortDebugString(final FieldDescriptor field,
+ final Object value) {
+ try {
+ final StringBuilder sb = new StringBuilder();
+ SINGLE_LINE_PRINTER.printField(field, value, new TextGenerator(sb));
+ return sb.toString().trim();
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Generates a human readable form of the unknown fields, useful for debugging
+ * and other purposes, with no newline characters.
+ */
+ public static String shortDebugString(final UnknownFieldSet fields) {
+ try {
+ final StringBuilder sb = new StringBuilder();
+ SINGLE_LINE_PRINTER.printUnknownFields(fields, new TextGenerator(sb));
+ // Single line mode currently might have an extra space at the end.
+ return sb.toString().trim();
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Like {@code print()}, but writes directly to a {@code String} and
+ * returns it.
+ */
+ public static String printToString(final MessageOrBuilder message) {
+ try {
+ final StringBuilder text = new StringBuilder();
+ print(message, text);
+ return text.toString();
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Like {@code print()}, but writes directly to a {@code String} and
+ * returns it.
+ */
+ public static String printToString(final UnknownFieldSet fields) {
+ try {
+ final StringBuilder text = new StringBuilder();
+ print(fields, text);
+ return text.toString();
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Same as {@code printToString()}, except that non-ASCII characters
+ * in string type fields are not escaped in backslash+octals.
+ */
+ public static String printToUnicodeString(final MessageOrBuilder message) {
+ try {
+ final StringBuilder text = new StringBuilder();
+ UNICODE_PRINTER.print(message, new TextGenerator(text));
+ return text.toString();
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Same as {@code printToString()}, except that non-ASCII characters
+ * in string type fields are not escaped in backslash+octals.
+ */
+ public static String printToUnicodeString(final UnknownFieldSet fields) {
+ try {
+ final StringBuilder text = new StringBuilder();
+ UNICODE_PRINTER.printUnknownFields(fields, new TextGenerator(text));
+ return text.toString();
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public static void printField(final FieldDescriptor field,
+ final Object value,
+ final Appendable output)
+ throws IOException {
+ DEFAULT_PRINTER.printField(field, value, new TextGenerator(output));
+ }
+
+ public static String printFieldToString(final FieldDescriptor field,
+ final Object value) {
+ try {
+ final StringBuilder text = new StringBuilder();
+ printField(field, value, text);
+ return text.toString();
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Outputs a textual representation of the value of given field value.
+ *
+ * @param field the descriptor of the field
+ * @param value the value of the field
+ * @param output the output to which to append the formatted value
+ * @throws ClassCastException if the value is not appropriate for the
+ * given field descriptor
+ * @throws IOException if there is an exception writing to the output
+ */
+ public static void printFieldValue(final FieldDescriptor field,
+ final Object value,
+ final Appendable output)
+ throws IOException {
+ DEFAULT_PRINTER.printFieldValue(field, value, new TextGenerator(output));
+ }
+
+ /**
+ * Outputs a textual representation of the value of an unknown field.
+ *
+ * @param tag the field's tag number
+ * @param value the value of the field
+ * @param output the output to which to append the formatted value
+ * @throws ClassCastException if the value is not appropriate for the
+ * given field descriptor
+ * @throws IOException if there is an exception writing to the output
+ */
+ public static void printUnknownFieldValue(final int tag,
+ final Object value,
+ final Appendable output)
+ throws IOException {
+ printUnknownFieldValue(tag, value, new TextGenerator(output));
+ }
+
+ private static void printUnknownFieldValue(final int tag,
+ final Object value,
+ final TextGenerator generator)
+ throws IOException {
+ switch (WireFormat.getTagWireType(tag)) {
+ case WireFormat.WIRETYPE_VARINT:
+ generator.print(unsignedToString((Long) value));
+ break;
+ case WireFormat.WIRETYPE_FIXED32:
+ generator.print(
+ String.format((Locale) null, "0x%08x", (Integer) value));
+ break;
+ case WireFormat.WIRETYPE_FIXED64:
+ generator.print(String.format((Locale) null, "0x%016x", (Long) value));
+ break;
+ case WireFormat.WIRETYPE_LENGTH_DELIMITED:
+ generator.print("\"");
+ generator.print(escapeBytes((ByteString) value));
+ generator.print("\"");
+ break;
+ case WireFormat.WIRETYPE_START_GROUP:
+ DEFAULT_PRINTER.printUnknownFields((UnknownFieldSet) value, generator);
+ break;
+ default:
+ throw new IllegalArgumentException("Bad tag: " + tag);
+ }
+ }
+
+ /** Helper class for converting protobufs to text. */
+ private static final class Printer {
+ /** Whether to omit newlines from the output. */
+ boolean singleLineMode = false;
+
+ /** Whether to escape non ASCII characters with backslash and octal. */
+ boolean escapeNonAscii = true;
+
+ private Printer() {}
+
+ /** Setter of singleLineMode */
+ private Printer setSingleLineMode(boolean singleLineMode) {
+ this.singleLineMode = singleLineMode;
+ return this;
+ }
+
+ /** Setter of escapeNonAscii */
+ private Printer setEscapeNonAscii(boolean escapeNonAscii) {
+ this.escapeNonAscii = escapeNonAscii;
+ return this;
+ }
+
+ private void print(
+ final MessageOrBuilder message, final TextGenerator generator)
+ throws IOException {
+ for (Map.Entry<FieldDescriptor, Object> field
+ : message.getAllFields().entrySet()) {
+ printField(field.getKey(), field.getValue(), generator);
+ }
+ printUnknownFields(message.getUnknownFields(), generator);
+ }
+
+ private void printField(final FieldDescriptor field, final Object value,
+ final TextGenerator generator) throws IOException {
+ if (field.isRepeated()) {
+ // Repeated field. Print each element.
+ for (Object element : (List<?>) value) {
+ printSingleField(field, element, generator);
+ }
+ } else {
+ printSingleField(field, value, generator);
+ }
+ }
+
+ private void printSingleField(final FieldDescriptor field,
+ final Object value,
+ final TextGenerator generator)
+ throws IOException {
+ if (field.isExtension()) {
+ generator.print("[");
+ // We special-case MessageSet elements for compatibility with proto1.
+ if (field.getContainingType().getOptions().getMessageSetWireFormat()
+ && (field.getType() == FieldDescriptor.Type.MESSAGE)
+ && (field.isOptional())
+ // object equality
+ && (field.getExtensionScope() == field.getMessageType())) {
+ generator.print(field.getMessageType().getFullName());
+ } else {
+ generator.print(field.getFullName());
+ }
+ generator.print("]");
+ } else {
+ if (field.getType() == FieldDescriptor.Type.GROUP) {
+ // Groups must be serialized with their original capitalization.
+ generator.print(field.getMessageType().getName());
+ } else {
+ generator.print(field.getName());
+ }
+ }
+
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ if (singleLineMode) {
+ generator.print(" { ");
+ } else {
+ generator.print(" {\n");
+ generator.indent();
+ }
+ } else {
+ generator.print(": ");
+ }
+
+ printFieldValue(field, value, generator);
+
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ if (singleLineMode) {
+ generator.print("} ");
+ } else {
+ generator.outdent();
+ generator.print("}\n");
+ }
+ } else {
+ if (singleLineMode) {
+ generator.print(" ");
+ } else {
+ generator.print("\n");
+ }
+ }
+ }
+
+ private void printFieldValue(final FieldDescriptor field,
+ final Object value,
+ final TextGenerator generator)
+ throws IOException {
+ switch (field.getType()) {
+ case INT32:
+ case SINT32:
+ case SFIXED32:
+ generator.print(((Integer) value).toString());
+ break;
+
+ case INT64:
+ case SINT64:
+ case SFIXED64:
+ generator.print(((Long) value).toString());
+ break;
+
+ case BOOL:
+ generator.print(((Boolean) value).toString());
+ break;
+
+ case FLOAT:
+ generator.print(((Float) value).toString());
+ break;
+
+ case DOUBLE:
+ generator.print(((Double) value).toString());
+ break;
+
+ case UINT32:
+ case FIXED32:
+ generator.print(unsignedToString((Integer) value));
+ break;
+
+ case UINT64:
+ case FIXED64:
+ generator.print(unsignedToString((Long) value));
+ break;
+
+ case STRING:
+ generator.print("\"");
+ generator.print(escapeNonAscii
+ ? TextFormatEscaper.escapeText((String) value)
+ : escapeDoubleQuotesAndBackslashes((String) value)
+ .replace("\n", "\\n"));
+ generator.print("\"");
+ break;
+
+ case BYTES:
+ generator.print("\"");
+ if (value instanceof ByteString) {
+ generator.print(escapeBytes((ByteString) value));
+ } else {
+ generator.print(escapeBytes((byte[]) value));
+ }
+ generator.print("\"");
+ break;
+
+ case ENUM:
+ generator.print(((EnumValueDescriptor) value).getName());
+ break;
+
+ case MESSAGE:
+ case GROUP:
+ print((Message) value, generator);
+ break;
+ }
+ }
+
+ private void printUnknownFields(final UnknownFieldSet unknownFields,
+ final TextGenerator generator)
+ throws IOException {
+ for (Map.Entry<Integer, UnknownFieldSet.Field> entry :
+ unknownFields.asMap().entrySet()) {
+ final int number = entry.getKey();
+ final UnknownFieldSet.Field field = entry.getValue();
+ printUnknownField(number, WireFormat.WIRETYPE_VARINT,
+ field.getVarintList(), generator);
+ printUnknownField(number, WireFormat.WIRETYPE_FIXED32,
+ field.getFixed32List(), generator);
+ printUnknownField(number, WireFormat.WIRETYPE_FIXED64,
+ field.getFixed64List(), generator);
+ printUnknownField(number, WireFormat.WIRETYPE_LENGTH_DELIMITED,
+ field.getLengthDelimitedList(), generator);
+ for (final UnknownFieldSet value : field.getGroupList()) {
+ generator.print(entry.getKey().toString());
+ if (singleLineMode) {
+ generator.print(" { ");
+ } else {
+ generator.print(" {\n");
+ generator.indent();
+ }
+ printUnknownFields(value, generator);
+ if (singleLineMode) {
+ generator.print("} ");
+ } else {
+ generator.outdent();
+ generator.print("}\n");
+ }
+ }
+ }
+ }
+
+ private void printUnknownField(final int number,
+ final int wireType,
+ final List<?> values,
+ final TextGenerator generator)
+ throws IOException {
+ for (final Object value : values) {
+ generator.print(String.valueOf(number));
+ generator.print(": ");
+ printUnknownFieldValue(wireType, value, generator);
+ generator.print(singleLineMode ? " " : "\n");
+ }
+ }
+ }
+
+ /** Convert an unsigned 32-bit integer to a string. */
+ public static String unsignedToString(final int value) {
+ if (value >= 0) {
+ return Integer.toString(value);
+ } else {
+ return Long.toString(value & 0x00000000FFFFFFFFL);
+ }
+ }
+
+ /** Convert an unsigned 64-bit integer to a string. */
+ public static String unsignedToString(final long value) {
+ if (value >= 0) {
+ return Long.toString(value);
+ } else {
+ // Pull off the most-significant bit so that BigInteger doesn't think
+ // the number is negative, then set it again using setBit().
+ return BigInteger.valueOf(value & 0x7FFFFFFFFFFFFFFFL)
+ .setBit(63).toString();
+ }
+ }
+
+ /**
+ * An inner class for writing text to the output stream.
+ */
+ private static final class TextGenerator {
+ private final Appendable output;
+ private final StringBuilder indent = new StringBuilder();
+ private boolean atStartOfLine = true;
+
+ private TextGenerator(final Appendable output) {
+ this.output = output;
+ }
+
+ /**
+ * Indent text by two spaces. After calling Indent(), two spaces will be
+ * inserted at the beginning of each line of text. Indent() may be called
+ * multiple times to produce deeper indents.
+ */
+ public void indent() {
+ indent.append(" ");
+ }
+
+ /**
+ * Reduces the current indent level by two spaces, or crashes if the indent
+ * level is zero.
+ */
+ public void outdent() {
+ final int length = indent.length();
+ if (length == 0) {
+ throw new IllegalArgumentException(
+ " Outdent() without matching Indent().");
+ }
+ indent.delete(length - 2, length);
+ }
+
+ /**
+ * Print text to the output stream.
+ */
+ public void print(final CharSequence text) throws IOException {
+ final int size = text.length();
+ int pos = 0;
+
+ for (int i = 0; i < size; i++) {
+ if (text.charAt(i) == '\n') {
+ write(text.subSequence(pos, i + 1));
+ pos = i + 1;
+ atStartOfLine = true;
+ }
+ }
+ write(text.subSequence(pos, size));
+ }
+
+ private void write(final CharSequence data) throws IOException {
+ if (data.length() == 0) {
+ return;
+ }
+ if (atStartOfLine) {
+ atStartOfLine = false;
+ output.append(indent);
+ }
+ output.append(data);
+ }
+ }
+
+ // =================================================================
+ // Parsing
+
+ /**
+ * Represents a stream of tokens parsed from a {@code String}.
+ *
+ * <p>The Java standard library provides many classes that you might think
+ * would be useful for implementing this, but aren't. For example:
+ *
+ * <ul>
+ * <li>{@code java.io.StreamTokenizer}: This almost does what we want -- or,
+ * at least, something that would get us close to what we want -- except
+ * for one fatal flaw: It automatically un-escapes strings using Java
+ * escape sequences, which do not include all the escape sequences we
+ * need to support (e.g. '\x').
+ * <li>{@code java.util.Scanner}: This seems like a great way at least to
+ * parse regular expressions out of a stream (so we wouldn't have to load
+ * the entire input into a single string before parsing). Sadly,
+ * {@code Scanner} requires that tokens be delimited with some delimiter.
+ * Thus, although the text "foo:" should parse to two tokens ("foo" and
+ * ":"), {@code Scanner} would recognize it only as a single token.
+ * Furthermore, {@code Scanner} provides no way to inspect the contents
+ * of delimiters, making it impossible to keep track of line and column
+ * numbers.
+ * </ul>
+ *
+ * <p>Luckily, Java's regular expression support does manage to be useful to
+ * us. (Barely: We need {@code Matcher.usePattern()}, which is new in
+ * Java 1.5.) So, we can use that, at least. Unfortunately, this implies
+ * that we need to have the entire input in one contiguous string.
+ */
+ private static final class Tokenizer {
+ private final CharSequence text;
+ private final Matcher matcher;
+ private String currentToken;
+
+ // The character index within this.text at which the current token begins.
+ private int pos = 0;
+
+ // The line and column numbers of the current token.
+ private int line = 0;
+ private int column = 0;
+
+ // The line and column numbers of the previous token (allows throwing
+ // errors *after* consuming).
+ private int previousLine = 0;
+ private int previousColumn = 0;
+
+ // We use possessive quantifiers (*+ and ++) because otherwise the Java
+ // regex matcher has stack overflows on large inputs.
+ private static final Pattern WHITESPACE =
+ Pattern.compile("(\\s|(#.*$))++", Pattern.MULTILINE);
+ private static final Pattern TOKEN = Pattern.compile(
+ "[a-zA-Z_][0-9a-zA-Z_+-]*+|" + // an identifier
+ "[.]?[0-9+-][0-9a-zA-Z_.+-]*+|" + // a number
+ "\"([^\"\n\\\\]|\\\\.)*+(\"|\\\\?$)|" + // a double-quoted string
+ "\'([^\'\n\\\\]|\\\\.)*+(\'|\\\\?$)", // a single-quoted string
+ Pattern.MULTILINE);
+
+ private static final Pattern DOUBLE_INFINITY = Pattern.compile(
+ "-?inf(inity)?",
+ Pattern.CASE_INSENSITIVE);
+ private static final Pattern FLOAT_INFINITY = Pattern.compile(
+ "-?inf(inity)?f?",
+ Pattern.CASE_INSENSITIVE);
+ private static final Pattern FLOAT_NAN = Pattern.compile(
+ "nanf?",
+ Pattern.CASE_INSENSITIVE);
+
+ /** Construct a tokenizer that parses tokens from the given text. */
+ private Tokenizer(final CharSequence text) {
+ this.text = text;
+ this.matcher = WHITESPACE.matcher(text);
+ skipWhitespace();
+ nextToken();
+ }
+
+ int getPreviousLine() {
+ return previousLine;
+ }
+
+ int getPreviousColumn() {
+ return previousColumn;
+ }
+
+ int getLine() {
+ return line;
+ }
+
+ int getColumn() {
+ return column;
+ }
+
+ /** Are we at the end of the input? */
+ public boolean atEnd() {
+ return currentToken.length() == 0;
+ }
+
+ /** Advance to the next token. */
+ public void nextToken() {
+ previousLine = line;
+ previousColumn = column;
+
+ // Advance the line counter to the current position.
+ while (pos < matcher.regionStart()) {
+ if (text.charAt(pos) == '\n') {
+ ++line;
+ column = 0;
+ } else {
+ ++column;
+ }
+ ++pos;
+ }
+
+ // Match the next token.
+ if (matcher.regionStart() == matcher.regionEnd()) {
+ // EOF
+ currentToken = "";
+ } else {
+ matcher.usePattern(TOKEN);
+ if (matcher.lookingAt()) {
+ currentToken = matcher.group();
+ matcher.region(matcher.end(), matcher.regionEnd());
+ } else {
+ // Take one character.
+ currentToken = String.valueOf(text.charAt(pos));
+ matcher.region(pos + 1, matcher.regionEnd());
+ }
+
+ skipWhitespace();
+ }
+ }
+
+ /**
+ * Skip over any whitespace so that the matcher region starts at the next
+ * token.
+ */
+ private void skipWhitespace() {
+ matcher.usePattern(WHITESPACE);
+ if (matcher.lookingAt()) {
+ matcher.region(matcher.end(), matcher.regionEnd());
+ }
+ }
+
+ /**
+ * If the next token exactly matches {@code token}, consume it and return
+ * {@code true}. Otherwise, return {@code false} without doing anything.
+ */
+ public boolean tryConsume(final String token) {
+ if (currentToken.equals(token)) {
+ nextToken();
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * If the next token exactly matches {@code token}, consume it. Otherwise,
+ * throw a {@link ParseException}.
+ */
+ public void consume(final String token) throws ParseException {
+ if (!tryConsume(token)) {
+ throw parseException("Expected \"" + token + "\".");
+ }
+ }
+
+ /**
+ * Returns {@code true} if the next token is an integer, but does
+ * not consume it.
+ */
+ public boolean lookingAtInteger() {
+ if (currentToken.length() == 0) {
+ return false;
+ }
+
+ final char c = currentToken.charAt(0);
+ return ('0' <= c && c <= '9')
+ || c == '-' || c == '+';
+ }
+
+ /**
+ * Returns {@code true} if the current token's text is equal to that
+ * specified.
+ */
+ public boolean lookingAt(String text) {
+ return currentToken.equals(text);
+ }
+
+ /**
+ * If the next token is an identifier, consume it and return its value.
+ * Otherwise, throw a {@link ParseException}.
+ */
+ public String consumeIdentifier() throws ParseException {
+ for (int i = 0; i < currentToken.length(); i++) {
+ final char c = currentToken.charAt(i);
+ if (('a' <= c && c <= 'z')
+ || ('A' <= c && c <= 'Z')
+ || ('0' <= c && c <= '9')
+ || (c == '_') || (c == '.')) {
+ // OK
+ } else {
+ throw parseException(
+ "Expected identifier. Found '" + currentToken + "'");
+ }
+ }
+
+ final String result = currentToken;
+ nextToken();
+ return result;
+ }
+
+ /**
+ * If the next token is an identifier, consume it and return {@code true}.
+ * Otherwise, return {@code false} without doing anything.
+ */
+ public boolean tryConsumeIdentifier() {
+ try {
+ consumeIdentifier();
+ return true;
+ } catch (ParseException e) {
+ return false;
+ }
+ }
+
+ /**
+ * If the next token is a 32-bit signed integer, consume it and return its
+ * value. Otherwise, throw a {@link ParseException}.
+ */
+ public int consumeInt32() throws ParseException {
+ try {
+ final int result = parseInt32(currentToken);
+ nextToken();
+ return result;
+ } catch (NumberFormatException e) {
+ throw integerParseException(e);
+ }
+ }
+
+ /**
+ * If the next token is a 32-bit unsigned integer, consume it and return its
+ * value. Otherwise, throw a {@link ParseException}.
+ */
+ public int consumeUInt32() throws ParseException {
+ try {
+ final int result = parseUInt32(currentToken);
+ nextToken();
+ return result;
+ } catch (NumberFormatException e) {
+ throw integerParseException(e);
+ }
+ }
+
+ /**
+ * If the next token is a 64-bit signed integer, consume it and return its
+ * value. Otherwise, throw a {@link ParseException}.
+ */
+ public long consumeInt64() throws ParseException {
+ try {
+ final long result = parseInt64(currentToken);
+ nextToken();
+ return result;
+ } catch (NumberFormatException e) {
+ throw integerParseException(e);
+ }
+ }
+
+ /**
+ * If the next token is a 64-bit signed integer, consume it and return
+ * {@code true}. Otherwise, return {@code false} without doing anything.
+ */
+ public boolean tryConsumeInt64() {
+ try {
+ consumeInt64();
+ return true;
+ } catch (ParseException e) {
+ return false;
+ }
+ }
+
+ /**
+ * If the next token is a 64-bit unsigned integer, consume it and return its
+ * value. Otherwise, throw a {@link ParseException}.
+ */
+ public long consumeUInt64() throws ParseException {
+ try {
+ final long result = parseUInt64(currentToken);
+ nextToken();
+ return result;
+ } catch (NumberFormatException e) {
+ throw integerParseException(e);
+ }
+ }
+
+ /**
+ * If the next token is a 64-bit unsigned integer, consume it and return
+ * {@code true}. Otherwise, return {@code false} without doing anything.
+ */
+ public boolean tryConsumeUInt64() {
+ try {
+ consumeUInt64();
+ return true;
+ } catch (ParseException e) {
+ return false;
+ }
+ }
+
+ /**
+ * If the next token is a double, consume it and return its value.
+ * Otherwise, throw a {@link ParseException}.
+ */
+ public double consumeDouble() throws ParseException {
+ // We need to parse infinity and nan separately because
+ // Double.parseDouble() does not accept "inf", "infinity", or "nan".
+ if (DOUBLE_INFINITY.matcher(currentToken).matches()) {
+ final boolean negative = currentToken.startsWith("-");
+ nextToken();
+ return negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
+ }
+ if (currentToken.equalsIgnoreCase("nan")) {
+ nextToken();
+ return Double.NaN;
+ }
+ try {
+ final double result = Double.parseDouble(currentToken);
+ nextToken();
+ return result;
+ } catch (NumberFormatException e) {
+ throw floatParseException(e);
+ }
+ }
+
+ /**
+ * If the next token is a double, consume it and return {@code true}.
+ * Otherwise, return {@code false} without doing anything.
+ */
+ public boolean tryConsumeDouble() {
+ try {
+ consumeDouble();
+ return true;
+ } catch (ParseException e) {
+ return false;
+ }
+ }
+
+ /**
+ * If the next token is a float, consume it and return its value.
+ * Otherwise, throw a {@link ParseException}.
+ */
+ public float consumeFloat() throws ParseException {
+ // We need to parse infinity and nan separately because
+ // Float.parseFloat() does not accept "inf", "infinity", or "nan".
+ if (FLOAT_INFINITY.matcher(currentToken).matches()) {
+ final boolean negative = currentToken.startsWith("-");
+ nextToken();
+ return negative ? Float.NEGATIVE_INFINITY : Float.POSITIVE_INFINITY;
+ }
+ if (FLOAT_NAN.matcher(currentToken).matches()) {
+ nextToken();
+ return Float.NaN;
+ }
+ try {
+ final float result = Float.parseFloat(currentToken);
+ nextToken();
+ return result;
+ } catch (NumberFormatException e) {
+ throw floatParseException(e);
+ }
+ }
+
+ /**
+ * If the next token is a float, consume it and return {@code true}.
+ * Otherwise, return {@code false} without doing anything.
+ */
+ public boolean tryConsumeFloat() {
+ try {
+ consumeFloat();
+ return true;
+ } catch (ParseException e) {
+ return false;
+ }
+ }
+
+ /**
+ * If the next token is a boolean, consume it and return its value.
+ * Otherwise, throw a {@link ParseException}.
+ */
+ public boolean consumeBoolean() throws ParseException {
+ if (currentToken.equals("true")
+ || currentToken.equals("True")
+ || currentToken.equals("t")
+ || currentToken.equals("1")) {
+ nextToken();
+ return true;
+ } else if (currentToken.equals("false")
+ || currentToken.equals("False")
+ || currentToken.equals("f")
+ || currentToken.equals("0")) {
+ nextToken();
+ return false;
+ } else {
+ throw parseException("Expected \"true\" or \"false\".");
+ }
+ }
+
+ /**
+ * If the next token is a string, consume it and return its (unescaped)
+ * value. Otherwise, throw a {@link ParseException}.
+ */
+ public String consumeString() throws ParseException {
+ return consumeByteString().toStringUtf8();
+ }
+
+ /**
+ * If the next token is a string, consume it and return true. Otherwise,
+ * return false.
+ */
+ public boolean tryConsumeString() {
+ try {
+ consumeString();
+ return true;
+ } catch (ParseException e) {
+ return false;
+ }
+ }
+
+ /**
+ * If the next token is a string, consume it, unescape it as a
+ * {@link ByteString}, and return it. Otherwise, throw a
+ * {@link ParseException}.
+ */
+ public ByteString consumeByteString() throws ParseException {
+ List<ByteString> list = new ArrayList<ByteString>();
+ consumeByteString(list);
+ while (currentToken.startsWith("'") || currentToken.startsWith("\"")) {
+ consumeByteString(list);
+ }
+ return ByteString.copyFrom(list);
+ }
+
+ /**
+ * Like {@link #consumeByteString()} but adds each token of the string to
+ * the given list. String literals (whether bytes or text) may come in
+ * multiple adjacent tokens which are automatically concatenated, like in
+ * C or Python.
+ */
+ private void consumeByteString(List<ByteString> list)
+ throws ParseException {
+ final char quote = currentToken.length() > 0
+ ? currentToken.charAt(0)
+ : '\0';
+ if (quote != '\"' && quote != '\'') {
+ throw parseException("Expected string.");
+ }
+
+ if (currentToken.length() < 2
+ || currentToken.charAt(currentToken.length() - 1) != quote) {
+ throw parseException("String missing ending quote.");
+ }
+
+ try {
+ final String escaped =
+ currentToken.substring(1, currentToken.length() - 1);
+ final ByteString result = unescapeBytes(escaped);
+ nextToken();
+ list.add(result);
+ } catch (InvalidEscapeSequenceException e) {
+ throw parseException(e.getMessage());
+ }
+ }
+
+ /**
+ * Returns a {@link ParseException} with the current line and column
+ * numbers in the description, suitable for throwing.
+ */
+ public ParseException parseException(final String description) {
+ // Note: People generally prefer one-based line and column numbers.
+ return new ParseException(
+ line + 1, column + 1, description);
+ }
+
+ /**
+ * Returns a {@link ParseException} with the line and column numbers of
+ * the previous token in the description, suitable for throwing.
+ */
+ public ParseException parseExceptionPreviousToken(
+ final String description) {
+ // Note: People generally prefer one-based line and column numbers.
+ return new ParseException(
+ previousLine + 1, previousColumn + 1, description);
+ }
+
+ /**
+ * Constructs an appropriate {@link ParseException} for the given
+ * {@code NumberFormatException} when trying to parse an integer.
+ */
+ private ParseException integerParseException(
+ final NumberFormatException e) {
+ return parseException("Couldn't parse integer: " + e.getMessage());
+ }
+
+ /**
+ * Constructs an appropriate {@link ParseException} for the given
+ * {@code NumberFormatException} when trying to parse a float or double.
+ */
+ private ParseException floatParseException(final NumberFormatException e) {
+ return parseException("Couldn't parse number: " + e.getMessage());
+ }
+
+ /**
+ * Returns a {@link UnknownFieldParseException} with the line and column
+ * numbers of the previous token in the description, and the unknown field
+ * name, suitable for throwing.
+ */
+ public UnknownFieldParseException unknownFieldParseExceptionPreviousToken(
+ final String unknownField, final String description) {
+ // Note: People generally prefer one-based line and column numbers.
+ return new UnknownFieldParseException(
+ previousLine + 1, previousColumn + 1, unknownField, description);
+ }
+ }
+
+ /** Thrown when parsing an invalid text format message. */
+ public static class ParseException extends IOException {
+ private static final long serialVersionUID = 3196188060225107702L;
+
+ private final int line;
+ private final int column;
+
+ /** Create a new instance, with -1 as the line and column numbers. */
+ public ParseException(final String message) {
+ this(-1, -1, message);
+ }
+
+ /**
+ * Create a new instance
+ *
+ * @param line the line number where the parse error occurred,
+ * using 1-offset.
+ * @param column the column number where the parser error occurred,
+ * using 1-offset.
+ */
+ public ParseException(final int line, final int column,
+ final String message) {
+ super(Integer.toString(line) + ":" + column + ": " + message);
+ this.line = line;
+ this.column = column;
+ }
+
+ /**
+ * Return the line where the parse exception occurred, or -1 when
+ * none is provided. The value is specified as 1-offset, so the first
+ * line is line 1.
+ */
+ public int getLine() {
+ return line;
+ }
+
+ /**
+ * Return the column where the parse exception occurred, or -1 when
+ * none is provided. The value is specified as 1-offset, so the first
+ * line is line 1.
+ */
+ public int getColumn() {
+ return column;
+ }
+ }
+
+ /**
+ * Thrown when encountering an unknown field while parsing
+ * a text format message.
+ */
+ public static class UnknownFieldParseException extends ParseException {
+ private final String unknownField;
+
+ /**
+ * Create a new instance, with -1 as the line and column numbers, and an
+ * empty unknown field name.
+ */
+ public UnknownFieldParseException(final String message) {
+ this(-1, -1, "", message);
+ }
+
+ /**
+ * Create a new instance
+ *
+ * @param line the line number where the parse error occurred,
+ * using 1-offset.
+ * @param column the column number where the parser error occurred,
+ * using 1-offset.
+ * @param unknownField the name of the unknown field found while parsing.
+ */
+ public UnknownFieldParseException(final int line, final int column,
+ final String unknownField, final String message) {
+ super(line, column, message);
+ this.unknownField = unknownField;
+ }
+
+ /**
+ * Return the name of the unknown field encountered while parsing the
+ * protocol buffer string.
+ */
+ public String getUnknownField() {
+ return unknownField;
+ }
+ }
+
+ private static final Parser PARSER = Parser.newBuilder().build();
+
+ /**
+ * Return a {@link Parser} instance which can parse text-format
+ * messages. The returned instance is thread-safe.
+ */
+ public static Parser getParser() {
+ return PARSER;
+ }
+
+ /**
+ * Parse a text-format message from {@code input} and merge the contents
+ * into {@code builder}.
+ */
+ public static void merge(final Readable input,
+ final Message.Builder builder)
+ throws IOException {
+ PARSER.merge(input, builder);
+ }
+
+ /**
+ * Parse a text-format message from {@code input} and merge the contents
+ * into {@code builder}.
+ */
+ public static void merge(final CharSequence input,
+ final Message.Builder builder)
+ throws ParseException {
+ PARSER.merge(input, builder);
+ }
+
+ /**
+ * Parse a text-format message from {@code input} and merge the contents
+ * into {@code builder}. Extensions will be recognized if they are
+ * registered in {@code extensionRegistry}.
+ */
+ public static void merge(final Readable input,
+ final ExtensionRegistry extensionRegistry,
+ final Message.Builder builder)
+ throws IOException {
+ PARSER.merge(input, extensionRegistry, builder);
+ }
+
+
+ /**
+ * Parse a text-format message from {@code input} and merge the contents
+ * into {@code builder}. Extensions will be recognized if they are
+ * registered in {@code extensionRegistry}.
+ */
+ public static void merge(final CharSequence input,
+ final ExtensionRegistry extensionRegistry,
+ final Message.Builder builder)
+ throws ParseException {
+ PARSER.merge(input, extensionRegistry, builder);
+ }
+
+
+ /**
+ * Parser for text-format proto2 instances. This class is thread-safe.
+ * The implementation largely follows google/protobuf/text_format.cc.
+ *
+ * <p>Use {@link TextFormat#getParser()} to obtain the default parser, or
+ * {@link Builder} to control the parser behavior.
+ */
+ public static class Parser {
+ /**
+ * Determines if repeated values for non-repeated fields and
+ * oneofs are permitted. For example, given required/optional field "foo"
+ * and a oneof containing "baz" and "qux":
+ * <ul>
+ * <li>"foo: 1 foo: 2"
+ * <li>"baz: 1 qux: 2"
+ * <li>merging "foo: 2" into a proto in which foo is already set, or
+ * <li>merging "qux: 2" into a proto in which baz is already set.
+ * </ul>
+ */
+ public enum SingularOverwritePolicy {
+ /** The last value is retained. */
+ ALLOW_SINGULAR_OVERWRITES,
+ /** An error is issued. */
+ FORBID_SINGULAR_OVERWRITES
+ }
+
+ private final boolean allowUnknownFields;
+ private final SingularOverwritePolicy singularOverwritePolicy;
+ private TextFormatParseInfoTree.Builder parseInfoTreeBuilder;
+
+ private Parser(
+ boolean allowUnknownFields, SingularOverwritePolicy singularOverwritePolicy,
+ TextFormatParseInfoTree.Builder parseInfoTreeBuilder) {
+ this.allowUnknownFields = allowUnknownFields;
+ this.singularOverwritePolicy = singularOverwritePolicy;
+ this.parseInfoTreeBuilder = parseInfoTreeBuilder;
+ }
+
+ /**
+ * Returns a new instance of {@link Builder}.
+ */
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
+ /**
+ * Builder that can be used to obtain new instances of {@link Parser}.
+ */
+ public static class Builder {
+ private boolean allowUnknownFields = false;
+ private SingularOverwritePolicy singularOverwritePolicy =
+ SingularOverwritePolicy.ALLOW_SINGULAR_OVERWRITES;
+ private TextFormatParseInfoTree.Builder parseInfoTreeBuilder = null;
+
+
+ /**
+ * Sets parser behavior when a non-repeated field appears more than once.
+ */
+ public Builder setSingularOverwritePolicy(SingularOverwritePolicy p) {
+ this.singularOverwritePolicy = p;
+ return this;
+ }
+
+ public Builder setParseInfoTreeBuilder(
+ TextFormatParseInfoTree.Builder parseInfoTreeBuilder) {
+ this.parseInfoTreeBuilder = parseInfoTreeBuilder;
+ return this;
+ }
+
+ public Parser build() {
+ return new Parser(
+ allowUnknownFields, singularOverwritePolicy, parseInfoTreeBuilder);
+ }
+ }
+
+ /**
+ * Parse a text-format message from {@code input} and merge the contents
+ * into {@code builder}.
+ */
+ public void merge(final Readable input,
+ final Message.Builder builder)
+ throws IOException {
+ merge(input, ExtensionRegistry.getEmptyRegistry(), builder);
+ }
+
+ /**
+ * Parse a text-format message from {@code input} and merge the contents
+ * into {@code builder}.
+ */
+ public void merge(final CharSequence input,
+ final Message.Builder builder)
+ throws ParseException {
+ merge(input, ExtensionRegistry.getEmptyRegistry(), builder);
+ }
+
+ /**
+ * Parse a text-format message from {@code input} and merge the contents
+ * into {@code builder}. Extensions will be recognized if they are
+ * registered in {@code extensionRegistry}.
+ */
+ public void merge(final Readable input,
+ final ExtensionRegistry extensionRegistry,
+ final Message.Builder builder)
+ throws IOException {
+ // Read the entire input to a String then parse that.
+
+ // If StreamTokenizer were not quite so crippled, or if there were a kind
+ // of Reader that could read in chunks that match some particular regex,
+ // or if we wanted to write a custom Reader to tokenize our stream, then
+ // we would not have to read to one big String. Alas, none of these is
+ // the case. Oh well.
+
+ merge(toStringBuilder(input), extensionRegistry, builder);
+ }
+
+
+ private static final int BUFFER_SIZE = 4096;
+
+ // TODO(chrisn): See if working around java.io.Reader#read(CharBuffer)
+ // overhead is worthwhile
+ private static StringBuilder toStringBuilder(final Readable input)
+ throws IOException {
+ final StringBuilder text = new StringBuilder();
+ final CharBuffer buffer = CharBuffer.allocate(BUFFER_SIZE);
+ while (true) {
+ final int n = input.read(buffer);
+ if (n == -1) {
+ break;
+ }
+ buffer.flip();
+ text.append(buffer, 0, n);
+ }
+ return text;
+ }
+
+ // Check both unknown fields and unknown extensions and log warming messages
+ // or throw exceptions according to the flag.
+ private void checkUnknownFields(final List<String> unknownFields)
+ throws ParseException {
+ if (unknownFields.isEmpty()) {
+ return;
+ }
+
+ StringBuilder msg = new StringBuilder("Input contains unknown fields and/or extensions:");
+ for (String field : unknownFields) {
+ msg.append('\n').append(field);
+ }
+
+ if (allowUnknownFields) {
+ logger.warning(msg.toString());
+ } else {
+ String[] lineColumn = unknownFields.get(0).split(":");
+ throw new ParseException(Integer.valueOf(lineColumn[0]),
+ Integer.valueOf(lineColumn[1]), msg.toString());
+ }
+ }
+
+ /**
+ * Parse a text-format message from {@code input} and merge the contents
+ * into {@code builder}. Extensions will be recognized if they are
+ * registered in {@code extensionRegistry}.
+ */
+ public void merge(final CharSequence input,
+ final ExtensionRegistry extensionRegistry,
+ final Message.Builder builder)
+ throws ParseException {
+ final Tokenizer tokenizer = new Tokenizer(input);
+ MessageReflection.BuilderAdapter target =
+ new MessageReflection.BuilderAdapter(builder);
+
+ List<String> unknownFields = new ArrayList<String>();
+
+ while (!tokenizer.atEnd()) {
+ mergeField(tokenizer, extensionRegistry, target, unknownFields);
+ }
+
+ checkUnknownFields(unknownFields);
+ }
+
+
+ /**
+ * Parse a single field from {@code tokenizer} and merge it into
+ * {@code builder}.
+ */
+ private void mergeField(final Tokenizer tokenizer,
+ final ExtensionRegistry extensionRegistry,
+ final MessageReflection.MergeTarget target,
+ List<String> unknownFields)
+ throws ParseException {
+ mergeField(tokenizer, extensionRegistry, target, parseInfoTreeBuilder,
+ unknownFields);
+ }
+
+ /**
+ * Parse a single field from {@code tokenizer} and merge it into
+ * {@code builder}.
+ */
+ private void mergeField(final Tokenizer tokenizer,
+ final ExtensionRegistry extensionRegistry,
+ final MessageReflection.MergeTarget target,
+ TextFormatParseInfoTree.Builder parseTreeBuilder,
+ List<String> unknownFields)
+ throws ParseException {
+ FieldDescriptor field = null;
+ int startLine = tokenizer.getLine();
+ int startColumn = tokenizer.getColumn();
+ final Descriptor type = target.getDescriptorForType();
+ ExtensionRegistry.ExtensionInfo extension = null;
+
+ if (tokenizer.tryConsume("[")) {
+ // An extension.
+ final StringBuilder name =
+ new StringBuilder(tokenizer.consumeIdentifier());
+ while (tokenizer.tryConsume(".")) {
+ name.append('.');
+ name.append(tokenizer.consumeIdentifier());
+ }
+
+ extension = target.findExtensionByName(
+ extensionRegistry, name.toString());
+
+ if (extension == null) {
+ unknownFields.add((tokenizer.getPreviousLine() + 1) + ":" +
+ (tokenizer.getPreviousColumn() + 1) + ":\t" +
+ type.getFullName() + ".[" + name + "]");
+ } else {
+ if (extension.descriptor.getContainingType() != type) {
+ throw tokenizer.parseExceptionPreviousToken(
+ "Extension \"" + name + "\" does not extend message type \""
+ + type.getFullName() + "\".");
+ }
+ field = extension.descriptor;
+ }
+
+ tokenizer.consume("]");
+ } else {
+ final String name = tokenizer.consumeIdentifier();
+ field = type.findFieldByName(name);
+
+ // Group names are expected to be capitalized as they appear in the
+ // .proto file, which actually matches their type names, not their field
+ // names.
+ if (field == null) {
+ // Explicitly specify US locale so that this code does not break when
+ // executing in Turkey.
+ final String lowerName = name.toLowerCase(Locale.US);
+ field = type.findFieldByName(lowerName);
+ // If the case-insensitive match worked but the field is NOT a group,
+ if (field != null && field.getType() != FieldDescriptor.Type.GROUP) {
+ field = null;
+ }
+ }
+ // Again, special-case group names as described above.
+ if (field != null && field.getType() == FieldDescriptor.Type.GROUP
+ && !field.getMessageType().getName().equals(name)) {
+ field = null;
+ }
+
+ if (field == null) {
+ unknownFields.add((tokenizer.getPreviousLine() + 1) + ":" +
+ (tokenizer.getPreviousColumn() + 1) + ":\t" +
+ type.getFullName() + "." + name);
+ }
+ }
+
+ // Skips unknown fields.
+ if (field == null) {
+ // Try to guess the type of this field.
+ // If this field is not a message, there should be a ":" between the
+ // field name and the field value and also the field value should not
+ // start with "{" or "<" which indicates the beginning of a message body.
+ // If there is no ":" or there is a "{" or "<" after ":", this field has
+ // to be a message or the input is ill-formed.
+ if (tokenizer.tryConsume(":")
+ && !tokenizer.lookingAt("{")
+ && !tokenizer.lookingAt("<")) {
+ skipFieldValue(tokenizer);
+ } else {
+ skipFieldMessage(tokenizer);
+ }
+ return;
+ }
+
+ // Handle potential ':'.
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ tokenizer.tryConsume(":"); // optional
+ if (parseTreeBuilder != null) {
+ TextFormatParseInfoTree.Builder childParseTreeBuilder =
+ parseTreeBuilder.getBuilderForSubMessageField(field);
+ consumeFieldValues(tokenizer, extensionRegistry, target, field, extension,
+ childParseTreeBuilder, unknownFields);
+ } else {
+ consumeFieldValues(tokenizer, extensionRegistry, target, field, extension,
+ parseTreeBuilder, unknownFields);
+ }
+ } else {
+ tokenizer.consume(":"); // required
+ consumeFieldValues(tokenizer, extensionRegistry, target, field,
+ extension, parseTreeBuilder, unknownFields);
+ }
+
+ if (parseTreeBuilder != null) {
+ parseTreeBuilder.setLocation(
+ field, TextFormatParseLocation.create(startLine, startColumn));
+ }
+
+ // For historical reasons, fields may optionally be separated by commas or
+ // semicolons.
+ if (!tokenizer.tryConsume(";")) {
+ tokenizer.tryConsume(",");
+ }
+ }
+
+ /**
+ * Parse a one or more field values from {@code tokenizer} and merge it into
+ * {@code builder}.
+ */
+ private void consumeFieldValues(
+ final Tokenizer tokenizer,
+ final ExtensionRegistry extensionRegistry,
+ final MessageReflection.MergeTarget target,
+ final FieldDescriptor field,
+ final ExtensionRegistry.ExtensionInfo extension,
+ final TextFormatParseInfoTree.Builder parseTreeBuilder,
+ List<String> unknownFields)
+ throws ParseException {
+ // Support specifying repeated field values as a comma-separated list.
+ // Ex."foo: [1, 2, 3]"
+ if (field.isRepeated() && tokenizer.tryConsume("[")) {
+ 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(",");
+ }
+ }
+ } else {
+ consumeFieldValue(tokenizer, extensionRegistry, target, field,
+ extension, parseTreeBuilder, unknownFields);
+ }
+ }
+
+ /**
+ * Parse a single field value from {@code tokenizer} and merge it into
+ * {@code builder}.
+ */
+ private void consumeFieldValue(
+ final Tokenizer tokenizer,
+ final ExtensionRegistry extensionRegistry,
+ final MessageReflection.MergeTarget target,
+ final FieldDescriptor field,
+ final ExtensionRegistry.ExtensionInfo extension,
+ final TextFormatParseInfoTree.Builder parseTreeBuilder,
+ List<String> unknownFields)
+ throws ParseException {
+ Object value = null;
+
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ final String endToken;
+ if (tokenizer.tryConsume("<")) {
+ endToken = ">";
+ } else {
+ tokenizer.consume("{");
+ endToken = "}";
+ }
+
+ final MessageReflection.MergeTarget subField;
+ subField = target.newMergeTargetForField(field,
+ (extension == null) ? null : extension.defaultInstance);
+
+ while (!tokenizer.tryConsume(endToken)) {
+ if (tokenizer.atEnd()) {
+ throw tokenizer.parseException(
+ "Expected \"" + endToken + "\".");
+ }
+ mergeField(tokenizer, extensionRegistry, subField, parseTreeBuilder,
+ unknownFields);
+ }
+
+ value = subField.finish();
+
+ } else {
+ switch (field.getType()) {
+ case INT32:
+ case SINT32:
+ case SFIXED32:
+ value = tokenizer.consumeInt32();
+ break;
+
+ case INT64:
+ case SINT64:
+ case SFIXED64:
+ value = tokenizer.consumeInt64();
+ break;
+
+ case UINT32:
+ case FIXED32:
+ value = tokenizer.consumeUInt32();
+ break;
+
+ case UINT64:
+ case FIXED64:
+ value = tokenizer.consumeUInt64();
+ break;
+
+ case FLOAT:
+ value = tokenizer.consumeFloat();
+ break;
+
+ case DOUBLE:
+ value = tokenizer.consumeDouble();
+ break;
+
+ case BOOL:
+ value = tokenizer.consumeBoolean();
+ break;
+
+ case STRING:
+ value = tokenizer.consumeString();
+ break;
+
+ case BYTES:
+ value = tokenizer.consumeByteString();
+ break;
+
+ case ENUM:
+ final EnumDescriptor enumType = field.getEnumType();
+
+ if (tokenizer.lookingAtInteger()) {
+ final int number = tokenizer.consumeInt32();
+ value = enumType.findValueByNumber(number);
+ if (value == null) {
+ throw tokenizer.parseExceptionPreviousToken(
+ "Enum type \"" + enumType.getFullName()
+ + "\" has no value with number " + number + '.');
+ }
+ } else {
+ final String id = tokenizer.consumeIdentifier();
+ value = enumType.findValueByName(id);
+ if (value == null) {
+ throw tokenizer.parseExceptionPreviousToken(
+ "Enum type \"" + enumType.getFullName()
+ + "\" has no value named \"" + id + "\".");
+ }
+ }
+
+ break;
+
+ case MESSAGE:
+ case GROUP:
+ throw new RuntimeException("Can't get here.");
+ }
+ }
+
+ if (field.isRepeated()) {
+ target.addRepeatedField(field, value);
+ } else if ((singularOverwritePolicy
+ == SingularOverwritePolicy.FORBID_SINGULAR_OVERWRITES)
+ && target.hasField(field)) {
+ throw tokenizer.parseExceptionPreviousToken("Non-repeated field \""
+ + field.getFullName() + "\" cannot be overwritten.");
+ } else if ((singularOverwritePolicy
+ == SingularOverwritePolicy.FORBID_SINGULAR_OVERWRITES)
+ && field.getContainingOneof() != null
+ && target.hasOneof(field.getContainingOneof())) {
+ Descriptors.OneofDescriptor oneof = field.getContainingOneof();
+ throw tokenizer.parseExceptionPreviousToken("Field \""
+ + field.getFullName() + "\" is specified along with field \""
+ + target.getOneofFieldDescriptor(oneof).getFullName()
+ + "\", another member of oneof \"" + oneof.getName() + "\".");
+ } else {
+ target.setField(field, value);
+ }
+ }
+
+ /**
+ * Skips the next field including the field's name and value.
+ */
+ private void skipField(Tokenizer tokenizer) throws ParseException {
+ if (tokenizer.tryConsume("[")) {
+ // Extension name.
+ do {
+ tokenizer.consumeIdentifier();
+ } while (tokenizer.tryConsume("."));
+ tokenizer.consume("]");
+ } else {
+ tokenizer.consumeIdentifier();
+ }
+
+ // Try to guess the type of this field.
+ // If this field is not a message, there should be a ":" between the
+ // field name and the field value and also the field value should not
+ // start with "{" or "<" which indicates the beginning of a message body.
+ // If there is no ":" or there is a "{" or "<" after ":", this field has
+ // to be a message or the input is ill-formed.
+ if (tokenizer.tryConsume(":")
+ && !tokenizer.lookingAt("<")
+ && !tokenizer.lookingAt("{")) {
+ skipFieldValue(tokenizer);
+ } else {
+ skipFieldMessage(tokenizer);
+ }
+ // For historical reasons, fields may optionally be separated by commas or
+ // semicolons.
+ if (!tokenizer.tryConsume(";")) {
+ tokenizer.tryConsume(",");
+ }
+ }
+
+ /**
+ * Skips the whole body of a message including the beginning delimiter and
+ * the ending delimiter.
+ */
+ private void skipFieldMessage(Tokenizer tokenizer) throws ParseException {
+ final String delimiter;
+ if (tokenizer.tryConsume("<")) {
+ delimiter = ">";
+ } else {
+ tokenizer.consume("{");
+ delimiter = "}";
+ }
+ while (!tokenizer.lookingAt(">") && !tokenizer.lookingAt("}")) {
+ skipField(tokenizer);
+ }
+ tokenizer.consume(delimiter);
+ }
+
+ /**
+ * Skips a field value.
+ */
+ private void skipFieldValue(Tokenizer tokenizer) throws ParseException {
+ if (tokenizer.tryConsumeString()) {
+ while (tokenizer.tryConsumeString()) {}
+ return;
+ }
+ if (!tokenizer.tryConsumeIdentifier() // includes enum & boolean
+ && !tokenizer.tryConsumeInt64() // includes int32
+ && !tokenizer.tryConsumeUInt64() // includes uint32
+ && !tokenizer.tryConsumeDouble()
+ && !tokenizer.tryConsumeFloat()) {
+ throw tokenizer.parseException(
+ "Invalid field value: " + tokenizer.currentToken);
+ }
+ }
+ }
+
+ // =================================================================
+ // Utility functions
+ //
+ // Some of these methods are package-private because Descriptors.java uses
+ // them.
+
+ /**
+ * Escapes bytes in the format used in protocol buffer text format, which
+ * is the same as the format used for C string literals. All bytes
+ * that are not printable 7-bit ASCII characters are escaped, as well as
+ * backslash, single-quote, and double-quote characters. Characters for
+ * which no defined short-hand escape sequence is defined will be escaped
+ * using 3-digit octal sequences.
+ */
+ public static String escapeBytes(ByteString input) {
+ return TextFormatEscaper.escapeBytes(input);
+ }
+
+ /**
+ * Like {@link #escapeBytes(ByteString)}, but used for byte array.
+ */
+ public static String escapeBytes(byte[] input) {
+ return TextFormatEscaper.escapeBytes(input);
+ }
+
+ /**
+ * Un-escape a byte sequence as escaped using
+ * {@link #escapeBytes(ByteString)}. Two-digit hex escapes (starting with
+ * "\x") are also recognized.
+ */
+ public static ByteString unescapeBytes(final CharSequence charString)
+ throws InvalidEscapeSequenceException {
+ // First convert the Java character sequence to UTF-8 bytes.
+ ByteString input = ByteString.copyFromUtf8(charString.toString());
+ // Then unescape certain byte sequences introduced by ASCII '\\'. The valid
+ // escapes can all be expressed with ASCII characters, so it is safe to
+ // operate on bytes here.
+ //
+ // Unescaping the input byte array will result in a byte sequence that's no
+ // longer than the input. That's because each escape sequence is between
+ // two and four bytes long and stands for a single byte.
+ final byte[] result = new byte[input.size()];
+ int pos = 0;
+ for (int i = 0; i < input.size(); i++) {
+ byte c = input.byteAt(i);
+ if (c == '\\') {
+ if (i + 1 < input.size()) {
+ ++i;
+ c = input.byteAt(i);
+ if (isOctal(c)) {
+ // Octal escape.
+ int code = digitValue(c);
+ if (i + 1 < input.size() && isOctal(input.byteAt(i + 1))) {
+ ++i;
+ code = code * 8 + digitValue(input.byteAt(i));
+ }
+ if (i + 1 < input.size() && isOctal(input.byteAt(i + 1))) {
+ ++i;
+ code = code * 8 + digitValue(input.byteAt(i));
+ }
+ // TODO: Check that 0 <= code && code <= 0xFF.
+ result[pos++] = (byte) code;
+ } else {
+ switch (c) {
+ case 'a' : result[pos++] = 0x07; break;
+ case 'b' : result[pos++] = '\b'; break;
+ case 'f' : result[pos++] = '\f'; break;
+ case 'n' : result[pos++] = '\n'; break;
+ case 'r' : result[pos++] = '\r'; break;
+ case 't' : result[pos++] = '\t'; break;
+ case 'v' : result[pos++] = 0x0b; break;
+ case '\\': result[pos++] = '\\'; break;
+ case '\'': result[pos++] = '\''; break;
+ case '"' : result[pos++] = '\"'; break;
+
+ case 'x':
+ // hex escape
+ int code = 0;
+ if (i + 1 < input.size() && isHex(input.byteAt(i + 1))) {
+ ++i;
+ code = digitValue(input.byteAt(i));
+ } else {
+ throw new InvalidEscapeSequenceException(
+ "Invalid escape sequence: '\\x' with no digits");
+ }
+ if (i + 1 < input.size() && isHex(input.byteAt(i + 1))) {
+ ++i;
+ code = code * 16 + digitValue(input.byteAt(i));
+ }
+ result[pos++] = (byte) code;
+ break;
+
+ default:
+ throw new InvalidEscapeSequenceException(
+ "Invalid escape sequence: '\\" + (char) c + '\'');
+ }
+ }
+ } else {
+ throw new InvalidEscapeSequenceException(
+ "Invalid escape sequence: '\\' at end of string.");
+ }
+ } else {
+ result[pos++] = c;
+ }
+ }
+
+ return result.length == pos
+ ? ByteString.wrap(result) // This reference has not been out of our control.
+ : ByteString.copyFrom(result, 0, pos);
+ }
+
+ /**
+ * Thrown by {@link TextFormat#unescapeBytes} and
+ * {@link TextFormat#unescapeText} when an invalid escape sequence is seen.
+ */
+ public static class InvalidEscapeSequenceException extends IOException {
+ private static final long serialVersionUID = -8164033650142593304L;
+
+ InvalidEscapeSequenceException(final String description) {
+ super(description);
+ }
+ }
+
+ /**
+ * Like {@link #escapeBytes(ByteString)}, but escapes a text string.
+ * Non-ASCII characters are first encoded as UTF-8, then each byte is escaped
+ * individually as a 3-digit octal escape. Yes, it's weird.
+ */
+ static String escapeText(final String input) {
+ return escapeBytes(ByteString.copyFromUtf8(input));
+ }
+
+ /**
+ * Escape double quotes and backslashes in a String for unicode output of a message.
+ */
+ public static String escapeDoubleQuotesAndBackslashes(final String input) {
+ return TextFormatEscaper.escapeDoubleQuotesAndBackslashes(input);
+ }
+
+ /**
+ * Un-escape a text string as escaped using {@link #escapeText(String)}.
+ * Two-digit hex escapes (starting with "\x") are also recognized.
+ */
+ static String unescapeText(final String input)
+ throws InvalidEscapeSequenceException {
+ return unescapeBytes(input).toStringUtf8();
+ }
+
+ /** Is this an octal digit? */
+ private static boolean isOctal(final byte c) {
+ return '0' <= c && c <= '7';
+ }
+
+ /** Is this a hex digit? */
+ private static boolean isHex(final byte c) {
+ return ('0' <= c && c <= '9')
+ || ('a' <= c && c <= 'f')
+ || ('A' <= c && c <= 'F');
+ }
+
+ /**
+ * Interpret a character as a digit (in any base up to 36) and return the
+ * numeric value. This is like {@code Character.digit()} but we don't accept
+ * non-ASCII digits.
+ */
+ private static int digitValue(final byte c) {
+ if ('0' <= c && c <= '9') {
+ return c - '0';
+ } else if ('a' <= c && c <= 'z') {
+ return c - 'a' + 10;
+ } else {
+ return c - 'A' + 10;
+ }
+ }
+
+ /**
+ * Parse a 32-bit signed integer from the text. Unlike the Java standard
+ * {@code Integer.parseInt()}, this function recognizes the prefixes "0x"
+ * and "0" to signify hexadecimal and octal numbers, respectively.
+ */
+ static int parseInt32(final String text) throws NumberFormatException {
+ return (int) parseInteger(text, true, false);
+ }
+
+ /**
+ * Parse a 32-bit unsigned integer from the text. Unlike the Java standard
+ * {@code Integer.parseInt()}, this function recognizes the prefixes "0x"
+ * and "0" to signify hexadecimal and octal numbers, respectively. The
+ * result is coerced to a (signed) {@code int} when returned since Java has
+ * no unsigned integer type.
+ */
+ static int parseUInt32(final String text) throws NumberFormatException {
+ return (int) parseInteger(text, false, false);
+ }
+
+ /**
+ * Parse a 64-bit signed integer from the text. Unlike the Java standard
+ * {@code Integer.parseInt()}, this function recognizes the prefixes "0x"
+ * and "0" to signify hexadecimal and octal numbers, respectively.
+ */
+ static long parseInt64(final String text) throws NumberFormatException {
+ return parseInteger(text, true, true);
+ }
+
+ /**
+ * Parse a 64-bit unsigned integer from the text. Unlike the Java standard
+ * {@code Integer.parseInt()}, this function recognizes the prefixes "0x"
+ * and "0" to signify hexadecimal and octal numbers, respectively. The
+ * result is coerced to a (signed) {@code long} when returned since Java has
+ * no unsigned long type.
+ */
+ static long parseUInt64(final String text) throws NumberFormatException {
+ return parseInteger(text, false, true);
+ }
+
+ private static long parseInteger(final String text,
+ final boolean isSigned,
+ final boolean isLong)
+ throws NumberFormatException {
+ int pos = 0;
+
+ boolean negative = false;
+ if (text.startsWith("-", pos)) {
+ if (!isSigned) {
+ throw new NumberFormatException("Number must be positive: " + text);
+ }
+ ++pos;
+ negative = true;
+ }
+
+ int radix = 10;
+ if (text.startsWith("0x", pos)) {
+ pos += 2;
+ radix = 16;
+ } else if (text.startsWith("0", pos)) {
+ radix = 8;
+ }
+
+ final String numberText = text.substring(pos);
+
+ long result = 0;
+ if (numberText.length() < 16) {
+ // Can safely assume no overflow.
+ result = Long.parseLong(numberText, radix);
+ if (negative) {
+ result = -result;
+ }
+
+ // Check bounds.
+ // No need to check for 64-bit numbers since they'd have to be 16 chars
+ // or longer to overflow.
+ if (!isLong) {
+ if (isSigned) {
+ if (result > Integer.MAX_VALUE || result < Integer.MIN_VALUE) {
+ throw new NumberFormatException(
+ "Number out of range for 32-bit signed integer: " + text);
+ }
+ } else {
+ if (result >= (1L << 32) || result < 0) {
+ throw new NumberFormatException(
+ "Number out of range for 32-bit unsigned integer: " + text);
+ }
+ }
+ }
+ } else {
+ BigInteger bigValue = new BigInteger(numberText, radix);
+ if (negative) {
+ bigValue = bigValue.negate();
+ }
+
+ // Check bounds.
+ if (!isLong) {
+ if (isSigned) {
+ if (bigValue.bitLength() > 31) {
+ throw new NumberFormatException(
+ "Number out of range for 32-bit signed integer: " + text);
+ }
+ } else {
+ if (bigValue.bitLength() > 32) {
+ throw new NumberFormatException(
+ "Number out of range for 32-bit unsigned integer: " + text);
+ }
+ }
+ } else {
+ if (isSigned) {
+ if (bigValue.bitLength() > 63) {
+ throw new NumberFormatException(
+ "Number out of range for 64-bit signed integer: " + text);
+ }
+ } else {
+ if (bigValue.bitLength() > 64) {
+ throw new NumberFormatException(
+ "Number out of range for 64-bit unsigned integer: " + text);
+ }
+ }
+ }
+
+ result = bigValue.longValue();
+ }
+
+ return result;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormatEscaper.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormatEscaper.java
new file mode 100644
index 0000000000..da9ceadd16
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormatEscaper.java
@@ -0,0 +1,137 @@
+// 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;
+
+/**
+ * Provide text format escaping support for proto2 instances.
+ */
+final class TextFormatEscaper {
+ private TextFormatEscaper() {}
+
+ private interface ByteSequence {
+ int size();
+ byte byteAt(int offset);
+ }
+
+ /**
+ * Escapes bytes in the format used in protocol buffer text format, which
+ * is the same as the format used for C string literals. All bytes
+ * that are not printable 7-bit ASCII characters are escaped, as well as
+ * backslash, single-quote, and double-quote characters. Characters for
+ * which no defined short-hand escape sequence is defined will be escaped
+ * using 3-digit octal sequences.
+ */
+ static String escapeBytes(final ByteSequence input) {
+ final StringBuilder builder = new StringBuilder(input.size());
+ for (int i = 0; i < input.size(); i++) {
+ final byte b = input.byteAt(i);
+ switch (b) {
+ // Java does not recognize \a or \v, apparently.
+ case 0x07: builder.append("\\a"); break;
+ case '\b': builder.append("\\b"); break;
+ case '\f': builder.append("\\f"); break;
+ case '\n': builder.append("\\n"); break;
+ case '\r': builder.append("\\r"); break;
+ case '\t': builder.append("\\t"); break;
+ case 0x0b: builder.append("\\v"); break;
+ case '\\': builder.append("\\\\"); break;
+ case '\'': builder.append("\\\'"); break;
+ case '"' : builder.append("\\\""); break;
+ default:
+ // Only ASCII characters between 0x20 (space) and 0x7e (tilde) are
+ // printable. Other byte values must be escaped.
+ if (b >= 0x20 && b <= 0x7e) {
+ builder.append((char) b);
+ } else {
+ builder.append('\\');
+ builder.append((char) ('0' + ((b >>> 6) & 3)));
+ builder.append((char) ('0' + ((b >>> 3) & 7)));
+ builder.append((char) ('0' + (b & 7)));
+ }
+ break;
+ }
+ }
+ return builder.toString();
+ }
+
+ /**
+ * Escapes bytes in the format used in protocol buffer text format, which
+ * is the same as the format used for C string literals. All bytes
+ * that are not printable 7-bit ASCII characters are escaped, as well as
+ * backslash, single-quote, and double-quote characters. Characters for
+ * which no defined short-hand escape sequence is defined will be escaped
+ * using 3-digit octal sequences.
+ */
+ static String escapeBytes(final ByteString input) {
+ return escapeBytes(new ByteSequence() {
+ @Override
+ public int size() {
+ return input.size();
+ }
+ @Override
+ public byte byteAt(int offset) {
+ return input.byteAt(offset);
+ }
+ });
+ }
+
+ /**
+ * Like {@link #escapeBytes(ByteString)}, but used for byte array.
+ */
+ static String escapeBytes(final byte[] input) {
+ return escapeBytes(new ByteSequence() {
+ @Override
+ public int size() {
+ return input.length;
+ }
+ @Override
+ public byte byteAt(int offset) {
+ return input[offset];
+ }
+ });
+ }
+
+ /**
+ * Like {@link #escapeBytes(ByteString)}, but escapes a text string.
+ * Non-ASCII characters are first encoded as UTF-8, then each byte is escaped
+ * individually as a 3-digit octal escape. Yes, it's weird.
+ */
+ static String escapeText(final String input) {
+ return escapeBytes(ByteString.copyFromUtf8(input));
+ }
+
+ /**
+ * Escape double quotes and backslashes in a String for unicode output of a message.
+ */
+ static String escapeDoubleQuotesAndBackslashes(final String input) {
+ return input.replace("\\", "\\\\").replace("\"", "\\\"");
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormatParseInfoTree.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormatParseInfoTree.java
new file mode 100644
index 0000000000..0127ce92a3
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormatParseInfoTree.java
@@ -0,0 +1,226 @@
+// 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.FieldDescriptor;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+
+/**
+ * Data structure which is populated with the locations of each field value parsed from the text.
+ *
+ * <p>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}.
+ *
+ * <p>The {@code TextFormatParseInfoTree} is created by a Builder.
+ */
+public class TextFormatParseInfoTree {
+
+ // Defines a mapping between each field's descriptor to the list of locations where
+ // its value(s) were was encountered.
+ private Map<FieldDescriptor, List<TextFormatParseLocation>> locationsFromField;
+
+ // Defines a mapping between a field's descriptor to a list of TextFormatParseInfoTrees for
+ // sub message location information.
+ Map<FieldDescriptor, List<TextFormatParseInfoTree>> subtreesFromField;
+
+ /**
+ * Construct a {@code TextFormatParseInfoTree}.
+ *
+ * @param locationsFromField a map of fields to location in the source code
+ * @param subtreeBuildersFromField a map of fields to parse tree location information builders
+ */
+ private TextFormatParseInfoTree(
+ Map<FieldDescriptor, List<TextFormatParseLocation>> locationsFromField,
+ Map<FieldDescriptor, List<TextFormatParseInfoTree.Builder>> subtreeBuildersFromField) {
+
+ // The maps are unmodifiable. The values in the maps are unmodifiable.
+ Map<FieldDescriptor, List<TextFormatParseLocation>> locs =
+ new HashMap<FieldDescriptor, List<TextFormatParseLocation>>();
+ for (Entry<FieldDescriptor, List<TextFormatParseLocation>> kv : locationsFromField.entrySet()) {
+ locs.put(kv.getKey(), Collections.unmodifiableList(kv.getValue()));
+ }
+ this.locationsFromField = Collections.unmodifiableMap(locs);
+
+ Map<FieldDescriptor, List<TextFormatParseInfoTree>> subs =
+ new HashMap<FieldDescriptor, List<TextFormatParseInfoTree>>();
+ for (Entry<FieldDescriptor, List<Builder>> kv : subtreeBuildersFromField.entrySet()) {
+ List<TextFormatParseInfoTree> submessagesOfField = new ArrayList<TextFormatParseInfoTree>();
+ for (Builder subBuilder : kv.getValue()) {
+ submessagesOfField.add(subBuilder.build());
+ }
+ subs.put(kv.getKey(), Collections.unmodifiableList(submessagesOfField));
+ }
+ this.subtreesFromField = Collections.unmodifiableMap(subs);
+ }
+
+ /**
+ * Retrieve all the locations of a field.
+ *
+ * @param fieldDescriptor the the @{link FieldDescriptor} of the desired field
+ * @return a list of the locations of values of the field. If there are not values
+ * or the field doesn't exist, an empty list is returned.
+ */
+ public List<TextFormatParseLocation> getLocations(final FieldDescriptor fieldDescriptor) {
+ List<TextFormatParseLocation> result = locationsFromField.get(fieldDescriptor);
+ return (result == null) ? Collections.<TextFormatParseLocation>emptyList() : result;
+ }
+
+ /**
+ * Get the location in the source of a field's value.
+ *
+ * <p>Returns the {@link TextFormatParseLocation} for index-th value of the field in the parsed
+ * text.
+ *
+ * @param fieldDescriptor the @{link FieldDescriptor} of the desired field
+ * @param index the index of the value.
+ * @return the {@link TextFormatParseLocation} of the value
+ * @throws IllegalArgumentException index is out of range
+ */
+ public TextFormatParseLocation getLocation(final FieldDescriptor fieldDescriptor, int index) {
+ return getFromList(getLocations(fieldDescriptor), index, fieldDescriptor);
+ }
+
+ /**
+ * Retrieve a list of all the location information trees for a sub message field.
+ *
+ * @param fieldDescriptor the @{link FieldDescriptor} of the desired field
+ * @return A list of {@link TextFormatParseInfoTree}
+ */
+ public List<TextFormatParseInfoTree> getNestedTrees(final FieldDescriptor fieldDescriptor) {
+ List<TextFormatParseInfoTree> result = subtreesFromField.get(fieldDescriptor);
+ return result == null ? Collections.<TextFormatParseInfoTree>emptyList() : result;
+ }
+
+ /**
+ * Returns the parse info tree for the given field, which must be a message type.
+ *
+ * @param fieldDescriptor the @{link FieldDescriptor} of the desired sub message
+ * @param index the index of message value.
+ * @return the {@code ParseInfoTree} of the message value. {@code null} is returned if the field
+ * doesn't exist or the index is out of range.
+ * @throws IllegalArgumentException if index is out of range
+ */
+ public TextFormatParseInfoTree getNestedTree(final FieldDescriptor fieldDescriptor, int index) {
+ return getFromList(getNestedTrees(fieldDescriptor), index, fieldDescriptor);
+ }
+
+ /**
+ * Create a builder for a {@code ParseInfoTree}.
+ *
+ * @return the builder
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ private static <T> T getFromList(List<T> list, int index, FieldDescriptor fieldDescriptor) {
+ if (index >= list.size() || index < 0) {
+ throw new IllegalArgumentException(String.format("Illegal index field: %s, index %d",
+ fieldDescriptor == null ? "<null>" : fieldDescriptor.getName(), index));
+ }
+ return list.get(index);
+ }
+
+ /**
+ * Builder for a {@link TextFormatParseInfoTree}.
+ */
+ public static class Builder {
+
+ private Map<FieldDescriptor, List<TextFormatParseLocation>> locationsFromField;
+
+ // Defines a mapping between a field's descriptor to a list of ParseInfoTrees builders for
+ // sub message location information.
+ private Map<FieldDescriptor, List<Builder>> subtreeBuildersFromField;
+
+ /**
+ * Create a root level {@ParseInfoTree} builder.
+ */
+ private Builder() {
+ locationsFromField = new HashMap<FieldDescriptor, List<TextFormatParseLocation>>();
+ subtreeBuildersFromField = new HashMap<FieldDescriptor, List<Builder>>();
+ }
+
+ /**
+ * Record the starting location of a single value for a field.
+ *
+ * @param fieldDescriptor the field
+ * @param location source code location information
+ */
+ public Builder setLocation(
+ final FieldDescriptor fieldDescriptor, TextFormatParseLocation location) {
+ List<TextFormatParseLocation> fieldLocations = locationsFromField.get(fieldDescriptor);
+ if (fieldLocations == null) {
+ fieldLocations = new ArrayList<TextFormatParseLocation>();
+ locationsFromField.put(fieldDescriptor, fieldLocations);
+ }
+ fieldLocations.add(location);
+ return this;
+ }
+
+ /**
+ * Set for a sub message.
+ *
+ * <p>A new builder is created for a sub message. The builder that is returned is a new builder.
+ * The return is <em>not</em> the invoked {@code builder.getBuilderForSubMessageField}.
+ *
+ * @param fieldDescriptor the field whose value is the submessage
+ * @return a new Builder for the sub message
+ */
+ public Builder getBuilderForSubMessageField(final FieldDescriptor fieldDescriptor) {
+ List<Builder> submessageBuilders = subtreeBuildersFromField.get(fieldDescriptor);
+ if (submessageBuilders == null) {
+ submessageBuilders = new ArrayList<Builder>();
+ subtreeBuildersFromField.put(fieldDescriptor, submessageBuilders);
+ }
+ Builder subtreeBuilder = new Builder();
+ submessageBuilders.add(subtreeBuilder);
+ return subtreeBuilder;
+ }
+
+ /**
+ * Build the {@code TextFormatParseInfoTree}.
+ *
+ * @return the {@code TextFormatParseInfoTree}
+ */
+ public TextFormatParseInfoTree build() {
+ return new TextFormatParseInfoTree(locationsFromField, subtreeBuildersFromField);
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormatParseLocation.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormatParseLocation.java
new file mode 100644
index 0000000000..cce286e10f
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/TextFormatParseLocation.java
@@ -0,0 +1,104 @@
+// 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.util.Arrays;
+
+/**
+ * A location in the source code.
+ *
+ * <p>A location is the starting line number and starting column number.
+ */
+public final class TextFormatParseLocation {
+
+ /**
+ * The empty location.
+ */
+ public static final TextFormatParseLocation EMPTY = new TextFormatParseLocation(-1, -1);
+
+ /**
+ * Create a location.
+ *
+ * @param line the starting line number
+ * @param column the starting column number
+ * @return a {@code ParseLocation}
+ */
+ static TextFormatParseLocation create(int line, int column) {
+ if (line == -1 && column == -1) {
+ return EMPTY;
+ }
+ if (line < 0 || column < 0) {
+ throw new IllegalArgumentException(
+ String.format("line and column values must be >= 0: line %d, column: %d", line, column));
+ }
+ return new TextFormatParseLocation(line, column);
+ }
+
+ private final int line;
+ private final int column;
+
+ private TextFormatParseLocation(int line, int column) {
+ this.line = line;
+ this.column = column;
+ }
+
+ public int getLine() {
+ return line;
+ }
+
+ public int getColumn() {
+ return column;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("ParseLocation{line=%d, column=%d}", line, column);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) {
+ return true;
+ }
+ if (!(o instanceof TextFormatParseLocation)) {
+ return false;
+ }
+ TextFormatParseLocation that = (TextFormatParseLocation) o;
+ return (this.line == that.getLine())
+ && (this.column == that.getColumn());
+ }
+
+ @Override
+ public int hashCode() {
+ int[] values = {line, column};
+ return Arrays.hashCode(values);
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UninitializedMessageException.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UninitializedMessageException.java
new file mode 100644
index 0000000000..5714c063a9
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UninitializedMessageException.java
@@ -0,0 +1,99 @@
+// 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.util.Collections;
+import java.util.List;
+
+/**
+ * Thrown when attempting to build a protocol message that is missing required
+ * fields. This is a {@code RuntimeException} because it normally represents
+ * a programming error: it happens when some code which constructs a message
+ * fails to set all the fields. {@code parseFrom()} methods <b>do not</b>
+ * throw this; they throw an {@link InvalidProtocolBufferException} if
+ * required fields are missing, because it is not a programming error to
+ * receive an incomplete message. In other words,
+ * {@code UninitializedMessageException} should never be thrown by correct
+ * code, but {@code InvalidProtocolBufferException} might be.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class UninitializedMessageException extends RuntimeException {
+ private static final long serialVersionUID = -7466929953374883507L;
+
+ public UninitializedMessageException(final MessageLite message) {
+ super("Message was missing required fields. (Lite runtime could not " +
+ "determine which fields were missing).");
+ missingFields = null;
+ }
+
+ public UninitializedMessageException(final List<String> missingFields) {
+ super(buildDescription(missingFields));
+ this.missingFields = missingFields;
+ }
+
+ private final List<String> missingFields;
+
+ /**
+ * Get a list of human-readable names of required fields missing from this
+ * message. Each name is a full path to a field, e.g. "foo.bar[5].baz".
+ * Returns null if the lite runtime was used, since it lacks the ability to
+ * find missing fields.
+ */
+ public List<String> getMissingFields() {
+ return Collections.unmodifiableList(missingFields);
+ }
+
+ /**
+ * Converts this exception to an {@link InvalidProtocolBufferException}.
+ * When a parsed message is missing required fields, this should be thrown
+ * instead of {@code UninitializedMessageException}.
+ */
+ public InvalidProtocolBufferException asInvalidProtocolBufferException() {
+ return new InvalidProtocolBufferException(getMessage());
+ }
+
+ /** Construct the description string for this exception. */
+ private static String buildDescription(final List<String> missingFields) {
+ final StringBuilder description =
+ new StringBuilder("Message missing required fields: ");
+ boolean first = true;
+ for (final String field : missingFields) {
+ if (first) {
+ first = false;
+ } else {
+ description.append(", ");
+ }
+ description.append(field);
+ }
+ return description.toString();
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java
new file mode 100644
index 0000000000..2bef27e923
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnknownFieldSet.java
@@ -0,0 +1,1042 @@
+// 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;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * {@code UnknownFieldSet} is used to keep track of fields which were seen when
+ * parsing a protocol message but whose field numbers or types are unrecognized.
+ * This most frequently occurs when new fields are added to a message type
+ * and then messages containing those fields are read by old software that was
+ * compiled before the new types were added.
+ *
+ * <p>Every {@link Message} contains an {@code UnknownFieldSet} (and every
+ * {@link Message.Builder} contains an {@link Builder}).
+ *
+ * <p>Most users will never need to use this class.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public final class UnknownFieldSet implements MessageLite {
+
+ private UnknownFieldSet() {
+ fields = null;
+ }
+
+ /** Create a new {@link Builder}. */
+ public static Builder newBuilder() {
+ return Builder.create();
+ }
+
+ /**
+ * Create a new {@link Builder} and initialize it to be a copy
+ * of {@code copyFrom}.
+ */
+ public static Builder newBuilder(final UnknownFieldSet copyFrom) {
+ return newBuilder().mergeFrom(copyFrom);
+ }
+
+ /** Get an empty {@code UnknownFieldSet}. */
+ public static UnknownFieldSet getDefaultInstance() {
+ return defaultInstance;
+ }
+ @Override
+ public UnknownFieldSet getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+ private static final UnknownFieldSet defaultInstance =
+ new UnknownFieldSet(Collections.<Integer, Field>emptyMap(),
+ Collections.<Integer, Field>emptyMap());
+
+ /**
+ * Construct an {@code UnknownFieldSet} around the given map. The map is
+ * expected to be immutable.
+ */
+ private UnknownFieldSet(final Map<Integer, Field> fields,
+ final Map<Integer, Field> fieldsDescending) {
+ this.fields = fields;
+ }
+ private final Map<Integer, Field> fields;
+
+
+ @Override
+ public boolean equals(final Object other) {
+ if (this == other) {
+ return true;
+ }
+ return (other instanceof UnknownFieldSet) &&
+ fields.equals(((UnknownFieldSet) other).fields);
+ }
+
+ @Override
+ public int hashCode() {
+ return fields.hashCode();
+ }
+
+ /** Get a map of fields in the set by number. */
+ public Map<Integer, Field> asMap() {
+ return fields;
+ }
+
+ /** Check if the given field number is present in the set. */
+ public boolean hasField(final int number) {
+ return fields.containsKey(number);
+ }
+
+ /**
+ * Get a field by number. Returns an empty field if not present. Never
+ * returns {@code null}.
+ */
+ public Field getField(final int number) {
+ final Field result = fields.get(number);
+ return (result == null) ? Field.getDefaultInstance() : result;
+ }
+
+ /** Serializes the set and writes it to {@code output}. */
+ @Override
+ public void writeTo(final CodedOutputStream output) throws IOException {
+ for (final Map.Entry<Integer, Field> entry : fields.entrySet()) {
+ Field field = entry.getValue();
+ field.writeTo(entry.getKey(), output);
+ }
+ }
+
+ /**
+ * Converts the set to a string in protocol buffer text format. This is
+ * just a trivial wrapper around
+ * {@link TextFormat#printToString(UnknownFieldSet)}.
+ */
+ @Override
+ public String toString() {
+ return TextFormat.printToString(this);
+ }
+
+ /**
+ * Serializes the message to a {@code ByteString} and returns it. This is
+ * just a trivial wrapper around {@link #writeTo(CodedOutputStream)}.
+ */
+ @Override
+ public ByteString toByteString() {
+ try {
+ final ByteString.CodedBuilder out =
+ ByteString.newCodedBuilder(getSerializedSize());
+ writeTo(out.getCodedOutput());
+ return out.build();
+ } catch (final IOException e) {
+ throw new RuntimeException(
+ "Serializing to a ByteString threw an IOException (should " +
+ "never happen).", e);
+ }
+ }
+
+ /**
+ * Serializes the message to a {@code byte} array and returns it. This is
+ * just a trivial wrapper around {@link #writeTo(CodedOutputStream)}.
+ */
+ @Override
+ public byte[] toByteArray() {
+ try {
+ final byte[] result = new byte[getSerializedSize()];
+ final CodedOutputStream output = CodedOutputStream.newInstance(result);
+ writeTo(output);
+ output.checkNoSpaceLeft();
+ return result;
+ } catch (final IOException e) {
+ throw new RuntimeException(
+ "Serializing to a byte array threw an IOException " +
+ "(should never happen).", e);
+ }
+ }
+
+ /**
+ * Serializes the message and writes it to {@code output}. This is just a
+ * trivial wrapper around {@link #writeTo(CodedOutputStream)}.
+ */
+ @Override
+ public void writeTo(final OutputStream output) throws IOException {
+ final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output);
+ writeTo(codedOutput);
+ codedOutput.flush();
+ }
+
+ @Override
+ public void writeDelimitedTo(OutputStream output) throws IOException {
+ final CodedOutputStream codedOutput = CodedOutputStream.newInstance(output);
+ codedOutput.writeRawVarint32(getSerializedSize());
+ writeTo(codedOutput);
+ codedOutput.flush();
+ }
+
+ /** Get the number of bytes required to encode this set. */
+ @Override
+ public int getSerializedSize() {
+ int result = 0;
+ for (final Map.Entry<Integer, Field> entry : fields.entrySet()) {
+ result += entry.getValue().getSerializedSize(entry.getKey());
+ }
+ return result;
+ }
+
+ /**
+ * Serializes the set and writes it to {@code output} using
+ * {@code MessageSet} wire format.
+ */
+ public void writeAsMessageSetTo(final CodedOutputStream output)
+ throws IOException {
+ for (final Map.Entry<Integer, Field> entry : fields.entrySet()) {
+ entry.getValue().writeAsMessageSetExtensionTo(
+ entry.getKey(), output);
+ }
+ }
+
+
+ /** Get the number of bytes required to encode this set using {@code MessageSet} wire format. */
+ public int getSerializedSizeAsMessageSet() {
+ int result = 0;
+ for (final Map.Entry<Integer, Field> entry : fields.entrySet()) {
+ result += entry.getValue().getSerializedSizeAsMessageSetExtension(
+ entry.getKey());
+ }
+ return result;
+ }
+
+ @Override
+ public boolean isInitialized() {
+ // UnknownFieldSets do not have required fields, so they are always
+ // initialized.
+ return true;
+ }
+
+ /** Parse an {@code UnknownFieldSet} from the given input stream. */
+ public static UnknownFieldSet parseFrom(final CodedInputStream input)
+ throws IOException {
+ return newBuilder().mergeFrom(input).build();
+ }
+
+ /** Parse {@code data} as an {@code UnknownFieldSet} and return it. */
+ public static UnknownFieldSet parseFrom(final ByteString data)
+ throws InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).build();
+ }
+
+ /** Parse {@code data} as an {@code UnknownFieldSet} and return it. */
+ public static UnknownFieldSet parseFrom(final byte[] data)
+ throws InvalidProtocolBufferException {
+ return newBuilder().mergeFrom(data).build();
+ }
+
+ /** Parse an {@code UnknownFieldSet} from {@code input} and return it. */
+ public static UnknownFieldSet parseFrom(final InputStream input)
+ throws IOException {
+ return newBuilder().mergeFrom(input).build();
+ }
+
+ @Override
+ public Builder newBuilderForType() {
+ return newBuilder();
+ }
+
+ @Override
+ public Builder toBuilder() {
+ return newBuilder().mergeFrom(this);
+ }
+
+ /**
+ * Builder for {@link UnknownFieldSet}s.
+ *
+ * <p>Note that this class maintains {@link Field.Builder}s for all fields
+ * in the set. Thus, adding one element to an existing {@link Field} does not
+ * require making a copy. This is important for efficient parsing of
+ * unknown repeated fields. However, it implies that {@link Field}s cannot
+ * be constructed independently, nor can two {@link UnknownFieldSet}s share
+ * the same {@code Field} object.
+ *
+ * <p>Use {@link UnknownFieldSet#newBuilder()} to construct a {@code Builder}.
+ */
+ public static final class Builder implements MessageLite.Builder {
+ // This constructor should never be called directly (except from 'create').
+ private Builder() {}
+
+ private Map<Integer, Field> fields;
+
+ // Optimization: We keep around a builder for the last field that was
+ // modified so that we can efficiently add to it multiple times in a
+ // row (important when parsing an unknown repeated field).
+ private int lastFieldNumber;
+ private Field.Builder lastField;
+
+ private static Builder create() {
+ Builder builder = new Builder();
+ builder.reinitialize();
+ return builder;
+ }
+
+ /**
+ * Get a field builder for the given field number which includes any
+ * values that already exist.
+ */
+ private Field.Builder getFieldBuilder(final int number) {
+ if (lastField != null) {
+ if (number == lastFieldNumber) {
+ return lastField;
+ }
+ // Note: addField() will reset lastField and lastFieldNumber.
+ addField(lastFieldNumber, lastField.build());
+ }
+ if (number == 0) {
+ return null;
+ } else {
+ final Field existing = fields.get(number);
+ lastFieldNumber = number;
+ lastField = Field.newBuilder();
+ if (existing != null) {
+ lastField.mergeFrom(existing);
+ }
+ return lastField;
+ }
+ }
+
+ /**
+ * Build the {@link UnknownFieldSet} and return it.
+ *
+ * <p>Once {@code build()} has been called, the {@code Builder} will no
+ * longer be usable. Calling any method after {@code build()} will result
+ * in undefined behavior and can cause a {@code NullPointerException} to be
+ * thrown.
+ */
+ @Override
+ public UnknownFieldSet build() {
+ getFieldBuilder(0); // Force lastField to be built.
+ final UnknownFieldSet result;
+ if (fields.isEmpty()) {
+ result = getDefaultInstance();
+ } else {
+ Map<Integer, Field> descendingFields = null;
+ result = new UnknownFieldSet(Collections.unmodifiableMap(fields), descendingFields);
+ }
+ fields = null;
+ return result;
+ }
+
+ @Override
+ public UnknownFieldSet buildPartial() {
+ // No required fields, so this is the same as build().
+ return build();
+ }
+
+ @Override
+ public Builder clone() {
+ getFieldBuilder(0); // Force lastField to be built.
+ Map<Integer, Field> descendingFields = null;
+ return UnknownFieldSet.newBuilder().mergeFrom(
+ new UnknownFieldSet(fields, descendingFields));
+ }
+
+ @Override
+ public UnknownFieldSet getDefaultInstanceForType() {
+ return UnknownFieldSet.getDefaultInstance();
+ }
+
+ private void reinitialize() {
+ fields = Collections.emptyMap();
+ lastFieldNumber = 0;
+ lastField = null;
+ }
+
+ /** Reset the builder to an empty set. */
+ @Override
+ public Builder clear() {
+ reinitialize();
+ return this;
+ }
+
+ /** Clear fields from the set with a given field number. */
+ public Builder clearField(final int number) {
+ if (number == 0) {
+ throw new IllegalArgumentException("Zero is not a valid field number.");
+ }
+ if (lastField != null && lastFieldNumber == number) {
+ // Discard this.
+ lastField = null;
+ lastFieldNumber = 0;
+ }
+ if (fields.containsKey(number)) {
+ fields.remove(number);
+ }
+ return this;
+ }
+
+ /**
+ * Merge the fields from {@code other} into this set. If a field number
+ * exists in both sets, {@code other}'s values for that field will be
+ * appended to the values in this set.
+ */
+ public Builder mergeFrom(final UnknownFieldSet other) {
+ if (other != getDefaultInstance()) {
+ for (final Map.Entry<Integer, Field> entry : other.fields.entrySet()) {
+ mergeField(entry.getKey(), entry.getValue());
+ }
+ }
+ return this;
+ }
+
+ /**
+ * Add a field to the {@code UnknownFieldSet}. If a field with the same
+ * number already exists, the two are merged.
+ */
+ public Builder mergeField(final int number, final Field field) {
+ if (number == 0) {
+ throw new IllegalArgumentException("Zero is not a valid field number.");
+ }
+ if (hasField(number)) {
+ getFieldBuilder(number).mergeFrom(field);
+ } else {
+ // Optimization: We could call getFieldBuilder(number).mergeFrom(field)
+ // in this case, but that would create a copy of the Field object.
+ // We'd rather reuse the one passed to us, so call addField() instead.
+ addField(number, field);
+ }
+ return this;
+ }
+
+ /**
+ * Convenience method for merging a new field containing a single varint
+ * value. This is used in particular when an unknown enum value is
+ * encountered.
+ */
+ public Builder mergeVarintField(final int number, final int value) {
+ if (number == 0) {
+ throw new IllegalArgumentException("Zero is not a valid field number.");
+ }
+ getFieldBuilder(number).addVarint(value);
+ return this;
+ }
+
+
+ /**
+ * Convenience method for merging a length-delimited field.
+ *
+ * <p>For use by generated code only.
+ */
+ public Builder mergeLengthDelimitedField(
+ final int number, final ByteString value) {
+ if (number == 0) {
+ throw new IllegalArgumentException("Zero is not a valid field number.");
+ }
+ getFieldBuilder(number).addLengthDelimited(value);
+ return this;
+ }
+
+ /** Check if the given field number is present in the set. */
+ public boolean hasField(final int number) {
+ if (number == 0) {
+ throw new IllegalArgumentException("Zero is not a valid field number.");
+ }
+ return number == lastFieldNumber || fields.containsKey(number);
+ }
+
+ /**
+ * Add a field to the {@code UnknownFieldSet}. If a field with the same
+ * number already exists, it is removed.
+ */
+ public Builder addField(final int number, final Field field) {
+ if (number == 0) {
+ throw new IllegalArgumentException("Zero is not a valid field number.");
+ }
+ if (lastField != null && lastFieldNumber == number) {
+ // Discard this.
+ lastField = null;
+ lastFieldNumber = 0;
+ }
+ if (fields.isEmpty()) {
+ fields = new TreeMap<Integer,Field>();
+ }
+ fields.put(number, field);
+ return this;
+ }
+
+ /**
+ * Get all present {@code Field}s as an immutable {@code Map}. If more
+ * fields are added, the changes may or may not be reflected in this map.
+ */
+ public Map<Integer, Field> asMap() {
+ getFieldBuilder(0); // Force lastField to be built.
+ return Collections.unmodifiableMap(fields);
+ }
+
+ /**
+ * Parse an entire message from {@code input} and merge its fields into
+ * this set.
+ */
+ @Override
+ public Builder mergeFrom(final CodedInputStream input) throws IOException {
+ while (true) {
+ final int tag = input.readTag();
+ if (tag == 0 || !mergeFieldFrom(tag, input)) {
+ break;
+ }
+ }
+ return this;
+ }
+
+ /**
+ * Parse a single field from {@code input} and merge it into this set.
+ * @param tag The field's tag number, which was already parsed.
+ * @return {@code false} if the tag is an end group tag.
+ */
+ public boolean mergeFieldFrom(final int tag, final CodedInputStream input)
+ throws IOException {
+ final int number = WireFormat.getTagFieldNumber(tag);
+ switch (WireFormat.getTagWireType(tag)) {
+ case WireFormat.WIRETYPE_VARINT:
+ getFieldBuilder(number).addVarint(input.readInt64());
+ return true;
+ case WireFormat.WIRETYPE_FIXED64:
+ getFieldBuilder(number).addFixed64(input.readFixed64());
+ return true;
+ case WireFormat.WIRETYPE_LENGTH_DELIMITED:
+ getFieldBuilder(number).addLengthDelimited(input.readBytes());
+ return true;
+ case WireFormat.WIRETYPE_START_GROUP:
+ final Builder subBuilder = newBuilder();
+ input.readGroup(number, subBuilder,
+ ExtensionRegistry.getEmptyRegistry());
+ getFieldBuilder(number).addGroup(subBuilder.build());
+ return true;
+ case WireFormat.WIRETYPE_END_GROUP:
+ return false;
+ case WireFormat.WIRETYPE_FIXED32:
+ getFieldBuilder(number).addFixed32(input.readFixed32());
+ return true;
+ default:
+ throw InvalidProtocolBufferException.invalidWireType();
+ }
+ }
+
+ /**
+ * Parse {@code data} as an {@code UnknownFieldSet} and merge it with the
+ * set being built. This is just a small wrapper around
+ * {@link #mergeFrom(CodedInputStream)}.
+ */
+ @Override
+ public Builder mergeFrom(final ByteString data) throws InvalidProtocolBufferException {
+ try {
+ final CodedInputStream input = data.newCodedInput();
+ mergeFrom(input);
+ input.checkLastTagWas(0);
+ return this;
+ } catch (final InvalidProtocolBufferException e) {
+ throw e;
+ } catch (final IOException e) {
+ throw new RuntimeException(
+ "Reading from a ByteString threw an IOException (should " +
+ "never happen).", e);
+ }
+ }
+
+ /**
+ * Parse {@code data} as an {@code UnknownFieldSet} and merge it with the
+ * set being built. This is just a small wrapper around
+ * {@link #mergeFrom(CodedInputStream)}.
+ */
+ @Override
+ public Builder mergeFrom(final byte[] data) throws InvalidProtocolBufferException {
+ try {
+ final CodedInputStream input = CodedInputStream.newInstance(data);
+ mergeFrom(input);
+ input.checkLastTagWas(0);
+ return this;
+ } catch (final InvalidProtocolBufferException e) {
+ throw e;
+ } catch (final IOException e) {
+ throw new RuntimeException(
+ "Reading from a byte array threw an IOException (should " +
+ "never happen).", e);
+ }
+ }
+
+ /**
+ * Parse an {@code UnknownFieldSet} from {@code input} and merge it with the
+ * set being built. This is just a small wrapper around
+ * {@link #mergeFrom(CodedInputStream)}.
+ */
+ @Override
+ public Builder mergeFrom(final InputStream input) throws IOException {
+ final CodedInputStream codedInput = CodedInputStream.newInstance(input);
+ mergeFrom(codedInput);
+ codedInput.checkLastTagWas(0);
+ return this;
+ }
+
+ @Override
+ public boolean mergeDelimitedFrom(InputStream input) 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);
+ return true;
+ }
+
+ @Override
+ public boolean mergeDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry)
+ throws IOException {
+ // UnknownFieldSet has no extensions.
+ return mergeDelimitedFrom(input);
+ }
+
+ @Override
+ public Builder mergeFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry)
+ throws IOException {
+ // UnknownFieldSet has no extensions.
+ return mergeFrom(input);
+ }
+
+ @Override
+ public Builder mergeFrom(ByteString data, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ // UnknownFieldSet has no extensions.
+ return mergeFrom(data);
+ }
+
+ @Override
+ public Builder mergeFrom(byte[] data, int off, int len) throws InvalidProtocolBufferException {
+ try {
+ final CodedInputStream input =
+ CodedInputStream.newInstance(data, off, len);
+ mergeFrom(input);
+ input.checkLastTagWas(0);
+ return this;
+ } catch (InvalidProtocolBufferException e) {
+ throw e;
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "Reading from a byte array threw an IOException (should " +
+ "never happen).", e);
+ }
+ }
+
+ @Override
+ public Builder mergeFrom(byte[] data, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ // UnknownFieldSet has no extensions.
+ return mergeFrom(data);
+ }
+
+ @Override
+ public Builder mergeFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ // UnknownFieldSet has no extensions.
+ return mergeFrom(data, off, len);
+ }
+
+ @Override
+ public Builder mergeFrom(InputStream input, ExtensionRegistryLite extensionRegistry)
+ throws IOException {
+ // UnknownFieldSet has no extensions.
+ return mergeFrom(input);
+ }
+
+ @Override
+ public Builder mergeFrom(MessageLite m) {
+ if (m instanceof UnknownFieldSet) {
+ return mergeFrom((UnknownFieldSet) m);
+ }
+ throw new IllegalArgumentException(
+ "mergeFrom(MessageLite) can only merge messages of the same type.");
+ }
+
+ @Override
+ public boolean isInitialized() {
+ // UnknownFieldSets do not have required fields, so they are always
+ // initialized.
+ return true;
+ }
+ }
+
+ /**
+ * Represents a single field in an {@code UnknownFieldSet}.
+ *
+ * <p>A {@code Field} consists of five lists of values. The lists correspond
+ * to the five "wire types" used in the protocol buffer binary format.
+ * The wire type of each field can be determined from the encoded form alone,
+ * without knowing the field's declared type. So, we are able to parse
+ * unknown values at least this far and separate them. Normally, only one
+ * of the five lists will contain any values, since it is impossible to
+ * define a valid message type that declares two different types for the
+ * same field number. However, the code is designed to allow for the case
+ * where the same unknown field number is encountered using multiple different
+ * wire types.
+ *
+ * <p>{@code Field} is an immutable class. To construct one, you must use a
+ * {@link Builder}.
+ *
+ * @see UnknownFieldSet
+ */
+ public static final class Field {
+ private Field() {}
+
+ /** Construct a new {@link Builder}. */
+ public static Builder newBuilder() {
+ return Builder.create();
+ }
+
+ /**
+ * Construct a new {@link Builder} and initialize it to a copy of
+ * {@code copyFrom}.
+ */
+ public static Builder newBuilder(final Field copyFrom) {
+ return newBuilder().mergeFrom(copyFrom);
+ }
+
+ /** Get an empty {@code Field}. */
+ public static Field getDefaultInstance() {
+ return fieldDefaultInstance;
+ }
+ private static final Field fieldDefaultInstance = newBuilder().build();
+
+ /** Get the list of varint values for this field. */
+ public List<Long> getVarintList() { return varint; }
+
+ /** Get the list of fixed32 values for this field. */
+ public List<Integer> getFixed32List() { return fixed32; }
+
+ /** Get the list of fixed64 values for this field. */
+ public List<Long> getFixed64List() { return fixed64; }
+
+ /** Get the list of length-delimited values for this field. */
+ public List<ByteString> getLengthDelimitedList() { return lengthDelimited; }
+
+ /**
+ * Get the list of embedded group values for this field. These are
+ * represented using {@link UnknownFieldSet}s rather than {@link Message}s
+ * since the group's type is presumably unknown.
+ */
+ public List<UnknownFieldSet> getGroupList() { return group; }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof Field)) {
+ return false;
+ }
+ return Arrays.equals(getIdentityArray(),
+ ((Field) other).getIdentityArray());
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(getIdentityArray());
+ }
+
+ /**
+ * Returns the array of objects to be used to uniquely identify this
+ * {@link Field} instance.
+ */
+ private Object[] getIdentityArray() {
+ return new Object[] {
+ varint,
+ fixed32,
+ fixed64,
+ lengthDelimited,
+ group};
+ }
+
+ /**
+ * Serializes the field, including field number, and writes it to
+ * {@code output}.
+ */
+ public void writeTo(final int fieldNumber, final CodedOutputStream output)
+ throws IOException {
+ for (final long value : varint) {
+ output.writeUInt64(fieldNumber, value);
+ }
+ for (final int value : fixed32) {
+ output.writeFixed32(fieldNumber, value);
+ }
+ for (final long value : fixed64) {
+ output.writeFixed64(fieldNumber, value);
+ }
+ for (final ByteString value : lengthDelimited) {
+ output.writeBytes(fieldNumber, value);
+ }
+ for (final UnknownFieldSet value : group) {
+ output.writeGroup(fieldNumber, value);
+ }
+ }
+
+ /**
+ * Get the number of bytes required to encode this field, including field
+ * number.
+ */
+ public int getSerializedSize(final int fieldNumber) {
+ int result = 0;
+ for (final long value : varint) {
+ result += CodedOutputStream.computeUInt64Size(fieldNumber, value);
+ }
+ for (final int value : fixed32) {
+ result += CodedOutputStream.computeFixed32Size(fieldNumber, value);
+ }
+ for (final long value : fixed64) {
+ result += CodedOutputStream.computeFixed64Size(fieldNumber, value);
+ }
+ for (final ByteString value : lengthDelimited) {
+ result += CodedOutputStream.computeBytesSize(fieldNumber, value);
+ }
+ for (final UnknownFieldSet value : group) {
+ result += CodedOutputStream.computeGroupSize(fieldNumber, value);
+ }
+ return result;
+ }
+
+ /**
+ * Serializes the field, including field number, and writes it to
+ * {@code output}, using {@code MessageSet} wire format.
+ */
+ public void writeAsMessageSetExtensionTo(
+ final int fieldNumber,
+ final CodedOutputStream output)
+ throws IOException {
+ for (final ByteString value : lengthDelimited) {
+ output.writeRawMessageSetExtension(fieldNumber, value);
+ }
+ }
+
+
+ /**
+ * Get the number of bytes required to encode this field, including field number, using {@code
+ * MessageSet} wire format.
+ */
+ public int getSerializedSizeAsMessageSetExtension(final int fieldNumber) {
+ int result = 0;
+ for (final ByteString value : lengthDelimited) {
+ result += CodedOutputStream.computeRawMessageSetExtensionSize(
+ fieldNumber, value);
+ }
+ return result;
+ }
+
+ private List<Long> varint;
+ private List<Integer> fixed32;
+ private List<Long> fixed64;
+ private List<ByteString> lengthDelimited;
+ private List<UnknownFieldSet> group;
+
+ /**
+ * Used to build a {@link Field} within an {@link UnknownFieldSet}.
+ *
+ * <p>Use {@link Field#newBuilder()} to construct a {@code Builder}.
+ */
+ public static final class Builder {
+ // This constructor should never be called directly (except from 'create').
+ private Builder() {}
+
+ private static Builder create() {
+ Builder builder = new Builder();
+ builder.result = new Field();
+ return builder;
+ }
+
+ private Field result;
+
+ /**
+ * Build the field. After {@code build()} has been called, the
+ * {@code Builder} is no longer usable. Calling any other method will
+ * result in undefined behavior and can cause a
+ * {@code NullPointerException} to be thrown.
+ */
+ public Field build() {
+ if (result.varint == null) {
+ result.varint = Collections.emptyList();
+ } else {
+ result.varint = Collections.unmodifiableList(result.varint);
+ }
+ if (result.fixed32 == null) {
+ result.fixed32 = Collections.emptyList();
+ } else {
+ result.fixed32 = Collections.unmodifiableList(result.fixed32);
+ }
+ if (result.fixed64 == null) {
+ result.fixed64 = Collections.emptyList();
+ } else {
+ result.fixed64 = Collections.unmodifiableList(result.fixed64);
+ }
+ if (result.lengthDelimited == null) {
+ result.lengthDelimited = Collections.emptyList();
+ } else {
+ result.lengthDelimited =
+ Collections.unmodifiableList(result.lengthDelimited);
+ }
+ if (result.group == null) {
+ result.group = Collections.emptyList();
+ } else {
+ result.group = Collections.unmodifiableList(result.group);
+ }
+
+ final Field returnMe = result;
+ result = null;
+ return returnMe;
+ }
+
+ /** Discard the field's contents. */
+ public Builder clear() {
+ result = new Field();
+ return this;
+ }
+
+ /**
+ * Merge the values in {@code other} into this field. For each list
+ * of values, {@code other}'s values are append to the ones in this
+ * field.
+ */
+ public Builder mergeFrom(final Field other) {
+ if (!other.varint.isEmpty()) {
+ if (result.varint == null) {
+ result.varint = new ArrayList<Long>();
+ }
+ result.varint.addAll(other.varint);
+ }
+ if (!other.fixed32.isEmpty()) {
+ if (result.fixed32 == null) {
+ result.fixed32 = new ArrayList<Integer>();
+ }
+ result.fixed32.addAll(other.fixed32);
+ }
+ if (!other.fixed64.isEmpty()) {
+ if (result.fixed64 == null) {
+ result.fixed64 = new ArrayList<Long>();
+ }
+ result.fixed64.addAll(other.fixed64);
+ }
+ if (!other.lengthDelimited.isEmpty()) {
+ if (result.lengthDelimited == null) {
+ result.lengthDelimited = new ArrayList<ByteString>();
+ }
+ result.lengthDelimited.addAll(other.lengthDelimited);
+ }
+ if (!other.group.isEmpty()) {
+ if (result.group == null) {
+ result.group = new ArrayList<UnknownFieldSet>();
+ }
+ result.group.addAll(other.group);
+ }
+ return this;
+ }
+
+ /** Add a varint value. */
+ public Builder addVarint(final long value) {
+ if (result.varint == null) {
+ result.varint = new ArrayList<Long>();
+ }
+ result.varint.add(value);
+ return this;
+ }
+
+ /** Add a fixed32 value. */
+ public Builder addFixed32(final int value) {
+ if (result.fixed32 == null) {
+ result.fixed32 = new ArrayList<Integer>();
+ }
+ result.fixed32.add(value);
+ return this;
+ }
+
+ /** Add a fixed64 value. */
+ public Builder addFixed64(final long value) {
+ if (result.fixed64 == null) {
+ result.fixed64 = new ArrayList<Long>();
+ }
+ result.fixed64.add(value);
+ return this;
+ }
+
+ /** Add a length-delimited value. */
+ public Builder addLengthDelimited(final ByteString value) {
+ if (result.lengthDelimited == null) {
+ result.lengthDelimited = new ArrayList<ByteString>();
+ }
+ result.lengthDelimited.add(value);
+ return this;
+ }
+
+ /** Add an embedded group. */
+ public Builder addGroup(final UnknownFieldSet value) {
+ if (result.group == null) {
+ result.group = new ArrayList<UnknownFieldSet>();
+ }
+ result.group.add(value);
+ return this;
+ }
+ }
+ }
+
+ /**
+ * Parser to implement MessageLite interface.
+ */
+ public static final class Parser extends AbstractParser<UnknownFieldSet> {
+ @Override
+ public UnknownFieldSet parsePartialFrom(
+ CodedInputStream input, ExtensionRegistryLite extensionRegistry)
+ throws InvalidProtocolBufferException {
+ Builder builder = newBuilder();
+ try {
+ builder.mergeFrom(input);
+ } catch (InvalidProtocolBufferException e) {
+ throw e.setUnfinishedMessage(builder.buildPartial());
+ } catch (IOException e) {
+ throw new InvalidProtocolBufferException(e)
+ .setUnfinishedMessage(builder.buildPartial());
+ }
+ return builder.buildPartial();
+ }
+ }
+
+ private static final Parser PARSER = new Parser();
+ @Override
+ public final Parser getParserForType() {
+ return PARSER;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java
new file mode 100644
index 0000000000..d6226fc70c
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnknownFieldSetLite.java
@@ -0,0 +1,432 @@
+// 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.IOException;
+import java.util.Arrays;
+
+/**
+ * {@code UnknownFieldSetLite} is used to keep track of fields which were seen
+ * when parsing a protocol message but whose field numbers or types are
+ * unrecognized. This most frequently occurs when new fields are added to a
+ * message type and then messages containing those fields are read by old
+ * software that was compiled before the new types were added.
+ *
+ * <p>For use by generated code only.
+ *
+ * @author dweis@google.com (Daniel Weis)
+ */
+public final class UnknownFieldSetLite {
+
+ // Arbitrarily chosen.
+ // TODO(dweis): Tune this number?
+ private static final int MIN_CAPACITY = 8;
+
+ private static final UnknownFieldSetLite DEFAULT_INSTANCE =
+ new UnknownFieldSetLite(0, new int[0], new Object[0], false /* isMutable */);
+
+ /**
+ * Get an empty {@code UnknownFieldSetLite}.
+ *
+ * <p>For use by generated code only.
+ */
+ public static UnknownFieldSetLite getDefaultInstance() {
+ return DEFAULT_INSTANCE;
+ }
+
+ /**
+ * Returns a new mutable instance.
+ */
+ static UnknownFieldSetLite newInstance() {
+ return new UnknownFieldSetLite();
+ }
+
+ /**
+ * Returns a mutable {@code UnknownFieldSetLite} that is the composite of {@code first} and
+ * {@code second}.
+ */
+ static UnknownFieldSetLite mutableCopyOf(UnknownFieldSetLite first, UnknownFieldSetLite second) {
+ int count = first.count + second.count;
+ int[] tags = Arrays.copyOf(first.tags, count);
+ System.arraycopy(second.tags, 0, tags, first.count, second.count);
+ Object[] objects = Arrays.copyOf(first.objects, count);
+ System.arraycopy(second.objects, 0, objects, first.count, second.count);
+ return new UnknownFieldSetLite(count, tags, objects, true /* isMutable */);
+ }
+
+ /**
+ * The number of elements in the set.
+ */
+ private int count;
+
+ /**
+ * The tag numbers for the elements in the set.
+ */
+ private int[] tags;
+
+ /**
+ * The boxed values of the elements in the set.
+ */
+ private Object[] objects;
+
+ /**
+ * The lazily computed serialized size of the set.
+ */
+ private int memoizedSerializedSize = -1;
+
+ /**
+ * Indicates that this object is mutable.
+ */
+ private boolean isMutable;
+
+ /**
+ * Constructs a mutable {@code UnknownFieldSetLite}.
+ */
+ private UnknownFieldSetLite() {
+ this(0, new int[MIN_CAPACITY], new Object[MIN_CAPACITY], true /* isMutable */);
+ }
+
+ /**
+ * Constructs the {@code UnknownFieldSetLite}.
+ */
+ private UnknownFieldSetLite(int count, int[] tags, Object[] objects, boolean isMutable) {
+ this.count = count;
+ this.tags = tags;
+ this.objects = objects;
+ this.isMutable = isMutable;
+ }
+
+ /**
+ * Marks this object as immutable.
+ *
+ * <p>Future calls to methods that attempt to modify this object will throw.
+ */
+ public void makeImmutable() {
+ this.isMutable = false;
+ }
+
+ /**
+ * Throws an {@link UnsupportedOperationException} if immutable.
+ */
+ void checkMutable() {
+ if (!isMutable) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ /**
+ * Serializes the set and writes it to {@code output}.
+ *
+ * <p>For use by generated code only.
+ */
+ public void writeTo(CodedOutputStream output) throws IOException {
+ for (int i = 0; i < count; i++) {
+ int tag = tags[i];
+ int fieldNumber = WireFormat.getTagFieldNumber(tag);
+ switch (WireFormat.getTagWireType(tag)) {
+ case WireFormat.WIRETYPE_VARINT:
+ output.writeUInt64(fieldNumber, (Long) objects[i]);
+ break;
+ case WireFormat.WIRETYPE_FIXED32:
+ output.writeFixed32(fieldNumber, (Integer) objects[i]);
+ break;
+ case WireFormat.WIRETYPE_FIXED64:
+ output.writeFixed64(fieldNumber, (Long) objects[i]);
+ break;
+ case WireFormat.WIRETYPE_LENGTH_DELIMITED:
+ output.writeBytes(fieldNumber, (ByteString) objects[i]);
+ break;
+ case WireFormat.WIRETYPE_START_GROUP:
+ output.writeTag(fieldNumber, WireFormat.WIRETYPE_START_GROUP);
+ ((UnknownFieldSetLite) objects[i]).writeTo(output);
+ output.writeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP);
+ break;
+ default:
+ throw InvalidProtocolBufferException.invalidWireType();
+ }
+ }
+ }
+
+ /**
+ * Serializes the set and writes it to {@code output} using {@code MessageSet} wire format.
+ *
+ * <p>For use by generated code only.
+ */
+ public void writeAsMessageSetTo(CodedOutputStream output) throws IOException {
+ for (int i = 0; i < count; i++) {
+ int fieldNumber = WireFormat.getTagFieldNumber(tags[i]);
+ output.writeRawMessageSetExtension(fieldNumber, (ByteString) objects[i]);
+ }
+ }
+
+
+ /**
+ * Get the number of bytes required to encode this field, including field number, using {@code
+ * MessageSet} wire format.
+ */
+ public int getSerializedSizeAsMessageSet() {
+ int size = memoizedSerializedSize;
+ if (size != -1) {
+ return size;
+ }
+
+ size = 0;
+ for (int i = 0; i < count; i++) {
+ int tag = tags[i];
+ int fieldNumber = WireFormat.getTagFieldNumber(tag);
+ size += CodedOutputStream.computeRawMessageSetExtensionSize(
+ fieldNumber, (ByteString) objects[i]);
+ }
+
+ memoizedSerializedSize = size;
+
+ return size;
+ }
+
+ /**
+ * Get the number of bytes required to encode this set.
+ *
+ * <p>For use by generated code only.
+ */
+ public int getSerializedSize() {
+ int size = memoizedSerializedSize;
+ if (size != -1) {
+ return size;
+ }
+
+ size = 0;
+ for (int i = 0; i < count; i++) {
+ int tag = tags[i];
+ int fieldNumber = WireFormat.getTagFieldNumber(tag);
+ switch (WireFormat.getTagWireType(tag)) {
+ case WireFormat.WIRETYPE_VARINT:
+ size += CodedOutputStream.computeUInt64Size(fieldNumber, (Long) objects[i]);
+ break;
+ case WireFormat.WIRETYPE_FIXED32:
+ size += CodedOutputStream.computeFixed32Size(fieldNumber, (Integer) objects[i]);
+ break;
+ case WireFormat.WIRETYPE_FIXED64:
+ size += CodedOutputStream.computeFixed64Size(fieldNumber, (Long) objects[i]);
+ break;
+ case WireFormat.WIRETYPE_LENGTH_DELIMITED:
+ size += CodedOutputStream.computeBytesSize(fieldNumber, (ByteString) objects[i]);
+ break;
+ case WireFormat.WIRETYPE_START_GROUP:
+ size += CodedOutputStream.computeTagSize(fieldNumber) * 2
+ + ((UnknownFieldSetLite) objects[i]).getSerializedSize();
+ break;
+ default:
+ throw new IllegalStateException(InvalidProtocolBufferException.invalidWireType());
+ }
+ }
+
+ memoizedSerializedSize = size;
+
+ return size;
+ }
+
+ private static boolean equals(int[] tags1, int[] tags2, int count) {
+ for (int i = 0; i < count; ++i) {
+ if (tags1[i] != tags2[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static boolean equals(Object[] objects1, Object[] objects2, int count) {
+ for (int i = 0; i < count; ++i) {
+ if (!objects1[i].equals(objects2[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null) {
+ return false;
+ }
+
+ if (!(obj instanceof UnknownFieldSetLite)) {
+ return false;
+ }
+
+ UnknownFieldSetLite other = (UnknownFieldSetLite) obj;
+ if (count != other.count
+ || !equals(tags, other.tags, count)
+ || !equals(objects, other.objects, count)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int hashCode = 17;
+
+ hashCode = 31 * hashCode + count;
+ hashCode = 31 * hashCode + Arrays.hashCode(tags);
+ hashCode = 31 * hashCode + Arrays.deepHashCode(objects);
+
+ return hashCode;
+ }
+
+ /**
+ * Prints a String representation of the unknown field set.
+ *
+ * <p>For use by generated code only.
+ *
+ * @param buffer the buffer to write to
+ * @param indent the number of spaces the fields should be indented by
+ */
+ final void printWithIndent(StringBuilder buffer, int indent) {
+ for (int i = 0; i < count; i++) {
+ int fieldNumber = WireFormat.getTagFieldNumber(tags[i]);
+ MessageLiteToString.printField(buffer, indent, String.valueOf(fieldNumber), objects[i]);
+ }
+ }
+
+ // Package private for unsafe experimental runtime.
+ void storeField(int tag, Object value) {
+ ensureCapacity();
+
+ tags[count] = tag;
+ objects[count] = value;
+ count++;
+ }
+
+ /**
+ * Ensures that our arrays are long enough to store more metadata.
+ */
+ private void ensureCapacity() {
+ if (count == tags.length) {
+ int increment = count < (MIN_CAPACITY / 2) ? MIN_CAPACITY : count >> 1;
+ int newLength = count + increment;
+
+ tags = Arrays.copyOf(tags, newLength);
+ objects = Arrays.copyOf(objects, newLength);
+ }
+ }
+
+ /**
+ * Parse a single field from {@code input} and merge it into this set.
+ *
+ * <p>For use by generated code only.
+ *
+ * @param tag The field's tag number, which was already parsed.
+ * @return {@code false} if the tag is an end group tag.
+ */
+ boolean mergeFieldFrom(final int tag, final CodedInputStream input) throws IOException {
+ checkMutable();
+ final int fieldNumber = WireFormat.getTagFieldNumber(tag);
+ switch (WireFormat.getTagWireType(tag)) {
+ case WireFormat.WIRETYPE_VARINT:
+ storeField(tag, input.readInt64());
+ return true;
+ case WireFormat.WIRETYPE_FIXED32:
+ storeField(tag, input.readFixed32());
+ return true;
+ case WireFormat.WIRETYPE_FIXED64:
+ storeField(tag, input.readFixed64());
+ return true;
+ case WireFormat.WIRETYPE_LENGTH_DELIMITED:
+ storeField(tag, input.readBytes());
+ return true;
+ case WireFormat.WIRETYPE_START_GROUP:
+ final UnknownFieldSetLite subFieldSet = new UnknownFieldSetLite();
+ subFieldSet.mergeFrom(input);
+ input.checkLastTagWas(
+ WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP));
+ storeField(tag, subFieldSet);
+ return true;
+ case WireFormat.WIRETYPE_END_GROUP:
+ return false;
+ default:
+ throw InvalidProtocolBufferException.invalidWireType();
+ }
+ }
+
+ /**
+ * Convenience method for merging a new field containing a single varint
+ * value. This is used in particular when an unknown enum value is
+ * encountered.
+ *
+ * <p>For use by generated code only.
+ */
+ UnknownFieldSetLite mergeVarintField(int fieldNumber, int value) {
+ checkMutable();
+ if (fieldNumber == 0) {
+ throw new IllegalArgumentException("Zero is not a valid field number.");
+ }
+
+ storeField(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_VARINT), (long) value);
+
+ return this;
+ }
+
+ /**
+ * Convenience method for merging a length-delimited field.
+ *
+ * <p>For use by generated code only.
+ */
+ UnknownFieldSetLite mergeLengthDelimitedField(final int fieldNumber, final ByteString value) {
+ checkMutable();
+ if (fieldNumber == 0) {
+ throw new IllegalArgumentException("Zero is not a valid field number.");
+ }
+
+ storeField(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED), value);
+
+ return this;
+ }
+
+ /**
+ * Parse an entire message from {@code input} and merge its fields into
+ * this set.
+ */
+ private UnknownFieldSetLite mergeFrom(final CodedInputStream input) throws IOException {
+ // Ensures initialization in mergeFieldFrom.
+ while (true) {
+ final int tag = input.readTag();
+ if (tag == 0 || !mergeFieldFrom(tag, input)) {
+ break;
+ }
+ }
+ return this;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java
new file mode 100644
index 0000000000..30e8791178
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java
@@ -0,0 +1,210 @@
+// 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.util.AbstractList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.RandomAccess;
+
+/**
+ * An implementation of {@link LazyStringList} that wraps another
+ * {@link LazyStringList} such that it cannot be modified via the wrapper.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class UnmodifiableLazyStringList extends AbstractList<String>
+ implements LazyStringList, RandomAccess {
+
+ private final LazyStringList list;
+
+ public UnmodifiableLazyStringList(LazyStringList list) {
+ this.list = list;
+ }
+
+ @Override
+ public String get(int index) {
+ return list.get(index);
+ }
+
+ @Override
+ public Object getRaw(int index) {
+ return list.getRaw(index);
+ }
+
+ @Override
+ public int size() {
+ return list.size();
+ }
+
+ @Override
+ public ByteString getByteString(int index) {
+ return list.getByteString(index);
+ }
+
+ @Override
+ public void add(ByteString element) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void set(int index, ByteString element) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean addAllByteString(Collection<? extends ByteString> element) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public byte[] getByteArray(int index) {
+ return list.getByteArray(index);
+ }
+
+ @Override
+ public void add(byte[] element) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void set(int index, byte[] element) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean addAllByteArray(Collection<byte[]> element) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ListIterator<String> listIterator(final int index) {
+ return new ListIterator<String>() {
+ ListIterator<String> iter = list.listIterator(index);
+
+ @Override
+ public boolean hasNext() {
+ return iter.hasNext();
+ }
+
+ @Override
+ public String next() {
+ return iter.next();
+ }
+
+ @Override
+ public boolean hasPrevious() {
+ return iter.hasPrevious();
+ }
+
+ @Override
+ public String previous() {
+ return iter.previous();
+ }
+
+ @Override
+ public int nextIndex() {
+ return iter.nextIndex();
+ }
+
+ @Override
+ public int previousIndex() {
+ return iter.previousIndex();
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void set(String o) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void add(String o) {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ @Override
+ public Iterator<String> iterator() {
+ return new Iterator<String>() {
+ Iterator<String> iter = list.iterator();
+
+ @Override
+ public boolean hasNext() {
+ return iter.hasNext();
+ }
+
+ @Override
+ public String next() {
+ return iter.next();
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ @Override
+ public List<?> getUnderlyingElements() {
+ // The returned value is already unmodifiable.
+ return list.getUnderlyingElements();
+ }
+
+ @Override
+ public void mergeFrom(LazyStringList other) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<byte[]> asByteArrayList() {
+ return Collections.unmodifiableList(list.asByteArrayList());
+ }
+
+ @Override
+ public List<ByteString> asByteStringList() {
+ return Collections.unmodifiableList(list.asByteStringList());
+ }
+
+ @Override
+ public LazyStringList getUnmodifiableView() {
+ return this;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java
new file mode 100644
index 0000000000..878c775816
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnsafeByteOperations.java
@@ -0,0 +1,120 @@
+// 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.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * Provides a number of unsafe byte operations to be used by advanced applications with high
+ * performance requirements. These methods are referred to as "unsafe" due to the fact that they
+ * potentially expose the backing buffer of a {@link ByteString} to the application.
+ *
+ * <p><strong>DISCLAIMER:</strong> The methods in this class should only be called if it is
+ * guaranteed that the buffer backing the {@link ByteString} will never change! Mutation of a
+ * {@link ByteString} can lead to unexpected and undesirable consequences in your application,
+ * and will likely be difficult to debug. Proceed with caution!
+ *
+ * <p>This can have a number of significant side affects that have
+ * spooky-action-at-a-distance-like behavior. In particular, if the bytes value changes out from
+ * under a Protocol Buffer:
+ * <ul>
+ * <li>serialization may throw
+ * <li>serialization may succeed but the wrong bytes may be written out
+ * <li>messages are no longer threadsafe
+ * <li>hashCode may be incorrect
+ * <ul>
+ * <li>can result in a permanent memory leak when used as a key in a long-lived HashMap
+ * <li> the semantics of many programs may be violated if this is the case
+ * </ul>
+ * </ul>
+ * Each of these issues will occur in parts of the code base that are entirely distinct from the
+ * parts of the code base modifying the buffer. In fact, both parts of the code base may be correct
+ * - it is the bridging with the unsafe operations that was in error!
+ */
+@ExperimentalApi
+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.
+ *
+ * @param buffer the Java NIO buffer to be wrapped
+ * @return a {@link ByteString} backed by the provided buffer
+ */
+ public static ByteString unsafeWrap(ByteBuffer buffer) {
+ return ByteString.wrap(buffer);
+ }
+
+ /**
+ * Writes the given {@link ByteString} to the provided {@link ByteOutput}. Calling this method may
+ * result in multiple operations on the target {@link ByteOutput}
+ * (i.e. for roped {@link ByteString}s).
+ *
+ * <p>This method exposes the internal backing buffer(s) of the {@link ByteString} to the {@link
+ * ByteOutput} in order to avoid additional copying overhead. It would be possible for a malicious
+ * {@link ByteOutput} to corrupt the {@link ByteString}. Use with caution!
+ *
+ * <p> NOTE: The {@link ByteOutput} <strong>MUST NOT</strong> modify the provided buffers. Doing
+ * so may result in corrupted data, which would be difficult to debug.
+ *
+ * @param bytes the {@link ByteString} to be written
+ * @param output the output to receive the bytes
+ * @throws IOException if an I/O error occurs
+ */
+ public static void unsafeWriteTo(ByteString bytes, ByteOutput output) throws IOException {
+ bytes.writeTo(output);
+ }
+
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java
new file mode 100644
index 0000000000..5f7bafd602
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java
@@ -0,0 +1,295 @@
+// 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.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. */
+// TODO(nathanmittler): Add support for Android Memory/MemoryBlock
+final class UnsafeUtil {
+ private static final sun.misc.Unsafe UNSAFE = getUnsafe();
+ private static final boolean HAS_UNSAFE_BYTEBUFFER_OPERATIONS =
+ supportsUnsafeByteBufferOperations();
+ private static final boolean HAS_UNSAFE_ARRAY_OPERATIONS = supportsUnsafeArrayOperations();
+ private static final long ARRAY_BASE_OFFSET = byteArrayBaseOffset();
+ private static final long BUFFER_ADDRESS_OFFSET = fieldOffset(field(Buffer.class, "address"));
+
+ private UnsafeUtil() {}
+
+ static boolean hasUnsafeArrayOperations() {
+ return HAS_UNSAFE_ARRAY_OPERATIONS;
+ }
+
+ static boolean hasUnsafeByteBufferOperations() {
+ 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(Object target, long offset) {
+ return UNSAFE.getByte(target, offset);
+ }
+
+ static void putByte(Object target, long offset, byte value) {
+ UNSAFE.putByte(target, offset, value);
+ }
+
+ static int getInt(Object target, long offset) {
+ return UNSAFE.getInt(target, 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);
+ }
+
+ static void putByte(long address, byte value) {
+ 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}.
+ */
+ static long addressOffset(ByteBuffer buffer) {
+ return UNSAFE.getLong(buffer, BUFFER_ADDRESS_OFFSET);
+ }
+
+ /**
+ * Gets the {@code sun.misc.Unsafe} instance, or {@code null} if not available on this platform.
+ */
+ private static sun.misc.Unsafe getUnsafe() {
+ sun.misc.Unsafe unsafe = null;
+ try {
+ unsafe =
+ AccessController.doPrivileged(
+ new PrivilegedExceptionAction<Unsafe>() {
+ @Override
+ public sun.misc.Unsafe run() throws Exception {
+ Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
+
+ for (Field f : k.getDeclaredFields()) {
+ f.setAccessible(true);
+ Object x = f.get(null);
+ if (k.isInstance(x)) {
+ return k.cast(x);
+ }
+ }
+ // The sun.misc.Unsafe field does not exist.
+ return null;
+ }
+ });
+ } catch (Throwable e) {
+ // Catching Throwable here due to the fact that Google AppEngine raises NoClassDefFoundError
+ // for Unsafe.
+ }
+ return unsafe;
+ }
+
+ /** 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;
+ } catch (Throwable e) {
+ // Do nothing.
+ }
+ }
+ return supported;
+ }
+
+ private static boolean supportsUnsafeByteBufferOperations() {
+ boolean supported = false;
+ if (UNSAFE != null) {
+ try {
+ Class<?> clazz = UNSAFE.getClass();
+ // Methods for getting direct buffer address.
+ clazz.getMethod("objectFieldOffset", Field.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) {
+ // Do nothing.
+ }
+ }
+ return supported;
+ }
+
+ /**
+ * Get the base offset for byte arrays, or {@code -1} if {@code sun.misc.Unsafe} is not available.
+ */
+ private static int byteArrayBaseOffset() {
+ return HAS_UNSAFE_ARRAY_OPERATIONS ? UNSAFE.arrayBaseOffset(byte[].class) : -1;
+ }
+
+ /**
+ * Returns the offset of the provided field, or {@code -1} if {@code sun.misc.Unsafe} is not
+ * available.
+ */
+ private static long fieldOffset(Field field) {
+ return field == null || UNSAFE == null ? -1 : UNSAFE.objectFieldOffset(field);
+ }
+
+ /**
+ * Gets the field with the given name within the class, or {@code null} if not found. If found,
+ * the field is made accessible.
+ */
+ private static Field field(Class<?> clazz, String fieldName) {
+ Field field;
+ try {
+ field = clazz.getDeclaredField(fieldName);
+ field.setAccessible(true);
+ } catch (Throwable t) {
+ // Failed to access the fields.
+ field = null;
+ }
+ return field;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Utf8.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Utf8.java
new file mode 100644
index 0000000000..5b80d405eb
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/Utf8.java
@@ -0,0 +1,1573 @@
+// 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 static com.google.protobuf.UnsafeUtil.addressOffset;
+import static com.google.protobuf.UnsafeUtil.getArrayBaseOffset;
+import static com.google.protobuf.UnsafeUtil.hasUnsafeArrayOperations;
+import static com.google.protobuf.UnsafeUtil.hasUnsafeByteBufferOperations;
+import static java.lang.Character.MAX_SURROGATE;
+import static java.lang.Character.MIN_SURROGATE;
+import static java.lang.Character.isSurrogatePair;
+import static java.lang.Character.toCodePoint;
+
+import java.nio.ByteBuffer;
+
+/**
+ * A set of low-level, high-performance static utility methods related
+ * to the UTF-8 character encoding. This class has no dependencies
+ * outside of the core JDK libraries.
+ *
+ * <p>There are several variants of UTF-8. The one implemented by
+ * this class is the restricted definition of UTF-8 introduced in
+ * Unicode 3.1, which mandates the rejection of "overlong" byte
+ * sequences as well as rejection of 3-byte surrogate codepoint byte
+ * sequences. Note that the UTF-8 decoder included in Oracle's JDK
+ * has been modified to also reject "overlong" byte sequences, but (as
+ * of 2011) still accepts 3-byte surrogate codepoint byte sequences.
+ *
+ * <p>The byte sequences considered valid by this class are exactly
+ * those that can be roundtrip converted to Strings and back to bytes
+ * using the UTF-8 charset, without loss: <pre> {@code
+ * Arrays.equals(bytes, new String(bytes, Internal.UTF_8).getBytes(Internal.UTF_8))
+ * }</pre>
+ *
+ * <p>See the Unicode Standard,</br>
+ * Table 3-6. <em>UTF-8 Bit Distribution</em>,</br>
+ * Table 3-7. <em>Well Formed UTF-8 Byte Sequences</em>.
+ *
+ * <p>This class supports decoding of partial byte sequences, so that the
+ * bytes in a complete UTF-8 byte sequences can be stored in multiple
+ * segments. Methods typically return {@link #MALFORMED} if the partial
+ * byte sequence is definitely not well-formed, {@link #COMPLETE} if it is
+ * well-formed in the absence of additional input, or if the byte sequence
+ * apparently terminated in the middle of a character, an opaque integer
+ * "state" value containing enough information to decode the character when
+ * passed to a subsequent invocation of a partial decoding method.
+ *
+ * @author martinrb@google.com (Martin Buchholz)
+ */
+// TODO(nathanmittler): Copy changes in this class back to Guava
+final class Utf8 {
+
+ /**
+ * UTF-8 is a runtime hot spot so we attempt to provide heavily optimized implementations
+ * depending on what is available on the platform. The processor is the platform-optimized
+ * delegate for which all methods are delegated directly to.
+ */
+ private static final Processor processor =
+ UnsafeProcessor.isAvailable() ? new UnsafeProcessor() : new SafeProcessor();
+
+ /**
+ * A mask used when performing unsafe reads to determine if a long value contains any non-ASCII
+ * characters (i.e. any byte >= 0x80).
+ */
+ private static final long ASCII_MASK_LONG = 0x8080808080808080L;
+
+ /**
+ * Maximum number of bytes per Java UTF-16 char in UTF-8.
+ * @see java.nio.charset.CharsetEncoder#maxBytesPerChar()
+ */
+ static final int MAX_BYTES_PER_CHAR = 3;
+
+ /**
+ * State value indicating that the byte sequence is well-formed and
+ * complete (no further bytes are needed to complete a character).
+ */
+ public static final int COMPLETE = 0;
+
+ /**
+ * State value indicating that the byte sequence is definitely not
+ * well-formed.
+ */
+ public static final int MALFORMED = -1;
+
+ /**
+ * Used by {@code Unsafe} UTF-8 string validation logic to determine the minimum string length
+ * above which to employ an optimized algorithm for counting ASCII characters. The reason for this
+ * threshold is that for small strings, the optimization may not be beneficial or may even
+ * negatively impact performance since it requires additional logic to avoid unaligned reads
+ * (when calling {@code Unsafe.getLong}). This threshold guarantees that even if the initial
+ * offset is unaligned, we're guaranteed to make at least one call to {@code Unsafe.getLong()}
+ * which provides a performance improvement that entirely subsumes the cost of the additional
+ * logic.
+ */
+ private static final int UNSAFE_COUNT_ASCII_THRESHOLD = 16;
+
+ // Other state values include the partial bytes of the incomplete
+ // character to be decoded in the simplest way: we pack the bytes
+ // into the state int in little-endian order. For example:
+ //
+ // int state = byte1 ^ (byte2 << 8) ^ (byte3 << 16);
+ //
+ // Such a state is unpacked thus (note the ~ operation for byte2 to
+ // undo byte1's sign-extension bits):
+ //
+ // int byte1 = (byte) state;
+ // int byte2 = (byte) ~(state >> 8);
+ // int byte3 = (byte) (state >> 16);
+ //
+ // We cannot store a zero byte in the state because it would be
+ // indistinguishable from the absence of a byte. But we don't need
+ // to, because partial bytes must always be negative. When building
+ // a state, we ensure that byte1 is negative and subsequent bytes
+ // are valid trailing bytes.
+
+ /**
+ * Returns {@code true} if the given byte array is a well-formed
+ * UTF-8 byte sequence.
+ *
+ * <p>This is a convenience method, equivalent to a call to {@code
+ * isValidUtf8(bytes, 0, bytes.length)}.
+ */
+ public static boolean isValidUtf8(byte[] bytes) {
+ return processor.isValidUtf8(bytes, 0, bytes.length);
+ }
+
+ /**
+ * Returns {@code true} if the given byte array slice is a
+ * well-formed UTF-8 byte sequence. The range of bytes to be
+ * checked extends from index {@code index}, inclusive, to {@code
+ * limit}, exclusive.
+ *
+ * <p>This is a convenience method, equivalent to {@code
+ * partialIsValidUtf8(bytes, index, limit) == Utf8.COMPLETE}.
+ */
+ public static boolean isValidUtf8(byte[] bytes, int index, int limit) {
+ return processor.isValidUtf8(bytes, index, limit);
+ }
+
+ /**
+ * Tells whether the given byte array slice is a well-formed,
+ * malformed, or incomplete UTF-8 byte sequence. The range of bytes
+ * to be checked extends from index {@code index}, inclusive, to
+ * {@code limit}, exclusive.
+ *
+ * @param state either {@link Utf8#COMPLETE} (if this is the initial decoding
+ * operation) or the value returned from a call to a partial decoding method
+ * for the previous bytes
+ *
+ * @return {@link #MALFORMED} if the partial byte sequence is
+ * definitely not well-formed, {@link #COMPLETE} if it is well-formed
+ * (no additional input needed), or if the byte sequence is
+ * "incomplete", i.e. apparently terminated in the middle of a character,
+ * an opaque integer "state" value containing enough information to
+ * decode the character when passed to a subsequent invocation of a
+ * partial decoding method.
+ */
+ public static int partialIsValidUtf8(int state, byte[] bytes, int index, int limit) {
+ return processor.partialIsValidUtf8(state, bytes, index, limit);
+ }
+
+ private static int incompleteStateFor(int byte1) {
+ return (byte1 > (byte) 0xF4) ?
+ MALFORMED : byte1;
+ }
+
+ private static int incompleteStateFor(int byte1, int byte2) {
+ return (byte1 > (byte) 0xF4 ||
+ byte2 > (byte) 0xBF) ?
+ MALFORMED : byte1 ^ (byte2 << 8);
+ }
+
+ private static int incompleteStateFor(int byte1, int byte2, int byte3) {
+ return (byte1 > (byte) 0xF4 ||
+ byte2 > (byte) 0xBF ||
+ byte3 > (byte) 0xBF) ?
+ MALFORMED : byte1 ^ (byte2 << 8) ^ (byte3 << 16);
+ }
+
+ private static int incompleteStateFor(byte[] bytes, int index, int limit) {
+ int byte1 = bytes[index - 1];
+ switch (limit - index) {
+ case 0: return incompleteStateFor(byte1);
+ case 1: return incompleteStateFor(byte1, bytes[index]);
+ case 2: return incompleteStateFor(byte1, bytes[index], bytes[index + 1]);
+ default: throw new AssertionError();
+ }
+ }
+
+ private static int incompleteStateFor(
+ final ByteBuffer buffer, final int byte1, final int index, final int remaining) {
+ switch (remaining) {
+ case 0:
+ return incompleteStateFor(byte1);
+ case 1:
+ return incompleteStateFor(byte1, buffer.get(index));
+ case 2:
+ return incompleteStateFor(byte1, buffer.get(index), buffer.get(index + 1));
+ default:
+ throw new AssertionError();
+ }
+ }
+
+ // These UTF-8 handling methods are copied from Guava's Utf8 class with a modification to throw
+ // a protocol buffer local exception. This exception is then caught in CodedOutputStream so it can
+ // fallback to more lenient behavior.
+
+ static class UnpairedSurrogateException extends IllegalArgumentException {
+ UnpairedSurrogateException(int index, int length) {
+ super("Unpaired surrogate at index " + index + " of " + length);
+ }
+ }
+
+ /**
+ * Returns the number of bytes in the UTF-8-encoded form of {@code sequence}. For a string,
+ * this method is equivalent to {@code string.getBytes(UTF_8).length}, but is more efficient in
+ * both time and space.
+ *
+ * @throws IllegalArgumentException if {@code sequence} contains ill-formed UTF-16 (unpaired
+ * surrogates)
+ */
+ static int encodedLength(CharSequence sequence) {
+ // Warning to maintainers: this implementation is highly optimized.
+ int utf16Length = sequence.length();
+ int utf8Length = utf16Length;
+ int i = 0;
+
+ // This loop optimizes for pure ASCII.
+ while (i < utf16Length && sequence.charAt(i) < 0x80) {
+ i++;
+ }
+
+ // This loop optimizes for chars less than 0x800.
+ for (; i < utf16Length; i++) {
+ char c = sequence.charAt(i);
+ if (c < 0x800) {
+ utf8Length += ((0x7f - c) >>> 31); // branch free!
+ } else {
+ utf8Length += encodedLengthGeneral(sequence, i);
+ break;
+ }
+ }
+
+ if (utf8Length < utf16Length) {
+ // Necessary and sufficient condition for overflow because of maximum 3x expansion
+ throw new IllegalArgumentException("UTF-8 length does not fit in int: "
+ + (utf8Length + (1L << 32)));
+ }
+ return utf8Length;
+ }
+
+ private static int encodedLengthGeneral(CharSequence sequence, int start) {
+ int utf16Length = sequence.length();
+ int utf8Length = 0;
+ for (int i = start; i < utf16Length; i++) {
+ char c = sequence.charAt(i);
+ if (c < 0x800) {
+ utf8Length += (0x7f - c) >>> 31; // branch free!
+ } else {
+ utf8Length += 2;
+ // jdk7+: if (Character.isSurrogate(c)) {
+ if (Character.MIN_SURROGATE <= c && c <= Character.MAX_SURROGATE) {
+ // Check that we have a well-formed surrogate pair.
+ int cp = Character.codePointAt(sequence, i);
+ if (cp < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
+ throw new UnpairedSurrogateException(i, utf16Length);
+ }
+ i++;
+ }
+ }
+ }
+ return utf8Length;
+ }
+
+ static int encode(CharSequence in, byte[] out, int offset, int length) {
+ return processor.encodeUtf8(in, out, offset, length);
+ }
+ // End Guava UTF-8 methods.
+
+ /**
+ * Determines if the given {@link ByteBuffer} is a valid UTF-8 string.
+ *
+ * <p>Selects an optimal algorithm based on the type of {@link ByteBuffer} (i.e. heap or direct)
+ * and the capabilities of the platform.
+ *
+ * @param buffer the buffer to check.
+ * @see Utf8#isValidUtf8(byte[], int, int)
+ */
+ static boolean isValidUtf8(ByteBuffer buffer) {
+ return processor.isValidUtf8(buffer, buffer.position(), buffer.remaining());
+ }
+
+ /**
+ * Determines if the given {@link ByteBuffer} is a partially valid UTF-8 string.
+ *
+ * <p>Selects an optimal algorithm based on the type of {@link ByteBuffer} (i.e. heap or direct)
+ * and the capabilities of the platform.
+ *
+ * @param buffer the buffer to check.
+ * @see Utf8#partialIsValidUtf8(int, byte[], int, int)
+ */
+ static int partialIsValidUtf8(int state, ByteBuffer buffer, int index, int limit) {
+ return processor.partialIsValidUtf8(state, buffer, index, limit);
+ }
+
+ /**
+ * Encodes the given characters to the target {@link ByteBuffer} using UTF-8 encoding.
+ *
+ * <p>Selects an optimal algorithm based on the type of {@link ByteBuffer} (i.e. heap or direct)
+ * and the capabilities of the platform.
+ *
+ * @param in the source string to be encoded
+ * @param out the target buffer to receive the encoded string.
+ * @see Utf8#encode(CharSequence, byte[], int, int)
+ */
+ static void encodeUtf8(CharSequence in, ByteBuffer out) {
+ processor.encodeUtf8(in, out);
+ }
+
+ /**
+ * Counts (approximately) the number of consecutive ASCII characters in the given buffer.
+ * The byte order of the {@link ByteBuffer} does not matter, so performance can be improved if
+ * native byte order is used (i.e. no byte-swapping in {@link ByteBuffer#getLong(int)}).
+ *
+ * @param buffer the buffer to be scanned for ASCII chars
+ * @param index the starting index of the scan
+ * @param limit the limit within buffer for the scan
+ * @return the number of ASCII characters found. The stopping position will be at or
+ * before the first non-ASCII byte.
+ */
+ private static int estimateConsecutiveAscii(ByteBuffer buffer, int index, int limit) {
+ int i = index;
+ final int lim = limit - 7;
+ // This simple loop stops when we encounter a byte >= 0x80 (i.e. non-ASCII).
+ // To speed things up further, we're reading longs instead of bytes so we use a mask to
+ // determine if any byte in the current long is non-ASCII.
+ for (; i < lim && (buffer.getLong(i) & ASCII_MASK_LONG) == 0; i += 8) {}
+ return i - index;
+ }
+
+ /**
+ * A processor of UTF-8 strings, providing methods for checking validity and encoding.
+ */
+ // TODO(nathanmittler): Add support for Memory/MemoryBlock on Android.
+ abstract static class Processor {
+ /**
+ * Returns {@code true} if the given byte array slice is a
+ * well-formed UTF-8 byte sequence. The range of bytes to be
+ * checked extends from index {@code index}, inclusive, to {@code
+ * limit}, exclusive.
+ *
+ * <p>This is a convenience method, equivalent to {@code
+ * partialIsValidUtf8(bytes, index, limit) == Utf8.COMPLETE}.
+ */
+ final boolean isValidUtf8(byte[] bytes, int index, int limit) {
+ return partialIsValidUtf8(COMPLETE, bytes, index, limit) == COMPLETE;
+ }
+
+ /**
+ * Tells whether the given byte array slice is a well-formed,
+ * malformed, or incomplete UTF-8 byte sequence. The range of bytes
+ * to be checked extends from index {@code index}, inclusive, to
+ * {@code limit}, exclusive.
+ *
+ * @param state either {@link Utf8#COMPLETE} (if this is the initial decoding
+ * operation) or the value returned from a call to a partial decoding method
+ * for the previous bytes
+ *
+ * @return {@link #MALFORMED} if the partial byte sequence is
+ * definitely not well-formed, {@link #COMPLETE} if it is well-formed
+ * (no additional input needed), or if the byte sequence is
+ * "incomplete", i.e. apparently terminated in the middle of a character,
+ * an opaque integer "state" value containing enough information to
+ * decode the character when passed to a subsequent invocation of a
+ * partial decoding method.
+ */
+ abstract int partialIsValidUtf8(int state, byte[] bytes, int index, int limit);
+
+ /**
+ * Returns {@code true} if the given portion of the {@link ByteBuffer} is a
+ * well-formed UTF-8 byte sequence. The range of bytes to be
+ * checked extends from index {@code index}, inclusive, to {@code
+ * limit}, exclusive.
+ *
+ * <p>This is a convenience method, equivalent to {@code
+ * partialIsValidUtf8(bytes, index, limit) == Utf8.COMPLETE}.
+ */
+ final boolean isValidUtf8(ByteBuffer buffer, int index, int limit) {
+ return partialIsValidUtf8(COMPLETE, buffer, index, limit) == COMPLETE;
+ }
+
+ /**
+ * Indicates whether or not the given buffer contains a valid UTF-8 string.
+ *
+ * @param buffer the buffer to check.
+ * @return {@code true} if the given buffer contains a valid UTF-8 string.
+ */
+ final int partialIsValidUtf8(
+ final int state, final ByteBuffer buffer, int index, final int limit) {
+ if (buffer.hasArray()) {
+ final int offset = buffer.arrayOffset();
+ return partialIsValidUtf8(state, buffer.array(), offset + index, offset + limit);
+ } else if (buffer.isDirect()){
+ return partialIsValidUtf8Direct(state, buffer, index, limit);
+ }
+ return partialIsValidUtf8Default(state, buffer, index, limit);
+ }
+
+ /**
+ * Performs validation for direct {@link ByteBuffer} instances.
+ */
+ abstract int partialIsValidUtf8Direct(
+ final int state, final ByteBuffer buffer, int index, final int limit);
+
+ /**
+ * Performs validation for {@link ByteBuffer} instances using the {@link ByteBuffer} API rather
+ * than potentially faster approaches. This first completes validation for the current
+ * character (provided by {@code state}) and then finishes validation for the sequence.
+ */
+ final int partialIsValidUtf8Default(
+ final int state, final ByteBuffer buffer, int index, final int limit) {
+ if (state != COMPLETE) {
+ // The previous decoding operation was incomplete (or malformed).
+ // We look for a well-formed sequence consisting of bytes from
+ // the previous decoding operation (stored in state) together
+ // with bytes from the array slice.
+ //
+ // We expect such "straddler characters" to be rare.
+
+ if (index >= limit) { // No bytes? No progress.
+ return state;
+ }
+
+ byte byte1 = (byte) state;
+ // byte1 is never ASCII.
+ if (byte1 < (byte) 0xE0) {
+ // two-byte form
+
+ // Simultaneously checks for illegal trailing-byte in
+ // leading position and overlong 2-byte form.
+ if (byte1 < (byte) 0xC2
+ // byte2 trailing-byte test
+ || buffer.get(index++) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ } else if (byte1 < (byte) 0xF0) {
+ // three-byte form
+
+ // Get byte2 from saved state or array
+ byte byte2 = (byte) ~(state >> 8);
+ if (byte2 == 0) {
+ byte2 = buffer.get(index++);
+ if (index >= limit) {
+ return incompleteStateFor(byte1, byte2);
+ }
+ }
+ if (byte2 > (byte) 0xBF
+ // overlong? 5 most significant bits must not all be zero
+ || (byte1 == (byte) 0xE0 && byte2 < (byte) 0xA0)
+ // illegal surrogate codepoint?
+ || (byte1 == (byte) 0xED && byte2 >= (byte) 0xA0)
+ // byte3 trailing-byte test
+ || buffer.get(index++) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ } else {
+ // four-byte form
+
+ // Get byte2 and byte3 from saved state or array
+ byte byte2 = (byte) ~(state >> 8);
+ byte byte3 = 0;
+ if (byte2 == 0) {
+ byte2 = buffer.get(index++);
+ if (index >= limit) {
+ return incompleteStateFor(byte1, byte2);
+ }
+ } else {
+ byte3 = (byte) (state >> 16);
+ }
+ if (byte3 == 0) {
+ byte3 = buffer.get(index++);
+ if (index >= limit) {
+ return incompleteStateFor(byte1, byte2, byte3);
+ }
+ }
+
+ // If we were called with state == MALFORMED, then byte1 is 0xFF,
+ // which never occurs in well-formed UTF-8, and so we will return
+ // MALFORMED again below.
+
+ if (byte2 > (byte) 0xBF
+ // Check that 1 <= plane <= 16. Tricky optimized form of:
+ // if (byte1 > (byte) 0xF4 ||
+ // byte1 == (byte) 0xF0 && byte2 < (byte) 0x90 ||
+ // byte1 == (byte) 0xF4 && byte2 > (byte) 0x8F)
+ || (((byte1 << 28) + (byte2 - (byte) 0x90)) >> 30) != 0
+ // byte3 trailing-byte test
+ || byte3 > (byte) 0xBF
+ // byte4 trailing-byte test
+ || buffer.get(index++) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ }
+ }
+
+ // Finish validation for the sequence.
+ return partialIsValidUtf8(buffer, index, limit);
+ }
+
+ /**
+ * Performs validation for {@link ByteBuffer} instances using the {@link ByteBuffer} API rather
+ * than potentially faster approaches.
+ */
+ private static int partialIsValidUtf8(final ByteBuffer buffer, int index, final int limit) {
+ index += estimateConsecutiveAscii(buffer, index, limit);
+
+ for (;;) {
+ // Optimize for interior runs of ASCII bytes.
+ // TODO(nathanmittler): Consider checking 8 bytes at a time after some threshold?
+ // Maybe after seeing a few in a row that are ASCII, go back to fast mode?
+ int byte1;
+ do {
+ if (index >= limit) {
+ return COMPLETE;
+ }
+ } while ((byte1 = buffer.get(index++)) >= 0);
+
+ // If we're here byte1 is not ASCII. Only need to handle 2-4 byte forms.
+ if (byte1 < (byte) 0xE0) {
+ // Two-byte form (110xxxxx 10xxxxxx)
+ if (index >= limit) {
+ // Incomplete sequence
+ return byte1;
+ }
+
+ // Simultaneously checks for illegal trailing-byte in
+ // leading position and overlong 2-byte form.
+ if (byte1 < (byte) 0xC2 || buffer.get(index) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ index++;
+ } else if (byte1 < (byte) 0xF0) {
+ // Three-byte form (1110xxxx 10xxxxxx 10xxxxxx)
+ if (index >= limit - 1) {
+ // Incomplete sequence
+ return incompleteStateFor(buffer, byte1, index, limit - index);
+ }
+
+ final byte byte2 = buffer.get(index++);
+ if (byte2 > (byte) 0xBF
+ // overlong? 5 most significant bits must not all be zero
+ || (byte1 == (byte) 0xE0 && byte2 < (byte) 0xA0)
+ // check for illegal surrogate codepoints
+ || (byte1 == (byte) 0xED && byte2 >= (byte) 0xA0)
+ // byte3 trailing-byte test
+ || buffer.get(index) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ index++;
+ } else {
+ // Four-byte form (1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx)
+ if (index >= limit - 2) {
+ // Incomplete sequence
+ return incompleteStateFor(buffer, byte1, index, limit - index);
+ }
+
+ // TODO(nathanmittler): Consider using getInt() to improve performance.
+ final int byte2 = buffer.get(index++);
+ if (byte2 > (byte) 0xBF
+ // Check that 1 <= plane <= 16. Tricky optimized form of:
+ // if (byte1 > (byte) 0xF4 ||
+ // byte1 == (byte) 0xF0 && byte2 < (byte) 0x90 ||
+ // byte1 == (byte) 0xF4 && byte2 > (byte) 0x8F)
+ || (((byte1 << 28) + (byte2 - (byte) 0x90)) >> 30) != 0
+ // byte3 trailing-byte test
+ || buffer.get(index++) > (byte) 0xBF
+ // byte4 trailing-byte test
+ || buffer.get(index++) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ }
+ }
+ }
+
+ /**
+ * Encodes an input character sequence ({@code in}) to UTF-8 in the target array ({@code out}).
+ * For a string, this method is similar to
+ * <pre>{@code
+ * byte[] a = string.getBytes(UTF_8);
+ * System.arraycopy(a, 0, bytes, offset, a.length);
+ * return offset + a.length;
+ * }</pre>
+ *
+ * but is more efficient in both time and space. One key difference is that this method
+ * requires paired surrogates, and therefore does not support chunking.
+ * While {@code String.getBytes(UTF_8)} replaces unpaired surrogates with the default
+ * replacement character, this method throws {@link UnpairedSurrogateException}.
+ *
+ * <p>To ensure sufficient space in the output buffer, either call {@link #encodedLength} to
+ * compute the exact amount needed, or leave room for
+ * {@code Utf8.MAX_BYTES_PER_CHAR * sequence.length()}, which is the largest possible number
+ * of bytes that any input can be encoded to.
+ *
+ * @param in the input character sequence to be encoded
+ * @param out the target array
+ * @param offset the starting offset in {@code bytes} to start writing at
+ * @param length the length of the {@code bytes}, starting from {@code offset}
+ * @throws UnpairedSurrogateException if {@code sequence} contains ill-formed UTF-16 (unpaired
+ * surrogates)
+ * @throws ArrayIndexOutOfBoundsException if {@code sequence} encoded in UTF-8 is longer than
+ * {@code bytes.length - offset}
+ * @return the new offset, equivalent to {@code offset + Utf8.encodedLength(sequence)}
+ */
+ abstract int encodeUtf8(CharSequence in, byte[] out, int offset, int length);
+
+ /**
+ * Encodes an input character sequence ({@code in}) to UTF-8 in the target buffer ({@code out}).
+ * Upon returning from this method, the {@code out} position will point to the position after
+ * the last encoded byte. This method requires paired surrogates, and therefore does not
+ * support chunking.
+ *
+ * <p>To ensure sufficient space in the output buffer, either call {@link #encodedLength} to
+ * compute the exact amount needed, or leave room for
+ * {@code Utf8.MAX_BYTES_PER_CHAR * in.length()}, which is the largest possible number
+ * of bytes that any input can be encoded to.
+ *
+ * @param in the source character sequence to be encoded
+ * @param out the target buffer
+ * @throws UnpairedSurrogateException if {@code in} contains ill-formed UTF-16 (unpaired
+ * surrogates)
+ * @throws ArrayIndexOutOfBoundsException if {@code in} encoded in UTF-8 is longer than
+ * {@code out.remaining()}
+ */
+ final void encodeUtf8(CharSequence in, ByteBuffer out) {
+ if (out.hasArray()) {
+ final int offset = out.arrayOffset();
+ int endIndex =
+ Utf8.encode(in, out.array(), offset + out.position(), out.remaining());
+ out.position(endIndex - offset);
+ } else if (out.isDirect()) {
+ encodeUtf8Direct(in, out);
+ } else {
+ encodeUtf8Default(in, out);
+ }
+ }
+
+ /**
+ * Encodes the input character sequence to a direct {@link ByteBuffer} instance.
+ */
+ abstract void encodeUtf8Direct(CharSequence in, ByteBuffer out);
+
+ /**
+ * Encodes the input character sequence to a {@link ByteBuffer} instance using the {@link
+ * ByteBuffer} API, rather than potentially faster approaches.
+ */
+ final void encodeUtf8Default(CharSequence in, ByteBuffer out) {
+ final int inLength = in.length();
+ int outIx = out.position();
+ int inIx = 0;
+
+ // Since ByteBuffer.putXXX() already checks boundaries for us, no need to explicitly check
+ // access. Assume the buffer is big enough and let it handle the out of bounds exception
+ // if it occurs.
+ try {
+ // Designed to take advantage of
+ // https://wikis.oracle.com/display/HotSpotInternals/RangeCheckElimination
+ for (char c; inIx < inLength && (c = in.charAt(inIx)) < 0x80; ++inIx) {
+ out.put(outIx + inIx, (byte) c);
+ }
+ if (inIx == inLength) {
+ // Successfully encoded the entire string.
+ out.position(outIx + inIx);
+ return;
+ }
+
+ outIx += inIx;
+ for (char c; inIx < inLength; ++inIx, ++outIx) {
+ c = in.charAt(inIx);
+ if (c < 0x80) {
+ // One byte (0xxx xxxx)
+ out.put(outIx, (byte) c);
+ } else if (c < 0x800) {
+ // Two bytes (110x xxxx 10xx xxxx)
+
+ // Benchmarks show put performs better than putShort here (for HotSpot).
+ out.put(outIx++, (byte) (0xC0 | (c >>> 6)));
+ out.put(outIx, (byte) (0x80 | (0x3F & c)));
+ } else if (c < MIN_SURROGATE || MAX_SURROGATE < c) {
+ // Three bytes (1110 xxxx 10xx xxxx 10xx xxxx)
+ // Maximum single-char code point is 0xFFFF, 16 bits.
+
+ // Benchmarks show put performs better than putShort here (for HotSpot).
+ out.put(outIx++, (byte) (0xE0 | (c >>> 12)));
+ out.put(outIx++, (byte) (0x80 | (0x3F & (c >>> 6))));
+ out.put(outIx, (byte) (0x80 | (0x3F & c)));
+ } else {
+ // Four bytes (1111 xxxx 10xx xxxx 10xx xxxx 10xx xxxx)
+
+ // Minimum code point represented by a surrogate pair is 0x10000, 17 bits, four UTF-8
+ // bytes
+ final char low;
+ if (inIx + 1 == inLength || !isSurrogatePair(c, (low = in.charAt(++inIx)))) {
+ throw new UnpairedSurrogateException(inIx, inLength);
+ }
+ // TODO(nathanmittler): Consider using putInt() to improve performance.
+ int codePoint = toCodePoint(c, low);
+ out.put(outIx++, (byte) ((0xF << 4) | (codePoint >>> 18)));
+ out.put(outIx++, (byte) (0x80 | (0x3F & (codePoint >>> 12))));
+ out.put(outIx++, (byte) (0x80 | (0x3F & (codePoint >>> 6))));
+ out.put(outIx, (byte) (0x80 | (0x3F & codePoint)));
+ }
+ }
+
+ // Successfully encoded the entire string.
+ out.position(outIx);
+ } catch (IndexOutOfBoundsException e) {
+ // TODO(nathanmittler): Consider making the API throw IndexOutOfBoundsException instead.
+
+ // If we failed in the outer ASCII loop, outIx will not have been updated. In this case,
+ // use inIx to determine the bad write index.
+ int badWriteIndex = out.position() + Math.max(inIx, outIx - out.position() + 1);
+ throw new ArrayIndexOutOfBoundsException(
+ "Failed writing " + in.charAt(inIx) + " at index " + badWriteIndex);
+ }
+ }
+ }
+
+ /**
+ * {@link Processor} implementation that does not use any {@code sun.misc.Unsafe} methods.
+ */
+ static final class SafeProcessor extends Processor {
+ @Override
+ int partialIsValidUtf8(int state, byte[] bytes, int index, int limit) {
+ if (state != COMPLETE) {
+ // The previous decoding operation was incomplete (or malformed).
+ // We look for a well-formed sequence consisting of bytes from
+ // the previous decoding operation (stored in state) together
+ // with bytes from the array slice.
+ //
+ // We expect such "straddler characters" to be rare.
+
+ if (index >= limit) { // No bytes? No progress.
+ return state;
+ }
+ int byte1 = (byte) state;
+ // byte1 is never ASCII.
+ if (byte1 < (byte) 0xE0) {
+ // two-byte form
+
+ // Simultaneously checks for illegal trailing-byte in
+ // leading position and overlong 2-byte form.
+ if (byte1 < (byte) 0xC2
+ // byte2 trailing-byte test
+ || bytes[index++] > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ } else if (byte1 < (byte) 0xF0) {
+ // three-byte form
+
+ // Get byte2 from saved state or array
+ int byte2 = (byte) ~(state >> 8);
+ if (byte2 == 0) {
+ byte2 = bytes[index++];
+ if (index >= limit) {
+ return incompleteStateFor(byte1, byte2);
+ }
+ }
+ if (byte2 > (byte) 0xBF
+ // overlong? 5 most significant bits must not all be zero
+ || (byte1 == (byte) 0xE0 && byte2 < (byte) 0xA0)
+ // illegal surrogate codepoint?
+ || (byte1 == (byte) 0xED && byte2 >= (byte) 0xA0)
+ // byte3 trailing-byte test
+ || bytes[index++] > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ } else {
+ // four-byte form
+
+ // Get byte2 and byte3 from saved state or array
+ int byte2 = (byte) ~(state >> 8);
+ int byte3 = 0;
+ if (byte2 == 0) {
+ byte2 = bytes[index++];
+ if (index >= limit) {
+ return incompleteStateFor(byte1, byte2);
+ }
+ } else {
+ byte3 = (byte) (state >> 16);
+ }
+ if (byte3 == 0) {
+ byte3 = bytes[index++];
+ if (index >= limit) {
+ return incompleteStateFor(byte1, byte2, byte3);
+ }
+ }
+
+ // If we were called with state == MALFORMED, then byte1 is 0xFF,
+ // which never occurs in well-formed UTF-8, and so we will return
+ // MALFORMED again below.
+
+ if (byte2 > (byte) 0xBF
+ // Check that 1 <= plane <= 16. Tricky optimized form of:
+ // if (byte1 > (byte) 0xF4 ||
+ // byte1 == (byte) 0xF0 && byte2 < (byte) 0x90 ||
+ // byte1 == (byte) 0xF4 && byte2 > (byte) 0x8F)
+ || (((byte1 << 28) + (byte2 - (byte) 0x90)) >> 30) != 0
+ // byte3 trailing-byte test
+ || byte3 > (byte) 0xBF
+ // byte4 trailing-byte test
+ || bytes[index++] > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ }
+ }
+
+ return partialIsValidUtf8(bytes, index, limit);
+ }
+
+ @Override
+ int partialIsValidUtf8Direct(int state, ByteBuffer buffer, int index, int limit) {
+ // For safe processing, we have to use the ByteBuffer API.
+ return partialIsValidUtf8Default(state, buffer, index, limit);
+ }
+
+ @Override
+ int encodeUtf8(CharSequence in, byte[] out, int offset, int length) {
+ int utf16Length = in.length();
+ int j = offset;
+ int i = 0;
+ int limit = offset + length;
+ // Designed to take advantage of
+ // https://wikis.oracle.com/display/HotSpotInternals/RangeCheckElimination
+ for (char c; i < utf16Length && i + j < limit && (c = in.charAt(i)) < 0x80; i++) {
+ out[j + i] = (byte) c;
+ }
+ if (i == utf16Length) {
+ return j + utf16Length;
+ }
+ j += i;
+ for (char c; i < utf16Length; i++) {
+ c = in.charAt(i);
+ if (c < 0x80 && j < limit) {
+ out[j++] = (byte) c;
+ } else if (c < 0x800 && j <= limit - 2) { // 11 bits, two UTF-8 bytes
+ out[j++] = (byte) ((0xF << 6) | (c >>> 6));
+ out[j++] = (byte) (0x80 | (0x3F & c));
+ } else if ((c < Character.MIN_SURROGATE || Character.MAX_SURROGATE < c) && j <= limit - 3) {
+ // Maximum single-char code point is 0xFFFF, 16 bits, three UTF-8 bytes
+ out[j++] = (byte) ((0xF << 5) | (c >>> 12));
+ out[j++] = (byte) (0x80 | (0x3F & (c >>> 6)));
+ out[j++] = (byte) (0x80 | (0x3F & c));
+ } else if (j <= limit - 4) {
+ // Minimum code point represented by a surrogate pair is 0x10000, 17 bits,
+ // four UTF-8 bytes
+ final char low;
+ if (i + 1 == in.length()
+ || !Character.isSurrogatePair(c, (low = in.charAt(++i)))) {
+ throw new UnpairedSurrogateException((i - 1), utf16Length);
+ }
+ int codePoint = Character.toCodePoint(c, low);
+ out[j++] = (byte) ((0xF << 4) | (codePoint >>> 18));
+ out[j++] = (byte) (0x80 | (0x3F & (codePoint >>> 12)));
+ out[j++] = (byte) (0x80 | (0x3F & (codePoint >>> 6)));
+ out[j++] = (byte) (0x80 | (0x3F & codePoint));
+ } else {
+ // If we are surrogates and we're not a surrogate pair, always throw an
+ // UnpairedSurrogateException instead of an ArrayOutOfBoundsException.
+ if ((Character.MIN_SURROGATE <= c && c <= Character.MAX_SURROGATE)
+ && (i + 1 == in.length()
+ || !Character.isSurrogatePair(c, in.charAt(i + 1)))) {
+ throw new UnpairedSurrogateException(i, utf16Length);
+ }
+ throw new ArrayIndexOutOfBoundsException("Failed writing " + c + " at index " + j);
+ }
+ }
+ return j;
+ }
+
+ @Override
+ void encodeUtf8Direct(CharSequence in, ByteBuffer out) {
+ // For safe processing, we have to use the ByteBuffer API.
+ encodeUtf8Default(in, out);
+ }
+
+ private static int partialIsValidUtf8(byte[] bytes, int index, int limit) {
+ // Optimize for 100% ASCII (Hotspot loves small simple top-level loops like this).
+ // This simple loop stops when we encounter a byte >= 0x80 (i.e. non-ASCII).
+ while (index < limit && bytes[index] >= 0) {
+ index++;
+ }
+
+ return (index >= limit) ? COMPLETE : partialIsValidUtf8NonAscii(bytes, index, limit);
+ }
+
+ private static int partialIsValidUtf8NonAscii(byte[] bytes, int index, int limit) {
+ for (;;) {
+ int byte1, byte2;
+
+ // Optimize for interior runs of ASCII bytes.
+ do {
+ if (index >= limit) {
+ return COMPLETE;
+ }
+ } while ((byte1 = bytes[index++]) >= 0);
+
+ if (byte1 < (byte) 0xE0) {
+ // two-byte form
+
+ if (index >= limit) {
+ // Incomplete sequence
+ return byte1;
+ }
+
+ // Simultaneously checks for illegal trailing-byte in
+ // leading position and overlong 2-byte form.
+ if (byte1 < (byte) 0xC2
+ || bytes[index++] > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ } else if (byte1 < (byte) 0xF0) {
+ // three-byte form
+
+ if (index >= limit - 1) { // incomplete sequence
+ return incompleteStateFor(bytes, index, limit);
+ }
+ if ((byte2 = bytes[index++]) > (byte) 0xBF
+ // overlong? 5 most significant bits must not all be zero
+ || (byte1 == (byte) 0xE0 && byte2 < (byte) 0xA0)
+ // check for illegal surrogate codepoints
+ || (byte1 == (byte) 0xED && byte2 >= (byte) 0xA0)
+ // byte3 trailing-byte test
+ || bytes[index++] > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ } else {
+ // four-byte form
+
+ if (index >= limit - 2) { // incomplete sequence
+ return incompleteStateFor(bytes, index, limit);
+ }
+ if ((byte2 = bytes[index++]) > (byte) 0xBF
+ // Check that 1 <= plane <= 16. Tricky optimized form of:
+ // if (byte1 > (byte) 0xF4 ||
+ // byte1 == (byte) 0xF0 && byte2 < (byte) 0x90 ||
+ // byte1 == (byte) 0xF4 && byte2 > (byte) 0x8F)
+ || (((byte1 << 28) + (byte2 - (byte) 0x90)) >> 30) != 0
+ // byte3 trailing-byte test
+ || bytes[index++] > (byte) 0xBF
+ // byte4 trailing-byte test
+ || bytes[index++] > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * {@link Processor} that uses {@code sun.misc.Unsafe} where possible to improve performance.
+ */
+ static final class UnsafeProcessor extends Processor {
+ /**
+ * Indicates whether or not all required unsafe operations are supported on this platform.
+ */
+ static boolean isAvailable() {
+ return hasUnsafeArrayOperations() && hasUnsafeByteBufferOperations();
+ }
+
+ @Override
+ int partialIsValidUtf8(int state, byte[] bytes, final int index, final int limit) {
+ if ((index | limit | bytes.length - limit) < 0) {
+ throw new ArrayIndexOutOfBoundsException(
+ String.format("Array length=%d, index=%d, limit=%d", bytes.length, index, limit));
+ }
+ long offset = getArrayBaseOffset() + index;
+ final long offsetLimit = getArrayBaseOffset() + limit;
+ if (state != COMPLETE) {
+ // The previous decoding operation was incomplete (or malformed).
+ // We look for a well-formed sequence consisting of bytes from
+ // the previous decoding operation (stored in state) together
+ // with bytes from the array slice.
+ //
+ // We expect such "straddler characters" to be rare.
+
+ if (offset >= offsetLimit) { // No bytes? No progress.
+ return state;
+ }
+ int byte1 = (byte) state;
+ // byte1 is never ASCII.
+ if (byte1 < (byte) 0xE0) {
+ // two-byte form
+
+ // Simultaneously checks for illegal trailing-byte in
+ // leading position and overlong 2-byte form.
+ if (byte1 < (byte) 0xC2
+ // byte2 trailing-byte test
+ || UnsafeUtil.getByte(bytes, offset++) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ } else if (byte1 < (byte) 0xF0) {
+ // three-byte form
+
+ // Get byte2 from saved state or array
+ int byte2 = (byte) ~(state >> 8);
+ if (byte2 == 0) {
+ byte2 = UnsafeUtil.getByte(bytes, offset++);
+ if (offset >= offsetLimit) {
+ return incompleteStateFor(byte1, byte2);
+ }
+ }
+ if (byte2 > (byte) 0xBF
+ // overlong? 5 most significant bits must not all be zero
+ || (byte1 == (byte) 0xE0 && byte2 < (byte) 0xA0)
+ // illegal surrogate codepoint?
+ || (byte1 == (byte) 0xED && byte2 >= (byte) 0xA0)
+ // byte3 trailing-byte test
+ || UnsafeUtil.getByte(bytes, offset++) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ } else {
+ // four-byte form
+
+ // Get byte2 and byte3 from saved state or array
+ int byte2 = (byte) ~(state >> 8);
+ int byte3 = 0;
+ if (byte2 == 0) {
+ byte2 = UnsafeUtil.getByte(bytes, offset++);
+ if (offset >= offsetLimit) {
+ return incompleteStateFor(byte1, byte2);
+ }
+ } else {
+ byte3 = (byte) (state >> 16);
+ }
+ if (byte3 == 0) {
+ byte3 = UnsafeUtil.getByte(bytes, offset++);
+ if (offset >= offsetLimit) {
+ return incompleteStateFor(byte1, byte2, byte3);
+ }
+ }
+
+ // If we were called with state == MALFORMED, then byte1 is 0xFF,
+ // which never occurs in well-formed UTF-8, and so we will return
+ // MALFORMED again below.
+
+ if (byte2 > (byte) 0xBF
+ // Check that 1 <= plane <= 16. Tricky optimized form of:
+ // if (byte1 > (byte) 0xF4 ||
+ // byte1 == (byte) 0xF0 && byte2 < (byte) 0x90 ||
+ // byte1 == (byte) 0xF4 && byte2 > (byte) 0x8F)
+ || (((byte1 << 28) + (byte2 - (byte) 0x90)) >> 30) != 0
+ // byte3 trailing-byte test
+ || byte3 > (byte) 0xBF
+ // byte4 trailing-byte test
+ || UnsafeUtil.getByte(bytes, offset++) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ }
+ }
+
+ return partialIsValidUtf8(bytes, offset, (int) (offsetLimit - offset));
+ }
+
+ @Override
+ int partialIsValidUtf8Direct(
+ final int state, ByteBuffer buffer, final int index, final int limit) {
+ if ((index | limit | buffer.limit() - limit) < 0) {
+ throw new ArrayIndexOutOfBoundsException(
+ String.format("buffer limit=%d, index=%d, limit=%d", buffer.limit(), index, limit));
+ }
+ long address = addressOffset(buffer) + index;
+ final long addressLimit = address + (limit - index);
+ if (state != COMPLETE) {
+ // The previous decoding operation was incomplete (or malformed).
+ // We look for a well-formed sequence consisting of bytes from
+ // the previous decoding operation (stored in state) together
+ // with bytes from the array slice.
+ //
+ // We expect such "straddler characters" to be rare.
+
+ if (address >= addressLimit) { // No bytes? No progress.
+ return state;
+ }
+
+ final int byte1 = (byte) state;
+ // byte1 is never ASCII.
+ if (byte1 < (byte) 0xE0) {
+ // two-byte form
+
+ // Simultaneously checks for illegal trailing-byte in
+ // leading position and overlong 2-byte form.
+ if (byte1 < (byte) 0xC2
+ // byte2 trailing-byte test
+ || UnsafeUtil.getByte(address++) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ } else if (byte1 < (byte) 0xF0) {
+ // three-byte form
+
+ // Get byte2 from saved state or array
+ int byte2 = (byte) ~(state >> 8);
+ if (byte2 == 0) {
+ byte2 = UnsafeUtil.getByte(address++);
+ if (address >= addressLimit) {
+ return incompleteStateFor(byte1, byte2);
+ }
+ }
+ if (byte2 > (byte) 0xBF
+ // overlong? 5 most significant bits must not all be zero
+ || (byte1 == (byte) 0xE0 && byte2 < (byte) 0xA0)
+ // illegal surrogate codepoint?
+ || (byte1 == (byte) 0xED && byte2 >= (byte) 0xA0)
+ // byte3 trailing-byte test
+ || UnsafeUtil.getByte(address++) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ } else {
+ // four-byte form
+
+ // Get byte2 and byte3 from saved state or array
+ int byte2 = (byte) ~(state >> 8);
+ int byte3 = 0;
+ if (byte2 == 0) {
+ byte2 = UnsafeUtil.getByte(address++);
+ if (address >= addressLimit) {
+ return incompleteStateFor(byte1, byte2);
+ }
+ } else {
+ byte3 = (byte) (state >> 16);
+ }
+ if (byte3 == 0) {
+ byte3 = UnsafeUtil.getByte(address++);
+ if (address >= addressLimit) {
+ return incompleteStateFor(byte1, byte2, byte3);
+ }
+ }
+
+ // If we were called with state == MALFORMED, then byte1 is 0xFF,
+ // which never occurs in well-formed UTF-8, and so we will return
+ // MALFORMED again below.
+
+ if (byte2 > (byte) 0xBF
+ // Check that 1 <= plane <= 16. Tricky optimized form of:
+ // if (byte1 > (byte) 0xF4 ||
+ // byte1 == (byte) 0xF0 && byte2 < (byte) 0x90 ||
+ // byte1 == (byte) 0xF4 && byte2 > (byte) 0x8F)
+ || (((byte1 << 28) + (byte2 - (byte) 0x90)) >> 30) != 0
+ // byte3 trailing-byte test
+ || byte3 > (byte) 0xBF
+ // byte4 trailing-byte test
+ || UnsafeUtil.getByte(address++) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ }
+ }
+
+ return partialIsValidUtf8(address, (int) (addressLimit - address));
+ }
+
+ @Override
+ int encodeUtf8(final CharSequence in, final byte[] out, final int offset, final int length) {
+ long outIx = getArrayBaseOffset() + offset;
+ final long outLimit = outIx + length;
+ final int inLimit = in.length();
+ if (inLimit > length || out.length - length < offset) {
+ // Not even enough room for an ASCII-encoded string.
+ throw new ArrayIndexOutOfBoundsException(
+ "Failed writing " + in.charAt(inLimit - 1) + " at index " + (offset + length));
+ }
+
+ // Designed to take advantage of
+ // https://wikis.oracle.com/display/HotSpotInternals/RangeCheckElimination
+ int inIx = 0;
+ for (char c; inIx < inLimit && (c = in.charAt(inIx)) < 0x80; ++inIx) {
+ UnsafeUtil.putByte(out, outIx++, (byte) c);
+ }
+ if (inIx == inLimit) {
+ // We're done, it was ASCII encoded.
+ return (int) (outIx - getArrayBaseOffset());
+ }
+
+ for (char c; inIx < inLimit; ++inIx) {
+ c = in.charAt(inIx);
+ if (c < 0x80 && outIx < outLimit) {
+ UnsafeUtil.putByte(out, outIx++, (byte) c);
+ } else if (c < 0x800 && outIx <= outLimit - 2L) { // 11 bits, two UTF-8 bytes
+ UnsafeUtil.putByte(out, outIx++, (byte) ((0xF << 6) | (c >>> 6)));
+ UnsafeUtil.putByte(out, outIx++, (byte) (0x80 | (0x3F & c)));
+ } else if ((c < MIN_SURROGATE || MAX_SURROGATE < c) && outIx <= outLimit - 3L) {
+ // Maximum single-char code point is 0xFFFF, 16 bits, three UTF-8 bytes
+ UnsafeUtil.putByte(out, outIx++, (byte) ((0xF << 5) | (c >>> 12)));
+ UnsafeUtil.putByte(out, outIx++, (byte) (0x80 | (0x3F & (c >>> 6))));
+ UnsafeUtil.putByte(out, outIx++, (byte) (0x80 | (0x3F & c)));
+ } else if (outIx <= outLimit - 4L) {
+ // Minimum code point represented by a surrogate pair is 0x10000, 17 bits, four UTF-8
+ // bytes
+ final char low;
+ if (inIx + 1 == inLimit || !isSurrogatePair(c, (low = in.charAt(++inIx)))) {
+ throw new UnpairedSurrogateException((inIx - 1), inLimit);
+ }
+ int codePoint = toCodePoint(c, low);
+ UnsafeUtil.putByte(out, outIx++, (byte) ((0xF << 4) | (codePoint >>> 18)));
+ UnsafeUtil.putByte(out, outIx++, (byte) (0x80 | (0x3F & (codePoint >>> 12))));
+ UnsafeUtil.putByte(out, outIx++, (byte) (0x80 | (0x3F & (codePoint >>> 6))));
+ UnsafeUtil.putByte(out, outIx++, (byte) (0x80 | (0x3F & codePoint)));
+ } else {
+ if ((MIN_SURROGATE <= c && c <= MAX_SURROGATE)
+ && (inIx + 1 == inLimit || !isSurrogatePair(c, in.charAt(inIx + 1)))) {
+ // We are surrogates and we're not a surrogate pair.
+ throw new UnpairedSurrogateException(inIx, inLimit);
+ }
+ // Not enough space in the output buffer.
+ throw new ArrayIndexOutOfBoundsException("Failed writing " + c + " at index " + outIx);
+ }
+ }
+
+ // All bytes have been encoded.
+ return (int) (outIx - getArrayBaseOffset());
+ }
+
+ @Override
+ void encodeUtf8Direct(CharSequence in, ByteBuffer out) {
+ final long address = addressOffset(out);
+ long outIx = address + out.position();
+ final long outLimit = address + out.limit();
+ final int inLimit = in.length();
+ if (inLimit > outLimit - outIx) {
+ // Not even enough room for an ASCII-encoded string.
+ throw new ArrayIndexOutOfBoundsException(
+ "Failed writing " + in.charAt(inLimit - 1) + " at index " + out.limit());
+ }
+
+ // Designed to take advantage of
+ // https://wikis.oracle.com/display/HotSpotInternals/RangeCheckElimination
+ int inIx = 0;
+ for (char c; inIx < inLimit && (c = in.charAt(inIx)) < 0x80; ++inIx) {
+ UnsafeUtil.putByte(outIx++, (byte) c);
+ }
+ if (inIx == inLimit) {
+ // We're done, it was ASCII encoded.
+ out.position((int) (outIx - address));
+ return;
+ }
+
+ for (char c; inIx < inLimit; ++inIx) {
+ c = in.charAt(inIx);
+ if (c < 0x80 && outIx < outLimit) {
+ UnsafeUtil.putByte(outIx++, (byte) c);
+ } else if (c < 0x800 && outIx <= outLimit - 2L) { // 11 bits, two UTF-8 bytes
+ UnsafeUtil.putByte(outIx++, (byte) ((0xF << 6) | (c >>> 6)));
+ UnsafeUtil.putByte(outIx++, (byte) (0x80 | (0x3F & c)));
+ } else if ((c < MIN_SURROGATE || MAX_SURROGATE < c) && outIx <= outLimit - 3L) {
+ // Maximum single-char code point is 0xFFFF, 16 bits, three UTF-8 bytes
+ UnsafeUtil.putByte(outIx++, (byte) ((0xF << 5) | (c >>> 12)));
+ UnsafeUtil.putByte(outIx++, (byte) (0x80 | (0x3F & (c >>> 6))));
+ UnsafeUtil.putByte(outIx++, (byte) (0x80 | (0x3F & c)));
+ } else if (outIx <= outLimit - 4L) {
+ // Minimum code point represented by a surrogate pair is 0x10000, 17 bits, four UTF-8
+ // bytes
+ final char low;
+ if (inIx + 1 == inLimit || !isSurrogatePair(c, (low = in.charAt(++inIx)))) {
+ throw new UnpairedSurrogateException((inIx - 1), inLimit);
+ }
+ int codePoint = toCodePoint(c, low);
+ UnsafeUtil.putByte(outIx++, (byte) ((0xF << 4) | (codePoint >>> 18)));
+ UnsafeUtil.putByte(outIx++, (byte) (0x80 | (0x3F & (codePoint >>> 12))));
+ UnsafeUtil.putByte(outIx++, (byte) (0x80 | (0x3F & (codePoint >>> 6))));
+ UnsafeUtil.putByte(outIx++, (byte) (0x80 | (0x3F & codePoint)));
+ } else {
+ if ((MIN_SURROGATE <= c && c <= MAX_SURROGATE)
+ && (inIx + 1 == inLimit || !isSurrogatePair(c, in.charAt(inIx + 1)))) {
+ // We are surrogates and we're not a surrogate pair.
+ throw new UnpairedSurrogateException(inIx, inLimit);
+ }
+ // Not enough space in the output buffer.
+ throw new ArrayIndexOutOfBoundsException("Failed writing " + c + " at index " + outIx);
+ }
+ }
+
+ // All bytes have been encoded.
+ out.position((int) (outIx - address));
+ }
+
+ /**
+ * Counts (approximately) the number of consecutive ASCII characters starting from the given
+ * position, using the most efficient method available to the platform.
+ *
+ * @param bytes the array containing the character sequence
+ * @param offset the offset position of the index (same as index + arrayBaseOffset)
+ * @param maxChars the maximum number of characters to count
+ * @return the number of ASCII characters found. The stopping position will be at or
+ * before the first non-ASCII byte.
+ */
+ private static int unsafeEstimateConsecutiveAscii(
+ byte[] bytes, long offset, final int maxChars) {
+ int remaining = maxChars;
+ if (remaining < UNSAFE_COUNT_ASCII_THRESHOLD) {
+ // Don't bother with small strings.
+ return 0;
+ }
+
+ // Read bytes until 8-byte aligned so that we can read longs in the loop below.
+ // Byte arrays are already either 8 or 16-byte aligned, so we just need to make sure that
+ // the index (relative to the start of the array) is also 8-byte aligned. We do this by
+ // ANDing the index with 7 to determine the number of bytes that need to be read before
+ // we're 8-byte aligned.
+ final int unaligned = (int) offset & 7;
+ for (int j = unaligned; j > 0; j--) {
+ if (UnsafeUtil.getByte(bytes, offset++) < 0) {
+ return unaligned - j;
+ }
+ }
+
+ // This simple loop stops when we encounter a byte >= 0x80 (i.e. non-ASCII).
+ // To speed things up further, we're reading longs instead of bytes so we use a mask to
+ // determine if any byte in the current long is non-ASCII.
+ remaining -= unaligned;
+ for (; remaining >= 8 && (UnsafeUtil.getLong(bytes, offset) & ASCII_MASK_LONG) == 0;
+ offset += 8, remaining -= 8) {}
+ return maxChars - remaining;
+ }
+
+ /**
+ * Same as {@link Utf8#estimateConsecutiveAscii(ByteBuffer, int, int)} except that it uses the
+ * most efficient method available to the platform.
+ */
+ private static int unsafeEstimateConsecutiveAscii(long address, final int maxChars) {
+ int remaining = maxChars;
+ if (remaining < UNSAFE_COUNT_ASCII_THRESHOLD) {
+ // Don't bother with small strings.
+ return 0;
+ }
+
+ // Read bytes until 8-byte aligned so that we can read longs in the loop below.
+ // We do this by ANDing the address with 7 to determine the number of bytes that need to
+ // be read before we're 8-byte aligned.
+ final int unaligned = (int) address & 7;
+ for (int j = unaligned; j > 0; j--) {
+ if (UnsafeUtil.getByte(address++) < 0) {
+ return unaligned - j;
+ }
+ }
+
+ // This simple loop stops when we encounter a byte >= 0x80 (i.e. non-ASCII).
+ // To speed things up further, we're reading longs instead of bytes so we use a mask to
+ // determine if any byte in the current long is non-ASCII.
+ remaining -= unaligned;
+ for (; remaining >= 8 && (UnsafeUtil.getLong(address) & ASCII_MASK_LONG) == 0;
+ address += 8, remaining -= 8) {}
+ return maxChars - remaining;
+ }
+
+ private static int partialIsValidUtf8(final byte[] bytes, long offset, int remaining) {
+ // Skip past ASCII characters as quickly as possible.
+ final int skipped = unsafeEstimateConsecutiveAscii(bytes, offset, remaining);
+ remaining -= skipped;
+ offset += skipped;
+
+ for (;;) {
+ // Optimize for interior runs of ASCII bytes.
+ // TODO(nathanmittler): Consider checking 8 bytes at a time after some threshold?
+ // Maybe after seeing a few in a row that are ASCII, go back to fast mode?
+ int byte1 = 0;
+ for (; remaining > 0 && (byte1 = UnsafeUtil.getByte(bytes, offset++)) >= 0; --remaining) {
+ }
+ if (remaining == 0) {
+ return COMPLETE;
+ }
+ remaining--;
+
+ // If we're here byte1 is not ASCII. Only need to handle 2-4 byte forms.
+ if (byte1 < (byte) 0xE0) {
+ // Two-byte form (110xxxxx 10xxxxxx)
+ if (remaining == 0) {
+ // Incomplete sequence
+ return byte1;
+ }
+ remaining--;
+
+ // Simultaneously checks for illegal trailing-byte in
+ // leading position and overlong 2-byte form.
+ if (byte1 < (byte) 0xC2
+ || UnsafeUtil.getByte(bytes, offset++) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ } else if (byte1 < (byte) 0xF0) {
+ // Three-byte form (1110xxxx 10xxxxxx 10xxxxxx)
+ if (remaining < 2) {
+ // Incomplete sequence
+ return unsafeIncompleteStateFor(bytes, byte1, offset, remaining);
+ }
+ remaining -= 2;
+
+ final int byte2;
+ if ((byte2 = UnsafeUtil.getByte(bytes, offset++)) > (byte) 0xBF
+ // overlong? 5 most significant bits must not all be zero
+ || (byte1 == (byte) 0xE0 && byte2 < (byte) 0xA0)
+ // check for illegal surrogate codepoints
+ || (byte1 == (byte) 0xED && byte2 >= (byte) 0xA0)
+ // byte3 trailing-byte test
+ || UnsafeUtil.getByte(bytes, offset++) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ } else {
+ // Four-byte form (1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx)
+ if (remaining < 3) {
+ // Incomplete sequence
+ return unsafeIncompleteStateFor(bytes, byte1, offset, remaining);
+ }
+ remaining -= 3;
+
+ final int byte2;
+ if ((byte2 = UnsafeUtil.getByte(bytes, offset++)) > (byte) 0xBF
+ // Check that 1 <= plane <= 16. Tricky optimized form of:
+ // if (byte1 > (byte) 0xF4 ||
+ // byte1 == (byte) 0xF0 && byte2 < (byte) 0x90 ||
+ // byte1 == (byte) 0xF4 && byte2 > (byte) 0x8F)
+ || (((byte1 << 28) + (byte2 - (byte) 0x90)) >> 30) != 0
+ // byte3 trailing-byte test
+ || UnsafeUtil.getByte(bytes, offset++) > (byte) 0xBF
+ // byte4 trailing-byte test
+ || UnsafeUtil.getByte(bytes, offset++) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ }
+ }
+ }
+
+ private static int partialIsValidUtf8(long address, int remaining) {
+ // Skip past ASCII characters as quickly as possible.
+ final int skipped = unsafeEstimateConsecutiveAscii(address, remaining);
+ address += skipped;
+ remaining -= skipped;
+
+ for (;;) {
+ // Optimize for interior runs of ASCII bytes.
+ // TODO(nathanmittler): Consider checking 8 bytes at a time after some threshold?
+ // Maybe after seeing a few in a row that are ASCII, go back to fast mode?
+ int byte1 = 0;
+ for (; remaining > 0 && (byte1 = UnsafeUtil.getByte(address++)) >= 0; --remaining) {
+ }
+ if (remaining == 0) {
+ return COMPLETE;
+ }
+ remaining--;
+
+ if (byte1 < (byte) 0xE0) {
+ // Two-byte form
+
+ if (remaining == 0) {
+ // Incomplete sequence
+ return byte1;
+ }
+ remaining--;
+
+ // Simultaneously checks for illegal trailing-byte in
+ // leading position and overlong 2-byte form.
+ if (byte1 < (byte) 0xC2 || UnsafeUtil.getByte(address++) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ } else if (byte1 < (byte) 0xF0) {
+ // Three-byte form
+
+ if (remaining < 2) {
+ // Incomplete sequence
+ return unsafeIncompleteStateFor(address, byte1, remaining);
+ }
+ remaining -= 2;
+
+ final byte byte2 = UnsafeUtil.getByte(address++);
+ if (byte2 > (byte) 0xBF
+ // overlong? 5 most significant bits must not all be zero
+ || (byte1 == (byte) 0xE0 && byte2 < (byte) 0xA0)
+ // check for illegal surrogate codepoints
+ || (byte1 == (byte) 0xED && byte2 >= (byte) 0xA0)
+ // byte3 trailing-byte test
+ || UnsafeUtil.getByte(address++) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ } else {
+ // Four-byte form
+
+ if (remaining < 3) {
+ // Incomplete sequence
+ return unsafeIncompleteStateFor(address, byte1, remaining);
+ }
+ remaining -= 3;
+
+ final byte byte2 = UnsafeUtil.getByte(address++);
+ if (byte2 > (byte) 0xBF
+ // Check that 1 <= plane <= 16. Tricky optimized form of:
+ // if (byte1 > (byte) 0xF4 ||
+ // byte1 == (byte) 0xF0 && byte2 < (byte) 0x90 ||
+ // byte1 == (byte) 0xF4 && byte2 > (byte) 0x8F)
+ || (((byte1 << 28) + (byte2 - (byte) 0x90)) >> 30) != 0
+ // byte3 trailing-byte test
+ || UnsafeUtil.getByte(address++) > (byte) 0xBF
+ // byte4 trailing-byte test
+ || UnsafeUtil.getByte(address++) > (byte) 0xBF) {
+ return MALFORMED;
+ }
+ }
+ }
+ }
+
+ private static int unsafeIncompleteStateFor(byte[] bytes, int byte1, long offset,
+ int remaining) {
+ switch (remaining) {
+ case 0: {
+ return incompleteStateFor(byte1);
+ }
+ case 1: {
+ return incompleteStateFor(byte1, UnsafeUtil.getByte(bytes, offset));
+ }
+ case 2: {
+ return incompleteStateFor(byte1, UnsafeUtil.getByte(bytes, offset),
+ UnsafeUtil.getByte(bytes, offset + 1));
+ }
+ default: {
+ throw new AssertionError();
+ }
+ }
+ }
+
+ private static int unsafeIncompleteStateFor(long address, final int byte1, int remaining) {
+ switch (remaining) {
+ case 0: {
+ return incompleteStateFor(byte1);
+ }
+ case 1: {
+ return incompleteStateFor(byte1, UnsafeUtil.getByte(address));
+ }
+ case 2: {
+ return incompleteStateFor(byte1, UnsafeUtil.getByte(address),
+ UnsafeUtil.getByte(address + 1));
+ }
+ default: {
+ throw new AssertionError();
+ }
+ }
+ }
+ }
+
+ private Utf8() {}
+}
diff --git a/third_party/protobuf/java/core/src/main/java/com/google/protobuf/WireFormat.java b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/WireFormat.java
new file mode 100644
index 0000000000..0b0cdb7d0e
--- /dev/null
+++ b/third_party/protobuf/java/core/src/main/java/com/google/protobuf/WireFormat.java
@@ -0,0 +1,260 @@
+// 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.IOException;
+
+/**
+ * This class is used internally by the Protocol Buffer library and generated
+ * message implementations. It is public only because those generated messages
+ * do not reside in the {@code protobuf} package. Others should not use this
+ * class directly.
+ *
+ * This class contains constants and helper functions useful for dealing with
+ * the Protocol Buffer wire format.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+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;
+ public static final int WIRETYPE_START_GROUP = 3;
+ public static final int WIRETYPE_END_GROUP = 4;
+ public static final int WIRETYPE_FIXED32 = 5;
+
+ static final int TAG_TYPE_BITS = 3;
+ static final int TAG_TYPE_MASK = (1 << TAG_TYPE_BITS) - 1;
+
+ /** Given a tag value, determines the wire type (the lower 3 bits). */
+ public static int getTagWireType(final int tag) {
+ return tag & TAG_TYPE_MASK;
+ }
+
+ /** Given a tag value, determines the field number (the upper 29 bits). */
+ public static int getTagFieldNumber(final int tag) {
+ return tag >>> TAG_TYPE_BITS;
+ }
+
+ /** Makes a tag value given a field number and wire type. */
+ static int makeTag(final int fieldNumber, final int wireType) {
+ return (fieldNumber << TAG_TYPE_BITS) | wireType;
+ }
+
+ /**
+ * Lite equivalent to {@link Descriptors.FieldDescriptor.JavaType}. This is
+ * only here to support the lite runtime and should not be used by users.
+ */
+ public enum JavaType {
+ INT(0),
+ LONG(0L),
+ FLOAT(0F),
+ DOUBLE(0D),
+ BOOLEAN(false),
+ STRING(""),
+ BYTE_STRING(ByteString.EMPTY),
+ ENUM(null),
+ MESSAGE(null);
+
+ JavaType(final Object defaultDefault) {
+ this.defaultDefault = defaultDefault;
+ }
+
+ /**
+ * The default default value for fields of this type, if it's a primitive
+ * type.
+ */
+ Object getDefaultDefault() {
+ return defaultDefault;
+ }
+
+ private final Object defaultDefault;
+ }
+
+ /**
+ * Lite equivalent to {@link Descriptors.FieldDescriptor.Type}. This is
+ * only here to support the lite runtime and should not be used by users.
+ */
+ public enum FieldType {
+ DOUBLE (JavaType.DOUBLE , WIRETYPE_FIXED64 ),
+ FLOAT (JavaType.FLOAT , WIRETYPE_FIXED32 ),
+ INT64 (JavaType.LONG , WIRETYPE_VARINT ),
+ UINT64 (JavaType.LONG , WIRETYPE_VARINT ),
+ INT32 (JavaType.INT , WIRETYPE_VARINT ),
+ FIXED64 (JavaType.LONG , WIRETYPE_FIXED64 ),
+ FIXED32 (JavaType.INT , WIRETYPE_FIXED32 ),
+ BOOL (JavaType.BOOLEAN , WIRETYPE_VARINT ),
+ STRING (JavaType.STRING , WIRETYPE_LENGTH_DELIMITED) {
+ @Override
+ public boolean isPackable() {
+ return false; }
+ },
+ GROUP (JavaType.MESSAGE , WIRETYPE_START_GROUP ) {
+ @Override
+ public boolean isPackable() {
+ return false; }
+ },
+ MESSAGE (JavaType.MESSAGE , WIRETYPE_LENGTH_DELIMITED) {
+ @Override
+ public boolean isPackable() {
+ return false; }
+ },
+ BYTES (JavaType.BYTE_STRING, WIRETYPE_LENGTH_DELIMITED) {
+ @Override
+ public boolean isPackable() {
+ return false; }
+ },
+ UINT32 (JavaType.INT , WIRETYPE_VARINT ),
+ ENUM (JavaType.ENUM , WIRETYPE_VARINT ),
+ SFIXED32(JavaType.INT , WIRETYPE_FIXED32 ),
+ SFIXED64(JavaType.LONG , WIRETYPE_FIXED64 ),
+ SINT32 (JavaType.INT , WIRETYPE_VARINT ),
+ SINT64 (JavaType.LONG , WIRETYPE_VARINT );
+
+ FieldType(final JavaType javaType, final int wireType) {
+ this.javaType = javaType;
+ this.wireType = wireType;
+ }
+
+ private final JavaType javaType;
+ private final int wireType;
+
+ public JavaType getJavaType() { return javaType; }
+ public int getWireType() { return wireType; }
+
+ public boolean isPackable() { return true; }
+ }
+
+ // Field numbers for fields in MessageSet wire format.
+ static final int MESSAGE_SET_ITEM = 1;
+ static final int MESSAGE_SET_TYPE_ID = 2;
+ static final int MESSAGE_SET_MESSAGE = 3;
+
+ // Tag numbers.
+ static final int MESSAGE_SET_ITEM_TAG =
+ makeTag(MESSAGE_SET_ITEM, WIRETYPE_START_GROUP);
+ static final int MESSAGE_SET_ITEM_END_TAG =
+ makeTag(MESSAGE_SET_ITEM, WIRETYPE_END_GROUP);
+ static final int MESSAGE_SET_TYPE_ID_TAG =
+ makeTag(MESSAGE_SET_TYPE_ID, WIRETYPE_VARINT);
+ static final int MESSAGE_SET_MESSAGE_TAG =
+ makeTag(MESSAGE_SET_MESSAGE, WIRETYPE_LENGTH_DELIMITED);
+
+ /**
+ * Validation level for handling incoming string field data which potentially
+ * contain non-UTF8 bytes.
+ */
+ enum Utf8Validation {
+ /** Eagerly parses to String; silently accepts invalid UTF8 bytes. */
+ LOOSE {
+ @Override
+ Object readString(CodedInputStream input) throws IOException {
+ return input.readString();
+ }
+ },
+ /** Eagerly parses to String; throws an IOException on invalid bytes. */
+ STRICT {
+ @Override
+ Object readString(CodedInputStream input) throws IOException {
+ return input.readStringRequireUtf8();
+ }
+ },
+ /** Keep data as ByteString; validation/conversion to String is lazy. */
+ LAZY {
+ @Override
+ Object readString(CodedInputStream input) throws IOException {
+ return input.readBytes();
+ }
+ };
+
+ /** Read a string field from the input with the proper UTF8 validation. */
+ abstract Object readString(CodedInputStream input) throws IOException;
+ }
+
+ /**
+ * Read a field of any primitive type for immutable messages from a
+ * CodedInputStream. Enums, groups, and embedded messages are not handled by
+ * this method.
+ *
+ * @param input The stream from which to read.
+ * @param type Declared type of the field.
+ * @param utf8Validation Different string UTF8 validation level for handling
+ * string fields.
+ * @return An object representing the field's value, of the exact
+ * type which would be returned by
+ * {@link Message#getField(Descriptors.FieldDescriptor)} for
+ * this field.
+ */
+ static Object readPrimitiveField(
+ CodedInputStream input,
+ FieldType type,
+ Utf8Validation utf8Validation) throws IOException {
+ switch (type) {
+ case DOUBLE : return input.readDouble ();
+ case FLOAT : return input.readFloat ();
+ case INT64 : return input.readInt64 ();
+ case UINT64 : return input.readUInt64 ();
+ case INT32 : return input.readInt32 ();
+ case FIXED64 : return input.readFixed64 ();
+ case FIXED32 : return input.readFixed32 ();
+ case BOOL : return input.readBool ();
+ case BYTES : return input.readBytes ();
+ case UINT32 : return input.readUInt32 ();
+ case SFIXED32: return input.readSFixed32();
+ case SFIXED64: return input.readSFixed64();
+ case SINT32 : return input.readSInt32 ();
+ case SINT64 : return input.readSInt64 ();
+
+ case STRING : return utf8Validation.readString(input);
+ case GROUP:
+ throw new IllegalArgumentException(
+ "readPrimitiveField() cannot handle nested groups.");
+ case MESSAGE:
+ throw new IllegalArgumentException(
+ "readPrimitiveField() cannot handle embedded messages.");
+ case ENUM:
+ // We don't handle enums because we don't know what to do if the
+ // value is not recognized.
+ throw new IllegalArgumentException(
+ "readPrimitiveField() cannot handle enums.");
+ }
+
+ throw new RuntimeException(
+ "There is no way to get here, but the compiler thinks otherwise.");
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java
new file mode 100644
index 0000000000..622e36a413
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/AbstractMessageTest.java
@@ -0,0 +1,549 @@
+// 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.FieldDescriptor;
+import protobuf_unittest.UnittestOptimizeFor.TestOptimizedForSize;
+import protobuf_unittest.UnittestProto;
+import protobuf_unittest.UnittestProto.ForeignMessage;
+import protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestPackedTypes;
+import protobuf_unittest.UnittestProto.TestRequired;
+import protobuf_unittest.UnittestProto.TestRequiredForeign;
+import protobuf_unittest.UnittestProto.TestUnpackedTypes;
+import java.util.Map;
+import junit.framework.TestCase;
+
+/**
+ * Unit test for {@link AbstractMessage}.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class AbstractMessageTest extends TestCase {
+ /**
+ * Extends AbstractMessage and wraps some other message object. The methods
+ * of the Message interface which aren't explicitly implemented by
+ * AbstractMessage are forwarded to the wrapped object. This allows us to
+ * test that AbstractMessage's implementations work even if the wrapped
+ * object does not use them.
+ */
+ private static class AbstractMessageWrapper extends AbstractMessage {
+ private final Message wrappedMessage;
+
+ public AbstractMessageWrapper(Message wrappedMessage) {
+ this.wrappedMessage = wrappedMessage;
+ }
+
+ @Override
+ public Descriptors.Descriptor getDescriptorForType() {
+ return wrappedMessage.getDescriptorForType();
+ }
+ @Override
+ public AbstractMessageWrapper getDefaultInstanceForType() {
+ return new AbstractMessageWrapper(
+ wrappedMessage.getDefaultInstanceForType());
+ }
+ @Override
+ public Map<Descriptors.FieldDescriptor, Object> getAllFields() {
+ return wrappedMessage.getAllFields();
+ }
+ @Override
+ public boolean hasField(Descriptors.FieldDescriptor field) {
+ return wrappedMessage.hasField(field);
+ }
+ @Override
+ public Object getField(Descriptors.FieldDescriptor field) {
+ return wrappedMessage.getField(field);
+ }
+ @Override
+ public int getRepeatedFieldCount(Descriptors.FieldDescriptor field) {
+ return wrappedMessage.getRepeatedFieldCount(field);
+ }
+ @Override
+ public Object getRepeatedField(Descriptors.FieldDescriptor field, int index) {
+ return wrappedMessage.getRepeatedField(field, index);
+ }
+ @Override
+ public UnknownFieldSet getUnknownFields() {
+ return wrappedMessage.getUnknownFields();
+ }
+ @Override
+ public Builder newBuilderForType() {
+ return new Builder(wrappedMessage.newBuilderForType());
+ }
+ @Override
+ public Builder toBuilder() {
+ return new Builder(wrappedMessage.toBuilder());
+ }
+
+ static class Builder extends AbstractMessage.Builder<Builder> {
+ private final Message.Builder wrappedBuilder;
+
+ public Builder(Message.Builder wrappedBuilder) {
+ this.wrappedBuilder = wrappedBuilder;
+ }
+
+ @Override
+ public AbstractMessageWrapper build() {
+ return new AbstractMessageWrapper(wrappedBuilder.build());
+ }
+ @Override
+ public AbstractMessageWrapper buildPartial() {
+ return new AbstractMessageWrapper(wrappedBuilder.buildPartial());
+ }
+ @Override
+ public Builder clone() {
+ return new Builder(wrappedBuilder.clone());
+ }
+ @Override
+ public boolean isInitialized() {
+ return clone().buildPartial().isInitialized();
+ }
+ @Override
+ public Descriptors.Descriptor getDescriptorForType() {
+ return wrappedBuilder.getDescriptorForType();
+ }
+ @Override
+ public AbstractMessageWrapper getDefaultInstanceForType() {
+ return new AbstractMessageWrapper(
+ wrappedBuilder.getDefaultInstanceForType());
+ }
+ @Override
+ public Map<Descriptors.FieldDescriptor, Object> getAllFields() {
+ return wrappedBuilder.getAllFields();
+ }
+ @Override
+ public Builder newBuilderForField(Descriptors.FieldDescriptor field) {
+ return new Builder(wrappedBuilder.newBuilderForField(field));
+ }
+ @Override
+ public boolean hasField(Descriptors.FieldDescriptor field) {
+ return wrappedBuilder.hasField(field);
+ }
+ @Override
+ public Object getField(Descriptors.FieldDescriptor field) {
+ return wrappedBuilder.getField(field);
+ }
+ @Override
+ public Builder setField(Descriptors.FieldDescriptor field, Object value) {
+ wrappedBuilder.setField(field, value);
+ return this;
+ }
+ @Override
+ public Builder clearField(Descriptors.FieldDescriptor field) {
+ wrappedBuilder.clearField(field);
+ return this;
+ }
+ @Override
+ public int getRepeatedFieldCount(Descriptors.FieldDescriptor field) {
+ return wrappedBuilder.getRepeatedFieldCount(field);
+ }
+ @Override
+ public Object getRepeatedField(Descriptors.FieldDescriptor field, int index) {
+ return wrappedBuilder.getRepeatedField(field, index);
+ }
+ @Override
+ public Builder setRepeatedField(Descriptors.FieldDescriptor field, int index, Object value) {
+ wrappedBuilder.setRepeatedField(field, index, value);
+ return this;
+ }
+ @Override
+ public Builder addRepeatedField(Descriptors.FieldDescriptor field, Object value) {
+ wrappedBuilder.addRepeatedField(field, value);
+ return this;
+ }
+ @Override
+ public UnknownFieldSet getUnknownFields() {
+ return wrappedBuilder.getUnknownFields();
+ }
+ @Override
+ public Builder setUnknownFields(UnknownFieldSet unknownFields) {
+ wrappedBuilder.setUnknownFields(unknownFields);
+ return this;
+ }
+ @Override
+ public Message.Builder getFieldBuilder(FieldDescriptor field) {
+ return wrappedBuilder.getFieldBuilder(field);
+ }
+ }
+ @Override
+ public Parser<? extends Message> getParserForType() {
+ return wrappedMessage.getParserForType();
+ }
+ }
+
+ // =================================================================
+
+ TestUtil.ReflectionTester reflectionTester =
+ new TestUtil.ReflectionTester(TestAllTypes.getDescriptor(), null);
+
+ TestUtil.ReflectionTester extensionsReflectionTester =
+ new TestUtil.ReflectionTester(TestAllExtensions.getDescriptor(),
+ TestUtil.getExtensionRegistry());
+
+ public void testClear() throws Exception {
+ AbstractMessageWrapper message =
+ new AbstractMessageWrapper.Builder(
+ TestAllTypes.newBuilder(TestUtil.getAllSet()))
+ .clear().build();
+ TestUtil.assertClear((TestAllTypes) message.wrappedMessage);
+ }
+
+ public void testCopy() throws Exception {
+ AbstractMessageWrapper message =
+ new AbstractMessageWrapper.Builder(TestAllTypes.newBuilder())
+ .mergeFrom(TestUtil.getAllSet()).build();
+ TestUtil.assertAllFieldsSet((TestAllTypes) message.wrappedMessage);
+ }
+
+ public void testSerializedSize() throws Exception {
+ TestAllTypes message = TestUtil.getAllSet();
+ Message abstractMessage = new AbstractMessageWrapper(TestUtil.getAllSet());
+
+ assertEquals(message.getSerializedSize(),
+ abstractMessage.getSerializedSize());
+ }
+
+ public void testSerialization() throws Exception {
+ Message abstractMessage = new AbstractMessageWrapper(TestUtil.getAllSet());
+
+ TestUtil.assertAllFieldsSet(
+ TestAllTypes.parseFrom(abstractMessage.toByteString()));
+
+ assertEquals(TestUtil.getAllSet().toByteString(),
+ abstractMessage.toByteString());
+ }
+
+ public void testParsing() throws Exception {
+ AbstractMessageWrapper.Builder builder =
+ new AbstractMessageWrapper.Builder(TestAllTypes.newBuilder());
+ AbstractMessageWrapper message =
+ builder.mergeFrom(TestUtil.getAllSet().toByteString()).build();
+ TestUtil.assertAllFieldsSet((TestAllTypes) message.wrappedMessage);
+ }
+
+ public void testParsingUninitialized() throws Exception {
+ TestRequiredForeign.Builder builder = TestRequiredForeign.newBuilder();
+ builder.getOptionalMessageBuilder().setDummy2(10);
+ ByteString bytes = builder.buildPartial().toByteString();
+ Message.Builder abstractMessageBuilder =
+ new AbstractMessageWrapper.Builder(TestRequiredForeign.newBuilder());
+ // mergeFrom() should not throw initialization error.
+ abstractMessageBuilder.mergeFrom(bytes).buildPartial();
+ try {
+ abstractMessageBuilder.mergeFrom(bytes).build();
+ fail();
+ } catch (UninitializedMessageException ex) {
+ // pass
+ }
+
+ // test DynamicMessage directly.
+ Message.Builder dynamicMessageBuilder = DynamicMessage.newBuilder(
+ TestRequiredForeign.getDescriptor());
+ // mergeFrom() should not throw initialization error.
+ dynamicMessageBuilder.mergeFrom(bytes).buildPartial();
+ try {
+ dynamicMessageBuilder.mergeFrom(bytes).build();
+ fail();
+ } catch (UninitializedMessageException ex) {
+ // pass
+ }
+ }
+
+ public void testPackedSerialization() throws Exception {
+ Message abstractMessage =
+ new AbstractMessageWrapper(TestUtil.getPackedSet());
+
+ TestUtil.assertPackedFieldsSet(
+ TestPackedTypes.parseFrom(abstractMessage.toByteString()));
+
+ assertEquals(TestUtil.getPackedSet().toByteString(),
+ abstractMessage.toByteString());
+ }
+
+ public void testPackedParsing() throws Exception {
+ AbstractMessageWrapper.Builder builder =
+ new AbstractMessageWrapper.Builder(TestPackedTypes.newBuilder());
+ AbstractMessageWrapper message =
+ builder.mergeFrom(TestUtil.getPackedSet().toByteString()).build();
+ TestUtil.assertPackedFieldsSet((TestPackedTypes) message.wrappedMessage);
+ }
+
+ public void testUnpackedSerialization() throws Exception {
+ Message abstractMessage =
+ new AbstractMessageWrapper(TestUtil.getUnpackedSet());
+
+ TestUtil.assertUnpackedFieldsSet(
+ TestUnpackedTypes.parseFrom(abstractMessage.toByteString()));
+
+ assertEquals(TestUtil.getUnpackedSet().toByteString(),
+ abstractMessage.toByteString());
+ }
+
+ public void testParsePackedToUnpacked() throws Exception {
+ AbstractMessageWrapper.Builder builder =
+ new AbstractMessageWrapper.Builder(TestUnpackedTypes.newBuilder());
+ AbstractMessageWrapper message =
+ builder.mergeFrom(TestUtil.getPackedSet().toByteString()).build();
+ TestUtil.assertUnpackedFieldsSet(
+ (TestUnpackedTypes) message.wrappedMessage);
+ }
+
+ public void testParseUnpackedToPacked() throws Exception {
+ AbstractMessageWrapper.Builder builder =
+ new AbstractMessageWrapper.Builder(TestPackedTypes.newBuilder());
+ AbstractMessageWrapper message =
+ builder.mergeFrom(TestUtil.getUnpackedSet().toByteString()).build();
+ TestUtil.assertPackedFieldsSet((TestPackedTypes) message.wrappedMessage);
+ }
+
+ public void testUnpackedParsing() throws Exception {
+ AbstractMessageWrapper.Builder builder =
+ new AbstractMessageWrapper.Builder(TestUnpackedTypes.newBuilder());
+ AbstractMessageWrapper message =
+ builder.mergeFrom(TestUtil.getUnpackedSet().toByteString()).build();
+ TestUtil.assertUnpackedFieldsSet(
+ (TestUnpackedTypes) message.wrappedMessage);
+ }
+
+ public void testOptimizedForSize() throws Exception {
+ // We're mostly only checking that this class was compiled successfully.
+ TestOptimizedForSize message =
+ TestOptimizedForSize.newBuilder().setI(1).build();
+ message = TestOptimizedForSize.parseFrom(message.toByteString());
+ assertEquals(2, message.getSerializedSize());
+ }
+
+ // -----------------------------------------------------------------
+ // Tests for isInitialized().
+
+ private static final TestRequired TEST_REQUIRED_UNINITIALIZED =
+ TestRequired.getDefaultInstance();
+ private static final TestRequired TEST_REQUIRED_INITIALIZED =
+ TestRequired.newBuilder().setA(1).setB(2).setC(3).build();
+
+ public void testIsInitialized() throws Exception {
+ TestRequired.Builder builder = TestRequired.newBuilder();
+ AbstractMessageWrapper.Builder abstractBuilder =
+ new AbstractMessageWrapper.Builder(builder);
+
+ assertFalse(abstractBuilder.isInitialized());
+ assertEquals("a, b, c", abstractBuilder.getInitializationErrorString());
+ builder.setA(1);
+ assertFalse(abstractBuilder.isInitialized());
+ assertEquals("b, c", abstractBuilder.getInitializationErrorString());
+ builder.setB(1);
+ assertFalse(abstractBuilder.isInitialized());
+ assertEquals("c", abstractBuilder.getInitializationErrorString());
+ builder.setC(1);
+ assertTrue(abstractBuilder.isInitialized());
+ assertEquals("", abstractBuilder.getInitializationErrorString());
+ }
+
+ public void testForeignIsInitialized() throws Exception {
+ TestRequiredForeign.Builder builder = TestRequiredForeign.newBuilder();
+ AbstractMessageWrapper.Builder abstractBuilder =
+ new AbstractMessageWrapper.Builder(builder);
+
+ assertTrue(abstractBuilder.isInitialized());
+ assertEquals("", abstractBuilder.getInitializationErrorString());
+
+ builder.setOptionalMessage(TEST_REQUIRED_UNINITIALIZED);
+ assertFalse(abstractBuilder.isInitialized());
+ assertEquals(
+ "optional_message.a, optional_message.b, optional_message.c",
+ abstractBuilder.getInitializationErrorString());
+
+ builder.setOptionalMessage(TEST_REQUIRED_INITIALIZED);
+ assertTrue(abstractBuilder.isInitialized());
+ assertEquals("", abstractBuilder.getInitializationErrorString());
+
+ builder.addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED);
+ assertFalse(abstractBuilder.isInitialized());
+ assertEquals(
+ "repeated_message[0].a, repeated_message[0].b, repeated_message[0].c",
+ abstractBuilder.getInitializationErrorString());
+
+ builder.setRepeatedMessage(0, TEST_REQUIRED_INITIALIZED);
+ assertTrue(abstractBuilder.isInitialized());
+ assertEquals("", abstractBuilder.getInitializationErrorString());
+ }
+
+ // -----------------------------------------------------------------
+ // Tests for mergeFrom
+
+ static final TestAllTypes MERGE_SOURCE =
+ TestAllTypes.newBuilder()
+ .setOptionalInt32(1)
+ .setOptionalString("foo")
+ .setOptionalForeignMessage(ForeignMessage.getDefaultInstance())
+ .addRepeatedString("bar")
+ .build();
+
+ static final TestAllTypes MERGE_DEST =
+ TestAllTypes.newBuilder()
+ .setOptionalInt64(2)
+ .setOptionalString("baz")
+ .setOptionalForeignMessage(ForeignMessage.newBuilder().setC(3).build())
+ .addRepeatedString("qux")
+ .build();
+
+ static final String MERGE_RESULT_TEXT =
+ "optional_int32: 1\n" +
+ "optional_int64: 2\n" +
+ "optional_string: \"foo\"\n" +
+ "optional_foreign_message {\n" +
+ " c: 3\n" +
+ "}\n" +
+ "repeated_string: \"qux\"\n" +
+ "repeated_string: \"bar\"\n";
+
+ public void testMergeFrom() throws Exception {
+ AbstractMessageWrapper result =
+ new AbstractMessageWrapper.Builder(
+ TestAllTypes.newBuilder(MERGE_DEST))
+ .mergeFrom(MERGE_SOURCE).build();
+
+ assertEquals(MERGE_RESULT_TEXT, result.toString());
+ }
+
+ // -----------------------------------------------------------------
+ // Tests for equals and hashCode
+
+ public void testEqualsAndHashCode() throws Exception {
+ TestAllTypes a = TestUtil.getAllSet();
+ TestAllTypes b = TestAllTypes.newBuilder().build();
+ TestAllTypes c = TestAllTypes.newBuilder(b).addRepeatedString("x").build();
+ TestAllTypes d = TestAllTypes.newBuilder(c).addRepeatedString("y").build();
+ TestAllExtensions e = TestUtil.getAllExtensionsSet();
+ TestAllExtensions f = TestAllExtensions.newBuilder(e)
+ .addExtension(UnittestProto.repeatedInt32Extension, 999).build();
+
+ checkEqualsIsConsistent(a);
+ checkEqualsIsConsistent(b);
+ checkEqualsIsConsistent(c);
+ checkEqualsIsConsistent(d);
+ checkEqualsIsConsistent(e);
+ checkEqualsIsConsistent(f);
+
+ checkNotEqual(a, b);
+ checkNotEqual(a, c);
+ checkNotEqual(a, d);
+ checkNotEqual(a, e);
+ checkNotEqual(a, f);
+
+ checkNotEqual(b, c);
+ checkNotEqual(b, d);
+ checkNotEqual(b, e);
+ checkNotEqual(b, f);
+
+ checkNotEqual(c, d);
+ checkNotEqual(c, e);
+ checkNotEqual(c, f);
+
+ checkNotEqual(d, e);
+ checkNotEqual(d, f);
+
+ checkNotEqual(e, f);
+
+ // Deserializing into the TestEmptyMessage such that every field
+ // is an {@link UnknownFieldSet.Field}.
+ UnittestProto.TestEmptyMessage eUnknownFields =
+ UnittestProto.TestEmptyMessage.parseFrom(e.toByteArray());
+ UnittestProto.TestEmptyMessage fUnknownFields =
+ UnittestProto.TestEmptyMessage.parseFrom(f.toByteArray());
+ checkNotEqual(eUnknownFields, fUnknownFields);
+ checkEqualsIsConsistent(eUnknownFields);
+ checkEqualsIsConsistent(fUnknownFields);
+
+ // Subsequent reconstitutions should be identical
+ UnittestProto.TestEmptyMessage eUnknownFields2 =
+ UnittestProto.TestEmptyMessage.parseFrom(e.toByteArray());
+ checkEqualsIsConsistent(eUnknownFields, eUnknownFields2);
+ }
+
+ /**
+ * Asserts that the given proto has symmetric equals and hashCode methods.
+ */
+ private void checkEqualsIsConsistent(Message message) {
+ // Object should be equal to itself.
+ assertEquals(message, message);
+
+ // Object should be equal to a dynamic copy of itself.
+ DynamicMessage dynamic = DynamicMessage.newBuilder(message).build();
+ checkEqualsIsConsistent(message, dynamic);
+ }
+
+ /**
+ * Asserts that the given protos are equal and have the same hash code.
+ */
+ private void checkEqualsIsConsistent(Message message1, Message message2) {
+ assertEquals(message1, message2);
+ assertEquals(message2, message1);
+ assertEquals(message2.hashCode(), message1.hashCode());
+ }
+
+ /**
+ * Asserts that the given protos are not equal and have different hash codes.
+ *
+ * @warning It's valid for non-equal objects to have the same hash code, so
+ * this test is stricter than it needs to be. However, this should happen
+ * relatively rarely.
+ */
+ private void checkNotEqual(Message m1, Message m2) {
+ String equalsError = String.format("%s should not be equal to %s", m1, m2);
+ assertFalse(equalsError, m1.equals(m2));
+ assertFalse(equalsError, m2.equals(m1));
+
+ assertFalse(
+ String.format("%s should have a different hash code from %s", m1, m2),
+ m1.hashCode() == m2.hashCode());
+ }
+
+ public void testCheckByteStringIsUtf8OnUtf8() {
+ ByteString byteString = ByteString.copyFromUtf8("some text");
+ AbstractMessageLite.checkByteStringIsUtf8(byteString);
+ // No exception thrown.
+ }
+
+ public void testCheckByteStringIsUtf8OnNonUtf8() {
+ ByteString byteString =
+ ByteString.copyFrom(new byte[]{(byte) 0x80}); // A lone continuation byte.
+ try {
+ AbstractMessageLite.checkByteStringIsUtf8(byteString);
+ fail("Expected AbstractMessageLite.checkByteStringIsUtf8 to throw IllegalArgumentException");
+ } catch (IllegalArgumentException exception) {
+ assertEquals("Byte string is not UTF-8.", exception.getMessage());
+ }
+ }
+
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/AnyTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/AnyTest.java
new file mode 100644
index 0000000000..cf91ed91c6
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/AnyTest.java
@@ -0,0 +1,137 @@
+// 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 any_test.AnyTestProto.TestAny;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for Any message.
+ */
+public class AnyTest extends TestCase {
+ public void testAnyGeneratedApi() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ TestAllTypes message = builder.build();
+
+ TestAny container = TestAny.newBuilder()
+ .setValue(Any.pack(message)).build();
+
+ assertTrue(container.getValue().is(TestAllTypes.class));
+ assertFalse(container.getValue().is(TestAny.class));
+
+ TestAllTypes result = container.getValue().unpack(TestAllTypes.class);
+ TestUtil.assertAllFieldsSet(result);
+
+
+ // Unpacking to a wrong type will throw an exception.
+ try {
+ TestAny wrongMessage = container.getValue().unpack(TestAny.class);
+ fail("Exception is expected.");
+ } catch (InvalidProtocolBufferException e) {
+ // expected.
+ }
+
+ // Test that unpacking throws an exception if parsing fails.
+ TestAny.Builder containerBuilder = container.toBuilder();
+ containerBuilder.getValueBuilder().setValue(
+ ByteString.copyFrom(new byte[]{0x11}));
+ container = containerBuilder.build();
+ try {
+ TestAllTypes parsingFailed = container.getValue().unpack(TestAllTypes.class);
+ fail("Exception is expected.");
+ } catch (InvalidProtocolBufferException e) {
+ // expected.
+ }
+ }
+
+ public void testCustomTypeUrls() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ TestAllTypes message = builder.build();
+
+ TestAny container = TestAny.newBuilder()
+ .setValue(Any.pack(message, "xxx.com")).build();
+
+ assertEquals(
+ "xxx.com/" + TestAllTypes.getDescriptor().getFullName(),
+ container.getValue().getTypeUrl());
+
+ assertTrue(container.getValue().is(TestAllTypes.class));
+ assertFalse(container.getValue().is(TestAny.class));
+
+ TestAllTypes result = container.getValue().unpack(TestAllTypes.class);
+ TestUtil.assertAllFieldsSet(result);
+
+ container = TestAny.newBuilder()
+ .setValue(Any.pack(message, "yyy.com/")).build();
+
+ assertEquals(
+ "yyy.com/" + TestAllTypes.getDescriptor().getFullName(),
+ container.getValue().getTypeUrl());
+
+ assertTrue(container.getValue().is(TestAllTypes.class));
+ assertFalse(container.getValue().is(TestAny.class));
+
+ result = container.getValue().unpack(TestAllTypes.class);
+ TestUtil.assertAllFieldsSet(result);
+
+ container = TestAny.newBuilder()
+ .setValue(Any.pack(message, "")).build();
+
+ assertEquals(
+ "/" + TestAllTypes.getDescriptor().getFullName(),
+ container.getValue().getTypeUrl());
+
+ assertTrue(container.getValue().is(TestAllTypes.class));
+ assertFalse(container.getValue().is(TestAny.class));
+
+ result = container.getValue().unpack(TestAllTypes.class);
+ TestUtil.assertAllFieldsSet(result);
+ }
+
+ public void testCachedUnpackResult() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ TestAllTypes message = builder.build();
+
+ TestAny container = TestAny.newBuilder()
+ .setValue(Any.pack(message)).build();
+
+ assertTrue(container.getValue().is(TestAllTypes.class));
+
+ TestAllTypes result1 = container.getValue().unpack(TestAllTypes.class);
+ TestAllTypes result2 = container.getValue().unpack(TestAllTypes.class);
+ assertTrue(result1 == result2);
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java
new file mode 100644
index 0000000000..18132e9e03
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/BooleanArrayListTest.java
@@ -0,0 +1,458 @@
+// 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 static java.util.Arrays.asList;
+
+import java.util.Collections;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import junit.framework.TestCase;
+
+/**
+ * Tests for {@link BooleanArrayList}.
+ *
+ * @author dweis@google.com (Daniel Weis)
+ */
+public class BooleanArrayListTest extends TestCase {
+
+ private static final BooleanArrayList UNARY_LIST =
+ newImmutableBooleanArrayList(true);
+ private static final BooleanArrayList TERTIARY_LIST =
+ newImmutableBooleanArrayList(true, false, true);
+
+ private BooleanArrayList list;
+
+ @Override
+ protected void setUp() throws Exception {
+ list = new BooleanArrayList();
+ }
+
+ public void testEmptyListReturnsSameInstance() {
+ assertSame(BooleanArrayList.emptyList(), BooleanArrayList.emptyList());
+ }
+
+ public void testEmptyListIsImmutable() {
+ assertImmutable(BooleanArrayList.emptyList());
+ }
+
+ public void testMakeImmutable() {
+ list.addBoolean(true);
+ list.addBoolean(false);
+ list.addBoolean(true);
+ list.addBoolean(true);
+ list.makeImmutable();
+ assertImmutable(list);
+ }
+
+ public void testModificationWithIteration() {
+ list.addAll(asList(true, false, true, false));
+ Iterator<Boolean> iterator = list.iterator();
+ assertEquals(4, list.size());
+ assertEquals(true, (boolean) list.get(0));
+ assertEquals(true, (boolean) iterator.next());
+ list.set(0, true);
+ assertEquals(false, (boolean) iterator.next());
+
+ list.remove(0);
+ try {
+ iterator.next();
+ fail();
+ } catch (ConcurrentModificationException e) {
+ // expected
+ }
+
+ iterator = list.iterator();
+ list.add(0, false);
+ try {
+ iterator.next();
+ fail();
+ } catch (ConcurrentModificationException e) {
+ // expected
+ }
+ }
+
+ public void testGet() {
+ assertEquals(true, (boolean) TERTIARY_LIST.get(0));
+ assertEquals(false, (boolean) TERTIARY_LIST.get(1));
+ assertEquals(true, (boolean) TERTIARY_LIST.get(2));
+
+ try {
+ TERTIARY_LIST.get(-1);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ TERTIARY_LIST.get(3);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testGetBoolean() {
+ assertEquals(true, TERTIARY_LIST.getBoolean(0));
+ assertEquals(false, TERTIARY_LIST.getBoolean(1));
+ assertEquals(true, TERTIARY_LIST.getBoolean(2));
+
+ try {
+ TERTIARY_LIST.get(-1);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ TERTIARY_LIST.get(3);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testSize() {
+ assertEquals(0, BooleanArrayList.emptyList().size());
+ assertEquals(1, UNARY_LIST.size());
+ assertEquals(3, TERTIARY_LIST.size());
+
+ list.addBoolean(true);
+ list.addBoolean(false);
+ list.addBoolean(false);
+ list.addBoolean(false);
+ assertEquals(4, list.size());
+
+ list.remove(0);
+ assertEquals(3, list.size());
+
+ list.add(true);
+ assertEquals(4, list.size());
+ }
+
+ public void testSet() {
+ list.addBoolean(false);
+ list.addBoolean(false);
+
+ assertEquals(false, (boolean) list.set(0, true));
+ assertEquals(true, list.getBoolean(0));
+
+ assertEquals(false, (boolean) list.set(1, false));
+ assertEquals(false, list.getBoolean(1));
+
+ try {
+ list.set(-1, false);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.set(2, false);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testSetBoolean() {
+ list.addBoolean(true);
+ list.addBoolean(true);
+
+ assertEquals(true, list.setBoolean(0, false));
+ assertEquals(false, list.getBoolean(0));
+
+ assertEquals(true, list.setBoolean(1, false));
+ assertEquals(false, list.getBoolean(1));
+
+ try {
+ list.setBoolean(-1, false);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.setBoolean(2, false);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testAdd() {
+ assertEquals(0, list.size());
+
+ assertTrue(list.add(false));
+ assertEquals(asList(false), list);
+
+ assertTrue(list.add(true));
+ list.add(0, false);
+ assertEquals(asList(false, false, true), list);
+
+ list.add(0, true);
+ list.add(0, false);
+ // Force a resize by getting up to 11 elements.
+ for (int i = 0; i < 6; i++) {
+ list.add(i % 2 == 0);
+ }
+ assertEquals(
+ asList(false, true, false, false, true, true, false, true, false, true, false),
+ list);
+
+ try {
+ list.add(-1, true);
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.add(4, true);
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testAddBoolean() {
+ assertEquals(0, list.size());
+
+ list.addBoolean(false);
+ assertEquals(asList(false), list);
+
+ list.addBoolean(true);
+ assertEquals(asList(false, true), list);
+ }
+
+ public void testAddAll() {
+ assertEquals(0, list.size());
+
+ assertTrue(list.addAll(Collections.singleton(true)));
+ assertEquals(1, list.size());
+ assertEquals(true, (boolean) list.get(0));
+ assertEquals(true, list.getBoolean(0));
+
+ assertTrue(list.addAll(asList(false, true, false, true, false)));
+ assertEquals(asList(true, false, true, false, true, false), list);
+
+ assertTrue(list.addAll(TERTIARY_LIST));
+ assertEquals(asList(true, false, true, false, true, false, true, false, true), list);
+
+ assertFalse(list.addAll(Collections.<Boolean>emptyList()));
+ assertFalse(list.addAll(BooleanArrayList.emptyList()));
+ }
+
+ public void testRemove() {
+ list.addAll(TERTIARY_LIST);
+ assertEquals(true, (boolean) list.remove(0));
+ assertEquals(asList(false, true), list);
+
+ assertTrue(list.remove(Boolean.TRUE));
+ assertEquals(asList(false), list);
+
+ assertFalse(list.remove(Boolean.TRUE));
+ assertEquals(asList(false), list);
+
+ assertEquals(false, (boolean) list.remove(0));
+ assertEquals(asList(), list);
+
+ try {
+ list.remove(-1);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.remove(0);
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ private void assertImmutable(BooleanArrayList list) {
+
+ try {
+ list.add(true);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.add(0, true);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(Collections.<Boolean>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(Collections.singletonList(true));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(new BooleanArrayList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, Collections.singleton(true));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, Collections.<Boolean>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addBoolean(false);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.clear();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.remove(1);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.remove(new Object());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(Collections.<Boolean>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(Collections.singleton(Boolean.TRUE));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(Collections.<Boolean>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(Collections.singleton(Boolean.TRUE));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.set(0, false);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.setBoolean(0, false);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ private static BooleanArrayList newImmutableBooleanArrayList(boolean... elements) {
+ BooleanArrayList list = new BooleanArrayList();
+ for (boolean element : elements) {
+ list.addBoolean(element);
+ }
+ list.makeImmutable();
+ return list;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/BoundedByteStringTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/BoundedByteStringTest.java
new file mode 100644
index 0000000000..db10ee7483
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/BoundedByteStringTest.java
@@ -0,0 +1,100 @@
+// 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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * This class tests {@link BoundedByteString}, which extends {@link LiteralByteString},
+ * by inheriting the tests from {@link LiteralByteStringTest}. The only method which
+ * is strange enough that it needs to be overridden here is {@link #testToString()}.
+ *
+ * @author carlanton@google.com (Carl Haverl)
+ */
+public class BoundedByteStringTest extends LiteralByteStringTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ classUnderTest = "BoundedByteString";
+ byte[] sourceBytes = ByteStringTest.getTestBytes(2341, 11337766L);
+ int from = 100;
+ int to = sourceBytes.length - 100;
+ stringUnderTest = ByteString.copyFrom(sourceBytes).substring(from, to);
+ referenceBytes = new byte[to - from];
+ System.arraycopy(sourceBytes, from, referenceBytes, 0, to - from);
+ expectedHashCode = 727575887;
+ }
+
+ @Override
+ public void testToString() throws UnsupportedEncodingException {
+ String testString = "I love unicode \u1234\u5678 characters";
+ ByteString unicode = ByteString.wrap(testString.getBytes(Internal.UTF_8));
+ ByteString chopped = unicode.substring(2, unicode.size() - 6);
+ assertEquals(classUnderTest + ".substring() must have the expected type",
+ classUnderTest, getActualClassName(chopped));
+
+ String roundTripString = chopped.toString(UTF_8);
+ assertEquals(classUnderTest + " unicode bytes must match",
+ testString.substring(2, testString.length() - 6), roundTripString);
+ }
+
+ @Override
+ public void testCharsetToString() {
+ String testString = "I love unicode \u1234\u5678 characters";
+ ByteString unicode = ByteString.wrap(testString.getBytes(Internal.UTF_8));
+ ByteString chopped = unicode.substring(2, unicode.size() - 6);
+ assertEquals(classUnderTest + ".substring() must have the expected type",
+ classUnderTest, getActualClassName(chopped));
+
+ String roundTripString = chopped.toString(Internal.UTF_8);
+ assertEquals(classUnderTest + " unicode bytes must match",
+ testString.substring(2, testString.length() - 6), roundTripString);
+ }
+
+ @Override
+ public void testJavaSerialization() throws Exception {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(out);
+ oos.writeObject(stringUnderTest);
+ oos.close();
+ byte[] pickled = out.toByteArray();
+ InputStream in = new ByteArrayInputStream(pickled);
+ ObjectInputStream ois = new ObjectInputStream(in);
+ Object o = ois.readObject();
+ assertTrue("Didn't get a ByteString back", o instanceof ByteString);
+ assertEquals("Should get an equal ByteString back", stringUnderTest, o);
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ByteBufferWriterTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ByteBufferWriterTest.java
new file mode 100644
index 0000000000..6b1cfe78c1
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ByteBufferWriterTest.java
@@ -0,0 +1,80 @@
+// 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.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}.
+ */
+public class ByteBufferWriterTest extends TestCase {
+
+ public void testHeapBuffer() throws IOException {
+ // Test a small and large buffer.
+ testWrite(ByteBuffer.allocate(100));
+ testWrite(ByteBuffer.allocate(1024 * 100));
+ }
+
+ public void testDirectBuffer() throws IOException {
+ // Test a small and large buffer.
+ testWrite(ByteBuffer.allocateDirect(100));
+ testWrite(ByteBuffer.allocateDirect(1024 * 100));
+ }
+
+ private void testWrite(ByteBuffer buffer) throws IOException {
+ fillRandom(buffer);
+ ByteArrayOutputStream os = new ByteArrayOutputStream(buffer.remaining());
+ ByteBufferWriter.write(buffer, os);
+ assertEquals(0, buffer.position());
+ assertTrue(Arrays.equals(toArray(buffer), os.toByteArray()));
+ }
+
+ private void fillRandom(ByteBuffer buf) {
+ byte[] bytes = new byte[buf.remaining()];
+ new Random().nextBytes(bytes);
+ buf.put(bytes);
+ buf.flip();
+ return;
+ }
+
+ private byte[] toArray(ByteBuffer buf) {
+ int originalPosition = buf.position();
+ byte[] bytes = new byte[buf.remaining()];
+ buf.get(bytes);
+ buf.position(originalPosition);
+ return bytes;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ByteStringTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ByteStringTest.java
new file mode 100644
index 0000000000..be71f1f5a3
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ByteStringTest.java
@@ -0,0 +1,772 @@
+// 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.ByteString.Output;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.reflect.Field;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+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"
+ * tests.
+ *
+ * @author carlanton@google.com (Carl Haverl)
+ */
+public class ByteStringTest extends TestCase {
+
+ private static final Charset UTF_16 = Charset.forName("UTF-16");
+
+ static byte[] getTestBytes(int size, long seed) {
+ Random random = new Random(seed);
+ byte[] result = new byte[size];
+ random.nextBytes(result);
+ return result;
+ }
+
+ private byte[] getTestBytes(int size) {
+ return getTestBytes(size, 445566L);
+ }
+
+ private byte[] getTestBytes() {
+ return getTestBytes(1000);
+ }
+
+ // Compare the entire left array with a subset of the right array.
+ private boolean isArrayRange(byte[] left, byte[] right, int rightOffset, int length) {
+ boolean stillEqual = (left.length == length);
+ for (int i = 0; (stillEqual && i < length); ++i) {
+ stillEqual = (left[i] == right[rightOffset + i]);
+ }
+ return stillEqual;
+ }
+
+ // Returns true only if the given two arrays have identical contents.
+ private boolean isArray(byte[] left, byte[] right) {
+ return left.length == right.length && isArrayRange(left, right, 0, left.length);
+ }
+
+ public void testSubstring_BeginIndex() {
+ byte[] bytes = getTestBytes();
+ ByteString substring = ByteString.copyFrom(bytes).substring(500);
+ assertTrue("substring must contain the tail of the string",
+ isArrayRange(substring.toByteArray(), bytes, 500, bytes.length - 500));
+ }
+
+ public void testCopyFrom_BytesOffsetSize() {
+ byte[] bytes = getTestBytes();
+ ByteString byteString = ByteString.copyFrom(bytes, 500, 200);
+ assertTrue("copyFrom sub-range must contain the expected bytes",
+ isArrayRange(byteString.toByteArray(), bytes, 500, 200));
+ }
+
+ public void testCopyFrom_Bytes() {
+ byte[] bytes = getTestBytes();
+ ByteString byteString = ByteString.copyFrom(bytes);
+ assertTrue("copyFrom must contain the expected bytes",
+ isArray(byteString.toByteArray(), bytes));
+ }
+
+ public void testCopyFrom_ByteBufferSize() {
+ byte[] bytes = getTestBytes();
+ ByteBuffer byteBuffer = ByteBuffer.allocate(bytes.length);
+ byteBuffer.put(bytes);
+ byteBuffer.position(500);
+ ByteString byteString = ByteString.copyFrom(byteBuffer, 200);
+ assertTrue("copyFrom byteBuffer sub-range must contain the expected bytes",
+ isArrayRange(byteString.toByteArray(), bytes, 500, 200));
+ }
+
+ public void testCopyFrom_ByteBuffer() {
+ byte[] bytes = getTestBytes();
+ ByteBuffer byteBuffer = ByteBuffer.allocate(bytes.length);
+ byteBuffer.put(bytes);
+ byteBuffer.position(500);
+ ByteString byteString = ByteString.copyFrom(byteBuffer);
+ assertTrue("copyFrom byteBuffer sub-range must contain the expected bytes",
+ isArrayRange(byteString.toByteArray(), bytes, 500, bytes.length - 500));
+ }
+
+ public void testCopyFrom_StringEncoding() {
+ String testString = "I love unicode \u1234\u5678 characters";
+ ByteString byteString = ByteString.copyFrom(testString, UTF_16);
+ byte[] testBytes = testString.getBytes(UTF_16);
+ assertTrue("copyFrom string must respect the charset",
+ isArrayRange(byteString.toByteArray(), testBytes, 0, testBytes.length));
+ }
+
+ public void testCopyFrom_Utf8() {
+ String testString = "I love unicode \u1234\u5678 characters";
+ ByteString byteString = ByteString.copyFromUtf8(testString);
+ byte[] testBytes = testString.getBytes(Internal.UTF_8);
+ assertTrue("copyFromUtf8 string must respect the charset",
+ isArrayRange(byteString.toByteArray(), testBytes, 0, testBytes.length));
+ }
+
+ public void testCopyFrom_Iterable() {
+ byte[] testBytes = getTestBytes(77777, 113344L);
+ final List<ByteString> pieces = makeConcretePieces(testBytes);
+ // Call copyFrom() on a Collection
+ ByteString byteString = ByteString.copyFrom(pieces);
+ assertTrue("copyFrom a List must contain the expected bytes",
+ isArrayRange(byteString.toByteArray(), testBytes, 0, testBytes.length));
+ // Call copyFrom on an iteration that's not a collection
+ ByteString byteStringAlt = ByteString.copyFrom(new Iterable<ByteString>() {
+ @Override
+ public Iterator<ByteString> iterator() {
+ return pieces.iterator();
+ }
+ });
+ assertEquals("copyFrom from an Iteration must contain the expected bytes",
+ byteString, byteStringAlt);
+ }
+
+ public void testCopyTo_TargetOffset() {
+ byte[] bytes = getTestBytes();
+ ByteString byteString = ByteString.copyFrom(bytes);
+ byte[] target = new byte[bytes.length + 1000];
+ byteString.copyTo(target, 400);
+ assertTrue("copyFrom byteBuffer sub-range must contain the expected bytes",
+ isArrayRange(bytes, target, 400, bytes.length));
+ }
+
+ public void testReadFrom_emptyStream() throws IOException {
+ ByteString byteString =
+ ByteString.readFrom(new ByteArrayInputStream(new byte[0]));
+ assertSame("reading an empty stream must result in the EMPTY constant "
+ + "byte string", ByteString.EMPTY, byteString);
+ }
+
+ public void testReadFrom_smallStream() throws IOException {
+ assertReadFrom(getTestBytes(10));
+ }
+
+ public void testReadFrom_mutating() throws IOException {
+ byte[] capturedArray = null;
+ EvilInputStream eis = new EvilInputStream();
+ ByteString byteString = ByteString.readFrom(eis);
+
+ capturedArray = eis.capturedArray;
+ byte[] originalValue = byteString.toByteArray();
+ for (int x = 0; x < capturedArray.length; ++x) {
+ capturedArray[x] = (byte) 0;
+ }
+
+ byte[] newValue = byteString.toByteArray();
+ assertTrue("copyFrom byteBuffer must not grant access to underlying array",
+ Arrays.equals(originalValue, newValue));
+ }
+
+ // Tests sizes that are near the rope copy-out threshold.
+ public void testReadFrom_mediumStream() throws IOException {
+ assertReadFrom(getTestBytes(ByteString.CONCATENATE_BY_COPY_SIZE - 1));
+ assertReadFrom(getTestBytes(ByteString.CONCATENATE_BY_COPY_SIZE));
+ assertReadFrom(getTestBytes(ByteString.CONCATENATE_BY_COPY_SIZE + 1));
+ assertReadFrom(getTestBytes(200));
+ }
+
+ // Tests sizes that are over multi-segment rope threshold.
+ public void testReadFrom_largeStream() throws IOException {
+ assertReadFrom(getTestBytes(0x100));
+ assertReadFrom(getTestBytes(0x101));
+ assertReadFrom(getTestBytes(0x110));
+ assertReadFrom(getTestBytes(0x1000));
+ assertReadFrom(getTestBytes(0x1001));
+ assertReadFrom(getTestBytes(0x1010));
+ assertReadFrom(getTestBytes(0x10000));
+ assertReadFrom(getTestBytes(0x10001));
+ assertReadFrom(getTestBytes(0x10010));
+ }
+
+ // Tests sizes that are near the read buffer size.
+ public void testReadFrom_byteBoundaries() throws IOException {
+ final int min = ByteString.MIN_READ_FROM_CHUNK_SIZE;
+ final int max = ByteString.MAX_READ_FROM_CHUNK_SIZE;
+
+ assertReadFrom(getTestBytes(min - 1));
+ assertReadFrom(getTestBytes(min));
+ assertReadFrom(getTestBytes(min + 1));
+
+ assertReadFrom(getTestBytes(min * 2 - 1));
+ assertReadFrom(getTestBytes(min * 2));
+ assertReadFrom(getTestBytes(min * 2 + 1));
+
+ assertReadFrom(getTestBytes(min * 4 - 1));
+ assertReadFrom(getTestBytes(min * 4));
+ assertReadFrom(getTestBytes(min * 4 + 1));
+
+ assertReadFrom(getTestBytes(min * 8 - 1));
+ assertReadFrom(getTestBytes(min * 8));
+ assertReadFrom(getTestBytes(min * 8 + 1));
+
+ assertReadFrom(getTestBytes(max - 1));
+ assertReadFrom(getTestBytes(max));
+ assertReadFrom(getTestBytes(max + 1));
+
+ assertReadFrom(getTestBytes(max * 2 - 1));
+ assertReadFrom(getTestBytes(max * 2));
+ assertReadFrom(getTestBytes(max * 2 + 1));
+ }
+
+ // Tests that IOExceptions propagate through ByteString.readFrom().
+ public void testReadFrom_IOExceptions() {
+ try {
+ ByteString.readFrom(new FailStream());
+ fail("readFrom must throw the underlying IOException");
+
+ } catch (IOException e) {
+ assertEquals("readFrom must throw the expected exception",
+ "synthetic failure", e.getMessage());
+ }
+ }
+
+ // Tests that ByteString.readFrom works with streams that don't
+ // always fill their buffers.
+ public void testReadFrom_reluctantStream() throws IOException {
+ final byte[] data = getTestBytes(0x1000);
+
+ ByteString byteString = ByteString.readFrom(new ReluctantStream(data));
+ assertTrue("readFrom byte stream must contain the expected bytes",
+ isArray(byteString.toByteArray(), data));
+
+ // Same test as above, but with some specific chunk sizes.
+ assertReadFromReluctantStream(data, 100);
+ assertReadFromReluctantStream(data, 248);
+ assertReadFromReluctantStream(data, 249);
+ assertReadFromReluctantStream(data, 250);
+ assertReadFromReluctantStream(data, 251);
+ assertReadFromReluctantStream(data, 0x1000);
+ assertReadFromReluctantStream(data, 0x1001);
+ }
+
+ // Fails unless ByteString.readFrom reads the bytes correctly from a
+ // reluctant stream with the given chunkSize parameter.
+ private void assertReadFromReluctantStream(byte[] bytes, int chunkSize)
+ throws IOException {
+ ByteString b = ByteString.readFrom(new ReluctantStream(bytes), chunkSize);
+ assertTrue("readFrom byte stream must contain the expected bytes",
+ isArray(b.toByteArray(), bytes));
+ }
+
+ // Tests that ByteString.readFrom works with streams that implement
+ // available().
+ public void testReadFrom_available() throws IOException {
+ final byte[] data = getTestBytes(0x1001);
+
+ ByteString byteString = ByteString.readFrom(new AvailableStream(data));
+ assertTrue("readFrom byte stream must contain the expected bytes",
+ isArray(byteString.toByteArray(), data));
+ }
+
+ // Fails unless ByteString.readFrom reads the bytes correctly.
+ private void assertReadFrom(byte[] bytes) throws IOException {
+ ByteString byteString =
+ ByteString.readFrom(new ByteArrayInputStream(bytes));
+ assertTrue("readFrom byte stream must contain the expected bytes",
+ isArray(byteString.toByteArray(), bytes));
+ }
+
+ // A stream that fails when read.
+ private static final class FailStream extends InputStream {
+ @Override public int read() throws IOException {
+ throw new IOException("synthetic failure");
+ }
+ }
+
+ // A stream that simulates blocking by only producing 250 characters
+ // per call to read(byte[]).
+ private static class ReluctantStream extends InputStream {
+ protected final byte[] data;
+ protected int pos = 0;
+
+ public ReluctantStream(byte[] data) {
+ this.data = data;
+ }
+
+ @Override public int read() {
+ if (pos == data.length) {
+ return -1;
+ } else {
+ return data[pos++];
+ }
+ }
+
+ @Override public int read(byte[] buf) {
+ return read(buf, 0, buf.length);
+ }
+
+ @Override public int read(byte[] buf, int offset, int size) {
+ if (pos == data.length) {
+ return -1;
+ }
+ int count = Math.min(Math.min(size, data.length - pos), 250);
+ System.arraycopy(data, pos, buf, offset, count);
+ pos += count;
+ return count;
+ }
+ }
+
+ // Same as above, but also implements available().
+ private static final class AvailableStream extends ReluctantStream {
+ public AvailableStream(byte[] data) {
+ super(data);
+ }
+
+ @Override public int available() {
+ return Math.min(250, data.length - pos);
+ }
+ }
+
+ // A stream which exposes the byte array passed into read(byte[], int, int).
+ private static class EvilInputStream extends InputStream {
+ public byte[] capturedArray = null;
+
+ @Override
+ public int read(byte[] buf, int off, int len) {
+ if (capturedArray != null) {
+ return -1;
+ } else {
+ capturedArray = buf;
+ for (int x = 0; x < len; ++x) {
+ buf[x] = (byte) x;
+ }
+ return len;
+ }
+ }
+
+ @Override
+ public int read() {
+ // Purposefully do nothing.
+ return -1;
+ }
+ }
+
+ // A stream which exposes the byte array passed into write(byte[], int, int).
+ private static class EvilOutputStream extends OutputStream {
+ public byte[] capturedArray = null;
+
+ @Override
+ public void write(byte[] buf, int off, int len) {
+ if (capturedArray == null) {
+ capturedArray = buf;
+ }
+ }
+
+ @Override
+ public void write(int ignored) {
+ // Purposefully do nothing.
+ }
+ }
+
+ public void testToStringUtf8() {
+ String testString = "I love unicode \u1234\u5678 characters";
+ byte[] testBytes = testString.getBytes(Internal.UTF_8);
+ ByteString byteString = ByteString.copyFrom(testBytes);
+ assertEquals("copyToStringUtf8 must respect the charset",
+ testString, byteString.toStringUtf8());
+ }
+
+ public void testNewOutput_InitialCapacity() throws IOException {
+ byte[] bytes = getTestBytes();
+ ByteString.Output output = ByteString.newOutput(bytes.length + 100);
+ output.write(bytes);
+ ByteString byteString = output.toByteString();
+ assertTrue(
+ "String built from newOutput(int) must contain the expected bytes",
+ isArrayRange(bytes, byteString.toByteArray(), 0, bytes.length));
+ }
+
+ // Test newOutput() using a variety of buffer sizes and a variety of (fixed)
+ // write sizes
+ public void testNewOutput_ArrayWrite() {
+ byte[] bytes = getTestBytes();
+ int length = bytes.length;
+ int[] bufferSizes = {128, 256, length / 2, length - 1, length, length + 1,
+ 2 * length, 3 * length};
+ int[] writeSizes = {1, 4, 5, 7, 23, bytes.length};
+
+ for (int bufferSize : bufferSizes) {
+ for (int writeSize : writeSizes) {
+ // Test writing the entire output writeSize bytes at a time.
+ ByteString.Output output = ByteString.newOutput(bufferSize);
+ for (int i = 0; i < length; i += writeSize) {
+ output.write(bytes, i, Math.min(writeSize, length - i));
+ }
+ ByteString byteString = output.toByteString();
+ assertTrue("String built from newOutput() must contain the expected bytes",
+ isArrayRange(bytes, byteString.toByteArray(), 0, bytes.length));
+ }
+ }
+ }
+
+ // Test newOutput() using a variety of buffer sizes, but writing all the
+ // characters using write(byte);
+ public void testNewOutput_WriteChar() {
+ byte[] bytes = getTestBytes();
+ int length = bytes.length;
+ int[] bufferSizes = {0, 1, 128, 256, length / 2,
+ length - 1, length, length + 1,
+ 2 * length, 3 * length};
+ for (int bufferSize : bufferSizes) {
+ ByteString.Output output = ByteString.newOutput(bufferSize);
+ for (byte byteValue : bytes) {
+ output.write(byteValue);
+ }
+ ByteString byteString = output.toByteString();
+ assertTrue("String built from newOutput() must contain the expected bytes",
+ isArrayRange(bytes, byteString.toByteArray(), 0, bytes.length));
+ }
+ }
+
+ // Test newOutput() in which we write the bytes using a variety of methods
+ // and sizes, and in which we repeatedly call toByteString() in the middle.
+ public void testNewOutput_Mixed() {
+ Random rng = new Random(1);
+ byte[] bytes = getTestBytes();
+ int length = bytes.length;
+ int[] bufferSizes = {0, 1, 128, 256, length / 2,
+ length - 1, length, length + 1,
+ 2 * length, 3 * length};
+
+ for (int bufferSize : bufferSizes) {
+ // Test writing the entire output using a mixture of write sizes and
+ // methods;
+ ByteString.Output output = ByteString.newOutput(bufferSize);
+ int position = 0;
+ while (position < bytes.length) {
+ if (rng.nextBoolean()) {
+ int count = 1 + rng.nextInt(bytes.length - position);
+ output.write(bytes, position, count);
+ position += count;
+ } else {
+ output.write(bytes[position]);
+ position++;
+ }
+ assertEquals("size() returns the right value", position, output.size());
+ assertTrue("newOutput() substring must have correct bytes",
+ isArrayRange(output.toByteString().toByteArray(),
+ bytes, 0, position));
+ }
+ ByteString byteString = output.toByteString();
+ assertTrue("String built from newOutput() must contain the expected bytes",
+ isArrayRange(bytes, byteString.toByteArray(), 0, bytes.length));
+ }
+ }
+
+ public void testNewOutputEmpty() {
+ // Make sure newOutput() correctly builds empty byte strings
+ ByteString byteString = ByteString.newOutput().toByteString();
+ assertEquals(ByteString.EMPTY, byteString);
+ }
+
+ public void testNewOutput_Mutating() throws IOException {
+ Output os = ByteString.newOutput(5);
+ os.write(new byte[] {1, 2, 3, 4, 5});
+ EvilOutputStream eos = new EvilOutputStream();
+ os.writeTo(eos);
+ byte[] capturedArray = eos.capturedArray;
+ ByteString byteString = os.toByteString();
+ byte[] oldValue = byteString.toByteArray();
+ Arrays.fill(capturedArray, (byte) 0);
+ byte[] newValue = byteString.toByteArray();
+ assertTrue("Output must not provide access to the underlying byte array",
+ Arrays.equals(oldValue, newValue));
+ }
+
+ public void testNewCodedBuilder() throws IOException {
+ byte[] bytes = getTestBytes();
+ ByteString.CodedBuilder builder = ByteString.newCodedBuilder(bytes.length);
+ builder.getCodedOutput().writeRawBytes(bytes);
+ ByteString byteString = builder.build();
+ assertTrue("String built from newCodedBuilder() must contain the expected bytes",
+ isArrayRange(bytes, byteString.toByteArray(), 0, bytes.length));
+ }
+
+ public void testSubstringParity() {
+ byte[] bigBytes = getTestBytes(2048 * 1024, 113344L);
+ int start = 512 * 1024 - 3333;
+ int end = 512 * 1024 + 7777;
+ ByteString concreteSubstring = ByteString.copyFrom(bigBytes).substring(start, end);
+ boolean ok = true;
+ for (int i = start; ok && i < end; ++i) {
+ ok = (bigBytes[i] == concreteSubstring.byteAt(i - start));
+ }
+ assertTrue("Concrete substring didn't capture the right bytes", ok);
+
+ ByteString literalString = ByteString.copyFrom(bigBytes, start, end - start);
+ assertTrue("Substring must be equal to literal string",
+ concreteSubstring.equals(literalString));
+ assertEquals("Substring must have same hashcode as literal string",
+ literalString.hashCode(), concreteSubstring.hashCode());
+ }
+
+ public void testCompositeSubstring() {
+ byte[] referenceBytes = getTestBytes(77748, 113344L);
+
+ List<ByteString> pieces = makeConcretePieces(referenceBytes);
+ ByteString listString = ByteString.copyFrom(pieces);
+
+ int from = 1000;
+ int to = 40000;
+ ByteString compositeSubstring = listString.substring(from, to);
+ byte[] substringBytes = compositeSubstring.toByteArray();
+ boolean stillEqual = true;
+ for (int i = 0; stillEqual && i < to - from; ++i) {
+ stillEqual = referenceBytes[from + i] == substringBytes[i];
+ }
+ assertTrue("Substring must return correct bytes", stillEqual);
+
+ stillEqual = true;
+ for (int i = 0; stillEqual && i < to - from; ++i) {
+ stillEqual = referenceBytes[from + i] == compositeSubstring.byteAt(i);
+ }
+ assertTrue("Substring must support byteAt() correctly", stillEqual);
+
+ ByteString literalSubstring = ByteString.copyFrom(referenceBytes, from, to - from);
+ assertTrue("Composite substring must equal a literal substring over the same bytes",
+ compositeSubstring.equals(literalSubstring));
+ assertTrue("Literal substring must equal a composite substring over the same bytes",
+ literalSubstring.equals(compositeSubstring));
+
+ assertEquals("We must get the same hashcodes for composite and literal substrings",
+ literalSubstring.hashCode(), compositeSubstring.hashCode());
+
+ assertFalse("We can't be equal to a proper substring",
+ compositeSubstring.equals(literalSubstring.substring(0, literalSubstring.size() - 1)));
+ }
+
+ public void testCopyFromList() {
+ byte[] referenceBytes = getTestBytes(77748, 113344L);
+ ByteString literalString = ByteString.copyFrom(referenceBytes);
+
+ List<ByteString> pieces = makeConcretePieces(referenceBytes);
+ ByteString listString = ByteString.copyFrom(pieces);
+
+ assertTrue("Composite string must be equal to literal string",
+ listString.equals(literalString));
+ assertEquals("Composite string must have same hashcode as literal string",
+ literalString.hashCode(), listString.hashCode());
+ }
+
+ public void testConcat() {
+ byte[] referenceBytes = getTestBytes(77748, 113344L);
+ ByteString literalString = ByteString.copyFrom(referenceBytes);
+
+ List<ByteString> pieces = makeConcretePieces(referenceBytes);
+
+ Iterator<ByteString> iter = pieces.iterator();
+ ByteString concatenatedString = iter.next();
+ while (iter.hasNext()) {
+ concatenatedString = concatenatedString.concat(iter.next());
+ }
+
+ assertTrue("Concatenated string must be equal to literal string",
+ concatenatedString.equals(literalString));
+ assertEquals("Concatenated string must have same hashcode as literal string",
+ literalString.hashCode(), concatenatedString.hashCode());
+ }
+
+ /**
+ * Test the Rope implementation can deal with Empty nodes, even though we
+ * guard against them. See also {@link LiteralByteStringTest#testConcat_empty()}.
+ */
+ public void testConcat_empty() {
+ byte[] referenceBytes = getTestBytes(7748, 113344L);
+ ByteString literalString = ByteString.copyFrom(referenceBytes);
+
+ ByteString duo = RopeByteString.newInstanceForTest(literalString, literalString);
+ ByteString temp = RopeByteString.newInstanceForTest(
+ RopeByteString.newInstanceForTest(literalString, ByteString.EMPTY),
+ RopeByteString.newInstanceForTest(ByteString.EMPTY, literalString));
+ ByteString quintet = RopeByteString.newInstanceForTest(temp, ByteString.EMPTY);
+
+ assertTrue("String with concatenated nulls must equal simple concatenate",
+ duo.equals(quintet));
+ assertEquals("String with concatenated nulls have same hashcode as simple concatenate",
+ duo.hashCode(), quintet.hashCode());
+
+ ByteString.ByteIterator duoIter = duo.iterator();
+ ByteString.ByteIterator quintetIter = quintet.iterator();
+ boolean stillEqual = true;
+ while (stillEqual && quintetIter.hasNext()) {
+ stillEqual = (duoIter.nextByte() == quintetIter.nextByte());
+ }
+ assertTrue("We must get the same characters by iterating", stillEqual);
+ assertFalse("Iterator must be exhausted", duoIter.hasNext());
+ try {
+ duoIter.nextByte();
+ fail("Should have thrown an exception.");
+ } catch (NoSuchElementException e) {
+ // This is success
+ }
+ try {
+ quintetIter.nextByte();
+ fail("Should have thrown an exception.");
+ } catch (NoSuchElementException e) {
+ // This is success
+ }
+
+ // Test that even if we force empty strings in as rope leaves in this
+ // configuration, we always get a (possibly Bounded) LiteralByteString
+ // for a length 1 substring.
+ //
+ // It is possible, using the testing factory method to create deeply nested
+ // trees of empty leaves, to make a string that will fail this test.
+ for (int i = 1; i < duo.size(); ++i) {
+ assertTrue("Substrings of size() < 2 must not be RopeByteStrings",
+ duo.substring(i - 1, i) instanceof ByteString.LeafByteString);
+ }
+ for (int i = 1; i < quintet.size(); ++i) {
+ assertTrue("Substrings of size() < 2 must not be RopeByteStrings",
+ quintet.substring(i - 1, i) instanceof ByteString.LeafByteString);
+ }
+ }
+
+ public void testStartsWith() {
+ byte[] bytes = getTestBytes(1000, 1234L);
+ ByteString string = ByteString.copyFrom(bytes);
+ ByteString prefix = ByteString.copyFrom(bytes, 0, 500);
+ ByteString suffix = ByteString.copyFrom(bytes, 400, 600);
+ assertTrue(string.startsWith(ByteString.EMPTY));
+ assertTrue(string.startsWith(string));
+ assertTrue(string.startsWith(prefix));
+ assertFalse(string.startsWith(suffix));
+ assertFalse(prefix.startsWith(suffix));
+ assertFalse(suffix.startsWith(prefix));
+ assertFalse(ByteString.EMPTY.startsWith(prefix));
+ assertTrue(ByteString.EMPTY.startsWith(ByteString.EMPTY));
+ }
+
+ public void testEndsWith() {
+ byte[] bytes = getTestBytes(1000, 1234L);
+ ByteString string = ByteString.copyFrom(bytes);
+ ByteString prefix = ByteString.copyFrom(bytes, 0, 500);
+ ByteString suffix = ByteString.copyFrom(bytes, 400, 600);
+ assertTrue(string.endsWith(ByteString.EMPTY));
+ assertTrue(string.endsWith(string));
+ assertTrue(string.endsWith(suffix));
+ assertFalse(string.endsWith(prefix));
+ assertFalse(suffix.endsWith(prefix));
+ assertFalse(prefix.endsWith(suffix));
+ assertFalse(ByteString.EMPTY.endsWith(suffix));
+ assertTrue(ByteString.EMPTY.endsWith(ByteString.EMPTY));
+ }
+
+ static List<ByteString> makeConcretePieces(byte[] referenceBytes) {
+ List<ByteString> pieces = new ArrayList<ByteString>();
+ // Starting length should be small enough that we'll do some concatenating by
+ // copying if we just concatenate all these pieces together.
+ for (int start = 0, length = 16; start < referenceBytes.length; start += length) {
+ length = (length << 1) - 1;
+ if (start + length > referenceBytes.length) {
+ length = referenceBytes.length - start;
+ }
+ pieces.add(ByteString.copyFrom(referenceBytes, start, length));
+ }
+ return pieces;
+ }
+
+ private byte[] substringUsingWriteTo(
+ ByteString data, int offset, int length) throws IOException {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ data.writeTo(output, offset, length);
+ return output.toByteArray();
+ }
+
+ public void testWriteToOutputStream() throws Exception {
+ // Choose a size large enough so when two ByteStrings are concatenated they
+ // won't be merged into one byte array due to some optimizations.
+ final int dataSize = ByteString.CONCATENATE_BY_COPY_SIZE + 1;
+ byte[] data1 = new byte[dataSize];
+ for (int i = 0; i < data1.length; i++) {
+ data1[i] = (byte) 1;
+ }
+ data1[1] = (byte) 11;
+ // Test LiteralByteString.writeTo(OutputStream,int,int)
+ ByteString left = ByteString.wrap(data1);
+ byte[] result = substringUsingWriteTo(left, 1, 1);
+ assertEquals(1, result.length);
+ assertEquals((byte) 11, result[0]);
+
+ byte[] data2 = new byte[dataSize];
+ for (int i = 0; i < data1.length; i++) {
+ data2[i] = (byte) 2;
+ }
+ ByteString right = ByteString.wrap(data2);
+ // Concatenate two ByteStrings to create a RopeByteString.
+ ByteString root = left.concat(right);
+ // Make sure we are actually testing a RopeByteString with a simple tree
+ // structure.
+ assertEquals(1, root.getTreeDepth());
+ // Write parts of the left node.
+ result = substringUsingWriteTo(root, 0, dataSize);
+ assertEquals(dataSize, result.length);
+ assertEquals((byte) 1, result[0]);
+ assertEquals((byte) 1, result[dataSize - 1]);
+ // Write parts of the right node.
+ result = substringUsingWriteTo(root, dataSize, dataSize);
+ assertEquals(dataSize, result.length);
+ assertEquals((byte) 2, result[0]);
+ assertEquals((byte) 2, result[dataSize - 1]);
+ // Write a segment of bytes that runs across both nodes.
+ result = substringUsingWriteTo(root, dataSize / 2, dataSize);
+ assertEquals(dataSize, result.length);
+ assertEquals((byte) 1, result[0]);
+ assertEquals((byte) 1, result[dataSize - dataSize / 2 - 1]);
+ assertEquals((byte) 2, result[dataSize - dataSize / 2]);
+ assertEquals((byte) 2, result[dataSize - 1]);
+ }
+
+ /**
+ * Tests ByteString uses Arrays based byte copier when running under Hotstop VM.
+ */
+ public void testByteArrayCopier() throws Exception {
+ Field field = ByteString.class.getDeclaredField("byteArrayCopier");
+ field.setAccessible(true);
+ Object byteArrayCopier = field.get(null);
+ assertNotNull(byteArrayCopier);
+ assertTrue(
+ byteArrayCopier.toString(),
+ byteArrayCopier.getClass().getSimpleName().endsWith("ArraysByteArrayCopier"));
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/CheckUtf8Test.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/CheckUtf8Test.java
new file mode 100644
index 0000000000..cc65d19ab7
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/CheckUtf8Test.java
@@ -0,0 +1,141 @@
+// 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 proto2_test_check_utf8.TestCheckUtf8.BytesWrapper;
+import proto2_test_check_utf8.TestCheckUtf8.StringWrapper;
+import proto2_test_check_utf8_size.TestCheckUtf8Size.BytesWrapperSize;
+import proto2_test_check_utf8_size.TestCheckUtf8Size.StringWrapperSize;
+
+import junit.framework.TestCase;
+
+/**
+ * Test that protos generated with file option java_string_check_utf8 do in
+ * fact perform appropriate UTF-8 checks.
+ *
+ * @author jbaum@google.com (Jacob Butcher)
+ */
+public class CheckUtf8Test extends TestCase {
+
+ private static final String UTF8_BYTE_STRING_TEXT = "some text";
+ private static final ByteString UTF8_BYTE_STRING =
+ ByteString.copyFromUtf8(UTF8_BYTE_STRING_TEXT);
+ private static final ByteString NON_UTF8_BYTE_STRING =
+ ByteString.copyFrom(new byte[]{(byte) 0x80}); // A lone continuation byte.
+
+ public void testBuildRequiredStringWithGoodUtf8() throws Exception {
+ assertEquals(UTF8_BYTE_STRING_TEXT,
+ StringWrapper.newBuilder().setReqBytes(UTF8_BYTE_STRING).getReq());
+ }
+
+ public void testParseRequiredStringWithGoodUtf8() throws Exception {
+ ByteString serialized =
+ BytesWrapper.newBuilder().setReq(UTF8_BYTE_STRING).build().toByteString();
+ assertEquals(UTF8_BYTE_STRING_TEXT, StringWrapper.parser().parseFrom(serialized).getReq());
+ }
+
+ public void testBuildRequiredStringWithBadUtf8() throws Exception {
+ try {
+ StringWrapper.newBuilder().setReqBytes(NON_UTF8_BYTE_STRING);
+ fail("Expected IllegalArgumentException for non UTF-8 byte string.");
+ } catch (IllegalArgumentException exception) {
+ assertEquals("Byte string is not UTF-8.", exception.getMessage());
+ }
+ }
+
+ public void testBuildOptionalStringWithBadUtf8() throws Exception {
+ try {
+ StringWrapper.newBuilder().setOptBytes(NON_UTF8_BYTE_STRING);
+ fail("Expected IllegalArgumentException for non UTF-8 byte string.");
+ } catch (IllegalArgumentException exception) {
+ assertEquals("Byte string is not UTF-8.", exception.getMessage());
+ }
+ }
+
+ public void testBuildRepeatedStringWithBadUtf8() throws Exception {
+ try {
+ StringWrapper.newBuilder().addRepBytes(NON_UTF8_BYTE_STRING);
+ fail("Expected IllegalArgumentException for non UTF-8 byte string.");
+ } catch (IllegalArgumentException exception) {
+ assertEquals("Byte string is not UTF-8.", exception.getMessage());
+ }
+ }
+
+ public void testParseRequiredStringWithBadUtf8() throws Exception {
+ ByteString serialized =
+ BytesWrapper.newBuilder().setReq(NON_UTF8_BYTE_STRING).build().toByteString();
+ try {
+ StringWrapper.parser().parseFrom(serialized);
+ fail("Expected InvalidProtocolBufferException for non UTF-8 byte string.");
+ } catch (InvalidProtocolBufferException exception) {
+ assertEquals("Protocol message had invalid UTF-8.", exception.getMessage());
+ }
+ }
+
+ public void testBuildRequiredStringWithBadUtf8Size() throws Exception {
+ try {
+ StringWrapperSize.newBuilder().setReqBytes(NON_UTF8_BYTE_STRING);
+ fail("Expected IllegalArgumentException for non UTF-8 byte string.");
+ } catch (IllegalArgumentException exception) {
+ assertEquals("Byte string is not UTF-8.", exception.getMessage());
+ }
+ }
+
+ public void testBuildOptionalStringWithBadUtf8Size() throws Exception {
+ try {
+ StringWrapperSize.newBuilder().setOptBytes(NON_UTF8_BYTE_STRING);
+ fail("Expected IllegalArgumentException for non UTF-8 byte string.");
+ } catch (IllegalArgumentException exception) {
+ assertEquals("Byte string is not UTF-8.", exception.getMessage());
+ }
+ }
+
+ public void testBuildRepeatedStringWithBadUtf8Size() throws Exception {
+ try {
+ StringWrapperSize.newBuilder().addRepBytes(NON_UTF8_BYTE_STRING);
+ fail("Expected IllegalArgumentException for non UTF-8 byte string.");
+ } catch (IllegalArgumentException exception) {
+ assertEquals("Byte string is not UTF-8.", exception.getMessage());
+ }
+ }
+
+ public void testParseRequiredStringWithBadUtf8Size() throws Exception {
+ ByteString serialized =
+ BytesWrapperSize.newBuilder().setReq(NON_UTF8_BYTE_STRING).build().toByteString();
+ try {
+ StringWrapperSize.parser().parseFrom(serialized);
+ fail("Expected InvalidProtocolBufferException for non UTF-8 byte string.");
+ } catch (InvalidProtocolBufferException exception) {
+ assertEquals("Protocol message had invalid UTF-8.", exception.getMessage());
+ }
+ }
+
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java
new file mode 100644
index 0000000000..e440c7db3d
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/CodedInputStreamTest.java
@@ -0,0 +1,971 @@
+// 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 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 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}.
+ *
+ * @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.
+ */
+ private byte[] bytes(int... bytesAsInts) {
+ byte[] bytes = new byte[bytesAsInts.length];
+ for (int i = 0; i < bytesAsInts.length; i++) {
+ bytes[i] = (byte) bytesAsInts[i];
+ }
+ return bytes;
+ }
+
+ /**
+ * 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) {
+ super(new ByteArrayInputStream(data));
+ this.blockSize = blockSize;
+ }
+
+ @Override
+ public int read(byte[] b) throws IOException {
+ return super.read(b, 0, Math.min(b.length, blockSize));
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ return super.read(b, off, Math.min(len, blockSize));
+ }
+ }
+
+ private void assertDataConsumed(String msg, byte[] data, CodedInputStream input)
+ throws IOException {
+ 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.
+ */
+ private void assertReadVarint(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(), (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
+ // doesn't read past the end of the input, so we copy to a new, bigger
+ // array first.
+ byte[] longerData = new byte[data.length + 1];
+ System.arraycopy(data, 0, longerData, 0, data.length);
+ InputStream rawInput = new ByteArrayInputStream(longerData);
+ assertEquals((int) value, CodedInputStream.readRawVarint32(rawInput));
+ assertEquals(1, rawInput.available());
+ }
+
+ /**
+ * 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)
+ throws Exception {
+ 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.
+ try {
+ CodedInputStream.readRawVarint32(new ByteArrayInputStream(data));
+ fail("Should have thrown an exception.");
+ } catch (InvalidProtocolBufferException e) {
+ assertEquals(expected.getMessage(), e.getMessage());
+ }
+ }
+
+ /** Tests readRawVarint32() and readRawVarint64(). */
+ public void testReadVarint() throws Exception {
+ assertReadVarint(bytes(0x00), 0);
+ assertReadVarint(bytes(0x01), 1);
+ assertReadVarint(bytes(0x7f), 127);
+ // 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));
+
+ // 64-bit
+ // 7256456126
+ 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));
+ // 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));
+
+ // Failures
+ assertReadVarintFailure(
+ 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.
+ */
+ 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.
+ */
+ 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());
+ }
+ }
+ }
+
+ /** Tests readRawLittleEndian32() and readRawLittleEndian64(). */
+ public void testReadLittleEndian() throws Exception {
+ assertReadLittleEndian32(bytes(0x78, 0x56, 0x34, 0x12), 0x12345678);
+ assertReadLittleEndian32(bytes(0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef0);
+
+ assertReadLittleEndian64(
+ bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12), 0x123456789abcdef0L);
+ assertReadLittleEndian64(
+ 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(-1, CodedInputStream.decodeZigZag32(1));
+ 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(-1, CodedInputStream.decodeZigZag64(1));
+ 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));
+ }
+
+ /** Tests reading and parsing a whole message with every field type. */
+ public void testReadWholeMessage() throws Exception {
+ TestAllTypes message = TestUtil.getAllSet();
+
+ byte[] rawBytes = message.toByteArray();
+ assertEquals(rawBytes.length, message.getSerializedSize());
+
+ 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);
+ }
+ }
+ }
+
+ /** Tests skipField(). */
+ public void testSkipWholeMessage() throws Exception {
+ TestAllTypes message = TestUtil.getAllSet();
+ byte[] rawBytes = message.toByteArray();
+
+ 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();
+ // 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);
+ // 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.
+ */
+ public void testSkipRawBytesBug() throws Exception {
+ 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.
+ */
+ public void testSkipRawBytesPastEndOfBufferWithLimit() throws Exception {
+ 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 {
+ // Allocate and initialize a 1MB blob.
+ byte[] blob = new byte[1 << 20];
+ for (int i = 0; i < blob.length; i++) {
+ blob[i] = (byte) i;
+ }
+
+ // Make a message containing it.
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ builder.setOptionalBytes(ByteString.copyFrom(blob));
+ TestAllTypes message = builder.build();
+
+ 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 {
+ ByteString.Output rawOutput = ByteString.newOutput();
+ CodedOutputStream output = CodedOutputStream.newInstance(rawOutput);
+
+ 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.flush();
+
+ 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.
+ }
+ }
+ }
+
+ /**
+ * Test we can do messages that are up to CodedInputStream#DEFAULT_SIZE_LIMIT
+ * in size (2G or Integer#MAX_SIZE).
+ * @throws IOException
+ */
+ public void testParseMessagesCloseTo2G() throws IOException {
+ byte[] serializedMessage = getBigSerializedMessage();
+ // How many of these big messages do we need to take us near our 2G limit?
+ int count = Integer.MAX_VALUE / serializedMessage.length;
+ // Now make an inputstream that will fake a near 2G message of messages
+ // returning our big serialized message 'count' times.
+ InputStream is = new RepeatingInputStream(serializedMessage, count);
+ // Parse should succeed!
+ TestAllTypes.parseFrom(is);
+ }
+
+ /**
+ * Test there is an exception if a message exceeds
+ * CodedInputStream#DEFAULT_SIZE_LIMIT in size (2G or Integer#MAX_SIZE).
+ * @throws IOException
+ */
+ public void testParseMessagesOver2G() throws IOException {
+ byte[] serializedMessage = getBigSerializedMessage();
+ // How many of these big messages do we need to take us near our 2G limit?
+ int count = Integer.MAX_VALUE / serializedMessage.length;
+ // Now add one to take us over the limit
+ count++;
+ // Now make an inputstream that will fake a near 2G message of messages
+ // returning our big serialized message 'count' times.
+ InputStream is = new RepeatingInputStream(serializedMessage, count);
+ try {
+ TestAllTypes.parseFrom(is);
+ fail("Should have thrown an exception!");
+ } catch (InvalidProtocolBufferException e) {
+ assertTrue(e.getMessage().contains("too large"));
+ }
+ }
+
+ /*
+ * @return A serialized big message.
+ */
+ private static byte[] getBigSerializedMessage() {
+ byte[] value = new byte[16 * 1024 * 1024];
+ ByteString bsValue = ByteString.wrap(value);
+ return TestAllTypes.newBuilder().setOptionalBytes(bsValue).build().toByteArray();
+ }
+
+ /*
+ * An input stream that repeats a byte arrays' content a number of times.
+ * Simulates really large input without consuming loads of memory. Used above
+ * to test the parsing behavior when the input size exceeds 2G or close to it.
+ */
+ private static class RepeatingInputStream extends InputStream {
+ private final byte[] serializedMessage;
+ private final int count;
+ private int index = 0;
+ private int offset = 0;
+
+ RepeatingInputStream(byte[] serializedMessage, int count) {
+ this.serializedMessage = serializedMessage;
+ this.count = count;
+ }
+
+ @Override
+ public int read() throws IOException {
+ if (this.offset == this.serializedMessage.length) {
+ this.index++;
+ this.offset = 0;
+ }
+ if (this.index == this.count) {
+ return -1;
+ }
+ return this.serializedMessage[offset++];
+ }
+ }
+
+ private TestRecursiveMessage makeRecursiveMessage(int depth) {
+ if (depth == 0) {
+ return TestRecursiveMessage.newBuilder().setI(5).build();
+ } else {
+ return TestRecursiveMessage.newBuilder().setA(makeRecursiveMessage(depth - 1)).build();
+ }
+ }
+
+ private void assertMessageDepth(String msg, TestRecursiveMessage message, int depth) {
+ if (depth == 0) {
+ assertFalse(msg, message.hasA());
+ assertEquals(msg, 5, message.getI());
+ } else {
+ assertTrue(msg, message.hasA());
+ assertMessageDepth(msg, message.getA(), depth - 1);
+ }
+ }
+
+ public void testMaliciousRecursion() throws Exception {
+ byte[] data100 = makeRecursiveMessage(100).toByteArray();
+ byte[] data101 = makeRecursiveMessage(101).toByteArray();
+
+ for (InputType inputType : InputType.values()) {
+ assertMessageDepth(
+ inputType.name(), TestRecursiveMessage.parseFrom(inputType.newDecoder(data100)), 100);
+
+ try {
+ TestRecursiveMessage.parseFrom(inputType.newDecoder(data101));
+ 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());
+ }
+
+ public void testSizeLimit() throws Exception {
+ // NOTE: Size limit only applies to the stream-backed CIS.
+ CodedInputStream input =
+ CodedInputStream.newInstance(
+ new SmallBlockInputStream(TestUtil.getAllSet().toByteArray(), 16));
+ input.setSizeLimit(16);
+
+ try {
+ TestAllTypes.parseFrom(input);
+ fail("Should have thrown an exception!");
+ } catch (InvalidProtocolBufferException expected) {
+ checkSizeLimitExceeded(expected);
+ }
+ }
+
+ public void testResetSizeCounter() throws Exception {
+ // 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());
+
+ try {
+ input.readRawByte();
+ fail("Should have thrown an exception!");
+ } catch (InvalidProtocolBufferException expected) {
+ checkSizeLimitExceeded(expected);
+ }
+
+ input.resetSizeCounter();
+ assertEquals(0, input.getTotalBytesRead());
+ input.readRawByte(); // No exception thrown.
+ input.resetSizeCounter();
+ assertEquals(0, input.getTotalBytesRead());
+ input.readRawBytes(16);
+ assertEquals(16, input.getTotalBytesRead());
+ input.resetSizeCounter();
+
+ try {
+ input.readRawBytes(17); // Hits limit again.
+ fail("Should have thrown an exception!");
+ } catch (InvalidProtocolBufferException expected) {
+ checkSizeLimitExceeded(expected);
+ }
+ }
+
+ 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));
+ input.setSizeLimit(16);
+ for (int i = 0; i < 256 / 16; i++) {
+ byte[] message = input.readRawBytes(16);
+ for (int j = 0; j < message.length; j++) {
+ assertEquals(i * 16 + j, message[j] & 0xff);
+ }
+ assertEquals(16, input.getTotalBytesRead());
+ input.resetSizeCounter();
+ assertEquals(0, input.getTotalBytesRead());
+ }
+ }
+
+ public void testReadString() throws Exception {
+ String lorem = "Lorem ipsum dolor sit amet ";
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < 4096; i += lorem.length()) {
+ builder.append(lorem);
+ }
+ lorem = builder.toString().substring(0, 4096);
+ byte[] bytes = lorem.getBytes("UTF-8");
+ ByteString.Output rawOutput = ByteString.newOutput();
+ CodedOutputStream output = CodedOutputStream.newInstance(rawOutput, bytes.length);
+
+ int tag = WireFormat.makeTag(1, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ output.writeRawVarint32(tag);
+ output.writeRawVarint32(bytes.length);
+ output.writeRawBytes(bytes);
+ output.flush();
+
+ 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 {
+ String lorem = "Lorem ipsum dolor sit amet ";
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < 4096; i += lorem.length()) {
+ builder.append(lorem);
+ }
+ lorem = builder.toString().substring(0, 4096);
+ byte[] bytes = lorem.getBytes("UTF-8");
+ ByteString.Output rawOutput = ByteString.newOutput();
+ CodedOutputStream output = CodedOutputStream.newInstance(rawOutput, bytes.length);
+
+ int tag = WireFormat.makeTag(1, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ output.writeRawVarint32(tag);
+ output.writeRawVarint32(bytes.length);
+ output.writeRawBytes(bytes);
+ output.flush();
+
+ 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.
+ */
+ public void testReadStringInvalidUtf8() throws Exception {
+ ByteString.Output rawOutput = ByteString.newOutput();
+ CodedOutputStream output = CodedOutputStream.newInstance(rawOutput);
+
+ int tag = WireFormat.makeTag(1, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ output.writeRawVarint32(tag);
+ output.writeRawVarint32(1);
+ output.writeRawBytes(new byte[] {(byte) 0x80});
+ output.flush();
+
+ 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.
+ */
+ public void testReadStringRequireUtf8InvalidUtf8() throws Exception {
+ ByteString.Output rawOutput = ByteString.newOutput();
+ CodedOutputStream output = CodedOutputStream.newInstance(rawOutput);
+
+ int tag = WireFormat.makeTag(1, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ output.writeRawVarint32(tag);
+ output.writeRawVarint32(1);
+ output.writeRawBytes(new byte[] {(byte) 0x80});
+ output.flush();
+
+ 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());
+ }
+ }
+ }
+
+ public void testReadFromSlice() throws Exception {
+ byte[] bytes = bytes(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
+ CodedInputStream in = CodedInputStream.newInstance(bytes, 3, 5);
+ assertEquals(0, in.getTotalBytesRead());
+ for (int i = 3; i < 8; i++) {
+ assertEquals(i, in.readRawByte());
+ assertEquals(i - 2, in.getTotalBytesRead());
+ }
+ // eof
+ assertEquals(0, in.readTag());
+ assertEquals(5, in.getTotalBytesRead());
+ }
+
+ public void testInvalidTag() throws Exception {
+ // Any tag number which corresponds to field number zero is invalid and
+ // should throw InvalidProtocolBufferException.
+ 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());
+ }
+ }
+ }
+ }
+
+ public void testReadByteArray() throws Exception {
+ ByteString.Output rawOutput = ByteString.newOutput();
+ CodedOutputStream output = CodedOutputStream.newInstance(rawOutput);
+ // Zero-sized bytes field.
+ output.writeRawVarint32(0);
+ // One one-byte bytes field
+ output.writeRawVarint32(1);
+ output.writeRawBytes(new byte[] {(byte) 23});
+ // Another one-byte bytes field
+ output.writeRawVarint32(1);
+ 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];
+ bytes[0] = (byte) 67;
+ bytes[bytesLength - 1] = (byte) 89;
+ output.writeRawVarint32(bytesLength);
+ output.writeRawBytes(bytes);
+
+ output.flush();
+
+ 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 {
+ ByteString.Output rawOutput = ByteString.newOutput();
+ CodedOutputStream output = CodedOutputStream.newInstance(rawOutput);
+ // Zero-sized bytes field.
+ output.writeRawVarint32(0);
+ // One one-byte bytes field
+ output.writeRawVarint32(1);
+ output.writeRawBytes(new byte[] {(byte) 23});
+ // Another one-byte bytes field
+ output.writeRawVarint32(1);
+ 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];
+ bytes[0] = (byte) 67;
+ bytes[bytesLength - 1] = (byte) 89;
+ output.writeRawVarint32(bytesLength);
+ output.writeRawBytes(bytes);
+
+ output.flush();
+
+ 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 {
+ ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
+ CodedOutputStream output = CodedOutputStream.newInstance(byteArrayStream);
+ // Zero-sized bytes field.
+ output.writeRawVarint32(0);
+ // One one-byte bytes field
+ output.writeRawVarint32(1);
+ output.writeRawBytes(new byte[] {(byte) 23});
+ // Another one-byte bytes field
+ output.writeRawVarint32(1);
+ 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];
+ bytes[0] = (byte) 67;
+ bytes[bytesLength - 1] = (byte) 89;
+ output.writeRawVarint32(bytesLength);
+ output.writeRawBytes(bytes);
+ output.flush();
+
+ byte[] data = byteArrayStream.toByteArray();
+
+ 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();
+ 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());
+ }
+ }
+
+ 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
+ }
+ }
+ }
+
+ 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/third_party/protobuf/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java
new file mode 100644
index 0000000000..78f415c254
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java
@@ -0,0 +1,795 @@
+// 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.CodedOutputStream.OutOfSpaceException;
+import protobuf_unittest.UnittestProto.SparseEnumMessage;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestPackedTypes;
+import protobuf_unittest.UnittestProto.TestSparseEnum;
+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}.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class CodedOutputStreamTest extends TestCase {
+ private interface Coder {
+ CodedOutputStream stream();
+
+ byte[] toByteArray();
+
+ OutputType getOutputType();
+ }
+
+ private static final class OutputStreamCoder implements Coder {
+ private final CodedOutputStream stream;
+ private final ByteArrayOutputStream output;
+
+ OutputStreamCoder(int size) {
+ output = new ByteArrayOutputStream();
+ stream = CodedOutputStream.newInstance(output, size);
+ }
+
+ @Override
+ public CodedOutputStream stream() {
+ return stream;
+ }
+
+ @Override
+ public byte[] toByteArray() {
+ return output.toByteArray();
+ }
+
+ @Override
+ public OutputType getOutputType() {
+ return OutputType.STREAM;
+ }
+ }
+
+ private static final class ArrayCoder implements Coder {
+ private final CodedOutputStream stream;
+ private final byte[] bytes;
+
+ ArrayCoder(int size) {
+ bytes = new byte[size];
+ stream = CodedOutputStream.newInstance(bytes);
+ }
+
+ @Override
+ public CodedOutputStream stream() {
+ return stream;
+ }
+
+ @Override
+ public byte[] toByteArray() {
+ return Arrays.copyOf(bytes, stream.getTotalBytesWritten());
+ }
+
+ @Override
+ public OutputType getOutputType() {
+ return OutputType.ARRAY;
+ }
+ }
+
+ private static final class NioHeapCoder implements Coder {
+ private final CodedOutputStream stream;
+ private final ByteBuffer buffer;
+ private final int initialPosition;
+
+ NioHeapCoder(int size) {
+ this(size, 0);
+ }
+
+ NioHeapCoder(int size, int initialPosition) {
+ this.initialPosition = initialPosition;
+ buffer = ByteBuffer.allocate(size);
+ buffer.position(initialPosition);
+ stream = CodedOutputStream.newInstance(buffer);
+ }
+
+ @Override
+ public CodedOutputStream stream() {
+ return stream;
+ }
+
+ @Override
+ public byte[] toByteArray() {
+ ByteBuffer dup = buffer.duplicate();
+ dup.position(initialPosition);
+ dup.limit(buffer.position());
+
+ byte[] bytes = new byte[dup.remaining()];
+ dup.get(bytes);
+ return bytes;
+ }
+
+ @Override
+ public OutputType getOutputType() {
+ return OutputType.NIO_HEAP;
+ }
+ }
+
+ private static final class NioDirectCoder implements Coder {
+ private final int initialPosition;
+ private final CodedOutputStream stream;
+ private final ByteBuffer buffer;
+ private final boolean unsafe;
+
+ NioDirectCoder(int size, boolean unsafe) {
+ this(size, 0, unsafe);
+ }
+
+ NioDirectCoder(int size, int initialPosition, boolean unsafe) {
+ this.unsafe = unsafe;
+ this.initialPosition = initialPosition;
+ buffer = ByteBuffer.allocateDirect(size);
+ buffer.position(initialPosition);
+ stream =
+ unsafe
+ ? CodedOutputStream.newUnsafeInstance(buffer)
+ : CodedOutputStream.newSafeInstance(buffer);
+ }
+
+ @Override
+ public CodedOutputStream stream() {
+ return stream;
+ }
+
+ @Override
+ public byte[] toByteArray() {
+ ByteBuffer dup = buffer.duplicate();
+ dup.position(initialPosition);
+ dup.limit(buffer.position());
+
+ byte[] bytes = new byte[dup.remaining()];
+ dup.get(bytes);
+ return bytes;
+ }
+
+ @Override
+ public OutputType getOutputType() {
+ return unsafe ? OutputType.NIO_DIRECT_SAFE : OutputType.NIO_DIRECT_UNSAFE;
+ }
+ }
+
+ private enum OutputType {
+ ARRAY() {
+ @Override
+ Coder newCoder(int size) {
+ return new ArrayCoder(size);
+ }
+ },
+ NIO_HEAP() {
+ @Override
+ Coder newCoder(int size) {
+ return new NioHeapCoder(size);
+ }
+ },
+ NIO_DIRECT_SAFE() {
+ @Override
+ Coder newCoder(int size) {
+ return new NioDirectCoder(size, false);
+ }
+ },
+ NIO_DIRECT_UNSAFE() {
+ @Override
+ Coder newCoder(int size) {
+ return new NioDirectCoder(size, true);
+ }
+ },
+ STREAM() {
+ @Override
+ Coder newCoder(int size) {
+ return new OutputStreamCoder(size);
+ }
+ };
+
+ abstract Coder newCoder(int size);
+ }
+
+ /** Checks that invariants are maintained for varint round trip input and output. */
+ public void testVarintRoundTrips() throws Exception {
+ for (OutputType outputType : OutputType.values()) {
+ assertVarintRoundTrip(outputType, 0L);
+ for (int bits = 0; bits < 64; bits++) {
+ long value = 1L << bits;
+ assertVarintRoundTrip(outputType, value);
+ assertVarintRoundTrip(outputType, value + 1);
+ assertVarintRoundTrip(outputType, value - 1);
+ assertVarintRoundTrip(outputType, -value);
+ }
+ }
+ }
+
+ /** Tests writeRawVarint32() and writeRawVarint64(). */
+ public void testWriteVarint() throws Exception {
+ assertWriteVarint(bytes(0x00), 0);
+ assertWriteVarint(bytes(0x01), 1);
+ assertWriteVarint(bytes(0x7f), 127);
+ // 14882
+ assertWriteVarint(bytes(0xa2, 0x74), (0x22 << 0) | (0x74 << 7));
+ // 2961488830
+ assertWriteVarint(
+ bytes(0xbe, 0xf7, 0x92, 0x84, 0x0b),
+ (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | (0x0bL << 28));
+
+ // 64-bit
+ // 7256456126
+ assertWriteVarint(
+ bytes(0xbe, 0xf7, 0x92, 0x84, 0x1b),
+ (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | (0x1bL << 28));
+ // 41256202580718336
+ assertWriteVarint(
+ 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
+ assertWriteVarint(
+ 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));
+ }
+
+ /** Tests writeRawLittleEndian32() and writeRawLittleEndian64(). */
+ public void testWriteLittleEndian() throws Exception {
+ assertWriteLittleEndian32(bytes(0x78, 0x56, 0x34, 0x12), 0x12345678);
+ assertWriteLittleEndian32(bytes(0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef0);
+
+ assertWriteLittleEndian64(
+ bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12), 0x123456789abcdef0L);
+ assertWriteLittleEndian64(
+ bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef012345678L);
+ }
+
+ /** Test encodeZigZag32() and encodeZigZag64(). */
+ public void testEncodeZigZag() throws Exception {
+ assertEquals(0, CodedOutputStream.encodeZigZag32(0));
+ assertEquals(1, CodedOutputStream.encodeZigZag32(-1));
+ assertEquals(2, CodedOutputStream.encodeZigZag32(1));
+ assertEquals(3, CodedOutputStream.encodeZigZag32(-2));
+ assertEquals(0x7FFFFFFE, CodedOutputStream.encodeZigZag32(0x3FFFFFFF));
+ assertEquals(0x7FFFFFFF, CodedOutputStream.encodeZigZag32(0xC0000000));
+ assertEquals(0xFFFFFFFE, CodedOutputStream.encodeZigZag32(0x7FFFFFFF));
+ assertEquals(0xFFFFFFFF, CodedOutputStream.encodeZigZag32(0x80000000));
+
+ assertEquals(0, CodedOutputStream.encodeZigZag64(0));
+ assertEquals(1, CodedOutputStream.encodeZigZag64(-1));
+ assertEquals(2, CodedOutputStream.encodeZigZag64(1));
+ assertEquals(3, CodedOutputStream.encodeZigZag64(-2));
+ assertEquals(0x000000007FFFFFFEL, CodedOutputStream.encodeZigZag64(0x000000003FFFFFFFL));
+ assertEquals(0x000000007FFFFFFFL, CodedOutputStream.encodeZigZag64(0xFFFFFFFFC0000000L));
+ assertEquals(0x00000000FFFFFFFEL, CodedOutputStream.encodeZigZag64(0x000000007FFFFFFFL));
+ assertEquals(0x00000000FFFFFFFFL, CodedOutputStream.encodeZigZag64(0xFFFFFFFF80000000L));
+ assertEquals(0xFFFFFFFFFFFFFFFEL, CodedOutputStream.encodeZigZag64(0x7FFFFFFFFFFFFFFFL));
+ assertEquals(0xFFFFFFFFFFFFFFFFL, CodedOutputStream.encodeZigZag64(0x8000000000000000L));
+
+ // Some easier-to-verify round-trip tests. The inputs (other than 0, 1, -1)
+ // were chosen semi-randomly via keyboard bashing.
+ assertEquals(0, CodedOutputStream.encodeZigZag32(CodedInputStream.decodeZigZag32(0)));
+ assertEquals(1, CodedOutputStream.encodeZigZag32(CodedInputStream.decodeZigZag32(1)));
+ assertEquals(-1, CodedOutputStream.encodeZigZag32(CodedInputStream.decodeZigZag32(-1)));
+ assertEquals(14927, CodedOutputStream.encodeZigZag32(CodedInputStream.decodeZigZag32(14927)));
+ assertEquals(-3612, CodedOutputStream.encodeZigZag32(CodedInputStream.decodeZigZag32(-3612)));
+
+ assertEquals(0, CodedOutputStream.encodeZigZag64(CodedInputStream.decodeZigZag64(0)));
+ assertEquals(1, CodedOutputStream.encodeZigZag64(CodedInputStream.decodeZigZag64(1)));
+ assertEquals(-1, CodedOutputStream.encodeZigZag64(CodedInputStream.decodeZigZag64(-1)));
+ assertEquals(14927, CodedOutputStream.encodeZigZag64(CodedInputStream.decodeZigZag64(14927)));
+ assertEquals(-3612, CodedOutputStream.encodeZigZag64(CodedInputStream.decodeZigZag64(-3612)));
+
+ assertEquals(
+ 856912304801416L,
+ CodedOutputStream.encodeZigZag64(CodedInputStream.decodeZigZag64(856912304801416L)));
+ assertEquals(
+ -75123905439571256L,
+ CodedOutputStream.encodeZigZag64(CodedInputStream.decodeZigZag64(-75123905439571256L)));
+ }
+
+ /** Tests writing a whole message with every field type. */
+ public void testWriteWholeMessage() throws Exception {
+ final byte[] expectedBytes = TestUtil.getGoldenMessage().toByteArray();
+ TestAllTypes message = TestUtil.getAllSet();
+
+ for (OutputType outputType : OutputType.values()) {
+ Coder coder = outputType.newCoder(message.getSerializedSize());
+ message.writeTo(coder.stream());
+ coder.stream().flush();
+ byte[] rawBytes = coder.toByteArray();
+ assertEqualBytes(outputType, expectedBytes, rawBytes);
+ }
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize < 256; blockSize *= 2) {
+ Coder coder = OutputType.STREAM.newCoder(blockSize);
+ message.writeTo(coder.stream());
+ coder.stream().flush();
+ assertEqualBytes(OutputType.STREAM, expectedBytes, coder.toByteArray());
+ }
+ }
+
+ /**
+ * Tests writing a whole message with every packed field type. Ensures the
+ * wire format of packed fields is compatible with C++.
+ */
+ public void testWriteWholePackedFieldsMessage() throws Exception {
+ byte[] expectedBytes = TestUtil.getGoldenPackedFieldsMessage().toByteArray();
+ TestPackedTypes message = TestUtil.getPackedSet();
+
+ for (OutputType outputType : OutputType.values()) {
+ Coder coder = outputType.newCoder(message.getSerializedSize());
+ message.writeTo(coder.stream());
+ coder.stream().flush();
+ byte[] rawBytes = coder.toByteArray();
+ assertEqualBytes(outputType, expectedBytes, rawBytes);
+ }
+ }
+
+ /**
+ * Test writing a message containing a negative enum value. This used to
+ * fail because the size was not properly computed as a sign-extended varint.
+ */
+ public void testWriteMessageWithNegativeEnumValue() throws Exception {
+ SparseEnumMessage message =
+ SparseEnumMessage.newBuilder().setSparseEnum(TestSparseEnum.SPARSE_E).build();
+ assertTrue(message.getSparseEnum().getNumber() < 0);
+ for (OutputType outputType : OutputType.values()) {
+ Coder coder = outputType.newCoder(message.getSerializedSize());
+ message.writeTo(coder.stream());
+ coder.stream().flush();
+ byte[] rawBytes = coder.toByteArray();
+ SparseEnumMessage message2 = SparseEnumMessage.parseFrom(rawBytes);
+ assertEquals(TestSparseEnum.SPARSE_E, message2.getSparseEnum());
+ }
+ }
+
+ /** Test getTotalBytesWritten() */
+ public void testGetTotalBytesWritten() throws Exception {
+ Coder coder = OutputType.STREAM.newCoder(4 * 1024);
+
+ // Write some some bytes (more than the buffer can hold) and verify that totalWritten
+ // is correct.
+ byte[] value = "abcde".getBytes(Internal.UTF_8);
+ for (int i = 0; i < 1024; ++i) {
+ coder.stream().writeRawBytes(value, 0, value.length);
+ }
+ assertEquals(value.length * 1024, coder.stream().getTotalBytesWritten());
+
+ // Now write an encoded string.
+ String string =
+ "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
+ // Ensure we take the slower fast path.
+ assertTrue(CodedOutputStream.computeUInt32SizeNoTag(string.length())
+ != 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
+ assertEquals((value.length * 1024) + stringSize, coder.stream().getTotalBytesWritten());
+ }
+
+ // TODO(dweis): Write a comprehensive test suite for CodedOutputStream that covers more than just
+ // this case.
+ public void testWriteStringNoTag_fastpath() throws Exception {
+ int bufferSize = 153;
+ String threeBytesPer = "\u0981";
+ String string = threeBytesPer;
+ for (int i = 0; i < 50; i++) {
+ string += threeBytesPer;
+ }
+ // These checks ensure we will tickle the slower fast path.
+ assertEquals(1, CodedOutputStream.computeUInt32SizeNoTag(string.length()));
+ assertEquals(
+ 2, CodedOutputStream.computeUInt32SizeNoTag(string.length() * Utf8.MAX_BYTES_PER_CHAR));
+ assertEquals(bufferSize, string.length() * Utf8.MAX_BYTES_PER_CHAR);
+
+ for (OutputType outputType : OutputType.values()) {
+ Coder coder = outputType.newCoder(bufferSize + 2);
+ coder.stream().writeStringNoTag(string);
+ coder.stream().flush();
+ }
+ }
+
+ public void testWriteToByteBuffer() throws Exception {
+ final int bufferSize = 16 * 1024;
+ ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
+ CodedOutputStream codedStream = CodedOutputStream.newInstance(buffer);
+ // Write raw bytes into the ByteBuffer.
+ final int length1 = 5000;
+ for (int i = 0; i < length1; i++) {
+ codedStream.writeRawByte((byte) 1);
+ }
+ final int length2 = 8 * 1024;
+ byte[] data = new byte[length2];
+ for (int i = 0; i < length2; i++) {
+ data[i] = (byte) 2;
+ }
+ codedStream.writeRawBytes(data);
+ final int length3 = bufferSize - length1 - length2;
+ for (int i = 0; i < length3; i++) {
+ codedStream.writeRawByte((byte) 3);
+ }
+ codedStream.flush();
+
+ // Check that data is correctly written to the ByteBuffer.
+ assertEquals(0, buffer.remaining());
+ buffer.flip();
+ for (int i = 0; i < length1; i++) {
+ assertEquals((byte) 1, buffer.get());
+ }
+ for (int i = 0; i < length2; i++) {
+ assertEquals((byte) 2, buffer.get());
+ }
+ for (int i = 0; i < length3; i++) {
+ assertEquals((byte) 3, buffer.get());
+ }
+ }
+
+ public void testWriteByteBuffer() throws Exception {
+ byte[] value = "abcde".getBytes(Internal.UTF_8);
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ CodedOutputStream codedStream = CodedOutputStream.newInstance(outputStream);
+ ByteBuffer byteBuffer = ByteBuffer.wrap(value, 0, 1);
+ // This will actually write 5 bytes into the CodedOutputStream as the
+ // ByteBuffer's capacity() is 5.
+ codedStream.writeRawBytes(byteBuffer);
+ // The above call shouldn't affect the ByteBuffer's state.
+ assertEquals(0, byteBuffer.position());
+ assertEquals(1, byteBuffer.limit());
+
+ // The correct way to write part of an array using ByteBuffer.
+ codedStream.writeRawBytes(ByteBuffer.wrap(value, 2, 1).slice());
+
+ codedStream.flush();
+ byte[] result = outputStream.toByteArray();
+ assertEquals(6, result.length);
+ for (int i = 0; i < 5; i++) {
+ assertEquals(value[i], result[i]);
+ }
+ assertEquals(value[2], result[5]);
+ }
+
+ public void testWriteByteArrayWithOffsets() throws Exception {
+ byte[] fullArray = bytes(0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88);
+ 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 {
+ final String source = "abcdefghijklmnopqrstuvwxyz";
+
+ // Generate the expected output if the source string is written 2 bytes at a time.
+ ByteArrayOutputStream expectedBytesStream = new ByteArrayOutputStream();
+ for (int pos = 0; pos < source.length(); pos += 2) {
+ String substr = source.substring(pos, pos + 2);
+ expectedBytesStream.write(2);
+ expectedBytesStream.write(substr.getBytes(Internal.UTF_8));
+ }
+ final byte[] expectedBytes = expectedBytesStream.toByteArray();
+
+ // For each output type, write the source string 2 bytes at a time and verify the output.
+ for (OutputType outputType : OutputType.values()) {
+ Coder coder = outputType.newCoder(expectedBytes.length);
+ for (int pos = 0; pos < source.length(); pos += 2) {
+ String substr = source.substring(pos, pos + 2);
+ coder.stream().writeStringNoTag(substr);
+ }
+ coder.stream().flush();
+ assertEqualBytes(outputType, expectedBytes, coder.toByteArray());
+ }
+ }
+
+ public void testSerializeInvalidUtf8() throws Exception {
+ String[] invalidStrings = new String[] {newString(Character.MIN_HIGH_SURROGATE),
+ "foobar" + newString(Character.MIN_HIGH_SURROGATE), newString(Character.MIN_LOW_SURROGATE),
+ "foobar" + newString(Character.MIN_LOW_SURROGATE),
+ newString(Character.MIN_HIGH_SURROGATE, Character.MIN_HIGH_SURROGATE)};
+
+ CodedOutputStream outputWithStream = CodedOutputStream.newInstance(new ByteArrayOutputStream());
+ CodedOutputStream outputWithArray = CodedOutputStream.newInstance(new byte[10000]);
+ CodedOutputStream outputWithByteBuffer =
+ CodedOutputStream.newInstance(ByteBuffer.allocate(10000));
+ for (String s : invalidStrings) {
+ // TODO(dweis): These should all fail; instead they are corrupting data.
+ CodedOutputStream.computeStringSizeNoTag(s);
+ outputWithStream.writeStringNoTag(s);
+ outputWithArray.writeStringNoTag(s);
+ outputWithByteBuffer.writeStringNoTag(s);
+ }
+ }
+
+ // TODO(nathanmittler): This test can be deleted once we properly throw IOException while
+ // encoding invalid UTF-8 strings.
+ public void testSerializeInvalidUtf8FollowedByOutOfSpace() throws Exception {
+ final int notEnoughBytes = 4;
+ CodedOutputStream outputWithArray = CodedOutputStream.newInstance(new byte[notEnoughBytes]);
+ CodedOutputStream outputWithByteBuffer =
+ CodedOutputStream.newInstance(ByteBuffer.allocate(notEnoughBytes));
+
+ String invalidString = newString(Character.MIN_HIGH_SURROGATE, 'f', 'o', 'o', 'b', 'a', 'r');
+ try {
+ outputWithArray.writeStringNoTag(invalidString);
+ fail("Expected OutOfSpaceException");
+ } catch (OutOfSpaceException e) {
+ assertTrue(e.getCause() instanceof IndexOutOfBoundsException);
+ }
+ try {
+ outputWithByteBuffer.writeStringNoTag(invalidString);
+ fail("Expected OutOfSpaceException");
+ } catch (OutOfSpaceException e) {
+ assertTrue(e.getCause() instanceof IndexOutOfBoundsException);
+ }
+ }
+
+ /** Regression test for https://github.com/google/protobuf/issues/292 */
+ public void testCorrectExceptionThrowWhenEncodingStringsWithoutEnoughSpace() throws Exception {
+ String testCase = "Foooooooo";
+ assertEquals(
+ CodedOutputStream.computeUInt32SizeNoTag(testCase.length()),
+ CodedOutputStream.computeUInt32SizeNoTag(testCase.length() * 3));
+ assertEquals(11, CodedOutputStream.computeStringSize(1, 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_SAFE,
+ OutputType.NIO_DIRECT_UNSAFE
+ }) {
+ for (int i = 0; i < 11; i++) {
+ Coder coder = outputType.newCoder(i);
+ try {
+ coder.stream().writeString(1, testCase);
+ fail("Should have thrown an out of space exception");
+ } catch (CodedOutputStream.OutOfSpaceException expected) {
+ }
+ }
+ }
+ }
+
+ public void testDifferentStringLengths() throws Exception {
+ // Test string serialization roundtrip using strings of the following lengths,
+ // with ASCII and Unicode characters requiring different UTF-8 byte counts per
+ // char, hence causing the length delimiter varint to sometimes require more
+ // bytes for the Unicode strings than the ASCII string of the same length.
+ int[] lengths = new int[] {
+ 0,
+ 1,
+ (1 << 4) - 1, // 1 byte for ASCII and Unicode
+ (1 << 7) - 1, // 1 byte for ASCII, 2 bytes for Unicode
+ (1 << 11) - 1, // 2 bytes for ASCII and Unicode
+ (1 << 14) - 1, // 2 bytes for ASCII, 3 bytes for Unicode
+ (1 << 17) - 1,
+ // 3 bytes for ASCII and Unicode
+ };
+ for (OutputType outputType : OutputType.values()) {
+ for (int i : lengths) {
+ testEncodingOfString(outputType, 'q', i); // 1 byte per char
+ testEncodingOfString(outputType, '\u07FF', i); // 2 bytes per char
+ testEncodingOfString(outputType, '\u0981', i); // 3 bytes per char
+ }
+ }
+ }
+
+ public void testNioEncodersWithInitialOffsets() throws Exception {
+ String value = "abc";
+ 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());
+ }
+ }
+
+ /**
+ * Parses the given bytes using writeRawLittleEndian32() and checks
+ * that the result matches the given value.
+ */
+ private static void assertWriteLittleEndian32(byte[] data, int value) throws Exception {
+ for (OutputType outputType : OutputType.values()) {
+ Coder coder = outputType.newCoder(data.length);
+ coder.stream().writeFixed32NoTag(value);
+ coder.stream().flush();
+ assertEqualBytes(outputType, data, coder.toByteArray());
+ }
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2) {
+ Coder coder = OutputType.STREAM.newCoder(blockSize);
+ coder.stream().writeFixed32NoTag(value);
+ coder.stream().flush();
+ assertEqualBytes(OutputType.STREAM, data, coder.toByteArray());
+ }
+ }
+
+ /**
+ * Parses the given bytes using writeRawLittleEndian64() and checks
+ * that the result matches the given value.
+ */
+ private static void assertWriteLittleEndian64(byte[] data, long value) throws Exception {
+ for (OutputType outputType : OutputType.values()) {
+ Coder coder = outputType.newCoder(data.length);
+ coder.stream().writeFixed64NoTag(value);
+ coder.stream().flush();
+ assertEqualBytes(outputType, data, coder.toByteArray());
+ }
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2) {
+ Coder coder = OutputType.STREAM.newCoder(blockSize);
+ coder.stream().writeFixed64NoTag(value);
+ coder.stream().flush();
+ assertEqualBytes(OutputType.STREAM, data, coder.toByteArray());
+ }
+ }
+
+ private static String newString(char... chars) {
+ return new String(chars);
+ }
+
+ private static void testEncodingOfString(OutputType outputType, char c, int length)
+ throws Exception {
+ String fullString = fullString(c, length);
+ TestAllTypes testAllTypes = TestAllTypes.newBuilder().setOptionalString(fullString).build();
+ Coder coder = outputType.newCoder(testAllTypes.getSerializedSize());
+ testAllTypes.writeTo(coder.stream());
+ coder.stream().flush();
+ assertEquals(
+ "OuputType: " + outputType,
+ fullString,
+ TestAllTypes.parseFrom(coder.toByteArray()).getOptionalString());
+ }
+
+ private static String fullString(char c, int length) {
+ char[] result = new char[length];
+ Arrays.fill(result, c);
+ return new String(result);
+ }
+
+ /**
+ * 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 static byte[] bytes(int... bytesAsInts) {
+ byte[] bytes = new byte[bytesAsInts.length];
+ for (int i = 0; i < bytesAsInts.length; i++) {
+ bytes[i] = (byte) bytesAsInts[i];
+ }
+ return bytes;
+ }
+
+ /** Arrays.asList() does not work with arrays of primitives. :( */
+ private static List<Byte> toList(byte[] bytes) {
+ List<Byte> result = new ArrayList<Byte>();
+ for (byte b : bytes) {
+ result.add(b);
+ }
+ return result;
+ }
+
+ private static void assertEqualBytes(OutputType outputType, byte[] a, byte[] b) {
+ assertEquals(outputType.name(), toList(a), toList(b));
+ }
+
+ /**
+ * Writes the given value using writeRawVarint32() and writeRawVarint64() and
+ * checks that the result matches the given bytes.
+ */
+ private static void assertWriteVarint(byte[] data, long value) throws Exception {
+ for (OutputType outputType : OutputType.values()) {
+ // Only test 32-bit write if the value fits into an int.
+ if (value == (int) value) {
+ Coder coder = outputType.newCoder(10);
+ coder.stream().writeUInt32NoTag((int) value);
+ coder.stream().flush();
+ assertEqualBytes(outputType, data, coder.toByteArray());
+
+ // Also try computing size.
+ assertEquals(data.length, CodedOutputStream.computeUInt32SizeNoTag((int) value));
+ }
+
+ {
+ Coder coder = outputType.newCoder(10);
+ coder.stream().writeUInt64NoTag(value);
+ coder.stream().flush();
+ assertEqualBytes(outputType, data, coder.toByteArray());
+
+ // Also try computing size.
+ assertEquals(data.length, CodedOutputStream.computeUInt64SizeNoTag(value));
+ }
+ }
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2) {
+ // Only test 32-bit write if the value fits into an int.
+ if (value == (int) value) {
+ Coder coder = OutputType.STREAM.newCoder(blockSize);
+ coder.stream().writeUInt64NoTag((int) value);
+ coder.stream().flush();
+ assertEqualBytes(OutputType.STREAM, data, coder.toByteArray());
+
+ ByteArrayOutputStream rawOutput = new ByteArrayOutputStream();
+ CodedOutputStream output = CodedOutputStream.newInstance(rawOutput, blockSize);
+ output.writeUInt32NoTag((int) value);
+ output.flush();
+ assertEqualBytes(OutputType.STREAM, data, rawOutput.toByteArray());
+ }
+
+ {
+ Coder coder = OutputType.STREAM.newCoder(blockSize);
+ coder.stream().writeUInt64NoTag(value);
+ coder.stream().flush();
+ assertEqualBytes(OutputType.STREAM, data, coder.toByteArray());
+ }
+ }
+ }
+
+ private static void assertVarintRoundTrip(OutputType outputType, long value) throws Exception {
+ {
+ Coder coder = outputType.newCoder(10);
+ coder.stream().writeUInt64NoTag(value);
+ coder.stream().flush();
+ byte[] bytes = coder.toByteArray();
+ assertEquals(
+ outputType.name(), bytes.length, CodedOutputStream.computeUInt64SizeNoTag(value));
+ CodedInputStream input = CodedInputStream.newInstance(new ByteArrayInputStream(bytes));
+ assertEquals(outputType.name(), value, input.readRawVarint64());
+ }
+
+ if (value == (int) value) {
+ Coder coder = outputType.newCoder(10);
+ coder.stream().writeUInt32NoTag((int) value);
+ coder.stream().flush();
+ byte[] bytes = coder.toByteArray();
+ assertEquals(
+ outputType.name(), bytes.length, CodedOutputStream.computeUInt32SizeNoTag((int) value));
+ CodedInputStream input = CodedInputStream.newInstance(new ByteArrayInputStream(bytes));
+ assertEquals(outputType.name(), value, input.readRawVarint32());
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/DeprecatedFieldTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/DeprecatedFieldTest.java
new file mode 100644
index 0000000000..2c272a7347
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/DeprecatedFieldTest.java
@@ -0,0 +1,79 @@
+// 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 protobuf_unittest.UnittestProto.TestDeprecatedFields;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+import junit.framework.TestCase;
+
+/**
+ * Test field deprecation
+ *
+ * @author birdo@google.com (Roberto Scaramuzzi)
+ */
+public class DeprecatedFieldTest extends TestCase {
+ private String[] deprecatedGetterNames = {
+ "hasDeprecatedInt32",
+ "getDeprecatedInt32"};
+
+ private String[] deprecatedBuilderGetterNames = {
+ "hasDeprecatedInt32",
+ "getDeprecatedInt32",
+ "clearDeprecatedInt32"};
+
+ private String[] deprecatedBuilderSetterNames = {
+ "setDeprecatedInt32"};
+
+ public void testDeprecatedField() throws Exception {
+ Class<?> deprecatedFields = TestDeprecatedFields.class;
+ Class<?> deprecatedFieldsBuilder = TestDeprecatedFields.Builder.class;
+ for (String name : deprecatedGetterNames) {
+ Method method = deprecatedFields.getMethod(name);
+ assertTrue("Method " + name + " should be deprecated",
+ isDeprecated(method));
+ }
+ for (String name : deprecatedBuilderGetterNames) {
+ Method method = deprecatedFieldsBuilder.getMethod(name);
+ assertTrue("Method " + name + " should be deprecated",
+ isDeprecated(method));
+ }
+ for (String name : deprecatedBuilderSetterNames) {
+ Method method = deprecatedFieldsBuilder.getMethod(name, int.class);
+ assertTrue("Method " + name + " should be deprecated",
+ isDeprecated(method));
+ }
+ }
+
+ private boolean isDeprecated(AnnotatedElement annotated) {
+ return annotated.isAnnotationPresent(Deprecated.class);
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java
new file mode 100644
index 0000000000..b60cd62088
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/DescriptorsTest.java
@@ -0,0 +1,819 @@
+// 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.DescriptorProtos.DescriptorProto;
+import com.google.protobuf.DescriptorProtos.EnumDescriptorProto;
+import com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto;
+import com.google.protobuf.DescriptorProtos.FieldDescriptorProto;
+import com.google.protobuf.DescriptorProtos.FileDescriptorProto;
+import com.google.protobuf.Descriptors.Descriptor;
+import com.google.protobuf.Descriptors.DescriptorValidationException;
+import com.google.protobuf.Descriptors.EnumDescriptor;
+import com.google.protobuf.Descriptors.EnumValueDescriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+import com.google.protobuf.Descriptors.FileDescriptor;
+import com.google.protobuf.Descriptors.MethodDescriptor;
+import com.google.protobuf.Descriptors.OneofDescriptor;
+import com.google.protobuf.Descriptors.ServiceDescriptor;
+import com.google.protobuf.test.UnittestImport;
+import com.google.protobuf.test.UnittestImport.ImportEnum;
+import com.google.protobuf.test.UnittestImport.ImportEnumForMap;
+import protobuf_unittest.TestCustomOptions;
+import protobuf_unittest.UnittestCustomOptions;
+import protobuf_unittest.UnittestProto;
+import protobuf_unittest.UnittestProto.ForeignEnum;
+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 java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import junit.framework.TestCase;
+
+/**
+ * Unit test for {@link Descriptors}.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class DescriptorsTest extends TestCase {
+
+ // Regression test for bug where referencing a FieldDescriptor.Type value
+ // before a FieldDescriptorProto.Type value would yield a
+ // ExceptionInInitializerError.
+ @SuppressWarnings("unused")
+ private static final Object STATIC_INIT_TEST = FieldDescriptor.Type.BOOL;
+
+ public void testFieldTypeEnumMapping() throws Exception {
+ assertEquals(FieldDescriptor.Type.values().length,
+ FieldDescriptorProto.Type.values().length);
+ for (FieldDescriptor.Type type : FieldDescriptor.Type.values()) {
+ FieldDescriptorProto.Type protoType = type.toProto();
+ assertEquals("TYPE_" + type.name(), protoType.name());
+ assertEquals(type, FieldDescriptor.Type.valueOf(protoType));
+ }
+ }
+
+ public void testFileDescriptor() throws Exception {
+ FileDescriptor file = UnittestProto.getDescriptor();
+
+ assertEquals("google/protobuf/unittest.proto", file.getName());
+ assertEquals("protobuf_unittest", file.getPackage());
+
+ assertEquals("UnittestProto", file.getOptions().getJavaOuterClassname());
+ assertEquals("google/protobuf/unittest.proto",
+ file.toProto().getName());
+
+ assertEquals(Arrays.asList(UnittestImport.getDescriptor()),
+ file.getDependencies());
+
+ Descriptor messageType = TestAllTypes.getDescriptor();
+ assertEquals(messageType, file.getMessageTypes().get(0));
+ assertEquals(messageType, file.findMessageTypeByName("TestAllTypes"));
+ assertNull(file.findMessageTypeByName("NoSuchType"));
+ assertNull(file.findMessageTypeByName("protobuf_unittest.TestAllTypes"));
+ for (int i = 0; i < file.getMessageTypes().size(); i++) {
+ assertEquals(i, file.getMessageTypes().get(i).getIndex());
+ }
+
+ EnumDescriptor enumType = ForeignEnum.getDescriptor();
+ assertEquals(enumType, file.getEnumTypes().get(0));
+ assertEquals(enumType, file.findEnumTypeByName("ForeignEnum"));
+ assertNull(file.findEnumTypeByName("NoSuchType"));
+ assertNull(file.findEnumTypeByName("protobuf_unittest.ForeignEnum"));
+ assertEquals(Arrays.asList(ImportEnum.getDescriptor(),
+ ImportEnumForMap.getDescriptor()),
+ UnittestImport.getDescriptor().getEnumTypes());
+ for (int i = 0; i < file.getEnumTypes().size(); i++) {
+ assertEquals(i, file.getEnumTypes().get(i).getIndex());
+ }
+
+ ServiceDescriptor service = TestService.getDescriptor();
+ assertEquals(service, file.getServices().get(0));
+ assertEquals(service, file.findServiceByName("TestService"));
+ assertNull(file.findServiceByName("NoSuchType"));
+ assertNull(file.findServiceByName("protobuf_unittest.TestService"));
+ assertEquals(Collections.emptyList(),
+ UnittestImport.getDescriptor().getServices());
+ for (int i = 0; i < file.getServices().size(); i++) {
+ assertEquals(i, file.getServices().get(i).getIndex());
+ }
+
+ FieldDescriptor extension =
+ UnittestProto.optionalInt32Extension.getDescriptor();
+ assertEquals(extension, file.getExtensions().get(0));
+ assertEquals(extension,
+ file.findExtensionByName("optional_int32_extension"));
+ assertNull(file.findExtensionByName("no_such_ext"));
+ assertNull(file.findExtensionByName(
+ "protobuf_unittest.optional_int32_extension"));
+ assertEquals(Collections.emptyList(),
+ UnittestImport.getDescriptor().getExtensions());
+ for (int i = 0; i < file.getExtensions().size(); i++) {
+ assertEquals(i, file.getExtensions().get(i).getIndex());
+ }
+ }
+
+ public void testDescriptor() throws Exception {
+ Descriptor messageType = TestAllTypes.getDescriptor();
+ Descriptor nestedType = TestAllTypes.NestedMessage.getDescriptor();
+
+ assertEquals("TestAllTypes", messageType.getName());
+ assertEquals("protobuf_unittest.TestAllTypes", messageType.getFullName());
+ assertEquals(UnittestProto.getDescriptor(), messageType.getFile());
+ assertNull(messageType.getContainingType());
+ assertEquals(DescriptorProtos.MessageOptions.getDefaultInstance(),
+ messageType.getOptions());
+ assertEquals("TestAllTypes", messageType.toProto().getName());
+
+ assertEquals("NestedMessage", nestedType.getName());
+ assertEquals("protobuf_unittest.TestAllTypes.NestedMessage",
+ nestedType.getFullName());
+ assertEquals(UnittestProto.getDescriptor(), nestedType.getFile());
+ assertEquals(messageType, nestedType.getContainingType());
+
+ FieldDescriptor field = messageType.getFields().get(0);
+ assertEquals("optional_int32", field.getName());
+ assertEquals(field, messageType.findFieldByName("optional_int32"));
+ assertNull(messageType.findFieldByName("no_such_field"));
+ assertEquals(field, messageType.findFieldByNumber(1));
+ assertNull(messageType.findFieldByNumber(571283));
+ for (int i = 0; i < messageType.getFields().size(); i++) {
+ assertEquals(i, messageType.getFields().get(i).getIndex());
+ }
+
+ assertEquals(nestedType, messageType.getNestedTypes().get(0));
+ assertEquals(nestedType, messageType.findNestedTypeByName("NestedMessage"));
+ assertNull(messageType.findNestedTypeByName("NoSuchType"));
+ for (int i = 0; i < messageType.getNestedTypes().size(); i++) {
+ assertEquals(i, messageType.getNestedTypes().get(i).getIndex());
+ }
+
+ EnumDescriptor enumType = TestAllTypes.NestedEnum.getDescriptor();
+ assertEquals(enumType, messageType.getEnumTypes().get(0));
+ assertEquals(enumType, messageType.findEnumTypeByName("NestedEnum"));
+ assertNull(messageType.findEnumTypeByName("NoSuchType"));
+ for (int i = 0; i < messageType.getEnumTypes().size(); i++) {
+ assertEquals(i, messageType.getEnumTypes().get(i).getIndex());
+ }
+ }
+
+ public void testFieldDescriptor() throws Exception {
+ Descriptor messageType = TestAllTypes.getDescriptor();
+ FieldDescriptor primitiveField =
+ messageType.findFieldByName("optional_int32");
+ FieldDescriptor enumField =
+ messageType.findFieldByName("optional_nested_enum");
+ FieldDescriptor messageField =
+ messageType.findFieldByName("optional_foreign_message");
+ FieldDescriptor cordField =
+ messageType.findFieldByName("optional_cord");
+ FieldDescriptor extension =
+ UnittestProto.optionalInt32Extension.getDescriptor();
+ FieldDescriptor nestedExtension = TestRequired.single.getDescriptor();
+
+ assertEquals("optional_int32", primitiveField.getName());
+ assertEquals("protobuf_unittest.TestAllTypes.optional_int32",
+ primitiveField.getFullName());
+ assertEquals(1, primitiveField.getNumber());
+ assertEquals(messageType, primitiveField.getContainingType());
+ assertEquals(UnittestProto.getDescriptor(), primitiveField.getFile());
+ assertEquals(FieldDescriptor.Type.INT32, primitiveField.getType());
+ assertEquals(FieldDescriptor.JavaType.INT, primitiveField.getJavaType());
+ assertEquals(DescriptorProtos.FieldOptions.getDefaultInstance(),
+ primitiveField.getOptions());
+ assertFalse(primitiveField.isExtension());
+ assertEquals("optional_int32", primitiveField.toProto().getName());
+
+ assertEquals("optional_nested_enum", enumField.getName());
+ assertEquals(FieldDescriptor.Type.ENUM, enumField.getType());
+ assertEquals(FieldDescriptor.JavaType.ENUM, enumField.getJavaType());
+ assertEquals(TestAllTypes.NestedEnum.getDescriptor(),
+ enumField.getEnumType());
+
+ assertEquals("optional_foreign_message", messageField.getName());
+ assertEquals(FieldDescriptor.Type.MESSAGE, messageField.getType());
+ assertEquals(FieldDescriptor.JavaType.MESSAGE, messageField.getJavaType());
+ assertEquals(ForeignMessage.getDescriptor(), messageField.getMessageType());
+
+ assertEquals("optional_cord", cordField.getName());
+ assertEquals(FieldDescriptor.Type.STRING, cordField.getType());
+ assertEquals(FieldDescriptor.JavaType.STRING, cordField.getJavaType());
+ assertEquals(DescriptorProtos.FieldOptions.CType.CORD,
+ cordField.getOptions().getCtype());
+
+ assertEquals("optional_int32_extension", extension.getName());
+ assertEquals("protobuf_unittest.optional_int32_extension",
+ extension.getFullName());
+ assertEquals(1, extension.getNumber());
+ assertEquals(TestAllExtensions.getDescriptor(),
+ extension.getContainingType());
+ assertEquals(UnittestProto.getDescriptor(), extension.getFile());
+ assertEquals(FieldDescriptor.Type.INT32, extension.getType());
+ assertEquals(FieldDescriptor.JavaType.INT, extension.getJavaType());
+ assertEquals(DescriptorProtos.FieldOptions.getDefaultInstance(),
+ extension.getOptions());
+ assertTrue(extension.isExtension());
+ assertEquals(null, extension.getExtensionScope());
+ assertEquals("optional_int32_extension", extension.toProto().getName());
+
+ assertEquals("single", nestedExtension.getName());
+ assertEquals("protobuf_unittest.TestRequired.single",
+ nestedExtension.getFullName());
+ assertEquals(TestRequired.getDescriptor(),
+ nestedExtension.getExtensionScope());
+ }
+
+ public void testFieldDescriptorLabel() throws Exception {
+ FieldDescriptor requiredField =
+ TestRequired.getDescriptor().findFieldByName("a");
+ FieldDescriptor optionalField =
+ TestAllTypes.getDescriptor().findFieldByName("optional_int32");
+ FieldDescriptor repeatedField =
+ TestAllTypes.getDescriptor().findFieldByName("repeated_int32");
+
+ assertTrue(requiredField.isRequired());
+ assertFalse(requiredField.isRepeated());
+ assertFalse(optionalField.isRequired());
+ assertFalse(optionalField.isRepeated());
+ assertFalse(repeatedField.isRequired());
+ assertTrue(repeatedField.isRepeated());
+ }
+
+ public void testFieldDescriptorJsonName() throws Exception {
+ FieldDescriptor requiredField = TestRequired.getDescriptor().findFieldByName("a");
+ FieldDescriptor optionalField = TestAllTypes.getDescriptor().findFieldByName("optional_int32");
+ FieldDescriptor repeatedField = TestAllTypes.getDescriptor().findFieldByName("repeated_int32");
+ assertEquals("a", requiredField.getJsonName());
+ assertEquals("optionalInt32", optionalField.getJsonName());
+ assertEquals("repeatedInt32", repeatedField.getJsonName());
+ }
+
+ public void testFieldDescriptorDefault() throws Exception {
+ Descriptor d = TestAllTypes.getDescriptor();
+ assertFalse(d.findFieldByName("optional_int32").hasDefaultValue());
+ assertEquals(0, d.findFieldByName("optional_int32").getDefaultValue());
+ assertTrue(d.findFieldByName("default_int32").hasDefaultValue());
+ assertEquals(41, d.findFieldByName("default_int32").getDefaultValue());
+
+ d = TestExtremeDefaultValues.getDescriptor();
+ assertEquals(
+ ByteString.copyFrom(
+ "\0\001\007\b\f\n\r\t\013\\\'\"\u00fe".getBytes(Internal.ISO_8859_1)),
+ d.findFieldByName("escaped_bytes").getDefaultValue());
+ assertEquals(-1, d.findFieldByName("large_uint32").getDefaultValue());
+ assertEquals(-1L, d.findFieldByName("large_uint64").getDefaultValue());
+ }
+
+ public void testEnumDescriptor() throws Exception {
+ EnumDescriptor enumType = ForeignEnum.getDescriptor();
+ EnumDescriptor nestedType = TestAllTypes.NestedEnum.getDescriptor();
+
+ assertEquals("ForeignEnum", enumType.getName());
+ assertEquals("protobuf_unittest.ForeignEnum", enumType.getFullName());
+ assertEquals(UnittestProto.getDescriptor(), enumType.getFile());
+ assertNull(enumType.getContainingType());
+ assertEquals(DescriptorProtos.EnumOptions.getDefaultInstance(),
+ enumType.getOptions());
+
+ assertEquals("NestedEnum", nestedType.getName());
+ assertEquals("protobuf_unittest.TestAllTypes.NestedEnum",
+ nestedType.getFullName());
+ assertEquals(UnittestProto.getDescriptor(), nestedType.getFile());
+ assertEquals(TestAllTypes.getDescriptor(), nestedType.getContainingType());
+
+ EnumValueDescriptor value = ForeignEnum.FOREIGN_FOO.getValueDescriptor();
+ assertEquals(value, enumType.getValues().get(0));
+ assertEquals("FOREIGN_FOO", value.getName());
+ assertEquals("FOREIGN_FOO", value.toString());
+ assertEquals(4, value.getNumber());
+ assertEquals(value, enumType.findValueByName("FOREIGN_FOO"));
+ assertEquals(value, enumType.findValueByNumber(4));
+ assertNull(enumType.findValueByName("NO_SUCH_VALUE"));
+ for (int i = 0; i < enumType.getValues().size(); i++) {
+ assertEquals(i, enumType.getValues().get(i).getIndex());
+ }
+ }
+
+ public void testServiceDescriptor() throws Exception {
+ ServiceDescriptor service = TestService.getDescriptor();
+
+ assertEquals("TestService", service.getName());
+ assertEquals("protobuf_unittest.TestService", service.getFullName());
+ assertEquals(UnittestProto.getDescriptor(), service.getFile());
+
+
+ MethodDescriptor fooMethod = service.getMethods().get(0);
+ assertEquals("Foo", fooMethod.getName());
+ assertEquals(UnittestProto.FooRequest.getDescriptor(),
+ fooMethod.getInputType());
+ assertEquals(UnittestProto.FooResponse.getDescriptor(),
+ fooMethod.getOutputType());
+ assertEquals(fooMethod, service.findMethodByName("Foo"));
+
+ MethodDescriptor barMethod = service.getMethods().get(1);
+ assertEquals("Bar", barMethod.getName());
+ assertEquals(UnittestProto.BarRequest.getDescriptor(),
+ barMethod.getInputType());
+ assertEquals(UnittestProto.BarResponse.getDescriptor(),
+ barMethod.getOutputType());
+ assertEquals(barMethod, service.findMethodByName("Bar"));
+
+ assertNull(service.findMethodByName("NoSuchMethod"));
+
+ for (int i = 0; i < service.getMethods().size(); i++) {
+ assertEquals(i, service.getMethods().get(i).getIndex());
+ }
+ }
+
+
+ public void testCustomOptions() throws Exception {
+ // Get the descriptor indirectly from a dependent proto class. This is to
+ // ensure that when a proto class is loaded, custom options defined in its
+ // dependencies are also properly initialized.
+ Descriptor descriptor =
+ TestCustomOptions.TestMessageWithCustomOptionsContainer.getDescriptor()
+ .findFieldByName("field").getMessageType();
+
+ assertTrue(
+ descriptor.getOptions().hasExtension(UnittestCustomOptions.messageOpt1));
+ assertEquals(Integer.valueOf(-56),
+ descriptor.getOptions().getExtension(UnittestCustomOptions.messageOpt1));
+
+ FieldDescriptor field = descriptor.findFieldByName("field1");
+ assertNotNull(field);
+
+ assertTrue(
+ field.getOptions().hasExtension(UnittestCustomOptions.fieldOpt1));
+ assertEquals(Long.valueOf(8765432109L),
+ field.getOptions().getExtension(UnittestCustomOptions.fieldOpt1));
+
+ OneofDescriptor oneof = descriptor.getOneofs().get(0);
+ assertNotNull(oneof);
+
+ assertTrue(
+ oneof.getOptions().hasExtension(UnittestCustomOptions.oneofOpt1));
+ assertEquals(Integer.valueOf(-99),
+ oneof.getOptions().getExtension(UnittestCustomOptions.oneofOpt1));
+
+ EnumDescriptor enumType =
+ UnittestCustomOptions.TestMessageWithCustomOptions.AnEnum.getDescriptor();
+
+ assertTrue(
+ enumType.getOptions().hasExtension(UnittestCustomOptions.enumOpt1));
+ assertEquals(Integer.valueOf(-789),
+ enumType.getOptions().getExtension(UnittestCustomOptions.enumOpt1));
+
+ ServiceDescriptor service =
+ UnittestCustomOptions.TestServiceWithCustomOptions.getDescriptor();
+
+ assertTrue(
+ service.getOptions().hasExtension(UnittestCustomOptions.serviceOpt1));
+ assertEquals(Long.valueOf(-9876543210L),
+ service.getOptions().getExtension(UnittestCustomOptions.serviceOpt1));
+
+ MethodDescriptor method = service.findMethodByName("Foo");
+ assertNotNull(method);
+
+ assertTrue(
+ method.getOptions().hasExtension(UnittestCustomOptions.methodOpt1));
+ assertEquals(UnittestCustomOptions.MethodOpt1.METHODOPT1_VAL2,
+ method.getOptions().getExtension(UnittestCustomOptions.methodOpt1));
+ }
+
+ /**
+ * Test that the FieldDescriptor.Type enum is the same as the
+ * WireFormat.FieldType enum.
+ */
+ public void testFieldTypeTablesMatch() throws Exception {
+ FieldDescriptor.Type[] values1 = FieldDescriptor.Type.values();
+ WireFormat.FieldType[] values2 = WireFormat.FieldType.values();
+
+ assertEquals(values1.length, values2.length);
+
+ for (int i = 0; i < values1.length; i++) {
+ assertEquals(values1[i].toString(), values2[i].toString());
+ }
+ }
+
+ /**
+ * Test that the FieldDescriptor.JavaType enum is the same as the
+ * WireFormat.JavaType enum.
+ */
+ public void testJavaTypeTablesMatch() throws Exception {
+ FieldDescriptor.JavaType[] values1 = FieldDescriptor.JavaType.values();
+ WireFormat.JavaType[] values2 = WireFormat.JavaType.values();
+
+ assertEquals(values1.length, values2.length);
+
+ for (int i = 0; i < values1.length; i++) {
+ assertEquals(values1[i].toString(), values2[i].toString());
+ }
+ }
+
+ public void testEnormousDescriptor() throws Exception {
+ // The descriptor for this file is larger than 64k, yet it did not cause
+ // a compiler error due to an over-long string literal.
+ assertTrue(
+ UnittestEnormousDescriptor.getDescriptor()
+ .toProto().getSerializedSize() > 65536);
+ }
+
+ /**
+ * Tests that the DescriptorValidationException works as intended.
+ */
+ public void testDescriptorValidatorException() throws Exception {
+ FileDescriptorProto fileDescriptorProto = FileDescriptorProto.newBuilder()
+ .setName("foo.proto")
+ .addMessageType(DescriptorProto.newBuilder()
+ .setName("Foo")
+ .addField(FieldDescriptorProto.newBuilder()
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
+ .setType(FieldDescriptorProto.Type.TYPE_INT32)
+ .setName("foo")
+ .setNumber(1)
+ .setDefaultValue("invalid")
+ .build())
+ .build())
+ .build();
+ try {
+ Descriptors.FileDescriptor.buildFrom(fileDescriptorProto,
+ new FileDescriptor[0]);
+ fail("DescriptorValidationException expected");
+ } catch (DescriptorValidationException e) {
+ // Expected; check that the error message contains some useful hints
+ assertTrue(e.getMessage().indexOf("foo") != -1);
+ assertTrue(e.getMessage().indexOf("Foo") != -1);
+ assertTrue(e.getMessage().indexOf("invalid") != -1);
+ assertTrue(e.getCause() instanceof NumberFormatException);
+ assertTrue(e.getCause().getMessage().indexOf("invalid") != -1);
+ }
+ }
+
+ /**
+ * Tests the translate/crosslink for an example where a message field's name
+ * and type name are the same.
+ */
+ public void testDescriptorComplexCrosslink() throws Exception {
+ FileDescriptorProto fileDescriptorProto = FileDescriptorProto.newBuilder()
+ .setName("foo.proto")
+ .addMessageType(DescriptorProto.newBuilder()
+ .setName("Foo")
+ .addField(FieldDescriptorProto.newBuilder()
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
+ .setType(FieldDescriptorProto.Type.TYPE_INT32)
+ .setName("foo")
+ .setNumber(1)
+ .build())
+ .build())
+ .addMessageType(DescriptorProto.newBuilder()
+ .setName("Bar")
+ .addField(FieldDescriptorProto.newBuilder()
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
+ .setTypeName("Foo")
+ .setName("Foo")
+ .setNumber(1)
+ .build())
+ .build())
+ .build();
+ // translate and crosslink
+ FileDescriptor file =
+ Descriptors.FileDescriptor.buildFrom(fileDescriptorProto,
+ new FileDescriptor[0]);
+ // verify resulting descriptors
+ assertNotNull(file);
+ List<Descriptor> msglist = file.getMessageTypes();
+ assertNotNull(msglist);
+ assertTrue(msglist.size() == 2);
+ boolean barFound = false;
+ for (Descriptor desc : msglist) {
+ if (desc.getName().equals("Bar")) {
+ barFound = true;
+ assertNotNull(desc.getFields());
+ List<FieldDescriptor> fieldlist = desc.getFields();
+ assertNotNull(fieldlist);
+ assertTrue(fieldlist.size() == 1);
+ assertTrue(fieldlist.get(0).getType() == FieldDescriptor.Type.MESSAGE);
+ assertTrue(fieldlist.get(0).getMessageType().getName().equals("Foo"));
+ }
+ }
+ assertTrue(barFound);
+ }
+
+ public void testDependencyOrder() throws Exception {
+ FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
+ .setName("foo.proto").build();
+ FileDescriptorProto barProto = FileDescriptorProto.newBuilder()
+ .setName("bar.proto")
+ .addDependency("foo.proto")
+ .build();
+ FileDescriptorProto bazProto = FileDescriptorProto.newBuilder()
+ .setName("baz.proto")
+ .addDependency("foo.proto")
+ .addDependency("bar.proto")
+ .addPublicDependency(0)
+ .addPublicDependency(1)
+ .build();
+ FileDescriptor fooFile = Descriptors.FileDescriptor.buildFrom(fooProto,
+ new FileDescriptor[0]);
+ FileDescriptor barFile = Descriptors.FileDescriptor.buildFrom(barProto,
+ new FileDescriptor[] {fooFile});
+
+ // Items in the FileDescriptor array can be in any order.
+ Descriptors.FileDescriptor.buildFrom(bazProto,
+ new FileDescriptor[] {fooFile, barFile});
+ Descriptors.FileDescriptor.buildFrom(bazProto,
+ new FileDescriptor[] {barFile, fooFile});
+ }
+
+ public void testInvalidPublicDependency() throws Exception {
+ FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
+ .setName("foo.proto").build();
+ FileDescriptorProto barProto = FileDescriptorProto.newBuilder()
+ .setName("boo.proto")
+ .addDependency("foo.proto")
+ .addPublicDependency(1) // Error, should be 0.
+ .build();
+ FileDescriptor fooFile = Descriptors.FileDescriptor.buildFrom(fooProto,
+ new FileDescriptor[0]);
+ try {
+ Descriptors.FileDescriptor.buildFrom(barProto,
+ new FileDescriptor[] {fooFile});
+ fail("DescriptorValidationException expected");
+ } catch (DescriptorValidationException e) {
+ assertTrue(
+ e.getMessage().indexOf("Invalid public dependency index.") != -1);
+ }
+ }
+
+ public void testUnknownFieldsDenied() throws Exception {
+ FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
+ .setName("foo.proto")
+ .addMessageType(DescriptorProto.newBuilder()
+ .setName("Foo")
+ .addField(FieldDescriptorProto.newBuilder()
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
+ .setTypeName("Bar")
+ .setName("bar")
+ .setNumber(1)))
+ .build();
+
+ try {
+ Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[0]);
+ fail("DescriptorValidationException expected");
+ } catch (DescriptorValidationException e) {
+ assertTrue(e.getMessage().indexOf("Bar") != -1);
+ assertTrue(e.getMessage().indexOf("is not defined") != -1);
+ }
+ }
+
+ public void testUnknownFieldsAllowed() throws Exception {
+ FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
+ .setName("foo.proto")
+ .addDependency("bar.proto")
+ .addMessageType(DescriptorProto.newBuilder()
+ .setName("Foo")
+ .addField(FieldDescriptorProto.newBuilder()
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
+ .setTypeName("Bar")
+ .setName("bar")
+ .setNumber(1)))
+ .build();
+ Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[0], true);
+ }
+
+ public void testHiddenDependency() throws Exception {
+ FileDescriptorProto barProto = FileDescriptorProto.newBuilder()
+ .setName("bar.proto")
+ .addMessageType(DescriptorProto.newBuilder().setName("Bar"))
+ .build();
+ FileDescriptorProto forwardProto = FileDescriptorProto.newBuilder()
+ .setName("forward.proto")
+ .addDependency("bar.proto")
+ .build();
+ FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
+ .setName("foo.proto")
+ .addDependency("forward.proto")
+ .addMessageType(DescriptorProto.newBuilder()
+ .setName("Foo")
+ .addField(FieldDescriptorProto.newBuilder()
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
+ .setTypeName("Bar")
+ .setName("bar")
+ .setNumber(1)))
+ .build();
+ FileDescriptor barFile = Descriptors.FileDescriptor.buildFrom(
+ barProto, new FileDescriptor[0]);
+ FileDescriptor forwardFile = Descriptors.FileDescriptor.buildFrom(
+ forwardProto, new FileDescriptor[] {barFile});
+
+ try {
+ Descriptors.FileDescriptor.buildFrom(
+ fooProto, new FileDescriptor[] {forwardFile});
+ fail("DescriptorValidationException expected");
+ } catch (DescriptorValidationException e) {
+ assertTrue(e.getMessage().indexOf("Bar") != -1);
+ assertTrue(e.getMessage().indexOf("is not defined") != -1);
+ }
+ }
+
+ public void testPublicDependency() throws Exception {
+ FileDescriptorProto barProto = FileDescriptorProto.newBuilder()
+ .setName("bar.proto")
+ .addMessageType(DescriptorProto.newBuilder().setName("Bar"))
+ .build();
+ FileDescriptorProto forwardProto = FileDescriptorProto.newBuilder()
+ .setName("forward.proto")
+ .addDependency("bar.proto")
+ .addPublicDependency(0)
+ .build();
+ FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
+ .setName("foo.proto")
+ .addDependency("forward.proto")
+ .addMessageType(DescriptorProto.newBuilder()
+ .setName("Foo")
+ .addField(FieldDescriptorProto.newBuilder()
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
+ .setTypeName("Bar")
+ .setName("bar")
+ .setNumber(1)))
+ .build();
+ FileDescriptor barFile = Descriptors.FileDescriptor.buildFrom(
+ barProto, new FileDescriptor[0]);
+ FileDescriptor forwardFile = Descriptors.FileDescriptor.buildFrom(
+ forwardProto, new FileDescriptor[]{barFile});
+ Descriptors.FileDescriptor.buildFrom(
+ fooProto, new FileDescriptor[] {forwardFile});
+ }
+
+ /**
+ * Tests the translate/crosslink for an example with a more complex namespace
+ * referencing.
+ */
+ public void testComplexNamespacePublicDependency() throws Exception {
+ FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
+ .setName("bar.proto")
+ .setPackage("a.b.c.d.bar.shared")
+ .addEnumType(EnumDescriptorProto.newBuilder()
+ .setName("MyEnum")
+ .addValue(EnumValueDescriptorProto.newBuilder()
+ .setName("BLAH")
+ .setNumber(1)))
+ .build();
+ FileDescriptorProto barProto = FileDescriptorProto.newBuilder()
+ .setName("foo.proto")
+ .addDependency("bar.proto")
+ .setPackage("a.b.c.d.foo.shared")
+ .addMessageType(DescriptorProto.newBuilder()
+ .setName("MyMessage")
+ .addField(FieldDescriptorProto.newBuilder()
+ .setLabel(FieldDescriptorProto.Label.LABEL_REPEATED)
+ .setTypeName("bar.shared.MyEnum")
+ .setName("MyField")
+ .setNumber(1)))
+ .build();
+ // translate and crosslink
+ FileDescriptor fooFile = Descriptors.FileDescriptor.buildFrom(
+ fooProto, new FileDescriptor[0]);
+ FileDescriptor barFile = Descriptors.FileDescriptor.buildFrom(
+ barProto, new FileDescriptor[]{fooFile});
+ // verify resulting descriptors
+ assertNotNull(barFile);
+ List<Descriptor> msglist = barFile.getMessageTypes();
+ assertNotNull(msglist);
+ assertTrue(msglist.size() == 1);
+ Descriptor desc = msglist.get(0);
+ if (desc.getName().equals("MyMessage")) {
+ assertNotNull(desc.getFields());
+ List<FieldDescriptor> fieldlist = desc.getFields();
+ assertNotNull(fieldlist);
+ assertTrue(fieldlist.size() == 1);
+ FieldDescriptor field = fieldlist.get(0);
+ assertTrue(field.getType() == FieldDescriptor.Type.ENUM);
+ assertTrue(field.getEnumType().getName().equals("MyEnum"));
+ assertTrue(field.getEnumType().getFile().getName().equals("bar.proto"));
+ assertTrue(field.getEnumType().getFile().getPackage().equals(
+ "a.b.c.d.bar.shared"));
+ }
+ }
+
+ public void testOneofDescriptor() throws Exception {
+ Descriptor messageType = TestAllTypes.getDescriptor();
+ FieldDescriptor field =
+ messageType.findFieldByName("oneof_nested_message");
+ OneofDescriptor oneofDescriptor = field.getContainingOneof();
+ assertNotNull(oneofDescriptor);
+ assertSame(oneofDescriptor, messageType.getOneofs().get(0));
+ assertEquals("oneof_field", oneofDescriptor.getName());
+
+ assertEquals(4, oneofDescriptor.getFieldCount());
+ assertSame(oneofDescriptor.getField(1), field);
+
+ assertEquals(4, oneofDescriptor.getFields().size());
+ assertEquals(oneofDescriptor.getFields().get(1), field);
+ }
+
+ public void testMessageDescriptorExtensions() throws Exception {
+ assertFalse(TestAllTypes.getDescriptor().isExtendable());
+ assertTrue(TestAllExtensions.getDescriptor().isExtendable());
+ assertTrue(TestMultipleExtensionRanges.getDescriptor().isExtendable());
+
+ assertFalse(TestAllTypes.getDescriptor().isExtensionNumber(3));
+ assertTrue(TestAllExtensions.getDescriptor().isExtensionNumber(3));
+ assertTrue(TestMultipleExtensionRanges.getDescriptor().isExtensionNumber(42));
+ assertFalse(TestMultipleExtensionRanges.getDescriptor().isExtensionNumber(43));
+ assertFalse(TestMultipleExtensionRanges.getDescriptor().isExtensionNumber(4142));
+ assertTrue(TestMultipleExtensionRanges.getDescriptor().isExtensionNumber(4143));
+ }
+
+ public void testReservedFields() {
+ Descriptor d = TestReservedFields.getDescriptor();
+ assertTrue(d.isReservedNumber(2));
+ assertFalse(d.isReservedNumber(8));
+ assertTrue(d.isReservedNumber(9));
+ assertTrue(d.isReservedNumber(10));
+ assertTrue(d.isReservedNumber(11));
+ assertFalse(d.isReservedNumber(12));
+ assertFalse(d.isReservedName("foo"));
+ assertTrue(d.isReservedName("bar"));
+ assertTrue(d.isReservedName("baz"));
+ }
+
+ public void testToString() {
+ assertEquals("protobuf_unittest.TestAllTypes.optional_uint64",
+ UnittestProto.TestAllTypes.getDescriptor().findFieldByNumber(
+ UnittestProto.TestAllTypes.OPTIONAL_UINT64_FIELD_NUMBER).toString());
+ }
+
+ public void testPackedEnumField() throws Exception {
+ FileDescriptorProto fileDescriptorProto = FileDescriptorProto.newBuilder()
+ .setName("foo.proto")
+ .addEnumType(EnumDescriptorProto.newBuilder()
+ .setName("Enum")
+ .addValue(EnumValueDescriptorProto.newBuilder()
+ .setName("FOO")
+ .setNumber(1)
+ .build())
+ .build())
+ .addMessageType(DescriptorProto.newBuilder()
+ .setName("Message")
+ .addField(FieldDescriptorProto.newBuilder()
+ .setName("foo")
+ .setTypeName("Enum")
+ .setNumber(1)
+ .setLabel(FieldDescriptorProto.Label.LABEL_REPEATED)
+ .setOptions(DescriptorProtos.FieldOptions.newBuilder()
+ .setPacked(true)
+ .build())
+ .build())
+ .build())
+ .build();
+ 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/third_party/protobuf/java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java
new file mode 100644
index 0000000000..d894279297
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/DoubleArrayListTest.java
@@ -0,0 +1,461 @@
+// 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 static java.util.Arrays.asList;
+
+import java.util.Collections;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import junit.framework.TestCase;
+
+/**
+ * Tests for {@link DoubleArrayList}.
+ *
+ * @author dweis@google.com (Daniel Weis)
+ */
+public class DoubleArrayListTest extends TestCase {
+
+ private static final DoubleArrayList UNARY_LIST =
+ newImmutableDoubleArrayList(1);
+ private static final DoubleArrayList TERTIARY_LIST =
+ newImmutableDoubleArrayList(1, 2, 3);
+
+ private DoubleArrayList list;
+
+ @Override
+ protected void setUp() throws Exception {
+ list = new DoubleArrayList();
+ }
+
+ public void testEmptyListReturnsSameInstance() {
+ assertSame(DoubleArrayList.emptyList(), DoubleArrayList.emptyList());
+ }
+
+ public void testEmptyListIsImmutable() {
+ assertImmutable(DoubleArrayList.emptyList());
+ }
+
+ public void testMakeImmutable() {
+ list.addDouble(3);
+ list.addDouble(4);
+ list.addDouble(5);
+ list.addDouble(7);
+ list.makeImmutable();
+ assertImmutable(list);
+ }
+
+ public void testModificationWithIteration() {
+ list.addAll(asList(1D, 2D, 3D, 4D));
+ Iterator<Double> iterator = list.iterator();
+ assertEquals(4, list.size());
+ assertEquals(1D, (double) list.get(0));
+ assertEquals(1D, (double) iterator.next());
+ list.set(0, 1D);
+ assertEquals(2D, (double) iterator.next());
+
+ list.remove(0);
+ try {
+ iterator.next();
+ fail();
+ } catch (ConcurrentModificationException e) {
+ // expected
+ }
+
+ iterator = list.iterator();
+ list.add(0, 0D);
+ try {
+ iterator.next();
+ fail();
+ } catch (ConcurrentModificationException e) {
+ // expected
+ }
+ }
+
+ public void testGet() {
+ assertEquals(1D, (double) TERTIARY_LIST.get(0));
+ assertEquals(2D, (double) TERTIARY_LIST.get(1));
+ assertEquals(3D, (double) TERTIARY_LIST.get(2));
+
+ try {
+ TERTIARY_LIST.get(-1);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ TERTIARY_LIST.get(3);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testGetDouble() {
+ assertEquals(1D, TERTIARY_LIST.getDouble(0));
+ assertEquals(2D, TERTIARY_LIST.getDouble(1));
+ assertEquals(3D, TERTIARY_LIST.getDouble(2));
+
+ try {
+ TERTIARY_LIST.get(-1);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ TERTIARY_LIST.get(3);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testSize() {
+ assertEquals(0, DoubleArrayList.emptyList().size());
+ assertEquals(1, UNARY_LIST.size());
+ assertEquals(3, TERTIARY_LIST.size());
+
+ list.addDouble(3);
+ list.addDouble(4);
+ list.addDouble(6);
+ list.addDouble(8);
+ assertEquals(4, list.size());
+
+ list.remove(0);
+ assertEquals(3, list.size());
+
+ list.add(17D);
+ assertEquals(4, list.size());
+ }
+
+ public void testSet() {
+ list.addDouble(2);
+ list.addDouble(4);
+
+ assertEquals(2D, (double) list.set(0, 3D));
+ assertEquals(3D, list.getDouble(0));
+
+ assertEquals(4D, (double) list.set(1, 0D));
+ assertEquals(0D, list.getDouble(1));
+
+ try {
+ list.set(-1, 0D);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.set(2, 0D);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testSetDouble() {
+ list.addDouble(1);
+ list.addDouble(3);
+
+ assertEquals(1D, list.setDouble(0, 0));
+ assertEquals(0D, list.getDouble(0));
+
+ assertEquals(3D, list.setDouble(1, 0));
+ assertEquals(0D, list.getDouble(1));
+
+ try {
+ list.setDouble(-1, 0);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.setDouble(2, 0);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testAdd() {
+ assertEquals(0, list.size());
+
+ assertTrue(list.add(2D));
+ assertEquals(asList(2D), list);
+
+ assertTrue(list.add(3D));
+ list.add(0, 4D);
+ assertEquals(asList(4D, 2D, 3D), list);
+
+ list.add(0, 1D);
+ list.add(0, 0D);
+ // Force a resize by getting up to 11 elements.
+ for (int i = 0; i < 6; i++) {
+ list.add(Double.valueOf(5 + i));
+ }
+ assertEquals(
+ asList(0D, 1D, 4D, 2D, 3D, 5D, 6D, 7D, 8D, 9D, 10D),
+ list);
+
+ try {
+ list.add(-1, 5D);
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.add(4, 5D);
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testAddDouble() {
+ assertEquals(0, list.size());
+
+ list.addDouble(2);
+ assertEquals(asList(2D), list);
+
+ list.addDouble(3);
+ assertEquals(asList(2D, 3D), list);
+ }
+
+ public void testAddAll() {
+ assertEquals(0, list.size());
+
+ assertTrue(list.addAll(Collections.singleton(1D)));
+ assertEquals(1, list.size());
+ assertEquals(1D, (double) list.get(0));
+ assertEquals(1D, list.getDouble(0));
+
+ assertTrue(list.addAll(asList(2D, 3D, 4D, 5D, 6D)));
+ assertEquals(asList(1D, 2D, 3D, 4D, 5D, 6D), list);
+
+ assertTrue(list.addAll(TERTIARY_LIST));
+ assertEquals(asList(1D, 2D, 3D, 4D, 5D, 6D, 1D, 2D, 3D), list);
+
+ assertFalse(list.addAll(Collections.<Double>emptyList()));
+ assertFalse(list.addAll(DoubleArrayList.emptyList()));
+ }
+
+ public void testRemove() {
+ list.addAll(TERTIARY_LIST);
+ assertEquals(1D, (double) list.remove(0));
+ assertEquals(asList(2D, 3D), list);
+
+ assertTrue(list.remove(Double.valueOf(3)));
+ assertEquals(asList(2D), list);
+
+ assertFalse(list.remove(Double.valueOf(3)));
+ assertEquals(asList(2D), list);
+
+ assertEquals(2D, (double) list.remove(0));
+ assertEquals(asList(), list);
+
+ try {
+ list.remove(-1);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.remove(0);
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ private void assertImmutable(DoubleArrayList list) {
+ if (list.contains(1D)) {
+ throw new RuntimeException("Cannot test the immutability of lists that contain 1.");
+ }
+
+ try {
+ list.add(1D);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.add(0, 1D);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(Collections.<Double>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(Collections.singletonList(1D));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(new DoubleArrayList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, Collections.singleton(1D));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, Collections.<Double>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addDouble(0);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.clear();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.remove(1);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.remove(new Object());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(Collections.<Double>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(Collections.singleton(1D));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(Collections.<Double>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(Collections.singleton(1D));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.set(0, 0D);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.setDouble(0, 0);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ private static DoubleArrayList newImmutableDoubleArrayList(double... elements) {
+ DoubleArrayList list = new DoubleArrayList();
+ for (double element : elements) {
+ list.addDouble(element);
+ }
+ list.makeImmutable();
+ return list;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java
new file mode 100644
index 0000000000..77d14f6b3a
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/DynamicMessageTest.java
@@ -0,0 +1,324 @@
+// 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.EnumDescriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+import com.google.protobuf.Descriptors.OneofDescriptor;
+import protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestEmptyMessage;
+import protobuf_unittest.UnittestProto.TestPackedTypes;
+import java.util.Arrays;
+import junit.framework.TestCase;
+
+/**
+ * Unit test for {@link DynamicMessage}. See also {@link MessageTest}, which
+ * tests some {@link DynamicMessage} functionality.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class DynamicMessageTest extends TestCase {
+ TestUtil.ReflectionTester reflectionTester =
+ new TestUtil.ReflectionTester(TestAllTypes.getDescriptor(), null);
+
+ TestUtil.ReflectionTester extensionsReflectionTester =
+ new TestUtil.ReflectionTester(TestAllExtensions.getDescriptor(),
+ TestUtil.getExtensionRegistry());
+ TestUtil.ReflectionTester packedReflectionTester =
+ new TestUtil.ReflectionTester(TestPackedTypes.getDescriptor(), null);
+
+ public void testDynamicMessageAccessors() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ reflectionTester.setAllFieldsViaReflection(builder);
+ Message message = builder.build();
+ reflectionTester.assertAllFieldsSetViaReflection(message);
+ }
+
+ public void testSettersAfterBuild() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ Message firstMessage = builder.build();
+ // double build()
+ builder.build();
+ // clear() after build()
+ builder.clear();
+ // setters after build()
+ reflectionTester.setAllFieldsViaReflection(builder);
+ Message message = builder.build();
+ reflectionTester.assertAllFieldsSetViaReflection(message);
+ // repeated setters after build()
+ reflectionTester.modifyRepeatedFieldsViaReflection(builder);
+ message = builder.build();
+ reflectionTester.assertRepeatedFieldsModifiedViaReflection(message);
+ // firstMessage shouldn't have been modified.
+ reflectionTester.assertClearViaReflection(firstMessage);
+ }
+
+ public void testUnknownFields() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestEmptyMessage.getDescriptor());
+ builder.setUnknownFields(UnknownFieldSet.newBuilder()
+ .addField(1, UnknownFieldSet.Field.newBuilder().addVarint(1).build())
+ .addField(2, UnknownFieldSet.Field.newBuilder().addFixed32(1).build())
+ .build());
+ Message message = builder.build();
+ assertEquals(2, message.getUnknownFields().asMap().size());
+ // clone() with unknown fields
+ Message.Builder newBuilder = builder.clone();
+ assertEquals(2, newBuilder.getUnknownFields().asMap().size());
+ // clear() with unknown fields
+ newBuilder.clear();
+ assertTrue(newBuilder.getUnknownFields().asMap().isEmpty());
+ // serialize/parse with unknown fields
+ newBuilder.mergeFrom(message.toByteString());
+ assertEquals(2, newBuilder.getUnknownFields().asMap().size());
+ }
+
+ public void testDynamicMessageSettersRejectNull() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ reflectionTester.assertReflectionSettersRejectNull(builder);
+ }
+
+ public void testDynamicMessageExtensionAccessors() throws Exception {
+ // We don't need to extensively test DynamicMessage's handling of
+ // extensions because, frankly, it doesn't do anything special with them.
+ // It treats them just like any other fields.
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestAllExtensions.getDescriptor());
+ extensionsReflectionTester.setAllFieldsViaReflection(builder);
+ Message message = builder.build();
+ extensionsReflectionTester.assertAllFieldsSetViaReflection(message);
+ }
+
+ public void testDynamicMessageExtensionSettersRejectNull() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestAllExtensions.getDescriptor());
+ extensionsReflectionTester.assertReflectionSettersRejectNull(builder);
+ }
+
+ public void testDynamicMessageRepeatedSetters() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ reflectionTester.setAllFieldsViaReflection(builder);
+ reflectionTester.modifyRepeatedFieldsViaReflection(builder);
+ Message message = builder.build();
+ reflectionTester.assertRepeatedFieldsModifiedViaReflection(message);
+ }
+
+ public void testDynamicMessageRepeatedSettersRejectNull() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ reflectionTester.assertReflectionRepeatedSettersRejectNull(builder);
+ }
+
+ public void testDynamicMessageDefaults() throws Exception {
+ reflectionTester.assertClearViaReflection(
+ DynamicMessage.getDefaultInstance(TestAllTypes.getDescriptor()));
+ reflectionTester.assertClearViaReflection(
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor()).build());
+ }
+
+ public void testDynamicMessageSerializedSize() throws Exception {
+ TestAllTypes message = TestUtil.getAllSet();
+
+ Message.Builder dynamicBuilder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ reflectionTester.setAllFieldsViaReflection(dynamicBuilder);
+ Message dynamicMessage = dynamicBuilder.build();
+
+ assertEquals(message.getSerializedSize(),
+ dynamicMessage.getSerializedSize());
+ }
+
+ public void testDynamicMessageSerialization() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ reflectionTester.setAllFieldsViaReflection(builder);
+ Message message = builder.build();
+
+ ByteString rawBytes = message.toByteString();
+ TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
+
+ TestUtil.assertAllFieldsSet(message2);
+
+ // In fact, the serialized forms should be exactly the same, byte-for-byte.
+ assertEquals(TestUtil.getAllSet().toByteString(), rawBytes);
+ }
+
+ public void testDynamicMessageParsing() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ TestAllTypes message = builder.build();
+
+ ByteString rawBytes = message.toByteString();
+
+ Message message2 =
+ DynamicMessage.parseFrom(TestAllTypes.getDescriptor(), rawBytes);
+ reflectionTester.assertAllFieldsSetViaReflection(message2);
+
+ // Test Parser interface.
+ Message message3 = message2.getParserForType().parseFrom(rawBytes);
+ reflectionTester.assertAllFieldsSetViaReflection(message3);
+ }
+
+ public void testDynamicMessageExtensionParsing() throws Exception {
+ ByteString rawBytes = TestUtil.getAllExtensionsSet().toByteString();
+ Message message = DynamicMessage.parseFrom(
+ TestAllExtensions.getDescriptor(), rawBytes,
+ TestUtil.getExtensionRegistry());
+ extensionsReflectionTester.assertAllFieldsSetViaReflection(message);
+
+ // Test Parser interface.
+ Message message2 = message.getParserForType().parseFrom(
+ rawBytes, TestUtil.getExtensionRegistry());
+ extensionsReflectionTester.assertAllFieldsSetViaReflection(message2);
+ }
+
+ public void testDynamicMessagePackedSerialization() throws Exception {
+ Message.Builder builder =
+ DynamicMessage.newBuilder(TestPackedTypes.getDescriptor());
+ packedReflectionTester.setPackedFieldsViaReflection(builder);
+ Message message = builder.build();
+
+ ByteString rawBytes = message.toByteString();
+ TestPackedTypes message2 = TestPackedTypes.parseFrom(rawBytes);
+
+ TestUtil.assertPackedFieldsSet(message2);
+
+ // In fact, the serialized forms should be exactly the same, byte-for-byte.
+ assertEquals(TestUtil.getPackedSet().toByteString(), rawBytes);
+ }
+
+ public void testDynamicMessagePackedParsing() throws Exception {
+ TestPackedTypes.Builder builder = TestPackedTypes.newBuilder();
+ TestUtil.setPackedFields(builder);
+ TestPackedTypes message = builder.build();
+
+ ByteString rawBytes = message.toByteString();
+
+ Message message2 =
+ DynamicMessage.parseFrom(TestPackedTypes.getDescriptor(), rawBytes);
+ packedReflectionTester.assertPackedFieldsSetViaReflection(message2);
+
+ // Test Parser interface.
+ Message message3 = message2.getParserForType().parseFrom(rawBytes);
+ packedReflectionTester.assertPackedFieldsSetViaReflection(message3);
+ }
+
+ public void testDynamicMessageCopy() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ TestAllTypes message = builder.build();
+
+ DynamicMessage copy = DynamicMessage.newBuilder(message).build();
+ reflectionTester.assertAllFieldsSetViaReflection(copy);
+
+ // Test oneof behavior
+ FieldDescriptor bytesField =
+ TestAllTypes.getDescriptor().findFieldByName("oneof_bytes");
+ FieldDescriptor uint32Field =
+ TestAllTypes.getDescriptor().findFieldByName("oneof_uint32");
+ assertTrue(copy.hasField(bytesField));
+ assertFalse(copy.hasField(uint32Field));
+ DynamicMessage copy2 =
+ DynamicMessage.newBuilder(message).setField(uint32Field, 123).build();
+ assertFalse(copy2.hasField(bytesField));
+ assertTrue(copy2.hasField(uint32Field));
+ assertEquals(123, copy2.getField(uint32Field));
+ }
+
+ public void testToBuilder() throws Exception {
+ DynamicMessage.Builder builder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ reflectionTester.setAllFieldsViaReflection(builder);
+ int unknownFieldNum = 9;
+ long unknownFieldVal = 90;
+ builder.setUnknownFields(UnknownFieldSet.newBuilder()
+ .addField(unknownFieldNum,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(unknownFieldVal).build())
+ .build());
+ DynamicMessage message = builder.build();
+
+ DynamicMessage derived = message.toBuilder().build();
+ reflectionTester.assertAllFieldsSetViaReflection(derived);
+ assertEquals(Arrays.asList(unknownFieldVal),
+ derived.getUnknownFields().getField(unknownFieldNum).getVarintList());
+ }
+
+ public void testDynamicOneofMessage() throws Exception {
+ DynamicMessage.Builder builder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ OneofDescriptor oneof = TestAllTypes.getDescriptor().getOneofs().get(0);
+ assertFalse(builder.hasOneof(oneof));
+ assertSame(null, builder.getOneofFieldDescriptor(oneof));
+
+ reflectionTester.setAllFieldsViaReflection(builder);
+ assertTrue(builder.hasOneof(oneof));
+ FieldDescriptor field = oneof.getField(3);
+ assertSame(field, builder.getOneofFieldDescriptor(oneof));
+
+ DynamicMessage message = builder.buildPartial();
+ assertTrue(message.hasOneof(oneof));
+
+ DynamicMessage.Builder mergedBuilder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ FieldDescriptor mergedField = oneof.getField(0);
+ mergedBuilder.setField(mergedField, 123);
+ assertTrue(mergedBuilder.hasField(mergedField));
+ mergedBuilder.mergeFrom(message);
+ assertTrue(mergedBuilder.hasField(field));
+ assertFalse(mergedBuilder.hasField(mergedField));
+
+ builder.clearOneof(oneof);
+ assertSame(null, builder.getOneofFieldDescriptor(oneof));
+ message = builder.build();
+ assertSame(null, message.getOneofFieldDescriptor(oneof));
+ }
+
+ // Regression test for a bug that makes setField() not work for repeated
+ // enum fields.
+ public void testSettersForRepeatedEnumField() throws Exception {
+ DynamicMessage.Builder builder =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor());
+ FieldDescriptor repeatedEnumField =
+ TestAllTypes.getDescriptor().findFieldByName(
+ "repeated_nested_enum");
+ EnumDescriptor enumDescriptor = TestAllTypes.NestedEnum.getDescriptor();
+ builder.setField(repeatedEnumField, enumDescriptor.getValues());
+ DynamicMessage message = builder.build();
+ assertEquals(
+ enumDescriptor.getValues(), message.getField(repeatedEnumField));
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/EnumTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/EnumTest.java
new file mode 100644
index 0000000000..14c7406b3d
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/EnumTest.java
@@ -0,0 +1,76 @@
+// 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.UnittestLite.ForeignEnumLite;
+import com.google.protobuf.UnittestLite.TestAllTypesLite;
+import protobuf_unittest.UnittestProto.ForeignEnum;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+
+import junit.framework.TestCase;
+
+public class EnumTest extends TestCase {
+
+ public void testForNumber() {
+ ForeignEnum e = ForeignEnum.forNumber(ForeignEnum.FOREIGN_BAR.getNumber());
+ assertEquals(ForeignEnum.FOREIGN_BAR, e);
+
+ e = ForeignEnum.forNumber(1000);
+ assertEquals(null, e);
+ }
+
+ public void testForNumber_oneof() {
+ TestAllTypes.OneofFieldCase e = TestAllTypes.OneofFieldCase.forNumber(
+ TestAllTypes.OneofFieldCase.ONEOF_NESTED_MESSAGE.getNumber());
+ assertEquals(TestAllTypes.OneofFieldCase.ONEOF_NESTED_MESSAGE, e);
+
+ e = TestAllTypes.OneofFieldCase.forNumber(1000);
+ assertEquals(null, e);
+ }
+
+ public void testForNumberLite() {
+ ForeignEnumLite e = ForeignEnumLite.forNumber(ForeignEnumLite.FOREIGN_LITE_BAR.getNumber());
+ assertEquals(ForeignEnumLite.FOREIGN_LITE_BAR, e);
+
+ e = ForeignEnumLite.forNumber(1000);
+ assertEquals(null, e);
+ }
+
+ public void testForNumberLite_oneof() {
+ TestAllTypesLite.OneofFieldCase e = TestAllTypesLite.OneofFieldCase.forNumber(
+ TestAllTypesLite.OneofFieldCase.ONEOF_NESTED_MESSAGE.getNumber());
+ assertEquals(TestAllTypesLite.OneofFieldCase.ONEOF_NESTED_MESSAGE, e);
+
+ e = TestAllTypesLite.OneofFieldCase.forNumber(1000);
+ assertEquals(null, e);
+ }
+}
+
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ExtensionRegistryFactoryTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ExtensionRegistryFactoryTest.java
new file mode 100644
index 0000000000..6157e58966
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ExtensionRegistryFactoryTest.java
@@ -0,0 +1,276 @@
+// 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 protobuf_unittest.NonNestedExtension;
+import protobuf_unittest.NonNestedExtensionLite;
+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.
+ *
+ * <p>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.
+ *
+ * <p>The test mechanism employed here is based on the pattern in
+ * {@code com.google.common.util.concurrent.AbstractFutureFallbackAtomicHelperTest}
+ */
+public class ExtensionRegistryFactoryTest extends TestCase {
+
+ // A classloader which blacklists some non-Lite classes.
+ private static final ClassLoader LITE_CLASS_LOADER = getLiteOnlyClassLoader();
+
+ /**
+ * Defines the set of test methods which will be run.
+ */
+ static interface RegistryTests {
+ void testCreate();
+ void testEmpty();
+ void testIsFullRegistry();
+ void testAdd();
+ void testAdd_immutable();
+ }
+
+ /**
+ * Test implementations for the non-Lite usage of ExtensionRegistryFactory.
+ */
+ public static class InnerTest implements RegistryTests {
+
+ @Override
+ public void testCreate() {
+ ExtensionRegistryLite registry = ExtensionRegistryFactory.create();
+
+ assertEquals(registry.getClass(), ExtensionRegistry.class);
+ }
+
+ @Override
+ public void testEmpty() {
+ ExtensionRegistryLite emptyRegistry = ExtensionRegistryFactory.createEmpty();
+
+ assertEquals(emptyRegistry.getClass(), ExtensionRegistry.class);
+ assertEquals(emptyRegistry, ExtensionRegistry.EMPTY_REGISTRY);
+ }
+
+ @Override
+ public void testIsFullRegistry() {
+ ExtensionRegistryLite registry = ExtensionRegistryFactory.create();
+ assertTrue(ExtensionRegistryFactory.isFullRegistry(registry));
+ }
+
+ @Override
+ public void testAdd() {
+ ExtensionRegistryLite registry1 = ExtensionRegistryLite.newInstance();
+ NonNestedExtensionLite.registerAllExtensions(registry1);
+ registry1.add(NonNestedExtensionLite.nonNestedExtensionLite);
+
+ ExtensionRegistryLite registry2 = ExtensionRegistryLite.newInstance();
+ NonNestedExtension.registerAllExtensions((ExtensionRegistry) registry2);
+ registry2.add(NonNestedExtension.nonNestedExtension);
+
+ ExtensionRegistry fullRegistry1 = (ExtensionRegistry) registry1;
+ ExtensionRegistry fullRegistry2 = (ExtensionRegistry) registry2;
+
+ assertTrue("Test is using a non-lite extension",
+ GeneratedMessageLite.GeneratedExtension.class.isAssignableFrom(
+ NonNestedExtensionLite.nonNestedExtensionLite.getClass()));
+ assertNull("Extension is not registered in masqueraded full registry",
+ fullRegistry1.findImmutableExtensionByName("protobuf_unittest.nonNestedExtension"));
+ GeneratedMessageLite.GeneratedExtension<NonNestedExtensionLite.MessageLiteToBeExtended, ?>
+ extension = registry1.findLiteExtensionByNumber(
+ NonNestedExtensionLite.MessageLiteToBeExtended.getDefaultInstance(), 1);
+ assertNotNull("Extension registered in lite registry", extension);
+
+ assertTrue("Test is using a non-lite extension",
+ GeneratedMessage.GeneratedExtension.class.isAssignableFrom(
+ NonNestedExtension.nonNestedExtension.getClass()));
+ 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) {}
+ }
+ }
+
+ /**
+ * Test implementations for the Lite usage of ExtensionRegistryFactory.
+ */
+ public static final class InnerLiteTest implements RegistryTests {
+
+ @Override
+ public void testCreate() {
+ ExtensionRegistryLite registry = ExtensionRegistryFactory.create();
+
+ assertEquals(registry.getClass(), ExtensionRegistryLite.class);
+ }
+
+ @Override
+ public void testEmpty() {
+ ExtensionRegistryLite emptyRegistry = ExtensionRegistryFactory.createEmpty();
+
+ assertEquals(emptyRegistry.getClass(), ExtensionRegistryLite.class);
+ assertEquals(emptyRegistry, ExtensionRegistryLite.EMPTY_REGISTRY_LITE);
+ }
+
+ @Override
+ public void testIsFullRegistry() {
+ ExtensionRegistryLite registry = ExtensionRegistryFactory.create();
+ assertFalse(ExtensionRegistryFactory.isFullRegistry(registry));
+ }
+
+ @Override
+ public void testAdd() {
+ ExtensionRegistryLite registry = ExtensionRegistryLite.newInstance();
+ NonNestedExtensionLite.registerAllExtensions(registry);
+ GeneratedMessageLite.GeneratedExtension<NonNestedExtensionLite.MessageLiteToBeExtended, ?>
+ extension = registry.findLiteExtensionByNumber(
+ 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() {
+ TestSuite suite = new TestSuite();
+ for (Method method : RegistryTests.class.getMethods()) {
+ suite.addTest(TestSuite.createTest(ExtensionRegistryFactoryTest.class, method.getName()));
+ }
+ return suite;
+ }
+
+ /**
+ * Sequentially runs first the Lite and then the non-Lite test variant via classloader
+ * manipulation.
+ */
+ @Override
+ public void runTest() throws Exception {
+ ClassLoader storedClassLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(LITE_CLASS_LOADER);
+ try {
+ runTestMethod(LITE_CLASS_LOADER, InnerLiteTest.class);
+ } finally {
+ Thread.currentThread().setContextClassLoader(storedClassLoader);
+ }
+ try {
+ runTestMethod(storedClassLoader, InnerTest.class);
+ } finally {
+ Thread.currentThread().setContextClassLoader(storedClassLoader);
+ }
+ }
+
+ private void runTestMethod(ClassLoader classLoader, Class<? extends RegistryTests> testClass)
+ throws Exception {
+ classLoader.loadClass(ExtensionRegistryFactory.class.getName());
+ Class<?> test = classLoader.loadClass(testClass.getName());
+ String testName = getName();
+ test.getMethod(testName).invoke(test.newInstance());
+ }
+
+ /**
+ * Constructs a custom ClassLoader blacklisting the classes which are inspected in the SUT
+ * to determine the Lite/non-Lite runtime.
+ */
+ private static ClassLoader getLiteOnlyClassLoader() {
+ ClassLoader testClassLoader = ExtensionRegistryFactoryTest.class.getClassLoader();
+ final Set<String> classNamesNotInLite =
+ Collections.unmodifiableSet(
+ new HashSet<String>(
+ Arrays.asList(
+ ExtensionRegistryFactory.FULL_REGISTRY_CLASS_NAME,
+ ExtensionRegistry.EXTENSION_CLASS_NAME)));
+
+ // Construct a URLClassLoader delegating to the system ClassLoader, and looking up classes
+ // in jar files based on the URLs already configured for this test's UrlClassLoader.
+ // Certain classes throw a ClassNotFoundException by design.
+ return new URLClassLoader(((URLClassLoader) testClassLoader).getURLs(),
+ ClassLoader.getSystemClassLoader()) {
+ @Override
+ public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
+ if (classNamesNotInLite.contains(name)) {
+ throw new ClassNotFoundException("Class deliberately blacklisted by test.");
+ }
+ Class<?> loadedClass = null;
+ try {
+ loadedClass = findLoadedClass(name);
+ if (loadedClass == null) {
+ loadedClass = findClass(name);
+ if (resolve) {
+ resolveClass(loadedClass);
+ }
+ }
+ } catch (ClassNotFoundException e) {
+ loadedClass = super.loadClass(name, resolve);
+ }
+ return loadedClass;
+ }
+ };
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java
new file mode 100644
index 0000000000..4a42c8970e
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java
@@ -0,0 +1,443 @@
+// 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.Descriptor;
+import com.google.protobuf.Descriptors.EnumDescriptor;
+import com.google.protobuf.Descriptors.EnumValueDescriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+import com.google.protobuf.FieldPresenceTestProto.TestAllTypes;
+import com.google.protobuf.FieldPresenceTestProto.TestOptionalFieldsOnly;
+import com.google.protobuf.FieldPresenceTestProto.TestRepeatedFieldsOnly;
+import protobuf_unittest.UnittestProto;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for protos that doesn't support field presence test for optional
+ * non-message fields.
+ */
+public class FieldPresenceTest extends TestCase {
+ private static boolean hasMethod(Class<?> clazz, String name) {
+ try {
+ if (clazz.getMethod(name) != null) {
+ return true;
+ } else {
+ return false;
+ }
+ } catch (NoSuchMethodException e) {
+ return false;
+ }
+ }
+
+ private static void assertHasMethodRemoved(
+ Class<?> classWithFieldPresence,
+ Class<?> classWithoutFieldPresence,
+ String camelName) {
+ assertTrue(hasMethod(classWithFieldPresence, "get" + camelName));
+ assertTrue(hasMethod(classWithFieldPresence, "has" + camelName));
+ assertTrue(hasMethod(classWithoutFieldPresence, "get" + camelName));
+ assertFalse(hasMethod(classWithoutFieldPresence, "has" + camelName));
+ }
+
+ public void testHasMethod() {
+ // Optional non-message fields don't have a hasFoo() method generated.
+ assertHasMethodRemoved(
+ UnittestProto.TestAllTypes.class,
+ TestAllTypes.class,
+ "OptionalInt32");
+ assertHasMethodRemoved(
+ UnittestProto.TestAllTypes.class,
+ TestAllTypes.class,
+ "OptionalString");
+ assertHasMethodRemoved(
+ UnittestProto.TestAllTypes.class,
+ TestAllTypes.class,
+ "OptionalBytes");
+ assertHasMethodRemoved(
+ UnittestProto.TestAllTypes.class,
+ TestAllTypes.class,
+ "OptionalNestedEnum");
+
+ assertHasMethodRemoved(
+ UnittestProto.TestAllTypes.Builder.class,
+ TestAllTypes.Builder.class,
+ "OptionalInt32");
+ assertHasMethodRemoved(
+ UnittestProto.TestAllTypes.Builder.class,
+ TestAllTypes.Builder.class,
+ "OptionalString");
+ assertHasMethodRemoved(
+ UnittestProto.TestAllTypes.Builder.class,
+ TestAllTypes.Builder.class,
+ "OptionalBytes");
+ assertHasMethodRemoved(
+ UnittestProto.TestAllTypes.Builder.class,
+ TestAllTypes.Builder.class,
+ "OptionalNestedEnum");
+
+ // message fields still have the hasFoo() method generated.
+ assertFalse(TestAllTypes.newBuilder().build().hasOptionalNestedMessage());
+ assertFalse(TestAllTypes.newBuilder().hasOptionalNestedMessage());
+
+ // oneof fields don't have hasFoo() methods (even for message types).
+ assertHasMethodRemoved(
+ UnittestProto.TestAllTypes.class,
+ TestAllTypes.class,
+ "OneofUint32");
+ assertHasMethodRemoved(
+ UnittestProto.TestAllTypes.class,
+ TestAllTypes.class,
+ "OneofString");
+ assertHasMethodRemoved(
+ UnittestProto.TestAllTypes.class,
+ TestAllTypes.class,
+ "OneofBytes");
+ assertHasMethodRemoved(
+ UnittestProto.TestAllTypes.class,
+ TestAllTypes.class,
+ "OneofNestedMessage");
+
+ assertHasMethodRemoved(
+ UnittestProto.TestAllTypes.Builder.class,
+ TestAllTypes.Builder.class,
+ "OneofUint32");
+ assertHasMethodRemoved(
+ UnittestProto.TestAllTypes.Builder.class,
+ TestAllTypes.Builder.class,
+ "OneofString");
+ assertHasMethodRemoved(
+ UnittestProto.TestAllTypes.Builder.class,
+ TestAllTypes.Builder.class,
+ "OneofBytes");
+ assertHasMethodRemoved(
+ UnittestProto.TestAllTypes.Builder.class,
+ TestAllTypes.Builder.class,
+ "OneofNestedMessage");
+ }
+
+ public void testOneofEquals() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestAllTypes message1 = builder.build();
+ // Set message2's oneof_uint32 field to defalut value. The two
+ // messages should be different when check with oneof case.
+ builder.setOneofUint32(0);
+ TestAllTypes message2 = builder.build();
+ assertFalse(message1.equals(message2));
+ }
+
+ public void testLazyField() throws Exception {
+ // Test default constructed message.
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestAllTypes message = builder.build();
+ assertFalse(message.hasOptionalLazyMessage());
+ assertEquals(0, message.getSerializedSize());
+ assertEquals(ByteString.EMPTY, message.toByteString());
+
+ // Set default instance to the field.
+ builder.setOptionalLazyMessage(TestAllTypes.NestedMessage.getDefaultInstance());
+ message = builder.build();
+ assertTrue(message.hasOptionalLazyMessage());
+ assertEquals(2, message.getSerializedSize());
+
+ // Test parse zero-length from wire sets the presence.
+ TestAllTypes parsed = TestAllTypes.parseFrom(message.toByteString());
+ assertTrue(parsed.hasOptionalLazyMessage());
+ assertEquals(message.getOptionalLazyMessage(), parsed.getOptionalLazyMessage());
+ }
+
+ public void testFieldPresence() {
+ // Optional non-message fields set to their default value are treated the
+ // same way as not set.
+
+ // Serialization will ignore such fields.
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ builder.setOptionalInt32(0);
+ builder.setOptionalString("");
+ builder.setOptionalBytes(ByteString.EMPTY);
+ builder.setOptionalNestedEnum(TestAllTypes.NestedEnum.FOO);
+ TestAllTypes message = builder.build();
+ assertEquals(0, message.getSerializedSize());
+
+ // mergeFrom() will ignore such fields.
+ TestAllTypes.Builder a = TestAllTypes.newBuilder();
+ a.setOptionalInt32(1);
+ a.setOptionalString("x");
+ a.setOptionalBytes(ByteString.copyFromUtf8("y"));
+ a.setOptionalNestedEnum(TestAllTypes.NestedEnum.BAR);
+ TestAllTypes.Builder b = TestAllTypes.newBuilder();
+ b.setOptionalInt32(0);
+ b.setOptionalString("");
+ b.setOptionalBytes(ByteString.EMPTY);
+ b.setOptionalNestedEnum(TestAllTypes.NestedEnum.FOO);
+ a.mergeFrom(b.build());
+ message = a.build();
+ assertEquals(1, message.getOptionalInt32());
+ assertEquals("x", message.getOptionalString());
+ assertEquals(ByteString.copyFromUtf8("y"), message.getOptionalBytes());
+ assertEquals(TestAllTypes.NestedEnum.BAR, message.getOptionalNestedEnum());
+
+ // equals()/hashCode() should produce the same results.
+ TestAllTypes empty = TestAllTypes.newBuilder().build();
+ message = builder.build();
+ assertTrue(empty.equals(message));
+ assertTrue(message.equals(empty));
+ assertEquals(empty.hashCode(), message.hashCode());
+ }
+
+ public void testFieldPresenceByReflection() {
+ Descriptor descriptor = TestAllTypes.getDescriptor();
+ FieldDescriptor optionalInt32Field = descriptor.findFieldByName("optional_int32");
+ FieldDescriptor optionalStringField = descriptor.findFieldByName("optional_string");
+ FieldDescriptor optionalBytesField = descriptor.findFieldByName("optional_bytes");
+ FieldDescriptor optionalNestedEnumField = descriptor.findFieldByName("optional_nested_enum");
+
+ // Field not present.
+ TestAllTypes message = TestAllTypes.newBuilder().build();
+ assertFalse(message.hasField(optionalInt32Field));
+ assertFalse(message.hasField(optionalStringField));
+ assertFalse(message.hasField(optionalBytesField));
+ assertFalse(message.hasField(optionalNestedEnumField));
+ assertEquals(0, message.getAllFields().size());
+
+ // Field set to default value is seen as not present.
+ message = TestAllTypes.newBuilder()
+ .setOptionalInt32(0)
+ .setOptionalString("")
+ .setOptionalBytes(ByteString.EMPTY)
+ .setOptionalNestedEnum(TestAllTypes.NestedEnum.FOO)
+ .build();
+ assertFalse(message.hasField(optionalInt32Field));
+ assertFalse(message.hasField(optionalStringField));
+ assertFalse(message.hasField(optionalBytesField));
+ assertFalse(message.hasField(optionalNestedEnumField));
+ assertEquals(0, message.getAllFields().size());
+
+ // Field set to non-default value is seen as present.
+ message = TestAllTypes.newBuilder()
+ .setOptionalInt32(1)
+ .setOptionalString("x")
+ .setOptionalBytes(ByteString.copyFromUtf8("y"))
+ .setOptionalNestedEnum(TestAllTypes.NestedEnum.BAR)
+ .build();
+ assertTrue(message.hasField(optionalInt32Field));
+ assertTrue(message.hasField(optionalStringField));
+ assertTrue(message.hasField(optionalBytesField));
+ assertTrue(message.hasField(optionalNestedEnumField));
+ assertEquals(4, message.getAllFields().size());
+ }
+
+ public void testFieldPresenceDynamicMessage() {
+ Descriptor descriptor = TestAllTypes.getDescriptor();
+ FieldDescriptor optionalInt32Field = descriptor.findFieldByName("optional_int32");
+ FieldDescriptor optionalStringField = descriptor.findFieldByName("optional_string");
+ FieldDescriptor optionalBytesField = descriptor.findFieldByName("optional_bytes");
+ FieldDescriptor optionalNestedEnumField = descriptor.findFieldByName("optional_nested_enum");
+ EnumDescriptor enumDescriptor = optionalNestedEnumField.getEnumType();
+ EnumValueDescriptor defaultEnumValueDescriptor = enumDescriptor.getValues().get(0);
+ EnumValueDescriptor nonDefaultEnumValueDescriptor = enumDescriptor.getValues().get(1);
+
+ DynamicMessage defaultInstance = DynamicMessage.getDefaultInstance(descriptor);
+ // Field not present.
+ DynamicMessage message = defaultInstance.newBuilderForType().build();
+ assertFalse(message.hasField(optionalInt32Field));
+ assertFalse(message.hasField(optionalStringField));
+ assertFalse(message.hasField(optionalBytesField));
+ assertFalse(message.hasField(optionalNestedEnumField));
+ assertEquals(0, message.getAllFields().size());
+
+ // Field set to non-default value is seen as present.
+ message =
+ defaultInstance
+ .newBuilderForType()
+ .setField(optionalInt32Field, 1)
+ .setField(optionalStringField, "x")
+ .setField(optionalBytesField, ByteString.copyFromUtf8("y"))
+ .setField(optionalNestedEnumField, nonDefaultEnumValueDescriptor)
+ .build();
+ assertTrue(message.hasField(optionalInt32Field));
+ assertTrue(message.hasField(optionalStringField));
+ assertTrue(message.hasField(optionalBytesField));
+ assertTrue(message.hasField(optionalNestedEnumField));
+ assertEquals(4, message.getAllFields().size());
+
+ // Field set to default value is seen as not present.
+ message = message.toBuilder()
+ .setField(optionalInt32Field, 0)
+ .setField(optionalStringField, "")
+ .setField(optionalBytesField, ByteString.EMPTY)
+ .setField(optionalNestedEnumField, defaultEnumValueDescriptor)
+ .build();
+ assertFalse(message.hasField(optionalInt32Field));
+ assertFalse(message.hasField(optionalStringField));
+ assertFalse(message.hasField(optionalBytesField));
+ assertFalse(message.hasField(optionalNestedEnumField));
+ assertEquals(0, message.getAllFields().size());
+ }
+
+ public void testMessageField() {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ assertFalse(builder.hasOptionalNestedMessage());
+ assertFalse(builder.build().hasOptionalNestedMessage());
+
+ TestAllTypes.NestedMessage.Builder nestedBuilder =
+ builder.getOptionalNestedMessageBuilder();
+ assertTrue(builder.hasOptionalNestedMessage());
+ assertTrue(builder.build().hasOptionalNestedMessage());
+
+ nestedBuilder.setValue(1);
+ assertEquals(1, builder.build().getOptionalNestedMessage().getValue());
+
+ builder.clearOptionalNestedMessage();
+ assertFalse(builder.hasOptionalNestedMessage());
+ assertFalse(builder.build().hasOptionalNestedMessage());
+
+ // Unlike non-message fields, if we set a message field to its default value (i.e.,
+ // default instance), the field should be seen as present.
+ builder.setOptionalNestedMessage(TestAllTypes.NestedMessage.getDefaultInstance());
+ assertTrue(builder.hasOptionalNestedMessage());
+ assertTrue(builder.build().hasOptionalNestedMessage());
+ }
+
+ public void testSerializeAndParse() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ builder.setOptionalInt32(1234);
+ builder.setOptionalString("hello");
+ builder.setOptionalNestedMessage(TestAllTypes.NestedMessage.getDefaultInstance());
+ // Set an oneof field to its default value and expect it to be serialized (i.e.,
+ // an oneof field set to the default value should be treated as present).
+ builder.setOneofInt32(0);
+ ByteString data = builder.build().toByteString();
+
+ TestAllTypes message = TestAllTypes.parseFrom(data);
+ assertEquals(1234, message.getOptionalInt32());
+ assertEquals("hello", message.getOptionalString());
+ // Fields not set will have the default value.
+ assertEquals(ByteString.EMPTY, message.getOptionalBytes());
+ assertEquals(TestAllTypes.NestedEnum.FOO, message.getOptionalNestedEnum());
+ // The message field is set despite that it's set with a default instance.
+ assertTrue(message.hasOptionalNestedMessage());
+ assertEquals(0, message.getOptionalNestedMessage().getValue());
+ // The oneof field set to its default value is also present.
+ assertEquals(
+ TestAllTypes.OneofFieldCase.ONEOF_INT32, message.getOneofFieldCase());
+ }
+
+ // Regression test for b/16173397
+ // Make sure we haven't screwed up the code generation for repeated fields.
+ public void testRepeatedFields() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ builder.setOptionalInt32(1234);
+ builder.setOptionalString("hello");
+ builder.setOptionalNestedMessage(TestAllTypes.NestedMessage.getDefaultInstance());
+ builder.addRepeatedInt32(4321);
+ builder.addRepeatedString("world");
+ builder.addRepeatedNestedMessage(TestAllTypes.NestedMessage.getDefaultInstance());
+ ByteString data = builder.build().toByteString();
+
+ TestOptionalFieldsOnly optionalOnlyMessage = TestOptionalFieldsOnly.parseFrom(data);
+ assertEquals(1234, optionalOnlyMessage.getOptionalInt32());
+ assertEquals("hello", optionalOnlyMessage.getOptionalString());
+ assertTrue(optionalOnlyMessage.hasOptionalNestedMessage());
+ assertEquals(0, optionalOnlyMessage.getOptionalNestedMessage().getValue());
+
+ TestRepeatedFieldsOnly repeatedOnlyMessage = TestRepeatedFieldsOnly.parseFrom(data);
+ assertEquals(1, repeatedOnlyMessage.getRepeatedInt32Count());
+ assertEquals(4321, repeatedOnlyMessage.getRepeatedInt32(0));
+ assertEquals(1, repeatedOnlyMessage.getRepeatedStringCount());
+ assertEquals("world", repeatedOnlyMessage.getRepeatedString(0));
+ assertEquals(1, repeatedOnlyMessage.getRepeatedNestedMessageCount());
+ assertEquals(0, repeatedOnlyMessage.getRepeatedNestedMessage(0).getValue());
+ }
+
+ public void testIsInitialized() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+
+ // Test optional proto2 message fields.
+ UnittestProto.TestRequired.Builder proto2Builder =
+ builder.getOptionalProto2MessageBuilder();
+ assertFalse(builder.isInitialized());
+ assertFalse(builder.buildPartial().isInitialized());
+
+ proto2Builder.setA(1).setB(2).setC(3);
+ assertTrue(builder.isInitialized());
+ assertTrue(builder.buildPartial().isInitialized());
+
+ // Test oneof proto2 message fields.
+ proto2Builder = builder.getOneofProto2MessageBuilder();
+ assertFalse(builder.isInitialized());
+ assertFalse(builder.buildPartial().isInitialized());
+
+ proto2Builder.setA(1).setB(2).setC(3);
+ assertTrue(builder.isInitialized());
+ assertTrue(builder.buildPartial().isInitialized());
+
+ // Test repeated proto2 message fields.
+ proto2Builder = builder.addRepeatedProto2MessageBuilder();
+ assertFalse(builder.isInitialized());
+ assertFalse(builder.buildPartial().isInitialized());
+
+ proto2Builder.setA(1).setB(2).setC(3);
+ assertTrue(builder.isInitialized());
+ assertTrue(builder.buildPartial().isInitialized());
+ }
+
+
+ // Test that unknown fields are dropped.
+ public void testUnknownFields() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ builder.setOptionalInt32(1234);
+ builder.addRepeatedInt32(5678);
+ TestAllTypes message = builder.build();
+ ByteString data = message.toByteString();
+
+ TestOptionalFieldsOnly optionalOnlyMessage =
+ TestOptionalFieldsOnly.parseFrom(data);
+ // UnknownFieldSet should be empty.
+ assertEquals(
+ 0, optionalOnlyMessage.getUnknownFields().toByteString().size());
+ assertEquals(1234, optionalOnlyMessage.getOptionalInt32());
+ message = TestAllTypes.parseFrom(optionalOnlyMessage.toByteString());
+ assertEquals(1234, message.getOptionalInt32());
+ // The repeated field is discarded because it's unknown to the optional-only
+ // message.
+ assertEquals(0, message.getRepeatedInt32Count());
+
+ DynamicMessage dynamicOptionalOnlyMessage =
+ DynamicMessage.getDefaultInstance(
+ TestOptionalFieldsOnly.getDescriptor())
+ .getParserForType().parseFrom(data);
+ assertEquals(
+ 0, dynamicOptionalOnlyMessage.getUnknownFields().toByteString().size());
+ assertEquals(optionalOnlyMessage.toByteString(),
+ dynamicOptionalOnlyMessage.toByteString());
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java
new file mode 100644
index 0000000000..aa36be4977
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/FloatArrayListTest.java
@@ -0,0 +1,461 @@
+// 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 static java.util.Arrays.asList;
+
+import java.util.Collections;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import junit.framework.TestCase;
+
+/**
+ * Tests for {@link FloatArrayList}.
+ *
+ * @author dweis@google.com (Daniel Weis)
+ */
+public class FloatArrayListTest extends TestCase {
+
+ private static final FloatArrayList UNARY_LIST =
+ newImmutableFloatArrayList(1);
+ private static final FloatArrayList TERTIARY_LIST =
+ newImmutableFloatArrayList(1, 2, 3);
+
+ private FloatArrayList list;
+
+ @Override
+ protected void setUp() throws Exception {
+ list = new FloatArrayList();
+ }
+
+ public void testEmptyListReturnsSameInstance() {
+ assertSame(FloatArrayList.emptyList(), FloatArrayList.emptyList());
+ }
+
+ public void testEmptyListIsImmutable() {
+ assertImmutable(FloatArrayList.emptyList());
+ }
+
+ public void testMakeImmutable() {
+ list.addFloat(3);
+ list.addFloat(4);
+ list.addFloat(5);
+ list.addFloat(7);
+ list.makeImmutable();
+ assertImmutable(list);
+ }
+
+ public void testModificationWithIteration() {
+ list.addAll(asList(1F, 2F, 3F, 4F));
+ Iterator<Float> iterator = list.iterator();
+ assertEquals(4, list.size());
+ assertEquals(1F, (float) list.get(0));
+ assertEquals(1F, (float) iterator.next());
+ list.set(0, 1F);
+ assertEquals(2F, (float) iterator.next());
+
+ list.remove(0);
+ try {
+ iterator.next();
+ fail();
+ } catch (ConcurrentModificationException e) {
+ // expected
+ }
+
+ iterator = list.iterator();
+ list.add(0, 0F);
+ try {
+ iterator.next();
+ fail();
+ } catch (ConcurrentModificationException e) {
+ // expected
+ }
+ }
+
+ public void testGet() {
+ assertEquals(1F, (float) TERTIARY_LIST.get(0));
+ assertEquals(2F, (float) TERTIARY_LIST.get(1));
+ assertEquals(3F, (float) TERTIARY_LIST.get(2));
+
+ try {
+ TERTIARY_LIST.get(-1);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ TERTIARY_LIST.get(3);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testGetFloat() {
+ assertEquals(1F, TERTIARY_LIST.getFloat(0));
+ assertEquals(2F, TERTIARY_LIST.getFloat(1));
+ assertEquals(3F, TERTIARY_LIST.getFloat(2));
+
+ try {
+ TERTIARY_LIST.get(-1);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ TERTIARY_LIST.get(3);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testSize() {
+ assertEquals(0, FloatArrayList.emptyList().size());
+ assertEquals(1, UNARY_LIST.size());
+ assertEquals(3, TERTIARY_LIST.size());
+
+ list.addFloat(3);
+ list.addFloat(4);
+ list.addFloat(6);
+ list.addFloat(8);
+ assertEquals(4, list.size());
+
+ list.remove(0);
+ assertEquals(3, list.size());
+
+ list.add(17F);
+ assertEquals(4, list.size());
+ }
+
+ public void testSet() {
+ list.addFloat(2);
+ list.addFloat(4);
+
+ assertEquals(2F, (float) list.set(0, 3F));
+ assertEquals(3F, list.getFloat(0));
+
+ assertEquals(4F, (float) list.set(1, 0F));
+ assertEquals(0F, list.getFloat(1));
+
+ try {
+ list.set(-1, 0F);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.set(2, 0F);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testSetFloat() {
+ list.addFloat(1);
+ list.addFloat(3);
+
+ assertEquals(1F, list.setFloat(0, 0));
+ assertEquals(0F, list.getFloat(0));
+
+ assertEquals(3F, list.setFloat(1, 0));
+ assertEquals(0F, list.getFloat(1));
+
+ try {
+ list.setFloat(-1, 0);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.setFloat(2, 0);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testAdd() {
+ assertEquals(0, list.size());
+
+ assertTrue(list.add(2F));
+ assertEquals(asList(2F), list);
+
+ assertTrue(list.add(3F));
+ list.add(0, 4F);
+ assertEquals(asList(4F, 2F, 3F), list);
+
+ list.add(0, 1F);
+ list.add(0, 0F);
+ // Force a resize by getting up to 11 elements.
+ for (int i = 0; i < 6; i++) {
+ list.add(Float.valueOf(5 + i));
+ }
+ assertEquals(
+ asList(0F, 1F, 4F, 2F, 3F, 5F, 6F, 7F, 8F, 9F, 10F),
+ list);
+
+ try {
+ list.add(-1, 5F);
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.add(4, 5F);
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testAddFloat() {
+ assertEquals(0, list.size());
+
+ list.addFloat(2);
+ assertEquals(asList(2F), list);
+
+ list.addFloat(3);
+ assertEquals(asList(2F, 3F), list);
+ }
+
+ public void testAddAll() {
+ assertEquals(0, list.size());
+
+ assertTrue(list.addAll(Collections.singleton(1F)));
+ assertEquals(1, list.size());
+ assertEquals(1F, (float) list.get(0));
+ assertEquals(1F, list.getFloat(0));
+
+ assertTrue(list.addAll(asList(2F, 3F, 4F, 5F, 6F)));
+ assertEquals(asList(1F, 2F, 3F, 4F, 5F, 6F), list);
+
+ assertTrue(list.addAll(TERTIARY_LIST));
+ assertEquals(asList(1F, 2F, 3F, 4F, 5F, 6F, 1F, 2F, 3F), list);
+
+ assertFalse(list.addAll(Collections.<Float>emptyList()));
+ assertFalse(list.addAll(FloatArrayList.emptyList()));
+ }
+
+ public void testRemove() {
+ list.addAll(TERTIARY_LIST);
+ assertEquals(1F, (float) list.remove(0));
+ assertEquals(asList(2F, 3F), list);
+
+ assertTrue(list.remove(Float.valueOf(3)));
+ assertEquals(asList(2F), list);
+
+ assertFalse(list.remove(Float.valueOf(3)));
+ assertEquals(asList(2F), list);
+
+ assertEquals(2F, (float) list.remove(0));
+ assertEquals(asList(), list);
+
+ try {
+ list.remove(-1);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.remove(0);
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ private void assertImmutable(FloatArrayList list) {
+ if (list.contains(1F)) {
+ throw new RuntimeException("Cannot test the immutability of lists that contain 1.");
+ }
+
+ try {
+ list.add(1F);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.add(0, 1F);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(Collections.<Float>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(Collections.singletonList(1F));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(new FloatArrayList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, Collections.singleton(1F));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, Collections.<Float>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addFloat(0);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.clear();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.remove(1);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.remove(new Object());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(Collections.<Float>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(Collections.singleton(1F));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(Collections.<Float>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(Collections.singleton(1F));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.set(0, 0F);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.setFloat(0, 0);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ private static FloatArrayList newImmutableFloatArrayList(float... elements) {
+ FloatArrayList list = new FloatArrayList();
+ for (float element : elements) {
+ list.addFloat(element);
+ }
+ list.makeImmutable();
+ return list;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java
new file mode 100644
index 0000000000..b7eaebf5e2
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java
@@ -0,0 +1,48 @@
+// 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;
+
+/**
+ * A prerun for a test suite that allows running the full protocol buffer
+ * tests in a mode that disables the optimization for not using
+ * {@link RepeatedFieldBuilder} and {@link SingleFieldBuilder} until they are
+ * requested. This allows us to run all the tests through both code paths
+ * and ensures that both code paths produce identical results.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class ForceFieldBuildersPreRun implements Runnable {
+
+ @Override
+ public void run() {
+ GeneratedMessage.enableAlwaysUseFieldBuildersForTesting();
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java
new file mode 100644
index 0000000000..3eece26a4a
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java
@@ -0,0 +1,1674 @@
+// 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.Descriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+import com.google.protobuf.UnittestLite.TestAllExtensionsLite;
+import com.google.protobuf.test.UnittestImport;
+import protobuf_unittest.EnumWithNoOuter;
+import protobuf_unittest.MessageWithNoOuter;
+import protobuf_unittest.MultipleFilesTestProto;
+import protobuf_unittest.NestedExtension.MyNestedExtension;
+import protobuf_unittest.NestedExtensionLite.MyNestedExtensionLite;
+import protobuf_unittest.NonNestedExtension;
+import protobuf_unittest.NonNestedExtension.MessageToBeExtended;
+import protobuf_unittest.NonNestedExtension.MyNonNestedExtension;
+import protobuf_unittest.NonNestedExtensionLite;
+import protobuf_unittest.NonNestedExtensionLite.MessageLiteToBeExtended;
+import protobuf_unittest.NonNestedExtensionLite.MyNonNestedExtensionLite;
+import protobuf_unittest.OuterClassNameTest2OuterClass;
+import protobuf_unittest.OuterClassNameTest3OuterClass;
+import protobuf_unittest.OuterClassNameTestOuterClass;
+import protobuf_unittest.ServiceWithNoOuter;
+import protobuf_unittest.UnittestOptimizeFor.TestOptimizedForSize;
+import protobuf_unittest.UnittestOptimizeFor.TestOptionalOptimizedForSize;
+import protobuf_unittest.UnittestOptimizeFor.TestRequiredOptimizedForSize;
+import protobuf_unittest.UnittestProto;
+import protobuf_unittest.UnittestProto.ForeignEnum;
+import protobuf_unittest.UnittestProto.ForeignMessage;
+import protobuf_unittest.UnittestProto.ForeignMessageOrBuilder;
+import protobuf_unittest.UnittestProto.NestedTestAllTypes;
+import protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestAllTypes.NestedMessage;
+import protobuf_unittest.UnittestProto.TestAllTypesOrBuilder;
+import protobuf_unittest.UnittestProto.TestExtremeDefaultValues;
+import protobuf_unittest.UnittestProto.TestOneof2;
+import protobuf_unittest.UnittestProto.TestPackedTypes;
+import protobuf_unittest.UnittestProto.TestUnpackedTypes;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+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
+ * {@link MessageTest}, which tests some generated message functionality.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class GeneratedMessageTest extends TestCase {
+ TestUtil.ReflectionTester reflectionTester =
+ new TestUtil.ReflectionTester(TestAllTypes.getDescriptor(), null);
+
+ public void testDefaultInstance() throws Exception {
+ assertSame(TestAllTypes.getDefaultInstance(),
+ TestAllTypes.getDefaultInstance().getDefaultInstanceForType());
+ assertSame(TestAllTypes.getDefaultInstance(),
+ TestAllTypes.newBuilder().getDefaultInstanceForType());
+ }
+
+ public void testMessageOrBuilder() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ TestAllTypes message = builder.build();
+ TestUtil.assertAllFieldsSet(message);
+ }
+
+ public void testUsingBuilderMultipleTimes() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ // primitive field scalar and repeated
+ builder.setOptionalSfixed64(100);
+ builder.addRepeatedInt32(100);
+ // enum field scalar and repeated
+ builder.setOptionalImportEnum(UnittestImport.ImportEnum.IMPORT_BAR);
+ builder.addRepeatedImportEnum(UnittestImport.ImportEnum.IMPORT_BAR);
+ // proto field scalar and repeated
+ builder.setOptionalForeignMessage(ForeignMessage.newBuilder().setC(1));
+ builder.addRepeatedForeignMessage(ForeignMessage.newBuilder().setC(1));
+
+ TestAllTypes value1 = builder.build();
+
+ assertEquals(100, value1.getOptionalSfixed64());
+ assertEquals(100, value1.getRepeatedInt32(0));
+ assertEquals(UnittestImport.ImportEnum.IMPORT_BAR,
+ value1.getOptionalImportEnum());
+ assertEquals(UnittestImport.ImportEnum.IMPORT_BAR,
+ value1.getRepeatedImportEnum(0));
+ assertEquals(1, value1.getOptionalForeignMessage().getC());
+ assertEquals(1, value1.getRepeatedForeignMessage(0).getC());
+
+ // Make sure that builder didn't update previously created values
+ builder.setOptionalSfixed64(200);
+ builder.setRepeatedInt32(0, 200);
+ builder.setOptionalImportEnum(UnittestImport.ImportEnum.IMPORT_FOO);
+ builder.setRepeatedImportEnum(0, UnittestImport.ImportEnum.IMPORT_FOO);
+ builder.setOptionalForeignMessage(ForeignMessage.newBuilder().setC(2));
+ builder.setRepeatedForeignMessage(0, ForeignMessage.newBuilder().setC(2));
+
+ TestAllTypes value2 = builder.build();
+
+ // Make sure value1 didn't change.
+ assertEquals(100, value1.getOptionalSfixed64());
+ assertEquals(100, value1.getRepeatedInt32(0));
+ assertEquals(UnittestImport.ImportEnum.IMPORT_BAR,
+ value1.getOptionalImportEnum());
+ assertEquals(UnittestImport.ImportEnum.IMPORT_BAR,
+ value1.getRepeatedImportEnum(0));
+ assertEquals(1, value1.getOptionalForeignMessage().getC());
+ assertEquals(1, value1.getRepeatedForeignMessage(0).getC());
+
+ // Make sure value2 is correct
+ assertEquals(200, value2.getOptionalSfixed64());
+ assertEquals(200, value2.getRepeatedInt32(0));
+ assertEquals(UnittestImport.ImportEnum.IMPORT_FOO,
+ value2.getOptionalImportEnum());
+ assertEquals(UnittestImport.ImportEnum.IMPORT_FOO,
+ value2.getRepeatedImportEnum(0));
+ assertEquals(2, value2.getOptionalForeignMessage().getC());
+ assertEquals(2, value2.getRepeatedForeignMessage(0).getC());
+ }
+
+ public void testProtosShareRepeatedArraysIfDidntChange() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ builder.addRepeatedInt32(100);
+ builder.addRepeatedForeignMessage(ForeignMessage.getDefaultInstance());
+
+ TestAllTypes value1 = builder.build();
+ TestAllTypes value2 = value1.toBuilder().build();
+
+ assertSame(value1.getRepeatedInt32List(), value2.getRepeatedInt32List());
+ assertSame(value1.getRepeatedForeignMessageList(),
+ value2.getRepeatedForeignMessageList());
+ }
+
+ public void testRepeatedArraysAreImmutable() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ builder.addRepeatedInt32(100);
+ builder.addRepeatedImportEnum(UnittestImport.ImportEnum.IMPORT_BAR);
+ builder.addRepeatedForeignMessage(ForeignMessage.getDefaultInstance());
+ assertIsUnmodifiable(builder.getRepeatedInt32List());
+ assertIsUnmodifiable(builder.getRepeatedImportEnumList());
+ assertIsUnmodifiable(builder.getRepeatedForeignMessageList());
+ assertIsUnmodifiable(builder.getRepeatedFloatList());
+
+
+ TestAllTypes value = builder.build();
+ assertIsUnmodifiable(value.getRepeatedInt32List());
+ assertIsUnmodifiable(value.getRepeatedImportEnumList());
+ assertIsUnmodifiable(value.getRepeatedForeignMessageList());
+ assertIsUnmodifiable(value.getRepeatedFloatList());
+ }
+
+ public void testParsedMessagesAreImmutable() throws Exception {
+ TestAllTypes value = TestAllTypes.parser().parseFrom(TestUtil.getAllSet().toByteString());
+ assertIsUnmodifiable(value.getRepeatedInt32List());
+ assertIsUnmodifiable(value.getRepeatedInt64List());
+ assertIsUnmodifiable(value.getRepeatedUint32List());
+ assertIsUnmodifiable(value.getRepeatedUint64List());
+ assertIsUnmodifiable(value.getRepeatedSint32List());
+ assertIsUnmodifiable(value.getRepeatedSint64List());
+ assertIsUnmodifiable(value.getRepeatedFixed32List());
+ assertIsUnmodifiable(value.getRepeatedFixed64List());
+ assertIsUnmodifiable(value.getRepeatedSfixed32List());
+ assertIsUnmodifiable(value.getRepeatedSfixed64List());
+ assertIsUnmodifiable(value.getRepeatedFloatList());
+ assertIsUnmodifiable(value.getRepeatedDoubleList());
+ assertIsUnmodifiable(value.getRepeatedBoolList());
+ assertIsUnmodifiable(value.getRepeatedStringList());
+ assertIsUnmodifiable(value.getRepeatedBytesList());
+ assertIsUnmodifiable(value.getRepeatedGroupList());
+ assertIsUnmodifiable(value.getRepeatedNestedMessageList());
+ assertIsUnmodifiable(value.getRepeatedForeignMessageList());
+ assertIsUnmodifiable(value.getRepeatedImportMessageList());
+ assertIsUnmodifiable(value.getRepeatedNestedEnumList());
+ assertIsUnmodifiable(value.getRepeatedForeignEnumList());
+ assertIsUnmodifiable(value.getRepeatedImportEnumList());
+ }
+
+ private void assertIsUnmodifiable(List<?> list) {
+ if (list == Collections.emptyList()) {
+ // OKAY -- Need to check this b/c EmptyList allows you to call clear.
+ } else {
+ try {
+ list.clear();
+ fail("List wasn't immutable");
+ } catch (UnsupportedOperationException e) {
+ // good
+ }
+ }
+ }
+
+ public void testSettersRejectNull() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ try {
+ builder.setOptionalString(null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setOptionalBytes(null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setOptionalNestedMessage((TestAllTypes.NestedMessage) null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setOptionalNestedMessage(
+ (TestAllTypes.NestedMessage.Builder) null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setOptionalNestedEnum(null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.addRepeatedString(null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.addRepeatedBytes(null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.addRepeatedNestedMessage((TestAllTypes.NestedMessage) null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.addRepeatedNestedMessage(
+ (TestAllTypes.NestedMessage.Builder) null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.addRepeatedNestedEnum(null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ }
+
+ public void testRepeatedSetters() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ TestUtil.modifyRepeatedFields(builder);
+ TestAllTypes message = builder.build();
+ TestUtil.assertRepeatedFieldsModified(message);
+ }
+
+ public void testRepeatedSettersRejectNull() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+
+ builder.addRepeatedString("one");
+ builder.addRepeatedString("two");
+ try {
+ builder.setRepeatedString(1, null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ builder.addRepeatedBytes(TestUtil.toBytes("one"));
+ builder.addRepeatedBytes(TestUtil.toBytes("two"));
+ try {
+ builder.setRepeatedBytes(1, null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ builder.addRepeatedNestedMessage(
+ TestAllTypes.NestedMessage.newBuilder().setBb(218).build());
+ builder.addRepeatedNestedMessage(
+ TestAllTypes.NestedMessage.newBuilder().setBb(456).build());
+ try {
+ builder.setRepeatedNestedMessage(1, (TestAllTypes.NestedMessage) null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setRepeatedNestedMessage(
+ 1, (TestAllTypes.NestedMessage.Builder) null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ builder.addRepeatedNestedEnum(TestAllTypes.NestedEnum.FOO);
+ builder.addRepeatedNestedEnum(TestAllTypes.NestedEnum.BAR);
+ try {
+ builder.setRepeatedNestedEnum(1, null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ }
+
+ public void testRepeatedAppend() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+
+ builder.addAllRepeatedInt32(Arrays.asList(1, 2, 3, 4));
+ builder.addAllRepeatedForeignEnum(Arrays.asList(ForeignEnum.FOREIGN_BAZ));
+
+ ForeignMessage foreignMessage =
+ ForeignMessage.newBuilder().setC(12).build();
+ builder.addAllRepeatedForeignMessage(Arrays.asList(foreignMessage));
+
+ TestAllTypes message = builder.build();
+ assertEquals(message.getRepeatedInt32List(), Arrays.asList(1, 2, 3, 4));
+ assertEquals(message.getRepeatedForeignEnumList(),
+ Arrays.asList(ForeignEnum.FOREIGN_BAZ));
+ assertEquals(1, message.getRepeatedForeignMessageCount());
+ assertEquals(12, message.getRepeatedForeignMessage(0).getC());
+ }
+
+ public void testRepeatedAppendRejectsNull() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+
+ ForeignMessage foreignMessage =
+ ForeignMessage.newBuilder().setC(12).build();
+ try {
+ builder.addAllRepeatedForeignMessage(
+ Arrays.asList(foreignMessage, (ForeignMessage) null));
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ try {
+ builder.addAllRepeatedForeignEnum(
+ Arrays.asList(ForeignEnum.FOREIGN_BAZ, null));
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ try {
+ builder.addAllRepeatedString(Arrays.asList("one", null));
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ try {
+ builder.addAllRepeatedBytes(Arrays.asList(TestUtil.toBytes("one"), null));
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ }
+
+ public void testRepeatedAppendIterateOnlyOnce() throws Exception {
+ // Create a Iterable that can only be iterated once.
+ Iterable<String> stringIterable = new Iterable<String>() {
+ private boolean called = false;
+ @Override
+ public Iterator<String> iterator() {
+ if (called) {
+ throw new IllegalStateException();
+ }
+ called = true;
+ return Arrays.asList("one", "two", "three").iterator();
+ }
+ };
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ builder.addAllRepeatedString(stringIterable);
+ assertEquals(3, builder.getRepeatedStringCount());
+ assertEquals("one", builder.getRepeatedString(0));
+ assertEquals("two", builder.getRepeatedString(1));
+ assertEquals("three", builder.getRepeatedString(2));
+
+ try {
+ builder.addAllRepeatedString(stringIterable);
+ fail("Exception was not thrown");
+ } catch (IllegalStateException e) {
+ // We expect this exception.
+ }
+ }
+
+ public void testMergeFromOtherRejectsNull() throws Exception {
+ try {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ builder.mergeFrom((TestAllTypes) null);
+ fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ }
+
+ public void testSettingForeignMessageUsingBuilder() throws Exception {
+ TestAllTypes message = TestAllTypes.newBuilder()
+ // Pass builder for foreign message instance.
+ .setOptionalForeignMessage(ForeignMessage.newBuilder().setC(123))
+ .build();
+ TestAllTypes expectedMessage = TestAllTypes.newBuilder()
+ // Create expected version passing foreign message instance explicitly.
+ .setOptionalForeignMessage(
+ ForeignMessage.newBuilder().setC(123).build())
+ .build();
+ // TODO(ngd): Upgrade to using real #equals method once implemented
+ assertEquals(expectedMessage.toString(), message.toString());
+ }
+
+ public void testSettingRepeatedForeignMessageUsingBuilder() throws Exception {
+ TestAllTypes message = TestAllTypes.newBuilder()
+ // Pass builder for foreign message instance.
+ .addRepeatedForeignMessage(ForeignMessage.newBuilder().setC(456))
+ .build();
+ TestAllTypes expectedMessage = TestAllTypes.newBuilder()
+ // Create expected version passing foreign message instance explicitly.
+ .addRepeatedForeignMessage(
+ ForeignMessage.newBuilder().setC(456).build())
+ .build();
+ assertEquals(expectedMessage.toString(), message.toString());
+ }
+
+ public void testDefaults() throws Exception {
+ TestUtil.assertClear(TestAllTypes.getDefaultInstance());
+ TestUtil.assertClear(TestAllTypes.newBuilder().build());
+
+ TestExtremeDefaultValues message =
+ TestExtremeDefaultValues.getDefaultInstance();
+ assertEquals("\u1234", message.getUtf8String());
+ assertEquals(Double.POSITIVE_INFINITY, message.getInfDouble());
+ assertEquals(Double.NEGATIVE_INFINITY, message.getNegInfDouble());
+ assertTrue(Double.isNaN(message.getNanDouble()));
+ assertEquals(Float.POSITIVE_INFINITY, message.getInfFloat());
+ assertEquals(Float.NEGATIVE_INFINITY, message.getNegInfFloat());
+ assertTrue(Float.isNaN(message.getNanFloat()));
+ assertEquals("? ? ?? ?? ??? ??/ ??-", message.getCppTrigraph());
+ }
+
+ public void testClear() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.assertClear(builder);
+ TestUtil.setAllFields(builder);
+ builder.clear();
+ TestUtil.assertClear(builder);
+ }
+
+ public void testReflectionGetters() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ reflectionTester.assertAllFieldsSetViaReflection(builder);
+
+ TestAllTypes message = builder.build();
+ reflectionTester.assertAllFieldsSetViaReflection(message);
+ }
+
+ public void testReflectionSetters() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ reflectionTester.setAllFieldsViaReflection(builder);
+ TestUtil.assertAllFieldsSet(builder);
+
+ TestAllTypes message = builder.build();
+ TestUtil.assertAllFieldsSet(message);
+ }
+
+ public void testReflectionSettersRejectNull() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ reflectionTester.assertReflectionSettersRejectNull(builder);
+ }
+
+ public void testReflectionRepeatedSetters() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ reflectionTester.setAllFieldsViaReflection(builder);
+ reflectionTester.modifyRepeatedFieldsViaReflection(builder);
+ TestUtil.assertRepeatedFieldsModified(builder);
+
+ TestAllTypes message = builder.build();
+ TestUtil.assertRepeatedFieldsModified(message);
+ }
+
+ public void testReflectionRepeatedSettersRejectNull() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ reflectionTester.assertReflectionRepeatedSettersRejectNull(builder);
+ }
+
+ public void testReflectionDefaults() throws Exception {
+ reflectionTester.assertClearViaReflection(
+ TestAllTypes.getDefaultInstance());
+ reflectionTester.assertClearViaReflection(
+ TestAllTypes.newBuilder().build());
+ }
+
+ public void testReflectionGetOneof() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ reflectionTester.setAllFieldsViaReflection(builder);
+ Descriptors.OneofDescriptor oneof =
+ TestAllTypes.getDescriptor().getOneofs().get(0);
+ Descriptors.FieldDescriptor field =
+ TestAllTypes.getDescriptor().findFieldByName("oneof_bytes");
+ assertSame(field, builder.getOneofFieldDescriptor(oneof));
+
+ TestAllTypes message = builder.build();
+ assertSame(field, message.getOneofFieldDescriptor(oneof));
+ }
+
+ public void testReflectionClearOneof() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ reflectionTester.setAllFieldsViaReflection(builder);
+ Descriptors.OneofDescriptor oneof =
+ TestAllTypes.getDescriptor().getOneofs().get(0);
+ Descriptors.FieldDescriptor field =
+ TestAllTypes.getDescriptor().findFieldByName("oneof_bytes");
+
+ assertTrue(builder.hasOneof(oneof));
+ assertTrue(builder.hasField(field));
+ builder.clearOneof(oneof);
+ assertFalse(builder.hasOneof(oneof));
+ assertFalse(builder.hasField(field));
+ }
+
+ public void testEnumInterface() throws Exception {
+ assertTrue(TestAllTypes.getDefaultInstance().getDefaultNestedEnum()
+ instanceof ProtocolMessageEnum);
+ }
+
+ public void testEnumMap() throws Exception {
+ Internal.EnumLiteMap<ForeignEnum> map = ForeignEnum.internalGetValueMap();
+
+ for (ForeignEnum value : ForeignEnum.values()) {
+ assertEquals(value, map.findValueByNumber(value.getNumber()));
+ }
+
+ assertTrue(map.findValueByNumber(12345) == null);
+ }
+
+ public void testParsePackedToUnpacked() throws Exception {
+ TestUnpackedTypes.Builder builder = TestUnpackedTypes.newBuilder();
+ TestUnpackedTypes message =
+ builder.mergeFrom(TestUtil.getPackedSet().toByteString()).build();
+ TestUtil.assertUnpackedFieldsSet(message);
+ }
+
+ public void testParseUnpackedToPacked() throws Exception {
+ TestPackedTypes.Builder builder = TestPackedTypes.newBuilder();
+ TestPackedTypes message =
+ builder.mergeFrom(TestUtil.getUnpackedSet().toByteString()).build();
+ TestUtil.assertPackedFieldsSet(message);
+ }
+
+ // =================================================================
+ // Extensions.
+
+ TestUtil.ReflectionTester extensionsReflectionTester =
+ new TestUtil.ReflectionTester(TestAllExtensions.getDescriptor(),
+ TestUtil.getExtensionRegistry());
+
+ public void testExtensionMessageOrBuilder() throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ TestUtil.setAllExtensions(builder);
+ TestAllExtensions message = builder.build();
+ TestUtil.assertAllExtensionsSet(message);
+ }
+
+ public void testExtensionRepeatedSetters() throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ TestUtil.setAllExtensions(builder);
+ TestUtil.modifyRepeatedExtensions(builder);
+ TestAllExtensions message = builder.build();
+ TestUtil.assertRepeatedExtensionsModified(message);
+ }
+
+ public void testExtensionDefaults() throws Exception {
+ TestUtil.assertExtensionsClear(TestAllExtensions.getDefaultInstance());
+ TestUtil.assertExtensionsClear(TestAllExtensions.newBuilder().build());
+ }
+
+ public void testUnsetRepeatedExtensionGetField() {
+ TestAllExtensions message = TestAllExtensions.getDefaultInstance();
+ Object value;
+
+ value = message.getField(UnittestProto.repeatedStringExtension.getDescriptor());
+ assertTrue(value instanceof List);
+ assertTrue(((List<?>) value).isEmpty());
+ assertIsUnmodifiable((List<?>) value);
+
+ value = message.getField(UnittestProto.repeatedNestedMessageExtension.getDescriptor());
+ assertTrue(value instanceof List);
+ assertTrue(((List<?>) value).isEmpty());
+ assertIsUnmodifiable((List<?>) value);
+ }
+
+ public void testExtensionReflectionGetters() throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ TestUtil.setAllExtensions(builder);
+ extensionsReflectionTester.assertAllFieldsSetViaReflection(builder);
+
+ TestAllExtensions message = builder.build();
+ extensionsReflectionTester.assertAllFieldsSetViaReflection(message);
+ }
+
+ public void testExtensionReflectionSetters() throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ extensionsReflectionTester.setAllFieldsViaReflection(builder);
+ TestUtil.assertAllExtensionsSet(builder);
+
+ TestAllExtensions message = builder.build();
+ TestUtil.assertAllExtensionsSet(message);
+ }
+
+ public void testExtensionReflectionSettersRejectNull() throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ extensionsReflectionTester.assertReflectionSettersRejectNull(builder);
+ }
+
+ public void testExtensionReflectionRepeatedSetters() throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ extensionsReflectionTester.setAllFieldsViaReflection(builder);
+ extensionsReflectionTester.modifyRepeatedFieldsViaReflection(builder);
+ TestUtil.assertRepeatedExtensionsModified(builder);
+
+ TestAllExtensions message = builder.build();
+ TestUtil.assertRepeatedExtensionsModified(message);
+ }
+
+ public void testExtensionReflectionRepeatedSettersRejectNull()
+ throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ extensionsReflectionTester.assertReflectionRepeatedSettersRejectNull(
+ builder);
+ }
+
+ public void testExtensionReflectionDefaults() throws Exception {
+ extensionsReflectionTester.assertClearViaReflection(
+ TestAllExtensions.getDefaultInstance());
+ extensionsReflectionTester.assertClearViaReflection(
+ TestAllExtensions.newBuilder().build());
+ }
+
+ public void testClearExtension() throws Exception {
+ // clearExtension() is not actually used in TestUtil, so try it manually.
+ assertFalse(
+ TestAllExtensions.newBuilder()
+ .setExtension(UnittestProto.optionalInt32Extension, 1)
+ .clearExtension(UnittestProto.optionalInt32Extension)
+ .hasExtension(UnittestProto.optionalInt32Extension));
+ assertEquals(0,
+ TestAllExtensions.newBuilder()
+ .addExtension(UnittestProto.repeatedInt32Extension, 1)
+ .clearExtension(UnittestProto.repeatedInt32Extension)
+ .getExtensionCount(UnittestProto.repeatedInt32Extension));
+ }
+
+ public void testExtensionCopy() throws Exception {
+ TestAllExtensions original = TestUtil.getAllExtensionsSet();
+ TestAllExtensions copy = TestAllExtensions.newBuilder(original).build();
+ TestUtil.assertAllExtensionsSet(copy);
+ }
+
+ public void testExtensionMergeFrom() throws Exception {
+ TestAllExtensions original =
+ TestAllExtensions.newBuilder()
+ .setExtension(UnittestProto.optionalInt32Extension, 1).build();
+ TestAllExtensions merged =
+ TestAllExtensions.newBuilder().mergeFrom(original).build();
+ assertTrue(merged.hasExtension(UnittestProto.optionalInt32Extension));
+ assertEquals(
+ 1, (int) merged.getExtension(UnittestProto.optionalInt32Extension));
+ }
+
+ // =================================================================
+ // Lite Extensions.
+
+ // We test lite extensions directly because they have a separate
+ // implementation from full extensions. In contrast, we do not test
+ // lite fields directly since they are implemented exactly the same as
+ // regular fields.
+
+ public void testLiteExtensionMessageOrBuilder() throws Exception {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.newBuilder();
+ TestUtilLite.setAllExtensions(builder);
+ TestUtil.assertAllExtensionsSet(builder);
+
+ TestAllExtensionsLite message = builder.build();
+ TestUtil.assertAllExtensionsSet(message);
+ }
+
+ public void testLiteExtensionRepeatedSetters() throws Exception {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.newBuilder();
+ TestUtilLite.setAllExtensions(builder);
+ TestUtilLite.modifyRepeatedExtensions(builder);
+ TestUtil.assertRepeatedExtensionsModified(builder);
+
+ TestAllExtensionsLite message = builder.build();
+ TestUtil.assertRepeatedExtensionsModified(message);
+ }
+
+ public void testLiteExtensionDefaults() throws Exception {
+ TestUtil.assertExtensionsClear(TestAllExtensionsLite.getDefaultInstance());
+ TestUtil.assertExtensionsClear(TestAllExtensionsLite.newBuilder().build());
+ }
+
+ public void testClearLiteExtension() throws Exception {
+ // clearExtension() is not actually used in TestUtil, so try it manually.
+ assertFalse(
+ TestAllExtensionsLite.newBuilder()
+ .setExtension(UnittestLite.optionalInt32ExtensionLite, 1)
+ .clearExtension(UnittestLite.optionalInt32ExtensionLite)
+ .hasExtension(UnittestLite.optionalInt32ExtensionLite));
+ assertEquals(0,
+ TestAllExtensionsLite.newBuilder()
+ .addExtension(UnittestLite.repeatedInt32ExtensionLite, 1)
+ .clearExtension(UnittestLite.repeatedInt32ExtensionLite)
+ .getExtensionCount(UnittestLite.repeatedInt32ExtensionLite));
+ }
+
+ public void testLiteExtensionCopy() throws Exception {
+ TestAllExtensionsLite original = TestUtilLite.getAllLiteExtensionsSet();
+ TestAllExtensionsLite copy =
+ TestAllExtensionsLite.newBuilder(original).build();
+ TestUtil.assertAllExtensionsSet(copy);
+ }
+
+ public void testLiteExtensionMergeFrom() throws Exception {
+ TestAllExtensionsLite original =
+ TestAllExtensionsLite.newBuilder()
+ .setExtension(UnittestLite.optionalInt32ExtensionLite, 1).build();
+ TestAllExtensionsLite merged =
+ TestAllExtensionsLite.newBuilder().mergeFrom(original).build();
+ assertTrue(merged.hasExtension(UnittestLite.optionalInt32ExtensionLite));
+ assertEquals(
+ 1, (int) merged.getExtension(UnittestLite.optionalInt32ExtensionLite));
+ }
+
+ // =================================================================
+ // multiple_files_test
+
+ // Test that custom options of an file level enum are properly initialized.
+ // This test needs to be put before any other access to MultipleFilesTestProto
+ // or messages defined in multiple_files_test.proto because the class loading
+ // order affects initialization process of custom options.
+ public void testEnumValueOptionsInMultipleFilesMode() throws Exception {
+ assertEquals(12345, EnumWithNoOuter.FOO.getValueDescriptor().getOptions()
+ .getExtension(MultipleFilesTestProto.enumValueOption).intValue());
+ }
+
+ public void testMultipleFilesOption() throws Exception {
+ // We mostly just want to check that things compile.
+ MessageWithNoOuter message =
+ MessageWithNoOuter.newBuilder()
+ .setNested(MessageWithNoOuter.NestedMessage.newBuilder().setI(1))
+ .addForeign(TestAllTypes.newBuilder().setOptionalInt32(1))
+ .setNestedEnum(MessageWithNoOuter.NestedEnum.BAZ)
+ .setForeignEnum(EnumWithNoOuter.BAR)
+ .build();
+ assertEquals(message, MessageWithNoOuter.parseFrom(message.toByteString()));
+
+ assertEquals(MultipleFilesTestProto.getDescriptor(),
+ MessageWithNoOuter.getDescriptor().getFile());
+
+ Descriptors.FieldDescriptor field =
+ MessageWithNoOuter.getDescriptor().findFieldByName("foreign_enum");
+ assertEquals(EnumWithNoOuter.BAR.getValueDescriptor(),
+ message.getField(field));
+
+ assertEquals(MultipleFilesTestProto.getDescriptor(),
+ ServiceWithNoOuter.getDescriptor().getFile());
+
+ assertFalse(
+ TestAllExtensions.getDefaultInstance().hasExtension(
+ MultipleFilesTestProto.extensionWithOuter));
+ }
+
+ public void testOptionalFieldWithRequiredSubfieldsOptimizedForSize()
+ throws Exception {
+ TestOptionalOptimizedForSize message =
+ TestOptionalOptimizedForSize.getDefaultInstance();
+ assertTrue(message.isInitialized());
+
+ message = TestOptionalOptimizedForSize.newBuilder().setO(
+ TestRequiredOptimizedForSize.newBuilder().buildPartial()
+ ).buildPartial();
+ assertFalse(message.isInitialized());
+
+ message = TestOptionalOptimizedForSize.newBuilder().setO(
+ TestRequiredOptimizedForSize.newBuilder().setX(5).buildPartial()
+ ).buildPartial();
+ assertTrue(message.isInitialized());
+ }
+
+ public void testUninitializedExtensionInOptimizedForSize()
+ throws Exception {
+ TestOptimizedForSize.Builder builder = TestOptimizedForSize.newBuilder();
+ builder.setExtension(TestOptimizedForSize.testExtension2,
+ TestRequiredOptimizedForSize.newBuilder().buildPartial());
+ assertFalse(builder.isInitialized());
+ assertFalse(builder.buildPartial().isInitialized());
+
+ builder = TestOptimizedForSize.newBuilder();
+ builder.setExtension(TestOptimizedForSize.testExtension2,
+ TestRequiredOptimizedForSize.newBuilder().setX(10).buildPartial());
+ assertTrue(builder.isInitialized());
+ assertTrue(builder.buildPartial().isInitialized());
+ }
+
+ public void testToBuilder() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ TestAllTypes message = builder.build();
+ TestUtil.assertAllFieldsSet(message);
+ TestUtil.assertAllFieldsSet(message.toBuilder().build());
+ }
+
+ public void testFieldConstantValues() throws Exception {
+ assertEquals(TestAllTypes.NestedMessage.BB_FIELD_NUMBER, 1);
+ assertEquals(TestAllTypes.OPTIONAL_INT32_FIELD_NUMBER, 1);
+ assertEquals(TestAllTypes.OPTIONALGROUP_FIELD_NUMBER, 16);
+ assertEquals(TestAllTypes.OPTIONAL_NESTED_MESSAGE_FIELD_NUMBER, 18);
+ assertEquals(TestAllTypes.OPTIONAL_NESTED_ENUM_FIELD_NUMBER, 21);
+ assertEquals(TestAllTypes.REPEATED_INT32_FIELD_NUMBER, 31);
+ assertEquals(TestAllTypes.REPEATEDGROUP_FIELD_NUMBER, 46);
+ assertEquals(TestAllTypes.REPEATED_NESTED_MESSAGE_FIELD_NUMBER, 48);
+ assertEquals(TestAllTypes.REPEATED_NESTED_ENUM_FIELD_NUMBER, 51);
+ }
+
+ public void testExtensionConstantValues() throws Exception {
+ assertEquals(UnittestProto.TestRequired.SINGLE_FIELD_NUMBER, 1000);
+ assertEquals(UnittestProto.TestRequired.MULTI_FIELD_NUMBER, 1001);
+ assertEquals(UnittestProto.OPTIONAL_INT32_EXTENSION_FIELD_NUMBER, 1);
+ assertEquals(UnittestProto.OPTIONALGROUP_EXTENSION_FIELD_NUMBER, 16);
+ assertEquals(
+ UnittestProto.OPTIONAL_NESTED_MESSAGE_EXTENSION_FIELD_NUMBER, 18);
+ assertEquals(UnittestProto.OPTIONAL_NESTED_ENUM_EXTENSION_FIELD_NUMBER, 21);
+ assertEquals(UnittestProto.REPEATED_INT32_EXTENSION_FIELD_NUMBER, 31);
+ assertEquals(UnittestProto.REPEATEDGROUP_EXTENSION_FIELD_NUMBER, 46);
+ assertEquals(
+ UnittestProto.REPEATED_NESTED_MESSAGE_EXTENSION_FIELD_NUMBER, 48);
+ assertEquals(UnittestProto.REPEATED_NESTED_ENUM_EXTENSION_FIELD_NUMBER, 51);
+ }
+
+ public void testRecursiveMessageDefaultInstance() throws Exception {
+ UnittestProto.TestRecursiveMessage message =
+ UnittestProto.TestRecursiveMessage.getDefaultInstance();
+ assertTrue(message != null);
+ assertNotNull(message.getA());
+ assertTrue(message.getA() == message);
+ }
+
+ public void testSerialize() throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestUtil.setAllFields(builder);
+ TestAllTypes expected = builder.build();
+ ObjectOutputStream out = new ObjectOutputStream(baos);
+ try {
+ out.writeObject(expected);
+ } finally {
+ out.close();
+ }
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream in = new ObjectInputStream(bais);
+ TestAllTypes actual = (TestAllTypes) in.readObject();
+ assertEquals(expected, actual);
+ }
+
+ public void testSerializePartial() throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestAllTypes expected = builder.buildPartial();
+ ObjectOutputStream out = new ObjectOutputStream(baos);
+ try {
+ out.writeObject(expected);
+ } finally {
+ out.close();
+ }
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream in = new ObjectInputStream(bais);
+ TestAllTypes actual = (TestAllTypes) in.readObject();
+ assertEquals(expected, actual);
+ }
+
+ public void testEnumValues() {
+ assertEquals(
+ TestAllTypes.NestedEnum.BAR.getNumber(),
+ TestAllTypes.NestedEnum.BAR_VALUE);
+ assertEquals(
+ TestAllTypes.NestedEnum.BAZ.getNumber(),
+ TestAllTypes.NestedEnum.BAZ_VALUE);
+ assertEquals(
+ TestAllTypes.NestedEnum.FOO.getNumber(),
+ TestAllTypes.NestedEnum.FOO_VALUE);
+ }
+
+ public void testNonNestedExtensionInitialization() {
+ assertTrue(NonNestedExtension.nonNestedExtension
+ .getMessageDefaultInstance() instanceof MyNonNestedExtension);
+ assertEquals("nonNestedExtension",
+ NonNestedExtension.nonNestedExtension.getDescriptor().getName());
+ }
+
+ public void testNestedExtensionInitialization() {
+ assertTrue(MyNestedExtension.recursiveExtension.getMessageDefaultInstance()
+ instanceof MessageToBeExtended);
+ assertEquals("recursiveExtension",
+ MyNestedExtension.recursiveExtension.getDescriptor().getName());
+ }
+
+ public void testNonNestedExtensionLiteInitialization() {
+ assertTrue(NonNestedExtensionLite.nonNestedExtensionLite
+ .getMessageDefaultInstance() instanceof MyNonNestedExtensionLite);
+ }
+
+ public void testNestedExtensionLiteInitialization() {
+ assertTrue(MyNestedExtensionLite.recursiveExtensionLite
+ .getMessageDefaultInstance() instanceof MessageLiteToBeExtended);
+ }
+
+ public void testInvalidations() throws Exception {
+ GeneratedMessage.enableAlwaysUseFieldBuildersForTesting();
+ TestAllTypes.NestedMessage nestedMessage1 =
+ TestAllTypes.NestedMessage.newBuilder().build();
+ TestAllTypes.NestedMessage nestedMessage2 =
+ TestAllTypes.NestedMessage.newBuilder().build();
+
+ // Set all three flavors (enum, primitive, message and singular/repeated)
+ // and verify no invalidations fired
+ TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
+
+ TestAllTypes.Builder builder = (TestAllTypes.Builder)
+ ((AbstractMessage) TestAllTypes.getDefaultInstance()).
+ newBuilderForType(mockParent);
+ builder.setOptionalInt32(1);
+ builder.setOptionalNestedEnum(TestAllTypes.NestedEnum.BAR);
+ builder.setOptionalNestedMessage(nestedMessage1);
+ builder.addRepeatedInt32(1);
+ builder.addRepeatedNestedEnum(TestAllTypes.NestedEnum.BAR);
+ builder.addRepeatedNestedMessage(nestedMessage1);
+ assertEquals(0, mockParent.getInvalidationCount());
+
+ // Now tell it we want changes and make sure it's only fired once
+ // And do this for each flavor
+
+ // primitive single
+ builder.buildPartial();
+ builder.setOptionalInt32(2);
+ builder.setOptionalInt32(3);
+ assertEquals(1, mockParent.getInvalidationCount());
+
+ // enum single
+ builder.buildPartial();
+ builder.setOptionalNestedEnum(TestAllTypes.NestedEnum.BAZ);
+ builder.setOptionalNestedEnum(TestAllTypes.NestedEnum.BAR);
+ assertEquals(2, mockParent.getInvalidationCount());
+
+ // message single
+ builder.buildPartial();
+ builder.setOptionalNestedMessage(nestedMessage2);
+ builder.setOptionalNestedMessage(nestedMessage1);
+ assertEquals(3, mockParent.getInvalidationCount());
+
+ // primitive repeated
+ builder.buildPartial();
+ builder.addRepeatedInt32(2);
+ builder.addRepeatedInt32(3);
+ assertEquals(4, mockParent.getInvalidationCount());
+
+ // enum repeated
+ builder.buildPartial();
+ builder.addRepeatedNestedEnum(TestAllTypes.NestedEnum.BAZ);
+ builder.addRepeatedNestedEnum(TestAllTypes.NestedEnum.BAZ);
+ assertEquals(5, mockParent.getInvalidationCount());
+
+ // message repeated
+ builder.buildPartial();
+ builder.addRepeatedNestedMessage(nestedMessage2);
+ builder.addRepeatedNestedMessage(nestedMessage1);
+ assertEquals(6, mockParent.getInvalidationCount());
+
+ }
+
+ public void testInvalidations_Extensions() throws Exception {
+ TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
+
+ TestAllExtensions.Builder builder = (TestAllExtensions.Builder)
+ ((AbstractMessage) TestAllExtensions.getDefaultInstance()).
+ newBuilderForType(mockParent);
+
+ builder.addExtension(UnittestProto.repeatedInt32Extension, 1);
+ builder.setExtension(UnittestProto.repeatedInt32Extension, 0, 2);
+ builder.clearExtension(UnittestProto.repeatedInt32Extension);
+ assertEquals(0, mockParent.getInvalidationCount());
+
+ // Now tell it we want changes and make sure it's only fired once
+ builder.buildPartial();
+ builder.addExtension(UnittestProto.repeatedInt32Extension, 2);
+ builder.addExtension(UnittestProto.repeatedInt32Extension, 3);
+ assertEquals(1, mockParent.getInvalidationCount());
+
+ builder.buildPartial();
+ builder.setExtension(UnittestProto.repeatedInt32Extension, 0, 4);
+ builder.setExtension(UnittestProto.repeatedInt32Extension, 1, 5);
+ assertEquals(2, mockParent.getInvalidationCount());
+
+ builder.buildPartial();
+ builder.clearExtension(UnittestProto.repeatedInt32Extension);
+ builder.clearExtension(UnittestProto.repeatedInt32Extension);
+ assertEquals(3, mockParent.getInvalidationCount());
+ }
+
+ public void testBaseMessageOrBuilder() {
+ // Mostly just makes sure the base interface exists and has some methods.
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestAllTypes message = builder.buildPartial();
+ TestAllTypesOrBuilder builderAsInterface = (TestAllTypesOrBuilder) builder;
+ TestAllTypesOrBuilder messageAsInterface = (TestAllTypesOrBuilder) message;
+
+ assertEquals(
+ messageAsInterface.getDefaultBool(),
+ messageAsInterface.getDefaultBool());
+ assertEquals(
+ messageAsInterface.getOptionalDouble(),
+ messageAsInterface.getOptionalDouble());
+ }
+
+ public void testMessageOrBuilderGetters() {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+
+ // single fields
+ assertSame(ForeignMessage.getDefaultInstance(),
+ builder.getOptionalForeignMessageOrBuilder());
+ ForeignMessage.Builder subBuilder =
+ builder.getOptionalForeignMessageBuilder();
+ assertSame(subBuilder, builder.getOptionalForeignMessageOrBuilder());
+
+ // repeated fields
+ ForeignMessage m0 = ForeignMessage.newBuilder().buildPartial();
+ ForeignMessage m1 = ForeignMessage.newBuilder().buildPartial();
+ ForeignMessage m2 = ForeignMessage.newBuilder().buildPartial();
+ builder.addRepeatedForeignMessage(m0);
+ builder.addRepeatedForeignMessage(m1);
+ builder.addRepeatedForeignMessage(m2);
+ assertSame(m0, builder.getRepeatedForeignMessageOrBuilder(0));
+ assertSame(m1, builder.getRepeatedForeignMessageOrBuilder(1));
+ assertSame(m2, builder.getRepeatedForeignMessageOrBuilder(2));
+ ForeignMessage.Builder b0 = builder.getRepeatedForeignMessageBuilder(0);
+ ForeignMessage.Builder b1 = builder.getRepeatedForeignMessageBuilder(1);
+ assertSame(b0, builder.getRepeatedForeignMessageOrBuilder(0));
+ assertSame(b1, builder.getRepeatedForeignMessageOrBuilder(1));
+ assertSame(m2, builder.getRepeatedForeignMessageOrBuilder(2));
+
+ List<? extends ForeignMessageOrBuilder> messageOrBuilderList =
+ builder.getRepeatedForeignMessageOrBuilderList();
+ assertSame(b0, messageOrBuilderList.get(0));
+ assertSame(b1, messageOrBuilderList.get(1));
+ assertSame(m2, messageOrBuilderList.get(2));
+ }
+
+ public void testGetFieldBuilder() {
+ Descriptor descriptor = TestAllTypes.getDescriptor();
+
+ FieldDescriptor fieldDescriptor =
+ descriptor.findFieldByName("optional_nested_message");
+ FieldDescriptor foreignFieldDescriptor =
+ descriptor.findFieldByName("optional_foreign_message");
+ FieldDescriptor importFieldDescriptor =
+ descriptor.findFieldByName("optional_import_message");
+
+ // Mutate the message with new field builder
+ // Mutate nested message
+ TestAllTypes.Builder builder1 = TestAllTypes.newBuilder();
+ Message.Builder fieldBuilder1 = builder1.newBuilderForField(fieldDescriptor)
+ .mergeFrom((Message) builder1.getField(fieldDescriptor));
+ FieldDescriptor subFieldDescriptor1 =
+ fieldBuilder1.getDescriptorForType().findFieldByName("bb");
+ fieldBuilder1.setField(subFieldDescriptor1, 1);
+ builder1.setField(fieldDescriptor, fieldBuilder1.build());
+
+ // Mutate foreign message
+ Message.Builder foreignFieldBuilder1 = builder1.newBuilderForField(
+ foreignFieldDescriptor)
+ .mergeFrom((Message) builder1.getField(foreignFieldDescriptor));
+ FieldDescriptor subForeignFieldDescriptor1 =
+ foreignFieldBuilder1.getDescriptorForType().findFieldByName("c");
+ foreignFieldBuilder1.setField(subForeignFieldDescriptor1, 2);
+ builder1.setField(foreignFieldDescriptor, foreignFieldBuilder1.build());
+
+ // Mutate import message
+ Message.Builder importFieldBuilder1 = builder1.newBuilderForField(
+ importFieldDescriptor)
+ .mergeFrom((Message) builder1.getField(importFieldDescriptor));
+ FieldDescriptor subImportFieldDescriptor1 =
+ importFieldBuilder1.getDescriptorForType().findFieldByName("d");
+ importFieldBuilder1.setField(subImportFieldDescriptor1, 3);
+ builder1.setField(importFieldDescriptor, importFieldBuilder1.build());
+
+ Message newMessage1 = builder1.build();
+
+ // Mutate the message with existing field builder
+ // Mutate nested message
+ TestAllTypes.Builder builder2 = TestAllTypes.newBuilder();
+ Message.Builder fieldBuilder2 = builder2.getFieldBuilder(fieldDescriptor);
+ FieldDescriptor subFieldDescriptor2 =
+ fieldBuilder2.getDescriptorForType().findFieldByName("bb");
+ fieldBuilder2.setField(subFieldDescriptor2, 1);
+ builder2.setField(fieldDescriptor, fieldBuilder2.build());
+
+ // Mutate foreign message
+ Message.Builder foreignFieldBuilder2 = builder2.newBuilderForField(
+ foreignFieldDescriptor)
+ .mergeFrom((Message) builder2.getField(foreignFieldDescriptor));
+ FieldDescriptor subForeignFieldDescriptor2 =
+ foreignFieldBuilder2.getDescriptorForType().findFieldByName("c");
+ foreignFieldBuilder2.setField(subForeignFieldDescriptor2, 2);
+ builder2.setField(foreignFieldDescriptor, foreignFieldBuilder2.build());
+
+ // Mutate import message
+ Message.Builder importFieldBuilder2 = builder2.newBuilderForField(
+ importFieldDescriptor)
+ .mergeFrom((Message) builder2.getField(importFieldDescriptor));
+ FieldDescriptor subImportFieldDescriptor2 =
+ importFieldBuilder2.getDescriptorForType().findFieldByName("d");
+ importFieldBuilder2.setField(subImportFieldDescriptor2, 3);
+ builder2.setField(importFieldDescriptor, importFieldBuilder2.build());
+
+ Message newMessage2 = builder2.build();
+
+ // These two messages should be equal.
+ assertEquals(newMessage1, newMessage2);
+ }
+
+ public void testGetFieldBuilderWithInitializedValue() {
+ Descriptor descriptor = TestAllTypes.getDescriptor();
+ FieldDescriptor fieldDescriptor =
+ descriptor.findFieldByName("optional_nested_message");
+
+ // Before setting field, builder is initialized by default value.
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ NestedMessage.Builder fieldBuilder =
+ (NestedMessage.Builder) builder.getFieldBuilder(fieldDescriptor);
+ assertEquals(0, fieldBuilder.getBb());
+
+ // Setting field value with new field builder instance.
+ builder = TestAllTypes.newBuilder();
+ NestedMessage.Builder newFieldBuilder =
+ builder.getOptionalNestedMessageBuilder();
+ newFieldBuilder.setBb(2);
+ // Then get the field builder instance by getFieldBuilder().
+ fieldBuilder =
+ (NestedMessage.Builder) builder.getFieldBuilder(fieldDescriptor);
+ // It should contain new value.
+ assertEquals(2, fieldBuilder.getBb());
+ // These two builder should be equal.
+ assertSame(fieldBuilder, newFieldBuilder);
+ }
+
+ public void testGetFieldBuilderNotSupportedException() {
+ Descriptor descriptor = TestAllTypes.getDescriptor();
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ try {
+ builder.getFieldBuilder(descriptor.findFieldByName("optional_int32"));
+ fail("Exception was not thrown");
+ } catch (UnsupportedOperationException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.getFieldBuilder(
+ descriptor.findFieldByName("optional_nested_enum"));
+ fail("Exception was not thrown");
+ } catch (UnsupportedOperationException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.getFieldBuilder(descriptor.findFieldByName("repeated_int32"));
+ fail("Exception was not thrown");
+ } catch (UnsupportedOperationException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.getFieldBuilder(
+ descriptor.findFieldByName("repeated_nested_enum"));
+ fail("Exception was not thrown");
+ } catch (UnsupportedOperationException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.getFieldBuilder(
+ descriptor.findFieldByName("repeated_nested_message"));
+ fail("Exception was not thrown");
+ } catch (UnsupportedOperationException e) {
+ // We expect this exception.
+ }
+ }
+
+ // Test that when the default outer class name conflicts with another type
+ // defined in the proto the compiler will append a suffix to avoid the
+ // conflict.
+ public void testConflictingOuterClassName() {
+ // We just need to make sure we can refer to the outer class with the
+ // expected name. There is nothing else to test.
+ OuterClassNameTestOuterClass.OuterClassNameTest message =
+ OuterClassNameTestOuterClass.OuterClassNameTest.newBuilder().build();
+ assertTrue(message.getDescriptorForType() ==
+ OuterClassNameTestOuterClass.OuterClassNameTest.getDescriptor());
+
+ OuterClassNameTest2OuterClass.TestMessage2.NestedMessage.OuterClassNameTest2
+ message2 = OuterClassNameTest2OuterClass.TestMessage2.NestedMessage
+ .OuterClassNameTest2.newBuilder().build();
+ assertEquals(0, message2.getSerializedSize());
+
+ OuterClassNameTest3OuterClass.TestMessage3.NestedMessage.OuterClassNameTest3
+ enumValue = OuterClassNameTest3OuterClass.TestMessage3.NestedMessage
+ .OuterClassNameTest3.DUMMY_VALUE;
+ assertEquals(1, enumValue.getNumber());
+ }
+
+ // =================================================================
+ // oneof generated code test
+ public void testOneofEnumCase() throws Exception {
+ TestOneof2 message = TestOneof2.newBuilder()
+ .setFooInt(123).setFooString("foo").setFooCord("bar").build();
+ TestUtil.assertAtMostOneFieldSetOneof(message);
+ }
+
+ public void testClearOneof() throws Exception {
+ TestOneof2.Builder builder = TestOneof2.newBuilder().setFooInt(123);
+ assertEquals(TestOneof2.FooCase.FOO_INT, builder.getFooCase());
+ builder.clearFoo();
+ assertEquals(TestOneof2.FooCase.FOO_NOT_SET, builder.getFooCase());
+ }
+
+ public void testSetOneofClearsOthers() throws Exception {
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ TestOneof2 message =
+ builder.setFooInt(123).setFooString("foo").buildPartial();
+ assertTrue(message.hasFooString());
+ TestUtil.assertAtMostOneFieldSetOneof(message);
+
+ message = builder.setFooCord("bar").buildPartial();
+ assertTrue(message.hasFooCord());
+ TestUtil.assertAtMostOneFieldSetOneof(message);
+
+ message = builder.setFooStringPiece("baz").buildPartial();
+ assertTrue(message.hasFooStringPiece());
+ TestUtil.assertAtMostOneFieldSetOneof(message);
+
+ message = builder.setFooBytes(TestUtil.toBytes("qux")).buildPartial();
+ assertTrue(message.hasFooBytes());
+ TestUtil.assertAtMostOneFieldSetOneof(message);
+
+ message = builder.setFooEnum(TestOneof2.NestedEnum.FOO).buildPartial();
+ assertTrue(message.hasFooEnum());
+ TestUtil.assertAtMostOneFieldSetOneof(message);
+
+ message = builder.setFooMessage(
+ TestOneof2.NestedMessage.newBuilder().setQuxInt(234).build()).buildPartial();
+ assertTrue(message.hasFooMessage());
+ TestUtil.assertAtMostOneFieldSetOneof(message);
+
+ message = builder.setFooInt(123).buildPartial();
+ assertTrue(message.hasFooInt());
+ TestUtil.assertAtMostOneFieldSetOneof(message);
+ }
+
+ public void testOneofTypes() throws Exception {
+ // Primitive
+ {
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ assertEquals(builder.getFooInt(), 0);
+ assertFalse(builder.hasFooInt());
+ assertTrue(builder.setFooInt(123).hasFooInt());
+ assertEquals(builder.getFooInt(), 123);
+ TestOneof2 message = builder.buildPartial();
+ assertTrue(message.hasFooInt());
+ assertEquals(message.getFooInt(), 123);
+
+ assertFalse(builder.clearFooInt().hasFooInt());
+ TestOneof2 message2 = builder.build();
+ assertFalse(message2.hasFooInt());
+ assertEquals(message2.getFooInt(), 0);
+ }
+
+ // Enum
+ {
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ assertEquals(builder.getFooEnum(), TestOneof2.NestedEnum.FOO);
+ assertTrue(builder.setFooEnum(TestOneof2.NestedEnum.BAR).hasFooEnum());
+ assertEquals(builder.getFooEnum(), TestOneof2.NestedEnum.BAR);
+ TestOneof2 message = builder.buildPartial();
+ assertTrue(message.hasFooEnum());
+ assertEquals(message.getFooEnum(), TestOneof2.NestedEnum.BAR);
+
+ assertFalse(builder.clearFooEnum().hasFooEnum());
+ TestOneof2 message2 = builder.build();
+ assertFalse(message2.hasFooEnum());
+ assertEquals(message2.getFooEnum(), TestOneof2.NestedEnum.FOO);
+ }
+
+ // String
+ {
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ assertEquals(builder.getFooString(), "");
+ builder.setFooString("foo");
+ assertTrue(builder.hasFooString());
+ assertEquals(builder.getFooString(), "foo");
+ TestOneof2 message = builder.buildPartial();
+ assertTrue(message.hasFooString());
+ assertEquals(message.getFooString(), "foo");
+ assertEquals(message.getFooStringBytes(), TestUtil.toBytes("foo"));
+
+ assertFalse(builder.clearFooString().hasFooString());
+ TestOneof2 message2 = builder.buildPartial();
+ assertFalse(message2.hasFooString());
+ assertEquals(message2.getFooString(), "");
+ assertEquals(message2.getFooStringBytes(), TestUtil.toBytes(""));
+
+ // Get method should not change the oneof value.
+ builder.setFooInt(123);
+ assertEquals(builder.getFooString(), "");
+ assertEquals(builder.getFooStringBytes(), TestUtil.toBytes(""));
+ assertEquals(123, builder.getFooInt());
+
+ message = builder.build();
+ assertEquals(message.getFooString(), "");
+ assertEquals(message.getFooStringBytes(), TestUtil.toBytes(""));
+ assertEquals(123, message.getFooInt());
+ }
+
+ // Cord
+ {
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ assertEquals(builder.getFooCord(), "");
+ builder.setFooCord("foo");
+ assertTrue(builder.hasFooCord());
+ assertEquals(builder.getFooCord(), "foo");
+ TestOneof2 message = builder.buildPartial();
+ assertTrue(message.hasFooCord());
+ assertEquals(message.getFooCord(), "foo");
+ assertEquals(message.getFooCordBytes(), TestUtil.toBytes("foo"));
+
+ assertFalse(builder.clearFooCord().hasFooCord());
+ TestOneof2 message2 = builder.build();
+ assertFalse(message2.hasFooCord());
+ assertEquals(message2.getFooCord(), "");
+ assertEquals(message2.getFooCordBytes(), TestUtil.toBytes(""));
+ }
+
+ // StringPiece
+ {
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ assertEquals(builder.getFooStringPiece(), "");
+ builder.setFooStringPiece("foo");
+ assertTrue(builder.hasFooStringPiece());
+ assertEquals(builder.getFooStringPiece(), "foo");
+ TestOneof2 message = builder.buildPartial();
+ assertTrue(message.hasFooStringPiece());
+ assertEquals(message.getFooStringPiece(), "foo");
+ assertEquals(message.getFooStringPieceBytes(), TestUtil.toBytes("foo"));
+
+ assertFalse(builder.clearFooStringPiece().hasFooStringPiece());
+ TestOneof2 message2 = builder.build();
+ assertFalse(message2.hasFooStringPiece());
+ assertEquals(message2.getFooStringPiece(), "");
+ assertEquals(message2.getFooStringPieceBytes(), TestUtil.toBytes(""));
+ }
+
+ // Message
+ {
+ // set
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ assertEquals(builder.getFooMessage().getQuxInt(), 0);
+ builder.setFooMessage(
+ TestOneof2.NestedMessage.newBuilder().setQuxInt(234).build());
+ assertTrue(builder.hasFooMessage());
+ assertEquals(builder.getFooMessage().getQuxInt(), 234);
+ TestOneof2 message = builder.buildPartial();
+ assertTrue(message.hasFooMessage());
+ assertEquals(message.getFooMessage().getQuxInt(), 234);
+
+ // clear
+ assertFalse(builder.clearFooMessage().hasFooString());
+ message = builder.build();
+ assertFalse(message.hasFooMessage());
+ assertEquals(message.getFooMessage().getQuxInt(), 0);
+
+ // nested builder
+ builder = TestOneof2.newBuilder();
+ assertSame(builder.getFooMessageOrBuilder(),
+ TestOneof2.NestedMessage.getDefaultInstance());
+ assertFalse(builder.hasFooMessage());
+ builder.getFooMessageBuilder().setQuxInt(123);
+ assertTrue(builder.hasFooMessage());
+ assertEquals(builder.getFooMessage().getQuxInt(), 123);
+ message = builder.build();
+ assertTrue(message.hasFooMessage());
+ assertEquals(message.getFooMessage().getQuxInt(), 123);
+ }
+
+ // LazyMessage is tested in LazyMessageLiteTest.java
+ }
+
+ public void testOneofMerge() throws Exception {
+ // Primitive Type
+ {
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ TestOneof2 message = builder.setFooInt(123).build();
+ TestOneof2 message2 = TestOneof2.newBuilder().mergeFrom(message).build();
+ assertTrue(message2.hasFooInt());
+ assertEquals(message2.getFooInt(), 123);
+ }
+
+ // String
+ {
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ TestOneof2 message = builder.setFooString("foo").build();
+ TestOneof2 message2 = TestOneof2.newBuilder().mergeFrom(message).build();
+ assertTrue(message2.hasFooString());
+ assertEquals(message2.getFooString(), "foo");
+ }
+
+ // Enum
+ {
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ TestOneof2 message = builder.setFooEnum(TestOneof2.NestedEnum.BAR).build();
+ TestOneof2 message2 = TestOneof2.newBuilder().mergeFrom(message).build();
+ assertTrue(message2.hasFooEnum());
+ assertEquals(message2.getFooEnum(), TestOneof2.NestedEnum.BAR);
+ }
+
+ // Message
+ {
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ TestOneof2 message = builder.setFooMessage(
+ TestOneof2.NestedMessage.newBuilder().setQuxInt(234).build()).build();
+ TestOneof2 message2 = TestOneof2.newBuilder().mergeFrom(message).build();
+ assertTrue(message2.hasFooMessage());
+ assertEquals(message2.getFooMessage().getQuxInt(), 234);
+ }
+ }
+
+ public void testOneofSerialization() throws Exception {
+ // Primitive Type
+ {
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ TestOneof2 message = builder.setFooInt(123).build();
+ ByteString serialized = message.toByteString();
+ TestOneof2 message2 = TestOneof2.parseFrom(serialized);
+ assertTrue(message2.hasFooInt());
+ assertEquals(message2.getFooInt(), 123);
+ }
+
+ // String
+ {
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ TestOneof2 message = builder.setFooString("foo").build();
+ ByteString serialized = message.toByteString();
+ TestOneof2 message2 = TestOneof2.parseFrom(serialized);
+ assertTrue(message2.hasFooString());
+ assertEquals(message2.getFooString(), "foo");
+ }
+
+ // Enum
+ {
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ TestOneof2 message = builder.setFooEnum(TestOneof2.NestedEnum.BAR).build();
+ ByteString serialized = message.toByteString();
+ TestOneof2 message2 = TestOneof2.parseFrom(serialized);
+ assertTrue(message2.hasFooEnum());
+ assertEquals(message2.getFooEnum(), TestOneof2.NestedEnum.BAR);
+ }
+
+ // Message
+ {
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ TestOneof2 message = builder.setFooMessage(
+ TestOneof2.NestedMessage.newBuilder().setQuxInt(234).build()).build();
+ ByteString serialized = message.toByteString();
+ TestOneof2 message2 = TestOneof2.parseFrom(serialized);
+ assertTrue(message2.hasFooMessage());
+ assertEquals(message2.getFooMessage().getQuxInt(), 234);
+ }
+ }
+
+ public void testOneofNestedBuilderOnChangePropagation() {
+ NestedTestAllTypes.Builder parentBuilder = NestedTestAllTypes.newBuilder();
+ TestAllTypes.Builder builder = parentBuilder.getPayloadBuilder();
+ builder.getOneofNestedMessageBuilder();
+ assertTrue(builder.hasOneofNestedMessage());
+ assertTrue(parentBuilder.hasPayload());
+ NestedTestAllTypes message = parentBuilder.build();
+ assertTrue(message.hasPayload());
+ assertTrue(message.getPayload().hasOneofNestedMessage());
+ }
+
+ public void testGetRepeatedFieldBuilder() {
+ Descriptor descriptor = TestAllTypes.getDescriptor();
+
+ FieldDescriptor fieldDescriptor =
+ descriptor.findFieldByName("repeated_nested_message");
+ FieldDescriptor foreignFieldDescriptor =
+ descriptor.findFieldByName("repeated_foreign_message");
+ FieldDescriptor importFieldDescriptor =
+ descriptor.findFieldByName("repeated_import_message");
+
+ // Mutate the message with new field builder
+ // Mutate nested message
+ TestAllTypes.Builder builder1 = TestAllTypes.newBuilder();
+ Message.Builder fieldBuilder1 = builder1.newBuilderForField(
+ fieldDescriptor);
+ FieldDescriptor subFieldDescriptor1 =
+ fieldBuilder1.getDescriptorForType().findFieldByName("bb");
+ fieldBuilder1.setField(subFieldDescriptor1, 1);
+ builder1.addRepeatedField(fieldDescriptor, fieldBuilder1.build());
+
+ // Mutate foreign message
+ Message.Builder foreignFieldBuilder1 = builder1.newBuilderForField(
+ foreignFieldDescriptor);
+ FieldDescriptor subForeignFieldDescriptor1 =
+ foreignFieldBuilder1.getDescriptorForType().findFieldByName("c");
+ foreignFieldBuilder1.setField(subForeignFieldDescriptor1, 2);
+ builder1.addRepeatedField(foreignFieldDescriptor,
+ foreignFieldBuilder1.build());
+
+ // Mutate import message
+ Message.Builder importFieldBuilder1 = builder1.newBuilderForField(
+ importFieldDescriptor);
+ FieldDescriptor subImportFieldDescriptor1 =
+ importFieldBuilder1.getDescriptorForType().findFieldByName("d");
+ importFieldBuilder1.setField(subImportFieldDescriptor1, 3);
+ builder1.addRepeatedField(importFieldDescriptor,
+ importFieldBuilder1.build());
+
+ Message newMessage1 = builder1.build();
+
+ // Mutate the message with existing field builder
+ // Mutate nested message
+ TestAllTypes.Builder builder2 = TestAllTypes.newBuilder();
+ builder2.addRepeatedNestedMessageBuilder();
+ Message.Builder fieldBuilder2 = builder2.getRepeatedFieldBuilder(
+ fieldDescriptor, 0);
+ FieldDescriptor subFieldDescriptor2 =
+ fieldBuilder2.getDescriptorForType().findFieldByName("bb");
+ fieldBuilder2.setField(subFieldDescriptor2, 1);
+
+ // Mutate foreign message
+ Message.Builder foreignFieldBuilder2 = builder2.newBuilderForField(
+ foreignFieldDescriptor);
+ FieldDescriptor subForeignFieldDescriptor2 =
+ foreignFieldBuilder2.getDescriptorForType().findFieldByName("c");
+ foreignFieldBuilder2.setField(subForeignFieldDescriptor2, 2);
+ builder2.addRepeatedField(foreignFieldDescriptor,
+ foreignFieldBuilder2.build());
+
+ // Mutate import message
+ Message.Builder importFieldBuilder2 = builder2.newBuilderForField(
+ importFieldDescriptor);
+ FieldDescriptor subImportFieldDescriptor2 =
+ importFieldBuilder2.getDescriptorForType().findFieldByName("d");
+ importFieldBuilder2.setField(subImportFieldDescriptor2, 3);
+ builder2.addRepeatedField(importFieldDescriptor,
+ importFieldBuilder2.build());
+
+ Message newMessage2 = builder2.build();
+
+ // These two messages should be equal.
+ assertEquals(newMessage1, newMessage2);
+ }
+
+ public void testGetRepeatedFieldBuilderWithInitializedValue() {
+ Descriptor descriptor = TestAllTypes.getDescriptor();
+ FieldDescriptor fieldDescriptor =
+ descriptor.findFieldByName("repeated_nested_message");
+
+ // Before setting field, builder is initialized by default value.
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ builder.addRepeatedNestedMessageBuilder();
+ NestedMessage.Builder fieldBuilder =
+ (NestedMessage.Builder) builder.getRepeatedFieldBuilder(fieldDescriptor, 0);
+ assertEquals(0, fieldBuilder.getBb());
+
+ // Setting field value with new field builder instance.
+ builder = TestAllTypes.newBuilder();
+ NestedMessage.Builder newFieldBuilder =
+ builder.addRepeatedNestedMessageBuilder();
+ newFieldBuilder.setBb(2);
+ // Then get the field builder instance by getRepeatedFieldBuilder().
+ fieldBuilder =
+ (NestedMessage.Builder) builder.getRepeatedFieldBuilder(fieldDescriptor, 0);
+ // It should contain new value.
+ assertEquals(2, fieldBuilder.getBb());
+ // These two builder should be equal.
+ assertSame(fieldBuilder, newFieldBuilder);
+ }
+
+ public void testGetRepeatedFieldBuilderNotSupportedException() {
+ Descriptor descriptor = TestAllTypes.getDescriptor();
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ try {
+ builder.getRepeatedFieldBuilder(descriptor.findFieldByName("repeated_int32"), 0);
+ fail("Exception was not thrown");
+ } catch (UnsupportedOperationException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.getRepeatedFieldBuilder(
+ descriptor.findFieldByName("repeated_nested_enum"), 0);
+ fail("Exception was not thrown");
+ } catch (UnsupportedOperationException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.getRepeatedFieldBuilder(descriptor.findFieldByName("optional_int32"), 0);
+ fail("Exception was not thrown");
+ } catch (UnsupportedOperationException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.getRepeatedFieldBuilder(
+ descriptor.findFieldByName("optional_nested_enum"), 0);
+ fail("Exception was not thrown");
+ } catch (UnsupportedOperationException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.getRepeatedFieldBuilder(
+ descriptor.findFieldByName("optional_nested_message"), 0);
+ fail("Exception was not thrown");
+ } catch (UnsupportedOperationException e) {
+ // We expect this exception.
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java
new file mode 100644
index 0000000000..60c85450c3
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java
@@ -0,0 +1,461 @@
+// 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 static java.util.Arrays.asList;
+
+import java.util.Collections;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import junit.framework.TestCase;
+
+/**
+ * Tests for {@link IntArrayList}.
+ *
+ * @author dweis@google.com (Daniel Weis)
+ */
+public class IntArrayListTest extends TestCase {
+
+ private static final IntArrayList UNARY_LIST =
+ newImmutableIntArrayList(1);
+ private static final IntArrayList TERTIARY_LIST =
+ newImmutableIntArrayList(1, 2, 3);
+
+ private IntArrayList list;
+
+ @Override
+ protected void setUp() throws Exception {
+ list = new IntArrayList();
+ }
+
+ public void testEmptyListReturnsSameInstance() {
+ assertSame(IntArrayList.emptyList(), IntArrayList.emptyList());
+ }
+
+ public void testEmptyListIsImmutable() {
+ assertImmutable(IntArrayList.emptyList());
+ }
+
+ public void testMakeImmutable() {
+ list.addInt(3);
+ list.addInt(4);
+ list.addInt(5);
+ list.addInt(7);
+ list.makeImmutable();
+ assertImmutable(list);
+ }
+
+ public void testModificationWithIteration() {
+ list.addAll(asList(1, 2, 3, 4));
+ Iterator<Integer> iterator = list.iterator();
+ assertEquals(4, list.size());
+ assertEquals(1, (int) list.get(0));
+ assertEquals(1, (int) iterator.next());
+ list.set(0, 1);
+ assertEquals(2, (int) iterator.next());
+
+ list.remove(0);
+ try {
+ iterator.next();
+ fail();
+ } catch (ConcurrentModificationException e) {
+ // expected
+ }
+
+ iterator = list.iterator();
+ list.add(0, 0);
+ try {
+ iterator.next();
+ fail();
+ } catch (ConcurrentModificationException e) {
+ // expected
+ }
+ }
+
+ public void testGet() {
+ assertEquals(1, (int) TERTIARY_LIST.get(0));
+ assertEquals(2, (int) TERTIARY_LIST.get(1));
+ assertEquals(3, (int) TERTIARY_LIST.get(2));
+
+ try {
+ TERTIARY_LIST.get(-1);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ TERTIARY_LIST.get(3);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testGetInt() {
+ assertEquals(1, TERTIARY_LIST.getInt(0));
+ assertEquals(2, TERTIARY_LIST.getInt(1));
+ assertEquals(3, TERTIARY_LIST.getInt(2));
+
+ try {
+ TERTIARY_LIST.get(-1);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ TERTIARY_LIST.get(3);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testSize() {
+ assertEquals(0, IntArrayList.emptyList().size());
+ assertEquals(1, UNARY_LIST.size());
+ assertEquals(3, TERTIARY_LIST.size());
+
+ list.addInt(3);
+ list.addInt(4);
+ list.addInt(6);
+ list.addInt(8);
+ assertEquals(4, list.size());
+
+ list.remove(0);
+ assertEquals(3, list.size());
+
+ list.add(17);
+ assertEquals(4, list.size());
+ }
+
+ public void testSet() {
+ list.addInt(2);
+ list.addInt(4);
+
+ assertEquals(2, (int) list.set(0, 3));
+ assertEquals(3, list.getInt(0));
+
+ assertEquals(4, (int) list.set(1, 0));
+ assertEquals(0, list.getInt(1));
+
+ try {
+ list.set(-1, 0);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.set(2, 0);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testSetInt() {
+ list.addInt(1);
+ list.addInt(3);
+
+ assertEquals(1, list.setInt(0, 0));
+ assertEquals(0, list.getInt(0));
+
+ assertEquals(3, list.setInt(1, 0));
+ assertEquals(0, list.getInt(1));
+
+ try {
+ list.setInt(-1, 0);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.setInt(2, 0);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testAdd() {
+ assertEquals(0, list.size());
+
+ assertTrue(list.add(2));
+ assertEquals(asList(2), list);
+
+ assertTrue(list.add(3));
+ list.add(0, 4);
+ assertEquals(asList(4, 2, 3), list);
+
+ list.add(0, 1);
+ list.add(0, 0);
+ // Force a resize by getting up to 11 elements.
+ for (int i = 0; i < 6; i++) {
+ list.add(Integer.valueOf(5 + i));
+ }
+ assertEquals(
+ asList(0, 1, 4, 2, 3, 5, 6, 7, 8, 9, 10),
+ list);
+
+ try {
+ list.add(-1, 5);
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.add(4, 5);
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testAddInt() {
+ assertEquals(0, list.size());
+
+ list.addInt(2);
+ assertEquals(asList(2), list);
+
+ list.addInt(3);
+ assertEquals(asList(2, 3), list);
+ }
+
+ public void testAddAll() {
+ assertEquals(0, list.size());
+
+ assertTrue(list.addAll(Collections.singleton(1)));
+ assertEquals(1, list.size());
+ assertEquals(1, (int) list.get(0));
+ assertEquals(1, list.getInt(0));
+
+ assertTrue(list.addAll(asList(2, 3, 4, 5, 6)));
+ assertEquals(asList(1, 2, 3, 4, 5, 6), list);
+
+ assertTrue(list.addAll(TERTIARY_LIST));
+ assertEquals(asList(1, 2, 3, 4, 5, 6, 1, 2, 3), list);
+
+ assertFalse(list.addAll(Collections.<Integer>emptyList()));
+ assertFalse(list.addAll(IntArrayList.emptyList()));
+ }
+
+ public void testRemove() {
+ list.addAll(TERTIARY_LIST);
+ assertEquals(1, (int) list.remove(0));
+ assertEquals(asList(2, 3), list);
+
+ assertTrue(list.remove(Integer.valueOf(3)));
+ assertEquals(asList(2), list);
+
+ assertFalse(list.remove(Integer.valueOf(3)));
+ assertEquals(asList(2), list);
+
+ assertEquals(2, (int) list.remove(0));
+ assertEquals(asList(), list);
+
+ try {
+ list.remove(-1);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.remove(0);
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ private void assertImmutable(IntArrayList list) {
+ if (list.contains(1)) {
+ throw new RuntimeException("Cannot test the immutability of lists that contain 1.");
+ }
+
+ try {
+ list.add(1);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.add(0, 1);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(Collections.<Integer>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(Collections.singletonList(1));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(new IntArrayList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, Collections.singleton(1));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, Collections.<Integer>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addInt(0);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.clear();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.remove(1);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.remove(new Object());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(Collections.<Integer>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(Collections.singleton(1));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(Collections.<Integer>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(Collections.singleton(1));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.set(0, 0);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.setInt(0, 0);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ private static IntArrayList newImmutableIntArrayList(int... elements) {
+ IntArrayList list = new IntArrayList();
+ for (int element : elements) {
+ list.addInt(element);
+ }
+ list.makeImmutable();
+ return list;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/IsValidUtf8Test.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/IsValidUtf8Test.java
new file mode 100644
index 0000000000..756049b41f
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/IsValidUtf8Test.java
@@ -0,0 +1,186 @@
+// 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 static com.google.protobuf.IsValidUtf8TestUtil.DIRECT_NIO_FACTORY;
+import static com.google.protobuf.IsValidUtf8TestUtil.EXPECTED_ONE_BYTE_ROUNDTRIPPABLE_COUNT;
+import static com.google.protobuf.IsValidUtf8TestUtil.EXPECTED_THREE_BYTE_ROUNDTRIPPABLE_COUNT;
+import static com.google.protobuf.IsValidUtf8TestUtil.HEAP_NIO_FACTORY;
+import static com.google.protobuf.IsValidUtf8TestUtil.LITERAL_FACTORY;
+import static com.google.protobuf.IsValidUtf8TestUtil.testBytes;
+
+import com.google.protobuf.IsValidUtf8TestUtil.ByteStringFactory;
+import com.google.protobuf.IsValidUtf8TestUtil.Shard;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests cases for {@link ByteString#isValidUtf8()}. This includes three
+ * brute force tests that actually test every permutation of one byte, two byte,
+ * and three byte sequences to ensure that the method produces the right result
+ * for every possible byte encoding where "right" means it's consistent with
+ * java's UTF-8 string encoding/decoding such that the method returns true for
+ * any sequence that will round trip when converted to a String and then back to
+ * bytes and will return false for any sequence that will not round trip.
+ * See also {@link IsValidUtf8FourByteTest}. It also includes some
+ * other more targeted tests.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ * @author martinrb@google.com (Martin Buchholz)
+ */
+public class IsValidUtf8Test extends TestCase {
+ /**
+ * Tests that round tripping of all two byte permutations work.
+ */
+ public void testIsValidUtf8_1Byte() {
+ testBytes(LITERAL_FACTORY, 1, EXPECTED_ONE_BYTE_ROUNDTRIPPABLE_COUNT);
+ testBytes(HEAP_NIO_FACTORY, 1, EXPECTED_ONE_BYTE_ROUNDTRIPPABLE_COUNT);
+ testBytes(DIRECT_NIO_FACTORY, 1, EXPECTED_ONE_BYTE_ROUNDTRIPPABLE_COUNT);
+ }
+
+ /**
+ * Tests that round tripping of all two byte permutations work.
+ */
+ public void testIsValidUtf8_2Bytes() {
+ testBytes(LITERAL_FACTORY, 2, IsValidUtf8TestUtil.EXPECTED_TWO_BYTE_ROUNDTRIPPABLE_COUNT);
+ testBytes(HEAP_NIO_FACTORY, 2, IsValidUtf8TestUtil.EXPECTED_TWO_BYTE_ROUNDTRIPPABLE_COUNT);
+ testBytes(DIRECT_NIO_FACTORY, 2, IsValidUtf8TestUtil.EXPECTED_TWO_BYTE_ROUNDTRIPPABLE_COUNT);
+ }
+
+ /**
+ * Tests that round tripping of all three byte permutations work.
+ */
+ public void testIsValidUtf8_3Bytes() {
+ // Travis' OOM killer doesn't like this test
+ if (System.getenv("TRAVIS") == null) {
+ testBytes(LITERAL_FACTORY, 3, EXPECTED_THREE_BYTE_ROUNDTRIPPABLE_COUNT);
+ testBytes(HEAP_NIO_FACTORY, 3, EXPECTED_THREE_BYTE_ROUNDTRIPPABLE_COUNT);
+ testBytes(DIRECT_NIO_FACTORY, 3, EXPECTED_THREE_BYTE_ROUNDTRIPPABLE_COUNT);
+ }
+ }
+
+ /**
+ * Tests that round tripping of a sample of four byte permutations work.
+ * All permutations are prohibitively expensive to test for automated runs;
+ * {@link IsValidUtf8FourByteTest} is used for full coverage. This method
+ * tests specific four-byte cases.
+ */
+ public void testIsValidUtf8_4BytesSamples() {
+ // Valid 4 byte.
+ assertValidUtf8(0xF0, 0xA4, 0xAD, 0xA2);
+
+ // Bad trailing bytes
+ assertInvalidUtf8(0xF0, 0xA4, 0xAD, 0x7F);
+ assertInvalidUtf8(0xF0, 0xA4, 0xAD, 0xC0);
+
+ // Special cases for byte2
+ assertInvalidUtf8(0xF0, 0x8F, 0xAD, 0xA2);
+ assertInvalidUtf8(0xF4, 0x90, 0xAD, 0xA2);
+ }
+
+ /**
+ * Tests some hard-coded test cases.
+ */
+ public void testSomeSequences() {
+ // Empty
+ assertTrue(asBytes("").isValidUtf8());
+
+ // One-byte characters, including control characters
+ assertTrue(asBytes("\u0000abc\u007f").isValidUtf8());
+
+ // Two-byte characters
+ assertTrue(asBytes("\u00a2\u00a2").isValidUtf8());
+
+ // Three-byte characters
+ assertTrue(asBytes("\u020ac\u020ac").isValidUtf8());
+
+ // Four-byte characters
+ assertTrue(asBytes("\u024B62\u024B62").isValidUtf8());
+
+ // Mixed string
+ assertTrue(asBytes("a\u020ac\u00a2b\\u024B62u020acc\u00a2de\u024B62").isValidUtf8());
+
+ // Not a valid string
+ assertInvalidUtf8(-1, 0, -1, 0);
+ }
+
+ private byte[] toByteArray(int... bytes) {
+ byte[] realBytes = new byte[bytes.length];
+ for (int i = 0; i < bytes.length; i++) {
+ realBytes[i] = (byte) bytes[i];
+ }
+ return realBytes;
+ }
+
+ private void assertValidUtf8(ByteStringFactory factory, int[] bytes, boolean not) {
+ byte[] realBytes = toByteArray(bytes);
+ assertTrue(not ^ Utf8.isValidUtf8(realBytes));
+ assertTrue(not ^ Utf8.isValidUtf8(realBytes, 0, bytes.length));
+ ByteString leaf = factory.newByteString(realBytes);
+ ByteString sub = leaf.substring(0, bytes.length);
+ assertTrue(not ^ leaf.isValidUtf8());
+ assertTrue(not ^ sub.isValidUtf8());
+ ByteString[] ropes = {
+ RopeByteString.newInstanceForTest(ByteString.EMPTY, leaf),
+ RopeByteString.newInstanceForTest(ByteString.EMPTY, sub),
+ RopeByteString.newInstanceForTest(leaf, ByteString.EMPTY),
+ RopeByteString.newInstanceForTest(sub, ByteString.EMPTY),
+ RopeByteString.newInstanceForTest(sub, leaf)};
+ for (ByteString rope : ropes) {
+ assertTrue(not ^ rope.isValidUtf8());
+ }
+ }
+
+ private void assertValidUtf8(int... bytes) {
+ assertValidUtf8(LITERAL_FACTORY, bytes, false);
+ assertValidUtf8(HEAP_NIO_FACTORY, bytes, false);
+ assertValidUtf8(DIRECT_NIO_FACTORY, bytes, false);
+ }
+
+ private void assertInvalidUtf8(int... bytes) {
+ assertValidUtf8(LITERAL_FACTORY, bytes, true);
+ assertValidUtf8(HEAP_NIO_FACTORY, bytes, true);
+ assertValidUtf8(DIRECT_NIO_FACTORY, bytes, true);
+ }
+
+ private static ByteString asBytes(String s) {
+ return ByteString.copyFromUtf8(s);
+ }
+
+ public void testShardsHaveExpectedRoundTrippables() {
+ // A sanity check.
+ int actual = 0;
+ for (Shard shard : IsValidUtf8TestUtil.FOUR_BYTE_SHARDS) {
+ actual += shard.expected;
+ }
+ assertEquals(IsValidUtf8TestUtil.EXPECTED_FOUR_BYTE_ROUNDTRIPPABLE_COUNT, actual);
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java
new file mode 100644
index 0000000000..16a808bf31
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java
@@ -0,0 +1,448 @@
+// 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.lang.ref.SoftReference;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CoderResult;
+import java.nio.charset.CodingErrorAction;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
+import java.util.logging.Logger;
+
+/**
+ * Shared testing code for {@link IsValidUtf8Test} and
+ * {@link IsValidUtf8FourByteTest}.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ * @author martinrb@google.com (Martin Buchholz)
+ */
+final class IsValidUtf8TestUtil {
+ private static Logger logger = Logger.getLogger(IsValidUtf8TestUtil.class.getName());
+
+ private IsValidUtf8TestUtil() {}
+
+ static interface ByteStringFactory {
+ ByteString newByteString(byte[] bytes);
+ }
+
+ static final ByteStringFactory LITERAL_FACTORY = new ByteStringFactory() {
+ @Override
+ public ByteString newByteString(byte[] bytes) {
+ return ByteString.wrap(bytes);
+ }
+ };
+
+ static final ByteStringFactory HEAP_NIO_FACTORY = new ByteStringFactory() {
+ @Override
+ public ByteString newByteString(byte[] bytes) {
+ return new NioByteString(ByteBuffer.wrap(bytes));
+ }
+ };
+
+ private static ThreadLocal<SoftReference<ByteBuffer>> directBuffer =
+ new ThreadLocal<SoftReference<ByteBuffer>>();
+
+ /**
+ * Factory for direct {@link ByteBuffer} instances. To reduce direct memory usage, this
+ * uses a thread local direct buffer. This means that each call will overwrite the buffer's
+ * contents from the previous call, so the calling code must be careful not to continue using
+ * a buffer returned from a previous invocation.
+ */
+ static final ByteStringFactory DIRECT_NIO_FACTORY = new ByteStringFactory() {
+ @Override
+ public ByteString newByteString(byte[] bytes) {
+ SoftReference<ByteBuffer> ref = directBuffer.get();
+ ByteBuffer buffer = ref == null ? null : ref.get();
+ if (buffer == null || buffer.capacity() < bytes.length) {
+ buffer = ByteBuffer.allocateDirect(bytes.length);
+ directBuffer.set(new SoftReference<ByteBuffer>(buffer));
+ }
+ buffer.clear();
+ buffer.put(bytes);
+ buffer.flip();
+ return new NioByteString(buffer);
+ }
+ };
+
+ // 128 - [chars 0x0000 to 0x007f]
+ static final long ONE_BYTE_ROUNDTRIPPABLE_CHARACTERS = 0x007f - 0x0000 + 1;
+
+ // 128
+ static final long EXPECTED_ONE_BYTE_ROUNDTRIPPABLE_COUNT = ONE_BYTE_ROUNDTRIPPABLE_CHARACTERS;
+
+ // 1920 [chars 0x0080 to 0x07FF]
+ static final long TWO_BYTE_ROUNDTRIPPABLE_CHARACTERS = 0x07FF - 0x0080 + 1;
+
+ // 18,304
+ static final long EXPECTED_TWO_BYTE_ROUNDTRIPPABLE_COUNT =
+ // Both bytes are one byte characters
+ (long) Math.pow(EXPECTED_ONE_BYTE_ROUNDTRIPPABLE_COUNT, 2) +
+ // The possible number of two byte characters
+ TWO_BYTE_ROUNDTRIPPABLE_CHARACTERS;
+
+ // 2048
+ static final long THREE_BYTE_SURROGATES = 2 * 1024;
+
+ // 61,440 [chars 0x0800 to 0xFFFF, minus surrogates]
+ static final long THREE_BYTE_ROUNDTRIPPABLE_CHARACTERS =
+ 0xFFFF - 0x0800 + 1 - THREE_BYTE_SURROGATES;
+
+ // 2,650,112
+ static final long EXPECTED_THREE_BYTE_ROUNDTRIPPABLE_COUNT =
+ // All one byte characters
+ (long) Math.pow(EXPECTED_ONE_BYTE_ROUNDTRIPPABLE_COUNT, 3) +
+ // One two byte character and a one byte character
+ 2 * TWO_BYTE_ROUNDTRIPPABLE_CHARACTERS * ONE_BYTE_ROUNDTRIPPABLE_CHARACTERS +
+ // Three byte characters
+ THREE_BYTE_ROUNDTRIPPABLE_CHARACTERS;
+
+ // 1,048,576 [chars 0x10000L to 0x10FFFF]
+ static final long FOUR_BYTE_ROUNDTRIPPABLE_CHARACTERS = 0x10FFFF - 0x10000L + 1;
+
+ // 289,571,839
+ static final long EXPECTED_FOUR_BYTE_ROUNDTRIPPABLE_COUNT =
+ // All one byte characters
+ (long) Math.pow(EXPECTED_ONE_BYTE_ROUNDTRIPPABLE_COUNT, 4) +
+ // One and three byte characters
+ 2 * THREE_BYTE_ROUNDTRIPPABLE_CHARACTERS * ONE_BYTE_ROUNDTRIPPABLE_CHARACTERS +
+ // Two two byte characters
+ TWO_BYTE_ROUNDTRIPPABLE_CHARACTERS * TWO_BYTE_ROUNDTRIPPABLE_CHARACTERS +
+ // Permutations of one and two byte characters
+ 3 * TWO_BYTE_ROUNDTRIPPABLE_CHARACTERS * ONE_BYTE_ROUNDTRIPPABLE_CHARACTERS
+ * ONE_BYTE_ROUNDTRIPPABLE_CHARACTERS
+ +
+ // Four byte characters
+ FOUR_BYTE_ROUNDTRIPPABLE_CHARACTERS;
+
+ static final class Shard {
+ final long index;
+ final long start;
+ final long lim;
+ final long expected;
+
+
+ public Shard(long index, long start, long lim, long expected) {
+ assertTrue(start < lim);
+ this.index = index;
+ this.start = start;
+ this.lim = lim;
+ this.expected = expected;
+ }
+ }
+
+ static final long[] FOUR_BYTE_SHARDS_EXPECTED_ROUNTRIPPABLES =
+ generateFourByteShardsExpectedRunnables();
+
+ private static long[] generateFourByteShardsExpectedRunnables() {
+ long[] expected = new long[128];
+
+ // 0-63 are all 5300224
+ for (int i = 0; i <= 63; i++) {
+ expected[i] = 5300224;
+ }
+
+ // 97-111 are all 2342912
+ for (int i = 97; i <= 111; i++) {
+ expected[i] = 2342912;
+ }
+
+ // 113-117 are all 1048576
+ for (int i = 113; i <= 117; i++) {
+ expected[i] = 1048576;
+ }
+
+ // One offs
+ expected[112] = 786432;
+ expected[118] = 786432;
+ expected[119] = 1048576;
+ expected[120] = 458752;
+ expected[121] = 524288;
+ expected[122] = 65536;
+
+ // Anything not assigned was the default 0.
+ return expected;
+ }
+
+ static final List<Shard> FOUR_BYTE_SHARDS =
+ generateFourByteShards(128, FOUR_BYTE_SHARDS_EXPECTED_ROUNTRIPPABLES);
+
+
+ private static List<Shard> generateFourByteShards(int numShards, long[] expected) {
+ assertEquals(numShards, expected.length);
+ List<Shard> shards = new ArrayList<Shard>(numShards);
+ long LIM = 1L << 32;
+ long increment = LIM / numShards;
+ assertTrue(LIM % numShards == 0);
+ for (int i = 0; i < numShards; i++) {
+ shards.add(new Shard(i, increment * i, increment * (i + 1), expected[i]));
+ }
+ return shards;
+ }
+
+ /**
+ * Helper to run the loop to test all the permutations for the number of bytes
+ * specified.
+ *
+ * @param factory the factory for {@link ByteString} instances.
+ * @param numBytes the number of bytes in the byte array
+ * @param expectedCount the expected number of roundtrippable permutations
+ */
+ static void testBytes(ByteStringFactory factory, int numBytes, long expectedCount) {
+ testBytes(factory, numBytes, expectedCount, 0, -1);
+ }
+
+ /**
+ * Helper to run the loop to test all the permutations for the number of bytes
+ * specified. This overload is useful for debugging to get the loop to start
+ * at a certain character.
+ *
+ * @param factory the factory for {@link ByteString} instances.
+ * @param numBytes the number of bytes in the byte array
+ * @param expectedCount the expected number of roundtrippable permutations
+ * @param start the starting bytes encoded as a long as big-endian
+ * @param lim the limit of bytes to process encoded as a long as big-endian,
+ * or -1 to mean the max limit for numBytes
+ */
+ static void testBytes(
+ ByteStringFactory factory, int numBytes, long expectedCount, long start, long lim) {
+ Random rnd = new Random();
+ byte[] bytes = new byte[numBytes];
+
+ if (lim == -1) {
+ lim = 1L << (numBytes * 8);
+ }
+ long count = 0;
+ long countRoundTripped = 0;
+ for (long byteChar = start; byteChar < lim; byteChar++) {
+ long tmpByteChar = byteChar;
+ for (int i = 0; i < numBytes; i++) {
+ bytes[bytes.length - i - 1] = (byte) tmpByteChar;
+ tmpByteChar = tmpByteChar >> 8;
+ }
+ ByteString bs = factory.newByteString(bytes);
+ boolean isRoundTrippable = bs.isValidUtf8();
+ String s = new String(bytes, Internal.UTF_8);
+ byte[] bytesReencoded = s.getBytes(Internal.UTF_8);
+ boolean bytesEqual = Arrays.equals(bytes, bytesReencoded);
+
+ if (bytesEqual != isRoundTrippable) {
+ outputFailure(byteChar, bytes, bytesReencoded);
+ }
+
+ // Check agreement with static Utf8 methods.
+ assertEquals(isRoundTrippable, Utf8.isValidUtf8(bytes));
+ assertEquals(isRoundTrippable, Utf8.isValidUtf8(bytes, 0, numBytes));
+
+ // Test partial sequences.
+ // Partition numBytes into three segments (not necessarily non-empty).
+ int i = rnd.nextInt(numBytes);
+ int j = rnd.nextInt(numBytes);
+ if (j < i) {
+ int tmp = i;
+ i = j;
+ j = tmp;
+ }
+ int state1 = Utf8.partialIsValidUtf8(Utf8.COMPLETE, bytes, 0, i);
+ int state2 = Utf8.partialIsValidUtf8(state1, bytes, i, j);
+ int state3 = Utf8.partialIsValidUtf8(state2, bytes, j, numBytes);
+ if (isRoundTrippable != (state3 == Utf8.COMPLETE)) {
+ System.out.printf("state=%04x %04x %04x i=%d j=%d%n", state1, state2, state3, i, j);
+ outputFailure(byteChar, bytes, bytesReencoded);
+ }
+ assertEquals(isRoundTrippable, (state3 == Utf8.COMPLETE));
+
+ // Test ropes built out of small partial sequences
+ ByteString rope = RopeByteString.newInstanceForTest(
+ bs.substring(0, i),
+ RopeByteString.newInstanceForTest(bs.substring(i, j), bs.substring(j, numBytes)));
+ assertSame(RopeByteString.class, rope.getClass());
+
+ ByteString[] byteStrings = {bs, bs.substring(0, numBytes), rope};
+ for (ByteString x : byteStrings) {
+ assertEquals(isRoundTrippable, x.isValidUtf8());
+ assertEquals(state3, x.partialIsValidUtf8(Utf8.COMPLETE, 0, numBytes));
+
+ assertEquals(state1, x.partialIsValidUtf8(Utf8.COMPLETE, 0, i));
+ assertEquals(state1, x.substring(0, i).partialIsValidUtf8(Utf8.COMPLETE, 0, i));
+ assertEquals(state2, x.partialIsValidUtf8(state1, i, j - i));
+ assertEquals(state2, x.substring(i, j).partialIsValidUtf8(state1, 0, j - i));
+ assertEquals(state3, x.partialIsValidUtf8(state2, j, numBytes - j));
+ assertEquals(state3, x.substring(j, numBytes).partialIsValidUtf8(state2, 0, numBytes - j));
+ }
+
+ // ByteString reduplication should not affect its UTF-8 validity.
+ ByteString ropeADope = RopeByteString.newInstanceForTest(bs, bs.substring(0, numBytes));
+ assertEquals(isRoundTrippable, ropeADope.isValidUtf8());
+
+ if (isRoundTrippable) {
+ countRoundTripped++;
+ }
+ count++;
+ if (byteChar != 0 && byteChar % 1000000L == 0) {
+ logger.info("Processed " + (byteChar / 1000000L) + " million characters");
+ }
+ }
+ logger.info("Round tripped " + countRoundTripped + " of " + count);
+ assertEquals(expectedCount, countRoundTripped);
+ }
+
+ /**
+ * Variation of {@link #testBytes} that does less allocation using the
+ * low-level encoders/decoders directly. Checked in because it's useful for
+ * debugging when trying to process bytes faster, but since it doesn't use the
+ * actual String class, it's possible for incompatibilities to develop
+ * (although unlikely).
+ *
+ * @param factory the factory for {@link ByteString} instances.
+ * @param numBytes the number of bytes in the byte array
+ * @param expectedCount the expected number of roundtrippable permutations
+ * @param start the starting bytes encoded as a long as big-endian
+ * @param lim the limit of bytes to process encoded as a long as big-endian,
+ * or -1 to mean the max limit for numBytes
+ */
+ static void testBytesUsingByteBuffers(
+ ByteStringFactory factory, int numBytes, long expectedCount, long start, long lim) {
+ CharsetDecoder decoder =
+ Internal.UTF_8.newDecoder()
+ .onMalformedInput(CodingErrorAction.REPLACE)
+ .onUnmappableCharacter(CodingErrorAction.REPLACE);
+ CharsetEncoder encoder =
+ Internal.UTF_8.newEncoder()
+ .onMalformedInput(CodingErrorAction.REPLACE)
+ .onUnmappableCharacter(CodingErrorAction.REPLACE);
+ byte[] bytes = new byte[numBytes];
+ int maxChars = (int) (decoder.maxCharsPerByte() * numBytes) + 1;
+ char[] charsDecoded = new char[(int) (decoder.maxCharsPerByte() * numBytes) + 1];
+ int maxBytes = (int) (encoder.maxBytesPerChar() * maxChars) + 1;
+ byte[] bytesReencoded = new byte[maxBytes];
+
+ ByteBuffer bb = ByteBuffer.wrap(bytes);
+ CharBuffer cb = CharBuffer.wrap(charsDecoded);
+ ByteBuffer bbReencoded = ByteBuffer.wrap(bytesReencoded);
+ if (lim == -1) {
+ lim = 1L << (numBytes * 8);
+ }
+ long count = 0;
+ long countRoundTripped = 0;
+ for (long byteChar = start; byteChar < lim; byteChar++) {
+ bb.rewind();
+ bb.limit(bytes.length);
+ cb.rewind();
+ cb.limit(charsDecoded.length);
+ bbReencoded.rewind();
+ bbReencoded.limit(bytesReencoded.length);
+ encoder.reset();
+ decoder.reset();
+ long tmpByteChar = byteChar;
+ for (int i = 0; i < bytes.length; i++) {
+ bytes[bytes.length - i - 1] = (byte) tmpByteChar;
+ tmpByteChar = tmpByteChar >> 8;
+ }
+ boolean isRoundTrippable = factory.newByteString(bytes).isValidUtf8();
+ CoderResult result = decoder.decode(bb, cb, true);
+ assertFalse(result.isError());
+ result = decoder.flush(cb);
+ assertFalse(result.isError());
+
+ int charLen = cb.position();
+ cb.rewind();
+ cb.limit(charLen);
+ result = encoder.encode(cb, bbReencoded, true);
+ assertFalse(result.isError());
+ result = encoder.flush(bbReencoded);
+ assertFalse(result.isError());
+
+ boolean bytesEqual = true;
+ int bytesLen = bbReencoded.position();
+ if (bytesLen != numBytes) {
+ bytesEqual = false;
+ } else {
+ for (int i = 0; i < numBytes; i++) {
+ if (bytes[i] != bytesReencoded[i]) {
+ bytesEqual = false;
+ break;
+ }
+ }
+ }
+ if (bytesEqual != isRoundTrippable) {
+ outputFailure(byteChar, bytes, bytesReencoded, bytesLen);
+ }
+
+ count++;
+ if (isRoundTrippable) {
+ countRoundTripped++;
+ }
+ if (byteChar != 0 && byteChar % 1000000 == 0) {
+ logger.info("Processed " + (byteChar / 1000000) + " million characters");
+ }
+ }
+ logger.info("Round tripped " + countRoundTripped + " of " + count);
+ assertEquals(expectedCount, countRoundTripped);
+ }
+
+ private static void outputFailure(long byteChar, byte[] bytes, byte[] after) {
+ outputFailure(byteChar, bytes, after, after.length);
+ }
+
+ private static void outputFailure(long byteChar, byte[] bytes, byte[] after, int len) {
+ fail("Failure: (" + Long.toHexString(byteChar) + ") " + toHexString(bytes) + " => "
+ + toHexString(after, len));
+ }
+
+ private static String toHexString(byte[] b) {
+ return toHexString(b, b.length);
+ }
+
+ private static String toHexString(byte[] b, int len) {
+ StringBuilder s = new StringBuilder();
+ s.append("\"");
+ for (int i = 0; i < len; i++) {
+ if (i > 0) {
+ s.append(" ");
+ }
+ s.append(String.format("%02x", b[i] & 0xFF));
+ }
+ s.append("\"");
+ return s.toString();
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java
new file mode 100644
index 0000000000..813fe6bc69
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java
@@ -0,0 +1,246 @@
+// 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 static protobuf_unittest.UnittestProto.optionalInt32Extension;
+
+import protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import java.io.IOException;
+import junit.framework.TestCase;
+
+/**
+ * Unit test for {@link LazyFieldLite}.
+ *
+ * @author xiangl@google.com (Xiang Li)
+ */
+public class LazyFieldLiteTest extends TestCase {
+
+ public void testGetValue() {
+ MessageLite message = TestUtil.getAllSet();
+ LazyFieldLite lazyField = createLazyFieldLiteFromMessage(message);
+ assertEquals(message, lazyField.getValue(TestAllTypes.getDefaultInstance()));
+ changeValue(lazyField);
+ assertNotEqual(message, lazyField.getValue(TestAllTypes.getDefaultInstance()));
+ }
+
+ public void testGetValueEx() throws Exception {
+ TestAllExtensions message = TestUtil.getAllExtensionsSet();
+ LazyFieldLite lazyField = createLazyFieldLiteFromMessage(message);
+ assertEquals(message, lazyField.getValue(TestAllExtensions.getDefaultInstance()));
+ changeValue(lazyField);
+ assertNotEqual(message, lazyField.getValue(TestAllExtensions.getDefaultInstance()));
+ }
+
+ public void testSetValue() {
+ MessageLite message = TestUtil.getAllSet();
+ LazyFieldLite lazyField = createLazyFieldLiteFromMessage(message);
+ changeValue(lazyField);
+ assertNotEqual(message, lazyField.getValue(TestAllTypes.getDefaultInstance()));
+ message = lazyField.getValue(TestAllTypes.getDefaultInstance());
+ changeValue(lazyField);
+ assertEquals(message, lazyField.getValue(TestAllTypes.getDefaultInstance()));
+ }
+
+ public void testSetValueEx() throws Exception {
+ TestAllExtensions message = TestUtil.getAllExtensionsSet();
+ LazyFieldLite lazyField = createLazyFieldLiteFromMessage(message);
+ changeValue(lazyField);
+ assertNotEqual(message, lazyField.getValue(TestAllExtensions.getDefaultInstance()));
+ MessageLite value = lazyField.getValue(TestAllExtensions.getDefaultInstance());
+ changeValue(lazyField);
+ assertEquals(value, lazyField.getValue(TestAllExtensions.getDefaultInstance()));
+ }
+
+ public void testGetSerializedSize() {
+ MessageLite message = TestUtil.getAllSet();
+ LazyFieldLite lazyField = createLazyFieldLiteFromMessage(message);
+ assertEquals(message.getSerializedSize(), lazyField.getSerializedSize());
+ changeValue(lazyField);
+ assertNotEqual(message.getSerializedSize(), lazyField.getSerializedSize());
+ }
+
+ public void testGetSerializedSizeEx() throws Exception {
+ TestAllExtensions message = TestUtil.getAllExtensionsSet();
+ LazyFieldLite lazyField = createLazyFieldLiteFromMessage(message);
+ assertEquals(message.getSerializedSize(), lazyField.getSerializedSize());
+ changeValue(lazyField);
+ assertNotEqual(message.getSerializedSize(), lazyField.getSerializedSize());
+ }
+
+ public void testGetByteString() {
+ MessageLite message = TestUtil.getAllSet();
+ LazyFieldLite lazyField = createLazyFieldLiteFromMessage(message);
+ assertEquals(message.toByteString(), lazyField.toByteString());
+ changeValue(lazyField);
+ assertNotEqual(message.toByteString(), lazyField.toByteString());
+ }
+
+ public void testGetByteStringEx() throws Exception {
+ TestAllExtensions message = TestUtil.getAllExtensionsSet();
+ LazyFieldLite lazyField = createLazyFieldLiteFromMessage(message);
+ assertEquals(message.toByteString(), lazyField.toByteString());
+ changeValue(lazyField);
+ assertNotEqual(message.toByteString(), lazyField.toByteString());
+ }
+
+ public void testMergeExtensions() throws Exception {
+ TestAllExtensions message = TestUtil.getAllExtensionsSet();
+ LazyFieldLite original = createLazyFieldLiteFromMessage(message);
+ LazyFieldLite merged = new LazyFieldLite();
+ merged.merge(original);
+ TestAllExtensions value = (TestAllExtensions) merged.getValue(
+ TestAllExtensions.getDefaultInstance());
+ assertEquals(message, value);
+ }
+
+ public void testEmptyLazyField() throws Exception {
+ LazyFieldLite field = new LazyFieldLite();
+ assertEquals(0, field.getSerializedSize());
+ assertEquals(ByteString.EMPTY, field.toByteString());
+ }
+
+ public void testInvalidProto() throws Exception {
+ // Silently fails and uses the default instance.
+ LazyFieldLite field = new LazyFieldLite(
+ TestUtil.getExtensionRegistry(), ByteString.copyFromUtf8("invalid"));
+ assertEquals(
+ TestAllTypes.getDefaultInstance(), field.getValue(TestAllTypes.getDefaultInstance()));
+ assertEquals(0, field.getSerializedSize());
+ assertEquals(ByteString.EMPTY, field.toByteString());
+ }
+
+ public void testMergeBeforeParsing() throws Exception {
+ TestAllTypes message1 = TestAllTypes.newBuilder().setOptionalInt32(1).build();
+ LazyFieldLite field1 = createLazyFieldLiteFromMessage(message1);
+ TestAllTypes message2 = TestAllTypes.newBuilder().setOptionalInt64(2).build();
+ LazyFieldLite field2 = createLazyFieldLiteFromMessage(message2);
+
+ field1.merge(field2);
+ TestAllTypes expected =
+ TestAllTypes.newBuilder().setOptionalInt32(1).setOptionalInt64(2).build();
+ assertEquals(expected, field1.getValue(TestAllTypes.getDefaultInstance()));
+ }
+
+ public void testMergeOneNotParsed() throws Exception {
+ // Test a few different paths that involve one message that was not parsed.
+ TestAllTypes message1 = TestAllTypes.newBuilder().setOptionalInt32(1).build();
+ TestAllTypes message2 = TestAllTypes.newBuilder().setOptionalInt64(2).build();
+ TestAllTypes expected =
+ TestAllTypes.newBuilder().setOptionalInt32(1).setOptionalInt64(2).build();
+
+ LazyFieldLite field1 = LazyFieldLite.fromValue(message1);
+ field1.getValue(TestAllTypes.getDefaultInstance()); // Force parsing.
+ LazyFieldLite field2 = createLazyFieldLiteFromMessage(message2);
+ field1.merge(field2);
+ assertEquals(expected, field1.getValue(TestAllTypes.getDefaultInstance()));
+
+ // Now reverse which one is parsed first.
+ field1 = LazyFieldLite.fromValue(message1);
+ field2 = createLazyFieldLiteFromMessage(message2);
+ field2.getValue(TestAllTypes.getDefaultInstance()); // Force parsing.
+ field1.merge(field2);
+ assertEquals(expected, field1.getValue(TestAllTypes.getDefaultInstance()));
+ }
+
+ public void testMergeInvalid() throws Exception {
+ // Test a few different paths that involve one message that was not parsed.
+ TestAllTypes message = TestAllTypes.newBuilder().setOptionalInt32(1).build();
+ LazyFieldLite valid = LazyFieldLite.fromValue(message);
+ LazyFieldLite invalid = new LazyFieldLite(
+ TestUtil.getExtensionRegistry(), ByteString.copyFromUtf8("invalid"));
+ invalid.merge(valid);
+
+ // We swallow the exception and just use the set field.
+ assertEquals(message, invalid.getValue(TestAllTypes.getDefaultInstance()));
+ }
+
+ public void testMergeKeepsExtensionsWhenPossible() throws Exception {
+ // In this test we attempt to only use the empty registry, which will strip out all extensions
+ // when serializing and then parsing. We verify that each code path will attempt to not
+ // serialize and parse a message that was set directly without going through the
+ // extensionRegistry.
+ TestAllExtensions messageWithExtensions =
+ TestAllExtensions.newBuilder().setExtension(optionalInt32Extension, 42).build();
+ TestAllExtensions emptyMessage = TestAllExtensions.newBuilder().build();
+
+ ExtensionRegistryLite emptyRegistry = ExtensionRegistryLite.getEmptyRegistry();
+
+ LazyFieldLite field = LazyFieldLite.fromValue(messageWithExtensions);
+ field.merge(createLazyFieldLiteFromMessage(emptyRegistry, emptyMessage));
+ assertEquals(messageWithExtensions, field.getValue(TestAllExtensions.getDefaultInstance()));
+
+ // Now reverse the order of the merging.
+ field = createLazyFieldLiteFromMessage(emptyRegistry, emptyMessage);
+ field.merge(LazyFieldLite.fromValue(messageWithExtensions));
+ assertEquals(messageWithExtensions, field.getValue(TestAllExtensions.getDefaultInstance()));
+
+ // Now try parsing the empty field first.
+ field = LazyFieldLite.fromValue(messageWithExtensions);
+ LazyFieldLite other = createLazyFieldLiteFromMessage(emptyRegistry, emptyMessage);
+ other.getValue(TestAllExtensions.getDefaultInstance()); // Force parsing.
+ field.merge(other);
+ assertEquals(messageWithExtensions, field.getValue(TestAllExtensions.getDefaultInstance()));
+
+ // And again reverse.
+ field = createLazyFieldLiteFromMessage(emptyRegistry, emptyMessage);
+ field.getValue(TestAllExtensions.getDefaultInstance()); // Force parsing.
+ other = LazyFieldLite.fromValue(messageWithExtensions);
+ field.merge(other);
+ assertEquals(messageWithExtensions, field.getValue(TestAllExtensions.getDefaultInstance()));
+ }
+
+
+ // Help methods.
+
+ private LazyFieldLite createLazyFieldLiteFromMessage(MessageLite message) {
+ return createLazyFieldLiteFromMessage(TestUtil.getExtensionRegistry(), message);
+ }
+
+ private LazyFieldLite createLazyFieldLiteFromMessage(
+ ExtensionRegistryLite extensionRegistry, MessageLite message) {
+ ByteString bytes = message.toByteString();
+ return new LazyFieldLite(extensionRegistry, bytes);
+ }
+
+ private void changeValue(LazyFieldLite lazyField) {
+ TestAllTypes.Builder builder = TestUtil.getAllSet().toBuilder();
+ builder.addRepeatedBool(true);
+ MessageLite newMessage = builder.build();
+ lazyField.setValue(newMessage);
+ }
+
+ private void assertNotEqual(Object unexpected, Object actual) {
+ assertFalse(unexpected == actual
+ || (unexpected != null && unexpected.equals(actual)));
+ }
+
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyFieldTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyFieldTest.java
new file mode 100644
index 0000000000..5f013f3ce3
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyFieldTest.java
@@ -0,0 +1,120 @@
+// 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 protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import java.io.IOException;
+import junit.framework.TestCase;
+
+/**
+ * Unit test for {@link LazyField}.
+ *
+ * @author xiangl@google.com (Xiang Li)
+ */
+public class LazyFieldTest extends TestCase {
+ public void testHashCode() {
+ MessageLite message = TestUtil.getAllSet();
+ LazyField lazyField =
+ createLazyFieldFromMessage(message);
+ assertEquals(message.hashCode(), lazyField.hashCode());
+ lazyField.getValue();
+ assertEquals(message.hashCode(), lazyField.hashCode());
+ changeValue(lazyField);
+ // make sure two messages have different hash code
+ assertNotEqual(message.hashCode(), lazyField.hashCode());
+ }
+
+ public void testHashCodeEx() throws Exception {
+ TestAllExtensions message = TestUtil.getAllExtensionsSet();
+ LazyField lazyField = createLazyFieldFromMessage(message);
+ assertEquals(message.hashCode(), lazyField.hashCode());
+ lazyField.getValue();
+ assertEquals(message.hashCode(), lazyField.hashCode());
+ changeValue(lazyField);
+ // make sure two messages have different hash code
+ assertNotEqual(message.hashCode(), lazyField.hashCode());
+ }
+
+ public void testGetValue() {
+ MessageLite message = TestUtil.getAllSet();
+ LazyField lazyField = createLazyFieldFromMessage(message);
+ assertEquals(message, lazyField.getValue());
+ changeValue(lazyField);
+ assertNotEqual(message, lazyField.getValue());
+ }
+
+ public void testGetValueEx() throws Exception {
+ TestAllExtensions message = TestUtil.getAllExtensionsSet();
+ LazyField lazyField = createLazyFieldFromMessage(message);
+ assertEquals(message, lazyField.getValue());
+ changeValue(lazyField);
+ assertNotEqual(message, lazyField.getValue());
+ }
+
+ public void testEqualsObject() {
+ MessageLite message = TestUtil.getAllSet();
+ LazyField lazyField = createLazyFieldFromMessage(message);
+ assertTrue(lazyField.equals(message));
+ changeValue(lazyField);
+ assertFalse(lazyField.equals(message));
+ assertFalse(message.equals(lazyField.getValue()));
+ }
+
+ public void testEqualsObjectEx() throws Exception {
+ TestAllExtensions message = TestUtil.getAllExtensionsSet();
+ LazyField lazyField = createLazyFieldFromMessage(message);
+ assertTrue(lazyField.equals(message));
+ changeValue(lazyField);
+ assertFalse(lazyField.equals(message));
+ assertFalse(message.equals(lazyField.getValue()));
+ }
+
+ // Help methods.
+
+ private LazyField createLazyFieldFromMessage(MessageLite message) {
+ ByteString bytes = message.toByteString();
+ return new LazyField(message.getDefaultInstanceForType(),
+ TestUtil.getExtensionRegistry(), bytes);
+ }
+
+ private void changeValue(LazyField lazyField) {
+ TestAllTypes.Builder builder = TestUtil.getAllSet().toBuilder();
+ builder.addRepeatedBool(true);
+ MessageLite newMessage = builder.build();
+ lazyField.setValue(newMessage);
+ }
+
+ private void assertNotEqual(Object unexpected, Object actual) {
+ assertFalse(unexpected == actual
+ || (unexpected != null && unexpected.equals(actual)));
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyMessageLiteTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyMessageLiteTest.java
new file mode 100644
index 0000000000..968ca2065c
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyMessageLiteTest.java
@@ -0,0 +1,335 @@
+// 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 protobuf_unittest.LazyFieldsLite.LazyExtension;
+import protobuf_unittest.LazyFieldsLite.LazyInnerMessageLite;
+import protobuf_unittest.LazyFieldsLite.LazyMessageLite;
+import protobuf_unittest.LazyFieldsLite.LazyNestedInnerMessageLite;
+import java.util.ArrayList;
+import junit.framework.TestCase;
+
+/**
+ * Unit test for messages with lazy fields.
+ *
+ * @author niwasaki@google.com (Naoki Iwasaki)
+ */
+public class LazyMessageLiteTest extends TestCase {
+
+ private Parser<LazyInnerMessageLite> originalLazyInnerMessageLiteParser;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testSetValues() {
+ LazyNestedInnerMessageLite nested = LazyNestedInnerMessageLite.newBuilder()
+ .setNum(3)
+ .build();
+ LazyInnerMessageLite inner = LazyInnerMessageLite.newBuilder()
+ .setNum(2)
+ .setNested(nested)
+ .build();
+ LazyMessageLite outer = LazyMessageLite.newBuilder()
+ .setNum(1)
+ .setInner(inner)
+ .setOneofNum(123)
+ .setOneofInner(inner)
+ .build();
+
+ assertEquals(1, outer.getNum());
+ assertEquals(421, outer.getNumWithDefault());
+
+ assertEquals(2, outer.getInner().getNum());
+ assertEquals(42, outer.getInner().getNumWithDefault());
+
+ assertEquals(3, outer.getInner().getNested().getNum());
+ assertEquals(4, outer.getInner().getNested().getNumWithDefault());
+
+ assertFalse(outer.hasOneofNum());
+ assertTrue(outer.hasOneofInner());
+
+ assertEquals(2, outer.getOneofInner().getNum());
+ assertEquals(42, outer.getOneofInner().getNumWithDefault());
+ assertEquals(3, outer.getOneofInner().getNested().getNum());
+ assertEquals(4, outer.getOneofInner().getNested().getNumWithDefault());
+ }
+
+ public void testSetRepeatedValues() {
+ LazyMessageLite outer = LazyMessageLite.newBuilder()
+ .setNum(1)
+ .addRepeatedInner(LazyInnerMessageLite.newBuilder().setNum(119))
+ .addRepeatedInner(LazyInnerMessageLite.newBuilder().setNum(122))
+ .build();
+
+ assertEquals(1, outer.getNum());
+ assertEquals(2, outer.getRepeatedInnerCount());
+ assertEquals(119, outer.getRepeatedInner(0).getNum());
+ assertEquals(122, outer.getRepeatedInner(1).getNum());
+ }
+
+ public void testRepeatedMutability() throws Exception {
+ LazyMessageLite outer = LazyMessageLite.newBuilder()
+ .addRepeatedInner(LazyInnerMessageLite.newBuilder().setNum(119))
+ .addRepeatedInner(LazyInnerMessageLite.newBuilder().setNum(122))
+ .build();
+
+ outer = LazyMessageLite.parseFrom(outer.toByteArray());
+ try {
+ outer.getRepeatedInnerList().set(1, null);
+ fail();
+ } catch (UnsupportedOperationException expected) {}
+ }
+
+ public void testAddAll() {
+ ArrayList<LazyInnerMessageLite> inners = new ArrayList<LazyInnerMessageLite>();
+ int count = 4;
+ for (int i = 0; i < count; i++) {
+ LazyInnerMessageLite inner = LazyInnerMessageLite.newBuilder()
+ .setNum(i)
+ .build();
+ inners.add(inner);
+ }
+
+ LazyMessageLite outer = LazyMessageLite.newBuilder()
+ .addAllRepeatedInner(inners)
+ .build();
+ assertEquals(count, outer.getRepeatedInnerCount());
+ for (int i = 0; i < count; i++) {
+ assertEquals(i, outer.getRepeatedInner(i).getNum());
+ }
+ }
+
+ public void testGetDefaultValues() {
+ LazyMessageLite outer = LazyMessageLite.newBuilder()
+ .build();
+
+ assertEquals(0, outer.getNum());
+ assertEquals(421, outer.getNumWithDefault());
+
+ assertEquals(0, outer.getInner().getNum());
+ assertEquals(42, outer.getInner().getNumWithDefault());
+
+ assertEquals(0, outer.getInner().getNested().getNum());
+ assertEquals(4, outer.getInner().getNested().getNumWithDefault());
+
+ assertEquals(0, outer.getOneofNum());
+
+ assertEquals(0, outer.getOneofInner().getNum());
+ assertEquals(42, outer.getOneofInner().getNumWithDefault());
+ assertEquals(0, outer.getOneofInner().getNested().getNum());
+ assertEquals(4, outer.getOneofInner().getNested().getNumWithDefault());
+ }
+
+ public void testClearValues() {
+ LazyInnerMessageLite inner = LazyInnerMessageLite.newBuilder()
+ .setNum(115)
+ .build();
+
+ LazyMessageLite.Builder outerBuilder = LazyMessageLite.newBuilder();
+
+ assertEquals(0, outerBuilder.build().getNum());
+
+
+ // Set/Clear num
+ outerBuilder.setNum(100);
+
+ assertEquals(100, outerBuilder.build().getNum());
+ assertEquals(421, outerBuilder.build().getNumWithDefault());
+ assertFalse(outerBuilder.build().hasInner());
+
+ outerBuilder.clearNum();
+
+ assertEquals(0, outerBuilder.build().getNum());
+ assertEquals(421, outerBuilder.build().getNumWithDefault());
+ assertFalse(outerBuilder.build().hasInner());
+
+
+ // Set/Clear all
+ outerBuilder.setNum(100)
+ .setInner(inner)
+ .addRepeatedInner(LazyInnerMessageLite.newBuilder().setNum(119))
+ .addRepeatedInner(LazyInnerMessageLite.newBuilder().setNum(122))
+ .setOneofInner(LazyInnerMessageLite.newBuilder().setNum(123));
+
+ LazyMessageLite outer = outerBuilder.build();
+ assertEquals(100, outer.getNum());
+ assertEquals(421, outer.getNumWithDefault());
+ assertTrue(outer.hasInner());
+ assertEquals(115, outer.getInner().getNum());
+ assertEquals(2, outer.getRepeatedInnerCount());
+ assertEquals(119, outer.getRepeatedInner(0).getNum());
+ assertEquals(122, outer.getRepeatedInner(1).getNum());
+ assertTrue(outer.hasOneofInner());
+ assertEquals(123, outer.getOneofInner().getNum());
+
+ outerBuilder.clear();
+
+ outer = outerBuilder.build();
+
+ assertEquals(0, outer.getNum());
+ assertEquals(421, outer.getNumWithDefault());
+ assertFalse(outer.hasInner());
+ assertEquals(0, outer.getRepeatedInnerCount());
+ assertFalse(outer.hasOneofInner());
+ assertEquals(0, outer.getOneofInner().getNum());
+ }
+
+ public void testMergeValues() {
+ LazyMessageLite outerBase = LazyMessageLite.newBuilder()
+ .setNumWithDefault(122)
+ .build();
+
+ LazyInnerMessageLite innerMerging = LazyInnerMessageLite.newBuilder()
+ .setNum(115)
+ .build();
+ LazyMessageLite outerMerging = LazyMessageLite.newBuilder()
+ .setNum(119)
+ .setInner(innerMerging)
+ .setOneofInner(innerMerging)
+ .build();
+
+ LazyMessageLite merged = LazyMessageLite
+ .newBuilder(outerBase)
+ .mergeFrom(outerMerging)
+ .build();
+ assertEquals(119, merged.getNum());
+ assertEquals(122, merged.getNumWithDefault());
+ assertEquals(115, merged.getInner().getNum());
+ assertEquals(42, merged.getInner().getNumWithDefault());
+ assertEquals(115, merged.getOneofInner().getNum());
+ assertEquals(42, merged.getOneofInner().getNumWithDefault());
+ }
+
+ public void testMergeDefaultValues() {
+ LazyInnerMessageLite innerBase = LazyInnerMessageLite.newBuilder()
+ .setNum(115)
+ .build();
+ LazyMessageLite outerBase = LazyMessageLite.newBuilder()
+ .setNum(119)
+ .setNumWithDefault(122)
+ .setInner(innerBase)
+ .setOneofInner(innerBase)
+ .build();
+
+ LazyMessageLite outerMerging = LazyMessageLite.newBuilder()
+ .build();
+
+ LazyMessageLite merged = LazyMessageLite
+ .newBuilder(outerBase)
+ .mergeFrom(outerMerging)
+ .build();
+ // Merging default-instance shouldn't overwrite values in the base message.
+ assertEquals(119, merged.getNum());
+ assertEquals(122, merged.getNumWithDefault());
+ assertEquals(115, merged.getInner().getNum());
+ assertEquals(42, merged.getInner().getNumWithDefault());
+ assertEquals(115, merged.getOneofInner().getNum());
+ assertEquals(42, merged.getOneofInner().getNumWithDefault());
+ }
+
+ // Regression test for b/28198805.
+ public void testMergeOneofMessages() throws Exception {
+ LazyInnerMessageLite inner = LazyInnerMessageLite.newBuilder().build();
+ LazyMessageLite outer = LazyMessageLite.newBuilder().setOneofInner(inner).build();
+ ByteString data1 = outer.toByteString();
+
+ // The following should not alter the content of the 'outer' message.
+ LazyMessageLite.Builder merged = LazyMessageLite.newBuilder().mergeFrom(outer);
+ LazyInnerMessageLite anotherInner = LazyInnerMessageLite.newBuilder().setNum(12345).build();
+ merged.setOneofInner(anotherInner);
+
+ // Check that the 'outer' stays the same.
+ ByteString data2 = outer.toByteString();
+ assertEquals(data1, data2);
+ assertEquals(0, outer.getOneofInner().getNum());
+ }
+
+ public void testSerialize() throws InvalidProtocolBufferException {
+ LazyNestedInnerMessageLite nested = LazyNestedInnerMessageLite.newBuilder()
+ .setNum(3)
+ .build();
+ LazyInnerMessageLite inner = LazyInnerMessageLite.newBuilder()
+ .setNum(2)
+ .setNested(nested)
+ .build();
+ LazyMessageLite outer = LazyMessageLite.newBuilder()
+ .setNum(1)
+ .setInner(inner)
+ .setOneofInner(inner)
+ .build();
+
+ ByteString bytes = outer.toByteString();
+ assertEquals(bytes.size(), outer.getSerializedSize());
+
+ LazyMessageLite deserialized = LazyMessageLite.parseFrom(bytes);
+
+ assertEquals(1, deserialized.getNum());
+ assertEquals(421, deserialized.getNumWithDefault());
+
+ assertEquals(2, deserialized.getInner().getNum());
+ assertEquals(42, deserialized.getInner().getNumWithDefault());
+
+ assertEquals(3, deserialized.getInner().getNested().getNum());
+ assertEquals(4, deserialized.getInner().getNested().getNumWithDefault());
+
+ assertEquals(2, deserialized.getOneofInner().getNum());
+ assertEquals(42, deserialized.getOneofInner().getNumWithDefault());
+ assertEquals(3, deserialized.getOneofInner().getNested().getNum());
+ assertEquals(4, deserialized.getOneofInner().getNested().getNumWithDefault());
+
+ assertEquals(bytes, deserialized.toByteString());
+ }
+
+ public void testExtensions() throws Exception {
+ LazyInnerMessageLite.Builder innerBuilder = LazyInnerMessageLite.newBuilder();
+ innerBuilder.setExtension(
+ LazyExtension.extension, LazyExtension.newBuilder()
+ .setName("name").build());
+ assertTrue(innerBuilder.hasExtension(LazyExtension.extension));
+ assertEquals("name", innerBuilder.getExtension(LazyExtension.extension).getName());
+
+ LazyInnerMessageLite innerMessage = innerBuilder.build();
+ assertTrue(innerMessage.hasExtension(LazyExtension.extension));
+ assertEquals("name", innerMessage.getExtension(LazyExtension.extension).getName());
+
+ LazyMessageLite lite = LazyMessageLite.newBuilder()
+ .setInner(innerMessage).build();
+ assertTrue(lite.getInner().hasExtension(LazyExtension.extension));
+ assertEquals("name", lite.getInner().getExtension(LazyExtension.extension).getName());
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java
new file mode 100644
index 0000000000..2fc3124d4c
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyStringArrayListTest.java
@@ -0,0 +1,363 @@
+// 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 static java.util.Arrays.asList;
+
+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}.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class LazyStringArrayListTest extends TestCase {
+
+ private static String STRING_A = "A";
+ private static String STRING_B = "B";
+ private static String STRING_C = "C";
+
+ private static ByteString BYTE_STRING_A = ByteString.copyFromUtf8("A");
+ private static ByteString BYTE_STRING_B = ByteString.copyFromUtf8("B");
+ private static ByteString BYTE_STRING_C = ByteString.copyFromUtf8("C");
+
+ public void testJustStrings() {
+ LazyStringArrayList list = new LazyStringArrayList();
+ list.add(STRING_A);
+ list.add(STRING_B);
+ list.add(STRING_C);
+
+ assertEquals(3, list.size());
+ assertSame(STRING_A, list.get(0));
+ assertSame(STRING_B, list.get(1));
+ assertSame(STRING_C, list.get(2));
+
+ list.set(1, STRING_C);
+ assertSame(STRING_C, list.get(1));
+
+ list.remove(1);
+ assertSame(STRING_A, list.get(0));
+ assertSame(STRING_C, list.get(1));
+
+ List<ByteString> byteStringList = list.asByteStringList();
+ assertEquals(BYTE_STRING_A, byteStringList.get(0));
+ assertEquals(BYTE_STRING_C, byteStringList.get(1));
+
+ // Underlying list should be transformed.
+ assertSame(byteStringList.get(0), list.getByteString(0));
+ assertSame(byteStringList.get(1), list.getByteString(1));
+ }
+
+ public void testJustByteString() {
+ LazyStringArrayList list = new LazyStringArrayList();
+ list.add(BYTE_STRING_A);
+ list.add(BYTE_STRING_B);
+ list.add(BYTE_STRING_C);
+
+ assertEquals(3, list.size());
+ assertSame(BYTE_STRING_A, list.getByteString(0));
+ assertSame(BYTE_STRING_B, list.getByteString(1));
+ assertSame(BYTE_STRING_C, list.getByteString(2));
+
+ list.remove(1);
+ assertSame(BYTE_STRING_A, list.getByteString(0));
+ assertSame(BYTE_STRING_C, list.getByteString(1));
+
+ List<ByteString> byteStringList = list.asByteStringList();
+ assertSame(BYTE_STRING_A, byteStringList.get(0));
+ assertSame(BYTE_STRING_C, byteStringList.get(1));
+ }
+
+ public void testConversionBackAndForth() {
+ LazyStringArrayList list = new LazyStringArrayList();
+ list.add(STRING_A);
+ list.add(BYTE_STRING_B);
+ list.add(BYTE_STRING_C);
+
+ // String a should be the same because it was originally a string
+ assertSame(STRING_A, list.get(0));
+
+ // String b and c should be different because the string has to be computed
+ // from the ByteString
+ String bPrime = list.get(1);
+ assertNotSame(STRING_B, bPrime);
+ assertEquals(STRING_B, bPrime);
+ String cPrime = list.get(2);
+ assertNotSame(STRING_C, cPrime);
+ assertEquals(STRING_C, cPrime);
+
+ // String c and c should stay the same once cached.
+ assertSame(bPrime, list.get(1));
+ assertSame(cPrime, list.get(2));
+
+ // ByteString needs to be computed from string for both a and b
+ ByteString aPrimeByteString = list.getByteString(0);
+ assertEquals(BYTE_STRING_A, aPrimeByteString);
+ ByteString bPrimeByteString = list.getByteString(1);
+ assertNotSame(BYTE_STRING_B, bPrimeByteString);
+ assertEquals(BYTE_STRING_B, list.getByteString(1));
+
+ // Once cached, ByteString should stay cached.
+ assertSame(aPrimeByteString, list.getByteString(0));
+ assertSame(bPrimeByteString, list.getByteString(1));
+ }
+
+ public void testCopyConstructorCopiesByReference() {
+ LazyStringArrayList list1 = new LazyStringArrayList();
+ list1.add(STRING_A);
+ list1.add(BYTE_STRING_B);
+ list1.add(BYTE_STRING_C);
+
+ LazyStringArrayList list2 = new LazyStringArrayList(list1);
+ assertEquals(3, list2.size());
+ assertSame(STRING_A, list2.get(0));
+ assertSame(BYTE_STRING_B, list2.getByteString(1));
+ assertSame(BYTE_STRING_C, list2.getByteString(2));
+ }
+
+ public void testListCopyConstructor() {
+ List<String> list1 = new ArrayList<String>();
+ list1.add(STRING_A);
+ list1.add(STRING_B);
+ list1.add(STRING_C);
+
+ LazyStringArrayList list2 = new LazyStringArrayList(list1);
+ assertEquals(3, list2.size());
+ assertSame(STRING_A, list2.get(0));
+ assertSame(STRING_B, list2.get(1));
+ assertSame(STRING_C, list2.get(2));
+ }
+
+ public void testAddAllCopiesByReferenceIfPossible() {
+ LazyStringArrayList list1 = new LazyStringArrayList();
+ list1.add(STRING_A);
+ list1.add(BYTE_STRING_B);
+ list1.add(BYTE_STRING_C);
+
+ LazyStringArrayList list2 = new LazyStringArrayList();
+ list2.addAll(list1);
+
+ assertEquals(3, list2.size());
+ assertSame(STRING_A, list2.get(0));
+ assertSame(BYTE_STRING_B, list2.getByteString(1));
+ assertSame(BYTE_STRING_C, list2.getByteString(2));
+ }
+
+ public void testModificationWithIteration() {
+ LazyStringArrayList list = new LazyStringArrayList();
+ list.addAll(asList(STRING_A, STRING_B, STRING_C));
+ Iterator<String> iterator = list.iterator();
+ assertEquals(3, list.size());
+ assertEquals(STRING_A, list.get(0));
+ assertEquals(STRING_A, iterator.next());
+
+ // Does not structurally modify.
+ iterator = list.iterator();
+ list.set(0, STRING_B);
+ iterator.next();
+
+ list.remove(0);
+ try {
+ iterator.next();
+ fail();
+ } catch (ConcurrentModificationException e) {
+ // expected
+ }
+
+ iterator = list.iterator();
+ list.add(0, STRING_C);
+ try {
+ iterator.next();
+ fail();
+ } catch (ConcurrentModificationException e) {
+ // expected
+ }
+ }
+
+ public void testMakeImmutable() {
+ LazyStringArrayList list = new LazyStringArrayList();
+ list.add(STRING_A);
+ list.add(STRING_B);
+ list.add(STRING_C);
+ list.makeImmutable();
+ assertGenericListImmutable(list, STRING_A);
+
+ // LazyStringArrayList has extra methods not covered in the generic
+ // assertion.
+
+ try {
+ list.add(BYTE_STRING_A.toByteArray());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.add(BYTE_STRING_A);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAllByteArray(Collections.singletonList(BYTE_STRING_A.toByteArray()));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAllByteString(asList(BYTE_STRING_A));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.mergeFrom(new LazyStringArrayList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.set(0, BYTE_STRING_A.toByteArray());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.set(0, BYTE_STRING_A);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ public void testImmutabilityPropagation() {
+ LazyStringArrayList list = new LazyStringArrayList();
+ list.add(STRING_A);
+ list.makeImmutable();
+
+ assertGenericListImmutable(list.asByteStringList(), BYTE_STRING_A);
+
+ // Arrays use reference equality so need to retrieve the underlying value
+ // to properly test deep immutability.
+ List<byte[]> byteArrayList = list.asByteArrayList();
+ assertGenericListImmutable(byteArrayList, byteArrayList.get(0));
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> void assertGenericListImmutable(List<T> list, T value) {
+ try {
+ list.add(value);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.add(0, value);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(asList(value));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, asList(value));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.clear();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.remove(0);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.remove(value);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(asList(value));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(asList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(asList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.set(0, value);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java
new file mode 100644
index 0000000000..006e493366
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java
@@ -0,0 +1,130 @@
+// 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 protobuf_unittest.UnittestProto;
+import java.io.IOException;
+import junit.framework.TestCase;
+
+/**
+ * Tests to make sure the lazy conversion of UTF8-encoded byte arrays to
+ * strings works correctly.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class LazyStringEndToEndTest extends TestCase {
+
+ private static ByteString TEST_ALL_TYPES_SERIALIZED_WITH_ILLEGAL_UTF8 =
+ ByteString.copyFrom(new byte[] {
+ 114, 4, -1, 0, -1, 0, -30, 2, 4, -1,
+ 0, -1, 0, -30, 2, 4, -1, 0, -1, 0, });
+
+ private ByteString encodedTestAllTypes;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.encodedTestAllTypes = UnittestProto.TestAllTypes.newBuilder()
+ .setOptionalString("foo")
+ .addRepeatedString("bar")
+ .addRepeatedString("baz")
+ .build()
+ .toByteString();
+ }
+
+ /**
+ * Tests that an invalid UTF8 string will roundtrip through a parse
+ * and serialization.
+ */
+ public void testParseAndSerialize() throws InvalidProtocolBufferException {
+ UnittestProto.TestAllTypes tV2 = UnittestProto.TestAllTypes.parseFrom(
+ TEST_ALL_TYPES_SERIALIZED_WITH_ILLEGAL_UTF8);
+ ByteString bytes = tV2.toByteString();
+ assertEquals(TEST_ALL_TYPES_SERIALIZED_WITH_ILLEGAL_UTF8, bytes);
+
+ tV2.getOptionalString();
+ bytes = tV2.toByteString();
+ assertEquals(TEST_ALL_TYPES_SERIALIZED_WITH_ILLEGAL_UTF8, bytes);
+ }
+
+ public void testParseAndWrite() throws IOException {
+ UnittestProto.TestAllTypes tV2 = UnittestProto.TestAllTypes.parseFrom(
+ TEST_ALL_TYPES_SERIALIZED_WITH_ILLEGAL_UTF8);
+ byte[] sink = new byte[TEST_ALL_TYPES_SERIALIZED_WITH_ILLEGAL_UTF8.size()];
+ CodedOutputStream outputStream = CodedOutputStream.newInstance(sink);
+ tV2.writeTo(outputStream);
+ outputStream.flush();
+ assertEquals(
+ TEST_ALL_TYPES_SERIALIZED_WITH_ILLEGAL_UTF8,
+ ByteString.copyFrom(sink));
+ }
+
+ public void testCaching() {
+ String a = "a";
+ String b = "b";
+ String c = "c";
+ UnittestProto.TestAllTypes proto = UnittestProto.TestAllTypes.newBuilder()
+ .setOptionalString(a)
+ .addRepeatedString(b)
+ .addRepeatedString(c)
+ .build();
+
+ // String should be the one we passed it.
+ assertSame(a, proto.getOptionalString());
+ assertSame(b, proto.getRepeatedString(0));
+ assertSame(c, proto.getRepeatedString(1));
+
+
+ // Ensure serialization keeps strings cached.
+ proto.toByteString();
+
+ // And now the string should stay cached.
+ assertSame(a, proto.getOptionalString());
+ assertSame(b, proto.getRepeatedString(0));
+ assertSame(c, proto.getRepeatedString(1));
+ }
+
+ public void testNoStringCachingIfOnlyBytesAccessed() throws Exception {
+ UnittestProto.TestAllTypes proto =
+ UnittestProto.TestAllTypes.parseFrom(encodedTestAllTypes);
+ ByteString optional = proto.getOptionalStringBytes();
+ assertSame(optional, proto.getOptionalStringBytes());
+ assertSame(optional, proto.toBuilder().getOptionalStringBytes());
+
+ ByteString repeated0 = proto.getRepeatedStringBytes(0);
+ ByteString repeated1 = proto.getRepeatedStringBytes(1);
+ assertSame(repeated0, proto.getRepeatedStringBytes(0));
+ assertSame(repeated1, proto.getRepeatedStringBytes(1));
+ assertSame(repeated0, proto.toBuilder().getRepeatedStringBytes(0));
+ assertSame(repeated1, proto.toBuilder().getRepeatedStringBytes(1));
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java
new file mode 100644
index 0000000000..4764ca1bbc
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java
@@ -0,0 +1,125 @@
+// 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 protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.Bar;
+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;
+
+/**
+ * Test generate equal and hash methods for the lite runtime.
+ *
+ * @author pbogle@google.com Phil Bogle
+ */
+public class LiteEqualsAndHashTest extends TestCase {
+
+ public void testEquals() throws Exception {
+ // Since the generated equals and hashCode methods for lite messages are a
+ // mostly complete subset of those for regular messages, we can mostly assume
+ // that the generated methods are already thoroughly tested by the regular tests.
+
+ // This test mostly just verifies is that a proto with
+ // optimize_for = LITE_RUNTIME and java_generates_equals_and_hash_compiles
+ // correctly when linked only against the lite library.
+
+ // We do however do some basic testing to make sure that equals is actually
+ // overridden to test for value equality rather than simple object equality.
+
+ // Check that two identical objs are equal.
+ Foo foo1a = Foo.newBuilder()
+ .setValue(1)
+ .addBar(Bar.newBuilder().setName("foo1"))
+ .build();
+ Foo foo1b = Foo.newBuilder()
+ .setValue(1)
+ .addBar(Bar.newBuilder().setName("foo1"))
+ .build();
+ Foo foo2 = Foo.newBuilder()
+ .setValue(1)
+ .addBar(Bar.newBuilder().setName("foo2"))
+ .build();
+
+ // Check that equals is doing value rather than object equality.
+ assertEquals(foo1a, foo1b);
+ assertEquals(foo1a.hashCode(), foo1b.hashCode());
+
+ // Check that a diffeent object is not equal.
+ assertFalse(foo1a.equals(foo2));
+
+ // Check that two objects which have different types but the same field values are not
+ // considered to be equal.
+ Bar bar = Bar.newBuilder().setName("bar").build();
+ BarPrime barPrime = BarPrime.newBuilder().setName("bar").build();
+ assertFalse(bar.equals(barPrime));
+ }
+
+ public void testOneofEquals() throws Exception {
+ TestOneofEquals.Builder builder = TestOneofEquals.newBuilder();
+ TestOneofEquals message1 = builder.build();
+ // Set message2's name field to default value. The two messages should be different when we
+ // check with the oneof case.
+ builder.setName("");
+ TestOneofEquals message2 = builder.build();
+ assertFalse(message1.equals(message2));
+ }
+
+ public void testEqualsAndHashCodeWithUnknownFields() throws InvalidProtocolBufferException {
+ Foo fooWithOnlyValue = Foo.newBuilder()
+ .setValue(1)
+ .build();
+
+ Foo fooWithValueAndExtension = fooWithOnlyValue.toBuilder()
+ .setValue(1)
+ .setExtension(Bar.fooExt, Bar.newBuilder()
+ .setName("name")
+ .build())
+ .build();
+
+ Foo fooWithValueAndUnknownFields = Foo.parseFrom(fooWithValueAndExtension.toByteArray());
+
+ assertEqualsAndHashCodeAreFalse(fooWithOnlyValue, fooWithValueAndUnknownFields);
+ assertEqualsAndHashCodeAreFalse(fooWithValueAndExtension, fooWithValueAndUnknownFields);
+ }
+
+ private void assertEqualsAndHashCodeAreFalse(Object o1, Object o2) {
+ assertFalse(o1.equals(o2));
+ assertFalse(o1.hashCode() == o2.hashCode());
+ }
+
+ public void testRecursiveHashcode() {
+ // This tests that we don't infinite loop.
+ TestRecursiveOneof.getDefaultInstance().hashCode();
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LiteTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LiteTest.java
new file mode 100644
index 0000000000..538432f7c1
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LiteTest.java
@@ -0,0 +1,2273 @@
+// 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 static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
+
+import com.google.protobuf.UnittestImportLite.ImportEnumLite;
+import com.google.protobuf.UnittestImportPublicLite.PublicImportMessageLite;
+import com.google.protobuf.UnittestLite.ForeignEnumLite;
+import com.google.protobuf.UnittestLite.ForeignMessageLite;
+import com.google.protobuf.UnittestLite.TestAllExtensionsLite;
+import com.google.protobuf.UnittestLite.TestAllTypesLite;
+import com.google.protobuf.UnittestLite.TestAllTypesLite.NestedEnum;
+import com.google.protobuf.UnittestLite.TestAllTypesLite.NestedMessage;
+import com.google.protobuf.UnittestLite.TestAllTypesLite.OneofFieldCase;
+import com.google.protobuf.UnittestLite.TestAllTypesLite.OptionalGroup;
+import com.google.protobuf.UnittestLite.TestAllTypesLite.RepeatedGroup;
+import com.google.protobuf.UnittestLite.TestAllTypesLiteOrBuilder;
+import com.google.protobuf.UnittestLite.TestHugeFieldNumbersLite;
+import com.google.protobuf.UnittestLite.TestNestedExtensionLite;
+import protobuf_unittest.lite_equals_and_hash.LiteEqualsAndHash.Bar;
+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;
+
+/**
+ * Test lite runtime.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class LiteTest extends TestCase {
+ @Override
+ public void setUp() throws Exception {
+ // Test that nested extensions are initialized correctly even if the outer
+ // class has not been accessed directly. This was once a bug with lite
+ // messages.
+ //
+ // We put this in setUp() rather than in its own test method because we
+ // need to make sure it runs before any actual tests.
+ assertTrue(TestNestedExtensionLite.nestedExtension != null);
+ }
+
+ public void testLite() throws Exception {
+ // Since lite messages are a subset of regular messages, we can mostly
+ // assume that the functionality of lite messages is already thoroughly
+ // tested by the regular tests. All this test really verifies is that
+ // a proto with optimize_for = LITE_RUNTIME compiles correctly when
+ // linked only against the lite library. That is all tested at compile
+ // time, leaving not much to do in this method. Let's just do some random
+ // stuff to make sure the lite message is actually here and usable.
+
+ TestAllTypesLite message =
+ TestAllTypesLite.newBuilder()
+ .setOptionalInt32(123)
+ .addRepeatedString("hello")
+ .setOptionalNestedMessage(
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(7))
+ .build();
+
+ ByteString data = message.toByteString();
+
+ TestAllTypesLite message2 = TestAllTypesLite.parseFrom(data);
+
+ assertEquals(123, message2.getOptionalInt32());
+ assertEquals(1, message2.getRepeatedStringCount());
+ assertEquals("hello", message2.getRepeatedString(0));
+ assertEquals(7, message2.getOptionalNestedMessage().getBb());
+ }
+
+ public void testLiteExtensions() throws Exception {
+ // TODO(kenton): Unlike other features of the lite library, extensions are
+ // implemented completely differently from the regular library. We
+ // should probably test them more thoroughly.
+
+ TestAllExtensionsLite message =
+ TestAllExtensionsLite.newBuilder()
+ .setExtension(UnittestLite.optionalInt32ExtensionLite, 123)
+ .addExtension(UnittestLite.repeatedStringExtensionLite, "hello")
+ .setExtension(UnittestLite.optionalNestedEnumExtensionLite,
+ TestAllTypesLite.NestedEnum.BAZ)
+ .setExtension(UnittestLite.optionalNestedMessageExtensionLite,
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(7).build())
+ .build();
+
+ // Test copying a message, since coping extensions actually does use a
+ // different code path between lite and regular libraries, and as of this
+ // writing, parsing hasn't been implemented yet.
+ TestAllExtensionsLite message2 = message.toBuilder().build();
+
+ assertEquals(123, (int) message2.getExtension(
+ UnittestLite.optionalInt32ExtensionLite));
+ assertEquals(1, message2.getExtensionCount(
+ UnittestLite.repeatedStringExtensionLite));
+ assertEquals(1, message2.getExtension(
+ UnittestLite.repeatedStringExtensionLite).size());
+ assertEquals("hello", message2.getExtension(
+ UnittestLite.repeatedStringExtensionLite, 0));
+ assertEquals(TestAllTypesLite.NestedEnum.BAZ, message2.getExtension(
+ UnittestLite.optionalNestedEnumExtensionLite));
+ assertEquals(7, message2.getExtension(
+ UnittestLite.optionalNestedMessageExtensionLite).getBb());
+ }
+
+ public void testClone() {
+ TestAllTypesLite.Builder expected = TestAllTypesLite.newBuilder()
+ .setOptionalInt32(123);
+ assertEquals(
+ expected.getOptionalInt32(), expected.clone().getOptionalInt32());
+
+ TestAllExtensionsLite.Builder expected2 = TestAllExtensionsLite.newBuilder()
+ .setExtension(UnittestLite.optionalInt32ExtensionLite, 123);
+ assertEquals(
+ expected2.getExtension(UnittestLite.optionalInt32ExtensionLite),
+ expected2.clone().getExtension(UnittestLite.optionalInt32ExtensionLite));
+ }
+
+ public void testAddAll() {
+ try {
+ TestAllTypesLite.newBuilder()
+ .addAllRepeatedBytes(null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected.
+ }
+ }
+
+ public void testSanityCopyOnWrite() throws InvalidProtocolBufferException {
+ // Since builders are implemented as a thin wrapper around a message
+ // instance, we attempt to verify that we can't cause the builder to modify
+ // a produced message.
+
+ TestAllTypesLite.Builder builder = TestAllTypesLite.newBuilder();
+ TestAllTypesLite message = builder.build();
+ TestAllTypesLite messageAfterBuild;
+ builder.setOptionalBool(true);
+ assertEquals(false, message.getOptionalBool());
+ assertEquals(true, builder.getOptionalBool());
+ messageAfterBuild = builder.build();
+ assertEquals(true, messageAfterBuild.getOptionalBool());
+ assertEquals(false, message.getOptionalBool());
+ builder.clearOptionalBool();
+ assertEquals(false, builder.getOptionalBool());
+ assertEquals(true, messageAfterBuild.getOptionalBool());
+
+ message = builder.build();
+ builder.setOptionalBytes(ByteString.copyFromUtf8("hi"));
+ assertEquals(ByteString.EMPTY, message.getOptionalBytes());
+ assertEquals(ByteString.copyFromUtf8("hi"), builder.getOptionalBytes());
+ messageAfterBuild = builder.build();
+ assertEquals(
+ ByteString.copyFromUtf8("hi"), messageAfterBuild.getOptionalBytes());
+ assertEquals(ByteString.EMPTY, message.getOptionalBytes());
+ builder.clearOptionalBytes();
+ assertEquals(ByteString.EMPTY, builder.getOptionalBytes());
+ assertEquals(
+ ByteString.copyFromUtf8("hi"), messageAfterBuild.getOptionalBytes());
+
+ message = builder.build();
+ builder.setOptionalCord("hi");
+ assertEquals("", message.getOptionalCord());
+ assertEquals("hi", builder.getOptionalCord());
+ messageAfterBuild = builder.build();
+ assertEquals("hi", messageAfterBuild.getOptionalCord());
+ assertEquals("", message.getOptionalCord());
+ builder.clearOptionalCord();
+ assertEquals("", builder.getOptionalCord());
+ assertEquals("hi", messageAfterBuild.getOptionalCord());
+
+ message = builder.build();
+ builder.setOptionalCordBytes(ByteString.copyFromUtf8("no"));
+ assertEquals(ByteString.EMPTY, message.getOptionalCordBytes());
+ assertEquals(ByteString.copyFromUtf8("no"), builder.getOptionalCordBytes());
+ messageAfterBuild = builder.build();
+ assertEquals(
+ ByteString.copyFromUtf8("no"),
+ messageAfterBuild.getOptionalCordBytes());
+ assertEquals(ByteString.EMPTY, message.getOptionalCordBytes());
+ builder.clearOptionalCord();
+ assertEquals(ByteString.EMPTY, builder.getOptionalCordBytes());
+ assertEquals(
+ ByteString.copyFromUtf8("no"),
+ messageAfterBuild.getOptionalCordBytes());
+
+ message = builder.build();
+ builder.setOptionalDouble(1);
+ assertEquals(0D, message.getOptionalDouble());
+ assertEquals(1D, builder.getOptionalDouble());
+ messageAfterBuild = builder.build();
+ assertEquals(1D, messageAfterBuild.getOptionalDouble());
+ assertEquals(0D, message.getOptionalDouble());
+ builder.clearOptionalDouble();
+ assertEquals(0D, builder.getOptionalDouble());
+ assertEquals(1D, messageAfterBuild.getOptionalDouble());
+
+ message = builder.build();
+ builder.setOptionalFixed32(1);
+ assertEquals(0, message.getOptionalFixed32());
+ assertEquals(1, builder.getOptionalFixed32());
+ messageAfterBuild = builder.build();
+ assertEquals(1, messageAfterBuild.getOptionalFixed32());
+ assertEquals(0, message.getOptionalFixed32());
+ builder.clearOptionalFixed32();
+ assertEquals(0, builder.getOptionalFixed32());
+ assertEquals(1, messageAfterBuild.getOptionalFixed32());
+
+ message = builder.build();
+ builder.setOptionalFixed64(1);
+ assertEquals(0L, message.getOptionalFixed64());
+ assertEquals(1L, builder.getOptionalFixed64());
+ messageAfterBuild = builder.build();
+ assertEquals(1L, messageAfterBuild.getOptionalFixed64());
+ assertEquals(0L, message.getOptionalFixed64());
+ builder.clearOptionalFixed64();
+ assertEquals(0L, builder.getOptionalFixed64());
+ assertEquals(1L, messageAfterBuild.getOptionalFixed64());
+
+ message = builder.build();
+ builder.setOptionalFloat(1);
+ assertEquals(0F, message.getOptionalFloat());
+ assertEquals(1F, builder.getOptionalFloat());
+ messageAfterBuild = builder.build();
+ assertEquals(1F, messageAfterBuild.getOptionalFloat());
+ assertEquals(0F, message.getOptionalFloat());
+ builder.clearOptionalFloat();
+ assertEquals(0F, builder.getOptionalFloat());
+ assertEquals(1F, messageAfterBuild.getOptionalFloat());
+
+ message = builder.build();
+ builder.setOptionalForeignEnum(ForeignEnumLite.FOREIGN_LITE_BAR);
+ assertEquals(
+ ForeignEnumLite.FOREIGN_LITE_FOO, message.getOptionalForeignEnum());
+ assertEquals(
+ ForeignEnumLite.FOREIGN_LITE_BAR, builder.getOptionalForeignEnum());
+ messageAfterBuild = builder.build();
+ assertEquals(
+ ForeignEnumLite.FOREIGN_LITE_BAR,
+ messageAfterBuild.getOptionalForeignEnum());
+ assertEquals(
+ ForeignEnumLite.FOREIGN_LITE_FOO, message.getOptionalForeignEnum());
+ builder.clearOptionalForeignEnum();
+ assertEquals(
+ ForeignEnumLite.FOREIGN_LITE_FOO, builder.getOptionalForeignEnum());
+ assertEquals(
+ ForeignEnumLite.FOREIGN_LITE_BAR,
+ messageAfterBuild.getOptionalForeignEnum());
+
+ message = builder.build();
+ ForeignMessageLite foreignMessage = ForeignMessageLite.newBuilder()
+ .setC(1)
+ .build();
+ builder.setOptionalForeignMessage(foreignMessage);
+ assertEquals(
+ ForeignMessageLite.getDefaultInstance(),
+ message.getOptionalForeignMessage());
+ assertEquals(foreignMessage, builder.getOptionalForeignMessage());
+ messageAfterBuild = builder.build();
+ assertEquals(foreignMessage, messageAfterBuild.getOptionalForeignMessage());
+ assertEquals(
+ ForeignMessageLite.getDefaultInstance(),
+ message.getOptionalForeignMessage());
+ builder.clearOptionalForeignMessage();
+ assertEquals(
+ ForeignMessageLite.getDefaultInstance(),
+ builder.getOptionalForeignMessage());
+ assertEquals(foreignMessage, messageAfterBuild.getOptionalForeignMessage());
+
+ message = builder.build();
+ ForeignMessageLite.Builder foreignMessageBuilder =
+ ForeignMessageLite.newBuilder()
+ .setC(3);
+ builder.setOptionalForeignMessage(foreignMessageBuilder);
+ assertEquals(
+ ForeignMessageLite.getDefaultInstance(),
+ message.getOptionalForeignMessage());
+ assertEquals(foreignMessageBuilder.build(), builder.getOptionalForeignMessage());
+ messageAfterBuild = builder.build();
+ assertEquals(foreignMessageBuilder.build(), messageAfterBuild.getOptionalForeignMessage());
+ assertEquals(
+ ForeignMessageLite.getDefaultInstance(),
+ message.getOptionalForeignMessage());
+ builder.clearOptionalForeignMessage();
+ assertEquals(
+ ForeignMessageLite.getDefaultInstance(),
+ builder.getOptionalForeignMessage());
+ assertEquals(foreignMessageBuilder.build(), messageAfterBuild.getOptionalForeignMessage());
+
+ message = builder.build();
+ OptionalGroup optionalGroup = OptionalGroup.newBuilder()
+ .setA(1)
+ .build();
+ builder.setOptionalGroup(optionalGroup);
+ assertEquals(
+ OptionalGroup.getDefaultInstance(), message.getOptionalGroup());
+ assertEquals(optionalGroup, builder.getOptionalGroup());
+ messageAfterBuild = builder.build();
+ assertEquals(optionalGroup, messageAfterBuild.getOptionalGroup());
+ assertEquals(
+ OptionalGroup.getDefaultInstance(), message.getOptionalGroup());
+ builder.clearOptionalGroup();
+ assertEquals(
+ OptionalGroup.getDefaultInstance(), builder.getOptionalGroup());
+ assertEquals(optionalGroup, messageAfterBuild.getOptionalGroup());
+
+ message = builder.build();
+ OptionalGroup.Builder optionalGroupBuilder = OptionalGroup.newBuilder()
+ .setA(3);
+ builder.setOptionalGroup(optionalGroupBuilder);
+ assertEquals(
+ OptionalGroup.getDefaultInstance(), message.getOptionalGroup());
+ assertEquals(optionalGroupBuilder.build(), builder.getOptionalGroup());
+ messageAfterBuild = builder.build();
+ assertEquals(optionalGroupBuilder.build(), messageAfterBuild.getOptionalGroup());
+ assertEquals(
+ OptionalGroup.getDefaultInstance(), message.getOptionalGroup());
+ builder.clearOptionalGroup();
+ assertEquals(
+ OptionalGroup.getDefaultInstance(), builder.getOptionalGroup());
+ assertEquals(optionalGroupBuilder.build(), messageAfterBuild.getOptionalGroup());
+
+ message = builder.build();
+ builder.setOptionalInt32(1);
+ assertEquals(0, message.getOptionalInt32());
+ assertEquals(1, builder.getOptionalInt32());
+ messageAfterBuild = builder.build();
+ assertEquals(1, messageAfterBuild.getOptionalInt32());
+ assertEquals(0, message.getOptionalInt32());
+ builder.clearOptionalInt32();
+ assertEquals(0, builder.getOptionalInt32());
+ assertEquals(1, messageAfterBuild.getOptionalInt32());
+
+ message = builder.build();
+ builder.setOptionalInt64(1);
+ assertEquals(0L, message.getOptionalInt64());
+ assertEquals(1L, builder.getOptionalInt64());
+ messageAfterBuild = builder.build();
+ assertEquals(1L, messageAfterBuild.getOptionalInt64());
+ assertEquals(0L, message.getOptionalInt64());
+ builder.clearOptionalInt64();
+ assertEquals(0L, builder.getOptionalInt64());
+ assertEquals(1L, messageAfterBuild.getOptionalInt64());
+
+ message = builder.build();
+ NestedMessage nestedMessage = NestedMessage.newBuilder()
+ .setBb(1)
+ .build();
+ builder.setOptionalLazyMessage(nestedMessage);
+ assertEquals(
+ NestedMessage.getDefaultInstance(),
+ message.getOptionalLazyMessage());
+ assertEquals(nestedMessage, builder.getOptionalLazyMessage());
+ messageAfterBuild = builder.build();
+ assertEquals(nestedMessage, messageAfterBuild.getOptionalLazyMessage());
+ assertEquals(
+ NestedMessage.getDefaultInstance(),
+ message.getOptionalLazyMessage());
+ builder.clearOptionalLazyMessage();
+ assertEquals(
+ NestedMessage.getDefaultInstance(), builder.getOptionalLazyMessage());
+ assertEquals(nestedMessage, messageAfterBuild.getOptionalLazyMessage());
+
+ message = builder.build();
+ NestedMessage.Builder nestedMessageBuilder =
+ NestedMessage.newBuilder()
+ .setBb(3);
+ builder.setOptionalLazyMessage(nestedMessageBuilder);
+ assertEquals(
+ NestedMessage.getDefaultInstance(),
+ message.getOptionalLazyMessage());
+ assertEquals(nestedMessageBuilder.build(), builder.getOptionalLazyMessage());
+ messageAfterBuild = builder.build();
+ assertEquals(nestedMessageBuilder.build(), messageAfterBuild.getOptionalLazyMessage());
+ assertEquals(
+ NestedMessage.getDefaultInstance(),
+ message.getOptionalLazyMessage());
+ builder.clearOptionalLazyMessage();
+ assertEquals(
+ NestedMessage.getDefaultInstance(), builder.getOptionalLazyMessage());
+ assertEquals(nestedMessageBuilder.build(), messageAfterBuild.getOptionalLazyMessage());
+
+ message = builder.build();
+ builder.setOptionalSfixed32(1);
+ assertEquals(0, message.getOptionalSfixed32());
+ assertEquals(1, builder.getOptionalSfixed32());
+ messageAfterBuild = builder.build();
+ assertEquals(1, messageAfterBuild.getOptionalSfixed32());
+ assertEquals(0, message.getOptionalSfixed32());
+ builder.clearOptionalSfixed32();
+ assertEquals(0, builder.getOptionalSfixed32());
+ assertEquals(1, messageAfterBuild.getOptionalSfixed32());
+
+ message = builder.build();
+ builder.setOptionalSfixed64(1);
+ assertEquals(0L, message.getOptionalSfixed64());
+ assertEquals(1L, builder.getOptionalSfixed64());
+ messageAfterBuild = builder.build();
+ assertEquals(1L, messageAfterBuild.getOptionalSfixed64());
+ assertEquals(0L, message.getOptionalSfixed64());
+ builder.clearOptionalSfixed64();
+ assertEquals(0L, builder.getOptionalSfixed64());
+ assertEquals(1L, messageAfterBuild.getOptionalSfixed64());
+
+ message = builder.build();
+ builder.setOptionalSint32(1);
+ assertEquals(0, message.getOptionalSint32());
+ assertEquals(1, builder.getOptionalSint32());
+ messageAfterBuild = builder.build();
+ assertEquals(1, messageAfterBuild.getOptionalSint32());
+ builder.clearOptionalSint32();
+ assertEquals(0, builder.getOptionalSint32());
+ assertEquals(1, messageAfterBuild.getOptionalSint32());
+
+ message = builder.build();
+ builder.setOptionalSint64(1);
+ assertEquals(0L, message.getOptionalSint64());
+ assertEquals(1L, builder.getOptionalSint64());
+ messageAfterBuild = builder.build();
+ assertEquals(1L, messageAfterBuild.getOptionalSint64());
+ assertEquals(0L, message.getOptionalSint64());
+ builder.clearOptionalSint64();
+ assertEquals(0L, builder.getOptionalSint64());
+ assertEquals(1L, messageAfterBuild.getOptionalSint64());
+
+ message = builder.build();
+ builder.setOptionalString("hi");
+ assertEquals("", message.getOptionalString());
+ assertEquals("hi", builder.getOptionalString());
+ messageAfterBuild = builder.build();
+ assertEquals("hi", messageAfterBuild.getOptionalString());
+ assertEquals("", message.getOptionalString());
+ builder.clearOptionalString();
+ assertEquals("", builder.getOptionalString());
+ assertEquals("hi", messageAfterBuild.getOptionalString());
+
+ message = builder.build();
+ builder.setOptionalStringBytes(ByteString.copyFromUtf8("no"));
+ assertEquals(ByteString.EMPTY, message.getOptionalStringBytes());
+ assertEquals(
+ ByteString.copyFromUtf8("no"), builder.getOptionalStringBytes());
+ messageAfterBuild = builder.build();
+ assertEquals(
+ ByteString.copyFromUtf8("no"),
+ messageAfterBuild.getOptionalStringBytes());
+ assertEquals(ByteString.EMPTY, message.getOptionalStringBytes());
+ builder.clearOptionalString();
+ assertEquals(ByteString.EMPTY, builder.getOptionalStringBytes());
+ assertEquals(
+ ByteString.copyFromUtf8("no"),
+ messageAfterBuild.getOptionalStringBytes());
+
+ message = builder.build();
+ builder.setOptionalStringPiece("hi");
+ assertEquals("", message.getOptionalStringPiece());
+ assertEquals("hi", builder.getOptionalStringPiece());
+ messageAfterBuild = builder.build();
+ assertEquals("hi", messageAfterBuild.getOptionalStringPiece());
+ assertEquals("", message.getOptionalStringPiece());
+ builder.clearOptionalStringPiece();
+ assertEquals("", builder.getOptionalStringPiece());
+ assertEquals("hi", messageAfterBuild.getOptionalStringPiece());
+
+ message = builder.build();
+ builder.setOptionalStringPieceBytes(ByteString.copyFromUtf8("no"));
+ assertEquals(ByteString.EMPTY, message.getOptionalStringPieceBytes());
+ assertEquals(
+ ByteString.copyFromUtf8("no"), builder.getOptionalStringPieceBytes());
+ messageAfterBuild = builder.build();
+ assertEquals(
+ ByteString.copyFromUtf8("no"),
+ messageAfterBuild.getOptionalStringPieceBytes());
+ assertEquals(ByteString.EMPTY, message.getOptionalStringPieceBytes());
+ builder.clearOptionalStringPiece();
+ assertEquals(ByteString.EMPTY, builder.getOptionalStringPieceBytes());
+ assertEquals(
+ ByteString.copyFromUtf8("no"),
+ messageAfterBuild.getOptionalStringPieceBytes());
+
+ message = builder.build();
+ builder.setOptionalUint32(1);
+ assertEquals(0, message.getOptionalUint32());
+ assertEquals(1, builder.getOptionalUint32());
+ messageAfterBuild = builder.build();
+ assertEquals(1, messageAfterBuild.getOptionalUint32());
+ assertEquals(0, message.getOptionalUint32());
+ builder.clearOptionalUint32();
+ assertEquals(0, builder.getOptionalUint32());
+ assertEquals(1, messageAfterBuild.getOptionalUint32());
+
+ message = builder.build();
+ builder.setOptionalUint64(1);
+ assertEquals(0L, message.getOptionalUint64());
+ assertEquals(1L, builder.getOptionalUint64());
+ messageAfterBuild = builder.build();
+ assertEquals(1L, messageAfterBuild.getOptionalUint64());
+ assertEquals(0L, message.getOptionalUint64());
+ builder.clearOptionalUint64();
+ assertEquals(0L, builder.getOptionalUint64());
+ assertEquals(1L, messageAfterBuild.getOptionalUint64());
+
+ message = builder.build();
+ builder.addAllRepeatedBool(singletonList(true));
+ assertEquals(emptyList(), message.getRepeatedBoolList());
+ assertEquals(singletonList(true), builder.getRepeatedBoolList());
+ assertEquals(emptyList(), message.getRepeatedBoolList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedBool();
+ assertEquals(emptyList(), builder.getRepeatedBoolList());
+ assertEquals(singletonList(true), messageAfterBuild.getRepeatedBoolList());
+
+ message = builder.build();
+ builder.addAllRepeatedBytes(singletonList(ByteString.copyFromUtf8("hi")));
+ assertEquals(emptyList(), message.getRepeatedBytesList());
+ assertEquals(
+ singletonList(ByteString.copyFromUtf8("hi")),
+ builder.getRepeatedBytesList());
+ assertEquals(emptyList(), message.getRepeatedBytesList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedBytes();
+ assertEquals(emptyList(), builder.getRepeatedBytesList());
+ assertEquals(
+ singletonList(ByteString.copyFromUtf8("hi")),
+ messageAfterBuild.getRepeatedBytesList());
+
+ message = builder.build();
+ builder.addAllRepeatedCord(singletonList("hi"));
+ assertEquals(emptyList(), message.getRepeatedCordList());
+ assertEquals(singletonList("hi"), builder.getRepeatedCordList());
+ assertEquals(emptyList(), message.getRepeatedCordList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedCord();
+ assertEquals(emptyList(), builder.getRepeatedCordList());
+ assertEquals(singletonList("hi"), messageAfterBuild.getRepeatedCordList());
+
+ message = builder.build();
+ builder.addAllRepeatedDouble(singletonList(1D));
+ assertEquals(emptyList(), message.getRepeatedDoubleList());
+ assertEquals(singletonList(1D), builder.getRepeatedDoubleList());
+ assertEquals(emptyList(), message.getRepeatedDoubleList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedDouble();
+ assertEquals(emptyList(), builder.getRepeatedDoubleList());
+ assertEquals(singletonList(1D), messageAfterBuild.getRepeatedDoubleList());
+
+ message = builder.build();
+ builder.addAllRepeatedFixed32(singletonList(1));
+ assertEquals(emptyList(), message.getRepeatedFixed32List());
+ assertEquals(singletonList(1), builder.getRepeatedFixed32List());
+ assertEquals(emptyList(), message.getRepeatedFixed32List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedFixed32();
+ assertEquals(emptyList(), builder.getRepeatedFixed32List());
+ assertEquals(singletonList(1), messageAfterBuild.getRepeatedFixed32List());
+
+ message = builder.build();
+ builder.addAllRepeatedFixed64(singletonList(1L));
+ assertEquals(emptyList(), message.getRepeatedFixed64List());
+ assertEquals(singletonList(1L), builder.getRepeatedFixed64List());
+ assertEquals(emptyList(), message.getRepeatedFixed64List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedFixed64();
+ assertEquals(emptyList(), builder.getRepeatedFixed64List());
+ assertEquals(singletonList(1L), messageAfterBuild.getRepeatedFixed64List());
+
+ message = builder.build();
+ builder.addAllRepeatedFloat(singletonList(1F));
+ assertEquals(emptyList(), message.getRepeatedFloatList());
+ assertEquals(singletonList(1F), builder.getRepeatedFloatList());
+ assertEquals(emptyList(), message.getRepeatedFloatList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedFloat();
+ assertEquals(emptyList(), builder.getRepeatedFloatList());
+ assertEquals(singletonList(1F), messageAfterBuild.getRepeatedFloatList());
+
+ message = builder.build();
+ builder.addAllRepeatedForeignEnum(
+ singletonList(ForeignEnumLite.FOREIGN_LITE_BAR));
+ assertEquals(emptyList(), message.getRepeatedForeignEnumList());
+ assertEquals(
+ singletonList(ForeignEnumLite.FOREIGN_LITE_BAR),
+ builder.getRepeatedForeignEnumList());
+ assertEquals(emptyList(), message.getRepeatedForeignEnumList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedForeignEnum();
+ assertEquals(emptyList(), builder.getRepeatedForeignEnumList());
+ assertEquals(
+ singletonList(ForeignEnumLite.FOREIGN_LITE_BAR),
+ messageAfterBuild.getRepeatedForeignEnumList());
+
+ message = builder.build();
+ builder.addAllRepeatedForeignMessage(singletonList(foreignMessage));
+ assertEquals(emptyList(), message.getRepeatedForeignMessageList());
+ assertEquals(
+ singletonList(foreignMessage), builder.getRepeatedForeignMessageList());
+ assertEquals(emptyList(), message.getRepeatedForeignMessageList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedForeignMessage();
+ assertEquals(emptyList(), builder.getRepeatedForeignMessageList());
+ assertEquals(
+ singletonList(foreignMessage),
+ messageAfterBuild.getRepeatedForeignMessageList());
+
+ message = builder.build();
+ builder.addAllRepeatedGroup(
+ singletonList(RepeatedGroup.getDefaultInstance()));
+ assertEquals(emptyList(), message.getRepeatedGroupList());
+ assertEquals(
+ singletonList(RepeatedGroup.getDefaultInstance()),
+ builder.getRepeatedGroupList());
+ assertEquals(emptyList(), message.getRepeatedGroupList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedGroup();
+ assertEquals(emptyList(), builder.getRepeatedGroupList());
+ assertEquals(
+ singletonList(RepeatedGroup.getDefaultInstance()),
+ messageAfterBuild.getRepeatedGroupList());
+
+ message = builder.build();
+ builder.addAllRepeatedInt32(singletonList(1));
+ assertEquals(emptyList(), message.getRepeatedInt32List());
+ assertEquals(singletonList(1), builder.getRepeatedInt32List());
+ assertEquals(emptyList(), message.getRepeatedInt32List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedInt32();
+ assertEquals(emptyList(), builder.getRepeatedInt32List());
+ assertEquals(singletonList(1), messageAfterBuild.getRepeatedInt32List());
+
+ message = builder.build();
+ builder.addAllRepeatedInt64(singletonList(1L));
+ assertEquals(emptyList(), message.getRepeatedInt64List());
+ assertEquals(singletonList(1L), builder.getRepeatedInt64List());
+ assertEquals(emptyList(), message.getRepeatedInt64List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedInt64();
+ assertEquals(emptyList(), builder.getRepeatedInt64List());
+ assertEquals(singletonList(1L), messageAfterBuild.getRepeatedInt64List());
+
+ message = builder.build();
+ builder.addAllRepeatedLazyMessage(singletonList(nestedMessage));
+ assertEquals(emptyList(), message.getRepeatedLazyMessageList());
+ assertEquals(
+ singletonList(nestedMessage), builder.getRepeatedLazyMessageList());
+ assertEquals(emptyList(), message.getRepeatedLazyMessageList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedLazyMessage();
+ assertEquals(emptyList(), builder.getRepeatedLazyMessageList());
+ assertEquals(
+ singletonList(nestedMessage),
+ messageAfterBuild.getRepeatedLazyMessageList());
+
+ message = builder.build();
+ builder.addAllRepeatedSfixed32(singletonList(1));
+ assertEquals(emptyList(), message.getRepeatedSfixed32List());
+ assertEquals(singletonList(1), builder.getRepeatedSfixed32List());
+ assertEquals(emptyList(), message.getRepeatedSfixed32List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedSfixed32();
+ assertEquals(emptyList(), builder.getRepeatedSfixed32List());
+ assertEquals(singletonList(1), messageAfterBuild.getRepeatedSfixed32List());
+
+ message = builder.build();
+ builder.addAllRepeatedSfixed64(singletonList(1L));
+ assertEquals(emptyList(), message.getRepeatedSfixed64List());
+ assertEquals(singletonList(1L), builder.getRepeatedSfixed64List());
+ assertEquals(emptyList(), message.getRepeatedSfixed64List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedSfixed64();
+ assertEquals(emptyList(), builder.getRepeatedSfixed64List());
+ assertEquals(
+ singletonList(1L), messageAfterBuild.getRepeatedSfixed64List());
+
+ message = builder.build();
+ builder.addAllRepeatedSint32(singletonList(1));
+ assertEquals(emptyList(), message.getRepeatedSint32List());
+ assertEquals(singletonList(1), builder.getRepeatedSint32List());
+ assertEquals(emptyList(), message.getRepeatedSint32List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedSint32();
+ assertEquals(emptyList(), builder.getRepeatedSint32List());
+ assertEquals(singletonList(1), messageAfterBuild.getRepeatedSint32List());
+
+ message = builder.build();
+ builder.addAllRepeatedSint64(singletonList(1L));
+ assertEquals(emptyList(), message.getRepeatedSint64List());
+ assertEquals(singletonList(1L), builder.getRepeatedSint64List());
+ assertEquals(emptyList(), message.getRepeatedSint64List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedSint64();
+ assertEquals(emptyList(), builder.getRepeatedSint64List());
+ assertEquals(singletonList(1L), messageAfterBuild.getRepeatedSint64List());
+
+ message = builder.build();
+ builder.addAllRepeatedString(singletonList("hi"));
+ assertEquals(emptyList(), message.getRepeatedStringList());
+ assertEquals(singletonList("hi"), builder.getRepeatedStringList());
+ assertEquals(emptyList(), message.getRepeatedStringList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedString();
+ assertEquals(emptyList(), builder.getRepeatedStringList());
+ assertEquals(
+ singletonList("hi"), messageAfterBuild.getRepeatedStringList());
+
+ message = builder.build();
+ builder.addAllRepeatedStringPiece(singletonList("hi"));
+ assertEquals(emptyList(), message.getRepeatedStringPieceList());
+ assertEquals(singletonList("hi"), builder.getRepeatedStringPieceList());
+ assertEquals(emptyList(), message.getRepeatedStringPieceList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedStringPiece();
+ assertEquals(emptyList(), builder.getRepeatedStringPieceList());
+ assertEquals(
+ singletonList("hi"), messageAfterBuild.getRepeatedStringPieceList());
+
+ message = builder.build();
+ builder.addAllRepeatedUint32(singletonList(1));
+ assertEquals(emptyList(), message.getRepeatedUint32List());
+ assertEquals(singletonList(1), builder.getRepeatedUint32List());
+ assertEquals(emptyList(), message.getRepeatedUint32List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedUint32();
+ assertEquals(emptyList(), builder.getRepeatedUint32List());
+ assertEquals(singletonList(1), messageAfterBuild.getRepeatedUint32List());
+
+ message = builder.build();
+ builder.addAllRepeatedUint64(singletonList(1L));
+ assertEquals(emptyList(), message.getRepeatedUint64List());
+ assertEquals(singletonList(1L), builder.getRepeatedUint64List());
+ assertEquals(emptyList(), message.getRepeatedUint64List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedUint64();
+ assertEquals(emptyList(), builder.getRepeatedUint64List());
+ assertEquals(singletonList(1L), messageAfterBuild.getRepeatedUint64List());
+
+ message = builder.build();
+ builder.addRepeatedBool(true);
+ assertEquals(emptyList(), message.getRepeatedBoolList());
+ assertEquals(singletonList(true), builder.getRepeatedBoolList());
+ assertEquals(emptyList(), message.getRepeatedBoolList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedBool();
+ assertEquals(emptyList(), builder.getRepeatedBoolList());
+ assertEquals(singletonList(true), messageAfterBuild.getRepeatedBoolList());
+
+ message = builder.build();
+ builder.addRepeatedBytes(ByteString.copyFromUtf8("hi"));
+ assertEquals(emptyList(), message.getRepeatedBytesList());
+ assertEquals(
+ singletonList(ByteString.copyFromUtf8("hi")),
+ builder.getRepeatedBytesList());
+ assertEquals(emptyList(), message.getRepeatedBytesList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedBytes();
+ assertEquals(emptyList(), builder.getRepeatedBytesList());
+ assertEquals(
+ singletonList(ByteString.copyFromUtf8("hi")),
+ messageAfterBuild.getRepeatedBytesList());
+
+ message = builder.build();
+ builder.addRepeatedCord("hi");
+ assertEquals(emptyList(), message.getRepeatedCordList());
+ assertEquals(singletonList("hi"), builder.getRepeatedCordList());
+ assertEquals(emptyList(), message.getRepeatedCordList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedCord();
+ assertEquals(emptyList(), builder.getRepeatedCordList());
+ assertEquals(singletonList("hi"), messageAfterBuild.getRepeatedCordList());
+
+ message = builder.build();
+ builder.addRepeatedDouble(1D);
+ assertEquals(emptyList(), message.getRepeatedDoubleList());
+ assertEquals(singletonList(1D), builder.getRepeatedDoubleList());
+ assertEquals(emptyList(), message.getRepeatedDoubleList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedDouble();
+ assertEquals(emptyList(), builder.getRepeatedDoubleList());
+ assertEquals(singletonList(1D), messageAfterBuild.getRepeatedDoubleList());
+
+ message = builder.build();
+ builder.addRepeatedFixed32(1);
+ assertEquals(emptyList(), message.getRepeatedFixed32List());
+ assertEquals(singletonList(1), builder.getRepeatedFixed32List());
+ assertEquals(emptyList(), message.getRepeatedFixed32List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedFixed32();
+ assertEquals(emptyList(), builder.getRepeatedFixed32List());
+ assertEquals(singletonList(1), messageAfterBuild.getRepeatedFixed32List());
+
+ message = builder.build();
+ builder.addRepeatedFixed64(1L);
+ assertEquals(emptyList(), message.getRepeatedFixed64List());
+ assertEquals(singletonList(1L), builder.getRepeatedFixed64List());
+ assertEquals(emptyList(), message.getRepeatedFixed64List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedFixed64();
+ assertEquals(emptyList(), builder.getRepeatedFixed64List());
+ assertEquals(singletonList(1L), messageAfterBuild.getRepeatedFixed64List());
+
+ message = builder.build();
+ builder.addRepeatedFloat(1F);
+ assertEquals(emptyList(), message.getRepeatedFloatList());
+ assertEquals(singletonList(1F), builder.getRepeatedFloatList());
+ assertEquals(emptyList(), message.getRepeatedFloatList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedFloat();
+ assertEquals(emptyList(), builder.getRepeatedFloatList());
+ assertEquals(singletonList(1F), messageAfterBuild.getRepeatedFloatList());
+
+ message = builder.build();
+ builder.addRepeatedForeignEnum(ForeignEnumLite.FOREIGN_LITE_BAR);
+ assertEquals(emptyList(), message.getRepeatedForeignEnumList());
+ assertEquals(
+ singletonList(ForeignEnumLite.FOREIGN_LITE_BAR),
+ builder.getRepeatedForeignEnumList());
+ assertEquals(emptyList(), message.getRepeatedForeignEnumList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedForeignEnum();
+ assertEquals(emptyList(), builder.getRepeatedForeignEnumList());
+ assertEquals(
+ singletonList(ForeignEnumLite.FOREIGN_LITE_BAR),
+ messageAfterBuild.getRepeatedForeignEnumList());
+
+ message = builder.build();
+ builder.addRepeatedForeignMessage(foreignMessage);
+ assertEquals(emptyList(), message.getRepeatedForeignMessageList());
+ assertEquals(
+ singletonList(foreignMessage), builder.getRepeatedForeignMessageList());
+ assertEquals(emptyList(), message.getRepeatedForeignMessageList());
+ messageAfterBuild = builder.build();
+ builder.removeRepeatedForeignMessage(0);
+ assertEquals(emptyList(), builder.getRepeatedForeignMessageList());
+ assertEquals(
+ singletonList(foreignMessage),
+ messageAfterBuild.getRepeatedForeignMessageList());
+
+ message = builder.build();
+ builder.addRepeatedGroup(RepeatedGroup.getDefaultInstance());
+ assertEquals(emptyList(), message.getRepeatedGroupList());
+ assertEquals(
+ singletonList(RepeatedGroup.getDefaultInstance()),
+ builder.getRepeatedGroupList());
+ assertEquals(emptyList(), message.getRepeatedGroupList());
+ messageAfterBuild = builder.build();
+ builder.removeRepeatedGroup(0);
+ assertEquals(emptyList(), builder.getRepeatedGroupList());
+ assertEquals(
+ singletonList(RepeatedGroup.getDefaultInstance()),
+ messageAfterBuild.getRepeatedGroupList());
+
+ message = builder.build();
+ builder.addRepeatedInt32(1);
+ assertEquals(emptyList(), message.getRepeatedInt32List());
+ assertEquals(singletonList(1), builder.getRepeatedInt32List());
+ assertEquals(emptyList(), message.getRepeatedInt32List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedInt32();
+ assertEquals(emptyList(), builder.getRepeatedInt32List());
+ assertEquals(singletonList(1), messageAfterBuild.getRepeatedInt32List());
+
+ message = builder.build();
+ builder.addRepeatedInt64(1L);
+ assertEquals(emptyList(), message.getRepeatedInt64List());
+ assertEquals(singletonList(1L), builder.getRepeatedInt64List());
+ assertEquals(emptyList(), message.getRepeatedInt64List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedInt64();
+ assertEquals(emptyList(), builder.getRepeatedInt64List());
+ assertEquals(singletonList(1L), messageAfterBuild.getRepeatedInt64List());
+
+ message = builder.build();
+ builder.addRepeatedLazyMessage(nestedMessage);
+ assertEquals(emptyList(), message.getRepeatedLazyMessageList());
+ assertEquals(
+ singletonList(nestedMessage), builder.getRepeatedLazyMessageList());
+ assertEquals(emptyList(), message.getRepeatedLazyMessageList());
+ messageAfterBuild = builder.build();
+ builder.removeRepeatedLazyMessage(0);
+ assertEquals(emptyList(), builder.getRepeatedLazyMessageList());
+ assertEquals(
+ singletonList(nestedMessage),
+ messageAfterBuild.getRepeatedLazyMessageList());
+
+ message = builder.build();
+ builder.addRepeatedSfixed32(1);
+ assertEquals(emptyList(), message.getRepeatedSfixed32List());
+ assertEquals(singletonList(1), builder.getRepeatedSfixed32List());
+ assertEquals(emptyList(), message.getRepeatedSfixed32List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedSfixed32();
+ assertEquals(emptyList(), builder.getRepeatedSfixed32List());
+ assertEquals(singletonList(1), messageAfterBuild.getRepeatedSfixed32List());
+
+ message = builder.build();
+ builder.addRepeatedSfixed64(1L);
+ assertEquals(emptyList(), message.getRepeatedSfixed64List());
+ assertEquals(singletonList(1L), builder.getRepeatedSfixed64List());
+ assertEquals(emptyList(), message.getRepeatedSfixed64List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedSfixed64();
+ assertEquals(emptyList(), builder.getRepeatedSfixed64List());
+ assertEquals(
+ singletonList(1L), messageAfterBuild.getRepeatedSfixed64List());
+
+ message = builder.build();
+ builder.addRepeatedSint32(1);
+ assertEquals(emptyList(), message.getRepeatedSint32List());
+ assertEquals(singletonList(1), builder.getRepeatedSint32List());
+ assertEquals(emptyList(), message.getRepeatedSint32List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedSint32();
+ assertEquals(emptyList(), builder.getRepeatedSint32List());
+ assertEquals(singletonList(1), messageAfterBuild.getRepeatedSint32List());
+
+ message = builder.build();
+ builder.addRepeatedSint64(1L);
+ assertEquals(emptyList(), message.getRepeatedSint64List());
+ assertEquals(singletonList(1L), builder.getRepeatedSint64List());
+ assertEquals(emptyList(), message.getRepeatedSint64List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedSint64();
+ assertEquals(emptyList(), builder.getRepeatedSint64List());
+ assertEquals(singletonList(1L), messageAfterBuild.getRepeatedSint64List());
+
+ message = builder.build();
+ builder.addRepeatedString("hi");
+ assertEquals(emptyList(), message.getRepeatedStringList());
+ assertEquals(singletonList("hi"), builder.getRepeatedStringList());
+ assertEquals(emptyList(), message.getRepeatedStringList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedString();
+ assertEquals(emptyList(), builder.getRepeatedStringList());
+ assertEquals(
+ singletonList("hi"), messageAfterBuild.getRepeatedStringList());
+
+ message = builder.build();
+ builder.addRepeatedStringPiece("hi");
+ assertEquals(emptyList(), message.getRepeatedStringPieceList());
+ assertEquals(singletonList("hi"), builder.getRepeatedStringPieceList());
+ assertEquals(emptyList(), message.getRepeatedStringPieceList());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedStringPiece();
+ assertEquals(emptyList(), builder.getRepeatedStringPieceList());
+ assertEquals(
+ singletonList("hi"), messageAfterBuild.getRepeatedStringPieceList());
+
+ message = builder.build();
+ builder.addRepeatedUint32(1);
+ assertEquals(emptyList(), message.getRepeatedUint32List());
+ assertEquals(singletonList(1), builder.getRepeatedUint32List());
+ assertEquals(emptyList(), message.getRepeatedUint32List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedUint32();
+ assertEquals(emptyList(), builder.getRepeatedUint32List());
+ assertEquals(singletonList(1), messageAfterBuild.getRepeatedUint32List());
+
+ message = builder.build();
+ builder.addRepeatedUint64(1L);
+ assertEquals(emptyList(), message.getRepeatedUint64List());
+ assertEquals(singletonList(1L), builder.getRepeatedUint64List());
+ assertEquals(emptyList(), message.getRepeatedUint64List());
+ messageAfterBuild = builder.build();
+ builder.clearRepeatedUint64();
+ assertEquals(emptyList(), builder.getRepeatedUint64List());
+ assertEquals(singletonList(1L), messageAfterBuild.getRepeatedUint64List());
+
+ message = builder.build();
+ builder.addRepeatedBool(true);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedBoolCount());
+ builder.setRepeatedBool(0, false);
+ assertEquals(true, messageAfterBuild.getRepeatedBool(0));
+ assertEquals(false, builder.getRepeatedBool(0));
+ builder.clearRepeatedBool();
+
+ message = builder.build();
+ builder.addRepeatedBytes(ByteString.copyFromUtf8("hi"));
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedBytesCount());
+ builder.setRepeatedBytes(0, ByteString.EMPTY);
+ assertEquals(
+ ByteString.copyFromUtf8("hi"), messageAfterBuild.getRepeatedBytes(0));
+ assertEquals(ByteString.EMPTY, builder.getRepeatedBytes(0));
+ builder.clearRepeatedBytes();
+
+ message = builder.build();
+ builder.addRepeatedCord("hi");
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedCordCount());
+ builder.setRepeatedCord(0, "");
+ assertEquals("hi", messageAfterBuild.getRepeatedCord(0));
+ assertEquals("", builder.getRepeatedCord(0));
+ builder.clearRepeatedCord();
+ message = builder.build();
+
+ builder.addRepeatedCordBytes(ByteString.copyFromUtf8("hi"));
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedCordCount());
+ builder.setRepeatedCord(0, "");
+ assertEquals(
+ ByteString.copyFromUtf8("hi"), messageAfterBuild.getRepeatedCordBytes(0));
+ assertEquals(ByteString.EMPTY, builder.getRepeatedCordBytes(0));
+ builder.clearRepeatedCord();
+
+ message = builder.build();
+ builder.addRepeatedDouble(1D);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedDoubleCount());
+ builder.setRepeatedDouble(0, 0D);
+ assertEquals(1D, messageAfterBuild.getRepeatedDouble(0));
+ assertEquals(0D, builder.getRepeatedDouble(0));
+ builder.clearRepeatedDouble();
+
+ message = builder.build();
+ builder.addRepeatedFixed32(1);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedFixed32Count());
+ builder.setRepeatedFixed32(0, 0);
+ assertEquals(1, messageAfterBuild.getRepeatedFixed32(0));
+ assertEquals(0, builder.getRepeatedFixed32(0));
+ builder.clearRepeatedFixed32();
+
+ message = builder.build();
+ builder.addRepeatedFixed64(1L);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedFixed64Count());
+ builder.setRepeatedFixed64(0, 0L);
+ assertEquals(1L, messageAfterBuild.getRepeatedFixed64(0));
+ assertEquals(0L, builder.getRepeatedFixed64(0));
+ builder.clearRepeatedFixed64();
+
+ message = builder.build();
+ builder.addRepeatedFloat(1F);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedFloatCount());
+ builder.setRepeatedFloat(0, 0F);
+ assertEquals(1F, messageAfterBuild.getRepeatedFloat(0));
+ assertEquals(0F, builder.getRepeatedFloat(0));
+ builder.clearRepeatedFloat();
+
+ message = builder.build();
+ builder.addRepeatedForeignEnum(ForeignEnumLite.FOREIGN_LITE_BAR);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedForeignEnumCount());
+ builder.setRepeatedForeignEnum(0, ForeignEnumLite.FOREIGN_LITE_FOO);
+ assertEquals(
+ ForeignEnumLite.FOREIGN_LITE_BAR,
+ messageAfterBuild.getRepeatedForeignEnum(0));
+ assertEquals(
+ ForeignEnumLite.FOREIGN_LITE_FOO, builder.getRepeatedForeignEnum(0));
+ builder.clearRepeatedForeignEnum();
+
+ message = builder.build();
+ builder.addRepeatedForeignMessage(foreignMessage);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedForeignMessageCount());
+ builder.setRepeatedForeignMessage(
+ 0, ForeignMessageLite.getDefaultInstance());
+ assertEquals(
+ foreignMessage, messageAfterBuild.getRepeatedForeignMessage(0));
+ assertEquals(
+ ForeignMessageLite.getDefaultInstance(),
+ builder.getRepeatedForeignMessage(0));
+ builder.clearRepeatedForeignMessage();
+
+ message = builder.build();
+ builder.addRepeatedForeignMessage(foreignMessageBuilder);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedForeignMessageCount());
+ builder.setRepeatedForeignMessage(
+ 0, ForeignMessageLite.getDefaultInstance());
+ assertEquals(foreignMessageBuilder.build(), messageAfterBuild.getRepeatedForeignMessage(0));
+ assertEquals(
+ ForeignMessageLite.getDefaultInstance(),
+ builder.getRepeatedForeignMessage(0));
+ builder.clearRepeatedForeignMessage();
+
+ message = builder.build();
+ builder.addRepeatedForeignMessage(0, foreignMessage);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedForeignMessageCount());
+ builder.setRepeatedForeignMessage(0, foreignMessageBuilder);
+ assertEquals(
+ foreignMessage, messageAfterBuild.getRepeatedForeignMessage(0));
+ assertEquals(foreignMessageBuilder.build(), builder.getRepeatedForeignMessage(0));
+ builder.clearRepeatedForeignMessage();
+
+ message = builder.build();
+ RepeatedGroup repeatedGroup = RepeatedGroup.newBuilder()
+ .setA(1)
+ .build();
+ builder.addRepeatedGroup(repeatedGroup);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedGroupCount());
+ builder.setRepeatedGroup(0, RepeatedGroup.getDefaultInstance());
+ assertEquals(repeatedGroup, messageAfterBuild.getRepeatedGroup(0));
+ assertEquals(
+ RepeatedGroup.getDefaultInstance(), builder.getRepeatedGroup(0));
+ builder.clearRepeatedGroup();
+
+ message = builder.build();
+ builder.addRepeatedGroup(0, repeatedGroup);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedGroupCount());
+ builder.setRepeatedGroup(0, RepeatedGroup.getDefaultInstance());
+ assertEquals(repeatedGroup, messageAfterBuild.getRepeatedGroup(0));
+ assertEquals(
+ RepeatedGroup.getDefaultInstance(), builder.getRepeatedGroup(0));
+ builder.clearRepeatedGroup();
+
+ message = builder.build();
+ RepeatedGroup.Builder repeatedGroupBuilder = RepeatedGroup.newBuilder()
+ .setA(3);
+ builder.addRepeatedGroup(repeatedGroupBuilder);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedGroupCount());
+ builder.setRepeatedGroup(0, RepeatedGroup.getDefaultInstance());
+ assertEquals(repeatedGroupBuilder.build(), messageAfterBuild.getRepeatedGroup(0));
+ assertEquals(
+ RepeatedGroup.getDefaultInstance(), builder.getRepeatedGroup(0));
+ builder.clearRepeatedGroup();
+
+ message = builder.build();
+ builder.addRepeatedGroup(0, repeatedGroupBuilder);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedGroupCount());
+ builder.setRepeatedGroup(0, RepeatedGroup.getDefaultInstance());
+ assertEquals(repeatedGroupBuilder.build(), messageAfterBuild.getRepeatedGroup(0));
+ assertEquals(
+ RepeatedGroup.getDefaultInstance(), builder.getRepeatedGroup(0));
+ builder.clearRepeatedGroup();
+
+ message = builder.build();
+ builder.addRepeatedInt32(1);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedInt32Count());
+ builder.setRepeatedInt32(0, 0);
+ assertEquals(1, messageAfterBuild.getRepeatedInt32(0));
+ assertEquals(0, builder.getRepeatedInt32(0));
+ builder.clearRepeatedInt32();
+
+ message = builder.build();
+ builder.addRepeatedInt64(1L);
+ messageAfterBuild = builder.build();
+ assertEquals(0L, message.getRepeatedInt64Count());
+ builder.setRepeatedInt64(0, 0L);
+ assertEquals(1L, messageAfterBuild.getRepeatedInt64(0));
+ assertEquals(0L, builder.getRepeatedInt64(0));
+ builder.clearRepeatedInt64();
+
+ message = builder.build();
+ builder.addRepeatedLazyMessage(nestedMessage);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedLazyMessageCount());
+ builder.setRepeatedLazyMessage(0, NestedMessage.getDefaultInstance());
+ assertEquals(nestedMessage, messageAfterBuild.getRepeatedLazyMessage(0));
+ assertEquals(
+ NestedMessage.getDefaultInstance(), builder.getRepeatedLazyMessage(0));
+ builder.clearRepeatedLazyMessage();
+
+ message = builder.build();
+ builder.addRepeatedLazyMessage(0, nestedMessage);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedLazyMessageCount());
+ builder.setRepeatedLazyMessage(0, NestedMessage.getDefaultInstance());
+ assertEquals(nestedMessage, messageAfterBuild.getRepeatedLazyMessage(0));
+ assertEquals(
+ NestedMessage.getDefaultInstance(), builder.getRepeatedLazyMessage(0));
+ builder.clearRepeatedLazyMessage();
+
+ message = builder.build();
+ builder.addRepeatedLazyMessage(nestedMessageBuilder);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedLazyMessageCount());
+ builder.setRepeatedLazyMessage(0, NestedMessage.getDefaultInstance());
+ assertEquals(nestedMessageBuilder.build(), messageAfterBuild.getRepeatedLazyMessage(0));
+ assertEquals(
+ NestedMessage.getDefaultInstance(), builder.getRepeatedLazyMessage(0));
+ builder.clearRepeatedLazyMessage();
+
+ message = builder.build();
+ builder.addRepeatedLazyMessage(0, nestedMessageBuilder);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedLazyMessageCount());
+ builder.setRepeatedLazyMessage(0, NestedMessage.getDefaultInstance());
+ assertEquals(nestedMessageBuilder.build(), messageAfterBuild.getRepeatedLazyMessage(0));
+ assertEquals(
+ NestedMessage.getDefaultInstance(), builder.getRepeatedLazyMessage(0));
+ builder.clearRepeatedLazyMessage();
+
+ message = builder.build();
+ builder.addRepeatedSfixed32(1);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedSfixed32Count());
+ builder.setRepeatedSfixed32(0, 0);
+ assertEquals(1, messageAfterBuild.getRepeatedSfixed32(0));
+ assertEquals(0, builder.getRepeatedSfixed32(0));
+ builder.clearRepeatedSfixed32();
+
+ message = builder.build();
+ builder.addRepeatedSfixed64(1L);
+ messageAfterBuild = builder.build();
+ assertEquals(0L, message.getRepeatedSfixed64Count());
+ builder.setRepeatedSfixed64(0, 0L);
+ assertEquals(1L, messageAfterBuild.getRepeatedSfixed64(0));
+ assertEquals(0L, builder.getRepeatedSfixed64(0));
+ builder.clearRepeatedSfixed64();
+
+ message = builder.build();
+ builder.addRepeatedSint32(1);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedSint32Count());
+ builder.setRepeatedSint32(0, 0);
+ assertEquals(1, messageAfterBuild.getRepeatedSint32(0));
+ assertEquals(0, builder.getRepeatedSint32(0));
+ builder.clearRepeatedSint32();
+
+ message = builder.build();
+ builder.addRepeatedSint64(1L);
+ messageAfterBuild = builder.build();
+ assertEquals(0L, message.getRepeatedSint64Count());
+ builder.setRepeatedSint64(0, 0L);
+ assertEquals(1L, messageAfterBuild.getRepeatedSint64(0));
+ assertEquals(0L, builder.getRepeatedSint64(0));
+ builder.clearRepeatedSint64();
+
+ message = builder.build();
+ builder.addRepeatedString("hi");
+ messageAfterBuild = builder.build();
+ assertEquals(0L, message.getRepeatedStringCount());
+ builder.setRepeatedString(0, "");
+ assertEquals("hi", messageAfterBuild.getRepeatedString(0));
+ assertEquals("", builder.getRepeatedString(0));
+ builder.clearRepeatedString();
+
+ message = builder.build();
+ builder.addRepeatedStringBytes(ByteString.copyFromUtf8("hi"));
+ messageAfterBuild = builder.build();
+ assertEquals(0L, message.getRepeatedStringCount());
+ builder.setRepeatedString(0, "");
+ assertEquals(
+ ByteString.copyFromUtf8("hi"),
+ messageAfterBuild.getRepeatedStringBytes(0));
+ assertEquals(ByteString.EMPTY, builder.getRepeatedStringBytes(0));
+ builder.clearRepeatedString();
+
+ message = builder.build();
+ builder.addRepeatedStringPiece("hi");
+ messageAfterBuild = builder.build();
+ assertEquals(0L, message.getRepeatedStringPieceCount());
+ builder.setRepeatedStringPiece(0, "");
+ assertEquals("hi", messageAfterBuild.getRepeatedStringPiece(0));
+ assertEquals("", builder.getRepeatedStringPiece(0));
+ builder.clearRepeatedStringPiece();
+
+ message = builder.build();
+ builder.addRepeatedStringPieceBytes(ByteString.copyFromUtf8("hi"));
+ messageAfterBuild = builder.build();
+ assertEquals(0L, message.getRepeatedStringPieceCount());
+ builder.setRepeatedStringPiece(0, "");
+ assertEquals(
+ ByteString.copyFromUtf8("hi"),
+ messageAfterBuild.getRepeatedStringPieceBytes(0));
+ assertEquals(ByteString.EMPTY, builder.getRepeatedStringPieceBytes(0));
+ builder.clearRepeatedStringPiece();
+
+ message = builder.build();
+ builder.addRepeatedUint32(1);
+ messageAfterBuild = builder.build();
+ assertEquals(0, message.getRepeatedUint32Count());
+ builder.setRepeatedUint32(0, 0);
+ assertEquals(1, messageAfterBuild.getRepeatedUint32(0));
+ assertEquals(0, builder.getRepeatedUint32(0));
+ builder.clearRepeatedUint32();
+
+ message = builder.build();
+ builder.addRepeatedUint64(1L);
+ messageAfterBuild = builder.build();
+ assertEquals(0L, message.getRepeatedUint64Count());
+ builder.setRepeatedUint64(0, 0L);
+ assertEquals(1L, messageAfterBuild.getRepeatedUint64(0));
+ assertEquals(0L, builder.getRepeatedUint64(0));
+ builder.clearRepeatedUint64();
+
+ message = builder.build();
+ assertEquals(0, message.getSerializedSize());
+ builder.mergeFrom(TestAllTypesLite.newBuilder()
+ .setOptionalBool(true)
+ .build());
+ assertEquals(0, message.getSerializedSize());
+ assertEquals(true, builder.build().getOptionalBool());
+ builder.clearOptionalBool();
+
+ message = builder.build();
+ assertEquals(0, message.getSerializedSize());
+ builder.mergeFrom(TestAllTypesLite.newBuilder()
+ .setOptionalBool(true)
+ .build());
+ assertEquals(0, message.getSerializedSize());
+ assertEquals(true, builder.build().getOptionalBool());
+ builder.clear();
+ assertEquals(0, builder.build().getSerializedSize());
+
+ message = builder.build();
+ assertEquals(0, message.getSerializedSize());
+ builder.mergeOptionalForeignMessage(foreignMessage);
+ assertEquals(0, message.getSerializedSize());
+ assertEquals(
+ foreignMessage.getC(),
+ builder.build().getOptionalForeignMessage().getC());
+ builder.clearOptionalForeignMessage();
+
+ message = builder.build();
+ assertEquals(0, message.getSerializedSize());
+ builder.mergeOptionalLazyMessage(nestedMessage);
+ assertEquals(0, message.getSerializedSize());
+ assertEquals(
+ nestedMessage.getBb(),
+ builder.build().getOptionalLazyMessage().getBb());
+ builder.clearOptionalLazyMessage();
+
+ message = builder.build();
+ builder.setOneofString("hi");
+ assertEquals(
+ OneofFieldCase.ONEOFFIELD_NOT_SET, message.getOneofFieldCase());
+ assertEquals(OneofFieldCase.ONEOF_STRING, builder.getOneofFieldCase());
+ assertEquals("hi", builder.getOneofString());
+ messageAfterBuild = builder.build();
+ assertEquals(
+ OneofFieldCase.ONEOF_STRING, messageAfterBuild.getOneofFieldCase());
+ assertEquals("hi", messageAfterBuild.getOneofString());
+ builder.setOneofUint32(1);
+ assertEquals(
+ OneofFieldCase.ONEOF_STRING, messageAfterBuild.getOneofFieldCase());
+ assertEquals("hi", messageAfterBuild.getOneofString());
+ assertEquals(OneofFieldCase.ONEOF_UINT32, builder.getOneofFieldCase());
+ assertEquals(1, builder.getOneofUint32());
+ TestAllTypesLiteOrBuilder messageOrBuilder = builder;
+ assertEquals(OneofFieldCase.ONEOF_UINT32, messageOrBuilder.getOneofFieldCase());
+
+ TestAllExtensionsLite.Builder extendableMessageBuilder =
+ TestAllExtensionsLite.newBuilder();
+ TestAllExtensionsLite extendableMessage = extendableMessageBuilder.build();
+ extendableMessageBuilder.setExtension(
+ UnittestLite.optionalInt32ExtensionLite, 1);
+ assertFalse(extendableMessage.hasExtension(
+ UnittestLite.optionalInt32ExtensionLite));
+ extendableMessage = extendableMessageBuilder.build();
+ assertEquals(
+ 1, (int) extendableMessageBuilder.getExtension(
+ UnittestLite.optionalInt32ExtensionLite));
+ assertEquals(
+ 1, (int) extendableMessage.getExtension(
+ UnittestLite.optionalInt32ExtensionLite));
+ extendableMessageBuilder.setExtension(
+ UnittestLite.optionalInt32ExtensionLite, 3);
+ assertEquals(
+ 3, (int) extendableMessageBuilder.getExtension(
+ UnittestLite.optionalInt32ExtensionLite));
+ assertEquals(
+ 1, (int) extendableMessage.getExtension(
+ UnittestLite.optionalInt32ExtensionLite));
+ extendableMessage = extendableMessageBuilder.build();
+ assertEquals(
+ 3, (int) extendableMessageBuilder.getExtension(
+ UnittestLite.optionalInt32ExtensionLite));
+ assertEquals(
+ 3, (int) extendableMessage.getExtension(
+ UnittestLite.optionalInt32ExtensionLite));
+
+ // No extension registry, so it should be in unknown fields.
+ extendableMessage =
+ TestAllExtensionsLite.parseFrom(extendableMessage.toByteArray());
+ assertFalse(extendableMessage.hasExtension(
+ UnittestLite.optionalInt32ExtensionLite));
+
+ extendableMessageBuilder = extendableMessage.toBuilder();
+ extendableMessageBuilder.mergeFrom(TestAllExtensionsLite.newBuilder()
+ .setExtension(UnittestLite.optionalFixed32ExtensionLite, 11)
+ .build());
+
+ extendableMessage = extendableMessageBuilder.build();
+ ExtensionRegistryLite registry = ExtensionRegistryLite.newInstance();
+ UnittestLite.registerAllExtensions(registry);
+ extendableMessage = TestAllExtensionsLite.parseFrom(
+ extendableMessage.toByteArray(), registry);
+
+ // The unknown field was preserved.
+ assertEquals(
+ 3, (int) extendableMessage.getExtension(
+ UnittestLite.optionalInt32ExtensionLite));
+ assertEquals(
+ 11, (int) extendableMessage.getExtension(
+ UnittestLite.optionalFixed32ExtensionLite));
+ }
+
+ public void testToStringDefaultInstance() throws Exception {
+ assertToStringEquals("", TestAllTypesLite.getDefaultInstance());
+ }
+
+ public void testToStringScalarFieldsSuffixedWithList() throws Exception {
+ assertToStringEquals("deceptively_named_list: 7", TestAllTypesLite.newBuilder()
+ .setDeceptivelyNamedList(7)
+ .build());
+ }
+
+ public void testToStringPrimitives() throws Exception {
+ TestAllTypesLite proto = TestAllTypesLite.newBuilder()
+ .setOptionalInt32(1)
+ .setOptionalInt64(9223372036854775807L)
+ .build();
+ assertToStringEquals("optional_int32: 1\noptional_int64: 9223372036854775807", proto);
+
+ proto = TestAllTypesLite.newBuilder()
+ .setOptionalBool(true)
+ .setOptionalNestedEnum(TestAllTypesLite.NestedEnum.BAZ)
+ .build();
+ assertToStringEquals("optional_bool: true\noptional_nested_enum: BAZ", proto);
+
+ proto = TestAllTypesLite.newBuilder()
+ .setOptionalFloat(2.72f)
+ .setOptionalDouble(3.14)
+ .build();
+ assertToStringEquals("optional_double: 3.14\noptional_float: 2.72", proto);
+ }
+
+ public void testToStringStringFields() throws Exception {
+ TestAllTypesLite proto = TestAllTypesLite.newBuilder()
+ .setOptionalString("foo\"bar\nbaz\\")
+ .build();
+ assertToStringEquals("optional_string: \"foo\\\"bar\\nbaz\\\\\"", proto);
+
+ proto = TestAllTypesLite.newBuilder()
+ .setOptionalString("\u6587")
+ .build();
+ assertToStringEquals("optional_string: \"\\346\\226\\207\"", proto);
+ }
+
+ public void testToStringNestedMessage() throws Exception {
+ TestAllTypesLite proto = TestAllTypesLite.newBuilder()
+ .setOptionalNestedMessage(TestAllTypesLite.NestedMessage.getDefaultInstance())
+ .build();
+ assertToStringEquals("optional_nested_message {\n}", proto);
+
+ proto = TestAllTypesLite.newBuilder()
+ .setOptionalNestedMessage(
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(7))
+ .build();
+ assertToStringEquals("optional_nested_message {\n bb: 7\n}", proto);
+ }
+
+ public void testToStringRepeatedFields() throws Exception {
+ TestAllTypesLite proto = TestAllTypesLite.newBuilder()
+ .addRepeatedInt32(32)
+ .addRepeatedInt32(32)
+ .addRepeatedInt64(64)
+ .build();
+ assertToStringEquals("repeated_int32: 32\nrepeated_int32: 32\nrepeated_int64: 64", proto);
+
+ proto = TestAllTypesLite.newBuilder()
+ .addRepeatedLazyMessage(
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(7))
+ .addRepeatedLazyMessage(
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(8))
+ .build();
+ assertToStringEquals(
+ "repeated_lazy_message {\n bb: 7\n}\nrepeated_lazy_message {\n bb: 8\n}",
+ proto);
+ }
+
+ public void testToStringForeignFields() throws Exception {
+ TestAllTypesLite proto = TestAllTypesLite.newBuilder()
+ .setOptionalForeignEnum(ForeignEnumLite.FOREIGN_LITE_BAR)
+ .setOptionalForeignMessage(
+ ForeignMessageLite.newBuilder()
+ .setC(3))
+ .build();
+ assertToStringEquals(
+ "optional_foreign_enum: FOREIGN_LITE_BAR\noptional_foreign_message {\n c: 3\n}",
+ proto);
+ }
+
+ public void testToStringExtensions() throws Exception {
+ TestAllExtensionsLite message = TestAllExtensionsLite.newBuilder()
+ .setExtension(UnittestLite.optionalInt32ExtensionLite, 123)
+ .addExtension(UnittestLite.repeatedStringExtensionLite, "spam")
+ .addExtension(UnittestLite.repeatedStringExtensionLite, "eggs")
+ .setExtension(UnittestLite.optionalNestedEnumExtensionLite,
+ TestAllTypesLite.NestedEnum.BAZ)
+ .setExtension(UnittestLite.optionalNestedMessageExtensionLite,
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(7).build())
+ .build();
+ assertToStringEquals(
+ "[1]: 123\n[18] {\n bb: 7\n}\n[21]: 3\n[44]: \"spam\"\n[44]: \"eggs\"",
+ message);
+ }
+
+ public void testToStringUnknownFields() throws Exception {
+ TestAllExtensionsLite messageWithExtensions = TestAllExtensionsLite.newBuilder()
+ .setExtension(UnittestLite.optionalInt32ExtensionLite, 123)
+ .addExtension(UnittestLite.repeatedStringExtensionLite, "spam")
+ .addExtension(UnittestLite.repeatedStringExtensionLite, "eggs")
+ .setExtension(UnittestLite.optionalNestedEnumExtensionLite,
+ TestAllTypesLite.NestedEnum.BAZ)
+ .setExtension(UnittestLite.optionalNestedMessageExtensionLite,
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(7).build())
+ .build();
+ TestAllExtensionsLite messageWithUnknownFields = TestAllExtensionsLite.parseFrom(
+ messageWithExtensions.toByteArray());
+ assertToStringEquals(
+ "1: 123\n18: \"\\b\\a\"\n21: 3\n44: \"spam\"\n44: \"eggs\"",
+ messageWithUnknownFields);
+ }
+
+ public void testToStringLazyMessage() throws Exception {
+ TestAllTypesLite message = TestAllTypesLite.newBuilder()
+ .setOptionalLazyMessage(NestedMessage.newBuilder().setBb(1).build())
+ .build();
+ assertToStringEquals("optional_lazy_message {\n bb: 1\n}", message);
+ }
+
+ public void testToStringGroup() throws Exception {
+ TestAllTypesLite message = TestAllTypesLite.newBuilder()
+ .setOptionalGroup(OptionalGroup.newBuilder().setA(1).build())
+ .build();
+ assertToStringEquals("optional_group {\n a: 1\n}", message);
+ }
+
+ public void testToStringOneof() throws Exception {
+ TestAllTypesLite message = TestAllTypesLite.newBuilder()
+ .setOneofString("hello")
+ .build();
+ assertToStringEquals("oneof_string: \"hello\"", message);
+ }
+
+ // Asserts that the toString() representation of the message matches the expected. This verifies
+ // the first line starts with a comment; but, does not factor in said comment as part of the
+ // comparison as it contains unstable addresses.
+ private static void assertToStringEquals(String expected, MessageLite message) {
+ String toString = message.toString();
+ assertEquals('#', toString.charAt(0));
+ if (toString.indexOf("\n") >= 0) {
+ toString = toString.substring(toString.indexOf("\n") + 1);
+ } else {
+ toString = "";
+ }
+ assertEquals(expected, toString);
+ }
+
+ public void testParseLazy() throws Exception {
+ ByteString bb = TestAllTypesLite.newBuilder()
+ .setOptionalLazyMessage(NestedMessage.newBuilder()
+ .setBb(11)
+ .build())
+ .build().toByteString();
+ ByteString cc = TestAllTypesLite.newBuilder()
+ .setOptionalLazyMessage(NestedMessage.newBuilder()
+ .setCc(22)
+ .build())
+ .build().toByteString();
+
+ ByteString concat = bb.concat(cc);
+ TestAllTypesLite message = TestAllTypesLite.parseFrom(concat);
+
+ assertEquals(11, message.getOptionalLazyMessage().getBb());
+ assertEquals(22L, message.getOptionalLazyMessage().getCc());
+ }
+
+ public void testParseLazy_oneOf() throws Exception {
+ ByteString bb = TestAllTypesLite.newBuilder()
+ .setOneofLazyNestedMessage(NestedMessage.newBuilder()
+ .setBb(11)
+ .build())
+ .build().toByteString();
+ ByteString cc = TestAllTypesLite.newBuilder()
+ .setOneofLazyNestedMessage(NestedMessage.newBuilder()
+ .setCc(22)
+ .build())
+ .build().toByteString();
+
+ ByteString concat = bb.concat(cc);
+ TestAllTypesLite message = TestAllTypesLite.parseFrom(concat);
+
+ assertEquals(11, message.getOneofLazyNestedMessage().getBb());
+ assertEquals(22L, message.getOneofLazyNestedMessage().getCc());
+ }
+
+ public void testMergeFromStream_repeatedField() throws Exception {
+ TestAllTypesLite.Builder builder = TestAllTypesLite.newBuilder()
+ .addRepeatedString("hello");
+ builder.mergeFrom(CodedInputStream.newInstance(builder.build().toByteArray()));
+
+ assertEquals(2, builder.getRepeatedStringCount());
+ }
+
+ public void testMergeFromStream_invalidBytes() throws Exception {
+ TestAllTypesLite.Builder builder = TestAllTypesLite.newBuilder()
+ .setDefaultBool(true);
+ try {
+ builder.mergeFrom(CodedInputStream.newInstance("Invalid bytes".getBytes(Internal.UTF_8)));
+ fail();
+ } catch (InvalidProtocolBufferException expected) {}
+ }
+
+ public void testMergeFrom_sanity() throws Exception {
+ TestAllTypesLite one = TestUtilLite.getAllLiteSetBuilder().build();
+ byte[] bytes = one.toByteArray();
+ TestAllTypesLite two = TestAllTypesLite.parseFrom(bytes);
+
+ one = one.toBuilder().mergeFrom(one).build();
+ two = two.toBuilder().mergeFrom(bytes).build();
+ assertEquals(one, two);
+ assertEquals(two, one);
+ assertEquals(one.hashCode(), two.hashCode());
+ }
+
+ public void testMergeFromNoLazyFieldSharing() throws Exception {
+ TestAllTypesLite.Builder sourceBuilder = TestAllTypesLite.newBuilder().setOptionalLazyMessage(
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(1));
+ TestAllTypesLite.Builder targetBuilder =
+ TestAllTypesLite.newBuilder().mergeFrom(sourceBuilder.build());
+ assertEquals(1, sourceBuilder.getOptionalLazyMessage().getBb());
+ // now change the sourceBuilder, and target value shouldn't be affected.
+ sourceBuilder.setOptionalLazyMessage(
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(2));
+ assertEquals(1, targetBuilder.getOptionalLazyMessage().getBb());
+ }
+
+ public void testEquals_notEqual() throws Exception {
+ TestAllTypesLite one = TestUtilLite.getAllLiteSetBuilder().build();
+ byte[] bytes = one.toByteArray();
+ TestAllTypesLite two = one.toBuilder().mergeFrom(one).mergeFrom(bytes).build();
+
+ assertFalse(one.equals(two));
+ assertFalse(two.equals(one));
+
+ assertFalse(one.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(one));
+
+ TestAllTypesLite oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultBool(true)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultBytes(ByteString.EMPTY)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultCord("")
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultCordBytes(ByteString.EMPTY)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultDouble(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultFixed32(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultFixed64(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultFloat(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultForeignEnum(ForeignEnumLite.FOREIGN_LITE_BAR)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultImportEnum(ImportEnumLite.IMPORT_LITE_BAR)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultInt32(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultInt64(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultNestedEnum(NestedEnum.BAR)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultSfixed32(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultSfixed64(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultSint32(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultSint64(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultString("")
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultStringBytes(ByteString.EMPTY)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultStringPiece("")
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultStringPieceBytes(ByteString.EMPTY)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultUint32(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setDefaultUint64(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedBool(true)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedBytes(ByteString.EMPTY)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedCord("")
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedCordBytes(ByteString.EMPTY)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedDouble(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedFixed32(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedFixed64(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedFloat(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedForeignEnum(ForeignEnumLite.FOREIGN_LITE_BAR)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedImportEnum(ImportEnumLite.IMPORT_LITE_BAR)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedInt32(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedInt64(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedNestedEnum(NestedEnum.BAR)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedSfixed32(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedSfixed64(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedSint32(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedSint64(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedString("")
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedStringBytes(ByteString.EMPTY)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedStringPiece("")
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedStringPieceBytes(ByteString.EMPTY)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedUint32(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedUint64(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalBool(true)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalBytes(ByteString.EMPTY)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalCord("")
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalCordBytes(ByteString.EMPTY)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalDouble(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalFixed32(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalFixed64(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalFloat(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalForeignEnum(ForeignEnumLite.FOREIGN_LITE_BAR)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalImportEnum(ImportEnumLite.IMPORT_LITE_BAR)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalInt32(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalInt64(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalNestedEnum(NestedEnum.BAR)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalSfixed32(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalSfixed64(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalSint32(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalSint64(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalString("")
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalStringBytes(ByteString.EMPTY)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalStringPiece("")
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalStringPieceBytes(ByteString.EMPTY)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalUint32(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalUint64(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOneofBytes(ByteString.EMPTY)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOneofLazyNestedMessage(NestedMessage.getDefaultInstance())
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOneofNestedMessage(NestedMessage.getDefaultInstance())
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOneofString("")
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOneofStringBytes(ByteString.EMPTY)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOneofUint32(0)
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalForeignMessage(ForeignMessageLite.getDefaultInstance())
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalGroup(OptionalGroup.getDefaultInstance())
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalPublicImportMessage(PublicImportMessageLite.getDefaultInstance())
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .setOptionalLazyMessage(NestedMessage.getDefaultInstance())
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+ oneFieldSet = TestAllTypesLite.newBuilder()
+ .addRepeatedLazyMessage(NestedMessage.getDefaultInstance())
+ .build();
+ assertFalse(oneFieldSet.equals(TestAllTypesLite.getDefaultInstance()));
+ assertFalse(TestAllTypesLite.getDefaultInstance().equals(oneFieldSet));
+ }
+
+ public void testEquals() throws Exception {
+ // Check that two identical objs are equal.
+ Foo foo1a = Foo.newBuilder()
+ .setValue(1)
+ .addBar(Bar.newBuilder().setName("foo1"))
+ .build();
+ Foo foo1b = Foo.newBuilder()
+ .setValue(1)
+ .addBar(Bar.newBuilder().setName("foo1"))
+ .build();
+ Foo foo2 = Foo.newBuilder()
+ .setValue(1)
+ .addBar(Bar.newBuilder().setName("foo2"))
+ .build();
+
+ // Check that equals is doing value rather than object equality.
+ assertEquals(foo1a, foo1b);
+ assertEquals(foo1a.hashCode(), foo1b.hashCode());
+
+ // Check that a diffeent object is not equal.
+ assertFalse(foo1a.equals(foo2));
+
+ // Check that two objects which have different types but the same field values are not
+ // considered to be equal.
+ Bar bar = Bar.newBuilder().setName("bar").build();
+ BarPrime barPrime = BarPrime.newBuilder().setName("bar").build();
+ assertFalse(bar.equals(barPrime));
+ }
+
+ public void testOneofEquals() throws Exception {
+ TestOneofEquals.Builder builder = TestOneofEquals.newBuilder();
+ TestOneofEquals message1 = builder.build();
+ // Set message2's name field to default value. The two messages should be different when we
+ // check with the oneof case.
+ builder.setName("");
+ TestOneofEquals message2 = builder.build();
+ assertFalse(message1.equals(message2));
+ }
+
+ public void testEquals_sanity() throws Exception {
+ TestAllTypesLite one = TestUtilLite.getAllLiteSetBuilder().build();
+ TestAllTypesLite two = TestAllTypesLite.parseFrom(one.toByteArray());
+ assertEquals(one, two);
+ assertEquals(one.hashCode(), two.hashCode());
+
+ assertEquals(
+ one.toBuilder().mergeFrom(two).build(),
+ two.toBuilder().mergeFrom(two.toByteArray()).build());
+ }
+
+ public void testEqualsAndHashCodeWithUnknownFields() throws InvalidProtocolBufferException {
+ Foo fooWithOnlyValue = Foo.newBuilder()
+ .setValue(1)
+ .build();
+
+ Foo fooWithValueAndExtension = fooWithOnlyValue.toBuilder()
+ .setValue(1)
+ .setExtension(Bar.fooExt, Bar.newBuilder()
+ .setName("name")
+ .build())
+ .build();
+
+ Foo fooWithValueAndUnknownFields = Foo.parseFrom(fooWithValueAndExtension.toByteArray());
+
+ assertEqualsAndHashCodeAreFalse(fooWithOnlyValue, fooWithValueAndUnknownFields);
+ assertEqualsAndHashCodeAreFalse(fooWithValueAndExtension, fooWithValueAndUnknownFields);
+ }
+
+ public void testEqualsAndHashCodeWithExtensions() throws InvalidProtocolBufferException {
+ Foo fooWithOnlyValue = Foo.newBuilder()
+ .setValue(1)
+ .build();
+
+ Foo fooWithValueAndExtension = fooWithOnlyValue.toBuilder()
+ .setValue(1)
+ .setExtension(Bar.fooExt, Bar.newBuilder()
+ .setName("name")
+ .build())
+ .build();
+
+ assertEqualsAndHashCodeAreFalse(fooWithOnlyValue, fooWithValueAndExtension);
+ }
+
+ // Test to ensure we avoid a class cast exception with oneofs.
+ public void testEquals_oneOfMessages() {
+ TestAllTypesLite mine = TestAllTypesLite.newBuilder()
+ .setOneofString("Hello")
+ .build();
+
+ TestAllTypesLite other = TestAllTypesLite.newBuilder()
+ .setOneofNestedMessage(NestedMessage.getDefaultInstance())
+ .build();
+
+ assertFalse(mine.equals(other));
+ assertFalse(other.equals(mine));
+ }
+
+ public void testHugeFieldNumbers() throws InvalidProtocolBufferException {
+ TestHugeFieldNumbersLite message =
+ TestHugeFieldNumbersLite.newBuilder()
+ .setOptionalInt32(1)
+ .addRepeatedInt32(2)
+ .setOptionalEnum(ForeignEnumLite.FOREIGN_LITE_FOO)
+ .setOptionalString("xyz")
+ .setOptionalMessage(ForeignMessageLite.newBuilder().setC(3).build())
+ .build();
+
+ TestHugeFieldNumbersLite parsedMessage =
+ TestHugeFieldNumbersLite.parseFrom(message.toByteArray());
+ assertEquals(1, parsedMessage.getOptionalInt32());
+ assertEquals(2, parsedMessage.getRepeatedInt32(0));
+ assertEquals(ForeignEnumLite.FOREIGN_LITE_FOO, parsedMessage.getOptionalEnum());
+ assertEquals("xyz", parsedMessage.getOptionalString());
+ assertEquals(3, parsedMessage.getOptionalMessage().getC());
+ }
+
+ private void assertEqualsAndHashCodeAreFalse(Object o1, Object o2) {
+ assertFalse(o1.equals(o2));
+ assertFalse(o1.hashCode() == o2.hashCode());
+ }
+
+ public void testRecursiveHashcode() {
+ // This tests that we don't infinite loop.
+ TestRecursiveOneof.getDefaultInstance().hashCode();
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java
new file mode 100644
index 0000000000..eac47448e0
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LiteralByteStringTest.java
@@ -0,0 +1,544 @@
+// 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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+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()}.
+ * This class is designed to be extended for testing extensions of {@code LiteralByteString}
+ * such as {@code BoundedByteString}, see {@link BoundedByteStringTest}.
+ *
+ * @author carlanton@google.com (Carl Haverl)
+ */
+public class LiteralByteStringTest extends TestCase {
+ protected static final String UTF_8 = "UTF-8";
+
+ protected String classUnderTest;
+ protected byte[] referenceBytes;
+ protected ByteString stringUnderTest;
+ protected int expectedHashCode;
+
+ @Override
+ protected void setUp() throws Exception {
+ classUnderTest = "LiteralByteString";
+ referenceBytes = ByteStringTest.getTestBytes(1234, 11337766L);
+ stringUnderTest = ByteString.copyFrom(referenceBytes);
+ expectedHashCode = 331161852;
+ }
+
+ public void testExpectedType() {
+ String actualClassName = getActualClassName(stringUnderTest);
+ assertEquals(classUnderTest + " should match type exactly", classUnderTest, actualClassName);
+ }
+
+ protected String getActualClassName(Object object) {
+ return object.getClass().getSimpleName();
+ }
+
+ public void testByteAt() {
+ boolean stillEqual = true;
+ for (int i = 0; stillEqual && i < referenceBytes.length; ++i) {
+ stillEqual = (referenceBytes[i] == stringUnderTest.byteAt(i));
+ }
+ assertTrue(classUnderTest + " must capture the right bytes", stillEqual);
+ }
+
+ public void testByteIterator() {
+ boolean stillEqual = true;
+ ByteString.ByteIterator iter = stringUnderTest.iterator();
+ for (int i = 0; stillEqual && i < referenceBytes.length; ++i) {
+ stillEqual = (iter.hasNext() && referenceBytes[i] == iter.nextByte());
+ }
+ assertTrue(classUnderTest + " must capture the right bytes", stillEqual);
+ assertFalse(classUnderTest + " must have exhausted the itertor", iter.hasNext());
+
+ try {
+ iter.nextByte();
+ fail("Should have thrown an exception.");
+ } catch (NoSuchElementException e) {
+ // This is success
+ }
+ }
+
+ public void testByteIterable() {
+ boolean stillEqual = true;
+ int j = 0;
+ for (byte quantum : stringUnderTest) {
+ stillEqual = (referenceBytes[j] == quantum);
+ ++j;
+ }
+ assertTrue(classUnderTest + " must capture the right bytes as Bytes", stillEqual);
+ assertEquals(classUnderTest + " iterable character count", referenceBytes.length, j);
+ }
+
+ public void testSize() {
+ assertEquals(classUnderTest + " must have the expected size", referenceBytes.length,
+ stringUnderTest.size());
+ }
+
+ public void testGetTreeDepth() {
+ assertEquals(classUnderTest + " must have depth 0", 0, stringUnderTest.getTreeDepth());
+ }
+
+ public void testIsBalanced() {
+ assertTrue(classUnderTest + " is technically balanced", stringUnderTest.isBalanced());
+ }
+
+ public void testCopyTo_ByteArrayOffsetLength() {
+ int destinationOffset = 50;
+ int length = 100;
+ byte[] destination = new byte[destinationOffset + length];
+ int sourceOffset = 213;
+ stringUnderTest.copyTo(destination, sourceOffset, destinationOffset, length);
+ boolean stillEqual = true;
+ for (int i = 0; stillEqual && i < length; ++i) {
+ stillEqual = referenceBytes[i + sourceOffset] == destination[i + destinationOffset];
+ }
+ assertTrue(classUnderTest + ".copyTo(4 arg) must give the expected bytes", stillEqual);
+ }
+
+ public void testCopyTo_ByteArrayOffsetLengthErrors() {
+ int destinationOffset = 50;
+ int length = 100;
+ byte[] destination = new byte[destinationOffset + length];
+
+ try {
+ // Copy one too many bytes
+ stringUnderTest.copyTo(destination, stringUnderTest.size() + 1 - length,
+ destinationOffset, length);
+ fail("Should have thrown an exception when copying too many bytes of a "
+ + classUnderTest);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+
+ try {
+ // Copy with illegal negative sourceOffset
+ stringUnderTest.copyTo(destination, -1, destinationOffset, length);
+ fail("Should have thrown an exception when given a negative sourceOffset in "
+ + classUnderTest);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+
+ try {
+ // Copy with illegal negative destinationOffset
+ stringUnderTest.copyTo(destination, 0, -1, length);
+ fail("Should have thrown an exception when given a negative destinationOffset in "
+ + classUnderTest);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+
+ try {
+ // Copy with illegal negative size
+ stringUnderTest.copyTo(destination, 0, 0, -1);
+ fail("Should have thrown an exception when given a negative size in "
+ + classUnderTest);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+
+ try {
+ // Copy with illegal too-large sourceOffset
+ stringUnderTest.copyTo(destination, 2 * stringUnderTest.size(), 0, length);
+ fail("Should have thrown an exception when the destinationOffset is too large in "
+ + classUnderTest);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+
+ try {
+ // Copy with illegal too-large destinationOffset
+ stringUnderTest.copyTo(destination, 0, 2 * destination.length, length);
+ fail("Should have thrown an exception when the destinationOffset is too large in "
+ + classUnderTest);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+ }
+
+ public void testCopyTo_ByteBuffer() {
+ ByteBuffer myBuffer = ByteBuffer.allocate(referenceBytes.length);
+ stringUnderTest.copyTo(myBuffer);
+ assertTrue(classUnderTest + ".copyTo(ByteBuffer) must give back the same bytes",
+ Arrays.equals(referenceBytes, myBuffer.array()));
+ }
+
+ public void testMarkSupported() {
+ InputStream stream = stringUnderTest.newInput();
+ assertTrue(classUnderTest + ".newInput() must support marking", stream.markSupported());
+ }
+
+ public void testMarkAndReset() throws IOException {
+ int fraction = stringUnderTest.size() / 3;
+
+ InputStream stream = stringUnderTest.newInput();
+ stream.mark(stringUnderTest.size()); // First, mark() the end.
+
+ skipFully(stream, fraction); // Skip a large fraction, but not all.
+ int available = stream.available();
+ assertTrue(
+ classUnderTest + ": after skipping to the 'middle', half the bytes are available",
+ (stringUnderTest.size() - fraction) == available);
+ stream.reset();
+
+ skipFully(stream, stringUnderTest.size()); // Skip to the end.
+ available = stream.available();
+ assertTrue(
+ classUnderTest + ": after skipping to the end, no more bytes are available",
+ 0 == available);
+ }
+
+ /**
+ * Discards {@code n} bytes of data from the input stream. This method
+ * will block until the full amount has been skipped. Does not close the
+ * stream.
+ * <p>Copied from com.google.common.io.ByteStreams to avoid adding dependency.
+ *
+ * @param in the input stream to read from
+ * @param n the number of bytes to skip
+ * @throws EOFException if this stream reaches the end before skipping all
+ * the bytes
+ * @throws IOException if an I/O error occurs, or the stream does not
+ * support skipping
+ */
+ static void skipFully(InputStream in, long n) throws IOException {
+ long toSkip = n;
+ while (n > 0) {
+ long amt = in.skip(n);
+ if (amt == 0) {
+ // Force a blocking read to avoid infinite loop
+ if (in.read() == -1) {
+ long skipped = toSkip - n;
+ throw new EOFException("reached end of stream after skipping "
+ + skipped + " bytes; " + toSkip + " bytes expected");
+ }
+ n--;
+ } else {
+ n -= amt;
+ }
+ }
+ }
+
+ public void testAsReadOnlyByteBuffer() {
+ ByteBuffer byteBuffer = stringUnderTest.asReadOnlyByteBuffer();
+ byte[] roundTripBytes = new byte[referenceBytes.length];
+ assertTrue(byteBuffer.remaining() == referenceBytes.length);
+ assertTrue(byteBuffer.isReadOnly());
+ byteBuffer.get(roundTripBytes);
+ assertTrue(classUnderTest + ".asReadOnlyByteBuffer() must give back the same bytes",
+ Arrays.equals(referenceBytes, roundTripBytes));
+ }
+
+ public void testAsReadOnlyByteBufferList() {
+ List<ByteBuffer> byteBuffers = stringUnderTest.asReadOnlyByteBufferList();
+ int bytesSeen = 0;
+ byte[] roundTripBytes = new byte[referenceBytes.length];
+ for (ByteBuffer byteBuffer : byteBuffers) {
+ int thisLength = byteBuffer.remaining();
+ assertTrue(byteBuffer.isReadOnly());
+ assertTrue(bytesSeen + thisLength <= referenceBytes.length);
+ byteBuffer.get(roundTripBytes, bytesSeen, thisLength);
+ bytesSeen += thisLength;
+ }
+ assertTrue(bytesSeen == referenceBytes.length);
+ assertTrue(classUnderTest + ".asReadOnlyByteBufferTest() must give back the same bytes",
+ Arrays.equals(referenceBytes, roundTripBytes));
+ }
+
+ public void testToByteArray() {
+ byte[] roundTripBytes = stringUnderTest.toByteArray();
+ assertTrue(classUnderTest + ".toByteArray() must give back the same bytes",
+ Arrays.equals(referenceBytes, roundTripBytes));
+ }
+
+ public void testWriteTo() throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ stringUnderTest.writeTo(bos);
+ byte[] roundTripBytes = bos.toByteArray();
+ assertTrue(classUnderTest + ".writeTo() must give back the same bytes",
+ Arrays.equals(referenceBytes, roundTripBytes));
+ }
+
+ public void testWriteToShouldNotExposeInternalBufferToOutputStream() throws IOException {
+ OutputStream os = new OutputStream() {
+ @Override
+ public void write(byte[] b, int off, int len) {
+ Arrays.fill(b, off, off + len, (byte) 0);
+ }
+
+ @Override
+ public void write(int b) {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+ stringUnderTest.writeTo(os);
+ assertTrue(classUnderTest + ".writeTo() must not grant access to underlying array",
+ Arrays.equals(referenceBytes, stringUnderTest.toByteArray()));
+ }
+
+ public void testWriteToInternalShouldExposeInternalBufferToOutputStream() throws IOException {
+ OutputStream os = new OutputStream() {
+ @Override
+ public void write(byte[] b, int off, int len) {
+ Arrays.fill(b, off, off + len, (byte) 0);
+ }
+
+ @Override
+ public void write(int b) {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+ stringUnderTest.writeToInternal(os, 0, stringUnderTest.size());
+ byte[] allZeros = new byte[stringUnderTest.size()];
+ assertTrue(classUnderTest + ".writeToInternal() must grant access to underlying array",
+ Arrays.equals(allZeros, stringUnderTest.toByteArray()));
+ }
+
+ public void testWriteToShouldExposeInternalBufferToByteOutput() throws IOException {
+ ByteOutput out = new ByteOutput() {
+ @Override
+ public void write(byte value) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void write(byte[] value, int offset, int length) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void writeLazy(byte[] value, int offset, int length) throws IOException {
+ Arrays.fill(value, offset, offset + length, (byte) 0);
+ }
+
+ @Override
+ public void write(ByteBuffer value) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void writeLazy(ByteBuffer value) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+ stringUnderTest.writeTo(out);
+ byte[] allZeros = new byte[stringUnderTest.size()];
+ assertTrue(classUnderTest + ".writeToInternal() must grant access to underlying array",
+ Arrays.equals(allZeros, stringUnderTest.toByteArray()));
+ }
+
+ public void testNewOutput() throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ByteString.Output output = ByteString.newOutput();
+ stringUnderTest.writeTo(output);
+ assertEquals("Output Size returns correct result",
+ output.size(), stringUnderTest.size());
+ output.writeTo(bos);
+ assertTrue("Output.writeTo() must give back the same bytes",
+ Arrays.equals(referenceBytes, bos.toByteArray()));
+
+ // write the output stream to itself! This should cause it to double
+ output.writeTo(output);
+ assertEquals("Writing an output stream to itself is successful",
+ stringUnderTest.concat(stringUnderTest), output.toByteString());
+
+ output.reset();
+ assertEquals("Output.reset() resets the output", 0, output.size());
+ assertEquals("Output.reset() resets the output",
+ ByteString.EMPTY, output.toByteString());
+ }
+
+ public void testToString() throws UnsupportedEncodingException {
+ String testString = "I love unicode \u1234\u5678 characters";
+ ByteString unicode = ByteString.wrap(testString.getBytes(Internal.UTF_8));
+ String roundTripString = unicode.toString(UTF_8);
+ assertEquals(classUnderTest + " unicode must match", testString, roundTripString);
+ }
+
+ public void testCharsetToString() {
+ String testString = "I love unicode \u1234\u5678 characters";
+ ByteString unicode = ByteString.wrap(testString.getBytes(Internal.UTF_8));
+ String roundTripString = unicode.toString(Internal.UTF_8);
+ assertEquals(classUnderTest + " unicode must match", testString, roundTripString);
+ }
+
+ public void testToString_returnsCanonicalEmptyString() {
+ assertSame(classUnderTest + " must be the same string references",
+ ByteString.EMPTY.toString(Internal.UTF_8),
+ ByteString.wrap(new byte[]{}).toString(Internal.UTF_8));
+ }
+
+ public void testToString_raisesException() {
+ try {
+ ByteString.EMPTY.toString("invalid");
+ fail("Should have thrown an exception.");
+ } catch (UnsupportedEncodingException expected) {
+ // This is success
+ }
+
+ try {
+ ByteString.wrap(referenceBytes).toString("invalid");
+ fail("Should have thrown an exception.");
+ } catch (UnsupportedEncodingException expected) {
+ // This is success
+ }
+ }
+
+ public void testEquals() {
+ assertEquals(classUnderTest + " must not equal null", false, stringUnderTest.equals(null));
+ assertEquals(classUnderTest + " must equal self", stringUnderTest, stringUnderTest);
+ assertFalse(classUnderTest + " must not equal the empty string",
+ stringUnderTest.equals(ByteString.EMPTY));
+ assertEquals(classUnderTest + " empty strings must be equal",
+ ByteString.wrap(new byte[]{}), stringUnderTest.substring(55, 55));
+ assertEquals(classUnderTest + " must equal another string with the same value",
+ stringUnderTest, ByteString.wrap(referenceBytes));
+
+ byte[] mungedBytes = new byte[referenceBytes.length];
+ System.arraycopy(referenceBytes, 0, mungedBytes, 0, referenceBytes.length);
+ mungedBytes[mungedBytes.length - 5] = (byte) (mungedBytes[mungedBytes.length - 5] ^ 0xFF);
+ assertFalse(classUnderTest + " must not equal every string with the same length",
+ stringUnderTest.equals(ByteString.wrap(mungedBytes)));
+ }
+
+ public void testHashCode() {
+ int hash = stringUnderTest.hashCode();
+ assertEquals(classUnderTest + " must have expected hashCode", expectedHashCode, hash);
+ }
+
+ public void testPeekCachedHashCode() {
+ assertEquals(classUnderTest + ".peekCachedHashCode() should return zero at first", 0,
+ stringUnderTest.peekCachedHashCode());
+ stringUnderTest.hashCode();
+ assertEquals(classUnderTest + ".peekCachedHashCode should return zero at first",
+ expectedHashCode, stringUnderTest.peekCachedHashCode());
+ }
+
+ public void testPartialHash() {
+ // partialHash() is more strenuously tested elsewhere by testing hashes of substrings.
+ // This test would fail if the expected hash were 1. It's not.
+ int hash = stringUnderTest.partialHash(stringUnderTest.size(), 0, stringUnderTest.size());
+ assertEquals(classUnderTest + ".partialHash() must yield expected hashCode",
+ expectedHashCode, hash);
+ }
+
+ public void testNewInput() throws IOException {
+ InputStream input = stringUnderTest.newInput();
+ assertEquals("InputStream.available() returns correct value",
+ stringUnderTest.size(), input.available());
+ boolean stillEqual = true;
+ for (byte referenceByte : referenceBytes) {
+ int expectedInt = (referenceByte & 0xFF);
+ stillEqual = (expectedInt == input.read());
+ }
+ assertEquals("InputStream.available() returns correct value",
+ 0, input.available());
+ assertTrue(classUnderTest + " must give the same bytes from the InputStream", stillEqual);
+ assertEquals(classUnderTest + " InputStream must now be exhausted", -1, input.read());
+ }
+
+ public void testNewInput_skip() throws IOException {
+ InputStream input = stringUnderTest.newInput();
+ int stringSize = stringUnderTest.size();
+ int nearEndIndex = stringSize * 2 / 3;
+ long skipped1 = input.skip(nearEndIndex);
+ assertEquals("InputStream.skip()", skipped1, nearEndIndex);
+ assertEquals("InputStream.available()",
+ stringSize - skipped1, input.available());
+ assertTrue("InputStream.mark() is available", input.markSupported());
+ input.mark(0);
+ assertEquals("InputStream.skip(), read()",
+ stringUnderTest.byteAt(nearEndIndex) & 0xFF, input.read());
+ assertEquals("InputStream.available()",
+ stringSize - skipped1 - 1, input.available());
+ long skipped2 = input.skip(stringSize);
+ assertEquals("InputStream.skip() incomplete",
+ skipped2, stringSize - skipped1 - 1);
+ assertEquals("InputStream.skip(), no more input", 0, input.available());
+ assertEquals("InputStream.skip(), no more input", -1, input.read());
+ input.reset();
+ assertEquals("InputStream.reset() succeded",
+ stringSize - skipped1, input.available());
+ assertEquals("InputStream.reset(), read()",
+ stringUnderTest.byteAt(nearEndIndex) & 0xFF, input.read());
+ }
+
+ public void testNewCodedInput() throws IOException {
+ CodedInputStream cis = stringUnderTest.newCodedInput();
+ byte[] roundTripBytes = cis.readRawBytes(referenceBytes.length);
+ assertTrue(classUnderTest + " must give the same bytes back from the CodedInputStream",
+ Arrays.equals(referenceBytes, roundTripBytes));
+ assertTrue(classUnderTest + " CodedInputStream must now be exhausted", cis.isAtEnd());
+ }
+
+ /**
+ * Make sure we keep things simple when concatenating with empty. See also
+ * {@link ByteStringTest#testConcat_empty()}.
+ */
+ public void testConcat_empty() {
+ assertSame(classUnderTest + " concatenated with empty must give " + classUnderTest,
+ stringUnderTest.concat(ByteString.EMPTY), stringUnderTest);
+ assertSame("empty concatenated with " + classUnderTest + " must give " + classUnderTest,
+ ByteString.EMPTY.concat(stringUnderTest), stringUnderTest);
+ }
+
+ public void testJavaSerialization() throws Exception {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(out);
+ oos.writeObject(stringUnderTest);
+ oos.close();
+ byte[] pickled = out.toByteArray();
+ InputStream in = new ByteArrayInputStream(pickled);
+ ObjectInputStream ois = new ObjectInputStream(in);
+ Object o = ois.readObject();
+ assertTrue("Didn't get a ByteString back", o instanceof ByteString);
+ assertEquals("Should get an equal ByteString back", stringUnderTest, o);
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LongArrayListTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LongArrayListTest.java
new file mode 100644
index 0000000000..6bbdfcaa32
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LongArrayListTest.java
@@ -0,0 +1,461 @@
+// 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 static java.util.Arrays.asList;
+
+import java.util.Collections;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import junit.framework.TestCase;
+
+/**
+ * Tests for {@link LongArrayList}.
+ *
+ * @author dweis@google.com (Daniel Weis)
+ */
+public class LongArrayListTest extends TestCase {
+
+ private static final LongArrayList UNARY_LIST =
+ newImmutableLongArrayList(1);
+ private static final LongArrayList TERTIARY_LIST =
+ newImmutableLongArrayList(1, 2, 3);
+
+ private LongArrayList list;
+
+ @Override
+ protected void setUp() throws Exception {
+ list = new LongArrayList();
+ }
+
+ public void testEmptyListReturnsSameInstance() {
+ assertSame(LongArrayList.emptyList(), LongArrayList.emptyList());
+ }
+
+ public void testEmptyListIsImmutable() {
+ assertImmutable(LongArrayList.emptyList());
+ }
+
+ public void testMakeImmutable() {
+ list.addLong(3);
+ list.addLong(4);
+ list.addLong(5);
+ list.addLong(7);
+ list.makeImmutable();
+ assertImmutable(list);
+ }
+
+ public void testModificationWithIteration() {
+ list.addAll(asList(1L, 2L, 3L, 4L));
+ Iterator<Long> iterator = list.iterator();
+ assertEquals(4, list.size());
+ assertEquals(1L, (long) list.get(0));
+ assertEquals(1L, (long) iterator.next());
+ list.set(0, 1L);
+ assertEquals(2L, (long) iterator.next());
+
+ list.remove(0);
+ try {
+ iterator.next();
+ fail();
+ } catch (ConcurrentModificationException e) {
+ // expected
+ }
+
+ iterator = list.iterator();
+ list.add(0, 0L);
+ try {
+ iterator.next();
+ fail();
+ } catch (ConcurrentModificationException e) {
+ // expected
+ }
+ }
+
+ public void testGet() {
+ assertEquals(1L, (long) TERTIARY_LIST.get(0));
+ assertEquals(2L, (long) TERTIARY_LIST.get(1));
+ assertEquals(3L, (long) TERTIARY_LIST.get(2));
+
+ try {
+ TERTIARY_LIST.get(-1);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ TERTIARY_LIST.get(3);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testGetLong() {
+ assertEquals(1L, TERTIARY_LIST.getLong(0));
+ assertEquals(2L, TERTIARY_LIST.getLong(1));
+ assertEquals(3L, TERTIARY_LIST.getLong(2));
+
+ try {
+ TERTIARY_LIST.get(-1);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ TERTIARY_LIST.get(3);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testSize() {
+ assertEquals(0, LongArrayList.emptyList().size());
+ assertEquals(1, UNARY_LIST.size());
+ assertEquals(3, TERTIARY_LIST.size());
+
+ list.addLong(3);
+ list.addLong(4);
+ list.addLong(6);
+ list.addLong(8);
+ assertEquals(4, list.size());
+
+ list.remove(0);
+ assertEquals(3, list.size());
+
+ list.add(17L);
+ assertEquals(4, list.size());
+ }
+
+ public void testSet() {
+ list.addLong(2);
+ list.addLong(4);
+
+ assertEquals(2L, (long) list.set(0, 3L));
+ assertEquals(3L, list.getLong(0));
+
+ assertEquals(4L, (long) list.set(1, 0L));
+ assertEquals(0L, list.getLong(1));
+
+ try {
+ list.set(-1, 0L);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.set(2, 0L);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testSetLong() {
+ list.addLong(1);
+ list.addLong(3);
+
+ assertEquals(1L, list.setLong(0, 0));
+ assertEquals(0L, list.getLong(0));
+
+ assertEquals(3L, list.setLong(1, 0));
+ assertEquals(0L, list.getLong(1));
+
+ try {
+ list.setLong(-1, 0);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.setLong(2, 0);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testAdd() {
+ assertEquals(0, list.size());
+
+ assertTrue(list.add(2L));
+ assertEquals(asList(2L), list);
+
+ assertTrue(list.add(3L));
+ list.add(0, 4L);
+ assertEquals(asList(4L, 2L, 3L), list);
+
+ list.add(0, 1L);
+ list.add(0, 0L);
+ // Force a resize by getting up to 11 elements.
+ for (int i = 0; i < 6; i++) {
+ list.add(Long.valueOf(5 + i));
+ }
+ assertEquals(
+ asList(0L, 1L, 4L, 2L, 3L, 5L, 6L, 7L, 8L, 9L, 10L),
+ list);
+
+ try {
+ list.add(-1, 5L);
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.add(4, 5L);
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void testAddLong() {
+ assertEquals(0, list.size());
+
+ list.addLong(2);
+ assertEquals(asList(2L), list);
+
+ list.addLong(3);
+ assertEquals(asList(2L, 3L), list);
+ }
+
+ public void testAddAll() {
+ assertEquals(0, list.size());
+
+ assertTrue(list.addAll(Collections.singleton(1L)));
+ assertEquals(1, list.size());
+ assertEquals(1L, (long) list.get(0));
+ assertEquals(1L, list.getLong(0));
+
+ assertTrue(list.addAll(asList(2L, 3L, 4L, 5L, 6L)));
+ assertEquals(asList(1L, 2L, 3L, 4L, 5L, 6L), list);
+
+ assertTrue(list.addAll(TERTIARY_LIST));
+ assertEquals(asList(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L), list);
+
+ assertFalse(list.addAll(Collections.<Long>emptyList()));
+ assertFalse(list.addAll(LongArrayList.emptyList()));
+ }
+
+ public void testRemove() {
+ list.addAll(TERTIARY_LIST);
+ assertEquals(1L, (long) list.remove(0));
+ assertEquals(asList(2L, 3L), list);
+
+ assertTrue(list.remove(Long.valueOf(3)));
+ assertEquals(asList(2L), list);
+
+ assertFalse(list.remove(Long.valueOf(3)));
+ assertEquals(asList(2L), list);
+
+ assertEquals(2L, (long) list.remove(0));
+ assertEquals(asList(), list);
+
+ try {
+ list.remove(-1);
+ fail();
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ list.remove(0);
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ private void assertImmutable(LongArrayList list) {
+ if (list.contains(1L)) {
+ throw new RuntimeException("Cannot test the immutability of lists that contain 1.");
+ }
+
+ try {
+ list.add(1L);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.add(0, 1L);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(Collections.<Long>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(Collections.singletonList(1L));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(new LongArrayList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, Collections.singleton(1L));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, Collections.<Long>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addLong(0);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.clear();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.remove(1);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.remove(new Object());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(Collections.<Long>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(Collections.singleton(1L));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(Collections.<Long>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(Collections.singleton(1L));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.set(0, 0L);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.setLong(0, 0);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ private static LongArrayList newImmutableLongArrayList(long... elements) {
+ LongArrayList list = new LongArrayList();
+ for (long element : elements) {
+ list.addLong(element);
+ }
+ list.makeImmutable();
+ return list;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/MapForProto2LiteTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/MapForProto2LiteTest.java
new file mode 100644
index 0000000000..0a14f58417
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/MapForProto2LiteTest.java
@@ -0,0 +1,796 @@
+// 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 map_lite_test.MapForProto2TestProto.BizarroTestMap;
+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 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.
+ */
+public final class MapForProto2LiteTest extends TestCase {
+
+ private void setMapValues(TestMap.Builder builder) {
+ builder
+ .putInt32ToInt32Field(1, 11)
+ .putInt32ToInt32Field(2, 22)
+ .putInt32ToInt32Field(3, 33)
+
+ .putInt32ToStringField(1, "11")
+ .putInt32ToStringField(2, "22")
+ .putInt32ToStringField(3, "33")
+
+ .putInt32ToBytesField(1, TestUtil.toBytes("11"))
+ .putInt32ToBytesField(2, TestUtil.toBytes("22"))
+ .putInt32ToBytesField(3, TestUtil.toBytes("33"))
+
+ .putInt32ToEnumField(1, TestMap.EnumValue.FOO)
+ .putInt32ToEnumField(2, TestMap.EnumValue.BAR)
+ .putInt32ToEnumField(3, TestMap.EnumValue.BAZ)
+
+ .putInt32ToMessageField(1, MessageValue.newBuilder().setValue(11).build())
+ .putInt32ToMessageField(2, MessageValue.newBuilder().setValue(22).build())
+ .putInt32ToMessageField(3, MessageValue.newBuilder().setValue(33).build())
+
+ .putStringToInt32Field("1", 11)
+ .putStringToInt32Field("2", 22)
+ .putStringToInt32Field("3", 33);
+ }
+
+ public void testSetMapValues() {
+ TestMap.Builder mapBuilder = TestMap.newBuilder();
+ setMapValues(mapBuilder);
+ TestMap map = mapBuilder.build();
+ assertMapValuesSet(map);
+ }
+
+ private void copyMapValues(TestMap source, TestMap.Builder destination) {
+ destination
+ .putAllInt32ToInt32Field(source.getInt32ToInt32Field())
+ .putAllInt32ToStringField(source.getInt32ToStringField())
+ .putAllInt32ToBytesField(source.getInt32ToBytesField())
+ .putAllInt32ToEnumField(source.getInt32ToEnumField())
+ .putAllInt32ToMessageField(source.getInt32ToMessageField())
+ .putAllStringToInt32Field(source.getStringToInt32Field());
+ }
+
+ private void assertMapValuesSet(TestMap message) {
+ assertEquals(3, message.getInt32ToInt32Field().size());
+ assertEquals(11, message.getInt32ToInt32Field().get(1).intValue());
+ assertEquals(22, message.getInt32ToInt32Field().get(2).intValue());
+ assertEquals(33, message.getInt32ToInt32Field().get(3).intValue());
+
+ assertEquals(3, message.getInt32ToStringField().size());
+ assertEquals("11", message.getInt32ToStringField().get(1));
+ assertEquals("22", message.getInt32ToStringField().get(2));
+ assertEquals("33", message.getInt32ToStringField().get(3));
+
+ assertEquals(3, message.getInt32ToBytesField().size());
+ assertEquals(TestUtil.toBytes("11"), message.getInt32ToBytesField().get(1));
+ assertEquals(TestUtil.toBytes("22"), message.getInt32ToBytesField().get(2));
+ assertEquals(TestUtil.toBytes("33"), message.getInt32ToBytesField().get(3));
+
+ assertEquals(3, message.getInt32ToEnumField().size());
+ assertEquals(TestMap.EnumValue.FOO, message.getInt32ToEnumField().get(1));
+ assertEquals(TestMap.EnumValue.BAR, message.getInt32ToEnumField().get(2));
+ assertEquals(TestMap.EnumValue.BAZ, message.getInt32ToEnumField().get(3));
+
+ assertEquals(3, message.getInt32ToMessageField().size());
+ assertEquals(11, message.getInt32ToMessageField().get(1).getValue());
+ assertEquals(22, message.getInt32ToMessageField().get(2).getValue());
+ assertEquals(33, message.getInt32ToMessageField().get(3).getValue());
+
+ assertEquals(3, message.getStringToInt32Field().size());
+ assertEquals(11, message.getStringToInt32Field().get("1").intValue());
+ assertEquals(22, message.getStringToInt32Field().get("2").intValue());
+ assertEquals(33, message.getStringToInt32Field().get("3").intValue());
+ }
+
+ private void updateMapValues(TestMap.Builder builder) {
+ builder
+ .putInt32ToInt32Field(1, 111)
+ .removeInt32ToInt32Field(2)
+ .putInt32ToInt32Field(4, 44)
+
+ .putInt32ToStringField(1, "111")
+ .removeInt32ToStringField(2)
+ .putInt32ToStringField(4, "44")
+
+ .putInt32ToBytesField(1, TestUtil.toBytes("111"))
+ .removeInt32ToBytesField(2)
+ .putInt32ToBytesField(4, TestUtil.toBytes("44"))
+
+ .putInt32ToEnumField(1, TestMap.EnumValue.BAR)
+ .removeInt32ToEnumField(2)
+ .putInt32ToEnumField(4, TestMap.EnumValue.QUX)
+
+ .putInt32ToMessageField(1, MessageValue.newBuilder().setValue(111).build())
+ .removeInt32ToMessageField(2)
+ .putInt32ToMessageField(4, MessageValue.newBuilder().setValue(44).build())
+
+ .putStringToInt32Field("1", 111)
+ .removeStringToInt32Field("2")
+ .putStringToInt32Field("4", 44);
+ }
+
+ public void testUpdateMapValues() {
+ TestMap.Builder mapBuilder = TestMap.newBuilder();
+ setMapValues(mapBuilder);
+ TestMap map = mapBuilder.build();
+ assertMapValuesSet(map);
+
+ mapBuilder = map.toBuilder();
+ updateMapValues(mapBuilder);
+ map = mapBuilder.build();
+ assertMapValuesUpdated(map);
+ }
+
+ private void assertMapValuesUpdated(TestMap message) {
+ assertEquals(3, message.getInt32ToInt32Field().size());
+ assertEquals(111, message.getInt32ToInt32Field().get(1).intValue());
+ assertEquals(33, message.getInt32ToInt32Field().get(3).intValue());
+ assertEquals(44, message.getInt32ToInt32Field().get(4).intValue());
+
+ assertEquals(3, message.getInt32ToStringField().size());
+ assertEquals("111", message.getInt32ToStringField().get(1));
+ assertEquals("33", message.getInt32ToStringField().get(3));
+ assertEquals("44", message.getInt32ToStringField().get(4));
+
+ assertEquals(3, message.getInt32ToBytesField().size());
+ assertEquals(TestUtil.toBytes("111"), message.getInt32ToBytesField().get(1));
+ assertEquals(TestUtil.toBytes("33"), message.getInt32ToBytesField().get(3));
+ assertEquals(TestUtil.toBytes("44"), message.getInt32ToBytesField().get(4));
+
+ assertEquals(3, message.getInt32ToEnumField().size());
+ assertEquals(TestMap.EnumValue.BAR, message.getInt32ToEnumField().get(1));
+ assertEquals(TestMap.EnumValue.BAZ, message.getInt32ToEnumField().get(3));
+ assertEquals(TestMap.EnumValue.QUX, message.getInt32ToEnumField().get(4));
+
+ assertEquals(3, message.getInt32ToMessageField().size());
+ assertEquals(111, message.getInt32ToMessageField().get(1).getValue());
+ assertEquals(33, message.getInt32ToMessageField().get(3).getValue());
+ assertEquals(44, message.getInt32ToMessageField().get(4).getValue());
+
+ assertEquals(3, message.getStringToInt32Field().size());
+ assertEquals(111, message.getStringToInt32Field().get("1").intValue());
+ assertEquals(33, message.getStringToInt32Field().get("3").intValue());
+ assertEquals(44, message.getStringToInt32Field().get("4").intValue());
+ }
+
+ private void assertMapValuesCleared(TestMapOrBuilder testMapOrBuilder) {
+ assertEquals(0, testMapOrBuilder.getInt32ToInt32Field().size());
+ assertEquals(0, testMapOrBuilder.getInt32ToInt32FieldCount());
+ assertEquals(0, testMapOrBuilder.getInt32ToStringField().size());
+ assertEquals(0, testMapOrBuilder.getInt32ToStringFieldCount());
+ assertEquals(0, testMapOrBuilder.getInt32ToBytesField().size());
+ assertEquals(0, testMapOrBuilder.getInt32ToBytesFieldCount());
+ assertEquals(0, testMapOrBuilder.getInt32ToEnumField().size());
+ assertEquals(0, testMapOrBuilder.getInt32ToEnumFieldCount());
+ assertEquals(0, testMapOrBuilder.getInt32ToMessageField().size());
+ assertEquals(0, testMapOrBuilder.getInt32ToMessageFieldCount());
+ assertEquals(0, testMapOrBuilder.getStringToInt32Field().size());
+ assertEquals(0, testMapOrBuilder.getStringToInt32FieldCount());
+ }
+
+ public void testSanityCopyOnWrite() throws InvalidProtocolBufferException {
+ // Since builders are implemented as a thin wrapper around a message
+ // instance, we attempt to verify that we can't cause the builder to modify
+ // a produced message.
+
+ TestMap.Builder builder = TestMap.newBuilder();
+ TestMap message = builder.build();
+ builder.putInt32ToInt32Field(1, 2);
+ assertTrue(message.getInt32ToInt32Field().isEmpty());
+ message = builder.build();
+ assertEquals(newMap(1, 2), message.getInt32ToInt32Field());
+ assertEquals(newMap(1, 2), builder.getInt32ToInt32Field());
+ builder.putInt32ToInt32Field(2, 3);
+ assertEquals(newMap(1, 2), message.getInt32ToInt32Field());
+ assertEquals(newMap(1, 2, 2, 3), builder.getInt32ToInt32Field());
+ }
+
+ public void testGetMapIsImmutable() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ assertMapsAreImmutable(builder);
+ assertMapsAreImmutable(builder.build());
+
+ setMapValues(builder);
+ assertMapsAreImmutable(builder);
+ assertMapsAreImmutable(builder.build());
+ }
+
+ private void assertMapsAreImmutable(TestMapOrBuilder testMapOrBuilder) {
+ assertImmutable(testMapOrBuilder.getInt32ToInt32Field(), 1, 2);
+ assertImmutable(testMapOrBuilder.getInt32ToStringField(), 1, "2");
+ assertImmutable(testMapOrBuilder.getInt32ToBytesField(), 1, TestUtil.toBytes("2"));
+ assertImmutable(testMapOrBuilder.getInt32ToEnumField(), 1, TestMap.EnumValue.FOO);
+ assertImmutable(
+ testMapOrBuilder.getInt32ToMessageField(), 1, MessageValue.getDefaultInstance());
+ assertImmutable(testMapOrBuilder.getStringToInt32Field(), "1", 2);
+ }
+
+ private <K, V> void assertImmutable(Map<K, V> map, K key, V value) {
+ try {
+ map.put(key, value);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ if (!map.isEmpty()) {
+ try {
+ map.entrySet().remove(map.entrySet().iterator().next());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+ }
+
+ public void testMutableMapLifecycle() {
+ TestMap.Builder builder = TestMap.newBuilder()
+ .putInt32ToInt32Field(1, 2);
+ assertEquals(newMap(1, 2), builder.build().getInt32ToInt32Field());
+ assertEquals(newMap(1, 2), builder.getInt32ToInt32Field());
+ builder.putInt32ToInt32Field(2, 3);
+ assertEquals(newMap(1, 2, 2, 3), builder.getInt32ToInt32Field());
+
+ builder.putInt32ToEnumField(1, TestMap.EnumValue.BAR);
+ assertEquals(newMap(1, TestMap.EnumValue.BAR), builder.build().getInt32ToEnumField());
+ assertEquals(newMap(1, TestMap.EnumValue.BAR), builder.getInt32ToEnumField());
+ builder.putInt32ToEnumField(2, TestMap.EnumValue.FOO);
+ assertEquals(
+ newMap(1, TestMap.EnumValue.BAR, 2, TestMap.EnumValue.FOO),
+ builder.getInt32ToEnumField());
+
+ builder.putInt32ToStringField(1, "1");
+ assertEquals(newMap(1, "1"), builder.build().getInt32ToStringField());
+ assertEquals(newMap(1, "1"), builder.getInt32ToStringField());
+ builder.putInt32ToStringField(2, "2");
+ assertEquals(newMap(1, "1", 2, "2"), builder.getInt32ToStringField());
+
+ builder.putInt32ToMessageField(1, TestMap.MessageValue.getDefaultInstance());
+ assertEquals(newMap(1, TestMap.MessageValue.getDefaultInstance()),
+ builder.build().getInt32ToMessageField());
+ assertEquals(newMap(1, TestMap.MessageValue.getDefaultInstance()),
+ builder.getInt32ToMessageField());
+ builder.putInt32ToMessageField(2, TestMap.MessageValue.getDefaultInstance());
+ assertEquals(
+ newMap(1, TestMap.MessageValue.getDefaultInstance(),
+ 2, TestMap.MessageValue.getDefaultInstance()),
+ builder.getInt32ToMessageField());
+ }
+
+ public void testGettersAndSetters() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ TestMap message = builder.build();
+ assertMapValuesCleared(message);
+
+ builder = message.toBuilder();
+ setMapValues(builder);
+ message = builder.build();
+ assertMapValuesSet(message);
+
+ builder = message.toBuilder();
+ updateMapValues(builder);
+ message = builder.build();
+ assertMapValuesUpdated(message);
+
+ builder = message.toBuilder();
+ builder.clear();
+ assertMapValuesCleared(builder);
+ message = builder.build();
+ assertMapValuesCleared(message);
+ }
+
+ public void testPutAll() throws Exception {
+ TestMap.Builder sourceBuilder = TestMap.newBuilder();
+ setMapValues(sourceBuilder);
+ TestMap source = sourceBuilder.build();
+ assertMapValuesSet(source);
+
+ TestMap.Builder destination = TestMap.newBuilder();
+ copyMapValues(source, destination);
+ assertMapValuesSet(destination.build());
+ }
+
+ public void testPutChecksNullKeysAndValues() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+
+ try {
+ builder.putInt32ToStringField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected.
+ }
+
+ try {
+ builder.putInt32ToBytesField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected.
+ }
+
+ try {
+ builder.putInt32ToEnumField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected.
+ }
+
+ try {
+ builder.putInt32ToMessageField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected.
+ }
+
+ try {
+ builder.putStringToInt32Field(null, 1);
+ fail();
+ } catch (NullPointerException e) {
+ // expected.
+ }
+ }
+
+ public void testSerializeAndParse() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValues(builder);
+ TestMap message = builder.build();
+ assertEquals(message.getSerializedSize(), message.toByteString().size());
+ message = TestMap.parser().parseFrom(message.toByteString());
+ assertMapValuesSet(message);
+
+ builder = message.toBuilder();
+ updateMapValues(builder);
+ message = builder.build();
+ assertEquals(message.getSerializedSize(), message.toByteString().size());
+ message = TestMap.parser().parseFrom(message.toByteString());
+ assertMapValuesUpdated(message);
+
+ builder = message.toBuilder();
+ builder.clear();
+ message = builder.build();
+ assertEquals(message.getSerializedSize(), message.toByteString().size());
+ message = TestMap.parser().parseFrom(message.toByteString());
+ assertMapValuesCleared(message);
+ }
+
+ private TestMap tryParseTestMap(BizarroTestMap bizarroMap) throws IOException {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ CodedOutputStream output = CodedOutputStream.newInstance(byteArrayOutputStream);
+ bizarroMap.writeTo(output);
+ output.flush();
+ return TestMap.parser().parseFrom(ByteString.copyFrom(byteArrayOutputStream.toByteArray()));
+ }
+
+ public void testParseError() throws Exception {
+ ByteString bytes = TestUtil.toBytes("SOME BYTES");
+ String stringKey = "a string key";
+
+ TestMap map = tryParseTestMap(BizarroTestMap.newBuilder()
+ .putInt32ToInt32Field(5, bytes)
+ .build());
+ assertEquals(map.getInt32ToInt32FieldOrDefault(5, -1), 0);
+
+ map = tryParseTestMap(BizarroTestMap.newBuilder()
+ .putInt32ToStringField(stringKey, 5)
+ .build());
+ assertEquals(map.getInt32ToStringFieldOrDefault(0, null), "");
+
+ map = tryParseTestMap(BizarroTestMap.newBuilder()
+ .putInt32ToBytesField(stringKey, 5)
+ .build());
+ assertEquals(map.getInt32ToBytesFieldOrDefault(0, null), ByteString.EMPTY);
+
+ map = tryParseTestMap(BizarroTestMap.newBuilder()
+ .putInt32ToEnumField(stringKey, bytes)
+ .build());
+ assertEquals(map.getInt32ToEnumFieldOrDefault(0, null), TestMap.EnumValue.FOO);
+
+ try {
+ tryParseTestMap(BizarroTestMap.newBuilder()
+ .putInt32ToMessageField(stringKey, bytes)
+ .build());
+ fail();
+ } catch (InvalidProtocolBufferException expected) {
+ assertTrue(expected.getUnfinishedMessage() instanceof TestMap);
+ map = (TestMap) expected.getUnfinishedMessage();
+ assertTrue(map.getInt32ToMessageField().isEmpty());
+ }
+
+ map = tryParseTestMap(BizarroTestMap.newBuilder()
+ .putStringToInt32Field(stringKey, bytes)
+ .build());
+ assertEquals(map.getStringToInt32FieldOrDefault(stringKey, -1), 0);
+ }
+
+ public void testMergeFrom() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValues(builder);
+ TestMap message = builder.build();
+
+ TestMap.Builder other = TestMap.newBuilder();
+ other.mergeFrom(message);
+ assertMapValuesSet(other.build());
+ }
+
+ public void testEqualsAndHashCode() throws Exception {
+ // Test that generated equals() and hashCode() will disregard the order
+ // of map entries when comparing/hashing map fields.
+
+ // We can't control the order of elements in a HashMap. The best we can do
+ // here is to add elements in different order.
+ TestMap.Builder b1 = TestMap.newBuilder()
+ .putInt32ToInt32Field(1, 2)
+ .putInt32ToInt32Field(3, 4)
+ .putInt32ToInt32Field(5, 6);
+ TestMap m1 = b1.build();
+
+ TestMap.Builder b2 = TestMap.newBuilder()
+ .putInt32ToInt32Field(5, 6)
+ .putInt32ToInt32Field(1, 2)
+ .putInt32ToInt32Field(3, 4);
+ TestMap m2 = b2.build();
+
+ assertEquals(m1, m2);
+ assertEquals(m1.hashCode(), m2.hashCode());
+
+ // Make sure we did compare map fields.
+ b2.putInt32ToInt32Field(1, 0);
+ m2 = b2.build();
+ assertFalse(m1.equals(m2));
+ // Don't check m1.hashCode() != m2.hashCode() because it's not guaranteed
+ // to be different.
+ }
+
+ public void testUnknownEnumValues() throws Exception {
+ TestUnknownEnumValue.Builder builder = TestUnknownEnumValue.newBuilder()
+ .putInt32ToInt32Field(1, 1)
+ .putInt32ToInt32Field(2, 54321);
+ ByteString data = builder.build().toByteString();
+
+ TestMap message = TestMap.parseFrom(data);
+ // Entries with unknown enum values will be stored into UnknownFieldSet so
+ // there is only one entry in the map.
+ assertEquals(1, message.getInt32ToEnumField().size());
+ assertEquals(TestMap.EnumValue.BAR, message.getInt32ToEnumField().get(1));
+ // Serializing and parsing should preserve the unknown entry.
+ data = message.toByteString();
+ TestUnknownEnumValue messageWithUnknownEnums =
+ TestUnknownEnumValue.parseFrom(data);
+ assertEquals(2, messageWithUnknownEnums.getInt32ToInt32Field().size());
+ assertEquals(1, messageWithUnknownEnums.getInt32ToInt32Field().get(1).intValue());
+ assertEquals(54321, messageWithUnknownEnums.getInt32ToInt32Field().get(2).intValue());
+ }
+
+ public void testIterationOrder() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValues(builder);
+ TestMap message = builder.build();
+
+ assertEquals(Arrays.asList("1", "2", "3"),
+ new ArrayList<String>(message.getStringToInt32Field().keySet()));
+ }
+
+ private static <K, V> Map<K, V> newMap(K key1, V value1) {
+ Map<K, V> map = new HashMap<K, V>();
+ map.put(key1, value1);
+ return map;
+ }
+
+ private static <K, V> Map<K, V> newMap(K key1, V value1, K key2, V value2) {
+ Map<K, V> map = new HashMap<K, V>();
+ map.put(key1, value1);
+ map.put(key2, value2);
+ return map;
+ }
+
+ public void testGetMap() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValues(builder);
+ TestMap message = builder.build();
+ assertEquals(
+ message.getStringToInt32Field(),
+ message.getStringToInt32FieldMap());
+ assertEquals(
+ message.getInt32ToBytesField(),
+ message.getInt32ToBytesFieldMap());
+ assertEquals(
+ message.getInt32ToEnumField(),
+ message.getInt32ToEnumFieldMap());
+ assertEquals(
+ message.getInt32ToMessageField(),
+ message.getInt32ToMessageFieldMap());
+ }
+
+ public void testContains() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValues(builder);
+ assertMapContainsSetValues(builder);
+ assertMapContainsSetValues(builder.build());
+ }
+
+ private void assertMapContainsSetValues(TestMapOrBuilder testMapOrBuilder) {
+ assertTrue(testMapOrBuilder.containsInt32ToInt32Field(1));
+ assertTrue(testMapOrBuilder.containsInt32ToInt32Field(2));
+ assertTrue(testMapOrBuilder.containsInt32ToInt32Field(3));
+ assertFalse(testMapOrBuilder.containsInt32ToInt32Field(-1));
+
+ assertTrue(testMapOrBuilder.containsInt32ToStringField(1));
+ assertTrue(testMapOrBuilder.containsInt32ToStringField(2));
+ assertTrue(testMapOrBuilder.containsInt32ToStringField(3));
+ assertFalse(testMapOrBuilder.containsInt32ToStringField(-1));
+
+ assertTrue(testMapOrBuilder.containsInt32ToBytesField(1));
+ assertTrue(testMapOrBuilder.containsInt32ToBytesField(2));
+ assertTrue(testMapOrBuilder.containsInt32ToBytesField(3));
+ assertFalse(testMapOrBuilder.containsInt32ToBytesField(-1));
+
+ assertTrue(testMapOrBuilder.containsInt32ToEnumField(1));
+ assertTrue(testMapOrBuilder.containsInt32ToEnumField(2));
+ assertTrue(testMapOrBuilder.containsInt32ToEnumField(3));
+ assertFalse(testMapOrBuilder.containsInt32ToEnumField(-1));
+
+ assertTrue(testMapOrBuilder.containsInt32ToMessageField(1));
+ assertTrue(testMapOrBuilder.containsInt32ToMessageField(2));
+ assertTrue(testMapOrBuilder.containsInt32ToMessageField(3));
+ assertFalse(testMapOrBuilder.containsInt32ToMessageField(-1));
+
+ assertTrue(testMapOrBuilder.containsStringToInt32Field("1"));
+ assertTrue(testMapOrBuilder.containsStringToInt32Field("2"));
+ assertTrue(testMapOrBuilder.containsStringToInt32Field("3"));
+ assertFalse(testMapOrBuilder.containsStringToInt32Field("-1"));
+ }
+
+ public void testCount() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ assertMapCounts(0, builder);
+
+ setMapValues(builder);
+ assertMapCounts(3, builder);
+
+ TestMap message = builder.build();
+ assertMapCounts(3, message);
+
+ builder = message.toBuilder().putInt32ToInt32Field(4, 44);
+ assertEquals(4, builder.getInt32ToInt32FieldCount());
+ assertEquals(4, builder.build().getInt32ToInt32FieldCount());
+
+ // already present - should be unchanged
+ builder.putInt32ToInt32Field(4, 44);
+ assertEquals(4, builder.getInt32ToInt32FieldCount());
+ }
+
+ private void assertMapCounts(int expectedCount, TestMapOrBuilder testMapOrBuilder) {
+ assertEquals(expectedCount, testMapOrBuilder.getInt32ToInt32FieldCount());
+ assertEquals(expectedCount, testMapOrBuilder.getInt32ToStringFieldCount());
+ assertEquals(expectedCount, testMapOrBuilder.getInt32ToBytesFieldCount());
+ assertEquals(expectedCount, testMapOrBuilder.getInt32ToEnumFieldCount());
+ assertEquals(expectedCount, testMapOrBuilder.getInt32ToMessageFieldCount());
+ assertEquals(expectedCount, testMapOrBuilder.getStringToInt32FieldCount());
+ }
+
+ public void testGetOrDefault() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ assertMapCounts(0, builder);
+ setMapValues(builder);
+ doTestGetOrDefault(builder);
+ doTestGetOrDefault(builder.build());
+ }
+
+ public void doTestGetOrDefault(TestMapOrBuilder testMapOrBuilder) {
+ assertEquals(11, testMapOrBuilder.getInt32ToInt32FieldOrDefault(1, -11));
+ assertEquals(-11, testMapOrBuilder.getInt32ToInt32FieldOrDefault(-1, -11));
+
+ assertEquals("11", testMapOrBuilder.getInt32ToStringFieldOrDefault(1, "-11"));
+ assertNull("-11", testMapOrBuilder.getInt32ToStringFieldOrDefault(-1, null));
+
+ assertEquals(TestUtil.toBytes("11"), testMapOrBuilder.getInt32ToBytesFieldOrDefault(1, null));
+ assertNull(testMapOrBuilder.getInt32ToBytesFieldOrDefault(-1, null));
+
+ assertEquals(TestMap.EnumValue.FOO, testMapOrBuilder.getInt32ToEnumFieldOrDefault(1, null));
+ assertNull(testMapOrBuilder.getInt32ToEnumFieldOrDefault(-1, null));
+
+ assertEquals(MessageValue.newBuilder().setValue(11).build(),
+ testMapOrBuilder.getInt32ToMessageFieldOrDefault(1, null));
+ assertNull(testMapOrBuilder.getInt32ToMessageFieldOrDefault(-1, null));
+
+ assertEquals(11, testMapOrBuilder.getStringToInt32FieldOrDefault("1", -11));
+ assertEquals(-11, testMapOrBuilder.getStringToInt32FieldOrDefault("-1", -11));
+
+ try {
+ testMapOrBuilder.getStringToInt32FieldOrDefault(null, -11);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void testGetOrThrow() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ assertMapCounts(0, builder);
+ setMapValues(builder);
+ doTestGetOrDefault(builder);
+ doTestGetOrDefault(builder.build());
+ }
+
+ public void doTestGetOrThrow(TestMapOrBuilder testMapOrBuilder) {
+ assertEquals(11, testMapOrBuilder.getInt32ToInt32FieldOrThrow(1));
+ try {
+ testMapOrBuilder.getInt32ToInt32FieldOrThrow(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ assertEquals("11", testMapOrBuilder.getInt32ToStringFieldOrThrow(1));
+
+ try {
+ testMapOrBuilder.getInt32ToStringFieldOrThrow(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ assertEquals(TestUtil.toBytes("11"), testMapOrBuilder.getInt32ToBytesFieldOrThrow(1));
+
+ try {
+ testMapOrBuilder.getInt32ToBytesFieldOrThrow(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ assertEquals(TestMap.EnumValue.FOO, testMapOrBuilder.getInt32ToEnumFieldOrThrow(1));
+ try {
+ testMapOrBuilder.getInt32ToEnumFieldOrThrow(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ assertEquals(MessageValue.newBuilder().setValue(11).build(),
+ testMapOrBuilder.getInt32ToMessageFieldOrThrow(1));
+ try {
+ testMapOrBuilder.getInt32ToMessageFieldOrThrow(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ assertEquals(11, testMapOrBuilder.getStringToInt32FieldOrThrow("1"));
+ try {
+ testMapOrBuilder.getStringToInt32FieldOrThrow("-1");
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ testMapOrBuilder.getStringToInt32FieldOrThrow(null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void testPut() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ builder.putInt32ToInt32Field(1, 11);
+ assertEquals(11, builder.getInt32ToInt32FieldOrThrow(1));
+
+ builder.putInt32ToStringField(1, "a");
+ assertEquals("a", builder.getInt32ToStringFieldOrThrow(1));
+ try {
+ builder.putInt32ToStringField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ builder.putInt32ToBytesField(1, TestUtil.toBytes("11"));
+ assertEquals(TestUtil.toBytes("11"), builder.getInt32ToBytesFieldOrThrow(1));
+ try {
+ builder.putInt32ToBytesField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ builder.putInt32ToEnumField(1, TestMap.EnumValue.FOO);
+ assertEquals(TestMap.EnumValue.FOO, builder.getInt32ToEnumFieldOrThrow(1));
+ try {
+ builder.putInt32ToEnumField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ builder.putStringToInt32Field("a", 1);
+ assertEquals(1, builder.getStringToInt32FieldOrThrow("a"));
+ try {
+ builder.putStringToInt32Field(null, -1);
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void testRemove() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValues(builder);
+ assertEquals(11, builder.getInt32ToInt32FieldOrThrow(1));
+ for (int times = 0; times < 2; times++) {
+ builder.removeInt32ToInt32Field(1);
+ assertEquals(-1, builder.getInt32ToInt32FieldOrDefault(1, -1));
+ }
+
+ assertEquals("11", builder.getInt32ToStringFieldOrThrow(1));
+ for (int times = 0; times < 2; times++) {
+ builder.removeInt32ToStringField(1);
+ assertNull(builder.getInt32ToStringFieldOrDefault(1, null));
+ }
+
+ assertEquals(TestUtil.toBytes("11"), builder.getInt32ToBytesFieldOrThrow(1));
+ for (int times = 0; times < 2; times++) {
+ builder.removeInt32ToBytesField(1);
+ assertNull(builder.getInt32ToBytesFieldOrDefault(1, null));
+ }
+
+ assertEquals(TestMap.EnumValue.FOO, builder.getInt32ToEnumFieldOrThrow(1));
+ for (int times = 0; times < 2; times++) {
+ builder.removeInt32ToEnumField(1);
+ assertNull(builder.getInt32ToEnumFieldOrDefault(1, null));
+ }
+
+ assertEquals(11, builder.getStringToInt32FieldOrThrow("1"));
+ for (int times = 0; times < 2; times++) {
+ builder.removeStringToInt32Field("1");
+ assertEquals(-1, builder.getStringToInt32FieldOrDefault("1", -1));
+ }
+
+ try {
+ builder.removeStringToInt32Field(null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java
new file mode 100644
index 0000000000..cfe4c4536e
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/MapForProto2Test.java
@@ -0,0 +1,1178 @@
+// 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.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 java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+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.
+ */
+public class MapForProto2Test extends TestCase {
+
+ private void setMapValuesUsingMutableMap(TestMap.Builder builder) {
+ builder.getMutableInt32ToInt32Field().put(1, 11);
+ builder.getMutableInt32ToInt32Field().put(2, 22);
+ builder.getMutableInt32ToInt32Field().put(3, 33);
+ //
+ builder.getMutableInt32ToStringField().put(1, "11");
+ builder.getMutableInt32ToStringField().put(2, "22");
+ builder.getMutableInt32ToStringField().put(3, "33");
+ //
+ builder.getMutableInt32ToBytesField().put(1, TestUtil.toBytes("11"));
+ builder.getMutableInt32ToBytesField().put(2, TestUtil.toBytes("22"));
+ builder.getMutableInt32ToBytesField().put(3, TestUtil.toBytes("33"));
+ //
+ builder.getMutableInt32ToEnumField().put(1, TestMap.EnumValue.FOO);
+ builder.getMutableInt32ToEnumField().put(2, TestMap.EnumValue.BAR);
+ builder.getMutableInt32ToEnumField().put(3, TestMap.EnumValue.BAZ);
+ //
+ builder.getMutableInt32ToMessageField().put(
+ 1, MessageValue.newBuilder().setValue(11).build());
+ builder.getMutableInt32ToMessageField().put(
+ 2, MessageValue.newBuilder().setValue(22).build());
+ builder.getMutableInt32ToMessageField().put(
+ 3, MessageValue.newBuilder().setValue(33).build());
+ //
+ builder.getMutableStringToInt32Field().put("1", 11);
+ builder.getMutableStringToInt32Field().put("2", 22);
+ builder.getMutableStringToInt32Field().put("3", 33);
+ }
+
+ private void setMapValuesUsingAccessors(TestMap.Builder builder) {
+ builder
+ .putInt32ToInt32Field(1, 11)
+ .putInt32ToInt32Field(2, 22)
+ .putInt32ToInt32Field(3, 33)
+
+ .putInt32ToStringField(1, "11")
+ .putInt32ToStringField(2, "22")
+ .putInt32ToStringField(3, "33")
+
+ .putInt32ToBytesField(1, TestUtil.toBytes("11"))
+ .putInt32ToBytesField(2, TestUtil.toBytes("22"))
+ .putInt32ToBytesField(3, TestUtil.toBytes("33"))
+
+ .putInt32ToEnumField(1, TestMap.EnumValue.FOO)
+ .putInt32ToEnumField(2, TestMap.EnumValue.BAR)
+ .putInt32ToEnumField(3, TestMap.EnumValue.BAZ)
+
+ .putInt32ToMessageField(1, MessageValue.newBuilder().setValue(11).build())
+ .putInt32ToMessageField(2, MessageValue.newBuilder().setValue(22).build())
+ .putInt32ToMessageField(3, MessageValue.newBuilder().setValue(33).build())
+
+ .putStringToInt32Field("1", 11)
+ .putStringToInt32Field("2", 22)
+ .putStringToInt32Field("3", 33);
+ }
+
+ public void testSetMapValues() {
+ TestMap.Builder usingMutableMapBuilder = TestMap.newBuilder();
+ setMapValuesUsingMutableMap(usingMutableMapBuilder);
+ TestMap usingMutableMap = usingMutableMapBuilder.build();
+ assertMapValuesSet(usingMutableMap);
+
+ TestMap.Builder usingAccessorsBuilder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(usingAccessorsBuilder);
+ TestMap usingAccessors = usingAccessorsBuilder.build();
+ assertMapValuesSet(usingAccessors);
+
+ assertEquals(usingAccessors, usingMutableMap);
+ }
+
+ private void copyMapValues(TestMap source, TestMap.Builder destination) {
+ destination
+ .putAllInt32ToInt32Field(source.getInt32ToInt32Field())
+ .putAllInt32ToStringField(source.getInt32ToStringField())
+ .putAllInt32ToBytesField(source.getInt32ToBytesField())
+ .putAllInt32ToEnumField(source.getInt32ToEnumField())
+ .putAllInt32ToMessageField(source.getInt32ToMessageField())
+ .putAllStringToInt32Field(source.getStringToInt32Field());
+ }
+
+ private void assertMapValuesSet(TestMapOrBuilder message) {
+ assertEquals(3, message.getInt32ToInt32Field().size());
+ assertEquals(11, message.getInt32ToInt32Field().get(1).intValue());
+ assertEquals(22, message.getInt32ToInt32Field().get(2).intValue());
+ assertEquals(33, message.getInt32ToInt32Field().get(3).intValue());
+
+ assertEquals(3, message.getInt32ToStringField().size());
+ assertEquals("11", message.getInt32ToStringField().get(1));
+ assertEquals("22", message.getInt32ToStringField().get(2));
+ assertEquals("33", message.getInt32ToStringField().get(3));
+
+ assertEquals(3, message.getInt32ToBytesField().size());
+ assertEquals(TestUtil.toBytes("11"), message.getInt32ToBytesField().get(1));
+ assertEquals(TestUtil.toBytes("22"), message.getInt32ToBytesField().get(2));
+ assertEquals(TestUtil.toBytes("33"), message.getInt32ToBytesField().get(3));
+
+ assertEquals(3, message.getInt32ToEnumField().size());
+ assertEquals(TestMap.EnumValue.FOO, message.getInt32ToEnumField().get(1));
+ assertEquals(TestMap.EnumValue.BAR, message.getInt32ToEnumField().get(2));
+ assertEquals(TestMap.EnumValue.BAZ, message.getInt32ToEnumField().get(3));
+
+ assertEquals(3, message.getInt32ToMessageField().size());
+ assertEquals(11, message.getInt32ToMessageField().get(1).getValue());
+ assertEquals(22, message.getInt32ToMessageField().get(2).getValue());
+ assertEquals(33, message.getInt32ToMessageField().get(3).getValue());
+
+ assertEquals(3, message.getStringToInt32Field().size());
+ assertEquals(11, message.getStringToInt32Field().get("1").intValue());
+ assertEquals(22, message.getStringToInt32Field().get("2").intValue());
+ assertEquals(33, message.getStringToInt32Field().get("3").intValue());
+ }
+
+ private void updateMapValuesUsingMutableMap(TestMap.Builder builder) {
+ builder.getMutableInt32ToInt32Field().put(1, 111);
+ builder.getMutableInt32ToInt32Field().remove(2);
+ builder.getMutableInt32ToInt32Field().put(4, 44);
+ //
+ builder.getMutableInt32ToStringField().put(1, "111");
+ builder.getMutableInt32ToStringField().remove(2);
+ builder.getMutableInt32ToStringField().put(4, "44");
+ //
+ builder.getMutableInt32ToBytesField().put(1, TestUtil.toBytes("111"));
+ builder.getMutableInt32ToBytesField().remove(2);
+ builder.getMutableInt32ToBytesField().put(4, TestUtil.toBytes("44"));
+ //
+ builder.getMutableInt32ToEnumField().put(1, TestMap.EnumValue.BAR);
+ builder.getMutableInt32ToEnumField().remove(2);
+ builder.getMutableInt32ToEnumField().put(4, TestMap.EnumValue.QUX);
+ //
+ builder.getMutableInt32ToMessageField().put(
+ 1, MessageValue.newBuilder().setValue(111).build());
+ builder.getMutableInt32ToMessageField().remove(2);
+ builder.getMutableInt32ToMessageField().put(
+ 4, MessageValue.newBuilder().setValue(44).build());
+ //
+ builder.getMutableStringToInt32Field().put("1", 111);
+ builder.getMutableStringToInt32Field().remove("2");
+ builder.getMutableStringToInt32Field().put("4", 44);
+ }
+
+ private void updateMapValuesUsingAccessors(TestMap.Builder builder) {
+ builder
+ .putInt32ToInt32Field(1, 111)
+ .removeInt32ToInt32Field(2)
+ .putInt32ToInt32Field(4, 44)
+
+ .putInt32ToStringField(1, "111")
+ .removeInt32ToStringField(2)
+ .putInt32ToStringField(4, "44")
+
+ .putInt32ToBytesField(1, TestUtil.toBytes("111"))
+ .removeInt32ToBytesField(2)
+ .putInt32ToBytesField(4, TestUtil.toBytes("44"))
+
+ .putInt32ToEnumField(1, TestMap.EnumValue.BAR)
+ .removeInt32ToEnumField(2)
+ .putInt32ToEnumField(4, TestMap.EnumValue.QUX)
+
+ .putInt32ToMessageField(1, MessageValue.newBuilder().setValue(111).build())
+ .removeInt32ToMessageField(2)
+ .putInt32ToMessageField(4, MessageValue.newBuilder().setValue(44).build())
+
+ .putStringToInt32Field("1", 111)
+ .removeStringToInt32Field("2")
+ .putStringToInt32Field("4", 44);
+ }
+
+ public void testUpdateMapValues() {
+ TestMap.Builder usingMutableMapBuilder = TestMap.newBuilder();
+ setMapValuesUsingMutableMap(usingMutableMapBuilder);
+ TestMap usingMutableMap = usingMutableMapBuilder.build();
+ assertMapValuesSet(usingMutableMap);
+
+ TestMap.Builder usingAccessorsBuilder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(usingAccessorsBuilder);
+ TestMap usingAccessors = usingAccessorsBuilder.build();
+ assertMapValuesSet(usingAccessors);
+
+ assertEquals(usingAccessors, usingMutableMap);
+ //
+ usingMutableMapBuilder = usingMutableMap.toBuilder();
+ updateMapValuesUsingMutableMap(usingMutableMapBuilder);
+ usingMutableMap = usingMutableMapBuilder.build();
+ assertMapValuesUpdated(usingMutableMap);
+
+ usingAccessorsBuilder = usingAccessors.toBuilder();
+ updateMapValuesUsingAccessors(usingAccessorsBuilder);
+ usingAccessors = usingAccessorsBuilder.build();
+ assertMapValuesUpdated(usingAccessors);
+
+ assertEquals(usingAccessors, usingMutableMap);
+ }
+
+ private void assertMapValuesUpdated(TestMap message) {
+ assertEquals(3, message.getInt32ToInt32Field().size());
+ assertEquals(111, message.getInt32ToInt32Field().get(1).intValue());
+ assertEquals(33, message.getInt32ToInt32Field().get(3).intValue());
+ assertEquals(44, message.getInt32ToInt32Field().get(4).intValue());
+
+ assertEquals(3, message.getInt32ToStringField().size());
+ assertEquals("111", message.getInt32ToStringField().get(1));
+ assertEquals("33", message.getInt32ToStringField().get(3));
+ assertEquals("44", message.getInt32ToStringField().get(4));
+
+ assertEquals(3, message.getInt32ToBytesField().size());
+ assertEquals(TestUtil.toBytes("111"), message.getInt32ToBytesField().get(1));
+ assertEquals(TestUtil.toBytes("33"), message.getInt32ToBytesField().get(3));
+ assertEquals(TestUtil.toBytes("44"), message.getInt32ToBytesField().get(4));
+
+ assertEquals(3, message.getInt32ToEnumField().size());
+ assertEquals(TestMap.EnumValue.BAR, message.getInt32ToEnumField().get(1));
+ assertEquals(TestMap.EnumValue.BAZ, message.getInt32ToEnumField().get(3));
+ assertEquals(TestMap.EnumValue.QUX, message.getInt32ToEnumField().get(4));
+
+ assertEquals(3, message.getInt32ToMessageField().size());
+ assertEquals(111, message.getInt32ToMessageField().get(1).getValue());
+ assertEquals(33, message.getInt32ToMessageField().get(3).getValue());
+ assertEquals(44, message.getInt32ToMessageField().get(4).getValue());
+
+ assertEquals(3, message.getStringToInt32Field().size());
+ assertEquals(111, message.getStringToInt32Field().get("1").intValue());
+ assertEquals(33, message.getStringToInt32Field().get("3").intValue());
+ assertEquals(44, message.getStringToInt32Field().get("4").intValue());
+ }
+
+ private void assertMapValuesCleared(TestMapOrBuilder testMapOrBuilder) {
+ assertEquals(0, testMapOrBuilder.getInt32ToInt32Field().size());
+ assertEquals(0, testMapOrBuilder.getInt32ToInt32FieldCount());
+ assertEquals(0, testMapOrBuilder.getInt32ToStringField().size());
+ assertEquals(0, testMapOrBuilder.getInt32ToStringFieldCount());
+ assertEquals(0, testMapOrBuilder.getInt32ToBytesField().size());
+ assertEquals(0, testMapOrBuilder.getInt32ToBytesFieldCount());
+ assertEquals(0, testMapOrBuilder.getInt32ToEnumField().size());
+ assertEquals(0, testMapOrBuilder.getInt32ToEnumFieldCount());
+ assertEquals(0, testMapOrBuilder.getInt32ToMessageField().size());
+ assertEquals(0, testMapOrBuilder.getInt32ToMessageFieldCount());
+ assertEquals(0, testMapOrBuilder.getStringToInt32Field().size());
+ assertEquals(0, testMapOrBuilder.getStringToInt32FieldCount());
+ }
+
+ public void testGetMapIsImmutable() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ assertMapsAreImmutable(builder);
+ assertMapsAreImmutable(builder.build());
+
+ setMapValuesUsingAccessors(builder);
+ assertMapsAreImmutable(builder);
+ assertMapsAreImmutable(builder.build());
+ }
+
+ private void assertMapsAreImmutable(TestMapOrBuilder testMapOrBuilder) {
+ assertImmutable(testMapOrBuilder.getInt32ToInt32Field(), 1, 2);
+ assertImmutable(testMapOrBuilder.getInt32ToStringField(), 1, "2");
+ assertImmutable(testMapOrBuilder.getInt32ToBytesField(), 1, TestUtil.toBytes("2"));
+ assertImmutable(testMapOrBuilder.getInt32ToEnumField(), 1, TestMap.EnumValue.FOO);
+ assertImmutable(
+ testMapOrBuilder.getInt32ToMessageField(), 1, MessageValue.getDefaultInstance());
+ assertImmutable(testMapOrBuilder.getStringToInt32Field(), "1", 2);
+ }
+
+ private <K, V> void assertImmutable(Map<K, V> map, K key, V value) {
+ try {
+ map.put(key, value);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ public void testMutableMapLifecycle() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ Map<Integer, Integer> intMap = builder.getMutableInt32ToInt32Field();
+ intMap.put(1, 2);
+ assertEquals(newMap(1, 2), builder.build().getInt32ToInt32Field());
+ try {
+ intMap.put(2, 3);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(newMap(1, 2), builder.getInt32ToInt32Field());
+ builder.getMutableInt32ToInt32Field().put(2, 3);
+ assertEquals(newMap(1, 2, 2, 3), builder.getInt32ToInt32Field());
+ //
+ Map<Integer, TestMap.EnumValue> enumMap = builder.getMutableInt32ToEnumField();
+ enumMap.put(1, TestMap.EnumValue.BAR);
+ assertEquals(newMap(1, TestMap.EnumValue.BAR), builder.build().getInt32ToEnumField());
+ try {
+ enumMap.put(2, TestMap.EnumValue.FOO);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(newMap(1, TestMap.EnumValue.BAR), builder.getInt32ToEnumField());
+ builder.getMutableInt32ToEnumField().put(2, TestMap.EnumValue.FOO);
+ assertEquals(
+ newMap(1, TestMap.EnumValue.BAR, 2, TestMap.EnumValue.FOO),
+ builder.getInt32ToEnumField());
+ //
+ Map<Integer, String> stringMap = builder.getMutableInt32ToStringField();
+ stringMap.put(1, "1");
+ assertEquals(newMap(1, "1"), builder.build().getInt32ToStringField());
+ try {
+ stringMap.put(2, "2");
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(newMap(1, "1"), builder.getInt32ToStringField());
+ builder.getMutableInt32ToStringField().put(2, "2");
+ assertEquals(
+ newMap(1, "1", 2, "2"),
+ builder.getInt32ToStringField());
+ //
+ Map<Integer, TestMap.MessageValue> messageMap = builder.getMutableInt32ToMessageField();
+ messageMap.put(1, TestMap.MessageValue.getDefaultInstance());
+ assertEquals(newMap(1, TestMap.MessageValue.getDefaultInstance()),
+ builder.build().getInt32ToMessageField());
+ try {
+ messageMap.put(2, TestMap.MessageValue.getDefaultInstance());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(newMap(1, TestMap.MessageValue.getDefaultInstance()),
+ builder.getInt32ToMessageField());
+ builder.getMutableInt32ToMessageField().put(2, TestMap.MessageValue.getDefaultInstance());
+ assertEquals(
+ newMap(1, TestMap.MessageValue.getDefaultInstance(),
+ 2, TestMap.MessageValue.getDefaultInstance()),
+ builder.getInt32ToMessageField());
+ }
+ //
+ public void testMutableMapLifecycle_collections() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ Map<Integer, Integer> intMap = builder.getMutableInt32ToInt32Field();
+ intMap.put(1, 2);
+ assertEquals(newMap(1, 2), builder.build().getInt32ToInt32Field());
+ try {
+ intMap.remove(2);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ intMap.entrySet().remove(new Object());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ intMap.entrySet().iterator().remove();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ intMap.keySet().remove(new Object());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ intMap.values().remove(new Object());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ intMap.values().iterator().remove();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(newMap(1, 2), intMap);
+ assertEquals(newMap(1, 2), builder.getInt32ToInt32Field());
+ assertEquals(newMap(1, 2), builder.build().getInt32ToInt32Field());
+ }
+
+
+ public void testGettersAndSetters() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ TestMap message = builder.build();
+ assertMapValuesCleared(message);
+
+ builder = message.toBuilder();
+ setMapValuesUsingAccessors(builder);
+ message = builder.build();
+ assertMapValuesSet(message);
+
+ builder = message.toBuilder();
+ updateMapValuesUsingAccessors(builder);
+ message = builder.build();
+ assertMapValuesUpdated(message);
+
+ builder = message.toBuilder();
+ builder.clear();
+ assertMapValuesCleared(builder);
+ message = builder.build();
+ assertMapValuesCleared(message);
+ }
+
+ public void testPutAll() throws Exception {
+ TestMap.Builder sourceBuilder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(sourceBuilder);
+ TestMap source = sourceBuilder.build();
+ assertMapValuesSet(source);
+
+ TestMap.Builder destination = TestMap.newBuilder();
+ copyMapValues(source, destination);
+ assertMapValuesSet(destination.build());
+
+ assertEquals(3, destination.getInt32ToEnumFieldCount());
+ }
+
+ public void testPutChecksNullKeysAndValues() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+
+ try {
+ builder.putInt32ToStringField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected.
+ }
+
+ try {
+ builder.putInt32ToBytesField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected.
+ }
+
+ try {
+ builder.putInt32ToEnumField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected.
+ }
+
+ try {
+ builder.putInt32ToMessageField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected.
+ }
+
+ try {
+ builder.putStringToInt32Field(null, 1);
+ fail();
+ } catch (NullPointerException e) {
+ // expected.
+ }
+ }
+
+ public void testSerializeAndParse() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(builder);
+ TestMap message = builder.build();
+ assertEquals(message.getSerializedSize(), message.toByteString().size());
+ message = TestMap.parser().parseFrom(message.toByteString());
+ assertMapValuesSet(message);
+
+ builder = message.toBuilder();
+ updateMapValuesUsingAccessors(builder);
+ message = builder.build();
+ assertEquals(message.getSerializedSize(), message.toByteString().size());
+ message = TestMap.parser().parseFrom(message.toByteString());
+ assertMapValuesUpdated(message);
+
+ builder = message.toBuilder();
+ builder.clear();
+ message = builder.build();
+ assertEquals(message.getSerializedSize(), message.toByteString().size());
+ message = TestMap.parser().parseFrom(message.toByteString());
+ assertMapValuesCleared(message);
+ }
+
+ private TestMap tryParseTestMap(BizarroTestMap bizarroMap) throws IOException {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ CodedOutputStream output = CodedOutputStream.newInstance(byteArrayOutputStream);
+ bizarroMap.writeTo(output);
+ output.flush();
+ return TestMap.parser().parseFrom(ByteString.copyFrom(byteArrayOutputStream.toByteArray()));
+ }
+
+ public void testParseError() throws Exception {
+ ByteString bytes = TestUtil.toBytes("SOME BYTES");
+ String stringKey = "a string key";
+
+ TestMap map = tryParseTestMap(BizarroTestMap.newBuilder()
+ .putInt32ToInt32Field(5, bytes)
+ .build());
+ assertEquals(map.getInt32ToInt32FieldOrDefault(5, -1), 0);
+
+ map = tryParseTestMap(BizarroTestMap.newBuilder()
+ .putInt32ToStringField(stringKey, 5)
+ .build());
+ assertEquals(map.getInt32ToStringFieldOrDefault(0, null), "");
+
+ map = tryParseTestMap(BizarroTestMap.newBuilder()
+ .putInt32ToBytesField(stringKey, 5)
+ .build());
+ assertEquals(map.getInt32ToBytesFieldOrDefault(0, null), ByteString.EMPTY);
+
+ map = tryParseTestMap(BizarroTestMap.newBuilder()
+ .putInt32ToEnumField(stringKey, bytes)
+ .build());
+ assertEquals(map.getInt32ToEnumFieldOrDefault(0, null), TestMap.EnumValue.FOO);
+
+ try {
+ tryParseTestMap(BizarroTestMap.newBuilder()
+ .putInt32ToMessageField(stringKey, bytes)
+ .build());
+ fail();
+ } catch (InvalidProtocolBufferException expected) {
+ assertTrue(expected.getUnfinishedMessage() instanceof TestMap);
+ map = (TestMap) expected.getUnfinishedMessage();
+ assertTrue(map.getInt32ToMessageField().isEmpty());
+ }
+
+ map = tryParseTestMap(BizarroTestMap.newBuilder()
+ .putStringToInt32Field(stringKey, bytes)
+ .build());
+ assertEquals(map.getStringToInt32FieldOrDefault(stringKey, -1), 0);
+ }
+
+ public void testMergeFrom() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(builder);
+ TestMap message = builder.build();
+
+ TestMap.Builder other = TestMap.newBuilder();
+ other.mergeFrom(message);
+ assertMapValuesSet(other.build());
+ }
+
+ public void testEqualsAndHashCode() throws Exception {
+ // Test that generated equals() and hashCode() will disregard the order
+ // of map entries when comparing/hashing map fields.
+
+ // We can't control the order of elements in a HashMap. The best we can do
+ // here is to add elements in different order.
+ TestMap.Builder b1 = TestMap.newBuilder();
+ b1.putInt32ToInt32Field(1, 2);
+ b1.putInt32ToInt32Field(3, 4);
+ b1.putInt32ToInt32Field(5, 6);
+ TestMap m1 = b1.build();
+
+ TestMap.Builder b2 = TestMap.newBuilder();
+ b2.putInt32ToInt32Field(5, 6);
+ b2.putInt32ToInt32Field(1, 2);
+ b2.putInt32ToInt32Field(3, 4);
+ TestMap m2 = b2.build();
+
+ assertEquals(m1, m2);
+ assertEquals(m1.hashCode(), m2.hashCode());
+
+ // Make sure we did compare map fields.
+ b2.putInt32ToInt32Field(1, 0);
+ m2 = b2.build();
+ assertFalse(m1.equals(m2));
+ // Don't check m1.hashCode() != m2.hashCode() because it's not guaranteed
+ // to be different.
+ }
+
+
+ // The following methods are used to test reflection API.
+
+ private static FieldDescriptor f(String name) {
+ return TestMap.getDescriptor().findFieldByName(name);
+ }
+
+ private static Object getFieldValue(Message mapEntry, String name) {
+ FieldDescriptor field = mapEntry.getDescriptorForType().findFieldByName(name);
+ return mapEntry.getField(field);
+ }
+
+ private static Message.Builder setFieldValue(
+ Message.Builder mapEntry, String name, Object value) {
+ FieldDescriptor field = mapEntry.getDescriptorForType().findFieldByName(name);
+ mapEntry.setField(field, value);
+ return mapEntry;
+ }
+
+ private static void assertHasMapValues(Message message, String name, Map<?, ?> values) {
+ FieldDescriptor field = f(name);
+ for (Object entry : (List<?>) message.getField(field)) {
+ Message mapEntry = (Message) entry;
+ Object key = getFieldValue(mapEntry, "key");
+ Object value = getFieldValue(mapEntry, "value");
+ assertTrue(values.containsKey(key));
+ assertEquals(value, values.get(key));
+ }
+ assertEquals(values.size(), message.getRepeatedFieldCount(field));
+ for (int i = 0; i < message.getRepeatedFieldCount(field); i++) {
+ Message mapEntry = (Message) message.getRepeatedField(field, i);
+ Object key = getFieldValue(mapEntry, "key");
+ Object value = getFieldValue(mapEntry, "value");
+ assertTrue(values.containsKey(key));
+ assertEquals(value, values.get(key));
+ }
+ }
+
+ private static <KeyType, ValueType>
+ Message newMapEntry(Message.Builder builder, String name, KeyType key, ValueType value) {
+ FieldDescriptor field = builder.getDescriptorForType().findFieldByName(name);
+ Message.Builder entryBuilder = builder.newBuilderForField(field);
+ FieldDescriptor keyField = entryBuilder.getDescriptorForType().findFieldByName("key");
+ FieldDescriptor valueField = entryBuilder.getDescriptorForType().findFieldByName("value");
+ entryBuilder.setField(keyField, key);
+ entryBuilder.setField(valueField, value);
+ return entryBuilder.build();
+ }
+
+ private static void setMapValues(Message.Builder builder, String name, Map<?, ?> values) {
+ List<Message> entryList = new ArrayList<Message>();
+ for (Map.Entry<?, ?> entry : values.entrySet()) {
+ entryList.add(newMapEntry(builder, name, entry.getKey(), entry.getValue()));
+ }
+ FieldDescriptor field = builder.getDescriptorForType().findFieldByName(name);
+ builder.setField(field, entryList);
+ }
+
+ private static <KeyType, ValueType> Map<KeyType, ValueType> mapForValues(
+ KeyType key1, ValueType value1, KeyType key2, ValueType value2) {
+ Map<KeyType, ValueType> map = new HashMap<KeyType, ValueType>();
+ map.put(key1, value1);
+ map.put(key2, value2);
+ return map;
+ }
+
+ public void testReflectionApi() throws Exception {
+ // In reflection API, map fields are just repeated message fields.
+ TestMap.Builder builder = TestMap.newBuilder()
+ .putInt32ToInt32Field(1, 2)
+ .putInt32ToInt32Field(3, 4)
+ .putInt32ToMessageField(11, MessageValue.newBuilder().setValue(22).build())
+ .putInt32ToMessageField(33, MessageValue.newBuilder().setValue(44).build());
+ TestMap message = builder.build();
+
+ // Test getField(), getRepeatedFieldCount(), getRepeatedField().
+ assertHasMapValues(message, "int32_to_int32_field",
+ mapForValues(1, 2, 3, 4));
+ assertHasMapValues(message, "int32_to_message_field",
+ mapForValues(
+ 11, MessageValue.newBuilder().setValue(22).build(),
+ 33, MessageValue.newBuilder().setValue(44).build()));
+
+ // Test clearField()
+ builder.clearField(f("int32_to_int32_field"));
+ builder.clearField(f("int32_to_message_field"));
+ message = builder.build();
+ assertEquals(0, message.getInt32ToInt32Field().size());
+ assertEquals(0, message.getInt32ToMessageField().size());
+
+ // Test setField()
+ setMapValues(builder, "int32_to_int32_field",
+ mapForValues(11, 22, 33, 44));
+ setMapValues(builder, "int32_to_message_field",
+ mapForValues(
+ 111, MessageValue.newBuilder().setValue(222).build(),
+ 333, MessageValue.newBuilder().setValue(444).build()));
+ message = builder.build();
+ assertEquals(22, message.getInt32ToInt32Field().get(11).intValue());
+ assertEquals(44, message.getInt32ToInt32Field().get(33).intValue());
+ assertEquals(222, message.getInt32ToMessageField().get(111).getValue());
+ assertEquals(444, message.getInt32ToMessageField().get(333).getValue());
+
+ // Test addRepeatedField
+ builder.addRepeatedField(f("int32_to_int32_field"),
+ newMapEntry(builder, "int32_to_int32_field", 55, 66));
+ builder.addRepeatedField(f("int32_to_message_field"),
+ newMapEntry(builder, "int32_to_message_field", 555,
+ MessageValue.newBuilder().setValue(666).build()));
+ message = builder.build();
+ assertEquals(66, message.getInt32ToInt32Field().get(55).intValue());
+ assertEquals(666, message.getInt32ToMessageField().get(555).getValue());
+
+ // Test addRepeatedField (overriding existing values)
+ builder.addRepeatedField(f("int32_to_int32_field"),
+ newMapEntry(builder, "int32_to_int32_field", 55, 55));
+ builder.addRepeatedField(f("int32_to_message_field"),
+ newMapEntry(builder, "int32_to_message_field", 555,
+ MessageValue.newBuilder().setValue(555).build()));
+ message = builder.build();
+ assertEquals(55, message.getInt32ToInt32Field().get(55).intValue());
+ assertEquals(555, message.getInt32ToMessageField().get(555).getValue());
+
+ // Test setRepeatedField
+ for (int i = 0; i < builder.getRepeatedFieldCount(f("int32_to_int32_field")); i++) {
+ Message mapEntry = (Message) builder.getRepeatedField(f("int32_to_int32_field"), i);
+ int oldKey = ((Integer) getFieldValue(mapEntry, "key")).intValue();
+ int oldValue = ((Integer) getFieldValue(mapEntry, "value")).intValue();
+ // Swap key with value for each entry.
+ Message.Builder mapEntryBuilder = mapEntry.toBuilder();
+ setFieldValue(mapEntryBuilder, "key", oldValue);
+ setFieldValue(mapEntryBuilder, "value", oldKey);
+ builder.setRepeatedField(f("int32_to_int32_field"), i, mapEntryBuilder.build());
+ }
+ message = builder.build();
+ assertEquals(11, message.getInt32ToInt32Field().get(22).intValue());
+ assertEquals(33, message.getInt32ToInt32Field().get(44).intValue());
+ assertEquals(55, message.getInt32ToInt32Field().get(55).intValue());
+ }
+
+ public void testTextFormat() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(builder);
+ TestMap message = builder.build();
+
+ String textData = TextFormat.printToString(message);
+
+ builder = TestMap.newBuilder();
+ TextFormat.merge(textData, builder);
+ message = builder.build();
+
+ assertMapValuesSet(message);
+ }
+
+ public void testDynamicMessage() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(builder);
+ TestMap message = builder.build();
+
+ Message dynamicDefaultInstance =
+ DynamicMessage.getDefaultInstance(TestMap.getDescriptor());
+ Message dynamicMessage = dynamicDefaultInstance
+ .newBuilderForType().mergeFrom(message.toByteString()).build();
+
+ assertEquals(message, dynamicMessage);
+ assertEquals(message.hashCode(), dynamicMessage.hashCode());
+ }
+
+ public void testReflectionEqualsAndHashCode() throws Exception {
+ // Test that generated equals() and hashCode() will disregard the order
+ // of map entries when comparing/hashing map fields.
+
+ // We use DynamicMessage to test reflection based equals()/hashCode().
+ Message dynamicDefaultInstance =
+ DynamicMessage.getDefaultInstance(TestMap.getDescriptor());
+ FieldDescriptor field = f("int32_to_int32_field");
+
+ Message.Builder b1 = dynamicDefaultInstance.newBuilderForType();
+ b1.addRepeatedField(field, newMapEntry(b1, "int32_to_int32_field", 1, 2));
+ b1.addRepeatedField(field, newMapEntry(b1, "int32_to_int32_field", 3, 4));
+ b1.addRepeatedField(field, newMapEntry(b1, "int32_to_int32_field", 5, 6));
+ Message m1 = b1.build();
+
+ Message.Builder b2 = dynamicDefaultInstance.newBuilderForType();
+ b2.addRepeatedField(field, newMapEntry(b2, "int32_to_int32_field", 5, 6));
+ b2.addRepeatedField(field, newMapEntry(b2, "int32_to_int32_field", 1, 2));
+ b2.addRepeatedField(field, newMapEntry(b2, "int32_to_int32_field", 3, 4));
+ Message m2 = b2.build();
+
+ assertEquals(m1, m2);
+ assertEquals(m1.hashCode(), m2.hashCode());
+
+ // Make sure we did compare map fields.
+ b2.setRepeatedField(field, 0, newMapEntry(b1, "int32_to_int32_field", 0, 0));
+ m2 = b2.build();
+ assertFalse(m1.equals(m2));
+ // Don't check m1.hashCode() != m2.hashCode() because it's not guaranteed
+ // to be different.
+ }
+
+ public void testUnknownEnumValues() throws Exception {
+ TestUnknownEnumValue.Builder builder = TestUnknownEnumValue.newBuilder()
+ .putInt32ToInt32Field(1, 1)
+ .putInt32ToInt32Field(2, 54321);
+ ByteString data = builder.build().toByteString();
+
+ TestMap message = TestMap.parseFrom(data);
+ // Entries with unknown enum values will be stored into UnknownFieldSet so
+ // there is only one entry in the map.
+ assertEquals(1, message.getInt32ToEnumField().size());
+ assertEquals(TestMap.EnumValue.BAR, message.getInt32ToEnumField().get(1));
+ // UnknownFieldSet should not be empty.
+ assertFalse(message.getUnknownFields().asMap().isEmpty());
+ // Serializing and parsing should preserve the unknown entry.
+ data = message.toByteString();
+ TestUnknownEnumValue messageWithUnknownEnums =
+ TestUnknownEnumValue.parseFrom(data);
+ assertEquals(2, messageWithUnknownEnums.getInt32ToInt32Field().size());
+ assertEquals(1, messageWithUnknownEnums.getInt32ToInt32Field().get(1).intValue());
+ assertEquals(54321, messageWithUnknownEnums.getInt32ToInt32Field().get(2).intValue());
+ }
+
+ public void testRequiredMessage() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ builder.putRequiredMessageMap(0, MessageWithRequiredFields.newBuilder().buildPartial());
+ TestMap message = builder.buildPartial();
+ assertFalse(message.isInitialized());
+
+ builder.putRequiredMessageMap(0, MessageWithRequiredFields.newBuilder().setValue(1).build());
+ message = builder.build();
+ assertTrue(message.isInitialized());
+ }
+
+ public void testRecursiveMap() throws Exception {
+ TestRecursiveMap.Builder builder = TestRecursiveMap.newBuilder();
+ builder.putRecursiveMapField(1, TestRecursiveMap.newBuilder().setValue(2).build());
+ builder.putRecursiveMapField(3, TestRecursiveMap.newBuilder().setValue(4).build());
+ ByteString data = builder.build().toByteString();
+
+ TestRecursiveMap message = TestRecursiveMap.parseFrom(data);
+ assertEquals(2, message.getRecursiveMapField().get(1).getValue());
+ assertEquals(4, message.getRecursiveMapField().get(3).getValue());
+ }
+
+ public void testIterationOrder() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(builder);
+ TestMap message = builder.build();
+
+ assertEquals(Arrays.asList("1", "2", "3"),
+ new ArrayList<String>(message.getStringToInt32Field().keySet()));
+ }
+
+ public void testContains() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(builder);
+ assertMapContainsSetValues(builder);
+ assertMapContainsSetValues(builder.build());
+ }
+
+ private void assertMapContainsSetValues(TestMapOrBuilder testMapOrBuilder) {
+ assertTrue(testMapOrBuilder.containsInt32ToInt32Field(1));
+ assertTrue(testMapOrBuilder.containsInt32ToInt32Field(2));
+ assertTrue(testMapOrBuilder.containsInt32ToInt32Field(3));
+ assertFalse(testMapOrBuilder.containsInt32ToInt32Field(-1));
+
+ assertTrue(testMapOrBuilder.containsInt32ToStringField(1));
+ assertTrue(testMapOrBuilder.containsInt32ToStringField(2));
+ assertTrue(testMapOrBuilder.containsInt32ToStringField(3));
+ assertFalse(testMapOrBuilder.containsInt32ToStringField(-1));
+
+ assertTrue(testMapOrBuilder.containsInt32ToBytesField(1));
+ assertTrue(testMapOrBuilder.containsInt32ToBytesField(2));
+ assertTrue(testMapOrBuilder.containsInt32ToBytesField(3));
+ assertFalse(testMapOrBuilder.containsInt32ToBytesField(-1));
+
+ assertTrue(testMapOrBuilder.containsInt32ToEnumField(1));
+ assertTrue(testMapOrBuilder.containsInt32ToEnumField(2));
+ assertTrue(testMapOrBuilder.containsInt32ToEnumField(3));
+ assertFalse(testMapOrBuilder.containsInt32ToEnumField(-1));
+
+ assertTrue(testMapOrBuilder.containsInt32ToMessageField(1));
+ assertTrue(testMapOrBuilder.containsInt32ToMessageField(2));
+ assertTrue(testMapOrBuilder.containsInt32ToMessageField(3));
+ assertFalse(testMapOrBuilder.containsInt32ToMessageField(-1));
+
+ assertTrue(testMapOrBuilder.containsStringToInt32Field("1"));
+ assertTrue(testMapOrBuilder.containsStringToInt32Field("2"));
+ assertTrue(testMapOrBuilder.containsStringToInt32Field("3"));
+ assertFalse(testMapOrBuilder.containsStringToInt32Field("-1"));
+ }
+
+ public void testCount() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ assertMapCounts(0, builder);
+
+ setMapValuesUsingAccessors(builder);
+ assertMapCounts(3, builder);
+
+ TestMap message = builder.build();
+ assertMapCounts(3, message);
+
+ builder = message.toBuilder().putInt32ToInt32Field(4, 44);
+ assertEquals(4, builder.getInt32ToInt32FieldCount());
+ assertEquals(4, builder.build().getInt32ToInt32FieldCount());
+
+ // already present - should be unchanged
+ builder.putInt32ToInt32Field(4, 44);
+ assertEquals(4, builder.getInt32ToInt32FieldCount());
+ }
+
+ private void assertMapCounts(int expectedCount, TestMapOrBuilder testMapOrBuilder) {
+ assertEquals(expectedCount, testMapOrBuilder.getInt32ToInt32FieldCount());
+ assertEquals(expectedCount, testMapOrBuilder.getInt32ToStringFieldCount());
+ assertEquals(expectedCount, testMapOrBuilder.getInt32ToBytesFieldCount());
+ assertEquals(expectedCount, testMapOrBuilder.getInt32ToEnumFieldCount());
+ assertEquals(expectedCount, testMapOrBuilder.getInt32ToMessageFieldCount());
+ assertEquals(expectedCount, testMapOrBuilder.getStringToInt32FieldCount());
+ }
+
+ public void testGetOrDefault() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ assertMapCounts(0, builder);
+ setMapValuesUsingAccessors(builder);
+ doTestGetOrDefault(builder);
+ doTestGetOrDefault(builder.build());
+ }
+
+ public void doTestGetOrDefault(TestMapOrBuilder testMapOrBuilder) {
+ assertEquals(11, testMapOrBuilder.getInt32ToInt32FieldOrDefault(1, -11));
+ assertEquals(-11, testMapOrBuilder.getInt32ToInt32FieldOrDefault(-1, -11));
+
+ assertEquals("11", testMapOrBuilder.getInt32ToStringFieldOrDefault(1, "-11"));
+ assertNull("-11", testMapOrBuilder.getInt32ToStringFieldOrDefault(-1, null));
+
+ assertEquals(TestUtil.toBytes("11"), testMapOrBuilder.getInt32ToBytesFieldOrDefault(1, null));
+ assertNull(testMapOrBuilder.getInt32ToBytesFieldOrDefault(-1, null));
+
+ assertEquals(TestMap.EnumValue.FOO, testMapOrBuilder.getInt32ToEnumFieldOrDefault(1, null));
+ assertNull(testMapOrBuilder.getInt32ToEnumFieldOrDefault(-1, null));
+
+ assertEquals(MessageValue.newBuilder().setValue(11).build(),
+ testMapOrBuilder.getInt32ToMessageFieldOrDefault(1, null));
+ assertNull(testMapOrBuilder.getInt32ToMessageFieldOrDefault(-1, null));
+
+ assertEquals(11, testMapOrBuilder.getStringToInt32FieldOrDefault("1", -11));
+ assertEquals(-11, testMapOrBuilder.getStringToInt32FieldOrDefault("-1", -11));
+
+ try {
+ testMapOrBuilder.getStringToInt32FieldOrDefault(null, -11);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void testGetOrThrow() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ assertMapCounts(0, builder);
+ setMapValuesUsingAccessors(builder);
+ doTestGetOrDefault(builder);
+ doTestGetOrDefault(builder.build());
+ }
+
+ public void doTestGetOrThrow(TestMapOrBuilder testMapOrBuilder) {
+ assertEquals(11, testMapOrBuilder.getInt32ToInt32FieldOrThrow(1));
+ try {
+ testMapOrBuilder.getInt32ToInt32FieldOrThrow(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ assertEquals("11", testMapOrBuilder.getInt32ToStringFieldOrThrow(1));
+
+ try {
+ testMapOrBuilder.getInt32ToStringFieldOrThrow(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ assertEquals(TestUtil.toBytes("11"), testMapOrBuilder.getInt32ToBytesFieldOrThrow(1));
+
+ try {
+ testMapOrBuilder.getInt32ToBytesFieldOrThrow(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ assertEquals(TestMap.EnumValue.FOO, testMapOrBuilder.getInt32ToEnumFieldOrThrow(1));
+ try {
+ testMapOrBuilder.getInt32ToEnumFieldOrThrow(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ assertEquals(MessageValue.newBuilder().setValue(11).build(),
+ testMapOrBuilder.getInt32ToMessageFieldOrThrow(1));
+ try {
+ testMapOrBuilder.getInt32ToMessageFieldOrThrow(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ assertEquals(11, testMapOrBuilder.getStringToInt32FieldOrThrow("1"));
+ try {
+ testMapOrBuilder.getStringToInt32FieldOrThrow("-1");
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ testMapOrBuilder.getStringToInt32FieldOrThrow(null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void testPut() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ builder.putInt32ToInt32Field(1, 11);
+ assertEquals(11, builder.getInt32ToInt32FieldOrThrow(1));
+
+ builder.putInt32ToStringField(1, "a");
+ assertEquals("a", builder.getInt32ToStringFieldOrThrow(1));
+ try {
+ builder.putInt32ToStringField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ builder.putInt32ToBytesField(1, TestUtil.toBytes("11"));
+ assertEquals(TestUtil.toBytes("11"), builder.getInt32ToBytesFieldOrThrow(1));
+ try {
+ builder.putInt32ToBytesField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ builder.putInt32ToEnumField(1, TestMap.EnumValue.FOO);
+ assertEquals(TestMap.EnumValue.FOO, builder.getInt32ToEnumFieldOrThrow(1));
+ try {
+ builder.putInt32ToEnumField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ builder.putStringToInt32Field("a", 1);
+ assertEquals(1, builder.getStringToInt32FieldOrThrow("a"));
+ try {
+ builder.putStringToInt32Field(null, -1);
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void testRemove() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(builder);
+ assertEquals(11, builder.getInt32ToInt32FieldOrThrow(1));
+ for (int times = 0; times < 2; times++) {
+ builder.removeInt32ToInt32Field(1);
+ assertEquals(-1, builder.getInt32ToInt32FieldOrDefault(1, -1));
+ }
+
+ assertEquals("11", builder.getInt32ToStringFieldOrThrow(1));
+ for (int times = 0; times < 2; times++) {
+ builder.removeInt32ToStringField(1);
+ assertNull(builder.getInt32ToStringFieldOrDefault(1, null));
+ }
+
+ assertEquals(TestUtil.toBytes("11"), builder.getInt32ToBytesFieldOrThrow(1));
+ for (int times = 0; times < 2; times++) {
+ builder.removeInt32ToBytesField(1);
+ assertNull(builder.getInt32ToBytesFieldOrDefault(1, null));
+ }
+
+ assertEquals(TestMap.EnumValue.FOO, builder.getInt32ToEnumFieldOrThrow(1));
+ for (int times = 0; times < 2; times++) {
+ builder.removeInt32ToEnumField(1);
+ assertNull(builder.getInt32ToEnumFieldOrDefault(1, null));
+ }
+
+ assertEquals(11, builder.getStringToInt32FieldOrThrow("1"));
+ for (int times = 0; times < 2; times++) {
+ builder.removeStringToInt32Field("1");
+ assertEquals(-1, builder.getStringToInt32FieldOrDefault("1", -1));
+ }
+
+ try {
+ builder.removeStringToInt32Field(null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ // Regression test for b/20494788
+ public void testMapInitializationOrder() throws Exception {
+ assertEquals("RedactAllTypes", map_test.RedactAllTypes
+ .getDefaultInstance().getDescriptorForType().getName());
+
+ map_test.Message1.Builder builder =
+ map_test.Message1.newBuilder();
+ builder.putMapField("key", true);
+ map_test.Message1 message = builder.build();
+ Message mapEntry = (Message) message.getRepeatedField(
+ message.getDescriptorForType().findFieldByName("map_field"), 0);
+ assertEquals(2, mapEntry.getAllFields().size());
+ }
+
+ public void testReservedWordsFieldNames() {
+ ReservedAsMapField.newBuilder().build();
+ ReservedAsMapFieldWithEnumValue.newBuilder().build();
+ }
+
+ private static <K, V> Map<K, V> newMap(K key1, V value1) {
+ Map<K, V> map = new HashMap<K, V>();
+ map.put(key1, value1);
+ return map;
+ }
+
+ private static <K, V> Map<K, V> newMap(K key1, V value1, K key2, V value2) {
+ Map<K, V> map = new HashMap<K, V>();
+ map.put(key1, value1);
+ map.put(key2, value2);
+ return map;
+ }
+
+ public void testGetMap() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(builder);
+ assertMapValuesSet(builder);
+ TestMap message = builder.build();
+ assertEquals(
+ message.getStringToInt32Field(),
+ message.getStringToInt32FieldMap());
+ assertEquals(
+ message.getInt32ToBytesField(),
+ message.getInt32ToBytesFieldMap());
+ assertEquals(
+ message.getInt32ToEnumField(),
+ message.getInt32ToEnumFieldMap());
+ assertEquals(
+ message.getInt32ToMessageField(),
+ message.getInt32ToMessageFieldMap());
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/MapTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/MapTest.java
new file mode 100644
index 0000000000..81e951ccf7
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/MapTest.java
@@ -0,0 +1,1495 @@
+// 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.Descriptor;
+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 java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+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.
+ */
+public class MapTest extends TestCase {
+
+ private void setMapValuesUsingMutableMap(TestMap.Builder builder) {
+ builder.getMutableInt32ToInt32Field().put(1, 11);
+ builder.getMutableInt32ToInt32Field().put(2, 22);
+ builder.getMutableInt32ToInt32Field().put(3, 33);
+ //
+ builder.getMutableInt32ToStringField().put(1, "11");
+ builder.getMutableInt32ToStringField().put(2, "22");
+ builder.getMutableInt32ToStringField().put(3, "33");
+ //
+ builder.getMutableInt32ToBytesField().put(1, TestUtil.toBytes("11"));
+ builder.getMutableInt32ToBytesField().put(2, TestUtil.toBytes("22"));
+ builder.getMutableInt32ToBytesField().put(3, TestUtil.toBytes("33"));
+ //
+ builder.getMutableInt32ToEnumField().put(1, TestMap.EnumValue.FOO);
+ builder.getMutableInt32ToEnumField().put(2, TestMap.EnumValue.BAR);
+ builder.getMutableInt32ToEnumField().put(3, TestMap.EnumValue.BAZ);
+ //
+ builder.getMutableInt32ToMessageField().put(
+ 1, MessageValue.newBuilder().setValue(11).build());
+ builder.getMutableInt32ToMessageField().put(
+ 2, MessageValue.newBuilder().setValue(22).build());
+ builder.getMutableInt32ToMessageField().put(
+ 3, MessageValue.newBuilder().setValue(33).build());
+ //
+ builder.getMutableStringToInt32Field().put("1", 11);
+ builder.getMutableStringToInt32Field().put("2", 22);
+ builder.getMutableStringToInt32Field().put("3", 33);
+ }
+
+ private void setMapValuesUsingAccessors(TestMap.Builder builder) {
+ builder
+ .putInt32ToInt32Field(1, 11)
+ .putInt32ToInt32Field(2, 22)
+ .putInt32ToInt32Field(3, 33)
+
+ .putInt32ToStringField(1, "11")
+ .putInt32ToStringField(2, "22")
+ .putInt32ToStringField(3, "33")
+
+ .putInt32ToBytesField(1, TestUtil.toBytes("11"))
+ .putInt32ToBytesField(2, TestUtil.toBytes("22"))
+ .putInt32ToBytesField(3, TestUtil.toBytes("33"))
+
+ .putInt32ToEnumField(1, TestMap.EnumValue.FOO)
+ .putInt32ToEnumField(2, TestMap.EnumValue.BAR)
+ .putInt32ToEnumField(3, TestMap.EnumValue.BAZ)
+
+ .putInt32ToMessageField(1, MessageValue.newBuilder().setValue(11).build())
+ .putInt32ToMessageField(2, MessageValue.newBuilder().setValue(22).build())
+ .putInt32ToMessageField(3, MessageValue.newBuilder().setValue(33).build())
+
+ .putStringToInt32Field("1", 11)
+ .putStringToInt32Field("2", 22)
+ .putStringToInt32Field("3", 33);
+ }
+
+ public void testSetMapValues() {
+ TestMap.Builder usingMutableMapBuilder = TestMap.newBuilder();
+ setMapValuesUsingMutableMap(usingMutableMapBuilder);
+ TestMap usingMutableMap = usingMutableMapBuilder.build();
+ assertMapValuesSet(usingMutableMap);
+
+ TestMap.Builder usingAccessorsBuilder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(usingAccessorsBuilder);
+ TestMap usingAccessors = usingAccessorsBuilder.build();
+ assertMapValuesSet(usingAccessors);
+
+ assertEquals(usingAccessors, usingMutableMap);
+ }
+
+ private void copyMapValues(TestMap source, TestMap.Builder destination) {
+ destination
+ .putAllInt32ToInt32Field(source.getInt32ToInt32Field())
+ .putAllInt32ToStringField(source.getInt32ToStringField())
+ .putAllInt32ToBytesField(source.getInt32ToBytesField())
+ .putAllInt32ToEnumField(source.getInt32ToEnumField())
+ .putAllInt32ToMessageField(source.getInt32ToMessageField())
+ .putAllStringToInt32Field(source.getStringToInt32Field());
+ }
+
+ private void assertMapValuesSet(TestMap message) {
+ assertEquals(3, message.getInt32ToInt32Field().size());
+ assertEquals(11, message.getInt32ToInt32Field().get(1).intValue());
+ assertEquals(22, message.getInt32ToInt32Field().get(2).intValue());
+ assertEquals(33, message.getInt32ToInt32Field().get(3).intValue());
+
+ assertEquals(3, message.getInt32ToStringField().size());
+ assertEquals("11", message.getInt32ToStringField().get(1));
+ assertEquals("22", message.getInt32ToStringField().get(2));
+ assertEquals("33", message.getInt32ToStringField().get(3));
+
+ assertEquals(3, message.getInt32ToBytesField().size());
+ assertEquals(TestUtil.toBytes("11"), message.getInt32ToBytesField().get(1));
+ assertEquals(TestUtil.toBytes("22"), message.getInt32ToBytesField().get(2));
+ assertEquals(TestUtil.toBytes("33"), message.getInt32ToBytesField().get(3));
+
+ assertEquals(3, message.getInt32ToEnumField().size());
+ assertEquals(TestMap.EnumValue.FOO, message.getInt32ToEnumField().get(1));
+ assertEquals(TestMap.EnumValue.BAR, message.getInt32ToEnumField().get(2));
+ assertEquals(TestMap.EnumValue.BAZ, message.getInt32ToEnumField().get(3));
+
+ assertEquals(3, message.getInt32ToMessageField().size());
+ assertEquals(11, message.getInt32ToMessageField().get(1).getValue());
+ assertEquals(22, message.getInt32ToMessageField().get(2).getValue());
+ assertEquals(33, message.getInt32ToMessageField().get(3).getValue());
+
+ assertEquals(3, message.getStringToInt32Field().size());
+ assertEquals(11, message.getStringToInt32Field().get("1").intValue());
+ assertEquals(22, message.getStringToInt32Field().get("2").intValue());
+ assertEquals(33, message.getStringToInt32Field().get("3").intValue());
+ }
+
+ private void updateMapValuesUsingMutableMap(TestMap.Builder builder) {
+ builder.getMutableInt32ToInt32Field().put(1, 111);
+ builder.getMutableInt32ToInt32Field().remove(2);
+ builder.getMutableInt32ToInt32Field().put(4, 44);
+ //
+ builder.getMutableInt32ToStringField().put(1, "111");
+ builder.getMutableInt32ToStringField().remove(2);
+ builder.getMutableInt32ToStringField().put(4, "44");
+ //
+ builder.getMutableInt32ToBytesField().put(1, TestUtil.toBytes("111"));
+ builder.getMutableInt32ToBytesField().remove(2);
+ builder.getMutableInt32ToBytesField().put(4, TestUtil.toBytes("44"));
+ //
+ builder.getMutableInt32ToEnumField().put(1, TestMap.EnumValue.BAR);
+ builder.getMutableInt32ToEnumField().remove(2);
+ builder.getMutableInt32ToEnumField().put(4, TestMap.EnumValue.QUX);
+ //
+ builder.getMutableInt32ToMessageField().put(
+ 1, MessageValue.newBuilder().setValue(111).build());
+ builder.getMutableInt32ToMessageField().remove(2);
+ builder.getMutableInt32ToMessageField().put(
+ 4, MessageValue.newBuilder().setValue(44).build());
+ //
+ builder.getMutableStringToInt32Field().put("1", 111);
+ builder.getMutableStringToInt32Field().remove("2");
+ builder.getMutableStringToInt32Field().put("4", 44);
+ }
+
+ private void updateMapValuesUsingAccessors(TestMap.Builder builder) {
+ builder
+ .putInt32ToInt32Field(1, 111)
+ .removeInt32ToInt32Field(2)
+ .putInt32ToInt32Field(4, 44)
+
+ .putInt32ToStringField(1, "111")
+ .removeInt32ToStringField(2)
+ .putInt32ToStringField(4, "44")
+
+ .putInt32ToBytesField(1, TestUtil.toBytes("111"))
+ .removeInt32ToBytesField(2)
+ .putInt32ToBytesField(4, TestUtil.toBytes("44"))
+
+ .putInt32ToEnumField(1, TestMap.EnumValue.BAR)
+ .removeInt32ToEnumField(2)
+ .putInt32ToEnumField(4, TestMap.EnumValue.QUX)
+
+ .putInt32ToMessageField(1, MessageValue.newBuilder().setValue(111).build())
+ .removeInt32ToMessageField(2)
+ .putInt32ToMessageField(4, MessageValue.newBuilder().setValue(44).build())
+
+ .putStringToInt32Field("1", 111)
+ .removeStringToInt32Field("2")
+ .putStringToInt32Field("4", 44);
+ }
+
+ public void testUpdateMapValues() {
+ TestMap.Builder usingMutableMapBuilder = TestMap.newBuilder();
+ setMapValuesUsingMutableMap(usingMutableMapBuilder);
+ TestMap usingMutableMap = usingMutableMapBuilder.build();
+ assertMapValuesSet(usingMutableMap);
+
+ TestMap.Builder usingAccessorsBuilder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(usingAccessorsBuilder);
+ TestMap usingAccessors = usingAccessorsBuilder.build();
+ assertMapValuesSet(usingAccessors);
+
+ assertEquals(usingAccessors, usingMutableMap);
+ //
+ usingMutableMapBuilder = usingMutableMap.toBuilder();
+ updateMapValuesUsingMutableMap(usingMutableMapBuilder);
+ usingMutableMap = usingMutableMapBuilder.build();
+ assertMapValuesUpdated(usingMutableMap);
+
+ usingAccessorsBuilder = usingAccessors.toBuilder();
+ updateMapValuesUsingAccessors(usingAccessorsBuilder);
+ usingAccessors = usingAccessorsBuilder.build();
+ assertMapValuesUpdated(usingAccessors);
+
+ assertEquals(usingAccessors, usingMutableMap);
+ }
+
+ private void assertMapValuesUpdated(TestMap message) {
+ assertEquals(3, message.getInt32ToInt32Field().size());
+ assertEquals(111, message.getInt32ToInt32Field().get(1).intValue());
+ assertEquals(33, message.getInt32ToInt32Field().get(3).intValue());
+ assertEquals(44, message.getInt32ToInt32Field().get(4).intValue());
+
+ assertEquals(3, message.getInt32ToStringField().size());
+ assertEquals("111", message.getInt32ToStringField().get(1));
+ assertEquals("33", message.getInt32ToStringField().get(3));
+ assertEquals("44", message.getInt32ToStringField().get(4));
+
+ assertEquals(3, message.getInt32ToBytesField().size());
+ assertEquals(TestUtil.toBytes("111"), message.getInt32ToBytesField().get(1));
+ assertEquals(TestUtil.toBytes("33"), message.getInt32ToBytesField().get(3));
+ assertEquals(TestUtil.toBytes("44"), message.getInt32ToBytesField().get(4));
+
+ assertEquals(3, message.getInt32ToEnumField().size());
+ assertEquals(TestMap.EnumValue.BAR, message.getInt32ToEnumField().get(1));
+ assertEquals(TestMap.EnumValue.BAZ, message.getInt32ToEnumField().get(3));
+ assertEquals(TestMap.EnumValue.QUX, message.getInt32ToEnumField().get(4));
+
+ assertEquals(3, message.getInt32ToMessageField().size());
+ assertEquals(111, message.getInt32ToMessageField().get(1).getValue());
+ assertEquals(33, message.getInt32ToMessageField().get(3).getValue());
+ assertEquals(44, message.getInt32ToMessageField().get(4).getValue());
+
+ assertEquals(3, message.getStringToInt32Field().size());
+ assertEquals(111, message.getStringToInt32Field().get("1").intValue());
+ assertEquals(33, message.getStringToInt32Field().get("3").intValue());
+ assertEquals(44, message.getStringToInt32Field().get("4").intValue());
+ }
+
+ private void assertMapValuesCleared(TestMapOrBuilder testMapOrBuilder) {
+ assertEquals(0, testMapOrBuilder.getInt32ToInt32Field().size());
+ assertEquals(0, testMapOrBuilder.getInt32ToInt32FieldCount());
+ assertEquals(0, testMapOrBuilder.getInt32ToStringField().size());
+ assertEquals(0, testMapOrBuilder.getInt32ToStringFieldCount());
+ assertEquals(0, testMapOrBuilder.getInt32ToBytesField().size());
+ assertEquals(0, testMapOrBuilder.getInt32ToBytesFieldCount());
+ assertEquals(0, testMapOrBuilder.getInt32ToEnumField().size());
+ assertEquals(0, testMapOrBuilder.getInt32ToEnumFieldCount());
+ assertEquals(0, testMapOrBuilder.getInt32ToMessageField().size());
+ assertEquals(0, testMapOrBuilder.getInt32ToMessageFieldCount());
+ assertEquals(0, testMapOrBuilder.getStringToInt32Field().size());
+ assertEquals(0, testMapOrBuilder.getStringToInt32FieldCount());
+ }
+
+ public void testGetMapIsImmutable() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ assertMapsAreImmutable(builder);
+ assertMapsAreImmutable(builder.build());
+
+ setMapValuesUsingAccessors(builder);
+ assertMapsAreImmutable(builder);
+ assertMapsAreImmutable(builder.build());
+ }
+
+ private void assertMapsAreImmutable(TestMapOrBuilder testMapOrBuilder) {
+ assertImmutable(testMapOrBuilder.getInt32ToInt32Field(), 1, 2);
+ assertImmutable(testMapOrBuilder.getInt32ToStringField(), 1, "2");
+ assertImmutable(testMapOrBuilder.getInt32ToBytesField(), 1, TestUtil.toBytes("2"));
+ assertImmutable(testMapOrBuilder.getInt32ToEnumField(), 1, TestMap.EnumValue.FOO);
+ assertImmutable(
+ testMapOrBuilder.getInt32ToMessageField(), 1, MessageValue.getDefaultInstance());
+ assertImmutable(testMapOrBuilder.getStringToInt32Field(), "1", 2);
+ }
+
+ private <K, V> void assertImmutable(Map<K, V> map, K key, V value) {
+ try {
+ map.put(key, value);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ public void testMutableMapLifecycle() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ Map<Integer, Integer> intMap = builder.getMutableInt32ToInt32Field();
+ intMap.put(1, 2);
+ assertEquals(newMap(1, 2), builder.build().getInt32ToInt32Field());
+ try {
+ intMap.put(2, 3);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(newMap(1, 2), builder.getInt32ToInt32Field());
+ builder.getMutableInt32ToInt32Field().put(2, 3);
+ assertEquals(newMap(1, 2, 2, 3), builder.getInt32ToInt32Field());
+ //
+ Map<Integer, TestMap.EnumValue> enumMap = builder.getMutableInt32ToEnumField();
+ enumMap.put(1, TestMap.EnumValue.BAR);
+ assertEquals(newMap(1, TestMap.EnumValue.BAR), builder.build().getInt32ToEnumField());
+ try {
+ enumMap.put(2, TestMap.EnumValue.FOO);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(newMap(1, TestMap.EnumValue.BAR), builder.getInt32ToEnumField());
+ builder.getMutableInt32ToEnumField().put(2, TestMap.EnumValue.FOO);
+ assertEquals(
+ newMap(1, TestMap.EnumValue.BAR, 2, TestMap.EnumValue.FOO),
+ builder.getInt32ToEnumField());
+ //
+ Map<Integer, String> stringMap = builder.getMutableInt32ToStringField();
+ stringMap.put(1, "1");
+ assertEquals(newMap(1, "1"), builder.build().getInt32ToStringField());
+ try {
+ stringMap.put(2, "2");
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(newMap(1, "1"), builder.getInt32ToStringField());
+ builder.putInt32ToStringField(2, "2");
+ assertEquals(
+ newMap(1, "1", 2, "2"),
+ builder.getInt32ToStringField());
+ //
+ Map<Integer, TestMap.MessageValue> messageMap = builder.getMutableInt32ToMessageField();
+ messageMap.put(1, TestMap.MessageValue.getDefaultInstance());
+ assertEquals(newMap(1, TestMap.MessageValue.getDefaultInstance()),
+ builder.build().getInt32ToMessageField());
+ try {
+ messageMap.put(2, TestMap.MessageValue.getDefaultInstance());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(newMap(1, TestMap.MessageValue.getDefaultInstance()),
+ builder.getInt32ToMessageField());
+ builder.putInt32ToMessageField(2, TestMap.MessageValue.getDefaultInstance());
+ assertEquals(
+ newMap(1, TestMap.MessageValue.getDefaultInstance(),
+ 2, TestMap.MessageValue.getDefaultInstance()),
+ builder.getInt32ToMessageField());
+ }
+ //
+ public void testMutableMapLifecycle_collections() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ Map<Integer, Integer> intMap = builder.getMutableInt32ToInt32Field();
+ intMap.put(1, 2);
+ assertEquals(newMap(1, 2), builder.build().getInt32ToInt32Field());
+ try {
+ intMap.remove(2);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ intMap.entrySet().remove(new Object());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ intMap.entrySet().iterator().remove();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ intMap.keySet().remove(new Object());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ intMap.values().remove(new Object());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ intMap.values().iterator().remove();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(newMap(1, 2), intMap);
+ assertEquals(newMap(1, 2), builder.getInt32ToInt32Field());
+ assertEquals(newMap(1, 2), builder.build().getInt32ToInt32Field());
+ }
+
+
+ public void testGettersAndSetters() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ TestMap message = builder.build();
+ assertMapValuesCleared(message);
+
+ builder = message.toBuilder();
+ setMapValuesUsingAccessors(builder);
+ message = builder.build();
+ assertMapValuesSet(message);
+
+ builder = message.toBuilder();
+ updateMapValuesUsingAccessors(builder);
+ message = builder.build();
+ assertMapValuesUpdated(message);
+
+ builder = message.toBuilder();
+ builder.clear();
+ assertMapValuesCleared(builder);
+ message = builder.build();
+ assertMapValuesCleared(message);
+ }
+
+ public void testPutAll() throws Exception {
+ TestMap.Builder sourceBuilder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(sourceBuilder);
+ TestMap source = sourceBuilder.build();
+ assertMapValuesSet(source);
+
+ TestMap.Builder destination = TestMap.newBuilder();
+ copyMapValues(source, destination);
+ assertMapValuesSet(destination.build());
+ }
+
+ public void testPutAllForUnknownEnumValues() throws Exception {
+ TestMap source = TestMap.newBuilder()
+ .putAllInt32ToEnumFieldValue(newMap(
+ 0, 0,
+ 1, 1,
+ 2, 1000)) // unknown value.
+ .build();
+
+ TestMap destination = TestMap.newBuilder()
+ .putAllInt32ToEnumFieldValue(source.getInt32ToEnumFieldValue())
+ .build();
+
+ assertEquals(0, destination.getInt32ToEnumFieldValue().get(0).intValue());
+ assertEquals(1, destination.getInt32ToEnumFieldValue().get(1).intValue());
+ assertEquals(1000, destination.getInt32ToEnumFieldValue().get(2).intValue());
+ assertEquals(3, destination.getInt32ToEnumFieldCount());
+ }
+
+ public void testPutForUnknownEnumValues() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder()
+ .putInt32ToEnumFieldValue(0, 0)
+ .putInt32ToEnumFieldValue(1, 1);
+
+ try {
+ builder.putInt32ToEnumFieldValue(2, 1000); // unknown value.
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ TestMap message = builder.build();
+ assertEquals(0, message.getInt32ToEnumFieldValueOrThrow(0));
+ assertEquals(1, message.getInt32ToEnumFieldValueOrThrow(1));
+ assertEquals(2, message.getInt32ToEnumFieldCount());
+ }
+
+ public void testPutChecksNullKeysAndValues() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+
+ try {
+ builder.putInt32ToStringField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected.
+ }
+
+ try {
+ builder.putInt32ToBytesField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected.
+ }
+
+ try {
+ builder.putInt32ToEnumField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected.
+ }
+
+ try {
+ builder.putInt32ToMessageField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected.
+ }
+
+ try {
+ builder.putStringToInt32Field(null, 1);
+ fail();
+ } catch (NullPointerException e) {
+ // expected.
+ }
+ }
+
+ public void testSerializeAndParse() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(builder);
+ TestMap message = builder.build();
+ assertEquals(message.getSerializedSize(), message.toByteString().size());
+ message = TestMap.parser().parseFrom(message.toByteString());
+ assertMapValuesSet(message);
+
+ builder = message.toBuilder();
+ updateMapValuesUsingAccessors(builder);
+ message = builder.build();
+ assertEquals(message.getSerializedSize(), message.toByteString().size());
+ message = TestMap.parser().parseFrom(message.toByteString());
+ assertMapValuesUpdated(message);
+
+ builder = message.toBuilder();
+ builder.clear();
+ message = builder.build();
+ assertEquals(message.getSerializedSize(), message.toByteString().size());
+ message = TestMap.parser().parseFrom(message.toByteString());
+ assertMapValuesCleared(message);
+ }
+
+ private TestMap tryParseTestMap(BizarroTestMap bizarroMap) throws IOException {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ CodedOutputStream output = CodedOutputStream.newInstance(byteArrayOutputStream);
+ bizarroMap.writeTo(output);
+ output.flush();
+ return TestMap.parser().parseFrom(ByteString.copyFrom(byteArrayOutputStream.toByteArray()));
+ }
+
+ public void testParseError() throws Exception {
+ ByteString bytes = TestUtil.toBytes("SOME BYTES");
+ String stringKey = "a string key";
+
+ TestMap map = tryParseTestMap(BizarroTestMap.newBuilder()
+ .putInt32ToInt32Field(5, bytes)
+ .build());
+ assertEquals(map.getInt32ToInt32FieldOrDefault(5, -1), 0);
+
+ map = tryParseTestMap(BizarroTestMap.newBuilder()
+ .putInt32ToStringField(stringKey, 5)
+ .build());
+ assertEquals(map.getInt32ToStringFieldOrDefault(0, null), "");
+
+ map = tryParseTestMap(BizarroTestMap.newBuilder()
+ .putInt32ToBytesField(stringKey, 5)
+ .build());
+ assertEquals(map.getInt32ToBytesFieldOrDefault(0, null), ByteString.EMPTY);
+
+ map = tryParseTestMap(BizarroTestMap.newBuilder()
+ .putInt32ToEnumField(stringKey, bytes)
+ .build());
+ assertEquals(map.getInt32ToEnumFieldOrDefault(0, null), TestMap.EnumValue.FOO);
+
+ try {
+ tryParseTestMap(BizarroTestMap.newBuilder()
+ .putInt32ToMessageField(stringKey, bytes)
+ .build());
+ fail();
+ } catch (InvalidProtocolBufferException expected) {
+ assertTrue(expected.getUnfinishedMessage() instanceof TestMap);
+ map = (TestMap) expected.getUnfinishedMessage();
+ assertTrue(map.getInt32ToMessageField().isEmpty());
+ }
+
+ map = tryParseTestMap(BizarroTestMap.newBuilder()
+ .putStringToInt32Field(stringKey, bytes)
+ .build());
+ assertEquals(map.getStringToInt32FieldOrDefault(stringKey, -1), 0);
+ }
+
+ public void testMergeFrom() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(builder);
+ TestMap message = builder.build();
+
+ TestMap.Builder other = TestMap.newBuilder();
+ other.mergeFrom(message);
+ assertMapValuesSet(other.build());
+ }
+
+ public void testEqualsAndHashCode() throws Exception {
+ // Test that generated equals() and hashCode() will disregard the order
+ // of map entries when comparing/hashing map fields.
+
+ // We can't control the order of elements in a HashMap. The best we can do
+ // here is to add elements in different order.
+ TestMap.Builder b1 = TestMap.newBuilder()
+ .putInt32ToInt32Field(1, 2)
+ .putInt32ToInt32Field(3, 4)
+ .putInt32ToInt32Field(5, 6);
+ TestMap m1 = b1.build();
+
+ TestMap.Builder b2 = TestMap.newBuilder()
+ .putInt32ToInt32Field(5, 6)
+ .putInt32ToInt32Field(1, 2)
+ .putInt32ToInt32Field(3, 4);
+ TestMap m2 = b2.build();
+
+ assertEquals(m1, m2);
+ assertEquals(m1.hashCode(), m2.hashCode());
+
+ // Make sure we did compare map fields.
+ b2.putInt32ToInt32Field(1, 0);
+ m2 = b2.build();
+ assertFalse(m1.equals(m2));
+ // Don't check m1.hashCode() != m2.hashCode() because it's not guaranteed
+ // to be different.
+
+ // Regression test for b/18549190: if a map is a subset of the other map,
+ // equals() should return false.
+ b2.removeInt32ToInt32Field(1);
+ m2 = b2.build();
+ assertFalse(m1.equals(m2));
+ assertFalse(m2.equals(m1));
+ }
+
+ public void testNestedBuilderOnChangeEventPropagation() {
+ TestOnChangeEventPropagation.Builder parent =
+ TestOnChangeEventPropagation.newBuilder();
+ parent.getOptionalMessageBuilder().putInt32ToInt32Field(1, 2);
+ TestOnChangeEventPropagation message = parent.build();
+ assertEquals(2, message.getOptionalMessage().getInt32ToInt32Field().get(1).intValue());
+
+ // Make a change using nested builder.
+ parent.getOptionalMessageBuilder().putInt32ToInt32Field(1, 3);
+
+ // Should be able to observe the change.
+ message = parent.build();
+ assertEquals(3, message.getOptionalMessage().getInt32ToInt32Field().get(1).intValue());
+
+ // Make another change using mergeFrom()
+ TestMap.Builder other = TestMap.newBuilder().putInt32ToInt32Field(1, 4);
+ parent.getOptionalMessageBuilder().mergeFrom(other.build());
+
+ // Should be able to observe the change.
+ message = parent.build();
+ assertEquals(4, message.getOptionalMessage().getInt32ToInt32Field().get(1).intValue());
+
+ // Make yet another change by clearing the nested builder.
+ parent.getOptionalMessageBuilder().clear();
+
+ // Should be able to observe the change.
+ message = parent.build();
+ assertEquals(0, message.getOptionalMessage().getInt32ToInt32Field().size());
+ }
+
+ public void testNestedBuilderOnChangeEventPropagationReflection() {
+ FieldDescriptor intMapField = f("int32_to_int32_field");
+ // Create an outer message builder with nested builder.
+ TestOnChangeEventPropagation.Builder parentBuilder =
+ TestOnChangeEventPropagation.newBuilder();
+ TestMap.Builder testMapBuilder = parentBuilder.getOptionalMessageBuilder();
+
+ // Create a map entry message.
+ TestMap.Builder entryBuilder = TestMap.newBuilder().putInt32ToInt32Field(1, 1);
+
+ // Put the entry into the nested builder.
+ testMapBuilder.addRepeatedField(
+ intMapField, entryBuilder.getRepeatedField(intMapField, 0));
+
+ // Should be able to observe the change.
+ TestOnChangeEventPropagation message = parentBuilder.build();
+ assertEquals(1, message.getOptionalMessage().getInt32ToInt32Field().size());
+
+ // Change the entry value.
+ entryBuilder.putInt32ToInt32Field(1, 4);
+ testMapBuilder = parentBuilder.getOptionalMessageBuilder();
+ testMapBuilder.setRepeatedField(
+ intMapField, 0, entryBuilder.getRepeatedField(intMapField, 0));
+
+ // Should be able to observe the change.
+ message = parentBuilder.build();
+ assertEquals(4,
+ message.getOptionalMessage().getInt32ToInt32Field().get(1).intValue());
+
+ // Clear the nested builder.
+ testMapBuilder = parentBuilder.getOptionalMessageBuilder();
+ testMapBuilder.clearField(intMapField);
+
+ // Should be able to observe the change.
+ message = parentBuilder.build();
+ assertEquals(0, message.getOptionalMessage().getInt32ToInt32Field().size());
+ }
+
+ // The following methods are used to test reflection API.
+
+ private static FieldDescriptor f(String name) {
+ return TestMap.getDescriptor().findFieldByName(name);
+ }
+
+ private static Object getFieldValue(Message mapEntry, String name) {
+ FieldDescriptor field = mapEntry.getDescriptorForType().findFieldByName(name);
+ return mapEntry.getField(field);
+ }
+
+ private static Message.Builder setFieldValue(
+ Message.Builder mapEntry, String name, Object value) {
+ FieldDescriptor field = mapEntry.getDescriptorForType().findFieldByName(name);
+ mapEntry.setField(field, value);
+ return mapEntry;
+ }
+
+ private static void assertHasMapValues(Message message, String name, Map<?, ?> values) {
+ FieldDescriptor field = f(name);
+ for (Object entry : (List<?>) message.getField(field)) {
+ Message mapEntry = (Message) entry;
+ Object key = getFieldValue(mapEntry, "key");
+ Object value = getFieldValue(mapEntry, "value");
+ assertTrue(values.containsKey(key));
+ assertEquals(value, values.get(key));
+ }
+ assertEquals(values.size(), message.getRepeatedFieldCount(field));
+ for (int i = 0; i < message.getRepeatedFieldCount(field); i++) {
+ Message mapEntry = (Message) message.getRepeatedField(field, i);
+ Object key = getFieldValue(mapEntry, "key");
+ Object value = getFieldValue(mapEntry, "value");
+ assertTrue(values.containsKey(key));
+ assertEquals(value, values.get(key));
+ }
+ }
+
+ private static <KeyType, ValueType>
+ Message newMapEntry(Message.Builder builder, String name, KeyType key, ValueType value) {
+ FieldDescriptor field = builder.getDescriptorForType().findFieldByName(name);
+ Message.Builder entryBuilder = builder.newBuilderForField(field);
+ FieldDescriptor keyField = entryBuilder.getDescriptorForType().findFieldByName("key");
+ FieldDescriptor valueField = entryBuilder.getDescriptorForType().findFieldByName("value");
+ entryBuilder.setField(keyField, key);
+ entryBuilder.setField(valueField, value);
+ return entryBuilder.build();
+ }
+
+ private static void setMapValues(Message.Builder builder, String name, Map<?, ?> values) {
+ List<Message> entryList = new ArrayList<Message>();
+ for (Map.Entry<?, ?> entry : values.entrySet()) {
+ entryList.add(newMapEntry(builder, name, entry.getKey(), entry.getValue()));
+ }
+ FieldDescriptor field = builder.getDescriptorForType().findFieldByName(name);
+ builder.setField(field, entryList);
+ }
+
+ private static <KeyType, ValueType>
+ Map<KeyType, ValueType> mapForValues(
+ KeyType key1, ValueType value1, KeyType key2, ValueType value2) {
+ Map<KeyType, ValueType> map = new HashMap<KeyType, ValueType>();
+ map.put(key1, value1);
+ map.put(key2, value2);
+ return map;
+ }
+
+ public void testReflectionApi() throws Exception {
+ // In reflection API, map fields are just repeated message fields.
+ TestMap.Builder builder = TestMap.newBuilder()
+ .putInt32ToInt32Field(1, 2)
+ .putInt32ToInt32Field(3, 4)
+ .putInt32ToMessageField(11, MessageValue.newBuilder().setValue(22).build())
+ .putInt32ToMessageField(33, MessageValue.newBuilder().setValue(44).build());
+ TestMap message = builder.build();
+
+ // Test getField(), getRepeatedFieldCount(), getRepeatedField().
+ assertHasMapValues(message, "int32_to_int32_field",
+ mapForValues(1, 2, 3, 4));
+ assertHasMapValues(message, "int32_to_message_field",
+ mapForValues(
+ 11, MessageValue.newBuilder().setValue(22).build(),
+ 33, MessageValue.newBuilder().setValue(44).build()));
+
+ // Test clearField()
+ builder.clearField(f("int32_to_int32_field"));
+ builder.clearField(f("int32_to_message_field"));
+ message = builder.build();
+ assertEquals(0, message.getInt32ToInt32Field().size());
+ assertEquals(0, message.getInt32ToMessageField().size());
+
+ // Test setField()
+ setMapValues(builder, "int32_to_int32_field",
+ mapForValues(11, 22, 33, 44));
+ setMapValues(builder, "int32_to_message_field",
+ mapForValues(
+ 111, MessageValue.newBuilder().setValue(222).build(),
+ 333, MessageValue.newBuilder().setValue(444).build()));
+ message = builder.build();
+ assertEquals(22, message.getInt32ToInt32Field().get(11).intValue());
+ assertEquals(44, message.getInt32ToInt32Field().get(33).intValue());
+ assertEquals(222, message.getInt32ToMessageField().get(111).getValue());
+ assertEquals(444, message.getInt32ToMessageField().get(333).getValue());
+
+ // Test addRepeatedField
+ builder.addRepeatedField(f("int32_to_int32_field"),
+ newMapEntry(builder, "int32_to_int32_field", 55, 66));
+ builder.addRepeatedField(f("int32_to_message_field"),
+ newMapEntry(builder, "int32_to_message_field", 555,
+ MessageValue.newBuilder().setValue(666).build()));
+ message = builder.build();
+ assertEquals(66, message.getInt32ToInt32Field().get(55).intValue());
+ assertEquals(666, message.getInt32ToMessageField().get(555).getValue());
+
+ // Test addRepeatedField (overriding existing values)
+ builder.addRepeatedField(f("int32_to_int32_field"),
+ newMapEntry(builder, "int32_to_int32_field", 55, 55));
+ builder.addRepeatedField(f("int32_to_message_field"),
+ newMapEntry(builder, "int32_to_message_field", 555,
+ MessageValue.newBuilder().setValue(555).build()));
+ message = builder.build();
+ assertEquals(55, message.getInt32ToInt32Field().get(55).intValue());
+ assertEquals(555, message.getInt32ToMessageField().get(555).getValue());
+
+ // Test setRepeatedField
+ for (int i = 0; i < builder.getRepeatedFieldCount(f("int32_to_int32_field")); i++) {
+ Message mapEntry = (Message) builder.getRepeatedField(f("int32_to_int32_field"), i);
+ int oldKey = ((Integer) getFieldValue(mapEntry, "key")).intValue();
+ int oldValue = ((Integer) getFieldValue(mapEntry, "value")).intValue();
+ // Swap key with value for each entry.
+ Message.Builder mapEntryBuilder = mapEntry.toBuilder();
+ setFieldValue(mapEntryBuilder, "key", oldValue);
+ setFieldValue(mapEntryBuilder, "value", oldKey);
+ builder.setRepeatedField(f("int32_to_int32_field"), i, mapEntryBuilder.build());
+ }
+ message = builder.build();
+ assertEquals(11, message.getInt32ToInt32Field().get(22).intValue());
+ assertEquals(33, message.getInt32ToInt32Field().get(44).intValue());
+ assertEquals(55, message.getInt32ToInt32Field().get(55).intValue());
+ }
+
+ public void testTextFormat() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(builder);
+ TestMap message = builder.build();
+
+ String textData = TextFormat.printToString(message);
+
+ builder = TestMap.newBuilder();
+ TextFormat.merge(textData, builder);
+ message = builder.build();
+
+ assertMapValuesSet(message);
+ }
+
+ public void testDynamicMessage() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(builder);
+ TestMap message = builder.build();
+
+ Message dynamicDefaultInstance =
+ DynamicMessage.getDefaultInstance(TestMap.getDescriptor());
+ Message dynamicMessage = dynamicDefaultInstance
+ .newBuilderForType().mergeFrom(message.toByteString()).build();
+
+ assertEquals(message, dynamicMessage);
+ assertEquals(message.hashCode(), dynamicMessage.hashCode());
+ }
+
+ public void testReflectionEqualsAndHashCode() throws Exception {
+ // Test that generated equals() and hashCode() will disregard the order
+ // of map entries when comparing/hashing map fields.
+
+ // We use DynamicMessage to test reflection based equals()/hashCode().
+ Message dynamicDefaultInstance =
+ DynamicMessage.getDefaultInstance(TestMap.getDescriptor());
+ FieldDescriptor field = f("int32_to_int32_field");
+
+ Message.Builder b1 = dynamicDefaultInstance.newBuilderForType();
+ b1.addRepeatedField(field, newMapEntry(b1, "int32_to_int32_field", 1, 2));
+ b1.addRepeatedField(field, newMapEntry(b1, "int32_to_int32_field", 3, 4));
+ b1.addRepeatedField(field, newMapEntry(b1, "int32_to_int32_field", 5, 6));
+ Message m1 = b1.build();
+
+ Message.Builder b2 = dynamicDefaultInstance.newBuilderForType();
+ b2.addRepeatedField(field, newMapEntry(b2, "int32_to_int32_field", 5, 6));
+ b2.addRepeatedField(field, newMapEntry(b2, "int32_to_int32_field", 1, 2));
+ b2.addRepeatedField(field, newMapEntry(b2, "int32_to_int32_field", 3, 4));
+ Message m2 = b2.build();
+
+ assertEquals(m1, m2);
+ assertEquals(m1.hashCode(), m2.hashCode());
+
+ // Make sure we did compare map fields.
+ b2.setRepeatedField(field, 0, newMapEntry(b1, "int32_to_int32_field", 0, 0));
+ m2 = b2.build();
+ assertFalse(m1.equals(m2));
+ // Don't check m1.hashCode() != m2.hashCode() because it's not guaranteed
+ // to be different.
+ }
+
+ public void testUnknownEnumValues() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder()
+ .putAllInt32ToEnumFieldValue(newMap(
+ 0, 0,
+ 1, 1,
+ 2, 1000)); // unknown value.
+ TestMap message = builder.build();
+
+ assertEquals(TestMap.EnumValue.FOO,
+ message.getInt32ToEnumField().get(0));
+ assertEquals(TestMap.EnumValue.BAR,
+ message.getInt32ToEnumField().get(1));
+ assertEquals(TestMap.EnumValue.UNRECOGNIZED,
+ message.getInt32ToEnumField().get(2));
+ assertEquals(1000, message.getInt32ToEnumFieldValue().get(2).intValue());
+
+ // Unknown enum values should be preserved after:
+ // 1. Serialization and parsing.
+ // 2. toBuild().
+ // 3. mergeFrom().
+ message = TestMap.parseFrom(message.toByteString());
+ assertEquals(1000, message.getInt32ToEnumFieldValue().get(2).intValue());
+ builder = message.toBuilder();
+ assertEquals(1000, builder.getInt32ToEnumFieldValue().get(2).intValue());
+ builder = TestMap.newBuilder().mergeFrom(message);
+ assertEquals(1000, builder.getInt32ToEnumFieldValue().get(2).intValue());
+
+ // hashCode()/equals() should take unknown enum values into account.
+ builder.putAllInt32ToEnumFieldValue(newMap(2, 1001));
+ TestMap message2 = builder.build();
+ assertFalse(message.hashCode() == message2.hashCode());
+ assertFalse(message.equals(message2));
+ // Unknown values will be converted to UNRECOGNIZED so the resulted enum map
+ // should be the same.
+ assertTrue(message.getInt32ToEnumField().equals(message2.getInt32ToEnumField()));
+ }
+
+ public void testUnknownEnumValuesInReflectionApi() throws Exception {
+ Descriptor descriptor = TestMap.getDescriptor();
+ EnumDescriptor enumDescriptor = TestMap.EnumValue.getDescriptor();
+ FieldDescriptor field = descriptor.findFieldByName("int32_to_enum_field");
+
+ Map<Integer, Integer> data = newMap(
+ 0, 0,
+ 1, 1,
+ 2, 1000); // unknown value
+
+ TestMap.Builder builder = TestMap.newBuilder()
+ .putAllInt32ToEnumFieldValue(data);
+
+ // Try to read unknown enum values using reflection API.
+ for (int i = 0; i < builder.getRepeatedFieldCount(field); i++) {
+ Message mapEntry = (Message) builder.getRepeatedField(field, i);
+ int key = ((Integer) getFieldValue(mapEntry, "key")).intValue();
+ int value = ((EnumValueDescriptor) getFieldValue(mapEntry, "value")).getNumber();
+ assertEquals(data.get(key).intValue(), value);
+ Message.Builder mapEntryBuilder = mapEntry.toBuilder();
+ // Increase the value by 1.
+ setFieldValue(mapEntryBuilder, "value",
+ enumDescriptor.findValueByNumberCreatingIfUnknown(value + 1));
+ builder.setRepeatedField(field, i, mapEntryBuilder.build());
+ }
+
+ // Verify that enum values have been successfully updated.
+ TestMap message = builder.build();
+ for (Map.Entry<Integer, Integer> entry : message.getInt32ToEnumFieldValue().entrySet()) {
+ assertEquals(data.get(entry.getKey()) + 1, entry.getValue().intValue());
+ }
+ }
+
+ public void testIterationOrder() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(builder);
+ TestMap message = builder.build();
+
+ assertEquals(Arrays.asList("1", "2", "3"),
+ new ArrayList<String>(message.getStringToInt32Field().keySet()));
+ }
+
+ public void testGetMap() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(builder);
+ TestMap message = builder.build();
+ assertEquals(
+ message.getStringToInt32Field(),
+ message.getStringToInt32FieldMap());
+ assertEquals(
+ message.getInt32ToBytesField(),
+ message.getInt32ToBytesFieldMap());
+ assertEquals(
+ message.getInt32ToEnumField(),
+ message.getInt32ToEnumFieldMap());
+ assertEquals(
+ message.getInt32ToEnumFieldValue(),
+ message.getInt32ToEnumFieldValueMap());
+ assertEquals(
+ message.getInt32ToMessageField(),
+ message.getInt32ToMessageFieldMap());
+ }
+
+ public void testContains() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(builder);
+ assertMapContainsSetValues(builder);
+ assertMapContainsSetValues(builder.build());
+ }
+
+ private void assertMapContainsSetValues(TestMapOrBuilder testMapOrBuilder) {
+ assertTrue(testMapOrBuilder.containsInt32ToInt32Field(1));
+ assertTrue(testMapOrBuilder.containsInt32ToInt32Field(2));
+ assertTrue(testMapOrBuilder.containsInt32ToInt32Field(3));
+ assertFalse(testMapOrBuilder.containsInt32ToInt32Field(-1));
+
+ assertTrue(testMapOrBuilder.containsInt32ToStringField(1));
+ assertTrue(testMapOrBuilder.containsInt32ToStringField(2));
+ assertTrue(testMapOrBuilder.containsInt32ToStringField(3));
+ assertFalse(testMapOrBuilder.containsInt32ToStringField(-1));
+
+ assertTrue(testMapOrBuilder.containsInt32ToBytesField(1));
+ assertTrue(testMapOrBuilder.containsInt32ToBytesField(2));
+ assertTrue(testMapOrBuilder.containsInt32ToBytesField(3));
+ assertFalse(testMapOrBuilder.containsInt32ToBytesField(-1));
+
+ assertTrue(testMapOrBuilder.containsInt32ToEnumField(1));
+ assertTrue(testMapOrBuilder.containsInt32ToEnumField(2));
+ assertTrue(testMapOrBuilder.containsInt32ToEnumField(3));
+ assertFalse(testMapOrBuilder.containsInt32ToEnumField(-1));
+
+ assertTrue(testMapOrBuilder.containsInt32ToMessageField(1));
+ assertTrue(testMapOrBuilder.containsInt32ToMessageField(2));
+ assertTrue(testMapOrBuilder.containsInt32ToMessageField(3));
+ assertFalse(testMapOrBuilder.containsInt32ToMessageField(-1));
+
+ assertTrue(testMapOrBuilder.containsStringToInt32Field("1"));
+ assertTrue(testMapOrBuilder.containsStringToInt32Field("2"));
+ assertTrue(testMapOrBuilder.containsStringToInt32Field("3"));
+ assertFalse(testMapOrBuilder.containsStringToInt32Field("-1"));
+ }
+
+ public void testCount() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ assertMapCounts(0, builder);
+
+ setMapValuesUsingAccessors(builder);
+ assertMapCounts(3, builder);
+
+ TestMap message = builder.build();
+ assertMapCounts(3, message);
+
+ builder = message.toBuilder().putInt32ToInt32Field(4, 44);
+ assertEquals(4, builder.getInt32ToInt32FieldCount());
+ assertEquals(4, builder.build().getInt32ToInt32FieldCount());
+
+ // already present - should be unchanged
+ builder.putInt32ToInt32Field(4, 44);
+ assertEquals(4, builder.getInt32ToInt32FieldCount());
+ }
+
+ private void assertMapCounts(int expectedCount, TestMapOrBuilder testMapOrBuilder) {
+ assertEquals(expectedCount, testMapOrBuilder.getInt32ToInt32FieldCount());
+ assertEquals(expectedCount, testMapOrBuilder.getInt32ToStringFieldCount());
+ assertEquals(expectedCount, testMapOrBuilder.getInt32ToBytesFieldCount());
+ assertEquals(expectedCount, testMapOrBuilder.getInt32ToEnumFieldCount());
+ assertEquals(expectedCount, testMapOrBuilder.getInt32ToMessageFieldCount());
+ assertEquals(expectedCount, testMapOrBuilder.getStringToInt32FieldCount());
+ }
+
+ public void testGetOrDefault() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ assertMapCounts(0, builder);
+ setMapValuesUsingAccessors(builder);
+ doTestGetOrDefault(builder);
+ doTestGetOrDefault(builder.build());
+ }
+
+ public void doTestGetOrDefault(TestMapOrBuilder testMapOrBuilder) {
+ assertEquals(11, testMapOrBuilder.getInt32ToInt32FieldOrDefault(1, -11));
+ assertEquals(-11, testMapOrBuilder.getInt32ToInt32FieldOrDefault(-1, -11));
+
+ assertEquals("11", testMapOrBuilder.getInt32ToStringFieldOrDefault(1, "-11"));
+ assertNull("-11", testMapOrBuilder.getInt32ToStringFieldOrDefault(-1, null));
+
+ assertEquals(TestUtil.toBytes("11"), testMapOrBuilder.getInt32ToBytesFieldOrDefault(1, null));
+ assertNull(testMapOrBuilder.getInt32ToBytesFieldOrDefault(-1, null));
+
+ assertEquals(TestMap.EnumValue.FOO, testMapOrBuilder.getInt32ToEnumFieldOrDefault(1, null));
+ assertNull(testMapOrBuilder.getInt32ToEnumFieldOrDefault(-1, null));
+
+ assertEquals(
+ TestMap.EnumValue.BAR.getNumber(),
+ (int) testMapOrBuilder.getInt32ToEnumFieldValueOrDefault(2, -1));
+ assertEquals(-1, testMapOrBuilder.getInt32ToEnumFieldValueOrDefault(-1000, -1));
+
+ assertEquals(MessageValue.newBuilder().setValue(11).build(),
+ testMapOrBuilder.getInt32ToMessageFieldOrDefault(1, null));
+ assertNull(testMapOrBuilder.getInt32ToMessageFieldOrDefault(-1, null));
+
+ assertEquals(11, testMapOrBuilder.getStringToInt32FieldOrDefault("1", -11));
+ assertEquals(-11, testMapOrBuilder.getStringToInt32FieldOrDefault("-1", -11));
+
+ try {
+ testMapOrBuilder.getStringToInt32FieldOrDefault(null, -11);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void testGetOrThrow() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ assertMapCounts(0, builder);
+ setMapValuesUsingAccessors(builder);
+ doTestGetOrDefault(builder);
+ doTestGetOrDefault(builder.build());
+ }
+
+ public void doTestGetOrThrow(TestMapOrBuilder testMapOrBuilder) {
+ assertEquals(11, testMapOrBuilder.getInt32ToInt32FieldOrThrow(1));
+ try {
+ testMapOrBuilder.getInt32ToInt32FieldOrThrow(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ assertEquals("11", testMapOrBuilder.getInt32ToStringFieldOrThrow(1));
+
+ try {
+ testMapOrBuilder.getInt32ToStringFieldOrThrow(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ assertEquals(TestUtil.toBytes("11"), testMapOrBuilder.getInt32ToBytesFieldOrThrow(1));
+
+ try {
+ testMapOrBuilder.getInt32ToBytesFieldOrThrow(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ assertEquals(TestMap.EnumValue.FOO, testMapOrBuilder.getInt32ToEnumFieldOrThrow(1));
+ try {
+ testMapOrBuilder.getInt32ToEnumFieldOrThrow(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ assertEquals(
+ TestMap.EnumValue.BAR.getNumber(), testMapOrBuilder.getInt32ToEnumFieldValueOrThrow(2));
+ try {
+ testMapOrBuilder.getInt32ToEnumFieldValueOrThrow(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ assertEquals(MessageValue.newBuilder().setValue(11).build(),
+ testMapOrBuilder.getInt32ToMessageFieldOrThrow(1));
+ try {
+ testMapOrBuilder.getInt32ToMessageFieldOrThrow(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ assertEquals(11, testMapOrBuilder.getStringToInt32FieldOrThrow("1"));
+ try {
+ testMapOrBuilder.getStringToInt32FieldOrThrow("-1");
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ try {
+ testMapOrBuilder.getStringToInt32FieldOrThrow(null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void testPut() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ builder.putInt32ToInt32Field(1, 11);
+ assertEquals(11, builder.getInt32ToInt32FieldOrThrow(1));
+
+ builder.putInt32ToStringField(1, "a");
+ assertEquals("a", builder.getInt32ToStringFieldOrThrow(1));
+ try {
+ builder.putInt32ToStringField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ builder.putInt32ToBytesField(1, TestUtil.toBytes("11"));
+ assertEquals(TestUtil.toBytes("11"), builder.getInt32ToBytesFieldOrThrow(1));
+ try {
+ builder.putInt32ToBytesField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ builder.putInt32ToEnumField(1, TestMap.EnumValue.FOO);
+ assertEquals(TestMap.EnumValue.FOO, builder.getInt32ToEnumFieldOrThrow(1));
+ try {
+ builder.putInt32ToEnumField(1, null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ builder.putInt32ToEnumFieldValue(1, TestMap.EnumValue.BAR.getNumber());
+ assertEquals(
+ TestMap.EnumValue.BAR.getNumber(), builder.getInt32ToEnumFieldValueOrThrow(1));
+ try {
+ builder.putInt32ToEnumFieldValue(1, -1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ builder.putStringToInt32Field("a", 1);
+ assertEquals(1, builder.getStringToInt32FieldOrThrow("a"));
+ try {
+ builder.putStringToInt32Field(null, -1);
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void testRemove() {
+ TestMap.Builder builder = TestMap.newBuilder();
+ setMapValuesUsingAccessors(builder);
+ assertEquals(11, builder.getInt32ToInt32FieldOrThrow(1));
+ for (int times = 0; times < 2; times++) {
+ builder.removeInt32ToInt32Field(1);
+ assertEquals(-1, builder.getInt32ToInt32FieldOrDefault(1, -1));
+ }
+
+ assertEquals("11", builder.getInt32ToStringFieldOrThrow(1));
+ for (int times = 0; times < 2; times++) {
+ builder.removeInt32ToStringField(1);
+ assertNull(builder.getInt32ToStringFieldOrDefault(1, null));
+ }
+
+ assertEquals(TestUtil.toBytes("11"), builder.getInt32ToBytesFieldOrThrow(1));
+ for (int times = 0; times < 2; times++) {
+ builder.removeInt32ToBytesField(1);
+ assertNull(builder.getInt32ToBytesFieldOrDefault(1, null));
+ }
+
+ assertEquals(TestMap.EnumValue.FOO, builder.getInt32ToEnumFieldOrThrow(1));
+ for (int times = 0; times < 2; times++) {
+ builder.removeInt32ToEnumField(1);
+ assertNull(builder.getInt32ToEnumFieldOrDefault(1, null));
+ }
+
+ assertEquals(11, builder.getStringToInt32FieldOrThrow("1"));
+ for (int times = 0; times < 2; times++) {
+ builder.removeStringToInt32Field("1");
+ assertEquals(-1, builder.getStringToInt32FieldOrDefault("1", -1));
+ }
+
+ try {
+ builder.removeStringToInt32Field(null);
+ fail();
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ 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<Integer> int32Keys = new ArrayList<Integer>();
+ List<Integer> uint32Keys = new ArrayList<Integer>();
+ List<Long> int64Keys = new ArrayList<Long>();
+ List<String> stringKeys = new ArrayList<String>();
+ 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 <K, V> Map<K, V> newMap(K key1, V value1) {
+ Map<K, V> map = new HashMap<K, V>();
+ map.put(key1, value1);
+ return map;
+ }
+
+ private static <K, V> Map<K, V> newMap(K key1, V value1, K key2, V value2) {
+ Map<K, V> map = new HashMap<K, V>();
+ map.put(key1, value1);
+ map.put(key2, value2);
+ return map;
+ }
+
+ private static <K, V> Map<K, V> newMap(K key1, V value1, K key2, V value2, K key3, V value3) {
+ Map<K, V> map = new HashMap<K, V>();
+ map.put(key1, value1);
+ map.put(key2, value2);
+ map.put(key3, value3);
+ return map;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/MessageTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/MessageTest.java
new file mode 100644
index 0000000000..75b79a34e2
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/MessageTest.java
@@ -0,0 +1,351 @@
+// 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 protobuf_unittest.UnittestProto.ForeignMessage;
+import protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestRequired;
+import protobuf_unittest.UnittestProto.TestRequiredForeign;
+import java.util.List;
+import junit.framework.TestCase;
+
+/**
+ * Misc. unit tests for message operations that apply to both generated
+ * and dynamic messages.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class MessageTest extends TestCase {
+ // =================================================================
+ // Message-merging tests.
+
+ static final TestAllTypes MERGE_SOURCE =
+ TestAllTypes.newBuilder()
+ .setOptionalInt32(1)
+ .setOptionalString("foo")
+ .setOptionalForeignMessage(ForeignMessage.getDefaultInstance())
+ .addRepeatedString("bar")
+ .build();
+
+ static final TestAllTypes MERGE_DEST =
+ TestAllTypes.newBuilder()
+ .setOptionalInt64(2)
+ .setOptionalString("baz")
+ .setOptionalForeignMessage(ForeignMessage.newBuilder().setC(3).build())
+ .addRepeatedString("qux")
+ .build();
+
+ static final String MERGE_RESULT_TEXT =
+ "optional_int32: 1\n" +
+ "optional_int64: 2\n" +
+ "optional_string: \"foo\"\n" +
+ "optional_foreign_message {\n" +
+ " c: 3\n" +
+ "}\n" +
+ "repeated_string: \"qux\"\n" +
+ "repeated_string: \"bar\"\n";
+
+ public void testMergeFrom() throws Exception {
+ TestAllTypes result =
+ TestAllTypes.newBuilder(MERGE_DEST)
+ .mergeFrom(MERGE_SOURCE).build();
+
+ assertEquals(MERGE_RESULT_TEXT, result.toString());
+ }
+
+ /**
+ * Test merging a DynamicMessage into a GeneratedMessage. As long as they
+ * have the same descriptor, this should work, but it is an entirely different
+ * code path.
+ */
+ public void testMergeFromDynamic() throws Exception {
+ TestAllTypes result =
+ TestAllTypes.newBuilder(MERGE_DEST)
+ .mergeFrom(DynamicMessage.newBuilder(MERGE_SOURCE).build())
+ .build();
+
+ assertEquals(MERGE_RESULT_TEXT, result.toString());
+ }
+
+ /** Test merging two DynamicMessages. */
+ public void testDynamicMergeFrom() throws Exception {
+ DynamicMessage result =
+ DynamicMessage.newBuilder(MERGE_DEST)
+ .mergeFrom(DynamicMessage.newBuilder(MERGE_SOURCE).build())
+ .build();
+
+ assertEquals(MERGE_RESULT_TEXT, result.toString());
+ }
+
+ // =================================================================
+ // Required-field-related tests.
+
+ private static final TestRequired TEST_REQUIRED_UNINITIALIZED =
+ TestRequired.getDefaultInstance();
+ private static final TestRequired TEST_REQUIRED_INITIALIZED =
+ TestRequired.newBuilder().setA(1).setB(2).setC(3).build();
+
+ public void testRequired() throws Exception {
+ TestRequired.Builder builder = TestRequired.newBuilder();
+
+ assertFalse(builder.isInitialized());
+ builder.setA(1);
+ assertFalse(builder.isInitialized());
+ builder.setB(1);
+ assertFalse(builder.isInitialized());
+ builder.setC(1);
+ assertTrue(builder.isInitialized());
+ }
+
+ public void testRequiredForeign() throws Exception {
+ TestRequiredForeign.Builder builder = TestRequiredForeign.newBuilder();
+
+ assertTrue(builder.isInitialized());
+
+ builder.setOptionalMessage(TEST_REQUIRED_UNINITIALIZED);
+ assertFalse(builder.isInitialized());
+
+ builder.setOptionalMessage(TEST_REQUIRED_INITIALIZED);
+ assertTrue(builder.isInitialized());
+
+ builder.addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED);
+ assertFalse(builder.isInitialized());
+
+ builder.setRepeatedMessage(0, TEST_REQUIRED_INITIALIZED);
+ assertTrue(builder.isInitialized());
+ }
+
+ public void testRequiredExtension() throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+
+ assertTrue(builder.isInitialized());
+
+ builder.setExtension(TestRequired.single, TEST_REQUIRED_UNINITIALIZED);
+ assertFalse(builder.isInitialized());
+
+ builder.setExtension(TestRequired.single, TEST_REQUIRED_INITIALIZED);
+ assertTrue(builder.isInitialized());
+
+ builder.addExtension(TestRequired.multi, TEST_REQUIRED_UNINITIALIZED);
+ assertFalse(builder.isInitialized());
+
+ builder.setExtension(TestRequired.multi, 0, TEST_REQUIRED_INITIALIZED);
+ assertTrue(builder.isInitialized());
+ }
+
+ public void testRequiredDynamic() throws Exception {
+ Descriptors.Descriptor descriptor = TestRequired.getDescriptor();
+ DynamicMessage.Builder builder = DynamicMessage.newBuilder(descriptor);
+
+ assertFalse(builder.isInitialized());
+ builder.setField(descriptor.findFieldByName("a"), 1);
+ assertFalse(builder.isInitialized());
+ builder.setField(descriptor.findFieldByName("b"), 1);
+ assertFalse(builder.isInitialized());
+ builder.setField(descriptor.findFieldByName("c"), 1);
+ assertTrue(builder.isInitialized());
+ }
+
+ public void testRequiredDynamicForeign() throws Exception {
+ Descriptors.Descriptor descriptor = TestRequiredForeign.getDescriptor();
+ DynamicMessage.Builder builder = DynamicMessage.newBuilder(descriptor);
+
+ assertTrue(builder.isInitialized());
+
+ builder.setField(descriptor.findFieldByName("optional_message"),
+ TEST_REQUIRED_UNINITIALIZED);
+ assertFalse(builder.isInitialized());
+
+ builder.setField(descriptor.findFieldByName("optional_message"),
+ TEST_REQUIRED_INITIALIZED);
+ assertTrue(builder.isInitialized());
+
+ builder.addRepeatedField(descriptor.findFieldByName("repeated_message"),
+ TEST_REQUIRED_UNINITIALIZED);
+ assertFalse(builder.isInitialized());
+
+ builder.setRepeatedField(descriptor.findFieldByName("repeated_message"), 0,
+ TEST_REQUIRED_INITIALIZED);
+ assertTrue(builder.isInitialized());
+ }
+
+ public void testUninitializedException() throws Exception {
+ try {
+ TestRequired.newBuilder().build();
+ fail("Should have thrown an exception.");
+ } catch (UninitializedMessageException e) {
+ assertEquals("Message missing required fields: a, b, c", e.getMessage());
+ }
+ }
+
+ public void testBuildPartial() throws Exception {
+ // We're mostly testing that no exception is thrown.
+ TestRequired message = TestRequired.newBuilder().buildPartial();
+ assertFalse(message.isInitialized());
+ }
+
+ public void testNestedUninitializedException() throws Exception {
+ try {
+ TestRequiredForeign.newBuilder()
+ .setOptionalMessage(TEST_REQUIRED_UNINITIALIZED)
+ .addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED)
+ .addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED)
+ .build();
+ fail("Should have thrown an exception.");
+ } catch (UninitializedMessageException e) {
+ assertEquals(
+ "Message missing required fields: " +
+ "optional_message.a, " +
+ "optional_message.b, " +
+ "optional_message.c, " +
+ "repeated_message[0].a, " +
+ "repeated_message[0].b, " +
+ "repeated_message[0].c, " +
+ "repeated_message[1].a, " +
+ "repeated_message[1].b, " +
+ "repeated_message[1].c",
+ e.getMessage());
+ }
+ }
+
+ public void testBuildNestedPartial() throws Exception {
+ // We're mostly testing that no exception is thrown.
+ TestRequiredForeign message =
+ TestRequiredForeign.newBuilder()
+ .setOptionalMessage(TEST_REQUIRED_UNINITIALIZED)
+ .addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED)
+ .addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED)
+ .buildPartial();
+ assertFalse(message.isInitialized());
+ }
+
+ public void testParseUnititialized() throws Exception {
+ try {
+ TestRequired.parseFrom(ByteString.EMPTY);
+ fail("Should have thrown an exception.");
+ } catch (InvalidProtocolBufferException e) {
+ assertEquals("Message missing required fields: a, b, c", e.getMessage());
+ }
+ }
+
+ public void testParseNestedUnititialized() throws Exception {
+ ByteString data =
+ TestRequiredForeign.newBuilder()
+ .setOptionalMessage(TEST_REQUIRED_UNINITIALIZED)
+ .addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED)
+ .addRepeatedMessage(TEST_REQUIRED_UNINITIALIZED)
+ .buildPartial().toByteString();
+
+ try {
+ TestRequiredForeign.parseFrom(data);
+ fail("Should have thrown an exception.");
+ } catch (InvalidProtocolBufferException e) {
+ assertEquals(
+ "Message missing required fields: " +
+ "optional_message.a, " +
+ "optional_message.b, " +
+ "optional_message.c, " +
+ "repeated_message[0].a, " +
+ "repeated_message[0].b, " +
+ "repeated_message[0].c, " +
+ "repeated_message[1].a, " +
+ "repeated_message[1].b, " +
+ "repeated_message[1].c",
+ e.getMessage());
+ }
+ }
+
+ public void testDynamicUninitializedException() throws Exception {
+ try {
+ DynamicMessage.newBuilder(TestRequired.getDescriptor()).build();
+ fail("Should have thrown an exception.");
+ } catch (UninitializedMessageException e) {
+ assertEquals("Message missing required fields: a, b, c", e.getMessage());
+ }
+ }
+
+ public void testDynamicBuildPartial() throws Exception {
+ // We're mostly testing that no exception is thrown.
+ DynamicMessage message =
+ DynamicMessage.newBuilder(TestRequired.getDescriptor())
+ .buildPartial();
+ assertFalse(message.isInitialized());
+ }
+
+ public void testDynamicParseUnititialized() throws Exception {
+ try {
+ Descriptors.Descriptor descriptor = TestRequired.getDescriptor();
+ DynamicMessage.parseFrom(descriptor, ByteString.EMPTY);
+ fail("Should have thrown an exception.");
+ } catch (InvalidProtocolBufferException e) {
+ assertEquals("Message missing required fields: a, b, c", e.getMessage());
+ }
+ }
+
+ /** Test reading unset repeated message from DynamicMessage. */
+ public void testDynamicRepeatedMessageNull() throws Exception {
+ Descriptors.Descriptor descriptor = TestRequired.getDescriptor();
+ DynamicMessage result =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor())
+ .mergeFrom(DynamicMessage.newBuilder(MERGE_SOURCE).build())
+ .build();
+
+ assertTrue(result.getField(result.getDescriptorForType()
+ .findFieldByName("repeated_foreign_message")) instanceof List<?>);
+ assertEquals(result.getRepeatedFieldCount(result.getDescriptorForType()
+ .findFieldByName("repeated_foreign_message")), 0);
+ }
+
+ /** Test reading repeated message from DynamicMessage. */
+ public void testDynamicRepeatedMessageNotNull() throws Exception {
+
+ TestAllTypes REPEATED_NESTED =
+ TestAllTypes.newBuilder()
+ .setOptionalInt32(1)
+ .setOptionalString("foo")
+ .setOptionalForeignMessage(ForeignMessage.getDefaultInstance())
+ .addRepeatedString("bar")
+ .addRepeatedForeignMessage(ForeignMessage.getDefaultInstance())
+ .addRepeatedForeignMessage(ForeignMessage.getDefaultInstance())
+ .build();
+ Descriptors.Descriptor descriptor = TestRequired.getDescriptor();
+ DynamicMessage result =
+ DynamicMessage.newBuilder(TestAllTypes.getDescriptor())
+ .mergeFrom(DynamicMessage.newBuilder(REPEATED_NESTED).build())
+ .build();
+
+ assertTrue(result.getField(result.getDescriptorForType()
+ .findFieldByName("repeated_foreign_message")) instanceof List<?>);
+ assertEquals(result.getRepeatedFieldCount(result.getDescriptorForType()
+ .findFieldByName("repeated_foreign_message")), 2);
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/NestedBuildersTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/NestedBuildersTest.java
new file mode 100644
index 0000000000..03ed65a550
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/NestedBuildersTest.java
@@ -0,0 +1,183 @@
+// 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 protobuf_unittest.Vehicle;
+import protobuf_unittest.Wheel;
+import java.util.ArrayList;
+import java.util.List;
+import junit.framework.TestCase;
+
+/**
+ * Test cases that exercise end-to-end use cases involving
+ * {@link SingleFieldBuilder} and {@link RepeatedFieldBuilder}.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class NestedBuildersTest extends TestCase {
+
+ public void testMessagesAndBuilders() {
+ Vehicle.Builder vehicleBuilder = Vehicle.newBuilder();
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(4)
+ .setWidth(1);
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(4)
+ .setWidth(2);
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(4)
+ .setWidth(3);
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(4)
+ .setWidth(4);
+ vehicleBuilder.getEngineBuilder()
+ .setLiters(10);
+
+ Vehicle vehicle = vehicleBuilder.build();
+ assertEquals(4, vehicle.getWheelCount());
+ for (int i = 0; i < 4; i++) {
+ Wheel wheel = vehicle.getWheel(i);
+ assertEquals(4, wheel.getRadius());
+ assertEquals(i + 1, wheel.getWidth());
+ }
+ assertEquals(10, vehicle.getEngine().getLiters());
+
+ for (int i = 0; i < 4; i++) {
+ vehicleBuilder.getWheelBuilder(i)
+ .setRadius(5)
+ .setWidth(i + 10);
+ }
+ vehicleBuilder.getEngineBuilder().setLiters(20);
+
+ vehicle = vehicleBuilder.build();
+ for (int i = 0; i < 4; i++) {
+ Wheel wheel = vehicle.getWheel(i);
+ assertEquals(5, wheel.getRadius());
+ assertEquals(i + 10, wheel.getWidth());
+ }
+ assertEquals(20, vehicle.getEngine().getLiters());
+ assertTrue(vehicle.hasEngine());
+ }
+
+ public void testMessagesAreCached() {
+ Vehicle.Builder vehicleBuilder = Vehicle.newBuilder();
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(1)
+ .setWidth(2);
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(3)
+ .setWidth(4);
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(5)
+ .setWidth(6);
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(7)
+ .setWidth(8);
+
+ // Make sure messages are cached.
+ List<Wheel> wheels = new ArrayList<Wheel>(vehicleBuilder.getWheelList());
+ for (int i = 0; i < wheels.size(); i++) {
+ assertSame(wheels.get(i), vehicleBuilder.getWheel(i));
+ }
+
+ // Now get builders and check they didn't change.
+ for (int i = 0; i < wheels.size(); i++) {
+ vehicleBuilder.getWheel(i);
+ }
+ for (int i = 0; i < wheels.size(); i++) {
+ assertSame(wheels.get(i), vehicleBuilder.getWheel(i));
+ }
+
+ // Change just one
+ vehicleBuilder.getWheelBuilder(3)
+ .setRadius(20).setWidth(20);
+
+ // Now get wheels and check that only that one changed
+ for (int i = 0; i < wheels.size(); i++) {
+ if (i < 3) {
+ assertSame(wheels.get(i), vehicleBuilder.getWheel(i));
+ } else {
+ assertNotSame(wheels.get(i), vehicleBuilder.getWheel(i));
+ }
+ }
+ }
+
+ public void testRemove_WithNestedBuilders() {
+ Vehicle.Builder vehicleBuilder = Vehicle.newBuilder();
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(1)
+ .setWidth(1);
+ vehicleBuilder.addWheelBuilder()
+ .setRadius(2)
+ .setWidth(2);
+ vehicleBuilder.removeWheel(0);
+
+ assertEquals(1, vehicleBuilder.getWheelCount());
+ assertEquals(2, vehicleBuilder.getWheel(0).getRadius());
+ }
+
+ public void testRemove_WithNestedMessages() {
+ Vehicle.Builder vehicleBuilder = Vehicle.newBuilder();
+ vehicleBuilder.addWheel(Wheel.newBuilder()
+ .setRadius(1)
+ .setWidth(1));
+ vehicleBuilder.addWheel(Wheel.newBuilder()
+ .setRadius(2)
+ .setWidth(2));
+ vehicleBuilder.removeWheel(0);
+
+ assertEquals(1, vehicleBuilder.getWheelCount());
+ assertEquals(2, vehicleBuilder.getWheel(0).getRadius());
+ }
+
+ public void testMerge() {
+ Vehicle vehicle1 = Vehicle.newBuilder()
+ .addWheel(Wheel.newBuilder().setRadius(1).build())
+ .addWheel(Wheel.newBuilder().setRadius(2).build())
+ .build();
+
+ Vehicle vehicle2 = Vehicle.newBuilder()
+ .mergeFrom(vehicle1)
+ .build();
+ // List should be the same -- no allocation
+ assertSame(vehicle1.getWheelList(), vehicle2.getWheelList());
+
+ Vehicle vehicle3 = vehicle1.toBuilder().build();
+ assertSame(vehicle1.getWheelList(), vehicle3.getWheelList());
+ }
+
+ public void testGettingBuilderMarksFieldAsHaving() {
+ Vehicle.Builder vehicleBuilder = Vehicle.newBuilder();
+ vehicleBuilder.getEngineBuilder();
+ Vehicle vehicle = vehicleBuilder.buildPartial();
+ assertTrue(vehicle.hasEngine());
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java
new file mode 100644
index 0000000000..c388bd0561
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/NioByteStringTest.java
@@ -0,0 +1,619 @@
+// 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 static com.google.protobuf.Internal.UTF_8;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.List;
+import java.util.NoSuchElementException;
+import junit.framework.TestCase;
+
+/**
+ * Tests for {@link NioByteString}.
+ */
+public class NioByteStringTest extends TestCase {
+ private static final ByteString EMPTY = new NioByteString(ByteBuffer.wrap(new byte[0]));
+ private static final String CLASSNAME = NioByteString.class.getSimpleName();
+ private static final byte[] BYTES = ByteStringTest.getTestBytes(1234, 11337766L);
+ private static final int EXPECTED_HASH = ByteString.wrap(BYTES).hashCode();
+
+ private final ByteBuffer backingBuffer = ByteBuffer.wrap(BYTES.clone());
+ private final ByteString testString = new NioByteString(backingBuffer);
+
+ public void testExpectedType() {
+ String actualClassName = getActualClassName(testString);
+ assertEquals(CLASSNAME + " should match type exactly", CLASSNAME, actualClassName);
+ }
+
+ protected String getActualClassName(Object object) {
+ String actualClassName = object.getClass().getName();
+ actualClassName = actualClassName.substring(actualClassName.lastIndexOf('.') + 1);
+ return actualClassName;
+ }
+
+ public void testByteAt() {
+ boolean stillEqual = true;
+ for (int i = 0; stillEqual && i < BYTES.length; ++i) {
+ stillEqual = (BYTES[i] == testString.byteAt(i));
+ }
+ assertTrue(CLASSNAME + " must capture the right bytes", stillEqual);
+ }
+
+ public void testByteIterator() {
+ boolean stillEqual = true;
+ ByteString.ByteIterator iter = testString.iterator();
+ for (int i = 0; stillEqual && i < BYTES.length; ++i) {
+ stillEqual = (iter.hasNext() && BYTES[i] == iter.nextByte());
+ }
+ assertTrue(CLASSNAME + " must capture the right bytes", stillEqual);
+ assertFalse(CLASSNAME + " must have exhausted the itertor", iter.hasNext());
+
+ try {
+ iter.nextByte();
+ fail("Should have thrown an exception.");
+ } catch (NoSuchElementException e) {
+ // This is success
+ }
+ }
+
+ public void testByteIterable() {
+ boolean stillEqual = true;
+ int j = 0;
+ for (byte quantum : testString) {
+ stillEqual = (BYTES[j] == quantum);
+ ++j;
+ }
+ assertTrue(CLASSNAME + " must capture the right bytes as Bytes", stillEqual);
+ assertEquals(CLASSNAME + " iterable character count", BYTES.length, j);
+ }
+
+ public void testSize() {
+ assertEquals(CLASSNAME + " must have the expected size", BYTES.length,
+ testString.size());
+ }
+
+ public void testGetTreeDepth() {
+ assertEquals(CLASSNAME + " must have depth 0", 0, testString.getTreeDepth());
+ }
+
+ public void testIsBalanced() {
+ assertTrue(CLASSNAME + " is technically balanced", testString.isBalanced());
+ }
+
+ public void testCopyTo_ByteArrayOffsetLength() {
+ int destinationOffset = 50;
+ int length = 100;
+ byte[] destination = new byte[destinationOffset + length];
+ int sourceOffset = 213;
+ testString.copyTo(destination, sourceOffset, destinationOffset, length);
+ boolean stillEqual = true;
+ for (int i = 0; stillEqual && i < length; ++i) {
+ stillEqual = BYTES[i + sourceOffset] == destination[i + destinationOffset];
+ }
+ assertTrue(CLASSNAME + ".copyTo(4 arg) must give the expected bytes", stillEqual);
+ }
+
+ public void testCopyTo_ByteArrayOffsetLengthErrors() {
+ int destinationOffset = 50;
+ int length = 100;
+ byte[] destination = new byte[destinationOffset + length];
+
+ try {
+ // Copy one too many bytes
+ testString.copyTo(destination, testString.size() + 1 - length,
+ destinationOffset, length);
+ fail("Should have thrown an exception when copying too many bytes of a "
+ + CLASSNAME);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+
+ try {
+ // Copy with illegal negative sourceOffset
+ testString.copyTo(destination, -1, destinationOffset, length);
+ fail("Should have thrown an exception when given a negative sourceOffset in "
+ + CLASSNAME);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+
+ try {
+ // Copy with illegal negative destinationOffset
+ testString.copyTo(destination, 0, -1, length);
+ fail("Should have thrown an exception when given a negative destinationOffset in "
+ + CLASSNAME);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+
+ try {
+ // Copy with illegal negative size
+ testString.copyTo(destination, 0, 0, -1);
+ fail("Should have thrown an exception when given a negative size in "
+ + CLASSNAME);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+
+ try {
+ // Copy with illegal too-large sourceOffset
+ testString.copyTo(destination, 2 * testString.size(), 0, length);
+ fail("Should have thrown an exception when the destinationOffset is too large in "
+ + CLASSNAME);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+
+ try {
+ // Copy with illegal too-large destinationOffset
+ testString.copyTo(destination, 0, 2 * destination.length, length);
+ fail("Should have thrown an exception when the destinationOffset is too large in "
+ + CLASSNAME);
+ } catch (IndexOutOfBoundsException expected) {
+ // This is success
+ }
+ }
+
+ public void testCopyTo_ByteBuffer() {
+ // Same length.
+ ByteBuffer myBuffer = ByteBuffer.allocate(BYTES.length);
+ testString.copyTo(myBuffer);
+ myBuffer.flip();
+ assertEquals(CLASSNAME + ".copyTo(ByteBuffer) must give back the same bytes",
+ backingBuffer, myBuffer);
+
+ // Target buffer bigger than required.
+ myBuffer = ByteBuffer.allocate(testString.size() + 1);
+ testString.copyTo(myBuffer);
+ myBuffer.flip();
+ assertEquals(backingBuffer, myBuffer);
+
+ // Target buffer has no space.
+ myBuffer = ByteBuffer.allocate(0);
+ try {
+ testString.copyTo(myBuffer);
+ fail("Should have thrown an exception when target ByteBuffer has insufficient capacity");
+ } catch (BufferOverflowException e) {
+ // Expected.
+ }
+
+ // Target buffer too small.
+ myBuffer = ByteBuffer.allocate(1);
+ try {
+ testString.copyTo(myBuffer);
+ fail("Should have thrown an exception when target ByteBuffer has insufficient capacity");
+ } catch (BufferOverflowException e) {
+ // Expected.
+ }
+ }
+
+ public void testMarkSupported() {
+ InputStream stream = testString.newInput();
+ assertTrue(CLASSNAME + ".newInput() must support marking", stream.markSupported());
+ }
+
+ public void testMarkAndReset() throws IOException {
+ int fraction = testString.size() / 3;
+
+ InputStream stream = testString.newInput();
+ stream.mark(testString.size()); // First, mark() the end.
+
+ skipFully(stream, fraction); // Skip a large fraction, but not all.
+ assertEquals(
+ CLASSNAME + ": after skipping to the 'middle', half the bytes are available",
+ (testString.size() - fraction), stream.available());
+ stream.reset();
+ assertEquals(
+ CLASSNAME + ": after resetting, all bytes are available",
+ testString.size(), stream.available());
+
+ skipFully(stream, testString.size()); // Skip to the end.
+ assertEquals(
+ CLASSNAME + ": after skipping to the end, no more bytes are available",
+ 0, stream.available());
+ }
+
+ /**
+ * Discards {@code n} bytes of data from the input stream. This method
+ * will block until the full amount has been skipped. Does not close the
+ * stream.
+ * <p>Copied from com.google.common.io.ByteStreams to avoid adding dependency.
+ *
+ * @param in the input stream to read from
+ * @param n the number of bytes to skip
+ * @throws EOFException if this stream reaches the end before skipping all
+ * the bytes
+ * @throws IOException if an I/O error occurs, or the stream does not
+ * support skipping
+ */
+ static void skipFully(InputStream in, long n) throws IOException {
+ long toSkip = n;
+ while (n > 0) {
+ long amt = in.skip(n);
+ if (amt == 0) {
+ // Force a blocking read to avoid infinite loop
+ if (in.read() == -1) {
+ long skipped = toSkip - n;
+ throw new EOFException("reached end of stream after skipping "
+ + skipped + " bytes; " + toSkip + " bytes expected");
+ }
+ n--;
+ } else {
+ n -= amt;
+ }
+ }
+ }
+
+ public void testAsReadOnlyByteBuffer() {
+ ByteBuffer byteBuffer = testString.asReadOnlyByteBuffer();
+ byte[] roundTripBytes = new byte[BYTES.length];
+ assertTrue(byteBuffer.remaining() == BYTES.length);
+ assertTrue(byteBuffer.isReadOnly());
+ byteBuffer.get(roundTripBytes);
+ assertTrue(CLASSNAME + ".asReadOnlyByteBuffer() must give back the same bytes",
+ Arrays.equals(BYTES, roundTripBytes));
+ }
+
+ public void testAsReadOnlyByteBufferList() {
+ List<ByteBuffer> byteBuffers = testString.asReadOnlyByteBufferList();
+ int bytesSeen = 0;
+ byte[] roundTripBytes = new byte[BYTES.length];
+ for (ByteBuffer byteBuffer : byteBuffers) {
+ int thisLength = byteBuffer.remaining();
+ assertTrue(byteBuffer.isReadOnly());
+ assertTrue(bytesSeen + thisLength <= BYTES.length);
+ byteBuffer.get(roundTripBytes, bytesSeen, thisLength);
+ bytesSeen += thisLength;
+ }
+ assertTrue(bytesSeen == BYTES.length);
+ assertTrue(CLASSNAME + ".asReadOnlyByteBufferTest() must give back the same bytes",
+ Arrays.equals(BYTES, roundTripBytes));
+ }
+
+ public void testToByteArray() {
+ byte[] roundTripBytes = testString.toByteArray();
+ assertTrue(CLASSNAME + ".toByteArray() must give back the same bytes",
+ Arrays.equals(BYTES, roundTripBytes));
+ }
+
+ public void testWriteTo() throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ testString.writeTo(bos);
+ byte[] roundTripBytes = bos.toByteArray();
+ assertTrue(CLASSNAME + ".writeTo() must give back the same bytes",
+ Arrays.equals(BYTES, roundTripBytes));
+ }
+
+ public void testWriteToShouldNotExposeInternalBufferToOutputStream() throws IOException {
+ OutputStream os = new OutputStream() {
+ @Override
+ public void write(byte[] b, int off, int len) {
+ Arrays.fill(b, off, off + len, (byte) 0);
+ }
+
+ @Override
+ public void write(int b) {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+ byte[] original = Arrays.copyOf(BYTES, BYTES.length);
+ testString.writeTo(os);
+ assertTrue(CLASSNAME + ".writeTo() must NOT grant access to underlying buffer",
+ Arrays.equals(original, BYTES));
+ }
+
+ public void testWriteToInternalShouldExposeInternalBufferToOutputStream() throws IOException {
+ OutputStream os = new OutputStream() {
+ @Override
+ public void write(byte[] b, int off, int len) {
+ Arrays.fill(b, off, off + len, (byte) 0);
+ }
+
+ @Override
+ public void write(int b) {
+ throw new UnsupportedOperationException();
+ }
+ };
+
+ testString.writeToInternal(os, 0, testString.size());
+ byte[] allZeros = new byte[testString.size()];
+ assertTrue(CLASSNAME + ".writeToInternal() must grant access to underlying buffer",
+ Arrays.equals(allZeros, backingBuffer.array()));
+ }
+
+ public void testWriteToShouldExposeInternalBufferToByteOutput() throws IOException {
+ ByteOutput out = new ByteOutput() {
+ @Override
+ public void write(byte value) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void write(byte[] value, int offset, int length) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void writeLazy(byte[] value, int offset, int length) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void write(ByteBuffer value) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void writeLazy(ByteBuffer value) throws IOException {
+ Arrays.fill(value.array(), value.arrayOffset(), value.arrayOffset() + value.limit(),
+ (byte) 0);
+ }
+ };
+
+ testString.writeTo(out);
+ byte[] allZeros = new byte[testString.size()];
+ assertTrue(CLASSNAME + ".writeTo() must grant access to underlying buffer",
+ Arrays.equals(allZeros, backingBuffer.array()));
+ }
+
+ public void testNewOutput() throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ByteString.Output output = ByteString.newOutput();
+ testString.writeTo(output);
+ assertEquals("Output Size returns correct result",
+ output.size(), testString.size());
+ output.writeTo(bos);
+ assertTrue("Output.writeTo() must give back the same bytes",
+ Arrays.equals(BYTES, bos.toByteArray()));
+
+ // write the output stream to itself! This should cause it to double
+ output.writeTo(output);
+ assertEquals("Writing an output stream to itself is successful",
+ testString.concat(testString), output.toByteString());
+
+ output.reset();
+ assertEquals("Output.reset() resets the output", 0, output.size());
+ assertEquals("Output.reset() resets the output",
+ EMPTY, output.toByteString());
+ }
+
+ public void testToString() {
+ String testString = "I love unicode \u1234\u5678 characters";
+ ByteString unicode = forString(testString);
+ String roundTripString = unicode.toString(UTF_8);
+ assertEquals(CLASSNAME + " unicode must match", testString, roundTripString);
+ }
+
+ public void testCharsetToString() {
+ String testString = "I love unicode \u1234\u5678 characters";
+ ByteString unicode = forString(testString);
+ String roundTripString = unicode.toString(UTF_8);
+ assertEquals(CLASSNAME + " unicode must match", testString, roundTripString);
+ }
+
+ public void testToString_returnsCanonicalEmptyString() {
+ assertSame(CLASSNAME + " must be the same string references",
+ EMPTY.toString(UTF_8),
+ new NioByteString(ByteBuffer.wrap(new byte[0])).toString(UTF_8));
+ }
+
+ public void testToString_raisesException() {
+ try {
+ EMPTY.toString("invalid");
+ fail("Should have thrown an exception.");
+ } catch (UnsupportedEncodingException expected) {
+ // This is success
+ }
+
+ try {
+ testString.toString("invalid");
+ fail("Should have thrown an exception.");
+ } catch (UnsupportedEncodingException expected) {
+ // This is success
+ }
+ }
+
+ public void testEquals() {
+ assertEquals(CLASSNAME + " must not equal null", false, testString.equals(null));
+ assertEquals(CLASSNAME + " must equal self", testString, testString);
+ assertFalse(CLASSNAME + " must not equal the empty string",
+ testString.equals(EMPTY));
+ assertEquals(CLASSNAME + " empty strings must be equal",
+ EMPTY, testString.substring(55, 55));
+ assertEquals(CLASSNAME + " must equal another string with the same value",
+ testString, new NioByteString(backingBuffer));
+
+ byte[] mungedBytes = mungedBytes();
+ assertFalse(CLASSNAME + " must not equal every string with the same length",
+ testString.equals(new NioByteString(ByteBuffer.wrap(mungedBytes))));
+ }
+
+ public void testEqualsLiteralByteString() {
+ ByteString literal = ByteString.copyFrom(BYTES);
+ assertEquals(CLASSNAME + " must equal LiteralByteString with same value", literal,
+ testString);
+ assertEquals(CLASSNAME + " must equal LiteralByteString with same value", testString,
+ literal);
+ assertFalse(CLASSNAME + " must not equal the empty string",
+ testString.equals(ByteString.EMPTY));
+ assertEquals(CLASSNAME + " empty strings must be equal",
+ ByteString.EMPTY, testString.substring(55, 55));
+
+ literal = ByteString.copyFrom(mungedBytes());
+ assertFalse(CLASSNAME + " must not equal every LiteralByteString with the same length",
+ testString.equals(literal));
+ assertFalse(CLASSNAME + " must not equal every LiteralByteString with the same length",
+ literal.equals(testString));
+ }
+
+ public void testEqualsRopeByteString() {
+ ByteString p1 = ByteString.copyFrom(BYTES, 0, 5);
+ ByteString p2 = ByteString.copyFrom(BYTES, 5, BYTES.length - 5);
+ ByteString rope = p1.concat(p2);
+
+ assertEquals(CLASSNAME + " must equal RopeByteString with same value", rope,
+ testString);
+ assertEquals(CLASSNAME + " must equal RopeByteString with same value", testString,
+ rope);
+ assertFalse(CLASSNAME + " must not equal the empty string",
+ testString.equals(ByteString.EMPTY.concat(ByteString.EMPTY)));
+ assertEquals(CLASSNAME + " empty strings must be equal",
+ ByteString.EMPTY.concat(ByteString.EMPTY), testString.substring(55, 55));
+
+ byte[] mungedBytes = mungedBytes();
+ p1 = ByteString.copyFrom(mungedBytes, 0, 5);
+ p2 = ByteString.copyFrom(mungedBytes, 5, mungedBytes.length - 5);
+ rope = p1.concat(p2);
+ assertFalse(CLASSNAME + " must not equal every RopeByteString with the same length",
+ testString.equals(rope));
+ assertFalse(CLASSNAME + " must not equal every RopeByteString with the same length",
+ rope.equals(testString));
+ }
+
+ private byte[] mungedBytes() {
+ byte[] mungedBytes = new byte[BYTES.length];
+ System.arraycopy(BYTES, 0, mungedBytes, 0, BYTES.length);
+ mungedBytes[mungedBytes.length - 5] = (byte) (mungedBytes[mungedBytes.length - 5] ^ 0xFF);
+ return mungedBytes;
+ }
+
+ public void testHashCode() {
+ int hash = testString.hashCode();
+ assertEquals(CLASSNAME + " must have expected hashCode", EXPECTED_HASH, hash);
+ }
+
+ public void testPeekCachedHashCode() {
+ ByteString newString = new NioByteString(backingBuffer);
+ assertEquals(CLASSNAME + ".peekCachedHashCode() should return zero at first", 0,
+ newString.peekCachedHashCode());
+ newString.hashCode();
+ assertEquals(CLASSNAME + ".peekCachedHashCode should return zero at first",
+ EXPECTED_HASH, newString.peekCachedHashCode());
+ }
+
+ public void testPartialHash() {
+ // partialHash() is more strenuously tested elsewhere by testing hashes of substrings.
+ // This test would fail if the expected hash were 1. It's not.
+ int hash = testString.partialHash(testString.size(), 0, testString.size());
+ assertEquals(CLASSNAME + ".partialHash() must yield expected hashCode",
+ EXPECTED_HASH, hash);
+ }
+
+ public void testNewInput() throws IOException {
+ InputStream input = testString.newInput();
+ assertEquals("InputStream.available() returns correct value",
+ testString.size(), input.available());
+ boolean stillEqual = true;
+ for (byte referenceByte : BYTES) {
+ int expectedInt = (referenceByte & 0xFF);
+ stillEqual = (expectedInt == input.read());
+ }
+ assertEquals("InputStream.available() returns correct value",
+ 0, input.available());
+ assertTrue(CLASSNAME + " must give the same bytes from the InputStream", stillEqual);
+ assertEquals(CLASSNAME + " InputStream must now be exhausted", -1, input.read());
+ }
+
+ public void testNewInput_skip() throws IOException {
+ InputStream input = testString.newInput();
+ int stringSize = testString.size();
+ int nearEndIndex = stringSize * 2 / 3;
+ long skipped1 = input.skip(nearEndIndex);
+ assertEquals("InputStream.skip()", skipped1, nearEndIndex);
+ assertEquals("InputStream.available()",
+ stringSize - skipped1, input.available());
+ assertTrue("InputStream.mark() is available", input.markSupported());
+ input.mark(0);
+ assertEquals("InputStream.skip(), read()",
+ testString.byteAt(nearEndIndex) & 0xFF, input.read());
+ assertEquals("InputStream.available()",
+ stringSize - skipped1 - 1, input.available());
+ long skipped2 = input.skip(stringSize);
+ assertEquals("InputStream.skip() incomplete",
+ skipped2, stringSize - skipped1 - 1);
+ assertEquals("InputStream.skip(), no more input", 0, input.available());
+ assertEquals("InputStream.skip(), no more input", -1, input.read());
+ input.reset();
+ assertEquals("InputStream.reset() succeded",
+ stringSize - skipped1, input.available());
+ assertEquals("InputStream.reset(), read()",
+ testString.byteAt(nearEndIndex) & 0xFF, input.read());
+ }
+
+ public void testNewCodedInput() throws IOException {
+ CodedInputStream cis = testString.newCodedInput();
+ byte[] roundTripBytes = cis.readRawBytes(BYTES.length);
+ assertTrue(CLASSNAME + " must give the same bytes back from the CodedInputStream",
+ Arrays.equals(BYTES, roundTripBytes));
+ assertTrue(CLASSNAME + " CodedInputStream must now be exhausted", cis.isAtEnd());
+ }
+
+ /**
+ * Make sure we keep things simple when concatenating with empty. See also
+ * {@link ByteStringTest#testConcat_empty()}.
+ */
+ public void testConcat_empty() {
+ assertSame(CLASSNAME + " concatenated with empty must give " + CLASSNAME,
+ testString.concat(EMPTY), testString);
+ assertSame("empty concatenated with " + CLASSNAME + " must give " + CLASSNAME,
+ EMPTY.concat(testString), testString);
+ }
+
+ public void testJavaSerialization() throws Exception {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(out);
+ oos.writeObject(testString);
+ oos.close();
+ byte[] pickled = out.toByteArray();
+ InputStream in = new ByteArrayInputStream(pickled);
+ ObjectInputStream ois = new ObjectInputStream(in);
+ Object o = ois.readObject();
+ assertTrue("Didn't get a ByteString back", o instanceof ByteString);
+ assertEquals("Should get an equal ByteString back", testString, o);
+ }
+
+ private static ByteString forString(String str) {
+ return new NioByteString(ByteBuffer.wrap(str.getBytes(UTF_8)));
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ParseExceptionsTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ParseExceptionsTest.java
new file mode 100644
index 0000000000..e376b1cd72
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ParseExceptionsTest.java
@@ -0,0 +1,271 @@
+// 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import com.google.protobuf.DescriptorProtos.DescriptorProto;
+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}
+ * interface are specified to only throw {@link InvalidProtocolBufferException}. But we really want
+ * to distinguish between invalid protos vs. actual I/O errors (like failures reading from a
+ * socket, etc.). So, when we're not using the parser directly, an {@link IOException} should be
+ * thrown where appropriate, instead of always an {@link InvalidProtocolBufferException}.
+ *
+ * @author jh@squareup.com (Joshua Humphries)
+ */
+@RunWith(JUnit4.class)
+public class ParseExceptionsTest {
+
+ private interface ParseTester {
+ DescriptorProto parse(InputStream in) throws IOException;
+ }
+
+ private byte serializedProto[];
+
+ private void setup() {
+ serializedProto = DescriptorProto.getDescriptor().toProto().toByteArray();
+ }
+
+ private void setupDelimited() {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ try {
+ DescriptorProto.getDescriptor().toProto().writeDelimitedTo(bos);
+ } catch (IOException e) {
+ fail("Exception not expected: " + e);
+ }
+ serializedProto = bos.toByteArray();
+ }
+
+ @Test public void message_parseFrom_InputStream() {
+ setup();
+ verifyExceptions(
+ new ParseTester() {
+ @Override
+ public DescriptorProto parse(InputStream in) throws IOException {
+ return DescriptorProto.parseFrom(in);
+ }
+ });
+ }
+
+ @Test public void message_parseFrom_InputStreamAndExtensionRegistry() {
+ setup();
+ verifyExceptions(
+ new ParseTester() {
+ @Override
+ public DescriptorProto parse(InputStream in) throws IOException {
+ return DescriptorProto.parseFrom(in, ExtensionRegistry.newInstance());
+ }
+ });
+ }
+
+ @Test public void message_parseFrom_CodedInputStream() {
+ setup();
+ verifyExceptions(
+ new ParseTester() {
+ @Override
+ public DescriptorProto parse(InputStream in) throws IOException {
+ return DescriptorProto.parseFrom(CodedInputStream.newInstance(in));
+ }
+ });
+ }
+
+ @Test public void message_parseFrom_CodedInputStreamAndExtensionRegistry() {
+ setup();
+ verifyExceptions(
+ new ParseTester() {
+ @Override
+ public DescriptorProto parse(InputStream in) throws IOException {
+ return DescriptorProto.parseFrom(
+ CodedInputStream.newInstance(in), ExtensionRegistry.newInstance());
+ }
+ });
+ }
+
+ @Test public void message_parseDelimitedFrom_InputStream() {
+ setupDelimited();
+ verifyExceptions(
+ new ParseTester() {
+ @Override
+ public DescriptorProto parse(InputStream in) throws IOException {
+ return DescriptorProto.parseDelimitedFrom(in);
+ }
+ });
+ }
+
+ @Test public void message_parseDelimitedFrom_InputStreamAndExtensionRegistry() {
+ setupDelimited();
+ verifyExceptions(
+ new ParseTester() {
+ @Override
+ public DescriptorProto parse(InputStream in) throws IOException {
+ return DescriptorProto.parseDelimitedFrom(in, ExtensionRegistry.newInstance());
+ }
+ });
+ }
+
+ @Test public void messageBuilder_mergeFrom_InputStream() {
+ setup();
+ verifyExceptions(
+ new ParseTester() {
+ @Override
+ public DescriptorProto parse(InputStream in) throws IOException {
+ return DescriptorProto.newBuilder().mergeFrom(in).build();
+ }
+ });
+ }
+
+ @Test public void messageBuilder_mergeFrom_InputStreamAndExtensionRegistry() {
+ setup();
+ verifyExceptions(
+ new ParseTester() {
+ @Override
+ public DescriptorProto parse(InputStream in) throws IOException {
+ return DescriptorProto.newBuilder()
+ .mergeFrom(in, ExtensionRegistry.newInstance())
+ .build();
+ }
+ });
+ }
+
+ @Test public void messageBuilder_mergeFrom_CodedInputStream() {
+ setup();
+ verifyExceptions(
+ new ParseTester() {
+ @Override
+ public DescriptorProto parse(InputStream in) throws IOException {
+ return DescriptorProto.newBuilder().mergeFrom(CodedInputStream.newInstance(in)).build();
+ }
+ });
+ }
+
+ @Test public void messageBuilder_mergeFrom_CodedInputStreamAndExtensionRegistry() {
+ setup();
+ verifyExceptions(
+ new ParseTester() {
+ @Override
+ public DescriptorProto parse(InputStream in) throws IOException {
+ return DescriptorProto.newBuilder()
+ .mergeFrom(CodedInputStream.newInstance(in), ExtensionRegistry.newInstance())
+ .build();
+ }
+ });
+ }
+
+ @Test public void messageBuilder_mergeDelimitedFrom_InputStream() {
+ setupDelimited();
+ verifyExceptions(
+ new ParseTester() {
+ @Override
+ public DescriptorProto parse(InputStream in) throws IOException {
+ DescriptorProto.Builder builder = DescriptorProto.newBuilder();
+ builder.mergeDelimitedFrom(in);
+ return builder.build();
+ }
+ });
+ }
+
+ @Test public void messageBuilder_mergeDelimitedFrom_InputStreamAndExtensionRegistry() {
+ setupDelimited();
+ verifyExceptions(
+ new ParseTester() {
+ @Override
+ public DescriptorProto parse(InputStream in) throws IOException {
+ DescriptorProto.Builder builder = DescriptorProto.newBuilder();
+ builder.mergeDelimitedFrom(in, ExtensionRegistry.newInstance());
+ return builder.build();
+ }
+ });
+ }
+
+ private void verifyExceptions(ParseTester parseTester) {
+ // No exception
+ try {
+ assertEquals(DescriptorProto.getDescriptor().toProto(),
+ parseTester.parse(new ByteArrayInputStream(serializedProto)));
+ } catch (IOException e) {
+ fail("No exception expected: " + e);
+ }
+
+ // IOException
+ try {
+ // using a "broken" stream that will throw part-way through reading the message
+ parseTester.parse(broken(new ByteArrayInputStream(serializedProto)));
+ fail("IOException expected but not thrown");
+ } catch (IOException e) {
+ assertFalse(e instanceof InvalidProtocolBufferException);
+ }
+
+ // InvalidProtocolBufferException
+ try {
+ // make the serialized proto invalid
+ for (int i = 0; i < 50; i++) {
+ serializedProto[i] = -1;
+ }
+ parseTester.parse(new ByteArrayInputStream(serializedProto));
+ fail("InvalidProtocolBufferException expected but not thrown");
+ } catch (IOException e) {
+ assertTrue(e instanceof InvalidProtocolBufferException);
+ }
+ }
+
+ private InputStream broken(InputStream i) {
+ return new FilterInputStream(i) {
+ int count = 0;
+
+ @Override public int read() throws IOException {
+ if (count++ >= 50) {
+ throw new IOException("I'm broken!");
+ }
+ return super.read();
+ }
+
+ @Override public int read(byte b[], int off, int len) throws IOException {
+ if ((count += len) >= 50) {
+ throw new IOException("I'm broken!");
+ }
+ return super.read(b, off, len);
+ }
+ };
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ParserTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ParserTest.java
new file mode 100644
index 0000000000..8c2e4c261c
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ParserTest.java
@@ -0,0 +1,415 @@
+// 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.UnittestLite.TestAllTypesLite;
+import com.google.protobuf.UnittestLite.TestPackedExtensionsLite;
+import com.google.protobuf.UnittestLite.TestParsingMergeLite;
+import protobuf_unittest.UnittestOptimizeFor;
+import protobuf_unittest.UnittestOptimizeFor.TestOptimizedForSize;
+import protobuf_unittest.UnittestOptimizeFor.TestRequiredOptimizedForSize;
+import protobuf_unittest.UnittestProto;
+import protobuf_unittest.UnittestProto.ForeignMessage;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestEmptyMessage;
+import protobuf_unittest.UnittestProto.TestParsingMerge;
+import protobuf_unittest.UnittestProto.TestRequired;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InterruptedIOException;
+import junit.framework.TestCase;
+
+/**
+ * Unit test for {@link Parser}.
+ *
+ * @author liujisi@google.com (Pherl Liu)
+ */
+public class ParserTest extends TestCase {
+ public void testGeneratedMessageParserSingleton() throws Exception {
+ for (int i = 0; i < 10; i++) {
+ assertEquals(TestAllTypes.parser(), TestUtil.getAllSet().getParserForType());
+ }
+ }
+
+ private void assertRoundTripEquals(MessageLite message,
+ ExtensionRegistryLite registry)
+ throws Exception {
+ final byte[] data = message.toByteArray();
+ final int offset = 20;
+ final int length = data.length;
+ final int padding = 30;
+ Parser<? extends MessageLite> parser = message.getParserForType();
+ assertMessageEquals(message, parser.parseFrom(data, registry));
+ assertMessageEquals(message, parser.parseFrom(
+ generatePaddingArray(data, offset, padding),
+ offset, length, registry));
+ assertMessageEquals(message, parser.parseFrom(
+ message.toByteString(), registry));
+ assertMessageEquals(message, parser.parseFrom(
+ new ByteArrayInputStream(data), registry));
+ assertMessageEquals(message, parser.parseFrom(
+ CodedInputStream.newInstance(data), registry));
+ }
+
+ @SuppressWarnings("unchecked")
+ private void assertRoundTripEquals(MessageLite message) throws Exception {
+ final byte[] data = message.toByteArray();
+ final int offset = 20;
+ final int length = data.length;
+ final int padding = 30;
+
+ Parser<MessageLite> parser =
+ (Parser<MessageLite>) message.getParserForType();
+ assertMessageEquals(message, parser.parseFrom(data));
+ assertMessageEquals(message, parser.parseFrom(
+ generatePaddingArray(data, offset, padding),
+ offset, length));
+ assertMessageEquals(message, parser.parseFrom(message.toByteString()));
+ assertMessageEquals(message, parser.parseFrom(
+ new ByteArrayInputStream(data)));
+ assertMessageEquals(message, parser.parseFrom(
+ CodedInputStream.newInstance(data)));
+ }
+
+ private void assertMessageEquals(
+ MessageLite expected, MessageLite actual)
+ throws Exception {
+ if (expected instanceof Message) {
+ assertEquals(expected, actual);
+ } else {
+ assertEquals(expected.toByteString(), actual.toByteString());
+ }
+ }
+
+ private byte[] generatePaddingArray(byte[] data, int offset, int padding) {
+ byte[] result = new byte[offset + data.length + padding];
+ System.arraycopy(data, 0, result, offset, data.length);
+ return result;
+ }
+
+ public void testNormalMessage() throws Exception {
+ assertRoundTripEquals(TestUtil.getAllSet());
+ }
+
+
+ public void testParsePartial() throws Exception {
+ assertParsePartial(TestRequired.parser(), TestRequired.newBuilder().setA(1).buildPartial());
+ }
+
+ private <T extends MessageLite> void assertParsePartial(
+ Parser<T> parser, T partialMessage) throws Exception {
+ final String errorString =
+ "Should throw exceptions when the parsed message isn't initialized.";
+
+ // parsePartialFrom should pass.
+ byte[] data = partialMessage.toByteArray();
+ assertEquals(partialMessage, parser.parsePartialFrom(data));
+ assertEquals(partialMessage, parser.parsePartialFrom(
+ partialMessage.toByteString()));
+ assertEquals(partialMessage, parser.parsePartialFrom(
+ new ByteArrayInputStream(data)));
+ assertEquals(partialMessage, parser.parsePartialFrom(
+ CodedInputStream.newInstance(data)));
+
+ // parseFrom(ByteArray)
+ try {
+ parser.parseFrom(partialMessage.toByteArray());
+ fail(errorString);
+ } catch (InvalidProtocolBufferException e) {
+ // pass.
+ }
+
+ // parseFrom(ByteString)
+ try {
+ parser.parseFrom(partialMessage.toByteString());
+ fail(errorString);
+ } catch (InvalidProtocolBufferException e) {
+ // pass.
+ }
+
+ // parseFrom(InputStream)
+ try {
+ parser.parseFrom(new ByteArrayInputStream(partialMessage.toByteArray()));
+ fail(errorString);
+ } catch (IOException e) {
+ // pass.
+ }
+
+ // parseFrom(CodedInputStream)
+ try {
+ parser.parseFrom(CodedInputStream.newInstance(
+ partialMessage.toByteArray()));
+ fail(errorString);
+ } catch (IOException e) {
+ // pass.
+ }
+ }
+
+ public void testParseExtensions() throws Exception {
+ assertRoundTripEquals(TestUtil.getAllExtensionsSet(),
+ TestUtil.getExtensionRegistry());
+ assertRoundTripEquals(
+ TestUtilLite.getAllLiteExtensionsSet(), TestUtilLite.getExtensionRegistryLite());
+ }
+
+ public void testParsePacked() throws Exception {
+ assertRoundTripEquals(TestUtil.getPackedSet());
+ assertRoundTripEquals(TestUtil.getPackedExtensionsSet(),
+ TestUtil.getExtensionRegistry());
+ assertRoundTripEquals(
+ TestUtilLite.getLitePackedExtensionsSet(), TestUtilLite.getExtensionRegistryLite());
+ }
+
+ public void testParseDelimitedTo() throws Exception {
+ // Write normal Message.
+ TestAllTypes normalMessage = TestUtil.getAllSet();
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ normalMessage.writeDelimitedTo(output);
+
+ // Write MessageLite with packed extension fields.
+ TestPackedExtensionsLite packedMessage = TestUtilLite.getLitePackedExtensionsSet();
+ packedMessage.writeDelimitedTo(output);
+
+ InputStream input = new ByteArrayInputStream(output.toByteArray());
+ assertMessageEquals(
+ normalMessage,
+ normalMessage.getParserForType().parseDelimitedFrom(input));
+ assertMessageEquals(
+ packedMessage,
+ packedMessage
+ .getParserForType()
+ .parseDelimitedFrom(input, TestUtilLite.getExtensionRegistryLite()));
+ }
+
+ public void testParseUnknownFields() throws Exception {
+ // All fields will be treated as unknown fields in emptyMessage.
+ TestEmptyMessage emptyMessage =
+ TestEmptyMessage.parser().parseFrom(TestUtil.getAllSet().toByteString());
+ assertEquals(
+ TestUtil.getAllSet().toByteString(),
+ emptyMessage.toByteString());
+ }
+
+
+ public void testOptimizeForSize() throws Exception {
+ TestOptimizedForSize.Builder builder = TestOptimizedForSize.newBuilder();
+ builder.setI(12).setMsg(ForeignMessage.newBuilder().setC(34).build());
+ builder.setExtension(TestOptimizedForSize.testExtension, 56);
+ builder.setExtension(TestOptimizedForSize.testExtension2,
+ TestRequiredOptimizedForSize.newBuilder().setX(78).build());
+
+ TestOptimizedForSize message = builder.build();
+ ExtensionRegistry registry = ExtensionRegistry.newInstance();
+ UnittestOptimizeFor.registerAllExtensions(registry);
+
+ assertRoundTripEquals(message, registry);
+ }
+
+ /** Helper method for {@link #testParsingMerge()}.*/
+ private void assertMessageMerged(TestAllTypes allTypes)
+ throws Exception {
+ assertEquals(3, allTypes.getOptionalInt32());
+ assertEquals(2, allTypes.getOptionalInt64());
+ assertEquals("hello", allTypes.getOptionalString());
+ }
+
+ /** Helper method for {@link #testParsingMergeLite()}.*/
+ private void assertMessageMerged(TestAllTypesLite allTypes)
+ throws Exception {
+ assertEquals(3, allTypes.getOptionalInt32());
+ assertEquals(2, allTypes.getOptionalInt64());
+ assertEquals("hello", allTypes.getOptionalString());
+ }
+
+ public void testParsingMerge() throws Exception {
+ // Build messages.
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TestAllTypes msg1 = builder.setOptionalInt32(1).build();
+ builder.clear();
+ TestAllTypes msg2 = builder.setOptionalInt64(2).build();
+ builder.clear();
+ TestAllTypes msg3 = builder.setOptionalInt32(3)
+ .setOptionalString("hello").build();
+
+ // Build groups.
+ TestParsingMerge.RepeatedFieldsGenerator.Group1 optionalG1 =
+ TestParsingMerge.RepeatedFieldsGenerator.Group1.newBuilder()
+ .setField1(msg1).build();
+ TestParsingMerge.RepeatedFieldsGenerator.Group1 optionalG2 =
+ TestParsingMerge.RepeatedFieldsGenerator.Group1.newBuilder()
+ .setField1(msg2).build();
+ TestParsingMerge.RepeatedFieldsGenerator.Group1 optionalG3 =
+ TestParsingMerge.RepeatedFieldsGenerator.Group1.newBuilder()
+ .setField1(msg3).build();
+ TestParsingMerge.RepeatedFieldsGenerator.Group2 repeatedG1 =
+ TestParsingMerge.RepeatedFieldsGenerator.Group2.newBuilder()
+ .setField1(msg1).build();
+ TestParsingMerge.RepeatedFieldsGenerator.Group2 repeatedG2 =
+ TestParsingMerge.RepeatedFieldsGenerator.Group2.newBuilder()
+ .setField1(msg2).build();
+ TestParsingMerge.RepeatedFieldsGenerator.Group2 repeatedG3 =
+ TestParsingMerge.RepeatedFieldsGenerator.Group2.newBuilder()
+ .setField1(msg3).build();
+
+ // Assign and serialize RepeatedFieldsGenerator.
+ ByteString data = TestParsingMerge.RepeatedFieldsGenerator.newBuilder()
+ .addField1(msg1).addField1(msg2).addField1(msg3)
+ .addField2(msg1).addField2(msg2).addField2(msg3)
+ .addField3(msg1).addField3(msg2).addField3(msg3)
+ .addGroup1(optionalG1).addGroup1(optionalG2).addGroup1(optionalG3)
+ .addGroup2(repeatedG1).addGroup2(repeatedG2).addGroup2(repeatedG3)
+ .addExt1(msg1).addExt1(msg2).addExt1(msg3)
+ .addExt2(msg1).addExt2(msg2).addExt2(msg3)
+ .build().toByteString();
+
+ // Parse TestParsingMerge.
+ ExtensionRegistry registry = ExtensionRegistry.newInstance();
+ UnittestProto.registerAllExtensions(registry);
+ TestParsingMerge parsingMerge = TestParsingMerge.parser().parseFrom(data, registry);
+
+ // Required and optional fields should be merged.
+ assertMessageMerged(parsingMerge.getRequiredAllTypes());
+ assertMessageMerged(parsingMerge.getOptionalAllTypes());
+ assertMessageMerged(
+ parsingMerge.getOptionalGroup().getOptionalGroupAllTypes());
+ assertMessageMerged(parsingMerge.getExtension(
+ TestParsingMerge.optionalExt));
+
+ // Repeated fields should not be merged.
+ assertEquals(3, parsingMerge.getRepeatedAllTypesCount());
+ assertEquals(3, parsingMerge.getRepeatedGroupCount());
+ assertEquals(3, parsingMerge.getExtensionCount(
+ TestParsingMerge.repeatedExt));
+ }
+
+ public void testParsingMergeLite() throws Exception {
+ // Build messages.
+ TestAllTypesLite.Builder builder =
+ TestAllTypesLite.newBuilder();
+ TestAllTypesLite msg1 = builder.setOptionalInt32(1).build();
+ builder.clear();
+ TestAllTypesLite msg2 = builder.setOptionalInt64(2).build();
+ builder.clear();
+ TestAllTypesLite msg3 = builder.setOptionalInt32(3)
+ .setOptionalString("hello").build();
+
+ // Build groups.
+ TestParsingMergeLite.RepeatedFieldsGenerator.Group1 optionalG1 =
+ TestParsingMergeLite.RepeatedFieldsGenerator.Group1.newBuilder()
+ .setField1(msg1).build();
+ TestParsingMergeLite.RepeatedFieldsGenerator.Group1 optionalG2 =
+ TestParsingMergeLite.RepeatedFieldsGenerator.Group1.newBuilder()
+ .setField1(msg2).build();
+ TestParsingMergeLite.RepeatedFieldsGenerator.Group1 optionalG3 =
+ TestParsingMergeLite.RepeatedFieldsGenerator.Group1.newBuilder()
+ .setField1(msg3).build();
+ TestParsingMergeLite.RepeatedFieldsGenerator.Group2 repeatedG1 =
+ TestParsingMergeLite.RepeatedFieldsGenerator.Group2.newBuilder()
+ .setField1(msg1).build();
+ TestParsingMergeLite.RepeatedFieldsGenerator.Group2 repeatedG2 =
+ TestParsingMergeLite.RepeatedFieldsGenerator.Group2.newBuilder()
+ .setField1(msg2).build();
+ TestParsingMergeLite.RepeatedFieldsGenerator.Group2 repeatedG3 =
+ TestParsingMergeLite.RepeatedFieldsGenerator.Group2.newBuilder()
+ .setField1(msg3).build();
+
+ // Assign and serialize RepeatedFieldsGenerator.
+ ByteString data = TestParsingMergeLite.RepeatedFieldsGenerator.newBuilder()
+ .addField1(msg1).addField1(msg2).addField1(msg3)
+ .addField2(msg1).addField2(msg2).addField2(msg3)
+ .addField3(msg1).addField3(msg2).addField3(msg3)
+ .addGroup1(optionalG1).addGroup1(optionalG2).addGroup1(optionalG3)
+ .addGroup2(repeatedG1).addGroup2(repeatedG2).addGroup2(repeatedG3)
+ .addExt1(msg1).addExt1(msg2).addExt1(msg3)
+ .addExt2(msg1).addExt2(msg2).addExt2(msg3)
+ .build().toByteString();
+
+ // Parse TestParsingMergeLite.
+ ExtensionRegistry registry = ExtensionRegistry.newInstance();
+ UnittestLite.registerAllExtensions(registry);
+ TestParsingMergeLite parsingMerge = TestParsingMergeLite.parser().parseFrom(data, registry);
+
+ // Required and optional fields should be merged.
+ assertMessageMerged(parsingMerge.getRequiredAllTypes());
+ assertMessageMerged(parsingMerge.getOptionalAllTypes());
+ assertMessageMerged(
+ parsingMerge.getOptionalGroup().getOptionalGroupAllTypes());
+ assertMessageMerged(parsingMerge.getExtension(
+ TestParsingMergeLite.optionalExt));
+
+ // Repeated fields should not be merged.
+ assertEquals(3, parsingMerge.getRepeatedAllTypesCount());
+ assertEquals(3, parsingMerge.getRepeatedGroupCount());
+ assertEquals(3, parsingMerge.getExtensionCount(
+ TestParsingMergeLite.repeatedExt));
+ }
+
+ public void testParseDelimitedFrom_firstByteInterrupted_preservesCause() {
+ try {
+ TestUtil.getAllSet().parseDelimitedFrom(
+ new InputStream() {
+ @Override
+ public int read() throws IOException {
+ throw new InterruptedIOException();
+ }
+ });
+ fail("Expected InterruptedIOException");
+ } catch (Exception e) {
+ assertEquals(InterruptedIOException.class, e.getClass());
+ }
+ }
+
+ public void testParseDelimitedFrom_secondByteInterrupted_preservesCause() {
+ try {
+ TestUtil.getAllSet().parseDelimitedFrom(
+ new InputStream() {
+ private int i;
+
+ @Override
+ public int read() throws IOException {
+ switch (i++) {
+ case 0:
+ return 1;
+ case 1:
+ throw new InterruptedIOException();
+ default:
+ throw new AssertionError();
+ }
+ }
+ });
+ fail("Expected InterruptedIOException");
+ } catch (Exception e) {
+ assertEquals(InterruptedIOException.class, e.getClass());
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java
new file mode 100644
index 0000000000..af717bfd20
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ProtobufArrayListTest.java
@@ -0,0 +1,288 @@
+// 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 static java.util.Arrays.asList;
+
+import java.util.Collections;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import java.util.List;
+import junit.framework.TestCase;
+
+/**
+ * Tests for {@link ProtobufArrayList}.
+ */
+public class ProtobufArrayListTest extends TestCase {
+
+ private static final ProtobufArrayList<Integer> UNARY_LIST = newImmutableProtoArrayList(1);
+ private static final ProtobufArrayList<Integer> TERTIARY_LIST =
+ newImmutableProtoArrayList(1, 2, 3);
+
+ private ProtobufArrayList<Integer> list;
+
+ @Override
+ protected void setUp() throws Exception {
+ list = new ProtobufArrayList<Integer>();
+ }
+
+ public void testEmptyListReturnsSameInstance() {
+ assertSame(ProtobufArrayList.emptyList(), ProtobufArrayList.emptyList());
+ }
+
+ public void testEmptyListIsImmutable() {
+ assertImmutable(ProtobufArrayList.<Integer>emptyList());
+ }
+
+ public void testModificationWithIteration() {
+ list.addAll(asList(1, 2, 3, 4));
+ Iterator<Integer> iterator = list.iterator();
+ assertEquals(4, list.size());
+ assertEquals(1, (int) list.get(0));
+ assertEquals(1, (int) iterator.next());
+
+ list.remove(0);
+ try {
+ iterator.next();
+ fail();
+ } catch (ConcurrentModificationException e) {
+ // expected
+ }
+
+ iterator = list.iterator();
+ list.set(0, 1);
+ try {
+ iterator.next();
+ fail();
+ } catch (ConcurrentModificationException e) {
+ // expected
+ }
+
+ iterator = list.iterator();
+ list.add(0, 0);
+ try {
+ iterator.next();
+ fail();
+ } catch (ConcurrentModificationException e) {
+ // expected
+ }
+ }
+
+ public void testMakeImmutable() {
+ list.add(2);
+ list.add(4);
+ list.add(6);
+ list.add(8);
+ list.makeImmutable();
+ assertImmutable(list);
+ }
+
+ public void testRemove() {
+ list.add(2);
+ list.add(4);
+ list.add(6);
+
+ list.remove(1);
+ assertEquals(asList(2, 6), list);
+
+ list.remove(1);
+ assertEquals(asList(2), list);
+
+ list.remove(0);
+ assertEquals(asList(), list);
+ }
+
+ public void testGet() {
+ list.add(2);
+ list.add(6);
+
+ assertEquals(2, (int) list.get(0));
+ assertEquals(6, (int) list.get(1));
+ }
+
+ public void testSet() {
+ list.add(2);
+ list.add(6);
+
+ list.set(0, 1);
+ assertEquals(1, (int) list.get(0));
+ list.set(1, 2);
+ assertEquals(2, (int) list.get(1));
+ }
+
+ private void assertImmutable(List<Integer> list) {
+ if (list.contains(1)) {
+ throw new RuntimeException("Cannot test the immutability of lists that contain 1.");
+ }
+
+ try {
+ list.add(1);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.add(0, 1);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(Collections.<Integer>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(Collections.singletonList(1));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(new ProtobufArrayList<Integer>());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, Collections.singleton(1));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.addAll(0, Collections.<Integer>emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.clear();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.remove(1);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.remove(new Object());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(Collections.emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(Collections.singleton(1));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.removeAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(Collections.emptyList());
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(Collections.singleton(1));
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.retainAll(UNARY_LIST);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+
+ try {
+ list.set(0, 0);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+
+ private static ProtobufArrayList<Integer> newImmutableProtoArrayList(int... elements) {
+ ProtobufArrayList<Integer> list = new ProtobufArrayList<Integer>();
+ for (int element : elements) {
+ list.add(element);
+ }
+ list.makeImmutable();
+ return list;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/RepeatedFieldBuilderV3Test.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/RepeatedFieldBuilderV3Test.java
new file mode 100644
index 0000000000..edbd0afd75
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/RepeatedFieldBuilderV3Test.java
@@ -0,0 +1,188 @@
+// 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 protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestAllTypesOrBuilder;
+import java.util.Collections;
+import java.util.List;
+import junit.framework.TestCase;
+
+/**
+ * Tests for {@link RepeatedFieldBuilderV3}. This tests basic functionality.
+ * More extensive testing is provided via other tests that exercise the
+ * builder.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class RepeatedFieldBuilderV3Test extends TestCase {
+
+ public void testBasicUse() {
+ TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
+ RepeatedFieldBuilderV3<TestAllTypes, TestAllTypes.Builder,
+ TestAllTypesOrBuilder> builder = newRepeatedFieldBuilderV3(mockParent);
+ builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(0).build());
+ builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(1).build());
+ assertEquals(0, builder.getMessage(0).getOptionalInt32());
+ assertEquals(1, builder.getMessage(1).getOptionalInt32());
+
+ List<TestAllTypes> list = builder.build();
+ assertEquals(2, list.size());
+ assertEquals(0, list.get(0).getOptionalInt32());
+ assertEquals(1, list.get(1).getOptionalInt32());
+ assertIsUnmodifiable(list);
+
+ // Make sure it doesn't change.
+ List<TestAllTypes> list2 = builder.build();
+ assertSame(list, list2);
+ assertEquals(0, mockParent.getInvalidationCount());
+ }
+
+ public void testGoingBackAndForth() {
+ TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
+ RepeatedFieldBuilderV3<TestAllTypes, TestAllTypes.Builder,
+ TestAllTypesOrBuilder> builder = newRepeatedFieldBuilderV3(mockParent);
+ builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(0).build());
+ builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(1).build());
+ assertEquals(0, builder.getMessage(0).getOptionalInt32());
+ assertEquals(1, builder.getMessage(1).getOptionalInt32());
+
+ // Convert to list
+ List<TestAllTypes> list = builder.build();
+ assertEquals(2, list.size());
+ assertEquals(0, list.get(0).getOptionalInt32());
+ assertEquals(1, list.get(1).getOptionalInt32());
+ assertIsUnmodifiable(list);
+
+ // Update 0th item
+ assertEquals(0, mockParent.getInvalidationCount());
+ builder.getBuilder(0).setOptionalString("foo");
+ assertEquals(1, mockParent.getInvalidationCount());
+ list = builder.build();
+ assertEquals(2, list.size());
+ assertEquals(0, list.get(0).getOptionalInt32());
+ assertEquals("foo", list.get(0).getOptionalString());
+ assertEquals(1, list.get(1).getOptionalInt32());
+ assertIsUnmodifiable(list);
+ assertEquals(1, mockParent.getInvalidationCount());
+ }
+
+ public void testVariousMethods() {
+ TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
+ RepeatedFieldBuilderV3<TestAllTypes, TestAllTypes.Builder,
+ TestAllTypesOrBuilder> builder = newRepeatedFieldBuilderV3(mockParent);
+ builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(1).build());
+ builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(2).build());
+ builder.addBuilder(0, TestAllTypes.getDefaultInstance())
+ .setOptionalInt32(0);
+ builder.addBuilder(TestAllTypes.getDefaultInstance()).setOptionalInt32(3);
+
+ assertEquals(0, builder.getMessage(0).getOptionalInt32());
+ assertEquals(1, builder.getMessage(1).getOptionalInt32());
+ assertEquals(2, builder.getMessage(2).getOptionalInt32());
+ assertEquals(3, builder.getMessage(3).getOptionalInt32());
+
+ assertEquals(0, mockParent.getInvalidationCount());
+ List<TestAllTypes> messages = builder.build();
+ assertEquals(4, messages.size());
+ assertSame(messages, builder.build()); // expect same list
+
+ // Remove a message.
+ builder.remove(2);
+ assertEquals(1, mockParent.getInvalidationCount());
+ assertEquals(3, builder.getCount());
+ assertEquals(0, builder.getMessage(0).getOptionalInt32());
+ assertEquals(1, builder.getMessage(1).getOptionalInt32());
+ assertEquals(3, builder.getMessage(2).getOptionalInt32());
+
+ // Remove a builder.
+ builder.remove(0);
+ assertEquals(1, mockParent.getInvalidationCount());
+ assertEquals(2, builder.getCount());
+ assertEquals(1, builder.getMessage(0).getOptionalInt32());
+ assertEquals(3, builder.getMessage(1).getOptionalInt32());
+
+ // Test clear.
+ builder.clear();
+ assertEquals(1, mockParent.getInvalidationCount());
+ assertEquals(0, builder.getCount());
+ assertTrue(builder.isEmpty());
+ }
+
+ public void testLists() {
+ TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
+ RepeatedFieldBuilderV3<TestAllTypes, TestAllTypes.Builder,
+ TestAllTypesOrBuilder> builder = newRepeatedFieldBuilderV3(mockParent);
+ builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(1).build());
+ builder.addMessage(0,
+ TestAllTypes.newBuilder().setOptionalInt32(0).build());
+ assertEquals(0, builder.getMessage(0).getOptionalInt32());
+ assertEquals(1, builder.getMessage(1).getOptionalInt32());
+
+ // Use list of builders.
+ List<TestAllTypes.Builder> builders = builder.getBuilderList();
+ assertEquals(0, builders.get(0).getOptionalInt32());
+ assertEquals(1, builders.get(1).getOptionalInt32());
+ builders.get(0).setOptionalInt32(10);
+ builders.get(1).setOptionalInt32(11);
+
+ // Use list of protos
+ List<TestAllTypes> protos = builder.getMessageList();
+ assertEquals(10, protos.get(0).getOptionalInt32());
+ assertEquals(11, protos.get(1).getOptionalInt32());
+
+ // Add an item to the builders and verify it's updated in both
+ builder.addMessage(TestAllTypes.newBuilder().setOptionalInt32(12).build());
+ assertEquals(3, builders.size());
+ assertEquals(3, protos.size());
+ }
+
+ private void assertIsUnmodifiable(List<?> list) {
+ if (list == Collections.emptyList()) {
+ // OKAY -- Need to check this b/c EmptyList allows you to call clear.
+ } else {
+ try {
+ list.clear();
+ fail("List wasn't immutable");
+ } catch (UnsupportedOperationException e) {
+ // good
+ }
+ }
+ }
+
+ private RepeatedFieldBuilderV3<TestAllTypes, TestAllTypes.Builder,
+ TestAllTypesOrBuilder>
+ newRepeatedFieldBuilderV3(GeneratedMessage.BuilderParent parent) {
+ return new RepeatedFieldBuilderV3<TestAllTypes, TestAllTypes.Builder,
+ TestAllTypesOrBuilder>(Collections.<TestAllTypes>emptyList(), false,
+ parent, false);
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java
new file mode 100644
index 0000000000..dc56f2e9ac
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java
@@ -0,0 +1,127 @@
+// 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.UnsupportedEncodingException;
+import java.util.Iterator;
+
+/**
+ * This class tests {@link RopeByteString#substring(int, int)} by inheriting the tests from
+ * {@link LiteralByteStringTest}. Only a couple of methods are overridden.
+ *
+ * @author carlanton@google.com (Carl Haverl)
+ */
+public class RopeByteStringSubstringTest extends LiteralByteStringTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ classUnderTest = "RopeByteString";
+ byte[] sourceBytes = ByteStringTest.getTestBytes(22341, 22337766L);
+ Iterator<ByteString> iter = ByteStringTest.makeConcretePieces(sourceBytes).iterator();
+ ByteString sourceString = iter.next();
+ while (iter.hasNext()) {
+ sourceString = sourceString.concat(iter.next());
+ }
+
+ int from = 1130;
+ int to = sourceBytes.length - 5555;
+ stringUnderTest = sourceString.substring(from, to);
+ referenceBytes = new byte[to - from];
+ System.arraycopy(sourceBytes, from, referenceBytes, 0, to - from);
+ expectedHashCode = -1259260680;
+ }
+
+ @Override
+ public void testGetTreeDepth() {
+ assertEquals(classUnderTest + " must have the expected tree depth",
+ 3, stringUnderTest.getTreeDepth());
+ }
+
+ @Override
+ public void testToString() throws UnsupportedEncodingException {
+ String sourceString = "I love unicode \u1234\u5678 characters";
+ ByteString sourceByteString = ByteString.copyFromUtf8(sourceString);
+ int copies = 250;
+
+ // By building the RopeByteString by concatenating, this is actually a fairly strenuous test.
+ StringBuilder builder = new StringBuilder(copies * sourceString.length());
+ ByteString unicode = ByteString.EMPTY;
+ for (int i = 0; i < copies; ++i) {
+ builder.append(sourceString);
+ unicode = RopeByteString.concatenate(unicode, sourceByteString);
+ }
+ String testString = builder.toString();
+
+ // Do the substring part
+ testString = testString.substring(2, testString.length() - 6);
+ unicode = unicode.substring(2, unicode.size() - 6);
+
+ assertEquals(classUnderTest + " from string must have the expected type",
+ classUnderTest, getActualClassName(unicode));
+ String roundTripString = unicode.toString(UTF_8);
+ assertEquals(classUnderTest + " unicode bytes must match",
+ testString, roundTripString);
+ ByteString flatString = ByteString.copyFromUtf8(testString);
+ assertEquals(classUnderTest + " string must equal the flat string", flatString, unicode);
+ assertEquals(classUnderTest + " string must must have same hashCode as the flat string",
+ flatString.hashCode(), unicode.hashCode());
+ }
+
+ @Override
+ public void testCharsetToString() {
+ String sourceString = "I love unicode \u1234\u5678 characters";
+ ByteString sourceByteString = ByteString.copyFromUtf8(sourceString);
+ int copies = 250;
+
+ // By building the RopeByteString by concatenating, this is actually a fairly strenuous test.
+ StringBuilder builder = new StringBuilder(copies * sourceString.length());
+ ByteString unicode = ByteString.EMPTY;
+ for (int i = 0; i < copies; ++i) {
+ builder.append(sourceString);
+ unicode = RopeByteString.concatenate(unicode, sourceByteString);
+ }
+ String testString = builder.toString();
+
+ // Do the substring part
+ testString = testString.substring(2, testString.length() - 6);
+ unicode = unicode.substring(2, unicode.size() - 6);
+
+ assertEquals(classUnderTest + " from string must have the expected type",
+ classUnderTest, getActualClassName(unicode));
+ String roundTripString = unicode.toString(Internal.UTF_8);
+ assertEquals(classUnderTest + " unicode bytes must match",
+ testString, roundTripString);
+ ByteString flatString = ByteString.copyFromUtf8(testString);
+ assertEquals(classUnderTest + " string must equal the flat string", flatString, unicode);
+ assertEquals(classUnderTest + " string must must have same hashCode as the flat string",
+ flatString.hashCode(), unicode.hashCode());
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java
new file mode 100644
index 0000000000..4ec3a40988
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/RopeByteStringTest.java
@@ -0,0 +1,189 @@
+// 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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Iterator;
+
+/**
+ * This class tests {@link RopeByteString} by inheriting the tests from
+ * {@link LiteralByteStringTest}. Only a couple of methods are overridden.
+ *
+ * <p>A full test of the result of {@link RopeByteString#substring(int, int)} is found in the
+ * separate class {@link RopeByteStringSubstringTest}.
+ *
+ * @author carlanton@google.com (Carl Haverl)
+ */
+public class RopeByteStringTest extends LiteralByteStringTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ classUnderTest = "RopeByteString";
+ referenceBytes = ByteStringTest.getTestBytes(22341, 22337766L);
+ Iterator<ByteString> iter = ByteStringTest.makeConcretePieces(referenceBytes).iterator();
+ stringUnderTest = iter.next();
+ while (iter.hasNext()) {
+ stringUnderTest = stringUnderTest.concat(iter.next());
+ }
+ expectedHashCode = -1214197238;
+ }
+
+ @Override
+ public void testGetTreeDepth() {
+ assertEquals(classUnderTest + " must have the expected tree depth",
+ 4, stringUnderTest.getTreeDepth());
+ }
+
+ public void testBalance() {
+ int numberOfPieces = 10000;
+ int pieceSize = 64;
+ byte[] testBytes = ByteStringTest.getTestBytes(numberOfPieces * pieceSize, 113377L);
+
+ // Build up a big ByteString from smaller pieces to force a rebalance
+ ByteString concatenated = ByteString.EMPTY;
+ for (int i = 0; i < numberOfPieces; ++i) {
+ concatenated = concatenated.concat(ByteString.copyFrom(testBytes, i * pieceSize, pieceSize));
+ }
+
+ assertEquals(classUnderTest + " from string must have the expected type",
+ classUnderTest, getActualClassName(concatenated));
+ assertTrue(classUnderTest + " underlying bytes must match after balancing",
+ Arrays.equals(testBytes, concatenated.toByteArray()));
+ ByteString testString = ByteString.copyFrom(testBytes);
+ assertTrue(classUnderTest + " balanced string must equal flat string",
+ concatenated.equals(testString));
+ assertTrue(classUnderTest + " flat string must equal balanced string",
+ testString.equals(concatenated));
+ assertEquals(classUnderTest + " balanced string must have same hash code as flat string",
+ testString.hashCode(), concatenated.hashCode());
+ }
+
+ @Override
+ public void testToString() throws UnsupportedEncodingException {
+ String sourceString = "I love unicode \u1234\u5678 characters";
+ ByteString sourceByteString = ByteString.copyFromUtf8(sourceString);
+ int copies = 250;
+
+ // By building the RopeByteString by concatenating, this is actually a fairly strenuous test.
+ StringBuilder builder = new StringBuilder(copies * sourceString.length());
+ ByteString unicode = ByteString.EMPTY;
+ for (int i = 0; i < copies; ++i) {
+ builder.append(sourceString);
+ unicode = RopeByteString.concatenate(unicode, sourceByteString);
+ }
+ String testString = builder.toString();
+
+ assertEquals(classUnderTest + " from string must have the expected type",
+ classUnderTest, getActualClassName(unicode));
+ String roundTripString = unicode.toString(UTF_8);
+ assertEquals(classUnderTest + " unicode bytes must match",
+ testString, roundTripString);
+ ByteString flatString = ByteString.copyFromUtf8(testString);
+ assertEquals(classUnderTest + " string must equal the flat string", flatString, unicode);
+ assertEquals(classUnderTest + " string must must have same hashCode as the flat string",
+ flatString.hashCode(), unicode.hashCode());
+ }
+
+ @Override
+ public void testCharsetToString() {
+ String sourceString = "I love unicode \u1234\u5678 characters";
+ ByteString sourceByteString = ByteString.copyFromUtf8(sourceString);
+ int copies = 250;
+
+ // By building the RopeByteString by concatenating, this is actually a fairly strenuous test.
+ StringBuilder builder = new StringBuilder(copies * sourceString.length());
+ ByteString unicode = ByteString.EMPTY;
+ for (int i = 0; i < copies; ++i) {
+ builder.append(sourceString);
+ unicode = RopeByteString.concatenate(unicode, sourceByteString);
+ }
+ String testString = builder.toString();
+
+ assertEquals(classUnderTest + " from string must have the expected type",
+ classUnderTest, getActualClassName(unicode));
+ String roundTripString = unicode.toString(Internal.UTF_8);
+ assertEquals(classUnderTest + " unicode bytes must match",
+ testString, roundTripString);
+ ByteString flatString = ByteString.copyFromUtf8(testString);
+ assertEquals(classUnderTest + " string must equal the flat string", flatString, unicode);
+ assertEquals(classUnderTest + " string must must have same hashCode as the flat string",
+ flatString.hashCode(), unicode.hashCode());
+ }
+
+ @Override
+ public void testToString_returnsCanonicalEmptyString() {
+ RopeByteString ropeByteString =
+ RopeByteString.newInstanceForTest(ByteString.EMPTY, ByteString.EMPTY);
+ assertSame(classUnderTest + " must be the same string references",
+ ByteString.EMPTY.toString(Internal.UTF_8), ropeByteString.toString(Internal.UTF_8));
+ }
+
+ @Override
+ public void testToString_raisesException() {
+ try {
+ ByteString byteString =
+ RopeByteString.newInstanceForTest(ByteString.EMPTY, ByteString.EMPTY);
+ byteString.toString("invalid");
+ fail("Should have thrown an exception.");
+ } catch (UnsupportedEncodingException expected) {
+ // This is success
+ }
+
+ try {
+ ByteString byteString = RopeByteString.concatenate(ByteString.copyFromUtf8("foo"),
+ ByteString.copyFromUtf8("bar"));
+ byteString.toString("invalid");
+ fail("Should have thrown an exception.");
+ } catch (UnsupportedEncodingException expected) {
+ // This is success
+ }
+ }
+
+ @Override
+ public void testJavaSerialization() throws Exception {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(out);
+ oos.writeObject(stringUnderTest);
+ oos.close();
+ byte[] pickled = out.toByteArray();
+ InputStream in = new ByteArrayInputStream(pickled);
+ ObjectInputStream ois = new ObjectInputStream(in);
+ Object o = ois.readObject();
+ assertTrue("Didn't get a ByteString back", o instanceof ByteString);
+ assertEquals("Should get an equal ByteString back", stringUnderTest, o);
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ServiceTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ServiceTest.java
new file mode 100644
index 0000000000..b895ad8d36
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/ServiceTest.java
@@ -0,0 +1,326 @@
+// 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.FileDescriptor;
+import com.google.protobuf.Descriptors.MethodDescriptor;
+import google.protobuf.no_generic_services_test.UnittestNoGenericServices;
+import protobuf_unittest.MessageWithNoOuter;
+import protobuf_unittest.ServiceWithNoOuter;
+import protobuf_unittest.UnittestProto.BarRequest;
+import protobuf_unittest.UnittestProto.BarResponse;
+import protobuf_unittest.UnittestProto.FooRequest;
+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;
+
+/**
+ * Tests services and stubs.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class ServiceTest extends TestCase {
+ private IMocksControl control;
+ private RpcController mockController;
+
+ private final Descriptors.MethodDescriptor fooDescriptor =
+ TestService.getDescriptor().getMethods().get(0);
+ private final Descriptors.MethodDescriptor barDescriptor =
+ TestService.getDescriptor().getMethods().get(1);
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ control = EasyMock.createStrictControl();
+ mockController = control.createMock(RpcController.class);
+ }
+
+ // =================================================================
+
+ /** Tests Service.callMethod(). */
+ public void testCallMethod() throws Exception {
+ FooRequest fooRequest = FooRequest.newBuilder().build();
+ BarRequest barRequest = BarRequest.newBuilder().build();
+ MockCallback<Message> fooCallback = new MockCallback<Message>();
+ MockCallback<Message> barCallback = new MockCallback<Message>();
+ TestService mockService = control.createMock(TestService.class);
+
+ mockService.foo(EasyMock.same(mockController), EasyMock.same(fooRequest),
+ this.<FooResponse>wrapsCallback(fooCallback));
+ mockService.bar(EasyMock.same(mockController), EasyMock.same(barRequest),
+ this.<BarResponse>wrapsCallback(barCallback));
+ control.replay();
+
+ mockService.callMethod(fooDescriptor, mockController,
+ fooRequest, fooCallback);
+ mockService.callMethod(barDescriptor, mockController,
+ barRequest, barCallback);
+ control.verify();
+ }
+
+ /** Tests Service.get{Request,Response}Prototype(). */
+ public void testGetPrototype() throws Exception {
+ TestService mockService = control.createMock(TestService.class);
+
+ assertSame(mockService.getRequestPrototype(fooDescriptor),
+ FooRequest.getDefaultInstance());
+ assertSame(mockService.getResponsePrototype(fooDescriptor),
+ FooResponse.getDefaultInstance());
+ assertSame(mockService.getRequestPrototype(barDescriptor),
+ BarRequest.getDefaultInstance());
+ assertSame(mockService.getResponsePrototype(barDescriptor),
+ BarResponse.getDefaultInstance());
+ }
+
+ /** Tests generated stubs. */
+ public void testStub() throws Exception {
+ FooRequest fooRequest = FooRequest.newBuilder().build();
+ BarRequest barRequest = BarRequest.newBuilder().build();
+ MockCallback<FooResponse> fooCallback = new MockCallback<FooResponse>();
+ MockCallback<BarResponse> barCallback = new MockCallback<BarResponse>();
+ RpcChannel mockChannel = control.createMock(RpcChannel.class);
+ TestService stub = TestService.newStub(mockChannel);
+
+ mockChannel.callMethod(
+ EasyMock.same(fooDescriptor),
+ EasyMock.same(mockController),
+ EasyMock.same(fooRequest),
+ EasyMock.same(FooResponse.getDefaultInstance()),
+ this.<Message>wrapsCallback(fooCallback));
+ mockChannel.callMethod(
+ EasyMock.same(barDescriptor),
+ EasyMock.same(mockController),
+ EasyMock.same(barRequest),
+ EasyMock.same(BarResponse.getDefaultInstance()),
+ this.<Message>wrapsCallback(barCallback));
+ control.replay();
+
+ stub.foo(mockController, fooRequest, fooCallback);
+ stub.bar(mockController, barRequest, barCallback);
+ control.verify();
+ }
+
+ /** Tests generated blocking stubs. */
+ public void testBlockingStub() throws Exception {
+ FooRequest fooRequest = FooRequest.newBuilder().build();
+ BarRequest barRequest = BarRequest.newBuilder().build();
+ BlockingRpcChannel mockChannel =
+ control.createMock(BlockingRpcChannel.class);
+ TestService.BlockingInterface stub =
+ TestService.newBlockingStub(mockChannel);
+
+ FooResponse fooResponse = FooResponse.newBuilder().build();
+ BarResponse barResponse = BarResponse.newBuilder().build();
+
+ EasyMock.expect(mockChannel.callBlockingMethod(
+ EasyMock.same(fooDescriptor),
+ EasyMock.same(mockController),
+ EasyMock.same(fooRequest),
+ EasyMock.same(FooResponse.getDefaultInstance()))).andReturn(fooResponse);
+ EasyMock.expect(mockChannel.callBlockingMethod(
+ EasyMock.same(barDescriptor),
+ EasyMock.same(mockController),
+ EasyMock.same(barRequest),
+ EasyMock.same(BarResponse.getDefaultInstance()))).andReturn(barResponse);
+ control.replay();
+
+ assertSame(fooResponse, stub.foo(mockController, fooRequest));
+ assertSame(barResponse, stub.bar(mockController, barRequest));
+ control.verify();
+ }
+
+ public void testNewReflectiveService() {
+ ServiceWithNoOuter.Interface impl =
+ control.createMock(ServiceWithNoOuter.Interface.class);
+ RpcController controller = control.createMock(RpcController.class);
+ Service service = ServiceWithNoOuter.newReflectiveService(impl);
+
+ MethodDescriptor fooMethod =
+ ServiceWithNoOuter.getDescriptor().findMethodByName("Foo");
+ MessageWithNoOuter request = MessageWithNoOuter.getDefaultInstance();
+ RpcCallback<Message> callback =
+ new RpcCallback<Message>() {
+ @Override
+ public void run(Message parameter) {
+ // No reason this should be run.
+ fail();
+ }
+ };
+ RpcCallback<TestAllTypes> specializedCallback =
+ RpcUtil.specializeCallback(callback);
+
+ impl.foo(EasyMock.same(controller), EasyMock.same(request),
+ EasyMock.same(specializedCallback));
+ EasyMock.expectLastCall();
+
+ control.replay();
+
+ service.callMethod(fooMethod, controller, request, callback);
+
+ control.verify();
+ }
+
+ public void testNewReflectiveBlockingService() throws ServiceException {
+ ServiceWithNoOuter.BlockingInterface impl =
+ control.createMock(ServiceWithNoOuter.BlockingInterface.class);
+ RpcController controller = control.createMock(RpcController.class);
+ BlockingService service =
+ ServiceWithNoOuter.newReflectiveBlockingService(impl);
+
+ MethodDescriptor fooMethod =
+ ServiceWithNoOuter.getDescriptor().findMethodByName("Foo");
+ MessageWithNoOuter request = MessageWithNoOuter.getDefaultInstance();
+
+ TestAllTypes expectedResponse = TestAllTypes.getDefaultInstance();
+ EasyMock.expect(impl.foo(EasyMock.same(controller), EasyMock.same(request)))
+ .andReturn(expectedResponse);
+
+ control.replay();
+
+ Message response =
+ service.callBlockingMethod(fooMethod, controller, request);
+ assertEquals(expectedResponse, response);
+
+ control.verify();
+ }
+
+ public void testNoGenericServices() throws Exception {
+ // Non-services should be usable.
+ UnittestNoGenericServices.TestMessage message =
+ UnittestNoGenericServices.TestMessage.newBuilder()
+ .setA(123)
+ .setExtension(UnittestNoGenericServices.testExtension, 456)
+ .build();
+ assertEquals(123, message.getA());
+ assertEquals(1, UnittestNoGenericServices.TestEnum.FOO.getNumber());
+
+ // Build a list of the class names nested in UnittestNoGenericServices.
+ String outerName = "google.protobuf.no_generic_services_test." +
+ "UnittestNoGenericServices";
+ Class<?> outerClass = Class.forName(outerName);
+
+ Set<String> innerClassNames = new HashSet<String>();
+ for (Class<?> innerClass : outerClass.getClasses()) {
+ String fullName = innerClass.getName();
+ // Figure out the unqualified name of the inner class.
+ // Note: Surprisingly, the full name of an inner class will be separated
+ // from the outer class name by a '$' rather than a '.'. This is not
+ // mentioned in the documentation for java.lang.Class. I don't want to
+ // make assumptions, so I'm just going to accept any character as the
+ // separator.
+ assertTrue(fullName.startsWith(outerName));
+
+ if (!Service.class.isAssignableFrom(innerClass) &&
+ !Message.class.isAssignableFrom(innerClass) &&
+ !ProtocolMessageEnum.class.isAssignableFrom(innerClass)) {
+ // Ignore any classes not generated by the base code generator.
+ continue;
+ }
+
+ innerClassNames.add(fullName.substring(outerName.length() + 1));
+ }
+
+ // No service class should have been generated.
+ assertTrue(innerClassNames.contains("TestMessage"));
+ assertTrue(innerClassNames.contains("TestEnum"));
+ assertFalse(innerClassNames.contains("TestService"));
+
+ // But descriptors are there.
+ FileDescriptor file = UnittestNoGenericServices.getDescriptor();
+ assertEquals(1, file.getServices().size());
+ assertEquals("TestService", file.getServices().get(0).getName());
+ assertEquals(1, file.getServices().get(0).getMethods().size());
+ assertEquals("Foo",
+ file.getServices().get(0).getMethods().get(0).getName());
+ }
+
+
+
+ // =================================================================
+
+ /**
+ * wrapsCallback() is an EasyMock argument predicate. wrapsCallback(c)
+ * matches a callback if calling that callback causes c to be called.
+ * In other words, c wraps the given callback.
+ */
+ private <Type extends Message> RpcCallback<Type> wrapsCallback(
+ MockCallback<?> callback) {
+ EasyMock.reportMatcher(new WrapsCallback(callback));
+ return null;
+ }
+
+ /** The parameter to wrapsCallback() must be a MockCallback. */
+ private static class MockCallback<Type extends Message>
+ implements RpcCallback<Type> {
+ private boolean called = false;
+
+ public boolean isCalled() { return called; }
+
+ public void reset() { called = false; }
+ @Override
+ public void run(Type message) {
+ called = true; }
+ }
+
+ /** Implementation of the wrapsCallback() argument matcher. */
+ private static class WrapsCallback implements IArgumentMatcher {
+ private MockCallback<?> callback;
+
+ public WrapsCallback(MockCallback<?> callback) {
+ this.callback = callback;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public boolean matches(Object actual) {
+ if (!(actual instanceof RpcCallback)) {
+ return false;
+ }
+ RpcCallback actualCallback = (RpcCallback)actual;
+
+ callback.reset();
+ actualCallback.run(null);
+ return callback.isCalled();
+ }
+
+ @Override
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("wrapsCallback(mockCallback)");
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java
new file mode 100644
index 0000000000..e3a8d4f408
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/SingleFieldBuilderV3Test.java
@@ -0,0 +1,155 @@
+// 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 protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestAllTypesOrBuilder;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for {@link SingleFieldBuilderV3}. This tests basic functionality.
+ * More extensive testing is provided via other tests that exercise the
+ * builder.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class SingleFieldBuilderV3Test extends TestCase {
+
+ public void testBasicUseAndInvalidations() {
+ TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
+ SingleFieldBuilderV3<TestAllTypes, TestAllTypes.Builder,
+ TestAllTypesOrBuilder> builder =
+ new SingleFieldBuilderV3<TestAllTypes, TestAllTypes.Builder,
+ TestAllTypesOrBuilder>(
+ TestAllTypes.getDefaultInstance(),
+ mockParent,
+ false);
+ assertSame(TestAllTypes.getDefaultInstance(), builder.getMessage());
+ assertEquals(TestAllTypes.getDefaultInstance(),
+ builder.getBuilder().buildPartial());
+ assertEquals(0, mockParent.getInvalidationCount());
+
+ builder.getBuilder().setOptionalInt32(10);
+ assertEquals(0, mockParent.getInvalidationCount());
+ TestAllTypes message = builder.build();
+ assertEquals(10, message.getOptionalInt32());
+
+ // Test that we receive invalidations now that build has been called.
+ assertEquals(0, mockParent.getInvalidationCount());
+ builder.getBuilder().setOptionalInt32(20);
+ assertEquals(1, mockParent.getInvalidationCount());
+
+ // Test that we don't keep getting invalidations on every change
+ builder.getBuilder().setOptionalInt32(30);
+ assertEquals(1, mockParent.getInvalidationCount());
+
+ }
+
+ public void testSetMessage() {
+ TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
+ SingleFieldBuilderV3<TestAllTypes, TestAllTypes.Builder,
+ TestAllTypesOrBuilder> builder =
+ new SingleFieldBuilderV3<TestAllTypes, TestAllTypes.Builder,
+ TestAllTypesOrBuilder>(
+ TestAllTypes.getDefaultInstance(),
+ mockParent,
+ false);
+ builder.setMessage(TestAllTypes.newBuilder().setOptionalInt32(0).build());
+ assertEquals(0, builder.getMessage().getOptionalInt32());
+
+ // Update message using the builder
+ builder.getBuilder().setOptionalInt32(1);
+ assertEquals(0, mockParent.getInvalidationCount());
+ assertEquals(1, builder.getBuilder().getOptionalInt32());
+ assertEquals(1, builder.getMessage().getOptionalInt32());
+ builder.build();
+ builder.getBuilder().setOptionalInt32(2);
+ assertEquals(2, builder.getBuilder().getOptionalInt32());
+ assertEquals(2, builder.getMessage().getOptionalInt32());
+
+ // Make sure message stays cached
+ assertSame(builder.getMessage(), builder.getMessage());
+ }
+
+ public void testClear() {
+ TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
+ SingleFieldBuilderV3<TestAllTypes, TestAllTypes.Builder,
+ TestAllTypesOrBuilder> builder =
+ new SingleFieldBuilderV3<TestAllTypes, TestAllTypes.Builder,
+ TestAllTypesOrBuilder>(
+ TestAllTypes.getDefaultInstance(),
+ mockParent,
+ false);
+ builder.setMessage(TestAllTypes.newBuilder().setOptionalInt32(0).build());
+ assertNotSame(TestAllTypes.getDefaultInstance(), builder.getMessage());
+ builder.clear();
+ assertSame(TestAllTypes.getDefaultInstance(), builder.getMessage());
+
+ builder.getBuilder().setOptionalInt32(1);
+ assertNotSame(TestAllTypes.getDefaultInstance(), builder.getMessage());
+ builder.clear();
+ assertSame(TestAllTypes.getDefaultInstance(), builder.getMessage());
+ }
+
+ public void testMerge() {
+ TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
+ SingleFieldBuilderV3<TestAllTypes, TestAllTypes.Builder,
+ TestAllTypesOrBuilder> builder =
+ new SingleFieldBuilderV3<TestAllTypes, TestAllTypes.Builder,
+ TestAllTypesOrBuilder>(
+ TestAllTypes.getDefaultInstance(),
+ mockParent,
+ false);
+
+ // Merge into default field.
+ builder.mergeFrom(TestAllTypes.getDefaultInstance());
+ assertSame(TestAllTypes.getDefaultInstance(), builder.getMessage());
+
+ // Merge into non-default field on existing builder.
+ builder.getBuilder().setOptionalInt32(2);
+ builder.mergeFrom(TestAllTypes.newBuilder()
+ .setOptionalDouble(4.0)
+ .buildPartial());
+ assertEquals(2, builder.getMessage().getOptionalInt32());
+ assertEquals(4.0, builder.getMessage().getOptionalDouble());
+
+ // Merge into non-default field on existing message
+ builder.setMessage(TestAllTypes.newBuilder()
+ .setOptionalInt32(10)
+ .buildPartial());
+ builder.mergeFrom(TestAllTypes.newBuilder()
+ .setOptionalDouble(5.0)
+ .buildPartial());
+ assertEquals(10, builder.getMessage().getOptionalInt32());
+ assertEquals(5.0, builder.getMessage().getOptionalDouble());
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/SmallSortedMapTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/SmallSortedMapTest.java
new file mode 100644
index 0000000000..a7f8342d13
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/SmallSortedMapTest.java
@@ -0,0 +1,422 @@
+// 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.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+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
+ */
+public class SmallSortedMapTest extends TestCase {
+ // java.util.AbstractMap.SimpleEntry is private in JDK 1.5. We re-implement it
+ // here for JDK 1.5 users.
+ private static class SimpleEntry<K, V> implements Map.Entry<K, V> {
+ private final K key;
+ private V value;
+
+ SimpleEntry(K key, V value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ @Override
+ public K getKey() {
+ return key;
+ }
+
+ @Override
+ public V getValue() {
+ return value;
+ }
+
+ @Override
+ public V setValue(V value) {
+ V oldValue = this.value;
+ this.value = value;
+ return oldValue;
+ }
+
+ private static boolean eq(Object o1, Object o2) {
+ return o1 == null ? o2 == null : o1.equals(o2);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof Map.Entry))
+ return false;
+ Map.Entry e = (Map.Entry) o;
+ return eq(key, e.getKey()) && eq(value, e.getValue());
+ }
+
+ @Override
+ public int hashCode() {
+ return ((key == null) ? 0 : key.hashCode()) ^
+ ((value == null) ? 0 : value.hashCode());
+ }
+ }
+
+ public void testPutAndGetArrayEntriesOnly() {
+ runPutAndGetTest(3);
+ }
+
+ public void testPutAndGetOverflowEntries() {
+ runPutAndGetTest(6);
+ }
+
+ private void runPutAndGetTest(int numElements) {
+ // Test with even and odd arraySize
+ SmallSortedMap<Integer, Integer> map1 =
+ SmallSortedMap.newInstanceForTest(3);
+ SmallSortedMap<Integer, Integer> map2 =
+ SmallSortedMap.newInstanceForTest(4);
+ SmallSortedMap<Integer, Integer> map3 =
+ SmallSortedMap.newInstanceForTest(3);
+ SmallSortedMap<Integer, Integer> map4 =
+ SmallSortedMap.newInstanceForTest(4);
+
+ // Test with puts in ascending order.
+ for (int i = 0; i < numElements; i++) {
+ assertNull(map1.put(i, i + 1));
+ assertNull(map2.put(i, i + 1));
+ }
+ // Test with puts in descending order.
+ for (int i = numElements - 1; i >= 0; i--) {
+ assertNull(map3.put(i, i + 1));
+ assertNull(map4.put(i, i + 1));
+ }
+
+ assertEquals(Math.min(3, numElements), map1.getNumArrayEntries());
+ assertEquals(Math.min(4, numElements), map2.getNumArrayEntries());
+ assertEquals(Math.min(3, numElements), map3.getNumArrayEntries());
+ assertEquals(Math.min(4, numElements), map4.getNumArrayEntries());
+
+ List<SmallSortedMap<Integer, Integer>> allMaps =
+ new ArrayList<SmallSortedMap<Integer, Integer>>();
+ allMaps.add(map1);
+ allMaps.add(map2);
+ allMaps.add(map3);
+ allMaps.add(map4);
+
+ for (SmallSortedMap<Integer, Integer> map : allMaps) {
+ assertEquals(numElements, map.size());
+ for (int i = 0; i < numElements; i++) {
+ assertEquals(new Integer(i + 1), map.get(i));
+ }
+ }
+
+ assertEquals(map1, map2);
+ assertEquals(map2, map3);
+ assertEquals(map3, map4);
+ }
+
+ public void testReplacingPut() {
+ SmallSortedMap<Integer, Integer> map = SmallSortedMap.newInstanceForTest(3);
+ for (int i = 0; i < 6; i++) {
+ assertNull(map.put(i, i + 1));
+ assertNull(map.remove(i + 1));
+ }
+ for (int i = 0; i < 6; i++) {
+ assertEquals(new Integer(i + 1), map.put(i, i + 2));
+ }
+ }
+
+ public void testRemove() {
+ SmallSortedMap<Integer, Integer> map = SmallSortedMap.newInstanceForTest(3);
+ for (int i = 0; i < 6; i++) {
+ assertNull(map.put(i, i + 1));
+ assertNull(map.remove(i + 1));
+ }
+
+ assertEquals(3, map.getNumArrayEntries());
+ assertEquals(3, map.getNumOverflowEntries());
+ assertEquals(6, map.size());
+ assertEquals(makeSortedKeySet(0, 1, 2, 3, 4, 5), map.keySet());
+
+ assertEquals(new Integer(2), map.remove(1));
+ assertEquals(3, map.getNumArrayEntries());
+ assertEquals(2, map.getNumOverflowEntries());
+ assertEquals(5, map.size());
+ assertEquals(makeSortedKeySet(0, 2, 3, 4, 5), map.keySet());
+
+ assertEquals(new Integer(5), map.remove(4));
+ assertEquals(3, map.getNumArrayEntries());
+ assertEquals(1, map.getNumOverflowEntries());
+ assertEquals(4, map.size());
+ assertEquals(makeSortedKeySet(0, 2, 3, 5), map.keySet());
+
+ assertEquals(new Integer(4), map.remove(3));
+ assertEquals(3, map.getNumArrayEntries());
+ assertEquals(0, map.getNumOverflowEntries());
+ assertEquals(3, map.size());
+ assertEquals(makeSortedKeySet(0, 2, 5), map.keySet());
+
+ assertNull(map.remove(3));
+ assertEquals(3, map.getNumArrayEntries());
+ assertEquals(0, map.getNumOverflowEntries());
+ assertEquals(3, map.size());
+
+ assertEquals(new Integer(1), map.remove(0));
+ assertEquals(2, map.getNumArrayEntries());
+ assertEquals(0, map.getNumOverflowEntries());
+ assertEquals(2, map.size());
+ }
+
+ public void testClear() {
+ SmallSortedMap<Integer, Integer> map = SmallSortedMap.newInstanceForTest(3);
+ for (int i = 0; i < 6; i++) {
+ assertNull(map.put(i, i + 1));
+ }
+ map.clear();
+ assertEquals(0, map.getNumArrayEntries());
+ assertEquals(0, map.getNumOverflowEntries());
+ assertEquals(0, map.size());
+ }
+
+ public void testGetArrayEntryAndOverflowEntries() {
+ SmallSortedMap<Integer, Integer> map = SmallSortedMap.newInstanceForTest(3);
+ for (int i = 0; i < 6; i++) {
+ assertNull(map.put(i, i + 1));
+ }
+ assertEquals(3, map.getNumArrayEntries());
+ for (int i = 0; i < 3; i++) {
+ Map.Entry<Integer, Integer> entry = map.getArrayEntryAt(i);
+ assertEquals(new Integer(i), entry.getKey());
+ assertEquals(new Integer(i + 1), entry.getValue());
+ }
+ Iterator<Map.Entry<Integer, Integer>> it =
+ map.getOverflowEntries().iterator();
+ for (int i = 3; i < 6; i++) {
+ assertTrue(it.hasNext());
+ Map.Entry<Integer, Integer> entry = it.next();
+ assertEquals(new Integer(i), entry.getKey());
+ assertEquals(new Integer(i + 1), entry.getValue());
+ }
+ assertFalse(it.hasNext());
+ }
+
+ public void testEntrySetContains() {
+ SmallSortedMap<Integer, Integer> map = SmallSortedMap.newInstanceForTest(3);
+ for (int i = 0; i < 6; i++) {
+ assertNull(map.put(i, i + 1));
+ }
+ Set<Map.Entry<Integer, Integer>> entrySet = map.entrySet();
+ for (int i = 0; i < 6; i++) {
+ assertTrue(
+ entrySet.contains(new SimpleEntry<Integer, Integer>(i, i + 1)));
+ assertFalse(
+ entrySet.contains(new SimpleEntry<Integer, Integer>(i, i)));
+ }
+ }
+
+ public void testEntrySetAdd() {
+ SmallSortedMap<Integer, Integer> map = SmallSortedMap.newInstanceForTest(3);
+ Set<Map.Entry<Integer, Integer>> entrySet = map.entrySet();
+ for (int i = 0; i < 6; i++) {
+ Map.Entry<Integer, Integer> entry =
+ new SimpleEntry<Integer, Integer>(i, i + 1);
+ assertTrue(entrySet.add(entry));
+ assertFalse(entrySet.add(entry));
+ }
+ for (int i = 0; i < 6; i++) {
+ assertEquals(new Integer(i + 1), map.get(i));
+ }
+ assertEquals(3, map.getNumArrayEntries());
+ assertEquals(3, map.getNumOverflowEntries());
+ assertEquals(6, map.size());
+ }
+
+ public void testEntrySetRemove() {
+ SmallSortedMap<Integer, Integer> map = SmallSortedMap.newInstanceForTest(3);
+ Set<Map.Entry<Integer, Integer>> entrySet = map.entrySet();
+ for (int i = 0; i < 6; i++) {
+ assertNull(map.put(i, i + 1));
+ }
+ for (int i = 0; i < 6; i++) {
+ Map.Entry<Integer, Integer> entry =
+ new SimpleEntry<Integer, Integer>(i, i + 1);
+ assertTrue(entrySet.remove(entry));
+ assertFalse(entrySet.remove(entry));
+ }
+ assertTrue(map.isEmpty());
+ assertEquals(0, map.getNumArrayEntries());
+ assertEquals(0, map.getNumOverflowEntries());
+ assertEquals(0, map.size());
+ }
+
+ public void testEntrySetClear() {
+ SmallSortedMap<Integer, Integer> map = SmallSortedMap.newInstanceForTest(3);
+ for (int i = 0; i < 6; i++) {
+ assertNull(map.put(i, i + 1));
+ }
+ map.entrySet().clear();
+ assertTrue(map.isEmpty());
+ assertEquals(0, map.getNumArrayEntries());
+ assertEquals(0, map.getNumOverflowEntries());
+ assertEquals(0, map.size());
+ }
+
+ public void testEntrySetIteratorNext() {
+ SmallSortedMap<Integer, Integer> map = SmallSortedMap.newInstanceForTest(3);
+ for (int i = 0; i < 6; i++) {
+ assertNull(map.put(i, i + 1));
+ }
+ Iterator<Map.Entry<Integer, Integer>> it = map.entrySet().iterator();
+ for (int i = 0; i < 6; i++) {
+ assertTrue(it.hasNext());
+ Map.Entry<Integer, Integer> entry = it.next();
+ assertEquals(new Integer(i), entry.getKey());
+ assertEquals(new Integer(i + 1), entry.getValue());
+ }
+ assertFalse(it.hasNext());
+ }
+
+ public void testEntrySetIteratorRemove() {
+ SmallSortedMap<Integer, Integer> map = SmallSortedMap.newInstanceForTest(3);
+ for (int i = 0; i < 6; i++) {
+ assertNull(map.put(i, i + 1));
+ }
+ Iterator<Map.Entry<Integer, Integer>> it = map.entrySet().iterator();
+ for (int i = 0; i < 6; i++) {
+ assertTrue(map.containsKey(i));
+ it.next();
+ it.remove();
+ assertFalse(map.containsKey(i));
+ assertEquals(6 - i - 1, map.size());
+ }
+ }
+
+ public void testMapEntryModification() {
+ SmallSortedMap<Integer, Integer> map = SmallSortedMap.newInstanceForTest(3);
+ for (int i = 0; i < 6; i++) {
+ assertNull(map.put(i, i + 1));
+ }
+ Iterator<Map.Entry<Integer, Integer>> it = map.entrySet().iterator();
+ for (int i = 0; i < 6; i++) {
+ Map.Entry<Integer, Integer> entry = it.next();
+ entry.setValue(i + 23);
+ }
+ for (int i = 0; i < 6; i++) {
+ assertEquals(new Integer(i + 23), map.get(i));
+ }
+ }
+
+ public void testMakeImmutable() {
+ SmallSortedMap<Integer, Integer> map = SmallSortedMap.newInstanceForTest(3);
+ for (int i = 0; i < 6; i++) {
+ assertNull(map.put(i, i + 1));
+ }
+ map.makeImmutable();
+ assertEquals(new Integer(1), map.get(0));
+ assertEquals(6, map.size());
+
+ try {
+ map.put(23, 23);
+ fail("Expected UnsupportedOperationException");
+ } catch (UnsupportedOperationException expected) {
+ }
+
+ Map<Integer, Integer> other = new HashMap<Integer, Integer>();
+ other.put(23, 23);
+ try {
+ map.putAll(other);
+ fail("Expected UnsupportedOperationException");
+ } catch (UnsupportedOperationException expected) {
+ }
+
+ try {
+ map.remove(0);
+ fail("Expected UnsupportedOperationException");
+ } catch (UnsupportedOperationException expected) {
+ }
+
+ try {
+ map.clear();
+ fail("Expected UnsupportedOperationException");
+ } catch (UnsupportedOperationException expected) {
+ }
+
+ Set<Map.Entry<Integer, Integer>> entrySet = map.entrySet();
+ try {
+ entrySet.clear();
+ fail("Expected UnsupportedOperationException");
+ } catch (UnsupportedOperationException expected) {
+ }
+
+ Iterator<Map.Entry<Integer, Integer>> it = entrySet.iterator();
+ while (it.hasNext()) {
+ Map.Entry<Integer, Integer> entry = it.next();
+ try {
+ entry.setValue(0);
+ fail("Expected UnsupportedOperationException");
+ } catch (UnsupportedOperationException expected) {
+ }
+ try {
+ it.remove();
+ fail("Expected UnsupportedOperationException");
+ } catch (UnsupportedOperationException expected) {
+ }
+ }
+
+ Set<Integer> keySet = map.keySet();
+ try {
+ keySet.clear();
+ fail("Expected UnsupportedOperationException");
+ } catch (UnsupportedOperationException expected) {
+ }
+
+ Iterator<Integer> keys = keySet.iterator();
+ while (keys.hasNext()) {
+ Integer key = keys.next();
+ try {
+ keySet.remove(key);
+ fail("Expected UnsupportedOperationException");
+ } catch (UnsupportedOperationException expected) {
+ }
+ try {
+ keys.remove();
+ fail("Expected UnsupportedOperationException");
+ } catch (UnsupportedOperationException expected) {
+ }
+ }
+ }
+
+ private Set<Integer> makeSortedKeySet(Integer... keys) {
+ return new TreeSet<Integer>(Arrays.<Integer>asList(keys));
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java
new file mode 100644
index 0000000000..2c60fe0e1b
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TestBadIdentifiers.java
@@ -0,0 +1,96 @@
+// 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 junit.framework.TestCase;
+
+/**
+ * Tests that proto2 api generation doesn't cause compile errors when
+ * compiling protocol buffers that have names that would otherwise conflict
+ * if not fully qualified (like @Deprecated and @Override).
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class TestBadIdentifiers extends TestCase {
+
+ public void testCompilation() {
+ // If this compiles, it means the generation was correct.
+ TestBadIdentifiersProto.Deprecated.newBuilder();
+ TestBadIdentifiersProto.Override.newBuilder();
+ }
+
+ public void testGetDescriptor() {
+ Descriptors.FileDescriptor fileDescriptor =
+ TestBadIdentifiersProto.getDescriptor();
+ String descriptorField = TestBadIdentifiersProto.Descriptor
+ .getDefaultInstance().getDescriptor();
+ Descriptors.Descriptor protoDescriptor = TestBadIdentifiersProto.Descriptor
+ .getDefaultInstance().getDescriptorForType();
+ String nestedDescriptorField = TestBadIdentifiersProto.Descriptor
+ .NestedDescriptor.getDefaultInstance().getDescriptor();
+ Descriptors.Descriptor nestedProtoDescriptor = TestBadIdentifiersProto
+ .Descriptor.NestedDescriptor.getDefaultInstance()
+ .getDescriptorForType();
+ }
+
+ public void testConflictingFieldNames() throws Exception {
+ TestBadIdentifiersProto.TestConflictingFieldNames message =
+ TestBadIdentifiersProto.TestConflictingFieldNames.getDefaultInstance();
+ // Make sure generated accessors are properly named.
+ assertEquals(0, message.getInt32Field1Count());
+ assertEquals(0, message.getEnumField2Count());
+ assertEquals(0, message.getStringField3Count());
+ assertEquals(0, message.getBytesField4Count());
+ assertEquals(0, message.getMessageField5Count());
+
+ assertEquals(0, message.getInt32FieldCount11());
+ assertEquals(0, message.getEnumFieldCount12().getNumber());
+ assertEquals("", message.getStringFieldCount13());
+ assertEquals(ByteString.EMPTY, message.getBytesFieldCount14());
+ assertEquals(0, message.getMessageFieldCount15().getSerializedSize());
+
+ assertEquals(0, message.getInt32Field21Count());
+ assertEquals(0, message.getEnumField22Count());
+ assertEquals(0, message.getStringField23Count());
+ assertEquals(0, message.getBytesField24Count());
+ assertEquals(0, message.getMessageField25Count());
+
+ assertEquals(0, message.getInt32Field1List().size());
+ assertEquals(0, message.getInt32FieldList31());
+
+ assertEquals(0, message.getInt64FieldCount());
+ assertEquals(0L, message.getExtension(
+ TestBadIdentifiersProto.TestConflictingFieldNames.int64FieldCount).longValue());
+ assertEquals(0L, message.getExtension(
+ TestBadIdentifiersProto.TestConflictingFieldNames.int64FieldList).longValue());
+
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TestUtil.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TestUtil.java
new file mode 100644
index 0000000000..c1bd21db5c
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TestUtil.java
@@ -0,0 +1,3866 @@
+// 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 static com.google.protobuf.UnittestLite.defaultBoolExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultBytesExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultCordExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultDoubleExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultFixed32ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultFixed64ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultFloatExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultForeignEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultImportEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultInt32ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultInt64ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultNestedEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultSfixed32ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultSfixed64ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultSint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultSint64ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultStringExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultStringPieceExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultUint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultUint64ExtensionLite;
+import static com.google.protobuf.UnittestLite.oneofBytesExtensionLite;
+import static com.google.protobuf.UnittestLite.oneofNestedMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.oneofStringExtensionLite;
+import static com.google.protobuf.UnittestLite.oneofUint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalBoolExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalBytesExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalCordExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalDoubleExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalFixed32ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalFixed64ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalFloatExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalForeignEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalForeignMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalGroupExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalImportEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalImportMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalInt32ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalInt64ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalLazyMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalNestedEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalNestedMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalPublicImportMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalSfixed32ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalSfixed64ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalSint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalSint64ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalStringExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalStringPieceExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalUint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalUint64ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedBoolExtensionLite;
+import static com.google.protobuf.UnittestLite.packedDoubleExtensionLite;
+import static com.google.protobuf.UnittestLite.packedEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.packedFixed32ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedFixed64ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedFloatExtensionLite;
+import static com.google.protobuf.UnittestLite.packedInt32ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedInt64ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedSfixed32ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedSfixed64ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedSint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedSint64ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedUint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedUint64ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedBoolExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedBytesExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedCordExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedDoubleExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedFixed32ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedFixed64ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedFloatExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedForeignEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedForeignMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedGroupExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedImportEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedImportMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedInt32ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedInt64ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedLazyMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedNestedEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedNestedMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedSfixed32ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedSfixed64ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedSint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedSint64ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedStringExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedStringPieceExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedUint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedUint64ExtensionLite;
+import static protobuf_unittest.UnittestProto.OptionalGroup_extension;
+import static protobuf_unittest.UnittestProto.RepeatedGroup_extension;
+import static protobuf_unittest.UnittestProto.defaultBoolExtension;
+import static protobuf_unittest.UnittestProto.defaultBytesExtension;
+import static protobuf_unittest.UnittestProto.defaultCordExtension;
+import static protobuf_unittest.UnittestProto.defaultDoubleExtension;
+import static protobuf_unittest.UnittestProto.defaultFixed32Extension;
+import static protobuf_unittest.UnittestProto.defaultFixed64Extension;
+import static protobuf_unittest.UnittestProto.defaultFloatExtension;
+import static protobuf_unittest.UnittestProto.defaultForeignEnumExtension;
+import static protobuf_unittest.UnittestProto.defaultImportEnumExtension;
+// The static imports are to avoid 100+ char lines. The following is roughly equivalent to
+// import static protobuf_unittest.UnittestProto.*;
+import static protobuf_unittest.UnittestProto.defaultInt32Extension;
+import static protobuf_unittest.UnittestProto.defaultInt64Extension;
+import static protobuf_unittest.UnittestProto.defaultNestedEnumExtension;
+import static protobuf_unittest.UnittestProto.defaultSfixed32Extension;
+import static protobuf_unittest.UnittestProto.defaultSfixed64Extension;
+import static protobuf_unittest.UnittestProto.defaultSint32Extension;
+import static protobuf_unittest.UnittestProto.defaultSint64Extension;
+import static protobuf_unittest.UnittestProto.defaultStringExtension;
+import static protobuf_unittest.UnittestProto.defaultStringPieceExtension;
+import static protobuf_unittest.UnittestProto.defaultUint32Extension;
+import static protobuf_unittest.UnittestProto.defaultUint64Extension;
+import static protobuf_unittest.UnittestProto.oneofBytesExtension;
+import static protobuf_unittest.UnittestProto.oneofNestedMessageExtension;
+import static protobuf_unittest.UnittestProto.oneofStringExtension;
+import static protobuf_unittest.UnittestProto.oneofUint32Extension;
+import static protobuf_unittest.UnittestProto.optionalBoolExtension;
+import static protobuf_unittest.UnittestProto.optionalBytesExtension;
+import static protobuf_unittest.UnittestProto.optionalCordExtension;
+import static protobuf_unittest.UnittestProto.optionalDoubleExtension;
+import static protobuf_unittest.UnittestProto.optionalFixed32Extension;
+import static protobuf_unittest.UnittestProto.optionalFixed64Extension;
+import static protobuf_unittest.UnittestProto.optionalFloatExtension;
+import static protobuf_unittest.UnittestProto.optionalForeignEnumExtension;
+import static protobuf_unittest.UnittestProto.optionalForeignMessageExtension;
+import static protobuf_unittest.UnittestProto.optionalGroupExtension;
+import static protobuf_unittest.UnittestProto.optionalImportEnumExtension;
+import static protobuf_unittest.UnittestProto.optionalImportMessageExtension;
+import static protobuf_unittest.UnittestProto.optionalInt32Extension;
+import static protobuf_unittest.UnittestProto.optionalInt64Extension;
+import static protobuf_unittest.UnittestProto.optionalLazyMessageExtension;
+import static protobuf_unittest.UnittestProto.optionalNestedEnumExtension;
+import static protobuf_unittest.UnittestProto.optionalNestedMessageExtension;
+import static protobuf_unittest.UnittestProto.optionalPublicImportMessageExtension;
+import static protobuf_unittest.UnittestProto.optionalSfixed32Extension;
+import static protobuf_unittest.UnittestProto.optionalSfixed64Extension;
+import static protobuf_unittest.UnittestProto.optionalSint32Extension;
+import static protobuf_unittest.UnittestProto.optionalSint64Extension;
+import static protobuf_unittest.UnittestProto.optionalStringExtension;
+import static protobuf_unittest.UnittestProto.optionalStringPieceExtension;
+import static protobuf_unittest.UnittestProto.optionalUint32Extension;
+import static protobuf_unittest.UnittestProto.optionalUint64Extension;
+import static protobuf_unittest.UnittestProto.packedBoolExtension;
+import static protobuf_unittest.UnittestProto.packedDoubleExtension;
+import static protobuf_unittest.UnittestProto.packedEnumExtension;
+import static protobuf_unittest.UnittestProto.packedFixed32Extension;
+import static protobuf_unittest.UnittestProto.packedFixed64Extension;
+import static protobuf_unittest.UnittestProto.packedFloatExtension;
+import static protobuf_unittest.UnittestProto.packedInt32Extension;
+import static protobuf_unittest.UnittestProto.packedInt64Extension;
+import static protobuf_unittest.UnittestProto.packedSfixed32Extension;
+import static protobuf_unittest.UnittestProto.packedSfixed64Extension;
+import static protobuf_unittest.UnittestProto.packedSint32Extension;
+import static protobuf_unittest.UnittestProto.packedSint64Extension;
+import static protobuf_unittest.UnittestProto.packedUint32Extension;
+import static protobuf_unittest.UnittestProto.packedUint64Extension;
+import static protobuf_unittest.UnittestProto.repeatedBoolExtension;
+import static protobuf_unittest.UnittestProto.repeatedBytesExtension;
+import static protobuf_unittest.UnittestProto.repeatedCordExtension;
+import static protobuf_unittest.UnittestProto.repeatedDoubleExtension;
+import static protobuf_unittest.UnittestProto.repeatedFixed32Extension;
+import static protobuf_unittest.UnittestProto.repeatedFixed64Extension;
+import static protobuf_unittest.UnittestProto.repeatedFloatExtension;
+import static protobuf_unittest.UnittestProto.repeatedForeignEnumExtension;
+import static protobuf_unittest.UnittestProto.repeatedForeignMessageExtension;
+import static protobuf_unittest.UnittestProto.repeatedGroupExtension;
+import static protobuf_unittest.UnittestProto.repeatedImportEnumExtension;
+import static protobuf_unittest.UnittestProto.repeatedImportMessageExtension;
+import static protobuf_unittest.UnittestProto.repeatedInt32Extension;
+import static protobuf_unittest.UnittestProto.repeatedInt64Extension;
+import static protobuf_unittest.UnittestProto.repeatedLazyMessageExtension;
+import static protobuf_unittest.UnittestProto.repeatedNestedEnumExtension;
+import static protobuf_unittest.UnittestProto.repeatedNestedMessageExtension;
+import static protobuf_unittest.UnittestProto.repeatedSfixed32Extension;
+import static protobuf_unittest.UnittestProto.repeatedSfixed64Extension;
+import static protobuf_unittest.UnittestProto.repeatedSint32Extension;
+import static protobuf_unittest.UnittestProto.repeatedSint64Extension;
+import static protobuf_unittest.UnittestProto.repeatedStringExtension;
+import static protobuf_unittest.UnittestProto.repeatedStringPieceExtension;
+import static protobuf_unittest.UnittestProto.repeatedUint32Extension;
+import static protobuf_unittest.UnittestProto.repeatedUint64Extension;
+
+import com.google.protobuf.UnittestImportLite.ImportEnumLite;
+import com.google.protobuf.UnittestLite.ForeignEnumLite;
+import com.google.protobuf.UnittestLite.TestAllExtensionsLiteOrBuilder;
+import com.google.protobuf.UnittestLite.TestAllTypesLite;
+import com.google.protobuf.UnittestLite.TestPackedExtensionsLite;
+import com.google.protobuf.test.UnittestImport.ImportEnum;
+import com.google.protobuf.test.UnittestImport.ImportMessage;
+import com.google.protobuf.test.UnittestImportPublic.PublicImportMessage;
+import protobuf_unittest.UnittestProto;
+import protobuf_unittest.UnittestProto.ForeignEnum;
+import protobuf_unittest.UnittestProto.ForeignMessage;
+import protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestAllExtensionsOrBuilder;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestAllTypesOrBuilder;
+import protobuf_unittest.UnittestProto.TestOneof2;
+import protobuf_unittest.UnittestProto.TestPackedExtensions;
+import protobuf_unittest.UnittestProto.TestPackedTypes;
+import protobuf_unittest.UnittestProto.TestUnpackedTypes;
+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
+ * some values as well as checking that all the fields are set to those values.
+ * These are useful for testing various protocol message features, e.g.
+ * set all fields of a message, serialize it, parse it, and check that all
+ * fields are set.
+ *
+ * <p>This code is not to be used outside of {@code com.google.protobuf} and
+ * subpackages.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public final class TestUtil {
+ private TestUtil() {}
+
+ /** Helper to convert a String to ByteString. */
+ static ByteString toBytes(String str) {
+ 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)}.
+ */
+ public static TestAllTypes getAllSet() {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ setAllFields(builder);
+ return builder.build();
+ }
+
+ /**
+ * Get a {@code TestAllTypes.Builder} with all fields set as they would be by
+ * {@link #setAllFields(TestAllTypes.Builder)}.
+ */
+ public static TestAllTypes.Builder getAllSetBuilder() {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ setAllFields(builder);
+ return builder;
+ }
+
+ /**
+ * Get a {@code TestAllExtensions} with all fields set as they would be by
+ * {@link #setAllExtensions(TestAllExtensions.Builder)}.
+ */
+ public static TestAllExtensions getAllExtensionsSet() {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ setAllExtensions(builder);
+ return builder.build();
+ }
+
+ public static TestPackedTypes getPackedSet() {
+ TestPackedTypes.Builder builder = TestPackedTypes.newBuilder();
+ setPackedFields(builder);
+ return builder.build();
+ }
+
+ public static TestUnpackedTypes getUnpackedSet() {
+ TestUnpackedTypes.Builder builder = TestUnpackedTypes.newBuilder();
+ setUnpackedFields(builder);
+ return builder.build();
+ }
+
+ public static TestPackedExtensions getPackedExtensionsSet() {
+ TestPackedExtensions.Builder builder = TestPackedExtensions.newBuilder();
+ setPackedExtensions(builder);
+ return builder.build();
+ }
+
+ /**
+ * Set every field of {@code message} to the values expected by
+ * {@code assertAllFieldsSet()}.
+ */
+ public static void setAllFields(TestAllTypes.Builder message) {
+ message.setOptionalInt32 (101);
+ message.setOptionalInt64 (102);
+ message.setOptionalUint32 (103);
+ message.setOptionalUint64 (104);
+ message.setOptionalSint32 (105);
+ message.setOptionalSint64 (106);
+ message.setOptionalFixed32 (107);
+ message.setOptionalFixed64 (108);
+ message.setOptionalSfixed32(109);
+ message.setOptionalSfixed64(110);
+ message.setOptionalFloat (111);
+ message.setOptionalDouble (112);
+ message.setOptionalBool (true);
+ message.setOptionalString ("115");
+ message.setOptionalBytes (toBytes("116"));
+
+ message.setOptionalGroup(
+ TestAllTypes.OptionalGroup.newBuilder().setA(117).build());
+ message.setOptionalNestedMessage(
+ TestAllTypes.NestedMessage.newBuilder().setBb(118).build());
+ message.setOptionalForeignMessage(
+ ForeignMessage.newBuilder().setC(119).build());
+ message.setOptionalImportMessage(
+ ImportMessage.newBuilder().setD(120).build());
+ message.setOptionalPublicImportMessage(
+ PublicImportMessage.newBuilder().setE(126).build());
+ message.setOptionalLazyMessage(
+ TestAllTypes.NestedMessage.newBuilder().setBb(127).build());
+
+ message.setOptionalNestedEnum (TestAllTypes.NestedEnum.BAZ);
+ message.setOptionalForeignEnum(ForeignEnum.FOREIGN_BAZ);
+ message.setOptionalImportEnum (ImportEnum.IMPORT_BAZ);
+
+ message.setOptionalStringPiece("124");
+ message.setOptionalCord("125");
+
+ // -----------------------------------------------------------------
+
+ message.addRepeatedInt32 (201);
+ message.addRepeatedInt64 (202);
+ message.addRepeatedUint32 (203);
+ message.addRepeatedUint64 (204);
+ message.addRepeatedSint32 (205);
+ message.addRepeatedSint64 (206);
+ message.addRepeatedFixed32 (207);
+ message.addRepeatedFixed64 (208);
+ message.addRepeatedSfixed32(209);
+ message.addRepeatedSfixed64(210);
+ message.addRepeatedFloat (211);
+ message.addRepeatedDouble (212);
+ message.addRepeatedBool (true);
+ message.addRepeatedString ("215");
+ message.addRepeatedBytes (toBytes("216"));
+
+ message.addRepeatedGroup(
+ TestAllTypes.RepeatedGroup.newBuilder().setA(217).build());
+ message.addRepeatedNestedMessage(
+ TestAllTypes.NestedMessage.newBuilder().setBb(218).build());
+ message.addRepeatedForeignMessage(
+ ForeignMessage.newBuilder().setC(219).build());
+ message.addRepeatedImportMessage(
+ ImportMessage.newBuilder().setD(220).build());
+ message.addRepeatedLazyMessage(
+ TestAllTypes.NestedMessage.newBuilder().setBb(227).build());
+
+ message.addRepeatedNestedEnum (TestAllTypes.NestedEnum.BAR);
+ message.addRepeatedForeignEnum(ForeignEnum.FOREIGN_BAR);
+ message.addRepeatedImportEnum (ImportEnum.IMPORT_BAR);
+
+ message.addRepeatedStringPiece("224");
+ message.addRepeatedCord("225");
+
+ // Add a second one of each field.
+ message.addRepeatedInt32 (301);
+ message.addRepeatedInt64 (302);
+ message.addRepeatedUint32 (303);
+ message.addRepeatedUint64 (304);
+ message.addRepeatedSint32 (305);
+ message.addRepeatedSint64 (306);
+ message.addRepeatedFixed32 (307);
+ message.addRepeatedFixed64 (308);
+ message.addRepeatedSfixed32(309);
+ message.addRepeatedSfixed64(310);
+ message.addRepeatedFloat (311);
+ message.addRepeatedDouble (312);
+ message.addRepeatedBool (false);
+ message.addRepeatedString ("315");
+ message.addRepeatedBytes (toBytes("316"));
+
+ message.addRepeatedGroup(
+ TestAllTypes.RepeatedGroup.newBuilder().setA(317).build());
+ message.addRepeatedNestedMessage(
+ TestAllTypes.NestedMessage.newBuilder().setBb(318).build());
+ message.addRepeatedForeignMessage(
+ ForeignMessage.newBuilder().setC(319).build());
+ message.addRepeatedImportMessage(
+ ImportMessage.newBuilder().setD(320).build());
+ message.addRepeatedLazyMessage(
+ TestAllTypes.NestedMessage.newBuilder().setBb(327).build());
+
+ message.addRepeatedNestedEnum (TestAllTypes.NestedEnum.BAZ);
+ message.addRepeatedForeignEnum(ForeignEnum.FOREIGN_BAZ);
+ message.addRepeatedImportEnum (ImportEnum.IMPORT_BAZ);
+
+ message.addRepeatedStringPiece("324");
+ message.addRepeatedCord("325");
+
+ // -----------------------------------------------------------------
+
+ message.setDefaultInt32 (401);
+ message.setDefaultInt64 (402);
+ message.setDefaultUint32 (403);
+ message.setDefaultUint64 (404);
+ message.setDefaultSint32 (405);
+ message.setDefaultSint64 (406);
+ message.setDefaultFixed32 (407);
+ message.setDefaultFixed64 (408);
+ message.setDefaultSfixed32(409);
+ message.setDefaultSfixed64(410);
+ message.setDefaultFloat (411);
+ message.setDefaultDouble (412);
+ message.setDefaultBool (false);
+ message.setDefaultString ("415");
+ message.setDefaultBytes (toBytes("416"));
+
+ message.setDefaultNestedEnum (TestAllTypes.NestedEnum.FOO);
+ message.setDefaultForeignEnum(ForeignEnum.FOREIGN_FOO);
+ message.setDefaultImportEnum (ImportEnum.IMPORT_FOO);
+
+ message.setDefaultStringPiece("424");
+ message.setDefaultCord("425");
+
+ message.setOneofUint32(601);
+ message.setOneofNestedMessage(
+ TestAllTypes.NestedMessage.newBuilder().setBb(602).build());
+ message.setOneofString("603");
+ message.setOneofBytes(toBytes("604"));
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Modify the repeated fields of {@code message} to contain the values
+ * expected by {@code assertRepeatedFieldsModified()}.
+ */
+ public static void modifyRepeatedFields(TestAllTypes.Builder message) {
+ message.setRepeatedInt32 (1, 501);
+ message.setRepeatedInt64 (1, 502);
+ message.setRepeatedUint32 (1, 503);
+ message.setRepeatedUint64 (1, 504);
+ message.setRepeatedSint32 (1, 505);
+ message.setRepeatedSint64 (1, 506);
+ message.setRepeatedFixed32 (1, 507);
+ message.setRepeatedFixed64 (1, 508);
+ message.setRepeatedSfixed32(1, 509);
+ message.setRepeatedSfixed64(1, 510);
+ message.setRepeatedFloat (1, 511);
+ message.setRepeatedDouble (1, 512);
+ message.setRepeatedBool (1, true);
+ message.setRepeatedString (1, "515");
+ message.setRepeatedBytes (1, toBytes("516"));
+
+ message.setRepeatedGroup(1,
+ TestAllTypes.RepeatedGroup.newBuilder().setA(517).build());
+ message.setRepeatedNestedMessage(1,
+ TestAllTypes.NestedMessage.newBuilder().setBb(518).build());
+ message.setRepeatedForeignMessage(1,
+ ForeignMessage.newBuilder().setC(519).build());
+ message.setRepeatedImportMessage(1,
+ ImportMessage.newBuilder().setD(520).build());
+ message.setRepeatedLazyMessage(1,
+ TestAllTypes.NestedMessage.newBuilder().setBb(527).build());
+
+ message.setRepeatedNestedEnum (1, TestAllTypes.NestedEnum.FOO);
+ message.setRepeatedForeignEnum(1, ForeignEnum.FOREIGN_FOO);
+ message.setRepeatedImportEnum (1, ImportEnum.IMPORT_FOO);
+
+ message.setRepeatedStringPiece(1, "524");
+ message.setRepeatedCord(1, "525");
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all fields of
+ * {@code message} are set to the values assigned by {@code setAllFields}.
+ */
+ public static void assertAllFieldsSet(TestAllTypesOrBuilder message) {
+ Assert.assertTrue(message.hasOptionalInt32 ());
+ Assert.assertTrue(message.hasOptionalInt64 ());
+ Assert.assertTrue(message.hasOptionalUint32 ());
+ Assert.assertTrue(message.hasOptionalUint64 ());
+ Assert.assertTrue(message.hasOptionalSint32 ());
+ Assert.assertTrue(message.hasOptionalSint64 ());
+ Assert.assertTrue(message.hasOptionalFixed32 ());
+ Assert.assertTrue(message.hasOptionalFixed64 ());
+ Assert.assertTrue(message.hasOptionalSfixed32());
+ Assert.assertTrue(message.hasOptionalSfixed64());
+ Assert.assertTrue(message.hasOptionalFloat ());
+ Assert.assertTrue(message.hasOptionalDouble ());
+ Assert.assertTrue(message.hasOptionalBool ());
+ Assert.assertTrue(message.hasOptionalString ());
+ Assert.assertTrue(message.hasOptionalBytes ());
+
+ Assert.assertTrue(message.hasOptionalGroup ());
+ Assert.assertTrue(message.hasOptionalNestedMessage ());
+ Assert.assertTrue(message.hasOptionalForeignMessage());
+ Assert.assertTrue(message.hasOptionalImportMessage ());
+
+ Assert.assertTrue(message.getOptionalGroup ().hasA());
+ Assert.assertTrue(message.getOptionalNestedMessage ().hasBb());
+ Assert.assertTrue(message.getOptionalForeignMessage().hasC());
+ Assert.assertTrue(message.getOptionalImportMessage ().hasD());
+
+ Assert.assertTrue(message.hasOptionalNestedEnum ());
+ Assert.assertTrue(message.hasOptionalForeignEnum());
+ Assert.assertTrue(message.hasOptionalImportEnum ());
+
+ Assert.assertTrue(message.hasOptionalStringPiece());
+ Assert.assertTrue(message.hasOptionalCord());
+
+ Assert.assertEquals(101 , message.getOptionalInt32 ());
+ Assert.assertEquals(102 , message.getOptionalInt64 ());
+ Assert.assertEquals(103 , message.getOptionalUint32 ());
+ Assert.assertEquals(104 , message.getOptionalUint64 ());
+ Assert.assertEquals(105 , message.getOptionalSint32 ());
+ Assert.assertEquals(106 , message.getOptionalSint64 ());
+ Assert.assertEquals(107 , message.getOptionalFixed32 ());
+ Assert.assertEquals(108 , message.getOptionalFixed64 ());
+ Assert.assertEquals(109 , message.getOptionalSfixed32());
+ Assert.assertEquals(110 , message.getOptionalSfixed64());
+ Assert.assertEquals(111 , message.getOptionalFloat (), 0.0);
+ Assert.assertEquals(112 , message.getOptionalDouble (), 0.0);
+ Assert.assertEquals(true , message.getOptionalBool ());
+ Assert.assertEquals("115", message.getOptionalString ());
+ Assert.assertEquals(toBytes("116"), message.getOptionalBytes());
+
+ Assert.assertEquals(117, message.getOptionalGroup ().getA());
+ Assert.assertEquals(118, message.getOptionalNestedMessage ().getBb());
+ Assert.assertEquals(119, message.getOptionalForeignMessage ().getC());
+ Assert.assertEquals(120, message.getOptionalImportMessage ().getD());
+ Assert.assertEquals(126, message.getOptionalPublicImportMessage().getE());
+ Assert.assertEquals(127, message.getOptionalLazyMessage ().getBb());
+
+ Assert.assertEquals(TestAllTypes.NestedEnum.BAZ, message.getOptionalNestedEnum());
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAZ, message.getOptionalForeignEnum());
+ Assert.assertEquals(ImportEnum.IMPORT_BAZ, message.getOptionalImportEnum());
+
+ Assert.assertEquals("124", message.getOptionalStringPiece());
+ Assert.assertEquals("125", message.getOptionalCord());
+
+ // -----------------------------------------------------------------
+
+ Assert.assertEquals(2, message.getRepeatedInt32Count ());
+ Assert.assertEquals(2, message.getRepeatedInt64Count ());
+ Assert.assertEquals(2, message.getRepeatedUint32Count ());
+ Assert.assertEquals(2, message.getRepeatedUint64Count ());
+ Assert.assertEquals(2, message.getRepeatedSint32Count ());
+ Assert.assertEquals(2, message.getRepeatedSint64Count ());
+ Assert.assertEquals(2, message.getRepeatedFixed32Count ());
+ Assert.assertEquals(2, message.getRepeatedFixed64Count ());
+ Assert.assertEquals(2, message.getRepeatedSfixed32Count());
+ Assert.assertEquals(2, message.getRepeatedSfixed64Count());
+ Assert.assertEquals(2, message.getRepeatedFloatCount ());
+ Assert.assertEquals(2, message.getRepeatedDoubleCount ());
+ Assert.assertEquals(2, message.getRepeatedBoolCount ());
+ Assert.assertEquals(2, message.getRepeatedStringCount ());
+ Assert.assertEquals(2, message.getRepeatedBytesCount ());
+
+ Assert.assertEquals(2, message.getRepeatedGroupCount ());
+ Assert.assertEquals(2, message.getRepeatedNestedMessageCount ());
+ Assert.assertEquals(2, message.getRepeatedForeignMessageCount());
+ Assert.assertEquals(2, message.getRepeatedImportMessageCount ());
+ Assert.assertEquals(2, message.getRepeatedLazyMessageCount ());
+ Assert.assertEquals(2, message.getRepeatedNestedEnumCount ());
+ Assert.assertEquals(2, message.getRepeatedForeignEnumCount ());
+ Assert.assertEquals(2, message.getRepeatedImportEnumCount ());
+
+ Assert.assertEquals(2, message.getRepeatedStringPieceCount());
+ Assert.assertEquals(2, message.getRepeatedCordCount());
+
+ Assert.assertEquals(201 , message.getRepeatedInt32 (0));
+ Assert.assertEquals(202 , message.getRepeatedInt64 (0));
+ Assert.assertEquals(203 , message.getRepeatedUint32 (0));
+ Assert.assertEquals(204 , message.getRepeatedUint64 (0));
+ Assert.assertEquals(205 , message.getRepeatedSint32 (0));
+ Assert.assertEquals(206 , message.getRepeatedSint64 (0));
+ Assert.assertEquals(207 , message.getRepeatedFixed32 (0));
+ Assert.assertEquals(208 , message.getRepeatedFixed64 (0));
+ Assert.assertEquals(209 , message.getRepeatedSfixed32(0));
+ Assert.assertEquals(210 , message.getRepeatedSfixed64(0));
+ Assert.assertEquals(211 , message.getRepeatedFloat (0), 0.0);
+ Assert.assertEquals(212 , message.getRepeatedDouble (0), 0.0);
+ Assert.assertEquals(true , message.getRepeatedBool (0));
+ Assert.assertEquals("215", message.getRepeatedString (0));
+ Assert.assertEquals(toBytes("216"), message.getRepeatedBytes(0));
+
+ Assert.assertEquals(217, message.getRepeatedGroup (0).getA());
+ Assert.assertEquals(218, message.getRepeatedNestedMessage (0).getBb());
+ Assert.assertEquals(219, message.getRepeatedForeignMessage(0).getC());
+ Assert.assertEquals(220, message.getRepeatedImportMessage (0).getD());
+ Assert.assertEquals(227, message.getRepeatedLazyMessage (0).getBb());
+
+ Assert.assertEquals(TestAllTypes.NestedEnum.BAR, message.getRepeatedNestedEnum (0));
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAR, message.getRepeatedForeignEnum(0));
+ Assert.assertEquals(ImportEnum.IMPORT_BAR, message.getRepeatedImportEnum(0));
+
+ Assert.assertEquals("224", message.getRepeatedStringPiece(0));
+ Assert.assertEquals("225", message.getRepeatedCord(0));
+
+ Assert.assertEquals(301 , message.getRepeatedInt32 (1));
+ Assert.assertEquals(302 , message.getRepeatedInt64 (1));
+ Assert.assertEquals(303 , message.getRepeatedUint32 (1));
+ Assert.assertEquals(304 , message.getRepeatedUint64 (1));
+ Assert.assertEquals(305 , message.getRepeatedSint32 (1));
+ Assert.assertEquals(306 , message.getRepeatedSint64 (1));
+ Assert.assertEquals(307 , message.getRepeatedFixed32 (1));
+ Assert.assertEquals(308 , message.getRepeatedFixed64 (1));
+ Assert.assertEquals(309 , message.getRepeatedSfixed32(1));
+ Assert.assertEquals(310 , message.getRepeatedSfixed64(1));
+ Assert.assertEquals(311 , message.getRepeatedFloat (1), 0.0);
+ Assert.assertEquals(312 , message.getRepeatedDouble (1), 0.0);
+ Assert.assertEquals(false, message.getRepeatedBool (1));
+ Assert.assertEquals("315", message.getRepeatedString (1));
+ Assert.assertEquals(toBytes("316"), message.getRepeatedBytes(1));
+
+ Assert.assertEquals(317, message.getRepeatedGroup (1).getA());
+ Assert.assertEquals(318, message.getRepeatedNestedMessage (1).getBb());
+ Assert.assertEquals(319, message.getRepeatedForeignMessage(1).getC());
+ Assert.assertEquals(320, message.getRepeatedImportMessage (1).getD());
+ Assert.assertEquals(327, message.getRepeatedLazyMessage (1).getBb());
+
+ Assert.assertEquals(TestAllTypes.NestedEnum.BAZ, message.getRepeatedNestedEnum (1));
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAZ, message.getRepeatedForeignEnum(1));
+ Assert.assertEquals(ImportEnum.IMPORT_BAZ, message.getRepeatedImportEnum(1));
+
+ Assert.assertEquals("324", message.getRepeatedStringPiece(1));
+ Assert.assertEquals("325", message.getRepeatedCord(1));
+
+ // -----------------------------------------------------------------
+
+ Assert.assertTrue(message.hasDefaultInt32 ());
+ Assert.assertTrue(message.hasDefaultInt64 ());
+ Assert.assertTrue(message.hasDefaultUint32 ());
+ Assert.assertTrue(message.hasDefaultUint64 ());
+ Assert.assertTrue(message.hasDefaultSint32 ());
+ Assert.assertTrue(message.hasDefaultSint64 ());
+ Assert.assertTrue(message.hasDefaultFixed32 ());
+ Assert.assertTrue(message.hasDefaultFixed64 ());
+ Assert.assertTrue(message.hasDefaultSfixed32());
+ Assert.assertTrue(message.hasDefaultSfixed64());
+ Assert.assertTrue(message.hasDefaultFloat ());
+ Assert.assertTrue(message.hasDefaultDouble ());
+ Assert.assertTrue(message.hasDefaultBool ());
+ Assert.assertTrue(message.hasDefaultString ());
+ Assert.assertTrue(message.hasDefaultBytes ());
+
+ Assert.assertTrue(message.hasDefaultNestedEnum ());
+ Assert.assertTrue(message.hasDefaultForeignEnum());
+ Assert.assertTrue(message.hasDefaultImportEnum ());
+
+ Assert.assertTrue(message.hasDefaultStringPiece());
+ Assert.assertTrue(message.hasDefaultCord());
+
+ Assert.assertEquals(401 , message.getDefaultInt32 ());
+ Assert.assertEquals(402 , message.getDefaultInt64 ());
+ Assert.assertEquals(403 , message.getDefaultUint32 ());
+ Assert.assertEquals(404 , message.getDefaultUint64 ());
+ Assert.assertEquals(405 , message.getDefaultSint32 ());
+ Assert.assertEquals(406 , message.getDefaultSint64 ());
+ Assert.assertEquals(407 , message.getDefaultFixed32 ());
+ Assert.assertEquals(408 , message.getDefaultFixed64 ());
+ Assert.assertEquals(409 , message.getDefaultSfixed32());
+ Assert.assertEquals(410 , message.getDefaultSfixed64());
+ Assert.assertEquals(411 , message.getDefaultFloat (), 0.0);
+ Assert.assertEquals(412 , message.getDefaultDouble (), 0.0);
+ Assert.assertEquals(false, message.getDefaultBool ());
+ Assert.assertEquals("415", message.getDefaultString ());
+ Assert.assertEquals(toBytes("416"), message.getDefaultBytes());
+
+ Assert.assertEquals(TestAllTypes.NestedEnum.FOO, message.getDefaultNestedEnum ());
+ Assert.assertEquals(ForeignEnum.FOREIGN_FOO, message.getDefaultForeignEnum());
+ Assert.assertEquals(ImportEnum.IMPORT_FOO, message.getDefaultImportEnum());
+
+ Assert.assertEquals("424", message.getDefaultStringPiece());
+ Assert.assertEquals("425", message.getDefaultCord());
+
+ Assert.assertEquals(TestAllTypes.OneofFieldCase.ONEOF_BYTES, message.getOneofFieldCase());
+ Assert.assertFalse(message.hasOneofUint32());
+ Assert.assertFalse(message.hasOneofNestedMessage());
+ Assert.assertFalse(message.hasOneofString());
+ Assert.assertTrue(message.hasOneofBytes());
+
+ Assert.assertEquals(toBytes("604"), message.getOneofBytes());
+ }
+
+ // -------------------------------------------------------------------
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all fields of
+ * {@code message} are cleared, and that getting the fields returns their
+ * default values.
+ */
+ public static void assertClear(TestAllTypesOrBuilder message) {
+ // hasBlah() should initially be false for all optional fields.
+ Assert.assertFalse(message.hasOptionalInt32 ());
+ Assert.assertFalse(message.hasOptionalInt64 ());
+ Assert.assertFalse(message.hasOptionalUint32 ());
+ Assert.assertFalse(message.hasOptionalUint64 ());
+ Assert.assertFalse(message.hasOptionalSint32 ());
+ Assert.assertFalse(message.hasOptionalSint64 ());
+ Assert.assertFalse(message.hasOptionalFixed32 ());
+ Assert.assertFalse(message.hasOptionalFixed64 ());
+ Assert.assertFalse(message.hasOptionalSfixed32());
+ Assert.assertFalse(message.hasOptionalSfixed64());
+ Assert.assertFalse(message.hasOptionalFloat ());
+ Assert.assertFalse(message.hasOptionalDouble ());
+ Assert.assertFalse(message.hasOptionalBool ());
+ Assert.assertFalse(message.hasOptionalString ());
+ Assert.assertFalse(message.hasOptionalBytes ());
+
+ Assert.assertFalse(message.hasOptionalGroup ());
+ Assert.assertFalse(message.hasOptionalNestedMessage ());
+ Assert.assertFalse(message.hasOptionalForeignMessage());
+ Assert.assertFalse(message.hasOptionalImportMessage ());
+
+ Assert.assertFalse(message.hasOptionalNestedEnum ());
+ Assert.assertFalse(message.hasOptionalForeignEnum());
+ Assert.assertFalse(message.hasOptionalImportEnum ());
+
+ Assert.assertFalse(message.hasOptionalStringPiece());
+ Assert.assertFalse(message.hasOptionalCord());
+
+ // Optional fields without defaults are set to zero or something like it.
+ Assert.assertEquals(0 , message.getOptionalInt32 ());
+ Assert.assertEquals(0 , message.getOptionalInt64 ());
+ Assert.assertEquals(0 , message.getOptionalUint32 ());
+ Assert.assertEquals(0 , message.getOptionalUint64 ());
+ Assert.assertEquals(0 , message.getOptionalSint32 ());
+ Assert.assertEquals(0 , message.getOptionalSint64 ());
+ Assert.assertEquals(0 , message.getOptionalFixed32 ());
+ Assert.assertEquals(0 , message.getOptionalFixed64 ());
+ Assert.assertEquals(0 , message.getOptionalSfixed32());
+ Assert.assertEquals(0 , message.getOptionalSfixed64());
+ Assert.assertEquals(0 , message.getOptionalFloat (), 0.0);
+ Assert.assertEquals(0 , message.getOptionalDouble (), 0.0);
+ Assert.assertEquals(false, message.getOptionalBool ());
+ Assert.assertEquals("" , message.getOptionalString ());
+ Assert.assertEquals(ByteString.EMPTY, message.getOptionalBytes());
+
+ // Embedded messages should also be clear.
+ Assert.assertFalse(message.getOptionalGroup ().hasA());
+ Assert.assertFalse(message.getOptionalNestedMessage ().hasBb());
+ Assert.assertFalse(message.getOptionalForeignMessage ().hasC());
+ Assert.assertFalse(message.getOptionalImportMessage ().hasD());
+ Assert.assertFalse(message.getOptionalPublicImportMessage().hasE());
+ Assert.assertFalse(message.getOptionalLazyMessage ().hasBb());
+
+ Assert.assertEquals(0, message.getOptionalGroup ().getA());
+ Assert.assertEquals(0, message.getOptionalNestedMessage ().getBb());
+ Assert.assertEquals(0, message.getOptionalForeignMessage ().getC());
+ Assert.assertEquals(0, message.getOptionalImportMessage ().getD());
+ Assert.assertEquals(0, message.getOptionalPublicImportMessage().getE());
+ Assert.assertEquals(0, message.getOptionalLazyMessage ().getBb());
+
+ // Enums without defaults are set to the first value in the enum.
+ Assert.assertEquals(TestAllTypes.NestedEnum.FOO, message.getOptionalNestedEnum ());
+ Assert.assertEquals(ForeignEnum.FOREIGN_FOO, message.getOptionalForeignEnum());
+ Assert.assertEquals(ImportEnum.IMPORT_FOO, message.getOptionalImportEnum());
+
+ Assert.assertEquals("", message.getOptionalStringPiece());
+ Assert.assertEquals("", message.getOptionalCord());
+
+ // Repeated fields are empty.
+ Assert.assertEquals(0, message.getRepeatedInt32Count ());
+ Assert.assertEquals(0, message.getRepeatedInt64Count ());
+ Assert.assertEquals(0, message.getRepeatedUint32Count ());
+ Assert.assertEquals(0, message.getRepeatedUint64Count ());
+ Assert.assertEquals(0, message.getRepeatedSint32Count ());
+ Assert.assertEquals(0, message.getRepeatedSint64Count ());
+ Assert.assertEquals(0, message.getRepeatedFixed32Count ());
+ Assert.assertEquals(0, message.getRepeatedFixed64Count ());
+ Assert.assertEquals(0, message.getRepeatedSfixed32Count());
+ Assert.assertEquals(0, message.getRepeatedSfixed64Count());
+ Assert.assertEquals(0, message.getRepeatedFloatCount ());
+ Assert.assertEquals(0, message.getRepeatedDoubleCount ());
+ Assert.assertEquals(0, message.getRepeatedBoolCount ());
+ Assert.assertEquals(0, message.getRepeatedStringCount ());
+ Assert.assertEquals(0, message.getRepeatedBytesCount ());
+
+ Assert.assertEquals(0, message.getRepeatedGroupCount ());
+ Assert.assertEquals(0, message.getRepeatedNestedMessageCount ());
+ Assert.assertEquals(0, message.getRepeatedForeignMessageCount());
+ Assert.assertEquals(0, message.getRepeatedImportMessageCount ());
+ Assert.assertEquals(0, message.getRepeatedLazyMessageCount ());
+ Assert.assertEquals(0, message.getRepeatedNestedEnumCount ());
+ Assert.assertEquals(0, message.getRepeatedForeignEnumCount ());
+ Assert.assertEquals(0, message.getRepeatedImportEnumCount ());
+
+ Assert.assertEquals(0, message.getRepeatedStringPieceCount());
+ Assert.assertEquals(0, message.getRepeatedCordCount());
+
+ // hasBlah() should also be false for all default fields.
+ Assert.assertFalse(message.hasDefaultInt32 ());
+ Assert.assertFalse(message.hasDefaultInt64 ());
+ Assert.assertFalse(message.hasDefaultUint32 ());
+ Assert.assertFalse(message.hasDefaultUint64 ());
+ Assert.assertFalse(message.hasDefaultSint32 ());
+ Assert.assertFalse(message.hasDefaultSint64 ());
+ Assert.assertFalse(message.hasDefaultFixed32 ());
+ Assert.assertFalse(message.hasDefaultFixed64 ());
+ Assert.assertFalse(message.hasDefaultSfixed32());
+ Assert.assertFalse(message.hasDefaultSfixed64());
+ Assert.assertFalse(message.hasDefaultFloat ());
+ Assert.assertFalse(message.hasDefaultDouble ());
+ Assert.assertFalse(message.hasDefaultBool ());
+ Assert.assertFalse(message.hasDefaultString ());
+ Assert.assertFalse(message.hasDefaultBytes ());
+
+ Assert.assertFalse(message.hasDefaultNestedEnum ());
+ Assert.assertFalse(message.hasDefaultForeignEnum());
+ Assert.assertFalse(message.hasDefaultImportEnum ());
+
+ Assert.assertFalse(message.hasDefaultStringPiece());
+ Assert.assertFalse(message.hasDefaultCord());
+
+ // Fields with defaults have their default values (duh).
+ Assert.assertEquals( 41 , message.getDefaultInt32 ());
+ Assert.assertEquals( 42 , message.getDefaultInt64 ());
+ Assert.assertEquals( 43 , message.getDefaultUint32 ());
+ Assert.assertEquals( 44 , message.getDefaultUint64 ());
+ Assert.assertEquals(-45 , message.getDefaultSint32 ());
+ Assert.assertEquals( 46 , message.getDefaultSint64 ());
+ Assert.assertEquals( 47 , message.getDefaultFixed32 ());
+ Assert.assertEquals( 48 , message.getDefaultFixed64 ());
+ Assert.assertEquals( 49 , message.getDefaultSfixed32());
+ Assert.assertEquals(-50 , message.getDefaultSfixed64());
+ Assert.assertEquals( 51.5 , message.getDefaultFloat (), 0.0);
+ Assert.assertEquals( 52e3 , message.getDefaultDouble (), 0.0);
+ Assert.assertEquals(true , message.getDefaultBool ());
+ Assert.assertEquals("hello", message.getDefaultString ());
+ Assert.assertEquals(toBytes("world"), message.getDefaultBytes());
+
+ Assert.assertEquals(TestAllTypes.NestedEnum.BAR, message.getDefaultNestedEnum ());
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAR, message.getDefaultForeignEnum());
+ Assert.assertEquals(ImportEnum.IMPORT_BAR, message.getDefaultImportEnum());
+
+ Assert.assertEquals("abc", message.getDefaultStringPiece());
+ Assert.assertEquals("123", message.getDefaultCord());
+
+ Assert.assertFalse(message.hasOneofUint32());
+ Assert.assertFalse(message.hasOneofNestedMessage());
+ Assert.assertFalse(message.hasOneofString());
+ Assert.assertFalse(message.hasOneofBytes());
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all fields of
+ * {@code message} are set to the values assigned by {@code setAllFields}
+ * followed by {@code modifyRepeatedFields}.
+ */
+ public static void assertRepeatedFieldsModified(
+ TestAllTypesOrBuilder message) {
+ // ModifyRepeatedFields only sets the second repeated element of each
+ // field. In addition to verifying this, we also verify that the first
+ // element and size were *not* modified.
+ Assert.assertEquals(2, message.getRepeatedInt32Count ());
+ Assert.assertEquals(2, message.getRepeatedInt64Count ());
+ Assert.assertEquals(2, message.getRepeatedUint32Count ());
+ Assert.assertEquals(2, message.getRepeatedUint64Count ());
+ Assert.assertEquals(2, message.getRepeatedSint32Count ());
+ Assert.assertEquals(2, message.getRepeatedSint64Count ());
+ Assert.assertEquals(2, message.getRepeatedFixed32Count ());
+ Assert.assertEquals(2, message.getRepeatedFixed64Count ());
+ Assert.assertEquals(2, message.getRepeatedSfixed32Count());
+ Assert.assertEquals(2, message.getRepeatedSfixed64Count());
+ Assert.assertEquals(2, message.getRepeatedFloatCount ());
+ Assert.assertEquals(2, message.getRepeatedDoubleCount ());
+ Assert.assertEquals(2, message.getRepeatedBoolCount ());
+ Assert.assertEquals(2, message.getRepeatedStringCount ());
+ Assert.assertEquals(2, message.getRepeatedBytesCount ());
+
+ Assert.assertEquals(2, message.getRepeatedGroupCount ());
+ Assert.assertEquals(2, message.getRepeatedNestedMessageCount ());
+ Assert.assertEquals(2, message.getRepeatedForeignMessageCount());
+ Assert.assertEquals(2, message.getRepeatedImportMessageCount ());
+ Assert.assertEquals(2, message.getRepeatedLazyMessageCount ());
+ Assert.assertEquals(2, message.getRepeatedNestedEnumCount ());
+ Assert.assertEquals(2, message.getRepeatedForeignEnumCount ());
+ Assert.assertEquals(2, message.getRepeatedImportEnumCount ());
+
+ Assert.assertEquals(2, message.getRepeatedStringPieceCount());
+ Assert.assertEquals(2, message.getRepeatedCordCount());
+
+ Assert.assertEquals(201 , message.getRepeatedInt32 (0));
+ Assert.assertEquals(202L , message.getRepeatedInt64 (0));
+ Assert.assertEquals(203 , message.getRepeatedUint32 (0));
+ Assert.assertEquals(204L , message.getRepeatedUint64 (0));
+ Assert.assertEquals(205 , message.getRepeatedSint32 (0));
+ Assert.assertEquals(206L , message.getRepeatedSint64 (0));
+ Assert.assertEquals(207 , message.getRepeatedFixed32 (0));
+ Assert.assertEquals(208L , message.getRepeatedFixed64 (0));
+ Assert.assertEquals(209 , message.getRepeatedSfixed32(0));
+ Assert.assertEquals(210L , message.getRepeatedSfixed64(0));
+ Assert.assertEquals(211F , message.getRepeatedFloat (0));
+ Assert.assertEquals(212D , message.getRepeatedDouble (0));
+ Assert.assertEquals(true , message.getRepeatedBool (0));
+ Assert.assertEquals("215", message.getRepeatedString (0));
+ Assert.assertEquals(toBytes("216"), message.getRepeatedBytes(0));
+
+ Assert.assertEquals(217, message.getRepeatedGroup (0).getA());
+ Assert.assertEquals(218, message.getRepeatedNestedMessage (0).getBb());
+ Assert.assertEquals(219, message.getRepeatedForeignMessage(0).getC());
+ Assert.assertEquals(220, message.getRepeatedImportMessage (0).getD());
+ Assert.assertEquals(227, message.getRepeatedLazyMessage (0).getBb());
+
+ Assert.assertEquals(TestAllTypes.NestedEnum.BAR, message.getRepeatedNestedEnum (0));
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAR, message.getRepeatedForeignEnum(0));
+ Assert.assertEquals(ImportEnum.IMPORT_BAR, message.getRepeatedImportEnum(0));
+
+ Assert.assertEquals("224", message.getRepeatedStringPiece(0));
+ Assert.assertEquals("225", message.getRepeatedCord(0));
+
+ // Actually verify the second (modified) elements now.
+ Assert.assertEquals(501 , message.getRepeatedInt32 (1));
+ Assert.assertEquals(502L , message.getRepeatedInt64 (1));
+ Assert.assertEquals(503 , message.getRepeatedUint32 (1));
+ Assert.assertEquals(504L , message.getRepeatedUint64 (1));
+ Assert.assertEquals(505 , message.getRepeatedSint32 (1));
+ Assert.assertEquals(506L , message.getRepeatedSint64 (1));
+ Assert.assertEquals(507 , message.getRepeatedFixed32 (1));
+ Assert.assertEquals(508L , message.getRepeatedFixed64 (1));
+ Assert.assertEquals(509 , message.getRepeatedSfixed32(1));
+ Assert.assertEquals(510L , message.getRepeatedSfixed64(1));
+ Assert.assertEquals(511F , message.getRepeatedFloat (1));
+ Assert.assertEquals(512D , message.getRepeatedDouble (1));
+ Assert.assertEquals(true , message.getRepeatedBool (1));
+ Assert.assertEquals("515", message.getRepeatedString (1));
+ Assert.assertEquals(toBytes("516"), message.getRepeatedBytes(1));
+
+ Assert.assertEquals(517, message.getRepeatedGroup (1).getA());
+ Assert.assertEquals(518, message.getRepeatedNestedMessage (1).getBb());
+ Assert.assertEquals(519, message.getRepeatedForeignMessage(1).getC());
+ Assert.assertEquals(520, message.getRepeatedImportMessage (1).getD());
+ Assert.assertEquals(527, message.getRepeatedLazyMessage (1).getBb());
+
+ Assert.assertEquals(TestAllTypes.NestedEnum.FOO, message.getRepeatedNestedEnum (1));
+ Assert.assertEquals(ForeignEnum.FOREIGN_FOO, message.getRepeatedForeignEnum(1));
+ Assert.assertEquals(ImportEnum.IMPORT_FOO, message.getRepeatedImportEnum(1));
+
+ Assert.assertEquals("524", message.getRepeatedStringPiece(1));
+ Assert.assertEquals("525", message.getRepeatedCord(1));
+ }
+
+ /**
+ * Set every field of {@code message} to a unique value.
+ */
+ public static void setPackedFields(TestPackedTypes.Builder message) {
+ message.addPackedInt32 (601);
+ message.addPackedInt64 (602);
+ message.addPackedUint32 (603);
+ message.addPackedUint64 (604);
+ message.addPackedSint32 (605);
+ message.addPackedSint64 (606);
+ message.addPackedFixed32 (607);
+ message.addPackedFixed64 (608);
+ message.addPackedSfixed32(609);
+ message.addPackedSfixed64(610);
+ message.addPackedFloat (611);
+ message.addPackedDouble (612);
+ message.addPackedBool (true);
+ message.addPackedEnum (ForeignEnum.FOREIGN_BAR);
+ // Add a second one of each field.
+ message.addPackedInt32 (701);
+ message.addPackedInt64 (702);
+ message.addPackedUint32 (703);
+ message.addPackedUint64 (704);
+ message.addPackedSint32 (705);
+ message.addPackedSint64 (706);
+ message.addPackedFixed32 (707);
+ message.addPackedFixed64 (708);
+ message.addPackedSfixed32(709);
+ message.addPackedSfixed64(710);
+ message.addPackedFloat (711);
+ message.addPackedDouble (712);
+ message.addPackedBool (false);
+ message.addPackedEnum (ForeignEnum.FOREIGN_BAZ);
+ }
+
+ /**
+ * Set every field of {@code message} to a unique value. Must correspond with
+ * the values applied by {@code setPackedFields}.
+ */
+ public static void setUnpackedFields(TestUnpackedTypes.Builder message) {
+ message.addUnpackedInt32 (601);
+ message.addUnpackedInt64 (602);
+ message.addUnpackedUint32 (603);
+ message.addUnpackedUint64 (604);
+ message.addUnpackedSint32 (605);
+ message.addUnpackedSint64 (606);
+ message.addUnpackedFixed32 (607);
+ message.addUnpackedFixed64 (608);
+ message.addUnpackedSfixed32(609);
+ message.addUnpackedSfixed64(610);
+ message.addUnpackedFloat (611);
+ message.addUnpackedDouble (612);
+ message.addUnpackedBool (true);
+ message.addUnpackedEnum (ForeignEnum.FOREIGN_BAR);
+ // Add a second one of each field.
+ message.addUnpackedInt32 (701);
+ message.addUnpackedInt64 (702);
+ message.addUnpackedUint32 (703);
+ message.addUnpackedUint64 (704);
+ message.addUnpackedSint32 (705);
+ message.addUnpackedSint64 (706);
+ message.addUnpackedFixed32 (707);
+ message.addUnpackedFixed64 (708);
+ message.addUnpackedSfixed32(709);
+ message.addUnpackedSfixed64(710);
+ message.addUnpackedFloat (711);
+ message.addUnpackedDouble (712);
+ message.addUnpackedBool (false);
+ message.addUnpackedEnum (ForeignEnum.FOREIGN_BAZ);
+ }
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all fields of
+ * {@code message} are set to the values assigned by {@code setPackedFields}.
+ */
+ public static void assertPackedFieldsSet(TestPackedTypes message) {
+ Assert.assertEquals(2, message.getPackedInt32Count ());
+ Assert.assertEquals(2, message.getPackedInt64Count ());
+ Assert.assertEquals(2, message.getPackedUint32Count ());
+ Assert.assertEquals(2, message.getPackedUint64Count ());
+ Assert.assertEquals(2, message.getPackedSint32Count ());
+ Assert.assertEquals(2, message.getPackedSint64Count ());
+ Assert.assertEquals(2, message.getPackedFixed32Count ());
+ Assert.assertEquals(2, message.getPackedFixed64Count ());
+ Assert.assertEquals(2, message.getPackedSfixed32Count());
+ Assert.assertEquals(2, message.getPackedSfixed64Count());
+ Assert.assertEquals(2, message.getPackedFloatCount ());
+ Assert.assertEquals(2, message.getPackedDoubleCount ());
+ Assert.assertEquals(2, message.getPackedBoolCount ());
+ Assert.assertEquals(2, message.getPackedEnumCount ());
+ Assert.assertEquals(601 , message.getPackedInt32 (0));
+ Assert.assertEquals(602 , message.getPackedInt64 (0));
+ Assert.assertEquals(603 , message.getPackedUint32 (0));
+ Assert.assertEquals(604 , message.getPackedUint64 (0));
+ Assert.assertEquals(605 , message.getPackedSint32 (0));
+ Assert.assertEquals(606 , message.getPackedSint64 (0));
+ Assert.assertEquals(607 , message.getPackedFixed32 (0));
+ Assert.assertEquals(608 , message.getPackedFixed64 (0));
+ Assert.assertEquals(609 , message.getPackedSfixed32(0));
+ Assert.assertEquals(610 , message.getPackedSfixed64(0));
+ Assert.assertEquals(611 , message.getPackedFloat (0), 0.0);
+ Assert.assertEquals(612 , message.getPackedDouble (0), 0.0);
+ Assert.assertEquals(true , message.getPackedBool (0));
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAR, message.getPackedEnum(0));
+ Assert.assertEquals(701 , message.getPackedInt32 (1));
+ Assert.assertEquals(702 , message.getPackedInt64 (1));
+ Assert.assertEquals(703 , message.getPackedUint32 (1));
+ Assert.assertEquals(704 , message.getPackedUint64 (1));
+ Assert.assertEquals(705 , message.getPackedSint32 (1));
+ Assert.assertEquals(706 , message.getPackedSint64 (1));
+ Assert.assertEquals(707 , message.getPackedFixed32 (1));
+ Assert.assertEquals(708 , message.getPackedFixed64 (1));
+ Assert.assertEquals(709 , message.getPackedSfixed32(1));
+ Assert.assertEquals(710 , message.getPackedSfixed64(1));
+ Assert.assertEquals(711 , message.getPackedFloat (1), 0.0);
+ Assert.assertEquals(712 , message.getPackedDouble (1), 0.0);
+ Assert.assertEquals(false, message.getPackedBool (1));
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAZ, message.getPackedEnum(1));
+ }
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all fields of
+ * {@code message} are set to the values assigned by {@code setUnpackedFields}.
+ */
+ public static void assertUnpackedFieldsSet(TestUnpackedTypes message) {
+ Assert.assertEquals(2, message.getUnpackedInt32Count ());
+ Assert.assertEquals(2, message.getUnpackedInt64Count ());
+ Assert.assertEquals(2, message.getUnpackedUint32Count ());
+ Assert.assertEquals(2, message.getUnpackedUint64Count ());
+ Assert.assertEquals(2, message.getUnpackedSint32Count ());
+ Assert.assertEquals(2, message.getUnpackedSint64Count ());
+ Assert.assertEquals(2, message.getUnpackedFixed32Count ());
+ Assert.assertEquals(2, message.getUnpackedFixed64Count ());
+ Assert.assertEquals(2, message.getUnpackedSfixed32Count());
+ Assert.assertEquals(2, message.getUnpackedSfixed64Count());
+ Assert.assertEquals(2, message.getUnpackedFloatCount ());
+ Assert.assertEquals(2, message.getUnpackedDoubleCount ());
+ Assert.assertEquals(2, message.getUnpackedBoolCount ());
+ Assert.assertEquals(2, message.getUnpackedEnumCount ());
+ Assert.assertEquals(601 , message.getUnpackedInt32 (0));
+ Assert.assertEquals(602 , message.getUnpackedInt64 (0));
+ Assert.assertEquals(603 , message.getUnpackedUint32 (0));
+ Assert.assertEquals(604 , message.getUnpackedUint64 (0));
+ Assert.assertEquals(605 , message.getUnpackedSint32 (0));
+ Assert.assertEquals(606 , message.getUnpackedSint64 (0));
+ Assert.assertEquals(607 , message.getUnpackedFixed32 (0));
+ Assert.assertEquals(608 , message.getUnpackedFixed64 (0));
+ Assert.assertEquals(609 , message.getUnpackedSfixed32(0));
+ Assert.assertEquals(610 , message.getUnpackedSfixed64(0));
+ Assert.assertEquals(611 , message.getUnpackedFloat (0), 0.0);
+ Assert.assertEquals(612 , message.getUnpackedDouble (0), 0.0);
+ Assert.assertEquals(true , message.getUnpackedBool (0));
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAR, message.getUnpackedEnum(0));
+ Assert.assertEquals(701 , message.getUnpackedInt32 (1));
+ Assert.assertEquals(702 , message.getUnpackedInt64 (1));
+ Assert.assertEquals(703 , message.getUnpackedUint32 (1));
+ Assert.assertEquals(704 , message.getUnpackedUint64 (1));
+ Assert.assertEquals(705 , message.getUnpackedSint32 (1));
+ Assert.assertEquals(706 , message.getUnpackedSint64 (1));
+ Assert.assertEquals(707 , message.getUnpackedFixed32 (1));
+ Assert.assertEquals(708 , message.getUnpackedFixed64 (1));
+ Assert.assertEquals(709 , message.getUnpackedSfixed32(1));
+ Assert.assertEquals(710 , message.getUnpackedSfixed64(1));
+ Assert.assertEquals(711 , message.getUnpackedFloat (1), 0.0);
+ Assert.assertEquals(712 , message.getUnpackedDouble (1), 0.0);
+ Assert.assertEquals(false, message.getUnpackedBool (1));
+ Assert.assertEquals(ForeignEnum.FOREIGN_BAZ, message.getUnpackedEnum(1));
+ }
+
+ // ===================================================================
+ // Like above, but for extensions
+
+ // Java gets confused with things like assertEquals(int, Integer): it can't
+ // decide whether to call assertEquals(int, int) or assertEquals(Object,
+ // Object). So we define these methods to help it.
+ private static void assertEqualsExactType(int a, int b) {
+ Assert.assertEquals(a, b);
+ }
+ private static void assertEqualsExactType(long a, long b) {
+ Assert.assertEquals(a, b);
+ }
+ private static void assertEqualsExactType(float a, float b) {
+ Assert.assertEquals(a, b, 0.0);
+ }
+ private static void assertEqualsExactType(double a, double b) {
+ Assert.assertEquals(a, b, 0.0);
+ }
+ private static void assertEqualsExactType(boolean a, boolean b) {
+ Assert.assertEquals(a, b);
+ }
+ private static void assertEqualsExactType(String a, String b) {
+ Assert.assertEquals(a, b);
+ }
+ private static void assertEqualsExactType(ByteString a, ByteString b) {
+ Assert.assertEquals(a, b);
+ }
+ private static void assertEqualsExactType(TestAllTypes.NestedEnum a,
+ TestAllTypes.NestedEnum b) {
+ Assert.assertEquals(a, b);
+ }
+ private static void assertEqualsExactType(ForeignEnum a, ForeignEnum b) {
+ Assert.assertEquals(a, b);
+ }
+ private static void assertEqualsExactType(ImportEnum a, ImportEnum b) {
+ Assert.assertEquals(a, b);
+ }
+ private static void assertEqualsExactType(TestAllTypesLite.NestedEnum a,
+ TestAllTypesLite.NestedEnum b) {
+ Assert.assertEquals(a, b);
+ }
+ private static void assertEqualsExactType(ForeignEnumLite a,
+ ForeignEnumLite b) {
+ Assert.assertEquals(a, b);
+ }
+ private static void assertEqualsExactType(ImportEnumLite a,
+ ImportEnumLite b) {
+ Assert.assertEquals(a, b);
+ }
+
+ /**
+ * Get an unmodifiable {@link ExtensionRegistry} containing all the
+ * extensions of {@code TestAllExtensions}.
+ */
+ public static ExtensionRegistry getExtensionRegistry() {
+ ExtensionRegistry registry = ExtensionRegistry.newInstance();
+ registerAllExtensions(registry);
+ return registry.getUnmodifiable();
+ }
+
+ /**
+ * Register all of {@code TestAllExtensions}'s extensions with the
+ * given {@link ExtensionRegistry}.
+ */
+ public static void registerAllExtensions(ExtensionRegistry registry) {
+ UnittestProto.registerAllExtensions(registry);
+ TestUtilLite.registerAllExtensionsLite(registry);
+ }
+
+ /**
+ * Set every field of {@code message} to the values expected by
+ * {@code assertAllExtensionsSet()}.
+ */
+ public static void setAllExtensions(TestAllExtensions.Builder message) {
+ message.setExtension(optionalInt32Extension , 101);
+ message.setExtension(optionalInt64Extension , 102L);
+ message.setExtension(optionalUint32Extension , 103);
+ message.setExtension(optionalUint64Extension , 104L);
+ message.setExtension(optionalSint32Extension , 105);
+ message.setExtension(optionalSint64Extension , 106L);
+ message.setExtension(optionalFixed32Extension , 107);
+ message.setExtension(optionalFixed64Extension , 108L);
+ message.setExtension(optionalSfixed32Extension, 109);
+ message.setExtension(optionalSfixed64Extension, 110L);
+ message.setExtension(optionalFloatExtension , 111F);
+ message.setExtension(optionalDoubleExtension , 112D);
+ message.setExtension(optionalBoolExtension , true);
+ message.setExtension(optionalStringExtension , "115");
+ message.setExtension(optionalBytesExtension , toBytes("116"));
+
+ message.setExtension(optionalGroupExtension,
+ OptionalGroup_extension.newBuilder().setA(117).build());
+ message.setExtension(optionalNestedMessageExtension,
+ TestAllTypes.NestedMessage.newBuilder().setBb(118).build());
+ message.setExtension(optionalForeignMessageExtension,
+ ForeignMessage.newBuilder().setC(119).build());
+ message.setExtension(optionalImportMessageExtension,
+ ImportMessage.newBuilder().setD(120).build());
+ message.setExtension(optionalPublicImportMessageExtension,
+ PublicImportMessage.newBuilder().setE(126).build());
+ message.setExtension(optionalLazyMessageExtension,
+ TestAllTypes.NestedMessage.newBuilder().setBb(127).build());
+
+ message.setExtension(optionalNestedEnumExtension, TestAllTypes.NestedEnum.BAZ);
+ message.setExtension(optionalForeignEnumExtension, ForeignEnum.FOREIGN_BAZ);
+ message.setExtension(optionalImportEnumExtension, ImportEnum.IMPORT_BAZ);
+
+ message.setExtension(optionalStringPieceExtension, "124");
+ message.setExtension(optionalCordExtension, "125");
+
+ // -----------------------------------------------------------------
+
+ message.addExtension(repeatedInt32Extension , 201);
+ message.addExtension(repeatedInt64Extension , 202L);
+ message.addExtension(repeatedUint32Extension , 203);
+ message.addExtension(repeatedUint64Extension , 204L);
+ message.addExtension(repeatedSint32Extension , 205);
+ message.addExtension(repeatedSint64Extension , 206L);
+ message.addExtension(repeatedFixed32Extension , 207);
+ message.addExtension(repeatedFixed64Extension , 208L);
+ message.addExtension(repeatedSfixed32Extension, 209);
+ message.addExtension(repeatedSfixed64Extension, 210L);
+ message.addExtension(repeatedFloatExtension , 211F);
+ message.addExtension(repeatedDoubleExtension , 212D);
+ message.addExtension(repeatedBoolExtension , true);
+ message.addExtension(repeatedStringExtension , "215");
+ message.addExtension(repeatedBytesExtension , toBytes("216"));
+
+ message.addExtension(repeatedGroupExtension,
+ RepeatedGroup_extension.newBuilder().setA(217).build());
+ message.addExtension(repeatedNestedMessageExtension,
+ TestAllTypes.NestedMessage.newBuilder().setBb(218).build());
+ message.addExtension(repeatedForeignMessageExtension,
+ ForeignMessage.newBuilder().setC(219).build());
+ message.addExtension(repeatedImportMessageExtension,
+ ImportMessage.newBuilder().setD(220).build());
+ message.addExtension(repeatedLazyMessageExtension,
+ TestAllTypes.NestedMessage.newBuilder().setBb(227).build());
+
+ message.addExtension(repeatedNestedEnumExtension, TestAllTypes.NestedEnum.BAR);
+ message.addExtension(repeatedForeignEnumExtension, ForeignEnum.FOREIGN_BAR);
+ message.addExtension(repeatedImportEnumExtension, ImportEnum.IMPORT_BAR);
+
+ message.addExtension(repeatedStringPieceExtension, "224");
+ message.addExtension(repeatedCordExtension, "225");
+
+ // Add a second one of each field.
+ message.addExtension(repeatedInt32Extension , 301);
+ message.addExtension(repeatedInt64Extension , 302L);
+ message.addExtension(repeatedUint32Extension , 303);
+ message.addExtension(repeatedUint64Extension , 304L);
+ message.addExtension(repeatedSint32Extension , 305);
+ message.addExtension(repeatedSint64Extension , 306L);
+ message.addExtension(repeatedFixed32Extension , 307);
+ message.addExtension(repeatedFixed64Extension , 308L);
+ message.addExtension(repeatedSfixed32Extension, 309);
+ message.addExtension(repeatedSfixed64Extension, 310L);
+ message.addExtension(repeatedFloatExtension , 311F);
+ message.addExtension(repeatedDoubleExtension , 312D);
+ message.addExtension(repeatedBoolExtension , false);
+ message.addExtension(repeatedStringExtension , "315");
+ message.addExtension(repeatedBytesExtension , toBytes("316"));
+
+ message.addExtension(repeatedGroupExtension,
+ RepeatedGroup_extension.newBuilder().setA(317).build());
+ message.addExtension(repeatedNestedMessageExtension,
+ TestAllTypes.NestedMessage.newBuilder().setBb(318).build());
+ message.addExtension(repeatedForeignMessageExtension,
+ ForeignMessage.newBuilder().setC(319).build());
+ message.addExtension(repeatedImportMessageExtension,
+ ImportMessage.newBuilder().setD(320).build());
+ message.addExtension(repeatedLazyMessageExtension,
+ TestAllTypes.NestedMessage.newBuilder().setBb(327).build());
+
+ message.addExtension(repeatedNestedEnumExtension, TestAllTypes.NestedEnum.BAZ);
+ message.addExtension(repeatedForeignEnumExtension, ForeignEnum.FOREIGN_BAZ);
+ message.addExtension(repeatedImportEnumExtension, ImportEnum.IMPORT_BAZ);
+
+ message.addExtension(repeatedStringPieceExtension, "324");
+ message.addExtension(repeatedCordExtension, "325");
+
+ // -----------------------------------------------------------------
+
+ message.setExtension(defaultInt32Extension , 401);
+ message.setExtension(defaultInt64Extension , 402L);
+ message.setExtension(defaultUint32Extension , 403);
+ message.setExtension(defaultUint64Extension , 404L);
+ message.setExtension(defaultSint32Extension , 405);
+ message.setExtension(defaultSint64Extension , 406L);
+ message.setExtension(defaultFixed32Extension , 407);
+ message.setExtension(defaultFixed64Extension , 408L);
+ message.setExtension(defaultSfixed32Extension, 409);
+ message.setExtension(defaultSfixed64Extension, 410L);
+ message.setExtension(defaultFloatExtension , 411F);
+ message.setExtension(defaultDoubleExtension , 412D);
+ message.setExtension(defaultBoolExtension , false);
+ message.setExtension(defaultStringExtension , "415");
+ message.setExtension(defaultBytesExtension , toBytes("416"));
+
+ message.setExtension(defaultNestedEnumExtension, TestAllTypes.NestedEnum.FOO);
+ message.setExtension(defaultForeignEnumExtension, ForeignEnum.FOREIGN_FOO);
+ message.setExtension(defaultImportEnumExtension, ImportEnum.IMPORT_FOO);
+
+ message.setExtension(defaultStringPieceExtension, "424");
+ message.setExtension(defaultCordExtension, "425");
+
+ message.setExtension(oneofUint32Extension, 601);
+ message.setExtension(oneofNestedMessageExtension,
+ TestAllTypes.NestedMessage.newBuilder().setBb(602).build());
+ message.setExtension(oneofStringExtension, "603");
+ message.setExtension(oneofBytesExtension, toBytes("604"));
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Modify the repeated extensions of {@code message} to contain the values
+ * expected by {@code assertRepeatedExtensionsModified()}.
+ */
+ public static void modifyRepeatedExtensions(
+ TestAllExtensions.Builder message) {
+ message.setExtension(repeatedInt32Extension , 1, 501);
+ message.setExtension(repeatedInt64Extension , 1, 502L);
+ message.setExtension(repeatedUint32Extension , 1, 503);
+ message.setExtension(repeatedUint64Extension , 1, 504L);
+ message.setExtension(repeatedSint32Extension , 1, 505);
+ message.setExtension(repeatedSint64Extension , 1, 506L);
+ message.setExtension(repeatedFixed32Extension , 1, 507);
+ message.setExtension(repeatedFixed64Extension , 1, 508L);
+ message.setExtension(repeatedSfixed32Extension, 1, 509);
+ message.setExtension(repeatedSfixed64Extension, 1, 510L);
+ message.setExtension(repeatedFloatExtension , 1, 511F);
+ message.setExtension(repeatedDoubleExtension , 1, 512D);
+ message.setExtension(repeatedBoolExtension , 1, true);
+ message.setExtension(repeatedStringExtension , 1, "515");
+ message.setExtension(repeatedBytesExtension , 1, toBytes("516"));
+
+ message.setExtension(repeatedGroupExtension, 1,
+ RepeatedGroup_extension.newBuilder().setA(517).build());
+ message.setExtension(repeatedNestedMessageExtension, 1,
+ TestAllTypes.NestedMessage.newBuilder().setBb(518).build());
+ message.setExtension(repeatedForeignMessageExtension, 1,
+ ForeignMessage.newBuilder().setC(519).build());
+ message.setExtension(repeatedImportMessageExtension, 1,
+ ImportMessage.newBuilder().setD(520).build());
+ message.setExtension(repeatedLazyMessageExtension, 1,
+ TestAllTypes.NestedMessage.newBuilder().setBb(527).build());
+
+ message.setExtension(repeatedNestedEnumExtension , 1, TestAllTypes.NestedEnum.FOO);
+ message.setExtension(repeatedForeignEnumExtension, 1, ForeignEnum.FOREIGN_FOO);
+ message.setExtension(repeatedImportEnumExtension , 1, ImportEnum.IMPORT_FOO);
+
+ message.setExtension(repeatedStringPieceExtension, 1, "524");
+ message.setExtension(repeatedCordExtension, 1, "525");
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all extensions of
+ * {@code message} are set to the values assigned by {@code setAllExtensions}.
+ */
+ public static void assertAllExtensionsSet(
+ TestAllExtensionsOrBuilder message) {
+ Assert.assertTrue(message.hasExtension(optionalInt32Extension ));
+ Assert.assertTrue(message.hasExtension(optionalInt64Extension ));
+ Assert.assertTrue(message.hasExtension(optionalUint32Extension ));
+ Assert.assertTrue(message.hasExtension(optionalUint64Extension ));
+ Assert.assertTrue(message.hasExtension(optionalSint32Extension ));
+ Assert.assertTrue(message.hasExtension(optionalSint64Extension ));
+ Assert.assertTrue(message.hasExtension(optionalFixed32Extension ));
+ Assert.assertTrue(message.hasExtension(optionalFixed64Extension ));
+ Assert.assertTrue(message.hasExtension(optionalSfixed32Extension));
+ Assert.assertTrue(message.hasExtension(optionalSfixed64Extension));
+ Assert.assertTrue(message.hasExtension(optionalFloatExtension ));
+ Assert.assertTrue(message.hasExtension(optionalDoubleExtension ));
+ Assert.assertTrue(message.hasExtension(optionalBoolExtension ));
+ Assert.assertTrue(message.hasExtension(optionalStringExtension ));
+ Assert.assertTrue(message.hasExtension(optionalBytesExtension ));
+
+ Assert.assertTrue(message.hasExtension(optionalGroupExtension ));
+ Assert.assertTrue(message.hasExtension(optionalNestedMessageExtension ));
+ Assert.assertTrue(message.hasExtension(optionalForeignMessageExtension));
+ Assert.assertTrue(message.hasExtension(optionalImportMessageExtension ));
+
+ Assert.assertTrue(message.getExtension(optionalGroupExtension ).hasA());
+ Assert.assertTrue(message.getExtension(optionalNestedMessageExtension ).hasBb());
+ Assert.assertTrue(message.getExtension(optionalForeignMessageExtension).hasC());
+ Assert.assertTrue(message.getExtension(optionalImportMessageExtension ).hasD());
+
+ Assert.assertTrue(message.hasExtension(optionalNestedEnumExtension ));
+ Assert.assertTrue(message.hasExtension(optionalForeignEnumExtension));
+ Assert.assertTrue(message.hasExtension(optionalImportEnumExtension ));
+
+ Assert.assertTrue(message.hasExtension(optionalStringPieceExtension));
+ Assert.assertTrue(message.hasExtension(optionalCordExtension));
+
+ assertEqualsExactType(101 , message.getExtension(optionalInt32Extension ));
+ assertEqualsExactType(102L , message.getExtension(optionalInt64Extension ));
+ assertEqualsExactType(103 , message.getExtension(optionalUint32Extension ));
+ assertEqualsExactType(104L , message.getExtension(optionalUint64Extension ));
+ assertEqualsExactType(105 , message.getExtension(optionalSint32Extension ));
+ assertEqualsExactType(106L , message.getExtension(optionalSint64Extension ));
+ assertEqualsExactType(107 , message.getExtension(optionalFixed32Extension ));
+ assertEqualsExactType(108L , message.getExtension(optionalFixed64Extension ));
+ assertEqualsExactType(109 , message.getExtension(optionalSfixed32Extension));
+ assertEqualsExactType(110L , message.getExtension(optionalSfixed64Extension));
+ assertEqualsExactType(111F , message.getExtension(optionalFloatExtension ));
+ assertEqualsExactType(112D , message.getExtension(optionalDoubleExtension ));
+ assertEqualsExactType(true , message.getExtension(optionalBoolExtension ));
+ assertEqualsExactType("115", message.getExtension(optionalStringExtension ));
+ assertEqualsExactType(toBytes("116"), message.getExtension(optionalBytesExtension));
+
+ assertEqualsExactType(117, message.getExtension(optionalGroupExtension ).getA());
+ assertEqualsExactType(118, message.getExtension(optionalNestedMessageExtension ).getBb());
+ assertEqualsExactType(119, message.getExtension(optionalForeignMessageExtension ).getC());
+ assertEqualsExactType(120, message.getExtension(optionalImportMessageExtension ).getD());
+ assertEqualsExactType(126, message.getExtension(optionalPublicImportMessageExtension).getE());
+ assertEqualsExactType(127, message.getExtension(optionalLazyMessageExtension ).getBb());
+
+ assertEqualsExactType(TestAllTypes.NestedEnum.BAZ,
+ message.getExtension(optionalNestedEnumExtension));
+ assertEqualsExactType(ForeignEnum.FOREIGN_BAZ,
+ message.getExtension(optionalForeignEnumExtension));
+ assertEqualsExactType(ImportEnum.IMPORT_BAZ,
+ message.getExtension(optionalImportEnumExtension));
+
+ assertEqualsExactType("124", message.getExtension(optionalStringPieceExtension));
+ assertEqualsExactType("125", message.getExtension(optionalCordExtension));
+
+ // -----------------------------------------------------------------
+
+ Assert.assertEquals(2, message.getExtensionCount(repeatedInt32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedInt64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedUint32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedUint64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSint32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSint64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFixed32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFixed64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSfixed32Extension));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSfixed64Extension));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFloatExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedDoubleExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedBoolExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedStringExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedBytesExtension ));
+
+ Assert.assertEquals(2, message.getExtensionCount(repeatedGroupExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedNestedMessageExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedForeignMessageExtension));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedImportMessageExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedLazyMessageExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedNestedEnumExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedForeignEnumExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedImportEnumExtension ));
+
+ Assert.assertEquals(2, message.getExtensionCount(repeatedStringPieceExtension));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedCordExtension));
+
+ assertEqualsExactType(201 , message.getExtension(repeatedInt32Extension , 0));
+ assertEqualsExactType(202L , message.getExtension(repeatedInt64Extension , 0));
+ assertEqualsExactType(203 , message.getExtension(repeatedUint32Extension , 0));
+ assertEqualsExactType(204L , message.getExtension(repeatedUint64Extension , 0));
+ assertEqualsExactType(205 , message.getExtension(repeatedSint32Extension , 0));
+ assertEqualsExactType(206L , message.getExtension(repeatedSint64Extension , 0));
+ assertEqualsExactType(207 , message.getExtension(repeatedFixed32Extension , 0));
+ assertEqualsExactType(208L , message.getExtension(repeatedFixed64Extension , 0));
+ assertEqualsExactType(209 , message.getExtension(repeatedSfixed32Extension, 0));
+ assertEqualsExactType(210L , message.getExtension(repeatedSfixed64Extension, 0));
+ assertEqualsExactType(211F , message.getExtension(repeatedFloatExtension , 0));
+ assertEqualsExactType(212D , message.getExtension(repeatedDoubleExtension , 0));
+ assertEqualsExactType(true , message.getExtension(repeatedBoolExtension , 0));
+ assertEqualsExactType("215", message.getExtension(repeatedStringExtension , 0));
+ assertEqualsExactType(toBytes("216"), message.getExtension(repeatedBytesExtension, 0));
+
+ assertEqualsExactType(217, message.getExtension(repeatedGroupExtension , 0).getA());
+ assertEqualsExactType(218, message.getExtension(repeatedNestedMessageExtension , 0).getBb());
+ assertEqualsExactType(219, message.getExtension(repeatedForeignMessageExtension, 0).getC());
+ assertEqualsExactType(220, message.getExtension(repeatedImportMessageExtension , 0).getD());
+ assertEqualsExactType(227, message.getExtension(repeatedLazyMessageExtension , 0).getBb());
+
+ assertEqualsExactType(TestAllTypes.NestedEnum.BAR,
+ message.getExtension(repeatedNestedEnumExtension, 0));
+ assertEqualsExactType(ForeignEnum.FOREIGN_BAR,
+ message.getExtension(repeatedForeignEnumExtension, 0));
+ assertEqualsExactType(ImportEnum.IMPORT_BAR,
+ message.getExtension(repeatedImportEnumExtension, 0));
+
+ assertEqualsExactType("224", message.getExtension(repeatedStringPieceExtension, 0));
+ assertEqualsExactType("225", message.getExtension(repeatedCordExtension, 0));
+
+ assertEqualsExactType(301 , message.getExtension(repeatedInt32Extension , 1));
+ assertEqualsExactType(302L , message.getExtension(repeatedInt64Extension , 1));
+ assertEqualsExactType(303 , message.getExtension(repeatedUint32Extension , 1));
+ assertEqualsExactType(304L , message.getExtension(repeatedUint64Extension , 1));
+ assertEqualsExactType(305 , message.getExtension(repeatedSint32Extension , 1));
+ assertEqualsExactType(306L , message.getExtension(repeatedSint64Extension , 1));
+ assertEqualsExactType(307 , message.getExtension(repeatedFixed32Extension , 1));
+ assertEqualsExactType(308L , message.getExtension(repeatedFixed64Extension , 1));
+ assertEqualsExactType(309 , message.getExtension(repeatedSfixed32Extension, 1));
+ assertEqualsExactType(310L , message.getExtension(repeatedSfixed64Extension, 1));
+ assertEqualsExactType(311F , message.getExtension(repeatedFloatExtension , 1));
+ assertEqualsExactType(312D , message.getExtension(repeatedDoubleExtension , 1));
+ assertEqualsExactType(false, message.getExtension(repeatedBoolExtension , 1));
+ assertEqualsExactType("315", message.getExtension(repeatedStringExtension , 1));
+ assertEqualsExactType(toBytes("316"), message.getExtension(repeatedBytesExtension, 1));
+
+ assertEqualsExactType(317, message.getExtension(repeatedGroupExtension , 1).getA());
+ assertEqualsExactType(318, message.getExtension(repeatedNestedMessageExtension , 1).getBb());
+ assertEqualsExactType(319, message.getExtension(repeatedForeignMessageExtension, 1).getC());
+ assertEqualsExactType(320, message.getExtension(repeatedImportMessageExtension , 1).getD());
+ assertEqualsExactType(327, message.getExtension(repeatedLazyMessageExtension , 1).getBb());
+
+ assertEqualsExactType(TestAllTypes.NestedEnum.BAZ,
+ message.getExtension(repeatedNestedEnumExtension, 1));
+ assertEqualsExactType(ForeignEnum.FOREIGN_BAZ,
+ message.getExtension(repeatedForeignEnumExtension, 1));
+ assertEqualsExactType(ImportEnum.IMPORT_BAZ,
+ message.getExtension(repeatedImportEnumExtension, 1));
+
+ assertEqualsExactType("324", message.getExtension(repeatedStringPieceExtension, 1));
+ assertEqualsExactType("325", message.getExtension(repeatedCordExtension, 1));
+
+ // -----------------------------------------------------------------
+
+ Assert.assertTrue(message.hasExtension(defaultInt32Extension ));
+ Assert.assertTrue(message.hasExtension(defaultInt64Extension ));
+ Assert.assertTrue(message.hasExtension(defaultUint32Extension ));
+ Assert.assertTrue(message.hasExtension(defaultUint64Extension ));
+ Assert.assertTrue(message.hasExtension(defaultSint32Extension ));
+ Assert.assertTrue(message.hasExtension(defaultSint64Extension ));
+ Assert.assertTrue(message.hasExtension(defaultFixed32Extension ));
+ Assert.assertTrue(message.hasExtension(defaultFixed64Extension ));
+ Assert.assertTrue(message.hasExtension(defaultSfixed32Extension));
+ Assert.assertTrue(message.hasExtension(defaultSfixed64Extension));
+ Assert.assertTrue(message.hasExtension(defaultFloatExtension ));
+ Assert.assertTrue(message.hasExtension(defaultDoubleExtension ));
+ Assert.assertTrue(message.hasExtension(defaultBoolExtension ));
+ Assert.assertTrue(message.hasExtension(defaultStringExtension ));
+ Assert.assertTrue(message.hasExtension(defaultBytesExtension ));
+
+ Assert.assertTrue(message.hasExtension(defaultNestedEnumExtension ));
+ Assert.assertTrue(message.hasExtension(defaultForeignEnumExtension));
+ Assert.assertTrue(message.hasExtension(defaultImportEnumExtension ));
+
+ Assert.assertTrue(message.hasExtension(defaultStringPieceExtension));
+ Assert.assertTrue(message.hasExtension(defaultCordExtension));
+
+ assertEqualsExactType(401 , message.getExtension(defaultInt32Extension ));
+ assertEqualsExactType(402L , message.getExtension(defaultInt64Extension ));
+ assertEqualsExactType(403 , message.getExtension(defaultUint32Extension ));
+ assertEqualsExactType(404L , message.getExtension(defaultUint64Extension ));
+ assertEqualsExactType(405 , message.getExtension(defaultSint32Extension ));
+ assertEqualsExactType(406L , message.getExtension(defaultSint64Extension ));
+ assertEqualsExactType(407 , message.getExtension(defaultFixed32Extension ));
+ assertEqualsExactType(408L , message.getExtension(defaultFixed64Extension ));
+ assertEqualsExactType(409 , message.getExtension(defaultSfixed32Extension));
+ assertEqualsExactType(410L , message.getExtension(defaultSfixed64Extension));
+ assertEqualsExactType(411F , message.getExtension(defaultFloatExtension ));
+ assertEqualsExactType(412D , message.getExtension(defaultDoubleExtension ));
+ assertEqualsExactType(false, message.getExtension(defaultBoolExtension ));
+ assertEqualsExactType("415", message.getExtension(defaultStringExtension ));
+ assertEqualsExactType(toBytes("416"), message.getExtension(defaultBytesExtension));
+
+ assertEqualsExactType(TestAllTypes.NestedEnum.FOO,
+ message.getExtension(defaultNestedEnumExtension ));
+ assertEqualsExactType(ForeignEnum.FOREIGN_FOO,
+ message.getExtension(defaultForeignEnumExtension));
+ assertEqualsExactType(ImportEnum.IMPORT_FOO,
+ message.getExtension(defaultImportEnumExtension));
+
+ assertEqualsExactType("424", message.getExtension(defaultStringPieceExtension));
+ assertEqualsExactType("425", message.getExtension(defaultCordExtension));
+
+ Assert.assertTrue(message.hasExtension(oneofBytesExtension));
+
+ assertEqualsExactType(toBytes("604"), message.getExtension(oneofBytesExtension));
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all extensions of
+ * {@code message} are cleared, and that getting the extensions returns their
+ * default values.
+ */
+ public static void assertExtensionsClear(TestAllExtensionsOrBuilder message) {
+ // hasBlah() should initially be false for all optional fields.
+ Assert.assertFalse(message.hasExtension(optionalInt32Extension ));
+ Assert.assertFalse(message.hasExtension(optionalInt64Extension ));
+ Assert.assertFalse(message.hasExtension(optionalUint32Extension ));
+ Assert.assertFalse(message.hasExtension(optionalUint64Extension ));
+ Assert.assertFalse(message.hasExtension(optionalSint32Extension ));
+ Assert.assertFalse(message.hasExtension(optionalSint64Extension ));
+ Assert.assertFalse(message.hasExtension(optionalFixed32Extension ));
+ Assert.assertFalse(message.hasExtension(optionalFixed64Extension ));
+ Assert.assertFalse(message.hasExtension(optionalSfixed32Extension));
+ Assert.assertFalse(message.hasExtension(optionalSfixed64Extension));
+ Assert.assertFalse(message.hasExtension(optionalFloatExtension ));
+ Assert.assertFalse(message.hasExtension(optionalDoubleExtension ));
+ Assert.assertFalse(message.hasExtension(optionalBoolExtension ));
+ Assert.assertFalse(message.hasExtension(optionalStringExtension ));
+ Assert.assertFalse(message.hasExtension(optionalBytesExtension ));
+
+ Assert.assertFalse(message.hasExtension(optionalGroupExtension ));
+ Assert.assertFalse(message.hasExtension(optionalNestedMessageExtension ));
+ Assert.assertFalse(message.hasExtension(optionalForeignMessageExtension));
+ Assert.assertFalse(message.hasExtension(optionalImportMessageExtension ));
+
+ Assert.assertFalse(message.hasExtension(optionalNestedEnumExtension ));
+ Assert.assertFalse(message.hasExtension(optionalForeignEnumExtension));
+ Assert.assertFalse(message.hasExtension(optionalImportEnumExtension ));
+
+ Assert.assertFalse(message.hasExtension(optionalStringPieceExtension));
+ Assert.assertFalse(message.hasExtension(optionalCordExtension));
+
+ // Optional fields without defaults are set to zero or something like it.
+ assertEqualsExactType(0 , message.getExtension(optionalInt32Extension ));
+ assertEqualsExactType(0L , message.getExtension(optionalInt64Extension ));
+ assertEqualsExactType(0 , message.getExtension(optionalUint32Extension ));
+ assertEqualsExactType(0L , message.getExtension(optionalUint64Extension ));
+ assertEqualsExactType(0 , message.getExtension(optionalSint32Extension ));
+ assertEqualsExactType(0L , message.getExtension(optionalSint64Extension ));
+ assertEqualsExactType(0 , message.getExtension(optionalFixed32Extension ));
+ assertEqualsExactType(0L , message.getExtension(optionalFixed64Extension ));
+ assertEqualsExactType(0 , message.getExtension(optionalSfixed32Extension));
+ assertEqualsExactType(0L , message.getExtension(optionalSfixed64Extension));
+ assertEqualsExactType(0F , message.getExtension(optionalFloatExtension ));
+ assertEqualsExactType(0D , message.getExtension(optionalDoubleExtension ));
+ assertEqualsExactType(false, message.getExtension(optionalBoolExtension ));
+ assertEqualsExactType("" , message.getExtension(optionalStringExtension ));
+ assertEqualsExactType(ByteString.EMPTY, message.getExtension(optionalBytesExtension));
+
+ // Embedded messages should also be clear.
+ Assert.assertFalse(message.getExtension(optionalGroupExtension ).hasA());
+ Assert.assertFalse(message.getExtension(optionalNestedMessageExtension ).hasBb());
+ Assert.assertFalse(message.getExtension(optionalForeignMessageExtension).hasC());
+ Assert.assertFalse(message.getExtension(optionalImportMessageExtension ).hasD());
+
+ assertEqualsExactType(0, message.getExtension(optionalGroupExtension ).getA());
+ assertEqualsExactType(0, message.getExtension(optionalNestedMessageExtension ).getBb());
+ assertEqualsExactType(0, message.getExtension(optionalForeignMessageExtension).getC());
+ assertEqualsExactType(0, message.getExtension(optionalImportMessageExtension ).getD());
+
+ // Enums without defaults are set to the first value in the enum.
+ assertEqualsExactType(TestAllTypes.NestedEnum.FOO,
+ message.getExtension(optionalNestedEnumExtension ));
+ assertEqualsExactType(ForeignEnum.FOREIGN_FOO,
+ message.getExtension(optionalForeignEnumExtension));
+ assertEqualsExactType(ImportEnum.IMPORT_FOO,
+ message.getExtension(optionalImportEnumExtension));
+
+ assertEqualsExactType("", message.getExtension(optionalStringPieceExtension));
+ assertEqualsExactType("", message.getExtension(optionalCordExtension));
+
+ // Repeated fields are empty.
+ Assert.assertEquals(0, message.getExtensionCount(repeatedInt32Extension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedInt64Extension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedUint32Extension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedUint64Extension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedSint32Extension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedSint64Extension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedFixed32Extension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedFixed64Extension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedSfixed32Extension));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedSfixed64Extension));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedFloatExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedDoubleExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedBoolExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedStringExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedBytesExtension ));
+
+ Assert.assertEquals(0, message.getExtensionCount(repeatedGroupExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedNestedMessageExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedForeignMessageExtension));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedImportMessageExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedLazyMessageExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedNestedEnumExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedForeignEnumExtension ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedImportEnumExtension ));
+
+ Assert.assertEquals(0, message.getExtensionCount(repeatedStringPieceExtension));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedCordExtension));
+
+ // Repeated fields are empty via getExtension().size().
+ Assert.assertEquals(0, message.getExtension(repeatedInt32Extension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedInt64Extension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedUint32Extension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedUint64Extension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedSint32Extension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedSint64Extension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedFixed32Extension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedFixed64Extension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedSfixed32Extension).size());
+ Assert.assertEquals(0, message.getExtension(repeatedSfixed64Extension).size());
+ Assert.assertEquals(0, message.getExtension(repeatedFloatExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedDoubleExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedBoolExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedStringExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedBytesExtension ).size());
+
+ Assert.assertEquals(0, message.getExtension(repeatedGroupExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedNestedMessageExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedForeignMessageExtension).size());
+ Assert.assertEquals(0, message.getExtension(repeatedImportMessageExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedLazyMessageExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedNestedEnumExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedForeignEnumExtension ).size());
+ Assert.assertEquals(0, message.getExtension(repeatedImportEnumExtension ).size());
+
+ Assert.assertEquals(0, message.getExtension(repeatedStringPieceExtension).size());
+ Assert.assertEquals(0, message.getExtension(repeatedCordExtension).size());
+
+ // hasBlah() should also be false for all default fields.
+ Assert.assertFalse(message.hasExtension(defaultInt32Extension ));
+ Assert.assertFalse(message.hasExtension(defaultInt64Extension ));
+ Assert.assertFalse(message.hasExtension(defaultUint32Extension ));
+ Assert.assertFalse(message.hasExtension(defaultUint64Extension ));
+ Assert.assertFalse(message.hasExtension(defaultSint32Extension ));
+ Assert.assertFalse(message.hasExtension(defaultSint64Extension ));
+ Assert.assertFalse(message.hasExtension(defaultFixed32Extension ));
+ Assert.assertFalse(message.hasExtension(defaultFixed64Extension ));
+ Assert.assertFalse(message.hasExtension(defaultSfixed32Extension));
+ Assert.assertFalse(message.hasExtension(defaultSfixed64Extension));
+ Assert.assertFalse(message.hasExtension(defaultFloatExtension ));
+ Assert.assertFalse(message.hasExtension(defaultDoubleExtension ));
+ Assert.assertFalse(message.hasExtension(defaultBoolExtension ));
+ Assert.assertFalse(message.hasExtension(defaultStringExtension ));
+ Assert.assertFalse(message.hasExtension(defaultBytesExtension ));
+
+ Assert.assertFalse(message.hasExtension(defaultNestedEnumExtension ));
+ Assert.assertFalse(message.hasExtension(defaultForeignEnumExtension));
+ Assert.assertFalse(message.hasExtension(defaultImportEnumExtension ));
+
+ Assert.assertFalse(message.hasExtension(defaultStringPieceExtension));
+ Assert.assertFalse(message.hasExtension(defaultCordExtension));
+
+ // Fields with defaults have their default values (duh).
+ assertEqualsExactType( 41 , message.getExtension(defaultInt32Extension ));
+ assertEqualsExactType( 42L , message.getExtension(defaultInt64Extension ));
+ assertEqualsExactType( 43 , message.getExtension(defaultUint32Extension ));
+ assertEqualsExactType( 44L , message.getExtension(defaultUint64Extension ));
+ assertEqualsExactType(-45 , message.getExtension(defaultSint32Extension ));
+ assertEqualsExactType( 46L , message.getExtension(defaultSint64Extension ));
+ assertEqualsExactType( 47 , message.getExtension(defaultFixed32Extension ));
+ assertEqualsExactType( 48L , message.getExtension(defaultFixed64Extension ));
+ assertEqualsExactType( 49 , message.getExtension(defaultSfixed32Extension));
+ assertEqualsExactType(-50L , message.getExtension(defaultSfixed64Extension));
+ assertEqualsExactType( 51.5F , message.getExtension(defaultFloatExtension ));
+ assertEqualsExactType( 52e3D , message.getExtension(defaultDoubleExtension ));
+ assertEqualsExactType(true , message.getExtension(defaultBoolExtension ));
+ assertEqualsExactType("hello", message.getExtension(defaultStringExtension ));
+ assertEqualsExactType(toBytes("world"), message.getExtension(defaultBytesExtension));
+
+ assertEqualsExactType(TestAllTypes.NestedEnum.BAR,
+ message.getExtension(defaultNestedEnumExtension ));
+ assertEqualsExactType(ForeignEnum.FOREIGN_BAR,
+ message.getExtension(defaultForeignEnumExtension));
+ assertEqualsExactType(ImportEnum.IMPORT_BAR,
+ message.getExtension(defaultImportEnumExtension));
+
+ assertEqualsExactType("abc", message.getExtension(defaultStringPieceExtension));
+ assertEqualsExactType("123", message.getExtension(defaultCordExtension));
+
+ Assert.assertFalse(message.hasExtension(oneofUint32Extension));
+ Assert.assertFalse(message.hasExtension(oneofNestedMessageExtension));
+ Assert.assertFalse(message.hasExtension(oneofStringExtension));
+ Assert.assertFalse(message.hasExtension(oneofBytesExtension));
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all extensions of
+ * {@code message} are set to the values assigned by {@code setAllExtensions}
+ * followed by {@code modifyRepeatedExtensions}.
+ */
+ public static void assertRepeatedExtensionsModified(
+ TestAllExtensionsOrBuilder message) {
+ // ModifyRepeatedFields only sets the second repeated element of each
+ // field. In addition to verifying this, we also verify that the first
+ // element and size were *not* modified.
+ Assert.assertEquals(2, message.getExtensionCount(repeatedInt32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedInt64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedUint32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedUint64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSint32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSint64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFixed32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFixed64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSfixed32Extension));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSfixed64Extension));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFloatExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedDoubleExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedBoolExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedStringExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedBytesExtension ));
+
+ Assert.assertEquals(2, message.getExtensionCount(repeatedGroupExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedNestedMessageExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedForeignMessageExtension));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedImportMessageExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedLazyMessageExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedNestedEnumExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedForeignEnumExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedImportEnumExtension ));
+
+ Assert.assertEquals(2, message.getExtensionCount(repeatedStringPieceExtension));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedCordExtension));
+
+ assertEqualsExactType(201 , message.getExtension(repeatedInt32Extension , 0));
+ assertEqualsExactType(202L , message.getExtension(repeatedInt64Extension , 0));
+ assertEqualsExactType(203 , message.getExtension(repeatedUint32Extension , 0));
+ assertEqualsExactType(204L , message.getExtension(repeatedUint64Extension , 0));
+ assertEqualsExactType(205 , message.getExtension(repeatedSint32Extension , 0));
+ assertEqualsExactType(206L , message.getExtension(repeatedSint64Extension , 0));
+ assertEqualsExactType(207 , message.getExtension(repeatedFixed32Extension , 0));
+ assertEqualsExactType(208L , message.getExtension(repeatedFixed64Extension , 0));
+ assertEqualsExactType(209 , message.getExtension(repeatedSfixed32Extension, 0));
+ assertEqualsExactType(210L , message.getExtension(repeatedSfixed64Extension, 0));
+ assertEqualsExactType(211F , message.getExtension(repeatedFloatExtension , 0));
+ assertEqualsExactType(212D , message.getExtension(repeatedDoubleExtension , 0));
+ assertEqualsExactType(true , message.getExtension(repeatedBoolExtension , 0));
+ assertEqualsExactType("215", message.getExtension(repeatedStringExtension , 0));
+ assertEqualsExactType(toBytes("216"), message.getExtension(repeatedBytesExtension, 0));
+
+ assertEqualsExactType(217, message.getExtension(repeatedGroupExtension , 0).getA());
+ assertEqualsExactType(218, message.getExtension(repeatedNestedMessageExtension , 0).getBb());
+ assertEqualsExactType(219, message.getExtension(repeatedForeignMessageExtension, 0).getC());
+ assertEqualsExactType(220, message.getExtension(repeatedImportMessageExtension , 0).getD());
+ assertEqualsExactType(227, message.getExtension(repeatedLazyMessageExtension , 0).getBb());
+
+ assertEqualsExactType(TestAllTypes.NestedEnum.BAR,
+ message.getExtension(repeatedNestedEnumExtension, 0));
+ assertEqualsExactType(ForeignEnum.FOREIGN_BAR,
+ message.getExtension(repeatedForeignEnumExtension, 0));
+ assertEqualsExactType(ImportEnum.IMPORT_BAR,
+ message.getExtension(repeatedImportEnumExtension, 0));
+
+ assertEqualsExactType("224", message.getExtension(repeatedStringPieceExtension, 0));
+ assertEqualsExactType("225", message.getExtension(repeatedCordExtension, 0));
+
+ // Actually verify the second (modified) elements now.
+ assertEqualsExactType(501 , message.getExtension(repeatedInt32Extension , 1));
+ assertEqualsExactType(502L , message.getExtension(repeatedInt64Extension , 1));
+ assertEqualsExactType(503 , message.getExtension(repeatedUint32Extension , 1));
+ assertEqualsExactType(504L , message.getExtension(repeatedUint64Extension , 1));
+ assertEqualsExactType(505 , message.getExtension(repeatedSint32Extension , 1));
+ assertEqualsExactType(506L , message.getExtension(repeatedSint64Extension , 1));
+ assertEqualsExactType(507 , message.getExtension(repeatedFixed32Extension , 1));
+ assertEqualsExactType(508L , message.getExtension(repeatedFixed64Extension , 1));
+ assertEqualsExactType(509 , message.getExtension(repeatedSfixed32Extension, 1));
+ assertEqualsExactType(510L , message.getExtension(repeatedSfixed64Extension, 1));
+ assertEqualsExactType(511F , message.getExtension(repeatedFloatExtension , 1));
+ assertEqualsExactType(512D , message.getExtension(repeatedDoubleExtension , 1));
+ assertEqualsExactType(true , message.getExtension(repeatedBoolExtension , 1));
+ assertEqualsExactType("515", message.getExtension(repeatedStringExtension , 1));
+ assertEqualsExactType(toBytes("516"), message.getExtension(repeatedBytesExtension, 1));
+
+ assertEqualsExactType(517, message.getExtension(repeatedGroupExtension , 1).getA());
+ assertEqualsExactType(518, message.getExtension(repeatedNestedMessageExtension , 1).getBb());
+ assertEqualsExactType(519, message.getExtension(repeatedForeignMessageExtension, 1).getC());
+ assertEqualsExactType(520, message.getExtension(repeatedImportMessageExtension , 1).getD());
+ assertEqualsExactType(527, message.getExtension(repeatedLazyMessageExtension , 1).getBb());
+
+ assertEqualsExactType(TestAllTypes.NestedEnum.FOO,
+ message.getExtension(repeatedNestedEnumExtension, 1));
+ assertEqualsExactType(ForeignEnum.FOREIGN_FOO,
+ message.getExtension(repeatedForeignEnumExtension, 1));
+ assertEqualsExactType(ImportEnum.IMPORT_FOO,
+ message.getExtension(repeatedImportEnumExtension, 1));
+
+ assertEqualsExactType("524", message.getExtension(repeatedStringPieceExtension, 1));
+ assertEqualsExactType("525", message.getExtension(repeatedCordExtension, 1));
+ }
+
+ public static void setPackedExtensions(TestPackedExtensions.Builder message) {
+ message.addExtension(packedInt32Extension , 601);
+ message.addExtension(packedInt64Extension , 602L);
+ message.addExtension(packedUint32Extension , 603);
+ message.addExtension(packedUint64Extension , 604L);
+ message.addExtension(packedSint32Extension , 605);
+ message.addExtension(packedSint64Extension , 606L);
+ message.addExtension(packedFixed32Extension , 607);
+ message.addExtension(packedFixed64Extension , 608L);
+ message.addExtension(packedSfixed32Extension, 609);
+ message.addExtension(packedSfixed64Extension, 610L);
+ message.addExtension(packedFloatExtension , 611F);
+ message.addExtension(packedDoubleExtension , 612D);
+ message.addExtension(packedBoolExtension , true);
+ message.addExtension(packedEnumExtension, ForeignEnum.FOREIGN_BAR);
+ // Add a second one of each field.
+ message.addExtension(packedInt32Extension , 701);
+ message.addExtension(packedInt64Extension , 702L);
+ message.addExtension(packedUint32Extension , 703);
+ message.addExtension(packedUint64Extension , 704L);
+ message.addExtension(packedSint32Extension , 705);
+ message.addExtension(packedSint64Extension , 706L);
+ message.addExtension(packedFixed32Extension , 707);
+ message.addExtension(packedFixed64Extension , 708L);
+ message.addExtension(packedSfixed32Extension, 709);
+ message.addExtension(packedSfixed64Extension, 710L);
+ message.addExtension(packedFloatExtension , 711F);
+ message.addExtension(packedDoubleExtension , 712D);
+ message.addExtension(packedBoolExtension , false);
+ message.addExtension(packedEnumExtension, ForeignEnum.FOREIGN_BAZ);
+ }
+
+ public static void assertPackedExtensionsSet(TestPackedExtensions message) {
+ Assert.assertEquals(2, message.getExtensionCount(packedInt32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedInt64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedUint32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedUint64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedSint32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedSint64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedFixed32Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedFixed64Extension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedSfixed32Extension));
+ Assert.assertEquals(2, message.getExtensionCount(packedSfixed64Extension));
+ Assert.assertEquals(2, message.getExtensionCount(packedFloatExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedDoubleExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedBoolExtension ));
+ Assert.assertEquals(2, message.getExtensionCount(packedEnumExtension));
+ assertEqualsExactType(601 , message.getExtension(packedInt32Extension , 0));
+ assertEqualsExactType(602L , message.getExtension(packedInt64Extension , 0));
+ assertEqualsExactType(603 , message.getExtension(packedUint32Extension , 0));
+ assertEqualsExactType(604L , message.getExtension(packedUint64Extension , 0));
+ assertEqualsExactType(605 , message.getExtension(packedSint32Extension , 0));
+ assertEqualsExactType(606L , message.getExtension(packedSint64Extension , 0));
+ assertEqualsExactType(607 , message.getExtension(packedFixed32Extension , 0));
+ assertEqualsExactType(608L , message.getExtension(packedFixed64Extension , 0));
+ assertEqualsExactType(609 , message.getExtension(packedSfixed32Extension, 0));
+ assertEqualsExactType(610L , message.getExtension(packedSfixed64Extension, 0));
+ assertEqualsExactType(611F , message.getExtension(packedFloatExtension , 0));
+ assertEqualsExactType(612D , message.getExtension(packedDoubleExtension , 0));
+ assertEqualsExactType(true , message.getExtension(packedBoolExtension , 0));
+ assertEqualsExactType(ForeignEnum.FOREIGN_BAR,
+ message.getExtension(packedEnumExtension, 0));
+ assertEqualsExactType(701 , message.getExtension(packedInt32Extension , 1));
+ assertEqualsExactType(702L , message.getExtension(packedInt64Extension , 1));
+ assertEqualsExactType(703 , message.getExtension(packedUint32Extension , 1));
+ assertEqualsExactType(704L , message.getExtension(packedUint64Extension , 1));
+ assertEqualsExactType(705 , message.getExtension(packedSint32Extension , 1));
+ assertEqualsExactType(706L , message.getExtension(packedSint64Extension , 1));
+ assertEqualsExactType(707 , message.getExtension(packedFixed32Extension , 1));
+ assertEqualsExactType(708L , message.getExtension(packedFixed64Extension , 1));
+ assertEqualsExactType(709 , message.getExtension(packedSfixed32Extension, 1));
+ assertEqualsExactType(710L , message.getExtension(packedSfixed64Extension, 1));
+ assertEqualsExactType(711F , message.getExtension(packedFloatExtension , 1));
+ assertEqualsExactType(712D , message.getExtension(packedDoubleExtension , 1));
+ assertEqualsExactType(false, message.getExtension(packedBoolExtension , 1));
+ assertEqualsExactType(ForeignEnum.FOREIGN_BAZ,
+ message.getExtension(packedEnumExtension, 1));
+ }
+
+ // ===================================================================
+ // Lite extensions
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all extensions of
+ * {@code message} are set to the values assigned by {@code setAllExtensions}.
+ */
+ public static void assertAllExtensionsSet(
+ TestAllExtensionsLiteOrBuilder message) {
+ Assert.assertTrue(message.hasExtension(optionalInt32ExtensionLite ));
+ Assert.assertTrue(message.hasExtension(optionalInt64ExtensionLite ));
+ Assert.assertTrue(message.hasExtension(optionalUint32ExtensionLite ));
+ Assert.assertTrue(message.hasExtension(optionalUint64ExtensionLite ));
+ Assert.assertTrue(message.hasExtension(optionalSint32ExtensionLite ));
+ Assert.assertTrue(message.hasExtension(optionalSint64ExtensionLite ));
+ Assert.assertTrue(message.hasExtension(optionalFixed32ExtensionLite ));
+ Assert.assertTrue(message.hasExtension(optionalFixed64ExtensionLite ));
+ Assert.assertTrue(message.hasExtension(optionalSfixed32ExtensionLite));
+ Assert.assertTrue(message.hasExtension(optionalSfixed64ExtensionLite));
+ Assert.assertTrue(message.hasExtension(optionalFloatExtensionLite ));
+ Assert.assertTrue(message.hasExtension(optionalDoubleExtensionLite ));
+ Assert.assertTrue(message.hasExtension(optionalBoolExtensionLite ));
+ Assert.assertTrue(message.hasExtension(optionalStringExtensionLite ));
+ Assert.assertTrue(message.hasExtension(optionalBytesExtensionLite ));
+
+ Assert.assertTrue(message.hasExtension(optionalGroupExtensionLite ));
+ Assert.assertTrue(message.hasExtension(optionalNestedMessageExtensionLite ));
+ Assert.assertTrue(message.hasExtension(optionalForeignMessageExtensionLite));
+ Assert.assertTrue(message.hasExtension(optionalImportMessageExtensionLite ));
+
+ Assert.assertTrue(message.getExtension(optionalGroupExtensionLite ).hasA());
+ Assert.assertTrue(message.getExtension(optionalNestedMessageExtensionLite ).hasBb());
+ Assert.assertTrue(message.getExtension(optionalForeignMessageExtensionLite).hasC());
+ Assert.assertTrue(message.getExtension(optionalImportMessageExtensionLite ).hasD());
+
+ Assert.assertTrue(message.hasExtension(optionalNestedEnumExtensionLite ));
+ Assert.assertTrue(message.hasExtension(optionalForeignEnumExtensionLite));
+ Assert.assertTrue(message.hasExtension(optionalImportEnumExtensionLite ));
+
+ Assert.assertTrue(message.hasExtension(optionalStringPieceExtensionLite));
+ Assert.assertTrue(message.hasExtension(optionalCordExtensionLite));
+
+ assertEqualsExactType(101 , message.getExtension(optionalInt32ExtensionLite ));
+ assertEqualsExactType(102L , message.getExtension(optionalInt64ExtensionLite ));
+ assertEqualsExactType(103 , message.getExtension(optionalUint32ExtensionLite ));
+ assertEqualsExactType(104L , message.getExtension(optionalUint64ExtensionLite ));
+ assertEqualsExactType(105 , message.getExtension(optionalSint32ExtensionLite ));
+ assertEqualsExactType(106L , message.getExtension(optionalSint64ExtensionLite ));
+ assertEqualsExactType(107 , message.getExtension(optionalFixed32ExtensionLite ));
+ assertEqualsExactType(108L , message.getExtension(optionalFixed64ExtensionLite ));
+ assertEqualsExactType(109 , message.getExtension(optionalSfixed32ExtensionLite));
+ assertEqualsExactType(110L , message.getExtension(optionalSfixed64ExtensionLite));
+ assertEqualsExactType(111F , message.getExtension(optionalFloatExtensionLite ));
+ assertEqualsExactType(112D , message.getExtension(optionalDoubleExtensionLite ));
+ assertEqualsExactType(true , message.getExtension(optionalBoolExtensionLite ));
+ assertEqualsExactType("115", message.getExtension(optionalStringExtensionLite ));
+ assertEqualsExactType(toBytes("116"), message.getExtension(optionalBytesExtensionLite));
+
+ assertEqualsExactType(117, message.getExtension(optionalGroupExtensionLite ).getA());
+ assertEqualsExactType(118, message.getExtension(optionalNestedMessageExtensionLite ).getBb());
+ assertEqualsExactType(119, message.getExtension(optionalForeignMessageExtensionLite).getC());
+ assertEqualsExactType(120, message.getExtension(optionalImportMessageExtensionLite ).getD());
+ assertEqualsExactType(126, message.getExtension(
+ optionalPublicImportMessageExtensionLite).getE());
+ assertEqualsExactType(127, message.getExtension(optionalLazyMessageExtensionLite).getBb());
+
+ assertEqualsExactType(TestAllTypesLite.NestedEnum.BAZ,
+ message.getExtension(optionalNestedEnumExtensionLite));
+ assertEqualsExactType(ForeignEnumLite.FOREIGN_LITE_BAZ,
+ message.getExtension(optionalForeignEnumExtensionLite));
+ assertEqualsExactType(ImportEnumLite.IMPORT_LITE_BAZ,
+ message.getExtension(optionalImportEnumExtensionLite));
+
+ assertEqualsExactType("124", message.getExtension(optionalStringPieceExtensionLite));
+ assertEqualsExactType("125", message.getExtension(optionalCordExtensionLite));
+
+ // -----------------------------------------------------------------
+
+ Assert.assertEquals(2, message.getExtensionCount(repeatedInt32ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedInt64ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedUint32ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedUint64ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSint32ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSint64ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFixed32ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFixed64ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSfixed32ExtensionLite));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSfixed64ExtensionLite));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFloatExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedDoubleExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedBoolExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedStringExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedBytesExtensionLite ));
+
+ Assert.assertEquals(2, message.getExtensionCount(repeatedGroupExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedNestedMessageExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedForeignMessageExtensionLite));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedImportMessageExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedLazyMessageExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedNestedEnumExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedForeignEnumExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedImportEnumExtensionLite ));
+
+ Assert.assertEquals(2, message.getExtensionCount(repeatedStringPieceExtensionLite));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedCordExtensionLite));
+
+ assertEqualsExactType(201 , message.getExtension(repeatedInt32ExtensionLite , 0));
+ assertEqualsExactType(202L , message.getExtension(repeatedInt64ExtensionLite , 0));
+ assertEqualsExactType(203 , message.getExtension(repeatedUint32ExtensionLite , 0));
+ assertEqualsExactType(204L , message.getExtension(repeatedUint64ExtensionLite , 0));
+ assertEqualsExactType(205 , message.getExtension(repeatedSint32ExtensionLite , 0));
+ assertEqualsExactType(206L , message.getExtension(repeatedSint64ExtensionLite , 0));
+ assertEqualsExactType(207 , message.getExtension(repeatedFixed32ExtensionLite , 0));
+ assertEqualsExactType(208L , message.getExtension(repeatedFixed64ExtensionLite , 0));
+ assertEqualsExactType(209 , message.getExtension(repeatedSfixed32ExtensionLite, 0));
+ assertEqualsExactType(210L , message.getExtension(repeatedSfixed64ExtensionLite, 0));
+ assertEqualsExactType(211F , message.getExtension(repeatedFloatExtensionLite , 0));
+ assertEqualsExactType(212D , message.getExtension(repeatedDoubleExtensionLite , 0));
+ assertEqualsExactType(true , message.getExtension(repeatedBoolExtensionLite , 0));
+ assertEqualsExactType("215", message.getExtension(repeatedStringExtensionLite , 0));
+ assertEqualsExactType(toBytes("216"), message.getExtension(repeatedBytesExtensionLite, 0));
+
+ assertEqualsExactType(217, message.getExtension(repeatedGroupExtensionLite ,0).getA());
+ assertEqualsExactType(218, message.getExtension(repeatedNestedMessageExtensionLite ,0).getBb());
+ assertEqualsExactType(219, message.getExtension(repeatedForeignMessageExtensionLite,0).getC());
+ assertEqualsExactType(220, message.getExtension(repeatedImportMessageExtensionLite ,0).getD());
+ assertEqualsExactType(227, message.getExtension(repeatedLazyMessageExtensionLite ,0).getBb());
+
+ assertEqualsExactType(TestAllTypesLite.NestedEnum.BAR,
+ message.getExtension(repeatedNestedEnumExtensionLite, 0));
+ assertEqualsExactType(ForeignEnumLite.FOREIGN_LITE_BAR,
+ message.getExtension(repeatedForeignEnumExtensionLite, 0));
+ assertEqualsExactType(ImportEnumLite.IMPORT_LITE_BAR,
+ message.getExtension(repeatedImportEnumExtensionLite, 0));
+
+ assertEqualsExactType("224", message.getExtension(repeatedStringPieceExtensionLite, 0));
+ assertEqualsExactType("225", message.getExtension(repeatedCordExtensionLite, 0));
+
+ assertEqualsExactType(301 , message.getExtension(repeatedInt32ExtensionLite , 1));
+ assertEqualsExactType(302L , message.getExtension(repeatedInt64ExtensionLite , 1));
+ assertEqualsExactType(303 , message.getExtension(repeatedUint32ExtensionLite , 1));
+ assertEqualsExactType(304L , message.getExtension(repeatedUint64ExtensionLite , 1));
+ assertEqualsExactType(305 , message.getExtension(repeatedSint32ExtensionLite , 1));
+ assertEqualsExactType(306L , message.getExtension(repeatedSint64ExtensionLite , 1));
+ assertEqualsExactType(307 , message.getExtension(repeatedFixed32ExtensionLite , 1));
+ assertEqualsExactType(308L , message.getExtension(repeatedFixed64ExtensionLite , 1));
+ assertEqualsExactType(309 , message.getExtension(repeatedSfixed32ExtensionLite, 1));
+ assertEqualsExactType(310L , message.getExtension(repeatedSfixed64ExtensionLite, 1));
+ assertEqualsExactType(311F , message.getExtension(repeatedFloatExtensionLite , 1));
+ assertEqualsExactType(312D , message.getExtension(repeatedDoubleExtensionLite , 1));
+ assertEqualsExactType(false, message.getExtension(repeatedBoolExtensionLite , 1));
+ assertEqualsExactType("315", message.getExtension(repeatedStringExtensionLite , 1));
+ assertEqualsExactType(toBytes("316"), message.getExtension(repeatedBytesExtensionLite, 1));
+
+ assertEqualsExactType(317, message.getExtension(repeatedGroupExtensionLite ,1).getA());
+ assertEqualsExactType(318, message.getExtension(repeatedNestedMessageExtensionLite ,1).getBb());
+ assertEqualsExactType(319, message.getExtension(repeatedForeignMessageExtensionLite,1).getC());
+ assertEqualsExactType(320, message.getExtension(repeatedImportMessageExtensionLite ,1).getD());
+ assertEqualsExactType(327, message.getExtension(repeatedLazyMessageExtensionLite ,1).getBb());
+
+ assertEqualsExactType(TestAllTypesLite.NestedEnum.BAZ,
+ message.getExtension(repeatedNestedEnumExtensionLite, 1));
+ assertEqualsExactType(ForeignEnumLite.FOREIGN_LITE_BAZ,
+ message.getExtension(repeatedForeignEnumExtensionLite, 1));
+ assertEqualsExactType(ImportEnumLite.IMPORT_LITE_BAZ,
+ message.getExtension(repeatedImportEnumExtensionLite, 1));
+
+ assertEqualsExactType("324", message.getExtension(repeatedStringPieceExtensionLite, 1));
+ assertEqualsExactType("325", message.getExtension(repeatedCordExtensionLite, 1));
+
+ // -----------------------------------------------------------------
+
+ Assert.assertTrue(message.hasExtension(defaultInt32ExtensionLite ));
+ Assert.assertTrue(message.hasExtension(defaultInt64ExtensionLite ));
+ Assert.assertTrue(message.hasExtension(defaultUint32ExtensionLite ));
+ Assert.assertTrue(message.hasExtension(defaultUint64ExtensionLite ));
+ Assert.assertTrue(message.hasExtension(defaultSint32ExtensionLite ));
+ Assert.assertTrue(message.hasExtension(defaultSint64ExtensionLite ));
+ Assert.assertTrue(message.hasExtension(defaultFixed32ExtensionLite ));
+ Assert.assertTrue(message.hasExtension(defaultFixed64ExtensionLite ));
+ Assert.assertTrue(message.hasExtension(defaultSfixed32ExtensionLite));
+ Assert.assertTrue(message.hasExtension(defaultSfixed64ExtensionLite));
+ Assert.assertTrue(message.hasExtension(defaultFloatExtensionLite ));
+ Assert.assertTrue(message.hasExtension(defaultDoubleExtensionLite ));
+ Assert.assertTrue(message.hasExtension(defaultBoolExtensionLite ));
+ Assert.assertTrue(message.hasExtension(defaultStringExtensionLite ));
+ Assert.assertTrue(message.hasExtension(defaultBytesExtensionLite ));
+
+ Assert.assertTrue(message.hasExtension(defaultNestedEnumExtensionLite ));
+ Assert.assertTrue(message.hasExtension(defaultForeignEnumExtensionLite));
+ Assert.assertTrue(message.hasExtension(defaultImportEnumExtensionLite ));
+
+ Assert.assertTrue(message.hasExtension(defaultStringPieceExtensionLite));
+ Assert.assertTrue(message.hasExtension(defaultCordExtensionLite));
+
+ assertEqualsExactType(401 , message.getExtension(defaultInt32ExtensionLite ));
+ assertEqualsExactType(402L , message.getExtension(defaultInt64ExtensionLite ));
+ assertEqualsExactType(403 , message.getExtension(defaultUint32ExtensionLite ));
+ assertEqualsExactType(404L , message.getExtension(defaultUint64ExtensionLite ));
+ assertEqualsExactType(405 , message.getExtension(defaultSint32ExtensionLite ));
+ assertEqualsExactType(406L , message.getExtension(defaultSint64ExtensionLite ));
+ assertEqualsExactType(407 , message.getExtension(defaultFixed32ExtensionLite ));
+ assertEqualsExactType(408L , message.getExtension(defaultFixed64ExtensionLite ));
+ assertEqualsExactType(409 , message.getExtension(defaultSfixed32ExtensionLite));
+ assertEqualsExactType(410L , message.getExtension(defaultSfixed64ExtensionLite));
+ assertEqualsExactType(411F , message.getExtension(defaultFloatExtensionLite ));
+ assertEqualsExactType(412D , message.getExtension(defaultDoubleExtensionLite ));
+ assertEqualsExactType(false, message.getExtension(defaultBoolExtensionLite ));
+ assertEqualsExactType("415", message.getExtension(defaultStringExtensionLite ));
+ assertEqualsExactType(toBytes("416"), message.getExtension(defaultBytesExtensionLite));
+
+ assertEqualsExactType(TestAllTypesLite.NestedEnum.FOO,
+ message.getExtension(defaultNestedEnumExtensionLite ));
+ assertEqualsExactType(ForeignEnumLite.FOREIGN_LITE_FOO,
+ message.getExtension(defaultForeignEnumExtensionLite));
+ assertEqualsExactType(ImportEnumLite.IMPORT_LITE_FOO,
+ message.getExtension(defaultImportEnumExtensionLite));
+
+ assertEqualsExactType("424", message.getExtension(defaultStringPieceExtensionLite));
+ assertEqualsExactType("425", message.getExtension(defaultCordExtensionLite));
+
+ Assert.assertTrue(message.hasExtension(oneofBytesExtensionLite));
+
+ assertEqualsExactType(toBytes("604"), message.getExtension(oneofBytesExtensionLite));
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all extensions of
+ * {@code message} are cleared, and that getting the extensions returns their
+ * default values.
+ */
+ public static void assertExtensionsClear(
+ TestAllExtensionsLiteOrBuilder message) {
+ // hasBlah() should initially be false for all optional fields.
+ Assert.assertFalse(message.hasExtension(optionalInt32ExtensionLite ));
+ Assert.assertFalse(message.hasExtension(optionalInt64ExtensionLite ));
+ Assert.assertFalse(message.hasExtension(optionalUint32ExtensionLite ));
+ Assert.assertFalse(message.hasExtension(optionalUint64ExtensionLite ));
+ Assert.assertFalse(message.hasExtension(optionalSint32ExtensionLite ));
+ Assert.assertFalse(message.hasExtension(optionalSint64ExtensionLite ));
+ Assert.assertFalse(message.hasExtension(optionalFixed32ExtensionLite ));
+ Assert.assertFalse(message.hasExtension(optionalFixed64ExtensionLite ));
+ Assert.assertFalse(message.hasExtension(optionalSfixed32ExtensionLite));
+ Assert.assertFalse(message.hasExtension(optionalSfixed64ExtensionLite));
+ Assert.assertFalse(message.hasExtension(optionalFloatExtensionLite ));
+ Assert.assertFalse(message.hasExtension(optionalDoubleExtensionLite ));
+ Assert.assertFalse(message.hasExtension(optionalBoolExtensionLite ));
+ Assert.assertFalse(message.hasExtension(optionalStringExtensionLite ));
+ Assert.assertFalse(message.hasExtension(optionalBytesExtensionLite ));
+
+ Assert.assertFalse(message.hasExtension(optionalGroupExtensionLite ));
+ Assert.assertFalse(message.hasExtension(optionalNestedMessageExtensionLite ));
+ Assert.assertFalse(message.hasExtension(optionalForeignMessageExtensionLite ));
+ Assert.assertFalse(message.hasExtension(optionalImportMessageExtensionLite ));
+ Assert.assertFalse(message.hasExtension(optionalPublicImportMessageExtensionLite));
+ Assert.assertFalse(message.hasExtension(optionalLazyMessageExtensionLite ));
+
+ Assert.assertFalse(message.hasExtension(optionalNestedEnumExtensionLite ));
+ Assert.assertFalse(message.hasExtension(optionalForeignEnumExtensionLite));
+ Assert.assertFalse(message.hasExtension(optionalImportEnumExtensionLite ));
+
+ Assert.assertFalse(message.hasExtension(optionalStringPieceExtensionLite));
+ Assert.assertFalse(message.hasExtension(optionalCordExtensionLite));
+
+ // Optional fields without defaults are set to zero or something like it.
+ assertEqualsExactType(0 , message.getExtension(optionalInt32ExtensionLite ));
+ assertEqualsExactType(0L , message.getExtension(optionalInt64ExtensionLite ));
+ assertEqualsExactType(0 , message.getExtension(optionalUint32ExtensionLite ));
+ assertEqualsExactType(0L , message.getExtension(optionalUint64ExtensionLite ));
+ assertEqualsExactType(0 , message.getExtension(optionalSint32ExtensionLite ));
+ assertEqualsExactType(0L , message.getExtension(optionalSint64ExtensionLite ));
+ assertEqualsExactType(0 , message.getExtension(optionalFixed32ExtensionLite ));
+ assertEqualsExactType(0L , message.getExtension(optionalFixed64ExtensionLite ));
+ assertEqualsExactType(0 , message.getExtension(optionalSfixed32ExtensionLite));
+ assertEqualsExactType(0L , message.getExtension(optionalSfixed64ExtensionLite));
+ assertEqualsExactType(0F , message.getExtension(optionalFloatExtensionLite ));
+ assertEqualsExactType(0D , message.getExtension(optionalDoubleExtensionLite ));
+ assertEqualsExactType(false, message.getExtension(optionalBoolExtensionLite ));
+ assertEqualsExactType("" , message.getExtension(optionalStringExtensionLite ));
+ assertEqualsExactType(ByteString.EMPTY, message.getExtension(optionalBytesExtensionLite));
+
+ // Embedded messages should also be clear.
+ Assert.assertFalse(message.getExtension(optionalGroupExtensionLite ).hasA());
+ Assert.assertFalse(message.getExtension(optionalNestedMessageExtensionLite ).hasBb());
+ Assert.assertFalse(message.getExtension(optionalForeignMessageExtensionLite ).hasC());
+ Assert.assertFalse(message.getExtension(optionalImportMessageExtensionLite ).hasD());
+ Assert.assertFalse(message.getExtension(optionalPublicImportMessageExtensionLite).hasE());
+ Assert.assertFalse(message.getExtension(optionalLazyMessageExtensionLite ).hasBb());
+
+ assertEqualsExactType(0, message.getExtension(optionalGroupExtensionLite ).getA());
+ assertEqualsExactType(0, message.getExtension(optionalNestedMessageExtensionLite ).getBb());
+ assertEqualsExactType(0, message.getExtension(optionalForeignMessageExtensionLite).getC());
+ assertEqualsExactType(0, message.getExtension(optionalImportMessageExtensionLite ).getD());
+ assertEqualsExactType(0, message.getExtension(
+ optionalPublicImportMessageExtensionLite).getE());
+ assertEqualsExactType(0, message.getExtension(optionalLazyMessageExtensionLite ).getBb());
+
+ // Enums without defaults are set to the first value in the enum.
+ assertEqualsExactType(TestAllTypesLite.NestedEnum.FOO,
+ message.getExtension(optionalNestedEnumExtensionLite ));
+ assertEqualsExactType(ForeignEnumLite.FOREIGN_LITE_FOO,
+ message.getExtension(optionalForeignEnumExtensionLite));
+ assertEqualsExactType(ImportEnumLite.IMPORT_LITE_FOO,
+ message.getExtension(optionalImportEnumExtensionLite));
+
+ assertEqualsExactType("", message.getExtension(optionalStringPieceExtensionLite));
+ assertEqualsExactType("", message.getExtension(optionalCordExtensionLite));
+
+ // Repeated fields are empty.
+ Assert.assertEquals(0, message.getExtensionCount(repeatedInt32ExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedInt64ExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedUint32ExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedUint64ExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedSint32ExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedSint64ExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedFixed32ExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedFixed64ExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedSfixed32ExtensionLite));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedSfixed64ExtensionLite));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedFloatExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedDoubleExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedBoolExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedStringExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedBytesExtensionLite ));
+
+ Assert.assertEquals(0, message.getExtensionCount(repeatedGroupExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedNestedMessageExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedForeignMessageExtensionLite));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedImportMessageExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedLazyMessageExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedNestedEnumExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedForeignEnumExtensionLite ));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedImportEnumExtensionLite ));
+
+ Assert.assertEquals(0, message.getExtensionCount(repeatedStringPieceExtensionLite));
+ Assert.assertEquals(0, message.getExtensionCount(repeatedCordExtensionLite));
+
+ // hasBlah() should also be false for all default fields.
+ Assert.assertFalse(message.hasExtension(defaultInt32ExtensionLite ));
+ Assert.assertFalse(message.hasExtension(defaultInt64ExtensionLite ));
+ Assert.assertFalse(message.hasExtension(defaultUint32ExtensionLite ));
+ Assert.assertFalse(message.hasExtension(defaultUint64ExtensionLite ));
+ Assert.assertFalse(message.hasExtension(defaultSint32ExtensionLite ));
+ Assert.assertFalse(message.hasExtension(defaultSint64ExtensionLite ));
+ Assert.assertFalse(message.hasExtension(defaultFixed32ExtensionLite ));
+ Assert.assertFalse(message.hasExtension(defaultFixed64ExtensionLite ));
+ Assert.assertFalse(message.hasExtension(defaultSfixed32ExtensionLite));
+ Assert.assertFalse(message.hasExtension(defaultSfixed64ExtensionLite));
+ Assert.assertFalse(message.hasExtension(defaultFloatExtensionLite ));
+ Assert.assertFalse(message.hasExtension(defaultDoubleExtensionLite ));
+ Assert.assertFalse(message.hasExtension(defaultBoolExtensionLite ));
+ Assert.assertFalse(message.hasExtension(defaultStringExtensionLite ));
+ Assert.assertFalse(message.hasExtension(defaultBytesExtensionLite ));
+
+ Assert.assertFalse(message.hasExtension(defaultNestedEnumExtensionLite ));
+ Assert.assertFalse(message.hasExtension(defaultForeignEnumExtensionLite));
+ Assert.assertFalse(message.hasExtension(defaultImportEnumExtensionLite ));
+
+ Assert.assertFalse(message.hasExtension(defaultStringPieceExtensionLite));
+ Assert.assertFalse(message.hasExtension(defaultCordExtensionLite));
+
+ // Fields with defaults have their default values (duh).
+ assertEqualsExactType( 41 , message.getExtension(defaultInt32ExtensionLite ));
+ assertEqualsExactType( 42L , message.getExtension(defaultInt64ExtensionLite ));
+ assertEqualsExactType( 43 , message.getExtension(defaultUint32ExtensionLite ));
+ assertEqualsExactType( 44L , message.getExtension(defaultUint64ExtensionLite ));
+ assertEqualsExactType(-45 , message.getExtension(defaultSint32ExtensionLite ));
+ assertEqualsExactType( 46L , message.getExtension(defaultSint64ExtensionLite ));
+ assertEqualsExactType( 47 , message.getExtension(defaultFixed32ExtensionLite ));
+ assertEqualsExactType( 48L , message.getExtension(defaultFixed64ExtensionLite ));
+ assertEqualsExactType( 49 , message.getExtension(defaultSfixed32ExtensionLite));
+ assertEqualsExactType(-50L , message.getExtension(defaultSfixed64ExtensionLite));
+ assertEqualsExactType( 51.5F , message.getExtension(defaultFloatExtensionLite ));
+ assertEqualsExactType( 52e3D , message.getExtension(defaultDoubleExtensionLite ));
+ assertEqualsExactType(true , message.getExtension(defaultBoolExtensionLite ));
+ assertEqualsExactType("hello", message.getExtension(defaultStringExtensionLite ));
+ assertEqualsExactType(toBytes("world"), message.getExtension(defaultBytesExtensionLite));
+
+ assertEqualsExactType(TestAllTypesLite.NestedEnum.BAR,
+ message.getExtension(defaultNestedEnumExtensionLite ));
+ assertEqualsExactType(ForeignEnumLite.FOREIGN_LITE_BAR,
+ message.getExtension(defaultForeignEnumExtensionLite));
+ assertEqualsExactType(ImportEnumLite.IMPORT_LITE_BAR,
+ message.getExtension(defaultImportEnumExtensionLite));
+
+ assertEqualsExactType("abc", message.getExtension(defaultStringPieceExtensionLite));
+ assertEqualsExactType("123", message.getExtension(defaultCordExtensionLite));
+
+ Assert.assertFalse(message.hasExtension(oneofUint32ExtensionLite));
+ Assert.assertFalse(message.hasExtension(oneofNestedMessageExtensionLite));
+ Assert.assertFalse(message.hasExtension(oneofStringExtensionLite));
+ Assert.assertFalse(message.hasExtension(oneofBytesExtensionLite));
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all extensions of
+ * {@code message} are set to the values assigned by {@code setAllExtensions}
+ * followed by {@code modifyRepeatedExtensions}.
+ */
+ public static void assertRepeatedExtensionsModified(
+ TestAllExtensionsLiteOrBuilder message) {
+ // ModifyRepeatedFields only sets the second repeated element of each
+ // field. In addition to verifying this, we also verify that the first
+ // element and size were *not* modified.
+ Assert.assertEquals(2, message.getExtensionCount(repeatedInt32ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedInt64ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedUint32ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedUint64ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSint32ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSint64ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFixed32ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFixed64ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSfixed32ExtensionLite));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedSfixed64ExtensionLite));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedFloatExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedDoubleExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedBoolExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedStringExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedBytesExtensionLite ));
+
+ Assert.assertEquals(2, message.getExtensionCount(repeatedGroupExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedNestedMessageExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedForeignMessageExtensionLite));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedImportMessageExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedLazyMessageExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedNestedEnumExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedForeignEnumExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedImportEnumExtensionLite ));
+
+ Assert.assertEquals(2, message.getExtensionCount(repeatedStringPieceExtensionLite));
+ Assert.assertEquals(2, message.getExtensionCount(repeatedCordExtensionLite));
+
+ assertEqualsExactType(201 , message.getExtension(repeatedInt32ExtensionLite , 0));
+ assertEqualsExactType(202L , message.getExtension(repeatedInt64ExtensionLite , 0));
+ assertEqualsExactType(203 , message.getExtension(repeatedUint32ExtensionLite , 0));
+ assertEqualsExactType(204L , message.getExtension(repeatedUint64ExtensionLite , 0));
+ assertEqualsExactType(205 , message.getExtension(repeatedSint32ExtensionLite , 0));
+ assertEqualsExactType(206L , message.getExtension(repeatedSint64ExtensionLite , 0));
+ assertEqualsExactType(207 , message.getExtension(repeatedFixed32ExtensionLite , 0));
+ assertEqualsExactType(208L , message.getExtension(repeatedFixed64ExtensionLite , 0));
+ assertEqualsExactType(209 , message.getExtension(repeatedSfixed32ExtensionLite, 0));
+ assertEqualsExactType(210L , message.getExtension(repeatedSfixed64ExtensionLite, 0));
+ assertEqualsExactType(211F , message.getExtension(repeatedFloatExtensionLite , 0));
+ assertEqualsExactType(212D , message.getExtension(repeatedDoubleExtensionLite , 0));
+ assertEqualsExactType(true , message.getExtension(repeatedBoolExtensionLite , 0));
+ assertEqualsExactType("215", message.getExtension(repeatedStringExtensionLite , 0));
+ assertEqualsExactType(toBytes("216"), message.getExtension(repeatedBytesExtensionLite, 0));
+
+ assertEqualsExactType(217, message.getExtension(repeatedGroupExtensionLite ,0).getA());
+ assertEqualsExactType(218, message.getExtension(repeatedNestedMessageExtensionLite ,0).getBb());
+ assertEqualsExactType(219, message.getExtension(repeatedForeignMessageExtensionLite,0).getC());
+ assertEqualsExactType(220, message.getExtension(repeatedImportMessageExtensionLite ,0).getD());
+ assertEqualsExactType(227, message.getExtension(repeatedLazyMessageExtensionLite ,0).getBb());
+
+ assertEqualsExactType(TestAllTypesLite.NestedEnum.BAR,
+ message.getExtension(repeatedNestedEnumExtensionLite, 0));
+ assertEqualsExactType(ForeignEnumLite.FOREIGN_LITE_BAR,
+ message.getExtension(repeatedForeignEnumExtensionLite, 0));
+ assertEqualsExactType(ImportEnumLite.IMPORT_LITE_BAR,
+ message.getExtension(repeatedImportEnumExtensionLite, 0));
+
+ assertEqualsExactType("224", message.getExtension(repeatedStringPieceExtensionLite, 0));
+ assertEqualsExactType("225", message.getExtension(repeatedCordExtensionLite, 0));
+
+ // Actually verify the second (modified) elements now.
+ assertEqualsExactType(501 , message.getExtension(repeatedInt32ExtensionLite , 1));
+ assertEqualsExactType(502L , message.getExtension(repeatedInt64ExtensionLite , 1));
+ assertEqualsExactType(503 , message.getExtension(repeatedUint32ExtensionLite , 1));
+ assertEqualsExactType(504L , message.getExtension(repeatedUint64ExtensionLite , 1));
+ assertEqualsExactType(505 , message.getExtension(repeatedSint32ExtensionLite , 1));
+ assertEqualsExactType(506L , message.getExtension(repeatedSint64ExtensionLite , 1));
+ assertEqualsExactType(507 , message.getExtension(repeatedFixed32ExtensionLite , 1));
+ assertEqualsExactType(508L , message.getExtension(repeatedFixed64ExtensionLite , 1));
+ assertEqualsExactType(509 , message.getExtension(repeatedSfixed32ExtensionLite, 1));
+ assertEqualsExactType(510L , message.getExtension(repeatedSfixed64ExtensionLite, 1));
+ assertEqualsExactType(511F , message.getExtension(repeatedFloatExtensionLite , 1));
+ assertEqualsExactType(512D , message.getExtension(repeatedDoubleExtensionLite , 1));
+ assertEqualsExactType(true , message.getExtension(repeatedBoolExtensionLite , 1));
+ assertEqualsExactType("515", message.getExtension(repeatedStringExtensionLite , 1));
+ assertEqualsExactType(toBytes("516"), message.getExtension(repeatedBytesExtensionLite, 1));
+
+ assertEqualsExactType(517, message.getExtension(repeatedGroupExtensionLite ,1).getA());
+ assertEqualsExactType(518, message.getExtension(repeatedNestedMessageExtensionLite ,1).getBb());
+ assertEqualsExactType(519, message.getExtension(repeatedForeignMessageExtensionLite,1).getC());
+ assertEqualsExactType(520, message.getExtension(repeatedImportMessageExtensionLite ,1).getD());
+ assertEqualsExactType(527, message.getExtension(repeatedLazyMessageExtensionLite ,1).getBb());
+
+ assertEqualsExactType(TestAllTypesLite.NestedEnum.FOO,
+ message.getExtension(repeatedNestedEnumExtensionLite, 1));
+ assertEqualsExactType(ForeignEnumLite.FOREIGN_LITE_FOO,
+ message.getExtension(repeatedForeignEnumExtensionLite, 1));
+ assertEqualsExactType(ImportEnumLite.IMPORT_LITE_FOO,
+ message.getExtension(repeatedImportEnumExtensionLite, 1));
+
+ assertEqualsExactType("524", message.getExtension(repeatedStringPieceExtensionLite, 1));
+ assertEqualsExactType("525", message.getExtension(repeatedCordExtensionLite, 1));
+ }
+
+ public static void assertPackedExtensionsSet(TestPackedExtensionsLite message) {
+ Assert.assertEquals(2, message.getExtensionCount(packedInt32ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(packedInt64ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(packedUint32ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(packedUint64ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(packedSint32ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(packedSint64ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(packedFixed32ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(packedFixed64ExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(packedSfixed32ExtensionLite));
+ Assert.assertEquals(2, message.getExtensionCount(packedSfixed64ExtensionLite));
+ Assert.assertEquals(2, message.getExtensionCount(packedFloatExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(packedDoubleExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(packedBoolExtensionLite ));
+ Assert.assertEquals(2, message.getExtensionCount(packedEnumExtensionLite));
+ assertEqualsExactType(601 , message.getExtension(packedInt32ExtensionLite , 0));
+ assertEqualsExactType(602L , message.getExtension(packedInt64ExtensionLite , 0));
+ assertEqualsExactType(603 , message.getExtension(packedUint32ExtensionLite , 0));
+ assertEqualsExactType(604L , message.getExtension(packedUint64ExtensionLite , 0));
+ assertEqualsExactType(605 , message.getExtension(packedSint32ExtensionLite , 0));
+ assertEqualsExactType(606L , message.getExtension(packedSint64ExtensionLite , 0));
+ assertEqualsExactType(607 , message.getExtension(packedFixed32ExtensionLite , 0));
+ assertEqualsExactType(608L , message.getExtension(packedFixed64ExtensionLite , 0));
+ assertEqualsExactType(609 , message.getExtension(packedSfixed32ExtensionLite, 0));
+ assertEqualsExactType(610L , message.getExtension(packedSfixed64ExtensionLite, 0));
+ assertEqualsExactType(611F , message.getExtension(packedFloatExtensionLite , 0));
+ assertEqualsExactType(612D , message.getExtension(packedDoubleExtensionLite , 0));
+ assertEqualsExactType(true , message.getExtension(packedBoolExtensionLite , 0));
+ assertEqualsExactType(ForeignEnumLite.FOREIGN_LITE_BAR,
+ message.getExtension(packedEnumExtensionLite, 0));
+ assertEqualsExactType(701 , message.getExtension(packedInt32ExtensionLite , 1));
+ assertEqualsExactType(702L , message.getExtension(packedInt64ExtensionLite , 1));
+ assertEqualsExactType(703 , message.getExtension(packedUint32ExtensionLite , 1));
+ assertEqualsExactType(704L , message.getExtension(packedUint64ExtensionLite , 1));
+ assertEqualsExactType(705 , message.getExtension(packedSint32ExtensionLite , 1));
+ assertEqualsExactType(706L , message.getExtension(packedSint64ExtensionLite , 1));
+ assertEqualsExactType(707 , message.getExtension(packedFixed32ExtensionLite , 1));
+ assertEqualsExactType(708L , message.getExtension(packedFixed64ExtensionLite , 1));
+ assertEqualsExactType(709 , message.getExtension(packedSfixed32ExtensionLite, 1));
+ assertEqualsExactType(710L , message.getExtension(packedSfixed64ExtensionLite, 1));
+ assertEqualsExactType(711F , message.getExtension(packedFloatExtensionLite , 1));
+ assertEqualsExactType(712D , message.getExtension(packedDoubleExtensionLite , 1));
+ assertEqualsExactType(false, message.getExtension(packedBoolExtensionLite , 1));
+ assertEqualsExactType(ForeignEnumLite.FOREIGN_LITE_BAZ,
+ message.getExtension(packedEnumExtensionLite, 1));
+ }
+
+ // ===================================================================
+ // oneof
+ public static void setOneof(TestOneof2.Builder message) {
+ message.setFooLazyMessage(
+ TestOneof2.NestedMessage.newBuilder().setQuxInt(100).build());
+ message.setBarString("101");
+ message.setBazInt(102);
+ message.setBazString("103");
+ }
+
+ public static void assertOneofSet(TestOneof2 message) {
+ Assert.assertTrue(message.hasFooLazyMessage ());
+ Assert.assertTrue(message.getFooLazyMessage().hasQuxInt());
+
+ Assert.assertTrue(message.hasBarString());
+ Assert.assertTrue(message.hasBazInt ());
+ Assert.assertTrue(message.hasBazString());
+
+ Assert.assertEquals(100 , message.getFooLazyMessage().getQuxInt());
+ Assert.assertEquals("101", message.getBarString ());
+ Assert.assertEquals(102 , message.getBazInt ());
+ Assert.assertEquals("103", message.getBazString ());
+ }
+
+ public static void assertAtMostOneFieldSetOneof(TestOneof2 message) {
+ int count = 0;
+ if (message.hasFooInt()) { ++count; }
+ if (message.hasFooString()) { ++count; }
+ if (message.hasFooCord()) { ++count; }
+ if (message.hasFooStringPiece()) { ++count; }
+ if (message.hasFooBytes()) { ++count; }
+ if (message.hasFooEnum()) { ++count; }
+ if (message.hasFooMessage()) { ++count; }
+ if (message.hasFooGroup()) { ++count; }
+ if (message.hasFooLazyMessage()) { ++count; }
+ Assert.assertTrue(count <= 1);
+
+ count = 0;
+ if (message.hasBarInt()) { ++count; }
+ if (message.hasBarString()) { ++count; }
+ if (message.hasBarCord()) { ++count; }
+ if (message.hasBarStringPiece()) { ++count; }
+ if (message.hasBarBytes()) { ++count; }
+ if (message.hasBarEnum()) { ++count; }
+ Assert.assertTrue(count <= 1);
+
+ switch (message.getFooCase()) {
+ case FOO_INT:
+ Assert.assertTrue(message.hasFooInt());
+ break;
+ case FOO_STRING:
+ Assert.assertTrue(message.hasFooString());
+ break;
+ case FOO_CORD:
+ Assert.assertTrue(message.hasFooCord());
+ break;
+ case FOO_STRING_PIECE:
+ Assert.assertTrue(message.hasFooStringPiece());
+ break;
+ case FOO_BYTES:
+ Assert.assertTrue(message.hasFooBytes());
+ break;
+ case FOO_ENUM:
+ Assert.assertTrue(message.hasFooEnum());
+ break;
+ case FOO_MESSAGE:
+ Assert.assertTrue(message.hasFooMessage());
+ break;
+ case FOOGROUP:
+ Assert.assertTrue(message.hasFooGroup());
+ break;
+ case FOO_LAZY_MESSAGE:
+ Assert.assertTrue(message.hasFooLazyMessage());
+ break;
+ case FOO_NOT_SET:
+ break;
+ }
+ }
+
+ // =================================================================
+
+ /**
+ * Performs the same things that the methods of {@code TestUtil} do, but
+ * via the reflection interface. This is its own class because it needs
+ * to know what descriptor to use.
+ */
+ public static class ReflectionTester {
+ private final Descriptors.Descriptor baseDescriptor;
+ private final ExtensionRegistry extensionRegistry;
+
+ private final Descriptors.FileDescriptor file;
+ private final Descriptors.FileDescriptor importFile;
+ private final Descriptors.FileDescriptor publicImportFile;
+
+ private final Descriptors.Descriptor optionalGroup;
+ private final Descriptors.Descriptor repeatedGroup;
+ private final Descriptors.Descriptor nestedMessage;
+ private final Descriptors.Descriptor foreignMessage;
+ private final Descriptors.Descriptor importMessage;
+ private final Descriptors.Descriptor publicImportMessage;
+
+ private final Descriptors.FieldDescriptor groupA;
+ private final Descriptors.FieldDescriptor repeatedGroupA;
+ private final Descriptors.FieldDescriptor nestedB;
+ private final Descriptors.FieldDescriptor foreignC;
+ private final Descriptors.FieldDescriptor importD;
+ private final Descriptors.FieldDescriptor importE;
+
+ private final Descriptors.EnumDescriptor nestedEnum;
+ private final Descriptors.EnumDescriptor foreignEnum;
+ private final Descriptors.EnumDescriptor importEnum;
+
+ private final Descriptors.EnumValueDescriptor nestedFoo;
+ private final Descriptors.EnumValueDescriptor nestedBar;
+ private final Descriptors.EnumValueDescriptor nestedBaz;
+ private final Descriptors.EnumValueDescriptor foreignFoo;
+ private final Descriptors.EnumValueDescriptor foreignBar;
+ private final Descriptors.EnumValueDescriptor foreignBaz;
+ private final Descriptors.EnumValueDescriptor importFoo;
+ private final Descriptors.EnumValueDescriptor importBar;
+ private final Descriptors.EnumValueDescriptor importBaz;
+
+ /**
+ * Construct a {@code ReflectionTester} that will expect messages using
+ * the given descriptor.
+ *
+ * Normally {@code baseDescriptor} should be a descriptor for the type
+ * {@code TestAllTypes}, defined in
+ * {@code google/protobuf/unittest.proto}. However, if
+ * {@code extensionRegistry} is non-null, then {@code baseDescriptor} should
+ * be for {@code TestAllExtensions} instead, and instead of reading and
+ * writing normal fields, the tester will read and write extensions.
+ * All of {@code TestAllExtensions}' extensions must be registered in the
+ * registry.
+ */
+ public ReflectionTester(Descriptors.Descriptor baseDescriptor,
+ ExtensionRegistry extensionRegistry) {
+ this.baseDescriptor = baseDescriptor;
+ this.extensionRegistry = extensionRegistry;
+
+ this.file = baseDescriptor.getFile();
+ Assert.assertEquals(1, file.getDependencies().size());
+ this.importFile = file.getDependencies().get(0);
+ this.publicImportFile = importFile.getDependencies().get(0);
+
+ Descriptors.Descriptor testAllTypes;
+ if (baseDescriptor.getName() == "TestAllTypes") {
+ testAllTypes = baseDescriptor;
+ } else {
+ testAllTypes = file.findMessageTypeByName("TestAllTypes");
+ Assert.assertNotNull(testAllTypes);
+ }
+
+ if (extensionRegistry == null) {
+ // Use testAllTypes, rather than baseDescriptor, to allow
+ // initialization using TestPackedTypes descriptors. These objects
+ // won't be used by the methods for packed fields.
+ this.optionalGroup =
+ testAllTypes.findNestedTypeByName("OptionalGroup");
+ this.repeatedGroup =
+ testAllTypes.findNestedTypeByName("RepeatedGroup");
+ } else {
+ this.optionalGroup =
+ file.findMessageTypeByName("OptionalGroup_extension");
+ this.repeatedGroup =
+ file.findMessageTypeByName("RepeatedGroup_extension");
+ }
+ this.nestedMessage = testAllTypes.findNestedTypeByName("NestedMessage");
+ this.foreignMessage = file.findMessageTypeByName("ForeignMessage");
+ this.importMessage = importFile.findMessageTypeByName("ImportMessage");
+ this.publicImportMessage = publicImportFile.findMessageTypeByName(
+ "PublicImportMessage");
+
+ this.nestedEnum = testAllTypes.findEnumTypeByName("NestedEnum");
+ this.foreignEnum = file.findEnumTypeByName("ForeignEnum");
+ this.importEnum = importFile.findEnumTypeByName("ImportEnum");
+
+ Assert.assertNotNull(optionalGroup );
+ Assert.assertNotNull(repeatedGroup );
+ Assert.assertNotNull(nestedMessage );
+ Assert.assertNotNull(foreignMessage);
+ Assert.assertNotNull(importMessage );
+ Assert.assertNotNull(nestedEnum );
+ Assert.assertNotNull(foreignEnum );
+ Assert.assertNotNull(importEnum );
+
+ this.nestedB = nestedMessage .findFieldByName("bb");
+ this.foreignC = foreignMessage.findFieldByName("c");
+ this.importD = importMessage .findFieldByName("d");
+ this.importE = publicImportMessage.findFieldByName("e");
+ this.nestedFoo = nestedEnum.findValueByName("FOO");
+ this.nestedBar = nestedEnum.findValueByName("BAR");
+ this.nestedBaz = nestedEnum.findValueByName("BAZ");
+ this.foreignFoo = foreignEnum.findValueByName("FOREIGN_FOO");
+ this.foreignBar = foreignEnum.findValueByName("FOREIGN_BAR");
+ this.foreignBaz = foreignEnum.findValueByName("FOREIGN_BAZ");
+ this.importFoo = importEnum.findValueByName("IMPORT_FOO");
+ this.importBar = importEnum.findValueByName("IMPORT_BAR");
+ this.importBaz = importEnum.findValueByName("IMPORT_BAZ");
+
+ this.groupA = optionalGroup.findFieldByName("a");
+ this.repeatedGroupA = repeatedGroup.findFieldByName("a");
+
+ Assert.assertNotNull(groupA );
+ Assert.assertNotNull(repeatedGroupA);
+ Assert.assertNotNull(nestedB );
+ Assert.assertNotNull(foreignC );
+ Assert.assertNotNull(importD );
+ Assert.assertNotNull(importE );
+ Assert.assertNotNull(nestedFoo );
+ Assert.assertNotNull(nestedBar );
+ Assert.assertNotNull(nestedBaz );
+ Assert.assertNotNull(foreignFoo );
+ Assert.assertNotNull(foreignBar );
+ Assert.assertNotNull(foreignBaz );
+ Assert.assertNotNull(importFoo );
+ Assert.assertNotNull(importBar );
+ Assert.assertNotNull(importBaz );
+ }
+
+ /**
+ * Shorthand to get a FieldDescriptor for a field of unittest::TestAllTypes.
+ */
+ private Descriptors.FieldDescriptor f(String name) {
+ Descriptors.FieldDescriptor result;
+ if (extensionRegistry == null) {
+ result = baseDescriptor.findFieldByName(name);
+ } else {
+ result = file.findExtensionByName(name + "_extension");
+ }
+ Assert.assertNotNull(result);
+ return result;
+ }
+
+ /**
+ * Calls {@code parent.newBuilderForField()} or uses the
+ * {@code ExtensionRegistry} to find an appropriate builder, depending
+ * on what type is being tested.
+ */
+ private Message.Builder newBuilderForField(
+ Message.Builder parent, Descriptors.FieldDescriptor field) {
+ if (extensionRegistry == null) {
+ return parent.newBuilderForField(field);
+ } else {
+ ExtensionRegistry.ExtensionInfo extension =
+ extensionRegistry.findImmutableExtensionByNumber(
+ field.getContainingType(), field.getNumber());
+ Assert.assertNotNull(extension);
+ Assert.assertNotNull(extension.defaultInstance);
+ return extension.defaultInstance.newBuilderForType();
+ }
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Set every field of {@code message} to the values expected by
+ * {@code assertAllFieldsSet()}, using the {@link Message.Builder}
+ * reflection interface.
+ */
+ void setAllFieldsViaReflection(Message.Builder message) {
+ message.setField(f("optional_int32" ), 101 );
+ message.setField(f("optional_int64" ), 102L);
+ message.setField(f("optional_uint32" ), 103 );
+ message.setField(f("optional_uint64" ), 104L);
+ message.setField(f("optional_sint32" ), 105 );
+ message.setField(f("optional_sint64" ), 106L);
+ message.setField(f("optional_fixed32" ), 107 );
+ message.setField(f("optional_fixed64" ), 108L);
+ message.setField(f("optional_sfixed32"), 109 );
+ message.setField(f("optional_sfixed64"), 110L);
+ message.setField(f("optional_float" ), 111F);
+ message.setField(f("optional_double" ), 112D);
+ message.setField(f("optional_bool" ), true);
+ message.setField(f("optional_string" ), "115");
+ message.setField(f("optional_bytes" ), toBytes("116"));
+
+ message.setField(f("optionalgroup"),
+ newBuilderForField(message, f("optionalgroup"))
+ .setField(groupA, 117).build());
+ message.setField(f("optional_nested_message"),
+ newBuilderForField(message, f("optional_nested_message"))
+ .setField(nestedB, 118).build());
+ message.setField(f("optional_foreign_message"),
+ newBuilderForField(message, f("optional_foreign_message"))
+ .setField(foreignC, 119).build());
+ message.setField(f("optional_import_message"),
+ newBuilderForField(message, f("optional_import_message"))
+ .setField(importD, 120).build());
+ message.setField(f("optional_public_import_message"),
+ newBuilderForField(message, f("optional_public_import_message"))
+ .setField(importE, 126).build());
+ message.setField(f("optional_lazy_message"),
+ newBuilderForField(message, f("optional_lazy_message"))
+ .setField(nestedB, 127).build());
+
+ message.setField(f("optional_nested_enum" ), nestedBaz);
+ message.setField(f("optional_foreign_enum"), foreignBaz);
+ message.setField(f("optional_import_enum" ), importBaz);
+
+ message.setField(f("optional_string_piece" ), "124");
+ message.setField(f("optional_cord" ), "125");
+
+ // -----------------------------------------------------------------
+
+ message.addRepeatedField(f("repeated_int32" ), 201 );
+ message.addRepeatedField(f("repeated_int64" ), 202L);
+ message.addRepeatedField(f("repeated_uint32" ), 203 );
+ message.addRepeatedField(f("repeated_uint64" ), 204L);
+ message.addRepeatedField(f("repeated_sint32" ), 205 );
+ message.addRepeatedField(f("repeated_sint64" ), 206L);
+ message.addRepeatedField(f("repeated_fixed32" ), 207 );
+ message.addRepeatedField(f("repeated_fixed64" ), 208L);
+ message.addRepeatedField(f("repeated_sfixed32"), 209 );
+ message.addRepeatedField(f("repeated_sfixed64"), 210L);
+ message.addRepeatedField(f("repeated_float" ), 211F);
+ message.addRepeatedField(f("repeated_double" ), 212D);
+ message.addRepeatedField(f("repeated_bool" ), true);
+ message.addRepeatedField(f("repeated_string" ), "215");
+ message.addRepeatedField(f("repeated_bytes" ), toBytes("216"));
+
+ message.addRepeatedField(f("repeatedgroup"),
+ newBuilderForField(message, f("repeatedgroup"))
+ .setField(repeatedGroupA, 217).build());
+ message.addRepeatedField(f("repeated_nested_message"),
+ newBuilderForField(message, f("repeated_nested_message"))
+ .setField(nestedB, 218).build());
+ message.addRepeatedField(f("repeated_foreign_message"),
+ newBuilderForField(message, f("repeated_foreign_message"))
+ .setField(foreignC, 219).build());
+ message.addRepeatedField(f("repeated_import_message"),
+ newBuilderForField(message, f("repeated_import_message"))
+ .setField(importD, 220).build());
+ message.addRepeatedField(f("repeated_lazy_message"),
+ newBuilderForField(message, f("repeated_lazy_message"))
+ .setField(nestedB, 227).build());
+
+ message.addRepeatedField(f("repeated_nested_enum" ), nestedBar);
+ message.addRepeatedField(f("repeated_foreign_enum"), foreignBar);
+ message.addRepeatedField(f("repeated_import_enum" ), importBar);
+
+ message.addRepeatedField(f("repeated_string_piece" ), "224");
+ message.addRepeatedField(f("repeated_cord" ), "225");
+
+ // Add a second one of each field.
+ message.addRepeatedField(f("repeated_int32" ), 301 );
+ message.addRepeatedField(f("repeated_int64" ), 302L);
+ message.addRepeatedField(f("repeated_uint32" ), 303 );
+ message.addRepeatedField(f("repeated_uint64" ), 304L);
+ message.addRepeatedField(f("repeated_sint32" ), 305 );
+ message.addRepeatedField(f("repeated_sint64" ), 306L);
+ message.addRepeatedField(f("repeated_fixed32" ), 307 );
+ message.addRepeatedField(f("repeated_fixed64" ), 308L);
+ message.addRepeatedField(f("repeated_sfixed32"), 309 );
+ message.addRepeatedField(f("repeated_sfixed64"), 310L);
+ message.addRepeatedField(f("repeated_float" ), 311F);
+ message.addRepeatedField(f("repeated_double" ), 312D);
+ message.addRepeatedField(f("repeated_bool" ), false);
+ message.addRepeatedField(f("repeated_string" ), "315");
+ message.addRepeatedField(f("repeated_bytes" ), toBytes("316"));
+
+ message.addRepeatedField(f("repeatedgroup"),
+ newBuilderForField(message, f("repeatedgroup"))
+ .setField(repeatedGroupA, 317).build());
+ message.addRepeatedField(f("repeated_nested_message"),
+ newBuilderForField(message, f("repeated_nested_message"))
+ .setField(nestedB, 318).build());
+ message.addRepeatedField(f("repeated_foreign_message"),
+ newBuilderForField(message, f("repeated_foreign_message"))
+ .setField(foreignC, 319).build());
+ message.addRepeatedField(f("repeated_import_message"),
+ newBuilderForField(message, f("repeated_import_message"))
+ .setField(importD, 320).build());
+ message.addRepeatedField(f("repeated_lazy_message"),
+ newBuilderForField(message, f("repeated_lazy_message"))
+ .setField(nestedB, 327).build());
+
+ message.addRepeatedField(f("repeated_nested_enum" ), nestedBaz);
+ message.addRepeatedField(f("repeated_foreign_enum"), foreignBaz);
+ message.addRepeatedField(f("repeated_import_enum" ), importBaz);
+
+ message.addRepeatedField(f("repeated_string_piece" ), "324");
+ message.addRepeatedField(f("repeated_cord" ), "325");
+
+ // -----------------------------------------------------------------
+
+ message.setField(f("default_int32" ), 401 );
+ message.setField(f("default_int64" ), 402L);
+ message.setField(f("default_uint32" ), 403 );
+ message.setField(f("default_uint64" ), 404L);
+ message.setField(f("default_sint32" ), 405 );
+ message.setField(f("default_sint64" ), 406L);
+ message.setField(f("default_fixed32" ), 407 );
+ message.setField(f("default_fixed64" ), 408L);
+ message.setField(f("default_sfixed32"), 409 );
+ message.setField(f("default_sfixed64"), 410L);
+ message.setField(f("default_float" ), 411F);
+ message.setField(f("default_double" ), 412D);
+ message.setField(f("default_bool" ), false);
+ message.setField(f("default_string" ), "415");
+ message.setField(f("default_bytes" ), toBytes("416"));
+
+ message.setField(f("default_nested_enum" ), nestedFoo);
+ message.setField(f("default_foreign_enum"), foreignFoo);
+ message.setField(f("default_import_enum" ), importFoo);
+
+ message.setField(f("default_string_piece" ), "424");
+ message.setField(f("default_cord" ), "425");
+
+ message.setField(f("oneof_uint32" ), 601);
+ message.setField(f("oneof_nested_message"),
+ newBuilderForField(message, f("oneof_nested_message"))
+ .setField(nestedB, 602).build());
+ message.setField(f("oneof_string" ), "603");
+ message.setField(f("oneof_bytes" ), toBytes("604"));
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Modify the repeated fields of {@code message} to contain the values
+ * expected by {@code assertRepeatedFieldsModified()}, using the
+ * {@link Message.Builder} reflection interface.
+ */
+ void modifyRepeatedFieldsViaReflection(Message.Builder message) {
+ message.setRepeatedField(f("repeated_int32" ), 1, 501 );
+ message.setRepeatedField(f("repeated_int64" ), 1, 502L);
+ message.setRepeatedField(f("repeated_uint32" ), 1, 503 );
+ message.setRepeatedField(f("repeated_uint64" ), 1, 504L);
+ message.setRepeatedField(f("repeated_sint32" ), 1, 505 );
+ message.setRepeatedField(f("repeated_sint64" ), 1, 506L);
+ message.setRepeatedField(f("repeated_fixed32" ), 1, 507 );
+ message.setRepeatedField(f("repeated_fixed64" ), 1, 508L);
+ message.setRepeatedField(f("repeated_sfixed32"), 1, 509 );
+ message.setRepeatedField(f("repeated_sfixed64"), 1, 510L);
+ message.setRepeatedField(f("repeated_float" ), 1, 511F);
+ message.setRepeatedField(f("repeated_double" ), 1, 512D);
+ message.setRepeatedField(f("repeated_bool" ), 1, true);
+ message.setRepeatedField(f("repeated_string" ), 1, "515");
+ message.setRepeatedField(f("repeated_bytes" ), 1, toBytes("516"));
+
+ message.setRepeatedField(f("repeatedgroup"), 1,
+ newBuilderForField(message, f("repeatedgroup"))
+ .setField(repeatedGroupA, 517).build());
+ message.setRepeatedField(f("repeated_nested_message"), 1,
+ newBuilderForField(message, f("repeated_nested_message"))
+ .setField(nestedB, 518).build());
+ message.setRepeatedField(f("repeated_foreign_message"), 1,
+ newBuilderForField(message, f("repeated_foreign_message"))
+ .setField(foreignC, 519).build());
+ message.setRepeatedField(f("repeated_import_message"), 1,
+ newBuilderForField(message, f("repeated_import_message"))
+ .setField(importD, 520).build());
+ message.setRepeatedField(f("repeated_lazy_message"), 1,
+ newBuilderForField(message, f("repeated_lazy_message"))
+ .setField(nestedB, 527).build());
+
+ message.setRepeatedField(f("repeated_nested_enum" ), 1, nestedFoo);
+ message.setRepeatedField(f("repeated_foreign_enum"), 1, foreignFoo);
+ message.setRepeatedField(f("repeated_import_enum" ), 1, importFoo);
+
+ message.setRepeatedField(f("repeated_string_piece"), 1, "524");
+ message.setRepeatedField(f("repeated_cord"), 1, "525");
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all fields of
+ * {@code message} are set to the values assigned by {@code setAllFields},
+ * using the {@link Message} reflection interface.
+ */
+ public void assertAllFieldsSetViaReflection(MessageOrBuilder message) {
+ Assert.assertTrue(message.hasField(f("optional_int32" )));
+ Assert.assertTrue(message.hasField(f("optional_int64" )));
+ Assert.assertTrue(message.hasField(f("optional_uint32" )));
+ Assert.assertTrue(message.hasField(f("optional_uint64" )));
+ Assert.assertTrue(message.hasField(f("optional_sint32" )));
+ Assert.assertTrue(message.hasField(f("optional_sint64" )));
+ Assert.assertTrue(message.hasField(f("optional_fixed32" )));
+ Assert.assertTrue(message.hasField(f("optional_fixed64" )));
+ Assert.assertTrue(message.hasField(f("optional_sfixed32")));
+ Assert.assertTrue(message.hasField(f("optional_sfixed64")));
+ Assert.assertTrue(message.hasField(f("optional_float" )));
+ Assert.assertTrue(message.hasField(f("optional_double" )));
+ Assert.assertTrue(message.hasField(f("optional_bool" )));
+ Assert.assertTrue(message.hasField(f("optional_string" )));
+ Assert.assertTrue(message.hasField(f("optional_bytes" )));
+
+ Assert.assertTrue(message.hasField(f("optionalgroup" )));
+ Assert.assertTrue(message.hasField(f("optional_nested_message" )));
+ Assert.assertTrue(message.hasField(f("optional_foreign_message")));
+ Assert.assertTrue(message.hasField(f("optional_import_message" )));
+
+ Assert.assertTrue(
+ ((Message)message.getField(f("optionalgroup"))).hasField(groupA));
+ Assert.assertTrue(
+ ((Message)message.getField(f("optional_nested_message")))
+ .hasField(nestedB));
+ Assert.assertTrue(
+ ((Message)message.getField(f("optional_foreign_message")))
+ .hasField(foreignC));
+ Assert.assertTrue(
+ ((Message)message.getField(f("optional_import_message")))
+ .hasField(importD));
+
+ Assert.assertTrue(message.hasField(f("optional_nested_enum" )));
+ Assert.assertTrue(message.hasField(f("optional_foreign_enum")));
+ Assert.assertTrue(message.hasField(f("optional_import_enum" )));
+
+ Assert.assertTrue(message.hasField(f("optional_string_piece")));
+ Assert.assertTrue(message.hasField(f("optional_cord")));
+
+ Assert.assertEquals(101 , message.getField(f("optional_int32" )));
+ Assert.assertEquals(102L , message.getField(f("optional_int64" )));
+ Assert.assertEquals(103 , message.getField(f("optional_uint32" )));
+ Assert.assertEquals(104L , message.getField(f("optional_uint64" )));
+ Assert.assertEquals(105 , message.getField(f("optional_sint32" )));
+ Assert.assertEquals(106L , message.getField(f("optional_sint64" )));
+ Assert.assertEquals(107 , message.getField(f("optional_fixed32" )));
+ Assert.assertEquals(108L , message.getField(f("optional_fixed64" )));
+ Assert.assertEquals(109 , message.getField(f("optional_sfixed32")));
+ Assert.assertEquals(110L , message.getField(f("optional_sfixed64")));
+ Assert.assertEquals(111F , message.getField(f("optional_float" )));
+ Assert.assertEquals(112D , message.getField(f("optional_double" )));
+ Assert.assertEquals(true , message.getField(f("optional_bool" )));
+ Assert.assertEquals("115", message.getField(f("optional_string" )));
+ Assert.assertEquals(toBytes("116"), message.getField(f("optional_bytes")));
+
+ Assert.assertEquals(117,
+ ((Message)message.getField(f("optionalgroup"))).getField(groupA));
+ Assert.assertEquals(118,
+ ((Message)message.getField(f("optional_nested_message")))
+ .getField(nestedB));
+ Assert.assertEquals(119,
+ ((Message)message.getField(f("optional_foreign_message")))
+ .getField(foreignC));
+ Assert.assertEquals(120,
+ ((Message)message.getField(f("optional_import_message")))
+ .getField(importD));
+ Assert.assertEquals(126,
+ ((Message)message.getField(f("optional_public_import_message")))
+ .getField(importE));
+ Assert.assertEquals(127,
+ ((Message)message.getField(f("optional_lazy_message")))
+ .getField(nestedB));
+
+ Assert.assertEquals( nestedBaz, message.getField(f("optional_nested_enum" )));
+ Assert.assertEquals(foreignBaz, message.getField(f("optional_foreign_enum")));
+ Assert.assertEquals( importBaz, message.getField(f("optional_import_enum" )));
+
+ Assert.assertEquals("124", message.getField(f("optional_string_piece")));
+ Assert.assertEquals("125", message.getField(f("optional_cord")));
+
+ // -----------------------------------------------------------------
+
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_int32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_int64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_uint32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_uint64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_sint32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_sint64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_fixed32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_fixed64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_sfixed32")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_sfixed64")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_float" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_double" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_bool" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_string" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_bytes" )));
+
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeatedgroup" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_nested_message" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_foreign_message")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_import_message" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_lazy_message" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_nested_enum" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_foreign_enum" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_import_enum" )));
+
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_string_piece")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_cord")));
+
+ Assert.assertEquals(201 , message.getRepeatedField(f("repeated_int32" ), 0));
+ Assert.assertEquals(202L , message.getRepeatedField(f("repeated_int64" ), 0));
+ Assert.assertEquals(203 , message.getRepeatedField(f("repeated_uint32" ), 0));
+ Assert.assertEquals(204L , message.getRepeatedField(f("repeated_uint64" ), 0));
+ Assert.assertEquals(205 , message.getRepeatedField(f("repeated_sint32" ), 0));
+ Assert.assertEquals(206L , message.getRepeatedField(f("repeated_sint64" ), 0));
+ Assert.assertEquals(207 , message.getRepeatedField(f("repeated_fixed32" ), 0));
+ Assert.assertEquals(208L , message.getRepeatedField(f("repeated_fixed64" ), 0));
+ Assert.assertEquals(209 , message.getRepeatedField(f("repeated_sfixed32"), 0));
+ Assert.assertEquals(210L , message.getRepeatedField(f("repeated_sfixed64"), 0));
+ Assert.assertEquals(211F , message.getRepeatedField(f("repeated_float" ), 0));
+ Assert.assertEquals(212D , message.getRepeatedField(f("repeated_double" ), 0));
+ Assert.assertEquals(true , message.getRepeatedField(f("repeated_bool" ), 0));
+ Assert.assertEquals("215", message.getRepeatedField(f("repeated_string" ), 0));
+ Assert.assertEquals(toBytes("216"), message.getRepeatedField(f("repeated_bytes"), 0));
+
+ Assert.assertEquals(217,
+ ((Message)message.getRepeatedField(f("repeatedgroup"), 0))
+ .getField(repeatedGroupA));
+ Assert.assertEquals(218,
+ ((Message)message.getRepeatedField(f("repeated_nested_message"), 0))
+ .getField(nestedB));
+ Assert.assertEquals(219,
+ ((Message)message.getRepeatedField(f("repeated_foreign_message"), 0))
+ .getField(foreignC));
+ Assert.assertEquals(220,
+ ((Message)message.getRepeatedField(f("repeated_import_message"), 0))
+ .getField(importD));
+ Assert.assertEquals(227,
+ ((Message)message.getRepeatedField(f("repeated_lazy_message"), 0))
+ .getField(nestedB));
+
+ Assert.assertEquals( nestedBar, message.getRepeatedField(f("repeated_nested_enum" ),0));
+ Assert.assertEquals(foreignBar, message.getRepeatedField(f("repeated_foreign_enum"),0));
+ Assert.assertEquals( importBar, message.getRepeatedField(f("repeated_import_enum" ),0));
+
+ Assert.assertEquals("224", message.getRepeatedField(f("repeated_string_piece"), 0));
+ Assert.assertEquals("225", message.getRepeatedField(f("repeated_cord"), 0));
+
+ Assert.assertEquals(301 , message.getRepeatedField(f("repeated_int32" ), 1));
+ Assert.assertEquals(302L , message.getRepeatedField(f("repeated_int64" ), 1));
+ Assert.assertEquals(303 , message.getRepeatedField(f("repeated_uint32" ), 1));
+ Assert.assertEquals(304L , message.getRepeatedField(f("repeated_uint64" ), 1));
+ Assert.assertEquals(305 , message.getRepeatedField(f("repeated_sint32" ), 1));
+ Assert.assertEquals(306L , message.getRepeatedField(f("repeated_sint64" ), 1));
+ Assert.assertEquals(307 , message.getRepeatedField(f("repeated_fixed32" ), 1));
+ Assert.assertEquals(308L , message.getRepeatedField(f("repeated_fixed64" ), 1));
+ Assert.assertEquals(309 , message.getRepeatedField(f("repeated_sfixed32"), 1));
+ Assert.assertEquals(310L , message.getRepeatedField(f("repeated_sfixed64"), 1));
+ Assert.assertEquals(311F , message.getRepeatedField(f("repeated_float" ), 1));
+ Assert.assertEquals(312D , message.getRepeatedField(f("repeated_double" ), 1));
+ Assert.assertEquals(false, message.getRepeatedField(f("repeated_bool" ), 1));
+ Assert.assertEquals("315", message.getRepeatedField(f("repeated_string" ), 1));
+ Assert.assertEquals(toBytes("316"), message.getRepeatedField(f("repeated_bytes"), 1));
+
+ Assert.assertEquals(317,
+ ((Message)message.getRepeatedField(f("repeatedgroup"), 1))
+ .getField(repeatedGroupA));
+ Assert.assertEquals(318,
+ ((Message)message.getRepeatedField(f("repeated_nested_message"), 1))
+ .getField(nestedB));
+ Assert.assertEquals(319,
+ ((Message)message.getRepeatedField(f("repeated_foreign_message"), 1))
+ .getField(foreignC));
+ Assert.assertEquals(320,
+ ((Message)message.getRepeatedField(f("repeated_import_message"), 1))
+ .getField(importD));
+ Assert.assertEquals(327,
+ ((Message)message.getRepeatedField(f("repeated_lazy_message"), 1))
+ .getField(nestedB));
+
+ Assert.assertEquals( nestedBaz, message.getRepeatedField(f("repeated_nested_enum" ),1));
+ Assert.assertEquals(foreignBaz, message.getRepeatedField(f("repeated_foreign_enum"),1));
+ Assert.assertEquals( importBaz, message.getRepeatedField(f("repeated_import_enum" ),1));
+
+ Assert.assertEquals("324", message.getRepeatedField(f("repeated_string_piece"), 1));
+ Assert.assertEquals("325", message.getRepeatedField(f("repeated_cord"), 1));
+
+ // -----------------------------------------------------------------
+
+ Assert.assertTrue(message.hasField(f("default_int32" )));
+ Assert.assertTrue(message.hasField(f("default_int64" )));
+ Assert.assertTrue(message.hasField(f("default_uint32" )));
+ Assert.assertTrue(message.hasField(f("default_uint64" )));
+ Assert.assertTrue(message.hasField(f("default_sint32" )));
+ Assert.assertTrue(message.hasField(f("default_sint64" )));
+ Assert.assertTrue(message.hasField(f("default_fixed32" )));
+ Assert.assertTrue(message.hasField(f("default_fixed64" )));
+ Assert.assertTrue(message.hasField(f("default_sfixed32")));
+ Assert.assertTrue(message.hasField(f("default_sfixed64")));
+ Assert.assertTrue(message.hasField(f("default_float" )));
+ Assert.assertTrue(message.hasField(f("default_double" )));
+ Assert.assertTrue(message.hasField(f("default_bool" )));
+ Assert.assertTrue(message.hasField(f("default_string" )));
+ Assert.assertTrue(message.hasField(f("default_bytes" )));
+
+ Assert.assertTrue(message.hasField(f("default_nested_enum" )));
+ Assert.assertTrue(message.hasField(f("default_foreign_enum")));
+ Assert.assertTrue(message.hasField(f("default_import_enum" )));
+
+ Assert.assertTrue(message.hasField(f("default_string_piece")));
+ Assert.assertTrue(message.hasField(f("default_cord")));
+
+ Assert.assertEquals(401 , message.getField(f("default_int32" )));
+ Assert.assertEquals(402L , message.getField(f("default_int64" )));
+ Assert.assertEquals(403 , message.getField(f("default_uint32" )));
+ Assert.assertEquals(404L , message.getField(f("default_uint64" )));
+ Assert.assertEquals(405 , message.getField(f("default_sint32" )));
+ Assert.assertEquals(406L , message.getField(f("default_sint64" )));
+ Assert.assertEquals(407 , message.getField(f("default_fixed32" )));
+ Assert.assertEquals(408L , message.getField(f("default_fixed64" )));
+ Assert.assertEquals(409 , message.getField(f("default_sfixed32")));
+ Assert.assertEquals(410L , message.getField(f("default_sfixed64")));
+ Assert.assertEquals(411F , message.getField(f("default_float" )));
+ Assert.assertEquals(412D , message.getField(f("default_double" )));
+ Assert.assertEquals(false, message.getField(f("default_bool" )));
+ Assert.assertEquals("415", message.getField(f("default_string" )));
+ Assert.assertEquals(toBytes("416"), message.getField(f("default_bytes")));
+
+ Assert.assertEquals( nestedFoo, message.getField(f("default_nested_enum" )));
+ Assert.assertEquals(foreignFoo, message.getField(f("default_foreign_enum")));
+ Assert.assertEquals( importFoo, message.getField(f("default_import_enum" )));
+
+ Assert.assertEquals("424", message.getField(f("default_string_piece")));
+ Assert.assertEquals("425", message.getField(f("default_cord")));
+
+ Assert.assertTrue(message.hasField(f("oneof_bytes")));
+ Assert.assertEquals(toBytes("604"), message.getField(f("oneof_bytes")));
+
+ if (extensionRegistry == null) {
+ Assert.assertFalse(message.hasField(f("oneof_uint32")));
+ Assert.assertFalse(message.hasField(f("oneof_nested_message")));
+ Assert.assertFalse(message.hasField(f("oneof_string")));
+ } else {
+ Assert.assertTrue(message.hasField(f("oneof_uint32")));
+ Assert.assertTrue(message.hasField(f("oneof_nested_message")));
+ Assert.assertTrue(message.hasField(f("oneof_string")));
+ Assert.assertEquals(601, message.getField(f("oneof_uint32")));
+ Assert.assertEquals(602,
+ ((MessageOrBuilder) message.getField(f("oneof_nested_message")))
+ .getField(nestedB));
+ Assert.assertEquals("603", message.getField(f("oneof_string")));
+ }
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Assert (using {@code junit.framework.Assert}} that all fields of
+ * {@code message} are cleared, and that getting the fields returns their
+ * default values, using the {@link Message} reflection interface.
+ */
+ public void assertClearViaReflection(MessageOrBuilder message) {
+ // has_blah() should initially be false for all optional fields.
+ Assert.assertFalse(message.hasField(f("optional_int32" )));
+ Assert.assertFalse(message.hasField(f("optional_int64" )));
+ Assert.assertFalse(message.hasField(f("optional_uint32" )));
+ Assert.assertFalse(message.hasField(f("optional_uint64" )));
+ Assert.assertFalse(message.hasField(f("optional_sint32" )));
+ Assert.assertFalse(message.hasField(f("optional_sint64" )));
+ Assert.assertFalse(message.hasField(f("optional_fixed32" )));
+ Assert.assertFalse(message.hasField(f("optional_fixed64" )));
+ Assert.assertFalse(message.hasField(f("optional_sfixed32")));
+ Assert.assertFalse(message.hasField(f("optional_sfixed64")));
+ Assert.assertFalse(message.hasField(f("optional_float" )));
+ Assert.assertFalse(message.hasField(f("optional_double" )));
+ Assert.assertFalse(message.hasField(f("optional_bool" )));
+ Assert.assertFalse(message.hasField(f("optional_string" )));
+ Assert.assertFalse(message.hasField(f("optional_bytes" )));
+
+ Assert.assertFalse(message.hasField(f("optionalgroup" )));
+ Assert.assertFalse(message.hasField(f("optional_nested_message" )));
+ Assert.assertFalse(message.hasField(f("optional_foreign_message")));
+ Assert.assertFalse(message.hasField(f("optional_import_message" )));
+
+ Assert.assertFalse(message.hasField(f("optional_nested_enum" )));
+ Assert.assertFalse(message.hasField(f("optional_foreign_enum")));
+ Assert.assertFalse(message.hasField(f("optional_import_enum" )));
+
+ Assert.assertFalse(message.hasField(f("optional_string_piece")));
+ Assert.assertFalse(message.hasField(f("optional_cord")));
+
+ // Optional fields without defaults are set to zero or something like it.
+ Assert.assertEquals(0 , message.getField(f("optional_int32" )));
+ Assert.assertEquals(0L , message.getField(f("optional_int64" )));
+ Assert.assertEquals(0 , message.getField(f("optional_uint32" )));
+ Assert.assertEquals(0L , message.getField(f("optional_uint64" )));
+ Assert.assertEquals(0 , message.getField(f("optional_sint32" )));
+ Assert.assertEquals(0L , message.getField(f("optional_sint64" )));
+ Assert.assertEquals(0 , message.getField(f("optional_fixed32" )));
+ Assert.assertEquals(0L , message.getField(f("optional_fixed64" )));
+ Assert.assertEquals(0 , message.getField(f("optional_sfixed32")));
+ Assert.assertEquals(0L , message.getField(f("optional_sfixed64")));
+ Assert.assertEquals(0F , message.getField(f("optional_float" )));
+ Assert.assertEquals(0D , message.getField(f("optional_double" )));
+ Assert.assertEquals(false, message.getField(f("optional_bool" )));
+ Assert.assertEquals("" , message.getField(f("optional_string" )));
+ Assert.assertEquals(ByteString.EMPTY, message.getField(f("optional_bytes")));
+
+ // Embedded messages should also be clear.
+ Assert.assertFalse(
+ ((Message)message.getField(f("optionalgroup"))).hasField(groupA));
+ Assert.assertFalse(
+ ((Message)message.getField(f("optional_nested_message")))
+ .hasField(nestedB));
+ Assert.assertFalse(
+ ((Message)message.getField(f("optional_foreign_message")))
+ .hasField(foreignC));
+ Assert.assertFalse(
+ ((Message)message.getField(f("optional_import_message")))
+ .hasField(importD));
+ Assert.assertFalse(
+ ((Message)message.getField(f("optional_public_import_message")))
+ .hasField(importE));
+ Assert.assertFalse(
+ ((Message)message.getField(f("optional_lazy_message")))
+ .hasField(nestedB));
+
+ Assert.assertEquals(0,
+ ((Message)message.getField(f("optionalgroup"))).getField(groupA));
+ Assert.assertEquals(0,
+ ((Message)message.getField(f("optional_nested_message")))
+ .getField(nestedB));
+ Assert.assertEquals(0,
+ ((Message)message.getField(f("optional_foreign_message")))
+ .getField(foreignC));
+ Assert.assertEquals(0,
+ ((Message)message.getField(f("optional_import_message")))
+ .getField(importD));
+ Assert.assertEquals(0,
+ ((Message)message.getField(f("optional_public_import_message")))
+ .getField(importE));
+ Assert.assertEquals(0,
+ ((Message)message.getField(f("optional_lazy_message")))
+ .getField(nestedB));
+
+ // Enums without defaults are set to the first value in the enum.
+ Assert.assertEquals( nestedFoo, message.getField(f("optional_nested_enum" )));
+ Assert.assertEquals(foreignFoo, message.getField(f("optional_foreign_enum")));
+ Assert.assertEquals( importFoo, message.getField(f("optional_import_enum" )));
+
+ Assert.assertEquals("", message.getField(f("optional_string_piece")));
+ Assert.assertEquals("", message.getField(f("optional_cord")));
+
+ // Repeated fields are empty.
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_int32" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_int64" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_uint32" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_uint64" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_sint32" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_sint64" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_fixed32" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_fixed64" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_sfixed32")));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_sfixed64")));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_float" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_double" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_bool" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_string" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_bytes" )));
+
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeatedgroup" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_nested_message" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_foreign_message")));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_import_message" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_lazy_message" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_nested_enum" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_foreign_enum" )));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_import_enum" )));
+
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_string_piece")));
+ Assert.assertEquals(0, message.getRepeatedFieldCount(f("repeated_cord")));
+
+ // has_blah() should also be false for all default fields.
+ Assert.assertFalse(message.hasField(f("default_int32" )));
+ Assert.assertFalse(message.hasField(f("default_int64" )));
+ Assert.assertFalse(message.hasField(f("default_uint32" )));
+ Assert.assertFalse(message.hasField(f("default_uint64" )));
+ Assert.assertFalse(message.hasField(f("default_sint32" )));
+ Assert.assertFalse(message.hasField(f("default_sint64" )));
+ Assert.assertFalse(message.hasField(f("default_fixed32" )));
+ Assert.assertFalse(message.hasField(f("default_fixed64" )));
+ Assert.assertFalse(message.hasField(f("default_sfixed32")));
+ Assert.assertFalse(message.hasField(f("default_sfixed64")));
+ Assert.assertFalse(message.hasField(f("default_float" )));
+ Assert.assertFalse(message.hasField(f("default_double" )));
+ Assert.assertFalse(message.hasField(f("default_bool" )));
+ Assert.assertFalse(message.hasField(f("default_string" )));
+ Assert.assertFalse(message.hasField(f("default_bytes" )));
+
+ Assert.assertFalse(message.hasField(f("default_nested_enum" )));
+ Assert.assertFalse(message.hasField(f("default_foreign_enum")));
+ Assert.assertFalse(message.hasField(f("default_import_enum" )));
+
+ Assert.assertFalse(message.hasField(f("default_string_piece" )));
+ Assert.assertFalse(message.hasField(f("default_cord" )));
+
+ // Fields with defaults have their default values (duh).
+ Assert.assertEquals( 41 , message.getField(f("default_int32" )));
+ Assert.assertEquals( 42L , message.getField(f("default_int64" )));
+ Assert.assertEquals( 43 , message.getField(f("default_uint32" )));
+ Assert.assertEquals( 44L , message.getField(f("default_uint64" )));
+ Assert.assertEquals(-45 , message.getField(f("default_sint32" )));
+ Assert.assertEquals( 46L , message.getField(f("default_sint64" )));
+ Assert.assertEquals( 47 , message.getField(f("default_fixed32" )));
+ Assert.assertEquals( 48L , message.getField(f("default_fixed64" )));
+ Assert.assertEquals( 49 , message.getField(f("default_sfixed32")));
+ Assert.assertEquals(-50L , message.getField(f("default_sfixed64")));
+ Assert.assertEquals( 51.5F , message.getField(f("default_float" )));
+ Assert.assertEquals( 52e3D , message.getField(f("default_double" )));
+ Assert.assertEquals(true , message.getField(f("default_bool" )));
+ Assert.assertEquals("hello", message.getField(f("default_string" )));
+ Assert.assertEquals(toBytes("world"), message.getField(f("default_bytes")));
+
+ Assert.assertEquals( nestedBar, message.getField(f("default_nested_enum" )));
+ Assert.assertEquals(foreignBar, message.getField(f("default_foreign_enum")));
+ Assert.assertEquals( importBar, message.getField(f("default_import_enum" )));
+
+ Assert.assertEquals("abc", message.getField(f("default_string_piece")));
+ Assert.assertEquals("123", message.getField(f("default_cord")));
+
+ Assert.assertFalse(message.hasField(f("oneof_uint32")));
+ Assert.assertFalse(message.hasField(f("oneof_nested_message")));
+ Assert.assertFalse(message.hasField(f("oneof_string")));
+ Assert.assertFalse(message.hasField(f("oneof_bytes")));
+
+ Assert.assertEquals(0, message.getField(f("oneof_uint32")));
+ Assert.assertEquals("", message.getField(f("oneof_string")));
+ Assert.assertEquals(toBytes(""), message.getField(f("oneof_bytes")));
+ }
+
+
+ // ---------------------------------------------------------------
+
+ public void assertRepeatedFieldsModifiedViaReflection(
+ MessageOrBuilder message) {
+ // ModifyRepeatedFields only sets the second repeated element of each
+ // field. In addition to verifying this, we also verify that the first
+ // element and size were *not* modified.
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_int32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_int64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_uint32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_uint64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_sint32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_sint64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_fixed32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_fixed64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_sfixed32")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_sfixed64")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_float" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_double" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_bool" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_string" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_bytes" )));
+
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeatedgroup" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_nested_message" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_foreign_message")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_import_message" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_lazy_message" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_nested_enum" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_foreign_enum" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_import_enum" )));
+
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_string_piece")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("repeated_cord")));
+
+ Assert.assertEquals(201 , message.getRepeatedField(f("repeated_int32" ), 0));
+ Assert.assertEquals(202L , message.getRepeatedField(f("repeated_int64" ), 0));
+ Assert.assertEquals(203 , message.getRepeatedField(f("repeated_uint32" ), 0));
+ Assert.assertEquals(204L , message.getRepeatedField(f("repeated_uint64" ), 0));
+ Assert.assertEquals(205 , message.getRepeatedField(f("repeated_sint32" ), 0));
+ Assert.assertEquals(206L , message.getRepeatedField(f("repeated_sint64" ), 0));
+ Assert.assertEquals(207 , message.getRepeatedField(f("repeated_fixed32" ), 0));
+ Assert.assertEquals(208L , message.getRepeatedField(f("repeated_fixed64" ), 0));
+ Assert.assertEquals(209 , message.getRepeatedField(f("repeated_sfixed32"), 0));
+ Assert.assertEquals(210L , message.getRepeatedField(f("repeated_sfixed64"), 0));
+ Assert.assertEquals(211F , message.getRepeatedField(f("repeated_float" ), 0));
+ Assert.assertEquals(212D , message.getRepeatedField(f("repeated_double" ), 0));
+ Assert.assertEquals(true , message.getRepeatedField(f("repeated_bool" ), 0));
+ Assert.assertEquals("215", message.getRepeatedField(f("repeated_string" ), 0));
+ Assert.assertEquals(toBytes("216"), message.getRepeatedField(f("repeated_bytes"), 0));
+
+ Assert.assertEquals(217,
+ ((Message)message.getRepeatedField(f("repeatedgroup"), 0))
+ .getField(repeatedGroupA));
+ Assert.assertEquals(218,
+ ((Message)message.getRepeatedField(f("repeated_nested_message"), 0))
+ .getField(nestedB));
+ Assert.assertEquals(219,
+ ((Message)message.getRepeatedField(f("repeated_foreign_message"), 0))
+ .getField(foreignC));
+ Assert.assertEquals(220,
+ ((Message)message.getRepeatedField(f("repeated_import_message"), 0))
+ .getField(importD));
+ Assert.assertEquals(227,
+ ((Message)message.getRepeatedField(f("repeated_lazy_message"), 0))
+ .getField(nestedB));
+
+ Assert.assertEquals( nestedBar, message.getRepeatedField(f("repeated_nested_enum" ),0));
+ Assert.assertEquals(foreignBar, message.getRepeatedField(f("repeated_foreign_enum"),0));
+ Assert.assertEquals( importBar, message.getRepeatedField(f("repeated_import_enum" ),0));
+
+ Assert.assertEquals("224", message.getRepeatedField(f("repeated_string_piece"), 0));
+ Assert.assertEquals("225", message.getRepeatedField(f("repeated_cord"), 0));
+
+ Assert.assertEquals(501 , message.getRepeatedField(f("repeated_int32" ), 1));
+ Assert.assertEquals(502L , message.getRepeatedField(f("repeated_int64" ), 1));
+ Assert.assertEquals(503 , message.getRepeatedField(f("repeated_uint32" ), 1));
+ Assert.assertEquals(504L , message.getRepeatedField(f("repeated_uint64" ), 1));
+ Assert.assertEquals(505 , message.getRepeatedField(f("repeated_sint32" ), 1));
+ Assert.assertEquals(506L , message.getRepeatedField(f("repeated_sint64" ), 1));
+ Assert.assertEquals(507 , message.getRepeatedField(f("repeated_fixed32" ), 1));
+ Assert.assertEquals(508L , message.getRepeatedField(f("repeated_fixed64" ), 1));
+ Assert.assertEquals(509 , message.getRepeatedField(f("repeated_sfixed32"), 1));
+ Assert.assertEquals(510L , message.getRepeatedField(f("repeated_sfixed64"), 1));
+ Assert.assertEquals(511F , message.getRepeatedField(f("repeated_float" ), 1));
+ Assert.assertEquals(512D , message.getRepeatedField(f("repeated_double" ), 1));
+ Assert.assertEquals(true , message.getRepeatedField(f("repeated_bool" ), 1));
+ Assert.assertEquals("515", message.getRepeatedField(f("repeated_string" ), 1));
+ Assert.assertEquals(toBytes("516"), message.getRepeatedField(f("repeated_bytes"), 1));
+
+ Assert.assertEquals(517,
+ ((Message)message.getRepeatedField(f("repeatedgroup"), 1))
+ .getField(repeatedGroupA));
+ Assert.assertEquals(518,
+ ((Message)message.getRepeatedField(f("repeated_nested_message"), 1))
+ .getField(nestedB));
+ Assert.assertEquals(519,
+ ((Message)message.getRepeatedField(f("repeated_foreign_message"), 1))
+ .getField(foreignC));
+ Assert.assertEquals(520,
+ ((Message)message.getRepeatedField(f("repeated_import_message"), 1))
+ .getField(importD));
+ Assert.assertEquals(527,
+ ((Message)message.getRepeatedField(f("repeated_lazy_message"), 1))
+ .getField(nestedB));
+
+ Assert.assertEquals( nestedFoo, message.getRepeatedField(f("repeated_nested_enum" ),1));
+ Assert.assertEquals(foreignFoo, message.getRepeatedField(f("repeated_foreign_enum"),1));
+ Assert.assertEquals( importFoo, message.getRepeatedField(f("repeated_import_enum" ),1));
+
+ Assert.assertEquals("524", message.getRepeatedField(f("repeated_string_piece"), 1));
+ Assert.assertEquals("525", message.getRepeatedField(f("repeated_cord"), 1));
+ }
+
+ public void setPackedFieldsViaReflection(Message.Builder message) {
+ message.addRepeatedField(f("packed_int32" ), 601 );
+ message.addRepeatedField(f("packed_int64" ), 602L);
+ message.addRepeatedField(f("packed_uint32" ), 603 );
+ message.addRepeatedField(f("packed_uint64" ), 604L);
+ message.addRepeatedField(f("packed_sint32" ), 605 );
+ message.addRepeatedField(f("packed_sint64" ), 606L);
+ message.addRepeatedField(f("packed_fixed32" ), 607 );
+ message.addRepeatedField(f("packed_fixed64" ), 608L);
+ message.addRepeatedField(f("packed_sfixed32"), 609 );
+ message.addRepeatedField(f("packed_sfixed64"), 610L);
+ message.addRepeatedField(f("packed_float" ), 611F);
+ message.addRepeatedField(f("packed_double" ), 612D);
+ message.addRepeatedField(f("packed_bool" ), true);
+ message.addRepeatedField(f("packed_enum" ), foreignBar);
+ // Add a second one of each field.
+ message.addRepeatedField(f("packed_int32" ), 701 );
+ message.addRepeatedField(f("packed_int64" ), 702L);
+ message.addRepeatedField(f("packed_uint32" ), 703 );
+ message.addRepeatedField(f("packed_uint64" ), 704L);
+ message.addRepeatedField(f("packed_sint32" ), 705 );
+ message.addRepeatedField(f("packed_sint64" ), 706L);
+ message.addRepeatedField(f("packed_fixed32" ), 707 );
+ message.addRepeatedField(f("packed_fixed64" ), 708L);
+ message.addRepeatedField(f("packed_sfixed32"), 709 );
+ message.addRepeatedField(f("packed_sfixed64"), 710L);
+ message.addRepeatedField(f("packed_float" ), 711F);
+ message.addRepeatedField(f("packed_double" ), 712D);
+ message.addRepeatedField(f("packed_bool" ), false);
+ message.addRepeatedField(f("packed_enum" ), foreignBaz);
+ }
+
+ public void assertPackedFieldsSetViaReflection(MessageOrBuilder message) {
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_int32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_int64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_uint32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_uint64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_sint32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_sint64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_fixed32" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_fixed64" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_sfixed32")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_sfixed64")));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_float" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_double" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_bool" )));
+ Assert.assertEquals(2, message.getRepeatedFieldCount(f("packed_enum" )));
+ Assert.assertEquals(601 , message.getRepeatedField(f("packed_int32" ), 0));
+ Assert.assertEquals(602L , message.getRepeatedField(f("packed_int64" ), 0));
+ Assert.assertEquals(603 , message.getRepeatedField(f("packed_uint32" ), 0));
+ Assert.assertEquals(604L , message.getRepeatedField(f("packed_uint64" ), 0));
+ Assert.assertEquals(605 , message.getRepeatedField(f("packed_sint32" ), 0));
+ Assert.assertEquals(606L , message.getRepeatedField(f("packed_sint64" ), 0));
+ Assert.assertEquals(607 , message.getRepeatedField(f("packed_fixed32" ), 0));
+ Assert.assertEquals(608L , message.getRepeatedField(f("packed_fixed64" ), 0));
+ Assert.assertEquals(609 , message.getRepeatedField(f("packed_sfixed32"), 0));
+ Assert.assertEquals(610L , message.getRepeatedField(f("packed_sfixed64"), 0));
+ Assert.assertEquals(611F , message.getRepeatedField(f("packed_float" ), 0));
+ Assert.assertEquals(612D , message.getRepeatedField(f("packed_double" ), 0));
+ Assert.assertEquals(true , message.getRepeatedField(f("packed_bool" ), 0));
+ Assert.assertEquals(foreignBar, message.getRepeatedField(f("packed_enum" ),0));
+ Assert.assertEquals(701 , message.getRepeatedField(f("packed_int32" ), 1));
+ Assert.assertEquals(702L , message.getRepeatedField(f("packed_int64" ), 1));
+ Assert.assertEquals(703 , message.getRepeatedField(f("packed_uint32" ), 1));
+ Assert.assertEquals(704L , message.getRepeatedField(f("packed_uint64" ), 1));
+ Assert.assertEquals(705 , message.getRepeatedField(f("packed_sint32" ), 1));
+ Assert.assertEquals(706L , message.getRepeatedField(f("packed_sint64" ), 1));
+ Assert.assertEquals(707 , message.getRepeatedField(f("packed_fixed32" ), 1));
+ Assert.assertEquals(708L , message.getRepeatedField(f("packed_fixed64" ), 1));
+ Assert.assertEquals(709 , message.getRepeatedField(f("packed_sfixed32"), 1));
+ Assert.assertEquals(710L , message.getRepeatedField(f("packed_sfixed64"), 1));
+ Assert.assertEquals(711F , message.getRepeatedField(f("packed_float" ), 1));
+ Assert.assertEquals(712D , message.getRepeatedField(f("packed_double" ), 1));
+ Assert.assertEquals(false, message.getRepeatedField(f("packed_bool" ), 1));
+ Assert.assertEquals(foreignBaz, message.getRepeatedField(f("packed_enum" ),1));
+ }
+
+ /**
+ * Verifies that the reflection setters for the given.Builder object throw a
+ * NullPointerException if they are passed a null value. Uses Assert to throw an
+ * appropriate assertion failure, if the condition is not verified.
+ */
+ public void assertReflectionSettersRejectNull(Message.Builder builder)
+ throws Exception {
+ try {
+ builder.setField(f("optional_string"), null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setField(f("optional_bytes"), null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setField(f("optional_nested_enum"), null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setField(f("optional_nested_message"),
+ (TestAllTypes.NestedMessage) null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.setField(f("optional_nested_message"),
+ (TestAllTypes.NestedMessage.Builder) null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ try {
+ builder.addRepeatedField(f("repeated_string"), null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.addRepeatedField(f("repeated_bytes"), null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.addRepeatedField(f("repeated_nested_enum"), null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ try {
+ builder.addRepeatedField(f("repeated_nested_message"), null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ }
+
+ /**
+ * Verifies that the reflection repeated setters for the given Builder object throw a
+ * NullPointerException if they are passed a null value. Uses Assert to throw an appropriate
+ * assertion failure, if the condition is not verified.
+ */
+ public void assertReflectionRepeatedSettersRejectNull(Message.Builder builder)
+ throws Exception {
+ builder.addRepeatedField(f("repeated_string"), "one");
+ try {
+ builder.setRepeatedField(f("repeated_string"), 0, null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ builder.addRepeatedField(f("repeated_bytes"), toBytes("one"));
+ try {
+ builder.setRepeatedField(f("repeated_bytes"), 0, null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ builder.addRepeatedField(f("repeated_nested_enum"), nestedBaz);
+ try {
+ builder.setRepeatedField(f("repeated_nested_enum"), 0, null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+
+ builder.addRepeatedField(
+ f("repeated_nested_message"),
+ TestAllTypes.NestedMessage.newBuilder().setBb(218).build());
+ try {
+ builder.setRepeatedField(f("repeated_nested_message"), 0, null);
+ Assert.fail("Exception was not thrown");
+ } catch (NullPointerException e) {
+ // We expect this exception.
+ }
+ }
+ }
+
+ /**
+ * @param filePath The path relative to
+ * {@link #getTestDataDir}.
+ */
+ public static String readTextFromFile(String filePath) {
+ return readBytesFromFile(filePath).toStringUtf8();
+ }
+
+ private static File getTestDataDir() {
+ // Search each parent directory looking for "src/google/protobuf".
+ File ancestor = new File(System.getProperty("protobuf.dir", "."));
+ String initialPath = ancestor.getAbsolutePath();
+ try {
+ ancestor = ancestor.getCanonicalFile();
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "Couldn't get canonical name of working directory.", e);
+ }
+ while (ancestor != null && ancestor.exists()) {
+ if (new File(ancestor, "src/google/protobuf").exists()) {
+ return new File(ancestor, "src/google/protobuf/testdata");
+ }
+ ancestor = ancestor.getParentFile();
+ }
+
+ throw new RuntimeException(
+ "Could not find golden files. This test must be run from within the " +
+ "protobuf source package so that it can read test data files from the " +
+ "C++ source tree: " + initialPath);
+ }
+
+ /**
+ * @param filename The path relative to
+ * {@link #getTestDataDir}.
+ */
+ public static ByteString readBytesFromFile(String filename) {
+ File fullPath = new File(getTestDataDir(), filename);
+ try {
+ RandomAccessFile file = new RandomAccessFile(fullPath, "r");
+ byte[] content = new byte[(int) file.length()];
+ file.readFully(content);
+ return ByteString.copyFrom(content);
+ } catch (IOException e) {
+ // Throw a RuntimeException here so that we can call this function from
+ // static initializers.
+ throw new IllegalArgumentException(
+ "Couldn't read file: " + fullPath.getPath(), e);
+ }
+ }
+
+ /**
+ * Get the bytes of the "golden message". This is a serialized TestAllTypes
+ * with all fields set as they would be by
+ * {@link #setAllFields(TestAllTypes.Builder)}, but it is loaded from a file
+ * on disk rather than generated dynamically. The file is actually generated
+ * by C++ code, so testing against it verifies compatibility with C++.
+ */
+ public static ByteString getGoldenMessage() {
+ if (goldenMessage == null) {
+ goldenMessage = readBytesFromFile("golden_message_oneof_implemented");
+ }
+ return goldenMessage;
+ }
+ private static ByteString goldenMessage = null;
+
+ /**
+ * Get the bytes of the "golden packed fields message". This is a serialized
+ * TestPackedTypes with all fields set as they would be by
+ * {@link #setPackedFields(TestPackedTypes.Builder)}, but it is loaded from a
+ * file on disk rather than generated dynamically. The file is actually
+ * generated by C++ code, so testing against it verifies compatibility with
+ * C++.
+ */
+ public static ByteString getGoldenPackedFieldsMessage() {
+ if (goldenPackedFieldsMessage == null) {
+ goldenPackedFieldsMessage =
+ readBytesFromFile("golden_packed_fields_message");
+ }
+ return goldenPackedFieldsMessage;
+ }
+ private static ByteString goldenPackedFieldsMessage = null;
+
+ /**
+ * Mock implementation of {@link GeneratedMessage.BuilderParent} for testing.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+ public static class MockBuilderParent
+ implements GeneratedMessage.BuilderParent {
+
+ private int invalidations;
+
+ @Override
+ public void markDirty() {
+ invalidations++;
+ }
+
+ public int getInvalidationCount() {
+ return invalidations;
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TestUtilLite.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TestUtilLite.java
new file mode 100644
index 0000000000..8f33fa14ab
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TestUtilLite.java
@@ -0,0 +1,559 @@
+// 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 static com.google.protobuf.UnittestLite.OptionalGroup_extension_lite;
+import static com.google.protobuf.UnittestLite.RepeatedGroup_extension_lite;
+import static com.google.protobuf.UnittestLite.defaultBoolExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultBytesExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultCordExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultDoubleExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultFixed32ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultFixed64ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultFloatExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultForeignEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultImportEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultInt32ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultInt64ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultNestedEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultSfixed32ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultSfixed64ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultSint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultSint64ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultStringExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultStringPieceExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultUint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.defaultUint64ExtensionLite;
+import static com.google.protobuf.UnittestLite.oneofBytesExtensionLite;
+import static com.google.protobuf.UnittestLite.oneofNestedMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.oneofStringExtensionLite;
+import static com.google.protobuf.UnittestLite.oneofUint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalBoolExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalBytesExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalCordExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalDoubleExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalFixed32ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalFixed64ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalFloatExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalForeignEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalForeignMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalGroupExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalImportEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalImportMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalInt32ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalInt64ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalLazyMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalNestedEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalNestedMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalPublicImportMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalSfixed32ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalSfixed64ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalSint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalSint64ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalStringExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalStringPieceExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalUint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.optionalUint64ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedBoolExtensionLite;
+import static com.google.protobuf.UnittestLite.packedDoubleExtensionLite;
+import static com.google.protobuf.UnittestLite.packedEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.packedFixed32ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedFixed64ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedFloatExtensionLite;
+import static com.google.protobuf.UnittestLite.packedInt32ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedInt64ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedSfixed32ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedSfixed64ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedSint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedSint64ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedUint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.packedUint64ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedBoolExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedBytesExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedCordExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedDoubleExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedFixed32ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedFixed64ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedFloatExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedForeignEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedForeignMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedGroupExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedImportEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedImportMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedInt32ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedInt64ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedLazyMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedNestedEnumExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedNestedMessageExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedSfixed32ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedSfixed64ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedSint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedSint64ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedStringExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedStringPieceExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedUint32ExtensionLite;
+import static com.google.protobuf.UnittestLite.repeatedUint64ExtensionLite;
+
+import com.google.protobuf.UnittestImportLite.ImportEnumLite;
+import com.google.protobuf.UnittestImportLite.ImportMessageLite;
+import com.google.protobuf.UnittestImportPublicLite.PublicImportMessageLite;
+import com.google.protobuf.UnittestLite.ForeignEnumLite;
+import com.google.protobuf.UnittestLite.ForeignMessageLite;
+import com.google.protobuf.UnittestLite.TestAllExtensionsLite;
+import com.google.protobuf.UnittestLite.TestAllTypesLite;
+import com.google.protobuf.UnittestLite.TestPackedExtensionsLite;
+
+/**
+ * Contains methods for setting fields of {@code TestAllTypesLite}, {@code TestAllExtensionsLite},
+ * and {@code TestPackedExtensionsLite}. This is analogous to the functionality in TestUtil.java but
+ * does not depend on the presence of any non-lite protos.
+ *
+ * <p>This code is not to be used outside of {@code com.google.protobuf} and
+ * subpackages.
+ */
+public final class TestUtilLite {
+ private TestUtilLite() {}
+
+ /** Helper to convert a String to ByteString. */
+ static ByteString toBytes(String str) {
+ return ByteString.copyFrom(str.getBytes(Internal.UTF_8));
+ }
+
+ /**
+ * Get a {@code TestAllTypesLite.Builder} with all fields set as they would be by
+ * {@link #setAllFields(TestAllTypesLite.Builder)}.
+ */
+ public static TestAllTypesLite.Builder getAllLiteSetBuilder() {
+ TestAllTypesLite.Builder builder = TestAllTypesLite.newBuilder();
+ setAllFields(builder);
+ return builder;
+ }
+
+ /**
+ * Get a {@code TestAllExtensionsLite} with all fields set as they would be by
+ * {@link #setAllExtensions(TestAllExtensionsLite.Builder)}.
+ */
+ public static TestAllExtensionsLite getAllLiteExtensionsSet() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.newBuilder();
+ setAllExtensions(builder);
+ return builder.build();
+ }
+
+ public static TestPackedExtensionsLite getLitePackedExtensionsSet() {
+ TestPackedExtensionsLite.Builder builder = TestPackedExtensionsLite.newBuilder();
+ setPackedExtensions(builder);
+ return builder.build();
+ }
+
+ /**
+ * Set every field of {@code builder} to the values expected by
+ * {@code assertAllFieldsSet()}.
+ */
+ public static void setAllFields(TestAllTypesLite.Builder builder) {
+ builder.setOptionalInt32 (101);
+ builder.setOptionalInt64 (102);
+ builder.setOptionalUint32 (103);
+ builder.setOptionalUint64 (104);
+ builder.setOptionalSint32 (105);
+ builder.setOptionalSint64 (106);
+ builder.setOptionalFixed32 (107);
+ builder.setOptionalFixed64 (108);
+ builder.setOptionalSfixed32(109);
+ builder.setOptionalSfixed64(110);
+ builder.setOptionalFloat (111);
+ builder.setOptionalDouble (112);
+ builder.setOptionalBool (true);
+ builder.setOptionalString ("115");
+ builder.setOptionalBytes (toBytes("116"));
+
+ builder.setOptionalGroup(
+ TestAllTypesLite.OptionalGroup.newBuilder().setA(117).build());
+ builder.setOptionalNestedMessage(
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(118).build());
+ builder.setOptionalForeignMessage(
+ ForeignMessageLite.newBuilder().setC(119).build());
+ builder.setOptionalImportMessage(
+ ImportMessageLite.newBuilder().setD(120).build());
+ builder.setOptionalPublicImportMessage(
+ PublicImportMessageLite.newBuilder().setE(126).build());
+ builder.setOptionalLazyMessage(
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(127).build());
+
+ builder.setOptionalNestedEnum (TestAllTypesLite.NestedEnum.BAZ);
+ builder.setOptionalForeignEnum(ForeignEnumLite.FOREIGN_LITE_BAZ);
+ builder.setOptionalImportEnum (ImportEnumLite.IMPORT_LITE_BAZ);
+
+ builder.setOptionalStringPiece("124");
+ builder.setOptionalCord("125");
+
+ // -----------------------------------------------------------------
+
+ builder.addRepeatedInt32 (201);
+ builder.addRepeatedInt64 (202);
+ builder.addRepeatedUint32 (203);
+ builder.addRepeatedUint64 (204);
+ builder.addRepeatedSint32 (205);
+ builder.addRepeatedSint64 (206);
+ builder.addRepeatedFixed32 (207);
+ builder.addRepeatedFixed64 (208);
+ builder.addRepeatedSfixed32(209);
+ builder.addRepeatedSfixed64(210);
+ builder.addRepeatedFloat (211);
+ builder.addRepeatedDouble (212);
+ builder.addRepeatedBool (true);
+ builder.addRepeatedString ("215");
+ builder.addRepeatedBytes (toBytes("216"));
+
+ builder.addRepeatedGroup(
+ TestAllTypesLite.RepeatedGroup.newBuilder().setA(217).build());
+ builder.addRepeatedNestedMessage(
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(218).build());
+ builder.addRepeatedForeignMessage(
+ ForeignMessageLite.newBuilder().setC(219).build());
+ builder.addRepeatedImportMessage(
+ ImportMessageLite.newBuilder().setD(220).build());
+ builder.addRepeatedLazyMessage(
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(227).build());
+
+ builder.addRepeatedNestedEnum (TestAllTypesLite.NestedEnum.BAR);
+ builder.addRepeatedForeignEnum(ForeignEnumLite.FOREIGN_LITE_BAR);
+ builder.addRepeatedImportEnum (ImportEnumLite.IMPORT_LITE_BAR);
+
+ builder.addRepeatedStringPiece("224");
+ builder.addRepeatedCord("225");
+
+ // Add a second one of each field.
+ builder.addRepeatedInt32 (301);
+ builder.addRepeatedInt64 (302);
+ builder.addRepeatedUint32 (303);
+ builder.addRepeatedUint64 (304);
+ builder.addRepeatedSint32 (305);
+ builder.addRepeatedSint64 (306);
+ builder.addRepeatedFixed32 (307);
+ builder.addRepeatedFixed64 (308);
+ builder.addRepeatedSfixed32(309);
+ builder.addRepeatedSfixed64(310);
+ builder.addRepeatedFloat (311);
+ builder.addRepeatedDouble (312);
+ builder.addRepeatedBool (false);
+ builder.addRepeatedString ("315");
+ builder.addRepeatedBytes (toBytes("316"));
+
+ builder.addRepeatedGroup(
+ TestAllTypesLite.RepeatedGroup.newBuilder().setA(317).build());
+ builder.addRepeatedNestedMessage(
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(318).build());
+ builder.addRepeatedForeignMessage(
+ ForeignMessageLite.newBuilder().setC(319).build());
+ builder.addRepeatedImportMessage(
+ ImportMessageLite.newBuilder().setD(320).build());
+ builder.addRepeatedLazyMessage(
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(327).build());
+
+ builder.addRepeatedNestedEnum (TestAllTypesLite.NestedEnum.BAZ);
+ builder.addRepeatedForeignEnum(ForeignEnumLite.FOREIGN_LITE_BAZ);
+ builder.addRepeatedImportEnum (ImportEnumLite.IMPORT_LITE_BAZ);
+
+ builder.addRepeatedStringPiece("324");
+ builder.addRepeatedCord("325");
+
+ // -----------------------------------------------------------------
+
+ builder.setDefaultInt32 (401);
+ builder.setDefaultInt64 (402);
+ builder.setDefaultUint32 (403);
+ builder.setDefaultUint64 (404);
+ builder.setDefaultSint32 (405);
+ builder.setDefaultSint64 (406);
+ builder.setDefaultFixed32 (407);
+ builder.setDefaultFixed64 (408);
+ builder.setDefaultSfixed32(409);
+ builder.setDefaultSfixed64(410);
+ builder.setDefaultFloat (411);
+ builder.setDefaultDouble (412);
+ builder.setDefaultBool (false);
+ builder.setDefaultString ("415");
+ builder.setDefaultBytes (toBytes("416"));
+
+ builder.setDefaultNestedEnum (TestAllTypesLite.NestedEnum.FOO);
+ builder.setDefaultForeignEnum(ForeignEnumLite.FOREIGN_LITE_FOO);
+ builder.setDefaultImportEnum (ImportEnumLite.IMPORT_LITE_FOO);
+
+ builder.setDefaultStringPiece("424");
+ builder.setDefaultCord("425");
+
+ builder.setOneofUint32(601);
+ builder.setOneofNestedMessage(
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(602).build());
+ builder.setOneofString("603");
+ builder.setOneofBytes(toBytes("604"));
+ }
+
+ /**
+ * Get an unmodifiable {@link ExtensionRegistryLite} containing all the
+ * extensions of {@code TestAllExtensionsLite}.
+ */
+ public static ExtensionRegistryLite getExtensionRegistryLite() {
+ ExtensionRegistryLite registry = ExtensionRegistryLite.newInstance();
+ registerAllExtensionsLite(registry);
+ return registry.getUnmodifiable();
+ }
+
+ /**
+ * Register all of {@code TestAllExtensionsLite}'s extensions with the
+ * given {@link ExtensionRegistryLite}.
+ */
+ public static void registerAllExtensionsLite(ExtensionRegistryLite registry) {
+ UnittestLite.registerAllExtensions(registry);
+ }
+
+ // ===================================================================
+ // Lite extensions
+
+ /**
+ * Set every field of {@code message} to the values expected by
+ * {@code assertAllExtensionsSet()}.
+ */
+ public static void setAllExtensions(TestAllExtensionsLite.Builder message) {
+ message.setExtension(optionalInt32ExtensionLite , 101);
+ message.setExtension(optionalInt64ExtensionLite , 102L);
+ message.setExtension(optionalUint32ExtensionLite , 103);
+ message.setExtension(optionalUint64ExtensionLite , 104L);
+ message.setExtension(optionalSint32ExtensionLite , 105);
+ message.setExtension(optionalSint64ExtensionLite , 106L);
+ message.setExtension(optionalFixed32ExtensionLite , 107);
+ message.setExtension(optionalFixed64ExtensionLite , 108L);
+ message.setExtension(optionalSfixed32ExtensionLite, 109);
+ message.setExtension(optionalSfixed64ExtensionLite, 110L);
+ message.setExtension(optionalFloatExtensionLite , 111F);
+ message.setExtension(optionalDoubleExtensionLite , 112D);
+ message.setExtension(optionalBoolExtensionLite , true);
+ message.setExtension(optionalStringExtensionLite , "115");
+ message.setExtension(optionalBytesExtensionLite , toBytes("116"));
+
+ message.setExtension(optionalGroupExtensionLite,
+ OptionalGroup_extension_lite.newBuilder().setA(117).build());
+ message.setExtension(optionalNestedMessageExtensionLite,
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(118).build());
+ message.setExtension(optionalForeignMessageExtensionLite,
+ ForeignMessageLite.newBuilder().setC(119).build());
+ message.setExtension(optionalImportMessageExtensionLite,
+ ImportMessageLite.newBuilder().setD(120).build());
+ message.setExtension(optionalPublicImportMessageExtensionLite,
+ PublicImportMessageLite.newBuilder().setE(126).build());
+ message.setExtension(optionalLazyMessageExtensionLite,
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(127).build());
+
+ message.setExtension(optionalNestedEnumExtensionLite, TestAllTypesLite.NestedEnum.BAZ);
+ message.setExtension(optionalForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ);
+ message.setExtension(optionalImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ);
+
+ message.setExtension(optionalStringPieceExtensionLite, "124");
+ message.setExtension(optionalCordExtensionLite, "125");
+
+ // -----------------------------------------------------------------
+
+ message.addExtension(repeatedInt32ExtensionLite , 201);
+ message.addExtension(repeatedInt64ExtensionLite , 202L);
+ message.addExtension(repeatedUint32ExtensionLite , 203);
+ message.addExtension(repeatedUint64ExtensionLite , 204L);
+ message.addExtension(repeatedSint32ExtensionLite , 205);
+ message.addExtension(repeatedSint64ExtensionLite , 206L);
+ message.addExtension(repeatedFixed32ExtensionLite , 207);
+ message.addExtension(repeatedFixed64ExtensionLite , 208L);
+ message.addExtension(repeatedSfixed32ExtensionLite, 209);
+ message.addExtension(repeatedSfixed64ExtensionLite, 210L);
+ message.addExtension(repeatedFloatExtensionLite , 211F);
+ message.addExtension(repeatedDoubleExtensionLite , 212D);
+ message.addExtension(repeatedBoolExtensionLite , true);
+ message.addExtension(repeatedStringExtensionLite , "215");
+ message.addExtension(repeatedBytesExtensionLite , toBytes("216"));
+
+ message.addExtension(repeatedGroupExtensionLite,
+ RepeatedGroup_extension_lite.newBuilder().setA(217).build());
+ message.addExtension(repeatedNestedMessageExtensionLite,
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(218).build());
+ message.addExtension(repeatedForeignMessageExtensionLite,
+ ForeignMessageLite.newBuilder().setC(219).build());
+ message.addExtension(repeatedImportMessageExtensionLite,
+ ImportMessageLite.newBuilder().setD(220).build());
+ message.addExtension(repeatedLazyMessageExtensionLite,
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(227).build());
+
+ message.addExtension(repeatedNestedEnumExtensionLite, TestAllTypesLite.NestedEnum.BAR);
+ message.addExtension(repeatedForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAR);
+ message.addExtension(repeatedImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAR);
+
+ message.addExtension(repeatedStringPieceExtensionLite, "224");
+ message.addExtension(repeatedCordExtensionLite, "225");
+
+ // Add a second one of each field.
+ message.addExtension(repeatedInt32ExtensionLite , 301);
+ message.addExtension(repeatedInt64ExtensionLite , 302L);
+ message.addExtension(repeatedUint32ExtensionLite , 303);
+ message.addExtension(repeatedUint64ExtensionLite , 304L);
+ message.addExtension(repeatedSint32ExtensionLite , 305);
+ message.addExtension(repeatedSint64ExtensionLite , 306L);
+ message.addExtension(repeatedFixed32ExtensionLite , 307);
+ message.addExtension(repeatedFixed64ExtensionLite , 308L);
+ message.addExtension(repeatedSfixed32ExtensionLite, 309);
+ message.addExtension(repeatedSfixed64ExtensionLite, 310L);
+ message.addExtension(repeatedFloatExtensionLite , 311F);
+ message.addExtension(repeatedDoubleExtensionLite , 312D);
+ message.addExtension(repeatedBoolExtensionLite , false);
+ message.addExtension(repeatedStringExtensionLite , "315");
+ message.addExtension(repeatedBytesExtensionLite , toBytes("316"));
+
+ message.addExtension(repeatedGroupExtensionLite,
+ RepeatedGroup_extension_lite.newBuilder().setA(317).build());
+ message.addExtension(repeatedNestedMessageExtensionLite,
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(318).build());
+ message.addExtension(repeatedForeignMessageExtensionLite,
+ ForeignMessageLite.newBuilder().setC(319).build());
+ message.addExtension(repeatedImportMessageExtensionLite,
+ ImportMessageLite.newBuilder().setD(320).build());
+ message.addExtension(repeatedLazyMessageExtensionLite,
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(327).build());
+
+ message.addExtension(repeatedNestedEnumExtensionLite, TestAllTypesLite.NestedEnum.BAZ);
+ message.addExtension(repeatedForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ);
+ message.addExtension(repeatedImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ);
+
+ message.addExtension(repeatedStringPieceExtensionLite, "324");
+ message.addExtension(repeatedCordExtensionLite, "325");
+
+ // -----------------------------------------------------------------
+
+ message.setExtension(defaultInt32ExtensionLite , 401);
+ message.setExtension(defaultInt64ExtensionLite , 402L);
+ message.setExtension(defaultUint32ExtensionLite , 403);
+ message.setExtension(defaultUint64ExtensionLite , 404L);
+ message.setExtension(defaultSint32ExtensionLite , 405);
+ message.setExtension(defaultSint64ExtensionLite , 406L);
+ message.setExtension(defaultFixed32ExtensionLite , 407);
+ message.setExtension(defaultFixed64ExtensionLite , 408L);
+ message.setExtension(defaultSfixed32ExtensionLite, 409);
+ message.setExtension(defaultSfixed64ExtensionLite, 410L);
+ message.setExtension(defaultFloatExtensionLite , 411F);
+ message.setExtension(defaultDoubleExtensionLite , 412D);
+ message.setExtension(defaultBoolExtensionLite , false);
+ message.setExtension(defaultStringExtensionLite , "415");
+ message.setExtension(defaultBytesExtensionLite , toBytes("416"));
+
+ message.setExtension(defaultNestedEnumExtensionLite, TestAllTypesLite.NestedEnum.FOO);
+ message.setExtension(defaultForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_FOO);
+ message.setExtension(defaultImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_FOO);
+
+ message.setExtension(defaultStringPieceExtensionLite, "424");
+ message.setExtension(defaultCordExtensionLite, "425");
+
+ message.setExtension(oneofUint32ExtensionLite, 601);
+ message.setExtension(oneofNestedMessageExtensionLite,
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(602).build());
+ message.setExtension(oneofStringExtensionLite, "603");
+ message.setExtension(oneofBytesExtensionLite, toBytes("604"));
+ }
+
+ // -------------------------------------------------------------------
+
+ /**
+ * Modify the repeated extensions of {@code message} to contain the values
+ * expected by {@code assertRepeatedExtensionsModified()}.
+ */
+ public static void modifyRepeatedExtensions(
+ TestAllExtensionsLite.Builder message) {
+ message.setExtension(repeatedInt32ExtensionLite , 1, 501);
+ message.setExtension(repeatedInt64ExtensionLite , 1, 502L);
+ message.setExtension(repeatedUint32ExtensionLite , 1, 503);
+ message.setExtension(repeatedUint64ExtensionLite , 1, 504L);
+ message.setExtension(repeatedSint32ExtensionLite , 1, 505);
+ message.setExtension(repeatedSint64ExtensionLite , 1, 506L);
+ message.setExtension(repeatedFixed32ExtensionLite , 1, 507);
+ message.setExtension(repeatedFixed64ExtensionLite , 1, 508L);
+ message.setExtension(repeatedSfixed32ExtensionLite, 1, 509);
+ message.setExtension(repeatedSfixed64ExtensionLite, 1, 510L);
+ message.setExtension(repeatedFloatExtensionLite , 1, 511F);
+ message.setExtension(repeatedDoubleExtensionLite , 1, 512D);
+ message.setExtension(repeatedBoolExtensionLite , 1, true);
+ message.setExtension(repeatedStringExtensionLite , 1, "515");
+ message.setExtension(repeatedBytesExtensionLite , 1, toBytes("516"));
+
+ message.setExtension(repeatedGroupExtensionLite, 1,
+ RepeatedGroup_extension_lite.newBuilder().setA(517).build());
+ message.setExtension(repeatedNestedMessageExtensionLite, 1,
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(518).build());
+ message.setExtension(repeatedForeignMessageExtensionLite, 1,
+ ForeignMessageLite.newBuilder().setC(519).build());
+ message.setExtension(repeatedImportMessageExtensionLite, 1,
+ ImportMessageLite.newBuilder().setD(520).build());
+ message.setExtension(repeatedLazyMessageExtensionLite, 1,
+ TestAllTypesLite.NestedMessage.newBuilder().setBb(527).build());
+
+ message.setExtension(repeatedNestedEnumExtensionLite , 1, TestAllTypesLite.NestedEnum.FOO);
+ message.setExtension(repeatedForeignEnumExtensionLite, 1, ForeignEnumLite.FOREIGN_LITE_FOO);
+ message.setExtension(repeatedImportEnumExtensionLite , 1, ImportEnumLite.IMPORT_LITE_FOO);
+
+ message.setExtension(repeatedStringPieceExtensionLite, 1, "524");
+ message.setExtension(repeatedCordExtensionLite, 1, "525");
+ }
+
+ public static void setPackedExtensions(TestPackedExtensionsLite.Builder message) {
+ message.addExtension(packedInt32ExtensionLite , 601);
+ message.addExtension(packedInt64ExtensionLite , 602L);
+ message.addExtension(packedUint32ExtensionLite , 603);
+ message.addExtension(packedUint64ExtensionLite , 604L);
+ message.addExtension(packedSint32ExtensionLite , 605);
+ message.addExtension(packedSint64ExtensionLite , 606L);
+ message.addExtension(packedFixed32ExtensionLite , 607);
+ message.addExtension(packedFixed64ExtensionLite , 608L);
+ message.addExtension(packedSfixed32ExtensionLite, 609);
+ message.addExtension(packedSfixed64ExtensionLite, 610L);
+ message.addExtension(packedFloatExtensionLite , 611F);
+ message.addExtension(packedDoubleExtensionLite , 612D);
+ message.addExtension(packedBoolExtensionLite , true);
+ message.addExtension(packedEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAR);
+ // Add a second one of each field.
+ message.addExtension(packedInt32ExtensionLite , 701);
+ message.addExtension(packedInt64ExtensionLite , 702L);
+ message.addExtension(packedUint32ExtensionLite , 703);
+ message.addExtension(packedUint64ExtensionLite , 704L);
+ message.addExtension(packedSint32ExtensionLite , 705);
+ message.addExtension(packedSint64ExtensionLite , 706L);
+ message.addExtension(packedFixed32ExtensionLite , 707);
+ message.addExtension(packedFixed64ExtensionLite , 708L);
+ message.addExtension(packedSfixed32ExtensionLite, 709);
+ message.addExtension(packedSfixed64ExtensionLite, 710L);
+ message.addExtension(packedFloatExtensionLite , 711F);
+ message.addExtension(packedDoubleExtensionLite , 712D);
+ message.addExtension(packedBoolExtensionLite , false);
+ message.addExtension(packedEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ);
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TextFormatParseInfoTreeTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TextFormatParseInfoTreeTest.java
new file mode 100644
index 0000000000..e338af2112
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TextFormatParseInfoTreeTest.java
@@ -0,0 +1,182 @@
+// 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.Descriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+
+import junit.framework.TestCase;
+
+/**
+ * Test @{link TextFormatParseInfoTree}.
+ */
+public class TextFormatParseInfoTreeTest extends TestCase {
+
+ private static final Descriptor DESCRIPTOR = TestAllTypes.getDescriptor();
+ private static final FieldDescriptor OPTIONAL_INT32 =
+ DESCRIPTOR.findFieldByName("optional_int32");
+ private static final FieldDescriptor OPTIONAL_BOOLEAN =
+ DESCRIPTOR.findFieldByName("optional_boolean");
+ private static final FieldDescriptor REPEATED_INT32 =
+ DESCRIPTOR.findFieldByName("repeated_int32");
+ private static final FieldDescriptor OPTIONAL_NESTED_MESSAGE =
+ DESCRIPTOR.findFieldByName("optional_nested_message");
+ private static final FieldDescriptor REPEATED_NESTED_MESSAGE =
+ DESCRIPTOR.findFieldByName("repeated_nested_message");
+ private static final FieldDescriptor FIELD_BB =
+ TestAllTypes.NestedMessage.getDescriptor().findFieldByName("bb");
+
+ private static final TextFormatParseLocation LOC0 = TextFormatParseLocation.create(1, 2);
+ private static final TextFormatParseLocation LOC1 = TextFormatParseLocation.create(2, 3);
+
+ private TextFormatParseInfoTree.Builder rootBuilder;
+
+ @Override
+ public void setUp() {
+ rootBuilder = TextFormatParseInfoTree.builder();
+ }
+
+ public void testBuildEmptyParseTree() {
+ TextFormatParseInfoTree tree = rootBuilder.build();
+ assertTrue(tree.getLocations(null).isEmpty());
+ }
+
+ public void testGetLocationReturnsSingleLocation() {
+ rootBuilder.setLocation(OPTIONAL_INT32, LOC0);
+ TextFormatParseInfoTree root = rootBuilder.build();
+ assertEquals(LOC0, root.getLocation(OPTIONAL_INT32, 0));
+ assertEquals(1, root.getLocations(OPTIONAL_INT32).size());
+ }
+
+ public void testGetLocationsReturnsNoParseLocationsForUnknownField() {
+ assertTrue(rootBuilder.build().getLocations(OPTIONAL_INT32).isEmpty());
+ rootBuilder.setLocation(OPTIONAL_BOOLEAN, LOC0);
+ TextFormatParseInfoTree root = rootBuilder.build();
+ assertTrue(root.getLocations(OPTIONAL_INT32).isEmpty());
+ assertEquals(LOC0, root.getLocations(OPTIONAL_BOOLEAN).get(0));
+ }
+
+ public void testGetLocationThrowsIllegalArgumentExceptionForUnknownField() {
+ rootBuilder.setLocation(REPEATED_INT32, LOC0);
+ TextFormatParseInfoTree root = rootBuilder.build();
+ try {
+ root.getNestedTree(OPTIONAL_INT32, 0);
+ fail("Did not detect unknown field");
+ } catch (IllegalArgumentException expected) {
+ // pass
+ }
+ }
+
+ public void testGetLocationThrowsIllegalArgumentExceptionForInvalidIndex() {
+ TextFormatParseInfoTree root = rootBuilder.setLocation(OPTIONAL_INT32, LOC0).build();
+ try {
+ root.getLocation(OPTIONAL_INT32, 1);
+ fail("Invalid index not detected");
+ } catch (IllegalArgumentException expected) {
+ // pass
+ }
+ try {
+ root.getLocation(OPTIONAL_INT32, -1);
+ fail("Negative index not detected");
+ } catch (IllegalArgumentException expected) {
+ // pass
+ }
+ }
+
+ public void testGetLocationsReturnsMultipleLocations() {
+ rootBuilder.setLocation(REPEATED_INT32, LOC0);
+ rootBuilder.setLocation(REPEATED_INT32, LOC1);
+ TextFormatParseInfoTree root = rootBuilder.build();
+ assertEquals(LOC0, root.getLocation(REPEATED_INT32, 0));
+ assertEquals(LOC1, root.getLocation(REPEATED_INT32, 1));
+ assertEquals(2, root.getLocations(REPEATED_INT32).size());
+ }
+
+ public void testGetNestedTreeThrowsIllegalArgumentExceptionForUnknownField() {
+ rootBuilder.setLocation(REPEATED_INT32, LOC0);
+ TextFormatParseInfoTree root = rootBuilder.build();
+ try {
+ root.getNestedTree(OPTIONAL_NESTED_MESSAGE, 0);
+ fail("Did not detect unknown field");
+ } catch (IllegalArgumentException expected) {
+ // pass
+ }
+ }
+
+ public void testGetNestedTreesReturnsNoParseInfoTreesForUnknownField() {
+ rootBuilder.setLocation(REPEATED_INT32, LOC0);
+ TextFormatParseInfoTree root = rootBuilder.build();
+ assertTrue(root.getNestedTrees(OPTIONAL_NESTED_MESSAGE).isEmpty());
+ }
+
+ public void testGetNestedTreeThrowsIllegalArgumentExceptionForInvalidIndex() {
+ rootBuilder.setLocation(REPEATED_INT32, LOC0);
+ rootBuilder.getBuilderForSubMessageField(OPTIONAL_NESTED_MESSAGE);
+ TextFormatParseInfoTree root = rootBuilder.build();
+ try {
+ root.getNestedTree(OPTIONAL_NESTED_MESSAGE, 1);
+ fail("Submessage index that is too large not detected");
+ } catch (IllegalArgumentException expected) {
+ // pass
+ }
+ try {
+ rootBuilder.build().getNestedTree(OPTIONAL_NESTED_MESSAGE, -1);
+ fail("Invalid submessage index (-1) not detected");
+ } catch (IllegalArgumentException expected) {
+ // pass
+ }
+ }
+
+ public void testGetNestedTreesReturnsSingleTree() {
+ rootBuilder.getBuilderForSubMessageField(OPTIONAL_NESTED_MESSAGE);
+ TextFormatParseInfoTree root = rootBuilder.build();
+ assertEquals(1, root.getNestedTrees(OPTIONAL_NESTED_MESSAGE).size());
+ TextFormatParseInfoTree subtree = root.getNestedTrees(OPTIONAL_NESTED_MESSAGE).get(0);
+ assertNotNull(subtree);
+ }
+
+ public void testGetNestedTreesReturnsMultipleTrees() {
+ TextFormatParseInfoTree.Builder subtree1Builder =
+ rootBuilder.getBuilderForSubMessageField(REPEATED_NESTED_MESSAGE);
+ subtree1Builder.getBuilderForSubMessageField(FIELD_BB);
+ subtree1Builder.getBuilderForSubMessageField(FIELD_BB);
+ TextFormatParseInfoTree.Builder subtree2Builder =
+ rootBuilder.getBuilderForSubMessageField(REPEATED_NESTED_MESSAGE);
+ subtree2Builder.getBuilderForSubMessageField(FIELD_BB);
+ TextFormatParseInfoTree root = rootBuilder.build();
+ assertEquals(2, root.getNestedTrees(REPEATED_NESTED_MESSAGE).size());
+ assertEquals(
+ 2, root.getNestedTrees(REPEATED_NESTED_MESSAGE).get(0).getNestedTrees(FIELD_BB).size());
+ assertEquals(
+ 1, root.getNestedTrees(REPEATED_NESTED_MESSAGE).get(1).getNestedTrees(FIELD_BB).size());
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TextFormatParseLocationTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TextFormatParseLocationTest.java
new file mode 100644
index 0000000000..c42bfa6e71
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TextFormatParseLocationTest.java
@@ -0,0 +1,86 @@
+// 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 junit.framework.TestCase;
+
+/**
+ * Test @{link TextFormatParseLocation}.
+ */
+public class TextFormatParseLocationTest extends TestCase {
+
+ public void testCreateEmpty() {
+ TextFormatParseLocation location = TextFormatParseLocation.create(-1, -1);
+ assertEquals(TextFormatParseLocation.EMPTY, location);
+ }
+
+ public void testCreate() {
+ TextFormatParseLocation location = TextFormatParseLocation.create(2, 1);
+ assertEquals(2, location.getLine());
+ assertEquals(1, location.getColumn());
+ }
+
+ public void testCreateThrowsIllegalArgumentExceptionForInvalidIndex() {
+ try {
+ TextFormatParseLocation.create(-1, 0);
+ fail("Should throw IllegalArgumentException if line is less than 0");
+ } catch (IllegalArgumentException unused) {
+ // pass
+ }
+ try {
+ TextFormatParseLocation.create(0, -1);
+ fail("Should throw, column < 0");
+ } catch (IllegalArgumentException unused) {
+ // pass
+ }
+ }
+
+ public void testHashCode() {
+ TextFormatParseLocation loc0 = TextFormatParseLocation.create(2, 1);
+ TextFormatParseLocation loc1 = TextFormatParseLocation.create(2, 1);
+
+ assertEquals(loc0.hashCode(), loc1.hashCode());
+ assertEquals(
+ TextFormatParseLocation.EMPTY.hashCode(), TextFormatParseLocation.EMPTY.hashCode());
+ }
+
+ public void testEquals() {
+ TextFormatParseLocation loc0 = TextFormatParseLocation.create(2, 1);
+ TextFormatParseLocation loc1 = TextFormatParseLocation.create(1, 2);
+ TextFormatParseLocation loc2 = TextFormatParseLocation.create(2, 2);
+ TextFormatParseLocation loc3 = TextFormatParseLocation.create(2, 1);
+
+ assertEquals(loc0, loc3);
+ assertNotSame(loc0, loc1);
+ assertNotSame(loc0, loc2);
+ assertNotSame(loc1, loc2);
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TextFormatTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TextFormatTest.java
new file mode 100644
index 0000000000..6a91b02f03
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/TextFormatTest.java
@@ -0,0 +1,1153 @@
+// 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.Descriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+import com.google.protobuf.TextFormat.Parser.SingularOverwritePolicy;
+import protobuf_unittest.UnittestMset.TestMessageSetExtension1;
+import protobuf_unittest.UnittestMset.TestMessageSetExtension2;
+import protobuf_unittest.UnittestProto.OneString;
+import protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestAllTypes.NestedMessage;
+import protobuf_unittest.UnittestProto.TestEmptyMessage;
+import protobuf_unittest.UnittestProto.TestOneof2;
+import proto2_wireformat_unittest.UnittestMsetWireFormat.TestMessageSet;
+import java.io.StringReader;
+import java.util.List;
+import junit.framework.TestCase;
+
+/**
+ * Test case for {@link TextFormat}.
+ *
+ * TODO(wenboz): ExtensionTest and rest of text_format_unittest.cc.
+ *
+ * @author wenboz@google.com (Wenbo Zhu)
+ */
+public class TextFormatTest extends TestCase {
+
+ // A basic string with different escapable characters for testing.
+ private final static String kEscapeTestString =
+ "\"A string with ' characters \n and \r newlines and \t tabs and \001 "
+ + "slashes \\";
+
+ // A representation of the above string with all the characters escaped.
+ private final static String kEscapeTestStringEscaped =
+ "\\\"A string with \\' characters \\n and \\r newlines "
+ + "and \\t tabs and \\001 slashes \\\\";
+
+ private static String allFieldsSetText = TestUtil.readTextFromFile(
+ "text_format_unittest_data_oneof_implemented.txt");
+ private static String allExtensionsSetText = TestUtil.readTextFromFile(
+ "text_format_unittest_extensions_data.txt");
+
+ private static String exoticText =
+ "repeated_int32: -1\n" +
+ "repeated_int32: -2147483648\n" +
+ "repeated_int64: -1,\n" +
+ "repeated_int64: -9223372036854775808\n" +
+ "repeated_uint32: 4294967295\n" +
+ "repeated_uint32: 2147483648\n" +
+ "repeated_uint64: 18446744073709551615\n" +
+ "repeated_uint64: 9223372036854775808\n" +
+ "repeated_double: 123.0\n" +
+ "repeated_double: 123.5\n" +
+ "repeated_double: 0.125\n" +
+ "repeated_double: .125\n" +
+ "repeated_double: -.125\n" +
+ "repeated_double: 1.23E17\n" +
+ "repeated_double: 1.23E+17\n" +
+ "repeated_double: -1.23e-17\n" +
+ "repeated_double: .23e+17\n" +
+ "repeated_double: -.23E17\n" +
+ "repeated_double: 1.235E22\n" +
+ "repeated_double: 1.235E-18\n" +
+ "repeated_double: 123.456789\n" +
+ "repeated_double: Infinity\n" +
+ "repeated_double: -Infinity\n" +
+ "repeated_double: NaN\n" +
+ "repeated_string: \"\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\"" +
+ "\\341\\210\\264\"\n" +
+ "repeated_bytes: \"\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\"\\376\"\n";
+
+ private static String canonicalExoticText =
+ exoticText.replace(": .", ": 0.").replace(": -.", ": -0.") // short-form double
+ .replace("23e", "23E").replace("E+", "E").replace("0.23E17", "2.3E16").replace(",", "");
+
+ private String messageSetText =
+ "[protobuf_unittest.TestMessageSetExtension1] {\n" +
+ " i: 123\n" +
+ "}\n" +
+ "[protobuf_unittest.TestMessageSetExtension2] {\n" +
+ " str: \"foo\"\n" +
+ "}\n";
+
+ private String messageSetTextWithRepeatedExtension =
+ "[protobuf_unittest.TestMessageSetExtension1] {\n" +
+ " i: 123\n" +
+ "}\n" +
+ "[protobuf_unittest.TestMessageSetExtension1] {\n" +
+ " i: 456\n" +
+ "}\n";
+
+
+ private final TextFormat.Parser parserWithOverwriteForbidden =
+ TextFormat.Parser.newBuilder()
+ .setSingularOverwritePolicy(
+ SingularOverwritePolicy.FORBID_SINGULAR_OVERWRITES)
+ .build();
+
+ private final TextFormat.Parser defaultParser =
+ TextFormat.Parser.newBuilder().build();
+
+ /** Print TestAllTypes and compare with golden file. */
+ public void testPrintMessage() throws Exception {
+ String javaText = TextFormat.printToString(TestUtil.getAllSet());
+
+ // Java likes to add a trailing ".0" to floats and doubles. C printf
+ // (with %g format) does not. Our golden files are used for both
+ // C++ and Java TextFormat classes, so we need to conform.
+ javaText = javaText.replace(".0\n", "\n");
+
+ assertEquals(allFieldsSetText, javaText);
+ }
+
+ /** Print TestAllTypes as Builder and compare with golden file. */
+ public void testPrintMessageBuilder() throws Exception {
+ String javaText = TextFormat.printToString(TestUtil.getAllSetBuilder());
+
+ // Java likes to add a trailing ".0" to floats and doubles. C printf
+ // (with %g format) does not. Our golden files are used for both
+ // C++ and Java TextFormat classes, so we need to conform.
+ javaText = javaText.replace(".0\n", "\n");
+
+ assertEquals(allFieldsSetText, javaText);
+ }
+
+ /** Print TestAllExtensions and compare with golden file. */
+ public void testPrintExtensions() throws Exception {
+ String javaText = TextFormat.printToString(TestUtil.getAllExtensionsSet());
+
+ // Java likes to add a trailing ".0" to floats and doubles. C printf
+ // (with %g format) does not. Our golden files are used for both
+ // C++ and Java TextFormat classes, so we need to conform.
+ javaText = javaText.replace(".0\n", "\n");
+
+ assertEquals(allExtensionsSetText, javaText);
+ }
+
+ // Creates an example unknown field set.
+ private UnknownFieldSet makeUnknownFieldSet() {
+ return UnknownFieldSet.newBuilder()
+ .addField(5,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(1)
+ .addFixed32(2)
+ .addFixed64(3)
+ .addLengthDelimited(ByteString.copyFromUtf8("4"))
+ .addGroup(
+ UnknownFieldSet.newBuilder()
+ .addField(10,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(5)
+ .build())
+ .build())
+ .build())
+ .addField(8,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(1)
+ .addVarint(2)
+ .addVarint(3)
+ .build())
+ .addField(15,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(0xABCDEF1234567890L)
+ .addFixed32(0xABCD1234)
+ .addFixed64(0xABCDEF1234567890L)
+ .build())
+ .build();
+ }
+
+ public void testPrintUnknownFields() throws Exception {
+ // Test printing of unknown fields in a message.
+
+ TestEmptyMessage message =
+ TestEmptyMessage.newBuilder()
+ .setUnknownFields(makeUnknownFieldSet())
+ .build();
+
+ assertEquals(
+ "5: 1\n" +
+ "5: 0x00000002\n" +
+ "5: 0x0000000000000003\n" +
+ "5: \"4\"\n" +
+ "5 {\n" +
+ " 10: 5\n" +
+ "}\n" +
+ "8: 1\n" +
+ "8: 2\n" +
+ "8: 3\n" +
+ "15: 12379813812177893520\n" +
+ "15: 0xabcd1234\n" +
+ "15: 0xabcdef1234567890\n",
+ TextFormat.printToString(message));
+ }
+
+ public void testPrintField() throws Exception {
+ final FieldDescriptor dataField =
+ OneString.getDescriptor().findFieldByName("data");
+ assertEquals(
+ "data: \"test data\"\n",
+ TextFormat.printFieldToString(dataField, "test data"));
+
+ final FieldDescriptor optionalField =
+ TestAllTypes.getDescriptor().findFieldByName("optional_nested_message");
+ final Object value = NestedMessage.newBuilder().setBb(42).build();
+
+ assertEquals(
+ "optional_nested_message {\n bb: 42\n}\n",
+ TextFormat.printFieldToString(optionalField, value));
+ }
+
+ /**
+ * Helper to construct a ByteString from a String containing only 8-bit
+ * characters. The characters are converted directly to bytes, *not*
+ * encoded using UTF-8.
+ */
+ private ByteString bytes(String str) {
+ return ByteString.copyFrom(str.getBytes(Internal.ISO_8859_1));
+ }
+
+ /**
+ * Helper to construct a ByteString 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 ByteString bytes(int... bytesAsInts) {
+ byte[] bytes = new byte[bytesAsInts.length];
+ for (int i = 0; i < bytesAsInts.length; i++) {
+ bytes[i] = (byte) bytesAsInts[i];
+ }
+ return ByteString.copyFrom(bytes);
+ }
+
+ public void testPrintExotic() throws Exception {
+ Message message = TestAllTypes.newBuilder()
+ // Signed vs. unsigned numbers.
+ .addRepeatedInt32 (-1)
+ .addRepeatedUint32(-1)
+ .addRepeatedInt64 (-1)
+ .addRepeatedUint64(-1)
+
+ .addRepeatedInt32 (1 << 31)
+ .addRepeatedUint32(1 << 31)
+ .addRepeatedInt64 (1L << 63)
+ .addRepeatedUint64(1L << 63)
+
+ // Floats of various precisions and exponents.
+ .addRepeatedDouble(123)
+ .addRepeatedDouble(123.5)
+ .addRepeatedDouble(0.125)
+ .addRepeatedDouble(.125)
+ .addRepeatedDouble(-.125)
+ .addRepeatedDouble(123e15)
+ .addRepeatedDouble(123e15)
+ .addRepeatedDouble(-1.23e-17)
+ .addRepeatedDouble(.23e17)
+ .addRepeatedDouble(-23e15)
+ .addRepeatedDouble(123.5e20)
+ .addRepeatedDouble(123.5e-20)
+ .addRepeatedDouble(123.456789)
+ .addRepeatedDouble(Double.POSITIVE_INFINITY)
+ .addRepeatedDouble(Double.NEGATIVE_INFINITY)
+ .addRepeatedDouble(Double.NaN)
+
+ // Strings and bytes that needing escaping.
+ .addRepeatedString("\0\001\007\b\f\n\r\t\013\\\'\"\u1234")
+ .addRepeatedBytes(bytes("\0\001\007\b\f\n\r\t\013\\\'\"\u00fe"))
+ .build();
+
+ assertEquals(canonicalExoticText, message.toString());
+ }
+
+ public void testPrintMessageSet() throws Exception {
+ TestMessageSet messageSet =
+ TestMessageSet.newBuilder()
+ .setExtension(
+ TestMessageSetExtension1.messageSetExtension,
+ TestMessageSetExtension1.newBuilder().setI(123).build())
+ .setExtension(
+ TestMessageSetExtension2.messageSetExtension,
+ TestMessageSetExtension2.newBuilder().setStr("foo").build())
+ .build();
+
+ assertEquals(messageSetText, messageSet.toString());
+ }
+
+ // =================================================================
+
+ public void testParse() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge(allFieldsSetText, builder);
+ TestUtil.assertAllFieldsSet(builder.build());
+ }
+
+ public void testParseReader() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge(new StringReader(allFieldsSetText), builder);
+ TestUtil.assertAllFieldsSet(builder.build());
+ }
+
+ public void testParseExtensions() throws Exception {
+ TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
+ TextFormat.merge(allExtensionsSetText,
+ TestUtil.getExtensionRegistry(),
+ builder);
+ TestUtil.assertAllExtensionsSet(builder.build());
+ }
+
+ public void testParseCompatibility() throws Exception {
+ String original = "repeated_float: inf\n" +
+ "repeated_float: -inf\n" +
+ "repeated_float: nan\n" +
+ "repeated_float: inff\n" +
+ "repeated_float: -inff\n" +
+ "repeated_float: nanf\n" +
+ "repeated_float: 1.0f\n" +
+ "repeated_float: infinityf\n" +
+ "repeated_float: -Infinityf\n" +
+ "repeated_double: infinity\n" +
+ "repeated_double: -infinity\n" +
+ "repeated_double: nan\n";
+ String canonical = "repeated_float: Infinity\n" +
+ "repeated_float: -Infinity\n" +
+ "repeated_float: NaN\n" +
+ "repeated_float: Infinity\n" +
+ "repeated_float: -Infinity\n" +
+ "repeated_float: NaN\n" +
+ "repeated_float: 1.0\n" +
+ "repeated_float: Infinity\n" +
+ "repeated_float: -Infinity\n" +
+ "repeated_double: Infinity\n" +
+ "repeated_double: -Infinity\n" +
+ "repeated_double: NaN\n";
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge(original, builder);
+ assertEquals(canonical, builder.build().toString());
+ }
+
+ public void testParseExotic() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge(exoticText, builder);
+
+ // Too lazy to check things individually. Don't try to debug this
+ // if testPrintExotic() is failing.
+ assertEquals(canonicalExoticText, builder.build().toString());
+ }
+
+ public void testParseMessageSet() throws Exception {
+ ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance();
+ extensionRegistry.add(TestMessageSetExtension1.messageSetExtension);
+ extensionRegistry.add(TestMessageSetExtension2.messageSetExtension);
+
+ TestMessageSet.Builder builder = TestMessageSet.newBuilder();
+ TextFormat.merge(messageSetText, extensionRegistry, builder);
+ TestMessageSet messageSet = builder.build();
+
+ assertTrue(messageSet.hasExtension(
+ TestMessageSetExtension1.messageSetExtension));
+ assertEquals(123, messageSet.getExtension(
+ TestMessageSetExtension1.messageSetExtension).getI());
+ assertTrue(messageSet.hasExtension(
+ TestMessageSetExtension2.messageSetExtension));
+ assertEquals("foo", messageSet.getExtension(
+ TestMessageSetExtension2.messageSetExtension).getStr());
+
+ builder = TestMessageSet.newBuilder();
+ TextFormat.merge(messageSetTextWithRepeatedExtension, extensionRegistry,
+ builder);
+ messageSet = builder.build();
+ assertEquals(456, messageSet.getExtension(
+ TestMessageSetExtension1.messageSetExtension).getI());
+ }
+
+ public void testParseMessageSetWithOverwriteForbidden() throws Exception {
+ ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance();
+ extensionRegistry.add(TestMessageSetExtension1.messageSetExtension);
+ extensionRegistry.add(TestMessageSetExtension2.messageSetExtension);
+
+ TestMessageSet.Builder builder = TestMessageSet.newBuilder();
+ parserWithOverwriteForbidden.merge(
+ messageSetText, extensionRegistry, builder);
+ TestMessageSet messageSet = builder.build();
+ assertEquals(123, messageSet.getExtension(
+ TestMessageSetExtension1.messageSetExtension).getI());
+ assertEquals("foo", messageSet.getExtension(
+ TestMessageSetExtension2.messageSetExtension).getStr());
+
+ builder = TestMessageSet.newBuilder();
+ try {
+ parserWithOverwriteForbidden.merge(
+ messageSetTextWithRepeatedExtension, extensionRegistry, builder);
+ fail("expected parse exception");
+ } catch (TextFormat.ParseException e) {
+ assertEquals("6:1: Non-repeated field "
+ + "\"protobuf_unittest.TestMessageSetExtension1.message_set_extension\""
+ + " cannot be overwritten.",
+ e.getMessage());
+ }
+ }
+
+ public void testParseNumericEnum() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge("optional_nested_enum: 2", builder);
+ assertEquals(TestAllTypes.NestedEnum.BAR, builder.getOptionalNestedEnum());
+ }
+
+ public void testParseAngleBrackets() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge("OptionalGroup: < a: 1 >", builder);
+ assertTrue(builder.hasOptionalGroup());
+ assertEquals(1, builder.getOptionalGroup().getA());
+ }
+
+ public void testParseComment() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge(
+ "# this is a comment\n" +
+ "optional_int32: 1 # another comment\n" +
+ "optional_int64: 2\n" +
+ "# EOF comment", builder);
+ assertEquals(1, builder.getOptionalInt32());
+ assertEquals(2, builder.getOptionalInt64());
+ }
+
+ private void assertParseError(String error, String text) {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ try {
+ TextFormat.merge(text, TestUtil.getExtensionRegistry(), builder);
+ fail("Expected parse exception.");
+ } catch (TextFormat.ParseException e) {
+ assertEquals(error, e.getMessage());
+ }
+ }
+
+
+ private void assertParseErrorWithOverwriteForbidden(String error,
+ String text) {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ try {
+ parserWithOverwriteForbidden.merge(
+ text, TestUtil.getExtensionRegistry(), builder);
+ fail("Expected parse exception.");
+ } catch (TextFormat.ParseException e) {
+ assertEquals(error, e.getMessage());
+ }
+ }
+
+ private TestAllTypes assertParseSuccessWithOverwriteForbidden(
+ String text) throws TextFormat.ParseException {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ parserWithOverwriteForbidden.merge(
+ text, TestUtil.getExtensionRegistry(), builder);
+ return builder.build();
+ }
+
+ public void testParseErrors() throws Exception {
+ assertParseError(
+ "1:16: Expected \":\".",
+ "optional_int32 123");
+ assertParseError(
+ "1:23: Expected identifier. Found '?'",
+ "optional_nested_enum: ?");
+ assertParseError(
+ "1:18: Couldn't parse integer: Number must be positive: -1",
+ "optional_uint32: -1");
+ assertParseError(
+ "1:17: Couldn't parse integer: Number out of range for 32-bit signed " +
+ "integer: 82301481290849012385230157",
+ "optional_int32: 82301481290849012385230157");
+ assertParseError(
+ "1:16: Expected \"true\" or \"false\".",
+ "optional_bool: maybe");
+ assertParseError(
+ "1:16: Expected \"true\" or \"false\".",
+ "optional_bool: 2");
+ assertParseError(
+ "1:18: Expected string.",
+ "optional_string: 123");
+ assertParseError(
+ "1:18: String missing ending quote.",
+ "optional_string: \"ueoauaoe");
+ assertParseError(
+ "1:18: String missing ending quote.",
+ "optional_string: \"ueoauaoe\n" +
+ "optional_int32: 123");
+ assertParseError(
+ "1:18: Invalid escape sequence: '\\z'",
+ "optional_string: \"\\z\"");
+ assertParseError(
+ "1:18: String missing ending quote.",
+ "optional_string: \"ueoauaoe\n" +
+ "optional_int32: 123");
+ assertParseError(
+ "1:2: Input contains unknown fields and/or extensions:\n" +
+ "1:2:\tprotobuf_unittest.TestAllTypes.[nosuchext]",
+ "[nosuchext]: 123");
+ assertParseError(
+ "1:20: Extension \"protobuf_unittest.optional_int32_extension\" does " +
+ "not extend message type \"protobuf_unittest.TestAllTypes\".",
+ "[protobuf_unittest.optional_int32_extension]: 123");
+ assertParseError(
+ "1:1: Input contains unknown fields and/or extensions:\n" +
+ "1:1:\tprotobuf_unittest.TestAllTypes.nosuchfield",
+ "nosuchfield: 123");
+ assertParseError(
+ "1:21: Expected \">\".",
+ "OptionalGroup < a: 1");
+ assertParseError(
+ "1:23: Enum type \"protobuf_unittest.TestAllTypes.NestedEnum\" has no " +
+ "value named \"NO_SUCH_VALUE\".",
+ "optional_nested_enum: NO_SUCH_VALUE");
+ assertParseError(
+ "1:23: Enum type \"protobuf_unittest.TestAllTypes.NestedEnum\" has no " +
+ "value with number 123.",
+ "optional_nested_enum: 123");
+
+ // Delimiters must match.
+ assertParseError(
+ "1:22: Expected identifier. Found '}'",
+ "OptionalGroup < a: 1 }");
+ assertParseError(
+ "1:22: Expected identifier. Found '>'",
+ "OptionalGroup { a: 1 >");
+ }
+
+ // =================================================================
+
+ public void testEscape() throws Exception {
+ // Escape sequences.
+ assertEquals("\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\"\\177",
+ TextFormat.escapeBytes(bytes("\0\001\007\b\f\n\r\t\013\\\'\"\177")));
+ assertEquals("\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\"\\177",
+ TextFormat.escapeText("\0\001\007\b\f\n\r\t\013\\\'\"\177"));
+ assertEquals(bytes("\0\001\007\b\f\n\r\t\013\\\'\""),
+ TextFormat.unescapeBytes("\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\""));
+ assertEquals("\0\001\007\b\f\n\r\t\013\\\'\"",
+ TextFormat.unescapeText("\\000\\001\\a\\b\\f\\n\\r\\t\\v\\\\\\'\\\""));
+ assertEquals(kEscapeTestStringEscaped,
+ TextFormat.escapeText(kEscapeTestString));
+ assertEquals(kEscapeTestString,
+ TextFormat.unescapeText(kEscapeTestStringEscaped));
+
+ // Invariant
+ assertEquals("hello",
+ TextFormat.escapeBytes(bytes("hello")));
+ assertEquals("hello",
+ TextFormat.escapeText("hello"));
+ assertEquals(bytes("hello"),
+ TextFormat.unescapeBytes("hello"));
+ assertEquals("hello",
+ TextFormat.unescapeText("hello"));
+
+ // Unicode handling.
+ assertEquals("\\341\\210\\264", TextFormat.escapeText("\u1234"));
+ assertEquals("\\341\\210\\264",
+ TextFormat.escapeBytes(bytes(0xe1, 0x88, 0xb4)));
+ assertEquals("\u1234", TextFormat.unescapeText("\\341\\210\\264"));
+ assertEquals(bytes(0xe1, 0x88, 0xb4),
+ TextFormat.unescapeBytes("\\341\\210\\264"));
+ assertEquals("\u1234", TextFormat.unescapeText("\\xe1\\x88\\xb4"));
+ assertEquals(bytes(0xe1, 0x88, 0xb4),
+ TextFormat.unescapeBytes("\\xe1\\x88\\xb4"));
+
+ // Handling of strings with unescaped Unicode characters > 255.
+ final String zh = "\u9999\u6e2f\u4e0a\u6d77\ud84f\udf80\u8c50\u9280\u884c";
+ ByteString zhByteString = ByteString.copyFromUtf8(zh);
+ assertEquals(zhByteString, TextFormat.unescapeBytes(zh));
+
+ // Errors.
+ try {
+ TextFormat.unescapeText("\\x");
+ fail("Should have thrown an exception.");
+ } catch (TextFormat.InvalidEscapeSequenceException e) {
+ // success
+ }
+
+ try {
+ TextFormat.unescapeText("\\z");
+ fail("Should have thrown an exception.");
+ } catch (TextFormat.InvalidEscapeSequenceException e) {
+ // success
+ }
+
+ try {
+ TextFormat.unescapeText("\\");
+ fail("Should have thrown an exception.");
+ } catch (TextFormat.InvalidEscapeSequenceException e) {
+ // success
+ }
+ }
+
+ public void testParseInteger() throws Exception {
+ assertEquals( 0, TextFormat.parseInt32( "0"));
+ assertEquals( 1, TextFormat.parseInt32( "1"));
+ assertEquals( -1, TextFormat.parseInt32( "-1"));
+ assertEquals( 12345, TextFormat.parseInt32( "12345"));
+ assertEquals( -12345, TextFormat.parseInt32( "-12345"));
+ assertEquals( 2147483647, TextFormat.parseInt32( "2147483647"));
+ assertEquals(-2147483648, TextFormat.parseInt32("-2147483648"));
+
+ assertEquals( 0, TextFormat.parseUInt32( "0"));
+ assertEquals( 1, TextFormat.parseUInt32( "1"));
+ assertEquals( 12345, TextFormat.parseUInt32( "12345"));
+ assertEquals( 2147483647, TextFormat.parseUInt32("2147483647"));
+ assertEquals((int) 2147483648L, TextFormat.parseUInt32("2147483648"));
+ assertEquals((int) 4294967295L, TextFormat.parseUInt32("4294967295"));
+
+ assertEquals( 0L, TextFormat.parseInt64( "0"));
+ assertEquals( 1L, TextFormat.parseInt64( "1"));
+ assertEquals( -1L, TextFormat.parseInt64( "-1"));
+ assertEquals( 12345L, TextFormat.parseInt64( "12345"));
+ assertEquals( -12345L, TextFormat.parseInt64( "-12345"));
+ assertEquals( 2147483647L, TextFormat.parseInt64( "2147483647"));
+ assertEquals(-2147483648L, TextFormat.parseInt64("-2147483648"));
+ assertEquals( 4294967295L, TextFormat.parseInt64( "4294967295"));
+ assertEquals( 4294967296L, TextFormat.parseInt64( "4294967296"));
+ assertEquals(9223372036854775807L,
+ TextFormat.parseInt64("9223372036854775807"));
+ assertEquals(-9223372036854775808L,
+ TextFormat.parseInt64("-9223372036854775808"));
+
+ assertEquals( 0L, TextFormat.parseUInt64( "0"));
+ assertEquals( 1L, TextFormat.parseUInt64( "1"));
+ assertEquals( 12345L, TextFormat.parseUInt64( "12345"));
+ assertEquals( 2147483647L, TextFormat.parseUInt64( "2147483647"));
+ assertEquals( 4294967295L, TextFormat.parseUInt64( "4294967295"));
+ assertEquals( 4294967296L, TextFormat.parseUInt64( "4294967296"));
+ assertEquals(9223372036854775807L,
+ TextFormat.parseUInt64("9223372036854775807"));
+ assertEquals(-9223372036854775808L,
+ TextFormat.parseUInt64("9223372036854775808"));
+ assertEquals(-1L, TextFormat.parseUInt64("18446744073709551615"));
+
+ // Hex
+ assertEquals(0x1234abcd, TextFormat.parseInt32("0x1234abcd"));
+ assertEquals(-0x1234abcd, TextFormat.parseInt32("-0x1234abcd"));
+ assertEquals(-1, TextFormat.parseUInt64("0xffffffffffffffff"));
+ assertEquals(0x7fffffffffffffffL,
+ TextFormat.parseInt64("0x7fffffffffffffff"));
+
+ // Octal
+ assertEquals(01234567, TextFormat.parseInt32("01234567"));
+
+ // Out-of-range
+ try {
+ TextFormat.parseInt32("2147483648");
+ fail("Should have thrown an exception.");
+ } catch (NumberFormatException e) {
+ // success
+ }
+
+ try {
+ TextFormat.parseInt32("-2147483649");
+ fail("Should have thrown an exception.");
+ } catch (NumberFormatException e) {
+ // success
+ }
+
+ try {
+ TextFormat.parseUInt32("4294967296");
+ fail("Should have thrown an exception.");
+ } catch (NumberFormatException e) {
+ // success
+ }
+
+ try {
+ TextFormat.parseUInt32("-1");
+ fail("Should have thrown an exception.");
+ } catch (NumberFormatException e) {
+ // success
+ }
+
+ try {
+ TextFormat.parseInt64("9223372036854775808");
+ fail("Should have thrown an exception.");
+ } catch (NumberFormatException e) {
+ // success
+ }
+
+ try {
+ TextFormat.parseInt64("-9223372036854775809");
+ fail("Should have thrown an exception.");
+ } catch (NumberFormatException e) {
+ // success
+ }
+
+ try {
+ TextFormat.parseUInt64("18446744073709551616");
+ fail("Should have thrown an exception.");
+ } catch (NumberFormatException e) {
+ // success
+ }
+
+ try {
+ TextFormat.parseUInt64("-1");
+ fail("Should have thrown an exception.");
+ } catch (NumberFormatException e) {
+ // success
+ }
+
+ // Not a number.
+ try {
+ TextFormat.parseInt32("abcd");
+ fail("Should have thrown an exception.");
+ } catch (NumberFormatException e) {
+ // success
+ }
+ }
+
+ public void testParseString() throws Exception {
+ final String zh = "\u9999\u6e2f\u4e0a\u6d77\ud84f\udf80\u8c50\u9280\u884c";
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge("optional_string: \"" + zh + "\"", builder);
+ assertEquals(zh, builder.getOptionalString());
+ }
+
+ public void testParseLongString() throws Exception {
+ String longText =
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890" +
+ "123456789012345678901234567890123456789012345678901234567890";
+
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge("optional_string: \"" + longText + "\"", builder);
+ assertEquals(longText, builder.getOptionalString());
+ }
+
+ public void testParseBoolean() throws Exception {
+ String goodText =
+ "repeated_bool: t repeated_bool : 0\n" +
+ "repeated_bool :f repeated_bool:1\n" +
+ "repeated_bool: False repeated_bool: True";
+ String goodTextCanonical =
+ "repeated_bool: true\n" +
+ "repeated_bool: false\n" +
+ "repeated_bool: false\n" +
+ "repeated_bool: true\n" +
+ "repeated_bool: false\n" +
+ "repeated_bool: true\n";
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge(goodText, builder);
+ assertEquals(goodTextCanonical, builder.build().toString());
+
+ try {
+ TestAllTypes.Builder badBuilder = TestAllTypes.newBuilder();
+ TextFormat.merge("optional_bool:2", badBuilder);
+ fail("Should have thrown an exception.");
+ } catch (TextFormat.ParseException e) {
+ // success
+ }
+ try {
+ TestAllTypes.Builder badBuilder = TestAllTypes.newBuilder();
+ TextFormat.merge("optional_bool: foo", badBuilder);
+ fail("Should have thrown an exception.");
+ } catch (TextFormat.ParseException e) {
+ // success
+ }
+ }
+
+ public void testParseAdjacentStringLiterals() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge("optional_string: \"foo\" 'corge' \"grault\"", builder);
+ assertEquals("foocorgegrault", builder.getOptionalString());
+ }
+
+ public void testPrintFieldValue() throws Exception {
+ assertPrintFieldValue("\"Hello\"", "Hello", "repeated_string");
+ assertPrintFieldValue("123.0", 123f, "repeated_float");
+ assertPrintFieldValue("123.0", 123d, "repeated_double");
+ assertPrintFieldValue("123", 123, "repeated_int32");
+ assertPrintFieldValue("123", 123L, "repeated_int64");
+ assertPrintFieldValue("true", true, "repeated_bool");
+ assertPrintFieldValue("4294967295", 0xFFFFFFFF, "repeated_uint32");
+ assertPrintFieldValue("18446744073709551615", 0xFFFFFFFFFFFFFFFFL,
+ "repeated_uint64");
+ assertPrintFieldValue("\"\\001\\002\\003\"",
+ ByteString.copyFrom(new byte[] {1, 2, 3}), "repeated_bytes");
+ }
+
+ private void assertPrintFieldValue(String expect, Object value,
+ String fieldName) throws Exception {
+ StringBuilder sb = new StringBuilder();
+ TextFormat.printFieldValue(
+ TestAllTypes.getDescriptor().findFieldByName(fieldName),
+ value, sb);
+ assertEquals(expect, sb.toString());
+ }
+
+ public void testShortDebugString() {
+ assertEquals("optional_nested_message { bb: 42 } repeated_int32: 1"
+ + " repeated_uint32: 2",
+ TextFormat.shortDebugString(TestAllTypes.newBuilder()
+ .addRepeatedInt32(1)
+ .addRepeatedUint32(2)
+ .setOptionalNestedMessage(
+ NestedMessage.newBuilder().setBb(42).build())
+ .build()));
+ }
+
+ public void testShortDebugString_field() {
+ final FieldDescriptor dataField =
+ OneString.getDescriptor().findFieldByName("data");
+ assertEquals(
+ "data: \"test data\"",
+ TextFormat.shortDebugString(dataField, "test data"));
+
+ final FieldDescriptor optionalField =
+ TestAllTypes.getDescriptor().findFieldByName("optional_nested_message");
+ final Object value = NestedMessage.newBuilder().setBb(42).build();
+
+ assertEquals(
+ "optional_nested_message { bb: 42 }",
+ TextFormat.shortDebugString(optionalField, value));
+ }
+
+ public void testShortDebugString_unknown() {
+ assertEquals("5: 1 5: 0x00000002 5: 0x0000000000000003 5: \"4\" 5 { 10: 5 }"
+ + " 8: 1 8: 2 8: 3 15: 12379813812177893520 15: 0xabcd1234 15:"
+ + " 0xabcdef1234567890",
+ TextFormat.shortDebugString(makeUnknownFieldSet()));
+ }
+
+ public void testPrintToUnicodeString() throws Exception {
+ assertEquals(
+ "optional_string: \"abc\u3042efg\"\n" +
+ "optional_bytes: \"\\343\\201\\202\"\n" +
+ "repeated_string: \"\u3093XYZ\"\n",
+ TextFormat.printToUnicodeString(TestAllTypes.newBuilder()
+ .setOptionalString("abc\u3042efg")
+ .setOptionalBytes(bytes(0xe3, 0x81, 0x82))
+ .addRepeatedString("\u3093XYZ")
+ .build()));
+
+ // Double quotes and backslashes should be escaped
+ assertEquals(
+ "optional_string: \"a\\\\bc\\\"ef\\\"g\"\n",
+ TextFormat.printToUnicodeString(TestAllTypes.newBuilder()
+ .setOptionalString("a\\bc\"ef\"g")
+ .build()));
+
+ // Test escaping roundtrip
+ TestAllTypes message = TestAllTypes.newBuilder()
+ .setOptionalString("a\\bc\\\"ef\"g")
+ .build();
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge(TextFormat.printToUnicodeString(message), builder);
+ assertEquals(message.getOptionalString(), builder.getOptionalString());
+ }
+
+ public void testPrintToUnicodeStringWithNewlines() throws Exception {
+ // No newlines at start and end
+ assertEquals("optional_string: \"test newlines\\n\\nin\\nstring\"\n",
+ TextFormat.printToUnicodeString(TestAllTypes.newBuilder()
+ .setOptionalString("test newlines\n\nin\nstring")
+ .build()));
+
+ // Newlines at start and end
+ assertEquals("optional_string: \"\\ntest\\nnewlines\\n\\nin\\nstring\\n\"\n",
+ TextFormat.printToUnicodeString(TestAllTypes.newBuilder()
+ .setOptionalString("\ntest\nnewlines\n\nin\nstring\n")
+ .build()));
+
+ // Strings with 0, 1 and 2 newlines.
+ assertEquals("optional_string: \"\"\n",
+ TextFormat.printToUnicodeString(TestAllTypes.newBuilder()
+ .setOptionalString("")
+ .build()));
+ assertEquals("optional_string: \"\\n\"\n",
+ TextFormat.printToUnicodeString(TestAllTypes.newBuilder()
+ .setOptionalString("\n")
+ .build()));
+ assertEquals("optional_string: \"\\n\\n\"\n",
+ TextFormat.printToUnicodeString(TestAllTypes.newBuilder()
+ .setOptionalString("\n\n")
+ .build()));
+
+ // Test escaping roundtrip
+ TestAllTypes message = TestAllTypes.newBuilder()
+ .setOptionalString("\ntest\nnewlines\n\nin\nstring\n")
+ .build();
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ TextFormat.merge(TextFormat.printToUnicodeString(message), builder);
+ assertEquals(message.getOptionalString(), builder.getOptionalString());
+ }
+
+ public void testPrintToUnicodeString_unknown() {
+ assertEquals(
+ "1: \"\\343\\201\\202\"\n",
+ TextFormat.printToUnicodeString(UnknownFieldSet.newBuilder()
+ .addField(1,
+ UnknownFieldSet.Field.newBuilder()
+ .addLengthDelimited(bytes(0xe3, 0x81, 0x82)).build())
+ .build()));
+ }
+
+
+ public void testParseNonRepeatedFields() throws Exception {
+ assertParseSuccessWithOverwriteForbidden(
+ "repeated_int32: 1\n" +
+ "repeated_int32: 2\n");
+ assertParseSuccessWithOverwriteForbidden(
+ "RepeatedGroup { a: 1 }\n" +
+ "RepeatedGroup { a: 2 }\n");
+ assertParseSuccessWithOverwriteForbidden(
+ "repeated_nested_message { bb: 1 }\n" +
+ "repeated_nested_message { bb: 2 }\n");
+ assertParseErrorWithOverwriteForbidden(
+ "3:17: Non-repeated field " +
+ "\"protobuf_unittest.TestAllTypes.optional_int32\" " +
+ "cannot be overwritten.",
+ "optional_int32: 1\n" +
+ "optional_bool: true\n" +
+ "optional_int32: 1\n");
+ assertParseErrorWithOverwriteForbidden(
+ "2:17: Non-repeated field " +
+ "\"protobuf_unittest.TestAllTypes.optionalgroup\" " +
+ "cannot be overwritten.",
+ "OptionalGroup { a: 1 }\n" +
+ "OptionalGroup { }\n");
+ assertParseErrorWithOverwriteForbidden(
+ "2:33: Non-repeated field " +
+ "\"protobuf_unittest.TestAllTypes.optional_nested_message\" " +
+ "cannot be overwritten.",
+ "optional_nested_message { }\n" +
+ "optional_nested_message { bb: 3 }\n");
+ assertParseErrorWithOverwriteForbidden(
+ "2:16: Non-repeated field " +
+ "\"protobuf_unittest.TestAllTypes.default_int32\" " +
+ "cannot be overwritten.",
+ "default_int32: 41\n" + // the default value
+ "default_int32: 41\n");
+ assertParseErrorWithOverwriteForbidden(
+ "2:17: Non-repeated field " +
+ "\"protobuf_unittest.TestAllTypes.default_string\" " +
+ "cannot be overwritten.",
+ "default_string: \"zxcv\"\n" +
+ "default_string: \"asdf\"\n");
+ }
+
+ public void testParseShortRepeatedFormOfRepeatedFields() throws Exception {
+ assertParseSuccessWithOverwriteForbidden("repeated_foreign_enum: [FOREIGN_FOO, FOREIGN_BAR]");
+ assertParseSuccessWithOverwriteForbidden("repeated_int32: [ 1, 2 ]\n");
+ assertParseSuccessWithOverwriteForbidden("RepeatedGroup [{ a: 1 },{ a: 2 }]\n");
+ 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");
+ }
+
+ // =======================================================================
+ // test oneof
+
+ public void testOneofTextFormat() throws Exception {
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ TestUtil.setOneof(builder);
+ TestOneof2 message = builder.build();
+ TestOneof2.Builder dest = TestOneof2.newBuilder();
+ TextFormat.merge(TextFormat.printToUnicodeString(message), dest);
+ TestUtil.assertOneofSet(dest.build());
+ }
+
+ public void testOneofOverwriteForbidden() throws Exception {
+ String input = "foo_string: \"stringvalue\" foo_int: 123";
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ try {
+ parserWithOverwriteForbidden.merge(
+ input, TestUtil.getExtensionRegistry(), builder);
+ fail("Expected parse exception.");
+ } catch (TextFormat.ParseException e) {
+ assertEquals("1:36: Field \"protobuf_unittest.TestOneof2.foo_int\""
+ + " is specified along with field \"protobuf_unittest.TestOneof2.foo_string\","
+ + " another member of oneof \"foo\".", e.getMessage());
+ }
+ }
+
+ public void testOneofOverwriteAllowed() throws Exception {
+ String input = "foo_string: \"stringvalue\" foo_int: 123";
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ defaultParser.merge(input, TestUtil.getExtensionRegistry(), builder);
+ // Only the last value sticks.
+ TestOneof2 oneof = builder.build();
+ assertFalse(oneof.hasFooString());
+ assertTrue(oneof.hasFooInt());
+ }
+
+ // =======================================================================
+ // test location information
+
+ public void testParseInfoTreeBuilding() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+
+ Descriptor descriptor = TestAllTypes.getDescriptor();
+ TextFormatParseInfoTree.Builder treeBuilder = TextFormatParseInfoTree.builder();
+ // Set to allow unknown fields
+ TextFormat.Parser parser =
+ TextFormat.Parser.newBuilder()
+ .setParseInfoTreeBuilder(treeBuilder)
+ .build();
+
+ final String stringData =
+ "optional_int32: 1\n"
+ + "optional_int64: 2\n"
+ + " optional_double: 2.4\n"
+ + "repeated_int32: 5\n"
+ + "repeated_int32: 10\n"
+ + "optional_nested_message <\n"
+ + " bb: 78\n"
+ + ">\n"
+ + "repeated_nested_message <\n"
+ + " bb: 79\n"
+ + ">\n"
+ + "repeated_nested_message <\n"
+ + " bb: 80\n"
+ + ">";
+
+ parser.merge(stringData, builder);
+ TextFormatParseInfoTree tree = treeBuilder.build();
+
+ // Verify that the tree has the correct positions.
+ assertLocation(tree, descriptor, "optional_int32", 0, 0, 0);
+ assertLocation(tree, descriptor, "optional_int64", 0, 1, 0);
+ assertLocation(tree, descriptor, "optional_double", 0, 2, 2);
+
+ assertLocation(tree, descriptor, "repeated_int32", 0, 3, 0);
+ assertLocation(tree, descriptor, "repeated_int32", 1, 4, 0);
+
+ assertLocation(tree, descriptor, "optional_nested_message", 0, 5, 0);
+ assertLocation(tree, descriptor, "repeated_nested_message", 0, 8, 0);
+ assertLocation(tree, descriptor, "repeated_nested_message", 1, 11, 0);
+
+ // Check for fields not set. For an invalid field, the location returned should be -1, -1.
+ assertLocation(tree, descriptor, "repeated_int64", 0, -1, -1);
+ assertLocation(tree, descriptor, "repeated_int32", 6, -1, -1);
+
+ // Verify inside the nested message.
+ FieldDescriptor nestedField = descriptor.findFieldByName("optional_nested_message");
+
+ TextFormatParseInfoTree nestedTree = tree.getNestedTrees(nestedField).get(0);
+ assertLocation(nestedTree, nestedField.getMessageType(), "bb", 0, 6, 2);
+
+ // Verify inside another nested message.
+ nestedField = descriptor.findFieldByName("repeated_nested_message");
+ nestedTree = tree.getNestedTrees(nestedField).get(0);
+ assertLocation(nestedTree, nestedField.getMessageType(), "bb", 0, 9, 2);
+
+ nestedTree = tree.getNestedTrees(nestedField).get(1);
+ assertLocation(nestedTree, nestedField.getMessageType(), "bb", 0, 12, 2);
+
+ // Verify a NULL tree for an unknown nested field.
+ try {
+ tree.getNestedTree(nestedField, 2);
+ fail("unknown nested field should throw");
+ } catch (IllegalArgumentException unused) {
+ // pass
+ }
+ }
+
+ private void assertLocation(
+ TextFormatParseInfoTree tree,
+ final Descriptor descriptor,
+ final String fieldName,
+ int index,
+ int line,
+ int column) {
+ List<TextFormatParseLocation> locs = tree.getLocations(descriptor.findFieldByName(fieldName));
+ if (index < locs.size()) {
+ TextFormatParseLocation location = locs.get(index);
+ TextFormatParseLocation expected = TextFormatParseLocation.create(line, column);
+ assertEquals(expected, location);
+ } else if (line != -1 && column != -1) {
+ fail(
+ String.format(
+ "Tree/descriptor/fieldname did not contain index %d, line %d column %d expected",
+ index,
+ line,
+ column));
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnknownEnumValueTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnknownEnumValueTest.java
new file mode 100644
index 0000000000..8f45976fb4
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnknownEnumValueTest.java
@@ -0,0 +1,255 @@
+// 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.Descriptor;
+import com.google.protobuf.Descriptors.EnumDescriptor;
+import com.google.protobuf.Descriptors.EnumValueDescriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+import com.google.protobuf.FieldPresenceTestProto.TestAllTypes;
+import com.google.protobuf.TextFormat.ParseException;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for protos that keep unknown enum values rather than discard
+ * them as unknown fields.
+ */
+public class UnknownEnumValueTest extends TestCase {
+ public void testUnknownEnumValues() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ builder.setOptionalNestedEnumValue(4321);
+ builder.addRepeatedNestedEnumValue(5432);
+ builder.addPackedNestedEnumValue(6543);
+ TestAllTypes message = builder.build();
+ assertEquals(4321, message.getOptionalNestedEnumValue());
+ assertEquals(5432, message.getRepeatedNestedEnumValue(0));
+ assertEquals(5432, message.getRepeatedNestedEnumValueList().get(0).intValue());
+ assertEquals(6543, message.getPackedNestedEnumValue(0));
+ // Returns UNRECOGNIZED if an enum type is requested.
+ assertEquals(TestAllTypes.NestedEnum.UNRECOGNIZED, message.getOptionalNestedEnum());
+ assertEquals(TestAllTypes.NestedEnum.UNRECOGNIZED, message.getRepeatedNestedEnum(0));
+ assertEquals(TestAllTypes.NestedEnum.UNRECOGNIZED, message.getRepeatedNestedEnumList().get(0));
+ assertEquals(TestAllTypes.NestedEnum.UNRECOGNIZED, message.getPackedNestedEnum(0));
+
+ // Test serialization and parsing.
+ ByteString data = message.toByteString();
+ message = TestAllTypes.parseFrom(data);
+ assertEquals(4321, message.getOptionalNestedEnumValue());
+ assertEquals(5432, message.getRepeatedNestedEnumValue(0));
+ assertEquals(5432, message.getRepeatedNestedEnumValueList().get(0).intValue());
+ assertEquals(6543, message.getPackedNestedEnumValue(0));
+ // Returns UNRECOGNIZED if an enum type is requested.
+ assertEquals(TestAllTypes.NestedEnum.UNRECOGNIZED, message.getOptionalNestedEnum());
+ assertEquals(TestAllTypes.NestedEnum.UNRECOGNIZED, message.getRepeatedNestedEnum(0));
+ assertEquals(TestAllTypes.NestedEnum.UNRECOGNIZED, message.getRepeatedNestedEnumList().get(0));
+ assertEquals(TestAllTypes.NestedEnum.UNRECOGNIZED, message.getPackedNestedEnum(0));
+
+ // Test toBuilder().
+ builder = message.toBuilder();
+ assertEquals(4321, builder.getOptionalNestedEnumValue());
+ assertEquals(5432, builder.getRepeatedNestedEnumValue(0));
+ assertEquals(5432, builder.getRepeatedNestedEnumValueList().get(0).intValue());
+ assertEquals(6543, builder.getPackedNestedEnumValue(0));
+ // Returns UNRECOGNIZED if an enum type is requested.
+ assertEquals(TestAllTypes.NestedEnum.UNRECOGNIZED, builder.getOptionalNestedEnum());
+ assertEquals(TestAllTypes.NestedEnum.UNRECOGNIZED, builder.getRepeatedNestedEnum(0));
+ assertEquals(TestAllTypes.NestedEnum.UNRECOGNIZED, builder.getRepeatedNestedEnumList().get(0));
+ assertEquals(TestAllTypes.NestedEnum.UNRECOGNIZED, builder.getPackedNestedEnum(0));
+
+ // Test mergeFrom().
+ builder = TestAllTypes.newBuilder().mergeFrom(message);
+ assertEquals(4321, builder.getOptionalNestedEnumValue());
+ assertEquals(5432, builder.getRepeatedNestedEnumValue(0));
+ assertEquals(5432, builder.getRepeatedNestedEnumValueList().get(0).intValue());
+ assertEquals(6543, builder.getPackedNestedEnumValue(0));
+ // Returns UNRECOGNIZED if an enum type is requested.
+ assertEquals(TestAllTypes.NestedEnum.UNRECOGNIZED, builder.getOptionalNestedEnum());
+ assertEquals(TestAllTypes.NestedEnum.UNRECOGNIZED, builder.getRepeatedNestedEnum(0));
+ assertEquals(TestAllTypes.NestedEnum.UNRECOGNIZED, builder.getRepeatedNestedEnumList().get(0));
+ assertEquals(TestAllTypes.NestedEnum.UNRECOGNIZED, builder.getPackedNestedEnum(0));
+
+ // Test equals() and hashCode()
+ TestAllTypes sameMessage = builder.build();
+ assertEquals(message, sameMessage);
+ assertEquals(message.hashCode(), sameMessage.hashCode());
+
+ // Getting the numeric value of UNRECOGNIZED will throw an exception.
+ try {
+ TestAllTypes.NestedEnum.UNRECOGNIZED.getNumber();
+ fail("Exception is expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+
+ // Setting an enum field to an UNRECOGNIZED value will throw an exception.
+ try {
+ builder.setOptionalNestedEnum(builder.getOptionalNestedEnum());
+ fail("Exception is expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+ try {
+ builder.addRepeatedNestedEnum(builder.getOptionalNestedEnum());
+ fail("Exception is expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+ }
+
+ public void testUnknownEnumValueInReflectionApi() throws Exception {
+ Descriptor descriptor = TestAllTypes.getDescriptor();
+ FieldDescriptor optionalNestedEnumField = descriptor.findFieldByName("optional_nested_enum");
+ FieldDescriptor repeatedNestedEnumField = descriptor.findFieldByName("repeated_nested_enum");
+ FieldDescriptor packedNestedEnumField = descriptor.findFieldByName("packed_nested_enum");
+ EnumDescriptor enumType = TestAllTypes.NestedEnum.getDescriptor();
+
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ builder.setField(optionalNestedEnumField,
+ enumType.findValueByNumberCreatingIfUnknown(4321));
+ builder.addRepeatedField(repeatedNestedEnumField,
+ enumType.findValueByNumberCreatingIfUnknown(5432));
+ builder.addRepeatedField(packedNestedEnumField,
+ enumType.findValueByNumberCreatingIfUnknown(6543));
+ TestAllTypes message = builder.build();
+
+ // Getters will return unknown enum values as EnumValueDescriptor.
+ EnumValueDescriptor unknown4321 =
+ (EnumValueDescriptor) message.getField(optionalNestedEnumField);
+ EnumValueDescriptor unknown5432 =
+ (EnumValueDescriptor) message.getRepeatedField(repeatedNestedEnumField, 0);
+ EnumValueDescriptor unknown6543 =
+ (EnumValueDescriptor) message.getRepeatedField(packedNestedEnumField, 0);
+ assertEquals(4321, unknown4321.getNumber());
+ assertEquals(5432, unknown5432.getNumber());
+ assertEquals(6543, unknown6543.getNumber());
+
+ // Unknown EnumValueDescriptor will map to UNRECOGNIZED.
+ assertEquals(
+ TestAllTypes.NestedEnum.valueOf(unknown4321),
+ TestAllTypes.NestedEnum.UNRECOGNIZED);
+ assertEquals(
+ TestAllTypes.NestedEnum.valueOf(unknown5432),
+ TestAllTypes.NestedEnum.UNRECOGNIZED);
+ assertEquals(
+ TestAllTypes.NestedEnum.valueOf(unknown6543),
+ TestAllTypes.NestedEnum.UNRECOGNIZED);
+
+ // Setters also accept unknown EnumValueDescriptor.
+ builder.setField(optionalNestedEnumField, unknown6543);
+ builder.setRepeatedField(repeatedNestedEnumField, 0, unknown4321);
+ builder.setRepeatedField(packedNestedEnumField, 0, unknown5432);
+ message = builder.build();
+ // Like other descriptors, unknown EnumValueDescriptor can be compared by
+ // object identity.
+ assertTrue(unknown6543 == message.getField(optionalNestedEnumField));
+ assertTrue(unknown4321 == message.getRepeatedField(repeatedNestedEnumField, 0));
+ assertTrue(unknown5432 == message.getRepeatedField(packedNestedEnumField, 0));
+ }
+
+ public void testUnknownEnumValueWithDynamicMessage() throws Exception {
+ Descriptor descriptor = TestAllTypes.getDescriptor();
+ FieldDescriptor optionalNestedEnumField = descriptor.findFieldByName("optional_nested_enum");
+ FieldDescriptor repeatedNestedEnumField = descriptor.findFieldByName("repeated_nested_enum");
+ FieldDescriptor packedNestedEnumField = descriptor.findFieldByName("packed_nested_enum");
+ EnumDescriptor enumType = TestAllTypes.NestedEnum.getDescriptor();
+
+ Message dynamicMessageDefaultInstance = DynamicMessage.getDefaultInstance(descriptor);
+
+ Message.Builder builder = dynamicMessageDefaultInstance.newBuilderForType();
+ builder.setField(optionalNestedEnumField,
+ enumType.findValueByNumberCreatingIfUnknown(4321));
+ builder.addRepeatedField(repeatedNestedEnumField,
+ enumType.findValueByNumberCreatingIfUnknown(5432));
+ builder.addRepeatedField(packedNestedEnumField,
+ enumType.findValueByNumberCreatingIfUnknown(6543));
+ Message message = builder.build();
+ assertEquals(4321,
+ ((EnumValueDescriptor) message.getField(optionalNestedEnumField)).getNumber());
+ assertEquals(5432,
+ ((EnumValueDescriptor) message.getRepeatedField(repeatedNestedEnumField, 0)).getNumber());
+ assertEquals(6543,
+ ((EnumValueDescriptor) message.getRepeatedField(packedNestedEnumField, 0)).getNumber());
+
+ // Test reflection based serialization/parsing implementation.
+ ByteString data = message.toByteString();
+ message = dynamicMessageDefaultInstance
+ .newBuilderForType()
+ .mergeFrom(data)
+ .build();
+ assertEquals(4321,
+ ((EnumValueDescriptor) message.getField(optionalNestedEnumField)).getNumber());
+ assertEquals(5432,
+ ((EnumValueDescriptor) message.getRepeatedField(repeatedNestedEnumField, 0)).getNumber());
+ assertEquals(6543,
+ ((EnumValueDescriptor) message.getRepeatedField(packedNestedEnumField, 0)).getNumber());
+
+ // Test reflection based equals()/hashCode().
+ builder = dynamicMessageDefaultInstance.newBuilderForType();
+ builder.setField(optionalNestedEnumField,
+ enumType.findValueByNumberCreatingIfUnknown(4321));
+ builder.addRepeatedField(repeatedNestedEnumField,
+ enumType.findValueByNumberCreatingIfUnknown(5432));
+ builder.addRepeatedField(packedNestedEnumField,
+ enumType.findValueByNumberCreatingIfUnknown(6543));
+ Message sameMessage = builder.build();
+ assertEquals(message, sameMessage);
+ assertEquals(message.hashCode(), sameMessage.hashCode());
+ builder.setField(optionalNestedEnumField,
+ enumType.findValueByNumberCreatingIfUnknown(0));
+ Message differentMessage = builder.build();
+ assertFalse(message.equals(differentMessage));
+ }
+
+ public void testUnknownEnumValuesInTextFormat() {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ builder.setOptionalNestedEnumValue(4321);
+ builder.addRepeatedNestedEnumValue(5432);
+ builder.addPackedNestedEnumValue(6543);
+ TestAllTypes message = builder.build();
+
+ // We can print a message with unknown enum values.
+ String textData = TextFormat.printToString(message);
+ assertEquals(
+ "optional_nested_enum: UNKNOWN_ENUM_VALUE_NestedEnum_4321\n"
+ + "repeated_nested_enum: UNKNOWN_ENUM_VALUE_NestedEnum_5432\n"
+ + "packed_nested_enum: UNKNOWN_ENUM_VALUE_NestedEnum_6543\n", textData);
+
+ // Parsing unknown enum values will fail just like parsing other kinds of
+ // unknown fields.
+ try {
+ TextFormat.merge(textData, builder);
+ fail();
+ } catch (ParseException e) {
+ // expected.
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java
new file mode 100644
index 0000000000..f8cb0aabbc
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnknownFieldSetLiteTest.java
@@ -0,0 +1,334 @@
+// 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.UnittestLite.TestAllExtensionsLite;
+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 java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import junit.framework.TestCase;
+
+/**
+ * Tests for {@link UnknownFieldSetLite}.
+ *
+ * @author dweis@google.com (Daniel Weis)
+ */
+public class UnknownFieldSetLiteTest extends TestCase {
+
+ public void testDefaultInstance() {
+ UnknownFieldSetLite unknownFields = UnknownFieldSetLite.getDefaultInstance();
+
+ assertEquals(0, unknownFields.getSerializedSize());
+ assertEquals(ByteString.EMPTY, toByteString(unknownFields));
+ }
+
+ public void testEmptyInstance() {
+ UnknownFieldSetLite instance = UnknownFieldSetLite.newInstance();
+
+ assertEquals(0, instance.getSerializedSize());
+ assertEquals(ByteString.EMPTY, toByteString(instance));
+ assertEquals(UnknownFieldSetLite.getDefaultInstance(), instance);
+ }
+
+ public void testMergeFieldFrom() throws IOException {
+ Foo foo = Foo.newBuilder()
+ .setValue(2)
+ .build();
+
+ CodedInputStream input = CodedInputStream.newInstance(foo.toByteArray());
+
+ UnknownFieldSetLite instance = UnknownFieldSetLite.newInstance();
+ instance.mergeFieldFrom(input.readTag(), input);
+
+ assertEquals(foo.toByteString(), toByteString(instance));
+ }
+
+ public void testSerializedSize() throws IOException {
+ Foo foo = Foo.newBuilder()
+ .setValue(2)
+ .build();
+
+ CodedInputStream input = CodedInputStream.newInstance(foo.toByteArray());
+
+ UnknownFieldSetLite instance = UnknownFieldSetLite.newInstance();
+ instance.mergeFieldFrom(input.readTag(), input);
+
+ assertEquals(foo.toByteString().size(), instance.getSerializedSize());
+ }
+
+ public void testMergeVarintField() throws IOException {
+ UnknownFieldSetLite unknownFields = UnknownFieldSetLite.newInstance();
+ unknownFields.mergeVarintField(10, 2);
+
+ CodedInputStream input =
+ CodedInputStream.newInstance(toByteString(unknownFields).toByteArray());
+
+ int tag = input.readTag();
+ assertEquals(10, WireFormat.getTagFieldNumber(tag));
+ assertEquals(WireFormat.WIRETYPE_VARINT, WireFormat.getTagWireType(tag));
+ assertEquals(2, input.readUInt64());
+ assertTrue(input.isAtEnd());
+ }
+
+ public void testMergeVarintField_negative() throws IOException {
+ UnknownFieldSetLite builder = UnknownFieldSetLite.newInstance();
+ builder.mergeVarintField(10, -6);
+
+ CodedInputStream input =
+ CodedInputStream.newInstance(toByteString(builder).toByteArray());
+
+ int tag = input.readTag();
+ assertEquals(10, WireFormat.getTagFieldNumber(tag));
+ assertEquals(WireFormat.WIRETYPE_VARINT, WireFormat.getTagWireType(tag));
+ assertEquals(-6, input.readUInt64());
+ assertTrue(input.isAtEnd());
+ }
+
+ public void testEqualsAndHashCode() {
+ UnknownFieldSetLite unknownFields1 = UnknownFieldSetLite.newInstance();
+ unknownFields1.mergeVarintField(10, 2);
+
+ UnknownFieldSetLite unknownFields2 = UnknownFieldSetLite.newInstance();
+ unknownFields2.mergeVarintField(10, 2);
+
+ assertEquals(unknownFields1, unknownFields2);
+ assertEquals(unknownFields1.hashCode(), unknownFields2.hashCode());
+ assertFalse(unknownFields1.equals(UnknownFieldSetLite.getDefaultInstance()));
+ assertFalse(unknownFields1.hashCode() == UnknownFieldSetLite.getDefaultInstance().hashCode());
+ }
+
+ public void testMutableCopyOf() throws IOException {
+ UnknownFieldSetLite unknownFields = UnknownFieldSetLite.newInstance();
+ unknownFields.mergeVarintField(10, 2);
+ unknownFields = UnknownFieldSetLite.mutableCopyOf(unknownFields, unknownFields);
+ unknownFields.checkMutable();
+
+ CodedInputStream input =
+ CodedInputStream.newInstance(toByteString(unknownFields).toByteArray());
+
+ int tag = input.readTag();
+ assertEquals(10, WireFormat.getTagFieldNumber(tag));
+ assertEquals(WireFormat.WIRETYPE_VARINT, WireFormat.getTagWireType(tag));
+ assertEquals(2, input.readUInt64());
+ assertFalse(input.isAtEnd());
+ input.readTag();
+ assertEquals(10, WireFormat.getTagFieldNumber(tag));
+ assertEquals(WireFormat.WIRETYPE_VARINT, WireFormat.getTagWireType(tag));
+ assertEquals(2, input.readUInt64());
+ assertTrue(input.isAtEnd());
+ }
+
+ public void testMutableCopyOf_empty() {
+ UnknownFieldSetLite unknownFields = UnknownFieldSetLite.mutableCopyOf(
+ UnknownFieldSetLite.getDefaultInstance(), UnknownFieldSetLite.getDefaultInstance());
+ unknownFields.checkMutable();
+
+ assertEquals(0, unknownFields.getSerializedSize());
+ assertEquals(ByteString.EMPTY, toByteString(unknownFields));
+ }
+
+ public void testRoundTrips() throws InvalidProtocolBufferException {
+ Foo foo = Foo.newBuilder()
+ .setValue(1)
+ .setExtension(Bar.fooExt, Bar.newBuilder()
+ .setName("name")
+ .build())
+ .setExtension(LiteEqualsAndHash.varint, 22)
+ .setExtension(LiteEqualsAndHash.fixed32, 44)
+ .setExtension(LiteEqualsAndHash.fixed64, 66L)
+ .setExtension(LiteEqualsAndHash.myGroup, LiteEqualsAndHash.MyGroup.newBuilder()
+ .setGroupValue("value")
+ .build())
+ .build();
+
+ Foo copy = Foo.parseFrom(foo.toByteArray());
+
+ assertEquals(foo.getSerializedSize(), copy.getSerializedSize());
+ assertFalse(foo.equals(copy));
+
+ Foo secondCopy = Foo.parseFrom(foo.toByteArray());
+ assertEquals(copy, secondCopy);
+
+ ExtensionRegistryLite extensionRegistry = ExtensionRegistryLite.newInstance();
+ LiteEqualsAndHash.registerAllExtensions(extensionRegistry);
+ Foo copyOfCopy = Foo.parseFrom(copy.toByteArray(), extensionRegistry);
+
+ assertEquals(foo, copyOfCopy);
+ }
+
+ public void testMalformedBytes() throws Exception {
+ try {
+ Foo.parseFrom("this is a malformed protocol buffer".getBytes(Internal.UTF_8));
+ fail();
+ } catch (InvalidProtocolBufferException e) {
+ // Expected.
+ }
+ }
+
+ public void testMissingStartGroupTag() throws IOException {
+ ByteString.Output byteStringOutput = ByteString.newOutput();
+ CodedOutputStream output = CodedOutputStream.newInstance(byteStringOutput);
+ output.writeGroupNoTag(Foo.newBuilder().setValue(11).build());
+ output.writeTag(100, WireFormat.WIRETYPE_END_GROUP);
+ output.flush();
+
+ try {
+ Foo.parseFrom(byteStringOutput.toByteString());
+ fail();
+ } catch (InvalidProtocolBufferException e) {
+ // Expected.
+ }
+ }
+
+ public void testMissingEndGroupTag() throws IOException {
+ ByteString.Output byteStringOutput = ByteString.newOutput();
+ CodedOutputStream output = CodedOutputStream.newInstance(byteStringOutput);
+ output.writeTag(100, WireFormat.WIRETYPE_START_GROUP);
+ output.writeGroupNoTag(Foo.newBuilder().setValue(11).build());
+ output.flush();
+
+ try {
+ Foo.parseFrom(byteStringOutput.toByteString());
+ fail();
+ } catch (InvalidProtocolBufferException e) {
+ // Expected.
+ }
+ }
+
+ public void testMismatchingGroupTags() throws IOException {
+ ByteString.Output byteStringOutput = ByteString.newOutput();
+ CodedOutputStream output = CodedOutputStream.newInstance(byteStringOutput);
+ output.writeTag(100, WireFormat.WIRETYPE_START_GROUP);
+ output.writeGroupNoTag(Foo.newBuilder().setValue(11).build());
+ output.writeTag(101, WireFormat.WIRETYPE_END_GROUP);
+ output.flush();
+
+ try {
+ Foo.parseFrom(byteStringOutput.toByteString());
+ fail();
+ } catch (InvalidProtocolBufferException e) {
+ // Expected.
+ }
+ }
+
+ public void testTruncatedInput() {
+ Foo foo = Foo.newBuilder()
+ .setValue(1)
+ .setExtension(Bar.fooExt, Bar.newBuilder()
+ .setName("name")
+ .build())
+ .setExtension(LiteEqualsAndHash.varint, 22)
+ .setExtension(LiteEqualsAndHash.myGroup, LiteEqualsAndHash.MyGroup.newBuilder()
+ .setGroupValue("value")
+ .build())
+ .build();
+
+ try {
+ Foo.parseFrom(foo.toByteString().substring(0, foo.toByteString().size() - 10));
+ fail();
+ } catch (InvalidProtocolBufferException e) {
+ // Expected.
+ }
+ }
+
+ public void testMakeImmutable() throws Exception {
+ UnknownFieldSetLite unknownFields = UnknownFieldSetLite.newInstance();
+ unknownFields.makeImmutable();
+
+ try {
+ unknownFields.mergeVarintField(1, 1);
+ fail();
+ } catch (UnsupportedOperationException expected) {}
+
+ try {
+ unknownFields.mergeLengthDelimitedField(2, ByteString.copyFromUtf8("hello"));
+ fail();
+ } catch (UnsupportedOperationException expected) {}
+
+ try {
+ unknownFields.mergeFieldFrom(1, CodedInputStream.newInstance(new byte[0]));
+ fail();
+ } catch (UnsupportedOperationException expected) {}
+ }
+
+ public void testEndToEnd() throws Exception {
+ TestAllTypesLite testAllTypes = TestAllTypesLite.getDefaultInstance();
+ try {
+ testAllTypes.unknownFields.checkMutable();
+ fail();
+ } catch (UnsupportedOperationException expected) {}
+
+ testAllTypes = TestAllTypesLite.parseFrom(new byte[0]);
+ try {
+ testAllTypes.unknownFields.checkMutable();
+ fail();
+ } catch (UnsupportedOperationException expected) {}
+
+ testAllTypes = TestAllTypesLite.newBuilder().build();
+ try {
+ testAllTypes.unknownFields.checkMutable();
+ fail();
+ } catch (UnsupportedOperationException expected) {}
+
+ testAllTypes = TestAllTypesLite.newBuilder()
+ .setDefaultBool(true)
+ .build();
+ try {
+ testAllTypes.unknownFields.checkMutable();
+ fail();
+ } catch (UnsupportedOperationException expected) {}
+
+ TestAllExtensionsLite testAllExtensions = TestAllExtensionsLite.newBuilder()
+ .mergeFrom(TestAllExtensionsLite.newBuilder()
+ .setExtension(UnittestLite.optionalInt32ExtensionLite, 2)
+ .build().toByteArray())
+ .build();
+ try {
+ testAllExtensions.unknownFields.checkMutable();
+ fail();
+ } catch (UnsupportedOperationException expected) {}
+ }
+
+ private ByteString toByteString(UnknownFieldSetLite unknownFields) {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ CodedOutputStream output = CodedOutputStream.newInstance(byteArrayOutputStream);
+ try {
+ unknownFields.writeTo(output);
+ output.flush();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return ByteString.copyFrom(byteArrayOutputStream.toByteArray());
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java
new file mode 100644
index 0000000000..f81e90b459
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java
@@ -0,0 +1,652 @@
+// 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 protobuf_unittest.UnittestProto;
+import protobuf_unittest.UnittestProto.ForeignEnum;
+import protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestEmptyMessage;
+import protobuf_unittest.UnittestProto.TestEmptyMessageWithExtensions;
+import protobuf_unittest.UnittestProto.TestPackedExtensions;
+import protobuf_unittest.UnittestProto.TestPackedTypes;
+import java.util.Arrays;
+import java.util.Map;
+import junit.framework.TestCase;
+
+/**
+ * Tests related to unknown field handling.
+ *
+ * @author kenton@google.com (Kenton Varda)
+ */
+public class UnknownFieldSetTest extends TestCase {
+ @Override
+ public void setUp() throws Exception {
+ descriptor = TestAllTypes.getDescriptor();
+ allFields = TestUtil.getAllSet();
+ allFieldsData = allFields.toByteString();
+ emptyMessage = TestEmptyMessage.parseFrom(allFieldsData);
+ unknownFields = emptyMessage.getUnknownFields();
+ }
+
+ UnknownFieldSet.Field getField(String name) {
+ Descriptors.FieldDescriptor field = descriptor.findFieldByName(name);
+ assertNotNull(field);
+ return unknownFields.getField(field.getNumber());
+ }
+
+ // Constructs a protocol buffer which contains fields with all the same
+ // numbers as allFieldsData except that each field is some other wire
+ // type.
+ ByteString getBizarroData() throws Exception {
+ UnknownFieldSet.Builder bizarroFields = UnknownFieldSet.newBuilder();
+
+ UnknownFieldSet.Field varintField =
+ UnknownFieldSet.Field.newBuilder().addVarint(1).build();
+ UnknownFieldSet.Field fixed32Field =
+ UnknownFieldSet.Field.newBuilder().addFixed32(1).build();
+
+ for (Map.Entry<Integer, UnknownFieldSet.Field> entry :
+ unknownFields.asMap().entrySet()) {
+ if (entry.getValue().getVarintList().isEmpty()) {
+ // Original field is not a varint, so use a varint.
+ bizarroFields.addField(entry.getKey(), varintField);
+ } else {
+ // Original field *is* a varint, so use something else.
+ bizarroFields.addField(entry.getKey(), fixed32Field);
+ }
+ }
+
+ return bizarroFields.build().toByteString();
+ }
+
+ Descriptors.Descriptor descriptor;
+ TestAllTypes allFields;
+ ByteString allFieldsData;
+
+ // An empty message that has been parsed from allFieldsData. So, it has
+ // unknown fields of every type.
+ TestEmptyMessage emptyMessage;
+ UnknownFieldSet unknownFields;
+
+ // =================================================================
+
+ public void testVarint() throws Exception {
+ UnknownFieldSet.Field field = getField("optional_int32");
+ assertEquals(1, field.getVarintList().size());
+ assertEquals(allFields.getOptionalInt32(),
+ (long) field.getVarintList().get(0));
+ }
+
+ public void testFixed32() throws Exception {
+ UnknownFieldSet.Field field = getField("optional_fixed32");
+ assertEquals(1, field.getFixed32List().size());
+ assertEquals(allFields.getOptionalFixed32(),
+ (int) field.getFixed32List().get(0));
+ }
+
+ public void testFixed64() throws Exception {
+ UnknownFieldSet.Field field = getField("optional_fixed64");
+ assertEquals(1, field.getFixed64List().size());
+ assertEquals(allFields.getOptionalFixed64(),
+ (long) field.getFixed64List().get(0));
+ }
+
+ public void testLengthDelimited() throws Exception {
+ UnknownFieldSet.Field field = getField("optional_bytes");
+ assertEquals(1, field.getLengthDelimitedList().size());
+ assertEquals(allFields.getOptionalBytes(),
+ field.getLengthDelimitedList().get(0));
+ }
+
+ public void testGroup() throws Exception {
+ Descriptors.FieldDescriptor nestedFieldDescriptor =
+ TestAllTypes.OptionalGroup.getDescriptor().findFieldByName("a");
+ assertNotNull(nestedFieldDescriptor);
+
+ UnknownFieldSet.Field field = getField("optionalgroup");
+ assertEquals(1, field.getGroupList().size());
+
+ UnknownFieldSet group = field.getGroupList().get(0);
+ assertEquals(1, group.asMap().size());
+ assertTrue(group.hasField(nestedFieldDescriptor.getNumber()));
+
+ UnknownFieldSet.Field nestedField =
+ group.getField(nestedFieldDescriptor.getNumber());
+ assertEquals(1, nestedField.getVarintList().size());
+ assertEquals(allFields.getOptionalGroup().getA(),
+ (long) nestedField.getVarintList().get(0));
+ }
+
+ public void testSerialize() throws Exception {
+ // Check that serializing the UnknownFieldSet produces the original data
+ // again.
+ ByteString data = emptyMessage.toByteString();
+ assertEquals(allFieldsData, data);
+ }
+
+ public void testCopyFrom() throws Exception {
+ TestEmptyMessage message =
+ TestEmptyMessage.newBuilder().mergeFrom(emptyMessage).build();
+
+ assertEquals(emptyMessage.toString(), message.toString());
+ }
+
+ public void testMergeFrom() throws Exception {
+ TestEmptyMessage source =
+ TestEmptyMessage.newBuilder()
+ .setUnknownFields(
+ UnknownFieldSet.newBuilder()
+ .addField(2,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(2).build())
+ .addField(3,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(4).build())
+ .build())
+ .build();
+ TestEmptyMessage destination =
+ TestEmptyMessage.newBuilder()
+ .setUnknownFields(
+ UnknownFieldSet.newBuilder()
+ .addField(1,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(1).build())
+ .addField(3,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(3).build())
+ .build())
+ .mergeFrom(source)
+ .build();
+
+ assertEquals(
+ "1: 1\n" +
+ "2: 2\n" +
+ "3: 3\n" +
+ "3: 4\n",
+ destination.toString());
+ }
+
+ public void testClear() throws Exception {
+ UnknownFieldSet fields =
+ UnknownFieldSet.newBuilder().mergeFrom(unknownFields).clear().build();
+ assertTrue(fields.asMap().isEmpty());
+ }
+
+ public void testClearMessage() throws Exception {
+ TestEmptyMessage message =
+ TestEmptyMessage.newBuilder().mergeFrom(emptyMessage).clear().build();
+ assertEquals(0, message.getSerializedSize());
+ }
+
+ public void testClearField() throws Exception {
+ int fieldNumber = unknownFields.asMap().keySet().iterator().next();
+ UnknownFieldSet fields =
+ UnknownFieldSet.newBuilder().mergeFrom(unknownFields).clearField(fieldNumber).build();
+ assertFalse(fields.hasField(fieldNumber));
+ }
+
+ public void testParseKnownAndUnknown() throws Exception {
+ // Test mixing known and unknown fields when parsing.
+
+ UnknownFieldSet fields =
+ UnknownFieldSet.newBuilder(unknownFields)
+ .addField(123456,
+ UnknownFieldSet.Field.newBuilder().addVarint(654321).build())
+ .build();
+
+ ByteString data = fields.toByteString();
+ TestAllTypes destination = TestAllTypes.parseFrom(data);
+
+ TestUtil.assertAllFieldsSet(destination);
+ assertEquals(1, destination.getUnknownFields().asMap().size());
+
+ UnknownFieldSet.Field field =
+ destination.getUnknownFields().getField(123456);
+ assertEquals(1, field.getVarintList().size());
+ assertEquals(654321, (long) field.getVarintList().get(0));
+ }
+
+ public void testWrongTypeTreatedAsUnknown() throws Exception {
+ // Test that fields of the wrong wire type are treated like unknown fields
+ // when parsing.
+
+ ByteString bizarroData = getBizarroData();
+ TestAllTypes allTypesMessage = TestAllTypes.parseFrom(bizarroData);
+ TestEmptyMessage emptyMessage = TestEmptyMessage.parseFrom(bizarroData);
+
+ // All fields should have been interpreted as unknown, so the debug strings
+ // should be the same.
+ assertEquals(emptyMessage.toString(), allTypesMessage.toString());
+ }
+
+ public void testUnknownExtensions() throws Exception {
+ // Make sure fields are properly parsed to the UnknownFieldSet even when
+ // they are declared as extension numbers.
+
+ TestEmptyMessageWithExtensions message =
+ TestEmptyMessageWithExtensions.parseFrom(allFieldsData);
+
+ assertEquals(unknownFields.asMap().size(),
+ message.getUnknownFields().asMap().size());
+ assertEquals(allFieldsData, message.toByteString());
+ }
+
+ public void testWrongExtensionTypeTreatedAsUnknown() throws Exception {
+ // Test that fields of the wrong wire type are treated like unknown fields
+ // when parsing extensions.
+
+ ByteString bizarroData = getBizarroData();
+ TestAllExtensions allExtensionsMessage =
+ TestAllExtensions.parseFrom(bizarroData);
+ TestEmptyMessage emptyMessage = TestEmptyMessage.parseFrom(bizarroData);
+
+ // All fields should have been interpreted as unknown, so the debug strings
+ // should be the same.
+ assertEquals(emptyMessage.toString(),
+ allExtensionsMessage.toString());
+ }
+
+ public void testParseUnknownEnumValue() throws Exception {
+ Descriptors.FieldDescriptor singularField =
+ TestAllTypes.getDescriptor().findFieldByName("optional_nested_enum");
+ Descriptors.FieldDescriptor repeatedField =
+ TestAllTypes.getDescriptor().findFieldByName("repeated_nested_enum");
+ assertNotNull(singularField);
+ assertNotNull(repeatedField);
+
+ ByteString data =
+ UnknownFieldSet.newBuilder()
+ .addField(singularField.getNumber(),
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(TestAllTypes.NestedEnum.BAR.getNumber())
+ .addVarint(5) // not valid
+ .build())
+ .addField(repeatedField.getNumber(),
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(TestAllTypes.NestedEnum.FOO.getNumber())
+ .addVarint(4) // not valid
+ .addVarint(TestAllTypes.NestedEnum.BAZ.getNumber())
+ .addVarint(6) // not valid
+ .build())
+ .build()
+ .toByteString();
+
+ {
+ TestAllTypes message = TestAllTypes.parseFrom(data);
+ assertEquals(TestAllTypes.NestedEnum.BAR,
+ message.getOptionalNestedEnum());
+ assertEquals(
+ Arrays.asList(TestAllTypes.NestedEnum.FOO, TestAllTypes.NestedEnum.BAZ),
+ message.getRepeatedNestedEnumList());
+ assertEquals(Arrays.asList(5L),
+ message.getUnknownFields()
+ .getField(singularField.getNumber())
+ .getVarintList());
+ assertEquals(Arrays.asList(4L, 6L),
+ message.getUnknownFields()
+ .getField(repeatedField.getNumber())
+ .getVarintList());
+ }
+
+ {
+ TestAllExtensions message =
+ TestAllExtensions.parseFrom(data, TestUtil.getExtensionRegistry());
+ assertEquals(TestAllTypes.NestedEnum.BAR,
+ message.getExtension(UnittestProto.optionalNestedEnumExtension));
+ assertEquals(
+ Arrays.asList(TestAllTypes.NestedEnum.FOO, TestAllTypes.NestedEnum.BAZ),
+ message.getExtension(UnittestProto.repeatedNestedEnumExtension));
+ assertEquals(Arrays.asList(5L),
+ message.getUnknownFields()
+ .getField(singularField.getNumber())
+ .getVarintList());
+ assertEquals(Arrays.asList(4L, 6L),
+ message.getUnknownFields()
+ .getField(repeatedField.getNumber())
+ .getVarintList());
+ }
+ }
+
+ public void testLargeVarint() throws Exception {
+ ByteString data =
+ UnknownFieldSet.newBuilder()
+ .addField(1,
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(0x7FFFFFFFFFFFFFFFL)
+ .build())
+ .build()
+ .toByteString();
+ UnknownFieldSet parsed = UnknownFieldSet.parseFrom(data);
+ UnknownFieldSet.Field field = parsed.getField(1);
+ assertEquals(1, field.getVarintList().size());
+ assertEquals(0x7FFFFFFFFFFFFFFFL, (long)field.getVarintList().get(0));
+ }
+
+ public void testEqualsAndHashCode() {
+ UnknownFieldSet.Field fixed32Field =
+ UnknownFieldSet.Field.newBuilder()
+ .addFixed32(1)
+ .build();
+ UnknownFieldSet.Field fixed64Field =
+ UnknownFieldSet.Field.newBuilder()
+ .addFixed64(1)
+ .build();
+ UnknownFieldSet.Field varIntField =
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(1)
+ .build();
+ UnknownFieldSet.Field lengthDelimitedField =
+ UnknownFieldSet.Field.newBuilder()
+ .addLengthDelimited(ByteString.EMPTY)
+ .build();
+ UnknownFieldSet.Field groupField =
+ UnknownFieldSet.Field.newBuilder()
+ .addGroup(unknownFields)
+ .build();
+
+ UnknownFieldSet a =
+ UnknownFieldSet.newBuilder()
+ .addField(1, fixed32Field)
+ .build();
+ UnknownFieldSet b =
+ UnknownFieldSet.newBuilder()
+ .addField(1, fixed64Field)
+ .build();
+ UnknownFieldSet c =
+ UnknownFieldSet.newBuilder()
+ .addField(1, varIntField)
+ .build();
+ UnknownFieldSet d =
+ UnknownFieldSet.newBuilder()
+ .addField(1, lengthDelimitedField)
+ .build();
+ UnknownFieldSet e =
+ UnknownFieldSet.newBuilder()
+ .addField(1, groupField)
+ .build();
+
+ checkEqualsIsConsistent(a);
+ checkEqualsIsConsistent(b);
+ checkEqualsIsConsistent(c);
+ checkEqualsIsConsistent(d);
+ checkEqualsIsConsistent(e);
+
+ checkNotEqual(a, b);
+ checkNotEqual(a, c);
+ checkNotEqual(a, d);
+ checkNotEqual(a, e);
+ checkNotEqual(b, c);
+ checkNotEqual(b, d);
+ checkNotEqual(b, e);
+ checkNotEqual(c, d);
+ checkNotEqual(c, e);
+ checkNotEqual(d, e);
+ }
+
+ /**
+ * Asserts that the given field sets are not equal and have different
+ * hash codes.
+ *
+ * @warning It's valid for non-equal objects to have the same hash code, so
+ * this test is stricter than it needs to be. However, this should happen
+ * relatively rarely.
+ */
+ private void checkNotEqual(UnknownFieldSet s1, UnknownFieldSet s2) {
+ String equalsError = String.format("%s should not be equal to %s", s1, s2);
+ assertFalse(equalsError, s1.equals(s2));
+ assertFalse(equalsError, s2.equals(s1));
+
+ assertFalse(
+ String.format("%s should have a different hash code from %s", s1, s2),
+ s1.hashCode() == s2.hashCode());
+ }
+
+ /**
+ * Asserts that the given field sets are equal and have identical hash codes.
+ */
+ private void checkEqualsIsConsistent(UnknownFieldSet set) {
+ // Object should be equal to itself.
+ assertEquals(set, set);
+
+ // Object should be equal to a copy of itself.
+ UnknownFieldSet copy = UnknownFieldSet.newBuilder(set).build();
+ assertEquals(set, copy);
+ assertEquals(copy, set);
+ assertEquals(set.hashCode(), copy.hashCode());
+ }
+
+ // =================================================================
+
+ public void testSerializeLite() throws Exception {
+ UnittestLite.TestEmptyMessageLite emptyMessageLite =
+ UnittestLite.TestEmptyMessageLite.parseFrom(allFieldsData);
+ assertEquals(allFieldsData.size(), emptyMessageLite.getSerializedSize());
+ ByteString data = emptyMessageLite.toByteString();
+ TestAllTypes message = TestAllTypes.parseFrom(data);
+ TestUtil.assertAllFieldsSet(message);
+ assertEquals(allFieldsData, data);
+ }
+
+ public void testAllExtensionsLite() throws Exception {
+ TestAllExtensions allExtensions = TestUtil.getAllExtensionsSet();
+ ByteString allExtensionsData = allExtensions.toByteString();
+ UnittestLite.TestEmptyMessageLite emptyMessageLite =
+ UnittestLite.TestEmptyMessageLite.parser().parseFrom(allExtensionsData);
+ ByteString data = emptyMessageLite.toByteString();
+ TestAllExtensions message =
+ TestAllExtensions.parseFrom(data, TestUtil.getExtensionRegistry());
+ TestUtil.assertAllExtensionsSet(message);
+ assertEquals(allExtensionsData, data);
+ }
+
+ public void testAllPackedFieldsLite() throws Exception {
+ TestPackedTypes allPackedFields = TestUtil.getPackedSet();
+ ByteString allPackedData = allPackedFields.toByteString();
+ UnittestLite.TestEmptyMessageLite emptyMessageLite =
+ UnittestLite.TestEmptyMessageLite.parseFrom(allPackedData);
+ ByteString data = emptyMessageLite.toByteString();
+ TestPackedTypes message =
+ TestPackedTypes.parseFrom(data, TestUtil.getExtensionRegistry());
+ TestUtil.assertPackedFieldsSet(message);
+ assertEquals(allPackedData, data);
+ }
+
+ public void testAllPackedExtensionsLite() throws Exception {
+ TestPackedExtensions allPackedExtensions = TestUtil.getPackedExtensionsSet();
+ ByteString allPackedExtensionsData = allPackedExtensions.toByteString();
+ UnittestLite.TestEmptyMessageLite emptyMessageLite =
+ UnittestLite.TestEmptyMessageLite.parseFrom(allPackedExtensionsData);
+ ByteString data = emptyMessageLite.toByteString();
+ TestPackedExtensions message =
+ TestPackedExtensions.parseFrom(data, TestUtil.getExtensionRegistry());
+ TestUtil.assertPackedExtensionsSet(message);
+ assertEquals(allPackedExtensionsData, data);
+ }
+
+ public void testCopyFromLite() throws Exception {
+ UnittestLite.TestEmptyMessageLite emptyMessageLite =
+ UnittestLite.TestEmptyMessageLite.parseFrom(allFieldsData);
+ UnittestLite.TestEmptyMessageLite emptyMessageLite2 =
+ UnittestLite.TestEmptyMessageLite.newBuilder()
+ .mergeFrom(emptyMessageLite).build();
+ assertEquals(emptyMessageLite.toByteString(), emptyMessageLite2.toByteString());
+ }
+
+ public void testMergeFromLite() throws Exception {
+ TestAllTypes message1 = TestAllTypes.newBuilder()
+ .setOptionalInt32(1)
+ .setOptionalString("foo")
+ .addRepeatedString("bar")
+ .setOptionalNestedEnum(TestAllTypes.NestedEnum.BAZ)
+ .build();
+
+ TestAllTypes message2 = TestAllTypes.newBuilder()
+ .setOptionalInt64(2)
+ .setOptionalString("baz")
+ .addRepeatedString("qux")
+ .setOptionalForeignEnum(ForeignEnum.FOREIGN_BAZ)
+ .build();
+
+ ByteString data1 = message1.toByteString();
+ UnittestLite.TestEmptyMessageLite emptyMessageLite1 =
+ UnittestLite.TestEmptyMessageLite.parseFrom(data1);
+ ByteString data2 = message2.toByteString();
+ UnittestLite.TestEmptyMessageLite emptyMessageLite2 =
+ UnittestLite.TestEmptyMessageLite.parseFrom(data2);
+
+ message1 = TestAllTypes.newBuilder(message1).mergeFrom(message2).build();
+ emptyMessageLite1 = UnittestLite.TestEmptyMessageLite.newBuilder(emptyMessageLite1)
+ .mergeFrom(emptyMessageLite2).build();
+
+ data1 = emptyMessageLite1.toByteString();
+ message2 = TestAllTypes.parseFrom(data1);
+
+ assertEquals(message1, message2);
+ }
+
+ public void testWrongTypeTreatedAsUnknownLite() throws Exception {
+ // Test that fields of the wrong wire type are treated like unknown fields
+ // when parsing.
+
+ ByteString bizarroData = getBizarroData();
+ TestAllTypes allTypesMessage = TestAllTypes.parseFrom(bizarroData);
+ UnittestLite.TestEmptyMessageLite emptyMessageLite =
+ UnittestLite.TestEmptyMessageLite.parseFrom(bizarroData);
+ ByteString data = emptyMessageLite.toByteString();
+ TestAllTypes allTypesMessage2 = TestAllTypes.parseFrom(data);
+
+ assertEquals(allTypesMessage.toString(), allTypesMessage2.toString());
+ }
+
+ public void testUnknownExtensionsLite() throws Exception {
+ // Make sure fields are properly parsed to the UnknownFieldSet even when
+ // they are declared as extension numbers.
+
+ UnittestLite.TestEmptyMessageWithExtensionsLite message =
+ UnittestLite.TestEmptyMessageWithExtensionsLite.parseFrom(allFieldsData);
+
+ assertEquals(allFieldsData, message.toByteString());
+ }
+
+ public void testWrongExtensionTypeTreatedAsUnknownLite() throws Exception {
+ // Test that fields of the wrong wire type are treated like unknown fields
+ // when parsing extensions.
+
+ ByteString bizarroData = getBizarroData();
+ TestAllExtensions allExtensionsMessage =
+ TestAllExtensions.parseFrom(bizarroData);
+ UnittestLite.TestEmptyMessageLite emptyMessageLite =
+ UnittestLite.TestEmptyMessageLite.parseFrom(bizarroData);
+
+ // All fields should have been interpreted as unknown, so the byte strings
+ // should be the same.
+ assertEquals(emptyMessageLite.toByteString(),
+ allExtensionsMessage.toByteString());
+ }
+
+ public void testParseUnknownEnumValueLite() throws Exception {
+ Descriptors.FieldDescriptor singularField =
+ TestAllTypes.getDescriptor().findFieldByName("optional_nested_enum");
+ Descriptors.FieldDescriptor repeatedField =
+ TestAllTypes.getDescriptor().findFieldByName("repeated_nested_enum");
+ assertNotNull(singularField);
+ assertNotNull(repeatedField);
+
+ ByteString data =
+ UnknownFieldSet.newBuilder()
+ .addField(singularField.getNumber(),
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(TestAllTypes.NestedEnum.BAR.getNumber())
+ .addVarint(5) // not valid
+ .build())
+ .addField(repeatedField.getNumber(),
+ UnknownFieldSet.Field.newBuilder()
+ .addVarint(TestAllTypes.NestedEnum.FOO.getNumber())
+ .addVarint(4) // not valid
+ .addVarint(TestAllTypes.NestedEnum.BAZ.getNumber())
+ .addVarint(6) // not valid
+ .build())
+ .build()
+ .toByteString();
+
+ UnittestLite.TestEmptyMessageLite emptyMessageLite =
+ UnittestLite.TestEmptyMessageLite.parseFrom(data);
+ data = emptyMessageLite.toByteString();
+
+ {
+ TestAllTypes message = TestAllTypes.parseFrom(data);
+ assertEquals(TestAllTypes.NestedEnum.BAR,
+ message.getOptionalNestedEnum());
+ assertEquals(
+ Arrays.asList(TestAllTypes.NestedEnum.FOO, TestAllTypes.NestedEnum.BAZ),
+ message.getRepeatedNestedEnumList());
+ assertEquals(Arrays.asList(5L),
+ message.getUnknownFields()
+ .getField(singularField.getNumber())
+ .getVarintList());
+ assertEquals(Arrays.asList(4L, 6L),
+ message.getUnknownFields()
+ .getField(repeatedField.getNumber())
+ .getVarintList());
+ }
+
+ {
+ TestAllExtensions message =
+ TestAllExtensions.parseFrom(data, TestUtil.getExtensionRegistry());
+ assertEquals(TestAllTypes.NestedEnum.BAR,
+ message.getExtension(UnittestProto.optionalNestedEnumExtension));
+ assertEquals(
+ Arrays.asList(TestAllTypes.NestedEnum.FOO, TestAllTypes.NestedEnum.BAZ),
+ message.getExtension(UnittestProto.repeatedNestedEnumExtension));
+ assertEquals(Arrays.asList(5L),
+ message.getUnknownFields()
+ .getField(singularField.getNumber())
+ .getVarintList());
+ assertEquals(Arrays.asList(4L, 6L),
+ message.getUnknownFields()
+ .getField(repeatedField.getNumber())
+ .getVarintList());
+ }
+ }
+
+ public void testClearLite() throws Exception {
+ UnittestLite.TestEmptyMessageLite emptyMessageLite1 =
+ UnittestLite.TestEmptyMessageLite.parseFrom(allFieldsData);
+ UnittestLite.TestEmptyMessageLite emptyMessageLite2 =
+ UnittestLite.TestEmptyMessageLite.newBuilder()
+ .mergeFrom(emptyMessageLite1).clear().build();
+ assertEquals(0, emptyMessageLite2.getSerializedSize());
+ ByteString data = emptyMessageLite2.toByteString();
+ assertEquals(0, data.size());
+ }
+
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java
new file mode 100644
index 0000000000..00f201ca58
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java
@@ -0,0 +1,226 @@
+// 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.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import junit.framework.TestCase;
+
+/**
+ * Tests for {@link UnmodifiableLazyStringList}.
+ *
+ * @author jonp@google.com (Jon Perlow)
+ */
+public class UnmodifiableLazyStringListTest extends TestCase {
+
+ private static String STRING_A = "A";
+ private static String STRING_B = "B";
+ private static String STRING_C = "C";
+
+ private static ByteString BYTE_STRING_A = ByteString.copyFromUtf8("A");
+ private static ByteString BYTE_STRING_B = ByteString.copyFromUtf8("B");
+ private static ByteString BYTE_STRING_C = ByteString.copyFromUtf8("C");
+
+ public void testReadOnlyMethods() {
+ LazyStringArrayList rawList = createSampleList();
+ UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
+ assertEquals(3, list.size());
+ assertSame(STRING_A, list.get(0));
+ assertSame(STRING_B, list.get(1));
+ assertSame(STRING_C, list.get(2));
+ assertEquals(BYTE_STRING_A, list.getByteString(0));
+ assertEquals(BYTE_STRING_B, list.getByteString(1));
+ assertEquals(BYTE_STRING_C, list.getByteString(2));
+
+ List<ByteString> byteStringList = list.asByteStringList();
+ assertSame(list.getByteString(0), byteStringList.get(0));
+ assertSame(list.getByteString(1), byteStringList.get(1));
+ assertSame(list.getByteString(2), byteStringList.get(2));
+ }
+
+ public void testModifyMethods() {
+ LazyStringArrayList rawList = createSampleList();
+ UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
+
+ try {
+ list.remove(0);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(3, list.size());
+
+ try {
+ list.add(STRING_B);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(3, list.size());
+
+ try {
+ list.set(1, STRING_B);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(3, list.size());
+
+ List<ByteString> byteStringList = list.asByteStringList();
+ try {
+ byteStringList.remove(0);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(3, list.size());
+ assertEquals(3, byteStringList.size());
+
+ try {
+ byteStringList.add(BYTE_STRING_B);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(3, list.size());
+ assertEquals(3, byteStringList.size());
+
+ try {
+ byteStringList.set(1, BYTE_STRING_B);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ assertEquals(3, list.size());
+ assertEquals(3, byteStringList.size());
+ }
+
+ public void testIterator() {
+ LazyStringArrayList rawList = createSampleList();
+ UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
+
+ Iterator<String> iter = list.iterator();
+ int count = 0;
+ while (iter.hasNext()) {
+ iter.next();
+ count++;
+ try {
+ iter.remove();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+ assertEquals(3, count);
+
+ List<ByteString> byteStringList = list.asByteStringList();
+ Iterator<ByteString> byteIter = byteStringList.iterator();
+ count = 0;
+ while (byteIter.hasNext()) {
+ byteIter.next();
+ count++;
+ try {
+ byteIter.remove();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+ assertEquals(3, count);
+ }
+
+ public void testListIterator() {
+ LazyStringArrayList rawList = createSampleList();
+ UnmodifiableLazyStringList list = new UnmodifiableLazyStringList(rawList);
+
+ ListIterator<String> iter = list.listIterator();
+ int count = 0;
+ while (iter.hasNext()) {
+ iter.next();
+ count++;
+ try {
+ iter.remove();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ iter.set("bar");
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ iter.add("bar");
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+ assertEquals(3, count);
+
+ List<ByteString> byteStringList = list.asByteStringList();
+ ListIterator<ByteString> byteIter = byteStringList.listIterator();
+ count = 0;
+ while (byteIter.hasNext()) {
+ byteIter.next();
+ count++;
+ try {
+ byteIter.remove();
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ byteIter.set(BYTE_STRING_A);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ try {
+ byteIter.add(BYTE_STRING_A);
+ fail();
+ } catch (UnsupportedOperationException e) {
+ // expected
+ }
+ }
+ assertEquals(3, count);
+ }
+
+ private LazyStringArrayList createSampleList() {
+ LazyStringArrayList rawList = new LazyStringArrayList();
+ rawList.add(STRING_A);
+ rawList.add(STRING_B);
+ rawList.add(STRING_C);
+ return rawList;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/WellKnownTypesTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/WellKnownTypesTest.java
new file mode 100644
index 0000000000..982e200f53
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/WellKnownTypesTest.java
@@ -0,0 +1,65 @@
+// 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.Descriptor;
+import com.google.protobuf.Descriptors.EnumDescriptor;
+import com.google.protobuf.Descriptors.EnumValueDescriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+import com.google.protobuf.test.TestWellKnownTypes;
+
+import junit.framework.TestCase;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This test ensures that well-known types are included in protobuf Java
+ * runtime library.
+ */
+public class WellKnownTypesTest extends TestCase {
+ public void testWellKnownTypes() {
+ // The test passes if it compiles.
+ TestWellKnownTypes message = TestWellKnownTypes.newBuilder().build();
+ assertEquals(0, message.getAnyField().getSerializedSize());
+ assertEquals(0, message.getApiField().getSerializedSize());
+ assertEquals(0, message.getDurationField().getSerializedSize());
+ assertEquals(0, message.getEmptyField().getSerializedSize());
+ assertEquals(0, message.getFieldMaskField().getSerializedSize());
+ assertEquals(0, message.getSourceContextField().getSerializedSize());
+ assertEquals(0, message.getStructField().getSerializedSize());
+ assertEquals(0, message.getTimestampField().getSerializedSize());
+ assertEquals(0, message.getTypeField().getSerializedSize());
+ assertEquals(0, message.getInt32Field().getSerializedSize());
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/WireFormatTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/WireFormatTest.java
new file mode 100644
index 0000000000..370860c2f8
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/WireFormatTest.java
@@ -0,0 +1,604 @@
+// 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.UnittestLite.TestAllExtensionsLite;
+import com.google.protobuf.UnittestLite.TestPackedExtensionsLite;
+import protobuf_unittest.UnittestMset.RawMessageSet;
+import protobuf_unittest.UnittestMset.TestMessageSetExtension1;
+import protobuf_unittest.UnittestMset.TestMessageSetExtension2;
+import protobuf_unittest.UnittestProto;
+import protobuf_unittest.UnittestProto.TestAllExtensions;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestFieldOrderings;
+import protobuf_unittest.UnittestProto.TestOneof2;
+import protobuf_unittest.UnittestProto.TestOneofBackwardsCompatible;
+import protobuf_unittest.UnittestProto.TestPackedExtensions;
+import protobuf_unittest.UnittestProto.TestPackedTypes;
+import proto2_wireformat_unittest.UnittestMsetWireFormat.TestMessageSet;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.List;
+import junit.framework.TestCase;
+
+/**
+ * Tests related to parsing and serialization.
+ *
+ * @author kenton@google.com (Kenton Varda)
+ */
+public class WireFormatTest extends TestCase {
+ public void testSerialization() throws Exception {
+ TestAllTypes message = TestUtil.getAllSet();
+
+ ByteString rawBytes = message.toByteString();
+ assertEquals(rawBytes.size(), message.getSerializedSize());
+
+ TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
+
+ TestUtil.assertAllFieldsSet(message2);
+ }
+
+ public void testSerializationPacked() throws Exception {
+ TestPackedTypes message = TestUtil.getPackedSet();
+
+ ByteString rawBytes = message.toByteString();
+ assertEquals(rawBytes.size(), message.getSerializedSize());
+
+ TestPackedTypes message2 = TestPackedTypes.parseFrom(rawBytes);
+
+ TestUtil.assertPackedFieldsSet(message2);
+ }
+
+ public void testSerializeExtensions() throws Exception {
+ // TestAllTypes and TestAllExtensions should have compatible wire formats,
+ // so if we serialize a TestAllExtensions then parse it as TestAllTypes
+ // it should work.
+
+ TestAllExtensions message = TestUtil.getAllExtensionsSet();
+ ByteString rawBytes = message.toByteString();
+ assertEquals(rawBytes.size(), message.getSerializedSize());
+
+ TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
+
+ TestUtil.assertAllFieldsSet(message2);
+ }
+
+ public void testSerializePackedExtensions() throws Exception {
+ // TestPackedTypes and TestPackedExtensions should have compatible wire
+ // formats; check that they serialize to the same string.
+ TestPackedExtensions message = TestUtil.getPackedExtensionsSet();
+ ByteString rawBytes = message.toByteString();
+
+ TestPackedTypes message2 = TestUtil.getPackedSet();
+ ByteString rawBytes2 = message2.toByteString();
+
+ assertEquals(rawBytes, rawBytes2);
+ }
+
+ public void testSerializationPackedWithoutGetSerializedSize()
+ throws Exception {
+ // Write directly to an OutputStream, without invoking getSerializedSize()
+ // This used to be a bug where the size of a packed field was incorrect,
+ // since getSerializedSize() was never invoked.
+ TestPackedTypes message = TestUtil.getPackedSet();
+
+ // Directly construct a CodedOutputStream around the actual OutputStream,
+ // in case writeTo(OutputStream output) invokes getSerializedSize();
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ CodedOutputStream codedOutput = CodedOutputStream.newInstance(outputStream);
+
+ message.writeTo(codedOutput);
+
+ codedOutput.flush();
+
+ TestPackedTypes message2 = TestPackedTypes.parseFrom(
+ outputStream.toByteArray());
+
+ TestUtil.assertPackedFieldsSet(message2);
+ }
+
+ public void testSerializeExtensionsLite() throws Exception {
+ // TestAllTypes and TestAllExtensions should have compatible wire formats,
+ // so if we serialize a TestAllExtensions then parse it as TestAllTypes
+ // it should work.
+
+ TestAllExtensionsLite message = TestUtilLite.getAllLiteExtensionsSet();
+ ByteString rawBytes = message.toByteString();
+ assertEquals(rawBytes.size(), message.getSerializedSize());
+
+ TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
+
+ TestUtil.assertAllFieldsSet(message2);
+ }
+
+ public void testSerializePackedExtensionsLite() throws Exception {
+ // TestPackedTypes and TestPackedExtensions should have compatible wire
+ // formats; check that they serialize to the same string.
+ TestPackedExtensionsLite message = TestUtilLite.getLitePackedExtensionsSet();
+ ByteString rawBytes = message.toByteString();
+
+ TestPackedTypes message2 = TestUtil.getPackedSet();
+ ByteString rawBytes2 = message2.toByteString();
+
+ assertEquals(rawBytes, rawBytes2);
+ }
+
+ public void testParseExtensions() throws Exception {
+ // TestAllTypes and TestAllExtensions should have compatible wire formats,
+ // so if we serialize a TestAllTypes then parse it as TestAllExtensions
+ // it should work.
+
+ TestAllTypes message = TestUtil.getAllSet();
+ ByteString rawBytes = message.toByteString();
+
+ ExtensionRegistry registry = TestUtil.getExtensionRegistry();
+
+ TestAllExtensions message2 =
+ TestAllExtensions.parseFrom(rawBytes, registry);
+
+ TestUtil.assertAllExtensionsSet(message2);
+ }
+
+ public void testParsePackedExtensions() throws Exception {
+ // Ensure that packed extensions can be properly parsed.
+ TestPackedExtensions message = TestUtil.getPackedExtensionsSet();
+ ByteString rawBytes = message.toByteString();
+
+ ExtensionRegistry registry = TestUtil.getExtensionRegistry();
+
+ TestPackedExtensions message2 =
+ TestPackedExtensions.parseFrom(rawBytes, registry);
+
+ TestUtil.assertPackedExtensionsSet(message2);
+ }
+
+ public void testParseExtensionsLite() throws Exception {
+ // TestAllTypes and TestAllExtensions should have compatible wire formats,
+ // so if we serialize a TestAllTypes then parse it as TestAllExtensions
+ // it should work.
+
+ TestAllTypes message = TestUtil.getAllSet();
+ ByteString rawBytes = message.toByteString();
+
+ ExtensionRegistryLite registry_lite = TestUtilLite.getExtensionRegistryLite();
+
+ TestAllExtensionsLite message2 =
+ TestAllExtensionsLite.parseFrom(rawBytes, registry_lite);
+
+ TestUtil.assertAllExtensionsSet(message2);
+
+ // Try again using a full extension registry.
+ ExtensionRegistry registry = TestUtil.getExtensionRegistry();
+
+ TestAllExtensionsLite message3 =
+ TestAllExtensionsLite.parseFrom(rawBytes, registry);
+
+ TestUtil.assertAllExtensionsSet(message3);
+ }
+
+ public void testParsePackedExtensionsLite() throws Exception {
+ // Ensure that packed extensions can be properly parsed.
+ TestPackedExtensionsLite message = TestUtilLite.getLitePackedExtensionsSet();
+ ByteString rawBytes = message.toByteString();
+
+ ExtensionRegistryLite registry = TestUtilLite.getExtensionRegistryLite();
+
+ TestPackedExtensionsLite message2 =
+ TestPackedExtensionsLite.parseFrom(rawBytes, registry);
+
+ TestUtil.assertPackedExtensionsSet(message2);
+ }
+
+ public void testExtensionsSerializedSize() throws Exception {
+ assertNotSame(TestUtil.getAllSet().getSerializedSize(),
+ TestUtil.getAllExtensionsSet().getSerializedSize());
+ }
+
+ public void testSerializeDelimited() throws Exception {
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ TestUtil.getAllSet().writeDelimitedTo(output);
+ output.write(12);
+ TestUtil.getPackedSet().writeDelimitedTo(output);
+ output.write(34);
+
+ ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
+
+ TestUtil.assertAllFieldsSet(TestAllTypes.parseDelimitedFrom(input));
+ assertEquals(12, input.read());
+ TestUtil.assertPackedFieldsSet(TestPackedTypes.parseDelimitedFrom(input));
+ assertEquals(34, input.read());
+ assertEquals(-1, input.read());
+
+ // We're at EOF, so parsing again should return null.
+ assertTrue(TestAllTypes.parseDelimitedFrom(input) == null);
+ }
+
+ private void assertFieldsInOrder(ByteString data) throws Exception {
+ CodedInputStream input = data.newCodedInput();
+ int previousTag = 0;
+
+ while (true) {
+ int tag = input.readTag();
+ if (tag == 0) {
+ break;
+ }
+
+ assertTrue(tag > previousTag);
+ previousTag = tag;
+ input.skipField(tag);
+ }
+ }
+
+ public void testInterleavedFieldsAndExtensions() throws Exception {
+ // Tests that fields are written in order even when extension ranges
+ // are interleaved with field numbers.
+ ByteString data =
+ TestFieldOrderings.newBuilder()
+ .setMyInt(1)
+ .setMyString("foo")
+ .setMyFloat(1.0F)
+ .setExtension(UnittestProto.myExtensionInt, 23)
+ .setExtension(UnittestProto.myExtensionString, "bar")
+ .build().toByteString();
+ assertFieldsInOrder(data);
+
+ Descriptors.Descriptor descriptor = TestFieldOrderings.getDescriptor();
+ ByteString dynamic_data =
+ DynamicMessage.newBuilder(TestFieldOrderings.getDescriptor())
+ .setField(descriptor.findFieldByName("my_int"), 1L)
+ .setField(descriptor.findFieldByName("my_string"), "foo")
+ .setField(descriptor.findFieldByName("my_float"), 1.0F)
+ .setField(UnittestProto.myExtensionInt.getDescriptor(), 23)
+ .setField(UnittestProto.myExtensionString.getDescriptor(), "bar")
+ .build().toByteString();
+ assertFieldsInOrder(dynamic_data);
+ }
+
+ private ExtensionRegistry getTestFieldOrderingsRegistry() {
+ ExtensionRegistry result = ExtensionRegistry.newInstance();
+ result.add(UnittestProto.myExtensionInt);
+ result.add(UnittestProto.myExtensionString);
+ return result;
+ }
+
+ public void testParseMultipleExtensionRanges() throws Exception {
+ // Make sure we can parse a message that contains multiple extensions
+ // ranges.
+ TestFieldOrderings source =
+ TestFieldOrderings.newBuilder()
+ .setMyInt(1)
+ .setMyString("foo")
+ .setMyFloat(1.0F)
+ .setExtension(UnittestProto.myExtensionInt, 23)
+ .setExtension(UnittestProto.myExtensionString, "bar")
+ .build();
+ TestFieldOrderings dest =
+ TestFieldOrderings.parseFrom(source.toByteString(),
+ getTestFieldOrderingsRegistry());
+ assertEquals(source, dest);
+ }
+
+ public void testParseMultipleExtensionRangesDynamic() throws Exception {
+ // Same as above except with DynamicMessage.
+ Descriptors.Descriptor descriptor = TestFieldOrderings.getDescriptor();
+ DynamicMessage source =
+ DynamicMessage.newBuilder(TestFieldOrderings.getDescriptor())
+ .setField(descriptor.findFieldByName("my_int"), 1L)
+ .setField(descriptor.findFieldByName("my_string"), "foo")
+ .setField(descriptor.findFieldByName("my_float"), 1.0F)
+ .setField(UnittestProto.myExtensionInt.getDescriptor(), 23)
+ .setField(UnittestProto.myExtensionString.getDescriptor(), "bar")
+ .build();
+ DynamicMessage dest =
+ DynamicMessage.parseFrom(descriptor, source.toByteString(),
+ getTestFieldOrderingsRegistry());
+ assertEquals(source, dest);
+ }
+
+ private static final int UNKNOWN_TYPE_ID = 1550055;
+ private static final int TYPE_ID_1 =
+ TestMessageSetExtension1.getDescriptor().getExtensions().get(0).getNumber();
+ private static final int TYPE_ID_2 =
+ TestMessageSetExtension2.getDescriptor().getExtensions().get(0).getNumber();
+
+ public void testSerializeMessageSetEagerly() throws Exception {
+ testSerializeMessageSetWithFlag(true);
+ }
+
+ public void testSerializeMessageSetNotEagerly() throws Exception {
+ testSerializeMessageSetWithFlag(false);
+ }
+
+ private void testSerializeMessageSetWithFlag(boolean eagerParsing)
+ throws Exception {
+ ExtensionRegistryLite.setEagerlyParseMessageSets(eagerParsing);
+ // Set up a TestMessageSet with two known messages and an unknown one.
+ TestMessageSet messageSet =
+ TestMessageSet.newBuilder()
+ .setExtension(
+ TestMessageSetExtension1.messageSetExtension,
+ TestMessageSetExtension1.newBuilder().setI(123).build())
+ .setExtension(
+ TestMessageSetExtension2.messageSetExtension,
+ TestMessageSetExtension2.newBuilder().setStr("foo").build())
+ .setUnknownFields(
+ UnknownFieldSet.newBuilder()
+ .addField(UNKNOWN_TYPE_ID,
+ UnknownFieldSet.Field.newBuilder()
+ .addLengthDelimited(ByteString.copyFromUtf8("bar"))
+ .build())
+ .build())
+ .build();
+
+ ByteString data = messageSet.toByteString();
+
+ // Parse back using RawMessageSet and check the contents.
+ RawMessageSet raw = RawMessageSet.parseFrom(data);
+
+ assertTrue(raw.getUnknownFields().asMap().isEmpty());
+
+ assertEquals(3, raw.getItemCount());
+ assertEquals(TYPE_ID_1, raw.getItem(0).getTypeId());
+ assertEquals(TYPE_ID_2, raw.getItem(1).getTypeId());
+ assertEquals(UNKNOWN_TYPE_ID, raw.getItem(2).getTypeId());
+
+ TestMessageSetExtension1 message1 =
+ TestMessageSetExtension1.parseFrom(
+ raw.getItem(0).getMessage().toByteArray());
+ assertEquals(123, message1.getI());
+
+ TestMessageSetExtension2 message2 =
+ TestMessageSetExtension2.parseFrom(
+ raw.getItem(1).getMessage().toByteArray());
+ assertEquals("foo", message2.getStr());
+
+ assertEquals("bar", raw.getItem(2).getMessage().toStringUtf8());
+ }
+
+ public void testParseMessageSetEagerly() throws Exception {
+ testParseMessageSetWithFlag(true);
+ }
+
+ public void testParseMessageSetNotEagerly()throws Exception {
+ testParseMessageSetWithFlag(false);
+ }
+
+ private void testParseMessageSetWithFlag(boolean eagerParsing)
+ throws Exception {
+ ExtensionRegistryLite.setEagerlyParseMessageSets(eagerParsing);
+ ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance();
+ extensionRegistry.add(TestMessageSetExtension1.messageSetExtension);
+ extensionRegistry.add(TestMessageSetExtension2.messageSetExtension);
+
+ // Set up a RawMessageSet with two known messages and an unknown one.
+ RawMessageSet raw =
+ RawMessageSet.newBuilder()
+ .addItem(
+ RawMessageSet.Item.newBuilder()
+ .setTypeId(TYPE_ID_1)
+ .setMessage(
+ TestMessageSetExtension1.newBuilder()
+ .setI(123)
+ .build().toByteString())
+ .build())
+ .addItem(
+ RawMessageSet.Item.newBuilder()
+ .setTypeId(TYPE_ID_2)
+ .setMessage(
+ TestMessageSetExtension2.newBuilder()
+ .setStr("foo")
+ .build().toByteString())
+ .build())
+ .addItem(
+ RawMessageSet.Item.newBuilder()
+ .setTypeId(UNKNOWN_TYPE_ID)
+ .setMessage(ByteString.copyFromUtf8("bar"))
+ .build())
+ .build();
+
+ ByteString data = raw.toByteString();
+
+ // Parse as a TestMessageSet and check the contents.
+ TestMessageSet messageSet =
+ TestMessageSet.parseFrom(data, extensionRegistry);
+
+ assertEquals(123, messageSet.getExtension(
+ TestMessageSetExtension1.messageSetExtension).getI());
+ assertEquals("foo", messageSet.getExtension(
+ TestMessageSetExtension2.messageSetExtension).getStr());
+
+ // Check for unknown field with type LENGTH_DELIMITED,
+ // number UNKNOWN_TYPE_ID, and contents "bar".
+ UnknownFieldSet unknownFields = messageSet.getUnknownFields();
+ assertEquals(1, unknownFields.asMap().size());
+ assertTrue(unknownFields.hasField(UNKNOWN_TYPE_ID));
+
+ UnknownFieldSet.Field field = unknownFields.getField(UNKNOWN_TYPE_ID);
+ assertEquals(1, field.getLengthDelimitedList().size());
+ assertEquals("bar", field.getLengthDelimitedList().get(0).toStringUtf8());
+ }
+
+ public void testParseMessageSetExtensionEagerly() throws Exception {
+ testParseMessageSetExtensionWithFlag(true);
+ }
+
+ public void testParseMessageSetExtensionNotEagerly() throws Exception {
+ testParseMessageSetExtensionWithFlag(false);
+ }
+
+ private void testParseMessageSetExtensionWithFlag(boolean eagerParsing)
+ throws Exception {
+ ExtensionRegistryLite.setEagerlyParseMessageSets(eagerParsing);
+ ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance();
+ extensionRegistry.add(TestMessageSetExtension1.messageSetExtension);
+
+ // Set up a RawMessageSet with a known messages.
+ int TYPE_ID_1 =
+ TestMessageSetExtension1
+ .getDescriptor().getExtensions().get(0).getNumber();
+ RawMessageSet raw =
+ RawMessageSet.newBuilder()
+ .addItem(
+ RawMessageSet.Item.newBuilder()
+ .setTypeId(TYPE_ID_1)
+ .setMessage(
+ TestMessageSetExtension1.newBuilder()
+ .setI(123)
+ .build().toByteString())
+ .build())
+ .build();
+
+ ByteString data = raw.toByteString();
+
+ // Parse as a TestMessageSet and check the contents.
+ TestMessageSet messageSet =
+ TestMessageSet.parseFrom(data, extensionRegistry);
+ assertEquals(123, messageSet.getExtension(
+ TestMessageSetExtension1.messageSetExtension).getI());
+ }
+
+ public void testMergeLazyMessageSetExtensionEagerly() throws Exception {
+ testMergeLazyMessageSetExtensionWithFlag(true);
+ }
+
+ public void testMergeLazyMessageSetExtensionNotEagerly() throws Exception {
+ testMergeLazyMessageSetExtensionWithFlag(false);
+ }
+
+ private void testMergeLazyMessageSetExtensionWithFlag(boolean eagerParsing)
+ throws Exception {
+ ExtensionRegistryLite.setEagerlyParseMessageSets(eagerParsing);
+ ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance();
+ extensionRegistry.add(TestMessageSetExtension1.messageSetExtension);
+
+ // Set up a RawMessageSet with a known messages.
+ int TYPE_ID_1 =
+ TestMessageSetExtension1
+ .getDescriptor().getExtensions().get(0).getNumber();
+ RawMessageSet raw =
+ RawMessageSet.newBuilder()
+ .addItem(
+ RawMessageSet.Item.newBuilder()
+ .setTypeId(TYPE_ID_1)
+ .setMessage(
+ TestMessageSetExtension1.newBuilder()
+ .setI(123)
+ .build().toByteString())
+ .build())
+ .build();
+
+ ByteString data = raw.toByteString();
+
+ // Parse as a TestMessageSet and store value into lazy field
+ TestMessageSet messageSet =
+ TestMessageSet.parseFrom(data, extensionRegistry);
+ // Merge lazy field check the contents.
+ messageSet =
+ messageSet.toBuilder().mergeFrom(data, extensionRegistry).build();
+ assertEquals(123, messageSet.getExtension(
+ TestMessageSetExtension1.messageSetExtension).getI());
+ }
+
+ public void testMergeMessageSetExtensionEagerly() throws Exception {
+ testMergeMessageSetExtensionWithFlag(true);
+ }
+
+ public void testMergeMessageSetExtensionNotEagerly() throws Exception {
+ testMergeMessageSetExtensionWithFlag(false);
+ }
+
+ private void testMergeMessageSetExtensionWithFlag(boolean eagerParsing)
+ throws Exception {
+ ExtensionRegistryLite.setEagerlyParseMessageSets(eagerParsing);
+ ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance();
+ extensionRegistry.add(TestMessageSetExtension1.messageSetExtension);
+
+ // Set up a RawMessageSet with a known messages.
+ int TYPE_ID_1 =
+ TestMessageSetExtension1
+ .getDescriptor().getExtensions().get(0).getNumber();
+ RawMessageSet raw =
+ RawMessageSet.newBuilder()
+ .addItem(
+ RawMessageSet.Item.newBuilder()
+ .setTypeId(TYPE_ID_1)
+ .setMessage(
+ TestMessageSetExtension1.newBuilder()
+ .setI(123)
+ .build().toByteString())
+ .build())
+ .build();
+
+ // Serialize RawMessageSet unnormally (message value before type id)
+ ByteString.CodedBuilder out = ByteString.newCodedBuilder(
+ raw.getSerializedSize());
+ CodedOutputStream output = out.getCodedOutput();
+ List<RawMessageSet.Item> items = raw.getItemList();
+ for (int i = 0; i < items.size(); i++) {
+ RawMessageSet.Item item = items.get(i);
+ output.writeTag(1, WireFormat.WIRETYPE_START_GROUP);
+ output.writeBytes(3, item.getMessage());
+ output.writeInt32(2, item.getTypeId());
+ output.writeTag(1, WireFormat.WIRETYPE_END_GROUP);
+ }
+ ByteString data = out.build();
+
+ // Merge bytes into TestMessageSet and check the contents.
+ TestMessageSet messageSet =
+ TestMessageSet.newBuilder().mergeFrom(data, extensionRegistry).build();
+ assertEquals(123, messageSet.getExtension(
+ TestMessageSetExtension1.messageSetExtension).getI());
+ }
+
+ // ================================================================
+ // oneof
+ public void testOneofWireFormat() throws Exception {
+ TestOneof2.Builder builder = TestOneof2.newBuilder();
+ TestUtil.setOneof(builder);
+ TestOneof2 message = builder.build();
+ ByteString rawBytes = message.toByteString();
+
+ assertEquals(rawBytes.size(), message.getSerializedSize());
+
+ TestOneof2 message2 = TestOneof2.parseFrom(rawBytes);
+ TestUtil.assertOneofSet(message2);
+ }
+
+ public void testOneofOnlyLastSet() throws Exception {
+ TestOneofBackwardsCompatible source = TestOneofBackwardsCompatible
+ .newBuilder().setFooInt(100).setFooString("101").build();
+
+ ByteString rawBytes = source.toByteString();
+ TestOneof2 message = TestOneof2.parseFrom(rawBytes);
+ assertFalse(message.hasFooInt());
+ assertTrue(message.hasFooString());
+ }
+}
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/any_test.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/any_test.proto
index cd641ca0b8..80173d8a0e 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/any_test.proto
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/any_test.proto
@@ -28,15 +28,15 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Author: jieluo@google.com (Jie Luo)
-
syntax = "proto3";
-package google.protobuf.internal;
+package any_test;
+
+option java_package = "any_test";
+option java_outer_classname = "AnyTestProto";
import "google/protobuf/any.proto";
message TestAny {
google.protobuf.Any value = 1;
- int32 int_value = 2;
}
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/field_presence_test.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/field_presence_test.proto
new file mode 100644
index 0000000000..2367bd8bd0
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/field_presence_test.proto
@@ -0,0 +1,94 @@
+// 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.
+
+syntax = "proto3";
+
+package field_presence_test;
+
+import "google/protobuf/unittest.proto";
+
+option java_package = "com.google.protobuf";
+option java_outer_classname = "FieldPresenceTestProto";
+
+message TestAllTypes {
+ enum NestedEnum {
+ FOO = 0;
+ BAR = 1;
+ BAZ = 2;
+ }
+ message NestedMessage {
+ int32 value = 1;
+ }
+
+ int32 optional_int32 = 1;
+ string optional_string = 2;
+ bytes optional_bytes = 3;
+ NestedEnum optional_nested_enum = 4;
+ NestedMessage optional_nested_message = 5;
+ protobuf_unittest.TestRequired optional_proto2_message = 6;
+ NestedMessage optional_lazy_message = 7 [lazy=true];
+
+ oneof oneof_field {
+ int32 oneof_int32 = 11;
+ uint32 oneof_uint32 = 12;
+ string oneof_string = 13;
+ bytes oneof_bytes = 14;
+ NestedEnum oneof_nested_enum = 15;
+ NestedMessage oneof_nested_message = 16;
+ protobuf_unittest.TestRequired oneof_proto2_message = 17;
+ }
+
+ repeated int32 repeated_int32 = 21;
+ repeated string repeated_string = 22;
+ repeated bytes repeated_bytes = 23;
+ repeated NestedEnum repeated_nested_enum = 24;
+ repeated NestedMessage repeated_nested_message = 25;
+ repeated protobuf_unittest.TestRequired repeated_proto2_message = 26;
+ repeated NestedEnum packed_nested_enum = 27 [packed = true];
+}
+
+message TestOptionalFieldsOnly {
+ int32 optional_int32 = 1;
+ string optional_string = 2;
+ bytes optional_bytes = 3;
+ TestAllTypes.NestedEnum optional_nested_enum = 4;
+ TestAllTypes.NestedMessage optional_nested_message = 5;
+ protobuf_unittest.TestRequired optional_proto2_message = 6;
+ TestAllTypes.NestedMessage optional_lazy_message = 7 [lazy=true];
+}
+
+message TestRepeatedFieldsOnly {
+ repeated int32 repeated_int32 = 21;
+ repeated string repeated_string = 22;
+ repeated bytes repeated_bytes = 23;
+ repeated TestAllTypes.NestedEnum repeated_nested_enum = 24;
+ repeated TestAllTypes.NestedMessage repeated_nested_message = 25;
+ repeated protobuf_unittest.TestRequired repeated_proto2_message = 26;
+}
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/lazy_fields_lite.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/lazy_fields_lite.proto
new file mode 100644
index 0000000000..5580f72d99
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/lazy_fields_lite.proto
@@ -0,0 +1,71 @@
+// 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.
+
+// Author: Naoki Iwasaki (niwasaki@google.com)
+//
+// A proto file with lazy fields
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+option optimize_for = LITE_RUNTIME;
+
+message LazyMessageLite {
+ optional int32 num = 1;
+ optional int32 num_with_default = 2 [default = 421];
+ optional LazyInnerMessageLite inner = 3 [lazy = true];
+ repeated LazyInnerMessageLite repeated_inner = 4 [lazy = true];
+
+ oneof oneof_field {
+ int32 oneof_num = 5;
+ LazyInnerMessageLite oneof_inner = 6 [lazy = true];
+ }
+}
+
+message LazyInnerMessageLite {
+ optional int32 num = 1;
+ optional int32 num_with_default = 2 [default = 42];
+ optional LazyNestedInnerMessageLite nested = 3 [lazy = true];
+
+ extensions 1000 to max;
+}
+
+message LazyExtension {
+ extend LazyInnerMessageLite {
+ optional LazyExtension extension = 1000;
+ }
+ optional string name = 1;
+}
+
+message LazyNestedInnerMessageLite {
+ optional int32 num = 1;
+ optional int32 num_with_default = 2 [default = 4];
+}
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/lite_equals_and_hash.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/lite_equals_and_hash.proto
new file mode 100644
index 0000000000..6eef42c578
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/lite_equals_and_hash.proto
@@ -0,0 +1,81 @@
+// 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.
+
+// Author: pbogle@google.com (Phil Bogle)
+
+syntax = "proto2";
+
+package protobuf_unittest.lite_equals_and_hash;
+
+option optimize_for = LITE_RUNTIME;
+
+message TestOneofEquals {
+ oneof oneof_field {
+ string name = 1;
+ int32 value = 2;
+ }
+}
+
+message Foo {
+ optional int32 value = 1;
+ repeated Bar bar = 2;
+
+ extensions 100 to max;
+}
+
+message Bar {
+ extend Foo {
+ optional Bar foo_ext = 100;
+ }
+
+ optional string name = 1;
+}
+
+message BarPrime {
+ optional string name = 1;
+}
+
+message Empty {
+}
+
+extend Foo {
+ optional int32 varint = 101;
+ optional fixed32 fixed32 = 102;
+ optional fixed64 fixed64 = 103;
+ optional group MyGroup = 104 {
+ optional string group_value = 1;
+ }
+}
+
+message TestRecursiveOneof {
+ oneof Foo {
+ TestRecursiveOneof r = 1;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto
new file mode 100644
index 0000000000..2ca0251ca2
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/map_for_proto2_lite_test.proto
@@ -0,0 +1,121 @@
+// 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.
+
+syntax = "proto2";
+
+
+option java_outer_classname = "MapForProto2TestProto";
+
+message TestMap {
+ message MessageValue {
+ optional int32 value = 1;
+ }
+ enum EnumValue {
+ FOO = 0;
+ BAR = 1;
+ BAZ = 2;
+ QUX = 3;
+ }
+
+ map<int32, int32> int32_to_int32_field = 1;
+ map<int32, string> int32_to_string_field = 2;
+ map<int32, bytes> int32_to_bytes_field = 3;
+ map<int32, EnumValue> int32_to_enum_field = 4;
+ map<int32, MessageValue> int32_to_message_field = 5;
+ map<string, int32> string_to_int32_field = 6;
+
+ message MessageWithRequiredFields {
+ required int32 value = 1;
+ }
+ map<int32, MessageWithRequiredFields> required_message_map = 11;
+}
+
+message TestUnknownEnumValue {
+ // Wire-compatible with TestMap.int32_to_enum_field so we can test the
+ // parsing behavior of TestMap regarding unknown enum values.
+ map<int32, int32> int32_to_int32_field = 4;
+}
+
+// Test that the maps initialization code works correctly when the map field
+// references the containing message.
+message TestRecursiveMap {
+ optional int32 value = 1;
+ map<int32, TestRecursiveMap> recursive_map_field = 2;
+}
+
+
+// a decoy of TestMap for testing parsing errors
+message BizarroTestMap {
+ map<int32, bytes> int32_to_int32_field = 1; // same key type, different value
+ map<string, int32> int32_to_string_field = 2; // different key and value types
+ map<string, int32> int32_to_bytes_field = 3; // different key types, same value
+ map<string, bytes> int32_to_enum_field = 4; // different key and value types
+ map<string, bytes> int32_to_message_field = 5; // different key and value types
+ map<string, bytes> 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<string, uint32> if = 1;
+ map<string, uint32> const = 2;
+ map<string, uint32> private = 3;
+ map<string, uint32> class = 4;
+ map<string, uint32> int = 5;
+ map<string, uint32> void = 6;
+ map<string, uint32> string = 7; // These are also proto keywords
+ map<string, uint32> package = 8;
+ map<string, uint32> enum = 9; // Most recent Java reserved word
+ map<string, uint32> 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<string, SampleEnum> if = 1;
+ map<string, SampleEnum> const = 2;
+ map<string, SampleEnum> private = 3;
+ map<string, SampleEnum> class = 4;
+ map<string, SampleEnum> int = 5;
+ map<string, SampleEnum> void = 6;
+ map<string, SampleEnum> string = 7; // These are also proto keywords
+ map<string, SampleEnum> package = 8;
+ map<string, SampleEnum> enum = 9; // Most recent Java reserved word
+ map<string, SampleEnum> 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/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/map_for_proto2_test.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/map_for_proto2_test.proto
new file mode 100644
index 0000000000..974f8a2c74
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/map_for_proto2_test.proto
@@ -0,0 +1,120 @@
+// 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.
+
+syntax = "proto2";
+
+package map_for_proto2_test;
+
+option java_package = "map_test";
+option java_outer_classname = "MapForProto2TestProto";
+
+message TestMap {
+ message MessageValue {
+ optional int32 value = 1;
+ }
+ enum EnumValue {
+ FOO = 0;
+ BAR = 1;
+ BAZ = 2;
+ QUX = 3;
+ }
+
+ map<int32, int32> int32_to_int32_field = 1;
+ map<int32, string> int32_to_string_field = 2;
+ map<int32, bytes> int32_to_bytes_field = 3;
+ map<int32, EnumValue> int32_to_enum_field = 4;
+ map<int32, MessageValue> int32_to_message_field = 5;
+ map<string, int32> string_to_int32_field = 6;
+
+ message MessageWithRequiredFields {
+ required int32 value = 1;
+ }
+ map<int32, MessageWithRequiredFields> required_message_map = 11;
+}
+
+message TestUnknownEnumValue {
+ // Wire-compatible with TestMap.int32_to_enum_field so we can test the
+ // parsing behavior of TestMap regarding unknown enum values.
+ map<int32, int32> int32_to_int32_field = 4;
+}
+
+// Test that the maps initialization code works correctly when the map field
+// references the containing message.
+message TestRecursiveMap {
+ optional int32 value = 1;
+ map<int32, TestRecursiveMap> recursive_map_field = 2;
+}
+
+
+// a decoy of TestMap for testing parsing errors
+message BizarroTestMap {
+ map<int32, bytes> int32_to_int32_field = 1; // same key type, different value
+ map<string, int32> int32_to_string_field = 2; // different key and value types
+ map<string, int32> int32_to_bytes_field = 3; // different key types, same value
+ map<string, bytes> int32_to_enum_field = 4; // different key and value types
+ map<string, bytes> int32_to_message_field = 5; // different key and value types
+ map<string, bytes> 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<string, uint32> if = 1;
+ map<string, uint32> const = 2;
+ map<string, uint32> private = 3;
+ map<string, uint32> class = 4;
+ map<string, uint32> int = 5;
+ map<string, uint32> void = 6;
+ map<string, uint32> string = 7; // These are also proto keywords
+ map<string, uint32> package = 8;
+ map<string, uint32> enum = 9; // Most recent Java reserved word
+ map<string, uint32> 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<string, SampleEnum> if = 1;
+ map<string, SampleEnum> const = 2;
+ map<string, SampleEnum> private = 3;
+ map<string, SampleEnum> class = 4;
+ map<string, SampleEnum> int = 5;
+ map<string, SampleEnum> void = 6;
+ map<string, SampleEnum> string = 7; // These are also proto keywords
+ map<string, SampleEnum> package = 8;
+ map<string, SampleEnum> enum = 9; // Most recent Java reserved word
+ map<string, SampleEnum> null = 10;
+ // null is not a 'reserved word' per se but as a literal needs similar care
+}
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/map_initialization_order_test.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/map_initialization_order_test.proto
new file mode 100644
index 0000000000..b02ac599a5
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/map_initialization_order_test.proto
@@ -0,0 +1,61 @@
+// 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.
+
+// Regression test for a map initilaization order bug. The bug only manifests
+// when:
+// 1. A message contains map fields and is also extendable.
+// 2. There is a file-level extension defined in the same file referencing
+// the above message as the extension type.
+// 3. The program executes in the following order:
+// a. getDescriptor() is called on another message in the same file.
+// b. use protobuf reflection to access the map field.
+// The symptom is a NullPointerException being thrown.
+syntax = "proto2";
+
+package map_test;
+
+option java_package = "map_test";
+option java_outer_classname = "MapInitializationOrderTest";
+option java_multiple_files = true;
+
+// Mirrors the structure of
+// javatests/com/google/cloud/common/logging/logging_test.proto.
+
+message Message1 {
+ map<string, bool> map_field = 1;
+ extensions 1000 to max;
+}
+
+extend Message1 {
+ optional Message1 recursive_extension = 1001;
+}
+
+message RedactAllTypes {
+}
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/map_test.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/map_test.proto
new file mode 100644
index 0000000000..bc2105e50f
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/map_test.proto
@@ -0,0 +1,110 @@
+// 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.
+
+syntax = "proto3";
+
+package map_test;
+
+option java_package = "map_test";
+option java_outer_classname = "MapTestProto";
+
+message TestMap {
+ message MessageValue {
+ int32 value = 1;
+ }
+ enum EnumValue {
+ FOO = 0;
+ BAR = 1;
+ BAZ = 2;
+ QUX = 3;
+ }
+
+ map<int32, int32> int32_to_int32_field = 1;
+ map<int32, string> int32_to_string_field = 2;
+ map<int32, bytes> int32_to_bytes_field = 3;
+ map<int32, EnumValue> int32_to_enum_field = 4;
+ map<int32, MessageValue> int32_to_message_field = 5;
+ map<string, int32> string_to_int32_field = 6;
+ map<uint32, int32> uint32_to_int32_field = 7;
+ map<int64, int32> int64_to_int32_field = 8;
+}
+
+// Used to test that a nested builder containing map fields will properly
+// propagate the onChange event and mark its parent dirty when a change
+// is made to a map field.
+message TestOnChangeEventPropagation {
+ TestMap optional_message = 1;
+}
+
+// a decoy of TestMap for testing parsing errors
+message BizarroTestMap {
+ map<int32, bytes> int32_to_int32_field = 1; // same key type, different value
+ map<string, int32> int32_to_string_field = 2; // different key and value types
+ map<string, int32> int32_to_bytes_field = 3; // different key types, same value
+ map<string, bytes> int32_to_enum_field = 4; // different key and value types
+ map<string, bytes> int32_to_message_field = 5; // different key and value types
+ map<string, bytes> 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<string, uint32> if = 1;
+ map<string, uint32> const = 2;
+ map<string, uint32> private = 3;
+ map<string, uint32> class = 4;
+ map<string, uint32> int = 5;
+ map<string, uint32> void = 6;
+ map<string, uint32> string = 7; // These are also proto keywords
+ map<string, uint32> package = 8;
+ map<string, uint32> enum = 9; // Most recent Java reserved word
+ map<string, uint32> 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<string, SampleEnum> if = 1;
+ map<string, SampleEnum> const = 2;
+ map<string, SampleEnum> private = 3;
+ map<string, SampleEnum> class = 4;
+ map<string, SampleEnum> int = 5;
+ map<string, SampleEnum> void = 6;
+ map<string, SampleEnum> string = 7; // These are also proto keywords
+ map<string, SampleEnum> package = 8;
+ map<string, SampleEnum> enum = 9; // Most recent Java reserved word
+ map<string, SampleEnum> null = 10;
+ // null is not a 'reserved word' per se but as a literal needs similar care
+}
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/multiple_files_test.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/multiple_files_test.proto
new file mode 100644
index 0000000000..92790506f0
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/multiple_files_test.proto
@@ -0,0 +1,78 @@
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+//
+// A proto file which tests the java_multiple_files option.
+
+syntax = "proto2";
+
+// Some generic_services option(s) added automatically.
+// See: http://go/proto2-generic-services-default
+option java_generic_services = true; // auto-added
+
+import "google/protobuf/unittest.proto";
+import "google/protobuf/descriptor.proto";
+
+package protobuf_unittest;
+
+option java_multiple_files = true;
+option java_outer_classname = "MultipleFilesTestProto";
+
+
+message MessageWithNoOuter {
+ message NestedMessage {
+ optional int32 i = 1;
+ }
+ enum NestedEnum {
+ BAZ = 3;
+ }
+ optional NestedMessage nested = 1;
+ repeated TestAllTypes foreign = 2;
+ optional NestedEnum nested_enum = 3;
+ optional EnumWithNoOuter foreign_enum = 4;
+}
+
+extend google.protobuf.EnumValueOptions {
+ optional int32 enum_value_option = 7654321;
+}
+
+enum EnumWithNoOuter {
+ FOO = 1 [(enum_value_option) = 12345];
+ BAR = 2;
+}
+
+service ServiceWithNoOuter {
+ rpc Foo(MessageWithNoOuter) returns(TestAllTypes);
+}
+
+extend TestAllExtensions {
+ optional int32 extension_with_outer = 1234567;
+}
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/nested_builders_test.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/nested_builders_test.proto
new file mode 100644
index 0000000000..a5dd66d889
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/nested_builders_test.proto
@@ -0,0 +1,54 @@
+// 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.
+
+// Author: jonp@google.com (Jon Perlow)
+//
+syntax = "proto2";
+
+package protobuf_unittest;
+
+option java_multiple_files = true;
+option java_outer_classname = "NestedBuilders";
+
+
+message Vehicle {
+ optional Engine engine = 1;
+ repeated Wheel wheel = 2;
+}
+
+message Engine {
+ optional int32 cylinder = 1;
+ optional int32 liters = 2;
+}
+
+message Wheel {
+ optional int32 radius = 1;
+ optional int32 width = 2;
+}
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/nested_extension.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/nested_extension.proto
new file mode 100644
index 0000000000..704e649e02
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/nested_extension.proto
@@ -0,0 +1,47 @@
+// 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.
+
+// Author: Darick Tong (darick@google.com)
+//
+// A proto file with nested extensions. Note that this must be defined in
+// a separate file to properly test the initialization of the outer class.
+
+syntax = "proto2";
+
+import "com/google/protobuf/non_nested_extension.proto";
+
+package protobuf_unittest;
+
+
+message MyNestedExtension {
+ extend MessageToBeExtended {
+ optional MessageToBeExtended recursiveExtension = 2;
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/nested_extension_lite.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/nested_extension_lite.proto
new file mode 100644
index 0000000000..a95c38b234
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/nested_extension_lite.proto
@@ -0,0 +1,49 @@
+// 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.
+
+// Author: Darick Tong (darick@google.com)
+//
+// A proto file with nested extensions for a MessageLite messages. Note that
+// this must be defined in a separate file to properly test the initialization
+// of the outer class.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+option optimize_for = LITE_RUNTIME;
+
+import "com/google/protobuf/non_nested_extension_lite.proto";
+
+message MyNestedExtensionLite {
+ extend MessageLiteToBeExtended {
+ optional MessageLiteToBeExtended recursiveExtensionLite = 3;
+ }
+}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/arena_nc.cc b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/non_nested_extension.proto
index f2f084274a..31fac55295 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/arena_nc.cc
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/non_nested_extension.proto
@@ -28,18 +28,23 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Negative compilation test for arena usage.
+// Author: Darick Tong (darick@google.com)
+//
+// A proto file with extensions.
+
+syntax = "proto2";
+
+package protobuf_unittest;
-#include <google/protobuf/arena.h>
-#include <google/protobuf/unittest.pb.h>
-#ifdef TEST_ARENA_PRIVATE_CONSTRUCTOR
+message MessageToBeExtended {
+ extensions 1 to max;
+}
+
+message MyNonNestedExtension {
+}
-namespace google {
-void ArenaPrivateConstructor() {
- google::protobuf::Arena arena;
- protobuf_unittest::TestAllTypes message(&arena);
+extend MessageToBeExtended {
+ optional MyNonNestedExtension nonNestedExtension = 1;
}
-#endif
-} // namespace google
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/non_nested_extension_lite.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/non_nested_extension_lite.proto
new file mode 100644
index 0000000000..37c369edaa
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/non_nested_extension_lite.proto
@@ -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.
+
+// Author: Darick Tong (darick@google.com)
+//
+// A proto file with extensions for a MessageLite messages.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+option optimize_for = LITE_RUNTIME;
+
+message MessageLiteToBeExtended {
+ extensions 1 to max;
+}
+
+message MyNonNestedExtensionLite {
+}
+
+extend MessageLiteToBeExtended {
+ optional MyNonNestedExtensionLite nonNestedExtensionLite = 1;
+}
+
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/outer_class_name_test.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/outer_class_name_test.proto
new file mode 100644
index 0000000000..4208368146
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/outer_class_name_test.proto
@@ -0,0 +1,40 @@
+// 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.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+
+// This message's name is the same with the default outer class name of this
+// proto file. It's used to test if the compiler can avoid this conflict
+// correctly.
+message OuterClassNameTest {
+}
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/outer_class_name_test2.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/outer_class_name_test2.proto
new file mode 100644
index 0000000000..3e5956b0d4
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/outer_class_name_test2.proto
@@ -0,0 +1,44 @@
+// 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.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+
+message TestMessage2 {
+ message NestedMessage {
+ // This message's name is the same with the default outer class name of this
+ // proto file. It's used to test if the compiler can avoid this conflict
+ // correctly.
+ message OuterClassNameTest2 {
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/outer_class_name_test3.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/outer_class_name_test3.proto
new file mode 100644
index 0000000000..74a8ba3c3d
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/outer_class_name_test3.proto
@@ -0,0 +1,45 @@
+// 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.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+
+message TestMessage3 {
+ message NestedMessage {
+ // This enum's name is the same with the default outer class name of this
+ // proto file. It's used to test if the compiler can avoid this conflict
+ // correctly.
+ enum OuterClassNameTest3 {
+ DUMMY_VALUE = 1;
+ }
+ }
+}
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto
new file mode 100644
index 0000000000..d2c77936c3
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto
@@ -0,0 +1,168 @@
+// 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.
+
+// Author: jonp@google.com (Jon Perlow)
+
+// This file tests that various identifiers work as field and type names even
+// though the same identifiers are used internally by the java code generator.
+
+syntax = "proto2";
+
+// Some generic_services option(s) added automatically.
+// See: http://go/proto2-generic-services-default
+option java_generic_services = true; // auto-added
+
+package io_protocol_tests;
+
+option java_package = "com.google.protobuf";
+option java_outer_classname = "TestBadIdentifiersProto";
+
+message TestMessage {
+ optional string cached_size = 1;
+ optional string serialized_size = 2;
+ optional string class = 3;
+}
+
+message Descriptor {
+ option no_standard_descriptor_accessor = true;
+ optional string descriptor = 1;
+ message NestedDescriptor {
+ option no_standard_descriptor_accessor = true;
+ optional string descriptor = 1;
+ }
+ optional NestedDescriptor nested_descriptor = 2;
+ enum NestedEnum {
+ UNKNOWN = 0;
+ FOO = 1;
+ }
+}
+
+message Parser {
+ enum ParserEnum {
+ UNKNOWN = 0;
+ PARSER = 1;
+ }
+ optional ParserEnum parser = 1;
+}
+
+message Deprecated {
+ enum TestEnum {
+ UNKNOWN = 0;
+ FOO = 1;
+
+ // Test if @Deprecated annotation conflicts with Deprecated message name.
+ BAR = 2 [ deprecated = true ];
+ }
+
+ optional int32 field1 = 1 [deprecated=true];
+ optional TestEnum field2 = 2 [deprecated=true];
+ optional TestMessage field3 = 3 [deprecated=true];
+}
+
+message Override {
+ optional int32 override = 1;
+}
+
+message Object {
+ optional int32 object = 1;
+ optional string string_object = 2;
+}
+
+message String {
+ optional string string = 1;
+}
+
+message Integer {
+ optional int32 integer = 1;
+}
+
+message Long {
+ optional int32 long = 1;
+}
+
+message Float {
+ optional float float = 1;
+}
+
+message Double {
+ optional double double = 1;
+}
+
+service TestConflictingMethodNames {
+ rpc Override(TestMessage) returns (TestMessage);
+}
+
+message TestConflictingFieldNames {
+ enum TestEnum {
+ UNKNOWN = 0;
+ FOO = 1;
+ }
+ message TestMessage {
+ }
+ repeated int32 int32_field = 1;
+ repeated TestEnum enum_field = 2;
+ repeated string string_field = 3;
+ repeated bytes bytes_field = 4;
+ repeated TestMessage message_field = 5;
+
+ optional int32 int32_field_count = 11;
+ optional TestEnum enum_field_count = 12;
+ optional string string_field_count = 13;
+ optional bytes bytes_field_count = 14;
+ optional TestMessage message_field_count = 15;
+
+ repeated int32 Int32Field = 21; // NO_PROTO3
+ repeated TestEnum EnumField = 22; // NO_PROTO3
+ repeated string StringField = 23; // NO_PROTO3
+ repeated bytes BytesField = 24; // NO_PROTO3
+ repeated TestMessage MessageField = 25; // NO_PROTO3
+
+ // This field conflicts with "int32_field" as they both generate
+ // the method getInt32FieldList().
+ required int32 int32_field_list = 31; // NO_PROTO3
+
+ extensions 1000 to max; // NO_PROTO3
+
+ repeated int64 int64_field = 41;
+ extend TestConflictingFieldNames { // NO_PROTO3
+ // We don't generate accessors for extensions so the following extension
+ // fields don't conflict with the repeated field "int64_field".
+ optional int64 int64_field_count = 1001; // NO_PROTO3
+ optional int64 int64_field_list = 1002; // NO_PROTO3
+ } // NO_PROTO3
+}
+
+message TestMapField {
+ message MapField {}
+ message Pair {}
+ message Message {}
+
+ map<int32, int32> map_field = 1;
+}
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_check_utf8.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_check_utf8.proto
new file mode 100644
index 0000000000..119c1dcbad
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_check_utf8.proto
@@ -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.
+
+// Author: Jacob Butcher (jbaum@google.com)
+//
+// Test file option java_string_check_utf8.
+syntax = "proto2";
+
+package proto2_test_check_utf8;
+
+option java_outer_classname = "TestCheckUtf8";
+option java_string_check_utf8 = true;
+
+message StringWrapper {
+ required string req = 1;
+ optional string opt = 2;
+ repeated string rep = 3;
+}
+
+message BytesWrapper {
+ required bytes req = 1;
+ optional bytes opt = 2;
+ repeated bytes rep = 3;
+}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/timestamp_duration.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_check_utf8_size.proto
index 56351f168c..f06d76d629 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/timestamp_duration.proto
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_check_utf8_size.proto
@@ -28,20 +28,25 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Proto to test proto3 Timestamp and Duration.
-syntax = "proto3";
+// Author: Jacob Butcher (jbaum@google.com)
+//
+// Test file option java_string_check_utf8.
+syntax = "proto2";
-package google.protobuf.testing.timestampduration;
-option java_package = "com.google.protobuf.testing.timestampduration";
+package proto2_test_check_utf8_size;
-import "google/protobuf/timestamp.proto";
-import "google/protobuf/duration.proto";
+option java_outer_classname = "TestCheckUtf8Size";
+option java_string_check_utf8 = true;
+option optimize_for = CODE_SIZE;
-message TimestampDuration {
- google.protobuf.Timestamp ts = 1;
- google.protobuf.Duration dur = 2;
+message StringWrapperSize {
+ required string req = 1;
+ optional string opt = 2;
+ repeated string rep = 3;
}
-service TestService {
- rpc Call(TimestampDuration) returns (TimestampDuration);
+message BytesWrapperSize {
+ required bytes req = 1;
+ optional bytes opt = 2;
+ repeated bytes rep = 3;
}
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_custom_options.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_custom_options.proto
new file mode 100644
index 0000000000..f8efd455a1
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_custom_options.proto
@@ -0,0 +1,44 @@
+// 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.
+
+// Author: Feng Xiao (xiaofeng@google.com)
+//
+// Test that custom options defined in a proto file's dependencies are properly
+// initialized.
+syntax = "proto2";
+
+package protobuf_unittest;
+
+
+import "google/protobuf/unittest_custom_options.proto";
+
+message TestMessageWithCustomOptionsContainer {
+ optional TestMessageWithCustomOptions field = 1;
+}
diff --git a/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto
new file mode 100644
index 0000000000..645f57b4bb
--- /dev/null
+++ b/third_party/protobuf/java/core/src/test/proto/com/google/protobuf/test_extra_interfaces.proto
@@ -0,0 +1,61 @@
+// 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.
+
+// Author: Darick Tong (darick@google.com)
+syntax = "proto2";
+
+package protobuf_unittest;
+
+message Proto1 {
+ option experimental_java_message_interface =
+ "com.google.protobuf.ExtraInterfaces.HasBoolValue";
+
+ option experimental_java_interface_extends =
+ "com.google.protobuf.ExtraInterfaces.HasByteValue";
+
+ option experimental_java_message_interface =
+ "com.google.protobuf.ExtraInterfaces.HasStringValue<Proto1>";
+
+ option experimental_java_builder_interface =
+ "com.google.protobuf.ExtraInterfaces.HasStringValueBuilder"
+ "<Proto1, Builder>";
+
+ optional string string_value = 1;
+ optional bool bool_value = 2;
+ optional bytes byte_value = 3;
+ optional int32 int_value = 4;
+}
+
+message Proto2 {
+ option experimental_java_message_interface =
+ "com.google.protobuf.ExtraInterfaces.HasBoolValue";
+
+ optional bool bool_value = 1;
+}
diff --git a/third_party/protobuf/java/lite/generate-sources-build.xml b/third_party/protobuf/java/lite/generate-sources-build.xml
new file mode 100644
index 0000000000..89c21c1315
--- /dev/null
+++ b/third_party/protobuf/java/lite/generate-sources-build.xml
@@ -0,0 +1,20 @@
+<project name="generate-sources">
+ <echo message="Running protoc ..."/>
+ <mkdir dir="${generated.sources.lite.dir}"/>
+ <exec executable="${protoc}">
+ <arg value="--java_out=lite:${generated.sources.lite.dir}"/>
+ <arg value="--proto_path=${protobuf.source.dir}"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/any.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/api.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/descriptor.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/duration.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/empty.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/field_mask.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/source_context.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/struct.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/timestamp.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/type.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/wrappers.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/compiler/plugin.proto"/>
+ </exec>
+</project>
diff --git a/third_party/protobuf/java/lite/generate-test-sources-build.xml b/third_party/protobuf/java/lite/generate-test-sources-build.xml
new file mode 100644
index 0000000000..cdd1ee89a7
--- /dev/null
+++ b/third_party/protobuf/java/lite/generate-test-sources-build.xml
@@ -0,0 +1,43 @@
+<project name="generate-test-sources">
+ <mkdir dir="${generated.testsources.lite.dir}"/>
+ <exec executable="${protoc}">
+ <arg value="--java_out=lite:${generated.testsources.lite.dir}"/>
+ <arg value="--proto_path=${protobuf.source.dir}"/>
+ <arg value="--proto_path=${test.proto.dir}"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_import.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_import_public.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_mset.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_mset_wire_format.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_optimize_for.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_custom_options.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_lite.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_import_lite.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_import_public_lite.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_lite_imports_nonlite.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_enormous_descriptor.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_no_generic_services.proto"/>
+ <arg value="${protobuf.source.dir}/google/protobuf/unittest_well_known_types.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/lazy_fields_lite.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/lite_equals_and_hash.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/multiple_files_test.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/nested_builders_test.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/nested_extension.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/nested_extension_lite.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/non_nested_extension.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/non_nested_extension_lite.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/outer_class_name_test.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/outer_class_name_test2.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/outer_class_name_test3.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/test_bad_identifiers.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/test_check_utf8.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/test_check_utf8_size.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/test_custom_options.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/any_test.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/field_presence_test.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/map_for_proto2_lite_test.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/map_for_proto2_test.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/map_test.proto"/>
+ <arg value="${test.proto.dir}/com/google/protobuf/map_initialization_order_test.proto"/>
+ </exec>
+</project>
diff --git a/third_party/protobuf/java/lite/pom.xml b/third_party/protobuf/java/lite/pom.xml
new file mode 100644
index 0000000000..d7b150972d
--- /dev/null
+++ b/third_party/protobuf/java/lite/pom.xml
@@ -0,0 +1,184 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>com.google.protobuf</groupId>
+ <artifactId>protobuf-parent</artifactId>
+ <version>3.0.0</version>
+ </parent>
+
+ <artifactId>protobuf-lite</artifactId>
+ <packaging>bundle</packaging>
+
+ <name>Protocol Buffers [Lite]</name>
+ <description>A trimmed-down version of the Protocol Buffers library.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ </dependency>
+ </dependencies>
+
+ <properties>
+ <core.root>../core</core.root>
+ <test.proto.dir>${core.root}/src/test/proto</test.proto.dir>
+ </properties>
+
+ <build>
+ <sourceDirectory>${core.root}/src/main/java</sourceDirectory>
+ <testSourceDirectory>${core.root}/src/test/java</testSourceDirectory>
+
+ <plugins>
+ <!-- Use Antrun plugin to generate sources with protoc -->
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <!-- Generate core protos -->
+ <execution>
+ <id>generate-sources</id>
+ <phase>generate-sources</phase>
+ <configuration>
+ <target>
+ <ant antfile="generate-sources-build.xml"/>
+ </target>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+
+ <!-- Generate the test protos -->
+ <execution>
+ <id>generate-test-sources</id>
+ <phase>generate-test-sources</phase>
+ <configuration>
+ <target>
+ <ant antfile="generate-test-sources-build.xml"/>
+ </target>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- Only compile a subset of the files -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>add-generated-sources</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${generated.sources.lite.dir}</source>
+ </sources>
+ </configuration>
+ </execution>
+ <execution>
+ <id>add-generated-test-sources</id>
+ <phase>generate-test-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${generated.testsources.lite.dir}</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>**/AbstractMessageLite.java</include>
+ <include>**/AbstractParser.java</include>
+ <include>**/AbstractProtobufList.java</include>
+ <include>**/BooleanArrayList.java</include>
+ <include>**/ByteString.java</include>
+ <include>**/CodedInputStream.java</include>
+ <include>**/CodedOutputStream.java</include>
+ <include>**/DoubleArrayList.java</include>
+ <include>**/ExtensionLite.java</include>
+ <include>**/ExtensionRegistryLite.java</include>
+ <include>**/FieldSet.java</include>
+ <include>**/FloatArrayList.java</include>
+ <include>**/GeneratedMessageLite.java</include>
+ <include>**/IntArrayList.java</include>
+ <include>**/Internal.java</include>
+ <include>**/InvalidProtocolBufferException.java</include>
+ <include>**/LazyFieldLite.java</include>
+ <include>**/LazyStringArrayList.java</include>
+ <include>**/LazyStringList.java</include>
+ <include>**/LongArrayList.java</include>
+ <include>**/MapEntryLite.java</include>
+ <include>**/MapFieldLite.java</include>
+ <include>**/MessageLite.java</include>
+ <include>**/MessageLiteOrBuilder.java</include>
+ <include>**/MessageLiteToString.java</include>
+ <include>**/MutabilityOracle.java</include>
+ <include>**/NioByteString.java</include>
+ <include>**/Parser.java</include>
+ <include>**/ProtobufArrayList.java</include>
+ <include>**/ProtocolStringList.java</include>
+ <include>**/RopeByteString.java</include>
+ <include>**/SmallSortedMap.java</include>
+ <include>**/TextFormatEscaper.java</include>
+ <include>**/UninitializedMessageException.java</include>
+ <include>**/UnknownFieldSetLite.java</include>
+ <include>**/UnmodifiableLazyStringList.java</include>
+ <include>**/UnsafeByteOperations.java</include>
+ <include>**/Utf8.java</include>
+ <include>**/WireFormat.java</include>
+ </includes>
+ <testIncludes>
+ <testInclude>**/*Lite.java</testInclude>
+ <testInclude>**/BooleanArrayListTest.java</testInclude>
+ <testInclude>**/DoubleArrayListTest.java</testInclude>
+ <testInclude>**/FloatArrayListTest.java</testInclude>
+ <testInclude>**/IntArrayListTest.java</testInclude>
+ <testInclude>**/LazyMessageLiteTest.java</testInclude>
+ <testInclude>**/LiteTest.java</testInclude>
+ <testInclude>**/LongArrayListTest.java</testInclude>
+ <testInclude>**/NioByteStringTest.java</testInclude>
+ <testInclude>**/ProtobufArrayListTest.java</testInclude>
+ <testInclude>**/UnknownFieldSetLiteTest.java</testInclude>
+ </testIncludes>
+ </configuration>
+ </plugin>
+
+ <!-- OSGI bundle configuration -->
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-DocURL>https://developers.google.com/protocol-buffers/</Bundle-DocURL>
+ <Bundle-SymbolicName>com.google.protobuf</Bundle-SymbolicName>
+ <Export-Package>com.google.${project.artifactId};version=${project.version}</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/third_party/protobuf/java/pom.xml b/third_party/protobuf/java/pom.xml
new file mode 100644
index 0000000000..f89e442246
--- /dev/null
+++ b/third_party/protobuf/java/pom.xml
@@ -0,0 +1,215 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>com.google</groupId>
+ <artifactId>google</artifactId>
+ <version>1</version>
+ </parent>
+
+ <groupId>com.google.protobuf</groupId>
+ <artifactId>protobuf-parent</artifactId>
+ <version>3.2.0</version>
+ <packaging>pom</packaging>
+
+ <name>Protocol Buffers [Parent]</name>
+ <inceptionYear>2008</inceptionYear>
+ <url>https://developers.google.com/protocol-buffers/</url>
+ <description>
+ Protocol Buffers are a way of encoding structured data in an efficient yet
+ extensible format.
+ </description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+
+ <!-- These are relative to the submodules -->
+ <protobuf.basedir>${project.basedir}/../..</protobuf.basedir>
+ <protobuf.source.dir>${protobuf.basedir}/src</protobuf.source.dir>
+ <protoc>${protobuf.source.dir}/protoc</protoc>
+ <test.proto.dir>src/test/proto</test.proto.dir>
+ <generated.sources.dir>${project.build.directory}/generated-sources</generated.sources.dir>
+ <generated.testsources.dir>${project.build.directory}/generated-test-sources</generated.testsources.dir>
+ <generated.sources.lite.dir>${project.build.directory}/generated-sources-lite</generated.sources.lite.dir>
+ <generated.testsources.lite.dir>${project.build.directory}/generated-test-sources-lite</generated.testsources.lite.dir>
+ </properties>
+
+ <licenses>
+ <license>
+ <name>3-Clause BSD License</name>
+ <url>https://opensource.org/licenses/BSD-3-Clause</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+
+ <scm>
+ <url>https://github.com/google/protobuf</url>
+ <connection>scm:git:https://github.com/google/protobuf.git</connection>
+ </scm>
+
+ <distributionManagement>
+ <snapshotRepository>
+ <id>sonatype-nexus-staging</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ </snapshotRepository>
+ <repository>
+ <id>sonatype-nexus-staging</id>
+ <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
+ </repository>
+ </distributionManagement>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <version>2.2.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>18.0</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.6.0</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-source-plugin</artifactId>
+ <version>2.4</version>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar-no-fork</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.10.3</version>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.6</version>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.10</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>3.0.1</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>1.8</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>release</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <version>2.2.1</version>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar-no-fork</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.9.1</version>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-gpg-plugin</artifactId>
+ <version>1.6</version>
+ <executions>
+ <execution>
+ <id>sign-artifacts</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>sign</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.sonatype.plugins</groupId>
+ <artifactId>nexus-staging-maven-plugin</artifactId>
+ <version>1.6.6</version>
+ <extensions>true</extensions>
+ <configuration>
+ <serverId>sonatype-nexus-staging</serverId>
+ <nexusUrl>https://oss.sonatype.org/</nexusUrl>
+ <autoReleaseAfterClose>false</autoReleaseAfterClose>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+ <modules>
+ <module>core</module>
+ <!-- <module>lite</module> -->
+ <module>util</module>
+ </modules>
+
+</project>
diff --git a/third_party/protobuf/java/util/pom.xml b/third_party/protobuf/java/util/pom.xml
new file mode 100644
index 0000000000..ac771f6ecc
--- /dev/null
+++ b/third_party/protobuf/java/util/pom.xml
@@ -0,0 +1,127 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>com.google.protobuf</groupId>
+ <artifactId>protobuf-parent</artifactId>
+ <version>3.2.0</version>
+ </parent>
+
+ <artifactId>protobuf-java-util</artifactId>
+ <packaging>bundle</packaging>
+
+ <name>Protocol Buffers [Util]</name>
+ <description>Utilities for Protocol Buffers</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>protobuf-java</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.7</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ </dependency>
+ </dependencies>
+
+ <properties>
+ <!-- Use the core proto dir so that we can call the core generation script -->
+ <test.proto.dir>../core/src/test/proto</test.proto.dir>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <!-- Generate the test protos -->
+ <execution>
+ <id>generate-test-sources</id>
+ <phase>generate-test-sources</phase>
+ <configuration>
+ <target>
+ <!-- Generate all of the test protos from the core module -->
+ <ant antfile="../core/generate-test-sources-build.xml"/>
+
+ <!-- Generate additional test protos for this module -->
+ <exec executable="${protoc}">
+ <arg value="--java_out=${generated.testsources.dir}" />
+ <arg value="--proto_path=${protobuf.source.dir}" />
+ <arg value="--proto_path=src/test/proto" />
+ <arg value="src/test/proto/com/google/protobuf/util/json_test.proto" />
+ </exec>
+ </target>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- Add the generated test sources to the build -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>add-generated-test-sources</id>
+ <phase>generate-test-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${generated.testsources.dir}</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- Configure the OSGI bundle -->
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-DocURL>https://developers.google.com/protocol-buffers/</Bundle-DocURL>
+ <Bundle-SymbolicName>com.google.protobuf.util</Bundle-SymbolicName>
+ <Export-Package>com.google.protobuf.util;version=${project.version}</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+
+ <!-- Configure the fat jar to include all dependencies -->
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptorRefs>
+ <descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/Durations.java b/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/Durations.java
new file mode 100644
index 0000000000..46b2182865
--- /dev/null
+++ b/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/Durations.java
@@ -0,0 +1,302 @@
+// 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.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.protobuf.Duration;
+import java.text.ParseException;
+import java.util.Comparator;
+
+/**
+ * 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;
+
+ /** 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<Duration> COMPARATOR =
+ new Comparator<Duration>() {
+ @Override
+ public int compare(Duration d1, Duration d2) {
+ checkValid(d1);
+ checkValid(d2);
+ int secDiff = Long.compare(d1.getSeconds(), d2.getSeconds());
+ return (secDiff != 0) ? secDiff : Integer.compare(d1.getNanos(), d2.getNanos());
+ }
+ };
+
+ /**
+ * 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<Duration> 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].
+ *
+ * <p><b>Note:</b> 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].
+ *
+ * <p><b>Note:</b> 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, int nanos) {
+ if (seconds < DURATION_SECONDS_MIN || seconds > DURATION_SECONDS_MAX) {
+ return false;
+ }
+ if (nanos < -999999999L || nanos >= NANOS_PER_SECOND) {
+ return false;
+ }
+ if (seconds < 0 || nanos < 0) {
+ if (seconds > 0 || nanos > 0) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /** 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
+ * -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.
+ */
+ public static String toString(Duration duration) {
+ checkValid(duration);
+
+ long seconds = duration.getSeconds();
+ int nanos = duration.getNanos();
+
+ StringBuilder result = new StringBuilder();
+ if (seconds < 0 || nanos < 0) {
+ result.append("-");
+ seconds = -seconds;
+ nanos = -nanos;
+ }
+ result.append(seconds);
+ if (nanos != 0) {
+ result.append(".");
+ result.append(Timestamps.formatNanos(nanos));
+ }
+ result.append("s");
+ return result.toString();
+ }
+
+ /**
+ * Parse from a string to produce a duration.
+ *
+ * @return A Duration parsed from the string.
+ * @throws ParseException if parsing fails.
+ */
+ public static Duration parse(String value) throws ParseException {
+ // Must ended with "s".
+ if (value.isEmpty() || value.charAt(value.length() - 1) != 's') {
+ throw new ParseException("Invalid duration string: " + value, 0);
+ }
+ boolean negative = false;
+ if (value.charAt(0) == '-') {
+ negative = true;
+ value = value.substring(1);
+ }
+ String secondValue = value.substring(0, value.length() - 1);
+ String nanoValue = "";
+ int pointPosition = secondValue.indexOf('.');
+ if (pointPosition != -1) {
+ nanoValue = secondValue.substring(pointPosition + 1);
+ secondValue = secondValue.substring(0, pointPosition);
+ }
+ long seconds = Long.parseLong(secondValue);
+ int nanos = nanoValue.isEmpty() ? 0 : Timestamps.parseNanos(nanoValue);
+ if (seconds < 0) {
+ throw new ParseException("Invalid duration string: " + value, 0);
+ }
+ if (negative) {
+ seconds = -seconds;
+ nanos = -nanos;
+ }
+ try {
+ return normalizedDuration(seconds, nanos);
+ } catch (IllegalArgumentException e) {
+ throw new ParseException("Duration value is out of range.", 0);
+ }
+ }
+
+ /** Create a Duration from the number of seconds. */
+ public static Duration fromSeconds(long seconds) {
+ return normalizedDuration(seconds, 0);
+ }
+
+ /**
+ * 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,
+ (int) (milliseconds % MILLIS_PER_SECOND * NANOS_PER_MILLISECOND));
+ }
+
+ /**
+ * 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) {
+ checkValid(duration);
+ return checkedAdd(
+ checkedMultiply(duration.getSeconds(), MILLIS_PER_SECOND),
+ duration.getNanos() / NANOS_PER_MILLISECOND);
+ }
+
+ /** Create a Duration from the number of microseconds. */
+ public static Duration fromMicros(long microseconds) {
+ return normalizedDuration(
+ microseconds / MICROS_PER_SECOND,
+ (int) (microseconds % MICROS_PER_SECOND * NANOS_PER_MICROSECOND));
+ }
+
+ /**
+ * 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) {
+ checkValid(duration);
+ return checkedAdd(
+ checkedMultiply(duration.getSeconds(), MICROS_PER_SECOND),
+ duration.getNanos() / NANOS_PER_MICROSECOND);
+ }
+
+ /** 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. */
+ public static long toNanos(Duration duration) {
+ checkValid(duration);
+ return checkedAdd(
+ checkedMultiply(duration.getSeconds(), NANOS_PER_SECOND), duration.getNanos());
+ }
+
+ /** Add two durations. */
+ public static Duration add(Duration d1, Duration d2) {
+ checkValid(d1);
+ checkValid(d2);
+ return normalizedDuration(
+ checkedAdd(d1.getSeconds(), d2.getSeconds()), checkedAdd(d1.getNanos(), d2.getNanos()));
+ }
+
+ /** Subtract a duration from another. */
+ public static Duration subtract(Duration d1, Duration d2) {
+ 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 = checkedAdd(seconds, nanos / NANOS_PER_SECOND);
+ nanos %= NANOS_PER_SECOND;
+ }
+ if (seconds > 0 && nanos < 0) {
+ 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; // no overflow since nanos is positive (and we're subtracting)
+ seconds++; // no overflow since seconds is negative (and we're incrementing)
+ }
+ Duration duration = Duration.newBuilder().setSeconds(seconds).setNanos(nanos).build();
+ return checkValid(duration);
+ }
+}
diff --git a/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskTree.java b/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskTree.java
new file mode 100644
index 0000000000..b192b53edf
--- /dev/null
+++ b/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskTree.java
@@ -0,0 +1,287 @@
+// 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.util;
+
+import com.google.protobuf.Descriptors.Descriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+import com.google.protobuf.FieldMask;
+import com.google.protobuf.Message;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.logging.Logger;
+
+/**
+ * A tree representation of a FieldMask. Each leaf node in this tree represent
+ * a field path in the FieldMask.
+ *
+ * <p>For example, FieldMask "foo.bar,foo.baz,bar.baz" as a tree will be:
+ * <pre>
+ * [root] -+- foo -+- bar
+ * | |
+ * | +- baz
+ * |
+ * +- bar --- baz
+ * </pre>
+ *
+ * <p>By representing FieldMasks with this tree structure we can easily convert
+ * a FieldMask to a canonical form, merge two FieldMasks, calculate the
+ * intersection to two FieldMasks and traverse all fields specified by the
+ * FieldMask in a message tree.
+ */
+final class FieldMaskTree {
+ private static final Logger logger = Logger.getLogger(FieldMaskTree.class.getName());
+
+ private static final String FIELD_PATH_SEPARATOR_REGEX = "\\.";
+
+ private static final class Node {
+ final SortedMap<String, Node> children = new TreeMap<String, Node>();
+ }
+
+ private final Node root = new Node();
+
+ /**
+ * Creates an empty FieldMaskTree.
+ */
+ FieldMaskTree() {}
+
+ /**
+ * Creates a FieldMaskTree for a given FieldMask.
+ */
+ FieldMaskTree(FieldMask mask) {
+ mergeFromFieldMask(mask);
+ }
+
+ @Override
+ public String toString() {
+ return FieldMaskUtil.toString(toFieldMask());
+ }
+
+ /**
+ * Adds a field path to the tree. In a FieldMask, every field path matches the
+ * specified field as well as all its sub-fields. For example, a field path
+ * "foo.bar" matches field "foo.bar" and also "foo.bar.baz", etc. When adding
+ * a field path to the tree, redundant sub-paths will be removed. That is,
+ * after adding "foo.bar" to the tree, "foo.bar.baz" will be removed if it
+ * exists, which will turn the tree node for "foo.bar" to a leaf node.
+ * Likewise, if the field path to add is a sub-path of an existing leaf node,
+ * nothing will be changed in the tree.
+ */
+ FieldMaskTree addFieldPath(String path) {
+ String[] parts = path.split(FIELD_PATH_SEPARATOR_REGEX);
+ if (parts.length == 0) {
+ return this;
+ }
+ Node node = root;
+ boolean createNewBranch = false;
+ // Find the matching node in the tree.
+ for (String part : parts) {
+ // Check whether the path matches an existing leaf node.
+ if (!createNewBranch && node != root && node.children.isEmpty()) {
+ // The path to add is a sub-path of an existing leaf node.
+ return this;
+ }
+ if (node.children.containsKey(part)) {
+ node = node.children.get(part);
+ } else {
+ createNewBranch = true;
+ Node tmp = new Node();
+ node.children.put(part, tmp);
+ node = tmp;
+ }
+ }
+ // Turn the matching node into a leaf node (i.e., remove sub-paths).
+ node.children.clear();
+ return this;
+ }
+
+ /**
+ * Merges all field paths in a FieldMask into this tree.
+ */
+ FieldMaskTree mergeFromFieldMask(FieldMask mask) {
+ for (String path : mask.getPathsList()) {
+ addFieldPath(path);
+ }
+ return this;
+ }
+
+ /**
+ * Converts this tree to a FieldMask.
+ */
+ FieldMask toFieldMask() {
+ if (root.children.isEmpty()) {
+ return FieldMask.getDefaultInstance();
+ }
+ List<String> paths = new ArrayList<String>();
+ getFieldPaths(root, "", paths);
+ return FieldMask.newBuilder().addAllPaths(paths).build();
+ }
+
+ /**
+ * Gathers all field paths in a sub-tree.
+ */
+ private void getFieldPaths(Node node, String path, List<String> paths) {
+ if (node.children.isEmpty()) {
+ paths.add(path);
+ return;
+ }
+ for (Entry<String, Node> entry : node.children.entrySet()) {
+ String childPath = path.isEmpty() ? entry.getKey() : path + "." + entry.getKey();
+ getFieldPaths(entry.getValue(), childPath, paths);
+ }
+ }
+
+ /**
+ * Adds the intersection of this tree with the given {@code path} to {@code output}.
+ */
+ void intersectFieldPath(String path, FieldMaskTree output) {
+ if (root.children.isEmpty()) {
+ return;
+ }
+ String[] parts = path.split(FIELD_PATH_SEPARATOR_REGEX);
+ if (parts.length == 0) {
+ return;
+ }
+ Node node = root;
+ for (String part : parts) {
+ if (node != root && node.children.isEmpty()) {
+ // The given path is a sub-path of an existing leaf node in the tree.
+ output.addFieldPath(path);
+ return;
+ }
+ if (node.children.containsKey(part)) {
+ node = node.children.get(part);
+ } else {
+ return;
+ }
+ }
+ // We found a matching node for the path. All leaf children of this matching
+ // node is in the intersection.
+ List<String> paths = new ArrayList<String>();
+ getFieldPaths(node, path, paths);
+ for (String value : paths) {
+ output.addFieldPath(value);
+ }
+ }
+
+ /**
+ * Merges all fields specified by this FieldMaskTree from {@code source} to {@code destination}.
+ */
+ void merge(Message source, Message.Builder destination, FieldMaskUtil.MergeOptions options) {
+ if (source.getDescriptorForType() != destination.getDescriptorForType()) {
+ throw new IllegalArgumentException("Cannot merge messages of different types.");
+ }
+ if (root.children.isEmpty()) {
+ return;
+ }
+ merge(root, "", source, destination, options);
+ }
+
+ /**
+ * Merges all fields specified by a sub-tree from {@code source} to {@code destination}.
+ */
+ private void merge(
+ Node node,
+ String path,
+ Message source,
+ Message.Builder destination,
+ FieldMaskUtil.MergeOptions options) {
+ if (source.getDescriptorForType() != destination.getDescriptorForType()) {
+ throw new IllegalArgumentException(
+ String.format(
+ "source (%s) and destination (%s) descriptor must be equal",
+ source.getDescriptorForType(), destination.getDescriptorForType()));
+ }
+
+ Descriptor descriptor = source.getDescriptorForType();
+ for (Entry<String, Node> entry : node.children.entrySet()) {
+ FieldDescriptor field = descriptor.findFieldByName(entry.getKey());
+ if (field == null) {
+ logger.warning(
+ "Cannot find field \""
+ + entry.getKey()
+ + "\" in message type "
+ + descriptor.getFullName());
+ continue;
+ }
+ if (!entry.getValue().children.isEmpty()) {
+ if (field.isRepeated() || field.getJavaType() != FieldDescriptor.JavaType.MESSAGE) {
+ logger.warning(
+ "Field \""
+ + field.getFullName()
+ + "\" is not a "
+ + "singluar message field and cannot have sub-fields.");
+ continue;
+ }
+ String childPath = path.isEmpty() ? entry.getKey() : path + "." + entry.getKey();
+ merge(
+ entry.getValue(),
+ childPath,
+ (Message) source.getField(field),
+ destination.getFieldBuilder(field),
+ options);
+ continue;
+ }
+ if (field.isRepeated()) {
+ if (options.replaceRepeatedFields()) {
+ destination.setField(field, source.getField(field));
+ } else {
+ for (Object element : (List) source.getField(field)) {
+ destination.addRepeatedField(field, element);
+ }
+ }
+ } else {
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ if (options.replaceMessageFields()) {
+ if (!source.hasField(field)) {
+ destination.clearField(field);
+ } else {
+ destination.setField(field, source.getField(field));
+ }
+ } else {
+ if (source.hasField(field)) {
+ destination.getFieldBuilder(field).mergeFrom((Message) source.getField(field));
+ }
+ }
+ } else {
+ if (source.hasField(field) || !options.replacePrimitiveFields()) {
+ destination.setField(field, source.getField(field));
+ } else {
+ destination.clearField(field);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java b/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java
new file mode 100644
index 0000000000..21d11b2ce7
--- /dev/null
+++ b/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/FieldMaskUtil.java
@@ -0,0 +1,342 @@
+// 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.util;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import com.google.common.base.CaseFormat;
+import com.google.common.base.Joiner;
+import com.google.common.base.Splitter;
+import com.google.common.primitives.Ints;
+import com.google.protobuf.Descriptors.Descriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor;
+import com.google.protobuf.FieldMask;
+import com.google.protobuf.Internal;
+import com.google.protobuf.Message;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Utility helper functions to work with {@link com.google.protobuf.FieldMask}.
+ */
+public class FieldMaskUtil {
+ private static final String FIELD_PATH_SEPARATOR = ",";
+ private static final String FIELD_PATH_SEPARATOR_REGEX = ",";
+ private static final String FIELD_SEPARATOR_REGEX = "\\.";
+
+ private FieldMaskUtil() {}
+
+ /**
+ * Converts a FieldMask to a string.
+ */
+ public static String toString(FieldMask fieldMask) {
+ // TODO(xiaofeng): Consider using com.google.common.base.Joiner here instead.
+ StringBuilder result = new StringBuilder();
+ boolean first = true;
+ for (String value : fieldMask.getPathsList()) {
+ if (value.isEmpty()) {
+ // Ignore empty paths.
+ continue;
+ }
+ if (first) {
+ first = false;
+ } else {
+ result.append(FIELD_PATH_SEPARATOR);
+ }
+ result.append(value);
+ }
+ return result.toString();
+ }
+
+ /**
+ * Parses from a string to a FieldMask.
+ */
+ public static FieldMask fromString(String value) {
+ // TODO(xiaofeng): Consider using com.google.common.base.Splitter here instead.
+ return fromStringList(null, Arrays.asList(value.split(FIELD_PATH_SEPARATOR_REGEX)));
+ }
+
+ /**
+ * Parses from a string to a FieldMask and validates all field paths.
+ *
+ * @throws IllegalArgumentException if any of the field path is invalid.
+ */
+ public static FieldMask fromString(Class<? extends Message> type, String value) {
+ // TODO(xiaofeng): Consider using com.google.common.base.Splitter here instead.
+ return fromStringList(type, Arrays.asList(value.split(FIELD_PATH_SEPARATOR_REGEX)));
+ }
+
+ /**
+ * Constructs a FieldMask for a list of field paths in a certain type.
+ *
+ * @throws IllegalArgumentException if any of the field path is not valid.
+ */
+ // TODO(xiaofeng): Consider renaming fromStrings()
+ public static FieldMask fromStringList(Class<? extends Message> type, Iterable<String> paths) {
+ FieldMask.Builder builder = FieldMask.newBuilder();
+ for (String path : paths) {
+ if (path.isEmpty()) {
+ // Ignore empty field paths.
+ continue;
+ }
+ if (type != null && !isValid(type, path)) {
+ throw new IllegalArgumentException(path + " is not a valid path for " + type);
+ }
+ builder.addPaths(path);
+ }
+ return builder.build();
+ }
+
+ /**
+ * Constructs a FieldMask from the passed field numbers.
+ *
+ * @throws IllegalArgumentException if any of the fields are invalid for the message.
+ */
+ public static FieldMask fromFieldNumbers(Class<? extends Message> type, int... fieldNumbers) {
+ return fromFieldNumbers(type, Ints.asList(fieldNumbers));
+ }
+
+ /**
+ * Constructs a FieldMask from the passed field numbers.
+ *
+ * @throws IllegalArgumentException if any of the fields are invalid for the message.
+ */
+ public static FieldMask fromFieldNumbers(
+ Class<? extends Message> type, Iterable<Integer> fieldNumbers) {
+ Descriptor descriptor = Internal.getDefaultInstance(type).getDescriptorForType();
+
+ FieldMask.Builder builder = FieldMask.newBuilder();
+ for (Integer fieldNumber : fieldNumbers) {
+ FieldDescriptor field = descriptor.findFieldByNumber(fieldNumber);
+ checkArgument(
+ field != null,
+ String.format("%s is not a valid field number for %s.", fieldNumber, type));
+ builder.addPaths(field.getName());
+ }
+ return builder.build();
+ }
+
+ /**
+ * Converts a field mask to a Proto3 JSON string, that is converting from snake case to camel
+ * case and joining all paths into one string with commas.
+ */
+ public static String toJsonString(FieldMask fieldMask) {
+ List<String> paths = new ArrayList<String>(fieldMask.getPathsCount());
+ for (String path : fieldMask.getPathsList()) {
+ if (path.isEmpty()) {
+ continue;
+ }
+ paths.add(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, path));
+ }
+ return Joiner.on(FIELD_PATH_SEPARATOR).join(paths);
+ }
+
+ /**
+ * Converts a field mask from a Proto3 JSON string, that is splitting the paths along commas and
+ * converting from camel case to snake case.
+ */
+ public static FieldMask fromJsonString(String value) {
+ Iterable<String> paths = Splitter.on(FIELD_PATH_SEPARATOR).split(value);
+ FieldMask.Builder builder = FieldMask.newBuilder();
+ for (String path : paths) {
+ if (path.isEmpty()) {
+ continue;
+ }
+ builder.addPaths(CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, path));
+ }
+ return builder.build();
+ }
+
+ /**
+ * Checks whether paths in a given fields mask are valid.
+ */
+ public static boolean isValid(Class<? extends Message> type, FieldMask fieldMask) {
+ Descriptor descriptor = Internal.getDefaultInstance(type).getDescriptorForType();
+
+ return isValid(descriptor, fieldMask);
+ }
+
+ /**
+ * Checks whether paths in a given fields mask are valid.
+ */
+ public static boolean isValid(Descriptor descriptor, FieldMask fieldMask) {
+ for (String path : fieldMask.getPathsList()) {
+ if (!isValid(descriptor, path)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Checks whether a given field path is valid.
+ */
+ public static boolean isValid(Class<? extends Message> type, String path) {
+ Descriptor descriptor = Internal.getDefaultInstance(type).getDescriptorForType();
+
+ return isValid(descriptor, path);
+ }
+
+ /**
+ * Checks whether paths in a given fields mask are valid.
+ */
+ public static boolean isValid(Descriptor descriptor, String path) {
+ String[] parts = path.split(FIELD_SEPARATOR_REGEX);
+ if (parts.length == 0) {
+ return false;
+ }
+ for (String name : parts) {
+ if (descriptor == null) {
+ return false;
+ }
+ FieldDescriptor field = descriptor.findFieldByName(name);
+ if (field == null) {
+ return false;
+ }
+ if (!field.isRepeated() && field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
+ descriptor = field.getMessageType();
+ } else {
+ descriptor = null;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Converts a FieldMask to its canonical form. In the canonical form of a
+ * FieldMask, all field paths are sorted alphabetically and redundant field
+ * paths are moved.
+ */
+ public static FieldMask normalize(FieldMask mask) {
+ return new FieldMaskTree(mask).toFieldMask();
+ }
+
+ /**
+ * Creates a union of two or more FieldMasks.
+ */
+ public static FieldMask union(
+ FieldMask firstMask, FieldMask secondMask, FieldMask... otherMasks) {
+ FieldMaskTree maskTree = new FieldMaskTree(firstMask).mergeFromFieldMask(secondMask);
+ for (FieldMask mask : otherMasks) {
+ maskTree.mergeFromFieldMask(mask);
+ }
+ return maskTree.toFieldMask();
+ }
+
+ /**
+ * Calculates the intersection of two FieldMasks.
+ */
+ public static FieldMask intersection(FieldMask mask1, FieldMask mask2) {
+ FieldMaskTree tree = new FieldMaskTree(mask1);
+ FieldMaskTree result = new FieldMaskTree();
+ for (String path : mask2.getPathsList()) {
+ tree.intersectFieldPath(path, result);
+ }
+ return result.toFieldMask();
+ }
+
+ /**
+ * Options to customize merging behavior.
+ */
+ public static final class MergeOptions {
+ private boolean replaceMessageFields = false;
+ private boolean replaceRepeatedFields = false;
+ // TODO(b/28277137): change the default behavior to always replace primitive fields after
+ // fixing all failing TAP tests.
+ private boolean replacePrimitiveFields = false;
+
+ /**
+ * Whether to replace message fields (i.e., discard existing content in
+ * destination message fields) when merging.
+ * Default behavior is to merge the source message field into the
+ * destination message field.
+ */
+ public boolean replaceMessageFields() {
+ return replaceMessageFields;
+ }
+
+ /**
+ * Whether to replace repeated fields (i.e., discard existing content in
+ * destination repeated fields) when merging.
+ * Default behavior is to append elements from source repeated field to the
+ * destination repeated field.
+ */
+ public boolean replaceRepeatedFields() {
+ return replaceRepeatedFields;
+ }
+
+ /**
+ * Whether to replace primitive (non-repeated and non-message) fields in
+ * destination message fields with the source primitive fields (i.e., if the
+ * field is set in the source, the value is copied to the
+ * destination; if the field is unset in the source, the field is cleared
+ * from the destination) when merging.
+ *
+ * <p>Default behavior is to always set the value of the source primitive
+ * field to the destination primitive field, and if the source field is
+ * unset, the default value of the source field is copied to the
+ * destination.
+ */
+ public boolean replacePrimitiveFields() {
+ return replacePrimitiveFields;
+ }
+
+ public void setReplaceMessageFields(boolean value) {
+ replaceMessageFields = value;
+ }
+
+ public void setReplaceRepeatedFields(boolean value) {
+ replaceRepeatedFields = value;
+ }
+
+ public void setReplacePrimitiveFields(boolean value) {
+ replacePrimitiveFields = value;
+ }
+ }
+
+ /**
+ * Merges fields specified by a FieldMask from one message to another with the
+ * specified merge options.
+ */
+ public static void merge(
+ FieldMask mask, Message source, Message.Builder destination, MergeOptions options) {
+ new FieldMaskTree(mask).merge(source, destination, options);
+ }
+
+ /**
+ * Merges fields specified by a FieldMask from one message to another.
+ */
+ public static void merge(FieldMask mask, Message source, Message.Builder destination) {
+ merge(mask, source, destination, new MergeOptions());
+ }
+}
diff --git a/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java b/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
new file mode 100644
index 0000000000..838700f7f6
--- /dev/null
+++ b/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
@@ -0,0 +1,1766 @@
+// 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.util;
+
+import com.google.common.io.BaseEncoding;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonIOException;
+import com.google.gson.JsonNull;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.stream.JsonReader;
+import com.google.protobuf.Any;
+import com.google.protobuf.BoolValue;
+import com.google.protobuf.ByteString;
+import com.google.protobuf.BytesValue;
+import com.google.protobuf.Descriptors.Descriptor;
+import com.google.protobuf.Descriptors.EnumDescriptor;
+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.DoubleValue;
+import com.google.protobuf.Duration;
+import com.google.protobuf.DynamicMessage;
+import com.google.protobuf.FieldMask;
+import com.google.protobuf.FloatValue;
+import com.google.protobuf.Int32Value;
+import com.google.protobuf.Int64Value;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.google.protobuf.ListValue;
+import com.google.protobuf.Message;
+import com.google.protobuf.MessageOrBuilder;
+import com.google.protobuf.NullValue;
+import com.google.protobuf.StringValue;
+import com.google.protobuf.Struct;
+import com.google.protobuf.Timestamp;
+import com.google.protobuf.UInt32Value;
+import com.google.protobuf.UInt64Value;
+import com.google.protobuf.Value;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.text.ParseException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.logging.Logger;
+
+/**
+ * Utility classes to convert protobuf messages to/from JSON format. The JSON
+ * format follows Proto3 JSON specification and only proto3 features are
+ * supported. Proto2 only features (e.g., extensions and unknown fields) will
+ * be discarded in the conversion. That is, when converting proto2 messages
+ * to JSON format, extensions and unknown fields will be treated as if they
+ * do not exist. This applies to proto2 messages embedded in proto3 messages
+ * as well.
+ */
+public class JsonFormat {
+ private static final Logger logger = Logger.getLogger(JsonFormat.class.getName());
+
+ private JsonFormat() {}
+
+ /**
+ * Creates a {@link Printer} with default configurations.
+ */
+ public static Printer printer() {
+ return new Printer(TypeRegistry.getEmptyTypeRegistry(), false, false, false);
+ }
+
+ /**
+ * A Printer converts protobuf message to JSON format.
+ */
+ public static class Printer {
+ private final TypeRegistry registry;
+ private final boolean includingDefaultValueFields;
+ private final boolean preservingProtoFieldNames;
+ private final boolean omittingInsignificantWhitespace;
+
+ private Printer(
+ TypeRegistry registry,
+ boolean includingDefaultValueFields,
+ boolean preservingProtoFieldNames,
+ boolean omittingInsignificantWhitespace) {
+ this.registry = registry;
+ this.includingDefaultValueFields = includingDefaultValueFields;
+ this.preservingProtoFieldNames = preservingProtoFieldNames;
+ this.omittingInsignificantWhitespace = omittingInsignificantWhitespace;
+ }
+
+ /**
+ * Creates a new {@link Printer} using the given registry. The new Printer
+ * clones all other configurations from the current {@link Printer}.
+ *
+ * @throws IllegalArgumentException if a registry is already set.
+ */
+ public Printer usingTypeRegistry(TypeRegistry registry) {
+ if (this.registry != TypeRegistry.getEmptyTypeRegistry()) {
+ throw new IllegalArgumentException("Only one registry is allowed.");
+ }
+ return new Printer(
+ registry,
+ includingDefaultValueFields,
+ preservingProtoFieldNames,
+ omittingInsignificantWhitespace);
+ }
+
+ /**
+ * Creates a new {@link Printer} that will also print fields set to their
+ * defaults. Empty repeated fields and map fields will be printed as well.
+ * The new Printer clones all other configurations from the current
+ * {@link Printer}.
+ */
+ public Printer includingDefaultValueFields() {
+ return new Printer(
+ registry, true, preservingProtoFieldNames, omittingInsignificantWhitespace);
+ }
+
+ /**
+ * Creates a new {@link Printer} that is configured to use the original proto
+ * field names as defined in the .proto file rather than converting them to
+ * lowerCamelCase. The new Printer clones all other configurations from the
+ * current {@link Printer}.
+ */
+ public Printer preservingProtoFieldNames() {
+ return new Printer(
+ registry, includingDefaultValueFields, true, omittingInsignificantWhitespace);
+ }
+
+
+ /**
+ * Create a new {@link Printer} that will omit all insignificant whitespace
+ * in the JSON output. This new Printer clones all other configurations from the
+ * current Printer. Insignificant whitespace is defined by the JSON spec as whitespace
+ * that appear between JSON structural elements:
+ * <pre>
+ * ws = *(
+ * %x20 / ; Space
+ * %x09 / ; Horizontal tab
+ * %x0A / ; Line feed or New line
+ * %x0D ) ; Carriage return
+ * </pre>
+ * See <a href="https://tools.ietf.org/html/rfc7159">https://tools.ietf.org/html/rfc7159</a>
+ * current {@link Printer}.
+ */
+ public Printer omittingInsignificantWhitespace() {
+ return new Printer(registry, includingDefaultValueFields, preservingProtoFieldNames, true);
+ }
+
+ /**
+ * Converts a protobuf message to JSON format.
+ *
+ * @throws InvalidProtocolBufferException if the message contains Any types
+ * that can't be resolved.
+ * @throws IOException if writing to the output fails.
+ */
+ public void appendTo(MessageOrBuilder message, Appendable output) throws IOException {
+ // TODO(xiaofeng): Investigate the allocation overhead and optimize for
+ // mobile.
+ new PrinterImpl(
+ registry,
+ includingDefaultValueFields,
+ preservingProtoFieldNames,
+ output,
+ omittingInsignificantWhitespace)
+ .print(message);
+ }
+
+ /**
+ * Converts a protobuf message to JSON format. Throws exceptions if there
+ * are unknown Any types in the message.
+ */
+ public String print(MessageOrBuilder message) throws InvalidProtocolBufferException {
+ try {
+ StringBuilder builder = new StringBuilder();
+ appendTo(message, builder);
+ return builder.toString();
+ } catch (InvalidProtocolBufferException e) {
+ throw e;
+ } catch (IOException e) {
+ // Unexpected IOException.
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+
+ /**
+ * Creates a {@link Parser} with default configuration.
+ */
+ public static Parser parser() {
+ return new Parser(TypeRegistry.getEmptyTypeRegistry(), false, Parser.DEFAULT_RECURSION_LIMIT);
+ }
+
+ /**
+ * A Parser parses JSON to protobuf message.
+ */
+ public static class Parser {
+ private final TypeRegistry registry;
+ private final boolean ignoringUnknownFields;
+ private final int recursionLimit;
+
+ // The default parsing recursion limit is aligned with the proto binary parser.
+ private static final int DEFAULT_RECURSION_LIMIT = 100;
+
+ private Parser(TypeRegistry registry, boolean ignoreUnknownFields, int recursionLimit) {
+ this.registry = registry;
+ this.ignoringUnknownFields = ignoreUnknownFields;
+ this.recursionLimit = recursionLimit;
+ }
+
+ /**
+ * Creates a new {@link Parser} using the given registry. The new Parser
+ * clones all other configurations from this Parser.
+ *
+ * @throws IllegalArgumentException if a registry is already set.
+ */
+ public Parser usingTypeRegistry(TypeRegistry registry) {
+ if (this.registry != TypeRegistry.getEmptyTypeRegistry()) {
+ throw new IllegalArgumentException("Only one registry is allowed.");
+ }
+ return new Parser(registry, ignoringUnknownFields, recursionLimit);
+ }
+
+ /**
+ * Creates a new {@link Parser} configured to not throw an exception when an unknown field is
+ * encountered. The new Parser clones all other configurations from this Parser.
+ */
+ public Parser ignoringUnknownFields() {
+ return new Parser(this.registry, true, recursionLimit);
+ }
+
+ /**
+ * Parses from JSON into a protobuf message.
+ *
+ * @throws InvalidProtocolBufferException if the input is not valid JSON
+ * format or there are unknown fields in the input.
+ */
+ public void merge(String json, Message.Builder builder) throws InvalidProtocolBufferException {
+ // TODO(xiaofeng): Investigate the allocation overhead and optimize for
+ // mobile.
+ new ParserImpl(registry, ignoringUnknownFields, recursionLimit).merge(json, builder);
+ }
+
+ /**
+ * Parses from JSON into a protobuf message.
+ *
+ * @throws InvalidProtocolBufferException if the input is not valid JSON
+ * format or there are unknown fields in the input.
+ * @throws IOException if reading from the input throws.
+ */
+ public void merge(Reader json, Message.Builder builder) throws IOException {
+ // TODO(xiaofeng): Investigate the allocation overhead and optimize for
+ // mobile.
+ new ParserImpl(registry, ignoringUnknownFields, recursionLimit).merge(json, builder);
+ }
+
+ // For testing only.
+ Parser usingRecursionLimit(int recursionLimit) {
+ return new Parser(registry, ignoringUnknownFields, recursionLimit);
+ }
+ }
+
+ /**
+ * A TypeRegistry is used to resolve Any messages in the JSON conversion.
+ * You must provide a TypeRegistry containing all message types used in
+ * Any message fields, or the JSON conversion will fail because data
+ * in Any message fields is unrecognizable. You don't need to supply a
+ * TypeRegistry if you don't use Any message fields.
+ */
+ public static class TypeRegistry {
+ private static class EmptyTypeRegistryHolder {
+ private static final TypeRegistry EMPTY =
+ new TypeRegistry(Collections.<String, Descriptor>emptyMap());
+ }
+
+ public static TypeRegistry getEmptyTypeRegistry() {
+ return EmptyTypeRegistryHolder.EMPTY;
+ }
+
+ public static Builder newBuilder() {
+ return new Builder();
+ }
+
+ /**
+ * Find a type by its full name. Returns null if it cannot be found in
+ * this {@link TypeRegistry}.
+ */
+ public Descriptor find(String name) {
+ return types.get(name);
+ }
+
+ private final Map<String, Descriptor> types;
+
+ private TypeRegistry(Map<String, Descriptor> types) {
+ this.types = types;
+ }
+
+ /**
+ * A Builder is used to build {@link TypeRegistry}.
+ */
+ public static class Builder {
+ private Builder() {}
+
+ /**
+ * Adds a message type and all types defined in the same .proto file as
+ * well as all transitively imported .proto files to this {@link Builder}.
+ */
+ public Builder add(Descriptor messageType) {
+ if (types == null) {
+ throw new IllegalStateException("A TypeRegistry.Builer can only be used once.");
+ }
+ addFile(messageType.getFile());
+ return this;
+ }
+
+ /**
+ * Adds message types and all types defined in the same .proto file as
+ * well as all transitively imported .proto files to this {@link Builder}.
+ */
+ public Builder add(Iterable<Descriptor> messageTypes) {
+ if (types == null) {
+ throw new IllegalStateException("A TypeRegistry.Builer can only be used once.");
+ }
+ for (Descriptor type : messageTypes) {
+ addFile(type.getFile());
+ }
+ return this;
+ }
+
+ /**
+ * Builds a {@link TypeRegistry}. This method can only be called once for
+ * one Builder.
+ */
+ public TypeRegistry build() {
+ TypeRegistry result = new TypeRegistry(types);
+ // Make sure the built {@link TypeRegistry} is immutable.
+ types = null;
+ return result;
+ }
+
+ private void addFile(FileDescriptor file) {
+ // Skip the file if it's already added.
+ if (!files.add(file.getFullName())) {
+ return;
+ }
+ for (FileDescriptor dependency : file.getDependencies()) {
+ addFile(dependency);
+ }
+ for (Descriptor message : file.getMessageTypes()) {
+ addMessage(message);
+ }
+ }
+
+ private void addMessage(Descriptor message) {
+ for (Descriptor nestedType : message.getNestedTypes()) {
+ addMessage(nestedType);
+ }
+
+ if (types.containsKey(message.getFullName())) {
+ logger.warning("Type " + message.getFullName() + " is added multiple times.");
+ return;
+ }
+
+ types.put(message.getFullName(), message);
+ }
+
+ private final Set<String> files = new HashSet<String>();
+ private Map<String, Descriptor> types = new HashMap<String, Descriptor>();
+ }
+ }
+
+ /**
+ * An interface for json formatting that can be used in
+ * combination with the omittingInsignificantWhitespace() method
+ */
+ interface TextGenerator {
+ void indent();
+
+ void outdent();
+
+ void print(final CharSequence text) throws IOException;
+ }
+
+ /**
+ * Format the json without indentation
+ */
+ private static final class CompactTextGenerator implements TextGenerator {
+ private final Appendable output;
+
+ private CompactTextGenerator(final Appendable output) {
+ this.output = output;
+ }
+
+ /**
+ * ignored by compact printer
+ */
+ public void indent() {}
+
+ /**
+ * ignored by compact printer
+ */
+ public void outdent() {}
+
+ /**
+ * Print text to the output stream.
+ */
+ public void print(final CharSequence text) throws IOException {
+ output.append(text);
+ }
+ }
+ /**
+ * A TextGenerator adds indentation when writing formatted text.
+ */
+ private static final class PrettyTextGenerator implements TextGenerator {
+ private final Appendable output;
+ private final StringBuilder indent = new StringBuilder();
+ private boolean atStartOfLine = true;
+
+ private PrettyTextGenerator(final Appendable output) {
+ this.output = output;
+ }
+
+ /**
+ * Indent text by two spaces. After calling Indent(), two spaces will be
+ * inserted at the beginning of each line of text. Indent() may be called
+ * multiple times to produce deeper indents.
+ */
+ public void indent() {
+ indent.append(" ");
+ }
+
+ /**
+ * Reduces the current indent level by two spaces, or crashes if the indent
+ * level is zero.
+ */
+ public void outdent() {
+ final int length = indent.length();
+ if (length < 2) {
+ throw new IllegalArgumentException(" Outdent() without matching Indent().");
+ }
+ indent.delete(length - 2, length);
+ }
+
+ /**
+ * Print text to the output stream.
+ */
+ public void print(final CharSequence text) throws IOException {
+ final int size = text.length();
+ int pos = 0;
+
+ for (int i = 0; i < size; i++) {
+ if (text.charAt(i) == '\n') {
+ write(text.subSequence(pos, i + 1));
+ pos = i + 1;
+ atStartOfLine = true;
+ }
+ }
+ write(text.subSequence(pos, size));
+ }
+
+ private void write(final CharSequence data) throws IOException {
+ if (data.length() == 0) {
+ return;
+ }
+ if (atStartOfLine) {
+ atStartOfLine = false;
+ output.append(indent);
+ }
+ output.append(data);
+ }
+ }
+
+ /**
+ * A Printer converts protobuf messages to JSON format.
+ */
+ private static final class PrinterImpl {
+ private final TypeRegistry registry;
+ private final boolean includingDefaultValueFields;
+ private final boolean preservingProtoFieldNames;
+ private final TextGenerator generator;
+ // We use Gson to help handle string escapes.
+ private final Gson gson;
+ private final CharSequence blankOrSpace;
+ private final CharSequence blankOrNewLine;
+
+ private static class GsonHolder {
+ private static final Gson DEFAULT_GSON = new GsonBuilder().disableHtmlEscaping().create();
+ }
+
+ PrinterImpl(
+ TypeRegistry registry,
+ boolean includingDefaultValueFields,
+ boolean preservingProtoFieldNames,
+ Appendable jsonOutput,
+ boolean omittingInsignificantWhitespace) {
+ this.registry = registry;
+ this.includingDefaultValueFields = includingDefaultValueFields;
+ this.preservingProtoFieldNames = preservingProtoFieldNames;
+ this.gson = GsonHolder.DEFAULT_GSON;
+ // json format related properties, determined by printerType
+ if (omittingInsignificantWhitespace) {
+ this.generator = new CompactTextGenerator(jsonOutput);
+ this.blankOrSpace = "";
+ this.blankOrNewLine = "";
+ } else {
+ this.generator = new PrettyTextGenerator(jsonOutput);
+ this.blankOrSpace = " ";
+ this.blankOrNewLine = "\n";
+ }
+ }
+
+ void print(MessageOrBuilder message) throws IOException {
+ WellKnownTypePrinter specialPrinter =
+ wellKnownTypePrinters.get(message.getDescriptorForType().getFullName());
+ if (specialPrinter != null) {
+ specialPrinter.print(this, message);
+ return;
+ }
+ print(message, null);
+ }
+
+ private interface WellKnownTypePrinter {
+ void print(PrinterImpl printer, MessageOrBuilder message) throws IOException;
+ }
+
+ private static final Map<String, WellKnownTypePrinter> wellKnownTypePrinters =
+ buildWellKnownTypePrinters();
+
+ private static Map<String, WellKnownTypePrinter> buildWellKnownTypePrinters() {
+ Map<String, WellKnownTypePrinter> printers = new HashMap<String, WellKnownTypePrinter>();
+ // Special-case Any.
+ printers.put(
+ Any.getDescriptor().getFullName(),
+ new WellKnownTypePrinter() {
+ @Override
+ public void print(PrinterImpl printer, MessageOrBuilder message) throws IOException {
+ printer.printAny(message);
+ }
+ });
+ // Special-case wrapper types.
+ WellKnownTypePrinter wrappersPrinter =
+ new WellKnownTypePrinter() {
+ @Override
+ public void print(PrinterImpl printer, MessageOrBuilder message) throws IOException {
+ printer.printWrapper(message);
+ }
+ };
+ printers.put(BoolValue.getDescriptor().getFullName(), wrappersPrinter);
+ printers.put(Int32Value.getDescriptor().getFullName(), wrappersPrinter);
+ printers.put(UInt32Value.getDescriptor().getFullName(), wrappersPrinter);
+ printers.put(Int64Value.getDescriptor().getFullName(), wrappersPrinter);
+ printers.put(UInt64Value.getDescriptor().getFullName(), wrappersPrinter);
+ printers.put(StringValue.getDescriptor().getFullName(), wrappersPrinter);
+ printers.put(BytesValue.getDescriptor().getFullName(), wrappersPrinter);
+ printers.put(FloatValue.getDescriptor().getFullName(), wrappersPrinter);
+ printers.put(DoubleValue.getDescriptor().getFullName(), wrappersPrinter);
+ // Special-case Timestamp.
+ printers.put(
+ Timestamp.getDescriptor().getFullName(),
+ new WellKnownTypePrinter() {
+ @Override
+ public void print(PrinterImpl printer, MessageOrBuilder message) throws IOException {
+ printer.printTimestamp(message);
+ }
+ });
+ // Special-case Duration.
+ printers.put(
+ Duration.getDescriptor().getFullName(),
+ new WellKnownTypePrinter() {
+ @Override
+ public void print(PrinterImpl printer, MessageOrBuilder message) throws IOException {
+ printer.printDuration(message);
+ }
+ });
+ // Special-case FieldMask.
+ printers.put(
+ FieldMask.getDescriptor().getFullName(),
+ new WellKnownTypePrinter() {
+ @Override
+ public void print(PrinterImpl printer, MessageOrBuilder message) throws IOException {
+ printer.printFieldMask(message);
+ }
+ });
+ // Special-case Struct.
+ printers.put(
+ Struct.getDescriptor().getFullName(),
+ new WellKnownTypePrinter() {
+ @Override
+ public void print(PrinterImpl printer, MessageOrBuilder message) throws IOException {
+ printer.printStruct(message);
+ }
+ });
+ // Special-case Value.
+ printers.put(
+ Value.getDescriptor().getFullName(),
+ new WellKnownTypePrinter() {
+ @Override
+ public void print(PrinterImpl printer, MessageOrBuilder message) throws IOException {
+ printer.printValue(message);
+ }
+ });
+ // Special-case ListValue.
+ printers.put(
+ ListValue.getDescriptor().getFullName(),
+ new WellKnownTypePrinter() {
+ @Override
+ public void print(PrinterImpl printer, MessageOrBuilder message) throws IOException {
+ printer.printListValue(message);
+ }
+ });
+ return printers;
+ }
+
+ /** 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");
+ // Validates type of the message. Note that we can't just cast the message
+ // to com.google.protobuf.Any because it might be a DynamicMessage.
+ if (typeUrlField == null
+ || valueField == null
+ || typeUrlField.getType() != FieldDescriptor.Type.STRING
+ || valueField.getType() != FieldDescriptor.Type.BYTES) {
+ throw new InvalidProtocolBufferException("Invalid Any type.");
+ }
+ String typeUrl = (String) message.getField(typeUrlField);
+ String typeName = getTypeName(typeUrl);
+ Descriptor type = registry.find(typeName);
+ if (type == null) {
+ throw new InvalidProtocolBufferException("Cannot find type for url: " + typeUrl);
+ }
+ ByteString content = (ByteString) message.getField(valueField);
+ Message contentMessage =
+ DynamicMessage.getDefaultInstance(type).getParserForType().parseFrom(content);
+ WellKnownTypePrinter printer = wellKnownTypePrinters.get(typeName);
+ if (printer != null) {
+ // If the type is one of the well-known types, we use a special
+ // formatting.
+ generator.print("{" + blankOrNewLine);
+ generator.indent();
+ generator.print("\"@type\":" + blankOrSpace + gson.toJson(typeUrl) + "," + blankOrNewLine);
+ generator.print("\"value\":" + blankOrSpace);
+ printer.print(this, contentMessage);
+ generator.print(blankOrNewLine);
+ generator.outdent();
+ generator.print("}");
+ } else {
+ // Print the content message instead (with a "@type" field added).
+ print(contentMessage, typeUrl);
+ }
+ }
+
+ /** Prints wrapper types (e.g., google.protobuf.Int32Value) */
+ private void printWrapper(MessageOrBuilder message) throws IOException {
+ Descriptor descriptor = message.getDescriptorForType();
+ FieldDescriptor valueField = descriptor.findFieldByName("value");
+ if (valueField == null) {
+ throw new InvalidProtocolBufferException("Invalid Wrapper type.");
+ }
+ // When formatting wrapper types, we just print its value field instead of
+ // the whole message.
+ printSingleFieldValue(valueField, message.getField(valueField));
+ }
+
+ private ByteString toByteString(MessageOrBuilder message) {
+ if (message instanceof Message) {
+ return ((Message) message).toByteString();
+ } else {
+ return ((Message.Builder) message).build().toByteString();
+ }
+ }
+
+ /** Prints google.protobuf.Timestamp */
+ private void printTimestamp(MessageOrBuilder message) throws IOException {
+ Timestamp value = Timestamp.parseFrom(toByteString(message));
+ generator.print("\"" + Timestamps.toString(value) + "\"");
+ }
+
+ /** Prints google.protobuf.Duration */
+ private void printDuration(MessageOrBuilder message) throws IOException {
+ Duration value = Duration.parseFrom(toByteString(message));
+ generator.print("\"" + Durations.toString(value) + "\"");
+ }
+
+ /** Prints google.protobuf.FieldMask */
+ private void printFieldMask(MessageOrBuilder message) throws IOException {
+ FieldMask value = FieldMask.parseFrom(toByteString(message));
+ generator.print("\"" + FieldMaskUtil.toJsonString(value) + "\"");
+ }
+
+ /** Prints google.protobuf.Struct */
+ private void printStruct(MessageOrBuilder message) throws IOException {
+ Descriptor descriptor = message.getDescriptorForType();
+ FieldDescriptor field = descriptor.findFieldByName("fields");
+ if (field == null) {
+ throw new InvalidProtocolBufferException("Invalid Struct type.");
+ }
+ // Struct is formatted as a map object.
+ printMapFieldValue(field, message.getField(field));
+ }
+
+ /** Prints google.protobuf.Value */
+ private void printValue(MessageOrBuilder message) throws IOException {
+ // For a Value message, only the value of the field is formatted.
+ Map<FieldDescriptor, Object> fields = message.getAllFields();
+ if (fields.isEmpty()) {
+ // No value set.
+ generator.print("null");
+ return;
+ }
+ // A Value message can only have at most one field set (it only contains
+ // an oneof).
+ if (fields.size() != 1) {
+ throw new InvalidProtocolBufferException("Invalid Value type.");
+ }
+ for (Map.Entry<FieldDescriptor, Object> entry : fields.entrySet()) {
+ printSingleFieldValue(entry.getKey(), entry.getValue());
+ }
+ }
+
+ /** Prints google.protobuf.ListValue */
+ private void printListValue(MessageOrBuilder message) throws IOException {
+ Descriptor descriptor = message.getDescriptorForType();
+ FieldDescriptor field = descriptor.findFieldByName("values");
+ if (field == null) {
+ throw new InvalidProtocolBufferException("Invalid ListValue type.");
+ }
+ printRepeatedFieldValue(field, message.getField(field));
+ }
+
+ /** Prints a regular message with an optional type URL. */
+ private void print(MessageOrBuilder message, String typeUrl) throws IOException {
+ generator.print("{" + blankOrNewLine);
+ generator.indent();
+
+ boolean printedField = false;
+ if (typeUrl != null) {
+ generator.print("\"@type\":" + blankOrSpace + gson.toJson(typeUrl));
+ printedField = true;
+ }
+ Map<FieldDescriptor, Object> fieldsToPrint = null;
+ if (includingDefaultValueFields) {
+ fieldsToPrint = new TreeMap<FieldDescriptor, Object>();
+ for (FieldDescriptor field : message.getDescriptorForType().getFields()) {
+ if (field.isOptional()) {
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE
+ && !message.hasField(field)){
+ // Always skip empty optional message fields. If not we will recurse indefinitely if
+ // a message has itself as a sub-field.
+ continue;
+ }
+ OneofDescriptor oneof = field.getContainingOneof();
+ if (oneof != null && !message.hasField(field)) {
+ // Skip all oneof fields except the one that is actually set
+ continue;
+ }
+ }
+ fieldsToPrint.put(field, message.getField(field));
+ }
+ } else {
+ fieldsToPrint = message.getAllFields();
+ }
+ for (Map.Entry<FieldDescriptor, Object> field : fieldsToPrint.entrySet()) {
+ if (printedField) {
+ // Add line-endings for the previous field.
+ generator.print("," + blankOrNewLine);
+ } else {
+ printedField = true;
+ }
+ printField(field.getKey(), field.getValue());
+ }
+
+ // Add line-endings for the last field.
+ if (printedField) {
+ generator.print(blankOrNewLine);
+ }
+ generator.outdent();
+ generator.print("}");
+ }
+
+ private void printField(FieldDescriptor field, Object value) throws IOException {
+ if (preservingProtoFieldNames) {
+ generator.print("\"" + field.getName() + "\":" + blankOrSpace);
+ } else {
+ generator.print("\"" + field.getJsonName() + "\":" + blankOrSpace);
+ }
+ if (field.isMapField()) {
+ printMapFieldValue(field, value);
+ } else if (field.isRepeated()) {
+ printRepeatedFieldValue(field, value);
+ } else {
+ printSingleFieldValue(field, value);
+ }
+ }
+
+ @SuppressWarnings("rawtypes")
+ private void printRepeatedFieldValue(FieldDescriptor field, Object value) throws IOException {
+ generator.print("[");
+ boolean printedElement = false;
+ for (Object element : (List) value) {
+ if (printedElement) {
+ generator.print("," + blankOrSpace);
+ } else {
+ printedElement = true;
+ }
+ printSingleFieldValue(field, element);
+ }
+ generator.print("]");
+ }
+
+ @SuppressWarnings("rawtypes")
+ private void printMapFieldValue(FieldDescriptor field, Object value) throws IOException {
+ Descriptor type = field.getMessageType();
+ FieldDescriptor keyField = type.findFieldByName("key");
+ FieldDescriptor valueField = type.findFieldByName("value");
+ if (keyField == null || valueField == null) {
+ throw new InvalidProtocolBufferException("Invalid map field.");
+ }
+ generator.print("{" + blankOrNewLine);
+ generator.indent();
+ boolean printedElement = false;
+ for (Object element : (List) value) {
+ Message entry = (Message) element;
+ Object entryKey = entry.getField(keyField);
+ Object entryValue = entry.getField(valueField);
+ if (printedElement) {
+ generator.print("," + blankOrNewLine);
+ } else {
+ printedElement = true;
+ }
+ // Key fields are always double-quoted.
+ printSingleFieldValue(keyField, entryKey, true);
+ generator.print(":" + blankOrSpace);
+ printSingleFieldValue(valueField, entryValue);
+ }
+ if (printedElement) {
+ generator.print(blankOrNewLine);
+ }
+ generator.outdent();
+ generator.print("}");
+ }
+
+ private void printSingleFieldValue(FieldDescriptor field, Object value) throws IOException {
+ printSingleFieldValue(field, value, false);
+ }
+
+ /**
+ * Prints a field's value in JSON format.
+ *
+ * @param alwaysWithQuotes whether to always add double-quotes to primitive
+ * types.
+ */
+ private void printSingleFieldValue(
+ final FieldDescriptor field, final Object value, boolean alwaysWithQuotes)
+ throws IOException {
+ switch (field.getType()) {
+ case INT32:
+ case SINT32:
+ case SFIXED32:
+ if (alwaysWithQuotes) {
+ generator.print("\"");
+ }
+ generator.print(((Integer) value).toString());
+ if (alwaysWithQuotes) {
+ generator.print("\"");
+ }
+ break;
+
+ case INT64:
+ case SINT64:
+ case SFIXED64:
+ generator.print("\"" + ((Long) value).toString() + "\"");
+ break;
+
+ case BOOL:
+ if (alwaysWithQuotes) {
+ generator.print("\"");
+ }
+ if (((Boolean) value).booleanValue()) {
+ generator.print("true");
+ } else {
+ generator.print("false");
+ }
+ if (alwaysWithQuotes) {
+ generator.print("\"");
+ }
+ break;
+
+ case FLOAT:
+ Float floatValue = (Float) value;
+ if (floatValue.isNaN()) {
+ generator.print("\"NaN\"");
+ } else if (floatValue.isInfinite()) {
+ if (floatValue < 0) {
+ generator.print("\"-Infinity\"");
+ } else {
+ generator.print("\"Infinity\"");
+ }
+ } else {
+ if (alwaysWithQuotes) {
+ generator.print("\"");
+ }
+ generator.print(floatValue.toString());
+ if (alwaysWithQuotes) {
+ generator.print("\"");
+ }
+ }
+ break;
+
+ case DOUBLE:
+ Double doubleValue = (Double) value;
+ if (doubleValue.isNaN()) {
+ generator.print("\"NaN\"");
+ } else if (doubleValue.isInfinite()) {
+ if (doubleValue < 0) {
+ generator.print("\"-Infinity\"");
+ } else {
+ generator.print("\"Infinity\"");
+ }
+ } else {
+ if (alwaysWithQuotes) {
+ generator.print("\"");
+ }
+ generator.print(doubleValue.toString());
+ if (alwaysWithQuotes) {
+ generator.print("\"");
+ }
+ }
+ break;
+
+ case UINT32:
+ case FIXED32:
+ if (alwaysWithQuotes) {
+ generator.print("\"");
+ }
+ generator.print(unsignedToString((Integer) value));
+ if (alwaysWithQuotes) {
+ generator.print("\"");
+ }
+ break;
+
+ case UINT64:
+ case FIXED64:
+ generator.print("\"" + unsignedToString((Long) value) + "\"");
+ break;
+
+ case STRING:
+ generator.print(gson.toJson(value));
+ break;
+
+ case BYTES:
+ generator.print("\"");
+ generator.print(BaseEncoding.base64().encode(((ByteString) value).toByteArray()));
+ generator.print("\"");
+ break;
+
+ case ENUM:
+ // Special-case google.protobuf.NullValue (it's an Enum).
+ if (field.getEnumType().getFullName().equals("google.protobuf.NullValue")) {
+ // No matter what value it contains, we always print it as "null".
+ if (alwaysWithQuotes) {
+ generator.print("\"");
+ }
+ generator.print("null");
+ if (alwaysWithQuotes) {
+ generator.print("\"");
+ }
+ } else {
+ if (((EnumValueDescriptor) value).getIndex() == -1) {
+ generator.print(String.valueOf(((EnumValueDescriptor) value).getNumber()));
+ } else {
+ generator.print("\"" + ((EnumValueDescriptor) value).getName() + "\"");
+ }
+ }
+ break;
+
+ case MESSAGE:
+ case GROUP:
+ print((Message) value);
+ break;
+ }
+ }
+ }
+
+ /** Convert an unsigned 32-bit integer to a string. */
+ private static String unsignedToString(final int value) {
+ if (value >= 0) {
+ return Integer.toString(value);
+ } else {
+ return Long.toString(value & 0x00000000FFFFFFFFL);
+ }
+ }
+
+ /** Convert an unsigned 64-bit integer to a string. */
+ private static String unsignedToString(final long value) {
+ if (value >= 0) {
+ return Long.toString(value);
+ } else {
+ // Pull off the most-significant bit so that BigInteger doesn't think
+ // the number is negative, then set it again using setBit().
+ return BigInteger.valueOf(value & Long.MAX_VALUE).setBit(Long.SIZE - 1).toString();
+ }
+ }
+
+ private static String getTypeName(String typeUrl) throws InvalidProtocolBufferException {
+ String[] parts = typeUrl.split("/");
+ if (parts.length == 1) {
+ throw new InvalidProtocolBufferException("Invalid type url found: " + typeUrl);
+ }
+ return parts[parts.length - 1];
+ }
+
+ private static class ParserImpl {
+ private final TypeRegistry registry;
+ private final JsonParser jsonParser;
+ private final boolean ignoringUnknownFields;
+ private final int recursionLimit;
+ private int currentDepth;
+
+ ParserImpl(TypeRegistry registry, boolean ignoreUnknownFields, int recursionLimit) {
+ this.registry = registry;
+ this.ignoringUnknownFields = ignoreUnknownFields;
+ this.jsonParser = new JsonParser();
+ this.recursionLimit = recursionLimit;
+ this.currentDepth = 0;
+ }
+
+ void merge(Reader json, Message.Builder builder) throws IOException {
+ try {
+ JsonReader reader = new JsonReader(json);
+ reader.setLenient(false);
+ merge(jsonParser.parse(reader), builder);
+ } catch (InvalidProtocolBufferException e) {
+ throw e;
+ } catch (JsonIOException e) {
+ // Unwrap IOException.
+ if (e.getCause() instanceof IOException) {
+ throw (IOException) e.getCause();
+ } else {
+ throw new InvalidProtocolBufferException(e.getMessage());
+ }
+ } catch (Exception e) {
+ // We convert all exceptions from JSON parsing to our own exceptions.
+ throw new InvalidProtocolBufferException(e.getMessage());
+ }
+ }
+
+ void merge(String json, Message.Builder builder) throws InvalidProtocolBufferException {
+ try {
+ JsonReader reader = new JsonReader(new StringReader(json));
+ reader.setLenient(false);
+ merge(jsonParser.parse(reader), builder);
+ } catch (InvalidProtocolBufferException e) {
+ throw e;
+ } catch (Exception e) {
+ // We convert all exceptions from JSON parsing to our own exceptions.
+ throw new InvalidProtocolBufferException(e.getMessage());
+ }
+ }
+
+ private interface WellKnownTypeParser {
+ void merge(ParserImpl parser, JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException;
+ }
+
+ private static final Map<String, WellKnownTypeParser> wellKnownTypeParsers =
+ buildWellKnownTypeParsers();
+
+ private static Map<String, WellKnownTypeParser> buildWellKnownTypeParsers() {
+ Map<String, WellKnownTypeParser> parsers = new HashMap<String, WellKnownTypeParser>();
+ // Special-case Any.
+ parsers.put(
+ Any.getDescriptor().getFullName(),
+ new WellKnownTypeParser() {
+ @Override
+ public void merge(ParserImpl parser, JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ parser.mergeAny(json, builder);
+ }
+ });
+ // Special-case wrapper types.
+ WellKnownTypeParser wrappersPrinter =
+ new WellKnownTypeParser() {
+ @Override
+ public void merge(ParserImpl parser, JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ parser.mergeWrapper(json, builder);
+ }
+ };
+ parsers.put(BoolValue.getDescriptor().getFullName(), wrappersPrinter);
+ parsers.put(Int32Value.getDescriptor().getFullName(), wrappersPrinter);
+ parsers.put(UInt32Value.getDescriptor().getFullName(), wrappersPrinter);
+ parsers.put(Int64Value.getDescriptor().getFullName(), wrappersPrinter);
+ parsers.put(UInt64Value.getDescriptor().getFullName(), wrappersPrinter);
+ parsers.put(StringValue.getDescriptor().getFullName(), wrappersPrinter);
+ parsers.put(BytesValue.getDescriptor().getFullName(), wrappersPrinter);
+ parsers.put(FloatValue.getDescriptor().getFullName(), wrappersPrinter);
+ parsers.put(DoubleValue.getDescriptor().getFullName(), wrappersPrinter);
+ // Special-case Timestamp.
+ parsers.put(
+ Timestamp.getDescriptor().getFullName(),
+ new WellKnownTypeParser() {
+ @Override
+ public void merge(ParserImpl parser, JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ parser.mergeTimestamp(json, builder);
+ }
+ });
+ // Special-case Duration.
+ parsers.put(
+ Duration.getDescriptor().getFullName(),
+ new WellKnownTypeParser() {
+ @Override
+ public void merge(ParserImpl parser, JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ parser.mergeDuration(json, builder);
+ }
+ });
+ // Special-case FieldMask.
+ parsers.put(
+ FieldMask.getDescriptor().getFullName(),
+ new WellKnownTypeParser() {
+ @Override
+ public void merge(ParserImpl parser, JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ parser.mergeFieldMask(json, builder);
+ }
+ });
+ // Special-case Struct.
+ parsers.put(
+ Struct.getDescriptor().getFullName(),
+ new WellKnownTypeParser() {
+ @Override
+ public void merge(ParserImpl parser, JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ parser.mergeStruct(json, builder);
+ }
+ });
+ // Special-case ListValue.
+ parsers.put(
+ ListValue.getDescriptor().getFullName(),
+ new WellKnownTypeParser() {
+ @Override
+ public void merge(ParserImpl parser, JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ parser.mergeListValue(json, builder);
+ }
+ });
+ // Special-case Value.
+ parsers.put(
+ Value.getDescriptor().getFullName(),
+ new WellKnownTypeParser() {
+ @Override
+ public void merge(ParserImpl parser, JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ parser.mergeValue(json, builder);
+ }
+ });
+ return parsers;
+ }
+
+ private void merge(JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ WellKnownTypeParser specialParser =
+ wellKnownTypeParsers.get(builder.getDescriptorForType().getFullName());
+ if (specialParser != null) {
+ specialParser.merge(this, json, builder);
+ return;
+ }
+ mergeMessage(json, builder, false);
+ }
+
+ // Maps from camel-case field names to FieldDescriptor.
+ private final Map<Descriptor, Map<String, FieldDescriptor>> fieldNameMaps =
+ new HashMap<Descriptor, Map<String, FieldDescriptor>>();
+
+ private Map<String, FieldDescriptor> getFieldNameMap(Descriptor descriptor) {
+ if (!fieldNameMaps.containsKey(descriptor)) {
+ Map<String, FieldDescriptor> fieldNameMap = new HashMap<String, FieldDescriptor>();
+ for (FieldDescriptor field : descriptor.getFields()) {
+ fieldNameMap.put(field.getName(), field);
+ fieldNameMap.put(field.getJsonName(), field);
+ }
+ fieldNameMaps.put(descriptor, fieldNameMap);
+ return fieldNameMap;
+ }
+ return fieldNameMaps.get(descriptor);
+ }
+
+ private void mergeMessage(JsonElement json, Message.Builder builder, boolean skipTypeUrl)
+ throws InvalidProtocolBufferException {
+ if (!(json instanceof JsonObject)) {
+ throw new InvalidProtocolBufferException("Expect message object but got: " + json);
+ }
+ JsonObject object = (JsonObject) json;
+ Map<String, FieldDescriptor> fieldNameMap = getFieldNameMap(builder.getDescriptorForType());
+ for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
+ if (skipTypeUrl && entry.getKey().equals("@type")) {
+ continue;
+ }
+ FieldDescriptor field = fieldNameMap.get(entry.getKey());
+ if (field == null) {
+ if (ignoringUnknownFields) {
+ continue;
+ }
+ throw new InvalidProtocolBufferException(
+ "Cannot find field: "
+ + entry.getKey()
+ + " in message "
+ + builder.getDescriptorForType().getFullName());
+ }
+ mergeField(field, entry.getValue(), builder);
+ }
+ }
+
+ private void mergeAny(JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ Descriptor descriptor = builder.getDescriptorForType();
+ FieldDescriptor typeUrlField = descriptor.findFieldByName("type_url");
+ FieldDescriptor valueField = descriptor.findFieldByName("value");
+ // Validates type of the message. Note that we can't just cast the message
+ // to com.google.protobuf.Any because it might be a DynamicMessage.
+ if (typeUrlField == null
+ || valueField == null
+ || typeUrlField.getType() != FieldDescriptor.Type.STRING
+ || valueField.getType() != FieldDescriptor.Type.BYTES) {
+ throw new InvalidProtocolBufferException("Invalid Any type.");
+ }
+
+ if (!(json instanceof JsonObject)) {
+ 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);
+ }
+ String typeUrl = typeUrlElement.getAsString();
+ Descriptor contentType = registry.find(getTypeName(typeUrl));
+ if (contentType == null) {
+ throw new InvalidProtocolBufferException("Cannot resolve type: " + typeUrl);
+ }
+ builder.setField(typeUrlField, typeUrl);
+ Message.Builder contentBuilder =
+ DynamicMessage.getDefaultInstance(contentType).newBuilderForType();
+ WellKnownTypeParser specialParser = wellKnownTypeParsers.get(contentType.getFullName());
+ if (specialParser != null) {
+ JsonElement value = object.get("value");
+ if (value != null) {
+ specialParser.merge(this, value, contentBuilder);
+ }
+ } else {
+ mergeMessage(json, contentBuilder, true);
+ }
+ builder.setField(valueField, contentBuilder.build().toByteString());
+ }
+
+ private void mergeFieldMask(JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ FieldMask value = FieldMaskUtil.fromJsonString(json.getAsString());
+ builder.mergeFrom(value.toByteString());
+ }
+
+ private void mergeTimestamp(JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ try {
+ Timestamp value = Timestamps.parse(json.getAsString());
+ builder.mergeFrom(value.toByteString());
+ } catch (ParseException e) {
+ throw new InvalidProtocolBufferException("Failed to parse timestamp: " + json);
+ }
+ }
+
+ private void mergeDuration(JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ try {
+ Duration value = Durations.parse(json.getAsString());
+ builder.mergeFrom(value.toByteString());
+ } catch (ParseException e) {
+ throw new InvalidProtocolBufferException("Failed to parse duration: " + json);
+ }
+ }
+
+ private void mergeStruct(JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ Descriptor descriptor = builder.getDescriptorForType();
+ FieldDescriptor field = descriptor.findFieldByName("fields");
+ if (field == null) {
+ throw new InvalidProtocolBufferException("Invalid Struct type.");
+ }
+ mergeMapField(field, json, builder);
+ }
+
+ private void mergeListValue(JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ Descriptor descriptor = builder.getDescriptorForType();
+ FieldDescriptor field = descriptor.findFieldByName("values");
+ if (field == null) {
+ throw new InvalidProtocolBufferException("Invalid ListValue type.");
+ }
+ mergeRepeatedField(field, json, builder);
+ }
+
+ private void mergeValue(JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ Descriptor type = builder.getDescriptorForType();
+ if (json instanceof JsonPrimitive) {
+ JsonPrimitive primitive = (JsonPrimitive) json;
+ if (primitive.isBoolean()) {
+ builder.setField(type.findFieldByName("bool_value"), primitive.getAsBoolean());
+ } else if (primitive.isNumber()) {
+ builder.setField(type.findFieldByName("number_value"), primitive.getAsDouble());
+ } else {
+ builder.setField(type.findFieldByName("string_value"), primitive.getAsString());
+ }
+ } else if (json instanceof JsonObject) {
+ FieldDescriptor field = type.findFieldByName("struct_value");
+ Message.Builder structBuilder = builder.newBuilderForField(field);
+ merge(json, structBuilder);
+ builder.setField(field, structBuilder.build());
+ } else if (json instanceof JsonArray) {
+ FieldDescriptor field = type.findFieldByName("list_value");
+ 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);
+ }
+ }
+
+ private void mergeWrapper(JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ Descriptor type = builder.getDescriptorForType();
+ FieldDescriptor field = type.findFieldByName("value");
+ if (field == null) {
+ throw new InvalidProtocolBufferException("Invalid wrapper type: " + type.getFullName());
+ }
+ builder.setField(field, parseFieldValue(field, json, builder));
+ }
+
+ private void mergeField(FieldDescriptor field, JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ if (field.isRepeated()) {
+ if (builder.getRepeatedFieldCount(field) > 0) {
+ throw new InvalidProtocolBufferException(
+ "Field " + field.getFullName() + " has already been set.");
+ }
+ } else {
+ if (builder.hasField(field)) {
+ throw new InvalidProtocolBufferException(
+ "Field " + field.getFullName() + " has already been set.");
+ }
+ if (field.getContainingOneof() != null
+ && builder.getOneofFieldDescriptor(field.getContainingOneof()) != null) {
+ FieldDescriptor other = builder.getOneofFieldDescriptor(field.getContainingOneof());
+ throw new InvalidProtocolBufferException(
+ "Cannot set field "
+ + field.getFullName()
+ + " because another field "
+ + other.getFullName()
+ + " belonging to the same oneof has already been set ");
+ }
+ }
+ if (field.isRepeated() && json instanceof JsonNull) {
+ // We allow "null" as value for all field types and treat it as if the
+ // field is not present.
+ return;
+ }
+ if (field.isMapField()) {
+ mergeMapField(field, json, builder);
+ } else if (field.isRepeated()) {
+ mergeRepeatedField(field, json, builder);
+ } else {
+ Object value = parseFieldValue(field, json, builder);
+ if (value != null) {
+ builder.setField(field, value);
+ }
+ }
+ }
+
+ private void mergeMapField(FieldDescriptor field, JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ if (!(json instanceof JsonObject)) {
+ throw new InvalidProtocolBufferException("Expect a map object but found: " + json);
+ }
+ Descriptor type = field.getMessageType();
+ FieldDescriptor keyField = type.findFieldByName("key");
+ FieldDescriptor valueField = type.findFieldByName("value");
+ if (keyField == null || valueField == null) {
+ throw new InvalidProtocolBufferException("Invalid map field: " + field.getFullName());
+ }
+ JsonObject object = (JsonObject) json;
+ for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
+ Message.Builder entryBuilder = builder.newBuilderForField(field);
+ Object key = parseFieldValue(keyField, new JsonPrimitive(entry.getKey()), entryBuilder);
+ Object value = parseFieldValue(valueField, entry.getValue(), entryBuilder);
+ if (value == null) {
+ throw new InvalidProtocolBufferException("Map value cannot be null.");
+ }
+ entryBuilder.setField(keyField, key);
+ entryBuilder.setField(valueField, value);
+ builder.addRepeatedField(field, entryBuilder.build());
+ }
+ }
+
+ /**
+ * Gets the default value for a field type. Note that we use proto3
+ * language defaults and ignore any default values set through the
+ * proto "default" option.
+ */
+ private Object getDefaultValue(FieldDescriptor field, Message.Builder builder) {
+ switch (field.getType()) {
+ case INT32:
+ case SINT32:
+ case SFIXED32:
+ case UINT32:
+ case FIXED32:
+ return 0;
+ case INT64:
+ case SINT64:
+ case SFIXED64:
+ case UINT64:
+ case FIXED64:
+ return 0L;
+ case FLOAT:
+ return 0.0f;
+ case DOUBLE:
+ return 0.0;
+ case BOOL:
+ return false;
+ case STRING:
+ return "";
+ case BYTES:
+ return ByteString.EMPTY;
+ case ENUM:
+ return field.getEnumType().getValues().get(0);
+ case MESSAGE:
+ case GROUP:
+ return builder.newBuilderForField(field).getDefaultInstanceForType();
+ default:
+ throw new IllegalStateException("Invalid field type: " + field.getType());
+ }
+ }
+
+ private void mergeRepeatedField(
+ FieldDescriptor field, JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ if (!(json instanceof JsonArray)) {
+ throw new InvalidProtocolBufferException("Expect an array but found: " + json);
+ }
+ JsonArray array = (JsonArray) json;
+ for (int i = 0; i < array.size(); ++i) {
+ Object value = parseFieldValue(field, array.get(i), builder);
+ if (value == null) {
+ throw new InvalidProtocolBufferException("Repeated field elements cannot be null");
+ }
+ builder.addRepeatedField(field, value);
+ }
+ }
+
+ private int parseInt32(JsonElement json) throws InvalidProtocolBufferException {
+ try {
+ return Integer.parseInt(json.getAsString());
+ } catch (Exception e) {
+ // Fall through.
+ }
+ // JSON doesn't distinguish between integer values and floating point values so "1" and
+ // "1.000" are treated as equal in JSON. For this reason we accept floating point values for
+ // integer fields as well as long as it actually is an integer (i.e., round(value) == value).
+ try {
+ BigDecimal value = new BigDecimal(json.getAsString());
+ return value.intValueExact();
+ } catch (Exception e) {
+ throw new InvalidProtocolBufferException("Not an int32 value: " + json);
+ }
+ }
+
+ private long parseInt64(JsonElement json) throws InvalidProtocolBufferException {
+ try {
+ return Long.parseLong(json.getAsString());
+ } catch (Exception e) {
+ // Fall through.
+ }
+ // JSON doesn't distinguish between integer values and floating point values so "1" and
+ // "1.000" are treated as equal in JSON. For this reason we accept floating point values for
+ // integer fields as well as long as it actually is an integer (i.e., round(value) == value).
+ try {
+ BigDecimal value = new BigDecimal(json.getAsString());
+ return value.longValueExact();
+ } catch (Exception e) {
+ throw new InvalidProtocolBufferException("Not an int32 value: " + json);
+ }
+ }
+
+ private int parseUint32(JsonElement json) throws InvalidProtocolBufferException {
+ try {
+ long result = Long.parseLong(json.getAsString());
+ if (result < 0 || result > 0xFFFFFFFFL) {
+ throw new InvalidProtocolBufferException("Out of range uint32 value: " + json);
+ }
+ return (int) result;
+ } catch (InvalidProtocolBufferException e) {
+ throw e;
+ } catch (Exception e) {
+ // Fall through.
+ }
+ // JSON doesn't distinguish between integer values and floating point values so "1" and
+ // "1.000" are treated as equal in JSON. For this reason we accept floating point values for
+ // integer fields as well as long as it actually is an integer (i.e., round(value) == value).
+ try {
+ BigDecimal decimalValue = new BigDecimal(json.getAsString());
+ BigInteger value = decimalValue.toBigIntegerExact();
+ if (value.signum() < 0 || value.compareTo(new BigInteger("FFFFFFFF", 16)) > 0) {
+ throw new InvalidProtocolBufferException("Out of range uint32 value: " + json);
+ }
+ return value.intValue();
+ } catch (InvalidProtocolBufferException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new InvalidProtocolBufferException("Not an uint32 value: " + json);
+ }
+ }
+
+ private static final BigInteger MAX_UINT64 = new BigInteger("FFFFFFFFFFFFFFFF", 16);
+
+ private long parseUint64(JsonElement json) throws InvalidProtocolBufferException {
+ try {
+ BigDecimal decimalValue = new BigDecimal(json.getAsString());
+ BigInteger value = decimalValue.toBigIntegerExact();
+ if (value.compareTo(BigInteger.ZERO) < 0 || value.compareTo(MAX_UINT64) > 0) {
+ throw new InvalidProtocolBufferException("Out of range uint64 value: " + json);
+ }
+ return value.longValue();
+ } catch (InvalidProtocolBufferException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new InvalidProtocolBufferException("Not an uint64 value: " + json);
+ }
+ }
+
+ private boolean parseBool(JsonElement json) throws InvalidProtocolBufferException {
+ if (json.getAsString().equals("true")) {
+ return true;
+ }
+ if (json.getAsString().equals("false")) {
+ return false;
+ }
+ throw new InvalidProtocolBufferException("Invalid bool value: " + json);
+ }
+
+ private static final double EPSILON = 1e-6;
+
+ private float parseFloat(JsonElement json) throws InvalidProtocolBufferException {
+ if (json.getAsString().equals("NaN")) {
+ return Float.NaN;
+ } else if (json.getAsString().equals("Infinity")) {
+ return Float.POSITIVE_INFINITY;
+ } else if (json.getAsString().equals("-Infinity")) {
+ return Float.NEGATIVE_INFINITY;
+ }
+ try {
+ // We don't use Float.parseFloat() here because that function simply
+ // accepts all double values. Here we parse the value into a Double
+ // and do explicit range check on it.
+ double value = Double.parseDouble(json.getAsString());
+ // When a float value is printed, the printed value might be a little
+ // larger or smaller due to precision loss. Here we need to add a bit
+ // of tolerance when checking whether the float value is in range.
+ if (value > Float.MAX_VALUE * (1.0 + EPSILON)
+ || value < -Float.MAX_VALUE * (1.0 + EPSILON)) {
+ throw new InvalidProtocolBufferException("Out of range float value: " + json);
+ }
+ return (float) value;
+ } catch (InvalidProtocolBufferException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new InvalidProtocolBufferException("Not a float value: " + json);
+ }
+ }
+
+ private static final BigDecimal MORE_THAN_ONE = new BigDecimal(String.valueOf(1.0 + EPSILON));
+ // When a float value is printed, the printed value might be a little
+ // larger or smaller due to precision loss. Here we need to add a bit
+ // of tolerance when checking whether the float value is in range.
+ private static final BigDecimal MAX_DOUBLE =
+ new BigDecimal(String.valueOf(Double.MAX_VALUE)).multiply(MORE_THAN_ONE);
+ private static final BigDecimal MIN_DOUBLE =
+ new BigDecimal(String.valueOf(-Double.MAX_VALUE)).multiply(MORE_THAN_ONE);
+
+ private double parseDouble(JsonElement json) throws InvalidProtocolBufferException {
+ if (json.getAsString().equals("NaN")) {
+ return Double.NaN;
+ } else if (json.getAsString().equals("Infinity")) {
+ return Double.POSITIVE_INFINITY;
+ } else if (json.getAsString().equals("-Infinity")) {
+ return Double.NEGATIVE_INFINITY;
+ }
+ try {
+ // We don't use Double.parseDouble() here because that function simply
+ // accepts all values. Here we parse the value into a BigDecimal and do
+ // explicit range check on it.
+ BigDecimal value = new BigDecimal(json.getAsString());
+ if (value.compareTo(MAX_DOUBLE) > 0 || value.compareTo(MIN_DOUBLE) < 0) {
+ throw new InvalidProtocolBufferException("Out of range double value: " + json);
+ }
+ return value.doubleValue();
+ } catch (InvalidProtocolBufferException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new InvalidProtocolBufferException("Not an double value: " + json);
+ }
+ }
+
+ private String parseString(JsonElement json) {
+ return json.getAsString();
+ }
+
+ private ByteString parseBytes(JsonElement json) throws InvalidProtocolBufferException {
+ return ByteString.copyFrom(BaseEncoding.base64().decode(json.getAsString()));
+ }
+
+ private EnumValueDescriptor parseEnum(EnumDescriptor enumDescriptor, JsonElement json)
+ throws InvalidProtocolBufferException {
+ String value = json.getAsString();
+ EnumValueDescriptor result = enumDescriptor.findValueByName(value);
+ if (result == null) {
+ // Try to interpret the value as a number.
+ try {
+ int numericValue = parseInt32(json);
+ if (enumDescriptor.getFile().getSyntax() == FileDescriptor.Syntax.PROTO3) {
+ result = enumDescriptor.findValueByNumberCreatingIfUnknown(numericValue);
+ } else {
+ result = enumDescriptor.findValueByNumber(numericValue);
+ }
+ } catch (InvalidProtocolBufferException e) {
+ // Fall through. This exception is about invalid int32 value we get from parseInt32() but
+ // that's not the exception we want the user to see. Since result == null, we will throw
+ // an exception later.
+ }
+
+ if (result == null) {
+ throw new InvalidProtocolBufferException(
+ "Invalid enum value: " + value + " for enum type: " + enumDescriptor.getFullName());
+ }
+ }
+ return result;
+ }
+
+ private Object parseFieldValue(FieldDescriptor field, JsonElement json, Message.Builder builder)
+ throws InvalidProtocolBufferException {
+ if (json instanceof JsonNull) {
+ if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE
+ && field.getMessageType().getFullName().equals(Value.getDescriptor().getFullName())) {
+ // For every other type, "null" means absence, but for the special
+ // Value message, it means the "null_value" field has been set.
+ Value value = Value.newBuilder().setNullValueValue(0).build();
+ return builder.newBuilderForField(field).mergeFrom(value.toByteString()).build();
+ } else if (field.getJavaType() == FieldDescriptor.JavaType.ENUM
+ && field.getEnumType().getFullName().equals(NullValue.getDescriptor().getFullName())) {
+ // If the type of the field is a NullValue, then the value should be explicitly set.
+ return field.getEnumType().findValueByNumber(0);
+ }
+ return null;
+ }
+ switch (field.getType()) {
+ case INT32:
+ case SINT32:
+ case SFIXED32:
+ return parseInt32(json);
+
+ case INT64:
+ case SINT64:
+ case SFIXED64:
+ return parseInt64(json);
+
+ case BOOL:
+ return parseBool(json);
+
+ case FLOAT:
+ return parseFloat(json);
+
+ case DOUBLE:
+ return parseDouble(json);
+
+ case UINT32:
+ case FIXED32:
+ return parseUint32(json);
+
+ case UINT64:
+ case FIXED64:
+ return parseUint64(json);
+
+ case STRING:
+ return parseString(json);
+
+ case BYTES:
+ return parseBytes(json);
+
+ case ENUM:
+ return parseEnum(field.getEnumType(), json);
+
+ case MESSAGE:
+ case GROUP:
+ if (currentDepth >= recursionLimit) {
+ throw new InvalidProtocolBufferException("Hit recursion limit.");
+ }
+ ++currentDepth;
+ Message.Builder subBuilder = builder.newBuilderForField(field);
+ merge(json, subBuilder);
+ --currentDepth;
+ return subBuilder.build();
+
+ default:
+ throw new InvalidProtocolBufferException("Invalid field type: " + field.getType());
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/TimeUtil.java b/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/TimeUtil.java
new file mode 100644
index 0000000000..0475847349
--- /dev/null
+++ b/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/TimeUtil.java
@@ -0,0 +1,400 @@
+// 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.util;
+
+import com.google.protobuf.Duration;
+import com.google.protobuf.Timestamp;
+
+import java.math.BigInteger;
+import java.text.ParseException;
+
+/**
+ * Utilities to help create/manipulate Timestamp/Duration
+ *
+ * @deprecated Use {@link Durations} and {@link Timestamps} instead.
+ */
+@Deprecated
+public final class TimeUtil {
+ // Timestamp for "0001-01-01T00:00:00Z"
+ public static final long TIMESTAMP_SECONDS_MIN = -62135596800L;
+
+ // Timestamp for "9999-12-31T23:59:59Z"
+ public static final long TIMESTAMP_SECONDS_MAX = 253402300799L;
+ public static final long DURATION_SECONDS_MIN = -315576000000L;
+ public static final long DURATION_SECONDS_MAX = 315576000000L;
+
+ private static final long NANOS_PER_SECOND = 1000000000;
+
+ private TimeUtil() {}
+
+ /**
+ * 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
+ *
+ * <p>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.
+ * @deprecated Use {@link Timestamps#toString} instead.
+ */
+ @Deprecated
+ public static String toString(Timestamp timestamp) {
+ return Timestamps.toString(timestamp);
+ }
+
+ /**
+ * 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.
+ *
+ * <p>Example of accepted format: "1972-01-01T10:00:20.021-05:00"
+ *
+ * @return A Timestamp parsed from the string.
+ * @throws ParseException if parsing fails.
+ * @deprecated Use {@link Timestamps#parse} instead.
+ */
+ @Deprecated
+ public static Timestamp parseTimestamp(String value) throws ParseException {
+ return Timestamps.parse(value);
+ }
+
+ /**
+ * 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.
+ * @deprecated Use {@link Durations#toString} instead.
+ */
+ @Deprecated
+ public static String toString(Duration duration) {
+ return Durations.toString(duration);
+ }
+
+ /**
+ * Parse from a string to produce a duration.
+ *
+ * @return A Duration parsed from the string.
+ * @throws ParseException if parsing fails.
+ * @deprecated Use {@link Durations#parse} instead.
+ */
+ @Deprecated
+ public static Duration parseDuration(String value) throws ParseException {
+ return Durations.parse(value);
+ }
+
+ /**
+ * Create a Timestamp from the number of milliseconds elapsed from the epoch.
+ *
+ * @deprecated Use {@link Timestamps#fromMillis} instead.
+ */
+ @Deprecated
+ public static Timestamp createTimestampFromMillis(long milliseconds) {
+ return Timestamps.fromMillis(milliseconds);
+ }
+
+ /**
+ * Create a Duration from the number of milliseconds.
+ *
+ * @deprecated Use {@link Durations#fromMillis} instead.
+ */
+ @Deprecated
+ public static Duration createDurationFromMillis(long milliseconds) {
+ return Durations.fromMillis(milliseconds);
+ }
+
+ /**
+ * Convert a Timestamp to the number of milliseconds elapsed from the epoch.
+ *
+ * <p>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.
+ *
+ * @deprecated Use {@link Timestamps#toMillis} instead.
+ */
+ @Deprecated
+ public static long toMillis(Timestamp timestamp) {
+ return Timestamps.toMillis(timestamp);
+ }
+
+ /**
+ * 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.
+ *
+ * @deprecated Use {@link Durations#toMillis} instead.
+ */
+ @Deprecated
+ public static long toMillis(Duration duration) {
+ return Durations.toMillis(duration);
+ }
+
+ /**
+ * Create a Timestamp from the number of microseconds elapsed from the epoch.
+ *
+ * @deprecated Use {@link Timestamps#fromMicros} instead.
+ */
+ @Deprecated
+ public static Timestamp createTimestampFromMicros(long microseconds) {
+ return Timestamps.fromMicros(microseconds);
+ }
+
+ /**
+ * Create a Duration from the number of microseconds.
+ *
+ * @deprecated Use {@link Durations#fromMicros} instead.
+ */
+ @Deprecated
+ public static Duration createDurationFromMicros(long microseconds) {
+ return Durations.fromMicros(microseconds);
+ }
+
+ /**
+ * Convert a Timestamp to the number of microseconds elapsed from the epoch.
+ *
+ * <p>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.
+ *
+ * @deprecated Use {@link Timestamps#toMicros} instead.
+ */
+ @Deprecated
+ public static long toMicros(Timestamp timestamp) {
+ return Timestamps.toMicros(timestamp);
+ }
+
+ /**
+ * 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.
+ *
+ * @deprecated Use {@link Durations#toMicros} instead.
+ */
+ @Deprecated
+ public static long toMicros(Duration duration) {
+ return Durations.toMicros(duration);
+ }
+
+ /**
+ * Create a Timestamp from the number of nanoseconds elapsed from the epoch.
+ *
+ * @deprecated Use {@link Timestamps#fromNanos} instead.
+ */
+ @Deprecated
+ public static Timestamp createTimestampFromNanos(long nanoseconds) {
+ return Timestamps.fromNanos(nanoseconds);
+ }
+
+ /**
+ * Create a Duration from the number of nanoseconds.
+ *
+ * @deprecated Use {@link Durations#fromNanos} instead.
+ */
+ @Deprecated
+ public static Duration createDurationFromNanos(long nanoseconds) {
+ return Durations.fromNanos(nanoseconds);
+ }
+
+ /**
+ * Convert a Timestamp to the number of nanoseconds elapsed from the epoch.
+ *
+ * @deprecated Use {@link Timestamps#toNanos} instead.
+ */
+ @Deprecated
+ public static long toNanos(Timestamp timestamp) {
+ return Timestamps.toNanos(timestamp);
+ }
+
+ /**
+ * Convert a Duration to the number of nanoseconds.
+ *
+ * @deprecated Use {@link Durations#toNanos} instead.
+ */
+ @Deprecated
+ public static long toNanos(Duration duration) {
+ return Durations.toNanos(duration);
+ }
+
+ /**
+ * Get the current time.
+ *
+ * @deprecated Use {@code Timestamps.fromMillis(System.currentTimeMillis())} instead.
+ */
+ @Deprecated
+ public static Timestamp getCurrentTime() {
+ return Timestamps.fromMillis(System.currentTimeMillis());
+ }
+
+ /**
+ * Get the epoch.
+ *
+ * @deprecated Use {@code Timestamps.fromMillis(0)} instead.
+ */
+ @Deprecated
+ public static Timestamp getEpoch() {
+ return Timestamp.getDefaultInstance();
+ }
+
+ /**
+ * Calculate the difference between two timestamps.
+ *
+ * @deprecated Use {@link Timestamps#between} instead.
+ */
+ @Deprecated
+ public static Duration distance(Timestamp from, Timestamp to) {
+ return Timestamps.between(from, to);
+ }
+
+ /**
+ * Add a duration to a timestamp.
+ *
+ * @deprecated Use {@link Timestamps#add} instead.
+ */
+ @Deprecated
+ public static Timestamp add(Timestamp start, Duration length) {
+ return Timestamps.add(start, length);
+ }
+
+ /**
+ * Subtract a duration from a timestamp.
+ *
+ * @deprecated Use {@link Timestamps#subtract} instead.
+ */
+ @Deprecated
+ public static Timestamp subtract(Timestamp start, Duration length) {
+ return Timestamps.subtract(start, length);
+ }
+
+ /**
+ * Add two durations.
+ *
+ * @deprecated Use {@link Durations#add} instead.
+ */
+ @Deprecated
+ public static Duration add(Duration d1, Duration d2) {
+ return Durations.add(d1, d2);
+ }
+
+ /**
+ * Subtract a duration from another.
+ *
+ * @deprecated Use {@link Durations#subtract} instead.
+ */
+ @Deprecated
+ public static Duration subtract(Duration d1, Duration d2) {
+ return Durations.subtract(d1, d2);
+ }
+
+ // Multiplications and divisions.
+
+ // TODO(kak): Delete this.
+ public static Duration multiply(Duration duration, double times) {
+ double result = duration.getSeconds() * times + duration.getNanos() * times / 1000000000.0;
+ if (result < Long.MIN_VALUE || result > Long.MAX_VALUE) {
+ throw new IllegalArgumentException("Result is out of valid range.");
+ }
+ long seconds = (long) result;
+ int nanos = (int) ((result - seconds) * 1000000000);
+ return normalizedDuration(seconds, nanos);
+ }
+
+ // TODO(kak): Delete this.
+ public static Duration divide(Duration duration, double value) {
+ return multiply(duration, 1.0 / value);
+ }
+
+ // TODO(kak): Delete this.
+ public static Duration multiply(Duration duration, long times) {
+ return createDurationFromBigInteger(toBigInteger(duration).multiply(toBigInteger(times)));
+ }
+
+ // TODO(kak): Delete this.
+ public static Duration divide(Duration duration, long times) {
+ return createDurationFromBigInteger(toBigInteger(duration).divide(toBigInteger(times)));
+ }
+
+ // TODO(kak): Delete this.
+ public static long divide(Duration d1, Duration d2) {
+ return toBigInteger(d1).divide(toBigInteger(d2)).longValue();
+ }
+
+ // TODO(kak): Delete this.
+ public static Duration remainder(Duration d1, Duration d2) {
+ return createDurationFromBigInteger(toBigInteger(d1).remainder(toBigInteger(d2)));
+ }
+
+ private static final BigInteger NANOS_PER_SECOND_BIG_INTEGER =
+ new BigInteger(String.valueOf(NANOS_PER_SECOND));
+
+ private static BigInteger toBigInteger(Duration duration) {
+ return toBigInteger(duration.getSeconds())
+ .multiply(NANOS_PER_SECOND_BIG_INTEGER)
+ .add(toBigInteger(duration.getNanos()));
+ }
+
+ private static BigInteger toBigInteger(long value) {
+ return new BigInteger(String.valueOf(value));
+ }
+
+ private static Duration createDurationFromBigInteger(BigInteger value) {
+ long seconds = value.divide(new BigInteger(String.valueOf(NANOS_PER_SECOND))).longValue();
+ int nanos = value.remainder(new BigInteger(String.valueOf(NANOS_PER_SECOND))).intValue();
+ return normalizedDuration(seconds, nanos);
+ }
+
+ private static Duration normalizedDuration(long seconds, int nanos) {
+ if (nanos <= -NANOS_PER_SECOND || nanos >= NANOS_PER_SECOND) {
+ seconds += nanos / NANOS_PER_SECOND;
+ nanos %= NANOS_PER_SECOND;
+ }
+ if (seconds > 0 && nanos < 0) {
+ nanos += NANOS_PER_SECOND;
+ seconds -= 1;
+ }
+ if (seconds < 0 && nanos > 0) {
+ nanos -= NANOS_PER_SECOND;
+ seconds += 1;
+ }
+ if (seconds < DURATION_SECONDS_MIN || seconds > DURATION_SECONDS_MAX) {
+ throw new IllegalArgumentException("Duration is out of valid range.");
+ }
+ return Duration.newBuilder().setSeconds(seconds).setNanos(nanos).build();
+ }
+}
diff --git a/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/Timestamps.java b/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/Timestamps.java
new file mode 100644
index 0000000000..1d631a2c58
--- /dev/null
+++ b/third_party/protobuf/java/util/src/main/java/com/google/protobuf/util/Timestamps.java
@@ -0,0 +1,397 @@
+// 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.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.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.Locale;
+import java.util.TimeZone;
+
+/**
+ * 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;
+
+ // Timestamp for "9999-12-31T23:59:59Z"
+ static final long TIMESTAMP_SECONDS_MAX = 253402300799L;
+
+ static final long NANOS_PER_SECOND = 1000000000;
+ static final long NANOS_PER_MILLISECOND = 1000000;
+ static final long NANOS_PER_MICROSECOND = 1000;
+ static final long MILLIS_PER_SECOND = 1000;
+ static final long MICROS_PER_SECOND = 1000000;
+
+ /** 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<SimpleDateFormat> timestampFormat =
+ new ThreadLocal<SimpleDateFormat>() {
+ @Override
+ protected SimpleDateFormat initialValue() {
+ return createTimestampFormat();
+ }
+ };
+
+ private static SimpleDateFormat createTimestampFormat() {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH);
+ GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
+ // We use Proleptic Gregorian Calendar (i.e., Gregorian calendar extends
+ // backwards to year one) for timestamp formating.
+ calendar.setGregorianChange(new Date(Long.MIN_VALUE));
+ sdf.setCalendar(calendar);
+ return sdf;
+ }
+
+ private Timestamps() {}
+
+ private static final Comparator<Timestamp> COMPARATOR =
+ new Comparator<Timestamp>() {
+ @Override
+ public int compare(Timestamp t1, Timestamp t2) {
+ checkValid(t1);
+ checkValid(t2);
+ int secDiff = Long.compare(t1.getSeconds(), t2.getSeconds());
+ return (secDiff != 0) ? secDiff : Integer.compare(t1.getNanos(), t2.getNanos());
+ }
+ };
+
+ /**
+ * 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<Timestamp> 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].
+ *
+ * <p><b>Note:</b> 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
+ * 0001-01-01T00:00:00Z and 9999-12-31T23:59:59Z). The {@code nanos} value must be in the range
+ * [0, +999,999,999].
+ *
+ * <p><b>Note:</b> Negative second values with fractional seconds must still have non-negative
+ * nanos values that count forward in time.
+ */
+ public static boolean isValid(long seconds, int nanos) {
+ if (seconds < TIMESTAMP_SECONDS_MIN || seconds > TIMESTAMP_SECONDS_MAX) {
+ return false;
+ }
+ if (nanos < 0 || nanos >= NANOS_PER_SECOND) {
+ return false;
+ }
+ return true;
+ }
+
+ /** 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
+ * https://www.ietf.org/rfc/rfc3339.txt
+ *
+ * <p>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.
+ */
+ public static String toString(Timestamp timestamp) {
+ checkValid(timestamp);
+
+ long seconds = timestamp.getSeconds();
+ int nanos = timestamp.getNanos();
+
+ StringBuilder result = new StringBuilder();
+ // Format the seconds part.
+ Date date = new Date(seconds * MILLIS_PER_SECOND);
+ result.append(timestampFormat.get().format(date));
+ // Format the nanos part.
+ if (nanos != 0) {
+ result.append(".");
+ result.append(formatNanos(nanos));
+ }
+ result.append("Z");
+ return result.toString();
+ }
+
+ /**
+ * 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.
+ *
+ * <p>Example of accepted format: "1972-01-01T10:00:20.021-05:00"
+ *
+ * @return A Timestamp parsed from the string.
+ * @throws ParseException if parsing fails.
+ */
+ public static Timestamp parse(String value) throws ParseException {
+ int dayOffset = value.indexOf('T');
+ if (dayOffset == -1) {
+ throw new ParseException("Failed to parse timestamp: invalid timestamp \"" + value + "\"", 0);
+ }
+ int timezoneOffsetPosition = value.indexOf('Z', dayOffset);
+ if (timezoneOffsetPosition == -1) {
+ timezoneOffsetPosition = value.indexOf('+', dayOffset);
+ }
+ if (timezoneOffsetPosition == -1) {
+ timezoneOffsetPosition = value.indexOf('-', dayOffset);
+ }
+ if (timezoneOffsetPosition == -1) {
+ throw new ParseException("Failed to parse timestamp: missing valid timezone offset.", 0);
+ }
+ // Parse seconds and nanos.
+ String timeValue = value.substring(0, timezoneOffsetPosition);
+ String secondValue = timeValue;
+ String nanoValue = "";
+ int pointPosition = timeValue.indexOf('.');
+ if (pointPosition != -1) {
+ secondValue = timeValue.substring(0, pointPosition);
+ nanoValue = timeValue.substring(pointPosition + 1);
+ }
+ Date date = timestampFormat.get().parse(secondValue);
+ long seconds = date.getTime() / MILLIS_PER_SECOND;
+ int nanos = nanoValue.isEmpty() ? 0 : parseNanos(nanoValue);
+ // Parse timezone offsets.
+ if (value.charAt(timezoneOffsetPosition) == 'Z') {
+ if (value.length() != timezoneOffsetPosition + 1) {
+ throw new ParseException(
+ "Failed to parse timestamp: invalid trailing data \""
+ + value.substring(timezoneOffsetPosition)
+ + "\"",
+ 0);
+ }
+ } else {
+ String offsetValue = value.substring(timezoneOffsetPosition + 1);
+ long offset = parseTimezoneOffset(offsetValue);
+ if (value.charAt(timezoneOffsetPosition) == '+') {
+ seconds -= offset;
+ } else {
+ seconds += offset;
+ }
+ }
+ try {
+ return normalizedTimestamp(seconds, nanos);
+ } catch (IllegalArgumentException e) {
+ 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);
+ }
+
+ /**
+ * Convert a Timestamp to the number of seconds elapsed from the epoch.
+ *
+ * <p>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,
+ (int) (milliseconds % MILLIS_PER_SECOND * NANOS_PER_MILLISECOND));
+ }
+
+ /**
+ * Convert a Timestamp to the number of milliseconds elapsed from the epoch.
+ *
+ * <p>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) {
+ 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. */
+ public static Timestamp fromMicros(long microseconds) {
+ return normalizedTimestamp(
+ microseconds / MICROS_PER_SECOND,
+ (int) (microseconds % MICROS_PER_SECOND * NANOS_PER_MICROSECOND));
+ }
+
+ /**
+ * Convert a Timestamp to the number of microseconds elapsed from the epoch.
+ *
+ * <p>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) {
+ 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. */
+ 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. */
+ public static long toNanos(Timestamp timestamp) {
+ checkValid(timestamp);
+ return checkedAdd(
+ checkedMultiply(timestamp.getSeconds(), NANOS_PER_SECOND), timestamp.getNanos());
+ }
+
+ /** Calculate the difference between two timestamps. */
+ public static Duration between(Timestamp from, Timestamp to) {
+ checkValid(from);
+ checkValid(to);
+ return Durations.normalizedDuration(
+ checkedSubtract(to.getSeconds(), from.getSeconds()),
+ checkedSubtract(to.getNanos(), from.getNanos()));
+ }
+
+ /** Add a duration to a timestamp. */
+ public static Timestamp add(Timestamp start, Duration length) {
+ checkValid(start);
+ Durations.checkValid(length);
+ return normalizedTimestamp(
+ checkedAdd(start.getSeconds(), length.getSeconds()),
+ checkedAdd(start.getNanos(), length.getNanos()));
+ }
+
+ /** Subtract a duration from a timestamp. */
+ public static Timestamp subtract(Timestamp start, Duration length) {
+ checkValid(start);
+ Durations.checkValid(length);
+ return normalizedTimestamp(
+ checkedSubtract(start.getSeconds(), length.getSeconds()),
+ checkedSubtract(start.getNanos(), length.getNanos()));
+ }
+
+ static Timestamp normalizedTimestamp(long seconds, int nanos) {
+ if (nanos <= -NANOS_PER_SECOND || nanos >= NANOS_PER_SECOND) {
+ seconds = checkedAdd(seconds, nanos / NANOS_PER_SECOND);
+ nanos %= NANOS_PER_SECOND;
+ }
+ if (nanos < 0) {
+ nanos += NANOS_PER_SECOND; // no overflow since nanos is negative (and we're adding)
+ seconds = checkedSubtract(seconds, 1);
+ }
+ Timestamp timestamp = Timestamp.newBuilder().setSeconds(seconds).setNanos(nanos).build();
+ return checkValid(timestamp);
+ }
+
+ private static long parseTimezoneOffset(String value) throws ParseException {
+ int pos = value.indexOf(':');
+ if (pos == -1) {
+ throw new ParseException("Invalid offset value: " + value, 0);
+ }
+ String hours = value.substring(0, pos);
+ String minutes = value.substring(pos + 1);
+ return (Long.parseLong(hours) * 60 + Long.parseLong(minutes)) * 60;
+ }
+
+ static int parseNanos(String value) throws ParseException {
+ int result = 0;
+ for (int i = 0; i < 9; ++i) {
+ result = result * 10;
+ if (i < value.length()) {
+ if (value.charAt(i) < '0' || value.charAt(i) > '9') {
+ throw new ParseException("Invalid nanoseconds.", 0);
+ }
+ result += value.charAt(i) - '0';
+ }
+ }
+ return result;
+ }
+
+ /** Format the nano part of a timestamp or a duration. */
+ static String formatNanos(int nanos) {
+ // Determine whether to use 3, 6, or 9 digits for the nano part.
+ if (nanos % NANOS_PER_MILLISECOND == 0) {
+ return String.format(Locale.ENGLISH, "%1$03d", nanos / NANOS_PER_MILLISECOND);
+ } else if (nanos % NANOS_PER_MICROSECOND == 0) {
+ return String.format(Locale.ENGLISH, "%1$06d", nanos / NANOS_PER_MICROSECOND);
+ } else {
+ return String.format(Locale.ENGLISH, "%1$09d", nanos);
+ }
+ }
+}
diff --git a/third_party/protobuf/java/util/src/test/java/com/google/protobuf/util/FieldMaskTreeTest.java b/third_party/protobuf/java/util/src/test/java/com/google/protobuf/util/FieldMaskTreeTest.java
new file mode 100644
index 0000000000..3ee0fc6e6a
--- /dev/null
+++ b/third_party/protobuf/java/util/src/test/java/com/google/protobuf/util/FieldMaskTreeTest.java
@@ -0,0 +1,261 @@
+// 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.util;
+
+import protobuf_unittest.UnittestProto.NestedTestAllTypes;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+import protobuf_unittest.UnittestProto.TestAllTypes.NestedMessage;
+
+import junit.framework.TestCase;
+
+public class FieldMaskTreeTest extends TestCase {
+ public void testAddFieldPath() throws Exception {
+ FieldMaskTree tree = new FieldMaskTree();
+ assertEquals("", tree.toString());
+ tree.addFieldPath("");
+ assertEquals("", tree.toString());
+ // New branch.
+ tree.addFieldPath("foo");
+ assertEquals("foo", tree.toString());
+ // Redundant path.
+ tree.addFieldPath("foo");
+ assertEquals("foo", tree.toString());
+ // New branch.
+ tree.addFieldPath("bar.baz");
+ assertEquals("bar.baz,foo", tree.toString());
+ // Redundant sub-path.
+ tree.addFieldPath("foo.bar");
+ assertEquals("bar.baz,foo", tree.toString());
+ // New branch from a non-root node.
+ tree.addFieldPath("bar.quz");
+ assertEquals("bar.baz,bar.quz,foo", tree.toString());
+ // A path that matches several existing sub-paths.
+ tree.addFieldPath("bar");
+ assertEquals("bar,foo", tree.toString());
+ }
+
+ public void testMergeFromFieldMask() throws Exception {
+ FieldMaskTree tree = new FieldMaskTree(FieldMaskUtil.fromString("foo,bar.baz,bar.quz"));
+ assertEquals("bar.baz,bar.quz,foo", tree.toString());
+ tree.mergeFromFieldMask(FieldMaskUtil.fromString("foo.bar,bar"));
+ assertEquals("bar,foo", tree.toString());
+ }
+
+ public void testIntersectFieldPath() throws Exception {
+ FieldMaskTree tree = new FieldMaskTree(FieldMaskUtil.fromString("foo,bar.baz,bar.quz"));
+ FieldMaskTree result = new FieldMaskTree();
+ // Empty path.
+ tree.intersectFieldPath("", result);
+ assertEquals("", result.toString());
+ // Non-exist path.
+ tree.intersectFieldPath("quz", result);
+ assertEquals("", result.toString());
+ // Sub-path of an existing leaf.
+ tree.intersectFieldPath("foo.bar", result);
+ assertEquals("foo.bar", result.toString());
+ // Match an existing leaf node.
+ tree.intersectFieldPath("foo", result);
+ assertEquals("foo", result.toString());
+ // Non-exist path.
+ tree.intersectFieldPath("bar.foo", result);
+ assertEquals("foo", result.toString());
+ // Match a non-leaf node.
+ tree.intersectFieldPath("bar", result);
+ assertEquals("bar.baz,bar.quz,foo", result.toString());
+ }
+
+ public void testMerge() throws Exception {
+ TestAllTypes value =
+ TestAllTypes.newBuilder()
+ .setOptionalInt32(1234)
+ .setOptionalNestedMessage(NestedMessage.newBuilder().setBb(5678))
+ .addRepeatedInt32(4321)
+ .addRepeatedNestedMessage(NestedMessage.newBuilder().setBb(8765))
+ .build();
+ NestedTestAllTypes source =
+ NestedTestAllTypes.newBuilder()
+ .setPayload(value)
+ .setChild(NestedTestAllTypes.newBuilder().setPayload(value))
+ .build();
+ // Now we have a message source with the following structure:
+ // [root] -+- payload -+- optional_int32
+ // | +- optional_nested_message
+ // | +- repeated_int32
+ // | +- repeated_nested_message
+ // |
+ // +- child --- payload -+- optional_int32
+ // +- optional_nested_message
+ // +- repeated_int32
+ // +- repeated_nested_message
+
+ FieldMaskUtil.MergeOptions options = new FieldMaskUtil.MergeOptions();
+
+ // Test merging each individual field.
+ NestedTestAllTypes.Builder builder = NestedTestAllTypes.newBuilder();
+ new FieldMaskTree().addFieldPath("payload.optional_int32").merge(source, builder, options);
+ NestedTestAllTypes.Builder expected = NestedTestAllTypes.newBuilder();
+ expected.getPayloadBuilder().setOptionalInt32(1234);
+ assertEquals(expected.build(), builder.build());
+
+ builder = NestedTestAllTypes.newBuilder();
+ new FieldMaskTree()
+ .addFieldPath("payload.optional_nested_message")
+ .merge(source, builder, options);
+ expected = NestedTestAllTypes.newBuilder();
+ expected.getPayloadBuilder().setOptionalNestedMessage(NestedMessage.newBuilder().setBb(5678));
+ assertEquals(expected.build(), builder.build());
+
+ builder = NestedTestAllTypes.newBuilder();
+ new FieldMaskTree().addFieldPath("payload.repeated_int32").merge(source, builder, options);
+ expected = NestedTestAllTypes.newBuilder();
+ expected.getPayloadBuilder().addRepeatedInt32(4321);
+ assertEquals(expected.build(), builder.build());
+
+ builder = NestedTestAllTypes.newBuilder();
+ new FieldMaskTree()
+ .addFieldPath("payload.repeated_nested_message")
+ .merge(source, builder, options);
+ expected = NestedTestAllTypes.newBuilder();
+ expected.getPayloadBuilder().addRepeatedNestedMessage(NestedMessage.newBuilder().setBb(8765));
+ assertEquals(expected.build(), builder.build());
+
+ builder = NestedTestAllTypes.newBuilder();
+ new FieldMaskTree()
+ .addFieldPath("child.payload.optional_int32")
+ .merge(source, builder, options);
+ expected = NestedTestAllTypes.newBuilder();
+ expected.getChildBuilder().getPayloadBuilder().setOptionalInt32(1234);
+ assertEquals(expected.build(), builder.build());
+
+ builder = NestedTestAllTypes.newBuilder();
+ new FieldMaskTree()
+ .addFieldPath("child.payload.optional_nested_message")
+ .merge(source, builder, options);
+ expected = NestedTestAllTypes.newBuilder();
+ expected
+ .getChildBuilder()
+ .getPayloadBuilder()
+ .setOptionalNestedMessage(NestedMessage.newBuilder().setBb(5678));
+ assertEquals(expected.build(), builder.build());
+
+ builder = NestedTestAllTypes.newBuilder();
+ new FieldMaskTree()
+ .addFieldPath("child.payload.repeated_int32")
+ .merge(source, builder, options);
+ expected = NestedTestAllTypes.newBuilder();
+ expected.getChildBuilder().getPayloadBuilder().addRepeatedInt32(4321);
+ assertEquals(expected.build(), builder.build());
+
+ builder = NestedTestAllTypes.newBuilder();
+ new FieldMaskTree()
+ .addFieldPath("child.payload.repeated_nested_message")
+ .merge(source, builder, options);
+ expected = NestedTestAllTypes.newBuilder();
+ expected
+ .getChildBuilder()
+ .getPayloadBuilder()
+ .addRepeatedNestedMessage(NestedMessage.newBuilder().setBb(8765));
+ assertEquals(expected.build(), builder.build());
+
+ // Test merging all fields.
+ builder = NestedTestAllTypes.newBuilder();
+ new FieldMaskTree()
+ .addFieldPath("child")
+ .addFieldPath("payload")
+ .merge(source, builder, options);
+ assertEquals(source, builder.build());
+
+ // Test repeated options.
+ builder = NestedTestAllTypes.newBuilder();
+ builder.getPayloadBuilder().addRepeatedInt32(1000);
+ new FieldMaskTree().addFieldPath("payload.repeated_int32").merge(source, builder, options);
+ // Default behavior is to append repeated fields.
+ assertEquals(2, builder.getPayload().getRepeatedInt32Count());
+ assertEquals(1000, builder.getPayload().getRepeatedInt32(0));
+ assertEquals(4321, builder.getPayload().getRepeatedInt32(1));
+ // Change to replace repeated fields.
+ options.setReplaceRepeatedFields(true);
+ new FieldMaskTree().addFieldPath("payload.repeated_int32").merge(source, builder, options);
+ assertEquals(1, builder.getPayload().getRepeatedInt32Count());
+ assertEquals(4321, builder.getPayload().getRepeatedInt32(0));
+
+ // Test message options.
+ builder = NestedTestAllTypes.newBuilder();
+ builder.getPayloadBuilder().setOptionalInt32(1000);
+ builder.getPayloadBuilder().setOptionalUint32(2000);
+ new FieldMaskTree().addFieldPath("payload").merge(source, builder, options);
+ // Default behavior is to merge message fields.
+ assertEquals(1234, builder.getPayload().getOptionalInt32());
+ assertEquals(2000, builder.getPayload().getOptionalUint32());
+
+ // Test merging unset message fields.
+ NestedTestAllTypes clearedSource = source.toBuilder().clearPayload().build();
+ builder = NestedTestAllTypes.newBuilder();
+ new FieldMaskTree().addFieldPath("payload").merge(clearedSource, builder, options);
+ assertEquals(false, builder.hasPayload());
+
+ // Change to replace message fields.
+ options.setReplaceMessageFields(true);
+ builder = NestedTestAllTypes.newBuilder();
+ builder.getPayloadBuilder().setOptionalInt32(1000);
+ builder.getPayloadBuilder().setOptionalUint32(2000);
+ new FieldMaskTree().addFieldPath("payload").merge(source, builder, options);
+ assertEquals(1234, builder.getPayload().getOptionalInt32());
+ assertEquals(0, builder.getPayload().getOptionalUint32());
+
+ // Test merging unset message fields.
+ builder = NestedTestAllTypes.newBuilder();
+ builder.getPayloadBuilder().setOptionalInt32(1000);
+ builder.getPayloadBuilder().setOptionalUint32(2000);
+ new FieldMaskTree().addFieldPath("payload").merge(clearedSource, builder, options);
+ assertEquals(false, builder.hasPayload());
+
+ // Test merging unset primitive fields.
+ builder = source.toBuilder();
+ builder.getPayloadBuilder().clearOptionalInt32();
+ NestedTestAllTypes sourceWithPayloadInt32Unset = builder.build();
+ builder = source.toBuilder();
+ new FieldMaskTree()
+ .addFieldPath("payload.optional_int32")
+ .merge(sourceWithPayloadInt32Unset, builder, options);
+ assertEquals(true, builder.getPayload().hasOptionalInt32());
+ assertEquals(0, builder.getPayload().getOptionalInt32());
+
+ // Change to clear unset primitive fields.
+ options.setReplacePrimitiveFields(true);
+ builder = source.toBuilder();
+ new FieldMaskTree()
+ .addFieldPath("payload.optional_int32")
+ .merge(sourceWithPayloadInt32Unset, builder, options);
+ assertEquals(true, builder.hasPayload());
+ assertEquals(false, builder.getPayload().hasOptionalInt32());
+ }
+}
diff --git a/third_party/protobuf/java/util/src/test/java/com/google/protobuf/util/FieldMaskUtilTest.java b/third_party/protobuf/java/util/src/test/java/com/google/protobuf/util/FieldMaskUtilTest.java
new file mode 100644
index 0000000000..1a99857053
--- /dev/null
+++ b/third_party/protobuf/java/util/src/test/java/com/google/protobuf/util/FieldMaskUtilTest.java
@@ -0,0 +1,213 @@
+// 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.util;
+
+import com.google.protobuf.FieldMask;
+import protobuf_unittest.UnittestProto.NestedTestAllTypes;
+import protobuf_unittest.UnittestProto.TestAllTypes;
+
+import junit.framework.TestCase;
+
+/** Unit tests for {@link FieldMaskUtil}. */
+public class FieldMaskUtilTest extends TestCase {
+ public void testIsValid() throws Exception {
+ assertTrue(FieldMaskUtil.isValid(NestedTestAllTypes.class, "payload"));
+ assertFalse(FieldMaskUtil.isValid(NestedTestAllTypes.class, "nonexist"));
+ assertTrue(FieldMaskUtil.isValid(NestedTestAllTypes.class, "payload.optional_int32"));
+ assertTrue(FieldMaskUtil.isValid(NestedTestAllTypes.class, "payload.repeated_int32"));
+ assertTrue(FieldMaskUtil.isValid(NestedTestAllTypes.class, "payload.optional_nested_message"));
+ assertTrue(FieldMaskUtil.isValid(NestedTestAllTypes.class, "payload.repeated_nested_message"));
+ assertFalse(FieldMaskUtil.isValid(NestedTestAllTypes.class, "payload.nonexist"));
+
+ assertTrue(
+ FieldMaskUtil.isValid(NestedTestAllTypes.class, FieldMaskUtil.fromString("payload")));
+ assertFalse(
+ FieldMaskUtil.isValid(NestedTestAllTypes.class, FieldMaskUtil.fromString("nonexist")));
+ assertFalse(
+ FieldMaskUtil.isValid(
+ NestedTestAllTypes.class, FieldMaskUtil.fromString("payload,nonexist")));
+
+ assertTrue(FieldMaskUtil.isValid(NestedTestAllTypes.getDescriptor(), "payload"));
+ assertFalse(FieldMaskUtil.isValid(NestedTestAllTypes.getDescriptor(), "nonexist"));
+
+ assertTrue(
+ FieldMaskUtil.isValid(
+ NestedTestAllTypes.getDescriptor(), FieldMaskUtil.fromString("payload")));
+ assertFalse(
+ FieldMaskUtil.isValid(
+ NestedTestAllTypes.getDescriptor(), FieldMaskUtil.fromString("nonexist")));
+
+ assertTrue(
+ FieldMaskUtil.isValid(NestedTestAllTypes.class, "payload.optional_nested_message.bb"));
+ // Repeated fields cannot have sub-paths.
+ assertFalse(
+ FieldMaskUtil.isValid(NestedTestAllTypes.class, "payload.repeated_nested_message.bb"));
+ // Non-message fields cannot have sub-paths.
+ assertFalse(FieldMaskUtil.isValid(NestedTestAllTypes.class, "payload.optional_int32.bb"));
+ }
+
+ public void testToString() throws Exception {
+ assertEquals("", FieldMaskUtil.toString(FieldMask.getDefaultInstance()));
+ FieldMask mask = FieldMask.newBuilder().addPaths("foo").build();
+ assertEquals("foo", FieldMaskUtil.toString(mask));
+ mask = FieldMask.newBuilder().addPaths("foo").addPaths("bar").build();
+ assertEquals("foo,bar", FieldMaskUtil.toString(mask));
+
+ // Empty field paths are ignored.
+ mask =
+ FieldMask.newBuilder()
+ .addPaths("")
+ .addPaths("foo")
+ .addPaths("")
+ .addPaths("bar")
+ .addPaths("")
+ .build();
+ assertEquals("foo,bar", FieldMaskUtil.toString(mask));
+ }
+
+ public void testFromString() throws Exception {
+ FieldMask mask = FieldMaskUtil.fromString("");
+ assertEquals(0, mask.getPathsCount());
+ mask = FieldMaskUtil.fromString("foo");
+ assertEquals(1, mask.getPathsCount());
+ assertEquals("foo", mask.getPaths(0));
+ mask = FieldMaskUtil.fromString("foo,bar.baz");
+ assertEquals(2, mask.getPathsCount());
+ assertEquals("foo", mask.getPaths(0));
+ assertEquals("bar.baz", mask.getPaths(1));
+
+ // Empty field paths are ignore.
+ mask = FieldMaskUtil.fromString(",foo,,bar,");
+ assertEquals(2, mask.getPathsCount());
+ assertEquals("foo", mask.getPaths(0));
+ assertEquals("bar", mask.getPaths(1));
+
+ // Check whether the field paths are valid if a class parameter is provided.
+ mask = FieldMaskUtil.fromString(NestedTestAllTypes.class, ",payload");
+
+ try {
+ mask = FieldMaskUtil.fromString(NestedTestAllTypes.class, "payload,nonexist");
+ fail("Exception is expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+ }
+
+ public void testFromFieldNumbers() throws Exception {
+ FieldMask mask = FieldMaskUtil.fromFieldNumbers(TestAllTypes.class);
+ assertEquals(0, mask.getPathsCount());
+ mask =
+ FieldMaskUtil.fromFieldNumbers(
+ TestAllTypes.class, TestAllTypes.OPTIONAL_INT32_FIELD_NUMBER);
+ assertEquals(1, mask.getPathsCount());
+ assertEquals("optional_int32", mask.getPaths(0));
+ mask =
+ FieldMaskUtil.fromFieldNumbers(
+ TestAllTypes.class,
+ TestAllTypes.OPTIONAL_INT32_FIELD_NUMBER,
+ TestAllTypes.OPTIONAL_INT64_FIELD_NUMBER);
+ assertEquals(2, mask.getPathsCount());
+ assertEquals("optional_int32", mask.getPaths(0));
+ assertEquals("optional_int64", mask.getPaths(1));
+
+ try {
+ int invalidFieldNumber = 1000;
+ mask = FieldMaskUtil.fromFieldNumbers(TestAllTypes.class, invalidFieldNumber);
+ fail("Exception is expected.");
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+
+ public void testToJsonString() throws Exception {
+ FieldMask mask = FieldMask.getDefaultInstance();
+ assertEquals("", FieldMaskUtil.toJsonString(mask));
+ mask = FieldMask.newBuilder().addPaths("foo").build();
+ assertEquals("foo", FieldMaskUtil.toJsonString(mask));
+ mask = FieldMask.newBuilder().addPaths("foo.bar_baz").addPaths("").build();
+ assertEquals("foo.barBaz", FieldMaskUtil.toJsonString(mask));
+ mask = FieldMask.newBuilder().addPaths("foo").addPaths("bar_baz").build();
+ assertEquals("foo,barBaz", FieldMaskUtil.toJsonString(mask));
+ }
+
+ public void testFromJsonString() throws Exception {
+ FieldMask mask = FieldMaskUtil.fromJsonString("");
+ assertEquals(0, mask.getPathsCount());
+ mask = FieldMaskUtil.fromJsonString("foo");
+ assertEquals(1, mask.getPathsCount());
+ assertEquals("foo", mask.getPaths(0));
+ mask = FieldMaskUtil.fromJsonString("foo.barBaz");
+ assertEquals(1, mask.getPathsCount());
+ assertEquals("foo.bar_baz", mask.getPaths(0));
+ mask = FieldMaskUtil.fromJsonString("foo,barBaz");
+ assertEquals(2, mask.getPathsCount());
+ assertEquals("foo", mask.getPaths(0));
+ assertEquals("bar_baz", mask.getPaths(1));
+ }
+
+ public void testUnion() throws Exception {
+ // Only test a simple case here and expect
+ // {@link FieldMaskTreeTest#testAddFieldPath} to cover all scenarios.
+ FieldMask mask1 = FieldMaskUtil.fromString("foo,bar.baz,bar.quz");
+ FieldMask mask2 = FieldMaskUtil.fromString("foo.bar,bar");
+ FieldMask result = FieldMaskUtil.union(mask1, mask2);
+ assertEquals("bar,foo", FieldMaskUtil.toString(result));
+ }
+
+ public void testUnion_usingVarArgs() throws Exception {
+ FieldMask mask1 = FieldMaskUtil.fromString("foo");
+ FieldMask mask2 = FieldMaskUtil.fromString("foo.bar,bar.quz");
+ FieldMask mask3 = FieldMaskUtil.fromString("bar.quz");
+ FieldMask mask4 = FieldMaskUtil.fromString("bar");
+ FieldMask result = FieldMaskUtil.union(mask1, mask2, mask3, mask4);
+ assertEquals("bar,foo", FieldMaskUtil.toString(result));
+ }
+
+ public void testIntersection() throws Exception {
+ // Only test a simple case here and expect
+ // {@link FieldMaskTreeTest#testIntersectFieldPath} to cover all scenarios.
+ FieldMask mask1 = FieldMaskUtil.fromString("foo,bar.baz,bar.quz");
+ FieldMask mask2 = FieldMaskUtil.fromString("foo.bar,bar");
+ FieldMask result = FieldMaskUtil.intersection(mask1, mask2);
+ assertEquals("bar.baz,bar.quz,foo.bar", FieldMaskUtil.toString(result));
+ }
+
+ public void testMerge() throws Exception {
+ // Only test a simple case here and expect
+ // {@link FieldMaskTreeTest#testMerge} to cover all scenarios.
+ NestedTestAllTypes source =
+ NestedTestAllTypes.newBuilder()
+ .setPayload(TestAllTypes.newBuilder().setOptionalInt32(1234))
+ .build();
+ NestedTestAllTypes.Builder builder = NestedTestAllTypes.newBuilder();
+ FieldMaskUtil.merge(FieldMaskUtil.fromString("payload"), source, builder);
+ assertEquals(1234, builder.getPayload().getOptionalInt32());
+ }
+}
diff --git a/third_party/protobuf/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java b/third_party/protobuf/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java
new file mode 100644
index 0000000000..de02c117e3
--- /dev/null
+++ b/third_party/protobuf/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java
@@ -0,0 +1,1454 @@
+// 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.util;
+
+import com.google.protobuf.Any;
+import com.google.protobuf.BoolValue;
+import com.google.protobuf.ByteString;
+import com.google.protobuf.BytesValue;
+import com.google.protobuf.DoubleValue;
+import com.google.protobuf.FloatValue;
+import com.google.protobuf.Int32Value;
+import com.google.protobuf.Int64Value;
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.google.protobuf.ListValue;
+import com.google.protobuf.Message;
+import com.google.protobuf.NullValue;
+import com.google.protobuf.StringValue;
+import com.google.protobuf.Struct;
+import com.google.protobuf.UInt32Value;
+import com.google.protobuf.UInt64Value;
+import com.google.protobuf.Value;
+import com.google.protobuf.util.JsonFormat.TypeRegistry;
+import com.google.protobuf.util.JsonTestProto.TestAllTypes;
+import com.google.protobuf.util.JsonTestProto.TestAllTypes.NestedEnum;
+import com.google.protobuf.util.JsonTestProto.TestAllTypes.NestedMessage;
+import com.google.protobuf.util.JsonTestProto.TestAny;
+import com.google.protobuf.util.JsonTestProto.TestCustomJsonName;
+import com.google.protobuf.util.JsonTestProto.TestDuration;
+import com.google.protobuf.util.JsonTestProto.TestFieldMask;
+import com.google.protobuf.util.JsonTestProto.TestMap;
+import com.google.protobuf.util.JsonTestProto.TestOneof;
+import com.google.protobuf.util.JsonTestProto.TestRecursive;
+import com.google.protobuf.util.JsonTestProto.TestStruct;
+import com.google.protobuf.util.JsonTestProto.TestTimestamp;
+import com.google.protobuf.util.JsonTestProto.TestWrappers;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import junit.framework.TestCase;
+
+public class JsonFormatTest extends TestCase {
+ public JsonFormatTest() {
+ // Test that locale does not affect JsonFormat.
+ Locale.setDefault(Locale.forLanguageTag("hi-IN"));
+ }
+
+ private void setAllFields(TestAllTypes.Builder builder) {
+ builder.setOptionalInt32(1234);
+ builder.setOptionalInt64(1234567890123456789L);
+ builder.setOptionalUint32(5678);
+ builder.setOptionalUint64(2345678901234567890L);
+ builder.setOptionalSint32(9012);
+ builder.setOptionalSint64(3456789012345678901L);
+ builder.setOptionalFixed32(3456);
+ builder.setOptionalFixed64(4567890123456789012L);
+ builder.setOptionalSfixed32(7890);
+ builder.setOptionalSfixed64(5678901234567890123L);
+ builder.setOptionalFloat(1.5f);
+ builder.setOptionalDouble(1.25);
+ builder.setOptionalBool(true);
+ builder.setOptionalString("Hello world!");
+ builder.setOptionalBytes(ByteString.copyFrom(new byte[] {0, 1, 2}));
+ builder.setOptionalNestedEnum(NestedEnum.BAR);
+ builder.getOptionalNestedMessageBuilder().setValue(100);
+
+ builder.addRepeatedInt32(1234);
+ builder.addRepeatedInt64(1234567890123456789L);
+ builder.addRepeatedUint32(5678);
+ builder.addRepeatedUint64(2345678901234567890L);
+ builder.addRepeatedSint32(9012);
+ builder.addRepeatedSint64(3456789012345678901L);
+ builder.addRepeatedFixed32(3456);
+ builder.addRepeatedFixed64(4567890123456789012L);
+ builder.addRepeatedSfixed32(7890);
+ builder.addRepeatedSfixed64(5678901234567890123L);
+ builder.addRepeatedFloat(1.5f);
+ builder.addRepeatedDouble(1.25);
+ builder.addRepeatedBool(true);
+ builder.addRepeatedString("Hello world!");
+ builder.addRepeatedBytes(ByteString.copyFrom(new byte[] {0, 1, 2}));
+ builder.addRepeatedNestedEnum(NestedEnum.BAR);
+ builder.addRepeatedNestedMessageBuilder().setValue(100);
+
+ builder.addRepeatedInt32(234);
+ builder.addRepeatedInt64(234567890123456789L);
+ builder.addRepeatedUint32(678);
+ builder.addRepeatedUint64(345678901234567890L);
+ builder.addRepeatedSint32(012);
+ builder.addRepeatedSint64(456789012345678901L);
+ builder.addRepeatedFixed32(456);
+ builder.addRepeatedFixed64(567890123456789012L);
+ builder.addRepeatedSfixed32(890);
+ builder.addRepeatedSfixed64(678901234567890123L);
+ builder.addRepeatedFloat(11.5f);
+ builder.addRepeatedDouble(11.25);
+ builder.addRepeatedBool(true);
+ builder.addRepeatedString("ello world!");
+ builder.addRepeatedBytes(ByteString.copyFrom(new byte[] {1, 2}));
+ builder.addRepeatedNestedEnum(NestedEnum.BAZ);
+ builder.addRepeatedNestedMessageBuilder().setValue(200);
+ }
+
+ private void assertRoundTripEquals(Message message) throws Exception {
+ assertRoundTripEquals(message, TypeRegistry.getEmptyTypeRegistry());
+ }
+
+ private void assertRoundTripEquals(Message message, TypeRegistry registry) throws Exception {
+ JsonFormat.Printer printer = JsonFormat.printer().usingTypeRegistry(registry);
+ JsonFormat.Parser parser = JsonFormat.parser().usingTypeRegistry(registry);
+ Message.Builder builder = message.newBuilderForType();
+ parser.merge(printer.print(message), builder);
+ Message parsedMessage = builder.build();
+ assertEquals(message.toString(), parsedMessage.toString());
+ }
+
+ private String toJsonString(Message message) throws IOException {
+ return JsonFormat.printer().print(message);
+ }
+ private String toCompactJsonString(Message message) throws IOException {
+ return JsonFormat.printer().omittingInsignificantWhitespace().print(message);
+ }
+
+ private void mergeFromJson(String json, Message.Builder builder) throws IOException {
+ JsonFormat.parser().merge(json, builder);
+ }
+
+ public void testAllFields() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ setAllFields(builder);
+ TestAllTypes message = builder.build();
+
+ assertEquals(
+ "{\n"
+ + " \"optionalInt32\": 1234,\n"
+ + " \"optionalInt64\": \"1234567890123456789\",\n"
+ + " \"optionalUint32\": 5678,\n"
+ + " \"optionalUint64\": \"2345678901234567890\",\n"
+ + " \"optionalSint32\": 9012,\n"
+ + " \"optionalSint64\": \"3456789012345678901\",\n"
+ + " \"optionalFixed32\": 3456,\n"
+ + " \"optionalFixed64\": \"4567890123456789012\",\n"
+ + " \"optionalSfixed32\": 7890,\n"
+ + " \"optionalSfixed64\": \"5678901234567890123\",\n"
+ + " \"optionalFloat\": 1.5,\n"
+ + " \"optionalDouble\": 1.25,\n"
+ + " \"optionalBool\": true,\n"
+ + " \"optionalString\": \"Hello world!\",\n"
+ + " \"optionalBytes\": \"AAEC\",\n"
+ + " \"optionalNestedMessage\": {\n"
+ + " \"value\": 100\n"
+ + " },\n"
+ + " \"optionalNestedEnum\": \"BAR\",\n"
+ + " \"repeatedInt32\": [1234, 234],\n"
+ + " \"repeatedInt64\": [\"1234567890123456789\", \"234567890123456789\"],\n"
+ + " \"repeatedUint32\": [5678, 678],\n"
+ + " \"repeatedUint64\": [\"2345678901234567890\", \"345678901234567890\"],\n"
+ + " \"repeatedSint32\": [9012, 10],\n"
+ + " \"repeatedSint64\": [\"3456789012345678901\", \"456789012345678901\"],\n"
+ + " \"repeatedFixed32\": [3456, 456],\n"
+ + " \"repeatedFixed64\": [\"4567890123456789012\", \"567890123456789012\"],\n"
+ + " \"repeatedSfixed32\": [7890, 890],\n"
+ + " \"repeatedSfixed64\": [\"5678901234567890123\", \"678901234567890123\"],\n"
+ + " \"repeatedFloat\": [1.5, 11.5],\n"
+ + " \"repeatedDouble\": [1.25, 11.25],\n"
+ + " \"repeatedBool\": [true, true],\n"
+ + " \"repeatedString\": [\"Hello world!\", \"ello world!\"],\n"
+ + " \"repeatedBytes\": [\"AAEC\", \"AQI=\"],\n"
+ + " \"repeatedNestedMessage\": [{\n"
+ + " \"value\": 100\n"
+ + " }, {\n"
+ + " \"value\": 200\n"
+ + " }],\n"
+ + " \"repeatedNestedEnum\": [\"BAR\", \"BAZ\"]\n"
+ + "}",
+ toJsonString(message));
+
+ assertRoundTripEquals(message);
+ }
+
+ public void testUnknownEnumValues() throws Exception {
+ TestAllTypes message =
+ TestAllTypes.newBuilder()
+ .setOptionalNestedEnumValue(12345)
+ .addRepeatedNestedEnumValue(12345)
+ .addRepeatedNestedEnumValue(0)
+ .build();
+ assertEquals(
+ "{\n"
+ + " \"optionalNestedEnum\": 12345,\n"
+ + " \"repeatedNestedEnum\": [12345, \"FOO\"]\n"
+ + "}",
+ toJsonString(message));
+ assertRoundTripEquals(message);
+
+ TestMap.Builder mapBuilder = TestMap.newBuilder();
+ mapBuilder.putInt32ToEnumMapValue(1, 0);
+ Map<Integer, Integer> mapWithInvalidValues = new HashMap<Integer, Integer>();
+ mapWithInvalidValues.put(2, 12345);
+ mapBuilder.putAllInt32ToEnumMapValue(mapWithInvalidValues);
+ TestMap mapMessage = mapBuilder.build();
+ assertEquals(
+ "{\n"
+ + " \"int32ToEnumMap\": {\n"
+ + " \"1\": \"FOO\",\n"
+ + " \"2\": 12345\n"
+ + " }\n"
+ + "}",
+ toJsonString(mapMessage));
+ assertRoundTripEquals(mapMessage);
+ }
+
+ public void testSpecialFloatValues() throws Exception {
+ TestAllTypes message =
+ TestAllTypes.newBuilder()
+ .addRepeatedFloat(Float.NaN)
+ .addRepeatedFloat(Float.POSITIVE_INFINITY)
+ .addRepeatedFloat(Float.NEGATIVE_INFINITY)
+ .addRepeatedDouble(Double.NaN)
+ .addRepeatedDouble(Double.POSITIVE_INFINITY)
+ .addRepeatedDouble(Double.NEGATIVE_INFINITY)
+ .build();
+ assertEquals(
+ "{\n"
+ + " \"repeatedFloat\": [\"NaN\", \"Infinity\", \"-Infinity\"],\n"
+ + " \"repeatedDouble\": [\"NaN\", \"Infinity\", \"-Infinity\"]\n"
+ + "}",
+ toJsonString(message));
+
+ assertRoundTripEquals(message);
+ }
+
+ public void testParserAcceptStringForNumbericField() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ mergeFromJson(
+ "{\n"
+ + " \"optionalInt32\": \"1234\",\n"
+ + " \"optionalUint32\": \"5678\",\n"
+ + " \"optionalSint32\": \"9012\",\n"
+ + " \"optionalFixed32\": \"3456\",\n"
+ + " \"optionalSfixed32\": \"7890\",\n"
+ + " \"optionalFloat\": \"1.5\",\n"
+ + " \"optionalDouble\": \"1.25\",\n"
+ + " \"optionalBool\": \"true\"\n"
+ + "}",
+ builder);
+ TestAllTypes message = builder.build();
+ assertEquals(1234, message.getOptionalInt32());
+ assertEquals(5678, message.getOptionalUint32());
+ assertEquals(9012, message.getOptionalSint32());
+ assertEquals(3456, message.getOptionalFixed32());
+ assertEquals(7890, message.getOptionalSfixed32());
+ assertEquals(1.5f, message.getOptionalFloat());
+ assertEquals(1.25, message.getOptionalDouble());
+ assertEquals(true, message.getOptionalBool());
+ }
+
+ public void testParserAcceptFloatingPointValueForIntegerField() throws Exception {
+ // Test that numeric values like "1.000", "1e5" will also be accepted.
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ mergeFromJson(
+ "{\n"
+ + " \"repeatedInt32\": [1.000, 1e5, \"1.000\", \"1e5\"],\n"
+ + " \"repeatedUint32\": [1.000, 1e5, \"1.000\", \"1e5\"],\n"
+ + " \"repeatedInt64\": [1.000, 1e5, \"1.000\", \"1e5\"],\n"
+ + " \"repeatedUint64\": [1.000, 1e5, \"1.000\", \"1e5\"]\n"
+ + "}",
+ builder);
+ int[] expectedValues = new int[] {1, 100000, 1, 100000};
+ assertEquals(4, builder.getRepeatedInt32Count());
+ assertEquals(4, builder.getRepeatedUint32Count());
+ assertEquals(4, builder.getRepeatedInt64Count());
+ assertEquals(4, builder.getRepeatedUint64Count());
+ for (int i = 0; i < 4; ++i) {
+ assertEquals(expectedValues[i], builder.getRepeatedInt32(i));
+ assertEquals(expectedValues[i], builder.getRepeatedUint32(i));
+ assertEquals(expectedValues[i], builder.getRepeatedInt64(i));
+ assertEquals(expectedValues[i], builder.getRepeatedUint64(i));
+ }
+
+ // Non-integers will still be rejected.
+ assertRejects("optionalInt32", "1.5");
+ assertRejects("optionalUint32", "1.5");
+ assertRejects("optionalInt64", "1.5");
+ assertRejects("optionalUint64", "1.5");
+ }
+
+ private void assertRejects(String name, String value) {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ try {
+ // Numeric form is rejected.
+ mergeFromJson("{\"" + name + "\":" + value + "}", builder);
+ fail("Exception is expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ try {
+ // String form is also rejected.
+ mergeFromJson("{\"" + name + "\":\"" + value + "\"}", builder);
+ fail("Exception is expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ private void assertAccepts(String name, String value) throws IOException {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ // Both numeric form and string form are accepted.
+ mergeFromJson("{\"" + name + "\":" + value + "}", builder);
+ builder.clear();
+ mergeFromJson("{\"" + name + "\":\"" + value + "\"}", builder);
+ }
+
+ public void testParserRejectOutOfRangeNumericValues() throws Exception {
+ assertAccepts("optionalInt32", String.valueOf(Integer.MAX_VALUE));
+ assertAccepts("optionalInt32", String.valueOf(Integer.MIN_VALUE));
+ assertRejects("optionalInt32", String.valueOf(Integer.MAX_VALUE + 1L));
+ assertRejects("optionalInt32", String.valueOf(Integer.MIN_VALUE - 1L));
+
+ assertAccepts("optionalUint32", String.valueOf(Integer.MAX_VALUE + 1L));
+ assertRejects("optionalUint32", "123456789012345");
+ assertRejects("optionalUint32", "-1");
+
+ BigInteger one = new BigInteger("1");
+ BigInteger maxLong = new BigInteger(String.valueOf(Long.MAX_VALUE));
+ BigInteger minLong = new BigInteger(String.valueOf(Long.MIN_VALUE));
+ assertAccepts("optionalInt64", maxLong.toString());
+ assertAccepts("optionalInt64", minLong.toString());
+ assertRejects("optionalInt64", maxLong.add(one).toString());
+ assertRejects("optionalInt64", minLong.subtract(one).toString());
+
+ assertAccepts("optionalUint64", maxLong.add(one).toString());
+ assertRejects("optionalUint64", "1234567890123456789012345");
+ assertRejects("optionalUint64", "-1");
+
+ assertAccepts("optionalBool", "true");
+ assertRejects("optionalBool", "1");
+ assertRejects("optionalBool", "0");
+
+ assertAccepts("optionalFloat", String.valueOf(Float.MAX_VALUE));
+ assertAccepts("optionalFloat", String.valueOf(-Float.MAX_VALUE));
+ assertRejects("optionalFloat", String.valueOf(Double.MAX_VALUE));
+ assertRejects("optionalFloat", String.valueOf(-Double.MAX_VALUE));
+
+ BigDecimal moreThanOne = new BigDecimal("1.000001");
+ BigDecimal maxDouble = new BigDecimal(Double.MAX_VALUE);
+ BigDecimal minDouble = new BigDecimal(-Double.MAX_VALUE);
+ assertAccepts("optionalDouble", maxDouble.toString());
+ assertAccepts("optionalDouble", minDouble.toString());
+ assertRejects("optionalDouble", maxDouble.multiply(moreThanOne).toString());
+ assertRejects("optionalDouble", minDouble.multiply(moreThanOne).toString());
+ }
+
+ public void testParserAcceptNull() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ mergeFromJson(
+ "{\n"
+ + " \"optionalInt32\": null,\n"
+ + " \"optionalInt64\": null,\n"
+ + " \"optionalUint32\": null,\n"
+ + " \"optionalUint64\": null,\n"
+ + " \"optionalSint32\": null,\n"
+ + " \"optionalSint64\": null,\n"
+ + " \"optionalFixed32\": null,\n"
+ + " \"optionalFixed64\": null,\n"
+ + " \"optionalSfixed32\": null,\n"
+ + " \"optionalSfixed64\": null,\n"
+ + " \"optionalFloat\": null,\n"
+ + " \"optionalDouble\": null,\n"
+ + " \"optionalBool\": null,\n"
+ + " \"optionalString\": null,\n"
+ + " \"optionalBytes\": null,\n"
+ + " \"optionalNestedMessage\": null,\n"
+ + " \"optionalNestedEnum\": null,\n"
+ + " \"repeatedInt32\": null,\n"
+ + " \"repeatedInt64\": null,\n"
+ + " \"repeatedUint32\": null,\n"
+ + " \"repeatedUint64\": null,\n"
+ + " \"repeatedSint32\": null,\n"
+ + " \"repeatedSint64\": null,\n"
+ + " \"repeatedFixed32\": null,\n"
+ + " \"repeatedFixed64\": null,\n"
+ + " \"repeatedSfixed32\": null,\n"
+ + " \"repeatedSfixed64\": null,\n"
+ + " \"repeatedFloat\": null,\n"
+ + " \"repeatedDouble\": null,\n"
+ + " \"repeatedBool\": null,\n"
+ + " \"repeatedString\": null,\n"
+ + " \"repeatedBytes\": null,\n"
+ + " \"repeatedNestedMessage\": null,\n"
+ + " \"repeatedNestedEnum\": null\n"
+ + "}",
+ builder);
+ TestAllTypes message = builder.build();
+ assertEquals(TestAllTypes.getDefaultInstance(), message);
+
+ // Repeated field elements cannot be null.
+ try {
+ builder = TestAllTypes.newBuilder();
+ mergeFromJson("{\n" + " \"repeatedInt32\": [null, null],\n" + "}", builder);
+ fail();
+ } catch (InvalidProtocolBufferException e) {
+ // Exception expected.
+ }
+
+ try {
+ builder = TestAllTypes.newBuilder();
+ mergeFromJson("{\n" + " \"repeatedNestedMessage\": [null, null],\n" + "}", builder);
+ fail();
+ } catch (InvalidProtocolBufferException e) {
+ // Exception expected.
+ }
+ }
+
+ public void testNullInOneof() throws Exception {
+ TestOneof.Builder builder = TestOneof.newBuilder();
+ mergeFromJson("{\n" + " \"oneofNullValue\": null \n" + "}", builder);
+ TestOneof message = builder.build();
+ assertEquals(TestOneof.OneofFieldCase.ONEOF_NULL_VALUE, message.getOneofFieldCase());
+ assertEquals(NullValue.NULL_VALUE, message.getOneofNullValue());
+ }
+
+ public void testParserRejectDuplicatedFields() throws Exception {
+ // TODO(xiaofeng): The parser we are currently using (GSON) will accept and keep the last
+ // one if multiple entries have the same name. This is not the desired behavior but it can
+ // only be fixed by using our own parser. Here we only test the cases where the names are
+ // different but still referring to the same field.
+
+ // Duplicated optional fields.
+ try {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ mergeFromJson(
+ "{\n"
+ + " \"optionalNestedMessage\": {},\n"
+ + " \"optional_nested_message\": {}\n"
+ + "}",
+ builder);
+ fail();
+ } catch (InvalidProtocolBufferException e) {
+ // Exception expected.
+ }
+
+ // Duplicated repeated fields.
+ try {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ mergeFromJson(
+ "{\n"
+ + " \"repeatedNestedMessage\": [null, null],\n"
+ + " \"repeated_nested_message\": [null, null]\n"
+ + "}",
+ builder);
+ fail();
+ } catch (InvalidProtocolBufferException e) {
+ // Exception expected.
+ }
+
+ // Duplicated oneof fields.
+ try {
+ TestOneof.Builder builder = TestOneof.newBuilder();
+ mergeFromJson("{\n" + " \"oneofInt32\": 1,\n" + " \"oneof_int32\": 2\n" + "}", builder);
+ fail();
+ } catch (InvalidProtocolBufferException e) {
+ // Exception expected.
+ }
+ }
+
+ public void testMapFields() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ builder.putInt32ToInt32Map(1, 10);
+ builder.putInt64ToInt32Map(1234567890123456789L, 10);
+ builder.putUint32ToInt32Map(2, 20);
+ builder.putUint64ToInt32Map(2234567890123456789L, 20);
+ builder.putSint32ToInt32Map(3, 30);
+ builder.putSint64ToInt32Map(3234567890123456789L, 30);
+ builder.putFixed32ToInt32Map(4, 40);
+ builder.putFixed64ToInt32Map(4234567890123456789L, 40);
+ builder.putSfixed32ToInt32Map(5, 50);
+ builder.putSfixed64ToInt32Map(5234567890123456789L, 50);
+ builder.putBoolToInt32Map(false, 6);
+ builder.putStringToInt32Map("Hello", 10);
+
+ builder.putInt32ToInt64Map(1, 1234567890123456789L);
+ builder.putInt32ToUint32Map(2, 20);
+ builder.putInt32ToUint64Map(2, 2234567890123456789L);
+ builder.putInt32ToSint32Map(3, 30);
+ builder.putInt32ToSint64Map(3, 3234567890123456789L);
+ builder.putInt32ToFixed32Map(4, 40);
+ builder.putInt32ToFixed64Map(4, 4234567890123456789L);
+ builder.putInt32ToSfixed32Map(5, 50);
+ builder.putInt32ToSfixed64Map(5, 5234567890123456789L);
+ builder.putInt32ToFloatMap(6, 1.5f);
+ builder.putInt32ToDoubleMap(6, 1.25);
+ builder.putInt32ToBoolMap(7, false);
+ builder.putInt32ToStringMap(7, "World");
+ builder.putInt32ToBytesMap(8, ByteString.copyFrom(new byte[] {1, 2, 3}));
+ builder.putInt32ToMessageMap(8, NestedMessage.newBuilder().setValue(1234).build());
+ builder.putInt32ToEnumMap(9, NestedEnum.BAR);
+ TestMap message = builder.build();
+
+ assertEquals(
+ "{\n"
+ + " \"int32ToInt32Map\": {\n"
+ + " \"1\": 10\n"
+ + " },\n"
+ + " \"int64ToInt32Map\": {\n"
+ + " \"1234567890123456789\": 10\n"
+ + " },\n"
+ + " \"uint32ToInt32Map\": {\n"
+ + " \"2\": 20\n"
+ + " },\n"
+ + " \"uint64ToInt32Map\": {\n"
+ + " \"2234567890123456789\": 20\n"
+ + " },\n"
+ + " \"sint32ToInt32Map\": {\n"
+ + " \"3\": 30\n"
+ + " },\n"
+ + " \"sint64ToInt32Map\": {\n"
+ + " \"3234567890123456789\": 30\n"
+ + " },\n"
+ + " \"fixed32ToInt32Map\": {\n"
+ + " \"4\": 40\n"
+ + " },\n"
+ + " \"fixed64ToInt32Map\": {\n"
+ + " \"4234567890123456789\": 40\n"
+ + " },\n"
+ + " \"sfixed32ToInt32Map\": {\n"
+ + " \"5\": 50\n"
+ + " },\n"
+ + " \"sfixed64ToInt32Map\": {\n"
+ + " \"5234567890123456789\": 50\n"
+ + " },\n"
+ + " \"boolToInt32Map\": {\n"
+ + " \"false\": 6\n"
+ + " },\n"
+ + " \"stringToInt32Map\": {\n"
+ + " \"Hello\": 10\n"
+ + " },\n"
+ + " \"int32ToInt64Map\": {\n"
+ + " \"1\": \"1234567890123456789\"\n"
+ + " },\n"
+ + " \"int32ToUint32Map\": {\n"
+ + " \"2\": 20\n"
+ + " },\n"
+ + " \"int32ToUint64Map\": {\n"
+ + " \"2\": \"2234567890123456789\"\n"
+ + " },\n"
+ + " \"int32ToSint32Map\": {\n"
+ + " \"3\": 30\n"
+ + " },\n"
+ + " \"int32ToSint64Map\": {\n"
+ + " \"3\": \"3234567890123456789\"\n"
+ + " },\n"
+ + " \"int32ToFixed32Map\": {\n"
+ + " \"4\": 40\n"
+ + " },\n"
+ + " \"int32ToFixed64Map\": {\n"
+ + " \"4\": \"4234567890123456789\"\n"
+ + " },\n"
+ + " \"int32ToSfixed32Map\": {\n"
+ + " \"5\": 50\n"
+ + " },\n"
+ + " \"int32ToSfixed64Map\": {\n"
+ + " \"5\": \"5234567890123456789\"\n"
+ + " },\n"
+ + " \"int32ToFloatMap\": {\n"
+ + " \"6\": 1.5\n"
+ + " },\n"
+ + " \"int32ToDoubleMap\": {\n"
+ + " \"6\": 1.25\n"
+ + " },\n"
+ + " \"int32ToBoolMap\": {\n"
+ + " \"7\": false\n"
+ + " },\n"
+ + " \"int32ToStringMap\": {\n"
+ + " \"7\": \"World\"\n"
+ + " },\n"
+ + " \"int32ToBytesMap\": {\n"
+ + " \"8\": \"AQID\"\n"
+ + " },\n"
+ + " \"int32ToMessageMap\": {\n"
+ + " \"8\": {\n"
+ + " \"value\": 1234\n"
+ + " }\n"
+ + " },\n"
+ + " \"int32ToEnumMap\": {\n"
+ + " \"9\": \"BAR\"\n"
+ + " }\n"
+ + "}",
+ toJsonString(message));
+ assertRoundTripEquals(message);
+
+ // Test multiple entries.
+ builder = TestMap.newBuilder();
+ builder.putInt32ToInt32Map(1, 2);
+ builder.putInt32ToInt32Map(3, 4);
+ message = builder.build();
+
+ assertEquals(
+ "{\n" + " \"int32ToInt32Map\": {\n" + " \"1\": 2,\n" + " \"3\": 4\n" + " }\n" + "}",
+ toJsonString(message));
+ assertRoundTripEquals(message);
+ }
+
+ public void testMapNullValueIsRejected() throws Exception {
+ try {
+ TestMap.Builder builder = TestMap.newBuilder();
+ mergeFromJson(
+ "{\n"
+ + " \"int32ToInt32Map\": {null: 1},\n"
+ + " \"int32ToMessageMap\": {null: 2}\n"
+ + "}",
+ builder);
+ fail();
+ } catch (InvalidProtocolBufferException e) {
+ // Exception expected.
+ }
+
+ try {
+ TestMap.Builder builder = TestMap.newBuilder();
+ mergeFromJson(
+ "{\n"
+ + " \"int32ToInt32Map\": {\"1\": null},\n"
+ + " \"int32ToMessageMap\": {\"2\": null}\n"
+ + "}",
+ builder);
+ fail();
+ } catch (InvalidProtocolBufferException e) {
+ // Exception expected.
+ }
+ }
+
+ public void testParserAcceptNonQuotedObjectKey() throws Exception {
+ TestMap.Builder builder = TestMap.newBuilder();
+ mergeFromJson(
+ "{\n" + " int32ToInt32Map: {1: 2},\n" + " stringToInt32Map: {hello: 3}\n" + "}", builder);
+ TestMap message = builder.build();
+ assertEquals(2, message.getInt32ToInt32Map().get(1).intValue());
+ assertEquals(3, message.getStringToInt32Map().get("hello").intValue());
+ }
+
+ public void testWrappers() throws Exception {
+ TestWrappers.Builder builder = TestWrappers.newBuilder();
+ builder.getBoolValueBuilder().setValue(false);
+ builder.getInt32ValueBuilder().setValue(0);
+ builder.getInt64ValueBuilder().setValue(0);
+ builder.getUint32ValueBuilder().setValue(0);
+ builder.getUint64ValueBuilder().setValue(0);
+ builder.getFloatValueBuilder().setValue(0.0f);
+ builder.getDoubleValueBuilder().setValue(0.0);
+ builder.getStringValueBuilder().setValue("");
+ builder.getBytesValueBuilder().setValue(ByteString.EMPTY);
+ TestWrappers message = builder.build();
+
+ assertEquals(
+ "{\n"
+ + " \"int32Value\": 0,\n"
+ + " \"uint32Value\": 0,\n"
+ + " \"int64Value\": \"0\",\n"
+ + " \"uint64Value\": \"0\",\n"
+ + " \"floatValue\": 0.0,\n"
+ + " \"doubleValue\": 0.0,\n"
+ + " \"boolValue\": false,\n"
+ + " \"stringValue\": \"\",\n"
+ + " \"bytesValue\": \"\"\n"
+ + "}",
+ toJsonString(message));
+ assertRoundTripEquals(message);
+
+ builder = TestWrappers.newBuilder();
+ builder.getBoolValueBuilder().setValue(true);
+ builder.getInt32ValueBuilder().setValue(1);
+ builder.getInt64ValueBuilder().setValue(2);
+ builder.getUint32ValueBuilder().setValue(3);
+ builder.getUint64ValueBuilder().setValue(4);
+ builder.getFloatValueBuilder().setValue(5.0f);
+ builder.getDoubleValueBuilder().setValue(6.0);
+ builder.getStringValueBuilder().setValue("7");
+ builder.getBytesValueBuilder().setValue(ByteString.copyFrom(new byte[] {8}));
+ message = builder.build();
+
+ assertEquals(
+ "{\n"
+ + " \"int32Value\": 1,\n"
+ + " \"uint32Value\": 3,\n"
+ + " \"int64Value\": \"2\",\n"
+ + " \"uint64Value\": \"4\",\n"
+ + " \"floatValue\": 5.0,\n"
+ + " \"doubleValue\": 6.0,\n"
+ + " \"boolValue\": true,\n"
+ + " \"stringValue\": \"7\",\n"
+ + " \"bytesValue\": \"CA==\"\n"
+ + "}",
+ toJsonString(message));
+ assertRoundTripEquals(message);
+ }
+
+ public void testTimestamp() throws Exception {
+ TestTimestamp message =
+ TestTimestamp.newBuilder()
+ .setTimestampValue(Timestamps.parse("1970-01-01T00:00:00Z"))
+ .build();
+
+ assertEquals(
+ "{\n" + " \"timestampValue\": \"1970-01-01T00:00:00Z\"\n" + "}", toJsonString(message));
+ assertRoundTripEquals(message);
+ }
+
+ public void testDuration() throws Exception {
+ TestDuration message =
+ TestDuration.newBuilder().setDurationValue(Durations.parse("12345s")).build();
+
+ assertEquals("{\n" + " \"durationValue\": \"12345s\"\n" + "}", toJsonString(message));
+ assertRoundTripEquals(message);
+ }
+
+ public void testFieldMask() throws Exception {
+ TestFieldMask message =
+ TestFieldMask.newBuilder()
+ .setFieldMaskValue(FieldMaskUtil.fromString("foo.bar,baz,foo_bar.baz"))
+ .build();
+
+ assertEquals(
+ "{\n" + " \"fieldMaskValue\": \"foo.bar,baz,fooBar.baz\"\n" + "}", toJsonString(message));
+ assertRoundTripEquals(message);
+ }
+
+ public void testStruct() throws Exception {
+ // Build a struct with all possible values.
+ TestStruct.Builder builder = TestStruct.newBuilder();
+ Struct.Builder structBuilder = builder.getStructValueBuilder();
+ structBuilder.putFields("null_value", Value.newBuilder().setNullValueValue(0).build());
+ structBuilder.putFields("number_value", Value.newBuilder().setNumberValue(1.25).build());
+ structBuilder.putFields("string_value", Value.newBuilder().setStringValue("hello").build());
+ Struct.Builder subStructBuilder = Struct.newBuilder();
+ subStructBuilder.putFields("number_value", Value.newBuilder().setNumberValue(1234).build());
+ structBuilder.putFields(
+ "struct_value", Value.newBuilder().setStructValue(subStructBuilder.build()).build());
+ ListValue.Builder listBuilder = ListValue.newBuilder();
+ listBuilder.addValues(Value.newBuilder().setNumberValue(1.125).build());
+ listBuilder.addValues(Value.newBuilder().setNullValueValue(0).build());
+ structBuilder.putFields(
+ "list_value", Value.newBuilder().setListValue(listBuilder.build()).build());
+ TestStruct message = builder.build();
+
+ assertEquals(
+ "{\n"
+ + " \"structValue\": {\n"
+ + " \"null_value\": null,\n"
+ + " \"number_value\": 1.25,\n"
+ + " \"string_value\": \"hello\",\n"
+ + " \"struct_value\": {\n"
+ + " \"number_value\": 1234.0\n"
+ + " },\n"
+ + " \"list_value\": [1.125, null]\n"
+ + " }\n"
+ + "}",
+ toJsonString(message));
+ assertRoundTripEquals(message);
+
+ builder = TestStruct.newBuilder();
+ builder.setValue(Value.newBuilder().setNullValueValue(0).build());
+ message = builder.build();
+ assertEquals("{\n" + " \"value\": null\n" + "}", toJsonString(message));
+ assertRoundTripEquals(message);
+
+ builder = TestStruct.newBuilder();
+ listBuilder = builder.getListValueBuilder();
+ listBuilder.addValues(Value.newBuilder().setNumberValue(31831.125).build());
+ listBuilder.addValues(Value.newBuilder().setNullValueValue(0).build());
+ message = builder.build();
+ assertEquals("{\n" + " \"listValue\": [31831.125, null]\n" + "}", toJsonString(message));
+ assertRoundTripEquals(message);
+ }
+
+ public void testAnyFields() throws Exception {
+ TestAllTypes content = TestAllTypes.newBuilder().setOptionalInt32(1234).build();
+ TestAny message = TestAny.newBuilder().setAnyValue(Any.pack(content)).build();
+
+ // A TypeRegistry must be provided in order to convert Any types.
+ try {
+ toJsonString(message);
+ fail("Exception is expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ JsonFormat.TypeRegistry registry =
+ JsonFormat.TypeRegistry.newBuilder().add(TestAllTypes.getDescriptor()).build();
+ JsonFormat.Printer printer = JsonFormat.printer().usingTypeRegistry(registry);
+
+ assertEquals(
+ "{\n"
+ + " \"anyValue\": {\n"
+ + " \"@type\": \"type.googleapis.com/json_test.TestAllTypes\",\n"
+ + " \"optionalInt32\": 1234\n"
+ + " }\n"
+ + "}",
+ 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.
+ Any anyMessage = Any.pack(Any.pack(content));
+ assertEquals(
+ "{\n"
+ + " \"@type\": \"type.googleapis.com/google.protobuf.Any\",\n"
+ + " \"value\": {\n"
+ + " \"@type\": \"type.googleapis.com/json_test.TestAllTypes\",\n"
+ + " \"optionalInt32\": 1234\n"
+ + " }\n"
+ + "}",
+ printer.print(anyMessage));
+ assertRoundTripEquals(anyMessage, registry);
+
+ // 2. Wrappers in Any.
+ anyMessage = Any.pack(Int32Value.newBuilder().setValue(12345).build());
+ assertEquals(
+ "{\n"
+ + " \"@type\": \"type.googleapis.com/google.protobuf.Int32Value\",\n"
+ + " \"value\": 12345\n"
+ + "}",
+ printer.print(anyMessage));
+ assertRoundTripEquals(anyMessage, registry);
+ anyMessage = Any.pack(UInt32Value.newBuilder().setValue(12345).build());
+ assertEquals(
+ "{\n"
+ + " \"@type\": \"type.googleapis.com/google.protobuf.UInt32Value\",\n"
+ + " \"value\": 12345\n"
+ + "}",
+ printer.print(anyMessage));
+ assertRoundTripEquals(anyMessage, registry);
+ anyMessage = Any.pack(Int64Value.newBuilder().setValue(12345).build());
+ assertEquals(
+ "{\n"
+ + " \"@type\": \"type.googleapis.com/google.protobuf.Int64Value\",\n"
+ + " \"value\": \"12345\"\n"
+ + "}",
+ printer.print(anyMessage));
+ assertRoundTripEquals(anyMessage, registry);
+ anyMessage = Any.pack(UInt64Value.newBuilder().setValue(12345).build());
+ assertEquals(
+ "{\n"
+ + " \"@type\": \"type.googleapis.com/google.protobuf.UInt64Value\",\n"
+ + " \"value\": \"12345\"\n"
+ + "}",
+ printer.print(anyMessage));
+ assertRoundTripEquals(anyMessage, registry);
+ anyMessage = Any.pack(FloatValue.newBuilder().setValue(12345).build());
+ assertEquals(
+ "{\n"
+ + " \"@type\": \"type.googleapis.com/google.protobuf.FloatValue\",\n"
+ + " \"value\": 12345.0\n"
+ + "}",
+ printer.print(anyMessage));
+ assertRoundTripEquals(anyMessage, registry);
+ anyMessage = Any.pack(DoubleValue.newBuilder().setValue(12345).build());
+ assertEquals(
+ "{\n"
+ + " \"@type\": \"type.googleapis.com/google.protobuf.DoubleValue\",\n"
+ + " \"value\": 12345.0\n"
+ + "}",
+ printer.print(anyMessage));
+ assertRoundTripEquals(anyMessage, registry);
+ anyMessage = Any.pack(BoolValue.newBuilder().setValue(true).build());
+ assertEquals(
+ "{\n"
+ + " \"@type\": \"type.googleapis.com/google.protobuf.BoolValue\",\n"
+ + " \"value\": true\n"
+ + "}",
+ printer.print(anyMessage));
+ assertRoundTripEquals(anyMessage, registry);
+ anyMessage = Any.pack(StringValue.newBuilder().setValue("Hello").build());
+ assertEquals(
+ "{\n"
+ + " \"@type\": \"type.googleapis.com/google.protobuf.StringValue\",\n"
+ + " \"value\": \"Hello\"\n"
+ + "}",
+ printer.print(anyMessage));
+ assertRoundTripEquals(anyMessage, registry);
+ anyMessage =
+ Any.pack(BytesValue.newBuilder().setValue(ByteString.copyFrom(new byte[] {1, 2})).build());
+ assertEquals(
+ "{\n"
+ + " \"@type\": \"type.googleapis.com/google.protobuf.BytesValue\",\n"
+ + " \"value\": \"AQI=\"\n"
+ + "}",
+ printer.print(anyMessage));
+ assertRoundTripEquals(anyMessage, registry);
+
+ // 3. Timestamp in Any.
+ anyMessage = Any.pack(Timestamps.parse("1969-12-31T23:59:59Z"));
+ assertEquals(
+ "{\n"
+ + " \"@type\": \"type.googleapis.com/google.protobuf.Timestamp\",\n"
+ + " \"value\": \"1969-12-31T23:59:59Z\"\n"
+ + "}",
+ printer.print(anyMessage));
+ assertRoundTripEquals(anyMessage, registry);
+
+ // 4. Duration in Any
+ anyMessage = Any.pack(Durations.parse("12345.10s"));
+ assertEquals(
+ "{\n"
+ + " \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n"
+ + " \"value\": \"12345.100s\"\n"
+ + "}",
+ printer.print(anyMessage));
+ assertRoundTripEquals(anyMessage, registry);
+
+ // 5. FieldMask in Any
+ anyMessage = Any.pack(FieldMaskUtil.fromString("foo.bar,baz"));
+ assertEquals(
+ "{\n"
+ + " \"@type\": \"type.googleapis.com/google.protobuf.FieldMask\",\n"
+ + " \"value\": \"foo.bar,baz\"\n"
+ + "}",
+ printer.print(anyMessage));
+ assertRoundTripEquals(anyMessage, registry);
+
+ // 6. Struct in Any
+ Struct.Builder structBuilder = Struct.newBuilder();
+ structBuilder.putFields("number", Value.newBuilder().setNumberValue(1.125).build());
+ anyMessage = Any.pack(structBuilder.build());
+ assertEquals(
+ "{\n"
+ + " \"@type\": \"type.googleapis.com/google.protobuf.Struct\",\n"
+ + " \"value\": {\n"
+ + " \"number\": 1.125\n"
+ + " }\n"
+ + "}",
+ 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());
+ assertEquals(
+ "{\n"
+ + " \"@type\": \"type.googleapis.com/google.protobuf.Value\",\n"
+ + " \"value\": 1.0\n"
+ + "}",
+ 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 {
+ try {
+ Any.Builder builder = Any.newBuilder();
+ mergeFromJson("{\n" + " \"optionalInt32\": 1234\n" + "}", builder);
+ fail("Exception is expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void testParserUnexpectedTypeUrl() throws Exception {
+ try {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ mergeFromJson(
+ "{\n"
+ + " \"@type\": \"type.googleapis.com/json_test.TestAllTypes\",\n"
+ + " \"optionalInt32\": 12345\n"
+ + "}",
+ builder);
+ fail("Exception is expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void testParserRejectTrailingComma() throws Exception {
+ try {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ mergeFromJson("{\n" + " \"optionalInt32\": 12345,\n" + "}", builder);
+ fail("Exception is expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ // TODO(xiaofeng): GSON allows trailing comma in arrays even after I set
+ // the JsonReader to non-lenient mode. If we want to enforce strict JSON
+ // compliance, we might want to switch to a different JSON parser or
+ // implement one by ourselves.
+ // try {
+ // TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ // JsonFormat.merge(
+ // "{\n"
+ // + " \"repeatedInt32\": [12345,]\n"
+ // + "}", builder);
+ // fail("Exception is expected.");
+ // } catch (IOException e) {
+ // // Expected.
+ // }
+ }
+
+ public void testParserRejectInvalidBase64() throws Exception {
+ assertRejects("optionalBytes", "!@#$");
+ }
+
+ public void testParserAcceptBase64Variants() throws Exception {
+ assertAccepts("optionalBytes", "AQI");
+ }
+
+ public void testParserRejectInvalidEnumValue() throws Exception {
+ try {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ mergeFromJson("{\n" + " \"optionalNestedEnum\": \"XXX\"\n" + "}", builder);
+ fail("Exception is expected.");
+ } catch (InvalidProtocolBufferException e) {
+ // Expected.
+ }
+ }
+
+ public void testParserUnknownFields() throws Exception {
+ try {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ String json = "{\n" + " \"unknownField\": \"XXX\"\n" + "}";
+ JsonFormat.parser().merge(json, builder);
+ fail("Exception is expected.");
+ } catch (InvalidProtocolBufferException e) {
+ // Expected.
+ }
+ }
+
+ public void testParserIgnoringUnknownFields() throws Exception {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ String json = "{\n" + " \"unknownField\": \"XXX\"\n" + "}";
+ JsonFormat.parser().ignoringUnknownFields().merge(json, builder);
+ }
+
+ public void testCustomJsonName() throws Exception {
+ TestCustomJsonName message = TestCustomJsonName.newBuilder().setValue(12345).build();
+ assertEquals("{\n" + " \"@value\": 12345\n" + "}", JsonFormat.printer().print(message));
+ assertRoundTripEquals(message);
+ }
+
+ public void testDefaultGsonDoesNotHtmlEscape() throws Exception {
+ TestAllTypes message = TestAllTypes.newBuilder().setOptionalString("=").build();
+ assertEquals(
+ "{\n" + " \"optionalString\": \"=\"" + "\n}", JsonFormat.printer().print(message));
+ }
+
+ public void testIncludingDefaultValueFields() throws Exception {
+ TestAllTypes message = TestAllTypes.getDefaultInstance();
+ assertEquals("{\n}", JsonFormat.printer().print(message));
+ assertEquals(
+ "{\n"
+ + " \"optionalInt32\": 0,\n"
+ + " \"optionalInt64\": \"0\",\n"
+ + " \"optionalUint32\": 0,\n"
+ + " \"optionalUint64\": \"0\",\n"
+ + " \"optionalSint32\": 0,\n"
+ + " \"optionalSint64\": \"0\",\n"
+ + " \"optionalFixed32\": 0,\n"
+ + " \"optionalFixed64\": \"0\",\n"
+ + " \"optionalSfixed32\": 0,\n"
+ + " \"optionalSfixed64\": \"0\",\n"
+ + " \"optionalFloat\": 0.0,\n"
+ + " \"optionalDouble\": 0.0,\n"
+ + " \"optionalBool\": false,\n"
+ + " \"optionalString\": \"\",\n"
+ + " \"optionalBytes\": \"\",\n"
+ + " \"optionalNestedEnum\": \"FOO\",\n"
+ + " \"repeatedInt32\": [],\n"
+ + " \"repeatedInt64\": [],\n"
+ + " \"repeatedUint32\": [],\n"
+ + " \"repeatedUint64\": [],\n"
+ + " \"repeatedSint32\": [],\n"
+ + " \"repeatedSint64\": [],\n"
+ + " \"repeatedFixed32\": [],\n"
+ + " \"repeatedFixed64\": [],\n"
+ + " \"repeatedSfixed32\": [],\n"
+ + " \"repeatedSfixed64\": [],\n"
+ + " \"repeatedFloat\": [],\n"
+ + " \"repeatedDouble\": [],\n"
+ + " \"repeatedBool\": [],\n"
+ + " \"repeatedString\": [],\n"
+ + " \"repeatedBytes\": [],\n"
+ + " \"repeatedNestedMessage\": [],\n"
+ + " \"repeatedNestedEnum\": []\n"
+ + "}",
+ JsonFormat.printer().includingDefaultValueFields().print(message));
+
+ TestMap mapMessage = TestMap.getDefaultInstance();
+ assertEquals("{\n}", JsonFormat.printer().print(mapMessage));
+ assertEquals(
+ "{\n"
+ + " \"int32ToInt32Map\": {\n"
+ + " },\n"
+ + " \"int64ToInt32Map\": {\n"
+ + " },\n"
+ + " \"uint32ToInt32Map\": {\n"
+ + " },\n"
+ + " \"uint64ToInt32Map\": {\n"
+ + " },\n"
+ + " \"sint32ToInt32Map\": {\n"
+ + " },\n"
+ + " \"sint64ToInt32Map\": {\n"
+ + " },\n"
+ + " \"fixed32ToInt32Map\": {\n"
+ + " },\n"
+ + " \"fixed64ToInt32Map\": {\n"
+ + " },\n"
+ + " \"sfixed32ToInt32Map\": {\n"
+ + " },\n"
+ + " \"sfixed64ToInt32Map\": {\n"
+ + " },\n"
+ + " \"boolToInt32Map\": {\n"
+ + " },\n"
+ + " \"stringToInt32Map\": {\n"
+ + " },\n"
+ + " \"int32ToInt64Map\": {\n"
+ + " },\n"
+ + " \"int32ToUint32Map\": {\n"
+ + " },\n"
+ + " \"int32ToUint64Map\": {\n"
+ + " },\n"
+ + " \"int32ToSint32Map\": {\n"
+ + " },\n"
+ + " \"int32ToSint64Map\": {\n"
+ + " },\n"
+ + " \"int32ToFixed32Map\": {\n"
+ + " },\n"
+ + " \"int32ToFixed64Map\": {\n"
+ + " },\n"
+ + " \"int32ToSfixed32Map\": {\n"
+ + " },\n"
+ + " \"int32ToSfixed64Map\": {\n"
+ + " },\n"
+ + " \"int32ToFloatMap\": {\n"
+ + " },\n"
+ + " \"int32ToDoubleMap\": {\n"
+ + " },\n"
+ + " \"int32ToBoolMap\": {\n"
+ + " },\n"
+ + " \"int32ToStringMap\": {\n"
+ + " },\n"
+ + " \"int32ToBytesMap\": {\n"
+ + " },\n"
+ + " \"int32ToMessageMap\": {\n"
+ + " },\n"
+ + " \"int32ToEnumMap\": {\n"
+ + " }\n"
+ + "}",
+ JsonFormat.printer().includingDefaultValueFields().print(mapMessage));
+
+ TestOneof oneofMessage = TestOneof.getDefaultInstance();
+ assertEquals("{\n}", JsonFormat.printer().print(oneofMessage));
+ assertEquals("{\n}", JsonFormat.printer().includingDefaultValueFields().print(oneofMessage));
+
+ oneofMessage = TestOneof.newBuilder().setOneofInt32(42).build();
+ assertEquals("{\n \"oneofInt32\": 42\n}",
+ JsonFormat.printer().print(oneofMessage));
+ assertEquals("{\n \"oneofInt32\": 42\n}",
+ JsonFormat.printer().includingDefaultValueFields().print(oneofMessage));
+
+ TestOneof.Builder oneofBuilder = TestOneof.newBuilder();
+ mergeFromJson("{\n" + " \"oneofNullValue\": null \n" + "}", oneofBuilder);
+ oneofMessage = oneofBuilder.build();
+ assertEquals("{\n \"oneofNullValue\": null\n}", JsonFormat.printer().print(oneofMessage));
+ assertEquals("{\n \"oneofNullValue\": null\n}",
+ JsonFormat.printer().includingDefaultValueFields().print(oneofMessage));
+ }
+
+ public void testPreservingProtoFieldNames() throws Exception {
+ TestAllTypes message = TestAllTypes.newBuilder().setOptionalInt32(12345).build();
+ assertEquals("{\n" + " \"optionalInt32\": 12345\n" + "}", JsonFormat.printer().print(message));
+ assertEquals(
+ "{\n" + " \"optional_int32\": 12345\n" + "}",
+ JsonFormat.printer().preservingProtoFieldNames().print(message));
+
+ // The json_name field option is ignored when configured to use original proto field names.
+ TestCustomJsonName messageWithCustomJsonName =
+ TestCustomJsonName.newBuilder().setValue(12345).build();
+ assertEquals(
+ "{\n" + " \"value\": 12345\n" + "}",
+ JsonFormat.printer().preservingProtoFieldNames().print(messageWithCustomJsonName));
+
+ // Parsers accept both original proto field names and lowerCamelCase names.
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ JsonFormat.parser().merge("{\"optionalInt32\": 12345}", builder);
+ assertEquals(12345, builder.getOptionalInt32());
+ builder.clear();
+ JsonFormat.parser().merge("{\"optional_int32\": 54321}", builder);
+ assertEquals(54321, builder.getOptionalInt32());
+ }
+
+ public void testOmittingInsignificantWhiteSpace() throws Exception {
+ TestAllTypes message = TestAllTypes.newBuilder().setOptionalInt32(12345).build();
+ assertEquals(
+ "{" + "\"optionalInt32\":12345" + "}",
+ JsonFormat.printer().omittingInsignificantWhitespace().print(message));
+ TestAllTypes message1 = TestAllTypes.getDefaultInstance();
+ assertEquals("{}", JsonFormat.printer().omittingInsignificantWhitespace().print(message1));
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ setAllFields(builder);
+ TestAllTypes message2 = builder.build();
+ assertEquals(
+ "{"
+ + "\"optionalInt32\":1234,"
+ + "\"optionalInt64\":\"1234567890123456789\","
+ + "\"optionalUint32\":5678,"
+ + "\"optionalUint64\":\"2345678901234567890\","
+ + "\"optionalSint32\":9012,"
+ + "\"optionalSint64\":\"3456789012345678901\","
+ + "\"optionalFixed32\":3456,"
+ + "\"optionalFixed64\":\"4567890123456789012\","
+ + "\"optionalSfixed32\":7890,"
+ + "\"optionalSfixed64\":\"5678901234567890123\","
+ + "\"optionalFloat\":1.5,"
+ + "\"optionalDouble\":1.25,"
+ + "\"optionalBool\":true,"
+ + "\"optionalString\":\"Hello world!\","
+ + "\"optionalBytes\":\"AAEC\","
+ + "\"optionalNestedMessage\":{"
+ + "\"value\":100"
+ + "},"
+ + "\"optionalNestedEnum\":\"BAR\","
+ + "\"repeatedInt32\":[1234,234],"
+ + "\"repeatedInt64\":[\"1234567890123456789\",\"234567890123456789\"],"
+ + "\"repeatedUint32\":[5678,678],"
+ + "\"repeatedUint64\":[\"2345678901234567890\",\"345678901234567890\"],"
+ + "\"repeatedSint32\":[9012,10],"
+ + "\"repeatedSint64\":[\"3456789012345678901\",\"456789012345678901\"],"
+ + "\"repeatedFixed32\":[3456,456],"
+ + "\"repeatedFixed64\":[\"4567890123456789012\",\"567890123456789012\"],"
+ + "\"repeatedSfixed32\":[7890,890],"
+ + "\"repeatedSfixed64\":[\"5678901234567890123\",\"678901234567890123\"],"
+ + "\"repeatedFloat\":[1.5,11.5],"
+ + "\"repeatedDouble\":[1.25,11.25],"
+ + "\"repeatedBool\":[true,true],"
+ + "\"repeatedString\":[\"Hello world!\",\"ello world!\"],"
+ + "\"repeatedBytes\":[\"AAEC\",\"AQI=\"],"
+ + "\"repeatedNestedMessage\":[{"
+ + "\"value\":100"
+ + "},{"
+ + "\"value\":200"
+ + "}],"
+ + "\"repeatedNestedEnum\":[\"BAR\",\"BAZ\"]"
+ + "}",
+ toCompactJsonString(message2));
+ }
+
+ // Regression test for b/29892357
+ public void testEmptyWrapperTypesInAny() throws Exception {
+ JsonFormat.TypeRegistry registry =
+ JsonFormat.TypeRegistry.newBuilder().add(TestAllTypes.getDescriptor()).build();
+ JsonFormat.Parser parser = JsonFormat.parser().usingTypeRegistry(registry);
+
+ Any.Builder builder = Any.newBuilder();
+ parser.merge(
+ "{\n"
+ + " \"@type\": \"type.googleapis.com/google.protobuf.BoolValue\",\n"
+ + " \"value\": false\n"
+ + "}\n",
+ builder);
+ Any any = builder.build();
+ assertEquals(0, any.getValue().size());
+ }
+
+ public void testRecursionLimit() throws Exception {
+ String input =
+ "{\n"
+ + " \"nested\": {\n"
+ + " \"nested\": {\n"
+ + " \"nested\": {\n"
+ + " \"nested\": {\n"
+ + " \"value\": 1234\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + " }\n"
+ + "}\n";
+
+ JsonFormat.Parser parser = JsonFormat.parser();
+ TestRecursive.Builder builder = TestRecursive.newBuilder();
+ parser.merge(input, builder);
+ TestRecursive message = builder.build();
+ assertEquals(1234, message.getNested().getNested().getNested().getNested().getValue());
+
+ parser = JsonFormat.parser().usingRecursionLimit(3);
+ builder = TestRecursive.newBuilder();
+ try {
+ parser.merge(input, builder);
+ fail("Exception is expected.");
+ } catch (InvalidProtocolBufferException e) {
+ // Expected.
+ }
+ }
+
+ // Test that we are not leaking out JSON exceptions.
+ public void testJsonException() throws Exception {
+ InputStream throwingInputStream = new InputStream() {
+ public int read() throws IOException {
+ throw new IOException("12345");
+ }
+ };
+ InputStreamReader throwingReader = new InputStreamReader(throwingInputStream);
+ // When the underlying reader throws IOException, JsonFormat should forward
+ // through this IOException.
+ try {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ JsonFormat.parser().merge(throwingReader, builder);
+ fail("Exception is expected.");
+ } catch (IOException e) {
+ assertEquals("12345", e.getMessage());
+ }
+
+ Reader invalidJsonReader = new StringReader("{ xxx - yyy }");
+ // When the JSON parser throws parser exceptions, JsonFormat should turn
+ // that into InvalidProtocolBufferException.
+ try {
+ TestAllTypes.Builder builder = TestAllTypes.newBuilder();
+ JsonFormat.parser().merge(invalidJsonReader, builder);
+ fail("Exception is expected.");
+ } catch (InvalidProtocolBufferException e) {
+ // Expected.
+ }
+ }
+}
diff --git a/third_party/protobuf/java/util/src/test/java/com/google/protobuf/util/TimeUtilTest.java b/third_party/protobuf/java/util/src/test/java/com/google/protobuf/util/TimeUtilTest.java
new file mode 100644
index 0000000000..5af83d88e6
--- /dev/null
+++ b/third_party/protobuf/java/util/src/test/java/com/google/protobuf/util/TimeUtilTest.java
@@ -0,0 +1,498 @@
+// 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.util;
+
+import com.google.protobuf.Duration;
+import com.google.protobuf.Timestamp;
+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 {
+ public void testTimestampStringFormat() throws Exception {
+ Timestamp start = TimeUtil.parseTimestamp("0001-01-01T00:00:00Z");
+ Timestamp end = TimeUtil.parseTimestamp("9999-12-31T23:59:59.999999999Z");
+ assertEquals(TimeUtil.TIMESTAMP_SECONDS_MIN, start.getSeconds());
+ assertEquals(0, start.getNanos());
+ assertEquals(TimeUtil.TIMESTAMP_SECONDS_MAX, end.getSeconds());
+ assertEquals(999999999, end.getNanos());
+ assertEquals("0001-01-01T00:00:00Z", TimeUtil.toString(start));
+ assertEquals("9999-12-31T23:59:59.999999999Z", TimeUtil.toString(end));
+
+ Timestamp value = TimeUtil.parseTimestamp("1970-01-01T00:00:00Z");
+ assertEquals(0, value.getSeconds());
+ assertEquals(0, value.getNanos());
+
+ // Test negative timestamps.
+ value = TimeUtil.parseTimestamp("1969-12-31T23:59:59.999Z");
+ assertEquals(-1, value.getSeconds());
+ // Nano part is in the range of [0, 999999999] for Timestamp.
+ assertEquals(999000000, value.getNanos());
+
+ // Test that 3, 6, or 9 digits are used for the fractional part.
+ value = Timestamp.newBuilder().setNanos(10).build();
+ assertEquals("1970-01-01T00:00:00.000000010Z", TimeUtil.toString(value));
+ value = Timestamp.newBuilder().setNanos(10000).build();
+ assertEquals("1970-01-01T00:00:00.000010Z", TimeUtil.toString(value));
+ value = Timestamp.newBuilder().setNanos(10000000).build();
+ assertEquals("1970-01-01T00:00:00.010Z", TimeUtil.toString(value));
+
+ // Test that parsing accepts timezone offsets.
+ value = TimeUtil.parseTimestamp("1970-01-01T00:00:00.010+08:00");
+ assertEquals("1969-12-31T16:00:00.010Z", TimeUtil.toString(value));
+ value = TimeUtil.parseTimestamp("1970-01-01T00:00:00.010-08:00");
+ assertEquals("1970-01-01T08:00:00.010Z", TimeUtil.toString(value));
+ }
+
+ private volatile boolean stopParsingThreads = false;
+ private volatile String errorMessage = "";
+
+ private class ParseTimestampThread extends Thread {
+ private final String[] strings;
+ private final Timestamp[] values;
+
+ public ParseTimestampThread(String[] strings, Timestamp[] values) {
+ this.strings = strings;
+ this.values = values;
+ }
+
+ @Override
+ public void run() {
+ int index = 0;
+ while (!stopParsingThreads) {
+ Timestamp result;
+ try {
+ result = TimeUtil.parseTimestamp(strings[index]);
+ } catch (ParseException e) {
+ errorMessage = "Failed to parse timestamp: " + strings[index];
+ break;
+ }
+ if (result.getSeconds() != values[index].getSeconds()
+ || result.getNanos() != values[index].getNanos()) {
+ errorMessage =
+ "Actual result: " + result.toString() + ", expected: " + values[index].toString();
+ break;
+ }
+ index = (index + 1) % strings.length;
+ }
+ }
+ }
+
+ public void testTimestampConcurrentParsing() throws Exception {
+ String[] timestampStrings =
+ new String[] {
+ "0001-01-01T00:00:00Z",
+ "9999-12-31T23:59:59.999999999Z",
+ "1970-01-01T00:00:00Z",
+ "1969-12-31T23:59:59.999Z",
+ };
+ Timestamp[] timestampValues = new Timestamp[timestampStrings.length];
+ for (int i = 0; i < timestampStrings.length; i++) {
+ timestampValues[i] = TimeUtil.parseTimestamp(timestampStrings[i]);
+ }
+
+ final int THREAD_COUNT = 16;
+ final int RUNNING_TIME = 5000; // in milliseconds.
+ final List<Thread> threads = new ArrayList<Thread>();
+
+ stopParsingThreads = false;
+ errorMessage = "";
+ for (int i = 0; i < THREAD_COUNT; i++) {
+ Thread thread = new ParseTimestampThread(timestampStrings, timestampValues);
+ thread.start();
+ threads.add(thread);
+ }
+ Thread.sleep(RUNNING_TIME);
+ stopParsingThreads = true;
+ for (Thread thread : threads) {
+ thread.join();
+ }
+ Assert.assertEquals("", errorMessage);
+ }
+
+ public void testTimetampInvalidFormat() throws Exception {
+ try {
+ // Value too small.
+ Timestamp value =
+ Timestamp.newBuilder().setSeconds(TimeUtil.TIMESTAMP_SECONDS_MIN - 1).build();
+ TimeUtil.toString(value);
+ Assert.fail("Exception is expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+
+ try {
+ // Value too large.
+ Timestamp value =
+ Timestamp.newBuilder().setSeconds(TimeUtil.TIMESTAMP_SECONDS_MAX + 1).build();
+ TimeUtil.toString(value);
+ Assert.fail("Exception is expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+
+ try {
+ // Invalid nanos value.
+ Timestamp value = Timestamp.newBuilder().setNanos(-1).build();
+ TimeUtil.toString(value);
+ Assert.fail("Exception is expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+
+ try {
+ // Invalid nanos value.
+ Timestamp value = Timestamp.newBuilder().setNanos(1000000000).build();
+ TimeUtil.toString(value);
+ Assert.fail("Exception is expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+
+ try {
+ // Value to small.
+ TimeUtil.parseTimestamp("0000-01-01T00:00:00Z");
+ Assert.fail("Exception is expected.");
+ } catch (ParseException e) {
+ // Expected.
+ }
+
+ try {
+ // Value to large.
+ TimeUtil.parseTimestamp("10000-01-01T00:00:00Z");
+ Assert.fail("Exception is expected.");
+ } catch (ParseException e) {
+ // Expected.
+ }
+
+ try {
+ // Missing 'T'.
+ TimeUtil.parseTimestamp("1970-01-01 00:00:00Z");
+ Assert.fail("Exception is expected.");
+ } catch (ParseException e) {
+ // Expected.
+ }
+
+ try {
+ // Missing 'Z'.
+ TimeUtil.parseTimestamp("1970-01-01T00:00:00");
+ Assert.fail("Exception is expected.");
+ } catch (ParseException e) {
+ // Expected.
+ }
+
+ try {
+ // Invalid offset.
+ TimeUtil.parseTimestamp("1970-01-01T00:00:00+0000");
+ Assert.fail("Exception is expected.");
+ } catch (ParseException e) {
+ // Expected.
+ }
+
+ try {
+ // Trailing text.
+ TimeUtil.parseTimestamp("1970-01-01T00:00:00Z0");
+ Assert.fail("Exception is expected.");
+ } catch (ParseException e) {
+ // Expected.
+ }
+
+ try {
+ // Invalid nanosecond value.
+ TimeUtil.parseTimestamp("1970-01-01T00:00:00.ABCZ");
+ Assert.fail("Exception is expected.");
+ } catch (ParseException e) {
+ // Expected.
+ }
+ }
+
+ public void testDurationStringFormat() throws Exception {
+ Timestamp start = TimeUtil.parseTimestamp("0001-01-01T00:00:00Z");
+ Timestamp end = TimeUtil.parseTimestamp("9999-12-31T23:59:59.999999999Z");
+ Duration duration = TimeUtil.distance(start, end);
+ assertEquals("315537897599.999999999s", TimeUtil.toString(duration));
+ duration = TimeUtil.distance(end, start);
+ assertEquals("-315537897599.999999999s", TimeUtil.toString(duration));
+
+ // Generated output should contain 3, 6, or 9 fractional digits.
+ duration = Duration.newBuilder().setSeconds(1).build();
+ assertEquals("1s", TimeUtil.toString(duration));
+ duration = Duration.newBuilder().setNanos(10000000).build();
+ assertEquals("0.010s", TimeUtil.toString(duration));
+ duration = Duration.newBuilder().setNanos(10000).build();
+ assertEquals("0.000010s", TimeUtil.toString(duration));
+ duration = Duration.newBuilder().setNanos(10).build();
+ assertEquals("0.000000010s", TimeUtil.toString(duration));
+
+ // Parsing accepts an fractional digits as long as they fit into nano
+ // precision.
+ duration = TimeUtil.parseDuration("0.1s");
+ assertEquals(100000000, duration.getNanos());
+ duration = TimeUtil.parseDuration("0.0001s");
+ assertEquals(100000, duration.getNanos());
+ duration = TimeUtil.parseDuration("0.0000001s");
+ assertEquals(100, duration.getNanos());
+
+ // Duration must support range from -315,576,000,000s to +315576000000s
+ // which includes negative values.
+ duration = TimeUtil.parseDuration("315576000000.999999999s");
+ assertEquals(315576000000L, duration.getSeconds());
+ assertEquals(999999999, duration.getNanos());
+ duration = TimeUtil.parseDuration("-315576000000.999999999s");
+ assertEquals(-315576000000L, duration.getSeconds());
+ assertEquals(-999999999, duration.getNanos());
+ }
+
+ public void testDurationInvalidFormat() throws Exception {
+ try {
+ // Value too small.
+ Duration value = Duration.newBuilder().setSeconds(TimeUtil.DURATION_SECONDS_MIN - 1).build();
+ TimeUtil.toString(value);
+ Assert.fail("Exception is expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+
+ try {
+ // Value too large.
+ Duration value = Duration.newBuilder().setSeconds(TimeUtil.DURATION_SECONDS_MAX + 1).build();
+ TimeUtil.toString(value);
+ Assert.fail("Exception is expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+
+ try {
+ // Invalid nanos value.
+ Duration value = Duration.newBuilder().setSeconds(1).setNanos(-1).build();
+ TimeUtil.toString(value);
+ Assert.fail("Exception is expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+
+ try {
+ // Invalid nanos value.
+ Duration value = Duration.newBuilder().setSeconds(-1).setNanos(1).build();
+ TimeUtil.toString(value);
+ Assert.fail("Exception is expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+
+ try {
+ // Value too small.
+ TimeUtil.parseDuration("-315576000001s");
+ Assert.fail("Exception is expected.");
+ } catch (ParseException e) {
+ // Expected.
+ }
+
+ try {
+ // Value too large.
+ TimeUtil.parseDuration("315576000001s");
+ Assert.fail("Exception is expected.");
+ } catch (ParseException e) {
+ // Expected.
+ }
+
+ try {
+ // Empty.
+ TimeUtil.parseDuration("");
+ Assert.fail("Exception is expected.");
+ } catch (ParseException e) {
+ // Expected.
+ }
+
+ try {
+ // Missing "s".
+ TimeUtil.parseDuration("0");
+ Assert.fail("Exception is expected.");
+ } catch (ParseException e) {
+ // Expected.
+ }
+
+ try {
+ // Invalid trailing data.
+ TimeUtil.parseDuration("0s0");
+ Assert.fail("Exception is expected.");
+ } catch (ParseException e) {
+ // Expected.
+ }
+
+ try {
+ // Invalid prefix.
+ TimeUtil.parseDuration("--1s");
+ Assert.fail("Exception is expected.");
+ } catch (ParseException e) {
+ // Expected.
+ }
+ }
+
+ public void testTimestampConversion() throws Exception {
+ Timestamp timestamp = TimeUtil.parseTimestamp("1970-01-01T00:00:01.111111111Z");
+ assertEquals(1111111111, TimeUtil.toNanos(timestamp));
+ assertEquals(1111111, TimeUtil.toMicros(timestamp));
+ assertEquals(1111, TimeUtil.toMillis(timestamp));
+ timestamp = TimeUtil.createTimestampFromNanos(1111111111);
+ assertEquals("1970-01-01T00:00:01.111111111Z", TimeUtil.toString(timestamp));
+ timestamp = TimeUtil.createTimestampFromMicros(1111111);
+ assertEquals("1970-01-01T00:00:01.111111Z", TimeUtil.toString(timestamp));
+ timestamp = TimeUtil.createTimestampFromMillis(1111);
+ assertEquals("1970-01-01T00:00:01.111Z", TimeUtil.toString(timestamp));
+
+ timestamp = TimeUtil.parseTimestamp("1969-12-31T23:59:59.111111111Z");
+ assertEquals(-888888889, TimeUtil.toNanos(timestamp));
+ assertEquals(-888889, TimeUtil.toMicros(timestamp));
+ assertEquals(-889, TimeUtil.toMillis(timestamp));
+ timestamp = TimeUtil.createTimestampFromNanos(-888888889);
+ assertEquals("1969-12-31T23:59:59.111111111Z", TimeUtil.toString(timestamp));
+ timestamp = TimeUtil.createTimestampFromMicros(-888889);
+ assertEquals("1969-12-31T23:59:59.111111Z", TimeUtil.toString(timestamp));
+ timestamp = TimeUtil.createTimestampFromMillis(-889);
+ assertEquals("1969-12-31T23:59:59.111Z", TimeUtil.toString(timestamp));
+ }
+
+ public void testDurationConversion() throws Exception {
+ Duration duration = TimeUtil.parseDuration("1.111111111s");
+ assertEquals(1111111111, TimeUtil.toNanos(duration));
+ assertEquals(1111111, TimeUtil.toMicros(duration));
+ assertEquals(1111, TimeUtil.toMillis(duration));
+ duration = TimeUtil.createDurationFromNanos(1111111111);
+ assertEquals("1.111111111s", TimeUtil.toString(duration));
+ duration = TimeUtil.createDurationFromMicros(1111111);
+ assertEquals("1.111111s", TimeUtil.toString(duration));
+ duration = TimeUtil.createDurationFromMillis(1111);
+ assertEquals("1.111s", TimeUtil.toString(duration));
+
+ duration = TimeUtil.parseDuration("-1.111111111s");
+ assertEquals(-1111111111, TimeUtil.toNanos(duration));
+ assertEquals(-1111111, TimeUtil.toMicros(duration));
+ assertEquals(-1111, TimeUtil.toMillis(duration));
+ duration = TimeUtil.createDurationFromNanos(-1111111111);
+ assertEquals("-1.111111111s", TimeUtil.toString(duration));
+ duration = TimeUtil.createDurationFromMicros(-1111111);
+ assertEquals("-1.111111s", TimeUtil.toString(duration));
+ duration = TimeUtil.createDurationFromMillis(-1111);
+ assertEquals("-1.111s", TimeUtil.toString(duration));
+ }
+
+ public void testTimeOperations() throws Exception {
+ Timestamp start = TimeUtil.parseTimestamp("0001-01-01T00:00:00Z");
+ Timestamp end = TimeUtil.parseTimestamp("9999-12-31T23:59:59.999999999Z");
+
+ Duration duration = TimeUtil.distance(start, end);
+ assertEquals("315537897599.999999999s", TimeUtil.toString(duration));
+ Timestamp value = TimeUtil.add(start, duration);
+ assertEquals(end, value);
+ value = TimeUtil.subtract(end, duration);
+ assertEquals(start, value);
+
+ duration = TimeUtil.distance(end, start);
+ assertEquals("-315537897599.999999999s", TimeUtil.toString(duration));
+ value = TimeUtil.add(end, duration);
+ assertEquals(start, value);
+ value = TimeUtil.subtract(start, duration);
+ assertEquals(end, value);
+
+ // Result is larger than Long.MAX_VALUE.
+ try {
+ duration = TimeUtil.parseDuration("315537897599.999999999s");
+ duration = TimeUtil.multiply(duration, 315537897599.999999999);
+ Assert.fail("Exception is expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+
+ // Result is lesser than Long.MIN_VALUE.
+ try {
+ duration = TimeUtil.parseDuration("315537897599.999999999s");
+ duration = TimeUtil.multiply(duration, -315537897599.999999999);
+ Assert.fail("Exception is expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+
+ duration = TimeUtil.parseDuration("-1.125s");
+ duration = TimeUtil.divide(duration, 2.0);
+ assertEquals("-0.562500s", TimeUtil.toString(duration));
+ duration = TimeUtil.multiply(duration, 2.0);
+ assertEquals("-1.125s", TimeUtil.toString(duration));
+
+ duration = TimeUtil.add(duration, duration);
+ assertEquals("-2.250s", TimeUtil.toString(duration));
+
+ duration = TimeUtil.subtract(duration, TimeUtil.parseDuration("-1s"));
+ assertEquals("-1.250s", TimeUtil.toString(duration));
+
+ // Multiplications (with results larger than Long.MAX_VALUE in nanoseconds).
+ duration = TimeUtil.parseDuration("0.999999999s");
+ assertEquals(
+ "315575999684.424s", TimeUtil.toString(TimeUtil.multiply(duration, 315576000000L)));
+ duration = TimeUtil.parseDuration("-0.999999999s");
+ assertEquals(
+ "-315575999684.424s", TimeUtil.toString(TimeUtil.multiply(duration, 315576000000L)));
+ assertEquals(
+ "315575999684.424s", TimeUtil.toString(TimeUtil.multiply(duration, -315576000000L)));
+
+ // Divisions (with values larger than Long.MAX_VALUE in nanoseconds).
+ Duration d1 = TimeUtil.parseDuration("315576000000s");
+ Duration d2 = TimeUtil.subtract(d1, TimeUtil.createDurationFromNanos(1));
+ assertEquals(1, TimeUtil.divide(d1, d2));
+ assertEquals(0, TimeUtil.divide(d2, d1));
+ assertEquals("0.000000001s", TimeUtil.toString(TimeUtil.remainder(d1, d2)));
+ assertEquals("315575999999.999999999s", TimeUtil.toString(TimeUtil.remainder(d2, d1)));
+
+ // Divisions involving negative values.
+ //
+ // (-5) / 2 = -2, remainder = -1
+ d1 = TimeUtil.parseDuration("-5s");
+ d2 = TimeUtil.parseDuration("2s");
+ assertEquals(-2, TimeUtil.divide(d1, d2));
+ assertEquals(-2, TimeUtil.divide(d1, 2).getSeconds());
+ assertEquals(-1, TimeUtil.remainder(d1, d2).getSeconds());
+ // (-5) / (-2) = 2, remainder = -1
+ d1 = TimeUtil.parseDuration("-5s");
+ d2 = TimeUtil.parseDuration("-2s");
+ assertEquals(2, TimeUtil.divide(d1, d2));
+ assertEquals(2, TimeUtil.divide(d1, -2).getSeconds());
+ assertEquals(-1, TimeUtil.remainder(d1, d2).getSeconds());
+ // 5 / (-2) = -2, remainder = 1
+ d1 = TimeUtil.parseDuration("5s");
+ d2 = TimeUtil.parseDuration("-2s");
+ assertEquals(-2, TimeUtil.divide(d1, d2));
+ assertEquals(-2, TimeUtil.divide(d1, -2).getSeconds());
+ assertEquals(1, TimeUtil.remainder(d1, d2).getSeconds());
+ }
+}
diff --git a/third_party/protobuf/java/util/src/test/proto/com/google/protobuf/util/json_test.proto b/third_party/protobuf/java/util/src/test/proto/com/google/protobuf/util/json_test.proto
new file mode 100644
index 0000000000..d1248cfb71
--- /dev/null
+++ b/third_party/protobuf/java/util/src/test/proto/com/google/protobuf/util/json_test.proto
@@ -0,0 +1,178 @@
+// 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.
+
+syntax = "proto3";
+
+package json_test;
+
+option java_package = "com.google.protobuf.util";
+option java_outer_classname = "JsonTestProto";
+
+import "google/protobuf/any.proto";
+import "google/protobuf/wrappers.proto";
+import "google/protobuf/timestamp.proto";
+import "google/protobuf/duration.proto";
+import "google/protobuf/field_mask.proto";
+import "google/protobuf/struct.proto";
+
+message TestAllTypes {
+ enum NestedEnum {
+ FOO = 0;
+ BAR = 1;
+ BAZ = 2;
+ }
+ message NestedMessage {
+ int32 value = 1;
+ }
+
+ int32 optional_int32 = 1;
+ int64 optional_int64 = 2;
+ uint32 optional_uint32 = 3;
+ uint64 optional_uint64 = 4;
+ sint32 optional_sint32 = 5;
+ sint64 optional_sint64 = 6;
+ fixed32 optional_fixed32 = 7;
+ fixed64 optional_fixed64 = 8;
+ sfixed32 optional_sfixed32 = 9;
+ sfixed64 optional_sfixed64 = 10;
+ float optional_float = 11;
+ double optional_double = 12;
+ bool optional_bool = 13;
+ string optional_string = 14;
+ bytes optional_bytes = 15;
+ NestedMessage optional_nested_message = 18;
+ NestedEnum optional_nested_enum = 21;
+
+ // Repeated
+ repeated int32 repeated_int32 = 31;
+ repeated int64 repeated_int64 = 32;
+ repeated uint32 repeated_uint32 = 33;
+ repeated uint64 repeated_uint64 = 34;
+ repeated sint32 repeated_sint32 = 35;
+ repeated sint64 repeated_sint64 = 36;
+ repeated fixed32 repeated_fixed32 = 37;
+ repeated fixed64 repeated_fixed64 = 38;
+ repeated sfixed32 repeated_sfixed32 = 39;
+ repeated sfixed64 repeated_sfixed64 = 40;
+ repeated float repeated_float = 41;
+ repeated double repeated_double = 42;
+ repeated bool repeated_bool = 43;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+ repeated NestedMessage repeated_nested_message = 48;
+ repeated NestedEnum repeated_nested_enum = 51;
+}
+
+message TestOneof {
+ oneof oneof_field {
+ int32 oneof_int32 = 1;
+ TestAllTypes.NestedMessage oneof_nested_message = 2;
+ google.protobuf.NullValue oneof_null_value = 3;
+ }
+}
+
+message TestMap {
+ // Instead of testing all combinations (too many), we only make sure all
+ // valid types have been used at least in one field as key and in one
+ // field as value.
+ map<int32, int32> int32_to_int32_map = 1;
+ map<int64, int32> int64_to_int32_map = 2;
+ map<uint32, int32> uint32_to_int32_map = 3;
+ map<uint64, int32> uint64_to_int32_map = 4;
+ map<sint32, int32> sint32_to_int32_map = 5;
+ map<sint64, int32> sint64_to_int32_map = 6;
+ map<fixed32, int32> fixed32_to_int32_map = 7;
+ map<fixed64, int32> fixed64_to_int32_map = 8;
+ map<sfixed32, int32> sfixed32_to_int32_map = 9;
+ map<sfixed64, int32> sfixed64_to_int32_map = 10;
+ map<bool, int32> bool_to_int32_map = 11;
+ map<string, int32> string_to_int32_map = 12;
+
+ map<int32, int64> int32_to_int64_map = 101;
+ map<int32, uint32> int32_to_uint32_map = 102;
+ map<int32, uint64> int32_to_uint64_map = 103;
+ map<int32, sint32> int32_to_sint32_map = 104;
+ map<int32, sint64> int32_to_sint64_map = 105;
+ map<int32, fixed32> int32_to_fixed32_map = 106;
+ map<int32, fixed64> int32_to_fixed64_map = 107;
+ map<int32, sfixed32> int32_to_sfixed32_map = 108;
+ map<int32, sfixed64> int32_to_sfixed64_map = 109;
+ map<int32, float> int32_to_float_map = 110;
+ map<int32, double> int32_to_double_map = 111;
+ map<int32, bool> int32_to_bool_map = 112;
+ map<int32, string> int32_to_string_map = 113;
+ map<int32, bytes> int32_to_bytes_map = 114;
+ map<int32, TestAllTypes.NestedMessage> int32_to_message_map = 115;
+ map<int32, TestAllTypes.NestedEnum> int32_to_enum_map = 116;
+}
+
+message TestWrappers {
+ google.protobuf.Int32Value int32_value = 1;
+ google.protobuf.UInt32Value uint32_value = 2;
+ google.protobuf.Int64Value int64_value = 3;
+ google.protobuf.UInt64Value uint64_value = 4;
+ google.protobuf.FloatValue float_value = 5;
+ google.protobuf.DoubleValue double_value = 6;
+ google.protobuf.BoolValue bool_value = 7;
+ google.protobuf.StringValue string_value = 8;
+ google.protobuf.BytesValue bytes_value = 9;
+}
+
+message TestTimestamp {
+ google.protobuf.Timestamp timestamp_value = 1;
+}
+
+message TestDuration {
+ google.protobuf.Duration duration_value = 1;
+}
+
+message TestFieldMask {
+ google.protobuf.FieldMask field_mask_value = 1;
+}
+
+message TestStruct {
+ google.protobuf.Struct struct_value = 1;
+ google.protobuf.Value value = 2;
+ google.protobuf.ListValue list_value = 3;
+}
+
+message TestAny {
+ google.protobuf.Any any_value = 1;
+ map<string, google.protobuf.Any> any_map = 2;
+}
+
+message TestCustomJsonName {
+ int32 value = 1 [json_name = "@value"];
+}
+
+message TestRecursive {
+ int32 value = 1;
+ TestRecursive nested = 2;
+}
diff --git a/third_party/protobuf/javanano/README.md b/third_party/protobuf/javanano/README.md
new file mode 100644
index 0000000000..6b13ecea7c
--- /dev/null
+++ b/third_party/protobuf/javanano/README.md
@@ -0,0 +1,401 @@
+Protocol Buffers - Google's data interchange format
+===================================================
+
+[![Build Status](https://travis-ci.org/google/protobuf.svg?branch=master)](https://travis-ci.org/google/protobuf)
+
+Copyright 2008 Google Inc.
+
+This directory contains the Java Protocol Buffers Nano runtime library.
+
+**Nano is no longer supported by protobuf team. We recommend Android users to
+use protobuf lite runtime instead.**
+
+Installation - With Maven
+-------------------------
+
+The Protocol Buffers build is managed using Maven. If you would
+rather build without Maven, see below.
+
+1) Install Apache Maven if you don't have it:
+
+ http://maven.apache.org/
+
+2) Build the C++ code, or obtain a binary distribution of protoc. If
+ you install a binary distribution, make sure that it is the same
+ version as this package. If in doubt, run:
+
+ $ protoc --version
+
+ You will need to place the protoc executable in ../src. (If you
+ built it yourself, it should already be there.)
+
+3) Run the tests:
+
+ $ mvn test
+
+ If some tests fail, this library may not work correctly on your
+ system. Continue at your own risk.
+
+4) Install the library into your Maven repository:
+
+ $ mvn install
+
+5) If you do not use Maven to manage your own build, you can build a
+ .jar file to use:
+
+ $ mvn package
+
+ The .jar will be placed in the "target" directory.
+
+Installation - Without Maven
+----------------------------
+
+If you would rather not install Maven to build the library, you may
+follow these instructions instead. Note that these instructions skip
+running unit tests.
+
+1) Build the C++ code, or obtain a binary distribution of protoc. If
+ you install a binary distribution, make sure that it is the same
+ version as this package. If in doubt, run:
+
+ $ protoc --version
+
+ If you built the C++ code without installing, the compiler binary
+ should be located in ../src.
+
+2) Invoke protoc to build DescriptorProtos.java:
+
+ $ protoc --java_out=src/main/java -I../src \
+ ../src/google/protobuf/descriptor.proto
+
+3) Compile the code in src/main/java using whatever means you prefer.
+
+4) Install the classes wherever you prefer.
+
+Nano version
+------------
+
+JavaNano is a special code generator and runtime library designed specially for
+resource-restricted systems, like Android. It is very resource-friendly in both
+the amount of code and the runtime overhead. Here is an overview of JavaNano
+features compared with the official Java protobuf:
+
+- No descriptors or message builders.
+- All messages are mutable; fields are public Java fields.
+- For optional fields only, encapsulation behind setter/getter/hazzer/
+ clearer functions is opt-in, which provide proper 'has' state support.
+- For proto2, if not opted in, has state (field presence) is not available.
+ Serialization outputs all fields not equal to their defaults
+ (see important implications below).
+ The behavior is consistent with proto3 semantics.
+- Required fields (proto2 only) are always serialized.
+- Enum constants are integers; protection against invalid values only
+ when parsing from the wire.
+- Enum constants can be generated into container interfaces bearing
+ the enum's name (so the referencing code is in Java style).
+- CodedInputByteBufferNano can only take byte[] (not InputStream).
+- Similarly CodedOutputByteBufferNano can only write to byte[].
+- Repeated fields are in arrays, not ArrayList or Vector. Null array
+ elements are allowed and silently ignored.
+- Full support for serializing/deserializing repeated packed fields.
+- Support extensions (in proto2).
+- Unset messages/groups are null, not an immutable empty default
+ instance.
+- toByteArray(...) and mergeFrom(...) are now static functions of
+ MessageNano.
+- The 'bytes' type translates to the Java type byte[].
+
+The generated messages are not thread-safe for writes, but may be
+used simultaneously from multiple threads in a read-only manner.
+In other words, an appropriate synchronization mechanism (such as
+a ReadWriteLock) must be used to ensure that a message, its
+ancestors, and descendants are not accessed by any other threads
+while the message is being modified. Field reads, getter methods
+(but not getExtension(...)), toByteArray(...), writeTo(...),
+getCachedSize(), and getSerializedSize() are all considered read-only
+operations.
+
+IMPORTANT: If you have fields with defaults and opt out of accessors
+
+How fields with defaults are serialized has changed. Because we don't
+keep "has" state, any field equal to its default is assumed to be not
+set and therefore is not serialized. Consider the situation where we
+change the default value of a field. Senders compiled against an older
+version of the proto continue to match against the old default, and
+don't send values to the receiver even though the receiver assumes the
+new default value. Therefore, think carefully about the implications
+of changing the default value. Alternatively, turn on accessors and
+enjoy the benefit of the explicit has() checks.
+
+IMPORTANT: If you have "bytes" fields with non-empty defaults
+
+Because the byte buffer is now of mutable type byte[], the default
+static final cannot be exposed through a public field. Each time a
+message's constructor or clear() function is called, the default value
+(kept in a private byte[]) is cloned. This causes a small memory
+penalty. This is not a problem if the field has no default or is an
+empty default.
+
+Nano Generator options
+----------------------
+
+```
+java_package -> <file-name>|<package-name>
+java_outer_classname -> <file-name>|<package-name>
+java_multiple_files -> true or false
+java_nano_generate_has -> true or false [DEPRECATED]
+optional_field_style -> default or accessors
+enum_style -> c or java
+ignore_services -> true or false
+parcelable_messages -> true or false
+generate_intdefs -> true or false
+```
+
+**java_package=\<file-name\>|\<package-name\>** (no default)
+
+ This allows overriding the 'java_package' option value
+ for the given file from the command line. Use multiple
+ java_package options to override the option for multiple
+ files. The final Java package for each file is the value
+ of this command line option if present, or the value of
+ the same option defined in the file if present, or the
+ proto package if present, or the default Java package.
+
+**java_outer_classname=\<file-name\>|\<outer-classname\>** (no default)
+
+ This allows overriding the 'java_outer_classname' option
+ for the given file from the command line. Use multiple
+ java_outer_classname options to override the option for
+ multiple files. The final Java outer class name for each
+ file is the value of this command line option if present,
+ or the value of the same option defined in the file if
+ present, or the file name converted to CamelCase. This
+ outer class will nest all classes and integer constants
+ generated from file-scope messages and enums.
+
+**java_multiple_files={true,false}** (no default)
+
+ This allows overriding the 'java_multiple_files' option
+ in all source files and their imported files from the
+ command line. The final value of this option for each
+ file is the value defined in this command line option, or
+ the value of the same option defined in the file if
+ present, or false. This specifies whether to generate
+ package-level classes for the file-scope messages in the
+ same Java package as the outer class (instead of nested
+ classes in the outer class). File-scope enum constants
+ are still generated as integer constants in the outer
+ class. This affects the fully qualified references in the
+ Java code. NOTE: because the command line option
+ overrides the value for all files and their imported
+ files, using this option inconsistently may result in
+ incorrect references to the imported messages and enum
+ constants.
+
+**java_nano_generate_has={true,false}** (default: false)
+
+ DEPRECATED. Use optional_field_style=accessors.
+
+ If true, generates a public boolean variable has\<fieldname\>
+ accompanying each optional or required field (not present for
+ repeated fields, groups or messages). It is set to false initially
+ and upon clear(). If parseFrom(...) reads the field from the wire,
+ it is set to true. This is a way for clients to inspect the "has"
+ value upon parse. If it is set to true, writeTo(...) will ALWAYS
+ output that field (even if field value is equal to its
+ default).
+
+ IMPORTANT: This option costs an extra 4 bytes per primitive field in
+ the message. Think carefully about whether you really need this. In
+ many cases reading the default works and determining whether the
+ field was received over the wire is irrelevant.
+
+**optional_field_style={default,accessors,reftypes}** (default: default)
+
+ Defines the style of the generated code for fields.
+
+ * default
+
+ In the default style, optional fields translate into public mutable
+ Java fields, and the serialization process is as discussed in the
+ "IMPORTANT" section above.
+
+ * accessors
+
+ When set to 'accessors', each optional field is encapsulated behind
+ 4 accessors, namely get\<fieldname\>(), set\<fieldname\>(), has\<fieldname\>()
+ and clear\<fieldname\>() methods, with the standard semantics. The hazzer's
+ return value determines whether a field is serialized, so this style is
+ useful when you need to serialize a field with the default value, or check
+ if a field has been explicitly set to its default value from the wire.
+
+ In the 'accessors' style, required and nested message fields are still
+ translated to one public mutable Java field each, repeated fields are still
+ translated to arrays. No accessors are generated for them.
+
+ IMPORTANT: When using the 'accessors' style, ProGuard should always
+ be enabled with optimization (don't use -dontoptimize) and allowing
+ access modification (use -allowaccessmodification). This removes the
+ unused accessors and maybe inline the rest at the call sites,
+ reducing the final code size.
+ TODO(maxtroy): find ProGuard config that would work the best.
+
+ * reftypes
+
+ When set to 'reftypes', each proto field is generated as a public Java
+ field. For primitive types, these fields use the Java reference types
+ such as java.lang.Integer instead of primitive types such as int.
+
+ In the 'reftypes' style, fields are initialized to null (or empty
+ arrays for repeated fields), and their default values are not available.
+ They are serialized over the wire based on equality to null.
+
+ The 'reftypes' mode has some additional cost due to autoboxing and usage
+ of reference types. In practice, many boxed types are cached, and so don't
+ result in object creation. However, references do take slightly more memory
+ than primitives.
+
+ The 'reftypes' mode is useful when you want to be able to serialize fields
+ with default values, or check if a field has been explicitly set to the
+ default over the wire without paying the extra method cost of the
+ 'accessors' mode.
+
+ Note that if you attempt to write null to a required field in the reftypes
+ mode, serialization of the proto will cause a NullPointerException. This is
+ an intentional indicator that you must set required fields.
+
+ NOTE
+ optional_field_style=accessors or reftypes cannot be used together with
+ java_nano_generate_has=true. If you need the 'has' flag for any
+ required field (you have no reason to), you can only use
+ java_nano_generate_has=true.
+
+**enum_style={c,java}** (default: c)
+
+ Defines where to put the int constants generated from enum members.
+
+ * c
+
+ Use C-style, so the enum constants are available at the scope where
+ the enum is defined. A file-scope enum's members are referenced like
+ 'FileOuterClass.ENUM_VALUE'; a message-scope enum's members are
+ referenced as 'Message.ENUM_VALUE'. The enum name is unavailable.
+ This complies with the Micro code generator's behavior.
+
+ * java
+
+ Use Java-style, so the enum constants are available under the enum
+ name and referenced like 'EnumName.ENUM_VALUE' (they are still int
+ constants). The enum name becomes the name of a public interface, at
+ the scope where the enum is defined. If the enum is file-scope and
+ the java_multiple_files option is on, the interface will be defined
+ in its own file. To reduce code size, this interface should not be
+ implemented and ProGuard shrinking should be used, so after the Java
+ compiler inlines all referenced enum constants into the call sites,
+ the interface remains unused and can be removed by ProGuard.
+
+**ignore_services={true,false}** (default: false)
+
+ Skips services definitions.
+
+ Nano doesn't support services. By default, if a service is defined
+ it will generate a compilation error. If this flag is set to true,
+ services will be silently ignored, instead.
+
+**parcelable_messages={true,false}** (default: false)
+
+ Android-specific option to generate Parcelable messages.
+
+**generate_intdefs={true,false}** (default: false)
+ Android-specific option to generate @IntDef annotations for enums.
+
+ If turned on, an '@IntDef' annotation (a public @interface) will be
+ generated for each enum, and every integer parameter and return
+ value in the generated code meant for this enum will be annotated
+ with it. This interface is generated with the same name and at the
+ same place as the enum members' container interfaces described
+ above under 'enum_style=java', regardless of the enum_style option
+ used. When this is combined with enum_style=java, the interface
+ will be both the '@IntDef' annotation and the container of the enum
+ members; otherwise the interface has an empty body.
+
+ Your app must declare a compile-time dependency on the
+ android-support-annotations library.
+
+ For more information on how these @IntDef annotations help with
+ compile-time type safety, see:
+ https://sites.google.com/a/android.com/tools/tech-docs/support-annotations
+ and
+ https://developer.android.com/reference/android/support/annotation/IntDef.html
+
+
+To use nano protobufs within the Android repo:
+----------------------------------------------
+
+- Set 'LOCAL_PROTOC_OPTIMIZE_TYPE := nano' in your local .mk file.
+ When building a Java library or an app (package) target, the build
+ system will add the Java nano runtime library to the
+ LOCAL_STATIC_JAVA_LIBRARIES variable, so you don't need to.
+- Set 'LOCAL_PROTO_JAVA_OUTPUT_PARAMS := ...' in your local .mk file
+ for any command-line options you need. Use commas to join multiple
+ options. In the nano flavor only, whitespace surrounding the option
+ names and values are ignored, so you can use backslash-newline or
+ '+=' to structure your make files nicely.
+- The options will be applied to *all* proto files in LOCAL_SRC_FILES
+ when you build a Java library or package. In case different options
+ are needed for different proto files, build separate Java libraries
+ and reference them in your main target. Note: you should make sure
+ that, for each separate target, all proto files imported from any
+ proto file in LOCAL_SRC_FILES are included in LOCAL_SRC_FILES. This
+ is because the generator has to assume that the imported files are
+ built using the same options, and will generate code that reference
+ the fields and enums from the imported files using the same code
+ style.
+- Hint: 'include $(CLEAR_VARS)' resets all LOCAL_ variables, including
+ the two above.
+
+To use nano protobufs outside of Android repo:
+----------------------------------------------
+
+- Link with the generated jar file
+ \<protobuf-root\>java/target/protobuf-java-2.3.0-nano.jar.
+- Invoke with --javanano_out, e.g.:
+```
+./protoc '--javanano_out=\
+ java_package=src/proto/simple-data.proto|my_package,\
+ java_outer_classname=src/proto/simple-data.proto|OuterName\
+ :.' src/proto/simple-data.proto
+```
+
+Contributing to nano:
+---------------------
+
+Please add/edit tests in NanoTest.java.
+
+Please run the following steps to test:
+
+- cd external/protobuf
+- ./configure
+- Run "make -j12 check" and verify all tests pass.
+- cd java
+- Run "mvn test" and verify all tests pass.
+- cd ../../..
+- . build/envsetup.sh
+- lunch 1
+- "make -j12 aprotoc libprotobuf-java-2.3.0-nano aprotoc-test-nano-params NanoAndroidTest" and
+ check for build errors.
+- Plug in an Android device or start an emulator.
+- adb install -r out/target/product/generic/data/app/NanoAndroidTest.apk
+- Run:
+ "adb shell am instrument -w com.google.protobuf.nano.test/android.test.InstrumentationTestRunner"
+ and verify all tests pass.
+- repo sync -c -j256
+- "make -j12" and check for build errors
+
+Usage
+-----
+
+The complete documentation for Protocol Buffers is available via the
+web at:
+
+ https://developers.google.com/protocol-buffers/
diff --git a/third_party/protobuf/javanano/pom.xml b/third_party/protobuf/javanano/pom.xml
new file mode 100644
index 0000000000..0395e8f2dc
--- /dev/null
+++ b/third_party/protobuf/javanano/pom.xml
@@ -0,0 +1,244 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>com.google</groupId>
+ <artifactId>google</artifactId>
+ <version>1</version>
+ </parent>
+ <groupId>com.google.protobuf.nano</groupId>
+ <artifactId>protobuf-javanano</artifactId>
+ <version>3.2.0</version>
+ <packaging>bundle</packaging>
+ <name>Protocol Buffer JavaNano API</name>
+ <description>
+ Protocol Buffers are a way of encoding structured data in an efficient yet
+ extensible format.
+ </description>
+ <inceptionYear>2008</inceptionYear>
+ <url>https://developers.google.com/protocol-buffers/</url>
+ <licenses>
+ <license>
+ <name>3-Clause BSD License</name>
+ <url>https://opensource.org/licenses/BSD-3-Clause</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+ <scm>
+ <url>https://github.com/google/protobuf</url>
+ <connection>
+ scm:git:https://github.com/google/protobuf.git
+ </connection>
+ </scm>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymockclassextension</artifactId>
+ <version>2.2.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <includes>
+ <include>**/*Test.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>generate-test-sources</id>
+ <phase>generate-test-sources</phase>
+ <configuration>
+ <tasks>
+ <mkdir dir="target/generated-test-sources" />
+ <exec executable="../src/protoc">
+ <arg value="--javanano_out=generate_equals=true:target/generated-test-sources" />
+ <arg value="--proto_path=src/test/java/com" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_nano.proto" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_simple_nano.proto" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_stringutf8_nano.proto" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_recursive_nano.proto" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_import_nano.proto" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_single_nano.proto" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_multiple_nano.proto" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_multiple_nameclash_nano.proto" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_enum_class_nano.proto" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_repeated_merge_nano.proto" />
+ <arg value="src/test/java/com/google/protobuf/nano/map_test.proto" />
+ </exec>
+ <exec executable="../src/protoc">
+ <arg value="--javanano_out=store_unknown_fields=true,generate_equals=true,generate_clone=true:target/generated-test-sources" />
+ <arg value="--proto_path=src/test/java/com" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_extension_nano.proto" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_extension_singular_nano.proto" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_extension_repeated_nano.proto" />
+ </exec>
+ <exec executable="../src/protoc">
+ <arg value="--javanano_out=store_unknown_fields=true,generate_clone=true:target/generated-test-sources" />
+ <arg value="--proto_path=src/test/java/com" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_extension_packed_nano.proto" />
+ </exec>
+ <exec executable="../src/protoc">
+ <arg value="--javanano_out=java_nano_generate_has=true,generate_equals=true,generate_clone=true:target/generated-test-sources" />
+ <arg value="--proto_path=src/test/java/com" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_has_nano.proto" />
+ </exec>
+ <exec executable="../src/protoc">
+ <arg value="--javanano_out=optional_field_style=accessors,generate_equals=true:target/generated-test-sources" />
+ <arg value="--proto_path=src/test/java/com" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_accessors_nano.proto" />
+ </exec>
+ <exec executable="../src/protoc">
+ <arg value="--javanano_out=enum_style=java:target/generated-test-sources" />
+ <arg value="--proto_path=src/test/java/com" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_enum_class_nano.proto" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_enum_class_multiple_nano.proto" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_repeated_packables_nano.proto" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_enum_validity_nano.proto" />
+ </exec>
+ <exec executable="../src/protoc">
+ <arg value="--javanano_out=
+ optional_field_style=accessors,
+ java_outer_classname=google/protobuf/nano/unittest_enum_validity_nano.proto|EnumValidityAccessors
+ :target/generated-test-sources" />
+ <arg value="--proto_path=src/test/java/com" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_enum_validity_nano.proto" />
+ </exec>
+ <exec executable="../src/protoc">
+ <arg value="--javanano_out=optional_field_style=reftypes,generate_equals=true:target/generated-test-sources" />
+ <arg value="--proto_path=src/test/java/com" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_reference_types_nano.proto" />
+ </exec>
+ <exec executable="../src/protoc">
+ <arg value="--javanano_out=
+ optional_field_style=reftypes_compat_mode,
+ generate_equals=true,
+ java_outer_classname=google/protobuf/nano/unittest_reference_types_nano.proto|NanoReferenceTypesCompat
+ :target/generated-test-sources" />
+ <arg value="--proto_path=src/test/java/com" />
+ <arg value="src/test/java/com/google/protobuf/nano/unittest_reference_types_nano.proto" />
+ </exec>
+ </tasks>
+ <testSourceRoot>target/generated-test-sources</testSourceRoot>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-DocURL>https://developers.google.com/protocol-buffers/</Bundle-DocURL>
+ <Bundle-SymbolicName>com.google.protobuf.nano</Bundle-SymbolicName>
+ <Export-Package>com.google.protobuf.nano;version=3.0.0-alpha-7</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <profiles>
+ <profile>
+ <id>release</id>
+ <distributionManagement>
+ <snapshotRepository>
+ <id>sonatype-nexus-staging</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ </snapshotRepository>
+ <repository>
+ <id>sonatype-nexus-staging</id>
+ <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
+ </repository>
+ </distributionManagement>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <version>2.2.1</version>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar-no-fork</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.9.1</version>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-gpg-plugin</artifactId>
+ <version>1.5</version>
+ <executions>
+ <execution>
+ <id>sign-artifacts</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>sign</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.sonatype.plugins</groupId>
+ <artifactId>nexus-staging-maven-plugin</artifactId>
+ <version>1.6.3</version>
+ <extensions>true</extensions>
+ <configuration>
+ <serverId>sonatype-nexus-staging</serverId>
+ <nexusUrl>https://oss.sonatype.org/</nexusUrl>
+ <autoReleaseAfterClose>false</autoReleaseAfterClose>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
diff --git a/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/CodedInputByteBufferNano.java b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/CodedInputByteBufferNano.java
new file mode 100644
index 0000000000..f399315511
--- /dev/null
+++ b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/CodedInputByteBufferNano.java
@@ -0,0 +1,683 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2013 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.nano;
+
+import java.io.IOException;
+
+/**
+ * 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.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public final class CodedInputByteBufferNano {
+ /**
+ * Create a new CodedInputStream wrapping the given byte array.
+ */
+ public static CodedInputByteBufferNano newInstance(final byte[] buf) {
+ return newInstance(buf, 0, buf.length);
+ }
+
+ /**
+ * Create a new CodedInputStream wrapping the given byte array slice.
+ */
+ public static CodedInputByteBufferNano newInstance(final byte[] buf, final int off,
+ final int len) {
+ return new CodedInputByteBufferNano(buf, off, len);
+ }
+
+ // -----------------------------------------------------------------
+
+ /**
+ * 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 (lastTag == 0) {
+ // If we actually read zero, that's not a valid tag.
+ throw InvalidProtocolBufferNanoException.invalidTag();
+ }
+ return lastTag;
+ }
+
+ /**
+ * 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 InvalidProtocolBufferNanoException {@code value} does not match the
+ * last tag.
+ */
+ public void checkLastTagWas(final int value)
+ throws InvalidProtocolBufferNanoException {
+ if (lastTag != value) {
+ throw InvalidProtocolBufferNanoException.invalidEndTag();
+ }
+ }
+
+ /**
+ * 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}.
+ */
+ public boolean skipField(final int tag) throws IOException {
+ switch (WireFormatNano.getTagWireType(tag)) {
+ case WireFormatNano.WIRETYPE_VARINT:
+ readInt32();
+ return true;
+ case WireFormatNano.WIRETYPE_FIXED64:
+ readRawLittleEndian64();
+ return true;
+ case WireFormatNano.WIRETYPE_LENGTH_DELIMITED:
+ skipRawBytes(readRawVarint32());
+ return true;
+ case WireFormatNano.WIRETYPE_START_GROUP:
+ skipMessage();
+ checkLastTagWas(
+ WireFormatNano.makeTag(WireFormatNano.getTagFieldNumber(tag),
+ WireFormatNano.WIRETYPE_END_GROUP));
+ return true;
+ case WireFormatNano.WIRETYPE_END_GROUP:
+ return false;
+ case WireFormatNano.WIRETYPE_FIXED32:
+ readRawLittleEndian32();
+ return true;
+ default:
+ throw InvalidProtocolBufferNanoException.invalidWireType();
+ }
+ }
+
+ /**
+ * Reads and discards an entire message. This will read either until EOF
+ * or until an endgroup tag, whichever comes first.
+ */
+ public void skipMessage() throws IOException {
+ while (true) {
+ final int tag = readTag();
+ if (tag == 0 || !skipField(tag)) {
+ return;
+ }
+ }
+ }
+
+ // -----------------------------------------------------------------
+
+ /** Read a {@code double} field value from the stream. */
+ public double readDouble() throws IOException {
+ return Double.longBitsToDouble(readRawLittleEndian64());
+ }
+
+ /** Read a {@code float} field value from the stream. */
+ public float readFloat() throws IOException {
+ return Float.intBitsToFloat(readRawLittleEndian32());
+ }
+
+ /** Read a {@code uint64} field value from the stream. */
+ public long readUInt64() throws IOException {
+ return readRawVarint64();
+ }
+
+ /** Read an {@code int64} field value from the stream. */
+ public long readInt64() throws IOException {
+ return readRawVarint64();
+ }
+
+ /** Read an {@code int32} field value from the stream. */
+ public int readInt32() throws IOException {
+ return readRawVarint32();
+ }
+
+ /** Read a {@code fixed64} field value from the stream. */
+ public long readFixed64() throws IOException {
+ return readRawLittleEndian64();
+ }
+
+ /** Read a {@code fixed32} field value from the stream. */
+ public int readFixed32() throws IOException {
+ return readRawLittleEndian32();
+ }
+
+ /** Read a {@code bool} field value from the stream. */
+ public boolean readBool() throws IOException {
+ return readRawVarint32() != 0;
+ }
+
+ /** Read a {@code string} field value from the stream. */
+ 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, InternalNano.UTF_8);
+ bufferPos += size;
+ return result;
+ } else {
+ // Slow path: Build a byte array first then copy it.
+ return new String(readRawBytes(size), InternalNano.UTF_8);
+ }
+ }
+
+ /** Read a {@code group} field value from the stream. */
+ public void readGroup(final MessageNano msg, final int fieldNumber)
+ throws IOException {
+ if (recursionDepth >= recursionLimit) {
+ throw InvalidProtocolBufferNanoException.recursionLimitExceeded();
+ }
+ ++recursionDepth;
+ msg.mergeFrom(this);
+ checkLastTagWas(
+ WireFormatNano.makeTag(fieldNumber, WireFormatNano.WIRETYPE_END_GROUP));
+ --recursionDepth;
+ }
+
+ public void readMessage(final MessageNano msg)
+ throws IOException {
+ final int length = readRawVarint32();
+ if (recursionDepth >= recursionLimit) {
+ throw InvalidProtocolBufferNanoException.recursionLimitExceeded();
+ }
+ final int oldLimit = pushLimit(length);
+ ++recursionDepth;
+ msg.mergeFrom(this);
+ checkLastTagWas(0);
+ --recursionDepth;
+ popLimit(oldLimit);
+ }
+
+ /** Read a {@code bytes} field value from the stream. */
+ public byte[] 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 byte[] result = new byte[size];
+ System.arraycopy(buffer, bufferPos, result, 0, size);
+ bufferPos += size;
+ return result;
+ } else if (size == 0) {
+ return WireFormatNano.EMPTY_BYTES;
+ } else {
+ // Slow path: Build a byte array first then copy it.
+ return readRawBytes(size);
+ }
+ }
+
+ /** Read a {@code uint32} field value from the stream. */
+ public int readUInt32() throws IOException {
+ return readRawVarint32();
+ }
+
+ /**
+ * 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();
+ }
+
+ /** Read an {@code sfixed32} field value from the stream. */
+ public int readSFixed32() throws IOException {
+ return readRawLittleEndian32();
+ }
+
+ /** Read an {@code sfixed64} field value from the stream. */
+ public long readSFixed64() throws IOException {
+ return readRawLittleEndian64();
+ }
+
+ /** Read an {@code sint32} field value from the stream. */
+ public int readSInt32() throws IOException {
+ return decodeZigZag32(readRawVarint32());
+ }
+
+ /** Read an {@code sint64} field value from the stream. */
+ public long readSInt64() throws IOException {
+ return decodeZigZag64(readRawVarint64());
+ }
+
+ // =================================================================
+
+ /**
+ * Read a raw Varint from the stream. If larger than 32 bits, discard the
+ * upper bits.
+ */
+ public int readRawVarint32() throws IOException {
+ byte tmp = readRawByte();
+ if (tmp >= 0) {
+ return tmp;
+ }
+ int result = tmp & 0x7f;
+ if ((tmp = readRawByte()) >= 0) {
+ result |= tmp << 7;
+ } else {
+ result |= (tmp & 0x7f) << 7;
+ if ((tmp = readRawByte()) >= 0) {
+ result |= tmp << 14;
+ } else {
+ result |= (tmp & 0x7f) << 14;
+ if ((tmp = readRawByte()) >= 0) {
+ result |= tmp << 21;
+ } else {
+ result |= (tmp & 0x7f) << 21;
+ result |= (tmp = readRawByte()) << 28;
+ if (tmp < 0) {
+ // Discard upper 32 bits.
+ for (int i = 0; i < 5; i++) {
+ if (readRawByte() >= 0) {
+ return result;
+ }
+ }
+ throw InvalidProtocolBufferNanoException.malformedVarint();
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /** Read a raw Varint from the stream. */
+ public long readRawVarint64() throws IOException {
+ int shift = 0;
+ long result = 0;
+ while (shift < 64) {
+ final byte b = readRawByte();
+ result |= (long)(b & 0x7F) << shift;
+ if ((b & 0x80) == 0) {
+ return result;
+ }
+ shift += 7;
+ }
+ throw InvalidProtocolBufferNanoException.malformedVarint();
+ }
+
+ /** Read a 32-bit little-endian integer from the stream. */
+ public int readRawLittleEndian32() throws IOException {
+ final byte b1 = readRawByte();
+ final byte b2 = readRawByte();
+ final byte b3 = readRawByte();
+ final byte b4 = readRawByte();
+ return ((b1 & 0xff) ) |
+ ((b2 & 0xff) << 8) |
+ ((b3 & 0xff) << 16) |
+ ((b4 & 0xff) << 24);
+ }
+
+ /** Read a 64-bit little-endian integer from the stream. */
+ public long readRawLittleEndian64() throws IOException {
+ final byte b1 = readRawByte();
+ final byte b2 = readRawByte();
+ final byte b3 = readRawByte();
+ final byte b4 = readRawByte();
+ final byte b5 = readRawByte();
+ final byte b6 = readRawByte();
+ final byte b7 = readRawByte();
+ final byte b8 = readRawByte();
+ return (((long)b1 & 0xff) ) |
+ (((long)b2 & 0xff) << 8) |
+ (((long)b3 & 0xff) << 16) |
+ (((long)b4 & 0xff) << 24) |
+ (((long)b5 & 0xff) << 32) |
+ (((long)b6 & 0xff) << 40) |
+ (((long)b7 & 0xff) << 48) |
+ (((long)b8 & 0xff) << 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);
+ }
+
+ // -----------------------------------------------------------------
+
+ private final byte[] buffer;
+ private int bufferStart;
+ private int bufferSize;
+ private int bufferSizeAfterLimit;
+ private int bufferPos;
+ private int lastTag;
+
+ /** 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 = 64;
+ private static final int DEFAULT_SIZE_LIMIT = 64 << 20; // 64MB
+
+ private CodedInputByteBufferNano(final byte[] buffer, final int off, final int len) {
+ this.buffer = buffer;
+ bufferStart = off;
+ bufferSize = off + len;
+ bufferPos = off;
+ }
+
+ /**
+ * 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) {
+ if (limit < 0) {
+ throw new IllegalArgumentException(
+ "Recursion limit cannot be negative: " + limit);
+ }
+ final int oldLimit = recursionLimit;
+ recursionLimit = limit;
+ return oldLimit;
+ }
+
+ /**
+ * 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.
+ * <p>
+ * 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) {
+ if (limit < 0) {
+ throw new IllegalArgumentException(
+ "Size limit cannot be negative: " + limit);
+ }
+ final int oldLimit = sizeLimit;
+ sizeLimit = limit;
+ return oldLimit;
+ }
+
+ /**
+ * Resets the current size counter to zero (see {@link #setSizeLimit(int)}).
+ */
+ public void resetSizeCounter() {
+ }
+
+ /**
+ * Sets {@code currentLimit} to (current position) + {@code byteLimit}. This
+ * is called when descending into a length-delimited embedded message.
+ *
+ * @return the old limit.
+ */
+ public int pushLimit(int byteLimit) throws InvalidProtocolBufferNanoException {
+ if (byteLimit < 0) {
+ throw InvalidProtocolBufferNanoException.negativeSize();
+ }
+ byteLimit += bufferPos;
+ final int oldLimit = currentLimit;
+ if (byteLimit > oldLimit) {
+ throw InvalidProtocolBufferNanoException.truncatedMessage();
+ }
+ currentLimit = byteLimit;
+
+ recomputeBufferSizeAfterLimit();
+
+ return oldLimit;
+ }
+
+ private void recomputeBufferSizeAfterLimit() {
+ bufferSize += bufferSizeAfterLimit;
+ final int bufferEnd = bufferSize;
+ if (bufferEnd > currentLimit) {
+ // Limit is in current buffer.
+ bufferSizeAfterLimit = bufferEnd - currentLimit;
+ bufferSize -= bufferSizeAfterLimit;
+ } else {
+ bufferSizeAfterLimit = 0;
+ }
+ }
+
+ /**
+ * 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();
+ }
+
+ /**
+ * 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 = bufferPos;
+ return currentLimit - currentAbsolutePosition;
+ }
+
+ /**
+ * 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() {
+ return bufferPos == bufferSize;
+ }
+
+ /**
+ * Get current position in buffer relative to beginning offset.
+ */
+ public int getPosition() {
+ return bufferPos - bufferStart;
+ }
+
+ /**
+ * Retrieves a subset of data in the buffer. The returned array is not backed by the original
+ * buffer array.
+ *
+ * @param offset the position (relative to the buffer start position) to start at.
+ * @param length the number of bytes to retrieve.
+ */
+ public byte[] getData(int offset, int length) {
+ if (length == 0) {
+ return WireFormatNano.EMPTY_BYTES;
+ }
+ byte[] copy = new byte[length];
+ int start = bufferStart + offset;
+ System.arraycopy(buffer, start, copy, 0, length);
+ return copy;
+ }
+
+ /**
+ * Rewind to previous position. Cannot go forward.
+ */
+ public void rewindToPosition(int position) {
+ if (position > bufferPos - bufferStart) {
+ throw new IllegalArgumentException(
+ "Position " + position + " is beyond current " + (bufferPos - bufferStart));
+ }
+ if (position < 0) {
+ throw new IllegalArgumentException("Bad position " + position);
+ }
+ bufferPos = bufferStart + position;
+ }
+
+ /**
+ * Read one byte from the input.
+ *
+ * @throws InvalidProtocolBufferNanoException The end of the stream or the current
+ * limit was reached.
+ */
+ public byte readRawByte() throws IOException {
+ if (bufferPos == bufferSize) {
+ throw InvalidProtocolBufferNanoException.truncatedMessage();
+ }
+ return buffer[bufferPos++];
+ }
+
+ /**
+ * Read a fixed size of bytes from the input.
+ *
+ * @throws InvalidProtocolBufferNanoException The end of the stream or the current
+ * limit was reached.
+ */
+ public byte[] readRawBytes(final int size) throws IOException {
+ if (size < 0) {
+ throw InvalidProtocolBufferNanoException.negativeSize();
+ }
+
+ if (bufferPos + size > currentLimit) {
+ // Read to the end of the stream anyway.
+ skipRawBytes(currentLimit - bufferPos);
+ // Then fail.
+ throw InvalidProtocolBufferNanoException.truncatedMessage();
+ }
+
+ if (size <= bufferSize - bufferPos) {
+ // We have all the bytes we need already.
+ final byte[] bytes = new byte[size];
+ System.arraycopy(buffer, bufferPos, bytes, 0, size);
+ bufferPos += size;
+ return bytes;
+ } else {
+ throw InvalidProtocolBufferNanoException.truncatedMessage();
+ }
+ }
+
+ /**
+ * Reads and discards {@code size} bytes.
+ *
+ * @throws InvalidProtocolBufferNanoException The end of the stream or the current
+ * limit was reached.
+ */
+ public void skipRawBytes(final int size) throws IOException {
+ if (size < 0) {
+ throw InvalidProtocolBufferNanoException.negativeSize();
+ }
+
+ if (bufferPos + size > currentLimit) {
+ // Read to the end of the stream anyway.
+ skipRawBytes(currentLimit - bufferPos);
+ // Then fail.
+ throw InvalidProtocolBufferNanoException.truncatedMessage();
+ }
+
+ if (size <= bufferSize - bufferPos) {
+ // We have all the bytes we need already.
+ bufferPos += size;
+ } else {
+ throw InvalidProtocolBufferNanoException.truncatedMessage();
+ }
+ }
+
+ // Read a primitive type.
+ Object readPrimitiveField(int type) throws IOException {
+ switch (type) {
+ case InternalNano.TYPE_DOUBLE:
+ return readDouble();
+ case InternalNano.TYPE_FLOAT:
+ return readFloat();
+ case InternalNano.TYPE_INT64:
+ return readInt64();
+ case InternalNano.TYPE_UINT64:
+ return readUInt64();
+ case InternalNano.TYPE_INT32:
+ return readInt32();
+ case InternalNano.TYPE_FIXED64:
+ return readFixed64();
+ case InternalNano.TYPE_FIXED32:
+ return readFixed32();
+ case InternalNano.TYPE_BOOL:
+ return readBool();
+ case InternalNano.TYPE_STRING:
+ return readString();
+ case InternalNano.TYPE_BYTES:
+ return readBytes();
+ case InternalNano.TYPE_UINT32:
+ return readUInt32();
+ case InternalNano.TYPE_ENUM:
+ return readEnum();
+ case InternalNano.TYPE_SFIXED32:
+ return readSFixed32();
+ case InternalNano.TYPE_SFIXED64:
+ return readSFixed64();
+ case InternalNano.TYPE_SINT32:
+ return readSInt32();
+ case InternalNano.TYPE_SINT64:
+ return readSInt64();
+ default:
+ throw new IllegalArgumentException("Unknown type " + type);
+ }
+ }
+}
diff --git a/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
new file mode 100644
index 0000000000..322ada8e1f
--- /dev/null
+++ b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/CodedOutputByteBufferNano.java
@@ -0,0 +1,1214 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2013 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.nano;
+
+import java.io.IOException;
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.ReadOnlyBufferException;
+
+/**
+ * Encodes and writes protocol message fields.
+ *
+ * <p>This class contains two kinds of methods: methods that write specific
+ * protocol message constructs and field types (e.g. {@link #writeTag} and
+ * {@link #writeInt32}) and methods that write low-level values (e.g.
+ * {@link #writeRawVarint32} and {@link #writeRawBytes}). If you are
+ * writing encoded protocol messages, you should use the former methods, but if
+ * you are writing some other format of your own design, use the latter.
+ *
+ * <p>This class is totally unsynchronized.
+ *
+ * @author kneton@google.com Kenton Varda
+ */
+public final class CodedOutputByteBufferNano {
+ /* max bytes per java UTF-16 char in UTF-8 */
+ private static final int MAX_UTF8_EXPANSION = 3;
+ private final ByteBuffer buffer;
+
+ private CodedOutputByteBufferNano(final byte[] buffer, final int offset,
+ final int length) {
+ this(ByteBuffer.wrap(buffer, offset, length));
+ }
+
+ private CodedOutputByteBufferNano(final ByteBuffer buffer) {
+ this.buffer = buffer;
+ this.buffer.order(ByteOrder.LITTLE_ENDIAN);
+ }
+
+ /**
+ * Create a new {@code CodedOutputStream} that writes directly to the given
+ * byte array. If more bytes are written than fit in the array,
+ * {@link OutOfSpaceException} will be thrown. Writing directly to a flat
+ * array is faster than writing to an {@code OutputStream}.
+ */
+ public static CodedOutputByteBufferNano newInstance(final byte[] flatArray) {
+ return newInstance(flatArray, 0, flatArray.length);
+ }
+
+ /**
+ * Create a new {@code CodedOutputStream} that writes directly to the given
+ * byte array slice. If more bytes are written than fit in the slice,
+ * {@link OutOfSpaceException} will be thrown. Writing directly to a flat
+ * array is faster than writing to an {@code OutputStream}.
+ */
+ public static CodedOutputByteBufferNano newInstance(final byte[] flatArray,
+ final int offset,
+ final int length) {
+ return new CodedOutputByteBufferNano(flatArray, offset, length);
+ }
+
+ // -----------------------------------------------------------------
+
+ /** Write a {@code double} field, including tag, to the stream. */
+ public void writeDouble(final int fieldNumber, final double value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_FIXED64);
+ writeDoubleNoTag(value);
+ }
+
+ /** Write a {@code float} field, including tag, to the stream. */
+ public void writeFloat(final int fieldNumber, final float value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_FIXED32);
+ writeFloatNoTag(value);
+ }
+
+ /** Write a {@code uint64} field, including tag, to the stream. */
+ public void writeUInt64(final int fieldNumber, final long value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_VARINT);
+ writeUInt64NoTag(value);
+ }
+
+ /** Write an {@code int64} field, including tag, to the stream. */
+ public void writeInt64(final int fieldNumber, final long value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_VARINT);
+ writeInt64NoTag(value);
+ }
+
+ /** Write an {@code int32} field, including tag, to the stream. */
+ public void writeInt32(final int fieldNumber, final int value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_VARINT);
+ writeInt32NoTag(value);
+ }
+
+ /** Write a {@code fixed64} field, including tag, to the stream. */
+ public void writeFixed64(final int fieldNumber, final long value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_FIXED64);
+ writeFixed64NoTag(value);
+ }
+
+ /** Write a {@code fixed32} field, including tag, to the stream. */
+ public void writeFixed32(final int fieldNumber, final int value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_FIXED32);
+ writeFixed32NoTag(value);
+ }
+
+ /** Write a {@code bool} field, including tag, to the stream. */
+ public void writeBool(final int fieldNumber, final boolean value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_VARINT);
+ writeBoolNoTag(value);
+ }
+
+ /** Write a {@code string} field, including tag, to the stream. */
+ public void writeString(final int fieldNumber, final String value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_LENGTH_DELIMITED);
+ writeStringNoTag(value);
+ }
+
+ /** Write a {@code group} field, including tag, to the stream. */
+ public void writeGroup(final int fieldNumber, final MessageNano value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_START_GROUP);
+ writeGroupNoTag(value);
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_END_GROUP);
+ }
+
+ /** Write an embedded message field, including tag, to the stream. */
+ public void writeMessage(final int fieldNumber, final MessageNano value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_LENGTH_DELIMITED);
+ writeMessageNoTag(value);
+ }
+
+ /** Write a {@code bytes} field, including tag, to the stream. */
+ public void writeBytes(final int fieldNumber, final byte[] value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_LENGTH_DELIMITED);
+ writeBytesNoTag(value);
+ }
+
+ /** Write a {@code uint32} field, including tag, to the stream. */
+ public void writeUInt32(final int fieldNumber, final int value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_VARINT);
+ writeUInt32NoTag(value);
+ }
+
+ /**
+ * Write an enum field, including tag, to the stream. Caller is responsible
+ * for converting the enum value to its numeric value.
+ */
+ public void writeEnum(final int fieldNumber, final int value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_VARINT);
+ writeEnumNoTag(value);
+ }
+
+ /** Write an {@code sfixed32} field, including tag, to the stream. */
+ public void writeSFixed32(final int fieldNumber, final int value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_FIXED32);
+ writeSFixed32NoTag(value);
+ }
+
+ /** Write an {@code sfixed64} field, including tag, to the stream. */
+ public void writeSFixed64(final int fieldNumber, final long value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_FIXED64);
+ writeSFixed64NoTag(value);
+ }
+
+ /** Write an {@code sint32} field, including tag, to the stream. */
+ public void writeSInt32(final int fieldNumber, final int value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_VARINT);
+ writeSInt32NoTag(value);
+ }
+
+ /** Write an {@code sint64} field, including tag, to the stream. */
+ public void writeSInt64(final int fieldNumber, final long value)
+ throws IOException {
+ writeTag(fieldNumber, WireFormatNano.WIRETYPE_VARINT);
+ writeSInt64NoTag(value);
+ }
+
+ /**
+ * Write a MessageSet extension field to the stream. For historical reasons,
+ * the wire format differs from normal fields.
+ */
+// public void writeMessageSetExtension(final int fieldNumber,
+// final MessageMicro value)
+// throws IOException {
+// writeTag(WireFormatMicro.MESSAGE_SET_ITEM, WireFormatMicro.WIRETYPE_START_GROUP);
+// writeUInt32(WireFormatMicro.MESSAGE_SET_TYPE_ID, fieldNumber);
+// writeMessage(WireFormatMicro.MESSAGE_SET_MESSAGE, value);
+// writeTag(WireFormatMicro.MESSAGE_SET_ITEM, WireFormatMicro.WIRETYPE_END_GROUP);
+// }
+
+ /**
+ * Write an unparsed MessageSet extension field to the stream. For
+ * historical reasons, the wire format differs from normal fields.
+ */
+// public void writeRawMessageSetExtension(final int fieldNumber,
+// final ByteStringMicro value)
+// throws IOException {
+// writeTag(WireFormatMicro.MESSAGE_SET_ITEM, WireFormatMicro.WIRETYPE_START_GROUP);
+// writeUInt32(WireFormatMicro.MESSAGE_SET_TYPE_ID, fieldNumber);
+// writeBytes(WireFormatMicro.MESSAGE_SET_MESSAGE, value);
+// writeTag(WireFormatMicro.MESSAGE_SET_ITEM, WireFormatMicro.WIRETYPE_END_GROUP);
+// }
+
+ // -----------------------------------------------------------------
+
+ /** Write a {@code double} field to the stream. */
+ public void writeDoubleNoTag(final double value) throws IOException {
+ writeRawLittleEndian64(Double.doubleToLongBits(value));
+ }
+
+ /** Write a {@code float} field to the stream. */
+ public void writeFloatNoTag(final float value) throws IOException {
+ writeRawLittleEndian32(Float.floatToIntBits(value));
+ }
+
+ /** Write a {@code uint64} field to the stream. */
+ public void writeUInt64NoTag(final long value) throws IOException {
+ writeRawVarint64(value);
+ }
+
+ /** Write an {@code int64} field to the stream. */
+ public void writeInt64NoTag(final long value) throws IOException {
+ writeRawVarint64(value);
+ }
+
+ /** Write an {@code int32} field to the stream. */
+ public void writeInt32NoTag(final int value) throws IOException {
+ if (value >= 0) {
+ writeRawVarint32(value);
+ } else {
+ // Must sign-extend.
+ writeRawVarint64(value);
+ }
+ }
+
+ /** Write a {@code fixed64} field to the stream. */
+ public void writeFixed64NoTag(final long value) throws IOException {
+ writeRawLittleEndian64(value);
+ }
+
+ /** Write a {@code fixed32} field to the stream. */
+ public void writeFixed32NoTag(final int value) throws IOException {
+ writeRawLittleEndian32(value);
+ }
+
+ /** Write a {@code bool} field to the stream. */
+ public void writeBoolNoTag(final boolean value) throws IOException {
+ writeRawByte(value ? 1 : 0);
+ }
+
+ /** Write a {@code string} field to the stream. */
+ public void writeStringNoTag(final String value) throws IOException {
+ // 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. Optimize for the case where we know this length results in a
+ // constant varint length - saves measuring length of the string.
+ try {
+ final int minLengthVarIntSize = computeRawVarint32Size(value.length());
+ final int maxLengthVarIntSize = computeRawVarint32Size(value.length() * MAX_UTF8_EXPANSION);
+ if (minLengthVarIntSize == maxLengthVarIntSize) {
+ int oldPosition = buffer.position();
+ // Buffer.position, when passed a position that is past its limit, throws
+ // IllegalArgumentException, and this class is documented to throw
+ // OutOfSpaceException instead.
+ if (buffer.remaining() < minLengthVarIntSize) {
+ throw new OutOfSpaceException(oldPosition + minLengthVarIntSize, buffer.limit());
+ }
+ buffer.position(oldPosition + minLengthVarIntSize);
+ encode(value, buffer);
+ int newPosition = buffer.position();
+ buffer.position(oldPosition);
+ writeRawVarint32(newPosition - oldPosition - minLengthVarIntSize);
+ buffer.position(newPosition);
+ } else {
+ writeRawVarint32(encodedLength(value));
+ encode(value, buffer);
+ }
+ } catch (BufferOverflowException e) {
+ final OutOfSpaceException outOfSpaceException = new OutOfSpaceException(buffer.position(),
+ buffer.limit());
+ outOfSpaceException.initCause(e);
+ throw outOfSpaceException;
+ }
+ }
+
+ // These UTF-8 handling methods are copied from Guava's Utf8 class.
+ /**
+ * Returns the number of bytes in the UTF-8-encoded form of {@code sequence}. For a string,
+ * this method is equivalent to {@code string.getBytes(UTF_8).length}, but is more efficient in
+ * both time and space.
+ *
+ * @throws IllegalArgumentException if {@code sequence} contains ill-formed UTF-16 (unpaired
+ * surrogates)
+ */
+ private static int encodedLength(CharSequence sequence) {
+ // Warning to maintainers: this implementation is highly optimized.
+ int utf16Length = sequence.length();
+ int utf8Length = utf16Length;
+ int i = 0;
+
+ // This loop optimizes for pure ASCII.
+ while (i < utf16Length && sequence.charAt(i) < 0x80) {
+ i++;
+ }
+
+ // This loop optimizes for chars less than 0x800.
+ for (; i < utf16Length; i++) {
+ char c = sequence.charAt(i);
+ if (c < 0x800) {
+ utf8Length += ((0x7f - c) >>> 31); // branch free!
+ } else {
+ utf8Length += encodedLengthGeneral(sequence, i);
+ break;
+ }
+ }
+
+ if (utf8Length < utf16Length) {
+ // Necessary and sufficient condition for overflow because of maximum 3x expansion
+ throw new IllegalArgumentException("UTF-8 length does not fit in int: "
+ + (utf8Length + (1L << 32)));
+ }
+ return utf8Length;
+ }
+
+ private static int encodedLengthGeneral(CharSequence sequence, int start) {
+ int utf16Length = sequence.length();
+ int utf8Length = 0;
+ for (int i = start; i < utf16Length; i++) {
+ char c = sequence.charAt(i);
+ if (c < 0x800) {
+ utf8Length += (0x7f - c) >>> 31; // branch free!
+ } else {
+ utf8Length += 2;
+ // jdk7+: if (Character.isSurrogate(c)) {
+ if (Character.MIN_SURROGATE <= c && c <= Character.MAX_SURROGATE) {
+ // Check that we have a well-formed surrogate pair.
+ int cp = Character.codePointAt(sequence, i);
+ if (cp < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
+ throw new IllegalArgumentException("Unpaired surrogate at index " + i);
+ }
+ i++;
+ }
+ }
+ }
+ return utf8Length;
+ }
+
+ /**
+ * Encodes {@code sequence} into UTF-8, in {@code byteBuffer}. For a string, this method is
+ * equivalent to {@code buffer.put(string.getBytes(UTF_8))}, but is more efficient in both time
+ * and space. Bytes are written starting at the current position. This method requires paired
+ * surrogates, and therefore does not support chunking.
+ *
+ * <p>To ensure sufficient space in the output buffer, either call {@link #encodedLength} to
+ * compute the exact amount needed, or leave room for {@code 3 * sequence.length()}, which is the
+ * largest possible number of bytes that any input can be encoded to.
+ *
+ * @throws IllegalArgumentException if {@code sequence} contains ill-formed UTF-16 (unpaired
+ * surrogates)
+ * @throws BufferOverflowException if {@code sequence} encoded in UTF-8 does not fit in
+ * {@code byteBuffer}'s remaining space.
+ * @throws ReadOnlyBufferException if {@code byteBuffer} is a read-only buffer.
+ */
+ private static void encode(CharSequence sequence, ByteBuffer byteBuffer) {
+ if (byteBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ } else if (byteBuffer.hasArray()) {
+ try {
+ int encoded = encode(sequence,
+ byteBuffer.array(),
+ byteBuffer.arrayOffset() + byteBuffer.position(),
+ byteBuffer.remaining());
+ byteBuffer.position(encoded - byteBuffer.arrayOffset());
+ } catch (ArrayIndexOutOfBoundsException e) {
+ BufferOverflowException boe = new BufferOverflowException();
+ boe.initCause(e);
+ throw boe;
+ }
+ } else {
+ encodeDirect(sequence, byteBuffer);
+ }
+ }
+
+ private static void encodeDirect(CharSequence sequence, ByteBuffer byteBuffer) {
+ int utf16Length = sequence.length();
+ for (int i = 0; i < utf16Length; i++) {
+ final char c = sequence.charAt(i);
+ if (c < 0x80) { // ASCII
+ byteBuffer.put((byte) c);
+ } else if (c < 0x800) { // 11 bits, two UTF-8 bytes
+ byteBuffer.put((byte) ((0xF << 6) | (c >>> 6)));
+ byteBuffer.put((byte) (0x80 | (0x3F & c)));
+ } else if (c < Character.MIN_SURROGATE || Character.MAX_SURROGATE < c) {
+ // Maximium single-char code point is 0xFFFF, 16 bits, three UTF-8 bytes
+ byteBuffer.put((byte) ((0xF << 5) | (c >>> 12)));
+ byteBuffer.put((byte) (0x80 | (0x3F & (c >>> 6))));
+ byteBuffer.put((byte) (0x80 | (0x3F & c)));
+ } else {
+ final char low;
+ if (i + 1 == sequence.length()
+ || !Character.isSurrogatePair(c, (low = sequence.charAt(++i)))) {
+ throw new IllegalArgumentException("Unpaired surrogate at index " + (i - 1));
+ }
+ int codePoint = Character.toCodePoint(c, low);
+ byteBuffer.put((byte) ((0xF << 4) | (codePoint >>> 18)));
+ byteBuffer.put((byte) (0x80 | (0x3F & (codePoint >>> 12))));
+ byteBuffer.put((byte) (0x80 | (0x3F & (codePoint >>> 6))));
+ byteBuffer.put((byte) (0x80 | (0x3F & codePoint)));
+ }
+ }
+ }
+
+ private static int encode(CharSequence sequence, byte[] bytes, int offset, int length) {
+ int utf16Length = sequence.length();
+ int j = offset;
+ int i = 0;
+ int limit = offset + length;
+ // Designed to take advantage of
+ // https://wikis.oracle.com/display/HotSpotInternals/RangeCheckElimination
+ for (char c; i < utf16Length && i + j < limit && (c = sequence.charAt(i)) < 0x80; i++) {
+ bytes[j + i] = (byte) c;
+ }
+ if (i == utf16Length) {
+ return j + utf16Length;
+ }
+ j += i;
+ for (char c; i < utf16Length; i++) {
+ c = sequence.charAt(i);
+ if (c < 0x80 && j < limit) {
+ bytes[j++] = (byte) c;
+ } else if (c < 0x800 && j <= limit - 2) { // 11 bits, two UTF-8 bytes
+ bytes[j++] = (byte) ((0xF << 6) | (c >>> 6));
+ bytes[j++] = (byte) (0x80 | (0x3F & c));
+ } else if ((c < Character.MIN_SURROGATE || Character.MAX_SURROGATE < c) && j <= limit - 3) {
+ // Maximum single-char code point is 0xFFFF, 16 bits, three UTF-8 bytes
+ bytes[j++] = (byte) ((0xF << 5) | (c >>> 12));
+ bytes[j++] = (byte) (0x80 | (0x3F & (c >>> 6)));
+ bytes[j++] = (byte) (0x80 | (0x3F & c));
+ } else if (j <= limit - 4) {
+ // Minimum code point represented by a surrogate pair is 0x10000, 17 bits, four UTF-8 bytes
+ final char low;
+ if (i + 1 == sequence.length()
+ || !Character.isSurrogatePair(c, (low = sequence.charAt(++i)))) {
+ throw new IllegalArgumentException("Unpaired surrogate at index " + (i - 1));
+ }
+ int codePoint = Character.toCodePoint(c, low);
+ bytes[j++] = (byte) ((0xF << 4) | (codePoint >>> 18));
+ bytes[j++] = (byte) (0x80 | (0x3F & (codePoint >>> 12)));
+ bytes[j++] = (byte) (0x80 | (0x3F & (codePoint >>> 6)));
+ bytes[j++] = (byte) (0x80 | (0x3F & codePoint));
+ } else {
+ throw new ArrayIndexOutOfBoundsException("Failed writing " + c + " at index " + j);
+ }
+ }
+ return j;
+ }
+
+ // End guava UTF-8 methods
+
+
+ /** Write a {@code group} field to the stream. */
+ public void writeGroupNoTag(final MessageNano value) throws IOException {
+ value.writeTo(this);
+ }
+
+ /** Write an embedded message field to the stream. */
+ public void writeMessageNoTag(final MessageNano value) throws IOException {
+ writeRawVarint32(value.getCachedSize());
+ value.writeTo(this);
+ }
+
+ /** Write a {@code bytes} field to the stream. */
+ public void writeBytesNoTag(final byte[] value) throws IOException {
+ writeRawVarint32(value.length);
+ writeRawBytes(value);
+ }
+
+ /** Write a {@code uint32} field to the stream. */
+ public void writeUInt32NoTag(final int value) throws IOException {
+ writeRawVarint32(value);
+ }
+
+ /**
+ * Write an enum field to the stream. Caller is responsible
+ * for converting the enum value to its numeric value.
+ */
+ public void writeEnumNoTag(final int value) throws IOException {
+ writeRawVarint32(value);
+ }
+
+ /** Write an {@code sfixed32} field to the stream. */
+ public void writeSFixed32NoTag(final int value) throws IOException {
+ writeRawLittleEndian32(value);
+ }
+
+ /** Write an {@code sfixed64} field to the stream. */
+ public void writeSFixed64NoTag(final long value) throws IOException {
+ writeRawLittleEndian64(value);
+ }
+
+ /** Write an {@code sint32} field to the stream. */
+ public void writeSInt32NoTag(final int value) throws IOException {
+ writeRawVarint32(encodeZigZag32(value));
+ }
+
+ /** Write an {@code sint64} field to the stream. */
+ public void writeSInt64NoTag(final long value) throws IOException {
+ writeRawVarint64(encodeZigZag64(value));
+ }
+
+ // =================================================================
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code double} field, including tag.
+ */
+ public static int computeDoubleSize(final int fieldNumber,
+ final double value) {
+ return computeTagSize(fieldNumber) + computeDoubleSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code float} field, including tag.
+ */
+ public static int computeFloatSize(final int fieldNumber, final float value) {
+ return computeTagSize(fieldNumber) + computeFloatSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code uint64} field, including tag.
+ */
+ public static int computeUInt64Size(final int fieldNumber, final long value) {
+ return computeTagSize(fieldNumber) + computeUInt64SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code int64} field, including tag.
+ */
+ public static int computeInt64Size(final int fieldNumber, final long value) {
+ return computeTagSize(fieldNumber) + computeInt64SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code int32} field, including tag.
+ */
+ public static int computeInt32Size(final int fieldNumber, final int value) {
+ return computeTagSize(fieldNumber) + computeInt32SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code fixed64} field, including tag.
+ */
+ public static int computeFixed64Size(final int fieldNumber,
+ final long value) {
+ return computeTagSize(fieldNumber) + computeFixed64SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code fixed32} field, including tag.
+ */
+ public static int computeFixed32Size(final int fieldNumber,
+ final int value) {
+ return computeTagSize(fieldNumber) + computeFixed32SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code bool} field, including tag.
+ */
+ public static int computeBoolSize(final int fieldNumber,
+ final boolean value) {
+ return computeTagSize(fieldNumber) + computeBoolSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code string} field, including tag.
+ */
+ public static int computeStringSize(final int fieldNumber,
+ final String value) {
+ return computeTagSize(fieldNumber) + computeStringSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code group} field, including tag.
+ */
+ public static int computeGroupSize(final int fieldNumber,
+ final MessageNano value) {
+ return computeTagSize(fieldNumber) * 2 + computeGroupSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * embedded message field, including tag.
+ */
+ public static int computeMessageSize(final int fieldNumber,
+ final MessageNano value) {
+ return computeTagSize(fieldNumber) + computeMessageSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code bytes} field, including tag.
+ */
+ public static int computeBytesSize(final int fieldNumber,
+ final byte[] value) {
+ return computeTagSize(fieldNumber) + computeBytesSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code uint32} field, including tag.
+ */
+ public static int computeUInt32Size(final int fieldNumber, final int value) {
+ return computeTagSize(fieldNumber) + computeUInt32SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * enum field, including tag. Caller is responsible for converting the
+ * enum value to its numeric value.
+ */
+ public static int computeEnumSize(final int fieldNumber, final int value) {
+ return computeTagSize(fieldNumber) + computeEnumSizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sfixed32} field, including tag.
+ */
+ public static int computeSFixed32Size(final int fieldNumber,
+ final int value) {
+ return computeTagSize(fieldNumber) + computeSFixed32SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sfixed64} field, including tag.
+ */
+ public static int computeSFixed64Size(final int fieldNumber,
+ final long value) {
+ return computeTagSize(fieldNumber) + computeSFixed64SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sint32} field, including tag.
+ */
+ public static int computeSInt32Size(final int fieldNumber, final int value) {
+ return computeTagSize(fieldNumber) + computeSInt32SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sint64} field, including tag.
+ */
+ public static int computeSInt64Size(final int fieldNumber, final long value) {
+ return computeTagSize(fieldNumber) + computeSInt64SizeNoTag(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * MessageSet extension to the stream. For historical reasons,
+ * the wire format differs from normal fields.
+ */
+// public static int computeMessageSetExtensionSize(
+// final int fieldNumber, final MessageMicro value) {
+// return computeTagSize(WireFormatMicro.MESSAGE_SET_ITEM) * 2 +
+// computeUInt32Size(WireFormatMicro.MESSAGE_SET_TYPE_ID, fieldNumber) +
+// computeMessageSize(WireFormatMicro.MESSAGE_SET_MESSAGE, value);
+// }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * unparsed MessageSet extension field to the stream. For
+ * historical reasons, the wire format differs from normal fields.
+ */
+// public static int computeRawMessageSetExtensionSize(
+// final int fieldNumber, final ByteStringMicro value) {
+// return computeTagSize(WireFormatMicro.MESSAGE_SET_ITEM) * 2 +
+// computeUInt32Size(WireFormatMicro.MESSAGE_SET_TYPE_ID, fieldNumber) +
+// computeBytesSize(WireFormatMicro.MESSAGE_SET_MESSAGE, value);
+// }
+
+ // -----------------------------------------------------------------
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code double} field, including tag.
+ */
+ public static int computeDoubleSizeNoTag(final double value) {
+ return LITTLE_ENDIAN_64_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code float} field, including tag.
+ */
+ public static int computeFloatSizeNoTag(final float value) {
+ return LITTLE_ENDIAN_32_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code uint64} field, including tag.
+ */
+ public static int computeUInt64SizeNoTag(final long value) {
+ return computeRawVarint64Size(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code int64} field, including tag.
+ */
+ public static int computeInt64SizeNoTag(final long value) {
+ return computeRawVarint64Size(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code int32} field, including tag.
+ */
+ public static int computeInt32SizeNoTag(final int value) {
+ if (value >= 0) {
+ return computeRawVarint32Size(value);
+ } else {
+ // Must sign-extend.
+ return 10;
+ }
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code fixed64} field.
+ */
+ public static int computeFixed64SizeNoTag(final long value) {
+ return LITTLE_ENDIAN_64_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code fixed32} field.
+ */
+ public static int computeFixed32SizeNoTag(final int value) {
+ return LITTLE_ENDIAN_32_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code bool} field.
+ */
+ public static int computeBoolSizeNoTag(final boolean value) {
+ return 1;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code string} field.
+ */
+ public static int computeStringSizeNoTag(final String value) {
+ final int length = encodedLength(value);
+ return computeRawVarint32Size(length) + length;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code group} field.
+ */
+ public static int computeGroupSizeNoTag(final MessageNano value) {
+ return value.getSerializedSize();
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an embedded
+ * message field.
+ */
+ public static int computeMessageSizeNoTag(final MessageNano value) {
+ final int size = value.getSerializedSize();
+ return computeRawVarint32Size(size) + size;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code bytes} field.
+ */
+ public static int computeBytesSizeNoTag(final byte[] value) {
+ return computeRawVarint32Size(value.length) + value.length;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a
+ * {@code uint32} field.
+ */
+ public static int computeUInt32SizeNoTag(final int value) {
+ return computeRawVarint32Size(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an enum field.
+ * Caller is responsible for converting the enum value to its numeric value.
+ */
+ public static int computeEnumSizeNoTag(final int value) {
+ return computeRawVarint32Size(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sfixed32} field.
+ */
+ public static int computeSFixed32SizeNoTag(final int value) {
+ return LITTLE_ENDIAN_32_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sfixed64} field.
+ */
+ public static int computeSFixed64SizeNoTag(final long value) {
+ return LITTLE_ENDIAN_64_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sint32} field.
+ */
+ public static int computeSInt32SizeNoTag(final int value) {
+ return computeRawVarint32Size(encodeZigZag32(value));
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an
+ * {@code sint64} field.
+ */
+ public static int computeSInt64SizeNoTag(final long value) {
+ return computeRawVarint64Size(encodeZigZag64(value));
+ }
+
+ // =================================================================
+
+ /**
+ * If writing to a flat array, return the space left in the array.
+ * Otherwise, throws {@code UnsupportedOperationException}.
+ */
+ public int spaceLeft() {
+ return buffer.remaining();
+ }
+
+ /**
+ * Verifies that {@link #spaceLeft()} returns zero. It's common to create
+ * a byte array that is exactly big enough to hold a message, then write to
+ * it with a {@code CodedOutputStream}. Calling {@code checkNoSpaceLeft()}
+ * after writing verifies that the message was actually as big as expected,
+ * which can help catch bugs.
+ */
+ public void checkNoSpaceLeft() {
+ if (spaceLeft() != 0) {
+ throw new IllegalStateException(
+ "Did not write as much data as expected.");
+ }
+ }
+
+ /**
+ * Returns the position within the internal buffer.
+ */
+ public int position() {
+ return buffer.position();
+ }
+
+ /**
+ * Resets the position within the internal buffer to zero.
+ *
+ * @see #position
+ * @see #spaceLeft
+ */
+ public void reset() {
+ buffer.clear();
+ }
+
+ /**
+ * If you create a CodedOutputStream around a simple flat array, you must
+ * not attempt to write more bytes than the array has space. Otherwise,
+ * this exception will be thrown.
+ */
+ public static class OutOfSpaceException extends IOException {
+ private static final long serialVersionUID = -6947486886997889499L;
+
+ OutOfSpaceException(int position, int limit) {
+ super("CodedOutputStream was writing to a flat byte array and ran " +
+ "out of space (pos " + position + " limit " + limit + ").");
+ }
+ }
+
+ /** Write a single byte. */
+ public void writeRawByte(final byte value) throws IOException {
+ if (!buffer.hasRemaining()) {
+ // We're writing to a single buffer.
+ throw new OutOfSpaceException(buffer.position(), buffer.limit());
+ }
+
+ buffer.put(value);
+ }
+
+ /** Write a single byte, represented by an integer value. */
+ public void writeRawByte(final int value) throws IOException {
+ writeRawByte((byte) value);
+ }
+
+ /** Write an array of bytes. */
+ public void writeRawBytes(final byte[] value) throws IOException {
+ writeRawBytes(value, 0, value.length);
+ }
+
+ /** Write part of an array of bytes. */
+ public void writeRawBytes(final byte[] value, int offset, int length)
+ throws IOException {
+ if (buffer.remaining() >= length) {
+ buffer.put(value, offset, length);
+ } else {
+ // We're writing to a single buffer.
+ throw new OutOfSpaceException(buffer.position(), buffer.limit());
+ }
+ }
+
+ /** Encode and write a tag. */
+ public void writeTag(final int fieldNumber, final int wireType)
+ throws IOException {
+ writeRawVarint32(WireFormatNano.makeTag(fieldNumber, wireType));
+ }
+
+ /** Compute the number of bytes that would be needed to encode a tag. */
+ public static int computeTagSize(final int fieldNumber) {
+ return computeRawVarint32Size(WireFormatNano.makeTag(fieldNumber, 0));
+ }
+
+ /**
+ * Encode and write a varint. {@code value} is treated as
+ * unsigned, so it won't be sign-extended if negative.
+ */
+ public void writeRawVarint32(int value) throws IOException {
+ while (true) {
+ if ((value & ~0x7F) == 0) {
+ writeRawByte(value);
+ return;
+ } else {
+ writeRawByte((value & 0x7F) | 0x80);
+ value >>>= 7;
+ }
+ }
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a varint.
+ * {@code value} is treated as unsigned, so it won't be sign-extended if
+ * negative.
+ */
+ public static int computeRawVarint32Size(final int value) {
+ if ((value & (0xffffffff << 7)) == 0) return 1;
+ if ((value & (0xffffffff << 14)) == 0) return 2;
+ if ((value & (0xffffffff << 21)) == 0) return 3;
+ if ((value & (0xffffffff << 28)) == 0) return 4;
+ return 5;
+ }
+
+ /** Encode and write a varint. */
+ public void writeRawVarint64(long value) throws IOException {
+ while (true) {
+ if ((value & ~0x7FL) == 0) {
+ writeRawByte((int)value);
+ return;
+ } else {
+ writeRawByte(((int)value & 0x7F) | 0x80);
+ value >>>= 7;
+ }
+ }
+ }
+
+ /** Compute the number of bytes that would be needed to encode a varint. */
+ public static int computeRawVarint64Size(final long value) {
+ if ((value & (0xffffffffffffffffL << 7)) == 0) return 1;
+ if ((value & (0xffffffffffffffffL << 14)) == 0) return 2;
+ if ((value & (0xffffffffffffffffL << 21)) == 0) return 3;
+ if ((value & (0xffffffffffffffffL << 28)) == 0) return 4;
+ if ((value & (0xffffffffffffffffL << 35)) == 0) return 5;
+ if ((value & (0xffffffffffffffffL << 42)) == 0) return 6;
+ if ((value & (0xffffffffffffffffL << 49)) == 0) return 7;
+ if ((value & (0xffffffffffffffffL << 56)) == 0) return 8;
+ if ((value & (0xffffffffffffffffL << 63)) == 0) return 9;
+ return 10;
+ }
+
+ /** Write a little-endian 32-bit integer. */
+ public void writeRawLittleEndian32(final int value) throws IOException {
+ if (buffer.remaining() < 4) {
+ throw new OutOfSpaceException(buffer.position(), buffer.limit());
+ }
+ buffer.putInt(value);
+ }
+
+ public static final int LITTLE_ENDIAN_32_SIZE = 4;
+
+ /** Write a little-endian 64-bit integer. */
+ public void writeRawLittleEndian64(final long value) throws IOException {
+ if (buffer.remaining() < 8) {
+ throw new OutOfSpaceException(buffer.position(), buffer.limit());
+ }
+ buffer.putLong(value);
+ }
+
+ public static final int LITTLE_ENDIAN_64_SIZE = 8;
+
+ /**
+ * Encode 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 A signed 32-bit integer.
+ * @return An unsigned 32-bit integer, stored in a signed int because
+ * Java has no explicit unsigned support.
+ */
+ public static int encodeZigZag32(final int n) {
+ // Note: the right-shift must be arithmetic
+ return (n << 1) ^ (n >> 31);
+ }
+
+ /**
+ * Encode 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 A signed 64-bit integer.
+ * @return An unsigned 64-bit integer, stored in a signed int because
+ * Java has no explicit unsigned support.
+ */
+ public static long encodeZigZag64(final long n) {
+ // Note: the right-shift must be arithmetic
+ return (n << 1) ^ (n >> 63);
+ }
+
+ static int computeFieldSize(int number, int type, Object object) {
+ switch (type) {
+ case InternalNano.TYPE_BOOL:
+ return computeBoolSize(number, (Boolean) object);
+ case InternalNano.TYPE_BYTES:
+ return computeBytesSize(number, (byte[]) object);
+ case InternalNano.TYPE_STRING:
+ return computeStringSize(number, (String) object);
+ case InternalNano.TYPE_FLOAT:
+ return computeFloatSize(number, (Float) object);
+ case InternalNano.TYPE_DOUBLE:
+ return computeDoubleSize(number, (Double) object);
+ case InternalNano.TYPE_ENUM:
+ return computeEnumSize(number, (Integer) object);
+ case InternalNano.TYPE_FIXED32:
+ return computeFixed32Size(number, (Integer) object);
+ case InternalNano.TYPE_INT32:
+ return computeInt32Size(number, (Integer) object);
+ case InternalNano.TYPE_UINT32:
+ return computeUInt32Size(number, (Integer) object);
+ case InternalNano.TYPE_SINT32:
+ return computeSInt32Size(number, (Integer) object);
+ case InternalNano.TYPE_SFIXED32:
+ return computeSFixed32Size(number, (Integer) object);
+ case InternalNano.TYPE_INT64:
+ return computeInt64Size(number, (Long) object);
+ case InternalNano.TYPE_UINT64:
+ return computeUInt64Size(number, (Long) object);
+ case InternalNano.TYPE_SINT64:
+ return computeSInt64Size(number, (Long) object);
+ case InternalNano.TYPE_FIXED64:
+ return computeFixed64Size(number, (Long) object);
+ case InternalNano.TYPE_SFIXED64:
+ return computeSFixed64Size(number, (Long) object);
+ case InternalNano.TYPE_MESSAGE:
+ return computeMessageSize(number, (MessageNano) object);
+ case InternalNano.TYPE_GROUP:
+ return computeGroupSize(number, (MessageNano) object);
+ default:
+ throw new IllegalArgumentException("Unknown type: " + type);
+ }
+ }
+
+ void writeField(int number, int type, Object value)
+ throws IOException {
+ switch (type) {
+ case InternalNano.TYPE_DOUBLE:
+ Double doubleValue = (Double) value;
+ writeDouble(number, doubleValue);
+ break;
+ case InternalNano.TYPE_FLOAT:
+ Float floatValue = (Float) value;
+ writeFloat(number, floatValue);
+ break;
+ case InternalNano.TYPE_INT64:
+ Long int64Value = (Long) value;
+ writeInt64(number, int64Value);
+ break;
+ case InternalNano.TYPE_UINT64:
+ Long uint64Value = (Long) value;
+ writeUInt64(number, uint64Value);
+ break;
+ case InternalNano.TYPE_INT32:
+ Integer int32Value = (Integer) value;
+ writeInt32(number, int32Value);
+ break;
+ case InternalNano.TYPE_FIXED64:
+ Long fixed64Value = (Long) value;
+ writeFixed64(number, fixed64Value);
+ break;
+ case InternalNano.TYPE_FIXED32:
+ Integer fixed32Value = (Integer) value;
+ writeFixed32(number, fixed32Value);
+ break;
+ case InternalNano.TYPE_BOOL:
+ Boolean boolValue = (Boolean) value;
+ writeBool(number, boolValue);
+ break;
+ case InternalNano.TYPE_STRING:
+ String stringValue = (String) value;
+ writeString(number, stringValue);
+ break;
+ case InternalNano.TYPE_BYTES:
+ byte[] bytesValue = (byte[]) value;
+ writeBytes(number, bytesValue);
+ break;
+ case InternalNano.TYPE_UINT32:
+ Integer uint32Value = (Integer) value;
+ writeUInt32(number, uint32Value);
+ break;
+ case InternalNano.TYPE_ENUM:
+ Integer enumValue = (Integer) value;
+ writeEnum(number, enumValue);
+ break;
+ case InternalNano.TYPE_SFIXED32:
+ Integer sfixed32Value = (Integer) value;
+ writeSFixed32(number, sfixed32Value);
+ break;
+ case InternalNano.TYPE_SFIXED64:
+ Long sfixed64Value = (Long) value;
+ writeSFixed64(number, sfixed64Value);
+ break;
+ case InternalNano.TYPE_SINT32:
+ Integer sint32Value = (Integer) value;
+ writeSInt32(number, sint32Value);
+ break;
+ case InternalNano.TYPE_SINT64:
+ Long sint64Value = (Long) value;
+ writeSInt64(number, sint64Value);
+ break;
+ case InternalNano.TYPE_MESSAGE:
+ MessageNano messageValue = (MessageNano) value;
+ writeMessage(number, messageValue);
+ break;
+ case InternalNano.TYPE_GROUP:
+ MessageNano groupValue = (MessageNano) value;
+ writeGroup(number, groupValue);
+ break;
+ default:
+ throw new IOException("Unknown type: " + type);
+ }
+ }
+
+}
diff --git a/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java
new file mode 100644
index 0000000000..87973d76f0
--- /dev/null
+++ b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/ExtendableMessageNano.java
@@ -0,0 +1,169 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2013 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.nano;
+
+import java.io.IOException;
+
+/**
+ * Base class of those Protocol Buffer messages that need to store unknown fields,
+ * such as extensions.
+ */
+public abstract class ExtendableMessageNano<M extends ExtendableMessageNano<M>>
+ extends MessageNano {
+ /**
+ * A container for fields unknown to the message, including extensions. Extension fields can
+ * can be accessed through the {@link #getExtension} and {@link #setExtension} methods.
+ */
+ protected FieldArray unknownFieldData;
+
+ @Override
+ protected int computeSerializedSize() {
+ int size = 0;
+ if (unknownFieldData != null) {
+ for (int i = 0; i < unknownFieldData.size(); i++) {
+ FieldData field = unknownFieldData.dataAt(i);
+ size += field.computeSerializedSize();
+ }
+ }
+ return size;
+ }
+
+ @Override
+ public void writeTo(CodedOutputByteBufferNano output) throws IOException {
+ if (unknownFieldData == null) {
+ return;
+ }
+ for (int i = 0; i < unknownFieldData.size(); i++) {
+ FieldData field = unknownFieldData.dataAt(i);
+ field.writeTo(output);
+ }
+ }
+
+ /**
+ * Checks if there is a value stored for the specified extension in this
+ * message.
+ */
+ public final boolean hasExtension(Extension<M, ?> extension) {
+ if (unknownFieldData == null) {
+ return false;
+ }
+ FieldData field = unknownFieldData.get(WireFormatNano.getTagFieldNumber(extension.tag));
+ return field != null;
+ }
+
+ /**
+ * Gets the value stored in the specified extension of this message.
+ */
+ public final <T> T getExtension(Extension<M, T> extension) {
+ if (unknownFieldData == null) {
+ return null;
+ }
+ FieldData field = unknownFieldData.get(WireFormatNano.getTagFieldNumber(extension.tag));
+ return field == null ? null : field.getValue(extension);
+ }
+
+ /**
+ * Sets the value of the specified extension of this message.
+ */
+ public final <T> M setExtension(Extension<M, T> extension, T value) {
+ int fieldNumber = WireFormatNano.getTagFieldNumber(extension.tag);
+ if (value == null) {
+ if (unknownFieldData != null) {
+ unknownFieldData.remove(fieldNumber);
+ if (unknownFieldData.isEmpty()) {
+ unknownFieldData = null;
+ }
+ }
+ } else {
+ FieldData field = null;
+ if (unknownFieldData == null) {
+ unknownFieldData = new FieldArray();
+ } else {
+ field = unknownFieldData.get(fieldNumber);
+ }
+ if (field == null) {
+ unknownFieldData.put(fieldNumber, new FieldData(extension, value));
+ } else {
+ field.setValue(extension, value);
+ }
+ }
+
+ @SuppressWarnings("unchecked") // Generated code should guarantee type safety
+ M typedThis = (M) this;
+ return typedThis;
+ }
+
+ /**
+ * Stores the binary data of an unknown field.
+ *
+ * <p>Generated messages will call this for unknown fields if the store_unknown_fields
+ * option is on.
+ *
+ * <p>Note that the tag might be a end-group tag (rather than the start of an unknown field) in
+ * which case we do not want to add an unknown field entry.
+ *
+ * @param input the input buffer.
+ * @param tag the tag of the field.
+
+ * @return {@literal true} unless the tag is an end-group tag.
+ */
+ protected final boolean storeUnknownField(CodedInputByteBufferNano input, int tag)
+ throws IOException {
+ int startPos = input.getPosition();
+ if (!input.skipField(tag)) {
+ return false; // This wasn't an unknown field, it's an end-group tag.
+ }
+ int fieldNumber = WireFormatNano.getTagFieldNumber(tag);
+ int endPos = input.getPosition();
+ byte[] bytes = input.getData(startPos, endPos - startPos);
+ UnknownFieldData unknownField = new UnknownFieldData(tag, bytes);
+
+ FieldData field = null;
+ if (unknownFieldData == null) {
+ unknownFieldData = new FieldArray();
+ } else {
+ field = unknownFieldData.get(fieldNumber);
+ }
+ if (field == null) {
+ field = new FieldData();
+ unknownFieldData.put(fieldNumber, field);
+ }
+ field.addUnknownField(unknownField);
+ return true;
+ }
+
+ @Override
+ public M clone() throws CloneNotSupportedException {
+ M cloned = (M) super.clone();
+ InternalNano.cloneUnknownFieldData(this, cloned);
+ return cloned;
+ }
+}
diff --git a/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/Extension.java b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/Extension.java
new file mode 100644
index 0000000000..c458f9b1fc
--- /dev/null
+++ b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/Extension.java
@@ -0,0 +1,706 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2013 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.nano;
+
+import java.io.IOException;
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Represents an extension.
+ *
+ * @author bduff@google.com (Brian Duff)
+ * @author maxtroy@google.com (Max Cai)
+ * @param <M> the type of the extendable message this extension is for.
+ * @param <T> the Java type of the extension; see {@link #clazz}.
+ */
+public class Extension<M extends ExtendableMessageNano<M>, T> {
+
+ /*
+ * Because we typically only define message-typed extensions, the Extension class hierarchy is
+ * designed as follows, to allow a big amount of code in this file to be removed by ProGuard:
+ *
+ * Extension // ready to use for message/group typed extensions
+ * Δ
+ * |
+ * PrimitiveExtension // for primitive/enum typed extensions
+ */
+
+ public static final int TYPE_DOUBLE = InternalNano.TYPE_DOUBLE;
+ public static final int TYPE_FLOAT = InternalNano.TYPE_FLOAT;
+ public static final int TYPE_INT64 = InternalNano.TYPE_INT64;
+ public static final int TYPE_UINT64 = InternalNano.TYPE_UINT64;
+ public static final int TYPE_INT32 = InternalNano.TYPE_INT32;
+ public static final int TYPE_FIXED64 = InternalNano.TYPE_FIXED64;
+ public static final int TYPE_FIXED32 = InternalNano.TYPE_FIXED32;
+ public static final int TYPE_BOOL = InternalNano.TYPE_BOOL;
+ public static final int TYPE_STRING = InternalNano.TYPE_STRING;
+ public static final int TYPE_GROUP = InternalNano.TYPE_GROUP;
+ public static final int TYPE_MESSAGE = InternalNano.TYPE_MESSAGE;
+ public static final int TYPE_BYTES = InternalNano.TYPE_BYTES;
+ public static final int TYPE_UINT32 = InternalNano.TYPE_UINT32;
+ public static final int TYPE_ENUM = InternalNano.TYPE_ENUM;
+ public static final int TYPE_SFIXED32 = InternalNano.TYPE_SFIXED32;
+ public static final int TYPE_SFIXED64 = InternalNano.TYPE_SFIXED64;
+ public static final int TYPE_SINT32 = InternalNano.TYPE_SINT32;
+ public static final int TYPE_SINT64 = InternalNano.TYPE_SINT64;
+
+ /**
+ * Creates an {@code Extension} of the given message type and tag number.
+ * Should be used by the generated code only.
+ *
+ * @param type {@link #TYPE_MESSAGE} or {@link #TYPE_GROUP}
+ * @deprecated use {@link #createMessageTyped(int, Class, long)} instead.
+ */
+ @Deprecated
+ public static <M extends ExtendableMessageNano<M>, T extends MessageNano>
+ Extension<M, T> createMessageTyped(int type, Class<T> clazz, int tag) {
+ return new Extension<M, T>(type, clazz, tag, false);
+ }
+
+ // Note: these create...() methods take a long for the tag parameter,
+ // because tags are represented as unsigned ints, and these values exist
+ // in generated code as long values. However, they can fit in 32-bits, so
+ // it's safe to cast them to int without loss of precision.
+
+ /**
+ * Creates an {@code Extension} of the given message type and tag number.
+ * Should be used by the generated code only.
+ *
+ * @param type {@link #TYPE_MESSAGE} or {@link #TYPE_GROUP}
+ */
+ public static <M extends ExtendableMessageNano<M>, T extends MessageNano>
+ Extension<M, T> createMessageTyped(int type, Class<T> clazz, long tag) {
+ return new Extension<M, T>(type, clazz, (int) tag, false);
+ }
+
+ /**
+ * Creates a repeated {@code Extension} of the given message type and tag number.
+ * Should be used by the generated code only.
+ *
+ * @param type {@link #TYPE_MESSAGE} or {@link #TYPE_GROUP}
+ */
+ public static <M extends ExtendableMessageNano<M>, T extends MessageNano>
+ Extension<M, T[]> createRepeatedMessageTyped(int type, Class<T[]> clazz, long tag) {
+ return new Extension<M, T[]>(type, clazz, (int) tag, true);
+ }
+
+ /**
+ * Creates an {@code Extension} of the given primitive type and tag number.
+ * Should be used by the generated code only.
+ *
+ * @param type one of {@code TYPE_*}, except {@link #TYPE_MESSAGE} and {@link #TYPE_GROUP}
+ * @param clazz the boxed Java type of this extension
+ */
+ public static <M extends ExtendableMessageNano<M>, T>
+ Extension<M, T> createPrimitiveTyped(int type, Class<T> clazz, long tag) {
+ return new PrimitiveExtension<M, T>(type, clazz, (int) tag, false, 0, 0);
+ }
+
+ /**
+ * Creates a repeated {@code Extension} of the given primitive type and tag number.
+ * Should be used by the generated code only.
+ *
+ * @param type one of {@code TYPE_*}, except {@link #TYPE_MESSAGE} and {@link #TYPE_GROUP}
+ * @param clazz the Java array type of this extension, with an unboxed component type
+ */
+ public static <M extends ExtendableMessageNano<M>, T>
+ Extension<M, T> createRepeatedPrimitiveTyped(
+ int type, Class<T> clazz, long tag, long nonPackedTag, long packedTag) {
+ return new PrimitiveExtension<M, T>(type, clazz, (int) tag, true,
+ (int) nonPackedTag, (int) packedTag);
+ }
+
+ /**
+ * Protocol Buffer type of this extension; one of the {@code TYPE_} constants.
+ */
+ protected final int type;
+
+ /**
+ * Java type of this extension. For a singular extension, this is the boxed Java type for the
+ * Protocol Buffer {@link #type}; for a repeated extension, this is an array type whose
+ * component type is the unboxed Java type for {@link #type}. For example, for a singular
+ * {@code int32}/{@link #TYPE_INT32} extension, this equals {@code Integer.class}; for a
+ * repeated {@code int32} extension, this equals {@code int[].class}.
+ */
+ protected final Class<T> clazz;
+
+ /**
+ * Tag number of this extension. The data should be viewed as an unsigned 32-bit value.
+ */
+ public final int tag;
+
+ /**
+ * Whether this extension is repeated.
+ */
+ protected final boolean repeated;
+
+ private Extension(int type, Class<T> clazz, int tag, boolean repeated) {
+ this.type = type;
+ this.clazz = clazz;
+ this.tag = tag;
+ this.repeated = repeated;
+ }
+
+ /**
+ * Returns the value of this extension stored in the given list of unknown fields, or
+ * {@code null} if no unknown fields matches this extension.
+ *
+ * @param unknownFields a list of {@link UnknownFieldData}. All of the elements must have a tag
+ * that matches this Extension's tag.
+ *
+ */
+ final T getValueFrom(List<UnknownFieldData> unknownFields) {
+ if (unknownFields == null) {
+ return null;
+ }
+ return repeated ? getRepeatedValueFrom(unknownFields) : getSingularValueFrom(unknownFields);
+ }
+
+ private T getRepeatedValueFrom(List<UnknownFieldData> unknownFields) {
+ // For repeated extensions, read all matching unknown fields in their original order.
+ List<Object> resultList = new ArrayList<Object>();
+ for (int i = 0; i < unknownFields.size(); i++) {
+ UnknownFieldData data = unknownFields.get(i);
+ if (data.bytes.length != 0) {
+ readDataInto(data, resultList);
+ }
+ }
+
+ int resultSize = resultList.size();
+ if (resultSize == 0) {
+ return null;
+ } else {
+ T result = clazz.cast(Array.newInstance(clazz.getComponentType(), resultSize));
+ for (int i = 0; i < resultSize; i++) {
+ Array.set(result, i, resultList.get(i));
+ }
+ return result;
+ }
+ }
+
+ private T getSingularValueFrom(List<UnknownFieldData> unknownFields) {
+ // For singular extensions, get the last piece of data stored under this extension.
+ if (unknownFields.isEmpty()) {
+ return null;
+ }
+ UnknownFieldData lastData = unknownFields.get(unknownFields.size() - 1);
+ return clazz.cast(readData(CodedInputByteBufferNano.newInstance(lastData.bytes)));
+ }
+
+ protected Object readData(CodedInputByteBufferNano input) {
+ // This implementation is for message/group extensions.
+ Class<?> messageType = repeated ? clazz.getComponentType() : clazz;
+ try {
+ switch (type) {
+ case TYPE_GROUP:
+ MessageNano group = (MessageNano) messageType.newInstance();
+ input.readGroup(group, WireFormatNano.getTagFieldNumber(tag));
+ return group;
+ case TYPE_MESSAGE:
+ MessageNano message = (MessageNano) messageType.newInstance();
+ input.readMessage(message);
+ return message;
+ default:
+ throw new IllegalArgumentException("Unknown type " + type);
+ }
+ } catch (InstantiationException e) {
+ throw new IllegalArgumentException(
+ "Error creating instance of class " + messageType, e);
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException(
+ "Error creating instance of class " + messageType, e);
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Error reading extension field", e);
+ }
+ }
+
+ protected void readDataInto(UnknownFieldData data, List<Object> resultList) {
+ // This implementation is for message/group extensions.
+ resultList.add(readData(CodedInputByteBufferNano.newInstance(data.bytes)));
+ }
+
+ void writeTo(Object value, CodedOutputByteBufferNano output) throws IOException {
+ if (repeated) {
+ writeRepeatedData(value, output);
+ } else {
+ writeSingularData(value, output);
+ }
+ }
+
+ protected void writeSingularData(Object value, CodedOutputByteBufferNano out) {
+ // This implementation is for message/group extensions.
+ try {
+ out.writeRawVarint32(tag);
+ switch (type) {
+ case TYPE_GROUP:
+ MessageNano groupValue = (MessageNano) value;
+ int fieldNumber = WireFormatNano.getTagFieldNumber(tag);
+ out.writeGroupNoTag(groupValue);
+ // The endgroup tag must be included in the data payload.
+ out.writeTag(fieldNumber, WireFormatNano.WIRETYPE_END_GROUP);
+ break;
+ case TYPE_MESSAGE:
+ MessageNano messageValue = (MessageNano) value;
+ out.writeMessageNoTag(messageValue);
+ break;
+ default:
+ throw new IllegalArgumentException("Unknown type " + type);
+ }
+ } catch (IOException e) {
+ // Should not happen
+ throw new IllegalStateException(e);
+ }
+ }
+
+ protected void writeRepeatedData(Object array, CodedOutputByteBufferNano output) {
+ // This implementation is for non-packed extensions.
+ int arrayLength = Array.getLength(array);
+ for (int i = 0; i < arrayLength; i++) {
+ Object element = Array.get(array, i);
+ if (element != null) {
+ writeSingularData(element, output);
+ }
+ }
+ }
+
+ int computeSerializedSize(Object value) {
+ if (repeated) {
+ return computeRepeatedSerializedSize(value);
+ } else {
+ return computeSingularSerializedSize(value);
+ }
+ }
+
+ protected int computeRepeatedSerializedSize(Object array) {
+ // This implementation is for non-packed extensions.
+ int size = 0;
+ int arrayLength = Array.getLength(array);
+ for (int i = 0; i < arrayLength; i++) {
+ Object element = Array.get(array, i);
+ if (element != null) {
+ size += computeSingularSerializedSize(Array.get(array, i));
+ }
+ }
+ return size;
+ }
+
+ protected int computeSingularSerializedSize(Object value) {
+ // This implementation is for message/group extensions.
+ int fieldNumber = WireFormatNano.getTagFieldNumber(tag);
+ switch (type) {
+ case TYPE_GROUP:
+ MessageNano groupValue = (MessageNano) value;
+ return CodedOutputByteBufferNano.computeGroupSize(fieldNumber, groupValue);
+ case TYPE_MESSAGE:
+ MessageNano messageValue = (MessageNano) value;
+ return CodedOutputByteBufferNano.computeMessageSize(fieldNumber, messageValue);
+ default:
+ throw new IllegalArgumentException("Unknown type " + type);
+ }
+ }
+
+ /**
+ * Represents an extension of a primitive (including enum) type. If there is no primitive
+ * extensions, this subclass will be removable by ProGuard.
+ */
+ private static class PrimitiveExtension<M extends ExtendableMessageNano<M>, T>
+ extends Extension<M, T> {
+
+ /**
+ * Tag of a piece of non-packed data from the wire compatible with this extension.
+ */
+ private final int nonPackedTag;
+
+ /**
+ * Tag of a piece of packed data from the wire compatible with this extension.
+ * 0 if the type of this extension is not packable.
+ */
+ private final int packedTag;
+
+ public PrimitiveExtension(int type, Class<T> clazz, int tag, boolean repeated,
+ int nonPackedTag, int packedTag) {
+ super(type, clazz, tag, repeated);
+ this.nonPackedTag = nonPackedTag;
+ this.packedTag = packedTag;
+ }
+
+ @Override
+ protected Object readData(CodedInputByteBufferNano input) {
+ try {
+ return input.readPrimitiveField(type);
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Error reading extension field", e);
+ }
+ }
+
+ @Override
+ protected void readDataInto(UnknownFieldData data, List<Object> resultList) {
+ // This implementation is for primitive typed extensions,
+ // which can read both packed and non-packed data.
+ if (data.tag == nonPackedTag) {
+ resultList.add(readData(CodedInputByteBufferNano.newInstance(data.bytes)));
+ } else {
+ CodedInputByteBufferNano buffer =
+ CodedInputByteBufferNano.newInstance(data.bytes);
+ try {
+ buffer.pushLimit(buffer.readRawVarint32()); // length limit
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Error reading extension field", e);
+ }
+ while (!buffer.isAtEnd()) {
+ resultList.add(readData(buffer));
+ }
+ }
+ }
+
+ @Override
+ protected final void writeSingularData(Object value, CodedOutputByteBufferNano output) {
+ try {
+ output.writeRawVarint32(tag);
+ switch (type) {
+ case TYPE_DOUBLE:
+ Double doubleValue = (Double) value;
+ output.writeDoubleNoTag(doubleValue);
+ break;
+ case TYPE_FLOAT:
+ Float floatValue = (Float) value;
+ output.writeFloatNoTag(floatValue);
+ break;
+ case TYPE_INT64:
+ Long int64Value = (Long) value;
+ output.writeInt64NoTag(int64Value);
+ break;
+ case TYPE_UINT64:
+ Long uint64Value = (Long) value;
+ output.writeUInt64NoTag(uint64Value);
+ break;
+ case TYPE_INT32:
+ Integer int32Value = (Integer) value;
+ output.writeInt32NoTag(int32Value);
+ break;
+ case TYPE_FIXED64:
+ Long fixed64Value = (Long) value;
+ output.writeFixed64NoTag(fixed64Value);
+ break;
+ case TYPE_FIXED32:
+ Integer fixed32Value = (Integer) value;
+ output.writeFixed32NoTag(fixed32Value);
+ break;
+ case TYPE_BOOL:
+ Boolean boolValue = (Boolean) value;
+ output.writeBoolNoTag(boolValue);
+ break;
+ case TYPE_STRING:
+ String stringValue = (String) value;
+ output.writeStringNoTag(stringValue);
+ break;
+ case TYPE_BYTES:
+ byte[] bytesValue = (byte[]) value;
+ output.writeBytesNoTag(bytesValue);
+ break;
+ case TYPE_UINT32:
+ Integer uint32Value = (Integer) value;
+ output.writeUInt32NoTag(uint32Value);
+ break;
+ case TYPE_ENUM:
+ Integer enumValue = (Integer) value;
+ output.writeEnumNoTag(enumValue);
+ break;
+ case TYPE_SFIXED32:
+ Integer sfixed32Value = (Integer) value;
+ output.writeSFixed32NoTag(sfixed32Value);
+ break;
+ case TYPE_SFIXED64:
+ Long sfixed64Value = (Long) value;
+ output.writeSFixed64NoTag(sfixed64Value);
+ break;
+ case TYPE_SINT32:
+ Integer sint32Value = (Integer) value;
+ output.writeSInt32NoTag(sint32Value);
+ break;
+ case TYPE_SINT64:
+ Long sint64Value = (Long) value;
+ output.writeSInt64NoTag(sint64Value);
+ break;
+ default:
+ throw new IllegalArgumentException("Unknown type " + type);
+ }
+ } catch (IOException e) {
+ // Should not happen
+ throw new IllegalStateException(e);
+ }
+ }
+
+ @Override
+ protected void writeRepeatedData(Object array, CodedOutputByteBufferNano output) {
+ if (tag == nonPackedTag) {
+ // Use base implementation for non-packed data
+ super.writeRepeatedData(array, output);
+ } else if (tag == packedTag) {
+ // Packed. Note that the array element type is guaranteed to be primitive, so there
+ // won't be any null elements, so no null check in this block.
+ int arrayLength = Array.getLength(array);
+ int dataSize = computePackedDataSize(array);
+
+ try {
+ output.writeRawVarint32(tag);
+ output.writeRawVarint32(dataSize);
+ switch (type) {
+ case TYPE_BOOL:
+ for (int i = 0; i < arrayLength; i++) {
+ output.writeBoolNoTag(Array.getBoolean(array, i));
+ }
+ break;
+ case TYPE_FIXED32:
+ for (int i = 0; i < arrayLength; i++) {
+ output.writeFixed32NoTag(Array.getInt(array, i));
+ }
+ break;
+ case TYPE_SFIXED32:
+ for (int i = 0; i < arrayLength; i++) {
+ output.writeSFixed32NoTag(Array.getInt(array, i));
+ }
+ break;
+ case TYPE_FLOAT:
+ for (int i = 0; i < arrayLength; i++) {
+ output.writeFloatNoTag(Array.getFloat(array, i));
+ }
+ break;
+ case TYPE_FIXED64:
+ for (int i = 0; i < arrayLength; i++) {
+ output.writeFixed64NoTag(Array.getLong(array, i));
+ }
+ break;
+ case TYPE_SFIXED64:
+ for (int i = 0; i < arrayLength; i++) {
+ output.writeSFixed64NoTag(Array.getLong(array, i));
+ }
+ break;
+ case TYPE_DOUBLE:
+ for (int i = 0; i < arrayLength; i++) {
+ output.writeDoubleNoTag(Array.getDouble(array, i));
+ }
+ break;
+ case TYPE_INT32:
+ for (int i = 0; i < arrayLength; i++) {
+ output.writeInt32NoTag(Array.getInt(array, i));
+ }
+ break;
+ case TYPE_SINT32:
+ for (int i = 0; i < arrayLength; i++) {
+ output.writeSInt32NoTag(Array.getInt(array, i));
+ }
+ break;
+ case TYPE_UINT32:
+ for (int i = 0; i < arrayLength; i++) {
+ output.writeUInt32NoTag(Array.getInt(array, i));
+ }
+ break;
+ case TYPE_INT64:
+ for (int i = 0; i < arrayLength; i++) {
+ output.writeInt64NoTag(Array.getLong(array, i));
+ }
+ break;
+ case TYPE_SINT64:
+ for (int i = 0; i < arrayLength; i++) {
+ output.writeSInt64NoTag(Array.getLong(array, i));
+ }
+ break;
+ case TYPE_UINT64:
+ for (int i = 0; i < arrayLength; i++) {
+ output.writeUInt64NoTag(Array.getLong(array, i));
+ }
+ break;
+ case TYPE_ENUM:
+ for (int i = 0; i < arrayLength; i++) {
+ output.writeEnumNoTag(Array.getInt(array, i));
+ }
+ break;
+ default:
+ throw new IllegalArgumentException("Unpackable type " + type);
+ }
+ } catch (IOException e) {
+ // Should not happen.
+ throw new IllegalStateException(e);
+ }
+ } else {
+ throw new IllegalArgumentException("Unexpected repeated extension tag " + tag
+ + ", unequal to both non-packed variant " + nonPackedTag
+ + " and packed variant " + packedTag);
+ }
+ }
+
+ private int computePackedDataSize(Object array) {
+ int dataSize = 0;
+ int arrayLength = Array.getLength(array);
+ switch (type) {
+ case TYPE_BOOL:
+ // Bools are stored as int32 but just as 0 or 1, so 1 byte each.
+ dataSize = arrayLength;
+ break;
+ case TYPE_FIXED32:
+ case TYPE_SFIXED32:
+ case TYPE_FLOAT:
+ dataSize = arrayLength * CodedOutputByteBufferNano.LITTLE_ENDIAN_32_SIZE;
+ break;
+ case TYPE_FIXED64:
+ case TYPE_SFIXED64:
+ case TYPE_DOUBLE:
+ dataSize = arrayLength * CodedOutputByteBufferNano.LITTLE_ENDIAN_64_SIZE;
+ break;
+ case TYPE_INT32:
+ for (int i = 0; i < arrayLength; i++) {
+ dataSize += CodedOutputByteBufferNano.computeInt32SizeNoTag(
+ Array.getInt(array, i));
+ }
+ break;
+ case TYPE_SINT32:
+ for (int i = 0; i < arrayLength; i++) {
+ dataSize += CodedOutputByteBufferNano.computeSInt32SizeNoTag(
+ Array.getInt(array, i));
+ }
+ break;
+ case TYPE_UINT32:
+ for (int i = 0; i < arrayLength; i++) {
+ dataSize += CodedOutputByteBufferNano.computeUInt32SizeNoTag(
+ Array.getInt(array, i));
+ }
+ break;
+ case TYPE_INT64:
+ for (int i = 0; i < arrayLength; i++) {
+ dataSize += CodedOutputByteBufferNano.computeInt64SizeNoTag(
+ Array.getLong(array, i));
+ }
+ break;
+ case TYPE_SINT64:
+ for (int i = 0; i < arrayLength; i++) {
+ dataSize += CodedOutputByteBufferNano.computeSInt64SizeNoTag(
+ Array.getLong(array, i));
+ }
+ break;
+ case TYPE_UINT64:
+ for (int i = 0; i < arrayLength; i++) {
+ dataSize += CodedOutputByteBufferNano.computeUInt64SizeNoTag(
+ Array.getLong(array, i));
+ }
+ break;
+ case TYPE_ENUM:
+ for (int i = 0; i < arrayLength; i++) {
+ dataSize += CodedOutputByteBufferNano.computeEnumSizeNoTag(
+ Array.getInt(array, i));
+ }
+ break;
+ default:
+ throw new IllegalArgumentException("Unexpected non-packable type " + type);
+ }
+ return dataSize;
+ }
+
+ @Override
+ protected int computeRepeatedSerializedSize(Object array) {
+ if (tag == nonPackedTag) {
+ // Use base implementation for non-packed data
+ return super.computeRepeatedSerializedSize(array);
+ } else if (tag == packedTag) {
+ // Packed.
+ int dataSize = computePackedDataSize(array);
+ int payloadSize =
+ dataSize + CodedOutputByteBufferNano.computeRawVarint32Size(dataSize);
+ return payloadSize + CodedOutputByteBufferNano.computeRawVarint32Size(tag);
+ } else {
+ throw new IllegalArgumentException("Unexpected repeated extension tag " + tag
+ + ", unequal to both non-packed variant " + nonPackedTag
+ + " and packed variant " + packedTag);
+ }
+ }
+
+ @Override
+ protected final int computeSingularSerializedSize(Object value) {
+ int fieldNumber = WireFormatNano.getTagFieldNumber(tag);
+ switch (type) {
+ case TYPE_DOUBLE:
+ Double doubleValue = (Double) value;
+ return CodedOutputByteBufferNano.computeDoubleSize(fieldNumber, doubleValue);
+ case TYPE_FLOAT:
+ Float floatValue = (Float) value;
+ return CodedOutputByteBufferNano.computeFloatSize(fieldNumber, floatValue);
+ case TYPE_INT64:
+ Long int64Value = (Long) value;
+ return CodedOutputByteBufferNano.computeInt64Size(fieldNumber, int64Value);
+ case TYPE_UINT64:
+ Long uint64Value = (Long) value;
+ return CodedOutputByteBufferNano.computeUInt64Size(fieldNumber, uint64Value);
+ case TYPE_INT32:
+ Integer int32Value = (Integer) value;
+ return CodedOutputByteBufferNano.computeInt32Size(fieldNumber, int32Value);
+ case TYPE_FIXED64:
+ Long fixed64Value = (Long) value;
+ return CodedOutputByteBufferNano.computeFixed64Size(fieldNumber, fixed64Value);
+ case TYPE_FIXED32:
+ Integer fixed32Value = (Integer) value;
+ return CodedOutputByteBufferNano.computeFixed32Size(fieldNumber, fixed32Value);
+ case TYPE_BOOL:
+ Boolean boolValue = (Boolean) value;
+ return CodedOutputByteBufferNano.computeBoolSize(fieldNumber, boolValue);
+ case TYPE_STRING:
+ String stringValue = (String) value;
+ return CodedOutputByteBufferNano.computeStringSize(fieldNumber, stringValue);
+ case TYPE_BYTES:
+ byte[] bytesValue = (byte[]) value;
+ return CodedOutputByteBufferNano.computeBytesSize(fieldNumber, bytesValue);
+ case TYPE_UINT32:
+ Integer uint32Value = (Integer) value;
+ return CodedOutputByteBufferNano.computeUInt32Size(fieldNumber, uint32Value);
+ case TYPE_ENUM:
+ Integer enumValue = (Integer) value;
+ return CodedOutputByteBufferNano.computeEnumSize(fieldNumber, enumValue);
+ case TYPE_SFIXED32:
+ Integer sfixed32Value = (Integer) value;
+ return CodedOutputByteBufferNano.computeSFixed32Size(fieldNumber,
+ sfixed32Value);
+ case TYPE_SFIXED64:
+ Long sfixed64Value = (Long) value;
+ return CodedOutputByteBufferNano.computeSFixed64Size(fieldNumber,
+ sfixed64Value);
+ case TYPE_SINT32:
+ Integer sint32Value = (Integer) value;
+ return CodedOutputByteBufferNano.computeSInt32Size(fieldNumber, sint32Value);
+ case TYPE_SINT64:
+ Long sint64Value = (Long) value;
+ return CodedOutputByteBufferNano.computeSInt64Size(fieldNumber, sint64Value);
+ default:
+ throw new IllegalArgumentException("Unknown type " + type);
+ }
+ }
+ }
+}
diff --git a/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/FieldArray.java b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/FieldArray.java
new file mode 100644
index 0000000000..b49a97fa5a
--- /dev/null
+++ b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/FieldArray.java
@@ -0,0 +1,291 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 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.nano;
+
+
+/**
+ * A custom version of {@code android.util.SparseArray} with the minimal API
+ * for storing {@link FieldData} objects.
+ *
+ * <p>This class is an internal implementation detail of nano and should not
+ * be called directly by clients.
+ *
+ * Based on {@code android.support.v4.util.SpareArrayCompat}.
+ */
+public final class FieldArray implements Cloneable {
+ private static final FieldData DELETED = new FieldData();
+ private boolean mGarbage = false;
+
+ private int[] mFieldNumbers;
+ private FieldData[] mData;
+ private int mSize;
+
+ /**
+ * Creates a new FieldArray containing no fields.
+ */
+ FieldArray() {
+ this(10);
+ }
+
+ /**
+ * Creates a new FieldArray containing no mappings that will not
+ * require any additional memory allocation to store the specified
+ * number of mappings.
+ */
+ FieldArray(int initialCapacity) {
+ initialCapacity = idealIntArraySize(initialCapacity);
+ mFieldNumbers = new int[initialCapacity];
+ mData = new FieldData[initialCapacity];
+ mSize = 0;
+ }
+
+ /**
+ * Gets the FieldData mapped from the specified fieldNumber, or <code>null</code>
+ * if no such mapping has been made.
+ */
+ FieldData get(int fieldNumber) {
+ int i = binarySearch(fieldNumber);
+
+ if (i < 0 || mData[i] == DELETED) {
+ return null;
+ } else {
+ return mData[i];
+ }
+ }
+
+ /**
+ * Removes the data from the specified fieldNumber, if there was any.
+ */
+ void remove(int fieldNumber) {
+ int i = binarySearch(fieldNumber);
+
+ if (i >= 0 && mData[i] != DELETED) {
+ mData[i] = DELETED;
+ mGarbage = true;
+ }
+ }
+
+ private void gc() {
+ int n = mSize;
+ int o = 0;
+ int[] keys = mFieldNumbers;
+ FieldData[] values = mData;
+
+ for (int i = 0; i < n; i++) {
+ FieldData val = values[i];
+
+ if (val != DELETED) {
+ if (i != o) {
+ keys[o] = keys[i];
+ values[o] = val;
+ values[i] = null;
+ }
+
+ o++;
+ }
+ }
+
+ mGarbage = false;
+ mSize = o;
+ }
+
+ /**
+ * Adds a mapping from the specified fieldNumber to the specified data,
+ * replacing the previous mapping if there was one.
+ */
+ void put(int fieldNumber, FieldData data) {
+ int i = binarySearch(fieldNumber);
+
+ if (i >= 0) {
+ mData[i] = data;
+ } else {
+ i = ~i;
+
+ if (i < mSize && mData[i] == DELETED) {
+ mFieldNumbers[i] = fieldNumber;
+ mData[i] = data;
+ return;
+ }
+
+ if (mGarbage && mSize >= mFieldNumbers.length) {
+ gc();
+
+ // Search again because indices may have changed.
+ i = ~ binarySearch(fieldNumber);
+ }
+
+ if (mSize >= mFieldNumbers.length) {
+ int n = idealIntArraySize(mSize + 1);
+
+ int[] nkeys = new int[n];
+ FieldData[] nvalues = new FieldData[n];
+
+ System.arraycopy(mFieldNumbers, 0, nkeys, 0, mFieldNumbers.length);
+ System.arraycopy(mData, 0, nvalues, 0, mData.length);
+
+ mFieldNumbers = nkeys;
+ mData = nvalues;
+ }
+
+ if (mSize - i != 0) {
+ System.arraycopy(mFieldNumbers, i, mFieldNumbers, i + 1, mSize - i);
+ System.arraycopy(mData, i, mData, i + 1, mSize - i);
+ }
+
+ mFieldNumbers[i] = fieldNumber;
+ mData[i] = data;
+ mSize++;
+ }
+ }
+
+ /**
+ * Returns the number of key-value mappings that this FieldArray
+ * currently stores.
+ */
+ int size() {
+ if (mGarbage) {
+ gc();
+ }
+
+ return mSize;
+ }
+
+ public boolean isEmpty() {
+ return size() == 0;
+ }
+
+ /**
+ * Given an index in the range <code>0...size()-1</code>, returns
+ * the value from the <code>index</code>th key-value mapping that this
+ * FieldArray stores.
+ */
+ FieldData dataAt(int index) {
+ if (mGarbage) {
+ gc();
+ }
+
+ return mData[index];
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) {
+ return true;
+ }
+ if (!(o instanceof FieldArray)) {
+ return false;
+ }
+
+ FieldArray other = (FieldArray) o;
+ if (size() != other.size()) { // size() will call gc() if necessary.
+ return false;
+ }
+ return arrayEquals(mFieldNumbers, other.mFieldNumbers, mSize) &&
+ arrayEquals(mData, other.mData, mSize);
+ }
+
+ @Override
+ public int hashCode() {
+ if (mGarbage) {
+ gc();
+ }
+ int result = 17;
+ for (int i = 0; i < mSize; i++) {
+ result = 31 * result + mFieldNumbers[i];
+ result = 31 * result + mData[i].hashCode();
+ }
+ return result;
+ }
+
+ private int idealIntArraySize(int need) {
+ return idealByteArraySize(need * 4) / 4;
+ }
+
+ private int idealByteArraySize(int need) {
+ for (int i = 4; i < 32; i++)
+ if (need <= (1 << i) - 12)
+ return (1 << i) - 12;
+
+ return need;
+ }
+
+ private int binarySearch(int value) {
+ int lo = 0;
+ int hi = mSize - 1;
+
+ while (lo <= hi) {
+ int mid = (lo + hi) >>> 1;
+ int midVal = mFieldNumbers[mid];
+
+ if (midVal < value) {
+ lo = mid + 1;
+ } else if (midVal > value) {
+ hi = mid - 1;
+ } else {
+ return mid; // value found
+ }
+ }
+ return ~lo; // value not present
+ }
+
+ private boolean arrayEquals(int[] a, int[] b, int size) {
+ for (int i = 0; i < size; i++) {
+ if (a[i] != b[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private boolean arrayEquals(FieldData[] a, FieldData[] b, int size) {
+ for (int i = 0; i < size; i++) {
+ if (!a[i].equals(b[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public final FieldArray clone() {
+ // Trigger GC so we compact and don't copy DELETED elements.
+ int size = size();
+ FieldArray clone = new FieldArray(size);
+ System.arraycopy(mFieldNumbers, 0, clone.mFieldNumbers, 0, size);
+ for (int i = 0; i < size; i++) {
+ if (mData[i] != null) {
+ clone.mData[i] = mData[i].clone();
+ }
+ }
+ clone.mSize = size;
+ return clone;
+ }
+}
diff --git a/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/FieldData.java b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/FieldData.java
new file mode 100644
index 0000000000..ebebabc8e5
--- /dev/null
+++ b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/FieldData.java
@@ -0,0 +1,240 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 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.nano;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Stores unknown fields. These might be extensions or fields that the generated API doesn't
+ * know about yet.
+ */
+class FieldData implements Cloneable {
+ private Extension<?, ?> cachedExtension;
+ private Object value;
+ /** The serialised values for this object. Will be cleared if getValue is called */
+ private List<UnknownFieldData> unknownFieldData;
+
+ <T> FieldData(Extension<?, T> extension, T newValue) {
+ cachedExtension = extension;
+ value = newValue;
+ }
+
+ FieldData() {
+ unknownFieldData = new ArrayList<UnknownFieldData>();
+ }
+
+ void addUnknownField(UnknownFieldData unknownField) {
+ unknownFieldData.add(unknownField);
+ }
+
+ UnknownFieldData getUnknownField(int index) {
+ if (unknownFieldData == null) {
+ return null;
+ }
+ if (index < unknownFieldData.size()) {
+ return unknownFieldData.get(index);
+ }
+ return null;
+ }
+
+ int getUnknownFieldSize() {
+ if (unknownFieldData == null) {
+ return 0;
+ }
+ return unknownFieldData.size();
+ }
+
+ <T> T getValue(Extension<?, T> extension) {
+ if (value != null){
+ if (cachedExtension != extension) { // Extension objects are singletons.
+ throw new IllegalStateException(
+ "Tried to getExtension with a differernt Extension.");
+ }
+ } else {
+ cachedExtension = extension;
+ value = extension.getValueFrom(unknownFieldData);
+ unknownFieldData = null;
+ }
+ return (T) value;
+ }
+
+ <T> void setValue(Extension<?, T> extension, T newValue) {
+ cachedExtension = extension;
+ value = newValue;
+ unknownFieldData = null;
+ }
+
+ int computeSerializedSize() {
+ int size = 0;
+ if (value != null) {
+ size = cachedExtension.computeSerializedSize(value);
+ } else {
+ for (UnknownFieldData unknownField : unknownFieldData) {
+ size += unknownField.computeSerializedSize();
+ }
+ }
+ return size;
+ }
+
+ void writeTo(CodedOutputByteBufferNano output) throws IOException {
+ if (value != null) {
+ cachedExtension.writeTo(value, output);
+ } else {
+ for (UnknownFieldData unknownField : unknownFieldData) {
+ unknownField.writeTo(output);
+ }
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) {
+ return true;
+ }
+ if (!(o instanceof FieldData)) {
+ return false;
+ }
+
+ FieldData other = (FieldData) o;
+ if (value != null && other.value != null) {
+ // If both objects have deserialized values, compare those.
+ // Since unknown fields are only compared if messages have generated equals methods
+ // we know this will be a meaningful comparison (not identity) for all values.
+ if (cachedExtension != other.cachedExtension) { // Extension objects are singletons.
+ return false;
+ }
+ if (!cachedExtension.clazz.isArray()) {
+ // Can't test (!cachedExtension.repeated) due to 'bytes' -> 'byte[]'
+ return value.equals(other.value);
+ }
+ if (value instanceof byte[]) {
+ return Arrays.equals((byte[]) value, (byte[]) other.value);
+ } else if (value instanceof int[]) {
+ return Arrays.equals((int[]) value, (int[]) other.value);
+ } else if (value instanceof long[]) {
+ return Arrays.equals((long[]) value, (long[]) other.value);
+ } else if (value instanceof float[]) {
+ return Arrays.equals((float[]) value, (float[]) other.value);
+ } else if (value instanceof double[]) {
+ return Arrays.equals((double[]) value, (double[]) other.value);
+ } else if (value instanceof boolean[]) {
+ return Arrays.equals((boolean[]) value, (boolean[]) other.value);
+ } else {
+ return Arrays.deepEquals((Object[]) value, (Object[]) other.value);
+ }
+ }
+ if (unknownFieldData != null && other.unknownFieldData != null) {
+ // If both objects have byte arrays compare those directly.
+ return unknownFieldData.equals(other.unknownFieldData);
+ }
+ try {
+ // As a last resort, serialize and compare the resulting byte arrays.
+ return Arrays.equals(toByteArray(), other.toByteArray());
+ } catch (IOException e) {
+ // Should not happen.
+ throw new IllegalStateException(e);
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 17;
+ try {
+ // The only way to generate a consistent hash is to use the serialized form.
+ result = 31 * result + Arrays.hashCode(toByteArray());
+ } catch (IOException e) {
+ // Should not happen.
+ throw new IllegalStateException(e);
+ }
+ return result;
+ }
+
+ private byte[] toByteArray() throws IOException {
+ byte[] result = new byte[computeSerializedSize()];
+ CodedOutputByteBufferNano output = CodedOutputByteBufferNano.newInstance(result);
+ writeTo(output);
+ return result;
+ }
+
+ @Override
+ public final FieldData clone() {
+ FieldData clone = new FieldData();
+ try {
+ clone.cachedExtension = cachedExtension;
+ if (unknownFieldData == null) {
+ clone.unknownFieldData = null;
+ } else {
+ clone.unknownFieldData.addAll(unknownFieldData);
+ }
+
+ // Whether we need to deep clone value depends on its type. Primitive reference types
+ // (e.g. Integer, Long etc.) are ok, since they're immutable. We need to clone arrays
+ // and messages.
+ if (value == null) {
+ // No cloning required.
+ } else if (value instanceof MessageNano) {
+ clone.value = ((MessageNano) value).clone();
+ } else if (value instanceof byte[]) {
+ clone.value = ((byte[]) value).clone();
+ } else if (value instanceof byte[][]) {
+ byte[][] valueArray = (byte[][]) value;
+ byte[][] cloneArray = new byte[valueArray.length][];
+ clone.value = cloneArray;
+ for (int i = 0; i < valueArray.length; i++) {
+ cloneArray[i] = valueArray[i].clone();
+ }
+ } else if (value instanceof boolean[]) {
+ clone.value = ((boolean[]) value).clone();
+ } else if (value instanceof int[]) {
+ clone.value = ((int[]) value).clone();
+ } else if (value instanceof long[]) {
+ clone.value = ((long[]) value).clone();
+ } else if (value instanceof float[]) {
+ clone.value = ((float[]) value).clone();
+ } else if (value instanceof double[]) {
+ clone.value = ((double[]) value).clone();
+ } else if (value instanceof MessageNano[]) {
+ MessageNano[] valueArray = (MessageNano[]) value;
+ MessageNano[] cloneArray = new MessageNano[valueArray.length];
+ clone.value = cloneArray;
+ for (int i = 0; i < valueArray.length; i++) {
+ cloneArray[i] = valueArray[i].clone();
+ }
+ }
+ return clone;
+ } catch (CloneNotSupportedException e) {
+ throw new AssertionError(e);
+ }
+ }
+}
diff --git a/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/InternalNano.java b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/InternalNano.java
new file mode 100644
index 0000000000..278368a08b
--- /dev/null
+++ b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/InternalNano.java
@@ -0,0 +1,547 @@
+// 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.nano;
+
+import com.google.protobuf.nano.MapFactories.MapFactory;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * The classes contained within are used internally by the Protocol Buffer
+ * library and generated message implementations. They are public only because
+ * those generated messages do not reside in the {@code protobuf} package.
+ * Others should not use this class directly.
+ *
+ * @author kenton@google.com (Kenton Varda)
+ */
+public final class InternalNano {
+
+ public static final int TYPE_DOUBLE = 1;
+ public static final int TYPE_FLOAT = 2;
+ public static final int TYPE_INT64 = 3;
+ public static final int TYPE_UINT64 = 4;
+ public static final int TYPE_INT32 = 5;
+ public static final int TYPE_FIXED64 = 6;
+ public static final int TYPE_FIXED32 = 7;
+ public static final int TYPE_BOOL = 8;
+ public static final int TYPE_STRING = 9;
+ public static final int TYPE_GROUP = 10;
+ public static final int TYPE_MESSAGE = 11;
+ public static final int TYPE_BYTES = 12;
+ public static final int TYPE_UINT32 = 13;
+ public static final int TYPE_ENUM = 14;
+ public static final int TYPE_SFIXED32 = 15;
+ public static final int TYPE_SFIXED64 = 16;
+ public static final int TYPE_SINT32 = 17;
+ public static final int TYPE_SINT64 = 18;
+
+ static final Charset UTF_8 = Charset.forName("UTF-8");
+ static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
+
+ private InternalNano() {}
+
+ /**
+ * An object to provide synchronization when lazily initializing static fields
+ * of {@link MessageNano} subclasses.
+ * <p>
+ * To enable earlier versions of ProGuard to inline short methods from a
+ * generated MessageNano subclass to the call sites, that class must not have
+ * a class initializer, which will be created if there is any static variable
+ * initializers. To lazily initialize the static variables in a thread-safe
+ * manner, the initialization code will synchronize on this object.
+ */
+ public static final Object LAZY_INIT_LOCK = new Object();
+
+ /**
+ * Helper called by generated code to construct default values for string
+ * fields.
+ * <p>
+ * The protocol compiler does not actually contain a UTF-8 decoder -- it
+ * just pushes UTF-8-encoded text around without touching it. The one place
+ * where this presents a problem is when generating Java string literals.
+ * Unicode characters in the string literal would normally need to be encoded
+ * using a Unicode escape sequence, which would require decoding them.
+ * To get around this, protoc instead embeds the UTF-8 bytes into the
+ * generated code and leaves it to the runtime library to decode them.
+ * <p>
+ * It gets worse, though. If protoc just generated a byte array, like:
+ * new byte[] {0x12, 0x34, 0x56, 0x78}
+ * Java actually generates *code* which allocates an array and then fills
+ * in each value. This is much less efficient than just embedding the bytes
+ * directly into the bytecode. To get around this, we need another
+ * work-around. String literals are embedded directly, so protoc actually
+ * generates a string literal corresponding to the bytes. The easiest way
+ * to do this is to use the ISO-8859-1 character set, which corresponds to
+ * the first 256 characters of the Unicode range. Protoc can then use
+ * good old CEscape to generate the string.
+ * <p>
+ * So we have a string literal which represents a set of bytes which
+ * represents another string. This function -- stringDefaultValue --
+ * converts from the generated string to the string we actually want. The
+ * generated code calls this automatically.
+ */
+ public static String stringDefaultValue(String bytes) {
+ return new String(bytes.getBytes(ISO_8859_1), InternalNano.UTF_8);
+ }
+
+ /**
+ * Helper called by generated code to construct default values for bytes
+ * fields.
+ * <p>
+ * This is a lot like {@link #stringDefaultValue}, but for bytes fields.
+ * In this case we only need the second of the two hacks -- allowing us to
+ * embed raw bytes as a string literal with ISO-8859-1 encoding.
+ */
+ public static byte[] bytesDefaultValue(String bytes) {
+ return bytes.getBytes(ISO_8859_1);
+ }
+
+ /**
+ * Helper function to convert a string into UTF-8 while turning the
+ * UnsupportedEncodingException to a RuntimeException.
+ */
+ public static byte[] copyFromUtf8(final String text) {
+ return text.getBytes(InternalNano.UTF_8);
+ }
+
+ /**
+ * Checks repeated int field equality; null-value and 0-length fields are
+ * considered equal.
+ */
+ public static boolean equals(int[] field1, int[] field2) {
+ if (field1 == null || field1.length == 0) {
+ return field2 == null || field2.length == 0;
+ } else {
+ return Arrays.equals(field1, field2);
+ }
+ }
+
+ /**
+ * Checks repeated long field equality; null-value and 0-length fields are
+ * considered equal.
+ */
+ public static boolean equals(long[] field1, long[] field2) {
+ if (field1 == null || field1.length == 0) {
+ return field2 == null || field2.length == 0;
+ } else {
+ return Arrays.equals(field1, field2);
+ }
+ }
+
+ /**
+ * Checks repeated float field equality; null-value and 0-length fields are
+ * considered equal.
+ */
+ public static boolean equals(float[] field1, float[] field2) {
+ if (field1 == null || field1.length == 0) {
+ return field2 == null || field2.length == 0;
+ } else {
+ return Arrays.equals(field1, field2);
+ }
+ }
+
+ /**
+ * Checks repeated double field equality; null-value and 0-length fields are
+ * considered equal.
+ */
+ public static boolean equals(double[] field1, double[] field2) {
+ if (field1 == null || field1.length == 0) {
+ return field2 == null || field2.length == 0;
+ } else {
+ return Arrays.equals(field1, field2);
+ }
+ }
+
+ /**
+ * Checks repeated boolean field equality; null-value and 0-length fields are
+ * considered equal.
+ */
+ public static boolean equals(boolean[] field1, boolean[] field2) {
+ if (field1 == null || field1.length == 0) {
+ return field2 == null || field2.length == 0;
+ } else {
+ return Arrays.equals(field1, field2);
+ }
+ }
+
+ /**
+ * Checks repeated bytes field equality. Only non-null elements are tested.
+ * Returns true if the two fields have the same sequence of non-null
+ * elements. Null-value fields and fields of any length with only null
+ * elements are considered equal.
+ */
+ public static boolean equals(byte[][] field1, byte[][] field2) {
+ int index1 = 0;
+ int length1 = field1 == null ? 0 : field1.length;
+ int index2 = 0;
+ int length2 = field2 == null ? 0 : field2.length;
+ while (true) {
+ while (index1 < length1 && field1[index1] == null) {
+ index1++;
+ }
+ while (index2 < length2 && field2[index2] == null) {
+ index2++;
+ }
+ boolean atEndOf1 = index1 >= length1;
+ boolean atEndOf2 = index2 >= length2;
+ if (atEndOf1 && atEndOf2) {
+ // no more non-null elements to test in both arrays
+ return true;
+ } else if (atEndOf1 != atEndOf2) {
+ // one of the arrays have extra non-null elements
+ return false;
+ } else if (!Arrays.equals(field1[index1], field2[index2])) {
+ // element mismatch
+ return false;
+ }
+ index1++;
+ index2++;
+ }
+ }
+
+ /**
+ * Checks repeated string/message field equality. Only non-null elements are
+ * tested. Returns true if the two fields have the same sequence of non-null
+ * elements. Null-value fields and fields of any length with only null
+ * elements are considered equal.
+ */
+ public static boolean equals(Object[] field1, Object[] field2) {
+ int index1 = 0;
+ int length1 = field1 == null ? 0 : field1.length;
+ int index2 = 0;
+ int length2 = field2 == null ? 0 : field2.length;
+ while (true) {
+ while (index1 < length1 && field1[index1] == null) {
+ index1++;
+ }
+ while (index2 < length2 && field2[index2] == null) {
+ index2++;
+ }
+ boolean atEndOf1 = index1 >= length1;
+ boolean atEndOf2 = index2 >= length2;
+ if (atEndOf1 && atEndOf2) {
+ // no more non-null elements to test in both arrays
+ return true;
+ } else if (atEndOf1 != atEndOf2) {
+ // one of the arrays have extra non-null elements
+ return false;
+ } else if (!field1[index1].equals(field2[index2])) {
+ // element mismatch
+ return false;
+ }
+ index1++;
+ index2++;
+ }
+ }
+
+ /**
+ * Computes the hash code of a repeated int field. Null-value and 0-length
+ * fields have the same hash code.
+ */
+ public static int hashCode(int[] field) {
+ return field == null || field.length == 0 ? 0 : Arrays.hashCode(field);
+ }
+
+ /**
+ * Computes the hash code of a repeated long field. Null-value and 0-length
+ * fields have the same hash code.
+ */
+ public static int hashCode(long[] field) {
+ return field == null || field.length == 0 ? 0 : Arrays.hashCode(field);
+ }
+
+ /**
+ * Computes the hash code of a repeated float field. Null-value and 0-length
+ * fields have the same hash code.
+ */
+ public static int hashCode(float[] field) {
+ return field == null || field.length == 0 ? 0 : Arrays.hashCode(field);
+ }
+
+ /**
+ * Computes the hash code of a repeated double field. Null-value and 0-length
+ * fields have the same hash code.
+ */
+ public static int hashCode(double[] field) {
+ return field == null || field.length == 0 ? 0 : Arrays.hashCode(field);
+ }
+
+ /**
+ * Computes the hash code of a repeated boolean field. Null-value and 0-length
+ * fields have the same hash code.
+ */
+ public static int hashCode(boolean[] field) {
+ return field == null || field.length == 0 ? 0 : Arrays.hashCode(field);
+ }
+
+ /**
+ * Computes the hash code of a repeated bytes field. Only the sequence of all
+ * non-null elements are used in the computation. Null-value fields and fields
+ * of any length with only null elements have the same hash code.
+ */
+ public static int hashCode(byte[][] field) {
+ int result = 0;
+ for (int i = 0, size = field == null ? 0 : field.length; i < size; i++) {
+ byte[] element = field[i];
+ if (element != null) {
+ result = 31 * result + Arrays.hashCode(element);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Computes the hash code of a repeated string/message field. Only the
+ * sequence of all non-null elements are used in the computation. Null-value
+ * fields and fields of any length with only null elements have the same hash
+ * code.
+ */
+ public static int hashCode(Object[] field) {
+ int result = 0;
+ for (int i = 0, size = field == null ? 0 : field.length; i < size; i++) {
+ Object element = field[i];
+ if (element != null) {
+ result = 31 * result + element.hashCode();
+ }
+ }
+ return result;
+ }
+ private static Object primitiveDefaultValue(int type) {
+ switch (type) {
+ case TYPE_BOOL:
+ return Boolean.FALSE;
+ case TYPE_BYTES:
+ return WireFormatNano.EMPTY_BYTES;
+ case TYPE_STRING:
+ return "";
+ case TYPE_FLOAT:
+ return Float.valueOf(0);
+ case TYPE_DOUBLE:
+ return Double.valueOf(0);
+ case TYPE_ENUM:
+ case TYPE_FIXED32:
+ case TYPE_INT32:
+ case TYPE_UINT32:
+ case TYPE_SINT32:
+ case TYPE_SFIXED32:
+ return Integer.valueOf(0);
+ case TYPE_INT64:
+ case TYPE_UINT64:
+ case TYPE_SINT64:
+ case TYPE_FIXED64:
+ case TYPE_SFIXED64:
+ return Long.valueOf(0L);
+ case TYPE_MESSAGE:
+ case TYPE_GROUP:
+ default:
+ throw new IllegalArgumentException(
+ "Type: " + type + " is not a primitive type.");
+ }
+ }
+
+ /**
+ * Merges the map entry into the map field. Note this is only supposed to
+ * be called by generated messages.
+ *
+ * @param map the map field; may be null, in which case a map will be
+ * instantiated using the {@link MapFactories.MapFactory}
+ * @param input the input byte buffer
+ * @param keyType key type, as defined in InternalNano.TYPE_*
+ * @param valueType value type, as defined in InternalNano.TYPE_*
+ * @param value an new instance of the value, if the value is a TYPE_MESSAGE;
+ * otherwise this parameter can be null and will be ignored.
+ * @param keyTag wire tag for the key
+ * @param valueTag wire tag for the value
+ * @return the map field
+ * @throws IOException
+ */
+ @SuppressWarnings("unchecked")
+ public static final <K, V> Map<K, V> mergeMapEntry(
+ CodedInputByteBufferNano input,
+ Map<K, V> map,
+ MapFactory mapFactory,
+ int keyType,
+ int valueType,
+ V value,
+ int keyTag,
+ int valueTag) throws IOException {
+ map = mapFactory.forMap(map);
+ final int length = input.readRawVarint32();
+ final int oldLimit = input.pushLimit(length);
+ K key = null;
+ while (true) {
+ int tag = input.readTag();
+ if (tag == 0) {
+ break;
+ }
+ if (tag == keyTag) {
+ key = (K) input.readPrimitiveField(keyType);
+ } else if (tag == valueTag) {
+ if (valueType == TYPE_MESSAGE) {
+ input.readMessage((MessageNano) value);
+ } else {
+ value = (V) input.readPrimitiveField(valueType);
+ }
+ } else {
+ if (!input.skipField(tag)) {
+ break;
+ }
+ }
+ }
+ input.checkLastTagWas(0);
+ input.popLimit(oldLimit);
+
+ if (key == null) {
+ // key can only be primitive types.
+ key = (K) primitiveDefaultValue(keyType);
+ }
+
+ if (value == null) {
+ // message type value will be initialized by code-gen.
+ value = (V) primitiveDefaultValue(valueType);
+ }
+
+ map.put(key, value);
+ return map;
+ }
+
+ public static <K, V> void serializeMapField(
+ CodedOutputByteBufferNano output,
+ Map<K, V> map, int number, int keyType, int valueType)
+ throws IOException {
+ for (Entry<K, V> entry: map.entrySet()) {
+ K key = entry.getKey();
+ V value = entry.getValue();
+ if (key == null || value == null) {
+ throw new IllegalStateException(
+ "keys and values in maps cannot be null");
+ }
+ int entrySize =
+ CodedOutputByteBufferNano.computeFieldSize(1, keyType, key) +
+ CodedOutputByteBufferNano.computeFieldSize(2, valueType, value);
+ output.writeTag(number, WireFormatNano.WIRETYPE_LENGTH_DELIMITED);
+ output.writeRawVarint32(entrySize);
+ output.writeField(1, keyType, key);
+ output.writeField(2, valueType, value);
+ }
+ }
+
+ public static <K, V> int computeMapFieldSize(
+ Map<K, V> map, int number, int keyType, int valueType) {
+ int size = 0;
+ int tagSize = CodedOutputByteBufferNano.computeTagSize(number);
+ for (Entry<K, V> entry: map.entrySet()) {
+ K key = entry.getKey();
+ V value = entry.getValue();
+ if (key == null || value == null) {
+ throw new IllegalStateException(
+ "keys and values in maps cannot be null");
+ }
+ int entrySize =
+ CodedOutputByteBufferNano.computeFieldSize(1, keyType, key) +
+ CodedOutputByteBufferNano.computeFieldSize(2, valueType, value);
+ size += tagSize + entrySize
+ + CodedOutputByteBufferNano.computeRawVarint32Size(entrySize);
+ }
+ return size;
+ }
+
+ /**
+ * Checks whether two {@link Map} are equal. We don't use the default equals
+ * method of {@link Map} because it compares by identity not by content for
+ * byte arrays.
+ */
+ public static <K, V> boolean equals(Map<K, V> a, Map<K, V> b) {
+ if (a == b) {
+ return true;
+ }
+ if (a == null) {
+ return b.size() == 0;
+ }
+ if (b == null) {
+ return a.size() == 0;
+ }
+ if (a.size() != b.size()) {
+ return false;
+ }
+ for (Entry<K, V> entry : a.entrySet()) {
+ if (!b.containsKey(entry.getKey())) {
+ return false;
+ }
+ if (!equalsMapValue(entry.getValue(), b.get(entry.getKey()))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static boolean equalsMapValue(Object a, Object b) {
+ if (a == null || b == null) {
+ throw new IllegalStateException(
+ "keys and values in maps cannot be null");
+ }
+ if (a instanceof byte[] && b instanceof byte[]) {
+ return Arrays.equals((byte[]) a, (byte[]) b);
+ }
+ return a.equals(b);
+ }
+
+ public static <K, V> int hashCode(Map<K, V> map) {
+ if (map == null) {
+ return 0;
+ }
+ int result = 0;
+ for (Entry<K, V> entry : map.entrySet()) {
+ result += hashCodeForMap(entry.getKey())
+ ^ hashCodeForMap(entry.getValue());
+ }
+ return result;
+ }
+
+ private static int hashCodeForMap(Object o) {
+ if (o instanceof byte[]) {
+ return Arrays.hashCode((byte[]) o);
+ }
+ return o.hashCode();
+ }
+
+ // This avoids having to make FieldArray public.
+ public static void cloneUnknownFieldData(ExtendableMessageNano original,
+ ExtendableMessageNano cloned) {
+ if (original.unknownFieldData != null) {
+ cloned.unknownFieldData = (FieldArray) original.unknownFieldData.clone();
+ }
+ }
+}
diff --git a/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/InvalidProtocolBufferNanoException.java b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/InvalidProtocolBufferNanoException.java
new file mode 100644
index 0000000000..9a83d6d37c
--- /dev/null
+++ b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/InvalidProtocolBufferNanoException.java
@@ -0,0 +1,93 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2013 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.nano;
+
+import java.io.IOException;
+
+/**
+ * Thrown when a protocol message being parsed is invalid in some way,
+ * e.g. it contains a malformed varint or a negative byte length.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class InvalidProtocolBufferNanoException extends IOException {
+ private static final long serialVersionUID = -1616151763072450476L;
+
+ public InvalidProtocolBufferNanoException(final String description) {
+ super(description);
+ }
+
+ static InvalidProtocolBufferNanoException truncatedMessage() {
+ return new InvalidProtocolBufferNanoException(
+ "While parsing a protocol message, the input ended unexpectedly " +
+ "in the middle of a field. This could mean either that the " +
+ "input has been truncated or that an embedded message " +
+ "misreported its own length.");
+ }
+
+ static InvalidProtocolBufferNanoException negativeSize() {
+ return new InvalidProtocolBufferNanoException(
+ "CodedInputStream encountered an embedded string or message " +
+ "which claimed to have negative size.");
+ }
+
+ static InvalidProtocolBufferNanoException malformedVarint() {
+ return new InvalidProtocolBufferNanoException(
+ "CodedInputStream encountered a malformed varint.");
+ }
+
+ static InvalidProtocolBufferNanoException invalidTag() {
+ return new InvalidProtocolBufferNanoException(
+ "Protocol message contained an invalid tag (zero).");
+ }
+
+ static InvalidProtocolBufferNanoException invalidEndTag() {
+ return new InvalidProtocolBufferNanoException(
+ "Protocol message end-group tag did not match expected tag.");
+ }
+
+ static InvalidProtocolBufferNanoException invalidWireType() {
+ return new InvalidProtocolBufferNanoException(
+ "Protocol message tag had invalid wire type.");
+ }
+
+ static InvalidProtocolBufferNanoException recursionLimitExceeded() {
+ return new InvalidProtocolBufferNanoException(
+ "Protocol message had too many levels of nesting. May be malicious. " +
+ "Use CodedInputStream.setRecursionLimit() to increase the depth limit.");
+ }
+
+ static InvalidProtocolBufferNanoException sizeLimitExceeded() {
+ return new InvalidProtocolBufferNanoException(
+ "Protocol message was too large. May be malicious. " +
+ "Use CodedInputStream.setSizeLimit() to increase the size limit.");
+ }
+}
diff --git a/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/MapFactories.java b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/MapFactories.java
new file mode 100644
index 0000000000..98fa4877bc
--- /dev/null
+++ b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/MapFactories.java
@@ -0,0 +1,67 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2013 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.nano;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Utility class for maps support.
+ */
+public final class MapFactories {
+ public static interface MapFactory {
+ <K, V> Map<K, V> forMap(Map<K, V> oldMap);
+ }
+
+ // NOTE(liujisi): The factory setter is temporarily marked as package private.
+ // The way to provide customized implementations of maps for different
+ // platforms are still under discussion. Mark it as private to avoid exposing
+ // the API in proto3 alpha release.
+ /* public */ static void setMapFactory(MapFactory newMapFactory) {
+ mapFactory = newMapFactory;
+ }
+
+ public static MapFactory getMapFactory() {
+ return mapFactory;
+ }
+
+ private static class DefaultMapFactory implements MapFactory {
+ public <K, V> Map<K, V> forMap(Map<K, V> oldMap) {
+ if (oldMap == null) {
+ return new HashMap<K, V>();
+ }
+ return oldMap;
+ }
+ }
+ private static volatile MapFactory mapFactory = new DefaultMapFactory();
+
+ private MapFactories() {}
+}
diff --git a/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/MessageNano.java b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/MessageNano.java
new file mode 100644
index 0000000000..2347502702
--- /dev/null
+++ b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/MessageNano.java
@@ -0,0 +1,198 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2013 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.nano;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+/**
+ * Abstract interface implemented by Protocol Message objects.
+ *
+ * @author wink@google.com Wink Saville
+ */
+public abstract class MessageNano {
+ protected volatile int cachedSize = -1;
+
+ /**
+ * Get the number of bytes required to encode this message.
+ * Returns the cached size or calls getSerializedSize which
+ * sets the cached size. This is used internally when serializing
+ * so the size is only computed once. If a member is modified
+ * then this could be stale call getSerializedSize if in doubt.
+ */
+ public int getCachedSize() {
+ if (cachedSize < 0) {
+ // getSerializedSize sets cachedSize
+ getSerializedSize();
+ }
+ return cachedSize;
+ }
+
+ /**
+ * Computes the number of bytes required to encode this message.
+ * The size is cached and the cached result can be retrieved
+ * using getCachedSize().
+ */
+ public int getSerializedSize() {
+ int size = computeSerializedSize();
+ cachedSize = size;
+ return size;
+ }
+
+ /**
+ * Computes the number of bytes required to encode this message. This does not update the
+ * cached size.
+ */
+ protected int computeSerializedSize() {
+ // This is overridden if the generated message has serialized fields.
+ return 0;
+ }
+
+ /**
+ * Serializes the message and writes it to {@code output}.
+ *
+ * @param output the output to receive the serialized form.
+ * @throws IOException if an error occurred writing to {@code output}.
+ */
+ public void writeTo(CodedOutputByteBufferNano output) throws IOException {
+ // Does nothing by default. Overridden by subclasses which have data to write.
+ }
+
+ /**
+ * Parse {@code input} as a message of this type and merge it with the
+ * message being built.
+ */
+ public abstract MessageNano mergeFrom(CodedInputByteBufferNano input) throws IOException;
+
+ /**
+ * Serialize to a byte array.
+ * @return byte array with the serialized data.
+ */
+ public static final byte[] toByteArray(MessageNano msg) {
+ final byte[] result = new byte[msg.getSerializedSize()];
+ toByteArray(msg, result, 0, result.length);
+ return result;
+ }
+
+ /**
+ * Serialize to a byte array starting at offset through length. The
+ * method getSerializedSize must have been called prior to calling
+ * this method so the proper length is know. If an attempt to
+ * write more than length bytes OutOfSpaceException will be thrown
+ * and if length bytes are not written then IllegalStateException
+ * is thrown.
+ */
+ public static final void toByteArray(MessageNano msg, byte[] data, int offset, int length) {
+ try {
+ final CodedOutputByteBufferNano output =
+ CodedOutputByteBufferNano.newInstance(data, offset, length);
+ msg.writeTo(output);
+ output.checkNoSpaceLeft();
+ } catch (IOException e) {
+ throw new RuntimeException("Serializing to a byte array threw an IOException "
+ + "(should never happen).", e);
+ }
+ }
+
+ /**
+ * Parse {@code data} as a message of this type and merge it with the
+ * message being built.
+ */
+ public static final <T extends MessageNano> T mergeFrom(T msg, final byte[] data)
+ throws InvalidProtocolBufferNanoException {
+ return mergeFrom(msg, data, 0, data.length);
+ }
+
+ /**
+ * Parse {@code data} as a message of this type and merge it with the
+ * message being built.
+ */
+ public static final <T extends MessageNano> T mergeFrom(T msg, final byte[] data,
+ final int off, final int len) throws InvalidProtocolBufferNanoException {
+ try {
+ final CodedInputByteBufferNano input =
+ CodedInputByteBufferNano.newInstance(data, off, len);
+ msg.mergeFrom(input);
+ input.checkLastTagWas(0);
+ return msg;
+ } catch (InvalidProtocolBufferNanoException e) {
+ throw e;
+ } catch (IOException e) {
+ throw new RuntimeException("Reading from a byte array threw an IOException (should "
+ + "never happen).");
+ }
+ }
+
+ /**
+ * Compares two {@code MessageNano}s and returns true if the message's are the same class and
+ * have serialized form equality (i.e. all of the field values are the same).
+ */
+ public static final boolean messageNanoEquals(MessageNano a, MessageNano b) {
+ if (a == b) {
+ return true;
+ }
+ if (a == null || b == null) {
+ return false;
+ }
+ if (a.getClass() != b.getClass()) {
+ return false;
+ }
+ final int serializedSize = a.getSerializedSize();
+ if (b.getSerializedSize() != serializedSize) {
+ return false;
+ }
+ final byte[] aByteArray = new byte[serializedSize];
+ final byte[] bByteArray = new byte[serializedSize];
+ toByteArray(a, aByteArray, 0, serializedSize);
+ toByteArray(b, bByteArray, 0, serializedSize);
+ return Arrays.equals(aByteArray, bByteArray);
+ }
+
+ /**
+ * Returns a string that is (mostly) compatible with ProtoBuffer's TextFormat. Note that groups
+ * (which are deprecated) are not serialized with the correct field name.
+ *
+ * <p>This is implemented using reflection, so it is not especially fast nor is it guaranteed
+ * to find all fields if you have method removal turned on for proguard.
+ */
+ @Override
+ public String toString() {
+ return MessageNanoPrinter.print(this);
+ }
+
+ /**
+ * Provides support for cloning. This only works if you specify the generate_clone method.
+ */
+ @Override
+ public MessageNano clone() throws CloneNotSupportedException {
+ return (MessageNano) super.clone();
+ }
+}
diff --git a/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/MessageNanoPrinter.java b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/MessageNanoPrinter.java
new file mode 100644
index 0000000000..5f329f02fb
--- /dev/null
+++ b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/MessageNanoPrinter.java
@@ -0,0 +1,275 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2013 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.nano;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Map;
+
+/**
+ * Static helper methods for printing nano protos.
+ *
+ * @author flynn@google.com Andrew Flynn
+ */
+public final class MessageNanoPrinter {
+ // Do not allow instantiation
+ private MessageNanoPrinter() {}
+
+ private static final String INDENT = " ";
+ private static final int MAX_STRING_LEN = 200;
+
+ /**
+ * Returns an text representation of a MessageNano suitable for debugging. The returned string
+ * is mostly compatible with Protocol Buffer's TextFormat (as provided by non-nano protocol
+ * buffers) -- groups (which are deprecated) are output with an underscore name (e.g. foo_bar
+ * instead of FooBar) and will thus not parse.
+ *
+ * <p>Employs Java reflection on the given object and recursively prints primitive fields,
+ * groups, and messages.</p>
+ */
+ public static <T extends MessageNano> String print(T message) {
+ if (message == null) {
+ return "";
+ }
+
+ StringBuffer buf = new StringBuffer();
+ try {
+ print(null, message, new StringBuffer(), buf);
+ } catch (IllegalAccessException e) {
+ return "Error printing proto: " + e.getMessage();
+ } catch (InvocationTargetException e) {
+ return "Error printing proto: " + e.getMessage();
+ }
+ return buf.toString();
+ }
+
+ /**
+ * Function that will print the given message/field into the StringBuffer.
+ * Meant to be called recursively.
+ *
+ * @param identifier the identifier to use, or {@code null} if this is the root message to
+ * print.
+ * @param object the value to print. May in fact be a primitive value or byte array and not a
+ * message.
+ * @param indentBuf the indentation each line should begin with.
+ * @param buf the output buffer.
+ */
+ private static void print(String identifier, Object object,
+ StringBuffer indentBuf, StringBuffer buf) throws IllegalAccessException,
+ InvocationTargetException {
+ if (object == null) {
+ // This can happen if...
+ // - we're about to print a message, String, or byte[], but it not present;
+ // - we're about to print a primitive, but "reftype" optional style is enabled, and
+ // the field is unset.
+ // In both cases the appropriate behavior is to output nothing.
+ } else if (object instanceof MessageNano) { // Nano proto message
+ int origIndentBufLength = indentBuf.length();
+ if (identifier != null) {
+ buf.append(indentBuf).append(deCamelCaseify(identifier)).append(" <\n");
+ indentBuf.append(INDENT);
+ }
+ Class<?> clazz = object.getClass();
+
+ // Proto fields follow one of two formats:
+ //
+ // 1) Public, non-static variables that do not begin or end with '_'
+ // Find and print these using declared public fields
+ for (Field field : clazz.getFields()) {
+ int modifiers = field.getModifiers();
+ String fieldName = field.getName();
+ if ("cachedSize".equals(fieldName)) {
+ // TODO(bduff): perhaps cachedSize should have a more obscure name.
+ continue;
+ }
+
+ if ((modifiers & Modifier.PUBLIC) == Modifier.PUBLIC
+ && (modifiers & Modifier.STATIC) != Modifier.STATIC
+ && !fieldName.startsWith("_")
+ && !fieldName.endsWith("_")) {
+ Class<?> fieldType = field.getType();
+ Object value = field.get(object);
+
+ if (fieldType.isArray()) {
+ Class<?> arrayType = fieldType.getComponentType();
+
+ // bytes is special since it's not repeated, but is represented by an array
+ if (arrayType == byte.class) {
+ print(fieldName, value, indentBuf, buf);
+ } else {
+ int len = value == null ? 0 : Array.getLength(value);
+ for (int i = 0; i < len; i++) {
+ Object elem = Array.get(value, i);
+ print(fieldName, elem, indentBuf, buf);
+ }
+ }
+ } else {
+ print(fieldName, value, indentBuf, buf);
+ }
+ }
+ }
+
+ // 2) Fields that are accessed via getter methods (when accessors
+ // mode is turned on)
+ // Find and print these using getter methods.
+ for (Method method : clazz.getMethods()) {
+ String name = method.getName();
+ // Check for the setter accessor method since getters and hazzers both have
+ // non-proto-field name collisions (hashCode() and getSerializedSize())
+ if (name.startsWith("set")) {
+ String subfieldName = name.substring(3);
+
+ Method hazzer = null;
+ try {
+ hazzer = clazz.getMethod("has" + subfieldName);
+ } catch (NoSuchMethodException e) {
+ continue;
+ }
+ // If hazzer doesn't exist or returns false, no need to continue
+ if (!(Boolean) hazzer.invoke(object)) {
+ continue;
+ }
+
+ Method getter = null;
+ try {
+ getter = clazz.getMethod("get" + subfieldName);
+ } catch (NoSuchMethodException e) {
+ continue;
+ }
+
+ print(subfieldName, getter.invoke(object), indentBuf, buf);
+ }
+ }
+ if (identifier != null) {
+ indentBuf.setLength(origIndentBufLength);
+ buf.append(indentBuf).append(">\n");
+ }
+ } else if (object instanceof Map) {
+ Map<?,?> map = (Map<?,?>) object;
+ identifier = deCamelCaseify(identifier);
+
+ for (Map.Entry<?,?> entry : map.entrySet()) {
+ buf.append(indentBuf).append(identifier).append(" <\n");
+ int origIndentBufLength = indentBuf.length();
+ indentBuf.append(INDENT);
+ print("key", entry.getKey(), indentBuf, buf);
+ print("value", entry.getValue(), indentBuf, buf);
+ indentBuf.setLength(origIndentBufLength);
+ buf.append(indentBuf).append(">\n");
+ }
+ } else {
+ // Non-null primitive value
+ identifier = deCamelCaseify(identifier);
+ buf.append(indentBuf).append(identifier).append(": ");
+ if (object instanceof String) {
+ String stringMessage = sanitizeString((String) object);
+ buf.append("\"").append(stringMessage).append("\"");
+ } else if (object instanceof byte[]) {
+ appendQuotedBytes((byte[]) object, buf);
+ } else {
+ buf.append(object);
+ }
+ buf.append("\n");
+ }
+ }
+
+ /**
+ * Converts an identifier of the format "FieldName" into "field_name".
+ */
+ private static String deCamelCaseify(String identifier) {
+ StringBuffer out = new StringBuffer();
+ for (int i = 0; i < identifier.length(); i++) {
+ char currentChar = identifier.charAt(i);
+ if (i == 0) {
+ out.append(Character.toLowerCase(currentChar));
+ } else if (Character.isUpperCase(currentChar)) {
+ out.append('_').append(Character.toLowerCase(currentChar));
+ } else {
+ out.append(currentChar);
+ }
+ }
+ return out.toString();
+ }
+
+ /**
+ * Shortens and escapes the given string.
+ */
+ private static String sanitizeString(String str) {
+ if (!str.startsWith("http") && str.length() > MAX_STRING_LEN) {
+ // Trim non-URL strings.
+ str = str.substring(0, MAX_STRING_LEN) + "[...]";
+ }
+ return escapeString(str);
+ }
+
+ /**
+ * Escape everything except for low ASCII code points.
+ */
+ private static String escapeString(String str) {
+ int strLen = str.length();
+ StringBuilder b = new StringBuilder(strLen);
+ for (int i = 0; i < strLen; i++) {
+ char original = str.charAt(i);
+ if (original >= ' ' && original <= '~' && original != '"' && original != '\'') {
+ b.append(original);
+ } else {
+ b.append(String.format("\\u%04x", (int) original));
+ }
+ }
+ return b.toString();
+ }
+
+ /**
+ * Appends a quoted byte array to the provided {@code StringBuffer}.
+ */
+ private static void appendQuotedBytes(byte[] bytes, StringBuffer builder) {
+ if (bytes == null) {
+ builder.append("\"\"");
+ return;
+ }
+
+ builder.append('"');
+ for (int i = 0; i < bytes.length; ++i) {
+ int ch = bytes[i] & 0xff;
+ if (ch == '\\' || ch == '"') {
+ builder.append('\\').append((char) ch);
+ } else if (ch >= 32 && ch < 127) {
+ builder.append((char) ch);
+ } else {
+ builder.append(String.format("\\%03o", ch));
+ }
+ }
+ builder.append('"');
+ }
+}
diff --git a/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/UnknownFieldData.java b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/UnknownFieldData.java
new file mode 100644
index 0000000000..b1678d1b93
--- /dev/null
+++ b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/UnknownFieldData.java
@@ -0,0 +1,88 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2013 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.nano;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+/**
+ * Stores unknown fields. These might be extensions or fields that the generated
+ * API doesn't know about yet.
+ *
+ * @author bduff@google.com (Brian Duff)
+ */
+final class UnknownFieldData {
+
+ final int tag;
+ /**
+ * Important: this should be treated as immutable, even though it's possible
+ * to change the array values.
+ */
+ final byte[] bytes;
+
+ UnknownFieldData(int tag, byte[] bytes) {
+ this.tag = tag;
+ this.bytes = bytes;
+ }
+
+ int computeSerializedSize() {
+ int size = 0;
+ size += CodedOutputByteBufferNano.computeRawVarint32Size(tag);
+ size += bytes.length;
+ return size;
+ }
+
+ void writeTo(CodedOutputByteBufferNano output) throws IOException {
+ output.writeRawVarint32(tag);
+ output.writeRawBytes(bytes);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) {
+ return true;
+ }
+ if (!(o instanceof UnknownFieldData)) {
+ return false;
+ }
+
+ UnknownFieldData other = (UnknownFieldData) o;
+ return tag == other.tag && Arrays.equals(bytes, other.bytes);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 17;
+ result = 31 * result + tag;
+ result = 31 * result + Arrays.hashCode(bytes);
+ return result;
+ }
+}
diff --git a/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/WireFormatNano.java b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/WireFormatNano.java
new file mode 100644
index 0000000000..bbb6370a3e
--- /dev/null
+++ b/third_party/protobuf/javanano/src/main/java/com/google/protobuf/nano/WireFormatNano.java
@@ -0,0 +1,124 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2013 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.nano;
+
+import java.io.IOException;
+
+/**
+ * This class is used internally by the Protocol Buffer library and generated
+ * message implementations. It is public only because those generated messages
+ * do not reside in the {@code protobuf} package. Others should not use this
+ * class directly.
+ *
+ * This class contains constants and helper functions useful for dealing with
+ * the Protocol Buffer wire format.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public final class WireFormatNano {
+ // Do not allow instantiation.
+ private WireFormatNano() {}
+
+ static final int WIRETYPE_VARINT = 0;
+ static final int WIRETYPE_FIXED64 = 1;
+ static final int WIRETYPE_LENGTH_DELIMITED = 2;
+ static final int WIRETYPE_START_GROUP = 3;
+ static final int WIRETYPE_END_GROUP = 4;
+ static final int WIRETYPE_FIXED32 = 5;
+
+ static final int TAG_TYPE_BITS = 3;
+ static final int TAG_TYPE_MASK = (1 << TAG_TYPE_BITS) - 1;
+
+ /** Given a tag value, determines the wire type (the lower 3 bits). */
+ static int getTagWireType(final int tag) {
+ return tag & TAG_TYPE_MASK;
+ }
+
+ /** Given a tag value, determines the field number (the upper 29 bits). */
+ public static int getTagFieldNumber(final int tag) {
+ return tag >>> TAG_TYPE_BITS;
+ }
+
+ /** Makes a tag value given a field number and wire type. */
+ static int makeTag(final int fieldNumber, final int wireType) {
+ return (fieldNumber << TAG_TYPE_BITS) | wireType;
+ }
+
+ public static final int EMPTY_INT_ARRAY[] = {};
+ public static final long EMPTY_LONG_ARRAY[] = {};
+ public static final float EMPTY_FLOAT_ARRAY[] = {};
+ public static final double EMPTY_DOUBLE_ARRAY[] = {};
+ public static final boolean EMPTY_BOOLEAN_ARRAY[] = {};
+ public static final String EMPTY_STRING_ARRAY[] = {};
+ public static final byte[] EMPTY_BYTES_ARRAY[] = {};
+ public static final byte[] EMPTY_BYTES = {};
+
+ /**
+ * Parses an unknown field. This implementation skips the field.
+ *
+ * <p>Generated messages will call this for unknown fields if the store_unknown_fields
+ * option is off.
+ *
+ * @return {@literal true} unless the tag is an end-group tag.
+ */
+ public static boolean parseUnknownField(
+ final CodedInputByteBufferNano input,
+ final int tag) throws IOException {
+ return input.skipField(tag);
+ }
+
+ /**
+ * Computes the array length of a repeated field. We assume that in the common case repeated
+ * fields are contiguously serialized but we still correctly handle interspersed values of a
+ * repeated field (but with extra allocations).
+ *
+ * Rewinds to current input position before returning.
+ *
+ * @param input stream input, pointing to the byte after the first tag
+ * @param tag repeated field tag just read
+ * @return length of array
+ * @throws IOException
+ */
+ public static final int getRepeatedFieldArrayLength(
+ final CodedInputByteBufferNano input,
+ final int tag) throws IOException {
+ int arrayLength = 1;
+ int startPos = input.getPosition();
+ input.skipField(tag);
+ while (input.readTag() == tag) {
+ input.skipField(tag);
+ arrayLength++;
+ }
+ input.rewindToPosition(startPos);
+ return arrayLength;
+ }
+
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java
new file mode 100644
index 0000000000..4d6e7f0903
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java
@@ -0,0 +1,4471 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2013 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.nano;
+
+import com.google.protobuf.nano.CodedOutputByteBufferNano;
+import com.google.protobuf.nano.EnumClassNanos.EnumClassNano;
+import com.google.protobuf.nano.EnumClassNanos.EnumClassNano.MessageScopeEnum;
+import com.google.protobuf.nano.EnumClassNanos.FileScopeEnum;
+import com.google.protobuf.nano.MapTestProto.TestMap;
+import com.google.protobuf.nano.MapTestProto.TestMap.MessageValue;
+import com.google.protobuf.nano.NanoAccessorsOuterClass.TestNanoAccessors;
+import com.google.protobuf.nano.NanoHasOuterClass.TestAllTypesNanoHas;
+import com.google.protobuf.nano.NanoOuterClass.TestAllTypesNano;
+import com.google.protobuf.nano.UnittestRecursiveNano.RecursiveMessageNano;
+import com.google.protobuf.nano.NanoReferenceTypesCompat;
+import com.google.protobuf.nano.UnittestSimpleNano.SimpleMessageNano;
+import com.google.protobuf.nano.UnittestSingleNano.SingleMessageNano;
+import com.google.protobuf.nano.testext.nano.Extensions;
+import com.google.protobuf.nano.testext.nano.Extensions.AnotherMessage;
+import com.google.protobuf.nano.testext.nano.Extensions.MessageWithGroup;
+import com.google.protobuf.nano.testimport.nano.UnittestImportNano;
+
+import junit.framework.TestCase;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * Test nano runtime.
+ *
+ * @author ulas@google.com Ulas Kirazci
+ */
+public class NanoTest extends TestCase {
+ @Override
+ public void setUp() throws Exception {
+ }
+
+ public void testSimpleMessageNano() throws Exception {
+ SimpleMessageNano msg = new SimpleMessageNano();
+ assertEquals(123, msg.d);
+ assertEquals(null, msg.nestedMsg);
+ assertEquals(SimpleMessageNano.BAZ, msg.defaultNestedEnum);
+
+ msg.d = 456;
+ assertEquals(456, msg.d);
+
+ SimpleMessageNano.NestedMessage nestedMsg = new SimpleMessageNano.NestedMessage();
+ nestedMsg.bb = 2;
+ assertEquals(2, nestedMsg.bb);
+ msg.nestedMsg = nestedMsg;
+ assertEquals(2, msg.nestedMsg.bb);
+
+ msg.defaultNestedEnum = SimpleMessageNano.BAR;
+ assertEquals(SimpleMessageNano.BAR, msg.defaultNestedEnum);
+
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 9);
+ assertEquals(result.length, msgSerializedSize);
+
+ SimpleMessageNano newMsg = SimpleMessageNano.parseFrom(result);
+ assertEquals(456, newMsg.d);
+ assertEquals(2, msg.nestedMsg.bb);
+ assertEquals(SimpleMessageNano.BAR, msg.defaultNestedEnum);
+
+ msg.nestedMsg = null;
+ assertTrue(msgSerializedSize != msg.getSerializedSize());
+
+ msg.clear();
+ assertEquals(0, msg.getSerializedSize());
+ }
+
+ public void testRecursiveMessageNano() throws Exception {
+ RecursiveMessageNano msg = new RecursiveMessageNano();
+ assertTrue(msg.repeatedRecursiveMessageNano.length == 0);
+
+ RecursiveMessageNano msg1 = new RecursiveMessageNano();
+ msg1.id = 1;
+ assertEquals(1, msg1.id);
+ RecursiveMessageNano msg2 = new RecursiveMessageNano();
+ msg2.id = 2;
+ RecursiveMessageNano msg3 = new RecursiveMessageNano();
+ msg3.id = 3;
+
+ RecursiveMessageNano.NestedMessage nestedMsg = new RecursiveMessageNano.NestedMessage();
+ nestedMsg.a = msg1;
+ assertEquals(1, nestedMsg.a.id);
+
+ msg.id = 0;
+ msg.nestedMessage = nestedMsg;
+ msg.optionalRecursiveMessageNano = msg2;
+ msg.repeatedRecursiveMessageNano = new RecursiveMessageNano[] { msg3 };
+
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 16);
+ assertEquals(result.length, msgSerializedSize);
+
+ RecursiveMessageNano newMsg = RecursiveMessageNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedRecursiveMessageNano.length);
+
+ assertEquals(0, newMsg.id);
+ assertEquals(1, newMsg.nestedMessage.a.id);
+ assertEquals(2, newMsg.optionalRecursiveMessageNano.id);
+ assertEquals(3, newMsg.repeatedRecursiveMessageNano[0].id);
+ }
+
+ public void testMessageNoFields() {
+ SingleMessageNano msg = new SingleMessageNano();
+ assertEquals(0, msg.getSerializedSize());
+ assertEquals(0, MessageNano.toByteArray(msg).length);
+ }
+
+ public void testNanoRequiredInt32() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.id = 123;
+ assertEquals(123, msg.id);
+ msg.clear().id = 456;
+ assertEquals(456, msg.id);
+ msg.clear();
+
+ msg.id = 123;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 3);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(123, newMsg.id);
+ }
+
+ public void testNanoOptionalInt32() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalInt32 = 123;
+ assertEquals(123, msg.optionalInt32);
+ msg.clear()
+ .optionalInt32 = 456;
+ assertEquals(456, msg.optionalInt32);
+ msg.clear();
+
+ msg.optionalInt32 = 123;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 5);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(123, newMsg.optionalInt32);
+ }
+
+ public void testNanoOptionalInt64() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalInt64 = 123;
+ assertEquals(123, msg.optionalInt64);
+ msg.clear()
+ .optionalInt64 = 456;
+ assertEquals(456, msg.optionalInt64);
+ msg.clear();
+ assertEquals(0, msg.optionalInt64);
+
+ msg.optionalInt64 = 123;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 5);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(123, newMsg.optionalInt64);
+ }
+
+ public void testNanoOptionalUint32() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalUint32 = 123;
+ assertEquals(123, msg.optionalUint32);
+ msg.clear()
+ .optionalUint32 = 456;
+ assertEquals(456, msg.optionalUint32);
+ msg.clear();
+ assertEquals(0, msg.optionalUint32);
+
+ msg.optionalUint32 = 123;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 5);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(123, newMsg.optionalUint32);
+ }
+
+ public void testNanoOptionalUint64() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalUint64 = 123;
+ assertEquals(123, msg.optionalUint64);
+ msg.clear()
+ .optionalUint64 = 456;
+ assertEquals(456, msg.optionalUint64);
+ msg.clear();
+ assertEquals(0, msg.optionalUint64);
+
+ msg.optionalUint64 = 123;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 5);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(123, newMsg.optionalUint64);
+ }
+
+ public void testNanoOptionalSint32() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalSint32 = 123;
+ assertEquals(123, msg.optionalSint32);
+ msg.clear()
+ .optionalSint32 = 456;
+ assertEquals(456, msg.optionalSint32);
+ msg.clear();
+ assertEquals(0, msg.optionalSint32);
+
+ msg.optionalSint32 = -123;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(-123, newMsg.optionalSint32);
+ }
+
+ public void testNanoOptionalSint64() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalSint64 = 123;
+ assertEquals(123, msg.optionalSint64);
+ msg.clear()
+ .optionalSint64 = 456;
+ assertEquals(456, msg.optionalSint64);
+ msg.clear();
+ assertEquals(0, msg.optionalSint64);
+
+ msg.optionalSint64 = -123;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(-123, newMsg.optionalSint64);
+ }
+
+ public void testNanoOptionalFixed32() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalFixed32 = 123;
+ assertEquals(123, msg.optionalFixed32);
+ msg.clear()
+ .optionalFixed32 = 456;
+ assertEquals(456, msg.optionalFixed32);
+ msg.clear();
+ assertEquals(0, msg.optionalFixed32);
+
+ msg.optionalFixed32 = 123;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 8);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(123, newMsg.optionalFixed32);
+ }
+
+ public void testNanoOptionalFixed64() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalFixed64 = 123;
+ assertEquals(123, msg.optionalFixed64);
+ msg.clear()
+ .optionalFixed64 = 456;
+ assertEquals(456, msg.optionalFixed64);
+ msg.clear();
+ assertEquals(0, msg.optionalFixed64);
+
+ msg.optionalFixed64 = 123;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 12);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(123, newMsg.optionalFixed64);
+ }
+
+ public void testNanoOptionalSfixed32() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalSfixed32 = 123;
+ assertEquals(123, msg.optionalSfixed32);
+ msg.clear()
+ .optionalSfixed32 = 456;
+ assertEquals(456, msg.optionalSfixed32);
+ msg.clear();
+ assertEquals(0, msg.optionalSfixed32);
+
+ msg.optionalSfixed32 = 123;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 8);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(123, newMsg.optionalSfixed32);
+ }
+
+ public void testNanoOptionalSfixed64() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalSfixed64 = 123;
+ assertEquals(123, msg.optionalSfixed64);
+ msg.clear()
+ .optionalSfixed64 = 456;
+ assertEquals(456, msg.optionalSfixed64);
+ msg.clear();
+ assertEquals(0, msg.optionalSfixed64);
+
+ msg.optionalSfixed64 = -123;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 12);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(-123, newMsg.optionalSfixed64);
+ }
+
+ public void testNanoOptionalFloat() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalFloat = 123f;
+ assertTrue(123.0f == msg.optionalFloat);
+ msg.clear()
+ .optionalFloat = 456.0f;
+ assertTrue(456.0f == msg.optionalFloat);
+ msg.clear();
+ assertTrue(0.0f == msg.optionalFloat);
+
+ msg.optionalFloat = -123.456f;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 8);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertTrue(-123.456f == newMsg.optionalFloat);
+ }
+
+ public void testNanoOptionalDouble() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalDouble = 123;
+ assertTrue(123.0 == msg.optionalDouble);
+ msg.clear()
+ .optionalDouble = 456.0;
+ assertTrue(456.0 == msg.optionalDouble);
+ msg.clear();
+ assertTrue(0.0 == msg.optionalDouble);
+
+ msg.optionalDouble = -123.456;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 12);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertTrue(-123.456 == newMsg.optionalDouble);
+ }
+
+ public void testNanoOptionalBool() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalBool = true;
+ assertTrue(msg.optionalBool);
+ msg.clear()
+ .optionalBool = true;
+ assertTrue(msg.optionalBool);
+ msg.clear();
+ assertFalse(msg.optionalBool);
+
+ msg.optionalBool = true;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 5);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertTrue(newMsg.optionalBool);
+ }
+
+ public void testNanoOptionalString() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalString = "hello";
+ assertEquals("hello", msg.optionalString);
+ msg.clear();
+ assertTrue(msg.optionalString.isEmpty());
+ msg.clear()
+ .optionalString = "hello2";
+ assertEquals("hello2", msg.optionalString);
+ msg.clear();
+ assertTrue(msg.optionalString.isEmpty());
+
+ msg.optionalString = "bye";
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 8);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertTrue(newMsg.optionalString != null);
+ assertEquals("bye", newMsg.optionalString);
+ }
+
+ public void testNanoOptionalBytes() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertFalse(msg.optionalBytes.length > 0);
+ msg.optionalBytes = InternalNano.copyFromUtf8("hello");
+ assertTrue(msg.optionalBytes.length > 0);
+ assertEquals("hello", new String(msg.optionalBytes, InternalNano.UTF_8));
+ msg.clear();
+ assertFalse(msg.optionalBytes.length > 0);
+ msg.clear()
+ .optionalBytes = InternalNano.copyFromUtf8("hello");
+ assertTrue(msg.optionalBytes.length > 0);
+ msg.clear();
+ assertFalse(msg.optionalBytes.length > 0);
+
+ msg.optionalBytes = InternalNano.copyFromUtf8("bye");
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 8);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertTrue(newMsg.optionalBytes.length > 0);
+ assertEquals("bye", new String(newMsg.optionalBytes, InternalNano.UTF_8));
+ }
+
+ public void testNanoOptionalGroup() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ TestAllTypesNano.OptionalGroup grp = new TestAllTypesNano.OptionalGroup();
+ grp.a = 1;
+ assertFalse(msg.optionalGroup != null);
+ msg.optionalGroup = grp;
+ assertTrue(msg.optionalGroup != null);
+ assertEquals(1, msg.optionalGroup.a);
+ msg.clear();
+ assertFalse(msg.optionalGroup != null);
+ msg.clear()
+ .optionalGroup = new TestAllTypesNano.OptionalGroup();
+ msg.optionalGroup.a = 2;
+ assertTrue(msg.optionalGroup != null);
+ msg.clear();
+ assertFalse(msg.optionalGroup != null);
+
+ msg.optionalGroup = grp;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 10);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertTrue(newMsg.optionalGroup != null);
+ assertEquals(1, newMsg.optionalGroup.a);
+ }
+
+ public void testNanoOptionalGroupWithUnknownFieldsEnabled() throws Exception {
+ MessageWithGroup msg = new MessageWithGroup();
+ MessageWithGroup.Group grp = new MessageWithGroup.Group();
+ grp.a = 1;
+ msg.group = grp;
+ byte [] serialized = MessageNano.toByteArray(msg);
+
+ MessageWithGroup parsed = MessageWithGroup.parseFrom(serialized);
+ assertEquals(1, parsed.group.a);
+
+ byte [] serialized2 = MessageNano.toByteArray(parsed);
+ assertEquals(serialized.length, serialized2.length);
+ MessageWithGroup parsed2 = MessageWithGroup.parseFrom(serialized2);
+ assertEquals(1, parsed2.group.a);
+ }
+
+ public void testNanoOptionalNestedMessage() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ TestAllTypesNano.NestedMessage nestedMsg = new TestAllTypesNano.NestedMessage();
+ nestedMsg.bb = 1;
+ assertFalse(msg.optionalNestedMessage != null);
+ msg.optionalNestedMessage = nestedMsg;
+ assertTrue(msg.optionalNestedMessage != null);
+ assertEquals(1, msg.optionalNestedMessage.bb);
+ msg.clear();
+ assertFalse(msg.optionalNestedMessage != null);
+ msg.clear()
+ .optionalNestedMessage = new TestAllTypesNano.NestedMessage();
+ msg.optionalNestedMessage.bb = 2;
+ assertTrue(msg.optionalNestedMessage != null);
+ msg.clear();
+ assertFalse(msg.optionalNestedMessage != null);
+
+ msg.optionalNestedMessage = nestedMsg;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 8);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertTrue(newMsg.optionalNestedMessage != null);
+ assertEquals(1, newMsg.optionalNestedMessage.bb);
+ }
+
+ public void testNanoOptionalForeignMessage() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ NanoOuterClass.ForeignMessageNano nestedMsg = new NanoOuterClass.ForeignMessageNano();
+ nestedMsg.c = 1;
+ assertFalse(msg.optionalForeignMessage != null);
+ msg.optionalForeignMessage = nestedMsg;
+ assertTrue(msg.optionalForeignMessage != null);
+ assertEquals(1, msg.optionalForeignMessage.c);
+ msg.clear();
+ assertFalse(msg.optionalForeignMessage != null);
+ msg.clear()
+ .optionalForeignMessage = new NanoOuterClass.ForeignMessageNano();
+ msg.optionalForeignMessage.c = 2;
+ assertTrue(msg.optionalForeignMessage != null);
+ msg.clear();
+ assertFalse(msg.optionalForeignMessage != null);
+
+ msg.optionalForeignMessage = nestedMsg;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 8);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertTrue(newMsg.optionalForeignMessage != null);
+ assertEquals(1, newMsg.optionalForeignMessage.c);
+ }
+
+ public void testNanoOptionalImportMessage() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ UnittestImportNano.ImportMessageNano nestedMsg = new UnittestImportNano.ImportMessageNano();
+ nestedMsg.d = 1;
+ assertFalse(msg.optionalImportMessage != null);
+ msg.optionalImportMessage = nestedMsg;
+ assertTrue(msg.optionalImportMessage != null);
+ assertEquals(1, msg.optionalImportMessage.d);
+ msg.clear();
+ assertFalse(msg.optionalImportMessage != null);
+ msg.clear()
+ .optionalImportMessage = new UnittestImportNano.ImportMessageNano();
+ msg.optionalImportMessage.d = 2;
+ assertTrue(msg.optionalImportMessage != null);
+ msg.clear();
+ assertFalse(msg.optionalImportMessage != null);
+
+ msg.optionalImportMessage = nestedMsg;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 8);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertTrue(newMsg.optionalImportMessage != null);
+ assertEquals(1, newMsg.optionalImportMessage.d);
+ }
+
+ public void testNanoOptionalNestedEnum() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalNestedEnum = TestAllTypesNano.BAR;
+ assertEquals(TestAllTypesNano.BAR, msg.optionalNestedEnum);
+ msg.clear()
+ .optionalNestedEnum = TestAllTypesNano.BAZ;
+ assertEquals(TestAllTypesNano.BAZ, msg.optionalNestedEnum);
+ msg.clear();
+ assertEquals(TestAllTypesNano.FOO, msg.optionalNestedEnum);
+
+ msg.optionalNestedEnum = TestAllTypesNano.BAR;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(TestAllTypesNano.BAR, newMsg.optionalNestedEnum);
+ }
+
+ public void testNanoOptionalForeignEnum() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalForeignEnum = NanoOuterClass.FOREIGN_NANO_BAR;
+ assertEquals(NanoOuterClass.FOREIGN_NANO_BAR, msg.optionalForeignEnum);
+ msg.clear()
+ .optionalForeignEnum = NanoOuterClass.FOREIGN_NANO_BAZ;
+ assertEquals(NanoOuterClass.FOREIGN_NANO_BAZ, msg.optionalForeignEnum);
+ msg.clear();
+ assertEquals(NanoOuterClass.FOREIGN_NANO_FOO, msg.optionalForeignEnum);
+
+ msg.optionalForeignEnum = NanoOuterClass.FOREIGN_NANO_BAR;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(NanoOuterClass.FOREIGN_NANO_BAR, newMsg.optionalForeignEnum);
+ }
+
+ public void testNanoOptionalImportEnum() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalImportEnum = UnittestImportNano.IMPORT_NANO_BAR;
+ assertEquals(UnittestImportNano.IMPORT_NANO_BAR, msg.optionalImportEnum);
+ msg.clear()
+ .optionalImportEnum = UnittestImportNano.IMPORT_NANO_BAZ;
+ assertEquals(UnittestImportNano.IMPORT_NANO_BAZ, msg.optionalImportEnum);
+ msg.clear();
+ assertEquals(UnittestImportNano.IMPORT_NANO_FOO, msg.optionalImportEnum);
+
+ msg.optionalImportEnum = UnittestImportNano.IMPORT_NANO_BAR;
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(UnittestImportNano.IMPORT_NANO_BAR, newMsg.optionalImportEnum);
+ }
+
+ public void testNanoOptionalStringPiece() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalStringPiece = "hello";
+ assertEquals("hello", msg.optionalStringPiece);
+ msg.clear();
+ assertTrue(msg.optionalStringPiece.isEmpty());
+ msg.clear()
+ .optionalStringPiece = "hello2";
+ assertEquals("hello2", msg.optionalStringPiece);
+ msg.clear();
+ assertTrue(msg.optionalStringPiece.isEmpty());
+
+ msg.optionalStringPiece = "bye";
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 9);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertTrue(newMsg.optionalStringPiece != null);
+ assertEquals("bye", newMsg.optionalStringPiece);
+ }
+
+ public void testNanoOptionalCord() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalCord = "hello";
+ assertEquals("hello", msg.optionalCord);
+ msg.clear();
+ assertTrue(msg.optionalCord.isEmpty());
+ msg.clear()
+ .optionalCord = "hello2";
+ assertEquals("hello2", msg.optionalCord);
+ msg.clear();
+ assertTrue(msg.optionalCord.isEmpty());
+
+ msg.optionalCord = "bye";
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 9);
+ assertEquals(result.length, msgSerializedSize);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertTrue(newMsg.optionalCord != null);
+ assertEquals("bye", newMsg.optionalCord);
+ }
+
+ public void testNanoRepeatedInt32() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedInt32.length);
+ msg.repeatedInt32 = new int[] { 123, 789, 456 };
+ assertEquals(789, msg.repeatedInt32[1]);
+ assertEquals(456, msg.repeatedInt32[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedInt32.length);
+ msg.clear()
+ .repeatedInt32 = new int[] { 456 };
+ assertEquals(1, msg.repeatedInt32.length);
+ assertEquals(456, msg.repeatedInt32[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedInt32.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedInt32 = new int[] { 123 };
+ assertEquals(1, msg.repeatedInt32.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedInt32.length);
+ assertEquals(123, newMsg.repeatedInt32[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedInt32 = new int[] { 123, 456 };
+ assertEquals(2, msg.repeatedInt32.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 10);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedInt32.length);
+ assertEquals(123, newMsg.repeatedInt32[0]);
+ assertEquals(456, newMsg.repeatedInt32[1]);
+ }
+
+ public void testNanoRepeatedInt64() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedInt64.length);
+ msg.repeatedInt64 = new long[] { 123, 789, 456 };
+ assertEquals(789, msg.repeatedInt64[1]);
+ assertEquals(456, msg.repeatedInt64[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedInt64.length);
+ msg.clear()
+ .repeatedInt64 = new long[] { 456 };
+ assertEquals(1, msg.repeatedInt64.length);
+ assertEquals(456, msg.repeatedInt64[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedInt64.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedInt64 = new long[] { 123 };
+ assertEquals(1, msg.repeatedInt64.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedInt64.length);
+ assertEquals(123, newMsg.repeatedInt64[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedInt64 = new long[] { 123, 456 };
+ assertEquals(2, msg.repeatedInt64.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 10);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedInt64.length);
+ assertEquals(123, newMsg.repeatedInt64[0]);
+ assertEquals(456, newMsg.repeatedInt64[1]);
+ }
+
+ public void testNanoRepeatedUint32() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedUint32.length);
+ msg.repeatedUint32 = new int[] { 123, 789, 456 };
+ assertEquals(789, msg.repeatedUint32[1]);
+ assertEquals(456, msg.repeatedUint32[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedUint32.length);
+ msg.clear()
+ .repeatedUint32 = new int[] { 456 };
+ assertEquals(1, msg.repeatedUint32.length);
+ assertEquals(456, msg.repeatedUint32[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedUint32.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedUint32 = new int[] { 123 };
+ assertEquals(1, msg.repeatedUint32.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedUint32.length);
+ assertEquals(123, newMsg.repeatedUint32[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedUint32 = new int[] { 123, 456 };
+ assertEquals(2, msg.repeatedUint32.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 10);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedUint32.length);
+ assertEquals(123, newMsg.repeatedUint32[0]);
+ assertEquals(456, newMsg.repeatedUint32[1]);
+ }
+
+ public void testNanoRepeatedUint64() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedUint64.length);
+ msg.repeatedUint64 = new long[] { 123, 789, 456 };
+ assertEquals(789, msg.repeatedUint64[1]);
+ assertEquals(456, msg.repeatedUint64[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedUint64.length);
+ msg.clear()
+ .repeatedUint64 = new long[] { 456 };
+ assertEquals(1, msg.repeatedUint64.length);
+ assertEquals(456, msg.repeatedUint64[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedUint64.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedUint64 = new long[] { 123 };
+ assertEquals(1, msg.repeatedUint64.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedUint64.length);
+ assertEquals(123, newMsg.repeatedUint64[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedUint64 = new long[] { 123, 456 };
+ assertEquals(2, msg.repeatedUint64.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 10);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedUint64.length);
+ assertEquals(123, newMsg.repeatedUint64[0]);
+ assertEquals(456, newMsg.repeatedUint64[1]);
+ }
+
+ public void testNanoRepeatedSint32() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedSint32.length);
+ msg.repeatedSint32 = new int[] { 123, 789, 456 };
+ assertEquals(789, msg.repeatedSint32[1]);
+ assertEquals(456, msg.repeatedSint32[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedSint32.length);
+ msg.clear()
+ .repeatedSint32 = new int[] { 456 };
+ assertEquals(1, msg.repeatedSint32.length);
+ assertEquals(456, msg.repeatedSint32[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedSint32.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedSint32 = new int[] { 123 };
+ assertEquals(1, msg.repeatedSint32.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 7);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedSint32.length);
+ assertEquals(123, newMsg.repeatedSint32[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedSint32 = new int[] { 123, 456 };
+ assertEquals(2, msg.repeatedSint32.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 11);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedSint32.length);
+ assertEquals(123, newMsg.repeatedSint32[0]);
+ assertEquals(456, newMsg.repeatedSint32[1]);
+ }
+
+ public void testNanoRepeatedSint64() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedSint64.length);
+ msg.repeatedSint64 = new long[] { 123, 789, 456 };
+ assertEquals(789, msg.repeatedSint64[1]);
+ assertEquals(456, msg.repeatedSint64[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedSint64.length);
+ msg.clear()
+ .repeatedSint64 = new long[] { 456 };
+ assertEquals(1, msg.repeatedSint64.length);
+ assertEquals(456, msg.repeatedSint64[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedSint64.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedSint64 = new long[] { 123 };
+ assertEquals(1, msg.repeatedSint64.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 7);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedSint64.length);
+ assertEquals(123, newMsg.repeatedSint64[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedSint64 = new long[] { 123, 456 };
+ assertEquals(2, msg.repeatedSint64.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 11);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedSint64.length);
+ assertEquals(123, newMsg.repeatedSint64[0]);
+ assertEquals(456, newMsg.repeatedSint64[1]);
+ }
+
+ public void testNanoRepeatedFixed32() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedFixed32.length);
+ msg.repeatedFixed32 = new int[] { 123, 789, 456 };
+ assertEquals(789, msg.repeatedFixed32[1]);
+ assertEquals(456, msg.repeatedFixed32[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedFixed32.length);
+ msg.clear()
+ .repeatedFixed32 = new int[] { 456 };
+ assertEquals(1, msg.repeatedFixed32.length);
+ assertEquals(456, msg.repeatedFixed32[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedFixed32.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedFixed32 = new int[] { 123 };
+ assertEquals(1, msg.repeatedFixed32.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 9);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedFixed32.length);
+ assertEquals(123, newMsg.repeatedFixed32[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedFixed32 = new int[] { 123, 456 };
+ assertEquals(2, msg.repeatedFixed32.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 15);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedFixed32.length);
+ assertEquals(123, newMsg.repeatedFixed32[0]);
+ assertEquals(456, newMsg.repeatedFixed32[1]);
+ }
+
+ public void testNanoRepeatedFixed64() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedFixed64.length);
+ msg.repeatedFixed64 = new long[] { 123, 789, 456 };
+ assertEquals(789, msg.repeatedFixed64[1]);
+ assertEquals(456, msg.repeatedFixed64[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedFixed64.length);
+ msg.clear()
+ .repeatedFixed64 = new long[] { 456 };
+ assertEquals(1, msg.repeatedFixed64.length);
+ assertEquals(456, msg.repeatedFixed64[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedFixed64.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedFixed64 = new long[] { 123 };
+ assertEquals(1, msg.repeatedFixed64.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 13);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedFixed64.length);
+ assertEquals(123, newMsg.repeatedFixed64[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedFixed64 = new long[] { 123, 456 };
+ assertEquals(2, msg.repeatedFixed64.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 23);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedFixed64.length);
+ assertEquals(123, newMsg.repeatedFixed64[0]);
+ assertEquals(456, newMsg.repeatedFixed64[1]);
+ }
+
+ public void testNanoRepeatedSfixed32() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedSfixed32.length);
+ msg.repeatedSfixed32 = new int[] { 123, 789, 456 };
+ assertEquals(789, msg.repeatedSfixed32[1]);
+ assertEquals(456, msg.repeatedSfixed32[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedSfixed32.length);
+ msg.clear()
+ .repeatedSfixed32 = new int[] { 456 };
+ assertEquals(1, msg.repeatedSfixed32.length);
+ assertEquals(456, msg.repeatedSfixed32[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedSfixed32.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedSfixed32 = new int[] { 123 };
+ assertEquals(1, msg.repeatedSfixed32.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 9);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedSfixed32.length);
+ assertEquals(123, newMsg.repeatedSfixed32[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedSfixed32 = new int[] { 123, 456 };
+ assertEquals(2, msg.repeatedSfixed32.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 15);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedSfixed32.length);
+ assertEquals(123, newMsg.repeatedSfixed32[0]);
+ assertEquals(456, newMsg.repeatedSfixed32[1]);
+ }
+
+ public void testNanoRepeatedSfixed64() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedSfixed64.length);
+ msg.repeatedSfixed64 = new long[] { 123, 789, 456 };
+ assertEquals(789, msg.repeatedSfixed64[1]);
+ assertEquals(456, msg.repeatedSfixed64[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedSfixed64.length);
+ msg.clear()
+ .repeatedSfixed64 = new long[] { 456 };
+ assertEquals(1, msg.repeatedSfixed64.length);
+ assertEquals(456, msg.repeatedSfixed64[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedSfixed64.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedSfixed64 = new long[] { 123 };
+ assertEquals(1, msg.repeatedSfixed64.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 13);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedSfixed64.length);
+ assertEquals(123, newMsg.repeatedSfixed64[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedSfixed64 = new long[] { 123, 456 };
+ assertEquals(2, msg.repeatedSfixed64.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 23);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedSfixed64.length);
+ assertEquals(123, newMsg.repeatedSfixed64[0]);
+ assertEquals(456, newMsg.repeatedSfixed64[1]);
+ }
+
+ public void testNanoRepeatedFloat() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedFloat.length);
+ msg.repeatedFloat = new float[] { 123f, 789f, 456f };
+ assertEquals(789f, msg.repeatedFloat[1]);
+ assertEquals(456f, msg.repeatedFloat[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedFloat.length);
+ msg.clear()
+ .repeatedFloat = new float[] { 456f };
+ assertEquals(1, msg.repeatedFloat.length);
+ assertEquals(456f, msg.repeatedFloat[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedFloat.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedFloat = new float[] { 123f };
+ assertEquals(1, msg.repeatedFloat.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 9);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedFloat.length);
+ assertEquals(123f, newMsg.repeatedFloat[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedFloat = new float[] { 123f, 456f };
+ assertEquals(2, msg.repeatedFloat.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 15);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedFloat.length);
+ assertEquals(123f, newMsg.repeatedFloat[0]);
+ assertEquals(456f, newMsg.repeatedFloat[1]);
+ }
+
+ public void testNanoRepeatedDouble() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedDouble.length);
+ msg.repeatedDouble = new double[] { 123.0, 789.0, 456.0 };
+ assertEquals(789.0, msg.repeatedDouble[1]);
+ assertEquals(456.0, msg.repeatedDouble[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedDouble.length);
+ msg.clear()
+ .repeatedDouble = new double[] { 456.0 };
+ assertEquals(1, msg.repeatedDouble.length);
+ assertEquals(456.0, msg.repeatedDouble[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedDouble.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedDouble = new double[] { 123.0 };
+ assertEquals(1, msg.repeatedDouble.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 13);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedDouble.length);
+ assertEquals(123.0, newMsg.repeatedDouble[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedDouble = new double[] { 123.0, 456.0 };
+ assertEquals(2, msg.repeatedDouble.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 23);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedDouble.length);
+ assertEquals(123.0, newMsg.repeatedDouble[0]);
+ assertEquals(456.0, newMsg.repeatedDouble[1]);
+ }
+
+ public void testNanoRepeatedBool() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedBool.length);
+ msg.repeatedBool = new boolean[] { false, true, false };
+ assertTrue(msg.repeatedBool[1]);
+ assertFalse(msg.repeatedBool[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedBool.length);
+ msg.clear()
+ .repeatedBool = new boolean[] { true };
+ assertEquals(1, msg.repeatedBool.length);
+ assertTrue(msg.repeatedBool[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedBool.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedBool = new boolean[] { false };
+ assertEquals(1, msg.repeatedBool.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedBool.length);
+ assertFalse(newMsg.repeatedBool[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedBool = new boolean[] { true, false };
+ assertEquals(2, msg.repeatedBool.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 9);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedBool.length);
+ assertTrue(newMsg.repeatedBool[0]);
+ assertFalse(newMsg.repeatedBool[1]);
+ }
+
+ public void testNanoRepeatedString() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedString.length);
+ msg.repeatedString = new String[] { "hello", "bye", "boo" };
+ assertEquals("bye", msg.repeatedString[1]);
+ assertEquals("boo", msg.repeatedString[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedString.length);
+ msg.clear()
+ .repeatedString = new String[] { "boo" };
+ assertEquals(1, msg.repeatedString.length);
+ assertEquals("boo", msg.repeatedString[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedString.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedString = new String[] { "" };
+ assertEquals(1, msg.repeatedString.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedString.length);
+ assertTrue(newMsg.repeatedString[0].isEmpty());
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedString = new String[] { "hello", "world" };
+ assertEquals(2, msg.repeatedString.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 19);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedString.length);
+ assertEquals("hello", newMsg.repeatedString[0]);
+ assertEquals("world", newMsg.repeatedString[1]);
+ }
+
+ public void testNanoRepeatedBytes() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedBytes.length);
+ msg.repeatedBytes = new byte[][] {
+ InternalNano.copyFromUtf8("hello"),
+ InternalNano.copyFromUtf8("bye"),
+ InternalNano.copyFromUtf8("boo")
+ };
+ assertEquals("bye", new String(msg.repeatedBytes[1], InternalNano.UTF_8));
+ assertEquals("boo", new String(msg.repeatedBytes[2], InternalNano.UTF_8));
+ msg.clear();
+ assertEquals(0, msg.repeatedBytes.length);
+ msg.clear()
+ .repeatedBytes = new byte[][] { InternalNano.copyFromUtf8("boo") };
+ assertEquals(1, msg.repeatedBytes.length);
+ assertEquals("boo", new String(msg.repeatedBytes[0], InternalNano.UTF_8));
+ msg.clear();
+ assertEquals(0, msg.repeatedBytes.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedBytes = new byte[][] { InternalNano.copyFromUtf8("") };
+ assertEquals(1, msg.repeatedBytes.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedBytes.length);
+ assertTrue(newMsg.repeatedBytes[0].length == 0);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedBytes = new byte[][] {
+ InternalNano.copyFromUtf8("hello"),
+ InternalNano.copyFromUtf8("world")
+ };
+ assertEquals(2, msg.repeatedBytes.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 19);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedBytes.length);
+ assertEquals("hello", new String(newMsg.repeatedBytes[0], InternalNano.UTF_8));
+ assertEquals("world", new String(newMsg.repeatedBytes[1], InternalNano.UTF_8));
+ }
+
+ public void testNanoRepeatedGroup() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ TestAllTypesNano.RepeatedGroup group0 =
+ new TestAllTypesNano.RepeatedGroup();
+ group0.a = 0;
+ TestAllTypesNano.RepeatedGroup group1 =
+ new TestAllTypesNano.RepeatedGroup();
+ group1.a = 1;
+ TestAllTypesNano.RepeatedGroup group2 =
+ new TestAllTypesNano.RepeatedGroup();
+ group2.a = 2;
+
+ msg.repeatedGroup = new TestAllTypesNano.RepeatedGroup[] { group0, group1, group2 };
+ assertEquals(3, msg.repeatedGroup.length);
+ assertEquals(0, msg.repeatedGroup[0].a);
+ assertEquals(1, msg.repeatedGroup[1].a);
+ assertEquals(2, msg.repeatedGroup[2].a);
+ msg.clear();
+ assertEquals(0, msg.repeatedGroup.length);
+ msg.clear()
+ .repeatedGroup = new TestAllTypesNano.RepeatedGroup[] { group1 };
+ assertEquals(1, msg.repeatedGroup.length);
+ assertEquals(1, msg.repeatedGroup[0].a);
+ msg.clear();
+ assertEquals(0, msg.repeatedGroup.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedGroup = new TestAllTypesNano.RepeatedGroup[] { group0 };
+ assertEquals(1, msg.repeatedGroup.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 7);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedGroup.length);
+ assertEquals(0, newMsg.repeatedGroup[0].a);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedGroup = new TestAllTypesNano.RepeatedGroup[] { group0, group1 };
+ assertEquals(2, msg.repeatedGroup.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 14);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedGroup.length);
+ assertEquals(0, newMsg.repeatedGroup[0].a);
+ assertEquals(1, newMsg.repeatedGroup[1].a);
+ }
+
+ public void testNanoRepeatedNestedMessage() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ TestAllTypesNano.NestedMessage nestedMsg0 =
+ new TestAllTypesNano.NestedMessage();
+ nestedMsg0.bb = 0;
+ TestAllTypesNano.NestedMessage nestedMsg1 =
+ new TestAllTypesNano.NestedMessage();
+ nestedMsg1.bb = 1;
+ TestAllTypesNano.NestedMessage nestedMsg2 =
+ new TestAllTypesNano.NestedMessage();
+ nestedMsg2.bb = 2;
+
+ msg.repeatedNestedMessage =
+ new TestAllTypesNano.NestedMessage[] { nestedMsg0, nestedMsg1, nestedMsg2 };
+ assertEquals(3, msg.repeatedNestedMessage.length);
+ assertEquals(0, msg.repeatedNestedMessage[0].bb);
+ assertEquals(1, msg.repeatedNestedMessage[1].bb);
+ assertEquals(2, msg.repeatedNestedMessage[2].bb);
+ msg.clear();
+ assertEquals(0, msg.repeatedNestedMessage.length);
+ msg.clear()
+ .repeatedNestedMessage = new TestAllTypesNano.NestedMessage[] { nestedMsg1 };
+ assertEquals(1, msg.repeatedNestedMessage.length);
+ assertEquals(1, msg.repeatedNestedMessage[0].bb);
+ msg.clear();
+ assertEquals(0, msg.repeatedNestedMessage.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedNestedMessage = new TestAllTypesNano.NestedMessage[] { nestedMsg0 };
+ assertEquals(1, msg.repeatedNestedMessage.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedNestedMessage.length);
+ assertEquals(0, newMsg.repeatedNestedMessage[0].bb);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedNestedMessage = new TestAllTypesNano.NestedMessage[] { nestedMsg0, nestedMsg1 };
+ assertEquals(2, msg.repeatedNestedMessage.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 11);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedNestedMessage.length);
+ assertEquals(0, newMsg.repeatedNestedMessage[0].bb);
+ assertEquals(1, newMsg.repeatedNestedMessage[1].bb);
+ }
+
+ public void testNanoRepeatedForeignMessage() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ NanoOuterClass.ForeignMessageNano foreignMsg0 =
+ new NanoOuterClass.ForeignMessageNano();
+ foreignMsg0.c = 0;
+ NanoOuterClass.ForeignMessageNano foreignMsg1 =
+ new NanoOuterClass.ForeignMessageNano();
+ foreignMsg1.c = 1;
+ NanoOuterClass.ForeignMessageNano foreignMsg2 =
+ new NanoOuterClass.ForeignMessageNano();
+ foreignMsg2.c = 2;
+
+ msg.repeatedForeignMessage =
+ new NanoOuterClass.ForeignMessageNano[] { foreignMsg0, foreignMsg1, foreignMsg2 };
+ assertEquals(3, msg.repeatedForeignMessage.length);
+ assertEquals(0, msg.repeatedForeignMessage[0].c);
+ assertEquals(1, msg.repeatedForeignMessage[1].c);
+ assertEquals(2, msg.repeatedForeignMessage[2].c);
+ msg.clear();
+ assertEquals(0, msg.repeatedForeignMessage.length);
+ msg.clear()
+ .repeatedForeignMessage = new NanoOuterClass.ForeignMessageNano[] { foreignMsg1 };
+ assertEquals(1, msg.repeatedForeignMessage.length);
+ assertEquals(1, msg.repeatedForeignMessage[0].c);
+ msg.clear();
+ assertEquals(0, msg.repeatedForeignMessage.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedForeignMessage = new NanoOuterClass.ForeignMessageNano[] { foreignMsg0 };
+ assertEquals(1, msg.repeatedForeignMessage.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedForeignMessage.length);
+ assertEquals(0, newMsg.repeatedForeignMessage[0].c);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedForeignMessage = new NanoOuterClass.ForeignMessageNano[] { foreignMsg0, foreignMsg1 };
+ assertEquals(2, msg.repeatedForeignMessage.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 11);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedForeignMessage.length);
+ assertEquals(0, newMsg.repeatedForeignMessage[0].c);
+ assertEquals(1, newMsg.repeatedForeignMessage[1].c);
+ }
+
+ public void testNanoRepeatedImportMessage() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ UnittestImportNano.ImportMessageNano foreignMsg0 =
+ new UnittestImportNano.ImportMessageNano();
+ foreignMsg0.d = 0;
+ UnittestImportNano.ImportMessageNano foreignMsg1 =
+ new UnittestImportNano.ImportMessageNano();
+ foreignMsg1.d = 1;
+ UnittestImportNano.ImportMessageNano foreignMsg2 =
+ new UnittestImportNano.ImportMessageNano();
+ foreignMsg2.d = 2;
+
+ msg.repeatedImportMessage =
+ new UnittestImportNano.ImportMessageNano[] { foreignMsg0, foreignMsg1, foreignMsg2 };
+ assertEquals(3, msg.repeatedImportMessage.length);
+ assertEquals(0, msg.repeatedImportMessage[0].d);
+ assertEquals(1, msg.repeatedImportMessage[1].d);
+ assertEquals(2, msg.repeatedImportMessage[2].d);
+ msg.clear();
+ assertEquals(0, msg.repeatedImportMessage.length);
+ msg.clear()
+ .repeatedImportMessage = new UnittestImportNano.ImportMessageNano[] { foreignMsg1 };
+ assertEquals(1, msg.repeatedImportMessage.length);
+ assertEquals(1, msg.repeatedImportMessage[0].d);
+ msg.clear();
+ assertEquals(0, msg.repeatedImportMessage.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedImportMessage = new UnittestImportNano.ImportMessageNano[] { foreignMsg0 };
+ assertEquals(1, msg.repeatedImportMessage.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedImportMessage.length);
+ assertEquals(0, newMsg.repeatedImportMessage[0].d);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedImportMessage = new UnittestImportNano.ImportMessageNano[] { foreignMsg0, foreignMsg1 };
+ assertEquals(2, msg.repeatedImportMessage.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 11);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedImportMessage.length);
+ assertEquals(0, newMsg.repeatedImportMessage[0].d);
+ assertEquals(1, newMsg.repeatedImportMessage[1].d);
+ }
+
+ public void testNanoRepeatedNestedEnum() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.repeatedNestedEnum = new int[] {
+ TestAllTypesNano.FOO,
+ TestAllTypesNano.BAR,
+ TestAllTypesNano.BAZ
+ };
+ assertEquals(3, msg.repeatedNestedEnum.length);
+ assertEquals(TestAllTypesNano.FOO, msg.repeatedNestedEnum[0]);
+ assertEquals(TestAllTypesNano.BAR, msg.repeatedNestedEnum[1]);
+ assertEquals(TestAllTypesNano.BAZ, msg.repeatedNestedEnum[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedNestedEnum.length);
+ msg.clear()
+ .repeatedNestedEnum = new int[] { TestAllTypesNano.BAR };
+ assertEquals(1, msg.repeatedNestedEnum.length);
+ assertEquals(TestAllTypesNano.BAR, msg.repeatedNestedEnum[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedNestedEnum.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedNestedEnum = new int[] { TestAllTypesNano.FOO };
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedNestedEnum.length);
+ assertEquals(TestAllTypesNano.FOO, msg.repeatedNestedEnum[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedNestedEnum = new int[] { TestAllTypesNano.FOO, TestAllTypesNano.BAR };
+ assertEquals(2, msg.repeatedNestedEnum.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 9);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedNestedEnum.length);
+ assertEquals(TestAllTypesNano.FOO, msg.repeatedNestedEnum[0]);
+ assertEquals(TestAllTypesNano.BAR, msg.repeatedNestedEnum[1]);
+ }
+
+ public void testNanoRepeatedForeignEnum() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.repeatedForeignEnum = new int[] {
+ NanoOuterClass.FOREIGN_NANO_FOO,
+ NanoOuterClass.FOREIGN_NANO_BAR,
+ NanoOuterClass.FOREIGN_NANO_BAZ
+ };
+ assertEquals(3, msg.repeatedForeignEnum.length);
+ assertEquals(NanoOuterClass.FOREIGN_NANO_FOO, msg.repeatedForeignEnum[0]);
+ assertEquals(NanoOuterClass.FOREIGN_NANO_BAR, msg.repeatedForeignEnum[1]);
+ assertEquals(NanoOuterClass.FOREIGN_NANO_BAZ, msg.repeatedForeignEnum[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedForeignEnum.length);
+ msg.clear()
+ .repeatedForeignEnum = new int[] { NanoOuterClass.FOREIGN_NANO_BAR };
+ assertEquals(1, msg.repeatedForeignEnum.length);
+ assertEquals(NanoOuterClass.FOREIGN_NANO_BAR, msg.repeatedForeignEnum[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedForeignEnum.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedForeignEnum = new int[] { NanoOuterClass.FOREIGN_NANO_FOO };
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedForeignEnum.length);
+ assertEquals(NanoOuterClass.FOREIGN_NANO_FOO, msg.repeatedForeignEnum[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedForeignEnum = new int[] {
+ NanoOuterClass.FOREIGN_NANO_FOO,
+ NanoOuterClass.FOREIGN_NANO_BAR
+ };
+ assertEquals(2, msg.repeatedForeignEnum.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 9);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedForeignEnum.length);
+ assertEquals(NanoOuterClass.FOREIGN_NANO_FOO, msg.repeatedForeignEnum[0]);
+ assertEquals(NanoOuterClass.FOREIGN_NANO_BAR, msg.repeatedForeignEnum[1]);
+ }
+
+ public void testNanoRepeatedImportEnum() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.repeatedImportEnum = new int[] {
+ UnittestImportNano.IMPORT_NANO_FOO,
+ UnittestImportNano.IMPORT_NANO_BAR,
+ UnittestImportNano.IMPORT_NANO_BAZ
+ };
+ assertEquals(3, msg.repeatedImportEnum.length);
+ assertEquals(UnittestImportNano.IMPORT_NANO_FOO, msg.repeatedImportEnum[0]);
+ assertEquals(UnittestImportNano.IMPORT_NANO_BAR, msg.repeatedImportEnum[1]);
+ assertEquals(UnittestImportNano.IMPORT_NANO_BAZ, msg.repeatedImportEnum[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedImportEnum.length);
+ msg.clear()
+ .repeatedImportEnum = new int[] { UnittestImportNano.IMPORT_NANO_BAR };
+ assertEquals(1, msg.repeatedImportEnum.length);
+ assertEquals(UnittestImportNano.IMPORT_NANO_BAR, msg.repeatedImportEnum[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedImportEnum.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedImportEnum = new int[] { UnittestImportNano.IMPORT_NANO_FOO };
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedImportEnum.length);
+ assertEquals(UnittestImportNano.IMPORT_NANO_FOO, msg.repeatedImportEnum[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedImportEnum = new int[] {
+ UnittestImportNano.IMPORT_NANO_FOO,
+ UnittestImportNano.IMPORT_NANO_BAR
+ };
+ assertEquals(2, msg.repeatedImportEnum.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 9);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedImportEnum.length);
+ assertEquals(UnittestImportNano.IMPORT_NANO_FOO, msg.repeatedImportEnum[0]);
+ assertEquals(UnittestImportNano.IMPORT_NANO_BAR, msg.repeatedImportEnum[1]);
+ }
+
+ public void testNanoRepeatedStringPiece() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedStringPiece.length);
+ msg.repeatedStringPiece = new String[] { "hello", "bye", "boo" };
+ assertEquals("bye", msg.repeatedStringPiece[1]);
+ assertEquals("boo", msg.repeatedStringPiece[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedStringPiece.length);
+ msg.clear()
+ .repeatedStringPiece = new String[] { "boo" };
+ assertEquals(1, msg.repeatedStringPiece.length);
+ assertEquals("boo", msg.repeatedStringPiece[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedStringPiece.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedStringPiece = new String[] { "" };
+ assertEquals(1, msg.repeatedStringPiece.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedStringPiece.length);
+ assertTrue(newMsg.repeatedStringPiece[0].isEmpty());
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedStringPiece = new String[] { "hello", "world" };
+ assertEquals(2, msg.repeatedStringPiece.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 19);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedStringPiece.length);
+ assertEquals("hello", newMsg.repeatedStringPiece[0]);
+ assertEquals("world", newMsg.repeatedStringPiece[1]);
+ }
+
+ public void testNanoRepeatedCord() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedCord.length);
+ msg.repeatedCord = new String[] { "hello", "bye", "boo" };
+ assertEquals("bye", msg.repeatedCord[1]);
+ assertEquals("boo", msg.repeatedCord[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedCord.length);
+ msg.clear()
+ .repeatedCord = new String[] { "boo" };
+ assertEquals(1, msg.repeatedCord.length);
+ assertEquals("boo", msg.repeatedCord[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedCord.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedCord = new String[] { "" };
+ assertEquals(1, msg.repeatedCord.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 6);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedCord.length);
+ assertTrue(newMsg.repeatedCord[0].isEmpty());
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedCord = new String[] { "hello", "world" };
+ assertEquals(2, msg.repeatedCord.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 19);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedCord.length);
+ assertEquals("hello", newMsg.repeatedCord[0]);
+ assertEquals("world", newMsg.repeatedCord[1]);
+ }
+
+ public void testNanoRepeatedPackedInt32() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedPackedInt32.length);
+ msg.repeatedPackedInt32 = new int[] { 123, 789, 456 };
+ assertEquals(789, msg.repeatedPackedInt32[1]);
+ assertEquals(456, msg.repeatedPackedInt32[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedPackedInt32.length);
+ msg.clear()
+ .repeatedPackedInt32 = new int[] { 456 };
+ assertEquals(1, msg.repeatedPackedInt32.length);
+ assertEquals(456, msg.repeatedPackedInt32[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedPackedInt32.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedPackedInt32 = new int[] { 123 };
+ assertEquals(1, msg.repeatedPackedInt32.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 7);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedPackedInt32.length);
+ assertEquals(123, newMsg.repeatedPackedInt32[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedPackedInt32 = new int[] { 123, 456 };
+ assertEquals(2, msg.repeatedPackedInt32.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 9);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedPackedInt32.length);
+ assertEquals(123, newMsg.repeatedPackedInt32[0]);
+ assertEquals(456, newMsg.repeatedPackedInt32[1]);
+ }
+
+ public void testNanoRepeatedPackedSfixed64() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ assertEquals(0, msg.repeatedPackedSfixed64.length);
+ msg.repeatedPackedSfixed64 = new long[] { 123, 789, 456 };
+ assertEquals(789, msg.repeatedPackedSfixed64[1]);
+ assertEquals(456, msg.repeatedPackedSfixed64[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedPackedSfixed64.length);
+ msg.clear()
+ .repeatedPackedSfixed64 = new long[] { 456 };
+ assertEquals(1, msg.repeatedPackedSfixed64.length);
+ assertEquals(456, msg.repeatedPackedSfixed64[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedPackedSfixed64.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedPackedSfixed64 = new long[] { 123 };
+ assertEquals(1, msg.repeatedPackedSfixed64.length);
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 14);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedPackedSfixed64.length);
+ assertEquals(123, newMsg.repeatedPackedSfixed64[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedPackedSfixed64 = new long[] { 123, 456 };
+ assertEquals(2, msg.repeatedPackedSfixed64.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 22);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedPackedSfixed64.length);
+ assertEquals(123, newMsg.repeatedPackedSfixed64[0]);
+ assertEquals(456, newMsg.repeatedPackedSfixed64[1]);
+ }
+
+ public void testNanoRepeatedPackedNestedEnum() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.repeatedPackedNestedEnum = new int[] {
+ TestAllTypesNano.FOO,
+ TestAllTypesNano.BAR,
+ TestAllTypesNano.BAZ
+ };
+ assertEquals(3, msg.repeatedPackedNestedEnum.length);
+ assertEquals(TestAllTypesNano.FOO, msg.repeatedPackedNestedEnum[0]);
+ assertEquals(TestAllTypesNano.BAR, msg.repeatedPackedNestedEnum[1]);
+ assertEquals(TestAllTypesNano.BAZ, msg.repeatedPackedNestedEnum[2]);
+ msg.clear();
+ assertEquals(0, msg.repeatedPackedNestedEnum.length);
+ msg.clear()
+ .repeatedPackedNestedEnum = new int[] { TestAllTypesNano.BAR };
+ assertEquals(1, msg.repeatedPackedNestedEnum.length);
+ assertEquals(TestAllTypesNano.BAR, msg.repeatedPackedNestedEnum[0]);
+ msg.clear();
+ assertEquals(0, msg.repeatedPackedNestedEnum.length);
+
+ // Test 1 entry
+ msg.clear()
+ .repeatedPackedNestedEnum = new int[] { TestAllTypesNano.FOO };
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 7);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(1, newMsg.repeatedPackedNestedEnum.length);
+ assertEquals(TestAllTypesNano.FOO, msg.repeatedPackedNestedEnum[0]);
+
+ // Test 2 entries
+ msg.clear()
+ .repeatedPackedNestedEnum = new int[] { TestAllTypesNano.FOO, TestAllTypesNano.BAR };
+ assertEquals(2, msg.repeatedPackedNestedEnum.length);
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 8);
+ assertEquals(result.length, msgSerializedSize);
+
+ newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(2, newMsg.repeatedPackedNestedEnum.length);
+ assertEquals(TestAllTypesNano.FOO, msg.repeatedPackedNestedEnum[0]);
+ assertEquals(TestAllTypesNano.BAR, msg.repeatedPackedNestedEnum[1]);
+ }
+
+ public void testNanoRepeatedPackedSerializedSize() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.repeatedPackedInt32 = new int[] { 123, 789, 456 };
+ int msgSerializedSize = msg.getSerializedSize();
+ byte [] result = MessageNano.toByteArray(msg);
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 11);
+ assertEquals(result.length, msgSerializedSize);
+ TestAllTypesNano msg2 = new TestAllTypesNano();
+ msg2.repeatedPackedInt32 = new int[] { 123, 789, 456 };
+ byte [] result2 = new byte[msgSerializedSize];
+ MessageNano.toByteArray(msg2, result2, 0, msgSerializedSize);
+
+ // Check equal size and content.
+ assertEquals(msgSerializedSize, msg2.getSerializedSize());
+ assertTrue(Arrays.equals(result, result2));
+ }
+
+ public void testNanoRepeatedInt32ReMerge() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.repeatedInt32 = new int[] { 234 };
+ byte [] result1 = MessageNano.toByteArray(msg);
+
+ msg.clear().optionalInt32 = 789;
+ byte [] result2 = MessageNano.toByteArray(msg);
+
+ msg.clear().repeatedInt32 = new int[] { 123, 456 };
+ byte [] result3 = MessageNano.toByteArray(msg);
+
+ // Concatenate the three serializations and read as one message.
+ byte [] result = new byte[result1.length + result2.length + result3.length];
+ System.arraycopy(result1, 0, result, 0, result1.length);
+ System.arraycopy(result2, 0, result, result1.length, result2.length);
+ System.arraycopy(result3, 0, result, result1.length + result2.length, result3.length);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(789, newMsg.optionalInt32);
+ assertEquals(3, newMsg.repeatedInt32.length);
+ assertEquals(234, newMsg.repeatedInt32[0]);
+ assertEquals(123, newMsg.repeatedInt32[1]);
+ assertEquals(456, newMsg.repeatedInt32[2]);
+ }
+
+ public void testNanoRepeatedNestedEnumReMerge() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.repeatedNestedEnum = new int[] { TestAllTypesNano.FOO };
+ byte [] result1 = MessageNano.toByteArray(msg);
+
+ msg.clear().optionalInt32 = 789;
+ byte [] result2 = MessageNano.toByteArray(msg);
+
+ msg.clear().repeatedNestedEnum = new int[] { TestAllTypesNano.BAR, TestAllTypesNano.FOO };
+ byte [] result3 = MessageNano.toByteArray(msg);
+
+ // Concatenate the three serializations and read as one message.
+ byte [] result = new byte[result1.length + result2.length + result3.length];
+ System.arraycopy(result1, 0, result, 0, result1.length);
+ System.arraycopy(result2, 0, result, result1.length, result2.length);
+ System.arraycopy(result3, 0, result, result1.length + result2.length, result3.length);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(789, newMsg.optionalInt32);
+ assertEquals(3, newMsg.repeatedNestedEnum.length);
+ assertEquals(TestAllTypesNano.FOO, newMsg.repeatedNestedEnum[0]);
+ assertEquals(TestAllTypesNano.BAR, newMsg.repeatedNestedEnum[1]);
+ assertEquals(TestAllTypesNano.FOO, newMsg.repeatedNestedEnum[2]);
+ }
+
+ public void testNanoRepeatedNestedMessageReMerge() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ TestAllTypesNano.NestedMessage nestedMsg0 =
+ new TestAllTypesNano.NestedMessage();
+ nestedMsg0.bb = 0;
+ TestAllTypesNano.NestedMessage nestedMsg1 =
+ new TestAllTypesNano.NestedMessage();
+ nestedMsg1.bb = 1;
+ TestAllTypesNano.NestedMessage nestedMsg2 =
+ new TestAllTypesNano.NestedMessage();
+ nestedMsg2.bb = 2;
+
+ msg.repeatedNestedMessage = new TestAllTypesNano.NestedMessage[] { nestedMsg0 };
+ byte [] result1 = MessageNano.toByteArray(msg);
+
+ msg.clear().optionalInt32 = 789;
+ byte [] result2 = MessageNano.toByteArray(msg);
+
+ msg.clear().repeatedNestedMessage =
+ new TestAllTypesNano.NestedMessage[] { nestedMsg1, nestedMsg2 };
+ byte [] result3 = MessageNano.toByteArray(msg);
+
+ // Concatenate the three serializations and read as one message.
+ byte [] result = new byte[result1.length + result2.length + result3.length];
+ System.arraycopy(result1, 0, result, 0, result1.length);
+ System.arraycopy(result2, 0, result, result1.length, result2.length);
+ System.arraycopy(result3, 0, result, result1.length + result2.length, result3.length);
+
+ TestAllTypesNano newMsg = TestAllTypesNano.parseFrom(result);
+ assertEquals(789, newMsg.optionalInt32);
+ assertEquals(3, newMsg.repeatedNestedMessage.length);
+ assertEquals(nestedMsg0.bb, newMsg.repeatedNestedMessage[0].bb);
+ assertEquals(nestedMsg1.bb, newMsg.repeatedNestedMessage[1].bb);
+ assertEquals(nestedMsg2.bb, newMsg.repeatedNestedMessage[2].bb);
+ }
+
+ /**
+ * Tests that invalid enum values from the wire are not accepted.
+ */
+ public void testNanoEnumValidity() throws Exception {
+ final int invalid = 120;
+ final int alsoInvalid = 121;
+
+ EnumValidity.M m = new EnumValidity.M();
+ // Sanity check & baseline of the assertions for the first case below.
+ assertEquals(EnumValidity.E.default_, m.optionalE);
+ assertEquals(EnumValidity.E.BAZ, m.defaultE);
+
+ m.optionalE = invalid;
+ m.defaultE = invalid;
+ // E contains all valid values
+ m.repeatedE = new int[] {EnumValidity.E.FOO, EnumValidity.E.BAR};
+ m.packedE = new int[] {EnumValidity.E.FOO, EnumValidity.E.BAZ};
+ // E2 contains some invalid values
+ m.repeatedE2 = new int[] {invalid, EnumValidity.E.BAR, alsoInvalid};
+ m.packedE2 = new int[] {EnumValidity.E.FOO, invalid, alsoInvalid};
+ // E3 contains all invalid values
+ m.repeatedE3 = new int[] {invalid, invalid};
+ m.packedE3 = new int[] {alsoInvalid, alsoInvalid};
+ byte[] serialized = MessageNano.toByteArray(m);
+ // Sanity check that we do have all data in the byte array.
+ assertEquals(31, serialized.length);
+
+ // Test 1: tests that invalid values aren't included in the deserialized message.
+ EnumValidity.M deserialized = MessageNano.mergeFrom(new EnumValidity.M(), serialized);
+ assertEquals(EnumValidity.E.default_, deserialized.optionalE);
+ assertEquals(EnumValidity.E.BAZ, deserialized.defaultE);
+ assertTrue(Arrays.equals(
+ new int[] {EnumValidity.E.FOO, EnumValidity.E.BAR}, deserialized.repeatedE));
+ assertTrue(Arrays.equals(
+ new int[] {EnumValidity.E.FOO, EnumValidity.E.BAZ}, deserialized.packedE));
+ assertTrue(Arrays.equals(
+ new int[] {EnumValidity.E.BAR}, deserialized.repeatedE2));
+ assertTrue(Arrays.equals(
+ new int[] {EnumValidity.E.FOO}, deserialized.packedE2));
+ assertEquals(0, deserialized.repeatedE3.length);
+ assertEquals(0, deserialized.packedE3.length);
+
+ // Test 2: tests that invalid values do not override previous values in the field, including
+ // arrays, including pre-existing invalid values.
+ deserialized.optionalE = EnumValidity.E.BAR;
+ deserialized.defaultE = alsoInvalid;
+ deserialized.repeatedE = new int[] {EnumValidity.E.BAZ};
+ deserialized.packedE = new int[] {EnumValidity.E.BAZ, alsoInvalid};
+ deserialized.repeatedE2 = new int[] {invalid, alsoInvalid};
+ deserialized.packedE2 = null;
+ deserialized.repeatedE3 = null;
+ deserialized.packedE3 = new int[0];
+ MessageNano.mergeFrom(deserialized, serialized);
+ assertEquals(EnumValidity.E.BAR, deserialized.optionalE);
+ assertEquals(alsoInvalid, deserialized.defaultE);
+ assertTrue(Arrays.equals(
+ new int[] {EnumValidity.E.BAZ, /* + */ EnumValidity.E.FOO, EnumValidity.E.BAR},
+ deserialized.repeatedE));
+ assertTrue(Arrays.equals(
+ new int[] {EnumValidity.E.BAZ, alsoInvalid, /* + */ EnumValidity.E.FOO, EnumValidity.E.BAZ},
+ deserialized.packedE));
+ assertTrue(Arrays.equals(
+ new int[] {invalid, alsoInvalid, /* + */ EnumValidity.E.BAR},
+ deserialized.repeatedE2));
+ assertTrue(Arrays.equals(
+ new int[] {/* <null> + */ EnumValidity.E.FOO},
+ deserialized.packedE2));
+ assertNull(deserialized.repeatedE3); // null + all invalid == null
+ assertEquals(0, deserialized.packedE3.length); // empty + all invalid == empty
+
+ // Test 3: reading by alternative forms
+ EnumValidity.Alt alt = MessageNano.mergeFrom(new EnumValidity.Alt(), serialized);
+ assertEquals(EnumValidity.E.BAR, // last valid value in m.repeatedE2
+ alt.repeatedE2AsOptional);
+ assertTrue(Arrays.equals(new int[] {EnumValidity.E.FOO}, alt.packedE2AsNonPacked));
+ assertEquals(0, alt.nonPackedE3AsPacked.length);
+ }
+
+ /**
+ * Tests the same as {@link #testNanoEnumValidity()} with accessor style. Repeated fields are
+ * not re-tested here because they are not affected by the accessor style.
+ */
+ public void testNanoEnumValidityAccessors() throws Exception {
+ final int invalid = 120;
+ final int alsoInvalid = 121;
+
+ EnumValidityAccessors.M m = new EnumValidityAccessors.M();
+ // Sanity check & baseline of the assertions for the first case below.
+ assertEquals(EnumValidityAccessors.default_, m.getOptionalE());
+ assertEquals(EnumValidityAccessors.BAZ, m.getDefaultE());
+
+ m.setOptionalE(invalid);
+ m.setDefaultE(invalid);
+ // Set repeatedE2 for Alt.repeatedE2AsOptional
+ m.repeatedE2 = new int[] {invalid, EnumValidityAccessors.BAR, alsoInvalid};
+ byte[] serialized = MessageNano.toByteArray(m);
+ // Sanity check that we do have all data in the byte array.
+ assertEquals(10, serialized.length);
+
+ // Test 1: tests that invalid values aren't included in the deserialized message.
+ EnumValidityAccessors.M deserialized =
+ MessageNano.mergeFrom(new EnumValidityAccessors.M(), serialized);
+ assertEquals(EnumValidityAccessors.default_, deserialized.getOptionalE());
+ assertEquals(EnumValidityAccessors.BAZ, deserialized.getDefaultE());
+
+ // Test 2: tests that invalid values do not override previous values in the field, including
+ // pre-existing invalid values.
+ deserialized.setOptionalE(EnumValidityAccessors.BAR);
+ deserialized.setDefaultE(alsoInvalid);
+ MessageNano.mergeFrom(deserialized, serialized);
+ assertEquals(EnumValidityAccessors.BAR, deserialized.getOptionalE());
+ assertEquals(alsoInvalid, deserialized.getDefaultE());
+
+ // Test 3: reading by alternative forms
+ EnumValidityAccessors.Alt alt =
+ MessageNano.mergeFrom(new EnumValidityAccessors.Alt(), serialized);
+ assertEquals(EnumValidityAccessors.BAR, // last valid value in m.repeatedE2
+ alt.getRepeatedE2AsOptional());
+ }
+
+ /**
+ * Tests that code generation correctly wraps a single message into its outer
+ * class. The class {@code SingleMessageNano} is imported from the outer
+ * class {@code UnittestSingleNano}, whose name is implicit. Any error would
+ * cause this method to fail compilation.
+ */
+ public void testNanoSingle() throws Exception {
+ SingleMessageNano msg = new SingleMessageNano();
+ assertNotNull(msg);
+ }
+
+ /**
+ * Tests that code generation correctly skips generating the outer class if
+ * unnecessary, letting a file-scope entity have the same name. The class
+ * {@code MultipleNameClashNano} shares the same name with the file's outer
+ * class defined explicitly, but the file contains no other entities and has
+ * java_multiple_files set. Any error would cause this method to fail
+ * compilation.
+ */
+ public void testNanoMultipleNameClash() throws Exception {
+ MultipleNameClashNano msg = new MultipleNameClashNano();
+ msg.field = 0;
+ }
+
+ /**
+ * Tests that code generation correctly handles enums in different scopes in
+ * a source file with the option java_multiple_files set to true. Any error
+ * would cause this method to fail compilation.
+ */
+ public void testNanoMultipleEnumScoping() throws Exception {
+ FileScopeEnumRefNano msg1 = new FileScopeEnumRefNano();
+ msg1.enumField = UnittestMultipleNano.ONE;
+ MessageScopeEnumRefNano msg2 = new MessageScopeEnumRefNano();
+ msg2.enumField = MessageScopeEnumRefNano.TWO;
+ }
+
+ /**
+ * Tests that code generation with mixed values of the java_multiple_files
+ * options between the main source file and the imported source files would
+ * generate correct references. Any error would cause this method to fail
+ * compilation.
+ */
+ public void testNanoMultipleImportingNonMultiple() throws Exception {
+ UnittestImportNano.ImportMessageNano importMsg = new UnittestImportNano.ImportMessageNano();
+ MultipleImportingNonMultipleNano1 nano1 = new MultipleImportingNonMultipleNano1();
+ nano1.field = importMsg;
+ MultipleImportingNonMultipleNano2 nano2 = new MultipleImportingNonMultipleNano2();
+ nano2.nano1 = nano1;
+ }
+
+ public void testNanoDefaults() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ for (int i = 0; i < 2; i++) {
+ assertEquals(41, msg.defaultInt32);
+ assertEquals(42, msg.defaultInt64);
+ assertEquals(43, msg.defaultUint32);
+ assertEquals(44, msg.defaultUint64);
+ assertEquals(-45, msg.defaultSint32);
+ assertEquals(46, msg.defaultSint64);
+ assertEquals(47, msg.defaultFixed32);
+ assertEquals(48, msg.defaultFixed64);
+ assertEquals(49, msg.defaultSfixed32);
+ assertEquals(-50, msg.defaultSfixed64);
+ assertTrue(51.5f == msg.defaultFloat);
+ assertTrue(52.0e3 == msg.defaultDouble);
+ assertEquals(true, msg.defaultBool);
+ assertEquals("hello", msg.defaultString);
+ assertEquals("world", new String(msg.defaultBytes, InternalNano.UTF_8));
+ assertEquals("dünya", msg.defaultStringNonascii);
+ assertEquals("dünyab", new String(msg.defaultBytesNonascii, InternalNano.UTF_8));
+ assertEquals(TestAllTypesNano.BAR, msg.defaultNestedEnum);
+ assertEquals(NanoOuterClass.FOREIGN_NANO_BAR, msg.defaultForeignEnum);
+ assertEquals(UnittestImportNano.IMPORT_NANO_BAR, msg.defaultImportEnum);
+ assertEquals(Float.POSITIVE_INFINITY, msg.defaultFloatInf);
+ assertEquals(Float.NEGATIVE_INFINITY, msg.defaultFloatNegInf);
+ assertEquals(Float.NaN, msg.defaultFloatNan);
+ assertEquals(Double.POSITIVE_INFINITY, msg.defaultDoubleInf);
+ assertEquals(Double.NEGATIVE_INFINITY, msg.defaultDoubleNegInf);
+ assertEquals(Double.NaN, msg.defaultDoubleNan);
+
+ // Default values are not output, except for required fields.
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 3);
+ assertEquals(result.length, msgSerializedSize);
+ msg.clear();
+ }
+ }
+
+ public void testDifferentStringLengthsNano() throws Exception {
+ // Test string serialization roundtrip using strings of the following lengths,
+ // with ASCII and Unicode characters requiring different UTF-8 byte counts per
+ // char, hence causing the length delimiter varint to sometimes require more
+ // bytes for the Unicode strings than the ASCII string of the same length.
+ int[] lengths = new int[] {
+ 0,
+ 1,
+ (1 << 4) - 1, // 1 byte for ASCII and Unicode
+ (1 << 7) - 1, // 1 byte for ASCII, 2 bytes for Unicode
+ (1 << 11) - 1, // 2 bytes for ASCII and Unicode
+ (1 << 14) - 1, // 2 bytes for ASCII, 3 bytes for Unicode
+ (1 << 17) - 1, // 3 bytes for ASCII and Unicode
+ };
+ for (int i : lengths) {
+ testEncodingOfString('q', i); // 1 byte per char
+ testEncodingOfString('\u07FF', i); // 2 bytes per char
+ testEncodingOfString('\u0981', i); // 3 bytes per char
+ }
+ }
+
+ /** Regression test for https://github.com/google/protobuf/issues/292 */
+ public void testCorrectExceptionThrowWhenEncodingStringsWithoutEnoughSpace() throws Exception {
+ String testCase = "Foooooooo";
+ assertEquals(CodedOutputByteBufferNano.computeRawVarint32Size(testCase.length()),
+ CodedOutputByteBufferNano.computeRawVarint32Size(testCase.length() * 3));
+ assertEquals(11, CodedOutputByteBufferNano.computeStringSize(1, 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 (int i = 0; i < 11; i++) {
+ CodedOutputByteBufferNano bufferNano = CodedOutputByteBufferNano.newInstance(new byte[i]);
+ try {
+ bufferNano.writeString(1, testCase);
+ fail("Should have thrown an out of space exception");
+ } catch (CodedOutputByteBufferNano.OutOfSpaceException expected) {}
+ }
+ }
+
+ private void testEncodingOfString(char c, int length) throws InvalidProtocolBufferNanoException {
+ TestAllTypesNano testAllTypesNano = new TestAllTypesNano();
+ final String fullString = fullString(c, length);
+ testAllTypesNano.optionalString = fullString;
+ final TestAllTypesNano resultNano = new TestAllTypesNano();
+ MessageNano.mergeFrom(resultNano, MessageNano.toByteArray(testAllTypesNano));
+ assertEquals(fullString, resultNano.optionalString);
+ }
+
+ private String fullString(char c, int length) {
+ char[] result = new char[length];
+ Arrays.fill(result, c);
+ return new String(result);
+ }
+
+ public void testNanoWithHasParseFrom() throws Exception {
+ TestAllTypesNanoHas msg = null;
+ // Test false on creation, after clear and upon empty parse.
+ for (int i = 0; i < 3; i++) {
+ if (i == 0) {
+ msg = new TestAllTypesNanoHas();
+ } else if (i == 1) {
+ msg.clear();
+ } else if (i == 2) {
+ msg = TestAllTypesNanoHas.parseFrom(new byte[0]);
+ }
+ assertFalse(msg.hasOptionalInt32);
+ assertFalse(msg.hasOptionalString);
+ assertFalse(msg.hasOptionalBytes);
+ assertFalse(msg.hasOptionalNestedEnum);
+ assertFalse(msg.hasDefaultInt32);
+ assertFalse(msg.hasDefaultString);
+ assertFalse(msg.hasDefaultBytes);
+ assertFalse(msg.hasDefaultFloatNan);
+ assertFalse(msg.hasDefaultNestedEnum);
+ assertFalse(msg.hasId);
+ assertFalse(msg.hasRequiredEnum);
+ msg.optionalInt32 = 123;
+ msg.optionalNestedMessage = new TestAllTypesNanoHas.NestedMessage();
+ msg.optionalNestedMessage.bb = 2;
+ msg.optionalNestedEnum = TestAllTypesNano.BAZ;
+ }
+
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 10);
+ assertEquals(result.length, msgSerializedSize);
+
+ // Has fields true upon parse.
+ TestAllTypesNanoHas newMsg = TestAllTypesNanoHas.parseFrom(result);
+ assertEquals(123, newMsg.optionalInt32);
+ assertTrue(newMsg.hasOptionalInt32);
+ assertEquals(2, newMsg.optionalNestedMessage.bb);
+ assertTrue(newMsg.optionalNestedMessage.hasBb);
+ assertEquals(TestAllTypesNanoHas.BAZ, newMsg.optionalNestedEnum);
+ assertTrue(newMsg.hasOptionalNestedEnum);
+ }
+
+ public void testNanoWithHasSerialize() throws Exception {
+ TestAllTypesNanoHas msg = new TestAllTypesNanoHas();
+ msg.hasOptionalInt32 = true;
+ msg.hasOptionalString = true;
+ msg.hasOptionalBytes = true;
+ msg.optionalNestedMessage = new TestAllTypesNanoHas.NestedMessage();
+ msg.optionalNestedMessage.hasBb = true;
+ msg.hasOptionalNestedEnum = true;
+ msg.hasDefaultInt32 = true;
+ msg.hasDefaultString = true;
+ msg.hasDefaultBytes = true;
+ msg.hasDefaultFloatNan = true;
+ msg.hasDefaultNestedEnum = true;
+ msg.hasId = true;
+ msg.hasRequiredEnum = true;
+
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ assertEquals(result.length, msgSerializedSize);
+
+ // Now deserialize and find that all fields are set and equal to their defaults.
+ TestAllTypesNanoHas newMsg = TestAllTypesNanoHas.parseFrom(result);
+ assertTrue(newMsg.hasOptionalInt32);
+ assertTrue(newMsg.hasOptionalString);
+ assertTrue(newMsg.hasOptionalBytes);
+ assertTrue(newMsg.optionalNestedMessage.hasBb);
+ assertTrue(newMsg.hasOptionalNestedEnum);
+ assertTrue(newMsg.hasDefaultInt32);
+ assertTrue(newMsg.hasDefaultString);
+ assertTrue(newMsg.hasDefaultBytes);
+ assertTrue(newMsg.hasDefaultFloatNan);
+ assertTrue(newMsg.hasDefaultNestedEnum);
+ assertTrue(newMsg.hasId);
+ assertTrue(newMsg.hasRequiredEnum);
+ assertEquals(0, newMsg.optionalInt32);
+ assertEquals(0, newMsg.optionalString.length());
+ assertEquals(0, newMsg.optionalBytes.length);
+ assertEquals(0, newMsg.optionalNestedMessage.bb);
+ assertEquals(TestAllTypesNanoHas.FOO, newMsg.optionalNestedEnum);
+ assertEquals(41, newMsg.defaultInt32);
+ assertEquals("hello", newMsg.defaultString);
+ assertEquals("world", new String(newMsg.defaultBytes, InternalNano.UTF_8));
+ assertEquals(TestAllTypesNanoHas.BAR, newMsg.defaultNestedEnum);
+ assertEquals(Float.NaN, newMsg.defaultFloatNan);
+ assertEquals(0, newMsg.id);
+ assertEquals(TestAllTypesNanoHas.FOO, newMsg.requiredEnum);
+ }
+
+ public void testNanoWithAccessorsBasic() throws Exception {
+ TestNanoAccessors msg = new TestNanoAccessors();
+
+ // Makes sure required, repeated, and message fields are still public
+ msg.id = 3;
+ msg.repeatedBytes = new byte[2][3];
+ msg.optionalNestedMessage = null;
+
+ // Test accessors
+ assertEquals(0, msg.getOptionalInt32());
+ assertFalse(msg.hasOptionalInt32());
+ msg.setOptionalInt32(135);
+ assertEquals(135, msg.getOptionalInt32());
+ assertTrue(msg.hasOptionalInt32());
+ msg.clearOptionalInt32();
+ assertFalse(msg.hasOptionalInt32());
+ msg.setOptionalInt32(0); // default value
+ assertTrue(msg.hasOptionalInt32());
+
+ // Test NPE
+ try {
+ msg.setOptionalBytes(null);
+ fail();
+ } catch (NullPointerException expected) {}
+ try {
+ msg.setOptionalString(null);
+ fail();
+ } catch (NullPointerException expected) {}
+
+ // Test has bit on bytes field with defaults and clear() re-clones the default array
+ assertFalse(msg.hasDefaultBytes());
+ byte[] defaultBytes = msg.getDefaultBytes();
+ msg.setDefaultBytes(defaultBytes);
+ assertTrue(msg.hasDefaultBytes());
+ msg.clearDefaultBytes();
+ assertFalse(msg.hasDefaultBytes());
+ defaultBytes[0]++; // modify original array
+ assertFalse(Arrays.equals(defaultBytes, msg.getDefaultBytes()));
+
+ // Test has bits that require additional bit fields
+ assertFalse(msg.hasBitFieldCheck());
+ msg.setBitFieldCheck(0);
+ assertTrue(msg.hasBitFieldCheck());
+ assertFalse(msg.hasBeforeBitFieldCheck()); // checks bit field does not leak
+ assertFalse(msg.hasAfterBitFieldCheck());
+
+ // Test clear() clears has bits
+ msg.setOptionalString("hi");
+ msg.setDefaultString("there");
+ msg.clear();
+ assertFalse(msg.hasOptionalString());
+ assertFalse(msg.hasDefaultString());
+ assertFalse(msg.hasBitFieldCheck());
+
+ // Test set() and clear() returns itself (compiles = success)
+ msg.clear()
+ .setOptionalInt32(3)
+ .clearDefaultBytes()
+ .setOptionalString("4");
+ }
+
+ public void testNanoWithAccessorsParseFrom() throws Exception {
+ TestNanoAccessors msg = null;
+ // Test false on creation, after clear and upon empty parse.
+ for (int i = 0; i < 3; i++) {
+ if (i == 0) {
+ msg = new TestNanoAccessors();
+ } else if (i == 1) {
+ msg.clear();
+ } else if (i == 2) {
+ msg = TestNanoAccessors.parseFrom(new byte[0]);
+ }
+ assertFalse(msg.hasOptionalInt32());
+ assertFalse(msg.hasOptionalString());
+ assertFalse(msg.hasOptionalBytes());
+ assertFalse(msg.hasOptionalNestedEnum());
+ assertFalse(msg.hasDefaultInt32());
+ assertFalse(msg.hasDefaultString());
+ assertFalse(msg.hasDefaultBytes());
+ assertFalse(msg.hasDefaultFloatNan());
+ assertFalse(msg.hasDefaultNestedEnum());
+ msg.optionalNestedMessage = new TestNanoAccessors.NestedMessage();
+ msg.optionalNestedMessage.setBb(2);
+ msg.setOptionalNestedEnum(TestNanoAccessors.BAZ);
+ msg.setDefaultInt32(msg.getDefaultInt32());
+ }
+
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ //System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
+ assertTrue(msgSerializedSize == 14);
+ assertEquals(result.length, msgSerializedSize);
+
+ // Has fields true upon parse.
+ TestNanoAccessors newMsg = TestNanoAccessors.parseFrom(result);
+ assertEquals(2, newMsg.optionalNestedMessage.getBb());
+ assertTrue(newMsg.optionalNestedMessage.hasBb());
+ assertEquals(TestNanoAccessors.BAZ, newMsg.getOptionalNestedEnum());
+ assertTrue(newMsg.hasOptionalNestedEnum());
+
+ // Has field true on fields with explicit default values from wire.
+ assertTrue(newMsg.hasDefaultInt32());
+ assertEquals(41, newMsg.getDefaultInt32());
+ }
+
+ public void testNanoWithAccessorsPublicFieldTypes() throws Exception {
+ TestNanoAccessors msg = new TestNanoAccessors();
+ assertNull(msg.optionalNestedMessage);
+ assertEquals(0, msg.id);
+ assertEquals(0, msg.repeatedNestedEnum.length);
+
+ TestNanoAccessors newMsg = TestNanoAccessors.parseFrom(MessageNano.toByteArray(msg));
+ assertNull(newMsg.optionalNestedMessage);
+ assertEquals(0, newMsg.id);
+ assertEquals(0, newMsg.repeatedNestedEnum.length);
+
+ TestNanoAccessors.NestedMessage nestedMessage = new TestNanoAccessors.NestedMessage();
+ nestedMessage.setBb(5);
+ newMsg.optionalNestedMessage = nestedMessage;
+ newMsg.id = -1;
+ newMsg.repeatedNestedEnum = new int[] { TestAllTypesNano.FOO };
+
+ TestNanoAccessors newMsg2 = TestNanoAccessors.parseFrom(MessageNano.toByteArray(newMsg));
+ assertEquals(nestedMessage.getBb(), newMsg2.optionalNestedMessage.getBb());
+ assertEquals(-1, newMsg2.id);
+ assertEquals(TestAllTypesNano.FOO, newMsg2.repeatedNestedEnum[0]);
+
+ newMsg2.optionalNestedMessage = null;
+ newMsg2.id = 0;
+ newMsg2.repeatedNestedEnum = null;
+
+ TestNanoAccessors newMsg3 = TestNanoAccessors.parseFrom(MessageNano.toByteArray(newMsg2));
+ assertNull(newMsg3.optionalNestedMessage);
+ assertEquals(0, newMsg3.id);
+ assertEquals(0, newMsg3.repeatedNestedEnum.length);
+ }
+
+ public void testNanoWithAccessorsSerialize() throws Exception {
+ TestNanoAccessors msg = new TestNanoAccessors();
+ msg.setOptionalInt32(msg.getOptionalInt32());
+ msg.setOptionalString(msg.getOptionalString());
+ msg.setOptionalBytes(msg.getOptionalBytes());
+ TestNanoAccessors.NestedMessage nestedMessage = new TestNanoAccessors.NestedMessage();
+ nestedMessage.setBb(nestedMessage.getBb());
+ msg.optionalNestedMessage = nestedMessage;
+ msg.setOptionalNestedEnum(msg.getOptionalNestedEnum());
+ msg.setDefaultInt32(msg.getDefaultInt32());
+ msg.setDefaultString(msg.getDefaultString());
+ msg.setDefaultBytes(msg.getDefaultBytes());
+ msg.setDefaultFloatNan(msg.getDefaultFloatNan());
+ msg.setDefaultNestedEnum(msg.getDefaultNestedEnum());
+
+ byte [] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ assertEquals(result.length, msgSerializedSize);
+
+ // Now deserialize and find that all fields are set and equal to their defaults.
+ TestNanoAccessors newMsg = TestNanoAccessors.parseFrom(result);
+ assertTrue(newMsg.hasOptionalInt32());
+ assertTrue(newMsg.hasOptionalString());
+ assertTrue(newMsg.hasOptionalBytes());
+ assertTrue(newMsg.optionalNestedMessage.hasBb());
+ assertTrue(newMsg.hasOptionalNestedEnum());
+ assertTrue(newMsg.hasDefaultInt32());
+ assertTrue(newMsg.hasDefaultString());
+ assertTrue(newMsg.hasDefaultBytes());
+ assertTrue(newMsg.hasDefaultFloatNan());
+ assertTrue(newMsg.hasDefaultNestedEnum());
+ assertEquals(0, newMsg.getOptionalInt32());
+ assertEquals(0, newMsg.getOptionalString().length());
+ assertEquals(0, newMsg.getOptionalBytes().length);
+ assertEquals(0, newMsg.optionalNestedMessage.getBb());
+ assertEquals(TestNanoAccessors.FOO, newMsg.getOptionalNestedEnum());
+ assertEquals(41, newMsg.getDefaultInt32());
+ assertEquals("hello", newMsg.getDefaultString());
+ assertEquals("world", new String(newMsg.getDefaultBytes(), InternalNano.UTF_8));
+ assertEquals(TestNanoAccessors.BAR, newMsg.getDefaultNestedEnum());
+ assertEquals(Float.NaN, newMsg.getDefaultFloatNan());
+ assertEquals(0, newMsg.id);
+ }
+
+ public void testNanoJavaEnumStyle() throws Exception {
+ EnumClassNanos.EnumClassNano msg = new EnumClassNanos.EnumClassNano();
+ assertEquals(EnumClassNanos.FileScopeEnum.ONE, msg.one);
+ assertEquals(EnumClassNanos.EnumClassNano.MessageScopeEnum.TWO, msg.two);
+
+ EnumClassNanoMultiple msg2 = new EnumClassNanoMultiple();
+ assertEquals(FileScopeEnumMultiple.THREE, msg2.three);
+ assertEquals(EnumClassNanoMultiple.MessageScopeEnumMultiple.FOUR, msg2.four);
+ }
+
+ /**
+ * Tests that fields with a default value of NaN are not serialized when
+ * set to NaN. This is a special case as NaN != NaN, so normal equality
+ * checks don't work.
+ */
+ public void testNanoNotANumberDefaults() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.defaultDoubleNan = 0;
+ msg.defaultFloatNan = 0;
+ byte[] result = MessageNano.toByteArray(msg);
+ int msgSerializedSize = msg.getSerializedSize();
+ assertTrue(result.length == msgSerializedSize);
+ assertTrue(msgSerializedSize > 3);
+
+ msg.defaultDoubleNan = Double.NaN;
+ msg.defaultFloatNan = Float.NaN;
+ result = MessageNano.toByteArray(msg);
+ msgSerializedSize = msg.getSerializedSize();
+ assertEquals(3, result.length);
+ assertEquals(3, msgSerializedSize);
+ }
+
+ /**
+ * 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 };
+ CodedInputByteBufferNano input = CodedInputByteBufferNano.newInstance(rawBytes);
+
+ int limit = input.pushLimit(1);
+ input.skipRawBytes(1);
+ input.popLimit(limit);
+ assertEquals(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.
+ */
+ public void testSkipRawBytesPastEndOfBufferWithLimit() throws Exception {
+ byte[] rawBytes = new byte[] { 1, 2, 3, 4, 5 };
+ CodedInputByteBufferNano input = CodedInputByteBufferNano.newInstance(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(1, input.readRawByte());
+ // Skip to the end of the limit.
+ input.skipRawBytes(3);
+ assertTrue(input.isAtEnd());
+ input.popLimit(limit);
+ assertEquals(5, input.readRawByte());
+ }
+
+ // Test a smattering of various proto types for printing
+ public void testMessageNanoPrinter() {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.optionalInt32 = 14;
+ msg.optionalFloat = 42.3f;
+ msg.optionalString = "String \"with' both quotes";
+ msg.optionalBytes = new byte[] {'"', '\0', 1, 8};
+ msg.optionalGroup = new TestAllTypesNano.OptionalGroup();
+ msg.optionalGroup.a = 15;
+ msg.repeatedInt64 = new long[2];
+ msg.repeatedInt64[0] = 1L;
+ msg.repeatedInt64[1] = -1L;
+ msg.repeatedBytes = new byte[2][];
+ msg.repeatedBytes[1] = new byte[] {'h', 'e', 'l', 'l', 'o'};
+ msg.repeatedGroup = new TestAllTypesNano.RepeatedGroup[2];
+ msg.repeatedGroup[0] = new TestAllTypesNano.RepeatedGroup();
+ msg.repeatedGroup[0].a = -27;
+ msg.repeatedGroup[1] = new TestAllTypesNano.RepeatedGroup();
+ msg.repeatedGroup[1].a = -72;
+ msg.optionalNestedMessage = new TestAllTypesNano.NestedMessage();
+ msg.optionalNestedMessage.bb = 7;
+ msg.repeatedNestedMessage = new TestAllTypesNano.NestedMessage[2];
+ msg.repeatedNestedMessage[0] = new TestAllTypesNano.NestedMessage();
+ msg.repeatedNestedMessage[0].bb = 77;
+ msg.repeatedNestedMessage[1] = new TestAllTypesNano.NestedMessage();
+ msg.repeatedNestedMessage[1].bb = 88;
+ msg.optionalNestedEnum = TestAllTypesNano.BAZ;
+ msg.repeatedNestedEnum = new int[2];
+ msg.repeatedNestedEnum[0] = TestAllTypesNano.BAR;
+ msg.repeatedNestedEnum[1] = TestAllTypesNano.FOO;
+ msg.repeatedStringPiece = new String[] {null, "world"};
+ msg.setOneofString("hello");
+
+ String protoPrint = msg.toString();
+ assertTrue(protoPrint.contains("optional_int32: 14"));
+ assertTrue(protoPrint.contains("optional_float: 42.3"));
+ assertTrue(protoPrint.contains("optional_double: 0.0"));
+ assertTrue(protoPrint.contains("optional_string: \"String \\u0022with\\u0027 both quotes\""));
+ assertTrue(protoPrint.contains("optional_bytes: \"\\\"\\000\\001\\010\""));
+ assertTrue(protoPrint.contains("optional_group <\n a: 15\n>"));
+
+ assertTrue(protoPrint.contains("repeated_int64: 1\nrepeated_int64: -1"));
+ assertFalse(protoPrint.contains("repeated_bytes: \"\"")); // null should be dropped
+ assertTrue(protoPrint.contains("repeated_bytes: \"hello\""));
+ assertTrue(protoPrint.contains("repeated_group <\n a: -27\n>\n"
+ + "repeated_group <\n a: -72\n>"));
+ assertTrue(protoPrint.contains("optional_nested_message <\n bb: 7\n>"));
+ assertTrue(protoPrint.contains("repeated_nested_message <\n bb: 77\n>\n"
+ + "repeated_nested_message <\n bb: 88\n>"));
+ assertTrue(protoPrint.contains("optional_nested_enum: 3"));
+ assertTrue(protoPrint.contains("repeated_nested_enum: 2\nrepeated_nested_enum: 1"));
+ assertTrue(protoPrint.contains("default_int32: 41"));
+ assertTrue(protoPrint.contains("default_string: \"hello\""));
+ assertFalse(protoPrint.contains("repeated_string_piece: \"\"")); // null should be dropped
+ assertTrue(protoPrint.contains("repeated_string_piece: \"world\""));
+ assertTrue(protoPrint.contains("oneof_string: \"hello\""));
+ }
+
+ public void testMessageNanoPrinterAccessors() throws Exception {
+ TestNanoAccessors msg = new TestNanoAccessors();
+ msg.setOptionalInt32(13);
+ msg.setOptionalString("foo");
+ msg.setOptionalBytes(new byte[] {'"', '\0', 1, 8});
+ msg.optionalNestedMessage = new TestNanoAccessors.NestedMessage();
+ msg.optionalNestedMessage.setBb(7);
+ msg.setOptionalNestedEnum(TestNanoAccessors.BAZ);
+ msg.repeatedInt32 = new int[] { 1, -1 };
+ msg.repeatedString = new String[] { "Hello", "world" };
+ msg.repeatedBytes = new byte[2][];
+ msg.repeatedBytes[1] = new byte[] {'h', 'e', 'l', 'l', 'o'};
+ msg.repeatedNestedMessage = new TestNanoAccessors.NestedMessage[2];
+ msg.repeatedNestedMessage[0] = new TestNanoAccessors.NestedMessage();
+ msg.repeatedNestedMessage[0].setBb(5);
+ msg.repeatedNestedMessage[1] = new TestNanoAccessors.NestedMessage();
+ msg.repeatedNestedMessage[1].setBb(6);
+ msg.repeatedNestedEnum = new int[] { TestNanoAccessors.FOO, TestNanoAccessors.BAR };
+ msg.id = 33;
+
+ String protoPrint = msg.toString();
+ assertTrue(protoPrint.contains("optional_int32: 13"));
+ assertTrue(protoPrint.contains("optional_string: \"foo\""));
+ assertTrue(protoPrint.contains("optional_bytes: \"\\\"\\000\\001\\010\""));
+ assertTrue(protoPrint.contains("optional_nested_message <\n bb: 7\n>"));
+ assertTrue(protoPrint.contains("optional_nested_enum: 3"));
+ assertTrue(protoPrint.contains("repeated_int32: 1\nrepeated_int32: -1"));
+ assertTrue(protoPrint.contains("repeated_string: \"Hello\"\nrepeated_string: \"world\""));
+ assertFalse(protoPrint.contains("repeated_bytes: \"\"")); // null should be dropped
+ assertTrue(protoPrint.contains("repeated_bytes: \"hello\""));
+ assertTrue(protoPrint.contains("repeated_nested_message <\n bb: 5\n>\n"
+ + "repeated_nested_message <\n bb: 6\n>"));
+ assertTrue(protoPrint.contains("repeated_nested_enum: 1\nrepeated_nested_enum: 2"));
+ assertTrue(protoPrint.contains("id: 33"));
+ }
+
+ public void testMessageNanoPrinterForMaps() throws Exception {
+ TestMap msg = new TestMap();
+ MessageValue msgValues[] = new MessageValue[] {
+ new MessageValue(), new MessageValue()
+ };
+ msgValues[0].value = 1;
+ msgValues[1].value = 2;
+ msg.int32ToBytesField = new HashMap<Integer, byte[]>();
+ msg.int32ToBytesField.put(1, new byte[] {'"', '\0'});
+ msg.int32ToBytesField.put(2, new byte[] {1, 8});
+ msg.stringToInt32Field = new HashMap<String, Integer>();
+ msg.stringToInt32Field.put("hello", 1);
+ msg.stringToInt32Field.put("world", 2);
+ msg.int32ToMessageField = new HashMap<Integer, MapTestProto.TestMap.MessageValue>();
+ msg.int32ToMessageField.put(0, msgValues[0]);
+ msg.int32ToMessageField.put(1, msgValues[1]);
+ msg.int32ToEnumField = new HashMap<Integer, Integer>();
+ msg.int32ToEnumField.put(1, 2);
+ msg.int32ToEnumField.put(2, 3);
+ String protoPrint = msg.toString();
+
+ assertTrue(protoPrint.contains(
+ "int32_to_bytes_field <\n key: 1\n value: \"\\\"\\000\"\n>"));
+ assertTrue(protoPrint.contains(
+ "int32_to_bytes_field <\n key: 2\n value: \"\\001\\010\"\n>"));
+ assertTrue(protoPrint.contains(
+ "string_to_int32_field <\n key: \"hello\"\n value: 1\n>"));
+ assertTrue(protoPrint.contains(
+ "string_to_int32_field <\n key: \"world\"\n value: 2\n>"));
+ assertTrue(protoPrint.contains(
+ "int32_to_message_field <\n key: 0\n value <\n value: 1\n"));
+ assertTrue(protoPrint.contains(
+ "int32_to_message_field <\n key: 1\n value <\n value: 2\n"));
+ assertTrue(protoPrint.contains(
+ "int32_to_enum_field <\n key: 1\n value: 2\n>"));
+ assertTrue(protoPrint.contains(
+ "int32_to_enum_field <\n key: 2\n value: 3\n>"));
+ }
+
+ public void testExtensions() throws Exception {
+ Extensions.ExtendableMessage message = new Extensions.ExtendableMessage();
+ message.field = 5;
+ int[] int32s = {1, 2};
+ int[] uint32s = {3, 4};
+ int[] sint32s = {-5, -6};
+ long[] int64s = {7, 8};
+ long[] uint64s = {9, 10};
+ long[] sint64s = {-11, -12};
+ int[] fixed32s = {13, 14};
+ int[] sfixed32s = {-15, -16};
+ long[] fixed64s = {17, 18};
+ long[] sfixed64s = {-19, -20};
+ boolean[] bools = {true, false};
+ float[] floats = {2.1f, 2.2f};
+ double[] doubles = {2.3, 2.4};
+ int[] enums = {Extensions.SECOND_VALUE, Extensions.FIRST_VALUE};
+ String[] strings = {"vijfentwintig", "twenty-six"};
+ byte[][] bytess = {{2, 7}, {2, 8}};
+ AnotherMessage another1 = new AnotherMessage();
+ another1.string = "er shi jiu";
+ another1.value = false;
+ AnotherMessage another2 = new AnotherMessage();
+ another2.string = "trente";
+ another2.value = true;
+ AnotherMessage[] messages = {another1, another2};
+ RepeatedExtensions.RepeatedGroup group1 = new RepeatedExtensions.RepeatedGroup();
+ group1.a = 31;
+ RepeatedExtensions.RepeatedGroup group2 = new RepeatedExtensions.RepeatedGroup();
+ group2.a = 32;
+ RepeatedExtensions.RepeatedGroup[] groups = {group1, group2};
+ assertFalse(message.hasExtension(RepeatedExtensions.repeatedInt32));
+ message.setExtension(RepeatedExtensions.repeatedInt32, int32s);
+ assertTrue(message.hasExtension(RepeatedExtensions.repeatedInt32));
+ assertFalse(message.hasExtension(RepeatedExtensions.repeatedUint32));
+ message.setExtension(RepeatedExtensions.repeatedUint32, uint32s);
+ assertTrue(message.hasExtension(RepeatedExtensions.repeatedUint32));
+ message.setExtension(RepeatedExtensions.repeatedSint32, sint32s);
+ assertFalse(message.hasExtension(RepeatedExtensions.repeatedInt64));
+ message.setExtension(RepeatedExtensions.repeatedInt64, int64s);
+ assertTrue(message.hasExtension(RepeatedExtensions.repeatedInt64));
+ assertFalse(message.hasExtension(RepeatedExtensions.repeatedUint64));
+ message.setExtension(RepeatedExtensions.repeatedUint64, uint64s);
+ assertTrue(message.hasExtension(RepeatedExtensions.repeatedUint64));
+ assertFalse(message.hasExtension(RepeatedExtensions.repeatedSint64));
+ message.setExtension(RepeatedExtensions.repeatedSint64, sint64s);
+ assertTrue(message.hasExtension(RepeatedExtensions.repeatedSint64));
+ assertFalse(message.hasExtension(RepeatedExtensions.repeatedFixed32));
+ message.setExtension(RepeatedExtensions.repeatedFixed32, fixed32s);
+ assertTrue(message.hasExtension(RepeatedExtensions.repeatedFixed32));
+ assertFalse(message.hasExtension(RepeatedExtensions.repeatedSfixed32));
+ message.setExtension(RepeatedExtensions.repeatedSfixed32, sfixed32s);
+ assertTrue(message.hasExtension(RepeatedExtensions.repeatedSfixed32));
+ assertFalse(message.hasExtension(RepeatedExtensions.repeatedFixed64));
+ message.setExtension(RepeatedExtensions.repeatedFixed64, fixed64s);
+ assertTrue(message.hasExtension(RepeatedExtensions.repeatedFixed64));
+ assertFalse(message.hasExtension(RepeatedExtensions.repeatedSfixed64));
+ message.setExtension(RepeatedExtensions.repeatedSfixed64, sfixed64s);
+ assertTrue(message.hasExtension(RepeatedExtensions.repeatedSfixed64));
+ assertFalse(message.hasExtension(RepeatedExtensions.repeatedBool));
+ message.setExtension(RepeatedExtensions.repeatedBool, bools);
+ assertTrue(message.hasExtension(RepeatedExtensions.repeatedBool));
+ assertFalse(message.hasExtension(RepeatedExtensions.repeatedFloat));
+ message.setExtension(RepeatedExtensions.repeatedFloat, floats);
+ assertTrue(message.hasExtension(RepeatedExtensions.repeatedFloat));
+ assertFalse(message.hasExtension(RepeatedExtensions.repeatedDouble));
+ message.setExtension(RepeatedExtensions.repeatedDouble, doubles);
+ assertTrue(message.hasExtension(RepeatedExtensions.repeatedDouble));
+ assertFalse(message.hasExtension(RepeatedExtensions.repeatedEnum));
+ message.setExtension(RepeatedExtensions.repeatedEnum, enums);
+ assertTrue(message.hasExtension(RepeatedExtensions.repeatedEnum));
+ assertFalse(message.hasExtension(RepeatedExtensions.repeatedString));
+ message.setExtension(RepeatedExtensions.repeatedString, strings);
+ assertTrue(message.hasExtension(RepeatedExtensions.repeatedString));
+ assertFalse(message.hasExtension(RepeatedExtensions.repeatedBytes));
+ message.setExtension(RepeatedExtensions.repeatedBytes, bytess);
+ assertTrue(message.hasExtension(RepeatedExtensions.repeatedBytes));
+ assertFalse(message.hasExtension(RepeatedExtensions.repeatedMessage));
+ message.setExtension(RepeatedExtensions.repeatedMessage, messages);
+ assertTrue(message.hasExtension(RepeatedExtensions.repeatedMessage));
+ assertFalse(message.hasExtension(RepeatedExtensions.repeatedGroup));
+ message.setExtension(RepeatedExtensions.repeatedGroup, groups);
+ assertTrue(message.hasExtension(RepeatedExtensions.repeatedGroup));
+
+ byte[] data = MessageNano.toByteArray(message);
+ message = Extensions.ExtendableMessage.parseFrom(data);
+ assertEquals(5, message.field);
+
+ // Test reading back using SingularExtensions: the retrieved value should equal the last
+ // in each array.
+ assertEquals(int32s[1], (int) message.getExtension(SingularExtensions.someInt32));
+ assertEquals(uint32s[1], (int) message.getExtension(SingularExtensions.someUint32));
+ assertEquals(sint32s[1], (int) message.getExtension(SingularExtensions.someSint32));
+ assertEquals(int64s[1], (long) message.getExtension(SingularExtensions.someInt64));
+ assertEquals(uint64s[1], (long) message.getExtension(SingularExtensions.someUint64));
+ assertEquals(sint64s[1], (long) message.getExtension(SingularExtensions.someSint64));
+ assertEquals(fixed32s[1], (int) message.getExtension(SingularExtensions.someFixed32));
+ assertEquals(sfixed32s[1], (int) message.getExtension(SingularExtensions.someSfixed32));
+ assertEquals(fixed64s[1], (long) message.getExtension(SingularExtensions.someFixed64));
+ assertEquals(sfixed64s[1], (long) message.getExtension(SingularExtensions.someSfixed64));
+ assertEquals(bools[1], (boolean) message.getExtension(SingularExtensions.someBool));
+ assertEquals(floats[1], (float) message.getExtension(SingularExtensions.someFloat));
+ assertEquals(doubles[1], (double) message.getExtension(SingularExtensions.someDouble));
+ assertEquals(enums[1], (int) message.getExtension(SingularExtensions.someEnum));
+ assertEquals(strings[1], message.getExtension(SingularExtensions.someString));
+ assertTrue(Arrays.equals(bytess[1], message.getExtension(SingularExtensions.someBytes)));
+ AnotherMessage deserializedMessage = message.getExtension(SingularExtensions.someMessage);
+ assertEquals(another2.string, deserializedMessage.string);
+ assertEquals(another2.value, deserializedMessage.value);
+ assertEquals(group2.a, message.getExtension(SingularExtensions.someGroup).a);
+
+ // Test reading back using RepeatedExtensions: the arrays should be equal.
+ message = Extensions.ExtendableMessage.parseFrom(data);
+ assertEquals(5, message.field);
+ assertTrue(Arrays.equals(int32s, message.getExtension(RepeatedExtensions.repeatedInt32)));
+ assertTrue(Arrays.equals(uint32s, message.getExtension(RepeatedExtensions.repeatedUint32)));
+ assertTrue(Arrays.equals(sint32s, message.getExtension(RepeatedExtensions.repeatedSint32)));
+ assertTrue(Arrays.equals(int64s, message.getExtension(RepeatedExtensions.repeatedInt64)));
+ assertTrue(Arrays.equals(uint64s, message.getExtension(RepeatedExtensions.repeatedUint64)));
+ assertTrue(Arrays.equals(sint64s, message.getExtension(RepeatedExtensions.repeatedSint64)));
+ assertTrue(Arrays.equals(fixed32s, message.getExtension(RepeatedExtensions.repeatedFixed32)));
+ assertTrue(Arrays.equals(sfixed32s, message.getExtension(RepeatedExtensions.repeatedSfixed32)));
+ assertTrue(Arrays.equals(fixed64s, message.getExtension(RepeatedExtensions.repeatedFixed64)));
+ assertTrue(Arrays.equals(sfixed64s, message.getExtension(RepeatedExtensions.repeatedSfixed64)));
+ assertTrue(Arrays.equals(bools, message.getExtension(RepeatedExtensions.repeatedBool)));
+ assertTrue(Arrays.equals(floats, message.getExtension(RepeatedExtensions.repeatedFloat)));
+ assertTrue(Arrays.equals(doubles, message.getExtension(RepeatedExtensions.repeatedDouble)));
+ assertTrue(Arrays.equals(enums, message.getExtension(RepeatedExtensions.repeatedEnum)));
+ assertTrue(Arrays.equals(strings, message.getExtension(RepeatedExtensions.repeatedString)));
+ byte[][] deserializedRepeatedBytes = message.getExtension(RepeatedExtensions.repeatedBytes);
+ assertEquals(2, deserializedRepeatedBytes.length);
+ assertTrue(Arrays.equals(bytess[0], deserializedRepeatedBytes[0]));
+ assertTrue(Arrays.equals(bytess[1], deserializedRepeatedBytes[1]));
+ AnotherMessage[] deserializedRepeatedMessage =
+ message.getExtension(RepeatedExtensions.repeatedMessage);
+ assertEquals(2, deserializedRepeatedMessage.length);
+ assertEquals(another1.string, deserializedRepeatedMessage[0].string);
+ assertEquals(another1.value, deserializedRepeatedMessage[0].value);
+ assertEquals(another2.string, deserializedRepeatedMessage[1].string);
+ assertEquals(another2.value, deserializedRepeatedMessage[1].value);
+ RepeatedExtensions.RepeatedGroup[] deserializedRepeatedGroup =
+ message.getExtension(RepeatedExtensions.repeatedGroup);
+ assertEquals(2, deserializedRepeatedGroup.length);
+ assertEquals(group1.a, deserializedRepeatedGroup[0].a);
+ assertEquals(group2.a, deserializedRepeatedGroup[1].a);
+
+ message = Extensions.ExtendableMessage.parseFrom(data);
+ assertEquals(5, message.field);
+ // Test hasExtension using PackedExtensions.
+ assertTrue(message.hasExtension(PackedExtensions.packedInt32));
+ assertTrue(message.hasExtension(PackedExtensions.packedUint32));
+ assertTrue(message.hasExtension(PackedExtensions.packedSint32));
+ assertTrue(message.hasExtension(PackedExtensions.packedInt64));
+ assertTrue(message.hasExtension(PackedExtensions.packedUint64));
+ assertTrue(message.hasExtension(PackedExtensions.packedSint64));
+ assertTrue(message.hasExtension(PackedExtensions.packedFixed32));
+ assertTrue(message.hasExtension(PackedExtensions.packedSfixed32));
+ assertTrue(message.hasExtension(PackedExtensions.packedFixed64));
+ assertTrue(message.hasExtension(PackedExtensions.packedSfixed64));
+ assertTrue(message.hasExtension(PackedExtensions.packedBool));
+ assertTrue(message.hasExtension(PackedExtensions.packedFloat));
+ assertTrue(message.hasExtension(PackedExtensions.packedDouble));
+ assertTrue(message.hasExtension(PackedExtensions.packedEnum));
+
+ // Test reading back using PackedExtensions: the arrays should be equal, even the fields
+ // are non-packed.
+ assertTrue(Arrays.equals(int32s, message.getExtension(PackedExtensions.packedInt32)));
+ assertTrue(Arrays.equals(uint32s, message.getExtension(PackedExtensions.packedUint32)));
+ assertTrue(Arrays.equals(sint32s, message.getExtension(PackedExtensions.packedSint32)));
+ assertTrue(Arrays.equals(int64s, message.getExtension(PackedExtensions.packedInt64)));
+ assertTrue(Arrays.equals(uint64s, message.getExtension(PackedExtensions.packedUint64)));
+ assertTrue(Arrays.equals(sint64s, message.getExtension(PackedExtensions.packedSint64)));
+ assertTrue(Arrays.equals(fixed32s, message.getExtension(PackedExtensions.packedFixed32)));
+ assertTrue(Arrays.equals(sfixed32s, message.getExtension(PackedExtensions.packedSfixed32)));
+ assertTrue(Arrays.equals(fixed64s, message.getExtension(PackedExtensions.packedFixed64)));
+ assertTrue(Arrays.equals(sfixed64s, message.getExtension(PackedExtensions.packedSfixed64)));
+ assertTrue(Arrays.equals(bools, message.getExtension(PackedExtensions.packedBool)));
+ assertTrue(Arrays.equals(floats, message.getExtension(PackedExtensions.packedFloat)));
+ assertTrue(Arrays.equals(doubles, message.getExtension(PackedExtensions.packedDouble)));
+ assertTrue(Arrays.equals(enums, message.getExtension(PackedExtensions.packedEnum)));
+
+ // Now set the packable extension values using PackedExtensions so they're serialized packed.
+ message.setExtension(PackedExtensions.packedInt32, int32s);
+ message.setExtension(PackedExtensions.packedUint32, uint32s);
+ message.setExtension(PackedExtensions.packedSint32, sint32s);
+ message.setExtension(PackedExtensions.packedInt64, int64s);
+ message.setExtension(PackedExtensions.packedUint64, uint64s);
+ message.setExtension(PackedExtensions.packedSint64, sint64s);
+ message.setExtension(PackedExtensions.packedFixed32, fixed32s);
+ message.setExtension(PackedExtensions.packedSfixed32, sfixed32s);
+ message.setExtension(PackedExtensions.packedFixed64, fixed64s);
+ message.setExtension(PackedExtensions.packedSfixed64, sfixed64s);
+ message.setExtension(PackedExtensions.packedBool, bools);
+ message.setExtension(PackedExtensions.packedFloat, floats);
+ message.setExtension(PackedExtensions.packedDouble, doubles);
+ message.setExtension(PackedExtensions.packedEnum, enums);
+
+ // And read back using non-packed RepeatedExtensions.
+ byte[] data2 = MessageNano.toByteArray(message);
+ message = MessageNano.mergeFrom(new Extensions.ExtendableMessage(), data2);
+ assertTrue(Arrays.equals(int32s, message.getExtension(RepeatedExtensions.repeatedInt32)));
+ assertTrue(Arrays.equals(uint32s, message.getExtension(RepeatedExtensions.repeatedUint32)));
+ assertTrue(Arrays.equals(sint32s, message.getExtension(RepeatedExtensions.repeatedSint32)));
+ assertTrue(Arrays.equals(int64s, message.getExtension(RepeatedExtensions.repeatedInt64)));
+ assertTrue(Arrays.equals(uint64s, message.getExtension(RepeatedExtensions.repeatedUint64)));
+ assertTrue(Arrays.equals(sint64s, message.getExtension(RepeatedExtensions.repeatedSint64)));
+ assertTrue(Arrays.equals(fixed32s, message.getExtension(RepeatedExtensions.repeatedFixed32)));
+ assertTrue(Arrays.equals(sfixed32s, message.getExtension(RepeatedExtensions.repeatedSfixed32)));
+ assertTrue(Arrays.equals(fixed64s, message.getExtension(RepeatedExtensions.repeatedFixed64)));
+ assertTrue(Arrays.equals(sfixed64s, message.getExtension(RepeatedExtensions.repeatedSfixed64)));
+ assertTrue(Arrays.equals(bools, message.getExtension(RepeatedExtensions.repeatedBool)));
+ assertTrue(Arrays.equals(floats, message.getExtension(RepeatedExtensions.repeatedFloat)));
+ assertTrue(Arrays.equals(doubles, message.getExtension(RepeatedExtensions.repeatedDouble)));
+ assertTrue(Arrays.equals(enums, message.getExtension(RepeatedExtensions.repeatedEnum)));
+
+ // Clone the message and ensure it's still equal.
+ Extensions.ExtendableMessage clone = message.clone();
+ assertEquals(clone, message);
+ }
+
+ public void testNullExtensions() throws Exception {
+ // Check that clearing the extension on an empty message is a no-op.
+ Extensions.ExtendableMessage message = new Extensions.ExtendableMessage();
+ assertFalse(message.hasExtension(SingularExtensions.someMessage));
+ message.setExtension(SingularExtensions.someMessage, null);
+ assertFalse(message.hasExtension(SingularExtensions.someMessage));
+ assertEquals(0, MessageNano.toByteArray(message).length);
+
+ // Check that the message is empty after setting and clearing an extension.
+ AnotherMessage another = new AnotherMessage();
+ assertFalse(message.hasExtension(SingularExtensions.someMessage));
+ message.setExtension(SingularExtensions.someMessage, another);
+ assertTrue(message.hasExtension(SingularExtensions.someMessage));
+ assertTrue(MessageNano.toByteArray(message).length > 0);
+ message.setExtension(SingularExtensions.someMessage, null);
+ assertFalse(message.hasExtension(SingularExtensions.someMessage));
+ assertEquals(0, MessageNano.toByteArray(message).length);
+ }
+
+ public void testExtensionsMutation() {
+ Extensions.ExtendableMessage extendableMessage = new Extensions.ExtendableMessage();
+ extendableMessage.setExtension(SingularExtensions.someMessage,
+ new Extensions.AnotherMessage());
+
+ extendableMessage.getExtension(SingularExtensions.someMessage).string = "not empty";
+
+ assertEquals("not empty",
+ extendableMessage.getExtension(SingularExtensions.someMessage).string);
+ }
+
+ public void testExtensionsMutation_Equals() throws InvalidProtocolBufferNanoException {
+ Extensions.ExtendableMessage extendableMessage = new Extensions.ExtendableMessage();
+ extendableMessage.field = 5;
+ int int32 = 42;
+ int[] uint32s = {3, 4};
+ int[] sint32s = {-5, -6};
+ long[] int64s = {7, 8};
+ long[] uint64s = {9, 10};
+ long[] sint64s = {-11, -12};
+ int[] fixed32s = {13, 14};
+ int[] sfixed32s = {-15, -16};
+ long[] fixed64s = {17, 18};
+ long[] sfixed64s = {-19, -20};
+ boolean[] bools = {true, false};
+ float[] floats = {2.1f, 2.2f};
+ double[] doubles = {2.3, 2.4};
+ int[] enums = {Extensions.SECOND_VALUE, Extensions.FIRST_VALUE};
+ String[] strings = {"vijfentwintig", "twenty-six"};
+ byte[][] bytess = {{2, 7}, {2, 8}};
+ AnotherMessage another1 = new AnotherMessage();
+ another1.string = "er shi jiu";
+ another1.value = false;
+ AnotherMessage another2 = new AnotherMessage();
+ another2.string = "trente";
+ another2.value = true;
+ AnotherMessage[] messages = {another1, another2};
+ RepeatedExtensions.RepeatedGroup group1 = new RepeatedExtensions.RepeatedGroup();
+ group1.a = 31;
+ RepeatedExtensions.RepeatedGroup group2 = new RepeatedExtensions.RepeatedGroup();
+ group2.a = 32;
+ RepeatedExtensions.RepeatedGroup[] groups = {group1, group2};
+ extendableMessage.setExtension(SingularExtensions.someInt32, int32);
+ extendableMessage.setExtension(RepeatedExtensions.repeatedUint32, uint32s);
+ extendableMessage.setExtension(RepeatedExtensions.repeatedSint32, sint32s);
+ extendableMessage.setExtension(RepeatedExtensions.repeatedInt64, int64s);
+ extendableMessage.setExtension(RepeatedExtensions.repeatedUint64, uint64s);
+ extendableMessage.setExtension(RepeatedExtensions.repeatedSint64, sint64s);
+ extendableMessage.setExtension(RepeatedExtensions.repeatedFixed32, fixed32s);
+ extendableMessage.setExtension(RepeatedExtensions.repeatedSfixed32, sfixed32s);
+ extendableMessage.setExtension(RepeatedExtensions.repeatedFixed64, fixed64s);
+ extendableMessage.setExtension(RepeatedExtensions.repeatedSfixed64, sfixed64s);
+ extendableMessage.setExtension(RepeatedExtensions.repeatedBool, bools);
+ extendableMessage.setExtension(RepeatedExtensions.repeatedFloat, floats);
+ extendableMessage.setExtension(RepeatedExtensions.repeatedDouble, doubles);
+ extendableMessage.setExtension(RepeatedExtensions.repeatedEnum, enums);
+ extendableMessage.setExtension(RepeatedExtensions.repeatedString, strings);
+ extendableMessage.setExtension(RepeatedExtensions.repeatedBytes, bytess);
+ extendableMessage.setExtension(RepeatedExtensions.repeatedMessage, messages);
+ extendableMessage.setExtension(RepeatedExtensions.repeatedGroup, groups);
+
+ byte[] data = MessageNano.toByteArray(extendableMessage);
+
+ extendableMessage = Extensions.ExtendableMessage.parseFrom(data);
+ Extensions.ExtendableMessage messageCopy = Extensions.ExtendableMessage.parseFrom(data);
+
+ // Without deserialising.
+ assertEquals(extendableMessage, messageCopy);
+ assertEquals(extendableMessage.hashCode(), messageCopy.hashCode());
+
+ // Only one deserialized.
+ extendableMessage.getExtension(SingularExtensions.someInt32);
+ extendableMessage.getExtension(RepeatedExtensions.repeatedUint32);
+ extendableMessage.getExtension(RepeatedExtensions.repeatedSint32);
+ extendableMessage.getExtension(RepeatedExtensions.repeatedInt64);
+ extendableMessage.getExtension(RepeatedExtensions.repeatedUint64);
+ extendableMessage.getExtension(RepeatedExtensions.repeatedSint64);
+ extendableMessage.getExtension(RepeatedExtensions.repeatedFixed32);
+ extendableMessage.getExtension(RepeatedExtensions.repeatedSfixed32);
+ extendableMessage.getExtension(RepeatedExtensions.repeatedFixed64);
+ extendableMessage.getExtension(RepeatedExtensions.repeatedSfixed64);
+ extendableMessage.getExtension(RepeatedExtensions.repeatedBool);
+ extendableMessage.getExtension(RepeatedExtensions.repeatedFloat);
+ extendableMessage.getExtension(RepeatedExtensions.repeatedDouble);
+ extendableMessage.getExtension(RepeatedExtensions.repeatedEnum);
+ extendableMessage.getExtension(RepeatedExtensions.repeatedString);
+ extendableMessage.getExtension(RepeatedExtensions.repeatedBytes);
+ extendableMessage.getExtension(RepeatedExtensions.repeatedMessage);
+ extendableMessage.getExtension(RepeatedExtensions.repeatedGroup);
+ assertEquals(extendableMessage, messageCopy);
+ assertEquals(extendableMessage.hashCode(), messageCopy.hashCode());
+
+ // Both deserialized.
+ messageCopy.getExtension(SingularExtensions.someInt32);
+ messageCopy.getExtension(RepeatedExtensions.repeatedUint32);
+ messageCopy.getExtension(RepeatedExtensions.repeatedSint32);
+ messageCopy.getExtension(RepeatedExtensions.repeatedInt64);
+ messageCopy.getExtension(RepeatedExtensions.repeatedUint64);
+ messageCopy.getExtension(RepeatedExtensions.repeatedSint64);
+ messageCopy.getExtension(RepeatedExtensions.repeatedFixed32);
+ messageCopy.getExtension(RepeatedExtensions.repeatedSfixed32);
+ messageCopy.getExtension(RepeatedExtensions.repeatedFixed64);
+ messageCopy.getExtension(RepeatedExtensions.repeatedSfixed64);
+ messageCopy.getExtension(RepeatedExtensions.repeatedBool);
+ messageCopy.getExtension(RepeatedExtensions.repeatedFloat);
+ messageCopy.getExtension(RepeatedExtensions.repeatedDouble);
+ messageCopy.getExtension(RepeatedExtensions.repeatedEnum);
+ messageCopy.getExtension(RepeatedExtensions.repeatedString);
+ messageCopy.getExtension(RepeatedExtensions.repeatedBytes);
+ messageCopy.getExtension(RepeatedExtensions.repeatedMessage);
+ messageCopy.getExtension(RepeatedExtensions.repeatedGroup);
+ assertEquals(extendableMessage, messageCopy);
+ assertEquals(extendableMessage.hashCode(), messageCopy.hashCode());
+
+ // Change one, make sure they are still different.
+ messageCopy.getExtension(RepeatedExtensions.repeatedMessage)[0].string = "not empty";
+ assertFalse(extendableMessage.equals(messageCopy));
+
+ // Even if the extension hasn't been deserialized.
+ extendableMessage = Extensions.ExtendableMessage.parseFrom(data);
+ assertFalse(extendableMessage.equals(messageCopy));
+ }
+
+ public void testExtensionsCaching() {
+ Extensions.ExtendableMessage extendableMessage = new Extensions.ExtendableMessage();
+ extendableMessage.setExtension(SingularExtensions.someMessage,
+ new Extensions.AnotherMessage());
+ assertSame("Consecutive calls to getExtensions should return the same object",
+ extendableMessage.getExtension(SingularExtensions.someMessage),
+ extendableMessage.getExtension(SingularExtensions.someMessage));
+ }
+
+ public void testUnknownFields() throws Exception {
+ // Check that we roundtrip (serialize and deserialize) unrecognized fields.
+ AnotherMessage message = new AnotherMessage();
+ message.string = "Hello World";
+ message.value = false;
+
+ byte[] bytes = MessageNano.toByteArray(message);
+ int extraFieldSize = CodedOutputByteBufferNano.computeStringSize(
+ 1001, "This is an unknown field");
+ byte[] newBytes = new byte[bytes.length + extraFieldSize];
+ System.arraycopy(bytes, 0, newBytes, 0, bytes.length);
+ CodedOutputByteBufferNano.newInstance(newBytes, bytes.length, extraFieldSize)
+ .writeString(1001, "This is an unknown field");
+
+ // Deserialize with an unknown field.
+ AnotherMessage deserialized = AnotherMessage.parseFrom(newBytes);
+ byte[] serialized = MessageNano.toByteArray(deserialized);
+
+ assertEquals(newBytes.length, serialized.length);
+
+ // Clear, and make sure it clears everything.
+ deserialized.clear();
+ assertEquals(0, MessageNano.toByteArray(deserialized).length);
+ }
+
+ public void testMergeFrom() throws Exception {
+ SimpleMessageNano message = new SimpleMessageNano();
+ message.d = 123;
+ byte[] bytes = MessageNano.toByteArray(message);
+
+ SimpleMessageNano newMessage = MessageNano.mergeFrom(new SimpleMessageNano(), bytes);
+ assertEquals(message.d, newMessage.d);
+ }
+
+ public void testJavaKeyword() throws Exception {
+ TestAllTypesNano msg = new TestAllTypesNano();
+ msg.synchronized_ = 123;
+ assertEquals(123, msg.synchronized_);
+ }
+
+ public void testReferenceTypesForPrimitives() throws Exception {
+ NanoReferenceTypes.TestAllTypesNano message = new NanoReferenceTypes.TestAllTypesNano();
+
+ // Base check - when nothing is set, we serialize nothing.
+ assertHasWireData(message, false);
+
+ message.defaultBool = true;
+ assertHasWireData(message, true);
+
+ message.defaultBool = false;
+ assertHasWireData(message, true);
+
+ message.defaultBool = null;
+ assertHasWireData(message, false);
+
+ message.defaultInt32 = 5;
+ assertHasWireData(message, true);
+
+ message.defaultInt32 = null;
+ assertHasWireData(message, false);
+
+ message.defaultInt64 = 123456L;
+ assertHasWireData(message, true);
+
+ message.defaultInt64 = null;
+ assertHasWireData(message, false);
+
+ message.defaultFloat = 1f;
+ assertHasWireData(message, true);
+
+ message.defaultFloat = null;
+ assertHasWireData(message, false);
+
+ message.defaultDouble = 2.1;
+ assertHasWireData(message, true);
+
+ message.defaultDouble = null;
+ assertHasWireData(message, false);
+
+ message.defaultString = "hello";
+ assertHasWireData(message, true);
+
+ message.defaultString = null;
+ assertHasWireData(message, false);
+
+ message.defaultBytes = new byte[] { 1, 2, 3 };
+ assertHasWireData(message, true);
+
+ message.defaultBytes = null;
+ assertHasWireData(message, false);
+ }
+
+ public void testHashCodeEquals() throws Exception {
+ // Complete equality:
+ TestAllTypesNano a = createMessageForHashCodeEqualsTest();
+ TestAllTypesNano aEquivalent = createMessageForHashCodeEqualsTest();
+
+ assertTrue(MessageNano.messageNanoEquals(a, aEquivalent));
+ assertFalse(MessageNano.messageNanoEquals(a, new TestAllTypesNano()));
+
+ // Null and empty array for repeated fields equality:
+ TestAllTypesNano b = createMessageForHashCodeEqualsTest();
+ b.repeatedBool = null;
+ b.repeatedFloat = new float[0];
+ TestAllTypesNano bEquivalent = createMessageForHashCodeEqualsTest();
+ bEquivalent.repeatedBool = new boolean[0];
+ bEquivalent.repeatedFloat = null;
+
+ // Ref-element-type repeated fields use non-null subsequence equality:
+ TestAllTypesNano c = createMessageForHashCodeEqualsTest();
+ c.repeatedString = null;
+ c.repeatedStringPiece = new String[] {null, "one", null, "two"};
+ c.repeatedBytes = new byte[][] {{3, 4}, null};
+ TestAllTypesNano cEquivalent = createMessageForHashCodeEqualsTest();
+ cEquivalent.repeatedString = new String[3];
+ cEquivalent.repeatedStringPiece = new String[] {"one", "two", null};
+ cEquivalent.repeatedBytes = new byte[][] {{3, 4}};
+
+ // Complete equality for messages with has fields:
+ TestAllTypesNanoHas d = createMessageWithHasForHashCodeEqualsTest();
+ TestAllTypesNanoHas dEquivalent = createMessageWithHasForHashCodeEqualsTest();
+
+ // If has-fields exist, fields with the same default values but
+ // different has-field values are different.
+ TestAllTypesNanoHas e = createMessageWithHasForHashCodeEqualsTest();
+ e.optionalInt32++; // make different from d
+ e.hasDefaultString = false;
+ TestAllTypesNanoHas eDifferent = createMessageWithHasForHashCodeEqualsTest();
+ eDifferent.optionalInt32 = e.optionalInt32;
+ eDifferent.hasDefaultString = true;
+
+ // Complete equality for messages with accessors:
+ TestNanoAccessors f = createMessageWithAccessorsForHashCodeEqualsTest();
+ TestNanoAccessors fEquivalent = createMessageWithAccessorsForHashCodeEqualsTest();
+
+ // If using accessors, explicitly setting a field to its default value
+ // should make the message different.
+ TestNanoAccessors g = createMessageWithAccessorsForHashCodeEqualsTest();
+ g.setOptionalInt32(g.getOptionalInt32() + 1); // make different from f
+ g.clearDefaultString();
+ TestNanoAccessors gDifferent = createMessageWithAccessorsForHashCodeEqualsTest();
+ gDifferent.setOptionalInt32(g.getOptionalInt32());
+ gDifferent.setDefaultString(g.getDefaultString());
+
+ // Complete equality for reference typed messages:
+ NanoReferenceTypes.TestAllTypesNano h = createRefTypedMessageForHashCodeEqualsTest();
+ NanoReferenceTypes.TestAllTypesNano hEquivalent = createRefTypedMessageForHashCodeEqualsTest();
+
+ // Inequality of null and default value for reference typed messages:
+ NanoReferenceTypes.TestAllTypesNano i = createRefTypedMessageForHashCodeEqualsTest();
+ i.optionalInt32 = 1; // make different from h
+ i.optionalFloat = null;
+ NanoReferenceTypes.TestAllTypesNano iDifferent = createRefTypedMessageForHashCodeEqualsTest();
+ iDifferent.optionalInt32 = i.optionalInt32;
+ iDifferent.optionalFloat = 0.0f;
+
+ HashMap<MessageNano, String> hashMap = new HashMap<MessageNano, String>();
+ hashMap.put(a, "a");
+ hashMap.put(b, "b");
+ hashMap.put(c, "c");
+ hashMap.put(d, "d");
+ hashMap.put(e, "e");
+ hashMap.put(f, "f");
+ hashMap.put(g, "g");
+ hashMap.put(h, "h");
+ hashMap.put(i, "i");
+
+ assertEquals(9, hashMap.size()); // a-i should be different from each other.
+
+ assertEquals("a", hashMap.get(a));
+ assertEquals("a", hashMap.get(aEquivalent));
+
+ assertEquals("b", hashMap.get(b));
+ assertEquals("b", hashMap.get(bEquivalent));
+
+ assertEquals("c", hashMap.get(c));
+ assertEquals("c", hashMap.get(cEquivalent));
+
+ assertEquals("d", hashMap.get(d));
+ assertEquals("d", hashMap.get(dEquivalent));
+
+ assertEquals("e", hashMap.get(e));
+ assertNull(hashMap.get(eDifferent));
+
+ assertEquals("f", hashMap.get(f));
+ assertEquals("f", hashMap.get(fEquivalent));
+
+ assertEquals("g", hashMap.get(g));
+ assertNull(hashMap.get(gDifferent));
+
+ assertEquals("h", hashMap.get(h));
+ assertEquals("h", hashMap.get(hEquivalent));
+
+ assertEquals("i", hashMap.get(i));
+ assertNull(hashMap.get(iDifferent));
+ }
+
+ private TestAllTypesNano createMessageForHashCodeEqualsTest() {
+ TestAllTypesNano message = new TestAllTypesNano();
+ message.optionalInt32 = 5;
+ message.optionalInt64 = 777;
+ message.optionalFloat = 1.0f;
+ message.optionalDouble = 2.0;
+ message.optionalBool = true;
+ message.optionalString = "Hello";
+ message.optionalBytes = new byte[] { 1, 2, 3 };
+ message.optionalNestedMessage = new TestAllTypesNano.NestedMessage();
+ message.optionalNestedMessage.bb = 27;
+ message.optionalNestedEnum = TestAllTypesNano.BAR;
+ message.repeatedInt32 = new int[] { 5, 6, 7, 8 };
+ message.repeatedInt64 = new long[] { 27L, 28L, 29L };
+ message.repeatedFloat = new float[] { 5.0f, 6.0f };
+ message.repeatedDouble = new double[] { 99.1, 22.5 };
+ message.repeatedBool = new boolean[] { true, false, true };
+ message.repeatedString = new String[] { "One", "Two" };
+ message.repeatedBytes = new byte[][] { { 2, 7 }, { 2, 7 } };
+ message.repeatedNestedMessage = new TestAllTypesNano.NestedMessage[] {
+ message.optionalNestedMessage,
+ message.optionalNestedMessage
+ };
+ message.repeatedNestedEnum = new int[] {
+ TestAllTypesNano.BAR,
+ TestAllTypesNano.BAZ
+ };
+ message.setOneofUint32(3);
+ return message;
+ }
+
+ private TestAllTypesNanoHas createMessageWithHasForHashCodeEqualsTest() {
+ TestAllTypesNanoHas message = new TestAllTypesNanoHas();
+ message.optionalInt32 = 5;
+ message.optionalString = "Hello";
+ message.optionalBytes = new byte[] { 1, 2, 3 };
+ message.optionalNestedMessage = new TestAllTypesNanoHas.NestedMessage();
+ message.optionalNestedMessage.bb = 27;
+ message.optionalNestedEnum = TestAllTypesNano.BAR;
+ message.repeatedInt32 = new int[] { 5, 6, 7, 8 };
+ message.repeatedString = new String[] { "One", "Two" };
+ message.repeatedBytes = new byte[][] { { 2, 7 }, { 2, 7 } };
+ message.repeatedNestedMessage = new TestAllTypesNanoHas.NestedMessage[] {
+ message.optionalNestedMessage,
+ message.optionalNestedMessage
+ };
+ message.repeatedNestedEnum = new int[] {
+ TestAllTypesNano.BAR,
+ TestAllTypesNano.BAZ
+ };
+ return message;
+ }
+
+ private TestNanoAccessors createMessageWithAccessorsForHashCodeEqualsTest() {
+ TestNanoAccessors message = new TestNanoAccessors()
+ .setOptionalInt32(5)
+ .setOptionalString("Hello")
+ .setOptionalBytes(new byte[] {1, 2, 3})
+ .setOptionalNestedEnum(TestNanoAccessors.BAR);
+ message.optionalNestedMessage = new TestNanoAccessors.NestedMessage().setBb(27);
+ message.repeatedInt32 = new int[] { 5, 6, 7, 8 };
+ message.repeatedString = new String[] { "One", "Two" };
+ message.repeatedBytes = new byte[][] { { 2, 7 }, { 2, 7 } };
+ message.repeatedNestedMessage = new TestNanoAccessors.NestedMessage[] {
+ message.optionalNestedMessage,
+ message.optionalNestedMessage
+ };
+ message.repeatedNestedEnum = new int[] {
+ TestAllTypesNano.BAR,
+ TestAllTypesNano.BAZ
+ };
+ return message;
+ }
+
+ private NanoReferenceTypes.TestAllTypesNano createRefTypedMessageForHashCodeEqualsTest() {
+ NanoReferenceTypes.TestAllTypesNano message = new NanoReferenceTypes.TestAllTypesNano();
+ message.optionalInt32 = 5;
+ message.optionalInt64 = 777L;
+ message.optionalFloat = 1.0f;
+ message.optionalDouble = 2.0;
+ message.optionalBool = true;
+ message.optionalString = "Hello";
+ message.optionalBytes = new byte[] { 1, 2, 3 };
+ message.optionalNestedMessage =
+ new NanoReferenceTypes.TestAllTypesNano.NestedMessage();
+ message.optionalNestedMessage.foo = 27;
+ message.optionalNestedEnum = NanoReferenceTypes.TestAllTypesNano.BAR;
+ message.repeatedInt32 = new int[] { 5, 6, 7, 8 };
+ message.repeatedInt64 = new long[] { 27L, 28L, 29L };
+ message.repeatedFloat = new float[] { 5.0f, 6.0f };
+ message.repeatedDouble = new double[] { 99.1, 22.5 };
+ message.repeatedBool = new boolean[] { true, false, true };
+ message.repeatedString = new String[] { "One", "Two" };
+ message.repeatedBytes = new byte[][] { { 2, 7 }, { 2, 7 } };
+ message.repeatedNestedMessage =
+ new NanoReferenceTypes.TestAllTypesNano.NestedMessage[] {
+ message.optionalNestedMessage,
+ message.optionalNestedMessage
+ };
+ message.repeatedNestedEnum = new int[] {
+ NanoReferenceTypes.TestAllTypesNano.BAR,
+ NanoReferenceTypes.TestAllTypesNano.BAZ
+ };
+ return message;
+ }
+
+ public void testEqualsWithSpecialFloatingPointValues() throws Exception {
+ // Checks that the nano implementation complies with Object.equals() when treating
+ // floating point numbers, i.e. NaN == NaN and +0.0 != -0.0.
+ // This test assumes that the generated equals() implementations are symmetric, so
+ // there will only be one direction for each equality check.
+
+ TestAllTypesNano m1 = new TestAllTypesNano();
+ m1.optionalFloat = Float.NaN;
+ m1.optionalDouble = Double.NaN;
+ TestAllTypesNano m2 = new TestAllTypesNano();
+ m2.optionalFloat = Float.NaN;
+ m2.optionalDouble = Double.NaN;
+ assertTrue(m1.equals(m2));
+ assertTrue(m1.equals(
+ MessageNano.mergeFrom(new TestAllTypesNano(), MessageNano.toByteArray(m1))));
+
+ m1.optionalFloat = +0f;
+ m2.optionalFloat = -0f;
+ assertFalse(m1.equals(m2));
+
+ m1.optionalFloat = -0f;
+ m1.optionalDouble = +0d;
+ m2.optionalDouble = -0d;
+ assertFalse(m1.equals(m2));
+
+ m1.optionalDouble = -0d;
+ assertTrue(m1.equals(m2));
+ assertFalse(m1.equals(new TestAllTypesNano())); // -0 does not equals() the default +0
+ assertTrue(m1.equals(
+ MessageNano.mergeFrom(new TestAllTypesNano(), MessageNano.toByteArray(m1))));
+
+ // -------
+
+ TestAllTypesNanoHas m3 = new TestAllTypesNanoHas();
+ m3.optionalFloat = Float.NaN;
+ m3.hasOptionalFloat = true;
+ m3.optionalDouble = Double.NaN;
+ m3.hasOptionalDouble = true;
+ TestAllTypesNanoHas m4 = new TestAllTypesNanoHas();
+ m4.optionalFloat = Float.NaN;
+ m4.hasOptionalFloat = true;
+ m4.optionalDouble = Double.NaN;
+ m4.hasOptionalDouble = true;
+ assertTrue(m3.equals(m4));
+ assertTrue(m3.equals(
+ MessageNano.mergeFrom(new TestAllTypesNanoHas(), MessageNano.toByteArray(m3))));
+
+ m3.optionalFloat = +0f;
+ m4.optionalFloat = -0f;
+ assertFalse(m3.equals(m4));
+
+ m3.optionalFloat = -0f;
+ m3.optionalDouble = +0d;
+ m4.optionalDouble = -0d;
+ assertFalse(m3.equals(m4));
+
+ m3.optionalDouble = -0d;
+ m3.hasOptionalFloat = false; // -0 does not equals() the default +0,
+ m3.hasOptionalDouble = false; // so these incorrect 'has' flags should be disregarded.
+ assertTrue(m3.equals(m4)); // note: m4 has the 'has' flags set.
+ assertFalse(m3.equals(new TestAllTypesNanoHas())); // note: the new message has +0 defaults
+ assertTrue(m3.equals(
+ MessageNano.mergeFrom(new TestAllTypesNanoHas(), MessageNano.toByteArray(m3))));
+ // note: the deserialized message has the 'has' flags set.
+
+ // -------
+
+ TestNanoAccessors m5 = new TestNanoAccessors();
+ m5.setOptionalFloat(Float.NaN);
+ m5.setOptionalDouble(Double.NaN);
+ TestNanoAccessors m6 = new TestNanoAccessors();
+ m6.setOptionalFloat(Float.NaN);
+ m6.setOptionalDouble(Double.NaN);
+ assertTrue(m5.equals(m6));
+ assertTrue(m5.equals(
+ MessageNano.mergeFrom(new TestNanoAccessors(), MessageNano.toByteArray(m6))));
+
+ m5.setOptionalFloat(+0f);
+ m6.setOptionalFloat(-0f);
+ assertFalse(m5.equals(m6));
+
+ m5.setOptionalFloat(-0f);
+ m5.setOptionalDouble(+0d);
+ m6.setOptionalDouble(-0d);
+ assertFalse(m5.equals(m6));
+
+ m5.setOptionalDouble(-0d);
+ assertTrue(m5.equals(m6));
+ assertFalse(m5.equals(new TestNanoAccessors()));
+ assertTrue(m5.equals(
+ MessageNano.mergeFrom(new TestNanoAccessors(), MessageNano.toByteArray(m6))));
+
+ // -------
+
+ NanoReferenceTypes.TestAllTypesNano m7 = new NanoReferenceTypes.TestAllTypesNano();
+ m7.optionalFloat = Float.NaN;
+ m7.optionalDouble = Double.NaN;
+ NanoReferenceTypes.TestAllTypesNano m8 = new NanoReferenceTypes.TestAllTypesNano();
+ m8.optionalFloat = Float.NaN;
+ m8.optionalDouble = Double.NaN;
+ assertTrue(m7.equals(m8));
+ assertTrue(m7.equals(MessageNano.mergeFrom(
+ new NanoReferenceTypes.TestAllTypesNano(), MessageNano.toByteArray(m7))));
+
+ m7.optionalFloat = +0f;
+ m8.optionalFloat = -0f;
+ assertFalse(m7.equals(m8));
+
+ m7.optionalFloat = -0f;
+ m7.optionalDouble = +0d;
+ m8.optionalDouble = -0d;
+ assertFalse(m7.equals(m8));
+
+ m7.optionalDouble = -0d;
+ assertTrue(m7.equals(m8));
+ assertFalse(m7.equals(new NanoReferenceTypes.TestAllTypesNano()));
+ assertTrue(m7.equals(MessageNano.mergeFrom(
+ new NanoReferenceTypes.TestAllTypesNano(), MessageNano.toByteArray(m7))));
+ }
+
+ private static TestAllTypesNano generateMessageForOneof(int caseNumber) {
+ TestAllTypesNano result = new TestAllTypesNano();
+ TestAllTypesNano.NestedMessage nested =
+ new TestAllTypesNano.NestedMessage();
+ nested.bb = 2;
+ switch (caseNumber) {
+ case TestAllTypesNano.ONEOF_UINT32_FIELD_NUMBER:
+ result.setOneofUint32(1);
+ break;
+ case TestAllTypesNano.ONEOF_ENUM_FIELD_NUMBER:
+ result.setOneofEnum(TestAllTypesNano.BAR);
+ break;
+ case TestAllTypesNano.ONEOF_NESTED_MESSAGE_FIELD_NUMBER:
+ result.setOneofNestedMessage(nested);
+ break;
+ case TestAllTypesNano.ONEOF_BYTES_FIELD_NUMBER:
+ result.setOneofBytes(new byte[] {1, 2});
+ break;
+ case TestAllTypesNano.ONEOF_STRING_FIELD_NUMBER:
+ result.setOneofString("hello");
+ break;
+ case TestAllTypesNano.ONEOF_FIXED64_FIELD_NUMBER:
+ result.setOneofFixed64(-1L);
+ break;
+ default:
+ throw new RuntimeException("unexpected case number: " + caseNumber);
+ }
+ return result;
+ }
+
+ public void testOneofHashCodeEquals() throws Exception {
+ TestAllTypesNano m1 = generateMessageForOneof(
+ TestAllTypesNano.ONEOF_UINT32_FIELD_NUMBER);
+ assertEquals(m1, generateMessageForOneof(
+ TestAllTypesNano.ONEOF_UINT32_FIELD_NUMBER));
+ assertFalse(m1.equals(new TestAllTypesNano()));
+
+ TestAllTypesNano m2 = generateMessageForOneof(
+ TestAllTypesNano.ONEOF_ENUM_FIELD_NUMBER);
+ assertEquals(m2, generateMessageForOneof(
+ TestAllTypesNano.ONEOF_ENUM_FIELD_NUMBER));
+ assertFalse(m2.equals(new TestAllTypesNano()));
+
+ TestAllTypesNano m3 = generateMessageForOneof(
+ TestAllTypesNano.ONEOF_NESTED_MESSAGE_FIELD_NUMBER);
+ assertEquals(m3, generateMessageForOneof(
+ TestAllTypesNano.ONEOF_NESTED_MESSAGE_FIELD_NUMBER));
+ assertFalse(m3.equals(new TestAllTypesNano()));
+
+ TestAllTypesNano m4 = generateMessageForOneof(
+ TestAllTypesNano.ONEOF_BYTES_FIELD_NUMBER);
+ assertEquals(m4, generateMessageForOneof(
+ TestAllTypesNano.ONEOF_BYTES_FIELD_NUMBER));
+ assertFalse(m4.equals(new TestAllTypesNano()));
+
+ TestAllTypesNano m5 = generateMessageForOneof(
+ TestAllTypesNano.ONEOF_STRING_FIELD_NUMBER);
+ assertEquals(m5, generateMessageForOneof(
+ TestAllTypesNano.ONEOF_STRING_FIELD_NUMBER));
+ assertFalse(m5.equals(new TestAllTypesNano()));
+
+ TestAllTypesNano m6 = generateMessageForOneof(
+ TestAllTypesNano.ONEOF_FIXED64_FIELD_NUMBER);
+ assertEquals(m6, generateMessageForOneof(
+ TestAllTypesNano.ONEOF_FIXED64_FIELD_NUMBER));
+ assertFalse(m6.equals(new TestAllTypesNano()));
+
+ Map<TestAllTypesNano, Integer> map =
+ new HashMap<TestAllTypesNano, Integer>();
+ map.put(m1, 1);
+ map.put(m2, 2);
+ map.put(m3, 3);
+ map.put(m4, 4);
+ map.put(m5, 5);
+ map.put(m6, 6);
+
+ assertEquals(6, map.size());
+ }
+
+ private void checkOneofCase(TestAllTypesNano nano, int field)
+ throws Exception {
+ assertEquals(field, nano.getOneofFieldCase());
+ assertEquals(
+ field == TestAllTypesNano.ONEOF_BYTES_FIELD_NUMBER,
+ nano.hasOneofBytes());
+ assertEquals(
+ field == TestAllTypesNano.ONEOF_ENUM_FIELD_NUMBER,
+ nano.hasOneofEnum());
+ assertEquals(
+ field == TestAllTypesNano.ONEOF_FIXED64_FIELD_NUMBER,
+ nano.hasOneofFixed64());
+ assertEquals(
+ field == TestAllTypesNano.ONEOF_NESTED_MESSAGE_FIELD_NUMBER,
+ nano.hasOneofNestedMessage());
+ assertEquals(
+ field == TestAllTypesNano.ONEOF_STRING_FIELD_NUMBER,
+ nano.hasOneofString());
+ assertEquals(
+ field == TestAllTypesNano.ONEOF_UINT32_FIELD_NUMBER,
+ nano.hasOneofUint32());
+
+ }
+
+ public void testOneofDefault() throws Exception {
+ TestAllTypesNano m1 = new TestAllTypesNano();
+ checkOneofCase(m1, 0);
+ assertEquals(WireFormatNano.EMPTY_BYTES, m1.getOneofBytes());
+ assertEquals(TestAllTypesNano.FOO, m1.getOneofEnum());
+ assertEquals(0L, m1.getOneofFixed64());
+ assertEquals(null, m1.getOneofNestedMessage());
+ assertEquals("", m1.getOneofString());
+ assertEquals(0, m1.getOneofUint32());
+ }
+
+ public void testOneofExclusiveness() throws Exception {
+ TestAllTypesNano m = new TestAllTypesNano();
+ checkOneofCase(m, 0);
+
+ m.setOneofBytes(new byte[]{0, 1});
+ checkOneofCase(m, TestAllTypesNano.ONEOF_BYTES_FIELD_NUMBER);
+ assertTrue(Arrays.equals(new byte[]{0, 1}, m.getOneofBytes()));
+
+ m.setOneofEnum(TestAllTypesNano.BAZ);
+ checkOneofCase(m, TestAllTypesNano.ONEOF_ENUM_FIELD_NUMBER);
+ assertEquals(TestAllTypesNano.BAZ, m.getOneofEnum());
+ assertEquals(WireFormatNano.EMPTY_BYTES, m.getOneofBytes());
+
+ m.setOneofFixed64(-1L);
+ checkOneofCase(m, TestAllTypesNano.ONEOF_FIXED64_FIELD_NUMBER);
+ assertEquals(-1L, m.getOneofFixed64());
+ assertEquals(TestAllTypesNano.FOO, m.getOneofEnum());
+
+ m.setOneofNestedMessage(new TestAllTypesNano.NestedMessage());
+ checkOneofCase(m, TestAllTypesNano.ONEOF_NESTED_MESSAGE_FIELD_NUMBER);
+ assertEquals(
+ new TestAllTypesNano.NestedMessage(), m.getOneofNestedMessage());
+ assertEquals(0L, m.getOneofFixed64());
+
+ m.setOneofString("hello");
+ checkOneofCase(m, TestAllTypesNano.ONEOF_STRING_FIELD_NUMBER);
+ assertEquals("hello", m.getOneofString());
+ assertNull(m.getOneofNestedMessage());
+
+ m.setOneofUint32(10);
+ checkOneofCase(m, TestAllTypesNano.ONEOF_UINT32_FIELD_NUMBER);
+ assertEquals(10, m.getOneofUint32());
+ assertEquals("", m.getOneofString());
+
+ m.setOneofBytes(new byte[]{0, 1});
+ checkOneofCase(m, TestAllTypesNano.ONEOF_BYTES_FIELD_NUMBER);
+ assertTrue(Arrays.equals(new byte[]{0, 1}, m.getOneofBytes()));
+ assertEquals(0, m.getOneofUint32());
+ }
+
+ public void testOneofClear() throws Exception {
+ TestAllTypesNano m = new TestAllTypesNano();
+ m.setOneofBytes(new byte[]{0, 1});
+ m.clearOneofField();
+ checkOneofCase(m, 0);
+
+ m.setOneofEnum(TestAllTypesNano.BAZ);
+ m.clearOneofField();
+ checkOneofCase(m, 0);
+
+ m.setOneofFixed64(-1L);
+ m.clearOneofField();
+ checkOneofCase(m, 0);
+
+ m.setOneofNestedMessage(new TestAllTypesNano.NestedMessage());
+ m.clearOneofField();
+ checkOneofCase(m, 0);
+
+ m.setOneofString("hello");
+ m.clearOneofField();
+ checkOneofCase(m, 0);
+
+ m.setOneofUint32(10);
+ m.clearOneofField();
+ checkOneofCase(m, 0);
+ }
+
+ public void testOneofMarshaling() throws Exception {
+ TestAllTypesNano m = new TestAllTypesNano();
+ TestAllTypesNano parsed = new TestAllTypesNano();
+ {
+ m.setOneofBytes(new byte[]{0, 1});
+ byte[] serialized = MessageNano.toByteArray(m);
+ MessageNano.mergeFrom(parsed, serialized);
+ checkOneofCase(parsed, TestAllTypesNano.ONEOF_BYTES_FIELD_NUMBER);
+ assertTrue(Arrays.equals(new byte[]{0, 1}, parsed.getOneofBytes()));
+ }
+ {
+ m.setOneofEnum(TestAllTypesNano.BAZ);
+ byte[] serialized = MessageNano.toByteArray(m);
+ MessageNano.mergeFrom(parsed, serialized);
+ checkOneofCase(m, TestAllTypesNano.ONEOF_ENUM_FIELD_NUMBER);
+ assertEquals(TestAllTypesNano.BAZ, m.getOneofEnum());
+ }
+ {
+ m.setOneofEnum(TestAllTypesNano.BAZ);
+ byte[] serialized = MessageNano.toByteArray(m);
+ MessageNano.mergeFrom(parsed, serialized);
+ checkOneofCase(m, TestAllTypesNano.ONEOF_ENUM_FIELD_NUMBER);
+ assertEquals(TestAllTypesNano.BAZ, m.getOneofEnum());
+ }
+ {
+ m.setOneofFixed64(-1L);
+ byte[] serialized = MessageNano.toByteArray(m);
+ MessageNano.mergeFrom(parsed, serialized);
+ checkOneofCase(m, TestAllTypesNano.ONEOF_FIXED64_FIELD_NUMBER);
+ assertEquals(-1L, m.getOneofFixed64());
+ }
+ {
+ m.setOneofNestedMessage(new TestAllTypesNano.NestedMessage());
+ byte[] serialized = MessageNano.toByteArray(m);
+ MessageNano.mergeFrom(parsed, serialized);
+ checkOneofCase(m, TestAllTypesNano.ONEOF_NESTED_MESSAGE_FIELD_NUMBER);
+ assertEquals(
+ new TestAllTypesNano.NestedMessage(), m.getOneofNestedMessage());
+ }
+ {
+ m.setOneofString("hello");
+ byte[] serialized = MessageNano.toByteArray(m);
+ MessageNano.mergeFrom(parsed, serialized);
+ assertEquals("hello", m.getOneofString());
+ assertNull(m.getOneofNestedMessage());
+ }
+ {
+ m.setOneofUint32(10);
+ byte[] serialized = MessageNano.toByteArray(m);
+ MessageNano.mergeFrom(parsed, serialized);
+ checkOneofCase(m, TestAllTypesNano.ONEOF_UINT32_FIELD_NUMBER);
+ assertEquals(10, m.getOneofUint32());
+ }
+ }
+
+ public void testOneofSerializedConcat() throws Exception {
+ TestAllTypesNano m1 = new TestAllTypesNano();
+ m1.setOneofBytes(new byte[] {0, 1});
+ byte[] b1 = MessageNano.toByteArray(m1);
+ TestAllTypesNano m2 = new TestAllTypesNano();
+ m2.setOneofEnum(TestAllTypesNano.BAZ);
+ byte[] b2 = MessageNano.toByteArray(m2);
+ byte[] b3 = new byte[b1.length + b2.length];
+ System.arraycopy(b1, 0, b3, 0, b1.length);
+ System.arraycopy(b2, 0, b3, b1.length, b2.length);
+ TestAllTypesNano parsed = new TestAllTypesNano();
+ MessageNano.mergeFrom(parsed, b3);
+ // the last on the wire wins.
+ checkOneofCase(parsed, TestAllTypesNano.ONEOF_ENUM_FIELD_NUMBER);
+ assertEquals(TestAllTypesNano.BAZ, parsed.getOneofEnum());
+ }
+
+ public void testNullRepeatedFields() throws Exception {
+ // Check that serialization after explicitly setting a repeated field
+ // to null doesn't NPE.
+ TestAllTypesNano message = new TestAllTypesNano();
+ message.repeatedInt32 = null;
+ MessageNano.toByteArray(message); // should not NPE
+ message.toString(); // should not NPE
+
+ message.repeatedNestedEnum = null;
+ MessageNano.toByteArray(message); // should not NPE
+ message.toString(); // should not NPE
+
+ message.repeatedBytes = null;
+ MessageNano.toByteArray(message); // should not NPE
+ message.toString(); // should not NPE
+
+ message.repeatedNestedMessage = null;
+ MessageNano.toByteArray(message); // should not NPE
+ message.toString(); // should not NPE
+
+ message.repeatedPackedInt32 = null;
+ MessageNano.toByteArray(message); // should not NPE
+ message.toString(); // should not NPE
+
+ message.repeatedPackedNestedEnum = null;
+ MessageNano.toByteArray(message); // should not NPE
+ message.toString(); // should not NPE
+
+ // Create a second message to merge into message.
+ TestAllTypesNano secondMessage = new TestAllTypesNano();
+ secondMessage.repeatedInt32 = new int[] {1, 2, 3};
+ secondMessage.repeatedNestedEnum = new int[] {
+ TestAllTypesNano.FOO, TestAllTypesNano.BAR
+ };
+ secondMessage.repeatedBytes = new byte[][] {{1, 2}, {3, 4}};
+ TestAllTypesNano.NestedMessage nested =
+ new TestAllTypesNano.NestedMessage();
+ nested.bb = 55;
+ secondMessage.repeatedNestedMessage =
+ new TestAllTypesNano.NestedMessage[] {nested};
+ secondMessage.repeatedPackedInt32 = new int[] {1, 2, 3};
+ secondMessage.repeatedPackedNestedEnum = new int[] {
+ TestAllTypesNano.FOO, TestAllTypesNano.BAR
+ };
+
+ // Should not NPE
+ message.mergeFrom(CodedInputByteBufferNano.newInstance(
+ MessageNano.toByteArray(secondMessage)));
+ assertEquals(3, message.repeatedInt32.length);
+ assertEquals(3, message.repeatedInt32[2]);
+ assertEquals(2, message.repeatedNestedEnum.length);
+ assertEquals(TestAllTypesNano.FOO, message.repeatedNestedEnum[0]);
+ assertEquals(2, message.repeatedBytes.length);
+ assertEquals(4, message.repeatedBytes[1][1]);
+ assertEquals(1, message.repeatedNestedMessage.length);
+ assertEquals(55, message.repeatedNestedMessage[0].bb);
+ assertEquals(3, message.repeatedPackedInt32.length);
+ assertEquals(2, message.repeatedPackedInt32[1]);
+ assertEquals(2, message.repeatedPackedNestedEnum.length);
+ assertEquals(TestAllTypesNano.BAR, message.repeatedPackedNestedEnum[1]);
+ }
+
+ public void testNullRepeatedFieldElements() throws Exception {
+ // Check that serialization with null array elements doesn't NPE.
+ String string1 = "1";
+ String string2 = "2";
+ byte[] bytes1 = {3, 4};
+ byte[] bytes2 = {5, 6};
+ TestAllTypesNano.NestedMessage msg1 = new TestAllTypesNano.NestedMessage();
+ msg1.bb = 7;
+ TestAllTypesNano.NestedMessage msg2 = new TestAllTypesNano.NestedMessage();
+ msg2.bb = 8;
+
+ TestAllTypesNano message = new TestAllTypesNano();
+ message.repeatedString = new String[] {null, string1, string2};
+ message.repeatedBytes = new byte[][] {bytes1, null, bytes2};
+ message.repeatedNestedMessage = new TestAllTypesNano.NestedMessage[] {msg1, msg2, null};
+ message.repeatedGroup = new TestAllTypesNano.RepeatedGroup[] {null, null, null};
+
+ byte[] serialized = MessageNano.toByteArray(message); // should not NPE
+ TestAllTypesNano deserialized = MessageNano.mergeFrom(new TestAllTypesNano(), serialized);
+ assertEquals(2, deserialized.repeatedString.length);
+ assertEquals(string1, deserialized.repeatedString[0]);
+ assertEquals(string2, deserialized.repeatedString[1]);
+ assertEquals(2, deserialized.repeatedBytes.length);
+ assertTrue(Arrays.equals(bytes1, deserialized.repeatedBytes[0]));
+ assertTrue(Arrays.equals(bytes2, deserialized.repeatedBytes[1]));
+ assertEquals(2, deserialized.repeatedNestedMessage.length);
+ assertEquals(msg1.bb, deserialized.repeatedNestedMessage[0].bb);
+ assertEquals(msg2.bb, deserialized.repeatedNestedMessage[1].bb);
+ assertEquals(0, deserialized.repeatedGroup.length);
+ }
+
+ public void testRepeatedMerge() throws Exception {
+ // Check that merging repeated fields cause the arrays to expand with
+ // new data.
+ TestAllTypesNano first = new TestAllTypesNano();
+ first.repeatedInt32 = new int[] {1, 2, 3};
+ TestAllTypesNano second = new TestAllTypesNano();
+ second.repeatedInt32 = new int[] {4, 5};
+ MessageNano.mergeFrom(first, MessageNano.toByteArray(second));
+ assertEquals(5, first.repeatedInt32.length);
+ assertEquals(1, first.repeatedInt32[0]);
+ assertEquals(4, first.repeatedInt32[3]);
+
+ first = new TestAllTypesNano();
+ first.repeatedNestedEnum = new int[] {TestAllTypesNano.BAR};
+ second = new TestAllTypesNano();
+ second.repeatedNestedEnum = new int[] {TestAllTypesNano.FOO};
+ MessageNano.mergeFrom(first, MessageNano.toByteArray(second));
+ assertEquals(2, first.repeatedNestedEnum.length);
+ assertEquals(TestAllTypesNano.BAR, first.repeatedNestedEnum[0]);
+ assertEquals(TestAllTypesNano.FOO, first.repeatedNestedEnum[1]);
+
+ first = new TestAllTypesNano();
+ first.repeatedNestedMessage = new TestAllTypesNano.NestedMessage[] {
+ new TestAllTypesNano.NestedMessage()
+ };
+ first.repeatedNestedMessage[0].bb = 3;
+ second = new TestAllTypesNano();
+ second.repeatedNestedMessage = new TestAllTypesNano.NestedMessage[] {
+ new TestAllTypesNano.NestedMessage()
+ };
+ second.repeatedNestedMessage[0].bb = 5;
+ MessageNano.mergeFrom(first, MessageNano.toByteArray(second));
+ assertEquals(2, first.repeatedNestedMessage.length);
+ assertEquals(3, first.repeatedNestedMessage[0].bb);
+ assertEquals(5, first.repeatedNestedMessage[1].bb);
+
+ first = new TestAllTypesNano();
+ first.repeatedPackedSfixed64 = new long[] {-1, -2, -3};
+ second = new TestAllTypesNano();
+ second.repeatedPackedSfixed64 = new long[] {-4, -5};
+ MessageNano.mergeFrom(first, MessageNano.toByteArray(second));
+ assertEquals(5, first.repeatedPackedSfixed64.length);
+ assertEquals(-1, first.repeatedPackedSfixed64[0]);
+ assertEquals(-4, first.repeatedPackedSfixed64[3]);
+
+ first = new TestAllTypesNano();
+ first.repeatedPackedNestedEnum = new int[] {TestAllTypesNano.BAR};
+ second = new TestAllTypesNano();
+ second.repeatedPackedNestedEnum = new int[] {TestAllTypesNano.FOO};
+ MessageNano.mergeFrom(first, MessageNano.toByteArray(second));
+ assertEquals(2, first.repeatedPackedNestedEnum.length);
+ assertEquals(TestAllTypesNano.BAR, first.repeatedPackedNestedEnum[0]);
+ assertEquals(TestAllTypesNano.FOO, first.repeatedPackedNestedEnum[1]);
+
+ // Now test repeated merging in a nested scope
+ TestRepeatedMergeNano firstContainer = new TestRepeatedMergeNano();
+ firstContainer.contained = new TestAllTypesNano();
+ firstContainer.contained.repeatedInt32 = new int[] {10, 20};
+ TestRepeatedMergeNano secondContainer = new TestRepeatedMergeNano();
+ secondContainer.contained = new TestAllTypesNano();
+ secondContainer.contained.repeatedInt32 = new int[] {30};
+ MessageNano.mergeFrom(firstContainer, MessageNano.toByteArray(secondContainer));
+ assertEquals(3, firstContainer.contained.repeatedInt32.length);
+ assertEquals(20, firstContainer.contained.repeatedInt32[1]);
+ assertEquals(30, firstContainer.contained.repeatedInt32[2]);
+ }
+
+ public void testRepeatedPackables() throws Exception {
+ // Check that repeated fields with packable types can accept both packed and unpacked
+ // serialized forms.
+ NanoRepeatedPackables.NonPacked nonPacked = new NanoRepeatedPackables.NonPacked();
+ // Exaggerates the first values of varint-typed arrays. This is to test that the parsing code
+ // of packed fields handles non-packed data correctly. If the code incorrectly thinks it is
+ // reading from a packed tag, it will read the first value as the byte length of the field,
+ // and the large number will cause the input to go out of bounds, thus capturing the error.
+ nonPacked.int32S = new int[] {1000, 2, 3};
+ nonPacked.int64S = new long[] {4000, 5, 6};
+ nonPacked.uint32S = new int[] {7000, 8, 9};
+ nonPacked.uint64S = new long[] {10000, 11, 12};
+ nonPacked.sint32S = new int[] {13000, 14, 15};
+ nonPacked.sint64S = new long[] {16000, 17, 18};
+ nonPacked.fixed32S = new int[] {19, 20, 21};
+ nonPacked.fixed64S = new long[] {22, 23, 24};
+ nonPacked.sfixed32S = new int[] {25, 26, 27};
+ nonPacked.sfixed64S = new long[] {28, 29, 30};
+ nonPacked.floats = new float[] {31, 32, 33};
+ nonPacked.doubles = new double[] {34, 35, 36};
+ nonPacked.bools = new boolean[] {false, true};
+ nonPacked.enums = new int[] {
+ NanoRepeatedPackables.Enum.OPTION_ONE,
+ NanoRepeatedPackables.Enum.OPTION_TWO,
+ };
+ nonPacked.noise = 13579;
+
+ byte[] nonPackedSerialized = MessageNano.toByteArray(nonPacked);
+
+ NanoRepeatedPackables.Packed packed =
+ MessageNano.mergeFrom(new NanoRepeatedPackables.Packed(), nonPackedSerialized);
+ assertRepeatedPackablesEqual(nonPacked, packed);
+
+ byte[] packedSerialized = MessageNano.toByteArray(packed);
+ // Just a cautious check that the two serialized forms are different,
+ // to make sure the remaining of this test is useful:
+ assertFalse(Arrays.equals(nonPackedSerialized, packedSerialized));
+
+ nonPacked = MessageNano.mergeFrom(new NanoRepeatedPackables.NonPacked(), packedSerialized);
+ assertRepeatedPackablesEqual(nonPacked, packed);
+
+ // Test mixed serialized form.
+ byte[] mixedSerialized = new byte[nonPackedSerialized.length + packedSerialized.length];
+ System.arraycopy(nonPackedSerialized, 0, mixedSerialized, 0, nonPackedSerialized.length);
+ System.arraycopy(packedSerialized, 0,
+ mixedSerialized, nonPackedSerialized.length, packedSerialized.length);
+
+ nonPacked = MessageNano.mergeFrom(new NanoRepeatedPackables.NonPacked(), mixedSerialized);
+ packed = MessageNano.mergeFrom(new NanoRepeatedPackables.Packed(), mixedSerialized);
+ assertRepeatedPackablesEqual(nonPacked, packed);
+ assertTrue(Arrays.equals(new int[] {1000, 2, 3, 1000, 2, 3}, nonPacked.int32S));
+ assertTrue(Arrays.equals(new int[] {13000, 14, 15, 13000, 14, 15}, nonPacked.sint32S));
+ assertTrue(Arrays.equals(new int[] {25, 26, 27, 25, 26, 27}, nonPacked.sfixed32S));
+ assertTrue(Arrays.equals(new boolean[] {false, true, false, true}, nonPacked.bools));
+ }
+
+ public void testMapsSerializeAndParse() throws Exception {
+ TestMap origin = new TestMap();
+ setMapMessage(origin);
+ assertMapMessageSet(origin);
+
+ byte[] output = MessageNano.toByteArray(origin);
+ TestMap parsed = new TestMap();
+ MessageNano.mergeFrom(parsed, output);
+ }
+
+ public void testMapSerializeRejectNull() throws Exception {
+ TestMap primitiveMap = new TestMap();
+ primitiveMap.int32ToInt32Field = new HashMap<Integer, Integer>();
+ primitiveMap.int32ToInt32Field.put(null, 1);
+ try {
+ MessageNano.toByteArray(primitiveMap);
+ fail("should reject null keys");
+ } catch (IllegalStateException e) {
+ // pass.
+ }
+
+ TestMap messageMap = new TestMap();
+ messageMap.int32ToMessageField =
+ new HashMap<Integer, MapTestProto.TestMap.MessageValue>();
+ messageMap.int32ToMessageField.put(0, null);
+ try {
+ MessageNano.toByteArray(messageMap);
+ fail("should reject null values");
+ } catch (IllegalStateException e) {
+ // pass.
+ }
+ }
+
+ /**
+ * Tests that merging bytes containing conflicting keys with override the
+ * message value instead of merging the message value into the existing entry.
+ */
+ public void testMapMergeOverrideMessageValues() throws Exception {
+ TestMap.MessageValue origValue = new TestMap.MessageValue();
+ origValue.value = 1;
+ origValue.value2 = 2;
+ TestMap.MessageValue newValue = new TestMap.MessageValue();
+ newValue.value = 3;
+
+ TestMap origMessage = new TestMap();
+ origMessage.int32ToMessageField =
+ new HashMap<Integer, MapTestProto.TestMap.MessageValue>();
+ origMessage.int32ToMessageField.put(1, origValue);
+
+ TestMap newMessage = new TestMap();
+ newMessage.int32ToMessageField =
+ new HashMap<Integer, MapTestProto.TestMap.MessageValue>();
+ newMessage.int32ToMessageField.put(1, newValue);
+ MessageNano.mergeFrom(origMessage,
+ MessageNano.toByteArray(newMessage));
+ TestMap.MessageValue mergedValue = origMessage.int32ToMessageField.get(1);
+ assertEquals(3, mergedValue.value);
+ assertEquals(0, mergedValue.value2);
+ }
+
+ /**
+ * Tests that when merging with empty entries,
+ * we will use default for the key and value, instead of null.
+ */
+ public void testMapMergeEmptyEntry() throws Exception {
+ TestMap testMap = new TestMap();
+ byte[] buffer = new byte[1024];
+ CodedOutputByteBufferNano output =
+ CodedOutputByteBufferNano.newInstance(buffer);
+ // An empty entry for int32_to_int32 map.
+ output.writeTag(1, WireFormatNano.WIRETYPE_LENGTH_DELIMITED);
+ output.writeRawVarint32(0);
+ // An empty entry for int32_to_message map.
+ output.writeTag(5, WireFormatNano.WIRETYPE_LENGTH_DELIMITED);
+ output.writeRawVarint32(0);
+
+ CodedInputByteBufferNano input = CodedInputByteBufferNano.newInstance(
+ buffer, 0, buffer.length - output.spaceLeft());
+ testMap.mergeFrom(input);
+ assertNotNull(testMap.int32ToInt32Field);;
+ assertEquals(1, testMap.int32ToInt32Field.size());
+ assertEquals(Integer.valueOf(0), testMap.int32ToInt32Field.get(0));
+ assertNotNull(testMap.int32ToMessageField);
+ assertEquals(1, testMap.int32ToMessageField.size());
+ TestMap.MessageValue messageValue = testMap.int32ToMessageField.get(0);
+ assertNotNull(messageValue);
+ assertEquals(0, messageValue.value);
+ assertEquals(0, messageValue.value2);
+ }
+
+ public void testMapEquals() throws Exception {
+ TestMap a = new TestMap();
+ TestMap b = new TestMap();
+
+ // empty and null map fields are equal.
+ assertTestMapEqual(a, b);
+ a.int32ToBytesField = new HashMap<Integer, byte[]>();
+ assertTestMapEqual(a, b);
+
+ a.int32ToInt32Field = new HashMap<Integer, Integer>();
+ b.int32ToInt32Field = new HashMap<Integer, Integer>();
+ setMap(a.int32ToInt32Field, deepCopy(int32Values), deepCopy(int32Values));
+ setMap(b.int32ToInt32Field, deepCopy(int32Values), deepCopy(int32Values));
+ assertTestMapEqual(a, b);
+
+ a.int32ToMessageField =
+ new HashMap<Integer, MapTestProto.TestMap.MessageValue>();
+ b.int32ToMessageField =
+ new HashMap<Integer, MapTestProto.TestMap.MessageValue>();
+ setMap(a.int32ToMessageField,
+ deepCopy(int32Values), deepCopy(messageValues));
+ setMap(b.int32ToMessageField,
+ deepCopy(int32Values), deepCopy(messageValues));
+ assertTestMapEqual(a, b);
+
+ a.stringToInt32Field = new HashMap<String, Integer>();
+ b.stringToInt32Field = new HashMap<String, Integer>();
+ setMap(a.stringToInt32Field, deepCopy(stringValues), deepCopy(int32Values));
+ setMap(b.stringToInt32Field, deepCopy(stringValues), deepCopy(int32Values));
+ assertTestMapEqual(a, b);
+
+ a.int32ToBytesField = new HashMap<Integer, byte[]>();
+ b.int32ToBytesField = new HashMap<Integer, byte[]>();
+ setMap(a.int32ToBytesField, deepCopy(int32Values), deepCopy(bytesValues));
+ setMap(b.int32ToBytesField, deepCopy(int32Values), deepCopy(bytesValues));
+ assertTestMapEqual(a, b);
+
+ // Make sure the map implementation does not matter.
+ a.int32ToStringField = new TreeMap<Integer, String>();
+ b.int32ToStringField = new HashMap<Integer, String>();
+ setMap(a.int32ToStringField, deepCopy(int32Values), deepCopy(stringValues));
+ setMap(b.int32ToStringField, deepCopy(int32Values), deepCopy(stringValues));
+ assertTestMapEqual(a, b);
+
+ a.clear();
+ b.clear();
+
+ // unequal cases: different value
+ a.int32ToInt32Field = new HashMap<Integer, Integer>();
+ b.int32ToInt32Field = new HashMap<Integer, Integer>();
+ a.int32ToInt32Field.put(1, 1);
+ b.int32ToInt32Field.put(1, 2);
+ assertTestMapUnequal(a, b);
+ // unequal case: additional entry
+ b.int32ToInt32Field.put(1, 1);
+ b.int32ToInt32Field.put(2, 1);
+ assertTestMapUnequal(a, b);
+ a.int32ToInt32Field.put(2, 1);
+ assertTestMapEqual(a, b);
+
+ // unequal case: different message value.
+ a.int32ToMessageField =
+ new HashMap<Integer, MapTestProto.TestMap.MessageValue>();
+ b.int32ToMessageField =
+ new HashMap<Integer, MapTestProto.TestMap.MessageValue>();
+ MessageValue va = new MessageValue();
+ va.value = 1;
+ MessageValue vb = new MessageValue();
+ vb.value = 1;
+ a.int32ToMessageField.put(1, va);
+ b.int32ToMessageField.put(1, vb);
+ assertTestMapEqual(a, b);
+ vb.value = 2;
+ assertTestMapUnequal(a, b);
+ }
+
+ private static void assertTestMapEqual(TestMap a, TestMap b)
+ throws Exception {
+ assertEquals(a.hashCode(), b.hashCode());
+ assertTrue(a.equals(b));
+ assertTrue(b.equals(a));
+ }
+
+ private static void assertTestMapUnequal(TestMap a, TestMap b)
+ throws Exception {
+ assertFalse(a.equals(b));
+ assertFalse(b.equals(a));
+ }
+
+ private static final Integer[] int32Values = new Integer[] {
+ 0, 1, -1, Integer.MAX_VALUE, Integer.MIN_VALUE,
+ };
+
+ private static final Long[] int64Values = new Long[] {
+ 0L, 1L, -1L, Long.MAX_VALUE, Long.MIN_VALUE,
+ };
+
+ private static final String[] stringValues = new String[] {
+ "", "hello", "world", "foo", "bar",
+ };
+
+ private static final byte[][] bytesValues = new byte[][] {
+ new byte[] {},
+ new byte[] {0},
+ new byte[] {1, -1},
+ new byte[] {127, -128},
+ new byte[] {'a', 'b', '0', '1'},
+ };
+
+ private static final Boolean[] boolValues = new Boolean[] {
+ false, true,
+ };
+
+ private static final Integer[] enumValues = new Integer[] {
+ TestMap.FOO, TestMap.BAR, TestMap.BAZ, TestMap.QUX,
+ Integer.MAX_VALUE /* unknown */,
+ };
+
+ private static final TestMap.MessageValue[] messageValues =
+ new TestMap.MessageValue[] {
+ newMapValueMessage(0),
+ newMapValueMessage(1),
+ newMapValueMessage(-1),
+ newMapValueMessage(Integer.MAX_VALUE),
+ newMapValueMessage(Integer.MIN_VALUE),
+ };
+
+ private static TestMap.MessageValue newMapValueMessage(int value) {
+ TestMap.MessageValue result = new TestMap.MessageValue();
+ result.value = value;
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> T[] deepCopy(T[] orig) throws Exception {
+ if (orig instanceof MessageValue[]) {
+ MessageValue[] result = new MessageValue[orig.length];
+ for (int i = 0; i < orig.length; i++) {
+ result[i] = new MessageValue();
+ MessageNano.mergeFrom(
+ result[i], MessageNano.toByteArray((MessageValue) orig[i]));
+ }
+ return (T[]) result;
+ }
+ if (orig instanceof byte[][]) {
+ byte[][] result = new byte[orig.length][];
+ for (int i = 0; i < orig.length; i++) {
+ byte[] origBytes = (byte[]) orig[i];
+ result[i] = Arrays.copyOf(origBytes, origBytes.length);
+ }
+ }
+ return Arrays.copyOf(orig, orig.length);
+ }
+
+ private <K, V> void setMap(Map<K, V> map, K[] keys, V[] values) {
+ assert(keys.length == values.length);
+ for (int i = 0; i < keys.length; i++) {
+ map.put(keys[i], values[i]);
+ }
+ }
+
+ private <K, V> void assertMapSet(
+ Map<K, V> map, K[] keys, V[] values) throws Exception {
+ assert(keys.length == values.length);
+ for (int i = 0; i < values.length; i++) {
+ assertEquals(values[i], map.get(keys[i]));
+ }
+ assertEquals(keys.length, map.size());
+ }
+
+ private void setMapMessage(TestMap testMap) {
+ testMap.int32ToInt32Field = new HashMap<Integer, Integer>();
+ testMap.int32ToBytesField = new HashMap<Integer, byte[]>();
+ testMap.int32ToEnumField = new HashMap<Integer, Integer>();
+ testMap.int32ToMessageField =
+ new HashMap<Integer, MapTestProto.TestMap.MessageValue>();
+ testMap.int32ToStringField = new HashMap<Integer, String>();
+ testMap.stringToInt32Field = new HashMap<String, Integer>();
+ testMap.boolToBoolField = new HashMap<Boolean, Boolean>();
+ testMap.uint32ToUint32Field = new HashMap<Integer, Integer>();
+ testMap.sint32ToSint32Field = new HashMap<Integer, Integer>();
+ testMap.fixed32ToFixed32Field = new HashMap<Integer, Integer>();
+ testMap.sfixed32ToSfixed32Field = new HashMap<Integer, Integer>();
+ testMap.int64ToInt64Field = new HashMap<Long, Long>();
+ testMap.uint64ToUint64Field = new HashMap<Long, Long>();
+ testMap.sint64ToSint64Field = new HashMap<Long, Long>();
+ testMap.fixed64ToFixed64Field = new HashMap<Long, Long>();
+ testMap.sfixed64ToSfixed64Field = new HashMap<Long, Long>();
+ setMap(testMap.int32ToInt32Field, int32Values, int32Values);
+ setMap(testMap.int32ToBytesField, int32Values, bytesValues);
+ setMap(testMap.int32ToEnumField, int32Values, enumValues);
+ setMap(testMap.int32ToMessageField, int32Values, messageValues);
+ setMap(testMap.int32ToStringField, int32Values, stringValues);
+ setMap(testMap.stringToInt32Field, stringValues, int32Values);
+ setMap(testMap.boolToBoolField, boolValues, boolValues);
+ setMap(testMap.uint32ToUint32Field, int32Values, int32Values);
+ setMap(testMap.sint32ToSint32Field, int32Values, int32Values);
+ setMap(testMap.fixed32ToFixed32Field, int32Values, int32Values);
+ setMap(testMap.sfixed32ToSfixed32Field, int32Values, int32Values);
+ setMap(testMap.int64ToInt64Field, int64Values, int64Values);
+ setMap(testMap.uint64ToUint64Field, int64Values, int64Values);
+ setMap(testMap.sint64ToSint64Field, int64Values, int64Values);
+ setMap(testMap.fixed64ToFixed64Field, int64Values, int64Values);
+ setMap(testMap.sfixed64ToSfixed64Field, int64Values, int64Values);
+ }
+ private void assertMapMessageSet(TestMap testMap) throws Exception {
+ assertMapSet(testMap.int32ToInt32Field, int32Values, int32Values);
+ assertMapSet(testMap.int32ToBytesField, int32Values, bytesValues);
+ assertMapSet(testMap.int32ToEnumField, int32Values, enumValues);
+ assertMapSet(testMap.int32ToMessageField, int32Values, messageValues);
+ assertMapSet(testMap.int32ToStringField, int32Values, stringValues);
+ assertMapSet(testMap.stringToInt32Field, stringValues, int32Values);
+ assertMapSet(testMap.boolToBoolField, boolValues, boolValues);
+ assertMapSet(testMap.uint32ToUint32Field, int32Values, int32Values);
+ assertMapSet(testMap.sint32ToSint32Field, int32Values, int32Values);
+ assertMapSet(testMap.fixed32ToFixed32Field, int32Values, int32Values);
+ assertMapSet(testMap.sfixed32ToSfixed32Field, int32Values, int32Values);
+ assertMapSet(testMap.int64ToInt64Field, int64Values, int64Values);
+ assertMapSet(testMap.uint64ToUint64Field, int64Values, int64Values);
+ assertMapSet(testMap.sint64ToSint64Field, int64Values, int64Values);
+ assertMapSet(testMap.fixed64ToFixed64Field, int64Values, int64Values);
+ assertMapSet(testMap.sfixed64ToSfixed64Field, int64Values, int64Values);
+ }
+
+ public void testRepeatedFieldInitializedInReftypesCompatMode() {
+ NanoReferenceTypesCompat.TestAllTypesNano proto = new NanoReferenceTypesCompat.TestAllTypesNano();
+ assertNotNull(proto.repeatedString);
+ }
+
+ private void assertRepeatedPackablesEqual(
+ NanoRepeatedPackables.NonPacked nonPacked, NanoRepeatedPackables.Packed packed) {
+ // Not using MessageNano.equals() -- that belongs to a separate test.
+ assertTrue(Arrays.equals(nonPacked.int32S, packed.int32S));
+ assertTrue(Arrays.equals(nonPacked.int64S, packed.int64S));
+ assertTrue(Arrays.equals(nonPacked.uint32S, packed.uint32S));
+ assertTrue(Arrays.equals(nonPacked.uint64S, packed.uint64S));
+ assertTrue(Arrays.equals(nonPacked.sint32S, packed.sint32S));
+ assertTrue(Arrays.equals(nonPacked.sint64S, packed.sint64S));
+ assertTrue(Arrays.equals(nonPacked.fixed32S, packed.fixed32S));
+ assertTrue(Arrays.equals(nonPacked.fixed64S, packed.fixed64S));
+ assertTrue(Arrays.equals(nonPacked.sfixed32S, packed.sfixed32S));
+ assertTrue(Arrays.equals(nonPacked.sfixed64S, packed.sfixed64S));
+ assertTrue(Arrays.equals(nonPacked.floats, packed.floats));
+ assertTrue(Arrays.equals(nonPacked.doubles, packed.doubles));
+ assertTrue(Arrays.equals(nonPacked.bools, packed.bools));
+ assertTrue(Arrays.equals(nonPacked.enums, packed.enums));
+ }
+
+ public void testClone() throws Exception {
+ // A simple message.
+ AnotherMessage anotherMessage = new AnotherMessage();
+ anotherMessage.string = "Hello";
+ anotherMessage.value = true;
+ anotherMessage.integers = new int[] { 1, 2, 3 };
+
+ AnotherMessage clone = anotherMessage.clone();
+ assertEquals(clone, anotherMessage);
+
+ // Verify it was a deep clone - changes to the clone shouldn't affect the
+ // original.
+ clone.integers[1] = 100;
+ assertFalse(clone.equals(anotherMessage));
+ }
+
+ private void assertHasWireData(MessageNano message, boolean expected) {
+ byte[] bytes = MessageNano.toByteArray(message);
+ int wireLength = bytes.length;
+ if (expected) {
+ assertFalse(wireLength == 0);
+ } else {
+ if (wireLength != 0) {
+ fail("Expected no wire data for message \n" + message
+ + "\nBut got:\n"
+ + hexDump(bytes));
+ }
+ }
+ }
+
+ private static String hexDump(byte[] bytes) {
+ StringBuilder sb = new StringBuilder();
+ for (byte b : bytes) {
+ sb.append(String.format("%02x ", b));
+ }
+ return sb.toString();
+ }
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/map_test.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/map_test.proto
new file mode 100644
index 0000000000..51498a4925
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/map_test.proto
@@ -0,0 +1,70 @@
+// 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.
+
+syntax = "proto3";
+
+package map_test;
+
+option java_package = "com.google.protobuf";
+option java_outer_classname = "MapTestProto";
+
+message TestMap {
+ message MessageValue {
+ int32 value = 1;
+ int32 value2 = 2;
+ }
+ enum EnumValue {
+ FOO = 0;
+ BAR = 1;
+ BAZ = 2;
+ QUX = 3;
+ }
+
+ map<int32, int32> int32_to_int32_field = 1;
+ map<int32, string> int32_to_string_field = 2;
+ map<int32, bytes> int32_to_bytes_field = 3;
+ map<int32, EnumValue> int32_to_enum_field = 4;
+ map<int32, MessageValue> int32_to_message_field = 5;
+ map<string, int32> string_to_int32_field = 6;
+ map<bool, bool> bool_to_bool_field = 7;
+
+ // Test all the other primitive types. As the key and value are not coupled in
+ // the implementation, we do not test all the combinations of key/value pairs,
+ // so that we can keep the number of test cases manageable
+ map<uint32, uint32> uint32_to_uint32_field = 11;
+ map<sint32, sint32> sint32_to_sint32_field = 12;
+ map<fixed32, fixed32> fixed32_to_fixed32_field = 13;
+ map<sfixed32, sfixed32> sfixed32_to_sfixed32_field = 14;
+ map<int64, int64> int64_to_int64_field = 15;
+ map<uint64, uint64> uint64_to_uint64_field = 16;
+ map<sint64, sint64> sint64_to_sint64_field = 17;
+ map<fixed64, fixed64> fixed64_to_fixed64_field = 18;
+ map<sfixed64, sfixed64> sfixed64_to_sfixed64_field = 19;
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_accessors_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_accessors_nano.proto
new file mode 100644
index 0000000000..6511e4703b
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_accessors_nano.proto
@@ -0,0 +1,118 @@
+// 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.
+
+// Author: maxtroy@google.com (Max Cai)
+
+package protobuf_unittest;
+
+option java_package = "com.google.protobuf";
+option java_outer_classname = "NanoAccessorsOuterClass";
+
+message TestNanoAccessors {
+
+ message NestedMessage {
+ optional int32 bb = 1;
+ }
+
+ enum NestedEnum {
+ FOO = 1;
+ BAR = 2;
+ BAZ = 3;
+ }
+
+ // Singular
+ optional int32 optional_int32 = 1;
+ optional float optional_float = 11;
+ optional double optional_double = 12;
+ optional string optional_string = 14;
+ optional bytes optional_bytes = 15;
+
+ optional NestedMessage optional_nested_message = 18;
+
+ optional NestedEnum optional_nested_enum = 21;
+
+ // Repeated
+ repeated int32 repeated_int32 = 31;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+
+ repeated NestedMessage repeated_nested_message = 48;
+
+ repeated NestedEnum repeated_nested_enum = 51;
+
+ // Singular with defaults
+ optional int32 default_int32 = 61 [default = 41 ];
+ optional string default_string = 74 [default = "hello"];
+ optional bytes default_bytes = 75 [default = "world"];
+
+ optional float default_float_nan = 99 [default = nan];
+
+ optional NestedEnum default_nested_enum = 81 [default = BAR];
+
+ // Required
+ required int32 id = 86;
+
+ // Add enough optional fields to make 2 bit fields in total
+ optional int32 filler100 = 100;
+ optional int32 filler101 = 101;
+ optional int32 filler102 = 102;
+ optional int32 filler103 = 103;
+ optional int32 filler104 = 104;
+ optional int32 filler105 = 105;
+ optional int32 filler106 = 106;
+ optional int32 filler107 = 107;
+ optional int32 filler108 = 108;
+ optional int32 filler109 = 109;
+ optional int32 filler110 = 110;
+ optional int32 filler111 = 111;
+ optional int32 filler112 = 112;
+ optional int32 filler113 = 113;
+ optional int32 filler114 = 114;
+ optional int32 filler115 = 115;
+ optional int32 filler116 = 116;
+ optional int32 filler117 = 117;
+ optional int32 filler118 = 118;
+ optional int32 filler119 = 119;
+ optional int32 filler120 = 120;
+ optional int32 filler121 = 121;
+ optional int32 filler122 = 122;
+ optional int32 filler123 = 123;
+ optional int32 filler124 = 124;
+ optional int32 filler125 = 125;
+ optional int32 filler126 = 126;
+ optional int32 filler127 = 127;
+ optional int32 filler128 = 128;
+ optional int32 filler129 = 129;
+ optional int32 filler130 = 130;
+
+ optional int32 before_bit_field_check = 139;
+ optional int32 bit_field_check = 140;
+ optional int32 after_bit_field_check = 141;
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_enum_class_multiple_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_enum_class_multiple_nano.proto
new file mode 100644
index 0000000000..958e1f17ca
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_enum_class_multiple_nano.proto
@@ -0,0 +1,48 @@
+// 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.
+
+// Author: maxtroy@google.com (Max Cai)
+
+package protobuf_unittest;
+
+option java_package = "com.google.protobuf";
+option java_multiple_files = true;
+
+enum FileScopeEnumMultiple {
+ THREE = 3;
+}
+
+message EnumClassNanoMultiple {
+ enum MessageScopeEnumMultiple {
+ FOUR = 4;
+ }
+ optional FileScopeEnumMultiple three = 3 [ default = THREE ];
+ optional MessageScopeEnumMultiple four = 4 [ default = FOUR ];
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_enum_class_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_enum_class_nano.proto
new file mode 100644
index 0000000000..3a1e07f6d9
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_enum_class_nano.proto
@@ -0,0 +1,48 @@
+// 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.
+
+// Author: maxtroy@google.com (Max Cai)
+
+package protobuf_unittest;
+
+option java_package = "com.google.protobuf";
+option java_outer_classname = "EnumClassNanos";
+
+enum FileScopeEnum {
+ ONE = 1;
+}
+
+message EnumClassNano {
+ enum MessageScopeEnum {
+ TWO = 2;
+ }
+ optional FileScopeEnum one = 1 [ default = ONE ];
+ optional MessageScopeEnum two = 2 [ default = TWO ];
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_enum_validity_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_enum_validity_nano.proto
new file mode 100644
index 0000000000..c0da8b422e
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_enum_validity_nano.proto
@@ -0,0 +1,28 @@
+package protobuf_unittest;
+
+option java_package = "com.google.protobuf";
+option java_outer_classname = "EnumValidity";
+
+enum E {
+ default = 1; // test java keyword renaming
+ FOO = 2;
+ BAR = 3;
+ BAZ = 4;
+}
+
+message M {
+ optional E optional_e = 1;
+ optional E default_e = 2 [ default = BAZ ];
+ repeated E repeated_e = 3;
+ repeated E packed_e = 4 [ packed = true ];
+ repeated E repeated_e2 = 5;
+ repeated E packed_e2 = 6 [ packed = true ];
+ repeated E repeated_e3 = 7;
+ repeated E packed_e3 = 8 [ packed = true ];
+}
+
+message Alt {
+ optional E repeated_e2_as_optional = 5;
+ repeated E packed_e2_as_non_packed = 6;
+ repeated E non_packed_e3_as_packed = 7 [ packed = true ];
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_nano.proto
new file mode 100644
index 0000000000..ca56b3dd45
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_nano.proto
@@ -0,0 +1,37 @@
+syntax = "proto2";
+
+option java_outer_classname = "Extensions";
+option java_package = "com.google.protobuf.nano.testext";
+
+message ExtendableMessage {
+ optional int32 field = 1;
+ extensions 10 to max;
+}
+
+enum AnEnum {
+ FIRST_VALUE = 1;
+ SECOND_VALUE = 2;
+}
+
+message AnotherMessage {
+ optional string string = 1;
+ optional bool value = 2;
+ repeated int32 integers = 3;
+}
+
+message ContainerMessage {
+ extend ExtendableMessage {
+ optional bool another_thing = 100;
+ // The largest permitted field number, per
+ // https://developers.google.com/protocol-buffers/docs/proto#simple
+ optional bool large_field_number = 536870911;
+ }
+}
+
+// For testNanoOptionalGroupWithUnknownFieldsEnabled;
+// not part of the extensions tests.
+message MessageWithGroup {
+ optional group Group = 1 {
+ optional int32 a = 2;
+ }
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_packed_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_packed_nano.proto
new file mode 100644
index 0000000000..3b7a004c9e
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_packed_nano.proto
@@ -0,0 +1,29 @@
+syntax = "proto2";
+
+option java_multiple_files = true;
+option java_package = "com.google.protobuf";
+
+import "google/protobuf/nano/unittest_extension_nano.proto";
+
+// Must be compiled separately due to extension number reuse.
+// The reuse is deliberate, for testing wire compatibility.
+
+message PackedExtensions {
+ extend ExtendableMessage {
+ repeated int32 packed_int32 = 10 [ packed = true ];
+ repeated uint32 packed_uint32 = 11 [ packed = true ];
+ repeated sint32 packed_sint32 = 12 [ packed = true ];
+ repeated int64 packed_int64 = 13 [ packed = true ];
+ repeated uint64 packed_uint64 = 14 [ packed = true ];
+ repeated sint64 packed_sint64 = 15 [ packed = true ];
+ repeated fixed32 packed_fixed32 = 16 [ packed = true ];
+ repeated sfixed32 packed_sfixed32 = 17 [ packed = true ];
+ repeated fixed64 packed_fixed64 = 18 [ packed = true ];
+ repeated sfixed64 packed_sfixed64 = 19 [ packed = true ];
+ repeated bool packed_bool = 20 [ packed = true ];
+ repeated float packed_float = 21 [ packed = true ];
+ repeated double packed_double = 22 [ packed = true ];
+ repeated AnEnum packed_enum = 23 [ packed = true ];
+ // Non-packable types omitted.
+ }
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_repeated_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_repeated_nano.proto
new file mode 100644
index 0000000000..e533c65b43
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_repeated_nano.proto
@@ -0,0 +1,34 @@
+syntax = "proto2";
+
+option java_multiple_files = true;
+option java_package = "com.google.protobuf";
+
+import "google/protobuf/nano/unittest_extension_nano.proto";
+
+// Must be compiled separately due to extension number reuse.
+// The reuse is deliberate, for testing wire compatibility.
+
+message RepeatedExtensions {
+ extend ExtendableMessage {
+ repeated int32 repeated_int32 = 10;
+ repeated uint32 repeated_uint32 = 11;
+ repeated sint32 repeated_sint32 = 12;
+ repeated int64 repeated_int64 = 13;
+ repeated uint64 repeated_uint64 = 14;
+ repeated sint64 repeated_sint64 = 15;
+ repeated fixed32 repeated_fixed32 = 16;
+ repeated sfixed32 repeated_sfixed32 = 17;
+ repeated fixed64 repeated_fixed64 = 18;
+ repeated sfixed64 repeated_sfixed64 = 19;
+ repeated bool repeated_bool = 20;
+ repeated float repeated_float = 21;
+ repeated double repeated_double = 22;
+ repeated AnEnum repeated_enum = 23;
+ repeated string repeated_string = 24;
+ repeated bytes repeated_bytes = 25;
+ repeated AnotherMessage repeated_message = 26;
+ repeated group RepeatedGroup = 27 {
+ optional int32 a = 1;
+ }
+ }
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_singular_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_singular_nano.proto
new file mode 100644
index 0000000000..8b2d965888
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_singular_nano.proto
@@ -0,0 +1,34 @@
+syntax = "proto2";
+
+option java_multiple_files = true;
+option java_package = "com.google.protobuf";
+
+import "google/protobuf/nano/unittest_extension_nano.proto";
+
+// Must be compiled separately due to extension number reuse.
+// The reuse is deliberate, for testing wire compatibility.
+
+message SingularExtensions {
+ extend ExtendableMessage {
+ optional int32 some_int32 = 10;
+ optional uint32 some_uint32 = 11;
+ optional sint32 some_sint32 = 12;
+ optional int64 some_int64 = 13;
+ optional uint64 some_uint64 = 14;
+ optional sint64 some_sint64 = 15;
+ optional fixed32 some_fixed32 = 16;
+ optional sfixed32 some_sfixed32 = 17;
+ optional fixed64 some_fixed64 = 18;
+ optional sfixed64 some_sfixed64 = 19;
+ optional bool some_bool = 20;
+ optional float some_float = 21;
+ optional double some_double = 22;
+ optional AnEnum some_enum = 23;
+ optional string some_string = 24;
+ optional bytes some_bytes = 25;
+ optional AnotherMessage some_message = 26;
+ optional group SomeGroup = 27 {
+ optional int32 a = 1;
+ }
+ }
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_has_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_has_nano.proto
new file mode 100644
index 0000000000..fe7d1794a7
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_has_nano.proto
@@ -0,0 +1,82 @@
+// 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.
+
+// Author: ulas@google.com (Ulas Kirazci)
+
+package protobuf_unittest;
+
+option java_package = "com.google.protobuf";
+option java_outer_classname = "NanoHasOuterClass";
+
+message TestAllTypesNanoHas {
+
+ message NestedMessage {
+ optional int32 bb = 1;
+ }
+
+ enum NestedEnum {
+ FOO = 1;
+ BAR = 2;
+ BAZ = 3;
+ }
+
+ // Singular
+ optional int32 optional_int32 = 1;
+ optional float optional_float = 11;
+ optional double optional_double = 12;
+ optional string optional_string = 14;
+ optional bytes optional_bytes = 15;
+
+ optional NestedMessage optional_nested_message = 18;
+
+ optional NestedEnum optional_nested_enum = 21;
+
+ // Repeated
+ repeated int32 repeated_int32 = 31;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+
+ repeated NestedMessage repeated_nested_message = 48;
+
+ repeated NestedEnum repeated_nested_enum = 51;
+
+ // Singular with defaults
+ optional int32 default_int32 = 61 [default = 41 ];
+ optional string default_string = 74 [default = "hello"];
+ optional bytes default_bytes = 75 [default = "world"];
+
+ optional float default_float_nan = 99 [default = nan];
+
+ optional NestedEnum default_nested_enum = 81 [default = BAR];
+
+ required int32 id = 86;
+ required NestedEnum required_enum = 87;
+
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_import_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_import_nano.proto
new file mode 100644
index 0000000000..1a3ddc57ea
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_import_nano.proto
@@ -0,0 +1,48 @@
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+//
+// This is like unittest_import.proto but with optimize_for = NANO_RUNTIME.
+
+package protobuf_unittest_import;
+
+option java_package = "com.google.protobuf.nano.testimport";
+option java_outer_classname = "UnittestImportNano";
+
+message ImportMessageNano {
+ optional int32 d = 1;
+}
+
+enum ImportEnumNano {
+ IMPORT_NANO_FOO = 7;
+ IMPORT_NANO_BAR = 8;
+ IMPORT_NANO_BAZ = 9;
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_multiple_nameclash_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_multiple_nameclash_nano.proto
new file mode 100644
index 0000000000..b31c43994c
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_multiple_nameclash_nano.proto
@@ -0,0 +1,41 @@
+// 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.
+
+// Author: maxtroy@google.com (Max Cai)
+
+package protobuf_unittest_import;
+
+option java_package = "com.google.protobuf";
+option java_outer_classname = "MultipleNameClashNano";
+option java_multiple_files = true;
+
+message MultipleNameClashNano {
+ optional int32 field = 1;
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_multiple_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_multiple_nano.proto
new file mode 100644
index 0000000000..406ab7741c
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_multiple_nano.proto
@@ -0,0 +1,63 @@
+// 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.
+
+// Author: maxtroy@google.com (Max Cai)
+
+package protobuf_unittest_import;
+
+import "google/protobuf/nano/unittest_import_nano.proto";
+
+option java_package = "com.google.protobuf";
+option java_multiple_files = true;
+
+enum FileScopeEnum {
+ ONE = 1;
+ TWO = 2;
+}
+
+message FileScopeEnumRefNano {
+ optional FileScopeEnum enum_field = 1;
+}
+
+message MessageScopeEnumRefNano {
+ enum MessageScopeEnum {
+ ONE = 1;
+ TWO = 2;
+ }
+ optional MessageScopeEnum enum_field = 1;
+}
+
+message MultipleImportingNonMultipleNano1 {
+ optional ImportMessageNano field = 1;
+}
+
+message MultipleImportingNonMultipleNano2 {
+ optional MultipleImportingNonMultipleNano1 nano1 = 1;
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_nano.proto
new file mode 100644
index 0000000000..3fff24c0c4
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_nano.proto
@@ -0,0 +1,195 @@
+// 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.
+
+// Author: wink@google.com (Wink Saville)
+
+package protobuf_unittest;
+
+import "google/protobuf/nano/unittest_import_nano.proto";
+
+option java_package = "com.google.protobuf";
+option java_outer_classname = "NanoOuterClass";
+
+// Same as TestAllTypes but with the nano runtime.
+message TestAllTypesNano {
+
+ message NestedMessage {
+ optional int32 bb = 1;
+ }
+
+ enum NestedEnum {
+ FOO = 1;
+ BAR = 2;
+ BAZ = 3;
+ }
+
+ // Singular
+ optional int32 optional_int32 = 1;
+ optional int64 optional_int64 = 2;
+ optional uint32 optional_uint32 = 3;
+ optional uint64 optional_uint64 = 4;
+ optional sint32 optional_sint32 = 5;
+ optional sint64 optional_sint64 = 6;
+ optional fixed32 optional_fixed32 = 7;
+ optional fixed64 optional_fixed64 = 8;
+ optional sfixed32 optional_sfixed32 = 9;
+ optional sfixed64 optional_sfixed64 = 10;
+ optional float optional_float = 11;
+ optional double optional_double = 12;
+ optional bool optional_bool = 13;
+ optional string optional_string = 14;
+ optional bytes optional_bytes = 15;
+
+ optional group OptionalGroup = 16 {
+ optional int32 a = 17;
+ }
+
+ optional NestedMessage optional_nested_message = 18;
+ optional ForeignMessageNano optional_foreign_message = 19;
+ optional protobuf_unittest_import.ImportMessageNano
+ optional_import_message = 20;
+
+ optional NestedEnum optional_nested_enum = 21;
+ optional ForeignEnumNano optional_foreign_enum = 22;
+ optional protobuf_unittest_import.ImportEnumNano optional_import_enum = 23;
+
+ optional string optional_string_piece = 24 [ctype=STRING_PIECE];
+ optional string optional_cord = 25 [ctype=CORD];
+
+ // Repeated
+ repeated int32 repeated_int32 = 31;
+ repeated int64 repeated_int64 = 32;
+ repeated uint32 repeated_uint32 = 33;
+ repeated uint64 repeated_uint64 = 34;
+ repeated sint32 repeated_sint32 = 35;
+ repeated sint64 repeated_sint64 = 36;
+ repeated fixed32 repeated_fixed32 = 37;
+ repeated fixed64 repeated_fixed64 = 38;
+ repeated sfixed32 repeated_sfixed32 = 39;
+ repeated sfixed64 repeated_sfixed64 = 40;
+ repeated float repeated_float = 41;
+ repeated double repeated_double = 42;
+ repeated bool repeated_bool = 43;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+
+ repeated group RepeatedGroup = 46 {
+ optional int32 a = 47;
+ }
+
+ repeated NestedMessage repeated_nested_message = 48;
+ repeated ForeignMessageNano repeated_foreign_message = 49;
+ repeated protobuf_unittest_import.ImportMessageNano
+ repeated_import_message = 50;
+
+ repeated NestedEnum repeated_nested_enum = 51;
+ repeated ForeignEnumNano repeated_foreign_enum = 52;
+ repeated protobuf_unittest_import.ImportEnumNano repeated_import_enum = 53;
+
+ repeated string repeated_string_piece = 54 [ctype=STRING_PIECE];
+ repeated string repeated_cord = 55 [ctype=CORD];
+
+ // Repeated packed
+ repeated int32 repeated_packed_int32 = 87 [packed=true];
+ repeated sfixed64 repeated_packed_sfixed64 = 88 [packed=true];
+
+ repeated NestedEnum repeated_packed_nested_enum = 89 [packed=true];
+
+ // Singular with defaults
+ optional int32 default_int32 = 61 [default = 41 ];
+ optional int64 default_int64 = 62 [default = 42 ];
+ optional uint32 default_uint32 = 63 [default = 43 ];
+ optional uint64 default_uint64 = 64 [default = 44 ];
+ optional sint32 default_sint32 = 65 [default = -45 ];
+ optional sint64 default_sint64 = 66 [default = 46 ];
+ optional fixed32 default_fixed32 = 67 [default = 47 ];
+ optional fixed64 default_fixed64 = 68 [default = 48 ];
+ optional sfixed32 default_sfixed32 = 69 [default = 49 ];
+ optional sfixed64 default_sfixed64 = 70 [default = -50 ];
+ optional float default_float = 71 [default = 51.5 ];
+ optional double default_double = 72 [default = 52e3 ];
+ optional bool default_bool = 73 [default = true ];
+ optional string default_string = 74 [default = "hello"];
+ optional bytes default_bytes = 75 [default = "world"];
+
+ optional string default_string_nonascii = 76 [default = "dünya"];
+ optional bytes default_bytes_nonascii = 77 [default = "dünyab"];
+
+ optional float default_float_inf = 97 [default = inf];
+ optional float default_float_neg_inf = 98 [default = -inf];
+ optional float default_float_nan = 99 [default = nan];
+ optional double default_double_inf = 100 [default = inf];
+ optional double default_double_neg_inf = 101 [default = -inf];
+ optional double default_double_nan = 102 [default = nan];
+
+ optional NestedEnum default_nested_enum = 81 [default = BAR];
+ optional ForeignEnumNano default_foreign_enum = 82
+ [default = FOREIGN_NANO_BAR];
+ optional protobuf_unittest_import.ImportEnumNano
+ default_import_enum = 83 [default = IMPORT_NANO_BAR];
+
+ optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"];
+ optional string default_cord = 85 [ctype=CORD,default="123"];
+
+ required int32 id = 86;
+
+ // Try to cause conflicts.
+ optional int32 tag = 93;
+ optional int32 get_serialized_size = 94;
+ optional int32 write_to = 95;
+
+ // Try to fail with java reserved keywords
+ optional int32 synchronized = 96;
+
+ oneof oneof_field {
+ uint32 oneof_uint32 = 111;
+ NestedMessage oneof_nested_message = 112;
+ string oneof_string = 123;
+ bytes oneof_bytes = 124;
+ fixed64 oneof_fixed64 = 115;
+ NestedEnum oneof_enum = 116;
+ }
+}
+
+message ForeignMessageNano {
+ optional int32 c = 1;
+}
+
+enum ForeignEnumNano {
+ FOREIGN_NANO_FOO = 4;
+ FOREIGN_NANO_BAR = 5;
+ FOREIGN_NANO_BAZ = 6;
+}
+
+// Test that deprecated fields work. We only verify that they compile (at one
+// point this failed).
+message TestDeprecatedNano {
+ optional int32 deprecated_field = 1 [deprecated = true];
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_recursive_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_recursive_nano.proto
new file mode 100644
index 0000000000..29b944f01f
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_recursive_nano.proto
@@ -0,0 +1,49 @@
+// 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.
+
+// Author: wink@google.com (Wink Saville)
+//
+
+package protobuf_unittest_import;
+
+option java_package = "com.google.protobuf";
+// Explicit outer classname to suppress legacy info.
+option java_outer_classname = "UnittestRecursiveNano";
+
+message RecursiveMessageNano {
+ message NestedMessage {
+ optional RecursiveMessageNano a = 1;
+ }
+
+ required int32 id = 1;
+ optional NestedMessage nested_message = 2;
+ optional RecursiveMessageNano optional_recursive_message_nano = 3;
+ repeated RecursiveMessageNano repeated_recursive_message_nano = 4;
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_reference_types_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_reference_types_nano.proto
new file mode 100644
index 0000000000..82eb8d1175
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_reference_types_nano.proto
@@ -0,0 +1,116 @@
+package protobuf_unittest;
+
+option java_package = "com.google.protobuf";
+option java_outer_classname = "NanoReferenceTypes";
+
+message TestAllTypesNano {
+
+ enum NestedEnum {
+ FOO = 1;
+ BAR = 2;
+ BAZ = 3;
+ }
+
+ message NestedMessage {
+ optional int32 foo = 1;
+ }
+
+ // Singular
+ optional int32 optional_int32 = 1;
+ optional int64 optional_int64 = 2;
+ optional uint32 optional_uint32 = 3;
+ optional uint64 optional_uint64 = 4;
+ optional sint32 optional_sint32 = 5;
+ optional sint64 optional_sint64 = 6;
+ optional fixed32 optional_fixed32 = 7;
+ optional fixed64 optional_fixed64 = 8;
+ optional sfixed32 optional_sfixed32 = 9;
+ optional sfixed64 optional_sfixed64 = 10;
+ optional float optional_float = 11;
+ optional double optional_double = 12;
+ optional bool optional_bool = 13;
+ optional string optional_string = 14;
+ optional bytes optional_bytes = 15;
+
+ optional group OptionalGroup = 16 {
+ optional int32 a = 17;
+ }
+
+ optional NestedMessage optional_nested_message = 18;
+
+ optional NestedEnum optional_nested_enum = 21;
+
+ optional string optional_string_piece = 24 [ctype=STRING_PIECE];
+ optional string optional_cord = 25 [ctype=CORD];
+
+ // Repeated
+ repeated int32 repeated_int32 = 31;
+ repeated int64 repeated_int64 = 32;
+ repeated uint32 repeated_uint32 = 33;
+ repeated uint64 repeated_uint64 = 34;
+ repeated sint32 repeated_sint32 = 35;
+ repeated sint64 repeated_sint64 = 36;
+ repeated fixed32 repeated_fixed32 = 37;
+ repeated fixed64 repeated_fixed64 = 38;
+ repeated sfixed32 repeated_sfixed32 = 39;
+ repeated sfixed64 repeated_sfixed64 = 40;
+ repeated float repeated_float = 41;
+ repeated double repeated_double = 42;
+ repeated bool repeated_bool = 43;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+
+ repeated group RepeatedGroup = 46 {
+ optional int32 a = 47;
+ }
+
+ repeated NestedMessage repeated_nested_message = 48;
+
+ repeated NestedEnum repeated_nested_enum = 51;
+
+ repeated string repeated_string_piece = 54 [ctype=STRING_PIECE];
+ repeated string repeated_cord = 55 [ctype=CORD];
+
+ // Repeated packed
+ repeated int32 repeated_packed_int32 = 87 [packed=true];
+ repeated sfixed64 repeated_packed_sfixed64 = 88 [packed=true];
+
+ repeated NestedEnum repeated_packed_nested_enum = 89 [packed=true];
+
+ // Singular with defaults
+ optional int32 default_int32 = 61 [default = 41 ];
+ optional int64 default_int64 = 62 [default = 42 ];
+ optional uint32 default_uint32 = 63 [default = 43 ];
+ optional uint64 default_uint64 = 64 [default = 44 ];
+ optional sint32 default_sint32 = 65 [default = -45 ];
+ optional sint64 default_sint64 = 66 [default = 46 ];
+ optional fixed32 default_fixed32 = 67 [default = 47 ];
+ optional fixed64 default_fixed64 = 68 [default = 48 ];
+ optional sfixed32 default_sfixed32 = 69 [default = 49 ];
+ optional sfixed64 default_sfixed64 = 70 [default = -50 ];
+ optional float default_float = 71 [default = 51.5 ];
+ optional double default_double = 72 [default = 52e3 ];
+ optional bool default_bool = 73 [default = true ];
+ optional string default_string = 74 [default = "hello"];
+ optional bytes default_bytes = 75 [default = "world"];
+
+
+ optional float default_float_inf = 97 [default = inf];
+ optional float default_float_neg_inf = 98 [default = -inf];
+ optional float default_float_nan = 99 [default = nan];
+ optional double default_double_inf = 100 [default = inf];
+ optional double default_double_neg_inf = 101 [default = -inf];
+ optional double default_double_nan = 102 [default = nan];
+
+}
+
+message ForeignMessageNano {
+ optional int32 c = 1;
+}
+
+enum ForeignEnumNano {
+ FOREIGN_NANO_FOO = 4;
+ FOREIGN_NANO_BAR = 5;
+ FOREIGN_NANO_BAZ = 6;
+}
+
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_repeated_merge_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_repeated_merge_nano.proto
new file mode 100644
index 0000000000..ef4e2d2f65
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_repeated_merge_nano.proto
@@ -0,0 +1,47 @@
+// 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.
+
+// Author: maxtroy@google.com (Max Cai)
+
+package protobuf_unittest;
+
+import "google/protobuf/nano/unittest_nano.proto";
+
+option java_package = "com.google.protobuf";
+option java_multiple_files = true;
+
+// A container message for testing the merging of repeated fields at a
+// nested level. Other tests will be done using the repeated fields in
+// TestAllTypesNano.
+message TestRepeatedMergeNano {
+
+ optional TestAllTypesNano contained = 1;
+
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_repeated_packables_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_repeated_packables_nano.proto
new file mode 100644
index 0000000000..96af8856cf
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_repeated_packables_nano.proto
@@ -0,0 +1,95 @@
+// 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.
+
+// Author: maxtroy@google.com (Max Cai)
+
+package protobuf_unittest;
+
+option java_package = "com.google.protobuf";
+option java_outer_classname = "NanoRepeatedPackables";
+
+enum Enum {
+ OPTION_ONE = 1;
+ OPTION_TWO = 2;
+}
+
+// Two almost identical messages with all packable repeated field types.
+// One with none marked as packed and the other all packed. For
+// compatibility, they should be able to parse each other's serialized
+// forms.
+
+message NonPacked {
+
+ // All packable types, none marked as packed.
+
+ repeated int32 int32s = 1;
+ repeated int64 int64s = 2;
+ repeated uint32 uint32s = 3;
+ repeated uint64 uint64s = 4;
+ repeated sint32 sint32s = 5;
+ repeated sint64 sint64s = 6;
+ repeated fixed32 fixed32s = 7;
+ repeated fixed64 fixed64s = 8;
+ repeated sfixed32 sfixed32s = 9;
+ repeated sfixed64 sfixed64s = 10;
+ repeated float floats = 11;
+ repeated double doubles = 12;
+ repeated bool bools = 13;
+ repeated Enum enums = 14;
+
+ // Noise for testing merged deserialization.
+ optional int32 noise = 15;
+
+}
+
+message Packed {
+
+ // All packable types, all matching the field numbers in NonPacked,
+ // all marked as packed.
+
+ repeated int32 int32s = 1 [ packed = true ];
+ repeated int64 int64s = 2 [ packed = true ];
+ repeated uint32 uint32s = 3 [ packed = true ];
+ repeated uint64 uint64s = 4 [ packed = true ];
+ repeated sint32 sint32s = 5 [ packed = true ];
+ repeated sint64 sint64s = 6 [ packed = true ];
+ repeated fixed32 fixed32s = 7 [ packed = true ];
+ repeated fixed64 fixed64s = 8 [ packed = true ];
+ repeated sfixed32 sfixed32s = 9 [ packed = true ];
+ repeated sfixed64 sfixed64s = 10 [ packed = true ];
+ repeated float floats = 11 [ packed = true ];
+ repeated double doubles = 12 [ packed = true ];
+ repeated bool bools = 13 [ packed = true ];
+ repeated Enum enums = 14 [ packed = true ];
+
+ // Noise for testing merged deserialization.
+ optional int32 noise = 15;
+
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_simple_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_simple_nano.proto
new file mode 100644
index 0000000000..25786cc227
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_simple_nano.proto
@@ -0,0 +1,54 @@
+// 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.
+
+// Author: wink@google.com (Wink Saville)
+//
+
+package protobuf_unittest_import;
+
+option java_package = "com.google.protobuf";
+// Explicit outer classname to suppress legacy info.
+option java_outer_classname = "UnittestSimpleNano";
+
+message SimpleMessageNano {
+ message NestedMessage {
+ optional int32 bb = 1;
+ }
+
+ enum NestedEnum {
+ FOO = 1;
+ BAR = 2;
+ BAZ = 3;
+ }
+
+ optional int32 d = 1 [default = 123];
+ optional NestedMessage nested_msg = 2;
+ optional NestedEnum default_nested_enum = 3 [default = BAZ];
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_single_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_single_nano.proto
new file mode 100644
index 0000000000..7de30c877d
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_single_nano.proto
@@ -0,0 +1,38 @@
+// 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.
+
+// Author: maxtroy@google.com (Max Cai)
+
+package protobuf_unittest_import;
+
+option java_package = "com.google.protobuf";
+
+message SingleMessageNano {
+}
diff --git a/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_stringutf8_nano.proto b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_stringutf8_nano.proto
new file mode 100644
index 0000000000..bbd677cfd6
--- /dev/null
+++ b/third_party/protobuf/javanano/src/test/java/com/google/protobuf/nano/unittest_stringutf8_nano.proto
@@ -0,0 +1,43 @@
+// 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.
+
+// Author: wink@google.com (Wink Saville)
+//
+
+package protobuf_unittest_import;
+
+option java_package = "com.google.protobuf";
+// Explicit outer classname to suppress legacy info.
+option java_outer_classname = "UnittestStringutf8Nano";
+
+message StringUtf8 {
+ optional string id = 1;
+ repeated string rs = 2;
+}
diff --git a/third_party/protobuf/jenkins/README.md b/third_party/protobuf/jenkins/README.md
new file mode 100644
index 0000000000..29f664f299
--- /dev/null
+++ b/third_party/protobuf/jenkins/README.md
@@ -0,0 +1,6 @@
+
+Jenkins Infrastructure
+----------------------
+
+The scripts in this directory serve as plumbing for running the protobuf
+tests under Jenkins.
diff --git a/third_party/protobuf/jenkins/build_and_run_docker.sh b/third_party/protobuf/jenkins/build_and_run_docker.sh
new file mode 100755
index 0000000000..50e1e8c684
--- /dev/null
+++ b/third_party/protobuf/jenkins/build_and_run_docker.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+#
+# Builds docker image and runs a command under it.
+# This is a generic script that is configured with the following variables:
+#
+# DOCKERFILE_DIR - Directory in which Dockerfile file is located.
+# DOCKER_RUN_SCRIPT - Script to run under docker (relative to protobuf repo root)
+# OUTPUT_DIR - Directory that will be copied from inside docker after finishing.
+# $@ - Extra args to pass to docker run
+
+
+set -ex
+
+cd $(dirname $0)/..
+git_root=$(pwd)
+cd -
+
+# Use image name based on Dockerfile location checksum
+DOCKER_IMAGE_NAME=$(basename $DOCKERFILE_DIR)_$(sha1sum $DOCKERFILE_DIR/Dockerfile | cut -f1 -d\ )
+
+# Make sure docker image has been built. Should be instantaneous if so.
+docker build -t $DOCKER_IMAGE_NAME $DOCKERFILE_DIR
+
+# Ensure existence of ccache directory
+CCACHE_DIR=/tmp/protobuf-ccache
+mkdir -p $CCACHE_DIR
+
+# Choose random name for docker container
+CONTAINER_NAME="build_and_run_docker_$(uuidgen)"
+
+# Run command inside docker
+docker run \
+ "$@" \
+ -e CCACHE_DIR=$CCACHE_DIR \
+ -e EXTERNAL_GIT_ROOT="/var/local/jenkins/protobuf" \
+ -e TEST_SET="$TEST_SET" \
+ -e THIS_IS_REALLY_NEEDED='see https://github.com/docker/docker/issues/14203 for why docker is awful' \
+ -v "$git_root:/var/local/jenkins/protobuf:ro" \
+ -v $CCACHE_DIR:$CCACHE_DIR \
+ -w /var/local/git/protobuf \
+ --name=$CONTAINER_NAME \
+ $DOCKER_IMAGE_NAME \
+ bash -l "/var/local/jenkins/protobuf/$DOCKER_RUN_SCRIPT" || FAILED="true"
+
+# Copy output artifacts
+if [ "$OUTPUT_DIR" != "" ]
+then
+ docker cp "$CONTAINER_NAME:/var/local/git/protobuf/$OUTPUT_DIR" "$git_root" || FAILED="true"
+fi
+
+# remove the container, possibly killing it first
+docker rm -f $CONTAINER_NAME || true
+
+if [ "$FAILED" != "" ]
+then
+ exit 1
+fi
diff --git a/third_party/protobuf/jenkins/buildcmds/README.md b/third_party/protobuf/jenkins/buildcmds/README.md
new file mode 100644
index 0000000000..7a48f2d5c9
--- /dev/null
+++ b/third_party/protobuf/jenkins/buildcmds/README.md
@@ -0,0 +1,6 @@
+
+Jenkins Build Commands
+----------------------
+
+The scripts in this directory are designed to be top-level entry points for
+Jenkins projects.
diff --git a/third_party/protobuf/jenkins/buildcmds/pull_request.sh b/third_party/protobuf/jenkins/buildcmds/pull_request.sh
new file mode 100755
index 0000000000..51e4bfa48c
--- /dev/null
+++ b/third_party/protobuf/jenkins/buildcmds/pull_request.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+#
+# This is the top-level script we give to Jenkins as the entry point for
+# running the "pull request" project:
+#
+# https://grpc-testing.appspot.com/view/Protocol%20Buffers/job/protobuf_pull_request/
+#
+# This script selects a specific Dockerfile (for building a Docker image) and
+# a script to run inside that image. Then we delegate to the general
+# build_and_run_docker.sh script.
+
+export DOCKERFILE_DIR=jenkins/docker
+export DOCKER_RUN_SCRIPT=jenkins/pull_request_in_docker.sh
+export OUTPUT_DIR=testoutput
+export TEST_SET="csharp java_jdk7 javanano_jdk7 java_oracle7 javanano_oracle7 python python_cpp ruby_all javascript golang php_all"
+./jenkins/build_and_run_docker.sh
diff --git a/third_party/protobuf/jenkins/buildcmds/pull_request_32.sh b/third_party/protobuf/jenkins/buildcmds/pull_request_32.sh
new file mode 100755
index 0000000000..bf0fb7ffe3
--- /dev/null
+++ b/third_party/protobuf/jenkins/buildcmds/pull_request_32.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+#
+# This is the top-level script we give to Jenkins as the entry point for
+# running the "pull request 32" project:
+#
+# https://grpc-testing.appspot.com/view/Protocol%20Buffers/job/Protocol%20Buffers%20Pull%20Request%2032/
+#
+# This script selects a specific Dockerfile (for building a Docker image) and
+# a script to run inside that image. Then we delegate to the general
+# build_and_run_docker.sh script.
+
+export DOCKERFILE_DIR=jenkins/docker32
+export DOCKER_RUN_SCRIPT=jenkins/pull_request_in_docker.sh
+export OUTPUT_DIR=testoutput
+export TEST_SET="php_all_32"
+./jenkins/build_and_run_docker.sh
diff --git a/third_party/protobuf/jenkins/docker/Dockerfile b/third_party/protobuf/jenkins/docker/Dockerfile
new file mode 100644
index 0000000000..659336d825
--- /dev/null
+++ b/third_party/protobuf/jenkins/docker/Dockerfile
@@ -0,0 +1,207 @@
+# This Dockerfile specifies the recipe for creating an image for the tests
+# to run in.
+#
+# We install as many test dependencies here as we can, because these setup
+# steps can be cached. They do *not* run every time we run the build.
+# The Docker image is only rebuilt when the Dockerfile (ie. this file)
+# changes.
+
+# Base Dockerfile for gRPC dev images
+FROM debian:latest
+
+# Apt source for old Python versions.
+RUN echo 'deb http://ppa.launchpad.net/fkrull/deadsnakes/ubuntu trusty main' > /etc/apt/sources.list.d/deadsnakes.list && \
+ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DB82666C
+
+# Apt source for Oracle Java.
+RUN echo 'deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main' > /etc/apt/sources.list.d/webupd8team-java-trusty.list && \
+ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886 && \
+ echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections
+
+# Apt source for Mono
+RUN echo "deb http://download.mono-project.com/repo/debian wheezy main" | tee /etc/apt/sources.list.d/mono-xamarin.list && \
+ echo "deb http://download.mono-project.com/repo/debian wheezy-libjpeg62-compat main" | tee -a /etc/apt/sources.list.d/mono-xamarin.list && \
+ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
+
+# Apt source for php
+RUN echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu trusty main" | tee /etc/apt/sources.list.d/various-php.list && \
+ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F4FCBB07
+
+# Install dotnet SDK based on https://www.microsoft.com/net/core#debian
+# (Ubuntu instructions need apt to support https)
+RUN apt-get update && apt-get install -y --force-yes curl libunwind8 gettext && \
+ curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809130 && \
+ mkdir -p /opt/dotnet && tar zxf dotnet.tar.gz -C /opt/dotnet && \
+ ln -s /opt/dotnet/dotnet /usr/local/bin
+
+# Install dependencies. We start with the basic ones require to build protoc
+# and the C++ build
+RUN apt-get clean && apt-get update && apt-get install -y --force-yes \
+ autoconf \
+ autotools-dev \
+ build-essential \
+ bzip2 \
+ ccache \
+ curl \
+ gcc \
+ git \
+ libc6 \
+ libc6-dbg \
+ libc6-dev \
+ libgtest-dev \
+ libtool \
+ make \
+ parallel \
+ time \
+ wget \
+ # -- For csharp --
+ mono-devel \
+ referenceassemblies-pcl \
+ nunit \
+ # -- For all Java builds -- \
+ maven \
+ # -- For java_jdk6 -- \
+ # oops! not in jessie. too old? openjdk-6-jdk \
+ # -- For java_jdk7 -- \
+ openjdk-7-jdk \
+ # -- For java_oracle7 -- \
+ oracle-java7-installer \
+ # -- For python / python_cpp -- \
+ python-setuptools \
+ python-pip \
+ python-dev \
+ python2.6-dev \
+ python3.3-dev \
+ python3.4-dev \
+ # -- For Ruby --
+ ruby \
+ # -- For C++ benchmarks --
+ cmake \
+ # -- For PHP --
+ php5.6 \
+ php5.6-dev \
+ php5.6-xml \
+ php7.0 \
+ php7.0-dev \
+ php7.0-xml \
+ phpunit \
+ valgrind \
+ libxml2-dev \
+ && apt-get clean
+
+##################
+# C# dependencies
+
+RUN wget www.nuget.org/NuGet.exe -O /usr/local/bin/nuget.exe
+
+##################
+# Python dependencies
+
+# These packages exist in apt-get, but their versions are too old, so we have
+# to get updates from pip.
+
+RUN pip install pip --upgrade
+RUN pip install virtualenv tox yattag
+
+##################
+# Ruby dependencies
+
+# Install rvm
+RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
+RUN \curl -sSL https://get.rvm.io | bash -s stable
+
+# Install Ruby 2.1, Ruby 2.2 and JRuby 1.7
+RUN /bin/bash -l -c "rvm install ruby-2.1"
+RUN /bin/bash -l -c "rvm install ruby-2.2"
+RUN /bin/bash -l -c "rvm install jruby-1.7"
+RUN /bin/bash -l -c "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
+RUN /bin/bash -l -c "echo 'export PATH=/usr/local/rvm/bin:$PATH' >> ~/.bashrc"
+RUN /bin/bash -l -c "gem install bundler --no-ri --no-rdoc"
+
+##################
+# Java dependencies
+
+# This step requires compiling protoc. :(
+
+ENV MAVEN_REPO /var/maven_local_repository
+ENV MVN mvn --batch-mode
+
+RUN cd /tmp && \
+ git clone https://github.com/google/protobuf.git && \
+ cd protobuf && \
+ git reset 6b27c1f981a9a93918e4039f236ead27165a8e91 && \
+ ./autogen.sh && \
+ ./configure && \
+ make -j4 && \
+ cd java && \
+ $MVN install dependency:go-offline -Dmaven.repo.local=$MAVEN_REPO && \
+ cd ../javanano && \
+ $MVN install dependency:go-offline -Dmaven.repo.local=$MAVEN_REPO
+
+##################
+# PHP dependencies.
+RUN wget http://am1.php.net/get/php-5.5.38.tar.bz2/from/this/mirror
+RUN mv mirror php-5.5.38.tar.bz2
+RUN tar -xvf php-5.5.38.tar.bz2
+RUN cd php-5.5.38 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-5.5-zts && \
+ make && make install && cd ..
+RUN cd php-5.5.38 && make clean && ./configure --prefix=/usr/local/php-5.5 && \
+ make && make install && cd ..
+RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
+RUN php composer-setup.php
+RUN mv composer.phar /usr/bin/composer
+RUN php -r "unlink('composer-setup.php');"
+RUN composer config -g -- disable-tls true
+RUN composer config -g -- secure-http false
+RUN cd /tmp && \
+ rm -rf protobuf && \
+ git clone https://github.com/google/protobuf.git && \
+ cd protobuf && \
+ git reset 46ae90dc5e145b12fffa7e053a908a9f3e066286 && \
+ cd php && \
+ ln -sfn /usr/local/php-5.5/bin/php /usr/bin/php && \
+ ln -sfn /usr/local/php-5.5/bin/php-config /usr/bin/php-config && \
+ ln -sfn /usr/local/php-5.5/bin/phpize /usr/bin/phpize && \
+ composer install && \
+ mv vendor /usr/local/vendor-5.5 && \
+ ln -sfn /usr/bin/php5.6 /usr/bin/php && \
+ ln -sfn /usr/bin/php-config5.6 /usr/bin/php-config && \
+ ln -sfn /usr/bin/phpize5.6 /usr/bin/phpize && \
+ composer install && \
+ mv vendor /usr/local/vendor-5.6 && \
+ ln -sfn /usr/bin/php7.0 /usr/bin/php && \
+ ln -sfn /usr/bin/php-config7.0 /usr/bin/php-config && \
+ ln -sfn /usr/bin/phpize7.0 /usr/bin/phpize && \
+ composer install && \
+ mv vendor /usr/local/vendor-7.0
+
+##################
+# Go dependencies.
+RUN apt-get install -y \
+ # -- For go -- \
+ golang
+
+##################
+# Javascript dependencies.
+RUN apt-get install -y \
+ # -- For javascript -- \
+ npm
+
+# On Debian/Ubuntu, nodejs binary is named 'nodejs' because the name 'node'
+# is taken by another legacy binary. We don't have that legacy binary and
+# npm expects the binary to be named 'node', so we just create a symbol
+# link here.
+RUN ln -s `which nodejs` /usr/bin/node
+
+##################
+# Prepare ccache
+
+RUN ln -s /usr/bin/ccache /usr/local/bin/gcc
+RUN ln -s /usr/bin/ccache /usr/local/bin/g++
+RUN ln -s /usr/bin/ccache /usr/local/bin/cc
+RUN ln -s /usr/bin/ccache /usr/local/bin/c++
+RUN ln -s /usr/bin/ccache /usr/local/bin/clang
+RUN ln -s /usr/bin/ccache /usr/local/bin/clang++
+
+# Define the default command.
+CMD ["bash"]
diff --git a/third_party/protobuf/jenkins/docker32/Dockerfile b/third_party/protobuf/jenkins/docker32/Dockerfile
new file mode 100644
index 0000000000..02e9df176c
--- /dev/null
+++ b/third_party/protobuf/jenkins/docker32/Dockerfile
@@ -0,0 +1,111 @@
+# This Dockerfile specifies the recipe for creating an image for the tests
+# to run in.
+#
+# We install as many test dependencies here as we can, because these setup
+# steps can be cached. They do *not* run every time we run the build.
+# The Docker image is only rebuilt when the Dockerfile (ie. this file)
+# changes.
+
+# Base Dockerfile for gRPC dev images
+FROM 32bit/debian:latest
+
+# Apt source for php
+RUN echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu trusty main" | tee /etc/apt/sources.list.d/various-php.list && \
+ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F4FCBB07
+
+# Install dependencies. We start with the basic ones require to build protoc
+# and the C++ build
+RUN apt-get clean && apt-get update && apt-get install -y --force-yes \
+ autoconf \
+ autotools-dev \
+ build-essential \
+ bzip2 \
+ ccache \
+ curl \
+ gcc \
+ git \
+ libc6 \
+ libc6-dbg \
+ libc6-dev \
+ libgtest-dev \
+ libtool \
+ make \
+ parallel \
+ time \
+ wget \
+ unzip \
+ # -- For python --
+ python-setuptools \
+ python-pip \
+ python-dev \
+ # -- For C++ benchmarks --
+ cmake \
+ # -- For PHP --
+ php5.5 \
+ php5.5-dev \
+ php5.5-xml \
+ php5.6 \
+ php5.6-dev \
+ php5.6-xml \
+ php7.0 \
+ php7.0-dev \
+ php7.0-xml \
+ phpunit \
+ valgrind \
+ libxml2-dev \
+ && apt-get clean
+
+##################
+# PHP dependencies.
+RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
+RUN php composer-setup.php
+RUN mv composer.phar /usr/bin/composer
+RUN php -r "unlink('composer-setup.php');"
+RUN cd /tmp && \
+ git clone https://github.com/google/protobuf.git && \
+ cd protobuf/php && \
+ git reset 6b27c1f981a9a93918e4039f236ead27165a8e91 && \
+ ln -sfn /usr/bin/php5.5 /usr/bin/php && \
+ ln -sfn /usr/bin/php-config5.5 /usr/bin/php-config && \
+ ln -sfn /usr/bin/phpize5.5 /usr/bin/phpize && \
+ composer install && \
+ mv vendor /usr/local/vendor-5.5 && \
+ ln -sfn /usr/bin/php5.6 /usr/bin/php && \
+ ln -sfn /usr/bin/php-config5.6 /usr/bin/php-config && \
+ ln -sfn /usr/bin/phpize5.6 /usr/bin/phpize && \
+ composer install && \
+ mv vendor /usr/local/vendor-5.6 && \
+ ln -sfn /usr/bin/php7.0 /usr/bin/php && \
+ ln -sfn /usr/bin/php-config7.0 /usr/bin/php-config && \
+ ln -sfn /usr/bin/phpize7.0 /usr/bin/phpize && \
+ composer install && \
+ mv vendor /usr/local/vendor-7.0
+RUN wget http://am1.php.net/get/php-5.5.38.tar.bz2/from/this/mirror
+RUN mv mirror php-5.5.38.tar.bz2
+RUN tar -xvf php-5.5.38.tar.bz2
+RUN cd php-5.5.38 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-5.5-zts && \
+ make && make install && make clean && cd ..
+RUN cd php-5.5.38 && ./configure --enable-bcmath --prefix=/usr/local/php-5.5-bc && \
+ make && make install && make clean && cd ..
+
+##################
+# Python dependencies
+
+# These packages exist in apt-get, but their versions are too old, so we have
+# to get updates from pip.
+
+RUN pip install pip --upgrade
+RUN pip install virtualenv tox yattag
+
+##################
+# Prepare ccache
+
+RUN ln -s /usr/bin/ccache /usr/local/bin/gcc
+RUN ln -s /usr/bin/ccache /usr/local/bin/g++
+RUN ln -s /usr/bin/ccache /usr/local/bin/cc
+RUN ln -s /usr/bin/ccache /usr/local/bin/c++
+RUN ln -s /usr/bin/ccache /usr/local/bin/clang
+RUN ln -s /usr/bin/ccache /usr/local/bin/clang++
+
+# Define the default command.
+CMD ["bash"]
diff --git a/third_party/protobuf/jenkins/make_test_output.py b/third_party/protobuf/jenkins/make_test_output.py
new file mode 100644
index 0000000000..b1f2e2c0bb
--- /dev/null
+++ b/third_party/protobuf/jenkins/make_test_output.py
@@ -0,0 +1,91 @@
+"""Gathers output from test runs and create an XML file in JUnit format.
+
+The output files from the individual tests have been written in a directory
+structure like:
+
+ $DIR/joblog (output from "parallel --joblog joblog")
+ $DIR/logs/1/cpp/stdout
+ $DIR/logs/1/cpp/stderr
+ $DIR/logs/1/csharp/stdout
+ $DIR/logs/1/csharp/stderr
+ $DIR/logs/1/java_jdk7/stdout
+ $DIR/logs/1/java_jdk7/stderr
+ etc.
+
+This script bundles them into a single output XML file so Jenkins can show
+detailed test results. It runs as the last step before the Jenkins build
+finishes.
+"""
+
+import os;
+import sys;
+from yattag import Doc
+from collections import defaultdict
+
+def readtests(basedir):
+ tests = defaultdict(dict)
+
+ # Sample input (note: separators are tabs).
+ #
+ # Seq Host Starttime Runtime Send Receive Exitval Signal Command
+ # 1 : 1456263838.313 0.005 0 0 0 0 echo A
+ with open(basedir + "/joblog") as jobs:
+ firstline = next(jobs)
+ for line in jobs:
+ values = line.split("\t")
+
+ name = values[8].split()[-1]
+ test = tests[name]
+ test["name"] = name
+ test["time"] = values[3]
+
+ exitval = values[6]
+ if int(exitval):
+ # We don't have a more specific message. User should look at stderr.
+ test["failure"] = "TEST FAILURE"
+ else:
+ test["failure"] = False
+
+ for testname in os.listdir(basedir + "/logs/1"):
+ test = tests[testname]
+
+ with open(basedir + "/logs/1/" + testname + "/stdout") as f:
+ test["stdout"] = f.read()
+
+ with open(basedir + "/logs/1/" + testname + "/stderr") as f:
+ test["stderr"] = f.read()
+
+ # The cpp test is special since it doesn't run under parallel so doesn't show
+ # up in the job log.
+ tests["cpp"]["name"] = "cpp"
+
+ with open(basedir + '/logs/1/cpp/build_time', 'r') as f:
+ tests["cpp"]["time"] = f.read().strip()
+ tests["cpp"]["failure"] = False
+
+ ret = tests.values()
+ ret.sort(key=lambda x: x["name"])
+
+ return ret
+
+def genxml(tests):
+ doc, tag, text = Doc().tagtext()
+
+ with tag("testsuites"):
+ with tag("testsuite", name="Protobuf Tests"):
+ for test in tests:
+ with tag("testcase", name=test["name"], classname=test["name"],
+ time=test["time"]):
+ with tag("system-out"):
+ text(test["stdout"])
+ with tag("system-err"):
+ text(test["stderr"])
+ if test["failure"]:
+ with tag("failure"):
+ text(test["failure"])
+
+ return doc.getvalue()
+
+sys.stderr.write("make_test_output.py: writing XML from directory: " +
+ sys.argv[1] + "\n");
+print genxml(readtests(sys.argv[1]))
diff --git a/third_party/protobuf/jenkins/pull_request_in_docker.sh b/third_party/protobuf/jenkins/pull_request_in_docker.sh
new file mode 100755
index 0000000000..10daf0a593
--- /dev/null
+++ b/third_party/protobuf/jenkins/pull_request_in_docker.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+#
+# This is the script that runs inside Docker, once the image has been built,
+# to execute all tests for the "pull request" project.
+
+WORKSPACE_BASE=`pwd`
+MY_DIR="$(dirname "$0")"
+TEST_SCRIPT=$MY_DIR/../tests.sh
+BUILD_DIR=/tmp/protobuf
+
+set -e # exit immediately on error
+set -x # display all commands
+
+# The protobuf repository is mounted into our Docker image, but read-only.
+# We clone into a directory inside Docker (this is faster than cp).
+rm -rf $BUILD_DIR
+mkdir -p $BUILD_DIR
+cd $BUILD_DIR
+git clone /var/local/jenkins/protobuf
+cd protobuf
+
+# Set up the directory where our test output is going to go.
+OUTPUT_DIR=`mktemp -d`
+LOG_OUTPUT_DIR=$OUTPUT_DIR/logs
+mkdir -p $LOG_OUTPUT_DIR/1/cpp
+
+################################################################################
+# cpp build needs to run first, non-parallelized, so that protoc is available
+# for other builds.
+
+# Output filenames to follow the overall scheme used by parallel, ie:
+# $DIR/logs/1/cpp/stdout
+# $DIR/logs/1/cpp/stderr
+# $DIR/logs/1/csharp/stdout
+# $DIR/logs/1/csharp/stderr
+# $DIR/logs/1/java_jdk7/stdout
+# $DIR/logs/1/java_jdk7/stderr
+CPP_STDOUT=$LOG_OUTPUT_DIR/1/cpp/stdout
+CPP_STDERR=$LOG_OUTPUT_DIR/1/cpp/stderr
+
+# Time the C++ build, so we can put this info in the test output.
+# It's important that we get /usr/bin/time (which supports -f and -o) and not
+# the bash builtin "time" which doesn't.
+TIME_CMD="/usr/bin/time -f %e -o $LOG_OUTPUT_DIR/1/cpp/build_time"
+
+$TIME_CMD $TEST_SCRIPT cpp > >(tee $CPP_STDOUT) 2> >(tee $CPP_STDERR >&2)
+
+# Other tests are run in parallel. TEST_SET is defined in
+# buildcmds/pull_request{_32}.sh
+
+parallel --results $LOG_OUTPUT_DIR --joblog $OUTPUT_DIR/joblog $TEST_SCRIPT ::: \
+ $TEST_SET \
+ || true # Process test results even if tests fail.
+
+cat $OUTPUT_DIR/joblog
+
+# The directory that is copied from Docker back into the Jenkins workspace.
+COPY_FROM_DOCKER=/var/local/git/protobuf/testoutput
+mkdir -p $COPY_FROM_DOCKER
+TESTOUTPUT_XML_FILE=$COPY_FROM_DOCKER/testresults.xml
+
+# Process all the output files from "parallel" and package them into a single
+# .xml file with detailed, broken-down test output.
+python $MY_DIR/make_test_output.py $OUTPUT_DIR > $TESTOUTPUT_XML_FILE
+
+ls -l $TESTOUTPUT_XML_FILE
diff --git a/third_party/protobuf/js/README.md b/third_party/protobuf/js/README.md
new file mode 100644
index 0000000000..f4184621c2
--- /dev/null
+++ b/third_party/protobuf/js/README.md
@@ -0,0 +1,158 @@
+Protocol Buffers - Google's data interchange format
+===================================================
+
+[![Build Status](https://travis-ci.org/google/protobuf.svg?branch=master)](https://travis-ci.org/google/protobuf)
+
+Copyright 2008 Google Inc.
+
+This directory contains the JavaScript Protocol Buffers runtime library.
+
+The library is currently compatible with:
+
+1. CommonJS-style imports (eg. `var protos = require('my-protos');`)
+2. Closure-style imports (eg. `goog.require('my.package.MyProto');`)
+
+Support for ES6-style imports is not implemented yet. Browsers can
+be supported by using Browserify, webpack, Closure Compiler, etc. to
+resolve imports at compile time.
+
+To use Protocol Buffers with JavaScript, you need two main components:
+
+1. The protobuf runtime library. You can install this with
+ `npm install google-protobuf`, or use the files in this directory.
+2. The Protocol Compiler `protoc`. This translates `.proto` files
+ into `.js` files. The compiler is not currently available via
+ npm, but you can download a pre-built binary
+ [on GitHub](https://github.com/google/protobuf/releases)
+ (look for the `protoc-*.zip` files under **Downloads**).
+
+
+Setup
+=====
+
+First, obtain the Protocol Compiler. The easiest way is to download
+a pre-built binary from [https://github.com/google/protobuf/releases](https://github.com/google/protobuf/releases).
+
+If you want, you can compile `protoc` from source instead. To do this
+follow the instructions in [the top-level
+README](https://github.com/google/protobuf/blob/master/src/README.md).
+
+Once you have `protoc` compiled, you can run the tests by typing:
+
+ $ cd js
+ $ npm install
+ $ npm test
+
+ # If your protoc is somewhere else than ../src/protoc, instead do this.
+ # But make sure your protoc is the same version as this (or compatible)!
+ $ PROTOC=/usr/local/bin/protoc npm test
+
+This will run two separate copies of the tests: one that uses
+Closure Compiler style imports and one that uses CommonJS imports.
+You can see all the CommonJS files in `commonjs_out/`.
+If all of these tests pass, you know you have a working setup.
+
+
+Using Protocol Buffers in your own project
+==========================================
+
+To use Protocol Buffers in your own project, you need to integrate
+the Protocol Compiler into your build system. The details are a
+little different depending on whether you are using Closure imports
+or CommonJS imports:
+
+Closure Imports
+---------------
+
+If you want to use Closure imports, your build should run a command
+like this:
+
+ $ protoc --js_out=library=myproto_libs,binary:. messages.proto base.proto
+
+For Closure imports, `protoc` will generate a single output file
+(`myproto_libs.js` in this example). The generated file will `goog.provide()`
+all of the types defined in your .proto files. For example, for the unit
+tests the generated files contain many `goog.provide` statements like:
+
+ goog.provide('proto.google.protobuf.DescriptorProto');
+ goog.provide('proto.google.protobuf.DescriptorProto.ExtensionRange');
+ goog.provide('proto.google.protobuf.DescriptorProto.ReservedRange');
+ goog.provide('proto.google.protobuf.EnumDescriptorProto');
+ goog.provide('proto.google.protobuf.EnumOptions');
+
+The generated code will also `goog.require()` many types in the core library,
+and they will require many types in the Google Closure library. So make sure
+that your `goog.provide()` / `goog.require()` setup can find all of your
+generated code, the core library `.js` files in this directory, and the
+Google Closure library itself.
+
+Once you've done this, you should be able to import your types with
+statements like:
+
+ goog.require('proto.my.package.MyMessage');
+
+ var message = proto.my.package.MyMessage();
+
+CommonJS imports
+----------------
+
+If you want to use CommonJS imports, your build should run a command
+like this:
+
+ $ protoc --js_out=import_style=commonjs,binary:. messages.proto base.proto
+
+For CommonJS imports, `protoc` will spit out one file per input file
+(so `messages_pb.js` and `base_pb.js` in this example). The generated
+code will depend on the core runtime, which should be in a file called
+`google-protobuf.js`. If you are installing from `npm`, this file should
+already be built and available. If you are running from GitHub, you need
+to build it first by running:
+
+ $ gulp dist
+
+Once you've done this, you should be able to import your types with
+statements like:
+
+ var messages = require('./messages_pb');
+
+ var message = new messages.MyMessage();
+
+The `--js_out` flag
+-------------------
+
+The syntax of the `--js_out` flag is:
+
+ --js_out=[OPTIONS:]output_dir
+
+Where `OPTIONS` are separated by commas. Options are either `opt=val` or
+just `opt` (for options that don't take a value). The available options
+are specified and documented in the `GeneratorOptions` struct in
+[src/google/protobuf/compiler/js/js_generator.h](https://github.com/google/protobuf/blob/master/src/google/protobuf/compiler/js/js_generator.h#L53).
+
+Some examples:
+
+- `--js_out=library=myprotos_lib.js,binary:.`: this contains the options
+ `library=myprotos.lib.js` and `binary` and outputs to the current directory.
+ The `import_style` option is left to the default, which is `closure`.
+- `--js_out=import_style=commonjs,binary:protos`: this contains the options
+ `import_style=commonjs` and `binary` and outputs to the directory `protos`.
+
+API
+===
+
+The API is not well-documented yet. Here is a quick example to give you an
+idea of how the library generally works:
+
+ var message = new MyMessage();
+
+ message.setName("John Doe");
+ message.setAge(25);
+ message.setPhoneNumbers(["800-555-1212", "800-555-0000"]);
+
+ // Serializes to a UInt8Array.
+ bytes = message.serializeBinary();
+
+ var message2 = MyMessage.deserializeBinary(bytes);
+
+For more examples, see the tests. You can also look at the generated code
+to see what methods are defined for your generated messages.
diff --git a/third_party/protobuf/js/binary/arith.js b/third_party/protobuf/js/binary/arith.js
new file mode 100644
index 0000000000..70257de716
--- /dev/null
+++ b/third_party/protobuf/js/binary/arith.js
@@ -0,0 +1,413 @@
+// 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.
+
+/**
+ * @fileoverview This file contains helper code used by jspb.utils to
+ * handle 64-bit integer conversion to/from strings.
+ *
+ * @author cfallin@google.com (Chris Fallin)
+ *
+ * TODO(haberman): move this to javascript/closure/math?
+ */
+
+goog.provide('jspb.arith.Int64');
+goog.provide('jspb.arith.UInt64');
+
+/**
+ * UInt64 implements some 64-bit arithmetic routines necessary for properly
+ * handling 64-bit integer fields. It implements lossless integer arithmetic on
+ * top of JavaScript's number type, which has only 53 bits of precision, by
+ * representing 64-bit integers as two 32-bit halves.
+ *
+ * @param {number} lo The low 32 bits.
+ * @param {number} hi The high 32 bits.
+ * @constructor
+ */
+jspb.arith.UInt64 = function(lo, hi) {
+ /**
+ * The low 32 bits.
+ * @public {number}
+ */
+ this.lo = lo;
+ /**
+ * The high 32 bits.
+ * @public {number}
+ */
+ this.hi = hi;
+};
+
+
+/**
+ * Compare two 64-bit numbers. Returns -1 if the first is
+ * less, +1 if the first is greater, or 0 if both are equal.
+ * @param {!jspb.arith.UInt64} other
+ * @return {number}
+ */
+jspb.arith.UInt64.prototype.cmp = function(other) {
+ if (this.hi < other.hi || (this.hi == other.hi && this.lo < other.lo)) {
+ return -1;
+ } else if (this.hi == other.hi && this.lo == other.lo) {
+ return 0;
+ } else {
+ return 1;
+ }
+};
+
+
+/**
+ * Right-shift this number by one bit.
+ * @return {!jspb.arith.UInt64}
+ */
+jspb.arith.UInt64.prototype.rightShift = function() {
+ var hi = this.hi >>> 1;
+ var lo = (this.lo >>> 1) | ((this.hi & 1) << 31);
+ return new jspb.arith.UInt64(lo >>> 0, hi >>> 0);
+};
+
+
+/**
+ * Left-shift this number by one bit.
+ * @return {!jspb.arith.UInt64}
+ */
+jspb.arith.UInt64.prototype.leftShift = function() {
+ var lo = this.lo << 1;
+ var hi = (this.hi << 1) | (this.lo >>> 31);
+ return new jspb.arith.UInt64(lo >>> 0, hi >>> 0);
+};
+
+
+/**
+ * Test the MSB.
+ * @return {boolean}
+ */
+jspb.arith.UInt64.prototype.msb = function() {
+ return !!(this.hi & 0x80000000);
+};
+
+
+/**
+ * Test the LSB.
+ * @return {boolean}
+ */
+jspb.arith.UInt64.prototype.lsb = function() {
+ return !!(this.lo & 1);
+};
+
+
+/**
+ * Test whether this number is zero.
+ * @return {boolean}
+ */
+jspb.arith.UInt64.prototype.zero = function() {
+ return this.lo == 0 && this.hi == 0;
+};
+
+
+/**
+ * Add two 64-bit numbers to produce a 64-bit number.
+ * @param {!jspb.arith.UInt64} other
+ * @return {!jspb.arith.UInt64}
+ */
+jspb.arith.UInt64.prototype.add = function(other) {
+ var lo = ((this.lo + other.lo) & 0xffffffff) >>> 0;
+ var hi =
+ (((this.hi + other.hi) & 0xffffffff) >>> 0) +
+ (((this.lo + other.lo) >= 0x100000000) ? 1 : 0);
+ return new jspb.arith.UInt64(lo >>> 0, hi >>> 0);
+};
+
+
+/**
+ * Subtract two 64-bit numbers to produce a 64-bit number.
+ * @param {!jspb.arith.UInt64} other
+ * @return {!jspb.arith.UInt64}
+ */
+jspb.arith.UInt64.prototype.sub = function(other) {
+ var lo = ((this.lo - other.lo) & 0xffffffff) >>> 0;
+ var hi =
+ (((this.hi - other.hi) & 0xffffffff) >>> 0) -
+ (((this.lo - other.lo) < 0) ? 1 : 0);
+ return new jspb.arith.UInt64(lo >>> 0, hi >>> 0);
+};
+
+
+/**
+ * Multiply two 32-bit numbers to produce a 64-bit number.
+ * @param {number} a The first integer: must be in [0, 2^32-1).
+ * @param {number} b The second integer: must be in [0, 2^32-1).
+ * @return {!jspb.arith.UInt64}
+ */
+jspb.arith.UInt64.mul32x32 = function(a, b) {
+ // Directly multiplying two 32-bit numbers may produce up to 64 bits of
+ // precision, thus losing precision because of the 53-bit mantissa of
+ // JavaScript numbers. So we multiply with 16-bit digits (radix 65536)
+ // instead.
+ var aLow = (a & 0xffff);
+ var aHigh = (a >>> 16);
+ var bLow = (b & 0xffff);
+ var bHigh = (b >>> 16);
+ var productLow =
+ // 32-bit result, result bits 0-31, take all 32 bits
+ (aLow * bLow) +
+ // 32-bit result, result bits 16-47, take bottom 16 as our top 16
+ ((aLow * bHigh) & 0xffff) * 0x10000 +
+ // 32-bit result, result bits 16-47, take bottom 16 as our top 16
+ ((aHigh * bLow) & 0xffff) * 0x10000;
+ var productHigh =
+ // 32-bit result, result bits 32-63, take all 32 bits
+ (aHigh * bHigh) +
+ // 32-bit result, result bits 16-47, take top 16 as our bottom 16
+ ((aLow * bHigh) >>> 16) +
+ // 32-bit result, result bits 16-47, take top 16 as our bottom 16
+ ((aHigh * bLow) >>> 16);
+
+ // Carry. Note that we actually have up to *two* carries due to addition of
+ // three terms.
+ while (productLow >= 0x100000000) {
+ productLow -= 0x100000000;
+ productHigh += 1;
+ }
+
+ return new jspb.arith.UInt64(productLow >>> 0, productHigh >>> 0);
+};
+
+
+/**
+ * Multiply this number by a 32-bit number, producing a 96-bit number, then
+ * truncate the top 32 bits.
+ * @param {number} a The multiplier.
+ * @return {!jspb.arith.UInt64}
+ */
+jspb.arith.UInt64.prototype.mul = function(a) {
+ // Produce two parts: at bits 0-63, and 32-95.
+ var lo = jspb.arith.UInt64.mul32x32(this.lo, a);
+ var hi = jspb.arith.UInt64.mul32x32(this.hi, a);
+ // Left-shift hi by 32 bits, truncating its top bits. The parts will then be
+ // aligned for addition.
+ hi.hi = hi.lo;
+ hi.lo = 0;
+ return lo.add(hi);
+};
+
+
+/**
+ * Divide a 64-bit number by a 32-bit number to produce a
+ * 64-bit quotient and a 32-bit remainder.
+ * @param {number} _divisor
+ * @return {Array.<jspb.arith.UInt64>} array of [quotient, remainder],
+ * unless divisor is 0, in which case an empty array is returned.
+ */
+jspb.arith.UInt64.prototype.div = function(_divisor) {
+ if (_divisor == 0) {
+ return [];
+ }
+
+ // We perform long division using a radix-2 algorithm, for simplicity (i.e.,
+ // one bit at a time). TODO: optimize to a radix-2^32 algorithm, taking care
+ // to get the variable shifts right.
+ var quotient = new jspb.arith.UInt64(0, 0);
+ var remainder = new jspb.arith.UInt64(this.lo, this.hi);
+ var divisor = new jspb.arith.UInt64(_divisor, 0);
+ var unit = new jspb.arith.UInt64(1, 0);
+
+ // Left-shift the divisor and unit until the high bit of divisor is set.
+ while (!divisor.msb()) {
+ divisor = divisor.leftShift();
+ unit = unit.leftShift();
+ }
+
+ // Perform long division one bit at a time.
+ while (!unit.zero()) {
+ // If divisor < remainder, add unit to quotient and subtract divisor from
+ // remainder.
+ if (divisor.cmp(remainder) <= 0) {
+ quotient = quotient.add(unit);
+ remainder = remainder.sub(divisor);
+ }
+ // Right-shift the divisor and unit.
+ divisor = divisor.rightShift();
+ unit = unit.rightShift();
+ }
+
+ return [quotient, remainder];
+};
+
+
+/**
+ * Convert a 64-bit number to a string.
+ * @return {string}
+ * @override
+ */
+jspb.arith.UInt64.prototype.toString = function() {
+ var result = '';
+ var num = this;
+ while (!num.zero()) {
+ var divResult = num.div(10);
+ var quotient = divResult[0], remainder = divResult[1];
+ result = remainder.lo + result;
+ num = quotient;
+ }
+ if (result == '') {
+ result = '0';
+ }
+ return result;
+};
+
+
+/**
+ * Parse a string into a 64-bit number. Returns `null` on a parse error.
+ * @param {string} s
+ * @return {?jspb.arith.UInt64}
+ */
+jspb.arith.UInt64.fromString = function(s) {
+ var result = new jspb.arith.UInt64(0, 0);
+ // optimization: reuse this instance for each digit.
+ var digit64 = new jspb.arith.UInt64(0, 0);
+ for (var i = 0; i < s.length; i++) {
+ if (s[i] < '0' || s[i] > '9') {
+ return null;
+ }
+ var digit = parseInt(s[i], 10);
+ digit64.lo = digit;
+ result = result.mul(10).add(digit64);
+ }
+ return result;
+};
+
+
+/**
+ * Make a copy of the uint64.
+ * @return {!jspb.arith.UInt64}
+ */
+jspb.arith.UInt64.prototype.clone = function() {
+ return new jspb.arith.UInt64(this.lo, this.hi);
+};
+
+
+/**
+ * Int64 is like UInt64, but modifies string conversions to interpret the stored
+ * 64-bit value as a twos-complement-signed integer. It does *not* support the
+ * full range of operations that UInt64 does: only add, subtract, and string
+ * conversions.
+ *
+ * N.B. that multiply and divide routines are *NOT* supported. They will throw
+ * exceptions. (They are not necessary to implement string conversions, which
+ * are the only operations we really need in jspb.)
+ *
+ * @param {number} lo The low 32 bits.
+ * @param {number} hi The high 32 bits.
+ * @constructor
+ */
+jspb.arith.Int64 = function(lo, hi) {
+ /**
+ * The low 32 bits.
+ * @public {number}
+ */
+ this.lo = lo;
+ /**
+ * The high 32 bits.
+ * @public {number}
+ */
+ this.hi = hi;
+};
+
+
+/**
+ * Add two 64-bit numbers to produce a 64-bit number.
+ * @param {!jspb.arith.Int64} other
+ * @return {!jspb.arith.Int64}
+ */
+jspb.arith.Int64.prototype.add = function(other) {
+ var lo = ((this.lo + other.lo) & 0xffffffff) >>> 0;
+ var hi =
+ (((this.hi + other.hi) & 0xffffffff) >>> 0) +
+ (((this.lo + other.lo) >= 0x100000000) ? 1 : 0);
+ return new jspb.arith.Int64(lo >>> 0, hi >>> 0);
+};
+
+
+/**
+ * Subtract two 64-bit numbers to produce a 64-bit number.
+ * @param {!jspb.arith.Int64} other
+ * @return {!jspb.arith.Int64}
+ */
+jspb.arith.Int64.prototype.sub = function(other) {
+ var lo = ((this.lo - other.lo) & 0xffffffff) >>> 0;
+ var hi =
+ (((this.hi - other.hi) & 0xffffffff) >>> 0) -
+ (((this.lo - other.lo) < 0) ? 1 : 0);
+ return new jspb.arith.Int64(lo >>> 0, hi >>> 0);
+};
+
+
+/**
+ * Make a copy of the int64.
+ * @return {!jspb.arith.Int64}
+ */
+jspb.arith.Int64.prototype.clone = function() {
+ return new jspb.arith.Int64(this.lo, this.hi);
+};
+
+
+/**
+ * Convert a 64-bit number to a string.
+ * @return {string}
+ * @override
+ */
+jspb.arith.Int64.prototype.toString = function() {
+ // If the number is negative, find its twos-complement inverse.
+ var sign = (this.hi & 0x80000000) != 0;
+ var num = new jspb.arith.UInt64(this.lo, this.hi);
+ if (sign) {
+ num = new jspb.arith.UInt64(0, 0).sub(num);
+ }
+ return (sign ? '-' : '') + num.toString();
+};
+
+
+/**
+ * Parse a string into a 64-bit number. Returns `null` on a parse error.
+ * @param {string} s
+ * @return {?jspb.arith.Int64}
+ */
+jspb.arith.Int64.fromString = function(s) {
+ var hasNegative = (s.length > 0 && s[0] == '-');
+ if (hasNegative) {
+ s = s.substring(1);
+ }
+ var num = jspb.arith.UInt64.fromString(s);
+ if (num === null) {
+ return null;
+ }
+ if (hasNegative) {
+ num = new jspb.arith.UInt64(0, 0).sub(num);
+ }
+ return new jspb.arith.Int64(num.lo, num.hi);
+};
diff --git a/third_party/protobuf/js/binary/arith_test.js b/third_party/protobuf/js/binary/arith_test.js
new file mode 100644
index 0000000000..89796bf795
--- /dev/null
+++ b/third_party/protobuf/js/binary/arith_test.js
@@ -0,0 +1,355 @@
+// 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.
+
+/**
+ * @fileoverview Test cases for Int64-manipulation functions.
+ *
+ * Test suite is written using Jasmine -- see http://jasmine.github.io/
+ *
+ * @author cfallin@google.com (Chris Fallin)
+ */
+
+goog.require('goog.testing.asserts');
+goog.require('jspb.arith.Int64');
+goog.require('jspb.arith.UInt64');
+
+
+describe('binaryArithTest', function() {
+ /**
+ * Tests comparison operations.
+ */
+ it('testCompare', function() {
+ var a = new jspb.arith.UInt64(1234, 5678);
+ var b = new jspb.arith.UInt64(1234, 5678);
+ assertEquals(a.cmp(b), 0);
+ assertEquals(b.cmp(a), 0);
+ b.lo -= 1;
+ assertEquals(a.cmp(b), 1);
+ assertEquals(b.cmp(a), -1);
+ b.lo += 2;
+ assertEquals(a.cmp(b), -1);
+ assertEquals(b.cmp(a), 1);
+ b.lo = a.lo;
+ b.hi = a.hi - 1;
+ assertEquals(a.cmp(b), 1);
+ assertEquals(b.cmp(a), -1);
+
+ assertEquals(a.zero(), false);
+ assertEquals(a.msb(), false);
+ assertEquals(a.lsb(), false);
+ a.hi = 0;
+ a.lo = 0;
+ assertEquals(a.zero(), true);
+ a.hi = 0x80000000;
+ assertEquals(a.zero(), false);
+ assertEquals(a.msb(), true);
+ a.lo = 0x00000001;
+ assertEquals(a.lsb(), true);
+ });
+
+
+ /**
+ * Tests shifts.
+ */
+ it('testShifts', function() {
+ var a = new jspb.arith.UInt64(1, 0);
+ assertEquals(a.lo, 1);
+ assertEquals(a.hi, 0);
+ var orig = a;
+ a = a.leftShift();
+ assertEquals(orig.lo, 1); // original unmodified.
+ assertEquals(orig.hi, 0);
+ assertEquals(a.lo, 2);
+ assertEquals(a.hi, 0);
+ a = a.leftShift();
+ assertEquals(a.lo, 4);
+ assertEquals(a.hi, 0);
+ for (var i = 0; i < 29; i++) {
+ a = a.leftShift();
+ }
+ assertEquals(a.lo, 0x80000000);
+ assertEquals(a.hi, 0);
+ a = a.leftShift();
+ assertEquals(a.lo, 0);
+ assertEquals(a.hi, 1);
+ a = a.leftShift();
+ assertEquals(a.lo, 0);
+ assertEquals(a.hi, 2);
+ a = a.rightShift();
+ a = a.rightShift();
+ assertEquals(a.lo, 0x80000000);
+ assertEquals(a.hi, 0);
+ a = a.rightShift();
+ assertEquals(a.lo, 0x40000000);
+ assertEquals(a.hi, 0);
+ });
+
+
+ /**
+ * Tests additions.
+ */
+ it('testAdd', function() {
+ var a = new jspb.arith.UInt64(/* lo = */ 0x89abcdef,
+ /* hi = */ 0x01234567);
+ var b = new jspb.arith.UInt64(/* lo = */ 0xff52ab91,
+ /* hi = */ 0x92fa2123);
+ // Addition with carry.
+ var c = a.add(b);
+ assertEquals(a.lo, 0x89abcdef); // originals unmodified.
+ assertEquals(a.hi, 0x01234567);
+ assertEquals(b.lo, 0xff52ab91);
+ assertEquals(b.hi, 0x92fa2123);
+ assertEquals(c.lo, 0x88fe7980);
+ assertEquals(c.hi, 0x941d668b);
+
+ // Simple addition without carry.
+ a.lo = 2;
+ a.hi = 0;
+ b.lo = 3;
+ b.hi = 0;
+ c = a.add(b);
+ assertEquals(c.lo, 5);
+ assertEquals(c.hi, 0);
+ });
+
+
+ /**
+ * Test subtractions.
+ */
+ it('testSub', function() {
+ var kLength = 10;
+ var hiValues = [0x1682ef32,
+ 0x583902f7,
+ 0xb62f5955,
+ 0x6ea99bbf,
+ 0x25a39c20,
+ 0x0700a08b,
+ 0x00f7304d,
+ 0x91a5b5af,
+ 0x89077fd2,
+ 0xe09e347c];
+ var loValues = [0xe1538b18,
+ 0xbeacd556,
+ 0x74100758,
+ 0x96e3cb26,
+ 0x56c37c3f,
+ 0xe00b3f7d,
+ 0x859f25d7,
+ 0xc2ee614a,
+ 0xe1d21cd7,
+ 0x30aae6a4];
+ for (var i = 0; i < kLength; i++) {
+ for (var j = 0; j < kLength; j++) {
+ var a = new jspb.arith.UInt64(loValues[i], hiValues[j]);
+ var b = new jspb.arith.UInt64(loValues[j], hiValues[i]);
+ var c = a.add(b).sub(b);
+ assertEquals(c.hi, a.hi);
+ assertEquals(c.lo, a.lo);
+ }
+ }
+ });
+
+
+ /**
+ * Tests 32-by-32 multiplication.
+ */
+ it('testMul32x32', function() {
+ var testData = [
+ // a b low(a*b) high(a*b)
+ [0xc0abe2f8, 0x1607898a, 0x5de711b0, 0x109471b8],
+ [0x915eb3cb, 0x4fb66d0e, 0xbd0d441a, 0x2d43d0bc],
+ [0xfe4efe70, 0x80b48c37, 0xbcddea10, 0x7fdada0c],
+ [0xe222fd4a, 0xe43d524a, 0xd5e0eb64, 0xc99d549c],
+ [0xd171f469, 0xb94ebd01, 0x4be17969, 0x979bc4fa],
+ [0x829cc1df, 0xe2598b38, 0xf4157dc8, 0x737c12ad],
+ [0xf10c3767, 0x8382881e, 0x942b3612, 0x7bd428b8],
+ [0xb0f6dd24, 0x232597e1, 0x079c98a4, 0x184bbce7],
+ [0xfcdb05a7, 0x902f55bc, 0x636199a4, 0x8e69f412],
+ [0x0dd0bfa9, 0x916e27b1, 0x6e2542d9, 0x07d92e65]
+ ];
+
+ for (var i = 0; i < testData.length; i++) {
+ var a = testData[i][0] >>> 0;
+ var b = testData[i][1] >>> 0;
+ var cLow = testData[i][2] >>> 0;
+ var cHigh = testData[i][3] >>> 0;
+ var c = jspb.arith.UInt64.mul32x32(a, b);
+ assertEquals(c.lo, cLow);
+ assertEquals(c.hi, cHigh);
+ }
+ });
+
+
+ /**
+ * Tests 64-by-32 multiplication.
+ */
+ it('testMul', function() {
+ // 64x32 bits produces 96 bits of product. The multiplication function under
+ // test truncates the top 32 bits, so we compare against a 64-bit expected
+ // product.
+ var testData = [
+ // low(a) high(a) low(a*b) high(a*b)
+ [0xec10955b, 0x360eb168, 0x4b7f3f5b, 0xbfcb7c59, 0x9517da5f],
+ [0x42b000fc, 0x9d101642, 0x6fa1ab72, 0x2584c438, 0x6a9e6d2b],
+ [0xf42d4fb4, 0xae366403, 0xa65a1000, 0x92434000, 0x1ff978df],
+ [0x17e2f56b, 0x25487693, 0xf13f98c7, 0x73794e2d, 0xa96b0c6a],
+ [0x492f241f, 0x76c0eb67, 0x7377ac44, 0xd4336c3c, 0xfc4b1ebe],
+ [0xd6b92321, 0xe184fa48, 0xd6e76904, 0x93141584, 0xcbf44da1],
+ [0x4bf007ea, 0x968c0a9e, 0xf5e4026a, 0x4fdb1ae4, 0x61b9fb7d],
+ [0x10a83be7, 0x2d685ba6, 0xc9e5fb7f, 0x2ad43499, 0x3742473d],
+ [0x2f261829, 0x1aca681a, 0x3d3494e3, 0x8213205b, 0x283719f8],
+ [0xe4f2ce21, 0x2e74b7bd, 0xd801b38b, 0xbc17feeb, 0xc6c44e0f]
+ ];
+
+ for (var i = 0; i < testData.length; i++) {
+ var a = new jspb.arith.UInt64(testData[i][0], testData[i][1]);
+ var prod = a.mul(testData[i][2]);
+ assertEquals(prod.lo, testData[i][3]);
+ assertEquals(prod.hi, testData[i][4]);
+ }
+ });
+
+
+ /**
+ * Tests 64-div-by-32 division.
+ */
+ it('testDiv', function() {
+ // Compute a/b, yielding quot = a/b and rem = a%b.
+ var testData = [
+ // --- divisors in (0, 2^32-1) to test full divisor range
+ // low(a) high(a) b low(quot) high(quot) rem
+ [0x712443f1, 0xe85cefcc, 0xc1a7050b, 0x332c79ad, 0x00000001, 0x92ffa882],
+ [0x11912915, 0xb2699eb5, 0x30467cbe, 0xb21b4be4, 0x00000003, 0x283465dd],
+ [0x0d917982, 0x201f2a6e, 0x3f35bf03, 0x8217c8e4, 0x00000000, 0x153402d6],
+ [0xa072c108, 0x74020c96, 0xc60568fd, 0x95f9613e, 0x00000000, 0x3f4676c2],
+ [0xd845d5d8, 0xcdd235c4, 0x20426475, 0x6154e78b, 0x00000006, 0x202fb751],
+ [0xa4dbf71f, 0x9e90465e, 0xf08e022f, 0xa8be947f, 0x00000000, 0xbe43b5ce],
+ [0x3dbe627f, 0xa791f4b9, 0x28a5bd89, 0x1f5dfe93, 0x00000004, 0x02bf9ed4],
+ [0x5c1c53ee, 0xccf5102e, 0x198576e7, 0x07e3ae31, 0x00000008, 0x02ea8fb7],
+ [0xfef1e581, 0x04714067, 0xca6540c1, 0x059e73ec, 0x00000000, 0x31658095],
+ [0x1e2dd90c, 0x13dd6667, 0x8b2184c3, 0x248d1a42, 0x00000000, 0x4ca6d0c6],
+ // --- divisors in (0, 2^16-1) to test larger quotient high-words
+ // low(a) high(a) b low(quot) high(quot) rem
+ [0x86722b47, 0x2cd57c9a, 0x00003123, 0x2ae41b7a, 0x0000e995, 0x00000f99],
+ [0x1dd7884c, 0xf5e839bc, 0x00009eeb, 0x5c886242, 0x00018c21, 0x000099b6],
+ [0x5c53d625, 0x899fc7e5, 0x000087d7, 0xd625007a, 0x0001035c, 0x000019af],
+ [0x6932d932, 0x9d0a5488, 0x000051fb, 0x9d976143, 0x0001ea63, 0x00004981],
+ [0x4d18bb85, 0x0c92fb31, 0x00001d9f, 0x03265ab4, 0x00006cac, 0x000001b9],
+ [0xbe756768, 0xdea67ccb, 0x00008a03, 0x58add442, 0x00019cff, 0x000056a2],
+ [0xe2466f9a, 0x2521f114, 0x0000c350, 0xa0c0860d, 0x000030ab, 0x0000a48a],
+ [0xf00ddad1, 0xe2f5446a, 0x00002cfc, 0x762697a6, 0x00050b96, 0x00000b69],
+ [0xa879152a, 0x0a70e0a5, 0x00007cdf, 0xb44151b3, 0x00001567, 0x0000363d],
+ [0x7179a74c, 0x46083fff, 0x0000253c, 0x4d39ba6e, 0x0001e17f, 0x00000f84]
+ ];
+
+ for (var i = 0; i < testData.length; i++) {
+ var a = new jspb.arith.UInt64(testData[i][0], testData[i][1]);
+ var result = a.div(testData[i][2]);
+ var quotient = result[0];
+ var remainder = result[1];
+ assertEquals(quotient.lo, testData[i][3]);
+ assertEquals(quotient.hi, testData[i][4]);
+ assertEquals(remainder.lo, testData[i][5]);
+ }
+ });
+
+
+ /**
+ * Tests .toString() and .fromString().
+ */
+ it('testStrings', function() {
+ var testData = [
+ [0x5e84c935, 0xcae33d0e, '14619595947299359029'],
+ [0x62b3b8b8, 0x93480544, '10612738313170434232'],
+ [0x319bfb13, 0xc01c4172, '13843011313344445203'],
+ [0x5b8a65fb, 0xa5885b31, '11927883880638080507'],
+ [0x6bdb80f1, 0xb0d1b16b, '12741159895737008369'],
+ [0x4b82b442, 0x2e0d8c97, '3318463081876730946'],
+ [0x780d5208, 0x7d76752c, '9040542135845999112'],
+ [0x2e46800f, 0x0993778d, '690026616168284175'],
+ [0xf00a7e32, 0xcd8e3931, '14811839111111540274'],
+ [0x1baeccd6, 0x923048c4, '10533999535534820566'],
+ [0x03669d29, 0xbff3ab72, '13831587386756603177'],
+ [0x2526073e, 0x01affc81, '121593346566522686'],
+ [0xc24244e0, 0xd7f40d0e, '15561076969511732448'],
+ [0xc56a341e, 0xa68b66a7, '12000798502816461854'],
+ [0x8738d64d, 0xbfe78604, '13828168534871037517'],
+ [0x5baff03b, 0xd7572aea, '15516918227177304123'],
+ [0x4a843d8a, 0x864e132b, '9677693725920476554'],
+ [0x25b4e94d, 0x22b54dc6, '2500990681505655117'],
+ [0x6bbe664b, 0x55a5cc0e, '6171563226690381387'],
+ [0xee916c81, 0xb00aabb3, '12685140089732426881']
+ ];
+
+ for (var i = 0; i < testData.length; i++) {
+ var a = new jspb.arith.UInt64(testData[i][0], testData[i][1]);
+ var roundtrip = jspb.arith.UInt64.fromString(a.toString());
+ assertEquals(roundtrip.lo, a.lo);
+ assertEquals(roundtrip.hi, a.hi);
+ assertEquals(a.toString(), testData[i][2]);
+ }
+ });
+
+
+ /**
+ * Tests signed Int64s. These are built on UInt64s, so we only need to test
+ * the explicit overrides: .toString() and .fromString().
+ */
+ it('testSignedInt64', function() {
+ var testStrings = [
+ '-7847499644178593666',
+ '3771946501229139523',
+ '2872856549054995060',
+ '-5780049594274350904',
+ '3383785956695105201',
+ '2973055184857072610',
+ '-3879428459215627206',
+ '4589812431064156631',
+ '8484075557333689940',
+ '1075325817098092407',
+ '-4346697501012292314',
+ '2488620459718316637',
+ '6112655187423520672',
+ '-3655278273928612104',
+ '3439154019435803196',
+ '1004112478843763757',
+ '-6587790776614368413',
+ '664320065099714586',
+ '4760412909973292912',
+ '-7911903989602274672'
+ ];
+
+ for (var i = 0; i < testStrings.length; i++) {
+ var roundtrip =
+ jspb.arith.Int64.fromString(testStrings[i]).toString();
+ assertEquals(roundtrip, testStrings[i]);
+ }
+ });
+});
diff --git a/third_party/protobuf/js/binary/constants.js b/third_party/protobuf/js/binary/constants.js
new file mode 100644
index 0000000000..ef5fecddc5
--- /dev/null
+++ b/third_party/protobuf/js/binary/constants.js
@@ -0,0 +1,360 @@
+// 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.
+
+/**
+ * @fileoverview This file contains constants and typedefs used by
+ * jspb.BinaryReader and BinaryWriter.
+ *
+ * @author aappleby@google.com (Austin Appleby)
+ */
+
+goog.provide('jspb.AnyFieldType');
+goog.provide('jspb.BinaryConstants');
+goog.provide('jspb.BinaryMessage');
+goog.provide('jspb.BuilderFunction');
+goog.provide('jspb.ByteSource');
+goog.provide('jspb.ClonerFunction');
+goog.provide('jspb.ComparerFunction');
+goog.provide('jspb.ConstBinaryMessage');
+goog.provide('jspb.PrunerFunction');
+goog.provide('jspb.ReaderFunction');
+goog.provide('jspb.RecyclerFunction');
+goog.provide('jspb.RepeatedFieldType');
+goog.provide('jspb.ScalarFieldType');
+goog.provide('jspb.WriterFunction');
+
+
+goog.forwardDeclare('jspb.Message');
+goog.forwardDeclare('jsproto.BinaryExtension');
+
+
+
+/**
+ * Base interface class for all const messages. Does __not__ define any
+ * methods, as doing so on a widely-used interface defeats dead-code
+ * elimination.
+ * @interface
+ */
+jspb.ConstBinaryMessage = function() {};
+
+
+
+/**
+ * Base interface class for all messages. Does __not__ define any methods, as
+ * doing so on a widely-used interface defeats dead-code elimination.
+ * @interface
+ * @extends {jspb.ConstBinaryMessage}
+ */
+jspb.BinaryMessage = function() {};
+
+
+/**
+ * The types convertible to Uint8Arrays. Strings are assumed to be
+ * base64-encoded.
+ * @typedef {ArrayBuffer|Uint8Array|Array<number>|string}
+ */
+jspb.ByteSource;
+
+
+/**
+ * A scalar field in jspb can be a boolean, number, or string.
+ * @typedef {boolean|number|string}
+ */
+jspb.ScalarFieldType;
+
+
+/**
+ * A repeated field in jspb is an array of scalars, blobs, or messages.
+ * @typedef {!Array<jspb.ScalarFieldType>|
+ !Array<!Uint8Array>|
+ !Array<!jspb.BinaryMessage>}
+ */
+jspb.RepeatedFieldType;
+
+
+/**
+ * A field in jspb can be a scalar, a block of bytes, another proto, or an
+ * array of any of the above.
+ * @typedef {jspb.ScalarFieldType|
+ jspb.RepeatedFieldType|
+ !Uint8Array|
+ !jspb.BinaryMessage|
+ !jsproto.BinaryExtension}
+ */
+jspb.AnyFieldType;
+
+
+/**
+ * A builder function creates an instance of a message object.
+ * @typedef {function():!jspb.BinaryMessage}
+ */
+jspb.BuilderFunction;
+
+
+/**
+ * A cloner function creates a deep copy of a message object.
+ * @typedef {function(jspb.ConstBinaryMessage):jspb.BinaryMessage}
+ */
+jspb.ClonerFunction;
+
+
+/**
+ * A recycler function destroys an instance of a message object.
+ * @typedef {function(!jspb.BinaryMessage):void}
+ */
+jspb.RecyclerFunction;
+
+
+/**
+ * A reader function initializes a message using data from a BinaryReader.
+ * @typedef {function(!jspb.BinaryMessage, !jspb.BinaryReader):void}
+ */
+jspb.ReaderFunction;
+
+
+/**
+ * A writer function serializes a message to a BinaryWriter.
+ * @typedef {function((!jspb.Message|!jspb.ConstBinaryMessage),
+ * !jspb.BinaryWriter):void}
+ */
+jspb.WriterFunction;
+
+
+/**
+ * A pruner function removes default-valued fields and empty submessages from a
+ * message and returns either the pruned message or null if the entire message
+ * was pruned away.
+ * @typedef {function(?jspb.BinaryMessage):?jspb.BinaryMessage}
+ */
+jspb.PrunerFunction;
+
+
+/**
+ * A comparer function returns true if two protos are equal.
+ * @typedef {!function(?jspb.ConstBinaryMessage,
+ * ?jspb.ConstBinaryMessage):boolean}
+ */
+jspb.ComparerFunction;
+
+
+/**
+ * Field type codes, taken from proto2/public/wire_format_lite.h.
+ * @enum {number}
+ */
+jspb.BinaryConstants.FieldType = {
+ INVALID: -1,
+ DOUBLE: 1,
+ FLOAT: 2,
+ INT64: 3,
+ UINT64: 4,
+ INT32: 5,
+ FIXED64: 6,
+ FIXED32: 7,
+ BOOL: 8,
+ STRING: 9,
+ GROUP: 10,
+ MESSAGE: 11,
+ BYTES: 12,
+ UINT32: 13,
+ ENUM: 14,
+ SFIXED32: 15,
+ SFIXED64: 16,
+ SINT32: 17,
+ SINT64: 18,
+
+ // Extended types for Javascript
+
+ FHASH64: 30, // 64-bit hash string, fixed-length encoding.
+ VHASH64: 31 // 64-bit hash string, varint encoding.
+};
+
+
+/**
+ * Wire-format type codes, taken from proto2/public/wire_format_lite.h.
+ * @enum {number}
+ */
+jspb.BinaryConstants.WireType = {
+ INVALID: -1,
+ VARINT: 0,
+ FIXED64: 1,
+ DELIMITED: 2,
+ START_GROUP: 3,
+ END_GROUP: 4,
+ FIXED32: 5
+};
+
+
+/**
+ * Translates field type to wire type.
+ * @param {jspb.BinaryConstants.FieldType} fieldType
+ * @return {jspb.BinaryConstants.WireType}
+ */
+jspb.BinaryConstants.FieldTypeToWireType = function(fieldType) {
+ var fieldTypes = jspb.BinaryConstants.FieldType;
+ var wireTypes = jspb.BinaryConstants.WireType;
+ switch (fieldType) {
+ case fieldTypes.INT32:
+ case fieldTypes.INT64:
+ case fieldTypes.UINT32:
+ case fieldTypes.UINT64:
+ case fieldTypes.SINT32:
+ case fieldTypes.SINT64:
+ case fieldTypes.BOOL:
+ case fieldTypes.ENUM:
+ case fieldTypes.VHASH64:
+ return wireTypes.VARINT;
+
+ case fieldTypes.DOUBLE:
+ case fieldTypes.FIXED64:
+ case fieldTypes.SFIXED64:
+ case fieldTypes.FHASH64:
+ return wireTypes.FIXED64;
+
+ case fieldTypes.STRING:
+ case fieldTypes.MESSAGE:
+ case fieldTypes.BYTES:
+ return wireTypes.DELIMITED;
+
+ case fieldTypes.FLOAT:
+ case fieldTypes.FIXED32:
+ case fieldTypes.SFIXED32:
+ return wireTypes.FIXED32;
+
+ case fieldTypes.INVALID:
+ case fieldTypes.GROUP:
+ default:
+ return wireTypes.INVALID;
+ }
+};
+
+
+/**
+ * Flag to indicate a missing field.
+ * @const {number}
+ */
+jspb.BinaryConstants.INVALID_FIELD_NUMBER = -1;
+
+
+/**
+ * The smallest denormal float32 value.
+ * @const {number}
+ */
+jspb.BinaryConstants.FLOAT32_EPS = 1.401298464324817e-45;
+
+
+/**
+ * The smallest normal float64 value.
+ * @const {number}
+ */
+jspb.BinaryConstants.FLOAT32_MIN = 1.1754943508222875e-38;
+
+
+/**
+ * The largest finite float32 value.
+ * @const {number}
+ */
+jspb.BinaryConstants.FLOAT32_MAX = 3.4028234663852886e+38;
+
+
+/**
+ * The smallest denormal float64 value.
+ * @const {number}
+ */
+jspb.BinaryConstants.FLOAT64_EPS = 5e-324;
+
+
+/**
+ * The smallest normal float64 value.
+ * @const {number}
+ */
+jspb.BinaryConstants.FLOAT64_MIN = 2.2250738585072014e-308;
+
+
+/**
+ * The largest finite float64 value.
+ * @const {number}
+ */
+jspb.BinaryConstants.FLOAT64_MAX = 1.7976931348623157e+308;
+
+
+/**
+ * Convenience constant equal to 2^20.
+ * @const {number}
+ */
+jspb.BinaryConstants.TWO_TO_20 = 1048576;
+
+
+/**
+ * Convenience constant equal to 2^23.
+ * @const {number}
+ */
+jspb.BinaryConstants.TWO_TO_23 = 8388608;
+
+
+/**
+ * Convenience constant equal to 2^31.
+ * @const {number}
+ */
+jspb.BinaryConstants.TWO_TO_31 = 2147483648;
+
+
+/**
+ * Convenience constant equal to 2^32.
+ * @const {number}
+ */
+jspb.BinaryConstants.TWO_TO_32 = 4294967296;
+
+
+/**
+ * Convenience constant equal to 2^52.
+ * @const {number}
+ */
+jspb.BinaryConstants.TWO_TO_52 = 4503599627370496;
+
+
+/**
+ * Convenience constant equal to 2^63.
+ * @const {number}
+ */
+jspb.BinaryConstants.TWO_TO_63 = 9223372036854775808;
+
+
+/**
+ * Convenience constant equal to 2^64.
+ * @const {number}
+ */
+jspb.BinaryConstants.TWO_TO_64 = 18446744073709551616;
+
+
+/**
+ * Eight-character string of zeros, used as the default 64-bit hash value.
+ * @const {string}
+ */
+jspb.BinaryConstants.ZERO_HASH = '\0\0\0\0\0\0\0\0';
diff --git a/third_party/protobuf/js/binary/decoder.js b/third_party/protobuf/js/binary/decoder.js
new file mode 100644
index 0000000000..26bf359459
--- /dev/null
+++ b/third_party/protobuf/js/binary/decoder.js
@@ -0,0 +1,1066 @@
+// 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.
+
+/**
+ * @fileoverview This file contains utilities for decoding primitive values
+ * (signed and unsigned integers, varints, booleans, enums, hashes, strings,
+ * and raw bytes) embedded in Uint8Arrays into their corresponding Javascript
+ * types.
+ *
+ * Major caveat - Javascript is unable to accurately represent integers larger
+ * than 2^53 due to its use of a double-precision floating point format or all
+ * numbers. If you need to guarantee that 64-bit values survive with all bits
+ * intact, you _must_ read them using one of the Hash64 methods, which return
+ * an 8-character string.
+ *
+ * @author aappleby@google.com (Austin Appleby)
+ */
+
+goog.provide('jspb.BinaryDecoder');
+goog.provide('jspb.BinaryIterator');
+
+goog.require('goog.asserts');
+goog.require('jspb.utils');
+
+
+
+/**
+ * Simple helper class for traversing the contents of repeated scalar fields.
+ * that may or may not have been packed into a wire-format blob.
+ * @param {?jspb.BinaryDecoder=} opt_decoder
+ * @param {?function(this:jspb.BinaryDecoder):(number|boolean|string)=}
+ * opt_next The decoder method to use for next().
+ * @param {?Array.<number|boolean|string>=} opt_elements
+ * @constructor
+ * @struct
+ */
+jspb.BinaryIterator = function(opt_decoder, opt_next, opt_elements) {
+ /** @private {jspb.BinaryDecoder} */
+ this.decoder_ = null;
+
+ /**
+ * The BinaryDecoder member function used when iterating over packed data.
+ * @private {?function(this:jspb.BinaryDecoder):(number|boolean|string)}
+ */
+ this.nextMethod_ = null;
+
+ /** @private {Array.<number>} */
+ this.elements_ = null;
+
+ /** @private {number} */
+ this.cursor_ = 0;
+
+ /** @private {number|boolean|string|null} */
+ this.nextValue_ = null;
+
+ /** @private {boolean} */
+ this.atEnd_ = true;
+
+ this.init_(opt_decoder, opt_next, opt_elements);
+};
+
+
+/**
+ * @param {?jspb.BinaryDecoder=} opt_decoder
+ * @param {?function(this:jspb.BinaryDecoder):(number|boolean|string)=}
+ * opt_next The decoder method to use for next().
+ * @param {?Array.<number|boolean|string>=} opt_elements
+ * @private
+ */
+jspb.BinaryIterator.prototype.init_ =
+ function(opt_decoder, opt_next, opt_elements) {
+ if (opt_decoder && opt_next) {
+ this.decoder_ = opt_decoder;
+ this.nextMethod_ = opt_next;
+ }
+ this.elements_ = opt_elements ? opt_elements : null;
+ this.cursor_ = 0;
+ this.nextValue_ = null;
+ this.atEnd_ = !this.decoder_ && !this.elements_;
+
+ this.next();
+};
+
+
+/**
+ * Global pool of BinaryIterator instances.
+ * @private {!Array.<!jspb.BinaryIterator>}
+ */
+jspb.BinaryIterator.instanceCache_ = [];
+
+
+/**
+ * Allocates a BinaryIterator from the cache, creating a new one if the cache
+ * is empty.
+ * @param {?jspb.BinaryDecoder=} opt_decoder
+ * @param {?function(this:jspb.BinaryDecoder):(number|boolean|string)=}
+ * opt_next The decoder method to use for next().
+ * @param {?Array.<number|boolean|string>=} opt_elements
+ * @return {!jspb.BinaryIterator}
+ */
+jspb.BinaryIterator.alloc = function(opt_decoder, opt_next, opt_elements) {
+ if (jspb.BinaryIterator.instanceCache_.length) {
+ var iterator = jspb.BinaryIterator.instanceCache_.pop();
+ iterator.init_(opt_decoder, opt_next, opt_elements);
+ return iterator;
+ } else {
+ return new jspb.BinaryIterator(opt_decoder, opt_next, opt_elements);
+ }
+};
+
+
+/**
+ * Puts this instance back in the instance cache.
+ */
+jspb.BinaryIterator.prototype.free = function() {
+ this.clear();
+ if (jspb.BinaryIterator.instanceCache_.length < 100) {
+ jspb.BinaryIterator.instanceCache_.push(this);
+ }
+};
+
+
+/**
+ * Clears the iterator.
+ */
+jspb.BinaryIterator.prototype.clear = function() {
+ if (this.decoder_) {
+ this.decoder_.free();
+ }
+ this.decoder_ = null;
+ this.nextMethod_ = null;
+ this.elements_ = null;
+ this.cursor_ = 0;
+ this.nextValue_ = null;
+ this.atEnd_ = true;
+};
+
+
+/**
+ * Returns the element at the iterator, or null if the iterator is invalid or
+ * past the end of the decoder/array.
+ * @return {number|boolean|string|null}
+ */
+jspb.BinaryIterator.prototype.get = function() {
+ return this.nextValue_;
+};
+
+
+/**
+ * Returns true if the iterator is at the end of the decoder/array.
+ * @return {boolean}
+ */
+jspb.BinaryIterator.prototype.atEnd = function() {
+ return this.atEnd_;
+};
+
+
+/**
+ * Returns the element at the iterator and steps to the next element,
+ * equivalent to '*pointer++' in C.
+ * @return {number|boolean|string|null}
+ */
+jspb.BinaryIterator.prototype.next = function() {
+ var lastValue = this.nextValue_;
+ if (this.decoder_) {
+ if (this.decoder_.atEnd()) {
+ this.nextValue_ = null;
+ this.atEnd_ = true;
+ } else {
+ this.nextValue_ = this.nextMethod_.call(this.decoder_);
+ }
+ } else if (this.elements_) {
+ if (this.cursor_ == this.elements_.length) {
+ this.nextValue_ = null;
+ this.atEnd_ = true;
+ } else {
+ this.nextValue_ = this.elements_[this.cursor_++];
+ }
+ }
+ return lastValue;
+};
+
+
+
+/**
+ * BinaryDecoder implements the decoders for all the wire types specified in
+ * https://developers.google.com/protocol-buffers/docs/encoding.
+ *
+ * @param {jspb.ByteSource=} opt_bytes The bytes we're reading from.
+ * @param {number=} opt_start The optional offset to start reading at.
+ * @param {number=} opt_length The optional length of the block to read -
+ * we'll throw an assertion if we go off the end of the block.
+ * @constructor
+ * @struct
+ */
+jspb.BinaryDecoder = function(opt_bytes, opt_start, opt_length) {
+ /**
+ * Typed byte-wise view of the source buffer.
+ * @private {?Uint8Array}
+ */
+ this.bytes_ = null;
+
+ /**
+ * Start point of the block to read.
+ * @private {number}
+ */
+ this.start_ = 0;
+
+ /**
+ * End point of the block to read.
+ * @private {number}
+ */
+ this.end_ = 0;
+
+ /**
+ * Current read location in bytes_.
+ * @private {number}
+ */
+ this.cursor_ = 0;
+
+ /**
+ * Temporary storage for the low 32 bits of 64-bit data types that we're
+ * decoding.
+ * @private {number}
+ */
+ this.tempLow_ = 0;
+
+ /**
+ * Temporary storage for the high 32 bits of 64-bit data types that we're
+ * decoding.
+ * @private {number}
+ */
+ this.tempHigh_ = 0;
+
+ /**
+ * Set to true if this decoder encountered an error due to corrupt data.
+ * @private {boolean}
+ */
+ this.error_ = false;
+
+ if (opt_bytes) {
+ this.setBlock(opt_bytes, opt_start, opt_length);
+ }
+};
+
+
+/**
+ * Global pool of BinaryDecoder instances.
+ * @private {!Array.<!jspb.BinaryDecoder>}
+ */
+jspb.BinaryDecoder.instanceCache_ = [];
+
+
+/**
+ * Pops an instance off the instance cache, or creates one if the cache is
+ * empty.
+ * @param {jspb.ByteSource=} opt_bytes The bytes we're reading from.
+ * @param {number=} opt_start The optional offset to start reading at.
+ * @param {number=} opt_length The optional length of the block to read -
+ * we'll throw an assertion if we go off the end of the block.
+ * @return {!jspb.BinaryDecoder}
+ */
+jspb.BinaryDecoder.alloc = function(opt_bytes, opt_start, opt_length) {
+ if (jspb.BinaryDecoder.instanceCache_.length) {
+ var newDecoder = jspb.BinaryDecoder.instanceCache_.pop();
+ if (opt_bytes) {
+ newDecoder.setBlock(opt_bytes, opt_start, opt_length);
+ }
+ return newDecoder;
+ } else {
+ return new jspb.BinaryDecoder(opt_bytes, opt_start, opt_length);
+ }
+};
+
+
+/**
+ * Puts this instance back in the instance cache.
+ */
+jspb.BinaryDecoder.prototype.free = function() {
+ this.clear();
+ if (jspb.BinaryDecoder.instanceCache_.length < 100) {
+ jspb.BinaryDecoder.instanceCache_.push(this);
+ }
+};
+
+
+/**
+ * Makes a copy of this decoder.
+ * @return {!jspb.BinaryDecoder}
+ */
+jspb.BinaryDecoder.prototype.clone = function() {
+ return jspb.BinaryDecoder.alloc(this.bytes_,
+ this.start_, this.end_ - this.start_);
+};
+
+
+/**
+ * Clears the decoder.
+ */
+jspb.BinaryDecoder.prototype.clear = function() {
+ this.bytes_ = null;
+ this.start_ = 0;
+ this.end_ = 0;
+ this.cursor_ = 0;
+ this.error_ = false;
+};
+
+
+/**
+ * Returns the raw buffer.
+ * @return {?Uint8Array} The raw buffer.
+ */
+jspb.BinaryDecoder.prototype.getBuffer = function() {
+ return this.bytes_;
+};
+
+
+/**
+ * Changes the block of bytes we're decoding.
+ * @param {!jspb.ByteSource} data The bytes we're reading from.
+ * @param {number=} opt_start The optional offset to start reading at.
+ * @param {number=} opt_length The optional length of the block to read -
+ * we'll throw an assertion if we go off the end of the block.
+ */
+jspb.BinaryDecoder.prototype.setBlock =
+ function(data, opt_start, opt_length) {
+ this.bytes_ = jspb.utils.byteSourceToUint8Array(data);
+ this.start_ = goog.isDef(opt_start) ? opt_start : 0;
+ this.end_ =
+ goog.isDef(opt_length) ? this.start_ + opt_length : this.bytes_.length;
+ this.cursor_ = this.start_;
+};
+
+
+/**
+ * @return {number}
+ */
+jspb.BinaryDecoder.prototype.getEnd = function() {
+ return this.end_;
+};
+
+
+/**
+ * @param {number} end
+ */
+jspb.BinaryDecoder.prototype.setEnd = function(end) {
+ this.end_ = end;
+};
+
+
+/**
+ * Moves the read cursor back to the start of the block.
+ */
+jspb.BinaryDecoder.prototype.reset = function() {
+ this.cursor_ = this.start_;
+};
+
+
+/**
+ * Returns the internal read cursor.
+ * @return {number} The internal read cursor.
+ */
+jspb.BinaryDecoder.prototype.getCursor = function() {
+ return this.cursor_;
+};
+
+
+/**
+ * Returns the internal read cursor.
+ * @param {number} cursor The new cursor.
+ */
+jspb.BinaryDecoder.prototype.setCursor = function(cursor) {
+ this.cursor_ = cursor;
+};
+
+
+/**
+ * Advances the stream cursor by the given number of bytes.
+ * @param {number} count The number of bytes to advance by.
+ */
+jspb.BinaryDecoder.prototype.advance = function(count) {
+ this.cursor_ += count;
+ goog.asserts.assert(this.cursor_ <= this.end_);
+};
+
+
+/**
+ * Returns true if this decoder is at the end of the block.
+ * @return {boolean}
+ */
+jspb.BinaryDecoder.prototype.atEnd = function() {
+ return this.cursor_ == this.end_;
+};
+
+
+/**
+ * Returns true if this decoder is at the end of the block.
+ * @return {boolean}
+ */
+jspb.BinaryDecoder.prototype.pastEnd = function() {
+ return this.cursor_ > this.end_;
+};
+
+
+/**
+ * Returns true if this decoder encountered an error due to corrupt data.
+ * @return {boolean}
+ */
+jspb.BinaryDecoder.prototype.getError = function() {
+ return this.error_ ||
+ (this.cursor_ < 0) ||
+ (this.cursor_ > this.end_);
+};
+
+
+/**
+ * Reads an unsigned varint from the binary stream and stores it as a split
+ * 64-bit integer. Since this does not convert the value to a number, no
+ * precision is lost.
+ *
+ * It's possible for an unsigned varint to be incorrectly encoded - more than
+ * 64 bits' worth of data could be present. If this happens, this method will
+ * throw an error.
+ *
+ * Decoding varints requires doing some funny base-128 math - for more
+ * details on the format, see
+ * https://developers.google.com/protocol-buffers/docs/encoding
+ *
+ * @private
+ */
+jspb.BinaryDecoder.prototype.readSplitVarint64_ = function() {
+ var temp;
+ var lowBits = 0;
+ var highBits = 0;
+
+ // Read the first four bytes of the varint, stopping at the terminator if we
+ // see it.
+ for (var i = 0; i < 4; i++) {
+ temp = this.bytes_[this.cursor_++];
+ lowBits |= (temp & 0x7F) << (i * 7);
+ if (temp < 128) {
+ this.tempLow_ = lowBits >>> 0;
+ this.tempHigh_ = 0;
+ return;
+ }
+ }
+
+ // Read the fifth byte, which straddles the low and high dwords.
+ temp = this.bytes_[this.cursor_++];
+ lowBits |= (temp & 0x7F) << 28;
+ highBits |= (temp & 0x7F) >> 4;
+ if (temp < 128) {
+ this.tempLow_ = lowBits >>> 0;
+ this.tempHigh_ = highBits >>> 0;
+ return;
+ }
+
+ // Read the sixth through tenth byte.
+ for (var i = 0; i < 5; i++) {
+ temp = this.bytes_[this.cursor_++];
+ highBits |= (temp & 0x7F) << (i * 7 + 3);
+ if (temp < 128) {
+ this.tempLow_ = lowBits >>> 0;
+ this.tempHigh_ = highBits >>> 0;
+ return;
+ }
+ }
+
+ // If we did not see the terminator, the encoding was invalid.
+ goog.asserts.fail('Failed to read varint, encoding is invalid.');
+ this.error_ = true;
+};
+
+
+/**
+ * Skips over a varint in the block without decoding it.
+ */
+jspb.BinaryDecoder.prototype.skipVarint = function() {
+ while (this.bytes_[this.cursor_] & 0x80) {
+ this.cursor_++;
+ }
+ this.cursor_++;
+};
+
+
+/**
+ * Skips backwards over a varint in the block - to do this correctly, we have
+ * to know the value we're skipping backwards over or things are ambiguous.
+ * @param {number} value The varint value to unskip.
+ */
+jspb.BinaryDecoder.prototype.unskipVarint = function(value) {
+ while (value > 128) {
+ this.cursor_--;
+ value = value >>> 7;
+ }
+ this.cursor_--;
+};
+
+
+/**
+ * Reads a 32-bit varint from the binary stream. Due to a quirk of the encoding
+ * format and Javascript's handling of bitwise math, this actually works
+ * correctly for both signed and unsigned 32-bit varints.
+ *
+ * This function is called vastly more frequently than any other in
+ * BinaryDecoder, so it has been unrolled and tweaked for performance.
+ *
+ * If there are more than 32 bits of data in the varint, it _must_ be due to
+ * sign-extension. If we're in debug mode and the high 32 bits don't match the
+ * expected sign extension, this method will throw an error.
+ *
+ * Decoding varints requires doing some funny base-128 math - for more
+ * details on the format, see
+ * https://developers.google.com/protocol-buffers/docs/encoding
+ *
+ * @return {number} The decoded unsigned 32-bit varint.
+ */
+jspb.BinaryDecoder.prototype.readUnsignedVarint32 = function() {
+ var temp;
+ var bytes = this.bytes_;
+
+ temp = bytes[this.cursor_ + 0];
+ var x = (temp & 0x7F);
+ if (temp < 128) {
+ this.cursor_ += 1;
+ goog.asserts.assert(this.cursor_ <= this.end_);
+ return x;
+ }
+
+ temp = bytes[this.cursor_ + 1];
+ x |= (temp & 0x7F) << 7;
+ if (temp < 128) {
+ this.cursor_ += 2;
+ goog.asserts.assert(this.cursor_ <= this.end_);
+ return x;
+ }
+
+ temp = bytes[this.cursor_ + 2];
+ x |= (temp & 0x7F) << 14;
+ if (temp < 128) {
+ this.cursor_ += 3;
+ goog.asserts.assert(this.cursor_ <= this.end_);
+ return x;
+ }
+
+ temp = bytes[this.cursor_ + 3];
+ x |= (temp & 0x7F) << 21;
+ if (temp < 128) {
+ this.cursor_ += 4;
+ goog.asserts.assert(this.cursor_ <= this.end_);
+ return x;
+ }
+
+ temp = bytes[this.cursor_ + 4];
+ x |= (temp & 0x0F) << 28;
+ if (temp < 128) {
+ // We're reading the high bits of an unsigned varint. The byte we just read
+ // also contains bits 33 through 35, which we're going to discard. Those
+ // bits _must_ be zero, or the encoding is invalid.
+ goog.asserts.assert((temp & 0xF0) == 0);
+ this.cursor_ += 5;
+ goog.asserts.assert(this.cursor_ <= this.end_);
+ return x >>> 0;
+ }
+
+ // If we get here, we're reading the sign extension of a negative 32-bit int.
+ // We can skip these bytes, as we know in advance that they have to be all
+ // 1's if the varint is correctly encoded. Since we also know the value is
+ // negative, we don't have to coerce it to unsigned before we return it.
+
+ goog.asserts.assert((temp & 0xF0) == 0xF0);
+ goog.asserts.assert(bytes[this.cursor_ + 5] == 0xFF);
+ goog.asserts.assert(bytes[this.cursor_ + 6] == 0xFF);
+ goog.asserts.assert(bytes[this.cursor_ + 7] == 0xFF);
+ goog.asserts.assert(bytes[this.cursor_ + 8] == 0xFF);
+ goog.asserts.assert(bytes[this.cursor_ + 9] == 0x01);
+
+ this.cursor_ += 10;
+ goog.asserts.assert(this.cursor_ <= this.end_);
+ return x;
+};
+
+
+/**
+ * The readUnsignedVarint32 above deals with signed 32-bit varints correctly,
+ * so this is just an alias.
+ *
+ * @return {number} The decoded signed 32-bit varint.
+ */
+jspb.BinaryDecoder.prototype.readSignedVarint32 =
+ jspb.BinaryDecoder.prototype.readUnsignedVarint32;
+
+
+/**
+ * Reads a 32-bit unsigned variant and returns its value as a string.
+ *
+ * @return {string} The decoded unsigned 32-bit varint as a string.
+ */
+jspb.BinaryDecoder.prototype.readUnsignedVarint32String = function() {
+ // 32-bit integers fit in JavaScript numbers without loss of precision, so
+ // string variants of 32-bit varint readers can simply delegate then convert
+ // to string.
+ var value = this.readUnsignedVarint32();
+ return value.toString();
+};
+
+
+/**
+ * Reads a 32-bit signed variant and returns its value as a string.
+ *
+ * @return {string} The decoded signed 32-bit varint as a string.
+ */
+jspb.BinaryDecoder.prototype.readSignedVarint32String = function() {
+ // 32-bit integers fit in JavaScript numbers without loss of precision, so
+ // string variants of 32-bit varint readers can simply delegate then convert
+ // to string.
+ var value = this.readSignedVarint32();
+ return value.toString();
+};
+
+
+/**
+ * Reads a signed, zigzag-encoded 32-bit varint from the binary stream.
+ *
+ * Zigzag encoding is a modification of varint encoding that reduces the
+ * storage overhead for small negative integers - for more details on the
+ * format, see https://developers.google.com/protocol-buffers/docs/encoding
+ *
+ * @return {number} The decoded signed, zigzag-encoded 32-bit varint.
+ */
+jspb.BinaryDecoder.prototype.readZigzagVarint32 = function() {
+ var result = this.readUnsignedVarint32();
+ return (result >>> 1) ^ - (result & 1);
+};
+
+
+/**
+ * Reads an unsigned 64-bit varint from the binary stream. Note that since
+ * Javascript represents all numbers as double-precision floats, there will be
+ * precision lost if the absolute value of the varint is larger than 2^53.
+ *
+ * @return {number} The decoded unsigned varint. Precision will be lost if the
+ * integer exceeds 2^53.
+ */
+jspb.BinaryDecoder.prototype.readUnsignedVarint64 = function() {
+ this.readSplitVarint64_();
+ return jspb.utils.joinUint64(this.tempLow_, this.tempHigh_);
+};
+
+
+/**
+ * Reads an unsigned 64-bit varint from the binary stream and returns the value
+ * as a decimal string.
+ *
+ * @return {string} The decoded unsigned varint as a decimal string.
+ */
+jspb.BinaryDecoder.prototype.readUnsignedVarint64String = function() {
+ this.readSplitVarint64_();
+ return jspb.utils.joinUnsignedDecimalString(this.tempLow_, this.tempHigh_);
+};
+
+
+/**
+ * Reads a signed 64-bit varint from the binary stream. Note that since
+ * Javascript represents all numbers as double-precision floats, there will be
+ * precision lost if the absolute value of the varint is larger than 2^53.
+ *
+ * @return {number} The decoded signed varint. Precision will be lost if the
+ * integer exceeds 2^53.
+ */
+jspb.BinaryDecoder.prototype.readSignedVarint64 = function() {
+ this.readSplitVarint64_();
+ return jspb.utils.joinInt64(this.tempLow_, this.tempHigh_);
+};
+
+
+/**
+ * Reads an signed 64-bit varint from the binary stream and returns the value
+ * as a decimal string.
+ *
+ * @return {string} The decoded signed varint as a decimal string.
+ */
+jspb.BinaryDecoder.prototype.readSignedVarint64String = function() {
+ this.readSplitVarint64_();
+ return jspb.utils.joinSignedDecimalString(this.tempLow_, this.tempHigh_);
+};
+
+
+/**
+ * Reads a signed, zigzag-encoded 64-bit varint from the binary stream. Note
+ * that since Javascript represents all numbers as double-precision floats,
+ * there will be precision lost if the absolute value of the varint is larger
+ * than 2^53.
+ *
+ * Zigzag encoding is a modification of varint encoding that reduces the
+ * storage overhead for small negative integers - for more details on the
+ * format, see https://developers.google.com/protocol-buffers/docs/encoding
+ *
+ * @return {number} The decoded zigzag varint. Precision will be lost if the
+ * integer exceeds 2^53.
+ */
+jspb.BinaryDecoder.prototype.readZigzagVarint64 = function() {
+ this.readSplitVarint64_();
+ return jspb.utils.joinZigzag64(this.tempLow_, this.tempHigh_);
+};
+
+
+/**
+ * Reads a signed, zigzag-encoded 64-bit varint from the binary stream and
+ * returns its valud as a string.
+ *
+ * Zigzag encoding is a modification of varint encoding that reduces the
+ * storage overhead for small negative integers - for more details on the
+ * format, see https://developers.google.com/protocol-buffers/docs/encoding
+ *
+ * @return {string} The decoded signed, zigzag-encoded 64-bit varint as a
+ * string.
+ */
+jspb.BinaryDecoder.prototype.readZigzagVarint64String = function() {
+ // TODO(haberman): write lossless 64-bit zig-zag math.
+ var value = this.readZigzagVarint64();
+ return value.toString();
+};
+
+
+/**
+ * Reads a raw unsigned 8-bit integer from the binary stream.
+ *
+ * @return {number} The unsigned 8-bit integer read from the binary stream.
+ */
+jspb.BinaryDecoder.prototype.readUint8 = function() {
+ var a = this.bytes_[this.cursor_ + 0];
+ this.cursor_ += 1;
+ goog.asserts.assert(this.cursor_ <= this.end_);
+ return a;
+};
+
+
+/**
+ * Reads a raw unsigned 16-bit integer from the binary stream.
+ *
+ * @return {number} The unsigned 16-bit integer read from the binary stream.
+ */
+jspb.BinaryDecoder.prototype.readUint16 = function() {
+ var a = this.bytes_[this.cursor_ + 0];
+ var b = this.bytes_[this.cursor_ + 1];
+ this.cursor_ += 2;
+ goog.asserts.assert(this.cursor_ <= this.end_);
+ return (a << 0) | (b << 8);
+};
+
+
+/**
+ * Reads a raw unsigned 32-bit integer from the binary stream.
+ *
+ * @return {number} The unsigned 32-bit integer read from the binary stream.
+ */
+jspb.BinaryDecoder.prototype.readUint32 = function() {
+ var a = this.bytes_[this.cursor_ + 0];
+ var b = this.bytes_[this.cursor_ + 1];
+ var c = this.bytes_[this.cursor_ + 2];
+ var d = this.bytes_[this.cursor_ + 3];
+ this.cursor_ += 4;
+ goog.asserts.assert(this.cursor_ <= this.end_);
+ return ((a << 0) | (b << 8) | (c << 16) | (d << 24)) >>> 0;
+};
+
+
+/**
+ * Reads a raw unsigned 64-bit integer from the binary stream. Note that since
+ * Javascript represents all numbers as double-precision floats, there will be
+ * precision lost if the absolute value of the integer is larger than 2^53.
+ *
+ * @return {number} The unsigned 64-bit integer read from the binary stream.
+ * Precision will be lost if the integer exceeds 2^53.
+ */
+jspb.BinaryDecoder.prototype.readUint64 = function() {
+ var bitsLow = this.readUint32();
+ var bitsHigh = this.readUint32();
+ return jspb.utils.joinUint64(bitsLow, bitsHigh);
+};
+
+
+/**
+ * Reads a raw unsigned 64-bit integer from the binary stream. Note that since
+ * Javascript represents all numbers as double-precision floats, there will be
+ * precision lost if the absolute value of the integer is larger than 2^53.
+ *
+ * @return {string} The unsigned 64-bit integer read from the binary stream.
+ */
+jspb.BinaryDecoder.prototype.readUint64String = function() {
+ var bitsLow = this.readUint32();
+ var bitsHigh = this.readUint32();
+ return jspb.utils.joinUnsignedDecimalString(bitsLow, bitsHigh);
+};
+
+
+/**
+ * Reads a raw signed 8-bit integer from the binary stream.
+ *
+ * @return {number} The signed 8-bit integer read from the binary stream.
+ */
+jspb.BinaryDecoder.prototype.readInt8 = function() {
+ var a = this.bytes_[this.cursor_ + 0];
+ this.cursor_ += 1;
+ goog.asserts.assert(this.cursor_ <= this.end_);
+ return (a << 24) >> 24;
+};
+
+
+/**
+ * Reads a raw signed 16-bit integer from the binary stream.
+ *
+ * @return {number} The signed 16-bit integer read from the binary stream.
+ */
+jspb.BinaryDecoder.prototype.readInt16 = function() {
+ var a = this.bytes_[this.cursor_ + 0];
+ var b = this.bytes_[this.cursor_ + 1];
+ this.cursor_ += 2;
+ goog.asserts.assert(this.cursor_ <= this.end_);
+ return (((a << 0) | (b << 8)) << 16) >> 16;
+};
+
+
+/**
+ * Reads a raw signed 32-bit integer from the binary stream.
+ *
+ * @return {number} The signed 32-bit integer read from the binary stream.
+ */
+jspb.BinaryDecoder.prototype.readInt32 = function() {
+ var a = this.bytes_[this.cursor_ + 0];
+ var b = this.bytes_[this.cursor_ + 1];
+ var c = this.bytes_[this.cursor_ + 2];
+ var d = this.bytes_[this.cursor_ + 3];
+ this.cursor_ += 4;
+ goog.asserts.assert(this.cursor_ <= this.end_);
+ return (a << 0) | (b << 8) | (c << 16) | (d << 24);
+};
+
+
+/**
+ * Reads a raw signed 64-bit integer from the binary stream. Note that since
+ * Javascript represents all numbers as double-precision floats, there will be
+ * precision lost if the absolute vlaue of the integer is larger than 2^53.
+ *
+ * @return {number} The signed 64-bit integer read from the binary stream.
+ * Precision will be lost if the integer exceeds 2^53.
+ */
+jspb.BinaryDecoder.prototype.readInt64 = function() {
+ var bitsLow = this.readUint32();
+ var bitsHigh = this.readUint32();
+ return jspb.utils.joinInt64(bitsLow, bitsHigh);
+};
+
+
+/**
+ * Reads a raw signed 64-bit integer from the binary stream and returns it as a
+ * string.
+ *
+ * @return {string} The signed 64-bit integer read from the binary stream.
+ * Precision will be lost if the integer exceeds 2^53.
+ */
+jspb.BinaryDecoder.prototype.readInt64String = function() {
+ var bitsLow = this.readUint32();
+ var bitsHigh = this.readUint32();
+ return jspb.utils.joinSignedDecimalString(bitsLow, bitsHigh);
+};
+
+
+/**
+ * Reads a 32-bit floating-point number from the binary stream, using the
+ * temporary buffer to realign the data.
+ *
+ * @return {number} The float read from the binary stream.
+ */
+jspb.BinaryDecoder.prototype.readFloat = function() {
+ var bitsLow = this.readUint32();
+ var bitsHigh = 0;
+ return jspb.utils.joinFloat32(bitsLow, bitsHigh);
+};
+
+
+/**
+ * Reads a 64-bit floating-point number from the binary stream, using the
+ * temporary buffer to realign the data.
+ *
+ * @return {number} The double read from the binary stream.
+ */
+jspb.BinaryDecoder.prototype.readDouble = function() {
+ var bitsLow = this.readUint32();
+ var bitsHigh = this.readUint32();
+ return jspb.utils.joinFloat64(bitsLow, bitsHigh);
+};
+
+
+/**
+ * Reads a boolean value from the binary stream.
+ * @return {boolean} The boolean read from the binary stream.
+ */
+jspb.BinaryDecoder.prototype.readBool = function() {
+ return !!this.bytes_[this.cursor_++];
+};
+
+
+/**
+ * Reads an enum value from the binary stream, which are always encoded as
+ * signed varints.
+ * @return {number} The enum value read from the binary stream.
+ */
+jspb.BinaryDecoder.prototype.readEnum = function() {
+ return this.readSignedVarint32();
+};
+
+
+/**
+ * Reads and parses a UTF-8 encoded unicode string from the stream.
+ * The code is inspired by maps.vectortown.parse.StreamedDataViewReader.
+ * Supports codepoints from U+0000 up to U+10FFFF.
+ * (http://en.wikipedia.org/wiki/UTF-8).
+ * @param {number} length The length of the string to read.
+ * @return {string} The decoded string.
+ */
+jspb.BinaryDecoder.prototype.readString = function(length) {
+ var bytes = this.bytes_;
+ var cursor = this.cursor_;
+ var end = cursor + length;
+ var codeUnits = [];
+
+ while (cursor < end) {
+ var c = bytes[cursor++];
+ if (c < 128) { // Regular 7-bit ASCII.
+ codeUnits.push(c);
+ } else if (c < 192) {
+ // UTF-8 continuation mark. We are out of sync. This
+ // might happen if we attempted to read a character
+ // with more than four bytes.
+ continue;
+ } else if (c < 224) { // UTF-8 with two bytes.
+ var c2 = bytes[cursor++];
+ codeUnits.push(((c & 31) << 6) | (c2 & 63));
+ } else if (c < 240) { // UTF-8 with three bytes.
+ var c2 = bytes[cursor++];
+ var c3 = bytes[cursor++];
+ codeUnits.push(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
+ } else if (c < 248) { // UTF-8 with 4 bytes.
+ var c2 = bytes[cursor++];
+ var c3 = bytes[cursor++];
+ var c4 = bytes[cursor++];
+ // Characters written on 4 bytes have 21 bits for a codepoint.
+ // We can't fit that on 16bit characters, so we use surrogates.
+ var codepoint = ((c & 7) << 18) | ((c2 & 63) << 12) | ((c3 & 63) << 6) | (c4 & 63);
+ // Surrogates formula from wikipedia.
+ // 1. Subtract 0x10000 from codepoint
+ codepoint -= 0x10000;
+ // 2. Split this into the high 10-bit value and the low 10-bit value
+ // 3. Add 0xD800 to the high value to form the high surrogate
+ // 4. Add 0xDC00 to the low value to form the low surrogate:
+ var low = (codepoint & 1023) + 0xDC00;
+ var high = ((codepoint >> 10) & 1023) + 0xD800;
+ codeUnits.push(high, low);
+ }
+ }
+ // String.fromCharCode.apply is faster than manually appending characters on
+ // Chrome 25+, and generates no additional cons string garbage.
+ var result = String.fromCharCode.apply(null, codeUnits);
+ this.cursor_ = cursor;
+ return result;
+};
+
+
+/**
+ * Reads and parses a UTF-8 encoded unicode string (with length prefix) from
+ * the stream.
+ * @return {string} The decoded string.
+ */
+jspb.BinaryDecoder.prototype.readStringWithLength = function() {
+ var length = this.readUnsignedVarint32();
+ return this.readString(length);
+};
+
+
+/**
+ * Reads a block of raw bytes from the binary stream.
+ *
+ * @param {number} length The number of bytes to read.
+ * @return {!Uint8Array} The decoded block of bytes, or an empty block if the
+ * length was invalid.
+ */
+jspb.BinaryDecoder.prototype.readBytes = function(length) {
+ if (length < 0 ||
+ this.cursor_ + length > this.bytes_.length) {
+ this.error_ = true;
+ goog.asserts.fail('Invalid byte length!');
+ return new Uint8Array(0);
+ }
+
+ var result = this.bytes_.subarray(this.cursor_, this.cursor_ + length);
+
+ this.cursor_ += length;
+ goog.asserts.assert(this.cursor_ <= this.end_);
+ return result;
+};
+
+
+/**
+ * Reads a 64-bit varint from the stream and returns it as an 8-character
+ * Unicode string for use as a hash table key.
+ *
+ * @return {string} The hash value.
+ */
+jspb.BinaryDecoder.prototype.readVarintHash64 = function() {
+ this.readSplitVarint64_();
+ return jspb.utils.joinHash64(this.tempLow_, this.tempHigh_);
+};
+
+
+/**
+ * Reads a 64-bit fixed-width value from the stream and returns it as an
+ * 8-character Unicode string for use as a hash table key.
+ *
+ * @return {string} The hash value.
+ */
+jspb.BinaryDecoder.prototype.readFixedHash64 = function() {
+ var bytes = this.bytes_;
+ var cursor = this.cursor_;
+
+ var a = bytes[cursor + 0];
+ var b = bytes[cursor + 1];
+ var c = bytes[cursor + 2];
+ var d = bytes[cursor + 3];
+ var e = bytes[cursor + 4];
+ var f = bytes[cursor + 5];
+ var g = bytes[cursor + 6];
+ var h = bytes[cursor + 7];
+
+ this.cursor_ += 8;
+
+ return String.fromCharCode(a, b, c, d, e, f, g, h);
+};
diff --git a/third_party/protobuf/js/binary/decoder_test.js b/third_party/protobuf/js/binary/decoder_test.js
new file mode 100644
index 0000000000..cb8aff969d
--- /dev/null
+++ b/third_party/protobuf/js/binary/decoder_test.js
@@ -0,0 +1,357 @@
+// 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.
+
+/**
+ * @fileoverview Test cases for jspb's binary protocol buffer decoder.
+ *
+ * There are two particular magic numbers that need to be pointed out -
+ * 2^64-1025 is the largest number representable as both a double and an
+ * unsigned 64-bit integer, and 2^63-513 is the largest number representable as
+ * both a double and a signed 64-bit integer.
+ *
+ * Test suite is written using Jasmine -- see http://jasmine.github.io/
+ *
+ * @author aappleby@google.com (Austin Appleby)
+ */
+
+goog.require('goog.testing.asserts');
+goog.require('jspb.BinaryConstants');
+goog.require('jspb.BinaryDecoder');
+goog.require('jspb.BinaryEncoder');
+
+
+/**
+ * Tests encoding and decoding of unsigned types.
+ * @param {Function} readValue
+ * @param {Function} writeValue
+ * @param {number} epsilon
+ * @param {number} upperLimit
+ * @param {Function} filter
+ * @suppress {missingProperties|visibility}
+ */
+function doTestUnsignedValue(readValue,
+ writeValue, epsilon, upperLimit, filter) {
+ var encoder = new jspb.BinaryEncoder();
+
+ // Encode zero and limits.
+ writeValue.call(encoder, filter(0));
+ writeValue.call(encoder, filter(epsilon));
+ writeValue.call(encoder, filter(upperLimit));
+
+ // Encode positive values.
+ for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) {
+ writeValue.call(encoder, filter(cursor));
+ }
+
+ var decoder = jspb.BinaryDecoder.alloc(encoder.end());
+
+ // Check zero and limits.
+ assertEquals(filter(0), readValue.call(decoder));
+ assertEquals(filter(epsilon), readValue.call(decoder));
+ assertEquals(filter(upperLimit), readValue.call(decoder));
+
+ // Check positive values.
+ for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) {
+ if (filter(cursor) != readValue.call(decoder)) throw 'fail!';
+ }
+
+ // Encoding values outside the valid range should assert.
+ assertThrows(function() {writeValue.call(encoder, -1);});
+ assertThrows(function() {writeValue.call(encoder, upperLimit * 1.1);});
+}
+
+
+/**
+ * Tests encoding and decoding of signed types.
+ * @param {Function} readValue
+ * @param {Function} writeValue
+ * @param {number} epsilon
+ * @param {number} lowerLimit
+ * @param {number} upperLimit
+ * @param {Function} filter
+ * @suppress {missingProperties}
+ */
+function doTestSignedValue(readValue,
+ writeValue, epsilon, lowerLimit, upperLimit, filter) {
+ var encoder = new jspb.BinaryEncoder();
+
+ // Encode zero and limits.
+ writeValue.call(encoder, filter(lowerLimit));
+ writeValue.call(encoder, filter(-epsilon));
+ writeValue.call(encoder, filter(0));
+ writeValue.call(encoder, filter(epsilon));
+ writeValue.call(encoder, filter(upperLimit));
+
+ var inputValues = [];
+
+ // Encode negative values.
+ for (var cursor = lowerLimit; cursor < -epsilon; cursor /= 1.1) {
+ var val = filter(cursor);
+ writeValue.call(encoder, val);
+ inputValues.push(val);
+ }
+
+ // Encode positive values.
+ for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) {
+ var val = filter(cursor);
+ writeValue.call(encoder, val);
+ inputValues.push(val);
+ }
+
+ var decoder = jspb.BinaryDecoder.alloc(encoder.end());
+
+ // Check zero and limits.
+ assertEquals(filter(lowerLimit), readValue.call(decoder));
+ assertEquals(filter(-epsilon), readValue.call(decoder));
+ assertEquals(filter(0), readValue.call(decoder));
+ assertEquals(filter(epsilon), readValue.call(decoder));
+ assertEquals(filter(upperLimit), readValue.call(decoder));
+
+ // Verify decoded values.
+ for (var i = 0; i < inputValues.length; i++) {
+ assertEquals(inputValues[i], readValue.call(decoder));
+ }
+
+ // Encoding values outside the valid range should assert.
+ assertThrows(function() {writeValue.call(encoder, lowerLimit * 1.1);});
+ assertThrows(function() {writeValue.call(encoder, upperLimit * 1.1);});
+}
+
+describe('binaryDecoderTest', function() {
+ /**
+ * Tests the decoder instance cache.
+ */
+ it('testInstanceCache', /** @suppress {visibility} */ function() {
+ // Empty the instance caches.
+ jspb.BinaryDecoder.instanceCache_ = [];
+
+ // Allocating and then freeing a decoder should put it in the instance
+ // cache.
+ jspb.BinaryDecoder.alloc().free();
+
+ assertEquals(1, jspb.BinaryDecoder.instanceCache_.length);
+
+ // Allocating and then freeing three decoders should leave us with three in
+ // the cache.
+
+ var decoder1 = jspb.BinaryDecoder.alloc();
+ var decoder2 = jspb.BinaryDecoder.alloc();
+ var decoder3 = jspb.BinaryDecoder.alloc();
+ decoder1.free();
+ decoder2.free();
+ decoder3.free();
+
+ assertEquals(3, jspb.BinaryDecoder.instanceCache_.length);
+ });
+
+
+ /**
+ * Tests reading 64-bit integers as hash strings.
+ */
+ it('testHashStrings', function() {
+ var encoder = new jspb.BinaryEncoder();
+
+ var hashA = String.fromCharCode(0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00);
+ var hashB = String.fromCharCode(0x12, 0x34, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00);
+ var hashC = String.fromCharCode(0x12, 0x34, 0x56, 0x78,
+ 0x87, 0x65, 0x43, 0x21);
+ var hashD = String.fromCharCode(0xFF, 0xFF, 0xFF, 0xFF,
+ 0xFF, 0xFF, 0xFF, 0xFF);
+
+ encoder.writeVarintHash64(hashA);
+ encoder.writeVarintHash64(hashB);
+ encoder.writeVarintHash64(hashC);
+ encoder.writeVarintHash64(hashD);
+
+ encoder.writeFixedHash64(hashA);
+ encoder.writeFixedHash64(hashB);
+ encoder.writeFixedHash64(hashC);
+ encoder.writeFixedHash64(hashD);
+
+ var decoder = jspb.BinaryDecoder.alloc(encoder.end());
+
+ assertEquals(hashA, decoder.readVarintHash64());
+ assertEquals(hashB, decoder.readVarintHash64());
+ assertEquals(hashC, decoder.readVarintHash64());
+ assertEquals(hashD, decoder.readVarintHash64());
+
+ assertEquals(hashA, decoder.readFixedHash64());
+ assertEquals(hashB, decoder.readFixedHash64());
+ assertEquals(hashC, decoder.readFixedHash64());
+ assertEquals(hashD, decoder.readFixedHash64());
+ });
+
+ /**
+ * Test encoding and decoding utf-8.
+ */
+ it('testUtf8', function() {
+ var encoder = new jspb.BinaryEncoder();
+
+ var ascii = "ASCII should work in 3, 2, 1...";
+ var utf8_two_bytes = "©";
+ var utf8_three_bytes = "❄";
+ var utf8_four_bytes = "😁";
+
+ encoder.writeString(ascii);
+ encoder.writeString(utf8_two_bytes);
+ encoder.writeString(utf8_three_bytes);
+ encoder.writeString(utf8_four_bytes);
+
+ var decoder = jspb.BinaryDecoder.alloc(encoder.end());
+
+ assertEquals(ascii, decoder.readString(ascii.length));
+ assertEquals(utf8_two_bytes, decoder.readString(utf8_two_bytes.length));
+ assertEquals(utf8_three_bytes, decoder.readString(utf8_three_bytes.length));
+ assertEquals(utf8_four_bytes, decoder.readString(utf8_four_bytes.length));
+ });
+
+ /**
+ * Verifies that misuse of the decoder class triggers assertions.
+ * @suppress {checkTypes|visibility}
+ */
+ it('testDecodeErrors', function() {
+ // Reading a value past the end of the stream should trigger an assertion.
+ var decoder = jspb.BinaryDecoder.alloc([0, 1, 2]);
+ assertThrows(function() {decoder.readUint64()});
+
+ // Overlong varints should trigger assertions.
+ decoder.setBlock([255, 255, 255, 255, 255, 255,
+ 255, 255, 255, 255, 255, 0]);
+ assertThrows(function() {decoder.readUnsignedVarint64()});
+ decoder.reset();
+ assertThrows(function() {decoder.readSignedVarint64()});
+ decoder.reset();
+ assertThrows(function() {decoder.readZigzagVarint64()});
+
+ // Positive 32-bit varints encoded with 1 bits in positions 33 through 35
+ // should trigger assertions.
+ decoder.setBlock([255, 255, 255, 255, 0x1F]);
+ assertThrows(function() {decoder.readUnsignedVarint32()});
+
+ decoder.setBlock([255, 255, 255, 255, 0x2F]);
+ assertThrows(function() {decoder.readUnsignedVarint32()});
+
+ decoder.setBlock([255, 255, 255, 255, 0x4F]);
+ assertThrows(function() {decoder.readUnsignedVarint32()});
+
+ // Negative 32-bit varints encoded with non-1 bits in the high dword should
+ // trigger assertions.
+ decoder.setBlock([255, 255, 255, 255, 255, 255, 0, 255, 255, 1]);
+ assertThrows(function() {decoder.readUnsignedVarint32()});
+
+ decoder.setBlock([255, 255, 255, 255, 255, 255, 255, 255, 255, 0]);
+ assertThrows(function() {decoder.readUnsignedVarint32()});
+ });
+
+
+ /**
+ * Tests encoding and decoding of unsigned integers.
+ */
+ it('testUnsignedIntegers', function() {
+ doTestUnsignedValue(
+ jspb.BinaryDecoder.prototype.readUint8,
+ jspb.BinaryEncoder.prototype.writeUint8,
+ 1, 0xFF, Math.round);
+
+ doTestUnsignedValue(
+ jspb.BinaryDecoder.prototype.readUint16,
+ jspb.BinaryEncoder.prototype.writeUint16,
+ 1, 0xFFFF, Math.round);
+
+ doTestUnsignedValue(
+ jspb.BinaryDecoder.prototype.readUint32,
+ jspb.BinaryEncoder.prototype.writeUint32,
+ 1, 0xFFFFFFFF, Math.round);
+
+ doTestUnsignedValue(
+ jspb.BinaryDecoder.prototype.readUint64,
+ jspb.BinaryEncoder.prototype.writeUint64,
+ 1, Math.pow(2, 64) - 1025, Math.round);
+ });
+
+
+ /**
+ * Tests encoding and decoding of signed integers.
+ */
+ it('testSignedIntegers', function() {
+ doTestSignedValue(
+ jspb.BinaryDecoder.prototype.readInt8,
+ jspb.BinaryEncoder.prototype.writeInt8,
+ 1, -0x80, 0x7F, Math.round);
+
+ doTestSignedValue(
+ jspb.BinaryDecoder.prototype.readInt16,
+ jspb.BinaryEncoder.prototype.writeInt16,
+ 1, -0x8000, 0x7FFF, Math.round);
+
+ doTestSignedValue(
+ jspb.BinaryDecoder.prototype.readInt32,
+ jspb.BinaryEncoder.prototype.writeInt32,
+ 1, -0x80000000, 0x7FFFFFFF, Math.round);
+
+ doTestSignedValue(
+ jspb.BinaryDecoder.prototype.readInt64,
+ jspb.BinaryEncoder.prototype.writeInt64,
+ 1, -Math.pow(2, 63), Math.pow(2, 63) - 513, Math.round);
+ });
+
+
+ /**
+ * Tests encoding and decoding of floats.
+ */
+ it('testFloats', function() {
+ /**
+ * @param {number} x
+ * @return {number}
+ */
+ function truncate(x) {
+ var temp = new Float32Array(1);
+ temp[0] = x;
+ return temp[0];
+ }
+ doTestSignedValue(
+ jspb.BinaryDecoder.prototype.readFloat,
+ jspb.BinaryEncoder.prototype.writeFloat,
+ jspb.BinaryConstants.FLOAT32_EPS,
+ -jspb.BinaryConstants.FLOAT32_MAX,
+ jspb.BinaryConstants.FLOAT32_MAX,
+ truncate);
+
+ doTestSignedValue(
+ jspb.BinaryDecoder.prototype.readDouble,
+ jspb.BinaryEncoder.prototype.writeDouble,
+ jspb.BinaryConstants.FLOAT64_EPS * 10,
+ -jspb.BinaryConstants.FLOAT64_MAX,
+ jspb.BinaryConstants.FLOAT64_MAX,
+ function(x) { return x; });
+ });
+});
diff --git a/third_party/protobuf/js/binary/encoder.js b/third_party/protobuf/js/binary/encoder.js
new file mode 100644
index 0000000000..aee33e7e68
--- /dev/null
+++ b/third_party/protobuf/js/binary/encoder.js
@@ -0,0 +1,490 @@
+// 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.
+
+/**
+ * @fileoverview BinaryEncode defines methods for encoding Javascript values
+ * into arrays of bytes compatible with the Protocol Buffer wire format.
+ *
+ * @author aappleby@google.com (Austin Appleby)
+ */
+
+goog.provide('jspb.BinaryEncoder');
+
+goog.require('goog.asserts');
+goog.require('jspb.BinaryConstants');
+goog.require('jspb.utils');
+
+
+
+/**
+ * BinaryEncoder implements encoders for all the wire types specified in
+ * https://developers.google.com/protocol-buffers/docs/encoding.
+ *
+ * @constructor
+ * @struct
+ */
+jspb.BinaryEncoder = function() {
+ /** @private {!Array.<number>} */
+ this.buffer_ = [];
+};
+
+
+/**
+ * @return {number}
+ */
+jspb.BinaryEncoder.prototype.length = function() {
+ return this.buffer_.length;
+};
+
+
+/**
+ * @return {!Array.<number>}
+ */
+jspb.BinaryEncoder.prototype.end = function() {
+ var buffer = this.buffer_;
+ this.buffer_ = [];
+ return buffer;
+};
+
+
+/**
+ * Encodes a 64-bit integer in 32:32 split representation into its wire-format
+ * varint representation and stores it in the buffer.
+ * @param {number} lowBits The low 32 bits of the int.
+ * @param {number} highBits The high 32 bits of the int.
+ */
+jspb.BinaryEncoder.prototype.writeSplitVarint64 = function(lowBits, highBits) {
+ goog.asserts.assert(lowBits == Math.floor(lowBits));
+ goog.asserts.assert(highBits == Math.floor(highBits));
+ goog.asserts.assert((lowBits >= 0) &&
+ (lowBits < jspb.BinaryConstants.TWO_TO_32));
+ goog.asserts.assert((highBits >= 0) &&
+ (highBits < jspb.BinaryConstants.TWO_TO_32));
+
+ // Break the binary representation into chunks of 7 bits, set the 8th bit
+ // in each chunk if it's not the final chunk, and append to the result.
+ while (highBits > 0 || lowBits > 127) {
+ this.buffer_.push((lowBits & 0x7f) | 0x80);
+ lowBits = ((lowBits >>> 7) | (highBits << 25)) >>> 0;
+ highBits = highBits >>> 7;
+ }
+ this.buffer_.push(lowBits);
+};
+
+
+/**
+ * Encodes a 64-bit integer in 32:32 split representation into its wire-format
+ * fixed representation and stores it in the buffer.
+ * @param {number} lowBits The low 32 bits of the int.
+ * @param {number} highBits The high 32 bits of the int.
+ */
+jspb.BinaryEncoder.prototype.writeSplitFixed64 = function(lowBits, highBits) {
+ goog.asserts.assert(lowBits == Math.floor(lowBits));
+ goog.asserts.assert(highBits == Math.floor(highBits));
+ goog.asserts.assert((lowBits >= 0) &&
+ (lowBits < jspb.BinaryConstants.TWO_TO_32));
+ goog.asserts.assert((highBits >= 0) &&
+ (highBits < jspb.BinaryConstants.TWO_TO_32));
+ this.writeUint32(lowBits);
+ this.writeUint32(highBits);
+};
+
+
+/**
+ * Encodes a 32-bit unsigned integer into its wire-format varint representation
+ * and stores it in the buffer.
+ * @param {number} value The integer to convert.
+ */
+jspb.BinaryEncoder.prototype.writeUnsignedVarint32 = function(value) {
+ goog.asserts.assert(value == Math.floor(value));
+ goog.asserts.assert((value >= 0) &&
+ (value < jspb.BinaryConstants.TWO_TO_32));
+
+ while (value > 127) {
+ this.buffer_.push((value & 0x7f) | 0x80);
+ value = value >>> 7;
+ }
+
+ this.buffer_.push(value);
+};
+
+
+/**
+ * Encodes a 32-bit signed integer into its wire-format varint representation
+ * and stores it in the buffer.
+ * @param {number} value The integer to convert.
+ */
+jspb.BinaryEncoder.prototype.writeSignedVarint32 = function(value) {
+ goog.asserts.assert(value == Math.floor(value));
+ goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_31) &&
+ (value < jspb.BinaryConstants.TWO_TO_31));
+
+ // Use the unsigned version if the value is not negative.
+ if (value >= 0) {
+ this.writeUnsignedVarint32(value);
+ return;
+ }
+
+ // Write nine bytes with a _signed_ right shift so we preserve the sign bit.
+ for (var i = 0; i < 9; i++) {
+ this.buffer_.push((value & 0x7f) | 0x80);
+ value = value >> 7;
+ }
+
+ // The above loop writes out 63 bits, so the last byte is always the sign bit
+ // which is always set for negative numbers.
+ this.buffer_.push(1);
+};
+
+
+/**
+ * Encodes a 64-bit unsigned integer into its wire-format varint representation
+ * and stores it in the buffer. Integers that are not representable in 64 bits
+ * will be truncated.
+ * @param {number} value The integer to convert.
+ */
+jspb.BinaryEncoder.prototype.writeUnsignedVarint64 = function(value) {
+ goog.asserts.assert(value == Math.floor(value));
+ goog.asserts.assert((value >= 0) &&
+ (value < jspb.BinaryConstants.TWO_TO_64));
+ jspb.utils.splitInt64(value);
+ this.writeSplitVarint64(jspb.utils.split64Low,
+ jspb.utils.split64High);
+};
+
+
+/**
+ * Encodes a 64-bit signed integer into its wire-format varint representation
+ * and stores it in the buffer. Integers that are not representable in 64 bits
+ * will be truncated.
+ * @param {number} value The integer to convert.
+ */
+jspb.BinaryEncoder.prototype.writeSignedVarint64 = function(value) {
+ goog.asserts.assert(value == Math.floor(value));
+ goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_63) &&
+ (value < jspb.BinaryConstants.TWO_TO_63));
+ jspb.utils.splitInt64(value);
+ this.writeSplitVarint64(jspb.utils.split64Low,
+ jspb.utils.split64High);
+};
+
+
+/**
+ * Encodes a JavaScript integer into its wire-format, zigzag-encoded varint
+ * representation and stores it in the buffer.
+ * @param {number} value The integer to convert.
+ */
+jspb.BinaryEncoder.prototype.writeZigzagVarint32 = function(value) {
+ goog.asserts.assert(value == Math.floor(value));
+ goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_31) &&
+ (value < jspb.BinaryConstants.TWO_TO_31));
+ this.writeUnsignedVarint32(((value << 1) ^ (value >> 31)) >>> 0);
+};
+
+
+/**
+ * Encodes a JavaScript integer into its wire-format, zigzag-encoded varint
+ * representation and stores it in the buffer. Integers not representable in 64
+ * bits will be truncated.
+ * @param {number} value The integer to convert.
+ */
+jspb.BinaryEncoder.prototype.writeZigzagVarint64 = function(value) {
+ goog.asserts.assert(value == Math.floor(value));
+ goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_63) &&
+ (value < jspb.BinaryConstants.TWO_TO_63));
+ jspb.utils.splitZigzag64(value);
+ this.writeSplitVarint64(jspb.utils.split64Low,
+ jspb.utils.split64High);
+};
+
+
+/**
+ * Encodes a JavaScript decimal string into its wire-format, zigzag-encoded
+ * varint representation and stores it in the buffer. Integers not representable
+ * in 64 bits will be truncated.
+ * @param {string} value The integer to convert.
+ */
+jspb.BinaryEncoder.prototype.writeZigzagVarint64String = function(value) {
+ // TODO(haberman): write lossless 64-bit zig-zag math.
+ this.writeZigzagVarint64(parseInt(value, 10));
+};
+
+
+/**
+ * Writes a 8-bit unsigned integer to the buffer. Numbers outside the range
+ * [0,2^8) will be truncated.
+ * @param {number} value The value to write.
+ */
+jspb.BinaryEncoder.prototype.writeUint8 = function(value) {
+ goog.asserts.assert(value == Math.floor(value));
+ goog.asserts.assert((value >= 0) && (value < 256));
+ this.buffer_.push((value >>> 0) & 0xFF);
+};
+
+
+/**
+ * Writes a 16-bit unsigned integer to the buffer. Numbers outside the
+ * range [0,2^16) will be truncated.
+ * @param {number} value The value to write.
+ */
+jspb.BinaryEncoder.prototype.writeUint16 = function(value) {
+ goog.asserts.assert(value == Math.floor(value));
+ goog.asserts.assert((value >= 0) && (value < 65536));
+ this.buffer_.push((value >>> 0) & 0xFF);
+ this.buffer_.push((value >>> 8) & 0xFF);
+};
+
+
+/**
+ * Writes a 32-bit unsigned integer to the buffer. Numbers outside the
+ * range [0,2^32) will be truncated.
+ * @param {number} value The value to write.
+ */
+jspb.BinaryEncoder.prototype.writeUint32 = function(value) {
+ goog.asserts.assert(value == Math.floor(value));
+ goog.asserts.assert((value >= 0) &&
+ (value < jspb.BinaryConstants.TWO_TO_32));
+ this.buffer_.push((value >>> 0) & 0xFF);
+ this.buffer_.push((value >>> 8) & 0xFF);
+ this.buffer_.push((value >>> 16) & 0xFF);
+ this.buffer_.push((value >>> 24) & 0xFF);
+};
+
+
+/**
+ * Writes a 64-bit unsigned integer to the buffer. Numbers outside the
+ * range [0,2^64) will be truncated.
+ * @param {number} value The value to write.
+ */
+jspb.BinaryEncoder.prototype.writeUint64 = function(value) {
+ goog.asserts.assert(value == Math.floor(value));
+ goog.asserts.assert((value >= 0) &&
+ (value < jspb.BinaryConstants.TWO_TO_64));
+ jspb.utils.splitUint64(value);
+ this.writeUint32(jspb.utils.split64Low);
+ this.writeUint32(jspb.utils.split64High);
+};
+
+
+/**
+ * Writes a 8-bit integer to the buffer. Numbers outside the range
+ * [-2^7,2^7) will be truncated.
+ * @param {number} value The value to write.
+ */
+jspb.BinaryEncoder.prototype.writeInt8 = function(value) {
+ goog.asserts.assert(value == Math.floor(value));
+ goog.asserts.assert((value >= -128) && (value < 128));
+ this.buffer_.push((value >>> 0) & 0xFF);
+};
+
+
+/**
+ * Writes a 16-bit integer to the buffer. Numbers outside the range
+ * [-2^15,2^15) will be truncated.
+ * @param {number} value The value to write.
+ */
+jspb.BinaryEncoder.prototype.writeInt16 = function(value) {
+ goog.asserts.assert(value == Math.floor(value));
+ goog.asserts.assert((value >= -32768) && (value < 32768));
+ this.buffer_.push((value >>> 0) & 0xFF);
+ this.buffer_.push((value >>> 8) & 0xFF);
+};
+
+
+/**
+ * Writes a 32-bit integer to the buffer. Numbers outside the range
+ * [-2^31,2^31) will be truncated.
+ * @param {number} value The value to write.
+ */
+jspb.BinaryEncoder.prototype.writeInt32 = function(value) {
+ goog.asserts.assert(value == Math.floor(value));
+ goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_31) &&
+ (value < jspb.BinaryConstants.TWO_TO_31));
+ this.buffer_.push((value >>> 0) & 0xFF);
+ this.buffer_.push((value >>> 8) & 0xFF);
+ this.buffer_.push((value >>> 16) & 0xFF);
+ this.buffer_.push((value >>> 24) & 0xFF);
+};
+
+
+/**
+ * Writes a 64-bit integer to the buffer. Numbers outside the range
+ * [-2^63,2^63) will be truncated.
+ * @param {number} value The value to write.
+ */
+jspb.BinaryEncoder.prototype.writeInt64 = function(value) {
+ goog.asserts.assert(value == Math.floor(value));
+ goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_63) &&
+ (value < jspb.BinaryConstants.TWO_TO_63));
+ jspb.utils.splitInt64(value);
+ this.writeSplitFixed64(jspb.utils.split64Low, jspb.utils.split64High);
+};
+
+
+/**
+ * Writes a 64-bit integer decimal strings to the buffer. Numbers outside the
+ * range [-2^63,2^63) will be truncated.
+ * @param {string} value The value to write.
+ */
+jspb.BinaryEncoder.prototype.writeInt64String = function(value) {
+ goog.asserts.assert(value == Math.floor(value));
+ goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_63) &&
+ (value < jspb.BinaryConstants.TWO_TO_63));
+ jspb.utils.splitHash64(jspb.utils.decimalStringToHash64(value));
+ this.writeSplitFixed64(jspb.utils.split64Low, jspb.utils.split64High);
+};
+
+
+/**
+ * Writes a single-precision floating point value to the buffer. Numbers
+ * requiring more than 32 bits of precision will be truncated.
+ * @param {number} value The value to write.
+ */
+jspb.BinaryEncoder.prototype.writeFloat = function(value) {
+ goog.asserts.assert((value >= -jspb.BinaryConstants.FLOAT32_MAX) &&
+ (value <= jspb.BinaryConstants.FLOAT32_MAX));
+ jspb.utils.splitFloat32(value);
+ this.writeUint32(jspb.utils.split64Low);
+};
+
+
+/**
+ * Writes a double-precision floating point value to the buffer. As this is
+ * the native format used by JavaScript, no precision will be lost.
+ * @param {number} value The value to write.
+ */
+jspb.BinaryEncoder.prototype.writeDouble = function(value) {
+ goog.asserts.assert((value >= -jspb.BinaryConstants.FLOAT64_MAX) &&
+ (value <= jspb.BinaryConstants.FLOAT64_MAX));
+ jspb.utils.splitFloat64(value);
+ this.writeUint32(jspb.utils.split64Low);
+ this.writeUint32(jspb.utils.split64High);
+};
+
+
+/**
+ * Writes a boolean value to the buffer as a varint.
+ * @param {boolean} value The value to write.
+ */
+jspb.BinaryEncoder.prototype.writeBool = function(value) {
+ goog.asserts.assert(goog.isBoolean(value));
+ this.buffer_.push(value ? 1 : 0);
+};
+
+
+/**
+ * Writes an enum value to the buffer as a varint.
+ * @param {number} value The value to write.
+ */
+jspb.BinaryEncoder.prototype.writeEnum = function(value) {
+ goog.asserts.assert(value == Math.floor(value));
+ goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_31) &&
+ (value < jspb.BinaryConstants.TWO_TO_31));
+ this.writeSignedVarint32(value);
+};
+
+
+/**
+ * Writes an arbitrary byte array to the buffer.
+ * @param {!Uint8Array} bytes The array of bytes to write.
+ */
+jspb.BinaryEncoder.prototype.writeBytes = function(bytes) {
+ this.buffer_.push.apply(this.buffer_, bytes);
+};
+
+
+/**
+ * Writes a 64-bit hash string (8 characters @ 8 bits of data each) to the
+ * buffer as a varint.
+ * @param {string} hash The hash to write.
+ */
+jspb.BinaryEncoder.prototype.writeVarintHash64 = function(hash) {
+ jspb.utils.splitHash64(hash);
+ this.writeSplitVarint64(jspb.utils.split64Low,
+ jspb.utils.split64High);
+};
+
+
+/**
+ * Writes a 64-bit hash string (8 characters @ 8 bits of data each) to the
+ * buffer as a fixed64.
+ * @param {string} hash The hash to write.
+ */
+jspb.BinaryEncoder.prototype.writeFixedHash64 = function(hash) {
+ jspb.utils.splitHash64(hash);
+ this.writeUint32(jspb.utils.split64Low);
+ this.writeUint32(jspb.utils.split64High);
+};
+
+
+/**
+ * Writes a UTF16 Javascript string to the buffer encoded as UTF8.
+ * TODO(aappleby): Add support for surrogate pairs, reject unpaired surrogates.
+ * @param {string} value The string to write.
+ * @return {number} The number of bytes used to encode the string.
+ */
+jspb.BinaryEncoder.prototype.writeString = function(value) {
+ var oldLength = this.buffer_.length;
+
+ for (var i = 0; i < value.length; i++) {
+
+ var c = value.charCodeAt(i);
+
+ if (c < 128) {
+ this.buffer_.push(c);
+ } else if (c < 2048) {
+ this.buffer_.push((c >> 6) | 192);
+ this.buffer_.push((c & 63) | 128);
+ } else if (c < 65536) {
+ // Look for surrogates
+ if (c >= 0xD800 && c <= 0xDBFF && i + 1 < value.length) {
+ var second = value.charCodeAt(i + 1);
+ if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate
+ // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
+ c = (c - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
+
+ this.buffer_.push((c >> 18) | 240);
+ this.buffer_.push(((c >> 12) & 63 ) | 128);
+ this.buffer_.push(((c >> 6) & 63) | 128);
+ this.buffer_.push((c & 63) | 128);
+ i++;
+ }
+ }
+ else {
+ this.buffer_.push((c >> 12) | 224);
+ this.buffer_.push(((c >> 6) & 63) | 128);
+ this.buffer_.push((c & 63) | 128);
+ }
+ }
+ }
+
+ var length = this.buffer_.length - oldLength;
+ return length;
+};
diff --git a/third_party/protobuf/js/binary/message_test.js b/third_party/protobuf/js/binary/message_test.js
new file mode 100644
index 0000000000..4edc666b88
--- /dev/null
+++ b/third_party/protobuf/js/binary/message_test.js
@@ -0,0 +1,60 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Test suite is written using Jasmine -- see http://jasmine.github.io/
+
+goog.setTestOnly();
+
+goog.require('goog.testing.asserts');
+
+// CommonJS-LoadFromFile: test_pb proto.jspb.test
+goog.require('proto.jspb.test.Deeply.Nested.Message');
+
+// CommonJS-LoadFromFile: test2_pb proto.jspb.test
+goog.require('proto.jspb.test.ForeignNestedFieldMessage');
+
+describe('Message test suite', function() {
+ // Verify that we can successfully use a field referring to a nested message
+ // from a different .proto file.
+ it('testForeignNestedMessage', function() {
+ var msg = new proto.jspb.test.ForeignNestedFieldMessage();
+ var nested = new proto.jspb.test.Deeply.Nested.Message();
+ nested.setCount(5);
+ msg.setDeeplyNestedMessage(nested);
+ assertEquals(5, msg.getDeeplyNestedMessage().getCount());
+
+ // After a serialization-deserialization round trip we should get back the
+ // same data we started with.
+ var serialized = msg.serializeBinary();
+ var deserialized =
+ proto.jspb.test.ForeignNestedFieldMessage.deserializeBinary(serialized);
+ assertEquals(5, deserialized.getDeeplyNestedMessage().getCount());
+ });
+});
diff --git a/third_party/protobuf/js/binary/proto_test.js b/third_party/protobuf/js/binary/proto_test.js
new file mode 100644
index 0000000000..f5e1b6bbf0
--- /dev/null
+++ b/third_party/protobuf/js/binary/proto_test.js
@@ -0,0 +1,663 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Test suite is written using Jasmine -- see http://jasmine.github.io/
+
+goog.require('goog.crypt.base64');
+goog.require('goog.testing.asserts');
+goog.require('jspb.BinaryWriter');
+goog.require('jspb.Message');
+
+// CommonJS-LoadFromFile: ../testbinary_pb proto.jspb.test
+goog.require('proto.jspb.test.ExtendsWithMessage');
+goog.require('proto.jspb.test.ForeignEnum');
+goog.require('proto.jspb.test.ForeignMessage');
+goog.require('proto.jspb.test.TestAllTypes');
+goog.require('proto.jspb.test.TestExtendable');
+goog.require('proto.jspb.test.extendOptionalBool');
+goog.require('proto.jspb.test.extendOptionalBytes');
+goog.require('proto.jspb.test.extendOptionalDouble');
+goog.require('proto.jspb.test.extendOptionalFixed32');
+goog.require('proto.jspb.test.extendOptionalFixed64');
+goog.require('proto.jspb.test.extendOptionalFloat');
+goog.require('proto.jspb.test.extendOptionalForeignEnum');
+goog.require('proto.jspb.test.extendOptionalInt32');
+goog.require('proto.jspb.test.extendOptionalInt64');
+goog.require('proto.jspb.test.extendOptionalSfixed32');
+goog.require('proto.jspb.test.extendOptionalSfixed64');
+goog.require('proto.jspb.test.extendOptionalSint32');
+goog.require('proto.jspb.test.extendOptionalSint64');
+goog.require('proto.jspb.test.extendOptionalString');
+goog.require('proto.jspb.test.extendOptionalUint32');
+goog.require('proto.jspb.test.extendOptionalUint64');
+goog.require('proto.jspb.test.extendPackedRepeatedBoolList');
+goog.require('proto.jspb.test.extendPackedRepeatedDoubleList');
+goog.require('proto.jspb.test.extendPackedRepeatedFixed32List');
+goog.require('proto.jspb.test.extendPackedRepeatedFixed64List');
+goog.require('proto.jspb.test.extendPackedRepeatedFloatList');
+goog.require('proto.jspb.test.extendPackedRepeatedForeignEnumList');
+goog.require('proto.jspb.test.extendPackedRepeatedInt32List');
+goog.require('proto.jspb.test.extendPackedRepeatedInt64List');
+goog.require('proto.jspb.test.extendPackedRepeatedSfixed32List');
+goog.require('proto.jspb.test.extendPackedRepeatedSfixed64List');
+goog.require('proto.jspb.test.extendPackedRepeatedSint32List');
+goog.require('proto.jspb.test.extendPackedRepeatedSint64List');
+goog.require('proto.jspb.test.extendPackedRepeatedUint32List');
+goog.require('proto.jspb.test.extendPackedRepeatedUint64List');
+goog.require('proto.jspb.test.extendRepeatedBoolList');
+goog.require('proto.jspb.test.extendRepeatedBytesList');
+goog.require('proto.jspb.test.extendRepeatedDoubleList');
+goog.require('proto.jspb.test.extendRepeatedFixed32List');
+goog.require('proto.jspb.test.extendRepeatedFixed64List');
+goog.require('proto.jspb.test.extendRepeatedFloatList');
+goog.require('proto.jspb.test.extendRepeatedForeignEnumList');
+goog.require('proto.jspb.test.extendRepeatedInt32List');
+goog.require('proto.jspb.test.extendRepeatedInt64List');
+goog.require('proto.jspb.test.extendRepeatedSfixed32List');
+goog.require('proto.jspb.test.extendRepeatedSfixed64List');
+goog.require('proto.jspb.test.extendRepeatedSint32List');
+goog.require('proto.jspb.test.extendRepeatedSint64List');
+goog.require('proto.jspb.test.extendRepeatedStringList');
+goog.require('proto.jspb.test.extendRepeatedUint32List');
+goog.require('proto.jspb.test.extendRepeatedUint64List');
+
+// CommonJS-LoadFromFile: ../node_modules/google-protobuf/google/protobuf/any_pb proto.google.protobuf
+goog.require('proto.google.protobuf.Any');
+
+
+var suite = {};
+
+var BYTES = new Uint8Array([1, 2, 8, 9]);
+
+var BYTES_B64 = goog.crypt.base64.encodeByteArray(BYTES);
+
+
+/**
+ * Helper: fill all fields on a TestAllTypes message.
+ * @param {proto.jspb.test.TestAllTypes} msg
+ */
+function fillAllFields(msg) {
+ msg.setOptionalInt32(-42);
+ // can be exactly represented by JS number (64-bit double, i.e., 52-bit
+ // mantissa).
+ msg.setOptionalInt64(-0x7fffffff00000000);
+ msg.setOptionalUint32(0x80000000);
+ msg.setOptionalUint64(0xf000000000000000);
+ msg.setOptionalSint32(-100);
+ msg.setOptionalSint64(-0x8000000000000000);
+ msg.setOptionalFixed32(1234);
+ msg.setOptionalFixed64(0x1234567800000000);
+ msg.setOptionalSfixed32(-1234);
+ msg.setOptionalSfixed64(-0x1234567800000000);
+ msg.setOptionalFloat(1.5);
+ msg.setOptionalDouble(-1.5);
+ msg.setOptionalBool(true);
+ msg.setOptionalString('hello world');
+ msg.setOptionalBytes(BYTES);
+ msg.setOptionalGroup(new proto.jspb.test.TestAllTypes.OptionalGroup());
+ msg.getOptionalGroup().setA(100);
+ var submsg = new proto.jspb.test.ForeignMessage();
+ submsg.setC(16);
+ msg.setOptionalForeignMessage(submsg);
+ msg.setOptionalForeignEnum(proto.jspb.test.ForeignEnum.FOREIGN_FOO);
+ msg.setOneofString('oneof');
+
+
+ msg.setRepeatedInt32List([-42]);
+ msg.setRepeatedInt64List([-0x7fffffff00000000]);
+ msg.setRepeatedUint32List([0x80000000]);
+ msg.setRepeatedUint64List([0xf000000000000000]);
+ msg.setRepeatedSint32List([-100]);
+ msg.setRepeatedSint64List([-0x8000000000000000]);
+ msg.setRepeatedFixed32List([1234]);
+ msg.setRepeatedFixed64List([0x1234567800000000]);
+ msg.setRepeatedSfixed32List([-1234]);
+ msg.setRepeatedSfixed64List([-0x1234567800000000]);
+ msg.setRepeatedFloatList([1.5]);
+ msg.setRepeatedDoubleList([-1.5]);
+ msg.setRepeatedBoolList([true]);
+ msg.setRepeatedStringList(['hello world']);
+ msg.setRepeatedBytesList([BYTES, BYTES]);
+ msg.setRepeatedGroupList([new proto.jspb.test.TestAllTypes.RepeatedGroup()]);
+ msg.getRepeatedGroupList()[0].setA(100);
+ submsg = new proto.jspb.test.ForeignMessage();
+ submsg.setC(1000);
+ msg.setRepeatedForeignMessageList([submsg]);
+ msg.setRepeatedForeignEnumList([proto.jspb.test.ForeignEnum.FOREIGN_FOO]);
+
+ msg.setPackedRepeatedInt32List([-42]);
+ msg.setPackedRepeatedInt64List([-0x7fffffff00000000]);
+ msg.setPackedRepeatedUint32List([0x80000000]);
+ msg.setPackedRepeatedUint64List([0xf000000000000000]);
+ msg.setPackedRepeatedSint32List([-100]);
+ msg.setPackedRepeatedSint64List([-0x8000000000000000]);
+ msg.setPackedRepeatedFixed32List([1234]);
+ msg.setPackedRepeatedFixed64List([0x1234567800000000]);
+ msg.setPackedRepeatedSfixed32List([-1234]);
+ msg.setPackedRepeatedSfixed64List([-0x1234567800000000]);
+ msg.setPackedRepeatedFloatList([1.5]);
+ msg.setPackedRepeatedDoubleList([-1.5]);
+ msg.setPackedRepeatedBoolList([true]);
+
+}
+
+
+/**
+ * Helper: compare a bytes field to an expected value
+ * @param {Uint8Array|string} arr
+ * @param {Uint8Array} expected
+ * @return {boolean}
+ */
+function bytesCompare(arr, expected) {
+ if (goog.isString(arr)) {
+ arr = goog.crypt.base64.decodeStringToUint8Array(arr);
+ }
+ if (arr.length != expected.length) {
+ return false;
+ }
+ for (var i = 0; i < arr.length; i++) {
+ if (arr[i] != expected[i]) {
+ return false;
+ }
+ }
+ return true;
+}
+
+
+/**
+ * Helper: verify contents of given TestAllTypes message as set by
+ * fillAllFields().
+ * @param {proto.jspb.test.TestAllTypes} original
+ * @param {proto.jspb.test.TestAllTypes} copy
+ */
+function checkAllFields(original, copy) {
+ assertEquals(copy.getOptionalInt32(), -42);
+ assertEquals(copy.getOptionalInt64(), -0x7fffffff00000000);
+ assertEquals(copy.getOptionalUint32(), 0x80000000);
+ assertEquals(copy.getOptionalUint64(), 0xf000000000000000);
+ assertEquals(copy.getOptionalSint32(), -100);
+ assertEquals(copy.getOptionalSint64(), -0x8000000000000000);
+ assertEquals(copy.getOptionalFixed32(), 1234);
+ assertEquals(copy.getOptionalFixed64(), 0x1234567800000000);
+ assertEquals(copy.getOptionalSfixed32(), -1234);
+ assertEquals(copy.getOptionalSfixed64(), -0x1234567800000000);
+ assertEquals(copy.getOptionalFloat(), 1.5);
+ assertEquals(copy.getOptionalDouble(), -1.5);
+ assertEquals(copy.getOptionalBool(), true);
+ assertEquals(copy.getOptionalString(), 'hello world');
+ assertEquals(true, bytesCompare(copy.getOptionalBytes(), BYTES));
+ assertEquals(true, bytesCompare(copy.getOptionalBytes_asU8(), BYTES));
+ assertEquals(
+ copy.getOptionalBytes_asB64(), goog.crypt.base64.encodeByteArray(BYTES));
+
+ assertEquals(copy.getOptionalGroup().getA(), 100);
+ assertEquals(copy.getOptionalForeignMessage().getC(), 16);
+ assertEquals(copy.getOptionalForeignEnum(),
+ proto.jspb.test.ForeignEnum.FOREIGN_FOO);
+
+
+ assertEquals(copy.getOneofString(), 'oneof');
+ assertEquals(copy.getOneofFieldCase(),
+ proto.jspb.test.TestAllTypes.OneofFieldCase.ONEOF_STRING);
+
+ assertElementsEquals(copy.getRepeatedInt32List(), [-42]);
+ assertElementsEquals(copy.getRepeatedInt64List(), [-0x7fffffff00000000]);
+ assertElementsEquals(copy.getRepeatedUint32List(), [0x80000000]);
+ assertElementsEquals(copy.getRepeatedUint64List(), [0xf000000000000000]);
+ assertElementsEquals(copy.getRepeatedSint32List(), [-100]);
+ assertElementsEquals(copy.getRepeatedSint64List(), [-0x8000000000000000]);
+ assertElementsEquals(copy.getRepeatedFixed32List(), [1234]);
+ assertElementsEquals(copy.getRepeatedFixed64List(), [0x1234567800000000]);
+ assertElementsEquals(copy.getRepeatedSfixed32List(), [-1234]);
+ assertElementsEquals(copy.getRepeatedSfixed64List(), [-0x1234567800000000]);
+ assertElementsEquals(copy.getRepeatedFloatList(), [1.5]);
+ assertElementsEquals(copy.getRepeatedDoubleList(), [-1.5]);
+ assertElementsEquals(copy.getRepeatedBoolList(), [true]);
+ assertElementsEquals(copy.getRepeatedStringList(), ['hello world']);
+ assertEquals(copy.getRepeatedBytesList().length, 2);
+ assertEquals(true, bytesCompare(copy.getRepeatedBytesList_asU8()[0], BYTES));
+ assertEquals(true, bytesCompare(copy.getRepeatedBytesList()[0], BYTES));
+ assertEquals(true, bytesCompare(copy.getRepeatedBytesList_asU8()[1], BYTES));
+ assertEquals(copy.getRepeatedBytesList_asB64()[0], BYTES_B64);
+ assertEquals(copy.getRepeatedBytesList_asB64()[1], BYTES_B64);
+ assertEquals(copy.getRepeatedGroupList().length, 1);
+ assertEquals(copy.getRepeatedGroupList()[0].getA(), 100);
+ assertEquals(copy.getRepeatedForeignMessageList().length, 1);
+ assertEquals(copy.getRepeatedForeignMessageList()[0].getC(), 1000);
+ assertElementsEquals(copy.getRepeatedForeignEnumList(),
+ [proto.jspb.test.ForeignEnum.FOREIGN_FOO]);
+
+ assertElementsEquals(copy.getPackedRepeatedInt32List(), [-42]);
+ assertElementsEquals(copy.getPackedRepeatedInt64List(),
+ [-0x7fffffff00000000]);
+ assertElementsEquals(copy.getPackedRepeatedUint32List(), [0x80000000]);
+ assertElementsEquals(copy.getPackedRepeatedUint64List(),
+ [0xf000000000000000]);
+ assertElementsEquals(copy.getPackedRepeatedSint32List(), [-100]);
+ assertElementsEquals(copy.getPackedRepeatedSint64List(),
+ [-0x8000000000000000]);
+ assertElementsEquals(copy.getPackedRepeatedFixed32List(), [1234]);
+ assertElementsEquals(copy.getPackedRepeatedFixed64List(),
+ [0x1234567800000000]);
+ assertElementsEquals(copy.getPackedRepeatedSfixed32List(), [-1234]);
+ assertElementsEquals(copy.getPackedRepeatedSfixed64List(),
+ [-0x1234567800000000]);
+ assertElementsEquals(copy.getPackedRepeatedFloatList(), [1.5]);
+ assertElementsEquals(copy.getPackedRepeatedDoubleList(), [-1.5]);
+
+
+ // Check last so we get more granular errors first.
+ assertTrue(jspb.Message.equals(original, copy));
+}
+
+
+/**
+ * Helper: verify that all expected extensions are present.
+ * @param {!proto.jspb.test.TestExtendable} msg
+ */
+function checkExtensions(msg) {
+ assertEquals(0, msg.getExtension(proto.jspb.test.extendOptionalInt32));
+ assertEquals(-0x7fffffff00000000,
+ msg.getExtension(proto.jspb.test.extendOptionalInt64));
+ assertEquals(0x80000000,
+ msg.getExtension(proto.jspb.test.extendOptionalUint32));
+ assertEquals(0xf000000000000000,
+ msg.getExtension(proto.jspb.test.extendOptionalUint64));
+ assertEquals(-100,
+ msg.getExtension(proto.jspb.test.extendOptionalSint32));
+ assertEquals(-0x8000000000000000,
+ msg.getExtension(proto.jspb.test.extendOptionalSint64));
+ assertEquals(1234,
+ msg.getExtension(proto.jspb.test.extendOptionalFixed32));
+ assertEquals(0x1234567800000000,
+ msg.getExtension(proto.jspb.test.extendOptionalFixed64));
+ assertEquals(-1234,
+ msg.getExtension(proto.jspb.test.extendOptionalSfixed32));
+ assertEquals(-0x1234567800000000,
+ msg.getExtension(proto.jspb.test.extendOptionalSfixed64));
+ assertEquals(1.5,
+ msg.getExtension(proto.jspb.test.extendOptionalFloat));
+ assertEquals(-1.5,
+ msg.getExtension(proto.jspb.test.extendOptionalDouble));
+ assertEquals(true,
+ msg.getExtension(proto.jspb.test.extendOptionalBool));
+ assertEquals('hello world',
+ msg.getExtension(proto.jspb.test.extendOptionalString));
+ assertEquals(
+ true, bytesCompare(
+ msg.getExtension(proto.jspb.test.extendOptionalBytes), BYTES));
+ assertEquals(16,
+ msg.getExtension(
+ proto.jspb.test.ExtendsWithMessage.optionalExtension).getFoo());
+
+
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendRepeatedInt32List),
+ [-42]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendRepeatedInt64List),
+ [-0x7fffffff00000000]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendRepeatedUint32List),
+ [0x80000000]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendRepeatedUint64List),
+ [0xf000000000000000]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendRepeatedSint32List),
+ [-100]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendRepeatedSint64List),
+ [-0x8000000000000000]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendRepeatedFixed32List),
+ [1234]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendRepeatedFixed64List),
+ [0x1234567800000000]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendRepeatedSfixed32List),
+ [-1234]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendRepeatedSfixed64List),
+ [-0x1234567800000000]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendRepeatedFloatList),
+ [1.5]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendRepeatedDoubleList),
+ [-1.5]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendRepeatedBoolList),
+ [true]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendRepeatedStringList),
+ ['hello world']);
+ assertEquals(
+ true,
+ bytesCompare(
+ msg.getExtension(proto.jspb.test.extendRepeatedBytesList)[0], BYTES));
+ assertEquals(1000,
+ msg.getExtension(
+ proto.jspb.test.ExtendsWithMessage.repeatedExtensionList)[0]
+ .getFoo());
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendRepeatedForeignEnumList),
+ [proto.jspb.test.ForeignEnum.FOREIGN_FOO]);
+
+
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendPackedRepeatedInt32List),
+ [-42]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendPackedRepeatedInt64List),
+ [-0x7fffffff00000000]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendPackedRepeatedUint32List),
+ [0x80000000]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendPackedRepeatedUint64List),
+ [0xf000000000000000]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendPackedRepeatedSint32List),
+ [-100]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendPackedRepeatedSint64List),
+ [-0x8000000000000000]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendPackedRepeatedFixed32List),
+ [1234]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendPackedRepeatedFixed64List),
+ [0x1234567800000000]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendPackedRepeatedSfixed32List),
+ [-1234]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendPackedRepeatedSfixed64List),
+ [-0x1234567800000000]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendPackedRepeatedFloatList),
+ [1.5]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendPackedRepeatedDoubleList),
+ [-1.5]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendPackedRepeatedBoolList),
+ [true]);
+ assertElementsEquals(
+ msg.getExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList),
+ [proto.jspb.test.ForeignEnum.FOREIGN_FOO]);
+
+}
+
+
+describe('protoBinaryTest', function() {
+ /**
+ * Tests a basic serialization-deserializaton round-trip with all supported
+ * field types (on the TestAllTypes message type).
+ */
+ it('testRoundTrip', function() {
+ var msg = new proto.jspb.test.TestAllTypes();
+ fillAllFields(msg);
+ var encoded = msg.serializeBinary();
+ var decoded = proto.jspb.test.TestAllTypes.deserializeBinary(encoded);
+ checkAllFields(msg, decoded);
+ });
+
+ /**
+ * Test that base64 string and Uint8Array are interchangeable in bytes fields.
+ */
+ it('testBytesFieldsGettersInterop', function() {
+ var msg = new proto.jspb.test.TestAllTypes();
+ // Set from a base64 string and check all the getters work.
+ msg.setOptionalBytes(BYTES_B64);
+ assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES));
+ assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES));
+ assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));
+
+ // Test binary serialize round trip doesn't break it.
+ msg = proto.jspb.test.TestAllTypes.deserializeBinary(msg.serializeBinary());
+ assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES));
+ assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES));
+ assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));
+
+ msg = new proto.jspb.test.TestAllTypes();
+ // Set from a Uint8Array and check all the getters work.
+ msg.setOptionalBytes(BYTES);
+ assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES));
+ assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES));
+ assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));
+
+ });
+
+ /**
+ * Test that bytes setters will receive result of any of the getters.
+ */
+ it('testBytesFieldsSettersInterop', function() {
+ var msg = new proto.jspb.test.TestAllTypes();
+ msg.setOptionalBytes(BYTES);
+ assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));
+
+ msg.setOptionalBytes(msg.getOptionalBytes());
+ assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));
+ msg.setOptionalBytes(msg.getOptionalBytes_asB64());
+ assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));
+ msg.setOptionalBytes(msg.getOptionalBytes_asU8());
+ assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));
+ });
+
+ /**
+ * Test that bytes setters will receive result of any of the getters.
+ */
+ it('testRepeatedBytesGetters', function() {
+ var msg = new proto.jspb.test.TestAllTypes();
+
+ function assertGetters() {
+ assertTrue(goog.isString(msg.getRepeatedBytesList_asB64()[0]));
+ assertTrue(goog.isString(msg.getRepeatedBytesList_asB64()[1]));
+ assertTrue(msg.getRepeatedBytesList_asU8()[0] instanceof Uint8Array);
+ assertTrue(msg.getRepeatedBytesList_asU8()[1] instanceof Uint8Array);
+
+ assertTrue(bytesCompare(msg.getRepeatedBytesList()[0], BYTES));
+ assertTrue(bytesCompare(msg.getRepeatedBytesList()[1], BYTES));
+ assertTrue(bytesCompare(msg.getRepeatedBytesList_asB64()[0], BYTES));
+ assertTrue(bytesCompare(msg.getRepeatedBytesList_asB64()[1], BYTES));
+ assertTrue(bytesCompare(msg.getRepeatedBytesList_asU8()[0], BYTES));
+ assertTrue(bytesCompare(msg.getRepeatedBytesList_asU8()[1], BYTES));
+ }
+
+ msg.setRepeatedBytesList([BYTES, BYTES]);
+ assertGetters();
+
+ msg.setRepeatedBytesList([BYTES_B64, BYTES_B64]);
+ assertGetters();
+
+ msg.setRepeatedBytesList([]);
+ assertEquals(0, msg.getRepeatedBytesList().length);
+ assertEquals(0, msg.getRepeatedBytesList_asB64().length);
+ assertEquals(0, msg.getRepeatedBytesList_asU8().length);
+ });
+
+ /**
+ * Helper: fill all extension values.
+ * @param {proto.jspb.test.TestExtendable} msg
+ */
+ function fillExtensions(msg) {
+ msg.setExtension(proto.jspb.test.extendOptionalInt32, 0);
+ msg.setExtension(
+ proto.jspb.test.extendOptionalInt64, -0x7fffffff00000000);
+ msg.setExtension(
+ proto.jspb.test.extendOptionalUint32, 0x80000000);
+ msg.setExtension(
+ proto.jspb.test.extendOptionalUint64, 0xf000000000000000);
+ msg.setExtension(
+ proto.jspb.test.extendOptionalSint32, -100);
+ msg.setExtension(
+ proto.jspb.test.extendOptionalSint64, -0x8000000000000000);
+ msg.setExtension(
+ proto.jspb.test.extendOptionalFixed32, 1234);
+ msg.setExtension(
+ proto.jspb.test.extendOptionalFixed64, 0x1234567800000000);
+ msg.setExtension(
+ proto.jspb.test.extendOptionalSfixed32, -1234);
+ msg.setExtension(
+ proto.jspb.test.extendOptionalSfixed64, -0x1234567800000000);
+ msg.setExtension(
+ proto.jspb.test.extendOptionalFloat, 1.5);
+ msg.setExtension(
+ proto.jspb.test.extendOptionalDouble, -1.5);
+ msg.setExtension(
+ proto.jspb.test.extendOptionalBool, true);
+ msg.setExtension(
+ proto.jspb.test.extendOptionalString, 'hello world');
+ msg.setExtension(proto.jspb.test.extendOptionalBytes, BYTES);
+ var submsg = new proto.jspb.test.ExtendsWithMessage();
+ submsg.setFoo(16);
+ msg.setExtension(
+ proto.jspb.test.ExtendsWithMessage.optionalExtension, submsg);
+ msg.setExtension(
+ proto.jspb.test.extendOptionalForeignEnum,
+ proto.jspb.test.ForeignEnum.FOREIGN_FOO);
+
+
+ msg.setExtension(
+ proto.jspb.test.extendRepeatedInt32List, [-42]);
+ msg.setExtension(
+ proto.jspb.test.extendRepeatedInt64List, [-0x7fffffff00000000]);
+ msg.setExtension(
+ proto.jspb.test.extendRepeatedUint32List, [0x80000000]);
+ msg.setExtension(
+ proto.jspb.test.extendRepeatedUint64List, [0xf000000000000000]);
+ msg.setExtension(
+ proto.jspb.test.extendRepeatedSint32List, [-100]);
+ msg.setExtension(
+ proto.jspb.test.extendRepeatedSint64List, [-0x8000000000000000]);
+ msg.setExtension(
+ proto.jspb.test.extendRepeatedFixed32List, [1234]);
+ msg.setExtension(
+ proto.jspb.test.extendRepeatedFixed64List, [0x1234567800000000]);
+ msg.setExtension(
+ proto.jspb.test.extendRepeatedSfixed32List, [-1234]);
+ msg.setExtension(
+ proto.jspb.test.extendRepeatedSfixed64List, [-0x1234567800000000]);
+ msg.setExtension(
+ proto.jspb.test.extendRepeatedFloatList, [1.5]);
+ msg.setExtension(
+ proto.jspb.test.extendRepeatedDoubleList, [-1.5]);
+ msg.setExtension(
+ proto.jspb.test.extendRepeatedBoolList, [true]);
+ msg.setExtension(
+ proto.jspb.test.extendRepeatedStringList, ['hello world']);
+ msg.setExtension(proto.jspb.test.extendRepeatedBytesList, [BYTES]);
+ submsg = new proto.jspb.test.ExtendsWithMessage();
+ submsg.setFoo(1000);
+ msg.setExtension(
+ proto.jspb.test.ExtendsWithMessage.repeatedExtensionList, [submsg]);
+ msg.setExtension(proto.jspb.test.extendRepeatedForeignEnumList,
+ [proto.jspb.test.ForeignEnum.FOREIGN_FOO]);
+
+
+ msg.setExtension(
+ proto.jspb.test.extendPackedRepeatedInt32List, [-42]);
+ msg.setExtension(
+ proto.jspb.test.extendPackedRepeatedInt64List, [-0x7fffffff00000000]);
+ msg.setExtension(
+ proto.jspb.test.extendPackedRepeatedUint32List, [0x80000000]);
+ msg.setExtension(
+ proto.jspb.test.extendPackedRepeatedUint64List, [0xf000000000000000]);
+ msg.setExtension(
+ proto.jspb.test.extendPackedRepeatedSint32List, [-100]);
+ msg.setExtension(
+ proto.jspb.test.extendPackedRepeatedSint64List, [-0x8000000000000000]);
+ msg.setExtension(
+ proto.jspb.test.extendPackedRepeatedFixed32List, [1234]);
+ msg.setExtension(
+ proto.jspb.test.extendPackedRepeatedFixed64List, [0x1234567800000000]);
+ msg.setExtension(
+ proto.jspb.test.extendPackedRepeatedSfixed32List, [-1234]);
+ msg.setExtension(
+ proto.jspb.test.extendPackedRepeatedSfixed64List,
+ [-0x1234567800000000]);
+ msg.setExtension(
+ proto.jspb.test.extendPackedRepeatedFloatList, [1.5]);
+ msg.setExtension(
+ proto.jspb.test.extendPackedRepeatedDoubleList, [-1.5]);
+ msg.setExtension(
+ proto.jspb.test.extendPackedRepeatedBoolList, [true]);
+ msg.setExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList,
+ [proto.jspb.test.ForeignEnum.FOREIGN_FOO]);
+
+ }
+
+
+ /**
+ * Tests extension serialization and deserialization.
+ */
+ it('testExtensions', function() {
+ var msg = new proto.jspb.test.TestExtendable();
+ fillExtensions(msg);
+ var encoded = msg.serializeBinary();
+ var decoded = proto.jspb.test.TestExtendable.deserializeBinary(encoded);
+ checkExtensions(decoded);
+ });
+
+ /**
+ * Tests that unknown extensions don't cause deserialization failure.
+ */
+ it('testUnknownExtension', function() {
+ var msg = new proto.jspb.test.TestExtendable();
+ fillExtensions(msg);
+ var writer = new jspb.BinaryWriter();
+ writer.writeBool((1 << 29) - 1, true);
+ proto.jspb.test.TestExtendable.serializeBinaryToWriter(msg, writer);
+ var encoded = writer.getResultBuffer();
+ var decoded = proto.jspb.test.TestExtendable.deserializeBinary(encoded);
+ checkExtensions(decoded);
+ });
+
+ it('testAnyWellKnownType', function() {
+ var any = new proto.google.protobuf.Any();
+ var msg = new proto.jspb.test.TestAllTypes();
+
+ fillAllFields(msg);
+
+ any.pack(msg.serializeBinary(), 'jspb.test.TestAllTypes');
+
+ assertEquals('type.googleapis.com/jspb.test.TestAllTypes',
+ any.getTypeUrl());
+
+ var msg2 = any.unpack(
+ proto.jspb.test.TestAllTypes.deserializeBinary,
+ 'jspb.test.TestAllTypes');
+
+ checkAllFields(msg, msg2);
+ });
+});
diff --git a/third_party/protobuf/js/binary/reader.js b/third_party/protobuf/js/binary/reader.js
new file mode 100644
index 0000000000..8c5a4e88db
--- /dev/null
+++ b/third_party/protobuf/js/binary/reader.js
@@ -0,0 +1,1219 @@
+// 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.
+
+/**
+ * @fileoverview This file contains utilities for converting binary,
+ * wire-format protocol buffers into Javascript data structures.
+ *
+ * jspb's BinaryReader class wraps the BinaryDecoder class to add methods
+ * that understand the protocol buffer syntax and can do the type checking and
+ * bookkeeping necessary to parse trees of nested messages.
+ *
+ * Major caveat - Users of this library _must_ keep their Javascript proto
+ * parsing code in sync with the original .proto file - presumably you'll be
+ * using the typed jspb code generator, but if you bypass that you'll need
+ * to keep things in sync by hand.
+ *
+ * @author aappleby@google.com (Austin Appleby)
+ */
+
+goog.provide('jspb.BinaryReader');
+
+goog.require('goog.asserts');
+goog.require('jspb.BinaryConstants');
+goog.require('jspb.BinaryDecoder');
+
+
+
+/**
+ * BinaryReader implements the decoders for all the wire types specified in
+ * https://developers.google.com/protocol-buffers/docs/encoding.
+ *
+ * @param {jspb.ByteSource=} opt_bytes The bytes we're reading from.
+ * @param {number=} opt_start The optional offset to start reading at.
+ * @param {number=} opt_length The optional length of the block to read -
+ * we'll throw an assertion if we go off the end of the block.
+ * @constructor
+ * @struct
+ */
+jspb.BinaryReader = function(opt_bytes, opt_start, opt_length) {
+ /**
+ * Wire-format decoder.
+ * @private {!jspb.BinaryDecoder}
+ */
+ this.decoder_ = jspb.BinaryDecoder.alloc(opt_bytes, opt_start, opt_length);
+
+ /**
+ * Cursor immediately before the field tag.
+ * @private {number}
+ */
+ this.fieldCursor_ = this.decoder_.getCursor();
+
+ /**
+ * Field number of the next field in the buffer, filled in by nextField().
+ * @private {number}
+ */
+ this.nextField_ = jspb.BinaryConstants.INVALID_FIELD_NUMBER;
+
+ /**
+ * Wire type of the next proto field in the buffer, filled in by
+ * nextField().
+ * @private {jspb.BinaryConstants.WireType}
+ */
+ this.nextWireType_ = jspb.BinaryConstants.WireType.INVALID;
+
+ /**
+ * Set to true if this reader encountered an error due to corrupt data.
+ * @private {boolean}
+ */
+ this.error_ = false;
+
+ /**
+ * User-defined reader callbacks.
+ * @private {Object.<string, function(!jspb.BinaryReader):*>}
+ */
+ this.readCallbacks_ = null;
+};
+
+
+/**
+ * Global pool of BinaryReader instances.
+ * @private {!Array.<!jspb.BinaryReader>}
+ */
+jspb.BinaryReader.instanceCache_ = [];
+
+
+/**
+ * Pops an instance off the instance cache, or creates one if the cache is
+ * empty.
+ * @param {jspb.ByteSource=} opt_bytes The bytes we're reading from.
+ * @param {number=} opt_start The optional offset to start reading at.
+ * @param {number=} opt_length The optional length of the block to read -
+ * we'll throw an assertion if we go off the end of the block.
+ * @return {!jspb.BinaryReader}
+ */
+jspb.BinaryReader.alloc =
+ function(opt_bytes, opt_start, opt_length) {
+ if (jspb.BinaryReader.instanceCache_.length) {
+ var newReader = jspb.BinaryReader.instanceCache_.pop();
+ if (opt_bytes) {
+ newReader.decoder_.setBlock(opt_bytes, opt_start, opt_length);
+ }
+ return newReader;
+ } else {
+ return new jspb.BinaryReader(opt_bytes, opt_start, opt_length);
+ }
+};
+
+
+/**
+ * Alias for the above method.
+ * @param {jspb.ByteSource=} opt_bytes The bytes we're reading from.
+ * @param {number=} opt_start The optional offset to start reading at.
+ * @param {number=} opt_length The optional length of the block to read -
+ * we'll throw an assertion if we go off the end of the block.
+ * @return {!jspb.BinaryReader}
+ */
+jspb.BinaryReader.prototype.alloc = jspb.BinaryReader.alloc;
+
+
+/**
+ * Puts this instance back in the instance cache.
+ */
+jspb.BinaryReader.prototype.free = function() {
+ this.decoder_.clear();
+ this.nextField_ = jspb.BinaryConstants.INVALID_FIELD_NUMBER;
+ this.nextWireType_ = jspb.BinaryConstants.WireType.INVALID;
+ this.error_ = false;
+ this.readCallbacks_ = null;
+
+ if (jspb.BinaryReader.instanceCache_.length < 100) {
+ jspb.BinaryReader.instanceCache_.push(this);
+ }
+};
+
+
+/**
+ * Returns the cursor immediately before the current field's tag.
+ * @return {number} The internal read cursor.
+ */
+jspb.BinaryReader.prototype.getFieldCursor = function() {
+ return this.fieldCursor_;
+};
+
+
+/**
+ * Returns the internal read cursor.
+ * @return {number} The internal read cursor.
+ */
+jspb.BinaryReader.prototype.getCursor = function() {
+ return this.decoder_.getCursor();
+};
+
+
+/**
+ * Returns the raw buffer.
+ * @return {?Uint8Array} The raw buffer.
+ */
+jspb.BinaryReader.prototype.getBuffer = function() {
+ return this.decoder_.getBuffer();
+};
+
+
+/**
+ * @return {number} The field number of the next field in the buffer, or
+ * INVALID_FIELD_NUMBER if there is no next field.
+ */
+jspb.BinaryReader.prototype.getFieldNumber = function() {
+ return this.nextField_;
+};
+
+
+/**
+ * @return {jspb.BinaryConstants.WireType} The wire type of the next field
+ * in the stream, or WireType.INVALID if there is no next field.
+ */
+jspb.BinaryReader.prototype.getWireType = function() {
+ return this.nextWireType_;
+};
+
+
+/**
+ * @return {boolean} Whether the current wire type is an end-group tag. Used as
+ * an exit condition in decoder loops in generated code.
+ */
+jspb.BinaryReader.prototype.isEndGroup = function() {
+ return this.nextWireType_ == jspb.BinaryConstants.WireType.END_GROUP;
+};
+
+
+/**
+ * Returns true if this reader hit an error due to corrupt data.
+ * @return {boolean}
+ */
+jspb.BinaryReader.prototype.getError = function() {
+ return this.error_ || this.decoder_.getError();
+};
+
+
+/**
+ * Points this reader at a new block of bytes.
+ * @param {!Uint8Array} bytes The block of bytes we're reading from.
+ * @param {number} start The offset to start reading at.
+ * @param {number} length The length of the block to read.
+ */
+jspb.BinaryReader.prototype.setBlock = function(bytes, start, length) {
+ this.decoder_.setBlock(bytes, start, length);
+ this.nextField_ = jspb.BinaryConstants.INVALID_FIELD_NUMBER;
+ this.nextWireType_ = jspb.BinaryConstants.WireType.INVALID;
+};
+
+
+/**
+ * Rewinds the stream cursor to the beginning of the buffer and resets all
+ * internal state.
+ */
+jspb.BinaryReader.prototype.reset = function() {
+ this.decoder_.reset();
+ this.nextField_ = jspb.BinaryConstants.INVALID_FIELD_NUMBER;
+ this.nextWireType_ = jspb.BinaryConstants.WireType.INVALID;
+};
+
+
+/**
+ * Advances the stream cursor by the given number of bytes.
+ * @param {number} count The number of bytes to advance by.
+ */
+jspb.BinaryReader.prototype.advance = function(count) {
+ this.decoder_.advance(count);
+};
+
+
+/**
+ * Reads the next field header in the stream if there is one, returns true if
+ * we saw a valid field header or false if we've read the whole stream.
+ * Throws an error if we encountered a deprecated START_GROUP/END_GROUP field.
+ * @return {boolean} True if the stream contains more fields.
+ */
+jspb.BinaryReader.prototype.nextField = function() {
+ // If we're at the end of the block, there are no more fields.
+ if (this.decoder_.atEnd()) {
+ return false;
+ }
+
+ // If we hit an error decoding the previous field, stop now before we
+ // try to decode anything else
+ if (this.getError()) {
+ goog.asserts.fail('Decoder hit an error');
+ return false;
+ }
+
+ // Otherwise just read the header of the next field.
+ this.fieldCursor_ = this.decoder_.getCursor();
+ var header = this.decoder_.readUnsignedVarint32();
+
+ var nextField = header >>> 3;
+ var nextWireType = /** @type {jspb.BinaryConstants.WireType} */
+ (header & 0x7);
+
+ // If the wire type isn't one of the valid ones, something's broken.
+ if (nextWireType != jspb.BinaryConstants.WireType.VARINT &&
+ nextWireType != jspb.BinaryConstants.WireType.FIXED32 &&
+ nextWireType != jspb.BinaryConstants.WireType.FIXED64 &&
+ nextWireType != jspb.BinaryConstants.WireType.DELIMITED &&
+ nextWireType != jspb.BinaryConstants.WireType.START_GROUP &&
+ nextWireType != jspb.BinaryConstants.WireType.END_GROUP) {
+ goog.asserts.fail('Invalid wire type');
+ this.error_ = true;
+ return false;
+ }
+
+ this.nextField_ = nextField;
+ this.nextWireType_ = nextWireType;
+
+ return true;
+};
+
+
+/**
+ * Winds the reader back to just before this field's header.
+ */
+jspb.BinaryReader.prototype.unskipHeader = function() {
+ this.decoder_.unskipVarint((this.nextField_ << 3) | this.nextWireType_);
+};
+
+
+/**
+ * Skips all contiguous fields whose header matches the one we just read.
+ */
+jspb.BinaryReader.prototype.skipMatchingFields = function() {
+ var field = this.nextField_;
+ this.unskipHeader();
+
+ while (this.nextField() && (this.getFieldNumber() == field)) {
+ this.skipField();
+ }
+
+ if (!this.decoder_.atEnd()) {
+ this.unskipHeader();
+ }
+};
+
+
+/**
+ * Skips over the next varint field in the binary stream.
+ */
+jspb.BinaryReader.prototype.skipVarintField = function() {
+ if (this.nextWireType_ != jspb.BinaryConstants.WireType.VARINT) {
+ goog.asserts.fail('Invalid wire type for skipVarintField');
+ this.skipField();
+ return;
+ }
+
+ this.decoder_.skipVarint();
+};
+
+
+/**
+ * Skips over the next delimited field in the binary stream.
+ */
+jspb.BinaryReader.prototype.skipDelimitedField = function() {
+ if (this.nextWireType_ != jspb.BinaryConstants.WireType.DELIMITED) {
+ goog.asserts.fail('Invalid wire type for skipDelimitedField');
+ this.skipField();
+ return;
+ }
+
+ var length = this.decoder_.readUnsignedVarint32();
+ this.decoder_.advance(length);
+};
+
+
+/**
+ * Skips over the next fixed32 field in the binary stream.
+ */
+jspb.BinaryReader.prototype.skipFixed32Field = function() {
+ if (this.nextWireType_ != jspb.BinaryConstants.WireType.FIXED32) {
+ goog.asserts.fail('Invalid wire type for skipFixed32Field');
+ this.skipField();
+ return;
+ }
+
+ this.decoder_.advance(4);
+};
+
+
+/**
+ * Skips over the next fixed64 field in the binary stream.
+ */
+jspb.BinaryReader.prototype.skipFixed64Field = function() {
+ if (this.nextWireType_ != jspb.BinaryConstants.WireType.FIXED64) {
+ goog.asserts.fail('Invalid wire type for skipFixed64Field');
+ this.skipField();
+ return;
+ }
+
+ this.decoder_.advance(8);
+};
+
+
+/**
+ * Skips over the next group field in the binary stream.
+ */
+jspb.BinaryReader.prototype.skipGroup = function() {
+ // Keep a stack of start-group tags that must be matched by end-group tags.
+ var nestedGroups = [this.nextField_];
+ do {
+ if (!this.nextField()) {
+ goog.asserts.fail('Unmatched start-group tag: stream EOF');
+ this.error_ = true;
+ return;
+ }
+ if (this.nextWireType_ ==
+ jspb.BinaryConstants.WireType.START_GROUP) {
+ // Nested group start.
+ nestedGroups.push(this.nextField_);
+ } else if (this.nextWireType_ ==
+ jspb.BinaryConstants.WireType.END_GROUP) {
+ // Group end: check that it matches top-of-stack.
+ if (this.nextField_ != nestedGroups.pop()) {
+ goog.asserts.fail('Unmatched end-group tag');
+ this.error_ = true;
+ return;
+ }
+ }
+ } while (nestedGroups.length > 0);
+};
+
+
+/**
+ * Skips over the next field in the binary stream - this is useful if we're
+ * decoding a message that contain unknown fields.
+ */
+jspb.BinaryReader.prototype.skipField = function() {
+ switch (this.nextWireType_) {
+ case jspb.BinaryConstants.WireType.VARINT:
+ this.skipVarintField();
+ break;
+ case jspb.BinaryConstants.WireType.FIXED64:
+ this.skipFixed64Field();
+ break;
+ case jspb.BinaryConstants.WireType.DELIMITED:
+ this.skipDelimitedField();
+ break;
+ case jspb.BinaryConstants.WireType.FIXED32:
+ this.skipFixed32Field();
+ break;
+ case jspb.BinaryConstants.WireType.START_GROUP:
+ this.skipGroup();
+ break;
+ default:
+ goog.asserts.fail('Invalid wire encoding for field.');
+ }
+};
+
+
+/**
+ * Registers a user-defined read callback.
+ * @param {string} callbackName
+ * @param {function(!jspb.BinaryReader):*} callback
+ */
+jspb.BinaryReader.prototype.registerReadCallback =
+ function(callbackName, callback) {
+ if (goog.isNull(this.readCallbacks_)) {
+ this.readCallbacks_ = {};
+ }
+ goog.asserts.assert(!this.readCallbacks_[callbackName]);
+ this.readCallbacks_[callbackName] = callback;
+};
+
+
+/**
+ * Runs a registered read callback.
+ * @param {string} callbackName The name the callback is registered under.
+ * @return {*} The value returned by the callback.
+ */
+jspb.BinaryReader.prototype.runReadCallback = function(callbackName) {
+ goog.asserts.assert(!goog.isNull(this.readCallbacks_));
+ var callback = this.readCallbacks_[callbackName];
+ goog.asserts.assert(callback);
+ return callback(this);
+};
+
+
+/**
+ * Reads a field of any valid non-message type from the binary stream.
+ * @param {jspb.BinaryConstants.FieldType} fieldType
+ * @return {jspb.AnyFieldType}
+ */
+jspb.BinaryReader.prototype.readAny = function(fieldType) {
+ this.nextWireType_ = jspb.BinaryConstants.FieldTypeToWireType(fieldType);
+ var fieldTypes = jspb.BinaryConstants.FieldType;
+ switch (fieldType) {
+ case fieldTypes.DOUBLE:
+ return this.readDouble();
+ case fieldTypes.FLOAT:
+ return this.readFloat();
+ case fieldTypes.INT64:
+ return this.readInt64();
+ case fieldTypes.UINT64:
+ return this.readUint64();
+ case fieldTypes.INT32:
+ return this.readInt32();
+ case fieldTypes.FIXED64:
+ return this.readFixed64();
+ case fieldTypes.FIXED32:
+ return this.readFixed32();
+ case fieldTypes.BOOL:
+ return this.readBool();
+ case fieldTypes.STRING:
+ return this.readString();
+ case fieldTypes.GROUP:
+ goog.asserts.fail('Group field type not supported in readAny()');
+ case fieldTypes.MESSAGE:
+ goog.asserts.fail('Message field type not supported in readAny()');
+ case fieldTypes.BYTES:
+ return this.readBytes();
+ case fieldTypes.UINT32:
+ return this.readUint32();
+ case fieldTypes.ENUM:
+ return this.readEnum();
+ case fieldTypes.SFIXED32:
+ return this.readSfixed32();
+ case fieldTypes.SFIXED64:
+ return this.readSfixed64();
+ case fieldTypes.SINT32:
+ return this.readSint32();
+ case fieldTypes.SINT64:
+ return this.readSint64();
+ case fieldTypes.FHASH64:
+ return this.readFixedHash64();
+ case fieldTypes.VHASH64:
+ return this.readVarintHash64();
+ default:
+ goog.asserts.fail('Invalid field type in readAny()');
+ }
+ return 0;
+};
+
+
+/**
+ * Deserialize a proto into the provided message object using the provided
+ * reader function. This function is templated as we currently have one client
+ * who is using manual deserialization instead of the code-generated versions.
+ * @template T
+ * @param {T} message
+ * @param {function(T, !jspb.BinaryReader)} reader
+ */
+jspb.BinaryReader.prototype.readMessage = function(message, reader) {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.DELIMITED);
+
+ // Save the current endpoint of the decoder and move it to the end of the
+ // embedded message.
+ var oldEnd = this.decoder_.getEnd();
+ var length = this.decoder_.readUnsignedVarint32();
+ var newEnd = this.decoder_.getCursor() + length;
+ this.decoder_.setEnd(newEnd);
+
+ // Deserialize the embedded message.
+ reader(message, this);
+
+ // Advance the decoder past the embedded message and restore the endpoint.
+ this.decoder_.setCursor(newEnd);
+ this.decoder_.setEnd(oldEnd);
+};
+
+
+/**
+ * Deserialize a proto into the provided message object using the provided
+ * reader function, assuming that the message is serialized as a group
+ * with the given tag.
+ * @template T
+ * @param {number} field
+ * @param {T} message
+ * @param {function(T, !jspb.BinaryReader)} reader
+ */
+jspb.BinaryReader.prototype.readGroup =
+ function(field, message, reader) {
+ // Ensure that the wire type is correct.
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.START_GROUP);
+ // Ensure that the field number is correct.
+ goog.asserts.assert(this.nextField_ == field);
+
+ // Deserialize the message. The deserialization will stop at an END_GROUP tag.
+ reader(message, this);
+
+ if (!this.error_ &&
+ this.nextWireType_ != jspb.BinaryConstants.WireType.END_GROUP) {
+ goog.asserts.fail('Group submessage did not end with an END_GROUP tag');
+ this.error_ = true;
+ }
+};
+
+
+/**
+ * Return a decoder that wraps the current delimited field.
+ * @return {!jspb.BinaryDecoder}
+ */
+jspb.BinaryReader.prototype.getFieldDecoder = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.DELIMITED);
+
+ var length = this.decoder_.readUnsignedVarint32();
+ var start = this.decoder_.getCursor();
+ var end = start + length;
+
+ var innerDecoder =
+ jspb.BinaryDecoder.alloc(this.decoder_.getBuffer(), start, length);
+ this.decoder_.setCursor(end);
+ return innerDecoder;
+};
+
+
+/**
+ * Reads a signed 32-bit integer field from the binary stream, or throws an
+ * error if the next field in the stream is not of the correct wire type.
+ *
+ * @return {number} The value of the signed 32-bit integer field.
+ */
+jspb.BinaryReader.prototype.readInt32 = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);
+ return this.decoder_.readSignedVarint32();
+};
+
+
+/**
+ * Reads a signed 32-bit integer field from the binary stream, or throws an
+ * error if the next field in the stream is not of the correct wire type.
+ *
+ * Returns the value as a string.
+ *
+ * @return {string} The value of the signed 32-bit integer field as a decimal
+ * string.
+ */
+jspb.BinaryReader.prototype.readInt32String = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);
+ return this.decoder_.readSignedVarint32String();
+};
+
+
+/**
+ * Reads a signed 64-bit integer field from the binary stream, or throws an
+ * error if the next field in the stream is not of the correct wire type.
+ *
+ * @return {number} The value of the signed 64-bit integer field.
+ */
+jspb.BinaryReader.prototype.readInt64 = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);
+ return this.decoder_.readSignedVarint64();
+};
+
+
+/**
+ * Reads a signed 64-bit integer field from the binary stream, or throws an
+ * error if the next field in the stream is not of the correct wire type.
+ *
+ * Returns the value as a string.
+ *
+ * @return {string} The value of the signed 64-bit integer field as a decimal
+ * string.
+ */
+jspb.BinaryReader.prototype.readInt64String = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);
+ return this.decoder_.readSignedVarint64String();
+};
+
+
+/**
+ * Reads an unsigned 32-bit integer field from the binary stream, or throws an
+ * error if the next field in the stream is not of the correct wire type.
+ *
+ * @return {number} The value of the unsigned 32-bit integer field.
+ */
+jspb.BinaryReader.prototype.readUint32 = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);
+ return this.decoder_.readUnsignedVarint32();
+};
+
+
+/**
+ * Reads an unsigned 32-bit integer field from the binary stream, or throws an
+ * error if the next field in the stream is not of the correct wire type.
+ *
+ * Returns the value as a string.
+ *
+ * @return {string} The value of the unsigned 32-bit integer field as a decimal
+ * string.
+ */
+jspb.BinaryReader.prototype.readUint32String = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);
+ return this.decoder_.readUnsignedVarint32String();
+};
+
+
+/**
+ * Reads an unsigned 64-bit integer field from the binary stream, or throws an
+ * error if the next field in the stream is not of the correct wire type.
+ *
+ * @return {number} The value of the unsigned 64-bit integer field.
+ */
+jspb.BinaryReader.prototype.readUint64 = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);
+ return this.decoder_.readUnsignedVarint64();
+};
+
+
+/**
+ * Reads an unsigned 64-bit integer field from the binary stream, or throws an
+ * error if the next field in the stream is not of the correct wire type.
+ *
+ * Returns the value as a string.
+ *
+ * @return {string} The value of the unsigned 64-bit integer field as a decimal
+ * string.
+ */
+jspb.BinaryReader.prototype.readUint64String = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);
+ return this.decoder_.readUnsignedVarint64String();
+};
+
+
+/**
+ * Reads a signed zigzag-encoded 32-bit integer field from the binary stream,
+ * or throws an error if the next field in the stream is not of the correct
+ * wire type.
+ *
+ * @return {number} The value of the signed 32-bit integer field.
+ */
+jspb.BinaryReader.prototype.readSint32 = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);
+ return this.decoder_.readZigzagVarint32();
+};
+
+
+/**
+ * Reads a signed zigzag-encoded 64-bit integer field from the binary stream,
+ * or throws an error if the next field in the stream is not of the correct
+ * wire type.
+ *
+ * @return {number} The value of the signed 64-bit integer field.
+ */
+jspb.BinaryReader.prototype.readSint64 = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);
+ return this.decoder_.readZigzagVarint64();
+};
+
+
+/**
+ * Reads a signed zigzag-encoded 64-bit integer field from the binary stream,
+ * or throws an error if the next field in the stream is not of the correct
+ * wire type.
+ *
+ * @return {string} The value of the signed 64-bit integer field as a decimal string.
+ */
+jspb.BinaryReader.prototype.readSint64String = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);
+ return this.decoder_.readZigzagVarint64String();
+};
+
+
+/**
+ * Reads an unsigned 32-bit fixed-length integer fiield from the binary stream,
+ * or throws an error if the next field in the stream is not of the correct
+ * wire type.
+ *
+ * @return {number} The value of the double field.
+ */
+jspb.BinaryReader.prototype.readFixed32 = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED32);
+ return this.decoder_.readUint32();
+};
+
+
+/**
+ * Reads an unsigned 64-bit fixed-length integer fiield from the binary stream,
+ * or throws an error if the next field in the stream is not of the correct
+ * wire type.
+ *
+ * @return {number} The value of the float field.
+ */
+jspb.BinaryReader.prototype.readFixed64 = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED64);
+ return this.decoder_.readUint64();
+};
+
+
+/**
+ * Reads a signed 64-bit integer field from the binary stream as a string, or
+ * throws an error if the next field in the stream is not of the correct wire
+ * type.
+ *
+ * Returns the value as a string.
+ *
+ * @return {string} The value of the unsigned 64-bit integer field as a decimal
+ * string.
+ */
+jspb.BinaryReader.prototype.readFixed64String = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED64);
+ return this.decoder_.readUint64String();
+};
+
+
+/**
+ * Reads a signed 32-bit fixed-length integer fiield from the binary stream, or
+ * throws an error if the next field in the stream is not of the correct wire
+ * type.
+ *
+ * @return {number} The value of the signed 32-bit integer field.
+ */
+jspb.BinaryReader.prototype.readSfixed32 = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED32);
+ return this.decoder_.readInt32();
+};
+
+
+/**
+ * Reads a signed 32-bit fixed-length integer fiield from the binary stream, or
+ * throws an error if the next field in the stream is not of the correct wire
+ * type.
+ *
+ * @return {string} The value of the signed 32-bit integer field as a decimal
+ * string.
+ */
+jspb.BinaryReader.prototype.readSfixed32String = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED32);
+ return this.decoder_.readInt32().toString();
+};
+
+
+/**
+ * Reads a signed 64-bit fixed-length integer fiield from the binary stream, or
+ * throws an error if the next field in the stream is not of the correct wire
+ * type.
+ *
+ * @return {number} The value of the sfixed64 field.
+ */
+jspb.BinaryReader.prototype.readSfixed64 = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED64);
+ return this.decoder_.readInt64();
+};
+
+
+/**
+ * Reads a signed 64-bit fixed-length integer fiield from the binary stream, or
+ * throws an error if the next field in the stream is not of the correct wire
+ * type.
+ *
+ * Returns the value as a string.
+ *
+ * @return {string} The value of the sfixed64 field as a decimal string.
+ */
+jspb.BinaryReader.prototype.readSfixed64String = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED64);
+ return this.decoder_.readInt64String();
+};
+
+
+/**
+ * Reads a 32-bit floating-point field from the binary stream, or throws an
+ * error if the next field in the stream is not of the correct wire type.
+ *
+ * @return {number} The value of the float field.
+ */
+jspb.BinaryReader.prototype.readFloat = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED32);
+ return this.decoder_.readFloat();
+};
+
+
+/**
+ * Reads a 64-bit floating-point field from the binary stream, or throws an
+ * error if the next field in the stream is not of the correct wire type.
+ *
+ * @return {number} The value of the double field.
+ */
+jspb.BinaryReader.prototype.readDouble = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED64);
+ return this.decoder_.readDouble();
+};
+
+
+/**
+ * Reads a boolean field from the binary stream, or throws an error if the next
+ * field in the stream is not of the correct wire type.
+ *
+ * @return {boolean} The value of the boolean field.
+ */
+jspb.BinaryReader.prototype.readBool = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);
+ return !!this.decoder_.readUnsignedVarint32();
+};
+
+
+/**
+ * Reads an enum field from the binary stream, or throws an error if the next
+ * field in the stream is not of the correct wire type.
+ *
+ * @return {number} The value of the enum field.
+ */
+jspb.BinaryReader.prototype.readEnum = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);
+ return this.decoder_.readSignedVarint64();
+};
+
+
+/**
+ * Reads a string field from the binary stream, or throws an error if the next
+ * field in the stream is not of the correct wire type.
+ *
+ * @return {string} The value of the string field.
+ */
+jspb.BinaryReader.prototype.readString = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.DELIMITED);
+ var length = this.decoder_.readUnsignedVarint32();
+ return this.decoder_.readString(length);
+};
+
+
+/**
+ * Reads a length-prefixed block of bytes from the binary stream, or returns
+ * null if the next field in the stream has an invalid length value.
+ *
+ * @return {!Uint8Array} The block of bytes.
+ */
+jspb.BinaryReader.prototype.readBytes = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.DELIMITED);
+ var length = this.decoder_.readUnsignedVarint32();
+ return this.decoder_.readBytes(length);
+};
+
+
+/**
+ * Reads a 64-bit varint or fixed64 field from the stream and returns it as a
+ * 8-character Unicode string for use as a hash table key, or throws an error
+ * if the next field in the stream is not of the correct wire type.
+ *
+ * @return {string} The hash value.
+ */
+jspb.BinaryReader.prototype.readVarintHash64 = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);
+ return this.decoder_.readVarintHash64();
+};
+
+
+/**
+ * Reads a 64-bit varint or fixed64 field from the stream and returns it as a
+ * 8-character Unicode string for use as a hash table key, or throws an error
+ * if the next field in the stream is not of the correct wire type.
+ *
+ * @return {string} The hash value.
+ */
+jspb.BinaryReader.prototype.readFixedHash64 = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED64);
+ return this.decoder_.readFixedHash64();
+};
+
+
+/**
+ * Reads a packed scalar field using the supplied raw reader function.
+ * @param {function()} decodeMethod
+ * @return {!Array}
+ * @private
+ */
+jspb.BinaryReader.prototype.readPackedField_ = function(decodeMethod) {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.DELIMITED);
+ var length = this.decoder_.readUnsignedVarint32();
+ var end = this.decoder_.getCursor() + length;
+ var result = [];
+ while (this.decoder_.getCursor() < end) {
+ // TODO(aappleby): .call is slow
+ result.push(decodeMethod.call(this.decoder_));
+ }
+ return result;
+};
+
+
+/**
+ * Reads a packed int32 field, which consists of a length header and a list of
+ * signed varints.
+ * @return {!Array.<number>}
+ */
+jspb.BinaryReader.prototype.readPackedInt32 = function() {
+ return this.readPackedField_(this.decoder_.readSignedVarint32);
+};
+
+
+/**
+ * Reads a packed int32 field, which consists of a length header and a list of
+ * signed varints. Returns a list of strings.
+ * @return {!Array.<string>}
+ */
+jspb.BinaryReader.prototype.readPackedInt32String = function() {
+ return this.readPackedField_(this.decoder_.readSignedVarint32String);
+};
+
+
+/**
+ * Reads a packed int64 field, which consists of a length header and a list of
+ * signed varints.
+ * @return {!Array.<number>}
+ */
+jspb.BinaryReader.prototype.readPackedInt64 = function() {
+ return this.readPackedField_(this.decoder_.readSignedVarint64);
+};
+
+
+/**
+ * Reads a packed int64 field, which consists of a length header and a list of
+ * signed varints. Returns a list of strings.
+ * @return {!Array.<string>}
+ */
+jspb.BinaryReader.prototype.readPackedInt64String = function() {
+ return this.readPackedField_(this.decoder_.readSignedVarint64String);
+};
+
+
+/**
+ * Reads a packed uint32 field, which consists of a length header and a list of
+ * unsigned varints.
+ * @return {!Array.<number>}
+ */
+jspb.BinaryReader.prototype.readPackedUint32 = function() {
+ return this.readPackedField_(this.decoder_.readUnsignedVarint32);
+};
+
+
+/**
+ * Reads a packed uint32 field, which consists of a length header and a list of
+ * unsigned varints. Returns a list of strings.
+ * @return {!Array.<string>}
+ */
+jspb.BinaryReader.prototype.readPackedUint32String = function() {
+ return this.readPackedField_(this.decoder_.readUnsignedVarint32String);
+};
+
+
+/**
+ * Reads a packed uint64 field, which consists of a length header and a list of
+ * unsigned varints.
+ * @return {!Array.<number>}
+ */
+jspb.BinaryReader.prototype.readPackedUint64 = function() {
+ return this.readPackedField_(this.decoder_.readUnsignedVarint64);
+};
+
+
+/**
+ * Reads a packed uint64 field, which consists of a length header and a list of
+ * unsigned varints. Returns a list of strings.
+ * @return {!Array.<string>}
+ */
+jspb.BinaryReader.prototype.readPackedUint64String = function() {
+ return this.readPackedField_(this.decoder_.readUnsignedVarint64String);
+};
+
+
+/**
+ * Reads a packed sint32 field, which consists of a length header and a list of
+ * zigzag varints.
+ * @return {!Array.<number>}
+ */
+jspb.BinaryReader.prototype.readPackedSint32 = function() {
+ return this.readPackedField_(this.decoder_.readZigzagVarint32);
+};
+
+
+/**
+ * Reads a packed sint64 field, which consists of a length header and a list of
+ * zigzag varints.
+ * @return {!Array.<number>}
+ */
+jspb.BinaryReader.prototype.readPackedSint64 = function() {
+ return this.readPackedField_(this.decoder_.readZigzagVarint64);
+};
+
+
+/**
+ * Reads a packed sint64 field, which consists of a length header and a list of
+ * zigzag varints. Returns a list of strings.
+ * @return {!Array.<string>}
+ */
+jspb.BinaryReader.prototype.readPackedSint64String = function() {
+ return this.readPackedField_(this.decoder_.readZigzagVarint64String);
+};
+
+
+/**
+ * Reads a packed fixed32 field, which consists of a length header and a list
+ * of unsigned 32-bit ints.
+ * @return {!Array.<number>}
+ */
+jspb.BinaryReader.prototype.readPackedFixed32 = function() {
+ return this.readPackedField_(this.decoder_.readUint32);
+};
+
+
+/**
+ * Reads a packed fixed64 field, which consists of a length header and a list
+ * of unsigned 64-bit ints.
+ * @return {!Array.<number>}
+ */
+jspb.BinaryReader.prototype.readPackedFixed64 = function() {
+ return this.readPackedField_(this.decoder_.readUint64);
+};
+
+
+/**
+ * Reads a packed fixed64 field, which consists of a length header and a list
+ * of unsigned 64-bit ints. Returns a list of strings.
+ * @return {!Array.<number>}
+ */
+jspb.BinaryReader.prototype.readPackedFixed64String = function() {
+ return this.readPackedField_(this.decoder_.readUint64String);
+};
+
+
+/**
+ * Reads a packed sfixed32 field, which consists of a length header and a list
+ * of 32-bit ints.
+ * @return {!Array.<number>}
+ */
+jspb.BinaryReader.prototype.readPackedSfixed32 = function() {
+ return this.readPackedField_(this.decoder_.readInt32);
+};
+
+
+/**
+ * Reads a packed sfixed64 field, which consists of a length header and a list
+ * of 64-bit ints.
+ * @return {!Array.<number>}
+ */
+jspb.BinaryReader.prototype.readPackedSfixed64 = function() {
+ return this.readPackedField_(this.decoder_.readInt64);
+};
+
+
+/**
+ * Reads a packed sfixed64 field, which consists of a length header and a list
+ * of 64-bit ints. Returns a list of strings.
+ * @return {!Array.<string>}
+ */
+jspb.BinaryReader.prototype.readPackedSfixed64String = function() {
+ return this.readPackedField_(this.decoder_.readInt64String);
+};
+
+
+/**
+ * Reads a packed float field, which consists of a length header and a list of
+ * floats.
+ * @return {!Array.<number>}
+ */
+jspb.BinaryReader.prototype.readPackedFloat = function() {
+ return this.readPackedField_(this.decoder_.readFloat);
+};
+
+
+/**
+ * Reads a packed double field, which consists of a length header and a list of
+ * doubles.
+ * @return {!Array.<number>}
+ */
+jspb.BinaryReader.prototype.readPackedDouble = function() {
+ return this.readPackedField_(this.decoder_.readDouble);
+};
+
+
+/**
+ * Reads a packed bool field, which consists of a length header and a list of
+ * unsigned varints.
+ * @return {!Array.<boolean>}
+ */
+jspb.BinaryReader.prototype.readPackedBool = function() {
+ return this.readPackedField_(this.decoder_.readBool);
+};
+
+
+/**
+ * Reads a packed enum field, which consists of a length header and a list of
+ * unsigned varints.
+ * @return {!Array.<number>}
+ */
+jspb.BinaryReader.prototype.readPackedEnum = function() {
+ return this.readPackedField_(this.decoder_.readEnum);
+};
+
+
+/**
+ * Reads a packed varint hash64 field, which consists of a length header and a
+ * list of varint hash64s.
+ * @return {!Array.<string>}
+ */
+jspb.BinaryReader.prototype.readPackedVarintHash64 = function() {
+ return this.readPackedField_(this.decoder_.readVarintHash64);
+};
+
+
+/**
+ * Reads a packed fixed hash64 field, which consists of a length header and a
+ * list of fixed hash64s.
+ * @return {!Array.<string>}
+ */
+jspb.BinaryReader.prototype.readPackedFixedHash64 = function() {
+ return this.readPackedField_(this.decoder_.readFixedHash64);
+};
diff --git a/third_party/protobuf/js/binary/reader_test.js b/third_party/protobuf/js/binary/reader_test.js
new file mode 100644
index 0000000000..957113859e
--- /dev/null
+++ b/third_party/protobuf/js/binary/reader_test.js
@@ -0,0 +1,922 @@
+// 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.
+
+/**
+ * @fileoverview Test cases for jspb's binary protocol buffer reader.
+ *
+ * There are two particular magic numbers that need to be pointed out -
+ * 2^64-1025 is the largest number representable as both a double and an
+ * unsigned 64-bit integer, and 2^63-513 is the largest number representable as
+ * both a double and a signed 64-bit integer.
+ *
+ * Test suite is written using Jasmine -- see http://jasmine.github.io/
+ *
+ * @author aappleby@google.com (Austin Appleby)
+ */
+
+goog.require('goog.testing.asserts');
+goog.require('jspb.BinaryConstants');
+goog.require('jspb.BinaryDecoder');
+goog.require('jspb.BinaryReader');
+goog.require('jspb.BinaryWriter');
+
+
+
+describe('binaryReaderTest', function() {
+ /**
+ * Tests the reader instance cache.
+ */
+ it('testInstanceCaches', /** @suppress {visibility} */ function() {
+ var writer = new jspb.BinaryWriter();
+ var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
+ writer.writeMessage(1, dummyMessage, goog.nullFunction);
+ writer.writeMessage(2, dummyMessage, goog.nullFunction);
+
+ var buffer = writer.getResultBuffer();
+
+ // Empty the instance caches.
+ jspb.BinaryReader.instanceCache_ = [];
+
+ // Allocating and then freeing three decoders should leave us with three in
+ // the cache.
+
+ var decoder1 = jspb.BinaryDecoder.alloc();
+ var decoder2 = jspb.BinaryDecoder.alloc();
+ var decoder3 = jspb.BinaryDecoder.alloc();
+ decoder1.free();
+ decoder2.free();
+ decoder3.free();
+
+ assertEquals(3, jspb.BinaryDecoder.instanceCache_.length);
+ assertEquals(0, jspb.BinaryReader.instanceCache_.length);
+
+ // Allocating and then freeing a reader should remove one decoder from its
+ // cache, but it should stay stuck to the reader afterwards since we can't
+ // have a reader without a decoder.
+ jspb.BinaryReader.alloc().free();
+
+ assertEquals(2, jspb.BinaryDecoder.instanceCache_.length);
+ assertEquals(1, jspb.BinaryReader.instanceCache_.length);
+
+ // Allocating a reader should remove a reader from the cache.
+ var reader = jspb.BinaryReader.alloc(buffer);
+
+ assertEquals(2, jspb.BinaryDecoder.instanceCache_.length);
+ assertEquals(0, jspb.BinaryReader.instanceCache_.length);
+
+ // Processing the message reuses the current reader.
+ reader.nextField();
+ assertEquals(1, reader.getFieldNumber());
+ reader.readMessage(dummyMessage, function() {
+ assertEquals(0, jspb.BinaryReader.instanceCache_.length);
+ });
+
+ reader.nextField();
+ assertEquals(2, reader.getFieldNumber());
+ reader.readMessage(dummyMessage, function() {
+ assertEquals(0, jspb.BinaryReader.instanceCache_.length);
+ });
+
+ assertEquals(false, reader.nextField());
+
+ assertEquals(2, jspb.BinaryDecoder.instanceCache_.length);
+ assertEquals(0, jspb.BinaryReader.instanceCache_.length);
+
+ // Freeing the reader should put it back into the cache.
+ reader.free();
+
+ assertEquals(2, jspb.BinaryDecoder.instanceCache_.length);
+ assertEquals(1, jspb.BinaryReader.instanceCache_.length);
+ });
+
+
+ /**
+ * @param {number} x
+ * @return {number}
+ */
+ function truncate(x) {
+ var temp = new Float32Array(1);
+ temp[0] = x;
+ return temp[0];
+ }
+
+
+ /**
+ * Verifies that misuse of the reader class triggers assertions.
+ */
+ it('testReadErrors', /** @suppress {checkTypes|visibility} */ function() {
+ // Calling readMessage on a non-delimited field should trigger an
+ // assertion.
+ var reader = jspb.BinaryReader.alloc([8, 1]);
+ var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
+ reader.nextField();
+ assertThrows(function() {
+ reader.readMessage(dummyMessage, goog.nullFunction);
+ });
+
+ // Reading past the end of the stream should trigger an assertion.
+ reader = jspb.BinaryReader.alloc([9, 1]);
+ reader.nextField();
+ assertThrows(function() {reader.readFixed64()});
+
+ // Reading past the end of a submessage should trigger an assertion.
+ reader = jspb.BinaryReader.alloc([10, 4, 13, 1, 1, 1]);
+ reader.nextField();
+ reader.readMessage(dummyMessage, function() {
+ reader.nextField();
+ assertThrows(function() {reader.readFixed32()});
+ });
+
+ // Skipping an invalid field should trigger an assertion.
+ reader = jspb.BinaryReader.alloc([12, 1]);
+ reader.nextWireType_ = 1000;
+ assertThrows(function() {reader.skipField()});
+
+ // Reading fields with the wrong wire type should assert.
+ reader = jspb.BinaryReader.alloc([9, 0, 0, 0, 0, 0, 0, 0, 0]);
+ reader.nextField();
+ assertThrows(function() {reader.readInt32()});
+ assertThrows(function() {reader.readInt32String()});
+ assertThrows(function() {reader.readInt64()});
+ assertThrows(function() {reader.readInt64String()});
+ assertThrows(function() {reader.readUint32()});
+ assertThrows(function() {reader.readUint32String()});
+ assertThrows(function() {reader.readUint64()});
+ assertThrows(function() {reader.readUint64String()});
+ assertThrows(function() {reader.readSint32()});
+ assertThrows(function() {reader.readBool()});
+ assertThrows(function() {reader.readEnum()});
+
+ reader = jspb.BinaryReader.alloc([8, 1]);
+ reader.nextField();
+ assertThrows(function() {reader.readFixed32()});
+ assertThrows(function() {reader.readFixed64()});
+ assertThrows(function() {reader.readSfixed32()});
+ assertThrows(function() {reader.readSfixed64()});
+ assertThrows(function() {reader.readFloat()});
+ assertThrows(function() {reader.readDouble()});
+
+ assertThrows(function() {reader.readString()});
+ assertThrows(function() {reader.readBytes()});
+ });
+
+
+ /**
+ * Tests encoding and decoding of unsigned field types.
+ * @param {Function} readField
+ * @param {Function} writeField
+ * @param {number} epsilon
+ * @param {number} upperLimit
+ * @param {Function} filter
+ * @private
+ * @suppress {missingProperties}
+ */
+ var doTestUnsignedField_ = function(readField,
+ writeField, epsilon, upperLimit, filter) {
+ assertNotNull(readField);
+ assertNotNull(writeField);
+
+ var writer = new jspb.BinaryWriter();
+
+ // Encode zero and limits.
+ writeField.call(writer, 1, filter(0));
+ writeField.call(writer, 2, filter(epsilon));
+ writeField.call(writer, 3, filter(upperLimit));
+
+ // Encode positive values.
+ for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) {
+ writeField.call(writer, 4, filter(cursor));
+ }
+
+ var reader = jspb.BinaryReader.alloc(writer.getResultBuffer());
+
+ // Check zero and limits.
+ reader.nextField();
+ assertEquals(1, reader.getFieldNumber());
+ assertEquals(filter(0), readField.call(reader));
+
+ reader.nextField();
+ assertEquals(2, reader.getFieldNumber());
+ assertEquals(filter(epsilon), readField.call(reader));
+
+ reader.nextField();
+ assertEquals(3, reader.getFieldNumber());
+ assertEquals(filter(upperLimit), readField.call(reader));
+
+ // Check positive values.
+ for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) {
+ reader.nextField();
+ if (4 != reader.getFieldNumber()) throw 'fail!';
+ if (filter(cursor) != readField.call(reader)) throw 'fail!';
+ }
+ };
+
+
+ /**
+ * Tests encoding and decoding of signed field types.
+ * @param {Function} readField
+ * @param {Function} writeField
+ * @param {number} epsilon
+ * @param {number} lowerLimit
+ * @param {number} upperLimit
+ * @param {Function} filter
+ * @private
+ * @suppress {missingProperties}
+ */
+ var doTestSignedField_ = function(readField,
+ writeField, epsilon, lowerLimit, upperLimit, filter) {
+ var writer = new jspb.BinaryWriter();
+
+ // Encode zero and limits.
+ writeField.call(writer, 1, filter(lowerLimit));
+ writeField.call(writer, 2, filter(-epsilon));
+ writeField.call(writer, 3, filter(0));
+ writeField.call(writer, 4, filter(epsilon));
+ writeField.call(writer, 5, filter(upperLimit));
+
+ var inputValues = [];
+
+ // Encode negative values.
+ for (var cursor = lowerLimit; cursor < -epsilon; cursor /= 1.1) {
+ var val = filter(cursor);
+ writeField.call(writer, 6, val);
+ inputValues.push({
+ fieldNumber: 6,
+ value: val
+ });
+ }
+
+ // Encode positive values.
+ for (var cursor = epsilon; cursor < upperLimit; cursor *= 1.1) {
+ var val = filter(cursor);
+ writeField.call(writer, 7, val);
+ inputValues.push({
+ fieldNumber: 7,
+ value: val
+ });
+ }
+
+ var reader = jspb.BinaryReader.alloc(writer.getResultBuffer());
+
+ // Check zero and limits.
+ reader.nextField();
+ assertEquals(1, reader.getFieldNumber());
+ assertEquals(filter(lowerLimit), readField.call(reader));
+
+ reader.nextField();
+ assertEquals(2, reader.getFieldNumber());
+ assertEquals(filter(-epsilon), readField.call(reader));
+
+ reader.nextField();
+ assertEquals(3, reader.getFieldNumber());
+ assertEquals(filter(0), readField.call(reader));
+
+ reader.nextField();
+ assertEquals(4, reader.getFieldNumber());
+ assertEquals(filter(epsilon), readField.call(reader));
+
+ reader.nextField();
+ assertEquals(5, reader.getFieldNumber());
+ assertEquals(filter(upperLimit), readField.call(reader));
+
+ for (var i = 0; i < inputValues.length; i++) {
+ var expected = inputValues[i];
+ reader.nextField();
+ assertEquals(expected.fieldNumber, reader.getFieldNumber());
+ assertEquals(expected.value, readField.call(reader));
+ }
+ };
+
+
+ /**
+ * Tests fields that use varint encoding.
+ */
+ it('testVarintFields', function() {
+ assertNotUndefined(jspb.BinaryReader.prototype.readUint32);
+ assertNotUndefined(jspb.BinaryWriter.prototype.writeUint32);
+ assertNotUndefined(jspb.BinaryReader.prototype.readUint64);
+ assertNotUndefined(jspb.BinaryWriter.prototype.writeUint64);
+ assertNotUndefined(jspb.BinaryReader.prototype.readBool);
+ assertNotUndefined(jspb.BinaryWriter.prototype.writeBool);
+ doTestUnsignedField_(
+ jspb.BinaryReader.prototype.readUint32,
+ jspb.BinaryWriter.prototype.writeUint32,
+ 1, Math.pow(2, 32) - 1, Math.round);
+
+ doTestUnsignedField_(
+ jspb.BinaryReader.prototype.readUint64,
+ jspb.BinaryWriter.prototype.writeUint64,
+ 1, Math.pow(2, 64) - 1025, Math.round);
+
+ doTestSignedField_(
+ jspb.BinaryReader.prototype.readInt32,
+ jspb.BinaryWriter.prototype.writeInt32,
+ 1, -Math.pow(2, 31), Math.pow(2, 31) - 1, Math.round);
+
+ doTestSignedField_(
+ jspb.BinaryReader.prototype.readInt64,
+ jspb.BinaryWriter.prototype.writeInt64,
+ 1, -Math.pow(2, 63), Math.pow(2, 63) - 513, Math.round);
+
+ doTestSignedField_(
+ jspb.BinaryReader.prototype.readEnum,
+ jspb.BinaryWriter.prototype.writeEnum,
+ 1, -Math.pow(2, 31), Math.pow(2, 31) - 1, Math.round);
+
+ doTestUnsignedField_(
+ jspb.BinaryReader.prototype.readBool,
+ jspb.BinaryWriter.prototype.writeBool,
+ 1, 1, function(x) { return !!x; });
+ });
+
+
+ /**
+ * Tests reading a field from hexadecimal string (format: '08 BE EF').
+ * @param {Function} readField
+ * @param {number} expected
+ * @param {string} hexString
+ */
+ function doTestHexStringVarint_(readField, expected, hexString) {
+ var bytesCount = (hexString.length + 1) / 3;
+ var bytes = new Uint8Array(bytesCount);
+ for (var i = 0; i < bytesCount; i++) {
+ bytes[i] = parseInt(hexString.substring(i * 3, i * 3 + 2), 16);
+ }
+ var reader = jspb.BinaryReader.alloc(bytes);
+ reader.nextField();
+ assertEquals(expected, readField.call(reader));
+ }
+
+
+ /**
+ * Tests non-canonical redundant varint decoding.
+ */
+ it('testRedundantVarintFields', function() {
+ assertNotNull(jspb.BinaryReader.prototype.readUint32);
+ assertNotNull(jspb.BinaryReader.prototype.readUint64);
+ assertNotNull(jspb.BinaryReader.prototype.readSint32);
+ assertNotNull(jspb.BinaryReader.prototype.readSint64);
+
+ // uint32 and sint32 take no more than 5 bytes
+ // 08 - field prefix (type = 0 means varint)
+ doTestHexStringVarint_(
+ jspb.BinaryReader.prototype.readUint32,
+ 12, '08 8C 80 80 80 00');
+
+ // 11 stands for -6 in zigzag encoding
+ doTestHexStringVarint_(
+ jspb.BinaryReader.prototype.readSint32,
+ -6, '08 8B 80 80 80 00');
+
+ // uint64 and sint64 take no more than 10 bytes
+ // 08 - field prefix (type = 0 means varint)
+ doTestHexStringVarint_(
+ jspb.BinaryReader.prototype.readUint64,
+ 12, '08 8C 80 80 80 80 80 80 80 80 00');
+
+ // 11 stands for -6 in zigzag encoding
+ doTestHexStringVarint_(
+ jspb.BinaryReader.prototype.readSint64,
+ -6, '08 8B 80 80 80 80 80 80 80 80 00');
+ });
+
+
+ /**
+ * Tests 64-bit fields that are handled as strings.
+ */
+ it('testStringInt64Fields', function() {
+ var writer = new jspb.BinaryWriter();
+
+ var testSignedData = [
+ '2730538252207801776',
+ '-2688470994844604560',
+ '3398529779486536359',
+ '3568577411627971000',
+ '272477188847484900',
+ '-6649058714086158188',
+ '-7695254765712060806',
+ '-4525541438037104029',
+ '-4993706538836508568',
+ '4990160321893729138'
+ ];
+ var testUnsignedData = [
+ '7822732630241694882',
+ '6753602971916687352',
+ '2399935075244442116',
+ '8724292567325338867',
+ '16948784802625696584',
+ '4136275908516066934',
+ '3575388346793700364',
+ '5167142028379259461',
+ '1557573948689737699',
+ '17100725280812548567'
+ ];
+
+ for (var i = 0; i < testSignedData.length; i++) {
+ writer.writeInt64String(2 * i + 1, testSignedData[i]);
+ writer.writeUint64String(2 * i + 2, testUnsignedData[i]);
+ }
+
+ var reader = jspb.BinaryReader.alloc(writer.getResultBuffer());
+
+ for (var i = 0; i < testSignedData.length; i++) {
+ reader.nextField();
+ assertEquals(2 * i + 1, reader.getFieldNumber());
+ assertEquals(testSignedData[i], reader.readInt64String());
+ reader.nextField();
+ assertEquals(2 * i + 2, reader.getFieldNumber());
+ assertEquals(testUnsignedData[i], reader.readUint64String());
+ }
+ });
+
+
+ /**
+ * Tests fields that use zigzag encoding.
+ */
+ it('testZigzagFields', function() {
+ doTestSignedField_(
+ jspb.BinaryReader.prototype.readSint32,
+ jspb.BinaryWriter.prototype.writeSint32,
+ 1, -Math.pow(2, 31), Math.pow(2, 31) - 1, Math.round);
+
+ doTestSignedField_(
+ jspb.BinaryReader.prototype.readSint64,
+ jspb.BinaryWriter.prototype.writeSint64,
+ 1, -Math.pow(2, 63), Math.pow(2, 63) - 513, Math.round);
+ });
+
+
+ /**
+ * Tests fields that use fixed-length encoding.
+ */
+ it('testFixedFields', function() {
+ doTestUnsignedField_(
+ jspb.BinaryReader.prototype.readFixed32,
+ jspb.BinaryWriter.prototype.writeFixed32,
+ 1, Math.pow(2, 32) - 1, Math.round);
+
+ doTestUnsignedField_(
+ jspb.BinaryReader.prototype.readFixed64,
+ jspb.BinaryWriter.prototype.writeFixed64,
+ 1, Math.pow(2, 64) - 1025, Math.round);
+
+ doTestSignedField_(
+ jspb.BinaryReader.prototype.readSfixed32,
+ jspb.BinaryWriter.prototype.writeSfixed32,
+ 1, -Math.pow(2, 31), Math.pow(2, 31) - 1, Math.round);
+
+ doTestSignedField_(
+ jspb.BinaryReader.prototype.readSfixed64,
+ jspb.BinaryWriter.prototype.writeSfixed64,
+ 1, -Math.pow(2, 63), Math.pow(2, 63) - 513, Math.round);
+ });
+
+
+ /**
+ * Tests floating point fields.
+ */
+ it('testFloatFields', function() {
+ doTestSignedField_(
+ jspb.BinaryReader.prototype.readFloat,
+ jspb.BinaryWriter.prototype.writeFloat,
+ jspb.BinaryConstants.FLOAT32_MIN,
+ -jspb.BinaryConstants.FLOAT32_MAX,
+ jspb.BinaryConstants.FLOAT32_MAX,
+ truncate);
+
+ doTestSignedField_(
+ jspb.BinaryReader.prototype.readDouble,
+ jspb.BinaryWriter.prototype.writeDouble,
+ jspb.BinaryConstants.FLOAT64_EPS * 10,
+ -jspb.BinaryConstants.FLOAT64_MIN,
+ jspb.BinaryConstants.FLOAT64_MIN,
+ function(x) { return x; });
+ });
+
+
+ /**
+ * Tests length-delimited string fields.
+ */
+ it('testStringFields', function() {
+ var s1 = 'The quick brown fox jumps over the lazy dog.';
+ var s2 = '人人生而自由,在尊嚴和權利上一律平等。';
+
+ var writer = new jspb.BinaryWriter();
+
+ writer.writeString(1, s1);
+ writer.writeString(2, s2);
+
+ var reader = jspb.BinaryReader.alloc(writer.getResultBuffer());
+
+ reader.nextField();
+ assertEquals(1, reader.getFieldNumber());
+ assertEquals(s1, reader.readString());
+
+ reader.nextField();
+ assertEquals(2, reader.getFieldNumber());
+ assertEquals(s2, reader.readString());
+ });
+
+
+ /**
+ * Tests length-delimited byte fields.
+ */
+ it('testByteFields', function() {
+ var message = [];
+ var lowerLimit = 1;
+ var upperLimit = 256;
+ var scale = 1.1;
+
+ var writer = new jspb.BinaryWriter();
+
+ for (var cursor = lowerLimit; cursor < upperLimit; cursor *= 1.1) {
+ var len = Math.round(cursor);
+ var bytes = [];
+ for (var i = 0; i < len; i++) bytes.push(i % 256);
+
+ writer.writeBytes(len, bytes);
+ }
+
+ var reader = jspb.BinaryReader.alloc(writer.getResultBuffer());
+
+ for (var cursor = lowerLimit; reader.nextField(); cursor *= 1.1) {
+ var len = Math.round(cursor);
+ if (len != reader.getFieldNumber()) throw 'fail!';
+
+ var bytes = reader.readBytes();
+ if (len != bytes.length) throw 'fail!';
+ for (var i = 0; i < bytes.length; i++) {
+ if (i % 256 != bytes[i]) throw 'fail!';
+ }
+ }
+ });
+
+
+ /**
+ * Tests nested messages.
+ */
+ it('testNesting', function() {
+ var writer = new jspb.BinaryWriter();
+ var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
+
+ writer.writeInt32(1, 100);
+
+ // Add one message with 3 int fields.
+ writer.writeMessage(2, dummyMessage, function() {
+ writer.writeInt32(3, 300);
+ writer.writeInt32(4, 400);
+ writer.writeInt32(5, 500);
+ });
+
+ // Add one empty message.
+ writer.writeMessage(6, dummyMessage, goog.nullFunction);
+
+ writer.writeInt32(7, 700);
+
+ var reader = jspb.BinaryReader.alloc(writer.getResultBuffer());
+
+ // Validate outermost message.
+
+ reader.nextField();
+ assertEquals(1, reader.getFieldNumber());
+ assertEquals(100, reader.readInt32());
+
+ reader.nextField();
+ assertEquals(2, reader.getFieldNumber());
+ reader.readMessage(dummyMessage, function() {
+ // Validate embedded message 1.
+ reader.nextField();
+ assertEquals(3, reader.getFieldNumber());
+ assertEquals(300, reader.readInt32());
+
+ reader.nextField();
+ assertEquals(4, reader.getFieldNumber());
+ assertEquals(400, reader.readInt32());
+
+ reader.nextField();
+ assertEquals(5, reader.getFieldNumber());
+ assertEquals(500, reader.readInt32());
+
+ assertEquals(false, reader.nextField());
+ });
+
+ reader.nextField();
+ assertEquals(6, reader.getFieldNumber());
+ reader.readMessage(dummyMessage, function() {
+ // Validate embedded message 2.
+
+ assertEquals(false, reader.nextField());
+ });
+
+ reader.nextField();
+ assertEquals(7, reader.getFieldNumber());
+ assertEquals(700, reader.readInt32());
+
+ assertEquals(false, reader.nextField());
+ });
+
+ /**
+ * Tests skipping fields of each type by interleaving them with sentinel
+ * values and skipping everything that's not a sentinel.
+ */
+ it('testSkipField', function() {
+ var writer = new jspb.BinaryWriter();
+
+ var sentinel = 123456789;
+
+ // Write varint fields of different sizes.
+ writer.writeInt32(1, sentinel);
+ writer.writeInt32(1, 1);
+ writer.writeInt32(1, 1000);
+ writer.writeInt32(1, 1000000);
+ writer.writeInt32(1, 1000000000);
+
+ // Write fixed 64-bit encoded fields.
+ writer.writeInt32(2, sentinel);
+ writer.writeDouble(2, 1);
+ writer.writeFixed64(2, 1);
+ writer.writeSfixed64(2, 1);
+
+ // Write fixed 32-bit encoded fields.
+ writer.writeInt32(3, sentinel);
+ writer.writeFloat(3, 1);
+ writer.writeFixed32(3, 1);
+ writer.writeSfixed32(3, 1);
+
+ // Write delimited fields.
+ writer.writeInt32(4, sentinel);
+ writer.writeBytes(4, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
+ writer.writeString(4, 'The quick brown fox jumps over the lazy dog');
+
+ // Write a group with a nested group inside.
+ writer.writeInt32(5, sentinel);
+ var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
+ writer.writeGroup(5, dummyMessage, function() {
+ writer.writeInt64(42, 42);
+ writer.writeGroup(6, dummyMessage, function() {
+ writer.writeInt64(84, 42);
+ });
+ });
+
+ // Write final sentinel.
+ writer.writeInt32(6, sentinel);
+
+ var reader = jspb.BinaryReader.alloc(writer.getResultBuffer());
+
+ function skip(field, count) {
+ for (var i = 0; i < count; i++) {
+ reader.nextField();
+ if (field != reader.getFieldNumber()) throw 'fail!';
+ reader.skipField();
+ }
+ }
+
+ reader.nextField();
+ assertEquals(1, reader.getFieldNumber());
+ assertEquals(sentinel, reader.readInt32());
+ skip(1, 4);
+
+ reader.nextField();
+ assertEquals(2, reader.getFieldNumber());
+ assertEquals(sentinel, reader.readInt32());
+ skip(2, 3);
+
+ reader.nextField();
+ assertEquals(3, reader.getFieldNumber());
+ assertEquals(sentinel, reader.readInt32());
+ skip(3, 3);
+
+ reader.nextField();
+ assertEquals(4, reader.getFieldNumber());
+ assertEquals(sentinel, reader.readInt32());
+ skip(4, 2);
+
+ reader.nextField();
+ assertEquals(5, reader.getFieldNumber());
+ assertEquals(sentinel, reader.readInt32());
+ skip(5, 1);
+
+ reader.nextField();
+ assertEquals(6, reader.getFieldNumber());
+ assertEquals(sentinel, reader.readInt32());
+ });
+
+
+ /**
+ * Tests packed fields.
+ */
+ it('testPackedFields', function() {
+ var writer = new jspb.BinaryWriter();
+
+ var sentinel = 123456789;
+
+ var unsignedData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
+ var signedData = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10];
+ var floatData = [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10];
+ var doubleData = [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.10];
+ var boolData = [true, false, true, true, false, false, true, false];
+
+ for (var i = 0; i < floatData.length; i++) {
+ floatData[i] = truncate(floatData[i]);
+ }
+
+ writer.writeInt32(1, sentinel);
+
+ writer.writePackedInt32(2, signedData);
+ writer.writePackedInt64(2, signedData);
+ writer.writePackedUint32(2, unsignedData);
+ writer.writePackedUint64(2, unsignedData);
+ writer.writePackedSint32(2, signedData);
+ writer.writePackedSint64(2, signedData);
+ writer.writePackedFixed32(2, unsignedData);
+ writer.writePackedFixed64(2, unsignedData);
+ writer.writePackedSfixed32(2, signedData);
+ writer.writePackedSfixed64(2, signedData);
+ writer.writePackedFloat(2, floatData);
+ writer.writePackedDouble(2, doubleData);
+ writer.writePackedBool(2, boolData);
+ writer.writePackedEnum(2, unsignedData);
+
+ writer.writeInt32(3, sentinel);
+
+ var reader = jspb.BinaryReader.alloc(writer.getResultBuffer());
+
+ reader.nextField();
+ assertEquals(sentinel, reader.readInt32());
+
+ reader.nextField();
+ assertElementsEquals(reader.readPackedInt32(), signedData);
+
+ reader.nextField();
+ assertElementsEquals(reader.readPackedInt64(), signedData);
+
+ reader.nextField();
+ assertElementsEquals(reader.readPackedUint32(), unsignedData);
+
+ reader.nextField();
+ assertElementsEquals(reader.readPackedUint64(), unsignedData);
+
+ reader.nextField();
+ assertElementsEquals(reader.readPackedSint32(), signedData);
+
+ reader.nextField();
+ assertElementsEquals(reader.readPackedSint64(), signedData);
+
+ reader.nextField();
+ assertElementsEquals(reader.readPackedFixed32(), unsignedData);
+
+ reader.nextField();
+ assertElementsEquals(reader.readPackedFixed64(), unsignedData);
+
+ reader.nextField();
+ assertElementsEquals(reader.readPackedSfixed32(), signedData);
+
+ reader.nextField();
+ assertElementsEquals(reader.readPackedSfixed64(), signedData);
+
+ reader.nextField();
+ assertElementsEquals(reader.readPackedFloat(), floatData);
+
+ reader.nextField();
+ assertElementsEquals(reader.readPackedDouble(), doubleData);
+
+ reader.nextField();
+ assertElementsEquals(reader.readPackedBool(), boolData);
+
+ reader.nextField();
+ assertElementsEquals(reader.readPackedEnum(), unsignedData);
+
+ reader.nextField();
+ assertEquals(sentinel, reader.readInt32());
+ });
+
+
+ /**
+ * Byte blobs inside nested messages should always have their byte offset set
+ * relative to the start of the outermost blob, not the start of their parent
+ * blob.
+ */
+ it('testNestedBlobs', function() {
+ // Create a proto consisting of two nested messages, with the inner one
+ // containing a blob of bytes.
+
+ var fieldTag = (1 << 3) | jspb.BinaryConstants.WireType.DELIMITED;
+ var blob = [1, 2, 3, 4, 5];
+ var writer = new jspb.BinaryWriter();
+ var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
+
+ writer.writeMessage(1, dummyMessage, function() {
+ writer.writeMessage(1, dummyMessage, function() {
+ writer.writeBytes(1, blob);
+ });
+ });
+
+ // Peel off the outer two message layers. Each layer should have two bytes
+ // of overhead, one for the field tag and one for the length of the inner
+ // blob.
+
+ var decoder1 = new jspb.BinaryDecoder(writer.getResultBuffer());
+ assertEquals(fieldTag, decoder1.readUnsignedVarint32());
+ assertEquals(blob.length + 4, decoder1.readUnsignedVarint32());
+
+ var decoder2 = new jspb.BinaryDecoder(decoder1.readBytes(blob.length + 4));
+ assertEquals(fieldTag, decoder2.readUnsignedVarint32());
+ assertEquals(blob.length + 2, decoder2.readUnsignedVarint32());
+
+ assertEquals(fieldTag, decoder2.readUnsignedVarint32());
+ assertEquals(blob.length, decoder2.readUnsignedVarint32());
+ var bytes = decoder2.readBytes(blob.length);
+
+ assertElementsEquals(bytes, blob);
+ });
+
+
+ /**
+ * Tests read callbacks.
+ */
+ it('testReadCallbacks', function() {
+ var writer = new jspb.BinaryWriter();
+ var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
+
+ // Add an int, a submessage, and another int.
+ writer.writeInt32(1, 100);
+
+ writer.writeMessage(2, dummyMessage, function() {
+ writer.writeInt32(3, 300);
+ writer.writeInt32(4, 400);
+ writer.writeInt32(5, 500);
+ });
+
+ writer.writeInt32(7, 700);
+
+ // Create the reader and register a custom read callback.
+ var reader = jspb.BinaryReader.alloc(writer.getResultBuffer());
+
+ /**
+ * @param {!jspb.BinaryReader} reader
+ * @return {*}
+ */
+ function readCallback(reader) {
+ reader.nextField();
+ assertEquals(3, reader.getFieldNumber());
+ assertEquals(300, reader.readInt32());
+
+ reader.nextField();
+ assertEquals(4, reader.getFieldNumber());
+ assertEquals(400, reader.readInt32());
+
+ reader.nextField();
+ assertEquals(5, reader.getFieldNumber());
+ assertEquals(500, reader.readInt32());
+
+ assertEquals(false, reader.nextField());
+ };
+
+ reader.registerReadCallback('readCallback', readCallback);
+
+ // Read the container message.
+ reader.nextField();
+ assertEquals(1, reader.getFieldNumber());
+ assertEquals(100, reader.readInt32());
+
+ reader.nextField();
+ assertEquals(2, reader.getFieldNumber());
+ reader.readMessage(dummyMessage, function() {
+ // Decode the embedded message using the registered callback.
+ reader.runReadCallback('readCallback');
+ });
+
+ reader.nextField();
+ assertEquals(7, reader.getFieldNumber());
+ assertEquals(700, reader.readInt32());
+
+ assertEquals(false, reader.nextField());
+ });
+});
diff --git a/third_party/protobuf/js/binary/utils.js b/third_party/protobuf/js/binary/utils.js
new file mode 100644
index 0000000000..3ecd08e9f3
--- /dev/null
+++ b/third_party/protobuf/js/binary/utils.js
@@ -0,0 +1,989 @@
+// 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.
+
+/**
+ * @fileoverview This file contains helper code used by jspb.BinaryReader
+ * and BinaryWriter.
+ *
+ * @author aappleby@google.com (Austin Appleby)
+ */
+
+goog.provide('jspb.utils');
+
+goog.require('goog.asserts');
+goog.require('goog.crypt.base64');
+goog.require('goog.string');
+goog.require('jspb.BinaryConstants');
+
+
+/**
+ * Javascript can't natively handle 64-bit data types, so to manipulate them we
+ * have to split them into two 32-bit halves and do the math manually.
+ *
+ * Instead of instantiating and passing small structures around to do this, we
+ * instead just use two global temporary values. This one stores the low 32
+ * bits of a split value - for example, if the original value was a 64-bit
+ * integer, this temporary value will contain the low 32 bits of that integer.
+ * If the original value was a double, this temporary value will contain the
+ * low 32 bits of the binary representation of that double, etcetera.
+ * @type {number}
+ */
+jspb.utils.split64Low = 0;
+
+
+/**
+ * And correspondingly, this temporary variable will contain the high 32 bits
+ * of whatever value was split.
+ * @type {number}
+ */
+jspb.utils.split64High = 0;
+
+
+/**
+ * Splits an unsigned Javascript integer into two 32-bit halves and stores it
+ * in the temp values above.
+ * @param {number} value The number to split.
+ */
+jspb.utils.splitUint64 = function(value) {
+ // Extract low 32 bits and high 32 bits as unsigned integers.
+ var lowBits = value >>> 0;
+ var highBits = Math.floor((value - lowBits) /
+ jspb.BinaryConstants.TWO_TO_32) >>> 0;
+
+ jspb.utils.split64Low = lowBits;
+ jspb.utils.split64High = highBits;
+};
+
+
+/**
+ * Splits a signed Javascript integer into two 32-bit halves and stores it in
+ * the temp values above.
+ * @param {number} value The number to split.
+ */
+jspb.utils.splitInt64 = function(value) {
+ // Convert to sign-magnitude representation.
+ var sign = (value < 0);
+ value = Math.abs(value);
+
+ // Extract low 32 bits and high 32 bits as unsigned integers.
+ var lowBits = value >>> 0;
+ var highBits = Math.floor((value - lowBits) /
+ jspb.BinaryConstants.TWO_TO_32);
+ highBits = highBits >>> 0;
+
+ // Perform two's complement conversion if the sign bit was set.
+ if (sign) {
+ highBits = ~highBits >>> 0;
+ lowBits = ~lowBits >>> 0;
+ lowBits += 1;
+ if (lowBits > 0xFFFFFFFF) {
+ lowBits = 0;
+ highBits++;
+ if (highBits > 0xFFFFFFFF) highBits = 0;
+ }
+ }
+
+ jspb.utils.split64Low = lowBits;
+ jspb.utils.split64High = highBits;
+};
+
+
+/**
+ * Convers a signed Javascript integer into zigzag format, splits it into two
+ * 32-bit halves, and stores it in the temp values above.
+ * @param {number} value The number to split.
+ */
+jspb.utils.splitZigzag64 = function(value) {
+ // Convert to sign-magnitude and scale by 2 before we split the value.
+ var sign = (value < 0);
+ value = Math.abs(value) * 2;
+
+ jspb.utils.splitUint64(value);
+ var lowBits = jspb.utils.split64Low;
+ var highBits = jspb.utils.split64High;
+
+ // If the value is negative, subtract 1 from the split representation so we
+ // don't lose the sign bit due to precision issues.
+ if (sign) {
+ if (lowBits == 0) {
+ if (highBits == 0) {
+ lowBits = 0xFFFFFFFF;
+ highBits = 0xFFFFFFFF;
+ } else {
+ highBits--;
+ lowBits = 0xFFFFFFFF;
+ }
+ } else {
+ lowBits--;
+ }
+ }
+
+ jspb.utils.split64Low = lowBits;
+ jspb.utils.split64High = highBits;
+};
+
+
+/**
+ * Converts a floating-point number into 32-bit IEEE representation and stores
+ * it in the temp values above.
+ * @param {number} value
+ */
+jspb.utils.splitFloat32 = function(value) {
+ var sign = (value < 0) ? 1 : 0;
+ value = sign ? -value : value;
+ var exp;
+ var mant;
+
+ // Handle zeros.
+ if (value === 0) {
+ if ((1 / value) > 0) {
+ // Positive zero.
+ jspb.utils.split64High = 0;
+ jspb.utils.split64Low = 0x00000000;
+ } else {
+ // Negative zero.
+ jspb.utils.split64High = 0;
+ jspb.utils.split64Low = 0x80000000;
+ }
+ return;
+ }
+
+ // Handle nans.
+ if (isNaN(value)) {
+ jspb.utils.split64High = 0;
+ jspb.utils.split64Low = 0x7FFFFFFF;
+ return;
+ }
+
+ // Handle infinities.
+ if (value > jspb.BinaryConstants.FLOAT32_MAX) {
+ jspb.utils.split64High = 0;
+ jspb.utils.split64Low = ((sign << 31) | (0x7F800000)) >>> 0;
+ return;
+ }
+
+ // Handle denormals.
+ if (value < jspb.BinaryConstants.FLOAT32_MIN) {
+ // Number is a denormal.
+ mant = Math.round(value / Math.pow(2, -149));
+ jspb.utils.split64High = 0;
+ jspb.utils.split64Low = ((sign << 31) | mant) >>> 0;
+ return;
+ }
+
+ exp = Math.floor(Math.log(value) / Math.LN2);
+ mant = value * Math.pow(2, -exp);
+ mant = Math.round(mant * jspb.BinaryConstants.TWO_TO_23) & 0x7FFFFF;
+
+ jspb.utils.split64High = 0;
+ jspb.utils.split64Low = ((sign << 31) | ((exp + 127) << 23) | mant) >>> 0;
+};
+
+
+/**
+ * Converts a floating-point number into 64-bit IEEE representation and stores
+ * it in the temp values above.
+ * @param {number} value
+ */
+jspb.utils.splitFloat64 = function(value) {
+ var sign = (value < 0) ? 1 : 0;
+ value = sign ? -value : value;
+
+ // Handle zeros.
+ if (value === 0) {
+ if ((1 / value) > 0) {
+ // Positive zero.
+ jspb.utils.split64High = 0x00000000;
+ jspb.utils.split64Low = 0x00000000;
+ } else {
+ // Negative zero.
+ jspb.utils.split64High = 0x80000000;
+ jspb.utils.split64Low = 0x00000000;
+ }
+ return;
+ }
+
+ // Handle nans.
+ if (isNaN(value)) {
+ jspb.utils.split64High = 0x7FFFFFFF;
+ jspb.utils.split64Low = 0xFFFFFFFF;
+ return;
+ }
+
+ // Handle infinities.
+ if (value > jspb.BinaryConstants.FLOAT64_MAX) {
+ jspb.utils.split64High = ((sign << 31) | (0x7FF00000)) >>> 0;
+ jspb.utils.split64Low = 0;
+ return;
+ }
+
+ // Handle denormals.
+ if (value < jspb.BinaryConstants.FLOAT64_MIN) {
+ // Number is a denormal.
+ var mant = value / Math.pow(2, -1074);
+ var mantHigh = (mant / jspb.BinaryConstants.TWO_TO_32);
+ jspb.utils.split64High = ((sign << 31) | mantHigh) >>> 0;
+ jspb.utils.split64Low = (mant >>> 0);
+ return;
+ }
+
+ var exp = Math.floor(Math.log(value) / Math.LN2);
+ if (exp == 1024) exp = 1023;
+ var mant = value * Math.pow(2, -exp);
+
+ var mantHigh = (mant * jspb.BinaryConstants.TWO_TO_20) & 0xFFFFF;
+ var mantLow = (mant * jspb.BinaryConstants.TWO_TO_52) >>> 0;
+
+ jspb.utils.split64High =
+ ((sign << 31) | ((exp + 1023) << 20) | mantHigh) >>> 0;
+ jspb.utils.split64Low = mantLow;
+};
+
+
+/**
+ * Converts an 8-character hash string into two 32-bit numbers and stores them
+ * in the temp values above.
+ * @param {string} hash
+ */
+jspb.utils.splitHash64 = function(hash) {
+ var a = hash.charCodeAt(0);
+ var b = hash.charCodeAt(1);
+ var c = hash.charCodeAt(2);
+ var d = hash.charCodeAt(3);
+ var e = hash.charCodeAt(4);
+ var f = hash.charCodeAt(5);
+ var g = hash.charCodeAt(6);
+ var h = hash.charCodeAt(7);
+
+ jspb.utils.split64Low = (a + (b << 8) + (c << 16) + (d << 24)) >>> 0;
+ jspb.utils.split64High = (e + (f << 8) + (g << 16) + (h << 24)) >>> 0;
+};
+
+
+/**
+ * Joins two 32-bit values into a 64-bit unsigned integer. Precision will be
+ * lost if the result is greater than 2^52.
+ * @param {number} bitsLow
+ * @param {number} bitsHigh
+ * @return {number}
+ */
+jspb.utils.joinUint64 = function(bitsLow, bitsHigh) {
+ return bitsHigh * jspb.BinaryConstants.TWO_TO_32 + bitsLow;
+};
+
+
+/**
+ * Joins two 32-bit values into a 64-bit signed integer. Precision will be lost
+ * if the result is greater than 2^52.
+ * @param {number} bitsLow
+ * @param {number} bitsHigh
+ * @return {number}
+ */
+jspb.utils.joinInt64 = function(bitsLow, bitsHigh) {
+ // If the high bit is set, do a manual two's complement conversion.
+ var sign = (bitsHigh & 0x80000000);
+ if (sign) {
+ bitsLow = (~bitsLow + 1) >>> 0;
+ bitsHigh = ~bitsHigh >>> 0;
+ if (bitsLow == 0) {
+ bitsHigh = (bitsHigh + 1) >>> 0;
+ }
+ }
+
+ var result = jspb.utils.joinUint64(bitsLow, bitsHigh);
+ return sign ? -result : result;
+};
+
+
+/**
+ * Joins two 32-bit values into a 64-bit unsigned integer and applies zigzag
+ * decoding. Precision will be lost if the result is greater than 2^52.
+ * @param {number} bitsLow
+ * @param {number} bitsHigh
+ * @return {number}
+ */
+jspb.utils.joinZigzag64 = function(bitsLow, bitsHigh) {
+ // Extract the sign bit and shift right by one.
+ var sign = bitsLow & 1;
+ bitsLow = ((bitsLow >>> 1) | (bitsHigh << 31)) >>> 0;
+ bitsHigh = bitsHigh >>> 1;
+
+ // Increment the split value if the sign bit was set.
+ if (sign) {
+ bitsLow = (bitsLow + 1) >>> 0;
+ if (bitsLow == 0) {
+ bitsHigh = (bitsHigh + 1) >>> 0;
+ }
+ }
+
+ var result = jspb.utils.joinUint64(bitsLow, bitsHigh);
+ return sign ? -result : result;
+};
+
+
+/**
+ * Joins two 32-bit values into a 32-bit IEEE floating point number and
+ * converts it back into a Javascript number.
+ * @param {number} bitsLow The low 32 bits of the binary number;
+ * @param {number} bitsHigh The high 32 bits of the binary number.
+ * @return {number}
+ */
+jspb.utils.joinFloat32 = function(bitsLow, bitsHigh) {
+ var sign = ((bitsLow >> 31) * 2 + 1);
+ var exp = (bitsLow >>> 23) & 0xFF;
+ var mant = bitsLow & 0x7FFFFF;
+
+ if (exp == 0xFF) {
+ if (mant) {
+ return NaN;
+ } else {
+ return sign * Infinity;
+ }
+ }
+
+ if (exp == 0) {
+ // Denormal.
+ return sign * Math.pow(2, -149) * mant;
+ } else {
+ return sign * Math.pow(2, exp - 150) *
+ (mant + Math.pow(2, 23));
+ }
+};
+
+
+/**
+ * Joins two 32-bit values into a 64-bit IEEE floating point number and
+ * converts it back into a Javascript number.
+ * @param {number} bitsLow The low 32 bits of the binary number;
+ * @param {number} bitsHigh The high 32 bits of the binary number.
+ * @return {number}
+ */
+jspb.utils.joinFloat64 = function(bitsLow, bitsHigh) {
+ var sign = ((bitsHigh >> 31) * 2 + 1);
+ var exp = (bitsHigh >>> 20) & 0x7FF;
+ var mant = jspb.BinaryConstants.TWO_TO_32 * (bitsHigh & 0xFFFFF) + bitsLow;
+
+ if (exp == 0x7FF) {
+ if (mant) {
+ return NaN;
+ } else {
+ return sign * Infinity;
+ }
+ }
+
+ if (exp == 0) {
+ // Denormal.
+ return sign * Math.pow(2, -1074) * mant;
+ } else {
+ return sign * Math.pow(2, exp - 1075) *
+ (mant + jspb.BinaryConstants.TWO_TO_52);
+ }
+};
+
+
+/**
+ * Joins two 32-bit values into an 8-character hash string.
+ * @param {number} bitsLow
+ * @param {number} bitsHigh
+ * @return {string}
+ */
+jspb.utils.joinHash64 = function(bitsLow, bitsHigh) {
+ var a = (bitsLow >>> 0) & 0xFF;
+ var b = (bitsLow >>> 8) & 0xFF;
+ var c = (bitsLow >>> 16) & 0xFF;
+ var d = (bitsLow >>> 24) & 0xFF;
+ var e = (bitsHigh >>> 0) & 0xFF;
+ var f = (bitsHigh >>> 8) & 0xFF;
+ var g = (bitsHigh >>> 16) & 0xFF;
+ var h = (bitsHigh >>> 24) & 0xFF;
+
+ return String.fromCharCode(a, b, c, d, e, f, g, h);
+};
+
+
+/**
+ * Individual digits for number->string conversion.
+ * @const {!Array.<number>}
+ */
+jspb.utils.DIGITS = [
+ '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
+];
+
+
+/**
+ * Losslessly converts a 64-bit unsigned integer in 32:32 split representation
+ * into a decimal string.
+ * @param {number} bitsLow The low 32 bits of the binary number;
+ * @param {number} bitsHigh The high 32 bits of the binary number.
+ * @return {string} The binary number represented as a string.
+ */
+jspb.utils.joinUnsignedDecimalString = function(bitsLow, bitsHigh) {
+ // Skip the expensive conversion if the number is small enough to use the
+ // built-in conversions.
+ if (bitsHigh <= 0x1FFFFF) {
+ return '' + (jspb.BinaryConstants.TWO_TO_32 * bitsHigh + bitsLow);
+ }
+
+ // What this code is doing is essentially converting the input number from
+ // base-2 to base-1e7, which allows us to represent the 64-bit range with
+ // only 3 (very large) digits. Those digits are then trivial to convert to
+ // a base-10 string.
+
+ // The magic numbers used here are -
+ // 2^24 = 16777216 = (1,6777216) in base-1e7.
+ // 2^48 = 281474976710656 = (2,8147497,6710656) in base-1e7.
+
+ // Split 32:32 representation into 16:24:24 representation so our
+ // intermediate digits don't overflow.
+ var low = bitsLow & 0xFFFFFF;
+ var mid = (((bitsLow >>> 24) | (bitsHigh << 8)) >>> 0) & 0xFFFFFF;
+ var high = (bitsHigh >> 16) & 0xFFFF;
+
+ // Assemble our three base-1e7 digits, ignoring carries. The maximum
+ // value in a digit at this step is representable as a 48-bit integer, which
+ // can be stored in a 64-bit floating point number.
+ var digitA = low + (mid * 6777216) + (high * 6710656);
+ var digitB = mid + (high * 8147497);
+ var digitC = (high * 2);
+
+ // Apply carries from A to B and from B to C.
+ var base = 10000000;
+ if (digitA >= base) {
+ digitB += Math.floor(digitA / base);
+ digitA %= base;
+ }
+
+ if (digitB >= base) {
+ digitC += Math.floor(digitB / base);
+ digitB %= base;
+ }
+
+ // Convert base-1e7 digits to base-10, omitting leading zeroes.
+ var table = jspb.utils.DIGITS;
+ var start = false;
+ var result = '';
+
+ function emit(digit) {
+ var temp = base;
+ for (var i = 0; i < 7; i++) {
+ temp /= 10;
+ var decimalDigit = ((digit / temp) % 10) >>> 0;
+ if ((decimalDigit == 0) && !start) continue;
+ start = true;
+ result += table[decimalDigit];
+ }
+ }
+
+ if (digitC || start) emit(digitC);
+ if (digitB || start) emit(digitB);
+ if (digitA || start) emit(digitA);
+
+ return result;
+};
+
+
+/**
+ * Losslessly converts a 64-bit signed integer in 32:32 split representation
+ * into a decimal string.
+ * @param {number} bitsLow The low 32 bits of the binary number;
+ * @param {number} bitsHigh The high 32 bits of the binary number.
+ * @return {string} The binary number represented as a string.
+ */
+jspb.utils.joinSignedDecimalString = function(bitsLow, bitsHigh) {
+ // If we're treating the input as a signed value and the high bit is set, do
+ // a manual two's complement conversion before the decimal conversion.
+ var negative = (bitsHigh & 0x80000000);
+ if (negative) {
+ bitsLow = (~bitsLow + 1) >>> 0;
+ var carry = (bitsLow == 0) ? 1 : 0;
+ bitsHigh = (~bitsHigh + carry) >>> 0;
+ }
+
+ var result = jspb.utils.joinUnsignedDecimalString(bitsLow, bitsHigh);
+ return negative ? '-' + result : result;
+};
+
+
+/**
+ * Convert an 8-character hash string representing either a signed or unsigned
+ * 64-bit integer into its decimal representation without losing accuracy.
+ * @param {string} hash The hash string to convert.
+ * @param {boolean} signed True if we should treat the hash string as encoding
+ * a signed integer.
+ * @return {string}
+ */
+jspb.utils.hash64ToDecimalString = function(hash, signed) {
+ jspb.utils.splitHash64(hash);
+ var bitsLow = jspb.utils.split64Low;
+ var bitsHigh = jspb.utils.split64High;
+ return signed ?
+ jspb.utils.joinSignedDecimalString(bitsLow, bitsHigh) :
+ jspb.utils.joinUnsignedDecimalString(bitsLow, bitsHigh);
+};
+
+
+/**
+ * Converts an array of 8-character hash strings into their decimal
+ * representations.
+ * @param {!Array.<string>} hashes The array of hash strings to convert.
+ * @param {boolean} signed True if we should treat the hash string as encoding
+ * a signed integer.
+ * @return {!Array.<string>}
+ */
+jspb.utils.hash64ArrayToDecimalStrings = function(hashes, signed) {
+ var result = new Array(hashes.length);
+ for (var i = 0; i < hashes.length; i++) {
+ result[i] = jspb.utils.hash64ToDecimalString(hashes[i], signed);
+ }
+ return result;
+};
+
+
+/**
+ * Converts a signed or unsigned decimal string into its hash string
+ * representation.
+ * @param {string} dec
+ * @return {string}
+ */
+jspb.utils.decimalStringToHash64 = function(dec) {
+ goog.asserts.assert(dec.length > 0);
+
+ // Check for minus sign.
+ var minus = false;
+ if (dec[0] === '-') {
+ minus = true;
+ dec = dec.slice(1);
+ }
+
+ // Store result as a byte array.
+ var resultBytes = [0, 0, 0, 0, 0, 0, 0, 0];
+
+ // Set result to m*result + c.
+ function muladd(m, c) {
+ for (var i = 0; i < 8 && (m !== 1 || c > 0); i++) {
+ var r = m * resultBytes[i] + c;
+ resultBytes[i] = r & 0xFF;
+ c = r >>> 8;
+ }
+ }
+
+ // Negate the result bits.
+ function neg() {
+ for (var i = 0; i < 8; i++) {
+ resultBytes[i] = (~resultBytes[i]) & 0xFF;
+ }
+ }
+
+ // For each decimal digit, set result to 10*result + digit.
+ for (var i = 0; i < dec.length; i++) {
+ muladd(10, jspb.utils.DIGITS.indexOf(dec[i]));
+ }
+
+ // If there's a minus sign, convert into two's complement.
+ if (minus) {
+ neg();
+ muladd(1, 1);
+ }
+
+ return String.fromCharCode.apply(null, resultBytes);
+};
+
+
+/**
+ * Converts a signed or unsigned decimal string into two 32-bit halves, and
+ * stores them in the temp variables listed above.
+ * @param {string} value The decimal string to convert.
+ */
+jspb.utils.splitDecimalString = function(value) {
+ jspb.utils.splitHash64(jspb.utils.decimalStringToHash64(value));
+};
+
+
+/**
+ * Converts an 8-character hash string into its hexadecimal representation.
+ * @param {string} hash
+ * @return {string}
+ */
+jspb.utils.hash64ToHexString = function(hash) {
+ var temp = new Array(18);
+ temp[0] = '0';
+ temp[1] = 'x';
+
+ for (var i = 0; i < 8; i++) {
+ var c = hash.charCodeAt(7 - i);
+ temp[i * 2 + 2] = jspb.utils.DIGITS[c >> 4];
+ temp[i * 2 + 3] = jspb.utils.DIGITS[c & 0xF];
+ }
+
+ var result = temp.join('');
+ return result;
+};
+
+
+/**
+ * Converts a '0x<16 digits>' hex string into its hash string representation.
+ * @param {string} hex
+ * @return {string}
+ */
+jspb.utils.hexStringToHash64 = function(hex) {
+ hex = hex.toLowerCase();
+ goog.asserts.assert(hex.length == 18);
+ goog.asserts.assert(hex[0] == '0');
+ goog.asserts.assert(hex[1] == 'x');
+
+ var result = '';
+ for (var i = 0; i < 8; i++) {
+ var hi = jspb.utils.DIGITS.indexOf(hex[i * 2 + 2]);
+ var lo = jspb.utils.DIGITS.indexOf(hex[i * 2 + 3]);
+ result = String.fromCharCode(hi * 16 + lo) + result;
+ }
+
+ return result;
+};
+
+
+/**
+ * Convert an 8-character hash string representing either a signed or unsigned
+ * 64-bit integer into a Javascript number. Will lose accuracy if the result is
+ * larger than 2^52.
+ * @param {string} hash The hash string to convert.
+ * @param {boolean} signed True if the has should be interpreted as a signed
+ * number.
+ * @return {number}
+ */
+jspb.utils.hash64ToNumber = function(hash, signed) {
+ jspb.utils.splitHash64(hash);
+ var bitsLow = jspb.utils.split64Low;
+ var bitsHigh = jspb.utils.split64High;
+ return signed ? jspb.utils.joinInt64(bitsLow, bitsHigh) :
+ jspb.utils.joinUint64(bitsLow, bitsHigh);
+};
+
+
+/**
+ * Convert a Javascript number into an 8-character hash string. Will lose
+ * precision if the value is non-integral or greater than 2^64.
+ * @param {number} value The integer to convert.
+ * @return {string}
+ */
+jspb.utils.numberToHash64 = function(value) {
+ jspb.utils.splitInt64(value);
+ return jspb.utils.joinHash64(jspb.utils.split64Low,
+ jspb.utils.split64High);
+};
+
+
+/**
+ * Counts the number of contiguous varints in a buffer.
+ * @param {!Uint8Array} buffer The buffer to scan.
+ * @param {number} start The starting point in the buffer to scan.
+ * @param {number} end The end point in the buffer to scan.
+ * @return {number} The number of varints in the buffer.
+ */
+jspb.utils.countVarints = function(buffer, start, end) {
+ // Count how many high bits of each byte were set in the buffer.
+ var count = 0;
+ for (var i = start; i < end; i++) {
+ count += buffer[i] >> 7;
+ }
+
+ // The number of varints in the buffer equals the size of the buffer minus
+ // the number of non-terminal bytes in the buffer (those with the high bit
+ // set).
+ return (end - start) - count;
+};
+
+
+/**
+ * Counts the number of contiguous varint fields with the given field number in
+ * the buffer.
+ * @param {!Uint8Array} buffer The buffer to scan.
+ * @param {number} start The starting point in the buffer to scan.
+ * @param {number} end The end point in the buffer to scan.
+ * @param {number} field The field number to count.
+ * @return {number} The number of matching fields in the buffer.
+ */
+jspb.utils.countVarintFields = function(buffer, start, end, field) {
+ var count = 0;
+ var cursor = start;
+ var tag = field * 8 + jspb.BinaryConstants.WireType.VARINT;
+
+ if (tag < 128) {
+ // Single-byte field tag, we can use a slightly quicker count.
+ while (cursor < end) {
+ // Skip the field tag, or exit if we find a non-matching tag.
+ if (buffer[cursor++] != tag) return count;
+
+ // Field tag matches, we've found a valid field.
+ count++;
+
+ // Skip the varint.
+ while (1) {
+ var x = buffer[cursor++];
+ if ((x & 0x80) == 0) break;
+ }
+ }
+ } else {
+ while (cursor < end) {
+ // Skip the field tag, or exit if we find a non-matching tag.
+ var temp = tag;
+ while (temp > 128) {
+ if (buffer[cursor] != ((temp & 0x7F) | 0x80)) return count;
+ cursor++;
+ temp >>= 7;
+ }
+ if (buffer[cursor++] != temp) return count;
+
+ // Field tag matches, we've found a valid field.
+ count++;
+
+ // Skip the varint.
+ while (1) {
+ var x = buffer[cursor++];
+ if ((x & 0x80) == 0) break;
+ }
+ }
+ }
+ return count;
+};
+
+
+/**
+ * Counts the number of contiguous fixed32 fields with the given tag in the
+ * buffer.
+ * @param {!Uint8Array} buffer The buffer to scan.
+ * @param {number} start The starting point in the buffer to scan.
+ * @param {number} end The end point in the buffer to scan.
+ * @param {number} tag The tag value to count.
+ * @param {number} stride The number of bytes to skip per field.
+ * @return {number} The number of fields with a matching tag in the buffer.
+ * @private
+ */
+jspb.utils.countFixedFields_ =
+ function(buffer, start, end, tag, stride) {
+ var count = 0;
+ var cursor = start;
+
+ if (tag < 128) {
+ // Single-byte field tag, we can use a slightly quicker count.
+ while (cursor < end) {
+ // Skip the field tag, or exit if we find a non-matching tag.
+ if (buffer[cursor++] != tag) return count;
+
+ // Field tag matches, we've found a valid field.
+ count++;
+
+ // Skip the value.
+ cursor += stride;
+ }
+ } else {
+ while (cursor < end) {
+ // Skip the field tag, or exit if we find a non-matching tag.
+ var temp = tag;
+ while (temp > 128) {
+ if (buffer[cursor++] != ((temp & 0x7F) | 0x80)) return count;
+ temp >>= 7;
+ }
+ if (buffer[cursor++] != temp) return count;
+
+ // Field tag matches, we've found a valid field.
+ count++;
+
+ // Skip the value.
+ cursor += stride;
+ }
+ }
+ return count;
+};
+
+
+/**
+ * Counts the number of contiguous fixed32 fields with the given field number
+ * in the buffer.
+ * @param {!Uint8Array} buffer The buffer to scan.
+ * @param {number} start The starting point in the buffer to scan.
+ * @param {number} end The end point in the buffer to scan.
+ * @param {number} field The field number to count.
+ * @return {number} The number of matching fields in the buffer.
+ */
+jspb.utils.countFixed32Fields = function(buffer, start, end, field) {
+ var tag = field * 8 + jspb.BinaryConstants.WireType.FIXED32;
+ return jspb.utils.countFixedFields_(buffer, start, end, tag, 4);
+};
+
+
+/**
+ * Counts the number of contiguous fixed64 fields with the given field number
+ * in the buffer.
+ * @param {!Uint8Array} buffer The buffer to scan.
+ * @param {number} start The starting point in the buffer to scan.
+ * @param {number} end The end point in the buffer to scan.
+ * @param {number} field The field number to count
+ * @return {number} The number of matching fields in the buffer.
+ */
+jspb.utils.countFixed64Fields = function(buffer, start, end, field) {
+ var tag = field * 8 + jspb.BinaryConstants.WireType.FIXED64;
+ return jspb.utils.countFixedFields_(buffer, start, end, tag, 8);
+};
+
+
+/**
+ * Counts the number of contiguous delimited fields with the given field number
+ * in the buffer.
+ * @param {!Uint8Array} buffer The buffer to scan.
+ * @param {number} start The starting point in the buffer to scan.
+ * @param {number} end The end point in the buffer to scan.
+ * @param {number} field The field number to count.
+ * @return {number} The number of matching fields in the buffer.
+ */
+jspb.utils.countDelimitedFields = function(buffer, start, end, field) {
+ var count = 0;
+ var cursor = start;
+ var tag = field * 8 + jspb.BinaryConstants.WireType.DELIMITED;
+
+ while (cursor < end) {
+ // Skip the field tag, or exit if we find a non-matching tag.
+ var temp = tag;
+ while (temp > 128) {
+ if (buffer[cursor++] != ((temp & 0x7F) | 0x80)) return count;
+ temp >>= 7;
+ }
+ if (buffer[cursor++] != temp) return count;
+
+ // Field tag matches, we've found a valid field.
+ count++;
+
+ // Decode the length prefix.
+ var length = 0;
+ var shift = 1;
+ while (1) {
+ temp = buffer[cursor++];
+ length += (temp & 0x7f) * shift;
+ shift *= 128;
+ if ((temp & 0x80) == 0) break;
+ }
+
+ // Advance the cursor past the blob.
+ cursor += length;
+ }
+ return count;
+};
+
+
+/**
+ * String-ify bytes for text format. Should be optimized away in non-debug.
+ * The returned string uses \xXX escapes for all values and is itself quoted.
+ * [1, 31] serializes to '"\x01\x1f"'.
+ * @param {jspb.ByteSource} byteSource The bytes to serialize.
+ * @return {string} Stringified bytes for text format.
+ */
+jspb.utils.debugBytesToTextFormat = function(byteSource) {
+ var s = '"';
+ if (byteSource) {
+ var bytes = jspb.utils.byteSourceToUint8Array(byteSource);
+ for (var i = 0; i < bytes.length; i++) {
+ s += '\\x';
+ if (bytes[i] < 16) s += '0';
+ s += bytes[i].toString(16);
+ }
+ }
+ return s + '"';
+};
+
+
+/**
+ * String-ify a scalar for text format. Should be optimized away in non-debug.
+ * @param {string|number|boolean} scalar The scalar to stringify.
+ * @return {string} Stringified scalar for text format.
+ */
+jspb.utils.debugScalarToTextFormat = function(scalar) {
+ if (goog.isString(scalar)) {
+ return goog.string.quote(scalar);
+ } else {
+ return scalar.toString();
+ }
+};
+
+
+/**
+ * Utility function: convert a string with codepoints 0--255 inclusive to a
+ * Uint8Array. If any codepoints greater than 255 exist in the string, throws an
+ * exception.
+ * @param {string} str
+ * @return {!Uint8Array}
+ */
+jspb.utils.stringToByteArray = function(str) {
+ var arr = new Uint8Array(str.length);
+ for (var i = 0; i < str.length; i++) {
+ var codepoint = str.charCodeAt(i);
+ if (codepoint > 255) {
+ throw new Error('Conversion error: string contains codepoint ' +
+ 'outside of byte range');
+ }
+ arr[i] = codepoint;
+ }
+ return arr;
+};
+
+
+/**
+ * Converts any type defined in jspb.ByteSource into a Uint8Array.
+ * @param {!jspb.ByteSource} data
+ * @return {!Uint8Array}
+ * @suppress {invalidCasts}
+ */
+jspb.utils.byteSourceToUint8Array = function(data) {
+ if (data.constructor === Uint8Array) {
+ return /** @type {!Uint8Array} */(data);
+ }
+
+ if (data.constructor === ArrayBuffer) {
+ data = /** @type {!ArrayBuffer} */(data);
+ return /** @type {!Uint8Array} */(new Uint8Array(data));
+ }
+
+ if (data.constructor === Buffer) {
+ return /** @type {!Uint8Array} */(new Uint8Array(data));
+ }
+
+ if (data.constructor === Array) {
+ data = /** @type {!Array.<number>} */(data);
+ return /** @type {!Uint8Array} */(new Uint8Array(data));
+ }
+
+ if (data.constructor === String) {
+ data = /** @type {string} */(data);
+ return goog.crypt.base64.decodeStringToUint8Array(data);
+ }
+
+ goog.asserts.fail('Type not convertible to Uint8Array.');
+ return /** @type {!Uint8Array} */(new Uint8Array(0));
+};
diff --git a/third_party/protobuf/js/binary/utils_test.js b/third_party/protobuf/js/binary/utils_test.js
new file mode 100644
index 0000000000..d27e5ea2c6
--- /dev/null
+++ b/third_party/protobuf/js/binary/utils_test.js
@@ -0,0 +1,668 @@
+// 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.
+
+/**
+ * @fileoverview Test cases for jspb's helper functions.
+ *
+ * Test suite is written using Jasmine -- see http://jasmine.github.io/
+ *
+ * @author aappleby@google.com (Austin Appleby)
+ */
+
+goog.require('goog.crypt.base64');
+goog.require('goog.testing.asserts');
+goog.require('jspb.BinaryConstants');
+goog.require('jspb.BinaryWriter');
+goog.require('jspb.utils');
+
+
+/**
+ * @param {number} x
+ * @return {number}
+ */
+function truncate(x) {
+ var temp = new Float32Array(1);
+ temp[0] = x;
+ return temp[0];
+}
+
+
+/**
+ * Converts an 64-bit integer in split representation to a 64-bit hash string
+ * (8 bits encoded per character).
+ * @param {number} bitsLow The low 32 bits of the split 64-bit integer.
+ * @param {number} bitsHigh The high 32 bits of the split 64-bit integer.
+ * @return {string} The encoded hash string, 8 bits per character.
+ */
+function toHashString(bitsLow, bitsHigh) {
+ return String.fromCharCode((bitsLow >>> 0) & 0xFF,
+ (bitsLow >>> 8) & 0xFF,
+ (bitsLow >>> 16) & 0xFF,
+ (bitsLow >>> 24) & 0xFF,
+ (bitsHigh >>> 0) & 0xFF,
+ (bitsHigh >>> 8) & 0xFF,
+ (bitsHigh >>> 16) & 0xFF,
+ (bitsHigh >>> 24) & 0xFF);
+}
+
+
+describe('binaryUtilsTest', function() {
+ /**
+ * Tests lossless binary-to-decimal conversion.
+ */
+ it('testDecimalConversion', function() {
+ // Check some magic numbers.
+ var result =
+ jspb.utils.joinUnsignedDecimalString(0x89e80001, 0x8ac72304);
+ assertEquals('10000000000000000001', result);
+
+ result = jspb.utils.joinUnsignedDecimalString(0xacd05f15, 0x1b69b4b);
+ assertEquals('123456789123456789', result);
+
+ result = jspb.utils.joinUnsignedDecimalString(0xeb1f0ad2, 0xab54a98c);
+ assertEquals('12345678901234567890', result);
+
+ result = jspb.utils.joinUnsignedDecimalString(0xe3b70cb1, 0x891087b8);
+ assertEquals('9876543210987654321', result);
+
+ // Check limits.
+ result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x00000000);
+ assertEquals('0', result);
+
+ result = jspb.utils.joinUnsignedDecimalString(0xFFFFFFFF, 0xFFFFFFFF);
+ assertEquals('18446744073709551615', result);
+
+ // Check each bit of the low dword.
+ for (var i = 0; i < 32; i++) {
+ var low = (1 << i) >>> 0;
+ result = jspb.utils.joinUnsignedDecimalString(low, 0);
+ assertEquals('' + Math.pow(2, i), result);
+ }
+
+ // Check the first 20 bits of the high dword.
+ for (var i = 0; i < 20; i++) {
+ var high = (1 << i) >>> 0;
+ result = jspb.utils.joinUnsignedDecimalString(0, high);
+ assertEquals('' + Math.pow(2, 32 + i), result);
+ }
+
+ // V8's internal double-to-string conversion is inaccurate for values above
+ // 2^52, even if they're representable integers - check the rest of the bits
+ // manually against the correct string representations of 2^N.
+
+ result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x00100000);
+ assertEquals('4503599627370496', result);
+
+ result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x00200000);
+ assertEquals('9007199254740992', result);
+
+ result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x00400000);
+ assertEquals('18014398509481984', result);
+
+ result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x00800000);
+ assertEquals('36028797018963968', result);
+
+ result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x01000000);
+ assertEquals('72057594037927936', result);
+
+ result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x02000000);
+ assertEquals('144115188075855872', result);
+
+ result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x04000000);
+ assertEquals('288230376151711744', result);
+
+ result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x08000000);
+ assertEquals('576460752303423488', result);
+
+ result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x10000000);
+ assertEquals('1152921504606846976', result);
+
+ result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x20000000);
+ assertEquals('2305843009213693952', result);
+
+ result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x40000000);
+ assertEquals('4611686018427387904', result);
+
+ result = jspb.utils.joinUnsignedDecimalString(0x00000000, 0x80000000);
+ assertEquals('9223372036854775808', result);
+ });
+
+
+ /**
+ * Going from hash strings to decimal strings should also be lossless.
+ */
+ it('testHashToDecimalConversion', function() {
+ var result;
+ var convert = jspb.utils.hash64ToDecimalString;
+
+ result = convert(toHashString(0x00000000, 0x00000000), false);
+ assertEquals('0', result);
+
+ result = convert(toHashString(0x00000000, 0x00000000), true);
+ assertEquals('0', result);
+
+ result = convert(toHashString(0xFFFFFFFF, 0xFFFFFFFF), false);
+ assertEquals('18446744073709551615', result);
+
+ result = convert(toHashString(0xFFFFFFFF, 0xFFFFFFFF), true);
+ assertEquals('-1', result);
+
+ result = convert(toHashString(0x00000000, 0x80000000), false);
+ assertEquals('9223372036854775808', result);
+
+ result = convert(toHashString(0x00000000, 0x80000000), true);
+ assertEquals('-9223372036854775808', result);
+
+ result = convert(toHashString(0xacd05f15, 0x01b69b4b), false);
+ assertEquals('123456789123456789', result);
+
+ result = convert(toHashString(~0xacd05f15 + 1, ~0x01b69b4b), true);
+ assertEquals('-123456789123456789', result);
+
+ // And converting arrays of hashes should work the same way.
+ result = jspb.utils.hash64ArrayToDecimalStrings([
+ toHashString(0xFFFFFFFF, 0xFFFFFFFF),
+ toHashString(0x00000000, 0x80000000),
+ toHashString(0xacd05f15, 0x01b69b4b)], false);
+ assertEquals(3, result.length);
+ assertEquals('18446744073709551615', result[0]);
+ assertEquals('9223372036854775808', result[1]);
+ assertEquals('123456789123456789', result[2]);
+ });
+
+ /*
+ * Going from decimal strings to hash strings should be lossless.
+ */
+ it('testDecimalToHashConversion', function() {
+ var result;
+ var convert = jspb.utils.decimalStringToHash64;
+
+ result = convert('0');
+ assertEquals(String.fromCharCode.apply(null,
+ [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), result);
+
+ result = convert('-1');
+ assertEquals(String.fromCharCode.apply(null,
+ [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), result);
+
+ result = convert('18446744073709551615');
+ assertEquals(String.fromCharCode.apply(null,
+ [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), result);
+
+ result = convert('9223372036854775808');
+ assertEquals(String.fromCharCode.apply(null,
+ [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80]), result);
+
+ result = convert('-9223372036854775808');
+ assertEquals(String.fromCharCode.apply(null,
+ [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80]), result);
+
+ result = convert('123456789123456789');
+ assertEquals(String.fromCharCode.apply(null,
+ [0x15, 0x5F, 0xD0, 0xAC, 0x4B, 0x9B, 0xB6, 0x01]), result);
+
+ result = convert('-123456789123456789');
+ assertEquals(String.fromCharCode.apply(null,
+ [0xEB, 0xA0, 0x2F, 0x53, 0xB4, 0x64, 0x49, 0xFE]), result);
+ });
+
+ /**
+ * Going from hash strings to hex strings should be lossless.
+ */
+ it('testHashToHexConversion', function() {
+ var result;
+ var convert = jspb.utils.hash64ToHexString;
+
+ result = convert(toHashString(0x00000000, 0x00000000));
+ assertEquals('0x0000000000000000', result);
+
+ result = convert(toHashString(0xFFFFFFFF, 0xFFFFFFFF));
+ assertEquals('0xffffffffffffffff', result);
+
+ result = convert(toHashString(0x12345678, 0x9ABCDEF0));
+ assertEquals('0x9abcdef012345678', result);
+ });
+
+
+ /**
+ * Going from hex strings to hash strings should be lossless.
+ */
+ it('testHexToHashConversion', function() {
+ var result;
+ var convert = jspb.utils.hexStringToHash64;
+
+ result = convert('0x0000000000000000');
+ assertEquals(String.fromCharCode.apply(null,
+ [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), result);
+
+ result = convert('0xffffffffffffffff');
+ assertEquals(String.fromCharCode.apply(null,
+ [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), result);
+
+ // Hex string is big-endian, hash string is little-endian.
+ result = convert('0x123456789ABCDEF0');
+ assertEquals(String.fromCharCode.apply(null,
+ [0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12]), result);
+
+ // Capitalization should not matter.
+ result = convert('0x0000abcdefABCDEF');
+ assertEquals(String.fromCharCode.apply(null,
+ [0xEF, 0xCD, 0xAB, 0xEF, 0xCD, 0xAB, 0x00, 0x00]), result);
+ });
+
+
+ /**
+ * Going from numbers to hash strings should be lossless for up to 53 bits of
+ * precision.
+ */
+ it('testNumberToHashConversion', function() {
+ var result;
+ var convert = jspb.utils.numberToHash64;
+
+ result = convert(0x0000000000000);
+ assertEquals('0x0000000000000000', jspb.utils.hash64ToHexString(result));
+
+ result = convert(0xFFFFFFFFFFFFF);
+ assertEquals('0x000fffffffffffff', jspb.utils.hash64ToHexString(result));
+
+ result = convert(0x123456789ABCD);
+ assertEquals('0x000123456789abcd', jspb.utils.hash64ToHexString(result));
+
+ result = convert(0xDCBA987654321);
+ assertEquals('0x000dcba987654321', jspb.utils.hash64ToHexString(result));
+
+ // 53 bits of precision should not be truncated.
+ result = convert(0x10000000000001);
+ assertEquals('0x0010000000000001', jspb.utils.hash64ToHexString(result));
+
+ // 54 bits of precision should be truncated.
+ result = convert(0x20000000000001);
+ assertNotEquals(
+ '0x0020000000000001', jspb.utils.hash64ToHexString(result));
+ });
+
+
+ /**
+ * Sanity check the behavior of Javascript's strings when doing funny things
+ * with unicode characters.
+ */
+ it('sanityCheckUnicodeStrings', function() {
+ var strings = new Array(65536);
+
+ // All possible unsigned 16-bit values should be storable in a string, they
+ // shouldn't do weird things with the length of the string, and they should
+ // come back out of the string unchanged.
+ for (var i = 0; i < 65536; i++) {
+ strings[i] = 'a' + String.fromCharCode(i) + 'a';
+ if (3 != strings[i].length) throw 'fail!';
+ if (i != strings[i].charCodeAt(1)) throw 'fail!';
+ }
+
+ // Each unicode character should compare equal to itself and not equal to a
+ // different unicode character.
+ for (var i = 0; i < 65536; i++) {
+ if (strings[i] != strings[i]) throw 'fail!';
+ if (strings[i] == strings[(i + 1) % 65536]) throw 'fail!';
+ }
+ });
+
+
+ /**
+ * Tests conversion from 32-bit floating point numbers to split64 numbers.
+ */
+ it('testFloat32ToSplit64', function() {
+ var f32_eps = jspb.BinaryConstants.FLOAT32_EPS;
+ var f32_min = jspb.BinaryConstants.FLOAT32_MIN;
+ var f32_max = jspb.BinaryConstants.FLOAT32_MAX;
+
+ // NaN.
+ jspb.utils.splitFloat32(NaN);
+ if (!isNaN(jspb.utils.joinFloat32(jspb.utils.split64Low,
+ jspb.utils.split64High))) {
+ throw 'fail!';
+ }
+
+ /**
+ * @param {number} x
+ * @param {number=} opt_bits
+ */
+ function test(x, opt_bits) {
+ jspb.utils.splitFloat32(x);
+ if (goog.isDef(opt_bits)) {
+ if (opt_bits != jspb.utils.split64Low) throw 'fail!';
+ }
+ if (truncate(x) != jspb.utils.joinFloat32(jspb.utils.split64Low,
+ jspb.utils.split64High)) {
+ throw 'fail!';
+ }
+ }
+
+ // Positive and negative infinity.
+ test(Infinity, 0x7f800000);
+ test(-Infinity, 0xff800000);
+
+ // Positive and negative zero.
+ test(0, 0x00000000);
+ test(-0, 0x80000000);
+
+ // Positive and negative epsilon.
+ test(f32_eps, 0x00000001);
+ test(-f32_eps, 0x80000001);
+
+ // Positive and negative min.
+ test(f32_min, 0x00800000);
+ test(-f32_min, 0x80800000);
+
+ // Positive and negative max.
+ test(f32_max, 0x7F7FFFFF);
+ test(-f32_max, 0xFF7FFFFF);
+
+ // Various positive values.
+ var cursor = f32_eps * 10;
+ while (cursor != Infinity) {
+ test(cursor);
+ cursor *= 1.1;
+ }
+
+ // Various negative values.
+ cursor = -f32_eps * 10;
+ while (cursor != -Infinity) {
+ test(cursor);
+ cursor *= 1.1;
+ }
+ });
+
+
+ /**
+ * Tests conversion from 64-bit floating point numbers to split64 numbers.
+ */
+ it('testFloat64ToSplit64', function() {
+ var f64_eps = jspb.BinaryConstants.FLOAT64_EPS;
+ var f64_min = jspb.BinaryConstants.FLOAT64_MIN;
+ var f64_max = jspb.BinaryConstants.FLOAT64_MAX;
+
+ // NaN.
+ jspb.utils.splitFloat64(NaN);
+ if (!isNaN(jspb.utils.joinFloat64(jspb.utils.split64Low,
+ jspb.utils.split64High))) {
+ throw 'fail!';
+ }
+
+ /**
+ * @param {number} x
+ * @param {number=} opt_highBits
+ * @param {number=} opt_lowBits
+ */
+ function test(x, opt_highBits, opt_lowBits) {
+ jspb.utils.splitFloat64(x);
+ if (goog.isDef(opt_highBits)) {
+ if (opt_highBits != jspb.utils.split64High) throw 'fail!';
+ }
+ if (goog.isDef(opt_lowBits)) {
+ if (opt_lowBits != jspb.utils.split64Low) throw 'fail!';
+ }
+ if (x != jspb.utils.joinFloat64(jspb.utils.split64Low,
+ jspb.utils.split64High)) {
+ throw 'fail!';
+ }
+ }
+
+ // Positive and negative infinity.
+ test(Infinity, 0x7ff00000, 0x00000000);
+ test(-Infinity, 0xfff00000, 0x00000000);
+
+ // Positive and negative zero.
+ test(0, 0x00000000, 0x00000000);
+ test(-0, 0x80000000, 0x00000000);
+
+ // Positive and negative epsilon.
+ test(f64_eps, 0x00000000, 0x00000001);
+ test(-f64_eps, 0x80000000, 0x00000001);
+
+ // Positive and negative min.
+ test(f64_min, 0x00100000, 0x00000000);
+ test(-f64_min, 0x80100000, 0x00000000);
+
+ // Positive and negative max.
+ test(f64_max, 0x7FEFFFFF, 0xFFFFFFFF);
+ test(-f64_max, 0xFFEFFFFF, 0xFFFFFFFF);
+
+ // Various positive values.
+ var cursor = f64_eps * 10;
+ while (cursor != Infinity) {
+ test(cursor);
+ cursor *= 1.1;
+ }
+
+ // Various negative values.
+ cursor = -f64_eps * 10;
+ while (cursor != -Infinity) {
+ test(cursor);
+ cursor *= 1.1;
+ }
+ });
+
+
+ /**
+ * Tests counting packed varints.
+ */
+ it('testCountVarints', function() {
+ var values = [];
+ for (var i = 1; i < 1000000000; i *= 1.1) {
+ values.push(Math.floor(i));
+ }
+
+ var writer = new jspb.BinaryWriter();
+ writer.writePackedUint64(1, values);
+
+ var buffer = new Uint8Array(writer.getResultBuffer());
+
+ // We should have two more varints than we started with - one for the field
+ // tag, one for the packed length.
+ assertEquals(values.length + 2,
+ jspb.utils.countVarints(buffer, 0, buffer.length));
+ });
+
+
+ /**
+ * Tests counting matching varint fields.
+ */
+ it('testCountVarintFields', function() {
+ var writer = new jspb.BinaryWriter();
+
+ var count = 0;
+ for (var i = 1; i < 1000000000; i *= 1.1) {
+ writer.writeUint64(1, Math.floor(i));
+ count++;
+ }
+ writer.writeString(2, 'terminator');
+
+ var buffer = new Uint8Array(writer.getResultBuffer());
+ assertEquals(count,
+ jspb.utils.countVarintFields(buffer, 0, buffer.length, 1));
+
+ writer = new jspb.BinaryWriter();
+
+ count = 0;
+ for (var i = 1; i < 1000000000; i *= 1.1) {
+ writer.writeUint64(123456789, Math.floor(i));
+ count++;
+ }
+ writer.writeString(2, 'terminator');
+
+ buffer = new Uint8Array(writer.getResultBuffer());
+ assertEquals(count,
+ jspb.utils.countVarintFields(buffer, 0, buffer.length, 123456789));
+ });
+
+
+ /**
+ * Tests counting matching fixed32 fields.
+ */
+ it('testCountFixed32Fields', function() {
+ var writer = new jspb.BinaryWriter();
+
+ var count = 0;
+ for (var i = 1; i < 1000000000; i *= 1.1) {
+ writer.writeFixed32(1, Math.floor(i));
+ count++;
+ }
+ writer.writeString(2, 'terminator');
+
+ var buffer = new Uint8Array(writer.getResultBuffer());
+ assertEquals(count,
+ jspb.utils.countFixed32Fields(buffer, 0, buffer.length, 1));
+
+ writer = new jspb.BinaryWriter();
+
+ count = 0;
+ for (var i = 1; i < 1000000000; i *= 1.1) {
+ writer.writeFixed32(123456789, Math.floor(i));
+ count++;
+ }
+ writer.writeString(2, 'terminator');
+
+ buffer = new Uint8Array(writer.getResultBuffer());
+ assertEquals(count,
+ jspb.utils.countFixed32Fields(buffer, 0, buffer.length, 123456789));
+ });
+
+
+ /**
+ * Tests counting matching fixed64 fields.
+ */
+ it('testCountFixed64Fields', function() {
+ var writer = new jspb.BinaryWriter();
+
+ var count = 0;
+ for (var i = 1; i < 1000000000; i *= 1.1) {
+ writer.writeDouble(1, i);
+ count++;
+ }
+ writer.writeString(2, 'terminator');
+
+ var buffer = new Uint8Array(writer.getResultBuffer());
+ assertEquals(count,
+ jspb.utils.countFixed64Fields(buffer, 0, buffer.length, 1));
+
+ writer = new jspb.BinaryWriter();
+
+ count = 0;
+ for (var i = 1; i < 1000000000; i *= 1.1) {
+ writer.writeDouble(123456789, i);
+ count++;
+ }
+ writer.writeString(2, 'terminator');
+
+ buffer = new Uint8Array(writer.getResultBuffer());
+ assertEquals(count,
+ jspb.utils.countFixed64Fields(buffer, 0, buffer.length, 123456789));
+ });
+
+
+ /**
+ * Tests counting matching delimited fields.
+ */
+ it('testCountDelimitedFields', function() {
+ var writer = new jspb.BinaryWriter();
+
+ var count = 0;
+ for (var i = 1; i < 1000; i *= 1.1) {
+ writer.writeBytes(1, [Math.floor(i)]);
+ count++;
+ }
+ writer.writeString(2, 'terminator');
+
+ var buffer = new Uint8Array(writer.getResultBuffer());
+ assertEquals(count,
+ jspb.utils.countDelimitedFields(buffer, 0, buffer.length, 1));
+
+ writer = new jspb.BinaryWriter();
+
+ count = 0;
+ for (var i = 1; i < 1000; i *= 1.1) {
+ writer.writeBytes(123456789, [Math.floor(i)]);
+ count++;
+ }
+ writer.writeString(2, 'terminator');
+
+ buffer = new Uint8Array(writer.getResultBuffer());
+ assertEquals(count,
+ jspb.utils.countDelimitedFields(buffer, 0, buffer.length, 123456789));
+ });
+
+
+ /**
+ * Tests byte format for debug strings.
+ */
+ it('testDebugBytesToTextFormat', function() {
+ assertEquals('""', jspb.utils.debugBytesToTextFormat(null));
+ assertEquals('"\\x00\\x10\\xff"',
+ jspb.utils.debugBytesToTextFormat([0, 16, 255]));
+ });
+
+
+ /**
+ * Tests converting byte blob sources into byte blobs.
+ */
+ it('testByteSourceToUint8Array', function() {
+ var convert = jspb.utils.byteSourceToUint8Array;
+
+ var sourceData = [];
+ for (var i = 0; i < 256; i++) {
+ sourceData.push(i);
+ }
+
+ var sourceBytes = new Uint8Array(sourceData);
+ var sourceBuffer = sourceBytes.buffer;
+ var sourceBase64 = goog.crypt.base64.encodeByteArray(sourceData);
+ var sourceString = String.fromCharCode.apply(null, sourceData);
+
+ function check(result) {
+ assertEquals(Uint8Array, result.constructor);
+ assertEquals(sourceData.length, result.length);
+ for (var i = 0; i < result.length; i++) {
+ assertEquals(sourceData[i], result[i]);
+ }
+ }
+
+ // Converting Uint8Arrays into Uint8Arrays should be a no-op.
+ assertEquals(sourceBytes, convert(sourceBytes));
+
+ // Converting Array.<numbers> into Uint8Arrays should work.
+ check(convert(sourceData));
+
+ // Converting ArrayBuffers into Uint8Arrays should work.
+ check(convert(sourceBuffer));
+
+ // Converting base64-encoded strings into Uint8Arrays should work.
+ check(convert(sourceBase64));
+ });
+});
diff --git a/third_party/protobuf/js/binary/writer.js b/third_party/protobuf/js/binary/writer.js
new file mode 100644
index 0000000000..c3009dbb54
--- /dev/null
+++ b/third_party/protobuf/js/binary/writer.js
@@ -0,0 +1,1590 @@
+// 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.
+
+/**
+ * @fileoverview This file contains utilities for encoding Javascript objects
+ * into binary, wire-format protocol buffers (in the form of Uint8Arrays) that
+ * a server can consume directly.
+ *
+ * jspb's BinaryWriter class defines methods for efficiently encoding
+ * Javascript objects into binary, wire-format protocol buffers and supports
+ * all the fundamental field types used in protocol buffers.
+ *
+ * Major caveat 1 - Users of this library _must_ keep their Javascript proto
+ * parsing code in sync with the original .proto file - presumably you'll be
+ * using the typed jspb code generator, but if you bypass that you'll need
+ * to keep things in sync by hand.
+ *
+ * Major caveat 2 - Javascript is unable to accurately represent integers
+ * larger than 2^53 due to its use of a double-precision floating point format
+ * for all numbers. BinaryWriter does not make any special effort to preserve
+ * precision for values above this limit - if you need to pass 64-bit integers
+ * (hash codes, for example) between the client and server without precision
+ * loss, do _not_ use this library.
+ *
+ * Major caveat 3 - This class uses typed arrays and must not be used on older
+ * browsers that do not support them.
+ *
+ * @author aappleby@google.com (Austin Appleby)
+ */
+
+goog.provide('jspb.BinaryWriter');
+
+goog.require('goog.asserts');
+goog.require('goog.crypt.base64');
+goog.require('jspb.BinaryConstants');
+goog.require('jspb.BinaryEncoder');
+goog.require('jspb.arith.Int64');
+goog.require('jspb.arith.UInt64');
+goog.require('jspb.utils');
+
+
+
+/**
+ * BinaryWriter implements encoders for all the wire types specified in
+ * https://developers.google.com/protocol-buffers/docs/encoding.
+ *
+ * @constructor
+ * @struct
+ */
+jspb.BinaryWriter = function() {
+ /**
+ * Blocks of serialized data that will be concatenated once all messages have
+ * been written.
+ * @private {!Array<!Uint8Array|!Array<number>>}
+ */
+ this.blocks_ = [];
+
+ /**
+ * Total number of bytes in the blocks_ array. Does _not_ include bytes in
+ * the encoder below.
+ * @private {number}
+ */
+ this.totalLength_ = 0;
+
+ /**
+ * Binary encoder holding pieces of a message that we're still serializing.
+ * When we get to a stopping point (either the start of a new submessage, or
+ * when we need to append a raw Uint8Array), the encoder's buffer will be
+ * added to the block array above and the encoder will be reset.
+ * @private {!jspb.BinaryEncoder}
+ */
+ this.encoder_ = new jspb.BinaryEncoder();
+
+ /**
+ * A stack of bookmarks containing the parent blocks for each message started
+ * via beginSubMessage(), needed as bookkeeping for endSubMessage().
+ * TODO(aappleby): Deprecated, users should be calling writeMessage().
+ * @private {!Array.<!Array.<number>>}
+ */
+ this.bookmarks_ = [];
+};
+
+
+/**
+ * Append a typed array of bytes onto the buffer.
+ *
+ * @param {!Uint8Array} arr The byte array to append.
+ * @private
+ */
+jspb.BinaryWriter.prototype.appendUint8Array_ = function(arr) {
+ var temp = this.encoder_.end();
+ this.blocks_.push(temp);
+ this.blocks_.push(arr);
+ this.totalLength_ += temp.length + arr.length;
+};
+
+
+/**
+ * Begins a new message by writing the field header and returning a bookmark
+ * which we will use to patch in the message length to in endDelimited_ below.
+ * @param {number} field
+ * @return {!Array.<number>}
+ * @private
+ */
+jspb.BinaryWriter.prototype.beginDelimited_ = function(field) {
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
+ var bookmark = this.encoder_.end();
+ this.blocks_.push(bookmark);
+ this.totalLength_ += bookmark.length;
+ bookmark.push(this.totalLength_);
+ return bookmark;
+};
+
+
+/**
+ * Ends a message by encoding the _change_ in length of the buffer to the
+ * parent block and adds the number of bytes needed to encode that length to
+ * the total byte length.
+ * @param {!Array.<number>} bookmark
+ * @private
+ */
+jspb.BinaryWriter.prototype.endDelimited_ = function(bookmark) {
+ var oldLength = bookmark.pop();
+ var messageLength = this.totalLength_ + this.encoder_.length() - oldLength;
+ goog.asserts.assert(messageLength >= 0);
+
+ while (messageLength > 127) {
+ bookmark.push((messageLength & 0x7f) | 0x80);
+ messageLength = messageLength >>> 7;
+ this.totalLength_++;
+ }
+
+ bookmark.push(messageLength);
+ this.totalLength_++;
+};
+
+
+/**
+ * Writes a pre-serialized message to the buffer.
+ * @param {!Uint8Array} bytes The array of bytes to write.
+ * @param {number} start The start of the range to write.
+ * @param {number} end The end of the range to write.
+ */
+jspb.BinaryWriter.prototype.writeSerializedMessage = function(
+ bytes, start, end) {
+ this.appendUint8Array_(bytes.subarray(start, end));
+};
+
+
+/**
+ * Writes a pre-serialized message to the buffer if the message and endpoints
+ * are non-null.
+ * @param {?Uint8Array} bytes The array of bytes to write.
+ * @param {?number} start The start of the range to write.
+ * @param {?number} end The end of the range to write.
+ */
+jspb.BinaryWriter.prototype.maybeWriteSerializedMessage = function(
+ bytes, start, end) {
+ if (bytes != null && start != null && end != null) {
+ this.writeSerializedMessage(bytes, start, end);
+ }
+};
+
+
+/**
+ * Resets the writer, throwing away any accumulated buffers.
+ */
+jspb.BinaryWriter.prototype.reset = function() {
+ this.blocks_ = [];
+ this.encoder_.end();
+ this.totalLength_ = 0;
+ this.bookmarks_ = [];
+};
+
+
+/**
+ * Converts the encoded data into a Uint8Array.
+ * @return {!Uint8Array}
+ */
+jspb.BinaryWriter.prototype.getResultBuffer = function() {
+ goog.asserts.assert(this.bookmarks_.length == 0);
+
+ var flat = new Uint8Array(this.totalLength_ + this.encoder_.length());
+
+ var blocks = this.blocks_;
+ var blockCount = blocks.length;
+ var offset = 0;
+
+ for (var i = 0; i < blockCount; i++) {
+ var block = blocks[i];
+ flat.set(block, offset);
+ offset += block.length;
+ }
+
+ var tail = this.encoder_.end();
+ flat.set(tail, offset);
+ offset += tail.length;
+
+ // Post condition: `flattened` must have had every byte written.
+ goog.asserts.assert(offset == flat.length);
+
+ // Replace our block list with the flattened block, which lets GC reclaim
+ // the temp blocks sooner.
+ this.blocks_ = [flat];
+
+ return flat;
+};
+
+
+/**
+ * Converts the encoded data into a bas64-encoded string.
+ * @return {string}
+ */
+jspb.BinaryWriter.prototype.getResultBase64String = function() {
+ return goog.crypt.base64.encodeByteArray(this.getResultBuffer());
+};
+
+
+/**
+ * Begins a new sub-message. The client must call endSubMessage() when they're
+ * done.
+ * TODO(aappleby): Deprecated. Move callers to writeMessage().
+ * @param {number} field The field number of the sub-message.
+ */
+jspb.BinaryWriter.prototype.beginSubMessage = function(field) {
+ this.bookmarks_.push(this.beginDelimited_(field));
+};
+
+
+/**
+ * Finishes a sub-message and packs it into the parent messages' buffer.
+ * TODO(aappleby): Deprecated. Move callers to writeMessage().
+ */
+jspb.BinaryWriter.prototype.endSubMessage = function() {
+ goog.asserts.assert(this.bookmarks_.length >= 0);
+ this.endDelimited_(this.bookmarks_.pop());
+};
+
+
+/**
+ * Encodes a (field number, wire type) tuple into a wire-format field header
+ * and stores it in the buffer as a varint.
+ * @param {number} field The field number.
+ * @param {number} wireType The wire-type of the field, as specified in the
+ * protocol buffer documentation.
+ * @private
+ */
+jspb.BinaryWriter.prototype.writeFieldHeader_ =
+ function(field, wireType) {
+ goog.asserts.assert(field >= 1 && field == Math.floor(field));
+ var x = field * 8 + wireType;
+ this.encoder_.writeUnsignedVarint32(x);
+};
+
+
+/**
+ * Writes a field of any valid scalar type to the binary stream.
+ * @param {jspb.BinaryConstants.FieldType} fieldType
+ * @param {number} field
+ * @param {jspb.AnyFieldType} value
+ */
+jspb.BinaryWriter.prototype.writeAny = function(fieldType, field, value) {
+ var fieldTypes = jspb.BinaryConstants.FieldType;
+ switch (fieldType) {
+ case fieldTypes.DOUBLE:
+ this.writeDouble(field, /** @type {number} */(value));
+ return;
+ case fieldTypes.FLOAT:
+ this.writeFloat(field, /** @type {number} */(value));
+ return;
+ case fieldTypes.INT64:
+ this.writeInt64(field, /** @type {number} */(value));
+ return;
+ case fieldTypes.UINT64:
+ this.writeUint64(field, /** @type {number} */(value));
+ return;
+ case fieldTypes.INT32:
+ this.writeInt32(field, /** @type {number} */(value));
+ return;
+ case fieldTypes.FIXED64:
+ this.writeFixed64(field, /** @type {number} */(value));
+ return;
+ case fieldTypes.FIXED32:
+ this.writeFixed32(field, /** @type {number} */(value));
+ return;
+ case fieldTypes.BOOL:
+ this.writeBool(field, /** @type {boolean} */(value));
+ return;
+ case fieldTypes.STRING:
+ this.writeString(field, /** @type {string} */(value));
+ return;
+ case fieldTypes.GROUP:
+ goog.asserts.fail('Group field type not supported in writeAny()');
+ return;
+ case fieldTypes.MESSAGE:
+ goog.asserts.fail('Message field type not supported in writeAny()');
+ return;
+ case fieldTypes.BYTES:
+ this.writeBytes(field, /** @type {?Uint8Array} */(value));
+ return;
+ case fieldTypes.UINT32:
+ this.writeUint32(field, /** @type {number} */(value));
+ return;
+ case fieldTypes.ENUM:
+ this.writeEnum(field, /** @type {number} */(value));
+ return;
+ case fieldTypes.SFIXED32:
+ this.writeSfixed32(field, /** @type {number} */(value));
+ return;
+ case fieldTypes.SFIXED64:
+ this.writeSfixed64(field, /** @type {number} */(value));
+ return;
+ case fieldTypes.SINT32:
+ this.writeSint32(field, /** @type {number} */(value));
+ return;
+ case fieldTypes.SINT64:
+ this.writeSint64(field, /** @type {number} */(value));
+ return;
+ case fieldTypes.FHASH64:
+ this.writeFixedHash64(field, /** @type {string} */(value));
+ return;
+ case fieldTypes.VHASH64:
+ this.writeVarintHash64(field, /** @type {string} */(value));
+ return;
+ default:
+ goog.asserts.fail('Invalid field type in writeAny()');
+ return;
+ }
+};
+
+
+/**
+ * Writes a varint field to the buffer without range checking.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ * @private
+ */
+jspb.BinaryWriter.prototype.writeUnsignedVarint32_ = function(field, value) {
+ if (value == null) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT);
+ this.encoder_.writeUnsignedVarint32(value);
+};
+
+
+/**
+ * Writes a varint field to the buffer without range checking.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ * @private
+ */
+jspb.BinaryWriter.prototype.writeSignedVarint32_ = function(field, value) {
+ if (value == null) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT);
+ this.encoder_.writeSignedVarint32(value);
+};
+
+
+/**
+ * Writes a varint field to the buffer without range checking.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ * @private
+ */
+jspb.BinaryWriter.prototype.writeUnsignedVarint64_ = function(field, value) {
+ if (value == null) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT);
+ this.encoder_.writeUnsignedVarint64(value);
+};
+
+
+/**
+ * Writes a varint field to the buffer without range checking.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ * @private
+ */
+jspb.BinaryWriter.prototype.writeSignedVarint64_ = function(field, value) {
+ if (value == null) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT);
+ this.encoder_.writeSignedVarint64(value);
+};
+
+
+/**
+ * Writes a zigzag varint field to the buffer without range checking.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ * @private
+ */
+jspb.BinaryWriter.prototype.writeZigzagVarint32_ = function(field, value) {
+ if (value == null) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT);
+ this.encoder_.writeZigzagVarint32(value);
+};
+
+
+/**
+ * Writes a zigzag varint field to the buffer without range checking.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ * @private
+ */
+jspb.BinaryWriter.prototype.writeZigzagVarint64_ = function(field, value) {
+ if (value == null) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT);
+ this.encoder_.writeZigzagVarint64(value);
+};
+
+
+/**
+ * Writes a zigzag varint field to the buffer without range checking.
+ * @param {number} field The field number.
+ * @param {string?} value The value to write.
+ * @private
+ */
+jspb.BinaryWriter.prototype.writeZigzagVarint64String_ = function(
+ field, value) {
+ if (value == null) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT);
+ this.encoder_.writeZigzagVarint64String(value);
+};
+
+
+/**
+ * Writes an int32 field to the buffer. Numbers outside the range [-2^31,2^31)
+ * will be truncated.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeInt32 = function(field, value) {
+ if (value == null) return;
+ goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_31) &&
+ (value < jspb.BinaryConstants.TWO_TO_31));
+ this.writeSignedVarint32_(field, value);
+};
+
+
+/**
+ * Writes an int32 field represented as a string to the buffer. Numbers outside
+ * the range [-2^31,2^31) will be truncated.
+ * @param {number} field The field number.
+ * @param {string?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeInt32String = function(field, value) {
+ if (value == null) return;
+ var intValue = /** {number} */ parseInt(value, 10);
+ goog.asserts.assert((intValue >= -jspb.BinaryConstants.TWO_TO_31) &&
+ (intValue < jspb.BinaryConstants.TWO_TO_31));
+ this.writeSignedVarint32_(field, intValue);
+};
+
+
+/**
+ * Writes an int64 field to the buffer. Numbers outside the range [-2^63,2^63)
+ * will be truncated.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeInt64 = function(field, value) {
+ if (value == null) return;
+ goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_63) &&
+ (value < jspb.BinaryConstants.TWO_TO_63));
+ this.writeSignedVarint64_(field, value);
+};
+
+
+/**
+ * Writes a int64 field (with value as a string) to the buffer.
+ * @param {number} field The field number.
+ * @param {string?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeInt64String = function(field, value) {
+ if (value == null) return;
+ var num = jspb.arith.Int64.fromString(value);
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT);
+ this.encoder_.writeSplitVarint64(num.lo, num.hi);
+};
+
+
+/**
+ * Writes a uint32 field to the buffer. Numbers outside the range [0,2^32)
+ * will be truncated.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeUint32 = function(field, value) {
+ if (value == null) return;
+ goog.asserts.assert((value >= 0) &&
+ (value < jspb.BinaryConstants.TWO_TO_32));
+ this.writeUnsignedVarint32_(field, value);
+};
+
+
+/**
+ * Writes a uint32 field represented as a string to the buffer. Numbers outside
+ * the range [0,2^32) will be truncated.
+ * @param {number} field The field number.
+ * @param {string?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeUint32String = function(field, value) {
+ if (value == null) return;
+ var intValue = /** {number} */ parseInt(value, 10);
+ goog.asserts.assert((intValue >= 0) &&
+ (intValue < jspb.BinaryConstants.TWO_TO_32));
+ this.writeUnsignedVarint32_(field, intValue);
+};
+
+
+/**
+ * Writes a uint64 field to the buffer. Numbers outside the range [0,2^64)
+ * will be truncated.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeUint64 = function(field, value) {
+ if (value == null) return;
+ goog.asserts.assert((value >= 0) &&
+ (value < jspb.BinaryConstants.TWO_TO_64));
+ this.writeUnsignedVarint64_(field, value);
+};
+
+
+/**
+ * Writes a uint64 field (with value as a string) to the buffer.
+ * @param {number} field The field number.
+ * @param {string?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeUint64String = function(field, value) {
+ if (value == null) return;
+ var num = jspb.arith.UInt64.fromString(value);
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT);
+ this.encoder_.writeSplitVarint64(num.lo, num.hi);
+};
+
+
+/**
+ * Writes a sint32 field to the buffer. Numbers outside the range [-2^31,2^31)
+ * will be truncated.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeSint32 = function(field, value) {
+ if (value == null) return;
+ goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_31) &&
+ (value < jspb.BinaryConstants.TWO_TO_31));
+ this.writeZigzagVarint32_(field, value);
+};
+
+
+/**
+ * Writes a sint64 field to the buffer. Numbers outside the range [-2^63,2^63)
+ * will be truncated.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeSint64 = function(field, value) {
+ if (value == null) return;
+ goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_63) &&
+ (value < jspb.BinaryConstants.TWO_TO_63));
+ this.writeZigzagVarint64_(field, value);
+};
+
+
+/**
+ * Writes a sint64 field to the buffer. Numbers outside the range [-2^63,2^63)
+ * will be truncated.
+ * @param {number} field The field number.
+ * @param {string?} value The decimal string to write.
+ */
+jspb.BinaryWriter.prototype.writeSint64String = function(field, value) {
+ if (value == null) return;
+ goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_63) &&
+ (value < jspb.BinaryConstants.TWO_TO_63));
+ this.writeZigzagVarint64String_(field, value);
+};
+
+
+/**
+ * Writes a fixed32 field to the buffer. Numbers outside the range [0,2^32)
+ * will be truncated.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeFixed32 = function(field, value) {
+ if (value == null) return;
+ goog.asserts.assert((value >= 0) &&
+ (value < jspb.BinaryConstants.TWO_TO_32));
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED32);
+ this.encoder_.writeUint32(value);
+};
+
+
+/**
+ * Writes a fixed64 field to the buffer. Numbers outside the range [0,2^64)
+ * will be truncated.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeFixed64 = function(field, value) {
+ if (value == null) return;
+ goog.asserts.assert((value >= 0) &&
+ (value < jspb.BinaryConstants.TWO_TO_64));
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED64);
+ this.encoder_.writeUint64(value);
+};
+
+
+/**
+ * Writes a fixed64 field (with value as a string) to the buffer.
+ * @param {number} field The field number.
+ * @param {string?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeFixed64String = function(field, value) {
+ if (value == null) return;
+ var num = jspb.arith.UInt64.fromString(value);
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED64);
+ this.encoder_.writeSplitFixed64(num.lo, num.hi);
+};
+
+
+/**
+ * Writes a sfixed32 field to the buffer. Numbers outside the range
+ * [-2^31,2^31) will be truncated.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeSfixed32 = function(field, value) {
+ if (value == null) return;
+ goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_31) &&
+ (value < jspb.BinaryConstants.TWO_TO_31));
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED32);
+ this.encoder_.writeInt32(value);
+};
+
+
+/**
+ * Writes a sfixed64 field to the buffer. Numbers outside the range
+ * [-2^63,2^63) will be truncated.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeSfixed64 = function(field, value) {
+ if (value == null) return;
+ goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_63) &&
+ (value < jspb.BinaryConstants.TWO_TO_63));
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED64);
+ this.encoder_.writeInt64(value);
+};
+
+
+/**
+ * Writes a sfixed64 string field to the buffer. Numbers outside the range
+ * [-2^63,2^63) will be truncated.
+ * @param {number} field The field number.
+ * @param {string?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeSfixed64String = function(field, value) {
+ if (value == null) return;
+ var num = jspb.arith.Int64.fromString(value);
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED64);
+ this.encoder_.writeSplitFixed64(num.lo, num.hi);
+};
+
+
+/**
+ * Writes a single-precision floating point field to the buffer. Numbers
+ * requiring more than 32 bits of precision will be truncated.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeFloat = function(field, value) {
+ if (value == null) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED32);
+ this.encoder_.writeFloat(value);
+};
+
+
+/**
+ * Writes a double-precision floating point field to the buffer. As this is the
+ * native format used by JavaScript, no precision will be lost.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeDouble = function(field, value) {
+ if (value == null) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED64);
+ this.encoder_.writeDouble(value);
+};
+
+
+/**
+ * Writes a boolean field to the buffer.
+ * @param {number} field The field number.
+ * @param {boolean?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeBool = function(field, value) {
+ if (value == null) return;
+ goog.asserts.assert(goog.isBoolean(value));
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT);
+ this.encoder_.writeBool(value);
+};
+
+
+/**
+ * Writes an enum field to the buffer.
+ * @param {number} field The field number.
+ * @param {number?} value The value to write.
+ */
+jspb.BinaryWriter.prototype.writeEnum = function(field, value) {
+ if (value == null) return;
+ goog.asserts.assert((value >= -jspb.BinaryConstants.TWO_TO_31) &&
+ (value < jspb.BinaryConstants.TWO_TO_31));
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT);
+ this.encoder_.writeSignedVarint32(value);
+};
+
+
+/**
+ * Writes a string field to the buffer.
+ * @param {number} field The field number.
+ * @param {string?} value The string to write.
+ */
+jspb.BinaryWriter.prototype.writeString = function(field, value) {
+ if (value == null) return;
+ var bookmark = this.beginDelimited_(field);
+ this.encoder_.writeString(value);
+ this.endDelimited_(bookmark);
+};
+
+
+/**
+ * Writes an arbitrary byte field to the buffer. Note - to match the behavior
+ * of the C++ implementation, empty byte arrays _are_ serialized.
+ * @param {number} field The field number.
+ * @param {?jspb.ByteSource} value The array of bytes to write.
+ */
+jspb.BinaryWriter.prototype.writeBytes = function(field, value) {
+ if (value == null) return;
+ var bytes = jspb.utils.byteSourceToUint8Array(value);
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
+ this.encoder_.writeUnsignedVarint32(bytes.length);
+ this.appendUint8Array_(bytes);
+};
+
+
+/**
+ * Writes a message to the buffer.
+ * @param {number} field The field number.
+ * @param {?MessageType} value The message to write.
+ * @param {function(MessageTypeNonNull, !jspb.BinaryWriter)} writerCallback
+ * Will be invoked with the value to write and the writer to write it with.
+ * @template MessageType
+ * Use go/closure-ttl to declare a non-nullable version of MessageType. Replace
+ * the null in blah|null with none. This is necessary because the compiler will
+ * infer MessageType to be nullable if the value parameter is nullable.
+ * @template MessageTypeNonNull :=
+ * cond(isUnknown(MessageType), unknown(),
+ * mapunion(MessageType, (X) =>
+ * cond(eq(X, 'null'), none(), X)))
+ * =:
+ */
+jspb.BinaryWriter.prototype.writeMessage = function(
+ field, value, writerCallback) {
+ if (value == null) return;
+ var bookmark = this.beginDelimited_(field);
+ writerCallback(value, this);
+ this.endDelimited_(bookmark);
+};
+
+
+/**
+ * Writes a group message to the buffer.
+ *
+ * @param {number} field The field number.
+ * @param {?MessageType} value The message to write, wrapped with START_GROUP /
+ * END_GROUP tags. Will be a no-op if 'value' is null.
+ * @param {function(MessageTypeNonNull, !jspb.BinaryWriter)} writerCallback
+ * Will be invoked with the value to write and the writer to write it with.
+ * @template MessageType
+ * Use go/closure-ttl to declare a non-nullable version of MessageType. Replace
+ * the null in blah|null with none. This is necessary because the compiler will
+ * infer MessageType to be nullable if the value parameter is nullable.
+ * @template MessageTypeNonNull :=
+ * cond(isUnknown(MessageType), unknown(),
+ * mapunion(MessageType, (X) =>
+ * cond(eq(X, 'null'), none(), X)))
+ * =:
+ */
+jspb.BinaryWriter.prototype.writeGroup = function(
+ field, value, writerCallback) {
+ if (value == null) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.START_GROUP);
+ writerCallback(value, this);
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.END_GROUP);
+};
+
+
+/**
+ * Writes a 64-bit hash string field (8 characters @ 8 bits of data each) to
+ * the buffer.
+ * @param {number} field The field number.
+ * @param {string?} value The hash string.
+ */
+jspb.BinaryWriter.prototype.writeFixedHash64 = function(field, value) {
+ if (value == null) return;
+ goog.asserts.assert(value.length == 8);
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.FIXED64);
+ this.encoder_.writeFixedHash64(value);
+};
+
+
+/**
+ * Writes a 64-bit hash string field (8 characters @ 8 bits of data each) to
+ * the buffer.
+ * @param {number} field The field number.
+ * @param {string?} value The hash string.
+ */
+jspb.BinaryWriter.prototype.writeVarintHash64 = function(field, value) {
+ if (value == null) return;
+ goog.asserts.assert(value.length == 8);
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.VARINT);
+ this.encoder_.writeVarintHash64(value);
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a repeated 32-bit int field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedInt32 = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeSignedVarint32_(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers formatted as strings to the buffer as a repeated
+ * 32-bit int field.
+ * @param {number} field The field number.
+ * @param {?Array.<string>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedInt32String = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeInt32String(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a repeated 64-bit int field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedInt64 = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeSignedVarint64_(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers formatted as strings to the buffer as a repeated
+ * 64-bit int field.
+ * @param {number} field The field number.
+ * @param {?Array.<string>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedInt64String = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeInt64String(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array numbers to the buffer as a repeated unsigned 32-bit int
+ * field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedUint32 = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeUnsignedVarint32_(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers formatted as strings to the buffer as a repeated
+ * unsigned 32-bit int field.
+ * @param {number} field The field number.
+ * @param {?Array.<string>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedUint32String = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeUint32String(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array numbers to the buffer as a repeated unsigned 64-bit int
+ * field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedUint64 = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeUnsignedVarint64_(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers formatted as strings to the buffer as a repeated
+ * unsigned 64-bit int field.
+ * @param {number} field The field number.
+ * @param {?Array.<string>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedUint64String = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeUint64String(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array numbers to the buffer as a repeated signed 32-bit int field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedSint32 = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeZigzagVarint32_(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array numbers to the buffer as a repeated signed 64-bit int field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedSint64 = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeZigzagVarint64_(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array numbers to the buffer as a repeated signed 64-bit int field.
+ * @param {number} field The field number.
+ * @param {?Array.<string>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedSint64String = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeZigzagVarint64String_(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a repeated fixed32 field. This
+ * works for both signed and unsigned fixed32s.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedFixed32 = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeFixed32(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a repeated fixed64 field. This
+ * works for both signed and unsigned fixed64s.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedFixed64 = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeFixed64(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a repeated fixed64 field. This
+ * works for both signed and unsigned fixed64s.
+ * @param {number} field The field number.
+ * @param {?Array.<string>} value The array of decimal strings to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedFixed64String = function(
+ field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeFixed64String(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a repeated sfixed32 field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedSfixed32 = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeSfixed32(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a repeated sfixed64 field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedSfixed64 = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeSfixed64(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of decimal strings to the buffer as a repeated sfixed64
+ * field.
+ * @param {number} field The field number.
+ * @param {?Array.<string>} value The array of decimal strings to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedSfixed64String = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeSfixed64String(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a repeated float field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedFloat = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeFloat(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a repeated double field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedDouble = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeDouble(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of booleans to the buffer as a repeated bool field.
+ * @param {number} field The field number.
+ * @param {?Array.<boolean>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedBool = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeBool(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of enums to the buffer as a repeated enum field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedEnum = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeEnum(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of strings to the buffer as a repeated string field.
+ * @param {number} field The field number.
+ * @param {?Array.<string>} value The array of strings to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedString = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeString(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of arbitrary byte fields to the buffer.
+ * @param {number} field The field number.
+ * @param {?Array.<!jspb.ByteSource>} value The arrays of arrays of bytes to
+ * write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedBytes = function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeBytes(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of messages to the buffer.
+ * @template MessageType
+ * @param {number} field The field number.
+ * @param {?Array.<MessageType>} value The array of messages to
+ * write.
+ * @param {function(MessageType, !jspb.BinaryWriter)} writerCallback
+ * Will be invoked with the value to write and the writer to write it with.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedMessage = function(
+ field, value, writerCallback) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ var bookmark = this.beginDelimited_(field);
+ writerCallback(value[i], this);
+ this.endDelimited_(bookmark);
+ }
+};
+
+
+/**
+ * Writes an array of group messages to the buffer.
+ * @template MessageType
+ * @param {number} field The field number.
+ * @param {?Array.<MessageType>} value The array of messages to
+ * write.
+ * @param {function(MessageType, !jspb.BinaryWriter)} writerCallback
+ * Will be invoked with the value to write and the writer to write it with.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedGroup = function(
+ field, value, writerCallback) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.START_GROUP);
+ writerCallback(value[i], this);
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.END_GROUP);
+ }
+};
+
+
+/**
+ * Writes a 64-bit hash string field (8 characters @ 8 bits of data each) to
+ * the buffer.
+ * @param {number} field The field number.
+ * @param {?Array.<string>} value The array of hashes to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedFixedHash64 =
+ function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeFixedHash64(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes a repeated 64-bit hash string field (8 characters @ 8 bits of data
+ * each) to the buffer.
+ * @param {number} field The field number.
+ * @param {?Array.<string>} value The array of hashes to write.
+ */
+jspb.BinaryWriter.prototype.writeRepeatedVarintHash64 =
+ function(field, value) {
+ if (value == null) return;
+ for (var i = 0; i < value.length; i++) {
+ this.writeVarintHash64(field, value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a packed 32-bit int field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writePackedInt32 = function(field, value) {
+ if (value == null || !value.length) return;
+ var bookmark = this.beginDelimited_(field);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeSignedVarint32(value[i]);
+ }
+ this.endDelimited_(bookmark);
+};
+
+
+/**
+ * Writes an array of numbers represented as strings to the buffer as a packed
+ * 32-bit int field.
+ * @param {number} field
+ * @param {?Array.<string>} value
+ */
+jspb.BinaryWriter.prototype.writePackedInt32String = function(field, value) {
+ if (value == null || !value.length) return;
+ var bookmark = this.beginDelimited_(field);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeSignedVarint32(parseInt(value[i], 10));
+ }
+ this.endDelimited_(bookmark);
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a packed 64-bit int field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writePackedInt64 = function(field, value) {
+ if (value == null || !value.length) return;
+ var bookmark = this.beginDelimited_(field);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeSignedVarint64(value[i]);
+ }
+ this.endDelimited_(bookmark);
+};
+
+
+/**
+ * Writes an array of numbers represented as strings to the buffer as a packed
+ * 64-bit int field.
+ * @param {number} field
+ * @param {?Array.<string>} value
+ */
+jspb.BinaryWriter.prototype.writePackedInt64String = function(field, value) {
+ if (value == null || !value.length) return;
+ var bookmark = this.beginDelimited_(field);
+ for (var i = 0; i < value.length; i++) {
+ var num = jspb.arith.Int64.fromString(value[i]);
+ this.encoder_.writeSplitVarint64(num.lo, num.hi);
+ }
+ this.endDelimited_(bookmark);
+};
+
+
+/**
+ * Writes an array numbers to the buffer as a packed unsigned 32-bit int field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writePackedUint32 = function(field, value) {
+ if (value == null || !value.length) return;
+ var bookmark = this.beginDelimited_(field);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeUnsignedVarint32(value[i]);
+ }
+ this.endDelimited_(bookmark);
+};
+
+
+/**
+ * Writes an array of numbers represented as strings to the buffer as a packed
+ * unsigned 32-bit int field.
+ * @param {number} field
+ * @param {?Array.<string>} value
+ */
+jspb.BinaryWriter.prototype.writePackedUint32String =
+ function(field, value) {
+ if (value == null || !value.length) return;
+ var bookmark = this.beginDelimited_(field);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeUnsignedVarint32(parseInt(value[i], 10));
+ }
+ this.endDelimited_(bookmark);
+};
+
+
+/**
+ * Writes an array numbers to the buffer as a packed unsigned 64-bit int field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writePackedUint64 = function(field, value) {
+ if (value == null || !value.length) return;
+ var bookmark = this.beginDelimited_(field);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeUnsignedVarint64(value[i]);
+ }
+ this.endDelimited_(bookmark);
+};
+
+
+/**
+ * Writes an array of numbers represented as strings to the buffer as a packed
+ * unsigned 64-bit int field.
+ * @param {number} field
+ * @param {?Array.<string>} value
+ */
+jspb.BinaryWriter.prototype.writePackedUint64String =
+ function(field, value) {
+ if (value == null || !value.length) return;
+ var bookmark = this.beginDelimited_(field);
+ for (var i = 0; i < value.length; i++) {
+ var num = jspb.arith.UInt64.fromString(value[i]);
+ this.encoder_.writeSplitVarint64(num.lo, num.hi);
+ }
+ this.endDelimited_(bookmark);
+};
+
+
+/**
+ * Writes an array numbers to the buffer as a packed signed 32-bit int field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writePackedSint32 = function(field, value) {
+ if (value == null || !value.length) return;
+ var bookmark = this.beginDelimited_(field);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeZigzagVarint32(value[i]);
+ }
+ this.endDelimited_(bookmark);
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a packed signed 64-bit int field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writePackedSint64 = function(field, value) {
+ if (value == null || !value.length) return;
+ var bookmark = this.beginDelimited_(field);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeZigzagVarint64(value[i]);
+ }
+ this.endDelimited_(bookmark);
+};
+
+
+/**
+ * Writes an array of decimal strings to the buffer as a packed signed 64-bit
+ * int field.
+ * @param {number} field The field number.
+ * @param {?Array.<string>} value The array of decimal strings to write.
+ */
+jspb.BinaryWriter.prototype.writePackedSint64String = function(field, value) {
+ if (value == null || !value.length) return;
+ var bookmark = this.beginDelimited_(field);
+ for (var i = 0; i < value.length; i++) {
+ // TODO(haberman): make lossless
+ this.encoder_.writeZigzagVarint64(parseInt(value[i], 10));
+ }
+ this.endDelimited_(bookmark);
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a packed fixed32 field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writePackedFixed32 = function(field, value) {
+ if (value == null || !value.length) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
+ this.encoder_.writeUnsignedVarint32(value.length * 4);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeUint32(value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a packed fixed64 field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writePackedFixed64 = function(field, value) {
+ if (value == null || !value.length) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
+ this.encoder_.writeUnsignedVarint32(value.length * 8);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeUint64(value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers represented as strings to the buffer as a packed
+ * fixed64 field.
+ * @param {number} field The field number.
+ * @param {?Array.<string>} value The array of strings to write.
+ */
+jspb.BinaryWriter.prototype.writePackedFixed64String = function(field, value) {
+ if (value == null || !value.length) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
+ this.encoder_.writeUnsignedVarint32(value.length * 8);
+ for (var i = 0; i < value.length; i++) {
+ var num = jspb.arith.UInt64.fromString(value[i]);
+ this.encoder_.writeSplitFixed64(num.lo, num.hi);
+ }
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a packed sfixed32 field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writePackedSfixed32 = function(field, value) {
+ if (value == null || !value.length) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
+ this.encoder_.writeUnsignedVarint32(value.length * 4);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeInt32(value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a packed sfixed64 field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writePackedSfixed64 = function(field, value) {
+ if (value == null || !value.length) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
+ this.encoder_.writeUnsignedVarint32(value.length * 8);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeInt64(value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a packed sfixed64 field.
+ * @param {number} field The field number.
+ * @param {?Array.<string>} value The array of decimal strings to write.
+ */
+jspb.BinaryWriter.prototype.writePackedSfixed64String = function(field, value) {
+ if (value == null || !value.length) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
+ this.encoder_.writeUnsignedVarint32(value.length * 8);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeInt64String(value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a packed float field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writePackedFloat = function(field, value) {
+ if (value == null || !value.length) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
+ this.encoder_.writeUnsignedVarint32(value.length * 4);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeFloat(value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of numbers to the buffer as a packed double field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writePackedDouble = function(field, value) {
+ if (value == null || !value.length) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
+ this.encoder_.writeUnsignedVarint32(value.length * 8);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeDouble(value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of booleans to the buffer as a packed bool field.
+ * @param {number} field The field number.
+ * @param {?Array.<boolean>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writePackedBool = function(field, value) {
+ if (value == null || !value.length) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
+ this.encoder_.writeUnsignedVarint32(value.length);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeBool(value[i]);
+ }
+};
+
+
+/**
+ * Writes an array of enums to the buffer as a packed enum field.
+ * @param {number} field The field number.
+ * @param {?Array.<number>} value The array of ints to write.
+ */
+jspb.BinaryWriter.prototype.writePackedEnum = function(field, value) {
+ if (value == null || !value.length) return;
+ var bookmark = this.beginDelimited_(field);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeEnum(value[i]);
+ }
+ this.endDelimited_(bookmark);
+};
+
+
+/**
+ * Writes a 64-bit hash string field (8 characters @ 8 bits of data each) to
+ * the buffer.
+ * @param {number} field The field number.
+ * @param {?Array.<string>} value The array of hashes to write.
+ */
+jspb.BinaryWriter.prototype.writePackedFixedHash64 = function(field, value) {
+ if (value == null || !value.length) return;
+ this.writeFieldHeader_(field, jspb.BinaryConstants.WireType.DELIMITED);
+ this.encoder_.writeUnsignedVarint32(value.length * 8);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeFixedHash64(value[i]);
+ }
+};
+
+
+/**
+ * Writes a 64-bit hash string field (8 characters @ 8 bits of data each) to
+ * the buffer.
+ * @param {number} field The field number.
+ * @param {?Array.<string>} value The array of hashes to write.
+ */
+jspb.BinaryWriter.prototype.writePackedVarintHash64 = function(field, value) {
+ if (value == null || !value.length) return;
+ var bookmark = this.beginDelimited_(field);
+ for (var i = 0; i < value.length; i++) {
+ this.encoder_.writeVarintHash64(value[i]);
+ }
+ this.endDelimited_(bookmark);
+};
diff --git a/third_party/protobuf/js/binary/writer_test.js b/third_party/protobuf/js/binary/writer_test.js
new file mode 100644
index 0000000000..83fcdf917f
--- /dev/null
+++ b/third_party/protobuf/js/binary/writer_test.js
@@ -0,0 +1,121 @@
+// 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.
+
+/**
+ * @fileoverview Test cases for jspb's binary protocol buffer writer. In
+ * practice BinaryWriter is used to drive the Decoder and Reader test cases,
+ * so only writer-specific tests are here.
+ *
+ * Test suite is written using Jasmine -- see http://jasmine.github.io/
+ *
+ * @author aappleby@google.com (Austin Appleby)
+ */
+
+goog.require('goog.crypt');
+goog.require('goog.testing.asserts');
+goog.require('jspb.BinaryWriter');
+
+
+/**
+ * @param {function()} func This function should throw an error when run.
+ */
+function assertFails(func) {
+ var e = assertThrows(func);
+}
+
+
+describe('binaryWriterTest', function() {
+ /**
+ * Verifies that misuse of the writer class triggers assertions.
+ */
+ it('testWriteErrors', function() {
+ // Submessages with invalid field indices should assert.
+ var writer = new jspb.BinaryWriter();
+ var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
+
+ assertFails(function() {
+ writer.writeMessage(-1, dummyMessage, goog.nullFunction);
+ });
+
+ // Writing invalid field indices should assert.
+ writer = new jspb.BinaryWriter();
+ assertFails(function() {writer.writeUint64(-1, 1);});
+
+ // Writing out-of-range field values should assert.
+ writer = new jspb.BinaryWriter();
+
+ assertFails(function() {writer.writeInt32(1, -Infinity);});
+ assertFails(function() {writer.writeInt32(1, Infinity);});
+
+ assertFails(function() {writer.writeInt64(1, -Infinity);});
+ assertFails(function() {writer.writeInt64(1, Infinity);});
+
+ assertFails(function() {writer.writeUint32(1, -1);});
+ assertFails(function() {writer.writeUint32(1, Infinity);});
+
+ assertFails(function() {writer.writeUint64(1, -1);});
+ assertFails(function() {writer.writeUint64(1, Infinity);});
+
+ assertFails(function() {writer.writeSint32(1, -Infinity);});
+ assertFails(function() {writer.writeSint32(1, Infinity);});
+
+ assertFails(function() {writer.writeSint64(1, -Infinity);});
+ assertFails(function() {writer.writeSint64(1, Infinity);});
+
+ assertFails(function() {writer.writeFixed32(1, -1);});
+ assertFails(function() {writer.writeFixed32(1, Infinity);});
+
+ assertFails(function() {writer.writeFixed64(1, -1);});
+ assertFails(function() {writer.writeFixed64(1, Infinity);});
+
+ assertFails(function() {writer.writeSfixed32(1, -Infinity);});
+ assertFails(function() {writer.writeSfixed32(1, Infinity);});
+
+ assertFails(function() {writer.writeSfixed64(1, -Infinity);});
+ assertFails(function() {writer.writeSfixed64(1, Infinity);});
+ });
+
+
+ /**
+ * Basic test of retrieving the result as a Uint8Array buffer
+ */
+ it('testGetResultBuffer', function() {
+ var expected = '0864120b48656c6c6f20776f726c641a0301020320c801';
+
+ var writer = new jspb.BinaryWriter();
+ writer.writeUint32(1, 100);
+ writer.writeString(2, 'Hello world');
+ writer.writeBytes(3, new Uint8Array([1, 2, 3]));
+ writer.writeUint32(4, 200);
+
+ var buffer = writer.getResultBuffer();
+ assertEquals(expected, goog.crypt.byteArrayToHex(buffer));
+ });
+});
diff --git a/third_party/protobuf/js/commonjs/export.js b/third_party/protobuf/js/commonjs/export.js
new file mode 100644
index 0000000000..a93ee928ff
--- /dev/null
+++ b/third_party/protobuf/js/commonjs/export.js
@@ -0,0 +1,31 @@
+/**
+ * @fileoverview Export symbols needed by generated code in CommonJS style.
+ *
+ * This effectively is our canonical list of what we publicly export from
+ * the google-protobuf.js file that we build at distribution time.
+ */
+
+// Include a dummy provide statement so that closurebuilder.py does not skip over this
+// file.
+goog.provide('jspb.Export');
+
+goog.require('goog.object');
+goog.require('jspb.BinaryReader');
+goog.require('jspb.BinaryWriter');
+goog.require('jspb.ExtensionFieldBinaryInfo');
+goog.require('jspb.ExtensionFieldInfo');
+goog.require('jspb.Message');
+goog.require('jspb.Map');
+
+exports.Map = jspb.Map;
+exports.Message = jspb.Message;
+exports.BinaryReader = jspb.BinaryReader;
+exports.BinaryWriter = jspb.BinaryWriter;
+exports.ExtensionFieldInfo = jspb.ExtensionFieldInfo;
+exports.ExtensionFieldBinaryInfo = jspb.ExtensionFieldBinaryInfo;
+
+// These are used by generated code but should not be used directly by clients.
+exports.exportSymbol = goog.exportSymbol;
+exports.inherits = goog.inherits;
+exports.object = {extend: goog.object.extend};
+exports.typeOf = goog.typeOf;
diff --git a/third_party/protobuf/js/commonjs/export_asserts.js b/third_party/protobuf/js/commonjs/export_asserts.js
new file mode 100644
index 0000000000..ad9446c74a
--- /dev/null
+++ b/third_party/protobuf/js/commonjs/export_asserts.js
@@ -0,0 +1,41 @@
+/**
+ * @fileoverview Exports symbols needed only by tests.
+ *
+ * This file exports several Closure Library symbols that are only
+ * used by tests. It is used to generate a file
+ * closure_asserts_commonjs.js that is only used at testing time.
+ */
+
+// Include a dummy provide statement so that closurebuilder.py does not skip over this
+// file.
+goog.provide('jspb.ExportAsserts');
+
+goog.require('goog.testing.asserts');
+
+var global = Function('return this')();
+
+// All of the closure "assert" functions are exported at the global level.
+//
+// The Google Closure assert functions start with assert, eg.
+// assertThrows
+// assertNotThrows
+// assertTrue
+// ...
+//
+// The one exception is the "fail" function.
+function shouldExport(str) {
+ return str.lastIndexOf('assert') === 0 || str == 'fail';
+}
+
+for (var key in global) {
+ if ((typeof key == "string") && global.hasOwnProperty(key) &&
+ shouldExport(key)) {
+ exports[key] = global[key];
+ }
+}
+
+// The COMPILED variable is set by Closure compiler to "true" when it compiles
+// JavaScript, so in practice this is equivalent to "exports.COMPILED = true".
+// This will disable some debugging functionality in debug.js. We could
+// investigate whether this can/should be enabled in CommonJS builds.
+exports.COMPILED = COMPILED
diff --git a/third_party/protobuf/js/commonjs/export_testdeps.js b/third_party/protobuf/js/commonjs/export_testdeps.js
new file mode 100644
index 0000000000..6f5cd0839b
--- /dev/null
+++ b/third_party/protobuf/js/commonjs/export_testdeps.js
@@ -0,0 +1,23 @@
+/**
+ * @fileoverview Export symbols needed by tests in CommonJS style.
+ *
+ * This file is like export.js, but for symbols that are only used by tests.
+ * However we exclude assert functions here, because they are exported into
+ * the global namespace, so those are handled as a special case in
+ * export_asserts.js.
+ */
+
+// Include a dummy provide statement so that closurebuilder.py does not skip over this
+// file.
+goog.provide('jspb.ExportTestDeps');
+
+goog.require('goog.crypt.base64');
+goog.require('jspb.arith.Int64');
+goog.require('jspb.arith.UInt64');
+goog.require('jspb.BinaryEncoder');
+goog.require('jspb.BinaryDecoder');
+goog.require('jspb.BinaryWriter');
+goog.require('jspb.utils');
+
+exports.goog = goog;
+exports.jspb = jspb;
diff --git a/third_party/protobuf/js/commonjs/import_test.js b/third_party/protobuf/js/commonjs/import_test.js
new file mode 100644
index 0000000000..ffa34fea61
--- /dev/null
+++ b/third_party/protobuf/js/commonjs/import_test.js
@@ -0,0 +1,52 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Test suite is written using Jasmine -- see http://jasmine.github.io/
+
+
+
+var googleProtobuf = require('google-protobuf');
+var asserts = require('closure_asserts_commonjs');
+var global = Function('return this')();
+
+// Bring asserts into the global namespace.
+googleProtobuf.object.extend(global, asserts);
+googleProtobuf.exportSymbol('jspb.Message', googleProtobuf.Message, global);
+
+var test7_pb = require('./test7/test7_pb');
+googleProtobuf.exportSymbol('proto.jspb.test.framing.FramingMessage', test7_pb.FramingMessage, global);
+
+describe('Import test suite', function() {
+ it('testImportedMessage', function() {
+ var framing1 = new proto.jspb.test.framing.FramingMessage([]);
+ var framing2 = new proto.jspb.test.framing.FramingMessage([]);
+ assertObjectEquals(framing1.toObject(), framing2.toObject());
+ });
+});
diff --git a/third_party/protobuf/js/commonjs/jasmine.json b/third_party/protobuf/js/commonjs/jasmine.json
new file mode 100644
index 0000000000..666b8edbf8
--- /dev/null
+++ b/third_party/protobuf/js/commonjs/jasmine.json
@@ -0,0 +1,9 @@
+{
+ "spec_dir": "",
+ "spec_files": [
+ "*_test.js",
+ "binary/proto_test.js"
+ ],
+ "helpers": [
+ ]
+}
diff --git a/third_party/protobuf/js/commonjs/rewrite_tests_for_commonjs.js b/third_party/protobuf/js/commonjs/rewrite_tests_for_commonjs.js
new file mode 100644
index 0000000000..b6d90d287d
--- /dev/null
+++ b/third_party/protobuf/js/commonjs/rewrite_tests_for_commonjs.js
@@ -0,0 +1,97 @@
+/**
+ * @fileoverview Utility to translate test files to CommonJS imports.
+ *
+ * This is a somewhat hacky tool designed to do one very specific thing.
+ * All of the test files in *_test.js are written with Closure-style
+ * imports (goog.require()). This works great for running the tests
+ * against Closure-style generated code, but we also want to run the
+ * tests against CommonJS-style generated code without having to fork
+ * the tests.
+ *
+ * Closure-style imports import each individual type by name. This is
+ * very different than CommonJS imports which are by file. So we put
+ * special comments in these tests like:
+ *
+ * // CommonJS-LoadFromFile: test_pb
+ * goog.require('proto.jspb.test.CloneExtension');
+ * goog.require('proto.jspb.test.Complex');
+ * goog.require('proto.jspb.test.DefaultValues');
+ *
+ * This script parses that special comment and uses it to generate proper
+ * CommonJS require() statements so that the tests can run and pass using
+ * CommonJS imports. The script will change the above statements into:
+ *
+ * var test_pb = require('test_pb');
+ * googleProtobuf.exportSymbol('proto.jspb.test.CloneExtension', test_pb.CloneExtension, global);
+ * googleProtobuf.exportSymbol('proto.jspb.test.Complex', test_pb.Complex, global);
+ * googleProtobuf.exportSymbol('proto.jspb.test.DefaultValues', test_pb.DefaultValues, global);
+ *
+ * (The "exportSymbol" function will define the given names in the global
+ * namespace, taking care not to overwrite any previous value for
+ * "proto.jspb.test").
+ */
+
+var lineReader = require('readline').createInterface({
+ input: process.stdin,
+ output: process.stdout
+});
+
+function tryStripPrefix(str, prefix) {
+ if (str.lastIndexOf(prefix) !== 0) {
+ throw "String: " + str + " didn't start with: " + prefix;
+ }
+ return str.substr(prefix.length);
+}
+
+function camelCase(str) {
+ var ret = '';
+ var ucaseNext = false;
+ for (var i = 0; i < str.length; i++) {
+ if (str[i] == '-') {
+ ucaseNext = true;
+ } else if (ucaseNext) {
+ ret += str[i].toUpperCase();
+ ucaseNext = false;
+ } else {
+ ret += str[i];
+ }
+ }
+ return ret;
+}
+
+var module = null;
+var pkg = null;
+
+// Header: goes in every file at the top.
+console.log("var global = Function('return this')();");
+console.log("var googleProtobuf = require('google-protobuf');");
+console.log("var testdeps = require('testdeps_commonjs');");
+console.log("global.goog = testdeps.goog;");
+console.log("global.jspb = testdeps.jspb;");
+console.log("var asserts = require('closure_asserts_commonjs');");
+console.log("");
+console.log("// Bring asserts into the global namespace.");
+console.log("googleProtobuf.object.extend(global, asserts);");
+
+lineReader.on('line', function(line) {
+ var isRequire = line.match(/goog\.require\('([^']*)'\)/);
+ var isLoadFromFile = line.match(/CommonJS-LoadFromFile: (\S*) (.*)/);
+ var isSetTestOnly = line.match(/goog.setTestOnly()/);
+ if (isRequire) {
+ if (module) { // Skip goog.require() lines before the first directive.
+ var fullSym = isRequire[1];
+ var sym = tryStripPrefix(fullSym, pkg);
+ console.log("googleProtobuf.exportSymbol('" + fullSym + "', " + module + sym + ', global);');
+ }
+ } else if (isLoadFromFile) {
+ var module_path = isLoadFromFile[1].split('/');
+ module = camelCase(module_path[module_path.length - 1]);
+ pkg = isLoadFromFile[2];
+
+ if (module != "googleProtobuf") { // We unconditionally require this in the header.
+ console.log("var " + module + " = require('./" + isLoadFromFile[1] + "');");
+ }
+ } else if (!isSetTestOnly) { // Remove goog.setTestOnly() lines.
+ console.log(line);
+ }
+});
diff --git a/third_party/protobuf/js/commonjs/test6/test6.proto b/third_party/protobuf/js/commonjs/test6/test6.proto
new file mode 100644
index 0000000000..a060925f2d
--- /dev/null
+++ b/third_party/protobuf/js/commonjs/test6/test6.proto
@@ -0,0 +1,40 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 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.
+
+syntax = "proto3";
+
+option java_package = "com.google.apps.jspb.proto";
+option java_multiple_files = true;
+
+package jspb.test.importing;
+
+message ImportedMessage {
+ string string_value = 1;
+}
diff --git a/third_party/protobuf/js/commonjs/test7/test7.proto b/third_party/protobuf/js/commonjs/test7/test7.proto
new file mode 100644
index 0000000000..f5574a3dd3
--- /dev/null
+++ b/third_party/protobuf/js/commonjs/test7/test7.proto
@@ -0,0 +1,42 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 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.
+
+syntax = "proto3";
+
+option java_package = "com.google.apps.jspb.proto";
+option java_multiple_files = true;
+
+package jspb.test.framing;
+
+import "test6/test6.proto";
+
+message FramingMessage {
+ jspb.test.importing.ImportedMessage imported_message = 1;
+}
diff --git a/third_party/protobuf/js/data.proto b/third_party/protobuf/js/data.proto
new file mode 100644
index 0000000000..74a8a994c7
--- /dev/null
+++ b/third_party/protobuf/js/data.proto
@@ -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.
+
+// Author: mwr@google.com (Mark Rawling)
+
+syntax = "proto2";
+
+option java_package = "com.google.apps.jspb.proto";
+option java_multiple_files = true;
+
+package jspb.test;
+
+// legacy data, must be nested
+message data {
+ message NestedData {
+ required string str = 1;
+ }
+}
+
+// new data, does not require nesting
+message UnnestedData {
+ required string str = 1;
+}
+
diff --git a/third_party/protobuf/js/debug.js b/third_party/protobuf/js/debug.js
new file mode 100644
index 0000000000..46b2485315
--- /dev/null
+++ b/third_party/protobuf/js/debug.js
@@ -0,0 +1,141 @@
+// 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.
+
+/**
+ * @fileoverview Utilities to debug JSPB based proto objects.
+ */
+
+goog.provide('jspb.debug');
+
+goog.require('goog.array');
+goog.require('goog.asserts');
+goog.require('goog.object');
+goog.require('jspb.Message');
+
+
+/**
+ * Turns a proto into a human readable object that can i.e. be written to the
+ * console: {@code console.log(jspb.debug.dump(myProto))}.
+ * This function makes a best effort and may not work in all cases. It will not
+ * work in obfuscated and or optimized code.
+ * Use this in environments where {@see jspb.Message.prototype.toObject} is
+ * not available for code size reasons.
+ * @param {jspb.Message} message A jspb.Message.
+ * @return {Object}
+ */
+jspb.debug.dump = function(message) {
+ if (!goog.DEBUG) {
+ return null;
+ }
+ goog.asserts.assert(message instanceof jspb.Message,
+ 'jspb.Message instance expected');
+ /** @type {Object} */
+ var object = message;
+ goog.asserts.assert(object['getExtension'],
+ 'Only unobfuscated and unoptimized compilation modes supported.');
+ return /** @type {Object} */ (jspb.debug.dump_(message));
+};
+
+
+/**
+ * Recursively introspects a message and the values its getters return to
+ * make a best effort in creating a human readable representation of the
+ * message.
+ * @param {?} thing A jspb.Message, Array or primitive type to dump.
+ * @return {*}
+ * @private
+ */
+jspb.debug.dump_ = function(thing) {
+ var type = goog.typeOf(thing);
+ if (type == 'number' || type == 'string' || type == 'boolean' ||
+ type == 'null' || type == 'undefined') {
+ return thing;
+ }
+ if (type == 'array') {
+ goog.asserts.assertArray(thing);
+ return goog.array.map(thing, jspb.debug.dump_);
+ }
+ var message = thing; // Copy because we don't want type inference on thing.
+ goog.asserts.assert(message instanceof jspb.Message,
+ 'Only messages expected: ' + thing);
+ var ctor = message.constructor;
+ var messageName = ctor.name || ctor.displayName;
+ var object = {
+ '$name': messageName
+ };
+ for (var name in ctor.prototype) {
+ var match = /^get([A-Z]\w*)/.exec(name);
+ if (match && name != 'getExtension' &&
+ name != 'getJsPbMessageId') {
+ var has = 'has' + match[1];
+ if (!thing[has] || thing[has]()) {
+ var val = thing[name]();
+ object[jspb.debug.formatFieldName_(match[1])] = jspb.debug.dump_(val);
+ }
+ }
+ }
+ if (COMPILED && thing['extensionObject_']) {
+ object['$extensions'] = 'Recursive dumping of extensions not supported ' +
+ 'in compiled code. Switch to uncompiled or dump extension object ' +
+ 'directly';
+ return object;
+ }
+ var extensionsObject;
+ for (var id in ctor['extensions']) {
+ if (/^\d+$/.test(id)) {
+ var ext = ctor['extensions'][id];
+ var extVal = thing.getExtension(ext);
+ var fieldName = goog.object.getKeys(ext.fieldName)[0];
+ if (extVal != null) {
+ if (!extensionsObject) {
+ extensionsObject = object['$extensions'] = {};
+ }
+ extensionsObject[jspb.debug.formatFieldName_(fieldName)] =
+ jspb.debug.dump_(extVal);
+ }
+ }
+ }
+ return object;
+};
+
+
+/**
+ * Formats a field name for output as camelCase.
+ *
+ * @param {string} name Name of the field.
+ * @return {string}
+ * @private
+ */
+jspb.debug.formatFieldName_ = function(name) {
+ // Name may be in TitleCase.
+ return name.replace(/^[A-Z]/, function(c) {
+ return c.toLowerCase();
+ });
+};
diff --git a/third_party/protobuf/js/debug_test.js b/third_party/protobuf/js/debug_test.js
new file mode 100644
index 0000000000..702cc76e90
--- /dev/null
+++ b/third_party/protobuf/js/debug_test.js
@@ -0,0 +1,105 @@
+// 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.setTestOnly();
+
+goog.require('goog.testing.asserts');
+
+// CommonJS-LoadFromFile: google-protobuf
+goog.require('jspb.debug');
+
+// CommonJS-LoadFromFile: test_pb
+goog.require('proto.jspb.test.HasExtensions');
+goog.require('proto.jspb.test.IsExtension');
+goog.require('proto.jspb.test.Simple1');
+
+
+
+describe('debugTest', function() {
+ it('testSimple1', function() {
+ if (COMPILED) {
+ return;
+ }
+ var message = new proto.jspb.test.Simple1();
+ message.setAString('foo');
+ assertObjectEquals({
+ $name: 'proto.jspb.test.Simple1',
+ 'aString': 'foo',
+ 'aRepeatedStringList': []
+ }, jspb.debug.dump(message));
+
+ message.setABoolean(true);
+ message.setARepeatedStringList(['1', '2']);
+
+ assertObjectEquals({
+ $name: 'proto.jspb.test.Simple1',
+ 'aString': 'foo',
+ 'aRepeatedStringList': ['1', '2'],
+ 'aBoolean': true
+ }, jspb.debug.dump(message));
+
+ message.clearAString();
+
+ assertObjectEquals({
+ $name: 'proto.jspb.test.Simple1',
+ 'aRepeatedStringList': ['1', '2'],
+ 'aBoolean': true
+ }, jspb.debug.dump(message));
+ });
+
+
+ it('testExtensions', function() {
+ if (COMPILED) {
+ return;
+ }
+ var extension = new proto.jspb.test.IsExtension();
+ extension.setExt1('ext1field');
+ var extendable = new proto.jspb.test.HasExtensions();
+ extendable.setStr1('v1');
+ extendable.setStr2('v2');
+ extendable.setStr3('v3');
+ extendable.setExtension(proto.jspb.test.IsExtension.extField, extension);
+
+ assertObjectEquals({
+ '$name': 'proto.jspb.test.HasExtensions',
+ 'str1': 'v1',
+ 'str2': 'v2',
+ 'str3': 'v3',
+ '$extensions': {
+ 'extField': {
+ '$name': 'proto.jspb.test.IsExtension',
+ 'ext1': 'ext1field'
+ },
+ 'repeatedSimpleList': []
+ }
+ }, jspb.debug.dump(extendable));
+ });
+
+});
diff --git a/third_party/protobuf/js/gulpfile.js b/third_party/protobuf/js/gulpfile.js
new file mode 100644
index 0000000000..16c302ed67
--- /dev/null
+++ b/third_party/protobuf/js/gulpfile.js
@@ -0,0 +1,160 @@
+var gulp = require('gulp');
+var execFile = require('child_process').execFile;
+var glob = require('glob');
+
+function exec(command, cb) {
+ execFile('sh', ['-c', command], cb);
+}
+
+var protoc = process.env.PROTOC || '../src/protoc';
+
+var wellKnownTypes = [
+ '../src/google/protobuf/any.proto',
+ '../src/google/protobuf/api.proto',
+ '../src/google/protobuf/compiler/plugin.proto',
+ '../src/google/protobuf/descriptor.proto',
+ '../src/google/protobuf/duration.proto',
+ '../src/google/protobuf/empty.proto',
+ '../src/google/protobuf/field_mask.proto',
+ '../src/google/protobuf/source_context.proto',
+ '../src/google/protobuf/struct.proto',
+ '../src/google/protobuf/timestamp.proto',
+ '../src/google/protobuf/type.proto',
+ '../src/google/protobuf/wrappers.proto',
+];
+
+gulp.task('genproto_closure', function (cb) {
+ exec(protoc + ' --js_out=library=testproto_libs,binary:. -I ../src -I . *.proto && ' + protoc + ' --js_out=one_output_file_per_input_file,binary:. -I ../src -I . ' + wellKnownTypes.join(' '),
+ function (err, stdout, stderr) {
+ console.log(stdout);
+ console.log(stderr);
+ cb(err);
+ });
+});
+
+gulp.task('genproto_commonjs', function (cb) {
+ exec('mkdir -p commonjs_out && ' + protoc + ' --js_out=import_style=commonjs,binary:commonjs_out -I ../src -I commonjs -I . *.proto commonjs/test*/*.proto ' + wellKnownTypes.join(' '),
+ function (err, stdout, stderr) {
+ console.log(stdout);
+ console.log(stderr);
+ cb(err);
+ });
+});
+
+gulp.task('genproto_commonjs_wellknowntypes', function (cb) {
+ exec('mkdir -p commonjs_out/node_modules/google-protobuf && ' + protoc + ' --js_out=import_style=commonjs,binary:commonjs_out/node_modules/google-protobuf -I ../src ' + wellKnownTypes.join(' '),
+ function (err, stdout, stderr) {
+ console.log(stdout);
+ console.log(stderr);
+ cb(err);
+ });
+});
+
+gulp.task('genproto_wellknowntypes', function (cb) {
+ exec(protoc + ' --js_out=import_style=commonjs,binary:. -I ../src ' + wellKnownTypes.join(' '),
+ function (err, stdout, stderr) {
+ console.log(stdout);
+ console.log(stderr);
+ cb(err);
+ });
+});
+
+function getClosureBuilderCommand(exportsFile, outputFile) {
+ return './node_modules/google-closure-library/closure/bin/build/closurebuilder.py ' +
+ '--root node_modules ' +
+ '-o compiled ' +
+ '--compiler_jar node_modules/google-closure-compiler/compiler.jar ' +
+ '-i ' + exportsFile + ' ' +
+ 'map.js message.js binary/arith.js binary/constants.js binary/decoder.js ' +
+ 'binary/encoder.js binary/reader.js binary/utils.js binary/writer.js ' +
+ exportsFile + ' > ' + outputFile;
+}
+
+gulp.task('dist', ['genproto_wellknowntypes'], function (cb) {
+ // TODO(haberman): minify this more aggressively.
+ // Will require proper externs/exports.
+ exec(getClosureBuilderCommand('commonjs/export.js', 'google-protobuf.js'),
+ function (err, stdout, stderr) {
+ console.log(stdout);
+ console.log(stderr);
+ cb(err);
+ });
+});
+
+gulp.task('commonjs_asserts', function (cb) {
+ exec('mkdir -p commonjs_out/test_node_modules && ' +
+ getClosureBuilderCommand(
+ 'commonjs/export_asserts.js',
+ 'commonjs_out/test_node_modules/closure_asserts_commonjs.js'),
+ function (err, stdout, stderr) {
+ console.log(stdout);
+ console.log(stderr);
+ cb(err);
+ });
+});
+
+gulp.task('commonjs_testdeps', function (cb) {
+ exec('mkdir -p commonjs_out/test_node_modules && ' +
+ getClosureBuilderCommand(
+ 'commonjs/export_testdeps.js',
+ 'commonjs_out/test_node_modules/testdeps_commonjs.js'),
+ function (err, stdout, stderr) {
+ console.log(stdout);
+ console.log(stderr);
+ cb(err);
+ });
+});
+
+gulp.task('make_commonjs_out', ['dist', 'genproto_commonjs', 'genproto_commonjs_wellknowntypes', 'commonjs_asserts', 'commonjs_testdeps'], function (cb) {
+ // TODO(haberman): minify this more aggressively.
+ // Will require proper externs/exports.
+ var cmd = "mkdir -p commonjs_out/binary && mkdir -p commonjs_out/test_node_modules && ";
+ function addTestFile(file) {
+ cmd += 'node commonjs/rewrite_tests_for_commonjs.js < ' + file +
+ ' > commonjs_out/' + file + '&& ';
+ }
+
+ glob.sync('*_test.js').forEach(addTestFile);
+ glob.sync('binary/*_test.js').forEach(addTestFile);
+
+ exec(cmd +
+ 'cp commonjs/jasmine.json commonjs_out/jasmine.json && ' +
+ 'cp google-protobuf.js commonjs_out/test_node_modules && ' +
+ 'cp commonjs/import_test.js commonjs_out/import_test.js',
+ function (err, stdout, stderr) {
+ console.log(stdout);
+ console.log(stderr);
+ cb(err);
+ });
+});
+
+gulp.task('deps', ['genproto_closure'], function (cb) {
+ exec('./node_modules/google-closure-library/closure/bin/build/depswriter.py *.js binary/*.js > deps.js',
+ function (err, stdout, stderr) {
+ console.log(stdout);
+ console.log(stderr);
+ cb(err);
+ });
+});
+
+gulp.task('test_closure', ['genproto_closure', 'deps'], function (cb) {
+ exec('JASMINE_CONFIG_PATH=jasmine.json ./node_modules/.bin/jasmine',
+ function (err, stdout, stderr) {
+ console.log(stdout);
+ console.log(stderr);
+ cb(err);
+ });
+});
+
+gulp.task('test_commonjs', ['make_commonjs_out'], function (cb) {
+ exec('cd commonjs_out && JASMINE_CONFIG_PATH=jasmine.json NODE_PATH=test_node_modules ../node_modules/.bin/jasmine',
+ function (err, stdout, stderr) {
+ console.log(stdout);
+ console.log(stderr);
+ cb(err);
+ });
+});
+
+gulp.task('test', ['test_closure', 'test_commonjs'], function(cb) {
+ cb();
+});
diff --git a/third_party/protobuf/js/jasmine.json b/third_party/protobuf/js/jasmine.json
new file mode 100644
index 0000000000..093f15794f
--- /dev/null
+++ b/third_party/protobuf/js/jasmine.json
@@ -0,0 +1,15 @@
+{
+ "spec_dir": "",
+ "spec_files": [
+ "*_test.js",
+ "binary/*_test.js"
+ ],
+ "helpers": [
+ "node_modules/google-closure-library/closure/goog/bootstrap/nodejs.js",
+ "node_loader.js",
+ "deps.js",
+ "google/protobuf/any.js",
+ "google/protobuf/struct.js",
+ "google/protobuf/timestamp.js"
+ ]
+}
diff --git a/third_party/protobuf/js/map.js b/third_party/protobuf/js/map.js
new file mode 100644
index 0000000000..4f562dbc1e
--- /dev/null
+++ b/third_party/protobuf/js/map.js
@@ -0,0 +1,531 @@
+// 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.provide('jspb.Map');
+
+goog.require('goog.asserts');
+
+goog.forwardDeclare('jspb.BinaryReader');
+goog.forwardDeclare('jspb.BinaryWriter');
+
+
+
+/**
+ * Constructs a new Map. A Map is a container that is used to implement map
+ * fields on message objects. It closely follows the ES6 Map API; however,
+ * it is distinct because we do not want to depend on external polyfills or
+ * on ES6 itself.
+ *
+ * This constructor should only be called from generated message code. It is not
+ * intended for general use by library consumers.
+ *
+ * @template K, V
+ *
+ * @param {!Array<!Array<!Object>>} arr
+ *
+ * @param {?function(new:V)|function(new:V,?)=} opt_valueCtor
+ * The constructor for type V, if type V is a message type.
+ *
+ * @constructor
+ * @struct
+ */
+jspb.Map = function(arr, opt_valueCtor) {
+ /** @const @private */
+ this.arr_ = arr;
+ /** @const @private */
+ this.valueCtor_ = opt_valueCtor;
+
+ /** @type {!Object<string, !jspb.Map.Entry_<K,V>>} @private */
+ this.map_ = {};
+
+ /**
+ * Is `this.arr_ updated with respect to `this.map_`?
+ * @type {boolean}
+ */
+ this.arrClean = true;
+
+ if (this.arr_.length > 0) {
+ this.loadFromArray_();
+ }
+};
+
+
+/**
+ * Load initial content from underlying array.
+ * @private
+ */
+jspb.Map.prototype.loadFromArray_ = function() {
+ for (var i = 0; i < this.arr_.length; i++) {
+ var record = this.arr_[i];
+ var key = record[0];
+ var value = record[1];
+ this.map_[key.toString()] = new jspb.Map.Entry_(key, value);
+ }
+ this.arrClean = true;
+};
+
+
+/**
+ * Synchronize content to underlying array, if needed, and return it.
+ * @return {!Array<!Array<!Object>>}
+ */
+jspb.Map.prototype.toArray = function() {
+ if (this.arrClean) {
+ if (this.valueCtor_) {
+ // We need to recursively sync maps in submessages to their arrays.
+ var m = this.map_;
+ for (var p in m) {
+ if (Object.prototype.hasOwnProperty.call(m, p)) {
+ var valueWrapper = /** @type {?jspb.Message} */ (m[p].valueWrapper);
+ if (valueWrapper) {
+ valueWrapper.toArray();
+ }
+ }
+ }
+ }
+ } else {
+ // Delete all elements.
+ this.arr_.length = 0;
+ var strKeys = this.stringKeys_();
+ // Output keys in deterministic (sorted) order.
+ strKeys.sort();
+ for (var i = 0; i < strKeys.length; i++) {
+ var entry = this.map_[strKeys[i]];
+ var valueWrapper = /** @type {!Object} */ (entry.valueWrapper);
+ if (valueWrapper) {
+ valueWrapper.toArray();
+ }
+ this.arr_.push([entry.key, entry.value]);
+ }
+ this.arrClean = true;
+ }
+ return this.arr_;
+};
+
+
+/**
+ * Returns the map formatted as an array of key-value pairs, suitable for the
+ * toObject() form of a message.
+ *
+ * @param {boolean=} includeInstance Whether to include the JSPB instance for
+ * transitional soy proto support: http://goto/soy-param-migration
+ * @param {!function((boolean|undefined),!V):!Object=} valueToObject
+ * The static toObject() method, if V is a message type.
+ * @return {!Array<!Array<!Object>>}
+ */
+jspb.Map.prototype.toObject = function(includeInstance, valueToObject) {
+ var rawArray = this.toArray();
+ var entries = [];
+ for (var i = 0; i < rawArray.length; i++) {
+ var entry = this.map_[rawArray[i][0].toString()];
+ this.wrapEntry_(entry);
+ var valueWrapper = /** @type {!V|undefined} */ (entry.valueWrapper);
+ if (valueWrapper) {
+ goog.asserts.assert(valueToObject);
+ entries.push([entry.key, valueToObject(includeInstance, valueWrapper)]);
+ } else {
+ entries.push([entry.key, entry.value]);
+ }
+ }
+ return entries;
+};
+
+
+/**
+ * Returns a Map from the given array of key-value pairs when the values are of
+ * message type. The values in the array must match the format returned by their
+ * message type's toObject() method.
+ *
+ * @template K, V
+ * @param {!Array<!Array<!Object>>} entries
+ * @param {!function(new:V)|function(new:V,?)} valueCtor
+ * The constructor for type V.
+ * @param {!function(!Object):V} valueFromObject
+ * The fromObject function for type V.
+ * @return {!jspb.Map<K, V>}
+ */
+jspb.Map.fromObject = function(entries, valueCtor, valueFromObject) {
+ var result = new jspb.Map([], valueCtor);
+ for (var i = 0; i < entries.length; i++) {
+ var key = entries[i][0];
+ var value = valueFromObject(entries[i][1]);
+ result.set(key, value);
+ }
+ return result;
+};
+
+
+/**
+ * Helper: an IteratorIterable over an array.
+ * @template T
+ * @param {!Array<T>} arr the array
+ * @implements {IteratorIterable<T>}
+ * @constructor @struct
+ * @private
+ */
+jspb.Map.ArrayIteratorIterable_ = function(arr) {
+ /** @type {number} @private */
+ this.idx_ = 0;
+
+ /** @const @private */
+ this.arr_ = arr;
+};
+
+
+/** @override @final */
+jspb.Map.ArrayIteratorIterable_.prototype.next = function() {
+ if (this.idx_ < this.arr_.length) {
+ return {done: false, value: this.arr_[this.idx_++]};
+ } else {
+ return {done: true, value: undefined};
+ }
+};
+
+if (typeof(Symbol) != 'undefined') {
+ /** @override */
+ jspb.Map.ArrayIteratorIterable_.prototype[Symbol.iterator] = function() {
+ return this;
+ };
+}
+
+
+/**
+ * Returns the map's length (number of key/value pairs).
+ * @return {number}
+ */
+jspb.Map.prototype.getLength = function() {
+ return this.stringKeys_().length;
+};
+
+
+/**
+ * Clears the map.
+ */
+jspb.Map.prototype.clear = function() {
+ this.map_ = {};
+ this.arrClean = false;
+};
+
+
+/**
+ * Deletes a particular key from the map.
+ * N.B.: differs in name from ES6 Map's `delete` because IE8 does not support
+ * reserved words as property names.
+ * @this {jspb.Map}
+ * @param {K} key
+ * @return {boolean} Whether any entry with this key was deleted.
+ */
+jspb.Map.prototype.del = function(key) {
+ var keyValue = key.toString();
+ var hadKey = this.map_.hasOwnProperty(keyValue);
+ delete this.map_[keyValue];
+ this.arrClean = false;
+ return hadKey;
+};
+
+
+/**
+ * Returns an array of [key, value] pairs in the map.
+ *
+ * This is redundant compared to the plain entries() method, but we provide this
+ * to help out Angular 1.x users. Still evaluating whether this is the best
+ * option.
+ *
+ * @return {!Array<!Array<K|V>>}
+ */
+jspb.Map.prototype.getEntryList = function() {
+ var entries = [];
+ var strKeys = this.stringKeys_();
+ strKeys.sort();
+ for (var i = 0; i < strKeys.length; i++) {
+ var entry = this.map_[strKeys[i]];
+ entries.push([entry.key, entry.value]);
+ }
+ return entries;
+};
+
+
+/**
+ * Returns an iterator-iterable over [key, value] pairs in the map.
+ * Closure compiler sadly doesn't support tuples, ie. Iterator<[K,V]>.
+ * @return {!IteratorIterable<!Array<K|V>>} The iterator-iterable.
+ */
+jspb.Map.prototype.entries = function() {
+ var entries = [];
+ var strKeys = this.stringKeys_();
+ strKeys.sort();
+ for (var i = 0; i < strKeys.length; i++) {
+ var entry = this.map_[strKeys[i]];
+ entries.push([entry.key, this.wrapEntry_(entry)]);
+ }
+ return new jspb.Map.ArrayIteratorIterable_(entries);
+};
+
+
+/**
+ * Returns an iterator-iterable over keys in the map.
+ * @return {!IteratorIterable<K>} The iterator-iterable.
+ */
+jspb.Map.prototype.keys = function() {
+ var keys = [];
+ var strKeys = this.stringKeys_();
+ strKeys.sort();
+ for (var i = 0; i < strKeys.length; i++) {
+ var entry = this.map_[strKeys[i]];
+ keys.push(entry.key);
+ }
+ return new jspb.Map.ArrayIteratorIterable_(keys);
+};
+
+
+/**
+ * Returns an iterator-iterable over values in the map.
+ * @return {!IteratorIterable<V>} The iterator-iterable.
+ */
+jspb.Map.prototype.values = function() {
+ var values = [];
+ var strKeys = this.stringKeys_();
+ strKeys.sort();
+ for (var i = 0; i < strKeys.length; i++) {
+ var entry = this.map_[strKeys[i]];
+ values.push(this.wrapEntry_(entry));
+ }
+ return new jspb.Map.ArrayIteratorIterable_(values);
+};
+
+
+/**
+ * Iterates over entries in the map, calling a function on each.
+ * @template T
+ * @param {function(this:T, V, K, ?jspb.Map<K, V>)} cb
+ * @param {T=} opt_thisArg
+ */
+jspb.Map.prototype.forEach = function(cb, opt_thisArg) {
+ var strKeys = this.stringKeys_();
+ strKeys.sort();
+ for (var i = 0; i < strKeys.length; i++) {
+ var entry = this.map_[strKeys[i]];
+ cb.call(opt_thisArg, this.wrapEntry_(entry), entry.key, this);
+ }
+};
+
+
+/**
+ * Sets a key in the map to the given value.
+ * @param {K} key The key
+ * @param {V} value The value
+ * @return {!jspb.Map<K,V>}
+ */
+jspb.Map.prototype.set = function(key, value) {
+ var entry = new jspb.Map.Entry_(key);
+ if (this.valueCtor_) {
+ entry.valueWrapper = value;
+ // .toArray() on a message returns a reference to the underlying array
+ // rather than a copy.
+ entry.value = value.toArray();
+ } else {
+ entry.value = value;
+ }
+ this.map_[key.toString()] = entry;
+ this.arrClean = false;
+ return this;
+};
+
+
+/**
+ * Helper: lazily construct a wrapper around an entry, if needed, and return the
+ * user-visible type.
+ * @param {!jspb.Map.Entry_<K,V>} entry
+ * @return {V}
+ * @private
+ */
+jspb.Map.prototype.wrapEntry_ = function(entry) {
+ if (this.valueCtor_) {
+ if (!entry.valueWrapper) {
+ entry.valueWrapper = new this.valueCtor_(entry.value);
+ }
+ return /** @type {V} */ (entry.valueWrapper);
+ } else {
+ return entry.value;
+ }
+};
+
+
+/**
+ * Gets the value corresponding to a key in the map.
+ * @param {K} key
+ * @return {V|undefined} The value, or `undefined` if key not present
+ */
+jspb.Map.prototype.get = function(key) {
+ var keyValue = key.toString();
+ var entry = this.map_[keyValue];
+ if (entry) {
+ return this.wrapEntry_(entry);
+ } else {
+ return undefined;
+ }
+};
+
+
+/**
+ * Determines whether the given key is present in the map.
+ * @param {K} key
+ * @return {boolean} `true` if the key is present
+ */
+jspb.Map.prototype.has = function(key) {
+ var keyValue = key.toString();
+ return (keyValue in this.map_);
+};
+
+
+/**
+ * Write this Map field in wire format to a BinaryWriter, using the given field
+ * number.
+ * @param {number} fieldNumber
+ * @param {!jspb.BinaryWriter} writer
+ * @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
+ * 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
+ * The BinaryWriter serialization callback for type V, if V is a message
+ * type.
+ */
+jspb.Map.prototype.serializeBinary = function(
+ fieldNumber, writer, keyWriterFn, valueWriterFn, opt_valueWriterCallback) {
+ var strKeys = this.stringKeys_();
+ strKeys.sort();
+ for (var i = 0; i < strKeys.length; i++) {
+ var entry = this.map_[strKeys[i]];
+ writer.beginSubMessage(fieldNumber);
+ keyWriterFn.call(writer, 1, entry.key);
+ if (this.valueCtor_) {
+ valueWriterFn.call(writer, 2, this.wrapEntry_(entry),
+ opt_valueWriterCallback);
+ } else {
+ valueWriterFn.call(writer, 2, entry.value);
+ }
+ writer.endSubMessage();
+ }
+};
+
+
+/**
+ * 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
+ * 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
+ * The method on BinaryReader that reads type V from the stream. May be
+ * readMessage, in which case the second callback arg form is used.
+ *
+ * @param {?function(V,!jspb.BinaryReader)=} opt_valueReaderCallback
+ * The BinaryReader parsing callback for type V, if V is a message type.
+ *
+ */
+jspb.Map.deserializeBinary = function(map, reader, keyReaderFn, valueReaderFn,
+ opt_valueReaderCallback) {
+ var key = undefined;
+ var value = undefined;
+
+ while (reader.nextField()) {
+ if (reader.isEndGroup()) {
+ break;
+ }
+ var field = reader.getFieldNumber();
+ if (field == 1) {
+ // Key.
+ key = keyReaderFn.call(reader);
+ } else if (field == 2) {
+ // Value.
+ if (map.valueCtor_) {
+ value = new map.valueCtor_();
+ valueReaderFn.call(reader, value, opt_valueReaderCallback);
+ } else {
+ value = valueReaderFn.call(reader);
+ }
+ }
+ }
+
+ goog.asserts.assert(key != undefined);
+ goog.asserts.assert(value != undefined);
+ map.set(key, value);
+};
+
+
+/**
+ * Helper: compute the list of all stringified keys in the underlying Object
+ * map.
+ * @return {!Array<string>}
+ * @private
+ */
+jspb.Map.prototype.stringKeys_ = function() {
+ var m = this.map_;
+ var ret = [];
+ for (var p in m) {
+ if (Object.prototype.hasOwnProperty.call(m, p)) {
+ ret.push(p);
+ }
+ }
+ return ret;
+};
+
+
+
+/**
+ * @param {!K} key The entry's key.
+ * @param {V=} opt_value The entry's value wrapper.
+ * @constructor
+ * @struct
+ * @template K, V
+ * @private
+ */
+jspb.Map.Entry_ = function(key, opt_value) {
+ /** @const {K} */
+ this.key = key;
+
+ // The JSPB-serializable value. For primitive types this will be of type V.
+ // For message types it will be an array.
+ /** @type {V} */
+ this.value = opt_value;
+
+ // Only used for submessage values.
+ /** @type {V} */
+ this.valueWrapper = undefined;
+};
diff --git a/third_party/protobuf/js/maps_test.js b/third_party/protobuf/js/maps_test.js
new file mode 100755
index 0000000000..e8dd2f219b
--- /dev/null
+++ b/third_party/protobuf/js/maps_test.js
@@ -0,0 +1,350 @@
+// 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');
+
+// CommonJS-LoadFromFile: testbinary_pb proto.jspb.test
+goog.require('proto.jspb.test.MapValueEnum');
+goog.require('proto.jspb.test.MapValueMessage');
+goog.require('proto.jspb.test.TestMapFields');
+
+// CommonJS-LoadFromFile: test_pb proto.jspb.test
+goog.require('proto.jspb.test.MapValueMessageNoBinary');
+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<!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<T>} iter an iterator
+ * @return {!Array<T>}
+ */
+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);
+ });
+ }
+
+
+ /**
+ * 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
+ });
+
+ /**
+ * Returns IteratorIterables for entries(), keys() and values().
+ */
+ it('testIteratorIterables' + suffix, function() {
+ var msg = new msgInfo.constructor();
+ var m = msg.getMapStringStringMap();
+ m.set('key1', 'value1');
+ m.set('key2', 'value2');
+ var entryIterator = m.entries();
+ assertElementsEquals(entryIterator.next().value, ['key1', 'value1']);
+ assertElementsEquals(entryIterator.next().value, ['key2', 'value2']);
+ assertEquals(entryIterator.next().done, true);
+
+ if (typeof(Symbol) != 'undefined') {
+ var entryIterable = m.entries()[Symbol.iterator]();
+ assertElementsEquals(entryIterable.next().value, ['key1', 'value1']);
+ assertElementsEquals(entryIterable.next().value, ['key2', 'value2']);
+ assertEquals(entryIterable.next().done, true);
+ }
+
+ var keyIterator = m.keys();
+ assertEquals(keyIterator.next().value, 'key1');
+ assertEquals(keyIterator.next().value, 'key2');
+ assertEquals(keyIterator.next().done, true);
+
+ if (typeof(Symbol) != 'undefined') {
+ var keyIterable = m.keys()[Symbol.iterator]();
+ assertEquals(keyIterable.next().value, 'key1');
+ assertEquals(keyIterable.next().value, 'key2');
+ assertEquals(keyIterable.next().done, true);
+ }
+ var valueIterator = m.values();
+ assertEquals(valueIterator.next().value, 'value1');
+ assertEquals(valueIterator.next().value, 'value2');
+ assertEquals(valueIterator.next().done, true);
+
+ if (typeof(Symbol) != 'undefined') {
+ var valueIterable = m.values()[Symbol.iterator]();
+ assertEquals(valueIterable.next().value, 'value1');
+ assertEquals(valueIterable.next().value, 'value2');
+ assertEquals(valueIterable.next().done, true);
+ }
+ });
+}
+
+describe('mapsTest', function() {
+ makeTests(
+ {
+ constructor: proto.jspb.test.TestMapFields,
+ deserializeBinary: proto.jspb.test.TestMapFields.deserializeBinary
+ },
+ proto.jspb.test.MapValueMessage, '_Binary');
+ makeTests(
+ {
+ constructor: proto.jspb.test.TestMapFieldsNoBinary,
+ deserializeBinary: null
+ },
+ proto.jspb.test.MapValueMessageNoBinary, '_NoBinary');
+});
diff --git a/third_party/protobuf/js/message.js b/third_party/protobuf/js/message.js
new file mode 100644
index 0000000000..220a5bdb7e
--- /dev/null
+++ b/third_party/protobuf/js/message.js
@@ -0,0 +1,1578 @@
+// 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.
+
+/**
+ * @fileoverview Definition of jspb.Message.
+ *
+ * @author mwr@google.com (Mark Rawling)
+ */
+
+goog.provide('jspb.ExtensionFieldBinaryInfo');
+goog.provide('jspb.ExtensionFieldInfo');
+goog.provide('jspb.Message');
+
+goog.require('goog.array');
+goog.require('goog.asserts');
+goog.require('goog.crypt.base64');
+goog.require('goog.json');
+goog.require('jspb.Map');
+
+// Not needed in compilation units that have no protos with xids.
+goog.forwardDeclare('xid.String');
+
+
+
+/**
+ * Stores information for a single extension field.
+ *
+ * For example, an extension field defined like so:
+ *
+ * extend BaseMessage {
+ * optional MyMessage my_field = 123;
+ * }
+ *
+ * will result in an ExtensionFieldInfo object with these properties:
+ *
+ * {
+ * fieldIndex: 123,
+ * fieldName: {my_field_renamed: 0},
+ * ctor: proto.example.MyMessage,
+ * toObjectFn: proto.example.MyMessage.toObject,
+ * isRepeated: 0
+ * }
+ *
+ * We include `toObjectFn` to allow the JSCompiler to perform dead-code removal
+ * on unused toObject() methods.
+ *
+ * If an extension field is primitive, ctor and toObjectFn will be null.
+ * isRepeated should be 0 or 1.
+ *
+ * binary{Reader,Writer}Fn and (if message type) binaryMessageSerializeFn are
+ * always provided. binaryReaderFn and binaryWriterFn are references to the
+ * appropriate methods on BinaryReader/BinaryWriter to read/write the value of
+ * this extension, and binaryMessageSerializeFn is a reference to the message
+ * class's .serializeBinary method, if available.
+ *
+ * @param {number} fieldNumber
+ * @param {Object} fieldName This has the extension field name as a property.
+ * @param {?function(new: jspb.Message, Array=)} ctor
+ * @param {?function((boolean|undefined),!jspb.Message):!Object} toObjectFn
+ * @param {number} isRepeated
+ * @constructor
+ * @struct
+ * @template T
+ */
+jspb.ExtensionFieldInfo = function(fieldNumber, fieldName, ctor, toObjectFn,
+ isRepeated) {
+ /** @const */
+ this.fieldIndex = fieldNumber;
+ /** @const */
+ this.fieldName = fieldName;
+ /** @const */
+ this.ctor = ctor;
+ /** @const */
+ this.toObjectFn = toObjectFn;
+ /** @const */
+ this.isRepeated = isRepeated;
+};
+
+/**
+ * Stores binary-related information for a single extension field.
+ * @param {!jspb.ExtensionFieldInfo<T>} fieldInfo
+ * @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,
+ opt_binaryMessageSerializeFn, opt_binaryMessageDeserializeFn, opt_isPacked) {
+ /** @const */
+ this.fieldInfo = fieldInfo;
+ /** @const */
+ this.binaryReaderFn = binaryReaderFn;
+ /** @const */
+ this.binaryWriterFn = binaryWriterFn;
+ /** @const */
+ this.binaryMessageSerializeFn = opt_binaryMessageSerializeFn;
+ /** @const */
+ this.binaryMessageDeserializeFn = opt_binaryMessageDeserializeFn;
+ /** @const */
+ this.isPacked = opt_isPacked;
+};
+
+/**
+ * @return {boolean} Does this field represent a sub Message?
+ */
+jspb.ExtensionFieldInfo.prototype.isMessageType = function() {
+ return !!this.ctor;
+};
+
+
+/**
+ * Base class for all JsPb messages.
+ * @constructor
+ * @struct
+ */
+jspb.Message = function() {
+};
+
+
+/**
+ * @define {boolean} Whether to generate toObject methods for objects. Turn
+ * this off, if you do not want toObject to be ever used in your project.
+ * When turning off this flag, consider adding a conformance test that bans
+ * calling toObject. Enabling this will disable the JSCompiler's ability to
+ * dead code eliminate fields used in protocol buffers that are never used
+ * in an application.
+ */
+goog.define('jspb.Message.GENERATE_TO_OBJECT', true);
+
+
+/**
+ * @define {boolean} Whether to generate fromObject methods for objects. Turn
+ * this off, if you do not want fromObject to be ever used in your project.
+ * When turning off this flag, consider adding a conformance test that bans
+ * calling fromObject. Enabling this might disable the JSCompiler's ability
+ * to dead code eliminate fields used in protocol buffers that are never
+ * used in an application.
+ * NOTE: By default no protos actually have a fromObject method. You need to
+ * add the jspb.generate_from_object options to the proto definition to
+ * activate the feature.
+ * By default this is enabled for test code only.
+ */
+goog.define('jspb.Message.GENERATE_FROM_OBJECT', !goog.DISALLOW_TEST_ONLY_CODE);
+
+
+/**
+ * @define {boolean} Whether to generate toString methods for objects. Turn
+ * this off if you do use toString in your project and want to trim it from
+ * compiled JS.
+ */
+goog.define('jspb.Message.GENERATE_TO_STRING', true);
+
+
+/**
+ * @define {boolean} Whether arrays passed to initialize() can be assumed to be
+ * local (e.g. not from another iframe) and thus safely classified with
+ * instanceof Array.
+ */
+goog.define('jspb.Message.ASSUME_LOCAL_ARRAYS', false);
+
+
+/**
+ * @define {boolean} Turning on this flag does NOT change the behavior of JSPB
+ * and only affects private internal state. It may, however, break some
+ * tests that use naive deeply-equals algorithms, because using a proto
+ * mutates its internal state.
+ * Projects are advised to turn this flag always on.
+ */
+goog.define('jspb.Message.MINIMIZE_MEMORY_ALLOCATIONS', COMPILED);
+// TODO(b/19419436) Turn this on by default.
+
+
+/**
+ * Does this JavaScript environment support Uint8Aray typed arrays?
+ * @type {boolean}
+ * @private
+ */
+jspb.Message.SUPPORTS_UINT8ARRAY_ = (typeof Uint8Array == 'function');
+
+
+/**
+ * The internal data array.
+ * @type {!Array}
+ * @protected
+ */
+jspb.Message.prototype.array;
+
+
+/**
+ * Wrappers are the constructed instances of message-type fields. They are built
+ * on demand from the raw array data. Includes message fields, repeated message
+ * fields and extension message fields. Indexed by field number.
+ * @type {Object}
+ * @private
+ */
+jspb.Message.prototype.wrappers_;
+
+
+/**
+ * The object that contains extension fields, if any. This is an object that
+ * maps from a proto field number to the field's value.
+ * @type {Object}
+ * @private
+ */
+jspb.Message.prototype.extensionObject_;
+
+
+/**
+ * Non-extension fields with a field number at or above the pivot are
+ * stored in the extension object (in addition to all extension fields).
+ * @type {number}
+ * @private
+ */
+jspb.Message.prototype.pivot_;
+
+
+/**
+ * The JsPb message_id of this proto.
+ * @type {string|undefined} the message id or undefined if this message
+ * has no id.
+ * @private
+ */
+jspb.Message.prototype.messageId_;
+
+
+/**
+ * Repeated float or double fields which have been converted to include only
+ * numbers and not strings holding "NaN", "Infinity" and "-Infinity".
+ * @private {!Object<number,boolean>|undefined}
+ */
+jspb.Message.prototype.convertedFloatingPointFields_;
+
+
+/**
+ * The xid of this proto type (The same for all instances of a proto). Provides
+ * a way to identify a proto by stable obfuscated name.
+ * @see {xid}.
+ * Available if {@link jspb.generate_xid} is added as a Message option to
+ * a protocol buffer.
+ * @const {!xid.String|undefined} The xid or undefined if message is
+ * annotated to generate the xid.
+ */
+jspb.Message.prototype.messageXid;
+
+
+
+/**
+ * Returns the JsPb message_id of this proto.
+ * @return {string|undefined} the message id or undefined if this message
+ * has no id.
+ */
+jspb.Message.prototype.getJsPbMessageId = function() {
+ return this.messageId_;
+};
+
+
+/**
+ * An offset applied to lookups into this.array to account for the presence or
+ * absence of a messageId at position 0. For response messages, this will be 0.
+ * Otherwise, it will be -1 so that the first array position is not wasted.
+ * @type {number}
+ * @private
+ */
+jspb.Message.prototype.arrayIndexOffset_;
+
+
+/**
+ * Returns the index into msg.array at which the proto field with tag number
+ * fieldNumber will be located.
+ * @param {!jspb.Message} msg Message for which we're calculating an index.
+ * @param {number} fieldNumber The field number.
+ * @return {number} The index.
+ * @private
+ */
+jspb.Message.getIndex_ = function(msg, fieldNumber) {
+ return fieldNumber + msg.arrayIndexOffset_;
+};
+
+
+/**
+ * Initializes a JsPb Message.
+ * @param {!jspb.Message} msg The JsPb proto to modify.
+ * @param {Array|undefined} data An initial data array.
+ * @param {string|number} messageId For response messages, the message id or ''
+ * if no message id is specified. For non-response messages, 0.
+ * @param {number} suggestedPivot The field number at which to start putting
+ * fields into the extension object. This is only used if data does not
+ * contain an extension object already. -1 if no extension object is
+ * required for this message type.
+ * @param {Array<number>} repeatedFields The message's repeated fields.
+ * @param {Array<!Array<number>>=} opt_oneofFields The fields belonging to
+ * each of the message's oneof unions.
+ * @protected
+ */
+jspb.Message.initialize = function(
+ msg, data, messageId, suggestedPivot, repeatedFields, opt_oneofFields) {
+ msg.wrappers_ = jspb.Message.MINIMIZE_MEMORY_ALLOCATIONS ? null : {};
+ if (!data) {
+ data = messageId ? [messageId] : [];
+ }
+ msg.messageId_ = messageId ? String(messageId) : undefined;
+ // If the messageId is 0, this message is not a response message, so we shift
+ // array indices down by 1 so as not to waste the first position in the array,
+ // which would otherwise go unused.
+ msg.arrayIndexOffset_ = messageId === 0 ? -1 : 0;
+ msg.array = data;
+ jspb.Message.materializeExtensionObject_(msg, suggestedPivot);
+ msg.convertedFloatingPointFields_ = {};
+
+ if (repeatedFields) {
+ for (var i = 0; i < repeatedFields.length; i++) {
+ var fieldNumber = repeatedFields[i];
+ if (fieldNumber < msg.pivot_) {
+ var index = jspb.Message.getIndex_(msg, fieldNumber);
+ msg.array[index] = msg.array[index] ||
+ (jspb.Message.MINIMIZE_MEMORY_ALLOCATIONS ?
+ jspb.Message.EMPTY_LIST_SENTINEL_ :
+ []);
+ } else {
+ msg.extensionObject_[fieldNumber] =
+ msg.extensionObject_[fieldNumber] ||
+ (jspb.Message.MINIMIZE_MEMORY_ALLOCATIONS ?
+ jspb.Message.EMPTY_LIST_SENTINEL_ :
+ []);
+ }
+ }
+ }
+
+ if (opt_oneofFields && opt_oneofFields.length) {
+ // Compute the oneof case for each union. This ensures only one value is
+ // set in the union.
+ goog.array.forEach(
+ opt_oneofFields, goog.partial(jspb.Message.computeOneofCase, msg));
+ }
+};
+
+
+/**
+ * Used to mark empty repeated fields. Serializes to null when serialized
+ * to JSON.
+ * When reading a repeated field readers must check the return value against
+ * this value and return and replace it with a new empty array if it is
+ * present.
+ * @private @const {!Object}
+ */
+jspb.Message.EMPTY_LIST_SENTINEL_ = goog.DEBUG && Object.freeze ?
+ Object.freeze([]) :
+ [];
+
+
+/**
+ * Returns true if the provided argument is an array.
+ * @param {*} o The object to classify as array or not.
+ * @return {boolean} True if the provided object is an array.
+ * @private
+ */
+jspb.Message.isArray_ = function(o) {
+ return jspb.Message.ASSUME_LOCAL_ARRAYS ? o instanceof Array :
+ goog.isArray(o);
+};
+
+
+/**
+ * Ensures that the array contains an extension object if necessary.
+ * If the array contains an extension object in its last position, then the
+ * object is kept in place and its position is used as the pivot. If not, then
+ * create an extension object using suggestedPivot. If suggestedPivot is -1,
+ * we don't have an extension object at all, in which case all fields are stored
+ * in the array.
+ * @param {!jspb.Message} msg The JsPb proto to modify.
+ * @param {number} suggestedPivot See description for initialize().
+ * @private
+ */
+jspb.Message.materializeExtensionObject_ = function(msg, suggestedPivot) {
+ if (msg.array.length) {
+ var foundIndex = msg.array.length - 1;
+ var obj = msg.array[foundIndex];
+ // Normal fields are never objects, so we can be sure that if we find an
+ // object here, then it's the extension object. However, we must ensure that
+ // the object is not an array, since arrays are valid field values.
+ // NOTE(lukestebbing): We avoid looking at .length to avoid a JIT bug
+ // in Safari on iOS 8. See the description of CL/86511464 for details.
+ if (obj && typeof obj == 'object' && !jspb.Message.isArray_(obj) &&
+ !(jspb.Message.SUPPORTS_UINT8ARRAY_ && obj instanceof Uint8Array)) {
+ msg.pivot_ = foundIndex - msg.arrayIndexOffset_;
+ msg.extensionObject_ = obj;
+ return;
+ }
+ }
+ // This complexity exists because we keep all extension fields in the
+ // extensionObject_ regardless of proto field number. Changing this would
+ // simplify the code here, but it would require changing the serialization
+ // format from the server, which is not backwards compatible.
+ // TODO(jshneier): Should we just treat extension fields the same as
+ // non-extension fields, and select whether they appear in the object or in
+ // the array purely based on tag number? This would allow simplifying all the
+ // get/setExtension logic, but it would require the breaking change described
+ // above.
+ if (suggestedPivot > -1) {
+ msg.pivot_ = suggestedPivot;
+ var pivotIndex = jspb.Message.getIndex_(msg, suggestedPivot);
+ if (!jspb.Message.MINIMIZE_MEMORY_ALLOCATIONS) {
+ msg.extensionObject_ = msg.array[pivotIndex] = {};
+ } else {
+ // Initialize to null to avoid changing the shape of the proto when it
+ // gets eventually set.
+ msg.extensionObject_ = null;
+ }
+ } else {
+ msg.pivot_ = Number.MAX_VALUE;
+ }
+};
+
+
+/**
+ * Creates an empty extensionObject_ if non exists.
+ * @param {!jspb.Message} msg The JsPb proto to modify.
+ * @private
+ */
+jspb.Message.maybeInitEmptyExtensionObject_ = function(msg) {
+ var pivotIndex = jspb.Message.getIndex_(msg, msg.pivot_);
+ if (!msg.array[pivotIndex]) {
+ msg.extensionObject_ = msg.array[pivotIndex] = {};
+ }
+};
+
+
+/**
+ * Converts a JsPb repeated message field into an object list.
+ * @param {!Array<T>} field The repeated message field to be
+ * converted.
+ * @param {?function(boolean=): Object|
+ * function((boolean|undefined),T): Object} toObjectFn The toObject
+ * function for this field. We need to pass this for effective dead code
+ * removal.
+ * @param {boolean=} opt_includeInstance Whether to include the JSPB instance
+ * for transitional soy proto support: http://goto/soy-param-migration
+ * @return {!Array<Object>} An array of converted message objects.
+ * @template T
+ */
+jspb.Message.toObjectList = function(field, toObjectFn, opt_includeInstance) {
+ // Not using goog.array.map in the generated code to keep it small.
+ // And not using it here to avoid a function call.
+ var result = [];
+ for (var i = 0; i < field.length; i++) {
+ result[i] = toObjectFn.call(field[i], opt_includeInstance,
+ /** @type {!jspb.Message} */ (field[i]));
+ }
+ return result;
+};
+
+
+/**
+ * Adds a proto's extension data to a Soy rendering object.
+ * @param {!jspb.Message} proto The proto whose extensions to convert.
+ * @param {!Object} obj The Soy object to add converted extension data to.
+ * @param {!Object} extensions The proto class' registered extensions.
+ * @param {function(this:?, jspb.ExtensionFieldInfo) : *} getExtensionFn
+ * The proto class' getExtension function. Passed for effective dead code
+ * removal.
+ * @param {boolean=} opt_includeInstance Whether to include the JSPB instance
+ * for transitional soy proto support: http://goto/soy-param-migration
+ */
+jspb.Message.toObjectExtension = function(proto, obj, extensions,
+ getExtensionFn, opt_includeInstance) {
+ for (var fieldNumber in extensions) {
+ var fieldInfo = extensions[fieldNumber];
+ var value = getExtensionFn.call(proto, fieldInfo);
+ if (goog.isDefAndNotNull(value)) {
+ for (var name in fieldInfo.fieldName) {
+ if (fieldInfo.fieldName.hasOwnProperty(name)) {
+ break; // the compiled field name
+ }
+ }
+ if (!fieldInfo.toObjectFn) {
+ obj[name] = value;
+ } else {
+ if (fieldInfo.isRepeated) {
+ obj[name] = jspb.Message.toObjectList(
+ /** @type {!Array<jspb.Message>} */ (value),
+ fieldInfo.toObjectFn, opt_includeInstance);
+ } else {
+ obj[name] = fieldInfo.toObjectFn(opt_includeInstance, value);
+ }
+ }
+ }
+ }
+};
+
+
+/**
+ * Writes a proto's extension data to a binary-format output stream.
+ * @param {!jspb.Message} proto The proto whose extensions to convert.
+ * @param {*} writer The binary-format writer to write to.
+ * @param {!Object} extensions The proto class' registered extensions.
+ * @param {function(jspb.ExtensionFieldInfo) : *} getExtensionFn The proto
+ * class' getExtension function. Passed for effective dead code removal.
+ */
+jspb.Message.serializeBinaryExtensions = function(proto, writer, extensions,
+ getExtensionFn) {
+ for (var fieldNumber in extensions) {
+ var binaryFieldInfo = extensions[fieldNumber];
+ var fieldInfo = binaryFieldInfo.fieldInfo;
+
+ // The old codegen doesn't add the extra fields to ExtensionFieldInfo, so we
+ // need to gracefully error-out here rather than produce a null dereference
+ // below.
+ if (!binaryFieldInfo.binaryWriterFn) {
+ throw new Error('Message extension present that was generated ' +
+ 'without binary serialization support');
+ }
+ var value = getExtensionFn.call(proto, fieldInfo);
+ if (goog.isDefAndNotNull(value)) {
+ if (fieldInfo.isMessageType()) {
+ // If the message type of the extension was generated without binary
+ // support, there may not be a binary message serializer function, and
+ // we can't know when we codegen the extending message that the extended
+ // message may require binary support, so we can *only* catch this error
+ // here, at runtime (and this decoupled codegen is the whole point of
+ // extensions!).
+ if (binaryFieldInfo.binaryMessageSerializeFn) {
+ binaryFieldInfo.binaryWriterFn.call(writer, fieldInfo.fieldIndex,
+ value, binaryFieldInfo.binaryMessageSerializeFn);
+ } else {
+ throw new Error('Message extension present holding submessage ' +
+ 'without binary support enabled, and message is ' +
+ 'being serialized to binary format');
+ }
+ } else {
+ binaryFieldInfo.binaryWriterFn.call(
+ writer, fieldInfo.fieldIndex, value);
+ }
+ }
+ }
+};
+
+
+/**
+ * Reads an extension field from the given reader and, if a valid extension,
+ * sets the extension value.
+ * @param {!jspb.Message} msg A jspb proto.
+ * @param {{skipField:function(),getFieldNumber:function():number}} reader
+ * @param {!Object} extensions The extensions object.
+ * @param {function(jspb.ExtensionFieldInfo)} getExtensionFn
+ * @param {function(jspb.ExtensionFieldInfo, ?)} setExtensionFn
+ */
+jspb.Message.readBinaryExtension = function(msg, reader, extensions,
+ getExtensionFn, setExtensionFn) {
+ var binaryFieldInfo = extensions[reader.getFieldNumber()];
+ if (!binaryFieldInfo) {
+ reader.skipField();
+ return;
+ }
+ var fieldInfo = binaryFieldInfo.fieldInfo;
+ if (!binaryFieldInfo.binaryReaderFn) {
+ throw new Error('Deserializing extension whose generated code does not ' +
+ 'support binary format');
+ }
+
+ var value;
+ if (fieldInfo.isMessageType()) {
+ value = new fieldInfo.ctor();
+ binaryFieldInfo.binaryReaderFn.call(
+ reader, value, binaryFieldInfo.binaryMessageDeserializeFn);
+ } else {
+ // All other types.
+ value = binaryFieldInfo.binaryReaderFn.call(reader);
+ }
+
+ if (fieldInfo.isRepeated && !binaryFieldInfo.isPacked) {
+ var currentList = getExtensionFn.call(msg, fieldInfo);
+ if (!currentList) {
+ setExtensionFn.call(msg, fieldInfo, [value]);
+ } else {
+ currentList.push(value);
+ }
+ } else {
+ setExtensionFn.call(msg, fieldInfo, value);
+ }
+};
+
+
+/**
+ * Gets the value of a non-extension field.
+ * @param {!jspb.Message} msg A jspb proto.
+ * @param {number} fieldNumber The field number.
+ * @return {string|number|boolean|Uint8Array|Array|null|undefined}
+ * The field's value.
+ * @protected
+ */
+jspb.Message.getField = function(msg, fieldNumber) {
+ if (fieldNumber < msg.pivot_) {
+ var index = jspb.Message.getIndex_(msg, fieldNumber);
+ var val = msg.array[index];
+ if (val === jspb.Message.EMPTY_LIST_SENTINEL_) {
+ return msg.array[index] = [];
+ }
+ return val;
+ } else {
+ var val = msg.extensionObject_[fieldNumber];
+ if (val === jspb.Message.EMPTY_LIST_SENTINEL_) {
+ return msg.extensionObject_[fieldNumber] = [];
+ }
+ return val;
+ }
+};
+
+
+/**
+ * Gets the value of an optional float or double field.
+ * @param {!jspb.Message} msg A jspb proto.
+ * @param {number} fieldNumber The field number.
+ * @return {?number|undefined} The field's value.
+ * @protected
+ */
+jspb.Message.getOptionalFloatingPointField = function(msg, fieldNumber) {
+ var value = jspb.Message.getField(msg, fieldNumber);
+ // Converts "NaN", "Infinity" and "-Infinity" to their corresponding numbers.
+ return value == null ? value : +value;
+};
+
+
+/**
+ * Gets the value of a repeated float or double field.
+ * @param {!jspb.Message} msg A jspb proto.
+ * @param {number} fieldNumber The field number.
+ * @return {!Array<number>} The field's value.
+ * @protected
+ */
+jspb.Message.getRepeatedFloatingPointField = function(msg, fieldNumber) {
+ var values = jspb.Message.getField(msg, fieldNumber);
+ if (!msg.convertedFloatingPointFields_) {
+ msg.convertedFloatingPointFields_ = {};
+ }
+ if (!msg.convertedFloatingPointFields_[fieldNumber]) {
+ for (var i = 0; i < values.length; i++) {
+ // Converts "NaN", "Infinity" and "-Infinity" to their corresponding
+ // numbers.
+ values[i] = +values[i];
+ }
+ msg.convertedFloatingPointFields_[fieldNumber] = true;
+ }
+ return /** @type {!Array<number>} */ (values);
+};
+
+
+/**
+ * Coerce a 'bytes' field to a base 64 string.
+ * @param {string|Uint8Array|null} value
+ * @return {?string} The field's coerced value.
+ */
+jspb.Message.bytesAsB64 = function(value) {
+ if (value == null || goog.isString(value)) {
+ return value;
+ }
+ if (jspb.Message.SUPPORTS_UINT8ARRAY_ && value instanceof Uint8Array) {
+ return goog.crypt.base64.encodeByteArray(value);
+ }
+ goog.asserts.fail('Cannot coerce to b64 string: ' + goog.typeOf(value));
+ return null;
+};
+
+
+/**
+ * Coerce a 'bytes' field to a Uint8Array byte buffer.
+ * Note that Uint8Array is not supported on IE versions before 10 nor on Opera
+ * Mini. @see http://caniuse.com/Uint8Array
+ * @param {string|Uint8Array|null} value
+ * @return {?Uint8Array} The field's coerced value.
+ */
+jspb.Message.bytesAsU8 = function(value) {
+ if (value == null || value instanceof Uint8Array) {
+ return value;
+ }
+ if (goog.isString(value)) {
+ return goog.crypt.base64.decodeStringToUint8Array(value);
+ }
+ goog.asserts.fail('Cannot coerce to Uint8Array: ' + goog.typeOf(value));
+ return null;
+};
+
+
+/**
+ * Coerce a repeated 'bytes' field to an array of base 64 strings.
+ * Note: the returned array should be treated as immutable.
+ * @param {!Array<string>|!Array<!Uint8Array>} value
+ * @return {!Array<string?>} The field's coerced value.
+ */
+jspb.Message.bytesListAsB64 = function(value) {
+ jspb.Message.assertConsistentTypes_(value);
+ if (!value.length || goog.isString(value[0])) {
+ return /** @type {!Array<string>} */ (value);
+ }
+ return goog.array.map(value, jspb.Message.bytesAsB64);
+};
+
+
+/**
+ * Coerce a repeated 'bytes' field to an array of Uint8Array byte buffers.
+ * Note: the returned array should be treated as immutable.
+ * Note that Uint8Array is not supported on IE versions before 10 nor on Opera
+ * Mini. @see http://caniuse.com/Uint8Array
+ * @param {!Array<string>|!Array<!Uint8Array>} value
+ * @return {!Array<Uint8Array?>} The field's coerced value.
+ */
+jspb.Message.bytesListAsU8 = function(value) {
+ jspb.Message.assertConsistentTypes_(value);
+ if (!value.length || value[0] instanceof Uint8Array) {
+ return /** @type {!Array<!Uint8Array>} */ (value);
+ }
+ return goog.array.map(value, jspb.Message.bytesAsU8);
+};
+
+
+/**
+ * Asserts that all elements of an array are of the same type.
+ * @param {Array?} array The array to test.
+ * @private
+ */
+jspb.Message.assertConsistentTypes_ = function(array) {
+ if (goog.DEBUG && array && array.length > 1) {
+ var expected = goog.typeOf(array[0]);
+ goog.array.forEach(array, function(e) {
+ if (goog.typeOf(e) != expected) {
+ goog.asserts.fail('Inconsistent type in JSPB repeated field array. ' +
+ 'Got ' + goog.typeOf(e) + ' expected ' + expected);
+ }
+ });
+ }
+};
+
+
+/**
+ * Gets the value of a non-extension primitive field, with proto3 (non-nullable
+ * primitives) semantics. Returns `defaultValue` if the field is not otherwise
+ * set.
+ * @template T
+ * @param {!jspb.Message} msg A jspb proto.
+ * @param {number} fieldNumber The field number.
+ * @param {T} defaultValue The default value.
+ * @return {T} The field's value.
+ * @protected
+ */
+jspb.Message.getFieldWithDefault = function(msg, fieldNumber, defaultValue) {
+ var value = jspb.Message.getField(msg, fieldNumber);
+ if (value == null) {
+ return defaultValue;
+ } else {
+ return value;
+ }
+};
+
+
+/**
+ * Alias for getFieldWithDefault used by older generated code.
+ * @template T
+ * @param {!jspb.Message} msg A jspb proto.
+ * @param {number} fieldNumber The field number.
+ * @param {T} defaultValue The default value.
+ * @return {T} The field's value.
+ * @protected
+ */
+jspb.Message.getFieldProto3 = jspb.Message.getFieldWithDefault;
+
+
+/**
+ * Gets the value of a map field, lazily creating the map container if
+ * necessary.
+ *
+ * This should only be called from generated code, because it requires knowledge
+ * of serialization/parsing callbacks (which are required by the map at
+ * construction time, and the map may be constructed here).
+ *
+ * @template K, V
+ * @param {!jspb.Message} msg
+ * @param {number} fieldNumber
+ * @param {boolean|undefined} noLazyCreate
+ * @param {?=} opt_valueCtor
+ * @return {!jspb.Map<K, V>|undefined}
+ * @protected
+ */
+jspb.Message.getMapField = function(msg, fieldNumber, noLazyCreate,
+ opt_valueCtor) {
+ if (!msg.wrappers_) {
+ msg.wrappers_ = {};
+ }
+ // If we already have a map in the map wrappers, return that.
+ if (fieldNumber in msg.wrappers_) {
+ return msg.wrappers_[fieldNumber];
+ } else if (noLazyCreate) {
+ return undefined;
+ } else {
+ // Wrap the underlying elements array with a Map.
+ var arr = jspb.Message.getField(msg, fieldNumber);
+ if (!arr) {
+ arr = [];
+ jspb.Message.setField(msg, fieldNumber, arr);
+ }
+ return msg.wrappers_[fieldNumber] =
+ new jspb.Map(
+ /** @type {!Array<!Array<!Object>>} */ (arr), opt_valueCtor);
+ }
+};
+
+
+/**
+ * Sets the value of a non-extension field.
+ * @param {!jspb.Message} msg A jspb proto.
+ * @param {number} fieldNumber The field number.
+ * @param {string|number|boolean|Uint8Array|Array|undefined} value New value
+ * @protected
+ */
+jspb.Message.setField = function(msg, fieldNumber, value) {
+ if (fieldNumber < msg.pivot_) {
+ msg.array[jspb.Message.getIndex_(msg, fieldNumber)] = value;
+ } else {
+ msg.extensionObject_[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.
+ * @param {!jspb.Message} msg A jspb proto.
+ * @param {number} fieldNumber The field number.
+ * @param {!Array<number>} oneof The fields belonging to the union.
+ * @param {string|number|boolean|Uint8Array|Array|undefined} value New value
+ * @protected
+ */
+jspb.Message.setOneofField = function(msg, fieldNumber, oneof, value) {
+ var currentCase = jspb.Message.computeOneofCase(msg, oneof);
+ if (currentCase && currentCase !== fieldNumber && value !== undefined) {
+ if (msg.wrappers_ && currentCase in msg.wrappers_) {
+ msg.wrappers_[currentCase] = undefined;
+ }
+ jspb.Message.setField(msg, currentCase, undefined);
+ }
+ jspb.Message.setField(msg, fieldNumber, value);
+};
+
+
+/**
+ * Computes the selection in a oneof group for the given message, ensuring
+ * only one field is set in the process.
+ *
+ * According to the protobuf language guide (
+ * https://developers.google.com/protocol-buffers/docs/proto#oneof), "if the
+ * parser encounters multiple members of the same oneof on the wire, only the
+ * last member seen is used in the parsed message." Since JSPB serializes
+ * messages to a JSON array, the "last member seen" will always be the field
+ * with the greatest field number (directly corresponding to the greatest
+ * array index).
+ *
+ * @param {!jspb.Message} msg A jspb proto.
+ * @param {!Array<number>} oneof The field numbers belonging to the union.
+ * @return {number} The field number currently set in the union, or 0 if none.
+ * @protected
+ */
+jspb.Message.computeOneofCase = function(msg, oneof) {
+ var oneofField;
+ var oneofValue;
+
+ goog.array.forEach(oneof, function(fieldNumber) {
+ var value = jspb.Message.getField(msg, fieldNumber);
+ if (goog.isDefAndNotNull(value)) {
+ oneofField = fieldNumber;
+ oneofValue = value;
+ jspb.Message.setField(msg, fieldNumber, undefined);
+ }
+ });
+
+ if (oneofField) {
+ // NB: We know the value is unique, so we can call jspb.Message.setField
+ // directly instead of jpsb.Message.setOneofField. Also, setOneofField
+ // calls this function.
+ jspb.Message.setField(msg, oneofField, oneofValue);
+ return oneofField;
+ }
+
+ return 0;
+};
+
+
+/**
+ * Gets and wraps a proto field on access.
+ * @param {!jspb.Message} msg A jspb proto.
+ * @param {function(new:jspb.Message, Array)} ctor Constructor for the field.
+ * @param {number} fieldNumber The field number.
+ * @param {number=} opt_required True (1) if this is a required field.
+ * @return {jspb.Message} The field as a jspb proto.
+ * @protected
+ */
+jspb.Message.getWrapperField = function(msg, ctor, fieldNumber, opt_required) {
+ // TODO(mwr): Consider copying data and/or arrays.
+ if (!msg.wrappers_) {
+ msg.wrappers_ = {};
+ }
+ if (!msg.wrappers_[fieldNumber]) {
+ var data = /** @type {Array} */ (jspb.Message.getField(msg, fieldNumber));
+ if (opt_required || data) {
+ // TODO(mwr): Remove existence test for always valid default protos.
+ msg.wrappers_[fieldNumber] = new ctor(data);
+ }
+ }
+ return /** @type {jspb.Message} */ (msg.wrappers_[fieldNumber]);
+};
+
+
+/**
+ * Gets and wraps a repeated proto field on access.
+ * @param {!jspb.Message} msg A jspb proto.
+ * @param {function(new:jspb.Message, Array)} ctor Constructor for the field.
+ * @param {number} fieldNumber The field number.
+ * @return {Array<!jspb.Message>} The repeated field as an array of protos.
+ * @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<!jspb.Message>} */ (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_ = {};
+ }
+ if (!msg.wrappers_[fieldNumber]) {
+ var data = jspb.Message.getField(msg, fieldNumber);
+ for (var wrappers = [], i = 0; i < data.length; i++) {
+ wrappers[i] = new ctor(data[i]);
+ }
+ msg.wrappers_[fieldNumber] = wrappers;
+ }
+};
+
+
+/**
+ * Sets a proto field and syncs it to the backing array.
+ * @param {!jspb.Message} msg A jspb proto.
+ * @param {number} fieldNumber The field number.
+ * @param {?jspb.Message|?jspb.Map|undefined} value A new value for this proto
+ * field.
+ * @protected
+ */
+jspb.Message.setWrapperField = function(msg, fieldNumber, value) {
+ if (!msg.wrappers_) {
+ msg.wrappers_ = {};
+ }
+ var data = value ? value.toArray() : value;
+ msg.wrappers_[fieldNumber] = value;
+ jspb.Message.setField(msg, fieldNumber, data);
+};
+
+
+/**
+ * Sets a proto field in a oneof union and syncs it to the backing array.
+ * @param {!jspb.Message} msg A jspb proto.
+ * @param {number} fieldNumber The field number.
+ * @param {!Array<number>} oneof The fields belonging to the union.
+ * @param {jspb.Message|undefined} value A new value for this proto field.
+ * @protected
+ */
+jspb.Message.setOneofWrapperField = function(msg, fieldNumber, oneof, value) {
+ if (!msg.wrappers_) {
+ msg.wrappers_ = {};
+ }
+ var data = value ? value.toArray() : value;
+ msg.wrappers_[fieldNumber] = value;
+ jspb.Message.setOneofField(msg, fieldNumber, oneof, data);
+};
+
+
+/**
+ * Sets a repeated proto field and syncs it to the backing array.
+ * @param {!jspb.Message} msg A jspb proto.
+ * @param {number} fieldNumber The field number.
+ * @param {Array<!jspb.Message>|undefined} value An array of protos.
+ * @protected
+ */
+jspb.Message.setRepeatedWrapperField = function(msg, fieldNumber, value) {
+ if (!msg.wrappers_) {
+ msg.wrappers_ = {};
+ }
+ value = value || [];
+ for (var data = [], i = 0; i < value.length; i++) {
+ data[i] = value[i].toArray();
+ }
+ msg.wrappers_[fieldNumber] = value;
+ jspb.Message.setField(msg, fieldNumber, data);
+};
+
+
+/**
+ * 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
+ * contain objects suitable for Soy rendering.
+ * @param {!Array<T>} field The repeated message field to be
+ * converted.
+ * @param {function() : string?} mapKeyGetterFn The function to get the key of
+ * the map.
+ * @param {?function(boolean=): Object|
+ * function((boolean|undefined),T): Object} opt_toObjectFn The
+ * toObject function for this field. We need to pass this for effective
+ * dead code removal.
+ * @param {boolean=} opt_includeInstance Whether to include the JSPB instance
+ * for transitional soy proto support: http://goto/soy-param-migration
+ * @return {!Object.<string, Object>} A map of proto or Soy objects.
+ * @template T
+ */
+jspb.Message.toMap = function(
+ field, mapKeyGetterFn, opt_toObjectFn, opt_includeInstance) {
+ var result = {};
+ for (var i = 0; i < field.length; i++) {
+ result[mapKeyGetterFn.call(field[i])] = opt_toObjectFn ?
+ opt_toObjectFn.call(field[i], opt_includeInstance,
+ /** @type {!jspb.Message} */ (field[i])) : field[i];
+ }
+ return result;
+};
+
+
+/**
+ * Syncs all map fields' contents back to their underlying arrays.
+ * @private
+ */
+jspb.Message.prototype.syncMapFields_ = function() {
+ // This iterates over submessage, map, and repeated fields, which is intended.
+ // Submessages can contain maps which also need to be synced.
+ //
+ // There is a lot of opportunity for optimization here. For example we could
+ // statically determine that some messages have no submessages with maps and
+ // optimize this method away for those just by generating one extra static
+ // boolean per message type.
+ if (this.wrappers_) {
+ for (var fieldNumber in this.wrappers_) {
+ var val = this.wrappers_[fieldNumber];
+ if (goog.isArray(val)) {
+ for (var i = 0; i < val.length; i++) {
+ if (val[i]) {
+ val[i].toArray();
+ }
+ }
+ } else {
+ // Works for submessages and maps.
+ if (val) {
+ val.toArray();
+ }
+ }
+ }
+ }
+};
+
+
+/**
+ * Returns the internal array of this proto.
+ * <p>Note: If you use this array to construct a second proto, the content
+ * would then be partially shared between the two protos.
+ * @return {!Array} The proto represented as an array.
+ */
+jspb.Message.prototype.toArray = function() {
+ this.syncMapFields_();
+ return this.array;
+};
+
+
+
+if (jspb.Message.GENERATE_TO_STRING) {
+
+/**
+ * Creates a string representation of the internal data array of this proto.
+ * <p>NOTE: This string is *not* suitable for use in server requests.
+ * @return {string} A string representation of this proto.
+ * @override
+ */
+jspb.Message.prototype.toString = function() {
+ this.syncMapFields_();
+ return this.array.toString();
+};
+
+}
+
+/**
+ * Gets the value of the extension field from the extended object.
+ * @param {jspb.ExtensionFieldInfo.<T>} fieldInfo Specifies the field to get.
+ * @return {T} The value of the field.
+ * @template T
+ */
+jspb.Message.prototype.getExtension = function(fieldInfo) {
+ if (!this.extensionObject_) {
+ return undefined;
+ }
+ if (!this.wrappers_) {
+ this.wrappers_ = {};
+ }
+ var fieldNumber = fieldInfo.fieldIndex;
+ if (fieldInfo.isRepeated) {
+ if (fieldInfo.isMessageType()) {
+ if (!this.wrappers_[fieldNumber]) {
+ this.wrappers_[fieldNumber] =
+ goog.array.map(this.extensionObject_[fieldNumber] || [],
+ function(arr) {
+ return new fieldInfo.ctor(arr);
+ });
+ }
+ return this.wrappers_[fieldNumber];
+ } else {
+ return this.extensionObject_[fieldNumber];
+ }
+ } else {
+ if (fieldInfo.isMessageType()) {
+ if (!this.wrappers_[fieldNumber] && this.extensionObject_[fieldNumber]) {
+ this.wrappers_[fieldNumber] = new fieldInfo.ctor(
+ /** @type {Array|undefined} */ (
+ this.extensionObject_[fieldNumber]));
+ }
+ return this.wrappers_[fieldNumber];
+ } else {
+ return this.extensionObject_[fieldNumber];
+ }
+ }
+};
+
+
+/**
+ * Sets the value of the extension field in the extended object.
+ * @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) {
+ // 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_(self);
+ var fieldNumber = fieldInfo.fieldIndex;
+ if (fieldInfo.isRepeated) {
+ value = value || [];
+ if (fieldInfo.isMessageType()) {
+ self.wrappers_[fieldNumber] = value;
+ self.extensionObject_[fieldNumber] = goog.array.map(
+ /** @type {Array<jspb.Message>} */ (value), function(msg) {
+ return msg.toArray();
+ });
+ } else {
+ self.extensionObject_[fieldNumber] = value;
+ }
+ } else {
+ if (fieldInfo.isMessageType()) {
+ self.wrappers_[fieldNumber] = value;
+ self.extensionObject_[fieldNumber] = value ? value.toArray() : value;
+ } else {
+ self.extensionObject_[fieldNumber] = value;
+ }
+ }
+ return self;
+};
+
+
+/**
+ * Creates a difference object between two messages.
+ *
+ * The result will contain the top-level fields of m2 that differ from those of
+ * m1 at any level of nesting. No data is cloned, the result object will
+ * share its top-level elements with m2 (but not with m1).
+ *
+ * Note that repeated fields should not have null/undefined elements, but if
+ * they do, this operation will treat repeated fields of different length as
+ * the same if the only difference between them is due to trailing
+ * null/undefined values.
+ *
+ * @param {!jspb.Message} m1 The first message object.
+ * @param {!jspb.Message} m2 The second message object.
+ * @return {!jspb.Message} The difference returned as a proto message.
+ * Note that the returned message may be missing required fields. This is
+ * currently tolerated in Js, but would cause an error if you tried to
+ * send such a proto to the server. You can access the raw difference
+ * array with result.toArray().
+ * @throws {Error} If the messages are responses with different types.
+ */
+jspb.Message.difference = function(m1, m2) {
+ if (!(m1 instanceof m2.constructor)) {
+ throw new Error('Messages have different types.');
+ }
+ var arr1 = m1.toArray();
+ var arr2 = m2.toArray();
+ var res = [];
+ var start = 0;
+ var length = arr1.length > arr2.length ? arr1.length : arr2.length;
+ if (m1.getJsPbMessageId()) {
+ res[0] = m1.getJsPbMessageId();
+ start = 1;
+ }
+ for (var i = start; i < length; i++) {
+ if (!jspb.Message.compareFields(arr1[i], arr2[i])) {
+ res[i] = arr2[i];
+ }
+ }
+ return new m1.constructor(res);
+};
+
+
+/**
+ * Tests whether two messages are equal.
+ * @param {jspb.Message|undefined} m1 The first message object.
+ * @param {jspb.Message|undefined} m2 The second message object.
+ * @return {boolean} true if both messages are null/undefined, or if both are
+ * of the same type and have the same field values.
+ */
+jspb.Message.equals = function(m1, m2) {
+ return m1 == m2 || (!!(m1 && m2) && (m1 instanceof m2.constructor) &&
+ jspb.Message.compareFields(m1.toArray(), m2.toArray()));
+};
+
+
+/**
+ * Compares two message extension fields recursively.
+ * @param {!Object} extension1 The first field.
+ * @param {!Object} extension2 The second field.
+ * @return {boolean} true if the extensions are null/undefined, or otherwise
+ * equal.
+ */
+jspb.Message.compareExtensions = function(extension1, extension2) {
+ extension1 = extension1 || {};
+ extension2 = extension2 || {};
+
+ var keys = {};
+ for (var name in extension1) {
+ keys[name] = 0;
+ }
+ for (var name in extension2) {
+ keys[name] = 0;
+ }
+ for (name in keys) {
+ if (!jspb.Message.compareFields(extension1[name], extension2[name])) {
+ return false;
+ }
+ }
+ return true;
+};
+
+
+/**
+ * Compares two message fields recursively.
+ * @param {*} field1 The first field.
+ * @param {*} field2 The second field.
+ * @return {boolean} true if the fields are null/undefined, or otherwise equal.
+ */
+jspb.Message.compareFields = function(field1, field2) {
+ // If the fields are trivially equal, they're equal.
+ if (field1 == field2) return true;
+
+ // If the fields aren't trivially equal and one of them isn't an object,
+ // they can't possibly be equal.
+ if (!goog.isObject(field1) || !goog.isObject(field2)) {
+ return false;
+ }
+
+ // We have two objects. If they're different types, they're not equal.
+ field1 = /** @type {!Object} */(field1);
+ field2 = /** @type {!Object} */(field2);
+ if (field1.constructor != field2.constructor) return false;
+
+ // If both are Uint8Arrays, compare them element-by-element.
+ if (jspb.Message.SUPPORTS_UINT8ARRAY_ && field1.constructor === Uint8Array) {
+ var bytes1 = /** @type {!Uint8Array} */(field1);
+ var bytes2 = /** @type {!Uint8Array} */(field2);
+ if (bytes1.length != bytes2.length) return false;
+ for (var i = 0; i < bytes1.length; i++) {
+ if (bytes1[i] != bytes2[i]) return false;
+ }
+ return true;
+ }
+
+ // If they're both Arrays, compare them element by element except for the
+ // optional extension objects at the end, which we compare separately.
+ if (field1.constructor === Array) {
+ var extension1 = undefined;
+ var extension2 = undefined;
+
+ var length = Math.max(field1.length, field2.length);
+ for (var i = 0; i < length; i++) {
+ var val1 = field1[i];
+ var val2 = field2[i];
+
+ if (val1 && (val1.constructor == Object)) {
+ goog.asserts.assert(extension1 === undefined);
+ goog.asserts.assert(i === field1.length - 1);
+ extension1 = val1;
+ val1 = undefined;
+ }
+
+ if (val2 && (val2.constructor == Object)) {
+ goog.asserts.assert(extension2 === undefined);
+ goog.asserts.assert(i === field2.length - 1);
+ extension2 = val2;
+ val2 = undefined;
+ }
+
+ if (!jspb.Message.compareFields(val1, val2)) {
+ return false;
+ }
+ }
+
+ if (extension1 || extension2) {
+ extension1 = extension1 || {};
+ extension2 = extension2 || {};
+ return jspb.Message.compareExtensions(extension1, extension2);
+ }
+
+ return true;
+ }
+
+ // If they're both plain Objects (i.e. extensions), compare them as
+ // extensions.
+ if (field1.constructor === Object) {
+ return jspb.Message.compareExtensions(field1, field2);
+ }
+
+ throw new Error('Invalid type in JSPB array');
+};
+
+
+/**
+ * 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.
+ */
+jspb.Message.clone = function(msg) {
+ // Although we could include the wrappers, we leave them out here.
+ return jspb.Message.cloneMessage(msg);
+};
+
+
+/**
+ * @param {!jspb.Message} msg A message to clone.
+ * @return {!jspb.Message} A deep clone of the given message.
+ * @protected
+ */
+jspb.Message.cloneMessage = function(msg) {
+ // Although we could include the wrappers, we leave them out here.
+ return new msg.constructor(jspb.Message.clone_(msg.toArray()));
+};
+
+
+/**
+ * Takes 2 messages of the same type and copies the contents of the first
+ * message into the second. After this the 2 messages will equals in terms of
+ * value semantics but share no state. All data in the destination message will
+ * be overridden.
+ *
+ * @param {MESSAGE} fromMessage Message that will be copied into toMessage.
+ * @param {MESSAGE} toMessage Message which will receive a copy of fromMessage
+ * as its contents.
+ * @template MESSAGE
+ */
+jspb.Message.copyInto = function(fromMessage, toMessage) {
+ goog.asserts.assertInstanceof(fromMessage, jspb.Message);
+ goog.asserts.assertInstanceof(toMessage, jspb.Message);
+ goog.asserts.assert(fromMessage.constructor == toMessage.constructor,
+ 'Copy source and target message should have the same type.');
+ var copyOfFrom = jspb.Message.clone(fromMessage);
+
+ var to = toMessage.toArray();
+ var from = copyOfFrom.toArray();
+
+ // Empty destination in case it has more values at the end of the array.
+ to.length = 0;
+ // and then copy everything from the new to the existing message.
+ for (var i = 0; i < from.length; i++) {
+ to[i] = from[i];
+ }
+
+ // This is either null or empty for a fresh copy.
+ toMessage.wrappers_ = copyOfFrom.wrappers_;
+ // Just a reference into the shared array.
+ toMessage.extensionObject_ = copyOfFrom.extensionObject_;
+};
+
+
+/**
+ * Helper for cloning an internal JsPb object.
+ * @param {!Object} obj A JsPb object, eg, a field, to be cloned.
+ * @return {!Object} A clone of the input object.
+ * @private
+ */
+jspb.Message.clone_ = function(obj) {
+ var o;
+ if (goog.isArray(obj)) {
+ // Allocate array of correct size.
+ var clonedArray = new Array(obj.length);
+ // Use array iteration where possible because it is faster than for-in.
+ for (var i = 0; i < obj.length; i++) {
+ if ((o = obj[i]) != null) {
+ clonedArray[i] = typeof o == 'object' ? jspb.Message.clone_(o) : o;
+ }
+ }
+ return clonedArray;
+ }
+ if (jspb.Message.SUPPORTS_UINT8ARRAY_ && obj instanceof Uint8Array) {
+ return new Uint8Array(obj);
+ }
+ var clone = {};
+ for (var key in obj) {
+ if ((o = obj[key]) != null) {
+ clone[key] = typeof o == 'object' ? jspb.Message.clone_(o) : o;
+ }
+ }
+ return clone;
+};
+
+
+/**
+ * Registers a JsPb message type id with its constructor.
+ * @param {string} id The id for this type of message.
+ * @param {Function} constructor The message constructor.
+ */
+jspb.Message.registerMessageType = function(id, constructor) {
+ jspb.Message.registry_[id] = constructor;
+ // This is needed so we can later access messageId directly on the contructor,
+ // otherwise it is not available due to 'property collapsing' by the compiler.
+ constructor.messageId = id;
+};
+
+
+/**
+ * The registry of message ids to message constructors.
+ * @private
+ */
+jspb.Message.registry_ = {};
+
+
+/**
+ * The extensions registered on MessageSet. This is a map of extension
+ * field number to field info object. This should be considered as a
+ * private API.
+ *
+ * This is similar to [jspb class name].extensions object for
+ * non-MessageSet. We special case MessageSet so that we do not need
+ * to goog.require MessageSet from classes that extends MessageSet.
+ *
+ * @type {!Object.<number, jspb.ExtensionFieldInfo>}
+ */
+jspb.Message.messageSetExtensions = {};
+jspb.Message.messageSetExtensionsBinary = {};
diff --git a/third_party/protobuf/js/message_test.js b/third_party/protobuf/js/message_test.js
new file mode 100644
index 0000000000..2298742d77
--- /dev/null
+++ b/third_party/protobuf/js/message_test.js
@@ -0,0 +1,1055 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Test suite is written using Jasmine -- see http://jasmine.github.io/
+
+goog.setTestOnly();
+
+goog.require('goog.json');
+goog.require('goog.testing.asserts');
+goog.require('goog.userAgent');
+
+// CommonJS-LoadFromFile: google-protobuf jspb
+goog.require('jspb.Message');
+
+// CommonJS-LoadFromFile: test8_pb proto.jspb.exttest.nested
+goog.require('proto.jspb.exttest.nested.TestOuterMessage');
+
+// CommonJS-LoadFromFile: test5_pb proto.jspb.exttest.beta
+goog.require('proto.jspb.exttest.beta.floatingStrField');
+
+// CommonJS-LoadFromFile: test3_pb proto.jspb.exttest
+goog.require('proto.jspb.exttest.floatingMsgField');
+
+// CommonJS-LoadFromFile: test4_pb proto.jspb.exttest
+goog.require('proto.jspb.exttest.floatingMsgFieldTwo');
+
+// CommonJS-LoadFromFile: test_pb proto.jspb.test
+goog.require('proto.jspb.test.CloneExtension');
+goog.require('proto.jspb.test.Complex');
+goog.require('proto.jspb.test.DefaultValues');
+goog.require('proto.jspb.test.Empty');
+goog.require('proto.jspb.test.EnumContainer');
+goog.require('proto.jspb.test.floatingMsgField');
+goog.require('proto.jspb.test.FloatingPointFields');
+goog.require('proto.jspb.test.floatingStrField');
+goog.require('proto.jspb.test.HasExtensions');
+goog.require('proto.jspb.test.IndirectExtension');
+goog.require('proto.jspb.test.IsExtension');
+goog.require('proto.jspb.test.OptionalFields');
+goog.require('proto.jspb.test.OuterEnum');
+goog.require('proto.jspb.test.OuterMessage.Complex');
+goog.require('proto.jspb.test.Simple1');
+goog.require('proto.jspb.test.Simple2');
+goog.require('proto.jspb.test.SpecialCases');
+goog.require('proto.jspb.test.TestClone');
+goog.require('proto.jspb.test.TestEndsWithBytes');
+goog.require('proto.jspb.test.TestGroup');
+goog.require('proto.jspb.test.TestGroup1');
+goog.require('proto.jspb.test.TestMessageWithOneof');
+goog.require('proto.jspb.test.TestReservedNames');
+goog.require('proto.jspb.test.TestReservedNamesExtension');
+
+// CommonJS-LoadFromFile: test2_pb proto.jspb.test
+goog.require('proto.jspb.test.ExtensionMessage');
+goog.require('proto.jspb.test.TestExtensionsMessage');
+
+
+
+
+describe('Message test suite', function() {
+ it('testEmptyProto', function() {
+ var empty1 = new proto.jspb.test.Empty([]);
+ var empty2 = new proto.jspb.test.Empty([]);
+ assertObjectEquals({}, empty1.toObject());
+ assertObjectEquals('Message should not be corrupted:', empty2, empty1);
+ });
+
+ it('testTopLevelEnum', function() {
+ var response = new proto.jspb.test.EnumContainer([]);
+ response.setOuterEnum(proto.jspb.test.OuterEnum.FOO);
+ assertEquals(proto.jspb.test.OuterEnum.FOO, response.getOuterEnum());
+ });
+
+ it('testByteStrings', function() {
+ var data = new proto.jspb.test.DefaultValues([]);
+ data.setBytesField('some_bytes');
+ assertEquals('some_bytes', data.getBytesField());
+ });
+
+ it('testComplexConversion', function() {
+ var data1 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, 1];
+ var data2 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, 1];
+ var foo = new proto.jspb.test.Complex(data1);
+ var bar = new proto.jspb.test.Complex(data2);
+ var result = foo.toObject();
+ assertObjectEquals({
+ aString: 'a',
+ anOutOfOrderBool: 1,
+ aNestedMessage: {
+ anInt: 11
+ },
+ aRepeatedMessageList: [{anInt: 22}, {anInt: 33}],
+ aRepeatedStringList: ['s1', 's2']
+ }, result);
+
+ // Now test with the jspb instances included.
+ result = foo.toObject(true /* opt_includeInstance */);
+ assertObjectEquals({
+ aString: 'a',
+ anOutOfOrderBool: 1,
+ aNestedMessage: {
+ anInt: 11,
+ $jspbMessageInstance: foo.getANestedMessage()
+ },
+ aRepeatedMessageList: [
+ {anInt: 22, $jspbMessageInstance: foo.getARepeatedMessageList()[0]},
+ {anInt: 33, $jspbMessageInstance: foo.getARepeatedMessageList()[1]}
+ ],
+ aRepeatedStringList: ['s1', 's2'],
+ $jspbMessageInstance: foo
+ }, result);
+
+ });
+
+ it('testMissingFields', function() {
+ var foo = new proto.jspb.test.Complex([
+ undefined, undefined, undefined, [],
+ undefined, undefined, undefined, undefined]);
+ var bar = new proto.jspb.test.Complex([
+ undefined, undefined, undefined, [],
+ undefined, undefined, undefined, undefined]);
+ var result = foo.toObject();
+ assertObjectEquals({
+ aString: undefined,
+ anOutOfOrderBool: undefined,
+ aNestedMessage: {
+ anInt: undefined
+ },
+ // Note: JsPb converts undefined repeated fields to empty arrays.
+ aRepeatedMessageList: [],
+ aRepeatedStringList: []
+ }, result);
+
+ });
+
+ it('testNestedComplexMessage', function() {
+ // Instantiate the message and set a unique field, just to ensure that we
+ // are not getting jspb.test.Complex instead.
+ var msg = new proto.jspb.test.OuterMessage.Complex();
+ msg.setInnerComplexField(5);
+ });
+
+ it('testSpecialCases', function() {
+ // Note: Some property names are reserved in JavaScript.
+ // These names are converted to the Js property named pb_<reserved_name>.
+ var special =
+ new proto.jspb.test.SpecialCases(['normal', 'default', 'function',
+ 'var']);
+ var result = special.toObject();
+ assertObjectEquals({
+ normal: 'normal',
+ pb_default: 'default',
+ pb_function: 'function',
+ pb_var: 'var'
+ }, result);
+ });
+
+ it('testDefaultValues', function() {
+ var defaultString = "default<>\'\"abc";
+ var response = new proto.jspb.test.DefaultValues();
+
+ // Test toObject
+ var expectedObject = {
+ stringField: defaultString,
+ boolField: true,
+ intField: 11,
+ enumField: 13,
+ emptyField: '',
+ bytesField: 'bW9v'
+ };
+ assertObjectEquals(expectedObject, response.toObject());
+
+
+ // Test getters
+ response = new proto.jspb.test.DefaultValues();
+ assertEquals(defaultString, response.getStringField());
+ assertEquals(true, response.getBoolField());
+ assertEquals(11, response.getIntField());
+ assertEquals(13, response.getEnumField());
+ assertEquals('', response.getEmptyField());
+ assertEquals('bW9v', response.getBytesField());
+
+ function makeDefault(values) {
+ return new proto.jspb.test.DefaultValues(values);
+ }
+
+ // Test with undefined values,
+ // Use push to workaround IE treating undefined array elements as holes.
+ response = makeDefault([undefined, undefined, undefined, undefined]);
+ assertEquals(defaultString, response.getStringField());
+ assertEquals(true, response.getBoolField());
+ assertEquals(11, response.getIntField());
+ assertEquals(13, response.getEnumField());
+ assertFalse(response.hasStringField());
+ assertFalse(response.hasBoolField());
+ assertFalse(response.hasIntField());
+ assertFalse(response.hasEnumField());
+
+ // Test with null values, as would be returned by a JSON serializer.
+ response = makeDefault([null, null, null, null]);
+ assertEquals(defaultString, response.getStringField());
+ assertEquals(true, response.getBoolField());
+ assertEquals(11, response.getIntField());
+ assertEquals(13, response.getEnumField());
+ assertFalse(response.hasStringField());
+ assertFalse(response.hasBoolField());
+ assertFalse(response.hasIntField());
+ assertFalse(response.hasEnumField());
+
+ // Test with false-like values.
+ response = makeDefault(['', false, 0, 0]);
+ assertEquals('', response.getStringField());
+ assertEquals(false, response.getBoolField());
+ assertEquals(true, response.getIntField() == 0);
+ assertEquals(true, response.getEnumField() == 0);
+ assertTrue(response.hasStringField());
+ assertTrue(response.hasBoolField());
+ assertTrue(response.hasIntField());
+ assertTrue(response.hasEnumField());
+
+ // Test that clearing the values reverts them to the default state.
+ response = makeDefault(['blah', false, 111, 77]);
+ response.clearStringField(); response.clearBoolField();
+ response.clearIntField(); response.clearEnumField();
+ assertEquals(defaultString, response.getStringField());
+ assertEquals(true, response.getBoolField());
+ assertEquals(11, response.getIntField());
+ assertEquals(13, response.getEnumField());
+ assertFalse(response.hasStringField());
+ assertFalse(response.hasBoolField());
+ assertFalse(response.hasIntField());
+ assertFalse(response.hasEnumField());
+
+ // Test that setFoo(null) clears the values.
+ response = makeDefault(['blah', false, 111, 77]);
+ response.setStringField(null); response.setBoolField(null);
+ response.setIntField(undefined); response.setEnumField(undefined);
+ assertEquals(defaultString, response.getStringField());
+ assertEquals(true, response.getBoolField());
+ assertEquals(11, response.getIntField());
+ assertEquals(13, response.getEnumField());
+ assertFalse(response.hasStringField());
+ assertFalse(response.hasBoolField());
+ assertFalse(response.hasIntField());
+ assertFalse(response.hasEnumField());
+ });
+
+ 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);
+ });
+
+ it('testClearFields', function() {
+ var data = ['str', true, [11], [[22], [33]], ['s1', 's2']];
+ var foo = new proto.jspb.test.OptionalFields(data);
+ foo.clearAString();
+ foo.clearABool();
+ foo.clearANestedMessage();
+ foo.clearARepeatedMessageList();
+ foo.clearARepeatedStringList();
+ assertEquals('', foo.getAString());
+ assertEquals(false, foo.getABool());
+ assertUndefined(foo.getANestedMessage());
+ assertFalse(foo.hasAString());
+ assertFalse(foo.hasABool());
+ assertObjectEquals([], foo.getARepeatedMessageList());
+ assertObjectEquals([], foo.getARepeatedStringList());
+ // NOTE: We want the missing fields in 'expected' to be undefined,
+ // but we actually get a sparse array instead. We could use something
+ // like [1,undefined,2] to avoid this, except that this is still
+ // sparse on IE. No comment...
+ var expected = [,,, [], []];
+ expected[0] = expected[1] = expected[2] = undefined;
+ assertObjectEquals(expected, foo.toArray());
+ });
+
+ 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'}]);
+ var diff = /** @type {proto.jspb.test.HasExtensions} */
+ (jspb.Message.difference(p1, p2));
+ assertEquals('', diff.getStr1());
+ assertEquals('what', diff.getStr2());
+ assertEquals('', diff.getStr3());
+ assertEquals('unique', diff.extensionObject_[1000]);
+ });
+
+ it('testEqualsSimple', function() {
+ var s1 = new proto.jspb.test.Simple1(['hi']);
+ assertTrue(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['hi'])));
+ assertFalse(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['bye'])));
+ var s1b = new proto.jspb.test.Simple1(['hi', ['hello']]);
+ assertTrue(jspb.Message.equals(s1b,
+ new proto.jspb.test.Simple1(['hi', ['hello']])));
+ assertTrue(jspb.Message.equals(s1b,
+ new proto.jspb.test.Simple1(['hi', ['hello', undefined,
+ undefined, undefined]])));
+ assertFalse(jspb.Message.equals(s1b,
+ new proto.jspb.test.Simple1(['no', ['hello']])));
+ // Test with messages of different types
+ var s2 = new proto.jspb.test.Simple2(['hi']);
+ assertFalse(jspb.Message.equals(s1, s2));
+ });
+
+ it('testEquals_softComparison', function() {
+ var s1 = new proto.jspb.test.Simple1(['hi', [], null]);
+ assertTrue(jspb.Message.equals(s1,
+ new proto.jspb.test.Simple1(['hi', []])));
+
+ var s1b = new proto.jspb.test.Simple1(['hi', [], true]);
+ assertTrue(jspb.Message.equals(s1b,
+ new proto.jspb.test.Simple1(['hi', [], 1])));
+ });
+
+ it('testEqualsComplex', function() {
+ var data1 = ['a',,, [, 11], [[, 22], [, 33]],, ['s1', 's2'],, 1];
+ var data2 = ['a',,, [, 11], [[, 22], [, 34]],, ['s1', 's2'],, 1];
+ var data3 = ['a',,, [, 11], [[, 22]],, ['s1', 's2'],, 1];
+ var data4 = ['hi'];
+ var c1a = new proto.jspb.test.Complex(data1);
+ var c1b = new proto.jspb.test.Complex(data1);
+ var c2 = new proto.jspb.test.Complex(data2);
+ var c3 = new proto.jspb.test.Complex(data3);
+ var s1 = new proto.jspb.test.Simple1(data4);
+
+ assertTrue(jspb.Message.equals(c1a, c1b));
+ assertFalse(jspb.Message.equals(c1a, c2));
+ assertFalse(jspb.Message.equals(c2, c3));
+ assertFalse(jspb.Message.equals(c1a, s1));
+ });
+
+ it('testEqualsExtensionsConstructed', function() {
+ assertTrue(jspb.Message.equals(
+ new proto.jspb.test.HasExtensions([]),
+ new proto.jspb.test.HasExtensions([{}])
+ ));
+ assertTrue(jspb.Message.equals(
+ new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]),
+ new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}])
+ ));
+ assertFalse(jspb.Message.equals(
+ new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]),
+ new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'b'}]}])
+ ));
+ assertTrue(jspb.Message.equals(
+ new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]),
+ new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}])
+ ));
+ assertTrue(jspb.Message.equals(
+ new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]),
+ new proto.jspb.test.HasExtensions([,,, {100: [{200: 'a'}]}])
+ ));
+ assertTrue(jspb.Message.equals(
+ new proto.jspb.test.HasExtensions([,,, {100: [{200: 'a'}]}]),
+ new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}])
+ ));
+ assertTrue(jspb.Message.equals(
+ new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]),
+ new proto.jspb.test.HasExtensions(['hi',,, {100: [{200: 'a'}]}])
+ ));
+ assertTrue(jspb.Message.equals(
+ new proto.jspb.test.HasExtensions(['hi',,, {100: [{200: 'a'}]}]),
+ new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}])
+ ));
+ });
+
+ it('testEqualsExtensionsUnconstructed', function() {
+ assertTrue(jspb.Message.compareFields([], [{}]));
+ assertTrue(jspb.Message.compareFields([,,, {}], []));
+ assertTrue(jspb.Message.compareFields([,,, {}], [,, {}]));
+ assertTrue(jspb.Message.compareFields(
+ ['hi', {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}]));
+ assertFalse(jspb.Message.compareFields(
+ ['hi', {100: [{200: 'a'}]}], ['hi', {100: [{200: 'b'}]}]));
+ assertTrue(jspb.Message.compareFields(
+ [{100: [{200: 'a'}]}], [{100: [{200: 'a'}]}]));
+ assertTrue(jspb.Message.compareFields(
+ [{100: [{200: 'a'}]}], [,,, {100: [{200: 'a'}]}]));
+ assertTrue(jspb.Message.compareFields(
+ [,,, {100: [{200: 'a'}]}], [{100: [{200: 'a'}]}]));
+ assertTrue(jspb.Message.compareFields(
+ ['hi', {100: [{200: 'a'}]}], ['hi',,, {100: [{200: 'a'}]}]));
+ assertTrue(jspb.Message.compareFields(
+ ['hi',,, {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}]));
+ });
+
+ it('testToMap', function() {
+ var p1 = new proto.jspb.test.Simple1(['k', ['v']]);
+ var p2 = new proto.jspb.test.Simple1(['k1', ['v1', 'v2']]);
+ var soymap = jspb.Message.toMap([p1, p2],
+ proto.jspb.test.Simple1.prototype.getAString,
+ proto.jspb.test.Simple1.prototype.toObject);
+ assertEquals('k', soymap['k'].aString);
+ assertArrayEquals(['v'], soymap['k'].aRepeatedStringList);
+ var protomap = jspb.Message.toMap([p1, p2],
+ proto.jspb.test.Simple1.prototype.getAString);
+ assertEquals('k', protomap['k'].getAString());
+ assertArrayEquals(['v'], protomap['k'].getARepeatedStringList());
+ });
+
+ it('testClone', function() {
+ var supportsUint8Array =
+ !goog.userAgent.IE || goog.userAgent.isVersionOrHigher('10');
+ var original = new proto.jspb.test.TestClone();
+ original.setStr('v1');
+ var simple1 = new proto.jspb.test.Simple1(['x1', ['y1', 'z1']]);
+ var simple2 = new proto.jspb.test.Simple1(['x2', ['y2', 'z2']]);
+ var simple3 = new proto.jspb.test.Simple1(['x3', ['y3', 'z3']]);
+ original.setSimple1(simple1);
+ original.setSimple2List([simple2, simple3]);
+ var bytes1 = supportsUint8Array ? new Uint8Array([1, 2, 3]) : '123';
+ original.setBytesField(bytes1);
+ var extension = new proto.jspb.test.CloneExtension();
+ extension.setExt('e1');
+ original.setExtension(proto.jspb.test.IsExtension.extField, extension);
+ var clone = original.clone();
+ assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],,
+ [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1,, { 100: [, 'e1'] }],
+ clone.toArray());
+ clone.setStr('v2');
+ var simple4 = new proto.jspb.test.Simple1(['a1', ['b1', 'c1']]);
+ var simple5 = new proto.jspb.test.Simple1(['a2', ['b2', 'c2']]);
+ var simple6 = new proto.jspb.test.Simple1(['a3', ['b3', 'c3']]);
+ clone.setSimple1(simple4);
+ clone.setSimple2List([simple5, simple6]);
+ if (supportsUint8Array) {
+ clone.getBytesField()[0] = 4;
+ assertObjectEquals(bytes1, original.getBytesField());
+ }
+ var bytes2 = supportsUint8Array ? new Uint8Array([4, 5, 6]) : '456';
+ clone.setBytesField(bytes2);
+ var newExtension = new proto.jspb.test.CloneExtension();
+ newExtension.setExt('e2');
+ clone.setExtension(proto.jspb.test.CloneExtension.extField, newExtension);
+ assertArrayEquals(['v2',, ['a1', ['b1', 'c1']],,
+ [['a2', ['b2', 'c2']], ['a3', ['b3', 'c3']]], bytes2,, { 100: [, 'e2'] }],
+ clone.toArray());
+ assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],,
+ [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1,, { 100: [, 'e1'] }],
+ original.toArray());
+ });
+
+ it('testCopyInto', function() {
+ var supportsUint8Array =
+ !goog.userAgent.IE || goog.userAgent.isVersionOrHigher('10');
+ var original = new proto.jspb.test.TestClone();
+ original.setStr('v1');
+ var dest = new proto.jspb.test.TestClone();
+ dest.setStr('override');
+ var simple1 = new proto.jspb.test.Simple1(['x1', ['y1', 'z1']]);
+ var simple2 = new proto.jspb.test.Simple1(['x2', ['y2', 'z2']]);
+ var simple3 = new proto.jspb.test.Simple1(['x3', ['y3', 'z3']]);
+ var destSimple1 = new proto.jspb.test.Simple1(['ox1', ['oy1', 'oz1']]);
+ var destSimple2 = new proto.jspb.test.Simple1(['ox2', ['oy2', 'oz2']]);
+ var destSimple3 = new proto.jspb.test.Simple1(['ox3', ['oy3', 'oz3']]);
+ original.setSimple1(simple1);
+ original.setSimple2List([simple2, simple3]);
+ dest.setSimple1(destSimple1);
+ dest.setSimple2List([destSimple2, destSimple3]);
+ var bytes1 = supportsUint8Array ? new Uint8Array([1, 2, 3]) : '123';
+ var bytes2 = supportsUint8Array ? new Uint8Array([4, 5, 6]) : '456';
+ original.setBytesField(bytes1);
+ dest.setBytesField(bytes2);
+ var extension = new proto.jspb.test.CloneExtension();
+ extension.setExt('e1');
+ original.setExtension(proto.jspb.test.CloneExtension.extField, extension);
+
+ jspb.Message.copyInto(original, dest);
+ assertArrayEquals(original.toArray(), dest.toArray());
+ assertEquals('x1', dest.getSimple1().getAString());
+ assertEquals('e1',
+ dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt());
+ dest.getSimple1().setAString('new value');
+ assertNotEquals(dest.getSimple1().getAString(),
+ original.getSimple1().getAString());
+ if (supportsUint8Array) {
+ dest.getBytesField()[0] = 7;
+ assertObjectEquals(bytes1, original.getBytesField());
+ assertObjectEquals(new Uint8Array([7, 2, 3]), dest.getBytesField());
+ } else {
+ dest.setBytesField('789');
+ assertObjectEquals(bytes1, original.getBytesField());
+ assertObjectEquals('789', dest.getBytesField());
+ }
+ dest.getExtension(proto.jspb.test.CloneExtension.extField).
+ setExt('new value');
+ assertNotEquals(
+ dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt(),
+ original.getExtension(
+ proto.jspb.test.CloneExtension.extField).getExt());
+ });
+
+ it('testCopyInto_notSameType', function() {
+ var a = new proto.jspb.test.TestClone();
+ var b = new proto.jspb.test.Simple1(['str', ['s1', 's2']]);
+
+ var e = assertThrows(function() {
+ jspb.Message.copyInto(a, b);
+ });
+ assertContains('should have the same type', e.message);
+ });
+
+ it('testExtensions', function() {
+ var extension1 = new proto.jspb.test.IsExtension(['ext1field']);
+ var extension2 = new proto.jspb.test.Simple1(['str', ['s1', 's2']]);
+ var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']);
+ extendable.setExtension(proto.jspb.test.IsExtension.extField, extension1);
+ extendable.setExtension(proto.jspb.test.IndirectExtension.simple,
+ extension2);
+ extendable.setExtension(proto.jspb.test.IndirectExtension.str, 'xyzzy');
+ extendable.setExtension(proto.jspb.test.IndirectExtension.repeatedStrList,
+ ['a', 'b']);
+ var s1 = new proto.jspb.test.Simple1(['foo', ['s1', 's2']]);
+ var s2 = new proto.jspb.test.Simple1(['bar', ['t1', 't2']]);
+ extendable.setExtension(
+ proto.jspb.test.IndirectExtension.repeatedSimpleList,
+ [s1, s2]);
+ assertObjectEquals(extension1,
+ extendable.getExtension(proto.jspb.test.IsExtension.extField));
+ assertObjectEquals(extension2,
+ extendable.getExtension(proto.jspb.test.IndirectExtension.simple));
+ assertObjectEquals('xyzzy',
+ extendable.getExtension(proto.jspb.test.IndirectExtension.str));
+ assertObjectEquals(['a', 'b'], extendable.getExtension(
+ proto.jspb.test.IndirectExtension.repeatedStrList));
+ assertObjectEquals([s1, s2], extendable.getExtension(
+ proto.jspb.test.IndirectExtension.repeatedSimpleList));
+ // Not supported yet, but it should work...
+ extendable.setExtension(proto.jspb.test.IndirectExtension.simple, null);
+ assertNull(
+ extendable.getExtension(proto.jspb.test.IndirectExtension.simple));
+ extendable.setExtension(proto.jspb.test.IndirectExtension.str, null);
+ assertNull(extendable.getExtension(proto.jspb.test.IndirectExtension.str));
+
+
+ // Extension fields with jspb.ignore = true are ignored.
+ assertUndefined(proto.jspb.test.IndirectExtension['ignored']);
+ assertUndefined(proto.jspb.test.HasExtensions['ignoredFloating']);
+ });
+
+ it('testFloatingExtensions', function() {
+ // From an autogenerated container.
+ var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']);
+ var extension = new proto.jspb.test.Simple1(['foo', ['s1', 's2']]);
+ extendable.setExtension(proto.jspb.test.simple1, extension);
+ assertObjectEquals(extension,
+ extendable.getExtension(proto.jspb.test.simple1));
+
+ // From _lib mode.
+ extension = new proto.jspb.test.ExtensionMessage(['s1']);
+ extendable = new proto.jspb.test.TestExtensionsMessage([16]);
+ extendable.setExtension(proto.jspb.test.floatingMsgField, extension);
+ extendable.setExtension(proto.jspb.test.floatingStrField, 's2');
+ assertObjectEquals(extension,
+ extendable.getExtension(proto.jspb.test.floatingMsgField));
+ assertObjectEquals('s2',
+ extendable.getExtension(proto.jspb.test.floatingStrField));
+ assertNotUndefined(proto.jspb.exttest.floatingMsgField);
+ assertNotUndefined(proto.jspb.exttest.floatingMsgFieldTwo);
+ assertNotUndefined(proto.jspb.exttest.beta.floatingStrField);
+ });
+
+ it('testNestedExtensions', function() {
+ var extendable = new proto.jspb.exttest.nested.TestNestedExtensionsMessage();
+ var extension = new proto.jspb.exttest.nested.TestOuterMessage.NestedExtensionMessage(['s1']);
+ extendable.setExtension(proto.jspb.exttest.nested.TestOuterMessage.innerExtension, extension);
+ assertObjectEquals(extension,
+ extendable.getExtension(proto.jspb.exttest.nested.TestOuterMessage.innerExtension));
+ });
+
+ it('testToObject_extendedObject', function() {
+ var extension1 = new proto.jspb.test.IsExtension(['ext1field']);
+ var extension2 = new proto.jspb.test.Simple1(['str', ['s1', 's2'], true]);
+ var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']);
+ extendable.setExtension(proto.jspb.test.IsExtension.extField, extension1);
+ extendable.setExtension(proto.jspb.test.IndirectExtension.simple,
+ extension2);
+ extendable.setExtension(proto.jspb.test.IndirectExtension.str, 'xyzzy');
+ extendable.setExtension(proto.jspb.test.IndirectExtension.repeatedStrList,
+ ['a', 'b']);
+ var s1 = new proto.jspb.test.Simple1(['foo', ['s1', 's2'], true]);
+ var s2 = new proto.jspb.test.Simple1(['bar', ['t1', 't2'], false]);
+ extendable.setExtension(
+ proto.jspb.test.IndirectExtension.repeatedSimpleList,
+ [s1, s2]);
+ assertObjectEquals({
+ str1: 'v1', str2: 'v2', str3: 'v3',
+ extField: { ext1: 'ext1field' },
+ simple: {
+ aString: 'str', aRepeatedStringList: ['s1', 's2'], aBoolean: true
+ },
+ str: 'xyzzy',
+ repeatedStrList: ['a', 'b'],
+ repeatedSimpleList: [
+ { aString: 'foo', aRepeatedStringList: ['s1', 's2'], aBoolean: true},
+ { aString: 'bar', aRepeatedStringList: ['t1', 't2'], aBoolean: false}
+ ]
+ }, extendable.toObject());
+
+ // Now, with instances included.
+ assertObjectEquals({
+ str1: 'v1', str2: 'v2', str3: 'v3',
+ extField: {
+ ext1: 'ext1field',
+ $jspbMessageInstance:
+ extendable.getExtension(proto.jspb.test.IsExtension.extField)
+ },
+ simple: {
+ aString: 'str',
+ aRepeatedStringList: ['s1', 's2'],
+ aBoolean: true,
+ $jspbMessageInstance:
+ extendable.getExtension(proto.jspb.test.IndirectExtension.simple)
+ },
+ str: 'xyzzy',
+ repeatedStrList: ['a', 'b'],
+ repeatedSimpleList: [{
+ aString: 'foo',
+ aRepeatedStringList: ['s1', 's2'],
+ aBoolean: true,
+ $jspbMessageInstance: s1
+ }, {
+ aString: 'bar',
+ aRepeatedStringList: ['t1', 't2'],
+ aBoolean: false,
+ $jspbMessageInstance: s2
+ }],
+ $jspbMessageInstance: extendable
+ }, extendable.toObject(true /* opt_includeInstance */));
+ });
+
+ it('testInitialization_emptyArray', function() {
+ var msg = new proto.jspb.test.HasExtensions([]);
+ if (jspb.Message.MINIMIZE_MEMORY_ALLOCATIONS) {
+ assertArrayEquals([], msg.toArray());
+ } else {
+ // Extension object is created past all regular fields.
+ assertArrayEquals([,,, {}], msg.toArray());
+ }
+ });
+
+ it('testInitialization_justExtensionObject', function() {
+ var msg = new proto.jspb.test.Empty([{1: 'hi'}]);
+ // The extensionObject is not moved from its original location.
+ assertArrayEquals([{1: 'hi'}], msg.toArray());
+ });
+
+ it('testInitialization_incompleteList', function() {
+ var msg = new proto.jspb.test.Empty([1, {4: 'hi'}]);
+ // The extensionObject is not moved from its original location.
+ assertArrayEquals([1, {4: 'hi'}], msg.toArray());
+ });
+
+ it('testInitialization_forwardCompatible', function() {
+ var msg = new proto.jspb.test.Empty([1, 2, 3, {1: 'hi'}]);
+ assertArrayEquals([1, 2, 3, {1: 'hi'}], msg.toArray());
+ });
+
+ 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'], 102: ''}]);
+ var obj = data.toObject();
+ assertEquals('str1', obj.str1);
+ assertEquals('ext1', obj.extField.ext1);
+ assertEquals('', obj.str);
+ });
+
+ it('testGetExtension', function() {
+ var data = new proto.jspb.test.HasExtensions(['str1', {100: ['ext1']}]);
+ assertEquals('str1', data.getStr1());
+ var extension = data.getExtension(proto.jspb.test.IsExtension.extField);
+ assertNotNull(extension);
+ assertEquals('ext1', extension.getExt1());
+ });
+
+ it('testSetExtension', function() {
+ var data = new proto.jspb.test.HasExtensions();
+ var extensionMessage = new proto.jspb.test.IsExtension(['is_extension']);
+ data.setExtension(proto.jspb.test.IsExtension.extField, extensionMessage);
+ var obj = data.toObject();
+ assertNotNull(
+ data.getExtension(proto.jspb.test.IsExtension.extField));
+ assertEquals('is_extension', obj.extField.ext1);
+ });
+
+ /**
+ * Note that group is long deprecated, we only support it because JsPb has
+ * a goal of being able to generate JS classes for all proto descriptors.
+ */
+ it('testGroups', function() {
+ var group = new proto.jspb.test.TestGroup();
+ var someGroup = new proto.jspb.test.TestGroup.RepeatedGroup();
+ someGroup.setId('g1');
+ someGroup.setSomeBoolList([true, false]);
+ group.setRepeatedGroupList([someGroup]);
+ var groups = group.getRepeatedGroupList();
+ assertEquals('g1', groups[0].getId());
+ assertObjectEquals([true, false], groups[0].getSomeBoolList());
+ assertObjectEquals({id: 'g1', someBoolList: [true, false]},
+ groups[0].toObject());
+ assertObjectEquals({
+ repeatedGroupList: [{id: 'g1', someBoolList: [true, false]}],
+ requiredGroup: {id: undefined},
+ optionalGroup: undefined,
+ requiredSimple: {aRepeatedStringList: [], aString: undefined},
+ optionalSimple: undefined,
+ id: undefined
+ }, group.toObject());
+ var group1 = new proto.jspb.test.TestGroup1();
+ group1.setGroup(someGroup);
+ assertEquals(someGroup, group1.getGroup());
+ });
+
+ it('testNonExtensionFieldsAfterExtensionRange', function() {
+ var data = [{'1': 'a_string'}];
+ var message = new proto.jspb.test.Complex(data);
+ assertArrayEquals([], message.getARepeatedStringList());
+ });
+
+ it('testReservedGetterNames', function() {
+ var message = new proto.jspb.test.TestReservedNames();
+ message.setExtension$(11);
+ message.setExtension(proto.jspb.test.TestReservedNamesExtension.foo, 12);
+ assertEquals(11, message.getExtension$());
+ assertEquals(12, message.getExtension(
+ proto.jspb.test.TestReservedNamesExtension.foo));
+ assertObjectEquals({extension: 11, foo: 12}, message.toObject());
+ });
+
+ it('testInitializeMessageWithUnsetOneof', function() {
+ var message = new proto.jspb.test.TestMessageWithOneof([]);
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.PartialOneofCase.
+ PARTIAL_ONEOF_NOT_SET,
+ message.getPartialOneofCase());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.
+ RECURSIVE_ONEOF_NOT_SET,
+ message.getRecursiveOneofCase());
+ });
+
+ it('testInitializeMessageWithSingleValueSetInOneof', function() {
+ var message = new proto.jspb.test.TestMessageWithOneof([,, 'x']);
+
+ assertEquals('x', message.getPone());
+ assertEquals('', message.getPthree());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE,
+ message.getPartialOneofCase());
+ });
+
+ it('testKeepsLastWireValueSetInUnion_multipleValues', function() {
+ var message = new proto.jspb.test.TestMessageWithOneof([,, 'x',, 'y']);
+
+ assertEquals('', message.getPone());
+ assertEquals('y', message.getPthree());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PTHREE,
+ message.getPartialOneofCase());
+ });
+
+ it('testSettingOneofFieldClearsOthers', function() {
+ var message = new proto.jspb.test.TestMessageWithOneof;
+ assertEquals('', message.getPone());
+ assertEquals('', message.getPthree());
+ assertFalse(message.hasPone());
+ assertFalse(message.hasPthree());
+
+ message.setPone('hi');
+ assertEquals('hi', message.getPone());
+ assertEquals('', message.getPthree());
+ assertTrue(message.hasPone());
+ assertFalse(message.hasPthree());
+
+ message.setPthree('bye');
+ assertEquals('', message.getPone());
+ assertEquals('bye', message.getPthree());
+ assertFalse(message.hasPone());
+ assertTrue(message.hasPthree());
+ });
+
+ it('testSettingOneofFieldDoesNotClearFieldsFromOtherUnions', function() {
+ var other = new proto.jspb.test.TestMessageWithOneof;
+ var message = new proto.jspb.test.TestMessageWithOneof;
+ assertEquals('', message.getPone());
+ assertEquals('', message.getPthree());
+ assertUndefined(message.getRone());
+ assertFalse(message.hasPone());
+ assertFalse(message.hasPthree());
+
+ message.setPone('hi');
+ message.setRone(other);
+ assertEquals('hi', message.getPone());
+ assertEquals('', message.getPthree());
+ assertEquals(other, message.getRone());
+ assertTrue(message.hasPone());
+ assertFalse(message.hasPthree());
+
+ message.setPthree('bye');
+ assertEquals('', message.getPone());
+ assertEquals('bye', message.getPthree());
+ assertEquals(other, message.getRone());
+ assertFalse(message.hasPone());
+ assertTrue(message.hasPthree());
+ });
+
+ it('testUnsetsOneofCaseWhenFieldIsCleared', function() {
+ var message = new proto.jspb.test.TestMessageWithOneof;
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.PartialOneofCase.
+ PARTIAL_ONEOF_NOT_SET,
+ message.getPartialOneofCase());
+
+ message.setPone('hi');
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE,
+ message.getPartialOneofCase());
+
+ message.clearPone();
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.PartialOneofCase.
+ PARTIAL_ONEOF_NOT_SET,
+ message.getPartialOneofCase());
+ });
+
+ it('testMessageWithDefaultOneofValues', function() {
+ var message = new proto.jspb.test.TestMessageWithOneof;
+ assertEquals(1234, message.getAone());
+ assertEquals(0, message.getAtwo());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.DefaultOneofACase
+ .DEFAULT_ONEOF_A_NOT_SET,
+ message.getDefaultOneofACase());
+
+ message.setAone(567);
+ assertEquals(567, message.getAone());
+ assertEquals(0, message.getAtwo());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.AONE,
+ message.getDefaultOneofACase());
+
+ message.setAtwo(890);
+ assertEquals(1234, message.getAone());
+ assertEquals(890, message.getAtwo());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.ATWO,
+ message.getDefaultOneofACase());
+
+ message.clearAtwo();
+ assertEquals(1234, message.getAone());
+ assertEquals(0, message.getAtwo());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.DefaultOneofACase
+ .DEFAULT_ONEOF_A_NOT_SET,
+ message.getDefaultOneofACase());
+ });
+
+ it('testMessageWithDefaultOneofValues_defaultNotOnFirstField', function() {
+ var message = new proto.jspb.test.TestMessageWithOneof;
+ assertEquals(0, message.getBone());
+ assertEquals(1234, message.getBtwo());
+ assertFalse(message.hasBone());
+ assertFalse(message.hasBtwo());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase
+ .DEFAULT_ONEOF_B_NOT_SET,
+ message.getDefaultOneofBCase());
+
+ message.setBone(2);
+ assertEquals(2, message.getBone());
+ assertEquals(1234, message.getBtwo());
+ assertTrue(message.hasBone());
+ assertFalse(message.hasBtwo());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BONE,
+ message.getDefaultOneofBCase());
+
+ message.setBtwo(3);
+ assertEquals(0, message.getBone());
+ assertFalse(message.hasBone());
+ assertTrue(message.hasBtwo());
+ assertEquals(3, message.getBtwo());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO,
+ message.getDefaultOneofBCase());
+
+ message.clearBtwo();
+ assertEquals(0, message.getBone());
+ assertFalse(message.hasBone());
+ assertFalse(message.hasBtwo());
+ assertEquals(1234, message.getBtwo());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase
+ .DEFAULT_ONEOF_B_NOT_SET,
+ message.getDefaultOneofBCase());
+ });
+
+ it('testInitializeMessageWithOneofDefaults', function() {
+ var message =
+ new proto.jspb.test.TestMessageWithOneof(new Array(9).concat(567));
+ assertEquals(567, message.getAone());
+ assertEquals(0, message.getAtwo());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.AONE,
+ message.getDefaultOneofACase());
+
+ message =
+ new proto.jspb.test.TestMessageWithOneof(new Array(10).concat(890));
+ assertEquals(1234, message.getAone());
+ assertEquals(890, message.getAtwo());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.ATWO,
+ message.getDefaultOneofACase());
+
+ message =
+ new proto.jspb.test.TestMessageWithOneof(new Array(9).concat(567, 890));
+ assertEquals(1234, message.getAone());
+ assertEquals(890, message.getAtwo());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.ATWO,
+ message.getDefaultOneofACase());
+ });
+
+ it('testInitializeMessageWithOneofDefaults_defaultNotSetOnFirstField',
+ function() {
+ var message;
+
+ message =
+ new proto.jspb.test.TestMessageWithOneof(new Array(11).concat(567));
+ assertEquals(567, message.getBone());
+ assertEquals(1234, message.getBtwo());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BONE,
+ message.getDefaultOneofBCase());
+
+ message =
+ new proto.jspb.test.TestMessageWithOneof(new Array(12).concat(890));
+ assertEquals(0, message.getBone());
+ assertEquals(890, message.getBtwo());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO,
+ message.getDefaultOneofBCase());
+
+ message = new proto.jspb.test.TestMessageWithOneof(
+ new Array(11).concat(567, 890));
+ assertEquals(0, message.getBone());
+ assertEquals(890, message.getBtwo());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO,
+ message.getDefaultOneofBCase());
+ });
+
+ it('testOneofContainingAnotherMessage', function() {
+ var message = new proto.jspb.test.TestMessageWithOneof;
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.
+ RECURSIVE_ONEOF_NOT_SET,
+ message.getRecursiveOneofCase());
+
+ var other = new proto.jspb.test.TestMessageWithOneof;
+ message.setRone(other);
+ assertEquals(other, message.getRone());
+ assertEquals('', message.getRtwo());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.RONE,
+ message.getRecursiveOneofCase());
+
+ message.setRtwo('hi');
+ assertUndefined(message.getRone());
+ assertEquals('hi', message.getRtwo());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.RTWO,
+ message.getRecursiveOneofCase());
+ });
+
+ it('testQueryingOneofCaseEnsuresOnlyOneFieldIsSetInUnderlyingArray',
+ function() {
+ var message = new proto.jspb.test.TestMessageWithOneof;
+ message.setPone('x');
+ assertEquals('x', message.getPone());
+ assertEquals('', message.getPthree());
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE,
+ message.getPartialOneofCase());
+
+ var array = message.toArray();
+ assertEquals('x', array[2]);
+ assertUndefined(array[4]);
+ array[4] = 'y';
+
+ assertEquals(
+ proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PTHREE,
+ message.getPartialOneofCase());
+ assertUndefined(array[2]);
+ assertEquals('y', array[4]);
+ });
+
+ it('testFloatingPointFieldsSupportNan', function() {
+ var assertNan = function(x) {
+ assertTrue('Expected ' + x + ' (' + goog.typeOf(x) + ') to be NaN.',
+ goog.isNumber(x) && isNaN(x));
+ };
+
+ var message = new proto.jspb.test.FloatingPointFields([
+ 'NaN', 'NaN', ['NaN', 'NaN'], 'NaN',
+ 'NaN', 'NaN', ['NaN', 'NaN'], 'NaN'
+ ]);
+ assertNan(message.getOptionalFloatField());
+ assertNan(message.getRequiredFloatField());
+ assertNan(message.getRepeatedFloatFieldList()[0]);
+ assertNan(message.getRepeatedFloatFieldList()[1]);
+ assertNan(message.getDefaultFloatField());
+ assertNan(message.getOptionalDoubleField());
+ assertNan(message.getRequiredDoubleField());
+ assertNan(message.getRepeatedDoubleFieldList()[0]);
+ assertNan(message.getRepeatedDoubleFieldList()[1]);
+ assertNan(message.getDefaultDoubleField());
+ });
+
+});
diff --git a/third_party/protobuf/js/node_loader.js b/third_party/protobuf/js/node_loader.js
new file mode 100644
index 0000000000..79211adda4
--- /dev/null
+++ b/third_party/protobuf/js/node_loader.js
@@ -0,0 +1,49 @@
+// 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.
+
+/**
+ * @fileoverview Loader that handles goog.require() for Node.JS.
+ */
+
+var oldLoader = goog.global.CLOSURE_IMPORT_SCRIPT;
+
+goog.global.CLOSURE_IMPORT_SCRIPT = function(src, opt_sourceText) {
+ if (opt_sourceText === undefined) {
+ try {
+ // Load from the current directory.
+ require("./" + src);
+ return true;
+ } catch (e) {
+ // Fall back to the Closure loader.
+ }
+ }
+
+ return oldLoader(src, opt_sourceText);
+};
diff --git a/third_party/protobuf/js/package.json b/third_party/protobuf/js/package.json
new file mode 100644
index 0000000000..dd6373de0d
--- /dev/null
+++ b/third_party/protobuf/js/package.json
@@ -0,0 +1,26 @@
+{
+ "name": "google-protobuf",
+ "version": "3.2.0",
+ "description": "Protocol Buffers for JavaScript",
+ "main": "google-protobuf.js",
+ "files": [
+ "google"
+ ],
+ "dependencies": {},
+ "devDependencies": {
+ "glob": "~6.0.4",
+ "google-closure-compiler": "~20160619.0.0",
+ "google-closure-library": "~20160125.0.0",
+ "gulp": "~3.9.0",
+ "jasmine": "~2.4.1"
+ },
+ "scripts": {
+ "test": "node ./node_modules/gulp/bin/gulp.js test"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/google/protobuf/tree/master/js"
+ },
+ "author": "Google Protocol Buffers Team",
+ "license" : "BSD-3-Clause"
+}
diff --git a/third_party/protobuf/js/proto3_test.js b/third_party/protobuf/js/proto3_test.js
new file mode 100644
index 0000000000..81d6de2f5e
--- /dev/null
+++ b/third_party/protobuf/js/proto3_test.js
@@ -0,0 +1,367 @@
+// 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.crypt.base64');
+goog.require('goog.testing.asserts');
+
+// CommonJS-LoadFromFile: testbinary_pb proto.jspb.test
+goog.require('proto.jspb.test.ForeignMessage');
+
+// CommonJS-LoadFromFile: proto3_test_pb proto.jspb.test
+goog.require('proto.jspb.test.Proto3Enum');
+goog.require('proto.jspb.test.TestProto3');
+
+// CommonJS-LoadFromFile: google/protobuf/timestamp_pb proto.google.protobuf
+goog.require('proto.google.protobuf.Timestamp');
+
+// CommonJS-LoadFromFile: google/protobuf/struct_pb proto.google.protobuf
+goog.require('proto.google.protobuf.Struct');
+
+
+var BYTES = new Uint8Array([1, 2, 8, 9]);
+var BYTES_B64 = goog.crypt.base64.encodeByteArray(BYTES);
+
+
+/**
+ * Helper: compare a bytes field to an expected value
+ * @param {Uint8Array|string} arr
+ * @param {Uint8Array} expected
+ * @return {boolean}
+ */
+function bytesCompare(arr, expected) {
+ if (goog.isString(arr)) {
+ arr = goog.crypt.base64.decodeStringToUint8Array(arr);
+ }
+ if (arr.length != expected.length) {
+ return false;
+ }
+ for (var i = 0; i < arr.length; i++) {
+ if (arr[i] != expected[i]) {
+ return false;
+ }
+ }
+ return true;
+}
+
+
+describe('proto3Test', function() {
+ /**
+ * Test defaults for proto3 message fields.
+ */
+ it('testProto3FieldDefaults', function() {
+ var msg = new proto.jspb.test.TestProto3();
+
+ assertEquals(msg.getOptionalInt32(), 0);
+ assertEquals(msg.getOptionalInt64(), 0);
+ assertEquals(msg.getOptionalUint32(), 0);
+ assertEquals(msg.getOptionalUint64(), 0);
+ assertEquals(msg.getOptionalSint32(), 0);
+ assertEquals(msg.getOptionalSint64(), 0);
+ assertEquals(msg.getOptionalFixed32(), 0);
+ assertEquals(msg.getOptionalFixed64(), 0);
+ assertEquals(msg.getOptionalSfixed32(), 0);
+ assertEquals(msg.getOptionalSfixed64(), 0);
+ assertEquals(msg.getOptionalFloat(), 0);
+ assertEquals(msg.getOptionalDouble(), 0);
+ assertEquals(msg.getOptionalString(), '');
+
+ // TODO(b/26173701): when we change bytes fields default getter to return
+ // Uint8Array, we'll want to switch this assertion to match the u8 case.
+ assertEquals(typeof msg.getOptionalBytes(), 'string');
+ assertEquals(msg.getOptionalBytes_asU8() instanceof Uint8Array, true);
+ assertEquals(typeof msg.getOptionalBytes_asB64(), 'string');
+ assertEquals(msg.getOptionalBytes().length, 0);
+ assertEquals(msg.getOptionalBytes_asU8().length, 0);
+ assertEquals(msg.getOptionalBytes_asB64(), '');
+
+ assertEquals(msg.getOptionalForeignEnum(),
+ proto.jspb.test.Proto3Enum.PROTO3_FOO);
+ assertEquals(msg.getOptionalForeignMessage(), undefined);
+ assertEquals(msg.getOptionalForeignMessage(), undefined);
+
+ assertEquals(msg.getRepeatedInt32List().length, 0);
+ assertEquals(msg.getRepeatedInt64List().length, 0);
+ assertEquals(msg.getRepeatedUint32List().length, 0);
+ assertEquals(msg.getRepeatedUint64List().length, 0);
+ assertEquals(msg.getRepeatedSint32List().length, 0);
+ assertEquals(msg.getRepeatedSint64List().length, 0);
+ assertEquals(msg.getRepeatedFixed32List().length, 0);
+ assertEquals(msg.getRepeatedFixed64List().length, 0);
+ assertEquals(msg.getRepeatedSfixed32List().length, 0);
+ assertEquals(msg.getRepeatedSfixed64List().length, 0);
+ assertEquals(msg.getRepeatedFloatList().length, 0);
+ assertEquals(msg.getRepeatedDoubleList().length, 0);
+ assertEquals(msg.getRepeatedStringList().length, 0);
+ assertEquals(msg.getRepeatedBytesList().length, 0);
+ assertEquals(msg.getRepeatedForeignEnumList().length, 0);
+ assertEquals(msg.getRepeatedForeignMessageList().length, 0);
+
+ });
+
+
+ /**
+ * Test that all fields can be set and read via a serialization roundtrip.
+ */
+ it('testProto3FieldSetGet', function() {
+ var msg = new proto.jspb.test.TestProto3();
+
+ msg.setOptionalInt32(-42);
+ msg.setOptionalInt64(-0x7fffffff00000000);
+ msg.setOptionalUint32(0x80000000);
+ msg.setOptionalUint64(0xf000000000000000);
+ msg.setOptionalSint32(-100);
+ msg.setOptionalSint64(-0x8000000000000000);
+ msg.setOptionalFixed32(1234);
+ msg.setOptionalFixed64(0x1234567800000000);
+ msg.setOptionalSfixed32(-1234);
+ msg.setOptionalSfixed64(-0x1234567800000000);
+ msg.setOptionalFloat(1.5);
+ msg.setOptionalDouble(-1.5);
+ msg.setOptionalBool(true);
+ msg.setOptionalString('hello world');
+ msg.setOptionalBytes(BYTES);
+ var submsg = new proto.jspb.test.ForeignMessage();
+ submsg.setC(16);
+ msg.setOptionalForeignMessage(submsg);
+ msg.setOptionalForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_BAR);
+
+ msg.setRepeatedInt32List([-42]);
+ msg.setRepeatedInt64List([-0x7fffffff00000000]);
+ msg.setRepeatedUint32List([0x80000000]);
+ msg.setRepeatedUint64List([0xf000000000000000]);
+ msg.setRepeatedSint32List([-100]);
+ msg.setRepeatedSint64List([-0x8000000000000000]);
+ msg.setRepeatedFixed32List([1234]);
+ msg.setRepeatedFixed64List([0x1234567800000000]);
+ msg.setRepeatedSfixed32List([-1234]);
+ msg.setRepeatedSfixed64List([-0x1234567800000000]);
+ msg.setRepeatedFloatList([1.5]);
+ msg.setRepeatedDoubleList([-1.5]);
+ msg.setRepeatedBoolList([true]);
+ msg.setRepeatedStringList(['hello world']);
+ msg.setRepeatedBytesList([BYTES]);
+ submsg = new proto.jspb.test.ForeignMessage();
+ submsg.setC(1000);
+ msg.setRepeatedForeignMessageList([submsg]);
+ msg.setRepeatedForeignEnumList([proto.jspb.test.Proto3Enum.PROTO3_BAR]);
+
+ msg.setOneofString('asdf');
+
+ var serialized = msg.serializeBinary();
+ msg = proto.jspb.test.TestProto3.deserializeBinary(serialized);
+
+ assertEquals(msg.getOptionalInt32(), -42);
+ assertEquals(msg.getOptionalInt64(), -0x7fffffff00000000);
+ assertEquals(msg.getOptionalUint32(), 0x80000000);
+ assertEquals(msg.getOptionalUint64(), 0xf000000000000000);
+ assertEquals(msg.getOptionalSint32(), -100);
+ assertEquals(msg.getOptionalSint64(), -0x8000000000000000);
+ assertEquals(msg.getOptionalFixed32(), 1234);
+ assertEquals(msg.getOptionalFixed64(), 0x1234567800000000);
+ assertEquals(msg.getOptionalSfixed32(), -1234);
+ assertEquals(msg.getOptionalSfixed64(), -0x1234567800000000);
+ assertEquals(msg.getOptionalFloat(), 1.5);
+ assertEquals(msg.getOptionalDouble(), -1.5);
+ assertEquals(msg.getOptionalBool(), true);
+ assertEquals(msg.getOptionalString(), 'hello world');
+ assertEquals(true, bytesCompare(msg.getOptionalBytes(), BYTES));
+ assertEquals(msg.getOptionalForeignMessage().getC(), 16);
+ assertEquals(msg.getOptionalForeignEnum(),
+ proto.jspb.test.Proto3Enum.PROTO3_BAR);
+
+ assertElementsEquals(msg.getRepeatedInt32List(), [-42]);
+ assertElementsEquals(msg.getRepeatedInt64List(), [-0x7fffffff00000000]);
+ assertElementsEquals(msg.getRepeatedUint32List(), [0x80000000]);
+ assertElementsEquals(msg.getRepeatedUint64List(), [0xf000000000000000]);
+ assertElementsEquals(msg.getRepeatedSint32List(), [-100]);
+ assertElementsEquals(msg.getRepeatedSint64List(), [-0x8000000000000000]);
+ assertElementsEquals(msg.getRepeatedFixed32List(), [1234]);
+ assertElementsEquals(msg.getRepeatedFixed64List(), [0x1234567800000000]);
+ assertElementsEquals(msg.getRepeatedSfixed32List(), [-1234]);
+ assertElementsEquals(msg.getRepeatedSfixed64List(), [-0x1234567800000000]);
+ assertElementsEquals(msg.getRepeatedFloatList(), [1.5]);
+ assertElementsEquals(msg.getRepeatedDoubleList(), [-1.5]);
+ assertElementsEquals(msg.getRepeatedBoolList(), [true]);
+ assertElementsEquals(msg.getRepeatedStringList(), ['hello world']);
+ assertEquals(msg.getRepeatedBytesList().length, 1);
+ assertEquals(true, bytesCompare(msg.getRepeatedBytesList()[0], BYTES));
+ assertEquals(msg.getRepeatedForeignMessageList().length, 1);
+ assertEquals(msg.getRepeatedForeignMessageList()[0].getC(), 1000);
+ assertElementsEquals(msg.getRepeatedForeignEnumList(),
+ [proto.jspb.test.Proto3Enum.PROTO3_BAR]);
+
+ assertEquals(msg.getOneofString(), 'asdf');
+ });
+
+
+ /**
+ * Test that oneofs continue to have a notion of field presence.
+ */
+ it('testOneofs', function() {
+ var msg = new proto.jspb.test.TestProto3();
+
+ assertEquals(msg.getOneofUint32(), 0);
+ assertEquals(msg.getOneofForeignMessage(), undefined);
+ assertEquals(msg.getOneofString(), '');
+ assertEquals(msg.getOneofBytes(), '');
+ assertFalse(msg.hasOneofUint32());
+ assertFalse(msg.hasOneofString());
+ assertFalse(msg.hasOneofBytes());
+
+ msg.setOneofUint32(42);
+ assertEquals(msg.getOneofUint32(), 42);
+ assertEquals(msg.getOneofForeignMessage(), undefined);
+ assertEquals(msg.getOneofString(), '');
+ assertEquals(msg.getOneofBytes(), '');
+ assertTrue(msg.hasOneofUint32());
+ assertFalse(msg.hasOneofString());
+ assertFalse(msg.hasOneofBytes());
+
+
+ var submsg = new proto.jspb.test.ForeignMessage();
+ msg.setOneofForeignMessage(submsg);
+ assertEquals(msg.getOneofUint32(), 0);
+ assertEquals(msg.getOneofForeignMessage(), submsg);
+ assertEquals(msg.getOneofString(), '');
+ assertEquals(msg.getOneofBytes(), '');
+ assertFalse(msg.hasOneofUint32());
+ assertFalse(msg.hasOneofString());
+ assertFalse(msg.hasOneofBytes());
+
+ msg.setOneofString('hello');
+ assertEquals(msg.getOneofUint32(), 0);
+ assertEquals(msg.getOneofForeignMessage(), undefined);
+ assertEquals(msg.getOneofString(), 'hello');
+ assertEquals(msg.getOneofBytes(), '');
+ assertFalse(msg.hasOneofUint32());
+ assertTrue(msg.hasOneofString());
+ assertFalse(msg.hasOneofBytes());
+
+ msg.setOneofBytes(goog.crypt.base64.encodeString('\u00FF\u00FF'));
+ assertEquals(msg.getOneofUint32(), 0);
+ assertEquals(msg.getOneofForeignMessage(), undefined);
+ assertEquals(msg.getOneofString(), '');
+ assertEquals(msg.getOneofBytes_asB64(),
+ goog.crypt.base64.encodeString('\u00FF\u00FF'));
+ assertFalse(msg.hasOneofUint32());
+ assertFalse(msg.hasOneofString());
+ assertTrue(msg.hasOneofBytes());
+ });
+
+
+ /**
+ * Test that "default"-valued primitive fields are not emitted on the wire.
+ */
+ it('testNoSerializeDefaults', function() {
+ var msg = new proto.jspb.test.TestProto3();
+
+ // Set each primitive to a non-default value, then back to its default, to
+ // ensure that the serialization is actually checking the value and not just
+ // whether it has ever been set.
+ msg.setOptionalInt32(42);
+ msg.setOptionalInt32(0);
+ msg.setOptionalDouble(3.14);
+ msg.setOptionalDouble(0.0);
+ msg.setOptionalBool(true);
+ msg.setOptionalBool(false);
+ msg.setOptionalString('hello world');
+ msg.setOptionalString('');
+ msg.setOptionalBytes(goog.crypt.base64.encodeString('\u00FF\u00FF'));
+ msg.setOptionalBytes('');
+ msg.setOptionalForeignMessage(new proto.jspb.test.ForeignMessage());
+ msg.setOptionalForeignMessage(null);
+ msg.setOptionalForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_BAR);
+ msg.setOptionalForeignEnum(proto.jspb.test.Proto3Enum.PROTO3_FOO);
+ msg.setOneofUint32(32);
+ msg.clearOneofUint32();
+
+
+ var serialized = msg.serializeBinary();
+ assertEquals(0, serialized.length);
+ });
+
+ /**
+ * Test that base64 string and Uint8Array are interchangeable in bytes fields.
+ */
+ it('testBytesFieldsInterop', function() {
+ var msg = new proto.jspb.test.TestProto3();
+ // Set as a base64 string and check all the getters work.
+ msg.setOptionalBytes(BYTES_B64);
+ assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES));
+ assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES));
+ assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));
+
+ // Test binary serialize round trip doesn't break it.
+ msg = proto.jspb.test.TestProto3.deserializeBinary(msg.serializeBinary());
+ assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES));
+ assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES));
+ assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));
+
+ msg = new proto.jspb.test.TestProto3();
+ // Set as a Uint8Array and check all the getters work.
+ msg.setOptionalBytes(BYTES);
+ assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES));
+ assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES));
+ assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES));
+
+ });
+
+ it('testTimestampWellKnownType', function() {
+ var msg = new proto.google.protobuf.Timestamp();
+ msg.fromDate(new Date(123456789));
+ assertEquals(123456, msg.getSeconds());
+ assertEquals(789000000, msg.getNanos());
+ var date = msg.toDate();
+ assertEquals(123456789, date.getTime());
+ });
+
+ it('testStructWellKnownType', function() {
+ var jsObj = {
+ abc: "def",
+ number: 12345.678,
+ nullKey: null,
+ boolKey: true,
+ listKey: [1, null, true, false, "abc"],
+ structKey: {foo: "bar", somenum: 123},
+ complicatedKey: [{xyz: {abc: [3, 4, null, false]}}, "zzz"]
+ };
+
+ var struct = proto.google.protobuf.Struct.fromJavaScript(jsObj);
+ var jsObj2 = struct.toJavaScript();
+
+ assertEquals("def", jsObj2.abc);
+ assertEquals(12345.678, jsObj2.number);
+ assertEquals(null, jsObj2.nullKey);
+ assertEquals(true, jsObj2.boolKey);
+ assertEquals("abc", jsObj2.listKey[4]);
+ assertEquals("bar", jsObj2.structKey.foo);
+ assertEquals(4, jsObj2.complicatedKey[0].xyz.abc[1]);
+ });
+});
diff --git a/third_party/protobuf/js/proto3_test.proto b/third_party/protobuf/js/proto3_test.proto
new file mode 100644
index 0000000000..acb6716492
--- /dev/null
+++ b/third_party/protobuf/js/proto3_test.proto
@@ -0,0 +1,89 @@
+// 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.
+
+syntax = "proto3";
+
+import "testbinary.proto";
+
+package jspb.test;
+
+message TestProto3 {
+ int32 optional_int32 = 1;
+ int64 optional_int64 = 2;
+ uint32 optional_uint32 = 3;
+ uint64 optional_uint64 = 4;
+ sint32 optional_sint32 = 5;
+ sint64 optional_sint64 = 6;
+ fixed32 optional_fixed32 = 7;
+ fixed64 optional_fixed64 = 8;
+ sfixed32 optional_sfixed32 = 9;
+ sfixed64 optional_sfixed64 = 10;
+ float optional_float = 11;
+ double optional_double = 12;
+ bool optional_bool = 13;
+ string optional_string = 14;
+ bytes optional_bytes = 15;
+
+ ForeignMessage optional_foreign_message = 19;
+ Proto3Enum optional_foreign_enum = 22;
+
+ repeated int32 repeated_int32 = 31;
+ repeated int64 repeated_int64 = 32;
+ repeated uint32 repeated_uint32 = 33;
+ repeated uint64 repeated_uint64 = 34;
+ repeated sint32 repeated_sint32 = 35;
+ repeated sint64 repeated_sint64 = 36;
+ repeated fixed32 repeated_fixed32 = 37;
+ repeated fixed64 repeated_fixed64 = 38;
+ repeated sfixed32 repeated_sfixed32 = 39;
+ repeated sfixed64 repeated_sfixed64 = 40;
+ repeated float repeated_float = 41;
+ repeated double repeated_double = 42;
+ repeated bool repeated_bool = 43;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+
+ repeated ForeignMessage repeated_foreign_message = 49;
+ repeated Proto3Enum repeated_foreign_enum = 52;
+
+
+ oneof oneof_field {
+ uint32 oneof_uint32 = 111;
+ ForeignMessage oneof_foreign_message = 112;
+ string oneof_string = 113;
+ bytes oneof_bytes = 114;
+ }
+}
+
+enum Proto3Enum {
+ PROTO3_FOO = 0;
+ PROTO3_BAR = 1;
+ PROTO3_BAZ = 2;
+}
diff --git a/third_party/protobuf/js/test.proto b/third_party/protobuf/js/test.proto
new file mode 100644
index 0000000000..2be5b8c184
--- /dev/null
+++ b/third_party/protobuf/js/test.proto
@@ -0,0 +1,273 @@
+// 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.
+
+// Author: mwr@google.com (Mark Rawling)
+
+syntax = "proto2";
+
+option java_package = "com.google.apps.jspb.proto";
+option java_multiple_files = true;
+
+import "google/protobuf/descriptor.proto";
+
+package jspb.test;
+
+message Empty {
+}
+
+enum OuterEnum {
+ FOO = 1;
+ BAR = 2;
+}
+
+message EnumContainer {
+ optional OuterEnum outer_enum = 1;
+}
+
+message Simple1 {
+ required string a_string = 1;
+ repeated string a_repeated_string = 2;
+ optional bool a_boolean = 3;
+}
+
+// A message that differs from Simple1 only by name
+message Simple2 {
+ required string a_string = 1;
+ repeated string a_repeated_string = 2;
+}
+
+message SpecialCases {
+ required string normal = 1;
+ // Examples of Js reserved names that are converted to pb_<name>.
+ required string default = 2;
+ required string function = 3;
+ required string var = 4;
+}
+
+message OptionalFields {
+ message Nested {
+ optional int32 an_int = 1;
+ }
+ optional string a_string = 1;
+ required bool a_bool = 2;
+ optional Nested a_nested_message = 3;
+ repeated Nested a_repeated_message = 4;
+ repeated string a_repeated_string = 5;
+}
+
+message HasExtensions {
+ optional string str1 = 1;
+ optional string str2 = 2;
+ optional string str3 = 3;
+ extensions 10 to max;
+}
+
+message Complex {
+ message Nested {
+ required int32 an_int = 2;
+ }
+ required string a_string = 1;
+ required bool an_out_of_order_bool = 9;
+ optional Nested a_nested_message = 4;
+ repeated Nested a_repeated_message = 5;
+ repeated string a_repeated_string = 7;
+}
+
+message OuterMessage {
+ // Make sure this doesn't conflict with the other Complex message.
+ message Complex {
+ optional int32 inner_complex_field = 1;
+ }
+}
+
+message IsExtension {
+ extend HasExtensions {
+ optional IsExtension ext_field = 100;
+ }
+ optional string ext1 = 1;
+
+ // Extensions of proto2 Descriptor messages will be ignored.
+ extend google.protobuf.EnumOptions {
+ optional string simple_option = 42113038;
+ }
+}
+
+message IndirectExtension {
+ extend HasExtensions {
+ optional Simple1 simple = 101;
+ optional string str = 102;
+ repeated string repeated_str = 103;
+ repeated Simple1 repeated_simple = 104;
+ }
+}
+
+extend HasExtensions {
+ optional Simple1 simple1 = 105;
+}
+
+message DefaultValues {
+ enum Enum {
+ E1 = 13;
+ E2 = 77;
+ }
+ optional string string_field = 1 [default="default<>\'\"abc"];
+ optional bool bool_field = 2 [default=true];
+ optional int64 int_field = 3 [default=11];
+ optional Enum enum_field = 4 [default=E1];
+ optional string empty_field = 6 [default=""];
+ optional bytes bytes_field = 8 [default="moo"]; // Base64 encoding is "bW9v"
+}
+
+message FloatingPointFields {
+ optional float optional_float_field = 1;
+ required float required_float_field = 2;
+ repeated float repeated_float_field = 3;
+ optional float default_float_field = 4 [default = 2.0];
+ optional double optional_double_field = 5;
+ required double required_double_field = 6;
+ repeated double repeated_double_field = 7;
+ optional double default_double_field = 8 [default = 2.0];
+}
+
+message TestClone {
+ optional string str = 1;
+ optional Simple1 simple1 = 3;
+ repeated Simple1 simple2 = 5;
+ optional bytes bytes_field = 6;
+ optional string unused = 7;
+ extensions 10 to max;
+}
+
+message CloneExtension {
+ extend TestClone {
+ optional CloneExtension ext_field = 100;
+ }
+ optional string ext = 2;
+}
+
+message TestGroup {
+ repeated group RepeatedGroup = 1 {
+ required string id = 1;
+ repeated bool some_bool = 2;
+ }
+ required group RequiredGroup = 2 {
+ required string id = 1;
+ }
+ optional group OptionalGroup = 3 {
+ required string id = 1;
+ }
+ optional string id = 4;
+ required Simple2 required_simple = 5;
+ optional Simple2 optional_simple = 6;
+}
+
+message TestGroup1 {
+ optional TestGroup.RepeatedGroup group = 1;
+}
+
+message TestReservedNames {
+ optional int32 extension = 1;
+ extensions 10 to max;
+}
+
+message TestReservedNamesExtension {
+ extend TestReservedNames {
+ optional int32 foo = 10;
+ }
+}
+
+message TestMessageWithOneof {
+
+ oneof partial_oneof {
+ string pone = 3;
+ string pthree = 5;
+ }
+
+ oneof recursive_oneof {
+ TestMessageWithOneof rone = 6;
+ string rtwo = 7;
+ }
+
+ optional bool normal_field = 8;
+ repeated string repeated_field = 9;
+
+ oneof default_oneof_a {
+ int32 aone = 10 [default = 1234];
+ int32 atwo = 11;
+ }
+
+ oneof default_oneof_b {
+ int32 bone = 12;
+ int32 btwo = 13 [default = 1234];
+ }
+}
+
+message TestEndsWithBytes {
+ optional int32 value = 1;
+ optional bytes data = 2;
+}
+
+
+message TestMapFieldsNoBinary {
+
+ map<string, string> map_string_string = 1;
+ map<string, int32> map_string_int32 = 2;
+ map<string, int64> map_string_int64 = 3;
+ map<string, bool> map_string_bool = 4;
+ map<string, double> map_string_double = 5;
+ map<string, MapValueEnumNoBinary> map_string_enum = 6;
+ map<string, MapValueMessageNoBinary> map_string_msg = 7;
+
+ map<int32, string> map_int32_string = 8;
+ map<int64, string> map_int64_string = 9;
+ map<bool, string> map_bool_string = 10;
+
+ optional TestMapFieldsNoBinary test_map_fields = 11;
+ map<string, TestMapFieldsNoBinary> map_string_testmapfields = 12;
+}
+
+enum MapValueEnumNoBinary {
+ MAP_VALUE_FOO_NOBINARY = 0;
+ MAP_VALUE_BAR_NOBINARY = 1;
+ MAP_VALUE_BAZ_NOBINARY = 2;
+}
+
+message MapValueMessageNoBinary {
+
+ optional int32 foo = 1;
+}
+
+message Deeply {
+ message Nested {
+ message Message {
+ optional int32 count = 1;
+ }
+ }
+}
diff --git a/third_party/protobuf/js/test2.proto b/third_party/protobuf/js/test2.proto
new file mode 100644
index 0000000000..b67f93fa9e
--- /dev/null
+++ b/third_party/protobuf/js/test2.proto
@@ -0,0 +1,60 @@
+// 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.
+
+syntax = "proto2";
+
+option java_package = "com.google.apps.jspb.proto";
+option java_multiple_files = true;
+
+package jspb.test;
+
+import "test.proto";
+
+message TestExtensionsMessage {
+ optional int32 intfield = 1;
+ extensions 100 to max;
+}
+
+message ExtensionMessage {
+ extend TestExtensionsMessage {
+ optional ExtensionMessage ext_field = 100;
+ }
+ optional string ext1 = 1;
+}
+
+// Floating extensions are only supported when generating a _lib.js library.
+extend TestExtensionsMessage {
+ optional ExtensionMessage floating_msg_field = 101;
+ optional string floating_str_field = 102;
+}
+
+message ForeignNestedFieldMessage {
+ optional Deeply.Nested.Message deeply_nested_message = 1;
+}
diff --git a/third_party/protobuf/js/test3.proto b/third_party/protobuf/js/test3.proto
new file mode 100644
index 0000000000..940a552ed5
--- /dev/null
+++ b/third_party/protobuf/js/test3.proto
@@ -0,0 +1,53 @@
+// 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.
+
+syntax = "proto2";
+
+option java_package = "com.google.apps.jspb.proto";
+option java_multiple_files = true;
+
+package jspb.exttest;
+
+message TestExtensionsMessage {
+ optional int32 intfield = 1;
+ extensions 100 to max;
+}
+
+message ExtensionMessage {
+ extend TestExtensionsMessage {
+ optional ExtensionMessage ext_field = 100;
+ }
+ optional string ext1 = 1;
+}
+
+extend TestExtensionsMessage {
+ optional ExtensionMessage floating_msg_field = 101;
+ optional string floating_str_field = 102;
+}
diff --git a/third_party/protobuf/js/test4.proto b/third_party/protobuf/js/test4.proto
new file mode 100644
index 0000000000..cf2451e9cb
--- /dev/null
+++ b/third_party/protobuf/js/test4.proto
@@ -0,0 +1,42 @@
+// 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.
+
+syntax = "proto2";
+
+option java_package = "com.google.apps.jspb.proto";
+option java_multiple_files = true;
+
+package jspb.exttest;
+
+import "test3.proto";
+
+extend TestExtensionsMessage {
+ optional ExtensionMessage floating_msg_field_two = 103;
+}
diff --git a/third_party/protobuf/js/test5.proto b/third_party/protobuf/js/test5.proto
new file mode 100644
index 0000000000..34979517e5
--- /dev/null
+++ b/third_party/protobuf/js/test5.proto
@@ -0,0 +1,44 @@
+// 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.
+
+syntax = "proto2";
+
+option java_package = "com.google.apps.jspb.proto";
+option java_multiple_files = true;
+
+package jspb.exttest.beta;
+
+message TestBetaExtensionsMessage {
+ extensions 100 to max;
+}
+
+extend TestBetaExtensionsMessage {
+ optional string floating_str_field = 101;
+}
diff --git a/third_party/protobuf/js/test8.proto b/third_party/protobuf/js/test8.proto
new file mode 100644
index 0000000000..2ae80dab67
--- /dev/null
+++ b/third_party/protobuf/js/test8.proto
@@ -0,0 +1,50 @@
+// 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.
+
+syntax = "proto2";
+
+option java_package = "com.google.apps.jspb.proto";
+option java_multiple_files = true;
+
+package jspb.exttest.nested;
+
+message TestNestedExtensionsMessage {
+ optional int32 intfield = 1;
+ extensions 100 to max;
+}
+
+message TestOuterMessage {
+ message NestedExtensionMessage {
+ optional string ext1 = 1;
+ }
+ extend TestNestedExtensionsMessage {
+ optional NestedExtensionMessage inner_extension = 100;
+ }
+}
diff --git a/third_party/protobuf/js/test_bootstrap.js b/third_party/protobuf/js/test_bootstrap.js
new file mode 100644
index 0000000000..9d00a1c430
--- /dev/null
+++ b/third_party/protobuf/js/test_bootstrap.js
@@ -0,0 +1,41 @@
+// 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.
+
+/**
+ * @fileoverview Sets flags for uncompiled JSUnit tests.
+ */
+
+/**
+ * Set uncompiled flags.
+ */
+var CLOSURE_DEFINES = {
+ // Enable the fromObject method on the message class.
+ 'jspb.Message.GENERATE_FROM_OBJECT': true
+};
diff --git a/third_party/protobuf/js/testbinary.proto b/third_party/protobuf/js/testbinary.proto
new file mode 100644
index 0000000000..116f17fb50
--- /dev/null
+++ b/third_party/protobuf/js/testbinary.proto
@@ -0,0 +1,212 @@
+// 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.
+
+// LINT: ALLOW_GROUPS
+
+syntax = "proto2";
+
+
+package jspb.test;
+
+// These types are borrowed from `unittest.proto` in the protobuf tree. We want
+// to ensure that the binary-format support will handle all field types
+// properly.
+message TestAllTypes {
+ optional int32 optional_int32 = 1;
+ optional int64 optional_int64 = 2;
+ optional uint32 optional_uint32 = 3;
+ optional uint64 optional_uint64 = 4;
+ optional sint32 optional_sint32 = 5;
+ optional sint64 optional_sint64 = 6;
+ optional fixed32 optional_fixed32 = 7;
+ optional fixed64 optional_fixed64 = 8;
+ optional sfixed32 optional_sfixed32 = 9;
+ optional sfixed64 optional_sfixed64 = 10;
+ optional float optional_float = 11;
+ optional double optional_double = 12;
+ optional bool optional_bool = 13;
+ optional string optional_string = 14;
+ optional bytes optional_bytes = 15;
+ optional group OptionalGroup = 16 {
+ optional int32 a = 17;
+ }
+
+ optional ForeignMessage optional_foreign_message = 19;
+ optional ForeignEnum optional_foreign_enum = 22;
+
+ // Repeated
+ repeated int32 repeated_int32 = 31;
+ repeated int64 repeated_int64 = 32;
+ repeated uint32 repeated_uint32 = 33;
+ repeated uint64 repeated_uint64 = 34;
+ repeated sint32 repeated_sint32 = 35;
+ repeated sint64 repeated_sint64 = 36;
+ repeated fixed32 repeated_fixed32 = 37;
+ repeated fixed64 repeated_fixed64 = 38;
+ repeated sfixed32 repeated_sfixed32 = 39;
+ repeated sfixed64 repeated_sfixed64 = 40;
+ repeated float repeated_float = 41;
+ repeated double repeated_double = 42;
+ repeated bool repeated_bool = 43;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+
+ repeated group RepeatedGroup = 46 {
+ optional int32 a = 47;
+ }
+
+ repeated ForeignMessage repeated_foreign_message = 49;
+ repeated ForeignEnum repeated_foreign_enum = 52;
+
+ // Packed repeated
+ repeated int32 packed_repeated_int32 = 61 [packed=true];
+ repeated int64 packed_repeated_int64 = 62 [packed=true];
+ repeated uint32 packed_repeated_uint32 = 63 [packed=true];
+ repeated uint64 packed_repeated_uint64 = 64 [packed=true];
+ repeated sint32 packed_repeated_sint32 = 65 [packed=true];
+ repeated sint64 packed_repeated_sint64 = 66 [packed=true];
+ repeated fixed32 packed_repeated_fixed32 = 67 [packed=true];
+ repeated fixed64 packed_repeated_fixed64 = 68 [packed=true];
+ repeated sfixed32 packed_repeated_sfixed32 = 69 [packed=true];
+ repeated sfixed64 packed_repeated_sfixed64 = 70 [packed=true];
+ repeated float packed_repeated_float = 71 [packed=true];
+ repeated double packed_repeated_double = 72 [packed=true];
+ repeated bool packed_repeated_bool = 73 [packed=true];
+
+ oneof oneof_field {
+ uint32 oneof_uint32 = 111;
+ ForeignMessage oneof_foreign_message = 112;
+ string oneof_string = 113;
+ bytes oneof_bytes = 114;
+ }
+
+}
+
+message ForeignMessage {
+ optional int32 c = 1;
+}
+
+enum ForeignEnum {
+ FOREIGN_FOO = 4;
+ FOREIGN_BAR = 5;
+ FOREIGN_BAZ = 6;
+}
+
+message TestExtendable {
+ extensions 1 to max;
+}
+
+message ExtendsWithMessage {
+ extend TestExtendable {
+ optional ExtendsWithMessage optional_extension = 19;
+ repeated ExtendsWithMessage repeated_extension = 49;
+ }
+ optional int32 foo = 1;
+}
+
+extend TestExtendable {
+ optional int32 extend_optional_int32 = 1;
+ optional int64 extend_optional_int64 = 2;
+ optional uint32 extend_optional_uint32 = 3;
+ optional uint64 extend_optional_uint64 = 4;
+ optional sint32 extend_optional_sint32 = 5;
+ optional sint64 extend_optional_sint64 = 6;
+ optional fixed32 extend_optional_fixed32 = 7;
+ optional fixed64 extend_optional_fixed64 = 8;
+ optional sfixed32 extend_optional_sfixed32 = 9;
+ optional sfixed64 extend_optional_sfixed64 = 10;
+ optional float extend_optional_float = 11;
+ optional double extend_optional_double = 12;
+ optional bool extend_optional_bool = 13;
+ optional string extend_optional_string = 14;
+ optional bytes extend_optional_bytes = 15;
+ optional ForeignEnum extend_optional_foreign_enum = 22;
+
+ repeated int32 extend_repeated_int32 = 31;
+ repeated int64 extend_repeated_int64 = 32;
+ repeated uint32 extend_repeated_uint32 = 33;
+ repeated uint64 extend_repeated_uint64 = 34;
+ repeated sint32 extend_repeated_sint32 = 35;
+ repeated sint64 extend_repeated_sint64 = 36;
+ repeated fixed32 extend_repeated_fixed32 = 37;
+ repeated fixed64 extend_repeated_fixed64 = 38;
+ repeated sfixed32 extend_repeated_sfixed32 = 39;
+ repeated sfixed64 extend_repeated_sfixed64 = 40;
+ repeated float extend_repeated_float = 41;
+ repeated double extend_repeated_double = 42;
+ repeated bool extend_repeated_bool = 43;
+ repeated string extend_repeated_string = 44;
+ repeated bytes extend_repeated_bytes = 45;
+ repeated ForeignEnum extend_repeated_foreign_enum = 52;
+
+ repeated int32 extend_packed_repeated_int32 = 61 [packed=true];
+ repeated int64 extend_packed_repeated_int64 = 62 [packed=true];
+ repeated uint32 extend_packed_repeated_uint32 = 63 [packed=true];
+ repeated uint64 extend_packed_repeated_uint64 = 64 [packed=true];
+ repeated sint32 extend_packed_repeated_sint32 = 65 [packed=true];
+ repeated sint64 extend_packed_repeated_sint64 = 66 [packed=true];
+ repeated fixed32 extend_packed_repeated_fixed32 = 67 [packed=true];
+ repeated fixed64 extend_packed_repeated_fixed64 = 68 [packed=true];
+ repeated sfixed32 extend_packed_repeated_sfixed32 = 69 [packed=true];
+ repeated sfixed64 extend_packed_repeated_sfixed64 = 70 [packed=true];
+ repeated float extend_packed_repeated_float = 71 [packed=true];
+ repeated double extend_packed_repeated_double = 72 [packed=true];
+ repeated bool extend_packed_repeated_bool = 73 [packed=true];
+ repeated ForeignEnum extend_packed_repeated_foreign_enum = 82
+ [packed=true];
+
+}
+
+message TestMapFields {
+ map<string, string> map_string_string = 1;
+ map<string, int32> map_string_int32 = 2;
+ map<string, int64> map_string_int64 = 3;
+ map<string, bool> map_string_bool = 4;
+ map<string, double> map_string_double = 5;
+ map<string, MapValueEnum> map_string_enum = 6;
+ map<string, MapValueMessage> map_string_msg = 7;
+
+ map<int32, string> map_int32_string = 8;
+ map<int64, string> map_int64_string = 9;
+ map<bool, string> map_bool_string = 10;
+
+ optional TestMapFields test_map_fields = 11;
+ map<string, TestMapFields> map_string_testmapfields = 12;
+}
+
+enum MapValueEnum {
+ MAP_VALUE_FOO = 0;
+ MAP_VALUE_BAR = 1;
+ MAP_VALUE_BAZ = 2;
+}
+
+message MapValueMessage {
+ optional int32 foo = 1;
+}
diff --git a/third_party/protobuf/js/testempty.proto b/third_party/protobuf/js/testempty.proto
new file mode 100644
index 0000000000..960bce4e5c
--- /dev/null
+++ b/third_party/protobuf/js/testempty.proto
@@ -0,0 +1,34 @@
+// 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.
+
+syntax = "proto2";
+
+package javatests.com.google.apps.jspb;
+
diff --git a/third_party/protobuf/m4/ac_system_extensions.m4 b/third_party/protobuf/m4/ac_system_extensions.m4
new file mode 100644
index 0000000000..1ca2eeb1d8
--- /dev/null
+++ b/third_party/protobuf/m4/ac_system_extensions.m4
@@ -0,0 +1,37 @@
+dnl Provide AC_USE_SYSTEM_EXTENSIONS for old autoconf machines.
+AC_DEFUN([ACX_USE_SYSTEM_EXTENSIONS],[
+ ifdef([AC_USE_SYSTEM_EXTENSIONS],[
+ AC_USE_SYSTEM_EXTENSIONS
+ ],[
+ AC_BEFORE([$0], [AC_COMPILE_IFELSE])
+ AC_BEFORE([$0], [AC_RUN_IFELSE])
+
+ AC_REQUIRE([AC_GNU_SOURCE])
+ AC_REQUIRE([AC_AIX])
+ AC_REQUIRE([AC_MINIX])
+
+ AH_VERBATIM([__EXTENSIONS__],
+[/* Enable extensions on Solaris. */
+#ifndef __EXTENSIONS__
+# undef __EXTENSIONS__
+#endif
+#ifndef _POSIX_PTHREAD_SEMANTICS
+# undef _POSIX_PTHREAD_SEMANTICS
+#endif
+#ifndef _TANDEM_SOURCE
+# undef _TANDEM_SOURCE
+#endif])
+ AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__],
+ [ac_cv_safe_to_define___extensions__],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([
+# define __EXTENSIONS__ 1
+ AC_INCLUDES_DEFAULT])],
+ [ac_cv_safe_to_define___extensions__=yes],
+ [ac_cv_safe_to_define___extensions__=no])])
+ test $ac_cv_safe_to_define___extensions__ = yes &&
+ AC_DEFINE([__EXTENSIONS__])
+ AC_DEFINE([_POSIX_PTHREAD_SEMANTICS])
+ AC_DEFINE([_TANDEM_SOURCE])
+ ])
+])
diff --git a/third_party/protobuf/m4/acx_check_suncc.m4 b/third_party/protobuf/m4/acx_check_suncc.m4
new file mode 100644
index 0000000000..8bc0a890dc
--- /dev/null
+++ b/third_party/protobuf/m4/acx_check_suncc.m4
@@ -0,0 +1,70 @@
+dnl Check for the presence of the Sun Studio compiler.
+dnl If Sun Studio compiler is found, set appropriate flags.
+dnl Additionally, Sun Studio doesn't default to 64-bit by itself,
+dnl nor does it automatically look in standard Solaris places for
+dnl 64-bit libs, so we must add those options and paths to the search
+dnl paths.
+
+dnl TODO(kenton): This is pretty hacky. It sets CXXFLAGS, which the autoconf
+dnl docs say should never be overridden except by the user. It also isn't
+dnl cross-compile safe. We should fix these problems, but since I don't have
+dnl Sun CC at my disposal for testing, someone else will have to do it.
+
+AC_DEFUN([ACX_CHECK_SUNCC],[
+
+ AC_LANG_PUSH([C++])
+ AC_CHECK_DECL([__SUNPRO_CC], [SUNCC="yes"], [SUNCC="no"])
+ AC_LANG_POP()
+
+
+ AC_ARG_ENABLE([64bit-solaris],
+ [AS_HELP_STRING([--disable-64bit-solaris],
+ [Build 64 bit binary on Solaris @<:@default=on@:>@])],
+ [ac_enable_64bit="$enableval"],
+ [ac_enable_64bit="yes"])
+
+ AS_IF([test "$SUNCC" = "yes" -a "x${ac_cv_env_CXXFLAGS_set}" = "x"],[
+ dnl Sun Studio has a crashing bug with -xO4 in some cases. Keep this
+ dnl at -xO3 until a proper test to detect those crashes can be done.
+ CXXFLAGS="-g0 -xO3 -xlibmil -xdepend -xbuiltin -mt -compat=5 -library=stlport4 -library=Crun -template=no%extdef ${CXXFLAGS}"
+ ])
+
+ case $host_os in
+ *solaris*)
+ AC_CHECK_PROGS(ISAINFO, [isainfo], [no])
+ AS_IF([test "x$ISAINFO" != "xno"],
+ [isainfo_b=`${ISAINFO} -b`],
+ [isainfo_b="x"])
+
+ AS_IF([test "$isainfo_b" != "x"],[
+
+ isainfo_k=`${ISAINFO} -k`
+
+ AS_IF([test "x$ac_enable_64bit" = "xyes"],[
+
+ AS_IF([test "x$libdir" = "x\${exec_prefix}/lib"],[
+ dnl The user hasn't overridden the default libdir, so we'll
+ dnl the dir suffix to match solaris 32/64-bit policy
+ libdir="${libdir}/${isainfo_k}"
+ ])
+
+ dnl This should just be set in CPPFLAGS and in LDFLAGS, but libtool
+ dnl does the wrong thing if you don't put it into CXXFLAGS. sigh.
+ dnl (It also needs it in CFLAGS, or it does a different wrong thing!)
+ CXXFLAGS="${CXXFLAGS} -m64"
+ ac_cv_env_CXXFLAGS_set=set
+ ac_cv_env_CXXFLAGS_value='-m64'
+
+ CFLAGS="${CFLAGS} -m64"
+ ac_cv_env_CFLAGS_set=set
+ ac_cv_env_CFLAGS_value='-m64'
+
+ AS_IF([test "$target_cpu" = "sparc" -a "x$SUNCC" = "xyes" ],[
+ CXXFLAGS="-xmemalign=8s ${CXXFLAGS}"
+ ])
+ ])
+ ])
+ ;;
+ esac
+
+])
diff --git a/third_party/protobuf/m4/acx_pthread.m4 b/third_party/protobuf/m4/acx_pthread.m4
new file mode 100644
index 0000000000..89d42c7449
--- /dev/null
+++ b/third_party/protobuf/m4/acx_pthread.m4
@@ -0,0 +1,397 @@
+# This was retrieved from
+# http://svn.0pointer.de/viewvc/trunk/common/acx_pthread.m4?revision=1277&root=avahi
+# See also (perhaps for new versions?)
+# http://svn.0pointer.de/viewvc/trunk/common/acx_pthread.m4?root=avahi
+#
+# We've rewritten the inconsistency check code (from avahi), to work
+# more broadly. In particular, it no longer assumes ld accepts -zdefs.
+# This caused a restructing of the code, but the functionality has only
+# changed a little.
+
+dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
+dnl
+dnl @summary figure out how to build C programs using POSIX threads
+dnl
+dnl This macro figures out how to build C programs using POSIX threads.
+dnl It sets the PTHREAD_LIBS output variable to the threads library and
+dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
+dnl C compiler flags that are needed. (The user can also force certain
+dnl compiler flags/libs to be tested by setting these environment
+dnl variables.)
+dnl
+dnl Also sets PTHREAD_CC to any special C compiler that is needed for
+dnl multi-threaded programs (defaults to the value of CC otherwise).
+dnl (This is necessary on AIX to use the special cc_r compiler alias.)
+dnl
+dnl NOTE: You are assumed to not only compile your program with these
+dnl flags, but also link it with them as well. e.g. you should link
+dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
+dnl $LIBS
+dnl
+dnl If you are only building threads programs, you may wish to use
+dnl these variables in your default LIBS, CFLAGS, and CC:
+dnl
+dnl LIBS="$PTHREAD_LIBS $LIBS"
+dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+dnl CC="$PTHREAD_CC"
+dnl
+dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
+dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
+dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
+dnl
+dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
+dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
+dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
+dnl default action will define HAVE_PTHREAD.
+dnl
+dnl Please let the authors know if this macro fails on any platform, or
+dnl if you have any other suggestions or comments. This macro was based
+dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
+dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
+dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
+dnl We are also grateful for the helpful feedback of numerous users.
+dnl
+dnl @category InstalledPackages
+dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
+dnl @version 2006-05-29
+dnl @license GPLWithACException
+dnl
+dnl Checks for GCC shared/pthread inconsistency based on work by
+dnl Marcin Owsiany <marcin@owsiany.pl>
+
+
+AC_DEFUN([ACX_PTHREAD], [
+AC_REQUIRE([AC_CANONICAL_HOST])
+AC_LANG_SAVE
+AC_LANG_C
+acx_pthread_ok=no
+
+# We used to check for pthread.h first, but this fails if pthread.h
+# requires special compiler flags (e.g. on True64 or Sequent).
+# It gets checked for in the link test anyway.
+
+# First of all, check if the user has set any of the PTHREAD_LIBS,
+# etcetera environment variables, and if threads linking works using
+# them:
+if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+ save_LIBS="$LIBS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
+ AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
+ AC_MSG_RESULT($acx_pthread_ok)
+ if test x"$acx_pthread_ok" = xno; then
+ PTHREAD_LIBS=""
+ PTHREAD_CFLAGS=""
+ fi
+ LIBS="$save_LIBS"
+ CFLAGS="$save_CFLAGS"
+fi
+
+# We must check for the threads library under a number of different
+# names; the ordering is very important because some systems
+# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
+# libraries is broken (non-POSIX).
+
+# Create a list of thread flags to try. Items starting with a "-" are
+# C compiler flags, and other items are library names, except for "none"
+# which indicates that we try without any flags at all, and "pthread-config"
+# which is a program returning the flags for the Pth emulation library.
+
+acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
+
+# The ordering *is* (sometimes) important. Some notes on the
+# individual items follow:
+
+# pthreads: AIX (must check this before -lpthread)
+# none: in case threads are in libc; should be tried before -Kthread and
+# other compiler flags to prevent continual compiler warnings
+# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
+# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
+# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
+# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
+# -pthreads: Solaris/gcc
+# -mthreads: Mingw32/gcc, Lynx/gcc
+# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
+# doesn't hurt to check since this sometimes defines pthreads too;
+# also defines -D_REENTRANT)
+# ... -mt is also the pthreads flag for HP/aCC
+# pthread: Linux, etcetera
+# --thread-safe: KAI C++
+# pthread-config: use pthread-config program (for GNU Pth library)
+
+case "${host_cpu}-${host_os}" in
+ *solaris*)
+
+ # On Solaris (at least, for some versions), libc contains stubbed
+ # (non-functional) versions of the pthreads routines, so link-based
+ # tests will erroneously succeed. (We need to link with -pthreads/-mt/
+ # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
+ # a function called by this macro, so we could check for that, but
+ # who knows whether they'll stub that too in a future libc.) So,
+ # we'll just look for -pthreads and -lpthread first:
+
+ acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
+ ;;
+esac
+
+if test x"$acx_pthread_ok" = xno; then
+for flag in $acx_pthread_flags; do
+
+ case $flag in
+ none)
+ AC_MSG_CHECKING([whether pthreads work without any flags])
+ ;;
+
+ -*)
+ AC_MSG_CHECKING([whether pthreads work with $flag])
+ PTHREAD_CFLAGS="$flag"
+ ;;
+
+ pthread-config)
+ AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
+ if test x"$acx_pthread_config" = xno; then continue; fi
+ PTHREAD_CFLAGS="`pthread-config --cflags`"
+ PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
+ ;;
+
+ *)
+ AC_MSG_CHECKING([for the pthreads library -l$flag])
+ PTHREAD_LIBS="-l$flag"
+ ;;
+ esac
+
+ save_LIBS="$LIBS"
+ save_CFLAGS="$CFLAGS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+
+ # Check for various functions. We must include pthread.h,
+ # since some functions may be macros. (On the Sequent, we
+ # need a special flag -Kthread to make this header compile.)
+ # We check for pthread_join because it is in -lpthread on IRIX
+ # while pthread_create is in libc. We check for pthread_attr_init
+ # due to DEC craziness with -lpthreads. We check for
+ # pthread_cleanup_push because it is one of the few pthread
+ # functions on Solaris that doesn't have a non-functional libc stub.
+ # We try pthread_create on general principles.
+ AC_TRY_LINK([#include <pthread.h>],
+ [pthread_t th; pthread_join(th, 0);
+ pthread_attr_init(0); pthread_cleanup_push(0, 0);
+ pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
+ [acx_pthread_ok=yes])
+
+ LIBS="$save_LIBS"
+ CFLAGS="$save_CFLAGS"
+
+ AC_MSG_RESULT($acx_pthread_ok)
+ if test "x$acx_pthread_ok" = xyes; then
+ break;
+ fi
+
+ PTHREAD_LIBS=""
+ PTHREAD_CFLAGS=""
+done
+fi
+
+# Various other checks:
+if test "x$acx_pthread_ok" = xyes; then
+ save_LIBS="$LIBS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+
+ # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
+ AC_MSG_CHECKING([for joinable pthread attribute])
+ attr_name=unknown
+ for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
+ AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
+ [attr_name=$attr; break])
+ done
+ AC_MSG_RESULT($attr_name)
+ if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
+ AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
+ [Define to necessary symbol if this constant
+ uses a non-standard name on your system.])
+ fi
+
+ AC_MSG_CHECKING([if more special flags are required for pthreads])
+ flag=no
+ case "${host_cpu}-${host_os}" in
+ *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
+ *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
+ esac
+ AC_MSG_RESULT(${flag})
+ if test "x$flag" != xno; then
+ PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
+ fi
+
+ LIBS="$save_LIBS"
+ CFLAGS="$save_CFLAGS"
+ # More AIX lossage: must compile with xlc_r or cc_r
+ if test x"$GCC" != xyes; then
+ AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
+ else
+ PTHREAD_CC=$CC
+ fi
+
+ # The next part tries to detect GCC inconsistency with -shared on some
+ # architectures and systems. The problem is that in certain
+ # configurations, when -shared is specified, GCC "forgets" to
+ # internally use various flags which are still necessary.
+
+ #
+ # Prepare the flags
+ #
+ save_CFLAGS="$CFLAGS"
+ save_LIBS="$LIBS"
+ save_CC="$CC"
+
+ # Try with the flags determined by the earlier checks.
+ #
+ # -Wl,-z,defs forces link-time symbol resolution, so that the
+ # linking checks with -shared actually have any value
+ #
+ # FIXME: -fPIC is required for -shared on many architectures,
+ # so we specify it here, but the right way would probably be to
+ # properly detect whether it is actually required.
+ CFLAGS="-shared -fPIC -Wl,-z,defs $CFLAGS $PTHREAD_CFLAGS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ CC="$PTHREAD_CC"
+
+ # In order not to create several levels of indentation, we test
+ # the value of "$done" until we find the cure or run out of ideas.
+ done="no"
+
+ # First, make sure the CFLAGS we added are actually accepted by our
+ # compiler. If not (and OS X's ld, for instance, does not accept -z),
+ # then we can't do this test.
+ if test x"$done" = xno; then
+ AC_MSG_CHECKING([whether to check for GCC pthread/shared inconsistencies])
+ AC_TRY_LINK(,, , [done=yes])
+
+ if test "x$done" = xyes ; then
+ AC_MSG_RESULT([no])
+ else
+ AC_MSG_RESULT([yes])
+ fi
+ fi
+
+ if test x"$done" = xno; then
+ AC_MSG_CHECKING([whether -pthread is sufficient with -shared])
+ AC_TRY_LINK([#include <pthread.h>],
+ [pthread_t th; pthread_join(th, 0);
+ pthread_attr_init(0); pthread_cleanup_push(0, 0);
+ pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
+ [done=yes])
+
+ if test "x$done" = xyes; then
+ AC_MSG_RESULT([yes])
+ else
+ AC_MSG_RESULT([no])
+ fi
+ fi
+
+ #
+ # Linux gcc on some architectures such as mips/mipsel forgets
+ # about -lpthread
+ #
+ if test x"$done" = xno; then
+ AC_MSG_CHECKING([whether -lpthread fixes that])
+ LIBS="-lpthread $PTHREAD_LIBS $save_LIBS"
+ AC_TRY_LINK([#include <pthread.h>],
+ [pthread_t th; pthread_join(th, 0);
+ pthread_attr_init(0); pthread_cleanup_push(0, 0);
+ pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
+ [done=yes])
+
+ if test "x$done" = xyes; then
+ AC_MSG_RESULT([yes])
+ PTHREAD_LIBS="-lpthread $PTHREAD_LIBS"
+ else
+ AC_MSG_RESULT([no])
+ fi
+ fi
+ #
+ # FreeBSD 4.10 gcc forgets to use -lc_r instead of -lc
+ #
+ if test x"$done" = xno; then
+ AC_MSG_CHECKING([whether -lc_r fixes that])
+ LIBS="-lc_r $PTHREAD_LIBS $save_LIBS"
+ AC_TRY_LINK([#include <pthread.h>],
+ [pthread_t th; pthread_join(th, 0);
+ pthread_attr_init(0); pthread_cleanup_push(0, 0);
+ pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
+ [done=yes])
+
+ if test "x$done" = xyes; then
+ AC_MSG_RESULT([yes])
+ PTHREAD_LIBS="-lc_r $PTHREAD_LIBS"
+ else
+ AC_MSG_RESULT([no])
+ fi
+ fi
+ if test x"$done" = xno; then
+ # OK, we have run out of ideas
+ AC_MSG_WARN([Impossible to determine how to use pthreads with shared libraries])
+
+ # so it's not safe to assume that we may use pthreads
+ acx_pthread_ok=no
+ fi
+
+ AC_MSG_CHECKING([whether what we have so far is sufficient with -nostdlib])
+ CFLAGS="-nostdlib $CFLAGS"
+ # we need c with nostdlib
+ LIBS="$LIBS -lc"
+ AC_TRY_LINK([#include <pthread.h>],
+ [pthread_t th; pthread_join(th, 0);
+ pthread_attr_init(0); pthread_cleanup_push(0, 0);
+ pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
+ [done=yes],[done=no])
+
+ if test "x$done" = xyes; then
+ AC_MSG_RESULT([yes])
+ else
+ AC_MSG_RESULT([no])
+ fi
+
+ if test x"$done" = xno; then
+ AC_MSG_CHECKING([whether -lpthread saves the day])
+ LIBS="-lpthread $LIBS"
+ AC_TRY_LINK([#include <pthread.h>],
+ [pthread_t th; pthread_join(th, 0);
+ pthread_attr_init(0); pthread_cleanup_push(0, 0);
+ pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
+ [done=yes],[done=no])
+
+ if test "x$done" = xyes; then
+ AC_MSG_RESULT([yes])
+ PTHREAD_LIBS="$PTHREAD_LIBS -lpthread"
+ else
+ AC_MSG_RESULT([no])
+ AC_MSG_WARN([Impossible to determine how to use pthreads with shared libraries and -nostdlib])
+ fi
+ fi
+
+ CFLAGS="$save_CFLAGS"
+ LIBS="$save_LIBS"
+ CC="$save_CC"
+else
+ PTHREAD_CC="$CC"
+fi
+
+AC_SUBST(PTHREAD_LIBS)
+AC_SUBST(PTHREAD_CFLAGS)
+AC_SUBST(PTHREAD_CC)
+
+# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
+if test x"$acx_pthread_ok" = xyes; then
+ ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
+ :
+else
+ acx_pthread_ok=no
+ $2
+fi
+AC_LANG_RESTORE
+])dnl ACX_PTHREAD
diff --git a/third_party/protobuf/m4/ax_cxx_compile_stdcxx.m4 b/third_party/protobuf/m4/ax_cxx_compile_stdcxx.m4
new file mode 100644
index 0000000000..b61fcb6314
--- /dev/null
+++ b/third_party/protobuf/m4/ax_cxx_compile_stdcxx.m4
@@ -0,0 +1,982 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional])
+#
+# DESCRIPTION
+#
+# Check for baseline language coverage in the compiler for the specified
+# version of the C++ standard. If necessary, add switches to CXX and
+# CXXCPP to enable support. VERSION may be '11' (for the C++11 standard)
+# or '14' (for the C++14 standard).
+#
+# The second argument, if specified, indicates whether you insist on an
+# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
+# -std=c++11). If neither is specified, you get whatever works, with
+# preference for an extended mode.
+#
+# The third argument, if specified 'mandatory' or if left unspecified,
+# indicates that baseline support for the specified C++ standard is
+# required and that the macro should error out if no mode with that
+# support is found. If specified 'optional', then configuration proceeds
+# regardless, after defining HAVE_CXX${VERSION} if and only if a
+# supporting mode is found.
+#
+# LICENSE
+#
+# Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
+# Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
+# Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
+# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com>
+# Copyright (c) 2015 Paul Norman <penorman@mac.com>
+# Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu>
+# Copyright (c) 2016 Krzesimir Nowak <qdlacz@gmail.com>
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 6
+
+dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
+dnl (serial version number 13).
+
+AX_REQUIRE_DEFINED([AC_MSG_WARN])
+AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
+ m4_if([$1], [11], [ax_cxx_compile_alternatives="11 0x"],
+ [$1], [14], [ax_cxx_compile_alternatives="14 1y"],
+ [$1], [17], [ax_cxx_compile_alternatives="17 1z"],
+ [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl
+ m4_if([$2], [], [],
+ [$2], [ext], [],
+ [$2], [noext], [],
+ [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl
+ m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true],
+ [$3], [mandatory], [ax_cxx_compile_cxx$1_required=true],
+ [$3], [optional], [ax_cxx_compile_cxx$1_required=false],
+ [m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])])
+ AC_LANG_PUSH([C++])dnl
+ ac_success=no
+ AC_CACHE_CHECK(whether $CXX supports C++$1 features by default,
+ ax_cv_cxx_compile_cxx$1,
+ [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
+ [ax_cv_cxx_compile_cxx$1=yes],
+ [ax_cv_cxx_compile_cxx$1=no])])
+ if test x$ax_cv_cxx_compile_cxx$1 = xyes; then
+ ac_success=yes
+ fi
+
+ m4_if([$2], [noext], [], [dnl
+ if test x$ac_success = xno; then
+ for alternative in ${ax_cxx_compile_alternatives}; do
+ switch="-std=gnu++${alternative}"
+ cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
+ AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
+ $cachevar,
+ [ac_save_CXX="$CXX"
+ CXX="$CXX $switch"
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
+ [eval $cachevar=yes],
+ [eval $cachevar=no])
+ CXX="$ac_save_CXX"])
+ if eval test x\$$cachevar = xyes; then
+ CXX="$CXX $switch"
+ if test -n "$CXXCPP" ; then
+ CXXCPP="$CXXCPP $switch"
+ fi
+ ac_success=yes
+ break
+ fi
+ done
+ fi])
+
+ m4_if([$2], [ext], [], [dnl
+ if test x$ac_success = xno; then
+ dnl HP's aCC needs +std=c++11 according to:
+ dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf
+ dnl Cray's crayCC needs "-h std=c++11"
+ for alternative in ${ax_cxx_compile_alternatives}; do
+ for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do
+ cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
+ AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
+ $cachevar,
+ [ac_save_CXX="$CXX"
+ CXX="$CXX $switch"
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
+ [eval $cachevar=yes],
+ [eval $cachevar=no])
+ CXX="$ac_save_CXX"])
+ if eval test x\$$cachevar = xyes; then
+ CXX="$CXX $switch"
+ if test -n "$CXXCPP" ; then
+ CXXCPP="$CXXCPP $switch"
+ fi
+ ac_success=yes
+ break
+ fi
+ done
+ if test x$ac_success = xyes; then
+ break
+ fi
+ done
+ fi])
+ AC_LANG_POP([C++])
+ if test x$ax_cxx_compile_cxx$1_required = xtrue; then
+ if test x$ac_success = xno; then
+ AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.])
+ fi
+ fi
+ if test x$ac_success = xno; then
+ HAVE_CXX$1=0
+ AC_MSG_NOTICE([No compiler with C++$1 support was found])
+ else
+ HAVE_CXX$1=1
+ AC_DEFINE(HAVE_CXX$1,1,
+ [define if the compiler supports basic C++$1 syntax])
+ fi
+ AC_SUBST(HAVE_CXX$1)
+ m4_if([$1], [17], [AC_MSG_WARN([C++17 is not yet standardized, so the checks may change in incompatible ways anytime])])
+])
+
+
+dnl Test body for checking C++11 support
+
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11],
+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
+)
+
+
+dnl Test body for checking C++14 support
+
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14],
+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
+)
+
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17],
+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_17
+)
+
+dnl Tests for new features in C++11
+
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
+
+// If the compiler admits that it is not ready for C++11, why torture it?
+// Hopefully, this will speed up the test.
+
+#ifndef __cplusplus
+
+#error "This is not a C++ compiler"
+
+#elif __cplusplus < 201103L
+
+#error "This is not a C++11 compiler"
+
+#else
+
+namespace cxx11
+{
+
+ namespace test_static_assert
+ {
+
+ template <typename T>
+ struct check
+ {
+ static_assert(sizeof(int) <= sizeof(T), "not big enough");
+ };
+
+ }
+
+ namespace test_final_override
+ {
+
+ struct Base
+ {
+ virtual void f() {}
+ };
+
+ struct Derived : public Base
+ {
+ virtual void f() override {}
+ };
+
+ }
+
+ namespace test_double_right_angle_brackets
+ {
+
+ template < typename T >
+ struct check {};
+
+ typedef check<void> single_type;
+ typedef check<check<void>> double_type;
+ typedef check<check<check<void>>> triple_type;
+ typedef check<check<check<check<void>>>> quadruple_type;
+
+ }
+
+ namespace test_decltype
+ {
+
+ int
+ f()
+ {
+ int a = 1;
+ decltype(a) b = 2;
+ return a + b;
+ }
+
+ }
+
+ namespace test_type_deduction
+ {
+
+ template < typename T1, typename T2 >
+ struct is_same
+ {
+ static const bool value = false;
+ };
+
+ template < typename T >
+ struct is_same<T, T>
+ {
+ static const bool value = true;
+ };
+
+ template < typename T1, typename T2 >
+ auto
+ add(T1 a1, T2 a2) -> decltype(a1 + a2)
+ {
+ return a1 + a2;
+ }
+
+ int
+ test(const int c, volatile int v)
+ {
+ static_assert(is_same<int, decltype(0)>::value == true, "");
+ static_assert(is_same<int, decltype(c)>::value == false, "");
+ static_assert(is_same<int, decltype(v)>::value == false, "");
+ auto ac = c;
+ auto av = v;
+ auto sumi = ac + av + 'x';
+ auto sumf = ac + av + 1.0;
+ static_assert(is_same<int, decltype(ac)>::value == true, "");
+ static_assert(is_same<int, decltype(av)>::value == true, "");
+ static_assert(is_same<int, decltype(sumi)>::value == true, "");
+ static_assert(is_same<int, decltype(sumf)>::value == false, "");
+ static_assert(is_same<int, decltype(add(c, v))>::value == true, "");
+ return (sumf > 0.0) ? sumi : add(c, v);
+ }
+
+ }
+
+ namespace test_noexcept
+ {
+
+ int f() { return 0; }
+ int g() noexcept { return 0; }
+
+ static_assert(noexcept(f()) == false, "");
+ static_assert(noexcept(g()) == true, "");
+
+ }
+
+ namespace test_constexpr
+ {
+
+ template < typename CharT >
+ unsigned long constexpr
+ strlen_c_r(const CharT *const s, const unsigned long acc) noexcept
+ {
+ return *s ? strlen_c_r(s + 1, acc + 1) : acc;
+ }
+
+ template < typename CharT >
+ unsigned long constexpr
+ strlen_c(const CharT *const s) noexcept
+ {
+ return strlen_c_r(s, 0UL);
+ }
+
+ static_assert(strlen_c("") == 0UL, "");
+ static_assert(strlen_c("1") == 1UL, "");
+ static_assert(strlen_c("example") == 7UL, "");
+ static_assert(strlen_c("another\0example") == 7UL, "");
+
+ }
+
+ namespace test_rvalue_references
+ {
+
+ template < int N >
+ struct answer
+ {
+ static constexpr int value = N;
+ };
+
+ answer<1> f(int&) { return answer<1>(); }
+ answer<2> f(const int&) { return answer<2>(); }
+ answer<3> f(int&&) { return answer<3>(); }
+
+ void
+ test()
+ {
+ int i = 0;
+ const int c = 0;
+ static_assert(decltype(f(i))::value == 1, "");
+ static_assert(decltype(f(c))::value == 2, "");
+ static_assert(decltype(f(0))::value == 3, "");
+ }
+
+ }
+
+ namespace test_uniform_initialization
+ {
+
+ struct test
+ {
+ static const int zero {};
+ static const int one {1};
+ };
+
+ static_assert(test::zero == 0, "");
+ static_assert(test::one == 1, "");
+
+ }
+
+ namespace test_lambdas
+ {
+
+ void
+ test1()
+ {
+ auto lambda1 = [](){};
+ auto lambda2 = lambda1;
+ lambda1();
+ lambda2();
+ }
+
+ int
+ test2()
+ {
+ auto a = [](int i, int j){ return i + j; }(1, 2);
+ auto b = []() -> int { return '0'; }();
+ auto c = [=](){ return a + b; }();
+ auto d = [&](){ return c; }();
+ auto e = [a, &b](int x) mutable {
+ const auto identity = [](int y){ return y; };
+ for (auto i = 0; i < a; ++i)
+ a += b--;
+ return x + identity(a + b);
+ }(0);
+ return a + b + c + d + e;
+ }
+
+ int
+ test3()
+ {
+ const auto nullary = [](){ return 0; };
+ const auto unary = [](int x){ return x; };
+ using nullary_t = decltype(nullary);
+ using unary_t = decltype(unary);
+ const auto higher1st = [](nullary_t f){ return f(); };
+ const auto higher2nd = [unary](nullary_t f1){
+ return [unary, f1](unary_t f2){ return f2(unary(f1())); };
+ };
+ return higher1st(nullary) + higher2nd(nullary)(unary);
+ }
+
+ }
+
+ namespace test_variadic_templates
+ {
+
+ template <int...>
+ struct sum;
+
+ template <int N0, int... N1toN>
+ struct sum<N0, N1toN...>
+ {
+ static constexpr auto value = N0 + sum<N1toN...>::value;
+ };
+
+ template <>
+ struct sum<>
+ {
+ static constexpr auto value = 0;
+ };
+
+ static_assert(sum<>::value == 0, "");
+ static_assert(sum<1>::value == 1, "");
+ static_assert(sum<23>::value == 23, "");
+ static_assert(sum<1, 2>::value == 3, "");
+ static_assert(sum<5, 5, 11>::value == 21, "");
+ static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, "");
+
+ }
+
+ // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae
+ // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function
+ // because of this.
+ namespace test_template_alias_sfinae
+ {
+
+ struct foo {};
+
+ template<typename T>
+ using member = typename T::member_type;
+
+ template<typename T>
+ void func(...) {}
+
+ template<typename T>
+ void func(member<T>*) {}
+
+ void test();
+
+ void test() { func<foo>(0); }
+
+ }
+
+} // namespace cxx11
+
+#endif // __cplusplus >= 201103L
+
+]])
+
+
+dnl Tests for new features in C++14
+
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[
+
+// If the compiler admits that it is not ready for C++14, why torture it?
+// Hopefully, this will speed up the test.
+
+#ifndef __cplusplus
+
+#error "This is not a C++ compiler"
+
+#elif __cplusplus < 201402L
+
+#error "This is not a C++14 compiler"
+
+#else
+
+namespace cxx14
+{
+
+ namespace test_polymorphic_lambdas
+ {
+
+ int
+ test()
+ {
+ const auto lambda = [](auto&&... args){
+ const auto istiny = [](auto x){
+ return (sizeof(x) == 1UL) ? 1 : 0;
+ };
+ const int aretiny[] = { istiny(args)... };
+ return aretiny[0];
+ };
+ return lambda(1, 1L, 1.0f, '1');
+ }
+
+ }
+
+ namespace test_binary_literals
+ {
+
+ constexpr auto ivii = 0b0000000000101010;
+ static_assert(ivii == 42, "wrong value");
+
+ }
+
+ namespace test_generalized_constexpr
+ {
+
+ template < typename CharT >
+ constexpr unsigned long
+ strlen_c(const CharT *const s) noexcept
+ {
+ auto length = 0UL;
+ for (auto p = s; *p; ++p)
+ ++length;
+ return length;
+ }
+
+ static_assert(strlen_c("") == 0UL, "");
+ static_assert(strlen_c("x") == 1UL, "");
+ static_assert(strlen_c("test") == 4UL, "");
+ static_assert(strlen_c("another\0test") == 7UL, "");
+
+ }
+
+ namespace test_lambda_init_capture
+ {
+
+ int
+ test()
+ {
+ auto x = 0;
+ const auto lambda1 = [a = x](int b){ return a + b; };
+ const auto lambda2 = [a = lambda1(x)](){ return a; };
+ return lambda2();
+ }
+
+ }
+
+ namespace test_digit_separators
+ {
+
+ constexpr auto ten_million = 100'000'000;
+ static_assert(ten_million == 100000000, "");
+
+ }
+
+ namespace test_return_type_deduction
+ {
+
+ auto f(int& x) { return x; }
+ decltype(auto) g(int& x) { return x; }
+
+ template < typename T1, typename T2 >
+ struct is_same
+ {
+ static constexpr auto value = false;
+ };
+
+ template < typename T >
+ struct is_same<T, T>
+ {
+ static constexpr auto value = true;
+ };
+
+ int
+ test()
+ {
+ auto x = 0;
+ static_assert(is_same<int, decltype(f(x))>::value, "");
+ static_assert(is_same<int&, decltype(g(x))>::value, "");
+ return x;
+ }
+
+ }
+
+} // namespace cxx14
+
+#endif // __cplusplus >= 201402L
+
+]])
+
+
+dnl Tests for new features in C++17
+
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[
+
+// If the compiler admits that it is not ready for C++17, why torture it?
+// Hopefully, this will speed up the test.
+
+#ifndef __cplusplus
+
+#error "This is not a C++ compiler"
+
+#elif __cplusplus <= 201402L
+
+#error "This is not a C++17 compiler"
+
+#else
+
+#if defined(__clang__)
+ #define REALLY_CLANG
+#else
+ #if defined(__GNUC__)
+ #define REALLY_GCC
+ #endif
+#endif
+
+#include <initializer_list>
+#include <utility>
+#include <type_traits>
+
+namespace cxx17
+{
+
+#if !defined(REALLY_CLANG)
+ namespace test_constexpr_lambdas
+ {
+
+ // TODO: test it with clang++ from git
+
+ constexpr int foo = [](){return 42;}();
+
+ }
+#endif // !defined(REALLY_CLANG)
+
+ namespace test::nested_namespace::definitions
+ {
+
+ }
+
+ namespace test_fold_expression
+ {
+
+ template<typename... Args>
+ int multiply(Args... args)
+ {
+ return (args * ... * 1);
+ }
+
+ template<typename... Args>
+ bool all(Args... args)
+ {
+ return (args && ...);
+ }
+
+ }
+
+ namespace test_extended_static_assert
+ {
+
+ static_assert (true);
+
+ }
+
+ namespace test_auto_brace_init_list
+ {
+
+ auto foo = {5};
+ auto bar {5};
+
+ static_assert(std::is_same<std::initializer_list<int>, decltype(foo)>::value);
+ static_assert(std::is_same<int, decltype(bar)>::value);
+ }
+
+ namespace test_typename_in_template_template_parameter
+ {
+
+ template<template<typename> typename X> struct D;
+
+ }
+
+ namespace test_fallthrough_nodiscard_maybe_unused_attributes
+ {
+
+ int f1()
+ {
+ return 42;
+ }
+
+ [[nodiscard]] int f2()
+ {
+ [[maybe_unused]] auto unused = f1();
+
+ switch (f1())
+ {
+ case 17:
+ f1();
+ [[fallthrough]];
+ case 42:
+ f1();
+ }
+ return f1();
+ }
+
+ }
+
+ namespace test_extended_aggregate_initialization
+ {
+
+ struct base1
+ {
+ int b1, b2 = 42;
+ };
+
+ struct base2
+ {
+ base2() {
+ b3 = 42;
+ }
+ int b3;
+ };
+
+ struct derived : base1, base2
+ {
+ int d;
+ };
+
+ derived d1 {{1, 2}, {}, 4}; // full initialization
+ derived d2 {{}, {}, 4}; // value-initialized bases
+
+ }
+
+ namespace test_general_range_based_for_loop
+ {
+
+ struct iter
+ {
+ int i;
+
+ int& operator* ()
+ {
+ return i;
+ }
+
+ const int& operator* () const
+ {
+ return i;
+ }
+
+ iter& operator++()
+ {
+ ++i;
+ return *this;
+ }
+ };
+
+ struct sentinel
+ {
+ int i;
+ };
+
+ bool operator== (const iter& i, const sentinel& s)
+ {
+ return i.i == s.i;
+ }
+
+ bool operator!= (const iter& i, const sentinel& s)
+ {
+ return !(i == s);
+ }
+
+ struct range
+ {
+ iter begin() const
+ {
+ return {0};
+ }
+
+ sentinel end() const
+ {
+ return {5};
+ }
+ };
+
+ void f()
+ {
+ range r {};
+
+ for (auto i : r)
+ {
+ [[maybe_unused]] auto v = i;
+ }
+ }
+
+ }
+
+ namespace test_lambda_capture_asterisk_this_by_value
+ {
+
+ struct t
+ {
+ int i;
+ int foo()
+ {
+ return [*this]()
+ {
+ return i;
+ }();
+ }
+ };
+
+ }
+
+ namespace test_enum_class_construction
+ {
+
+ enum class byte : unsigned char
+ {};
+
+ byte foo {42};
+
+ }
+
+ namespace test_constexpr_if
+ {
+
+ template <bool cond>
+ int f ()
+ {
+ if constexpr(cond)
+ {
+ return 13;
+ }
+ else
+ {
+ return 42;
+ }
+ }
+
+ }
+
+ namespace test_selection_statement_with_initializer
+ {
+
+ int f()
+ {
+ return 13;
+ }
+
+ int f2()
+ {
+ if (auto i = f(); i > 0)
+ {
+ return 3;
+ }
+
+ switch (auto i = f(); i + 4)
+ {
+ case 17:
+ return 2;
+
+ default:
+ return 1;
+ }
+ }
+
+ }
+
+#if !defined(REALLY_CLANG)
+ namespace test_template_argument_deduction_for_class_templates
+ {
+
+ // TODO: test it with clang++ from git
+
+ template <typename T1, typename T2>
+ struct pair
+ {
+ pair (T1 p1, T2 p2)
+ : m1 {p1},
+ m2 {p2}
+ {}
+
+ T1 m1;
+ T2 m2;
+ };
+
+ void f()
+ {
+ [[maybe_unused]] auto p = pair{13, 42u};
+ }
+
+ }
+#endif // !defined(REALLY_CLANG)
+
+ namespace test_non_type_auto_template_parameters
+ {
+
+ template <auto n>
+ struct B
+ {};
+
+ B<5> b1;
+ B<'a'> b2;
+
+ }
+
+#if !defined(REALLY_CLANG)
+ namespace test_structured_bindings
+ {
+
+ // TODO: test it with clang++ from git
+
+ int arr[2] = { 1, 2 };
+ std::pair<int, int> pr = { 1, 2 };
+
+ auto f1() -> int(&)[2]
+ {
+ return arr;
+ }
+
+ auto f2() -> std::pair<int, int>&
+ {
+ return pr;
+ }
+
+ struct S
+ {
+ int x1 : 2;
+ volatile double y1;
+ };
+
+ S f3()
+ {
+ return {};
+ }
+
+ auto [ x1, y1 ] = f1();
+ auto& [ xr1, yr1 ] = f1();
+ auto [ x2, y2 ] = f2();
+ auto& [ xr2, yr2 ] = f2();
+ const auto [ x3, y3 ] = f3();
+
+ }
+#endif // !defined(REALLY_CLANG)
+
+#if !defined(REALLY_CLANG)
+ namespace test_exception_spec_type_system
+ {
+
+ // TODO: test it with clang++ from git
+
+ struct Good {};
+ struct Bad {};
+
+ void g1() noexcept;
+ void g2();
+
+ template<typename T>
+ Bad
+ f(T*, T*);
+
+ template<typename T1, typename T2>
+ Good
+ f(T1*, T2*);
+
+ static_assert (std::is_same_v<Good, decltype(f(g1, g2))>);
+
+ }
+#endif // !defined(REALLY_CLANG)
+
+ namespace test_inline_variables
+ {
+
+ template<class T> void f(T)
+ {}
+
+ template<class T> inline T g(T)
+ {
+ return T{};
+ }
+
+ template<> inline void f<>(int)
+ {}
+
+ template<> int g<>(int)
+ {
+ return 5;
+ }
+
+ }
+
+} // namespace cxx17
+
+#endif // __cplusplus <= 201402L
+
+]])
diff --git a/third_party/protobuf/m4/ax_prog_cc_for_build.m4 b/third_party/protobuf/m4/ax_prog_cc_for_build.m4
new file mode 100644
index 0000000000..77fd346a79
--- /dev/null
+++ b/third_party/protobuf/m4/ax_prog_cc_for_build.m4
@@ -0,0 +1,125 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_prog_cc_for_build.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_PROG_CC_FOR_BUILD
+#
+# DESCRIPTION
+#
+# This macro searches for a C compiler that generates native executables,
+# that is a C compiler that surely is not a cross-compiler. This can be
+# useful if you have to generate source code at compile-time like for
+# example GCC does.
+#
+# The macro sets the CC_FOR_BUILD and CPP_FOR_BUILD macros to anything
+# needed to compile or link (CC_FOR_BUILD) and preprocess (CPP_FOR_BUILD).
+# The value of these variables can be overridden by the user by specifying
+# a compiler with an environment variable (like you do for standard CC).
+#
+# It also sets BUILD_EXEEXT and BUILD_OBJEXT to the executable and object
+# file extensions for the build platform, and GCC_FOR_BUILD to `yes' if
+# the compiler we found is GCC. All these variables but GCC_FOR_BUILD are
+# substituted in the Makefile.
+#
+# LICENSE
+#
+# Copyright (c) 2008 Paolo Bonzini <bonzini@gnu.org>
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 8
+
+AU_ALIAS([AC_PROG_CC_FOR_BUILD], [AX_PROG_CC_FOR_BUILD])
+AC_DEFUN([AX_PROG_CC_FOR_BUILD], [dnl
+AC_REQUIRE([AC_PROG_CC])dnl
+AC_REQUIRE([AC_PROG_CPP])dnl
+AC_REQUIRE([AC_EXEEXT])dnl
+AC_REQUIRE([AC_CANONICAL_HOST])dnl
+
+dnl Use the standard macros, but make them use other variable names
+dnl
+pushdef([ac_cv_prog_CPP], ac_cv_build_prog_CPP)dnl
+pushdef([ac_cv_prog_gcc], ac_cv_build_prog_gcc)dnl
+pushdef([ac_cv_prog_cc_works], ac_cv_build_prog_cc_works)dnl
+pushdef([ac_cv_prog_cc_cross], ac_cv_build_prog_cc_cross)dnl
+pushdef([ac_cv_prog_cc_g], ac_cv_build_prog_cc_g)dnl
+pushdef([ac_cv_exeext], ac_cv_build_exeext)dnl
+pushdef([ac_cv_objext], ac_cv_build_objext)dnl
+pushdef([ac_exeext], ac_build_exeext)dnl
+pushdef([ac_objext], ac_build_objext)dnl
+pushdef([CC], CC_FOR_BUILD)dnl
+pushdef([CPP], CPP_FOR_BUILD)dnl
+pushdef([CFLAGS], CFLAGS_FOR_BUILD)dnl
+pushdef([CPPFLAGS], CPPFLAGS_FOR_BUILD)dnl
+pushdef([LDFLAGS], LDFLAGS_FOR_BUILD)dnl
+pushdef([host], build)dnl
+pushdef([host_alias], build_alias)dnl
+pushdef([host_cpu], build_cpu)dnl
+pushdef([host_vendor], build_vendor)dnl
+pushdef([host_os], build_os)dnl
+pushdef([ac_cv_host], ac_cv_build)dnl
+pushdef([ac_cv_host_alias], ac_cv_build_alias)dnl
+pushdef([ac_cv_host_cpu], ac_cv_build_cpu)dnl
+pushdef([ac_cv_host_vendor], ac_cv_build_vendor)dnl
+pushdef([ac_cv_host_os], ac_cv_build_os)dnl
+pushdef([ac_cpp], ac_build_cpp)dnl
+pushdef([ac_compile], ac_build_compile)dnl
+pushdef([ac_link], ac_build_link)dnl
+
+save_cross_compiling=$cross_compiling
+save_ac_tool_prefix=$ac_tool_prefix
+cross_compiling=no
+ac_tool_prefix=
+
+AC_PROG_CC
+AC_PROG_CPP
+AC_EXEEXT
+
+ac_tool_prefix=$save_ac_tool_prefix
+cross_compiling=$save_cross_compiling
+
+dnl Restore the old definitions
+dnl
+popdef([ac_link])dnl
+popdef([ac_compile])dnl
+popdef([ac_cpp])dnl
+popdef([ac_cv_host_os])dnl
+popdef([ac_cv_host_vendor])dnl
+popdef([ac_cv_host_cpu])dnl
+popdef([ac_cv_host_alias])dnl
+popdef([ac_cv_host])dnl
+popdef([host_os])dnl
+popdef([host_vendor])dnl
+popdef([host_cpu])dnl
+popdef([host_alias])dnl
+popdef([host])dnl
+popdef([LDFLAGS])dnl
+popdef([CPPFLAGS])dnl
+popdef([CFLAGS])dnl
+popdef([CPP])dnl
+popdef([CC])dnl
+popdef([ac_objext])dnl
+popdef([ac_exeext])dnl
+popdef([ac_cv_objext])dnl
+popdef([ac_cv_exeext])dnl
+popdef([ac_cv_prog_cc_g])dnl
+popdef([ac_cv_prog_cc_cross])dnl
+popdef([ac_cv_prog_cc_works])dnl
+popdef([ac_cv_prog_gcc])dnl
+popdef([ac_cv_prog_CPP])dnl
+
+dnl Finally, set Makefile variables
+dnl
+BUILD_EXEEXT=$ac_build_exeext
+BUILD_OBJEXT=$ac_build_objext
+AC_SUBST(BUILD_EXEEXT)dnl
+AC_SUBST(BUILD_OBJEXT)dnl
+AC_SUBST([CFLAGS_FOR_BUILD])dnl
+AC_SUBST([CPPFLAGS_FOR_BUILD])dnl
+AC_SUBST([LDFLAGS_FOR_BUILD])dnl
+])
diff --git a/third_party/protobuf/m4/ax_prog_cxx_for_build.m4 b/third_party/protobuf/m4/ax_prog_cxx_for_build.m4
new file mode 100644
index 0000000000..8cc0f73c0f
--- /dev/null
+++ b/third_party/protobuf/m4/ax_prog_cxx_for_build.m4
@@ -0,0 +1,110 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_prog_cxx_for_build.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_PROG_CXX_FOR_BUILD
+#
+# DESCRIPTION
+#
+# This macro searches for a C++ compiler that generates native
+# executables, that is a C++ compiler that surely is not a cross-compiler.
+# This can be useful if you have to generate source code at compile-time
+# like for example GCC does.
+#
+# The macro sets the CXX_FOR_BUILD and CXXCPP_FOR_BUILD macros to anything
+# needed to compile or link (CXX_FOR_BUILD) and preprocess
+# (CXXCPP_FOR_BUILD). The value of these variables can be overridden by
+# the user by specifying a compiler with an environment variable (like you
+# do for standard CXX).
+#
+# LICENSE
+#
+# Copyright (c) 2008 Paolo Bonzini <bonzini@gnu.org>
+# Copyright (c) 2012 Avionic Design GmbH
+#
+# Based on the AX_PROG_CC_FOR_BUILD macro by Paolo Bonzini.
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 2
+
+AU_ALIAS([AC_PROG_CXX_FOR_BUILD], [AX_PROG_CXX_FOR_BUILD])
+AC_DEFUN([AX_PROG_CXX_FOR_BUILD], [dnl
+AC_REQUIRE([AX_PROG_CC_FOR_BUILD])dnl
+AC_REQUIRE([AC_PROG_CXX])dnl
+AC_REQUIRE([AC_PROG_CXXCPP])dnl
+AC_REQUIRE([AC_CANONICAL_HOST])dnl
+
+dnl Use the standard macros, but make them use other variable names
+dnl
+pushdef([ac_cv_prog_CXXCPP], ac_cv_build_prog_CXXCPP)dnl
+pushdef([ac_cv_prog_gxx], ac_cv_build_prog_gxx)dnl
+pushdef([ac_cv_prog_cxx_works], ac_cv_build_prog_cxx_works)dnl
+pushdef([ac_cv_prog_cxx_cross], ac_cv_build_prog_cxx_cross)dnl
+pushdef([ac_cv_prog_cxx_g], ac_cv_build_prog_cxx_g)dnl
+pushdef([CXX], CXX_FOR_BUILD)dnl
+pushdef([CXXCPP], CXXCPP_FOR_BUILD)dnl
+pushdef([CXXFLAGS], CXXFLAGS_FOR_BUILD)dnl
+pushdef([CPPFLAGS], CPPFLAGS_FOR_BUILD)dnl
+pushdef([CXXCPPFLAGS], CXXCPPFLAGS_FOR_BUILD)dnl
+pushdef([host], build)dnl
+pushdef([host_alias], build_alias)dnl
+pushdef([host_cpu], build_cpu)dnl
+pushdef([host_vendor], build_vendor)dnl
+pushdef([host_os], build_os)dnl
+pushdef([ac_cv_host], ac_cv_build)dnl
+pushdef([ac_cv_host_alias], ac_cv_build_alias)dnl
+pushdef([ac_cv_host_cpu], ac_cv_build_cpu)dnl
+pushdef([ac_cv_host_vendor], ac_cv_build_vendor)dnl
+pushdef([ac_cv_host_os], ac_cv_build_os)dnl
+pushdef([ac_cxxcpp], ac_build_cxxcpp)dnl
+pushdef([ac_compile], ac_build_compile)dnl
+pushdef([ac_link], ac_build_link)dnl
+
+save_cross_compiling=$cross_compiling
+save_ac_tool_prefix=$ac_tool_prefix
+cross_compiling=no
+ac_tool_prefix=
+
+AC_PROG_CXX
+AC_PROG_CXXCPP
+
+ac_tool_prefix=$save_ac_tool_prefix
+cross_compiling=$save_cross_compiling
+
+dnl Restore the old definitions
+dnl
+popdef([ac_link])dnl
+popdef([ac_compile])dnl
+popdef([ac_cxxcpp])dnl
+popdef([ac_cv_host_os])dnl
+popdef([ac_cv_host_vendor])dnl
+popdef([ac_cv_host_cpu])dnl
+popdef([ac_cv_host_alias])dnl
+popdef([ac_cv_host])dnl
+popdef([host_os])dnl
+popdef([host_vendor])dnl
+popdef([host_cpu])dnl
+popdef([host_alias])dnl
+popdef([host])dnl
+popdef([CXXCPPFLAGS])dnl
+popdef([CPPFLAGS])dnl
+popdef([CXXFLAGS])dnl
+popdef([CXXCPP])dnl
+popdef([CXX])dnl
+popdef([ac_cv_prog_cxx_g])dnl
+popdef([ac_cv_prog_cxx_cross])dnl
+popdef([ac_cv_prog_cxx_works])dnl
+popdef([ac_cv_prog_gxx])dnl
+popdef([ac_cv_prog_CXXCPP])dnl
+
+dnl Finally, set Makefile variables
+dnl
+AC_SUBST([CXXFLAGS_FOR_BUILD])dnl
+AC_SUBST([CXXCPPFLAGS_FOR_BUILD])dnl
+])
diff --git a/third_party/protobuf/m4/stl_hash.m4 b/third_party/protobuf/m4/stl_hash.m4
new file mode 100644
index 0000000000..d7def1af9b
--- /dev/null
+++ b/third_party/protobuf/m4/stl_hash.m4
@@ -0,0 +1,71 @@
+# We check two things: where the include file is for
+# unordered_map/hash_map (we prefer the first form), and what
+# namespace unordered/hash_map lives in within that include file. We
+# include AC_TRY_COMPILE for all the combinations we've seen in the
+# wild. We define HASH_MAP_H to the location of the header file, and
+# HASH_NAMESPACE to the namespace the class (unordered_map or
+# hash_map) is in.
+
+# This also checks if unordered map exists.
+AC_DEFUN([AC_CXX_STL_HASH],
+ [
+ AC_MSG_CHECKING(the location of hash_map)
+ AC_LANG_SAVE
+ AC_LANG_CPLUSPLUS
+ ac_cv_cxx_hash_map=""
+ # First try unordered_map, but not on gcc's before 4.2 -- I've
+ # seen unexplainable unordered_map bugs with -O2 on older gcc's.
+ AC_TRY_COMPILE([#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
+ # error GCC too old for unordered_map
+ #endif
+ ],
+ [/* no program body necessary */],
+ [stl_hash_old_gcc=no],
+ [stl_hash_old_gcc=yes])
+ for location in unordered_map tr1/unordered_map; do
+ for namespace in std std::tr1; do
+ if test -z "$ac_cv_cxx_hash_map" -a "$stl_hash_old_gcc" != yes; then
+ # Some older gcc's have a buggy tr1, so test a bit of code.
+ AC_TRY_COMPILE([#include <$location>],
+ [const ${namespace}::unordered_map<int, int> t;
+ return t.find(5) == t.end();],
+ [ac_cv_cxx_hash_map="<$location>";
+ ac_cv_cxx_hash_namespace="$namespace";
+ ac_cv_cxx_hash_map_class="unordered_map";])
+ fi
+ done
+ done
+ # Now try hash_map
+ for location in ext/hash_map hash_map; do
+ for namespace in __gnu_cxx "" std stdext; do
+ if test -z "$ac_cv_cxx_hash_map"; then
+ AC_TRY_COMPILE([#include <$location>],
+ [${namespace}::hash_map<int, int> t],
+ [ac_cv_cxx_hash_map="<$location>";
+ ac_cv_cxx_hash_namespace="$namespace";
+ ac_cv_cxx_hash_map_class="hash_map";])
+ fi
+ done
+ done
+ ac_cv_cxx_hash_set=`echo "$ac_cv_cxx_hash_map" | sed s/map/set/`;
+ ac_cv_cxx_hash_set_class=`echo "$ac_cv_cxx_hash_map_class" | sed s/map/set/`;
+ if test -n "$ac_cv_cxx_hash_map"; then
+ AC_DEFINE(HAVE_HASH_MAP, 1, [define if the compiler has hash_map])
+ AC_DEFINE(HAVE_HASH_SET, 1, [define if the compiler has hash_set])
+ AC_DEFINE_UNQUOTED(HASH_MAP_H,$ac_cv_cxx_hash_map,
+ [the location of <unordered_map> or <hash_map>])
+ AC_DEFINE_UNQUOTED(HASH_SET_H,$ac_cv_cxx_hash_set,
+ [the location of <unordered_set> or <hash_set>])
+ AC_DEFINE_UNQUOTED(HASH_NAMESPACE,$ac_cv_cxx_hash_namespace,
+ [the namespace of hash_map/hash_set])
+ AC_DEFINE_UNQUOTED(HASH_MAP_CLASS,$ac_cv_cxx_hash_map_class,
+ [the name of <hash_map>])
+ AC_DEFINE_UNQUOTED(HASH_SET_CLASS,$ac_cv_cxx_hash_set_class,
+ [the name of <hash_set>])
+ AC_MSG_RESULT([$ac_cv_cxx_hash_map])
+ else
+ AC_MSG_RESULT()
+ AC_MSG_WARN([could not find an STL hash_map])
+ fi
+])
+
diff --git a/third_party/protobuf/more_tests/Makefile b/third_party/protobuf/more_tests/Makefile
new file mode 100755
index 0000000000..286cf0f12c
--- /dev/null
+++ b/third_party/protobuf/more_tests/Makefile
@@ -0,0 +1,41 @@
+# Additional tests to run before releasing a package.
+#
+# Run like:
+# make PACKAGE=/path/to/protobuf-VERSION.tar.gz
+#
+# Some of these tests require tools or make assumptions that may not be
+# available on end-user machines, so these cannot be part of "make check". For
+# example, we test that the headers compile with strict warning settings, but
+# since different compilers produce wildly different warnings we cannot assume
+# that this test will pass everywhere. If we ran it as part of "make check",
+# it could unnecessarily block users from running the real tests just because
+# their compiler produces some extra warnings that probably aren't a big deal.
+# So we run it separately.
+
+all: header_warning_test
+
+clean:
+ rm -rf src target header_warning_test.cc header_warning_test.o header_warning_test
+
+# Unpack the package into src, then install it into target.
+PACKAGE=protobuf.tar.gz
+
+src: $(PACKAGE)
+ tar zxvf $(PACKAGE)
+ mv `basename $(PACKAGE) .tar.gz` src
+
+target: src
+ (cd src && ./configure --prefix=$$PWD/../target --disable-shared)
+ (cd src && make -j4 check)
+ (cd src && make install)
+
+# Verify that headers produce no warnings even under strict settings.
+header_warning_test.cc: target
+ ( (cd target/include && find google/protobuf -name '*.h') | \
+ awk '{print "#include \""$$1"\""} ' > header_warning_test.cc )
+
+header_warning_test: header_warning_test.cc
+ # TODO(kenton): Consider adding -pedantic and -Weffc++. Currently these
+ # produce tons of extra warnings so we'll need to do some work first.
+ g++ -Itarget/include -Wall -Werror -Wsign-compare -O2 -c header_warning_test.cc
+ touch header_warning_test
diff --git a/third_party/protobuf/objectivec/.gitignore b/third_party/protobuf/objectivec/.gitignore
new file mode 100644
index 0000000000..f786ffce82
--- /dev/null
+++ b/third_party/protobuf/objectivec/.gitignore
@@ -0,0 +1,23 @@
+## Build generated
+build/
+DerivedData/
+
+## Various settings
+*.pbxuser
+!default.pbxuser
+*.mode1v3
+!default.mode1v3
+*.mode2v3
+!default.mode2v3
+*.perspectivev3
+!default.perspectivev3
+xcuserdata/
+
+## Other
+*.moved-aside
+*.xccheckout
+*.xcscmblueprint
+
+## Obj-C/Swift specific
+*.hmap
+*.ipa
diff --git a/third_party/protobuf/objectivec/DevTools/check_version_stamps.sh b/third_party/protobuf/objectivec/DevTools/check_version_stamps.sh
new file mode 100755
index 0000000000..1acbe2a2b7
--- /dev/null
+++ b/third_party/protobuf/objectivec/DevTools/check_version_stamps.sh
@@ -0,0 +1,55 @@
+#!/bin/bash -eu
+
+# This script checks that the runtime version number constant in the compiler
+# source and in the runtime source is the same.
+#
+# A distro can be made of the protobuf sources with only a subset of the
+# languages, so if the compiler depended on the Objective C runtime, those
+# builds would break. At the same time, we don't want the runtime source
+# depending on the compiler sources; so two copies of the constant are needed.
+
+readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
+readonly ProtoRootDir="${ScriptDir}/../.."
+
+die() {
+ echo "Error: $1"
+ exit 1
+}
+
+readonly GeneratorSrc="${ProtoRootDir}/src/google/protobuf/compiler/objectivec/objectivec_file.cc"
+readonly RuntimeSrc="${ProtoRootDir}/objectivec/GPBBootstrap.h"
+
+check_constant() {
+ local ConstantName="$1"
+
+ # Collect version from generator sources.
+ local GeneratorVersion=$( \
+ cat "${GeneratorSrc}" \
+ | sed -n -e "s:const int32 ${ConstantName} = \([0-9]*\);:\1:p"
+ )
+ if [[ -z "${GeneratorVersion}" ]] ; then
+ die "Failed to find ${ConstantName} in the generator source (${GeneratorSrc})."
+ fi
+
+ # Collect version from runtime sources.
+ local RuntimeVersion=$( \
+ cat "${RuntimeSrc}" \
+ | sed -n -e "s:#define ${ConstantName} \([0-9]*\):\1:p"
+ )
+ if [[ -z "${RuntimeVersion}" ]] ; then
+ die "Failed to find ${ConstantName} in the runtime source (${RuntimeSrc})."
+ fi
+
+ # Compare them.
+ if [[ "${GeneratorVersion}" != "${RuntimeVersion}" ]] ; then
+ die "${ConstantName} values don't match!
+ Generator: ${GeneratorVersion} from ${GeneratorSrc}
+ Runtime: ${RuntimeVersion} from ${RuntimeSrc}
+"
+ fi
+}
+
+# Do the check.
+check_constant GOOGLE_PROTOBUF_OBJC_VERSION
+
+# Success
diff --git a/third_party/protobuf/objectivec/DevTools/compile_testing_protos.sh b/third_party/protobuf/objectivec/DevTools/compile_testing_protos.sh
new file mode 100755
index 0000000000..d7f3f60589
--- /dev/null
+++ b/third_party/protobuf/objectivec/DevTools/compile_testing_protos.sh
@@ -0,0 +1,149 @@
+#!/bin/bash -eu
+# Invoked by the Xcode projects to build the protos needed for the unittests.
+
+readonly OUTPUT_DIR="${PROJECT_DERIVED_FILE_DIR}/protos"
+
+# -----------------------------------------------------------------------------
+# Helper for bailing.
+die() {
+ echo "Error: $1"
+ exit 2
+}
+
+# -----------------------------------------------------------------------------
+# What to do.
+case "${ACTION}" in
+ "")
+ # Build, fall thru
+ ;;
+ "clean")
+ rm -rf "${OUTPUT_DIR}"
+ exit 0
+ ;;
+ *)
+ die "Unknown action requested: ${ACTION}"
+ ;;
+esac
+
+# -----------------------------------------------------------------------------
+# Ensure the output dir exists
+mkdir -p "${OUTPUT_DIR}/google/protobuf"
+
+# -----------------------------------------------------------------------------
+# Move to the top of the protobuf directories and ensure there is a protoc
+# binary to use.
+cd "${SRCROOT}/.."
+[[ -x src/protoc ]] || \
+ die "Could not find the protoc binary; make sure you have built it (objectivec/DevTools/full_mac_build.sh -h)."
+
+# -----------------------------------------------------------------------------
+# See the compiler or proto files have changed.
+RUN_PROTOC=no
+if [[ ! -d "${OUTPUT_DIR}" ]] ; then
+ RUN_PROTOC=yes
+else
+ # Find the newest input file (protos, compiler, and this script).
+ # (these patterns catch some extra stuff, but better to over sample than
+ # under)
+ readonly NewestInput=$(find \
+ src/google/protobuf/*.proto \
+ objectivec/Tests/*.proto \
+ src/.libs src/*.la src/protoc \
+ objectivec/DevTools/compile_testing_protos.sh \
+ -type f -print0 \
+ | xargs -0 stat -f "%m %N" \
+ | sort -n | tail -n1 | cut -f2- -d" ")
+ # Find the oldest output file.
+ readonly OldestOutput=$(find \
+ "${OUTPUT_DIR}" \
+ -type f -name "*pbobjc.[hm]" -print0 \
+ | xargs -0 stat -f "%m %N" \
+ | sort -n -r | tail -n1 | cut -f2- -d" ")
+ # If the newest input is newer than the oldest output, regenerate.
+ if [[ "${NewestInput}" -nt "${OldestOutput}" ]] ; then
+ RUN_PROTOC=yes
+ fi
+fi
+
+if [[ "${RUN_PROTOC}" != "yes" ]] ; then
+ # Up to date.
+ exit 0
+fi
+
+# -----------------------------------------------------------------------------
+# Prune out all the files from previous generations to ensure we only have
+# current ones.
+find "${OUTPUT_DIR}" \
+ -type f -name "*pbobjc.[hm]" -print0 \
+ | xargs -0 rm -rf
+
+# -----------------------------------------------------------------------------
+# Helper to invoke protoc
+compile_protos() {
+ src/protoc \
+ --objc_out="${OUTPUT_DIR}/google/protobuf" \
+ --proto_path=src/google/protobuf/ \
+ --proto_path=src \
+ "$@"
+}
+
+# -----------------------------------------------------------------------------
+# Generate most of the proto files that exist in the C++ src tree. Several
+# are used in the tests, but the extra don't hurt in that they ensure ObjC
+# sources can be generated from them.
+
+CORE_PROTO_FILES=(
+ src/google/protobuf/any_test.proto
+ src/google/protobuf/unittest_arena.proto
+ src/google/protobuf/unittest_custom_options.proto
+ src/google/protobuf/unittest_enormous_descriptor.proto
+ src/google/protobuf/unittest_embed_optimize_for.proto
+ src/google/protobuf/unittest_empty.proto
+ src/google/protobuf/unittest_import.proto
+ src/google/protobuf/unittest_import_lite.proto
+ src/google/protobuf/unittest_lite.proto
+ src/google/protobuf/unittest_mset.proto
+ src/google/protobuf/unittest_mset_wire_format.proto
+ src/google/protobuf/unittest_no_arena.proto
+ src/google/protobuf/unittest_no_arena_import.proto
+ src/google/protobuf/unittest_no_generic_services.proto
+ src/google/protobuf/unittest_optimize_for.proto
+ src/google/protobuf/unittest.proto
+ src/google/protobuf/unittest_import_public.proto
+ src/google/protobuf/unittest_import_public_lite.proto
+ src/google/protobuf/unittest_drop_unknown_fields.proto
+ src/google/protobuf/unittest_preserve_unknown_enum.proto
+ src/google/protobuf/map_lite_unittest.proto
+ src/google/protobuf/map_proto2_unittest.proto
+ src/google/protobuf/map_unittest.proto
+ # The unittest_custom_options.proto extends the messages in descriptor.proto
+ # so we build it in to test extending in general. The library doesn't provide
+ # a descriptor as it doesn't use the classes/enums.
+ src/google/protobuf/descriptor.proto
+)
+
+# Note: there is overlap in package.Message names between some of the test
+# files, so they can't be generated all at once. This works because the overlap
+# isn't linked into a single binary.
+for a_proto in "${CORE_PROTO_FILES[@]}" ; do
+ compile_protos "${a_proto}"
+done
+
+# -----------------------------------------------------------------------------
+# Generate the Objective C specific testing protos.
+compile_protos \
+ --proto_path="objectivec/Tests" \
+ objectivec/Tests/unittest_cycle.proto \
+ objectivec/Tests/unittest_deprecated.proto \
+ objectivec/Tests/unittest_deprecated_file.proto \
+ objectivec/Tests/unittest_extension_chain_a.proto \
+ objectivec/Tests/unittest_extension_chain_b.proto \
+ objectivec/Tests/unittest_extension_chain_c.proto \
+ objectivec/Tests/unittest_extension_chain_d.proto \
+ objectivec/Tests/unittest_extension_chain_e.proto \
+ objectivec/Tests/unittest_extension_chain_f.proto \
+ objectivec/Tests/unittest_extension_chain_g.proto \
+ objectivec/Tests/unittest_runtime_proto2.proto \
+ objectivec/Tests/unittest_runtime_proto3.proto \
+ objectivec/Tests/unittest_objc.proto \
+ objectivec/Tests/unittest_objc_startup.proto
diff --git a/third_party/protobuf/objectivec/DevTools/full_mac_build.sh b/third_party/protobuf/objectivec/DevTools/full_mac_build.sh
new file mode 100755
index 0000000000..ea9fd2736b
--- /dev/null
+++ b/third_party/protobuf/objectivec/DevTools/full_mac_build.sh
@@ -0,0 +1,329 @@
+#!/bin/bash
+#
+# Helper to do build so you don't have to remember all the steps/args.
+
+
+set -eu
+
+# Some base locations.
+readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
+readonly ProtoRootDir="${ScriptDir}/../.."
+
+printUsage() {
+ NAME=$(basename "${0}")
+ cat << EOF
+usage: ${NAME} [OPTIONS]
+
+This script does the common build steps needed.
+
+OPTIONS:
+
+ General:
+
+ -h, --help
+ Show this message
+ -c, --clean
+ Issue a clean before the normal build.
+ -a, --autogen
+ Start by rerunning autogen & configure.
+ -r, --regenerate-descriptors
+ Run generate_descriptor_proto.sh to regenerate all the checked in
+ proto sources.
+ -j #, --jobs #
+ Force the number of parallel jobs (useful for debugging build issues).
+ --core-only
+ Skip some of the core protobuf build/checks to shorten the build time.
+ --skip-xcode
+ Skip the invoke of Xcode to test the runtime on both iOS and OS X.
+ --skip-xcode-ios
+ Skip the invoke of Xcode to test the runtime on iOS.
+ --skip-xcode-debug
+ Skip the Xcode Debug configuration.
+ --skip-xcode-release
+ Skip the Xcode Release configuration.
+ --skip-xcode-osx
+ Skip the invoke of Xcode to test the runtime on OS X.
+ --skip-objc-conformance
+ Skip the Objective C conformance tests (run on OS X).
+ --xcode-quiet
+ Pass -quiet to xcodebuild.
+
+EOF
+}
+
+header() {
+ echo ""
+ echo "========================================================================"
+ echo " ${@}"
+ echo "========================================================================"
+}
+
+# Thanks to libtool, builds can fail in odd ways and since it eats some output
+# it can be hard to spot, so force error output if make exits with a non zero.
+wrapped_make() {
+ set +e # Don't stop if the command fails.
+ make $*
+ MAKE_EXIT_STATUS=$?
+ if [ ${MAKE_EXIT_STATUS} -ne 0 ]; then
+ echo "Error: 'make $*' exited with status ${MAKE_EXIT_STATUS}"
+ exit ${MAKE_EXIT_STATUS}
+ fi
+ set -e
+}
+
+NUM_MAKE_JOBS=$(/usr/sbin/sysctl -n hw.ncpu)
+if [[ "${NUM_MAKE_JOBS}" -lt 2 ]] ; then
+ NUM_MAKE_JOBS=2
+fi
+
+DO_AUTOGEN=no
+DO_CLEAN=no
+REGEN_DESCRIPTORS=no
+CORE_ONLY=no
+DO_XCODE_IOS_TESTS=yes
+DO_XCODE_OSX_TESTS=yes
+DO_XCODE_DEBUG=yes
+DO_XCODE_RELEASE=yes
+DO_OBJC_CONFORMANCE_TESTS=yes
+XCODE_QUIET=no
+while [[ $# != 0 ]]; do
+ case "${1}" in
+ -h | --help )
+ printUsage
+ exit 0
+ ;;
+ -c | --clean )
+ DO_CLEAN=yes
+ ;;
+ -a | --autogen )
+ DO_AUTOGEN=yes
+ ;;
+ -r | --regenerate-descriptors )
+ REGEN_DESCRIPTORS=yes
+ ;;
+ -j | --jobs )
+ shift
+ NUM_MAKE_JOBS="${1}"
+ ;;
+ --core-only )
+ CORE_ONLY=yes
+ ;;
+ --skip-xcode )
+ DO_XCODE_IOS_TESTS=no
+ DO_XCODE_OSX_TESTS=no
+ ;;
+ --skip-xcode-ios )
+ DO_XCODE_IOS_TESTS=no
+ ;;
+ --skip-xcode-osx )
+ DO_XCODE_OSX_TESTS=no
+ ;;
+ --skip-xcode-debug )
+ DO_XCODE_DEBUG=no
+ ;;
+ --skip-xcode-release )
+ DO_XCODE_RELEASE=no
+ ;;
+ --skip-objc-conformance )
+ DO_OBJC_CONFORMANCE_TESTS=no
+ ;;
+ --xcode-quiet )
+ XCODE_QUIET=yes
+ ;;
+ -*)
+ echo "ERROR: Unknown option: ${1}" 1>&2
+ printUsage
+ exit 1
+ ;;
+ *)
+ echo "ERROR: Unknown argument: ${1}" 1>&2
+ printUsage
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+# Into the proto dir.
+cd "${ProtoRootDir}"
+
+# if no Makefile, force the autogen.
+if [[ ! -f Makefile ]] ; then
+ DO_AUTOGEN=yes
+fi
+
+if [[ "${DO_AUTOGEN}" == "yes" ]] ; then
+ header "Running autogen & configure"
+ ./autogen.sh
+ ./configure \
+ CPPFLAGS="-mmacosx-version-min=10.9 -Wunused-const-variable -Wunused-function" \
+ CXXFLAGS="-Wnon-virtual-dtor -Woverloaded-virtual"
+fi
+
+if [[ "${DO_CLEAN}" == "yes" ]] ; then
+ header "Cleaning"
+ wrapped_make clean
+ if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then
+ XCODEBUILD_CLEAN_BASE_IOS=(
+ xcodebuild
+ -project objectivec/ProtocolBuffers_iOS.xcodeproj
+ -scheme ProtocolBuffers
+ )
+ if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
+ "${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Debug clean
+ fi
+ if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
+ "${XCODEBUILD_CLEAN_BASE_IOS[@]}" -configuration Release clean
+ fi
+ fi
+ if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then
+ XCODEBUILD_CLEAN_BASE_OSX=(
+ xcodebuild
+ -project objectivec/ProtocolBuffers_OSX.xcodeproj
+ -scheme ProtocolBuffers
+ )
+ if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
+ "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Debug clean
+ fi
+ if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
+ "${XCODEBUILD_CLEAN_BASE_OSX[@]}" -configuration Release clean
+ fi
+ fi
+fi
+
+if [[ "${REGEN_DESCRIPTORS}" == "yes" ]] ; then
+ header "Regenerating the descriptor sources."
+ ./generate_descriptor_proto.sh -j "${NUM_MAKE_JOBS}"
+fi
+
+if [[ "${CORE_ONLY}" == "yes" ]] ; then
+ header "Building core Only"
+ wrapped_make -j "${NUM_MAKE_JOBS}"
+else
+ header "Building"
+ # Can't issue these together, when fully parallel, something sometimes chokes
+ # at random.
+ wrapped_make -j "${NUM_MAKE_JOBS}" all
+ wrapped_make -j "${NUM_MAKE_JOBS}" check
+ # Fire off the conformance tests also.
+ cd conformance
+ wrapped_make -j "${NUM_MAKE_JOBS}" test_cpp
+ cd ..
+fi
+
+# Ensure the WKT sources checked in are current.
+objectivec/generate_well_known_types.sh --check-only -j "${NUM_MAKE_JOBS}"
+
+header "Checking on the ObjC Runtime Code"
+objectivec/DevTools/pddm_tests.py
+if ! objectivec/DevTools/pddm.py --dry-run objectivec/*.[hm] objectivec/Tests/*.[hm] ; then
+ echo ""
+ echo "Update by running:"
+ echo " objectivec/DevTools/pddm.py objectivec/*.[hm] objectivec/Tests/*.[hm]"
+ exit 1
+fi
+
+readonly XCODE_VERSION_LINE="$(xcodebuild -version | grep Xcode\ )"
+readonly XCODE_VERSION="${XCODE_VERSION_LINE/Xcode /}" # drop the prefix.
+
+if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then
+ XCODEBUILD_TEST_BASE_IOS=(
+ xcodebuild
+ -project objectivec/ProtocolBuffers_iOS.xcodeproj
+ -scheme ProtocolBuffers
+ )
+ if [[ "${XCODE_QUIET}" == "yes" ]] ; then
+ XCODEBUILD_TEST_BASE_IOS+=( -quiet )
+ fi
+ # Don't need to worry about form factors or retina/non retina;
+ # just pick a mix of OS Versions and 32/64 bit.
+ # NOTE: Different Xcode have different simulated hardware/os support.
+ case "${XCODE_VERSION}" in
+ 6.* )
+ echo "ERROR: Xcode 6.3/6.4 no longer supported for building, please use 8.0 or higher." 1>&2
+ exit 10
+ ;;
+ 7.* )
+ echo "ERROR: The unittests include Swift code that is now Swift 3.0." 1>&2
+ echo "ERROR: Xcode 8.0 or higher is required to build the test suite, but the library works with Xcode 7.x." 1>&2
+ exit 11
+ ;;
+ 8.0* )
+ # The 8.* device seem to hang and never start under Xcode 8.
+ XCODEBUILD_TEST_BASE_IOS+=(
+ -destination "platform=iOS Simulator,name=iPhone 4s,OS=9.0" # 32bit
+ -destination "platform=iOS Simulator,name=iPhone 7,OS=10.0" # 64bit
+ -destination "platform=iOS Simulator,name=iPad 2,OS=9.0" # 32bit
+ -destination "platform=iOS Simulator,name=iPad Pro (9.7 inch),OS=10.0" # 64bit
+ )
+ ;;
+ 8.1* )
+ XCODEBUILD_TEST_BASE_IOS+=(
+ -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
+ -destination "platform=iOS Simulator,name=iPhone 7,OS=10.1" # 64bit
+ -destination "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
+ -destination "platform=iOS Simulator,name=iPad Pro (9.7 inch),OS=10.1" # 64bit
+ )
+ ;;
+ 8.2* )
+ XCODEBUILD_TEST_BASE_IOS+=(
+ -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
+ -destination "platform=iOS Simulator,name=iPhone 7,OS=10.2" # 64bit
+ -destination "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
+ -destination "platform=iOS Simulator,name=iPad Pro (9.7 inch),OS=10.2" # 64bit
+ )
+ ;;
+ * )
+ echo "Time to update the simulator targets for Xcode ${XCODE_VERSION}"
+ exit 2
+ ;;
+ esac
+ if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
+ header "Doing Xcode iOS build/tests - Debug"
+ "${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Debug test
+ fi
+ if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
+ header "Doing Xcode iOS build/tests - Release"
+ "${XCODEBUILD_TEST_BASE_IOS[@]}" -configuration Release test
+ fi
+ # Don't leave the simulator in the developer's face.
+ killall Simulator
+fi
+if [[ "${DO_XCODE_OSX_TESTS}" == "yes" ]] ; then
+ XCODEBUILD_TEST_BASE_OSX=(
+ xcodebuild
+ -project objectivec/ProtocolBuffers_OSX.xcodeproj
+ -scheme ProtocolBuffers
+ # Since the ObjC 2.0 Runtime is required, 32bit OS X isn't supported.
+ -destination "platform=OS X,arch=x86_64" # 64bit
+ )
+ if [[ "${XCODE_QUIET}" == "yes" ]] ; then
+ XCODEBUILD_TEST_BASE_OSX+=( -quiet )
+ fi
+ case "${XCODE_VERSION}" in
+ 6.* )
+ echo "ERROR: Xcode 6.3/6.4 no longer supported for building, please use 8.0 or higher." 1>&2
+ exit 10
+ ;;
+ 7.* )
+ echo "ERROR: The unittests include Swift code that is now Swift 3.0." 1>&2
+ echo "ERROR: Xcode 8.0 or higher is required to build the test suite, but the library works with Xcode 7.x." 1>&2
+ exit 11
+ ;;
+ esac
+ if [[ "${DO_XCODE_DEBUG}" == "yes" ]] ; then
+ header "Doing Xcode OS X build/tests - Debug"
+ "${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Debug test
+ fi
+ if [[ "${DO_XCODE_RELEASE}" == "yes" ]] ; then
+ header "Doing Xcode OS X build/tests - Release"
+ "${XCODEBUILD_TEST_BASE_OSX[@]}" -configuration Release test
+ fi
+fi
+
+if [[ "${DO_OBJC_CONFORMANCE_TESTS}" == "yes" ]] ; then
+ header "Running ObjC Conformance Tests"
+ cd conformance
+ wrapped_make -j "${NUM_MAKE_JOBS}" test_objc
+ cd ..
+fi
diff --git a/third_party/protobuf/objectivec/DevTools/pddm.py b/third_party/protobuf/objectivec/DevTools/pddm.py
new file mode 100755
index 0000000000..9a11fec449
--- /dev/null
+++ b/third_party/protobuf/objectivec/DevTools/pddm.py
@@ -0,0 +1,686 @@
+#! /usr/bin/python
+#
+# Protocol Buffers - Google's data interchange format
+# Copyright 2015 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.
+
+"""PDDM - Poor Developers' Debug-able Macros
+
+A simple markup that can be added in comments of source so they can then be
+expanded out into code. Most of this could be done with CPP macros, but then
+developers can't really step through them in the debugger, this way they are
+expanded to the same code, but you can debug them.
+
+Any file can be processed, but the syntax is designed around a C based compiler.
+Processed lines start with "//%". There are three types of sections you can
+create: Text (left alone), Macro Definitions, and Macro Expansions. There is
+no order required between definitions and expansions, all definitions are read
+before any expansions are processed (thus, if desired, definitions can be put
+at the end of the file to keep them out of the way of the code).
+
+Macro Definitions are started with "//%PDDM-DEFINE Name(args)" and all lines
+afterwards that start with "//%" are included in the definition. Multiple
+macros can be defined in one block by just using a another "//%PDDM-DEFINE"
+line to start the next macro. Optionally, a macro can be ended with
+"//%PDDM-DEFINE-END", this can be useful when you want to make it clear that
+trailing blank lines are included in the macro. You can also end a definition
+with an expansion.
+
+Macro Expansions are started by single lines containing
+"//%PDDM-EXPAND Name(args)" and then with "//%PDDM-EXPAND-END" or another
+expansions. All lines in-between are replaced by the result of the expansion.
+The first line of the expansion is always a blank like just for readability.
+
+Expansion itself is pretty simple, one macro can invoke another macro, but
+you cannot nest the invoke of a macro in another macro (i.e. - can't do
+"foo(bar(a))", but you can define foo(a) and bar(b) where bar invokes foo()
+within its expansion.
+
+When macros are expanded, the arg references can also add "$O" suffix to the
+name (i.e. - "NAME$O") to specify an option to be applied. The options are:
+
+ $S - Replace each character in the value with a space.
+ $l - Lowercase the first letter of the value.
+ $L - Lowercase the whole value.
+ $u - Uppercase the first letter of the value.
+ $U - Uppercase the whole value.
+
+Within a macro you can use ## to cause things to get joined together after
+expansion (i.e. - "a##b" within a macro will become "ab").
+
+Example:
+
+ int foo(MyEnum x) {
+ switch (x) {
+ //%PDDM-EXPAND case(Enum_Left, 1)
+ //%PDDM-EXPAND case(Enum_Center, 2)
+ //%PDDM-EXPAND case(Enum_Right, 3)
+ //%PDDM-EXPAND-END
+ }
+
+ //%PDDM-DEFINE case(_A, _B)
+ //% case _A:
+ //% return _B;
+
+ A macro ends at the start of the next one, or an optional %PDDM-DEFINE-END
+ can be used to avoid adding extra blank lines/returns (or make it clear when
+ it is desired).
+
+ One macro can invoke another by simply using its name NAME(ARGS). You cannot
+ nest an invoke inside another (i.e. - NAME1(NAME2(ARGS)) isn't supported).
+
+ Within a macro you can use ## to cause things to get joined together after
+ processing (i.e. - "a##b" within a macro will become "ab").
+
+
+"""
+
+import optparse
+import os
+import re
+import sys
+
+
+# Regex for macro definition.
+_MACRO_RE = re.compile(r'(?P<name>\w+)\((?P<args>.*?)\)')
+# Regex for macro's argument definition.
+_MACRO_ARG_NAME_RE = re.compile(r'^\w+$')
+
+# Line inserted after each EXPAND.
+_GENERATED_CODE_LINE = (
+ '// This block of code is generated, do not edit it directly.'
+)
+
+
+def _MacroRefRe(macro_names):
+ # Takes in a list of macro names and makes a regex that will match invokes
+ # of those macros.
+ return re.compile(r'\b(?P<macro_ref>(?P<name>(%s))\((?P<args>.*?)\))' %
+ '|'.join(macro_names))
+
+def _MacroArgRefRe(macro_arg_names):
+ # Takes in a list of macro arg names and makes a regex that will match
+ # uses of those args.
+ return re.compile(r'\b(?P<name>(%s))(\$(?P<option>.))?\b' %
+ '|'.join(macro_arg_names))
+
+
+class PDDMError(Exception):
+ """Error thrown by pddm."""
+ pass
+
+
+class MacroCollection(object):
+ """Hold a set of macros and can resolve/expand them."""
+
+ def __init__(self, a_file=None):
+ """Initializes the collection.
+
+ Args:
+ a_file: The file like stream to parse.
+
+ Raises:
+ PDDMError if there are any issues.
+ """
+ self._macros = dict()
+ if a_file:
+ self.ParseInput(a_file)
+
+ class MacroDefinition(object):
+ """Holds a macro definition."""
+
+ def __init__(self, name, arg_names):
+ self._name = name
+ self._args = tuple(arg_names)
+ self._body = ''
+ self._needNewLine = False
+
+ def AppendLine(self, line):
+ if self._needNewLine:
+ self._body += '\n'
+ self._body += line
+ self._needNewLine = not line.endswith('\n')
+
+ @property
+ def name(self):
+ return self._name
+
+ @property
+ def args(self):
+ return self._args
+
+ @property
+ def body(self):
+ return self._body
+
+ def ParseInput(self, a_file):
+ """Consumes input extracting definitions.
+
+ Args:
+ a_file: The file like stream to parse.
+
+ Raises:
+ PDDMError if there are any issues.
+ """
+ input_lines = a_file.read().splitlines()
+ self.ParseLines(input_lines)
+
+ def ParseLines(self, input_lines):
+ """Parses list of lines.
+
+ Args:
+ input_lines: A list of strings of input to parse (no newlines on the
+ strings).
+
+ Raises:
+ PDDMError if there are any issues.
+ """
+ current_macro = None
+ for line in input_lines:
+ if line.startswith('PDDM-'):
+ directive = line.split(' ', 1)[0]
+ if directive == 'PDDM-DEFINE':
+ name, args = self._ParseDefineLine(line)
+ if self._macros.get(name):
+ raise PDDMError('Attempt to redefine macro: "%s"' % line)
+ current_macro = self.MacroDefinition(name, args)
+ self._macros[name] = current_macro
+ continue
+ if directive == 'PDDM-DEFINE-END':
+ if not current_macro:
+ raise PDDMError('Got DEFINE-END directive without an active macro:'
+ ' "%s"' % line)
+ current_macro = None
+ continue
+ raise PDDMError('Hit a line with an unknown directive: "%s"' % line)
+
+ if current_macro:
+ current_macro.AppendLine(line)
+ continue
+
+ # Allow blank lines between macro definitions.
+ if line.strip() == '':
+ continue
+
+ raise PDDMError('Hit a line that wasn\'t a directive and no open macro'
+ ' definition: "%s"' % line)
+
+ def _ParseDefineLine(self, input_line):
+ assert input_line.startswith('PDDM-DEFINE')
+ line = input_line[12:].strip()
+ match = _MACRO_RE.match(line)
+ # Must match full line
+ if match is None or match.group(0) != line:
+ raise PDDMError('Failed to parse macro definition: "%s"' % input_line)
+ name = match.group('name')
+ args_str = match.group('args').strip()
+ args = []
+ if args_str:
+ for part in args_str.split(','):
+ arg = part.strip()
+ if arg == '':
+ raise PDDMError('Empty arg name in macro definition: "%s"'
+ % input_line)
+ if not _MACRO_ARG_NAME_RE.match(arg):
+ raise PDDMError('Invalid arg name "%s" in macro definition: "%s"'
+ % (arg, input_line))
+ if arg in args:
+ raise PDDMError('Arg name "%s" used more than once in macro'
+ ' definition: "%s"' % (arg, input_line))
+ args.append(arg)
+ return (name, tuple(args))
+
+ def Expand(self, macro_ref_str):
+ """Expands the macro reference.
+
+ Args:
+ macro_ref_str: String of a macro reference (i.e. foo(a, b)).
+
+ Returns:
+ The text from the expansion.
+
+ Raises:
+ PDDMError if there are any issues.
+ """
+ match = _MACRO_RE.match(macro_ref_str)
+ if match is None or match.group(0) != macro_ref_str:
+ raise PDDMError('Failed to parse macro reference: "%s"' % macro_ref_str)
+ if match.group('name') not in self._macros:
+ raise PDDMError('No macro named "%s".' % match.group('name'))
+ return self._Expand(match, [], macro_ref_str)
+
+ def _FormatStack(self, macro_ref_stack):
+ result = ''
+ for _, macro_ref in reversed(macro_ref_stack):
+ result += '\n...while expanding "%s".' % macro_ref
+ return result
+
+ def _Expand(self, macro_ref_match, macro_stack, macro_ref_str=None):
+ if macro_ref_str is None:
+ macro_ref_str = macro_ref_match.group('macro_ref')
+ name = macro_ref_match.group('name')
+ for prev_name, prev_macro_ref in macro_stack:
+ if name == prev_name:
+ raise PDDMError('Found macro recusion, invoking "%s":%s' %
+ (macro_ref_str, self._FormatStack(macro_stack)))
+ macro = self._macros[name]
+ args_str = macro_ref_match.group('args').strip()
+ args = []
+ if args_str or len(macro.args):
+ args = [x.strip() for x in args_str.split(',')]
+ if len(args) != len(macro.args):
+ raise PDDMError('Expected %d args, got: "%s".%s' %
+ (len(macro.args), macro_ref_str,
+ self._FormatStack(macro_stack)))
+ # Replace args usages.
+ result = self._ReplaceArgValues(macro, args, macro_ref_str, macro_stack)
+ # Expand any macro invokes.
+ new_macro_stack = macro_stack + [(name, macro_ref_str)]
+ while True:
+ eval_result = self._EvalMacrosRefs(result, new_macro_stack)
+ # Consume all ## directives to glue things together.
+ eval_result = eval_result.replace('##', '')
+ if eval_result == result:
+ break
+ result = eval_result
+ return result
+
+ def _ReplaceArgValues(self,
+ macro, arg_values, macro_ref_to_report, macro_stack):
+ if len(arg_values) == 0:
+ # Nothing to do
+ return macro.body
+ assert len(arg_values) == len(macro.args)
+ args = dict(zip(macro.args, arg_values))
+ def _lookupArg(match):
+ val = args[match.group('name')]
+ opt = match.group('option')
+ if opt:
+ if opt == 'S': # Spaces for the length
+ return ' ' * len(val)
+ elif opt == 'l': # Lowercase first character
+ if val:
+ return val[0].lower() + val[1:]
+ else:
+ return val
+ elif opt == 'L': # All Lowercase
+ return val.lower()
+ elif opt == 'u': # Uppercase first character
+ if val:
+ return val[0].upper() + val[1:]
+ else:
+ return val
+ elif opt == 'U': # All Uppercase
+ return val.upper()
+ else:
+ raise PDDMError('Unknown arg option "%s$%s" while expanding "%s".%s'
+ % (match.group('name'), match.group('option'),
+ macro_ref_to_report,
+ self._FormatStack(macro_stack)))
+ return val
+ # Let the regex do the work!
+ macro_arg_ref_re = _MacroArgRefRe(macro.args)
+ return macro_arg_ref_re.sub(_lookupArg, macro.body)
+
+ def _EvalMacrosRefs(self, text, macro_stack):
+ macro_ref_re = _MacroRefRe(self._macros.keys())
+ def _resolveMacro(match):
+ return self._Expand(match, macro_stack)
+ return macro_ref_re.sub(_resolveMacro, text)
+
+
+class SourceFile(object):
+ """Represents a source file with PDDM directives in it."""
+
+ def __init__(self, a_file, import_resolver=None):
+ """Initializes the file reading in the file.
+
+ Args:
+ a_file: The file to read in.
+ import_resolver: a function that given a path will return a stream for
+ the contents.
+
+ Raises:
+ PDDMError if there are any issues.
+ """
+ self._sections = []
+ self._original_content = a_file.read()
+ self._import_resolver = import_resolver
+ self._processed_content = None
+
+ class SectionBase(object):
+
+ def __init__(self, first_line_num):
+ self._lines = []
+ self._first_line_num = first_line_num
+
+ def TryAppend(self, line, line_num):
+ """Try appending a line.
+
+ Args:
+ line: The line to append.
+ line_num: The number of the line.
+
+ Returns:
+ A tuple of (SUCCESS, CAN_ADD_MORE). If SUCCESS if False, the line
+ wasn't append. If SUCCESS is True, then CAN_ADD_MORE is True/False to
+ indicate if more lines can be added after this one.
+ """
+ assert False, "sublcass should have overridden"
+ return (False, False)
+
+ def HitEOF(self):
+ """Called when the EOF was reached for for a given section."""
+ pass
+
+ def BindMacroCollection(self, macro_collection):
+ """Binds the chunk to a macro collection.
+
+ Args:
+ macro_collection: The collection to bind too.
+ """
+ pass
+
+ def Append(self, line):
+ self._lines.append(line)
+
+ @property
+ def lines(self):
+ return self._lines
+
+ @property
+ def num_lines_captured(self):
+ return len(self._lines)
+
+ @property
+ def first_line_num(self):
+ return self._first_line_num
+
+ @property
+ def first_line(self):
+ if not self._lines:
+ return ''
+ return self._lines[0]
+
+ @property
+ def text(self):
+ return '\n'.join(self.lines) + '\n'
+
+ class TextSection(SectionBase):
+ """Text section that is echoed out as is."""
+
+ def TryAppend(self, line, line_num):
+ if line.startswith('//%PDDM'):
+ return (False, False)
+ self.Append(line)
+ return (True, True)
+
+ class ExpansionSection(SectionBase):
+ """Section that is the result of an macro expansion."""
+
+ def __init__(self, first_line_num):
+ SourceFile.SectionBase.__init__(self, first_line_num)
+ self._macro_collection = None
+
+ def TryAppend(self, line, line_num):
+ if line.startswith('//%PDDM'):
+ directive = line.split(' ', 1)[0]
+ if directive == '//%PDDM-EXPAND':
+ self.Append(line)
+ return (True, True)
+ if directive == '//%PDDM-EXPAND-END':
+ assert self.num_lines_captured > 0
+ return (True, False)
+ raise PDDMError('Ran into directive ("%s", line %d) while in "%s".' %
+ (directive, line_num, self.first_line))
+ # Eat other lines.
+ return (True, True)
+
+ def HitEOF(self):
+ raise PDDMError('Hit the end of the file while in "%s".' %
+ self.first_line)
+
+ def BindMacroCollection(self, macro_collection):
+ self._macro_collection = macro_collection
+
+ @property
+ def lines(self):
+ captured_lines = SourceFile.SectionBase.lines.fget(self)
+ directive_len = len('//%PDDM-EXPAND')
+ result = []
+ for line in captured_lines:
+ result.append(line)
+ if self._macro_collection:
+ # Always add a blank line, seems to read better. (If need be, add an
+ # option to the EXPAND to indicate if this should be done.)
+ result.extend([_GENERATED_CODE_LINE, ''])
+ macro = line[directive_len:].strip()
+ try:
+ expand_result = self._macro_collection.Expand(macro)
+ # Since expansions are line oriented, strip trailing whitespace
+ # from the lines.
+ lines = [x.rstrip() for x in expand_result.split('\n')]
+ result.append('\n'.join(lines))
+ except PDDMError as e:
+ raise PDDMError('%s\n...while expanding "%s" from the section'
+ ' that started:\n Line %d: %s' %
+ (e.message, macro,
+ self.first_line_num, self.first_line))
+
+ # Add the ending marker.
+ if len(captured_lines) == 1:
+ result.append('//%%PDDM-EXPAND-END %s' %
+ captured_lines[0][directive_len:].strip())
+ else:
+ result.append('//%%PDDM-EXPAND-END (%s expansions)' % len(captured_lines))
+
+ return result
+
+ class DefinitionSection(SectionBase):
+ """Section containing macro definitions"""
+
+ def TryAppend(self, line, line_num):
+ if not line.startswith('//%'):
+ return (False, False)
+ if line.startswith('//%PDDM'):
+ directive = line.split(' ', 1)[0]
+ if directive == "//%PDDM-EXPAND":
+ return False, False
+ if directive not in ('//%PDDM-DEFINE', '//%PDDM-DEFINE-END'):
+ raise PDDMError('Ran into directive ("%s", line %d) while in "%s".' %
+ (directive, line_num, self.first_line))
+ self.Append(line)
+ return (True, True)
+
+ def BindMacroCollection(self, macro_collection):
+ if macro_collection:
+ try:
+ # Parse the lines after stripping the prefix.
+ macro_collection.ParseLines([x[3:] for x in self.lines])
+ except PDDMError as e:
+ raise PDDMError('%s\n...while parsing section that started:\n'
+ ' Line %d: %s' %
+ (e.message, self.first_line_num, self.first_line))
+
+ class ImportDefinesSection(SectionBase):
+ """Section containing an import of PDDM-DEFINES from an external file."""
+
+ def __init__(self, first_line_num, import_resolver):
+ SourceFile.SectionBase.__init__(self, first_line_num)
+ self._import_resolver = import_resolver
+
+ def TryAppend(self, line, line_num):
+ if not line.startswith('//%PDDM-IMPORT-DEFINES '):
+ return (False, False)
+ assert self.num_lines_captured == 0
+ self.Append(line)
+ return (True, False)
+
+ def BindMacroCollection(self, macro_colletion):
+ if not macro_colletion:
+ return
+ if self._import_resolver is None:
+ raise PDDMError('Got an IMPORT-DEFINES without a resolver (line %d):'
+ ' "%s".' % (self.first_line_num, self.first_line))
+ import_name = self.first_line.split(' ', 1)[1].strip()
+ imported_file = self._import_resolver(import_name)
+ if imported_file is None:
+ raise PDDMError('Resolver failed to find "%s" (line %d):'
+ ' "%s".' %
+ (import_name, self.first_line_num, self.first_line))
+ try:
+ imported_src_file = SourceFile(imported_file, self._import_resolver)
+ imported_src_file._ParseFile()
+ for section in imported_src_file._sections:
+ section.BindMacroCollection(macro_colletion)
+ except PDDMError as e:
+ raise PDDMError('%s\n...while importing defines:\n'
+ ' Line %d: %s' %
+ (e.message, self.first_line_num, self.first_line))
+
+ def _ParseFile(self):
+ self._sections = []
+ lines = self._original_content.splitlines()
+ cur_section = None
+ for line_num, line in enumerate(lines, 1):
+ if not cur_section:
+ cur_section = self._MakeSection(line, line_num)
+ was_added, accept_more = cur_section.TryAppend(line, line_num)
+ if not was_added:
+ cur_section = self._MakeSection(line, line_num)
+ was_added, accept_more = cur_section.TryAppend(line, line_num)
+ assert was_added
+ if not accept_more:
+ cur_section = None
+
+ if cur_section:
+ cur_section.HitEOF()
+
+ def _MakeSection(self, line, line_num):
+ if not line.startswith('//%PDDM'):
+ section = self.TextSection(line_num)
+ else:
+ directive = line.split(' ', 1)[0]
+ if directive == '//%PDDM-EXPAND':
+ section = self.ExpansionSection(line_num)
+ elif directive == '//%PDDM-DEFINE':
+ section = self.DefinitionSection(line_num)
+ elif directive == '//%PDDM-IMPORT-DEFINES':
+ section = self.ImportDefinesSection(line_num, self._import_resolver)
+ else:
+ raise PDDMError('Unexpected line %d: "%s".' % (line_num, line))
+ self._sections.append(section)
+ return section
+
+ def ProcessContent(self, strip_expansion=False):
+ """Processes the file contents."""
+ self._ParseFile()
+ if strip_expansion:
+ # Without a collection the expansions become blank, removing them.
+ collection = None
+ else:
+ collection = MacroCollection()
+ for section in self._sections:
+ section.BindMacroCollection(collection)
+ result = ''
+ for section in self._sections:
+ result += section.text
+ self._processed_content = result
+
+ @property
+ def original_content(self):
+ return self._original_content
+
+ @property
+ def processed_content(self):
+ return self._processed_content
+
+
+def main(args):
+ usage = '%prog [OPTIONS] PATH ...'
+ description = (
+ 'Processes PDDM directives in the given paths and write them back out.'
+ )
+ parser = optparse.OptionParser(usage=usage, description=description)
+ parser.add_option('--dry-run',
+ default=False, action='store_true',
+ help='Don\'t write back to the file(s), just report if the'
+ ' contents needs an update and exit with a value of 1.')
+ parser.add_option('--verbose',
+ default=False, action='store_true',
+ help='Reports is a file is already current.')
+ parser.add_option('--collapse',
+ default=False, action='store_true',
+ help='Removes all the generated code.')
+ opts, extra_args = parser.parse_args(args)
+
+ if not extra_args:
+ parser.error('Need atleast one file to process')
+
+ result = 0
+ for a_path in extra_args:
+ if not os.path.exists(a_path):
+ sys.stderr.write('ERROR: File not found: %s\n' % a_path)
+ return 100
+
+ def _ImportResolver(name):
+ # resolve based on the file being read.
+ a_dir = os.path.dirname(a_path)
+ import_path = os.path.join(a_dir, name)
+ if not os.path.exists(import_path):
+ return None
+ return open(import_path, 'r')
+
+ with open(a_path, 'r') as f:
+ src_file = SourceFile(f, _ImportResolver)
+
+ try:
+ src_file.ProcessContent(strip_expansion=opts.collapse)
+ except PDDMError as e:
+ sys.stderr.write('ERROR: %s\n...While processing "%s"\n' %
+ (e.message, a_path))
+ return 101
+
+ if src_file.processed_content != src_file.original_content:
+ if not opts.dry_run:
+ print 'Updating for "%s".' % a_path
+ with open(a_path, 'w') as f:
+ f.write(src_file.processed_content)
+ else:
+ # Special result to indicate things need updating.
+ print 'Update needed for "%s".' % a_path
+ result = 1
+ elif opts.verbose:
+ print 'No update for "%s".' % a_path
+
+ return result
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:]))
diff --git a/third_party/protobuf/objectivec/DevTools/pddm_tests.py b/third_party/protobuf/objectivec/DevTools/pddm_tests.py
new file mode 100755
index 0000000000..8a73b8427b
--- /dev/null
+++ b/third_party/protobuf/objectivec/DevTools/pddm_tests.py
@@ -0,0 +1,515 @@
+#! /usr/bin/python
+#
+# Protocol Buffers - Google's data interchange format
+# Copyright 2015 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.
+
+"""Tests for pddm.py."""
+
+import io
+import unittest
+
+import pddm
+
+
+class TestParsingMacros(unittest.TestCase):
+
+ def testParseEmpty(self):
+ f = io.StringIO(u'')
+ result = pddm.MacroCollection(f)
+ self.assertEqual(len(result._macros), 0)
+
+ def testParseOne(self):
+ f = io.StringIO(u"""PDDM-DEFINE foo( )
+body""")
+ result = pddm.MacroCollection(f)
+ self.assertEqual(len(result._macros), 1)
+ macro = result._macros.get('foo')
+ self.assertIsNotNone(macro)
+ self.assertEquals(macro.name, 'foo')
+ self.assertEquals(macro.args, tuple())
+ self.assertEquals(macro.body, 'body')
+
+ def testParseGeneral(self):
+ # Tests multiple defines, spaces in all places, etc.
+ f = io.StringIO(u"""
+PDDM-DEFINE noArgs( )
+body1
+body2
+
+PDDM-DEFINE-END
+
+PDDM-DEFINE oneArg(foo)
+body3
+PDDM-DEFINE twoArgs( bar_ , baz )
+body4
+body5""")
+ result = pddm.MacroCollection(f)
+ self.assertEqual(len(result._macros), 3)
+ macro = result._macros.get('noArgs')
+ self.assertIsNotNone(macro)
+ self.assertEquals(macro.name, 'noArgs')
+ self.assertEquals(macro.args, tuple())
+ self.assertEquals(macro.body, 'body1\nbody2\n')
+ macro = result._macros.get('oneArg')
+ self.assertIsNotNone(macro)
+ self.assertEquals(macro.name, 'oneArg')
+ self.assertEquals(macro.args, ('foo',))
+ self.assertEquals(macro.body, 'body3')
+ macro = result._macros.get('twoArgs')
+ self.assertIsNotNone(macro)
+ self.assertEquals(macro.name, 'twoArgs')
+ self.assertEquals(macro.args, ('bar_', 'baz'))
+ self.assertEquals(macro.body, 'body4\nbody5')
+ # Add into existing collection
+ f = io.StringIO(u"""
+PDDM-DEFINE another(a,b,c)
+body1
+body2""")
+ result.ParseInput(f)
+ self.assertEqual(len(result._macros), 4)
+ macro = result._macros.get('another')
+ self.assertIsNotNone(macro)
+ self.assertEquals(macro.name, 'another')
+ self.assertEquals(macro.args, ('a', 'b', 'c'))
+ self.assertEquals(macro.body, 'body1\nbody2')
+
+ def testParseDirectiveIssues(self):
+ test_list = [
+ # Unknown directive
+ (u'PDDM-DEFINE foo()\nbody\nPDDM-DEFINED foo\nbaz',
+ 'Hit a line with an unknown directive: '),
+ # End without begin
+ (u'PDDM-DEFINE foo()\nbody\nPDDM-DEFINE-END\nPDDM-DEFINE-END\n',
+ 'Got DEFINE-END directive without an active macro: '),
+ # Line not in macro block
+ (u'PDDM-DEFINE foo()\nbody\nPDDM-DEFINE-END\nmumble\n',
+ 'Hit a line that wasn\'t a directive and no open macro definition: '),
+ # Redefine macro
+ (u'PDDM-DEFINE foo()\nbody\nPDDM-DEFINE foo(a)\nmumble\n',
+ 'Attempt to redefine macro: '),
+ ]
+ for idx, (input_str, expected_prefix) in enumerate(test_list, 1):
+ f = io.StringIO(input_str)
+ try:
+ result = pddm.MacroCollection(f)
+ self.fail('Should throw exception, entry %d' % idx)
+ except pddm.PDDMError as e:
+ self.assertTrue(e.message.startswith(expected_prefix),
+ 'Entry %d failed: %r' % (idx, e))
+
+ def testParseBeginIssues(self):
+ test_list = [
+ # 1. No name
+ (u'PDDM-DEFINE\nmumble',
+ 'Failed to parse macro definition: '),
+ # 2. No name (with spaces)
+ (u'PDDM-DEFINE \nmumble',
+ 'Failed to parse macro definition: '),
+ # 3. No open paren
+ (u'PDDM-DEFINE foo\nmumble',
+ 'Failed to parse macro definition: '),
+ # 4. No close paren
+ (u'PDDM-DEFINE foo(\nmumble',
+ 'Failed to parse macro definition: '),
+ # 5. No close paren (with args)
+ (u'PDDM-DEFINE foo(a, b\nmumble',
+ 'Failed to parse macro definition: '),
+ # 6. No name before args
+ (u'PDDM-DEFINE (a, b)\nmumble',
+ 'Failed to parse macro definition: '),
+ # 7. No name before args
+ (u'PDDM-DEFINE foo bar(a, b)\nmumble',
+ 'Failed to parse macro definition: '),
+ # 8. Empty arg name
+ (u'PDDM-DEFINE foo(a, ,b)\nmumble',
+ 'Empty arg name in macro definition: '),
+ (u'PDDM-DEFINE foo(a,,b)\nmumble',
+ 'Empty arg name in macro definition: '),
+ # 10. Duplicate name
+ (u'PDDM-DEFINE foo(a,b,a,c)\nmumble',
+ 'Arg name "a" used more than once in macro definition: '),
+ # 11. Invalid arg name
+ (u'PDDM-DEFINE foo(a b,c)\nmumble',
+ 'Invalid arg name "a b" in macro definition: '),
+ (u'PDDM-DEFINE foo(a.b,c)\nmumble',
+ 'Invalid arg name "a.b" in macro definition: '),
+ (u'PDDM-DEFINE foo(a-b,c)\nmumble',
+ 'Invalid arg name "a-b" in macro definition: '),
+ (u'PDDM-DEFINE foo(a,b,c.)\nmumble',
+ 'Invalid arg name "c." in macro definition: '),
+ # 15. Extra stuff after the name
+ (u'PDDM-DEFINE foo(a,c) foo\nmumble',
+ 'Failed to parse macro definition: '),
+ (u'PDDM-DEFINE foo(a,c) foo)\nmumble',
+ 'Failed to parse macro definition: '),
+ ]
+ for idx, (input_str, expected_prefix) in enumerate(test_list, 1):
+ f = io.StringIO(input_str)
+ try:
+ result = pddm.MacroCollection(f)
+ self.fail('Should throw exception, entry %d' % idx)
+ except pddm.PDDMError as e:
+ self.assertTrue(e.message.startswith(expected_prefix),
+ 'Entry %d failed: %r' % (idx, e))
+
+
+class TestExpandingMacros(unittest.TestCase):
+
+ def testExpandBasics(self):
+ f = io.StringIO(u"""
+PDDM-DEFINE noArgs( )
+body1
+body2
+
+PDDM-DEFINE-END
+
+PDDM-DEFINE oneArg(a)
+body3 a
+
+PDDM-DEFINE-END
+
+PDDM-DEFINE twoArgs(b,c)
+body4 b c
+body5
+PDDM-DEFINE-END
+
+""")
+ mc = pddm.MacroCollection(f)
+ test_list = [
+ (u'noArgs()',
+ 'body1\nbody2\n'),
+ (u'oneArg(wee)',
+ 'body3 wee\n'),
+ (u'twoArgs(having some, fun)',
+ 'body4 having some fun\nbody5'),
+ # One arg, pass empty.
+ (u'oneArg()',
+ 'body3 \n'),
+ # Two args, gets empty in each slot.
+ (u'twoArgs(, empty)',
+ 'body4 empty\nbody5'),
+ (u'twoArgs(empty, )',
+ 'body4 empty \nbody5'),
+ (u'twoArgs(, )',
+ 'body4 \nbody5'),
+ ]
+ for idx, (input_str, expected) in enumerate(test_list, 1):
+ result = mc.Expand(input_str)
+ self.assertEqual(result, expected,
+ 'Entry %d --\n Result: %r\n Expected: %r' %
+ (idx, result, expected))
+
+ def testExpandArgOptions(self):
+ f = io.StringIO(u"""
+PDDM-DEFINE bar(a)
+a-a$S-a$l-a$L-a$u-a$U
+PDDM-DEFINE-END
+""")
+ mc = pddm.MacroCollection(f)
+
+ self.assertEqual(mc.Expand('bar(xYz)'), 'xYz- -xYz-xyz-XYz-XYZ')
+ self.assertEqual(mc.Expand('bar(MnoP)'), 'MnoP- -mnoP-mnop-MnoP-MNOP')
+ # Test empty
+ self.assertEqual(mc.Expand('bar()'), '-----')
+
+ def testExpandSimpleMacroErrors(self):
+ f = io.StringIO(u"""
+PDDM-DEFINE foo(a, b)
+<a-z>
+PDDM-DEFINE baz(a)
+a - a$z
+""")
+ mc = pddm.MacroCollection(f)
+ test_list = [
+ # 1. Unknown macro
+ (u'bar()',
+ 'No macro named "bar".'),
+ (u'bar(a)',
+ 'No macro named "bar".'),
+ # 3. Arg mismatch
+ (u'foo()',
+ 'Expected 2 args, got: "foo()".'),
+ (u'foo(a b)',
+ 'Expected 2 args, got: "foo(a b)".'),
+ (u'foo(a,b,c)',
+ 'Expected 2 args, got: "foo(a,b,c)".'),
+ # 6. Unknown option in expansion
+ (u'baz(mumble)',
+ 'Unknown arg option "a$z" while expanding "baz(mumble)".'),
+ ]
+ for idx, (input_str, expected_err) in enumerate(test_list, 1):
+ try:
+ result = mc.Expand(input_str)
+ self.fail('Should throw exception, entry %d' % idx)
+ except pddm.PDDMError as e:
+ self.assertEqual(e.message, expected_err,
+ 'Entry %d failed: %r' % (idx, e))
+
+ def testExpandReferences(self):
+ f = io.StringIO(u"""
+PDDM-DEFINE StartIt()
+foo(abc, def)
+foo(ghi, jkl)
+PDDM-DEFINE foo(a, b)
+bar(a, int)
+bar(b, NSString *)
+PDDM-DEFINE bar(n, t)
+- (t)n;
+- (void)set##n$u##:(t)value;
+
+""")
+ mc = pddm.MacroCollection(f)
+ expected = """- (int)abc;
+- (void)setAbc:(int)value;
+
+- (NSString *)def;
+- (void)setDef:(NSString *)value;
+
+- (int)ghi;
+- (void)setGhi:(int)value;
+
+- (NSString *)jkl;
+- (void)setJkl:(NSString *)value;
+"""
+ self.assertEqual(mc.Expand('StartIt()'), expected)
+
+ def testCatchRecursion(self):
+ f = io.StringIO(u"""
+PDDM-DEFINE foo(a, b)
+bar(1, a)
+bar(2, b)
+PDDM-DEFINE bar(x, y)
+foo(x, y)
+""")
+ mc = pddm.MacroCollection(f)
+ try:
+ result = mc.Expand('foo(A,B)')
+ self.fail('Should throw exception, entry %d' % idx)
+ except pddm.PDDMError as e:
+ self.assertEqual(e.message,
+ 'Found macro recusion, invoking "foo(1, A)":\n...while expanding "bar(1, A)".\n...while expanding "foo(A,B)".')
+
+
+class TestParsingSource(unittest.TestCase):
+
+ def testBasicParse(self):
+ test_list = [
+ # 1. no directives
+ (u'a\nb\nc',
+ (3,) ),
+ # 2. One define
+ (u'a\n//%PDDM-DEFINE foo()\n//%body\nc',
+ (1, 2, 1) ),
+ # 3. Two defines
+ (u'a\n//%PDDM-DEFINE foo()\n//%body\n//%PDDM-DEFINE bar()\n//%body2\nc',
+ (1, 4, 1) ),
+ # 4. Two defines with ends
+ (u'a\n//%PDDM-DEFINE foo()\n//%body\n//%PDDM-DEFINE-END\n'
+ u'//%PDDM-DEFINE bar()\n//%body2\n//%PDDM-DEFINE-END\nc',
+ (1, 6, 1) ),
+ # 5. One expand, one define (that runs to end of file)
+ (u'a\n//%PDDM-EXPAND foo()\nbody\n//%PDDM-EXPAND-END\n'
+ u'//%PDDM-DEFINE bar()\n//%body2\n',
+ (1, 1, 2) ),
+ # 6. One define ended with an expand.
+ (u'a\nb\n//%PDDM-DEFINE bar()\n//%body2\n'
+ u'//%PDDM-EXPAND bar()\nbody2\n//%PDDM-EXPAND-END\n',
+ (2, 2, 1) ),
+ # 7. Two expands (one end), one define.
+ (u'a\n//%PDDM-EXPAND foo(1)\nbody\n//%PDDM-EXPAND foo(2)\nbody2\n//%PDDM-EXPAND-END\n'
+ u'//%PDDM-DEFINE foo()\n//%body2\n',
+ (1, 2, 2) ),
+ ]
+ for idx, (input_str, line_counts) in enumerate(test_list, 1):
+ f = io.StringIO(input_str)
+ sf = pddm.SourceFile(f)
+ sf._ParseFile()
+ self.assertEqual(len(sf._sections), len(line_counts),
+ 'Entry %d -- %d != %d' %
+ (idx, len(sf._sections), len(line_counts)))
+ for idx2, (sec, expected) in enumerate(zip(sf._sections, line_counts), 1):
+ self.assertEqual(sec.num_lines_captured, expected,
+ 'Entry %d, section %d -- %d != %d' %
+ (idx, idx2, sec.num_lines_captured, expected))
+
+ def testErrors(self):
+ test_list = [
+ # 1. Directive within expansion
+ (u'//%PDDM-EXPAND a()\n//%PDDM-BOGUS',
+ 'Ran into directive ("//%PDDM-BOGUS", line 2) while in "//%PDDM-EXPAND a()".'),
+ (u'//%PDDM-EXPAND a()\n//%PDDM-DEFINE a()\n//%body\n',
+ 'Ran into directive ("//%PDDM-DEFINE", line 2) while in "//%PDDM-EXPAND a()".'),
+ # 3. Expansion ran off end of file
+ (u'//%PDDM-EXPAND a()\na\nb\n',
+ 'Hit the end of the file while in "//%PDDM-EXPAND a()".'),
+ # 4. Directive within define
+ (u'//%PDDM-DEFINE a()\n//%body\n//%PDDM-BOGUS',
+ 'Ran into directive ("//%PDDM-BOGUS", line 3) while in "//%PDDM-DEFINE a()".'),
+ (u'//%PDDM-DEFINE a()\n//%body\n//%PDDM-EXPAND-END a()',
+ 'Ran into directive ("//%PDDM-EXPAND-END", line 3) while in "//%PDDM-DEFINE a()".'),
+ # 6. Directives that shouldn't start sections
+ (u'a\n//%PDDM-DEFINE-END a()\n//a\n',
+ 'Unexpected line 2: "//%PDDM-DEFINE-END a()".'),
+ (u'a\n//%PDDM-EXPAND-END a()\n//a\n',
+ 'Unexpected line 2: "//%PDDM-EXPAND-END a()".'),
+ (u'//%PDDM-BOGUS\n//a\n',
+ 'Unexpected line 1: "//%PDDM-BOGUS".'),
+ ]
+ for idx, (input_str, expected_err) in enumerate(test_list, 1):
+ f = io.StringIO(input_str)
+ try:
+ pddm.SourceFile(f)._ParseFile()
+ self.fail('Should throw exception, entry %d' % idx)
+ except pddm.PDDMError as e:
+ self.assertEqual(e.message, expected_err,
+ 'Entry %d failed: %r' % (idx, e))
+
+class TestProcessingSource(unittest.TestCase):
+
+ def testBasics(self):
+ input_str = u"""
+//%PDDM-IMPORT-DEFINES ImportFile
+foo
+//%PDDM-EXPAND mumble(abc)
+//%PDDM-EXPAND-END
+bar
+//%PDDM-EXPAND mumble(def)
+//%PDDM-EXPAND mumble(ghi)
+//%PDDM-EXPAND-END
+baz
+//%PDDM-DEFINE mumble(a_)
+//%a_: getName(a_)
+"""
+ input_str2 = u"""
+//%PDDM-DEFINE getName(x_)
+//%do##x_$u##(int x_);
+
+"""
+ expected = u"""
+//%PDDM-IMPORT-DEFINES ImportFile
+foo
+//%PDDM-EXPAND mumble(abc)
+// This block of code is generated, do not edit it directly.
+
+abc: doAbc(int abc);
+//%PDDM-EXPAND-END mumble(abc)
+bar
+//%PDDM-EXPAND mumble(def)
+// This block of code is generated, do not edit it directly.
+
+def: doDef(int def);
+//%PDDM-EXPAND mumble(ghi)
+// This block of code is generated, do not edit it directly.
+
+ghi: doGhi(int ghi);
+//%PDDM-EXPAND-END (2 expansions)
+baz
+//%PDDM-DEFINE mumble(a_)
+//%a_: getName(a_)
+"""
+ expected_stripped = u"""
+//%PDDM-IMPORT-DEFINES ImportFile
+foo
+//%PDDM-EXPAND mumble(abc)
+//%PDDM-EXPAND-END mumble(abc)
+bar
+//%PDDM-EXPAND mumble(def)
+//%PDDM-EXPAND mumble(ghi)
+//%PDDM-EXPAND-END (2 expansions)
+baz
+//%PDDM-DEFINE mumble(a_)
+//%a_: getName(a_)
+"""
+ def _Resolver(name):
+ self.assertEqual(name, 'ImportFile')
+ return io.StringIO(input_str2)
+ f = io.StringIO(input_str)
+ sf = pddm.SourceFile(f, _Resolver)
+ sf.ProcessContent()
+ self.assertEqual(sf.processed_content, expected)
+ # Feed it through and nothing should change.
+ f2 = io.StringIO(sf.processed_content)
+ sf2 = pddm.SourceFile(f2, _Resolver)
+ sf2.ProcessContent()
+ self.assertEqual(sf2.processed_content, expected)
+ self.assertEqual(sf2.processed_content, sf.processed_content)
+ # Test stripping (with the original input and expanded version).
+ f2 = io.StringIO(input_str)
+ sf2 = pddm.SourceFile(f2)
+ sf2.ProcessContent(strip_expansion=True)
+ self.assertEqual(sf2.processed_content, expected_stripped)
+ f2 = io.StringIO(sf.processed_content)
+ sf2 = pddm.SourceFile(f2, _Resolver)
+ sf2.ProcessContent(strip_expansion=True)
+ self.assertEqual(sf2.processed_content, expected_stripped)
+
+ def testProcessFileWithMacroParseError(self):
+ input_str = u"""
+foo
+//%PDDM-DEFINE mumble(a_)
+//%body
+//%PDDM-DEFINE mumble(x_)
+//%body2
+
+"""
+ f = io.StringIO(input_str)
+ sf = pddm.SourceFile(f)
+ try:
+ sf.ProcessContent()
+ self.fail('Should throw exception, entry %d' % idx)
+ except pddm.PDDMError as e:
+ self.assertEqual(e.message,
+ 'Attempt to redefine macro: "PDDM-DEFINE mumble(x_)"\n'
+ '...while parsing section that started:\n'
+ ' Line 3: //%PDDM-DEFINE mumble(a_)')
+
+ def testProcessFileWithExpandError(self):
+ input_str = u"""
+foo
+//%PDDM-DEFINE mumble(a_)
+//%body
+//%PDDM-EXPAND foobar(x_)
+//%PDDM-EXPAND-END
+
+"""
+ f = io.StringIO(input_str)
+ sf = pddm.SourceFile(f)
+ try:
+ sf.ProcessContent()
+ self.fail('Should throw exception, entry %d' % idx)
+ except pddm.PDDMError as e:
+ self.assertEqual(e.message,
+ 'No macro named "foobar".\n'
+ '...while expanding "foobar(x_)" from the section that'
+ ' started:\n Line 5: //%PDDM-EXPAND foobar(x_)')
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/third_party/protobuf/objectivec/GPBArray.h b/third_party/protobuf/objectivec/GPBArray.h
new file mode 100644
index 0000000000..638b2882d3
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBArray.h
@@ -0,0 +1,1967 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBRuntimeTypes.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+//%PDDM-EXPAND DECLARE_ARRAYS()
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Int32
+
+/**
+ * Class used for repeated fields of int32_t values. This performs better than
+ * boxing into NSNumbers in NSArrays.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32Array : NSObject <NSCopying>
+
+/** The number of elements contained in the array. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty GPBInt32Array.
+ **/
++ (instancetype)array;
+
+/**
+ * Creates and initializes a GPBInt32Array with the single element given.
+ *
+ * @param value The value to be placed in the array.
+ *
+ * @return A newly instanced GPBInt32Array with value in it.
+ **/
++ (instancetype)arrayWithValue:(int32_t)value;
+
+/**
+ * Creates and initializes a GPBInt32Array with the contents of the given
+ * array.
+ *
+ * @param array Array with the contents to be put into the new array.
+ *
+ * @return A newly instanced GPBInt32Array with the contents of array.
+ **/
++ (instancetype)arrayWithValueArray:(GPBInt32Array *)array;
+
+/**
+ * Creates and initializes a GPBInt32Array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly instanced GPBInt32Array with a capacity of count.
+ **/
++ (instancetype)arrayWithCapacity:(NSUInteger)count;
+
+/**
+ * @return A newly initialized and empty GPBInt32Array.
+ **/
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param values An array with the values to put inside this array.
+ * @param count The number of elements to copy into the array.
+ *
+ * @return A newly initialized GPBInt32Array with a copy of the values.
+ **/
+- (instancetype)initWithValues:(const int32_t [__nullable])values
+ count:(NSUInteger)count;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param array An array with the values to put inside this array.
+ *
+ * @return A newly initialized GPBInt32Array with a copy of the values.
+ **/
+- (instancetype)initWithValueArray:(GPBInt32Array *)array;
+
+/**
+ * Initializes the array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly initialized GPBInt32Array with a capacity of count.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)count;
+
+/**
+ * Gets the value at the given index.
+ *
+ * @param index The index of the value to get.
+ *
+ * @return The value at the given index.
+ **/
+- (int32_t)valueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Adds a value to this array.
+ *
+ * @param value The value to add to this array.
+ **/
+- (void)addValue:(int32_t)value;
+
+/**
+ * Adds values to this array.
+ *
+ * @param values The values to add to this array.
+ * @param count The number of elements to add.
+ **/
+- (void)addValues:(const int32_t [__nullable])values count:(NSUInteger)count;
+
+/**
+ * Adds the values from the given array to this array.
+ *
+ * @param array The array containing the elements to add to this array.
+ **/
+- (void)addValuesFromArray:(GPBInt32Array *)array;
+
+/**
+ * Inserts a value into the given position.
+ *
+ * @param value The value to add to this array.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertValue:(int32_t)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the value at the given index with the given value.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(int32_t)value;
+
+/**
+ * Removes the value at the given index.
+ *
+ * @param index The index of the value to remove.
+ **/
+- (void)removeValueAtIndex:(NSUInteger)index;
+
+/**
+ * Removes all the values from this array.
+ **/
+- (void)removeAll;
+
+/**
+ * Exchanges the values between the given indexes.
+ *
+ * @param idx1 The index of the first element to exchange.
+ * @param idx2 The index of the second element to exchange.
+ **/
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2;
+
+@end
+
+#pragma mark - UInt32
+
+/**
+ * Class used for repeated fields of uint32_t values. This performs better than
+ * boxing into NSNumbers in NSArrays.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32Array : NSObject <NSCopying>
+
+/** The number of elements contained in the array. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty GPBUInt32Array.
+ **/
++ (instancetype)array;
+
+/**
+ * Creates and initializes a GPBUInt32Array with the single element given.
+ *
+ * @param value The value to be placed in the array.
+ *
+ * @return A newly instanced GPBUInt32Array with value in it.
+ **/
++ (instancetype)arrayWithValue:(uint32_t)value;
+
+/**
+ * Creates and initializes a GPBUInt32Array with the contents of the given
+ * array.
+ *
+ * @param array Array with the contents to be put into the new array.
+ *
+ * @return A newly instanced GPBUInt32Array with the contents of array.
+ **/
++ (instancetype)arrayWithValueArray:(GPBUInt32Array *)array;
+
+/**
+ * Creates and initializes a GPBUInt32Array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly instanced GPBUInt32Array with a capacity of count.
+ **/
++ (instancetype)arrayWithCapacity:(NSUInteger)count;
+
+/**
+ * @return A newly initialized and empty GPBUInt32Array.
+ **/
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param values An array with the values to put inside this array.
+ * @param count The number of elements to copy into the array.
+ *
+ * @return A newly initialized GPBUInt32Array with a copy of the values.
+ **/
+- (instancetype)initWithValues:(const uint32_t [__nullable])values
+ count:(NSUInteger)count;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param array An array with the values to put inside this array.
+ *
+ * @return A newly initialized GPBUInt32Array with a copy of the values.
+ **/
+- (instancetype)initWithValueArray:(GPBUInt32Array *)array;
+
+/**
+ * Initializes the array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly initialized GPBUInt32Array with a capacity of count.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)count;
+
+/**
+ * Gets the value at the given index.
+ *
+ * @param index The index of the value to get.
+ *
+ * @return The value at the given index.
+ **/
+- (uint32_t)valueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithBlock:(void (^)(uint32_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(uint32_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Adds a value to this array.
+ *
+ * @param value The value to add to this array.
+ **/
+- (void)addValue:(uint32_t)value;
+
+/**
+ * Adds values to this array.
+ *
+ * @param values The values to add to this array.
+ * @param count The number of elements to add.
+ **/
+- (void)addValues:(const uint32_t [__nullable])values count:(NSUInteger)count;
+
+/**
+ * Adds the values from the given array to this array.
+ *
+ * @param array The array containing the elements to add to this array.
+ **/
+- (void)addValuesFromArray:(GPBUInt32Array *)array;
+
+/**
+ * Inserts a value into the given position.
+ *
+ * @param value The value to add to this array.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertValue:(uint32_t)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the value at the given index with the given value.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(uint32_t)value;
+
+/**
+ * Removes the value at the given index.
+ *
+ * @param index The index of the value to remove.
+ **/
+- (void)removeValueAtIndex:(NSUInteger)index;
+
+/**
+ * Removes all the values from this array.
+ **/
+- (void)removeAll;
+
+/**
+ * Exchanges the values between the given indexes.
+ *
+ * @param idx1 The index of the first element to exchange.
+ * @param idx2 The index of the second element to exchange.
+ **/
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2;
+
+@end
+
+#pragma mark - Int64
+
+/**
+ * Class used for repeated fields of int64_t values. This performs better than
+ * boxing into NSNumbers in NSArrays.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64Array : NSObject <NSCopying>
+
+/** The number of elements contained in the array. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty GPBInt64Array.
+ **/
++ (instancetype)array;
+
+/**
+ * Creates and initializes a GPBInt64Array with the single element given.
+ *
+ * @param value The value to be placed in the array.
+ *
+ * @return A newly instanced GPBInt64Array with value in it.
+ **/
++ (instancetype)arrayWithValue:(int64_t)value;
+
+/**
+ * Creates and initializes a GPBInt64Array with the contents of the given
+ * array.
+ *
+ * @param array Array with the contents to be put into the new array.
+ *
+ * @return A newly instanced GPBInt64Array with the contents of array.
+ **/
++ (instancetype)arrayWithValueArray:(GPBInt64Array *)array;
+
+/**
+ * Creates and initializes a GPBInt64Array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly instanced GPBInt64Array with a capacity of count.
+ **/
++ (instancetype)arrayWithCapacity:(NSUInteger)count;
+
+/**
+ * @return A newly initialized and empty GPBInt64Array.
+ **/
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param values An array with the values to put inside this array.
+ * @param count The number of elements to copy into the array.
+ *
+ * @return A newly initialized GPBInt64Array with a copy of the values.
+ **/
+- (instancetype)initWithValues:(const int64_t [__nullable])values
+ count:(NSUInteger)count;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param array An array with the values to put inside this array.
+ *
+ * @return A newly initialized GPBInt64Array with a copy of the values.
+ **/
+- (instancetype)initWithValueArray:(GPBInt64Array *)array;
+
+/**
+ * Initializes the array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly initialized GPBInt64Array with a capacity of count.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)count;
+
+/**
+ * Gets the value at the given index.
+ *
+ * @param index The index of the value to get.
+ *
+ * @return The value at the given index.
+ **/
+- (int64_t)valueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithBlock:(void (^)(int64_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(int64_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Adds a value to this array.
+ *
+ * @param value The value to add to this array.
+ **/
+- (void)addValue:(int64_t)value;
+
+/**
+ * Adds values to this array.
+ *
+ * @param values The values to add to this array.
+ * @param count The number of elements to add.
+ **/
+- (void)addValues:(const int64_t [__nullable])values count:(NSUInteger)count;
+
+/**
+ * Adds the values from the given array to this array.
+ *
+ * @param array The array containing the elements to add to this array.
+ **/
+- (void)addValuesFromArray:(GPBInt64Array *)array;
+
+/**
+ * Inserts a value into the given position.
+ *
+ * @param value The value to add to this array.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertValue:(int64_t)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the value at the given index with the given value.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(int64_t)value;
+
+/**
+ * Removes the value at the given index.
+ *
+ * @param index The index of the value to remove.
+ **/
+- (void)removeValueAtIndex:(NSUInteger)index;
+
+/**
+ * Removes all the values from this array.
+ **/
+- (void)removeAll;
+
+/**
+ * Exchanges the values between the given indexes.
+ *
+ * @param idx1 The index of the first element to exchange.
+ * @param idx2 The index of the second element to exchange.
+ **/
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2;
+
+@end
+
+#pragma mark - UInt64
+
+/**
+ * Class used for repeated fields of uint64_t values. This performs better than
+ * boxing into NSNumbers in NSArrays.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64Array : NSObject <NSCopying>
+
+/** The number of elements contained in the array. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty GPBUInt64Array.
+ **/
++ (instancetype)array;
+
+/**
+ * Creates and initializes a GPBUInt64Array with the single element given.
+ *
+ * @param value The value to be placed in the array.
+ *
+ * @return A newly instanced GPBUInt64Array with value in it.
+ **/
++ (instancetype)arrayWithValue:(uint64_t)value;
+
+/**
+ * Creates and initializes a GPBUInt64Array with the contents of the given
+ * array.
+ *
+ * @param array Array with the contents to be put into the new array.
+ *
+ * @return A newly instanced GPBUInt64Array with the contents of array.
+ **/
++ (instancetype)arrayWithValueArray:(GPBUInt64Array *)array;
+
+/**
+ * Creates and initializes a GPBUInt64Array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly instanced GPBUInt64Array with a capacity of count.
+ **/
++ (instancetype)arrayWithCapacity:(NSUInteger)count;
+
+/**
+ * @return A newly initialized and empty GPBUInt64Array.
+ **/
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param values An array with the values to put inside this array.
+ * @param count The number of elements to copy into the array.
+ *
+ * @return A newly initialized GPBUInt64Array with a copy of the values.
+ **/
+- (instancetype)initWithValues:(const uint64_t [__nullable])values
+ count:(NSUInteger)count;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param array An array with the values to put inside this array.
+ *
+ * @return A newly initialized GPBUInt64Array with a copy of the values.
+ **/
+- (instancetype)initWithValueArray:(GPBUInt64Array *)array;
+
+/**
+ * Initializes the array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly initialized GPBUInt64Array with a capacity of count.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)count;
+
+/**
+ * Gets the value at the given index.
+ *
+ * @param index The index of the value to get.
+ *
+ * @return The value at the given index.
+ **/
+- (uint64_t)valueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithBlock:(void (^)(uint64_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(uint64_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Adds a value to this array.
+ *
+ * @param value The value to add to this array.
+ **/
+- (void)addValue:(uint64_t)value;
+
+/**
+ * Adds values to this array.
+ *
+ * @param values The values to add to this array.
+ * @param count The number of elements to add.
+ **/
+- (void)addValues:(const uint64_t [__nullable])values count:(NSUInteger)count;
+
+/**
+ * Adds the values from the given array to this array.
+ *
+ * @param array The array containing the elements to add to this array.
+ **/
+- (void)addValuesFromArray:(GPBUInt64Array *)array;
+
+/**
+ * Inserts a value into the given position.
+ *
+ * @param value The value to add to this array.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertValue:(uint64_t)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the value at the given index with the given value.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(uint64_t)value;
+
+/**
+ * Removes the value at the given index.
+ *
+ * @param index The index of the value to remove.
+ **/
+- (void)removeValueAtIndex:(NSUInteger)index;
+
+/**
+ * Removes all the values from this array.
+ **/
+- (void)removeAll;
+
+/**
+ * Exchanges the values between the given indexes.
+ *
+ * @param idx1 The index of the first element to exchange.
+ * @param idx2 The index of the second element to exchange.
+ **/
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2;
+
+@end
+
+#pragma mark - Float
+
+/**
+ * Class used for repeated fields of float values. This performs better than
+ * boxing into NSNumbers in NSArrays.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBFloatArray : NSObject <NSCopying>
+
+/** The number of elements contained in the array. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty GPBFloatArray.
+ **/
++ (instancetype)array;
+
+/**
+ * Creates and initializes a GPBFloatArray with the single element given.
+ *
+ * @param value The value to be placed in the array.
+ *
+ * @return A newly instanced GPBFloatArray with value in it.
+ **/
++ (instancetype)arrayWithValue:(float)value;
+
+/**
+ * Creates and initializes a GPBFloatArray with the contents of the given
+ * array.
+ *
+ * @param array Array with the contents to be put into the new array.
+ *
+ * @return A newly instanced GPBFloatArray with the contents of array.
+ **/
++ (instancetype)arrayWithValueArray:(GPBFloatArray *)array;
+
+/**
+ * Creates and initializes a GPBFloatArray with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly instanced GPBFloatArray with a capacity of count.
+ **/
++ (instancetype)arrayWithCapacity:(NSUInteger)count;
+
+/**
+ * @return A newly initialized and empty GPBFloatArray.
+ **/
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param values An array with the values to put inside this array.
+ * @param count The number of elements to copy into the array.
+ *
+ * @return A newly initialized GPBFloatArray with a copy of the values.
+ **/
+- (instancetype)initWithValues:(const float [__nullable])values
+ count:(NSUInteger)count;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param array An array with the values to put inside this array.
+ *
+ * @return A newly initialized GPBFloatArray with a copy of the values.
+ **/
+- (instancetype)initWithValueArray:(GPBFloatArray *)array;
+
+/**
+ * Initializes the array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly initialized GPBFloatArray with a capacity of count.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)count;
+
+/**
+ * Gets the value at the given index.
+ *
+ * @param index The index of the value to get.
+ *
+ * @return The value at the given index.
+ **/
+- (float)valueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithBlock:(void (^)(float value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(float value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Adds a value to this array.
+ *
+ * @param value The value to add to this array.
+ **/
+- (void)addValue:(float)value;
+
+/**
+ * Adds values to this array.
+ *
+ * @param values The values to add to this array.
+ * @param count The number of elements to add.
+ **/
+- (void)addValues:(const float [__nullable])values count:(NSUInteger)count;
+
+/**
+ * Adds the values from the given array to this array.
+ *
+ * @param array The array containing the elements to add to this array.
+ **/
+- (void)addValuesFromArray:(GPBFloatArray *)array;
+
+/**
+ * Inserts a value into the given position.
+ *
+ * @param value The value to add to this array.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertValue:(float)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the value at the given index with the given value.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(float)value;
+
+/**
+ * Removes the value at the given index.
+ *
+ * @param index The index of the value to remove.
+ **/
+- (void)removeValueAtIndex:(NSUInteger)index;
+
+/**
+ * Removes all the values from this array.
+ **/
+- (void)removeAll;
+
+/**
+ * Exchanges the values between the given indexes.
+ *
+ * @param idx1 The index of the first element to exchange.
+ * @param idx2 The index of the second element to exchange.
+ **/
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2;
+
+@end
+
+#pragma mark - Double
+
+/**
+ * Class used for repeated fields of double values. This performs better than
+ * boxing into NSNumbers in NSArrays.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBDoubleArray : NSObject <NSCopying>
+
+/** The number of elements contained in the array. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty GPBDoubleArray.
+ **/
++ (instancetype)array;
+
+/**
+ * Creates and initializes a GPBDoubleArray with the single element given.
+ *
+ * @param value The value to be placed in the array.
+ *
+ * @return A newly instanced GPBDoubleArray with value in it.
+ **/
++ (instancetype)arrayWithValue:(double)value;
+
+/**
+ * Creates and initializes a GPBDoubleArray with the contents of the given
+ * array.
+ *
+ * @param array Array with the contents to be put into the new array.
+ *
+ * @return A newly instanced GPBDoubleArray with the contents of array.
+ **/
++ (instancetype)arrayWithValueArray:(GPBDoubleArray *)array;
+
+/**
+ * Creates and initializes a GPBDoubleArray with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly instanced GPBDoubleArray with a capacity of count.
+ **/
++ (instancetype)arrayWithCapacity:(NSUInteger)count;
+
+/**
+ * @return A newly initialized and empty GPBDoubleArray.
+ **/
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param values An array with the values to put inside this array.
+ * @param count The number of elements to copy into the array.
+ *
+ * @return A newly initialized GPBDoubleArray with a copy of the values.
+ **/
+- (instancetype)initWithValues:(const double [__nullable])values
+ count:(NSUInteger)count;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param array An array with the values to put inside this array.
+ *
+ * @return A newly initialized GPBDoubleArray with a copy of the values.
+ **/
+- (instancetype)initWithValueArray:(GPBDoubleArray *)array;
+
+/**
+ * Initializes the array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly initialized GPBDoubleArray with a capacity of count.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)count;
+
+/**
+ * Gets the value at the given index.
+ *
+ * @param index The index of the value to get.
+ *
+ * @return The value at the given index.
+ **/
+- (double)valueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithBlock:(void (^)(double value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(double value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Adds a value to this array.
+ *
+ * @param value The value to add to this array.
+ **/
+- (void)addValue:(double)value;
+
+/**
+ * Adds values to this array.
+ *
+ * @param values The values to add to this array.
+ * @param count The number of elements to add.
+ **/
+- (void)addValues:(const double [__nullable])values count:(NSUInteger)count;
+
+/**
+ * Adds the values from the given array to this array.
+ *
+ * @param array The array containing the elements to add to this array.
+ **/
+- (void)addValuesFromArray:(GPBDoubleArray *)array;
+
+/**
+ * Inserts a value into the given position.
+ *
+ * @param value The value to add to this array.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertValue:(double)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the value at the given index with the given value.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(double)value;
+
+/**
+ * Removes the value at the given index.
+ *
+ * @param index The index of the value to remove.
+ **/
+- (void)removeValueAtIndex:(NSUInteger)index;
+
+/**
+ * Removes all the values from this array.
+ **/
+- (void)removeAll;
+
+/**
+ * Exchanges the values between the given indexes.
+ *
+ * @param idx1 The index of the first element to exchange.
+ * @param idx2 The index of the second element to exchange.
+ **/
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2;
+
+@end
+
+#pragma mark - Bool
+
+/**
+ * Class used for repeated fields of BOOL values. This performs better than
+ * boxing into NSNumbers in NSArrays.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolArray : NSObject <NSCopying>
+
+/** The number of elements contained in the array. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty GPBBoolArray.
+ **/
++ (instancetype)array;
+
+/**
+ * Creates and initializes a GPBBoolArray with the single element given.
+ *
+ * @param value The value to be placed in the array.
+ *
+ * @return A newly instanced GPBBoolArray with value in it.
+ **/
++ (instancetype)arrayWithValue:(BOOL)value;
+
+/**
+ * Creates and initializes a GPBBoolArray with the contents of the given
+ * array.
+ *
+ * @param array Array with the contents to be put into the new array.
+ *
+ * @return A newly instanced GPBBoolArray with the contents of array.
+ **/
++ (instancetype)arrayWithValueArray:(GPBBoolArray *)array;
+
+/**
+ * Creates and initializes a GPBBoolArray with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly instanced GPBBoolArray with a capacity of count.
+ **/
++ (instancetype)arrayWithCapacity:(NSUInteger)count;
+
+/**
+ * @return A newly initialized and empty GPBBoolArray.
+ **/
+- (instancetype)init NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param values An array with the values to put inside this array.
+ * @param count The number of elements to copy into the array.
+ *
+ * @return A newly initialized GPBBoolArray with a copy of the values.
+ **/
+- (instancetype)initWithValues:(const BOOL [__nullable])values
+ count:(NSUInteger)count;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param array An array with the values to put inside this array.
+ *
+ * @return A newly initialized GPBBoolArray with a copy of the values.
+ **/
+- (instancetype)initWithValueArray:(GPBBoolArray *)array;
+
+/**
+ * Initializes the array with the given capacity.
+ *
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly initialized GPBBoolArray with a capacity of count.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)count;
+
+/**
+ * Gets the value at the given index.
+ *
+ * @param index The index of the value to get.
+ *
+ * @return The value at the given index.
+ **/
+- (BOOL)valueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithBlock:(void (^)(BOOL value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(BOOL value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Adds a value to this array.
+ *
+ * @param value The value to add to this array.
+ **/
+- (void)addValue:(BOOL)value;
+
+/**
+ * Adds values to this array.
+ *
+ * @param values The values to add to this array.
+ * @param count The number of elements to add.
+ **/
+- (void)addValues:(const BOOL [__nullable])values count:(NSUInteger)count;
+
+/**
+ * Adds the values from the given array to this array.
+ *
+ * @param array The array containing the elements to add to this array.
+ **/
+- (void)addValuesFromArray:(GPBBoolArray *)array;
+
+/**
+ * Inserts a value into the given position.
+ *
+ * @param value The value to add to this array.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertValue:(BOOL)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the value at the given index with the given value.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(BOOL)value;
+
+/**
+ * Removes the value at the given index.
+ *
+ * @param index The index of the value to remove.
+ **/
+- (void)removeValueAtIndex:(NSUInteger)index;
+
+/**
+ * Removes all the values from this array.
+ **/
+- (void)removeAll;
+
+/**
+ * Exchanges the values between the given indexes.
+ *
+ * @param idx1 The index of the first element to exchange.
+ * @param idx2 The index of the second element to exchange.
+ **/
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2;
+
+@end
+
+#pragma mark - Enum
+
+/**
+ * This class is used for repeated fields of int32_t values. This performs
+ * better than boxing into NSNumbers in NSArrays.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBEnumArray : NSObject <NSCopying>
+
+/** The number of elements contained in the array. */
+@property(nonatomic, readonly) NSUInteger count;
+/** The validation function to check if the enums are valid. */
+@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+
+/**
+ * @return A newly instanced and empty GPBEnumArray.
+ **/
++ (instancetype)array;
+
+/**
+ * Creates and initializes a GPBEnumArray with the enum validation function
+ * given.
+ *
+ * @param func The enum validation function for the array.
+ *
+ * @return A newly instanced GPBEnumArray.
+ **/
++ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Creates and initializes a GPBEnumArray with the enum validation function
+ * given and the single raw value given.
+ *
+ * @param func The enum validation function for the array.
+ * @param value The raw value to add to this array.
+ *
+ * @return A newly instanced GPBEnumArray.
+ **/
++ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValue:(int32_t)value;
+
+/**
+ * Creates and initializes a GPBEnumArray that adds the elements from the
+ * given array.
+ *
+ * @param array Array containing the values to add to the new array.
+ *
+ * @return A newly instanced GPBEnumArray.
+ **/
++ (instancetype)arrayWithValueArray:(GPBEnumArray *)array;
+
+/**
+ * Creates and initializes a GPBEnumArray with the given enum validation
+ * function and with the givencapacity.
+ *
+ * @param func The enum validation function for the array.
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly instanced GPBEnumArray with a capacity of count.
+ **/
++ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)count;
+
+/**
+ * Initializes the array with the given enum validation function.
+ *
+ * @param func The enum validation function for the array.
+ *
+ * @return A newly initialized GPBEnumArray with a copy of the values.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param func The enum validation function for the array.
+ * @param values An array with the values to put inside this array.
+ * @param count The number of elements to copy into the array.
+ *
+ * @return A newly initialized GPBEnumArray with a copy of the values.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ count:(NSUInteger)count;
+
+/**
+ * Initializes the array, copying the given values.
+ *
+ * @param array An array with the values to put inside this array.
+ *
+ * @return A newly initialized GPBEnumArray with a copy of the values.
+ **/
+- (instancetype)initWithValueArray:(GPBEnumArray *)array;
+
+/**
+ * Initializes the array with the given capacity.
+ *
+ * @param func The enum validation function for the array.
+ * @param count The capacity needed for the array.
+ *
+ * @return A newly initialized GPBEnumArray with a capacity of count.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)count;
+
+// These will return kGPBUnrecognizedEnumeratorValue if the value at index is not a
+// valid enumerator as defined by validationFunc. If the actual value is
+// desired, use "raw" version of the method.
+
+/**
+ * Gets the value at the given index.
+ *
+ * @param index The index of the value to get.
+ *
+ * @return The value at the given index.
+ **/
+- (int32_t)valueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block;
+
+// These methods bypass the validationFunc to provide access to values that were not
+// known at the time the binary was compiled.
+
+/**
+ * Gets the raw enum value at the given index.
+ *
+ * @param index The index of the raw enum value to get.
+ *
+ * @return The raw enum value at the given index.
+ **/
+- (int32_t)rawValueAtIndex:(NSUInteger)index;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateRawValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block;
+
+/**
+ * Enumerates the values on this array with the given block.
+ *
+ * @param opts Options to control the enumeration.
+ * @param block The block to enumerate with.
+ * **value**: The current value being enumerated.
+ * **idx**: The index of the current value.
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateRawValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block;
+
+// If value is not a valid enumerator as defined by validationFunc, these
+// methods will assert in debug, and will log in release and assign the value
+// to the default value. Use the rawValue methods below to assign non enumerator
+// values.
+
+/**
+ * Adds a value to this array.
+ *
+ * @param value The value to add to this array.
+ **/
+- (void)addValue:(int32_t)value;
+
+/**
+ * Adds values to this array.
+ *
+ * @param values The values to add to this array.
+ * @param count The number of elements to add.
+ **/
+- (void)addValues:(const int32_t [__nullable])values count:(NSUInteger)count;
+
+
+/**
+ * Inserts a value into the given position.
+ *
+ * @param value The value to add to this array.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertValue:(int32_t)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the value at the given index with the given value.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(int32_t)value;
+
+// These methods bypass the validationFunc to provide setting of values that were not
+// known at the time the binary was compiled.
+
+/**
+ * Adds a raw enum value to this array.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param value The raw enum value to add to the array.
+ **/
+- (void)addRawValue:(int32_t)value;
+
+/**
+ * Adds raw enum values to this array.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param array Array containing the raw enum values to add to this array.
+ **/
+- (void)addRawValuesFromArray:(GPBEnumArray *)array;
+
+/**
+ * Adds raw enum values to this array.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param values Array containing the raw enum values to add to this array.
+ * @param count The number of raw values to add.
+ **/
+- (void)addRawValues:(const int32_t [__nullable])values count:(NSUInteger)count;
+
+/**
+ * Inserts a raw enum value at the given index.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param value Raw enum value to add.
+ * @param index The index into which to insert the value.
+ **/
+- (void)insertRawValue:(int32_t)value atIndex:(NSUInteger)index;
+
+/**
+ * Replaces the raw enum value at the given index with the given value.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param index The index for which to replace the value.
+ * @param value The raw enum value to replace with.
+ **/
+- (void)replaceValueAtIndex:(NSUInteger)index withRawValue:(int32_t)value;
+
+// No validation applies to these methods.
+
+/**
+ * Removes the value at the given index.
+ *
+ * @param index The index of the value to remove.
+ **/
+- (void)removeValueAtIndex:(NSUInteger)index;
+
+/**
+ * Removes all the values from this array.
+ **/
+- (void)removeAll;
+
+/**
+ * Exchanges the values between the given indexes.
+ *
+ * @param idx1 The index of the first element to exchange.
+ * @param idx2 The index of the second element to exchange.
+ **/
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2;
+
+@end
+
+//%PDDM-EXPAND-END DECLARE_ARRAYS()
+
+NS_ASSUME_NONNULL_END
+
+//%PDDM-DEFINE DECLARE_ARRAYS()
+//%ARRAY_INTERFACE_SIMPLE(Int32, int32_t)
+//%ARRAY_INTERFACE_SIMPLE(UInt32, uint32_t)
+//%ARRAY_INTERFACE_SIMPLE(Int64, int64_t)
+//%ARRAY_INTERFACE_SIMPLE(UInt64, uint64_t)
+//%ARRAY_INTERFACE_SIMPLE(Float, float)
+//%ARRAY_INTERFACE_SIMPLE(Double, double)
+//%ARRAY_INTERFACE_SIMPLE(Bool, BOOL)
+//%ARRAY_INTERFACE_ENUM(Enum, int32_t)
+
+//
+// The common case (everything but Enum)
+//
+
+//%PDDM-DEFINE ARRAY_INTERFACE_SIMPLE(NAME, TYPE)
+//%#pragma mark - NAME
+//%
+//%/**
+//% * Class used for repeated fields of ##TYPE## values. This performs better than
+//% * boxing into NSNumbers in NSArrays.
+//% *
+//% * @note This class is not meant to be subclassed.
+//% **/
+//%@interface GPB##NAME##Array : NSObject <NSCopying>
+//%
+//%/** The number of elements contained in the array. */
+//%@property(nonatomic, readonly) NSUInteger count;
+//%
+//%/**
+//% * @return A newly instanced and empty GPB##NAME##Array.
+//% **/
+//%+ (instancetype)array;
+//%
+//%/**
+//% * Creates and initializes a GPB##NAME##Array with the single element given.
+//% *
+//% * @param value The value to be placed in the array.
+//% *
+//% * @return A newly instanced GPB##NAME##Array with value in it.
+//% **/
+//%+ (instancetype)arrayWithValue:(TYPE)value;
+//%
+//%/**
+//% * Creates and initializes a GPB##NAME##Array with the contents of the given
+//% * array.
+//% *
+//% * @param array Array with the contents to be put into the new array.
+//% *
+//% * @return A newly instanced GPB##NAME##Array with the contents of array.
+//% **/
+//%+ (instancetype)arrayWithValueArray:(GPB##NAME##Array *)array;
+//%
+//%/**
+//% * Creates and initializes a GPB##NAME##Array with the given capacity.
+//% *
+//% * @param count The capacity needed for the array.
+//% *
+//% * @return A newly instanced GPB##NAME##Array with a capacity of count.
+//% **/
+//%+ (instancetype)arrayWithCapacity:(NSUInteger)count;
+//%
+//%/**
+//% * @return A newly initialized and empty GPB##NAME##Array.
+//% **/
+//%- (instancetype)init NS_DESIGNATED_INITIALIZER;
+//%
+//%/**
+//% * Initializes the array, copying the given values.
+//% *
+//% * @param values An array with the values to put inside this array.
+//% * @param count The number of elements to copy into the array.
+//% *
+//% * @return A newly initialized GPB##NAME##Array with a copy of the values.
+//% **/
+//%- (instancetype)initWithValues:(const TYPE [__nullable])values
+//% count:(NSUInteger)count;
+//%
+//%/**
+//% * Initializes the array, copying the given values.
+//% *
+//% * @param array An array with the values to put inside this array.
+//% *
+//% * @return A newly initialized GPB##NAME##Array with a copy of the values.
+//% **/
+//%- (instancetype)initWithValueArray:(GPB##NAME##Array *)array;
+//%
+//%/**
+//% * Initializes the array with the given capacity.
+//% *
+//% * @param count The capacity needed for the array.
+//% *
+//% * @return A newly initialized GPB##NAME##Array with a capacity of count.
+//% **/
+//%- (instancetype)initWithCapacity:(NSUInteger)count;
+//%
+//%ARRAY_IMMUTABLE_INTERFACE(NAME, TYPE, Basic)
+//%
+//%ARRAY_MUTABLE_INTERFACE(NAME, TYPE, Basic)
+//%
+//%@end
+//%
+
+//
+// Macros specific to Enums (to tweak their interface).
+//
+
+//%PDDM-DEFINE ARRAY_INTERFACE_ENUM(NAME, TYPE)
+//%#pragma mark - NAME
+//%
+//%/**
+//% * This class is used for repeated fields of ##TYPE## values. This performs
+//% * better than boxing into NSNumbers in NSArrays.
+//% *
+//% * @note This class is not meant to be subclassed.
+//% **/
+//%@interface GPB##NAME##Array : NSObject <NSCopying>
+//%
+//%/** The number of elements contained in the array. */
+//%@property(nonatomic, readonly) NSUInteger count;
+//%/** The validation function to check if the enums are valid. */
+//%@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+//%
+//%/**
+//% * @return A newly instanced and empty GPB##NAME##Array.
+//% **/
+//%+ (instancetype)array;
+//%
+//%/**
+//% * Creates and initializes a GPB##NAME##Array with the enum validation function
+//% * given.
+//% *
+//% * @param func The enum validation function for the array.
+//% *
+//% * @return A newly instanced GPB##NAME##Array.
+//% **/
+//%+ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+//%
+//%/**
+//% * Creates and initializes a GPB##NAME##Array with the enum validation function
+//% * given and the single raw value given.
+//% *
+//% * @param func The enum validation function for the array.
+//% * @param value The raw value to add to this array.
+//% *
+//% * @return A newly instanced GPB##NAME##Array.
+//% **/
+//%+ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% rawValue:(TYPE)value;
+//%
+//%/**
+//% * Creates and initializes a GPB##NAME##Array that adds the elements from the
+//% * given array.
+//% *
+//% * @param array Array containing the values to add to the new array.
+//% *
+//% * @return A newly instanced GPB##NAME##Array.
+//% **/
+//%+ (instancetype)arrayWithValueArray:(GPB##NAME##Array *)array;
+//%
+//%/**
+//% * Creates and initializes a GPB##NAME##Array with the given enum validation
+//% * function and with the givencapacity.
+//% *
+//% * @param func The enum validation function for the array.
+//% * @param count The capacity needed for the array.
+//% *
+//% * @return A newly instanced GPB##NAME##Array with a capacity of count.
+//% **/
+//%+ (instancetype)arrayWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% capacity:(NSUInteger)count;
+//%
+//%/**
+//% * Initializes the array with the given enum validation function.
+//% *
+//% * @param func The enum validation function for the array.
+//% *
+//% * @return A newly initialized GPB##NAME##Array with a copy of the values.
+//% **/
+//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% NS_DESIGNATED_INITIALIZER;
+//%
+//%/**
+//% * Initializes the array, copying the given values.
+//% *
+//% * @param func The enum validation function for the array.
+//% * @param values An array with the values to put inside this array.
+//% * @param count The number of elements to copy into the array.
+//% *
+//% * @return A newly initialized GPB##NAME##Array with a copy of the values.
+//% **/
+//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% rawValues:(const TYPE [__nullable])values
+//% count:(NSUInteger)count;
+//%
+//%/**
+//% * Initializes the array, copying the given values.
+//% *
+//% * @param array An array with the values to put inside this array.
+//% *
+//% * @return A newly initialized GPB##NAME##Array with a copy of the values.
+//% **/
+//%- (instancetype)initWithValueArray:(GPB##NAME##Array *)array;
+//%
+//%/**
+//% * Initializes the array with the given capacity.
+//% *
+//% * @param func The enum validation function for the array.
+//% * @param count The capacity needed for the array.
+//% *
+//% * @return A newly initialized GPB##NAME##Array with a capacity of count.
+//% **/
+//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% capacity:(NSUInteger)count;
+//%
+//%// These will return kGPBUnrecognizedEnumeratorValue if the value at index is not a
+//%// valid enumerator as defined by validationFunc. If the actual value is
+//%// desired, use "raw" version of the method.
+//%
+//%ARRAY_IMMUTABLE_INTERFACE(NAME, TYPE, NAME)
+//%
+//%// These methods bypass the validationFunc to provide access to values that were not
+//%// known at the time the binary was compiled.
+//%
+//%/**
+//% * Gets the raw enum value at the given index.
+//% *
+//% * @param index The index of the raw enum value to get.
+//% *
+//% * @return The raw enum value at the given index.
+//% **/
+//%- (TYPE)rawValueAtIndex:(NSUInteger)index;
+//%
+//%/**
+//% * Enumerates the values on this array with the given block.
+//% *
+//% * @param block The block to enumerate with.
+//% * **value**: The current value being enumerated.
+//% * **idx**: The index of the current value.
+//% * **stop**: A pointer to a boolean that when set stops the enumeration.
+//% **/
+//%- (void)enumerateRawValuesWithBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block;
+//%
+//%/**
+//% * Enumerates the values on this array with the given block.
+//% *
+//% * @param opts Options to control the enumeration.
+//% * @param block The block to enumerate with.
+//% * **value**: The current value being enumerated.
+//% * **idx**: The index of the current value.
+//% * **stop**: A pointer to a boolean that when set stops the enumeration.
+//% **/
+//%- (void)enumerateRawValuesWithOptions:(NSEnumerationOptions)opts
+//% usingBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block;
+//%
+//%// If value is not a valid enumerator as defined by validationFunc, these
+//%// methods will assert in debug, and will log in release and assign the value
+//%// to the default value. Use the rawValue methods below to assign non enumerator
+//%// values.
+//%
+//%ARRAY_MUTABLE_INTERFACE(NAME, TYPE, NAME)
+//%
+//%@end
+//%
+
+//%PDDM-DEFINE ARRAY_IMMUTABLE_INTERFACE(NAME, TYPE, HELPER_NAME)
+//%/**
+//% * Gets the value at the given index.
+//% *
+//% * @param index The index of the value to get.
+//% *
+//% * @return The value at the given index.
+//% **/
+//%- (TYPE)valueAtIndex:(NSUInteger)index;
+//%
+//%/**
+//% * Enumerates the values on this array with the given block.
+//% *
+//% * @param block The block to enumerate with.
+//% * **value**: The current value being enumerated.
+//% * **idx**: The index of the current value.
+//% * **stop**: A pointer to a boolean that when set stops the enumeration.
+//% **/
+//%- (void)enumerateValuesWithBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block;
+//%
+//%/**
+//% * Enumerates the values on this array with the given block.
+//% *
+//% * @param opts Options to control the enumeration.
+//% * @param block The block to enumerate with.
+//% * **value**: The current value being enumerated.
+//% * **idx**: The index of the current value.
+//% * **stop**: A pointer to a boolean that when set stops the enumeration.
+//% **/
+//%- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+//% usingBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block;
+
+//%PDDM-DEFINE ARRAY_MUTABLE_INTERFACE(NAME, TYPE, HELPER_NAME)
+//%/**
+//% * Adds a value to this array.
+//% *
+//% * @param value The value to add to this array.
+//% **/
+//%- (void)addValue:(TYPE)value;
+//%
+//%/**
+//% * Adds values to this array.
+//% *
+//% * @param values The values to add to this array.
+//% * @param count The number of elements to add.
+//% **/
+//%- (void)addValues:(const TYPE [__nullable])values count:(NSUInteger)count;
+//%
+//%ARRAY_EXTRA_MUTABLE_METHODS1_##HELPER_NAME(NAME, TYPE)
+//%/**
+//% * Inserts a value into the given position.
+//% *
+//% * @param value The value to add to this array.
+//% * @param index The index into which to insert the value.
+//% **/
+//%- (void)insertValue:(TYPE)value atIndex:(NSUInteger)index;
+//%
+//%/**
+//% * Replaces the value at the given index with the given value.
+//% *
+//% * @param index The index for which to replace the value.
+//% * @param value The value to replace with.
+//% **/
+//%- (void)replaceValueAtIndex:(NSUInteger)index withValue:(TYPE)value;
+//%ARRAY_EXTRA_MUTABLE_METHODS2_##HELPER_NAME(NAME, TYPE)
+//%/**
+//% * Removes the value at the given index.
+//% *
+//% * @param index The index of the value to remove.
+//% **/
+//%- (void)removeValueAtIndex:(NSUInteger)index;
+//%
+//%/**
+//% * Removes all the values from this array.
+//% **/
+//%- (void)removeAll;
+//%
+//%/**
+//% * Exchanges the values between the given indexes.
+//% *
+//% * @param idx1 The index of the first element to exchange.
+//% * @param idx2 The index of the second element to exchange.
+//% **/
+//%- (void)exchangeValueAtIndex:(NSUInteger)idx1
+//% withValueAtIndex:(NSUInteger)idx2;
+
+//
+// These are hooks invoked by the above to do insert as needed.
+//
+
+//%PDDM-DEFINE ARRAY_EXTRA_MUTABLE_METHODS1_Basic(NAME, TYPE)
+//%/**
+//% * Adds the values from the given array to this array.
+//% *
+//% * @param array The array containing the elements to add to this array.
+//% **/
+//%- (void)addValuesFromArray:(GPB##NAME##Array *)array;
+//%
+//%PDDM-DEFINE ARRAY_EXTRA_MUTABLE_METHODS2_Basic(NAME, TYPE)
+// Empty
+//%PDDM-DEFINE ARRAY_EXTRA_MUTABLE_METHODS1_Enum(NAME, TYPE)
+// Empty
+//%PDDM-DEFINE ARRAY_EXTRA_MUTABLE_METHODS2_Enum(NAME, TYPE)
+//%
+//%// These methods bypass the validationFunc to provide setting of values that were not
+//%// known at the time the binary was compiled.
+//%
+//%/**
+//% * Adds a raw enum value to this array.
+//% *
+//% * @note This method bypass the validationFunc to enable the setting of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param value The raw enum value to add to the array.
+//% **/
+//%- (void)addRawValue:(TYPE)value;
+//%
+//%/**
+//% * Adds raw enum values to this array.
+//% *
+//% * @note This method bypass the validationFunc to enable the setting of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param array Array containing the raw enum values to add to this array.
+//% **/
+//%- (void)addRawValuesFromArray:(GPB##NAME##Array *)array;
+//%
+//%/**
+//% * Adds raw enum values to this array.
+//% *
+//% * @note This method bypass the validationFunc to enable the setting of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param values Array containing the raw enum values to add to this array.
+//% * @param count The number of raw values to add.
+//% **/
+//%- (void)addRawValues:(const TYPE [__nullable])values count:(NSUInteger)count;
+//%
+//%/**
+//% * Inserts a raw enum value at the given index.
+//% *
+//% * @note This method bypass the validationFunc to enable the setting of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param value Raw enum value to add.
+//% * @param index The index into which to insert the value.
+//% **/
+//%- (void)insertRawValue:(TYPE)value atIndex:(NSUInteger)index;
+//%
+//%/**
+//% * Replaces the raw enum value at the given index with the given value.
+//% *
+//% * @note This method bypass the validationFunc to enable the setting of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param index The index for which to replace the value.
+//% * @param value The raw enum value to replace with.
+//% **/
+//%- (void)replaceValueAtIndex:(NSUInteger)index withRawValue:(TYPE)value;
+//%
+//%// No validation applies to these methods.
+//%
diff --git a/third_party/protobuf/objectivec/GPBArray.m b/third_party/protobuf/objectivec/GPBArray.m
new file mode 100644
index 0000000000..f401631d12
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBArray.m
@@ -0,0 +1,2551 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBArray_PackagePrivate.h"
+
+#import "GPBMessage_PackagePrivate.h"
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+// Mutable arrays use an internal buffer that can always hold a multiple of this elements.
+#define kChunkSize 16
+#define CapacityFromCount(x) (((x / kChunkSize) + 1) * kChunkSize)
+
+static BOOL ArrayDefault_IsValidValue(int32_t value) {
+ // Anything but the bad value marker is allowed.
+ return (value != kGPBUnrecognizedEnumeratorValue);
+}
+
+//%PDDM-DEFINE VALIDATE_RANGE(INDEX, COUNT)
+//% if (INDEX >= COUNT) {
+//% [NSException raise:NSRangeException
+//% format:@"Index (%lu) beyond bounds (%lu)",
+//% (unsigned long)INDEX, (unsigned long)COUNT];
+//% }
+//%PDDM-DEFINE MAYBE_GROW_TO_SET_COUNT(NEW_COUNT)
+//% if (NEW_COUNT > _capacity) {
+//% [self internalResizeToCapacity:CapacityFromCount(NEW_COUNT)];
+//% }
+//% _count = NEW_COUNT;
+//%PDDM-DEFINE SET_COUNT_AND_MAYBE_SHRINK(NEW_COUNT)
+//% _count = NEW_COUNT;
+//% if ((NEW_COUNT + (2 * kChunkSize)) < _capacity) {
+//% [self internalResizeToCapacity:CapacityFromCount(NEW_COUNT)];
+//% }
+
+//
+// Macros for the common basic cases.
+//
+
+//%PDDM-DEFINE ARRAY_INTERFACE_SIMPLE(NAME, TYPE, FORMAT)
+//%#pragma mark - NAME
+//%
+//%@implementation GPB##NAME##Array {
+//% @package
+//% TYPE *_values;
+//% NSUInteger _count;
+//% NSUInteger _capacity;
+//%}
+//%
+//%@synthesize count = _count;
+//%
+//%+ (instancetype)array {
+//% return [[[self alloc] init] autorelease];
+//%}
+//%
+//%+ (instancetype)arrayWithValue:(TYPE)value {
+//% // Cast is needed so the compiler knows what class we are invoking initWithValues: on to get
+//% // the type correct.
+//% return [[(GPB##NAME##Array*)[self alloc] initWithValues:&value count:1] autorelease];
+//%}
+//%
+//%+ (instancetype)arrayWithValueArray:(GPB##NAME##Array *)array {
+//% return [[(GPB##NAME##Array*)[self alloc] initWithValueArray:array] autorelease];
+//%}
+//%
+//%+ (instancetype)arrayWithCapacity:(NSUInteger)count {
+//% return [[[self alloc] initWithCapacity:count] autorelease];
+//%}
+//%
+//%- (instancetype)init {
+//% self = [super init];
+//% // No work needed;
+//% return self;
+//%}
+//%
+//%- (instancetype)initWithValueArray:(GPB##NAME##Array *)array {
+//% return [self initWithValues:array->_values count:array->_count];
+//%}
+//%
+//%- (instancetype)initWithValues:(const TYPE [])values count:(NSUInteger)count {
+//% self = [self init];
+//% if (self) {
+//% if (count && values) {
+//% _values = reallocf(_values, count * sizeof(TYPE));
+//% if (_values != NULL) {
+//% _capacity = count;
+//% memcpy(_values, values, count * sizeof(TYPE));
+//% _count = count;
+//% } else {
+//% [self release];
+//% [NSException raise:NSMallocException
+//% format:@"Failed to allocate %lu bytes",
+//% (unsigned long)(count * sizeof(TYPE))];
+//% }
+//% }
+//% }
+//% return self;
+//%}
+//%
+//%- (instancetype)initWithCapacity:(NSUInteger)count {
+//% self = [self initWithValues:NULL count:0];
+//% if (self && count) {
+//% [self internalResizeToCapacity:count];
+//% }
+//% return self;
+//%}
+//%
+//%- (instancetype)copyWithZone:(NSZone *)zone {
+//% return [[GPB##NAME##Array allocWithZone:zone] initWithValues:_values count:_count];
+//%}
+//%
+//%ARRAY_IMMUTABLE_CORE(NAME, TYPE, , FORMAT)
+//%
+//%- (TYPE)valueAtIndex:(NSUInteger)index {
+//%VALIDATE_RANGE(index, _count)
+//% return _values[index];
+//%}
+//%
+//%ARRAY_MUTABLE_CORE(NAME, TYPE, , FORMAT)
+//%@end
+//%
+
+//
+// Some core macros used for both the simple types and Enums.
+//
+
+//%PDDM-DEFINE ARRAY_IMMUTABLE_CORE(NAME, TYPE, ACCESSOR_NAME, FORMAT)
+//%- (void)dealloc {
+//% NSAssert(!_autocreator,
+//% @"%@: Autocreator must be cleared before release, autocreator: %@",
+//% [self class], _autocreator);
+//% free(_values);
+//% [super dealloc];
+//%}
+//%
+//%- (BOOL)isEqual:(id)other {
+//% if (self == other) {
+//% return YES;
+//% }
+//% if (![other isKindOfClass:[GPB##NAME##Array class]]) {
+//% return NO;
+//% }
+//% GPB##NAME##Array *otherArray = other;
+//% return (_count == otherArray->_count
+//% && memcmp(_values, otherArray->_values, (_count * sizeof(TYPE))) == 0);
+//%}
+//%
+//%- (NSUInteger)hash {
+//% // Follow NSArray's lead, and use the count as the hash.
+//% return _count;
+//%}
+//%
+//%- (NSString *)description {
+//% NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+//% for (NSUInteger i = 0, count = _count; i < count; ++i) {
+//% if (i == 0) {
+//% [result appendFormat:@"##FORMAT##", _values[i]];
+//% } else {
+//% [result appendFormat:@", ##FORMAT##", _values[i]];
+//% }
+//% }
+//% [result appendFormat:@" }"];
+//% return result;
+//%}
+//%
+//%- (void)enumerate##ACCESSOR_NAME##ValuesWithBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block {
+//% [self enumerate##ACCESSOR_NAME##ValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+//%}
+//%
+//%- (void)enumerate##ACCESSOR_NAME##ValuesWithOptions:(NSEnumerationOptions)opts
+//% ACCESSOR_NAME$S usingBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block {
+//% // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+//% BOOL stop = NO;
+//% if ((opts & NSEnumerationReverse) == 0) {
+//% for (NSUInteger i = 0, count = _count; i < count; ++i) {
+//% block(_values[i], i, &stop);
+//% if (stop) break;
+//% }
+//% } else if (_count > 0) {
+//% for (NSUInteger i = _count; i > 0; --i) {
+//% block(_values[i - 1], (i - 1), &stop);
+//% if (stop) break;
+//% }
+//% }
+//%}
+
+//%PDDM-DEFINE MUTATION_HOOK_None()
+//%PDDM-DEFINE MUTATION_METHODS(NAME, TYPE, ACCESSOR_NAME, HOOK_1, HOOK_2)
+//%- (void)add##ACCESSOR_NAME##Value:(TYPE)value {
+//% [self add##ACCESSOR_NAME##Values:&value count:1];
+//%}
+//%
+//%- (void)add##ACCESSOR_NAME##Values:(const TYPE [])values count:(NSUInteger)count {
+//% if (values == NULL || count == 0) return;
+//%MUTATION_HOOK_##HOOK_1() NSUInteger initialCount = _count;
+//% NSUInteger newCount = initialCount + count;
+//%MAYBE_GROW_TO_SET_COUNT(newCount)
+//% memcpy(&_values[initialCount], values, count * sizeof(TYPE));
+//% if (_autocreator) {
+//% GPBAutocreatedArrayModified(_autocreator, self);
+//% }
+//%}
+//%
+//%- (void)insert##ACCESSOR_NAME##Value:(TYPE)value atIndex:(NSUInteger)index {
+//%VALIDATE_RANGE(index, _count + 1)
+//%MUTATION_HOOK_##HOOK_2() NSUInteger initialCount = _count;
+//% NSUInteger newCount = initialCount + 1;
+//%MAYBE_GROW_TO_SET_COUNT(newCount)
+//% if (index != initialCount) {
+//% memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(TYPE));
+//% }
+//% _values[index] = value;
+//% if (_autocreator) {
+//% GPBAutocreatedArrayModified(_autocreator, self);
+//% }
+//%}
+//%
+//%- (void)replaceValueAtIndex:(NSUInteger)index with##ACCESSOR_NAME##Value:(TYPE)value {
+//%VALIDATE_RANGE(index, _count)
+//%MUTATION_HOOK_##HOOK_2() _values[index] = value;
+//%}
+
+//%PDDM-DEFINE ARRAY_MUTABLE_CORE(NAME, TYPE, ACCESSOR_NAME, FORMAT)
+//%- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+//% _values = reallocf(_values, newCapacity * sizeof(TYPE));
+//% if (_values == NULL) {
+//% _capacity = 0;
+//% _count = 0;
+//% [NSException raise:NSMallocException
+//% format:@"Failed to allocate %lu bytes",
+//% (unsigned long)(newCapacity * sizeof(TYPE))];
+//% }
+//% _capacity = newCapacity;
+//%}
+//%
+//%MUTATION_METHODS(NAME, TYPE, ACCESSOR_NAME, None, None)
+//%
+//%- (void)add##ACCESSOR_NAME##ValuesFromArray:(GPB##NAME##Array *)array {
+//% [self add##ACCESSOR_NAME##Values:array->_values count:array->_count];
+//%}
+//%
+//%- (void)removeValueAtIndex:(NSUInteger)index {
+//%VALIDATE_RANGE(index, _count)
+//% NSUInteger newCount = _count - 1;
+//% if (index != newCount) {
+//% memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(TYPE));
+//% }
+//%SET_COUNT_AND_MAYBE_SHRINK(newCount)
+//%}
+//%
+//%- (void)removeAll {
+//%SET_COUNT_AND_MAYBE_SHRINK(0)
+//%}
+//%
+//%- (void)exchangeValueAtIndex:(NSUInteger)idx1
+//% withValueAtIndex:(NSUInteger)idx2 {
+//%VALIDATE_RANGE(idx1, _count)
+//%VALIDATE_RANGE(idx2, _count)
+//% TYPE temp = _values[idx1];
+//% _values[idx1] = _values[idx2];
+//% _values[idx2] = temp;
+//%}
+//%
+
+//%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(Int32, int32_t, %d)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Int32
+
+@implementation GPBInt32Array {
+ @package
+ int32_t *_values;
+ NSUInteger _count;
+ NSUInteger _capacity;
+}
+
+@synthesize count = _count;
+
++ (instancetype)array {
+ return [[[self alloc] init] autorelease];
+}
+
++ (instancetype)arrayWithValue:(int32_t)value {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues: on to get
+ // the type correct.
+ return [[(GPBInt32Array*)[self alloc] initWithValues:&value count:1] autorelease];
+}
+
++ (instancetype)arrayWithValueArray:(GPBInt32Array *)array {
+ return [[(GPBInt32Array*)[self alloc] initWithValueArray:array] autorelease];
+}
+
++ (instancetype)arrayWithCapacity:(NSUInteger)count {
+ return [[[self alloc] initWithCapacity:count] autorelease];
+}
+
+- (instancetype)init {
+ self = [super init];
+ // No work needed;
+ return self;
+}
+
+- (instancetype)initWithValueArray:(GPBInt32Array *)array {
+ return [self initWithValues:array->_values count:array->_count];
+}
+
+- (instancetype)initWithValues:(const int32_t [])values count:(NSUInteger)count {
+ self = [self init];
+ if (self) {
+ if (count && values) {
+ _values = reallocf(_values, count * sizeof(int32_t));
+ if (_values != NULL) {
+ _capacity = count;
+ memcpy(_values, values, count * sizeof(int32_t));
+ _count = count;
+ } else {
+ [self release];
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(count * sizeof(int32_t))];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)count {
+ self = [self initWithValues:NULL count:0];
+ if (self && count) {
+ [self internalResizeToCapacity:count];
+ }
+ return self;
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32Array allocWithZone:zone] initWithValues:_values count:_count];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ free(_values);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32Array class]]) {
+ return NO;
+ }
+ GPBInt32Array *otherArray = other;
+ return (_count == otherArray->_count
+ && memcmp(_values, otherArray->_values, (_count * sizeof(int32_t))) == 0);
+}
+
+- (NSUInteger)hash {
+ // Follow NSArray's lead, and use the count as the hash.
+ return _count;
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ if (i == 0) {
+ [result appendFormat:@"%d", _values[i]];
+ } else {
+ [result appendFormat:@", %d", _values[i]];
+ }
+ }
+ [result appendFormat:@" }"];
+ return result;
+}
+
+- (void)enumerateValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ if ((opts & NSEnumerationReverse) == 0) {
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ block(_values[i], i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ for (NSUInteger i = _count; i > 0; --i) {
+ block(_values[i - 1], (i - 1), &stop);
+ if (stop) break;
+ }
+ }
+}
+
+- (int32_t)valueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ return _values[index];
+}
+
+- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+ _values = reallocf(_values, newCapacity * sizeof(int32_t));
+ if (_values == NULL) {
+ _capacity = 0;
+ _count = 0;
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(newCapacity * sizeof(int32_t))];
+ }
+ _capacity = newCapacity;
+}
+
+- (void)addValue:(int32_t)value {
+ [self addValues:&value count:1];
+}
+
+- (void)addValues:(const int32_t [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(int32_t));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertValue:(int32_t)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(int32_t));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(int32_t)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ _values[index] = value;
+}
+
+- (void)addValuesFromArray:(GPBInt32Array *)array {
+ [self addValues:array->_values count:array->_count];
+}
+
+- (void)removeValueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ NSUInteger newCount = _count - 1;
+ if (index != newCount) {
+ memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(int32_t));
+ }
+ _count = newCount;
+ if ((newCount + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+}
+
+- (void)removeAll {
+ _count = 0;
+ if ((0 + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(0)];
+ }
+}
+
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2 {
+ if (idx1 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx1, (unsigned long)_count];
+ }
+ if (idx2 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx2, (unsigned long)_count];
+ }
+ int32_t temp = _values[idx1];
+ _values[idx1] = _values[idx2];
+ _values[idx2] = temp;
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(UInt32, uint32_t, %u)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - UInt32
+
+@implementation GPBUInt32Array {
+ @package
+ uint32_t *_values;
+ NSUInteger _count;
+ NSUInteger _capacity;
+}
+
+@synthesize count = _count;
+
++ (instancetype)array {
+ return [[[self alloc] init] autorelease];
+}
+
++ (instancetype)arrayWithValue:(uint32_t)value {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues: on to get
+ // the type correct.
+ return [[(GPBUInt32Array*)[self alloc] initWithValues:&value count:1] autorelease];
+}
+
++ (instancetype)arrayWithValueArray:(GPBUInt32Array *)array {
+ return [[(GPBUInt32Array*)[self alloc] initWithValueArray:array] autorelease];
+}
+
++ (instancetype)arrayWithCapacity:(NSUInteger)count {
+ return [[[self alloc] initWithCapacity:count] autorelease];
+}
+
+- (instancetype)init {
+ self = [super init];
+ // No work needed;
+ return self;
+}
+
+- (instancetype)initWithValueArray:(GPBUInt32Array *)array {
+ return [self initWithValues:array->_values count:array->_count];
+}
+
+- (instancetype)initWithValues:(const uint32_t [])values count:(NSUInteger)count {
+ self = [self init];
+ if (self) {
+ if (count && values) {
+ _values = reallocf(_values, count * sizeof(uint32_t));
+ if (_values != NULL) {
+ _capacity = count;
+ memcpy(_values, values, count * sizeof(uint32_t));
+ _count = count;
+ } else {
+ [self release];
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(count * sizeof(uint32_t))];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)count {
+ self = [self initWithValues:NULL count:0];
+ if (self && count) {
+ [self internalResizeToCapacity:count];
+ }
+ return self;
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32Array allocWithZone:zone] initWithValues:_values count:_count];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ free(_values);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32Array class]]) {
+ return NO;
+ }
+ GPBUInt32Array *otherArray = other;
+ return (_count == otherArray->_count
+ && memcmp(_values, otherArray->_values, (_count * sizeof(uint32_t))) == 0);
+}
+
+- (NSUInteger)hash {
+ // Follow NSArray's lead, and use the count as the hash.
+ return _count;
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ if (i == 0) {
+ [result appendFormat:@"%u", _values[i]];
+ } else {
+ [result appendFormat:@", %u", _values[i]];
+ }
+ }
+ [result appendFormat:@" }"];
+ return result;
+}
+
+- (void)enumerateValuesWithBlock:(void (^)(uint32_t value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(uint32_t value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ if ((opts & NSEnumerationReverse) == 0) {
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ block(_values[i], i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ for (NSUInteger i = _count; i > 0; --i) {
+ block(_values[i - 1], (i - 1), &stop);
+ if (stop) break;
+ }
+ }
+}
+
+- (uint32_t)valueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ return _values[index];
+}
+
+- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+ _values = reallocf(_values, newCapacity * sizeof(uint32_t));
+ if (_values == NULL) {
+ _capacity = 0;
+ _count = 0;
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(newCapacity * sizeof(uint32_t))];
+ }
+ _capacity = newCapacity;
+}
+
+- (void)addValue:(uint32_t)value {
+ [self addValues:&value count:1];
+}
+
+- (void)addValues:(const uint32_t [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(uint32_t));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertValue:(uint32_t)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(uint32_t));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(uint32_t)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ _values[index] = value;
+}
+
+- (void)addValuesFromArray:(GPBUInt32Array *)array {
+ [self addValues:array->_values count:array->_count];
+}
+
+- (void)removeValueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ NSUInteger newCount = _count - 1;
+ if (index != newCount) {
+ memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(uint32_t));
+ }
+ _count = newCount;
+ if ((newCount + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+}
+
+- (void)removeAll {
+ _count = 0;
+ if ((0 + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(0)];
+ }
+}
+
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2 {
+ if (idx1 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx1, (unsigned long)_count];
+ }
+ if (idx2 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx2, (unsigned long)_count];
+ }
+ uint32_t temp = _values[idx1];
+ _values[idx1] = _values[idx2];
+ _values[idx2] = temp;
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(Int64, int64_t, %lld)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Int64
+
+@implementation GPBInt64Array {
+ @package
+ int64_t *_values;
+ NSUInteger _count;
+ NSUInteger _capacity;
+}
+
+@synthesize count = _count;
+
++ (instancetype)array {
+ return [[[self alloc] init] autorelease];
+}
+
++ (instancetype)arrayWithValue:(int64_t)value {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues: on to get
+ // the type correct.
+ return [[(GPBInt64Array*)[self alloc] initWithValues:&value count:1] autorelease];
+}
+
++ (instancetype)arrayWithValueArray:(GPBInt64Array *)array {
+ return [[(GPBInt64Array*)[self alloc] initWithValueArray:array] autorelease];
+}
+
++ (instancetype)arrayWithCapacity:(NSUInteger)count {
+ return [[[self alloc] initWithCapacity:count] autorelease];
+}
+
+- (instancetype)init {
+ self = [super init];
+ // No work needed;
+ return self;
+}
+
+- (instancetype)initWithValueArray:(GPBInt64Array *)array {
+ return [self initWithValues:array->_values count:array->_count];
+}
+
+- (instancetype)initWithValues:(const int64_t [])values count:(NSUInteger)count {
+ self = [self init];
+ if (self) {
+ if (count && values) {
+ _values = reallocf(_values, count * sizeof(int64_t));
+ if (_values != NULL) {
+ _capacity = count;
+ memcpy(_values, values, count * sizeof(int64_t));
+ _count = count;
+ } else {
+ [self release];
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(count * sizeof(int64_t))];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)count {
+ self = [self initWithValues:NULL count:0];
+ if (self && count) {
+ [self internalResizeToCapacity:count];
+ }
+ return self;
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64Array allocWithZone:zone] initWithValues:_values count:_count];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ free(_values);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64Array class]]) {
+ return NO;
+ }
+ GPBInt64Array *otherArray = other;
+ return (_count == otherArray->_count
+ && memcmp(_values, otherArray->_values, (_count * sizeof(int64_t))) == 0);
+}
+
+- (NSUInteger)hash {
+ // Follow NSArray's lead, and use the count as the hash.
+ return _count;
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ if (i == 0) {
+ [result appendFormat:@"%lld", _values[i]];
+ } else {
+ [result appendFormat:@", %lld", _values[i]];
+ }
+ }
+ [result appendFormat:@" }"];
+ return result;
+}
+
+- (void)enumerateValuesWithBlock:(void (^)(int64_t value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(int64_t value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ if ((opts & NSEnumerationReverse) == 0) {
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ block(_values[i], i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ for (NSUInteger i = _count; i > 0; --i) {
+ block(_values[i - 1], (i - 1), &stop);
+ if (stop) break;
+ }
+ }
+}
+
+- (int64_t)valueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ return _values[index];
+}
+
+- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+ _values = reallocf(_values, newCapacity * sizeof(int64_t));
+ if (_values == NULL) {
+ _capacity = 0;
+ _count = 0;
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(newCapacity * sizeof(int64_t))];
+ }
+ _capacity = newCapacity;
+}
+
+- (void)addValue:(int64_t)value {
+ [self addValues:&value count:1];
+}
+
+- (void)addValues:(const int64_t [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(int64_t));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertValue:(int64_t)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(int64_t));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(int64_t)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ _values[index] = value;
+}
+
+- (void)addValuesFromArray:(GPBInt64Array *)array {
+ [self addValues:array->_values count:array->_count];
+}
+
+- (void)removeValueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ NSUInteger newCount = _count - 1;
+ if (index != newCount) {
+ memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(int64_t));
+ }
+ _count = newCount;
+ if ((newCount + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+}
+
+- (void)removeAll {
+ _count = 0;
+ if ((0 + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(0)];
+ }
+}
+
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2 {
+ if (idx1 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx1, (unsigned long)_count];
+ }
+ if (idx2 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx2, (unsigned long)_count];
+ }
+ int64_t temp = _values[idx1];
+ _values[idx1] = _values[idx2];
+ _values[idx2] = temp;
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(UInt64, uint64_t, %llu)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - UInt64
+
+@implementation GPBUInt64Array {
+ @package
+ uint64_t *_values;
+ NSUInteger _count;
+ NSUInteger _capacity;
+}
+
+@synthesize count = _count;
+
++ (instancetype)array {
+ return [[[self alloc] init] autorelease];
+}
+
++ (instancetype)arrayWithValue:(uint64_t)value {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues: on to get
+ // the type correct.
+ return [[(GPBUInt64Array*)[self alloc] initWithValues:&value count:1] autorelease];
+}
+
++ (instancetype)arrayWithValueArray:(GPBUInt64Array *)array {
+ return [[(GPBUInt64Array*)[self alloc] initWithValueArray:array] autorelease];
+}
+
++ (instancetype)arrayWithCapacity:(NSUInteger)count {
+ return [[[self alloc] initWithCapacity:count] autorelease];
+}
+
+- (instancetype)init {
+ self = [super init];
+ // No work needed;
+ return self;
+}
+
+- (instancetype)initWithValueArray:(GPBUInt64Array *)array {
+ return [self initWithValues:array->_values count:array->_count];
+}
+
+- (instancetype)initWithValues:(const uint64_t [])values count:(NSUInteger)count {
+ self = [self init];
+ if (self) {
+ if (count && values) {
+ _values = reallocf(_values, count * sizeof(uint64_t));
+ if (_values != NULL) {
+ _capacity = count;
+ memcpy(_values, values, count * sizeof(uint64_t));
+ _count = count;
+ } else {
+ [self release];
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(count * sizeof(uint64_t))];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)count {
+ self = [self initWithValues:NULL count:0];
+ if (self && count) {
+ [self internalResizeToCapacity:count];
+ }
+ return self;
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64Array allocWithZone:zone] initWithValues:_values count:_count];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ free(_values);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64Array class]]) {
+ return NO;
+ }
+ GPBUInt64Array *otherArray = other;
+ return (_count == otherArray->_count
+ && memcmp(_values, otherArray->_values, (_count * sizeof(uint64_t))) == 0);
+}
+
+- (NSUInteger)hash {
+ // Follow NSArray's lead, and use the count as the hash.
+ return _count;
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ if (i == 0) {
+ [result appendFormat:@"%llu", _values[i]];
+ } else {
+ [result appendFormat:@", %llu", _values[i]];
+ }
+ }
+ [result appendFormat:@" }"];
+ return result;
+}
+
+- (void)enumerateValuesWithBlock:(void (^)(uint64_t value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(uint64_t value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ if ((opts & NSEnumerationReverse) == 0) {
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ block(_values[i], i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ for (NSUInteger i = _count; i > 0; --i) {
+ block(_values[i - 1], (i - 1), &stop);
+ if (stop) break;
+ }
+ }
+}
+
+- (uint64_t)valueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ return _values[index];
+}
+
+- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+ _values = reallocf(_values, newCapacity * sizeof(uint64_t));
+ if (_values == NULL) {
+ _capacity = 0;
+ _count = 0;
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(newCapacity * sizeof(uint64_t))];
+ }
+ _capacity = newCapacity;
+}
+
+- (void)addValue:(uint64_t)value {
+ [self addValues:&value count:1];
+}
+
+- (void)addValues:(const uint64_t [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(uint64_t));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertValue:(uint64_t)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(uint64_t));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(uint64_t)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ _values[index] = value;
+}
+
+- (void)addValuesFromArray:(GPBUInt64Array *)array {
+ [self addValues:array->_values count:array->_count];
+}
+
+- (void)removeValueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ NSUInteger newCount = _count - 1;
+ if (index != newCount) {
+ memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(uint64_t));
+ }
+ _count = newCount;
+ if ((newCount + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+}
+
+- (void)removeAll {
+ _count = 0;
+ if ((0 + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(0)];
+ }
+}
+
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2 {
+ if (idx1 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx1, (unsigned long)_count];
+ }
+ if (idx2 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx2, (unsigned long)_count];
+ }
+ uint64_t temp = _values[idx1];
+ _values[idx1] = _values[idx2];
+ _values[idx2] = temp;
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(Float, float, %f)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Float
+
+@implementation GPBFloatArray {
+ @package
+ float *_values;
+ NSUInteger _count;
+ NSUInteger _capacity;
+}
+
+@synthesize count = _count;
+
++ (instancetype)array {
+ return [[[self alloc] init] autorelease];
+}
+
++ (instancetype)arrayWithValue:(float)value {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues: on to get
+ // the type correct.
+ return [[(GPBFloatArray*)[self alloc] initWithValues:&value count:1] autorelease];
+}
+
++ (instancetype)arrayWithValueArray:(GPBFloatArray *)array {
+ return [[(GPBFloatArray*)[self alloc] initWithValueArray:array] autorelease];
+}
+
++ (instancetype)arrayWithCapacity:(NSUInteger)count {
+ return [[[self alloc] initWithCapacity:count] autorelease];
+}
+
+- (instancetype)init {
+ self = [super init];
+ // No work needed;
+ return self;
+}
+
+- (instancetype)initWithValueArray:(GPBFloatArray *)array {
+ return [self initWithValues:array->_values count:array->_count];
+}
+
+- (instancetype)initWithValues:(const float [])values count:(NSUInteger)count {
+ self = [self init];
+ if (self) {
+ if (count && values) {
+ _values = reallocf(_values, count * sizeof(float));
+ if (_values != NULL) {
+ _capacity = count;
+ memcpy(_values, values, count * sizeof(float));
+ _count = count;
+ } else {
+ [self release];
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(count * sizeof(float))];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)count {
+ self = [self initWithValues:NULL count:0];
+ if (self && count) {
+ [self internalResizeToCapacity:count];
+ }
+ return self;
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBFloatArray allocWithZone:zone] initWithValues:_values count:_count];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ free(_values);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBFloatArray class]]) {
+ return NO;
+ }
+ GPBFloatArray *otherArray = other;
+ return (_count == otherArray->_count
+ && memcmp(_values, otherArray->_values, (_count * sizeof(float))) == 0);
+}
+
+- (NSUInteger)hash {
+ // Follow NSArray's lead, and use the count as the hash.
+ return _count;
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ if (i == 0) {
+ [result appendFormat:@"%f", _values[i]];
+ } else {
+ [result appendFormat:@", %f", _values[i]];
+ }
+ }
+ [result appendFormat:@" }"];
+ return result;
+}
+
+- (void)enumerateValuesWithBlock:(void (^)(float value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(float value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ if ((opts & NSEnumerationReverse) == 0) {
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ block(_values[i], i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ for (NSUInteger i = _count; i > 0; --i) {
+ block(_values[i - 1], (i - 1), &stop);
+ if (stop) break;
+ }
+ }
+}
+
+- (float)valueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ return _values[index];
+}
+
+- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+ _values = reallocf(_values, newCapacity * sizeof(float));
+ if (_values == NULL) {
+ _capacity = 0;
+ _count = 0;
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(newCapacity * sizeof(float))];
+ }
+ _capacity = newCapacity;
+}
+
+- (void)addValue:(float)value {
+ [self addValues:&value count:1];
+}
+
+- (void)addValues:(const float [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(float));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertValue:(float)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(float));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(float)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ _values[index] = value;
+}
+
+- (void)addValuesFromArray:(GPBFloatArray *)array {
+ [self addValues:array->_values count:array->_count];
+}
+
+- (void)removeValueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ NSUInteger newCount = _count - 1;
+ if (index != newCount) {
+ memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(float));
+ }
+ _count = newCount;
+ if ((newCount + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+}
+
+- (void)removeAll {
+ _count = 0;
+ if ((0 + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(0)];
+ }
+}
+
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2 {
+ if (idx1 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx1, (unsigned long)_count];
+ }
+ if (idx2 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx2, (unsigned long)_count];
+ }
+ float temp = _values[idx1];
+ _values[idx1] = _values[idx2];
+ _values[idx2] = temp;
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(Double, double, %lf)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Double
+
+@implementation GPBDoubleArray {
+ @package
+ double *_values;
+ NSUInteger _count;
+ NSUInteger _capacity;
+}
+
+@synthesize count = _count;
+
++ (instancetype)array {
+ return [[[self alloc] init] autorelease];
+}
+
++ (instancetype)arrayWithValue:(double)value {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues: on to get
+ // the type correct.
+ return [[(GPBDoubleArray*)[self alloc] initWithValues:&value count:1] autorelease];
+}
+
++ (instancetype)arrayWithValueArray:(GPBDoubleArray *)array {
+ return [[(GPBDoubleArray*)[self alloc] initWithValueArray:array] autorelease];
+}
+
++ (instancetype)arrayWithCapacity:(NSUInteger)count {
+ return [[[self alloc] initWithCapacity:count] autorelease];
+}
+
+- (instancetype)init {
+ self = [super init];
+ // No work needed;
+ return self;
+}
+
+- (instancetype)initWithValueArray:(GPBDoubleArray *)array {
+ return [self initWithValues:array->_values count:array->_count];
+}
+
+- (instancetype)initWithValues:(const double [])values count:(NSUInteger)count {
+ self = [self init];
+ if (self) {
+ if (count && values) {
+ _values = reallocf(_values, count * sizeof(double));
+ if (_values != NULL) {
+ _capacity = count;
+ memcpy(_values, values, count * sizeof(double));
+ _count = count;
+ } else {
+ [self release];
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(count * sizeof(double))];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)count {
+ self = [self initWithValues:NULL count:0];
+ if (self && count) {
+ [self internalResizeToCapacity:count];
+ }
+ return self;
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBDoubleArray allocWithZone:zone] initWithValues:_values count:_count];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ free(_values);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBDoubleArray class]]) {
+ return NO;
+ }
+ GPBDoubleArray *otherArray = other;
+ return (_count == otherArray->_count
+ && memcmp(_values, otherArray->_values, (_count * sizeof(double))) == 0);
+}
+
+- (NSUInteger)hash {
+ // Follow NSArray's lead, and use the count as the hash.
+ return _count;
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ if (i == 0) {
+ [result appendFormat:@"%lf", _values[i]];
+ } else {
+ [result appendFormat:@", %lf", _values[i]];
+ }
+ }
+ [result appendFormat:@" }"];
+ return result;
+}
+
+- (void)enumerateValuesWithBlock:(void (^)(double value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(double value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ if ((opts & NSEnumerationReverse) == 0) {
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ block(_values[i], i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ for (NSUInteger i = _count; i > 0; --i) {
+ block(_values[i - 1], (i - 1), &stop);
+ if (stop) break;
+ }
+ }
+}
+
+- (double)valueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ return _values[index];
+}
+
+- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+ _values = reallocf(_values, newCapacity * sizeof(double));
+ if (_values == NULL) {
+ _capacity = 0;
+ _count = 0;
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(newCapacity * sizeof(double))];
+ }
+ _capacity = newCapacity;
+}
+
+- (void)addValue:(double)value {
+ [self addValues:&value count:1];
+}
+
+- (void)addValues:(const double [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(double));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertValue:(double)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(double));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(double)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ _values[index] = value;
+}
+
+- (void)addValuesFromArray:(GPBDoubleArray *)array {
+ [self addValues:array->_values count:array->_count];
+}
+
+- (void)removeValueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ NSUInteger newCount = _count - 1;
+ if (index != newCount) {
+ memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(double));
+ }
+ _count = newCount;
+ if ((newCount + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+}
+
+- (void)removeAll {
+ _count = 0;
+ if ((0 + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(0)];
+ }
+}
+
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2 {
+ if (idx1 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx1, (unsigned long)_count];
+ }
+ if (idx2 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx2, (unsigned long)_count];
+ }
+ double temp = _values[idx1];
+ _values[idx1] = _values[idx2];
+ _values[idx2] = temp;
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_INTERFACE_SIMPLE(Bool, BOOL, %d)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool
+
+@implementation GPBBoolArray {
+ @package
+ BOOL *_values;
+ NSUInteger _count;
+ NSUInteger _capacity;
+}
+
+@synthesize count = _count;
+
++ (instancetype)array {
+ return [[[self alloc] init] autorelease];
+}
+
++ (instancetype)arrayWithValue:(BOOL)value {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues: on to get
+ // the type correct.
+ return [[(GPBBoolArray*)[self alloc] initWithValues:&value count:1] autorelease];
+}
+
++ (instancetype)arrayWithValueArray:(GPBBoolArray *)array {
+ return [[(GPBBoolArray*)[self alloc] initWithValueArray:array] autorelease];
+}
+
++ (instancetype)arrayWithCapacity:(NSUInteger)count {
+ return [[[self alloc] initWithCapacity:count] autorelease];
+}
+
+- (instancetype)init {
+ self = [super init];
+ // No work needed;
+ return self;
+}
+
+- (instancetype)initWithValueArray:(GPBBoolArray *)array {
+ return [self initWithValues:array->_values count:array->_count];
+}
+
+- (instancetype)initWithValues:(const BOOL [])values count:(NSUInteger)count {
+ self = [self init];
+ if (self) {
+ if (count && values) {
+ _values = reallocf(_values, count * sizeof(BOOL));
+ if (_values != NULL) {
+ _capacity = count;
+ memcpy(_values, values, count * sizeof(BOOL));
+ _count = count;
+ } else {
+ [self release];
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(count * sizeof(BOOL))];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)count {
+ self = [self initWithValues:NULL count:0];
+ if (self && count) {
+ [self internalResizeToCapacity:count];
+ }
+ return self;
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolArray allocWithZone:zone] initWithValues:_values count:_count];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ free(_values);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolArray class]]) {
+ return NO;
+ }
+ GPBBoolArray *otherArray = other;
+ return (_count == otherArray->_count
+ && memcmp(_values, otherArray->_values, (_count * sizeof(BOOL))) == 0);
+}
+
+- (NSUInteger)hash {
+ // Follow NSArray's lead, and use the count as the hash.
+ return _count;
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ if (i == 0) {
+ [result appendFormat:@"%d", _values[i]];
+ } else {
+ [result appendFormat:@", %d", _values[i]];
+ }
+ }
+ [result appendFormat:@" }"];
+ return result;
+}
+
+- (void)enumerateValuesWithBlock:(void (^)(BOOL value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(BOOL value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ if ((opts & NSEnumerationReverse) == 0) {
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ block(_values[i], i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ for (NSUInteger i = _count; i > 0; --i) {
+ block(_values[i - 1], (i - 1), &stop);
+ if (stop) break;
+ }
+ }
+}
+
+- (BOOL)valueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ return _values[index];
+}
+
+- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+ _values = reallocf(_values, newCapacity * sizeof(BOOL));
+ if (_values == NULL) {
+ _capacity = 0;
+ _count = 0;
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(newCapacity * sizeof(BOOL))];
+ }
+ _capacity = newCapacity;
+}
+
+- (void)addValue:(BOOL)value {
+ [self addValues:&value count:1];
+}
+
+- (void)addValues:(const BOOL [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(BOOL));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertValue:(BOOL)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(BOOL));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(BOOL)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ _values[index] = value;
+}
+
+- (void)addValuesFromArray:(GPBBoolArray *)array {
+ [self addValues:array->_values count:array->_count];
+}
+
+- (void)removeValueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ NSUInteger newCount = _count - 1;
+ if (index != newCount) {
+ memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(BOOL));
+ }
+ _count = newCount;
+ if ((newCount + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+}
+
+- (void)removeAll {
+ _count = 0;
+ if ((0 + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(0)];
+ }
+}
+
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2 {
+ if (idx1 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx1, (unsigned long)_count];
+ }
+ if (idx2 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx2, (unsigned long)_count];
+ }
+ BOOL temp = _values[idx1];
+ _values[idx1] = _values[idx2];
+ _values[idx2] = temp;
+}
+
+@end
+
+//%PDDM-EXPAND-END (7 expansions)
+
+#pragma mark - Enum
+
+@implementation GPBEnumArray {
+ @package
+ GPBEnumValidationFunc _validationFunc;
+ int32_t *_values;
+ NSUInteger _count;
+ NSUInteger _capacity;
+}
+
+@synthesize count = _count;
+@synthesize validationFunc = _validationFunc;
+
++ (instancetype)array {
+ return [[[self alloc] initWithValidationFunction:NULL] autorelease];
+}
+
++ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [[[self alloc] initWithValidationFunction:func] autorelease];
+}
+
++ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValue:(int32_t)value {
+ return [[[self alloc] initWithValidationFunction:func
+ rawValues:&value
+ count:1] autorelease];
+}
+
++ (instancetype)arrayWithValueArray:(GPBEnumArray *)array {
+ return [[(GPBEnumArray*)[self alloc] initWithValueArray:array] autorelease];
+}
+
++ (instancetype)arrayWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)count {
+ return [[[self alloc] initWithValidationFunction:func capacity:count] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithValidationFunction:NULL];
+}
+
+- (instancetype)initWithValueArray:(GPBEnumArray *)array {
+ return [self initWithValidationFunction:array->_validationFunc
+ rawValues:array->_values
+ count:array->_count];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
+ self = [super init];
+ if (self) {
+ _validationFunc = (func != NULL ? func : ArrayDefault_IsValidValue);
+ }
+ return self;
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])values
+ count:(NSUInteger)count {
+ self = [self initWithValidationFunction:func];
+ if (self) {
+ if (count && values) {
+ _values = reallocf(_values, count * sizeof(int32_t));
+ if (_values != NULL) {
+ _capacity = count;
+ memcpy(_values, values, count * sizeof(int32_t));
+ _count = count;
+ } else {
+ [self release];
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(count * sizeof(int32_t))];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)count {
+ self = [self initWithValidationFunction:func];
+ if (self && count) {
+ [self internalResizeToCapacity:count];
+ }
+ return self;
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBEnumArray allocWithZone:zone]
+ initWithValidationFunction:_validationFunc
+ rawValues:_values
+ count:_count];
+}
+
+//%PDDM-EXPAND ARRAY_IMMUTABLE_CORE(Enum, int32_t, Raw, %d)
+// This block of code is generated, do not edit it directly.
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ free(_values);
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBEnumArray class]]) {
+ return NO;
+ }
+ GPBEnumArray *otherArray = other;
+ return (_count == otherArray->_count
+ && memcmp(_values, otherArray->_values, (_count * sizeof(int32_t))) == 0);
+}
+
+- (NSUInteger)hash {
+ // Follow NSArray's lead, and use the count as the hash.
+ return _count;
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> { ", [self class], self];
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ if (i == 0) {
+ [result appendFormat:@"%d", _values[i]];
+ } else {
+ [result appendFormat:@", %d", _values[i]];
+ }
+ }
+ [result appendFormat:@" }"];
+ return result;
+}
+
+- (void)enumerateRawValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateRawValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateRawValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ if ((opts & NSEnumerationReverse) == 0) {
+ for (NSUInteger i = 0, count = _count; i < count; ++i) {
+ block(_values[i], i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ for (NSUInteger i = _count; i > 0; --i) {
+ block(_values[i - 1], (i - 1), &stop);
+ if (stop) break;
+ }
+ }
+}
+//%PDDM-EXPAND-END ARRAY_IMMUTABLE_CORE(Enum, int32_t, Raw, %d)
+
+- (int32_t)valueAtIndex:(NSUInteger)index {
+//%PDDM-EXPAND VALIDATE_RANGE(index, _count)
+// This block of code is generated, do not edit it directly.
+
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+//%PDDM-EXPAND-END VALIDATE_RANGE(index, _count)
+ int32_t result = _values[index];
+ if (!_validationFunc(result)) {
+ result = kGPBUnrecognizedEnumeratorValue;
+ }
+ return result;
+}
+
+- (int32_t)rawValueAtIndex:(NSUInteger)index {
+//%PDDM-EXPAND VALIDATE_RANGE(index, _count)
+// This block of code is generated, do not edit it directly.
+
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+//%PDDM-EXPAND-END VALIDATE_RANGE(index, _count)
+ return _values[index];
+}
+
+- (void)enumerateValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block {
+ [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block];
+}
+
+- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block {
+ // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok).
+ BOOL stop = NO;
+ GPBEnumValidationFunc func = _validationFunc;
+ if ((opts & NSEnumerationReverse) == 0) {
+ int32_t *scan = _values;
+ int32_t *end = scan + _count;
+ for (NSUInteger i = 0; scan < end; ++i, ++scan) {
+ int32_t value = *scan;
+ if (!func(value)) {
+ value = kGPBUnrecognizedEnumeratorValue;
+ }
+ block(value, i, &stop);
+ if (stop) break;
+ }
+ } else if (_count > 0) {
+ int32_t *end = _values;
+ int32_t *scan = end + (_count - 1);
+ for (NSUInteger i = (_count - 1); scan >= end; --i, --scan) {
+ int32_t value = *scan;
+ if (!func(value)) {
+ value = kGPBUnrecognizedEnumeratorValue;
+ }
+ block(value, i, &stop);
+ if (stop) break;
+ }
+ }
+}
+
+//%PDDM-EXPAND ARRAY_MUTABLE_CORE(Enum, int32_t, Raw, %d)
+// This block of code is generated, do not edit it directly.
+
+- (void)internalResizeToCapacity:(NSUInteger)newCapacity {
+ _values = reallocf(_values, newCapacity * sizeof(int32_t));
+ if (_values == NULL) {
+ _capacity = 0;
+ _count = 0;
+ [NSException raise:NSMallocException
+ format:@"Failed to allocate %lu bytes",
+ (unsigned long)(newCapacity * sizeof(int32_t))];
+ }
+ _capacity = newCapacity;
+}
+
+- (void)addRawValue:(int32_t)value {
+ [self addRawValues:&value count:1];
+}
+
+- (void)addRawValues:(const int32_t [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(int32_t));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertRawValue:(int32_t)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(int32_t));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withRawValue:(int32_t)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ _values[index] = value;
+}
+
+- (void)addRawValuesFromArray:(GPBEnumArray *)array {
+ [self addRawValues:array->_values count:array->_count];
+}
+
+- (void)removeValueAtIndex:(NSUInteger)index {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ NSUInteger newCount = _count - 1;
+ if (index != newCount) {
+ memmove(&_values[index], &_values[index + 1], (newCount - index) * sizeof(int32_t));
+ }
+ _count = newCount;
+ if ((newCount + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+}
+
+- (void)removeAll {
+ _count = 0;
+ if ((0 + (2 * kChunkSize)) < _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(0)];
+ }
+}
+
+- (void)exchangeValueAtIndex:(NSUInteger)idx1
+ withValueAtIndex:(NSUInteger)idx2 {
+ if (idx1 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx1, (unsigned long)_count];
+ }
+ if (idx2 >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)idx2, (unsigned long)_count];
+ }
+ int32_t temp = _values[idx1];
+ _values[idx1] = _values[idx2];
+ _values[idx2] = temp;
+}
+
+//%PDDM-EXPAND MUTATION_METHODS(Enum, int32_t, , EnumValidationList, EnumValidationOne)
+// This block of code is generated, do not edit it directly.
+
+- (void)addValue:(int32_t)value {
+ [self addValues:&value count:1];
+}
+
+- (void)addValues:(const int32_t [])values count:(NSUInteger)count {
+ if (values == NULL || count == 0) return;
+ GPBEnumValidationFunc func = _validationFunc;
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!func(values[i])) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@: Attempt to set an unknown enum value (%d)",
+ [self class], values[i]];
+ }
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + count;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ memcpy(&_values[initialCount], values, count * sizeof(int32_t));
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)insertValue:(int32_t)value atIndex:(NSUInteger)index {
+ if (index >= _count + 1) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count + 1];
+ }
+ if (!_validationFunc(value)) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@: Attempt to set an unknown enum value (%d)",
+ [self class], value];
+ }
+ NSUInteger initialCount = _count;
+ NSUInteger newCount = initialCount + 1;
+ if (newCount > _capacity) {
+ [self internalResizeToCapacity:CapacityFromCount(newCount)];
+ }
+ _count = newCount;
+ if (index != initialCount) {
+ memmove(&_values[index + 1], &_values[index], (initialCount - index) * sizeof(int32_t));
+ }
+ _values[index] = value;
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)replaceValueAtIndex:(NSUInteger)index withValue:(int32_t)value {
+ if (index >= _count) {
+ [NSException raise:NSRangeException
+ format:@"Index (%lu) beyond bounds (%lu)",
+ (unsigned long)index, (unsigned long)_count];
+ }
+ if (!_validationFunc(value)) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@: Attempt to set an unknown enum value (%d)",
+ [self class], value];
+ }
+ _values[index] = value;
+}
+//%PDDM-EXPAND-END (2 expansions)
+
+//%PDDM-DEFINE MUTATION_HOOK_EnumValidationList()
+//% GPBEnumValidationFunc func = _validationFunc;
+//% for (NSUInteger i = 0; i < count; ++i) {
+//% if (!func(values[i])) {
+//% [NSException raise:NSInvalidArgumentException
+//% format:@"%@: Attempt to set an unknown enum value (%d)",
+//% [self class], values[i]];
+//% }
+//% }
+//%
+//%PDDM-DEFINE MUTATION_HOOK_EnumValidationOne()
+//% if (!_validationFunc(value)) {
+//% [NSException raise:NSInvalidArgumentException
+//% format:@"%@: Attempt to set an unknown enum value (%d)",
+//% [self class], value];
+//% }
+//%
+
+@end
+
+#pragma mark - NSArray Subclass
+
+@implementation GPBAutocreatedArray {
+ NSMutableArray *_array;
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_array release];
+ [super dealloc];
+}
+
+#pragma mark Required NSArray overrides
+
+- (NSUInteger)count {
+ return [_array count];
+}
+
+- (id)objectAtIndex:(NSUInteger)idx {
+ return [_array objectAtIndex:idx];
+}
+
+#pragma mark Required NSMutableArray overrides
+
+// Only need to call GPBAutocreatedArrayModified() when adding things since
+// we only autocreate empty arrays.
+
+- (void)insertObject:(id)anObject atIndex:(NSUInteger)idx {
+ if (_array == nil) {
+ _array = [[NSMutableArray alloc] init];
+ }
+ [_array insertObject:anObject atIndex:idx];
+
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)removeObject:(id)anObject {
+ [_array removeObject:anObject];
+}
+
+- (void)removeObjectAtIndex:(NSUInteger)idx {
+ [_array removeObjectAtIndex:idx];
+}
+
+- (void)addObject:(id)anObject {
+ if (_array == nil) {
+ _array = [[NSMutableArray alloc] init];
+ }
+ [_array addObject:anObject];
+
+ if (_autocreator) {
+ GPBAutocreatedArrayModified(_autocreator, self);
+ }
+}
+
+- (void)removeLastObject {
+ [_array removeLastObject];
+}
+
+- (void)replaceObjectAtIndex:(NSUInteger)idx withObject:(id)anObject {
+ [_array replaceObjectAtIndex:idx withObject:anObject];
+}
+
+#pragma mark Extra things hooked
+
+- (id)copyWithZone:(NSZone *)zone {
+ if (_array == nil) {
+ return [[NSMutableArray allocWithZone:zone] init];
+ }
+ return [_array copyWithZone:zone];
+}
+
+- (id)mutableCopyWithZone:(NSZone *)zone {
+ if (_array == nil) {
+ return [[NSMutableArray allocWithZone:zone] init];
+ }
+ return [_array mutableCopyWithZone:zone];
+}
+
+- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
+ objects:(id __unsafe_unretained [])buffer
+ count:(NSUInteger)len {
+ return [_array countByEnumeratingWithState:state objects:buffer count:len];
+}
+
+- (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block {
+ [_array enumerateObjectsUsingBlock:block];
+}
+
+- (void)enumerateObjectsWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block {
+ [_array enumerateObjectsWithOptions:opts usingBlock:block];
+}
+
+@end
+
+#pragma clang diagnostic pop
diff --git a/third_party/protobuf/objectivec/GPBArray_PackagePrivate.h b/third_party/protobuf/objectivec/GPBArray_PackagePrivate.h
new file mode 100644
index 0000000000..35a4538131
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBArray_PackagePrivate.h
@@ -0,0 +1,130 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBArray.h"
+
+@class GPBMessage;
+
+//%PDDM-DEFINE DECLARE_ARRAY_EXTRAS()
+//%ARRAY_INTERFACE_EXTRAS(Int32, int32_t)
+//%ARRAY_INTERFACE_EXTRAS(UInt32, uint32_t)
+//%ARRAY_INTERFACE_EXTRAS(Int64, int64_t)
+//%ARRAY_INTERFACE_EXTRAS(UInt64, uint64_t)
+//%ARRAY_INTERFACE_EXTRAS(Float, float)
+//%ARRAY_INTERFACE_EXTRAS(Double, double)
+//%ARRAY_INTERFACE_EXTRAS(Bool, BOOL)
+//%ARRAY_INTERFACE_EXTRAS(Enum, int32_t)
+
+//%PDDM-DEFINE ARRAY_INTERFACE_EXTRAS(NAME, TYPE)
+//%#pragma mark - NAME
+//%
+//%@interface GPB##NAME##Array () {
+//% @package
+//% GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+//%}
+//%@end
+//%
+
+//%PDDM-EXPAND DECLARE_ARRAY_EXTRAS()
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Int32
+
+@interface GPBInt32Array () {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+#pragma mark - UInt32
+
+@interface GPBUInt32Array () {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+#pragma mark - Int64
+
+@interface GPBInt64Array () {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+#pragma mark - UInt64
+
+@interface GPBUInt64Array () {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+#pragma mark - Float
+
+@interface GPBFloatArray () {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+#pragma mark - Double
+
+@interface GPBDoubleArray () {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+#pragma mark - Bool
+
+@interface GPBBoolArray () {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+#pragma mark - Enum
+
+@interface GPBEnumArray () {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+//%PDDM-EXPAND-END DECLARE_ARRAY_EXTRAS()
+
+#pragma mark - NSArray Subclass
+
+@interface GPBAutocreatedArray : NSMutableArray {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
diff --git a/third_party/protobuf/objectivec/GPBBootstrap.h b/third_party/protobuf/objectivec/GPBBootstrap.h
new file mode 100644
index 0000000000..ed53ae7cbc
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBBootstrap.h
@@ -0,0 +1,123 @@
+// 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.
+
+/**
+ * The Objective C runtime has complete enough info that most protos don’t end
+ * up using this, so leaving it on is no cost or very little cost. If you
+ * happen to see it causing bloat, this is the way to disable it. If you do
+ * need to disable it, try only disabling it for Release builds as having
+ * full TextFormat can be useful for debugging.
+ **/
+#ifndef GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
+#define GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS 0
+#endif
+
+// Used in the generated code to give sizes to enums. int32_t was chosen based
+// on the fact that Protocol Buffers enums are limited to this range.
+#if !__has_feature(objc_fixed_enum)
+ #error All supported Xcode versions should support objc_fixed_enum.
+#endif
+
+// If the headers are imported into Objective-C++, we can run into an issue
+// where the defintion of NS_ENUM (really CF_ENUM) changes based on the C++
+// standard that is in effect. If it isn't C++11 or higher, the definition
+// doesn't allow us to forward declare. We work around this one case by
+// providing a local definition. The default case has to use NS_ENUM for the
+// magic that is Swift bridging of enums.
+#if (defined(__cplusplus) && __cplusplus && __cplusplus < 201103L)
+ #define GPB_ENUM(X) enum X : int32_t X; enum X : int32_t
+#else
+ #define GPB_ENUM(X) NS_ENUM(int32_t, X)
+#endif
+
+/**
+ * GPB_ENUM_FWD_DECLARE is used for forward declaring enums, for example:
+ *
+ * ```
+ * GPB_ENUM_FWD_DECLARE(Foo_Enum)
+ *
+ * @interface BarClass : NSObject
+ * @property (nonatomic) enum Foo_Enum value;
+ * - (void)bazMethod:(enum Foo_Enum):value;
+ * @end
+ * ```
+ **/
+#define GPB_ENUM_FWD_DECLARE(X) enum X : int32_t
+
+/**
+ * Based upon CF_INLINE. Forces inlining in non DEBUG builds.
+ **/
+#if !defined(DEBUG)
+#define GPB_INLINE static __inline__ __attribute__((always_inline))
+#else
+#define GPB_INLINE static __inline__
+#endif
+
+/**
+ * For use in public headers that might need to deal with ARC.
+ **/
+#ifndef GPB_UNSAFE_UNRETAINED
+#if __has_feature(objc_arc)
+#define GPB_UNSAFE_UNRETAINED __unsafe_unretained
+#else
+#define GPB_UNSAFE_UNRETAINED
+#endif
+#endif
+
+// If property name starts with init we need to annotate it to get past ARC.
+// http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227
+//
+// Meant to be used internally by generated code.
+#define GPB_METHOD_FAMILY_NONE __attribute__((objc_method_family(none)))
+
+// ----------------------------------------------------------------------------
+// These version numbers are all internal to the ObjC Protobuf runtime; they
+// are used to ensure compatibility between the generated sources and the
+// headers being compiled against and/or the version of sources being run
+// against.
+//
+// They are all #defines so the values are captured into every .o file they
+// are used in and to allow comparisons in the preprocessor.
+
+// Current library runtime version.
+// - Gets bumped when the runtime makes changes to the interfaces between the
+// generated code and runtime (things added/removed, etc).
+#define GOOGLE_PROTOBUF_OBJC_VERSION 30002
+
+// Minimum runtime version supported for compiling/running against.
+// - Gets changed when support for the older generated code is dropped.
+#define GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION 30001
+
+
+// This is a legacy constant now frozen in time for old generated code. If
+// GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION ever gets moved above 30001 then
+// this should also change to break code compiled with an old runtime that
+// can't be supported any more.
+#define GOOGLE_PROTOBUF_OBJC_GEN_VERSION 30001
diff --git a/third_party/protobuf/objectivec/GPBCodedInputStream.h b/third_party/protobuf/objectivec/GPBCodedInputStream.h
new file mode 100644
index 0000000000..fbe5009c92
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBCodedInputStream.h
@@ -0,0 +1,253 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+@class GPBMessage;
+@class GPBExtensionRegistry;
+
+NS_ASSUME_NONNULL_BEGIN
+
+CF_EXTERN_C_BEGIN
+
+/**
+ * @c GPBCodedInputStream exception name. Exceptions raised from
+ * @c GPBCodedInputStream contain an underlying error in the userInfo dictionary
+ * under the GPBCodedInputStreamUnderlyingErrorKey key.
+ **/
+extern NSString *const GPBCodedInputStreamException;
+
+/** The key under which the underlying NSError from the exception is stored. */
+extern NSString *const GPBCodedInputStreamUnderlyingErrorKey;
+
+/** NSError domain used for @c GPBCodedInputStream errors. */
+extern NSString *const GPBCodedInputStreamErrorDomain;
+
+/**
+ * Error code for NSError with @c GPBCodedInputStreamErrorDomain.
+ **/
+typedef NS_ENUM(NSInteger, GPBCodedInputStreamErrorCode) {
+ /** The size does not fit in the remaining bytes to be read. */
+ GPBCodedInputStreamErrorInvalidSize = -100,
+ /** Attempted to read beyond the subsection limit. */
+ GPBCodedInputStreamErrorSubsectionLimitReached = -101,
+ /** The requested subsection limit is invalid. */
+ GPBCodedInputStreamErrorInvalidSubsectionLimit = -102,
+ /** Invalid tag read. */
+ GPBCodedInputStreamErrorInvalidTag = -103,
+ /** Invalid UTF-8 character in a string. */
+ GPBCodedInputStreamErrorInvalidUTF8 = -104,
+ /** Invalid VarInt read. */
+ GPBCodedInputStreamErrorInvalidVarInt = -105,
+ /** The maximum recursion depth of messages was exceeded. */
+ GPBCodedInputStreamErrorRecursionDepthExceeded = -106,
+};
+
+CF_EXTERN_C_END
+
+/**
+ * Reads and decodes protocol message fields.
+ *
+ * The common uses of protocol buffers shouldn't need to use this class.
+ * @c GPBMessage's provide a @c +parseFromData:error: and
+ * @c +parseFromData:extensionRegistry:error: method that will decode a
+ * message for you.
+ *
+ * @note Subclassing of @c GPBCodedInputStream is NOT supported.
+ **/
+@interface GPBCodedInputStream : NSObject
+
+/**
+ * Creates a new stream wrapping some data.
+ *
+ * @param data The data to wrap inside the stream.
+ *
+ * @return A newly instanced GPBCodedInputStream.
+ **/
++ (instancetype)streamWithData:(NSData *)data;
+
+/**
+ * Initializes a stream wrapping some data.
+ *
+ * @param data The data to wrap inside the stream.
+ *
+ * @return A newly initialized GPBCodedInputStream.
+ **/
+- (instancetype)initWithData:(NSData *)data;
+
+/**
+ * Attempts 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.
+ *
+ * @return The field tag, or zero if EOF was reached.
+ **/
+- (int32_t)readTag;
+
+/**
+ * @return A double read from the stream.
+ **/
+- (double)readDouble;
+/**
+ * @return A float read from the stream.
+ **/
+- (float)readFloat;
+/**
+ * @return A uint64 read from the stream.
+ **/
+- (uint64_t)readUInt64;
+/**
+ * @return A uint32 read from the stream.
+ **/
+- (uint32_t)readUInt32;
+/**
+ * @return An int64 read from the stream.
+ **/
+- (int64_t)readInt64;
+/**
+ * @return An int32 read from the stream.
+ **/
+- (int32_t)readInt32;
+/**
+ * @return A fixed64 read from the stream.
+ **/
+- (uint64_t)readFixed64;
+/**
+ * @return A fixed32 read from the stream.
+ **/
+- (uint32_t)readFixed32;
+/**
+ * @return An enum read from the stream.
+ **/
+- (int32_t)readEnum;
+/**
+ * @return A sfixed32 read from the stream.
+ **/
+- (int32_t)readSFixed32;
+/**
+ * @return A fixed64 read from the stream.
+ **/
+- (int64_t)readSFixed64;
+/**
+ * @return A sint32 read from the stream.
+ **/
+- (int32_t)readSInt32;
+/**
+ * @return A sint64 read from the stream.
+ **/
+- (int64_t)readSInt64;
+/**
+ * @return A boolean read from the stream.
+ **/
+- (BOOL)readBool;
+/**
+ * @return A string read from the stream.
+ **/
+- (NSString *)readString;
+/**
+ * @return Data read from the stream.
+ **/
+- (NSData *)readBytes;
+
+/**
+ * Read an embedded message field value from the stream.
+ *
+ * @param message The message to set fields on as they are read.
+ * @param extensionRegistry An optional extension registry to use to lookup
+ * extensions for message.
+ **/
+- (void)readMessage:(GPBMessage *)message
+ extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry;
+
+/**
+ * Reads and discards a single field, given its tag value.
+ *
+ * @param tag The tag number of the field to skip.
+ *
+ * @return NO if the tag is an endgroup tag (in which case nothing is skipped),
+ * YES in all other cases.
+ **/
+- (BOOL)skipField:(int32_t)tag;
+
+/**
+ * Reads and discards an entire message. This will read either until EOF or
+ * until an endgroup tag, whichever comes first.
+ **/
+- (void)skipMessage;
+
+/**
+ * Check to see if the logical end of the stream has been reached.
+ *
+ * @note This can return NO when there is no more data, but the current parsing
+ * expected more data.
+ *
+ * @return YES if the logical end of the stream has been reached, NO otherwise.
+ **/
+- (BOOL)isAtEnd;
+
+/**
+ * @return The offset into the stream.
+ **/
+- (size_t)position;
+
+/**
+ * Moves the limit to the given byte offset starting at the current location.
+ *
+ * @exception GPBCodedInputStreamException If the requested bytes exceeed the
+ * current limit.
+ *
+ * @param byteLimit The number of bytes to move the limit, offset to the current
+ * location.
+ *
+ * @return The limit offset before moving the new limit.
+ */
+- (size_t)pushLimit:(size_t)byteLimit;
+
+/**
+ * Moves the limit back to the offset as it was before calling pushLimit:.
+ *
+ * @param oldLimit The number of bytes to move the current limit. Usually this
+ * is the value returned by the pushLimit: method.
+ */
+- (void)popLimit:(size_t)oldLimit;
+
+/**
+ * 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.
+ *
+ * @exception NSParseErrorException If the value does not match the last tag.
+ *
+ * @param expected The tag that was expected.
+ **/
+- (void)checkLastTagWas:(int32_t)expected;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBCodedInputStream.m b/third_party/protobuf/objectivec/GPBCodedInputStream.m
new file mode 100644
index 0000000000..eef053534b
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBCodedInputStream.m
@@ -0,0 +1,538 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBCodedInputStream_PackagePrivate.h"
+
+#import "GPBDictionary_PackagePrivate.h"
+#import "GPBMessage_PackagePrivate.h"
+#import "GPBUnknownFieldSet_PackagePrivate.h"
+#import "GPBUtilities_PackagePrivate.h"
+#import "GPBWireFormat.h"
+
+NSString *const GPBCodedInputStreamException =
+ GPBNSStringifySymbol(GPBCodedInputStreamException);
+
+NSString *const GPBCodedInputStreamUnderlyingErrorKey =
+ GPBNSStringifySymbol(GPBCodedInputStreamUnderlyingErrorKey);
+
+NSString *const GPBCodedInputStreamErrorDomain =
+ GPBNSStringifySymbol(GPBCodedInputStreamErrorDomain);
+
+// Matching:
+// https://github.com/google/protobuf/blob/master/java/core/src/main/java/com/google/protobuf/CodedInputStream.java#L62
+// private static final int DEFAULT_RECURSION_LIMIT = 100;
+// https://github.com/google/protobuf/blob/master/src/google/protobuf/io/coded_stream.cc#L86
+// int CodedInputStream::default_recursion_limit_ = 100;
+static const NSUInteger kDefaultRecursionLimit = 100;
+
+static void RaiseException(NSInteger code, NSString *reason) {
+ NSDictionary *errorInfo = nil;
+ if ([reason length]) {
+ errorInfo = @{ GPBErrorReasonKey: reason };
+ }
+ NSError *error = [NSError errorWithDomain:GPBCodedInputStreamErrorDomain
+ code:code
+ userInfo:errorInfo];
+
+ NSDictionary *exceptionInfo =
+ @{ GPBCodedInputStreamUnderlyingErrorKey: error };
+ [[[NSException alloc] initWithName:GPBCodedInputStreamException
+ reason:reason
+ userInfo:exceptionInfo] raise];
+}
+
+static void CheckSize(GPBCodedInputStreamState *state, size_t size) {
+ size_t newSize = state->bufferPos + size;
+ if (newSize > state->bufferSize) {
+ RaiseException(GPBCodedInputStreamErrorInvalidSize, nil);
+ }
+ if (newSize > state->currentLimit) {
+ // Fast forward to end of currentLimit;
+ state->bufferPos = state->currentLimit;
+ RaiseException(GPBCodedInputStreamErrorSubsectionLimitReached, nil);
+ }
+}
+
+static int8_t ReadRawByte(GPBCodedInputStreamState *state) {
+ CheckSize(state, sizeof(int8_t));
+ return ((int8_t *)state->bytes)[state->bufferPos++];
+}
+
+static int32_t ReadRawLittleEndian32(GPBCodedInputStreamState *state) {
+ CheckSize(state, sizeof(int32_t));
+ int32_t value = OSReadLittleInt32(state->bytes, state->bufferPos);
+ state->bufferPos += sizeof(int32_t);
+ return value;
+}
+
+static int64_t ReadRawLittleEndian64(GPBCodedInputStreamState *state) {
+ CheckSize(state, sizeof(int64_t));
+ int64_t value = OSReadLittleInt64(state->bytes, state->bufferPos);
+ state->bufferPos += sizeof(int64_t);
+ return value;
+}
+
+static int32_t ReadRawVarint32(GPBCodedInputStreamState *state) {
+ int8_t tmp = ReadRawByte(state);
+ if (tmp >= 0) {
+ return tmp;
+ }
+ int32_t result = tmp & 0x7f;
+ if ((tmp = ReadRawByte(state)) >= 0) {
+ result |= tmp << 7;
+ } else {
+ result |= (tmp & 0x7f) << 7;
+ if ((tmp = ReadRawByte(state)) >= 0) {
+ result |= tmp << 14;
+ } else {
+ result |= (tmp & 0x7f) << 14;
+ if ((tmp = ReadRawByte(state)) >= 0) {
+ result |= tmp << 21;
+ } else {
+ result |= (tmp & 0x7f) << 21;
+ result |= (tmp = ReadRawByte(state)) << 28;
+ if (tmp < 0) {
+ // Discard upper 32 bits.
+ for (int i = 0; i < 5; i++) {
+ if (ReadRawByte(state) >= 0) {
+ return result;
+ }
+ }
+ RaiseException(GPBCodedInputStreamErrorInvalidVarInt,
+ @"Invalid VarInt32");
+ }
+ }
+ }
+ }
+ return result;
+}
+
+static int64_t ReadRawVarint64(GPBCodedInputStreamState *state) {
+ int32_t shift = 0;
+ int64_t result = 0;
+ while (shift < 64) {
+ int8_t b = ReadRawByte(state);
+ result |= (int64_t)(b & 0x7F) << shift;
+ if ((b & 0x80) == 0) {
+ return result;
+ }
+ shift += 7;
+ }
+ RaiseException(GPBCodedInputStreamErrorInvalidVarInt, @"Invalid VarInt64");
+ return 0;
+}
+
+static void SkipRawData(GPBCodedInputStreamState *state, size_t size) {
+ CheckSize(state, size);
+ state->bufferPos += size;
+}
+
+double GPBCodedInputStreamReadDouble(GPBCodedInputStreamState *state) {
+ int64_t value = ReadRawLittleEndian64(state);
+ return GPBConvertInt64ToDouble(value);
+}
+
+float GPBCodedInputStreamReadFloat(GPBCodedInputStreamState *state) {
+ int32_t value = ReadRawLittleEndian32(state);
+ return GPBConvertInt32ToFloat(value);
+}
+
+uint64_t GPBCodedInputStreamReadUInt64(GPBCodedInputStreamState *state) {
+ uint64_t value = ReadRawVarint64(state);
+ return value;
+}
+
+uint32_t GPBCodedInputStreamReadUInt32(GPBCodedInputStreamState *state) {
+ uint32_t value = ReadRawVarint32(state);
+ return value;
+}
+
+int64_t GPBCodedInputStreamReadInt64(GPBCodedInputStreamState *state) {
+ int64_t value = ReadRawVarint64(state);
+ return value;
+}
+
+int32_t GPBCodedInputStreamReadInt32(GPBCodedInputStreamState *state) {
+ int32_t value = ReadRawVarint32(state);
+ return value;
+}
+
+uint64_t GPBCodedInputStreamReadFixed64(GPBCodedInputStreamState *state) {
+ uint64_t value = ReadRawLittleEndian64(state);
+ return value;
+}
+
+uint32_t GPBCodedInputStreamReadFixed32(GPBCodedInputStreamState *state) {
+ uint32_t value = ReadRawLittleEndian32(state);
+ return value;
+}
+
+int32_t GPBCodedInputStreamReadEnum(GPBCodedInputStreamState *state) {
+ int32_t value = ReadRawVarint32(state);
+ return value;
+}
+
+int32_t GPBCodedInputStreamReadSFixed32(GPBCodedInputStreamState *state) {
+ int32_t value = ReadRawLittleEndian32(state);
+ return value;
+}
+
+int64_t GPBCodedInputStreamReadSFixed64(GPBCodedInputStreamState *state) {
+ int64_t value = ReadRawLittleEndian64(state);
+ return value;
+}
+
+int32_t GPBCodedInputStreamReadSInt32(GPBCodedInputStreamState *state) {
+ int32_t value = GPBDecodeZigZag32(ReadRawVarint32(state));
+ return value;
+}
+
+int64_t GPBCodedInputStreamReadSInt64(GPBCodedInputStreamState *state) {
+ int64_t value = GPBDecodeZigZag64(ReadRawVarint64(state));
+ return value;
+}
+
+BOOL GPBCodedInputStreamReadBool(GPBCodedInputStreamState *state) {
+ return ReadRawVarint32(state) != 0;
+}
+
+int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
+ if (GPBCodedInputStreamIsAtEnd(state)) {
+ state->lastTag = 0;
+ return 0;
+ }
+
+ state->lastTag = ReadRawVarint32(state);
+ if (state->lastTag == 0) {
+ // If we actually read zero, that's not a valid tag.
+ RaiseException(GPBCodedInputStreamErrorInvalidTag,
+ @"A zero tag on the wire is invalid.");
+ }
+ // Tags have to include a valid wireformat, check that also.
+ if (!GPBWireFormatIsValidTag(state->lastTag)) {
+ RaiseException(GPBCodedInputStreamErrorInvalidTag,
+ @"Invalid wireformat in tag.");
+ }
+ return state->lastTag;
+}
+
+NSString *GPBCodedInputStreamReadRetainedString(
+ GPBCodedInputStreamState *state) {
+ int32_t size = ReadRawVarint32(state);
+ NSString *result;
+ if (size == 0) {
+ result = @"";
+ } else {
+ CheckSize(state, size);
+ result = [[NSString alloc] initWithBytes:&state->bytes[state->bufferPos]
+ length:size
+ encoding:NSUTF8StringEncoding];
+ state->bufferPos += size;
+ if (!result) {
+#ifdef DEBUG
+ // https://developers.google.com/protocol-buffers/docs/proto#scalar
+ NSLog(@"UTF-8 failure, is some field type 'string' when it should be "
+ @"'bytes'?");
+#endif
+ RaiseException(GPBCodedInputStreamErrorInvalidUTF8, nil);
+ }
+ }
+ return result;
+}
+
+NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state) {
+ int32_t size = ReadRawVarint32(state);
+ if (size < 0) return nil;
+ CheckSize(state, size);
+ NSData *result = [[NSData alloc] initWithBytes:state->bytes + state->bufferPos
+ length:size];
+ state->bufferPos += size;
+ return result;
+}
+
+NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(
+ GPBCodedInputStreamState *state) {
+ int32_t size = ReadRawVarint32(state);
+ if (size < 0) return nil;
+ CheckSize(state, size);
+ // Cast is safe because freeWhenDone is NO.
+ NSData *result = [[NSData alloc]
+ initWithBytesNoCopy:(void *)(state->bytes + state->bufferPos)
+ length:size
+ freeWhenDone:NO];
+ state->bufferPos += size;
+ return result;
+}
+
+size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state,
+ size_t byteLimit) {
+ byteLimit += state->bufferPos;
+ size_t oldLimit = state->currentLimit;
+ if (byteLimit > oldLimit) {
+ RaiseException(GPBCodedInputStreamErrorInvalidSubsectionLimit, nil);
+ }
+ state->currentLimit = byteLimit;
+ return oldLimit;
+}
+
+void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state,
+ size_t oldLimit) {
+ state->currentLimit = oldLimit;
+}
+
+size_t GPBCodedInputStreamBytesUntilLimit(GPBCodedInputStreamState *state) {
+ return state->currentLimit - state->bufferPos;
+}
+
+BOOL GPBCodedInputStreamIsAtEnd(GPBCodedInputStreamState *state) {
+ return (state->bufferPos == state->bufferSize) ||
+ (state->bufferPos == state->currentLimit);
+}
+
+void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state,
+ int32_t value) {
+ if (state->lastTag != value) {
+ RaiseException(GPBCodedInputStreamErrorInvalidTag, @"Unexpected tag read");
+ }
+}
+
+@implementation GPBCodedInputStream
+
++ (instancetype)streamWithData:(NSData *)data {
+ return [[[self alloc] initWithData:data] autorelease];
+}
+
+- (instancetype)initWithData:(NSData *)data {
+ if ((self = [super init])) {
+#ifdef DEBUG
+ NSCAssert([self class] == [GPBCodedInputStream class],
+ @"Subclassing of GPBCodedInputStream is not allowed.");
+#endif
+ buffer_ = [data retain];
+ state_.bytes = (const uint8_t *)[data bytes];
+ state_.bufferSize = [data length];
+ state_.currentLimit = state_.bufferSize;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [buffer_ release];
+ [super dealloc];
+}
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+- (int32_t)readTag {
+ return GPBCodedInputStreamReadTag(&state_);
+}
+
+- (void)checkLastTagWas:(int32_t)value {
+ GPBCodedInputStreamCheckLastTagWas(&state_, value);
+}
+
+- (BOOL)skipField:(int32_t)tag {
+ NSAssert(GPBWireFormatIsValidTag(tag), @"Invalid tag");
+ switch (GPBWireFormatGetTagWireType(tag)) {
+ case GPBWireFormatVarint:
+ GPBCodedInputStreamReadInt32(&state_);
+ return YES;
+ case GPBWireFormatFixed64:
+ SkipRawData(&state_, sizeof(int64_t));
+ return YES;
+ case GPBWireFormatLengthDelimited:
+ SkipRawData(&state_, ReadRawVarint32(&state_));
+ return YES;
+ case GPBWireFormatStartGroup:
+ [self skipMessage];
+ GPBCodedInputStreamCheckLastTagWas(
+ &state_, GPBWireFormatMakeTag(GPBWireFormatGetTagFieldNumber(tag),
+ GPBWireFormatEndGroup));
+ return YES;
+ case GPBWireFormatEndGroup:
+ return NO;
+ case GPBWireFormatFixed32:
+ SkipRawData(&state_, sizeof(int32_t));
+ return YES;
+ }
+}
+
+- (void)skipMessage {
+ while (YES) {
+ int32_t tag = GPBCodedInputStreamReadTag(&state_);
+ if (tag == 0 || ![self skipField:tag]) {
+ return;
+ }
+ }
+}
+
+- (BOOL)isAtEnd {
+ return GPBCodedInputStreamIsAtEnd(&state_);
+}
+
+- (size_t)position {
+ return state_.bufferPos;
+}
+
+- (size_t)pushLimit:(size_t)byteLimit {
+ return GPBCodedInputStreamPushLimit(&state_, byteLimit);
+}
+
+- (void)popLimit:(size_t)oldLimit {
+ GPBCodedInputStreamPopLimit(&state_, oldLimit);
+}
+
+- (double)readDouble {
+ return GPBCodedInputStreamReadDouble(&state_);
+}
+
+- (float)readFloat {
+ return GPBCodedInputStreamReadFloat(&state_);
+}
+
+- (uint64_t)readUInt64 {
+ return GPBCodedInputStreamReadUInt64(&state_);
+}
+
+- (int64_t)readInt64 {
+ return GPBCodedInputStreamReadInt64(&state_);
+}
+
+- (int32_t)readInt32 {
+ return GPBCodedInputStreamReadInt32(&state_);
+}
+
+- (uint64_t)readFixed64 {
+ return GPBCodedInputStreamReadFixed64(&state_);
+}
+
+- (uint32_t)readFixed32 {
+ return GPBCodedInputStreamReadFixed32(&state_);
+}
+
+- (BOOL)readBool {
+ return GPBCodedInputStreamReadBool(&state_);
+}
+
+- (NSString *)readString {
+ return [GPBCodedInputStreamReadRetainedString(&state_) autorelease];
+}
+
+- (void)readGroup:(int32_t)fieldNumber
+ message:(GPBMessage *)message
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ if (state_.recursionDepth >= kDefaultRecursionLimit) {
+ RaiseException(GPBCodedInputStreamErrorRecursionDepthExceeded, nil);
+ }
+ ++state_.recursionDepth;
+ [message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry];
+ GPBCodedInputStreamCheckLastTagWas(
+ &state_, GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup));
+ --state_.recursionDepth;
+}
+
+- (void)readUnknownGroup:(int32_t)fieldNumber
+ message:(GPBUnknownFieldSet *)message {
+ if (state_.recursionDepth >= kDefaultRecursionLimit) {
+ RaiseException(GPBCodedInputStreamErrorRecursionDepthExceeded, nil);
+ }
+ ++state_.recursionDepth;
+ [message mergeFromCodedInputStream:self];
+ GPBCodedInputStreamCheckLastTagWas(
+ &state_, GPBWireFormatMakeTag(fieldNumber, GPBWireFormatEndGroup));
+ --state_.recursionDepth;
+}
+
+- (void)readMessage:(GPBMessage *)message
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ int32_t length = ReadRawVarint32(&state_);
+ if (state_.recursionDepth >= kDefaultRecursionLimit) {
+ RaiseException(GPBCodedInputStreamErrorRecursionDepthExceeded, nil);
+ }
+ size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length);
+ ++state_.recursionDepth;
+ [message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry];
+ GPBCodedInputStreamCheckLastTagWas(&state_, 0);
+ --state_.recursionDepth;
+ GPBCodedInputStreamPopLimit(&state_, oldLimit);
+}
+
+- (void)readMapEntry:(id)mapDictionary
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ field:(GPBFieldDescriptor *)field
+ parentMessage:(GPBMessage *)parentMessage {
+ int32_t length = ReadRawVarint32(&state_);
+ if (state_.recursionDepth >= kDefaultRecursionLimit) {
+ RaiseException(GPBCodedInputStreamErrorRecursionDepthExceeded, nil);
+ }
+ size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length);
+ ++state_.recursionDepth;
+ GPBDictionaryReadEntry(mapDictionary, self, extensionRegistry, field,
+ parentMessage);
+ GPBCodedInputStreamCheckLastTagWas(&state_, 0);
+ --state_.recursionDepth;
+ GPBCodedInputStreamPopLimit(&state_, oldLimit);
+}
+
+- (NSData *)readBytes {
+ return [GPBCodedInputStreamReadRetainedBytes(&state_) autorelease];
+}
+
+- (uint32_t)readUInt32 {
+ return GPBCodedInputStreamReadUInt32(&state_);
+}
+
+- (int32_t)readEnum {
+ return GPBCodedInputStreamReadEnum(&state_);
+}
+
+- (int32_t)readSFixed32 {
+ return GPBCodedInputStreamReadSFixed32(&state_);
+}
+
+- (int64_t)readSFixed64 {
+ return GPBCodedInputStreamReadSFixed64(&state_);
+}
+
+- (int32_t)readSInt32 {
+ return GPBCodedInputStreamReadSInt32(&state_);
+}
+
+- (int64_t)readSInt64 {
+ return GPBCodedInputStreamReadSInt64(&state_);
+}
+
+#pragma clang diagnostic pop
+
+@end
diff --git a/third_party/protobuf/objectivec/GPBCodedInputStream_PackagePrivate.h b/third_party/protobuf/objectivec/GPBCodedInputStream_PackagePrivate.h
new file mode 100644
index 0000000000..90bd0c92ce
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBCodedInputStream_PackagePrivate.h
@@ -0,0 +1,114 @@
+// 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.
+
+// This header is private to the ProtobolBuffers library and must NOT be
+// included by any sources outside this library. The contents of this file are
+// subject to change at any time without notice.
+
+#import "GPBCodedInputStream.h"
+
+#import <libkern/OSAtomic.h>
+
+@class GPBUnknownFieldSet;
+@class GPBFieldDescriptor;
+
+typedef struct GPBCodedInputStreamState {
+ const uint8_t *bytes;
+ size_t bufferSize;
+ size_t bufferPos;
+
+ // For parsing subsections of an input stream you can put a hard limit on
+ // how much should be read. Normally the limit is the end of the stream,
+ // but you can adjust it to anywhere, and if you hit it you will be at the
+ // end of the stream, until you adjust the limit.
+ size_t currentLimit;
+ int32_t lastTag;
+ NSUInteger recursionDepth;
+} GPBCodedInputStreamState;
+
+@interface GPBCodedInputStream () {
+ @package
+ struct GPBCodedInputStreamState state_;
+ NSData *buffer_;
+}
+
+// Group support is deprecated, so we hide this interface from users, but
+// support for older data.
+- (void)readGroup:(int32_t)fieldNumber
+ message:(GPBMessage *)message
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry;
+
+// Reads a group field value from the stream and merges it into the given
+// UnknownFieldSet.
+- (void)readUnknownGroup:(int32_t)fieldNumber
+ message:(GPBUnknownFieldSet *)message;
+
+// Reads a map entry.
+- (void)readMapEntry:(id)mapDictionary
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ field:(GPBFieldDescriptor *)field
+ parentMessage:(GPBMessage *)parentMessage;
+@end
+
+CF_EXTERN_C_BEGIN
+
+int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state);
+
+double GPBCodedInputStreamReadDouble(GPBCodedInputStreamState *state);
+float GPBCodedInputStreamReadFloat(GPBCodedInputStreamState *state);
+uint64_t GPBCodedInputStreamReadUInt64(GPBCodedInputStreamState *state);
+uint32_t GPBCodedInputStreamReadUInt32(GPBCodedInputStreamState *state);
+int64_t GPBCodedInputStreamReadInt64(GPBCodedInputStreamState *state);
+int32_t GPBCodedInputStreamReadInt32(GPBCodedInputStreamState *state);
+uint64_t GPBCodedInputStreamReadFixed64(GPBCodedInputStreamState *state);
+uint32_t GPBCodedInputStreamReadFixed32(GPBCodedInputStreamState *state);
+int32_t GPBCodedInputStreamReadEnum(GPBCodedInputStreamState *state);
+int32_t GPBCodedInputStreamReadSFixed32(GPBCodedInputStreamState *state);
+int64_t GPBCodedInputStreamReadSFixed64(GPBCodedInputStreamState *state);
+int32_t GPBCodedInputStreamReadSInt32(GPBCodedInputStreamState *state);
+int64_t GPBCodedInputStreamReadSInt64(GPBCodedInputStreamState *state);
+BOOL GPBCodedInputStreamReadBool(GPBCodedInputStreamState *state);
+NSString *GPBCodedInputStreamReadRetainedString(GPBCodedInputStreamState *state)
+ __attribute((ns_returns_retained));
+NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state)
+ __attribute((ns_returns_retained));
+NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(
+ GPBCodedInputStreamState *state) __attribute((ns_returns_retained));
+
+size_t GPBCodedInputStreamPushLimit(GPBCodedInputStreamState *state,
+ size_t byteLimit);
+void GPBCodedInputStreamPopLimit(GPBCodedInputStreamState *state,
+ size_t oldLimit);
+size_t GPBCodedInputStreamBytesUntilLimit(GPBCodedInputStreamState *state);
+BOOL GPBCodedInputStreamIsAtEnd(GPBCodedInputStreamState *state);
+void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state,
+ int32_t value);
+
+CF_EXTERN_C_END
diff --git a/third_party/protobuf/objectivec/GPBCodedOutputStream.h b/third_party/protobuf/objectivec/GPBCodedOutputStream.h
new file mode 100644
index 0000000000..d6fff3dbb6
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBCodedOutputStream.h
@@ -0,0 +1,739 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBRuntimeTypes.h"
+#import "GPBWireFormat.h"
+
+@class GPBBoolArray;
+@class GPBDoubleArray;
+@class GPBEnumArray;
+@class GPBFloatArray;
+@class GPBMessage;
+@class GPBInt32Array;
+@class GPBInt64Array;
+@class GPBUInt32Array;
+@class GPBUInt64Array;
+@class GPBUnknownFieldSet;
+
+NS_ASSUME_NONNULL_BEGIN
+
+/**
+ * Writes out protocol message fields.
+ *
+ * The common uses of protocol buffers shouldn't need to use this class.
+ * GPBMessage's provide a -data method that will serialize the message for you.
+ *
+ * @note Subclassing of GPBCodedOutputStream is NOT supported.
+ **/
+@interface GPBCodedOutputStream : NSObject
+
+/**
+ * Creates a stream to fill in the given data. Data must be sized to fit or
+ * an error will be raised when out of space.
+ *
+ * @param data The data where the stream will be written to.
+ *
+ * @return A newly instanced GPBCodedOutputStream.
+ **/
++ (instancetype)streamWithData:(NSMutableData *)data;
+
+/**
+ * Creates a stream to write into the given NSOutputStream.
+ *
+ * @param output The output stream where the stream will be written to.
+ *
+ * @return A newly instanced GPBCodedOutputStream.
+ **/
++ (instancetype)streamWithOutputStream:(NSOutputStream *)output;
+
+/**
+ * Initializes a stream to fill in the given data. Data must be sized to fit
+ * or an error will be raised when out of space.
+ *
+ * @param data The data where the stream will be written to.
+ *
+ * @return A newly initialized GPBCodedOutputStream.
+ **/
+- (instancetype)initWithData:(NSMutableData *)data;
+
+/**
+ * Initializes a stream to write into the given @c NSOutputStream.
+ *
+ * @param output The output stream where the stream will be written to.
+ *
+ * @return A newly initialized GPBCodedOutputStream.
+ **/
+- (instancetype)initWithOutputStream:(NSOutputStream *)output;
+
+/**
+ * Flush any buffered data out.
+ **/
+- (void)flush;
+
+/**
+ * Write the raw byte out.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeRawByte:(uint8_t)value;
+
+/**
+ * Write the tag for the given field number and wire format.
+ *
+ * @param fieldNumber The field number.
+ * @param format The wire format the data for the field will be in.
+ **/
+- (void)writeTag:(uint32_t)fieldNumber format:(GPBWireFormat)format;
+
+/**
+ * Write a 32bit value out in little endian format.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeRawLittleEndian32:(int32_t)value;
+/**
+ * Write a 64bit value out in little endian format.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeRawLittleEndian64:(int64_t)value;
+
+/**
+ * Write a 32bit value out in varint format.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeRawVarint32:(int32_t)value;
+/**
+ * Write a 64bit value out in varint format.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeRawVarint64:(int64_t)value;
+
+/**
+ * Write a size_t out as a 32bit varint value.
+ *
+ * @note This will truncate 64 bit values to 32.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeRawVarintSizeTAs32:(size_t)value;
+
+/**
+ * Writes the contents of an NSData out.
+ *
+ * @param data The data to write out.
+ **/
+- (void)writeRawData:(NSData *)data;
+/**
+ * Writes out the given data.
+ *
+ * @param data The data blob to write out.
+ * @param offset The offset into the blob to start writing out.
+ * @param length The number of bytes from the blob to write out.
+ **/
+- (void)writeRawPtr:(const void *)data
+ offset:(size_t)offset
+ length:(size_t)length;
+
+//%PDDM-EXPAND _WRITE_DECLS()
+// This block of code is generated, do not edit it directly.
+
+/**
+ * Write a double for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeDouble:(int32_t)fieldNumber value:(double)value;
+/**
+ * Write a packed array of double for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeDoubleArray:(int32_t)fieldNumber
+ values:(GPBDoubleArray *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a double without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeDoubleNoTag:(double)value;
+
+/**
+ * Write a float for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeFloat:(int32_t)fieldNumber value:(float)value;
+/**
+ * Write a packed array of float for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeFloatArray:(int32_t)fieldNumber
+ values:(GPBFloatArray *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a float without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeFloatNoTag:(float)value;
+
+/**
+ * Write a uint64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeUInt64:(int32_t)fieldNumber value:(uint64_t)value;
+/**
+ * Write a packed array of uint64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeUInt64Array:(int32_t)fieldNumber
+ values:(GPBUInt64Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a uint64_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeUInt64NoTag:(uint64_t)value;
+
+/**
+ * Write a int64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeInt64:(int32_t)fieldNumber value:(int64_t)value;
+/**
+ * Write a packed array of int64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeInt64Array:(int32_t)fieldNumber
+ values:(GPBInt64Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a int64_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeInt64NoTag:(int64_t)value;
+
+/**
+ * Write a int32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeInt32:(int32_t)fieldNumber value:(int32_t)value;
+/**
+ * Write a packed array of int32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeInt32Array:(int32_t)fieldNumber
+ values:(GPBInt32Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a int32_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeInt32NoTag:(int32_t)value;
+
+/**
+ * Write a uint32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeUInt32:(int32_t)fieldNumber value:(uint32_t)value;
+/**
+ * Write a packed array of uint32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeUInt32Array:(int32_t)fieldNumber
+ values:(GPBUInt32Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a uint32_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeUInt32NoTag:(uint32_t)value;
+
+/**
+ * Write a uint64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeFixed64:(int32_t)fieldNumber value:(uint64_t)value;
+/**
+ * Write a packed array of uint64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeFixed64Array:(int32_t)fieldNumber
+ values:(GPBUInt64Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a uint64_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeFixed64NoTag:(uint64_t)value;
+
+/**
+ * Write a uint32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeFixed32:(int32_t)fieldNumber value:(uint32_t)value;
+/**
+ * Write a packed array of uint32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeFixed32Array:(int32_t)fieldNumber
+ values:(GPBUInt32Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a uint32_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeFixed32NoTag:(uint32_t)value;
+
+/**
+ * Write a int32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeSInt32:(int32_t)fieldNumber value:(int32_t)value;
+/**
+ * Write a packed array of int32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeSInt32Array:(int32_t)fieldNumber
+ values:(GPBInt32Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a int32_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeSInt32NoTag:(int32_t)value;
+
+/**
+ * Write a int64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeSInt64:(int32_t)fieldNumber value:(int64_t)value;
+/**
+ * Write a packed array of int64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeSInt64Array:(int32_t)fieldNumber
+ values:(GPBInt64Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a int64_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeSInt64NoTag:(int64_t)value;
+
+/**
+ * Write a int64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeSFixed64:(int32_t)fieldNumber value:(int64_t)value;
+/**
+ * Write a packed array of int64_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeSFixed64Array:(int32_t)fieldNumber
+ values:(GPBInt64Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a int64_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeSFixed64NoTag:(int64_t)value;
+
+/**
+ * Write a int32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeSFixed32:(int32_t)fieldNumber value:(int32_t)value;
+/**
+ * Write a packed array of int32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeSFixed32Array:(int32_t)fieldNumber
+ values:(GPBInt32Array *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a int32_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeSFixed32NoTag:(int32_t)value;
+
+/**
+ * Write a BOOL for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeBool:(int32_t)fieldNumber value:(BOOL)value;
+/**
+ * Write a packed array of BOOL for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeBoolArray:(int32_t)fieldNumber
+ values:(GPBBoolArray *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a BOOL without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeBoolNoTag:(BOOL)value;
+
+/**
+ * Write a int32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeEnum:(int32_t)fieldNumber value:(int32_t)value;
+/**
+ * Write a packed array of int32_t for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ * @param tag The tag assigned to the values.
+ **/
+- (void)writeEnumArray:(int32_t)fieldNumber
+ values:(GPBEnumArray *)values
+ tag:(uint32_t)tag;
+/**
+ * Write a int32_t without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeEnumNoTag:(int32_t)value;
+
+/**
+ * Write a NSString for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeString:(int32_t)fieldNumber value:(NSString *)value;
+/**
+ * Write an array of NSString for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ **/
+- (void)writeStringArray:(int32_t)fieldNumber values:(NSArray<NSString*> *)values;
+/**
+ * Write a NSString without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeStringNoTag:(NSString *)value;
+
+/**
+ * Write a GPBMessage for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeMessage:(int32_t)fieldNumber value:(GPBMessage *)value;
+/**
+ * Write an array of GPBMessage for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ **/
+- (void)writeMessageArray:(int32_t)fieldNumber values:(NSArray<GPBMessage*> *)values;
+/**
+ * Write a GPBMessage without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeMessageNoTag:(GPBMessage *)value;
+
+/**
+ * Write a NSData for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeBytes:(int32_t)fieldNumber value:(NSData *)value;
+/**
+ * Write an array of NSData for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ **/
+- (void)writeBytesArray:(int32_t)fieldNumber values:(NSArray<NSData*> *)values;
+/**
+ * Write a NSData without any tag.
+ *
+ * @param value The value to write out.
+ **/
+- (void)writeBytesNoTag:(NSData *)value;
+
+/**
+ * Write a GPBMessage for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeGroup:(int32_t)fieldNumber
+ value:(GPBMessage *)value;
+/**
+ * Write an array of GPBMessage for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ **/
+- (void)writeGroupArray:(int32_t)fieldNumber values:(NSArray<GPBMessage*> *)values;
+/**
+ * Write a GPBMessage without any tag (but does write the endGroup tag).
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeGroupNoTag:(int32_t)fieldNumber
+ value:(GPBMessage *)value;
+
+/**
+ * Write a GPBUnknownFieldSet for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeUnknownGroup:(int32_t)fieldNumber
+ value:(GPBUnknownFieldSet *)value;
+/**
+ * Write an array of GPBUnknownFieldSet for the given field number.
+ *
+ * @param fieldNumber The field number assigned to the values.
+ * @param values The values to write out.
+ **/
+- (void)writeUnknownGroupArray:(int32_t)fieldNumber values:(NSArray<GPBUnknownFieldSet*> *)values;
+/**
+ * Write a GPBUnknownFieldSet without any tag (but does write the endGroup tag).
+ *
+ * @param fieldNumber The field number assigned to the value.
+ * @param value The value to write out.
+ **/
+- (void)writeUnknownGroupNoTag:(int32_t)fieldNumber
+ value:(GPBUnknownFieldSet *)value;
+
+//%PDDM-EXPAND-END _WRITE_DECLS()
+
+/**
+Write a MessageSet extension field to the stream. For historical reasons,
+the wire format differs from normal fields.
+
+@param fieldNumber The extension field number to write out.
+@param value The message from where to get the extension.
+*/
+- (void)writeMessageSetExtension:(int32_t)fieldNumber value:(GPBMessage *)value;
+
+/**
+Write an unparsed MessageSet extension field to the stream. For historical
+reasons, the wire format differs from normal fields.
+
+@param fieldNumber The extension field number to write out.
+@param value The raw message from where to get the extension.
+*/
+- (void)writeRawMessageSetExtension:(int32_t)fieldNumber value:(NSData *)value;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+// Write methods for types that can be in packed arrays.
+//%PDDM-DEFINE _WRITE_PACKABLE_DECLS(NAME, ARRAY_TYPE, TYPE)
+//%/**
+//% * Write a TYPE for the given field number.
+//% *
+//% * @param fieldNumber The field number assigned to the value.
+//% * @param value The value to write out.
+//% **/
+//%- (void)write##NAME:(int32_t)fieldNumber value:(TYPE)value;
+//%/**
+//% * Write a packed array of TYPE for the given field number.
+//% *
+//% * @param fieldNumber The field number assigned to the values.
+//% * @param values The values to write out.
+//% * @param tag The tag assigned to the values.
+//% **/
+//%- (void)write##NAME##Array:(int32_t)fieldNumber
+//% NAME$S values:(GPB##ARRAY_TYPE##Array *)values
+//% NAME$S tag:(uint32_t)tag;
+//%/**
+//% * Write a TYPE without any tag.
+//% *
+//% * @param value The value to write out.
+//% **/
+//%- (void)write##NAME##NoTag:(TYPE)value;
+//%
+// Write methods for types that aren't in packed arrays.
+//%PDDM-DEFINE _WRITE_UNPACKABLE_DECLS(NAME, TYPE)
+//%/**
+//% * Write a TYPE for the given field number.
+//% *
+//% * @param fieldNumber The field number assigned to the value.
+//% * @param value The value to write out.
+//% **/
+//%- (void)write##NAME:(int32_t)fieldNumber value:(TYPE *)value;
+//%/**
+//% * Write an array of TYPE for the given field number.
+//% *
+//% * @param fieldNumber The field number assigned to the values.
+//% * @param values The values to write out.
+//% **/
+//%- (void)write##NAME##Array:(int32_t)fieldNumber values:(NSArray<##TYPE##*> *)values;
+//%/**
+//% * Write a TYPE without any tag.
+//% *
+//% * @param value The value to write out.
+//% **/
+//%- (void)write##NAME##NoTag:(TYPE *)value;
+//%
+// Special write methods for Groups.
+//%PDDM-DEFINE _WRITE_GROUP_DECLS(NAME, TYPE)
+//%/**
+//% * Write a TYPE for the given field number.
+//% *
+//% * @param fieldNumber The field number assigned to the value.
+//% * @param value The value to write out.
+//% **/
+//%- (void)write##NAME:(int32_t)fieldNumber
+//% NAME$S value:(TYPE *)value;
+//%/**
+//% * Write an array of TYPE for the given field number.
+//% *
+//% * @param fieldNumber The field number assigned to the values.
+//% * @param values The values to write out.
+//% **/
+//%- (void)write##NAME##Array:(int32_t)fieldNumber values:(NSArray<##TYPE##*> *)values;
+//%/**
+//% * Write a TYPE without any tag (but does write the endGroup tag).
+//% *
+//% * @param fieldNumber The field number assigned to the value.
+//% * @param value The value to write out.
+//% **/
+//%- (void)write##NAME##NoTag:(int32_t)fieldNumber
+//% NAME$S value:(TYPE *)value;
+//%
+
+// One macro to hide it all up above.
+//%PDDM-DEFINE _WRITE_DECLS()
+//%_WRITE_PACKABLE_DECLS(Double, Double, double)
+//%_WRITE_PACKABLE_DECLS(Float, Float, float)
+//%_WRITE_PACKABLE_DECLS(UInt64, UInt64, uint64_t)
+//%_WRITE_PACKABLE_DECLS(Int64, Int64, int64_t)
+//%_WRITE_PACKABLE_DECLS(Int32, Int32, int32_t)
+//%_WRITE_PACKABLE_DECLS(UInt32, UInt32, uint32_t)
+//%_WRITE_PACKABLE_DECLS(Fixed64, UInt64, uint64_t)
+//%_WRITE_PACKABLE_DECLS(Fixed32, UInt32, uint32_t)
+//%_WRITE_PACKABLE_DECLS(SInt32, Int32, int32_t)
+//%_WRITE_PACKABLE_DECLS(SInt64, Int64, int64_t)
+//%_WRITE_PACKABLE_DECLS(SFixed64, Int64, int64_t)
+//%_WRITE_PACKABLE_DECLS(SFixed32, Int32, int32_t)
+//%_WRITE_PACKABLE_DECLS(Bool, Bool, BOOL)
+//%_WRITE_PACKABLE_DECLS(Enum, Enum, int32_t)
+//%_WRITE_UNPACKABLE_DECLS(String, NSString)
+//%_WRITE_UNPACKABLE_DECLS(Message, GPBMessage)
+//%_WRITE_UNPACKABLE_DECLS(Bytes, NSData)
+//%_WRITE_GROUP_DECLS(Group, GPBMessage)
+//%_WRITE_GROUP_DECLS(UnknownGroup, GPBUnknownFieldSet)
diff --git a/third_party/protobuf/objectivec/GPBCodedOutputStream.m b/third_party/protobuf/objectivec/GPBCodedOutputStream.m
new file mode 100644
index 0000000000..7c3ab44715
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBCodedOutputStream.m
@@ -0,0 +1,1202 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBCodedOutputStream_PackagePrivate.h"
+
+#import <mach/vm_param.h>
+
+#import "GPBArray.h"
+#import "GPBUnknownFieldSet_PackagePrivate.h"
+#import "GPBUtilities_PackagePrivate.h"
+
+// Structure for containing state of a GPBCodedInputStream. Brought out into
+// a struct so that we can inline several common functions instead of dealing
+// with overhead of ObjC dispatch.
+typedef struct GPBOutputBufferState {
+ uint8_t *bytes;
+ size_t size;
+ size_t position;
+ NSOutputStream *output;
+} GPBOutputBufferState;
+
+@implementation GPBCodedOutputStream {
+ GPBOutputBufferState state_;
+ NSMutableData *buffer_;
+}
+
+static const int32_t LITTLE_ENDIAN_32_SIZE = sizeof(uint32_t);
+static const int32_t LITTLE_ENDIAN_64_SIZE = sizeof(uint64_t);
+
+// Internal helper that writes the current buffer to the output. The
+// buffer position is reset to its initial value when this returns.
+static void GPBRefreshBuffer(GPBOutputBufferState *state) {
+ if (state->output == nil) {
+ // We're writing to a single buffer.
+ [NSException raise:@"OutOfSpace" format:@""];
+ }
+ if (state->position != 0) {
+ NSInteger written =
+ [state->output write:state->bytes maxLength:state->position];
+ if (written != (NSInteger)state->position) {
+ [NSException raise:@"WriteFailed" format:@""];
+ }
+ state->position = 0;
+ }
+}
+
+static void GPBWriteRawByte(GPBOutputBufferState *state, uint8_t value) {
+ if (state->position == state->size) {
+ GPBRefreshBuffer(state);
+ }
+ state->bytes[state->position++] = value;
+}
+
+static void GPBWriteRawVarint32(GPBOutputBufferState *state, int32_t value) {
+ while (YES) {
+ if ((value & ~0x7F) == 0) {
+ uint8_t val = (uint8_t)value;
+ GPBWriteRawByte(state, val);
+ return;
+ } else {
+ GPBWriteRawByte(state, (value & 0x7F) | 0x80);
+ value = GPBLogicalRightShift32(value, 7);
+ }
+ }
+}
+
+static void GPBWriteRawVarint64(GPBOutputBufferState *state, int64_t value) {
+ while (YES) {
+ if ((value & ~0x7FL) == 0) {
+ uint8_t val = (uint8_t)value;
+ GPBWriteRawByte(state, val);
+ return;
+ } else {
+ GPBWriteRawByte(state, ((int32_t)value & 0x7F) | 0x80);
+ value = GPBLogicalRightShift64(value, 7);
+ }
+ }
+}
+
+static void GPBWriteInt32NoTag(GPBOutputBufferState *state, int32_t value) {
+ if (value >= 0) {
+ GPBWriteRawVarint32(state, value);
+ } else {
+ // Must sign-extend
+ GPBWriteRawVarint64(state, value);
+ }
+}
+
+static void GPBWriteUInt32(GPBOutputBufferState *state, int32_t fieldNumber,
+ uint32_t value) {
+ GPBWriteTagWithFormat(state, fieldNumber, GPBWireFormatVarint);
+ GPBWriteRawVarint32(state, value);
+}
+
+static void GPBWriteTagWithFormat(GPBOutputBufferState *state,
+ uint32_t fieldNumber, GPBWireFormat format) {
+ GPBWriteRawVarint32(state, GPBWireFormatMakeTag(fieldNumber, format));
+}
+
+static void GPBWriteRawLittleEndian32(GPBOutputBufferState *state,
+ int32_t value) {
+ GPBWriteRawByte(state, (value)&0xFF);
+ GPBWriteRawByte(state, (value >> 8) & 0xFF);
+ GPBWriteRawByte(state, (value >> 16) & 0xFF);
+ GPBWriteRawByte(state, (value >> 24) & 0xFF);
+}
+
+static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state,
+ int64_t value) {
+ GPBWriteRawByte(state, (int32_t)(value)&0xFF);
+ GPBWriteRawByte(state, (int32_t)(value >> 8) & 0xFF);
+ GPBWriteRawByte(state, (int32_t)(value >> 16) & 0xFF);
+ GPBWriteRawByte(state, (int32_t)(value >> 24) & 0xFF);
+ GPBWriteRawByte(state, (int32_t)(value >> 32) & 0xFF);
+ GPBWriteRawByte(state, (int32_t)(value >> 40) & 0xFF);
+ GPBWriteRawByte(state, (int32_t)(value >> 48) & 0xFF);
+ GPBWriteRawByte(state, (int32_t)(value >> 56) & 0xFF);
+}
+
+- (void)dealloc {
+ [self flush];
+ [state_.output close];
+ [state_.output release];
+ [buffer_ release];
+
+ [super dealloc];
+}
+
+- (instancetype)initWithOutputStream:(NSOutputStream *)output {
+ NSMutableData *data = [NSMutableData dataWithLength:PAGE_SIZE];
+ return [self initWithOutputStream:output data:data];
+}
+
+- (instancetype)initWithData:(NSMutableData *)data {
+ return [self initWithOutputStream:nil data:data];
+}
+
+// This initializer isn't exposed, but it is the designated initializer.
+// Setting OutputStream and NSData is to control the buffering behavior/size
+// of the work, but that is more obvious via the bufferSize: version.
+- (instancetype)initWithOutputStream:(NSOutputStream *)output
+ data:(NSMutableData *)data {
+ if ((self = [super init])) {
+ buffer_ = [data retain];
+ [output open];
+ state_.bytes = [data mutableBytes];
+ state_.size = [data length];
+ state_.output = [output retain];
+ }
+ return self;
+}
+
++ (instancetype)streamWithOutputStream:(NSOutputStream *)output {
+ NSMutableData *data = [NSMutableData dataWithLength:PAGE_SIZE];
+ return [[[self alloc] initWithOutputStream:output
+ data:data] autorelease];
+}
+
++ (instancetype)streamWithData:(NSMutableData *)data {
+ return [[[self alloc] initWithData:data] autorelease];
+}
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+- (void)writeDoubleNoTag:(double)value {
+ GPBWriteRawLittleEndian64(&state_, GPBConvertDoubleToInt64(value));
+}
+
+- (void)writeDouble:(int32_t)fieldNumber value:(double)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed64);
+ GPBWriteRawLittleEndian64(&state_, GPBConvertDoubleToInt64(value));
+}
+
+- (void)writeFloatNoTag:(float)value {
+ GPBWriteRawLittleEndian32(&state_, GPBConvertFloatToInt32(value));
+}
+
+- (void)writeFloat:(int32_t)fieldNumber value:(float)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed32);
+ GPBWriteRawLittleEndian32(&state_, GPBConvertFloatToInt32(value));
+}
+
+- (void)writeUInt64NoTag:(uint64_t)value {
+ GPBWriteRawVarint64(&state_, value);
+}
+
+- (void)writeUInt64:(int32_t)fieldNumber value:(uint64_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint);
+ GPBWriteRawVarint64(&state_, value);
+}
+
+- (void)writeInt64NoTag:(int64_t)value {
+ GPBWriteRawVarint64(&state_, value);
+}
+
+- (void)writeInt64:(int32_t)fieldNumber value:(int64_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint);
+ GPBWriteRawVarint64(&state_, value);
+}
+
+- (void)writeInt32NoTag:(int32_t)value {
+ GPBWriteInt32NoTag(&state_, value);
+}
+
+- (void)writeInt32:(int32_t)fieldNumber value:(int32_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint);
+ GPBWriteInt32NoTag(&state_, value);
+}
+
+- (void)writeFixed64NoTag:(uint64_t)value {
+ GPBWriteRawLittleEndian64(&state_, value);
+}
+
+- (void)writeFixed64:(int32_t)fieldNumber value:(uint64_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed64);
+ GPBWriteRawLittleEndian64(&state_, value);
+}
+
+- (void)writeFixed32NoTag:(uint32_t)value {
+ GPBWriteRawLittleEndian32(&state_, value);
+}
+
+- (void)writeFixed32:(int32_t)fieldNumber value:(uint32_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed32);
+ GPBWriteRawLittleEndian32(&state_, value);
+}
+
+- (void)writeBoolNoTag:(BOOL)value {
+ GPBWriteRawByte(&state_, (value ? 1 : 0));
+}
+
+- (void)writeBool:(int32_t)fieldNumber value:(BOOL)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint);
+ GPBWriteRawByte(&state_, (value ? 1 : 0));
+}
+
+- (void)writeStringNoTag:(const NSString *)value {
+ size_t length = [value lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+ GPBWriteRawVarint32(&state_, (int32_t)length);
+ if (length == 0) {
+ return;
+ }
+
+ const char *quickString =
+ CFStringGetCStringPtr((CFStringRef)value, kCFStringEncodingUTF8);
+
+ // Fast path: Most strings are short, if the buffer already has space,
+ // add to it directly.
+ NSUInteger bufferBytesLeft = state_.size - state_.position;
+ if (bufferBytesLeft >= length) {
+ NSUInteger usedBufferLength = 0;
+ BOOL result;
+ if (quickString != NULL) {
+ memcpy(state_.bytes + state_.position, quickString, length);
+ usedBufferLength = length;
+ result = YES;
+ } else {
+ result = [value getBytes:state_.bytes + state_.position
+ maxLength:bufferBytesLeft
+ usedLength:&usedBufferLength
+ encoding:NSUTF8StringEncoding
+ options:(NSStringEncodingConversionOptions)0
+ range:NSMakeRange(0, [value length])
+ remainingRange:NULL];
+ }
+ if (result) {
+ NSAssert2((usedBufferLength == length),
+ @"Our UTF8 calc was wrong? %tu vs %zd", usedBufferLength,
+ length);
+ state_.position += usedBufferLength;
+ return;
+ }
+ } else if (quickString != NULL) {
+ [self writeRawPtr:quickString offset:0 length:length];
+ } else {
+ // Slow path: just get it as data and write it out.
+ NSData *utf8Data = [value dataUsingEncoding:NSUTF8StringEncoding];
+ NSAssert2(([utf8Data length] == length),
+ @"Strings UTF8 length was wrong? %tu vs %zd", [utf8Data length],
+ length);
+ [self writeRawData:utf8Data];
+ }
+}
+
+- (void)writeString:(int32_t)fieldNumber value:(NSString *)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatLengthDelimited);
+ [self writeStringNoTag:value];
+}
+
+- (void)writeGroupNoTag:(int32_t)fieldNumber value:(GPBMessage *)value {
+ [value writeToCodedOutputStream:self];
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatEndGroup);
+}
+
+- (void)writeGroup:(int32_t)fieldNumber value:(GPBMessage *)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatStartGroup);
+ [self writeGroupNoTag:fieldNumber value:value];
+}
+
+- (void)writeUnknownGroupNoTag:(int32_t)fieldNumber
+ value:(const GPBUnknownFieldSet *)value {
+ [value writeToCodedOutputStream:self];
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatEndGroup);
+}
+
+- (void)writeUnknownGroup:(int32_t)fieldNumber
+ value:(GPBUnknownFieldSet *)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatStartGroup);
+ [self writeUnknownGroupNoTag:fieldNumber value:value];
+}
+
+- (void)writeMessageNoTag:(GPBMessage *)value {
+ GPBWriteRawVarint32(&state_, (int32_t)[value serializedSize]);
+ [value writeToCodedOutputStream:self];
+}
+
+- (void)writeMessage:(int32_t)fieldNumber value:(GPBMessage *)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatLengthDelimited);
+ [self writeMessageNoTag:value];
+}
+
+- (void)writeBytesNoTag:(NSData *)value {
+ GPBWriteRawVarint32(&state_, (int32_t)[value length]);
+ [self writeRawData:value];
+}
+
+- (void)writeBytes:(int32_t)fieldNumber value:(NSData *)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatLengthDelimited);
+ [self writeBytesNoTag:value];
+}
+
+- (void)writeUInt32NoTag:(uint32_t)value {
+ GPBWriteRawVarint32(&state_, value);
+}
+
+- (void)writeUInt32:(int32_t)fieldNumber value:(uint32_t)value {
+ GPBWriteUInt32(&state_, fieldNumber, value);
+}
+
+- (void)writeEnumNoTag:(int32_t)value {
+ GPBWriteRawVarint32(&state_, value);
+}
+
+- (void)writeEnum:(int32_t)fieldNumber value:(int32_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint);
+ GPBWriteRawVarint32(&state_, value);
+}
+
+- (void)writeSFixed32NoTag:(int32_t)value {
+ GPBWriteRawLittleEndian32(&state_, value);
+}
+
+- (void)writeSFixed32:(int32_t)fieldNumber value:(int32_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed32);
+ GPBWriteRawLittleEndian32(&state_, value);
+}
+
+- (void)writeSFixed64NoTag:(int64_t)value {
+ GPBWriteRawLittleEndian64(&state_, value);
+}
+
+- (void)writeSFixed64:(int32_t)fieldNumber value:(int64_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatFixed64);
+ GPBWriteRawLittleEndian64(&state_, value);
+}
+
+- (void)writeSInt32NoTag:(int32_t)value {
+ GPBWriteRawVarint32(&state_, GPBEncodeZigZag32(value));
+}
+
+- (void)writeSInt32:(int32_t)fieldNumber value:(int32_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint);
+ GPBWriteRawVarint32(&state_, GPBEncodeZigZag32(value));
+}
+
+- (void)writeSInt64NoTag:(int64_t)value {
+ GPBWriteRawVarint64(&state_, GPBEncodeZigZag64(value));
+}
+
+- (void)writeSInt64:(int32_t)fieldNumber value:(int64_t)value {
+ GPBWriteTagWithFormat(&state_, fieldNumber, GPBWireFormatVarint);
+ GPBWriteRawVarint64(&state_, GPBEncodeZigZag64(value));
+}
+
+//%PDDM-DEFINE WRITE_PACKABLE_DEFNS(NAME, ARRAY_TYPE, TYPE, ACCESSOR_NAME)
+//%- (void)write##NAME##Array:(int32_t)fieldNumber
+//% NAME$S values:(GPB##ARRAY_TYPE##Array *)values
+//% NAME$S tag:(uint32_t)tag {
+//% if (tag != 0) {
+//% if (values.count == 0) return;
+//% __block size_t dataSize = 0;
+//% [values enumerate##ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//%#pragma unused(idx, stop)
+//% dataSize += GPBCompute##NAME##SizeNoTag(value);
+//% }];
+//% GPBWriteRawVarint32(&state_, tag);
+//% GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+//% [values enumerate##ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//%#pragma unused(idx, stop)
+//% [self write##NAME##NoTag:value];
+//% }];
+//% } else {
+//% [values enumerate##ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//%#pragma unused(idx, stop)
+//% [self write##NAME:fieldNumber value:value];
+//% }];
+//% }
+//%}
+//%
+//%PDDM-DEFINE WRITE_UNPACKABLE_DEFNS(NAME, TYPE)
+//%- (void)write##NAME##Array:(int32_t)fieldNumber values:(NSArray *)values {
+//% for (TYPE *value in values) {
+//% [self write##NAME:fieldNumber value:value];
+//% }
+//%}
+//%
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Double, Double, double, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeDoubleArray:(int32_t)fieldNumber
+ values:(GPBDoubleArray *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeDoubleSizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeDoubleNoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeDouble:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Float, Float, float, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeFloatArray:(int32_t)fieldNumber
+ values:(GPBFloatArray *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeFloatSizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeFloatNoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeFloat:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(UInt64, UInt64, uint64_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeUInt64Array:(int32_t)fieldNumber
+ values:(GPBUInt64Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeUInt64SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeUInt64NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeUInt64:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Int64, Int64, int64_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeInt64Array:(int32_t)fieldNumber
+ values:(GPBInt64Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeInt64SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeInt64NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeInt64:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Int32, Int32, int32_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeInt32Array:(int32_t)fieldNumber
+ values:(GPBInt32Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeInt32SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeInt32NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeInt32:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(UInt32, UInt32, uint32_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeUInt32Array:(int32_t)fieldNumber
+ values:(GPBUInt32Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeUInt32SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeUInt32NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeUInt32:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Fixed64, UInt64, uint64_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeFixed64Array:(int32_t)fieldNumber
+ values:(GPBUInt64Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeFixed64SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeFixed64NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeFixed64:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Fixed32, UInt32, uint32_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeFixed32Array:(int32_t)fieldNumber
+ values:(GPBUInt32Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeFixed32SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeFixed32NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeFixed32:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(SInt32, Int32, int32_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeSInt32Array:(int32_t)fieldNumber
+ values:(GPBInt32Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeSInt32SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeSInt32NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeSInt32:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(SInt64, Int64, int64_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeSInt64Array:(int32_t)fieldNumber
+ values:(GPBInt64Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeSInt64SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeSInt64NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeSInt64:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(SFixed64, Int64, int64_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeSFixed64Array:(int32_t)fieldNumber
+ values:(GPBInt64Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeSFixed64SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeSFixed64NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeSFixed64:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(SFixed32, Int32, int32_t, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeSFixed32Array:(int32_t)fieldNumber
+ values:(GPBInt32Array *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeSFixed32SizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeSFixed32NoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeSFixed32:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Bool, Bool, BOOL, )
+// This block of code is generated, do not edit it directly.
+
+- (void)writeBoolArray:(int32_t)fieldNumber
+ values:(GPBBoolArray *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeBoolSizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeBoolNoTag:value];
+ }];
+ } else {
+ [values enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeBool:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_PACKABLE_DEFNS(Enum, Enum, int32_t, Raw)
+// This block of code is generated, do not edit it directly.
+
+- (void)writeEnumArray:(int32_t)fieldNumber
+ values:(GPBEnumArray *)values
+ tag:(uint32_t)tag {
+ if (tag != 0) {
+ if (values.count == 0) return;
+ __block size_t dataSize = 0;
+ [values enumerateRawValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ dataSize += GPBComputeEnumSizeNoTag(value);
+ }];
+ GPBWriteRawVarint32(&state_, tag);
+ GPBWriteRawVarint32(&state_, (int32_t)dataSize);
+ [values enumerateRawValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeEnumNoTag:value];
+ }];
+ } else {
+ [values enumerateRawValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [self writeEnum:fieldNumber value:value];
+ }];
+ }
+}
+
+//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(String, NSString)
+// This block of code is generated, do not edit it directly.
+
+- (void)writeStringArray:(int32_t)fieldNumber values:(NSArray *)values {
+ for (NSString *value in values) {
+ [self writeString:fieldNumber value:value];
+ }
+}
+
+//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(Message, GPBMessage)
+// This block of code is generated, do not edit it directly.
+
+- (void)writeMessageArray:(int32_t)fieldNumber values:(NSArray *)values {
+ for (GPBMessage *value in values) {
+ [self writeMessage:fieldNumber value:value];
+ }
+}
+
+//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(Bytes, NSData)
+// This block of code is generated, do not edit it directly.
+
+- (void)writeBytesArray:(int32_t)fieldNumber values:(NSArray *)values {
+ for (NSData *value in values) {
+ [self writeBytes:fieldNumber value:value];
+ }
+}
+
+//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(Group, GPBMessage)
+// This block of code is generated, do not edit it directly.
+
+- (void)writeGroupArray:(int32_t)fieldNumber values:(NSArray *)values {
+ for (GPBMessage *value in values) {
+ [self writeGroup:fieldNumber value:value];
+ }
+}
+
+//%PDDM-EXPAND WRITE_UNPACKABLE_DEFNS(UnknownGroup, GPBUnknownFieldSet)
+// This block of code is generated, do not edit it directly.
+
+- (void)writeUnknownGroupArray:(int32_t)fieldNumber values:(NSArray *)values {
+ for (GPBUnknownFieldSet *value in values) {
+ [self writeUnknownGroup:fieldNumber value:value];
+ }
+}
+
+//%PDDM-EXPAND-END (19 expansions)
+
+- (void)writeMessageSetExtension:(int32_t)fieldNumber
+ value:(GPBMessage *)value {
+ GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem,
+ GPBWireFormatStartGroup);
+ GPBWriteUInt32(&state_, GPBWireFormatMessageSetTypeId, fieldNumber);
+ [self writeMessage:GPBWireFormatMessageSetMessage value:value];
+ GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem,
+ GPBWireFormatEndGroup);
+}
+
+- (void)writeRawMessageSetExtension:(int32_t)fieldNumber value:(NSData *)value {
+ GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem,
+ GPBWireFormatStartGroup);
+ GPBWriteUInt32(&state_, GPBWireFormatMessageSetTypeId, fieldNumber);
+ [self writeBytes:GPBWireFormatMessageSetMessage value:value];
+ GPBWriteTagWithFormat(&state_, GPBWireFormatMessageSetItem,
+ GPBWireFormatEndGroup);
+}
+
+- (void)flush {
+ if (state_.output != nil) {
+ GPBRefreshBuffer(&state_);
+ }
+}
+
+- (void)writeRawByte:(uint8_t)value {
+ GPBWriteRawByte(&state_, value);
+}
+
+- (void)writeRawData:(const NSData *)data {
+ [self writeRawPtr:[data bytes] offset:0 length:[data length]];
+}
+
+- (void)writeRawPtr:(const void *)value
+ offset:(size_t)offset
+ length:(size_t)length {
+ if (value == nil || length == 0) {
+ return;
+ }
+
+ NSUInteger bufferLength = state_.size;
+ NSUInteger bufferBytesLeft = bufferLength - state_.position;
+ if (bufferBytesLeft >= length) {
+ // We have room in the current buffer.
+ memcpy(state_.bytes + state_.position, ((uint8_t *)value) + offset, length);
+ state_.position += length;
+ } else {
+ // Write extends past current buffer. Fill the rest of this buffer and
+ // flush.
+ size_t bytesWritten = bufferBytesLeft;
+ memcpy(state_.bytes + state_.position, ((uint8_t *)value) + offset,
+ bytesWritten);
+ offset += bytesWritten;
+ length -= bytesWritten;
+ state_.position = bufferLength;
+ GPBRefreshBuffer(&state_);
+ bufferLength = state_.size;
+
+ // Now deal with the rest.
+ // Since we have an output stream, this is our buffer
+ // and buffer offset == 0
+ if (length <= bufferLength) {
+ // Fits in new buffer.
+ memcpy(state_.bytes, ((uint8_t *)value) + offset, length);
+ state_.position = length;
+ } else {
+ // Write is very big. Let's do it all at once.
+ [state_.output write:((uint8_t *)value) + offset maxLength:length];
+ }
+ }
+}
+
+- (void)writeTag:(uint32_t)fieldNumber format:(GPBWireFormat)format {
+ GPBWriteTagWithFormat(&state_, fieldNumber, format);
+}
+
+- (void)writeRawVarint32:(int32_t)value {
+ GPBWriteRawVarint32(&state_, value);
+}
+
+- (void)writeRawVarintSizeTAs32:(size_t)value {
+ // Note the truncation.
+ GPBWriteRawVarint32(&state_, (int32_t)value);
+}
+
+- (void)writeRawVarint64:(int64_t)value {
+ GPBWriteRawVarint64(&state_, value);
+}
+
+- (void)writeRawLittleEndian32:(int32_t)value {
+ GPBWriteRawLittleEndian32(&state_, value);
+}
+
+- (void)writeRawLittleEndian64:(int64_t)value {
+ GPBWriteRawLittleEndian64(&state_, value);
+}
+
+#pragma clang diagnostic pop
+
+@end
+
+size_t GPBComputeDoubleSizeNoTag(Float64 value) {
+#pragma unused(value)
+ return LITTLE_ENDIAN_64_SIZE;
+}
+
+size_t GPBComputeFloatSizeNoTag(Float32 value) {
+#pragma unused(value)
+ return LITTLE_ENDIAN_32_SIZE;
+}
+
+size_t GPBComputeUInt64SizeNoTag(uint64_t value) {
+ return GPBComputeRawVarint64Size(value);
+}
+
+size_t GPBComputeInt64SizeNoTag(int64_t value) {
+ return GPBComputeRawVarint64Size(value);
+}
+
+size_t GPBComputeInt32SizeNoTag(int32_t value) {
+ if (value >= 0) {
+ return GPBComputeRawVarint32Size(value);
+ } else {
+ // Must sign-extend.
+ return 10;
+ }
+}
+
+size_t GPBComputeSizeTSizeAsInt32NoTag(size_t value) {
+ return GPBComputeInt32SizeNoTag((int32_t)value);
+}
+
+size_t GPBComputeFixed64SizeNoTag(uint64_t value) {
+#pragma unused(value)
+ return LITTLE_ENDIAN_64_SIZE;
+}
+
+size_t GPBComputeFixed32SizeNoTag(uint32_t value) {
+#pragma unused(value)
+ return LITTLE_ENDIAN_32_SIZE;
+}
+
+size_t GPBComputeBoolSizeNoTag(BOOL value) {
+#pragma unused(value)
+ return 1;
+}
+
+size_t GPBComputeStringSizeNoTag(NSString *value) {
+ NSUInteger length = [value lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+ return GPBComputeRawVarint32SizeForInteger(length) + length;
+}
+
+size_t GPBComputeGroupSizeNoTag(GPBMessage *value) {
+ return [value serializedSize];
+}
+
+size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value) {
+ return value.serializedSize;
+}
+
+size_t GPBComputeMessageSizeNoTag(GPBMessage *value) {
+ size_t size = [value serializedSize];
+ return GPBComputeRawVarint32SizeForInteger(size) + size;
+}
+
+size_t GPBComputeBytesSizeNoTag(NSData *value) {
+ NSUInteger valueLength = [value length];
+ return GPBComputeRawVarint32SizeForInteger(valueLength) + valueLength;
+}
+
+size_t GPBComputeUInt32SizeNoTag(int32_t value) {
+ return GPBComputeRawVarint32Size(value);
+}
+
+size_t GPBComputeEnumSizeNoTag(int32_t value) {
+ return GPBComputeRawVarint32Size(value);
+}
+
+size_t GPBComputeSFixed32SizeNoTag(int32_t value) {
+#pragma unused(value)
+ return LITTLE_ENDIAN_32_SIZE;
+}
+
+size_t GPBComputeSFixed64SizeNoTag(int64_t value) {
+#pragma unused(value)
+ return LITTLE_ENDIAN_64_SIZE;
+}
+
+size_t GPBComputeSInt32SizeNoTag(int32_t value) {
+ return GPBComputeRawVarint32Size(GPBEncodeZigZag32(value));
+}
+
+size_t GPBComputeSInt64SizeNoTag(int64_t value) {
+ return GPBComputeRawVarint64Size(GPBEncodeZigZag64(value));
+}
+
+size_t GPBComputeDoubleSize(int32_t fieldNumber, double value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeDoubleSizeNoTag(value);
+}
+
+size_t GPBComputeFloatSize(int32_t fieldNumber, float value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeFloatSizeNoTag(value);
+}
+
+size_t GPBComputeUInt64Size(int32_t fieldNumber, uint64_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeUInt64SizeNoTag(value);
+}
+
+size_t GPBComputeInt64Size(int32_t fieldNumber, int64_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeInt64SizeNoTag(value);
+}
+
+size_t GPBComputeInt32Size(int32_t fieldNumber, int32_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeInt32SizeNoTag(value);
+}
+
+size_t GPBComputeFixed64Size(int32_t fieldNumber, uint64_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeFixed64SizeNoTag(value);
+}
+
+size_t GPBComputeFixed32Size(int32_t fieldNumber, uint32_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeFixed32SizeNoTag(value);
+}
+
+size_t GPBComputeBoolSize(int32_t fieldNumber, BOOL value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeBoolSizeNoTag(value);
+}
+
+size_t GPBComputeStringSize(int32_t fieldNumber, NSString *value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeStringSizeNoTag(value);
+}
+
+size_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *value) {
+ return GPBComputeTagSize(fieldNumber) * 2 + GPBComputeGroupSizeNoTag(value);
+}
+
+size_t GPBComputeUnknownGroupSize(int32_t fieldNumber,
+ GPBUnknownFieldSet *value) {
+ return GPBComputeTagSize(fieldNumber) * 2 +
+ GPBComputeUnknownGroupSizeNoTag(value);
+}
+
+size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeMessageSizeNoTag(value);
+}
+
+size_t GPBComputeBytesSize(int32_t fieldNumber, NSData *value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeBytesSizeNoTag(value);
+}
+
+size_t GPBComputeUInt32Size(int32_t fieldNumber, uint32_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeUInt32SizeNoTag(value);
+}
+
+size_t GPBComputeEnumSize(int32_t fieldNumber, int32_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeEnumSizeNoTag(value);
+}
+
+size_t GPBComputeSFixed32Size(int32_t fieldNumber, int32_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeSFixed32SizeNoTag(value);
+}
+
+size_t GPBComputeSFixed64Size(int32_t fieldNumber, int64_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeSFixed64SizeNoTag(value);
+}
+
+size_t GPBComputeSInt32Size(int32_t fieldNumber, int32_t value) {
+ return GPBComputeTagSize(fieldNumber) + GPBComputeSInt32SizeNoTag(value);
+}
+
+size_t GPBComputeSInt64Size(int32_t fieldNumber, int64_t value) {
+ return GPBComputeTagSize(fieldNumber) +
+ GPBComputeRawVarint64Size(GPBEncodeZigZag64(value));
+}
+
+size_t GPBComputeMessageSetExtensionSize(int32_t fieldNumber,
+ GPBMessage *value) {
+ return GPBComputeTagSize(GPBWireFormatMessageSetItem) * 2 +
+ GPBComputeUInt32Size(GPBWireFormatMessageSetTypeId, fieldNumber) +
+ GPBComputeMessageSize(GPBWireFormatMessageSetMessage, value);
+}
+
+size_t GPBComputeRawMessageSetExtensionSize(int32_t fieldNumber,
+ NSData *value) {
+ return GPBComputeTagSize(GPBWireFormatMessageSetItem) * 2 +
+ GPBComputeUInt32Size(GPBWireFormatMessageSetTypeId, fieldNumber) +
+ GPBComputeBytesSize(GPBWireFormatMessageSetMessage, value);
+}
+
+size_t GPBComputeTagSize(int32_t fieldNumber) {
+ return GPBComputeRawVarint32Size(
+ GPBWireFormatMakeTag(fieldNumber, GPBWireFormatVarint));
+}
+
+size_t GPBComputeWireFormatTagSize(int field_number, GPBDataType dataType) {
+ size_t result = GPBComputeTagSize(field_number);
+ if (dataType == GPBDataTypeGroup) {
+ // Groups have both a start and an end tag.
+ return result * 2;
+ } else {
+ return result;
+ }
+}
+
+size_t GPBComputeRawVarint32Size(int32_t value) {
+ // value is treated as unsigned, so it won't be sign-extended if negative.
+ if ((value & (0xffffffff << 7)) == 0) return 1;
+ if ((value & (0xffffffff << 14)) == 0) return 2;
+ if ((value & (0xffffffff << 21)) == 0) return 3;
+ if ((value & (0xffffffff << 28)) == 0) return 4;
+ return 5;
+}
+
+size_t GPBComputeRawVarint32SizeForInteger(NSInteger value) {
+ // Note the truncation.
+ return GPBComputeRawVarint32Size((int32_t)value);
+}
+
+size_t GPBComputeRawVarint64Size(int64_t value) {
+ if ((value & (0xffffffffffffffffL << 7)) == 0) return 1;
+ if ((value & (0xffffffffffffffffL << 14)) == 0) return 2;
+ if ((value & (0xffffffffffffffffL << 21)) == 0) return 3;
+ if ((value & (0xffffffffffffffffL << 28)) == 0) return 4;
+ if ((value & (0xffffffffffffffffL << 35)) == 0) return 5;
+ if ((value & (0xffffffffffffffffL << 42)) == 0) return 6;
+ if ((value & (0xffffffffffffffffL << 49)) == 0) return 7;
+ if ((value & (0xffffffffffffffffL << 56)) == 0) return 8;
+ if ((value & (0xffffffffffffffffL << 63)) == 0) return 9;
+ return 10;
+}
diff --git a/third_party/protobuf/objectivec/GPBCodedOutputStream_PackagePrivate.h b/third_party/protobuf/objectivec/GPBCodedOutputStream_PackagePrivate.h
new file mode 100644
index 0000000000..2e7bb4c4a2
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBCodedOutputStream_PackagePrivate.h
@@ -0,0 +1,126 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBCodedOutputStream.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+CF_EXTERN_C_BEGIN
+
+size_t GPBComputeDoubleSize(int32_t fieldNumber, double value)
+ __attribute__((const));
+size_t GPBComputeFloatSize(int32_t fieldNumber, float value)
+ __attribute__((const));
+size_t GPBComputeUInt64Size(int32_t fieldNumber, uint64_t value)
+ __attribute__((const));
+size_t GPBComputeInt64Size(int32_t fieldNumber, int64_t value)
+ __attribute__((const));
+size_t GPBComputeInt32Size(int32_t fieldNumber, int32_t value)
+ __attribute__((const));
+size_t GPBComputeFixed64Size(int32_t fieldNumber, uint64_t value)
+ __attribute__((const));
+size_t GPBComputeFixed32Size(int32_t fieldNumber, uint32_t value)
+ __attribute__((const));
+size_t GPBComputeBoolSize(int32_t fieldNumber, BOOL value)
+ __attribute__((const));
+size_t GPBComputeStringSize(int32_t fieldNumber, NSString *value)
+ __attribute__((const));
+size_t GPBComputeGroupSize(int32_t fieldNumber, GPBMessage *value)
+ __attribute__((const));
+size_t GPBComputeUnknownGroupSize(int32_t fieldNumber,
+ GPBUnknownFieldSet *value)
+ __attribute__((const));
+size_t GPBComputeMessageSize(int32_t fieldNumber, GPBMessage *value)
+ __attribute__((const));
+size_t GPBComputeBytesSize(int32_t fieldNumber, NSData *value)
+ __attribute__((const));
+size_t GPBComputeUInt32Size(int32_t fieldNumber, uint32_t value)
+ __attribute__((const));
+size_t GPBComputeSFixed32Size(int32_t fieldNumber, int32_t value)
+ __attribute__((const));
+size_t GPBComputeSFixed64Size(int32_t fieldNumber, int64_t value)
+ __attribute__((const));
+size_t GPBComputeSInt32Size(int32_t fieldNumber, int32_t value)
+ __attribute__((const));
+size_t GPBComputeSInt64Size(int32_t fieldNumber, int64_t value)
+ __attribute__((const));
+size_t GPBComputeTagSize(int32_t fieldNumber) __attribute__((const));
+size_t GPBComputeWireFormatTagSize(int field_number, GPBDataType dataType)
+ __attribute__((const));
+
+size_t GPBComputeDoubleSizeNoTag(double value) __attribute__((const));
+size_t GPBComputeFloatSizeNoTag(float value) __attribute__((const));
+size_t GPBComputeUInt64SizeNoTag(uint64_t value) __attribute__((const));
+size_t GPBComputeInt64SizeNoTag(int64_t value) __attribute__((const));
+size_t GPBComputeInt32SizeNoTag(int32_t value) __attribute__((const));
+size_t GPBComputeFixed64SizeNoTag(uint64_t value) __attribute__((const));
+size_t GPBComputeFixed32SizeNoTag(uint32_t value) __attribute__((const));
+size_t GPBComputeBoolSizeNoTag(BOOL value) __attribute__((const));
+size_t GPBComputeStringSizeNoTag(NSString *value) __attribute__((const));
+size_t GPBComputeGroupSizeNoTag(GPBMessage *value) __attribute__((const));
+size_t GPBComputeUnknownGroupSizeNoTag(GPBUnknownFieldSet *value)
+ __attribute__((const));
+size_t GPBComputeMessageSizeNoTag(GPBMessage *value) __attribute__((const));
+size_t GPBComputeBytesSizeNoTag(NSData *value) __attribute__((const));
+size_t GPBComputeUInt32SizeNoTag(int32_t value) __attribute__((const));
+size_t GPBComputeEnumSizeNoTag(int32_t value) __attribute__((const));
+size_t GPBComputeSFixed32SizeNoTag(int32_t value) __attribute__((const));
+size_t GPBComputeSFixed64SizeNoTag(int64_t value) __attribute__((const));
+size_t GPBComputeSInt32SizeNoTag(int32_t value) __attribute__((const));
+size_t GPBComputeSInt64SizeNoTag(int64_t value) __attribute__((const));
+
+// Note that this will calculate the size of 64 bit values truncated to 32.
+size_t GPBComputeSizeTSizeAsInt32NoTag(size_t value) __attribute__((const));
+
+size_t GPBComputeRawVarint32Size(int32_t value) __attribute__((const));
+size_t GPBComputeRawVarint64Size(int64_t value) __attribute__((const));
+
+// Note that this will calculate the size of 64 bit values truncated to 32.
+size_t GPBComputeRawVarint32SizeForInteger(NSInteger value)
+ __attribute__((const));
+
+// Compute the number of bytes that would be needed to encode a
+// MessageSet extension to the stream. For historical reasons,
+// the wire format differs from normal fields.
+size_t GPBComputeMessageSetExtensionSize(int32_t fieldNumber, GPBMessage *value)
+ __attribute__((const));
+
+// Compute the number of bytes that would be needed to encode an
+// unparsed MessageSet extension field to the stream. For
+// historical reasons, the wire format differs from normal fields.
+size_t GPBComputeRawMessageSetExtensionSize(int32_t fieldNumber, NSData *value)
+ __attribute__((const));
+
+size_t GPBComputeEnumSize(int32_t fieldNumber, int32_t value)
+ __attribute__((const));
+
+CF_EXTERN_C_END
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBDescriptor.h b/third_party/protobuf/objectivec/GPBDescriptor.h
new file mode 100644
index 0000000000..651f4de08f
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBDescriptor.h
@@ -0,0 +1,288 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBRuntimeTypes.h"
+
+@class GPBEnumDescriptor;
+@class GPBFieldDescriptor;
+@class GPBFileDescriptor;
+@class GPBOneofDescriptor;
+
+NS_ASSUME_NONNULL_BEGIN
+
+/** Syntax used in the proto file. */
+typedef NS_ENUM(uint8_t, GPBFileSyntax) {
+ /** Unknown syntax. */
+ GPBFileSyntaxUnknown = 0,
+ /** Proto2 syntax. */
+ GPBFileSyntaxProto2 = 2,
+ /** Proto3 syntax. */
+ GPBFileSyntaxProto3 = 3,
+};
+
+/** Type of proto field. */
+typedef NS_ENUM(uint8_t, GPBFieldType) {
+ /** Optional/required field. Only valid for proto2 fields. */
+ GPBFieldTypeSingle,
+ /** Repeated field. */
+ GPBFieldTypeRepeated,
+ /** Map field. */
+ GPBFieldTypeMap,
+};
+
+/**
+ * Describes a proto message.
+ **/
+@interface GPBDescriptor : NSObject<NSCopying>
+
+/** Name of the message. */
+@property(nonatomic, readonly, copy) NSString *name;
+/** Fields declared in the message. */
+@property(nonatomic, readonly, strong, nullable) NSArray<GPBFieldDescriptor*> *fields;
+/** Oneofs declared in the message. */
+@property(nonatomic, readonly, strong, nullable) NSArray<GPBOneofDescriptor*> *oneofs;
+/** Extension range declared for the message. */
+@property(nonatomic, readonly, nullable) const GPBExtensionRange *extensionRanges;
+/** Number of extension ranges declared for the message. */
+@property(nonatomic, readonly) uint32_t extensionRangesCount;
+/** Descriptor for the file where the message was defined. */
+@property(nonatomic, readonly, assign) GPBFileDescriptor *file;
+
+/** Whether the message is in wire format or not. */
+@property(nonatomic, readonly, getter=isWireFormat) BOOL wireFormat;
+/** The class of this message. */
+@property(nonatomic, readonly) Class messageClass;
+/** Containing message descriptor if this message is nested, or nil otherwise. */
+@property(readonly, nullable) GPBDescriptor *containingType;
+/**
+ * Fully qualified name for this message (package.message). Can be nil if the
+ * value is unable to be computed.
+ */
+@property(readonly, nullable) NSString *fullName;
+
+/**
+ * Gets the field for the given number.
+ *
+ * @param fieldNumber The number for the field to get.
+ *
+ * @return The field descriptor for the given number, or nil if not found.
+ **/
+- (nullable GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
+
+/**
+ * Gets the field for the given name.
+ *
+ * @param name The name for the field to get.
+ *
+ * @return The field descriptor for the given name, or nil if not found.
+ **/
+- (nullable GPBFieldDescriptor *)fieldWithName:(NSString *)name;
+
+/**
+ * Gets the oneof for the given name.
+ *
+ * @param name The name for the oneof to get.
+ *
+ * @return The oneof descriptor for the given name, or nil if not found.
+ **/
+- (nullable GPBOneofDescriptor *)oneofWithName:(NSString *)name;
+
+@end
+
+/**
+ * Describes a proto file.
+ **/
+@interface GPBFileDescriptor : NSObject
+
+/** The package declared in the proto file. */
+@property(nonatomic, readonly, copy) NSString *package;
+/** The objc prefix declared in the proto file. */
+@property(nonatomic, readonly, copy, nullable) NSString *objcPrefix;
+/** The syntax of the proto file. */
+@property(nonatomic, readonly) GPBFileSyntax syntax;
+
+@end
+
+/**
+ * Describes a oneof field.
+ **/
+@interface GPBOneofDescriptor : NSObject
+/** Name of the oneof field. */
+@property(nonatomic, readonly) NSString *name;
+/** Fields declared in the oneof. */
+@property(nonatomic, readonly) NSArray<GPBFieldDescriptor*> *fields;
+
+/**
+ * Gets the field for the given number.
+ *
+ * @param fieldNumber The number for the field to get.
+ *
+ * @return The field descriptor for the given number, or nil if not found.
+ **/
+- (nullable GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
+
+/**
+ * Gets the field for the given name.
+ *
+ * @param name The name for the field to get.
+ *
+ * @return The field descriptor for the given name, or nil if not found.
+ **/
+- (nullable GPBFieldDescriptor *)fieldWithName:(NSString *)name;
+
+@end
+
+/**
+ * Describes a proto field.
+ **/
+@interface GPBFieldDescriptor : NSObject
+
+/** Name of the field. */
+@property(nonatomic, readonly, copy) NSString *name;
+/** Number associated with the field. */
+@property(nonatomic, readonly) uint32_t number;
+/** Data type contained in the field. */
+@property(nonatomic, readonly) GPBDataType dataType;
+/** Whether it has a default value or not. */
+@property(nonatomic, readonly) BOOL hasDefaultValue;
+/** Default value for the field. */
+@property(nonatomic, readonly) GPBGenericValue defaultValue;
+/** Whether this field is required. Only valid for proto2 fields. */
+@property(nonatomic, readonly, getter=isRequired) BOOL required;
+/** Whether this field is optional. */
+@property(nonatomic, readonly, getter=isOptional) BOOL optional;
+/** Type of field (single, repeated, map). */
+@property(nonatomic, readonly) GPBFieldType fieldType;
+/** Type of the key if the field is a map. The value's type is -fieldType. */
+@property(nonatomic, readonly) GPBDataType mapKeyDataType;
+/** Whether the field is packable. */
+@property(nonatomic, readonly, getter=isPackable) BOOL packable;
+
+/** The containing oneof if this field is part of one, nil otherwise. */
+@property(nonatomic, readonly, assign, nullable) GPBOneofDescriptor *containingOneof;
+
+/** Class of the message if the field is of message type. */
+@property(nonatomic, readonly, assign, nullable) Class msgClass;
+
+/** Descriptor for the enum if this field is an enum. */
+@property(nonatomic, readonly, strong, nullable) GPBEnumDescriptor *enumDescriptor;
+
+/**
+ * Checks whether the given enum raw value is a valid enum value.
+ *
+ * @param value The raw enum value to check.
+ *
+ * @return YES if value is a valid enum raw value.
+ **/
+- (BOOL)isValidEnumValue:(int32_t)value;
+
+/** @return Name for the text format, or nil if not known. */
+- (nullable NSString *)textFormatName;
+
+@end
+
+/**
+ * Describes a proto enum.
+ **/
+@interface GPBEnumDescriptor : NSObject
+
+/** Name of the enum. */
+@property(nonatomic, readonly, copy) NSString *name;
+/** Function that validates that raw values are valid enum values. */
+@property(nonatomic, readonly) GPBEnumValidationFunc enumVerifier;
+
+/**
+ * Returns the enum value name for the given raw enum.
+ *
+ * @param number The raw enum value.
+ *
+ * @return The name of the enum value passed, or nil if not valid.
+ **/
+- (nullable NSString *)enumNameForValue:(int32_t)number;
+
+/**
+ * Gets the enum raw value for the given enum name.
+ *
+ * @param outValue A pointer where the value will be set.
+ * @param name The enum name for which to get the raw value.
+ *
+ * @return YES if a value was copied into the pointer, NO otherwise.
+ **/
+- (BOOL)getValue:(nullable int32_t *)outValue forEnumName:(NSString *)name;
+
+/**
+ * Returns the text format for the given raw enum value.
+ *
+ * @param number The raw enum value.
+ *
+ * @return The text format name for the raw enum value, or nil if not valid.
+ **/
+- (nullable NSString *)textFormatNameForValue:(int32_t)number;
+
+/**
+ * Gets the enum raw value for the given text format name.
+ *
+ * @param outValue A pointer where the value will be set.
+ * @param textFormatName The text format name for which to get the raw value.
+ *
+ * @return YES if a value was copied into the pointer, NO otherwise.
+ **/
+- (BOOL)getValue:(nullable int32_t *)outValue forEnumTextFormatName:(NSString *)textFormatName;
+
+@end
+
+/**
+ * Describes a proto extension.
+ **/
+@interface GPBExtensionDescriptor : NSObject<NSCopying>
+/** Field number under which the extension is stored. */
+@property(nonatomic, readonly) uint32_t fieldNumber;
+/** The containing message class, i.e. the class extended by this extension. */
+@property(nonatomic, readonly) Class containingMessageClass;
+/** Data type contained in the extension. */
+@property(nonatomic, readonly) GPBDataType dataType;
+/** Whether the extension is repeated. */
+@property(nonatomic, readonly, getter=isRepeated) BOOL repeated;
+/** Whether the extension is packable. */
+@property(nonatomic, readonly, getter=isPackable) BOOL packable;
+/** The class of the message if the extension is of message type. */
+@property(nonatomic, readonly, assign) Class msgClass;
+/** The singleton name for the extension. */
+@property(nonatomic, readonly) NSString *singletonName;
+/** The enum descriptor if the extension is of enum type. */
+@property(nonatomic, readonly, strong, nullable) GPBEnumDescriptor *enumDescriptor;
+/** The default value for the extension. */
+@property(nonatomic, readonly, nullable) id defaultValue;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBDescriptor.m b/third_party/protobuf/objectivec/GPBDescriptor.m
new file mode 100644
index 0000000000..0753a9485b
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBDescriptor.m
@@ -0,0 +1,1104 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBDescriptor_PackagePrivate.h"
+
+#import <objc/runtime.h>
+
+#import "GPBUtilities_PackagePrivate.h"
+#import "GPBWireFormat.h"
+#import "GPBMessage_PackagePrivate.h"
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+// The addresses of these variables are used as keys for objc_getAssociatedObject.
+static const char kTextFormatExtraValueKey = 0;
+static const char kParentClassNameValueKey = 0;
+static const char kClassNameSuffixKey = 0;
+
+// Utility function to generate selectors on the fly.
+static SEL SelFromStrings(const char *prefix, const char *middle,
+ const char *suffix, BOOL takesArg) {
+ if (prefix == NULL && suffix == NULL && !takesArg) {
+ return sel_getUid(middle);
+ }
+ const size_t prefixLen = prefix != NULL ? strlen(prefix) : 0;
+ const size_t middleLen = strlen(middle);
+ const size_t suffixLen = suffix != NULL ? strlen(suffix) : 0;
+ size_t totalLen =
+ prefixLen + middleLen + suffixLen + 1; // include space for null on end.
+ if (takesArg) {
+ totalLen += 1;
+ }
+ char buffer[totalLen];
+ if (prefix != NULL) {
+ memcpy(buffer, prefix, prefixLen);
+ memcpy(buffer + prefixLen, middle, middleLen);
+ buffer[prefixLen] = (char)toupper(buffer[prefixLen]);
+ } else {
+ memcpy(buffer, middle, middleLen);
+ }
+ if (suffix != NULL) {
+ memcpy(buffer + prefixLen + middleLen, suffix, suffixLen);
+ }
+ if (takesArg) {
+ buffer[totalLen - 2] = ':';
+ }
+ // Always null terminate it.
+ buffer[totalLen - 1] = 0;
+
+ SEL result = sel_getUid(buffer);
+ return result;
+}
+
+static NSArray *NewFieldsArrayForHasIndex(int hasIndex,
+ NSArray *allMessageFields)
+ __attribute__((ns_returns_retained));
+
+static NSArray *NewFieldsArrayForHasIndex(int hasIndex,
+ NSArray *allMessageFields) {
+ NSMutableArray *result = [[NSMutableArray alloc] init];
+ for (GPBFieldDescriptor *fieldDesc in allMessageFields) {
+ if (fieldDesc->description_->hasIndex == hasIndex) {
+ [result addObject:fieldDesc];
+ }
+ }
+ return result;
+}
+
+@implementation GPBDescriptor {
+ Class messageClass_;
+ GPBFileDescriptor *file_;
+ BOOL wireFormat_;
+}
+
+@synthesize messageClass = messageClass_;
+@synthesize fields = fields_;
+@synthesize oneofs = oneofs_;
+@synthesize extensionRanges = extensionRanges_;
+@synthesize extensionRangesCount = extensionRangesCount_;
+@synthesize file = file_;
+@synthesize wireFormat = wireFormat_;
+
++ (instancetype)
+ allocDescriptorForClass:(Class)messageClass
+ rootClass:(Class)rootClass
+ file:(GPBFileDescriptor *)file
+ fields:(void *)fieldDescriptions
+ fieldCount:(uint32_t)fieldCount
+ storageSize:(uint32_t)storageSize
+ flags:(GPBDescriptorInitializationFlags)flags {
+ // The rootClass is no longer used, but it is passed in to ensure it
+ // was started up during initialization also.
+ (void)rootClass;
+ NSMutableArray *fields = nil;
+ GPBFileSyntax syntax = file.syntax;
+ BOOL fieldsIncludeDefault =
+ (flags & GPBDescriptorInitializationFlag_FieldsWithDefault) != 0;
+
+ void *desc;
+ for (uint32_t i = 0; i < fieldCount; ++i) {
+ if (fields == nil) {
+ fields = [[NSMutableArray alloc] initWithCapacity:fieldCount];
+ }
+ // Need correctly typed pointer for array indexing below to work.
+ if (fieldsIncludeDefault) {
+ GPBMessageFieldDescriptionWithDefault *fieldDescWithDefault = fieldDescriptions;
+ desc = &(fieldDescWithDefault[i]);
+ } else {
+ GPBMessageFieldDescription *fieldDesc = fieldDescriptions;
+ desc = &(fieldDesc[i]);
+ }
+ GPBFieldDescriptor *fieldDescriptor =
+ [[GPBFieldDescriptor alloc] initWithFieldDescription:desc
+ includesDefault:fieldsIncludeDefault
+ syntax:syntax];
+ [fields addObject:fieldDescriptor];
+ [fieldDescriptor release];
+ }
+
+ BOOL wireFormat = (flags & GPBDescriptorInitializationFlag_WireFormat) != 0;
+ GPBDescriptor *descriptor = [[self alloc] initWithClass:messageClass
+ file:file
+ fields:fields
+ storageSize:storageSize
+ wireFormat:wireFormat];
+ [fields release];
+ return descriptor;
+}
+
+- (instancetype)initWithClass:(Class)messageClass
+ file:(GPBFileDescriptor *)file
+ fields:(NSArray *)fields
+ storageSize:(uint32_t)storageSize
+ wireFormat:(BOOL)wireFormat {
+ if ((self = [super init])) {
+ messageClass_ = messageClass;
+ file_ = file;
+ fields_ = [fields retain];
+ storageSize_ = storageSize;
+ wireFormat_ = wireFormat;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [fields_ release];
+ [oneofs_ release];
+ [super dealloc];
+}
+
+- (void)setupOneofs:(const char **)oneofNames
+ count:(uint32_t)count
+ firstHasIndex:(int32_t)firstHasIndex {
+ NSCAssert(firstHasIndex < 0, @"Should always be <0");
+ NSMutableArray *oneofs = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0, hasIndex = firstHasIndex; i < count; ++i, --hasIndex) {
+ const char *name = oneofNames[i];
+ NSArray *fieldsForOneof = NewFieldsArrayForHasIndex(hasIndex, fields_);
+ NSCAssert(fieldsForOneof.count > 0,
+ @"No fields for this oneof? (%s:%d)", name, hasIndex);
+ GPBOneofDescriptor *oneofDescriptor =
+ [[GPBOneofDescriptor alloc] initWithName:name fields:fieldsForOneof];
+ [oneofs addObject:oneofDescriptor];
+ [oneofDescriptor release];
+ [fieldsForOneof release];
+ }
+ oneofs_ = oneofs;
+}
+
+- (void)setupExtraTextInfo:(const char *)extraTextFormatInfo {
+ // Extra info is a compile time option, so skip the work if not needed.
+ if (extraTextFormatInfo) {
+ NSValue *extraInfoValue = [NSValue valueWithPointer:extraTextFormatInfo];
+ for (GPBFieldDescriptor *fieldDescriptor in fields_) {
+ if (fieldDescriptor->description_->flags & GPBFieldTextFormatNameCustom) {
+ objc_setAssociatedObject(fieldDescriptor, &kTextFormatExtraValueKey,
+ extraInfoValue,
+ OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+ }
+ }
+}
+
+- (void)setupExtensionRanges:(const GPBExtensionRange *)ranges count:(int32_t)count {
+ extensionRanges_ = ranges;
+ extensionRangesCount_ = count;
+}
+
+- (void)setupContainingMessageClassName:(const char *)msgClassName {
+ // Note: Only fetch the class here, can't send messages to it because
+ // that could cause cycles back to this class within +initialize if
+ // two messages have each other in fields (i.e. - they build a graph).
+ NSAssert(objc_getClass(msgClassName), @"Class %s not defined", msgClassName);
+ NSValue *parentNameValue = [NSValue valueWithPointer:msgClassName];
+ objc_setAssociatedObject(self, &kParentClassNameValueKey,
+ parentNameValue,
+ OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+}
+
+- (void)setupMessageClassNameSuffix:(NSString *)suffix {
+ if (suffix.length) {
+ objc_setAssociatedObject(self, &kClassNameSuffixKey,
+ suffix,
+ OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ }
+}
+
+- (NSString *)name {
+ return NSStringFromClass(messageClass_);
+}
+
+- (GPBDescriptor *)containingType {
+ NSValue *parentNameValue =
+ objc_getAssociatedObject(self, &kParentClassNameValueKey);
+ if (!parentNameValue) {
+ return nil;
+ }
+ const char *parentName = [parentNameValue pointerValue];
+ Class parentClass = objc_getClass(parentName);
+ NSAssert(parentClass, @"Class %s not defined", parentName);
+ return [parentClass descriptor];
+}
+
+- (NSString *)fullName {
+ NSString *className = NSStringFromClass(self.messageClass);
+ GPBFileDescriptor *file = self.file;
+ NSString *objcPrefix = file.objcPrefix;
+ if (objcPrefix && ![className hasPrefix:objcPrefix]) {
+ NSAssert(0,
+ @"Class didn't have correct prefix? (%@ - %@)",
+ className, objcPrefix);
+ return nil;
+ }
+ GPBDescriptor *parent = self.containingType;
+
+ NSString *name = nil;
+ if (parent) {
+ NSString *parentClassName = NSStringFromClass(parent.messageClass);
+ // The generator will add _Class to avoid reserved words, drop it.
+ NSString *suffix = objc_getAssociatedObject(parent, &kClassNameSuffixKey);
+ if (suffix) {
+ if (![parentClassName hasSuffix:suffix]) {
+ NSAssert(0,
+ @"ParentMessage class didn't have correct suffix? (%@ - %@)",
+ className, suffix);
+ return nil;
+ }
+ parentClassName =
+ [parentClassName substringToIndex:(parentClassName.length - suffix.length)];
+ }
+ NSString *parentPrefix = [parentClassName stringByAppendingString:@"_"];
+ if (![className hasPrefix:parentPrefix]) {
+ NSAssert(0,
+ @"Class didn't have the correct parent name prefix? (%@ - %@)",
+ parentPrefix, className);
+ return nil;
+ }
+ name = [className substringFromIndex:parentPrefix.length];
+ } else {
+ name = [className substringFromIndex:objcPrefix.length];
+ }
+
+ // The generator will add _Class to avoid reserved words, drop it.
+ NSString *suffix = objc_getAssociatedObject(self, &kClassNameSuffixKey);
+ if (suffix) {
+ if (![name hasSuffix:suffix]) {
+ NSAssert(0,
+ @"Message class didn't have correct suffix? (%@ - %@)",
+ name, suffix);
+ return nil;
+ }
+ name = [name substringToIndex:(name.length - suffix.length)];
+ }
+
+ NSString *prefix = (parent != nil ? parent.fullName : file.package);
+ NSString *result;
+ if (prefix.length > 0) {
+ result = [NSString stringWithFormat:@"%@.%@", prefix, name];
+ } else {
+ result = name;
+ }
+ return result;
+}
+
+- (id)copyWithZone:(NSZone *)zone {
+#pragma unused(zone)
+ return [self retain];
+}
+
+- (GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber {
+ for (GPBFieldDescriptor *descriptor in fields_) {
+ if (GPBFieldNumber(descriptor) == fieldNumber) {
+ return descriptor;
+ }
+ }
+ return nil;
+}
+
+- (GPBFieldDescriptor *)fieldWithName:(NSString *)name {
+ for (GPBFieldDescriptor *descriptor in fields_) {
+ if ([descriptor.name isEqual:name]) {
+ return descriptor;
+ }
+ }
+ return nil;
+}
+
+- (GPBOneofDescriptor *)oneofWithName:(NSString *)name {
+ for (GPBOneofDescriptor *descriptor in oneofs_) {
+ if ([descriptor.name isEqual:name]) {
+ return descriptor;
+ }
+ }
+ return nil;
+}
+
+@end
+
+@implementation GPBFileDescriptor {
+ NSString *package_;
+ NSString *objcPrefix_;
+ GPBFileSyntax syntax_;
+}
+
+@synthesize package = package_;
+@synthesize objcPrefix = objcPrefix_;
+@synthesize syntax = syntax_;
+
+- (instancetype)initWithPackage:(NSString *)package
+ objcPrefix:(NSString *)objcPrefix
+ syntax:(GPBFileSyntax)syntax {
+ self = [super init];
+ if (self) {
+ package_ = [package copy];
+ objcPrefix_ = [objcPrefix copy];
+ syntax_ = syntax;
+ }
+ return self;
+}
+
+- (instancetype)initWithPackage:(NSString *)package
+ syntax:(GPBFileSyntax)syntax {
+ self = [super init];
+ if (self) {
+ package_ = [package copy];
+ syntax_ = syntax;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [package_ release];
+ [objcPrefix_ release];
+ [super dealloc];
+}
+
+@end
+
+@implementation GPBOneofDescriptor
+
+@synthesize fields = fields_;
+
+- (instancetype)initWithName:(const char *)name fields:(NSArray *)fields {
+ self = [super init];
+ if (self) {
+ name_ = name;
+ fields_ = [fields retain];
+ for (GPBFieldDescriptor *fieldDesc in fields) {
+ fieldDesc->containingOneof_ = self;
+ }
+
+ caseSel_ = SelFromStrings(NULL, name, "OneOfCase", NO);
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [fields_ release];
+ [super dealloc];
+}
+
+- (NSString *)name {
+ return @(name_);
+}
+
+- (GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber {
+ for (GPBFieldDescriptor *descriptor in fields_) {
+ if (GPBFieldNumber(descriptor) == fieldNumber) {
+ return descriptor;
+ }
+ }
+ return nil;
+}
+
+- (GPBFieldDescriptor *)fieldWithName:(NSString *)name {
+ for (GPBFieldDescriptor *descriptor in fields_) {
+ if ([descriptor.name isEqual:name]) {
+ return descriptor;
+ }
+ }
+ return nil;
+}
+
+@end
+
+uint32_t GPBFieldTag(GPBFieldDescriptor *self) {
+ GPBMessageFieldDescription *description = self->description_;
+ GPBWireFormat format;
+ if ((description->flags & GPBFieldMapKeyMask) != 0) {
+ // Maps are repeated messages on the wire.
+ format = GPBWireFormatForType(GPBDataTypeMessage, NO);
+ } else {
+ format = GPBWireFormatForType(description->dataType,
+ ((description->flags & GPBFieldPacked) != 0));
+ }
+ return GPBWireFormatMakeTag(description->number, format);
+}
+
+uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
+ GPBMessageFieldDescription *description = self->description_;
+ NSCAssert((description->flags & GPBFieldRepeated) != 0,
+ @"Only valid on repeated fields");
+ GPBWireFormat format =
+ GPBWireFormatForType(description->dataType,
+ ((description->flags & GPBFieldPacked) == 0));
+ return GPBWireFormatMakeTag(description->number, format);
+}
+
+@implementation GPBFieldDescriptor {
+ GPBGenericValue defaultValue_;
+
+ // Message ivars
+ Class msgClass_;
+
+ // Enum ivars.
+ // If protos are generated with GenerateEnumDescriptors on then it will
+ // be a enumDescriptor, otherwise it will be a enumVerifier.
+ union {
+ GPBEnumDescriptor *enumDescriptor_;
+ GPBEnumValidationFunc enumVerifier_;
+ } enumHandling_;
+}
+
+@synthesize msgClass = msgClass_;
+@synthesize containingOneof = containingOneof_;
+
+- (instancetype)init {
+ // Throw an exception if people attempt to not use the designated initializer.
+ self = [super init];
+ if (self != nil) {
+ [self doesNotRecognizeSelector:_cmd];
+ self = nil;
+ }
+ return self;
+}
+
+- (instancetype)initWithFieldDescription:(void *)description
+ includesDefault:(BOOL)includesDefault
+ syntax:(GPBFileSyntax)syntax {
+ if ((self = [super init])) {
+ GPBMessageFieldDescription *coreDesc;
+ if (includesDefault) {
+ coreDesc = &(((GPBMessageFieldDescriptionWithDefault *)description)->core);
+ } else {
+ coreDesc = description;
+ }
+ description_ = coreDesc;
+ getSel_ = sel_getUid(coreDesc->name);
+ setSel_ = SelFromStrings("set", coreDesc->name, NULL, YES);
+
+ GPBDataType dataType = coreDesc->dataType;
+ BOOL isMessage = GPBDataTypeIsMessage(dataType);
+ BOOL isMapOrArray = GPBFieldIsMapOrArray(self);
+
+ if (isMapOrArray) {
+ // map<>/repeated fields get a *Count property (inplace of a has*) to
+ // support checking if there are any entries without triggering
+ // autocreation.
+ hasOrCountSel_ = SelFromStrings(NULL, coreDesc->name, "_Count", NO);
+ } else {
+ // If there is a positive hasIndex, then:
+ // - All fields types for proto2 messages get has* selectors.
+ // - Only message fields for proto3 messages get has* selectors.
+ // Note: the positive check is to handle oneOfs, we can't check
+ // containingOneof_ because it isn't set until after initialization.
+ if ((coreDesc->hasIndex >= 0) &&
+ (coreDesc->hasIndex != GPBNoHasBit) &&
+ ((syntax != GPBFileSyntaxProto3) || isMessage)) {
+ hasOrCountSel_ = SelFromStrings("has", coreDesc->name, NULL, NO);
+ setHasSel_ = SelFromStrings("setHas", coreDesc->name, NULL, YES);
+ }
+ }
+
+ // Extra type specific data.
+ if (isMessage) {
+ const char *className = coreDesc->dataTypeSpecific.className;
+ // Note: Only fetch the class here, can't send messages to it because
+ // that could cause cycles back to this class within +initialize if
+ // two messages have each other in fields (i.e. - they build a graph).
+ msgClass_ = objc_getClass(className);
+ NSAssert(msgClass_, @"Class %s not defined", className);
+ } else if (dataType == GPBDataTypeEnum) {
+ if ((coreDesc->flags & GPBFieldHasEnumDescriptor) != 0) {
+ enumHandling_.enumDescriptor_ =
+ coreDesc->dataTypeSpecific.enumDescFunc();
+ } else {
+ enumHandling_.enumVerifier_ =
+ coreDesc->dataTypeSpecific.enumVerifier;
+ }
+ }
+
+ // Non map<>/repeated fields can have defaults in proto2 syntax.
+ if (!isMapOrArray && includesDefault) {
+ defaultValue_ = ((GPBMessageFieldDescriptionWithDefault *)description)->defaultValue;
+ if (dataType == GPBDataTypeBytes) {
+ // Data stored as a length prefixed (network byte order) c-string in
+ // descriptor structure.
+ const uint8_t *bytes = (const uint8_t *)defaultValue_.valueData;
+ if (bytes) {
+ uint32_t length = *((uint32_t *)bytes);
+ length = ntohl(length);
+ bytes += sizeof(length);
+ defaultValue_.valueData =
+ [[NSData alloc] initWithBytes:bytes length:length];
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (void)dealloc {
+ if (description_->dataType == GPBDataTypeBytes &&
+ !(description_->flags & GPBFieldRepeated)) {
+ [defaultValue_.valueData release];
+ }
+ [super dealloc];
+}
+
+- (GPBDataType)dataType {
+ return description_->dataType;
+}
+
+- (BOOL)hasDefaultValue {
+ return (description_->flags & GPBFieldHasDefaultValue) != 0;
+}
+
+- (uint32_t)number {
+ return description_->number;
+}
+
+- (NSString *)name {
+ return @(description_->name);
+}
+
+- (BOOL)isRequired {
+ return (description_->flags & GPBFieldRequired) != 0;
+}
+
+- (BOOL)isOptional {
+ return (description_->flags & GPBFieldOptional) != 0;
+}
+
+- (GPBFieldType)fieldType {
+ GPBFieldFlags flags = description_->flags;
+ if ((flags & GPBFieldRepeated) != 0) {
+ return GPBFieldTypeRepeated;
+ } else if ((flags & GPBFieldMapKeyMask) != 0) {
+ return GPBFieldTypeMap;
+ } else {
+ return GPBFieldTypeSingle;
+ }
+}
+
+- (GPBDataType)mapKeyDataType {
+ switch (description_->flags & GPBFieldMapKeyMask) {
+ case GPBFieldMapKeyInt32:
+ return GPBDataTypeInt32;
+ case GPBFieldMapKeyInt64:
+ return GPBDataTypeInt64;
+ case GPBFieldMapKeyUInt32:
+ return GPBDataTypeUInt32;
+ case GPBFieldMapKeyUInt64:
+ return GPBDataTypeUInt64;
+ case GPBFieldMapKeySInt32:
+ return GPBDataTypeSInt32;
+ case GPBFieldMapKeySInt64:
+ return GPBDataTypeSInt64;
+ case GPBFieldMapKeyFixed32:
+ return GPBDataTypeFixed32;
+ case GPBFieldMapKeyFixed64:
+ return GPBDataTypeFixed64;
+ case GPBFieldMapKeySFixed32:
+ return GPBDataTypeSFixed32;
+ case GPBFieldMapKeySFixed64:
+ return GPBDataTypeSFixed64;
+ case GPBFieldMapKeyBool:
+ return GPBDataTypeBool;
+ case GPBFieldMapKeyString:
+ return GPBDataTypeString;
+
+ default:
+ NSAssert(0, @"Not a map type");
+ return GPBDataTypeInt32; // For lack of anything better.
+ }
+}
+
+- (BOOL)isPackable {
+ return (description_->flags & GPBFieldPacked) != 0;
+}
+
+- (BOOL)isValidEnumValue:(int32_t)value {
+ NSAssert(description_->dataType == GPBDataTypeEnum,
+ @"Field Must be of type GPBDataTypeEnum");
+ if (description_->flags & GPBFieldHasEnumDescriptor) {
+ return enumHandling_.enumDescriptor_.enumVerifier(value);
+ } else {
+ return enumHandling_.enumVerifier_(value);
+ }
+}
+
+- (GPBEnumDescriptor *)enumDescriptor {
+ if (description_->flags & GPBFieldHasEnumDescriptor) {
+ return enumHandling_.enumDescriptor_;
+ } else {
+ return nil;
+ }
+}
+
+- (GPBGenericValue)defaultValue {
+ // Depends on the fact that defaultValue_ is initialized either to "0/nil" or
+ // to an actual defaultValue in our initializer.
+ GPBGenericValue value = defaultValue_;
+
+ if (!(description_->flags & GPBFieldRepeated)) {
+ // We special handle data and strings. If they are nil, we replace them
+ // with empty string/empty data.
+ GPBDataType type = description_->dataType;
+ if (type == GPBDataTypeBytes && value.valueData == nil) {
+ value.valueData = GPBEmptyNSData();
+ } else if (type == GPBDataTypeString && value.valueString == nil) {
+ value.valueString = @"";
+ }
+ }
+ return value;
+}
+
+- (NSString *)textFormatName {
+ if ((description_->flags & GPBFieldTextFormatNameCustom) != 0) {
+ NSValue *extraInfoValue =
+ objc_getAssociatedObject(self, &kTextFormatExtraValueKey);
+ // Support can be left out at generation time.
+ if (!extraInfoValue) {
+ return nil;
+ }
+ const uint8_t *extraTextFormatInfo = [extraInfoValue pointerValue];
+ return GPBDecodeTextFormatName(extraTextFormatInfo, GPBFieldNumber(self),
+ self.name);
+ }
+
+ // The logic here has to match SetCommonFieldVariables() from
+ // objectivec_field.cc in the proto compiler.
+ NSString *name = self.name;
+ NSUInteger len = [name length];
+
+ // Remove the "_p" added to reserved names.
+ if ([name hasSuffix:@"_p"]) {
+ name = [name substringToIndex:(len - 2)];
+ len = [name length];
+ }
+
+ // Remove "Array" from the end for repeated fields.
+ if (((description_->flags & GPBFieldRepeated) != 0) &&
+ [name hasSuffix:@"Array"]) {
+ name = [name substringToIndex:(len - 5)];
+ len = [name length];
+ }
+
+ // Groups vs. other fields.
+ if (description_->dataType == GPBDataTypeGroup) {
+ // Just capitalize the first letter.
+ unichar firstChar = [name characterAtIndex:0];
+ if (firstChar >= 'a' && firstChar <= 'z') {
+ NSString *firstCharString =
+ [NSString stringWithFormat:@"%C", (unichar)(firstChar - 'a' + 'A')];
+ NSString *result =
+ [name stringByReplacingCharactersInRange:NSMakeRange(0, 1)
+ withString:firstCharString];
+ return result;
+ }
+ return name;
+
+ } else {
+ // Undo the CamelCase.
+ NSMutableString *result = [NSMutableString stringWithCapacity:len];
+ for (uint32_t i = 0; i < len; i++) {
+ unichar c = [name characterAtIndex:i];
+ if (c >= 'A' && c <= 'Z') {
+ if (i > 0) {
+ [result appendFormat:@"_%C", (unichar)(c - 'A' + 'a')];
+ } else {
+ [result appendFormat:@"%C", c];
+ }
+ } else {
+ [result appendFormat:@"%C", c];
+ }
+ }
+ return result;
+ }
+}
+
+@end
+
+@implementation GPBEnumDescriptor {
+ NSString *name_;
+ // valueNames_ is a single c string with all of the value names appended
+ // together, each null terminated. -calcValueNameOffsets fills in
+ // nameOffsets_ with the offsets to allow quicker access to the individual
+ // names.
+ const char *valueNames_;
+ const int32_t *values_;
+ GPBEnumValidationFunc enumVerifier_;
+ const uint8_t *extraTextFormatInfo_;
+ uint32_t *nameOffsets_;
+ uint32_t valueCount_;
+}
+
+@synthesize name = name_;
+@synthesize enumVerifier = enumVerifier_;
+
++ (instancetype)
+ allocDescriptorForName:(NSString *)name
+ valueNames:(const char *)valueNames
+ values:(const int32_t *)values
+ count:(uint32_t)valueCount
+ enumVerifier:(GPBEnumValidationFunc)enumVerifier {
+ GPBEnumDescriptor *descriptor = [[self alloc] initWithName:name
+ valueNames:valueNames
+ values:values
+ count:valueCount
+ enumVerifier:enumVerifier];
+ return descriptor;
+}
+
++ (instancetype)
+ allocDescriptorForName:(NSString *)name
+ valueNames:(const char *)valueNames
+ values:(const int32_t *)values
+ count:(uint32_t)valueCount
+ enumVerifier:(GPBEnumValidationFunc)enumVerifier
+ extraTextFormatInfo:(const char *)extraTextFormatInfo {
+ // Call the common case.
+ GPBEnumDescriptor *descriptor = [self allocDescriptorForName:name
+ valueNames:valueNames
+ values:values
+ count:valueCount
+ enumVerifier:enumVerifier];
+ // Set the extra info.
+ descriptor->extraTextFormatInfo_ = (const uint8_t *)extraTextFormatInfo;
+ return descriptor;
+}
+
+- (instancetype)initWithName:(NSString *)name
+ valueNames:(const char *)valueNames
+ values:(const int32_t *)values
+ count:(uint32_t)valueCount
+ enumVerifier:(GPBEnumValidationFunc)enumVerifier {
+ if ((self = [super init])) {
+ name_ = [name copy];
+ valueNames_ = valueNames;
+ values_ = values;
+ valueCount_ = valueCount;
+ enumVerifier_ = enumVerifier;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [name_ release];
+ if (nameOffsets_) free(nameOffsets_);
+ [super dealloc];
+}
+
+- (void)calcValueNameOffsets {
+ @synchronized(self) {
+ if (nameOffsets_ != NULL) {
+ return;
+ }
+ uint32_t *offsets = malloc(valueCount_ * sizeof(uint32_t));
+ const char *scan = valueNames_;
+ for (uint32_t i = 0; i < valueCount_; ++i) {
+ offsets[i] = (uint32_t)(scan - valueNames_);
+ while (*scan != '\0') ++scan;
+ ++scan; // Step over the null.
+ }
+ nameOffsets_ = offsets;
+ }
+}
+
+- (NSString *)enumNameForValue:(int32_t)number {
+ if (nameOffsets_ == NULL) [self calcValueNameOffsets];
+
+ for (uint32_t i = 0; i < valueCount_; ++i) {
+ if (values_[i] == number) {
+ const char *valueName = valueNames_ + nameOffsets_[i];
+ NSString *fullName = [NSString stringWithFormat:@"%@_%s", name_, valueName];
+ return fullName;
+ }
+ }
+ return nil;
+}
+
+- (BOOL)getValue:(int32_t *)outValue forEnumName:(NSString *)name {
+ // Must have the prefix.
+ NSUInteger prefixLen = name_.length + 1;
+ if ((name.length <= prefixLen) || ![name hasPrefix:name_] ||
+ ([name characterAtIndex:prefixLen - 1] != '_')) {
+ return NO;
+ }
+
+ // Skip over the prefix.
+ const char *nameAsCStr = [name UTF8String];
+ nameAsCStr += prefixLen;
+
+ if (nameOffsets_ == NULL) [self calcValueNameOffsets];
+
+ // Find it.
+ for (uint32_t i = 0; i < valueCount_; ++i) {
+ const char *valueName = valueNames_ + nameOffsets_[i];
+ if (strcmp(nameAsCStr, valueName) == 0) {
+ if (outValue) {
+ *outValue = values_[i];
+ }
+ return YES;
+ }
+ }
+ return NO;
+}
+
+- (BOOL)getValue:(int32_t *)outValue forEnumTextFormatName:(NSString *)textFormatName {
+ if (nameOffsets_ == NULL) [self calcValueNameOffsets];
+
+ for (uint32_t i = 0; i < valueCount_; ++i) {
+ int32_t value = values_[i];
+ NSString *valueTextFormatName = [self textFormatNameForValue:value];
+ if ([valueTextFormatName isEqual:textFormatName]) {
+ if (outValue) {
+ *outValue = value;
+ }
+ return YES;
+ }
+ }
+ return NO;
+}
+
+- (NSString *)textFormatNameForValue:(int32_t)number {
+ if (nameOffsets_ == NULL) [self calcValueNameOffsets];
+
+ // Find the EnumValue descriptor and its index.
+ BOOL foundIt = NO;
+ uint32_t valueDescriptorIndex;
+ for (valueDescriptorIndex = 0; valueDescriptorIndex < valueCount_;
+ ++valueDescriptorIndex) {
+ if (values_[valueDescriptorIndex] == number) {
+ foundIt = YES;
+ break;
+ }
+ }
+
+ if (!foundIt) {
+ return nil;
+ }
+
+ NSString *result = nil;
+ // Naming adds an underscore between enum name and value name, skip that also.
+ const char *valueName = valueNames_ + nameOffsets_[valueDescriptorIndex];
+ NSString *shortName = @(valueName);
+
+ // See if it is in the map of special format handling.
+ if (extraTextFormatInfo_) {
+ result = GPBDecodeTextFormatName(extraTextFormatInfo_,
+ (int32_t)valueDescriptorIndex, shortName);
+ }
+ // Logic here needs to match what objectivec_enum.cc does in the proto
+ // compiler.
+ if (result == nil) {
+ NSUInteger len = [shortName length];
+ NSMutableString *worker = [NSMutableString stringWithCapacity:len];
+ for (NSUInteger i = 0; i < len; i++) {
+ unichar c = [shortName characterAtIndex:i];
+ if (i > 0 && c >= 'A' && c <= 'Z') {
+ [worker appendString:@"_"];
+ }
+ [worker appendFormat:@"%c", toupper((char)c)];
+ }
+ result = worker;
+ }
+ return result;
+}
+
+@end
+
+@implementation GPBExtensionDescriptor {
+ GPBGenericValue defaultValue_;
+}
+
+@synthesize containingMessageClass = containingMessageClass_;
+
+- (instancetype)initWithExtensionDescription:
+ (GPBExtensionDescription *)description {
+ if ((self = [super init])) {
+ description_ = description;
+
+#if defined(DEBUG) && DEBUG
+ const char *className = description->messageOrGroupClassName;
+ if (className) {
+ NSAssert(objc_lookUpClass(className) != Nil,
+ @"Class %s not defined", className);
+ }
+#endif
+
+ if (description->extendedClass) {
+ Class containingClass = objc_lookUpClass(description->extendedClass);
+ NSAssert(containingClass, @"Class %s not defined",
+ description->extendedClass);
+ containingMessageClass_ = containingClass;
+ }
+
+ GPBDataType type = description_->dataType;
+ if (type == GPBDataTypeBytes) {
+ // Data stored as a length prefixed c-string in descriptor records.
+ const uint8_t *bytes =
+ (const uint8_t *)description->defaultValue.valueData;
+ if (bytes) {
+ uint32_t length = *((uint32_t *)bytes);
+ // The length is stored in network byte order.
+ length = ntohl(length);
+ bytes += sizeof(length);
+ defaultValue_.valueData =
+ [[NSData alloc] initWithBytes:bytes length:length];
+ }
+ } else if (type == GPBDataTypeMessage || type == GPBDataTypeGroup) {
+ // The default is looked up in -defaultValue instead since extensions
+ // aren't common, we avoid the hit startup hit and it avoid initialization
+ // order issues.
+ } else {
+ defaultValue_ = description->defaultValue;
+ }
+ }
+ return self;
+}
+
+- (void)dealloc {
+ if ((description_->dataType == GPBDataTypeBytes) &&
+ !GPBExtensionIsRepeated(description_)) {
+ [defaultValue_.valueData release];
+ }
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+#pragma unused(zone)
+ // Immutable.
+ return [self retain];
+}
+
+- (NSString *)singletonName {
+ return @(description_->singletonName);
+}
+
+- (const char *)singletonNameC {
+ return description_->singletonName;
+}
+
+- (uint32_t)fieldNumber {
+ return description_->fieldNumber;
+}
+
+- (GPBDataType)dataType {
+ return description_->dataType;
+}
+
+- (GPBWireFormat)wireType {
+ return GPBWireFormatForType(description_->dataType,
+ GPBExtensionIsPacked(description_));
+}
+
+- (GPBWireFormat)alternateWireType {
+ NSAssert(GPBExtensionIsRepeated(description_),
+ @"Only valid on repeated extensions");
+ return GPBWireFormatForType(description_->dataType,
+ !GPBExtensionIsPacked(description_));
+}
+
+- (BOOL)isRepeated {
+ return GPBExtensionIsRepeated(description_);
+}
+
+- (BOOL)isMap {
+ return (description_->options & GPBFieldMapKeyMask) != 0;
+}
+
+- (BOOL)isPackable {
+ return GPBExtensionIsPacked(description_);
+}
+
+- (Class)msgClass {
+ return objc_getClass(description_->messageOrGroupClassName);
+}
+
+- (GPBEnumDescriptor *)enumDescriptor {
+ if (description_->dataType == GPBDataTypeEnum) {
+ GPBEnumDescriptor *enumDescriptor = description_->enumDescriptorFunc();
+ return enumDescriptor;
+ }
+ return nil;
+}
+
+- (id)defaultValue {
+ if (GPBExtensionIsRepeated(description_)) {
+ return nil;
+ }
+
+ switch (description_->dataType) {
+ case GPBDataTypeBool:
+ return @(defaultValue_.valueBool);
+ case GPBDataTypeFloat:
+ return @(defaultValue_.valueFloat);
+ case GPBDataTypeDouble:
+ return @(defaultValue_.valueDouble);
+ case GPBDataTypeInt32:
+ case GPBDataTypeSInt32:
+ case GPBDataTypeEnum:
+ case GPBDataTypeSFixed32:
+ return @(defaultValue_.valueInt32);
+ case GPBDataTypeInt64:
+ case GPBDataTypeSInt64:
+ case GPBDataTypeSFixed64:
+ return @(defaultValue_.valueInt64);
+ case GPBDataTypeUInt32:
+ case GPBDataTypeFixed32:
+ return @(defaultValue_.valueUInt32);
+ case GPBDataTypeUInt64:
+ case GPBDataTypeFixed64:
+ return @(defaultValue_.valueUInt64);
+ case GPBDataTypeBytes:
+ // Like message fields, the default is zero length data.
+ return (defaultValue_.valueData ? defaultValue_.valueData
+ : GPBEmptyNSData());
+ case GPBDataTypeString:
+ // Like message fields, the default is zero length string.
+ return (defaultValue_.valueString ? defaultValue_.valueString : @"");
+ case GPBDataTypeGroup:
+ case GPBDataTypeMessage:
+ return nil;
+ }
+}
+
+- (NSComparisonResult)compareByFieldNumber:(GPBExtensionDescriptor *)other {
+ int32_t selfNumber = description_->fieldNumber;
+ int32_t otherNumber = other->description_->fieldNumber;
+ if (selfNumber < otherNumber) {
+ return NSOrderedAscending;
+ } else if (selfNumber == otherNumber) {
+ return NSOrderedSame;
+ } else {
+ return NSOrderedDescending;
+ }
+}
+
+@end
+
+#pragma clang diagnostic pop
diff --git a/third_party/protobuf/objectivec/GPBDescriptor_PackagePrivate.h b/third_party/protobuf/objectivec/GPBDescriptor_PackagePrivate.h
new file mode 100644
index 0000000000..9173e7a2b1
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBDescriptor_PackagePrivate.h
@@ -0,0 +1,329 @@
+// 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.
+
+// This header is private to the ProtobolBuffers library and must NOT be
+// included by any sources outside this library. The contents of this file are
+// subject to change at any time without notice.
+
+#import "GPBDescriptor.h"
+#import "GPBWireFormat.h"
+
+// Describes attributes of the field.
+typedef NS_OPTIONS(uint16_t, GPBFieldFlags) {
+ GPBFieldNone = 0,
+ // These map to standard protobuf concepts.
+ GPBFieldRequired = 1 << 0,
+ GPBFieldRepeated = 1 << 1,
+ GPBFieldPacked = 1 << 2,
+ GPBFieldOptional = 1 << 3,
+ GPBFieldHasDefaultValue = 1 << 4,
+
+ // Indicates the field needs custom handling for the TextFormat name, if not
+ // set, the name can be derived from the ObjC name.
+ GPBFieldTextFormatNameCustom = 1 << 6,
+ // Indicates the field has an enum descriptor.
+ GPBFieldHasEnumDescriptor = 1 << 7,
+
+ // These are not standard protobuf concepts, they are specific to the
+ // Objective C runtime.
+
+ // These bits are used to mark the field as a map and what the key
+ // type is.
+ GPBFieldMapKeyMask = 0xF << 8,
+ GPBFieldMapKeyInt32 = 1 << 8,
+ GPBFieldMapKeyInt64 = 2 << 8,
+ GPBFieldMapKeyUInt32 = 3 << 8,
+ GPBFieldMapKeyUInt64 = 4 << 8,
+ GPBFieldMapKeySInt32 = 5 << 8,
+ GPBFieldMapKeySInt64 = 6 << 8,
+ GPBFieldMapKeyFixed32 = 7 << 8,
+ GPBFieldMapKeyFixed64 = 8 << 8,
+ GPBFieldMapKeySFixed32 = 9 << 8,
+ GPBFieldMapKeySFixed64 = 10 << 8,
+ GPBFieldMapKeyBool = 11 << 8,
+ GPBFieldMapKeyString = 12 << 8,
+};
+
+// NOTE: The structures defined here have their members ordered to minimize
+// their size. This directly impacts the size of apps since these exist per
+// field/extension.
+
+// Describes a single field in a protobuf as it is represented as an ivar.
+typedef struct GPBMessageFieldDescription {
+ // Name of ivar.
+ const char *name;
+ union {
+ const char *className; // Name for message class.
+ // For enums only: If EnumDescriptors are compiled in, it will be that,
+ // otherwise it will be the verifier.
+ GPBEnumDescriptorFunc enumDescFunc;
+ GPBEnumValidationFunc enumVerifier;
+ } dataTypeSpecific;
+ // The field number for the ivar.
+ uint32_t number;
+ // The index (in bits) into _has_storage_.
+ // >= 0: the bit to use for a value being set.
+ // = GPBNoHasBit(INT32_MAX): no storage used.
+ // < 0: in a oneOf, use a full int32 to record the field active.
+ int32_t hasIndex;
+ // Offset of the variable into it's structure struct.
+ uint32_t offset;
+ // Field flags. Use accessor functions below.
+ GPBFieldFlags flags;
+ // Data type of the ivar.
+ GPBDataType dataType;
+} GPBMessageFieldDescription;
+
+// Fields in messages defined in a 'proto2' syntax file can provide a default
+// value. This struct provides the default along with the field info.
+typedef struct GPBMessageFieldDescriptionWithDefault {
+ // Default value for the ivar.
+ GPBGenericValue defaultValue;
+
+ GPBMessageFieldDescription core;
+} GPBMessageFieldDescriptionWithDefault;
+
+// Describes attributes of the extension.
+typedef NS_OPTIONS(uint8_t, GPBExtensionOptions) {
+ GPBExtensionNone = 0,
+ // These map to standard protobuf concepts.
+ GPBExtensionRepeated = 1 << 0,
+ GPBExtensionPacked = 1 << 1,
+ GPBExtensionSetWireFormat = 1 << 2,
+};
+
+// An extension
+typedef struct GPBExtensionDescription {
+ GPBGenericValue defaultValue;
+ const char *singletonName;
+ const char *extendedClass;
+ const char *messageOrGroupClassName;
+ GPBEnumDescriptorFunc enumDescriptorFunc;
+ int32_t fieldNumber;
+ GPBDataType dataType;
+ GPBExtensionOptions options;
+} GPBExtensionDescription;
+
+typedef NS_OPTIONS(uint32_t, GPBDescriptorInitializationFlags) {
+ GPBDescriptorInitializationFlag_None = 0,
+ GPBDescriptorInitializationFlag_FieldsWithDefault = 1 << 0,
+ GPBDescriptorInitializationFlag_WireFormat = 1 << 1,
+};
+
+@interface GPBDescriptor () {
+ @package
+ NSArray *fields_;
+ NSArray *oneofs_;
+ uint32_t storageSize_;
+}
+
+// fieldDescriptions have to be long lived, they are held as raw pointers.
++ (instancetype)
+ allocDescriptorForClass:(Class)messageClass
+ rootClass:(Class)rootClass
+ file:(GPBFileDescriptor *)file
+ fields:(void *)fieldDescriptions
+ fieldCount:(uint32_t)fieldCount
+ storageSize:(uint32_t)storageSize
+ flags:(GPBDescriptorInitializationFlags)flags;
+
+- (instancetype)initWithClass:(Class)messageClass
+ file:(GPBFileDescriptor *)file
+ fields:(NSArray *)fields
+ storageSize:(uint32_t)storage
+ wireFormat:(BOOL)wireFormat;
+
+// Called right after init to provide extra information to avoid init having
+// an explosion of args. These pointers are recorded, so they are expected
+// to live for the lifetime of the app.
+- (void)setupOneofs:(const char **)oneofNames
+ count:(uint32_t)count
+ firstHasIndex:(int32_t)firstHasIndex;
+- (void)setupExtraTextInfo:(const char *)extraTextFormatInfo;
+- (void)setupExtensionRanges:(const GPBExtensionRange *)ranges count:(int32_t)count;
+- (void)setupContainingMessageClassName:(const char *)msgClassName;
+- (void)setupMessageClassNameSuffix:(NSString *)suffix;
+
+@end
+
+@interface GPBFileDescriptor ()
+- (instancetype)initWithPackage:(NSString *)package
+ objcPrefix:(NSString *)objcPrefix
+ syntax:(GPBFileSyntax)syntax;
+- (instancetype)initWithPackage:(NSString *)package
+ syntax:(GPBFileSyntax)syntax;
+@end
+
+@interface GPBOneofDescriptor () {
+ @package
+ const char *name_;
+ NSArray *fields_;
+ SEL caseSel_;
+}
+// name must be long lived.
+- (instancetype)initWithName:(const char *)name fields:(NSArray *)fields;
+@end
+
+@interface GPBFieldDescriptor () {
+ @package
+ GPBMessageFieldDescription *description_;
+ GPB_UNSAFE_UNRETAINED GPBOneofDescriptor *containingOneof_;
+
+ SEL getSel_;
+ SEL setSel_;
+ SEL hasOrCountSel_; // *Count for map<>/repeated fields, has* otherwise.
+ SEL setHasSel_;
+}
+
+// Single initializer
+// description has to be long lived, it is held as a raw pointer.
+- (instancetype)initWithFieldDescription:(void *)description
+ includesDefault:(BOOL)includesDefault
+ syntax:(GPBFileSyntax)syntax;
+@end
+
+@interface GPBEnumDescriptor ()
+// valueNames, values and extraTextFormatInfo have to be long lived, they are
+// held as raw pointers.
++ (instancetype)
+ allocDescriptorForName:(NSString *)name
+ valueNames:(const char *)valueNames
+ values:(const int32_t *)values
+ count:(uint32_t)valueCount
+ enumVerifier:(GPBEnumValidationFunc)enumVerifier;
++ (instancetype)
+ allocDescriptorForName:(NSString *)name
+ valueNames:(const char *)valueNames
+ values:(const int32_t *)values
+ count:(uint32_t)valueCount
+ enumVerifier:(GPBEnumValidationFunc)enumVerifier
+ extraTextFormatInfo:(const char *)extraTextFormatInfo;
+
+- (instancetype)initWithName:(NSString *)name
+ valueNames:(const char *)valueNames
+ values:(const int32_t *)values
+ count:(uint32_t)valueCount
+ enumVerifier:(GPBEnumValidationFunc)enumVerifier;
+@end
+
+@interface GPBExtensionDescriptor () {
+ @package
+ GPBExtensionDescription *description_;
+}
+@property(nonatomic, readonly) GPBWireFormat wireType;
+
+// For repeated extensions, alternateWireType is the wireType with the opposite
+// value for the packable property. i.e. - if the extension was marked packed
+// it would be the wire type for unpacked; if the extension was marked unpacked,
+// it would be the wire type for packed.
+@property(nonatomic, readonly) GPBWireFormat alternateWireType;
+
+// description has to be long lived, it is held as a raw pointer.
+- (instancetype)initWithExtensionDescription:
+ (GPBExtensionDescription *)description;
+- (NSComparisonResult)compareByFieldNumber:(GPBExtensionDescriptor *)other;
+@end
+
+CF_EXTERN_C_BEGIN
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+GPB_INLINE BOOL GPBFieldIsMapOrArray(GPBFieldDescriptor *field) {
+ return (field->description_->flags &
+ (GPBFieldRepeated | GPBFieldMapKeyMask)) != 0;
+}
+
+GPB_INLINE GPBDataType GPBGetFieldDataType(GPBFieldDescriptor *field) {
+ return field->description_->dataType;
+}
+
+GPB_INLINE int32_t GPBFieldHasIndex(GPBFieldDescriptor *field) {
+ return field->description_->hasIndex;
+}
+
+GPB_INLINE uint32_t GPBFieldNumber(GPBFieldDescriptor *field) {
+ return field->description_->number;
+}
+
+#pragma clang diagnostic pop
+
+uint32_t GPBFieldTag(GPBFieldDescriptor *self);
+
+// For repeated fields, alternateWireType is the wireType with the opposite
+// value for the packable property. i.e. - if the field was marked packed it
+// would be the wire type for unpacked; if the field was marked unpacked, it
+// would be the wire type for packed.
+uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self);
+
+GPB_INLINE BOOL GPBPreserveUnknownFields(GPBFileSyntax syntax) {
+ return syntax != GPBFileSyntaxProto3;
+}
+
+GPB_INLINE BOOL GPBHasPreservingUnknownEnumSemantics(GPBFileSyntax syntax) {
+ return syntax == GPBFileSyntaxProto3;
+}
+
+GPB_INLINE BOOL GPBExtensionIsRepeated(GPBExtensionDescription *description) {
+ return (description->options & GPBExtensionRepeated) != 0;
+}
+
+GPB_INLINE BOOL GPBExtensionIsPacked(GPBExtensionDescription *description) {
+ return (description->options & GPBExtensionPacked) != 0;
+}
+
+GPB_INLINE BOOL GPBExtensionIsWireFormat(GPBExtensionDescription *description) {
+ return (description->options & GPBExtensionSetWireFormat) != 0;
+}
+
+// Helper for compile time assets.
+#ifndef GPBInternalCompileAssert
+ #if __has_feature(c_static_assert) || __has_extension(c_static_assert)
+ #define GPBInternalCompileAssert(test, msg) _Static_assert((test), #msg)
+ #else
+ // Pre-Xcode 7 support.
+ #define GPBInternalCompileAssertSymbolInner(line, msg) GPBInternalCompileAssert ## line ## __ ## msg
+ #define GPBInternalCompileAssertSymbol(line, msg) GPBInternalCompileAssertSymbolInner(line, msg)
+ #define GPBInternalCompileAssert(test, msg) \
+ typedef char GPBInternalCompileAssertSymbol(__LINE__, msg) [ ((test) ? 1 : -1) ]
+ #endif // __has_feature(c_static_assert) || __has_extension(c_static_assert)
+#endif // GPBInternalCompileAssert
+
+// Sanity check that there isn't padding between the field description
+// structures with and without a default.
+GPBInternalCompileAssert(sizeof(GPBMessageFieldDescriptionWithDefault) ==
+ (sizeof(GPBGenericValue) +
+ sizeof(GPBMessageFieldDescription)),
+ DescriptionsWithDefault_different_size_than_expected);
+
+CF_EXTERN_C_END
diff --git a/third_party/protobuf/objectivec/GPBDictionary.h b/third_party/protobuf/objectivec/GPBDictionary.h
new file mode 100644
index 0000000000..9d674150e3
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBDictionary.h
@@ -0,0 +1,8570 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBRuntimeTypes.h"
+
+// Note on naming: for the classes holding numeric values, a more natural
+// naming of the method might be things like "-valueForKey:",
+// "-setValue:forKey:"; etc. But those selectors are also defined by Key Value
+// Coding (KVC) as categories on NSObject. So "overloading" the selectors with
+// other meanings can cause warnings (based on compiler settings), but more
+// importantly, some of those selector get called as KVC breaks up keypaths.
+// So if those selectors are used, using KVC will compile cleanly, but could
+// crash as it invokes those selectors with the wrong types of arguments.
+
+NS_ASSUME_NONNULL_BEGIN
+
+//%PDDM-EXPAND DECLARE_DICTIONARIES()
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - UInt32 -> UInt32
+
+/**
+ * Class used for map fields of <uint32_t, uint32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32UInt32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(uint32_t key, uint32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt32UInt32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt32:(uint32_t)value forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt32ForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt32 -> Int32
+
+/**
+ * Class used for map fields of <uint32_t, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32Int32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32Int32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32Int32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(uint32_t key, int32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt32Int32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt32:(int32_t)value forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt32ForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt32 -> UInt64
+
+/**
+ * Class used for map fields of <uint32_t, uint64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32UInt64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(uint32_t key, uint64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt32UInt64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt64:(uint64_t)value forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt64ForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt32 -> Int64
+
+/**
+ * Class used for map fields of <uint32_t, int64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32Int64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32Int64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32Int64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(uint32_t key, int64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt32Int64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt64:(int64_t)value forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt64ForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt32 -> Bool
+
+/**
+ * Class used for map fields of <uint32_t, BOOL>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32BoolDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32BoolDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithBools:(const BOOL [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32BoolDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getBool:(nullable BOOL *)value forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(uint32_t key, BOOL value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt32BoolDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setBool:(BOOL)value forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeBoolForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt32 -> Float
+
+/**
+ * Class used for map fields of <uint32_t, float>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32FloatDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithFloats:(const float [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32FloatDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithFloats:(const float [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32FloatDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getFloat:(nullable float *)value forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(uint32_t key, float value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt32FloatDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setFloat:(float)value forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeFloatForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt32 -> Double
+
+/**
+ * Class used for map fields of <uint32_t, double>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32DoubleDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithDoubles:(const double [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32DoubleDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithDoubles:(const double [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32DoubleDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getDouble:(nullable double *)value forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(uint32_t key, double value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt32DoubleDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setDouble:(double)value forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeDoubleForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt32 -> Enum
+
+/**
+ * Class used for map fields of <uint32_t, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32EnumDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+/** The validation function to check if the enums are valid. */
+@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly instanced dictionary.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param rawValue The raw enum value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32EnumDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+/**
+ * Initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly initialized dictionary.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly initialized dictionary with the keys and values in it.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly initialized dictionary with the entries from the given
+ * dictionary in it.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32EnumDictionary *)dictionary;
+
+/**
+ * Initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly initialized dictionary with the given capacity.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
+// is not a valid enumerator as defined by validationFunc. If the actual value is
+// desired, use "raw" version of the method.
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getEnum:(nullable int32_t *)value forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(uint32_t key, int32_t value, BOOL *stop))block;
+
+/**
+ * Gets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **rawValue**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(uint32_t key, int32_t rawValue, BOOL *stop))block;
+
+/**
+ * Adds the keys and raw enum values from another dictionary.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary;
+
+// If value is not a valid enumerator as defined by validationFunc, these
+// methods will assert in debug, and will log in release and assign the value
+// to the default value. Use the rawValue methods below to assign non enumerator
+// values.
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setEnum:(int32_t)value forKey:(uint32_t)key;
+
+/**
+ * Sets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue The raw enum value to set.
+ * @param key The key under which to store the raw enum value.
+ **/
+- (void)setRawValue:(int32_t)rawValue forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeEnumForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt32 -> Object
+
+/**
+ * Class used for map fields of <uint32_t, ObjectType>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt32ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param object The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithObject:(ObjectType)object
+ forKey:(uint32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param objects The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt32ObjectDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param objects The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const uint32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt32ObjectDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Fetches the object stored under the given key.
+ *
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return The object if found, nil otherwise.
+ **/
+- (ObjectType)objectForKey:(uint32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **object**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(uint32_t key, ObjectType object, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt32ObjectDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param object The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setObject:(ObjectType)object forKey:(uint32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeObjectForKey:(uint32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> UInt32
+
+/**
+ * Class used for map fields of <int32_t, uint32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32UInt32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32UInt32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(int32_t key, uint32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt32:(uint32_t)value forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt32ForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> Int32
+
+/**
+ * Class used for map fields of <int32_t, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32Int32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32Int32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(int32_t key, int32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt32:(int32_t)value forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt32ForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> UInt64
+
+/**
+ * Class used for map fields of <int32_t, uint64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32UInt64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32UInt64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(int32_t key, uint64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt64:(uint64_t)value forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt64ForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> Int64
+
+/**
+ * Class used for map fields of <int32_t, int64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32Int64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32Int64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(int32_t key, int64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt64:(int64_t)value forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt64ForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> Bool
+
+/**
+ * Class used for map fields of <int32_t, BOOL>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32BoolDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32BoolDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithBools:(const BOOL [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getBool:(nullable BOOL *)value forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(int32_t key, BOOL value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setBool:(BOOL)value forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeBoolForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> Float
+
+/**
+ * Class used for map fields of <int32_t, float>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32FloatDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithFloats:(const float [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32FloatDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithFloats:(const float [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getFloat:(nullable float *)value forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(int32_t key, float value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setFloat:(float)value forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeFloatForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> Double
+
+/**
+ * Class used for map fields of <int32_t, double>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32DoubleDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithDoubles:(const double [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32DoubleDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithDoubles:(const double [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getDouble:(nullable double *)value forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(int32_t key, double value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setDouble:(double)value forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeDoubleForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> Enum
+
+/**
+ * Class used for map fields of <int32_t, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32EnumDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+/** The validation function to check if the enums are valid. */
+@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly instanced dictionary.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param rawValue The raw enum value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32EnumDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+/**
+ * Initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly initialized dictionary.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly initialized dictionary with the keys and values in it.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly initialized dictionary with the entries from the given
+ * dictionary in it.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32EnumDictionary *)dictionary;
+
+/**
+ * Initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly initialized dictionary with the given capacity.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
+// is not a valid enumerator as defined by validationFunc. If the actual value is
+// desired, use "raw" version of the method.
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getEnum:(nullable int32_t *)value forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(int32_t key, int32_t value, BOOL *stop))block;
+
+/**
+ * Gets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **rawValue**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(int32_t key, int32_t rawValue, BOOL *stop))block;
+
+/**
+ * Adds the keys and raw enum values from another dictionary.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary;
+
+// If value is not a valid enumerator as defined by validationFunc, these
+// methods will assert in debug, and will log in release and assign the value
+// to the default value. Use the rawValue methods below to assign non enumerator
+// values.
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setEnum:(int32_t)value forKey:(int32_t)key;
+
+/**
+ * Sets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue The raw enum value to set.
+ * @param key The key under which to store the raw enum value.
+ **/
+- (void)setRawValue:(int32_t)rawValue forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeEnumForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int32 -> Object
+
+/**
+ * Class used for map fields of <int32_t, ObjectType>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt32ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param object The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithObject:(ObjectType)object
+ forKey:(int32_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param objects The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt32ObjectDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param objects The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const int32_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt32ObjectDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Fetches the object stored under the given key.
+ *
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return The object if found, nil otherwise.
+ **/
+- (ObjectType)objectForKey:(int32_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **object**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(int32_t key, ObjectType object, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt32ObjectDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param object The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setObject:(ObjectType)object forKey:(int32_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeObjectForKey:(int32_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> UInt32
+
+/**
+ * Class used for map fields of <uint64_t, uint32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64UInt32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(uint64_t key, uint32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt32:(uint32_t)value forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt32ForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> Int32
+
+/**
+ * Class used for map fields of <uint64_t, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64Int32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64Int32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(uint64_t key, int32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt32:(int32_t)value forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt32ForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> UInt64
+
+/**
+ * Class used for map fields of <uint64_t, uint64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64UInt64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(uint64_t key, uint64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt64:(uint64_t)value forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt64ForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> Int64
+
+/**
+ * Class used for map fields of <uint64_t, int64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64Int64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64Int64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(uint64_t key, int64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt64:(int64_t)value forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt64ForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> Bool
+
+/**
+ * Class used for map fields of <uint64_t, BOOL>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64BoolDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64BoolDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithBools:(const BOOL [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getBool:(nullable BOOL *)value forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(uint64_t key, BOOL value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setBool:(BOOL)value forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeBoolForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> Float
+
+/**
+ * Class used for map fields of <uint64_t, float>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64FloatDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithFloats:(const float [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64FloatDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithFloats:(const float [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getFloat:(nullable float *)value forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(uint64_t key, float value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setFloat:(float)value forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeFloatForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> Double
+
+/**
+ * Class used for map fields of <uint64_t, double>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64DoubleDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithDoubles:(const double [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64DoubleDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithDoubles:(const double [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getDouble:(nullable double *)value forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(uint64_t key, double value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setDouble:(double)value forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeDoubleForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> Enum
+
+/**
+ * Class used for map fields of <uint64_t, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64EnumDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+/** The validation function to check if the enums are valid. */
+@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly instanced dictionary.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param rawValue The raw enum value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64EnumDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+/**
+ * Initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly initialized dictionary.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly initialized dictionary with the keys and values in it.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly initialized dictionary with the entries from the given
+ * dictionary in it.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64EnumDictionary *)dictionary;
+
+/**
+ * Initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly initialized dictionary with the given capacity.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
+// is not a valid enumerator as defined by validationFunc. If the actual value is
+// desired, use "raw" version of the method.
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getEnum:(nullable int32_t *)value forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(uint64_t key, int32_t value, BOOL *stop))block;
+
+/**
+ * Gets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **rawValue**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(uint64_t key, int32_t rawValue, BOOL *stop))block;
+
+/**
+ * Adds the keys and raw enum values from another dictionary.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary;
+
+// If value is not a valid enumerator as defined by validationFunc, these
+// methods will assert in debug, and will log in release and assign the value
+// to the default value. Use the rawValue methods below to assign non enumerator
+// values.
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setEnum:(int32_t)value forKey:(uint64_t)key;
+
+/**
+ * Sets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue The raw enum value to set.
+ * @param key The key under which to store the raw enum value.
+ **/
+- (void)setRawValue:(int32_t)rawValue forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeEnumForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - UInt64 -> Object
+
+/**
+ * Class used for map fields of <uint64_t, ObjectType>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBUInt64ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param object The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithObject:(ObjectType)object
+ forKey:(uint64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param objects The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBUInt64ObjectDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param objects The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const uint64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBUInt64ObjectDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Fetches the object stored under the given key.
+ *
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return The object if found, nil otherwise.
+ **/
+- (ObjectType)objectForKey:(uint64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **object**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(uint64_t key, ObjectType object, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBUInt64ObjectDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param object The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setObject:(ObjectType)object forKey:(uint64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeObjectForKey:(uint64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> UInt32
+
+/**
+ * Class used for map fields of <int64_t, uint32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64UInt32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64UInt32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(int64_t key, uint32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt32:(uint32_t)value forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt32ForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> Int32
+
+/**
+ * Class used for map fields of <int64_t, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64Int32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64Int32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(int64_t key, int32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt32:(int32_t)value forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt32ForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> UInt64
+
+/**
+ * Class used for map fields of <int64_t, uint64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64UInt64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64UInt64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(int64_t key, uint64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt64:(uint64_t)value forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt64ForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> Int64
+
+/**
+ * Class used for map fields of <int64_t, int64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64Int64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64Int64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(int64_t key, int64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt64:(int64_t)value forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt64ForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> Bool
+
+/**
+ * Class used for map fields of <int64_t, BOOL>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64BoolDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64BoolDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithBools:(const BOOL [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getBool:(nullable BOOL *)value forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(int64_t key, BOOL value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setBool:(BOOL)value forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeBoolForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> Float
+
+/**
+ * Class used for map fields of <int64_t, float>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64FloatDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithFloats:(const float [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64FloatDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithFloats:(const float [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getFloat:(nullable float *)value forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(int64_t key, float value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setFloat:(float)value forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeFloatForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> Double
+
+/**
+ * Class used for map fields of <int64_t, double>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64DoubleDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithDoubles:(const double [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64DoubleDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithDoubles:(const double [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getDouble:(nullable double *)value forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(int64_t key, double value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setDouble:(double)value forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeDoubleForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> Enum
+
+/**
+ * Class used for map fields of <int64_t, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64EnumDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+/** The validation function to check if the enums are valid. */
+@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly instanced dictionary.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param rawValue The raw enum value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64EnumDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+/**
+ * Initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly initialized dictionary.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly initialized dictionary with the keys and values in it.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly initialized dictionary with the entries from the given
+ * dictionary in it.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64EnumDictionary *)dictionary;
+
+/**
+ * Initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly initialized dictionary with the given capacity.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
+// is not a valid enumerator as defined by validationFunc. If the actual value is
+// desired, use "raw" version of the method.
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getEnum:(nullable int32_t *)value forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(int64_t key, int32_t value, BOOL *stop))block;
+
+/**
+ * Gets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **rawValue**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(int64_t key, int32_t rawValue, BOOL *stop))block;
+
+/**
+ * Adds the keys and raw enum values from another dictionary.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary;
+
+// If value is not a valid enumerator as defined by validationFunc, these
+// methods will assert in debug, and will log in release and assign the value
+// to the default value. Use the rawValue methods below to assign non enumerator
+// values.
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setEnum:(int32_t)value forKey:(int64_t)key;
+
+/**
+ * Sets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue The raw enum value to set.
+ * @param key The key under which to store the raw enum value.
+ **/
+- (void)setRawValue:(int32_t)rawValue forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeEnumForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Int64 -> Object
+
+/**
+ * Class used for map fields of <int64_t, ObjectType>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBInt64ObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param object The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithObject:(ObjectType)object
+ forKey:(int64_t)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param objects The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBInt64ObjectDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param objects The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const int64_t [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBInt64ObjectDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Fetches the object stored under the given key.
+ *
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return The object if found, nil otherwise.
+ **/
+- (ObjectType)objectForKey:(int64_t)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **object**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(int64_t key, ObjectType object, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBInt64ObjectDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param object The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setObject:(ObjectType)object forKey:(int64_t)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeObjectForKey:(int64_t)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> UInt32
+
+/**
+ * Class used for map fields of <BOOL, uint32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolUInt32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolUInt32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(BOOL key, uint32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBBoolUInt32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt32:(uint32_t)value forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt32ForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> Int32
+
+/**
+ * Class used for map fields of <BOOL, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolInt32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolInt32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(BOOL key, int32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBBoolInt32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt32:(int32_t)value forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt32ForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> UInt64
+
+/**
+ * Class used for map fields of <BOOL, uint64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolUInt64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolUInt64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(BOOL key, uint64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBBoolUInt64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt64:(uint64_t)value forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt64ForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> Int64
+
+/**
+ * Class used for map fields of <BOOL, int64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolInt64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolInt64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(BOOL key, int64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBBoolInt64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt64:(int64_t)value forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt64ForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> Bool
+
+/**
+ * Class used for map fields of <BOOL, BOOL>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolBoolDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolBoolDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithBools:(const BOOL [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getBool:(nullable BOOL *)value forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(BOOL key, BOOL value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBBoolBoolDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setBool:(BOOL)value forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeBoolForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> Float
+
+/**
+ * Class used for map fields of <BOOL, float>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolFloatDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithFloats:(const float [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolFloatDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithFloats:(const float [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getFloat:(nullable float *)value forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(BOOL key, float value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBBoolFloatDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setFloat:(float)value forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeFloatForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> Double
+
+/**
+ * Class used for map fields of <BOOL, double>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolDoubleDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithDoubles:(const double [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolDoubleDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithDoubles:(const double [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getDouble:(nullable double *)value forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(BOOL key, double value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBBoolDoubleDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setDouble:(double)value forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeDoubleForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> Enum
+
+/**
+ * Class used for map fields of <BOOL, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolEnumDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+/** The validation function to check if the enums are valid. */
+@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly instanced dictionary.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param rawValue The raw enum value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolEnumDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+/**
+ * Initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly initialized dictionary.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly initialized dictionary with the keys and values in it.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly initialized dictionary with the entries from the given
+ * dictionary in it.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolEnumDictionary *)dictionary;
+
+/**
+ * Initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly initialized dictionary with the given capacity.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
+// is not a valid enumerator as defined by validationFunc. If the actual value is
+// desired, use "raw" version of the method.
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getEnum:(nullable int32_t *)value forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(BOOL key, int32_t value, BOOL *stop))block;
+
+/**
+ * Gets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **rawValue**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(BOOL key, int32_t rawValue, BOOL *stop))block;
+
+/**
+ * Adds the keys and raw enum values from another dictionary.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addRawEntriesFromDictionary:(GPBBoolEnumDictionary *)otherDictionary;
+
+// If value is not a valid enumerator as defined by validationFunc, these
+// methods will assert in debug, and will log in release and assign the value
+// to the default value. Use the rawValue methods below to assign non enumerator
+// values.
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setEnum:(int32_t)value forKey:(BOOL)key;
+
+/**
+ * Sets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue The raw enum value to set.
+ * @param key The key under which to store the raw enum value.
+ **/
+- (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeEnumForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - Bool -> Object
+
+/**
+ * Class used for map fields of <BOOL, ObjectType>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBBoolObjectDictionary<__covariant ObjectType> : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param object The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithObject:(ObjectType)object
+ forKey:(BOOL)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param objects The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBBoolObjectDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param objects The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithObjects:(const ObjectType __nonnull GPB_UNSAFE_UNRETAINED [__nullable])objects
+ forKeys:(const BOOL [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBBoolObjectDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Fetches the object stored under the given key.
+ *
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return The object if found, nil otherwise.
+ **/
+- (ObjectType)objectForKey:(BOOL)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **object**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(BOOL key, ObjectType object, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBBoolObjectDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param object The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setObject:(ObjectType)object forKey:(BOOL)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeObjectForKey:(BOOL)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - String -> UInt32
+
+/**
+ * Class used for map fields of <NSString, uint32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBStringUInt32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(NSString *)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBStringUInt32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt32s:(const uint32_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(NSString *key, uint32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt32:(uint32_t)value forKey:(NSString *)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt32ForKey:(NSString *)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - String -> Int32
+
+/**
+ * Class used for map fields of <NSString, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBStringInt32Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(NSString *)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBStringInt32Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt32s:(const int32_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(NSString *key, int32_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt32:(int32_t)value forKey:(NSString *)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt32ForKey:(NSString *)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - String -> UInt64
+
+/**
+ * Class used for map fields of <NSString, uint64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBStringUInt64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(NSString *)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBStringUInt64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithUInt64s:(const uint64_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(NSString *key, uint64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setUInt64:(uint64_t)value forKey:(NSString *)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeUInt64ForKey:(NSString *)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - String -> Int64
+
+/**
+ * Class used for map fields of <NSString, int64_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBStringInt64Dictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(NSString *)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBStringInt64Dictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithInt64s:(const int64_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(NSString *key, int64_t value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setInt64:(int64_t)value forKey:(NSString *)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeInt64ForKey:(NSString *)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - String -> Bool
+
+/**
+ * Class used for map fields of <NSString, BOOL>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBStringBoolDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(NSString *)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithBools:(const BOOL [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBStringBoolDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithBools:(const BOOL [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getBool:(nullable BOOL *)value forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(NSString *key, BOOL value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setBool:(BOOL)value forKey:(NSString *)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeBoolForKey:(NSString *)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - String -> Float
+
+/**
+ * Class used for map fields of <NSString, float>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBStringFloatDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(NSString *)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithFloats:(const float [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBStringFloatDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithFloats:(const float [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getFloat:(nullable float *)value forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(NSString *key, float value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setFloat:(float)value forKey:(NSString *)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeFloatForKey:(NSString *)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - String -> Double
+
+/**
+ * Class used for map fields of <NSString, double>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBStringDoubleDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param value The value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(NSString *)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param values The values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithDoubles:(const double [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBStringDoubleDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Initializes this dictionary, copying the given values and keys.
+ *
+ * @param values The values to be placed in this dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of elements to copy into the dictionary.
+ *
+ * @return A newly initialized dictionary with a copy of the values and keys.
+ **/
+- (instancetype)initWithDoubles:(const double [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes this dictionary, copying the entries from the given dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to this dictionary.
+ *
+ * @return A newly initialized dictionary with the entries of the given dictionary.
+ **/
+- (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary;
+
+/**
+ * Initializes this dictionary with the requested capacity.
+ *
+ * @param numItems Number of items needed for this dictionary.
+ *
+ * @return A newly initialized dictionary with the requested capacity.
+ **/
+- (instancetype)initWithCapacity:(NSUInteger)numItems;
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getDouble:(nullable double *)value forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(NSString *key, double value, BOOL *stop))block;
+
+/**
+ * Adds the keys and values from another dictionary.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary;
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setDouble:(double)value forKey:(NSString *)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeDoubleForKey:(NSString *)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+#pragma mark - String -> Enum
+
+/**
+ * Class used for map fields of <NSString, int32_t>
+ * values. This performs better than boxing into NSNumbers in NSDictionaries.
+ *
+ * @note This class is not meant to be subclassed.
+ **/
+@interface GPBStringEnumDictionary : NSObject <NSCopying>
+
+/** Number of entries stored in this dictionary. */
+@property(nonatomic, readonly) NSUInteger count;
+/** The validation function to check if the enums are valid. */
+@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+
+/**
+ * @return A newly instanced and empty dictionary.
+ **/
++ (instancetype)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly instanced dictionary.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Creates and initializes a dictionary with the single entry given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param rawValue The raw enum value to be placed in the dictionary.
+ * @param key The key under which to store the value.
+ *
+ * @return A newly instanced dictionary with the key and value in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(NSString *)key;
+
+/**
+ * Creates and initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly instanced dictionary with the keys and values in it.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count;
+
+/**
+ * Creates and initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly instanced dictionary with the entries from the given
+ * dictionary in it.
+ **/
++ (instancetype)dictionaryWithDictionary:(GPBStringEnumDictionary *)dictionary;
+
+/**
+ * Creates and initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly instanced dictionary with the given capacity.
+ **/
++ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+/**
+ * Initializes a dictionary with the given validation function.
+ *
+ * @param func The enum validation function for the dictionary.
+ *
+ * @return A newly initialized dictionary.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+
+/**
+ * Initializes a dictionary with the entries given.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param values The raw enum values values to be placed in the dictionary.
+ * @param keys The keys under which to store the values.
+ * @param count The number of entries to store in the dictionary.
+ *
+ * @return A newly initialized dictionary with the keys and values in it.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ rawValues:(const int32_t [__nullable])values
+ forKeys:(const NSString * __nonnull GPB_UNSAFE_UNRETAINED [__nullable])keys
+ count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+
+/**
+ * Initializes a dictionary with the entries from the given.
+ * dictionary.
+ *
+ * @param dictionary Dictionary containing the entries to add to the dictionary.
+ *
+ * @return A newly initialized dictionary with the entries from the given
+ * dictionary in it.
+ **/
+- (instancetype)initWithDictionary:(GPBStringEnumDictionary *)dictionary;
+
+/**
+ * Initializes a dictionary with the given capacity.
+ *
+ * @param func The enum validation function for the dictionary.
+ * @param numItems Capacity needed for the dictionary.
+ *
+ * @return A newly initialized dictionary with the given capacity.
+ **/
+- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems;
+
+// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
+// is not a valid enumerator as defined by validationFunc. If the actual value is
+// desired, use "raw" version of the method.
+
+/**
+ * Gets the value for the given key.
+ *
+ * @param value Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getEnum:(nullable int32_t *)value forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **value**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(NSString *key, int32_t value, BOOL *stop))block;
+
+/**
+ * Gets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue Pointer into which the value will be set, if found.
+ * @param key Key under which the value is stored, if present.
+ *
+ * @return YES if the key was found and the value was copied, NO otherwise.
+ **/
+- (BOOL)getRawValue:(nullable int32_t *)rawValue forKey:(NSString *)key;
+
+/**
+ * Enumerates the keys and values on this dictionary with the given block.
+ *
+ * @note This method bypass the validationFunc to enable the access of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param block The block to enumerate with.
+ * **key**: The key for the current entry.
+ * **rawValue**: The value for the current entry
+ * **stop**: A pointer to a boolean that when set stops the enumeration.
+ **/
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(NSString *key, int32_t rawValue, BOOL *stop))block;
+
+/**
+ * Adds the keys and raw enum values from another dictionary.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param otherDictionary Dictionary containing entries to be added to this
+ * dictionary.
+ **/
+- (void)addRawEntriesFromDictionary:(GPBStringEnumDictionary *)otherDictionary;
+
+// If value is not a valid enumerator as defined by validationFunc, these
+// methods will assert in debug, and will log in release and assign the value
+// to the default value. Use the rawValue methods below to assign non enumerator
+// values.
+
+/**
+ * Sets the value for the given key.
+ *
+ * @param value The value to set.
+ * @param key The key under which to store the value.
+ **/
+- (void)setEnum:(int32_t)value forKey:(NSString *)key;
+
+/**
+ * Sets the raw enum value for the given key.
+ *
+ * @note This method bypass the validationFunc to enable the setting of values that
+ * were not known at the time the binary was compiled.
+ *
+ * @param rawValue The raw enum value to set.
+ * @param key The key under which to store the raw enum value.
+ **/
+- (void)setRawValue:(int32_t)rawValue forKey:(NSString *)key;
+
+/**
+ * Removes the entry for the given key.
+ *
+ * @param aKey Key to be removed from this dictionary.
+ **/
+- (void)removeEnumForKey:(NSString *)aKey;
+
+/**
+ * Removes all entries in this dictionary.
+ **/
+- (void)removeAll;
+
+@end
+
+//%PDDM-EXPAND-END DECLARE_DICTIONARIES()
+
+NS_ASSUME_NONNULL_END
+
+//%PDDM-DEFINE DECLARE_DICTIONARIES()
+//%DICTIONARY_INTERFACES_FOR_POD_KEY(UInt32, uint32_t)
+//%DICTIONARY_INTERFACES_FOR_POD_KEY(Int32, int32_t)
+//%DICTIONARY_INTERFACES_FOR_POD_KEY(UInt64, uint64_t)
+//%DICTIONARY_INTERFACES_FOR_POD_KEY(Int64, int64_t)
+//%DICTIONARY_INTERFACES_FOR_POD_KEY(Bool, BOOL)
+//%DICTIONARY_POD_INTERFACES_FOR_KEY(String, NSString, *, OBJECT)
+//%PDDM-DEFINE DICTIONARY_INTERFACES_FOR_POD_KEY(KEY_NAME, KEY_TYPE)
+//%DICTIONARY_POD_INTERFACES_FOR_KEY(KEY_NAME, KEY_TYPE, , POD)
+//%DICTIONARY_POD_KEY_TO_OBJECT_INTERFACE(KEY_NAME, KEY_TYPE, Object, ObjectType)
+//%PDDM-DEFINE DICTIONARY_POD_INTERFACES_FOR_KEY(KEY_NAME, KEY_TYPE, KisP, KHELPER)
+//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, UInt32, uint32_t)
+//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Int32, int32_t)
+//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, UInt64, uint64_t)
+//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Int64, int64_t)
+//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Bool, BOOL)
+//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Float, float)
+//%DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Double, double)
+//%DICTIONARY_KEY_TO_ENUM_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, Enum, int32_t)
+//%PDDM-DEFINE DICTIONARY_KEY_TO_POD_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE)
+//%DICTIONARY_COMMON_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE, POD, VALUE_NAME, value)
+//%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_INTERFACE(KEY_NAME, KEY_TYPE, VALUE_NAME, VALUE_TYPE)
+//%DICTIONARY_COMMON_INTERFACE(KEY_NAME, KEY_TYPE, , POD, VALUE_NAME, VALUE_TYPE, OBJECT, Object, object)
+//%PDDM-DEFINE VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_TYPE, VNAME)
+//%/**
+//% * Gets the value for the given key.
+//% *
+//% * @param value Pointer into which the value will be set, if found.
+//% * @param key Key under which the value is stored, if present.
+//% *
+//% * @return YES if the key was found and the value was copied, NO otherwise.
+//% **/
+//%- (BOOL)get##VNAME##:(nullable VALUE_TYPE *)value forKey:(KEY_TYPE)key;
+//%PDDM-DEFINE VALUE_FOR_KEY_OBJECT(KEY_TYPE, VALUE_TYPE, VNAME)
+//%/**
+//% * Fetches the object stored under the given key.
+//% *
+//% * @param key Key under which the value is stored, if present.
+//% *
+//% * @return The object if found, nil otherwise.
+//% **/
+//%- (VALUE_TYPE)objectForKey:(KEY_TYPE)key;
+//%PDDM-DEFINE VALUE_FOR_KEY_Enum(KEY_TYPE, VALUE_TYPE, VNAME)
+//%VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_TYPE, VNAME)
+//%PDDM-DEFINE ARRAY_ARG_MODIFIERPOD()
+// Nothing
+//%PDDM-DEFINE ARRAY_ARG_MODIFIEREnum()
+// Nothing
+//%PDDM-DEFINE ARRAY_ARG_MODIFIEROBJECT()
+//%__nonnull GPB_UNSAFE_UNRETAINED ##
+//%PDDM-DEFINE DICTIONARY_CLASS_DECLPOD(KEY_NAME, VALUE_NAME, VALUE_TYPE)
+//%GPB##KEY_NAME##VALUE_NAME##Dictionary
+//%PDDM-DEFINE DICTIONARY_CLASS_DECLEnum(KEY_NAME, VALUE_NAME, VALUE_TYPE)
+//%GPB##KEY_NAME##VALUE_NAME##Dictionary
+//%PDDM-DEFINE DICTIONARY_CLASS_DECLOBJECT(KEY_NAME, VALUE_NAME, VALUE_TYPE)
+//%GPB##KEY_NAME##VALUE_NAME##Dictionary<__covariant VALUE_TYPE>
+//%PDDM-DEFINE DICTIONARY_COMMON_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
+//%#pragma mark - KEY_NAME -> VALUE_NAME
+//%
+//%/**
+//% * Class used for map fields of <##KEY_TYPE##, ##VALUE_TYPE##>
+//% * values. This performs better than boxing into NSNumbers in NSDictionaries.
+//% *
+//% * @note This class is not meant to be subclassed.
+//% **/
+//%@interface DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) : NSObject <NSCopying>
+//%
+//%/** Number of entries stored in this dictionary. */
+//%@property(nonatomic, readonly) NSUInteger count;
+//%
+//%/**
+//% * @return A newly instanced and empty dictionary.
+//% **/
+//%+ (instancetype)dictionary;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the single entry given.
+//% *
+//% * @param ##VNAME_VAR The value to be placed in the dictionary.
+//% * @param key ##VNAME_VAR$S## The key under which to store the value.
+//% *
+//% * @return A newly instanced dictionary with the key and value in it.
+//% **/
+//%+ (instancetype)dictionaryWith##VNAME##:(VALUE_TYPE)##VNAME_VAR
+//% ##VNAME$S## forKey:(KEY_TYPE##KisP$S##KisP)key;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the entries given.
+//% *
+//% * @param ##VNAME_VAR##s The values to be placed in the dictionary.
+//% * @param keys ##VNAME_VAR$S## The keys under which to store the values.
+//% * @param count ##VNAME_VAR$S## The number of entries to store in the dictionary.
+//% *
+//% * @return A newly instanced dictionary with the keys and values in it.
+//% **/
+//%+ (instancetype)dictionaryWith##VNAME##s:(const VALUE_TYPE ARRAY_ARG_MODIFIER##VHELPER()[__nullable])##VNAME_VAR##s
+//% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP ARRAY_ARG_MODIFIER##KHELPER()[__nullable])keys
+//% ##VNAME$S## count:(NSUInteger)count;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the entries from the given.
+//% * dictionary.
+//% *
+//% * @param dictionary Dictionary containing the entries to add to the dictionary.
+//% *
+//% * @return A newly instanced dictionary with the entries from the given
+//% * dictionary in it.
+//% **/
+//%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the given capacity.
+//% *
+//% * @param numItems Capacity needed for the dictionary.
+//% *
+//% * @return A newly instanced dictionary with the given capacity.
+//% **/
+//%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems;
+//%
+//%/**
+//% * Initializes this dictionary, copying the given values and keys.
+//% *
+//% * @param ##VNAME_VAR##s The values to be placed in this dictionary.
+//% * @param keys ##VNAME_VAR$S## The keys under which to store the values.
+//% * @param count ##VNAME_VAR$S## The number of elements to copy into the dictionary.
+//% *
+//% * @return A newly initialized dictionary with a copy of the values and keys.
+//% **/
+//%- (instancetype)initWith##VNAME##s:(const VALUE_TYPE ARRAY_ARG_MODIFIER##VHELPER()[__nullable])##VNAME_VAR##s
+//% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP ARRAY_ARG_MODIFIER##KHELPER()[__nullable])keys
+//% ##VNAME$S## count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+//%
+//%/**
+//% * Initializes this dictionary, copying the entries from the given dictionary.
+//% *
+//% * @param dictionary Dictionary containing the entries to add to this dictionary.
+//% *
+//% * @return A newly initialized dictionary with the entries of the given dictionary.
+//% **/
+//%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary;
+//%
+//%/**
+//% * Initializes this dictionary with the requested capacity.
+//% *
+//% * @param numItems Number of items needed for this dictionary.
+//% *
+//% * @return A newly initialized dictionary with the requested capacity.
+//% **/
+//%- (instancetype)initWithCapacity:(NSUInteger)numItems;
+//%
+//%DICTIONARY_IMMUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
+//%
+//%/**
+//% * Adds the keys and values from another dictionary.
+//% *
+//% * @param otherDictionary Dictionary containing entries to be added to this
+//% * dictionary.
+//% **/
+//%- (void)addEntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)otherDictionary;
+//%
+//%DICTIONARY_MUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
+//%
+//%@end
+//%
+
+//%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_INTERFACE(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE)
+//%DICTIONARY_KEY_TO_ENUM_INTERFACE2(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE, Enum)
+//%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_INTERFACE2(KEY_NAME, KEY_TYPE, KisP, KHELPER, VALUE_NAME, VALUE_TYPE, VHELPER)
+//%#pragma mark - KEY_NAME -> VALUE_NAME
+//%
+//%/**
+//% * Class used for map fields of <##KEY_TYPE##, ##VALUE_TYPE##>
+//% * values. This performs better than boxing into NSNumbers in NSDictionaries.
+//% *
+//% * @note This class is not meant to be subclassed.
+//% **/
+//%@interface GPB##KEY_NAME##VALUE_NAME##Dictionary : NSObject <NSCopying>
+//%
+//%/** Number of entries stored in this dictionary. */
+//%@property(nonatomic, readonly) NSUInteger count;
+//%/** The validation function to check if the enums are valid. */
+//%@property(nonatomic, readonly) GPBEnumValidationFunc validationFunc;
+//%
+//%/**
+//% * @return A newly instanced and empty dictionary.
+//% **/
+//%+ (instancetype)dictionary;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the given validation function.
+//% *
+//% * @param func The enum validation function for the dictionary.
+//% *
+//% * @return A newly instanced dictionary.
+//% **/
+//%+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the single entry given.
+//% *
+//% * @param func The enum validation function for the dictionary.
+//% * @param rawValue The raw enum value to be placed in the dictionary.
+//% * @param key The key under which to store the value.
+//% *
+//% * @return A newly instanced dictionary with the key and value in it.
+//% **/
+//%+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% rawValue:(VALUE_TYPE)rawValue
+//% forKey:(KEY_TYPE##KisP$S##KisP)key;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the entries given.
+//% *
+//% * @param func The enum validation function for the dictionary.
+//% * @param values The raw enum values values to be placed in the dictionary.
+//% * @param keys The keys under which to store the values.
+//% * @param count The number of entries to store in the dictionary.
+//% *
+//% * @return A newly instanced dictionary with the keys and values in it.
+//% **/
+//%+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% rawValues:(const VALUE_TYPE ARRAY_ARG_MODIFIER##VHELPER()[__nullable])values
+//% forKeys:(const KEY_TYPE##KisP$S##KisP ARRAY_ARG_MODIFIER##KHELPER()[__nullable])keys
+//% count:(NSUInteger)count;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the entries from the given.
+//% * dictionary.
+//% *
+//% * @param dictionary Dictionary containing the entries to add to the dictionary.
+//% *
+//% * @return A newly instanced dictionary with the entries from the given
+//% * dictionary in it.
+//% **/
+//%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary;
+//%
+//%/**
+//% * Creates and initializes a dictionary with the given capacity.
+//% *
+//% * @param func The enum validation function for the dictionary.
+//% * @param numItems Capacity needed for the dictionary.
+//% *
+//% * @return A newly instanced dictionary with the given capacity.
+//% **/
+//%+ (instancetype)dictionaryWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% capacity:(NSUInteger)numItems;
+//%
+//%/**
+//% * Initializes a dictionary with the given validation function.
+//% *
+//% * @param func The enum validation function for the dictionary.
+//% *
+//% * @return A newly initialized dictionary.
+//% **/
+//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func;
+//%
+//%/**
+//% * Initializes a dictionary with the entries given.
+//% *
+//% * @param func The enum validation function for the dictionary.
+//% * @param values The raw enum values values to be placed in the dictionary.
+//% * @param keys The keys under which to store the values.
+//% * @param count The number of entries to store in the dictionary.
+//% *
+//% * @return A newly initialized dictionary with the keys and values in it.
+//% **/
+//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% rawValues:(const VALUE_TYPE ARRAY_ARG_MODIFIER##VHELPER()[__nullable])values
+//% forKeys:(const KEY_TYPE##KisP$S##KisP ARRAY_ARG_MODIFIER##KHELPER()[__nullable])keys
+//% count:(NSUInteger)count NS_DESIGNATED_INITIALIZER;
+//%
+//%/**
+//% * Initializes a dictionary with the entries from the given.
+//% * dictionary.
+//% *
+//% * @param dictionary Dictionary containing the entries to add to the dictionary.
+//% *
+//% * @return A newly initialized dictionary with the entries from the given
+//% * dictionary in it.
+//% **/
+//%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary;
+//%
+//%/**
+//% * Initializes a dictionary with the given capacity.
+//% *
+//% * @param func The enum validation function for the dictionary.
+//% * @param numItems Capacity needed for the dictionary.
+//% *
+//% * @return A newly initialized dictionary with the given capacity.
+//% **/
+//%- (instancetype)initWithValidationFunction:(nullable GPBEnumValidationFunc)func
+//% capacity:(NSUInteger)numItems;
+//%
+//%// These will return kGPBUnrecognizedEnumeratorValue if the value for the key
+//%// is not a valid enumerator as defined by validationFunc. If the actual value is
+//%// desired, use "raw" version of the method.
+//%
+//%DICTIONARY_IMMUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, Enum, value)
+//%
+//%/**
+//% * Gets the raw enum value for the given key.
+//% *
+//% * @note This method bypass the validationFunc to enable the access of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param rawValue Pointer into which the value will be set, if found.
+//% * @param key Key under which the value is stored, if present.
+//% *
+//% * @return YES if the key was found and the value was copied, NO otherwise.
+//% **/
+//%- (BOOL)getRawValue:(nullable VALUE_TYPE *)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key;
+//%
+//%/**
+//% * Enumerates the keys and values on this dictionary with the given block.
+//% *
+//% * @note This method bypass the validationFunc to enable the access of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param block The block to enumerate with.
+//% * **key**: The key for the current entry.
+//% * **rawValue**: The value for the current entry
+//% * **stop**: A pointer to a boolean that when set stops the enumeration.
+//% **/
+//%- (void)enumerateKeysAndRawValuesUsingBlock:
+//% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE rawValue, BOOL *stop))block;
+//%
+//%/**
+//% * Adds the keys and raw enum values from another dictionary.
+//% *
+//% * @note This method bypass the validationFunc to enable the setting of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param otherDictionary Dictionary containing entries to be added to this
+//% * dictionary.
+//% **/
+//%- (void)addRawEntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)otherDictionary;
+//%
+//%// If value is not a valid enumerator as defined by validationFunc, these
+//%// methods will assert in debug, and will log in release and assign the value
+//%// to the default value. Use the rawValue methods below to assign non enumerator
+//%// values.
+//%
+//%DICTIONARY_MUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, Enum, value)
+//%
+//%@end
+//%
+
+//%PDDM-DEFINE DICTIONARY_IMMUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
+//%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_TYPE, VNAME)
+//%
+//%/**
+//% * Enumerates the keys and values on this dictionary with the given block.
+//% *
+//% * @param block The block to enumerate with.
+//% * **key**: ##VNAME_VAR$S## The key for the current entry.
+//% * **VNAME_VAR**: The value for the current entry
+//% * **stop**: ##VNAME_VAR$S## A pointer to a boolean that when set stops the enumeration.
+//% **/
+//%- (void)enumerateKeysAnd##VNAME##sUsingBlock:
+//% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop))block;
+
+//%PDDM-DEFINE DICTIONARY_MUTABLE_INTERFACE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, VHELPER, VNAME, VNAME_VAR)
+//%/**
+//% * Sets the value for the given key.
+//% *
+//% * @param ##VNAME_VAR The value to set.
+//% * @param key ##VNAME_VAR$S## The key under which to store the value.
+//% **/
+//%- (void)set##VNAME##:(VALUE_TYPE)##VNAME_VAR forKey:(KEY_TYPE##KisP$S##KisP)key;
+//%DICTIONARY_EXTRA_MUTABLE_METHODS_##VHELPER(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE)
+//%/**
+//% * Removes the entry for the given key.
+//% *
+//% * @param aKey Key to be removed from this dictionary.
+//% **/
+//%- (void)remove##VNAME##ForKey:(KEY_TYPE##KisP$S##KisP)aKey;
+//%
+//%/**
+//% * Removes all entries in this dictionary.
+//% **/
+//%- (void)removeAll;
+
+//%PDDM-DEFINE DICTIONARY_EXTRA_MUTABLE_METHODS_POD(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE)
+// Empty
+//%PDDM-DEFINE DICTIONARY_EXTRA_MUTABLE_METHODS_OBJECT(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE)
+// Empty
+//%PDDM-DEFINE DICTIONARY_EXTRA_MUTABLE_METHODS_Enum(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE)
+//%
+//%/**
+//% * Sets the raw enum value for the given key.
+//% *
+//% * @note This method bypass the validationFunc to enable the setting of values that
+//% * were not known at the time the binary was compiled.
+//% *
+//% * @param rawValue The raw enum value to set.
+//% * @param key The key under which to store the raw enum value.
+//% **/
+//%- (void)setRawValue:(VALUE_TYPE)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key;
+//%
diff --git a/third_party/protobuf/objectivec/GPBDictionary.m b/third_party/protobuf/objectivec/GPBDictionary.m
new file mode 100644
index 0000000000..1c67c680e9
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBDictionary.m
@@ -0,0 +1,13627 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBDictionary_PackagePrivate.h"
+
+#import "GPBCodedInputStream_PackagePrivate.h"
+#import "GPBCodedOutputStream_PackagePrivate.h"
+#import "GPBDescriptor_PackagePrivate.h"
+#import "GPBMessage_PackagePrivate.h"
+#import "GPBUtilities_PackagePrivate.h"
+
+// ------------------------------ NOTE ------------------------------
+// At the moment, this is all using NSNumbers in NSDictionaries under
+// the hood, but it is all hidden so we can come back and optimize
+// with direct CFDictionary usage later. The reason that wasn't
+// done yet is needing to support 32bit iOS builds. Otherwise
+// it would be pretty simple to store all this data in CFDictionaries
+// directly.
+// ------------------------------------------------------------------
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+// Used to include code only visible to specific versions of the static
+// analyzer. Useful for wrapping code that only exists to silence the analyzer.
+// Determine the values you want to use for BEGIN_APPLE_BUILD_VERSION,
+// END_APPLE_BUILD_VERSION using:
+// xcrun clang -dM -E -x c /dev/null | grep __apple_build_version__
+// Example usage:
+// #if GPB_STATIC_ANALYZER_ONLY(5621, 5623) ... #endif
+#define GPB_STATIC_ANALYZER_ONLY(BEGIN_APPLE_BUILD_VERSION, END_APPLE_BUILD_VERSION) \
+ (defined(__clang_analyzer__) && \
+ (__apple_build_version__ >= BEGIN_APPLE_BUILD_VERSION && \
+ __apple_build_version__ <= END_APPLE_BUILD_VERSION))
+
+enum {
+ kMapKeyFieldNumber = 1,
+ kMapValueFieldNumber = 2,
+};
+
+static BOOL DictDefault_IsValidValue(int32_t value) {
+ // Anything but the bad value marker is allowed.
+ return (value != kGPBUnrecognizedEnumeratorValue);
+}
+
+//%PDDM-DEFINE SERIALIZE_SUPPORT_2_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2)
+//%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
+//% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
+//% return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value);
+//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
+//% return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value);
+//% } else {
+//% NSCAssert(NO, @"Unexpected type %d", dataType);
+//% return 0;
+//% }
+//%}
+//%
+//%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
+//% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
+//% [stream write##GPBDATATYPE_NAME1##:fieldNum value:value];
+//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
+//% [stream write##GPBDATATYPE_NAME2##:fieldNum value:value];
+//% } else {
+//% NSCAssert(NO, @"Unexpected type %d", dataType);
+//% }
+//%}
+//%
+//%PDDM-DEFINE SERIALIZE_SUPPORT_3_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2, GPBDATATYPE_NAME3)
+//%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
+//% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
+//% return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value);
+//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
+//% return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value);
+//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) {
+//% return GPBCompute##GPBDATATYPE_NAME3##Size(fieldNum, value);
+//% } else {
+//% NSCAssert(NO, @"Unexpected type %d", dataType);
+//% return 0;
+//% }
+//%}
+//%
+//%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
+//% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
+//% [stream write##GPBDATATYPE_NAME1##:fieldNum value:value];
+//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
+//% [stream write##GPBDATATYPE_NAME2##:fieldNum value:value];
+//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) {
+//% [stream write##GPBDATATYPE_NAME3##:fieldNum value:value];
+//% } else {
+//% NSCAssert(NO, @"Unexpected type %d", dataType);
+//% }
+//%}
+//%
+//%PDDM-DEFINE SIMPLE_SERIALIZE_SUPPORT(VALUE_NAME, VALUE_TYPE, VisP)
+//%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE VisP##value, uint32_t fieldNum, GPBDataType dataType) {
+//% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType);
+//% #pragma unused(dataType) // For when asserts are off in release.
+//% return GPBCompute##VALUE_NAME##Size(fieldNum, value);
+//%}
+//%
+//%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE VisP##value, uint32_t fieldNum, GPBDataType dataType) {
+//% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType);
+//% #pragma unused(dataType) // For when asserts are off in release.
+//% [stream write##VALUE_NAME##:fieldNum value:value];
+//%}
+//%
+//%PDDM-DEFINE SERIALIZE_SUPPORT_HELPERS()
+//%SERIALIZE_SUPPORT_3_TYPE(Int32, int32_t, Int32, SInt32, SFixed32)
+//%SERIALIZE_SUPPORT_2_TYPE(UInt32, uint32_t, UInt32, Fixed32)
+//%SERIALIZE_SUPPORT_3_TYPE(Int64, int64_t, Int64, SInt64, SFixed64)
+//%SERIALIZE_SUPPORT_2_TYPE(UInt64, uint64_t, UInt64, Fixed64)
+//%SIMPLE_SERIALIZE_SUPPORT(Bool, BOOL, )
+//%SIMPLE_SERIALIZE_SUPPORT(Enum, int32_t, )
+//%SIMPLE_SERIALIZE_SUPPORT(Float, float, )
+//%SIMPLE_SERIALIZE_SUPPORT(Double, double, )
+//%SIMPLE_SERIALIZE_SUPPORT(String, NSString, *)
+//%SERIALIZE_SUPPORT_3_TYPE(Object, id, Message, String, Bytes)
+//%PDDM-EXPAND SERIALIZE_SUPPORT_HELPERS()
+// This block of code is generated, do not edit it directly.
+
+static size_t ComputeDictInt32FieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeInt32) {
+ return GPBComputeInt32Size(fieldNum, value);
+ } else if (dataType == GPBDataTypeSInt32) {
+ return GPBComputeSInt32Size(fieldNum, value);
+ } else if (dataType == GPBDataTypeSFixed32) {
+ return GPBComputeSFixed32Size(fieldNum, value);
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ return 0;
+ }
+}
+
+static void WriteDictInt32Field(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeInt32) {
+ [stream writeInt32:fieldNum value:value];
+ } else if (dataType == GPBDataTypeSInt32) {
+ [stream writeSInt32:fieldNum value:value];
+ } else if (dataType == GPBDataTypeSFixed32) {
+ [stream writeSFixed32:fieldNum value:value];
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ }
+}
+
+static size_t ComputeDictUInt32FieldSize(uint32_t value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeUInt32) {
+ return GPBComputeUInt32Size(fieldNum, value);
+ } else if (dataType == GPBDataTypeFixed32) {
+ return GPBComputeFixed32Size(fieldNum, value);
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ return 0;
+ }
+}
+
+static void WriteDictUInt32Field(GPBCodedOutputStream *stream, uint32_t value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeUInt32) {
+ [stream writeUInt32:fieldNum value:value];
+ } else if (dataType == GPBDataTypeFixed32) {
+ [stream writeFixed32:fieldNum value:value];
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ }
+}
+
+static size_t ComputeDictInt64FieldSize(int64_t value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeInt64) {
+ return GPBComputeInt64Size(fieldNum, value);
+ } else if (dataType == GPBDataTypeSInt64) {
+ return GPBComputeSInt64Size(fieldNum, value);
+ } else if (dataType == GPBDataTypeSFixed64) {
+ return GPBComputeSFixed64Size(fieldNum, value);
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ return 0;
+ }
+}
+
+static void WriteDictInt64Field(GPBCodedOutputStream *stream, int64_t value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeInt64) {
+ [stream writeInt64:fieldNum value:value];
+ } else if (dataType == GPBDataTypeSInt64) {
+ [stream writeSInt64:fieldNum value:value];
+ } else if (dataType == GPBDataTypeSFixed64) {
+ [stream writeSFixed64:fieldNum value:value];
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ }
+}
+
+static size_t ComputeDictUInt64FieldSize(uint64_t value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeUInt64) {
+ return GPBComputeUInt64Size(fieldNum, value);
+ } else if (dataType == GPBDataTypeFixed64) {
+ return GPBComputeFixed64Size(fieldNum, value);
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ return 0;
+ }
+}
+
+static void WriteDictUInt64Field(GPBCodedOutputStream *stream, uint64_t value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeUInt64) {
+ [stream writeUInt64:fieldNum value:value];
+ } else if (dataType == GPBDataTypeFixed64) {
+ [stream writeFixed64:fieldNum value:value];
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ }
+}
+
+static size_t ComputeDictBoolFieldSize(BOOL value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ return GPBComputeBoolSize(fieldNum, value);
+}
+
+static void WriteDictBoolField(GPBCodedOutputStream *stream, BOOL value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ [stream writeBool:fieldNum value:value];
+}
+
+static size_t ComputeDictEnumFieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ return GPBComputeEnumSize(fieldNum, value);
+}
+
+static void WriteDictEnumField(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ [stream writeEnum:fieldNum value:value];
+}
+
+static size_t ComputeDictFloatFieldSize(float value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ return GPBComputeFloatSize(fieldNum, value);
+}
+
+static void WriteDictFloatField(GPBCodedOutputStream *stream, float value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ [stream writeFloat:fieldNum value:value];
+}
+
+static size_t ComputeDictDoubleFieldSize(double value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ return GPBComputeDoubleSize(fieldNum, value);
+}
+
+static void WriteDictDoubleField(GPBCodedOutputStream *stream, double value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ [stream writeDouble:fieldNum value:value];
+}
+
+static size_t ComputeDictStringFieldSize(NSString *value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ return GPBComputeStringSize(fieldNum, value);
+}
+
+static void WriteDictStringField(GPBCodedOutputStream *stream, NSString *value, uint32_t fieldNum, GPBDataType dataType) {
+ NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType);
+ #pragma unused(dataType) // For when asserts are off in release.
+ [stream writeString:fieldNum value:value];
+}
+
+static size_t ComputeDictObjectFieldSize(id value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeMessage) {
+ return GPBComputeMessageSize(fieldNum, value);
+ } else if (dataType == GPBDataTypeString) {
+ return GPBComputeStringSize(fieldNum, value);
+ } else if (dataType == GPBDataTypeBytes) {
+ return GPBComputeBytesSize(fieldNum, value);
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ return 0;
+ }
+}
+
+static void WriteDictObjectField(GPBCodedOutputStream *stream, id value, uint32_t fieldNum, GPBDataType dataType) {
+ if (dataType == GPBDataTypeMessage) {
+ [stream writeMessage:fieldNum value:value];
+ } else if (dataType == GPBDataTypeString) {
+ [stream writeString:fieldNum value:value];
+ } else if (dataType == GPBDataTypeBytes) {
+ [stream writeBytes:fieldNum value:value];
+ } else {
+ NSCAssert(NO, @"Unexpected type %d", dataType);
+ }
+}
+
+//%PDDM-EXPAND-END SERIALIZE_SUPPORT_HELPERS()
+
+size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) {
+ GPBDataType mapValueType = GPBGetFieldDataType(field);
+ __block size_t result = 0;
+ [dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key);
+ msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * dict.count;
+ return result;
+}
+
+void GPBDictionaryWriteToStreamInternalHelper(GPBCodedOutputStream *outputStream,
+ NSDictionary *dict,
+ GPBFieldDescriptor *field) {
+ NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type");
+ GPBDataType mapValueType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key);
+ msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType);
+
+ // Write the size and fields.
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ [outputStream writeString:kMapKeyFieldNumber value:key];
+ WriteDictObjectField(outputStream, obj, kMapValueFieldNumber, mapValueType);
+ }];
+}
+
+BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) {
+ NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type");
+ NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeMessage, @"Unexpected value type");
+ #pragma unused(field) // For when asserts are off in release.
+ for (GPBMessage *msg in [dict objectEnumerator]) {
+ if (!msg.initialized) {
+ return NO;
+ }
+ }
+ return YES;
+}
+
+// Note: if the type is an object, it the retain pass back to the caller.
+static void ReadValue(GPBCodedInputStream *stream,
+ GPBGenericValue *valueToFill,
+ GPBDataType type,
+ GPBExtensionRegistry *registry,
+ GPBFieldDescriptor *field) {
+ switch (type) {
+ case GPBDataTypeBool:
+ valueToFill->valueBool = GPBCodedInputStreamReadBool(&stream->state_);
+ break;
+ case GPBDataTypeFixed32:
+ valueToFill->valueUInt32 = GPBCodedInputStreamReadFixed32(&stream->state_);
+ break;
+ case GPBDataTypeSFixed32:
+ valueToFill->valueInt32 = GPBCodedInputStreamReadSFixed32(&stream->state_);
+ break;
+ case GPBDataTypeFloat:
+ valueToFill->valueFloat = GPBCodedInputStreamReadFloat(&stream->state_);
+ break;
+ case GPBDataTypeFixed64:
+ valueToFill->valueUInt64 = GPBCodedInputStreamReadFixed64(&stream->state_);
+ break;
+ case GPBDataTypeSFixed64:
+ valueToFill->valueInt64 = GPBCodedInputStreamReadSFixed64(&stream->state_);
+ break;
+ case GPBDataTypeDouble:
+ valueToFill->valueDouble = GPBCodedInputStreamReadDouble(&stream->state_);
+ break;
+ case GPBDataTypeInt32:
+ valueToFill->valueInt32 = GPBCodedInputStreamReadInt32(&stream->state_);
+ break;
+ case GPBDataTypeInt64:
+ valueToFill->valueInt64 = GPBCodedInputStreamReadInt32(&stream->state_);
+ break;
+ case GPBDataTypeSInt32:
+ valueToFill->valueInt32 = GPBCodedInputStreamReadSInt32(&stream->state_);
+ break;
+ case GPBDataTypeSInt64:
+ valueToFill->valueInt64 = GPBCodedInputStreamReadSInt64(&stream->state_);
+ break;
+ case GPBDataTypeUInt32:
+ valueToFill->valueUInt32 = GPBCodedInputStreamReadUInt32(&stream->state_);
+ break;
+ case GPBDataTypeUInt64:
+ valueToFill->valueUInt64 = GPBCodedInputStreamReadUInt64(&stream->state_);
+ break;
+ case GPBDataTypeBytes:
+ [valueToFill->valueData release];
+ valueToFill->valueData = GPBCodedInputStreamReadRetainedBytes(&stream->state_);
+ break;
+ case GPBDataTypeString:
+ [valueToFill->valueString release];
+ valueToFill->valueString = GPBCodedInputStreamReadRetainedString(&stream->state_);
+ break;
+ case GPBDataTypeMessage: {
+ GPBMessage *message = [[field.msgClass alloc] init];
+ [stream readMessage:message extensionRegistry:registry];
+ [valueToFill->valueMessage release];
+ valueToFill->valueMessage = message;
+ break;
+ }
+ case GPBDataTypeGroup:
+ NSCAssert(NO, @"Can't happen");
+ break;
+ case GPBDataTypeEnum:
+ valueToFill->valueEnum = GPBCodedInputStreamReadEnum(&stream->state_);
+ break;
+ }
+}
+
+void GPBDictionaryReadEntry(id mapDictionary,
+ GPBCodedInputStream *stream,
+ GPBExtensionRegistry *registry,
+ GPBFieldDescriptor *field,
+ GPBMessage *parentMessage) {
+ GPBDataType keyDataType = field.mapKeyDataType;
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+
+ GPBGenericValue key;
+ GPBGenericValue value;
+ // Zero them (but pick up any enum default for proto2).
+ key.valueString = value.valueString = nil;
+ if (valueDataType == GPBDataTypeEnum) {
+ value = field.defaultValue;
+ }
+
+ GPBCodedInputStreamState *state = &stream->state_;
+ uint32_t keyTag =
+ GPBWireFormatMakeTag(kMapKeyFieldNumber, GPBWireFormatForType(keyDataType, NO));
+ uint32_t valueTag =
+ GPBWireFormatMakeTag(kMapValueFieldNumber, GPBWireFormatForType(valueDataType, NO));
+
+ BOOL hitError = NO;
+ while (YES) {
+ uint32_t tag = GPBCodedInputStreamReadTag(state);
+ if (tag == keyTag) {
+ ReadValue(stream, &key, keyDataType, registry, field);
+ } else if (tag == valueTag) {
+ ReadValue(stream, &value, valueDataType, registry, field);
+ } else if (tag == 0) {
+ // zero signals EOF / limit reached
+ break;
+ } else { // Unknown
+ if (![stream skipField:tag]){
+ hitError = YES;
+ break;
+ }
+ }
+ }
+
+ if (!hitError) {
+ // Handle the special defaults and/or missing key/value.
+ if ((keyDataType == GPBDataTypeString) && (key.valueString == nil)) {
+ key.valueString = [@"" retain];
+ }
+ if (GPBDataTypeIsObject(valueDataType) && value.valueString == nil) {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wswitch-enum"
+ switch (valueDataType) {
+ case GPBDataTypeString:
+ value.valueString = [@"" retain];
+ break;
+ case GPBDataTypeBytes:
+ value.valueData = [GPBEmptyNSData() retain];
+ break;
+#if defined(__clang_analyzer__)
+ case GPBDataTypeGroup:
+ // Maps can't really have Groups as the value type, but this case is needed
+ // so the analyzer won't report the posibility of send nil in for the value
+ // in the NSMutableDictionary case below.
+#endif
+ case GPBDataTypeMessage: {
+ value.valueMessage = [[field.msgClass alloc] init];
+ break;
+ }
+ default:
+ // Nothing
+ break;
+ }
+#pragma clang diagnostic pop
+ }
+
+ if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)) {
+#if GPB_STATIC_ANALYZER_ONLY(6020053, 7000181)
+ // Limited to Xcode 6.4 - 7.2, are known to fail here. The upper end can
+ // be raised as needed for new Xcodes.
+ //
+ // This is only needed on a "shallow" analyze; on a "deep" analyze, the
+ // existing code path gets this correct. In shallow, the analyzer decides
+ // GPBDataTypeIsObject(valueDataType) is both false and true on a single
+ // path through this function, allowing nil to be used for the
+ // setObject:forKey:.
+ if (value.valueString == nil) {
+ value.valueString = [@"" retain];
+ }
+#endif
+ // mapDictionary is an NSMutableDictionary
+ [(NSMutableDictionary *)mapDictionary setObject:value.valueString
+ forKey:key.valueString];
+ } else {
+ if (valueDataType == GPBDataTypeEnum) {
+ if (GPBHasPreservingUnknownEnumSemantics([parentMessage descriptor].file.syntax) ||
+ [field isValidEnumValue:value.valueEnum]) {
+ [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key];
+ } else {
+ NSData *data = [mapDictionary serializedDataForUnknownValue:value.valueEnum
+ forKey:&key
+ keyDataType:keyDataType];
+ [parentMessage addUnknownMapEntry:GPBFieldNumber(field) value:data];
+ }
+ } else {
+ [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key];
+ }
+ }
+ }
+
+ if (GPBDataTypeIsObject(keyDataType)) {
+ [key.valueString release];
+ }
+ if (GPBDataTypeIsObject(valueDataType)) {
+ [value.valueString release];
+ }
+}
+
+//
+// Macros for the common basic cases.
+//
+
+//%PDDM-DEFINE DICTIONARY_IMPL_FOR_POD_KEY(KEY_NAME, KEY_TYPE)
+//%DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, , POD)
+//%DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, Object, id)
+
+//%PDDM-DEFINE DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, KisP, KHELPER)
+//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt32, uint32_t, KHELPER)
+//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int32, int32_t, KHELPER)
+//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt64, uint64_t, KHELPER)
+//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int64, int64_t, KHELPER)
+//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Bool, BOOL, KHELPER)
+//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Float, float, KHELPER)
+//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Double, double, KHELPER)
+//%DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, Enum, int32_t, KHELPER)
+
+//%PDDM-DEFINE DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
+//%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD, VALUE_NAME, value)
+
+//%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, VALUE_NAME, VALUE_TYPE)
+//%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, , VALUE_NAME, VALUE_TYPE, POD, OBJECT, Object, object)
+
+//%PDDM-DEFINE DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR)
+//%#pragma mark - KEY_NAME -> VALUE_NAME
+//%
+//%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary {
+//% @package
+//% NSMutableDictionary *_dictionary;
+//%}
+//%
+//%+ (instancetype)dictionary {
+//% return [[[self alloc] initWith##VNAME##s:NULL forKeys:NULL count:0] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWith##VNAME##:(VALUE_TYPE)##VNAME_VAR
+//% ##VNAME$S## forKey:(KEY_TYPE##KisP$S##KisP)key {
+//% // Cast is needed so the compiler knows what class we are invoking initWith##VNAME##s:forKeys:count:
+//% // on to get the type correct.
+//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME##s:&##VNAME_VAR
+//% KEY_NAME$S VALUE_NAME$S ##VNAME$S## forKeys:&key
+//% KEY_NAME$S VALUE_NAME$S ##VNAME$S## count:1] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s
+//% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
+//% ##VNAME$S## count:(NSUInteger)count {
+//% // Cast is needed so the compiler knows what class we are invoking initWith##VNAME##s:forKeys:count:
+//% // on to get the type correct.
+//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME##s:##VNAME_VAR##s
+//% KEY_NAME$S VALUE_NAME$S forKeys:keys
+//% KEY_NAME$S VALUE_NAME$S count:count] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
+//% // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+//% // on to get the type correct.
+//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+//% return [[[self alloc] initWithCapacity:numItems] autorelease];
+//%}
+//%
+//%- (instancetype)init {
+//% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
+//%}
+//%
+//%- (instancetype)initWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s
+//% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
+//% ##VNAME$S## count:(NSUInteger)count {
+//% self = [super init];
+//% if (self) {
+//% _dictionary = [[NSMutableDictionary alloc] init];
+//% if (count && VNAME_VAR##s && keys) {
+//% for (NSUInteger i = 0; i < count; ++i) {
+//%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME_VAR##s[i], ______)##DICTIONARY_VALIDATE_KEY_##KHELPER(keys[i], ______) [_dictionary setObject:WRAPPED##VHELPER(VNAME_VAR##s[i]) forKey:WRAPPED##KHELPER(keys[i])];
+//% }
+//% }
+//% }
+//% return self;
+//%}
+//%
+//%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
+//% self = [self initWith##VNAME##s:NULL forKeys:NULL count:0];
+//% if (self) {
+//% if (dictionary) {
+//% [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+//% }
+//% }
+//% return self;
+//%}
+//%
+//%- (instancetype)initWithCapacity:(NSUInteger)numItems {
+//% #pragma unused(numItems)
+//% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
+//%}
+//%
+//%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, )
+//%
+//%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
+//%
+//%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, )
+//%
+//%@end
+//%
+
+//%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
+//%DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD)
+//%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER)
+//%#pragma mark - KEY_NAME -> VALUE_NAME
+//%
+//%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary {
+//% @package
+//% NSMutableDictionary *_dictionary;
+//% GPBEnumValidationFunc _validationFunc;
+//%}
+//%
+//%@synthesize validationFunc = _validationFunc;
+//%
+//%+ (instancetype)dictionary {
+//% return [[[self alloc] initWithValidationFunction:NULL
+//% rawValues:NULL
+//% forKeys:NULL
+//% count:0] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func {
+//% return [[[self alloc] initWithValidationFunction:func
+//% rawValues:NULL
+//% forKeys:NULL
+//% count:0] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+//% rawValue:(VALUE_TYPE)rawValue
+//% forKey:(KEY_TYPE##KisP$S##KisP)key {
+//% // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+//% // on to get the type correct.
+//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithValidationFunction:func
+//% KEY_NAME$S VALUE_NAME$S rawValues:&rawValue
+//% KEY_NAME$S VALUE_NAME$S forKeys:&key
+//% KEY_NAME$S VALUE_NAME$S count:1] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+//% rawValues:(const VALUE_TYPE [])rawValues
+//% forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
+//% count:(NSUInteger)count {
+//% // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+//% // on to get the type correct.
+//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithValidationFunction:func
+//% KEY_NAME$S VALUE_NAME$S rawValues:rawValues
+//% KEY_NAME$S VALUE_NAME$S forKeys:keys
+//% KEY_NAME$S VALUE_NAME$S count:count] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
+//% // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+//% // on to get the type correct.
+//% return [[(GPB##KEY_NAME##VALUE_NAME##Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+//% capacity:(NSUInteger)numItems {
+//% return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease];
+//%}
+//%
+//%- (instancetype)init {
+//% return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
+//%}
+//%
+//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
+//% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+//%}
+//%
+//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+//% rawValues:(const VALUE_TYPE [])rawValues
+//% forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
+//% count:(NSUInteger)count {
+//% self = [super init];
+//% if (self) {
+//% _dictionary = [[NSMutableDictionary alloc] init];
+//% _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
+//% if (count && rawValues && keys) {
+//% for (NSUInteger i = 0; i < count; ++i) {
+//%DICTIONARY_VALIDATE_KEY_##KHELPER(keys[i], ______) [_dictionary setObject:WRAPPED##VHELPER(rawValues[i]) forKey:WRAPPED##KHELPER(keys[i])];
+//% }
+//% }
+//% }
+//% return self;
+//%}
+//%
+//%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
+//% self = [self initWithValidationFunction:dictionary.validationFunc
+//% rawValues:NULL
+//% forKeys:NULL
+//% count:0];
+//% if (self) {
+//% if (dictionary) {
+//% [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+//% }
+//% }
+//% return self;
+//%}
+//%
+//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+//% capacity:(NSUInteger)numItems {
+//% #pragma unused(numItems)
+//% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+//%}
+//%
+//%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, value, Raw)
+//%
+//%- (BOOL)getEnum:(VALUE_TYPE *)value forKey:(KEY_TYPE##KisP$S##KisP)key {
+//% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
+//% if (wrapped && value) {
+//% VALUE_TYPE result = UNWRAP##VALUE_NAME(wrapped);
+//% if (!_validationFunc(result)) {
+//% result = kGPBUnrecognizedEnumeratorValue;
+//% }
+//% *value = result;
+//% }
+//% return (wrapped != NULL);
+//%}
+//%
+//%- (BOOL)getRawValue:(VALUE_TYPE *)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key {
+//% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
+//% if (wrapped && rawValue) {
+//% *rawValue = UNWRAP##VALUE_NAME(wrapped);
+//% }
+//% return (wrapped != NULL);
+//%}
+//%
+//%- (void)enumerateKeysAndEnumsUsingBlock:
+//% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE value, BOOL *stop))block {
+//% GPBEnumValidationFunc func = _validationFunc;
+//% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYPE)##aKey,
+//% ENUM_TYPE##VHELPER(VALUE_TYPE)##aValue,
+//% BOOL *stop) {
+//% VALUE_TYPE unwrapped = UNWRAP##VALUE_NAME(aValue);
+//% if (!func(unwrapped)) {
+//% unwrapped = kGPBUnrecognizedEnumeratorValue;
+//% }
+//% block(UNWRAP##KEY_NAME(aKey), unwrapped, stop);
+//% }];
+//%}
+//%
+//%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, Enum, value, Raw)
+//%
+//%- (void)setEnum:(VALUE_TYPE)value forKey:(KEY_TYPE##KisP$S##KisP)key {
+//%DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) if (!_validationFunc(value)) {
+//% [NSException raise:NSInvalidArgumentException
+//% format:@"GPB##KEY_NAME##VALUE_NAME##Dictionary: Attempt to set an unknown enum value (%d)",
+//% value];
+//% }
+//%
+//% [_dictionary setObject:WRAPPED##VHELPER(value) forKey:WRAPPED##KHELPER(key)];
+//% if (_autocreator) {
+//% GPBAutocreatedDictionaryModified(_autocreator, self);
+//% }
+//%}
+//%
+//%@end
+//%
+
+//%PDDM-DEFINE DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME)
+//%- (void)dealloc {
+//% NSAssert(!_autocreator,
+//% @"%@: Autocreator must be cleared before release, autocreator: %@",
+//% [self class], _autocreator);
+//% [_dictionary release];
+//% [super dealloc];
+//%}
+//%
+//%- (instancetype)copyWithZone:(NSZone *)zone {
+//% return [[GPB##KEY_NAME##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self];
+//%}
+//%
+//%- (BOOL)isEqual:(id)other {
+//% if (self == other) {
+//% return YES;
+//% }
+//% if (![other isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]) {
+//% return NO;
+//% }
+//% GPB##KEY_NAME##VALUE_NAME##Dictionary *otherDictionary = other;
+//% return [_dictionary isEqual:otherDictionary->_dictionary];
+//%}
+//%
+//%- (NSUInteger)hash {
+//% return _dictionary.count;
+//%}
+//%
+//%- (NSString *)description {
+//% return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+//%}
+//%
+//%- (NSUInteger)count {
+//% return _dictionary.count;
+//%}
+//%
+//%- (void)enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:
+//% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop))block {
+//% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYPE)##aKey,
+//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u,
+//% BOOL *stop) {
+//% block(UNWRAP##KEY_NAME(aKey), UNWRAP##VALUE_NAME(a##VNAME_VAR$u), stop);
+//% }];
+//%}
+//%
+//%EXTRA_METHODS_##VHELPER(KEY_NAME, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+//% NSUInteger count = _dictionary.count;
+//% if (count == 0) {
+//% return 0;
+//% }
+//%
+//% GPBDataType valueDataType = GPBGetFieldDataType(field);
+//% GPBDataType keyDataType = field.mapKeyDataType;
+//% __block size_t result = 0;
+//% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYPE)##aKey,
+//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u##,
+//% BOOL *stop) {
+//% #pragma unused(stop)
+//% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey), kMapKeyFieldNumber, keyDataType);
+//% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME_VAR$u), kMapValueFieldNumber, valueDataType);
+//% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+//% }];
+//% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+//% result += tagSize * count;
+//% return result;
+//%}
+//%
+//%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+//% asField:(GPBFieldDescriptor *)field {
+//% GPBDataType valueDataType = GPBGetFieldDataType(field);
+//% GPBDataType keyDataType = field.mapKeyDataType;
+//% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+//% [_dictionary enumerateKeysAndObjectsUsingBlock:^(ENUM_TYPE##KHELPER(KEY_TYPE)##aKey,
+//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u,
+//% BOOL *stop) {
+//% #pragma unused(stop)
+//% // Write the tag.
+//% [outputStream writeInt32NoTag:tag];
+//% // Write the size of the message.
+//% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey), kMapKeyFieldNumber, keyDataType);
+//% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME_VAR$u), kMapValueFieldNumber, valueDataType);
+//% [outputStream writeInt32NoTag:(int32_t)msgSize];
+//% // Write the fields.
+//% WriteDict##KEY_NAME##Field(outputStream, UNWRAP##KEY_NAME(aKey), kMapKeyFieldNumber, keyDataType);
+//% WriteDict##VALUE_NAME##Field(outputStream, UNWRAP##VALUE_NAME(a##VNAME_VAR$u), kMapValueFieldNumber, valueDataType);
+//% }];
+//%}
+//%
+//%SERIAL_DATA_FOR_ENTRY_##VHELPER(KEY_NAME, VALUE_NAME)- (void)setGPBGenericValue:(GPBGenericValue *)value
+//% forGPBGenericValueKey:(GPBGenericValue *)key {
+//% [_dictionary setObject:WRAPPED##VHELPER(value->##GPBVALUE_##VHELPER(VALUE_NAME)##) forKey:WRAPPED##KHELPER(key->value##KEY_NAME)];
+//%}
+//%
+//%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+//% [self enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:^(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop) {
+//% #pragma unused(stop)
+//% block(TEXT_FORMAT_OBJ##KEY_NAME(key), TEXT_FORMAT_OBJ##VALUE_NAME(VNAME_VAR));
+//% }];
+//%}
+//%PDDM-DEFINE DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME)
+//%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME, VNAME_VAR, ACCESSOR_NAME)
+//%PDDM-DEFINE DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_REMOVE, VNAME_VAR, ACCESSOR_NAME)
+//%- (void)add##ACCESSOR_NAME##EntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)otherDictionary {
+//% if (otherDictionary) {
+//% [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+//% if (_autocreator) {
+//% GPBAutocreatedDictionaryModified(_autocreator, self);
+//% }
+//% }
+//%}
+//%
+//%- (void)set##ACCESSOR_NAME##VNAME##:(VALUE_TYPE)VNAME_VAR forKey:(KEY_TYPE##KisP$S##KisP)key {
+//%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME_VAR, )##DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) [_dictionary setObject:WRAPPED##VHELPER(VNAME_VAR) forKey:WRAPPED##KHELPER(key)];
+//% if (_autocreator) {
+//% GPBAutocreatedDictionaryModified(_autocreator, self);
+//% }
+//%}
+//%
+//%- (void)remove##VNAME_REMOVE##ForKey:(KEY_TYPE##KisP$S##KisP)aKey {
+//% [_dictionary removeObjectForKey:WRAPPED##KHELPER(aKey)];
+//%}
+//%
+//%- (void)removeAll {
+//% [_dictionary removeAllObjects];
+//%}
+
+//
+// Custom Generation for Bool keys
+//
+
+//%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_POD_IMPL(VALUE_NAME, VALUE_TYPE)
+//%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, POD, VALUE_NAME, value)
+//%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(VALUE_NAME, VALUE_TYPE)
+//%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, OBJECT, Object, object)
+
+//%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, HELPER, VNAME, VNAME_VAR)
+//%#pragma mark - Bool -> VALUE_NAME
+//%
+//%@implementation GPBBool##VALUE_NAME##Dictionary {
+//% @package
+//% VALUE_TYPE _values[2];
+//%BOOL_DICT_HAS_STORAGE_##HELPER()}
+//%
+//%+ (instancetype)dictionary {
+//% return [[[self alloc] initWith##VNAME##s:NULL forKeys:NULL count:0] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWith##VNAME##:(VALUE_TYPE)VNAME_VAR
+//% ##VNAME$S## forKey:(BOOL)key {
+//% // Cast is needed so the compiler knows what class we are invoking initWith##VNAME##s:forKeys:count:
+//% // on to get the type correct.
+//% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME##s:&##VNAME_VAR
+//% VALUE_NAME$S ##VNAME$S## forKeys:&key
+//% VALUE_NAME$S ##VNAME$S## count:1] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s
+//% ##VNAME$S## forKeys:(const BOOL [])keys
+//% ##VNAME$S## count:(NSUInteger)count {
+//% // Cast is needed so the compiler knows what class we are invoking initWith##VNAME##s:forKeys:count:
+//% // on to get the type correct.
+//% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWith##VNAME##s:##VNAME_VAR##s
+//% VALUE_NAME$S ##VNAME$S## forKeys:keys
+//% VALUE_NAME$S ##VNAME$S## count:count] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary {
+//% // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+//% // on to get the type correct.
+//% return [[(GPBBool##VALUE_NAME##Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+//%}
+//%
+//%+ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+//% return [[[self alloc] initWithCapacity:numItems] autorelease];
+//%}
+//%
+//%- (instancetype)init {
+//% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
+//%}
+//%
+//%BOOL_DICT_INITS_##HELPER(VALUE_NAME, VALUE_TYPE)
+//%
+//%- (instancetype)initWithCapacity:(NSUInteger)numItems {
+//% #pragma unused(numItems)
+//% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
+//%}
+//%
+//%BOOL_DICT_DEALLOC##HELPER()
+//%
+//%- (instancetype)copyWithZone:(NSZone *)zone {
+//% return [[GPBBool##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self];
+//%}
+//%
+//%- (BOOL)isEqual:(id)other {
+//% if (self == other) {
+//% return YES;
+//% }
+//% if (![other isKindOfClass:[GPBBool##VALUE_NAME##Dictionary class]]) {
+//% return NO;
+//% }
+//% GPBBool##VALUE_NAME##Dictionary *otherDictionary = other;
+//% if ((BOOL_DICT_W_HAS##HELPER(0, ) != BOOL_DICT_W_HAS##HELPER(0, otherDictionary->)) ||
+//% (BOOL_DICT_W_HAS##HELPER(1, ) != BOOL_DICT_W_HAS##HELPER(1, otherDictionary->))) {
+//% return NO;
+//% }
+//% if ((BOOL_DICT_W_HAS##HELPER(0, ) && (NEQ_##HELPER(_values[0], otherDictionary->_values[0]))) ||
+//% (BOOL_DICT_W_HAS##HELPER(1, ) && (NEQ_##HELPER(_values[1], otherDictionary->_values[1])))) {
+//% return NO;
+//% }
+//% return YES;
+//%}
+//%
+//%- (NSUInteger)hash {
+//% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0);
+//%}
+//%
+//%- (NSString *)description {
+//% NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+//% if (BOOL_DICT_W_HAS##HELPER(0, )) {
+//% [result appendFormat:@"NO: STR_FORMAT_##HELPER(VALUE_NAME)", _values[0]];
+//% }
+//% if (BOOL_DICT_W_HAS##HELPER(1, )) {
+//% [result appendFormat:@"YES: STR_FORMAT_##HELPER(VALUE_NAME)", _values[1]];
+//% }
+//% [result appendString:@" }"];
+//% return result;
+//%}
+//%
+//%- (NSUInteger)count {
+//% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0);
+//%}
+//%
+//%BOOL_VALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE)
+//%
+//%BOOL_SET_GPBVALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE, VisP)
+//%
+//%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+//% if (BOOL_DICT_HAS##HELPER(0, )) {
+//% block(@"false", TEXT_FORMAT_OBJ##VALUE_NAME(_values[0]));
+//% }
+//% if (BOOL_DICT_W_HAS##HELPER(1, )) {
+//% block(@"true", TEXT_FORMAT_OBJ##VALUE_NAME(_values[1]));
+//% }
+//%}
+//%
+//%- (void)enumerateKeysAnd##VNAME##sUsingBlock:
+//% (void (^)(BOOL key, VALUE_TYPE VNAME_VAR, BOOL *stop))block {
+//% BOOL stop = NO;
+//% if (BOOL_DICT_HAS##HELPER(0, )) {
+//% block(NO, _values[0], &stop);
+//% }
+//% if (!stop && BOOL_DICT_W_HAS##HELPER(1, )) {
+//% block(YES, _values[1], &stop);
+//% }
+//%}
+//%
+//%BOOL_EXTRA_METHODS_##HELPER(Bool, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+//% GPBDataType valueDataType = GPBGetFieldDataType(field);
+//% NSUInteger count = 0;
+//% size_t result = 0;
+//% for (int i = 0; i < 2; ++i) {
+//% if (BOOL_DICT_HAS##HELPER(i, )) {
+//% ++count;
+//% size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+//% msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+//% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+//% }
+//% }
+//% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+//% result += tagSize * count;
+//% return result;
+//%}
+//%
+//%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+//% asField:(GPBFieldDescriptor *)field {
+//% GPBDataType valueDataType = GPBGetFieldDataType(field);
+//% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+//% for (int i = 0; i < 2; ++i) {
+//% if (BOOL_DICT_HAS##HELPER(i, )) {
+//% // Write the tag.
+//% [outputStream writeInt32NoTag:tag];
+//% // Write the size of the message.
+//% size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+//% msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+//% [outputStream writeInt32NoTag:(int32_t)msgSize];
+//% // Write the fields.
+//% WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+//% WriteDict##VALUE_NAME##Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+//% }
+//% }
+//%}
+//%
+//%BOOL_DICT_MUTATIONS_##HELPER(VALUE_NAME, VALUE_TYPE)
+//%
+//%@end
+//%
+
+
+//
+// Helpers for PODs
+//
+
+//%PDDM-DEFINE VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER)
+//%- (BOOL)get##VALUE_NAME##:(nullable VALUE_TYPE *)value forKey:(KEY_TYPE)key {
+//% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
+//% if (wrapped && value) {
+//% *value = UNWRAP##VALUE_NAME(wrapped);
+//% }
+//% return (wrapped != NULL);
+//%}
+//%PDDM-DEFINE WRAPPEDPOD(VALUE)
+//%@(VALUE)
+//%PDDM-DEFINE UNWRAPUInt32(VALUE)
+//%[VALUE unsignedIntValue]
+//%PDDM-DEFINE UNWRAPInt32(VALUE)
+//%[VALUE intValue]
+//%PDDM-DEFINE UNWRAPUInt64(VALUE)
+//%[VALUE unsignedLongLongValue]
+//%PDDM-DEFINE UNWRAPInt64(VALUE)
+//%[VALUE longLongValue]
+//%PDDM-DEFINE UNWRAPBool(VALUE)
+//%[VALUE boolValue]
+//%PDDM-DEFINE UNWRAPFloat(VALUE)
+//%[VALUE floatValue]
+//%PDDM-DEFINE UNWRAPDouble(VALUE)
+//%[VALUE doubleValue]
+//%PDDM-DEFINE UNWRAPEnum(VALUE)
+//%[VALUE intValue]
+//%PDDM-DEFINE TEXT_FORMAT_OBJUInt32(VALUE)
+//%[NSString stringWithFormat:@"%u", VALUE]
+//%PDDM-DEFINE TEXT_FORMAT_OBJInt32(VALUE)
+//%[NSString stringWithFormat:@"%d", VALUE]
+//%PDDM-DEFINE TEXT_FORMAT_OBJUInt64(VALUE)
+//%[NSString stringWithFormat:@"%llu", VALUE]
+//%PDDM-DEFINE TEXT_FORMAT_OBJInt64(VALUE)
+//%[NSString stringWithFormat:@"%lld", VALUE]
+//%PDDM-DEFINE TEXT_FORMAT_OBJBool(VALUE)
+//%(VALUE ? @"true" : @"false")
+//%PDDM-DEFINE TEXT_FORMAT_OBJFloat(VALUE)
+//%[NSString stringWithFormat:@"%.*g", FLT_DIG, VALUE]
+//%PDDM-DEFINE TEXT_FORMAT_OBJDouble(VALUE)
+//%[NSString stringWithFormat:@"%.*lg", DBL_DIG, VALUE]
+//%PDDM-DEFINE TEXT_FORMAT_OBJEnum(VALUE)
+//%@(VALUE)
+//%PDDM-DEFINE ENUM_TYPEPOD(TYPE)
+//%NSNumber *
+//%PDDM-DEFINE NEQ_POD(VAL1, VAL2)
+//%VAL1 != VAL2
+//%PDDM-DEFINE EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME)
+// Empty
+//%PDDM-DEFINE BOOL_EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME)
+// Empty
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD(KEY_NAME, VALUE_NAME)
+//%SERIAL_DATA_FOR_ENTRY_POD_##VALUE_NAME(KEY_NAME)
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt32(KEY_NAME)
+// Empty
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int32(KEY_NAME)
+// Empty
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt64(KEY_NAME)
+// Empty
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int64(KEY_NAME)
+// Empty
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Bool(KEY_NAME)
+// Empty
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Float(KEY_NAME)
+// Empty
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Double(KEY_NAME)
+// Empty
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Enum(KEY_NAME)
+//%- (NSData *)serializedDataForUnknownValue:(int32_t)value
+//% forKey:(GPBGenericValue *)key
+//% keyDataType:(GPBDataType)keyDataType {
+//% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(key->value##KEY_NAME, kMapKeyFieldNumber, keyDataType);
+//% msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
+//% NSMutableData *data = [NSMutableData dataWithLength:msgSize];
+//% GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
+//% WriteDict##KEY_NAME##Field(outputStream, key->value##KEY_NAME, kMapKeyFieldNumber, keyDataType);
+//% WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
+//% [outputStream release];
+//% return data;
+//%}
+//%
+//%PDDM-DEFINE GPBVALUE_POD(VALUE_NAME)
+//%value##VALUE_NAME
+//%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_POD(VALUE_NAME, EXTRA_INDENT)
+// Empty
+//%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_POD(KEY_NAME, EXTRA_INDENT)
+// Empty
+
+//%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_POD()
+//% BOOL _valueSet[2];
+//%
+//%PDDM-DEFINE BOOL_DICT_INITS_POD(VALUE_NAME, VALUE_TYPE)
+//%- (instancetype)initWith##VALUE_NAME##s:(const VALUE_TYPE [])values
+//% ##VALUE_NAME$S## forKeys:(const BOOL [])keys
+//% ##VALUE_NAME$S## count:(NSUInteger)count {
+//% self = [super init];
+//% if (self) {
+//% for (NSUInteger i = 0; i < count; ++i) {
+//% int idx = keys[i] ? 1 : 0;
+//% _values[idx] = values[i];
+//% _valueSet[idx] = YES;
+//% }
+//% }
+//% return self;
+//%}
+//%
+//%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary {
+//% self = [self initWith##VALUE_NAME##s:NULL forKeys:NULL count:0];
+//% if (self) {
+//% if (dictionary) {
+//% for (int i = 0; i < 2; ++i) {
+//% if (dictionary->_valueSet[i]) {
+//% _values[i] = dictionary->_values[i];
+//% _valueSet[i] = YES;
+//% }
+//% }
+//% }
+//% }
+//% return self;
+//%}
+//%PDDM-DEFINE BOOL_DICT_DEALLOCPOD()
+//%#if !defined(NS_BLOCK_ASSERTIONS)
+//%- (void)dealloc {
+//% NSAssert(!_autocreator,
+//% @"%@: Autocreator must be cleared before release, autocreator: %@",
+//% [self class], _autocreator);
+//% [super dealloc];
+//%}
+//%#endif // !defined(NS_BLOCK_ASSERTIONS)
+//%PDDM-DEFINE BOOL_DICT_W_HASPOD(IDX, REF)
+//%BOOL_DICT_HASPOD(IDX, REF)
+//%PDDM-DEFINE BOOL_DICT_HASPOD(IDX, REF)
+//%REF##_valueSet[IDX]
+//%PDDM-DEFINE BOOL_VALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE)
+//%- (BOOL)get##VALUE_NAME##:(VALUE_TYPE *)value forKey:(BOOL)key {
+//% int idx = (key ? 1 : 0);
+//% if (_valueSet[idx]) {
+//% if (value) {
+//% *value = _values[idx];
+//% }
+//% return YES;
+//% }
+//% return NO;
+//%}
+//%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE, VisP)
+//%- (void)setGPBGenericValue:(GPBGenericValue *)value
+//% forGPBGenericValueKey:(GPBGenericValue *)key {
+//% int idx = (key->valueBool ? 1 : 0);
+//% _values[idx] = value->value##VALUE_NAME;
+//% _valueSet[idx] = YES;
+//%}
+//%PDDM-DEFINE BOOL_DICT_MUTATIONS_POD(VALUE_NAME, VALUE_TYPE)
+//%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDictionary {
+//% if (otherDictionary) {
+//% for (int i = 0; i < 2; ++i) {
+//% if (otherDictionary->_valueSet[i]) {
+//% _valueSet[i] = YES;
+//% _values[i] = otherDictionary->_values[i];
+//% }
+//% }
+//% if (_autocreator) {
+//% GPBAutocreatedDictionaryModified(_autocreator, self);
+//% }
+//% }
+//%}
+//%
+//%- (void)set##VALUE_NAME:(VALUE_TYPE)value forKey:(BOOL)key {
+//% int idx = (key ? 1 : 0);
+//% _values[idx] = value;
+//% _valueSet[idx] = YES;
+//% if (_autocreator) {
+//% GPBAutocreatedDictionaryModified(_autocreator, self);
+//% }
+//%}
+//%
+//%- (void)remove##VALUE_NAME##ForKey:(BOOL)aKey {
+//% _valueSet[aKey ? 1 : 0] = NO;
+//%}
+//%
+//%- (void)removeAll {
+//% _valueSet[0] = NO;
+//% _valueSet[1] = NO;
+//%}
+//%PDDM-DEFINE STR_FORMAT_POD(VALUE_NAME)
+//%STR_FORMAT_##VALUE_NAME()
+//%PDDM-DEFINE STR_FORMAT_UInt32()
+//%%u
+//%PDDM-DEFINE STR_FORMAT_Int32()
+//%%d
+//%PDDM-DEFINE STR_FORMAT_UInt64()
+//%%llu
+//%PDDM-DEFINE STR_FORMAT_Int64()
+//%%lld
+//%PDDM-DEFINE STR_FORMAT_Bool()
+//%%d
+//%PDDM-DEFINE STR_FORMAT_Float()
+//%%f
+//%PDDM-DEFINE STR_FORMAT_Double()
+//%%lf
+
+//
+// Helpers for Objects
+//
+
+//%PDDM-DEFINE VALUE_FOR_KEY_OBJECT(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER)
+//%- (VALUE_TYPE)objectForKey:(KEY_TYPE)key {
+//% VALUE_TYPE result = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
+//% return result;
+//%}
+//%PDDM-DEFINE WRAPPEDOBJECT(VALUE)
+//%VALUE
+//%PDDM-DEFINE UNWRAPString(VALUE)
+//%VALUE
+//%PDDM-DEFINE UNWRAPObject(VALUE)
+//%VALUE
+//%PDDM-DEFINE TEXT_FORMAT_OBJString(VALUE)
+//%VALUE
+//%PDDM-DEFINE TEXT_FORMAT_OBJObject(VALUE)
+//%VALUE
+//%PDDM-DEFINE ENUM_TYPEOBJECT(TYPE)
+//%ENUM_TYPEOBJECT_##TYPE()
+//%PDDM-DEFINE ENUM_TYPEOBJECT_NSString()
+//%NSString *
+//%PDDM-DEFINE ENUM_TYPEOBJECT_id()
+//%id ##
+//%PDDM-DEFINE NEQ_OBJECT(VAL1, VAL2)
+//%![VAL1 isEqual:VAL2]
+//%PDDM-DEFINE EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME)
+//%- (BOOL)isInitialized {
+//% for (GPBMessage *msg in [_dictionary objectEnumerator]) {
+//% if (!msg.initialized) {
+//% return NO;
+//% }
+//% }
+//% return YES;
+//%}
+//%
+//%- (instancetype)deepCopyWithZone:(NSZone *)zone {
+//% GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
+//% [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey,
+//% GPBMessage *msg,
+//% BOOL *stop) {
+//% #pragma unused(stop)
+//% GPBMessage *copiedMsg = [msg copyWithZone:zone];
+//% [newDict->_dictionary setObject:copiedMsg forKey:aKey];
+//% [copiedMsg release];
+//% }];
+//% return newDict;
+//%}
+//%
+//%
+//%PDDM-DEFINE BOOL_EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME)
+//%- (BOOL)isInitialized {
+//% if (_values[0] && ![_values[0] isInitialized]) {
+//% return NO;
+//% }
+//% if (_values[1] && ![_values[1] isInitialized]) {
+//% return NO;
+//% }
+//% return YES;
+//%}
+//%
+//%- (instancetype)deepCopyWithZone:(NSZone *)zone {
+//% GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
+//% for (int i = 0; i < 2; ++i) {
+//% if (_values[i] != nil) {
+//% newDict->_values[i] = [_values[i] copyWithZone:zone];
+//% }
+//% }
+//% return newDict;
+//%}
+//%
+//%
+//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_OBJECT(KEY_NAME, VALUE_NAME)
+// Empty
+//%PDDM-DEFINE GPBVALUE_OBJECT(VALUE_NAME)
+//%valueString
+//%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_OBJECT(VALUE_NAME, EXTRA_INDENT)
+//%##EXTRA_INDENT$S## if (!##VALUE_NAME) {
+//%##EXTRA_INDENT$S## [NSException raise:NSInvalidArgumentException
+//%##EXTRA_INDENT$S## format:@"Attempting to add nil object to a Dictionary"];
+//%##EXTRA_INDENT$S## }
+//%
+//%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_OBJECT(KEY_NAME, EXTRA_INDENT)
+//%##EXTRA_INDENT$S## if (!##KEY_NAME) {
+//%##EXTRA_INDENT$S## [NSException raise:NSInvalidArgumentException
+//%##EXTRA_INDENT$S## format:@"Attempting to add nil key to a Dictionary"];
+//%##EXTRA_INDENT$S## }
+//%
+
+//%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_OBJECT()
+// Empty
+//%PDDM-DEFINE BOOL_DICT_INITS_OBJECT(VALUE_NAME, VALUE_TYPE)
+//%- (instancetype)initWithObjects:(const VALUE_TYPE [])objects
+//% forKeys:(const BOOL [])keys
+//% count:(NSUInteger)count {
+//% self = [super init];
+//% if (self) {
+//% for (NSUInteger i = 0; i < count; ++i) {
+//% if (!objects[i]) {
+//% [NSException raise:NSInvalidArgumentException
+//% format:@"Attempting to add nil object to a Dictionary"];
+//% }
+//% int idx = keys[i] ? 1 : 0;
+//% [_values[idx] release];
+//% _values[idx] = (VALUE_TYPE)[objects[i] retain];
+//% }
+//% }
+//% return self;
+//%}
+//%
+//%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary {
+//% self = [self initWithObjects:NULL forKeys:NULL count:0];
+//% if (self) {
+//% if (dictionary) {
+//% _values[0] = [dictionary->_values[0] retain];
+//% _values[1] = [dictionary->_values[1] retain];
+//% }
+//% }
+//% return self;
+//%}
+//%PDDM-DEFINE BOOL_DICT_DEALLOCOBJECT()
+//%- (void)dealloc {
+//% NSAssert(!_autocreator,
+//% @"%@: Autocreator must be cleared before release, autocreator: %@",
+//% [self class], _autocreator);
+//% [_values[0] release];
+//% [_values[1] release];
+//% [super dealloc];
+//%}
+//%PDDM-DEFINE BOOL_DICT_W_HASOBJECT(IDX, REF)
+//%(BOOL_DICT_HASOBJECT(IDX, REF))
+//%PDDM-DEFINE BOOL_DICT_HASOBJECT(IDX, REF)
+//%REF##_values[IDX] != nil
+//%PDDM-DEFINE BOOL_VALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE)
+//%- (VALUE_TYPE)objectForKey:(BOOL)key {
+//% return _values[key ? 1 : 0];
+//%}
+//%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE, VisP)
+//%- (void)setGPBGenericValue:(GPBGenericValue *)value
+//% forGPBGenericValueKey:(GPBGenericValue *)key {
+//% int idx = (key->valueBool ? 1 : 0);
+//% [_values[idx] release];
+//% _values[idx] = [value->valueString retain];
+//%}
+
+//%PDDM-DEFINE BOOL_DICT_MUTATIONS_OBJECT(VALUE_NAME, VALUE_TYPE)
+//%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDictionary {
+//% if (otherDictionary) {
+//% for (int i = 0; i < 2; ++i) {
+//% if (otherDictionary->_values[i] != nil) {
+//% [_values[i] release];
+//% _values[i] = [otherDictionary->_values[i] retain];
+//% }
+//% }
+//% if (_autocreator) {
+//% GPBAutocreatedDictionaryModified(_autocreator, self);
+//% }
+//% }
+//%}
+//%
+//%- (void)setObject:(VALUE_TYPE)object forKey:(BOOL)key {
+//% if (!object) {
+//% [NSException raise:NSInvalidArgumentException
+//% format:@"Attempting to add nil object to a Dictionary"];
+//% }
+//% int idx = (key ? 1 : 0);
+//% [_values[idx] release];
+//% _values[idx] = [object retain];
+//% if (_autocreator) {
+//% GPBAutocreatedDictionaryModified(_autocreator, self);
+//% }
+//%}
+//%
+//%- (void)removeObjectForKey:(BOOL)aKey {
+//% int idx = (aKey ? 1 : 0);
+//% [_values[idx] release];
+//% _values[idx] = nil;
+//%}
+//%
+//%- (void)removeAll {
+//% for (int i = 0; i < 2; ++i) {
+//% [_values[i] release];
+//% _values[i] = nil;
+//% }
+//%}
+//%PDDM-DEFINE STR_FORMAT_OBJECT(VALUE_NAME)
+//%%@
+
+
+//%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt32, uint32_t)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - UInt32 -> UInt32
+
+@implementation GPBUInt32UInt32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithUInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithUInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt32UInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt32s:(const uint32_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary {
+ self = [self initWithUInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32UInt32Dictionary class]]) {
+ return NO;
+ }
+ GPBUInt32UInt32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(uint32_t key, uint32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], [aValue unsignedIntValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt32sUsingBlock:^(uint32_t key, uint32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%u", value]);
+ }];
+}
+
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped unsignedIntValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt32UInt32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt32:(uint32_t)value forKey:(uint32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt32ForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt32 -> Int32
+
+@implementation GPBUInt32Int32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32s:(const int32_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32Int32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt32Int32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt32s:(const int32_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32Int32Dictionary *)dictionary {
+ self = [self initWithInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32Int32Dictionary class]]) {
+ return NO;
+ }
+ GPBUInt32Int32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(uint32_t key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt32sUsingBlock:^(uint32_t key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%d", value]);
+ }];
+}
+
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt32Int32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt32:(int32_t)value forKey:(uint32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt32ForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt32 -> UInt64
+
+@implementation GPBUInt32UInt64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithUInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithUInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt32UInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt64s:(const uint64_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary {
+ self = [self initWithUInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32UInt64Dictionary class]]) {
+ return NO;
+ }
+ GPBUInt32UInt64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(uint32_t key, uint64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], [aValue unsignedLongLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt64sUsingBlock:^(uint32_t key, uint64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%llu", value]);
+ }];
+}
+
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped unsignedLongLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt32UInt64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt64:(uint64_t)value forKey:(uint32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt64ForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt32 -> Int64
+
+@implementation GPBUInt32Int64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64s:(const int64_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32Int64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt32Int64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt64s:(const int64_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32Int64Dictionary *)dictionary {
+ self = [self initWithInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32Int64Dictionary class]]) {
+ return NO;
+ }
+ GPBUInt32Int64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(uint32_t key, int64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], [aValue longLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt64sUsingBlock:^(uint32_t key, int64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%lld", value]);
+ }];
+}
+
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped longLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt32Int64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt64:(int64_t)value forKey:(uint32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt64ForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt32 -> Bool
+
+@implementation GPBUInt32BoolDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32BoolDictionary*)[self alloc] initWithBools:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithBools:(const BOOL [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32BoolDictionary*)[self alloc] initWithBools:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32BoolDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt32BoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithBools:(const BOOL [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32BoolDictionary *)dictionary {
+ self = [self initWithBools:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32BoolDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32BoolDictionary class]]) {
+ return NO;
+ }
+ GPBUInt32BoolDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(uint32_t key, BOOL value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], [aValue boolValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndBoolsUsingBlock:^(uint32_t key, BOOL value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], (value ? @"true" : @"false"));
+ }];
+}
+
+- (BOOL)getBool:(nullable BOOL *)value forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped boolValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt32BoolDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setBool:(BOOL)value forKey:(uint32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeBoolForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt32 -> Float
+
+@implementation GPBUInt32FloatDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32FloatDictionary*)[self alloc] initWithFloats:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithFloats:(const float [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32FloatDictionary*)[self alloc] initWithFloats:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32FloatDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt32FloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithFloats:(const float [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32FloatDictionary *)dictionary {
+ self = [self initWithFloats:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32FloatDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32FloatDictionary class]]) {
+ return NO;
+ }
+ GPBUInt32FloatDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(uint32_t key, float value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], [aValue floatValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndFloatsUsingBlock:^(uint32_t key, float value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
+ }];
+}
+
+- (BOOL)getFloat:(nullable float *)value forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped floatValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt32FloatDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setFloat:(float)value forKey:(uint32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeFloatForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt32 -> Double
+
+@implementation GPBUInt32DoubleDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDoubles:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithDoubles:(const double [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDoubles:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32DoubleDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt32DoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithDoubles:(const double [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32DoubleDictionary *)dictionary {
+ self = [self initWithDoubles:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32DoubleDictionary class]]) {
+ return NO;
+ }
+ GPBUInt32DoubleDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(uint32_t key, double value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], [aValue doubleValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndDoublesUsingBlock:^(uint32_t key, double value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
+ }];
+}
+
+- (BOOL)getDouble:(nullable double *)value forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped doubleValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt32DoubleDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setDouble:(double)value forKey:(uint32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeDoubleForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt32 -> Enum
+
+@implementation GPBUInt32EnumDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+ GPBEnumValidationFunc _validationFunc;
+}
+
+@synthesize validationFunc = _validationFunc;
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithValidationFunction:NULL
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [[[self alloc] initWithValidationFunction:func
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32EnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:&rawValue
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32EnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:rawValues
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32EnumDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32EnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
+ if (count && rawValues && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32EnumDictionary *)dictionary {
+ self = [self initWithValidationFunction:dictionary.validationFunc
+ rawValues:NULL
+ forKeys:NULL
+ count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32EnumDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32EnumDictionary class]]) {
+ return NO;
+ }
+ GPBUInt32EnumDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(uint32_t key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType {
+ size_t msgSize = ComputeDictUInt32FieldSize(key->valueUInt32, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
+ NSMutableData *data = [NSMutableData dataWithLength:msgSize];
+ GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
+ WriteDictUInt32Field(outputStream, key->valueUInt32, kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
+ [outputStream release];
+ return data;
+}
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndRawValuesUsingBlock:^(uint32_t key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], @(value));
+ }];
+}
+
+- (BOOL)getEnum:(int32_t *)value forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ int32_t result = [wrapped intValue];
+ if (!_validationFunc(result)) {
+ result = kGPBUnrecognizedEnumeratorValue;
+ }
+ *value = result;
+ }
+ return (wrapped != NULL);
+}
+
+- (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && rawValue) {
+ *rawValue = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(uint32_t key, int32_t value, BOOL *stop))block {
+ GPBEnumValidationFunc func = _validationFunc;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ int32_t unwrapped = [aValue intValue];
+ if (!func(unwrapped)) {
+ unwrapped = kGPBUnrecognizedEnumeratorValue;
+ }
+ block([aKey unsignedIntValue], unwrapped, stop);
+ }];
+}
+
+- (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setRawValue:(int32_t)value forKey:(uint32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeEnumForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+- (void)setEnum:(int32_t)value forKey:(uint32_t)key {
+ if (!_validationFunc(value)) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"GPBUInt32EnumDictionary: Attempt to set an unknown enum value (%d)",
+ value];
+ }
+
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+@end
+
+#pragma mark - UInt32 -> Object
+
+@implementation GPBUInt32ObjectDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithObjects:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithObject:(id)object
+ forKey:(uint32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32ObjectDictionary*)[self alloc] initWithObjects:&object
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithObjects:(const id [])objects
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt32ObjectDictionary*)[self alloc] initWithObjects:objects
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt32ObjectDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt32ObjectDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithObjects:(const id [])objects
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && objects && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!objects[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ [_dictionary setObject:objects[i] forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt32ObjectDictionary *)dictionary {
+ self = [self initWithObjects:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt32ObjectDictionary class]]) {
+ return NO;
+ }
+ GPBUInt32ObjectDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(uint32_t key, id object, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ block([aKey unsignedIntValue], aObject, stop);
+ }];
+}
+
+- (BOOL)isInitialized {
+ for (GPBMessage *msg in [_dictionary objectEnumerator]) {
+ if (!msg.initialized) {
+ return NO;
+ }
+ }
+ return YES;
+}
+
+- (instancetype)deepCopyWithZone:(NSZone *)zone {
+ GPBUInt32ObjectDictionary *newDict =
+ [[GPBUInt32ObjectDictionary alloc] init];
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey,
+ GPBMessage *msg,
+ BOOL *stop) {
+ #pragma unused(stop)
+ GPBMessage *copiedMsg = [msg copyWithZone:zone];
+ [newDict->_dictionary setObject:copiedMsg forKey:aKey];
+ [copiedMsg release];
+ }];
+ return newDict;
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt32Field(outputStream, [aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictObjectField(outputStream, aObject, kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:value->valueString forKey:@(key->valueUInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndObjectsUsingBlock:^(uint32_t key, id object, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%u", key], object);
+ }];
+}
+
+- (id)objectForKey:(uint32_t)key {
+ id result = [_dictionary objectForKey:@(key)];
+ return result;
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt32ObjectDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setObject:(id)object forKey:(uint32_t)key {
+ if (!object) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ [_dictionary setObject:object forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeObjectForKey:(uint32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int32, int32_t)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Int32 -> UInt32
+
+@implementation GPBInt32UInt32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithUInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithUInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32UInt32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt32UInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt32s:(const uint32_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary {
+ self = [self initWithUInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32UInt32Dictionary class]]) {
+ return NO;
+ }
+ GPBInt32UInt32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(int32_t key, uint32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey intValue], [aValue unsignedIntValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt32sUsingBlock:^(int32_t key, uint32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%u", value]);
+ }];
+}
+
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped unsignedIntValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt32:(uint32_t)value forKey:(int32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt32ForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int32 -> Int32
+
+@implementation GPBInt32Int32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32Int32Dictionary*)[self alloc] initWithInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32s:(const int32_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32Int32Dictionary*)[self alloc] initWithInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32Int32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt32Int32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt32s:(const int32_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary {
+ self = [self initWithInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32Int32Dictionary class]]) {
+ return NO;
+ }
+ GPBInt32Int32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(int32_t key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey intValue], [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt32sUsingBlock:^(int32_t key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%d", value]);
+ }];
+}
+
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt32:(int32_t)value forKey:(int32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt32ForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int32 -> UInt64
+
+@implementation GPBInt32UInt64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithUInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithUInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32UInt64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt32UInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt64s:(const uint64_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary {
+ self = [self initWithUInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32UInt64Dictionary class]]) {
+ return NO;
+ }
+ GPBInt32UInt64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(int32_t key, uint64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey intValue], [aValue unsignedLongLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt64sUsingBlock:^(int32_t key, uint64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%llu", value]);
+ }];
+}
+
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped unsignedLongLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt64:(uint64_t)value forKey:(int32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt64ForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int32 -> Int64
+
+@implementation GPBInt32Int64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32Int64Dictionary*)[self alloc] initWithInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64s:(const int64_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32Int64Dictionary*)[self alloc] initWithInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32Int64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt32Int64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt64s:(const int64_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary {
+ self = [self initWithInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32Int64Dictionary class]]) {
+ return NO;
+ }
+ GPBInt32Int64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(int32_t key, int64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey intValue], [aValue longLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt64sUsingBlock:^(int32_t key, int64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%lld", value]);
+ }];
+}
+
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped longLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt64:(int64_t)value forKey:(int32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt64ForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int32 -> Bool
+
+@implementation GPBInt32BoolDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32BoolDictionary*)[self alloc] initWithBools:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithBools:(const BOOL [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32BoolDictionary*)[self alloc] initWithBools:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32BoolDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt32BoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithBools:(const BOOL [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary {
+ self = [self initWithBools:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32BoolDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32BoolDictionary class]]) {
+ return NO;
+ }
+ GPBInt32BoolDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(int32_t key, BOOL value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey intValue], [aValue boolValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndBoolsUsingBlock:^(int32_t key, BOOL value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], (value ? @"true" : @"false"));
+ }];
+}
+
+- (BOOL)getBool:(nullable BOOL *)value forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped boolValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setBool:(BOOL)value forKey:(int32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeBoolForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int32 -> Float
+
+@implementation GPBInt32FloatDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32FloatDictionary*)[self alloc] initWithFloats:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithFloats:(const float [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32FloatDictionary*)[self alloc] initWithFloats:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32FloatDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt32FloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithFloats:(const float [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary {
+ self = [self initWithFloats:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32FloatDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32FloatDictionary class]]) {
+ return NO;
+ }
+ GPBInt32FloatDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(int32_t key, float value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey intValue], [aValue floatValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndFloatsUsingBlock:^(int32_t key, float value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
+ }];
+}
+
+- (BOOL)getFloat:(nullable float *)value forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped floatValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setFloat:(float)value forKey:(int32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeFloatForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int32 -> Double
+
+@implementation GPBInt32DoubleDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDoubles:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithDoubles:(const double [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDoubles:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32DoubleDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt32DoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithDoubles:(const double [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary {
+ self = [self initWithDoubles:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32DoubleDictionary class]]) {
+ return NO;
+ }
+ GPBInt32DoubleDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(int32_t key, double value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey intValue], [aValue doubleValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndDoublesUsingBlock:^(int32_t key, double value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
+ }];
+}
+
+- (BOOL)getDouble:(nullable double *)value forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped doubleValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setDouble:(double)value forKey:(int32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeDoubleForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int32 -> Enum
+
+@implementation GPBInt32EnumDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+ GPBEnumValidationFunc _validationFunc;
+}
+
+@synthesize validationFunc = _validationFunc;
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithValidationFunction:NULL
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [[[self alloc] initWithValidationFunction:func
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32EnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:&rawValue
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32EnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:rawValues
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32EnumDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32EnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
+ if (count && rawValues && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32EnumDictionary *)dictionary {
+ self = [self initWithValidationFunction:dictionary.validationFunc
+ rawValues:NULL
+ forKeys:NULL
+ count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32EnumDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32EnumDictionary class]]) {
+ return NO;
+ }
+ GPBInt32EnumDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(int32_t key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey intValue], [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType {
+ size_t msgSize = ComputeDictInt32FieldSize(key->valueInt32, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
+ NSMutableData *data = [NSMutableData dataWithLength:msgSize];
+ GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
+ WriteDictInt32Field(outputStream, key->valueInt32, kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
+ [outputStream release];
+ return data;
+}
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndRawValuesUsingBlock:^(int32_t key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], @(value));
+ }];
+}
+
+- (BOOL)getEnum:(int32_t *)value forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ int32_t result = [wrapped intValue];
+ if (!_validationFunc(result)) {
+ result = kGPBUnrecognizedEnumeratorValue;
+ }
+ *value = result;
+ }
+ return (wrapped != NULL);
+}
+
+- (BOOL)getRawValue:(int32_t *)rawValue forKey:(int32_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && rawValue) {
+ *rawValue = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(int32_t key, int32_t value, BOOL *stop))block {
+ GPBEnumValidationFunc func = _validationFunc;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ int32_t unwrapped = [aValue intValue];
+ if (!func(unwrapped)) {
+ unwrapped = kGPBUnrecognizedEnumeratorValue;
+ }
+ block([aKey intValue], unwrapped, stop);
+ }];
+}
+
+- (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setRawValue:(int32_t)value forKey:(int32_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeEnumForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+- (void)setEnum:(int32_t)value forKey:(int32_t)key {
+ if (!_validationFunc(value)) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"GPBInt32EnumDictionary: Attempt to set an unknown enum value (%d)",
+ value];
+ }
+
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+@end
+
+#pragma mark - Int32 -> Object
+
+@implementation GPBInt32ObjectDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithObjects:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithObject:(id)object
+ forKey:(int32_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32ObjectDictionary*)[self alloc] initWithObjects:&object
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithObjects:(const id [])objects
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt32ObjectDictionary*)[self alloc] initWithObjects:objects
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt32ObjectDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt32ObjectDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithObjects:(const id [])objects
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && objects && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!objects[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ [_dictionary setObject:objects[i] forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt32ObjectDictionary *)dictionary {
+ self = [self initWithObjects:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt32ObjectDictionary class]]) {
+ return NO;
+ }
+ GPBInt32ObjectDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(int32_t key, id object, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ block([aKey intValue], aObject, stop);
+ }];
+}
+
+- (BOOL)isInitialized {
+ for (GPBMessage *msg in [_dictionary objectEnumerator]) {
+ if (!msg.initialized) {
+ return NO;
+ }
+ }
+ return YES;
+}
+
+- (instancetype)deepCopyWithZone:(NSZone *)zone {
+ GPBInt32ObjectDictionary *newDict =
+ [[GPBInt32ObjectDictionary alloc] init];
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey,
+ GPBMessage *msg,
+ BOOL *stop) {
+ #pragma unused(stop)
+ GPBMessage *copiedMsg = [msg copyWithZone:zone];
+ [newDict->_dictionary setObject:copiedMsg forKey:aKey];
+ [copiedMsg release];
+ }];
+ return newDict;
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt32Field(outputStream, [aKey intValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictObjectField(outputStream, aObject, kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:value->valueString forKey:@(key->valueInt32)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndObjectsUsingBlock:^(int32_t key, id object, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%d", key], object);
+ }];
+}
+
+- (id)objectForKey:(int32_t)key {
+ id result = [_dictionary objectForKey:@(key)];
+ return result;
+}
+
+- (void)addEntriesFromDictionary:(GPBInt32ObjectDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setObject:(id)object forKey:(int32_t)key {
+ if (!object) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ [_dictionary setObject:object forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeObjectForKey:(int32_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt64, uint64_t)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - UInt64 -> UInt32
+
+@implementation GPBUInt64UInt32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithUInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithUInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt64UInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt32s:(const uint32_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary {
+ self = [self initWithUInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64UInt32Dictionary class]]) {
+ return NO;
+ }
+ GPBUInt64UInt32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(uint64_t key, uint32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], [aValue unsignedIntValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt32sUsingBlock:^(uint64_t key, uint32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%u", value]);
+ }];
+}
+
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped unsignedIntValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt32:(uint32_t)value forKey:(uint64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt32ForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt64 -> Int32
+
+@implementation GPBUInt64Int32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32s:(const int32_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64Int32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt64Int32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt32s:(const int32_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary {
+ self = [self initWithInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64Int32Dictionary class]]) {
+ return NO;
+ }
+ GPBUInt64Int32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(uint64_t key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt32sUsingBlock:^(uint64_t key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%d", value]);
+ }];
+}
+
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt32:(int32_t)value forKey:(uint64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt32ForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt64 -> UInt64
+
+@implementation GPBUInt64UInt64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithUInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithUInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt64UInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt64s:(const uint64_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary {
+ self = [self initWithUInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64UInt64Dictionary class]]) {
+ return NO;
+ }
+ GPBUInt64UInt64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(uint64_t key, uint64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], [aValue unsignedLongLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt64sUsingBlock:^(uint64_t key, uint64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%llu", value]);
+ }];
+}
+
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped unsignedLongLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt64:(uint64_t)value forKey:(uint64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt64ForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt64 -> Int64
+
+@implementation GPBUInt64Int64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64s:(const int64_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64Int64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt64Int64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt64s:(const int64_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary {
+ self = [self initWithInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64Int64Dictionary class]]) {
+ return NO;
+ }
+ GPBUInt64Int64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(uint64_t key, int64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], [aValue longLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt64sUsingBlock:^(uint64_t key, int64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%lld", value]);
+ }];
+}
+
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped longLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt64:(int64_t)value forKey:(uint64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt64ForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt64 -> Bool
+
+@implementation GPBUInt64BoolDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64BoolDictionary*)[self alloc] initWithBools:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithBools:(const BOOL [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64BoolDictionary*)[self alloc] initWithBools:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64BoolDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt64BoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithBools:(const BOOL [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary {
+ self = [self initWithBools:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64BoolDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64BoolDictionary class]]) {
+ return NO;
+ }
+ GPBUInt64BoolDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(uint64_t key, BOOL value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], [aValue boolValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndBoolsUsingBlock:^(uint64_t key, BOOL value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], (value ? @"true" : @"false"));
+ }];
+}
+
+- (BOOL)getBool:(nullable BOOL *)value forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped boolValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setBool:(BOOL)value forKey:(uint64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeBoolForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt64 -> Float
+
+@implementation GPBUInt64FloatDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64FloatDictionary*)[self alloc] initWithFloats:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithFloats:(const float [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64FloatDictionary*)[self alloc] initWithFloats:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64FloatDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt64FloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithFloats:(const float [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary {
+ self = [self initWithFloats:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64FloatDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64FloatDictionary class]]) {
+ return NO;
+ }
+ GPBUInt64FloatDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(uint64_t key, float value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], [aValue floatValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndFloatsUsingBlock:^(uint64_t key, float value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
+ }];
+}
+
+- (BOOL)getFloat:(nullable float *)value forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped floatValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setFloat:(float)value forKey:(uint64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeFloatForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt64 -> Double
+
+@implementation GPBUInt64DoubleDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDoubles:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithDoubles:(const double [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDoubles:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64DoubleDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt64DoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithDoubles:(const double [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary {
+ self = [self initWithDoubles:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64DoubleDictionary class]]) {
+ return NO;
+ }
+ GPBUInt64DoubleDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(uint64_t key, double value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], [aValue doubleValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndDoublesUsingBlock:^(uint64_t key, double value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
+ }];
+}
+
+- (BOOL)getDouble:(nullable double *)value forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped doubleValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setDouble:(double)value forKey:(uint64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeDoubleForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - UInt64 -> Enum
+
+@implementation GPBUInt64EnumDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+ GPBEnumValidationFunc _validationFunc;
+}
+
+@synthesize validationFunc = _validationFunc;
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithValidationFunction:NULL
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [[[self alloc] initWithValidationFunction:func
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64EnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:&rawValue
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64EnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:rawValues
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64EnumDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64EnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
+ if (count && rawValues && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64EnumDictionary *)dictionary {
+ self = [self initWithValidationFunction:dictionary.validationFunc
+ rawValues:NULL
+ forKeys:NULL
+ count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64EnumDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64EnumDictionary class]]) {
+ return NO;
+ }
+ GPBUInt64EnumDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(uint64_t key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType {
+ size_t msgSize = ComputeDictUInt64FieldSize(key->valueUInt64, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
+ NSMutableData *data = [NSMutableData dataWithLength:msgSize];
+ GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
+ WriteDictUInt64Field(outputStream, key->valueUInt64, kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
+ [outputStream release];
+ return data;
+}
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndRawValuesUsingBlock:^(uint64_t key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], @(value));
+ }];
+}
+
+- (BOOL)getEnum:(int32_t *)value forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ int32_t result = [wrapped intValue];
+ if (!_validationFunc(result)) {
+ result = kGPBUnrecognizedEnumeratorValue;
+ }
+ *value = result;
+ }
+ return (wrapped != NULL);
+}
+
+- (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && rawValue) {
+ *rawValue = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(uint64_t key, int32_t value, BOOL *stop))block {
+ GPBEnumValidationFunc func = _validationFunc;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ int32_t unwrapped = [aValue intValue];
+ if (!func(unwrapped)) {
+ unwrapped = kGPBUnrecognizedEnumeratorValue;
+ }
+ block([aKey unsignedLongLongValue], unwrapped, stop);
+ }];
+}
+
+- (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setRawValue:(int32_t)value forKey:(uint64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeEnumForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+- (void)setEnum:(int32_t)value forKey:(uint64_t)key {
+ if (!_validationFunc(value)) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"GPBUInt64EnumDictionary: Attempt to set an unknown enum value (%d)",
+ value];
+ }
+
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+@end
+
+#pragma mark - UInt64 -> Object
+
+@implementation GPBUInt64ObjectDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithObjects:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithObject:(id)object
+ forKey:(uint64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64ObjectDictionary*)[self alloc] initWithObjects:&object
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithObjects:(const id [])objects
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBUInt64ObjectDictionary*)[self alloc] initWithObjects:objects
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBUInt64ObjectDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBUInt64ObjectDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithObjects:(const id [])objects
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && objects && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!objects[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ [_dictionary setObject:objects[i] forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBUInt64ObjectDictionary *)dictionary {
+ self = [self initWithObjects:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBUInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBUInt64ObjectDictionary class]]) {
+ return NO;
+ }
+ GPBUInt64ObjectDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(uint64_t key, id object, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ block([aKey unsignedLongLongValue], aObject, stop);
+ }];
+}
+
+- (BOOL)isInitialized {
+ for (GPBMessage *msg in [_dictionary objectEnumerator]) {
+ if (!msg.initialized) {
+ return NO;
+ }
+ }
+ return YES;
+}
+
+- (instancetype)deepCopyWithZone:(NSZone *)zone {
+ GPBUInt64ObjectDictionary *newDict =
+ [[GPBUInt64ObjectDictionary alloc] init];
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey,
+ GPBMessage *msg,
+ BOOL *stop) {
+ #pragma unused(stop)
+ GPBMessage *copiedMsg = [msg copyWithZone:zone];
+ [newDict->_dictionary setObject:copiedMsg forKey:aKey];
+ [copiedMsg release];
+ }];
+ return newDict;
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictUInt64Field(outputStream, [aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictObjectField(outputStream, aObject, kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:value->valueString forKey:@(key->valueUInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndObjectsUsingBlock:^(uint64_t key, id object, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%llu", key], object);
+ }];
+}
+
+- (id)objectForKey:(uint64_t)key {
+ id result = [_dictionary objectForKey:@(key)];
+ return result;
+}
+
+- (void)addEntriesFromDictionary:(GPBUInt64ObjectDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setObject:(id)object forKey:(uint64_t)key {
+ if (!object) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ [_dictionary setObject:object forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeObjectForKey:(uint64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int64, int64_t)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Int64 -> UInt32
+
+@implementation GPBInt64UInt32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithUInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithUInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64UInt32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt64UInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt32s:(const uint32_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary {
+ self = [self initWithUInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64UInt32Dictionary class]]) {
+ return NO;
+ }
+ GPBInt64UInt32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(int64_t key, uint32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey longLongValue], [aValue unsignedIntValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt32sUsingBlock:^(int64_t key, uint32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%u", value]);
+ }];
+}
+
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped unsignedIntValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt32:(uint32_t)value forKey:(int64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt32ForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int64 -> Int32
+
+@implementation GPBInt64Int32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64Int32Dictionary*)[self alloc] initWithInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32s:(const int32_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64Int32Dictionary*)[self alloc] initWithInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64Int32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt64Int32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt32s:(const int32_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary {
+ self = [self initWithInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64Int32Dictionary class]]) {
+ return NO;
+ }
+ GPBInt64Int32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(int64_t key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey longLongValue], [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt32sUsingBlock:^(int64_t key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%d", value]);
+ }];
+}
+
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt32:(int32_t)value forKey:(int64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt32ForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int64 -> UInt64
+
+@implementation GPBInt64UInt64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithUInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithUInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64UInt64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt64UInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt64s:(const uint64_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary {
+ self = [self initWithUInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64UInt64Dictionary class]]) {
+ return NO;
+ }
+ GPBInt64UInt64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(int64_t key, uint64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey longLongValue], [aValue unsignedLongLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt64sUsingBlock:^(int64_t key, uint64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%llu", value]);
+ }];
+}
+
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped unsignedLongLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt64:(uint64_t)value forKey:(int64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt64ForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int64 -> Int64
+
+@implementation GPBInt64Int64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64Int64Dictionary*)[self alloc] initWithInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64s:(const int64_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64Int64Dictionary*)[self alloc] initWithInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64Int64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt64Int64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt64s:(const int64_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary {
+ self = [self initWithInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64Int64Dictionary class]]) {
+ return NO;
+ }
+ GPBInt64Int64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(int64_t key, int64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey longLongValue], [aValue longLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt64sUsingBlock:^(int64_t key, int64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%lld", value]);
+ }];
+}
+
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped longLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt64:(int64_t)value forKey:(int64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt64ForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int64 -> Bool
+
+@implementation GPBInt64BoolDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64BoolDictionary*)[self alloc] initWithBools:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithBools:(const BOOL [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64BoolDictionary*)[self alloc] initWithBools:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64BoolDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt64BoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithBools:(const BOOL [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary {
+ self = [self initWithBools:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64BoolDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64BoolDictionary class]]) {
+ return NO;
+ }
+ GPBInt64BoolDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(int64_t key, BOOL value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey longLongValue], [aValue boolValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndBoolsUsingBlock:^(int64_t key, BOOL value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], (value ? @"true" : @"false"));
+ }];
+}
+
+- (BOOL)getBool:(nullable BOOL *)value forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped boolValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setBool:(BOOL)value forKey:(int64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeBoolForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int64 -> Float
+
+@implementation GPBInt64FloatDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64FloatDictionary*)[self alloc] initWithFloats:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithFloats:(const float [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64FloatDictionary*)[self alloc] initWithFloats:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64FloatDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt64FloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithFloats:(const float [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary {
+ self = [self initWithFloats:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64FloatDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64FloatDictionary class]]) {
+ return NO;
+ }
+ GPBInt64FloatDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(int64_t key, float value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey longLongValue], [aValue floatValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndFloatsUsingBlock:^(int64_t key, float value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
+ }];
+}
+
+- (BOOL)getFloat:(nullable float *)value forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped floatValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setFloat:(float)value forKey:(int64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeFloatForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int64 -> Double
+
+@implementation GPBInt64DoubleDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDoubles:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithDoubles:(const double [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDoubles:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64DoubleDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt64DoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithDoubles:(const double [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary {
+ self = [self initWithDoubles:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64DoubleDictionary class]]) {
+ return NO;
+ }
+ GPBInt64DoubleDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(int64_t key, double value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey longLongValue], [aValue doubleValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndDoublesUsingBlock:^(int64_t key, double value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
+ }];
+}
+
+- (BOOL)getDouble:(nullable double *)value forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ *value = [wrapped doubleValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setDouble:(double)value forKey:(int64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeDoubleForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - Int64 -> Enum
+
+@implementation GPBInt64EnumDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+ GPBEnumValidationFunc _validationFunc;
+}
+
+@synthesize validationFunc = _validationFunc;
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithValidationFunction:NULL
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [[[self alloc] initWithValidationFunction:func
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64EnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:&rawValue
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64EnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:rawValues
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64EnumDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64EnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
+ if (count && rawValues && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64EnumDictionary *)dictionary {
+ self = [self initWithValidationFunction:dictionary.validationFunc
+ rawValues:NULL
+ forKeys:NULL
+ count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64EnumDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64EnumDictionary class]]) {
+ return NO;
+ }
+ GPBInt64EnumDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(int64_t key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block([aKey longLongValue], [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType {
+ size_t msgSize = ComputeDictInt64FieldSize(key->valueInt64, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
+ NSMutableData *data = [NSMutableData dataWithLength:msgSize];
+ GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
+ WriteDictInt64Field(outputStream, key->valueInt64, kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
+ [outputStream release];
+ return data;
+}
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndRawValuesUsingBlock:^(int64_t key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], @(value));
+ }];
+}
+
+- (BOOL)getEnum:(int32_t *)value forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && value) {
+ int32_t result = [wrapped intValue];
+ if (!_validationFunc(result)) {
+ result = kGPBUnrecognizedEnumeratorValue;
+ }
+ *value = result;
+ }
+ return (wrapped != NULL);
+}
+
+- (BOOL)getRawValue:(int32_t *)rawValue forKey:(int64_t)key {
+ NSNumber *wrapped = [_dictionary objectForKey:@(key)];
+ if (wrapped && rawValue) {
+ *rawValue = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(int64_t key, int32_t value, BOOL *stop))block {
+ GPBEnumValidationFunc func = _validationFunc;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ int32_t unwrapped = [aValue intValue];
+ if (!func(unwrapped)) {
+ unwrapped = kGPBUnrecognizedEnumeratorValue;
+ }
+ block([aKey longLongValue], unwrapped, stop);
+ }];
+}
+
+- (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setRawValue:(int32_t)value forKey:(int64_t)key {
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeEnumForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+- (void)setEnum:(int32_t)value forKey:(int64_t)key {
+ if (!_validationFunc(value)) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"GPBInt64EnumDictionary: Attempt to set an unknown enum value (%d)",
+ value];
+ }
+
+ [_dictionary setObject:@(value) forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+@end
+
+#pragma mark - Int64 -> Object
+
+@implementation GPBInt64ObjectDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithObjects:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithObject:(id)object
+ forKey:(int64_t)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64ObjectDictionary*)[self alloc] initWithObjects:&object
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithObjects:(const id [])objects
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBInt64ObjectDictionary*)[self alloc] initWithObjects:objects
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBInt64ObjectDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBInt64ObjectDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithObjects:(const id [])objects
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && objects && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!objects[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ [_dictionary setObject:objects[i] forKey:@(keys[i])];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBInt64ObjectDictionary *)dictionary {
+ self = [self initWithObjects:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBInt64ObjectDictionary class]]) {
+ return NO;
+ }
+ GPBInt64ObjectDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(int64_t key, id object, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ block([aKey longLongValue], aObject, stop);
+ }];
+}
+
+- (BOOL)isInitialized {
+ for (GPBMessage *msg in [_dictionary objectEnumerator]) {
+ if (!msg.initialized) {
+ return NO;
+ }
+ }
+ return YES;
+}
+
+- (instancetype)deepCopyWithZone:(NSZone *)zone {
+ GPBInt64ObjectDictionary *newDict =
+ [[GPBInt64ObjectDictionary alloc] init];
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(id aKey,
+ GPBMessage *msg,
+ BOOL *stop) {
+ #pragma unused(stop)
+ GPBMessage *copiedMsg = [msg copyWithZone:zone];
+ [newDict->_dictionary setObject:copiedMsg forKey:aKey];
+ [copiedMsg release];
+ }];
+ return newDict;
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSNumber *aKey,
+ id aObject,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictInt64Field(outputStream, [aKey longLongValue], kMapKeyFieldNumber, keyDataType);
+ WriteDictObjectField(outputStream, aObject, kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:value->valueString forKey:@(key->valueInt64)];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndObjectsUsingBlock:^(int64_t key, id object, BOOL *stop) {
+ #pragma unused(stop)
+ block([NSString stringWithFormat:@"%lld", key], object);
+ }];
+}
+
+- (id)objectForKey:(int64_t)key {
+ id result = [_dictionary objectForKey:@(key)];
+ return result;
+}
+
+- (void)addEntriesFromDictionary:(GPBInt64ObjectDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setObject:(id)object forKey:(int64_t)key {
+ if (!object) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ [_dictionary setObject:object forKey:@(key)];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeObjectForKey:(int64_t)aKey {
+ [_dictionary removeObjectForKey:@(aKey)];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_POD_IMPL_FOR_KEY(String, NSString, *, OBJECT)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - String -> UInt32
+
+@implementation GPBStringUInt32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(NSString *)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringUInt32Dictionary*)[self alloc] initWithUInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringUInt32Dictionary*)[self alloc] initWithUInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBStringUInt32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBStringUInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt32s:(const uint32_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!keys[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(values[i]) forKey:keys[i]];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary {
+ self = [self initWithUInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBStringUInt32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBStringUInt32Dictionary class]]) {
+ return NO;
+ }
+ GPBStringUInt32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(NSString *key, uint32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block(aKey, [aValue unsignedIntValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt32Field(outputStream, [aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt32) forKey:key->valueString];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt32sUsingBlock:^(NSString *key, uint32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block(key, [NSString stringWithFormat:@"%u", value]);
+ }];
+}
+
+- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && value) {
+ *value = [wrapped unsignedIntValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt32:(uint32_t)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt32ForKey:(NSString *)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - String -> Int32
+
+@implementation GPBStringInt32Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(NSString *)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringInt32Dictionary*)[self alloc] initWithInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32s:(const int32_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringInt32Dictionary*)[self alloc] initWithInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBStringInt32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBStringInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt32s:(const int32_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!keys[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(values[i]) forKey:keys[i]];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary {
+ self = [self initWithInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBStringInt32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBStringInt32Dictionary class]]) {
+ return NO;
+ }
+ GPBStringInt32Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(NSString *key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block(aKey, [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType);
+ WriteDictInt32Field(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt32) forKey:key->valueString];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt32sUsingBlock:^(NSString *key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block(key, [NSString stringWithFormat:@"%d", value]);
+ }];
+}
+
+- (BOOL)getInt32:(nullable int32_t *)value forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && value) {
+ *value = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt32:(int32_t)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt32ForKey:(NSString *)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - String -> UInt64
+
+@implementation GPBStringUInt64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(NSString *)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringUInt64Dictionary*)[self alloc] initWithUInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringUInt64Dictionary*)[self alloc] initWithUInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBStringUInt64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBStringUInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt64s:(const uint64_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!keys[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(values[i]) forKey:keys[i]];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary {
+ self = [self initWithUInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBStringUInt64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBStringUInt64Dictionary class]]) {
+ return NO;
+ }
+ GPBStringUInt64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(NSString *key, uint64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block(aKey, [aValue unsignedLongLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType);
+ WriteDictUInt64Field(outputStream, [aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueUInt64) forKey:key->valueString];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndUInt64sUsingBlock:^(NSString *key, uint64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block(key, [NSString stringWithFormat:@"%llu", value]);
+ }];
+}
+
+- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && value) {
+ *value = [wrapped unsignedLongLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt64:(uint64_t)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt64ForKey:(NSString *)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - String -> Int64
+
+@implementation GPBStringInt64Dictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(NSString *)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringInt64Dictionary*)[self alloc] initWithInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64s:(const int64_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringInt64Dictionary*)[self alloc] initWithInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBStringInt64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBStringInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt64s:(const int64_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!keys[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(values[i]) forKey:keys[i]];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary {
+ self = [self initWithInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBStringInt64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBStringInt64Dictionary class]]) {
+ return NO;
+ }
+ GPBStringInt64Dictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(NSString *key, int64_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block(aKey, [aValue longLongValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType);
+ WriteDictInt64Field(outputStream, [aValue longLongValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueInt64) forKey:key->valueString];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndInt64sUsingBlock:^(NSString *key, int64_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block(key, [NSString stringWithFormat:@"%lld", value]);
+ }];
+}
+
+- (BOOL)getInt64:(nullable int64_t *)value forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && value) {
+ *value = [wrapped longLongValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt64:(int64_t)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt64ForKey:(NSString *)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - String -> Bool
+
+@implementation GPBStringBoolDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(NSString *)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringBoolDictionary*)[self alloc] initWithBools:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithBools:(const BOOL [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringBoolDictionary*)[self alloc] initWithBools:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBStringBoolDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBStringBoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithBools:(const BOOL [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!keys[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(values[i]) forKey:keys[i]];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary {
+ self = [self initWithBools:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBStringBoolDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBStringBoolDictionary class]]) {
+ return NO;
+ }
+ GPBStringBoolDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(NSString *key, BOOL value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block(aKey, [aValue boolValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType);
+ WriteDictBoolField(outputStream, [aValue boolValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueBool) forKey:key->valueString];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndBoolsUsingBlock:^(NSString *key, BOOL value, BOOL *stop) {
+ #pragma unused(stop)
+ block(key, (value ? @"true" : @"false"));
+ }];
+}
+
+- (BOOL)getBool:(nullable BOOL *)value forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && value) {
+ *value = [wrapped boolValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setBool:(BOOL)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeBoolForKey:(NSString *)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - String -> Float
+
+@implementation GPBStringFloatDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(NSString *)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringFloatDictionary*)[self alloc] initWithFloats:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithFloats:(const float [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringFloatDictionary*)[self alloc] initWithFloats:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBStringFloatDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBStringFloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithFloats:(const float [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!keys[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(values[i]) forKey:keys[i]];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary {
+ self = [self initWithFloats:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBStringFloatDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBStringFloatDictionary class]]) {
+ return NO;
+ }
+ GPBStringFloatDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(NSString *key, float value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block(aKey, [aValue floatValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType);
+ WriteDictFloatField(outputStream, [aValue floatValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueFloat) forKey:key->valueString];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndFloatsUsingBlock:^(NSString *key, float value, BOOL *stop) {
+ #pragma unused(stop)
+ block(key, [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
+ }];
+}
+
+- (BOOL)getFloat:(nullable float *)value forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && value) {
+ *value = [wrapped floatValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setFloat:(float)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeFloatForKey:(NSString *)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - String -> Double
+
+@implementation GPBStringDoubleDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(NSString *)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringDoubleDictionary*)[self alloc] initWithDoubles:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithDoubles:(const double [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringDoubleDictionary*)[self alloc] initWithDoubles:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBStringDoubleDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBStringDoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithDoubles:(const double [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ if (count && values && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!keys[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(values[i]) forKey:keys[i]];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary {
+ self = [self initWithDoubles:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBStringDoubleDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBStringDoubleDictionary class]]) {
+ return NO;
+ }
+ GPBStringDoubleDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(NSString *key, double value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block(aKey, [aValue doubleValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType);
+ WriteDictDoubleField(outputStream, [aValue doubleValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueDouble) forKey:key->valueString];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndDoublesUsingBlock:^(NSString *key, double value, BOOL *stop) {
+ #pragma unused(stop)
+ block(key, [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
+ }];
+}
+
+- (BOOL)getDouble:(nullable double *)value forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && value) {
+ *value = [wrapped doubleValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setDouble:(double)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeDoubleForKey:(NSString *)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+@end
+
+#pragma mark - String -> Enum
+
+@implementation GPBStringEnumDictionary {
+ @package
+ NSMutableDictionary *_dictionary;
+ GPBEnumValidationFunc _validationFunc;
+}
+
+@synthesize validationFunc = _validationFunc;
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithValidationFunction:NULL
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [[[self alloc] initWithValidationFunction:func
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(NSString *)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringEnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:&rawValue
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringEnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:rawValues
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBStringEnumDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBStringEnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
+ if (count && rawValues && keys) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!keys[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(rawValues[i]) forKey:keys[i]];
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBStringEnumDictionary *)dictionary {
+ self = [self initWithValidationFunction:dictionary.validationFunc
+ rawValues:NULL
+ forKeys:NULL
+ count:0];
+ if (self) {
+ if (dictionary) {
+ [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBStringEnumDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBStringEnumDictionary class]]) {
+ return NO;
+ }
+ GPBStringEnumDictionary *otherDictionary = other;
+ return [_dictionary isEqual:otherDictionary->_dictionary];
+}
+
+- (NSUInteger)hash {
+ return _dictionary.count;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
+}
+
+- (NSUInteger)count {
+ return _dictionary.count;
+}
+
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(NSString *key, int32_t value, BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ block(aKey, [aValue intValue], stop);
+ }];
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ NSUInteger count = _dictionary.count;
+ if (count == 0) {
+ return 0;
+ }
+
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ __block size_t result = 0;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }];
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ GPBDataType keyDataType = field.mapKeyDataType;
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ #pragma unused(stop)
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictStringField(outputStream, aKey, kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, [aValue intValue], kMapValueFieldNumber, valueDataType);
+ }];
+}
+
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType {
+ size_t msgSize = ComputeDictStringFieldSize(key->valueString, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
+ NSMutableData *data = [NSMutableData dataWithLength:msgSize];
+ GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
+ WriteDictStringField(outputStream, key->valueString, kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
+ [outputStream release];
+ return data;
+}
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ [_dictionary setObject:@(value->valueEnum) forKey:key->valueString];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ [self enumerateKeysAndRawValuesUsingBlock:^(NSString *key, int32_t value, BOOL *stop) {
+ #pragma unused(stop)
+ block(key, @(value));
+ }];
+}
+
+- (BOOL)getEnum:(int32_t *)value forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && value) {
+ int32_t result = [wrapped intValue];
+ if (!_validationFunc(result)) {
+ result = kGPBUnrecognizedEnumeratorValue;
+ }
+ *value = result;
+ }
+ return (wrapped != NULL);
+}
+
+- (BOOL)getRawValue:(int32_t *)rawValue forKey:(NSString *)key {
+ NSNumber *wrapped = [_dictionary objectForKey:key];
+ if (wrapped && rawValue) {
+ *rawValue = [wrapped intValue];
+ }
+ return (wrapped != NULL);
+}
+
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(NSString *key, int32_t value, BOOL *stop))block {
+ GPBEnumValidationFunc func = _validationFunc;
+ [_dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *aKey,
+ NSNumber *aValue,
+ BOOL *stop) {
+ int32_t unwrapped = [aValue intValue];
+ if (!func(unwrapped)) {
+ unwrapped = kGPBUnrecognizedEnumeratorValue;
+ }
+ block(aKey, unwrapped, stop);
+ }];
+}
+
+- (void)addRawEntriesFromDictionary:(GPBStringEnumDictionary *)otherDictionary {
+ if (otherDictionary) {
+ [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setRawValue:(int32_t)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeEnumForKey:(NSString *)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+- (void)removeAll {
+ [_dictionary removeAllObjects];
+}
+
+- (void)setEnum:(int32_t)value forKey:(NSString *)key {
+ if (!key) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil key to a Dictionary"];
+ }
+ if (!_validationFunc(value)) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"GPBStringEnumDictionary: Attempt to set an unknown enum value (%d)",
+ value];
+ }
+
+ [_dictionary setObject:@(value) forKey:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+@end
+
+//%PDDM-EXPAND-END (5 expansions)
+
+
+//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt32, uint32_t)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> UInt32
+
+@implementation GPBBoolUInt32Dictionary {
+ @package
+ uint32_t _values[2];
+ BOOL _valueSet[2];
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32:(uint32_t)value
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithUInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt32s:(const uint32_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithUInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolUInt32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBBoolUInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt32s:(const uint32_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ int idx = keys[i] ? 1 : 0;
+ _values[idx] = values[i];
+ _valueSet[idx] = YES;
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary {
+ self = [self initWithUInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (dictionary->_valueSet[i]) {
+ _values[i] = dictionary->_values[i];
+ _valueSet[i] = YES;
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt32s:NULL forKeys:NULL count:0];
+}
+
+#if !defined(NS_BLOCK_ASSERTIONS)
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [super dealloc];
+}
+#endif // !defined(NS_BLOCK_ASSERTIONS)
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolUInt32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolUInt32Dictionary class]]) {
+ return NO;
+ }
+ GPBBoolUInt32Dictionary *otherDictionary = other;
+ if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
+ (_valueSet[1] != otherDictionary->_valueSet[1])) {
+ return NO;
+ }
+ if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
+ (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if (_valueSet[0]) {
+ [result appendFormat:@"NO: %u", _values[0]];
+ }
+ if (_valueSet[1]) {
+ [result appendFormat:@"YES: %u", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (BOOL)getUInt32:(uint32_t *)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (value) {
+ *value = _values[idx];
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ _values[idx] = value->valueUInt32;
+ _valueSet[idx] = YES;
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_valueSet[0]) {
+ block(@"false", [NSString stringWithFormat:@"%u", _values[0]]);
+ }
+ if (_valueSet[1]) {
+ block(@"true", [NSString stringWithFormat:@"%u", _values[1]]);
+ }
+}
+
+- (void)enumerateKeysAndUInt32sUsingBlock:
+ (void (^)(BOOL key, uint32_t value, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_valueSet[0]) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictUInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)addEntriesFromDictionary:(GPBBoolUInt32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_valueSet[i]) {
+ _valueSet[i] = YES;
+ _values[i] = otherDictionary->_values[i];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt32:(uint32_t)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ _values[idx] = value;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt32ForKey:(BOOL)aKey {
+ _valueSet[aKey ? 1 : 0] = NO;
+}
+
+- (void)removeAll {
+ _valueSet[0] = NO;
+ _valueSet[1] = NO;
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int32, int32_t)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Int32
+
+@implementation GPBBoolInt32Dictionary {
+ @package
+ int32_t _values[2];
+ BOOL _valueSet[2];
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt32s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32:(int32_t)value
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolInt32Dictionary*)[self alloc] initWithInt32s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt32s:(const int32_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt32s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolInt32Dictionary*)[self alloc] initWithInt32s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolInt32Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBBoolInt32Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt32s:(const int32_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ int idx = keys[i] ? 1 : 0;
+ _values[idx] = values[i];
+ _valueSet[idx] = YES;
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary {
+ self = [self initWithInt32s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (dictionary->_valueSet[i]) {
+ _values[i] = dictionary->_values[i];
+ _valueSet[i] = YES;
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt32s:NULL forKeys:NULL count:0];
+}
+
+#if !defined(NS_BLOCK_ASSERTIONS)
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [super dealloc];
+}
+#endif // !defined(NS_BLOCK_ASSERTIONS)
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolInt32Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolInt32Dictionary class]]) {
+ return NO;
+ }
+ GPBBoolInt32Dictionary *otherDictionary = other;
+ if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
+ (_valueSet[1] != otherDictionary->_valueSet[1])) {
+ return NO;
+ }
+ if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
+ (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if (_valueSet[0]) {
+ [result appendFormat:@"NO: %d", _values[0]];
+ }
+ if (_valueSet[1]) {
+ [result appendFormat:@"YES: %d", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (BOOL)getInt32:(int32_t *)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (value) {
+ *value = _values[idx];
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ _values[idx] = value->valueInt32;
+ _valueSet[idx] = YES;
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_valueSet[0]) {
+ block(@"false", [NSString stringWithFormat:@"%d", _values[0]]);
+ }
+ if (_valueSet[1]) {
+ block(@"true", [NSString stringWithFormat:@"%d", _values[1]]);
+ }
+}
+
+- (void)enumerateKeysAndInt32sUsingBlock:
+ (void (^)(BOOL key, int32_t value, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_valueSet[0]) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)addEntriesFromDictionary:(GPBBoolInt32Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_valueSet[i]) {
+ _valueSet[i] = YES;
+ _values[i] = otherDictionary->_values[i];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt32:(int32_t)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ _values[idx] = value;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt32ForKey:(BOOL)aKey {
+ _valueSet[aKey ? 1 : 0] = NO;
+}
+
+- (void)removeAll {
+ _valueSet[0] = NO;
+ _valueSet[1] = NO;
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt64, uint64_t)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> UInt64
+
+@implementation GPBBoolUInt64Dictionary {
+ @package
+ uint64_t _values[2];
+ BOOL _valueSet[2];
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithUInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64:(uint64_t)value
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithUInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithUInt64s:(const uint64_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithUInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithUInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolUInt64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBBoolUInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithUInt64s:(const uint64_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ int idx = keys[i] ? 1 : 0;
+ _values[idx] = values[i];
+ _valueSet[idx] = YES;
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary {
+ self = [self initWithUInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (dictionary->_valueSet[i]) {
+ _values[i] = dictionary->_values[i];
+ _valueSet[i] = YES;
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithUInt64s:NULL forKeys:NULL count:0];
+}
+
+#if !defined(NS_BLOCK_ASSERTIONS)
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [super dealloc];
+}
+#endif // !defined(NS_BLOCK_ASSERTIONS)
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolUInt64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolUInt64Dictionary class]]) {
+ return NO;
+ }
+ GPBBoolUInt64Dictionary *otherDictionary = other;
+ if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
+ (_valueSet[1] != otherDictionary->_valueSet[1])) {
+ return NO;
+ }
+ if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
+ (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if (_valueSet[0]) {
+ [result appendFormat:@"NO: %llu", _values[0]];
+ }
+ if (_valueSet[1]) {
+ [result appendFormat:@"YES: %llu", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (BOOL)getUInt64:(uint64_t *)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (value) {
+ *value = _values[idx];
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ _values[idx] = value->valueUInt64;
+ _valueSet[idx] = YES;
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_valueSet[0]) {
+ block(@"false", [NSString stringWithFormat:@"%llu", _values[0]]);
+ }
+ if (_valueSet[1]) {
+ block(@"true", [NSString stringWithFormat:@"%llu", _values[1]]);
+ }
+}
+
+- (void)enumerateKeysAndUInt64sUsingBlock:
+ (void (^)(BOOL key, uint64_t value, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_valueSet[0]) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictUInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)addEntriesFromDictionary:(GPBBoolUInt64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_valueSet[i]) {
+ _valueSet[i] = YES;
+ _values[i] = otherDictionary->_values[i];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setUInt64:(uint64_t)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ _values[idx] = value;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeUInt64ForKey:(BOOL)aKey {
+ _valueSet[aKey ? 1 : 0] = NO;
+}
+
+- (void)removeAll {
+ _valueSet[0] = NO;
+ _valueSet[1] = NO;
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int64, int64_t)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Int64
+
+@implementation GPBBoolInt64Dictionary {
+ @package
+ int64_t _values[2];
+ BOOL _valueSet[2];
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithInt64s:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64:(int64_t)value
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolInt64Dictionary*)[self alloc] initWithInt64s:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithInt64s:(const int64_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithInt64s:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolInt64Dictionary*)[self alloc] initWithInt64s:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolInt64Dictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBBoolInt64Dictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithInt64s:(const int64_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ int idx = keys[i] ? 1 : 0;
+ _values[idx] = values[i];
+ _valueSet[idx] = YES;
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary {
+ self = [self initWithInt64s:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (dictionary->_valueSet[i]) {
+ _values[i] = dictionary->_values[i];
+ _valueSet[i] = YES;
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithInt64s:NULL forKeys:NULL count:0];
+}
+
+#if !defined(NS_BLOCK_ASSERTIONS)
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [super dealloc];
+}
+#endif // !defined(NS_BLOCK_ASSERTIONS)
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolInt64Dictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolInt64Dictionary class]]) {
+ return NO;
+ }
+ GPBBoolInt64Dictionary *otherDictionary = other;
+ if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
+ (_valueSet[1] != otherDictionary->_valueSet[1])) {
+ return NO;
+ }
+ if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
+ (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if (_valueSet[0]) {
+ [result appendFormat:@"NO: %lld", _values[0]];
+ }
+ if (_valueSet[1]) {
+ [result appendFormat:@"YES: %lld", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (BOOL)getInt64:(int64_t *)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (value) {
+ *value = _values[idx];
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ _values[idx] = value->valueInt64;
+ _valueSet[idx] = YES;
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_valueSet[0]) {
+ block(@"false", [NSString stringWithFormat:@"%lld", _values[0]]);
+ }
+ if (_valueSet[1]) {
+ block(@"true", [NSString stringWithFormat:@"%lld", _values[1]]);
+ }
+}
+
+- (void)enumerateKeysAndInt64sUsingBlock:
+ (void (^)(BOOL key, int64_t value, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_valueSet[0]) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)addEntriesFromDictionary:(GPBBoolInt64Dictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_valueSet[i]) {
+ _valueSet[i] = YES;
+ _values[i] = otherDictionary->_values[i];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setInt64:(int64_t)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ _values[idx] = value;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeInt64ForKey:(BOOL)aKey {
+ _valueSet[aKey ? 1 : 0] = NO;
+}
+
+- (void)removeAll {
+ _valueSet[0] = NO;
+ _valueSet[1] = NO;
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Bool, BOOL)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Bool
+
+@implementation GPBBoolBoolDictionary {
+ @package
+ BOOL _values[2];
+ BOOL _valueSet[2];
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithBools:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithBool:(BOOL)value
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolBoolDictionary*)[self alloc] initWithBools:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithBools:(const BOOL [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithBools:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolBoolDictionary*)[self alloc] initWithBools:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolBoolDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBBoolBoolDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithBools:(const BOOL [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ int idx = keys[i] ? 1 : 0;
+ _values[idx] = values[i];
+ _valueSet[idx] = YES;
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary {
+ self = [self initWithBools:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (dictionary->_valueSet[i]) {
+ _values[i] = dictionary->_values[i];
+ _valueSet[i] = YES;
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithBools:NULL forKeys:NULL count:0];
+}
+
+#if !defined(NS_BLOCK_ASSERTIONS)
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [super dealloc];
+}
+#endif // !defined(NS_BLOCK_ASSERTIONS)
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolBoolDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolBoolDictionary class]]) {
+ return NO;
+ }
+ GPBBoolBoolDictionary *otherDictionary = other;
+ if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
+ (_valueSet[1] != otherDictionary->_valueSet[1])) {
+ return NO;
+ }
+ if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
+ (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if (_valueSet[0]) {
+ [result appendFormat:@"NO: %d", _values[0]];
+ }
+ if (_valueSet[1]) {
+ [result appendFormat:@"YES: %d", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (BOOL)getBool:(BOOL *)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (value) {
+ *value = _values[idx];
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ _values[idx] = value->valueBool;
+ _valueSet[idx] = YES;
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_valueSet[0]) {
+ block(@"false", (_values[0] ? @"true" : @"false"));
+ }
+ if (_valueSet[1]) {
+ block(@"true", (_values[1] ? @"true" : @"false"));
+ }
+}
+
+- (void)enumerateKeysAndBoolsUsingBlock:
+ (void (^)(BOOL key, BOOL value, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_valueSet[0]) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictBoolField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)addEntriesFromDictionary:(GPBBoolBoolDictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_valueSet[i]) {
+ _valueSet[i] = YES;
+ _values[i] = otherDictionary->_values[i];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setBool:(BOOL)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ _values[idx] = value;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeBoolForKey:(BOOL)aKey {
+ _valueSet[aKey ? 1 : 0] = NO;
+}
+
+- (void)removeAll {
+ _valueSet[0] = NO;
+ _valueSet[1] = NO;
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Float, float)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Float
+
+@implementation GPBBoolFloatDictionary {
+ @package
+ float _values[2];
+ BOOL _valueSet[2];
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithFloats:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithFloat:(float)value
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolFloatDictionary*)[self alloc] initWithFloats:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithFloats:(const float [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithFloats:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolFloatDictionary*)[self alloc] initWithFloats:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolFloatDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBBoolFloatDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithFloats:(const float [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ int idx = keys[i] ? 1 : 0;
+ _values[idx] = values[i];
+ _valueSet[idx] = YES;
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary {
+ self = [self initWithFloats:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (dictionary->_valueSet[i]) {
+ _values[i] = dictionary->_values[i];
+ _valueSet[i] = YES;
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithFloats:NULL forKeys:NULL count:0];
+}
+
+#if !defined(NS_BLOCK_ASSERTIONS)
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [super dealloc];
+}
+#endif // !defined(NS_BLOCK_ASSERTIONS)
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolFloatDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolFloatDictionary class]]) {
+ return NO;
+ }
+ GPBBoolFloatDictionary *otherDictionary = other;
+ if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
+ (_valueSet[1] != otherDictionary->_valueSet[1])) {
+ return NO;
+ }
+ if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
+ (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if (_valueSet[0]) {
+ [result appendFormat:@"NO: %f", _values[0]];
+ }
+ if (_valueSet[1]) {
+ [result appendFormat:@"YES: %f", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (BOOL)getFloat:(float *)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (value) {
+ *value = _values[idx];
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ _values[idx] = value->valueFloat;
+ _valueSet[idx] = YES;
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_valueSet[0]) {
+ block(@"false", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[0]]);
+ }
+ if (_valueSet[1]) {
+ block(@"true", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[1]]);
+ }
+}
+
+- (void)enumerateKeysAndFloatsUsingBlock:
+ (void (^)(BOOL key, float value, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_valueSet[0]) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictFloatField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)addEntriesFromDictionary:(GPBBoolFloatDictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_valueSet[i]) {
+ _valueSet[i] = YES;
+ _values[i] = otherDictionary->_values[i];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setFloat:(float)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ _values[idx] = value;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeFloatForKey:(BOOL)aKey {
+ _valueSet[aKey ? 1 : 0] = NO;
+}
+
+- (void)removeAll {
+ _valueSet[0] = NO;
+ _valueSet[1] = NO;
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Double, double)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Double
+
+@implementation GPBBoolDoubleDictionary {
+ @package
+ double _values[2];
+ BOOL _valueSet[2];
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithDoubles:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithDouble:(double)value
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDoubles:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithDoubles:(const double [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithDoubles:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDoubles:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolDoubleDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBBoolDoubleDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithDoubles:(const double [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ int idx = keys[i] ? 1 : 0;
+ _values[idx] = values[i];
+ _valueSet[idx] = YES;
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary {
+ self = [self initWithDoubles:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (dictionary->_valueSet[i]) {
+ _values[i] = dictionary->_values[i];
+ _valueSet[i] = YES;
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithDoubles:NULL forKeys:NULL count:0];
+}
+
+#if !defined(NS_BLOCK_ASSERTIONS)
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [super dealloc];
+}
+#endif // !defined(NS_BLOCK_ASSERTIONS)
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolDoubleDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolDoubleDictionary class]]) {
+ return NO;
+ }
+ GPBBoolDoubleDictionary *otherDictionary = other;
+ if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
+ (_valueSet[1] != otherDictionary->_valueSet[1])) {
+ return NO;
+ }
+ if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
+ (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if (_valueSet[0]) {
+ [result appendFormat:@"NO: %lf", _values[0]];
+ }
+ if (_valueSet[1]) {
+ [result appendFormat:@"YES: %lf", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (BOOL)getDouble:(double *)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (value) {
+ *value = _values[idx];
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ _values[idx] = value->valueDouble;
+ _valueSet[idx] = YES;
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_valueSet[0]) {
+ block(@"false", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[0]]);
+ }
+ if (_valueSet[1]) {
+ block(@"true", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[1]]);
+ }
+}
+
+- (void)enumerateKeysAndDoublesUsingBlock:
+ (void (^)(BOOL key, double value, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_valueSet[0]) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictDoubleField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)addEntriesFromDictionary:(GPBBoolDoubleDictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_valueSet[i]) {
+ _valueSet[i] = YES;
+ _values[i] = otherDictionary->_values[i];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setDouble:(double)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ _values[idx] = value;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeDoubleForKey:(BOOL)aKey {
+ _valueSet[aKey ? 1 : 0] = NO;
+}
+
+- (void)removeAll {
+ _valueSet[0] = NO;
+ _valueSet[1] = NO;
+}
+
+@end
+
+//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(Object, id)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Object
+
+@implementation GPBBoolObjectDictionary {
+ @package
+ id _values[2];
+}
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithObjects:NULL forKeys:NULL count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithObject:(id)object
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolObjectDictionary*)[self alloc] initWithObjects:&object
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithObjects:(const id [])objects
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithObjects:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolObjectDictionary*)[self alloc] initWithObjects:objects
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolObjectDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithDictionary:
+ // on to get the type correct.
+ return [[(GPBBoolObjectDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithCapacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithCapacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithObjects:(const id [])objects
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ for (NSUInteger i = 0; i < count; ++i) {
+ if (!objects[i]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ int idx = keys[i] ? 1 : 0;
+ [_values[idx] release];
+ _values[idx] = (id)[objects[i] retain];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolObjectDictionary *)dictionary {
+ self = [self initWithObjects:NULL forKeys:NULL count:0];
+ if (self) {
+ if (dictionary) {
+ _values[0] = [dictionary->_values[0] retain];
+ _values[1] = [dictionary->_values[1] retain];
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithCapacity:(NSUInteger)numItems {
+ #pragma unused(numItems)
+ return [self initWithObjects:NULL forKeys:NULL count:0];
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_values[0] release];
+ [_values[1] release];
+ [super dealloc];
+}
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolObjectDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolObjectDictionary class]]) {
+ return NO;
+ }
+ GPBBoolObjectDictionary *otherDictionary = other;
+ if (((_values[0] != nil) != (otherDictionary->_values[0] != nil)) ||
+ ((_values[1] != nil) != (otherDictionary->_values[1] != nil))) {
+ return NO;
+ }
+ if (((_values[0] != nil) && (![_values[0] isEqual:otherDictionary->_values[0]])) ||
+ ((_values[1] != nil) && (![_values[1] isEqual:otherDictionary->_values[1]]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if ((_values[0] != nil)) {
+ [result appendFormat:@"NO: %@", _values[0]];
+ }
+ if ((_values[1] != nil)) {
+ [result appendFormat:@"YES: %@", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0);
+}
+
+- (id)objectForKey:(BOOL)key {
+ return _values[key ? 1 : 0];
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ [_values[idx] release];
+ _values[idx] = [value->valueString retain];
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_values[0] != nil) {
+ block(@"false", _values[0]);
+ }
+ if ((_values[1] != nil)) {
+ block(@"true", _values[1]);
+ }
+}
+
+- (void)enumerateKeysAndObjectsUsingBlock:
+ (void (^)(BOOL key, id object, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_values[0] != nil) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && (_values[1] != nil)) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (BOOL)isInitialized {
+ if (_values[0] && ![_values[0] isInitialized]) {
+ return NO;
+ }
+ if (_values[1] && ![_values[1] isInitialized]) {
+ return NO;
+ }
+ return YES;
+}
+
+- (instancetype)deepCopyWithZone:(NSZone *)zone {
+ GPBBoolObjectDictionary *newDict =
+ [[GPBBoolObjectDictionary alloc] init];
+ for (int i = 0; i < 2; ++i) {
+ if (_values[i] != nil) {
+ newDict->_values[i] = [_values[i] copyWithZone:zone];
+ }
+ }
+ return newDict;
+}
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_values[i] != nil) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_values[i] != nil) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictObjectField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)addEntriesFromDictionary:(GPBBoolObjectDictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_values[i] != nil) {
+ [_values[i] release];
+ _values[i] = [otherDictionary->_values[i] retain];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setObject:(id)object forKey:(BOOL)key {
+ if (!object) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Attempting to add nil object to a Dictionary"];
+ }
+ int idx = (key ? 1 : 0);
+ [_values[idx] release];
+ _values[idx] = [object retain];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeObjectForKey:(BOOL)aKey {
+ int idx = (aKey ? 1 : 0);
+ [_values[idx] release];
+ _values[idx] = nil;
+}
+
+- (void)removeAll {
+ for (int i = 0; i < 2; ++i) {
+ [_values[i] release];
+ _values[i] = nil;
+ }
+}
+
+@end
+
+//%PDDM-EXPAND-END (8 expansions)
+
+#pragma mark - Bool -> Enum
+
+@implementation GPBBoolEnumDictionary {
+ @package
+ GPBEnumValidationFunc _validationFunc;
+ int32_t _values[2];
+ BOOL _valueSet[2];
+}
+
+@synthesize validationFunc = _validationFunc;
+
++ (instancetype)dictionary {
+ return [[[self alloc] initWithValidationFunction:NULL
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [[[self alloc] initWithValidationFunction:func
+ rawValues:NULL
+ forKeys:NULL
+ count:0] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValue:(int32_t)rawValue
+ forKey:(BOOL)key {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolEnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:&rawValue
+ forKeys:&key
+ count:1] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])values
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolEnumDictionary*)[self alloc] initWithValidationFunction:func
+ rawValues:values
+ forKeys:keys
+ count:count] autorelease];
+}
+
++ (instancetype)dictionaryWithDictionary:(GPBBoolEnumDictionary *)dictionary {
+ // Cast is needed so the compiler knows what class we are invoking initWithValues:forKeys:count:
+ // on to get the type correct.
+ return [[(GPBBoolEnumDictionary*)[self alloc] initWithDictionary:dictionary] autorelease];
+}
+
++ (instancetype)dictionaryWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+ return [[[self alloc] initWithValidationFunction:func capacity:numItems] autorelease];
+}
+
+- (instancetype)init {
+ return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ rawValues:(const int32_t [])rawValues
+ forKeys:(const BOOL [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
+ for (NSUInteger i = 0; i < count; ++i) {
+ int idx = keys[i] ? 1 : 0;
+ _values[idx] = rawValues[i];
+ _valueSet[idx] = YES;
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithDictionary:(GPBBoolEnumDictionary *)dictionary {
+ self = [self initWithValidationFunction:dictionary.validationFunc
+ rawValues:NULL
+ forKeys:NULL
+ count:0];
+ if (self) {
+ if (dictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (dictionary->_valueSet[i]) {
+ _values[i] = dictionary->_values[i];
+ _valueSet[i] = YES;
+ }
+ }
+ }
+ }
+ return self;
+}
+
+- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
+ capacity:(NSUInteger)numItems {
+#pragma unused(numItems)
+ return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
+}
+
+#if !defined(NS_BLOCK_ASSERTIONS)
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [super dealloc];
+}
+#endif // !defined(NS_BLOCK_ASSERTIONS)
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ return [[GPBBoolEnumDictionary allocWithZone:zone] initWithDictionary:self];
+}
+
+- (BOOL)isEqual:(id)other {
+ if (self == other) {
+ return YES;
+ }
+ if (![other isKindOfClass:[GPBBoolEnumDictionary class]]) {
+ return NO;
+ }
+ GPBBoolEnumDictionary *otherDictionary = other;
+ if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
+ (_valueSet[1] != otherDictionary->_valueSet[1])) {
+ return NO;
+ }
+ if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
+ (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSUInteger)hash {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (NSString *)description {
+ NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
+ if (_valueSet[0]) {
+ [result appendFormat:@"NO: %d", _values[0]];
+ }
+ if (_valueSet[1]) {
+ [result appendFormat:@"YES: %d", _values[1]];
+ }
+ [result appendString:@" }"];
+ return result;
+}
+
+- (NSUInteger)count {
+ return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
+}
+
+- (BOOL)getEnum:(int32_t*)value forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (value) {
+ int32_t result = _values[idx];
+ if (!_validationFunc(result)) {
+ result = kGPBUnrecognizedEnumeratorValue;
+ }
+ *value = result;
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (BOOL)getRawValue:(int32_t*)rawValue forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ if (_valueSet[idx]) {
+ if (rawValue) {
+ *rawValue = _values[idx];
+ }
+ return YES;
+ }
+ return NO;
+}
+
+- (void)enumerateKeysAndRawValuesUsingBlock:
+ (void (^)(BOOL key, int32_t value, BOOL *stop))block {
+ BOOL stop = NO;
+ if (_valueSet[0]) {
+ block(NO, _values[0], &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ block(YES, _values[1], &stop);
+ }
+}
+
+- (void)enumerateKeysAndEnumsUsingBlock:
+ (void (^)(BOOL key, int32_t rawValue, BOOL *stop))block {
+ BOOL stop = NO;
+ GPBEnumValidationFunc func = _validationFunc;
+ int32_t validatedValue;
+ if (_valueSet[0]) {
+ validatedValue = _values[0];
+ if (!func(validatedValue)) {
+ validatedValue = kGPBUnrecognizedEnumeratorValue;
+ }
+ block(NO, validatedValue, &stop);
+ }
+ if (!stop && _valueSet[1]) {
+ validatedValue = _values[1];
+ if (!func(validatedValue)) {
+ validatedValue = kGPBUnrecognizedEnumeratorValue;
+ }
+ block(YES, validatedValue, &stop);
+ }
+}
+
+//%PDDM-EXPAND SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool)
+// This block of code is generated, do not edit it directly.
+
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType {
+ size_t msgSize = ComputeDictBoolFieldSize(key->valueBool, kMapKeyFieldNumber, keyDataType);
+ msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
+ NSMutableData *data = [NSMutableData dataWithLength:msgSize];
+ GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
+ WriteDictBoolField(outputStream, key->valueBool, kMapKeyFieldNumber, keyDataType);
+ WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
+ [outputStream release];
+ return data;
+}
+
+//%PDDM-EXPAND-END SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool)
+
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSUInteger count = 0;
+ size_t result = 0;
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ ++count;
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
+ }
+ }
+ size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
+ result += tagSize * count;
+ return result;
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field {
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
+ for (int i = 0; i < 2; ++i) {
+ if (_valueSet[i]) {
+ // Write the tag.
+ [outputStream writeInt32NoTag:tag];
+ // Write the size of the message.
+ size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
+ [outputStream writeInt32NoTag:(int32_t)msgSize];
+ // Write the fields.
+ WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
+ WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
+ }
+ }
+}
+
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
+ if (_valueSet[0]) {
+ block(@"false", @(_values[0]));
+ }
+ if (_valueSet[1]) {
+ block(@"true", @(_values[1]));
+ }
+}
+
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key {
+ int idx = (key->valueBool ? 1 : 0);
+ _values[idx] = value->valueInt32;
+ _valueSet[idx] = YES;
+}
+
+- (void)addRawEntriesFromDictionary:(GPBBoolEnumDictionary *)otherDictionary {
+ if (otherDictionary) {
+ for (int i = 0; i < 2; ++i) {
+ if (otherDictionary->_valueSet[i]) {
+ _valueSet[i] = YES;
+ _values[i] = otherDictionary->_values[i];
+ }
+ }
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+ }
+}
+
+- (void)setEnum:(int32_t)value forKey:(BOOL)key {
+ if (!_validationFunc(value)) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"GPBBoolEnumDictionary: Attempt to set an unknown enum value (%d)",
+ value];
+ }
+ int idx = (key ? 1 : 0);
+ _values[idx] = value;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key {
+ int idx = (key ? 1 : 0);
+ _values[idx] = rawValue;
+ _valueSet[idx] = YES;
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeEnumForKey:(BOOL)aKey {
+ _valueSet[aKey ? 1 : 0] = NO;
+}
+
+- (void)removeAll {
+ _valueSet[0] = NO;
+ _valueSet[1] = NO;
+}
+
+@end
+
+#pragma mark - NSDictionary Subclass
+
+@implementation GPBAutocreatedDictionary {
+ NSMutableDictionary *_dictionary;
+}
+
+- (void)dealloc {
+ NSAssert(!_autocreator,
+ @"%@: Autocreator must be cleared before release, autocreator: %@",
+ [self class], _autocreator);
+ [_dictionary release];
+ [super dealloc];
+}
+
+#pragma mark Required NSDictionary overrides
+
+- (instancetype)initWithObjects:(const id [])objects
+ forKeys:(const id<NSCopying> [])keys
+ count:(NSUInteger)count {
+ self = [super init];
+ if (self) {
+ _dictionary = [[NSMutableDictionary alloc] initWithObjects:objects
+ forKeys:keys
+ count:count];
+ }
+ return self;
+}
+
+- (NSUInteger)count {
+ return [_dictionary count];
+}
+
+- (id)objectForKey:(id)aKey {
+ return [_dictionary objectForKey:aKey];
+}
+
+- (NSEnumerator *)keyEnumerator {
+ if (_dictionary == nil) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ }
+ return [_dictionary keyEnumerator];
+}
+
+#pragma mark Required NSMutableDictionary overrides
+
+// Only need to call GPBAutocreatedDictionaryModified() when adding things
+// since we only autocreate empty dictionaries.
+
+- (void)setObject:(id)anObject forKey:(id<NSCopying>)aKey {
+ if (_dictionary == nil) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ }
+ [_dictionary setObject:anObject forKey:aKey];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)removeObjectForKey:(id)aKey {
+ [_dictionary removeObjectForKey:aKey];
+}
+
+#pragma mark Extra things hooked
+
+- (id)copyWithZone:(NSZone *)zone {
+ if (_dictionary == nil) {
+ return [[NSMutableDictionary allocWithZone:zone] init];
+ }
+ return [_dictionary copyWithZone:zone];
+}
+
+- (id)mutableCopyWithZone:(NSZone *)zone {
+ if (_dictionary == nil) {
+ return [[NSMutableDictionary allocWithZone:zone] init];
+ }
+ return [_dictionary mutableCopyWithZone:zone];
+}
+
+// Not really needed, but subscripting is likely common enough it doesn't hurt
+// to ensure it goes directly to the real NSMutableDictionary.
+- (id)objectForKeyedSubscript:(id)key {
+ return [_dictionary objectForKeyedSubscript:key];
+}
+
+// Not really needed, but subscripting is likely common enough it doesn't hurt
+// to ensure it goes directly to the real NSMutableDictionary.
+- (void)setObject:(id)obj forKeyedSubscript:(id<NSCopying>)key {
+ if (_dictionary == nil) {
+ _dictionary = [[NSMutableDictionary alloc] init];
+ }
+ [_dictionary setObject:obj forKeyedSubscript:key];
+ if (_autocreator) {
+ GPBAutocreatedDictionaryModified(_autocreator, self);
+ }
+}
+
+- (void)enumerateKeysAndObjectsUsingBlock:(void (^)(id key,
+ id obj,
+ BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsUsingBlock:block];
+}
+
+- (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts
+ usingBlock:(void (^)(id key,
+ id obj,
+ BOOL *stop))block {
+ [_dictionary enumerateKeysAndObjectsWithOptions:opts usingBlock:block];
+}
+
+@end
+
+#pragma clang diagnostic pop
diff --git a/third_party/protobuf/objectivec/GPBDictionary_PackagePrivate.h b/third_party/protobuf/objectivec/GPBDictionary_PackagePrivate.h
new file mode 100644
index 0000000000..7b921e8ec7
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBDictionary_PackagePrivate.h
@@ -0,0 +1,488 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBDictionary.h"
+
+@class GPBCodedInputStream;
+@class GPBCodedOutputStream;
+@class GPBExtensionRegistry;
+@class GPBFieldDescriptor;
+
+@protocol GPBDictionaryInternalsProtocol
+- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field;
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
+ asField:(GPBFieldDescriptor *)field;
+- (void)setGPBGenericValue:(GPBGenericValue *)value
+ forGPBGenericValueKey:(GPBGenericValue *)key;
+- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block;
+@end
+
+//%PDDM-DEFINE DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(KEY_NAME)
+//%DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(KEY_NAME)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Object, Object)
+//%PDDM-DEFINE DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(KEY_NAME)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, UInt32, Basic)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Int32, Basic)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, UInt64, Basic)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Int64, Basic)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Bool, Basic)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Float, Basic)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Double, Basic)
+//%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Enum, Enum)
+
+//%PDDM-DEFINE DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, VALUE_NAME, HELPER)
+//%@interface GPB##KEY_NAME##VALUE_NAME##Dictionary () <GPBDictionaryInternalsProtocol> {
+//% @package
+//% GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+//%}
+//%EXTRA_DICTIONARY_PRIVATE_INTERFACES_##HELPER()@end
+//%
+
+//%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Basic()
+// Empty
+//%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Object()
+//%- (BOOL)isInitialized;
+//%- (instancetype)deepCopyWithZone:(NSZone *)zone
+//% __attribute__((ns_returns_retained));
+//%
+//%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Enum()
+//%- (NSData *)serializedDataForUnknownValue:(int32_t)value
+//% forKey:(GPBGenericValue *)key
+//% keyDataType:(GPBDataType)keyDataType;
+//%
+
+//%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(UInt32)
+// This block of code is generated, do not edit it directly.
+
+@interface GPBUInt32UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt32Int32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt32UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt32Int64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt32BoolDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt32FloatDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt32DoubleDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt32EnumDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType;
+@end
+
+@interface GPBUInt32ObjectDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (BOOL)isInitialized;
+- (instancetype)deepCopyWithZone:(NSZone *)zone
+ __attribute__((ns_returns_retained));
+@end
+
+//%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Int32)
+// This block of code is generated, do not edit it directly.
+
+@interface GPBInt32UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt32Int32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt32UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt32Int64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt32BoolDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt32FloatDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt32DoubleDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt32EnumDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType;
+@end
+
+@interface GPBInt32ObjectDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (BOOL)isInitialized;
+- (instancetype)deepCopyWithZone:(NSZone *)zone
+ __attribute__((ns_returns_retained));
+@end
+
+//%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(UInt64)
+// This block of code is generated, do not edit it directly.
+
+@interface GPBUInt64UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt64Int32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt64UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt64Int64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt64BoolDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt64FloatDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt64DoubleDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBUInt64EnumDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType;
+@end
+
+@interface GPBUInt64ObjectDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (BOOL)isInitialized;
+- (instancetype)deepCopyWithZone:(NSZone *)zone
+ __attribute__((ns_returns_retained));
+@end
+
+//%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Int64)
+// This block of code is generated, do not edit it directly.
+
+@interface GPBInt64UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt64Int32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt64UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt64Int64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt64BoolDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt64FloatDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt64DoubleDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBInt64EnumDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType;
+@end
+
+@interface GPBInt64ObjectDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (BOOL)isInitialized;
+- (instancetype)deepCopyWithZone:(NSZone *)zone
+ __attribute__((ns_returns_retained));
+@end
+
+//%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Bool)
+// This block of code is generated, do not edit it directly.
+
+@interface GPBBoolUInt32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBBoolInt32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBBoolUInt64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBBoolInt64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBBoolBoolDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBBoolFloatDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBBoolDoubleDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBBoolEnumDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType;
+@end
+
+@interface GPBBoolObjectDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (BOOL)isInitialized;
+- (instancetype)deepCopyWithZone:(NSZone *)zone
+ __attribute__((ns_returns_retained));
+@end
+
+//%PDDM-EXPAND DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(String)
+// This block of code is generated, do not edit it directly.
+
+@interface GPBStringUInt32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBStringInt32Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBStringUInt64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBStringInt64Dictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBStringBoolDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBStringFloatDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBStringDoubleDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+@interface GPBStringEnumDictionary () <GPBDictionaryInternalsProtocol> {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+- (NSData *)serializedDataForUnknownValue:(int32_t)value
+ forKey:(GPBGenericValue *)key
+ keyDataType:(GPBDataType)keyDataType;
+@end
+
+//%PDDM-EXPAND-END (6 expansions)
+
+#pragma mark - NSDictionary Subclass
+
+@interface GPBAutocreatedDictionary : NSMutableDictionary {
+ @package
+ GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
+}
+@end
+
+#pragma mark - Helpers
+
+CF_EXTERN_C_BEGIN
+
+// Helper to compute size when an NSDictionary is used for the map instead
+// of a custom type.
+size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict,
+ GPBFieldDescriptor *field);
+
+// Helper to write out when an NSDictionary is used for the map instead
+// of a custom type.
+void GPBDictionaryWriteToStreamInternalHelper(
+ GPBCodedOutputStream *outputStream, NSDictionary *dict,
+ GPBFieldDescriptor *field);
+
+// Helper to check message initialization when an NSDictionary is used for
+// the map instead of a custom type.
+BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict,
+ GPBFieldDescriptor *field);
+
+// Helper to read a map instead.
+void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream,
+ GPBExtensionRegistry *registry,
+ GPBFieldDescriptor *field,
+ GPBMessage *parentMessage);
+
+CF_EXTERN_C_END
diff --git a/third_party/protobuf/objectivec/GPBExtensionInternals.h b/third_party/protobuf/objectivec/GPBExtensionInternals.h
new file mode 100644
index 0000000000..2b980aefa4
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBExtensionInternals.h
@@ -0,0 +1,50 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBDescriptor.h"
+
+@class GPBCodedInputStream;
+@class GPBCodedOutputStream;
+@class GPBExtensionRegistry;
+
+void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension,
+ BOOL isPackedOnStream,
+ GPBCodedInputStream *input,
+ GPBExtensionRegistry *extensionRegistry,
+ GPBMessage *message);
+
+size_t GPBComputeExtensionSerializedSizeIncludingTag(
+ GPBExtensionDescriptor *extension, id value);
+
+void GPBWriteExtensionValueToOutputStream(GPBExtensionDescriptor *extension,
+ id value,
+ GPBCodedOutputStream *output);
diff --git a/third_party/protobuf/objectivec/GPBExtensionInternals.m b/third_party/protobuf/objectivec/GPBExtensionInternals.m
new file mode 100644
index 0000000000..290c82a1bb
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBExtensionInternals.m
@@ -0,0 +1,391 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBExtensionInternals.h"
+
+#import <objc/runtime.h>
+
+#import "GPBCodedInputStream_PackagePrivate.h"
+#import "GPBCodedOutputStream_PackagePrivate.h"
+#import "GPBDescriptor_PackagePrivate.h"
+#import "GPBMessage_PackagePrivate.h"
+#import "GPBUtilities_PackagePrivate.h"
+
+static id NewSingleValueFromInputStream(GPBExtensionDescriptor *extension,
+ GPBCodedInputStream *input,
+ GPBExtensionRegistry *extensionRegistry,
+ GPBMessage *existingValue)
+ __attribute__((ns_returns_retained));
+
+GPB_INLINE size_t DataTypeSize(GPBDataType dataType) {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wswitch-enum"
+ switch (dataType) {
+ case GPBDataTypeBool:
+ return 1;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeFloat:
+ return 4;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeDouble:
+ return 8;
+ default:
+ return 0;
+ }
+#pragma clang diagnostic pop
+}
+
+static size_t ComputePBSerializedSizeNoTagOfObject(GPBDataType dataType, id object) {
+#define FIELD_CASE(TYPE, ACCESSOR) \
+ case GPBDataType##TYPE: \
+ return GPBCompute##TYPE##SizeNoTag([(NSNumber *)object ACCESSOR]);
+#define FIELD_CASE2(TYPE) \
+ case GPBDataType##TYPE: \
+ return GPBCompute##TYPE##SizeNoTag(object);
+ switch (dataType) {
+ FIELD_CASE(Bool, boolValue)
+ FIELD_CASE(Float, floatValue)
+ FIELD_CASE(Double, doubleValue)
+ FIELD_CASE(Int32, intValue)
+ FIELD_CASE(SFixed32, intValue)
+ FIELD_CASE(SInt32, intValue)
+ FIELD_CASE(Enum, intValue)
+ FIELD_CASE(Int64, longLongValue)
+ FIELD_CASE(SInt64, longLongValue)
+ FIELD_CASE(SFixed64, longLongValue)
+ FIELD_CASE(UInt32, unsignedIntValue)
+ FIELD_CASE(Fixed32, unsignedIntValue)
+ FIELD_CASE(UInt64, unsignedLongLongValue)
+ FIELD_CASE(Fixed64, unsignedLongLongValue)
+ FIELD_CASE2(Bytes)
+ FIELD_CASE2(String)
+ FIELD_CASE2(Message)
+ FIELD_CASE2(Group)
+ }
+#undef FIELD_CASE
+#undef FIELD_CASE2
+}
+
+static size_t ComputeSerializedSizeIncludingTagOfObject(
+ GPBExtensionDescription *description, id object) {
+#define FIELD_CASE(TYPE, ACCESSOR) \
+ case GPBDataType##TYPE: \
+ return GPBCompute##TYPE##Size(description->fieldNumber, \
+ [(NSNumber *)object ACCESSOR]);
+#define FIELD_CASE2(TYPE) \
+ case GPBDataType##TYPE: \
+ return GPBCompute##TYPE##Size(description->fieldNumber, object);
+ switch (description->dataType) {
+ FIELD_CASE(Bool, boolValue)
+ FIELD_CASE(Float, floatValue)
+ FIELD_CASE(Double, doubleValue)
+ FIELD_CASE(Int32, intValue)
+ FIELD_CASE(SFixed32, intValue)
+ FIELD_CASE(SInt32, intValue)
+ FIELD_CASE(Enum, intValue)
+ FIELD_CASE(Int64, longLongValue)
+ FIELD_CASE(SInt64, longLongValue)
+ FIELD_CASE(SFixed64, longLongValue)
+ FIELD_CASE(UInt32, unsignedIntValue)
+ FIELD_CASE(Fixed32, unsignedIntValue)
+ FIELD_CASE(UInt64, unsignedLongLongValue)
+ FIELD_CASE(Fixed64, unsignedLongLongValue)
+ FIELD_CASE2(Bytes)
+ FIELD_CASE2(String)
+ FIELD_CASE2(Group)
+ case GPBDataTypeMessage:
+ if (GPBExtensionIsWireFormat(description)) {
+ return GPBComputeMessageSetExtensionSize(description->fieldNumber,
+ object);
+ } else {
+ return GPBComputeMessageSize(description->fieldNumber, object);
+ }
+ }
+#undef FIELD_CASE
+#undef FIELD_CASE2
+}
+
+static size_t ComputeSerializedSizeIncludingTagOfArray(
+ GPBExtensionDescription *description, NSArray *values) {
+ if (GPBExtensionIsPacked(description)) {
+ size_t size = 0;
+ size_t typeSize = DataTypeSize(description->dataType);
+ if (typeSize != 0) {
+ size = values.count * typeSize;
+ } else {
+ for (id value in values) {
+ size +=
+ ComputePBSerializedSizeNoTagOfObject(description->dataType, value);
+ }
+ }
+ return size + GPBComputeTagSize(description->fieldNumber) +
+ GPBComputeRawVarint32SizeForInteger(size);
+ } else {
+ size_t size = 0;
+ for (id value in values) {
+ size += ComputeSerializedSizeIncludingTagOfObject(description, value);
+ }
+ return size;
+ }
+}
+
+static void WriteObjectIncludingTagToCodedOutputStream(
+ id object, GPBExtensionDescription *description,
+ GPBCodedOutputStream *output) {
+#define FIELD_CASE(TYPE, ACCESSOR) \
+ case GPBDataType##TYPE: \
+ [output write##TYPE:description->fieldNumber \
+ value:[(NSNumber *)object ACCESSOR]]; \
+ return;
+#define FIELD_CASE2(TYPE) \
+ case GPBDataType##TYPE: \
+ [output write##TYPE:description->fieldNumber value:object]; \
+ return;
+ switch (description->dataType) {
+ FIELD_CASE(Bool, boolValue)
+ FIELD_CASE(Float, floatValue)
+ FIELD_CASE(Double, doubleValue)
+ FIELD_CASE(Int32, intValue)
+ FIELD_CASE(SFixed32, intValue)
+ FIELD_CASE(SInt32, intValue)
+ FIELD_CASE(Enum, intValue)
+ FIELD_CASE(Int64, longLongValue)
+ FIELD_CASE(SInt64, longLongValue)
+ FIELD_CASE(SFixed64, longLongValue)
+ FIELD_CASE(UInt32, unsignedIntValue)
+ FIELD_CASE(Fixed32, unsignedIntValue)
+ FIELD_CASE(UInt64, unsignedLongLongValue)
+ FIELD_CASE(Fixed64, unsignedLongLongValue)
+ FIELD_CASE2(Bytes)
+ FIELD_CASE2(String)
+ FIELD_CASE2(Group)
+ case GPBDataTypeMessage:
+ if (GPBExtensionIsWireFormat(description)) {
+ [output writeMessageSetExtension:description->fieldNumber value:object];
+ } else {
+ [output writeMessage:description->fieldNumber value:object];
+ }
+ return;
+ }
+#undef FIELD_CASE
+#undef FIELD_CASE2
+}
+
+static void WriteObjectNoTagToCodedOutputStream(
+ id object, GPBExtensionDescription *description,
+ GPBCodedOutputStream *output) {
+#define FIELD_CASE(TYPE, ACCESSOR) \
+ case GPBDataType##TYPE: \
+ [output write##TYPE##NoTag:[(NSNumber *)object ACCESSOR]]; \
+ return;
+#define FIELD_CASE2(TYPE) \
+ case GPBDataType##TYPE: \
+ [output write##TYPE##NoTag:object]; \
+ return;
+ switch (description->dataType) {
+ FIELD_CASE(Bool, boolValue)
+ FIELD_CASE(Float, floatValue)
+ FIELD_CASE(Double, doubleValue)
+ FIELD_CASE(Int32, intValue)
+ FIELD_CASE(SFixed32, intValue)
+ FIELD_CASE(SInt32, intValue)
+ FIELD_CASE(Enum, intValue)
+ FIELD_CASE(Int64, longLongValue)
+ FIELD_CASE(SInt64, longLongValue)
+ FIELD_CASE(SFixed64, longLongValue)
+ FIELD_CASE(UInt32, unsignedIntValue)
+ FIELD_CASE(Fixed32, unsignedIntValue)
+ FIELD_CASE(UInt64, unsignedLongLongValue)
+ FIELD_CASE(Fixed64, unsignedLongLongValue)
+ FIELD_CASE2(Bytes)
+ FIELD_CASE2(String)
+ FIELD_CASE2(Message)
+ case GPBDataTypeGroup:
+ [output writeGroupNoTag:description->fieldNumber value:object];
+ return;
+ }
+#undef FIELD_CASE
+#undef FIELD_CASE2
+}
+
+static void WriteArrayIncludingTagsToCodedOutputStream(
+ NSArray *values, GPBExtensionDescription *description,
+ GPBCodedOutputStream *output) {
+ if (GPBExtensionIsPacked(description)) {
+ [output writeTag:description->fieldNumber
+ format:GPBWireFormatLengthDelimited];
+ size_t dataSize = 0;
+ size_t typeSize = DataTypeSize(description->dataType);
+ if (typeSize != 0) {
+ dataSize = values.count * typeSize;
+ } else {
+ for (id value in values) {
+ dataSize +=
+ ComputePBSerializedSizeNoTagOfObject(description->dataType, value);
+ }
+ }
+ [output writeRawVarintSizeTAs32:dataSize];
+ for (id value in values) {
+ WriteObjectNoTagToCodedOutputStream(value, description, output);
+ }
+ } else {
+ for (id value in values) {
+ WriteObjectIncludingTagToCodedOutputStream(value, description, output);
+ }
+ }
+}
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension,
+ BOOL isPackedOnStream,
+ GPBCodedInputStream *input,
+ GPBExtensionRegistry *extensionRegistry,
+ GPBMessage *message) {
+ GPBExtensionDescription *description = extension->description_;
+ GPBCodedInputStreamState *state = &input->state_;
+ if (isPackedOnStream) {
+ NSCAssert(GPBExtensionIsRepeated(description),
+ @"How was it packed if it isn't repeated?");
+ int32_t length = GPBCodedInputStreamReadInt32(state);
+ size_t limit = GPBCodedInputStreamPushLimit(state, length);
+ while (GPBCodedInputStreamBytesUntilLimit(state) > 0) {
+ id value = NewSingleValueFromInputStream(extension,
+ input,
+ extensionRegistry,
+ nil);
+ [message addExtension:extension value:value];
+ [value release];
+ }
+ GPBCodedInputStreamPopLimit(state, limit);
+ } else {
+ id existingValue = nil;
+ BOOL isRepeated = GPBExtensionIsRepeated(description);
+ if (!isRepeated && GPBDataTypeIsMessage(description->dataType)) {
+ existingValue = [message getExistingExtension:extension];
+ }
+ id value = NewSingleValueFromInputStream(extension,
+ input,
+ extensionRegistry,
+ existingValue);
+ if (isRepeated) {
+ [message addExtension:extension value:value];
+ } else {
+ [message setExtension:extension value:value];
+ }
+ [value release];
+ }
+}
+
+void GPBWriteExtensionValueToOutputStream(GPBExtensionDescriptor *extension,
+ id value,
+ GPBCodedOutputStream *output) {
+ GPBExtensionDescription *description = extension->description_;
+ if (GPBExtensionIsRepeated(description)) {
+ WriteArrayIncludingTagsToCodedOutputStream(value, description, output);
+ } else {
+ WriteObjectIncludingTagToCodedOutputStream(value, description, output);
+ }
+}
+
+size_t GPBComputeExtensionSerializedSizeIncludingTag(
+ GPBExtensionDescriptor *extension, id value) {
+ GPBExtensionDescription *description = extension->description_;
+ if (GPBExtensionIsRepeated(description)) {
+ return ComputeSerializedSizeIncludingTagOfArray(description, value);
+ } else {
+ return ComputeSerializedSizeIncludingTagOfObject(description, value);
+ }
+}
+
+// Note that this returns a retained value intentionally.
+static id NewSingleValueFromInputStream(GPBExtensionDescriptor *extension,
+ GPBCodedInputStream *input,
+ GPBExtensionRegistry *extensionRegistry,
+ GPBMessage *existingValue) {
+ GPBExtensionDescription *description = extension->description_;
+ GPBCodedInputStreamState *state = &input->state_;
+ switch (description->dataType) {
+ case GPBDataTypeBool: return [[NSNumber alloc] initWithBool:GPBCodedInputStreamReadBool(state)];
+ case GPBDataTypeFixed32: return [[NSNumber alloc] initWithUnsignedInt:GPBCodedInputStreamReadFixed32(state)];
+ case GPBDataTypeSFixed32: return [[NSNumber alloc] initWithInt:GPBCodedInputStreamReadSFixed32(state)];
+ case GPBDataTypeFloat: return [[NSNumber alloc] initWithFloat:GPBCodedInputStreamReadFloat(state)];
+ case GPBDataTypeFixed64: return [[NSNumber alloc] initWithUnsignedLongLong:GPBCodedInputStreamReadFixed64(state)];
+ case GPBDataTypeSFixed64: return [[NSNumber alloc] initWithLongLong:GPBCodedInputStreamReadSFixed64(state)];
+ case GPBDataTypeDouble: return [[NSNumber alloc] initWithDouble:GPBCodedInputStreamReadDouble(state)];
+ case GPBDataTypeInt32: return [[NSNumber alloc] initWithInt:GPBCodedInputStreamReadInt32(state)];
+ case GPBDataTypeInt64: return [[NSNumber alloc] initWithLongLong:GPBCodedInputStreamReadInt64(state)];
+ case GPBDataTypeSInt32: return [[NSNumber alloc] initWithInt:GPBCodedInputStreamReadSInt32(state)];
+ case GPBDataTypeSInt64: return [[NSNumber alloc] initWithLongLong:GPBCodedInputStreamReadSInt64(state)];
+ case GPBDataTypeUInt32: return [[NSNumber alloc] initWithUnsignedInt:GPBCodedInputStreamReadUInt32(state)];
+ case GPBDataTypeUInt64: return [[NSNumber alloc] initWithUnsignedLongLong:GPBCodedInputStreamReadUInt64(state)];
+ case GPBDataTypeBytes: return GPBCodedInputStreamReadRetainedBytes(state);
+ case GPBDataTypeString: return GPBCodedInputStreamReadRetainedString(state);
+ case GPBDataTypeEnum: return [[NSNumber alloc] initWithInt:GPBCodedInputStreamReadEnum(state)];
+ case GPBDataTypeGroup:
+ case GPBDataTypeMessage: {
+ GPBMessage *message;
+ if (existingValue) {
+ message = [existingValue retain];
+ } else {
+ GPBDescriptor *decriptor = [extension.msgClass descriptor];
+ message = [[decriptor.messageClass alloc] init];
+ }
+
+ if (description->dataType == GPBDataTypeGroup) {
+ [input readGroup:description->fieldNumber
+ message:message
+ extensionRegistry:extensionRegistry];
+ } else {
+ // description->dataType == GPBDataTypeMessage
+ if (GPBExtensionIsWireFormat(description)) {
+ // For MessageSet fields the message length will have already been
+ // read.
+ [message mergeFromCodedInputStream:input
+ extensionRegistry:extensionRegistry];
+ } else {
+ [input readMessage:message extensionRegistry:extensionRegistry];
+ }
+ }
+
+ return message;
+ }
+ }
+
+ return nil;
+}
+
+#pragma clang diagnostic pop
diff --git a/third_party/protobuf/objectivec/GPBExtensionRegistry.h b/third_party/protobuf/objectivec/GPBExtensionRegistry.h
new file mode 100644
index 0000000000..d79632d28b
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBExtensionRegistry.h
@@ -0,0 +1,87 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+@class GPBDescriptor;
+@class GPBExtensionDescriptor;
+
+NS_ASSUME_NONNULL_BEGIN
+
+/**
+ * A table of known extensions, searchable by name or field number. When
+ * parsing a protocol message that might have extensions, you must provide a
+ * GPBExtensionRegistry in which you have registered any extensions that you
+ * want to be able to parse. Otherwise, those extensions will just be treated
+ * like unknown fields.
+ *
+ * The *Root classes provide `+extensionRegistry` for the extensions defined
+ * in a given file *and* all files it imports. You can also create a
+ * GPBExtensionRegistry, and merge those registries to handle parsing
+ * extensions defined from non overlapping files.
+ *
+ * ```
+ * GPBExtensionRegistry *registry = [[MyProtoFileRoot extensionRegistry] copy];
+ * [registry addExtension:[OtherMessage neededExtension]]; // Not in MyProtoFile
+ * NSError *parseError;
+ * MyMessage *msg = [MyMessage parseData:data extensionRegistry:registry error:&parseError];
+ * ```
+ **/
+@interface GPBExtensionRegistry : NSObject<NSCopying>
+
+/**
+ * Adds the given GPBExtensionDescriptor to this registry.
+ *
+ * @param extension The extension description to add.
+ **/
+- (void)addExtension:(GPBExtensionDescriptor *)extension;
+
+/**
+ * Adds all the extensions from another registry to this registry.
+ *
+ * @param registry The registry to merge into this registry.
+ **/
+- (void)addExtensions:(GPBExtensionRegistry *)registry;
+
+/**
+ * Looks for the extension registered for the given field number on a given
+ * GPBDescriptor.
+ *
+ * @param descriptor The descriptor to look for a registered extension on.
+ * @param fieldNumber The field number of the extension to look for.
+ *
+ * @return The registered GPBExtensionDescriptor or nil if none was found.
+ **/
+- (nullable GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor
+ fieldNumber:(NSInteger)fieldNumber;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBExtensionRegistry.m b/third_party/protobuf/objectivec/GPBExtensionRegistry.m
new file mode 100644
index 0000000000..65534b67af
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBExtensionRegistry.m
@@ -0,0 +1,131 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBExtensionRegistry.h"
+
+#import "GPBBootstrap.h"
+#import "GPBDescriptor.h"
+
+@implementation GPBExtensionRegistry {
+ NSMutableDictionary *mutableClassMap_;
+}
+
+- (instancetype)init {
+ if ((self = [super init])) {
+ mutableClassMap_ = [[NSMutableDictionary alloc] init];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [mutableClassMap_ release];
+ [super dealloc];
+}
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+- (instancetype)copyWithZone:(NSZone *)zone {
+ GPBExtensionRegistry *result = [[[self class] allocWithZone:zone] init];
+ if (result && mutableClassMap_.count) {
+ [result->mutableClassMap_ addEntriesFromDictionary:mutableClassMap_];
+ }
+ return result;
+}
+
+- (CFMutableDictionaryRef)extensionMapForContainingMessageClass:
+ (Class)containingMessageClass {
+ CFMutableDictionaryRef extensionMap = (CFMutableDictionaryRef)
+ [mutableClassMap_ objectForKey:containingMessageClass];
+ if (extensionMap == nil) {
+ // Use a custom dictionary here because the keys are numbers and conversion
+ // back and forth from NSNumber isn't worth the cost.
+ extensionMap = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL,
+ &kCFTypeDictionaryValueCallBacks);
+ [mutableClassMap_ setObject:(id)extensionMap
+ forKey:(id<NSCopying>)containingMessageClass];
+ }
+ return extensionMap;
+}
+
+- (void)addExtension:(GPBExtensionDescriptor *)extension {
+ if (extension == nil) {
+ return;
+ }
+
+ Class containingMessageClass = extension.containingMessageClass;
+ CFMutableDictionaryRef extensionMap =
+ [self extensionMapForContainingMessageClass:containingMessageClass];
+ ssize_t key = extension.fieldNumber;
+ CFDictionarySetValue(extensionMap, (const void *)key, extension);
+}
+
+- (GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor
+ fieldNumber:(NSInteger)fieldNumber {
+ Class messageClass = descriptor.messageClass;
+ CFMutableDictionaryRef extensionMap = (CFMutableDictionaryRef)
+ [mutableClassMap_ objectForKey:messageClass];
+ ssize_t key = fieldNumber;
+ GPBExtensionDescriptor *result =
+ (extensionMap
+ ? CFDictionaryGetValue(extensionMap, (const void *)key)
+ : nil);
+ return result;
+}
+
+static void CopyKeyValue(const void *key, const void *value, void *context) {
+ CFMutableDictionaryRef extensionMap = (CFMutableDictionaryRef)context;
+ CFDictionarySetValue(extensionMap, key, value);
+}
+
+- (void)addExtensions:(GPBExtensionRegistry *)registry {
+ if (registry == nil) {
+ // In the case where there are no extensions just ignore.
+ return;
+ }
+ NSMutableDictionary *otherClassMap = registry->mutableClassMap_;
+ [otherClassMap enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL * stop) {
+#pragma unused(stop)
+ Class containingMessageClass = key;
+ CFMutableDictionaryRef otherExtensionMap = (CFMutableDictionaryRef)value;
+
+ CFMutableDictionaryRef extensionMap =
+ [self extensionMapForContainingMessageClass:containingMessageClass];
+
+ CFDictionaryApplyFunction(otherExtensionMap, CopyKeyValue, extensionMap);
+ }];
+}
+
+#pragma clang diagnostic pop
+
+@end
diff --git a/third_party/protobuf/objectivec/GPBMessage.h b/third_party/protobuf/objectivec/GPBMessage.h
new file mode 100644
index 0000000000..2c325ba85b
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBMessage.h
@@ -0,0 +1,461 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBBootstrap.h"
+
+@class GPBDescriptor;
+@class GPBCodedInputStream;
+@class GPBCodedOutputStream;
+@class GPBExtensionDescriptor;
+@class GPBExtensionRegistry;
+@class GPBFieldDescriptor;
+@class GPBUnknownFieldSet;
+
+NS_ASSUME_NONNULL_BEGIN
+
+CF_EXTERN_C_BEGIN
+
+/** NSError domain used for errors. */
+extern NSString *const GPBMessageErrorDomain;
+
+/** Error codes for NSErrors originated in GPBMessage. */
+typedef NS_ENUM(NSInteger, GPBMessageErrorCode) {
+ /** Uncategorized error. */
+ GPBMessageErrorCodeOther = -100,
+ /** Message couldn't be serialized because it is missing required fields. */
+ GPBMessageErrorCodeMissingRequiredField = -101,
+};
+
+/**
+ * Key under which the GPBMessage error's reason is stored inside the userInfo
+ * dictionary.
+ **/
+extern NSString *const GPBErrorReasonKey;
+
+CF_EXTERN_C_END
+
+/**
+ * Base class that each generated message subclasses from.
+ *
+ * @note @c NSCopying support is a "deep copy", in that all sub objects are
+ * copied. Just like you wouldn't want a UIView/NSView trying to
+ * exist in two places, you don't want a sub message to be a property
+ * property of two other messages.
+ *
+ * @note While the class support NSSecureCoding, if the message has any
+ * extensions, they will end up reloaded in @c unknownFields as there is
+ * no way for the @c NSCoding plumbing to pass through a
+ * @c GPBExtensionRegistry. To support extensions, instead of passing the
+ * calls off to the Message, simple store the result of @c data, and then
+ * when loading, fetch the data and use
+ * @c +parseFromData:extensionRegistry:error: to provide an extension
+ * registry.
+ **/
+@interface GPBMessage : NSObject<NSSecureCoding, NSCopying>
+
+// If you add an instance method/property to this class that may conflict with
+// fields declared in protos, you need to update objective_helpers.cc. The main
+// cases are methods that take no arguments, or setFoo:/hasFoo: type methods.
+
+/**
+ * The set of unknown fields for this message.
+ *
+ * Only messages from proto files declared with "proto2" syntax support unknown
+ * fields. For "proto3" syntax, any unknown fields found while parsing are
+ * dropped.
+ **/
+@property(nonatomic, copy, nullable) GPBUnknownFieldSet *unknownFields;
+
+/**
+ * Whether the message, along with all submessages, have the required fields
+ * set. This is only applicable for files declared with "proto2" syntax, as
+ * there are no required fields for "proto3" syntax.
+ **/
+@property(nonatomic, readonly, getter=isInitialized) BOOL initialized;
+
+/**
+ * @return An autoreleased message with the default values set.
+ **/
++ (instancetype)message;
+
+/**
+ * Creates a new instance by parsing the provided data. This method should be
+ * sent to the generated message class that the data should be interpreted as.
+ * If there is an error the method returns nil and the error is returned in
+ * errorPtr (when provided).
+ *
+ * @note In DEBUG builds, the parsed message is checked to be sure all required
+ * fields were provided, and the parse will fail if some are missing.
+ *
+ * @note The errors returned are likely coming from the domain and codes listed
+ * at the top of this file and GPBCodedInputStream.h.
+ *
+ * @param data The data to parse.
+ * @param errorPtr An optional error pointer to fill in with a failure reason if
+ * the data can not be parsed.
+ *
+ * @return A new instance of the generated class.
+ **/
++ (nullable instancetype)parseFromData:(NSData *)data error:(NSError **)errorPtr;
+
+/**
+ * Creates a new instance by parsing the data. This method should be sent to
+ * the generated message class that the data should be interpreted as. If
+ * there is an error the method returns nil and the error is returned in
+ * errorPtr (when provided).
+ *
+ * @note In DEBUG builds, the parsed message is checked to be sure all required
+ * fields were provided, and the parse will fail if some are missing.
+ *
+ * @note The errors returned are likely coming from the domain and codes listed
+ * at the top of this file and GPBCodedInputStream.h.
+ *
+ * @param data The data to parse.
+ * @param extensionRegistry The extension registry to use to look up extensions.
+ * @param errorPtr An optional error pointer to fill in with a failure
+ * reason if the data can not be parsed.
+ *
+ * @return A new instance of the generated class.
+ **/
++ (nullable instancetype)parseFromData:(NSData *)data
+ extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr;
+
+/**
+ * Creates a new instance by parsing the data from the given input stream. This
+ * method should be sent to the generated message class that the data should
+ * be interpreted as. If there is an error the method returns nil and the error
+ * is returned in errorPtr (when provided).
+ *
+ * @note In DEBUG builds, the parsed message is checked to be sure all required
+ * fields were provided, and the parse will fail if some are missing.
+ *
+ * @note The errors returned are likely coming from the domain and codes listed
+ * at the top of this file and GPBCodedInputStream.h.
+ *
+ * @param input The stream to read data from.
+ * @param extensionRegistry The extension registry to use to look up extensions.
+ * @param errorPtr An optional error pointer to fill in with a failure
+ * reason if the data can not be parsed.
+ *
+ * @return A new instance of the generated class.
+ **/
++ (nullable instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:
+ (nullable GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr;
+
+/**
+ * Creates a new instance by parsing the data from the given input stream. This
+ * method should be sent to the generated message class that the data should
+ * be interpreted as. If there is an error the method returns nil and the error
+ * is returned in errorPtr (when provided).
+ *
+ * @note Unlike the parseFrom... methods, this never checks to see if all of
+ * the required fields are set. So this method can be used to reload
+ * messages that may not be complete.
+ *
+ * @note The errors returned are likely coming from the domain and codes listed
+ * at the top of this file and GPBCodedInputStream.h.
+ *
+ * @param input The stream to read data from.
+ * @param extensionRegistry The extension registry to use to look up extensions.
+ * @param errorPtr An optional error pointer to fill in with a failure
+ * reason if the data can not be parsed.
+ *
+ * @return A new instance of the generated class.
+ **/
++ (nullable instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:
+ (nullable GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr;
+
+/**
+ * Initializes an instance by parsing the data. This method should be sent to
+ * the generated message class that the data should be interpreted as. If
+ * there is an error the method returns nil and the error is returned in
+ * errorPtr (when provided).
+ *
+ * @note In DEBUG builds, the parsed message is checked to be sure all required
+ * fields were provided, and the parse will fail if some are missing.
+ *
+ * @note The errors returned are likely coming from the domain and codes listed
+ * at the top of this file and GPBCodedInputStream.h.
+ *
+ * @param data The data to parse.
+ * @param errorPtr An optional error pointer to fill in with a failure reason if
+ * the data can not be parsed.
+ *
+ * @return An initialized instance of the generated class.
+ **/
+- (nullable instancetype)initWithData:(NSData *)data error:(NSError **)errorPtr;
+
+/**
+ * Initializes an instance by parsing the data. This method should be sent to
+ * the generated message class that the data should be interpreted as. If
+ * there is an error the method returns nil and the error is returned in
+ * errorPtr (when provided).
+ *
+ * @note In DEBUG builds, the parsed message is checked to be sure all required
+ * fields were provided, and the parse will fail if some are missing.
+ *
+ * @note The errors returned are likely coming from the domain and codes listed
+ * at the top of this file and GPBCodedInputStream.h.
+ *
+ * @param data The data to parse.
+ * @param extensionRegistry The extension registry to use to look up extensions.
+ * @param errorPtr An optional error pointer to fill in with a failure
+ * reason if the data can not be parsed.
+ *
+ * @return An initialized instance of the generated class.
+ **/
+- (nullable instancetype)initWithData:(NSData *)data
+ extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr;
+
+/**
+ * Initializes an instance by parsing the data from the given input stream. This
+ * method should be sent to the generated message class that the data should
+ * be interpreted as. If there is an error the method returns nil and the error
+ * is returned in errorPtr (when provided).
+ *
+ * @note Unlike the parseFrom... methods, this never checks to see if all of
+ * the required fields are set. So this method can be used to reload
+ * messages that may not be complete.
+ *
+ * @note The errors returned are likely coming from the domain and codes listed
+ * at the top of this file and GPBCodedInputStream.h.
+ *
+ * @param input The stream to read data from.
+ * @param extensionRegistry The extension registry to use to look up extensions.
+ * @param errorPtr An optional error pointer to fill in with a failure
+ * reason if the data can not be parsed.
+ *
+ * @return An initialized instance of the generated class.
+ **/
+- (nullable instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:
+ (nullable GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr;
+
+/**
+ * Parses the given data as this message's class, and merges those values into
+ * this message.
+ *
+ * @param data The binary representation of the message to merge.
+ * @param extensionRegistry The extension registry to use to look up extensions.
+ *
+ * @exception GPBCodedInputStreamException Exception thrown when parsing was
+ * unsuccessful.
+ **/
+- (void)mergeFromData:(NSData *)data
+ extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry;
+
+/**
+ * Merges the fields from another message (of the same type) into this
+ * message.
+ *
+ * @param other Message to merge into this message.
+ **/
+- (void)mergeFrom:(GPBMessage *)other;
+
+/**
+ * Writes out the message to the given coded output stream.
+ *
+ * @param output The coded output stream into which to write the message.
+ **/
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output;
+
+/**
+ * Writes out the message to the given output stream.
+ *
+ * @param output The output stream into which to write the message.
+ **/
+- (void)writeToOutputStream:(NSOutputStream *)output;
+
+/**
+ * Writes out a varint for the message size followed by the the message to
+ * the given output stream.
+ *
+ * @param output The coded output stream into which to write the message.
+ **/
+- (void)writeDelimitedToCodedOutputStream:(GPBCodedOutputStream *)output;
+
+/**
+ * Writes out a varint for the message size followed by the the message to
+ * the given output stream.
+ *
+ * @param output The output stream into which to write the message.
+ **/
+- (void)writeDelimitedToOutputStream:(NSOutputStream *)output;
+
+/**
+ * Serializes the message to an NSData.
+ *
+ * If there is an error while generating the data, nil is returned.
+ *
+ * @note This value is not cached, so if you are using it repeatedly, cache
+ * it yourself.
+ *
+ * @note In DEBUG ONLY, the message is also checked for all required field,
+ * if one is missing, nil will be returned.
+ *
+ * @return The binary representation of the message.
+ **/
+- (nullable NSData *)data;
+
+/**
+ * Serializes a varint with the message size followed by the message data,
+ * returning that as an NSData.
+ *
+ * @note This value is not cached, so if you are using it repeatedly, it is
+ * recommended to keep a local copy.
+ *
+ * @return The binary representation of the size along with the message.
+ **/
+- (NSData *)delimitedData;
+
+/**
+ * Calculates the size of the object if it were serialized.
+ *
+ * This is not a cached value. If you are following a pattern like this:
+ *
+ * ```
+ * size_t size = [aMsg serializedSize];
+ * NSMutableData *foo = [NSMutableData dataWithCapacity:size + sizeof(size)];
+ * [foo writeSize:size];
+ * [foo appendData:[aMsg data]];
+ * ```
+ *
+ * you would be better doing:
+ *
+ * ```
+ * NSData *data = [aMsg data];
+ * NSUInteger size = [aMsg length];
+ * NSMutableData *foo = [NSMutableData dataWithCapacity:size + sizeof(size)];
+ * [foo writeSize:size];
+ * [foo appendData:data];
+ * ```
+ *
+ * @return The size of the message in it's binary representation.
+ **/
+- (size_t)serializedSize;
+
+/**
+ * @return The descriptor for the message class.
+ **/
++ (GPBDescriptor *)descriptor;
+
+/**
+ * Return the descriptor for the message.
+ **/
+- (GPBDescriptor *)descriptor;
+
+/**
+ * @return An array with the extension descriptors that are currently set on the
+ * message.
+ **/
+- (NSArray *)extensionsCurrentlySet;
+
+/**
+ * Checks whether there is an extension set on the message which matches the
+ * given extension descriptor.
+ *
+ * @param extension Extension descriptor to check if it's set on the message.
+ *
+ * @return Whether the extension is currently set on the message.
+ **/
+- (BOOL)hasExtension:(GPBExtensionDescriptor *)extension;
+
+/*
+ * Fetches the given extension's value for this message.
+ *
+ * Extensions use boxed values (NSNumbers) for PODs and NSMutableArrays for
+ * repeated fields. If the extension is a Message one will be auto created for
+ * you and returned similar to fields.
+ *
+ * @param extension The extension descriptor of the extension to fetch.
+ *
+ * @return The extension matching the given descriptor, or nil if none found.
+ **/
+- (nullable id)getExtension:(GPBExtensionDescriptor *)extension;
+
+/**
+ * Sets the given extension's value for this message. This only applies for
+ * single field extensions (i.e. - not repeated fields).
+ *
+ * Extensions use boxed values (NSNumbers).
+ *
+ * @param extension The extension descriptor under which to set the value.
+ * @param value The value to be set as the extension.
+ **/
+- (void)setExtension:(GPBExtensionDescriptor *)extension
+ value:(nullable id)value;
+
+/**
+ * Adds the given value to the extension for this message. This only applies
+ * to repeated field extensions. If the field is a repeated POD type, the value
+ * should be an NSNumber.
+ *
+ * @param extension The extension descriptor under which to add the value.
+ * @param value The value to be added to the repeated extension.
+ **/
+- (void)addExtension:(GPBExtensionDescriptor *)extension value:(id)value;
+
+/**
+ * Replaces the value at the given index with the given value for the extension
+ * on this message. This only applies to repeated field extensions. If the field
+ * is a repeated POD type, the value is should be an NSNumber.
+ *
+ * @param extension The extension descriptor under which to replace the value.
+ * @param index The index of the extension to be replaced.
+ * @param value The value to be replaced in the repeated extension.
+ **/
+- (void)setExtension:(GPBExtensionDescriptor *)extension
+ index:(NSUInteger)index
+ value:(id)value;
+
+/**
+ * Clears the given extension for this message.
+ *
+ * @param extension The extension descriptor to be cleared from this message.
+ **/
+- (void)clearExtension:(GPBExtensionDescriptor *)extension;
+
+/**
+ * Resets all of the fields of this message to their default values.
+ **/
+- (void)clear;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBMessage.m b/third_party/protobuf/objectivec/GPBMessage.m
new file mode 100644
index 0000000000..58a10fdb9b
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBMessage.m
@@ -0,0 +1,3243 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBMessage_PackagePrivate.h"
+
+#import <objc/runtime.h>
+#import <objc/message.h>
+
+#import "GPBArray_PackagePrivate.h"
+#import "GPBCodedInputStream_PackagePrivate.h"
+#import "GPBCodedOutputStream_PackagePrivate.h"
+#import "GPBDescriptor_PackagePrivate.h"
+#import "GPBDictionary_PackagePrivate.h"
+#import "GPBExtensionInternals.h"
+#import "GPBExtensionRegistry.h"
+#import "GPBRootObject_PackagePrivate.h"
+#import "GPBUnknownFieldSet_PackagePrivate.h"
+#import "GPBUtilities_PackagePrivate.h"
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+NSString *const GPBMessageErrorDomain =
+ GPBNSStringifySymbol(GPBMessageErrorDomain);
+
+NSString *const GPBErrorReasonKey = @"Reason";
+
+static NSString *const kGPBDataCoderKey = @"GPBData";
+
+//
+// PLEASE REMEMBER:
+//
+// This is the base class for *all* messages generated, so any selector defined,
+// *public* or *private* could end up colliding with a proto message field. So
+// avoid using selectors that could match a property, use C functions to hide
+// them, etc.
+//
+
+@interface GPBMessage () {
+ @package
+ GPBUnknownFieldSet *unknownFields_;
+ NSMutableDictionary *extensionMap_;
+ NSMutableDictionary *autocreatedExtensionMap_;
+
+ // If the object was autocreated, we remember the creator so that if we get
+ // mutated, we can inform the creator to make our field visible.
+ GPBMessage *autocreator_;
+ GPBFieldDescriptor *autocreatorField_;
+ GPBExtensionDescriptor *autocreatorExtension_;
+}
+@end
+
+static id CreateArrayForField(GPBFieldDescriptor *field,
+ GPBMessage *autocreator)
+ __attribute__((ns_returns_retained));
+static id GetOrCreateArrayIvarWithField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ GPBFileSyntax syntax);
+static id GetArrayIvarWithField(GPBMessage *self, GPBFieldDescriptor *field);
+static id CreateMapForField(GPBFieldDescriptor *field,
+ GPBMessage *autocreator)
+ __attribute__((ns_returns_retained));
+static id GetOrCreateMapIvarWithField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ GPBFileSyntax syntax);
+static id GetMapIvarWithField(GPBMessage *self, GPBFieldDescriptor *field);
+static NSMutableDictionary *CloneExtensionMap(NSDictionary *extensionMap,
+ NSZone *zone)
+ __attribute__((ns_returns_retained));
+
+#ifdef DEBUG
+static NSError *MessageError(NSInteger code, NSDictionary *userInfo) {
+ return [NSError errorWithDomain:GPBMessageErrorDomain
+ code:code
+ userInfo:userInfo];
+}
+#endif
+
+static NSError *ErrorFromException(NSException *exception) {
+ NSError *error = nil;
+
+ if ([exception.name isEqual:GPBCodedInputStreamException]) {
+ NSDictionary *exceptionInfo = exception.userInfo;
+ error = exceptionInfo[GPBCodedInputStreamUnderlyingErrorKey];
+ }
+
+ if (!error) {
+ NSString *reason = exception.reason;
+ NSDictionary *userInfo = nil;
+ if ([reason length]) {
+ userInfo = @{ GPBErrorReasonKey : reason };
+ }
+
+ error = [NSError errorWithDomain:GPBMessageErrorDomain
+ code:GPBMessageErrorCodeOther
+ userInfo:userInfo];
+ }
+ return error;
+}
+
+static void CheckExtension(GPBMessage *self,
+ GPBExtensionDescriptor *extension) {
+ if ([self class] != extension.containingMessageClass) {
+ [NSException
+ raise:NSInvalidArgumentException
+ format:@"Extension %@ used on wrong class (%@ instead of %@)",
+ extension.singletonName,
+ [self class], extension.containingMessageClass];
+ }
+}
+
+static NSMutableDictionary *CloneExtensionMap(NSDictionary *extensionMap,
+ NSZone *zone) {
+ if (extensionMap.count == 0) {
+ return nil;
+ }
+ NSMutableDictionary *result = [[NSMutableDictionary allocWithZone:zone]
+ initWithCapacity:extensionMap.count];
+
+ for (GPBExtensionDescriptor *extension in extensionMap) {
+ id value = [extensionMap objectForKey:extension];
+ BOOL isMessageExtension = GPBExtensionIsMessage(extension);
+
+ if (extension.repeated) {
+ if (isMessageExtension) {
+ NSMutableArray *list =
+ [[NSMutableArray alloc] initWithCapacity:[value count]];
+ for (GPBMessage *listValue in value) {
+ GPBMessage *copiedValue = [listValue copyWithZone:zone];
+ [list addObject:copiedValue];
+ [copiedValue release];
+ }
+ [result setObject:list forKey:extension];
+ [list release];
+ } else {
+ NSMutableArray *copiedValue = [value mutableCopyWithZone:zone];
+ [result setObject:copiedValue forKey:extension];
+ [copiedValue release];
+ }
+ } else {
+ if (isMessageExtension) {
+ GPBMessage *copiedValue = [value copyWithZone:zone];
+ [result setObject:copiedValue forKey:extension];
+ [copiedValue release];
+ } else {
+ [result setObject:value forKey:extension];
+ }
+ }
+ }
+
+ return result;
+}
+
+static id CreateArrayForField(GPBFieldDescriptor *field,
+ GPBMessage *autocreator) {
+ id result;
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ switch (fieldDataType) {
+ case GPBDataTypeBool:
+ result = [[GPBBoolArray alloc] init];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ result = [[GPBUInt32Array alloc] init];
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ result = [[GPBInt32Array alloc] init];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ result = [[GPBUInt64Array alloc] init];
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ result = [[GPBInt64Array alloc] init];
+ break;
+ case GPBDataTypeFloat:
+ result = [[GPBFloatArray alloc] init];
+ break;
+ case GPBDataTypeDouble:
+ result = [[GPBDoubleArray alloc] init];
+ break;
+
+ case GPBDataTypeEnum:
+ result = [[GPBEnumArray alloc]
+ initWithValidationFunction:field.enumDescriptor.enumVerifier];
+ break;
+
+ case GPBDataTypeBytes:
+ case GPBDataTypeGroup:
+ case GPBDataTypeMessage:
+ case GPBDataTypeString:
+ if (autocreator) {
+ result = [[GPBAutocreatedArray alloc] init];
+ } else {
+ result = [[NSMutableArray alloc] init];
+ }
+ break;
+ }
+
+ if (autocreator) {
+ if (GPBDataTypeIsObject(fieldDataType)) {
+ GPBAutocreatedArray *autoArray = result;
+ autoArray->_autocreator = autocreator;
+ } else {
+ GPBInt32Array *gpbArray = result;
+ gpbArray->_autocreator = autocreator;
+ }
+ }
+
+ return result;
+}
+
+static id CreateMapForField(GPBFieldDescriptor *field,
+ GPBMessage *autocreator) {
+ id result;
+ GPBDataType keyDataType = field.mapKeyDataType;
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ switch (keyDataType) {
+ case GPBDataTypeBool:
+ switch (valueDataType) {
+ case GPBDataTypeBool:
+ result = [[GPBBoolBoolDictionary alloc] init];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ result = [[GPBBoolUInt32Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ result = [[GPBBoolInt32Dictionary alloc] init];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ result = [[GPBBoolUInt64Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ result = [[GPBBoolInt64Dictionary alloc] init];
+ break;
+ case GPBDataTypeFloat:
+ result = [[GPBBoolFloatDictionary alloc] init];
+ break;
+ case GPBDataTypeDouble:
+ result = [[GPBBoolDoubleDictionary alloc] init];
+ break;
+ case GPBDataTypeEnum:
+ result = [[GPBBoolEnumDictionary alloc]
+ initWithValidationFunction:field.enumDescriptor.enumVerifier];
+ break;
+ case GPBDataTypeBytes:
+ case GPBDataTypeMessage:
+ case GPBDataTypeString:
+ result = [[GPBBoolObjectDictionary alloc] init];
+ break;
+ case GPBDataTypeGroup:
+ NSCAssert(NO, @"shouldn't happen");
+ return nil;
+ }
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ switch (valueDataType) {
+ case GPBDataTypeBool:
+ result = [[GPBUInt32BoolDictionary alloc] init];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ result = [[GPBUInt32UInt32Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ result = [[GPBUInt32Int32Dictionary alloc] init];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ result = [[GPBUInt32UInt64Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ result = [[GPBUInt32Int64Dictionary alloc] init];
+ break;
+ case GPBDataTypeFloat:
+ result = [[GPBUInt32FloatDictionary alloc] init];
+ break;
+ case GPBDataTypeDouble:
+ result = [[GPBUInt32DoubleDictionary alloc] init];
+ break;
+ case GPBDataTypeEnum:
+ result = [[GPBUInt32EnumDictionary alloc]
+ initWithValidationFunction:field.enumDescriptor.enumVerifier];
+ break;
+ case GPBDataTypeBytes:
+ case GPBDataTypeMessage:
+ case GPBDataTypeString:
+ result = [[GPBUInt32ObjectDictionary alloc] init];
+ break;
+ case GPBDataTypeGroup:
+ NSCAssert(NO, @"shouldn't happen");
+ return nil;
+ }
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ switch (valueDataType) {
+ case GPBDataTypeBool:
+ result = [[GPBInt32BoolDictionary alloc] init];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ result = [[GPBInt32UInt32Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ result = [[GPBInt32Int32Dictionary alloc] init];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ result = [[GPBInt32UInt64Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ result = [[GPBInt32Int64Dictionary alloc] init];
+ break;
+ case GPBDataTypeFloat:
+ result = [[GPBInt32FloatDictionary alloc] init];
+ break;
+ case GPBDataTypeDouble:
+ result = [[GPBInt32DoubleDictionary alloc] init];
+ break;
+ case GPBDataTypeEnum:
+ result = [[GPBInt32EnumDictionary alloc]
+ initWithValidationFunction:field.enumDescriptor.enumVerifier];
+ break;
+ case GPBDataTypeBytes:
+ case GPBDataTypeMessage:
+ case GPBDataTypeString:
+ result = [[GPBInt32ObjectDictionary alloc] init];
+ break;
+ case GPBDataTypeGroup:
+ NSCAssert(NO, @"shouldn't happen");
+ return nil;
+ }
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ switch (valueDataType) {
+ case GPBDataTypeBool:
+ result = [[GPBUInt64BoolDictionary alloc] init];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ result = [[GPBUInt64UInt32Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ result = [[GPBUInt64Int32Dictionary alloc] init];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ result = [[GPBUInt64UInt64Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ result = [[GPBUInt64Int64Dictionary alloc] init];
+ break;
+ case GPBDataTypeFloat:
+ result = [[GPBUInt64FloatDictionary alloc] init];
+ break;
+ case GPBDataTypeDouble:
+ result = [[GPBUInt64DoubleDictionary alloc] init];
+ break;
+ case GPBDataTypeEnum:
+ result = [[GPBUInt64EnumDictionary alloc]
+ initWithValidationFunction:field.enumDescriptor.enumVerifier];
+ break;
+ case GPBDataTypeBytes:
+ case GPBDataTypeMessage:
+ case GPBDataTypeString:
+ result = [[GPBUInt64ObjectDictionary alloc] init];
+ break;
+ case GPBDataTypeGroup:
+ NSCAssert(NO, @"shouldn't happen");
+ return nil;
+ }
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ switch (valueDataType) {
+ case GPBDataTypeBool:
+ result = [[GPBInt64BoolDictionary alloc] init];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ result = [[GPBInt64UInt32Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ result = [[GPBInt64Int32Dictionary alloc] init];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ result = [[GPBInt64UInt64Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ result = [[GPBInt64Int64Dictionary alloc] init];
+ break;
+ case GPBDataTypeFloat:
+ result = [[GPBInt64FloatDictionary alloc] init];
+ break;
+ case GPBDataTypeDouble:
+ result = [[GPBInt64DoubleDictionary alloc] init];
+ break;
+ case GPBDataTypeEnum:
+ result = [[GPBInt64EnumDictionary alloc]
+ initWithValidationFunction:field.enumDescriptor.enumVerifier];
+ break;
+ case GPBDataTypeBytes:
+ case GPBDataTypeMessage:
+ case GPBDataTypeString:
+ result = [[GPBInt64ObjectDictionary alloc] init];
+ break;
+ case GPBDataTypeGroup:
+ NSCAssert(NO, @"shouldn't happen");
+ return nil;
+ }
+ break;
+ case GPBDataTypeString:
+ switch (valueDataType) {
+ case GPBDataTypeBool:
+ result = [[GPBStringBoolDictionary alloc] init];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ result = [[GPBStringUInt32Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ result = [[GPBStringInt32Dictionary alloc] init];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ result = [[GPBStringUInt64Dictionary alloc] init];
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ result = [[GPBStringInt64Dictionary alloc] init];
+ break;
+ case GPBDataTypeFloat:
+ result = [[GPBStringFloatDictionary alloc] init];
+ break;
+ case GPBDataTypeDouble:
+ result = [[GPBStringDoubleDictionary alloc] init];
+ break;
+ case GPBDataTypeEnum:
+ result = [[GPBStringEnumDictionary alloc]
+ initWithValidationFunction:field.enumDescriptor.enumVerifier];
+ break;
+ case GPBDataTypeBytes:
+ case GPBDataTypeMessage:
+ case GPBDataTypeString:
+ if (autocreator) {
+ result = [[GPBAutocreatedDictionary alloc] init];
+ } else {
+ result = [[NSMutableDictionary alloc] init];
+ }
+ break;
+ case GPBDataTypeGroup:
+ NSCAssert(NO, @"shouldn't happen");
+ return nil;
+ }
+ break;
+
+ case GPBDataTypeFloat:
+ case GPBDataTypeDouble:
+ case GPBDataTypeEnum:
+ case GPBDataTypeBytes:
+ case GPBDataTypeGroup:
+ case GPBDataTypeMessage:
+ NSCAssert(NO, @"shouldn't happen");
+ return nil;
+ }
+
+ if (autocreator) {
+ if ((keyDataType == GPBDataTypeString) &&
+ GPBDataTypeIsObject(valueDataType)) {
+ GPBAutocreatedDictionary *autoDict = result;
+ autoDict->_autocreator = autocreator;
+ } else {
+ GPBInt32Int32Dictionary *gpbDict = result;
+ gpbDict->_autocreator = autocreator;
+ }
+ }
+
+ return result;
+}
+
+#if !defined(__clang_analyzer__)
+// These functions are blocked from the analyzer because the analyzer sees the
+// GPBSetRetainedObjectIvarWithFieldInternal() call as consuming the array/map,
+// so use of the array/map after the call returns is flagged as a use after
+// free.
+// But GPBSetRetainedObjectIvarWithFieldInternal() is "consuming" the retain
+// count be holding onto the object (it is transfering it), the object is
+// still valid after returning from the call. The other way to avoid this
+// would be to add a -retain/-autorelease, but that would force every
+// repeated/map field parsed into the autorelease pool which is both a memory
+// and performance hit.
+
+static id GetOrCreateArrayIvarWithField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ GPBFileSyntax syntax) {
+ id array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (!array) {
+ // No lock needed, this is called from places expecting to mutate
+ // so no threading protection is needed.
+ array = CreateArrayForField(field, nil);
+ GPBSetRetainedObjectIvarWithFieldInternal(self, field, array, syntax);
+ }
+ return array;
+}
+
+// This is like GPBGetObjectIvarWithField(), but for arrays, it should
+// only be used to wire the method into the class.
+static id GetArrayIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) {
+ id array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (!array) {
+ // Check again after getting the lock.
+ GPBPrepareReadOnlySemaphore(self);
+ dispatch_semaphore_wait(self->readOnlySemaphore_, DISPATCH_TIME_FOREVER);
+ array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (!array) {
+ array = CreateArrayForField(field, self);
+ GPBSetAutocreatedRetainedObjectIvarWithField(self, field, array);
+ }
+ dispatch_semaphore_signal(self->readOnlySemaphore_);
+ }
+ return array;
+}
+
+static id GetOrCreateMapIvarWithField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ GPBFileSyntax syntax) {
+ id dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (!dict) {
+ // No lock needed, this is called from places expecting to mutate
+ // so no threading protection is needed.
+ dict = CreateMapForField(field, nil);
+ GPBSetRetainedObjectIvarWithFieldInternal(self, field, dict, syntax);
+ }
+ return dict;
+}
+
+// This is like GPBGetObjectIvarWithField(), but for maps, it should
+// only be used to wire the method into the class.
+static id GetMapIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) {
+ id dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (!dict) {
+ // Check again after getting the lock.
+ GPBPrepareReadOnlySemaphore(self);
+ dispatch_semaphore_wait(self->readOnlySemaphore_, DISPATCH_TIME_FOREVER);
+ dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (!dict) {
+ dict = CreateMapForField(field, self);
+ GPBSetAutocreatedRetainedObjectIvarWithField(self, field, dict);
+ }
+ dispatch_semaphore_signal(self->readOnlySemaphore_);
+ }
+ return dict;
+}
+
+#endif // !defined(__clang_analyzer__)
+
+GPBMessage *GPBCreateMessageWithAutocreator(Class msgClass,
+ GPBMessage *autocreator,
+ GPBFieldDescriptor *field) {
+ GPBMessage *message = [[msgClass alloc] init];
+ message->autocreator_ = autocreator;
+ message->autocreatorField_ = [field retain];
+ return message;
+}
+
+static GPBMessage *CreateMessageWithAutocreatorForExtension(
+ Class msgClass, GPBMessage *autocreator, GPBExtensionDescriptor *extension)
+ __attribute__((ns_returns_retained));
+
+static GPBMessage *CreateMessageWithAutocreatorForExtension(
+ Class msgClass, GPBMessage *autocreator,
+ GPBExtensionDescriptor *extension) {
+ GPBMessage *message = [[msgClass alloc] init];
+ message->autocreator_ = autocreator;
+ message->autocreatorExtension_ = [extension retain];
+ return message;
+}
+
+BOOL GPBWasMessageAutocreatedBy(GPBMessage *message, GPBMessage *parent) {
+ return (message->autocreator_ == parent);
+}
+
+void GPBBecomeVisibleToAutocreator(GPBMessage *self) {
+ // Message objects that are implicitly created by accessing a message field
+ // are initially not visible via the hasX selector. This method makes them
+ // visible.
+ if (self->autocreator_) {
+ // This will recursively make all parent messages visible until it reaches a
+ // super-creator that's visible.
+ if (self->autocreatorField_) {
+ GPBFileSyntax syntax = [self->autocreator_ descriptor].file.syntax;
+ GPBSetObjectIvarWithFieldInternal(self->autocreator_,
+ self->autocreatorField_, self, syntax);
+ } else {
+ [self->autocreator_ setExtension:self->autocreatorExtension_ value:self];
+ }
+ }
+}
+
+void GPBAutocreatedArrayModified(GPBMessage *self, id array) {
+ // When one of our autocreated arrays adds elements, make it visible.
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ if (field.fieldType == GPBFieldTypeRepeated) {
+ id curArray = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (curArray == array) {
+ if (GPBFieldDataTypeIsObject(field)) {
+ GPBAutocreatedArray *autoArray = array;
+ autoArray->_autocreator = nil;
+ } else {
+ GPBInt32Array *gpbArray = array;
+ gpbArray->_autocreator = nil;
+ }
+ GPBBecomeVisibleToAutocreator(self);
+ return;
+ }
+ }
+ }
+ NSCAssert(NO, @"Unknown autocreated %@ for %@.", [array class], self);
+}
+
+void GPBAutocreatedDictionaryModified(GPBMessage *self, id dictionary) {
+ // When one of our autocreated dicts adds elements, make it visible.
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ if (field.fieldType == GPBFieldTypeMap) {
+ id curDict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (curDict == dictionary) {
+ if ((field.mapKeyDataType == GPBDataTypeString) &&
+ GPBFieldDataTypeIsObject(field)) {
+ GPBAutocreatedDictionary *autoDict = dictionary;
+ autoDict->_autocreator = nil;
+ } else {
+ GPBInt32Int32Dictionary *gpbDict = dictionary;
+ gpbDict->_autocreator = nil;
+ }
+ GPBBecomeVisibleToAutocreator(self);
+ return;
+ }
+ }
+ }
+ NSCAssert(NO, @"Unknown autocreated %@ for %@.", [dictionary class], self);
+}
+
+void GPBClearMessageAutocreator(GPBMessage *self) {
+ if ((self == nil) || !self->autocreator_) {
+ return;
+ }
+
+#if defined(DEBUG) && DEBUG && !defined(NS_BLOCK_ASSERTIONS)
+ // Either the autocreator must have its "has" flag set to YES, or it must be
+ // NO and not equal to ourselves.
+ BOOL autocreatorHas =
+ (self->autocreatorField_
+ ? GPBGetHasIvarField(self->autocreator_, self->autocreatorField_)
+ : [self->autocreator_ hasExtension:self->autocreatorExtension_]);
+ GPBMessage *autocreatorFieldValue =
+ (self->autocreatorField_
+ ? GPBGetObjectIvarWithFieldNoAutocreate(self->autocreator_,
+ self->autocreatorField_)
+ : [self->autocreator_->autocreatedExtensionMap_
+ objectForKey:self->autocreatorExtension_]);
+ NSCAssert(autocreatorHas || autocreatorFieldValue != self,
+ @"Cannot clear autocreator because it still refers to self, self: %@.",
+ self);
+
+#endif // DEBUG && !defined(NS_BLOCK_ASSERTIONS)
+
+ self->autocreator_ = nil;
+ [self->autocreatorField_ release];
+ self->autocreatorField_ = nil;
+ [self->autocreatorExtension_ release];
+ self->autocreatorExtension_ = nil;
+}
+
+static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
+ if (!self->unknownFields_) {
+ self->unknownFields_ = [[GPBUnknownFieldSet alloc] init];
+ GPBBecomeVisibleToAutocreator(self);
+ }
+ return self->unknownFields_;
+}
+
+@implementation GPBMessage
+
++ (void)initialize {
+ Class pbMessageClass = [GPBMessage class];
+ if ([self class] == pbMessageClass) {
+ // This is here to start up the "base" class descriptor.
+ [self descriptor];
+ // Message shares extension method resolving with GPBRootObject so insure
+ // it is started up at the same time.
+ (void)[GPBRootObject class];
+ } else if ([self superclass] == pbMessageClass) {
+ // This is here to start up all the "message" subclasses. Just needs to be
+ // done for the messages, not any of the subclasses.
+ // This must be done in initialize to enforce thread safety of start up of
+ // the protocol buffer library.
+ // Note: The generated code for -descriptor calls
+ // +[GPBDescriptor allocDescriptorForClass:...], passing the GPBRootObject
+ // subclass for the file. That call chain is what ensures that *Root class
+ // is started up to support extension resolution off the message class
+ // (+resolveClassMethod: below) in a thread safe manner.
+ [self descriptor];
+ }
+}
+
++ (instancetype)allocWithZone:(NSZone *)zone {
+ // Override alloc to allocate our classes with the additional storage
+ // required for the instance variables.
+ GPBDescriptor *descriptor = [self descriptor];
+ return NSAllocateObject(self, descriptor->storageSize_, zone);
+}
+
++ (instancetype)alloc {
+ return [self allocWithZone:nil];
+}
+
++ (GPBDescriptor *)descriptor {
+ // This is thread safe because it is called from +initialize.
+ static GPBDescriptor *descriptor = NULL;
+ static GPBFileDescriptor *fileDescriptor = NULL;
+ if (!descriptor) {
+ // Use a dummy file that marks it as proto2 syntax so when used generically
+ // it supports unknowns/etc.
+ fileDescriptor =
+ [[GPBFileDescriptor alloc] initWithPackage:@"internal"
+ syntax:GPBFileSyntaxProto2];
+
+ descriptor = [GPBDescriptor allocDescriptorForClass:[GPBMessage class]
+ rootClass:Nil
+ file:fileDescriptor
+ fields:NULL
+ fieldCount:0
+ storageSize:0
+ flags:0];
+ }
+ return descriptor;
+}
+
++ (instancetype)message {
+ return [[[self alloc] init] autorelease];
+}
+
+- (instancetype)init {
+ if ((self = [super init])) {
+ messageStorage_ = (GPBMessage_StoragePtr)(
+ ((uint8_t *)self) + class_getInstanceSize([self class]));
+ }
+
+ return self;
+}
+
+- (instancetype)initWithData:(NSData *)data error:(NSError **)errorPtr {
+ return [self initWithData:data extensionRegistry:nil error:errorPtr];
+}
+
+- (instancetype)initWithData:(NSData *)data
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr {
+ if ((self = [self init])) {
+ @try {
+ [self mergeFromData:data extensionRegistry:extensionRegistry];
+ if (errorPtr) {
+ *errorPtr = nil;
+ }
+ }
+ @catch (NSException *exception) {
+ [self release];
+ self = nil;
+ if (errorPtr) {
+ *errorPtr = ErrorFromException(exception);
+ }
+ }
+#ifdef DEBUG
+ if (self && !self.initialized) {
+ [self release];
+ self = nil;
+ if (errorPtr) {
+ *errorPtr = MessageError(GPBMessageErrorCodeMissingRequiredField, nil);
+ }
+ }
+#endif
+ }
+ return self;
+}
+
+- (instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:
+ (GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr {
+ if ((self = [self init])) {
+ @try {
+ [self mergeFromCodedInputStream:input extensionRegistry:extensionRegistry];
+ if (errorPtr) {
+ *errorPtr = nil;
+ }
+ }
+ @catch (NSException *exception) {
+ [self release];
+ self = nil;
+ if (errorPtr) {
+ *errorPtr = ErrorFromException(exception);
+ }
+ }
+#ifdef DEBUG
+ if (self && !self.initialized) {
+ [self release];
+ self = nil;
+ if (errorPtr) {
+ *errorPtr = MessageError(GPBMessageErrorCodeMissingRequiredField, nil);
+ }
+ }
+#endif
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [self internalClear:NO];
+ NSCAssert(!autocreator_, @"Autocreator was not cleared before dealloc.");
+ if (readOnlySemaphore_) {
+ dispatch_release(readOnlySemaphore_);
+ }
+ [super dealloc];
+}
+
+- (void)copyFieldsInto:(GPBMessage *)message
+ zone:(NSZone *)zone
+ descriptor:(GPBDescriptor *)descriptor {
+ // Copy all the storage...
+ memcpy(message->messageStorage_, messageStorage_, descriptor->storageSize_);
+
+ GPBFileSyntax syntax = descriptor.file.syntax;
+
+ // Loop over the fields doing fixup...
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ if (GPBFieldIsMapOrArray(field)) {
+ id value = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (value) {
+ // We need to copy the array/map, but the catch is for message fields,
+ // we also need to ensure all the messages as those need copying also.
+ id newValue;
+ if (GPBFieldDataTypeIsMessage(field)) {
+ if (field.fieldType == GPBFieldTypeRepeated) {
+ NSArray *existingArray = (NSArray *)value;
+ NSMutableArray *newArray =
+ [[NSMutableArray alloc] initWithCapacity:existingArray.count];
+ newValue = newArray;
+ for (GPBMessage *msg in existingArray) {
+ GPBMessage *copiedMsg = [msg copyWithZone:zone];
+ [newArray addObject:copiedMsg];
+ [copiedMsg release];
+ }
+ } else {
+ if (field.mapKeyDataType == GPBDataTypeString) {
+ // Map is an NSDictionary.
+ NSDictionary *existingDict = value;
+ NSMutableDictionary *newDict = [[NSMutableDictionary alloc]
+ initWithCapacity:existingDict.count];
+ newValue = newDict;
+ [existingDict enumerateKeysAndObjectsUsingBlock:^(NSString *key,
+ GPBMessage *msg,
+ BOOL *stop) {
+#pragma unused(stop)
+ GPBMessage *copiedMsg = [msg copyWithZone:zone];
+ [newDict setObject:copiedMsg forKey:key];
+ [copiedMsg release];
+ }];
+ } else {
+ // Is one of the GPB*ObjectDictionary classes. Type doesn't
+ // matter, just need one to invoke the selector.
+ GPBInt32ObjectDictionary *existingDict = value;
+ newValue = [existingDict deepCopyWithZone:zone];
+ }
+ }
+ } else {
+ // Not messages (but is a map/array)...
+ if (field.fieldType == GPBFieldTypeRepeated) {
+ if (GPBFieldDataTypeIsObject(field)) {
+ // NSArray
+ newValue = [value mutableCopyWithZone:zone];
+ } else {
+ // GPB*Array
+ newValue = [value copyWithZone:zone];
+ }
+ } else {
+ if (field.mapKeyDataType == GPBDataTypeString) {
+ // NSDictionary
+ newValue = [value mutableCopyWithZone:zone];
+ } else {
+ // Is one of the GPB*Dictionary classes. Type doesn't matter,
+ // just need one to invoke the selector.
+ GPBInt32Int32Dictionary *existingDict = value;
+ newValue = [existingDict copyWithZone:zone];
+ }
+ }
+ }
+ // We retain here because the memcpy picked up the pointer value and
+ // the next call to SetRetainedObject... will release the current value.
+ [value retain];
+ GPBSetRetainedObjectIvarWithFieldInternal(message, field, newValue,
+ syntax);
+ }
+ } else if (GPBFieldDataTypeIsMessage(field)) {
+ // For object types, if we have a value, copy it. If we don't,
+ // zero it to remove the pointer to something that was autocreated
+ // (and the ptr just got memcpyed).
+ if (GPBGetHasIvarField(self, field)) {
+ GPBMessage *value = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ GPBMessage *newValue = [value copyWithZone:zone];
+ // We retain here because the memcpy picked up the pointer value and
+ // the next call to SetRetainedObject... will release the current value.
+ [value retain];
+ GPBSetRetainedObjectIvarWithFieldInternal(message, field, newValue,
+ syntax);
+ } else {
+ uint8_t *storage = (uint8_t *)message->messageStorage_;
+ id *typePtr = (id *)&storage[field->description_->offset];
+ *typePtr = NULL;
+ }
+ } else if (GPBFieldDataTypeIsObject(field) &&
+ GPBGetHasIvarField(self, field)) {
+ // A set string/data value (message picked off above), copy it.
+ id value = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ id newValue = [value copyWithZone:zone];
+ // We retain here because the memcpy picked up the pointer value and
+ // the next call to SetRetainedObject... will release the current value.
+ [value retain];
+ GPBSetRetainedObjectIvarWithFieldInternal(message, field, newValue,
+ syntax);
+ } else {
+ // memcpy took care of the rest of the primitive fields if they were set.
+ }
+ } // for (field in descriptor->fields_)
+}
+
+- (id)copyWithZone:(NSZone *)zone {
+ GPBDescriptor *descriptor = [self descriptor];
+ GPBMessage *result = [[descriptor.messageClass allocWithZone:zone] init];
+
+ [self copyFieldsInto:result zone:zone descriptor:descriptor];
+ // Make immutable copies of the extra bits.
+ result->unknownFields_ = [unknownFields_ copyWithZone:zone];
+ result->extensionMap_ = CloneExtensionMap(extensionMap_, zone);
+ return result;
+}
+
+- (void)clear {
+ [self internalClear:YES];
+}
+
+- (void)internalClear:(BOOL)zeroStorage {
+ GPBDescriptor *descriptor = [self descriptor];
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ if (GPBFieldIsMapOrArray(field)) {
+ id arrayOrMap = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (arrayOrMap) {
+ if (field.fieldType == GPBFieldTypeRepeated) {
+ if (GPBFieldDataTypeIsObject(field)) {
+ if ([arrayOrMap isKindOfClass:[GPBAutocreatedArray class]]) {
+ GPBAutocreatedArray *autoArray = arrayOrMap;
+ if (autoArray->_autocreator == self) {
+ autoArray->_autocreator = nil;
+ }
+ }
+ } else {
+ // Type doesn't matter, it is a GPB*Array.
+ GPBInt32Array *gpbArray = arrayOrMap;
+ if (gpbArray->_autocreator == self) {
+ gpbArray->_autocreator = nil;
+ }
+ }
+ } else {
+ if ((field.mapKeyDataType == GPBDataTypeString) &&
+ GPBFieldDataTypeIsObject(field)) {
+ if ([arrayOrMap isKindOfClass:[GPBAutocreatedDictionary class]]) {
+ GPBAutocreatedDictionary *autoDict = arrayOrMap;
+ if (autoDict->_autocreator == self) {
+ autoDict->_autocreator = nil;
+ }
+ }
+ } else {
+ // Type doesn't matter, it is a GPB*Dictionary.
+ GPBInt32Int32Dictionary *gpbDict = arrayOrMap;
+ if (gpbDict->_autocreator == self) {
+ gpbDict->_autocreator = nil;
+ }
+ }
+ }
+ [arrayOrMap release];
+ }
+ } else if (GPBFieldDataTypeIsMessage(field)) {
+ GPBClearAutocreatedMessageIvarWithField(self, field);
+ GPBMessage *value = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [value release];
+ } else if (GPBFieldDataTypeIsObject(field) &&
+ GPBGetHasIvarField(self, field)) {
+ id value = GPBGetObjectIvarWithField(self, field);
+ [value release];
+ }
+ }
+
+ // GPBClearMessageAutocreator() expects that its caller has already been
+ // removed from autocreatedExtensionMap_ so we set to nil first.
+ NSArray *autocreatedValues = [autocreatedExtensionMap_ allValues];
+ [autocreatedExtensionMap_ release];
+ autocreatedExtensionMap_ = nil;
+
+ // Since we're clearing all of our extensions, make sure that we clear the
+ // autocreator on any that we've created so they no longer refer to us.
+ for (GPBMessage *value in autocreatedValues) {
+ NSCAssert(GPBWasMessageAutocreatedBy(value, self),
+ @"Autocreated extension does not refer back to self.");
+ GPBClearMessageAutocreator(value);
+ }
+
+ [extensionMap_ release];
+ extensionMap_ = nil;
+ [unknownFields_ release];
+ unknownFields_ = nil;
+
+ // Note that clearing does not affect autocreator_. If we are being cleared
+ // because of a dealloc, then autocreator_ should be nil anyway. If we are
+ // being cleared because someone explicitly clears us, we don't want to
+ // sever our relationship with our autocreator.
+
+ if (zeroStorage) {
+ memset(messageStorage_, 0, descriptor->storageSize_);
+ }
+}
+
+- (BOOL)isInitialized {
+ GPBDescriptor *descriptor = [self descriptor];
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ if (field.isRequired) {
+ if (!GPBGetHasIvarField(self, field)) {
+ return NO;
+ }
+ }
+ if (GPBFieldDataTypeIsMessage(field)) {
+ GPBFieldType fieldType = field.fieldType;
+ if (fieldType == GPBFieldTypeSingle) {
+ if (field.isRequired) {
+ GPBMessage *message = GPBGetMessageMessageField(self, field);
+ if (!message.initialized) {
+ return NO;
+ }
+ } else {
+ NSAssert(field.isOptional,
+ @"%@: Single message field %@ not required or optional?",
+ [self class], field.name);
+ if (GPBGetHasIvarField(self, field)) {
+ GPBMessage *message = GPBGetMessageMessageField(self, field);
+ if (!message.initialized) {
+ return NO;
+ }
+ }
+ }
+ } else if (fieldType == GPBFieldTypeRepeated) {
+ NSArray *array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ for (GPBMessage *message in array) {
+ if (!message.initialized) {
+ return NO;
+ }
+ }
+ } else { // fieldType == GPBFieldTypeMap
+ if (field.mapKeyDataType == GPBDataTypeString) {
+ NSDictionary *map =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (map && !GPBDictionaryIsInitializedInternalHelper(map, field)) {
+ return NO;
+ }
+ } else {
+ // Real type is GPB*ObjectDictionary, exact type doesn't matter.
+ GPBInt32ObjectDictionary *map =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (map && ![map isInitialized]) {
+ return NO;
+ }
+ }
+ }
+ }
+ }
+
+ __block BOOL result = YES;
+ [extensionMap_
+ enumerateKeysAndObjectsUsingBlock:^(GPBExtensionDescriptor *extension,
+ id obj,
+ BOOL *stop) {
+ if (GPBExtensionIsMessage(extension)) {
+ if (extension.isRepeated) {
+ for (GPBMessage *msg in obj) {
+ if (!msg.initialized) {
+ result = NO;
+ *stop = YES;
+ break;
+ }
+ }
+ } else {
+ GPBMessage *asMsg = obj;
+ if (!asMsg.initialized) {
+ result = NO;
+ *stop = YES;
+ }
+ }
+ }
+ }];
+ return result;
+}
+
+- (GPBDescriptor *)descriptor {
+ return [[self class] descriptor];
+}
+
+- (NSData *)data {
+#ifdef DEBUG
+ if (!self.initialized) {
+ return nil;
+ }
+#endif
+ NSMutableData *data = [NSMutableData dataWithLength:[self serializedSize]];
+ GPBCodedOutputStream *stream =
+ [[GPBCodedOutputStream alloc] initWithData:data];
+ @try {
+ [self writeToCodedOutputStream:stream];
+ }
+ @catch (NSException *exception) {
+ // This really shouldn't happen. The only way writeToCodedOutputStream:
+ // could throw is if something in the library has a bug and the
+ // serializedSize was wrong.
+#ifdef DEBUG
+ NSLog(@"%@: Internal exception while building message data: %@",
+ [self class], exception);
+#endif
+ data = nil;
+ }
+ [stream release];
+ return data;
+}
+
+- (NSData *)delimitedData {
+ size_t serializedSize = [self serializedSize];
+ size_t varintSize = GPBComputeRawVarint32SizeForInteger(serializedSize);
+ NSMutableData *data =
+ [NSMutableData dataWithLength:(serializedSize + varintSize)];
+ GPBCodedOutputStream *stream =
+ [[GPBCodedOutputStream alloc] initWithData:data];
+ @try {
+ [self writeDelimitedToCodedOutputStream:stream];
+ }
+ @catch (NSException *exception) {
+ // This really shouldn't happen. The only way writeToCodedOutputStream:
+ // could throw is if something in the library has a bug and the
+ // serializedSize was wrong.
+#ifdef DEBUG
+ NSLog(@"%@: Internal exception while building message delimitedData: %@",
+ [self class], exception);
+#endif
+ // If it happens, truncate.
+ data.length = 0;
+ }
+ [stream release];
+ return data;
+}
+
+- (void)writeToOutputStream:(NSOutputStream *)output {
+ GPBCodedOutputStream *stream =
+ [[GPBCodedOutputStream alloc] initWithOutputStream:output];
+ [self writeToCodedOutputStream:stream];
+ [stream release];
+}
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output {
+ GPBDescriptor *descriptor = [self descriptor];
+ NSArray *fieldsArray = descriptor->fields_;
+ NSUInteger fieldCount = fieldsArray.count;
+ const GPBExtensionRange *extensionRanges = descriptor.extensionRanges;
+ NSUInteger extensionRangesCount = descriptor.extensionRangesCount;
+ for (NSUInteger i = 0, j = 0; i < fieldCount || j < extensionRangesCount;) {
+ if (i == fieldCount) {
+ [self writeExtensionsToCodedOutputStream:output
+ range:extensionRanges[j++]];
+ } else if (j == extensionRangesCount ||
+ GPBFieldNumber(fieldsArray[i]) < extensionRanges[j].start) {
+ [self writeField:fieldsArray[i++] toCodedOutputStream:output];
+ } else {
+ [self writeExtensionsToCodedOutputStream:output
+ range:extensionRanges[j++]];
+ }
+ }
+ if (descriptor.isWireFormat) {
+ [unknownFields_ writeAsMessageSetTo:output];
+ } else {
+ [unknownFields_ writeToCodedOutputStream:output];
+ }
+}
+
+- (void)writeDelimitedToOutputStream:(NSOutputStream *)output {
+ GPBCodedOutputStream *codedOutput =
+ [[GPBCodedOutputStream alloc] initWithOutputStream:output];
+ [self writeDelimitedToCodedOutputStream:codedOutput];
+ [codedOutput release];
+}
+
+- (void)writeDelimitedToCodedOutputStream:(GPBCodedOutputStream *)output {
+ [output writeRawVarintSizeTAs32:[self serializedSize]];
+ [self writeToCodedOutputStream:output];
+}
+
+- (void)writeField:(GPBFieldDescriptor *)field
+ toCodedOutputStream:(GPBCodedOutputStream *)output {
+ GPBFieldType fieldType = field.fieldType;
+ if (fieldType == GPBFieldTypeSingle) {
+ BOOL has = GPBGetHasIvarField(self, field);
+ if (!has) {
+ return;
+ }
+ }
+ uint32_t fieldNumber = GPBFieldNumber(field);
+
+//%PDDM-DEFINE FIELD_CASE(TYPE, REAL_TYPE)
+//%FIELD_CASE_FULL(TYPE, REAL_TYPE, REAL_TYPE)
+//%PDDM-DEFINE FIELD_CASE_FULL(TYPE, REAL_TYPE, ARRAY_TYPE)
+//% case GPBDataType##TYPE:
+//% if (fieldType == GPBFieldTypeRepeated) {
+//% uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+//% GPB##ARRAY_TYPE##Array *array =
+//% GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+//% [output write##TYPE##Array:fieldNumber values:array tag:tag];
+//% } else if (fieldType == GPBFieldTypeSingle) {
+//% [output write##TYPE:fieldNumber
+//% TYPE$S value:GPBGetMessage##REAL_TYPE##Field(self, field)];
+//% } else { // fieldType == GPBFieldTypeMap
+//% // Exact type here doesn't matter.
+//% GPBInt32##ARRAY_TYPE##Dictionary *dict =
+//% GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+//% [dict writeToCodedOutputStream:output asField:field];
+//% }
+//% break;
+//%
+//%PDDM-DEFINE FIELD_CASE2(TYPE)
+//% case GPBDataType##TYPE:
+//% if (fieldType == GPBFieldTypeRepeated) {
+//% NSArray *array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+//% [output write##TYPE##Array:fieldNumber values:array];
+//% } else if (fieldType == GPBFieldTypeSingle) {
+//% // GPBGetObjectIvarWithFieldNoAutocreate() avoids doing the has check
+//% // again.
+//% [output write##TYPE:fieldNumber
+//% TYPE$S value:GPBGetObjectIvarWithFieldNoAutocreate(self, field)];
+//% } else { // fieldType == GPBFieldTypeMap
+//% // Exact type here doesn't matter.
+//% id dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+//% GPBDataType mapKeyDataType = field.mapKeyDataType;
+//% if (mapKeyDataType == GPBDataTypeString) {
+//% GPBDictionaryWriteToStreamInternalHelper(output, dict, field);
+//% } else {
+//% [dict writeToCodedOutputStream:output asField:field];
+//% }
+//% }
+//% break;
+//%
+
+ switch (GPBGetFieldDataType(field)) {
+
+//%PDDM-EXPAND FIELD_CASE(Bool, Bool)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeBool:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBBoolArray *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeBoolArray:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeBool:fieldNumber
+ value:GPBGetMessageBoolField(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32BoolDictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(Fixed32, UInt32)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeFixed32:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBUInt32Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeFixed32Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeFixed32:fieldNumber
+ value:GPBGetMessageUInt32Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32UInt32Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(SFixed32, Int32)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeSFixed32:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBInt32Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeSFixed32Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeSFixed32:fieldNumber
+ value:GPBGetMessageInt32Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32Int32Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(Float, Float)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeFloat:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBFloatArray *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeFloatArray:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeFloat:fieldNumber
+ value:GPBGetMessageFloatField(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32FloatDictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(Fixed64, UInt64)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeFixed64:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBUInt64Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeFixed64Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeFixed64:fieldNumber
+ value:GPBGetMessageUInt64Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32UInt64Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(SFixed64, Int64)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeSFixed64:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBInt64Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeSFixed64Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeSFixed64:fieldNumber
+ value:GPBGetMessageInt64Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32Int64Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(Double, Double)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeDouble:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBDoubleArray *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeDoubleArray:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeDouble:fieldNumber
+ value:GPBGetMessageDoubleField(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32DoubleDictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(Int32, Int32)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeInt32:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBInt32Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeInt32Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeInt32:fieldNumber
+ value:GPBGetMessageInt32Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32Int32Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(Int64, Int64)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeInt64:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBInt64Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeInt64Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeInt64:fieldNumber
+ value:GPBGetMessageInt64Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32Int64Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(SInt32, Int32)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeSInt32:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBInt32Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeSInt32Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeSInt32:fieldNumber
+ value:GPBGetMessageInt32Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32Int32Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(SInt64, Int64)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeSInt64:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBInt64Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeSInt64Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeSInt64:fieldNumber
+ value:GPBGetMessageInt64Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32Int64Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(UInt32, UInt32)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeUInt32:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBUInt32Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeUInt32Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeUInt32:fieldNumber
+ value:GPBGetMessageUInt32Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32UInt32Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE(UInt64, UInt64)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeUInt64:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBUInt64Array *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeUInt64Array:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeUInt64:fieldNumber
+ value:GPBGetMessageUInt64Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32UInt64Dictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE_FULL(Enum, Int32, Enum)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeEnum:
+ if (fieldType == GPBFieldTypeRepeated) {
+ uint32_t tag = field.isPackable ? GPBFieldTag(field) : 0;
+ GPBEnumArray *array =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeEnumArray:fieldNumber values:array tag:tag];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ [output writeEnum:fieldNumber
+ value:GPBGetMessageInt32Field(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ GPBInt32EnumDictionary *dict =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE2(Bytes)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeBytes:
+ if (fieldType == GPBFieldTypeRepeated) {
+ NSArray *array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeBytesArray:fieldNumber values:array];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ // GPBGetObjectIvarWithFieldNoAutocreate() avoids doing the has check
+ // again.
+ [output writeBytes:fieldNumber
+ value:GPBGetObjectIvarWithFieldNoAutocreate(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ id dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ GPBDataType mapKeyDataType = field.mapKeyDataType;
+ if (mapKeyDataType == GPBDataTypeString) {
+ GPBDictionaryWriteToStreamInternalHelper(output, dict, field);
+ } else {
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE2(String)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeString:
+ if (fieldType == GPBFieldTypeRepeated) {
+ NSArray *array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeStringArray:fieldNumber values:array];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ // GPBGetObjectIvarWithFieldNoAutocreate() avoids doing the has check
+ // again.
+ [output writeString:fieldNumber
+ value:GPBGetObjectIvarWithFieldNoAutocreate(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ id dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ GPBDataType mapKeyDataType = field.mapKeyDataType;
+ if (mapKeyDataType == GPBDataTypeString) {
+ GPBDictionaryWriteToStreamInternalHelper(output, dict, field);
+ } else {
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE2(Message)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeMessage:
+ if (fieldType == GPBFieldTypeRepeated) {
+ NSArray *array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeMessageArray:fieldNumber values:array];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ // GPBGetObjectIvarWithFieldNoAutocreate() avoids doing the has check
+ // again.
+ [output writeMessage:fieldNumber
+ value:GPBGetObjectIvarWithFieldNoAutocreate(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ id dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ GPBDataType mapKeyDataType = field.mapKeyDataType;
+ if (mapKeyDataType == GPBDataTypeString) {
+ GPBDictionaryWriteToStreamInternalHelper(output, dict, field);
+ } else {
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ }
+ break;
+
+//%PDDM-EXPAND FIELD_CASE2(Group)
+// This block of code is generated, do not edit it directly.
+
+ case GPBDataTypeGroup:
+ if (fieldType == GPBFieldTypeRepeated) {
+ NSArray *array = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [output writeGroupArray:fieldNumber values:array];
+ } else if (fieldType == GPBFieldTypeSingle) {
+ // GPBGetObjectIvarWithFieldNoAutocreate() avoids doing the has check
+ // again.
+ [output writeGroup:fieldNumber
+ value:GPBGetObjectIvarWithFieldNoAutocreate(self, field)];
+ } else { // fieldType == GPBFieldTypeMap
+ // Exact type here doesn't matter.
+ id dict = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ GPBDataType mapKeyDataType = field.mapKeyDataType;
+ if (mapKeyDataType == GPBDataTypeString) {
+ GPBDictionaryWriteToStreamInternalHelper(output, dict, field);
+ } else {
+ [dict writeToCodedOutputStream:output asField:field];
+ }
+ }
+ break;
+
+//%PDDM-EXPAND-END (18 expansions)
+ }
+}
+
+#pragma mark - Extensions
+
+- (id)getExtension:(GPBExtensionDescriptor *)extension {
+ CheckExtension(self, extension);
+ id value = [extensionMap_ objectForKey:extension];
+ if (value != nil) {
+ return value;
+ }
+
+ // No default for repeated.
+ if (extension.isRepeated) {
+ return nil;
+ }
+ // Non messages get their default.
+ if (!GPBExtensionIsMessage(extension)) {
+ return extension.defaultValue;
+ }
+
+ // Check for an autocreated value.
+ GPBPrepareReadOnlySemaphore(self);
+ dispatch_semaphore_wait(readOnlySemaphore_, DISPATCH_TIME_FOREVER);
+ value = [autocreatedExtensionMap_ objectForKey:extension];
+ if (!value) {
+ // Auto create the message extensions to match normal fields.
+ value = CreateMessageWithAutocreatorForExtension(extension.msgClass, self,
+ extension);
+
+ if (autocreatedExtensionMap_ == nil) {
+ autocreatedExtensionMap_ = [[NSMutableDictionary alloc] init];
+ }
+
+ // We can't simply call setExtension here because that would clear the new
+ // value's autocreator.
+ [autocreatedExtensionMap_ setObject:value forKey:extension];
+ [value release];
+ }
+
+ dispatch_semaphore_signal(readOnlySemaphore_);
+ return value;
+}
+
+- (id)getExistingExtension:(GPBExtensionDescriptor *)extension {
+ // This is an internal method so we don't need to call CheckExtension().
+ return [extensionMap_ objectForKey:extension];
+}
+
+- (BOOL)hasExtension:(GPBExtensionDescriptor *)extension {
+#if defined(DEBUG) && DEBUG
+ CheckExtension(self, extension);
+#endif // DEBUG
+ return nil != [extensionMap_ objectForKey:extension];
+}
+
+- (NSArray *)extensionsCurrentlySet {
+ return [extensionMap_ allKeys];
+}
+
+- (void)writeExtensionsToCodedOutputStream:(GPBCodedOutputStream *)output
+ range:(GPBExtensionRange)range {
+ NSArray *sortedExtensions = [[extensionMap_ allKeys]
+ sortedArrayUsingSelector:@selector(compareByFieldNumber:)];
+ uint32_t start = range.start;
+ uint32_t end = range.end;
+ for (GPBExtensionDescriptor *extension in sortedExtensions) {
+ uint32_t fieldNumber = extension.fieldNumber;
+ if (fieldNumber >= start && fieldNumber < end) {
+ id value = [extensionMap_ objectForKey:extension];
+ GPBWriteExtensionValueToOutputStream(extension, value, output);
+ }
+ }
+}
+
+- (void)setExtension:(GPBExtensionDescriptor *)extension value:(id)value {
+ if (!value) {
+ [self clearExtension:extension];
+ return;
+ }
+
+ CheckExtension(self, extension);
+
+ if (extension.repeated) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Must call addExtension() for repeated types."];
+ }
+
+ if (extensionMap_ == nil) {
+ extensionMap_ = [[NSMutableDictionary alloc] init];
+ }
+
+ // This pointless cast is for CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION.
+ // Without it, the compiler complains we're passing an id nullable when
+ // setObject:forKey: requires a id nonnull for the value. The check for
+ // !value at the start of the method ensures it isn't nil, but the check
+ // isn't smart enough to realize that.
+ [extensionMap_ setObject:(id)value forKey:extension];
+
+ GPBExtensionDescriptor *descriptor = extension;
+
+ if (GPBExtensionIsMessage(descriptor) && !descriptor.isRepeated) {
+ GPBMessage *autocreatedValue =
+ [[autocreatedExtensionMap_ objectForKey:extension] retain];
+ // Must remove from the map before calling GPBClearMessageAutocreator() so
+ // that GPBClearMessageAutocreator() knows its safe to clear.
+ [autocreatedExtensionMap_ removeObjectForKey:extension];
+ GPBClearMessageAutocreator(autocreatedValue);
+ [autocreatedValue release];
+ }
+
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+- (void)addExtension:(GPBExtensionDescriptor *)extension value:(id)value {
+ CheckExtension(self, extension);
+
+ if (!extension.repeated) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Must call setExtension() for singular types."];
+ }
+
+ if (extensionMap_ == nil) {
+ extensionMap_ = [[NSMutableDictionary alloc] init];
+ }
+ NSMutableArray *list = [extensionMap_ objectForKey:extension];
+ if (list == nil) {
+ list = [NSMutableArray array];
+ [extensionMap_ setObject:list forKey:extension];
+ }
+
+ [list addObject:value];
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+- (void)setExtension:(GPBExtensionDescriptor *)extension
+ index:(NSUInteger)idx
+ value:(id)value {
+ CheckExtension(self, extension);
+
+ if (!extension.repeated) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Must call setExtension() for singular types."];
+ }
+
+ if (extensionMap_ == nil) {
+ extensionMap_ = [[NSMutableDictionary alloc] init];
+ }
+
+ NSMutableArray *list = [extensionMap_ objectForKey:extension];
+
+ [list replaceObjectAtIndex:idx withObject:value];
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+- (void)clearExtension:(GPBExtensionDescriptor *)extension {
+ CheckExtension(self, extension);
+
+ // Only become visible if there was actually a value to clear.
+ if ([extensionMap_ objectForKey:extension]) {
+ [extensionMap_ removeObjectForKey:extension];
+ GPBBecomeVisibleToAutocreator(self);
+ }
+}
+
+#pragma mark - mergeFrom
+
+- (void)mergeFromData:(NSData *)data
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ GPBCodedInputStream *input = [[GPBCodedInputStream alloc] initWithData:data];
+ [self mergeFromCodedInputStream:input extensionRegistry:extensionRegistry];
+ [input checkLastTagWas:0];
+ [input release];
+}
+
+#pragma mark - mergeDelimitedFrom
+
+- (void)mergeDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ GPBCodedInputStreamState *state = &input->state_;
+ if (GPBCodedInputStreamIsAtEnd(state)) {
+ return;
+ }
+ NSData *data = GPBCodedInputStreamReadRetainedBytesNoCopy(state);
+ if (data == nil) {
+ return;
+ }
+ [self mergeFromData:data extensionRegistry:extensionRegistry];
+ [data release];
+}
+
+#pragma mark - Parse From Data Support
+
++ (instancetype)parseFromData:(NSData *)data error:(NSError **)errorPtr {
+ return [self parseFromData:data extensionRegistry:nil error:errorPtr];
+}
+
++ (instancetype)parseFromData:(NSData *)data
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr {
+ return [[[self alloc] initWithData:data
+ extensionRegistry:extensionRegistry
+ error:errorPtr] autorelease];
+}
+
++ (instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr {
+ return
+ [[[self alloc] initWithCodedInputStream:input
+ extensionRegistry:extensionRegistry
+ error:errorPtr] autorelease];
+}
+
+#pragma mark - Parse Delimited From Data Support
+
++ (instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:
+ (GPBExtensionRegistry *)extensionRegistry
+ error:(NSError **)errorPtr {
+ GPBMessage *message = [[[self alloc] init] autorelease];
+ @try {
+ [message mergeDelimitedFromCodedInputStream:input
+ extensionRegistry:extensionRegistry];
+ if (errorPtr) {
+ *errorPtr = nil;
+ }
+ }
+ @catch (NSException *exception) {
+ message = nil;
+ if (errorPtr) {
+ *errorPtr = ErrorFromException(exception);
+ }
+ }
+#ifdef DEBUG
+ if (message && !message.initialized) {
+ message = nil;
+ if (errorPtr) {
+ *errorPtr = MessageError(GPBMessageErrorCodeMissingRequiredField, nil);
+ }
+ }
+#endif
+ return message;
+}
+
+#pragma mark - Unknown Field Support
+
+- (GPBUnknownFieldSet *)unknownFields {
+ return unknownFields_;
+}
+
+- (void)setUnknownFields:(GPBUnknownFieldSet *)unknownFields {
+ if (unknownFields != unknownFields_) {
+ [unknownFields_ release];
+ unknownFields_ = [unknownFields copy];
+ GPBBecomeVisibleToAutocreator(self);
+ }
+}
+
+- (void)parseMessageSet:(GPBCodedInputStream *)input
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ uint32_t typeId = 0;
+ NSData *rawBytes = nil;
+ GPBExtensionDescriptor *extension = nil;
+ GPBCodedInputStreamState *state = &input->state_;
+ while (true) {
+ uint32_t tag = GPBCodedInputStreamReadTag(state);
+ if (tag == 0) {
+ break;
+ }
+
+ if (tag == GPBWireFormatMessageSetTypeIdTag) {
+ typeId = GPBCodedInputStreamReadUInt32(state);
+ if (typeId != 0) {
+ extension = [extensionRegistry extensionForDescriptor:[self descriptor]
+ fieldNumber:typeId];
+ }
+ } else if (tag == GPBWireFormatMessageSetMessageTag) {
+ rawBytes =
+ [GPBCodedInputStreamReadRetainedBytesNoCopy(state) autorelease];
+ } else {
+ if (![input skipField:tag]) {
+ break;
+ }
+ }
+ }
+
+ [input checkLastTagWas:GPBWireFormatMessageSetItemEndTag];
+
+ if (rawBytes != nil && typeId != 0) {
+ if (extension != nil) {
+ GPBCodedInputStream *newInput =
+ [[GPBCodedInputStream alloc] initWithData:rawBytes];
+ GPBExtensionMergeFromInputStream(extension,
+ extension.packable,
+ newInput,
+ extensionRegistry,
+ self);
+ [newInput release];
+ } else {
+ GPBUnknownFieldSet *unknownFields = GetOrMakeUnknownFields(self);
+ [unknownFields mergeMessageSetMessage:typeId data:rawBytes];
+ }
+ }
+}
+
+- (BOOL)parseUnknownField:(GPBCodedInputStream *)input
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ tag:(uint32_t)tag {
+ GPBWireFormat wireType = GPBWireFormatGetTagWireType(tag);
+ int32_t fieldNumber = GPBWireFormatGetTagFieldNumber(tag);
+
+ GPBDescriptor *descriptor = [self descriptor];
+ GPBExtensionDescriptor *extension =
+ [extensionRegistry extensionForDescriptor:descriptor
+ fieldNumber:fieldNumber];
+ if (extension == nil) {
+ if (descriptor.wireFormat && GPBWireFormatMessageSetItemTag == tag) {
+ [self parseMessageSet:input extensionRegistry:extensionRegistry];
+ return YES;
+ }
+ } else {
+ if (extension.wireType == wireType) {
+ GPBExtensionMergeFromInputStream(extension,
+ extension.packable,
+ input,
+ extensionRegistry,
+ self);
+ return YES;
+ }
+ // Primitive, repeated types can be packed on unpacked on the wire, and are
+ // parsed either way.
+ if ([extension isRepeated] &&
+ !GPBDataTypeIsObject(extension->description_->dataType) &&
+ (extension.alternateWireType == wireType)) {
+ GPBExtensionMergeFromInputStream(extension,
+ !extension.packable,
+ input,
+ extensionRegistry,
+ self);
+ return YES;
+ }
+ }
+ if ([GPBUnknownFieldSet isFieldTag:tag]) {
+ GPBUnknownFieldSet *unknownFields = GetOrMakeUnknownFields(self);
+ return [unknownFields mergeFieldFrom:tag input:input];
+ } else {
+ return NO;
+ }
+}
+
+- (void)addUnknownMapEntry:(int32_t)fieldNum value:(NSData *)data {
+ GPBUnknownFieldSet *unknownFields = GetOrMakeUnknownFields(self);
+ [unknownFields addUnknownMapEntry:fieldNum value:data];
+}
+
+#pragma mark - MergeFromCodedInputStream Support
+
+static void MergeSingleFieldFromCodedInputStream(
+ GPBMessage *self, GPBFieldDescriptor *field, GPBFileSyntax syntax,
+ GPBCodedInputStream *input, GPBExtensionRegistry *extensionRegistry) {
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ switch (fieldDataType) {
+#define CASE_SINGLE_POD(NAME, TYPE, FUNC_TYPE) \
+ case GPBDataType##NAME: { \
+ TYPE val = GPBCodedInputStreamRead##NAME(&input->state_); \
+ GPBSet##FUNC_TYPE##IvarWithFieldInternal(self, field, val, syntax); \
+ break; \
+ }
+#define CASE_SINGLE_OBJECT(NAME) \
+ case GPBDataType##NAME: { \
+ id val = GPBCodedInputStreamReadRetained##NAME(&input->state_); \
+ GPBSetRetainedObjectIvarWithFieldInternal(self, field, val, syntax); \
+ break; \
+ }
+ CASE_SINGLE_POD(Bool, BOOL, Bool)
+ CASE_SINGLE_POD(Fixed32, uint32_t, UInt32)
+ CASE_SINGLE_POD(SFixed32, int32_t, Int32)
+ CASE_SINGLE_POD(Float, float, Float)
+ CASE_SINGLE_POD(Fixed64, uint64_t, UInt64)
+ CASE_SINGLE_POD(SFixed64, int64_t, Int64)
+ CASE_SINGLE_POD(Double, double, Double)
+ CASE_SINGLE_POD(Int32, int32_t, Int32)
+ CASE_SINGLE_POD(Int64, int64_t, Int64)
+ CASE_SINGLE_POD(SInt32, int32_t, Int32)
+ CASE_SINGLE_POD(SInt64, int64_t, Int64)
+ CASE_SINGLE_POD(UInt32, uint32_t, UInt32)
+ CASE_SINGLE_POD(UInt64, uint64_t, UInt64)
+ CASE_SINGLE_OBJECT(Bytes)
+ CASE_SINGLE_OBJECT(String)
+#undef CASE_SINGLE_POD
+#undef CASE_SINGLE_OBJECT
+
+ case GPBDataTypeMessage: {
+ if (GPBGetHasIvarField(self, field)) {
+ // GPBGetObjectIvarWithFieldNoAutocreate() avoids doing the has
+ // check again.
+ GPBMessage *message =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [input readMessage:message extensionRegistry:extensionRegistry];
+ } else {
+ GPBMessage *message = [[field.msgClass alloc] init];
+ [input readMessage:message extensionRegistry:extensionRegistry];
+ GPBSetRetainedObjectIvarWithFieldInternal(self, field, message, syntax);
+ }
+ break;
+ }
+
+ case GPBDataTypeGroup: {
+ if (GPBGetHasIvarField(self, field)) {
+ // GPBGetObjectIvarWithFieldNoAutocreate() avoids doing the has
+ // check again.
+ GPBMessage *message =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [input readGroup:GPBFieldNumber(field)
+ message:message
+ extensionRegistry:extensionRegistry];
+ } else {
+ GPBMessage *message = [[field.msgClass alloc] init];
+ [input readGroup:GPBFieldNumber(field)
+ message:message
+ extensionRegistry:extensionRegistry];
+ GPBSetRetainedObjectIvarWithFieldInternal(self, field, message, syntax);
+ }
+ break;
+ }
+
+ case GPBDataTypeEnum: {
+ int32_t val = GPBCodedInputStreamReadEnum(&input->state_);
+ if (GPBHasPreservingUnknownEnumSemantics(syntax) ||
+ [field isValidEnumValue:val]) {
+ GPBSetInt32IvarWithFieldInternal(self, field, val, syntax);
+ } else {
+ GPBUnknownFieldSet *unknownFields = GetOrMakeUnknownFields(self);
+ [unknownFields mergeVarintField:GPBFieldNumber(field) value:val];
+ }
+ }
+ } // switch
+}
+
+static void MergeRepeatedPackedFieldFromCodedInputStream(
+ GPBMessage *self, GPBFieldDescriptor *field, GPBFileSyntax syntax,
+ GPBCodedInputStream *input) {
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ GPBCodedInputStreamState *state = &input->state_;
+ id genericArray = GetOrCreateArrayIvarWithField(self, field, syntax);
+ int32_t length = GPBCodedInputStreamReadInt32(state);
+ size_t limit = GPBCodedInputStreamPushLimit(state, length);
+ while (GPBCodedInputStreamBytesUntilLimit(state) > 0) {
+ switch (fieldDataType) {
+#define CASE_REPEATED_PACKED_POD(NAME, TYPE, ARRAY_TYPE) \
+ case GPBDataType##NAME: { \
+ TYPE val = GPBCodedInputStreamRead##NAME(state); \
+ [(GPB##ARRAY_TYPE##Array *)genericArray addValue:val]; \
+ break; \
+ }
+ CASE_REPEATED_PACKED_POD(Bool, BOOL, Bool)
+ CASE_REPEATED_PACKED_POD(Fixed32, uint32_t, UInt32)
+ CASE_REPEATED_PACKED_POD(SFixed32, int32_t, Int32)
+ CASE_REPEATED_PACKED_POD(Float, float, Float)
+ CASE_REPEATED_PACKED_POD(Fixed64, uint64_t, UInt64)
+ CASE_REPEATED_PACKED_POD(SFixed64, int64_t, Int64)
+ CASE_REPEATED_PACKED_POD(Double, double, Double)
+ CASE_REPEATED_PACKED_POD(Int32, int32_t, Int32)
+ CASE_REPEATED_PACKED_POD(Int64, int64_t, Int64)
+ CASE_REPEATED_PACKED_POD(SInt32, int32_t, Int32)
+ CASE_REPEATED_PACKED_POD(SInt64, int64_t, Int64)
+ CASE_REPEATED_PACKED_POD(UInt32, uint32_t, UInt32)
+ CASE_REPEATED_PACKED_POD(UInt64, uint64_t, UInt64)
+#undef CASE_REPEATED_PACKED_POD
+
+ case GPBDataTypeBytes:
+ case GPBDataTypeString:
+ case GPBDataTypeMessage:
+ case GPBDataTypeGroup:
+ NSCAssert(NO, @"Non primitive types can't be packed");
+ break;
+
+ case GPBDataTypeEnum: {
+ int32_t val = GPBCodedInputStreamReadEnum(state);
+ if (GPBHasPreservingUnknownEnumSemantics(syntax) ||
+ [field isValidEnumValue:val]) {
+ [(GPBEnumArray*)genericArray addRawValue:val];
+ } else {
+ GPBUnknownFieldSet *unknownFields = GetOrMakeUnknownFields(self);
+ [unknownFields mergeVarintField:GPBFieldNumber(field) value:val];
+ }
+ break;
+ }
+ } // switch
+ } // while(BytesUntilLimit() > 0)
+ GPBCodedInputStreamPopLimit(state, limit);
+}
+
+static void MergeRepeatedNotPackedFieldFromCodedInputStream(
+ GPBMessage *self, GPBFieldDescriptor *field, GPBFileSyntax syntax,
+ GPBCodedInputStream *input, GPBExtensionRegistry *extensionRegistry) {
+ GPBCodedInputStreamState *state = &input->state_;
+ id genericArray = GetOrCreateArrayIvarWithField(self, field, syntax);
+ switch (GPBGetFieldDataType(field)) {
+#define CASE_REPEATED_NOT_PACKED_POD(NAME, TYPE, ARRAY_TYPE) \
+ case GPBDataType##NAME: { \
+ TYPE val = GPBCodedInputStreamRead##NAME(state); \
+ [(GPB##ARRAY_TYPE##Array *)genericArray addValue:val]; \
+ break; \
+ }
+#define CASE_REPEATED_NOT_PACKED_OBJECT(NAME) \
+ case GPBDataType##NAME: { \
+ id val = GPBCodedInputStreamReadRetained##NAME(state); \
+ [(NSMutableArray*)genericArray addObject:val]; \
+ [val release]; \
+ break; \
+ }
+ CASE_REPEATED_NOT_PACKED_POD(Bool, BOOL, Bool)
+ CASE_REPEATED_NOT_PACKED_POD(Fixed32, uint32_t, UInt32)
+ CASE_REPEATED_NOT_PACKED_POD(SFixed32, int32_t, Int32)
+ CASE_REPEATED_NOT_PACKED_POD(Float, float, Float)
+ CASE_REPEATED_NOT_PACKED_POD(Fixed64, uint64_t, UInt64)
+ CASE_REPEATED_NOT_PACKED_POD(SFixed64, int64_t, Int64)
+ CASE_REPEATED_NOT_PACKED_POD(Double, double, Double)
+ CASE_REPEATED_NOT_PACKED_POD(Int32, int32_t, Int32)
+ CASE_REPEATED_NOT_PACKED_POD(Int64, int64_t, Int64)
+ CASE_REPEATED_NOT_PACKED_POD(SInt32, int32_t, Int32)
+ CASE_REPEATED_NOT_PACKED_POD(SInt64, int64_t, Int64)
+ CASE_REPEATED_NOT_PACKED_POD(UInt32, uint32_t, UInt32)
+ CASE_REPEATED_NOT_PACKED_POD(UInt64, uint64_t, UInt64)
+ CASE_REPEATED_NOT_PACKED_OBJECT(Bytes)
+ CASE_REPEATED_NOT_PACKED_OBJECT(String)
+#undef CASE_REPEATED_NOT_PACKED_POD
+#undef CASE_NOT_PACKED_OBJECT
+ case GPBDataTypeMessage: {
+ GPBMessage *message = [[field.msgClass alloc] init];
+ [input readMessage:message extensionRegistry:extensionRegistry];
+ [(NSMutableArray*)genericArray addObject:message];
+ [message release];
+ break;
+ }
+ case GPBDataTypeGroup: {
+ GPBMessage *message = [[field.msgClass alloc] init];
+ [input readGroup:GPBFieldNumber(field)
+ message:message
+ extensionRegistry:extensionRegistry];
+ [(NSMutableArray*)genericArray addObject:message];
+ [message release];
+ break;
+ }
+ case GPBDataTypeEnum: {
+ int32_t val = GPBCodedInputStreamReadEnum(state);
+ if (GPBHasPreservingUnknownEnumSemantics(syntax) ||
+ [field isValidEnumValue:val]) {
+ [(GPBEnumArray*)genericArray addRawValue:val];
+ } else {
+ GPBUnknownFieldSet *unknownFields = GetOrMakeUnknownFields(self);
+ [unknownFields mergeVarintField:GPBFieldNumber(field) value:val];
+ }
+ break;
+ }
+ } // switch
+}
+
+- (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ GPBDescriptor *descriptor = [self descriptor];
+ GPBFileSyntax syntax = descriptor.file.syntax;
+ GPBCodedInputStreamState *state = &input->state_;
+ uint32_t tag = 0;
+ NSUInteger startingIndex = 0;
+ NSArray *fields = descriptor->fields_;
+ NSUInteger numFields = fields.count;
+ while (YES) {
+ BOOL merged = NO;
+ tag = GPBCodedInputStreamReadTag(state);
+ if (tag == 0) {
+ break; // Reached end.
+ }
+ for (NSUInteger i = 0; i < numFields; ++i) {
+ if (startingIndex >= numFields) startingIndex = 0;
+ GPBFieldDescriptor *fieldDescriptor = fields[startingIndex];
+ if (GPBFieldTag(fieldDescriptor) == tag) {
+ GPBFieldType fieldType = fieldDescriptor.fieldType;
+ if (fieldType == GPBFieldTypeSingle) {
+ MergeSingleFieldFromCodedInputStream(self, fieldDescriptor, syntax,
+ input, extensionRegistry);
+ // Well formed protos will only have a single field once, advance
+ // the starting index to the next field.
+ startingIndex += 1;
+ } else if (fieldType == GPBFieldTypeRepeated) {
+ if (fieldDescriptor.isPackable) {
+ MergeRepeatedPackedFieldFromCodedInputStream(
+ self, fieldDescriptor, syntax, input);
+ // Well formed protos will only have a repeated field that is
+ // packed once, advance the starting index to the next field.
+ startingIndex += 1;
+ } else {
+ MergeRepeatedNotPackedFieldFromCodedInputStream(
+ self, fieldDescriptor, syntax, input, extensionRegistry);
+ }
+ } else { // fieldType == GPBFieldTypeMap
+ // GPB*Dictionary or NSDictionary, exact type doesn't matter at this
+ // point.
+ id map = GetOrCreateMapIvarWithField(self, fieldDescriptor, syntax);
+ [input readMapEntry:map
+ extensionRegistry:extensionRegistry
+ field:fieldDescriptor
+ parentMessage:self];
+ }
+ merged = YES;
+ break;
+ } else {
+ startingIndex += 1;
+ }
+ } // for(i < numFields)
+
+ if (!merged && (tag != 0)) {
+ // Primitive, repeated types can be packed on unpacked on the wire, and
+ // are parsed either way. The above loop covered tag in the preferred
+ // for, so this need to check the alternate form.
+ for (NSUInteger i = 0; i < numFields; ++i) {
+ if (startingIndex >= numFields) startingIndex = 0;
+ GPBFieldDescriptor *fieldDescriptor = fields[startingIndex];
+ if ((fieldDescriptor.fieldType == GPBFieldTypeRepeated) &&
+ !GPBFieldDataTypeIsObject(fieldDescriptor) &&
+ (GPBFieldAlternateTag(fieldDescriptor) == tag)) {
+ BOOL alternateIsPacked = !fieldDescriptor.isPackable;
+ if (alternateIsPacked) {
+ MergeRepeatedPackedFieldFromCodedInputStream(
+ self, fieldDescriptor, syntax, input);
+ // Well formed protos will only have a repeated field that is
+ // packed once, advance the starting index to the next field.
+ startingIndex += 1;
+ } else {
+ MergeRepeatedNotPackedFieldFromCodedInputStream(
+ self, fieldDescriptor, syntax, input, extensionRegistry);
+ }
+ merged = YES;
+ break;
+ } else {
+ startingIndex += 1;
+ }
+ }
+ }
+
+ if (!merged) {
+ if (tag == 0) {
+ // zero signals EOF / limit reached
+ return;
+ } else {
+ if (GPBPreserveUnknownFields(syntax)) {
+ if (![self parseUnknownField:input
+ extensionRegistry:extensionRegistry
+ tag:tag]) {
+ // it's an endgroup tag
+ return;
+ }
+ } else {
+ if (![input skipField:tag]) {
+ return;
+ }
+ }
+ }
+ } // if(!merged)
+
+ } // while(YES)
+}
+
+#pragma mark - MergeFrom Support
+
+- (void)mergeFrom:(GPBMessage *)other {
+ Class selfClass = [self class];
+ Class otherClass = [other class];
+ if (!([selfClass isSubclassOfClass:otherClass] ||
+ [otherClass isSubclassOfClass:selfClass])) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Classes must match %@ != %@", selfClass, otherClass];
+ }
+
+ // We assume something will be done and become visible.
+ GPBBecomeVisibleToAutocreator(self);
+
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ GPBFileSyntax syntax = descriptor.file.syntax;
+
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ GPBFieldType fieldType = field.fieldType;
+ if (fieldType == GPBFieldTypeSingle) {
+ int32_t hasIndex = GPBFieldHasIndex(field);
+ uint32_t fieldNumber = GPBFieldNumber(field);
+ if (!GPBGetHasIvar(other, hasIndex, fieldNumber)) {
+ // Other doesn't have the field set, on to the next.
+ continue;
+ }
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ switch (fieldDataType) {
+ case GPBDataTypeBool:
+ GPBSetBoolIvarWithFieldInternal(
+ self, field, GPBGetMessageBoolField(other, field), syntax);
+ break;
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeEnum:
+ case GPBDataTypeInt32:
+ case GPBDataTypeSInt32:
+ GPBSetInt32IvarWithFieldInternal(
+ self, field, GPBGetMessageInt32Field(other, field), syntax);
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ GPBSetUInt32IvarWithFieldInternal(
+ self, field, GPBGetMessageUInt32Field(other, field), syntax);
+ break;
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeInt64:
+ case GPBDataTypeSInt64:
+ GPBSetInt64IvarWithFieldInternal(
+ self, field, GPBGetMessageInt64Field(other, field), syntax);
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ GPBSetUInt64IvarWithFieldInternal(
+ self, field, GPBGetMessageUInt64Field(other, field), syntax);
+ break;
+ case GPBDataTypeFloat:
+ GPBSetFloatIvarWithFieldInternal(
+ self, field, GPBGetMessageFloatField(other, field), syntax);
+ break;
+ case GPBDataTypeDouble:
+ GPBSetDoubleIvarWithFieldInternal(
+ self, field, GPBGetMessageDoubleField(other, field), syntax);
+ break;
+ case GPBDataTypeBytes:
+ case GPBDataTypeString: {
+ id otherVal = GPBGetObjectIvarWithFieldNoAutocreate(other, field);
+ GPBSetObjectIvarWithFieldInternal(self, field, otherVal, syntax);
+ break;
+ }
+ case GPBDataTypeMessage:
+ case GPBDataTypeGroup: {
+ id otherVal = GPBGetObjectIvarWithFieldNoAutocreate(other, field);
+ if (GPBGetHasIvar(self, hasIndex, fieldNumber)) {
+ GPBMessage *message =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ [message mergeFrom:otherVal];
+ } else {
+ GPBMessage *message = [otherVal copy];
+ GPBSetRetainedObjectIvarWithFieldInternal(self, field, message,
+ syntax);
+ }
+ break;
+ }
+ } // switch()
+ } else if (fieldType == GPBFieldTypeRepeated) {
+ // In the case of a list, they need to be appended, and there is no
+ // _hasIvar to worry about setting.
+ id otherArray =
+ GPBGetObjectIvarWithFieldNoAutocreate(other, field);
+ if (otherArray) {
+ GPBDataType fieldDataType = field->description_->dataType;
+ if (GPBDataTypeIsObject(fieldDataType)) {
+ NSMutableArray *resultArray =
+ GetOrCreateArrayIvarWithField(self, field, syntax);
+ [resultArray addObjectsFromArray:otherArray];
+ } else if (fieldDataType == GPBDataTypeEnum) {
+ GPBEnumArray *resultArray =
+ GetOrCreateArrayIvarWithField(self, field, syntax);
+ [resultArray addRawValuesFromArray:otherArray];
+ } else {
+ // The array type doesn't matter, that all implment
+ // -addValuesFromArray:.
+ GPBInt32Array *resultArray =
+ GetOrCreateArrayIvarWithField(self, field, syntax);
+ [resultArray addValuesFromArray:otherArray];
+ }
+ }
+ } else { // fieldType = GPBFieldTypeMap
+ // In the case of a map, they need to be merged, and there is no
+ // _hasIvar to worry about setting.
+ id otherDict = GPBGetObjectIvarWithFieldNoAutocreate(other, field);
+ if (otherDict) {
+ GPBDataType keyDataType = field.mapKeyDataType;
+ GPBDataType valueDataType = field->description_->dataType;
+ if (GPBDataTypeIsObject(keyDataType) &&
+ GPBDataTypeIsObject(valueDataType)) {
+ NSMutableDictionary *resultDict =
+ GetOrCreateMapIvarWithField(self, field, syntax);
+ [resultDict addEntriesFromDictionary:otherDict];
+ } else if (valueDataType == GPBDataTypeEnum) {
+ // The exact type doesn't matter, just need to know it is a
+ // GPB*EnumDictionary.
+ GPBInt32EnumDictionary *resultDict =
+ GetOrCreateMapIvarWithField(self, field, syntax);
+ [resultDict addRawEntriesFromDictionary:otherDict];
+ } else {
+ // The exact type doesn't matter, they all implement
+ // -addEntriesFromDictionary:.
+ GPBInt32Int32Dictionary *resultDict =
+ GetOrCreateMapIvarWithField(self, field, syntax);
+ [resultDict addEntriesFromDictionary:otherDict];
+ }
+ }
+ } // if (fieldType)..else if...else
+ } // for(fields)
+
+ // Unknown fields.
+ if (!unknownFields_) {
+ [self setUnknownFields:other.unknownFields];
+ } else {
+ [unknownFields_ mergeUnknownFields:other.unknownFields];
+ }
+
+ // Extensions
+
+ if (other->extensionMap_.count == 0) {
+ return;
+ }
+
+ if (extensionMap_ == nil) {
+ extensionMap_ =
+ CloneExtensionMap(other->extensionMap_, NSZoneFromPointer(self));
+ } else {
+ for (GPBExtensionDescriptor *extension in other->extensionMap_) {
+ id otherValue = [other->extensionMap_ objectForKey:extension];
+ id value = [extensionMap_ objectForKey:extension];
+ BOOL isMessageExtension = GPBExtensionIsMessage(extension);
+
+ if (extension.repeated) {
+ NSMutableArray *list = value;
+ if (list == nil) {
+ list = [[NSMutableArray alloc] init];
+ [extensionMap_ setObject:list forKey:extension];
+ [list release];
+ }
+ if (isMessageExtension) {
+ for (GPBMessage *otherListValue in otherValue) {
+ GPBMessage *copiedValue = [otherListValue copy];
+ [list addObject:copiedValue];
+ [copiedValue release];
+ }
+ } else {
+ [list addObjectsFromArray:otherValue];
+ }
+ } else {
+ if (isMessageExtension) {
+ if (value) {
+ [(GPBMessage *)value mergeFrom:(GPBMessage *)otherValue];
+ } else {
+ GPBMessage *copiedValue = [otherValue copy];
+ [extensionMap_ setObject:copiedValue forKey:extension];
+ [copiedValue release];
+ }
+ } else {
+ [extensionMap_ setObject:otherValue forKey:extension];
+ }
+ }
+
+ if (isMessageExtension && !extension.isRepeated) {
+ GPBMessage *autocreatedValue =
+ [[autocreatedExtensionMap_ objectForKey:extension] retain];
+ // Must remove from the map before calling GPBClearMessageAutocreator()
+ // so that GPBClearMessageAutocreator() knows its safe to clear.
+ [autocreatedExtensionMap_ removeObjectForKey:extension];
+ GPBClearMessageAutocreator(autocreatedValue);
+ [autocreatedValue release];
+ }
+ }
+ }
+}
+
+#pragma mark - isEqual: & hash Support
+
+- (BOOL)isEqual:(id)other {
+ if (other == self) {
+ return YES;
+ }
+ if (![other isKindOfClass:[self class]] &&
+ ![self isKindOfClass:[other class]]) {
+ return NO;
+ }
+
+ GPBMessage *otherMsg = other;
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ uint8_t *selfStorage = (uint8_t *)messageStorage_;
+ uint8_t *otherStorage = (uint8_t *)otherMsg->messageStorage_;
+
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ if (GPBFieldIsMapOrArray(field)) {
+ // In the case of a list or map, there is no _hasIvar to worry about.
+ // NOTE: These are NSArray/GPB*Array or NSDictionary/GPB*Dictionary, but
+ // the type doesn't really matter as the objects all support -count and
+ // -isEqual:.
+ NSArray *resultMapOrArray =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ NSArray *otherMapOrArray =
+ GPBGetObjectIvarWithFieldNoAutocreate(other, field);
+ // nil and empty are equal
+ if (resultMapOrArray.count != 0 || otherMapOrArray.count != 0) {
+ if (![resultMapOrArray isEqual:otherMapOrArray]) {
+ return NO;
+ }
+ }
+ } else { // Single field
+ int32_t hasIndex = GPBFieldHasIndex(field);
+ uint32_t fieldNum = GPBFieldNumber(field);
+ BOOL selfHas = GPBGetHasIvar(self, hasIndex, fieldNum);
+ BOOL otherHas = GPBGetHasIvar(other, hasIndex, fieldNum);
+ if (selfHas != otherHas) {
+ return NO; // Differing has values, not equal.
+ }
+ if (!selfHas) {
+ // Same has values, was no, nothing else to check for this field.
+ continue;
+ }
+ // Now compare the values.
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ size_t fieldOffset = field->description_->offset;
+ switch (fieldDataType) {
+ case GPBDataTypeBool: {
+ // Bools are stored in has_bits to avoid needing explicit space in
+ // the storage structure.
+ // (the field number passed to the HasIvar helper doesn't really
+ // matter since the offset is never negative)
+ BOOL selfValue = GPBGetHasIvar(self, (int32_t)(fieldOffset), 0);
+ BOOL otherValue = GPBGetHasIvar(other, (int32_t)(fieldOffset), 0);
+ if (selfValue != otherValue) {
+ return NO;
+ }
+ break;
+ }
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeInt32:
+ case GPBDataTypeSInt32:
+ case GPBDataTypeEnum:
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ case GPBDataTypeFloat: {
+ GPBInternalCompileAssert(sizeof(float) == sizeof(uint32_t), float_not_32_bits);
+ // These are all 32bit, signed/unsigned doesn't matter for equality.
+ uint32_t *selfValPtr = (uint32_t *)&selfStorage[fieldOffset];
+ uint32_t *otherValPtr = (uint32_t *)&otherStorage[fieldOffset];
+ if (*selfValPtr != *otherValPtr) {
+ return NO;
+ }
+ break;
+ }
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeInt64:
+ case GPBDataTypeSInt64:
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ case GPBDataTypeDouble: {
+ GPBInternalCompileAssert(sizeof(double) == sizeof(uint64_t), double_not_64_bits);
+ // These are all 64bit, signed/unsigned doesn't matter for equality.
+ uint64_t *selfValPtr = (uint64_t *)&selfStorage[fieldOffset];
+ uint64_t *otherValPtr = (uint64_t *)&otherStorage[fieldOffset];
+ if (*selfValPtr != *otherValPtr) {
+ return NO;
+ }
+ break;
+ }
+ case GPBDataTypeBytes:
+ case GPBDataTypeString:
+ case GPBDataTypeMessage:
+ case GPBDataTypeGroup: {
+ // Type doesn't matter here, they all implement -isEqual:.
+ id *selfValPtr = (id *)&selfStorage[fieldOffset];
+ id *otherValPtr = (id *)&otherStorage[fieldOffset];
+ if (![*selfValPtr isEqual:*otherValPtr]) {
+ return NO;
+ }
+ break;
+ }
+ } // switch()
+ } // if(mapOrArray)...else
+ } // for(fields)
+
+ // nil and empty are equal
+ if (extensionMap_.count != 0 || otherMsg->extensionMap_.count != 0) {
+ if (![extensionMap_ isEqual:otherMsg->extensionMap_]) {
+ return NO;
+ }
+ }
+
+ // nil and empty are equal
+ GPBUnknownFieldSet *otherUnknowns = otherMsg->unknownFields_;
+ if ([unknownFields_ countOfFields] != 0 ||
+ [otherUnknowns countOfFields] != 0) {
+ if (![unknownFields_ isEqual:otherUnknowns]) {
+ return NO;
+ }
+ }
+
+ return YES;
+}
+
+// It is very difficult to implement a generic hash for ProtoBuf messages that
+// will perform well. If you need hashing on your ProtoBufs (eg you are using
+// them as dictionary keys) you will probably want to implement a ProtoBuf
+// message specific hash as a category on your protobuf class. Do not make it a
+// category on GPBMessage as you will conflict with this hash, and will possibly
+// override hash for all generated protobufs. A good implementation of hash will
+// be really fast, so we would recommend only hashing protobufs that have an
+// identifier field of some kind that you can easily hash. If you implement
+// hash, we would strongly recommend overriding isEqual: in your category as
+// well, as the default implementation of isEqual: is extremely slow, and may
+// drastically affect performance in large sets.
+- (NSUInteger)hash {
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ const NSUInteger prime = 19;
+ uint8_t *storage = (uint8_t *)messageStorage_;
+
+ // Start with the descriptor and then mix it with some instance info.
+ // Hopefully that will give a spread based on classes and what fields are set.
+ NSUInteger result = (NSUInteger)descriptor;
+
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ if (GPBFieldIsMapOrArray(field)) {
+ // Exact type doesn't matter, just check if there are any elements.
+ NSArray *mapOrArray = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ NSUInteger count = mapOrArray.count;
+ if (count) {
+ // NSArray/NSDictionary use count, use the field number and the count.
+ result = prime * result + GPBFieldNumber(field);
+ result = prime * result + count;
+ }
+ } else if (GPBGetHasIvarField(self, field)) {
+ // Just using the field number seemed simple/fast, but then a small
+ // message class where all the same fields are always set (to different
+ // things would end up all with the same hash, so pull in some data).
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ size_t fieldOffset = field->description_->offset;
+ switch (fieldDataType) {
+ case GPBDataTypeBool: {
+ // Bools are stored in has_bits to avoid needing explicit space in
+ // the storage structure.
+ // (the field number passed to the HasIvar helper doesn't really
+ // matter since the offset is never negative)
+ BOOL value = GPBGetHasIvar(self, (int32_t)(fieldOffset), 0);
+ result = prime * result + value;
+ break;
+ }
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeInt32:
+ case GPBDataTypeSInt32:
+ case GPBDataTypeEnum:
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ case GPBDataTypeFloat: {
+ GPBInternalCompileAssert(sizeof(float) == sizeof(uint32_t), float_not_32_bits);
+ // These are all 32bit, just mix it in.
+ uint32_t *valPtr = (uint32_t *)&storage[fieldOffset];
+ result = prime * result + *valPtr;
+ break;
+ }
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeInt64:
+ case GPBDataTypeSInt64:
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ case GPBDataTypeDouble: {
+ GPBInternalCompileAssert(sizeof(double) == sizeof(uint64_t), double_not_64_bits);
+ // These are all 64bit, just mix what fits into an NSUInteger in.
+ uint64_t *valPtr = (uint64_t *)&storage[fieldOffset];
+ result = prime * result + (NSUInteger)(*valPtr);
+ break;
+ }
+ case GPBDataTypeBytes:
+ case GPBDataTypeString: {
+ // Type doesn't matter here, they both implement -hash:.
+ id *valPtr = (id *)&storage[fieldOffset];
+ result = prime * result + [*valPtr hash];
+ break;
+ }
+
+ case GPBDataTypeMessage:
+ case GPBDataTypeGroup: {
+ GPBMessage **valPtr = (GPBMessage **)&storage[fieldOffset];
+ // Could call -hash on the sub message, but that could recurse pretty
+ // deep; follow the lead of NSArray/NSDictionary and don't really
+ // recurse for hash, instead use the field number and the descriptor
+ // of the sub message. Yes, this could suck for a bunch of messages
+ // where they all only differ in the sub messages, but if you are
+ // using a message with sub messages for something that needs -hash,
+ // odds are you are also copying them as keys, and that deep copy
+ // will also suck.
+ result = prime * result + GPBFieldNumber(field);
+ result = prime * result + (NSUInteger)[[*valPtr class] descriptor];
+ break;
+ }
+ } // switch()
+ }
+ }
+
+ // Unknowns and extensions are not included.
+
+ return result;
+}
+
+#pragma mark - Description Support
+
+- (NSString *)description {
+ NSString *textFormat = GPBTextFormatForMessage(self, @" ");
+ NSString *description = [NSString
+ stringWithFormat:@"<%@ %p>: {\n%@}", [self class], self, textFormat];
+ return description;
+}
+
+#if defined(DEBUG) && DEBUG
+
+// Xcode 5.1 added support for custom quick look info.
+// https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/CustomClassDisplay_in_QuickLook/CH01-quick_look_for_custom_objects/CH01-quick_look_for_custom_objects.html#//apple_ref/doc/uid/TP40014001-CH2-SW1
+- (id)debugQuickLookObject {
+ return GPBTextFormatForMessage(self, nil);
+}
+
+#endif // DEBUG
+
+#pragma mark - SerializedSize
+
+- (size_t)serializedSize {
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ size_t result = 0;
+
+ // Has check is done explicitly, so GPBGetObjectIvarWithFieldNoAutocreate()
+ // avoids doing the has check again.
+
+ // Fields.
+ for (GPBFieldDescriptor *fieldDescriptor in descriptor->fields_) {
+ GPBFieldType fieldType = fieldDescriptor.fieldType;
+ GPBDataType fieldDataType = GPBGetFieldDataType(fieldDescriptor);
+
+ // Single Fields
+ if (fieldType == GPBFieldTypeSingle) {
+ BOOL selfHas = GPBGetHasIvarField(self, fieldDescriptor);
+ if (!selfHas) {
+ continue; // Nothing to do.
+ }
+
+ uint32_t fieldNumber = GPBFieldNumber(fieldDescriptor);
+
+ switch (fieldDataType) {
+#define CASE_SINGLE_POD(NAME, TYPE, FUNC_TYPE) \
+ case GPBDataType##NAME: { \
+ TYPE fieldVal = GPBGetMessage##FUNC_TYPE##Field(self, fieldDescriptor); \
+ result += GPBCompute##NAME##Size(fieldNumber, fieldVal); \
+ break; \
+ }
+#define CASE_SINGLE_OBJECT(NAME) \
+ case GPBDataType##NAME: { \
+ id fieldVal = GPBGetObjectIvarWithFieldNoAutocreate(self, fieldDescriptor); \
+ result += GPBCompute##NAME##Size(fieldNumber, fieldVal); \
+ break; \
+ }
+ CASE_SINGLE_POD(Bool, BOOL, Bool)
+ CASE_SINGLE_POD(Fixed32, uint32_t, UInt32)
+ CASE_SINGLE_POD(SFixed32, int32_t, Int32)
+ CASE_SINGLE_POD(Float, float, Float)
+ CASE_SINGLE_POD(Fixed64, uint64_t, UInt64)
+ CASE_SINGLE_POD(SFixed64, int64_t, Int64)
+ CASE_SINGLE_POD(Double, double, Double)
+ CASE_SINGLE_POD(Int32, int32_t, Int32)
+ CASE_SINGLE_POD(Int64, int64_t, Int64)
+ CASE_SINGLE_POD(SInt32, int32_t, Int32)
+ CASE_SINGLE_POD(SInt64, int64_t, Int64)
+ CASE_SINGLE_POD(UInt32, uint32_t, UInt32)
+ CASE_SINGLE_POD(UInt64, uint64_t, UInt64)
+ CASE_SINGLE_OBJECT(Bytes)
+ CASE_SINGLE_OBJECT(String)
+ CASE_SINGLE_OBJECT(Message)
+ CASE_SINGLE_OBJECT(Group)
+ CASE_SINGLE_POD(Enum, int32_t, Int32)
+#undef CASE_SINGLE_POD
+#undef CASE_SINGLE_OBJECT
+ }
+
+ // Repeated Fields
+ } else if (fieldType == GPBFieldTypeRepeated) {
+ id genericArray =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, fieldDescriptor);
+ NSUInteger count = [genericArray count];
+ if (count == 0) {
+ continue; // Nothing to add.
+ }
+ __block size_t dataSize = 0;
+
+ switch (fieldDataType) {
+#define CASE_REPEATED_POD(NAME, TYPE, ARRAY_TYPE) \
+ CASE_REPEATED_POD_EXTRA(NAME, TYPE, ARRAY_TYPE, )
+#define CASE_REPEATED_POD_EXTRA(NAME, TYPE, ARRAY_TYPE, ARRAY_ACCESSOR_NAME) \
+ case GPBDataType##NAME: { \
+ GPB##ARRAY_TYPE##Array *array = genericArray; \
+ [array enumerate##ARRAY_ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) { \
+ _Pragma("unused(idx, stop)"); \
+ dataSize += GPBCompute##NAME##SizeNoTag(value); \
+ }]; \
+ break; \
+ }
+#define CASE_REPEATED_OBJECT(NAME) \
+ case GPBDataType##NAME: { \
+ for (id value in genericArray) { \
+ dataSize += GPBCompute##NAME##SizeNoTag(value); \
+ } \
+ break; \
+ }
+ CASE_REPEATED_POD(Bool, BOOL, Bool)
+ CASE_REPEATED_POD(Fixed32, uint32_t, UInt32)
+ CASE_REPEATED_POD(SFixed32, int32_t, Int32)
+ CASE_REPEATED_POD(Float, float, Float)
+ CASE_REPEATED_POD(Fixed64, uint64_t, UInt64)
+ CASE_REPEATED_POD(SFixed64, int64_t, Int64)
+ CASE_REPEATED_POD(Double, double, Double)
+ CASE_REPEATED_POD(Int32, int32_t, Int32)
+ CASE_REPEATED_POD(Int64, int64_t, Int64)
+ CASE_REPEATED_POD(SInt32, int32_t, Int32)
+ CASE_REPEATED_POD(SInt64, int64_t, Int64)
+ CASE_REPEATED_POD(UInt32, uint32_t, UInt32)
+ CASE_REPEATED_POD(UInt64, uint64_t, UInt64)
+ CASE_REPEATED_OBJECT(Bytes)
+ CASE_REPEATED_OBJECT(String)
+ CASE_REPEATED_OBJECT(Message)
+ CASE_REPEATED_OBJECT(Group)
+ CASE_REPEATED_POD_EXTRA(Enum, int32_t, Enum, Raw)
+#undef CASE_REPEATED_POD
+#undef CASE_REPEATED_POD_EXTRA
+#undef CASE_REPEATED_OBJECT
+ } // switch
+ result += dataSize;
+ size_t tagSize = GPBComputeTagSize(GPBFieldNumber(fieldDescriptor));
+ if (fieldDataType == GPBDataTypeGroup) {
+ // Groups have both a start and an end tag.
+ tagSize *= 2;
+ }
+ if (fieldDescriptor.isPackable) {
+ result += tagSize;
+ result += GPBComputeSizeTSizeAsInt32NoTag(dataSize);
+ } else {
+ result += count * tagSize;
+ }
+
+ // Map<> Fields
+ } else { // fieldType == GPBFieldTypeMap
+ if (GPBDataTypeIsObject(fieldDataType) &&
+ (fieldDescriptor.mapKeyDataType == GPBDataTypeString)) {
+ // If key type was string, then the map is an NSDictionary.
+ NSDictionary *map =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, fieldDescriptor);
+ if (map) {
+ result += GPBDictionaryComputeSizeInternalHelper(map, fieldDescriptor);
+ }
+ } else {
+ // Type will be GPB*GroupDictionary, exact type doesn't matter.
+ GPBInt32Int32Dictionary *map =
+ GPBGetObjectIvarWithFieldNoAutocreate(self, fieldDescriptor);
+ result += [map computeSerializedSizeAsField:fieldDescriptor];
+ }
+ }
+ } // for(fields)
+
+ // Add any unknown fields.
+ if (descriptor.wireFormat) {
+ result += [unknownFields_ serializedSizeAsMessageSet];
+ } else {
+ result += [unknownFields_ serializedSize];
+ }
+
+ // Add any extensions.
+ for (GPBExtensionDescriptor *extension in extensionMap_) {
+ id value = [extensionMap_ objectForKey:extension];
+ result += GPBComputeExtensionSerializedSizeIncludingTag(extension, value);
+ }
+
+ return result;
+}
+
+#pragma mark - Resolve Methods Support
+
+typedef struct ResolveIvarAccessorMethodResult {
+ IMP impToAdd;
+ SEL encodingSelector;
+} ResolveIvarAccessorMethodResult;
+
+static void ResolveIvarGet(GPBFieldDescriptor *field,
+ ResolveIvarAccessorMethodResult *result) {
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ switch (fieldDataType) {
+#define CASE_GET(NAME, TYPE, TRUE_NAME) \
+ case GPBDataType##NAME: { \
+ result->impToAdd = imp_implementationWithBlock(^(id obj) { \
+ return GPBGetMessage##TRUE_NAME##Field(obj, field); \
+ }); \
+ result->encodingSelector = @selector(get##NAME); \
+ break; \
+ }
+#define CASE_GET_OBJECT(NAME, TYPE, TRUE_NAME) \
+ case GPBDataType##NAME: { \
+ result->impToAdd = imp_implementationWithBlock(^(id obj) { \
+ return GPBGetObjectIvarWithField(obj, field); \
+ }); \
+ result->encodingSelector = @selector(get##NAME); \
+ break; \
+ }
+ CASE_GET(Bool, BOOL, Bool)
+ CASE_GET(Fixed32, uint32_t, UInt32)
+ CASE_GET(SFixed32, int32_t, Int32)
+ CASE_GET(Float, float, Float)
+ CASE_GET(Fixed64, uint64_t, UInt64)
+ CASE_GET(SFixed64, int64_t, Int64)
+ CASE_GET(Double, double, Double)
+ CASE_GET(Int32, int32_t, Int32)
+ CASE_GET(Int64, int64_t, Int64)
+ CASE_GET(SInt32, int32_t, Int32)
+ CASE_GET(SInt64, int64_t, Int64)
+ CASE_GET(UInt32, uint32_t, UInt32)
+ CASE_GET(UInt64, uint64_t, UInt64)
+ CASE_GET_OBJECT(Bytes, id, Object)
+ CASE_GET_OBJECT(String, id, Object)
+ CASE_GET_OBJECT(Message, id, Object)
+ CASE_GET_OBJECT(Group, id, Object)
+ CASE_GET(Enum, int32_t, Enum)
+#undef CASE_GET
+ }
+}
+
+static void ResolveIvarSet(GPBFieldDescriptor *field,
+ GPBFileSyntax syntax,
+ ResolveIvarAccessorMethodResult *result) {
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ switch (fieldDataType) {
+#define CASE_SET(NAME, TYPE, TRUE_NAME) \
+ case GPBDataType##NAME: { \
+ result->impToAdd = imp_implementationWithBlock(^(id obj, TYPE value) { \
+ return GPBSet##TRUE_NAME##IvarWithFieldInternal(obj, field, value, syntax); \
+ }); \
+ result->encodingSelector = @selector(set##NAME:); \
+ break; \
+ }
+ CASE_SET(Bool, BOOL, Bool)
+ CASE_SET(Fixed32, uint32_t, UInt32)
+ CASE_SET(SFixed32, int32_t, Int32)
+ CASE_SET(Float, float, Float)
+ CASE_SET(Fixed64, uint64_t, UInt64)
+ CASE_SET(SFixed64, int64_t, Int64)
+ CASE_SET(Double, double, Double)
+ CASE_SET(Int32, int32_t, Int32)
+ CASE_SET(Int64, int64_t, Int64)
+ CASE_SET(SInt32, int32_t, Int32)
+ CASE_SET(SInt64, int64_t, Int64)
+ CASE_SET(UInt32, uint32_t, UInt32)
+ CASE_SET(UInt64, uint64_t, UInt64)
+ CASE_SET(Bytes, id, Object)
+ CASE_SET(String, id, Object)
+ CASE_SET(Message, id, Object)
+ CASE_SET(Group, id, Object)
+ CASE_SET(Enum, int32_t, Enum)
+#undef CASE_SET
+ }
+}
+
++ (BOOL)resolveInstanceMethod:(SEL)sel {
+ const GPBDescriptor *descriptor = [self descriptor];
+ if (!descriptor) {
+ return NO;
+ }
+
+ // NOTE: hasOrCountSel_/setHasSel_ will be NULL if the field for the given
+ // message should not have has support (done in GPBDescriptor.m), so there is
+ // no need for checks here to see if has*/setHas* are allowed.
+
+ ResolveIvarAccessorMethodResult result = {NULL, NULL};
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ BOOL isMapOrArray = GPBFieldIsMapOrArray(field);
+ if (!isMapOrArray) {
+ // Single fields.
+ if (sel == field->getSel_) {
+ ResolveIvarGet(field, &result);
+ break;
+ } else if (sel == field->setSel_) {
+ ResolveIvarSet(field, descriptor.file.syntax, &result);
+ break;
+ } else if (sel == field->hasOrCountSel_) {
+ int32_t index = GPBFieldHasIndex(field);
+ uint32_t fieldNum = GPBFieldNumber(field);
+ result.impToAdd = imp_implementationWithBlock(^(id obj) {
+ return GPBGetHasIvar(obj, index, fieldNum);
+ });
+ result.encodingSelector = @selector(getBool);
+ break;
+ } else if (sel == field->setHasSel_) {
+ result.impToAdd = imp_implementationWithBlock(^(id obj, BOOL value) {
+ if (value) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@: %@ can only be set to NO (to clear field).",
+ [obj class],
+ NSStringFromSelector(field->setHasSel_)];
+ }
+ GPBClearMessageField(obj, field);
+ });
+ result.encodingSelector = @selector(setBool:);
+ break;
+ } else {
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof && (sel == oneof->caseSel_)) {
+ int32_t index = GPBFieldHasIndex(field);
+ result.impToAdd = imp_implementationWithBlock(^(id obj) {
+ return GPBGetHasOneof(obj, index);
+ });
+ result.encodingSelector = @selector(getEnum);
+ break;
+ }
+ }
+ } else {
+ // map<>/repeated fields.
+ if (sel == field->getSel_) {
+ if (field.fieldType == GPBFieldTypeRepeated) {
+ result.impToAdd = imp_implementationWithBlock(^(id obj) {
+ return GetArrayIvarWithField(obj, field);
+ });
+ } else {
+ result.impToAdd = imp_implementationWithBlock(^(id obj) {
+ return GetMapIvarWithField(obj, field);
+ });
+ }
+ result.encodingSelector = @selector(getArray);
+ break;
+ } else if (sel == field->setSel_) {
+ // Local for syntax so the block can directly capture it and not the
+ // full lookup.
+ const GPBFileSyntax syntax = descriptor.file.syntax;
+ result.impToAdd = imp_implementationWithBlock(^(id obj, id value) {
+ return GPBSetObjectIvarWithFieldInternal(obj, field, value, syntax);
+ });
+ result.encodingSelector = @selector(setArray:);
+ break;
+ } else if (sel == field->hasOrCountSel_) {
+ result.impToAdd = imp_implementationWithBlock(^(id obj) {
+ // Type doesn't matter, all *Array and *Dictionary types support
+ // -count.
+ NSArray *arrayOrMap =
+ GPBGetObjectIvarWithFieldNoAutocreate(obj, field);
+ return [arrayOrMap count];
+ });
+ result.encodingSelector = @selector(getArrayCount);
+ break;
+ }
+ }
+ }
+ if (result.impToAdd) {
+ const char *encoding =
+ GPBMessageEncodingForSelector(result.encodingSelector, YES);
+ Class msgClass = descriptor.messageClass;
+ BOOL methodAdded = class_addMethod(msgClass, sel, result.impToAdd, encoding);
+ // class_addMethod() is documented as also failing if the method was already
+ // added; so we check if the method is already there and return success so
+ // the method dispatch will still happen. Why would it already be added?
+ // Two threads could cause the same method to be bound at the same time,
+ // but only one will actually bind it; the other still needs to return true
+ // so things will dispatch.
+ if (!methodAdded) {
+ methodAdded = GPBClassHasSel(msgClass, sel);
+ }
+ return methodAdded;
+ }
+ return [super resolveInstanceMethod:sel];
+}
+
++ (BOOL)resolveClassMethod:(SEL)sel {
+ // Extensions scoped to a Message and looked up via class methods.
+ if (GPBResolveExtensionClassMethod(self, sel)) {
+ return YES;
+ }
+ return [super resolveClassMethod:sel];
+}
+
+#pragma mark - NSCoding Support
+
++ (BOOL)supportsSecureCoding {
+ return YES;
+}
+
+- (instancetype)initWithCoder:(NSCoder *)aDecoder {
+ self = [self init];
+ if (self) {
+ NSData *data =
+ [aDecoder decodeObjectOfClass:[NSData class] forKey:kGPBDataCoderKey];
+ if (data.length) {
+ [self mergeFromData:data extensionRegistry:nil];
+ }
+ }
+ return self;
+}
+
+- (void)encodeWithCoder:(NSCoder *)aCoder {
+ NSData *data = [self data];
+ if (data.length) {
+ [aCoder encodeObject:data forKey:kGPBDataCoderKey];
+ }
+}
+
+#pragma mark - KVC Support
+
++ (BOOL)accessInstanceVariablesDirectly {
+ // Make sure KVC doesn't use instance variables.
+ return NO;
+}
+
+@end
+
+#pragma mark - Messages from GPBUtilities.h but defined here for access to helpers.
+
+// Only exists for public api, no core code should use this.
+id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field) {
+#if defined(DEBUG) && DEBUG
+ if (field.fieldType != GPBFieldTypeRepeated) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@.%@ is not a repeated field.",
+ [self class], field.name];
+ }
+#endif
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ GPBFileSyntax syntax = descriptor.file.syntax;
+ return GetOrCreateArrayIvarWithField(self, field, syntax);
+}
+
+// Only exists for public api, no core code should use this.
+id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field) {
+#if defined(DEBUG) && DEBUG
+ if (field.fieldType != GPBFieldTypeMap) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@.%@ is not a map<> field.",
+ [self class], field.name];
+ }
+#endif
+ GPBDescriptor *descriptor = [[self class] descriptor];
+ GPBFileSyntax syntax = descriptor.file.syntax;
+ return GetOrCreateMapIvarWithField(self, field, syntax);
+}
+
+#pragma clang diagnostic pop
diff --git a/third_party/protobuf/objectivec/GPBMessage_PackagePrivate.h b/third_party/protobuf/objectivec/GPBMessage_PackagePrivate.h
new file mode 100644
index 0000000000..9324cf8d5e
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBMessage_PackagePrivate.h
@@ -0,0 +1,150 @@
+// 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.
+
+// This header is private to the ProtobolBuffers library and must NOT be
+// included by any sources outside this library. The contents of this file are
+// subject to change at any time without notice.
+
+#import "GPBMessage.h"
+
+#import <libkern/OSAtomic.h>
+
+#import "GPBBootstrap.h"
+
+typedef struct GPBMessage_Storage {
+ uint32_t _has_storage_[0];
+} GPBMessage_Storage;
+
+typedef struct GPBMessage_Storage *GPBMessage_StoragePtr;
+
+@interface GPBMessage () {
+ @package
+ // NOTE: Because of the +allocWithZone code using NSAllocateObject(),
+ // this structure should ideally always be kept pointer aligned where the
+ // real storage starts is also pointer aligned. The compiler/runtime already
+ // do this, but it may not be documented.
+
+ // A pointer to the actual fields of the subclasses. The actual structure
+ // pointed to by this pointer will depend on the subclass.
+ // All of the actual structures will start the same as
+ // GPBMessage_Storage with _has_storage__ as the first field.
+ // Kept public because static functions need to access it.
+ GPBMessage_StoragePtr messageStorage_;
+
+ // A lock to provide mutual exclusion from internal data that can be modified
+ // by *read* operations such as getters (autocreation of message fields and
+ // message extensions, not setting of values). Used to guarantee thread safety
+ // for concurrent reads on the message.
+ // NOTE: OSSpinLock may seem like a good fit here but Apple engineers have
+ // pointed out that they are vulnerable to live locking on iOS in cases of
+ // priority inversion:
+ // http://mjtsai.com/blog/2015/12/16/osspinlock-is-unsafe/
+ // https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000372.html
+ // Use of readOnlySemaphore_ must be prefaced by a call to
+ // GPBPrepareReadOnlySemaphore to ensure it has been created. This allows
+ // readOnlySemaphore_ to be only created when actually needed.
+ dispatch_once_t readOnlySemaphoreCreationOnce_;
+ dispatch_semaphore_t readOnlySemaphore_;
+}
+
+// Gets an extension value without autocreating the result if not found. (i.e.
+// returns nil if the extension is not set)
+- (id)getExistingExtension:(GPBExtensionDescriptor *)extension;
+
+// Parses a message of this type from the input and merges it with this
+// message.
+//
+// Warning: This does not verify that all required fields are present in
+// the input message.
+// Note: The caller should call
+// -[CodedInputStream checkLastTagWas:] after calling this to
+// verify that the last tag seen was the appropriate end-group tag,
+// or zero for EOF.
+// NOTE: This will throw if there is an error while parsing.
+- (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:(GPBExtensionRegistry *)extensionRegistry;
+
+// Parses the next delimited message of this type from the input and merges it
+// with this message.
+- (void)mergeDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
+ extensionRegistry:
+ (GPBExtensionRegistry *)extensionRegistry;
+
+- (void)addUnknownMapEntry:(int32_t)fieldNum value:(NSData *)data;
+
+@end
+
+CF_EXTERN_C_BEGIN
+
+
+// Call this before using the readOnlySemaphore_. This ensures it is created only once.
+NS_INLINE void GPBPrepareReadOnlySemaphore(GPBMessage *self) {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+// Starting on Xcode 8.3, the static analyzer complains that the dispatch_once_t
+// variable passed to dispatch_once should not be allocated on the heap or
+// stack. Given that the semaphore is also an instance variable of the message,
+// both variables are cleared at the same time, so this is safe.
+#if !defined(__clang_analyzer__)
+ dispatch_once(&self->readOnlySemaphoreCreationOnce_, ^{
+ self->readOnlySemaphore_ = dispatch_semaphore_create(1);
+ });
+#endif // !defined(__clang_analyzer__)
+
+#pragma clang diagnostic pop
+}
+
+// Returns a new instance that was automatically created by |autocreator| for
+// its field |field|.
+GPBMessage *GPBCreateMessageWithAutocreator(Class msgClass,
+ GPBMessage *autocreator,
+ GPBFieldDescriptor *field)
+ __attribute__((ns_returns_retained));
+
+// Returns whether |message| autocreated this message. This is NO if the message
+// was not autocreated by |message| or if it has been mutated since
+// autocreation.
+BOOL GPBWasMessageAutocreatedBy(GPBMessage *message, GPBMessage *parent);
+
+// Call this when you mutate a message. It will cause the message to become
+// visible to its autocreator.
+void GPBBecomeVisibleToAutocreator(GPBMessage *self);
+
+// Call this when an array/dictionary is mutated so the parent message that
+// autocreated it can react.
+void GPBAutocreatedArrayModified(GPBMessage *self, id array);
+void GPBAutocreatedDictionaryModified(GPBMessage *self, id dictionary);
+
+// Clear the autocreator, if any. Asserts if the autocreator still has an
+// autocreated reference to this message.
+void GPBClearMessageAutocreator(GPBMessage *self);
+
+CF_EXTERN_C_END
diff --git a/third_party/protobuf/objectivec/GPBProtocolBuffers.h b/third_party/protobuf/objectivec/GPBProtocolBuffers.h
new file mode 100644
index 0000000000..68d8854eb8
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBProtocolBuffers.h
@@ -0,0 +1,76 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBBootstrap.h"
+
+#import "GPBArray.h"
+#import "GPBCodedInputStream.h"
+#import "GPBCodedOutputStream.h"
+#import "GPBDescriptor.h"
+#import "GPBDictionary.h"
+#import "GPBExtensionRegistry.h"
+#import "GPBMessage.h"
+#import "GPBRootObject.h"
+#import "GPBUnknownField.h"
+#import "GPBUnknownFieldSet.h"
+#import "GPBUtilities.h"
+#import "GPBWellKnownTypes.h"
+#import "GPBWireFormat.h"
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+// Well-known proto types
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Any.pbobjc.h>
+ #import <Protobuf/Api.pbobjc.h>
+ #import <Protobuf/Duration.pbobjc.h>
+ #import <Protobuf/Empty.pbobjc.h>
+ #import <Protobuf/FieldMask.pbobjc.h>
+ #import <Protobuf/SourceContext.pbobjc.h>
+ #import <Protobuf/Struct.pbobjc.h>
+ #import <Protobuf/Timestamp.pbobjc.h>
+ #import <Protobuf/Type.pbobjc.h>
+ #import <Protobuf/Wrappers.pbobjc.h>
+#else
+ #import "google/protobuf/Any.pbobjc.h"
+ #import "google/protobuf/Api.pbobjc.h"
+ #import "google/protobuf/Duration.pbobjc.h"
+ #import "google/protobuf/Empty.pbobjc.h"
+ #import "google/protobuf/FieldMask.pbobjc.h"
+ #import "google/protobuf/SourceContext.pbobjc.h"
+ #import "google/protobuf/Struct.pbobjc.h"
+ #import "google/protobuf/Timestamp.pbobjc.h"
+ #import "google/protobuf/Type.pbobjc.h"
+ #import "google/protobuf/Wrappers.pbobjc.h"
+#endif
diff --git a/third_party/protobuf/objectivec/GPBProtocolBuffers.m b/third_party/protobuf/objectivec/GPBProtocolBuffers.m
new file mode 100644
index 0000000000..d04c8be155
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBProtocolBuffers.m
@@ -0,0 +1,66 @@
+// 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.
+
+// If you want to build protocol buffers in your own project without adding the
+// project dependency, you can just add this file.
+
+
+// This warning seems to treat code differently when it is #imported than when
+// it is inline in the file. GPBDictionary.m compiles cleanly in other targets,
+// but when #imported here it triggers a bunch of warnings that don't make
+// much sense, and don't trigger when compiled directly. So we shut off the
+// warnings here.
+#pragma clang diagnostic ignored "-Wnullability-completeness"
+
+#import "GPBArray.m"
+#import "GPBCodedInputStream.m"
+#import "GPBCodedOutputStream.m"
+#import "GPBDescriptor.m"
+#import "GPBDictionary.m"
+#import "GPBExtensionInternals.m"
+#import "GPBExtensionRegistry.m"
+#import "GPBMessage.m"
+#import "GPBRootObject.m"
+#import "GPBUnknownField.m"
+#import "GPBUnknownFieldSet.m"
+#import "GPBUtilities.m"
+#import "GPBWellKnownTypes.m"
+#import "GPBWireFormat.m"
+
+#import "google/protobuf/Any.pbobjc.m"
+#import "google/protobuf/Api.pbobjc.m"
+#import "google/protobuf/Duration.pbobjc.m"
+#import "google/protobuf/Empty.pbobjc.m"
+#import "google/protobuf/FieldMask.pbobjc.m"
+#import "google/protobuf/SourceContext.pbobjc.m"
+#import "google/protobuf/Struct.pbobjc.m"
+#import "google/protobuf/Timestamp.pbobjc.m"
+#import "google/protobuf/Type.pbobjc.m"
+#import "google/protobuf/Wrappers.pbobjc.m"
diff --git a/third_party/protobuf/objectivec/GPBProtocolBuffers_RuntimeSupport.h b/third_party/protobuf/objectivec/GPBProtocolBuffers_RuntimeSupport.h
new file mode 100644
index 0000000000..fea75b93bc
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBProtocolBuffers_RuntimeSupport.h
@@ -0,0 +1,40 @@
+// 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.
+
+// This header is meant to only be used by the generated source, it should not
+// be included in code using protocol buffers.
+
+#import "GPBProtocolBuffers.h"
+
+#import "GPBDescriptor_PackagePrivate.h"
+#import "GPBExtensionInternals.h"
+#import "GPBMessage_PackagePrivate.h"
+#import "GPBRootObject_PackagePrivate.h"
+#import "GPBUtilities_PackagePrivate.h"
diff --git a/third_party/protobuf/objectivec/GPBRootObject.h b/third_party/protobuf/objectivec/GPBRootObject.h
new file mode 100644
index 0000000000..d2e2aebfcc
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBRootObject.h
@@ -0,0 +1,52 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+@class GPBExtensionRegistry;
+
+NS_ASSUME_NONNULL_BEGIN
+
+/**
+ * Every generated proto file defines a local "Root" class that exposes a
+ * GPBExtensionRegistry for all the extensions defined by that file and
+ * the files it depends on.
+ **/
+@interface GPBRootObject : NSObject
+
+/**
+ * @return An extension registry for the given file and all the files it depends
+ * on.
+ **/
++ (GPBExtensionRegistry *)extensionRegistry;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBRootObject.m b/third_party/protobuf/objectivec/GPBRootObject.m
new file mode 100644
index 0000000000..585d205a21
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBRootObject.m
@@ -0,0 +1,237 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBRootObject_PackagePrivate.h"
+
+#import <objc/runtime.h>
+
+#import <CoreFoundation/CoreFoundation.h>
+
+#import "GPBDescriptor.h"
+#import "GPBExtensionRegistry.h"
+#import "GPBUtilities_PackagePrivate.h"
+
+@interface GPBExtensionDescriptor (GPBRootObject)
+// Get singletonName as a c string.
+- (const char *)singletonNameC;
+@end
+
+@implementation GPBRootObject
+
+// Taken from http://www.burtleburtle.net/bob/hash/doobs.html
+// Public Domain
+static uint32_t jenkins_one_at_a_time_hash(const char *key) {
+ uint32_t hash = 0;
+ for (uint32_t i = 0; key[i] != '\0'; ++i) {
+ hash += key[i];
+ hash += (hash << 10);
+ hash ^= (hash >> 6);
+ }
+ hash += (hash << 3);
+ hash ^= (hash >> 11);
+ hash += (hash << 15);
+ return hash;
+}
+
+// Key methods for our custom CFDictionary.
+// Note that the dictionary lasts for the lifetime of our app, so no need
+// to worry about deallocation. All of the items are added to it at
+// startup, and so the keys don't need to be retained/released.
+// Keys are NULL terminated char *.
+static const void *GPBRootExtensionKeyRetain(CFAllocatorRef allocator,
+ const void *value) {
+#pragma unused(allocator)
+ return value;
+}
+
+static void GPBRootExtensionKeyRelease(CFAllocatorRef allocator,
+ const void *value) {
+#pragma unused(allocator)
+#pragma unused(value)
+}
+
+static CFStringRef GPBRootExtensionCopyKeyDescription(const void *value) {
+ const char *key = (const char *)value;
+ return CFStringCreateWithCString(kCFAllocatorDefault, key,
+ kCFStringEncodingUTF8);
+}
+
+static Boolean GPBRootExtensionKeyEqual(const void *value1,
+ const void *value2) {
+ const char *key1 = (const char *)value1;
+ const char *key2 = (const char *)value2;
+ return strcmp(key1, key2) == 0;
+}
+
+static CFHashCode GPBRootExtensionKeyHash(const void *value) {
+ const char *key = (const char *)value;
+ return jenkins_one_at_a_time_hash(key);
+}
+
+// NOTE: OSSpinLock may seem like a good fit here but Apple engineers have
+// pointed out that they are vulnerable to live locking on iOS in cases of
+// priority inversion:
+// http://mjtsai.com/blog/2015/12/16/osspinlock-is-unsafe/
+// https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151214/000372.html
+static dispatch_semaphore_t gExtensionSingletonDictionarySemaphore;
+static CFMutableDictionaryRef gExtensionSingletonDictionary = NULL;
+static GPBExtensionRegistry *gDefaultExtensionRegistry = NULL;
+
++ (void)initialize {
+ // Ensure the global is started up.
+ if (!gExtensionSingletonDictionary) {
+ gExtensionSingletonDictionarySemaphore = dispatch_semaphore_create(1);
+ CFDictionaryKeyCallBacks keyCallBacks = {
+ // See description above for reason for using custom dictionary.
+ 0,
+ GPBRootExtensionKeyRetain,
+ GPBRootExtensionKeyRelease,
+ GPBRootExtensionCopyKeyDescription,
+ GPBRootExtensionKeyEqual,
+ GPBRootExtensionKeyHash,
+ };
+ gExtensionSingletonDictionary =
+ CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &keyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
+ gDefaultExtensionRegistry = [[GPBExtensionRegistry alloc] init];
+ }
+
+ if ([self superclass] == [GPBRootObject class]) {
+ // This is here to start up all the per file "Root" subclasses.
+ // This must be done in initialize to enforce thread safety of start up of
+ // the protocol buffer library.
+ [self extensionRegistry];
+ }
+}
+
++ (GPBExtensionRegistry *)extensionRegistry {
+ // Is overridden in all the subclasses that provide extensions to provide the
+ // per class one.
+ return gDefaultExtensionRegistry;
+}
+
++ (void)globallyRegisterExtension:(GPBExtensionDescriptor *)field {
+ const char *key = [field singletonNameC];
+ dispatch_semaphore_wait(gExtensionSingletonDictionarySemaphore,
+ DISPATCH_TIME_FOREVER);
+ CFDictionarySetValue(gExtensionSingletonDictionary, key, field);
+ dispatch_semaphore_signal(gExtensionSingletonDictionarySemaphore);
+}
+
+static id ExtensionForName(id self, SEL _cmd) {
+ // Really fast way of doing "classname_selName".
+ // This came up as a hotspot (creation of NSString *) when accessing a
+ // lot of extensions.
+ const char *selName = sel_getName(_cmd);
+ if (selName[0] == '_') {
+ return nil; // Apple internal selector.
+ }
+ size_t selNameLen = 0;
+ while (1) {
+ char c = selName[selNameLen];
+ if (c == '\0') { // String end.
+ break;
+ }
+ if (c == ':') {
+ return nil; // Selector took an arg, not one of the runtime methods.
+ }
+ ++selNameLen;
+ }
+
+ const char *className = class_getName(self);
+ size_t classNameLen = strlen(className);
+ char key[classNameLen + selNameLen + 2];
+ memcpy(key, className, classNameLen);
+ key[classNameLen] = '_';
+ memcpy(&key[classNameLen + 1], selName, selNameLen);
+ key[classNameLen + 1 + selNameLen] = '\0';
+
+ // NOTE: Even though this method is called from another C function,
+ // gExtensionSingletonDictionarySemaphore and gExtensionSingletonDictionary
+ // will always be initialized. This is because this call flow is just to
+ // lookup the Extension, meaning the code is calling an Extension class
+ // message on a Message or Root class. This guarantees that the class was
+ // initialized and Message classes ensure their Root was also initialized.
+ NSAssert(gExtensionSingletonDictionary, @"Startup order broken!");
+
+ dispatch_semaphore_wait(gExtensionSingletonDictionarySemaphore,
+ DISPATCH_TIME_FOREVER);
+ id extension = (id)CFDictionaryGetValue(gExtensionSingletonDictionary, key);
+ // We can't remove the key from the dictionary here (as an optimization),
+ // two threads could have gone into +resolveClassMethod: for the same method,
+ // and ended up here; there's no way to ensure both return YES without letting
+ // both try to wire in the method.
+ dispatch_semaphore_signal(gExtensionSingletonDictionarySemaphore);
+ return extension;
+}
+
+BOOL GPBResolveExtensionClassMethod(Class self, SEL sel) {
+ // Another option would be to register the extensions with the class at
+ // globallyRegisterExtension:
+ // Timing the two solutions, this solution turned out to be much faster
+ // and reduced startup time, and runtime memory.
+ // The advantage to globallyRegisterExtension is that it would reduce the
+ // size of the protos somewhat because the singletonNameC wouldn't need
+ // to include the class name. For a class with a lot of extensions it
+ // can add up. You could also significantly reduce the code complexity of this
+ // file.
+ id extension = ExtensionForName(self, sel);
+ if (extension != nil) {
+ const char *encoding =
+ GPBMessageEncodingForSelector(@selector(getClassValue), NO);
+ Class metaClass = objc_getMetaClass(class_getName(self));
+ IMP imp = imp_implementationWithBlock(^(id obj) {
+#pragma unused(obj)
+ return extension;
+ });
+ BOOL methodAdded = class_addMethod(metaClass, sel, imp, encoding);
+ // class_addMethod() is documented as also failing if the method was already
+ // added; so we check if the method is already there and return success so
+ // the method dispatch will still happen. Why would it already be added?
+ // Two threads could cause the same method to be bound at the same time,
+ // but only one will actually bind it; the other still needs to return true
+ // so things will dispatch.
+ if (!methodAdded) {
+ methodAdded = GPBClassHasSel(metaClass, sel);
+ }
+ return methodAdded;
+ }
+ return NO;
+}
+
+
++ (BOOL)resolveClassMethod:(SEL)sel {
+ if (GPBResolveExtensionClassMethod(self, sel)) {
+ return YES;
+ }
+ return [super resolveClassMethod:sel];
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/GPBRootObject_PackagePrivate.h b/third_party/protobuf/objectivec/GPBRootObject_PackagePrivate.h
new file mode 100644
index 0000000000..3c8f09c896
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBRootObject_PackagePrivate.h
@@ -0,0 +1,46 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBRootObject.h"
+
+@class GPBExtensionDescriptor;
+
+@interface GPBRootObject ()
+
+// Globally register.
++ (void)globallyRegisterExtension:(GPBExtensionDescriptor *)field;
+
+@end
+
+// Returns YES if the selector was resolved and added to the class,
+// NO otherwise.
+BOOL GPBResolveExtensionClassMethod(Class self, SEL sel);
diff --git a/third_party/protobuf/objectivec/GPBRuntimeTypes.h b/third_party/protobuf/objectivec/GPBRuntimeTypes.h
new file mode 100644
index 0000000000..4d552060b0
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBRuntimeTypes.h
@@ -0,0 +1,144 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBBootstrap.h"
+
+@class GPBEnumDescriptor;
+@class GPBMessage;
+@class GPBInt32Array;
+
+/**
+ * Verifies that a given value can be represented by an enum type.
+ * */
+typedef BOOL (*GPBEnumValidationFunc)(int32_t);
+
+/**
+ * Fetches an EnumDescriptor.
+ * */
+typedef GPBEnumDescriptor *(*GPBEnumDescriptorFunc)(void);
+
+/**
+ * Magic value used at runtime to indicate an enum value that wasn't know at
+ * compile time.
+ * */
+enum {
+ kGPBUnrecognizedEnumeratorValue = (int32_t)0xFBADBEEF,
+};
+
+/**
+ * A union for storing all possible Protobuf values. Note that owner is
+ * responsible for memory management of object types.
+ * */
+typedef union {
+ BOOL valueBool;
+ int32_t valueInt32;
+ int64_t valueInt64;
+ uint32_t valueUInt32;
+ uint64_t valueUInt64;
+ float valueFloat;
+ double valueDouble;
+ GPB_UNSAFE_UNRETAINED NSData *valueData;
+ GPB_UNSAFE_UNRETAINED NSString *valueString;
+ GPB_UNSAFE_UNRETAINED GPBMessage *valueMessage;
+ int32_t valueEnum;
+} GPBGenericValue;
+
+/**
+ * Enum listing the possible data types that a field can contain.
+ *
+ * @note Do not change the order of this enum (or add things to it) without
+ * thinking about it very carefully. There are several things that depend
+ * on the order.
+ * */
+typedef NS_ENUM(uint8_t, GPBDataType) {
+ /** Field contains boolean value(s). */
+ GPBDataTypeBool = 0,
+ /** Field contains unsigned 4 byte value(s). */
+ GPBDataTypeFixed32,
+ /** Field contains signed 4 byte value(s). */
+ GPBDataTypeSFixed32,
+ /** Field contains float value(s). */
+ GPBDataTypeFloat,
+ /** Field contains unsigned 8 byte value(s). */
+ GPBDataTypeFixed64,
+ /** Field contains signed 8 byte value(s). */
+ GPBDataTypeSFixed64,
+ /** Field contains double value(s). */
+ GPBDataTypeDouble,
+ /**
+ * Field contains variable length value(s). Inefficient for encoding negative
+ * numbers – if your field is likely to have negative values, use
+ * GPBDataTypeSInt32 instead.
+ **/
+ GPBDataTypeInt32,
+ /**
+ * Field contains variable length value(s). Inefficient for encoding negative
+ * numbers – if your field is likely to have negative values, use
+ * GPBDataTypeSInt64 instead.
+ **/
+ GPBDataTypeInt64,
+ /** Field contains signed variable length integer value(s). */
+ GPBDataTypeSInt32,
+ /** Field contains signed variable length integer value(s). */
+ GPBDataTypeSInt64,
+ /** Field contains unsigned variable length integer value(s). */
+ GPBDataTypeUInt32,
+ /** Field contains unsigned variable length integer value(s). */
+ GPBDataTypeUInt64,
+ /** Field contains an arbitrary sequence of bytes. */
+ GPBDataTypeBytes,
+ /** Field contains UTF-8 encoded or 7-bit ASCII text. */
+ GPBDataTypeString,
+ /** Field contains message type(s). */
+ GPBDataTypeMessage,
+ /** Field contains message type(s). */
+ GPBDataTypeGroup,
+ /** Field contains enum value(s). */
+ GPBDataTypeEnum,
+};
+
+enum {
+ /**
+ * A count of the number of types in GPBDataType. Separated out from the
+ * GPBDataType enum to avoid warnings regarding not handling GPBDataType_Count
+ * in switch statements.
+ **/
+ GPBDataType_Count = GPBDataTypeEnum + 1
+};
+
+/** An extension range. */
+typedef struct GPBExtensionRange {
+ /** Inclusive. */
+ uint32_t start;
+ /** Exclusive. */
+ uint32_t end;
+} GPBExtensionRange;
diff --git a/third_party/protobuf/objectivec/GPBUnknownField.h b/third_party/protobuf/objectivec/GPBUnknownField.h
new file mode 100644
index 0000000000..a135cc2031
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUnknownField.h
@@ -0,0 +1,96 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+@class GPBCodedOutputStream;
+@class GPBUInt32Array;
+@class GPBUInt64Array;
+@class GPBUnknownFieldSet;
+
+NS_ASSUME_NONNULL_BEGIN
+/**
+ * Store an unknown field. These are used in conjunction with
+ * GPBUnknownFieldSet.
+ **/
+@interface GPBUnknownField : NSObject<NSCopying>
+
+/** The field number the data is stored under. */
+@property(nonatomic, readonly, assign) int32_t number;
+
+/** An array of varint values for this field. */
+@property(nonatomic, readonly, strong) GPBUInt64Array *varintList;
+
+/** An array of fixed32 values for this field. */
+@property(nonatomic, readonly, strong) GPBUInt32Array *fixed32List;
+
+/** An array of fixed64 values for this field. */
+@property(nonatomic, readonly, strong) GPBUInt64Array *fixed64List;
+
+/** An array of data values for this field. */
+@property(nonatomic, readonly, strong) NSArray<NSData*> *lengthDelimitedList;
+
+/** An array of groups of values for this field. */
+@property(nonatomic, readonly, strong) NSArray<GPBUnknownFieldSet*> *groupList;
+
+/**
+ * Add a value to the varintList.
+ *
+ * @param value The value to add.
+ **/
+- (void)addVarint:(uint64_t)value;
+/**
+ * Add a value to the fixed32List.
+ *
+ * @param value The value to add.
+ **/
+- (void)addFixed32:(uint32_t)value;
+/**
+ * Add a value to the fixed64List.
+ *
+ * @param value The value to add.
+ **/
+- (void)addFixed64:(uint64_t)value;
+/**
+ * Add a value to the lengthDelimitedList.
+ *
+ * @param value The value to add.
+ **/
+- (void)addLengthDelimited:(NSData *)value;
+/**
+ * Add a value to the groupList.
+ *
+ * @param value The value to add.
+ **/
+- (void)addGroup:(GPBUnknownFieldSet *)value;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBUnknownField.m b/third_party/protobuf/objectivec/GPBUnknownField.m
new file mode 100644
index 0000000000..30efe7563b
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUnknownField.m
@@ -0,0 +1,334 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBUnknownField_PackagePrivate.h"
+
+#import "GPBArray.h"
+#import "GPBCodedOutputStream_PackagePrivate.h"
+
+@implementation GPBUnknownField {
+ @protected
+ int32_t number_;
+ GPBUInt64Array *mutableVarintList_;
+ GPBUInt32Array *mutableFixed32List_;
+ GPBUInt64Array *mutableFixed64List_;
+ NSMutableArray<NSData*> *mutableLengthDelimitedList_;
+ NSMutableArray<GPBUnknownFieldSet*> *mutableGroupList_;
+}
+
+@synthesize number = number_;
+@synthesize varintList = mutableVarintList_;
+@synthesize fixed32List = mutableFixed32List_;
+@synthesize fixed64List = mutableFixed64List_;
+@synthesize lengthDelimitedList = mutableLengthDelimitedList_;
+@synthesize groupList = mutableGroupList_;
+
+- (instancetype)initWithNumber:(int32_t)number {
+ if ((self = [super init])) {
+ number_ = number;
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [mutableVarintList_ release];
+ [mutableFixed32List_ release];
+ [mutableFixed64List_ release];
+ [mutableLengthDelimitedList_ release];
+ [mutableGroupList_ release];
+
+ [super dealloc];
+}
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+- (id)copyWithZone:(NSZone *)zone {
+ GPBUnknownField *result =
+ [[GPBUnknownField allocWithZone:zone] initWithNumber:number_];
+ result->mutableFixed32List_ = [mutableFixed32List_ copyWithZone:zone];
+ result->mutableFixed64List_ = [mutableFixed64List_ copyWithZone:zone];
+ result->mutableLengthDelimitedList_ =
+ [mutableLengthDelimitedList_ copyWithZone:zone];
+ result->mutableVarintList_ = [mutableVarintList_ copyWithZone:zone];
+ if (mutableGroupList_.count) {
+ result->mutableGroupList_ = [[NSMutableArray allocWithZone:zone]
+ initWithCapacity:mutableGroupList_.count];
+ for (GPBUnknownFieldSet *group in mutableGroupList_) {
+ GPBUnknownFieldSet *copied = [group copyWithZone:zone];
+ [result->mutableGroupList_ addObject:copied];
+ [copied release];
+ }
+ }
+ return result;
+}
+
+- (BOOL)isEqual:(id)object {
+ if (self == object) return YES;
+ if (![object isKindOfClass:[GPBUnknownField class]]) return NO;
+ GPBUnknownField *field = (GPBUnknownField *)object;
+ BOOL equalVarint =
+ (mutableVarintList_.count == 0 && field->mutableVarintList_.count == 0) ||
+ [mutableVarintList_ isEqual:field->mutableVarintList_];
+ if (!equalVarint) return NO;
+ BOOL equalFixed32 = (mutableFixed32List_.count == 0 &&
+ field->mutableFixed32List_.count == 0) ||
+ [mutableFixed32List_ isEqual:field->mutableFixed32List_];
+ if (!equalFixed32) return NO;
+ BOOL equalFixed64 = (mutableFixed64List_.count == 0 &&
+ field->mutableFixed64List_.count == 0) ||
+ [mutableFixed64List_ isEqual:field->mutableFixed64List_];
+ if (!equalFixed64) return NO;
+ BOOL equalLDList =
+ (mutableLengthDelimitedList_.count == 0 &&
+ field->mutableLengthDelimitedList_.count == 0) ||
+ [mutableLengthDelimitedList_ isEqual:field->mutableLengthDelimitedList_];
+ if (!equalLDList) return NO;
+ BOOL equalGroupList =
+ (mutableGroupList_.count == 0 && field->mutableGroupList_.count == 0) ||
+ [mutableGroupList_ isEqual:field->mutableGroupList_];
+ if (!equalGroupList) return NO;
+ return YES;
+}
+
+- (NSUInteger)hash {
+ // Just mix the hashes of the possible sub arrays.
+ const int prime = 31;
+ NSUInteger result = prime + [mutableVarintList_ hash];
+ result = prime * result + [mutableFixed32List_ hash];
+ result = prime * result + [mutableFixed64List_ hash];
+ result = prime * result + [mutableLengthDelimitedList_ hash];
+ result = prime * result + [mutableGroupList_ hash];
+ return result;
+}
+
+- (void)writeToOutput:(GPBCodedOutputStream *)output {
+ NSUInteger count = mutableVarintList_.count;
+ if (count > 0) {
+ [output writeUInt64Array:number_ values:mutableVarintList_ tag:0];
+ }
+ count = mutableFixed32List_.count;
+ if (count > 0) {
+ [output writeFixed32Array:number_ values:mutableFixed32List_ tag:0];
+ }
+ count = mutableFixed64List_.count;
+ if (count > 0) {
+ [output writeFixed64Array:number_ values:mutableFixed64List_ tag:0];
+ }
+ count = mutableLengthDelimitedList_.count;
+ if (count > 0) {
+ [output writeBytesArray:number_ values:mutableLengthDelimitedList_];
+ }
+ count = mutableGroupList_.count;
+ if (count > 0) {
+ [output writeUnknownGroupArray:number_ values:mutableGroupList_];
+ }
+}
+
+- (size_t)serializedSize {
+ __block size_t result = 0;
+ int32_t number = number_;
+ [mutableVarintList_
+ enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ result += GPBComputeUInt64Size(number, value);
+ }];
+
+ [mutableFixed32List_
+ enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ result += GPBComputeFixed32Size(number, value);
+ }];
+
+ [mutableFixed64List_
+ enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ result += GPBComputeFixed64Size(number, value);
+ }];
+
+ for (NSData *data in mutableLengthDelimitedList_) {
+ result += GPBComputeBytesSize(number, data);
+ }
+
+ for (GPBUnknownFieldSet *set in mutableGroupList_) {
+ result += GPBComputeUnknownGroupSize(number, set);
+ }
+
+ return result;
+}
+
+- (void)writeAsMessageSetExtensionToOutput:(GPBCodedOutputStream *)output {
+ for (NSData *data in mutableLengthDelimitedList_) {
+ [output writeRawMessageSetExtension:number_ value:data];
+ }
+}
+
+- (size_t)serializedSizeAsMessageSetExtension {
+ size_t result = 0;
+ for (NSData *data in mutableLengthDelimitedList_) {
+ result += GPBComputeRawMessageSetExtensionSize(number_, data);
+ }
+ return result;
+}
+
+- (NSString *)description {
+ NSMutableString *description = [NSMutableString
+ stringWithFormat:@"<%@ %p>: Field: %d {\n", [self class], self, number_];
+ [mutableVarintList_
+ enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [description appendFormat:@"\t%llu\n", value];
+ }];
+
+ [mutableFixed32List_
+ enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [description appendFormat:@"\t%u\n", value];
+ }];
+
+ [mutableFixed64List_
+ enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+#pragma unused(idx, stop)
+ [description appendFormat:@"\t%llu\n", value];
+ }];
+
+ for (NSData *data in mutableLengthDelimitedList_) {
+ [description appendFormat:@"\t%@\n", data];
+ }
+
+ for (GPBUnknownFieldSet *set in mutableGroupList_) {
+ [description appendFormat:@"\t%@\n", set];
+ }
+ [description appendString:@"}"];
+ return description;
+}
+
+- (void)mergeFromField:(GPBUnknownField *)other {
+ GPBUInt64Array *otherVarintList = other.varintList;
+ if (otherVarintList.count > 0) {
+ if (mutableVarintList_ == nil) {
+ mutableVarintList_ = [otherVarintList copy];
+ } else {
+ [mutableVarintList_ addValuesFromArray:otherVarintList];
+ }
+ }
+
+ GPBUInt32Array *otherFixed32List = other.fixed32List;
+ if (otherFixed32List.count > 0) {
+ if (mutableFixed32List_ == nil) {
+ mutableFixed32List_ = [otherFixed32List copy];
+ } else {
+ [mutableFixed32List_ addValuesFromArray:otherFixed32List];
+ }
+ }
+
+ GPBUInt64Array *otherFixed64List = other.fixed64List;
+ if (otherFixed64List.count > 0) {
+ if (mutableFixed64List_ == nil) {
+ mutableFixed64List_ = [otherFixed64List copy];
+ } else {
+ [mutableFixed64List_ addValuesFromArray:otherFixed64List];
+ }
+ }
+
+ NSArray *otherLengthDelimitedList = other.lengthDelimitedList;
+ if (otherLengthDelimitedList.count > 0) {
+ if (mutableLengthDelimitedList_ == nil) {
+ mutableLengthDelimitedList_ = [otherLengthDelimitedList mutableCopy];
+ } else {
+ [mutableLengthDelimitedList_
+ addObjectsFromArray:otherLengthDelimitedList];
+ }
+ }
+
+ NSArray *otherGroupList = other.groupList;
+ if (otherGroupList.count > 0) {
+ if (mutableGroupList_ == nil) {
+ mutableGroupList_ =
+ [[NSMutableArray alloc] initWithCapacity:otherGroupList.count];
+ }
+ // Make our own mutable copies.
+ for (GPBUnknownFieldSet *group in otherGroupList) {
+ GPBUnknownFieldSet *copied = [group copy];
+ [mutableGroupList_ addObject:copied];
+ [copied release];
+ }
+ }
+}
+
+- (void)addVarint:(uint64_t)value {
+ if (mutableVarintList_ == nil) {
+ mutableVarintList_ = [[GPBUInt64Array alloc] initWithValues:&value count:1];
+ } else {
+ [mutableVarintList_ addValue:value];
+ }
+}
+
+- (void)addFixed32:(uint32_t)value {
+ if (mutableFixed32List_ == nil) {
+ mutableFixed32List_ =
+ [[GPBUInt32Array alloc] initWithValues:&value count:1];
+ } else {
+ [mutableFixed32List_ addValue:value];
+ }
+}
+
+- (void)addFixed64:(uint64_t)value {
+ if (mutableFixed64List_ == nil) {
+ mutableFixed64List_ =
+ [[GPBUInt64Array alloc] initWithValues:&value count:1];
+ } else {
+ [mutableFixed64List_ addValue:value];
+ }
+}
+
+- (void)addLengthDelimited:(NSData *)value {
+ if (mutableLengthDelimitedList_ == nil) {
+ mutableLengthDelimitedList_ =
+ [[NSMutableArray alloc] initWithObjects:&value count:1];
+ } else {
+ [mutableLengthDelimitedList_ addObject:value];
+ }
+}
+
+- (void)addGroup:(GPBUnknownFieldSet *)value {
+ if (mutableGroupList_ == nil) {
+ mutableGroupList_ = [[NSMutableArray alloc] initWithObjects:&value count:1];
+ } else {
+ [mutableGroupList_ addObject:value];
+ }
+}
+
+#pragma clang diagnostic pop
+
+@end
diff --git a/third_party/protobuf/objectivec/GPBUnknownFieldSet.h b/third_party/protobuf/objectivec/GPBUnknownFieldSet.h
new file mode 100644
index 0000000000..1b5f24f392
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUnknownFieldSet.h
@@ -0,0 +1,82 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+@class GPBUnknownField;
+
+NS_ASSUME_NONNULL_BEGIN
+
+/**
+ * A collection of unknown fields. Fields parsed from the binary representation
+ * of a message that are unknown end up in an instance of this set. This only
+ * applies for files declared with the "proto2" syntax. Files declared with the
+ * "proto3" syntax discard the unknown values.
+ **/
+@interface GPBUnknownFieldSet : NSObject<NSCopying>
+
+/**
+ * Tests to see if the given field number has a value.
+ *
+ * @param number The field number to check.
+ *
+ * @return YES if there is an unknown field for the given field number.
+ **/
+- (BOOL)hasField:(int32_t)number;
+
+/**
+ * Fetches the GPBUnknownField for the given field number.
+ *
+ * @param number The field number to look up.
+ *
+ * @return The GPBUnknownField or nil if none found.
+ **/
+- (nullable GPBUnknownField *)getField:(int32_t)number;
+
+/**
+ * @return The number of fields in this set.
+ **/
+- (NSUInteger)countOfFields;
+
+/**
+ * Adds the given field to the set.
+ *
+ * @param field The field to add to the set.
+ **/
+- (void)addField:(GPBUnknownField *)field;
+
+/**
+ * @return An array of the GPBUnknownFields sorted by the field numbers.
+ **/
+- (NSArray<GPBUnknownField *> *)sortedFields;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBUnknownFieldSet.m b/third_party/protobuf/objectivec/GPBUnknownFieldSet.m
new file mode 100644
index 0000000000..a7335f050b
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUnknownFieldSet.m
@@ -0,0 +1,395 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBUnknownFieldSet_PackagePrivate.h"
+
+#import "GPBCodedInputStream_PackagePrivate.h"
+#import "GPBCodedOutputStream.h"
+#import "GPBUnknownField_PackagePrivate.h"
+#import "GPBUtilities.h"
+#import "GPBWireFormat.h"
+
+#pragma mark Helpers
+
+static void checkNumber(int32_t number) {
+ if (number == 0) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Zero is not a valid field number."];
+ }
+}
+
+@implementation GPBUnknownFieldSet {
+ @package
+ CFMutableDictionaryRef fields_;
+}
+
+static void CopyWorker(const void *key, const void *value, void *context) {
+#pragma unused(key)
+ GPBUnknownField *field = value;
+ GPBUnknownFieldSet *result = context;
+
+ GPBUnknownField *copied = [field copy];
+ [result addField:copied];
+ [copied release];
+}
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+- (id)copyWithZone:(NSZone *)zone {
+ GPBUnknownFieldSet *result = [[GPBUnknownFieldSet allocWithZone:zone] init];
+ if (fields_) {
+ CFDictionaryApplyFunction(fields_, CopyWorker, result);
+ }
+ return result;
+}
+
+- (void)dealloc {
+ if (fields_) {
+ CFRelease(fields_);
+ }
+ [super dealloc];
+}
+
+- (BOOL)isEqual:(id)object {
+ BOOL equal = NO;
+ if ([object isKindOfClass:[GPBUnknownFieldSet class]]) {
+ GPBUnknownFieldSet *set = (GPBUnknownFieldSet *)object;
+ if ((fields_ == NULL) && (set->fields_ == NULL)) {
+ equal = YES;
+ } else if ((fields_ != NULL) && (set->fields_ != NULL)) {
+ equal = CFEqual(fields_, set->fields_);
+ }
+ }
+ return equal;
+}
+
+- (NSUInteger)hash {
+ // Return the hash of the fields dictionary (or just some value).
+ if (fields_) {
+ return CFHash(fields_);
+ }
+ return (NSUInteger)[GPBUnknownFieldSet class];
+}
+
+#pragma mark - Public Methods
+
+- (BOOL)hasField:(int32_t)number {
+ ssize_t key = number;
+ return fields_ ? (CFDictionaryGetValue(fields_, (void *)key) != nil) : NO;
+}
+
+- (GPBUnknownField *)getField:(int32_t)number {
+ ssize_t key = number;
+ GPBUnknownField *result =
+ fields_ ? CFDictionaryGetValue(fields_, (void *)key) : nil;
+ return result;
+}
+
+- (NSUInteger)countOfFields {
+ return fields_ ? CFDictionaryGetCount(fields_) : 0;
+}
+
+- (NSArray *)sortedFields {
+ if (!fields_) return [NSArray array];
+ size_t count = CFDictionaryGetCount(fields_);
+ ssize_t keys[count];
+ GPBUnknownField *values[count];
+ CFDictionaryGetKeysAndValues(fields_, (const void **)keys,
+ (const void **)values);
+ struct GPBFieldPair {
+ ssize_t key;
+ GPBUnknownField *value;
+ } pairs[count];
+ for (size_t i = 0; i < count; ++i) {
+ pairs[i].key = keys[i];
+ pairs[i].value = values[i];
+ };
+ qsort_b(pairs, count, sizeof(struct GPBFieldPair),
+ ^(const void *first, const void *second) {
+ const struct GPBFieldPair *a = first;
+ const struct GPBFieldPair *b = second;
+ return (a->key > b->key) ? 1 : ((a->key == b->key) ? 0 : -1);
+ });
+ for (size_t i = 0; i < count; ++i) {
+ values[i] = pairs[i].value;
+ };
+ return [NSArray arrayWithObjects:values count:count];
+}
+
+#pragma mark - Internal Methods
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output {
+ if (!fields_) return;
+ size_t count = CFDictionaryGetCount(fields_);
+ ssize_t keys[count];
+ GPBUnknownField *values[count];
+ CFDictionaryGetKeysAndValues(fields_, (const void **)keys,
+ (const void **)values);
+ if (count > 1) {
+ struct GPBFieldPair {
+ ssize_t key;
+ GPBUnknownField *value;
+ } pairs[count];
+
+ for (size_t i = 0; i < count; ++i) {
+ pairs[i].key = keys[i];
+ pairs[i].value = values[i];
+ };
+ qsort_b(pairs, count, sizeof(struct GPBFieldPair),
+ ^(const void *first, const void *second) {
+ const struct GPBFieldPair *a = first;
+ const struct GPBFieldPair *b = second;
+ return (a->key > b->key) ? 1 : ((a->key == b->key) ? 0 : -1);
+ });
+ for (size_t i = 0; i < count; ++i) {
+ GPBUnknownField *value = pairs[i].value;
+ [value writeToOutput:output];
+ }
+ } else {
+ [values[0] writeToOutput:output];
+ }
+}
+
+- (NSString *)description {
+ NSMutableString *description = [NSMutableString
+ stringWithFormat:@"<%@ %p>: TextFormat: {\n", [self class], self];
+ NSString *textFormat = GPBTextFormatForUnknownFieldSet(self, @" ");
+ [description appendString:textFormat];
+ [description appendString:@"}"];
+ return description;
+}
+
+static void GPBUnknownFieldSetSerializedSize(const void *key, const void *value,
+ void *context) {
+#pragma unused(key)
+ GPBUnknownField *field = value;
+ size_t *result = context;
+ *result += [field serializedSize];
+}
+
+- (size_t)serializedSize {
+ size_t result = 0;
+ if (fields_) {
+ CFDictionaryApplyFunction(fields_, GPBUnknownFieldSetSerializedSize,
+ &result);
+ }
+ return result;
+}
+
+static void GPBUnknownFieldSetWriteAsMessageSetTo(const void *key,
+ const void *value,
+ void *context) {
+#pragma unused(key)
+ GPBUnknownField *field = value;
+ GPBCodedOutputStream *output = context;
+ [field writeAsMessageSetExtensionToOutput:output];
+}
+
+- (void)writeAsMessageSetTo:(GPBCodedOutputStream *)output {
+ if (fields_) {
+ CFDictionaryApplyFunction(fields_, GPBUnknownFieldSetWriteAsMessageSetTo,
+ output);
+ }
+}
+
+static void GPBUnknownFieldSetSerializedSizeAsMessageSet(const void *key,
+ const void *value,
+ void *context) {
+#pragma unused(key)
+ GPBUnknownField *field = value;
+ size_t *result = context;
+ *result += [field serializedSizeAsMessageSetExtension];
+}
+
+- (size_t)serializedSizeAsMessageSet {
+ size_t result = 0;
+ if (fields_) {
+ CFDictionaryApplyFunction(
+ fields_, GPBUnknownFieldSetSerializedSizeAsMessageSet, &result);
+ }
+ return result;
+}
+
+- (NSData *)data {
+ NSMutableData *data = [NSMutableData dataWithLength:self.serializedSize];
+ GPBCodedOutputStream *output =
+ [[GPBCodedOutputStream alloc] initWithData:data];
+ [self writeToCodedOutputStream:output];
+ [output release];
+ return data;
+}
+
++ (BOOL)isFieldTag:(int32_t)tag {
+ return GPBWireFormatGetTagWireType(tag) != GPBWireFormatEndGroup;
+}
+
+- (void)addField:(GPBUnknownField *)field {
+ int32_t number = [field number];
+ checkNumber(number);
+ if (!fields_) {
+ // Use a custom dictionary here because the keys are numbers and conversion
+ // back and forth from NSNumber isn't worth the cost.
+ fields_ = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL,
+ &kCFTypeDictionaryValueCallBacks);
+ }
+ ssize_t key = number;
+ CFDictionarySetValue(fields_, (const void *)key, field);
+}
+
+- (GPBUnknownField *)mutableFieldForNumber:(int32_t)number create:(BOOL)create {
+ ssize_t key = number;
+ GPBUnknownField *existing =
+ fields_ ? CFDictionaryGetValue(fields_, (const void *)key) : nil;
+ if (!existing && create) {
+ existing = [[GPBUnknownField alloc] initWithNumber:number];
+ // This retains existing.
+ [self addField:existing];
+ [existing release];
+ }
+ return existing;
+}
+
+static void GPBUnknownFieldSetMergeUnknownFields(const void *key,
+ const void *value,
+ void *context) {
+#pragma unused(key)
+ GPBUnknownField *field = value;
+ GPBUnknownFieldSet *self = context;
+
+ int32_t number = [field number];
+ checkNumber(number);
+ GPBUnknownField *oldField = [self mutableFieldForNumber:number create:NO];
+ if (oldField) {
+ [oldField mergeFromField:field];
+ } else {
+ // Merge only comes from GPBMessage's mergeFrom:, so it means we are on
+ // mutable message and are an mutable instance, so make sure we need
+ // mutable fields.
+ GPBUnknownField *fieldCopy = [field copy];
+ [self addField:fieldCopy];
+ [fieldCopy release];
+ }
+}
+
+- (void)mergeUnknownFields:(GPBUnknownFieldSet *)other {
+ if (other && other->fields_) {
+ CFDictionaryApplyFunction(other->fields_,
+ GPBUnknownFieldSetMergeUnknownFields, self);
+ }
+}
+
+- (void)mergeFromData:(NSData *)data {
+ GPBCodedInputStream *input = [[GPBCodedInputStream alloc] initWithData:data];
+ [self mergeFromCodedInputStream:input];
+ [input checkLastTagWas:0];
+ [input release];
+}
+
+- (void)mergeVarintField:(int32_t)number value:(int32_t)value {
+ checkNumber(number);
+ [[self mutableFieldForNumber:number create:YES] addVarint:value];
+}
+
+- (BOOL)mergeFieldFrom:(int32_t)tag input:(GPBCodedInputStream *)input {
+ NSAssert(GPBWireFormatIsValidTag(tag), @"Got passed an invalid tag");
+ int32_t number = GPBWireFormatGetTagFieldNumber(tag);
+ GPBCodedInputStreamState *state = &input->state_;
+ switch (GPBWireFormatGetTagWireType(tag)) {
+ case GPBWireFormatVarint: {
+ GPBUnknownField *field = [self mutableFieldForNumber:number create:YES];
+ [field addVarint:GPBCodedInputStreamReadInt64(state)];
+ return YES;
+ }
+ case GPBWireFormatFixed64: {
+ GPBUnknownField *field = [self mutableFieldForNumber:number create:YES];
+ [field addFixed64:GPBCodedInputStreamReadFixed64(state)];
+ return YES;
+ }
+ case GPBWireFormatLengthDelimited: {
+ NSData *data = GPBCodedInputStreamReadRetainedBytes(state);
+ GPBUnknownField *field = [self mutableFieldForNumber:number create:YES];
+ [field addLengthDelimited:data];
+ [data release];
+ return YES;
+ }
+ case GPBWireFormatStartGroup: {
+ GPBUnknownFieldSet *unknownFieldSet = [[GPBUnknownFieldSet alloc] init];
+ [input readUnknownGroup:number message:unknownFieldSet];
+ GPBUnknownField *field = [self mutableFieldForNumber:number create:YES];
+ [field addGroup:unknownFieldSet];
+ [unknownFieldSet release];
+ return YES;
+ }
+ case GPBWireFormatEndGroup:
+ return NO;
+ case GPBWireFormatFixed32: {
+ GPBUnknownField *field = [self mutableFieldForNumber:number create:YES];
+ [field addFixed32:GPBCodedInputStreamReadFixed32(state)];
+ return YES;
+ }
+ }
+}
+
+- (void)mergeMessageSetMessage:(int32_t)number data:(NSData *)messageData {
+ [[self mutableFieldForNumber:number create:YES]
+ addLengthDelimited:messageData];
+}
+
+- (void)addUnknownMapEntry:(int32_t)fieldNum value:(NSData *)data {
+ GPBUnknownField *field = [self mutableFieldForNumber:fieldNum create:YES];
+ [field addLengthDelimited:data];
+}
+
+- (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input {
+ while (YES) {
+ int32_t tag = GPBCodedInputStreamReadTag(&input->state_);
+ if (tag == 0 || ![self mergeFieldFrom:tag input:input]) {
+ break;
+ }
+ }
+}
+
+- (void)getTags:(int32_t *)tags {
+ if (!fields_) return;
+ size_t count = CFDictionaryGetCount(fields_);
+ ssize_t keys[count];
+ CFDictionaryGetKeysAndValues(fields_, (const void **)keys, NULL);
+ for (size_t i = 0; i < count; ++i) {
+ tags[i] = (int32_t)keys[i];
+ }
+}
+
+#pragma clang diagnostic pop
+
+@end
diff --git a/third_party/protobuf/objectivec/GPBUnknownFieldSet_PackagePrivate.h b/third_party/protobuf/objectivec/GPBUnknownFieldSet_PackagePrivate.h
new file mode 100644
index 0000000000..e27127ad1d
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUnknownFieldSet_PackagePrivate.h
@@ -0,0 +1,61 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBUnknownFieldSet.h"
+
+@class GPBCodedOutputStream;
+@class GPBCodedInputStream;
+
+@interface GPBUnknownFieldSet ()
+
++ (BOOL)isFieldTag:(int32_t)tag;
+
+- (NSData *)data;
+
+- (size_t)serializedSize;
+- (size_t)serializedSizeAsMessageSet;
+
+- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output;
+- (void)writeAsMessageSetTo:(GPBCodedOutputStream *)output;
+
+- (void)mergeUnknownFields:(GPBUnknownFieldSet *)other;
+
+- (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input;
+- (void)mergeFromData:(NSData *)data;
+
+- (void)mergeVarintField:(int32_t)number value:(int32_t)value;
+- (BOOL)mergeFieldFrom:(int32_t)tag input:(GPBCodedInputStream *)input;
+- (void)mergeMessageSetMessage:(int32_t)number data:(NSData *)messageData;
+
+- (void)addUnknownMapEntry:(int32_t)fieldNum value:(NSData *)data;
+
+@end
diff --git a/third_party/protobuf/objectivec/GPBUnknownField_PackagePrivate.h b/third_party/protobuf/objectivec/GPBUnknownField_PackagePrivate.h
new file mode 100644
index 0000000000..1fbce0f954
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUnknownField_PackagePrivate.h
@@ -0,0 +1,49 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBUnknownField.h"
+
+@class GPBCodedOutputStream;
+
+@interface GPBUnknownField ()
+
+- (instancetype)initWithNumber:(int32_t)number;
+
+- (void)writeToOutput:(GPBCodedOutputStream *)output;
+- (size_t)serializedSize;
+
+- (void)writeAsMessageSetExtensionToOutput:(GPBCodedOutputStream *)output;
+- (size_t)serializedSizeAsMessageSetExtension;
+
+- (void)mergeFromField:(GPBUnknownField *)other;
+
+@end
diff --git a/third_party/protobuf/objectivec/GPBUtilities.h b/third_party/protobuf/objectivec/GPBUtilities.h
new file mode 100644
index 0000000000..5464dfb356
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUtilities.h
@@ -0,0 +1,539 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBArray.h"
+#import "GPBMessage.h"
+#import "GPBRuntimeTypes.h"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+/**
+ * Generates a string that should be a valid "TextFormat" for the C++ version
+ * of Protocol Buffers.
+ *
+ * @param message The message to generate from.
+ * @param lineIndent A string to use as the prefix for all lines generated. Can
+ * be nil if no extra indent is needed.
+ *
+ * @return An NSString with the TextFormat of the message.
+ **/
+NSString *GPBTextFormatForMessage(GPBMessage *message,
+ NSString * __nullable lineIndent);
+
+/**
+ * Generates a string that should be a valid "TextFormat" for the C++ version
+ * of Protocol Buffers.
+ *
+ * @param unknownSet The unknown field set to generate from.
+ * @param lineIndent A string to use as the prefix for all lines generated. Can
+ * be nil if no extra indent is needed.
+ *
+ * @return An NSString with the TextFormat of the unknown field set.
+ **/
+NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet * __nullable unknownSet,
+ NSString * __nullable lineIndent);
+
+/**
+ * Checks if the given field number is set on a message.
+ *
+ * @param self The message to check.
+ * @param fieldNumber The field number to check.
+ *
+ * @return YES if the field number is set on the given message.
+ **/
+BOOL GPBMessageHasFieldNumberSet(GPBMessage *self, uint32_t fieldNumber);
+
+/**
+ * Checks if the given field is set on a message.
+ *
+ * @param self The message to check.
+ * @param field The field to check.
+ *
+ * @return YES if the field is set on the given message.
+ **/
+BOOL GPBMessageHasFieldSet(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Clears the given field for the given message.
+ *
+ * @param self The message for which to clear the field.
+ * @param field The field to clear.
+ **/
+void GPBClearMessageField(GPBMessage *self, GPBFieldDescriptor *field);
+
+//%PDDM-EXPAND GPB_ACCESSORS()
+// This block of code is generated, do not edit it directly.
+
+
+//
+// Get/Set a given field from/to a message.
+//
+
+// Single Fields
+
+/**
+ * Gets the value of a bytes field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+NSData *GPBGetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a bytes field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field, NSData *value);
+
+/**
+ * Gets the value of a string field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+NSString *GPBGetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a string field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field, NSString *value);
+
+/**
+ * Gets the value of a message field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+GPBMessage *GPBGetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a message field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value);
+
+/**
+ * Gets the value of a group field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+GPBMessage *GPBGetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a group field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value);
+
+/**
+ * Gets the value of a bool field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+BOOL GPBGetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a bool field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field, BOOL value);
+
+/**
+ * Gets the value of an int32 field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+int32_t GPBGetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of an int32 field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
+
+/**
+ * Gets the value of an uint32 field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+uint32_t GPBGetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of an uint32 field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field, uint32_t value);
+
+/**
+ * Gets the value of an int64 field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+int64_t GPBGetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of an int64 field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field, int64_t value);
+
+/**
+ * Gets the value of an uint64 field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+uint64_t GPBGetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of an uint64 field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field, uint64_t value);
+
+/**
+ * Gets the value of a float field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+float GPBGetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a float field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field, float value);
+
+/**
+ * Gets the value of a double field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ **/
+double GPBGetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a double field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The to set in the field.
+ **/
+void GPBSetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field, double value);
+
+/**
+ * Gets the given enum field of a message. For proto3, if the value isn't a
+ * member of the enum, @c kGPBUnrecognizedEnumeratorValue will be returned.
+ * GPBGetMessageRawEnumField will bypass the check and return whatever value
+ * was set.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ *
+ * @return The enum value for the given field.
+ **/
+int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Set the given enum field of a message. You can only set values that are
+ * members of the enum.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The enum value to set in the field.
+ **/
+void GPBSetMessageEnumField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int32_t value);
+
+/**
+ * Get the given enum field of a message. No check is done to ensure the value
+ * was defined in the enum.
+ *
+ * @param self The message from which to get the field.
+ * @param field The field to get.
+ *
+ * @return The raw enum value for the given field.
+ **/
+int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Set the given enum field of a message. You can set the value to anything,
+ * even a value that is not a member of the enum.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param value The raw enum value to set in the field.
+ **/
+void GPBSetMessageRawEnumField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int32_t value);
+
+// Repeated Fields
+
+/**
+ * Gets the value of a repeated field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The repeated field to get.
+ *
+ * @return A GPB*Array or an NSMutableArray based on the field's type.
+ **/
+id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a repeated field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param array A GPB*Array or NSMutableArray based on the field's type.
+ **/
+void GPBSetMessageRepeatedField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ id array);
+
+// Map Fields
+
+/**
+ * Gets the value of a map<> field.
+ *
+ * @param self The message from which to get the field.
+ * @param field The repeated field to get.
+ *
+ * @return A GPB*Dictionary or NSMutableDictionary based on the field's type.
+ **/
+id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field);
+
+/**
+ * Sets the value of a map<> field.
+ *
+ * @param self The message into which to set the field.
+ * @param field The field to set.
+ * @param dictionary A GPB*Dictionary or NSMutableDictionary based on the
+ * field's type.
+ **/
+void GPBSetMessageMapField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ id dictionary);
+
+//%PDDM-EXPAND-END GPB_ACCESSORS()
+
+/**
+ * Returns an empty NSData to assign to byte fields when you wish to assign them
+ * to empty. Prevents allocating a lot of little [NSData data] objects.
+ **/
+NSData *GPBEmptyNSData(void) __attribute__((pure));
+
+/**
+ * Drops the `unknownFields` from the given message and from all sub message.
+ **/
+void GPBMessageDropUnknownFieldsRecursively(GPBMessage *message);
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+
+//%PDDM-DEFINE GPB_ACCESSORS()
+//%
+//%//
+//%// Get/Set a given field from/to a message.
+//%//
+//%
+//%// Single Fields
+//%
+//%GPB_ACCESSOR_SINGLE_FULL(Bytes, NSData, , *)
+//%GPB_ACCESSOR_SINGLE_FULL(String, NSString, , *)
+//%GPB_ACCESSOR_SINGLE_FULL(Message, GPBMessage, , *)
+//%GPB_ACCESSOR_SINGLE_FULL(Group, GPBMessage, , *)
+//%GPB_ACCESSOR_SINGLE(Bool, BOOL, )
+//%GPB_ACCESSOR_SINGLE(Int32, int32_t, n)
+//%GPB_ACCESSOR_SINGLE(UInt32, uint32_t, n)
+//%GPB_ACCESSOR_SINGLE(Int64, int64_t, n)
+//%GPB_ACCESSOR_SINGLE(UInt64, uint64_t, n)
+//%GPB_ACCESSOR_SINGLE(Float, float, )
+//%GPB_ACCESSOR_SINGLE(Double, double, )
+//%/**
+//% * Gets the given enum field of a message. For proto3, if the value isn't a
+//% * member of the enum, @c kGPBUnrecognizedEnumeratorValue will be returned.
+//% * GPBGetMessageRawEnumField will bypass the check and return whatever value
+//% * was set.
+//% *
+//% * @param self The message from which to get the field.
+//% * @param field The field to get.
+//% *
+//% * @return The enum value for the given field.
+//% **/
+//%int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field);
+//%
+//%/**
+//% * Set the given enum field of a message. You can only set values that are
+//% * members of the enum.
+//% *
+//% * @param self The message into which to set the field.
+//% * @param field The field to set.
+//% * @param value The enum value to set in the field.
+//% **/
+//%void GPBSetMessageEnumField(GPBMessage *self,
+//% GPBFieldDescriptor *field,
+//% int32_t value);
+//%
+//%/**
+//% * Get the given enum field of a message. No check is done to ensure the value
+//% * was defined in the enum.
+//% *
+//% * @param self The message from which to get the field.
+//% * @param field The field to get.
+//% *
+//% * @return The raw enum value for the given field.
+//% **/
+//%int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field);
+//%
+//%/**
+//% * Set the given enum field of a message. You can set the value to anything,
+//% * even a value that is not a member of the enum.
+//% *
+//% * @param self The message into which to set the field.
+//% * @param field The field to set.
+//% * @param value The raw enum value to set in the field.
+//% **/
+//%void GPBSetMessageRawEnumField(GPBMessage *self,
+//% GPBFieldDescriptor *field,
+//% int32_t value);
+//%
+//%// Repeated Fields
+//%
+//%/**
+//% * Gets the value of a repeated field.
+//% *
+//% * @param self The message from which to get the field.
+//% * @param field The repeated field to get.
+//% *
+//% * @return A GPB*Array or an NSMutableArray based on the field's type.
+//% **/
+//%id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field);
+//%
+//%/**
+//% * Sets the value of a repeated field.
+//% *
+//% * @param self The message into which to set the field.
+//% * @param field The field to set.
+//% * @param array A GPB*Array or NSMutableArray based on the field's type.
+//% **/
+//%void GPBSetMessageRepeatedField(GPBMessage *self,
+//% GPBFieldDescriptor *field,
+//% id array);
+//%
+//%// Map Fields
+//%
+//%/**
+//% * Gets the value of a map<> field.
+//% *
+//% * @param self The message from which to get the field.
+//% * @param field The repeated field to get.
+//% *
+//% * @return A GPB*Dictionary or NSMutableDictionary based on the field's type.
+//% **/
+//%id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field);
+//%
+//%/**
+//% * Sets the value of a map<> field.
+//% *
+//% * @param self The message into which to set the field.
+//% * @param field The field to set.
+//% * @param dictionary A GPB*Dictionary or NSMutableDictionary based on the
+//% * field's type.
+//% **/
+//%void GPBSetMessageMapField(GPBMessage *self,
+//% GPBFieldDescriptor *field,
+//% id dictionary);
+//%
+
+//%PDDM-DEFINE GPB_ACCESSOR_SINGLE(NAME, TYPE, AN)
+//%GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, AN, )
+//%PDDM-DEFINE GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, AN, TisP)
+//%/**
+//% * Gets the value of a##AN NAME$L field.
+//% *
+//% * @param self The message from which to get the field.
+//% * @param field The field to get.
+//% **/
+//%TYPE TisP##GPBGetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field);
+//%
+//%/**
+//% * Sets the value of a##AN NAME$L field.
+//% *
+//% * @param self The message into which to set the field.
+//% * @param field The field to set.
+//% * @param value The to set in the field.
+//% **/
+//%void GPBSetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field, TYPE TisP##value);
+//%
diff --git a/third_party/protobuf/objectivec/GPBUtilities.m b/third_party/protobuf/objectivec/GPBUtilities.m
new file mode 100644
index 0000000000..5029ec73b3
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUtilities.m
@@ -0,0 +1,1923 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBUtilities_PackagePrivate.h"
+
+#import <objc/runtime.h>
+
+#import "GPBArray_PackagePrivate.h"
+#import "GPBDescriptor_PackagePrivate.h"
+#import "GPBDictionary_PackagePrivate.h"
+#import "GPBMessage_PackagePrivate.h"
+#import "GPBUnknownField.h"
+#import "GPBUnknownFieldSet.h"
+
+// Direct access is use for speed, to avoid even internally declaring things
+// read/write, etc. The warning is enabled in the project to ensure code calling
+// protos can turn on -Wdirect-ivar-access without issues.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+static void AppendTextFormatForMessage(GPBMessage *message,
+ NSMutableString *toStr,
+ NSString *lineIndent);
+
+NSData *GPBEmptyNSData(void) {
+ static dispatch_once_t onceToken;
+ static NSData *defaultNSData = nil;
+ dispatch_once(&onceToken, ^{
+ defaultNSData = [[NSData alloc] init];
+ });
+ return defaultNSData;
+}
+
+void GPBMessageDropUnknownFieldsRecursively(GPBMessage *initialMessage) {
+ if (!initialMessage) {
+ return;
+ }
+
+ // Use an array as a list to process to avoid recursion.
+ NSMutableArray *todo = [NSMutableArray arrayWithObject:initialMessage];
+
+ while (todo.count) {
+ GPBMessage *msg = todo.lastObject;
+ [todo removeLastObject];
+
+ // Clear unknowns.
+ msg.unknownFields = nil;
+
+ // Handle the message fields.
+ GPBDescriptor *descriptor = [[msg class] descriptor];
+ for (GPBFieldDescriptor *field in descriptor->fields_) {
+ if (!GPBFieldDataTypeIsMessage(field)) {
+ continue;
+ }
+ switch (field.fieldType) {
+ case GPBFieldTypeSingle:
+ if (GPBGetHasIvarField(msg, field)) {
+ GPBMessage *fieldMessage = GPBGetObjectIvarWithFieldNoAutocreate(msg, field);
+ [todo addObject:fieldMessage];
+ }
+ break;
+
+ case GPBFieldTypeRepeated: {
+ NSArray *fieldMessages = GPBGetObjectIvarWithFieldNoAutocreate(msg, field);
+ if (fieldMessages.count) {
+ [todo addObjectsFromArray:fieldMessages];
+ }
+ break;
+ }
+
+ case GPBFieldTypeMap: {
+ id rawFieldMap = GPBGetObjectIvarWithFieldNoAutocreate(msg, field);
+ switch (field.mapKeyDataType) {
+ case GPBDataTypeBool:
+ [(GPBBoolObjectDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^(
+ BOOL key, id _Nonnull object, BOOL * _Nonnull stop) {
+ #pragma unused(key, stop)
+ [todo addObject:object];
+ }];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ [(GPBUInt32ObjectDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^(
+ uint32_t key, id _Nonnull object, BOOL * _Nonnull stop) {
+ #pragma unused(key, stop)
+ [todo addObject:object];
+ }];
+ break;
+ case GPBDataTypeInt32:
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeSInt32:
+ [(GPBInt32ObjectDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^(
+ int32_t key, id _Nonnull object, BOOL * _Nonnull stop) {
+ #pragma unused(key, stop)
+ [todo addObject:object];
+ }];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ [(GPBUInt64ObjectDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^(
+ uint64_t key, id _Nonnull object, BOOL * _Nonnull stop) {
+ #pragma unused(key, stop)
+ [todo addObject:object];
+ }];
+ break;
+ case GPBDataTypeInt64:
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeSInt64:
+ [(GPBInt64ObjectDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^(
+ int64_t key, id _Nonnull object, BOOL * _Nonnull stop) {
+ #pragma unused(key, stop)
+ [todo addObject:object];
+ }];
+ break;
+ case GPBDataTypeString:
+ [(NSDictionary*)rawFieldMap enumerateKeysAndObjectsUsingBlock:^(
+ NSString * _Nonnull key, GPBMessage * _Nonnull obj, BOOL * _Nonnull stop) {
+ #pragma unused(key, stop)
+ [todo addObject:obj];
+ }];
+ break;
+ case GPBDataTypeFloat:
+ case GPBDataTypeDouble:
+ case GPBDataTypeEnum:
+ case GPBDataTypeBytes:
+ case GPBDataTypeGroup:
+ case GPBDataTypeMessage:
+ NSCAssert(NO, @"Aren't valid key types.");
+ }
+ break;
+ } // switch(field.mapKeyDataType)
+ } // switch(field.fieldType)
+ } // for(fields)
+
+ // Handle any extensions holding messages.
+ for (GPBExtensionDescriptor *extension in [msg extensionsCurrentlySet]) {
+ if (!GPBDataTypeIsMessage(extension.dataType)) {
+ continue;
+ }
+ if (extension.isRepeated) {
+ NSArray *extMessages = [msg getExtension:extension];
+ [todo addObjectsFromArray:extMessages];
+ } else {
+ GPBMessage *extMessage = [msg getExtension:extension];
+ [todo addObject:extMessage];
+ }
+ } // for(extensionsCurrentlySet)
+
+ } // while(todo.count)
+}
+
+
+// -- About Version Checks --
+// There's actually 3 places these checks all come into play:
+// 1. When the generated source is compile into .o files, the header check
+// happens. This is checking the protoc used matches the library being used
+// when making the .o.
+// 2. Every place a generated proto header is included in a developer's code,
+// the header check comes into play again. But this time it is checking that
+// the current library headers being used still support/match the ones for
+// the generated code.
+// 3. At runtime the final check here (GPBCheckRuntimeVersionsInternal), is
+// called from the generated code passing in values captured when the
+// generated code's .o was made. This checks that at runtime the generated
+// code and runtime library match.
+
+void GPBCheckRuntimeVersionSupport(int32_t objcRuntimeVersion) {
+ // NOTE: This is passing the value captured in the compiled code to check
+ // against the values captured when the runtime support was compiled. This
+ // ensures the library code isn't in a different framework/library that
+ // was generated with a non matching version.
+ if (GOOGLE_PROTOBUF_OBJC_VERSION < objcRuntimeVersion) {
+ // Library is too old for headers.
+ [NSException raise:NSInternalInconsistencyException
+ format:@"Linked to ProtocolBuffer runtime version %d,"
+ @" but code compiled needing atleast %d!",
+ GOOGLE_PROTOBUF_OBJC_VERSION, objcRuntimeVersion];
+ }
+ if (objcRuntimeVersion < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION) {
+ // Headers are too old for library.
+ [NSException raise:NSInternalInconsistencyException
+ format:@"Proto generation source compiled against runtime"
+ @" version %d, but this version of the runtime only"
+ @" supports back to %d!",
+ objcRuntimeVersion,
+ GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION];
+ }
+}
+
+// This api is no longer used for version checks. 30001 is the last version
+// using this old versioning model. When that support is removed, this function
+// can be removed (along with the declaration in GPBUtilities_PackagePrivate.h).
+void GPBCheckRuntimeVersionInternal(int32_t version) {
+ GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION == 30001,
+ time_to_remove_this_old_version_shim);
+ if (version != GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION) {
+ [NSException raise:NSInternalInconsistencyException
+ format:@"Linked to ProtocolBuffer runtime version %d,"
+ @" but code compiled with version %d!",
+ GOOGLE_PROTOBUF_OBJC_GEN_VERSION, version];
+ }
+}
+
+BOOL GPBMessageHasFieldNumberSet(GPBMessage *self, uint32_t fieldNumber) {
+ GPBDescriptor *descriptor = [self descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:fieldNumber];
+ return GPBMessageHasFieldSet(self, field);
+}
+
+BOOL GPBMessageHasFieldSet(GPBMessage *self, GPBFieldDescriptor *field) {
+ if (self == nil || field == nil) return NO;
+
+ // Repeated/Map don't use the bit, they check the count.
+ if (GPBFieldIsMapOrArray(field)) {
+ // Array/map type doesn't matter, since GPB*Array/NSArray and
+ // GPB*Dictionary/NSDictionary all support -count;
+ NSArray *arrayOrMap = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ return (arrayOrMap.count > 0);
+ } else {
+ return GPBGetHasIvarField(self, field);
+ }
+}
+
+void GPBClearMessageField(GPBMessage *self, GPBFieldDescriptor *field) {
+ // If not set, nothing to do.
+ if (!GPBGetHasIvarField(self, field)) {
+ return;
+ }
+
+ if (GPBFieldStoresObject(field)) {
+ // Object types are handled slightly differently, they need to be released.
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ id *typePtr = (id *)&storage[field->description_->offset];
+ [*typePtr release];
+ *typePtr = nil;
+ } else {
+ // POD types just need to clear the has bit as the Get* method will
+ // fetch the default when needed.
+ }
+ GPBSetHasIvarField(self, field, NO);
+}
+
+BOOL GPBGetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber) {
+ NSCAssert(self->messageStorage_ != NULL,
+ @"%@: All messages should have storage (from init)",
+ [self class]);
+ if (idx < 0) {
+ NSCAssert(fieldNumber != 0, @"Invalid field number.");
+ BOOL hasIvar = (self->messageStorage_->_has_storage_[-idx] == fieldNumber);
+ return hasIvar;
+ } else {
+ NSCAssert(idx != GPBNoHasBit, @"Invalid has bit.");
+ uint32_t byteIndex = idx / 32;
+ uint32_t bitMask = (1 << (idx % 32));
+ BOOL hasIvar =
+ (self->messageStorage_->_has_storage_[byteIndex] & bitMask) ? YES : NO;
+ return hasIvar;
+ }
+}
+
+uint32_t GPBGetHasOneof(GPBMessage *self, int32_t idx) {
+ NSCAssert(idx < 0, @"%@: invalid index (%d) for oneof.",
+ [self class], idx);
+ uint32_t result = self->messageStorage_->_has_storage_[-idx];
+ return result;
+}
+
+void GPBSetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber,
+ BOOL value) {
+ if (idx < 0) {
+ NSCAssert(fieldNumber != 0, @"Invalid field number.");
+ uint32_t *has_storage = self->messageStorage_->_has_storage_;
+ has_storage[-idx] = (value ? fieldNumber : 0);
+ } else {
+ NSCAssert(idx != GPBNoHasBit, @"Invalid has bit.");
+ uint32_t *has_storage = self->messageStorage_->_has_storage_;
+ uint32_t byte = idx / 32;
+ uint32_t bitMask = (1 << (idx % 32));
+ if (value) {
+ has_storage[byte] |= bitMask;
+ } else {
+ has_storage[byte] &= ~bitMask;
+ }
+ }
+}
+
+void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof,
+ int32_t oneofHasIndex, uint32_t fieldNumberNotToClear) {
+ uint32_t fieldNumberSet = GPBGetHasOneof(self, oneofHasIndex);
+ if ((fieldNumberSet == fieldNumberNotToClear) || (fieldNumberSet == 0)) {
+ // Do nothing/nothing set in the oneof.
+ return;
+ }
+
+ // Like GPBClearMessageField(), free the memory if an objecttype is set,
+ // pod types don't need to do anything.
+ GPBFieldDescriptor *fieldSet = [oneof fieldWithNumber:fieldNumberSet];
+ NSCAssert(fieldSet,
+ @"%@: oneof set to something (%u) not in the oneof?",
+ [self class], fieldNumberSet);
+ if (fieldSet && GPBFieldStoresObject(fieldSet)) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ id *typePtr = (id *)&storage[fieldSet->description_->offset];
+ [*typePtr release];
+ *typePtr = nil;
+ }
+
+ // Set to nothing stored in the oneof.
+ // (field number doesn't matter since setting to nothing).
+ GPBSetHasIvar(self, oneofHasIndex, 1, NO);
+}
+
+#pragma mark - IVar accessors
+
+//%PDDM-DEFINE IVAR_POD_ACCESSORS_DEFN(NAME, TYPE)
+//%TYPE GPBGetMessage##NAME##Field(GPBMessage *self,
+//% TYPE$S NAME$S GPBFieldDescriptor *field) {
+//% if (GPBGetHasIvarField(self, field)) {
+//% uint8_t *storage = (uint8_t *)self->messageStorage_;
+//% TYPE *typePtr = (TYPE *)&storage[field->description_->offset];
+//% return *typePtr;
+//% } else {
+//% return field.defaultValue.value##NAME;
+//% }
+//%}
+//%
+//%// Only exists for public api, no core code should use this.
+//%void GPBSetMessage##NAME##Field(GPBMessage *self,
+//% NAME$S GPBFieldDescriptor *field,
+//% NAME$S TYPE value) {
+//% if (self == nil || field == nil) return;
+//% GPBFileSyntax syntax = [self descriptor].file.syntax;
+//% GPBSet##NAME##IvarWithFieldInternal(self, field, value, syntax);
+//%}
+//%
+//%void GPBSet##NAME##IvarWithFieldInternal(GPBMessage *self,
+//% NAME$S GPBFieldDescriptor *field,
+//% NAME$S TYPE value,
+//% NAME$S GPBFileSyntax syntax) {
+//% GPBOneofDescriptor *oneof = field->containingOneof_;
+//% if (oneof) {
+//% GPBMessageFieldDescription *fieldDesc = field->description_;
+//% GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+//% }
+//% NSCAssert(self->messageStorage_ != NULL,
+//% @"%@: All messages should have storage (from init)",
+//% [self class]);
+//%#if defined(__clang_analyzer__)
+//% if (self->messageStorage_ == NULL) return;
+//%#endif
+//% uint8_t *storage = (uint8_t *)self->messageStorage_;
+//% TYPE *typePtr = (TYPE *)&storage[field->description_->offset];
+//% *typePtr = value;
+//% // proto2: any value counts as having been set; proto3, it
+//% // has to be a non zero value or be in a oneof.
+//% BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
+//% || (value != (TYPE)0)
+//% || (field->containingOneof_ != NULL));
+//% GPBSetHasIvarField(self, field, hasValue);
+//% GPBBecomeVisibleToAutocreator(self);
+//%}
+//%
+//%PDDM-DEFINE IVAR_ALIAS_DEFN_OBJECT(NAME, TYPE)
+//%// Only exists for public api, no core code should use this.
+//%TYPE *GPBGetMessage##NAME##Field(GPBMessage *self,
+//% TYPE$S NAME$S GPBFieldDescriptor *field) {
+//% return (TYPE *)GPBGetObjectIvarWithField(self, field);
+//%}
+//%
+//%// Only exists for public api, no core code should use this.
+//%void GPBSetMessage##NAME##Field(GPBMessage *self,
+//% NAME$S GPBFieldDescriptor *field,
+//% NAME$S TYPE *value) {
+//% GPBSetObjectIvarWithField(self, field, (id)value);
+//%}
+//%
+
+// Object types are handled slightly differently, they need to be released
+// and retained.
+
+void GPBSetAutocreatedRetainedObjectIvarWithField(
+ GPBMessage *self, GPBFieldDescriptor *field,
+ id __attribute__((ns_consumed)) value) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ id *typePtr = (id *)&storage[field->description_->offset];
+ NSCAssert(*typePtr == NULL, @"Can't set autocreated object more than once.");
+ *typePtr = value;
+}
+
+void GPBClearAutocreatedMessageIvarWithField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (GPBGetHasIvarField(self, field)) {
+ return;
+ }
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ id *typePtr = (id *)&storage[field->description_->offset];
+ GPBMessage *oldValue = *typePtr;
+ *typePtr = NULL;
+ GPBClearMessageAutocreator(oldValue);
+ [oldValue release];
+}
+
+// This exists only for briging some aliased types, nothing else should use it.
+static void GPBSetObjectIvarWithField(GPBMessage *self,
+ GPBFieldDescriptor *field, id value) {
+ if (self == nil || field == nil) return;
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetRetainedObjectIvarWithFieldInternal(self, field, [value retain],
+ syntax);
+}
+
+void GPBSetObjectIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field, id value,
+ GPBFileSyntax syntax) {
+ GPBSetRetainedObjectIvarWithFieldInternal(self, field, [value retain],
+ syntax);
+}
+
+void GPBSetRetainedObjectIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ id value, GPBFileSyntax syntax) {
+ NSCAssert(self->messageStorage_ != NULL,
+ @"%@: All messages should have storage (from init)",
+ [self class]);
+#if defined(__clang_analyzer__)
+ if (self->messageStorage_ == NULL) return;
+#endif
+ GPBDataType fieldType = GPBGetFieldDataType(field);
+ BOOL isMapOrArray = GPBFieldIsMapOrArray(field);
+ BOOL fieldIsMessage = GPBDataTypeIsMessage(fieldType);
+#ifdef DEBUG
+ if (value == nil && !isMapOrArray && !fieldIsMessage &&
+ field.hasDefaultValue) {
+ // Setting a message to nil is an obvious way to "clear" the value
+ // as there is no way to set a non-empty default value for messages.
+ //
+ // For Strings and Bytes that have default values set it is not clear what
+ // should be done when their value is set to nil. Is the intention just to
+ // clear the set value and reset to default, or is the intention to set the
+ // value to the empty string/data? Arguments can be made for both cases.
+ // 'nil' has been abused as a replacement for an empty string/data in ObjC.
+ // We decided to be consistent with all "object" types and clear the has
+ // field, and fall back on the default value. The warning below will only
+ // appear in debug, but the could should be changed so the intention is
+ // clear.
+ NSString *hasSel = NSStringFromSelector(field->hasOrCountSel_);
+ NSString *propName = field.name;
+ NSString *className = self.descriptor.name;
+ NSLog(@"warning: '%@.%@ = nil;' is not clearly defined for fields with "
+ @"default values. Please use '%@.%@ = %@' if you want to set it to "
+ @"empty, or call '%@.%@ = NO' to reset it to it's default value of "
+ @"'%@'. Defaulting to resetting default value.",
+ className, propName, className, propName,
+ (fieldType == GPBDataTypeString) ? @"@\"\"" : @"GPBEmptyNSData()",
+ className, hasSel, field.defaultValue.valueString);
+ // Note: valueString, depending on the type, it could easily be
+ // valueData/valueMessage.
+ }
+#endif // DEBUG
+ if (!isMapOrArray) {
+ // Non repeated/map can be in an oneof, clear any existing value from the
+ // oneof.
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+ }
+ // Clear "has" if they are being set to nil.
+ BOOL setHasValue = (value != nil);
+ // Under proto3, Bytes & String fields get cleared by resetting them to
+ // their default (empty) values, so if they are set to something of length
+ // zero, they are being cleared.
+ if ((syntax == GPBFileSyntaxProto3) && !fieldIsMessage &&
+ ([value length] == 0)) {
+ // Except, if the field was in a oneof, then it still gets recorded as
+ // having been set so the state of the oneof can be serialized back out.
+ if (!oneof) {
+ setHasValue = NO;
+ }
+ if (setHasValue) {
+ NSCAssert(value != nil, @"Should never be setting has for nil");
+ } else {
+ // The value passed in was retained, it must be released since we
+ // aren't saving anything in the field.
+ [value release];
+ value = nil;
+ }
+ }
+ GPBSetHasIvarField(self, field, setHasValue);
+ }
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ id *typePtr = (id *)&storage[field->description_->offset];
+
+ id oldValue = *typePtr;
+
+ *typePtr = value;
+
+ if (oldValue) {
+ if (isMapOrArray) {
+ if (field.fieldType == GPBFieldTypeRepeated) {
+ // If the old array was autocreated by us, then clear it.
+ if (GPBDataTypeIsObject(fieldType)) {
+ if ([oldValue isKindOfClass:[GPBAutocreatedArray class]]) {
+ GPBAutocreatedArray *autoArray = oldValue;
+ if (autoArray->_autocreator == self) {
+ autoArray->_autocreator = nil;
+ }
+ }
+ } else {
+ // Type doesn't matter, it is a GPB*Array.
+ GPBInt32Array *gpbArray = oldValue;
+ if (gpbArray->_autocreator == self) {
+ gpbArray->_autocreator = nil;
+ }
+ }
+ } else { // GPBFieldTypeMap
+ // If the old map was autocreated by us, then clear it.
+ if ((field.mapKeyDataType == GPBDataTypeString) &&
+ GPBDataTypeIsObject(fieldType)) {
+ if ([oldValue isKindOfClass:[GPBAutocreatedDictionary class]]) {
+ GPBAutocreatedDictionary *autoDict = oldValue;
+ if (autoDict->_autocreator == self) {
+ autoDict->_autocreator = nil;
+ }
+ }
+ } else {
+ // Type doesn't matter, it is a GPB*Dictionary.
+ GPBInt32Int32Dictionary *gpbDict = oldValue;
+ if (gpbDict->_autocreator == self) {
+ gpbDict->_autocreator = nil;
+ }
+ }
+ }
+ } else if (fieldIsMessage) {
+ // If the old message value was autocreated by us, then clear it.
+ GPBMessage *oldMessageValue = oldValue;
+ if (GPBWasMessageAutocreatedBy(oldMessageValue, self)) {
+ GPBClearMessageAutocreator(oldMessageValue);
+ }
+ }
+ [oldValue release];
+ }
+
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+id GPBGetObjectIvarWithFieldNoAutocreate(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (self->messageStorage_ == nil) {
+ return nil;
+ }
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ id *typePtr = (id *)&storage[field->description_->offset];
+ return *typePtr;
+}
+
+id GPBGetObjectIvarWithField(GPBMessage *self, GPBFieldDescriptor *field) {
+ NSCAssert(!GPBFieldIsMapOrArray(field), @"Shouldn't get here");
+ if (GPBGetHasIvarField(self, field)) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ id *typePtr = (id *)&storage[field->description_->offset];
+ return *typePtr;
+ }
+ // Not set...
+
+ // Non messages (string/data), get their default.
+ if (!GPBFieldDataTypeIsMessage(field)) {
+ return field.defaultValue.valueMessage;
+ }
+
+ GPBPrepareReadOnlySemaphore(self);
+ dispatch_semaphore_wait(self->readOnlySemaphore_, DISPATCH_TIME_FOREVER);
+ GPBMessage *result = GPBGetObjectIvarWithFieldNoAutocreate(self, field);
+ if (!result) {
+ // For non repeated messages, create the object, set it and return it.
+ // This object will not initially be visible via GPBGetHasIvar, so
+ // we save its creator so it can become visible if it's mutated later.
+ result = GPBCreateMessageWithAutocreator(field.msgClass, self, field);
+ GPBSetAutocreatedRetainedObjectIvarWithField(self, field, result);
+ }
+ dispatch_semaphore_signal(self->readOnlySemaphore_);
+ return result;
+}
+
+// Only exists for public api, no core code should use this.
+int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field) {
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ return GPBGetEnumIvarWithFieldInternal(self, field, syntax);
+}
+
+int32_t GPBGetEnumIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ GPBFileSyntax syntax) {
+ int32_t result = GPBGetMessageInt32Field(self, field);
+ // If this is presevering unknown enums, make sure the value is valid before
+ // returning it.
+ if (GPBHasPreservingUnknownEnumSemantics(syntax) &&
+ ![field isValidEnumValue:result]) {
+ result = kGPBUnrecognizedEnumeratorValue;
+ }
+ return result;
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field,
+ int32_t value) {
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetInt32IvarWithFieldInternal(self, field, value, syntax);
+}
+
+void GPBSetEnumIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field, int32_t value,
+ GPBFileSyntax syntax) {
+ // Don't allow in unknown values. Proto3 can use the Raw method.
+ if (![field isValidEnumValue:value]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@.%@: Attempt to set an unknown enum value (%d)",
+ [self class], field.name, value];
+ }
+ GPBSetInt32IvarWithFieldInternal(self, field, value, syntax);
+}
+
+// Only exists for public api, no core code should use this.
+int32_t GPBGetMessageRawEnumField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ int32_t result = GPBGetMessageInt32Field(self, field);
+ return result;
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field,
+ int32_t value) {
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetInt32IvarWithFieldInternal(self, field, value, syntax);
+}
+
+BOOL GPBGetMessageBoolField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (GPBGetHasIvarField(self, field)) {
+ // Bools are stored in the has bits to avoid needing explicit space in the
+ // storage structure.
+ // (the field number passed to the HasIvar helper doesn't really matter
+ // since the offset is never negative)
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ return GPBGetHasIvar(self, (int32_t)(fieldDesc->offset), fieldDesc->number);
+ } else {
+ return field.defaultValue.valueBool;
+ }
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageBoolField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ BOOL value) {
+ if (self == nil || field == nil) return;
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetBoolIvarWithFieldInternal(self, field, value, syntax);
+}
+
+void GPBSetBoolIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ BOOL value,
+ GPBFileSyntax syntax) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof) {
+ GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+ }
+
+ // Bools are stored in the has bits to avoid needing explicit space in the
+ // storage structure.
+ // (the field number passed to the HasIvar helper doesn't really matter since
+ // the offset is never negative)
+ GPBSetHasIvar(self, (int32_t)(fieldDesc->offset), fieldDesc->number, value);
+
+ // proto2: any value counts as having been set; proto3, it
+ // has to be a non zero value or be in a oneof.
+ BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
+ || (value != (BOOL)0)
+ || (field->containingOneof_ != NULL));
+ GPBSetHasIvarField(self, field, hasValue);
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+//%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Int32, int32_t)
+// This block of code is generated, do not edit it directly.
+
+int32_t GPBGetMessageInt32Field(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (GPBGetHasIvarField(self, field)) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ int32_t *typePtr = (int32_t *)&storage[field->description_->offset];
+ return *typePtr;
+ } else {
+ return field.defaultValue.valueInt32;
+ }
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageInt32Field(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int32_t value) {
+ if (self == nil || field == nil) return;
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetInt32IvarWithFieldInternal(self, field, value, syntax);
+}
+
+void GPBSetInt32IvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int32_t value,
+ GPBFileSyntax syntax) {
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+ }
+ NSCAssert(self->messageStorage_ != NULL,
+ @"%@: All messages should have storage (from init)",
+ [self class]);
+#if defined(__clang_analyzer__)
+ if (self->messageStorage_ == NULL) return;
+#endif
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ int32_t *typePtr = (int32_t *)&storage[field->description_->offset];
+ *typePtr = value;
+ // proto2: any value counts as having been set; proto3, it
+ // has to be a non zero value or be in a oneof.
+ BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
+ || (value != (int32_t)0)
+ || (field->containingOneof_ != NULL));
+ GPBSetHasIvarField(self, field, hasValue);
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+//%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(UInt32, uint32_t)
+// This block of code is generated, do not edit it directly.
+
+uint32_t GPBGetMessageUInt32Field(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (GPBGetHasIvarField(self, field)) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ uint32_t *typePtr = (uint32_t *)&storage[field->description_->offset];
+ return *typePtr;
+ } else {
+ return field.defaultValue.valueUInt32;
+ }
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageUInt32Field(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ uint32_t value) {
+ if (self == nil || field == nil) return;
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetUInt32IvarWithFieldInternal(self, field, value, syntax);
+}
+
+void GPBSetUInt32IvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ uint32_t value,
+ GPBFileSyntax syntax) {
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+ }
+ NSCAssert(self->messageStorage_ != NULL,
+ @"%@: All messages should have storage (from init)",
+ [self class]);
+#if defined(__clang_analyzer__)
+ if (self->messageStorage_ == NULL) return;
+#endif
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ uint32_t *typePtr = (uint32_t *)&storage[field->description_->offset];
+ *typePtr = value;
+ // proto2: any value counts as having been set; proto3, it
+ // has to be a non zero value or be in a oneof.
+ BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
+ || (value != (uint32_t)0)
+ || (field->containingOneof_ != NULL));
+ GPBSetHasIvarField(self, field, hasValue);
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+//%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Int64, int64_t)
+// This block of code is generated, do not edit it directly.
+
+int64_t GPBGetMessageInt64Field(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (GPBGetHasIvarField(self, field)) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ int64_t *typePtr = (int64_t *)&storage[field->description_->offset];
+ return *typePtr;
+ } else {
+ return field.defaultValue.valueInt64;
+ }
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageInt64Field(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int64_t value) {
+ if (self == nil || field == nil) return;
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetInt64IvarWithFieldInternal(self, field, value, syntax);
+}
+
+void GPBSetInt64IvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int64_t value,
+ GPBFileSyntax syntax) {
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+ }
+ NSCAssert(self->messageStorage_ != NULL,
+ @"%@: All messages should have storage (from init)",
+ [self class]);
+#if defined(__clang_analyzer__)
+ if (self->messageStorage_ == NULL) return;
+#endif
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ int64_t *typePtr = (int64_t *)&storage[field->description_->offset];
+ *typePtr = value;
+ // proto2: any value counts as having been set; proto3, it
+ // has to be a non zero value or be in a oneof.
+ BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
+ || (value != (int64_t)0)
+ || (field->containingOneof_ != NULL));
+ GPBSetHasIvarField(self, field, hasValue);
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+//%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(UInt64, uint64_t)
+// This block of code is generated, do not edit it directly.
+
+uint64_t GPBGetMessageUInt64Field(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (GPBGetHasIvarField(self, field)) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ uint64_t *typePtr = (uint64_t *)&storage[field->description_->offset];
+ return *typePtr;
+ } else {
+ return field.defaultValue.valueUInt64;
+ }
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageUInt64Field(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ uint64_t value) {
+ if (self == nil || field == nil) return;
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetUInt64IvarWithFieldInternal(self, field, value, syntax);
+}
+
+void GPBSetUInt64IvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ uint64_t value,
+ GPBFileSyntax syntax) {
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+ }
+ NSCAssert(self->messageStorage_ != NULL,
+ @"%@: All messages should have storage (from init)",
+ [self class]);
+#if defined(__clang_analyzer__)
+ if (self->messageStorage_ == NULL) return;
+#endif
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ uint64_t *typePtr = (uint64_t *)&storage[field->description_->offset];
+ *typePtr = value;
+ // proto2: any value counts as having been set; proto3, it
+ // has to be a non zero value or be in a oneof.
+ BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
+ || (value != (uint64_t)0)
+ || (field->containingOneof_ != NULL));
+ GPBSetHasIvarField(self, field, hasValue);
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+//%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Float, float)
+// This block of code is generated, do not edit it directly.
+
+float GPBGetMessageFloatField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (GPBGetHasIvarField(self, field)) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ float *typePtr = (float *)&storage[field->description_->offset];
+ return *typePtr;
+ } else {
+ return field.defaultValue.valueFloat;
+ }
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageFloatField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ float value) {
+ if (self == nil || field == nil) return;
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetFloatIvarWithFieldInternal(self, field, value, syntax);
+}
+
+void GPBSetFloatIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ float value,
+ GPBFileSyntax syntax) {
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+ }
+ NSCAssert(self->messageStorage_ != NULL,
+ @"%@: All messages should have storage (from init)",
+ [self class]);
+#if defined(__clang_analyzer__)
+ if (self->messageStorage_ == NULL) return;
+#endif
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ float *typePtr = (float *)&storage[field->description_->offset];
+ *typePtr = value;
+ // proto2: any value counts as having been set; proto3, it
+ // has to be a non zero value or be in a oneof.
+ BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
+ || (value != (float)0)
+ || (field->containingOneof_ != NULL));
+ GPBSetHasIvarField(self, field, hasValue);
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+//%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Double, double)
+// This block of code is generated, do not edit it directly.
+
+double GPBGetMessageDoubleField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ if (GPBGetHasIvarField(self, field)) {
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ double *typePtr = (double *)&storage[field->description_->offset];
+ return *typePtr;
+ } else {
+ return field.defaultValue.valueDouble;
+ }
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageDoubleField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ double value) {
+ if (self == nil || field == nil) return;
+ GPBFileSyntax syntax = [self descriptor].file.syntax;
+ GPBSetDoubleIvarWithFieldInternal(self, field, value, syntax);
+}
+
+void GPBSetDoubleIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ double value,
+ GPBFileSyntax syntax) {
+ GPBOneofDescriptor *oneof = field->containingOneof_;
+ if (oneof) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
+ }
+ NSCAssert(self->messageStorage_ != NULL,
+ @"%@: All messages should have storage (from init)",
+ [self class]);
+#if defined(__clang_analyzer__)
+ if (self->messageStorage_ == NULL) return;
+#endif
+ uint8_t *storage = (uint8_t *)self->messageStorage_;
+ double *typePtr = (double *)&storage[field->description_->offset];
+ *typePtr = value;
+ // proto2: any value counts as having been set; proto3, it
+ // has to be a non zero value or be in a oneof.
+ BOOL hasValue = ((syntax == GPBFileSyntaxProto2)
+ || (value != (double)0)
+ || (field->containingOneof_ != NULL));
+ GPBSetHasIvarField(self, field, hasValue);
+ GPBBecomeVisibleToAutocreator(self);
+}
+
+//%PDDM-EXPAND-END (6 expansions)
+
+// Aliases are function calls that are virtually the same.
+
+//%PDDM-EXPAND IVAR_ALIAS_DEFN_OBJECT(String, NSString)
+// This block of code is generated, do not edit it directly.
+
+// Only exists for public api, no core code should use this.
+NSString *GPBGetMessageStringField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ return (NSString *)GPBGetObjectIvarWithField(self, field);
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageStringField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ NSString *value) {
+ GPBSetObjectIvarWithField(self, field, (id)value);
+}
+
+//%PDDM-EXPAND IVAR_ALIAS_DEFN_OBJECT(Bytes, NSData)
+// This block of code is generated, do not edit it directly.
+
+// Only exists for public api, no core code should use this.
+NSData *GPBGetMessageBytesField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ return (NSData *)GPBGetObjectIvarWithField(self, field);
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageBytesField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ NSData *value) {
+ GPBSetObjectIvarWithField(self, field, (id)value);
+}
+
+//%PDDM-EXPAND IVAR_ALIAS_DEFN_OBJECT(Message, GPBMessage)
+// This block of code is generated, do not edit it directly.
+
+// Only exists for public api, no core code should use this.
+GPBMessage *GPBGetMessageMessageField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ return (GPBMessage *)GPBGetObjectIvarWithField(self, field);
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageMessageField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ GPBMessage *value) {
+ GPBSetObjectIvarWithField(self, field, (id)value);
+}
+
+//%PDDM-EXPAND IVAR_ALIAS_DEFN_OBJECT(Group, GPBMessage)
+// This block of code is generated, do not edit it directly.
+
+// Only exists for public api, no core code should use this.
+GPBMessage *GPBGetMessageGroupField(GPBMessage *self,
+ GPBFieldDescriptor *field) {
+ return (GPBMessage *)GPBGetObjectIvarWithField(self, field);
+}
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageGroupField(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ GPBMessage *value) {
+ GPBSetObjectIvarWithField(self, field, (id)value);
+}
+
+//%PDDM-EXPAND-END (4 expansions)
+
+// GPBGetMessageRepeatedField is defined in GPBMessage.m
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field, id array) {
+#if defined(DEBUG) && DEBUG
+ if (field.fieldType != GPBFieldTypeRepeated) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@.%@ is not a repeated field.",
+ [self class], field.name];
+ }
+ Class expectedClass = Nil;
+ switch (GPBGetFieldDataType(field)) {
+ case GPBDataTypeBool:
+ expectedClass = [GPBBoolArray class];
+ break;
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeInt32:
+ case GPBDataTypeSInt32:
+ expectedClass = [GPBInt32Array class];
+ break;
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ expectedClass = [GPBUInt32Array class];
+ break;
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeInt64:
+ case GPBDataTypeSInt64:
+ expectedClass = [GPBInt64Array class];
+ break;
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ expectedClass = [GPBUInt64Array class];
+ break;
+ case GPBDataTypeFloat:
+ expectedClass = [GPBFloatArray class];
+ break;
+ case GPBDataTypeDouble:
+ expectedClass = [GPBDoubleArray class];
+ break;
+ case GPBDataTypeBytes:
+ case GPBDataTypeString:
+ case GPBDataTypeMessage:
+ case GPBDataTypeGroup:
+ expectedClass = [NSMutableArray class];
+ break;
+ case GPBDataTypeEnum:
+ expectedClass = [GPBEnumArray class];
+ break;
+ }
+ if (array && ![array isKindOfClass:expectedClass]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@.%@: Expected %@ object, got %@.",
+ [self class], field.name, expectedClass, [array class]];
+ }
+#endif
+ GPBSetObjectIvarWithField(self, field, array);
+}
+
+#if defined(DEBUG) && DEBUG
+static NSString *TypeToStr(GPBDataType dataType) {
+ switch (dataType) {
+ case GPBDataTypeBool:
+ return @"Bool";
+ case GPBDataTypeSFixed32:
+ case GPBDataTypeInt32:
+ case GPBDataTypeSInt32:
+ return @"Int32";
+ case GPBDataTypeFixed32:
+ case GPBDataTypeUInt32:
+ return @"UInt32";
+ case GPBDataTypeSFixed64:
+ case GPBDataTypeInt64:
+ case GPBDataTypeSInt64:
+ return @"Int64";
+ case GPBDataTypeFixed64:
+ case GPBDataTypeUInt64:
+ return @"UInt64";
+ case GPBDataTypeFloat:
+ return @"Float";
+ case GPBDataTypeDouble:
+ return @"Double";
+ case GPBDataTypeBytes:
+ case GPBDataTypeString:
+ case GPBDataTypeMessage:
+ case GPBDataTypeGroup:
+ return @"Object";
+ case GPBDataTypeEnum:
+ return @"Bool";
+ }
+}
+#endif
+
+// GPBGetMessageMapField is defined in GPBMessage.m
+
+// Only exists for public api, no core code should use this.
+void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field,
+ id dictionary) {
+#if defined(DEBUG) && DEBUG
+ if (field.fieldType != GPBFieldTypeMap) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@.%@ is not a map<> field.",
+ [self class], field.name];
+ }
+ if (dictionary) {
+ GPBDataType keyDataType = field.mapKeyDataType;
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ NSString *keyStr = TypeToStr(keyDataType);
+ NSString *valueStr = TypeToStr(valueDataType);
+ if (keyDataType == GPBDataTypeString) {
+ keyStr = @"String";
+ }
+ Class expectedClass = Nil;
+ if ((keyDataType == GPBDataTypeString) &&
+ GPBDataTypeIsObject(valueDataType)) {
+ expectedClass = [NSMutableDictionary class];
+ } else {
+ NSString *className =
+ [NSString stringWithFormat:@"GPB%@%@Dictionary", keyStr, valueStr];
+ expectedClass = NSClassFromString(className);
+ NSCAssert(expectedClass, @"Missing a class (%@)?", expectedClass);
+ }
+ if (![dictionary isKindOfClass:expectedClass]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"%@.%@: Expected %@ object, got %@.",
+ [self class], field.name, expectedClass,
+ [dictionary class]];
+ }
+ }
+#endif
+ GPBSetObjectIvarWithField(self, field, dictionary);
+}
+
+#pragma mark - Misc Dynamic Runtime Utils
+
+const char *GPBMessageEncodingForSelector(SEL selector, BOOL instanceSel) {
+ Protocol *protocol =
+ objc_getProtocol(GPBStringifySymbol(GPBMessageSignatureProtocol));
+ struct objc_method_description description =
+ protocol_getMethodDescription(protocol, selector, NO, instanceSel);
+ return description.types;
+}
+
+#pragma mark - Text Format Support
+
+static void AppendStringEscaped(NSString *toPrint, NSMutableString *destStr) {
+ [destStr appendString:@"\""];
+ NSUInteger len = [toPrint length];
+ for (NSUInteger i = 0; i < len; ++i) {
+ unichar aChar = [toPrint characterAtIndex:i];
+ switch (aChar) {
+ case '\n': [destStr appendString:@"\\n"]; break;
+ case '\r': [destStr appendString:@"\\r"]; break;
+ case '\t': [destStr appendString:@"\\t"]; break;
+ case '\"': [destStr appendString:@"\\\""]; break;
+ case '\'': [destStr appendString:@"\\\'"]; break;
+ case '\\': [destStr appendString:@"\\\\"]; break;
+ default:
+ // This differs slightly from the C++ code in that the C++ doesn't
+ // generate UTF8; it looks at the string in UTF8, but escapes every
+ // byte > 0x7E.
+ if (aChar < 0x20) {
+ [destStr appendFormat:@"\\%d%d%d",
+ (aChar / 64), ((aChar % 64) / 8), (aChar % 8)];
+ } else {
+ [destStr appendFormat:@"%C", aChar];
+ }
+ break;
+ }
+ }
+ [destStr appendString:@"\""];
+}
+
+static void AppendBufferAsString(NSData *buffer, NSMutableString *destStr) {
+ const char *src = (const char *)[buffer bytes];
+ size_t srcLen = [buffer length];
+ [destStr appendString:@"\""];
+ for (const char *srcEnd = src + srcLen; src < srcEnd; src++) {
+ switch (*src) {
+ case '\n': [destStr appendString:@"\\n"]; break;
+ case '\r': [destStr appendString:@"\\r"]; break;
+ case '\t': [destStr appendString:@"\\t"]; break;
+ case '\"': [destStr appendString:@"\\\""]; break;
+ case '\'': [destStr appendString:@"\\\'"]; break;
+ case '\\': [destStr appendString:@"\\\\"]; break;
+ default:
+ if (isprint(*src)) {
+ [destStr appendFormat:@"%c", *src];
+ } else {
+ // NOTE: doing hex means you have to worry about the letter after
+ // the hex being another hex char and forcing that to be escaped, so
+ // use octal to keep it simple.
+ [destStr appendFormat:@"\\%03o", (uint8_t)(*src)];
+ }
+ break;
+ }
+ }
+ [destStr appendString:@"\""];
+}
+
+static void AppendTextFormatForMapMessageField(
+ id map, GPBFieldDescriptor *field, NSMutableString *toStr,
+ NSString *lineIndent, NSString *fieldName, NSString *lineEnding) {
+ GPBDataType keyDataType = field.mapKeyDataType;
+ GPBDataType valueDataType = GPBGetFieldDataType(field);
+ BOOL isMessageValue = GPBDataTypeIsMessage(valueDataType);
+
+ NSString *msgStartFirst =
+ [NSString stringWithFormat:@"%@%@ {%@\n", lineIndent, fieldName, lineEnding];
+ NSString *msgStart =
+ [NSString stringWithFormat:@"%@%@ {\n", lineIndent, fieldName];
+ NSString *msgEnd = [NSString stringWithFormat:@"%@}\n", lineIndent];
+
+ NSString *keyLine = [NSString stringWithFormat:@"%@ key: ", lineIndent];
+ NSString *valueLine = [NSString stringWithFormat:@"%@ value%s ", lineIndent,
+ (isMessageValue ? "" : ":")];
+
+ __block BOOL isFirst = YES;
+
+ if ((keyDataType == GPBDataTypeString) &&
+ GPBDataTypeIsObject(valueDataType)) {
+ // map is an NSDictionary.
+ NSDictionary *dict = map;
+ [dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) {
+ #pragma unused(stop)
+ [toStr appendString:(isFirst ? msgStartFirst : msgStart)];
+ isFirst = NO;
+
+ [toStr appendString:keyLine];
+ AppendStringEscaped(key, toStr);
+ [toStr appendString:@"\n"];
+
+ [toStr appendString:valueLine];
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wswitch-enum"
+ switch (valueDataType) {
+ case GPBDataTypeString:
+ AppendStringEscaped(value, toStr);
+ break;
+
+ case GPBDataTypeBytes:
+ AppendBufferAsString(value, toStr);
+ break;
+
+ case GPBDataTypeMessage:
+ [toStr appendString:@"{\n"];
+ NSString *subIndent = [lineIndent stringByAppendingString:@" "];
+ AppendTextFormatForMessage(value, toStr, subIndent);
+ [toStr appendFormat:@"%@ }", lineIndent];
+ break;
+
+ default:
+ NSCAssert(NO, @"Can't happen");
+ break;
+ }
+#pragma clang diagnostic pop
+ [toStr appendString:@"\n"];
+
+ [toStr appendString:msgEnd];
+ }];
+ } else {
+ // map is one of the GPB*Dictionary classes, type doesn't matter.
+ GPBInt32Int32Dictionary *dict = map;
+ [dict enumerateForTextFormat:^(id keyObj, id valueObj) {
+ [toStr appendString:(isFirst ? msgStartFirst : msgStart)];
+ isFirst = NO;
+
+ // Key always is a NSString.
+ if (keyDataType == GPBDataTypeString) {
+ [toStr appendString:keyLine];
+ AppendStringEscaped(keyObj, toStr);
+ [toStr appendString:@"\n"];
+ } else {
+ [toStr appendFormat:@"%@%@\n", keyLine, keyObj];
+ }
+
+ [toStr appendString:valueLine];
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wswitch-enum"
+ switch (valueDataType) {
+ case GPBDataTypeString:
+ AppendStringEscaped(valueObj, toStr);
+ break;
+
+ case GPBDataTypeBytes:
+ AppendBufferAsString(valueObj, toStr);
+ break;
+
+ case GPBDataTypeMessage:
+ [toStr appendString:@"{\n"];
+ NSString *subIndent = [lineIndent stringByAppendingString:@" "];
+ AppendTextFormatForMessage(valueObj, toStr, subIndent);
+ [toStr appendFormat:@"%@ }", lineIndent];
+ break;
+
+ case GPBDataTypeEnum: {
+ int32_t enumValue = [valueObj intValue];
+ NSString *valueStr = nil;
+ GPBEnumDescriptor *descriptor = field.enumDescriptor;
+ if (descriptor) {
+ valueStr = [descriptor textFormatNameForValue:enumValue];
+ }
+ if (valueStr) {
+ [toStr appendString:valueStr];
+ } else {
+ [toStr appendFormat:@"%d", enumValue];
+ }
+ break;
+ }
+
+ default:
+ NSCAssert(valueDataType != GPBDataTypeGroup, @"Can't happen");
+ // Everything else is a NSString.
+ [toStr appendString:valueObj];
+ break;
+ }
+#pragma clang diagnostic pop
+ [toStr appendString:@"\n"];
+
+ [toStr appendString:msgEnd];
+ }];
+ }
+}
+
+static void AppendTextFormatForMessageField(GPBMessage *message,
+ GPBFieldDescriptor *field,
+ NSMutableString *toStr,
+ NSString *lineIndent) {
+ id arrayOrMap;
+ NSUInteger count;
+ GPBFieldType fieldType = field.fieldType;
+ switch (fieldType) {
+ case GPBFieldTypeSingle:
+ arrayOrMap = nil;
+ count = (GPBGetHasIvarField(message, field) ? 1 : 0);
+ break;
+
+ case GPBFieldTypeRepeated:
+ // Will be NSArray or GPB*Array, type doesn't matter, they both
+ // implement count.
+ arrayOrMap = GPBGetObjectIvarWithFieldNoAutocreate(message, field);
+ count = [(NSArray *)arrayOrMap count];
+ break;
+
+ case GPBFieldTypeMap: {
+ // Will be GPB*Dictionary or NSMutableDictionary, type doesn't matter,
+ // they both implement count.
+ arrayOrMap = GPBGetObjectIvarWithFieldNoAutocreate(message, field);
+ count = [(NSDictionary *)arrayOrMap count];
+ break;
+ }
+ }
+
+ if (count == 0) {
+ // Nothing to print, out of here.
+ return;
+ }
+
+ NSString *lineEnding = @"";
+
+ // If the name can't be reversed or support for extra info was turned off,
+ // this can return nil.
+ NSString *fieldName = [field textFormatName];
+ if ([fieldName length] == 0) {
+ fieldName = [NSString stringWithFormat:@"%u", GPBFieldNumber(field)];
+ // If there is only one entry, put the objc name as a comment, other wise
+ // add it before the repeated values.
+ if (count > 1) {
+ [toStr appendFormat:@"%@# %@\n", lineIndent, field.name];
+ } else {
+ lineEnding = [NSString stringWithFormat:@" # %@", field.name];
+ }
+ }
+
+ if (fieldType == GPBFieldTypeMap) {
+ AppendTextFormatForMapMessageField(arrayOrMap, field, toStr, lineIndent,
+ fieldName, lineEnding);
+ return;
+ }
+
+ id array = arrayOrMap;
+ const BOOL isRepeated = (array != nil);
+
+ GPBDataType fieldDataType = GPBGetFieldDataType(field);
+ BOOL isMessageField = GPBDataTypeIsMessage(fieldDataType);
+ for (NSUInteger j = 0; j < count; ++j) {
+ // Start the line.
+ [toStr appendFormat:@"%@%@%s ", lineIndent, fieldName,
+ (isMessageField ? "" : ":")];
+
+ // The value.
+ switch (fieldDataType) {
+#define FIELD_CASE(GPBDATATYPE, CTYPE, REAL_TYPE, ...) \
+ case GPBDataType##GPBDATATYPE: { \
+ CTYPE v = (isRepeated ? [(GPB##REAL_TYPE##Array *)array valueAtIndex:j] \
+ : GPBGetMessage##REAL_TYPE##Field(message, field)); \
+ [toStr appendFormat:__VA_ARGS__, v]; \
+ break; \
+ }
+
+ FIELD_CASE(Int32, int32_t, Int32, @"%d")
+ FIELD_CASE(SInt32, int32_t, Int32, @"%d")
+ FIELD_CASE(SFixed32, int32_t, Int32, @"%d")
+ FIELD_CASE(UInt32, uint32_t, UInt32, @"%u")
+ FIELD_CASE(Fixed32, uint32_t, UInt32, @"%u")
+ FIELD_CASE(Int64, int64_t, Int64, @"%lld")
+ FIELD_CASE(SInt64, int64_t, Int64, @"%lld")
+ FIELD_CASE(SFixed64, int64_t, Int64, @"%lld")
+ FIELD_CASE(UInt64, uint64_t, UInt64, @"%llu")
+ FIELD_CASE(Fixed64, uint64_t, UInt64, @"%llu")
+ FIELD_CASE(Float, float, Float, @"%.*g", FLT_DIG)
+ FIELD_CASE(Double, double, Double, @"%.*lg", DBL_DIG)
+
+#undef FIELD_CASE
+
+ case GPBDataTypeEnum: {
+ int32_t v = (isRepeated ? [(GPBEnumArray *)array rawValueAtIndex:j]
+ : GPBGetMessageInt32Field(message, field));
+ NSString *valueStr = nil;
+ GPBEnumDescriptor *descriptor = field.enumDescriptor;
+ if (descriptor) {
+ valueStr = [descriptor textFormatNameForValue:v];
+ }
+ if (valueStr) {
+ [toStr appendString:valueStr];
+ } else {
+ [toStr appendFormat:@"%d", v];
+ }
+ break;
+ }
+
+ case GPBDataTypeBool: {
+ BOOL v = (isRepeated ? [(GPBBoolArray *)array valueAtIndex:j]
+ : GPBGetMessageBoolField(message, field));
+ [toStr appendString:(v ? @"true" : @"false")];
+ break;
+ }
+
+ case GPBDataTypeString: {
+ NSString *v = (isRepeated ? [(NSArray *)array objectAtIndex:j]
+ : GPBGetMessageStringField(message, field));
+ AppendStringEscaped(v, toStr);
+ break;
+ }
+
+ case GPBDataTypeBytes: {
+ NSData *v = (isRepeated ? [(NSArray *)array objectAtIndex:j]
+ : GPBGetMessageBytesField(message, field));
+ AppendBufferAsString(v, toStr);
+ break;
+ }
+
+ case GPBDataTypeGroup:
+ case GPBDataTypeMessage: {
+ GPBMessage *v =
+ (isRepeated ? [(NSArray *)array objectAtIndex:j]
+ : GPBGetObjectIvarWithField(message, field));
+ [toStr appendFormat:@"{%@\n", lineEnding];
+ NSString *subIndent = [lineIndent stringByAppendingString:@" "];
+ AppendTextFormatForMessage(v, toStr, subIndent);
+ [toStr appendFormat:@"%@}", lineIndent];
+ lineEnding = @"";
+ break;
+ }
+
+ } // switch(fieldDataType)
+
+ // End the line.
+ [toStr appendFormat:@"%@\n", lineEnding];
+
+ } // for(count)
+}
+
+static void AppendTextFormatForMessageExtensionRange(GPBMessage *message,
+ NSArray *activeExtensions,
+ GPBExtensionRange range,
+ NSMutableString *toStr,
+ NSString *lineIndent) {
+ uint32_t start = range.start;
+ uint32_t end = range.end;
+ for (GPBExtensionDescriptor *extension in activeExtensions) {
+ uint32_t fieldNumber = extension.fieldNumber;
+ if (fieldNumber < start) {
+ // Not there yet.
+ continue;
+ }
+ if (fieldNumber > end) {
+ // Done.
+ break;
+ }
+
+ id rawExtValue = [message getExtension:extension];
+ BOOL isRepeated = extension.isRepeated;
+
+ NSUInteger numValues = 1;
+ NSString *lineEnding = @"";
+ if (isRepeated) {
+ numValues = [(NSArray *)rawExtValue count];
+ }
+
+ NSString *singletonName = extension.singletonName;
+ if (numValues == 1) {
+ lineEnding = [NSString stringWithFormat:@" # [%@]", singletonName];
+ } else {
+ [toStr appendFormat:@"%@# [%@]\n", lineIndent, singletonName];
+ }
+
+ GPBDataType extDataType = extension.dataType;
+ for (NSUInteger j = 0; j < numValues; ++j) {
+ id curValue = (isRepeated ? [rawExtValue objectAtIndex:j] : rawExtValue);
+
+ // Start the line.
+ [toStr appendFormat:@"%@%u%s ", lineIndent, fieldNumber,
+ (GPBDataTypeIsMessage(extDataType) ? "" : ":")];
+
+ // The value.
+ switch (extDataType) {
+#define FIELD_CASE(GPBDATATYPE, CTYPE, NUMSELECTOR, ...) \
+ case GPBDataType##GPBDATATYPE: { \
+ CTYPE v = [(NSNumber *)curValue NUMSELECTOR]; \
+ [toStr appendFormat:__VA_ARGS__, v]; \
+ break; \
+ }
+
+ FIELD_CASE(Int32, int32_t, intValue, @"%d")
+ FIELD_CASE(SInt32, int32_t, intValue, @"%d")
+ FIELD_CASE(SFixed32, int32_t, unsignedIntValue, @"%d")
+ FIELD_CASE(UInt32, uint32_t, unsignedIntValue, @"%u")
+ FIELD_CASE(Fixed32, uint32_t, unsignedIntValue, @"%u")
+ FIELD_CASE(Int64, int64_t, longLongValue, @"%lld")
+ FIELD_CASE(SInt64, int64_t, longLongValue, @"%lld")
+ FIELD_CASE(SFixed64, int64_t, longLongValue, @"%lld")
+ FIELD_CASE(UInt64, uint64_t, unsignedLongLongValue, @"%llu")
+ FIELD_CASE(Fixed64, uint64_t, unsignedLongLongValue, @"%llu")
+ FIELD_CASE(Float, float, floatValue, @"%.*g", FLT_DIG)
+ FIELD_CASE(Double, double, doubleValue, @"%.*lg", DBL_DIG)
+ // TODO: Add a comment with the enum name from enum descriptors
+ // (might not be real value, so leave it as a comment, ObjC compiler
+ // name mangles differently). Doesn't look like we actually generate
+ // an enum descriptor reference like we do for normal fields, so this
+ // will take a compiler change.
+ FIELD_CASE(Enum, int32_t, intValue, @"%d")
+
+#undef FIELD_CASE
+
+ case GPBDataTypeBool:
+ [toStr appendString:([(NSNumber *)curValue boolValue] ? @"true"
+ : @"false")];
+ break;
+
+ case GPBDataTypeString:
+ AppendStringEscaped(curValue, toStr);
+ break;
+
+ case GPBDataTypeBytes:
+ AppendBufferAsString((NSData *)curValue, toStr);
+ break;
+
+ case GPBDataTypeGroup:
+ case GPBDataTypeMessage: {
+ [toStr appendFormat:@"{%@\n", lineEnding];
+ NSString *subIndent = [lineIndent stringByAppendingString:@" "];
+ AppendTextFormatForMessage(curValue, toStr, subIndent);
+ [toStr appendFormat:@"%@}", lineIndent];
+ lineEnding = @"";
+ break;
+ }
+
+ } // switch(extDataType)
+
+ } // for(numValues)
+
+ // End the line.
+ [toStr appendFormat:@"%@\n", lineEnding];
+
+ } // for..in(activeExtensions)
+}
+
+static void AppendTextFormatForMessage(GPBMessage *message,
+ NSMutableString *toStr,
+ NSString *lineIndent) {
+ GPBDescriptor *descriptor = [message descriptor];
+ NSArray *fieldsArray = descriptor->fields_;
+ NSUInteger fieldCount = fieldsArray.count;
+ const GPBExtensionRange *extensionRanges = descriptor.extensionRanges;
+ NSUInteger extensionRangesCount = descriptor.extensionRangesCount;
+ NSArray *activeExtensions = [[message extensionsCurrentlySet]
+ sortedArrayUsingSelector:@selector(compareByFieldNumber:)];
+ for (NSUInteger i = 0, j = 0; i < fieldCount || j < extensionRangesCount;) {
+ if (i == fieldCount) {
+ AppendTextFormatForMessageExtensionRange(
+ message, activeExtensions, extensionRanges[j++], toStr, lineIndent);
+ } else if (j == extensionRangesCount ||
+ GPBFieldNumber(fieldsArray[i]) < extensionRanges[j].start) {
+ AppendTextFormatForMessageField(message, fieldsArray[i++], toStr,
+ lineIndent);
+ } else {
+ AppendTextFormatForMessageExtensionRange(
+ message, activeExtensions, extensionRanges[j++], toStr, lineIndent);
+ }
+ }
+
+ NSString *unknownFieldsStr =
+ GPBTextFormatForUnknownFieldSet(message.unknownFields, lineIndent);
+ if ([unknownFieldsStr length] > 0) {
+ [toStr appendFormat:@"%@# --- Unknown fields ---\n", lineIndent];
+ [toStr appendString:unknownFieldsStr];
+ }
+}
+
+NSString *GPBTextFormatForMessage(GPBMessage *message, NSString *lineIndent) {
+ if (message == nil) return @"";
+ if (lineIndent == nil) lineIndent = @"";
+
+ NSMutableString *buildString = [NSMutableString string];
+ AppendTextFormatForMessage(message, buildString, lineIndent);
+ return buildString;
+}
+
+NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet *unknownSet,
+ NSString *lineIndent) {
+ if (unknownSet == nil) return @"";
+ if (lineIndent == nil) lineIndent = @"";
+
+ NSMutableString *result = [NSMutableString string];
+ for (GPBUnknownField *field in [unknownSet sortedFields]) {
+ int32_t fieldNumber = [field number];
+
+#define PRINT_LOOP(PROPNAME, CTYPE, FORMAT) \
+ [field.PROPNAME \
+ enumerateValuesWithBlock:^(CTYPE value, NSUInteger idx, BOOL * stop) { \
+ _Pragma("unused(idx, stop)"); \
+ [result \
+ appendFormat:@"%@%d: " #FORMAT "\n", lineIndent, fieldNumber, value]; \
+ }];
+
+ PRINT_LOOP(varintList, uint64_t, %llu);
+ PRINT_LOOP(fixed32List, uint32_t, 0x%X);
+ PRINT_LOOP(fixed64List, uint64_t, 0x%llX);
+
+#undef PRINT_LOOP
+
+ // NOTE: C++ version of TextFormat tries to parse this as a message
+ // and print that if it succeeds.
+ for (NSData *data in field.lengthDelimitedList) {
+ [result appendFormat:@"%@%d: ", lineIndent, fieldNumber];
+ AppendBufferAsString(data, result);
+ [result appendString:@"\n"];
+ }
+
+ for (GPBUnknownFieldSet *subUnknownSet in field.groupList) {
+ [result appendFormat:@"%@%d: {\n", lineIndent, fieldNumber];
+ NSString *subIndent = [lineIndent stringByAppendingString:@" "];
+ NSString *subUnknwonSetStr =
+ GPBTextFormatForUnknownFieldSet(subUnknownSet, subIndent);
+ [result appendString:subUnknwonSetStr];
+ [result appendFormat:@"%@}\n", lineIndent];
+ }
+ }
+ return result;
+}
+
+// Helpers to decode a varint. Not using GPBCodedInputStream version because
+// that needs a state object, and we don't want to create an input stream out
+// of the data.
+GPB_INLINE int8_t ReadRawByteFromData(const uint8_t **data) {
+ int8_t result = *((int8_t *)(*data));
+ ++(*data);
+ return result;
+}
+
+static int32_t ReadRawVarint32FromData(const uint8_t **data) {
+ int8_t tmp = ReadRawByteFromData(data);
+ if (tmp >= 0) {
+ return tmp;
+ }
+ int32_t result = tmp & 0x7f;
+ if ((tmp = ReadRawByteFromData(data)) >= 0) {
+ result |= tmp << 7;
+ } else {
+ result |= (tmp & 0x7f) << 7;
+ if ((tmp = ReadRawByteFromData(data)) >= 0) {
+ result |= tmp << 14;
+ } else {
+ result |= (tmp & 0x7f) << 14;
+ if ((tmp = ReadRawByteFromData(data)) >= 0) {
+ result |= tmp << 21;
+ } else {
+ result |= (tmp & 0x7f) << 21;
+ result |= (tmp = ReadRawByteFromData(data)) << 28;
+ if (tmp < 0) {
+ // Discard upper 32 bits.
+ for (int i = 0; i < 5; i++) {
+ if (ReadRawByteFromData(data) >= 0) {
+ return result;
+ }
+ }
+ [NSException raise:NSParseErrorException
+ format:@"Unable to read varint32"];
+ }
+ }
+ }
+ }
+ return result;
+}
+
+NSString *GPBDecodeTextFormatName(const uint8_t *decodeData, int32_t key,
+ NSString *inputStr) {
+ // decodData form:
+ // varint32: num entries
+ // for each entry:
+ // varint32: key
+ // bytes*: decode data
+ //
+ // decode data one of two forms:
+ // 1: a \0 followed by the string followed by an \0
+ // 2: bytecodes to transform an input into the right thing, ending with \0
+ //
+ // the bytes codes are of the form:
+ // 0xabbccccc
+ // 0x0 (all zeros), end.
+ // a - if set, add an underscore
+ // bb - 00 ccccc bytes as is
+ // bb - 10 ccccc upper first, as is on rest, ccccc byte total
+ // bb - 01 ccccc lower first, as is on rest, ccccc byte total
+ // bb - 11 ccccc all upper, ccccc byte total
+
+ if (!decodeData || !inputStr) {
+ return nil;
+ }
+
+ // Find key
+ const uint8_t *scan = decodeData;
+ int32_t numEntries = ReadRawVarint32FromData(&scan);
+ BOOL foundKey = NO;
+ while (!foundKey && (numEntries > 0)) {
+ --numEntries;
+ int32_t dataKey = ReadRawVarint32FromData(&scan);
+ if (dataKey == key) {
+ foundKey = YES;
+ } else {
+ // If it is a inlined string, it will start with \0; if it is bytecode it
+ // will start with a code. So advance one (skipping the inline string
+ // marker), and then loop until reaching the end marker (\0).
+ ++scan;
+ while (*scan != 0) ++scan;
+ // Now move past the end marker.
+ ++scan;
+ }
+ }
+
+ if (!foundKey) {
+ return nil;
+ }
+
+ // Decode
+
+ if (*scan == 0) {
+ // Inline string. Move over the marker, and NSString can take it as
+ // UTF8.
+ ++scan;
+ NSString *result = [NSString stringWithUTF8String:(const char *)scan];
+ return result;
+ }
+
+ NSMutableString *result =
+ [NSMutableString stringWithCapacity:[inputStr length]];
+
+ const uint8_t kAddUnderscore = 0b10000000;
+ const uint8_t kOpMask = 0b01100000;
+ // const uint8_t kOpAsIs = 0b00000000;
+ const uint8_t kOpFirstUpper = 0b01000000;
+ const uint8_t kOpFirstLower = 0b00100000;
+ const uint8_t kOpAllUpper = 0b01100000;
+ const uint8_t kSegmentLenMask = 0b00011111;
+
+ NSInteger i = 0;
+ for (; *scan != 0; ++scan) {
+ if (*scan & kAddUnderscore) {
+ [result appendString:@"_"];
+ }
+ int segmentLen = *scan & kSegmentLenMask;
+ uint8_t decodeOp = *scan & kOpMask;
+
+ // Do op specific handling of the first character.
+ if (decodeOp == kOpFirstUpper) {
+ unichar c = [inputStr characterAtIndex:i];
+ [result appendFormat:@"%c", toupper((char)c)];
+ ++i;
+ --segmentLen;
+ } else if (decodeOp == kOpFirstLower) {
+ unichar c = [inputStr characterAtIndex:i];
+ [result appendFormat:@"%c", tolower((char)c)];
+ ++i;
+ --segmentLen;
+ }
+ // else op == kOpAsIs || op == kOpAllUpper
+
+ // Now pull over the rest of the length for this segment.
+ for (int x = 0; x < segmentLen; ++x) {
+ unichar c = [inputStr characterAtIndex:(i + x)];
+ if (decodeOp == kOpAllUpper) {
+ [result appendFormat:@"%c", toupper((char)c)];
+ } else {
+ [result appendFormat:@"%C", c];
+ }
+ }
+ i += segmentLen;
+ }
+
+ return result;
+}
+
+#pragma clang diagnostic pop
+
+BOOL GPBClassHasSel(Class aClass, SEL sel) {
+ // NOTE: We have to use class_copyMethodList, all other runtime method
+ // lookups actually also resolve the method implementation and this
+ // is called from within those methods.
+
+ BOOL result = NO;
+ unsigned int methodCount = 0;
+ Method *methodList = class_copyMethodList(aClass, &methodCount);
+ for (unsigned int i = 0; i < methodCount; ++i) {
+ SEL methodSelector = method_getName(methodList[i]);
+ if (methodSelector == sel) {
+ result = YES;
+ break;
+ }
+ }
+ free(methodList);
+ return result;
+}
+
+#pragma mark - GPBMessageSignatureProtocol
+
+// A series of selectors that are used solely to get @encoding values
+// for them by the dynamic protobuf runtime code. An object using the protocol
+// needs to be declared for the protocol to be valid at runtime.
+@interface GPBMessageSignatureProtocol : NSObject<GPBMessageSignatureProtocol>
+@end
+@implementation GPBMessageSignatureProtocol
+@end
diff --git a/third_party/protobuf/objectivec/GPBUtilities_PackagePrivate.h b/third_party/protobuf/objectivec/GPBUtilities_PackagePrivate.h
new file mode 100644
index 0000000000..16859d4875
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBUtilities_PackagePrivate.h
@@ -0,0 +1,350 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+#import "GPBUtilities.h"
+
+#import "GPBDescriptor_PackagePrivate.h"
+
+// Macros for stringifying library symbols. These are used in the generated
+// PB descriptor classes wherever a library symbol name is represented as a
+// string. See README.google for more information.
+#define GPBStringify(S) #S
+#define GPBStringifySymbol(S) GPBStringify(S)
+
+#define GPBNSStringify(S) @#S
+#define GPBNSStringifySymbol(S) GPBNSStringify(S)
+
+// Constant to internally mark when there is no has bit.
+#define GPBNoHasBit INT32_MAX
+
+CF_EXTERN_C_BEGIN
+
+// These two are used to inject a runtime check for version mismatch into the
+// generated sources to make sure they are linked with a supporting runtime.
+void GPBCheckRuntimeVersionSupport(int32_t objcRuntimeVersion);
+GPB_INLINE void GPB_DEBUG_CHECK_RUNTIME_VERSIONS() {
+ // NOTE: By being inline here, this captures the value from the library's
+ // headers at the time the generated code was compiled.
+#if defined(DEBUG) && DEBUG
+ GPBCheckRuntimeVersionSupport(GOOGLE_PROTOBUF_OBJC_VERSION);
+#endif
+}
+
+// Legacy version of the checks, remove when GOOGLE_PROTOBUF_OBJC_GEN_VERSION
+// goes away (see more info in GPBBootstrap.h).
+void GPBCheckRuntimeVersionInternal(int32_t version);
+GPB_INLINE void GPBDebugCheckRuntimeVersion() {
+#if defined(DEBUG) && DEBUG
+ GPBCheckRuntimeVersionInternal(GOOGLE_PROTOBUF_OBJC_GEN_VERSION);
+#endif
+}
+
+// Conversion functions for de/serializing floating point types.
+
+GPB_INLINE int64_t GPBConvertDoubleToInt64(double v) {
+ union { double f; int64_t i; } u;
+ u.f = v;
+ return u.i;
+}
+
+GPB_INLINE int32_t GPBConvertFloatToInt32(float v) {
+ union { float f; int32_t i; } u;
+ u.f = v;
+ return u.i;
+}
+
+GPB_INLINE double GPBConvertInt64ToDouble(int64_t v) {
+ union { double f; int64_t i; } u;
+ u.i = v;
+ return u.f;
+}
+
+GPB_INLINE float GPBConvertInt32ToFloat(int32_t v) {
+ union { float f; int32_t i; } u;
+ u.i = v;
+ return u.f;
+}
+
+GPB_INLINE int32_t GPBLogicalRightShift32(int32_t value, int32_t spaces) {
+ return (int32_t)((uint32_t)(value) >> spaces);
+}
+
+GPB_INLINE int64_t GPBLogicalRightShift64(int64_t value, int32_t spaces) {
+ return (int64_t)((uint64_t)(value) >> spaces);
+}
+
+// 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.)
+GPB_INLINE int32_t GPBDecodeZigZag32(uint32_t n) {
+ return (int32_t)(GPBLogicalRightShift32((int32_t)n, 1) ^ -((int32_t)(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.)
+GPB_INLINE int64_t GPBDecodeZigZag64(uint64_t n) {
+ return (int64_t)(GPBLogicalRightShift64((int64_t)n, 1) ^ -((int64_t)(n) & 1));
+}
+
+// Encode 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.)
+GPB_INLINE uint32_t GPBEncodeZigZag32(int32_t n) {
+ // Note: the right-shift must be arithmetic
+ return (uint32_t)((n << 1) ^ (n >> 31));
+}
+
+// Encode 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.)
+GPB_INLINE uint64_t GPBEncodeZigZag64(int64_t n) {
+ // Note: the right-shift must be arithmetic
+ return (uint64_t)((n << 1) ^ (n >> 63));
+}
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wswitch-enum"
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+GPB_INLINE BOOL GPBDataTypeIsObject(GPBDataType type) {
+ switch (type) {
+ case GPBDataTypeBytes:
+ case GPBDataTypeString:
+ case GPBDataTypeMessage:
+ case GPBDataTypeGroup:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+GPB_INLINE BOOL GPBDataTypeIsMessage(GPBDataType type) {
+ switch (type) {
+ case GPBDataTypeMessage:
+ case GPBDataTypeGroup:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+GPB_INLINE BOOL GPBFieldDataTypeIsMessage(GPBFieldDescriptor *field) {
+ return GPBDataTypeIsMessage(field->description_->dataType);
+}
+
+GPB_INLINE BOOL GPBFieldDataTypeIsObject(GPBFieldDescriptor *field) {
+ return GPBDataTypeIsObject(field->description_->dataType);
+}
+
+GPB_INLINE BOOL GPBExtensionIsMessage(GPBExtensionDescriptor *ext) {
+ return GPBDataTypeIsMessage(ext->description_->dataType);
+}
+
+// The field is an array/map or it has an object value.
+GPB_INLINE BOOL GPBFieldStoresObject(GPBFieldDescriptor *field) {
+ GPBMessageFieldDescription *desc = field->description_;
+ if ((desc->flags & (GPBFieldRepeated | GPBFieldMapKeyMask)) != 0) {
+ return YES;
+ }
+ return GPBDataTypeIsObject(desc->dataType);
+}
+
+BOOL GPBGetHasIvar(GPBMessage *self, int32_t index, uint32_t fieldNumber);
+void GPBSetHasIvar(GPBMessage *self, int32_t idx, uint32_t fieldNumber,
+ BOOL value);
+uint32_t GPBGetHasOneof(GPBMessage *self, int32_t index);
+
+GPB_INLINE BOOL
+GPBGetHasIvarField(GPBMessage *self, GPBFieldDescriptor *field) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ return GPBGetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number);
+}
+GPB_INLINE void GPBSetHasIvarField(GPBMessage *self, GPBFieldDescriptor *field,
+ BOOL value) {
+ GPBMessageFieldDescription *fieldDesc = field->description_;
+ GPBSetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number, value);
+}
+
+void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof,
+ int32_t oneofHasIndex, uint32_t fieldNumberNotToClear);
+
+#pragma clang diagnostic pop
+
+//%PDDM-DEFINE GPB_IVAR_SET_DECL(NAME, TYPE)
+//%void GPBSet##NAME##IvarWithFieldInternal(GPBMessage *self,
+//% NAME$S GPBFieldDescriptor *field,
+//% NAME$S TYPE value,
+//% NAME$S GPBFileSyntax syntax);
+//%PDDM-EXPAND GPB_IVAR_SET_DECL(Bool, BOOL)
+// This block of code is generated, do not edit it directly.
+
+void GPBSetBoolIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ BOOL value,
+ GPBFileSyntax syntax);
+//%PDDM-EXPAND GPB_IVAR_SET_DECL(Int32, int32_t)
+// This block of code is generated, do not edit it directly.
+
+void GPBSetInt32IvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int32_t value,
+ GPBFileSyntax syntax);
+//%PDDM-EXPAND GPB_IVAR_SET_DECL(UInt32, uint32_t)
+// This block of code is generated, do not edit it directly.
+
+void GPBSetUInt32IvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ uint32_t value,
+ GPBFileSyntax syntax);
+//%PDDM-EXPAND GPB_IVAR_SET_DECL(Int64, int64_t)
+// This block of code is generated, do not edit it directly.
+
+void GPBSetInt64IvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int64_t value,
+ GPBFileSyntax syntax);
+//%PDDM-EXPAND GPB_IVAR_SET_DECL(UInt64, uint64_t)
+// This block of code is generated, do not edit it directly.
+
+void GPBSetUInt64IvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ uint64_t value,
+ GPBFileSyntax syntax);
+//%PDDM-EXPAND GPB_IVAR_SET_DECL(Float, float)
+// This block of code is generated, do not edit it directly.
+
+void GPBSetFloatIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ float value,
+ GPBFileSyntax syntax);
+//%PDDM-EXPAND GPB_IVAR_SET_DECL(Double, double)
+// This block of code is generated, do not edit it directly.
+
+void GPBSetDoubleIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ double value,
+ GPBFileSyntax syntax);
+//%PDDM-EXPAND GPB_IVAR_SET_DECL(Enum, int32_t)
+// This block of code is generated, do not edit it directly.
+
+void GPBSetEnumIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ int32_t value,
+ GPBFileSyntax syntax);
+//%PDDM-EXPAND-END (8 expansions)
+
+int32_t GPBGetEnumIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ GPBFileSyntax syntax);
+
+id GPBGetObjectIvarWithField(GPBMessage *self, GPBFieldDescriptor *field);
+
+void GPBSetObjectIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field, id value,
+ GPBFileSyntax syntax);
+void GPBSetRetainedObjectIvarWithFieldInternal(GPBMessage *self,
+ GPBFieldDescriptor *field,
+ id __attribute__((ns_consumed))
+ value,
+ GPBFileSyntax syntax);
+
+// GPBGetObjectIvarWithField will automatically create the field (message) if
+// it doesn't exist. GPBGetObjectIvarWithFieldNoAutocreate will return nil.
+id GPBGetObjectIvarWithFieldNoAutocreate(GPBMessage *self,
+ GPBFieldDescriptor *field);
+
+void GPBSetAutocreatedRetainedObjectIvarWithField(
+ GPBMessage *self, GPBFieldDescriptor *field,
+ id __attribute__((ns_consumed)) value);
+
+// Clears and releases the autocreated message ivar, if it's autocreated. If
+// it's not set as autocreated, this method does nothing.
+void GPBClearAutocreatedMessageIvarWithField(GPBMessage *self,
+ GPBFieldDescriptor *field);
+
+// Returns an Objective C encoding for |selector|. |instanceSel| should be
+// YES if it's an instance selector (as opposed to a class selector).
+// |selector| must be a selector from MessageSignatureProtocol.
+const char *GPBMessageEncodingForSelector(SEL selector, BOOL instanceSel);
+
+// Helper for text format name encoding.
+// decodeData is the data describing the sepecial decodes.
+// key and inputString are the input that needs decoding.
+NSString *GPBDecodeTextFormatName(const uint8_t *decodeData, int32_t key,
+ NSString *inputString);
+
+// A series of selectors that are used solely to get @encoding values
+// for them by the dynamic protobuf runtime code. See
+// GPBMessageEncodingForSelector for details.
+@protocol GPBMessageSignatureProtocol
+@optional
+
+#define GPB_MESSAGE_SIGNATURE_ENTRY(TYPE, NAME) \
+ -(TYPE)get##NAME; \
+ -(void)set##NAME : (TYPE)value; \
+ -(TYPE)get##NAME##AtIndex : (NSUInteger)index;
+
+GPB_MESSAGE_SIGNATURE_ENTRY(BOOL, Bool)
+GPB_MESSAGE_SIGNATURE_ENTRY(uint32_t, Fixed32)
+GPB_MESSAGE_SIGNATURE_ENTRY(int32_t, SFixed32)
+GPB_MESSAGE_SIGNATURE_ENTRY(float, Float)
+GPB_MESSAGE_SIGNATURE_ENTRY(uint64_t, Fixed64)
+GPB_MESSAGE_SIGNATURE_ENTRY(int64_t, SFixed64)
+GPB_MESSAGE_SIGNATURE_ENTRY(double, Double)
+GPB_MESSAGE_SIGNATURE_ENTRY(int32_t, Int32)
+GPB_MESSAGE_SIGNATURE_ENTRY(int64_t, Int64)
+GPB_MESSAGE_SIGNATURE_ENTRY(int32_t, SInt32)
+GPB_MESSAGE_SIGNATURE_ENTRY(int64_t, SInt64)
+GPB_MESSAGE_SIGNATURE_ENTRY(uint32_t, UInt32)
+GPB_MESSAGE_SIGNATURE_ENTRY(uint64_t, UInt64)
+GPB_MESSAGE_SIGNATURE_ENTRY(NSData *, Bytes)
+GPB_MESSAGE_SIGNATURE_ENTRY(NSString *, String)
+GPB_MESSAGE_SIGNATURE_ENTRY(GPBMessage *, Message)
+GPB_MESSAGE_SIGNATURE_ENTRY(GPBMessage *, Group)
+GPB_MESSAGE_SIGNATURE_ENTRY(int32_t, Enum)
+
+#undef GPB_MESSAGE_SIGNATURE_ENTRY
+
+- (id)getArray;
+- (NSUInteger)getArrayCount;
+- (void)setArray:(NSArray *)array;
++ (id)getClassValue;
+@end
+
+BOOL GPBClassHasSel(Class aClass, SEL sel);
+
+CF_EXTERN_C_END
diff --git a/third_party/protobuf/objectivec/GPBWellKnownTypes.h b/third_party/protobuf/objectivec/GPBWellKnownTypes.h
new file mode 100644
index 0000000000..04df417889
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBWellKnownTypes.h
@@ -0,0 +1,245 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Any.pbobjc.h>
+ #import <Protobuf/Duration.pbobjc.h>
+ #import <Protobuf/Timestamp.pbobjc.h>
+#else
+ #import "google/protobuf/Any.pbobjc.h"
+ #import "google/protobuf/Duration.pbobjc.h"
+ #import "google/protobuf/Timestamp.pbobjc.h"
+#endif
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - Errors
+
+/** NSError domain used for errors. */
+extern NSString *const GPBWellKnownTypesErrorDomain;
+
+/** Error code for NSError with GPBWellKnownTypesErrorDomain. */
+typedef NS_ENUM(NSInteger, GPBWellKnownTypesErrorCode) {
+ /** The type_url could not be computed for the requested GPBMessage class. */
+ GPBWellKnownTypesErrorCodeFailedToComputeTypeURL = -100,
+ /** type_url in a Any doesn’t match that of the requested GPBMessage class. */
+ GPBWellKnownTypesErrorCodeTypeURLMismatch = -101,
+};
+
+#pragma mark - GPBTimestamp
+
+/**
+ * Category for GPBTimestamp to work with standard Foundation time/date types.
+ **/
+@interface GPBTimestamp (GBPWellKnownTypes)
+
+/** The NSDate representation of this GPBTimestamp. */
+@property(nonatomic, readwrite, strong) NSDate *date;
+
+/**
+ * The NSTimeInterval representation of this GPBTimestamp.
+ *
+ * @note: Not all second/nanos combinations can be represented in a
+ * NSTimeInterval, so getting this could be a lossy transform.
+ **/
+@property(nonatomic, readwrite) NSTimeInterval timeIntervalSince1970;
+
+/**
+ * Initializes a GPBTimestamp with the given NSDate.
+ *
+ * @param date The date to configure the GPBTimestamp with.
+ *
+ * @return A newly initialized GPBTimestamp.
+ **/
+- (instancetype)initWithDate:(NSDate *)date;
+
+/**
+ * Initializes a GPBTimestamp with the given NSTimeInterval.
+ *
+ * @param timeIntervalSince1970 Time interval to configure the GPBTimestamp with.
+ *
+ * @return A newly initialized GPBTimestamp.
+ **/
+- (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970;
+
+@end
+
+#pragma mark - GPBDuration
+
+/**
+ * Category for GPBDuration to work with standard Foundation time type.
+ **/
+@interface GPBDuration (GBPWellKnownTypes)
+
+/**
+ * The NSTimeInterval representation of this GPBDuration.
+ *
+ * @note: Not all second/nanos combinations can be represented in a
+ * NSTimeInterval, so getting this could be a lossy transform.
+ **/
+@property(nonatomic, readwrite) NSTimeInterval timeInterval;
+
+/**
+ * Initializes a GPBDuration with the given NSTimeInterval.
+ *
+ * @param timeInterval Time interval to configure the GPBDuration with.
+ *
+ * @return A newly initialized GPBDuration.
+ **/
+- (instancetype)initWithTimeInterval:(NSTimeInterval)timeInterval;
+
+// These next two methods are deprecated because GBPDuration has no need of a
+// "base" time. The older methods were about symmetry with GBPTimestamp, but
+// the unix epoch usage is too confusing.
+
+/** Deprecated, use timeInterval instead. */
+@property(nonatomic, readwrite) NSTimeInterval timeIntervalSince1970
+ __attribute__((deprecated("Use timeInterval")));
+/** Deprecated, use initWithTimeInterval: instead. */
+- (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970
+ __attribute__((deprecated("Use initWithTimeInterval:")));
+
+@end
+
+#pragma mark - GPBAny
+
+/**
+ * Category for GPBAny to help work with the message within the object.
+ **/
+@interface GPBAny (GBPWellKnownTypes)
+
+/**
+ * Convenience method to create a GPBAny containing the serialized message.
+ * This uses type.googleapis.com/ as the type_url's prefix.
+ *
+ * @param message The message to be packed into the GPBAny.
+ * @param errorPtr Pointer to an error that will be populated if something goes
+ * wrong.
+ *
+ * @return A newly configured GPBAny with the given message, or nil on failure.
+ */
++ (nullable instancetype)anyWithMessage:(nonnull GPBMessage *)message
+ error:(NSError **)errorPtr;
+
+/**
+ * Convenience method to create a GPBAny containing the serialized message.
+ *
+ * @param message The message to be packed into the GPBAny.
+ * @param typeURLPrefix The URL prefix to apply for type_url.
+ * @param errorPtr Pointer to an error that will be populated if something
+ * goes wrong.
+ *
+ * @return A newly configured GPBAny with the given message, or nil on failure.
+ */
++ (nullable instancetype)anyWithMessage:(nonnull GPBMessage *)message
+ typeURLPrefix:(nonnull NSString *)typeURLPrefix
+ error:(NSError **)errorPtr;
+
+/**
+ * Initializes a GPBAny to contain the serialized message. This uses
+ * type.googleapis.com/ as the type_url's prefix.
+ *
+ * @param message The message to be packed into the GPBAny.
+ * @param errorPtr Pointer to an error that will be populated if something goes
+ * wrong.
+ *
+ * @return A newly configured GPBAny with the given message, or nil on failure.
+ */
+- (nullable instancetype)initWithMessage:(nonnull GPBMessage *)message
+ error:(NSError **)errorPtr;
+
+/**
+ * Initializes a GPBAny to contain the serialized message.
+ *
+ * @param message The message to be packed into the GPBAny.
+ * @param typeURLPrefix The URL prefix to apply for type_url.
+ * @param errorPtr Pointer to an error that will be populated if something
+ * goes wrong.
+ *
+ * @return A newly configured GPBAny with the given message, or nil on failure.
+ */
+- (nullable instancetype)initWithMessage:(nonnull GPBMessage *)message
+ typeURLPrefix:(nonnull NSString *)typeURLPrefix
+ error:(NSError **)errorPtr;
+
+/**
+ * Packs the serialized message into this GPBAny. This uses
+ * type.googleapis.com/ as the type_url's prefix.
+ *
+ * @param message The message to be packed into the GPBAny.
+ * @param errorPtr Pointer to an error that will be populated if something goes
+ * wrong.
+ *
+ * @return Whether the packing was successful or not.
+ */
+- (BOOL)packWithMessage:(nonnull GPBMessage *)message
+ error:(NSError **)errorPtr;
+
+/**
+ * Packs the serialized message into this GPBAny.
+ *
+ * @param message The message to be packed into the GPBAny.
+ * @param typeURLPrefix The URL prefix to apply for type_url.
+ * @param errorPtr Pointer to an error that will be populated if something
+ * goes wrong.
+ *
+ * @return Whether the packing was successful or not.
+ */
+- (BOOL)packWithMessage:(nonnull GPBMessage *)message
+ typeURLPrefix:(nonnull NSString *)typeURLPrefix
+ error:(NSError **)errorPtr;
+
+/**
+ * Unpacks the serialized message as if it was an instance of the given class.
+ *
+ * @note When checking type_url, the base URL is not checked, only the fully
+ * qualified name.
+ *
+ * @param messageClass The class to use to deserialize the contained message.
+ * @param errorPtr Pointer to an error that will be populated if something
+ * goes wrong.
+ *
+ * @return An instance of the given class populated with the contained data, or
+ * nil on failure.
+ */
+- (nullable GPBMessage *)unpackMessageClass:(Class)messageClass
+ error:(NSError **)errorPtr;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/third_party/protobuf/objectivec/GPBWellKnownTypes.m b/third_party/protobuf/objectivec/GPBWellKnownTypes.m
new file mode 100644
index 0000000000..2808afeb23
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBWellKnownTypes.m
@@ -0,0 +1,272 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+
+// Importing sources here to force the linker to include our category methods in
+// the static library. If these were compiled separately, the category methods
+// below would be stripped by the linker.
+
+#import "GPBWellKnownTypes.h"
+
+#import "GPBUtilities_PackagePrivate.h"
+
+NSString *const GPBWellKnownTypesErrorDomain =
+ GPBNSStringifySymbol(GPBWellKnownTypesErrorDomain);
+
+static NSString *kTypePrefixGoogleApisCom = @"type.googleapis.com/";
+
+static NSTimeInterval TimeIntervalFromSecondsAndNanos(int64_t seconds,
+ int32_t nanos) {
+ return seconds + (NSTimeInterval)nanos / 1e9;
+}
+
+static int32_t SecondsAndNanosFromTimeInterval(NSTimeInterval time,
+ int64_t *outSeconds,
+ BOOL nanosMustBePositive) {
+ NSTimeInterval seconds;
+ NSTimeInterval nanos = modf(time, &seconds);
+
+ if (nanosMustBePositive && (nanos < 0)) {
+ // Per Timestamp.proto, nanos is non-negative and "Negative second values with
+ // fractions must still have non-negative nanos values that count forward in
+ // time. Must be from 0 to 999,999,999 inclusive."
+ --seconds;
+ nanos = 1.0 + nanos;
+ }
+
+ nanos *= 1e9;
+ *outSeconds = (int64_t)seconds;
+ return (int32_t)nanos;
+}
+
+static NSString *BuildTypeURL(NSString *typeURLPrefix, NSString *fullName) {
+ if (typeURLPrefix.length == 0) {
+ return fullName;
+ }
+
+ if ([typeURLPrefix hasSuffix:@"/"]) {
+ return [typeURLPrefix stringByAppendingString:fullName];
+ }
+
+ return [NSString stringWithFormat:@"%@/%@", typeURLPrefix, fullName];
+}
+
+static NSString *ParseTypeFromURL(NSString *typeURLString) {
+ NSRange range = [typeURLString rangeOfString:@"/" options:NSBackwardsSearch];
+ if ((range.location == NSNotFound) ||
+ (NSMaxRange(range) == typeURLString.length)) {
+ return nil;
+ }
+ NSString *result = [typeURLString substringFromIndex:range.location + 1];
+ return result;
+}
+
+#pragma mark - GPBTimestamp
+
+@implementation GPBTimestamp (GBPWellKnownTypes)
+
+- (instancetype)initWithDate:(NSDate *)date {
+ return [self initWithTimeIntervalSince1970:date.timeIntervalSince1970];
+}
+
+- (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970 {
+ if ((self = [super init])) {
+ int64_t seconds;
+ int32_t nanos = SecondsAndNanosFromTimeInterval(
+ timeIntervalSince1970, &seconds, YES);
+ self.seconds = seconds;
+ self.nanos = nanos;
+ }
+ return self;
+}
+
+- (NSDate *)date {
+ return [NSDate dateWithTimeIntervalSince1970:self.timeIntervalSince1970];
+}
+
+- (void)setDate:(NSDate *)date {
+ self.timeIntervalSince1970 = date.timeIntervalSince1970;
+}
+
+- (NSTimeInterval)timeIntervalSince1970 {
+ return TimeIntervalFromSecondsAndNanos(self.seconds, self.nanos);
+}
+
+- (void)setTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970 {
+ int64_t seconds;
+ int32_t nanos =
+ SecondsAndNanosFromTimeInterval(timeIntervalSince1970, &seconds, YES);
+ self.seconds = seconds;
+ self.nanos = nanos;
+}
+
+@end
+
+#pragma mark - GPBDuration
+
+@implementation GPBDuration (GBPWellKnownTypes)
+
+- (instancetype)initWithTimeInterval:(NSTimeInterval)timeInterval {
+ if ((self = [super init])) {
+ int64_t seconds;
+ int32_t nanos = SecondsAndNanosFromTimeInterval(
+ timeInterval, &seconds, NO);
+ self.seconds = seconds;
+ self.nanos = nanos;
+ }
+ return self;
+}
+
+- (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970 {
+ return [self initWithTimeInterval:timeIntervalSince1970];
+}
+
+- (NSTimeInterval)timeInterval {
+ return TimeIntervalFromSecondsAndNanos(self.seconds, self.nanos);
+}
+
+- (void)setTimeInterval:(NSTimeInterval)timeInterval {
+ int64_t seconds;
+ int32_t nanos =
+ SecondsAndNanosFromTimeInterval(timeInterval, &seconds, NO);
+ self.seconds = seconds;
+ self.nanos = nanos;
+}
+
+- (NSTimeInterval)timeIntervalSince1970 {
+ return self.timeInterval;
+}
+
+- (void)setTimeIntervalSince1970:(NSTimeInterval)timeIntervalSince1970 {
+ self.timeInterval = timeIntervalSince1970;
+}
+
+@end
+
+#pragma mark - GPBAny
+
+@implementation GPBAny (GBPWellKnownTypes)
+
++ (instancetype)anyWithMessage:(GPBMessage *)message
+ error:(NSError **)errorPtr {
+ return [self anyWithMessage:message
+ typeURLPrefix:kTypePrefixGoogleApisCom
+ error:errorPtr];
+}
+
++ (instancetype)anyWithMessage:(GPBMessage *)message
+ typeURLPrefix:(NSString *)typeURLPrefix
+ error:(NSError **)errorPtr {
+ return [[[self alloc] initWithMessage:message
+ typeURLPrefix:typeURLPrefix
+ error:errorPtr] autorelease];
+}
+
+- (instancetype)initWithMessage:(GPBMessage *)message
+ error:(NSError **)errorPtr {
+ return [self initWithMessage:message
+ typeURLPrefix:kTypePrefixGoogleApisCom
+ error:errorPtr];
+}
+
+- (instancetype)initWithMessage:(GPBMessage *)message
+ typeURLPrefix:(NSString *)typeURLPrefix
+ error:(NSError **)errorPtr {
+ self = [self init];
+ if (self) {
+ if (![self packWithMessage:message
+ typeURLPrefix:typeURLPrefix
+ error:errorPtr]) {
+ [self release];
+ self = nil;
+ }
+ }
+ return self;
+}
+
+- (BOOL)packWithMessage:(GPBMessage *)message
+ error:(NSError **)errorPtr {
+ return [self packWithMessage:message
+ typeURLPrefix:kTypePrefixGoogleApisCom
+ error:errorPtr];
+}
+
+- (BOOL)packWithMessage:(GPBMessage *)message
+ typeURLPrefix:(NSString *)typeURLPrefix
+ error:(NSError **)errorPtr {
+ NSString *fullName = [message descriptor].fullName;
+ if (fullName.length == 0) {
+ if (errorPtr) {
+ *errorPtr =
+ [NSError errorWithDomain:GPBWellKnownTypesErrorDomain
+ code:GPBWellKnownTypesErrorCodeFailedToComputeTypeURL
+ userInfo:nil];
+ }
+ return NO;
+ }
+ if (errorPtr) {
+ *errorPtr = nil;
+ }
+ self.typeURL = BuildTypeURL(typeURLPrefix, fullName);
+ self.value = message.data;
+ return YES;
+}
+
+- (GPBMessage *)unpackMessageClass:(Class)messageClass
+ error:(NSError **)errorPtr {
+ NSString *fullName = [messageClass descriptor].fullName;
+ if (fullName.length == 0) {
+ if (errorPtr) {
+ *errorPtr =
+ [NSError errorWithDomain:GPBWellKnownTypesErrorDomain
+ code:GPBWellKnownTypesErrorCodeFailedToComputeTypeURL
+ userInfo:nil];
+ }
+ return nil;
+ }
+
+ NSString *expectedFullName = ParseTypeFromURL(self.typeURL);
+ if ((expectedFullName == nil) || ![expectedFullName isEqual:fullName]) {
+ if (errorPtr) {
+ *errorPtr =
+ [NSError errorWithDomain:GPBWellKnownTypesErrorDomain
+ code:GPBWellKnownTypesErrorCodeTypeURLMismatch
+ userInfo:nil];
+ }
+ return nil;
+ }
+
+ // Any is proto3, which means no extensions, so this assumes anything put
+ // within an any also won't need extensions. A second helper could be added
+ // if needed.
+ return [messageClass parseFromData:self.value
+ error:errorPtr];
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/GPBWireFormat.h b/third_party/protobuf/objectivec/GPBWireFormat.h
new file mode 100644
index 0000000000..c5941a3824
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBWireFormat.h
@@ -0,0 +1,73 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBRuntimeTypes.h"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+typedef enum {
+ GPBWireFormatVarint = 0,
+ GPBWireFormatFixed64 = 1,
+ GPBWireFormatLengthDelimited = 2,
+ GPBWireFormatStartGroup = 3,
+ GPBWireFormatEndGroup = 4,
+ GPBWireFormatFixed32 = 5,
+} GPBWireFormat;
+
+enum {
+ GPBWireFormatMessageSetItem = 1,
+ GPBWireFormatMessageSetTypeId = 2,
+ GPBWireFormatMessageSetMessage = 3
+};
+
+uint32_t GPBWireFormatMakeTag(uint32_t fieldNumber, GPBWireFormat wireType)
+ __attribute__((const));
+GPBWireFormat GPBWireFormatGetTagWireType(uint32_t tag) __attribute__((const));
+uint32_t GPBWireFormatGetTagFieldNumber(uint32_t tag) __attribute__((const));
+BOOL GPBWireFormatIsValidTag(uint32_t tag) __attribute__((const));
+
+GPBWireFormat GPBWireFormatForType(GPBDataType dataType, BOOL isPacked)
+ __attribute__((const));
+
+#define GPBWireFormatMessageSetItemTag \
+ (GPBWireFormatMakeTag(GPBWireFormatMessageSetItem, GPBWireFormatStartGroup))
+#define GPBWireFormatMessageSetItemEndTag \
+ (GPBWireFormatMakeTag(GPBWireFormatMessageSetItem, GPBWireFormatEndGroup))
+#define GPBWireFormatMessageSetTypeIdTag \
+ (GPBWireFormatMakeTag(GPBWireFormatMessageSetTypeId, GPBWireFormatVarint))
+#define GPBWireFormatMessageSetMessageTag \
+ (GPBWireFormatMakeTag(GPBWireFormatMessageSetMessage, \
+ GPBWireFormatLengthDelimited))
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
diff --git a/third_party/protobuf/objectivec/GPBWireFormat.m b/third_party/protobuf/objectivec/GPBWireFormat.m
new file mode 100644
index 0000000000..860a339f9a
--- /dev/null
+++ b/third_party/protobuf/objectivec/GPBWireFormat.m
@@ -0,0 +1,85 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBWireFormat.h"
+
+#import "GPBUtilities_PackagePrivate.h"
+
+enum {
+ GPBWireFormatTagTypeBits = 3,
+ GPBWireFormatTagTypeMask = 7 /* = (1 << GPBWireFormatTagTypeBits) - 1 */,
+};
+
+uint32_t GPBWireFormatMakeTag(uint32_t fieldNumber, GPBWireFormat wireType) {
+ return (fieldNumber << GPBWireFormatTagTypeBits) | wireType;
+}
+
+GPBWireFormat GPBWireFormatGetTagWireType(uint32_t tag) {
+ return (GPBWireFormat)(tag & GPBWireFormatTagTypeMask);
+}
+
+uint32_t GPBWireFormatGetTagFieldNumber(uint32_t tag) {
+ return GPBLogicalRightShift32(tag, GPBWireFormatTagTypeBits);
+}
+
+BOOL GPBWireFormatIsValidTag(uint32_t tag) {
+ uint32_t formatBits = (tag & GPBWireFormatTagTypeMask);
+ // The valid GPBWireFormat* values are 0-5, anything else is not a valid tag.
+ BOOL result = (formatBits <= 5);
+ return result;
+}
+
+GPBWireFormat GPBWireFormatForType(GPBDataType type, BOOL isPacked) {
+ if (isPacked) {
+ return GPBWireFormatLengthDelimited;
+ }
+
+ static const GPBWireFormat format[GPBDataType_Count] = {
+ GPBWireFormatVarint, // GPBDataTypeBool
+ GPBWireFormatFixed32, // GPBDataTypeFixed32
+ GPBWireFormatFixed32, // GPBDataTypeSFixed32
+ GPBWireFormatFixed32, // GPBDataTypeFloat
+ GPBWireFormatFixed64, // GPBDataTypeFixed64
+ GPBWireFormatFixed64, // GPBDataTypeSFixed64
+ GPBWireFormatFixed64, // GPBDataTypeDouble
+ GPBWireFormatVarint, // GPBDataTypeInt32
+ GPBWireFormatVarint, // GPBDataTypeInt64
+ GPBWireFormatVarint, // GPBDataTypeSInt32
+ GPBWireFormatVarint, // GPBDataTypeSInt64
+ GPBWireFormatVarint, // GPBDataTypeUInt32
+ GPBWireFormatVarint, // GPBDataTypeUInt64
+ GPBWireFormatLengthDelimited, // GPBDataTypeBytes
+ GPBWireFormatLengthDelimited, // GPBDataTypeString
+ GPBWireFormatLengthDelimited, // GPBDataTypeMessage
+ GPBWireFormatStartGroup, // GPBDataTypeGroup
+ GPBWireFormatVarint // GPBDataTypeEnum
+ };
+ return format[type];
+}
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj
new file mode 100644
index 0000000000..919d007642
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj
@@ -0,0 +1,994 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 47;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 5102DABC1891A073002037B6 /* GPBConcurrencyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5102DABB1891A052002037B6 /* GPBConcurrencyTests.m */; };
+ 7461B5360F94FB4600A0C422 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
+ 7461B53C0F94FB4E00A0C422 /* GPBCodedInputStream.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B48F0F94F99000A0C422 /* GPBCodedInputStream.m */; };
+ 7461B53D0F94FB4E00A0C422 /* GPBCodedOutputStream.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4910F94F99000A0C422 /* GPBCodedOutputStream.m */; };
+ 7461B5490F94FB4E00A0C422 /* GPBExtensionRegistry.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4A90F94F99000A0C422 /* GPBExtensionRegistry.m */; };
+ 7461B54C0F94FB4E00A0C422 /* GPBUnknownField.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4AF0F94F99000A0C422 /* GPBUnknownField.m */; };
+ 7461B5530F94FB4E00A0C422 /* GPBMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4BF0F94F99000A0C422 /* GPBMessage.m */; };
+ 7461B5610F94FB4E00A0C422 /* GPBUnknownFieldSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4E20F94F99000A0C422 /* GPBUnknownFieldSet.m */; };
+ 7461B5630F94FB4E00A0C422 /* GPBUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4E60F94F99000A0C422 /* GPBUtilities.m */; };
+ 7461B5640F94FB4E00A0C422 /* GPBWireFormat.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4E80F94F99000A0C422 /* GPBWireFormat.m */; };
+ 8B210CCE159383D60032D72D /* golden_message in Resources */ = {isa = PBXBuildFile; fileRef = 8B210CCD159383D60032D72D /* golden_message */; };
+ 8B210CD0159386920032D72D /* golden_packed_fields_message in Resources */ = {isa = PBXBuildFile; fileRef = 8B210CCF159386920032D72D /* golden_packed_fields_message */; };
+ 8B4248BB1A8C256A00BC1EC6 /* GPBSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248BA1A8C256A00BC1EC6 /* GPBSwiftTests.swift */; };
+ 8B4248D21A927E1500BC1EC6 /* GPBWellKnownTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248D01A927E1500BC1EC6 /* GPBWellKnownTypes.m */; };
+ 8B4248DC1A92933A00BC1EC6 /* GPBWellKnownTypesTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248DB1A92933A00BC1EC6 /* GPBWellKnownTypesTest.m */; };
+ 8B79657B14992E3F002FFBFC /* GPBRootObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B79657914992E3E002FFBFC /* GPBRootObject.m */; };
+ 8B8B615D17DF7056002EE618 /* GPBARCUnittestProtos.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
+ 8B96157414C8C38C00A2AC0B /* GPBDescriptor.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */; };
+ 8BBEA4A9147C727D00C4ADB7 /* GPBCodedInputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */; };
+ 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOuputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */; };
+ 8BBEA4AC147C727D00C4ADB7 /* GPBMessageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */; };
+ 8BBEA4B0147C727D00C4ADB7 /* GPBTestUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */; };
+ 8BBEA4B6147C727D00C4ADB7 /* GPBUnknownFieldSetTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6B80F94FDF900A0C422 /* GPBUnknownFieldSetTest.m */; };
+ 8BBEA4B7147C727D00C4ADB7 /* GPBUtilitiesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6BA0F94FDF900A0C422 /* GPBUtilitiesTests.m */; };
+ 8BBEA4B8147C727D00C4ADB7 /* GPBWireFormatTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6BC0F94FDF900A0C422 /* GPBWireFormatTests.m */; };
+ 8BBEA4BB147C729200C4ADB7 /* libProtocolBuffers.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */; };
+ 8BD3981F14BE59D70081D629 /* GPBUnittestProtos.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */; };
+ 8BF8193514A0DDA600A2C982 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
+ F401DC2D1A8D444600FCC765 /* GPBArray.m in Sources */ = {isa = PBXBuildFile; fileRef = F401DC2B1A8D444600FCC765 /* GPBArray.m */; };
+ F401DC331A8E5C0200FCC765 /* GPBArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F401DC321A8E5C0200FCC765 /* GPBArrayTests.m */; };
+ F41C175D1833D3310064ED4D /* GPBPerfTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F41C175C1833D3310064ED4D /* GPBPerfTests.m */; };
+ F4353D1D1AB8822D005A6198 /* GPBDescriptorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D1C1AB8822D005A6198 /* GPBDescriptorTests.m */; };
+ F4353D231ABB1537005A6198 /* GPBDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D211ABB1537005A6198 /* GPBDictionary.m */; };
+ F4353D341AC06F10005A6198 /* GPBDictionaryTests+Bool.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D2D1AC06F10005A6198 /* GPBDictionaryTests+Bool.m */; };
+ F4353D351AC06F10005A6198 /* GPBDictionaryTests+Int32.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D2E1AC06F10005A6198 /* GPBDictionaryTests+Int32.m */; };
+ F4353D361AC06F10005A6198 /* GPBDictionaryTests+Int64.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D2F1AC06F10005A6198 /* GPBDictionaryTests+Int64.m */; };
+ F4353D371AC06F10005A6198 /* GPBDictionaryTests+String.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D301AC06F10005A6198 /* GPBDictionaryTests+String.m */; };
+ F4353D381AC06F10005A6198 /* GPBDictionaryTests+UInt32.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D311AC06F10005A6198 /* GPBDictionaryTests+UInt32.m */; };
+ F4353D391AC06F10005A6198 /* GPBDictionaryTests+UInt64.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D321AC06F10005A6198 /* GPBDictionaryTests+UInt64.m */; };
+ F43C88D0191D77FC009E917D /* text_format_unittest_data.txt in Resources */ = {isa = PBXBuildFile; fileRef = F43C88CF191D77FC009E917D /* text_format_unittest_data.txt */; };
+ F4487C4D1A9F8E0200531423 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
+ F4487C521A9F8E4D00531423 /* GPBProtocolBuffers.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */; };
+ F4487C751AADF7F500531423 /* GPBMessageTests+Runtime.m in Sources */ = {isa = PBXBuildFile; fileRef = F4487C741AADF7F500531423 /* GPBMessageTests+Runtime.m */; };
+ F4487C7F1AAF62CD00531423 /* GPBMessageTests+Serialization.m in Sources */ = {isa = PBXBuildFile; fileRef = F4487C7E1AAF62CD00531423 /* GPBMessageTests+Serialization.m */; };
+ F4487C831AAF6AB300531423 /* GPBMessageTests+Merge.m in Sources */ = {isa = PBXBuildFile; fileRef = F4487C821AAF6AB300531423 /* GPBMessageTests+Merge.m */; };
+ F45C69CC16DFD08D0081955B /* GPBExtensionInternals.m in Sources */ = {isa = PBXBuildFile; fileRef = F45C69CB16DFD08D0081955B /* GPBExtensionInternals.m */; };
+ F45E57C71AE6DC6A000B7D99 /* text_format_map_unittest_data.txt in Resources */ = {isa = PBXBuildFile; fileRef = F45E57C61AE6DC6A000B7D99 /* text_format_map_unittest_data.txt */; };
+ F47476E51D21A524007C7B1A /* Duration.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248D41A92826400BC1EC6 /* Duration.pbobjc.m */; };
+ F47476E61D21A524007C7B1A /* Timestamp.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248D61A92826400BC1EC6 /* Timestamp.pbobjc.m */; };
+ F4B51B1E1BBC610700744318 /* GPBObjectiveCPlusPlusTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4B51B1D1BBC610700744318 /* GPBObjectiveCPlusPlusTest.mm */; };
+ F4C4B9E41E1D976300D3B61D /* GPBDictionaryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F4C4B9E21E1D974F00D3B61D /* GPBDictionaryTests.m */; };
+ F4E675971B21D0000054530B /* Any.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675871B21D0000054530B /* Any.pbobjc.m */; };
+ F4E675991B21D0000054530B /* Api.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675891B21D0000054530B /* Api.pbobjc.m */; };
+ F4E6759B1B21D0000054530B /* Empty.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E6758B1B21D0000054530B /* Empty.pbobjc.m */; };
+ F4E6759D1B21D0000054530B /* FieldMask.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E6758D1B21D0000054530B /* FieldMask.pbobjc.m */; };
+ F4E6759F1B21D0000054530B /* SourceContext.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E6758F1B21D0000054530B /* SourceContext.pbobjc.m */; };
+ F4E675A11B21D0000054530B /* Struct.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675911B21D0000054530B /* Struct.pbobjc.m */; };
+ F4E675A31B21D0000054530B /* Type.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675931B21D0000054530B /* Type.pbobjc.m */; };
+ F4E675A51B21D0000054530B /* Wrappers.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675951B21D0000054530B /* Wrappers.pbobjc.m */; };
+ F4F8D8831D789FD9002CE128 /* GPBUnittestProtos2.m in Sources */ = {isa = PBXBuildFile; fileRef = F4F8D8811D789FCE002CE128 /* GPBUnittestProtos2.m */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXContainerItemProxy section */
+ 8BBEA4BC147C729A00C4ADB7 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 7461B52D0F94FAF800A0C422;
+ remoteInfo = ProtocolBuffers;
+ };
+ F45BBC181B0CE3D7002D064D /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = F45BBC141B0CE3C6002D064D;
+ remoteInfo = "Compile Unittest Protos";
+ };
+/* End PBXContainerItemProxy section */
+
+/* Begin PBXFileReference section */
+ 1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+ 5102DABB1891A052002037B6 /* GPBConcurrencyTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GPBConcurrencyTests.m; sourceTree = "<group>"; };
+ 51457B5F18D0B7AF00CCC606 /* GPBCodedInputStream_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBCodedInputStream_PackagePrivate.h; sourceTree = "<group>"; };
+ 515B840C18B7DEE30031753B /* GPBDescriptor_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBDescriptor_PackagePrivate.h; sourceTree = "<group>"; };
+ 5196A06918CE16B000B759E2 /* GPBMessage_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBMessage_PackagePrivate.h; sourceTree = "<group>"; };
+ 7401C1A90F950347006D8281 /* UnitTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "UnitTests-Info.plist"; sourceTree = "<group>"; };
+ 7461B48D0F94F99000A0C422 /* GPBBootstrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBBootstrap.h; sourceTree = "<group>"; };
+ 7461B48E0F94F99000A0C422 /* GPBCodedInputStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBCodedInputStream.h; sourceTree = "<group>"; };
+ 7461B48F0F94F99000A0C422 /* GPBCodedInputStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = GPBCodedInputStream.m; sourceTree = "<group>"; };
+ 7461B4900F94F99000A0C422 /* GPBCodedOutputStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBCodedOutputStream.h; sourceTree = "<group>"; };
+ 7461B4910F94F99000A0C422 /* GPBCodedOutputStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedOutputStream.m; sourceTree = "<group>"; };
+ 7461B4A80F94F99000A0C422 /* GPBExtensionRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBExtensionRegistry.h; sourceTree = "<group>"; };
+ 7461B4A90F94F99000A0C422 /* GPBExtensionRegistry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBExtensionRegistry.m; sourceTree = "<group>"; };
+ 7461B4AE0F94F99000A0C422 /* GPBUnknownField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBUnknownField.h; sourceTree = "<group>"; };
+ 7461B4AF0F94F99000A0C422 /* GPBUnknownField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnknownField.m; sourceTree = "<group>"; };
+ 7461B4BE0F94F99000A0C422 /* GPBMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBMessage.h; sourceTree = "<group>"; };
+ 7461B4BF0F94F99000A0C422 /* GPBMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBMessage.m; sourceTree = "<group>"; };
+ 7461B4CD0F94F99000A0C422 /* GPBProtocolBuffers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBProtocolBuffers.h; sourceTree = "<group>"; };
+ 7461B4E10F94F99000A0C422 /* GPBUnknownFieldSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBUnknownFieldSet.h; sourceTree = "<group>"; };
+ 7461B4E20F94F99000A0C422 /* GPBUnknownFieldSet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnknownFieldSet.m; sourceTree = "<group>"; };
+ 7461B4E50F94F99000A0C422 /* GPBUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBUtilities.h; sourceTree = "<group>"; };
+ 7461B4E60F94F99000A0C422 /* GPBUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUtilities.m; sourceTree = "<group>"; };
+ 7461B4E70F94F99000A0C422 /* GPBWireFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBWireFormat.h; sourceTree = "<group>"; };
+ 7461B4E80F94F99000A0C422 /* GPBWireFormat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWireFormat.m; sourceTree = "<group>"; };
+ 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libProtocolBuffers.a; sourceTree = BUILT_PRODUCTS_DIR; };
+ 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedInputStreamTests.m; sourceTree = "<group>"; };
+ 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedOuputStreamTests.m; sourceTree = "<group>"; };
+ 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBMessageTests.m; sourceTree = "<group>"; };
+ 7461B6AB0F94FDF800A0C422 /* GPBTestUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBTestUtilities.h; sourceTree = "<group>"; };
+ 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBTestUtilities.m; sourceTree = "<group>"; };
+ 7461B6B80F94FDF900A0C422 /* GPBUnknownFieldSetTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnknownFieldSetTest.m; sourceTree = "<group>"; };
+ 7461B6BA0F94FDF900A0C422 /* GPBUtilitiesTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUtilitiesTests.m; sourceTree = "<group>"; };
+ 7461B6BC0F94FDF900A0C422 /* GPBWireFormatTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWireFormatTests.m; sourceTree = "<group>"; };
+ 8B09AAF614B663A7007B4184 /* unittest_objc.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_objc.proto; sourceTree = "<group>"; };
+ 8B210CCD159383D60032D72D /* golden_message */ = {isa = PBXFileReference; lastKnownFileType = file; path = golden_message; sourceTree = "<group>"; };
+ 8B210CCF159386920032D72D /* golden_packed_fields_message */ = {isa = PBXFileReference; lastKnownFileType = file; path = golden_packed_fields_message; sourceTree = "<group>"; };
+ 8B4248B81A8C254000BC1EC6 /* protobuf */ = {isa = PBXFileReference; lastKnownFileType = text; name = protobuf; path = ../../Intermediates/ProtocolBuffers_OSX.build/DerivedSources/protos/google/protobuf; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8B4248B91A8C256900BC1EC6 /* UnitTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UnitTests-Bridging-Header.h"; sourceTree = "<group>"; };
+ 8B4248BA1A8C256A00BC1EC6 /* GPBSwiftTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GPBSwiftTests.swift; sourceTree = "<group>"; };
+ 8B4248CF1A927E1500BC1EC6 /* GPBWellKnownTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBWellKnownTypes.h; sourceTree = "<group>"; };
+ 8B4248D01A927E1500BC1EC6 /* GPBWellKnownTypes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWellKnownTypes.m; sourceTree = "<group>"; };
+ 8B4248D31A92826400BC1EC6 /* Duration.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Duration.pbobjc.h; path = google/protobuf/Duration.pbobjc.h; sourceTree = "<group>"; };
+ 8B4248D41A92826400BC1EC6 /* Duration.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Duration.pbobjc.m; path = google/protobuf/Duration.pbobjc.m; sourceTree = "<group>"; };
+ 8B4248D51A92826400BC1EC6 /* Timestamp.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Timestamp.pbobjc.h; path = google/protobuf/Timestamp.pbobjc.h; sourceTree = "<group>"; };
+ 8B4248D61A92826400BC1EC6 /* Timestamp.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Timestamp.pbobjc.m; path = google/protobuf/Timestamp.pbobjc.m; sourceTree = "<group>"; };
+ 8B4248DB1A92933A00BC1EC6 /* GPBWellKnownTypesTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWellKnownTypesTest.m; sourceTree = "<group>"; };
+ 8B42494C1A92A16600BC1EC6 /* duration.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = duration.proto; path = ../src/google/protobuf/duration.proto; sourceTree = "<group>"; };
+ 8B42494D1A92A16600BC1EC6 /* timestamp.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = timestamp.proto; path = ../src/google/protobuf/timestamp.proto; sourceTree = "<group>"; };
+ 8B79657814992E3E002FFBFC /* GPBRootObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBRootObject.h; sourceTree = "<group>"; };
+ 8B79657914992E3E002FFBFC /* GPBRootObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBRootObject.m; sourceTree = "<group>"; };
+ 8B7E6A7414893DBA00F8884A /* unittest_custom_options.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_custom_options.proto; path = ../../src/google/protobuf/unittest_custom_options.proto; sourceTree = "<group>"; };
+ 8B7E6A7514893DBA00F8884A /* unittest_embed_optimize_for.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_embed_optimize_for.proto; path = ../../src/google/protobuf/unittest_embed_optimize_for.proto; sourceTree = "<group>"; };
+ 8B7E6A7614893DBA00F8884A /* unittest_empty.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_empty.proto; path = ../../src/google/protobuf/unittest_empty.proto; sourceTree = "<group>"; };
+ 8B7E6A7814893DBB00F8884A /* unittest_import.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_import.proto; path = ../../src/google/protobuf/unittest_import.proto; sourceTree = "<group>"; };
+ 8B7E6A7B14893DBC00F8884A /* unittest_mset.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_mset.proto; path = ../../src/google/protobuf/unittest_mset.proto; sourceTree = "<group>"; };
+ 8B7E6A7C14893DBC00F8884A /* unittest_no_generic_services.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_no_generic_services.proto; path = ../../src/google/protobuf/unittest_no_generic_services.proto; sourceTree = "<group>"; };
+ 8B7E6A7D14893DBC00F8884A /* unittest_optimize_for.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_optimize_for.proto; path = ../../src/google/protobuf/unittest_optimize_for.proto; sourceTree = "<group>"; };
+ 8B7E6A7E14893DBC00F8884A /* unittest.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest.proto; path = ../../src/google/protobuf/unittest.proto; sourceTree = "<group>"; };
+ 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBARCUnittestProtos.m; sourceTree = "<group>"; };
+ 8B96157214C8B06000A2AC0B /* GPBDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBDescriptor.h; sourceTree = "<group>"; };
+ 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDescriptor.m; sourceTree = "<group>"; };
+ 8BBD9DB016DD1DC8008E1EC1 /* unittest_lite.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_lite.proto; path = ../../src/google/protobuf/unittest_lite.proto; sourceTree = "<group>"; };
+ 8BBEA4A6147C727100C4ADB7 /* UnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GPBProtocolBuffers.m; sourceTree = "<group>"; };
+ 8BD3981D14BE54220081D629 /* unittest_enormous_descriptor.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_enormous_descriptor.proto; path = ../../src/google/protobuf/unittest_enormous_descriptor.proto; sourceTree = "<group>"; };
+ 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos.m; sourceTree = "<group>"; };
+ 8BEB5AE01498033E0078BF9D /* GPBRuntimeTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBRuntimeTypes.h; sourceTree = "<group>"; };
+ F401DC2A1A8D444600FCC765 /* GPBArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBArray.h; sourceTree = "<group>"; };
+ F401DC2B1A8D444600FCC765 /* GPBArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBArray.m; sourceTree = "<group>"; };
+ F401DC321A8E5C0200FCC765 /* GPBArrayTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBArrayTests.m; sourceTree = "<group>"; };
+ F41C175C1833D3310064ED4D /* GPBPerfTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBPerfTests.m; sourceTree = "<group>"; };
+ F4353D1C1AB8822D005A6198 /* GPBDescriptorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDescriptorTests.m; sourceTree = "<group>"; };
+ F4353D201ABB1537005A6198 /* GPBDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBDictionary.h; sourceTree = "<group>"; };
+ F4353D211ABB1537005A6198 /* GPBDictionary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDictionary.m; sourceTree = "<group>"; };
+ F4353D2C1AC06F10005A6198 /* GPBDictionaryTests.pddm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = GPBDictionaryTests.pddm; sourceTree = "<group>"; };
+ F4353D2D1AC06F10005A6198 /* GPBDictionaryTests+Bool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+Bool.m"; sourceTree = "<group>"; };
+ F4353D2E1AC06F10005A6198 /* GPBDictionaryTests+Int32.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+Int32.m"; sourceTree = "<group>"; };
+ F4353D2F1AC06F10005A6198 /* GPBDictionaryTests+Int64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+Int64.m"; sourceTree = "<group>"; };
+ F4353D301AC06F10005A6198 /* GPBDictionaryTests+String.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+String.m"; sourceTree = "<group>"; };
+ F4353D311AC06F10005A6198 /* GPBDictionaryTests+UInt32.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+UInt32.m"; sourceTree = "<group>"; };
+ F4353D321AC06F10005A6198 /* GPBDictionaryTests+UInt64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+UInt64.m"; sourceTree = "<group>"; };
+ F43725911AC9832D004DCAFB /* GPBDictionary_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBDictionary_PackagePrivate.h; sourceTree = "<group>"; };
+ F43C88CF191D77FC009E917D /* text_format_unittest_data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = text_format_unittest_data.txt; sourceTree = "<group>"; };
+ F4411BE71AF12FD700324B4A /* GPBArray_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBArray_PackagePrivate.h; sourceTree = "<group>"; };
+ F4487C511A9F8E0200531423 /* libTestSingleSourceBuild.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libTestSingleSourceBuild.a; sourceTree = BUILT_PRODUCTS_DIR; };
+ F4487C741AADF7F500531423 /* GPBMessageTests+Runtime.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Runtime.m"; sourceTree = "<group>"; };
+ F4487C781AADFB3100531423 /* unittest_runtime_proto2.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_runtime_proto2.proto; sourceTree = "<group>"; };
+ F4487C791AADFB3200531423 /* unittest_runtime_proto3.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_runtime_proto3.proto; sourceTree = "<group>"; };
+ F4487C7C1AAE06AC00531423 /* GPBUtilities_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBUtilities_PackagePrivate.h; sourceTree = "<group>"; };
+ F4487C7E1AAF62CD00531423 /* GPBMessageTests+Serialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Serialization.m"; sourceTree = "<group>"; };
+ F4487C821AAF6AB300531423 /* GPBMessageTests+Merge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Merge.m"; sourceTree = "<group>"; };
+ F44929001C866B1900C2548A /* GPBCodedOutputStream_PackagePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBCodedOutputStream_PackagePrivate.h; sourceTree = "<group>"; };
+ F451D3F51A8AAE8700B8A22C /* GPBProtocolBuffers_RuntimeSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBProtocolBuffers_RuntimeSupport.h; sourceTree = "<group>"; };
+ F45C69CB16DFD08D0081955B /* GPBExtensionInternals.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBExtensionInternals.m; sourceTree = "<group>"; };
+ F45E57C61AE6DC6A000B7D99 /* text_format_map_unittest_data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = text_format_map_unittest_data.txt; sourceTree = "<group>"; };
+ F4AC9E1D1A8BEB3500BD6E83 /* unittest_cycle.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_cycle.proto; sourceTree = "<group>"; };
+ F4B51B1D1BBC610700744318 /* GPBObjectiveCPlusPlusTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GPBObjectiveCPlusPlusTest.mm; sourceTree = "<group>"; };
+ F4B6B8AF1A9CC98000892426 /* GPBUnknownField_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBUnknownField_PackagePrivate.h; sourceTree = "<group>"; };
+ F4B6B8B21A9CCBDA00892426 /* GPBUnknownFieldSet_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBUnknownFieldSet_PackagePrivate.h; sourceTree = "<group>"; };
+ F4B6B8B61A9CD1DE00892426 /* GPBExtensionInternals.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBExtensionInternals.h; sourceTree = "<group>"; };
+ F4B6B8B81A9CD1DE00892426 /* GPBRootObject_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBRootObject_PackagePrivate.h; sourceTree = "<group>"; };
+ F4C4B9E21E1D974F00D3B61D /* GPBDictionaryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDictionaryTests.m; sourceTree = "<group>"; };
+ F4CF31701B162ED800BD9B06 /* unittest_objc_startup.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_objc_startup.proto; sourceTree = "<group>"; };
+ F4E675861B21D0000054530B /* Any.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Any.pbobjc.h; path = google/protobuf/Any.pbobjc.h; sourceTree = "<group>"; };
+ F4E675871B21D0000054530B /* Any.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Any.pbobjc.m; path = google/protobuf/Any.pbobjc.m; sourceTree = "<group>"; };
+ F4E675881B21D0000054530B /* Api.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Api.pbobjc.h; path = google/protobuf/Api.pbobjc.h; sourceTree = "<group>"; };
+ F4E675891B21D0000054530B /* Api.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Api.pbobjc.m; path = google/protobuf/Api.pbobjc.m; sourceTree = "<group>"; };
+ F4E6758A1B21D0000054530B /* Empty.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Empty.pbobjc.h; path = google/protobuf/Empty.pbobjc.h; sourceTree = "<group>"; };
+ F4E6758B1B21D0000054530B /* Empty.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Empty.pbobjc.m; path = google/protobuf/Empty.pbobjc.m; sourceTree = "<group>"; };
+ F4E6758C1B21D0000054530B /* FieldMask.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FieldMask.pbobjc.h; path = google/protobuf/FieldMask.pbobjc.h; sourceTree = "<group>"; };
+ F4E6758D1B21D0000054530B /* FieldMask.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FieldMask.pbobjc.m; path = google/protobuf/FieldMask.pbobjc.m; sourceTree = "<group>"; };
+ F4E6758E1B21D0000054530B /* SourceContext.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SourceContext.pbobjc.h; path = google/protobuf/SourceContext.pbobjc.h; sourceTree = "<group>"; };
+ F4E6758F1B21D0000054530B /* SourceContext.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SourceContext.pbobjc.m; path = google/protobuf/SourceContext.pbobjc.m; sourceTree = "<group>"; };
+ F4E675901B21D0000054530B /* Struct.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Struct.pbobjc.h; path = google/protobuf/Struct.pbobjc.h; sourceTree = "<group>"; };
+ F4E675911B21D0000054530B /* Struct.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Struct.pbobjc.m; path = google/protobuf/Struct.pbobjc.m; sourceTree = "<group>"; };
+ F4E675921B21D0000054530B /* Type.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Type.pbobjc.h; path = google/protobuf/Type.pbobjc.h; sourceTree = "<group>"; };
+ F4E675931B21D0000054530B /* Type.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Type.pbobjc.m; path = google/protobuf/Type.pbobjc.m; sourceTree = "<group>"; };
+ F4E675941B21D0000054530B /* Wrappers.pbobjc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Wrappers.pbobjc.h; path = google/protobuf/Wrappers.pbobjc.h; sourceTree = "<group>"; };
+ F4E675951B21D0000054530B /* Wrappers.pbobjc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Wrappers.pbobjc.m; path = google/protobuf/Wrappers.pbobjc.m; sourceTree = "<group>"; };
+ F4E675A61B21D05C0054530B /* any.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = any.proto; path = ../src/google/protobuf/any.proto; sourceTree = "<group>"; };
+ F4E675A71B21D05C0054530B /* api.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = api.proto; path = ../src/google/protobuf/api.proto; sourceTree = "<group>"; };
+ F4E675A81B21D05C0054530B /* empty.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = empty.proto; path = ../src/google/protobuf/empty.proto; sourceTree = "<group>"; };
+ F4E675A91B21D05C0054530B /* field_mask.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = field_mask.proto; path = ../src/google/protobuf/field_mask.proto; sourceTree = "<group>"; };
+ F4E675AA1B21D05C0054530B /* source_context.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = source_context.proto; path = ../src/google/protobuf/source_context.proto; sourceTree = "<group>"; };
+ F4E675AB1B21D05C0054530B /* struct.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = struct.proto; path = ../src/google/protobuf/struct.proto; sourceTree = "<group>"; };
+ F4E675AC1B21D05C0054530B /* type.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = type.proto; path = ../src/google/protobuf/type.proto; sourceTree = "<group>"; };
+ F4E675AD1B21D05C0054530B /* wrappers.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = wrappers.proto; path = ../src/google/protobuf/wrappers.proto; sourceTree = "<group>"; };
+ F4F8D8811D789FCE002CE128 /* GPBUnittestProtos2.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos2.m; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 7461B52C0F94FAF800A0C422 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 7461B5360F94FB4600A0C422 /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 8BBEA4A3147C727100C4ADB7 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8BBEA4BB147C729200C4ADB7 /* libProtocolBuffers.a in Frameworks */,
+ 8BF8193514A0DDA600A2C982 /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ F4487C4C1A9F8E0200531423 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ F4487C4D1A9F8E0200531423 /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 080E96DDFE201D6D7F000001 /* Core Source */ = {
+ isa = PBXGroup;
+ children = (
+ 7461B4CD0F94F99000A0C422 /* GPBProtocolBuffers.h */,
+ F451D3F51A8AAE8700B8A22C /* GPBProtocolBuffers_RuntimeSupport.h */,
+ 8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */,
+ 7461B3C50F94F84100A0C422 /* Extensions */,
+ 7461B4850F94F96600A0C422 /* Fields */,
+ 7461B4860F94F96B00A0C422 /* IO */,
+ 7461B5150F94FA7300A0C422 /* Messages */,
+ 8BCF334414ED727300BC5317 /* Support */,
+ 29B97315FDCFA39411CA2CEA /* Generated */,
+ );
+ name = "Core Source";
+ sourceTree = "<group>";
+ };
+ 19C28FACFE9D520D11CA2CBB /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */,
+ 8BBEA4A6147C727100C4ADB7 /* UnitTests.xctest */,
+ F4487C511A9F8E0200531423 /* libTestSingleSourceBuild.a */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
+ isa = PBXGroup;
+ children = (
+ 080E96DDFE201D6D7F000001 /* Core Source */,
+ 7461B6940F94FDDD00A0C422 /* Tests */,
+ 29B97323FDCFA39411CA2CEA /* Frameworks */,
+ 19C28FACFE9D520D11CA2CBB /* Products */,
+ );
+ name = CustomTemplate;
+ sourceTree = "<group>";
+ };
+ 29B97315FDCFA39411CA2CEA /* Generated */ = {
+ isa = PBXGroup;
+ children = (
+ F4E675861B21D0000054530B /* Any.pbobjc.h */,
+ F4E675871B21D0000054530B /* Any.pbobjc.m */,
+ F4E675A61B21D05C0054530B /* any.proto */,
+ F4E675881B21D0000054530B /* Api.pbobjc.h */,
+ F4E675891B21D0000054530B /* Api.pbobjc.m */,
+ F4E675A71B21D05C0054530B /* api.proto */,
+ 8B4248D31A92826400BC1EC6 /* Duration.pbobjc.h */,
+ 8B4248D41A92826400BC1EC6 /* Duration.pbobjc.m */,
+ 8B42494C1A92A16600BC1EC6 /* duration.proto */,
+ F4E6758A1B21D0000054530B /* Empty.pbobjc.h */,
+ F4E6758B1B21D0000054530B /* Empty.pbobjc.m */,
+ F4E675A81B21D05C0054530B /* empty.proto */,
+ F4E675A91B21D05C0054530B /* field_mask.proto */,
+ F4E6758C1B21D0000054530B /* FieldMask.pbobjc.h */,
+ F4E6758D1B21D0000054530B /* FieldMask.pbobjc.m */,
+ F4E675AA1B21D05C0054530B /* source_context.proto */,
+ F4E6758E1B21D0000054530B /* SourceContext.pbobjc.h */,
+ F4E6758F1B21D0000054530B /* SourceContext.pbobjc.m */,
+ F4E675901B21D0000054530B /* Struct.pbobjc.h */,
+ F4E675911B21D0000054530B /* Struct.pbobjc.m */,
+ F4E675AB1B21D05C0054530B /* struct.proto */,
+ 8B4248D51A92826400BC1EC6 /* Timestamp.pbobjc.h */,
+ 8B4248D61A92826400BC1EC6 /* Timestamp.pbobjc.m */,
+ 8B42494D1A92A16600BC1EC6 /* timestamp.proto */,
+ F4E675921B21D0000054530B /* Type.pbobjc.h */,
+ F4E675931B21D0000054530B /* Type.pbobjc.m */,
+ F4E675AC1B21D05C0054530B /* type.proto */,
+ F4E675941B21D0000054530B /* Wrappers.pbobjc.h */,
+ F4E675951B21D0000054530B /* Wrappers.pbobjc.m */,
+ F4E675AD1B21D05C0054530B /* wrappers.proto */,
+ );
+ name = Generated;
+ sourceTree = "<group>";
+ };
+ 29B97323FDCFA39411CA2CEA /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 1D30AB110D05D00D00671497 /* Foundation.framework */,
+ );
+ name = Frameworks;
+ sourceTree = "<group>";
+ };
+ 7461B3C50F94F84100A0C422 /* Extensions */ = {
+ isa = PBXGroup;
+ children = (
+ F4B6B8B61A9CD1DE00892426 /* GPBExtensionInternals.h */,
+ F45C69CB16DFD08D0081955B /* GPBExtensionInternals.m */,
+ 7461B4A80F94F99000A0C422 /* GPBExtensionRegistry.h */,
+ 7461B4A90F94F99000A0C422 /* GPBExtensionRegistry.m */,
+ F4B6B8B81A9CD1DE00892426 /* GPBRootObject_PackagePrivate.h */,
+ 8B79657814992E3E002FFBFC /* GPBRootObject.h */,
+ 8B79657914992E3E002FFBFC /* GPBRootObject.m */,
+ );
+ name = Extensions;
+ sourceTree = "<group>";
+ };
+ 7461B4850F94F96600A0C422 /* Fields */ = {
+ isa = PBXGroup;
+ children = (
+ F4B6B8AF1A9CC98000892426 /* GPBUnknownField_PackagePrivate.h */,
+ 7461B4AE0F94F99000A0C422 /* GPBUnknownField.h */,
+ 7461B4AF0F94F99000A0C422 /* GPBUnknownField.m */,
+ F4B6B8B21A9CCBDA00892426 /* GPBUnknownFieldSet_PackagePrivate.h */,
+ 7461B4E10F94F99000A0C422 /* GPBUnknownFieldSet.h */,
+ 7461B4E20F94F99000A0C422 /* GPBUnknownFieldSet.m */,
+ );
+ name = Fields;
+ sourceTree = "<group>";
+ };
+ 7461B4860F94F96B00A0C422 /* IO */ = {
+ isa = PBXGroup;
+ children = (
+ 51457B5F18D0B7AF00CCC606 /* GPBCodedInputStream_PackagePrivate.h */,
+ 7461B48E0F94F99000A0C422 /* GPBCodedInputStream.h */,
+ 7461B48F0F94F99000A0C422 /* GPBCodedInputStream.m */,
+ F44929001C866B1900C2548A /* GPBCodedOutputStream_PackagePrivate.h */,
+ 7461B4900F94F99000A0C422 /* GPBCodedOutputStream.h */,
+ 7461B4910F94F99000A0C422 /* GPBCodedOutputStream.m */,
+ 7461B4E70F94F99000A0C422 /* GPBWireFormat.h */,
+ 7461B4E80F94F99000A0C422 /* GPBWireFormat.m */,
+ );
+ name = IO;
+ sourceTree = "<group>";
+ };
+ 7461B5150F94FA7300A0C422 /* Messages */ = {
+ isa = PBXGroup;
+ children = (
+ 515B840C18B7DEE30031753B /* GPBDescriptor_PackagePrivate.h */,
+ 8B96157214C8B06000A2AC0B /* GPBDescriptor.h */,
+ 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */,
+ 7461B4BE0F94F99000A0C422 /* GPBMessage.h */,
+ 5196A06918CE16B000B759E2 /* GPBMessage_PackagePrivate.h */,
+ 7461B4BF0F94F99000A0C422 /* GPBMessage.m */,
+ );
+ name = Messages;
+ sourceTree = "<group>";
+ };
+ 7461B6940F94FDDD00A0C422 /* Tests */ = {
+ isa = PBXGroup;
+ children = (
+ 8B4248B81A8C254000BC1EC6 /* protobuf */,
+ 8B210CCD159383D60032D72D /* golden_message */,
+ 8B210CCF159386920032D72D /* golden_packed_fields_message */,
+ 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */,
+ F401DC321A8E5C0200FCC765 /* GPBArrayTests.m */,
+ 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */,
+ 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */,
+ 5102DABB1891A052002037B6 /* GPBConcurrencyTests.m */,
+ F4353D1C1AB8822D005A6198 /* GPBDescriptorTests.m */,
+ F4C4B9E21E1D974F00D3B61D /* GPBDictionaryTests.m */,
+ F4353D2C1AC06F10005A6198 /* GPBDictionaryTests.pddm */,
+ F4353D2D1AC06F10005A6198 /* GPBDictionaryTests+Bool.m */,
+ F4353D2E1AC06F10005A6198 /* GPBDictionaryTests+Int32.m */,
+ F4353D2F1AC06F10005A6198 /* GPBDictionaryTests+Int64.m */,
+ F4353D301AC06F10005A6198 /* GPBDictionaryTests+String.m */,
+ F4353D311AC06F10005A6198 /* GPBDictionaryTests+UInt32.m */,
+ F4353D321AC06F10005A6198 /* GPBDictionaryTests+UInt64.m */,
+ 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */,
+ F4487C821AAF6AB300531423 /* GPBMessageTests+Merge.m */,
+ F4487C741AADF7F500531423 /* GPBMessageTests+Runtime.m */,
+ F4487C7E1AAF62CD00531423 /* GPBMessageTests+Serialization.m */,
+ F4B51B1D1BBC610700744318 /* GPBObjectiveCPlusPlusTest.mm */,
+ F41C175C1833D3310064ED4D /* GPBPerfTests.m */,
+ 8B4248BA1A8C256A00BC1EC6 /* GPBSwiftTests.swift */,
+ 7461B6AB0F94FDF800A0C422 /* GPBTestUtilities.h */,
+ 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */,
+ 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */,
+ F4F8D8811D789FCE002CE128 /* GPBUnittestProtos2.m */,
+ 7461B6B80F94FDF900A0C422 /* GPBUnknownFieldSetTest.m */,
+ 7461B6BA0F94FDF900A0C422 /* GPBUtilitiesTests.m */,
+ 8B4248DB1A92933A00BC1EC6 /* GPBWellKnownTypesTest.m */,
+ 7461B6BC0F94FDF900A0C422 /* GPBWireFormatTests.m */,
+ F43C88CF191D77FC009E917D /* text_format_unittest_data.txt */,
+ F45E57C61AE6DC6A000B7D99 /* text_format_map_unittest_data.txt */,
+ 8B7E6A7414893DBA00F8884A /* unittest_custom_options.proto */,
+ F4AC9E1D1A8BEB3500BD6E83 /* unittest_cycle.proto */,
+ 8B7E6A7514893DBA00F8884A /* unittest_embed_optimize_for.proto */,
+ 8B7E6A7614893DBA00F8884A /* unittest_empty.proto */,
+ 8BD3981D14BE54220081D629 /* unittest_enormous_descriptor.proto */,
+ 8B7E6A7814893DBB00F8884A /* unittest_import.proto */,
+ 8BBD9DB016DD1DC8008E1EC1 /* unittest_lite.proto */,
+ 8B7E6A7B14893DBC00F8884A /* unittest_mset.proto */,
+ 8B7E6A7C14893DBC00F8884A /* unittest_no_generic_services.proto */,
+ 8B09AAF614B663A7007B4184 /* unittest_objc.proto */,
+ F4CF31701B162ED800BD9B06 /* unittest_objc_startup.proto */,
+ 8B7E6A7D14893DBC00F8884A /* unittest_optimize_for.proto */,
+ F4487C781AADFB3100531423 /* unittest_runtime_proto2.proto */,
+ F4487C791AADFB3200531423 /* unittest_runtime_proto3.proto */,
+ 8B7E6A7E14893DBC00F8884A /* unittest.proto */,
+ 8B4248B91A8C256900BC1EC6 /* UnitTests-Bridging-Header.h */,
+ 7401C1A90F950347006D8281 /* UnitTests-Info.plist */,
+ );
+ path = Tests;
+ sourceTree = "<group>";
+ };
+ 8BCF334414ED727300BC5317 /* Support */ = {
+ isa = PBXGroup;
+ children = (
+ F4411BE71AF12FD700324B4A /* GPBArray_PackagePrivate.h */,
+ F401DC2A1A8D444600FCC765 /* GPBArray.h */,
+ F401DC2B1A8D444600FCC765 /* GPBArray.m */,
+ 7461B48D0F94F99000A0C422 /* GPBBootstrap.h */,
+ F43725911AC9832D004DCAFB /* GPBDictionary_PackagePrivate.h */,
+ F4353D201ABB1537005A6198 /* GPBDictionary.h */,
+ F4353D211ABB1537005A6198 /* GPBDictionary.m */,
+ 8BEB5AE01498033E0078BF9D /* GPBRuntimeTypes.h */,
+ F4487C7C1AAE06AC00531423 /* GPBUtilities_PackagePrivate.h */,
+ 7461B4E50F94F99000A0C422 /* GPBUtilities.h */,
+ 7461B4E60F94F99000A0C422 /* GPBUtilities.m */,
+ 8B4248CF1A927E1500BC1EC6 /* GPBWellKnownTypes.h */,
+ 8B4248D01A927E1500BC1EC6 /* GPBWellKnownTypes.m */,
+ );
+ name = Support;
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXHeadersBuildPhase section */
+ 7461B52A0F94FAF800A0C422 /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ F4487C391A9F8E0200531423 /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXHeadersBuildPhase section */
+
+/* Begin PBXLegacyTarget section */
+ F45BBC141B0CE3C6002D064D /* Compile Unittest Protos */ = {
+ isa = PBXLegacyTarget;
+ buildArgumentsString = "$(ACTION)";
+ buildConfigurationList = F45BBC171B0CE3C6002D064D /* Build configuration list for PBXLegacyTarget "Compile Unittest Protos" */;
+ buildPhases = (
+ );
+ buildToolPath = DevTools/compile_testing_protos.sh;
+ dependencies = (
+ );
+ name = "Compile Unittest Protos";
+ passBuildSettingsInEnvironment = 1;
+ productName = "Compile Unittest Protos";
+ };
+/* End PBXLegacyTarget section */
+
+/* Begin PBXNativeTarget section */
+ 7461B52D0F94FAF800A0C422 /* ProtocolBuffers */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 7461B5330F94FAFD00A0C422 /* Build configuration list for PBXNativeTarget "ProtocolBuffers" */;
+ buildPhases = (
+ 7461B52A0F94FAF800A0C422 /* Headers */,
+ 7461B52B0F94FAF800A0C422 /* Sources */,
+ 7461B52C0F94FAF800A0C422 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = ProtocolBuffers;
+ productName = "ProtocolBuffers-iPhoneDevice";
+ productReference = 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */;
+ productType = "com.apple.product-type.library.static";
+ };
+ 8BBEA4A5147C727100C4ADB7 /* UnitTests */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 8BBEA4BA147C728600C4ADB7 /* Build configuration list for PBXNativeTarget "UnitTests" */;
+ buildPhases = (
+ F4B62A781AF91F6000AFCEDC /* Script: Check Runtime Stamps */,
+ 8BBEA4A1147C727100C4ADB7 /* Resources */,
+ 8BBEA4A2147C727100C4ADB7 /* Sources */,
+ 8BBEA4A3147C727100C4ADB7 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ 8BBEA4BD147C729A00C4ADB7 /* PBXTargetDependency */,
+ F45BBC191B0CE3D7002D064D /* PBXTargetDependency */,
+ );
+ name = UnitTests;
+ productName = UnitTests;
+ productReference = 8BBEA4A6147C727100C4ADB7 /* UnitTests.xctest */;
+ productType = "com.apple.product-type.bundle.unit-test";
+ };
+ F4487C381A9F8E0200531423 /* TestSingleSourceBuild */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = F4487C4E1A9F8E0200531423 /* Build configuration list for PBXNativeTarget "TestSingleSourceBuild" */;
+ buildPhases = (
+ F4487C391A9F8E0200531423 /* Headers */,
+ F4487C3D1A9F8E0200531423 /* Sources */,
+ F4487C4C1A9F8E0200531423 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = TestSingleSourceBuild;
+ productName = "ProtocolBuffers-iPhoneDevice";
+ productReference = F4487C511A9F8E0200531423 /* libTestSingleSourceBuild.a */;
+ productType = "com.apple.product-type.library.static";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 29B97313FDCFA39411CA2CEA /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastSwiftUpdateCheck = 0710;
+ LastTestingUpgradeCheck = 0600;
+ LastUpgradeCheck = 0800;
+ TargetAttributes = {
+ 8BBEA4A5147C727100C4ADB7 = {
+ LastSwiftMigration = 0800;
+ TestTargetID = 8B9A5EA41831993600A9D33B;
+ };
+ F45BBC141B0CE3C6002D064D = {
+ CreatedOnToolsVersion = 6.3.2;
+ };
+ };
+ };
+ buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ProtocolBuffers_OSX" */;
+ compatibilityVersion = "Xcode 6.3";
+ developmentRegion = English;
+ hasScannedForEncodings = 1;
+ knownRegions = (
+ en,
+ );
+ mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 7461B52D0F94FAF800A0C422 /* ProtocolBuffers */,
+ 8BBEA4A5147C727100C4ADB7 /* UnitTests */,
+ F4487C381A9F8E0200531423 /* TestSingleSourceBuild */,
+ F45BBC141B0CE3C6002D064D /* Compile Unittest Protos */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ 8BBEA4A1147C727100C4ADB7 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8B210CCE159383D60032D72D /* golden_message in Resources */,
+ F43C88D0191D77FC009E917D /* text_format_unittest_data.txt in Resources */,
+ 8B210CD0159386920032D72D /* golden_packed_fields_message in Resources */,
+ F45E57C71AE6DC6A000B7D99 /* text_format_map_unittest_data.txt in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXShellScriptBuildPhase section */
+ F4B62A781AF91F6000AFCEDC /* Script: Check Runtime Stamps */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputPaths = (
+ );
+ name = "Script: Check Runtime Stamps";
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "set -eu\nexec \"${SOURCE_ROOT}/DevTools/check_version_stamps.sh\"\n";
+ showEnvVarsInLog = 0;
+ };
+/* End PBXShellScriptBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 7461B52B0F94FAF800A0C422 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 7461B53C0F94FB4E00A0C422 /* GPBCodedInputStream.m in Sources */,
+ F4E6759B1B21D0000054530B /* Empty.pbobjc.m in Sources */,
+ 7461B53D0F94FB4E00A0C422 /* GPBCodedOutputStream.m in Sources */,
+ F401DC2D1A8D444600FCC765 /* GPBArray.m in Sources */,
+ 7461B5490F94FB4E00A0C422 /* GPBExtensionRegistry.m in Sources */,
+ F4E6759D1B21D0000054530B /* FieldMask.pbobjc.m in Sources */,
+ 7461B54C0F94FB4E00A0C422 /* GPBUnknownField.m in Sources */,
+ 7461B5530F94FB4E00A0C422 /* GPBMessage.m in Sources */,
+ F47476E51D21A524007C7B1A /* Duration.pbobjc.m in Sources */,
+ 7461B5610F94FB4E00A0C422 /* GPBUnknownFieldSet.m in Sources */,
+ 7461B5630F94FB4E00A0C422 /* GPBUtilities.m in Sources */,
+ 7461B5640F94FB4E00A0C422 /* GPBWireFormat.m in Sources */,
+ F4E675991B21D0000054530B /* Api.pbobjc.m in Sources */,
+ F4E6759F1B21D0000054530B /* SourceContext.pbobjc.m in Sources */,
+ F4353D231ABB1537005A6198 /* GPBDictionary.m in Sources */,
+ 8B79657B14992E3F002FFBFC /* GPBRootObject.m in Sources */,
+ 8B96157414C8C38C00A2AC0B /* GPBDescriptor.m in Sources */,
+ F4E675971B21D0000054530B /* Any.pbobjc.m in Sources */,
+ F45C69CC16DFD08D0081955B /* GPBExtensionInternals.m in Sources */,
+ 8B4248D21A927E1500BC1EC6 /* GPBWellKnownTypes.m in Sources */,
+ F4E675A31B21D0000054530B /* Type.pbobjc.m in Sources */,
+ F4E675A11B21D0000054530B /* Struct.pbobjc.m in Sources */,
+ F4E675A51B21D0000054530B /* Wrappers.pbobjc.m in Sources */,
+ F47476E61D21A524007C7B1A /* Timestamp.pbobjc.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 8BBEA4A2147C727100C4ADB7 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8BBEA4A9147C727D00C4ADB7 /* GPBCodedInputStreamTests.m in Sources */,
+ F401DC331A8E5C0200FCC765 /* GPBArrayTests.m in Sources */,
+ F4353D361AC06F10005A6198 /* GPBDictionaryTests+Int64.m in Sources */,
+ F4353D391AC06F10005A6198 /* GPBDictionaryTests+UInt64.m in Sources */,
+ 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOuputStreamTests.m in Sources */,
+ 8BBEA4AC147C727D00C4ADB7 /* GPBMessageTests.m in Sources */,
+ F4B51B1E1BBC610700744318 /* GPBObjectiveCPlusPlusTest.mm in Sources */,
+ F4487C7F1AAF62CD00531423 /* GPBMessageTests+Serialization.m in Sources */,
+ 8B4248DC1A92933A00BC1EC6 /* GPBWellKnownTypesTest.m in Sources */,
+ F4F8D8831D789FD9002CE128 /* GPBUnittestProtos2.m in Sources */,
+ F4353D1D1AB8822D005A6198 /* GPBDescriptorTests.m in Sources */,
+ 8B4248BB1A8C256A00BC1EC6 /* GPBSwiftTests.swift in Sources */,
+ 5102DABC1891A073002037B6 /* GPBConcurrencyTests.m in Sources */,
+ F4487C751AADF7F500531423 /* GPBMessageTests+Runtime.m in Sources */,
+ F4353D351AC06F10005A6198 /* GPBDictionaryTests+Int32.m in Sources */,
+ 8BBEA4B0147C727D00C4ADB7 /* GPBTestUtilities.m in Sources */,
+ F41C175D1833D3310064ED4D /* GPBPerfTests.m in Sources */,
+ F4353D341AC06F10005A6198 /* GPBDictionaryTests+Bool.m in Sources */,
+ F4487C831AAF6AB300531423 /* GPBMessageTests+Merge.m in Sources */,
+ 8BBEA4B6147C727D00C4ADB7 /* GPBUnknownFieldSetTest.m in Sources */,
+ F4353D371AC06F10005A6198 /* GPBDictionaryTests+String.m in Sources */,
+ F4353D381AC06F10005A6198 /* GPBDictionaryTests+UInt32.m in Sources */,
+ 8BBEA4B7147C727D00C4ADB7 /* GPBUtilitiesTests.m in Sources */,
+ F4C4B9E41E1D976300D3B61D /* GPBDictionaryTests.m in Sources */,
+ 8BBEA4B8147C727D00C4ADB7 /* GPBWireFormatTests.m in Sources */,
+ 8BD3981F14BE59D70081D629 /* GPBUnittestProtos.m in Sources */,
+ 8B8B615D17DF7056002EE618 /* GPBARCUnittestProtos.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ F4487C3D1A9F8E0200531423 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ F4487C521A9F8E4D00531423 /* GPBProtocolBuffers.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXTargetDependency section */
+ 8BBEA4BD147C729A00C4ADB7 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 7461B52D0F94FAF800A0C422 /* ProtocolBuffers */;
+ targetProxy = 8BBEA4BC147C729A00C4ADB7 /* PBXContainerItemProxy */;
+ };
+ F45BBC191B0CE3D7002D064D /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = F45BBC141B0CE3C6002D064D /* Compile Unittest Protos */;
+ targetProxy = F45BBC181B0CE3D7002D064D /* PBXContainerItemProxy */;
+ };
+/* End PBXTargetDependency section */
+
+/* Begin XCBuildConfiguration section */
+ 7461B52F0F94FAFA00A0C422 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COMBINE_HIDPI_IMAGES = YES;
+ HEADER_SEARCH_PATHS = "$(SRCROOT)";
+ PRODUCT_NAME = ProtocolBuffers;
+ };
+ name = Debug;
+ };
+ 7461B5300F94FAFA00A0C422 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COMBINE_HIDPI_IMAGES = YES;
+ HEADER_SEARCH_PATHS = "$(SRCROOT)";
+ PRODUCT_NAME = ProtocolBuffers;
+ };
+ name = Release;
+ };
+ 8BBEA4A7147C727100C4ADB7 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CLANG_ENABLE_MODULES = YES;
+ COMBINE_HIDPI_IMAGES = YES;
+ HEADER_SEARCH_PATHS = (
+ "${PROJECT_DERIVED_FILE_DIR}/protos",
+ "$(SRCROOT)",
+ );
+ INFOPLIST_FILE = "Tests/UnitTests-Info.plist";
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
+ OTHER_LDFLAGS = "-ObjC";
+ PRODUCT_BUNDLE_IDENTIFIER = "com.yourcompany.${PRODUCT_NAME:identifier}";
+ PRODUCT_NAME = UnitTests;
+ SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h";
+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+ SWIFT_VERSION = 3.0;
+ WARNING_CFLAGS = (
+ "$(inherited)",
+ "-Wno-documentation-unknown-command",
+ "-Wno-reserved-id-macro",
+ "-Wno-direct-ivar-access",
+ );
+ };
+ name = Debug;
+ };
+ 8BBEA4A8147C727100C4ADB7 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CLANG_ENABLE_MODULES = YES;
+ COMBINE_HIDPI_IMAGES = YES;
+ HEADER_SEARCH_PATHS = (
+ "${PROJECT_DERIVED_FILE_DIR}/protos",
+ "$(SRCROOT)",
+ );
+ INFOPLIST_FILE = "Tests/UnitTests-Info.plist";
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
+ OTHER_LDFLAGS = "-ObjC";
+ PRODUCT_BUNDLE_IDENTIFIER = "com.yourcompany.${PRODUCT_NAME:identifier}";
+ PRODUCT_NAME = UnitTests;
+ SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h";
+ SWIFT_VERSION = 3.0;
+ WARNING_CFLAGS = (
+ "$(inherited)",
+ "-Wno-documentation-unknown-command",
+ "-Wno-reserved-id-macro",
+ "-Wno-direct-ivar-access",
+ );
+ };
+ name = Release;
+ };
+ C01FCF4F08A954540054247B /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = YES;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
+ CLANG_STATIC_ANALYZER_MODE = deep;
+ CLANG_WARN_ASSIGN_ENUM = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES;
+ CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES;
+ CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_TESTABILITY = YES;
+ GCC_C_LANGUAGE_STANDARD = c99;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
+ GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
+ GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES;
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
+ GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES;
+ GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
+ GCC_WARN_MISSING_PARENTHESES = YES;
+ GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
+ GCC_WARN_SHADOW = YES;
+ GCC_WARN_SIGN_COMPARE = YES;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNKNOWN_PRAGMAS = YES;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_LABEL = YES;
+ GCC_WARN_UNUSED_PARAMETER = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ GENERATE_PROFILING_CODE = NO;
+ MACOSX_DEPLOYMENT_TARGET = 10.9;
+ ONLY_ACTIVE_ARCH = YES;
+ RUN_CLANG_STATIC_ANALYZER = YES;
+ SDKROOT = macosx;
+ WARNING_CFLAGS = (
+ "-Wdocumentation-unknown-command",
+ "-Wundef",
+ "-Wreserved-id-macro",
+ "-Wswitch-enum",
+ "-Wdirect-ivar-access",
+ "-Woverriding-method-mismatch",
+ );
+ };
+ name = Debug;
+ };
+ C01FCF5008A954540054247B /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = YES;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
+ CLANG_STATIC_ANALYZER_MODE = deep;
+ CLANG_WARN_ASSIGN_ENUM = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES;
+ CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES;
+ CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ ENABLE_NS_ASSERTIONS = NO;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ GCC_C_LANGUAGE_STANDARD = c99;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
+ GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES;
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
+ GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES;
+ GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
+ GCC_WARN_MISSING_PARENTHESES = YES;
+ GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
+ GCC_WARN_SHADOW = YES;
+ GCC_WARN_SIGN_COMPARE = YES;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNKNOWN_PRAGMAS = YES;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_LABEL = YES;
+ GCC_WARN_UNUSED_PARAMETER = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ GENERATE_PROFILING_CODE = NO;
+ MACOSX_DEPLOYMENT_TARGET = 10.9;
+ RUN_CLANG_STATIC_ANALYZER = YES;
+ SDKROOT = macosx;
+ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
+ WARNING_CFLAGS = (
+ "-Wdocumentation-unknown-command",
+ "-Wundef",
+ "-Wreserved-id-macro",
+ "-Wswitch-enum",
+ "-Wdirect-ivar-access",
+ "-Woverriding-method-mismatch",
+ );
+ };
+ name = Release;
+ };
+ F4487C4F1A9F8E0200531423 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COMBINE_HIDPI_IMAGES = YES;
+ HEADER_SEARCH_PATHS = "$(SRCROOT)";
+ PRODUCT_NAME = TestSingleSourceBuild;
+ };
+ name = Debug;
+ };
+ F4487C501A9F8E0200531423 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ COMBINE_HIDPI_IMAGES = YES;
+ HEADER_SEARCH_PATHS = "$(SRCROOT)";
+ PRODUCT_NAME = TestSingleSourceBuild;
+ };
+ name = Release;
+ };
+ F45BBC151B0CE3C6002D064D /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ };
+ name = Debug;
+ };
+ F45BBC161B0CE3C6002D064D /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 7461B5330F94FAFD00A0C422 /* Build configuration list for PBXNativeTarget "ProtocolBuffers" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 7461B52F0F94FAFA00A0C422 /* Debug */,
+ 7461B5300F94FAFA00A0C422 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 8BBEA4BA147C728600C4ADB7 /* Build configuration list for PBXNativeTarget "UnitTests" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 8BBEA4A7147C727100C4ADB7 /* Debug */,
+ 8BBEA4A8147C727100C4ADB7 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ProtocolBuffers_OSX" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ C01FCF4F08A954540054247B /* Debug */,
+ C01FCF5008A954540054247B /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ F4487C4E1A9F8E0200531423 /* Build configuration list for PBXNativeTarget "TestSingleSourceBuild" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ F4487C4F1A9F8E0200531423 /* Debug */,
+ F4487C501A9F8E0200531423 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ F45BBC171B0CE3C6002D064D /* Build configuration list for PBXLegacyTarget "Compile Unittest Protos" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ F45BBC151B0CE3C6002D064D /* Debug */,
+ F45BBC161B0CE3C6002D064D /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
+}
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/contents.xcworkspacedata
new file mode 100644
index 0000000000..888be4da13
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+ version = "1.0">
+ <FileRef
+ location = "self:ProtocolBuffers_OSX.xcodeproj">
+ </FileRef>
+</Workspace>
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
new file mode 100644
index 0000000000..08de0be8d3
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>
+ <false/>
+</dict>
+</plist>
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme
new file mode 100644
index 0000000000..2f6181316a
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme
@@ -0,0 +1,335 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ LastUpgradeVersion = "0800"
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "YES">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ buildConfiguration = "Release"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES">
+ <Testables>
+ <TestableReference
+ skipped = "NO">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8BBEA4A5147C727100C4ADB7"
+ BuildableName = "UnitTests.xctest"
+ BlueprintName = "UnitTests"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ <SkippedTests>
+ <Test
+ Identifier = "CodedInputStreamTests">
+ </Test>
+ <Test
+ Identifier = "CodedOutputStreamTests">
+ </Test>
+ <Test
+ Identifier = "ConcurrencyTests">
+ </Test>
+ <Test
+ Identifier = "DescriptorTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolBoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolDoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolFloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolUInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolUInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBridgeTests">
+ </Test>
+ <Test
+ Identifier = "GPBDoubleArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBEnumArrayCustomTests">
+ </Test>
+ <Test
+ Identifier = "GPBEnumArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBFloatArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32ArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32BoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32DoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32EnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32EnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32FloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32Int32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32Int64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32ObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32UInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32UInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64ArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64BoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64DoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64EnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64EnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64FloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64Int32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64Int64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64ObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64UInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64UInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBObjectiveCPlusPlusTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringBoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringDoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringEnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringEnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringFloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringUInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringUInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBTestCase">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32ArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32BoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32DoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32EnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32EnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32FloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32Int32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32Int64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32ObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32UInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32UInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64ArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64BoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64DoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64EnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64EnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64FloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64Int32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64Int64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64ObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64UInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64UInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "MessageMergeTests">
+ </Test>
+ <Test
+ Identifier = "MessageRuntimeTests">
+ </Test>
+ <Test
+ Identifier = "MessageSerializationTests">
+ </Test>
+ <Test
+ Identifier = "MessageTests">
+ </Test>
+ <Test
+ Identifier = "UnknownFieldSetTest">
+ </Test>
+ <Test
+ Identifier = "UtilitiesTests">
+ </Test>
+ <Test
+ Identifier = "WellKnownTypesTest">
+ </Test>
+ <Test
+ Identifier = "WireFormatTests">
+ </Test>
+ </SkippedTests>
+ </TestableReference>
+ </Testables>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </TestAction>
+ <LaunchAction
+ buildConfiguration = "Release"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ debugServiceExtension = "internal"
+ allowLocationSimulation = "YES">
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ buildConfiguration = "Release"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ debugDocumentVersioning = "YES">
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Release">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme
new file mode 100644
index 0000000000..b1243b79b2
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_OSX.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ LastUpgradeVersion = "0800"
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "NO">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "NO"
+ buildForArchiving = "NO"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4487C381A9F8E0200531423"
+ BuildableName = "libTestSingleSourceBuild.a"
+ BlueprintName = "TestSingleSourceBuild"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "NO"
+ buildForProfiling = "NO"
+ buildForArchiving = "NO"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8BBEA4A5147C727100C4ADB7"
+ BuildableName = "UnitTests.xctest"
+ BlueprintName = "UnitTests"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ codeCoverageEnabled = "YES">
+ <Testables>
+ <TestableReference
+ skipped = "NO">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8BBEA4A5147C727100C4ADB7"
+ BuildableName = "UnitTests.xctest"
+ BlueprintName = "UnitTests"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ <SkippedTests>
+ <Test
+ Identifier = "PerfTests">
+ </Test>
+ </SkippedTests>
+ </TestableReference>
+ </Testables>
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </TestAction>
+ <LaunchAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ debugServiceExtension = "internal"
+ allowLocationSimulation = "YES">
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ buildConfiguration = "Release"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ debugDocumentVersioning = "YES">
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_OSX.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Debug">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj
new file mode 100644
index 0000000000..64fc45c0e2
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj
@@ -0,0 +1,1167 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 47;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 5102DABC1891A073002037B6 /* GPBConcurrencyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5102DABB1891A052002037B6 /* GPBConcurrencyTests.m */; };
+ 7461B5360F94FB4600A0C422 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
+ 7461B53C0F94FB4E00A0C422 /* GPBCodedInputStream.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B48F0F94F99000A0C422 /* GPBCodedInputStream.m */; };
+ 7461B53D0F94FB4E00A0C422 /* GPBCodedOutputStream.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4910F94F99000A0C422 /* GPBCodedOutputStream.m */; };
+ 7461B5490F94FB4E00A0C422 /* GPBExtensionRegistry.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4A90F94F99000A0C422 /* GPBExtensionRegistry.m */; };
+ 7461B54C0F94FB4E00A0C422 /* GPBUnknownField.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4AF0F94F99000A0C422 /* GPBUnknownField.m */; };
+ 7461B5530F94FB4E00A0C422 /* GPBMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4BF0F94F99000A0C422 /* GPBMessage.m */; };
+ 7461B5610F94FB4E00A0C422 /* GPBUnknownFieldSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4E20F94F99000A0C422 /* GPBUnknownFieldSet.m */; };
+ 7461B5630F94FB4E00A0C422 /* GPBUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4E60F94F99000A0C422 /* GPBUtilities.m */; };
+ 7461B5640F94FB4E00A0C422 /* GPBWireFormat.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B4E80F94F99000A0C422 /* GPBWireFormat.m */; };
+ 8B210CCE159383D60032D72D /* golden_message in Resources */ = {isa = PBXBuildFile; fileRef = 8B210CCD159383D60032D72D /* golden_message */; };
+ 8B210CD0159386920032D72D /* golden_packed_fields_message in Resources */ = {isa = PBXBuildFile; fileRef = 8B210CCF159386920032D72D /* golden_packed_fields_message */; };
+ 8B4248B41A8BD96E00BC1EC6 /* GPBSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248B31A8BD96E00BC1EC6 /* GPBSwiftTests.swift */; };
+ 8B4248E41A929C8900BC1EC6 /* GPBWellKnownTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248E21A929C8900BC1EC6 /* GPBWellKnownTypes.m */; };
+ 8B4248E61A929C9900BC1EC6 /* GPBWellKnownTypesTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248E51A929C9900BC1EC6 /* GPBWellKnownTypesTest.m */; };
+ 8B79657B14992E3F002FFBFC /* GPBRootObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B79657914992E3E002FFBFC /* GPBRootObject.m */; };
+ 8B8B615D17DF7056002EE618 /* GPBARCUnittestProtos.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; };
+ 8B96157414C8C38C00A2AC0B /* GPBDescriptor.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */; };
+ 8B9742331A89D19F00DCE92C /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8B9742321A89D19F00DCE92C /* LaunchScreen.xib */; };
+ 8B9742431A8AAA7800DCE92C /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9742421A8AAA7800DCE92C /* CoreGraphics.framework */; };
+ 8B9A5EA61831993600A9D33B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
+ 8B9A5EA81831993600A9D33B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9A5E9F1831913D00A9D33B /* UIKit.framework */; };
+ 8B9A5EAE1831993600A9D33B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8B9A5EAC1831993600A9D33B /* InfoPlist.strings */; };
+ 8B9A5EB41831993600A9D33B /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B9A5EB31831993600A9D33B /* AppDelegate.m */; };
+ 8B9A5EB61831993600A9D33B /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8B9A5EB51831993600A9D33B /* Images.xcassets */; };
+ 8B9A5EEC18330A0F00A9D33B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8B9A5E9F1831913D00A9D33B /* UIKit.framework */; };
+ 8BBEA4A9147C727D00C4ADB7 /* GPBCodedInputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */; };
+ 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOuputStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */; };
+ 8BBEA4AC147C727D00C4ADB7 /* GPBMessageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */; };
+ 8BBEA4B0147C727D00C4ADB7 /* GPBTestUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */; };
+ 8BBEA4B6147C727D00C4ADB7 /* GPBUnknownFieldSetTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6B80F94FDF900A0C422 /* GPBUnknownFieldSetTest.m */; };
+ 8BBEA4B7147C727D00C4ADB7 /* GPBUtilitiesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6BA0F94FDF900A0C422 /* GPBUtilitiesTests.m */; };
+ 8BBEA4B8147C727D00C4ADB7 /* GPBWireFormatTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7461B6BC0F94FDF900A0C422 /* GPBWireFormatTests.m */; };
+ 8BBEA4BB147C729200C4ADB7 /* libProtocolBuffers.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */; };
+ 8BD3981F14BE59D70081D629 /* GPBUnittestProtos.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */; };
+ 8BF8193514A0DDA600A2C982 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
+ F401DC351A8E5C6F00FCC765 /* GPBArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F401DC341A8E5C6F00FCC765 /* GPBArrayTests.m */; };
+ F41C175D1833D3310064ED4D /* GPBPerfTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F41C175C1833D3310064ED4D /* GPBPerfTests.m */; };
+ F4353D1F1AB88243005A6198 /* GPBDescriptorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D1E1AB88243005A6198 /* GPBDescriptorTests.m */; };
+ F4353D271ABB156F005A6198 /* GPBDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D251ABB156F005A6198 /* GPBDictionary.m */; };
+ F4353D421AC06F31005A6198 /* GPBDictionaryTests+Bool.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D3B1AC06F31005A6198 /* GPBDictionaryTests+Bool.m */; };
+ F4353D431AC06F31005A6198 /* GPBDictionaryTests+Int32.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D3C1AC06F31005A6198 /* GPBDictionaryTests+Int32.m */; };
+ F4353D441AC06F31005A6198 /* GPBDictionaryTests+Int64.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D3D1AC06F31005A6198 /* GPBDictionaryTests+Int64.m */; };
+ F4353D451AC06F31005A6198 /* GPBDictionaryTests+String.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D3E1AC06F31005A6198 /* GPBDictionaryTests+String.m */; };
+ F4353D461AC06F31005A6198 /* GPBDictionaryTests+UInt32.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D3F1AC06F31005A6198 /* GPBDictionaryTests+UInt32.m */; };
+ F4353D471AC06F31005A6198 /* GPBDictionaryTests+UInt64.m in Sources */ = {isa = PBXBuildFile; fileRef = F4353D401AC06F31005A6198 /* GPBDictionaryTests+UInt64.m */; };
+ F43C88D0191D77FC009E917D /* text_format_unittest_data.txt in Resources */ = {isa = PBXBuildFile; fileRef = F43C88CF191D77FC009E917D /* text_format_unittest_data.txt */; };
+ F4487C6A1A9F8F8100531423 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; };
+ F4487C6F1A9F8FFF00531423 /* GPBProtocolBuffers.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */; };
+ F4487C731A9F906200531423 /* GPBArray.m in Sources */ = {isa = PBXBuildFile; fileRef = F4487C711A9F906200531423 /* GPBArray.m */; };
+ F4487C771AADF84900531423 /* GPBMessageTests+Runtime.m in Sources */ = {isa = PBXBuildFile; fileRef = F4487C761AADF84900531423 /* GPBMessageTests+Runtime.m */; };
+ F4487C811AAF62FC00531423 /* GPBMessageTests+Serialization.m in Sources */ = {isa = PBXBuildFile; fileRef = F4487C801AAF62FC00531423 /* GPBMessageTests+Serialization.m */; };
+ F4487C851AAF6AC500531423 /* GPBMessageTests+Merge.m in Sources */ = {isa = PBXBuildFile; fileRef = F4487C841AAF6AC500531423 /* GPBMessageTests+Merge.m */; };
+ F45C69CC16DFD08D0081955B /* GPBExtensionInternals.m in Sources */ = {isa = PBXBuildFile; fileRef = F45C69CB16DFD08D0081955B /* GPBExtensionInternals.m */; };
+ F45E57C91AE6DC98000B7D99 /* text_format_map_unittest_data.txt in Resources */ = {isa = PBXBuildFile; fileRef = F45E57C81AE6DC98000B7D99 /* text_format_map_unittest_data.txt */; };
+ F47476E91D21A537007C7B1A /* Duration.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248DE1A929C7D00BC1EC6 /* Duration.pbobjc.m */; };
+ F47476EA1D21A537007C7B1A /* Timestamp.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B4248E01A929C7D00BC1EC6 /* Timestamp.pbobjc.m */; };
+ F4B51B1C1BBC5C7100744318 /* GPBObjectiveCPlusPlusTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4B51B1B1BBC5C7100744318 /* GPBObjectiveCPlusPlusTest.mm */; };
+ F4C4B9E71E1D97BF00D3B61D /* GPBDictionaryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F4C4B9E51E1D97BB00D3B61D /* GPBDictionaryTests.m */; };
+ F4E675D01B21D1620054530B /* Any.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675B71B21D1440054530B /* Any.pbobjc.m */; };
+ F4E675D11B21D1620054530B /* Api.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675B91B21D1440054530B /* Api.pbobjc.m */; };
+ F4E675D21B21D1620054530B /* Empty.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675BC1B21D1440054530B /* Empty.pbobjc.m */; };
+ F4E675D31B21D1620054530B /* FieldMask.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675BE1B21D1440054530B /* FieldMask.pbobjc.m */; };
+ F4E675D41B21D1620054530B /* SourceContext.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675C01B21D1440054530B /* SourceContext.pbobjc.m */; };
+ F4E675D51B21D1620054530B /* Struct.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675C21B21D1440054530B /* Struct.pbobjc.m */; };
+ F4E675D61B21D1620054530B /* Type.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675C51B21D1440054530B /* Type.pbobjc.m */; };
+ F4E675D71B21D1620054530B /* Wrappers.pbobjc.m in Sources */ = {isa = PBXBuildFile; fileRef = F4E675C71B21D1440054530B /* Wrappers.pbobjc.m */; };
+ F4F8D8861D78A193002CE128 /* GPBUnittestProtos2.m in Sources */ = {isa = PBXBuildFile; fileRef = F4F8D8841D78A186002CE128 /* GPBUnittestProtos2.m */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXContainerItemProxy section */
+ 8B9A5ED01831994600A9D33B /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 8B9A5EA41831993600A9D33B;
+ remoteInfo = iOSTestHarness;
+ };
+ 8BBEA4BC147C729A00C4ADB7 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 7461B52D0F94FAF800A0C422;
+ remoteInfo = ProtocolBuffers;
+ };
+ F45BBC121B0CDBBA002D064D /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 29B97313FDCFA39411CA2CEA /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = F45BBC0E1B0CDB50002D064D;
+ remoteInfo = "Compile Unittest Protos";
+ };
+/* End PBXContainerItemProxy section */
+
+/* Begin PBXFileReference section */
+ 1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+ 5102DABB1891A052002037B6 /* GPBConcurrencyTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GPBConcurrencyTests.m; sourceTree = "<group>"; };
+ 51457B5F18D0B7AF00CCC606 /* GPBCodedInputStream_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBCodedInputStream_PackagePrivate.h; sourceTree = "<group>"; };
+ 515B840C18B7DEE30031753B /* GPBDescriptor_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBDescriptor_PackagePrivate.h; sourceTree = "<group>"; };
+ 5196A06918CE16B000B759E2 /* GPBMessage_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBMessage_PackagePrivate.h; sourceTree = "<group>"; };
+ 7401C1A90F950347006D8281 /* UnitTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "UnitTests-Info.plist"; sourceTree = "<group>"; };
+ 7461B48D0F94F99000A0C422 /* GPBBootstrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBBootstrap.h; sourceTree = "<group>"; };
+ 7461B48E0F94F99000A0C422 /* GPBCodedInputStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBCodedInputStream.h; sourceTree = "<group>"; };
+ 7461B48F0F94F99000A0C422 /* GPBCodedInputStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = GPBCodedInputStream.m; sourceTree = "<group>"; };
+ 7461B4900F94F99000A0C422 /* GPBCodedOutputStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBCodedOutputStream.h; sourceTree = "<group>"; };
+ 7461B4910F94F99000A0C422 /* GPBCodedOutputStream.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedOutputStream.m; sourceTree = "<group>"; };
+ 7461B4A80F94F99000A0C422 /* GPBExtensionRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBExtensionRegistry.h; sourceTree = "<group>"; };
+ 7461B4A90F94F99000A0C422 /* GPBExtensionRegistry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBExtensionRegistry.m; sourceTree = "<group>"; };
+ 7461B4AE0F94F99000A0C422 /* GPBUnknownField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBUnknownField.h; sourceTree = "<group>"; };
+ 7461B4AF0F94F99000A0C422 /* GPBUnknownField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnknownField.m; sourceTree = "<group>"; };
+ 7461B4BE0F94F99000A0C422 /* GPBMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBMessage.h; sourceTree = "<group>"; };
+ 7461B4BF0F94F99000A0C422 /* GPBMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBMessage.m; sourceTree = "<group>"; };
+ 7461B4CD0F94F99000A0C422 /* GPBProtocolBuffers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBProtocolBuffers.h; sourceTree = "<group>"; };
+ 7461B4E10F94F99000A0C422 /* GPBUnknownFieldSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBUnknownFieldSet.h; sourceTree = "<group>"; };
+ 7461B4E20F94F99000A0C422 /* GPBUnknownFieldSet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnknownFieldSet.m; sourceTree = "<group>"; };
+ 7461B4E50F94F99000A0C422 /* GPBUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBUtilities.h; sourceTree = "<group>"; };
+ 7461B4E60F94F99000A0C422 /* GPBUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUtilities.m; sourceTree = "<group>"; };
+ 7461B4E70F94F99000A0C422 /* GPBWireFormat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBWireFormat.h; sourceTree = "<group>"; };
+ 7461B4E80F94F99000A0C422 /* GPBWireFormat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWireFormat.m; sourceTree = "<group>"; };
+ 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libProtocolBuffers.a; sourceTree = BUILT_PRODUCTS_DIR; };
+ 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedInputStreamTests.m; sourceTree = "<group>"; };
+ 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBCodedOuputStreamTests.m; sourceTree = "<group>"; };
+ 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBMessageTests.m; sourceTree = "<group>"; };
+ 7461B6AB0F94FDF800A0C422 /* GPBTestUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBTestUtilities.h; sourceTree = "<group>"; };
+ 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBTestUtilities.m; sourceTree = "<group>"; };
+ 7461B6B80F94FDF900A0C422 /* GPBUnknownFieldSetTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnknownFieldSetTest.m; sourceTree = "<group>"; };
+ 7461B6BA0F94FDF900A0C422 /* GPBUtilitiesTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUtilitiesTests.m; sourceTree = "<group>"; };
+ 7461B6BC0F94FDF900A0C422 /* GPBWireFormatTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWireFormatTests.m; sourceTree = "<group>"; };
+ 8B09AAF614B663A7007B4184 /* unittest_objc.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_objc.proto; sourceTree = "<group>"; };
+ 8B210CCD159383D60032D72D /* golden_message */ = {isa = PBXFileReference; lastKnownFileType = file; path = golden_message; sourceTree = "<group>"; };
+ 8B210CCF159386920032D72D /* golden_packed_fields_message */ = {isa = PBXFileReference; lastKnownFileType = file; path = golden_packed_fields_message; sourceTree = "<group>"; };
+ 8B4248B21A8BD96D00BC1EC6 /* UnitTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UnitTests-Bridging-Header.h"; sourceTree = "<group>"; };
+ 8B4248B31A8BD96E00BC1EC6 /* GPBSwiftTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GPBSwiftTests.swift; sourceTree = "<group>"; };
+ 8B4248B71A8BDD9600BC1EC6 /* protobuf */ = {isa = PBXFileReference; lastKnownFileType = text; name = protobuf; path = ../../Intermediates/ProtocolBuffers_iOS.build/DerivedSources/protos/google/protobuf; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8B4248DD1A929C7D00BC1EC6 /* Duration.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Duration.pbobjc.h; path = google/protobuf/Duration.pbobjc.h; sourceTree = "<group>"; };
+ 8B4248DE1A929C7D00BC1EC6 /* Duration.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Duration.pbobjc.m; path = google/protobuf/Duration.pbobjc.m; sourceTree = "<group>"; };
+ 8B4248E01A929C7D00BC1EC6 /* Timestamp.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Timestamp.pbobjc.m; path = google/protobuf/Timestamp.pbobjc.m; sourceTree = "<group>"; };
+ 8B4248E11A929C8900BC1EC6 /* GPBWellKnownTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBWellKnownTypes.h; sourceTree = "<group>"; };
+ 8B4248E21A929C8900BC1EC6 /* GPBWellKnownTypes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWellKnownTypes.m; sourceTree = "<group>"; };
+ 8B4248E51A929C9900BC1EC6 /* GPBWellKnownTypesTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBWellKnownTypesTest.m; sourceTree = "<group>"; };
+ 8B4249481A92A02300BC1EC6 /* timestamp.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = timestamp.proto; path = ../src/google/protobuf/timestamp.proto; sourceTree = "<group>"; };
+ 8B42494A1A92A0BA00BC1EC6 /* duration.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = duration.proto; path = ../src/google/protobuf/duration.proto; sourceTree = "<group>"; };
+ 8B79657814992E3E002FFBFC /* GPBRootObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBRootObject.h; sourceTree = "<group>"; };
+ 8B79657914992E3E002FFBFC /* GPBRootObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBRootObject.m; sourceTree = "<group>"; };
+ 8B7E6A7414893DBA00F8884A /* unittest_custom_options.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_custom_options.proto; path = ../../src/google/protobuf/unittest_custom_options.proto; sourceTree = "<group>"; };
+ 8B7E6A7514893DBA00F8884A /* unittest_embed_optimize_for.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_embed_optimize_for.proto; path = ../../src/google/protobuf/unittest_embed_optimize_for.proto; sourceTree = "<group>"; };
+ 8B7E6A7614893DBA00F8884A /* unittest_empty.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_empty.proto; path = ../../src/google/protobuf/unittest_empty.proto; sourceTree = "<group>"; };
+ 8B7E6A7814893DBB00F8884A /* unittest_import.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_import.proto; path = ../../src/google/protobuf/unittest_import.proto; sourceTree = "<group>"; };
+ 8B7E6A7B14893DBC00F8884A /* unittest_mset.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_mset.proto; path = ../../src/google/protobuf/unittest_mset.proto; sourceTree = "<group>"; };
+ 8B7E6A7C14893DBC00F8884A /* unittest_no_generic_services.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_no_generic_services.proto; path = ../../src/google/protobuf/unittest_no_generic_services.proto; sourceTree = "<group>"; };
+ 8B7E6A7D14893DBC00F8884A /* unittest_optimize_for.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_optimize_for.proto; path = ../../src/google/protobuf/unittest_optimize_for.proto; sourceTree = "<group>"; };
+ 8B7E6A7E14893DBC00F8884A /* unittest.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest.proto; path = ../../src/google/protobuf/unittest.proto; sourceTree = "<group>"; };
+ 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBARCUnittestProtos.m; sourceTree = "<group>"; };
+ 8B96157214C8B06000A2AC0B /* GPBDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBDescriptor.h; sourceTree = "<group>"; };
+ 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDescriptor.m; sourceTree = "<group>"; };
+ 8B9742321A89D19F00DCE92C /* LaunchScreen.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = LaunchScreen.xib; sourceTree = "<group>"; };
+ 8B9742421A8AAA7800DCE92C /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
+ 8B9A5E9F1831913D00A9D33B /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
+ 8B9A5EA51831993600A9D33B /* iOSTestHarness.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iOSTestHarness.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8B9A5EAB1831993600A9D33B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
+ 8B9A5EAD1831993600A9D33B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
+ 8B9A5EB31831993600A9D33B /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
+ 8B9A5EB51831993600A9D33B /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
+ 8BBD9DB016DD1DC8008E1EC1 /* unittest_lite.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_lite.proto; path = ../../src/google/protobuf/unittest_lite.proto; sourceTree = "<group>"; };
+ 8BBEA4A6147C727100C4ADB7 /* UnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
+ 8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GPBProtocolBuffers.m; sourceTree = "<group>"; };
+ 8BD3981D14BE54220081D629 /* unittest_enormous_descriptor.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = unittest_enormous_descriptor.proto; path = ../../src/google/protobuf/unittest_enormous_descriptor.proto; sourceTree = "<group>"; };
+ 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos.m; sourceTree = "<group>"; };
+ 8BEB5AE01498033E0078BF9D /* GPBRuntimeTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBRuntimeTypes.h; sourceTree = "<group>"; };
+ F401DC341A8E5C6F00FCC765 /* GPBArrayTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBArrayTests.m; sourceTree = "<group>"; };
+ F41C175C1833D3310064ED4D /* GPBPerfTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBPerfTests.m; sourceTree = "<group>"; };
+ F4353D1E1AB88243005A6198 /* GPBDescriptorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDescriptorTests.m; sourceTree = "<group>"; };
+ F4353D241ABB156F005A6198 /* GPBDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBDictionary.h; sourceTree = "<group>"; };
+ F4353D251ABB156F005A6198 /* GPBDictionary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDictionary.m; sourceTree = "<group>"; };
+ F4353D3A1AC06F31005A6198 /* GPBDictionaryTests.pddm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = GPBDictionaryTests.pddm; sourceTree = "<group>"; };
+ F4353D3B1AC06F31005A6198 /* GPBDictionaryTests+Bool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+Bool.m"; sourceTree = "<group>"; };
+ F4353D3C1AC06F31005A6198 /* GPBDictionaryTests+Int32.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+Int32.m"; sourceTree = "<group>"; };
+ F4353D3D1AC06F31005A6198 /* GPBDictionaryTests+Int64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+Int64.m"; sourceTree = "<group>"; };
+ F4353D3E1AC06F31005A6198 /* GPBDictionaryTests+String.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+String.m"; sourceTree = "<group>"; };
+ F4353D3F1AC06F31005A6198 /* GPBDictionaryTests+UInt32.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+UInt32.m"; sourceTree = "<group>"; };
+ F4353D401AC06F31005A6198 /* GPBDictionaryTests+UInt64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBDictionaryTests+UInt64.m"; sourceTree = "<group>"; };
+ F43725921AC9835D004DCAFB /* GPBDictionary_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBDictionary_PackagePrivate.h; sourceTree = "<group>"; };
+ F43C88CF191D77FC009E917D /* text_format_unittest_data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = text_format_unittest_data.txt; sourceTree = "<group>"; };
+ F4411BE81AF1301700324B4A /* GPBArray_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBArray_PackagePrivate.h; sourceTree = "<group>"; };
+ F4487C6E1A9F8F8100531423 /* libTestSingleSourceBuild.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libTestSingleSourceBuild.a; sourceTree = BUILT_PRODUCTS_DIR; };
+ F4487C701A9F906200531423 /* GPBArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBArray.h; sourceTree = "<group>"; };
+ F4487C711A9F906200531423 /* GPBArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBArray.m; sourceTree = "<group>"; };
+ F4487C761AADF84900531423 /* GPBMessageTests+Runtime.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Runtime.m"; sourceTree = "<group>"; };
+ F4487C7A1AADFB5500531423 /* unittest_runtime_proto2.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_runtime_proto2.proto; sourceTree = "<group>"; };
+ F4487C7B1AADFB5500531423 /* unittest_runtime_proto3.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_runtime_proto3.proto; sourceTree = "<group>"; };
+ F4487C7D1AAE06C500531423 /* GPBUtilities_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBUtilities_PackagePrivate.h; sourceTree = "<group>"; };
+ F4487C801AAF62FC00531423 /* GPBMessageTests+Serialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Serialization.m"; sourceTree = "<group>"; };
+ F4487C841AAF6AC500531423 /* GPBMessageTests+Merge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPBMessageTests+Merge.m"; sourceTree = "<group>"; };
+ F44929021C866B3B00C2548A /* GPBCodedOutputStream_PackagePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPBCodedOutputStream_PackagePrivate.h; sourceTree = "<group>"; };
+ F451D3F61A8AAEA600B8A22C /* GPBProtocolBuffers_RuntimeSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBProtocolBuffers_RuntimeSupport.h; sourceTree = "<group>"; };
+ F45C69CB16DFD08D0081955B /* GPBExtensionInternals.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBExtensionInternals.m; sourceTree = "<group>"; };
+ F45E57C81AE6DC98000B7D99 /* text_format_map_unittest_data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = text_format_map_unittest_data.txt; sourceTree = "<group>"; };
+ F4AC9E1C1A8BEB1000BD6E83 /* unittest_cycle.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_cycle.proto; sourceTree = "<group>"; };
+ F4B51B1B1BBC5C7100744318 /* GPBObjectiveCPlusPlusTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GPBObjectiveCPlusPlusTest.mm; sourceTree = "<group>"; };
+ F4B6B8B01A9CC99500892426 /* GPBUnknownField_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBUnknownField_PackagePrivate.h; sourceTree = "<group>"; };
+ F4B6B8B11A9CCBBB00892426 /* GPBUnknownFieldSet_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBUnknownFieldSet_PackagePrivate.h; sourceTree = "<group>"; };
+ F4B6B8B31A9CD1C600892426 /* GPBExtensionInternals.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBExtensionInternals.h; sourceTree = "<group>"; };
+ F4B6B8B51A9CD1C600892426 /* GPBRootObject_PackagePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPBRootObject_PackagePrivate.h; sourceTree = "<group>"; };
+ F4C4B9E51E1D97BB00D3B61D /* GPBDictionaryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBDictionaryTests.m; sourceTree = "<group>"; };
+ F4CF31711B162EF500BD9B06 /* unittest_objc_startup.proto */ = {isa = PBXFileReference; lastKnownFileType = text; path = unittest_objc_startup.proto; sourceTree = "<group>"; };
+ F4E675B61B21D1440054530B /* Any.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Any.pbobjc.h; path = google/protobuf/Any.pbobjc.h; sourceTree = "<group>"; };
+ F4E675B71B21D1440054530B /* Any.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Any.pbobjc.m; path = google/protobuf/Any.pbobjc.m; sourceTree = "<group>"; };
+ F4E675B81B21D1440054530B /* Api.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Api.pbobjc.h; path = google/protobuf/Api.pbobjc.h; sourceTree = "<group>"; };
+ F4E675B91B21D1440054530B /* Api.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Api.pbobjc.m; path = google/protobuf/Api.pbobjc.m; sourceTree = "<group>"; };
+ F4E675BB1B21D1440054530B /* Empty.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Empty.pbobjc.h; path = google/protobuf/Empty.pbobjc.h; sourceTree = "<group>"; };
+ F4E675BC1B21D1440054530B /* Empty.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Empty.pbobjc.m; path = google/protobuf/Empty.pbobjc.m; sourceTree = "<group>"; };
+ F4E675BD1B21D1440054530B /* FieldMask.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = FieldMask.pbobjc.h; path = google/protobuf/FieldMask.pbobjc.h; sourceTree = "<group>"; };
+ F4E675BE1B21D1440054530B /* FieldMask.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = FieldMask.pbobjc.m; path = google/protobuf/FieldMask.pbobjc.m; sourceTree = "<group>"; };
+ F4E675BF1B21D1440054530B /* SourceContext.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SourceContext.pbobjc.h; path = google/protobuf/SourceContext.pbobjc.h; sourceTree = "<group>"; };
+ F4E675C01B21D1440054530B /* SourceContext.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SourceContext.pbobjc.m; path = google/protobuf/SourceContext.pbobjc.m; sourceTree = "<group>"; };
+ F4E675C11B21D1440054530B /* Struct.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Struct.pbobjc.h; path = google/protobuf/Struct.pbobjc.h; sourceTree = "<group>"; };
+ F4E675C21B21D1440054530B /* Struct.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Struct.pbobjc.m; path = google/protobuf/Struct.pbobjc.m; sourceTree = "<group>"; };
+ F4E675C31B21D1440054530B /* Timestamp.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Timestamp.pbobjc.h; path = google/protobuf/Timestamp.pbobjc.h; sourceTree = "<group>"; };
+ F4E675C41B21D1440054530B /* Type.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Type.pbobjc.h; path = google/protobuf/Type.pbobjc.h; sourceTree = "<group>"; };
+ F4E675C51B21D1440054530B /* Type.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Type.pbobjc.m; path = google/protobuf/Type.pbobjc.m; sourceTree = "<group>"; };
+ F4E675C61B21D1440054530B /* Wrappers.pbobjc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Wrappers.pbobjc.h; path = google/protobuf/Wrappers.pbobjc.h; sourceTree = "<group>"; };
+ F4E675C71B21D1440054530B /* Wrappers.pbobjc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = Wrappers.pbobjc.m; path = google/protobuf/Wrappers.pbobjc.m; sourceTree = "<group>"; };
+ F4E675D81B21D1DE0054530B /* any.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = any.proto; path = ../src/google/protobuf/any.proto; sourceTree = "<group>"; };
+ F4E675D91B21D1DE0054530B /* api.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = api.proto; path = ../src/google/protobuf/api.proto; sourceTree = "<group>"; };
+ F4E675DA1B21D1DE0054530B /* empty.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = empty.proto; path = ../src/google/protobuf/empty.proto; sourceTree = "<group>"; };
+ F4E675DB1B21D1DE0054530B /* field_mask.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = field_mask.proto; path = ../src/google/protobuf/field_mask.proto; sourceTree = "<group>"; };
+ F4E675DC1B21D1DE0054530B /* source_context.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = source_context.proto; path = ../src/google/protobuf/source_context.proto; sourceTree = "<group>"; };
+ F4E675DD1B21D1DE0054530B /* struct.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = struct.proto; path = ../src/google/protobuf/struct.proto; sourceTree = "<group>"; };
+ F4E675DE1B21D1DE0054530B /* type.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = type.proto; path = ../src/google/protobuf/type.proto; sourceTree = "<group>"; };
+ F4E675DF1B21D1DE0054530B /* wrappers.proto */ = {isa = PBXFileReference; lastKnownFileType = text; name = wrappers.proto; path = ../src/google/protobuf/wrappers.proto; sourceTree = "<group>"; };
+ F4F8D8841D78A186002CE128 /* GPBUnittestProtos2.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPBUnittestProtos2.m; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 7461B52C0F94FAF800A0C422 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 7461B5360F94FB4600A0C422 /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 8B9A5EA21831993600A9D33B /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8B9742431A8AAA7800DCE92C /* CoreGraphics.framework in Frameworks */,
+ 8B9A5EA81831993600A9D33B /* UIKit.framework in Frameworks */,
+ 8B9A5EA61831993600A9D33B /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 8BBEA4A3147C727100C4ADB7 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8BBEA4BB147C729200C4ADB7 /* libProtocolBuffers.a in Frameworks */,
+ 8B9A5EEC18330A0F00A9D33B /* UIKit.framework in Frameworks */,
+ 8BF8193514A0DDA600A2C982 /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ F4487C691A9F8F8100531423 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ F4487C6A1A9F8F8100531423 /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 080E96DDFE201D6D7F000001 /* Core Source */ = {
+ isa = PBXGroup;
+ children = (
+ 7461B4CD0F94F99000A0C422 /* GPBProtocolBuffers.h */,
+ F451D3F61A8AAEA600B8A22C /* GPBProtocolBuffers_RuntimeSupport.h */,
+ 8BCF338814ED799900BC5317 /* GPBProtocolBuffers.m */,
+ 7461B3C50F94F84100A0C422 /* Extensions */,
+ 7461B4850F94F96600A0C422 /* Fields */,
+ 7461B4860F94F96B00A0C422 /* IO */,
+ 7461B5150F94FA7300A0C422 /* Messages */,
+ 8BCF334414ED727300BC5317 /* Support */,
+ 29B97315FDCFA39411CA2CEA /* Generated */,
+ );
+ name = "Core Source";
+ sourceTree = "<group>";
+ };
+ 19C28FACFE9D520D11CA2CBB /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */,
+ 8BBEA4A6147C727100C4ADB7 /* UnitTests.xctest */,
+ 8B9A5EA51831993600A9D33B /* iOSTestHarness.app */,
+ F4487C6E1A9F8F8100531423 /* libTestSingleSourceBuild.a */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
+ isa = PBXGroup;
+ children = (
+ 080E96DDFE201D6D7F000001 /* Core Source */,
+ 7461B6940F94FDDD00A0C422 /* Tests */,
+ 29B97323FDCFA39411CA2CEA /* Frameworks */,
+ 19C28FACFE9D520D11CA2CBB /* Products */,
+ );
+ name = CustomTemplate;
+ sourceTree = "<group>";
+ };
+ 29B97315FDCFA39411CA2CEA /* Generated */ = {
+ isa = PBXGroup;
+ children = (
+ F4E675B61B21D1440054530B /* Any.pbobjc.h */,
+ F4E675B71B21D1440054530B /* Any.pbobjc.m */,
+ F4E675D81B21D1DE0054530B /* any.proto */,
+ F4E675B81B21D1440054530B /* Api.pbobjc.h */,
+ F4E675B91B21D1440054530B /* Api.pbobjc.m */,
+ F4E675D91B21D1DE0054530B /* api.proto */,
+ 8B4248DD1A929C7D00BC1EC6 /* Duration.pbobjc.h */,
+ 8B4248DE1A929C7D00BC1EC6 /* Duration.pbobjc.m */,
+ 8B42494A1A92A0BA00BC1EC6 /* duration.proto */,
+ F4E675BB1B21D1440054530B /* Empty.pbobjc.h */,
+ F4E675BC1B21D1440054530B /* Empty.pbobjc.m */,
+ F4E675DA1B21D1DE0054530B /* empty.proto */,
+ F4E675DB1B21D1DE0054530B /* field_mask.proto */,
+ F4E675BD1B21D1440054530B /* FieldMask.pbobjc.h */,
+ F4E675BE1B21D1440054530B /* FieldMask.pbobjc.m */,
+ F4E675DC1B21D1DE0054530B /* source_context.proto */,
+ F4E675BF1B21D1440054530B /* SourceContext.pbobjc.h */,
+ F4E675C01B21D1440054530B /* SourceContext.pbobjc.m */,
+ F4E675C11B21D1440054530B /* Struct.pbobjc.h */,
+ F4E675C21B21D1440054530B /* Struct.pbobjc.m */,
+ F4E675DD1B21D1DE0054530B /* struct.proto */,
+ F4E675C31B21D1440054530B /* Timestamp.pbobjc.h */,
+ 8B4248E01A929C7D00BC1EC6 /* Timestamp.pbobjc.m */,
+ 8B4249481A92A02300BC1EC6 /* timestamp.proto */,
+ F4E675C41B21D1440054530B /* Type.pbobjc.h */,
+ F4E675C51B21D1440054530B /* Type.pbobjc.m */,
+ F4E675DE1B21D1DE0054530B /* type.proto */,
+ F4E675C61B21D1440054530B /* Wrappers.pbobjc.h */,
+ F4E675C71B21D1440054530B /* Wrappers.pbobjc.m */,
+ F4E675DF1B21D1DE0054530B /* wrappers.proto */,
+ );
+ name = Generated;
+ sourceTree = "<group>";
+ };
+ 29B97323FDCFA39411CA2CEA /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 8B9742421A8AAA7800DCE92C /* CoreGraphics.framework */,
+ 8B9A5E9F1831913D00A9D33B /* UIKit.framework */,
+ 1D30AB110D05D00D00671497 /* Foundation.framework */,
+ );
+ name = Frameworks;
+ sourceTree = "<group>";
+ };
+ 7461B3C50F94F84100A0C422 /* Extensions */ = {
+ isa = PBXGroup;
+ children = (
+ F4B6B8B31A9CD1C600892426 /* GPBExtensionInternals.h */,
+ F45C69CB16DFD08D0081955B /* GPBExtensionInternals.m */,
+ 7461B4A80F94F99000A0C422 /* GPBExtensionRegistry.h */,
+ 7461B4A90F94F99000A0C422 /* GPBExtensionRegistry.m */,
+ F4B6B8B51A9CD1C600892426 /* GPBRootObject_PackagePrivate.h */,
+ 8B79657814992E3E002FFBFC /* GPBRootObject.h */,
+ 8B79657914992E3E002FFBFC /* GPBRootObject.m */,
+ );
+ name = Extensions;
+ sourceTree = "<group>";
+ };
+ 7461B4850F94F96600A0C422 /* Fields */ = {
+ isa = PBXGroup;
+ children = (
+ F4B6B8B01A9CC99500892426 /* GPBUnknownField_PackagePrivate.h */,
+ 7461B4AE0F94F99000A0C422 /* GPBUnknownField.h */,
+ 7461B4AF0F94F99000A0C422 /* GPBUnknownField.m */,
+ F4B6B8B11A9CCBBB00892426 /* GPBUnknownFieldSet_PackagePrivate.h */,
+ 7461B4E10F94F99000A0C422 /* GPBUnknownFieldSet.h */,
+ 7461B4E20F94F99000A0C422 /* GPBUnknownFieldSet.m */,
+ );
+ name = Fields;
+ sourceTree = "<group>";
+ };
+ 7461B4860F94F96B00A0C422 /* IO */ = {
+ isa = PBXGroup;
+ children = (
+ 51457B5F18D0B7AF00CCC606 /* GPBCodedInputStream_PackagePrivate.h */,
+ 7461B48E0F94F99000A0C422 /* GPBCodedInputStream.h */,
+ 7461B48F0F94F99000A0C422 /* GPBCodedInputStream.m */,
+ F44929021C866B3B00C2548A /* GPBCodedOutputStream_PackagePrivate.h */,
+ 7461B4900F94F99000A0C422 /* GPBCodedOutputStream.h */,
+ 7461B4910F94F99000A0C422 /* GPBCodedOutputStream.m */,
+ 7461B4E70F94F99000A0C422 /* GPBWireFormat.h */,
+ 7461B4E80F94F99000A0C422 /* GPBWireFormat.m */,
+ );
+ name = IO;
+ sourceTree = "<group>";
+ };
+ 7461B5150F94FA7300A0C422 /* Messages */ = {
+ isa = PBXGroup;
+ children = (
+ 515B840C18B7DEE30031753B /* GPBDescriptor_PackagePrivate.h */,
+ 8B96157214C8B06000A2AC0B /* GPBDescriptor.h */,
+ 8B96157314C8C38C00A2AC0B /* GPBDescriptor.m */,
+ 7461B4BE0F94F99000A0C422 /* GPBMessage.h */,
+ 5196A06918CE16B000B759E2 /* GPBMessage_PackagePrivate.h */,
+ 7461B4BF0F94F99000A0C422 /* GPBMessage.m */,
+ );
+ name = Messages;
+ sourceTree = "<group>";
+ };
+ 7461B6940F94FDDD00A0C422 /* Tests */ = {
+ isa = PBXGroup;
+ children = (
+ 8B9A5EA91831993600A9D33B /* iOSTestHarness */,
+ 8B4248B71A8BDD9600BC1EC6 /* protobuf */,
+ 8B210CCD159383D60032D72D /* golden_message */,
+ 8B210CCF159386920032D72D /* golden_packed_fields_message */,
+ 8B8B615C17DF7056002EE618 /* GPBARCUnittestProtos.m */,
+ F401DC341A8E5C6F00FCC765 /* GPBArrayTests.m */,
+ 7461B69B0F94FDF800A0C422 /* GPBCodedInputStreamTests.m */,
+ 7461B69D0F94FDF800A0C422 /* GPBCodedOuputStreamTests.m */,
+ 5102DABB1891A052002037B6 /* GPBConcurrencyTests.m */,
+ F4353D1E1AB88243005A6198 /* GPBDescriptorTests.m */,
+ F4C4B9E51E1D97BB00D3B61D /* GPBDictionaryTests.m */,
+ F4353D3A1AC06F31005A6198 /* GPBDictionaryTests.pddm */,
+ F4353D3B1AC06F31005A6198 /* GPBDictionaryTests+Bool.m */,
+ F4353D3C1AC06F31005A6198 /* GPBDictionaryTests+Int32.m */,
+ F4353D3D1AC06F31005A6198 /* GPBDictionaryTests+Int64.m */,
+ F4353D3E1AC06F31005A6198 /* GPBDictionaryTests+String.m */,
+ F4353D3F1AC06F31005A6198 /* GPBDictionaryTests+UInt32.m */,
+ F4353D401AC06F31005A6198 /* GPBDictionaryTests+UInt64.m */,
+ 7461B6A30F94FDF800A0C422 /* GPBMessageTests.m */,
+ F4487C841AAF6AC500531423 /* GPBMessageTests+Merge.m */,
+ F4487C761AADF84900531423 /* GPBMessageTests+Runtime.m */,
+ F4487C801AAF62FC00531423 /* GPBMessageTests+Serialization.m */,
+ F4B51B1B1BBC5C7100744318 /* GPBObjectiveCPlusPlusTest.mm */,
+ F41C175C1833D3310064ED4D /* GPBPerfTests.m */,
+ 8B4248B31A8BD96E00BC1EC6 /* GPBSwiftTests.swift */,
+ 7461B6AB0F94FDF800A0C422 /* GPBTestUtilities.h */,
+ 7461B6AC0F94FDF800A0C422 /* GPBTestUtilities.m */,
+ 8BD3981E14BE59D70081D629 /* GPBUnittestProtos.m */,
+ F4F8D8841D78A186002CE128 /* GPBUnittestProtos2.m */,
+ 7461B6B80F94FDF900A0C422 /* GPBUnknownFieldSetTest.m */,
+ 7461B6BA0F94FDF900A0C422 /* GPBUtilitiesTests.m */,
+ 8B4248E51A929C9900BC1EC6 /* GPBWellKnownTypesTest.m */,
+ 7461B6BC0F94FDF900A0C422 /* GPBWireFormatTests.m */,
+ F43C88CF191D77FC009E917D /* text_format_unittest_data.txt */,
+ F45E57C81AE6DC98000B7D99 /* text_format_map_unittest_data.txt */,
+ 8B7E6A7414893DBA00F8884A /* unittest_custom_options.proto */,
+ F4AC9E1C1A8BEB1000BD6E83 /* unittest_cycle.proto */,
+ 8B7E6A7514893DBA00F8884A /* unittest_embed_optimize_for.proto */,
+ 8B7E6A7614893DBA00F8884A /* unittest_empty.proto */,
+ 8BD3981D14BE54220081D629 /* unittest_enormous_descriptor.proto */,
+ 8B7E6A7814893DBB00F8884A /* unittest_import.proto */,
+ 8BBD9DB016DD1DC8008E1EC1 /* unittest_lite.proto */,
+ 8B7E6A7B14893DBC00F8884A /* unittest_mset.proto */,
+ 8B7E6A7C14893DBC00F8884A /* unittest_no_generic_services.proto */,
+ 8B09AAF614B663A7007B4184 /* unittest_objc.proto */,
+ F4CF31711B162EF500BD9B06 /* unittest_objc_startup.proto */,
+ 8B7E6A7D14893DBC00F8884A /* unittest_optimize_for.proto */,
+ F4487C7A1AADFB5500531423 /* unittest_runtime_proto2.proto */,
+ F4487C7B1AADFB5500531423 /* unittest_runtime_proto3.proto */,
+ 8B7E6A7E14893DBC00F8884A /* unittest.proto */,
+ 8B4248B21A8BD96D00BC1EC6 /* UnitTests-Bridging-Header.h */,
+ 7401C1A90F950347006D8281 /* UnitTests-Info.plist */,
+ );
+ path = Tests;
+ sourceTree = "<group>";
+ };
+ 8B9A5EA91831993600A9D33B /* iOSTestHarness */ = {
+ isa = PBXGroup;
+ children = (
+ 8B9A5EB31831993600A9D33B /* AppDelegate.m */,
+ 8B9A5EB51831993600A9D33B /* Images.xcassets */,
+ 8B9A5EAA1831993600A9D33B /* Supporting Files */,
+ 8B9742321A89D19F00DCE92C /* LaunchScreen.xib */,
+ );
+ path = iOSTestHarness;
+ sourceTree = "<group>";
+ };
+ 8B9A5EAA1831993600A9D33B /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ 8B9A5EAB1831993600A9D33B /* Info.plist */,
+ 8B9A5EAC1831993600A9D33B /* InfoPlist.strings */,
+ );
+ name = "Supporting Files";
+ sourceTree = "<group>";
+ };
+ 8BCF334414ED727300BC5317 /* Support */ = {
+ isa = PBXGroup;
+ children = (
+ F4411BE81AF1301700324B4A /* GPBArray_PackagePrivate.h */,
+ F4487C701A9F906200531423 /* GPBArray.h */,
+ F4487C711A9F906200531423 /* GPBArray.m */,
+ 7461B48D0F94F99000A0C422 /* GPBBootstrap.h */,
+ F43725921AC9835D004DCAFB /* GPBDictionary_PackagePrivate.h */,
+ F4353D241ABB156F005A6198 /* GPBDictionary.h */,
+ F4353D251ABB156F005A6198 /* GPBDictionary.m */,
+ 8BEB5AE01498033E0078BF9D /* GPBRuntimeTypes.h */,
+ F4487C7D1AAE06C500531423 /* GPBUtilities_PackagePrivate.h */,
+ 7461B4E50F94F99000A0C422 /* GPBUtilities.h */,
+ 7461B4E60F94F99000A0C422 /* GPBUtilities.m */,
+ 8B4248E11A929C8900BC1EC6 /* GPBWellKnownTypes.h */,
+ 8B4248E21A929C8900BC1EC6 /* GPBWellKnownTypes.m */,
+ );
+ name = Support;
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXHeadersBuildPhase section */
+ 7461B52A0F94FAF800A0C422 /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ F4487C561A9F8F8100531423 /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXHeadersBuildPhase section */
+
+/* Begin PBXLegacyTarget section */
+ F45BBC0E1B0CDB50002D064D /* Compile Unittest Protos */ = {
+ isa = PBXLegacyTarget;
+ buildArgumentsString = "$(ACTION)";
+ buildConfigurationList = F45BBC111B0CDB50002D064D /* Build configuration list for PBXLegacyTarget "Compile Unittest Protos" */;
+ buildPhases = (
+ );
+ buildToolPath = DevTools/compile_testing_protos.sh;
+ buildWorkingDirectory = "";
+ dependencies = (
+ );
+ name = "Compile Unittest Protos";
+ passBuildSettingsInEnvironment = 1;
+ productName = "Compile Unittest Protos";
+ };
+/* End PBXLegacyTarget section */
+
+/* Begin PBXNativeTarget section */
+ 7461B52D0F94FAF800A0C422 /* ProtocolBuffers */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 7461B5330F94FAFD00A0C422 /* Build configuration list for PBXNativeTarget "ProtocolBuffers" */;
+ buildPhases = (
+ 7461B52A0F94FAF800A0C422 /* Headers */,
+ 7461B52B0F94FAF800A0C422 /* Sources */,
+ 7461B52C0F94FAF800A0C422 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = ProtocolBuffers;
+ productName = "ProtocolBuffers-iPhoneDevice";
+ productReference = 7461B52E0F94FAF800A0C422 /* libProtocolBuffers.a */;
+ productType = "com.apple.product-type.library.static";
+ };
+ 8B9A5EA41831993600A9D33B /* iOSTestHarness */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 8B9A5ECA1831993600A9D33B /* Build configuration list for PBXNativeTarget "iOSTestHarness" */;
+ buildPhases = (
+ 8B9A5EA11831993600A9D33B /* Sources */,
+ 8B9A5EA21831993600A9D33B /* Frameworks */,
+ 8B9A5EA31831993600A9D33B /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = iOSTestHarness;
+ productName = iOSTestHarness;
+ productReference = 8B9A5EA51831993600A9D33B /* iOSTestHarness.app */;
+ productType = "com.apple.product-type.application";
+ };
+ 8BBEA4A5147C727100C4ADB7 /* UnitTests */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 8BBEA4BA147C728600C4ADB7 /* Build configuration list for PBXNativeTarget "UnitTests" */;
+ buildPhases = (
+ F4B62A791AF91F7500AFCEDC /* Script: Check Runtime Stamps */,
+ 8BBEA4A1147C727100C4ADB7 /* Resources */,
+ 8BBEA4A2147C727100C4ADB7 /* Sources */,
+ 8BBEA4A3147C727100C4ADB7 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ 8BBEA4BD147C729A00C4ADB7 /* PBXTargetDependency */,
+ F45BBC131B0CDBBA002D064D /* PBXTargetDependency */,
+ 8B9A5ED11831994600A9D33B /* PBXTargetDependency */,
+ );
+ name = UnitTests;
+ productName = UnitTests;
+ productReference = 8BBEA4A6147C727100C4ADB7 /* UnitTests.xctest */;
+ productType = "com.apple.product-type.bundle.unit-test";
+ };
+ F4487C551A9F8F8100531423 /* TestSingleSourceBuild */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = F4487C6B1A9F8F8100531423 /* Build configuration list for PBXNativeTarget "TestSingleSourceBuild" */;
+ buildPhases = (
+ F4487C561A9F8F8100531423 /* Headers */,
+ F4487C5A1A9F8F8100531423 /* Sources */,
+ F4487C691A9F8F8100531423 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = TestSingleSourceBuild;
+ productName = "ProtocolBuffers-iPhoneDevice";
+ productReference = F4487C6E1A9F8F8100531423 /* libTestSingleSourceBuild.a */;
+ productType = "com.apple.product-type.library.static";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 29B97313FDCFA39411CA2CEA /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastSwiftUpdateCheck = 0710;
+ LastTestingUpgradeCheck = 0600;
+ LastUpgradeCheck = 0800;
+ TargetAttributes = {
+ 8BBEA4A5147C727100C4ADB7 = {
+ LastSwiftMigration = 0800;
+ TestTargetID = 8B9A5EA41831993600A9D33B;
+ };
+ F45BBC0E1B0CDB50002D064D = {
+ CreatedOnToolsVersion = 6.3.2;
+ };
+ };
+ };
+ buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ProtocolBuffers_iOS" */;
+ compatibilityVersion = "Xcode 6.3";
+ developmentRegion = English;
+ hasScannedForEncodings = 1;
+ knownRegions = (
+ en,
+ );
+ mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 7461B52D0F94FAF800A0C422 /* ProtocolBuffers */,
+ 8BBEA4A5147C727100C4ADB7 /* UnitTests */,
+ 8B9A5EA41831993600A9D33B /* iOSTestHarness */,
+ F4487C551A9F8F8100531423 /* TestSingleSourceBuild */,
+ F45BBC0E1B0CDB50002D064D /* Compile Unittest Protos */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ 8B9A5EA31831993600A9D33B /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8B9A5EAE1831993600A9D33B /* InfoPlist.strings in Resources */,
+ 8B9A5EB61831993600A9D33B /* Images.xcassets in Resources */,
+ 8B9742331A89D19F00DCE92C /* LaunchScreen.xib in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 8BBEA4A1147C727100C4ADB7 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8B210CCE159383D60032D72D /* golden_message in Resources */,
+ F43C88D0191D77FC009E917D /* text_format_unittest_data.txt in Resources */,
+ 8B210CD0159386920032D72D /* golden_packed_fields_message in Resources */,
+ F45E57C91AE6DC98000B7D99 /* text_format_map_unittest_data.txt in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXShellScriptBuildPhase section */
+ F4B62A791AF91F7500AFCEDC /* Script: Check Runtime Stamps */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputPaths = (
+ );
+ name = "Script: Check Runtime Stamps";
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "set -eu\nexec \"${SOURCE_ROOT}/DevTools/check_version_stamps.sh\"\n";
+ showEnvVarsInLog = 0;
+ };
+/* End PBXShellScriptBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 7461B52B0F94FAF800A0C422 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 7461B53C0F94FB4E00A0C422 /* GPBCodedInputStream.m in Sources */,
+ F4E675D21B21D1620054530B /* Empty.pbobjc.m in Sources */,
+ F4487C731A9F906200531423 /* GPBArray.m in Sources */,
+ 7461B53D0F94FB4E00A0C422 /* GPBCodedOutputStream.m in Sources */,
+ 7461B5490F94FB4E00A0C422 /* GPBExtensionRegistry.m in Sources */,
+ F4E675D31B21D1620054530B /* FieldMask.pbobjc.m in Sources */,
+ 7461B54C0F94FB4E00A0C422 /* GPBUnknownField.m in Sources */,
+ 7461B5530F94FB4E00A0C422 /* GPBMessage.m in Sources */,
+ F47476E91D21A537007C7B1A /* Duration.pbobjc.m in Sources */,
+ 7461B5610F94FB4E00A0C422 /* GPBUnknownFieldSet.m in Sources */,
+ 7461B5630F94FB4E00A0C422 /* GPBUtilities.m in Sources */,
+ 7461B5640F94FB4E00A0C422 /* GPBWireFormat.m in Sources */,
+ F4E675D11B21D1620054530B /* Api.pbobjc.m in Sources */,
+ F4E675D41B21D1620054530B /* SourceContext.pbobjc.m in Sources */,
+ F4353D271ABB156F005A6198 /* GPBDictionary.m in Sources */,
+ 8B79657B14992E3F002FFBFC /* GPBRootObject.m in Sources */,
+ 8B96157414C8C38C00A2AC0B /* GPBDescriptor.m in Sources */,
+ F4E675D01B21D1620054530B /* Any.pbobjc.m in Sources */,
+ F45C69CC16DFD08D0081955B /* GPBExtensionInternals.m in Sources */,
+ 8B4248E41A929C8900BC1EC6 /* GPBWellKnownTypes.m in Sources */,
+ F4E675D61B21D1620054530B /* Type.pbobjc.m in Sources */,
+ F4E675D51B21D1620054530B /* Struct.pbobjc.m in Sources */,
+ F4E675D71B21D1620054530B /* Wrappers.pbobjc.m in Sources */,
+ F47476EA1D21A537007C7B1A /* Timestamp.pbobjc.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 8B9A5EA11831993600A9D33B /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8B9A5EB41831993600A9D33B /* AppDelegate.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ 8BBEA4A2147C727100C4ADB7 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 8BBEA4A9147C727D00C4ADB7 /* GPBCodedInputStreamTests.m in Sources */,
+ F401DC351A8E5C6F00FCC765 /* GPBArrayTests.m in Sources */,
+ F4353D441AC06F31005A6198 /* GPBDictionaryTests+Int64.m in Sources */,
+ F4353D471AC06F31005A6198 /* GPBDictionaryTests+UInt64.m in Sources */,
+ 8BBEA4AA147C727D00C4ADB7 /* GPBCodedOuputStreamTests.m in Sources */,
+ 8BBEA4AC147C727D00C4ADB7 /* GPBMessageTests.m in Sources */,
+ F4487C811AAF62FC00531423 /* GPBMessageTests+Serialization.m in Sources */,
+ 8B4248E61A929C9900BC1EC6 /* GPBWellKnownTypesTest.m in Sources */,
+ F4353D1F1AB88243005A6198 /* GPBDescriptorTests.m in Sources */,
+ F4F8D8861D78A193002CE128 /* GPBUnittestProtos2.m in Sources */,
+ F4B51B1C1BBC5C7100744318 /* GPBObjectiveCPlusPlusTest.mm in Sources */,
+ 8B4248B41A8BD96E00BC1EC6 /* GPBSwiftTests.swift in Sources */,
+ 5102DABC1891A073002037B6 /* GPBConcurrencyTests.m in Sources */,
+ F4487C771AADF84900531423 /* GPBMessageTests+Runtime.m in Sources */,
+ F4353D431AC06F31005A6198 /* GPBDictionaryTests+Int32.m in Sources */,
+ 8BBEA4B0147C727D00C4ADB7 /* GPBTestUtilities.m in Sources */,
+ F41C175D1833D3310064ED4D /* GPBPerfTests.m in Sources */,
+ F4353D421AC06F31005A6198 /* GPBDictionaryTests+Bool.m in Sources */,
+ F4487C851AAF6AC500531423 /* GPBMessageTests+Merge.m in Sources */,
+ 8BBEA4B6147C727D00C4ADB7 /* GPBUnknownFieldSetTest.m in Sources */,
+ F4353D451AC06F31005A6198 /* GPBDictionaryTests+String.m in Sources */,
+ F4353D461AC06F31005A6198 /* GPBDictionaryTests+UInt32.m in Sources */,
+ 8BBEA4B7147C727D00C4ADB7 /* GPBUtilitiesTests.m in Sources */,
+ F4C4B9E71E1D97BF00D3B61D /* GPBDictionaryTests.m in Sources */,
+ 8BBEA4B8147C727D00C4ADB7 /* GPBWireFormatTests.m in Sources */,
+ 8BD3981F14BE59D70081D629 /* GPBUnittestProtos.m in Sources */,
+ 8B8B615D17DF7056002EE618 /* GPBARCUnittestProtos.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+ F4487C5A1A9F8F8100531423 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ F4487C6F1A9F8FFF00531423 /* GPBProtocolBuffers.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXTargetDependency section */
+ 8B9A5ED11831994600A9D33B /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 8B9A5EA41831993600A9D33B /* iOSTestHarness */;
+ targetProxy = 8B9A5ED01831994600A9D33B /* PBXContainerItemProxy */;
+ };
+ 8BBEA4BD147C729A00C4ADB7 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 7461B52D0F94FAF800A0C422 /* ProtocolBuffers */;
+ targetProxy = 8BBEA4BC147C729A00C4ADB7 /* PBXContainerItemProxy */;
+ };
+ F45BBC131B0CDBBA002D064D /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = F45BBC0E1B0CDB50002D064D /* Compile Unittest Protos */;
+ targetProxy = F45BBC121B0CDBBA002D064D /* PBXContainerItemProxy */;
+ };
+/* End PBXTargetDependency section */
+
+/* Begin PBXVariantGroup section */
+ 8B9A5EAC1831993600A9D33B /* InfoPlist.strings */ = {
+ isa = PBXVariantGroup;
+ children = (
+ 8B9A5EAD1831993600A9D33B /* en */,
+ );
+ name = InfoPlist.strings;
+ sourceTree = "<group>";
+ };
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+ 7461B52F0F94FAFA00A0C422 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ HEADER_SEARCH_PATHS = "$(SRCROOT)";
+ PRODUCT_NAME = ProtocolBuffers;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ };
+ name = Debug;
+ };
+ 7461B5300F94FAFA00A0C422 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ HEADER_SEARCH_PATHS = "$(SRCROOT)";
+ PRODUCT_NAME = ProtocolBuffers;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ };
+ name = Release;
+ };
+ 8B9A5ECB1831993600A9D33B /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ INFOPLIST_FILE = "$(SRCROOT)/Tests/iOSTestHarness/Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ PRODUCT_BUNDLE_IDENTIFIER = "com.google.${PRODUCT_NAME:rfc1034identifier}";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ TARGETED_DEVICE_FAMILY = "1,2";
+ WRAPPER_EXTENSION = app;
+ };
+ name = Debug;
+ };
+ 8B9A5ECC1831993600A9D33B /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ INFOPLIST_FILE = "$(SRCROOT)/Tests/iOSTestHarness/Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ PRODUCT_BUNDLE_IDENTIFIER = "com.google.${PRODUCT_NAME:rfc1034identifier}";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ TARGETED_DEVICE_FAMILY = "1,2";
+ WRAPPER_EXTENSION = app;
+ };
+ name = Release;
+ };
+ 8BBEA4A7147C727100C4ADB7 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CLANG_ENABLE_MODULES = YES;
+ FRAMEWORK_SEARCH_PATHS = (
+ "\"$(SDKROOT)/Developer/Library/Frameworks\"",
+ "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
+ "$(inherited)",
+ );
+ HEADER_SEARCH_PATHS = (
+ "${PROJECT_DERIVED_FILE_DIR}/protos",
+ "$(SRCROOT)",
+ );
+ INFOPLIST_FILE = "Tests/UnitTests-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
+ LIBRARY_SEARCH_PATHS = (
+ "$(inherited)",
+ "\"$(DEVELOPER_DIR)/usr/lib\"",
+ );
+ OTHER_LDFLAGS = "-ObjC";
+ PRODUCT_NAME = UnitTests;
+ SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h";
+ SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+ SWIFT_VERSION = 3.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ TEST_HOST = "$(BUILT_PRODUCTS_DIR)/iOSTestHarness.app/iOSTestHarness";
+ WARNING_CFLAGS = (
+ "$(inherited)",
+ "-Wno-documentation-unknown-command",
+ "-Wno-reserved-id-macro",
+ "-Wno-direct-ivar-access",
+ );
+ };
+ name = Debug;
+ };
+ 8BBEA4A8147C727100C4ADB7 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CLANG_ENABLE_MODULES = YES;
+ FRAMEWORK_SEARCH_PATHS = (
+ "\"$(SDKROOT)/Developer/Library/Frameworks\"",
+ "\"$(DEVELOPER_LIBRARY_DIR)/Frameworks\"",
+ "$(inherited)",
+ );
+ HEADER_SEARCH_PATHS = (
+ "${PROJECT_DERIVED_FILE_DIR}/protos",
+ "$(SRCROOT)",
+ );
+ INFOPLIST_FILE = "Tests/UnitTests-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
+ LIBRARY_SEARCH_PATHS = (
+ "$(inherited)",
+ "\"$(DEVELOPER_DIR)/usr/lib\"",
+ );
+ OTHER_LDFLAGS = "-ObjC";
+ PRODUCT_NAME = UnitTests;
+ SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnitTests-Bridging-Header.h";
+ SWIFT_VERSION = 3.0;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ TEST_HOST = "$(BUILT_PRODUCTS_DIR)/iOSTestHarness.app/iOSTestHarness";
+ WARNING_CFLAGS = (
+ "$(inherited)",
+ "-Wno-documentation-unknown-command",
+ "-Wno-reserved-id-macro",
+ "-Wno-direct-ivar-access",
+ );
+ };
+ name = Release;
+ };
+ C01FCF4F08A954540054247B /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = YES;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
+ CLANG_STATIC_ANALYZER_MODE = deep;
+ CLANG_WARN_ASSIGN_ENUM = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES;
+ CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES;
+ CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_TESTABILITY = YES;
+ GCC_C_LANGUAGE_STANDARD = c99;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
+ GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
+ GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES;
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
+ GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES;
+ GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
+ GCC_WARN_MISSING_PARENTHESES = YES;
+ GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
+ GCC_WARN_SHADOW = YES;
+ GCC_WARN_SIGN_COMPARE = YES;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNKNOWN_PRAGMAS = YES;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_LABEL = YES;
+ GCC_WARN_UNUSED_PARAMETER = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ GENERATE_PROFILING_CODE = NO;
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ ONLY_ACTIVE_ARCH = YES;
+ RUN_CLANG_STATIC_ANALYZER = YES;
+ SDKROOT = iphoneos;
+ WARNING_CFLAGS = (
+ "-Wdocumentation-unknown-command",
+ "-Wundef",
+ "-Wreserved-id-macro",
+ "-Wswitch-enum",
+ "-Wdirect-ivar-access",
+ "-Woverriding-method-mismatch",
+ );
+ };
+ name = Debug;
+ };
+ C01FCF5008A954540054247B /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = YES;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
+ CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
+ CLANG_STATIC_ANALYZER_MODE = deep;
+ CLANG_WARN_ASSIGN_ENUM = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
+ CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES;
+ CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
+ CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES;
+ CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
+ CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ ENABLE_NS_ASSERTIONS = NO;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ GCC_C_LANGUAGE_STANDARD = c99;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
+ GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES;
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;
+ GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES;
+ GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
+ GCC_WARN_MISSING_PARENTHESES = YES;
+ GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES;
+ GCC_WARN_SHADOW = YES;
+ GCC_WARN_SIGN_COMPARE = YES;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNKNOWN_PRAGMAS = YES;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_LABEL = YES;
+ GCC_WARN_UNUSED_PARAMETER = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ GENERATE_PROFILING_CODE = NO;
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ RUN_CLANG_STATIC_ANALYZER = YES;
+ SDKROOT = iphoneos;
+ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
+ WARNING_CFLAGS = (
+ "-Wdocumentation-unknown-command",
+ "-Wundef",
+ "-Wreserved-id-macro",
+ "-Wswitch-enum",
+ "-Wdirect-ivar-access",
+ "-Woverriding-method-mismatch",
+ );
+ };
+ name = Release;
+ };
+ F4487C6C1A9F8F8100531423 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ HEADER_SEARCH_PATHS = "$(SRCROOT)";
+ PRODUCT_NAME = TestSingleSourceBuild;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ };
+ name = Debug;
+ };
+ F4487C6D1A9F8F8100531423 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ HEADER_SEARCH_PATHS = "$(SRCROOT)";
+ PRODUCT_NAME = TestSingleSourceBuild;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ };
+ name = Release;
+ };
+ F45BBC0F1B0CDB50002D064D /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ };
+ name = Debug;
+ };
+ F45BBC101B0CDB50002D064D /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 7461B5330F94FAFD00A0C422 /* Build configuration list for PBXNativeTarget "ProtocolBuffers" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 7461B52F0F94FAFA00A0C422 /* Debug */,
+ 7461B5300F94FAFA00A0C422 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 8B9A5ECA1831993600A9D33B /* Build configuration list for PBXNativeTarget "iOSTestHarness" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 8B9A5ECB1831993600A9D33B /* Debug */,
+ 8B9A5ECC1831993600A9D33B /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 8BBEA4BA147C728600C4ADB7 /* Build configuration list for PBXNativeTarget "UnitTests" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 8BBEA4A7147C727100C4ADB7 /* Debug */,
+ 8BBEA4A8147C727100C4ADB7 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ProtocolBuffers_iOS" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ C01FCF4F08A954540054247B /* Debug */,
+ C01FCF5008A954540054247B /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ F4487C6B1A9F8F8100531423 /* Build configuration list for PBXNativeTarget "TestSingleSourceBuild" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ F4487C6C1A9F8F8100531423 /* Debug */,
+ F4487C6D1A9F8F8100531423 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ F45BBC111B0CDB50002D064D /* Build configuration list for PBXLegacyTarget "Compile Unittest Protos" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ F45BBC0F1B0CDB50002D064D /* Debug */,
+ F45BBC101B0CDB50002D064D /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
+}
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata
new file mode 100644
index 0000000000..037a91dfae
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+ version = "1.0">
+ <FileRef
+ location = "self:ProtocolBuffers_iOS.xcodeproj">
+ </FileRef>
+</Workspace>
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
new file mode 100644
index 0000000000..08de0be8d3
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>
+ <false/>
+</dict>
+</plist>
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme
new file mode 100644
index 0000000000..be31c30831
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/PerformanceTests.xcscheme
@@ -0,0 +1,345 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ LastUpgradeVersion = "0800"
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "YES">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ buildConfiguration = "Release"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES">
+ <Testables>
+ <TestableReference
+ skipped = "NO">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8BBEA4A5147C727100C4ADB7"
+ BuildableName = "UnitTests.xctest"
+ BlueprintName = "UnitTests"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ <SkippedTests>
+ <Test
+ Identifier = "CodedInputStreamTests">
+ </Test>
+ <Test
+ Identifier = "CodedOutputStreamTests">
+ </Test>
+ <Test
+ Identifier = "ConcurrencyTests">
+ </Test>
+ <Test
+ Identifier = "DescriptorTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolBoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolDoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolFloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolUInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBoolUInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBBridgeTests">
+ </Test>
+ <Test
+ Identifier = "GPBDoubleArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBEnumArrayCustomTests">
+ </Test>
+ <Test
+ Identifier = "GPBEnumArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBFloatArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32ArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32BoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32DoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32EnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32EnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32FloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32Int32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32Int64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32ObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32UInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt32UInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64ArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64BoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64DoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64EnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64EnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64FloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64Int32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64Int64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64ObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64UInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBInt64UInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBObjectiveCPlusPlusTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringBoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringDoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringEnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringEnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringFloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringUInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBStringUInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBTestCase">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32ArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32BoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32DoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32EnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32EnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32FloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32Int32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32Int64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32ObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32UInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt32UInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64ArrayTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64BoolDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64DoubleDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64EnumDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64EnumDictionaryUnknownEnumTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64FloatDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64Int32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64Int64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64ObjectDictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64UInt32DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "GPBUInt64UInt64DictionaryTests">
+ </Test>
+ <Test
+ Identifier = "MessageMergeTests">
+ </Test>
+ <Test
+ Identifier = "MessageRuntimeTests">
+ </Test>
+ <Test
+ Identifier = "MessageSerializationTests">
+ </Test>
+ <Test
+ Identifier = "MessageTests">
+ </Test>
+ <Test
+ Identifier = "UnknownFieldSetTest">
+ </Test>
+ <Test
+ Identifier = "UtilitiesTests">
+ </Test>
+ <Test
+ Identifier = "WellKnownTypesTest">
+ </Test>
+ <Test
+ Identifier = "WireFormatTests">
+ </Test>
+ </SkippedTests>
+ </TestableReference>
+ </Testables>
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8B9A5EA41831993600A9D33B"
+ BuildableName = "iOSTestHarness.app"
+ BlueprintName = "iOSTestHarness"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </TestAction>
+ <LaunchAction
+ buildConfiguration = "Release"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ debugServiceExtension = "internal"
+ allowLocationSimulation = "YES">
+ <BuildableProductRunnable
+ runnableDebuggingMode = "0">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8B9A5EA41831993600A9D33B"
+ BuildableName = "iOSTestHarness.app"
+ BlueprintName = "iOSTestHarness"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ buildConfiguration = "Release"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ debugDocumentVersioning = "YES">
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Release">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
diff --git a/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme
new file mode 100644
index 0000000000..edbe689822
--- /dev/null
+++ b/third_party/protobuf/objectivec/ProtocolBuffers_iOS.xcodeproj/xcshareddata/xcschemes/ProtocolBuffers.xcscheme
@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ LastUpgradeVersion = "0800"
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "NO">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "NO"
+ buildForArchiving = "NO"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4487C551A9F8F8100531423"
+ BuildableName = "libTestSingleSourceBuild.a"
+ BlueprintName = "TestSingleSourceBuild"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "NO"
+ buildForProfiling = "NO"
+ buildForArchiving = "NO"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8BBEA4A5147C727100C4ADB7"
+ BuildableName = "UnitTests.xctest"
+ BlueprintName = "UnitTests"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ codeCoverageEnabled = "YES">
+ <Testables>
+ <TestableReference
+ skipped = "NO">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8BBEA4A5147C727100C4ADB7"
+ BuildableName = "UnitTests.xctest"
+ BlueprintName = "UnitTests"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ <SkippedTests>
+ <Test
+ Identifier = "PerfTests">
+ </Test>
+ </SkippedTests>
+ </TestableReference>
+ </Testables>
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8B9A5EA41831993600A9D33B"
+ BuildableName = "iOSTestHarness.app"
+ BlueprintName = "iOSTestHarness"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </TestAction>
+ <LaunchAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ debugServiceExtension = "internal"
+ allowLocationSimulation = "YES">
+ <BuildableProductRunnable
+ runnableDebuggingMode = "0">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "8B9A5EA41831993600A9D33B"
+ BuildableName = "iOSTestHarness.app"
+ BlueprintName = "iOSTestHarness"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ buildConfiguration = "Release"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ debugDocumentVersioning = "YES">
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "7461B52D0F94FAF800A0C422"
+ BuildableName = "libProtocolBuffers.a"
+ BlueprintName = "ProtocolBuffers"
+ ReferencedContainer = "container:ProtocolBuffers_iOS.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Debug">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
diff --git a/third_party/protobuf/objectivec/README.md b/third_party/protobuf/objectivec/README.md
new file mode 100644
index 0000000000..7226f0b9a1
--- /dev/null
+++ b/third_party/protobuf/objectivec/README.md
@@ -0,0 +1,188 @@
+Protocol Buffers - Google's data interchange format
+===================================================
+
+[![Build Status](https://travis-ci.org/google/protobuf.svg?branch=master)](https://travis-ci.org/google/protobuf)
+
+Copyright 2008 Google Inc.
+
+This directory contains the Objective C Protocol Buffers runtime library.
+
+Requirements
+------------
+
+The Objective C implementation requires:
+
+- Objective C 2.0 Runtime (32bit & 64bit iOS, 64bit OS X).
+- Xcode 7.0 (or later).
+- The library code does *not* use ARC (for performance reasons), but it all can
+ be called from ARC code.
+
+Installation
+------------
+
+The full distribution pulled from github includes the sources for both the
+compiler (protoc) and the runtime (this directory). To build the compiler
+and run the runtime tests, you can use:
+
+ $ objectivec/DevTools/full_mac_build.sh
+
+This will generate the `src/protoc` binary.
+
+Building
+--------
+
+There are two ways to include the Runtime sources in your project:
+
+Add `objectivec/\*.h` & `objectivec/GPBProtocolBuffers.m` to your project.
+
+*or*
+
+Add `objectivec/\*.h` & `objectivec/\*.m` except for
+`objectivec/GPBProtocolBuffers.m` to your project.
+
+
+If the target is using ARC, remember to turn off ARC (`-fno-objc-arc`) for the
+`.m` files.
+
+The files generated by `protoc` for the `*.proto` files (`\*.pbobjc.h` and
+`\*.pbobjc.m`) are then also added to the target.
+
+Usage
+-----
+
+The objects generated for messages should work like any other Objective C
+object. They are mutable objects, but if you don't change them, they are safe
+to share between threads (similar to passing an NSMutableDictionary between
+threads/queues; as long as no one mutates it, things are fine).
+
+There are a few behaviors worth calling out:
+
+A property that is type NSString\* will never return nil. If the value is
+unset, it will return an empty string (@""). This is inpart to align things
+with the Protocol Buffers spec which says the default for strings is an empty
+string, but also so you can always safely pass them to isEqual:/compare:, etc.
+and have deterministic results.
+
+A property that is type NSData\* also won't return nil, it will return an empty
+data ([NSData data]). The reasoning is the same as for NSString not returning
+nil.
+
+A property that is another GPBMessage class also will not return nil. If the
+field wasn't already set, you will get a instance of the correct class. This
+instance will be a temporary instance unless you mutate it, at which point it
+will be attached to its parent object. We call this pattern *autocreators*.
+Similar to NSString and NSData properties it makes things a little safer when
+using them with isEqual:/etc.; but more importantly, this allows you to write
+code that uses Objective C's property dot notation to walk into nested objects
+and access and/or assign things without having to check that they are not nil
+and create them each step along the way. You can write this:
+
+```
+- (void)updateRecord:(MyMessage *)msg {
+ ...
+ // Note: You don't have to check subMessage and otherMessage for nil and
+ // alloc/init/assign them back along the way.
+ msg.subMessage.otherMessage.lastName = @"Smith";
+ ...
+}
+```
+
+If you want to check if a GPBMessage property is present, there is always as
+`has\[NAME\]` property to go with the main property to check if it is set.
+
+A property that is of an Array or Dictionary type also provides *autocreator*
+behavior and will never return nil. This provides all the same benefits you
+see for the message properties. Again, you can write:
+
+```
+- (void)updateRecord:(MyMessage *)msg {
+ ...
+ // Note: Just like above, you don't have to check subMessage and otherMessage
+ // for nil and alloc/init/assign them back along the way. You also don't have
+ // to create the siblingsArray, you can safely just append to it.
+ [msg.subMessage.otherMessage.siblingsArray addObject:@"Pat"];
+ ...
+}
+```
+
+If you are inspecting a message you got from some other place (server, disk,
+etc), you may want to check if the Array or Dictionary has entries without
+causing it to be created for you. For this, there is always a `\[NAME\]_Count`
+property also provided that can return zero or the real count, but won't trigger
+the creation.
+
+For primitive type fields (ints, floats, bools, enum) in messages defined in a
+`.proto` file that use *proto2* syntax there are conceptual differences between
+having an *explicit* and *default* value. You can always get the value of the
+property. In the case that it hasn't been set you will get the default. In
+cases where you need to know whether it was set explicitly or you are just
+getting the default, you can use the `has\[NAME\]` property. If the value has
+been set, and you want to clear it, you can set the `has\[NAME\]` to `NO`.
+*proto3* syntax messages do away with this concept, thus the default values are
+never included when the message is encoded.
+
+The Objective C classes/enums can be used from Swift code.
+
+Objective C Generator Proto File Options
+----------------------------------------
+
+**objc_class_prefix=\<prefix\>** (no default)
+
+Since Objective C uses a global namespace for all of its classes, there can
+be collisions. This option provides a prefix that will be added to the Enums
+and Objects (for messages) generated from the proto. Convention is to base
+the prefix on the package the proto is in.
+
+Objective C Generator `protoc` Options
+--------------------------------------
+
+When generating Objective C code, `protoc` supports a `--objc_opt` argument; the
+argument is comma-delimited name/value pairs (_key=value,key2=value2_). The
+_keys_ are used to change the behavior during generation. The currently
+supported keys are:
+
+ * `generate_for_named_framework`: The `value` used for this key will be used
+ when generating the `#import` statements in the generated code. Instead
+ of being plain `#import "some/path/file.pbobjc.h"` lines, they will be
+ framework based, i.e. - `#import <VALUE/file.pbobjc.h>`.
+
+ _NOTE:_ If this is used with `named_framework_to_proto_path_mappings_path`,
+ then this is effectively the _default_ to use for everything that wasn't
+ mapped by the other.
+
+ * `named_framework_to_proto_path_mappings_path`: The `value` used for this key
+ is a path to a file containing the listing of framework names and proto
+ files. The generator uses this to decide if another proto file referenced
+ should use a framework style import vs. a user level import
+ (`#import <FRAMEWORK/file.pbobjc.h>` vs `#import "dir/file.pbobjc.h"`).
+
+ The format of the file is:
+ * An entry is a line of `frameworkName: file.proto, dir/file2.proto`.
+ * Comments start with `#`.
+ * A comment can go on a line after an entry.
+ (i.e. - `frameworkName: file.proto # comment`)
+
+ Any number of files can be listed for a framework, just separate them with
+ commas.
+
+ There can be multiple lines listing the same frameworkName incase it has a
+ lot of proto files included in it; and having multiple lines makes things
+ easier to read.
+
+Contributing
+------------
+
+Please make updates to the tests along with changes. If just changing the
+runtime, the Xcode projects can be used to build and run tests. If your change
+also requires changes to the generated code,
+`objectivec/DevTools/full_mac_build.sh` can be used to easily rebuild and test
+changes. Passing `-h` to the script will show the addition options that could
+be useful.
+
+Documentation
+-------------
+
+The complete documentation for Protocol Buffers is available via the
+web at:
+
+ https://developers.google.com/protocol-buffers/
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.pbxproj b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.pbxproj
new file mode 100644
index 0000000000..b9df381a1c
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.pbxproj
@@ -0,0 +1,290 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 46;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ F4D5A0AE1CEE2D8F00562D79 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F4D5A0AD1CEE2D8F00562D79 /* AppDelegate.m */; };
+ F4D5A0B11CEE2D8F00562D79 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F4D5A0B01CEE2D8F00562D79 /* main.m */; };
+ F4D5A0B31CEE2D8F00562D79 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F4D5A0B21CEE2D8F00562D79 /* Assets.xcassets */; };
+ F4D5A0B61CEE2D8F00562D79 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = F4D5A0B41CEE2D8F00562D79 /* MainMenu.xib */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+ F4D5A0A91CEE2D8F00562D79 /* OSXCocoaPodsTester.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OSXCocoaPodsTester.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ F4D5A0AC1CEE2D8F00562D79 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
+ F4D5A0AD1CEE2D8F00562D79 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
+ F4D5A0B01CEE2D8F00562D79 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ F4D5A0B21CEE2D8F00562D79 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
+ F4D5A0B51CEE2D8F00562D79 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
+ F4D5A0B71CEE2D8F00562D79 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ F4D5A0A61CEE2D8F00562D79 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ F4D5A0A01CEE2D8F00562D79 = {
+ isa = PBXGroup;
+ children = (
+ F4D5A0AB1CEE2D8F00562D79 /* OSXCocoaPodsTester */,
+ F4D5A0AA1CEE2D8F00562D79 /* Products */,
+ );
+ sourceTree = "<group>";
+ };
+ F4D5A0AA1CEE2D8F00562D79 /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ F4D5A0A91CEE2D8F00562D79 /* OSXCocoaPodsTester.app */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ F4D5A0AB1CEE2D8F00562D79 /* OSXCocoaPodsTester */ = {
+ isa = PBXGroup;
+ children = (
+ F4D5A0AC1CEE2D8F00562D79 /* AppDelegate.h */,
+ F4D5A0AD1CEE2D8F00562D79 /* AppDelegate.m */,
+ F4D5A0B21CEE2D8F00562D79 /* Assets.xcassets */,
+ F4D5A0B41CEE2D8F00562D79 /* MainMenu.xib */,
+ F4D5A0B71CEE2D8F00562D79 /* Info.plist */,
+ F4D5A0AF1CEE2D8F00562D79 /* Supporting Files */,
+ );
+ path = OSXCocoaPodsTester;
+ sourceTree = "<group>";
+ };
+ F4D5A0AF1CEE2D8F00562D79 /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ F4D5A0B01CEE2D8F00562D79 /* main.m */,
+ );
+ name = "Supporting Files";
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ F4D5A0A81CEE2D8F00562D79 /* OSXCocoaPodsTester */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = F4D5A0BA1CEE2D8F00562D79 /* Build configuration list for PBXNativeTarget "OSXCocoaPodsTester" */;
+ buildPhases = (
+ F4D5A0A51CEE2D8F00562D79 /* Sources */,
+ F4D5A0A61CEE2D8F00562D79 /* Frameworks */,
+ F4D5A0A71CEE2D8F00562D79 /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = OSXCocoaPodsTester;
+ productName = OSXCocoaPodsTester;
+ productReference = F4D5A0A91CEE2D8F00562D79 /* OSXCocoaPodsTester.app */;
+ productType = "com.apple.product-type.application";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ F4D5A0A11CEE2D8F00562D79 /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0730;
+ ORGANIZATIONNAME = Google;
+ TargetAttributes = {
+ F4D5A0A81CEE2D8F00562D79 = {
+ CreatedOnToolsVersion = 7.3.1;
+ };
+ };
+ };
+ buildConfigurationList = F4D5A0A41CEE2D8F00562D79 /* Build configuration list for PBXProject "OSXCocoaPodsTester" */;
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ Base,
+ );
+ mainGroup = F4D5A0A01CEE2D8F00562D79;
+ productRefGroup = F4D5A0AA1CEE2D8F00562D79 /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ F4D5A0A81CEE2D8F00562D79 /* OSXCocoaPodsTester */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ F4D5A0A71CEE2D8F00562D79 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ F4D5A0B31CEE2D8F00562D79 /* Assets.xcassets in Resources */,
+ F4D5A0B61CEE2D8F00562D79 /* MainMenu.xib in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ F4D5A0A51CEE2D8F00562D79 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ F4D5A0B11CEE2D8F00562D79 /* main.m in Sources */,
+ F4D5A0AE1CEE2D8F00562D79 /* AppDelegate.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXVariantGroup section */
+ F4D5A0B41CEE2D8F00562D79 /* MainMenu.xib */ = {
+ isa = PBXVariantGroup;
+ children = (
+ F4D5A0B51CEE2D8F00562D79 /* Base */,
+ );
+ name = MainMenu.xib;
+ sourceTree = "<group>";
+ };
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+ F4D5A0B81CEE2D8F00562D79 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ CODE_SIGN_IDENTITY = "-";
+ COPY_PHASE_STRIP = NO;
+ DEBUG_INFORMATION_FORMAT = dwarf;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_TESTABILITY = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.11;
+ MTL_ENABLE_DEBUG_INFO = YES;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = macosx;
+ };
+ name = Debug;
+ };
+ F4D5A0B91CEE2D8F00562D79 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ CODE_SIGN_IDENTITY = "-";
+ COPY_PHASE_STRIP = NO;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ ENABLE_NS_ASSERTIONS = NO;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.11;
+ MTL_ENABLE_DEBUG_INFO = NO;
+ SDKROOT = macosx;
+ };
+ name = Release;
+ };
+ F4D5A0BB1CEE2D8F00562D79 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ COMBINE_HIDPI_IMAGES = YES;
+ INFOPLIST_FILE = OSXCocoaPodsTester/Info.plist;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = com.google.OSXCocoaPodsTester;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Debug;
+ };
+ F4D5A0BC1CEE2D8F00562D79 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ COMBINE_HIDPI_IMAGES = YES;
+ INFOPLIST_FILE = OSXCocoaPodsTester/Info.plist;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = com.google.OSXCocoaPodsTester;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ F4D5A0A41CEE2D8F00562D79 /* Build configuration list for PBXProject "OSXCocoaPodsTester" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ F4D5A0B81CEE2D8F00562D79 /* Debug */,
+ F4D5A0B91CEE2D8F00562D79 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ F4D5A0BA1CEE2D8F00562D79 /* Build configuration list for PBXNativeTarget "OSXCocoaPodsTester" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ F4D5A0BB1CEE2D8F00562D79 /* Debug */,
+ F4D5A0BC1CEE2D8F00562D79 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = F4D5A0A11CEE2D8F00562D79 /* Project object */;
+}
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata
new file mode 100644
index 0000000000..6d874e28a5
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+ version = "1.0">
+ <FileRef
+ location = "self:OSXCocoaPodsTester.xcodeproj">
+ </FileRef>
+</Workspace>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/OSXCocoaPodsTester.xcscheme b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/OSXCocoaPodsTester.xcscheme
new file mode 100644
index 0000000000..56f8782eb8
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/OSXCocoaPodsTester.xcscheme
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ LastUpgradeVersion = "0730"
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "YES">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4D5A0A81CEE2D8F00562D79"
+ BuildableName = "OSXCocoaPodsTester.app"
+ BlueprintName = "OSXCocoaPodsTester"
+ ReferencedContainer = "container:OSXCocoaPodsTester.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES">
+ <Testables>
+ </Testables>
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4D5A0A81CEE2D8F00562D79"
+ BuildableName = "OSXCocoaPodsTester.app"
+ BlueprintName = "OSXCocoaPodsTester"
+ ReferencedContainer = "container:OSXCocoaPodsTester.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </TestAction>
+ <LaunchAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ debugServiceExtension = "internal"
+ allowLocationSimulation = "YES">
+ <BuildableProductRunnable
+ runnableDebuggingMode = "0">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4D5A0A81CEE2D8F00562D79"
+ BuildableName = "OSXCocoaPodsTester.app"
+ BlueprintName = "OSXCocoaPodsTester"
+ ReferencedContainer = "container:OSXCocoaPodsTester.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ buildConfiguration = "Release"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ debugDocumentVersioning = "YES">
+ <BuildableProductRunnable
+ runnableDebuggingMode = "0">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4D5A0A81CEE2D8F00562D79"
+ BuildableName = "OSXCocoaPodsTester.app"
+ BlueprintName = "OSXCocoaPodsTester"
+ ReferencedContainer = "container:OSXCocoaPodsTester.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Debug">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.h b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.h
new file mode 100644
index 0000000000..c7ab521d0f
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.h
@@ -0,0 +1,37 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Cocoa/Cocoa.h>
+
+@interface AppDelegate : NSObject <NSApplicationDelegate>
+
+
+@end
+
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.m b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.m
new file mode 100644
index 0000000000..08735a0068
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/AppDelegate.m
@@ -0,0 +1,48 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "AppDelegate.h"
+
+@interface AppDelegate ()
+
+@property (weak) IBOutlet NSWindow *window;
+@end
+
+@implementation AppDelegate
+
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
+ // Insert code here to initialize your application
+}
+
+- (void)applicationWillTerminate:(NSNotification *)aNotification {
+ // Insert code here to tear down your application
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json
new file mode 100644
index 0000000000..2db2b1c7c6
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json
@@ -0,0 +1,58 @@
+{
+ "images" : [
+ {
+ "idiom" : "mac",
+ "size" : "16x16",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "16x16",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "32x32",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "32x32",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "128x128",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "128x128",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "256x256",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "256x256",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "512x512",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "512x512",
+ "scale" : "2x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Base.lproj/MainMenu.xib b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Base.lproj/MainMenu.xib
new file mode 100644
index 0000000000..aa3547ca18
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Base.lproj/MainMenu.xib
@@ -0,0 +1,680 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6233" systemVersion="14A329f" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+ <dependencies>
+ <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6233"/>
+ </dependencies>
+ <objects>
+ <customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
+ <connections>
+ <outlet property="delegate" destination="Voe-Tx-rLC" id="GzC-gU-4Uq"/>
+ </connections>
+ </customObject>
+ <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
+ <customObject id="-3" userLabel="Application" customClass="NSObject"/>
+ <customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModuleProvider="">
+ <connections>
+ <outlet property="window" destination="QvC-M9-y7g" id="gIp-Ho-8D9"/>
+ </connections>
+ </customObject>
+ <customObject id="YLy-65-1bz" customClass="NSFontManager"/>
+ <menu title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
+ <items>
+ <menuItem title="OSXCocoaPodsTester" id="1Xt-HY-uBw">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="OSXCocoaPodsTester" systemMenu="apple" id="uQy-DD-JDr">
+ <items>
+ <menuItem title="About OSXCocoaPodsTester" id="5kV-Vb-QxS">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="orderFrontStandardAboutPanel:" target="-1" id="Exp-CZ-Vem"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
+ <menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW"/>
+ <menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/>
+ <menuItem title="Services" id="NMo-om-nkz">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Services" systemMenu="services" id="hz9-B4-Xy5"/>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="4je-JR-u6R"/>
+ <menuItem title="Hide OSXCocoaPodsTester" keyEquivalent="h" id="Olw-nP-bQN">
+ <connections>
+ <action selector="hide:" target="-1" id="PnN-Uc-m68"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Hide Others" keyEquivalent="h" id="Vdr-fp-XzO">
+ <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
+ <connections>
+ <action selector="hideOtherApplications:" target="-1" id="VT4-aY-XCT"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Show All" id="Kd2-mp-pUS">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="unhideAllApplications:" target="-1" id="Dhg-Le-xox"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="kCx-OE-vgT"/>
+ <menuItem title="Quit OSXCocoaPodsTester" keyEquivalent="q" id="4sb-4s-VLi">
+ <connections>
+ <action selector="terminate:" target="-1" id="Te7-pn-YzF"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="File" id="dMs-cI-mzQ">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="File" id="bib-Uj-vzu">
+ <items>
+ <menuItem title="New" keyEquivalent="n" id="Was-JA-tGl">
+ <connections>
+ <action selector="newDocument:" target="-1" id="4Si-XN-c54"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Open…" keyEquivalent="o" id="IAo-SY-fd9">
+ <connections>
+ <action selector="openDocument:" target="-1" id="bVn-NM-KNZ"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Open Recent" id="tXI-mr-wws">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Open Recent" systemMenu="recentDocuments" id="oas-Oc-fiZ">
+ <items>
+ <menuItem title="Clear Menu" id="vNY-rz-j42">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="clearRecentDocuments:" target="-1" id="Daa-9d-B3U"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="m54-Is-iLE"/>
+ <menuItem title="Close" keyEquivalent="w" id="DVo-aG-piG">
+ <connections>
+ <action selector="performClose:" target="-1" id="HmO-Ls-i7Q"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Save…" keyEquivalent="s" id="pxx-59-PXV">
+ <connections>
+ <action selector="saveDocument:" target="-1" id="teZ-XB-qJY"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Save As…" keyEquivalent="S" id="Bw7-FT-i3A">
+ <connections>
+ <action selector="saveDocumentAs:" target="-1" id="mDf-zr-I0C"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Revert to Saved" id="KaW-ft-85H">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="revertDocumentToSaved:" target="-1" id="iJ3-Pv-kwq"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="aJh-i4-bef"/>
+ <menuItem title="Page Setup…" keyEquivalent="P" id="qIS-W8-SiK">
+ <modifierMask key="keyEquivalentModifierMask" shift="YES" command="YES"/>
+ <connections>
+ <action selector="runPageLayout:" target="-1" id="Din-rz-gC5"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Print…" keyEquivalent="p" id="aTl-1u-JFS">
+ <connections>
+ <action selector="print:" target="-1" id="qaZ-4w-aoO"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Edit" id="5QF-Oa-p0T">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Edit" id="W48-6f-4Dl">
+ <items>
+ <menuItem title="Undo" keyEquivalent="z" id="dRJ-4n-Yzg">
+ <connections>
+ <action selector="undo:" target="-1" id="M6e-cu-g7V"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Redo" keyEquivalent="Z" id="6dh-zS-Vam">
+ <connections>
+ <action selector="redo:" target="-1" id="oIA-Rs-6OD"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="WRV-NI-Exz"/>
+ <menuItem title="Cut" keyEquivalent="x" id="uRl-iY-unG">
+ <connections>
+ <action selector="cut:" target="-1" id="YJe-68-I9s"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Copy" keyEquivalent="c" id="x3v-GG-iWU">
+ <connections>
+ <action selector="copy:" target="-1" id="G1f-GL-Joy"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Paste" keyEquivalent="v" id="gVA-U4-sdL">
+ <connections>
+ <action selector="paste:" target="-1" id="UvS-8e-Qdg"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Paste and Match Style" keyEquivalent="V" id="WeT-3V-zwk">
+ <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
+ <connections>
+ <action selector="pasteAsPlainText:" target="-1" id="cEh-KX-wJQ"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Delete" id="pa3-QI-u2k">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="delete:" target="-1" id="0Mk-Ml-PaM"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Select All" keyEquivalent="a" id="Ruw-6m-B2m">
+ <connections>
+ <action selector="selectAll:" target="-1" id="VNm-Mi-diN"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="uyl-h8-XO2"/>
+ <menuItem title="Find" id="4EN-yA-p0u">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Find" id="1b7-l0-nxx">
+ <items>
+ <menuItem title="Find…" tag="1" keyEquivalent="f" id="Xz5-n4-O0W">
+ <connections>
+ <action selector="performFindPanelAction:" target="-1" id="cD7-Qs-BN4"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Find and Replace…" tag="12" keyEquivalent="f" id="YEy-JH-Tfz">
+ <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
+ <connections>
+ <action selector="performFindPanelAction:" target="-1" id="WD3-Gg-5AJ"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Find Next" tag="2" keyEquivalent="g" id="q09-fT-Sye">
+ <connections>
+ <action selector="performFindPanelAction:" target="-1" id="NDo-RZ-v9R"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Find Previous" tag="3" keyEquivalent="G" id="OwM-mh-QMV">
+ <connections>
+ <action selector="performFindPanelAction:" target="-1" id="HOh-sY-3ay"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Use Selection for Find" tag="7" keyEquivalent="e" id="buJ-ug-pKt">
+ <connections>
+ <action selector="performFindPanelAction:" target="-1" id="U76-nv-p5D"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Jump to Selection" keyEquivalent="j" id="S0p-oC-mLd">
+ <connections>
+ <action selector="centerSelectionInVisibleArea:" target="-1" id="IOG-6D-g5B"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Spelling and Grammar" id="Dv1-io-Yv7">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Spelling" id="3IN-sU-3Bg">
+ <items>
+ <menuItem title="Show Spelling and Grammar" keyEquivalent=":" id="HFo-cy-zxI">
+ <connections>
+ <action selector="showGuessPanel:" target="-1" id="vFj-Ks-hy3"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Check Document Now" keyEquivalent=";" id="hz2-CU-CR7">
+ <connections>
+ <action selector="checkSpelling:" target="-1" id="fz7-VC-reM"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="bNw-od-mp5"/>
+ <menuItem title="Check Spelling While Typing" id="rbD-Rh-wIN">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleContinuousSpellChecking:" target="-1" id="7w6-Qz-0kB"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Check Grammar With Spelling" id="mK6-2p-4JG">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleGrammarChecking:" target="-1" id="muD-Qn-j4w"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Correct Spelling Automatically" id="78Y-hA-62v">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleAutomaticSpellingCorrection:" target="-1" id="2lM-Qi-WAP"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Substitutions" id="9ic-FL-obx">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Substitutions" id="FeM-D8-WVr">
+ <items>
+ <menuItem title="Show Substitutions" id="z6F-FW-3nz">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="orderFrontSubstitutionsPanel:" target="-1" id="oku-mr-iSq"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="gPx-C9-uUO"/>
+ <menuItem title="Smart Copy/Paste" id="9yt-4B-nSM">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleSmartInsertDelete:" target="-1" id="3IJ-Se-DZD"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Smart Quotes" id="hQb-2v-fYv">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleAutomaticQuoteSubstitution:" target="-1" id="ptq-xd-QOA"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Smart Dashes" id="rgM-f4-ycn">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleAutomaticDashSubstitution:" target="-1" id="oCt-pO-9gS"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Smart Links" id="cwL-P1-jid">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleAutomaticLinkDetection:" target="-1" id="Gip-E3-Fov"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Data Detectors" id="tRr-pd-1PS">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleAutomaticDataDetection:" target="-1" id="R1I-Nq-Kbl"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Text Replacement" id="HFQ-gK-NFA">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleAutomaticTextReplacement:" target="-1" id="DvP-Fe-Py6"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Transformations" id="2oI-Rn-ZJC">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Transformations" id="c8a-y6-VQd">
+ <items>
+ <menuItem title="Make Upper Case" id="vmV-6d-7jI">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="uppercaseWord:" target="-1" id="sPh-Tk-edu"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Make Lower Case" id="d9M-CD-aMd">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="lowercaseWord:" target="-1" id="iUZ-b5-hil"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Capitalize" id="UEZ-Bs-lqG">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="capitalizeWord:" target="-1" id="26H-TL-nsh"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Speech" id="xrE-MZ-jX0">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Speech" id="3rS-ZA-NoH">
+ <items>
+ <menuItem title="Start Speaking" id="Ynk-f8-cLZ">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="startSpeaking:" target="-1" id="654-Ng-kyl"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Stop Speaking" id="Oyz-dy-DGm">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="stopSpeaking:" target="-1" id="dX8-6p-jy9"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Format" id="jxT-CU-nIS">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Format" id="GEO-Iw-cKr">
+ <items>
+ <menuItem title="Font" id="Gi5-1S-RQB">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Font" systemMenu="font" id="aXa-aM-Jaq">
+ <items>
+ <menuItem title="Show Fonts" keyEquivalent="t" id="Q5e-8K-NDq">
+ <connections>
+ <action selector="orderFrontFontPanel:" target="YLy-65-1bz" id="WHr-nq-2xA"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Bold" tag="2" keyEquivalent="b" id="GB9-OM-e27">
+ <connections>
+ <action selector="addFontTrait:" target="YLy-65-1bz" id="hqk-hr-sYV"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Italic" tag="1" keyEquivalent="i" id="Vjx-xi-njq">
+ <connections>
+ <action selector="addFontTrait:" target="YLy-65-1bz" id="IHV-OB-c03"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Underline" keyEquivalent="u" id="WRG-CD-K1S">
+ <connections>
+ <action selector="underline:" target="-1" id="FYS-2b-JAY"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="5gT-KC-WSO"/>
+ <menuItem title="Bigger" tag="3" keyEquivalent="+" id="Ptp-SP-VEL">
+ <connections>
+ <action selector="modifyFont:" target="YLy-65-1bz" id="Uc7-di-UnL"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Smaller" tag="4" keyEquivalent="-" id="i1d-Er-qST">
+ <connections>
+ <action selector="modifyFont:" target="YLy-65-1bz" id="HcX-Lf-eNd"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="kx3-Dk-x3B"/>
+ <menuItem title="Kern" id="jBQ-r6-VK2">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Kern" id="tlD-Oa-oAM">
+ <items>
+ <menuItem title="Use Default" id="GUa-eO-cwY">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="useStandardKerning:" target="-1" id="6dk-9l-Ckg"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Use None" id="cDB-IK-hbR">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="turnOffKerning:" target="-1" id="U8a-gz-Maa"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Tighten" id="46P-cB-AYj">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="tightenKerning:" target="-1" id="hr7-Nz-8ro"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Loosen" id="ogc-rX-tC1">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="loosenKerning:" target="-1" id="8i4-f9-FKE"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Ligatures" id="o6e-r0-MWq">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Ligatures" id="w0m-vy-SC9">
+ <items>
+ <menuItem title="Use Default" id="agt-UL-0e3">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="useStandardLigatures:" target="-1" id="7uR-wd-Dx6"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Use None" id="J7y-lM-qPV">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="turnOffLigatures:" target="-1" id="iX2-gA-Ilz"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Use All" id="xQD-1f-W4t">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="useAllLigatures:" target="-1" id="KcB-kA-TuK"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Baseline" id="OaQ-X3-Vso">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Baseline" id="ijk-EB-dga">
+ <items>
+ <menuItem title="Use Default" id="3Om-Ey-2VK">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="unscript:" target="-1" id="0vZ-95-Ywn"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Superscript" id="Rqc-34-cIF">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="superscript:" target="-1" id="3qV-fo-wpU"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Subscript" id="I0S-gh-46l">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="subscript:" target="-1" id="Q6W-4W-IGz"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Raise" id="2h7-ER-AoG">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="raiseBaseline:" target="-1" id="4sk-31-7Q9"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Lower" id="1tx-W0-xDw">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="lowerBaseline:" target="-1" id="OF1-bc-KW4"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="Ndw-q3-faq"/>
+ <menuItem title="Show Colors" keyEquivalent="C" id="bgn-CT-cEk">
+ <connections>
+ <action selector="orderFrontColorPanel:" target="-1" id="mSX-Xz-DV3"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="iMs-zA-UFJ"/>
+ <menuItem title="Copy Style" keyEquivalent="c" id="5Vv-lz-BsD">
+ <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
+ <connections>
+ <action selector="copyFont:" target="-1" id="GJO-xA-L4q"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Paste Style" keyEquivalent="v" id="vKC-jM-MkH">
+ <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
+ <connections>
+ <action selector="pasteFont:" target="-1" id="JfD-CL-leO"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Text" id="Fal-I4-PZk">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Text" id="d9c-me-L2H">
+ <items>
+ <menuItem title="Align Left" keyEquivalent="{" id="ZM1-6Q-yy1">
+ <connections>
+ <action selector="alignLeft:" target="-1" id="zUv-R1-uAa"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Center" keyEquivalent="|" id="VIY-Ag-zcb">
+ <connections>
+ <action selector="alignCenter:" target="-1" id="spX-mk-kcS"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Justify" id="J5U-5w-g23">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="alignJustified:" target="-1" id="ljL-7U-jND"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Align Right" keyEquivalent="}" id="wb2-vD-lq4">
+ <connections>
+ <action selector="alignRight:" target="-1" id="r48-bG-YeY"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="4s2-GY-VfK"/>
+ <menuItem title="Writing Direction" id="H1b-Si-o9J">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Writing Direction" id="8mr-sm-Yjd">
+ <items>
+ <menuItem title="Paragraph" enabled="NO" id="ZvO-Gk-QUH">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ </menuItem>
+ <menuItem id="YGs-j5-SAR">
+ <string key="title"> Default</string>
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="makeBaseWritingDirectionNatural:" target="-1" id="qtV-5e-UBP"/>
+ </connections>
+ </menuItem>
+ <menuItem id="Lbh-J2-qVU">
+ <string key="title"> Left to Right</string>
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="makeBaseWritingDirectionLeftToRight:" target="-1" id="S0X-9S-QSf"/>
+ </connections>
+ </menuItem>
+ <menuItem id="jFq-tB-4Kx">
+ <string key="title"> Right to Left</string>
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="makeBaseWritingDirectionRightToLeft:" target="-1" id="5fk-qB-AqJ"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="swp-gr-a21"/>
+ <menuItem title="Selection" enabled="NO" id="cqv-fj-IhA">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ </menuItem>
+ <menuItem id="Nop-cj-93Q">
+ <string key="title"> Default</string>
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="makeTextWritingDirectionNatural:" target="-1" id="lPI-Se-ZHp"/>
+ </connections>
+ </menuItem>
+ <menuItem id="BgM-ve-c93">
+ <string key="title"> Left to Right</string>
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="makeTextWritingDirectionLeftToRight:" target="-1" id="caW-Bv-w94"/>
+ </connections>
+ </menuItem>
+ <menuItem id="RB4-Sm-HuC">
+ <string key="title"> Right to Left</string>
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="makeTextWritingDirectionRightToLeft:" target="-1" id="EXD-6r-ZUu"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="fKy-g9-1gm"/>
+ <menuItem title="Show Ruler" id="vLm-3I-IUL">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="toggleRuler:" target="-1" id="FOx-HJ-KwY"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Copy Ruler" keyEquivalent="c" id="MkV-Pr-PK5">
+ <modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
+ <connections>
+ <action selector="copyRuler:" target="-1" id="71i-fW-3W2"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Paste Ruler" keyEquivalent="v" id="LVM-kO-fVI">
+ <modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
+ <connections>
+ <action selector="pasteRuler:" target="-1" id="cSh-wd-qM2"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="View" id="H8h-7b-M4v">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="View" id="HyV-fh-RgO">
+ <items>
+ <menuItem title="Show Toolbar" keyEquivalent="t" id="snW-S8-Cw5">
+ <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
+ <connections>
+ <action selector="toggleToolbarShown:" target="-1" id="BXY-wc-z0C"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Customize Toolbar…" id="1UK-8n-QPP">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="runToolbarCustomizationPalette:" target="-1" id="pQI-g3-MTW"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Window" id="aUF-d1-5bR">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo">
+ <items>
+ <menuItem title="Minimize" keyEquivalent="m" id="OY7-WF-poV">
+ <connections>
+ <action selector="performMiniaturize:" target="-1" id="VwT-WD-YPe"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Zoom" id="R4o-n2-Eq4">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="performZoom:" target="-1" id="DIl-cC-cCs"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/>
+ <menuItem title="Bring All to Front" id="LE2-aR-0XJ">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="arrangeInFront:" target="-1" id="DRN-fu-gQh"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ <menuItem title="Help" id="wpr-3q-Mcd">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Help" systemMenu="help" id="F2S-fz-NVQ">
+ <items>
+ <menuItem title="OSXCocoaPodsTester Help" keyEquivalent="?" id="FKE-Sm-Kum">
+ <connections>
+ <action selector="showHelp:" target="-1" id="y7X-2Q-9no"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ </items>
+ </menu>
+ <window title="OSXCocoaPodsTester" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g">
+ <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
+ <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
+ <rect key="contentRect" x="335" y="390" width="480" height="360"/>
+ <rect key="screenRect" x="0.0" y="0.0" width="1920" height="1177"/>
+ <view key="contentView" id="EiT-Mj-1SZ">
+ <rect key="frame" x="0.0" y="0.0" width="480" height="360"/>
+ <autoresizingMask key="autoresizingMask"/>
+ </view>
+ </window>
+ </objects>
+</document>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Info.plist b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Info.plist
new file mode 100644
index 0000000000..ed806e40d6
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/Info.plist
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>$(EXECUTABLE_NAME)</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>$(PRODUCT_NAME)</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>LSMinimumSystemVersion</key>
+ <string>$(MACOSX_DEPLOYMENT_TARGET)</string>
+ <key>NSHumanReadableCopyright</key>
+ <string>Copyright © 2016 Google. All rights reserved.</string>
+ <key>NSMainNibFile</key>
+ <string>MainMenu</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+</dict>
+</plist>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/main.m b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/main.m
new file mode 100644
index 0000000000..b230090e5e
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/OSXCocoaPodsTester/main.m
@@ -0,0 +1,35 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Cocoa/Cocoa.h>
+
+int main(int argc, const char * argv[]) {
+ return NSApplicationMain(argc, argv);
+}
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-framework b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-framework
new file mode 100644
index 0000000000..27eeafc9c8
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-framework
@@ -0,0 +1,10 @@
+source 'https://github.com/CocoaPods/Specs.git'
+platform :osx, '10.9'
+
+install! 'cocoapods', :deterministic_uuids => false
+
+use_frameworks!
+
+target 'OSXCocoaPodsTester' do
+ pod 'Protobuf', :path => '../../../..'
+end
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-static b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-static
new file mode 100644
index 0000000000..5dfc8de578
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/OSXCocoaPodsTester/Podfile-static
@@ -0,0 +1,8 @@
+source 'https://github.com/CocoaPods/Specs.git'
+platform :osx, '10.9'
+
+install! 'cocoapods', :deterministic_uuids => false
+
+target 'OSXCocoaPodsTester' do
+ pod 'Protobuf', :path => '../../../..'
+end
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/README.md b/third_party/protobuf/objectivec/Tests/CocoaPods/README.md
new file mode 100644
index 0000000000..0878591886
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/README.md
@@ -0,0 +1,9 @@
+CocoaPods Protocol Buffers Integration Tests
+============================================
+
+The sub directories are the basic projects as created by Xcode 6.3. They are
+used to then drive `pod` and `xcodebuild` to ensure things integrate/build
+as expected.
+
+`run_tests.sh` defaults to running all the tests, invoke it with `--help` to
+see the arguments to control what tests are run.
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-framework b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-framework
new file mode 100644
index 0000000000..913a289b8e
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-framework
@@ -0,0 +1,10 @@
+source 'https://github.com/CocoaPods/Specs.git'
+platform :ios, '8.0'
+
+install! 'cocoapods', :deterministic_uuids => false
+
+use_frameworks!
+
+target 'iOSCocoaPodsTester' do
+ pod 'Protobuf', :path => '../../../..'
+end
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-static b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-static
new file mode 100644
index 0000000000..e9b3c235dd
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/Podfile-static
@@ -0,0 +1,8 @@
+source 'https://github.com/CocoaPods/Specs.git'
+platform :ios, '8.0'
+
+install! 'cocoapods', :deterministic_uuids => false
+
+target 'iOSCocoaPodsTester' do
+ pod 'Protobuf', :path => '../../../..'
+end
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.pbxproj b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.pbxproj
new file mode 100644
index 0000000000..27fb553fd4
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.pbxproj
@@ -0,0 +1,309 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 46;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ F4D5A08B1CEE01E200562D79 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F4D5A08A1CEE01E200562D79 /* main.m */; };
+ F4D5A08E1CEE01E200562D79 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F4D5A08D1CEE01E200562D79 /* AppDelegate.m */; };
+ F4D5A0911CEE01E200562D79 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F4D5A0901CEE01E200562D79 /* ViewController.m */; };
+ F4D5A0941CEE01E200562D79 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F4D5A0921CEE01E200562D79 /* Main.storyboard */; };
+ F4D5A0961CEE01E200562D79 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F4D5A0951CEE01E200562D79 /* Assets.xcassets */; };
+ F4D5A0991CEE01E200562D79 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F4D5A0971CEE01E200562D79 /* LaunchScreen.storyboard */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXFileReference section */
+ F4D5A0861CEE01E200562D79 /* iOSCocoaPodsTester.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iOSCocoaPodsTester.app; sourceTree = BUILT_PRODUCTS_DIR; };
+ F4D5A08A1CEE01E200562D79 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ F4D5A08C1CEE01E200562D79 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
+ F4D5A08D1CEE01E200562D79 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
+ F4D5A08F1CEE01E200562D79 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
+ F4D5A0901CEE01E200562D79 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
+ F4D5A0931CEE01E200562D79 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
+ F4D5A0951CEE01E200562D79 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
+ F4D5A0981CEE01E200562D79 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
+ F4D5A09A1CEE01E200562D79 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ F4D5A0831CEE01E200562D79 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ F4D5A07D1CEE01E200562D79 = {
+ isa = PBXGroup;
+ children = (
+ F4D5A0881CEE01E200562D79 /* iOSCocoaPodsTester */,
+ F4D5A0871CEE01E200562D79 /* Products */,
+ );
+ sourceTree = "<group>";
+ };
+ F4D5A0871CEE01E200562D79 /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ F4D5A0861CEE01E200562D79 /* iOSCocoaPodsTester.app */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ F4D5A0881CEE01E200562D79 /* iOSCocoaPodsTester */ = {
+ isa = PBXGroup;
+ children = (
+ F4D5A08C1CEE01E200562D79 /* AppDelegate.h */,
+ F4D5A08D1CEE01E200562D79 /* AppDelegate.m */,
+ F4D5A08F1CEE01E200562D79 /* ViewController.h */,
+ F4D5A0901CEE01E200562D79 /* ViewController.m */,
+ F4D5A0921CEE01E200562D79 /* Main.storyboard */,
+ F4D5A0951CEE01E200562D79 /* Assets.xcassets */,
+ F4D5A0971CEE01E200562D79 /* LaunchScreen.storyboard */,
+ F4D5A09A1CEE01E200562D79 /* Info.plist */,
+ F4D5A0891CEE01E200562D79 /* Supporting Files */,
+ );
+ path = iOSCocoaPodsTester;
+ sourceTree = "<group>";
+ };
+ F4D5A0891CEE01E200562D79 /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ F4D5A08A1CEE01E200562D79 /* main.m */,
+ );
+ name = "Supporting Files";
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ F4D5A0851CEE01E200562D79 /* iOSCocoaPodsTester */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = F4D5A09D1CEE01E200562D79 /* Build configuration list for PBXNativeTarget "iOSCocoaPodsTester" */;
+ buildPhases = (
+ F4D5A0821CEE01E200562D79 /* Sources */,
+ F4D5A0831CEE01E200562D79 /* Frameworks */,
+ F4D5A0841CEE01E200562D79 /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = iOSCocoaPodsTester;
+ productName = iOSCocoaPodsTester;
+ productReference = F4D5A0861CEE01E200562D79 /* iOSCocoaPodsTester.app */;
+ productType = "com.apple.product-type.application";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ F4D5A07E1CEE01E200562D79 /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0730;
+ ORGANIZATIONNAME = Google;
+ TargetAttributes = {
+ F4D5A0851CEE01E200562D79 = {
+ CreatedOnToolsVersion = 7.3.1;
+ };
+ };
+ };
+ buildConfigurationList = F4D5A0811CEE01E200562D79 /* Build configuration list for PBXProject "iOSCocoaPodsTester" */;
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ Base,
+ );
+ mainGroup = F4D5A07D1CEE01E200562D79;
+ productRefGroup = F4D5A0871CEE01E200562D79 /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ F4D5A0851CEE01E200562D79 /* iOSCocoaPodsTester */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXResourcesBuildPhase section */
+ F4D5A0841CEE01E200562D79 /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ F4D5A0991CEE01E200562D79 /* LaunchScreen.storyboard in Resources */,
+ F4D5A0961CEE01E200562D79 /* Assets.xcassets in Resources */,
+ F4D5A0941CEE01E200562D79 /* Main.storyboard in Resources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXResourcesBuildPhase section */
+
+/* Begin PBXSourcesBuildPhase section */
+ F4D5A0821CEE01E200562D79 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ F4D5A0911CEE01E200562D79 /* ViewController.m in Sources */,
+ F4D5A08E1CEE01E200562D79 /* AppDelegate.m in Sources */,
+ F4D5A08B1CEE01E200562D79 /* main.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin PBXVariantGroup section */
+ F4D5A0921CEE01E200562D79 /* Main.storyboard */ = {
+ isa = PBXVariantGroup;
+ children = (
+ F4D5A0931CEE01E200562D79 /* Base */,
+ );
+ name = Main.storyboard;
+ sourceTree = "<group>";
+ };
+ F4D5A0971CEE01E200562D79 /* LaunchScreen.storyboard */ = {
+ isa = PBXVariantGroup;
+ children = (
+ F4D5A0981CEE01E200562D79 /* Base */,
+ );
+ name = LaunchScreen.storyboard;
+ sourceTree = "<group>";
+ };
+/* End PBXVariantGroup section */
+
+/* Begin XCBuildConfiguration section */
+ F4D5A09B1CEE01E200562D79 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ COPY_PHASE_STRIP = NO;
+ DEBUG_INFORMATION_FORMAT = dwarf;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_TESTABILITY = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.3;
+ MTL_ENABLE_DEBUG_INFO = YES;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = iphoneos;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ };
+ name = Debug;
+ };
+ F4D5A09C1CEE01E200562D79 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ CLANG_ANALYZER_NONNULL = YES;
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_MODULES = YES;
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_UNREACHABLE_CODE = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ COPY_PHASE_STRIP = NO;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ ENABLE_NS_ASSERTIONS = NO;
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_NO_COMMON_BLOCKS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+ GCC_WARN_UNUSED_FUNCTION = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.3;
+ MTL_ENABLE_DEBUG_INFO = NO;
+ SDKROOT = iphoneos;
+ TARGETED_DEVICE_FAMILY = "1,2";
+ VALIDATE_PRODUCT = YES;
+ };
+ name = Release;
+ };
+ F4D5A09E1CEE01E200562D79 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ INFOPLIST_FILE = iOSCocoaPodsTester/Info.plist;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = com.google.iOSCocoaPodsTester;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Debug;
+ };
+ F4D5A09F1CEE01E200562D79 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
+ INFOPLIST_FILE = iOSCocoaPodsTester/Info.plist;
+ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = com.google.iOSCocoaPodsTester;
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ F4D5A0811CEE01E200562D79 /* Build configuration list for PBXProject "iOSCocoaPodsTester" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ F4D5A09B1CEE01E200562D79 /* Debug */,
+ F4D5A09C1CEE01E200562D79 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ F4D5A09D1CEE01E200562D79 /* Build configuration list for PBXNativeTarget "iOSCocoaPodsTester" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ F4D5A09E1CEE01E200562D79 /* Debug */,
+ F4D5A09F1CEE01E200562D79 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = F4D5A07E1CEE01E200562D79 /* Project object */;
+}
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata
new file mode 100644
index 0000000000..008f7b4a6f
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+ version = "1.0">
+ <FileRef
+ location = "self:iOSCocoaPodsTester.xcodeproj">
+ </FileRef>
+</Workspace>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/iOSCocoaPodsTester.xcscheme b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/iOSCocoaPodsTester.xcscheme
new file mode 100644
index 0000000000..9558dd7a17
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester.xcodeproj/xcshareddata/xcschemes/iOSCocoaPodsTester.xcscheme
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ LastUpgradeVersion = "0730"
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "YES">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4D5A0851CEE01E200562D79"
+ BuildableName = "iOSCocoaPodsTester.app"
+ BlueprintName = "iOSCocoaPodsTester"
+ ReferencedContainer = "container:iOSCocoaPodsTester.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ shouldUseLaunchSchemeArgsEnv = "YES">
+ <Testables>
+ </Testables>
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4D5A0851CEE01E200562D79"
+ BuildableName = "iOSCocoaPodsTester.app"
+ BlueprintName = "iOSCocoaPodsTester"
+ ReferencedContainer = "container:iOSCocoaPodsTester.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </TestAction>
+ <LaunchAction
+ buildConfiguration = "Debug"
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ ignoresPersistentStateOnLaunch = "NO"
+ debugDocumentVersioning = "YES"
+ debugServiceExtension = "internal"
+ allowLocationSimulation = "YES">
+ <BuildableProductRunnable
+ runnableDebuggingMode = "0">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4D5A0851CEE01E200562D79"
+ BuildableName = "iOSCocoaPodsTester.app"
+ BlueprintName = "iOSCocoaPodsTester"
+ ReferencedContainer = "container:iOSCocoaPodsTester.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ buildConfiguration = "Release"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ debugDocumentVersioning = "YES">
+ <BuildableProductRunnable
+ runnableDebuggingMode = "0">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "F4D5A0851CEE01E200562D79"
+ BuildableName = "iOSCocoaPodsTester.app"
+ BlueprintName = "iOSCocoaPodsTester"
+ ReferencedContainer = "container:iOSCocoaPodsTester.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Debug">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.h b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.h
new file mode 100644
index 0000000000..5eca690ca7
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.h
@@ -0,0 +1,39 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <UIKit/UIKit.h>
+
+@interface AppDelegate : UIResponder <UIApplicationDelegate>
+
+@property (strong, nonatomic) UIWindow *window;
+
+
+@end
+
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.m b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.m
new file mode 100644
index 0000000000..dd7b969af8
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/AppDelegate.m
@@ -0,0 +1,67 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "AppDelegate.h"
+
+@interface AppDelegate ()
+
+@end
+
+@implementation AppDelegate
+
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+ // Override point for customization after application launch.
+ return YES;
+}
+
+- (void)applicationWillResignActive:(UIApplication *)application {
+ // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
+ // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
+}
+
+- (void)applicationDidEnterBackground:(UIApplication *)application {
+ // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
+ // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
+}
+
+- (void)applicationWillEnterForeground:(UIApplication *)application {
+ // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
+}
+
+- (void)applicationDidBecomeActive:(UIApplication *)application {
+ // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
+}
+
+- (void)applicationWillTerminate:(UIApplication *)application {
+ // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json
new file mode 100644
index 0000000000..36d2c80d88
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Assets.xcassets/AppIcon.appiconset/Contents.json
@@ -0,0 +1,68 @@
+{
+ "images" : [
+ {
+ "idiom" : "iphone",
+ "size" : "29x29",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "29x29",
+ "scale" : "3x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "40x40",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "40x40",
+ "scale" : "3x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "60x60",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "60x60",
+ "scale" : "3x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "29x29",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "29x29",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "40x40",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "40x40",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "76x76",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "76x76",
+ "scale" : "2x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/LaunchScreen.storyboard b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/LaunchScreen.storyboard
new file mode 100644
index 0000000000..2e721e1833
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/LaunchScreen.storyboard
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
+ <dependencies>
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/>
+ </dependencies>
+ <scenes>
+ <!--View Controller-->
+ <scene sceneID="EHf-IW-A2E">
+ <objects>
+ <viewController id="01J-lp-oVM" sceneMemberID="viewController">
+ <layoutGuides>
+ <viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
+ <viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
+ </layoutGuides>
+ <view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
+ <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ <animations/>
+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
+ </view>
+ </viewController>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
+ </objects>
+ <point key="canvasLocation" x="53" y="375"/>
+ </scene>
+ </scenes>
+</document>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/Main.storyboard b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/Main.storyboard
new file mode 100644
index 0000000000..82cd159ae3
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Base.lproj/Main.storyboard
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
+ <dependencies>
+ <deployment identifier="iOS"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
+ </dependencies>
+ <scenes>
+ <!--View Controller-->
+ <scene sceneID="tne-QT-ifu">
+ <objects>
+ <viewController id="BYZ-38-t0r" customClass="ViewController" sceneMemberID="viewController">
+ <layoutGuides>
+ <viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
+ <viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
+ </layoutGuides>
+ <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
+ <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
+ </view>
+ </viewController>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
+ </objects>
+ </scene>
+ </scenes>
+</document>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Info.plist b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Info.plist
new file mode 100644
index 0000000000..40c6215d90
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/Info.plist
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleExecutable</key>
+ <string>$(EXECUTABLE_NAME)</string>
+ <key>CFBundleIdentifier</key>
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>$(PRODUCT_NAME)</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>UILaunchStoryboardName</key>
+ <string>LaunchScreen</string>
+ <key>UIMainStoryboardFile</key>
+ <string>Main</string>
+ <key>UIRequiredDeviceCapabilities</key>
+ <array>
+ <string>armv7</string>
+ </array>
+ <key>UISupportedInterfaceOrientations</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+ <key>UISupportedInterfaceOrientations~ipad</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationPortraitUpsideDown</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+</dict>
+</plist>
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.h b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.h
new file mode 100644
index 0000000000..777257b85a
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.h
@@ -0,0 +1,37 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <UIKit/UIKit.h>
+
+@interface ViewController : UIViewController
+
+
+@end
+
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.m b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.m
new file mode 100644
index 0000000000..c3b7e6c0cc
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/ViewController.m
@@ -0,0 +1,49 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "ViewController.h"
+
+@interface ViewController ()
+
+@end
+
+@implementation ViewController
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ // Do any additional setup after loading the view, typically from a nib.
+}
+
+- (void)didReceiveMemoryWarning {
+ [super didReceiveMemoryWarning];
+ // Dispose of any resources that can be recreated.
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/main.m b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/main.m
new file mode 100644
index 0000000000..4df0b769cf
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/iOSCocoaPodsTester/iOSCocoaPodsTester/main.m
@@ -0,0 +1,39 @@
+//
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <UIKit/UIKit.h>
+#import "AppDelegate.h"
+
+int main(int argc, char * argv[]) {
+ @autoreleasepool {
+ return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
+ }
+}
diff --git a/third_party/protobuf/objectivec/Tests/CocoaPods/run_tests.sh b/third_party/protobuf/objectivec/Tests/CocoaPods/run_tests.sh
new file mode 100755
index 0000000000..6d3e12be30
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/CocoaPods/run_tests.sh
@@ -0,0 +1,150 @@
+#!/bin/bash
+#
+# Helper to run the pods tests.
+
+set -eu
+
+readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
+
+printUsage() {
+ NAME=$(basename "${0}")
+ cat << EOF
+usage: ${NAME} [OPTIONS]
+
+This script runs some test to check the CocoaPods integration.
+
+OPTIONS:
+
+ General:
+
+ -h, --help
+ Show this message
+ --skip-static
+ Skip the static based pods tests.
+ --skip-framework
+ Skip the framework based pods tests.
+ --skip-ios
+ Skip the iOS pods tests.
+ --skip-osx
+ Skip the OS X pods tests.
+
+EOF
+}
+
+TEST_MODES=( "static" "framework" )
+TEST_NAMES=( "iOSCocoaPodsTester" "OSXCocoaPodsTester" )
+while [[ $# != 0 ]]; do
+ case "${1}" in
+ -h | --help )
+ printUsage
+ exit 0
+ ;;
+ --skip-static )
+ TEST_MODES=(${TEST_MODES[@]/static})
+ ;;
+ --skip-framework )
+ TEST_MODES=(${TEST_MODES[@]/framework})
+ ;;
+ --skip-ios )
+ TEST_NAMES=(${TEST_NAMES[@]/iOSCocoaPodsTester})
+ ;;
+ --skip-osx )
+ TEST_NAMES=(${TEST_NAMES[@]/OSXCocoaPodsTester})
+ ;;
+ -*)
+ echo "ERROR: Unknown option: ${1}" 1>&2
+ printUsage
+ exit 1
+ ;;
+ *)
+ echo "ERROR: Unknown argument: ${1}" 1>&2
+ printUsage
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+# Sanity check.
+if [[ "${#TEST_NAMES[@]}" == 0 ]] ; then
+ echo "ERROR: Need to run at least iOS or OS X tests." 1>&2
+ exit 2
+fi
+if [[ "${#TEST_MODES[@]}" == 0 ]] ; then
+ echo "ERROR: Need to run at least static or frameworks tests." 1>&2
+ exit 2
+fi
+
+header() {
+ echo ""
+ echo "========================================================================"
+ echo " ${@}"
+ echo "========================================================================"
+ echo ""
+}
+
+# Cleanup hook for do_test, assumes directory is correct.
+cleanup() {
+ local TEST_NAME="$1"
+
+ echo "Cleaning up..."
+
+ # Generally don't let things fail, and eat common stdout, but let stderr show
+ # incase something does hiccup.
+ xcodebuild -workspace "${TEST_NAME}.xcworkspace" -scheme "${TEST_NAME}" clean > /dev/null || true
+ pod deintegrate > /dev/null || true
+ # Flush the cache so nothing is left behind.
+ pod cache clean --all || true
+ # Delete the files left after pod deintegrate.
+ rm -f Podfile.lock || true
+ rm -rf "${TEST_NAME}.xcworkspace" || true
+ git checkout -- "${TEST_NAME}.xcodeproj" || true
+ # Remove the Podfile that was put in place.
+ rm -f Podfile || true
+}
+
+do_test() {
+ local TEST_NAME="$1"
+ local TEST_MODE="$2"
+
+ header "${TEST_NAME}" - Mode: "${TEST_MODE}"
+ cd "${ScriptDir}/${TEST_NAME}"
+
+ # Hook in cleanup for any failures.
+ trap "cleanup ${TEST_NAME}" EXIT
+
+ # Ensure nothing is cached by pods to start with that could throw things off.
+ pod cache clean --all
+
+ # Put the right Podfile in place.
+ cp -f "Podfile-${TEST_MODE}" "Podfile"
+
+ xcodebuild_args=( "-workspace" "${TEST_NAME}.xcworkspace" "-scheme" "${TEST_NAME}" )
+
+ # For iOS, if the SDK is not provided it tries to use iphoneos, and the test
+ # fail on Travis since those machines don't have a Code Signing identity.
+ if [[ "${TEST_NAME}" == iOS* ]] ; then
+ # Apparently the destination flag is required to avoid "Unsupported architecture"
+ # errors.
+ xcodebuild_args+=(
+ -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO
+ -destination "platform=iOS Simulator,name=iPad 2,OS=9.3"
+ )
+ fi
+
+ # Do the work!
+ pod install --verbose
+
+ xcodebuild "${xcodebuild_args[@]}" build
+
+ # Clear the hook and manually run cleanup.
+ trap - EXIT
+ cleanup "${TEST_NAME}"
+}
+
+# Run the tests.
+for TEST_NAME in "${TEST_NAMES[@]}" ; do
+ for TEST_MODE in "${TEST_MODES[@]}" ; do
+ do_test "${TEST_NAME}" "${TEST_MODE}"
+ done
+done
diff --git a/third_party/protobuf/objectivec/Tests/GPBARCUnittestProtos.m b/third_party/protobuf/objectivec/Tests/GPBARCUnittestProtos.m
new file mode 100644
index 0000000000..29f6ccf69a
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBARCUnittestProtos.m
@@ -0,0 +1,63 @@
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+// 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.
+
+// Makes sure all the generated headers compile with ARC on.
+
+// The unittest_custom_options.proto extends the messages in descriptor.proto
+// so we build it in to test extending in general. The library doesn't provide
+// a descriptor as it doesn't use the classes/enums.
+#import "google/protobuf/Descriptor.pbobjc.h"
+
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestCustomOptions.pbobjc.h"
+#import "google/protobuf/UnittestCycle.pbobjc.h"
+#import "google/protobuf/UnittestDeprecated.pbobjc.h"
+#import "google/protobuf/UnittestDeprecatedFile.pbobjc.h"
+#import "google/protobuf/UnittestDropUnknownFields.pbobjc.h"
+#import "google/protobuf/UnittestEmbedOptimizeFor.pbobjc.h"
+#import "google/protobuf/UnittestEmpty.pbobjc.h"
+#import "google/protobuf/UnittestEnormousDescriptor.pbobjc.h"
+#import "google/protobuf/UnittestImport.pbobjc.h"
+#import "google/protobuf/UnittestImportLite.pbobjc.h"
+#import "google/protobuf/UnittestImportPublic.pbobjc.h"
+#import "google/protobuf/UnittestImportPublicLite.pbobjc.h"
+#import "google/protobuf/UnittestLite.pbobjc.h"
+#import "google/protobuf/UnittestMset.pbobjc.h"
+#import "google/protobuf/UnittestNoGenericServices.pbobjc.h"
+#import "google/protobuf/UnittestObjc.pbobjc.h"
+#import "google/protobuf/UnittestObjcStartup.pbobjc.h"
+#import "google/protobuf/UnittestOptimizeFor.pbobjc.h"
+#import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h"
diff --git a/third_party/protobuf/objectivec/Tests/GPBArrayTests.m b/third_party/protobuf/objectivec/Tests/GPBArrayTests.m
new file mode 100644
index 0000000000..31f75501dc
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBArrayTests.m
@@ -0,0 +1,3611 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+#import <XCTest/XCTest.h>
+
+#import "GPBArray.h"
+#import "GPBArray_PackagePrivate.h"
+
+#import "GPBTestUtilities.h"
+
+// To let the testing macros work, add some extra methods to simplify things.
+@interface GPBEnumArray (TestingTweak)
++ (instancetype)arrayWithValue:(int32_t)value;
+- (instancetype)initWithValues:(const int32_t [])values
+ count:(NSUInteger)count;
+@end
+
+static BOOL TestingEnum_IsValidValue(int32_t value) {
+ switch (value) {
+ case 71:
+ case 72:
+ case 73:
+ case 74:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+static BOOL TestingEnum_IsValidValue2(int32_t value) {
+ switch (value) {
+ case 71:
+ case 72:
+ case 73:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+@implementation GPBEnumArray (TestingTweak)
++ (instancetype)arrayWithValue:(int32_t)value {
+ return [[[self alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:&value
+ count:1] autorelease];
+}
+- (instancetype)initWithValues:(const int32_t [])values
+ count:(NSUInteger)count {
+ return [self initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:values
+ count:count];
+}
+@end
+
+#pragma mark - PDDM Macros
+
+//%PDDM-DEFINE ARRAY_TESTS(NAME, TYPE, VAL1, VAL2, VAL3, VAL4)
+//%ARRAY_TESTS2(NAME, TYPE, VAL1, VAL2, VAL3, VAL4, )
+//%PDDM-DEFINE ARRAY_TESTS2(NAME, TYPE, VAL1, VAL2, VAL3, VAL4, HELPER)
+//%#pragma mark - NAME
+//%
+//%@interface GPB##NAME##ArrayTests : XCTestCase
+//%@end
+//%
+//%@implementation GPB##NAME##ArrayTests
+//%
+//%- (void)testEmpty {
+//% GPB##NAME##Array *array = [[GPB##NAME##Array alloc] init];
+//% XCTAssertNotNil(array);
+//% XCTAssertEqual(array.count, 0U);
+//% XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+//% [array enumerateValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//% #pragma unused(value, idx, stop)
+//% XCTFail(@"Shouldn't get here!");
+//% }];
+//% [array enumerateValuesWithOptions:NSEnumerationReverse
+//% usingBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//% #pragma unused(value, idx, stop)
+//% XCTFail(@"Shouldn't get here!");
+//% }];
+//% [array release];
+//%}
+//%
+//%- (void)testOne {
+//% GPB##NAME##Array *array = [GPB##NAME##Array arrayWithValue:VAL1];
+//% XCTAssertNotNil(array);
+//% XCTAssertEqual(array.count, 1U);
+//% XCTAssertEqual([array valueAtIndex:0], VAL1);
+//% XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+//% [array enumerateValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//% XCTAssertEqual(idx, 0U);
+//% XCTAssertEqual(value, VAL1);
+//% XCTAssertNotEqual(stop, NULL);
+//% }];
+//% [array enumerateValuesWithOptions:NSEnumerationReverse
+//% usingBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//% XCTAssertEqual(idx, 0U);
+//% XCTAssertEqual(value, VAL1);
+//% XCTAssertNotEqual(stop, NULL);
+//% }];
+//%}
+//%
+//%- (void)testBasics {
+//% static const TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 };
+//% GPB##NAME##Array *array =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues
+//% NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(array);
+//% XCTAssertEqual(array.count, 4U);
+//% XCTAssertEqual([array valueAtIndex:0], VAL1);
+//% XCTAssertEqual([array valueAtIndex:1], VAL2);
+//% XCTAssertEqual([array valueAtIndex:2], VAL3);
+//% XCTAssertEqual([array valueAtIndex:3], VAL4);
+//% XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+//% __block NSUInteger idx2 = 0;
+//% [array enumerateValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//% XCTAssertEqual(idx, idx2);
+//% XCTAssertEqual(value, kValues[idx]);
+//% XCTAssertNotEqual(stop, NULL);
+//% ++idx2;
+//% }];
+//% idx2 = 0;
+//% [array enumerateValuesWithOptions:NSEnumerationReverse
+//% usingBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//% XCTAssertEqual(idx, (3 - idx2));
+//% XCTAssertEqual(value, kValues[idx]);
+//% XCTAssertNotEqual(stop, NULL);
+//% ++idx2;
+//% }];
+//% // Stopping the enumeration.
+//% idx2 = 0;
+//% [array enumerateValuesWithBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//% XCTAssertEqual(idx, idx2);
+//% XCTAssertEqual(value, kValues[idx]);
+//% XCTAssertNotEqual(stop, NULL);
+//% if (idx2 == 1) *stop = YES;
+//% XCTAssertNotEqual(idx, 2U);
+//% XCTAssertNotEqual(idx, 3U);
+//% ++idx2;
+//% }];
+//% idx2 = 0;
+//% [array enumerateValuesWithOptions:NSEnumerationReverse
+//% usingBlock:^(TYPE value, NSUInteger idx, BOOL *stop) {
+//% XCTAssertEqual(idx, (3 - idx2));
+//% XCTAssertEqual(value, kValues[idx]);
+//% XCTAssertNotEqual(stop, NULL);
+//% if (idx2 == 1) *stop = YES;
+//% XCTAssertNotEqual(idx, 1U);
+//% XCTAssertNotEqual(idx, 0U);
+//% ++idx2;
+//% }];
+//% [array release];
+//%}
+//%
+//%- (void)testEquality {
+//% const TYPE kValues1[] = { VAL1, VAL2, VAL3 };
+//% const TYPE kValues2[] = { VAL1, VAL4, VAL3 };
+//% const TYPE kValues3[] = { VAL1, VAL2, VAL3, VAL4 };
+//% GPB##NAME##Array *array1 =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues1
+//% NAME$S count:GPBARRAYSIZE(kValues1)];
+//% XCTAssertNotNil(array1);
+//% GPB##NAME##Array *array1prime =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues1
+//% NAME$S count:GPBARRAYSIZE(kValues1)];
+//% XCTAssertNotNil(array1prime);
+//% GPB##NAME##Array *array2 =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues2
+//% NAME$S count:GPBARRAYSIZE(kValues2)];
+//% XCTAssertNotNil(array2);
+//% GPB##NAME##Array *array3 =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues3
+//% NAME$S count:GPBARRAYSIZE(kValues3)];
+//% XCTAssertNotNil(array3);
+//%
+//% // 1/1Prime should be different objects, but equal.
+//% XCTAssertNotEqual(array1, array1prime);
+//% XCTAssertEqualObjects(array1, array1prime);
+//% // Equal, so they must have same hash.
+//% XCTAssertEqual([array1 hash], [array1prime hash]);
+//%
+//% // 1/2/3 shouldn't be equal.
+//% XCTAssertNotEqualObjects(array1, array2);
+//% XCTAssertNotEqualObjects(array1, array3);
+//% XCTAssertNotEqualObjects(array2, array3);
+//%
+//% [array1 release];
+//% [array1prime release];
+//% [array2 release];
+//% [array3 release];
+//%}
+//%
+//%- (void)testCopy {
+//% const TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 };
+//% GPB##NAME##Array *array =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues
+//% NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(array);
+//%
+//% GPB##NAME##Array *array2 = [array copy];
+//% XCTAssertNotNil(array2);
+//%
+//% // Should be new object but equal.
+//% XCTAssertNotEqual(array, array2);
+//% XCTAssertEqualObjects(array, array2);
+//% [array2 release];
+//% [array release];
+//%}
+//%
+//%- (void)testArrayFromArray {
+//% const TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 };
+//% GPB##NAME##Array *array =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues
+//% NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(array);
+//%
+//% GPB##NAME##Array *array2 = [GPB##NAME##Array arrayWithValueArray:array];
+//% XCTAssertNotNil(array2);
+//%
+//% // Should be new pointer, but equal objects.
+//% XCTAssertNotEqual(array, array2);
+//% XCTAssertEqualObjects(array, array2);
+//% [array release];
+//%}
+//%
+//%- (void)testAdds {
+//% GPB##NAME##Array *array = [GPB##NAME##Array array];
+//% XCTAssertNotNil(array);
+//%
+//% XCTAssertEqual(array.count, 0U);
+//% [array addValue:VAL1];
+//% XCTAssertEqual(array.count, 1U);
+//%
+//% const TYPE kValues1[] = { VAL2, VAL3 };
+//% [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+//% XCTAssertEqual(array.count, 3U);
+//%
+//% const TYPE kValues2[] = { VAL4, VAL1 };
+//% GPB##NAME##Array *array2 =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues2
+//% NAME$S count:GPBARRAYSIZE(kValues2)];
+//% XCTAssertNotNil(array2);
+//% [array add##HELPER##ValuesFromArray:array2];
+//% XCTAssertEqual(array.count, 5U);
+//%
+//% XCTAssertEqual([array valueAtIndex:0], VAL1);
+//% XCTAssertEqual([array valueAtIndex:1], VAL2);
+//% XCTAssertEqual([array valueAtIndex:2], VAL3);
+//% XCTAssertEqual([array valueAtIndex:3], VAL4);
+//% XCTAssertEqual([array valueAtIndex:4], VAL1);
+//% [array2 release];
+//%}
+//%
+//%- (void)testInsert {
+//% const TYPE kValues[] = { VAL1, VAL2, VAL3 };
+//% GPB##NAME##Array *array =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues
+//% NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(array);
+//% XCTAssertEqual(array.count, 3U);
+//%
+//% // First
+//% [array insertValue:VAL4 atIndex:0];
+//% XCTAssertEqual(array.count, 4U);
+//%
+//% // Middle
+//% [array insertValue:VAL4 atIndex:2];
+//% XCTAssertEqual(array.count, 5U);
+//%
+//% // End
+//% [array insertValue:VAL4 atIndex:5];
+//% XCTAssertEqual(array.count, 6U);
+//%
+//% // Too far.
+//% XCTAssertThrowsSpecificNamed([array insertValue:VAL4 atIndex:7],
+//% NSException, NSRangeException);
+//%
+//% XCTAssertEqual([array valueAtIndex:0], VAL4);
+//% XCTAssertEqual([array valueAtIndex:1], VAL1);
+//% XCTAssertEqual([array valueAtIndex:2], VAL4);
+//% XCTAssertEqual([array valueAtIndex:3], VAL2);
+//% XCTAssertEqual([array valueAtIndex:4], VAL3);
+//% XCTAssertEqual([array valueAtIndex:5], VAL4);
+//% [array release];
+//%}
+//%
+//%- (void)testRemove {
+//% const TYPE kValues[] = { VAL4, VAL1, VAL2, VAL4, VAL3, VAL4 };
+//% GPB##NAME##Array *array =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues
+//% NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(array);
+//% XCTAssertEqual(array.count, 6U);
+//%
+//% // First
+//% [array removeValueAtIndex:0];
+//% XCTAssertEqual(array.count, 5U);
+//% XCTAssertEqual([array valueAtIndex:0], VAL1);
+//%
+//% // Middle
+//% [array removeValueAtIndex:2];
+//% XCTAssertEqual(array.count, 4U);
+//% XCTAssertEqual([array valueAtIndex:2], VAL3);
+//%
+//% // End
+//% [array removeValueAtIndex:3];
+//% XCTAssertEqual(array.count, 3U);
+//%
+//% XCTAssertEqual([array valueAtIndex:0], VAL1);
+//% XCTAssertEqual([array valueAtIndex:1], VAL2);
+//% XCTAssertEqual([array valueAtIndex:2], VAL3);
+//%
+//% // Too far.
+//% XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+//% NSException, NSRangeException);
+//%
+//% [array removeAll];
+//% XCTAssertEqual(array.count, 0U);
+//% XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+//% NSException, NSRangeException);
+//% [array release];
+//%}
+//%
+//%- (void)testInplaceMutation {
+//% const TYPE kValues[] = { VAL1, VAL1, VAL3, VAL3 };
+//% GPB##NAME##Array *array =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues
+//% NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(array);
+//%
+//% [array replaceValueAtIndex:1 withValue:VAL2];
+//% [array replaceValueAtIndex:3 withValue:VAL4];
+//% XCTAssertEqual(array.count, 4U);
+//% XCTAssertEqual([array valueAtIndex:0], VAL1);
+//% XCTAssertEqual([array valueAtIndex:1], VAL2);
+//% XCTAssertEqual([array valueAtIndex:2], VAL3);
+//% XCTAssertEqual([array valueAtIndex:3], VAL4);
+//%
+//% XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:VAL4],
+//% NSException, NSRangeException);
+//%
+//% [array exchangeValueAtIndex:1 withValueAtIndex:3];
+//% XCTAssertEqual(array.count, 4U);
+//% XCTAssertEqual([array valueAtIndex:0], VAL1);
+//% XCTAssertEqual([array valueAtIndex:1], VAL4);
+//% XCTAssertEqual([array valueAtIndex:2], VAL3);
+//% XCTAssertEqual([array valueAtIndex:3], VAL2);
+//%
+//% [array exchangeValueAtIndex:2 withValueAtIndex:0];
+//% XCTAssertEqual(array.count, 4U);
+//% XCTAssertEqual([array valueAtIndex:0], VAL3);
+//% XCTAssertEqual([array valueAtIndex:1], VAL4);
+//% XCTAssertEqual([array valueAtIndex:2], VAL1);
+//% XCTAssertEqual([array valueAtIndex:3], VAL2);
+//%
+//% XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+//% NSException, NSRangeException);
+//% XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+//% NSException, NSRangeException);
+//% [array release];
+//%}
+//%
+//%- (void)testInternalResizing {
+//% const TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 };
+//% GPB##NAME##Array *array =
+//% [[GPB##NAME##Array alloc] initWithValues:kValues
+//% NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(array);
+//%
+//% // Add/remove to trigger the intneral buffer to grow/shrink.
+//% for (int i = 0; i < 100; ++i) {
+//% [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+//% }
+//% XCTAssertEqual(array.count, 404U);
+//% for (int i = 0; i < 100; ++i) {
+//% [array removeValueAtIndex:(i * 2)];
+//% }
+//% XCTAssertEqual(array.count, 304U);
+//% for (int i = 0; i < 100; ++i) {
+//% [array insertValue:VAL4 atIndex:(i * 3)];
+//% }
+//% XCTAssertEqual(array.count, 404U);
+//% [array removeAll];
+//% XCTAssertEqual(array.count, 0U);
+//% [array release];
+//%}
+//%
+//%@end
+//%
+//%PDDM-EXPAND ARRAY_TESTS(Int32, int32_t, 1, 2, 3, 4)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Int32
+
+@interface GPBInt32ArrayTests : XCTestCase
+@end
+
+@implementation GPBInt32ArrayTests
+
+- (void)testEmpty {
+ GPBInt32Array *array = [[GPBInt32Array alloc] init];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array release];
+}
+
+- (void)testOne {
+ GPBInt32Array *array = [GPBInt32Array arrayWithValue:1];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 1U);
+ XCTAssertEqual([array valueAtIndex:0], 1);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 1);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 1);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ static const int32_t kValues[] = { 1, 2, 3, 4 };
+ GPBInt32Array *array =
+ [[GPBInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 1);
+ XCTAssertEqual([array valueAtIndex:1], 2);
+ XCTAssertEqual([array valueAtIndex:2], 3);
+ XCTAssertEqual([array valueAtIndex:3], 4);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const int32_t kValues1[] = { 1, 2, 3 };
+ const int32_t kValues2[] = { 1, 4, 3 };
+ const int32_t kValues3[] = { 1, 2, 3, 4 };
+ GPBInt32Array *array1 =
+ [[GPBInt32Array alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBInt32Array *array1prime =
+ [[GPBInt32Array alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBInt32Array *array2 =
+ [[GPBInt32Array alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBInt32Array *array3 =
+ [[GPBInt32Array alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const int32_t kValues[] = { 1, 2, 3, 4 };
+ GPBInt32Array *array =
+ [[GPBInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBInt32Array *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const int32_t kValues[] = { 1, 2, 3, 4 };
+ GPBInt32Array *array =
+ [[GPBInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBInt32Array *array2 = [GPBInt32Array arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array release];
+}
+
+- (void)testAdds {
+ GPBInt32Array *array = [GPBInt32Array array];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addValue:1];
+ XCTAssertEqual(array.count, 1U);
+
+ const int32_t kValues1[] = { 2, 3 };
+ [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const int32_t kValues2[] = { 4, 1 };
+ GPBInt32Array *array2 =
+ [[GPBInt32Array alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array valueAtIndex:0], 1);
+ XCTAssertEqual([array valueAtIndex:1], 2);
+ XCTAssertEqual([array valueAtIndex:2], 3);
+ XCTAssertEqual([array valueAtIndex:3], 4);
+ XCTAssertEqual([array valueAtIndex:4], 1);
+ [array2 release];
+}
+
+- (void)testInsert {
+ const int32_t kValues[] = { 1, 2, 3 };
+ GPBInt32Array *array =
+ [[GPBInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertValue:4 atIndex:0];
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertValue:4 atIndex:2];
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertValue:4 atIndex:5];
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertValue:4 atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array valueAtIndex:0], 4);
+ XCTAssertEqual([array valueAtIndex:1], 1);
+ XCTAssertEqual([array valueAtIndex:2], 4);
+ XCTAssertEqual([array valueAtIndex:3], 2);
+ XCTAssertEqual([array valueAtIndex:4], 3);
+ XCTAssertEqual([array valueAtIndex:5], 4);
+ [array release];
+}
+
+- (void)testRemove {
+ const int32_t kValues[] = { 4, 1, 2, 4, 3, 4 };
+ GPBInt32Array *array =
+ [[GPBInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 6U);
+
+ // First
+ [array removeValueAtIndex:0];
+ XCTAssertEqual(array.count, 5U);
+ XCTAssertEqual([array valueAtIndex:0], 1);
+
+ // Middle
+ [array removeValueAtIndex:2];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:2], 3);
+
+ // End
+ [array removeValueAtIndex:3];
+ XCTAssertEqual(array.count, 3U);
+
+ XCTAssertEqual([array valueAtIndex:0], 1);
+ XCTAssertEqual([array valueAtIndex:1], 2);
+ XCTAssertEqual([array valueAtIndex:2], 3);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+ NSException, NSRangeException);
+
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kValues[] = { 1, 1, 3, 3 };
+ GPBInt32Array *array =
+ [[GPBInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withValue:2];
+ [array replaceValueAtIndex:3 withValue:4];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 1);
+ XCTAssertEqual([array valueAtIndex:1], 2);
+ XCTAssertEqual([array valueAtIndex:2], 3);
+ XCTAssertEqual([array valueAtIndex:3], 4);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:4],
+ NSException, NSRangeException);
+
+ [array exchangeValueAtIndex:1 withValueAtIndex:3];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 1);
+ XCTAssertEqual([array valueAtIndex:1], 4);
+ XCTAssertEqual([array valueAtIndex:2], 3);
+ XCTAssertEqual([array valueAtIndex:3], 2);
+
+ [array exchangeValueAtIndex:2 withValueAtIndex:0];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 3);
+ XCTAssertEqual([array valueAtIndex:1], 4);
+ XCTAssertEqual([array valueAtIndex:2], 1);
+ XCTAssertEqual([array valueAtIndex:3], 2);
+
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+ NSException, NSRangeException);
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInternalResizing {
+ const int32_t kValues[] = { 1, 2, 3, 4 };
+ GPBInt32Array *array =
+ [[GPBInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertValue:4 atIndex:(i * 3)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_TESTS(UInt32, uint32_t, 11U, 12U, 13U, 14U)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - UInt32
+
+@interface GPBUInt32ArrayTests : XCTestCase
+@end
+
+@implementation GPBUInt32ArrayTests
+
+- (void)testEmpty {
+ GPBUInt32Array *array = [[GPBUInt32Array alloc] init];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array release];
+}
+
+- (void)testOne {
+ GPBUInt32Array *array = [GPBUInt32Array arrayWithValue:11U];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 1U);
+ XCTAssertEqual([array valueAtIndex:0], 11U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 11U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 11U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ static const uint32_t kValues[] = { 11U, 12U, 13U, 14U };
+ GPBUInt32Array *array =
+ [[GPBUInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 11U);
+ XCTAssertEqual([array valueAtIndex:1], 12U);
+ XCTAssertEqual([array valueAtIndex:2], 13U);
+ XCTAssertEqual([array valueAtIndex:3], 14U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(uint32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const uint32_t kValues1[] = { 11U, 12U, 13U };
+ const uint32_t kValues2[] = { 11U, 14U, 13U };
+ const uint32_t kValues3[] = { 11U, 12U, 13U, 14U };
+ GPBUInt32Array *array1 =
+ [[GPBUInt32Array alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBUInt32Array *array1prime =
+ [[GPBUInt32Array alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBUInt32Array *array2 =
+ [[GPBUInt32Array alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBUInt32Array *array3 =
+ [[GPBUInt32Array alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const uint32_t kValues[] = { 11U, 12U, 13U, 14U };
+ GPBUInt32Array *array =
+ [[GPBUInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBUInt32Array *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const uint32_t kValues[] = { 11U, 12U, 13U, 14U };
+ GPBUInt32Array *array =
+ [[GPBUInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBUInt32Array *array2 = [GPBUInt32Array arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array release];
+}
+
+- (void)testAdds {
+ GPBUInt32Array *array = [GPBUInt32Array array];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addValue:11U];
+ XCTAssertEqual(array.count, 1U);
+
+ const uint32_t kValues1[] = { 12U, 13U };
+ [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const uint32_t kValues2[] = { 14U, 11U };
+ GPBUInt32Array *array2 =
+ [[GPBUInt32Array alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array valueAtIndex:0], 11U);
+ XCTAssertEqual([array valueAtIndex:1], 12U);
+ XCTAssertEqual([array valueAtIndex:2], 13U);
+ XCTAssertEqual([array valueAtIndex:3], 14U);
+ XCTAssertEqual([array valueAtIndex:4], 11U);
+ [array2 release];
+}
+
+- (void)testInsert {
+ const uint32_t kValues[] = { 11U, 12U, 13U };
+ GPBUInt32Array *array =
+ [[GPBUInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertValue:14U atIndex:0];
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertValue:14U atIndex:2];
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertValue:14U atIndex:5];
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertValue:14U atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array valueAtIndex:0], 14U);
+ XCTAssertEqual([array valueAtIndex:1], 11U);
+ XCTAssertEqual([array valueAtIndex:2], 14U);
+ XCTAssertEqual([array valueAtIndex:3], 12U);
+ XCTAssertEqual([array valueAtIndex:4], 13U);
+ XCTAssertEqual([array valueAtIndex:5], 14U);
+ [array release];
+}
+
+- (void)testRemove {
+ const uint32_t kValues[] = { 14U, 11U, 12U, 14U, 13U, 14U };
+ GPBUInt32Array *array =
+ [[GPBUInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 6U);
+
+ // First
+ [array removeValueAtIndex:0];
+ XCTAssertEqual(array.count, 5U);
+ XCTAssertEqual([array valueAtIndex:0], 11U);
+
+ // Middle
+ [array removeValueAtIndex:2];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:2], 13U);
+
+ // End
+ [array removeValueAtIndex:3];
+ XCTAssertEqual(array.count, 3U);
+
+ XCTAssertEqual([array valueAtIndex:0], 11U);
+ XCTAssertEqual([array valueAtIndex:1], 12U);
+ XCTAssertEqual([array valueAtIndex:2], 13U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+ NSException, NSRangeException);
+
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kValues[] = { 11U, 11U, 13U, 13U };
+ GPBUInt32Array *array =
+ [[GPBUInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withValue:12U];
+ [array replaceValueAtIndex:3 withValue:14U];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 11U);
+ XCTAssertEqual([array valueAtIndex:1], 12U);
+ XCTAssertEqual([array valueAtIndex:2], 13U);
+ XCTAssertEqual([array valueAtIndex:3], 14U);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:14U],
+ NSException, NSRangeException);
+
+ [array exchangeValueAtIndex:1 withValueAtIndex:3];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 11U);
+ XCTAssertEqual([array valueAtIndex:1], 14U);
+ XCTAssertEqual([array valueAtIndex:2], 13U);
+ XCTAssertEqual([array valueAtIndex:3], 12U);
+
+ [array exchangeValueAtIndex:2 withValueAtIndex:0];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 13U);
+ XCTAssertEqual([array valueAtIndex:1], 14U);
+ XCTAssertEqual([array valueAtIndex:2], 11U);
+ XCTAssertEqual([array valueAtIndex:3], 12U);
+
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+ NSException, NSRangeException);
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInternalResizing {
+ const uint32_t kValues[] = { 11U, 12U, 13U, 14U };
+ GPBUInt32Array *array =
+ [[GPBUInt32Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertValue:14U atIndex:(i * 3)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_TESTS(Int64, int64_t, 31LL, 32LL, 33LL, 34LL)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Int64
+
+@interface GPBInt64ArrayTests : XCTestCase
+@end
+
+@implementation GPBInt64ArrayTests
+
+- (void)testEmpty {
+ GPBInt64Array *array = [[GPBInt64Array alloc] init];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array release];
+}
+
+- (void)testOne {
+ GPBInt64Array *array = [GPBInt64Array arrayWithValue:31LL];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 1U);
+ XCTAssertEqual([array valueAtIndex:0], 31LL);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 31LL);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 31LL);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ static const int64_t kValues[] = { 31LL, 32LL, 33LL, 34LL };
+ GPBInt64Array *array =
+ [[GPBInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 31LL);
+ XCTAssertEqual([array valueAtIndex:1], 32LL);
+ XCTAssertEqual([array valueAtIndex:2], 33LL);
+ XCTAssertEqual([array valueAtIndex:3], 34LL);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const int64_t kValues1[] = { 31LL, 32LL, 33LL };
+ const int64_t kValues2[] = { 31LL, 34LL, 33LL };
+ const int64_t kValues3[] = { 31LL, 32LL, 33LL, 34LL };
+ GPBInt64Array *array1 =
+ [[GPBInt64Array alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBInt64Array *array1prime =
+ [[GPBInt64Array alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBInt64Array *array2 =
+ [[GPBInt64Array alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBInt64Array *array3 =
+ [[GPBInt64Array alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const int64_t kValues[] = { 31LL, 32LL, 33LL, 34LL };
+ GPBInt64Array *array =
+ [[GPBInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBInt64Array *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const int64_t kValues[] = { 31LL, 32LL, 33LL, 34LL };
+ GPBInt64Array *array =
+ [[GPBInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBInt64Array *array2 = [GPBInt64Array arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array release];
+}
+
+- (void)testAdds {
+ GPBInt64Array *array = [GPBInt64Array array];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addValue:31LL];
+ XCTAssertEqual(array.count, 1U);
+
+ const int64_t kValues1[] = { 32LL, 33LL };
+ [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const int64_t kValues2[] = { 34LL, 31LL };
+ GPBInt64Array *array2 =
+ [[GPBInt64Array alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array valueAtIndex:0], 31LL);
+ XCTAssertEqual([array valueAtIndex:1], 32LL);
+ XCTAssertEqual([array valueAtIndex:2], 33LL);
+ XCTAssertEqual([array valueAtIndex:3], 34LL);
+ XCTAssertEqual([array valueAtIndex:4], 31LL);
+ [array2 release];
+}
+
+- (void)testInsert {
+ const int64_t kValues[] = { 31LL, 32LL, 33LL };
+ GPBInt64Array *array =
+ [[GPBInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertValue:34LL atIndex:0];
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertValue:34LL atIndex:2];
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertValue:34LL atIndex:5];
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertValue:34LL atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array valueAtIndex:0], 34LL);
+ XCTAssertEqual([array valueAtIndex:1], 31LL);
+ XCTAssertEqual([array valueAtIndex:2], 34LL);
+ XCTAssertEqual([array valueAtIndex:3], 32LL);
+ XCTAssertEqual([array valueAtIndex:4], 33LL);
+ XCTAssertEqual([array valueAtIndex:5], 34LL);
+ [array release];
+}
+
+- (void)testRemove {
+ const int64_t kValues[] = { 34LL, 31LL, 32LL, 34LL, 33LL, 34LL };
+ GPBInt64Array *array =
+ [[GPBInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 6U);
+
+ // First
+ [array removeValueAtIndex:0];
+ XCTAssertEqual(array.count, 5U);
+ XCTAssertEqual([array valueAtIndex:0], 31LL);
+
+ // Middle
+ [array removeValueAtIndex:2];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:2], 33LL);
+
+ // End
+ [array removeValueAtIndex:3];
+ XCTAssertEqual(array.count, 3U);
+
+ XCTAssertEqual([array valueAtIndex:0], 31LL);
+ XCTAssertEqual([array valueAtIndex:1], 32LL);
+ XCTAssertEqual([array valueAtIndex:2], 33LL);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+ NSException, NSRangeException);
+
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kValues[] = { 31LL, 31LL, 33LL, 33LL };
+ GPBInt64Array *array =
+ [[GPBInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withValue:32LL];
+ [array replaceValueAtIndex:3 withValue:34LL];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 31LL);
+ XCTAssertEqual([array valueAtIndex:1], 32LL);
+ XCTAssertEqual([array valueAtIndex:2], 33LL);
+ XCTAssertEqual([array valueAtIndex:3], 34LL);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:34LL],
+ NSException, NSRangeException);
+
+ [array exchangeValueAtIndex:1 withValueAtIndex:3];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 31LL);
+ XCTAssertEqual([array valueAtIndex:1], 34LL);
+ XCTAssertEqual([array valueAtIndex:2], 33LL);
+ XCTAssertEqual([array valueAtIndex:3], 32LL);
+
+ [array exchangeValueAtIndex:2 withValueAtIndex:0];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 33LL);
+ XCTAssertEqual([array valueAtIndex:1], 34LL);
+ XCTAssertEqual([array valueAtIndex:2], 31LL);
+ XCTAssertEqual([array valueAtIndex:3], 32LL);
+
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+ NSException, NSRangeException);
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInternalResizing {
+ const int64_t kValues[] = { 31LL, 32LL, 33LL, 34LL };
+ GPBInt64Array *array =
+ [[GPBInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertValue:34LL atIndex:(i * 3)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_TESTS(UInt64, uint64_t, 41ULL, 42ULL, 43ULL, 44ULL)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - UInt64
+
+@interface GPBUInt64ArrayTests : XCTestCase
+@end
+
+@implementation GPBUInt64ArrayTests
+
+- (void)testEmpty {
+ GPBUInt64Array *array = [[GPBUInt64Array alloc] init];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array release];
+}
+
+- (void)testOne {
+ GPBUInt64Array *array = [GPBUInt64Array arrayWithValue:41ULL];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 1U);
+ XCTAssertEqual([array valueAtIndex:0], 41ULL);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 41ULL);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 41ULL);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ static const uint64_t kValues[] = { 41ULL, 42ULL, 43ULL, 44ULL };
+ GPBUInt64Array *array =
+ [[GPBUInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 41ULL);
+ XCTAssertEqual([array valueAtIndex:1], 42ULL);
+ XCTAssertEqual([array valueAtIndex:2], 43ULL);
+ XCTAssertEqual([array valueAtIndex:3], 44ULL);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const uint64_t kValues1[] = { 41ULL, 42ULL, 43ULL };
+ const uint64_t kValues2[] = { 41ULL, 44ULL, 43ULL };
+ const uint64_t kValues3[] = { 41ULL, 42ULL, 43ULL, 44ULL };
+ GPBUInt64Array *array1 =
+ [[GPBUInt64Array alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBUInt64Array *array1prime =
+ [[GPBUInt64Array alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBUInt64Array *array2 =
+ [[GPBUInt64Array alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBUInt64Array *array3 =
+ [[GPBUInt64Array alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const uint64_t kValues[] = { 41ULL, 42ULL, 43ULL, 44ULL };
+ GPBUInt64Array *array =
+ [[GPBUInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBUInt64Array *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const uint64_t kValues[] = { 41ULL, 42ULL, 43ULL, 44ULL };
+ GPBUInt64Array *array =
+ [[GPBUInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBUInt64Array *array2 = [GPBUInt64Array arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array release];
+}
+
+- (void)testAdds {
+ GPBUInt64Array *array = [GPBUInt64Array array];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addValue:41ULL];
+ XCTAssertEqual(array.count, 1U);
+
+ const uint64_t kValues1[] = { 42ULL, 43ULL };
+ [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const uint64_t kValues2[] = { 44ULL, 41ULL };
+ GPBUInt64Array *array2 =
+ [[GPBUInt64Array alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array valueAtIndex:0], 41ULL);
+ XCTAssertEqual([array valueAtIndex:1], 42ULL);
+ XCTAssertEqual([array valueAtIndex:2], 43ULL);
+ XCTAssertEqual([array valueAtIndex:3], 44ULL);
+ XCTAssertEqual([array valueAtIndex:4], 41ULL);
+ [array2 release];
+}
+
+- (void)testInsert {
+ const uint64_t kValues[] = { 41ULL, 42ULL, 43ULL };
+ GPBUInt64Array *array =
+ [[GPBUInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertValue:44ULL atIndex:0];
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertValue:44ULL atIndex:2];
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertValue:44ULL atIndex:5];
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertValue:44ULL atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array valueAtIndex:0], 44ULL);
+ XCTAssertEqual([array valueAtIndex:1], 41ULL);
+ XCTAssertEqual([array valueAtIndex:2], 44ULL);
+ XCTAssertEqual([array valueAtIndex:3], 42ULL);
+ XCTAssertEqual([array valueAtIndex:4], 43ULL);
+ XCTAssertEqual([array valueAtIndex:5], 44ULL);
+ [array release];
+}
+
+- (void)testRemove {
+ const uint64_t kValues[] = { 44ULL, 41ULL, 42ULL, 44ULL, 43ULL, 44ULL };
+ GPBUInt64Array *array =
+ [[GPBUInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 6U);
+
+ // First
+ [array removeValueAtIndex:0];
+ XCTAssertEqual(array.count, 5U);
+ XCTAssertEqual([array valueAtIndex:0], 41ULL);
+
+ // Middle
+ [array removeValueAtIndex:2];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:2], 43ULL);
+
+ // End
+ [array removeValueAtIndex:3];
+ XCTAssertEqual(array.count, 3U);
+
+ XCTAssertEqual([array valueAtIndex:0], 41ULL);
+ XCTAssertEqual([array valueAtIndex:1], 42ULL);
+ XCTAssertEqual([array valueAtIndex:2], 43ULL);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+ NSException, NSRangeException);
+
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kValues[] = { 41ULL, 41ULL, 43ULL, 43ULL };
+ GPBUInt64Array *array =
+ [[GPBUInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withValue:42ULL];
+ [array replaceValueAtIndex:3 withValue:44ULL];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 41ULL);
+ XCTAssertEqual([array valueAtIndex:1], 42ULL);
+ XCTAssertEqual([array valueAtIndex:2], 43ULL);
+ XCTAssertEqual([array valueAtIndex:3], 44ULL);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:44ULL],
+ NSException, NSRangeException);
+
+ [array exchangeValueAtIndex:1 withValueAtIndex:3];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 41ULL);
+ XCTAssertEqual([array valueAtIndex:1], 44ULL);
+ XCTAssertEqual([array valueAtIndex:2], 43ULL);
+ XCTAssertEqual([array valueAtIndex:3], 42ULL);
+
+ [array exchangeValueAtIndex:2 withValueAtIndex:0];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 43ULL);
+ XCTAssertEqual([array valueAtIndex:1], 44ULL);
+ XCTAssertEqual([array valueAtIndex:2], 41ULL);
+ XCTAssertEqual([array valueAtIndex:3], 42ULL);
+
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+ NSException, NSRangeException);
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInternalResizing {
+ const uint64_t kValues[] = { 41ULL, 42ULL, 43ULL, 44ULL };
+ GPBUInt64Array *array =
+ [[GPBUInt64Array alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertValue:44ULL atIndex:(i * 3)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_TESTS(Float, float, 51.f, 52.f, 53.f, 54.f)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Float
+
+@interface GPBFloatArrayTests : XCTestCase
+@end
+
+@implementation GPBFloatArrayTests
+
+- (void)testEmpty {
+ GPBFloatArray *array = [[GPBFloatArray alloc] init];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(float value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array release];
+}
+
+- (void)testOne {
+ GPBFloatArray *array = [GPBFloatArray arrayWithValue:51.f];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 1U);
+ XCTAssertEqual([array valueAtIndex:0], 51.f);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 51.f);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(float value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 51.f);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ static const float kValues[] = { 51.f, 52.f, 53.f, 54.f };
+ GPBFloatArray *array =
+ [[GPBFloatArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 51.f);
+ XCTAssertEqual([array valueAtIndex:1], 52.f);
+ XCTAssertEqual([array valueAtIndex:2], 53.f);
+ XCTAssertEqual([array valueAtIndex:3], 54.f);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(float value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(float value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(float value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const float kValues1[] = { 51.f, 52.f, 53.f };
+ const float kValues2[] = { 51.f, 54.f, 53.f };
+ const float kValues3[] = { 51.f, 52.f, 53.f, 54.f };
+ GPBFloatArray *array1 =
+ [[GPBFloatArray alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBFloatArray *array1prime =
+ [[GPBFloatArray alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBFloatArray *array2 =
+ [[GPBFloatArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBFloatArray *array3 =
+ [[GPBFloatArray alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const float kValues[] = { 51.f, 52.f, 53.f, 54.f };
+ GPBFloatArray *array =
+ [[GPBFloatArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBFloatArray *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const float kValues[] = { 51.f, 52.f, 53.f, 54.f };
+ GPBFloatArray *array =
+ [[GPBFloatArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBFloatArray *array2 = [GPBFloatArray arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array release];
+}
+
+- (void)testAdds {
+ GPBFloatArray *array = [GPBFloatArray array];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addValue:51.f];
+ XCTAssertEqual(array.count, 1U);
+
+ const float kValues1[] = { 52.f, 53.f };
+ [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const float kValues2[] = { 54.f, 51.f };
+ GPBFloatArray *array2 =
+ [[GPBFloatArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array valueAtIndex:0], 51.f);
+ XCTAssertEqual([array valueAtIndex:1], 52.f);
+ XCTAssertEqual([array valueAtIndex:2], 53.f);
+ XCTAssertEqual([array valueAtIndex:3], 54.f);
+ XCTAssertEqual([array valueAtIndex:4], 51.f);
+ [array2 release];
+}
+
+- (void)testInsert {
+ const float kValues[] = { 51.f, 52.f, 53.f };
+ GPBFloatArray *array =
+ [[GPBFloatArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertValue:54.f atIndex:0];
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertValue:54.f atIndex:2];
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertValue:54.f atIndex:5];
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertValue:54.f atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array valueAtIndex:0], 54.f);
+ XCTAssertEqual([array valueAtIndex:1], 51.f);
+ XCTAssertEqual([array valueAtIndex:2], 54.f);
+ XCTAssertEqual([array valueAtIndex:3], 52.f);
+ XCTAssertEqual([array valueAtIndex:4], 53.f);
+ XCTAssertEqual([array valueAtIndex:5], 54.f);
+ [array release];
+}
+
+- (void)testRemove {
+ const float kValues[] = { 54.f, 51.f, 52.f, 54.f, 53.f, 54.f };
+ GPBFloatArray *array =
+ [[GPBFloatArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 6U);
+
+ // First
+ [array removeValueAtIndex:0];
+ XCTAssertEqual(array.count, 5U);
+ XCTAssertEqual([array valueAtIndex:0], 51.f);
+
+ // Middle
+ [array removeValueAtIndex:2];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:2], 53.f);
+
+ // End
+ [array removeValueAtIndex:3];
+ XCTAssertEqual(array.count, 3U);
+
+ XCTAssertEqual([array valueAtIndex:0], 51.f);
+ XCTAssertEqual([array valueAtIndex:1], 52.f);
+ XCTAssertEqual([array valueAtIndex:2], 53.f);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+ NSException, NSRangeException);
+
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInplaceMutation {
+ const float kValues[] = { 51.f, 51.f, 53.f, 53.f };
+ GPBFloatArray *array =
+ [[GPBFloatArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withValue:52.f];
+ [array replaceValueAtIndex:3 withValue:54.f];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 51.f);
+ XCTAssertEqual([array valueAtIndex:1], 52.f);
+ XCTAssertEqual([array valueAtIndex:2], 53.f);
+ XCTAssertEqual([array valueAtIndex:3], 54.f);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:54.f],
+ NSException, NSRangeException);
+
+ [array exchangeValueAtIndex:1 withValueAtIndex:3];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 51.f);
+ XCTAssertEqual([array valueAtIndex:1], 54.f);
+ XCTAssertEqual([array valueAtIndex:2], 53.f);
+ XCTAssertEqual([array valueAtIndex:3], 52.f);
+
+ [array exchangeValueAtIndex:2 withValueAtIndex:0];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 53.f);
+ XCTAssertEqual([array valueAtIndex:1], 54.f);
+ XCTAssertEqual([array valueAtIndex:2], 51.f);
+ XCTAssertEqual([array valueAtIndex:3], 52.f);
+
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+ NSException, NSRangeException);
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInternalResizing {
+ const float kValues[] = { 51.f, 52.f, 53.f, 54.f };
+ GPBFloatArray *array =
+ [[GPBFloatArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertValue:54.f atIndex:(i * 3)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_TESTS(Double, double, 61., 62., 63., 64.)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Double
+
+@interface GPBDoubleArrayTests : XCTestCase
+@end
+
+@implementation GPBDoubleArrayTests
+
+- (void)testEmpty {
+ GPBDoubleArray *array = [[GPBDoubleArray alloc] init];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(double value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array release];
+}
+
+- (void)testOne {
+ GPBDoubleArray *array = [GPBDoubleArray arrayWithValue:61.];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 1U);
+ XCTAssertEqual([array valueAtIndex:0], 61.);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 61.);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(double value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 61.);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ static const double kValues[] = { 61., 62., 63., 64. };
+ GPBDoubleArray *array =
+ [[GPBDoubleArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 61.);
+ XCTAssertEqual([array valueAtIndex:1], 62.);
+ XCTAssertEqual([array valueAtIndex:2], 63.);
+ XCTAssertEqual([array valueAtIndex:3], 64.);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(double value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(double value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(double value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const double kValues1[] = { 61., 62., 63. };
+ const double kValues2[] = { 61., 64., 63. };
+ const double kValues3[] = { 61., 62., 63., 64. };
+ GPBDoubleArray *array1 =
+ [[GPBDoubleArray alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBDoubleArray *array1prime =
+ [[GPBDoubleArray alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBDoubleArray *array2 =
+ [[GPBDoubleArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBDoubleArray *array3 =
+ [[GPBDoubleArray alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const double kValues[] = { 61., 62., 63., 64. };
+ GPBDoubleArray *array =
+ [[GPBDoubleArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBDoubleArray *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const double kValues[] = { 61., 62., 63., 64. };
+ GPBDoubleArray *array =
+ [[GPBDoubleArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBDoubleArray *array2 = [GPBDoubleArray arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array release];
+}
+
+- (void)testAdds {
+ GPBDoubleArray *array = [GPBDoubleArray array];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addValue:61.];
+ XCTAssertEqual(array.count, 1U);
+
+ const double kValues1[] = { 62., 63. };
+ [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const double kValues2[] = { 64., 61. };
+ GPBDoubleArray *array2 =
+ [[GPBDoubleArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array valueAtIndex:0], 61.);
+ XCTAssertEqual([array valueAtIndex:1], 62.);
+ XCTAssertEqual([array valueAtIndex:2], 63.);
+ XCTAssertEqual([array valueAtIndex:3], 64.);
+ XCTAssertEqual([array valueAtIndex:4], 61.);
+ [array2 release];
+}
+
+- (void)testInsert {
+ const double kValues[] = { 61., 62., 63. };
+ GPBDoubleArray *array =
+ [[GPBDoubleArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertValue:64. atIndex:0];
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertValue:64. atIndex:2];
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertValue:64. atIndex:5];
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertValue:64. atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array valueAtIndex:0], 64.);
+ XCTAssertEqual([array valueAtIndex:1], 61.);
+ XCTAssertEqual([array valueAtIndex:2], 64.);
+ XCTAssertEqual([array valueAtIndex:3], 62.);
+ XCTAssertEqual([array valueAtIndex:4], 63.);
+ XCTAssertEqual([array valueAtIndex:5], 64.);
+ [array release];
+}
+
+- (void)testRemove {
+ const double kValues[] = { 64., 61., 62., 64., 63., 64. };
+ GPBDoubleArray *array =
+ [[GPBDoubleArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 6U);
+
+ // First
+ [array removeValueAtIndex:0];
+ XCTAssertEqual(array.count, 5U);
+ XCTAssertEqual([array valueAtIndex:0], 61.);
+
+ // Middle
+ [array removeValueAtIndex:2];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:2], 63.);
+
+ // End
+ [array removeValueAtIndex:3];
+ XCTAssertEqual(array.count, 3U);
+
+ XCTAssertEqual([array valueAtIndex:0], 61.);
+ XCTAssertEqual([array valueAtIndex:1], 62.);
+ XCTAssertEqual([array valueAtIndex:2], 63.);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+ NSException, NSRangeException);
+
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInplaceMutation {
+ const double kValues[] = { 61., 61., 63., 63. };
+ GPBDoubleArray *array =
+ [[GPBDoubleArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withValue:62.];
+ [array replaceValueAtIndex:3 withValue:64.];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 61.);
+ XCTAssertEqual([array valueAtIndex:1], 62.);
+ XCTAssertEqual([array valueAtIndex:2], 63.);
+ XCTAssertEqual([array valueAtIndex:3], 64.);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:64.],
+ NSException, NSRangeException);
+
+ [array exchangeValueAtIndex:1 withValueAtIndex:3];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 61.);
+ XCTAssertEqual([array valueAtIndex:1], 64.);
+ XCTAssertEqual([array valueAtIndex:2], 63.);
+ XCTAssertEqual([array valueAtIndex:3], 62.);
+
+ [array exchangeValueAtIndex:2 withValueAtIndex:0];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 63.);
+ XCTAssertEqual([array valueAtIndex:1], 64.);
+ XCTAssertEqual([array valueAtIndex:2], 61.);
+ XCTAssertEqual([array valueAtIndex:3], 62.);
+
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+ NSException, NSRangeException);
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInternalResizing {
+ const double kValues[] = { 61., 62., 63., 64. };
+ GPBDoubleArray *array =
+ [[GPBDoubleArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertValue:64. atIndex:(i * 3)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_TESTS(Bool, BOOL, TRUE, TRUE, FALSE, FALSE)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool
+
+@interface GPBBoolArrayTests : XCTestCase
+@end
+
+@implementation GPBBoolArrayTests
+
+- (void)testEmpty {
+ GPBBoolArray *array = [[GPBBoolArray alloc] init];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array release];
+}
+
+- (void)testOne {
+ GPBBoolArray *array = [GPBBoolArray arrayWithValue:TRUE];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 1U);
+ XCTAssertEqual([array valueAtIndex:0], TRUE);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, TRUE);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, TRUE);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ static const BOOL kValues[] = { TRUE, TRUE, FALSE, FALSE };
+ GPBBoolArray *array =
+ [[GPBBoolArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], TRUE);
+ XCTAssertEqual([array valueAtIndex:1], TRUE);
+ XCTAssertEqual([array valueAtIndex:2], FALSE);
+ XCTAssertEqual([array valueAtIndex:3], FALSE);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(BOOL value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const BOOL kValues1[] = { TRUE, TRUE, FALSE };
+ const BOOL kValues2[] = { TRUE, FALSE, FALSE };
+ const BOOL kValues3[] = { TRUE, TRUE, FALSE, FALSE };
+ GPBBoolArray *array1 =
+ [[GPBBoolArray alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBBoolArray *array1prime =
+ [[GPBBoolArray alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBBoolArray *array2 =
+ [[GPBBoolArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBBoolArray *array3 =
+ [[GPBBoolArray alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const BOOL kValues[] = { TRUE, TRUE, FALSE, FALSE };
+ GPBBoolArray *array =
+ [[GPBBoolArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBBoolArray *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const BOOL kValues[] = { TRUE, TRUE, FALSE, FALSE };
+ GPBBoolArray *array =
+ [[GPBBoolArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBBoolArray *array2 = [GPBBoolArray arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array release];
+}
+
+- (void)testAdds {
+ GPBBoolArray *array = [GPBBoolArray array];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addValue:TRUE];
+ XCTAssertEqual(array.count, 1U);
+
+ const BOOL kValues1[] = { TRUE, FALSE };
+ [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const BOOL kValues2[] = { FALSE, TRUE };
+ GPBBoolArray *array2 =
+ [[GPBBoolArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array valueAtIndex:0], TRUE);
+ XCTAssertEqual([array valueAtIndex:1], TRUE);
+ XCTAssertEqual([array valueAtIndex:2], FALSE);
+ XCTAssertEqual([array valueAtIndex:3], FALSE);
+ XCTAssertEqual([array valueAtIndex:4], TRUE);
+ [array2 release];
+}
+
+- (void)testInsert {
+ const BOOL kValues[] = { TRUE, TRUE, FALSE };
+ GPBBoolArray *array =
+ [[GPBBoolArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertValue:FALSE atIndex:0];
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertValue:FALSE atIndex:2];
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertValue:FALSE atIndex:5];
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertValue:FALSE atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array valueAtIndex:0], FALSE);
+ XCTAssertEqual([array valueAtIndex:1], TRUE);
+ XCTAssertEqual([array valueAtIndex:2], FALSE);
+ XCTAssertEqual([array valueAtIndex:3], TRUE);
+ XCTAssertEqual([array valueAtIndex:4], FALSE);
+ XCTAssertEqual([array valueAtIndex:5], FALSE);
+ [array release];
+}
+
+- (void)testRemove {
+ const BOOL kValues[] = { FALSE, TRUE, TRUE, FALSE, FALSE, FALSE };
+ GPBBoolArray *array =
+ [[GPBBoolArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 6U);
+
+ // First
+ [array removeValueAtIndex:0];
+ XCTAssertEqual(array.count, 5U);
+ XCTAssertEqual([array valueAtIndex:0], TRUE);
+
+ // Middle
+ [array removeValueAtIndex:2];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:2], FALSE);
+
+ // End
+ [array removeValueAtIndex:3];
+ XCTAssertEqual(array.count, 3U);
+
+ XCTAssertEqual([array valueAtIndex:0], TRUE);
+ XCTAssertEqual([array valueAtIndex:1], TRUE);
+ XCTAssertEqual([array valueAtIndex:2], FALSE);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+ NSException, NSRangeException);
+
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kValues[] = { TRUE, TRUE, FALSE, FALSE };
+ GPBBoolArray *array =
+ [[GPBBoolArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withValue:TRUE];
+ [array replaceValueAtIndex:3 withValue:FALSE];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], TRUE);
+ XCTAssertEqual([array valueAtIndex:1], TRUE);
+ XCTAssertEqual([array valueAtIndex:2], FALSE);
+ XCTAssertEqual([array valueAtIndex:3], FALSE);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:FALSE],
+ NSException, NSRangeException);
+
+ [array exchangeValueAtIndex:1 withValueAtIndex:3];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], TRUE);
+ XCTAssertEqual([array valueAtIndex:1], FALSE);
+ XCTAssertEqual([array valueAtIndex:2], FALSE);
+ XCTAssertEqual([array valueAtIndex:3], TRUE);
+
+ [array exchangeValueAtIndex:2 withValueAtIndex:0];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], FALSE);
+ XCTAssertEqual([array valueAtIndex:1], FALSE);
+ XCTAssertEqual([array valueAtIndex:2], TRUE);
+ XCTAssertEqual([array valueAtIndex:3], TRUE);
+
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+ NSException, NSRangeException);
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInternalResizing {
+ const BOOL kValues[] = { TRUE, TRUE, FALSE, FALSE };
+ GPBBoolArray *array =
+ [[GPBBoolArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertValue:FALSE atIndex:(i * 3)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+//%PDDM-EXPAND ARRAY_TESTS2(Enum, int32_t, 71, 72, 73, 74, Raw)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Enum
+
+@interface GPBEnumArrayTests : XCTestCase
+@end
+
+@implementation GPBEnumArrayTests
+
+- (void)testEmpty {
+ GPBEnumArray *array = [[GPBEnumArray alloc] init];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:0], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ #pragma unused(value, idx, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [array release];
+}
+
+- (void)testOne {
+ GPBEnumArray *array = [GPBEnumArray arrayWithValue:71];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 1U);
+ XCTAssertEqual([array valueAtIndex:0], 71);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:1], NSException, NSRangeException);
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 71);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, 0U);
+ XCTAssertEqual(value, 71);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ static const int32_t kValues[] = { 71, 72, 73, 74 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 71);
+ XCTAssertEqual([array valueAtIndex:1], 72);
+ XCTAssertEqual([array valueAtIndex:2], 73);
+ XCTAssertEqual([array valueAtIndex:3], 74);
+ XCTAssertThrowsSpecificNamed([array valueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const int32_t kValues1[] = { 71, 72, 73 };
+ const int32_t kValues2[] = { 71, 74, 73 };
+ const int32_t kValues3[] = { 71, 72, 73, 74 };
+ GPBEnumArray *array1 =
+ [[GPBEnumArray alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBEnumArray *array1prime =
+ [[GPBEnumArray alloc] initWithValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBEnumArray *array2 =
+ [[GPBEnumArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBEnumArray *array3 =
+ [[GPBEnumArray alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const int32_t kValues[] = { 71, 72, 73, 74 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBEnumArray *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const int32_t kValues[] = { 71, 72, 73, 74 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBEnumArray *array2 = [GPBEnumArray arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ [array release];
+}
+
+- (void)testAdds {
+ GPBEnumArray *array = [GPBEnumArray array];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addValue:71];
+ XCTAssertEqual(array.count, 1U);
+
+ const int32_t kValues1[] = { 72, 73 };
+ [array addValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const int32_t kValues2[] = { 74, 71 };
+ GPBEnumArray *array2 =
+ [[GPBEnumArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addRawValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array valueAtIndex:0], 71);
+ XCTAssertEqual([array valueAtIndex:1], 72);
+ XCTAssertEqual([array valueAtIndex:2], 73);
+ XCTAssertEqual([array valueAtIndex:3], 74);
+ XCTAssertEqual([array valueAtIndex:4], 71);
+ [array2 release];
+}
+
+- (void)testInsert {
+ const int32_t kValues[] = { 71, 72, 73 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertValue:74 atIndex:0];
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertValue:74 atIndex:2];
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertValue:74 atIndex:5];
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertValue:74 atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array valueAtIndex:0], 74);
+ XCTAssertEqual([array valueAtIndex:1], 71);
+ XCTAssertEqual([array valueAtIndex:2], 74);
+ XCTAssertEqual([array valueAtIndex:3], 72);
+ XCTAssertEqual([array valueAtIndex:4], 73);
+ XCTAssertEqual([array valueAtIndex:5], 74);
+ [array release];
+}
+
+- (void)testRemove {
+ const int32_t kValues[] = { 74, 71, 72, 74, 73, 74 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 6U);
+
+ // First
+ [array removeValueAtIndex:0];
+ XCTAssertEqual(array.count, 5U);
+ XCTAssertEqual([array valueAtIndex:0], 71);
+
+ // Middle
+ [array removeValueAtIndex:2];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:2], 73);
+
+ // End
+ [array removeValueAtIndex:3];
+ XCTAssertEqual(array.count, 3U);
+
+ XCTAssertEqual([array valueAtIndex:0], 71);
+ XCTAssertEqual([array valueAtIndex:1], 72);
+ XCTAssertEqual([array valueAtIndex:2], 73);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:3],
+ NSException, NSRangeException);
+
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ XCTAssertThrowsSpecificNamed([array removeValueAtIndex:0],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kValues[] = { 71, 71, 73, 73 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withValue:72];
+ [array replaceValueAtIndex:3 withValue:74];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 71);
+ XCTAssertEqual([array valueAtIndex:1], 72);
+ XCTAssertEqual([array valueAtIndex:2], 73);
+ XCTAssertEqual([array valueAtIndex:3], 74);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withValue:74],
+ NSException, NSRangeException);
+
+ [array exchangeValueAtIndex:1 withValueAtIndex:3];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 71);
+ XCTAssertEqual([array valueAtIndex:1], 74);
+ XCTAssertEqual([array valueAtIndex:2], 73);
+ XCTAssertEqual([array valueAtIndex:3], 72);
+
+ [array exchangeValueAtIndex:2 withValueAtIndex:0];
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 73);
+ XCTAssertEqual([array valueAtIndex:1], 74);
+ XCTAssertEqual([array valueAtIndex:2], 71);
+ XCTAssertEqual([array valueAtIndex:3], 72);
+
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:4 withValueAtIndex:1],
+ NSException, NSRangeException);
+ XCTAssertThrowsSpecificNamed([array exchangeValueAtIndex:1 withValueAtIndex:4],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testInternalResizing {
+ const int32_t kValues[] = { 71, 72, 73, 74 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertValue:74 atIndex:(i * 3)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+//%PDDM-EXPAND-END (8 expansions)
+
+#pragma mark - Non macro-based Enum tests
+
+// These are hand written tests to cover the verification and raw methods.
+
+@interface GPBEnumArrayCustomTests : XCTestCase
+@end
+
+@implementation GPBEnumArrayCustomTests
+
+- (void)testRawBasics {
+ static const int32_t kValues[] = { 71, 272, 73, 374 };
+ static const int32_t kValuesFiltered[] = {
+ 71, kGPBUnrecognizedEnumeratorValue, 73, kGPBUnrecognizedEnumeratorValue
+ };
+ XCTAssertEqual(GPBARRAYSIZE(kValues), GPBARRAYSIZE(kValuesFiltered));
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 4U);
+ GPBEnumValidationFunc func = TestingEnum_IsValidValue;
+ XCTAssertEqual(array.validationFunc, func);
+ XCTAssertEqual([array rawValueAtIndex:0], 71);
+ XCTAssertEqual([array rawValueAtIndex:1], 272);
+ XCTAssertEqual([array valueAtIndex:1], kGPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([array rawValueAtIndex:2], 73);
+ XCTAssertEqual([array rawValueAtIndex:3], 374);
+ XCTAssertEqual([array valueAtIndex:3], kGPBUnrecognizedEnumeratorValue);
+ XCTAssertThrowsSpecificNamed([array rawValueAtIndex:4], NSException, NSRangeException);
+ __block NSUInteger idx2 = 0;
+ [array enumerateRawValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValuesFiltered[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateRawValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValuesFiltered[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ ++idx2;
+ }];
+ // Stopping the enumeration.
+ idx2 = 0;
+ [array enumerateRawValuesWithBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, idx2);
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ XCTAssertNotEqual(idx, 3U);
+ ++idx2;
+ }];
+ idx2 = 0;
+ [array enumerateRawValuesWithOptions:NSEnumerationReverse
+ usingBlock:^(int32_t value, NSUInteger idx, BOOL *stop) {
+ XCTAssertEqual(idx, (3 - idx2));
+ XCTAssertEqual(value, kValues[idx]);
+ XCTAssertNotEqual(stop, NULL);
+ if (idx2 == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 1U);
+ XCTAssertNotEqual(idx, 0U);
+ ++idx2;
+ }];
+ [array release];
+}
+
+- (void)testEquality {
+ const int32_t kValues1[] = { 71, 72, 173 }; // With unknown value
+ const int32_t kValues2[] = { 71, 74, 173 }; // With unknown value
+ const int32_t kValues3[] = { 71, 72, 173, 74 }; // With unknown value
+ GPBEnumArray *array1 =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1);
+ GPBEnumArray *array1prime =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue2
+ rawValues:kValues1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(array1prime);
+ GPBEnumArray *array2 =
+ [[GPBEnumArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ GPBEnumArray *array3 =
+ [[GPBEnumArray alloc] initWithValues:kValues3
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(array3);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(array1, array1prime);
+ XCTAssertEqualObjects(array1, array1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([array1 hash], [array1prime hash]);
+ // But different validation functions.
+ XCTAssertNotEqual(array1.validationFunc, array1prime.validationFunc);
+
+ // 1/2/3 shouldn't be equal.
+ XCTAssertNotEqualObjects(array1, array2);
+ XCTAssertNotEqualObjects(array1, array3);
+ XCTAssertNotEqualObjects(array2, array3);
+
+ [array1 release];
+ [array1prime release];
+ [array2 release];
+ [array3 release];
+}
+
+- (void)testCopy {
+ const int32_t kValues[] = { 71, 72 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array addRawValue:1000]; // Unknown
+ XCTAssertEqual(array.count, 3U);
+ XCTAssertEqual([array rawValueAtIndex:0], 71);
+ XCTAssertEqual([array rawValueAtIndex:1], 72);
+ XCTAssertEqual([array rawValueAtIndex:2], 1000);
+ XCTAssertEqual([array valueAtIndex:2], kGPBUnrecognizedEnumeratorValue);
+
+ GPBEnumArray *array2 = [array copy];
+ XCTAssertNotNil(array2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ XCTAssertEqual(array.validationFunc, array2.validationFunc);
+ XCTAssertTrue([array2 isKindOfClass:[GPBEnumArray class]]);
+ XCTAssertEqual(array2.count, 3U);
+ XCTAssertEqual([array2 rawValueAtIndex:0], 71);
+ XCTAssertEqual([array2 rawValueAtIndex:1], 72);
+ XCTAssertEqual([array2 rawValueAtIndex:2], 1000);
+ XCTAssertEqual([array2 valueAtIndex:2], kGPBUnrecognizedEnumeratorValue);
+ [array2 release];
+ [array release];
+}
+
+- (void)testArrayFromArray {
+ const int32_t kValues[] = { 71, 172, 173, 74 }; // Unknowns
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ GPBEnumArray *array2 = [GPBEnumArray arrayWithValueArray:array];
+ XCTAssertNotNil(array2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(array, array2);
+ XCTAssertEqualObjects(array, array2);
+ XCTAssertEqual(array.validationFunc, array2.validationFunc);
+ [array release];
+}
+
+- (void)testUnknownAdds {
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue];
+ XCTAssertNotNil(array);
+
+ XCTAssertThrowsSpecificNamed([array addValue:172],
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(array.count, 0U);
+
+ const int32_t kValues1[] = { 172, 173 }; // Unknown
+ XCTAssertThrowsSpecificNamed([array addValues:kValues1 count:GPBARRAYSIZE(kValues1)],
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+- (void)testRawAdds {
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue];
+ XCTAssertNotNil(array);
+
+ XCTAssertEqual(array.count, 0U);
+ [array addRawValue:71]; // Valid
+ XCTAssertEqual(array.count, 1U);
+
+ const int32_t kValues1[] = { 172, 173 }; // Unknown
+ [array addRawValues:kValues1 count:GPBARRAYSIZE(kValues1)];
+ XCTAssertEqual(array.count, 3U);
+
+ const int32_t kValues2[] = { 74, 71 };
+ GPBEnumArray *array2 =
+ [[GPBEnumArray alloc] initWithValues:kValues2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(array2);
+ [array addRawValuesFromArray:array2];
+ XCTAssertEqual(array.count, 5U);
+
+ XCTAssertEqual([array rawValueAtIndex:0], 71);
+ XCTAssertEqual([array rawValueAtIndex:1], 172);
+ XCTAssertEqual([array valueAtIndex:1], kGPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([array rawValueAtIndex:2], 173);
+ XCTAssertEqual([array valueAtIndex:2], kGPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([array rawValueAtIndex:3], 74);
+ XCTAssertEqual([array rawValueAtIndex:4], 71);
+ [array release];
+}
+
+- (void)testUnknownInserts {
+ const int32_t kValues[] = { 71, 72, 73 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ XCTAssertThrowsSpecificNamed([array insertValue:174 atIndex:0],
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(array.count, 3U);
+
+ // Middle
+ XCTAssertThrowsSpecificNamed([array insertValue:274 atIndex:1],
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(array.count, 3U);
+
+ // End
+ XCTAssertThrowsSpecificNamed([array insertValue:374 atIndex:3],
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(array.count, 3U);
+ [array release];
+}
+
+- (void)testRawInsert {
+ const int32_t kValues[] = { 71, 72, 73 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+ XCTAssertEqual(array.count, 3U);
+
+ // First
+ [array insertRawValue:174 atIndex:0]; // Unknown
+ XCTAssertEqual(array.count, 4U);
+
+ // Middle
+ [array insertRawValue:274 atIndex:2]; // Unknown
+ XCTAssertEqual(array.count, 5U);
+
+ // End
+ [array insertRawValue:374 atIndex:5]; // Unknown
+ XCTAssertEqual(array.count, 6U);
+
+ // Too far.
+ XCTAssertThrowsSpecificNamed([array insertRawValue:74 atIndex:7],
+ NSException, NSRangeException);
+
+ XCTAssertEqual([array rawValueAtIndex:0], 174);
+ XCTAssertEqual([array valueAtIndex:0], kGPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([array rawValueAtIndex:1], 71);
+ XCTAssertEqual([array rawValueAtIndex:2], 274);
+ XCTAssertEqual([array valueAtIndex:2], kGPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([array rawValueAtIndex:3], 72);
+ XCTAssertEqual([array rawValueAtIndex:4], 73);
+ XCTAssertEqual([array rawValueAtIndex:5], 374);
+ XCTAssertEqual([array valueAtIndex:5], kGPBUnrecognizedEnumeratorValue);
+ [array release];
+}
+
+- (void)testUnknownInplaceMutation {
+ const int32_t kValues[] = { 71, 72, 73, 74 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:1 withValue:172],
+ NSException, NSInvalidArgumentException);
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:3 withValue:274],
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array valueAtIndex:0], 71);
+ XCTAssertEqual([array valueAtIndex:1], 72);
+ XCTAssertEqual([array valueAtIndex:2], 73);
+ XCTAssertEqual([array valueAtIndex:3], 74);
+ [array release];
+}
+
+
+- (void)testRawInplaceMutation {
+ const int32_t kValues[] = { 71, 72, 73, 74 };
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ [array replaceValueAtIndex:1 withRawValue:172]; // Unknown
+ [array replaceValueAtIndex:3 withRawValue:274]; // Unknown
+ XCTAssertEqual(array.count, 4U);
+ XCTAssertEqual([array rawValueAtIndex:0], 71);
+ XCTAssertEqual([array rawValueAtIndex:1], 172);
+ XCTAssertEqual([array valueAtIndex:1], kGPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([array rawValueAtIndex:2], 73);
+ XCTAssertEqual([array rawValueAtIndex:3], 274);
+ XCTAssertEqual([array valueAtIndex:3], kGPBUnrecognizedEnumeratorValue);
+
+ XCTAssertThrowsSpecificNamed([array replaceValueAtIndex:4 withRawValue:74],
+ NSException, NSRangeException);
+ [array release];
+}
+
+- (void)testRawInternalResizing {
+ const int32_t kValues[] = { 71, 172, 173, 74 }; // Unknown
+ GPBEnumArray *array =
+ [[GPBEnumArray alloc] initWithValues:kValues
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(array);
+
+ // Add/remove to trigger the intneral buffer to grow/shrink.
+ for (int i = 0; i < 100; ++i) {
+ [array addRawValues:kValues count:GPBARRAYSIZE(kValues)];
+ }
+ XCTAssertEqual(array.count, 404U);
+ for (int i = 0; i < 100; ++i) {
+ [array removeValueAtIndex:(i * 2)];
+ }
+ XCTAssertEqual(array.count, 304U);
+ for (int i = 0; i < 100; ++i) {
+ [array insertRawValue:274 atIndex:(i * 3)]; // Unknown
+ }
+ XCTAssertEqual(array.count, 404U);
+ [array removeAll];
+ XCTAssertEqual(array.count, 0U);
+ [array release];
+}
+
+@end
+
+#pragma mark - GPBAutocreatedArray Tests
+
+// These are hand written tests to double check some behaviors of the
+// GPBAutocreatedArray.
+
+// NOTE: GPBAutocreatedArray is private to the library, users of the library
+// should never have to directly deal with this class.
+
+@interface GPBAutocreatedArrayTests : XCTestCase
+@end
+
+@implementation GPBAutocreatedArrayTests
+
+- (void)testEquality {
+ GPBAutocreatedArray *array = [[GPBAutocreatedArray alloc] init];
+
+ XCTAssertTrue([array isEqual:@[]]);
+ XCTAssertTrue([array isEqualToArray:@[]]);
+
+ XCTAssertFalse([array isEqual:@[ @"foo" ]]);
+ XCTAssertFalse([array isEqualToArray:@[ @"foo" ]]);
+
+ [array addObject:@"foo"];
+
+ XCTAssertFalse([array isEqual:@[]]);
+ XCTAssertFalse([array isEqualToArray:@[]]);
+ XCTAssertTrue([array isEqual:@[ @"foo" ]]);
+ XCTAssertTrue([array isEqualToArray:@[ @"foo" ]]);
+ XCTAssertFalse([array isEqual:@[ @"bar" ]]);
+ XCTAssertFalse([array isEqualToArray:@[ @"bar" ]]);
+
+ GPBAutocreatedArray *array2 = [[GPBAutocreatedArray alloc] init];
+
+ XCTAssertFalse([array isEqual:array2]);
+ XCTAssertFalse([array isEqualToArray:array2]);
+
+ [array2 addObject:@"bar"];
+ XCTAssertFalse([array isEqual:array2]);
+ XCTAssertFalse([array isEqualToArray:array2]);
+
+ [array2 replaceObjectAtIndex:0 withObject:@"foo"];
+ XCTAssertTrue([array isEqual:array2]);
+ XCTAssertTrue([array isEqualToArray:array2]);
+
+ [array2 release];
+ [array release];
+}
+
+- (void)testCopy {
+ {
+ GPBAutocreatedArray *array = [[GPBAutocreatedArray alloc] init];
+
+ NSArray *cpy = [array copy];
+ XCTAssertTrue(cpy != array); // Ptr compare
+ XCTAssertTrue([cpy isKindOfClass:[NSArray class]]);
+ XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(cpy.count, (NSUInteger)0);
+
+ NSArray *cpy2 = [array copy];
+ XCTAssertTrue(cpy2 != array); // Ptr compare
+ // Can't compare cpy and cpy2 because NSArray has a singleton empty
+ // array it uses, so the ptrs are the same.
+ XCTAssertTrue([cpy2 isKindOfClass:[NSArray class]]);
+ XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(cpy2.count, (NSUInteger)0);
+
+ [cpy2 release];
+ [cpy release];
+ [array release];
+ }
+
+ {
+ GPBAutocreatedArray *array = [[GPBAutocreatedArray alloc] init];
+
+ NSMutableArray *cpy = [array mutableCopy];
+ XCTAssertTrue(cpy != array); // Ptr compare
+ XCTAssertTrue([cpy isKindOfClass:[NSMutableArray class]]);
+ XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(cpy.count, (NSUInteger)0);
+
+ NSMutableArray *cpy2 = [array mutableCopy];
+ XCTAssertTrue(cpy2 != array); // Ptr compare
+ XCTAssertTrue(cpy2 != cpy); // Ptr compare
+ XCTAssertTrue([cpy2 isKindOfClass:[NSMutableArray class]]);
+ XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(cpy2.count, (NSUInteger)0);
+
+ [cpy2 release];
+ [cpy release];
+ [array release];
+ }
+
+ {
+ GPBAutocreatedArray *array = [[GPBAutocreatedArray alloc] init];
+ [array addObject:@"foo"];
+ [array addObject:@"bar"];
+
+ NSArray *cpy = [array copy];
+ XCTAssertTrue(cpy != array); // Ptr compare
+ XCTAssertTrue([cpy isKindOfClass:[NSArray class]]);
+ XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(cpy.count, (NSUInteger)2);
+ XCTAssertEqualObjects(cpy[0], @"foo");
+ XCTAssertEqualObjects(cpy[1], @"bar");
+
+ NSArray *cpy2 = [array copy];
+ XCTAssertTrue(cpy2 != array); // Ptr compare
+ XCTAssertTrue(cpy2 != cpy); // Ptr compare
+ XCTAssertTrue([cpy2 isKindOfClass:[NSArray class]]);
+ XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(cpy2.count, (NSUInteger)2);
+ XCTAssertEqualObjects(cpy2[0], @"foo");
+ XCTAssertEqualObjects(cpy2[1], @"bar");
+
+ [cpy2 release];
+ [cpy release];
+ [array release];
+ }
+
+ {
+ GPBAutocreatedArray *array = [[GPBAutocreatedArray alloc] init];
+ [array addObject:@"foo"];
+ [array addObject:@"bar"];
+
+ NSMutableArray *cpy = [array mutableCopy];
+ XCTAssertTrue(cpy != array); // Ptr compare
+ XCTAssertTrue([cpy isKindOfClass:[NSArray class]]);
+ XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(cpy.count, (NSUInteger)2);
+ XCTAssertEqualObjects(cpy[0], @"foo");
+ XCTAssertEqualObjects(cpy[1], @"bar");
+
+ NSMutableArray *cpy2 = [array mutableCopy];
+ XCTAssertTrue(cpy2 != array); // Ptr compare
+ XCTAssertTrue(cpy2 != cpy); // Ptr compare
+ XCTAssertTrue([cpy2 isKindOfClass:[NSArray class]]);
+ XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(cpy2.count, (NSUInteger)2);
+ XCTAssertEqualObjects(cpy2[0], @"foo");
+ XCTAssertEqualObjects(cpy2[1], @"bar");
+
+ [cpy2 release];
+ [cpy release];
+ [array release];
+ }
+}
+
+- (void)testIndexedSubscriptSupport {
+ // The base NSArray/NSMutableArray behaviors for *IndexedSubscript methods
+ // should still work via the methods that one has to override to make an
+ // NSMutableArray subclass. i.e. - this should "just work" and if these
+ // crash/fail, then something is wrong in how NSMutableArray is subclassed.
+
+ GPBAutocreatedArray *array = [[GPBAutocreatedArray alloc] init];
+
+ [array addObject:@"foo"];
+ [array addObject:@"bar"];
+ XCTAssertEqual(array.count, (NSUInteger)2);
+ XCTAssertEqualObjects(array[0], @"foo");
+ XCTAssertEqualObjects(array[1], @"bar");
+ array[0] = @"foo2";
+ array[2] = @"baz";
+ XCTAssertEqual(array.count, (NSUInteger)3);
+ XCTAssertEqualObjects(array[0], @"foo2");
+ XCTAssertEqualObjects(array[1], @"bar");
+ XCTAssertEqualObjects(array[2], @"baz");
+
+ [array release];
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBCodedInputStreamTests.m b/third_party/protobuf/objectivec/Tests/GPBCodedInputStreamTests.m
new file mode 100644
index 0000000000..cc40215698
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBCodedInputStreamTests.m
@@ -0,0 +1,335 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import "GPBCodedInputStream.h"
+#import "GPBCodedOutputStream.h"
+#import "GPBUnknownFieldSet_PackagePrivate.h"
+#import "GPBUtilities_PackagePrivate.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+
+@interface CodedInputStreamTests : GPBTestCase
+@end
+
+@implementation CodedInputStreamTests
+
+- (NSData*)bytes_with_sentinel:(int32_t)unused, ... {
+ va_list list;
+ va_start(list, unused);
+
+ NSMutableData* values = [NSMutableData dataWithCapacity:0];
+ int32_t i;
+
+ while ((i = va_arg(list, int32_t)) != 256) {
+ NSAssert(i >= 0 && i < 256, @"");
+ uint8_t u = (uint8_t)i;
+ [values appendBytes:&u length:1];
+ }
+
+ va_end(list);
+
+ return values;
+}
+
+#define bytes(...) [self bytes_with_sentinel:0, __VA_ARGS__, 256]
+
+- (void)testDecodeZigZag {
+ XCTAssertEqual(0, GPBDecodeZigZag32(0));
+ XCTAssertEqual(-1, GPBDecodeZigZag32(1));
+ XCTAssertEqual(1, GPBDecodeZigZag32(2));
+ XCTAssertEqual(-2, GPBDecodeZigZag32(3));
+ XCTAssertEqual((int32_t)0x3FFFFFFF, GPBDecodeZigZag32(0x7FFFFFFE));
+ XCTAssertEqual((int32_t)0xC0000000, GPBDecodeZigZag32(0x7FFFFFFF));
+ XCTAssertEqual((int32_t)0x7FFFFFFF, GPBDecodeZigZag32(0xFFFFFFFE));
+ XCTAssertEqual((int32_t)0x80000000, GPBDecodeZigZag32(0xFFFFFFFF));
+
+ XCTAssertEqual((int64_t)0, GPBDecodeZigZag64(0));
+ XCTAssertEqual((int64_t)-1, GPBDecodeZigZag64(1));
+ XCTAssertEqual((int64_t)1, GPBDecodeZigZag64(2));
+ XCTAssertEqual((int64_t)-2, GPBDecodeZigZag64(3));
+ XCTAssertEqual((int64_t)0x000000003FFFFFFFL,
+ GPBDecodeZigZag64(0x000000007FFFFFFEL));
+ XCTAssertEqual((int64_t)0xFFFFFFFFC0000000L,
+ GPBDecodeZigZag64(0x000000007FFFFFFFL));
+ XCTAssertEqual((int64_t)0x000000007FFFFFFFL,
+ GPBDecodeZigZag64(0x00000000FFFFFFFEL));
+ XCTAssertEqual((int64_t)0xFFFFFFFF80000000L,
+ GPBDecodeZigZag64(0x00000000FFFFFFFFL));
+ XCTAssertEqual((int64_t)0x7FFFFFFFFFFFFFFFL,
+ GPBDecodeZigZag64(0xFFFFFFFFFFFFFFFEL));
+ XCTAssertEqual((int64_t)0x8000000000000000L,
+ GPBDecodeZigZag64(0xFFFFFFFFFFFFFFFFL));
+}
+
+- (void)assertReadVarint:(NSData*)data value:(int64_t)value {
+ {
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ XCTAssertEqual((int32_t)value, [input readInt32]);
+ }
+ {
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ XCTAssertEqual(value, [input readInt64]);
+ }
+}
+
+- (void)assertReadLittleEndian32:(NSData*)data value:(int32_t)value {
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ XCTAssertEqual(value, [input readSFixed32]);
+}
+
+- (void)assertReadLittleEndian64:(NSData*)data value:(int64_t)value {
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ XCTAssertEqual(value, [input readSFixed64]);
+}
+
+- (void)assertReadVarintFailure:(NSData*)data {
+ {
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ XCTAssertThrows([input readInt32]);
+ }
+ {
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ XCTAssertThrows([input readInt64]);
+ }
+}
+
+- (void)testBytes {
+ NSData* data = bytes(0xa2, 0x74);
+ XCTAssertEqual(data.length, (NSUInteger)2);
+ XCTAssertEqual(((uint8_t*)data.bytes)[0], (uint8_t)0xa2);
+ XCTAssertEqual(((uint8_t*)data.bytes)[1], (uint8_t)0x74);
+}
+
+- (void)testReadVarint {
+ [self assertReadVarint:bytes(0x00) value:0];
+ [self assertReadVarint:bytes(0x01) value:1];
+ [self assertReadVarint:bytes(0x7f) value:127];
+ // 14882
+ [self assertReadVarint:bytes(0xa2, 0x74) value:(0x22 << 0) | (0x74 << 7)];
+ // 2961488830
+ [self assertReadVarint:bytes(0xbe, 0xf7, 0x92, 0x84, 0x0b)
+ value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) |
+ (0x04 << 21) | (0x0bLL << 28)];
+
+ // 64-bit
+ // 7256456126
+ [self assertReadVarint:bytes(0xbe, 0xf7, 0x92, 0x84, 0x1b)
+ value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) |
+ (0x04 << 21) | (0x1bLL << 28)];
+ // 41256202580718336
+ [self assertReadVarint:bytes(0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49)
+ value:(0x00 << 0) | (0x66 << 7) | (0x6b << 14) |
+ (0x1c << 21) | (0x43LL << 28) | (0x49LL << 35) |
+ (0x24LL << 42) | (0x49LL << 49)];
+ // 11964378330978735131
+ [self
+ assertReadVarint:bytes(0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85,
+ 0xa6, 0x01)
+ value:(0x1b << 0) | (0x28 << 7) | (0x79 << 14) | (0x42 << 21) |
+ (0x3bLL << 28) | (0x56LL << 35) | (0x00LL << 42) |
+ (0x05LL << 49) | (0x26LL << 56) | (0x01LL << 63)];
+
+ // Failures
+ [self assertReadVarintFailure:bytes(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
+ 0x80, 0x80, 0x80, 0x00)];
+ [self assertReadVarintFailure:bytes(0x80)];
+}
+
+- (void)testReadLittleEndian {
+ [self assertReadLittleEndian32:bytes(0x78, 0x56, 0x34, 0x12)
+ value:0x12345678];
+ [self assertReadLittleEndian32:bytes(0xf0, 0xde, 0xbc, 0x9a)
+ value:0x9abcdef0];
+
+ [self assertReadLittleEndian64:bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34,
+ 0x12)
+ value:0x123456789abcdef0LL];
+ [self assertReadLittleEndian64:bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc,
+ 0x9a)
+ value:0x9abcdef012345678LL];
+}
+
+- (void)testReadWholeMessage {
+ TestAllTypes* message = [self allSetRepeatedCount:kGPBDefaultRepeatCount];
+
+ NSData* rawBytes = message.data;
+ XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length);
+
+ TestAllTypes* message2 =
+ [TestAllTypes parseFromData:rawBytes extensionRegistry:nil error:NULL];
+ [self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testSkipWholeMessage {
+ TestAllTypes* message = [self allSetRepeatedCount:kGPBDefaultRepeatCount];
+ NSData* rawBytes = message.data;
+
+ // Create two parallel inputs. Parse one as unknown fields while using
+ // skipField() to skip each field on the other. Expect the same tags.
+ GPBCodedInputStream* input1 = [GPBCodedInputStream streamWithData:rawBytes];
+ GPBCodedInputStream* input2 = [GPBCodedInputStream streamWithData:rawBytes];
+ GPBUnknownFieldSet* unknownFields =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+
+ while (YES) {
+ int32_t tag = [input1 readTag];
+ XCTAssertEqual(tag, [input2 readTag]);
+ if (tag == 0) {
+ break;
+ }
+ [unknownFields mergeFieldFrom:tag input:input1];
+ [input2 skipField:tag];
+ }
+}
+
+- (void)testReadHugeBlob {
+ // Allocate and initialize a 1MB blob.
+ NSMutableData* blob = [NSMutableData dataWithLength:1 << 20];
+ for (NSUInteger i = 0; i < blob.length; i++) {
+ ((uint8_t*)blob.mutableBytes)[i] = (uint8_t)i;
+ }
+
+ // Make a message containing it.
+ TestAllTypes* message = [TestAllTypes message];
+ [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount];
+ [message setOptionalBytes:blob];
+
+ // Serialize and parse it. Make sure to parse from an InputStream, not
+ // directly from a ByteString, so that CodedInputStream uses buffered
+ // reading.
+ NSData *messageData = message.data;
+ XCTAssertNotNil(messageData);
+ GPBCodedInputStream* stream =
+ [GPBCodedInputStream streamWithData:messageData];
+ TestAllTypes* message2 = [TestAllTypes parseFromCodedInputStream:stream
+ extensionRegistry:nil
+ error:NULL];
+
+ XCTAssertEqualObjects(message.optionalBytes, message2.optionalBytes);
+
+ // Make sure all the other fields were parsed correctly.
+ TestAllTypes* message3 = [[message2 copy] autorelease];
+ TestAllTypes* types = [self allSetRepeatedCount:kGPBDefaultRepeatCount];
+ NSData* data = [types optionalBytes];
+ [message3 setOptionalBytes:data];
+
+ [self assertAllFieldsSet:message3 repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testReadMaliciouslyLargeBlob {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput];
+
+ int32_t tag = GPBWireFormatMakeTag(1, GPBWireFormatLengthDelimited);
+ [output writeRawVarint32:tag];
+ [output writeRawVarint32:0x7FFFFFFF];
+ uint8_t bytes[32] = {0};
+ [output writeRawData:[NSData dataWithBytes:bytes length:32]];
+ [output flush];
+
+ NSData* data =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ GPBCodedInputStream* input =
+ [GPBCodedInputStream streamWithData:[NSMutableData dataWithData:data]];
+ XCTAssertEqual(tag, [input readTag]);
+
+ XCTAssertThrows([input readBytes]);
+}
+
+// Verifies fix for b/10315336.
+// Note: Now that there isn't a custom string class under the hood, this test
+// isn't as critical, but it does cover bad input and if a custom class is added
+// again, it will help validate that class' handing of bad utf8.
+- (void)testReadMalformedString {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput];
+
+ int32_t tag = GPBWireFormatMakeTag(TestAllTypes_FieldNumber_DefaultString,
+ GPBWireFormatLengthDelimited);
+ [output writeRawVarint32:tag];
+ [output writeRawVarint32:5];
+ // Create an invalid utf-8 byte array.
+ uint8_t bytes[] = {0xc2, 0xf2, 0x0, 0x0, 0x0};
+ [output writeRawData:[NSData dataWithBytes:bytes length:sizeof(bytes)]];
+ [output flush];
+
+ NSData *data =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ NSError *error = nil;
+ TestAllTypes* message = [TestAllTypes parseFromCodedInputStream:input
+ extensionRegistry:nil
+ error:&error];
+ XCTAssertNotNil(error);
+ XCTAssertNil(message);
+}
+
+- (void)testBOMWithinStrings {
+ // We've seen servers that end up with BOMs within strings (not always at the
+ // start, and sometimes in multiple places), make sure they always parse
+ // correctly. (Again, this is inpart incase a custom string class is ever
+ // used again.)
+ const char* strs[] = {
+ "\xEF\xBB\xBF String with BOM",
+ "String with \xEF\xBB\xBF in middle",
+ "String with end bom \xEF\xBB\xBF",
+ "\xEF\xBB\xBF\xe2\x99\xa1", // BOM White Heart
+ "\xEF\xBB\xBF\xEF\xBB\xBF String with Two BOM",
+ };
+ for (size_t i = 0; i < GPBARRAYSIZE(strs); ++i) {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput];
+
+ int32_t tag = GPBWireFormatMakeTag(TestAllTypes_FieldNumber_DefaultString,
+ GPBWireFormatLengthDelimited);
+ [output writeRawVarint32:tag];
+ size_t length = strlen(strs[i]);
+ [output writeRawVarint32:(int32_t)length];
+ [output writeRawData:[NSData dataWithBytes:strs[i] length:length]];
+ [output flush];
+
+ NSData* data =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ TestAllTypes* message = [TestAllTypes parseFromCodedInputStream:input
+ extensionRegistry:nil
+ error:NULL];
+ XCTAssertNotNil(message, @"Loop %zd", i);
+ // Ensure the string is there. NSString can consume the BOM in some
+ // cases, so don't actually check the string for exact equality.
+ XCTAssertTrue(message.defaultString.length > 0, @"Loop %zd", i);
+ }
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBCodedOuputStreamTests.m b/third_party/protobuf/objectivec/Tests/GPBCodedOuputStreamTests.m
new file mode 100644
index 0000000000..2ad326beb9
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBCodedOuputStreamTests.m
@@ -0,0 +1,426 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import "GPBCodedOutputStream_PackagePrivate.h"
+#import "GPBCodedInputStream.h"
+#import "GPBUtilities_PackagePrivate.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+
+@interface GPBCodedOutputStream (InternalMethods)
+// Declared in the .m file, expose for testing.
+- (instancetype)initWithOutputStream:(NSOutputStream *)output
+ data:(NSMutableData *)data;
+@end
+
+@interface GPBCodedOutputStream (Helper)
++ (instancetype)streamWithOutputStream:(NSOutputStream *)output
+ bufferSize:(size_t)bufferSize;
+@end
+
+@implementation GPBCodedOutputStream (Helper)
++ (instancetype)streamWithOutputStream:(NSOutputStream *)output
+ bufferSize:(size_t)bufferSize {
+ NSMutableData *data = [NSMutableData dataWithLength:bufferSize];
+ return [[[self alloc] initWithOutputStream:output data:data] autorelease];
+}
+@end
+
+@interface CodedOutputStreamTests : GPBTestCase
+@end
+
+@implementation CodedOutputStreamTests
+
+- (NSData*)bytes_with_sentinel:(int32_t)unused, ... {
+ va_list list;
+ va_start(list, unused);
+
+ NSMutableData* values = [NSMutableData dataWithCapacity:0];
+ int32_t i;
+
+ while ((i = va_arg(list, int32_t)) != 256) {
+ NSAssert(i >= 0 && i < 256, @"");
+ uint8_t u = (uint8_t)i;
+ [values appendBytes:&u length:1];
+ }
+
+ va_end(list);
+
+ return values;
+}
+
+#define bytes(...) [self bytes_with_sentinel:0, __VA_ARGS__, 256]
+
+- (void)assertWriteLittleEndian32:(NSData*)data value:(int32_t)value {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput];
+ [output writeRawLittleEndian32:(int32_t)value];
+ [output flush];
+
+ NSData* actual =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual);
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2) {
+ rawOutput = [NSOutputStream outputStreamToMemory];
+ output = [GPBCodedOutputStream streamWithOutputStream:rawOutput
+ bufferSize:blockSize];
+ [output writeRawLittleEndian32:(int32_t)value];
+ [output flush];
+
+ actual = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual);
+ }
+}
+
+- (void)assertWriteLittleEndian64:(NSData*)data value:(int64_t)value {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput];
+ [output writeRawLittleEndian64:value];
+ [output flush];
+
+ NSData* actual =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual);
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2) {
+ rawOutput = [NSOutputStream outputStreamToMemory];
+ output = [GPBCodedOutputStream streamWithOutputStream:rawOutput
+ bufferSize:blockSize];
+ [output writeRawLittleEndian64:value];
+ [output flush];
+
+ actual = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual);
+ }
+}
+
+- (void)assertWriteVarint:(NSData*)data value:(int64_t)value {
+ // Only do 32-bit write if the value fits in 32 bits.
+ if (GPBLogicalRightShift64(value, 32) == 0) {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput];
+ [output writeRawVarint32:(int32_t)value];
+ [output flush];
+
+ NSData* actual =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual);
+
+ // Also try computing size.
+ XCTAssertEqual(GPBComputeRawVarint32Size((int32_t)value),
+ (size_t)data.length);
+ }
+
+ {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput];
+ [output writeRawVarint64:value];
+ [output flush];
+
+ NSData* actual =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual);
+
+ // Also try computing size.
+ XCTAssertEqual(GPBComputeRawVarint64Size(value), (size_t)data.length);
+ }
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2) {
+ // Only do 32-bit write if the value fits in 32 bits.
+ if (GPBLogicalRightShift64(value, 32) == 0) {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput
+ bufferSize:blockSize];
+
+ [output writeRawVarint32:(int32_t)value];
+ [output flush];
+
+ NSData* actual =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual);
+ }
+
+ {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput
+ bufferSize:blockSize];
+
+ [output writeRawVarint64:value];
+ [output flush];
+
+ NSData* actual =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual);
+ }
+ }
+}
+
+- (void)assertWriteStringNoTag:(NSData*)data
+ value:(NSString *)value
+ context:(NSString *)contextMessage {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput];
+ [output writeStringNoTag:value];
+ [output flush];
+
+ NSData* actual =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual, @"%@", contextMessage);
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize <= 16; blockSize *= 2) {
+ rawOutput = [NSOutputStream outputStreamToMemory];
+ output = [GPBCodedOutputStream streamWithOutputStream:rawOutput
+ bufferSize:blockSize];
+ [output writeStringNoTag:value];
+ [output flush];
+
+ actual = [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(data, actual, @"%@", contextMessage);
+ }
+}
+
+- (void)testWriteVarint1 {
+ [self assertWriteVarint:bytes(0x00) value:0];
+}
+
+- (void)testWriteVarint2 {
+ [self assertWriteVarint:bytes(0x01) value:1];
+}
+
+- (void)testWriteVarint3 {
+ [self assertWriteVarint:bytes(0x7f) value:127];
+}
+
+- (void)testWriteVarint4 {
+ // 14882
+ [self assertWriteVarint:bytes(0xa2, 0x74) value:(0x22 << 0) | (0x74 << 7)];
+}
+
+- (void)testWriteVarint5 {
+ // 2961488830
+ [self assertWriteVarint:bytes(0xbe, 0xf7, 0x92, 0x84, 0x0b)
+ value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) |
+ (0x04 << 21) | (0x0bLL << 28)];
+}
+
+- (void)testWriteVarint6 {
+ // 64-bit
+ // 7256456126
+ [self assertWriteVarint:bytes(0xbe, 0xf7, 0x92, 0x84, 0x1b)
+ value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) |
+ (0x04 << 21) | (0x1bLL << 28)];
+}
+
+- (void)testWriteVarint7 {
+ // 41256202580718336
+ [self assertWriteVarint:bytes(0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49)
+ value:(0x00 << 0) | (0x66 << 7) | (0x6b << 14) |
+ (0x1c << 21) | (0x43LL << 28) | (0x49LL << 35) |
+ (0x24LL << 42) | (0x49LL << 49)];
+}
+
+- (void)testWriteVarint8 {
+ // 11964378330978735131
+ [self assertWriteVarint:bytes(0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85,
+ 0xa6, 0x01)
+ value:(0x1b << 0) | (0x28 << 7) | (0x79 << 14) |
+ (0x42 << 21) | (0x3bLL << 28) | (0x56LL << 35) |
+ (0x00LL << 42) | (0x05LL << 49) | (0x26LL << 56) |
+ (0x01LL << 63)];
+}
+
+- (void)testWriteLittleEndian {
+ [self assertWriteLittleEndian32:bytes(0x78, 0x56, 0x34, 0x12)
+ value:0x12345678];
+ [self assertWriteLittleEndian32:bytes(0xf0, 0xde, 0xbc, 0x9a)
+ value:0x9abcdef0];
+
+ [self assertWriteLittleEndian64:bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56,
+ 0x34, 0x12)
+ value:0x123456789abcdef0LL];
+ [self assertWriteLittleEndian64:bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde,
+ 0xbc, 0x9a)
+ value:0x9abcdef012345678LL];
+}
+
+- (void)testEncodeZigZag {
+ XCTAssertEqual(0U, GPBEncodeZigZag32(0));
+ XCTAssertEqual(1U, GPBEncodeZigZag32(-1));
+ XCTAssertEqual(2U, GPBEncodeZigZag32(1));
+ XCTAssertEqual(3U, GPBEncodeZigZag32(-2));
+ XCTAssertEqual(0x7FFFFFFEU, GPBEncodeZigZag32(0x3FFFFFFF));
+ XCTAssertEqual(0x7FFFFFFFU, GPBEncodeZigZag32(0xC0000000));
+ XCTAssertEqual(0xFFFFFFFEU, GPBEncodeZigZag32(0x7FFFFFFF));
+ XCTAssertEqual(0xFFFFFFFFU, GPBEncodeZigZag32(0x80000000));
+
+ XCTAssertEqual(0ULL, GPBEncodeZigZag64(0));
+ XCTAssertEqual(1ULL, GPBEncodeZigZag64(-1));
+ XCTAssertEqual(2ULL, GPBEncodeZigZag64(1));
+ XCTAssertEqual(3ULL, GPBEncodeZigZag64(-2));
+ XCTAssertEqual(0x000000007FFFFFFEULL,
+ GPBEncodeZigZag64(0x000000003FFFFFFFLL));
+ XCTAssertEqual(0x000000007FFFFFFFULL,
+ GPBEncodeZigZag64(0xFFFFFFFFC0000000LL));
+ XCTAssertEqual(0x00000000FFFFFFFEULL,
+ GPBEncodeZigZag64(0x000000007FFFFFFFLL));
+ XCTAssertEqual(0x00000000FFFFFFFFULL,
+ GPBEncodeZigZag64(0xFFFFFFFF80000000LL));
+ XCTAssertEqual(0xFFFFFFFFFFFFFFFEULL,
+ GPBEncodeZigZag64(0x7FFFFFFFFFFFFFFFLL));
+ XCTAssertEqual(0xFFFFFFFFFFFFFFFFULL,
+ GPBEncodeZigZag64(0x8000000000000000LL));
+
+ // Some easier-to-verify round-trip tests. The inputs (other than 0, 1, -1)
+ // were chosen semi-randomly via keyboard bashing.
+ XCTAssertEqual(0U, GPBEncodeZigZag32(GPBDecodeZigZag32(0)));
+ XCTAssertEqual(1U, GPBEncodeZigZag32(GPBDecodeZigZag32(1)));
+ XCTAssertEqual(-1U, GPBEncodeZigZag32(GPBDecodeZigZag32(-1)));
+ XCTAssertEqual(14927U, GPBEncodeZigZag32(GPBDecodeZigZag32(14927)));
+ XCTAssertEqual(-3612U, GPBEncodeZigZag32(GPBDecodeZigZag32(-3612)));
+
+ XCTAssertEqual(0ULL, GPBEncodeZigZag64(GPBDecodeZigZag64(0)));
+ XCTAssertEqual(1ULL, GPBEncodeZigZag64(GPBDecodeZigZag64(1)));
+ XCTAssertEqual(-1ULL, GPBEncodeZigZag64(GPBDecodeZigZag64(-1)));
+ XCTAssertEqual(14927ULL, GPBEncodeZigZag64(GPBDecodeZigZag64(14927)));
+ XCTAssertEqual(-3612ULL, GPBEncodeZigZag64(GPBDecodeZigZag64(-3612)));
+
+ XCTAssertEqual(856912304801416ULL,
+ GPBEncodeZigZag64(GPBDecodeZigZag64(856912304801416LL)));
+ XCTAssertEqual(-75123905439571256ULL,
+ GPBEncodeZigZag64(GPBDecodeZigZag64(-75123905439571256LL)));
+}
+
+- (void)testWriteWholeMessage {
+ // Not kGPBDefaultRepeatCount because we are comparing to a golden master file
+ // that was generated with 2.
+ TestAllTypes* message = [self allSetRepeatedCount:2];
+
+ NSData* rawBytes = message.data;
+ NSData* goldenData =
+ [self getDataFileNamed:@"golden_message" dataToWrite:rawBytes];
+ XCTAssertEqualObjects(rawBytes, goldenData);
+
+ // Try different block sizes.
+ for (int blockSize = 1; blockSize < 256; blockSize *= 2) {
+ NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
+ GPBCodedOutputStream* output =
+ [GPBCodedOutputStream streamWithOutputStream:rawOutput
+ bufferSize:blockSize];
+ [message writeToCodedOutputStream:output];
+ [output flush];
+
+ NSData* actual =
+ [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
+ XCTAssertEqualObjects(rawBytes, actual);
+ }
+
+ // Not kGPBDefaultRepeatCount because we are comparing to a golden master file
+ // that was generated with 2.
+ TestAllExtensions* extensions = [self allExtensionsSetRepeatedCount:2];
+ rawBytes = extensions.data;
+ goldenData = [self getDataFileNamed:@"golden_packed_fields_message"
+ dataToWrite:rawBytes];
+ XCTAssertEqualObjects(rawBytes, goldenData);
+}
+
+- (void)testCFStringGetCStringPtrAndStringsWithNullChars {
+ // This test exists to verify that CFStrings with embedded NULLs still expose
+ // their raw buffer if they are backed by UTF8 storage. If this fails, the
+ // quick/direct access paths in GPBCodedOutputStream that depend on
+ // CFStringGetCStringPtr need to be re-evalutated (maybe just removed).
+ // And yes, we do get NULLs in strings from some servers.
+
+ char zeroTest[] = "\0Test\0String";
+ // Note: there is a \0 at the end of this since it is a c-string.
+ NSString *asNSString = [[NSString alloc] initWithBytes:zeroTest
+ length:sizeof(zeroTest)
+ encoding:NSUTF8StringEncoding];
+ const char *cString =
+ CFStringGetCStringPtr((CFStringRef)asNSString, kCFStringEncodingUTF8);
+ XCTAssertTrue(cString != NULL);
+ // Again, if the above assert fails, then it means NSString no longer exposes
+ // the raw utf8 storage of a string created from utf8 input, so the code using
+ // CFStringGetCStringPtr in GPBCodedOutputStream will still work (it will take
+ // a different code path); but the optimizations for when
+ // CFStringGetCStringPtr does work could possibly go away.
+
+ XCTAssertEqual(sizeof(zeroTest),
+ [asNSString lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
+ XCTAssertTrue(0 == memcmp(cString, zeroTest, sizeof(zeroTest)));
+ [asNSString release];
+}
+
+- (void)testWriteStringsWithZeroChar {
+ // Unicode allows `\0` as a character, and NSString is a class cluster, so
+ // there are a few different classes that could end up beind a given string.
+ // Historically, we've seen differences based on constant strings in code and
+ // strings built via the NSString apis. So this round trips them to ensure
+ // they are acting as expected.
+
+ NSArray<NSString *> *strs = @[
+ @"\0at start",
+ @"in\0middle",
+ @"at end\0",
+ ];
+ int i = 0;
+ for (NSString *str in strs) {
+ NSData *asUTF8 = [str dataUsingEncoding:NSUTF8StringEncoding];
+ NSMutableData *expected = [NSMutableData data];
+ uint8_t lengthByte = (uint8_t)asUTF8.length;
+ [expected appendBytes:&lengthByte length:1];
+ [expected appendData:asUTF8];
+
+ NSString *context = [NSString stringWithFormat:@"Loop %d - Literal", i];
+ [self assertWriteStringNoTag:expected value:str context:context];
+
+ // Force a new string to be built which gets a different class from the
+ // NSString class cluster than the literal did.
+ NSString *str2 = [NSString stringWithFormat:@"%@", str];
+ context = [NSString stringWithFormat:@"Loop %d - Built", i];
+ [self assertWriteStringNoTag:expected value:str2 context:context];
+
+ ++i;
+ }
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBConcurrencyTests.m b/third_party/protobuf/objectivec/Tests/GPBConcurrencyTests.m
new file mode 100644
index 0000000000..daf75e7e72
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBConcurrencyTests.m
@@ -0,0 +1,206 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestObjc.pbobjc.h"
+
+static const int kNumThreads = 100;
+static const int kNumMessages = 100;
+
+// NOTE: Most of these tests don't "fail" in the sense that the XCTAsserts
+// trip. Rather, the asserts simply exercise the apis, and if there is
+// a concurancy issue, the NSAsserts in the runtime code fire and/or the
+// code just crashes outright.
+
+@interface ConcurrencyTests : GPBTestCase
+@end
+
+@implementation ConcurrencyTests
+
+- (NSArray *)createThreadsWithSelector:(SEL)selector object:(id)object {
+ NSMutableArray *array = [NSMutableArray array];
+ for (NSUInteger i = 0; i < kNumThreads; i++) {
+ NSThread *thread =
+ [[NSThread alloc] initWithTarget:self selector:selector object:object];
+ [array addObject:thread];
+ [thread release];
+ }
+ return array;
+}
+
+- (NSArray *)createMessagesWithType:(Class)msgType {
+ NSMutableArray *array = [NSMutableArray array];
+ for (NSUInteger i = 0; i < kNumMessages; i++) {
+ [array addObject:[msgType message]];
+ }
+ return array;
+}
+
+- (void)startThreads:(NSArray *)threads {
+ for (NSThread *thread in threads) {
+ [thread start];
+ }
+}
+
+- (void)joinThreads:(NSArray *)threads {
+ for (NSThread *thread in threads) {
+ while (![thread isFinished])
+ ;
+ }
+}
+
+- (void)readForeignMessage:(NSArray *)messages {
+ for (NSUInteger i = 0; i < 10; i++) {
+ for (TestAllTypes *message in messages) {
+ XCTAssertEqual(message.optionalForeignMessage.c, 0);
+ }
+ }
+}
+
+- (void)testConcurrentReadOfUnsetMessageField {
+ NSArray *messages = [self createMessagesWithType:[TestAllTypes class]];
+ NSArray *threads =
+ [self createThreadsWithSelector:@selector(readForeignMessage:)
+ object:messages];
+ [self startThreads:threads];
+ [self joinThreads:threads];
+ for (TestAllTypes *message in messages) {
+ XCTAssertFalse(message.hasOptionalForeignMessage);
+ }
+}
+
+- (void)readRepeatedInt32:(NSArray *)messages {
+ for (int i = 0; i < 10; i++) {
+ for (TestAllTypes *message in messages) {
+ XCTAssertEqual([message.repeatedInt32Array count], (NSUInteger)0);
+ }
+ }
+}
+
+- (void)testConcurrentReadOfUnsetRepeatedIntField {
+ NSArray *messages = [self createMessagesWithType:[TestAllTypes class]];
+ NSArray *threads =
+ [self createThreadsWithSelector:@selector(readRepeatedInt32:)
+ object:messages];
+ [self startThreads:threads];
+ [self joinThreads:threads];
+ for (TestAllTypes *message in messages) {
+ XCTAssertEqual([message.repeatedInt32Array count], (NSUInteger)0);
+ }
+}
+
+- (void)readRepeatedString:(NSArray *)messages {
+ for (int i = 0; i < 10; i++) {
+ for (TestAllTypes *message in messages) {
+ XCTAssertEqual([message.repeatedStringArray count], (NSUInteger)0);
+ }
+ }
+}
+
+- (void)testConcurrentReadOfUnsetRepeatedStringField {
+ NSArray *messages = [self createMessagesWithType:[TestAllTypes class]];
+ NSArray *threads =
+ [self createThreadsWithSelector:@selector(readRepeatedString:)
+ object:messages];
+ [self startThreads:threads];
+ [self joinThreads:threads];
+ for (TestAllTypes *message in messages) {
+ XCTAssertEqual([message.repeatedStringArray count], (NSUInteger)0);
+ }
+}
+
+- (void)readInt32Int32Map:(NSArray *)messages {
+ for (int i = 0; i < 10; i++) {
+ for (TestRecursiveMessageWithRepeatedField *message in messages) {
+ XCTAssertEqual([message.iToI count], (NSUInteger)0);
+ }
+ }
+}
+
+- (void)testConcurrentReadOfUnsetInt32Int32MapField {
+ NSArray *messages =
+ [self createMessagesWithType:[TestRecursiveMessageWithRepeatedField class]];
+ NSArray *threads =
+ [self createThreadsWithSelector:@selector(readInt32Int32Map:)
+ object:messages];
+ [self startThreads:threads];
+ [self joinThreads:threads];
+ for (TestRecursiveMessageWithRepeatedField *message in messages) {
+ XCTAssertEqual([message.iToI count], (NSUInteger)0);
+ }
+}
+
+- (void)readStringStringMap:(NSArray *)messages {
+ for (int i = 0; i < 10; i++) {
+ for (TestRecursiveMessageWithRepeatedField *message in messages) {
+ XCTAssertEqual([message.strToStr count], (NSUInteger)0);
+ }
+ }
+}
+
+- (void)testConcurrentReadOfUnsetStringStringMapField {
+ NSArray *messages =
+ [self createMessagesWithType:[TestRecursiveMessageWithRepeatedField class]];
+ NSArray *threads =
+ [self createThreadsWithSelector:@selector(readStringStringMap:)
+ object:messages];
+ [self startThreads:threads];
+ [self joinThreads:threads];
+ for (TestRecursiveMessageWithRepeatedField *message in messages) {
+ XCTAssertEqual([message.strToStr count], (NSUInteger)0);
+ }
+}
+
+- (void)readOptionalForeignMessageExtension:(NSArray *)messages {
+ for (int i = 0; i < 10; i++) {
+ for (TestAllExtensions *message in messages) {
+ ForeignMessage *foreign =
+ [message getExtension:[UnittestRoot optionalForeignMessageExtension]];
+ XCTAssertEqual(foreign.c, 0);
+ }
+ }
+}
+
+- (void)testConcurrentReadOfUnsetExtensionField {
+ NSArray *messages = [self createMessagesWithType:[TestAllExtensions class]];
+ SEL sel = @selector(readOptionalForeignMessageExtension:);
+ NSArray *threads = [self createThreadsWithSelector:sel object:messages];
+ [self startThreads:threads];
+ [self joinThreads:threads];
+ GPBExtensionDescriptor *extension =
+ [UnittestRoot optionalForeignMessageExtension];
+ for (TestAllExtensions *message in messages) {
+ XCTAssertFalse([message hasExtension:extension]);
+ }
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBDescriptorTests.m b/third_party/protobuf/objectivec/Tests/GPBDescriptorTests.m
new file mode 100644
index 0000000000..1e1c3de8d0
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDescriptorTests.m
@@ -0,0 +1,256 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import <objc/runtime.h>
+
+#import "GPBDescriptor.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestObjc.pbobjc.h"
+#import "google/protobuf/Descriptor.pbobjc.h"
+
+@interface DescriptorTests : GPBTestCase
+@end
+
+@implementation DescriptorTests
+
+- (void)testDescriptor_containingType {
+ GPBDescriptor *testAllTypesDesc = [TestAllTypes descriptor];
+ GPBDescriptor *nestedMessageDesc = [TestAllTypes_NestedMessage descriptor];
+ XCTAssertNil(testAllTypesDesc.containingType);
+ XCTAssertNotNil(nestedMessageDesc.containingType);
+ XCTAssertEqual(nestedMessageDesc.containingType, testAllTypesDesc); // Ptr comparison
+}
+
+- (void)testDescriptor_fullName {
+ GPBDescriptor *testAllTypesDesc = [TestAllTypes descriptor];
+ XCTAssertEqualObjects(testAllTypesDesc.fullName, @"protobuf_unittest.TestAllTypes");
+ GPBDescriptor *nestedMessageDesc = [TestAllTypes_NestedMessage descriptor];
+ XCTAssertEqualObjects(nestedMessageDesc.fullName, @"protobuf_unittest.TestAllTypes.NestedMessage");
+
+ // Prefixes removed.
+ GPBDescriptor *descDesc = [GPBDescriptorProto descriptor];
+ XCTAssertEqualObjects(descDesc.fullName, @"google.protobuf.DescriptorProto");
+ GPBDescriptor *descExtRngDesc = [GPBDescriptorProto_ExtensionRange descriptor];
+ XCTAssertEqualObjects(descExtRngDesc.fullName, @"google.protobuf.DescriptorProto.ExtensionRange");
+
+ // Things that get "_Class" added.
+ GPBDescriptor *pointDesc = [Point_Class descriptor];
+ XCTAssertEqualObjects(pointDesc.fullName, @"protobuf_unittest.Point");
+ GPBDescriptor *pointRectDesc = [Point_Rect descriptor];
+ XCTAssertEqualObjects(pointRectDesc.fullName, @"protobuf_unittest.Point.Rect");
+}
+
+- (void)testFieldDescriptor {
+ GPBDescriptor *descriptor = [TestAllTypes descriptor];
+
+ // Nested Enum
+ GPBFieldDescriptor *fieldDescriptorWithName =
+ [descriptor fieldWithName:@"optionalNestedEnum"];
+ XCTAssertNotNil(fieldDescriptorWithName);
+ GPBFieldDescriptor *fieldDescriptorWithNumber =
+ [descriptor fieldWithNumber:21];
+ XCTAssertNotNil(fieldDescriptorWithNumber);
+ XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
+ XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor);
+ XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name,
+ @"TestAllTypes_NestedEnum");
+
+ // Foreign Enum
+ fieldDescriptorWithName = [descriptor fieldWithName:@"optionalForeignEnum"];
+ XCTAssertNotNil(fieldDescriptorWithName);
+ fieldDescriptorWithNumber = [descriptor fieldWithNumber:22];
+ XCTAssertNotNil(fieldDescriptorWithNumber);
+ XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
+ XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor);
+ XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name,
+ @"ForeignEnum");
+
+ // Import Enum
+ fieldDescriptorWithName = [descriptor fieldWithName:@"optionalImportEnum"];
+ XCTAssertNotNil(fieldDescriptorWithName);
+ fieldDescriptorWithNumber = [descriptor fieldWithNumber:23];
+ XCTAssertNotNil(fieldDescriptorWithNumber);
+ XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
+ XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor);
+ XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name,
+ @"ImportEnum");
+
+ // Nested Message
+ fieldDescriptorWithName = [descriptor fieldWithName:@"optionalNestedMessage"];
+ XCTAssertNotNil(fieldDescriptorWithName);
+ fieldDescriptorWithNumber = [descriptor fieldWithNumber:18];
+ XCTAssertNotNil(fieldDescriptorWithNumber);
+ XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
+ XCTAssertNil(fieldDescriptorWithNumber.enumDescriptor);
+
+ // Foreign Message
+ fieldDescriptorWithName =
+ [descriptor fieldWithName:@"optionalForeignMessage"];
+ XCTAssertNotNil(fieldDescriptorWithName);
+ fieldDescriptorWithNumber = [descriptor fieldWithNumber:19];
+ XCTAssertNotNil(fieldDescriptorWithNumber);
+ XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
+ XCTAssertNil(fieldDescriptorWithNumber.enumDescriptor);
+
+ // Import Message
+ fieldDescriptorWithName = [descriptor fieldWithName:@"optionalImportMessage"];
+ XCTAssertNotNil(fieldDescriptorWithName);
+ fieldDescriptorWithNumber = [descriptor fieldWithNumber:20];
+ XCTAssertNotNil(fieldDescriptorWithNumber);
+ XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
+ XCTAssertNil(fieldDescriptorWithNumber.enumDescriptor);
+}
+
+- (void)testEnumDescriptor {
+ GPBEnumDescriptor *descriptor = TestAllTypes_NestedEnum_EnumDescriptor();
+
+ NSString *enumName = [descriptor enumNameForValue:1];
+ XCTAssertNotNil(enumName);
+ int32_t value;
+ XCTAssertTrue(
+ [descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Foo"]);
+ XCTAssertTrue(
+ [descriptor getValue:NULL forEnumName:@"TestAllTypes_NestedEnum_Foo"]);
+ XCTAssertEqual(value, TestAllTypes_NestedEnum_Foo);
+
+ enumName = [descriptor enumNameForValue:2];
+ XCTAssertNotNil(enumName);
+ XCTAssertTrue(
+ [descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Bar"]);
+ XCTAssertEqual(value, TestAllTypes_NestedEnum_Bar);
+
+ enumName = [descriptor enumNameForValue:3];
+ XCTAssertNotNil(enumName);
+ XCTAssertTrue(
+ [descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Baz"]);
+ XCTAssertEqual(value, TestAllTypes_NestedEnum_Baz);
+
+ // TextFormat
+ enumName = [descriptor textFormatNameForValue:1];
+ XCTAssertNotNil(enumName);
+ XCTAssertTrue([descriptor getValue:&value forEnumTextFormatName:@"FOO"]);
+ XCTAssertEqual(value, TestAllTypes_NestedEnum_Foo);
+
+ // Bad values
+ enumName = [descriptor enumNameForValue:0];
+ XCTAssertNil(enumName);
+ XCTAssertFalse([descriptor getValue:&value forEnumName:@"Unknown"]);
+ XCTAssertFalse([descriptor getValue:NULL forEnumName:@"Unknown"]);
+ XCTAssertFalse([descriptor getValue:&value
+ forEnumName:@"TestAllTypes_NestedEnum_Unknown"]);
+ XCTAssertFalse([descriptor getValue:NULL
+ forEnumName:@"TestAllTypes_NestedEnum_Unknown"]);
+ XCTAssertFalse([descriptor getValue:NULL forEnumTextFormatName:@"Unknown"]);
+ XCTAssertFalse([descriptor getValue:&value forEnumTextFormatName:@"Unknown"]);
+}
+
+- (void)testEnumValueValidator {
+ GPBDescriptor *descriptor = [TestAllTypes descriptor];
+ GPBFieldDescriptor *fieldDescriptor =
+ [descriptor fieldWithName:@"optionalNestedEnum"];
+
+ // Valid values
+ XCTAssertTrue([fieldDescriptor isValidEnumValue:1]);
+ XCTAssertTrue([fieldDescriptor isValidEnumValue:2]);
+ XCTAssertTrue([fieldDescriptor isValidEnumValue:3]);
+ XCTAssertTrue([fieldDescriptor isValidEnumValue:-1]);
+
+ // Invalid values
+ XCTAssertFalse([fieldDescriptor isValidEnumValue:4]);
+ XCTAssertFalse([fieldDescriptor isValidEnumValue:0]);
+ XCTAssertFalse([fieldDescriptor isValidEnumValue:-2]);
+}
+
+- (void)testOneofDescriptor {
+ GPBDescriptor *descriptor = [TestOneof2 descriptor];
+
+ // All fields should be listed.
+ XCTAssertEqual(descriptor.fields.count, 17U);
+
+ // There are two oneofs in there.
+ XCTAssertEqual(descriptor.oneofs.count, 2U);
+
+ GPBFieldDescriptor *fooStringField =
+ [descriptor fieldWithNumber:TestOneof2_FieldNumber_FooString];
+ XCTAssertNotNil(fooStringField);
+ GPBFieldDescriptor *barStringField =
+ [descriptor fieldWithNumber:TestOneof2_FieldNumber_BarString];
+ XCTAssertNotNil(barStringField);
+
+ // Check the oneofs to have what is expected.
+
+ GPBOneofDescriptor *oneofFoo = [descriptor oneofWithName:@"foo"];
+ XCTAssertNotNil(oneofFoo);
+ XCTAssertEqual(oneofFoo.fields.count, 9U);
+
+ // Pointer comparisons.
+ XCTAssertEqual([oneofFoo fieldWithNumber:TestOneof2_FieldNumber_FooString],
+ fooStringField);
+ XCTAssertEqual([oneofFoo fieldWithName:@"fooString"], fooStringField);
+
+ GPBOneofDescriptor *oneofBar = [descriptor oneofWithName:@"bar"];
+ XCTAssertNotNil(oneofBar);
+ XCTAssertEqual(oneofBar.fields.count, 6U);
+
+ // Pointer comparisons.
+ XCTAssertEqual([oneofBar fieldWithNumber:TestOneof2_FieldNumber_BarString],
+ barStringField);
+ XCTAssertEqual([oneofBar fieldWithName:@"barString"], barStringField);
+
+ // Unknown oneof not found.
+
+ XCTAssertNil([descriptor oneofWithName:@"mumble"]);
+ XCTAssertNil([descriptor oneofWithName:@"Foo"]);
+
+ // Unknown oneof item.
+
+ XCTAssertNil([oneofFoo fieldWithName:@"mumble"]);
+ XCTAssertNil([oneofFoo fieldWithNumber:666]);
+
+ // Field exists, but not in this oneof.
+
+ XCTAssertNil([oneofFoo fieldWithName:@"barString"]);
+ XCTAssertNil([oneofFoo fieldWithNumber:TestOneof2_FieldNumber_BarString]);
+ XCTAssertNil([oneofBar fieldWithName:@"fooString"]);
+ XCTAssertNil([oneofBar fieldWithNumber:TestOneof2_FieldNumber_FooString]);
+
+ // Check pointers back to the enclosing oneofs.
+ // (pointer comparisions)
+ XCTAssertEqual(fooStringField.containingOneof, oneofFoo);
+ XCTAssertEqual(barStringField.containingOneof, oneofBar);
+ GPBFieldDescriptor *bazString =
+ [descriptor fieldWithNumber:TestOneof2_FieldNumber_BazString];
+ XCTAssertNotNil(bazString);
+ XCTAssertNil(bazString.containingOneof);
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Bool.m b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Bool.m
new file mode 100644
index 0000000000..0dbe07b6e9
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Bool.m
@@ -0,0 +1,2418 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+#import <XCTest/XCTest.h>
+
+#import "GPBDictionary.h"
+
+#import "GPBTestUtilities.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+
+// Pull in the macros (using an external file because expanding all tests
+// in a single file makes a file that is failing to work with within Xcode.
+//%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm
+
+//%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(UInt32, uint32_t, 100U, 101U)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> UInt32
+
+@interface GPBBoolUInt32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBBoolUInt32DictionaryTests
+
+- (void)testEmpty {
+ GPBBoolUInt32Dictionary *dict = [[GPBBoolUInt32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:YES]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBBoolUInt32Dictionary *dict = [GPBBoolUInt32Dictionary dictionaryWithUInt32:100U forKey:YES];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:NO]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, YES);
+ XCTAssertEqual(aValue, 100U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const BOOL kKeys[] = { YES, NO };
+ const uint32_t kValues[] = { 100U, 101U };
+ GPBBoolUInt32Dictionary *dict =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 101U);
+
+ __block NSUInteger idx = 0;
+ BOOL *seenKeys = malloc(2 * sizeof(BOOL));
+ uint32_t *seenValues = malloc(2 * sizeof(uint32_t));
+ [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 2U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 2; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 2) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 0) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const BOOL kKeys1[] = { YES, NO };
+ const BOOL kKeys2[] = { NO, YES };
+ const uint32_t kValues1[] = { 100U, 101U };
+ const uint32_t kValues2[] = { 101U, 100U };
+ const uint32_t kValues3[] = { 101U };
+ GPBBoolUInt32Dictionary *dict1 =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBBoolUInt32Dictionary *dict1prime =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBBoolUInt32Dictionary *dict2 =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBBoolUInt32Dictionary *dict3 =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBBoolUInt32Dictionary *dict4 =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 Fewer pairs; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const BOOL kKeys[] = { YES, NO };
+ const uint32_t kValues[] = { 100U, 101U };
+ GPBBoolUInt32Dictionary *dict =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolUInt32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBBoolUInt32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const BOOL kKeys[] = { YES, NO };
+ const uint32_t kValues[] = { 100U, 101U };
+ GPBBoolUInt32Dictionary *dict =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolUInt32Dictionary *dict2 =
+ [GPBBoolUInt32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBBoolUInt32Dictionary *dict = [GPBBoolUInt32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt32:100U forKey:YES];
+ XCTAssertEqual(dict.count, 1U);
+
+ const BOOL kKeys[] = { NO };
+ const uint32_t kValues[] = { 101U };
+ GPBBoolUInt32Dictionary *dict2 =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 101U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const BOOL kKeys[] = { YES, NO};
+ const uint32_t kValues[] = { 100U, 101U };
+ GPBBoolUInt32Dictionary *dict =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+
+ [dict removeUInt32ForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:NO]);
+
+ // Remove again does nothing.
+ [dict removeUInt32ForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:NO]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:YES]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:NO]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kKeys[] = { YES, NO };
+ const uint32_t kValues[] = { 100U, 101U };
+ GPBBoolUInt32Dictionary *dict =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 101U);
+
+ [dict setUInt32:101U forKey:YES];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 101U);
+
+ [dict setUInt32:100U forKey:NO];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 100U);
+
+ const BOOL kKeys2[] = { NO, YES };
+ const uint32_t kValues2[] = { 101U, 100U };
+ GPBBoolUInt32Dictionary *dict2 =
+ [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 101U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Int32, int32_t, 200, 201)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Int32
+
+@interface GPBBoolInt32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBBoolInt32DictionaryTests
+
+- (void)testEmpty {
+ GPBBoolInt32Dictionary *dict = [[GPBBoolInt32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:YES]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBBoolInt32Dictionary *dict = [GPBBoolInt32Dictionary dictionaryWithInt32:200 forKey:YES];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:NO]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, YES);
+ XCTAssertEqual(aValue, 200);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const BOOL kKeys[] = { YES, NO };
+ const int32_t kValues[] = { 200, 201 };
+ GPBBoolInt32Dictionary *dict =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 201);
+
+ __block NSUInteger idx = 0;
+ BOOL *seenKeys = malloc(2 * sizeof(BOOL));
+ int32_t *seenValues = malloc(2 * sizeof(int32_t));
+ [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 2U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 2; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 2) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 0) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const BOOL kKeys1[] = { YES, NO };
+ const BOOL kKeys2[] = { NO, YES };
+ const int32_t kValues1[] = { 200, 201 };
+ const int32_t kValues2[] = { 201, 200 };
+ const int32_t kValues3[] = { 201 };
+ GPBBoolInt32Dictionary *dict1 =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBBoolInt32Dictionary *dict1prime =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBBoolInt32Dictionary *dict2 =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBBoolInt32Dictionary *dict3 =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBBoolInt32Dictionary *dict4 =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 Fewer pairs; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const BOOL kKeys[] = { YES, NO };
+ const int32_t kValues[] = { 200, 201 };
+ GPBBoolInt32Dictionary *dict =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolInt32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBBoolInt32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const BOOL kKeys[] = { YES, NO };
+ const int32_t kValues[] = { 200, 201 };
+ GPBBoolInt32Dictionary *dict =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolInt32Dictionary *dict2 =
+ [GPBBoolInt32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBBoolInt32Dictionary *dict = [GPBBoolInt32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt32:200 forKey:YES];
+ XCTAssertEqual(dict.count, 1U);
+
+ const BOOL kKeys[] = { NO };
+ const int32_t kValues[] = { 201 };
+ GPBBoolInt32Dictionary *dict2 =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 201);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const BOOL kKeys[] = { YES, NO};
+ const int32_t kValues[] = { 200, 201 };
+ GPBBoolInt32Dictionary *dict =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+
+ [dict removeInt32ForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:NO]);
+
+ // Remove again does nothing.
+ [dict removeInt32ForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:NO]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:YES]);
+ XCTAssertFalse([dict getInt32:NULL forKey:NO]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kKeys[] = { YES, NO };
+ const int32_t kValues[] = { 200, 201 };
+ GPBBoolInt32Dictionary *dict =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 201);
+
+ [dict setInt32:201 forKey:YES];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 201);
+
+ [dict setInt32:200 forKey:NO];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 200);
+
+ const BOOL kKeys2[] = { NO, YES };
+ const int32_t kValues2[] = { 201, 200 };
+ GPBBoolInt32Dictionary *dict2 =
+ [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt32:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt32:&value forKey:YES]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt32:&value forKey:NO]);
+ XCTAssertEqual(value, 201);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(UInt64, uint64_t, 300U, 301U)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> UInt64
+
+@interface GPBBoolUInt64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBBoolUInt64DictionaryTests
+
+- (void)testEmpty {
+ GPBBoolUInt64Dictionary *dict = [[GPBBoolUInt64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:YES]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBBoolUInt64Dictionary *dict = [GPBBoolUInt64Dictionary dictionaryWithUInt64:300U forKey:YES];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:NO]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, YES);
+ XCTAssertEqual(aValue, 300U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const BOOL kKeys[] = { YES, NO };
+ const uint64_t kValues[] = { 300U, 301U };
+ GPBBoolUInt64Dictionary *dict =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 301U);
+
+ __block NSUInteger idx = 0;
+ BOOL *seenKeys = malloc(2 * sizeof(BOOL));
+ uint64_t *seenValues = malloc(2 * sizeof(uint64_t));
+ [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 2U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 2; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 2) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 0) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const BOOL kKeys1[] = { YES, NO };
+ const BOOL kKeys2[] = { NO, YES };
+ const uint64_t kValues1[] = { 300U, 301U };
+ const uint64_t kValues2[] = { 301U, 300U };
+ const uint64_t kValues3[] = { 301U };
+ GPBBoolUInt64Dictionary *dict1 =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBBoolUInt64Dictionary *dict1prime =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBBoolUInt64Dictionary *dict2 =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBBoolUInt64Dictionary *dict3 =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBBoolUInt64Dictionary *dict4 =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 Fewer pairs; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const BOOL kKeys[] = { YES, NO };
+ const uint64_t kValues[] = { 300U, 301U };
+ GPBBoolUInt64Dictionary *dict =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolUInt64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBBoolUInt64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const BOOL kKeys[] = { YES, NO };
+ const uint64_t kValues[] = { 300U, 301U };
+ GPBBoolUInt64Dictionary *dict =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolUInt64Dictionary *dict2 =
+ [GPBBoolUInt64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBBoolUInt64Dictionary *dict = [GPBBoolUInt64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt64:300U forKey:YES];
+ XCTAssertEqual(dict.count, 1U);
+
+ const BOOL kKeys[] = { NO };
+ const uint64_t kValues[] = { 301U };
+ GPBBoolUInt64Dictionary *dict2 =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 301U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const BOOL kKeys[] = { YES, NO};
+ const uint64_t kValues[] = { 300U, 301U };
+ GPBBoolUInt64Dictionary *dict =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+
+ [dict removeUInt64ForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:NO]);
+
+ // Remove again does nothing.
+ [dict removeUInt64ForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:NO]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:YES]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:NO]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kKeys[] = { YES, NO };
+ const uint64_t kValues[] = { 300U, 301U };
+ GPBBoolUInt64Dictionary *dict =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 301U);
+
+ [dict setUInt64:301U forKey:YES];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 301U);
+
+ [dict setUInt64:300U forKey:NO];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 300U);
+
+ const BOOL kKeys2[] = { NO, YES };
+ const uint64_t kValues2[] = { 301U, 300U };
+ GPBBoolUInt64Dictionary *dict2 =
+ [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getUInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getUInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 301U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Int64, int64_t, 400, 401)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Int64
+
+@interface GPBBoolInt64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBBoolInt64DictionaryTests
+
+- (void)testEmpty {
+ GPBBoolInt64Dictionary *dict = [[GPBBoolInt64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:YES]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBBoolInt64Dictionary *dict = [GPBBoolInt64Dictionary dictionaryWithInt64:400 forKey:YES];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:NO]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, YES);
+ XCTAssertEqual(aValue, 400);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const BOOL kKeys[] = { YES, NO };
+ const int64_t kValues[] = { 400, 401 };
+ GPBBoolInt64Dictionary *dict =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 401);
+
+ __block NSUInteger idx = 0;
+ BOOL *seenKeys = malloc(2 * sizeof(BOOL));
+ int64_t *seenValues = malloc(2 * sizeof(int64_t));
+ [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 2U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 2; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 2) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 0) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const BOOL kKeys1[] = { YES, NO };
+ const BOOL kKeys2[] = { NO, YES };
+ const int64_t kValues1[] = { 400, 401 };
+ const int64_t kValues2[] = { 401, 400 };
+ const int64_t kValues3[] = { 401 };
+ GPBBoolInt64Dictionary *dict1 =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBBoolInt64Dictionary *dict1prime =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBBoolInt64Dictionary *dict2 =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBBoolInt64Dictionary *dict3 =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBBoolInt64Dictionary *dict4 =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 Fewer pairs; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const BOOL kKeys[] = { YES, NO };
+ const int64_t kValues[] = { 400, 401 };
+ GPBBoolInt64Dictionary *dict =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolInt64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBBoolInt64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const BOOL kKeys[] = { YES, NO };
+ const int64_t kValues[] = { 400, 401 };
+ GPBBoolInt64Dictionary *dict =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolInt64Dictionary *dict2 =
+ [GPBBoolInt64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBBoolInt64Dictionary *dict = [GPBBoolInt64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt64:400 forKey:YES];
+ XCTAssertEqual(dict.count, 1U);
+
+ const BOOL kKeys[] = { NO };
+ const int64_t kValues[] = { 401 };
+ GPBBoolInt64Dictionary *dict2 =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 401);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const BOOL kKeys[] = { YES, NO};
+ const int64_t kValues[] = { 400, 401 };
+ GPBBoolInt64Dictionary *dict =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+
+ [dict removeInt64ForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:NO]);
+
+ // Remove again does nothing.
+ [dict removeInt64ForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:NO]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:YES]);
+ XCTAssertFalse([dict getInt64:NULL forKey:NO]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kKeys[] = { YES, NO };
+ const int64_t kValues[] = { 400, 401 };
+ GPBBoolInt64Dictionary *dict =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 401);
+
+ [dict setInt64:401 forKey:YES];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 401);
+
+ [dict setInt64:400 forKey:NO];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 400);
+
+ const BOOL kKeys2[] = { NO, YES };
+ const int64_t kValues2[] = { 401, 400 };
+ GPBBoolInt64Dictionary *dict2 =
+ [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt64:NULL forKey:YES]);
+ XCTAssertTrue([dict getInt64:&value forKey:YES]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:NO]);
+ XCTAssertTrue([dict getInt64:&value forKey:NO]);
+ XCTAssertEqual(value, 401);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Bool, BOOL, NO, YES)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Bool
+
+@interface GPBBoolBoolDictionaryTests : XCTestCase
+@end
+
+@implementation GPBBoolBoolDictionaryTests
+
+- (void)testEmpty {
+ GPBBoolBoolDictionary *dict = [[GPBBoolBoolDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:YES]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBBoolBoolDictionary *dict = [GPBBoolBoolDictionary dictionaryWithBool:NO forKey:YES];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:NO]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, YES);
+ XCTAssertEqual(aValue, NO);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const BOOL kKeys[] = { YES, NO };
+ const BOOL kValues[] = { NO, YES };
+ GPBBoolBoolDictionary *dict =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:NO]);
+ XCTAssertTrue([dict getBool:&value forKey:NO]);
+ XCTAssertEqual(value, YES);
+
+ __block NSUInteger idx = 0;
+ BOOL *seenKeys = malloc(2 * sizeof(BOOL));
+ BOOL *seenValues = malloc(2 * sizeof(BOOL));
+ [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 2U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 2; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 2) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 0) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const BOOL kKeys1[] = { YES, NO };
+ const BOOL kKeys2[] = { NO, YES };
+ const BOOL kValues1[] = { NO, YES };
+ const BOOL kValues2[] = { YES, NO };
+ const BOOL kValues3[] = { YES };
+ GPBBoolBoolDictionary *dict1 =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBBoolBoolDictionary *dict1prime =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBBoolBoolDictionary *dict2 =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBBoolBoolDictionary *dict3 =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBBoolBoolDictionary *dict4 =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 Fewer pairs; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const BOOL kKeys[] = { YES, NO };
+ const BOOL kValues[] = { NO, YES };
+ GPBBoolBoolDictionary *dict =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolBoolDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBBoolBoolDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const BOOL kKeys[] = { YES, NO };
+ const BOOL kValues[] = { NO, YES };
+ GPBBoolBoolDictionary *dict =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolBoolDictionary *dict2 =
+ [GPBBoolBoolDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBBoolBoolDictionary *dict = [GPBBoolBoolDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setBool:NO forKey:YES];
+ XCTAssertEqual(dict.count, 1U);
+
+ const BOOL kKeys[] = { NO };
+ const BOOL kValues[] = { YES };
+ GPBBoolBoolDictionary *dict2 =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:NO]);
+ XCTAssertTrue([dict getBool:&value forKey:NO]);
+ XCTAssertEqual(value, YES);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const BOOL kKeys[] = { YES, NO};
+ const BOOL kValues[] = { NO, YES };
+ GPBBoolBoolDictionary *dict =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+
+ [dict removeBoolForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:NO]);
+
+ // Remove again does nothing.
+ [dict removeBoolForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:NO]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:YES]);
+ XCTAssertFalse([dict getBool:NULL forKey:NO]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kKeys[] = { YES, NO };
+ const BOOL kValues[] = { NO, YES };
+ GPBBoolBoolDictionary *dict =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:NO]);
+ XCTAssertTrue([dict getBool:&value forKey:NO]);
+ XCTAssertEqual(value, YES);
+
+ [dict setBool:YES forKey:YES];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:NO]);
+ XCTAssertTrue([dict getBool:&value forKey:NO]);
+ XCTAssertEqual(value, YES);
+
+ [dict setBool:NO forKey:NO];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:NO]);
+ XCTAssertTrue([dict getBool:&value forKey:NO]);
+ XCTAssertEqual(value, NO);
+
+ const BOOL kKeys2[] = { NO, YES };
+ const BOOL kValues2[] = { YES, NO };
+ GPBBoolBoolDictionary *dict2 =
+ [[GPBBoolBoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getBool:NULL forKey:YES]);
+ XCTAssertTrue([dict getBool:&value forKey:YES]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:NO]);
+ XCTAssertTrue([dict getBool:&value forKey:NO]);
+ XCTAssertEqual(value, YES);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Float, float, 500.f, 501.f)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Float
+
+@interface GPBBoolFloatDictionaryTests : XCTestCase
+@end
+
+@implementation GPBBoolFloatDictionaryTests
+
+- (void)testEmpty {
+ GPBBoolFloatDictionary *dict = [[GPBBoolFloatDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:YES]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBBoolFloatDictionary *dict = [GPBBoolFloatDictionary dictionaryWithFloat:500.f forKey:YES];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:NO]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, YES);
+ XCTAssertEqual(aValue, 500.f);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const BOOL kKeys[] = { YES, NO };
+ const float kValues[] = { 500.f, 501.f };
+ GPBBoolFloatDictionary *dict =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:NO]);
+ XCTAssertTrue([dict getFloat:&value forKey:NO]);
+ XCTAssertEqual(value, 501.f);
+
+ __block NSUInteger idx = 0;
+ BOOL *seenKeys = malloc(2 * sizeof(BOOL));
+ float *seenValues = malloc(2 * sizeof(float));
+ [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 2U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 2; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 2) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 0) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const BOOL kKeys1[] = { YES, NO };
+ const BOOL kKeys2[] = { NO, YES };
+ const float kValues1[] = { 500.f, 501.f };
+ const float kValues2[] = { 501.f, 500.f };
+ const float kValues3[] = { 501.f };
+ GPBBoolFloatDictionary *dict1 =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBBoolFloatDictionary *dict1prime =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBBoolFloatDictionary *dict2 =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBBoolFloatDictionary *dict3 =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBBoolFloatDictionary *dict4 =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 Fewer pairs; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const BOOL kKeys[] = { YES, NO };
+ const float kValues[] = { 500.f, 501.f };
+ GPBBoolFloatDictionary *dict =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolFloatDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBBoolFloatDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const BOOL kKeys[] = { YES, NO };
+ const float kValues[] = { 500.f, 501.f };
+ GPBBoolFloatDictionary *dict =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolFloatDictionary *dict2 =
+ [GPBBoolFloatDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBBoolFloatDictionary *dict = [GPBBoolFloatDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setFloat:500.f forKey:YES];
+ XCTAssertEqual(dict.count, 1U);
+
+ const BOOL kKeys[] = { NO };
+ const float kValues[] = { 501.f };
+ GPBBoolFloatDictionary *dict2 =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:NO]);
+ XCTAssertTrue([dict getFloat:&value forKey:NO]);
+ XCTAssertEqual(value, 501.f);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const BOOL kKeys[] = { YES, NO};
+ const float kValues[] = { 500.f, 501.f };
+ GPBBoolFloatDictionary *dict =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+
+ [dict removeFloatForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:NO]);
+
+ // Remove again does nothing.
+ [dict removeFloatForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:NO]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:YES]);
+ XCTAssertFalse([dict getFloat:NULL forKey:NO]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kKeys[] = { YES, NO };
+ const float kValues[] = { 500.f, 501.f };
+ GPBBoolFloatDictionary *dict =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:NO]);
+ XCTAssertTrue([dict getFloat:&value forKey:NO]);
+ XCTAssertEqual(value, 501.f);
+
+ [dict setFloat:501.f forKey:YES];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:NO]);
+ XCTAssertTrue([dict getFloat:&value forKey:NO]);
+ XCTAssertEqual(value, 501.f);
+
+ [dict setFloat:500.f forKey:NO];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:NO]);
+ XCTAssertTrue([dict getFloat:&value forKey:NO]);
+ XCTAssertEqual(value, 500.f);
+
+ const BOOL kKeys2[] = { NO, YES };
+ const float kValues2[] = { 501.f, 500.f };
+ GPBBoolFloatDictionary *dict2 =
+ [[GPBBoolFloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getFloat:NULL forKey:YES]);
+ XCTAssertTrue([dict getFloat:&value forKey:YES]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:NO]);
+ XCTAssertTrue([dict getFloat:&value forKey:NO]);
+ XCTAssertEqual(value, 501.f);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Double, double, 600., 601.)
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Double
+
+@interface GPBBoolDoubleDictionaryTests : XCTestCase
+@end
+
+@implementation GPBBoolDoubleDictionaryTests
+
+- (void)testEmpty {
+ GPBBoolDoubleDictionary *dict = [[GPBBoolDoubleDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:YES]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBBoolDoubleDictionary *dict = [GPBBoolDoubleDictionary dictionaryWithDouble:600. forKey:YES];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:NO]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, YES);
+ XCTAssertEqual(aValue, 600.);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const BOOL kKeys[] = { YES, NO };
+ const double kValues[] = { 600., 601. };
+ GPBBoolDoubleDictionary *dict =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:NO]);
+ XCTAssertTrue([dict getDouble:&value forKey:NO]);
+ XCTAssertEqual(value, 601.);
+
+ __block NSUInteger idx = 0;
+ BOOL *seenKeys = malloc(2 * sizeof(BOOL));
+ double *seenValues = malloc(2 * sizeof(double));
+ [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 2U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 2; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 2) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 0) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const BOOL kKeys1[] = { YES, NO };
+ const BOOL kKeys2[] = { NO, YES };
+ const double kValues1[] = { 600., 601. };
+ const double kValues2[] = { 601., 600. };
+ const double kValues3[] = { 601. };
+ GPBBoolDoubleDictionary *dict1 =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBBoolDoubleDictionary *dict1prime =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBBoolDoubleDictionary *dict2 =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBBoolDoubleDictionary *dict3 =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBBoolDoubleDictionary *dict4 =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 Fewer pairs; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const BOOL kKeys[] = { YES, NO };
+ const double kValues[] = { 600., 601. };
+ GPBBoolDoubleDictionary *dict =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolDoubleDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBBoolDoubleDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const BOOL kKeys[] = { YES, NO };
+ const double kValues[] = { 600., 601. };
+ GPBBoolDoubleDictionary *dict =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolDoubleDictionary *dict2 =
+ [GPBBoolDoubleDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBBoolDoubleDictionary *dict = [GPBBoolDoubleDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setDouble:600. forKey:YES];
+ XCTAssertEqual(dict.count, 1U);
+
+ const BOOL kKeys[] = { NO };
+ const double kValues[] = { 601. };
+ GPBBoolDoubleDictionary *dict2 =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:NO]);
+ XCTAssertTrue([dict getDouble:&value forKey:NO]);
+ XCTAssertEqual(value, 601.);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const BOOL kKeys[] = { YES, NO};
+ const double kValues[] = { 600., 601. };
+ GPBBoolDoubleDictionary *dict =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+
+ [dict removeDoubleForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:NO]);
+
+ // Remove again does nothing.
+ [dict removeDoubleForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:NO]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:YES]);
+ XCTAssertFalse([dict getDouble:NULL forKey:NO]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kKeys[] = { YES, NO };
+ const double kValues[] = { 600., 601. };
+ GPBBoolDoubleDictionary *dict =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:NO]);
+ XCTAssertTrue([dict getDouble:&value forKey:NO]);
+ XCTAssertEqual(value, 601.);
+
+ [dict setDouble:601. forKey:YES];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:NO]);
+ XCTAssertTrue([dict getDouble:&value forKey:NO]);
+ XCTAssertEqual(value, 601.);
+
+ [dict setDouble:600. forKey:NO];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:NO]);
+ XCTAssertTrue([dict getDouble:&value forKey:NO]);
+ XCTAssertEqual(value, 600.);
+
+ const BOOL kKeys2[] = { NO, YES };
+ const double kValues2[] = { 601., 600. };
+ GPBBoolDoubleDictionary *dict2 =
+ [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getDouble:NULL forKey:YES]);
+ XCTAssertTrue([dict getDouble:&value forKey:YES]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:NO]);
+ XCTAssertTrue([dict getDouble:&value forKey:NO]);
+ XCTAssertEqual(value, 601.);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND TESTS_FOR_BOOL_KEY_OBJECT_VALUE(Object, NSString*, @"abc", @"def")
+// This block of code is generated, do not edit it directly.
+
+#pragma mark - Bool -> Object
+
+@interface GPBBoolObjectDictionaryTests : XCTestCase
+@end
+
+@implementation GPBBoolObjectDictionaryTests
+
+- (void)testEmpty {
+ GPBBoolObjectDictionary<NSString*> *dict = [[GPBBoolObjectDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:YES]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBBoolObjectDictionary<NSString*> *dict = [GPBBoolObjectDictionary dictionaryWithObject:@"abc" forKey:YES];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
+ XCTAssertNil([dict objectForKey:NO]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertEqual(aKey, YES);
+ XCTAssertEqualObjects(aObject, @"abc");
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const BOOL kKeys[] = { YES, NO };
+ const NSString* kObjects[] = { @"abc", @"def" };
+ GPBBoolObjectDictionary<NSString*> *dict =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:NO], @"def");
+
+ __block NSUInteger idx = 0;
+ BOOL *seenKeys = malloc(2 * sizeof(BOOL));
+ NSString* *seenObjects = malloc(2 * sizeof(NSString*));
+ [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertLessThan(idx, 2U);
+ seenKeys[idx] = aKey;
+ seenObjects[idx] = aObject;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 2; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 2) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqualObjects(kObjects[i], seenObjects[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenObjects);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject)
+ if (idx == 0) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const BOOL kKeys1[] = { YES, NO };
+ const BOOL kKeys2[] = { NO, YES };
+ const NSString* kObjects1[] = { @"abc", @"def" };
+ const NSString* kObjects2[] = { @"def", @"abc" };
+ const NSString* kObjects3[] = { @"def" };
+ GPBBoolObjectDictionary<NSString*> *dict1 =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1);
+ GPBBoolObjectDictionary<NSString*> *dict1prime =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1prime);
+ GPBBoolObjectDictionary<NSString*> *dict2 =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ GPBBoolObjectDictionary<NSString*> *dict3 =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict3);
+ GPBBoolObjectDictionary<NSString*> *dict4 =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 Fewer pairs; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const BOOL kKeys[] = { YES, NO };
+ const NSString* kObjects[] = { @"abc", @"def" };
+ GPBBoolObjectDictionary<NSString*> *dict =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolObjectDictionary<NSString*> *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBBoolObjectDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const BOOL kKeys[] = { YES, NO };
+ const NSString* kObjects[] = { @"abc", @"def" };
+ GPBBoolObjectDictionary<NSString*> *dict =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBBoolObjectDictionary<NSString*> *dict2 =
+ [GPBBoolObjectDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBBoolObjectDictionary<NSString*> *dict = [GPBBoolObjectDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setObject:@"abc" forKey:YES];
+ XCTAssertEqual(dict.count, 1U);
+
+ const BOOL kKeys[] = { NO };
+ const NSString* kObjects[] = { @"def" };
+ GPBBoolObjectDictionary<NSString*> *dict2 =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+
+ XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:NO], @"def");
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const BOOL kKeys[] = { YES, NO};
+ const NSString* kObjects[] = { @"abc", @"def" };
+ GPBBoolObjectDictionary<NSString*> *dict =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+
+ [dict removeObjectForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
+ XCTAssertNil([dict objectForKey:NO]);
+
+ // Remove again does nothing.
+ [dict removeObjectForKey:NO];
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
+ XCTAssertNil([dict objectForKey:NO]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:YES]);
+ XCTAssertNil([dict objectForKey:NO]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const BOOL kKeys[] = { YES, NO };
+ const NSString* kObjects[] = { @"abc", @"def" };
+ GPBBoolObjectDictionary<NSString*> *dict =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:NO], @"def");
+
+ [dict setObject:@"def" forKey:YES];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:YES], @"def");
+ XCTAssertEqualObjects([dict objectForKey:NO], @"def");
+
+ [dict setObject:@"abc" forKey:NO];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:YES], @"def");
+ XCTAssertEqualObjects([dict objectForKey:NO], @"abc");
+
+ const BOOL kKeys2[] = { NO, YES };
+ const NSString* kObjects2[] = { @"def", @"abc" };
+ GPBBoolObjectDictionary<NSString*> *dict2 =
+ [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:NO], @"def");
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND-END (8 expansions)
+
+
diff --git a/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Int32.m b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Int32.m
new file mode 100644
index 0000000000..c539bdc2ed
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Int32.m
@@ -0,0 +1,3647 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+#import <XCTest/XCTest.h>
+
+#import "GPBDictionary.h"
+
+#import "GPBTestUtilities.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+
+// Pull in the macros (using an external file because expanding all tests
+// in a single file makes a file that is failing to work with within Xcode.
+//%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm
+
+//%PDDM-EXPAND TEST_FOR_POD_KEY(Int32, int32_t, 11, 12, 13, 14)
+// This block of code is generated, do not edit it directly.
+
+// To let the testing macros work, add some extra methods to simplify things.
+@interface GPBInt32EnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(int32_t)key;
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count;
+@end
+
+static BOOL TestingEnum_IsValidValue(int32_t value) {
+ switch (value) {
+ case 700:
+ case 701:
+ case 702:
+ case 703:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+@implementation GPBInt32EnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(int32_t)key {
+ // Cast is needed to compiler knows what class we are invoking initWithValues: on to get the
+ // type correct.
+ return [[(GPBInt32EnumDictionary*)[self alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const int32_t [])keys
+ count:(NSUInteger)count {
+ return [self initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:values
+ forKeys:keys
+ count:count];
+}
+@end
+
+
+#pragma mark - Int32 -> UInt32
+
+@interface GPBInt32UInt32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32UInt32DictionaryTests
+
+- (void)testEmpty {
+ GPBInt32UInt32Dictionary *dict = [[GPBInt32UInt32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:11]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(int32_t aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32UInt32Dictionary *dict = [GPBInt32UInt32Dictionary dictionaryWithUInt32:100U forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:12]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(int32_t aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqual(aValue, 100U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const uint32_t kValues[] = { 100U, 101U, 102U };
+ GPBInt32UInt32Dictionary *dict =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:&value forKey:12]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ uint32_t *seenValues = malloc(3 * sizeof(uint32_t));
+ [dict enumerateKeysAndUInt32sUsingBlock:^(int32_t aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt32sUsingBlock:^(int32_t aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const uint32_t kValues1[] = { 100U, 101U, 102U };
+ const uint32_t kValues2[] = { 100U, 103U, 102U };
+ const uint32_t kValues3[] = { 100U, 101U, 102U, 103U };
+ GPBInt32UInt32Dictionary *dict1 =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32UInt32Dictionary *dict1prime =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32UInt32Dictionary *dict2 =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32UInt32Dictionary *dict3 =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32UInt32Dictionary *dict4 =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBInt32UInt32Dictionary *dict =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32UInt32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32UInt32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBInt32UInt32Dictionary *dict =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32UInt32Dictionary *dict2 =
+ [GPBInt32UInt32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32UInt32Dictionary *dict = [GPBInt32UInt32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt32:100U forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const uint32_t kValues[] = { 101U, 102U, 103U };
+ GPBInt32UInt32Dictionary *dict2 =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:&value forKey:12]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt32:&value forKey:14]);
+ XCTAssertEqual(value, 103U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBInt32UInt32Dictionary *dict =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt32ForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt32:&value forKey:14]);
+ XCTAssertEqual(value, 103U);
+
+ // Remove again does nothing.
+ [dict removeUInt32ForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt32:&value forKey:14]);
+ XCTAssertEqual(value, 103U);
+
+ [dict removeUInt32ForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:11]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:12]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:13]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBInt32UInt32Dictionary *dict =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:&value forKey:12]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt32:&value forKey:14]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:103U forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:&value forKey:12]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt32:&value forKey:14]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:101U forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:&value forKey:12]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt32:&value forKey:14]);
+ XCTAssertEqual(value, 101U);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const uint32_t kValues2[] = { 102U, 100U };
+ GPBInt32UInt32Dictionary *dict2 =
+ [[GPBInt32UInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt32:&value forKey:11]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt32:&value forKey:12]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt32:&value forKey:13]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt32:&value forKey:14]);
+ XCTAssertEqual(value, 101U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> Int32
+
+@interface GPBInt32Int32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32Int32DictionaryTests
+
+- (void)testEmpty {
+ GPBInt32Int32Dictionary *dict = [[GPBInt32Int32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:11]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32Int32Dictionary *dict = [GPBInt32Int32Dictionary dictionaryWithInt32:200 forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:12]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqual(aValue, 200);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const int32_t kValues[] = { 200, 201, 202 };
+ GPBInt32Int32Dictionary *dict =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:&value forKey:12]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndInt32sUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt32sUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const int32_t kValues1[] = { 200, 201, 202 };
+ const int32_t kValues2[] = { 200, 203, 202 };
+ const int32_t kValues3[] = { 200, 201, 202, 203 };
+ GPBInt32Int32Dictionary *dict1 =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32Int32Dictionary *dict1prime =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32Int32Dictionary *dict2 =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32Int32Dictionary *dict3 =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32Int32Dictionary *dict4 =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBInt32Int32Dictionary *dict =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32Int32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32Int32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBInt32Int32Dictionary *dict =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32Int32Dictionary *dict2 =
+ [GPBInt32Int32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32Int32Dictionary *dict = [GPBInt32Int32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt32:200 forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const int32_t kValues[] = { 201, 202, 203 };
+ GPBInt32Int32Dictionary *dict2 =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:&value forKey:12]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getInt32:&value forKey:14]);
+ XCTAssertEqual(value, 203);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBInt32Int32Dictionary *dict =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt32ForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getInt32:&value forKey:14]);
+ XCTAssertEqual(value, 203);
+
+ // Remove again does nothing.
+ [dict removeInt32ForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getInt32:&value forKey:14]);
+ XCTAssertEqual(value, 203);
+
+ [dict removeInt32ForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:11]);
+ XCTAssertFalse([dict getInt32:NULL forKey:12]);
+ XCTAssertFalse([dict getInt32:NULL forKey:13]);
+ XCTAssertFalse([dict getInt32:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBInt32Int32Dictionary *dict =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:&value forKey:12]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getInt32:&value forKey:14]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:203 forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:&value forKey:12]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getInt32:&value forKey:14]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:201 forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:&value forKey:12]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getInt32:&value forKey:14]);
+ XCTAssertEqual(value, 201);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const int32_t kValues2[] = { 202, 200 };
+ GPBInt32Int32Dictionary *dict2 =
+ [[GPBInt32Int32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:11]);
+ XCTAssertTrue([dict getInt32:&value forKey:11]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:12]);
+ XCTAssertTrue([dict getInt32:&value forKey:12]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:13]);
+ XCTAssertTrue([dict getInt32:&value forKey:13]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:14]);
+ XCTAssertTrue([dict getInt32:&value forKey:14]);
+ XCTAssertEqual(value, 201);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> UInt64
+
+@interface GPBInt32UInt64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32UInt64DictionaryTests
+
+- (void)testEmpty {
+ GPBInt32UInt64Dictionary *dict = [[GPBInt32UInt64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:11]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(int32_t aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32UInt64Dictionary *dict = [GPBInt32UInt64Dictionary dictionaryWithUInt64:300U forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:12]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(int32_t aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqual(aValue, 300U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const uint64_t kValues[] = { 300U, 301U, 302U };
+ GPBInt32UInt64Dictionary *dict =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:&value forKey:12]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ uint64_t *seenValues = malloc(3 * sizeof(uint64_t));
+ [dict enumerateKeysAndUInt64sUsingBlock:^(int32_t aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt64sUsingBlock:^(int32_t aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const uint64_t kValues1[] = { 300U, 301U, 302U };
+ const uint64_t kValues2[] = { 300U, 303U, 302U };
+ const uint64_t kValues3[] = { 300U, 301U, 302U, 303U };
+ GPBInt32UInt64Dictionary *dict1 =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32UInt64Dictionary *dict1prime =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32UInt64Dictionary *dict2 =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32UInt64Dictionary *dict3 =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32UInt64Dictionary *dict4 =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBInt32UInt64Dictionary *dict =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32UInt64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32UInt64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBInt32UInt64Dictionary *dict =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32UInt64Dictionary *dict2 =
+ [GPBInt32UInt64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32UInt64Dictionary *dict = [GPBInt32UInt64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt64:300U forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const uint64_t kValues[] = { 301U, 302U, 303U };
+ GPBInt32UInt64Dictionary *dict2 =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:&value forKey:12]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt64:&value forKey:14]);
+ XCTAssertEqual(value, 303U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBInt32UInt64Dictionary *dict =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt64ForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt64:&value forKey:14]);
+ XCTAssertEqual(value, 303U);
+
+ // Remove again does nothing.
+ [dict removeUInt64ForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt64:&value forKey:14]);
+ XCTAssertEqual(value, 303U);
+
+ [dict removeUInt64ForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:11]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:12]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:13]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBInt32UInt64Dictionary *dict =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:&value forKey:12]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt64:&value forKey:14]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:303U forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:&value forKey:12]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt64:&value forKey:14]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:301U forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:&value forKey:12]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt64:&value forKey:14]);
+ XCTAssertEqual(value, 301U);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const uint64_t kValues2[] = { 302U, 300U };
+ GPBInt32UInt64Dictionary *dict2 =
+ [[GPBInt32UInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getUInt64:&value forKey:11]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getUInt64:&value forKey:12]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getUInt64:&value forKey:13]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getUInt64:&value forKey:14]);
+ XCTAssertEqual(value, 301U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> Int64
+
+@interface GPBInt32Int64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32Int64DictionaryTests
+
+- (void)testEmpty {
+ GPBInt32Int64Dictionary *dict = [[GPBInt32Int64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:11]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(int32_t aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32Int64Dictionary *dict = [GPBInt32Int64Dictionary dictionaryWithInt64:400 forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:12]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(int32_t aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqual(aValue, 400);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const int64_t kValues[] = { 400, 401, 402 };
+ GPBInt32Int64Dictionary *dict =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:&value forKey:12]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ int64_t *seenValues = malloc(3 * sizeof(int64_t));
+ [dict enumerateKeysAndInt64sUsingBlock:^(int32_t aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt64sUsingBlock:^(int32_t aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const int64_t kValues1[] = { 400, 401, 402 };
+ const int64_t kValues2[] = { 400, 403, 402 };
+ const int64_t kValues3[] = { 400, 401, 402, 403 };
+ GPBInt32Int64Dictionary *dict1 =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32Int64Dictionary *dict1prime =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32Int64Dictionary *dict2 =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32Int64Dictionary *dict3 =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32Int64Dictionary *dict4 =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBInt32Int64Dictionary *dict =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32Int64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32Int64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBInt32Int64Dictionary *dict =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32Int64Dictionary *dict2 =
+ [GPBInt32Int64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32Int64Dictionary *dict = [GPBInt32Int64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt64:400 forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const int64_t kValues[] = { 401, 402, 403 };
+ GPBInt32Int64Dictionary *dict2 =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:&value forKey:12]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getInt64:&value forKey:14]);
+ XCTAssertEqual(value, 403);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBInt32Int64Dictionary *dict =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt64ForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getInt64:&value forKey:14]);
+ XCTAssertEqual(value, 403);
+
+ // Remove again does nothing.
+ [dict removeInt64ForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getInt64:&value forKey:14]);
+ XCTAssertEqual(value, 403);
+
+ [dict removeInt64ForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:11]);
+ XCTAssertFalse([dict getInt64:NULL forKey:12]);
+ XCTAssertFalse([dict getInt64:NULL forKey:13]);
+ XCTAssertFalse([dict getInt64:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBInt32Int64Dictionary *dict =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:&value forKey:12]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getInt64:&value forKey:14]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:403 forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:&value forKey:12]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getInt64:&value forKey:14]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:401 forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:&value forKey:12]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getInt64:&value forKey:14]);
+ XCTAssertEqual(value, 401);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const int64_t kValues2[] = { 402, 400 };
+ GPBInt32Int64Dictionary *dict2 =
+ [[GPBInt32Int64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:11]);
+ XCTAssertTrue([dict getInt64:&value forKey:11]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:12]);
+ XCTAssertTrue([dict getInt64:&value forKey:12]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:13]);
+ XCTAssertTrue([dict getInt64:&value forKey:13]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:14]);
+ XCTAssertTrue([dict getInt64:&value forKey:14]);
+ XCTAssertEqual(value, 401);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> Bool
+
+@interface GPBInt32BoolDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32BoolDictionaryTests
+
+- (void)testEmpty {
+ GPBInt32BoolDictionary *dict = [[GPBInt32BoolDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:11]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(int32_t aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32BoolDictionary *dict = [GPBInt32BoolDictionary dictionaryWithBool:YES forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:12]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(int32_t aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqual(aValue, YES);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const BOOL kValues[] = { YES, YES, NO };
+ GPBInt32BoolDictionary *dict =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:&value forKey:12]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ BOOL *seenValues = malloc(3 * sizeof(BOOL));
+ [dict enumerateKeysAndBoolsUsingBlock:^(int32_t aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndBoolsUsingBlock:^(int32_t aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const BOOL kValues1[] = { YES, YES, NO };
+ const BOOL kValues2[] = { YES, NO, NO };
+ const BOOL kValues3[] = { YES, YES, NO, NO };
+ GPBInt32BoolDictionary *dict1 =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32BoolDictionary *dict1prime =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32BoolDictionary *dict2 =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32BoolDictionary *dict3 =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32BoolDictionary *dict4 =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBInt32BoolDictionary *dict =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32BoolDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32BoolDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBInt32BoolDictionary *dict =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32BoolDictionary *dict2 =
+ [GPBInt32BoolDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32BoolDictionary *dict = [GPBInt32BoolDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setBool:YES forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const BOOL kValues[] = { YES, NO, NO };
+ GPBInt32BoolDictionary *dict2 =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:&value forKey:12]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:14]);
+ XCTAssertTrue([dict getBool:&value forKey:14]);
+ XCTAssertEqual(value, NO);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBInt32BoolDictionary *dict =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeBoolForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:14]);
+ XCTAssertTrue([dict getBool:&value forKey:14]);
+ XCTAssertEqual(value, NO);
+
+ // Remove again does nothing.
+ [dict removeBoolForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:14]);
+ XCTAssertTrue([dict getBool:&value forKey:14]);
+ XCTAssertEqual(value, NO);
+
+ [dict removeBoolForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:11]);
+ XCTAssertFalse([dict getBool:NULL forKey:12]);
+ XCTAssertFalse([dict getBool:NULL forKey:13]);
+ XCTAssertFalse([dict getBool:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBInt32BoolDictionary *dict =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:&value forKey:12]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:14]);
+ XCTAssertTrue([dict getBool:&value forKey:14]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:NO forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:&value forKey:12]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:14]);
+ XCTAssertTrue([dict getBool:&value forKey:14]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:YES forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:&value forKey:12]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:14]);
+ XCTAssertTrue([dict getBool:&value forKey:14]);
+ XCTAssertEqual(value, YES);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const BOOL kValues2[] = { NO, YES };
+ GPBInt32BoolDictionary *dict2 =
+ [[GPBInt32BoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:11]);
+ XCTAssertTrue([dict getBool:&value forKey:11]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:12]);
+ XCTAssertTrue([dict getBool:&value forKey:12]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:13]);
+ XCTAssertTrue([dict getBool:&value forKey:13]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:14]);
+ XCTAssertTrue([dict getBool:&value forKey:14]);
+ XCTAssertEqual(value, YES);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> Float
+
+@interface GPBInt32FloatDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32FloatDictionaryTests
+
+- (void)testEmpty {
+ GPBInt32FloatDictionary *dict = [[GPBInt32FloatDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:11]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(int32_t aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32FloatDictionary *dict = [GPBInt32FloatDictionary dictionaryWithFloat:500.f forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:12]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(int32_t aKey, float aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqual(aValue, 500.f);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const float kValues[] = { 500.f, 501.f, 502.f };
+ GPBInt32FloatDictionary *dict =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:&value forKey:12]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ float *seenValues = malloc(3 * sizeof(float));
+ [dict enumerateKeysAndFloatsUsingBlock:^(int32_t aKey, float aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndFloatsUsingBlock:^(int32_t aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const float kValues1[] = { 500.f, 501.f, 502.f };
+ const float kValues2[] = { 500.f, 503.f, 502.f };
+ const float kValues3[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt32FloatDictionary *dict1 =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32FloatDictionary *dict1prime =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32FloatDictionary *dict2 =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32FloatDictionary *dict3 =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32FloatDictionary *dict4 =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt32FloatDictionary *dict =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32FloatDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32FloatDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt32FloatDictionary *dict =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32FloatDictionary *dict2 =
+ [GPBInt32FloatDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32FloatDictionary *dict = [GPBInt32FloatDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setFloat:500.f forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const float kValues[] = { 501.f, 502.f, 503.f };
+ GPBInt32FloatDictionary *dict2 =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:&value forKey:12]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:14]);
+ XCTAssertTrue([dict getFloat:&value forKey:14]);
+ XCTAssertEqual(value, 503.f);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt32FloatDictionary *dict =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeFloatForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:14]);
+ XCTAssertTrue([dict getFloat:&value forKey:14]);
+ XCTAssertEqual(value, 503.f);
+
+ // Remove again does nothing.
+ [dict removeFloatForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:14]);
+ XCTAssertTrue([dict getFloat:&value forKey:14]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict removeFloatForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:11]);
+ XCTAssertFalse([dict getFloat:NULL forKey:12]);
+ XCTAssertFalse([dict getFloat:NULL forKey:13]);
+ XCTAssertFalse([dict getFloat:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt32FloatDictionary *dict =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:&value forKey:12]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:14]);
+ XCTAssertTrue([dict getFloat:&value forKey:14]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:503.f forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:&value forKey:12]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:14]);
+ XCTAssertTrue([dict getFloat:&value forKey:14]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:501.f forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:&value forKey:12]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:14]);
+ XCTAssertTrue([dict getFloat:&value forKey:14]);
+ XCTAssertEqual(value, 501.f);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const float kValues2[] = { 502.f, 500.f };
+ GPBInt32FloatDictionary *dict2 =
+ [[GPBInt32FloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:11]);
+ XCTAssertTrue([dict getFloat:&value forKey:11]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:12]);
+ XCTAssertTrue([dict getFloat:&value forKey:12]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:13]);
+ XCTAssertTrue([dict getFloat:&value forKey:13]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:14]);
+ XCTAssertTrue([dict getFloat:&value forKey:14]);
+ XCTAssertEqual(value, 501.f);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> Double
+
+@interface GPBInt32DoubleDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32DoubleDictionaryTests
+
+- (void)testEmpty {
+ GPBInt32DoubleDictionary *dict = [[GPBInt32DoubleDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:11]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(int32_t aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32DoubleDictionary *dict = [GPBInt32DoubleDictionary dictionaryWithDouble:600. forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:12]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(int32_t aKey, double aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqual(aValue, 600.);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const double kValues[] = { 600., 601., 602. };
+ GPBInt32DoubleDictionary *dict =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:&value forKey:12]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ double *seenValues = malloc(3 * sizeof(double));
+ [dict enumerateKeysAndDoublesUsingBlock:^(int32_t aKey, double aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndDoublesUsingBlock:^(int32_t aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const double kValues1[] = { 600., 601., 602. };
+ const double kValues2[] = { 600., 603., 602. };
+ const double kValues3[] = { 600., 601., 602., 603. };
+ GPBInt32DoubleDictionary *dict1 =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32DoubleDictionary *dict1prime =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32DoubleDictionary *dict2 =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32DoubleDictionary *dict3 =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32DoubleDictionary *dict4 =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBInt32DoubleDictionary *dict =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32DoubleDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32DoubleDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBInt32DoubleDictionary *dict =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32DoubleDictionary *dict2 =
+ [GPBInt32DoubleDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32DoubleDictionary *dict = [GPBInt32DoubleDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setDouble:600. forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const double kValues[] = { 601., 602., 603. };
+ GPBInt32DoubleDictionary *dict2 =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:&value forKey:12]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:14]);
+ XCTAssertTrue([dict getDouble:&value forKey:14]);
+ XCTAssertEqual(value, 603.);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBInt32DoubleDictionary *dict =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeDoubleForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:14]);
+ XCTAssertTrue([dict getDouble:&value forKey:14]);
+ XCTAssertEqual(value, 603.);
+
+ // Remove again does nothing.
+ [dict removeDoubleForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:14]);
+ XCTAssertTrue([dict getDouble:&value forKey:14]);
+ XCTAssertEqual(value, 603.);
+
+ [dict removeDoubleForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:11]);
+ XCTAssertFalse([dict getDouble:NULL forKey:12]);
+ XCTAssertFalse([dict getDouble:NULL forKey:13]);
+ XCTAssertFalse([dict getDouble:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBInt32DoubleDictionary *dict =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:&value forKey:12]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:14]);
+ XCTAssertTrue([dict getDouble:&value forKey:14]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:603. forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:&value forKey:12]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:14]);
+ XCTAssertTrue([dict getDouble:&value forKey:14]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:601. forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:&value forKey:12]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:14]);
+ XCTAssertTrue([dict getDouble:&value forKey:14]);
+ XCTAssertEqual(value, 601.);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const double kValues2[] = { 602., 600. };
+ GPBInt32DoubleDictionary *dict2 =
+ [[GPBInt32DoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:11]);
+ XCTAssertTrue([dict getDouble:&value forKey:11]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:12]);
+ XCTAssertTrue([dict getDouble:&value forKey:12]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:13]);
+ XCTAssertTrue([dict getDouble:&value forKey:13]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:14]);
+ XCTAssertTrue([dict getDouble:&value forKey:14]);
+ XCTAssertEqual(value, 601.);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> Enum
+
+@interface GPBInt32EnumDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32EnumDictionaryTests
+
+- (void)testEmpty {
+ GPBInt32EnumDictionary *dict = [[GPBInt32EnumDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:11]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32EnumDictionary *dict = [GPBInt32EnumDictionary dictionaryWithEnum:700 forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqual(aValue, 700);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const int32_t kValues[] = { 700, 701, 702 };
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndEnumsUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const int32_t kValues1[] = { 700, 701, 702 };
+ const int32_t kValues2[] = { 700, 703, 702 };
+ const int32_t kValues3[] = { 700, 701, 702, 703 };
+ GPBInt32EnumDictionary *dict1 =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32EnumDictionary *dict1prime =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32EnumDictionary *dict2 =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32EnumDictionary *dict3 =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32EnumDictionary *dict4 =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32EnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32EnumDictionary *dict2 =
+ [GPBInt32EnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32EnumDictionary *dict = [GPBInt32EnumDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setEnum:700 forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const int32_t kValues[] = { 701, 702, 703 };
+ GPBInt32EnumDictionary *dict2 =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 703);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 703);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 703);
+
+ [dict removeEnumForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:11]);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ XCTAssertFalse([dict getEnum:NULL forKey:13]);
+ XCTAssertFalse([dict getEnum:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:703 forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:701 forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 701);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const int32_t kValues2[] = { 702, 700 };
+ GPBInt32EnumDictionary *dict2 =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 701);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> Enum (Unknown Enums)
+
+@interface GPBInt32EnumDictionaryUnknownEnumTests : XCTestCase
+@end
+
+@implementation GPBInt32EnumDictionaryUnknownEnumTests
+
+- (void)testRawBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const int32_t kValues[] = { 700, 801, 702 };
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue(dict.validationFunc == TestingEnum_IsValidValue); // Pointer comparison
+ int32_t value;
+ XCTAssertTrue([dict getRawValue:NULL forKey:11]);
+ XCTAssertTrue([dict getRawValue:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:12]);
+ XCTAssertTrue([dict getRawValue:&value forKey:12]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getRawValue:NULL forKey:13]);
+ XCTAssertTrue([dict getRawValue:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getRawValue:NULL forKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ if (i == 1) {
+ XCTAssertEqual(kGPBUnrecognizedEnumeratorValue, seenValues[j], @"i = %d, j = %d", i, j);
+ } else {
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(int32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEqualityWithUnknowns {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const int32_t kValues1[] = { 700, 801, 702 }; // Unknown
+ const int32_t kValues2[] = { 700, 803, 702 }; // Unknown
+ const int32_t kValues3[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBInt32EnumDictionary *dict1 =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32EnumDictionary *dict1prime =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32EnumDictionary *dict2 =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32EnumDictionary *dict3 =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32EnumDictionary *dict4 =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopyWithUnknowns {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknown
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertEqualObjects(dict, dict2);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32EnumDictionary *dict2 =
+ [GPBInt32EnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ [dict release];
+}
+
+- (void)testUnknownAdds {
+ GPBInt32EnumDictionary *dict =
+ [GPBInt32EnumDictionary dictionaryWithValidationFunction:TestingEnum_IsValidValue];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertThrowsSpecificNamed([dict setEnum:801 forKey:12], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 0U);
+ [dict setRawValue:801 forKey:12]; // Unknown
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 11, 13, 14 };
+ const int32_t kValues[] = { 700, 702, 803 }; // Unknown
+ GPBInt32EnumDictionary *dict2 =
+ [[GPBInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:12]);
+ XCTAssertTrue([dict getRawValue:&value forKey:12]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:14]);
+ XCTAssertTrue([dict getRawValue:&value forKey:14]);
+ XCTAssertEqual(value, 803);
+ [dict2 release];
+}
+
+- (void)testUnknownRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:14]);
+ XCTAssertTrue([dict getRawValue:&value forKey:14]);
+ XCTAssertEqual(value, 803);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:14]);
+ XCTAssertTrue([dict getRawValue:&value forKey:14]);
+ XCTAssertEqual(value, 803);
+
+ [dict removeEnumForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:11]);
+ XCTAssertFalse([dict getEnum:NULL forKey:12]);
+ XCTAssertFalse([dict getEnum:NULL forKey:13]);
+ XCTAssertFalse([dict getEnum:NULL forKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutationUnknowns {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:12]);
+ XCTAssertTrue([dict getRawValue:&value forKey:12]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:14]);
+ XCTAssertTrue([dict getRawValue:&value forKey:14]);
+ XCTAssertEqual(value, 803);
+
+ XCTAssertThrowsSpecificNamed([dict setEnum:803 forKey:11], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:11]);
+ XCTAssertTrue([dict getEnum:&value forKey:11]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:12]);
+ XCTAssertTrue([dict getRawValue:&value forKey:12]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:14]);
+ XCTAssertTrue([dict getRawValue:&value forKey:14]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:803 forKey:11]; // Unknown
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:11]);
+ XCTAssertTrue([dict getRawValue:&value forKey:11]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:12]);
+ XCTAssertTrue([dict getRawValue:&value forKey:12]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:14]);
+ XCTAssertTrue([dict getRawValue:&value forKey:14]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:700 forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:11]);
+ XCTAssertTrue([dict getRawValue:&value forKey:11]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:12]);
+ XCTAssertTrue([dict getRawValue:&value forKey:12]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:13]);
+ XCTAssertTrue([dict getEnum:&value forKey:13]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 700);
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const int32_t kValues2[] = { 702, 801 }; // Unknown
+ GPBInt32EnumDictionary *dict2 =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:11]);
+ XCTAssertTrue([dict getRawValue:&value forKey:11]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getEnum:NULL forKey:12]);
+ XCTAssertTrue([dict getEnum:&value forKey:12]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:13]);
+ XCTAssertTrue([dict getRawValue:&value forKey:13]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:14]);
+ XCTAssertTrue([dict getEnum:&value forKey:14]);
+ XCTAssertEqual(value, 700);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testCopyUnknowns {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const int32_t kValues[] = { 700, 801, 702, 803 };
+ GPBInt32EnumDictionary *dict =
+ [[GPBInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32EnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int32 -> Object
+
+@interface GPBInt32ObjectDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt32ObjectDictionaryTests
+
+- (void)testEmpty {
+ GPBInt32ObjectDictionary<NSString*> *dict = [[GPBInt32ObjectDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:11]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt32ObjectDictionary<NSString*> *dict = [GPBInt32ObjectDictionary dictionaryWithObject:@"abc" forKey:11];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"abc");
+ XCTAssertNil([dict objectForKey:12]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertEqual(aKey, 11);
+ XCTAssertEqualObjects(aObject, @"abc");
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int32_t kKeys[] = { 11, 12, 13 };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi" };
+ GPBInt32ObjectDictionary<NSString*> *dict =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:12], @"def");
+ XCTAssertEqualObjects([dict objectForKey:13], @"ghi");
+ XCTAssertNil([dict objectForKey:14]);
+
+ __block NSUInteger idx = 0;
+ int32_t *seenKeys = malloc(3 * sizeof(int32_t));
+ NSString* *seenObjects = malloc(3 * sizeof(NSString*));
+ [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenObjects[idx] = aObject;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqualObjects(kObjects[i], seenObjects[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenObjects);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndObjectsUsingBlock:^(int32_t aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int32_t kKeys1[] = { 11, 12, 13, 14 };
+ const int32_t kKeys2[] = { 12, 11, 14 };
+ const NSString* kObjects1[] = { @"abc", @"def", @"ghi" };
+ const NSString* kObjects2[] = { @"abc", @"jkl", @"ghi" };
+ const NSString* kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt32ObjectDictionary<NSString*> *dict1 =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1);
+ GPBInt32ObjectDictionary<NSString*> *dict1prime =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt32ObjectDictionary<NSString*> *dict2 =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ GPBInt32ObjectDictionary<NSString*> *dict3 =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict3);
+ GPBInt32ObjectDictionary<NSString*> *dict4 =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt32ObjectDictionary<NSString*> *dict =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32ObjectDictionary<NSString*> *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt32ObjectDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt32ObjectDictionary<NSString*> *dict =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBInt32ObjectDictionary<NSString*> *dict2 =
+ [GPBInt32ObjectDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt32ObjectDictionary<NSString*> *dict = [GPBInt32ObjectDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setObject:@"abc" forKey:11];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int32_t kKeys[] = { 12, 13, 14 };
+ const NSString* kObjects[] = { @"def", @"ghi", @"jkl" };
+ GPBInt32ObjectDictionary<NSString*> *dict2 =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ XCTAssertEqualObjects([dict objectForKey:11], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:12], @"def");
+ XCTAssertEqualObjects([dict objectForKey:13], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:14], @"jkl");
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt32ObjectDictionary<NSString*> *dict =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeObjectForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"abc");
+ XCTAssertNil([dict objectForKey:12]);
+ XCTAssertEqualObjects([dict objectForKey:13], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:14], @"jkl");
+
+ // Remove again does nothing.
+ [dict removeObjectForKey:12];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"abc");
+ XCTAssertNil([dict objectForKey:12]);
+ XCTAssertEqualObjects([dict objectForKey:13], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:14], @"jkl");
+
+ [dict removeObjectForKey:14];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"abc");
+ XCTAssertNil([dict objectForKey:12]);
+ XCTAssertEqualObjects([dict objectForKey:13], @"ghi");
+ XCTAssertNil([dict objectForKey:14]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:11]);
+ XCTAssertNil([dict objectForKey:12]);
+ XCTAssertNil([dict objectForKey:13]);
+ XCTAssertNil([dict objectForKey:14]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int32_t kKeys[] = { 11, 12, 13, 14 };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt32ObjectDictionary<NSString*> *dict =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:12], @"def");
+ XCTAssertEqualObjects([dict objectForKey:13], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:14], @"jkl");
+
+ [dict setObject:@"jkl" forKey:11];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:12], @"def");
+ XCTAssertEqualObjects([dict objectForKey:13], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:14], @"jkl");
+
+ [dict setObject:@"def" forKey:14];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:12], @"def");
+ XCTAssertEqualObjects([dict objectForKey:13], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:14], @"def");
+
+ const int32_t kKeys2[] = { 12, 13 };
+ const NSString* kObjects2[] = { @"ghi", @"abc" };
+ GPBInt32ObjectDictionary<NSString*> *dict2 =
+ [[GPBInt32ObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:11], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:12], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:13], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:14], @"def");
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND-END TEST_FOR_POD_KEY(Int32, int32_t, 11, 12, 13, 14)
+
diff --git a/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Int64.m b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Int64.m
new file mode 100644
index 0000000000..b90cdf8c02
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+Int64.m
@@ -0,0 +1,3647 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+#import <XCTest/XCTest.h>
+
+#import "GPBDictionary.h"
+
+#import "GPBTestUtilities.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+
+// Pull in the macros (using an external file because expanding all tests
+// in a single file makes a file that is failing to work with within Xcode.
+//%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm
+
+//%PDDM-EXPAND TEST_FOR_POD_KEY(Int64, int64_t, 21LL, 22LL, 23LL, 24LL)
+// This block of code is generated, do not edit it directly.
+
+// To let the testing macros work, add some extra methods to simplify things.
+@interface GPBInt64EnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(int64_t)key;
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count;
+@end
+
+static BOOL TestingEnum_IsValidValue(int32_t value) {
+ switch (value) {
+ case 700:
+ case 701:
+ case 702:
+ case 703:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+@implementation GPBInt64EnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(int64_t)key {
+ // Cast is needed to compiler knows what class we are invoking initWithValues: on to get the
+ // type correct.
+ return [[(GPBInt64EnumDictionary*)[self alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const int64_t [])keys
+ count:(NSUInteger)count {
+ return [self initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:values
+ forKeys:keys
+ count:count];
+}
+@end
+
+
+#pragma mark - Int64 -> UInt32
+
+@interface GPBInt64UInt32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64UInt32DictionaryTests
+
+- (void)testEmpty {
+ GPBInt64UInt32Dictionary *dict = [[GPBInt64UInt32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:21LL]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64UInt32Dictionary *dict = [GPBInt64UInt32Dictionary dictionaryWithUInt32:100U forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:22LL]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqual(aValue, 100U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const uint32_t kValues[] = { 100U, 101U, 102U };
+ GPBInt64UInt32Dictionary *dict =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ uint32_t *seenValues = malloc(3 * sizeof(uint32_t));
+ [dict enumerateKeysAndUInt32sUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt32sUsingBlock:^(int64_t aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const uint32_t kValues1[] = { 100U, 101U, 102U };
+ const uint32_t kValues2[] = { 100U, 103U, 102U };
+ const uint32_t kValues3[] = { 100U, 101U, 102U, 103U };
+ GPBInt64UInt32Dictionary *dict1 =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64UInt32Dictionary *dict1prime =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64UInt32Dictionary *dict2 =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64UInt32Dictionary *dict3 =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64UInt32Dictionary *dict4 =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBInt64UInt32Dictionary *dict =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64UInt32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64UInt32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBInt64UInt32Dictionary *dict =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64UInt32Dictionary *dict2 =
+ [GPBInt64UInt32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64UInt32Dictionary *dict = [GPBInt64UInt32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt32:100U forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const uint32_t kValues[] = { 101U, 102U, 103U };
+ GPBInt64UInt32Dictionary *dict2 =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 103U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBInt64UInt32Dictionary *dict =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt32ForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 103U);
+
+ // Remove again does nothing.
+ [dict removeUInt32ForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 103U);
+
+ [dict removeUInt32ForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBInt64UInt32Dictionary *dict =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:103U forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:101U forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 101U);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const uint32_t kValues2[] = { 102U, 100U };
+ GPBInt64UInt32Dictionary *dict2 =
+ [[GPBInt64UInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 101U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> Int32
+
+@interface GPBInt64Int32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64Int32DictionaryTests
+
+- (void)testEmpty {
+ GPBInt64Int32Dictionary *dict = [[GPBInt64Int32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:21LL]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64Int32Dictionary *dict = [GPBInt64Int32Dictionary dictionaryWithInt32:200 forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:22LL]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqual(aValue, 200);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const int32_t kValues[] = { 200, 201, 202 };
+ GPBInt64Int32Dictionary *dict =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndInt32sUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt32sUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const int32_t kValues1[] = { 200, 201, 202 };
+ const int32_t kValues2[] = { 200, 203, 202 };
+ const int32_t kValues3[] = { 200, 201, 202, 203 };
+ GPBInt64Int32Dictionary *dict1 =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64Int32Dictionary *dict1prime =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64Int32Dictionary *dict2 =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64Int32Dictionary *dict3 =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64Int32Dictionary *dict4 =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBInt64Int32Dictionary *dict =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64Int32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64Int32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBInt64Int32Dictionary *dict =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64Int32Dictionary *dict2 =
+ [GPBInt64Int32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64Int32Dictionary *dict = [GPBInt64Int32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt32:200 forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 201, 202, 203 };
+ GPBInt64Int32Dictionary *dict2 =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 203);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBInt64Int32Dictionary *dict =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt32ForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 203);
+
+ // Remove again does nothing.
+ [dict removeInt32ForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 203);
+
+ [dict removeInt32ForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:21LL]);
+ XCTAssertFalse([dict getInt32:NULL forKey:22LL]);
+ XCTAssertFalse([dict getInt32:NULL forKey:23LL]);
+ XCTAssertFalse([dict getInt32:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBInt64Int32Dictionary *dict =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:203 forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:201 forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 201);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const int32_t kValues2[] = { 202, 200 };
+ GPBInt64Int32Dictionary *dict2 =
+ [[GPBInt64Int32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:21LL]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:22LL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:23LL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt32:&value forKey:24LL]);
+ XCTAssertEqual(value, 201);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> UInt64
+
+@interface GPBInt64UInt64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64UInt64DictionaryTests
+
+- (void)testEmpty {
+ GPBInt64UInt64Dictionary *dict = [[GPBInt64UInt64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:21LL]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64UInt64Dictionary *dict = [GPBInt64UInt64Dictionary dictionaryWithUInt64:300U forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:22LL]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqual(aValue, 300U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const uint64_t kValues[] = { 300U, 301U, 302U };
+ GPBInt64UInt64Dictionary *dict =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ uint64_t *seenValues = malloc(3 * sizeof(uint64_t));
+ [dict enumerateKeysAndUInt64sUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt64sUsingBlock:^(int64_t aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const uint64_t kValues1[] = { 300U, 301U, 302U };
+ const uint64_t kValues2[] = { 300U, 303U, 302U };
+ const uint64_t kValues3[] = { 300U, 301U, 302U, 303U };
+ GPBInt64UInt64Dictionary *dict1 =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64UInt64Dictionary *dict1prime =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64UInt64Dictionary *dict2 =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64UInt64Dictionary *dict3 =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64UInt64Dictionary *dict4 =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBInt64UInt64Dictionary *dict =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64UInt64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64UInt64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBInt64UInt64Dictionary *dict =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64UInt64Dictionary *dict2 =
+ [GPBInt64UInt64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64UInt64Dictionary *dict = [GPBInt64UInt64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt64:300U forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const uint64_t kValues[] = { 301U, 302U, 303U };
+ GPBInt64UInt64Dictionary *dict2 =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 303U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBInt64UInt64Dictionary *dict =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt64ForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 303U);
+
+ // Remove again does nothing.
+ [dict removeUInt64ForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 303U);
+
+ [dict removeUInt64ForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBInt64UInt64Dictionary *dict =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:303U forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:301U forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 301U);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const uint64_t kValues2[] = { 302U, 300U };
+ GPBInt64UInt64Dictionary *dict2 =
+ [[GPBInt64UInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 301U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> Int64
+
+@interface GPBInt64Int64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64Int64DictionaryTests
+
+- (void)testEmpty {
+ GPBInt64Int64Dictionary *dict = [[GPBInt64Int64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:21LL]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64Int64Dictionary *dict = [GPBInt64Int64Dictionary dictionaryWithInt64:400 forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:22LL]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqual(aValue, 400);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const int64_t kValues[] = { 400, 401, 402 };
+ GPBInt64Int64Dictionary *dict =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ int64_t *seenValues = malloc(3 * sizeof(int64_t));
+ [dict enumerateKeysAndInt64sUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt64sUsingBlock:^(int64_t aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const int64_t kValues1[] = { 400, 401, 402 };
+ const int64_t kValues2[] = { 400, 403, 402 };
+ const int64_t kValues3[] = { 400, 401, 402, 403 };
+ GPBInt64Int64Dictionary *dict1 =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64Int64Dictionary *dict1prime =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64Int64Dictionary *dict2 =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64Int64Dictionary *dict3 =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64Int64Dictionary *dict4 =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBInt64Int64Dictionary *dict =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64Int64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64Int64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBInt64Int64Dictionary *dict =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64Int64Dictionary *dict2 =
+ [GPBInt64Int64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64Int64Dictionary *dict = [GPBInt64Int64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt64:400 forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const int64_t kValues[] = { 401, 402, 403 };
+ GPBInt64Int64Dictionary *dict2 =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 403);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBInt64Int64Dictionary *dict =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt64ForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 403);
+
+ // Remove again does nothing.
+ [dict removeInt64ForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 403);
+
+ [dict removeInt64ForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:21LL]);
+ XCTAssertFalse([dict getInt64:NULL forKey:22LL]);
+ XCTAssertFalse([dict getInt64:NULL forKey:23LL]);
+ XCTAssertFalse([dict getInt64:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBInt64Int64Dictionary *dict =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:403 forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:401 forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 401);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const int64_t kValues2[] = { 402, 400 };
+ GPBInt64Int64Dictionary *dict2 =
+ [[GPBInt64Int64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:21LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:21LL]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:22LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:22LL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:23LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:23LL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:24LL]);
+ XCTAssertTrue([dict getInt64:&value forKey:24LL]);
+ XCTAssertEqual(value, 401);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> Bool
+
+@interface GPBInt64BoolDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64BoolDictionaryTests
+
+- (void)testEmpty {
+ GPBInt64BoolDictionary *dict = [[GPBInt64BoolDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:21LL]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64BoolDictionary *dict = [GPBInt64BoolDictionary dictionaryWithBool:YES forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:22LL]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqual(aValue, YES);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const BOOL kValues[] = { YES, YES, NO };
+ GPBInt64BoolDictionary *dict =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:&value forKey:22LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ BOOL *seenValues = malloc(3 * sizeof(BOOL));
+ [dict enumerateKeysAndBoolsUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndBoolsUsingBlock:^(int64_t aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const BOOL kValues1[] = { YES, YES, NO };
+ const BOOL kValues2[] = { YES, NO, NO };
+ const BOOL kValues3[] = { YES, YES, NO, NO };
+ GPBInt64BoolDictionary *dict1 =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64BoolDictionary *dict1prime =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64BoolDictionary *dict2 =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64BoolDictionary *dict3 =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64BoolDictionary *dict4 =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBInt64BoolDictionary *dict =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64BoolDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64BoolDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBInt64BoolDictionary *dict =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64BoolDictionary *dict2 =
+ [GPBInt64BoolDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64BoolDictionary *dict = [GPBInt64BoolDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setBool:YES forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const BOOL kValues[] = { YES, NO, NO };
+ GPBInt64BoolDictionary *dict2 =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:&value forKey:22LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:24LL]);
+ XCTAssertTrue([dict getBool:&value forKey:24LL]);
+ XCTAssertEqual(value, NO);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBInt64BoolDictionary *dict =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeBoolForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:24LL]);
+ XCTAssertTrue([dict getBool:&value forKey:24LL]);
+ XCTAssertEqual(value, NO);
+
+ // Remove again does nothing.
+ [dict removeBoolForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:24LL]);
+ XCTAssertTrue([dict getBool:&value forKey:24LL]);
+ XCTAssertEqual(value, NO);
+
+ [dict removeBoolForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:21LL]);
+ XCTAssertFalse([dict getBool:NULL forKey:22LL]);
+ XCTAssertFalse([dict getBool:NULL forKey:23LL]);
+ XCTAssertFalse([dict getBool:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBInt64BoolDictionary *dict =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:&value forKey:22LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:24LL]);
+ XCTAssertTrue([dict getBool:&value forKey:24LL]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:NO forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:&value forKey:22LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:24LL]);
+ XCTAssertTrue([dict getBool:&value forKey:24LL]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:YES forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:&value forKey:22LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:24LL]);
+ XCTAssertTrue([dict getBool:&value forKey:24LL]);
+ XCTAssertEqual(value, YES);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const BOOL kValues2[] = { NO, YES };
+ GPBInt64BoolDictionary *dict2 =
+ [[GPBInt64BoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:21LL]);
+ XCTAssertTrue([dict getBool:&value forKey:21LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:22LL]);
+ XCTAssertTrue([dict getBool:&value forKey:22LL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:23LL]);
+ XCTAssertTrue([dict getBool:&value forKey:23LL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:24LL]);
+ XCTAssertTrue([dict getBool:&value forKey:24LL]);
+ XCTAssertEqual(value, YES);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> Float
+
+@interface GPBInt64FloatDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64FloatDictionaryTests
+
+- (void)testEmpty {
+ GPBInt64FloatDictionary *dict = [[GPBInt64FloatDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:21LL]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(int64_t aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64FloatDictionary *dict = [GPBInt64FloatDictionary dictionaryWithFloat:500.f forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:22LL]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(int64_t aKey, float aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqual(aValue, 500.f);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const float kValues[] = { 500.f, 501.f, 502.f };
+ GPBInt64FloatDictionary *dict =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:22LL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ float *seenValues = malloc(3 * sizeof(float));
+ [dict enumerateKeysAndFloatsUsingBlock:^(int64_t aKey, float aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndFloatsUsingBlock:^(int64_t aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const float kValues1[] = { 500.f, 501.f, 502.f };
+ const float kValues2[] = { 500.f, 503.f, 502.f };
+ const float kValues3[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt64FloatDictionary *dict1 =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64FloatDictionary *dict1prime =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64FloatDictionary *dict2 =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64FloatDictionary *dict3 =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64FloatDictionary *dict4 =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt64FloatDictionary *dict =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64FloatDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64FloatDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt64FloatDictionary *dict =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64FloatDictionary *dict2 =
+ [GPBInt64FloatDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64FloatDictionary *dict = [GPBInt64FloatDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setFloat:500.f forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const float kValues[] = { 501.f, 502.f, 503.f };
+ GPBInt64FloatDictionary *dict2 =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:22LL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:24LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:24LL]);
+ XCTAssertEqual(value, 503.f);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt64FloatDictionary *dict =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeFloatForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:24LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:24LL]);
+ XCTAssertEqual(value, 503.f);
+
+ // Remove again does nothing.
+ [dict removeFloatForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:24LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:24LL]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict removeFloatForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:21LL]);
+ XCTAssertFalse([dict getFloat:NULL forKey:22LL]);
+ XCTAssertFalse([dict getFloat:NULL forKey:23LL]);
+ XCTAssertFalse([dict getFloat:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBInt64FloatDictionary *dict =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:22LL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:24LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:24LL]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:503.f forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:22LL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:24LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:24LL]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:501.f forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:22LL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:24LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:24LL]);
+ XCTAssertEqual(value, 501.f);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const float kValues2[] = { 502.f, 500.f };
+ GPBInt64FloatDictionary *dict2 =
+ [[GPBInt64FloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:21LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:21LL]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:22LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:22LL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:23LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:23LL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:24LL]);
+ XCTAssertTrue([dict getFloat:&value forKey:24LL]);
+ XCTAssertEqual(value, 501.f);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> Double
+
+@interface GPBInt64DoubleDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64DoubleDictionaryTests
+
+- (void)testEmpty {
+ GPBInt64DoubleDictionary *dict = [[GPBInt64DoubleDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:21LL]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(int64_t aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64DoubleDictionary *dict = [GPBInt64DoubleDictionary dictionaryWithDouble:600. forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:22LL]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(int64_t aKey, double aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqual(aValue, 600.);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const double kValues[] = { 600., 601., 602. };
+ GPBInt64DoubleDictionary *dict =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:22LL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ double *seenValues = malloc(3 * sizeof(double));
+ [dict enumerateKeysAndDoublesUsingBlock:^(int64_t aKey, double aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndDoublesUsingBlock:^(int64_t aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const double kValues1[] = { 600., 601., 602. };
+ const double kValues2[] = { 600., 603., 602. };
+ const double kValues3[] = { 600., 601., 602., 603. };
+ GPBInt64DoubleDictionary *dict1 =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64DoubleDictionary *dict1prime =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64DoubleDictionary *dict2 =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64DoubleDictionary *dict3 =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64DoubleDictionary *dict4 =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBInt64DoubleDictionary *dict =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64DoubleDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64DoubleDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBInt64DoubleDictionary *dict =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64DoubleDictionary *dict2 =
+ [GPBInt64DoubleDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64DoubleDictionary *dict = [GPBInt64DoubleDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setDouble:600. forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const double kValues[] = { 601., 602., 603. };
+ GPBInt64DoubleDictionary *dict2 =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:22LL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:24LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:24LL]);
+ XCTAssertEqual(value, 603.);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBInt64DoubleDictionary *dict =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeDoubleForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:24LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:24LL]);
+ XCTAssertEqual(value, 603.);
+
+ // Remove again does nothing.
+ [dict removeDoubleForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:24LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:24LL]);
+ XCTAssertEqual(value, 603.);
+
+ [dict removeDoubleForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:21LL]);
+ XCTAssertFalse([dict getDouble:NULL forKey:22LL]);
+ XCTAssertFalse([dict getDouble:NULL forKey:23LL]);
+ XCTAssertFalse([dict getDouble:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBInt64DoubleDictionary *dict =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:22LL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:24LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:24LL]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:603. forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:22LL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:24LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:24LL]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:601. forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:22LL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:24LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:24LL]);
+ XCTAssertEqual(value, 601.);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const double kValues2[] = { 602., 600. };
+ GPBInt64DoubleDictionary *dict2 =
+ [[GPBInt64DoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:21LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:21LL]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:22LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:22LL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:23LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:23LL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:24LL]);
+ XCTAssertTrue([dict getDouble:&value forKey:24LL]);
+ XCTAssertEqual(value, 601.);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> Enum
+
+@interface GPBInt64EnumDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64EnumDictionaryTests
+
+- (void)testEmpty {
+ GPBInt64EnumDictionary *dict = [[GPBInt64EnumDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:21LL]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64EnumDictionary *dict = [GPBInt64EnumDictionary dictionaryWithEnum:700 forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqual(aValue, 700);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const int32_t kValues[] = { 700, 701, 702 };
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndEnumsUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const int32_t kValues1[] = { 700, 701, 702 };
+ const int32_t kValues2[] = { 700, 703, 702 };
+ const int32_t kValues3[] = { 700, 701, 702, 703 };
+ GPBInt64EnumDictionary *dict1 =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64EnumDictionary *dict1prime =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64EnumDictionary *dict2 =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64EnumDictionary *dict3 =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64EnumDictionary *dict4 =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64EnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64EnumDictionary *dict2 =
+ [GPBInt64EnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64EnumDictionary *dict = [GPBInt64EnumDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setEnum:700 forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 701, 702, 703 };
+ GPBInt64EnumDictionary *dict2 =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 703);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 703);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 703);
+
+ [dict removeEnumForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:21LL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:23LL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:703 forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:701 forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 701);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const int32_t kValues2[] = { 702, 700 };
+ GPBInt64EnumDictionary *dict2 =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 701);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> Enum (Unknown Enums)
+
+@interface GPBInt64EnumDictionaryUnknownEnumTests : XCTestCase
+@end
+
+@implementation GPBInt64EnumDictionaryUnknownEnumTests
+
+- (void)testRawBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const int32_t kValues[] = { 700, 801, 702 };
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue(dict.validationFunc == TestingEnum_IsValidValue); // Pointer comparison
+ int32_t value;
+ XCTAssertTrue([dict getRawValue:NULL forKey:21LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:22LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:22LL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getRawValue:NULL forKey:23LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getRawValue:NULL forKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ if (i == 1) {
+ XCTAssertEqual(kGPBUnrecognizedEnumeratorValue, seenValues[j], @"i = %d, j = %d", i, j);
+ } else {
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(int64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEqualityWithUnknowns {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const int32_t kValues1[] = { 700, 801, 702 }; // Unknown
+ const int32_t kValues2[] = { 700, 803, 702 }; // Unknown
+ const int32_t kValues3[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBInt64EnumDictionary *dict1 =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64EnumDictionary *dict1prime =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64EnumDictionary *dict2 =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64EnumDictionary *dict3 =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64EnumDictionary *dict4 =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopyWithUnknowns {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknown
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertEqualObjects(dict, dict2);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64EnumDictionary *dict2 =
+ [GPBInt64EnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ [dict release];
+}
+
+- (void)testUnknownAdds {
+ GPBInt64EnumDictionary *dict =
+ [GPBInt64EnumDictionary dictionaryWithValidationFunction:TestingEnum_IsValidValue];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertThrowsSpecificNamed([dict setEnum:801 forKey:22LL], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 0U);
+ [dict setRawValue:801 forKey:22LL]; // Unknown
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 21LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 702, 803 }; // Unknown
+ GPBInt64EnumDictionary *dict2 =
+ [[GPBInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:22LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:22LL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:24LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:24LL]);
+ XCTAssertEqual(value, 803);
+ [dict2 release];
+}
+
+- (void)testUnknownRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:24LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:24LL]);
+ XCTAssertEqual(value, 803);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:24LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:24LL]);
+ XCTAssertEqual(value, 803);
+
+ [dict removeEnumForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:21LL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:22LL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:23LL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutationUnknowns {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:22LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:22LL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:24LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:24LL]);
+ XCTAssertEqual(value, 803);
+
+ XCTAssertThrowsSpecificNamed([dict setEnum:803 forKey:21LL], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:21LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:21LL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:22LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:22LL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:24LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:24LL]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:803 forKey:21LL]; // Unknown
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:21LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:21LL]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:22LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:22LL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:24LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:24LL]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:700 forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:21LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:21LL]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:22LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:22LL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:23LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:23LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 700);
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const int32_t kValues2[] = { 702, 801 }; // Unknown
+ GPBInt64EnumDictionary *dict2 =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:21LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:21LL]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getEnum:NULL forKey:22LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:22LL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:23LL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:23LL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:24LL]);
+ XCTAssertTrue([dict getEnum:&value forKey:24LL]);
+ XCTAssertEqual(value, 700);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testCopyUnknowns {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const int32_t kValues[] = { 700, 801, 702, 803 };
+ GPBInt64EnumDictionary *dict =
+ [[GPBInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64EnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - Int64 -> Object
+
+@interface GPBInt64ObjectDictionaryTests : XCTestCase
+@end
+
+@implementation GPBInt64ObjectDictionaryTests
+
+- (void)testEmpty {
+ GPBInt64ObjectDictionary<NSString*> *dict = [[GPBInt64ObjectDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:21LL]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBInt64ObjectDictionary<NSString*> *dict = [GPBInt64ObjectDictionary dictionaryWithObject:@"abc" forKey:21LL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"abc");
+ XCTAssertNil([dict objectForKey:22LL]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertEqual(aKey, 21LL);
+ XCTAssertEqualObjects(aObject, @"abc");
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi" };
+ GPBInt64ObjectDictionary<NSString*> *dict =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:22LL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi");
+ XCTAssertNil([dict objectForKey:24LL]);
+
+ __block NSUInteger idx = 0;
+ int64_t *seenKeys = malloc(3 * sizeof(int64_t));
+ NSString* *seenObjects = malloc(3 * sizeof(NSString*));
+ [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenObjects[idx] = aObject;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqualObjects(kObjects[i], seenObjects[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenObjects);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndObjectsUsingBlock:^(int64_t aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const int64_t kKeys1[] = { 21LL, 22LL, 23LL, 24LL };
+ const int64_t kKeys2[] = { 22LL, 21LL, 24LL };
+ const NSString* kObjects1[] = { @"abc", @"def", @"ghi" };
+ const NSString* kObjects2[] = { @"abc", @"jkl", @"ghi" };
+ const NSString* kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt64ObjectDictionary<NSString*> *dict1 =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1);
+ GPBInt64ObjectDictionary<NSString*> *dict1prime =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1prime);
+ GPBInt64ObjectDictionary<NSString*> *dict2 =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ GPBInt64ObjectDictionary<NSString*> *dict3 =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict3);
+ GPBInt64ObjectDictionary<NSString*> *dict4 =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt64ObjectDictionary<NSString*> *dict =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64ObjectDictionary<NSString*> *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBInt64ObjectDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt64ObjectDictionary<NSString*> *dict =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBInt64ObjectDictionary<NSString*> *dict2 =
+ [GPBInt64ObjectDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBInt64ObjectDictionary<NSString*> *dict = [GPBInt64ObjectDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setObject:@"abc" forKey:21LL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const int64_t kKeys[] = { 22LL, 23LL, 24LL };
+ const NSString* kObjects[] = { @"def", @"ghi", @"jkl" };
+ GPBInt64ObjectDictionary<NSString*> *dict2 =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:22LL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl");
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt64ObjectDictionary<NSString*> *dict =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeObjectForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"abc");
+ XCTAssertNil([dict objectForKey:22LL]);
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl");
+
+ // Remove again does nothing.
+ [dict removeObjectForKey:22LL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"abc");
+ XCTAssertNil([dict objectForKey:22LL]);
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl");
+
+ [dict removeObjectForKey:24LL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"abc");
+ XCTAssertNil([dict objectForKey:22LL]);
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi");
+ XCTAssertNil([dict objectForKey:24LL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:21LL]);
+ XCTAssertNil([dict objectForKey:22LL]);
+ XCTAssertNil([dict objectForKey:23LL]);
+ XCTAssertNil([dict objectForKey:24LL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const int64_t kKeys[] = { 21LL, 22LL, 23LL, 24LL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBInt64ObjectDictionary<NSString*> *dict =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:22LL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl");
+
+ [dict setObject:@"jkl" forKey:21LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:22LL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:24LL], @"jkl");
+
+ [dict setObject:@"def" forKey:24LL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:22LL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:24LL], @"def");
+
+ const int64_t kKeys2[] = { 22LL, 23LL };
+ const NSString* kObjects2[] = { @"ghi", @"abc" };
+ GPBInt64ObjectDictionary<NSString*> *dict2 =
+ [[GPBInt64ObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:21LL], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:22LL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:23LL], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:24LL], @"def");
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND-END TEST_FOR_POD_KEY(Int64, int64_t, 21LL, 22LL, 23LL, 24LL)
+
diff --git a/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+String.m b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+String.m
new file mode 100644
index 0000000000..5df1d51d59
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+String.m
@@ -0,0 +1,3359 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+#import <XCTest/XCTest.h>
+
+#import "GPBDictionary.h"
+
+#import "GPBTestUtilities.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+
+// Pull in the macros (using an external file because expanding all tests
+// in a single file makes a file that is failing to work with within Xcode.
+//%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm
+
+//%PDDM-EXPAND TESTS_FOR_POD_VALUES(String, NSString, *, Objects, @"foo", @"bar", @"baz", @"mumble")
+// This block of code is generated, do not edit it directly.
+
+// To let the testing macros work, add some extra methods to simplify things.
+@interface GPBStringEnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(NSString *)key;
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count;
+@end
+
+static BOOL TestingEnum_IsValidValue(int32_t value) {
+ switch (value) {
+ case 700:
+ case 701:
+ case 702:
+ case 703:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+@implementation GPBStringEnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(NSString *)key {
+ // Cast is needed to compiler knows what class we are invoking initWithValues: on to get the
+ // type correct.
+ return [[(GPBStringEnumDictionary*)[self alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const NSString * [])keys
+ count:(NSUInteger)count {
+ return [self initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:values
+ forKeys:keys
+ count:count];
+}
+@end
+
+
+#pragma mark - String -> UInt32
+
+@interface GPBStringUInt32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBStringUInt32DictionaryTests
+
+- (void)testEmpty {
+ GPBStringUInt32Dictionary *dict = [[GPBStringUInt32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"foo"]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(NSString *aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBStringUInt32Dictionary *dict = [GPBStringUInt32Dictionary dictionaryWithUInt32:100U forKey:@"foo"];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"bar"]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(NSString *aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertEqualObjects(aKey, @"foo");
+ XCTAssertEqual(aValue, 100U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const uint32_t kValues[] = { 100U, 101U, 102U };
+ GPBStringUInt32Dictionary *dict =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ uint32_t *seenValues = malloc(3 * sizeof(uint32_t));
+ [dict enumerateKeysAndUInt32sUsingBlock:^(NSString *aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt32sUsingBlock:^(NSString *aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const uint32_t kValues1[] = { 100U, 101U, 102U };
+ const uint32_t kValues2[] = { 100U, 103U, 102U };
+ const uint32_t kValues3[] = { 100U, 101U, 102U, 103U };
+ GPBStringUInt32Dictionary *dict1 =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringUInt32Dictionary *dict1prime =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringUInt32Dictionary *dict2 =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringUInt32Dictionary *dict3 =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringUInt32Dictionary *dict4 =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBStringUInt32Dictionary *dict =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringUInt32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringUInt32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBStringUInt32Dictionary *dict =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringUInt32Dictionary *dict2 =
+ [GPBStringUInt32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBStringUInt32Dictionary *dict = [GPBStringUInt32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt32:100U forKey:@"foo"];
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"bar", @"baz", @"mumble" };
+ const uint32_t kValues[] = { 101U, 102U, 103U };
+ GPBStringUInt32Dictionary *dict2 =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 103U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBStringUInt32Dictionary *dict =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt32ForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 103U);
+
+ // Remove again does nothing.
+ [dict removeUInt32ForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 103U);
+
+ [dict removeUInt32ForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBStringUInt32Dictionary *dict =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:103U forKey:@"foo"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:101U forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 101U);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const uint32_t kValues2[] = { 102U, 100U };
+ GPBStringUInt32Dictionary *dict2 =
+ [[GPBStringUInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 101U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - String -> Int32
+
+@interface GPBStringInt32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBStringInt32DictionaryTests
+
+- (void)testEmpty {
+ GPBStringInt32Dictionary *dict = [[GPBStringInt32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"foo"]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBStringInt32Dictionary *dict = [GPBStringInt32Dictionary dictionaryWithInt32:200 forKey:@"foo"];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"bar"]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqualObjects(aKey, @"foo");
+ XCTAssertEqual(aValue, 200);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const int32_t kValues[] = { 200, 201, 202 };
+ GPBStringInt32Dictionary *dict =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndInt32sUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt32sUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const int32_t kValues1[] = { 200, 201, 202 };
+ const int32_t kValues2[] = { 200, 203, 202 };
+ const int32_t kValues3[] = { 200, 201, 202, 203 };
+ GPBStringInt32Dictionary *dict1 =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringInt32Dictionary *dict1prime =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringInt32Dictionary *dict2 =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringInt32Dictionary *dict3 =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringInt32Dictionary *dict4 =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBStringInt32Dictionary *dict =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringInt32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringInt32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBStringInt32Dictionary *dict =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringInt32Dictionary *dict2 =
+ [GPBStringInt32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBStringInt32Dictionary *dict = [GPBStringInt32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt32:200 forKey:@"foo"];
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 201, 202, 203 };
+ GPBStringInt32Dictionary *dict2 =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 203);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBStringInt32Dictionary *dict =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt32ForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 203);
+
+ // Remove again does nothing.
+ [dict removeInt32ForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 203);
+
+ [dict removeInt32ForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getInt32:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBStringInt32Dictionary *dict =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:203 forKey:@"foo"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:201 forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 201);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const int32_t kValues2[] = { 202, 200 };
+ GPBStringInt32Dictionary *dict2 =
+ [[GPBStringInt32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt32:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 201);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - String -> UInt64
+
+@interface GPBStringUInt64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBStringUInt64DictionaryTests
+
+- (void)testEmpty {
+ GPBStringUInt64Dictionary *dict = [[GPBStringUInt64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"foo"]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(NSString *aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBStringUInt64Dictionary *dict = [GPBStringUInt64Dictionary dictionaryWithUInt64:300U forKey:@"foo"];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"bar"]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(NSString *aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertEqualObjects(aKey, @"foo");
+ XCTAssertEqual(aValue, 300U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const uint64_t kValues[] = { 300U, 301U, 302U };
+ GPBStringUInt64Dictionary *dict =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ uint64_t *seenValues = malloc(3 * sizeof(uint64_t));
+ [dict enumerateKeysAndUInt64sUsingBlock:^(NSString *aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt64sUsingBlock:^(NSString *aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const uint64_t kValues1[] = { 300U, 301U, 302U };
+ const uint64_t kValues2[] = { 300U, 303U, 302U };
+ const uint64_t kValues3[] = { 300U, 301U, 302U, 303U };
+ GPBStringUInt64Dictionary *dict1 =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringUInt64Dictionary *dict1prime =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringUInt64Dictionary *dict2 =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringUInt64Dictionary *dict3 =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringUInt64Dictionary *dict4 =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBStringUInt64Dictionary *dict =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringUInt64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringUInt64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBStringUInt64Dictionary *dict =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringUInt64Dictionary *dict2 =
+ [GPBStringUInt64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBStringUInt64Dictionary *dict = [GPBStringUInt64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt64:300U forKey:@"foo"];
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"bar", @"baz", @"mumble" };
+ const uint64_t kValues[] = { 301U, 302U, 303U };
+ GPBStringUInt64Dictionary *dict2 =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 303U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBStringUInt64Dictionary *dict =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt64ForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 303U);
+
+ // Remove again does nothing.
+ [dict removeUInt64ForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 303U);
+
+ [dict removeUInt64ForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBStringUInt64Dictionary *dict =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:303U forKey:@"foo"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:301U forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 301U);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const uint64_t kValues2[] = { 302U, 300U };
+ GPBStringUInt64Dictionary *dict2 =
+ [[GPBStringUInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getUInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 301U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - String -> Int64
+
+@interface GPBStringInt64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBStringInt64DictionaryTests
+
+- (void)testEmpty {
+ GPBStringInt64Dictionary *dict = [[GPBStringInt64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"foo"]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(NSString *aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBStringInt64Dictionary *dict = [GPBStringInt64Dictionary dictionaryWithInt64:400 forKey:@"foo"];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"bar"]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(NSString *aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertEqualObjects(aKey, @"foo");
+ XCTAssertEqual(aValue, 400);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const int64_t kValues[] = { 400, 401, 402 };
+ GPBStringInt64Dictionary *dict =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ int64_t *seenValues = malloc(3 * sizeof(int64_t));
+ [dict enumerateKeysAndInt64sUsingBlock:^(NSString *aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt64sUsingBlock:^(NSString *aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const int64_t kValues1[] = { 400, 401, 402 };
+ const int64_t kValues2[] = { 400, 403, 402 };
+ const int64_t kValues3[] = { 400, 401, 402, 403 };
+ GPBStringInt64Dictionary *dict1 =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringInt64Dictionary *dict1prime =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringInt64Dictionary *dict2 =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringInt64Dictionary *dict3 =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringInt64Dictionary *dict4 =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBStringInt64Dictionary *dict =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringInt64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringInt64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBStringInt64Dictionary *dict =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringInt64Dictionary *dict2 =
+ [GPBStringInt64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBStringInt64Dictionary *dict = [GPBStringInt64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt64:400 forKey:@"foo"];
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"bar", @"baz", @"mumble" };
+ const int64_t kValues[] = { 401, 402, 403 };
+ GPBStringInt64Dictionary *dict2 =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 403);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBStringInt64Dictionary *dict =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt64ForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 403);
+
+ // Remove again does nothing.
+ [dict removeInt64ForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 403);
+
+ [dict removeInt64ForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getInt64:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBStringInt64Dictionary *dict =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:403 forKey:@"foo"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:401 forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 401);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const int64_t kValues2[] = { 402, 400 };
+ GPBStringInt64Dictionary *dict2 =
+ [[GPBStringInt64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getInt64:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 401);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - String -> Bool
+
+@interface GPBStringBoolDictionaryTests : XCTestCase
+@end
+
+@implementation GPBStringBoolDictionaryTests
+
+- (void)testEmpty {
+ GPBStringBoolDictionary *dict = [[GPBStringBoolDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:@"foo"]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(NSString *aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBStringBoolDictionary *dict = [GPBStringBoolDictionary dictionaryWithBool:YES forKey:@"foo"];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:@"bar"]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(NSString *aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertEqualObjects(aKey, @"foo");
+ XCTAssertEqual(aValue, YES);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const BOOL kValues[] = { YES, YES, NO };
+ GPBStringBoolDictionary *dict =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"bar"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ BOOL *seenValues = malloc(3 * sizeof(BOOL));
+ [dict enumerateKeysAndBoolsUsingBlock:^(NSString *aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndBoolsUsingBlock:^(NSString *aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const BOOL kValues1[] = { YES, YES, NO };
+ const BOOL kValues2[] = { YES, NO, NO };
+ const BOOL kValues3[] = { YES, YES, NO, NO };
+ GPBStringBoolDictionary *dict1 =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringBoolDictionary *dict1prime =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringBoolDictionary *dict2 =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringBoolDictionary *dict3 =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringBoolDictionary *dict4 =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBStringBoolDictionary *dict =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringBoolDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringBoolDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBStringBoolDictionary *dict =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringBoolDictionary *dict2 =
+ [GPBStringBoolDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBStringBoolDictionary *dict = [GPBStringBoolDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setBool:YES forKey:@"foo"];
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"bar", @"baz", @"mumble" };
+ const BOOL kValues[] = { YES, NO, NO };
+ GPBStringBoolDictionary *dict2 =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"bar"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, NO);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBStringBoolDictionary *dict =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeBoolForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, NO);
+
+ // Remove again does nothing.
+ [dict removeBoolForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, NO);
+
+ [dict removeBoolForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getBool:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBStringBoolDictionary *dict =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"bar"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:NO forKey:@"foo"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"bar"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:YES forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"bar"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, YES);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const BOOL kValues2[] = { NO, YES };
+ GPBStringBoolDictionary *dict2 =
+ [[GPBStringBoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"foo"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"bar"]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"baz"]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getBool:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, YES);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - String -> Float
+
+@interface GPBStringFloatDictionaryTests : XCTestCase
+@end
+
+@implementation GPBStringFloatDictionaryTests
+
+- (void)testEmpty {
+ GPBStringFloatDictionary *dict = [[GPBStringFloatDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"foo"]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(NSString *aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBStringFloatDictionary *dict = [GPBStringFloatDictionary dictionaryWithFloat:500.f forKey:@"foo"];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"bar"]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(NSString *aKey, float aValue, BOOL *stop) {
+ XCTAssertEqualObjects(aKey, @"foo");
+ XCTAssertEqual(aValue, 500.f);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const float kValues[] = { 500.f, 501.f, 502.f };
+ GPBStringFloatDictionary *dict =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ float *seenValues = malloc(3 * sizeof(float));
+ [dict enumerateKeysAndFloatsUsingBlock:^(NSString *aKey, float aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndFloatsUsingBlock:^(NSString *aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const float kValues1[] = { 500.f, 501.f, 502.f };
+ const float kValues2[] = { 500.f, 503.f, 502.f };
+ const float kValues3[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBStringFloatDictionary *dict1 =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringFloatDictionary *dict1prime =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringFloatDictionary *dict2 =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringFloatDictionary *dict3 =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringFloatDictionary *dict4 =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBStringFloatDictionary *dict =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringFloatDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringFloatDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBStringFloatDictionary *dict =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringFloatDictionary *dict2 =
+ [GPBStringFloatDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBStringFloatDictionary *dict = [GPBStringFloatDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setFloat:500.f forKey:@"foo"];
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"bar", @"baz", @"mumble" };
+ const float kValues[] = { 501.f, 502.f, 503.f };
+ GPBStringFloatDictionary *dict2 =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 503.f);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBStringFloatDictionary *dict =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeFloatForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 503.f);
+
+ // Remove again does nothing.
+ [dict removeFloatForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict removeFloatForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getFloat:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBStringFloatDictionary *dict =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:503.f forKey:@"foo"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:501.f forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 501.f);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const float kValues2[] = { 502.f, 500.f };
+ GPBStringFloatDictionary *dict2 =
+ [[GPBStringFloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getFloat:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 501.f);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - String -> Double
+
+@interface GPBStringDoubleDictionaryTests : XCTestCase
+@end
+
+@implementation GPBStringDoubleDictionaryTests
+
+- (void)testEmpty {
+ GPBStringDoubleDictionary *dict = [[GPBStringDoubleDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"foo"]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(NSString *aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBStringDoubleDictionary *dict = [GPBStringDoubleDictionary dictionaryWithDouble:600. forKey:@"foo"];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"bar"]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(NSString *aKey, double aValue, BOOL *stop) {
+ XCTAssertEqualObjects(aKey, @"foo");
+ XCTAssertEqual(aValue, 600.);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const double kValues[] = { 600., 601., 602. };
+ GPBStringDoubleDictionary *dict =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ double *seenValues = malloc(3 * sizeof(double));
+ [dict enumerateKeysAndDoublesUsingBlock:^(NSString *aKey, double aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndDoublesUsingBlock:^(NSString *aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const double kValues1[] = { 600., 601., 602. };
+ const double kValues2[] = { 600., 603., 602. };
+ const double kValues3[] = { 600., 601., 602., 603. };
+ GPBStringDoubleDictionary *dict1 =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringDoubleDictionary *dict1prime =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringDoubleDictionary *dict2 =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringDoubleDictionary *dict3 =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringDoubleDictionary *dict4 =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBStringDoubleDictionary *dict =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringDoubleDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringDoubleDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBStringDoubleDictionary *dict =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringDoubleDictionary *dict2 =
+ [GPBStringDoubleDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBStringDoubleDictionary *dict = [GPBStringDoubleDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setDouble:600. forKey:@"foo"];
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"bar", @"baz", @"mumble" };
+ const double kValues[] = { 601., 602., 603. };
+ GPBStringDoubleDictionary *dict2 =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 603.);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBStringDoubleDictionary *dict =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeDoubleForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 603.);
+
+ // Remove again does nothing.
+ [dict removeDoubleForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 603.);
+
+ [dict removeDoubleForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getDouble:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBStringDoubleDictionary *dict =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:603. forKey:@"foo"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:601. forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 601.);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const double kValues2[] = { 602., 600. };
+ GPBStringDoubleDictionary *dict2 =
+ [[GPBStringDoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getDouble:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 601.);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - String -> Enum
+
+@interface GPBStringEnumDictionaryTests : XCTestCase
+@end
+
+@implementation GPBStringEnumDictionaryTests
+
+- (void)testEmpty {
+ GPBStringEnumDictionary *dict = [[GPBStringEnumDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"foo"]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBStringEnumDictionary *dict = [GPBStringEnumDictionary dictionaryWithEnum:700 forKey:@"foo"];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqualObjects(aKey, @"foo");
+ XCTAssertEqual(aValue, 700);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const int32_t kValues[] = { 700, 701, 702 };
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndEnumsUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const int32_t kValues1[] = { 700, 701, 702 };
+ const int32_t kValues2[] = { 700, 703, 702 };
+ const int32_t kValues3[] = { 700, 701, 702, 703 };
+ GPBStringEnumDictionary *dict1 =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringEnumDictionary *dict1prime =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringEnumDictionary *dict2 =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringEnumDictionary *dict3 =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringEnumDictionary *dict4 =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringEnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringEnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringEnumDictionary *dict2 =
+ [GPBStringEnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBStringEnumDictionary *dict = [GPBStringEnumDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setEnum:700 forKey:@"foo"];
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 701, 702, 703 };
+ GPBStringEnumDictionary *dict2 =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 703);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 703);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 703);
+
+ [dict removeEnumForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:703 forKey:@"foo"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:701 forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 701);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const int32_t kValues2[] = { 702, 700 };
+ GPBStringEnumDictionary *dict2 =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 701);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - String -> Enum (Unknown Enums)
+
+@interface GPBStringEnumDictionaryUnknownEnumTests : XCTestCase
+@end
+
+@implementation GPBStringEnumDictionaryUnknownEnumTests
+
+- (void)testRawBasics {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz" };
+ const int32_t kValues[] = { 700, 801, 702 };
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue(dict.validationFunc == TestingEnum_IsValidValue); // Pointer comparison
+ int32_t value;
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getRawValue:NULL forKey:@"mumble"]);
+
+ __block NSUInteger idx = 0;
+ NSString **seenKeys = malloc(3 * sizeof(NSString*));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ if (i == 1) {
+ XCTAssertEqual(kGPBUnrecognizedEnumeratorValue, seenValues[j], @"i = %d, j = %d", i, j);
+ } else {
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if ([kKeys[i] isEqual:seenKeys[j]]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(NSString *aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEqualityWithUnknowns {
+ const NSString *kKeys1[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const NSString *kKeys2[] = { @"bar", @"foo", @"mumble" };
+ const int32_t kValues1[] = { 700, 801, 702 }; // Unknown
+ const int32_t kValues2[] = { 700, 803, 702 }; // Unknown
+ const int32_t kValues3[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBStringEnumDictionary *dict1 =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBStringEnumDictionary *dict1prime =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBStringEnumDictionary *dict2 =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBStringEnumDictionary *dict3 =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBStringEnumDictionary *dict4 =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopyWithUnknowns {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknown
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringEnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertEqualObjects(dict, dict2);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringEnumDictionary *dict2 =
+ [GPBStringEnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ [dict release];
+}
+
+- (void)testUnknownAdds {
+ GPBStringEnumDictionary *dict =
+ [GPBStringEnumDictionary dictionaryWithValidationFunction:TestingEnum_IsValidValue];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertThrowsSpecificNamed([dict setEnum:801 forKey:@"bar"], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 0U);
+ [dict setRawValue:801 forKey:@"bar"]; // Unknown
+ XCTAssertEqual(dict.count, 1U);
+
+ const NSString *kKeys[] = { @"foo", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 702, 803 }; // Unknown
+ GPBStringEnumDictionary *dict2 =
+ [[GPBStringEnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 803);
+ [dict2 release];
+}
+
+- (void)testUnknownRemove {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 803);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:@"bar"];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 803);
+
+ [dict removeEnumForKey:@"mumble"];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"mumble"]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertFalse([dict getEnum:NULL forKey:@"mumble"]);
+ [dict release];
+}
+
+- (void)testInplaceMutationUnknowns {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 803);
+
+ XCTAssertThrowsSpecificNamed([dict setEnum:803 forKey:@"foo"], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:803 forKey:@"foo"]; // Unknown
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:700 forKey:@"mumble"];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 700);
+
+ const NSString *kKeys2[] = { @"bar", @"baz" };
+ const int32_t kValues2[] = { 702, 801 }; // Unknown
+ GPBStringEnumDictionary *dict2 =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"foo"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"foo"]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"bar"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"bar"]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:@"baz"]);
+ XCTAssertTrue([dict getRawValue:&value forKey:@"baz"]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:@"mumble"]);
+ XCTAssertTrue([dict getEnum:&value forKey:@"mumble"]);
+ XCTAssertEqual(value, 700);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testCopyUnknowns {
+ const NSString *kKeys[] = { @"foo", @"bar", @"baz", @"mumble" };
+ const int32_t kValues[] = { 700, 801, 702, 803 };
+ GPBStringEnumDictionary *dict =
+ [[GPBStringEnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBStringEnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertTrue([dict2 isKindOfClass:[GPBStringEnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND-END TESTS_FOR_POD_VALUES(String, NSString, *, Objects, @"foo", @"bar", @"baz", @"mumble")
+
diff --git a/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+UInt32.m b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+UInt32.m
new file mode 100644
index 0000000000..1d3f6f78b0
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+UInt32.m
@@ -0,0 +1,3647 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+#import <XCTest/XCTest.h>
+
+#import "GPBDictionary.h"
+
+#import "GPBTestUtilities.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+
+// Pull in the macros (using an external file because expanding all tests
+// in a single file makes a file that is failing to work with within Xcode.
+//%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm
+
+//%PDDM-EXPAND TEST_FOR_POD_KEY(UInt32, uint32_t, 1U, 2U, 3U, 4U)
+// This block of code is generated, do not edit it directly.
+
+// To let the testing macros work, add some extra methods to simplify things.
+@interface GPBUInt32EnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(uint32_t)key;
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count;
+@end
+
+static BOOL TestingEnum_IsValidValue(int32_t value) {
+ switch (value) {
+ case 700:
+ case 701:
+ case 702:
+ case 703:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+@implementation GPBUInt32EnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(uint32_t)key {
+ // Cast is needed to compiler knows what class we are invoking initWithValues: on to get the
+ // type correct.
+ return [[(GPBUInt32EnumDictionary*)[self alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const uint32_t [])keys
+ count:(NSUInteger)count {
+ return [self initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:values
+ forKeys:keys
+ count:count];
+}
+@end
+
+
+#pragma mark - UInt32 -> UInt32
+
+@interface GPBUInt32UInt32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32UInt32DictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32UInt32Dictionary *dict = [[GPBUInt32UInt32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:1U]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(uint32_t aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32UInt32Dictionary *dict = [GPBUInt32UInt32Dictionary dictionaryWithUInt32:100U forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:2U]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(uint32_t aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqual(aValue, 100U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const uint32_t kValues[] = { 100U, 101U, 102U };
+ GPBUInt32UInt32Dictionary *dict =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ uint32_t *seenValues = malloc(3 * sizeof(uint32_t));
+ [dict enumerateKeysAndUInt32sUsingBlock:^(uint32_t aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt32sUsingBlock:^(uint32_t aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const uint32_t kValues1[] = { 100U, 101U, 102U };
+ const uint32_t kValues2[] = { 100U, 103U, 102U };
+ const uint32_t kValues3[] = { 100U, 101U, 102U, 103U };
+ GPBUInt32UInt32Dictionary *dict1 =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32UInt32Dictionary *dict1prime =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32UInt32Dictionary *dict2 =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32UInt32Dictionary *dict3 =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32UInt32Dictionary *dict4 =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBUInt32UInt32Dictionary *dict =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32UInt32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32UInt32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBUInt32UInt32Dictionary *dict =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32UInt32Dictionary *dict2 =
+ [GPBUInt32UInt32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32UInt32Dictionary *dict = [GPBUInt32UInt32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt32:100U forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const uint32_t kValues[] = { 101U, 102U, 103U };
+ GPBUInt32UInt32Dictionary *dict2 =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 103U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBUInt32UInt32Dictionary *dict =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt32ForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 103U);
+
+ // Remove again does nothing.
+ [dict removeUInt32ForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 103U);
+
+ [dict removeUInt32ForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:1U]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:2U]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:3U]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBUInt32UInt32Dictionary *dict =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:103U forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:101U forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 101U);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const uint32_t kValues2[] = { 102U, 100U };
+ GPBUInt32UInt32Dictionary *dict2 =
+ [[GPBUInt32UInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 101U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> Int32
+
+@interface GPBUInt32Int32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32Int32DictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32Int32Dictionary *dict = [[GPBUInt32Int32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:1U]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32Int32Dictionary *dict = [GPBUInt32Int32Dictionary dictionaryWithInt32:200 forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:2U]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqual(aValue, 200);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const int32_t kValues[] = { 200, 201, 202 };
+ GPBUInt32Int32Dictionary *dict =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndInt32sUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt32sUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const int32_t kValues1[] = { 200, 201, 202 };
+ const int32_t kValues2[] = { 200, 203, 202 };
+ const int32_t kValues3[] = { 200, 201, 202, 203 };
+ GPBUInt32Int32Dictionary *dict1 =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32Int32Dictionary *dict1prime =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32Int32Dictionary *dict2 =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32Int32Dictionary *dict3 =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32Int32Dictionary *dict4 =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBUInt32Int32Dictionary *dict =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32Int32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32Int32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBUInt32Int32Dictionary *dict =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32Int32Dictionary *dict2 =
+ [GPBUInt32Int32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32Int32Dictionary *dict = [GPBUInt32Int32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt32:200 forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const int32_t kValues[] = { 201, 202, 203 };
+ GPBUInt32Int32Dictionary *dict2 =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 203);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBUInt32Int32Dictionary *dict =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt32ForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 203);
+
+ // Remove again does nothing.
+ [dict removeInt32ForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 203);
+
+ [dict removeInt32ForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:1U]);
+ XCTAssertFalse([dict getInt32:NULL forKey:2U]);
+ XCTAssertFalse([dict getInt32:NULL forKey:3U]);
+ XCTAssertFalse([dict getInt32:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBUInt32Int32Dictionary *dict =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:203 forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:201 forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 201);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const int32_t kValues2[] = { 202, 200 };
+ GPBUInt32Int32Dictionary *dict2 =
+ [[GPBUInt32Int32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt32:&value forKey:1U]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt32:&value forKey:2U]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt32:&value forKey:3U]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt32:&value forKey:4U]);
+ XCTAssertEqual(value, 201);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> UInt64
+
+@interface GPBUInt32UInt64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32UInt64DictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32UInt64Dictionary *dict = [[GPBUInt32UInt64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:1U]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(uint32_t aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32UInt64Dictionary *dict = [GPBUInt32UInt64Dictionary dictionaryWithUInt64:300U forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:2U]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(uint32_t aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqual(aValue, 300U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const uint64_t kValues[] = { 300U, 301U, 302U };
+ GPBUInt32UInt64Dictionary *dict =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ uint64_t *seenValues = malloc(3 * sizeof(uint64_t));
+ [dict enumerateKeysAndUInt64sUsingBlock:^(uint32_t aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt64sUsingBlock:^(uint32_t aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const uint64_t kValues1[] = { 300U, 301U, 302U };
+ const uint64_t kValues2[] = { 300U, 303U, 302U };
+ const uint64_t kValues3[] = { 300U, 301U, 302U, 303U };
+ GPBUInt32UInt64Dictionary *dict1 =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32UInt64Dictionary *dict1prime =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32UInt64Dictionary *dict2 =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32UInt64Dictionary *dict3 =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32UInt64Dictionary *dict4 =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBUInt32UInt64Dictionary *dict =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32UInt64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32UInt64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBUInt32UInt64Dictionary *dict =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32UInt64Dictionary *dict2 =
+ [GPBUInt32UInt64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32UInt64Dictionary *dict = [GPBUInt32UInt64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt64:300U forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const uint64_t kValues[] = { 301U, 302U, 303U };
+ GPBUInt32UInt64Dictionary *dict2 =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 303U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBUInt32UInt64Dictionary *dict =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt64ForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 303U);
+
+ // Remove again does nothing.
+ [dict removeUInt64ForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 303U);
+
+ [dict removeUInt64ForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:1U]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:2U]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:3U]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBUInt32UInt64Dictionary *dict =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:303U forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:301U forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 301U);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const uint64_t kValues2[] = { 302U, 300U };
+ GPBUInt32UInt64Dictionary *dict2 =
+ [[GPBUInt32UInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getUInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 301U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> Int64
+
+@interface GPBUInt32Int64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32Int64DictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32Int64Dictionary *dict = [[GPBUInt32Int64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:1U]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(uint32_t aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32Int64Dictionary *dict = [GPBUInt32Int64Dictionary dictionaryWithInt64:400 forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:2U]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(uint32_t aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqual(aValue, 400);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const int64_t kValues[] = { 400, 401, 402 };
+ GPBUInt32Int64Dictionary *dict =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ int64_t *seenValues = malloc(3 * sizeof(int64_t));
+ [dict enumerateKeysAndInt64sUsingBlock:^(uint32_t aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt64sUsingBlock:^(uint32_t aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const int64_t kValues1[] = { 400, 401, 402 };
+ const int64_t kValues2[] = { 400, 403, 402 };
+ const int64_t kValues3[] = { 400, 401, 402, 403 };
+ GPBUInt32Int64Dictionary *dict1 =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32Int64Dictionary *dict1prime =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32Int64Dictionary *dict2 =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32Int64Dictionary *dict3 =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32Int64Dictionary *dict4 =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBUInt32Int64Dictionary *dict =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32Int64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32Int64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBUInt32Int64Dictionary *dict =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32Int64Dictionary *dict2 =
+ [GPBUInt32Int64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32Int64Dictionary *dict = [GPBUInt32Int64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt64:400 forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const int64_t kValues[] = { 401, 402, 403 };
+ GPBUInt32Int64Dictionary *dict2 =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 403);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBUInt32Int64Dictionary *dict =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt64ForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 403);
+
+ // Remove again does nothing.
+ [dict removeInt64ForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 403);
+
+ [dict removeInt64ForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:1U]);
+ XCTAssertFalse([dict getInt64:NULL forKey:2U]);
+ XCTAssertFalse([dict getInt64:NULL forKey:3U]);
+ XCTAssertFalse([dict getInt64:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBUInt32Int64Dictionary *dict =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:403 forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:401 forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 401);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const int64_t kValues2[] = { 402, 400 };
+ GPBUInt32Int64Dictionary *dict2 =
+ [[GPBUInt32Int64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:1U]);
+ XCTAssertTrue([dict getInt64:&value forKey:1U]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:2U]);
+ XCTAssertTrue([dict getInt64:&value forKey:2U]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:3U]);
+ XCTAssertTrue([dict getInt64:&value forKey:3U]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:4U]);
+ XCTAssertTrue([dict getInt64:&value forKey:4U]);
+ XCTAssertEqual(value, 401);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> Bool
+
+@interface GPBUInt32BoolDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32BoolDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32BoolDictionary *dict = [[GPBUInt32BoolDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:1U]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(uint32_t aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32BoolDictionary *dict = [GPBUInt32BoolDictionary dictionaryWithBool:YES forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:2U]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(uint32_t aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqual(aValue, YES);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const BOOL kValues[] = { YES, YES, NO };
+ GPBUInt32BoolDictionary *dict =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:&value forKey:2U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ BOOL *seenValues = malloc(3 * sizeof(BOOL));
+ [dict enumerateKeysAndBoolsUsingBlock:^(uint32_t aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndBoolsUsingBlock:^(uint32_t aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const BOOL kValues1[] = { YES, YES, NO };
+ const BOOL kValues2[] = { YES, NO, NO };
+ const BOOL kValues3[] = { YES, YES, NO, NO };
+ GPBUInt32BoolDictionary *dict1 =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32BoolDictionary *dict1prime =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32BoolDictionary *dict2 =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32BoolDictionary *dict3 =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32BoolDictionary *dict4 =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBUInt32BoolDictionary *dict =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32BoolDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32BoolDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBUInt32BoolDictionary *dict =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32BoolDictionary *dict2 =
+ [GPBUInt32BoolDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32BoolDictionary *dict = [GPBUInt32BoolDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setBool:YES forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const BOOL kValues[] = { YES, NO, NO };
+ GPBUInt32BoolDictionary *dict2 =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:&value forKey:2U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:4U]);
+ XCTAssertTrue([dict getBool:&value forKey:4U]);
+ XCTAssertEqual(value, NO);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBUInt32BoolDictionary *dict =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeBoolForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:4U]);
+ XCTAssertTrue([dict getBool:&value forKey:4U]);
+ XCTAssertEqual(value, NO);
+
+ // Remove again does nothing.
+ [dict removeBoolForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:4U]);
+ XCTAssertTrue([dict getBool:&value forKey:4U]);
+ XCTAssertEqual(value, NO);
+
+ [dict removeBoolForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:1U]);
+ XCTAssertFalse([dict getBool:NULL forKey:2U]);
+ XCTAssertFalse([dict getBool:NULL forKey:3U]);
+ XCTAssertFalse([dict getBool:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBUInt32BoolDictionary *dict =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:&value forKey:2U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:4U]);
+ XCTAssertTrue([dict getBool:&value forKey:4U]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:NO forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:&value forKey:2U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:4U]);
+ XCTAssertTrue([dict getBool:&value forKey:4U]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:YES forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:&value forKey:2U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:4U]);
+ XCTAssertTrue([dict getBool:&value forKey:4U]);
+ XCTAssertEqual(value, YES);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const BOOL kValues2[] = { NO, YES };
+ GPBUInt32BoolDictionary *dict2 =
+ [[GPBUInt32BoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:1U]);
+ XCTAssertTrue([dict getBool:&value forKey:1U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:2U]);
+ XCTAssertTrue([dict getBool:&value forKey:2U]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:3U]);
+ XCTAssertTrue([dict getBool:&value forKey:3U]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:4U]);
+ XCTAssertTrue([dict getBool:&value forKey:4U]);
+ XCTAssertEqual(value, YES);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> Float
+
+@interface GPBUInt32FloatDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32FloatDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32FloatDictionary *dict = [[GPBUInt32FloatDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:1U]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(uint32_t aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32FloatDictionary *dict = [GPBUInt32FloatDictionary dictionaryWithFloat:500.f forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:2U]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(uint32_t aKey, float aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqual(aValue, 500.f);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const float kValues[] = { 500.f, 501.f, 502.f };
+ GPBUInt32FloatDictionary *dict =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:&value forKey:2U]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ float *seenValues = malloc(3 * sizeof(float));
+ [dict enumerateKeysAndFloatsUsingBlock:^(uint32_t aKey, float aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndFloatsUsingBlock:^(uint32_t aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const float kValues1[] = { 500.f, 501.f, 502.f };
+ const float kValues2[] = { 500.f, 503.f, 502.f };
+ const float kValues3[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt32FloatDictionary *dict1 =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32FloatDictionary *dict1prime =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32FloatDictionary *dict2 =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32FloatDictionary *dict3 =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32FloatDictionary *dict4 =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt32FloatDictionary *dict =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32FloatDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32FloatDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt32FloatDictionary *dict =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32FloatDictionary *dict2 =
+ [GPBUInt32FloatDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32FloatDictionary *dict = [GPBUInt32FloatDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setFloat:500.f forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const float kValues[] = { 501.f, 502.f, 503.f };
+ GPBUInt32FloatDictionary *dict2 =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:&value forKey:2U]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:4U]);
+ XCTAssertTrue([dict getFloat:&value forKey:4U]);
+ XCTAssertEqual(value, 503.f);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt32FloatDictionary *dict =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeFloatForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:4U]);
+ XCTAssertTrue([dict getFloat:&value forKey:4U]);
+ XCTAssertEqual(value, 503.f);
+
+ // Remove again does nothing.
+ [dict removeFloatForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:4U]);
+ XCTAssertTrue([dict getFloat:&value forKey:4U]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict removeFloatForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:1U]);
+ XCTAssertFalse([dict getFloat:NULL forKey:2U]);
+ XCTAssertFalse([dict getFloat:NULL forKey:3U]);
+ XCTAssertFalse([dict getFloat:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt32FloatDictionary *dict =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:&value forKey:2U]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:4U]);
+ XCTAssertTrue([dict getFloat:&value forKey:4U]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:503.f forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:&value forKey:2U]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:4U]);
+ XCTAssertTrue([dict getFloat:&value forKey:4U]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:501.f forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:&value forKey:2U]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:4U]);
+ XCTAssertTrue([dict getFloat:&value forKey:4U]);
+ XCTAssertEqual(value, 501.f);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const float kValues2[] = { 502.f, 500.f };
+ GPBUInt32FloatDictionary *dict2 =
+ [[GPBUInt32FloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:1U]);
+ XCTAssertTrue([dict getFloat:&value forKey:1U]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:2U]);
+ XCTAssertTrue([dict getFloat:&value forKey:2U]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:3U]);
+ XCTAssertTrue([dict getFloat:&value forKey:3U]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:4U]);
+ XCTAssertTrue([dict getFloat:&value forKey:4U]);
+ XCTAssertEqual(value, 501.f);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> Double
+
+@interface GPBUInt32DoubleDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32DoubleDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32DoubleDictionary *dict = [[GPBUInt32DoubleDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:1U]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(uint32_t aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32DoubleDictionary *dict = [GPBUInt32DoubleDictionary dictionaryWithDouble:600. forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:2U]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(uint32_t aKey, double aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqual(aValue, 600.);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const double kValues[] = { 600., 601., 602. };
+ GPBUInt32DoubleDictionary *dict =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:&value forKey:2U]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ double *seenValues = malloc(3 * sizeof(double));
+ [dict enumerateKeysAndDoublesUsingBlock:^(uint32_t aKey, double aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndDoublesUsingBlock:^(uint32_t aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const double kValues1[] = { 600., 601., 602. };
+ const double kValues2[] = { 600., 603., 602. };
+ const double kValues3[] = { 600., 601., 602., 603. };
+ GPBUInt32DoubleDictionary *dict1 =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32DoubleDictionary *dict1prime =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32DoubleDictionary *dict2 =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32DoubleDictionary *dict3 =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32DoubleDictionary *dict4 =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBUInt32DoubleDictionary *dict =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32DoubleDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32DoubleDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBUInt32DoubleDictionary *dict =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32DoubleDictionary *dict2 =
+ [GPBUInt32DoubleDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32DoubleDictionary *dict = [GPBUInt32DoubleDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setDouble:600. forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const double kValues[] = { 601., 602., 603. };
+ GPBUInt32DoubleDictionary *dict2 =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:&value forKey:2U]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:4U]);
+ XCTAssertTrue([dict getDouble:&value forKey:4U]);
+ XCTAssertEqual(value, 603.);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBUInt32DoubleDictionary *dict =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeDoubleForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:4U]);
+ XCTAssertTrue([dict getDouble:&value forKey:4U]);
+ XCTAssertEqual(value, 603.);
+
+ // Remove again does nothing.
+ [dict removeDoubleForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:4U]);
+ XCTAssertTrue([dict getDouble:&value forKey:4U]);
+ XCTAssertEqual(value, 603.);
+
+ [dict removeDoubleForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:1U]);
+ XCTAssertFalse([dict getDouble:NULL forKey:2U]);
+ XCTAssertFalse([dict getDouble:NULL forKey:3U]);
+ XCTAssertFalse([dict getDouble:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBUInt32DoubleDictionary *dict =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:&value forKey:2U]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:4U]);
+ XCTAssertTrue([dict getDouble:&value forKey:4U]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:603. forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:&value forKey:2U]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:4U]);
+ XCTAssertTrue([dict getDouble:&value forKey:4U]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:601. forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:&value forKey:2U]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:4U]);
+ XCTAssertTrue([dict getDouble:&value forKey:4U]);
+ XCTAssertEqual(value, 601.);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const double kValues2[] = { 602., 600. };
+ GPBUInt32DoubleDictionary *dict2 =
+ [[GPBUInt32DoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:1U]);
+ XCTAssertTrue([dict getDouble:&value forKey:1U]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:2U]);
+ XCTAssertTrue([dict getDouble:&value forKey:2U]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:3U]);
+ XCTAssertTrue([dict getDouble:&value forKey:3U]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:4U]);
+ XCTAssertTrue([dict getDouble:&value forKey:4U]);
+ XCTAssertEqual(value, 601.);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> Enum
+
+@interface GPBUInt32EnumDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32EnumDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32EnumDictionary *dict = [[GPBUInt32EnumDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:1U]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32EnumDictionary *dict = [GPBUInt32EnumDictionary dictionaryWithEnum:700 forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqual(aValue, 700);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const int32_t kValues[] = { 700, 701, 702 };
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const int32_t kValues1[] = { 700, 701, 702 };
+ const int32_t kValues2[] = { 700, 703, 702 };
+ const int32_t kValues3[] = { 700, 701, 702, 703 };
+ GPBUInt32EnumDictionary *dict1 =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32EnumDictionary *dict1prime =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32EnumDictionary *dict2 =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32EnumDictionary *dict3 =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32EnumDictionary *dict4 =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32EnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32EnumDictionary *dict2 =
+ [GPBUInt32EnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32EnumDictionary *dict = [GPBUInt32EnumDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setEnum:700 forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const int32_t kValues[] = { 701, 702, 703 };
+ GPBUInt32EnumDictionary *dict2 =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 703);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 703);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 703);
+
+ [dict removeEnumForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:1U]);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ XCTAssertFalse([dict getEnum:NULL forKey:3U]);
+ XCTAssertFalse([dict getEnum:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:703 forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:701 forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 701);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const int32_t kValues2[] = { 702, 700 };
+ GPBUInt32EnumDictionary *dict2 =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 701);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> Enum (Unknown Enums)
+
+@interface GPBUInt32EnumDictionaryUnknownEnumTests : XCTestCase
+@end
+
+@implementation GPBUInt32EnumDictionaryUnknownEnumTests
+
+- (void)testRawBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const int32_t kValues[] = { 700, 801, 702 };
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue(dict.validationFunc == TestingEnum_IsValidValue); // Pointer comparison
+ int32_t value;
+ XCTAssertTrue([dict getRawValue:NULL forKey:1U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:2U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:2U]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getRawValue:NULL forKey:3U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getRawValue:NULL forKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ if (i == 1) {
+ XCTAssertEqual(kGPBUnrecognizedEnumeratorValue, seenValues[j], @"i = %d, j = %d", i, j);
+ } else {
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(uint32_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEqualityWithUnknowns {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const int32_t kValues1[] = { 700, 801, 702 }; // Unknown
+ const int32_t kValues2[] = { 700, 803, 702 }; // Unknown
+ const int32_t kValues3[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBUInt32EnumDictionary *dict1 =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32EnumDictionary *dict1prime =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32EnumDictionary *dict2 =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32EnumDictionary *dict3 =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32EnumDictionary *dict4 =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopyWithUnknowns {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknown
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertEqualObjects(dict, dict2);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32EnumDictionary *dict2 =
+ [GPBUInt32EnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ [dict release];
+}
+
+- (void)testUnknownAdds {
+ GPBUInt32EnumDictionary *dict =
+ [GPBUInt32EnumDictionary dictionaryWithValidationFunction:TestingEnum_IsValidValue];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertThrowsSpecificNamed([dict setEnum:801 forKey:2U], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 0U);
+ [dict setRawValue:801 forKey:2U]; // Unknown
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 1U, 3U, 4U };
+ const int32_t kValues[] = { 700, 702, 803 }; // Unknown
+ GPBUInt32EnumDictionary *dict2 =
+ [[GPBUInt32EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:2U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:2U]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:4U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:4U]);
+ XCTAssertEqual(value, 803);
+ [dict2 release];
+}
+
+- (void)testUnknownRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:4U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:4U]);
+ XCTAssertEqual(value, 803);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:4U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:4U]);
+ XCTAssertEqual(value, 803);
+
+ [dict removeEnumForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:1U]);
+ XCTAssertFalse([dict getEnum:NULL forKey:2U]);
+ XCTAssertFalse([dict getEnum:NULL forKey:3U]);
+ XCTAssertFalse([dict getEnum:NULL forKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutationUnknowns {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:2U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:2U]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:4U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:4U]);
+ XCTAssertEqual(value, 803);
+
+ XCTAssertThrowsSpecificNamed([dict setEnum:803 forKey:1U], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:1U]);
+ XCTAssertTrue([dict getEnum:&value forKey:1U]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:2U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:2U]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:4U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:4U]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:803 forKey:1U]; // Unknown
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:1U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:1U]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:2U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:2U]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:4U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:4U]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:700 forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:1U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:1U]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:2U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:2U]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:3U]);
+ XCTAssertTrue([dict getEnum:&value forKey:3U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 700);
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const int32_t kValues2[] = { 702, 801 }; // Unknown
+ GPBUInt32EnumDictionary *dict2 =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:1U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:1U]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getEnum:NULL forKey:2U]);
+ XCTAssertTrue([dict getEnum:&value forKey:2U]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:3U]);
+ XCTAssertTrue([dict getRawValue:&value forKey:3U]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:4U]);
+ XCTAssertTrue([dict getEnum:&value forKey:4U]);
+ XCTAssertEqual(value, 700);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testCopyUnknowns {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const int32_t kValues[] = { 700, 801, 702, 803 };
+ GPBUInt32EnumDictionary *dict =
+ [[GPBUInt32EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32EnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt32 -> Object
+
+@interface GPBUInt32ObjectDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt32ObjectDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt32ObjectDictionary<NSString*> *dict = [[GPBUInt32ObjectDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:1U]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt32ObjectDictionary<NSString*> *dict = [GPBUInt32ObjectDictionary dictionaryWithObject:@"abc" forKey:1U];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"abc");
+ XCTAssertNil([dict objectForKey:2U]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertEqual(aKey, 1U);
+ XCTAssertEqualObjects(aObject, @"abc");
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint32_t kKeys[] = { 1U, 2U, 3U };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi" };
+ GPBUInt32ObjectDictionary<NSString*> *dict =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:2U], @"def");
+ XCTAssertEqualObjects([dict objectForKey:3U], @"ghi");
+ XCTAssertNil([dict objectForKey:4U]);
+
+ __block NSUInteger idx = 0;
+ uint32_t *seenKeys = malloc(3 * sizeof(uint32_t));
+ NSString* *seenObjects = malloc(3 * sizeof(NSString*));
+ [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenObjects[idx] = aObject;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqualObjects(kObjects[i], seenObjects[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenObjects);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndObjectsUsingBlock:^(uint32_t aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint32_t kKeys1[] = { 1U, 2U, 3U, 4U };
+ const uint32_t kKeys2[] = { 2U, 1U, 4U };
+ const NSString* kObjects1[] = { @"abc", @"def", @"ghi" };
+ const NSString* kObjects2[] = { @"abc", @"jkl", @"ghi" };
+ const NSString* kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt32ObjectDictionary<NSString*> *dict1 =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt32ObjectDictionary<NSString*> *dict1prime =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt32ObjectDictionary<NSString*> *dict2 =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt32ObjectDictionary<NSString*> *dict3 =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt32ObjectDictionary<NSString*> *dict4 =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt32ObjectDictionary<NSString*> *dict =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32ObjectDictionary<NSString*> *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt32ObjectDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt32ObjectDictionary<NSString*> *dict =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt32ObjectDictionary<NSString*> *dict2 =
+ [GPBUInt32ObjectDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt32ObjectDictionary<NSString*> *dict = [GPBUInt32ObjectDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setObject:@"abc" forKey:1U];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint32_t kKeys[] = { 2U, 3U, 4U };
+ const NSString* kObjects[] = { @"def", @"ghi", @"jkl" };
+ GPBUInt32ObjectDictionary<NSString*> *dict2 =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ XCTAssertEqualObjects([dict objectForKey:1U], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:2U], @"def");
+ XCTAssertEqualObjects([dict objectForKey:3U], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:4U], @"jkl");
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt32ObjectDictionary<NSString*> *dict =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeObjectForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"abc");
+ XCTAssertNil([dict objectForKey:2U]);
+ XCTAssertEqualObjects([dict objectForKey:3U], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:4U], @"jkl");
+
+ // Remove again does nothing.
+ [dict removeObjectForKey:2U];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"abc");
+ XCTAssertNil([dict objectForKey:2U]);
+ XCTAssertEqualObjects([dict objectForKey:3U], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:4U], @"jkl");
+
+ [dict removeObjectForKey:4U];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"abc");
+ XCTAssertNil([dict objectForKey:2U]);
+ XCTAssertEqualObjects([dict objectForKey:3U], @"ghi");
+ XCTAssertNil([dict objectForKey:4U]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:1U]);
+ XCTAssertNil([dict objectForKey:2U]);
+ XCTAssertNil([dict objectForKey:3U]);
+ XCTAssertNil([dict objectForKey:4U]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint32_t kKeys[] = { 1U, 2U, 3U, 4U };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt32ObjectDictionary<NSString*> *dict =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:2U], @"def");
+ XCTAssertEqualObjects([dict objectForKey:3U], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:4U], @"jkl");
+
+ [dict setObject:@"jkl" forKey:1U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:2U], @"def");
+ XCTAssertEqualObjects([dict objectForKey:3U], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:4U], @"jkl");
+
+ [dict setObject:@"def" forKey:4U];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:2U], @"def");
+ XCTAssertEqualObjects([dict objectForKey:3U], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:4U], @"def");
+
+ const uint32_t kKeys2[] = { 2U, 3U };
+ const NSString* kObjects2[] = { @"ghi", @"abc" };
+ GPBUInt32ObjectDictionary<NSString*> *dict2 =
+ [[GPBUInt32ObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:1U], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:2U], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:3U], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:4U], @"def");
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND-END TEST_FOR_POD_KEY(UInt32, uint32_t, 1U, 2U, 3U, 4U)
+
diff --git a/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+UInt64.m b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+UInt64.m
new file mode 100644
index 0000000000..94c116f67f
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests+UInt64.m
@@ -0,0 +1,3646 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+#import <XCTest/XCTest.h>
+
+#import "GPBDictionary.h"
+
+#import "GPBTestUtilities.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+
+// Pull in the macros (using an external file because expanding all tests
+// in a single file makes a file that is failing to work with within Xcode.
+//%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm
+
+//%PDDM-EXPAND TEST_FOR_POD_KEY(UInt64, uint64_t, 31ULL, 32ULL, 33ULL, 34ULL)
+// This block of code is generated, do not edit it directly.
+
+// To let the testing macros work, add some extra methods to simplify things.
+@interface GPBUInt64EnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(uint64_t)key;
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count;
+@end
+
+static BOOL TestingEnum_IsValidValue(int32_t value) {
+ switch (value) {
+ case 700:
+ case 701:
+ case 702:
+ case 703:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+@implementation GPBUInt64EnumDictionary (TestingTweak)
++ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(uint64_t)key {
+ // Cast is needed to compiler knows what class we are invoking initWithValues: on to get the
+ // type correct.
+ return [[(GPBUInt64EnumDictionary*)[self alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:&value
+ forKeys:&key
+ count:1] autorelease];
+}
+- (instancetype)initWithEnums:(const int32_t [])values
+ forKeys:(const uint64_t [])keys
+ count:(NSUInteger)count {
+ return [self initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:values
+ forKeys:keys
+ count:count];
+}
+@end
+
+
+#pragma mark - UInt64 -> UInt32
+
+@interface GPBUInt64UInt32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64UInt32DictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64UInt32Dictionary *dict = [[GPBUInt64UInt32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:31ULL]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(uint64_t aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64UInt32Dictionary *dict = [GPBUInt64UInt32Dictionary dictionaryWithUInt32:100U forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:32ULL]);
+ [dict enumerateKeysAndUInt32sUsingBlock:^(uint64_t aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqual(aValue, 100U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const uint32_t kValues[] = { 100U, 101U, 102U };
+ GPBUInt64UInt32Dictionary *dict =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ uint32_t *seenValues = malloc(3 * sizeof(uint32_t));
+ [dict enumerateKeysAndUInt32sUsingBlock:^(uint64_t aKey, uint32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt32sUsingBlock:^(uint64_t aKey, uint32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const uint32_t kValues1[] = { 100U, 101U, 102U };
+ const uint32_t kValues2[] = { 100U, 103U, 102U };
+ const uint32_t kValues3[] = { 100U, 101U, 102U, 103U };
+ GPBUInt64UInt32Dictionary *dict1 =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64UInt32Dictionary *dict1prime =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64UInt32Dictionary *dict2 =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64UInt32Dictionary *dict3 =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64UInt32Dictionary *dict4 =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBUInt64UInt32Dictionary *dict =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64UInt32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64UInt32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBUInt64UInt32Dictionary *dict =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64UInt32Dictionary *dict2 =
+ [GPBUInt64UInt32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64UInt32Dictionary *dict = [GPBUInt64UInt32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt32:100U forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const uint32_t kValues[] = { 101U, 102U, 103U };
+ GPBUInt64UInt32Dictionary *dict2 =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 103U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBUInt64UInt32Dictionary *dict =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt32ForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 103U);
+
+ // Remove again does nothing.
+ [dict removeUInt32ForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 103U);
+
+ [dict removeUInt32ForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getUInt32:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint32_t kValues[] = { 100U, 101U, 102U, 103U };
+ GPBUInt64UInt32Dictionary *dict =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint32_t value;
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:103U forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 103U);
+
+ [dict setUInt32:101U forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 101U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 101U);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const uint32_t kValues2[] = { 102U, 100U };
+ GPBUInt64UInt32Dictionary *dict2 =
+ [[GPBUInt64UInt32Dictionary alloc] initWithUInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 103U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 102U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 100U);
+ XCTAssertTrue([dict getUInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 101U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> Int32
+
+@interface GPBUInt64Int32DictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64Int32DictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64Int32Dictionary *dict = [[GPBUInt64Int32Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:31ULL]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64Int32Dictionary *dict = [GPBUInt64Int32Dictionary dictionaryWithInt32:200 forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:32ULL]);
+ [dict enumerateKeysAndInt32sUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqual(aValue, 200);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const int32_t kValues[] = { 200, 201, 202 };
+ GPBUInt64Int32Dictionary *dict =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndInt32sUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt32sUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const int32_t kValues1[] = { 200, 201, 202 };
+ const int32_t kValues2[] = { 200, 203, 202 };
+ const int32_t kValues3[] = { 200, 201, 202, 203 };
+ GPBUInt64Int32Dictionary *dict1 =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64Int32Dictionary *dict1prime =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64Int32Dictionary *dict2 =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64Int32Dictionary *dict3 =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64Int32Dictionary *dict4 =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBUInt64Int32Dictionary *dict =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64Int32Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64Int32Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBUInt64Int32Dictionary *dict =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64Int32Dictionary *dict2 =
+ [GPBUInt64Int32Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64Int32Dictionary *dict = [GPBUInt64Int32Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt32:200 forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 201, 202, 203 };
+ GPBUInt64Int32Dictionary *dict2 =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 203);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBUInt64Int32Dictionary *dict =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt32ForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 203);
+
+ // Remove again does nothing.
+ [dict removeInt32ForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 203);
+
+ [dict removeInt32ForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertFalse([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertFalse([dict getInt32:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getInt32:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 200, 201, 202, 203 };
+ GPBUInt64Int32Dictionary *dict =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:203 forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 203);
+
+ [dict setInt32:201 forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 201);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 201);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const int32_t kValues2[] = { 202, 200 };
+ GPBUInt64Int32Dictionary *dict2 =
+ [[GPBUInt64Int32Dictionary alloc] initWithInt32s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt32:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:31ULL]);
+ XCTAssertEqual(value, 203);
+ XCTAssertTrue([dict getInt32:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:32ULL]);
+ XCTAssertEqual(value, 202);
+ XCTAssertTrue([dict getInt32:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:33ULL]);
+ XCTAssertEqual(value, 200);
+ XCTAssertTrue([dict getInt32:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt32:&value forKey:34ULL]);
+ XCTAssertEqual(value, 201);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> UInt64
+
+@interface GPBUInt64UInt64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64UInt64DictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64UInt64Dictionary *dict = [[GPBUInt64UInt64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:31ULL]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(uint64_t aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64UInt64Dictionary *dict = [GPBUInt64UInt64Dictionary dictionaryWithUInt64:300U forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:32ULL]);
+ [dict enumerateKeysAndUInt64sUsingBlock:^(uint64_t aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqual(aValue, 300U);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const uint64_t kValues[] = { 300U, 301U, 302U };
+ GPBUInt64UInt64Dictionary *dict =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ uint64_t *seenValues = malloc(3 * sizeof(uint64_t));
+ [dict enumerateKeysAndUInt64sUsingBlock:^(uint64_t aKey, uint64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndUInt64sUsingBlock:^(uint64_t aKey, uint64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const uint64_t kValues1[] = { 300U, 301U, 302U };
+ const uint64_t kValues2[] = { 300U, 303U, 302U };
+ const uint64_t kValues3[] = { 300U, 301U, 302U, 303U };
+ GPBUInt64UInt64Dictionary *dict1 =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64UInt64Dictionary *dict1prime =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64UInt64Dictionary *dict2 =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64UInt64Dictionary *dict3 =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64UInt64Dictionary *dict4 =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBUInt64UInt64Dictionary *dict =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64UInt64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64UInt64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBUInt64UInt64Dictionary *dict =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64UInt64Dictionary *dict2 =
+ [GPBUInt64UInt64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64UInt64Dictionary *dict = [GPBUInt64UInt64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setUInt64:300U forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const uint64_t kValues[] = { 301U, 302U, 303U };
+ GPBUInt64UInt64Dictionary *dict2 =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 303U);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBUInt64UInt64Dictionary *dict =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeUInt64ForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 303U);
+
+ // Remove again does nothing.
+ [dict removeUInt64ForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 303U);
+
+ [dict removeUInt64ForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getUInt64:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kValues[] = { 300U, 301U, 302U, 303U };
+ GPBUInt64UInt64Dictionary *dict =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ uint64_t value;
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:303U forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 303U);
+
+ [dict setUInt64:301U forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 301U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 301U);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const uint64_t kValues2[] = { 302U, 300U };
+ GPBUInt64UInt64Dictionary *dict2 =
+ [[GPBUInt64UInt64Dictionary alloc] initWithUInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 303U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 302U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 300U);
+ XCTAssertTrue([dict getUInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getUInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 301U);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> Int64
+
+@interface GPBUInt64Int64DictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64Int64DictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64Int64Dictionary *dict = [[GPBUInt64Int64Dictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:31ULL]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(uint64_t aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64Int64Dictionary *dict = [GPBUInt64Int64Dictionary dictionaryWithInt64:400 forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:32ULL]);
+ [dict enumerateKeysAndInt64sUsingBlock:^(uint64_t aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqual(aValue, 400);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const int64_t kValues[] = { 400, 401, 402 };
+ GPBUInt64Int64Dictionary *dict =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ int64_t *seenValues = malloc(3 * sizeof(int64_t));
+ [dict enumerateKeysAndInt64sUsingBlock:^(uint64_t aKey, int64_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndInt64sUsingBlock:^(uint64_t aKey, int64_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const int64_t kValues1[] = { 400, 401, 402 };
+ const int64_t kValues2[] = { 400, 403, 402 };
+ const int64_t kValues3[] = { 400, 401, 402, 403 };
+ GPBUInt64Int64Dictionary *dict1 =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64Int64Dictionary *dict1prime =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64Int64Dictionary *dict2 =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64Int64Dictionary *dict3 =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64Int64Dictionary *dict4 =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBUInt64Int64Dictionary *dict =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64Int64Dictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64Int64Dictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBUInt64Int64Dictionary *dict =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64Int64Dictionary *dict2 =
+ [GPBUInt64Int64Dictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64Int64Dictionary *dict = [GPBUInt64Int64Dictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setInt64:400 forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const int64_t kValues[] = { 401, 402, 403 };
+ GPBUInt64Int64Dictionary *dict2 =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 403);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBUInt64Int64Dictionary *dict =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeInt64ForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 403);
+
+ // Remove again does nothing.
+ [dict removeInt64ForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 403);
+
+ [dict removeInt64ForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertFalse([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertFalse([dict getInt64:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getInt64:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int64_t kValues[] = { 400, 401, 402, 403 };
+ GPBUInt64Int64Dictionary *dict =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int64_t value;
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:403 forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 403);
+
+ [dict setInt64:401 forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 401);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 401);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const int64_t kValues2[] = { 402, 400 };
+ GPBUInt64Int64Dictionary *dict2 =
+ [[GPBUInt64Int64Dictionary alloc] initWithInt64s:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getInt64:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:31ULL]);
+ XCTAssertEqual(value, 403);
+ XCTAssertTrue([dict getInt64:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:32ULL]);
+ XCTAssertEqual(value, 402);
+ XCTAssertTrue([dict getInt64:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:33ULL]);
+ XCTAssertEqual(value, 400);
+ XCTAssertTrue([dict getInt64:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getInt64:&value forKey:34ULL]);
+ XCTAssertEqual(value, 401);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> Bool
+
+@interface GPBUInt64BoolDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64BoolDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64BoolDictionary *dict = [[GPBUInt64BoolDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:31ULL]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(uint64_t aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64BoolDictionary *dict = [GPBUInt64BoolDictionary dictionaryWithBool:YES forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:32ULL]);
+ [dict enumerateKeysAndBoolsUsingBlock:^(uint64_t aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqual(aValue, YES);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const BOOL kValues[] = { YES, YES, NO };
+ GPBUInt64BoolDictionary *dict =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:32ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ BOOL *seenValues = malloc(3 * sizeof(BOOL));
+ [dict enumerateKeysAndBoolsUsingBlock:^(uint64_t aKey, BOOL aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndBoolsUsingBlock:^(uint64_t aKey, BOOL aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const BOOL kValues1[] = { YES, YES, NO };
+ const BOOL kValues2[] = { YES, NO, NO };
+ const BOOL kValues3[] = { YES, YES, NO, NO };
+ GPBUInt64BoolDictionary *dict1 =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64BoolDictionary *dict1prime =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64BoolDictionary *dict2 =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64BoolDictionary *dict3 =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64BoolDictionary *dict4 =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBUInt64BoolDictionary *dict =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64BoolDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64BoolDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBUInt64BoolDictionary *dict =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64BoolDictionary *dict2 =
+ [GPBUInt64BoolDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64BoolDictionary *dict = [GPBUInt64BoolDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setBool:YES forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const BOOL kValues[] = { YES, NO, NO };
+ GPBUInt64BoolDictionary *dict2 =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:32ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:34ULL]);
+ XCTAssertEqual(value, NO);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBUInt64BoolDictionary *dict =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeBoolForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:34ULL]);
+ XCTAssertEqual(value, NO);
+
+ // Remove again does nothing.
+ [dict removeBoolForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:34ULL]);
+ XCTAssertEqual(value, NO);
+
+ [dict removeBoolForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertFalse([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertFalse([dict getBool:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getBool:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getBool:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getBool:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getBool:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const BOOL kValues[] = { YES, YES, NO, NO };
+ GPBUInt64BoolDictionary *dict =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ BOOL value;
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:32ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:34ULL]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:NO forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:32ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:34ULL]);
+ XCTAssertEqual(value, NO);
+
+ [dict setBool:YES forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:32ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:34ULL]);
+ XCTAssertEqual(value, YES);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const BOOL kValues2[] = { NO, YES };
+ GPBUInt64BoolDictionary *dict2 =
+ [[GPBUInt64BoolDictionary alloc] initWithBools:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getBool:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:31ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:32ULL]);
+ XCTAssertEqual(value, NO);
+ XCTAssertTrue([dict getBool:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:33ULL]);
+ XCTAssertEqual(value, YES);
+ XCTAssertTrue([dict getBool:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getBool:&value forKey:34ULL]);
+ XCTAssertEqual(value, YES);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> Float
+
+@interface GPBUInt64FloatDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64FloatDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64FloatDictionary *dict = [[GPBUInt64FloatDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:31ULL]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(uint64_t aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64FloatDictionary *dict = [GPBUInt64FloatDictionary dictionaryWithFloat:500.f forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:32ULL]);
+ [dict enumerateKeysAndFloatsUsingBlock:^(uint64_t aKey, float aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqual(aValue, 500.f);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const float kValues[] = { 500.f, 501.f, 502.f };
+ GPBUInt64FloatDictionary *dict =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:32ULL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ float *seenValues = malloc(3 * sizeof(float));
+ [dict enumerateKeysAndFloatsUsingBlock:^(uint64_t aKey, float aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndFloatsUsingBlock:^(uint64_t aKey, float aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const float kValues1[] = { 500.f, 501.f, 502.f };
+ const float kValues2[] = { 500.f, 503.f, 502.f };
+ const float kValues3[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt64FloatDictionary *dict1 =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64FloatDictionary *dict1prime =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64FloatDictionary *dict2 =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64FloatDictionary *dict3 =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64FloatDictionary *dict4 =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt64FloatDictionary *dict =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64FloatDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64FloatDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt64FloatDictionary *dict =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64FloatDictionary *dict2 =
+ [GPBUInt64FloatDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64FloatDictionary *dict = [GPBUInt64FloatDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setFloat:500.f forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const float kValues[] = { 501.f, 502.f, 503.f };
+ GPBUInt64FloatDictionary *dict2 =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:32ULL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:34ULL]);
+ XCTAssertEqual(value, 503.f);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt64FloatDictionary *dict =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeFloatForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:34ULL]);
+ XCTAssertEqual(value, 503.f);
+
+ // Remove again does nothing.
+ [dict removeFloatForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:34ULL]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict removeFloatForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertFalse([dict getFloat:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getFloat:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const float kValues[] = { 500.f, 501.f, 502.f, 503.f };
+ GPBUInt64FloatDictionary *dict =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ float value;
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:32ULL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:34ULL]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:503.f forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:32ULL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:34ULL]);
+ XCTAssertEqual(value, 503.f);
+
+ [dict setFloat:501.f forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:32ULL]);
+ XCTAssertEqual(value, 501.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:34ULL]);
+ XCTAssertEqual(value, 501.f);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const float kValues2[] = { 502.f, 500.f };
+ GPBUInt64FloatDictionary *dict2 =
+ [[GPBUInt64FloatDictionary alloc] initWithFloats:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getFloat:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:31ULL]);
+ XCTAssertEqual(value, 503.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:32ULL]);
+ XCTAssertEqual(value, 502.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:33ULL]);
+ XCTAssertEqual(value, 500.f);
+ XCTAssertTrue([dict getFloat:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getFloat:&value forKey:34ULL]);
+ XCTAssertEqual(value, 501.f);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> Double
+
+@interface GPBUInt64DoubleDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64DoubleDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64DoubleDictionary *dict = [[GPBUInt64DoubleDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:31ULL]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(uint64_t aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64DoubleDictionary *dict = [GPBUInt64DoubleDictionary dictionaryWithDouble:600. forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:32ULL]);
+ [dict enumerateKeysAndDoublesUsingBlock:^(uint64_t aKey, double aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqual(aValue, 600.);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const double kValues[] = { 600., 601., 602. };
+ GPBUInt64DoubleDictionary *dict =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:32ULL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ double *seenValues = malloc(3 * sizeof(double));
+ [dict enumerateKeysAndDoublesUsingBlock:^(uint64_t aKey, double aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndDoublesUsingBlock:^(uint64_t aKey, double aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const double kValues1[] = { 600., 601., 602. };
+ const double kValues2[] = { 600., 603., 602. };
+ const double kValues3[] = { 600., 601., 602., 603. };
+ GPBUInt64DoubleDictionary *dict1 =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64DoubleDictionary *dict1prime =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64DoubleDictionary *dict2 =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64DoubleDictionary *dict3 =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64DoubleDictionary *dict4 =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBUInt64DoubleDictionary *dict =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64DoubleDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64DoubleDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBUInt64DoubleDictionary *dict =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64DoubleDictionary *dict2 =
+ [GPBUInt64DoubleDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64DoubleDictionary *dict = [GPBUInt64DoubleDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setDouble:600. forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const double kValues[] = { 601., 602., 603. };
+ GPBUInt64DoubleDictionary *dict2 =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:32ULL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:34ULL]);
+ XCTAssertEqual(value, 603.);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBUInt64DoubleDictionary *dict =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeDoubleForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:34ULL]);
+ XCTAssertEqual(value, 603.);
+
+ // Remove again does nothing.
+ [dict removeDoubleForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:34ULL]);
+ XCTAssertEqual(value, 603.);
+
+ [dict removeDoubleForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertFalse([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertFalse([dict getDouble:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getDouble:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const double kValues[] = { 600., 601., 602., 603. };
+ GPBUInt64DoubleDictionary *dict =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ double value;
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:32ULL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:34ULL]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:603. forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:32ULL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:34ULL]);
+ XCTAssertEqual(value, 603.);
+
+ [dict setDouble:601. forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:32ULL]);
+ XCTAssertEqual(value, 601.);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:34ULL]);
+ XCTAssertEqual(value, 601.);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const double kValues2[] = { 602., 600. };
+ GPBUInt64DoubleDictionary *dict2 =
+ [[GPBUInt64DoubleDictionary alloc] initWithDoubles:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getDouble:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:31ULL]);
+ XCTAssertEqual(value, 603.);
+ XCTAssertTrue([dict getDouble:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:32ULL]);
+ XCTAssertEqual(value, 602.);
+ XCTAssertTrue([dict getDouble:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:33ULL]);
+ XCTAssertEqual(value, 600.);
+ XCTAssertTrue([dict getDouble:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getDouble:&value forKey:34ULL]);
+ XCTAssertEqual(value, 601.);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> Enum
+
+@interface GPBUInt64EnumDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64EnumDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64EnumDictionary *dict = [[GPBUInt64EnumDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:31ULL]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64EnumDictionary *dict = [GPBUInt64EnumDictionary dictionaryWithEnum:700 forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqual(aValue, 700);
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const int32_t kValues[] = { 700, 701, 702 };
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const int32_t kValues1[] = { 700, 701, 702 };
+ const int32_t kValues2[] = { 700, 703, 702 };
+ const int32_t kValues3[] = { 700, 701, 702, 703 };
+ GPBUInt64EnumDictionary *dict1 =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64EnumDictionary *dict1prime =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64EnumDictionary *dict2 =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64EnumDictionary *dict3 =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64EnumDictionary *dict4 =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64EnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64EnumDictionary *dict2 =
+ [GPBUInt64EnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64EnumDictionary *dict = [GPBUInt64EnumDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setEnum:700 forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 701, 702, 703 };
+ GPBUInt64EnumDictionary *dict2 =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 703);
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 703);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 703);
+
+ [dict removeEnumForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 701, 702, 703 };
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:703 forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 703);
+
+ [dict setEnum:701 forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, 701);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 701);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const int32_t kValues2[] = { 702, 700 };
+ GPBUInt64EnumDictionary *dict2 =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 703);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 701);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> Enum (Unknown Enums)
+
+@interface GPBUInt64EnumDictionaryUnknownEnumTests : XCTestCase
+@end
+
+@implementation GPBUInt64EnumDictionaryUnknownEnumTests
+
+- (void)testRawBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const int32_t kValues[] = { 700, 801, 702 };
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue(dict.validationFunc == TestingEnum_IsValidValue); // Pointer comparison
+ int32_t value;
+ XCTAssertTrue([dict getRawValue:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:32ULL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getRawValue:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getRawValue:NULL forKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ int32_t *seenValues = malloc(3 * sizeof(int32_t));
+ [dict enumerateKeysAndEnumsUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ if (i == 1) {
+ XCTAssertEqual(kGPBUnrecognizedEnumeratorValue, seenValues[j], @"i = %d, j = %d", i, j);
+ } else {
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenValues[idx] = aValue;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenValues);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndRawValuesUsingBlock:^(uint64_t aKey, int32_t aValue, BOOL *stop) {
+ #pragma unused(aKey, aValue)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEqualityWithUnknowns {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const int32_t kValues1[] = { 700, 801, 702 }; // Unknown
+ const int32_t kValues2[] = { 700, 803, 702 }; // Unknown
+ const int32_t kValues3[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBUInt64EnumDictionary *dict1 =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64EnumDictionary *dict1prime =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64EnumDictionary *dict2 =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64EnumDictionary *dict3 =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64EnumDictionary *dict4 =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kValues3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same values; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopyWithUnknowns {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknown
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertEqualObjects(dict, dict2);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64EnumDictionary *dict2 =
+ [GPBUInt64EnumDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ [dict release];
+}
+
+- (void)testUnknownAdds {
+ GPBUInt64EnumDictionary *dict =
+ [GPBUInt64EnumDictionary dictionaryWithValidationFunction:TestingEnum_IsValidValue];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertThrowsSpecificNamed([dict setEnum:801 forKey:32ULL], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 0U);
+ [dict setRawValue:801 forKey:32ULL]; // Unknown
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 31ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 702, 803 }; // Unknown
+ GPBUInt64EnumDictionary *dict2 =
+ [[GPBUInt64EnumDictionary alloc] initWithEnums:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:32ULL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, kGPBUnrecognizedEnumeratorValue);
+ XCTAssertTrue([dict getRawValue:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:34ULL]);
+ XCTAssertEqual(value, 803);
+ [dict2 release];
+}
+
+- (void)testUnknownRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeEnumForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:34ULL]);
+ XCTAssertEqual(value, 803);
+
+ // Remove again does nothing.
+ [dict removeEnumForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:34ULL]);
+ XCTAssertEqual(value, 803);
+
+ [dict removeEnumForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertFalse([dict getEnum:NULL forKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertFalse([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertFalse([dict getEnum:NULL forKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutationUnknowns {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 801, 702, 803 }; // Unknowns
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ int32_t value;
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:32ULL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:34ULL]);
+ XCTAssertEqual(value, 803);
+
+ XCTAssertThrowsSpecificNamed([dict setEnum:803 forKey:31ULL], // Unknown
+ NSException, NSInvalidArgumentException);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getEnum:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:31ULL]);
+ XCTAssertEqual(value, 700);
+ XCTAssertTrue([dict getRawValue:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:32ULL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:34ULL]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:803 forKey:31ULL]; // Unknown
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:31ULL]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:32ULL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:34ULL]);
+ XCTAssertEqual(value, 803);
+
+ [dict setRawValue:700 forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:31ULL]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getRawValue:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:32ULL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:33ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 700);
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const int32_t kValues2[] = { 702, 801 }; // Unknown
+ GPBUInt64EnumDictionary *dict2 =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kValues2)];
+ XCTAssertNotNil(dict2);
+ [dict addRawEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertTrue([dict getRawValue:NULL forKey:31ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:31ULL]);
+ XCTAssertEqual(value, 803);
+ XCTAssertTrue([dict getEnum:NULL forKey:32ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:32ULL]);
+ XCTAssertEqual(value, 702);
+ XCTAssertTrue([dict getRawValue:NULL forKey:33ULL]);
+ XCTAssertTrue([dict getRawValue:&value forKey:33ULL]);
+ XCTAssertEqual(value, 801);
+ XCTAssertTrue([dict getEnum:NULL forKey:34ULL]);
+ XCTAssertTrue([dict getEnum:&value forKey:34ULL]);
+ XCTAssertEqual(value, 700);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testCopyUnknowns {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const int32_t kValues[] = { 700, 801, 702, 803 };
+ GPBUInt64EnumDictionary *dict =
+ [[GPBUInt64EnumDictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+ rawValues:kValues
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kValues)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64EnumDictionary *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64EnumDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+#pragma mark - UInt64 -> Object
+
+@interface GPBUInt64ObjectDictionaryTests : XCTestCase
+@end
+
+@implementation GPBUInt64ObjectDictionaryTests
+
+- (void)testEmpty {
+ GPBUInt64ObjectDictionary<NSString*> *dict = [[GPBUInt64ObjectDictionary alloc] init];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:31ULL]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject, stop)
+ XCTFail(@"Shouldn't get here!");
+ }];
+ [dict release];
+}
+
+- (void)testOne {
+ GPBUInt64ObjectDictionary<NSString*> *dict = [GPBUInt64ObjectDictionary dictionaryWithObject:@"abc" forKey:31ULL];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 1U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"abc");
+ XCTAssertNil([dict objectForKey:32ULL]);
+ [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertEqual(aKey, 31ULL);
+ XCTAssertEqualObjects(aObject, @"abc");
+ XCTAssertNotEqual(stop, NULL);
+ }];
+}
+
+- (void)testBasics {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi" };
+ GPBUInt64ObjectDictionary<NSString*> *dict =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:32ULL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"ghi");
+ XCTAssertNil([dict objectForKey:34ULL]);
+
+ __block NSUInteger idx = 0;
+ uint64_t *seenKeys = malloc(3 * sizeof(uint64_t));
+ NSString* *seenObjects = malloc(3 * sizeof(NSString*));
+ [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, NSString* aObject, BOOL *stop) {
+ XCTAssertLessThan(idx, 3U);
+ seenKeys[idx] = aKey;
+ seenObjects[idx] = aObject;
+ XCTAssertNotEqual(stop, NULL);
+ ++idx;
+ }];
+ for (int i = 0; i < 3; ++i) {
+ BOOL foundKey = NO;
+ for (int j = 0; (j < 3) && !foundKey; ++j) {
+ if (kKeys[i] == seenKeys[j]) {
+ foundKey = YES;
+ XCTAssertEqualObjects(kObjects[i], seenObjects[j], @"i = %d, j = %d", i, j);
+ }
+ }
+ XCTAssertTrue(foundKey, @"i = %d", i);
+ }
+ free(seenKeys);
+ free(seenObjects);
+
+ // Stopping the enumeration.
+ idx = 0;
+ [dict enumerateKeysAndObjectsUsingBlock:^(uint64_t aKey, NSString* aObject, BOOL *stop) {
+ #pragma unused(aKey, aObject)
+ if (idx == 1) *stop = YES;
+ XCTAssertNotEqual(idx, 2U);
+ ++idx;
+ }];
+ [dict release];
+}
+
+- (void)testEquality {
+ const uint64_t kKeys1[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const uint64_t kKeys2[] = { 32ULL, 31ULL, 34ULL };
+ const NSString* kObjects1[] = { @"abc", @"def", @"ghi" };
+ const NSString* kObjects2[] = { @"abc", @"jkl", @"ghi" };
+ const NSString* kObjects3[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt64ObjectDictionary<NSString*> *dict1 =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1);
+ GPBUInt64ObjectDictionary<NSString*> *dict1prime =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict1prime);
+ GPBUInt64ObjectDictionary<NSString*> *dict2 =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ GPBUInt64ObjectDictionary<NSString*> *dict3 =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects1
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects1)];
+ XCTAssertNotNil(dict3);
+ GPBUInt64ObjectDictionary<NSString*> *dict4 =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects3
+ forKeys:kKeys1
+ count:GPBARRAYSIZE(kObjects3)];
+ XCTAssertNotNil(dict4);
+
+ // 1/1Prime should be different objects, but equal.
+ XCTAssertNotEqual(dict1, dict1prime);
+ XCTAssertEqualObjects(dict1, dict1prime);
+ // Equal, so they must have same hash.
+ XCTAssertEqual([dict1 hash], [dict1prime hash]);
+
+ // 2 is same keys, different objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict2);
+
+ // 3 is different keys, same objects; not equal.
+ XCTAssertNotEqualObjects(dict1, dict3);
+
+ // 4 extra pair; not equal
+ XCTAssertNotEqualObjects(dict1, dict4);
+
+ [dict1 release];
+ [dict1prime release];
+ [dict2 release];
+ [dict3 release];
+ [dict4 release];
+}
+
+- (void)testCopy {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt64ObjectDictionary<NSString*> *dict =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64ObjectDictionary<NSString*> *dict2 = [dict copy];
+ XCTAssertNotNil(dict2);
+
+ // Should be new object but equal.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ XCTAssertTrue([dict2 isKindOfClass:[GPBUInt64ObjectDictionary class]]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testDictionaryFromDictionary {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt64ObjectDictionary<NSString*> *dict =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+
+ GPBUInt64ObjectDictionary<NSString*> *dict2 =
+ [GPBUInt64ObjectDictionary dictionaryWithDictionary:dict];
+ XCTAssertNotNil(dict2);
+
+ // Should be new pointer, but equal objects.
+ XCTAssertNotEqual(dict, dict2);
+ XCTAssertEqualObjects(dict, dict2);
+ [dict release];
+}
+
+- (void)testAdds {
+ GPBUInt64ObjectDictionary<NSString*> *dict = [GPBUInt64ObjectDictionary dictionary];
+ XCTAssertNotNil(dict);
+
+ XCTAssertEqual(dict.count, 0U);
+ [dict setObject:@"abc" forKey:31ULL];
+ XCTAssertEqual(dict.count, 1U);
+
+ const uint64_t kKeys[] = { 32ULL, 33ULL, 34ULL };
+ const NSString* kObjects[] = { @"def", @"ghi", @"jkl" };
+ GPBUInt64ObjectDictionary<NSString*> *dict2 =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:32ULL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:34ULL], @"jkl");
+ [dict2 release];
+}
+
+- (void)testRemove {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt64ObjectDictionary<NSString*> *dict =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+
+ [dict removeObjectForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"abc");
+ XCTAssertNil([dict objectForKey:32ULL]);
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:34ULL], @"jkl");
+
+ // Remove again does nothing.
+ [dict removeObjectForKey:32ULL];
+ XCTAssertEqual(dict.count, 3U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"abc");
+ XCTAssertNil([dict objectForKey:32ULL]);
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:34ULL], @"jkl");
+
+ [dict removeObjectForKey:34ULL];
+ XCTAssertEqual(dict.count, 2U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"abc");
+ XCTAssertNil([dict objectForKey:32ULL]);
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"ghi");
+ XCTAssertNil([dict objectForKey:34ULL]);
+
+ [dict removeAll];
+ XCTAssertEqual(dict.count, 0U);
+ XCTAssertNil([dict objectForKey:31ULL]);
+ XCTAssertNil([dict objectForKey:32ULL]);
+ XCTAssertNil([dict objectForKey:33ULL]);
+ XCTAssertNil([dict objectForKey:34ULL]);
+ [dict release];
+}
+
+- (void)testInplaceMutation {
+ const uint64_t kKeys[] = { 31ULL, 32ULL, 33ULL, 34ULL };
+ const NSString* kObjects[] = { @"abc", @"def", @"ghi", @"jkl" };
+ GPBUInt64ObjectDictionary<NSString*> *dict =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects
+ forKeys:kKeys
+ count:GPBARRAYSIZE(kObjects)];
+ XCTAssertNotNil(dict);
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:32ULL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:34ULL], @"jkl");
+
+ [dict setObject:@"jkl" forKey:31ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:32ULL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:34ULL], @"jkl");
+
+ [dict setObject:@"def" forKey:34ULL];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:32ULL], @"def");
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:34ULL], @"def");
+
+ const uint64_t kKeys2[] = { 32ULL, 33ULL };
+ const NSString* kObjects2[] = { @"ghi", @"abc" };
+ GPBUInt64ObjectDictionary<NSString*> *dict2 =
+ [[GPBUInt64ObjectDictionary alloc] initWithObjects:kObjects2
+ forKeys:kKeys2
+ count:GPBARRAYSIZE(kObjects2)];
+ XCTAssertNotNil(dict2);
+ [dict addEntriesFromDictionary:dict2];
+ XCTAssertEqual(dict.count, 4U);
+ XCTAssertEqualObjects([dict objectForKey:31ULL], @"jkl");
+ XCTAssertEqualObjects([dict objectForKey:32ULL], @"ghi");
+ XCTAssertEqualObjects([dict objectForKey:33ULL], @"abc");
+ XCTAssertEqualObjects([dict objectForKey:34ULL], @"def");
+
+ [dict2 release];
+ [dict release];
+}
+
+@end
+
+//%PDDM-EXPAND-END TEST_FOR_POD_KEY(UInt64, uint64_t, 31ULL, 32ULL, 33ULL, 34ULL)
diff --git a/third_party/protobuf/objectivec/Tests/GPBDictionaryTests.m b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests.m
new file mode 100644
index 0000000000..52b4b32806
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests.m
@@ -0,0 +1,186 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2017 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <Foundation/Foundation.h>
+#import <XCTest/XCTest.h>
+
+#import "GPBDictionary.h"
+#import "GPBDictionary_PackagePrivate.h"
+
+#import "GPBTestUtilities.h"
+
+#pragma mark - GPBAutocreatedDictionary Tests
+
+// These are hand written tests to double check some behaviors of the
+// GPBAutocreatedDictionary. The GPBDictionary+[type]Tests files are generate
+// tests.
+
+// NOTE: GPBAutocreatedDictionary is private to the library, users of the
+// library should never have to directly deal with this class.
+
+@interface GPBAutocreatedDictionaryTests : XCTestCase
+@end
+
+@implementation GPBAutocreatedDictionaryTests
+
+- (void)testEquality {
+ GPBAutocreatedDictionary *dict = [[GPBAutocreatedDictionary alloc] init];
+
+ XCTAssertTrue([dict isEqual:@{}]);
+ XCTAssertTrue([dict isEqualToDictionary:@{}]);
+
+ XCTAssertFalse([dict isEqual:@{ @"foo" : @"bar" }]);
+ XCTAssertFalse([dict isEqualToDictionary:@{ @"foo" : @"bar" }]);
+
+ [dict setObject:@"bar" forKey:@"foo"];
+
+ XCTAssertFalse([dict isEqual:@{}]);
+ XCTAssertFalse([dict isEqualToDictionary:@{}]);
+ XCTAssertTrue([dict isEqual:@{ @"foo" : @"bar" }]);
+ XCTAssertTrue([dict isEqualToDictionary:@{ @"foo" : @"bar" }]);
+ XCTAssertFalse([dict isEqual:@{ @"bar" : @"baz" }]);
+ XCTAssertFalse([dict isEqualToDictionary:@{ @"bar" : @"baz" }]);
+
+ GPBAutocreatedDictionary *dict2 = [[GPBAutocreatedDictionary alloc] init];
+
+ XCTAssertFalse([dict isEqual:dict2]);
+ XCTAssertFalse([dict isEqualToDictionary:dict2]);
+
+ [dict2 setObject:@"mumble" forKey:@"foo"];
+ XCTAssertFalse([dict isEqual:dict2]);
+ XCTAssertFalse([dict isEqualToDictionary:dict2]);
+
+ [dict2 setObject:@"bar" forKey:@"foo"];
+ XCTAssertTrue([dict isEqual:dict2]);
+ XCTAssertTrue([dict isEqualToDictionary:dict2]);
+
+ [dict2 release];
+ [dict release];
+}
+
+- (void)testCopy {
+ {
+ GPBAutocreatedDictionary *dict = [[GPBAutocreatedDictionary alloc] init];
+
+ NSDictionary *cpy = [dict copy];
+ XCTAssertTrue(cpy != dict); // Ptr compare
+ XCTAssertTrue([cpy isKindOfClass:[NSDictionary class]]);
+ XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(cpy.count, (NSUInteger)0);
+
+ NSDictionary *cpy2 = [dict copy];
+ XCTAssertTrue(cpy2 != dict); // Ptr compare
+ XCTAssertTrue(cpy2 != cpy); // Ptr compare
+ XCTAssertTrue([cpy2 isKindOfClass:[NSDictionary class]]);
+ XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(cpy2.count, (NSUInteger)0);
+
+ [cpy2 release];
+ [cpy release];
+ [dict release];
+ }
+
+ {
+ GPBAutocreatedDictionary *dict = [[GPBAutocreatedDictionary alloc] init];
+
+ NSMutableDictionary *cpy = [dict mutableCopy];
+ XCTAssertTrue(cpy != dict); // Ptr compare
+ XCTAssertTrue([cpy isKindOfClass:[NSMutableDictionary class]]);
+ XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(cpy.count, (NSUInteger)0);
+
+ NSMutableDictionary *cpy2 = [dict mutableCopy];
+ XCTAssertTrue(cpy2 != dict); // Ptr compare
+ XCTAssertTrue(cpy2 != cpy); // Ptr compare
+ XCTAssertTrue([cpy2 isKindOfClass:[NSMutableDictionary class]]);
+ XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(cpy2.count, (NSUInteger)0);
+
+ [cpy2 release];
+ [cpy release];
+ [dict release];
+ }
+
+ {
+ GPBAutocreatedDictionary *dict = [[GPBAutocreatedDictionary alloc] init];
+ dict[@"foo"] = @"bar";
+ dict[@"baz"] = @"mumble";
+
+ NSDictionary *cpy = [dict copy];
+ XCTAssertTrue(cpy != dict); // Ptr compare
+ XCTAssertTrue([cpy isKindOfClass:[NSDictionary class]]);
+ XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(cpy.count, (NSUInteger)2);
+ XCTAssertEqualObjects(cpy[@"foo"], @"bar");
+ XCTAssertEqualObjects(cpy[@"baz"], @"mumble");
+
+ NSDictionary *cpy2 = [dict copy];
+ XCTAssertTrue(cpy2 != dict); // Ptr compare
+ XCTAssertTrue(cpy2 != cpy); // Ptr compare
+ XCTAssertTrue([cpy2 isKindOfClass:[NSDictionary class]]);
+ XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(cpy2.count, (NSUInteger)2);
+ XCTAssertEqualObjects(cpy2[@"foo"], @"bar");
+ XCTAssertEqualObjects(cpy2[@"baz"], @"mumble");
+
+ [cpy2 release];
+ [cpy release];
+ [dict release];
+ }
+
+ {
+ GPBAutocreatedDictionary *dict = [[GPBAutocreatedDictionary alloc] init];
+ dict[@"foo"] = @"bar";
+ dict[@"baz"] = @"mumble";
+
+ NSMutableDictionary *cpy = [dict mutableCopy];
+ XCTAssertTrue(cpy != dict); // Ptr compare
+ XCTAssertTrue([cpy isKindOfClass:[NSMutableDictionary class]]);
+ XCTAssertFalse([cpy isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(cpy.count, (NSUInteger)2);
+ XCTAssertEqualObjects(cpy[@"foo"], @"bar");
+ XCTAssertEqualObjects(cpy[@"baz"], @"mumble");
+
+ NSMutableDictionary *cpy2 = [dict mutableCopy];
+ XCTAssertTrue(cpy2 != dict); // Ptr compare
+ XCTAssertTrue(cpy2 != cpy); // Ptr compare
+ XCTAssertTrue([cpy2 isKindOfClass:[NSMutableDictionary class]]);
+ XCTAssertFalse([cpy2 isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(cpy2.count, (NSUInteger)2);
+ XCTAssertEqualObjects(cpy2[@"foo"], @"bar");
+ XCTAssertEqualObjects(cpy2[@"baz"], @"mumble");
+
+ [cpy2 release];
+ [cpy release];
+ [dict release];
+ }
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBDictionaryTests.pddm b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests.pddm
new file mode 100644
index 0000000000..d6aa721190
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBDictionaryTests.pddm
@@ -0,0 +1,1047 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 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.
+
+//%PDDM-DEFINE TEST_FOR_POD_KEY(KEY_NAME, KEY_TYPE, KEY1, KEY2, KEY3, KEY4)
+//%TESTS_FOR_POD_VALUES(KEY_NAME, KEY_TYPE, , , KEY1, KEY2, KEY3, KEY4)
+//%TESTS_FOR_POD_KEY_OBJECT_VALUE(KEY_NAME, KEY_TYPE, KEY1, KEY2, KEY3, KEY4, Object, NSString*, @"abc", @"def", @"ghi", @"jkl")
+
+//%PDDM-DEFINE TESTS_FOR_POD_VALUES(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4)
+//%TEST_HELPERS(KEY_NAME, KEY_TYPE, KisP)
+//%TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, UInt32, uint32_t, , 100U, 101U, 102U, 103U)
+//%TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, Int32, int32_t, , 200, 201, 202, 203)
+//%TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, UInt64, uint64_t, , 300U, 301U, 302U, 303U)
+//%TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, Int64, int64_t, , 400, 401, 402, 403)
+//%TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, Bool, BOOL, , YES, YES, NO, NO)
+//%TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, Float, float, , 500.f, 501.f, 502.f, 503.f)
+//%TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, Double, double, , 600., 601., 602., 603.)
+//%TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, Enum, int32_t, Raw, 700, 701, 702, 703)
+//%TESTS_FOR_ENUM_VALUE_RAW_ADDITIONS(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4)
+
+//%PDDM-DEFINE TESTS_FOR_POD_VALUE(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, VALUE_NAME, VALUE_TYPE, VACCESSOR, VAL1, VAL2, VAL3, VAL4)
+//%TESTS_COMMON(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, VALUE_NAME, VALUE_TYPE, , value, POD, VACCESSOR, VAL1, VAL2, VAL3, VAL4)
+
+//%PDDM-DEFINE TESTS_FOR_POD_KEY_OBJECT_VALUE(KEY_NAME, KEY_TYPE, KEY1, KEY2, KEY3, KEY4, VALUE_NAME, VALUE_TYPE, VAL1, VAL2, VAL3, VAL4)
+//%TESTS_COMMON(KEY_NAME, KEY_TYPE, , , KEY1, KEY2, KEY3, KEY4, VALUE_NAME, VALUE_TYPE, Objects, object, OBJECT, , VAL1, VAL2, VAL3, VAL4)
+
+//%PDDM-DEFINE DICTIONARY_CLASS_DECLPOD(KEY_NAME, VALUE_NAME, VALUE_TYPE)
+//%GPB##KEY_NAME##VALUE_NAME##Dictionary
+//%PDDM-DEFINE DICTIONARY_CLASS_DECLEnum(KEY_NAME, VALUE_NAME, VALUE_TYPE)
+//%GPB##KEY_NAME##VALUE_NAME##Dictionary
+//%PDDM-DEFINE DICTIONARY_CLASS_DECLOBJECT(KEY_NAME, VALUE_NAME, VALUE_TYPE)
+//%GPB##KEY_NAME##VALUE_NAME##Dictionary<VALUE_TYPE>
+
+//%PDDM-DEFINE TESTS_COMMON(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, VALUE_NAME, VALUE_TYPE, VSUFFIX, VNAME, VHELPER, VACCESSOR, VAL1, VAL2, VAL3, VAL4)
+//%#pragma mark - KEY_NAME -> VALUE_NAME
+//%
+//%@interface GPB##KEY_NAME##VALUE_NAME##DictionaryTests : XCTestCase
+//%@end
+//%
+//%@implementation GPB##KEY_NAME##VALUE_NAME##DictionaryTests
+//%
+//%- (void)testEmpty {
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 0U);
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY1)
+//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u, BOOL *stop) {
+//% #pragma unused(aKey, a##VNAME$u, stop)
+//% XCTFail(@"Shouldn't get here!");
+//% }];
+//% [dict release];
+//%}
+//%
+//%- (void)testOne {
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWith##VALUE_NAME$u##:VAL1 forKey:KEY1];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 1U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u, BOOL *stop) {
+//% XCTAssertEqual##KSUFFIX(aKey, KEY1);
+//% XCTAssertEqual##VSUFFIX(a##VNAME$u, VAL1);
+//% XCTAssertNotEqual(stop, NULL);
+//% }];
+//%}
+//%
+//%- (void)testBasics {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2, VAL3 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME$u##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 3U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL3)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY4)
+//%
+//% __block NSUInteger idx = 0;
+//% KEY_TYPE KisP##*seenKeys = malloc(3 * sizeof(KEY_TYPE##KisP));
+//% VALUE_TYPE *seen##VNAME$u##s = malloc(3 * sizeof(VALUE_TYPE));
+//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u, BOOL *stop) {
+//% XCTAssertLessThan(idx, 3U);
+//% seenKeys[idx] = aKey;
+//% seen##VNAME$u##s[idx] = a##VNAME$u##;
+//% XCTAssertNotEqual(stop, NULL);
+//% ++idx;
+//% }];
+//% for (int i = 0; i < 3; ++i) {
+//% BOOL foundKey = NO;
+//% for (int j = 0; (j < 3) && !foundKey; ++j) {
+//% if (COMPARE_KEYS##KSUFFIX(kKeys[i], seenKeys[j])) {
+//% foundKey = YES;
+//% XCTAssertEqual##VSUFFIX(k##VNAME$u##s[i], seen##VNAME$u##s[j], @"i = %d, j = %d", i, j);
+//% }
+//% }
+//% XCTAssertTrue(foundKey, @"i = %d", i);
+//% }
+//% free(seenKeys);
+//% free(seen##VNAME$u##s);
+//%
+//% // Stopping the enumeration.
+//% idx = 0;
+//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u, BOOL *stop) {
+//% #pragma unused(aKey, a##VNAME$u)
+//% if (idx == 1) *stop = YES;
+//% XCTAssertNotEqual(idx, 2U);
+//% ++idx;
+//% }];
+//% [dict release];
+//%}
+//%
+//%- (void)testEquality {
+//% const KEY_TYPE KisP##kKeys1[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const KEY_TYPE KisP##kKeys2[] = { KEY2, KEY1, KEY4 };
+//% const VALUE_TYPE k##VNAME$u##s1[] = { VAL1, VAL2, VAL3 };
+//% const VALUE_TYPE k##VNAME$u##s2[] = { VAL1, VAL4, VAL3 };
+//% const VALUE_TYPE k##VNAME$u##s3[] = { VAL1, VAL2, VAL3, VAL4 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)];
+//% XCTAssertNotNil(dict1);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1prime =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)];
+//% XCTAssertNotNil(dict1prime);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s2
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s2)];
+//% XCTAssertNotNil(dict2);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict3 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys2
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)];
+//% XCTAssertNotNil(dict3);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict4 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s3
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s3)];
+//% XCTAssertNotNil(dict4);
+//%
+//% // 1/1Prime should be different objects, but equal.
+//% XCTAssertNotEqual(dict1, dict1prime);
+//% XCTAssertEqualObjects(dict1, dict1prime);
+//% // Equal, so they must have same hash.
+//% XCTAssertEqual([dict1 hash], [dict1prime hash]);
+//%
+//% // 2 is same keys, different ##VNAME##s; not equal.
+//% XCTAssertNotEqualObjects(dict1, dict2);
+//%
+//% // 3 is different keys, same ##VNAME##s; not equal.
+//% XCTAssertNotEqualObjects(dict1, dict3);
+//%
+//% // 4 extra pair; not equal
+//% XCTAssertNotEqualObjects(dict1, dict4);
+//%
+//% [dict1 release];
+//% [dict1prime release];
+//% [dict2 release];
+//% [dict3 release];
+//% [dict4 release];
+//%}
+//%
+//%- (void)testCopy {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2, VAL3, VAL4 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//%
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = [dict copy];
+//% XCTAssertNotNil(dict2);
+//%
+//% // Should be new object but equal.
+//% XCTAssertNotEqual(dict, dict2);
+//% XCTAssertEqualObjects(dict, dict2);
+//% XCTAssertTrue([dict2 isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]);
+//%
+//% [dict2 release];
+//% [dict release];
+//%}
+//%
+//%- (void)testDictionaryFromDictionary {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2, VAL3, VAL4 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//%
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWithDictionary:dict];
+//% XCTAssertNotNil(dict2);
+//%
+//% // Should be new pointer, but equal objects.
+//% XCTAssertNotEqual(dict, dict2);
+//% XCTAssertEqualObjects(dict, dict2);
+//% [dict release];
+//%}
+//%
+//%- (void)testAdds {
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionary];
+//% XCTAssertNotNil(dict);
+//%
+//% XCTAssertEqual(dict.count, 0U);
+//% [dict set##VALUE_NAME##:VAL1 forKey:KEY1];
+//% XCTAssertEqual(dict.count, 1U);
+//%
+//% const KEY_TYPE KisP##kKeys[] = { KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL2, VAL3, VAL4 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict2);
+//% [dict add##VACCESSOR##EntriesFromDictionary:dict2];
+//% XCTAssertEqual(dict.count, 4U);
+//%
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY4, VAL4)
+//% [dict2 release];
+//%}
+//%
+//%- (void)testRemove {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2, VAL3, VAL4 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 4U);
+//%
+//% [dict remove##VALUE_NAME##ForKey:KEY2];
+//% XCTAssertEqual(dict.count, 3U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY4, VAL4)
+//%
+//% // Remove again does nothing.
+//% [dict remove##VALUE_NAME##ForKey:KEY2];
+//% XCTAssertEqual(dict.count, 3U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY4, VAL4)
+//%
+//% [dict remove##VALUE_NAME##ForKey:KEY4];
+//% XCTAssertEqual(dict.count, 2U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL3)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY4)
+//%
+//% [dict removeAll];
+//% XCTAssertEqual(dict.count, 0U);
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY3)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY4)
+//% [dict release];
+//%}
+//%
+//%- (void)testInplaceMutation {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2, VAL3, VAL4 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 4U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY4, VAL4)
+//%
+//% [dict set##VALUE_NAME##:VAL4 forKey:KEY1];
+//% XCTAssertEqual(dict.count, 4U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL4)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY4, VAL4)
+//%
+//% [dict set##VALUE_NAME##:VAL2 forKey:KEY4];
+//% XCTAssertEqual(dict.count, 4U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL4)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY4, VAL2)
+//%
+//% const KEY_TYPE KisP##kKeys2[] = { KEY2, KEY3 };
+//% const VALUE_TYPE k##VNAME$u##s2[] = { VAL3, VAL1 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s2
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys2
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s2)];
+//% XCTAssertNotNil(dict2);
+//% [dict add##VACCESSOR##EntriesFromDictionary:dict2];
+//% XCTAssertEqual(dict.count, 4U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL4)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY3, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY4, VAL2)
+//%
+//% [dict2 release];
+//% [dict release];
+//%}
+//%
+//%@end
+//%
+
+//%PDDM-DEFINE TESTS_FOR_ENUM_VALUE_RAW_ADDITIONS(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4)
+//%TESTS_FOR_ENUM_VALUE_RAW_ADDITIONS2(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, Enum, int32_t, , POD, 700, 801, 702, 803)
+//%PDDM-DEFINE TESTS_FOR_ENUM_VALUE_RAW_ADDITIONS2(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, KEY3, KEY4, VALUE_NAME, VALUE_TYPE, VSUFFIX, VHELPER, VAL1, VAL2, VAL3, VAL4)
+//%#pragma mark - KEY_NAME -> VALUE_NAME (Unknown Enums)
+//%
+//%@interface GPB##KEY_NAME##VALUE_NAME##DictionaryUnknownEnumTests : XCTestCase
+//%@end
+//%
+//%@implementation GPB##KEY_NAME##VALUE_NAME##DictionaryUnknownEnumTests
+//%
+//%- (void)testRawBasics {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3 };
+//% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 3U);
+//% XCTAssertTrue(dict.validationFunc == TestingEnum_IsValidValue); // Pointer comparison
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, value)TEST_RAW_VALUE##VHELPER(dict, value, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY2, kGPBUnrecognizedEnumeratorValue)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY2, VAL2)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY3, VAL3)
+//%RAW_VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY4)
+//%
+//% __block NSUInteger idx = 0;
+//% KEY_TYPE KisP##*seenKeys = malloc(3 * sizeof(KEY_TYPE##KisP));
+//% VALUE_TYPE *seenValues = malloc(3 * sizeof(VALUE_TYPE));
+//% [dict enumerateKeysAndEnumsUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE aValue, BOOL *stop) {
+//% XCTAssertLessThan(idx, 3U);
+//% seenKeys[idx] = aKey;
+//% seenValues[idx] = aValue;
+//% XCTAssertNotEqual(stop, NULL);
+//% ++idx;
+//% }];
+//% for (int i = 0; i < 3; ++i) {
+//% BOOL foundKey = NO;
+//% for (int j = 0; (j < 3) && !foundKey; ++j) {
+//% if (COMPARE_KEYS##KSUFFIX(kKeys[i], seenKeys[j])) {
+//% foundKey = YES;
+//% if (i == 1) {
+//% XCTAssertEqual##VSUFFIX(kGPBUnrecognizedEnumeratorValue, seenValues[j], @"i = %d, j = %d", i, j);
+//% } else {
+//% XCTAssertEqual##VSUFFIX(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+//% }
+//% }
+//% }
+//% XCTAssertTrue(foundKey, @"i = %d", i);
+//% }
+//% idx = 0;
+//% [dict enumerateKeysAndRawValuesUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE aValue, BOOL *stop) {
+//% XCTAssertLessThan(idx, 3U);
+//% seenKeys[idx] = aKey;
+//% seenValues[idx] = aValue;
+//% XCTAssertNotEqual(stop, NULL);
+//% ++idx;
+//% }];
+//% for (int i = 0; i < 3; ++i) {
+//% BOOL foundKey = NO;
+//% for (int j = 0; (j < 3) && !foundKey; ++j) {
+//% if (COMPARE_KEYS##KSUFFIX(kKeys[i], seenKeys[j])) {
+//% foundKey = YES;
+//% XCTAssertEqual##VSUFFIX(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
+//% }
+//% }
+//% XCTAssertTrue(foundKey, @"i = %d", i);
+//% }
+//% free(seenKeys);
+//% free(seenValues);
+//%
+//% // Stopping the enumeration.
+//% idx = 0;
+//% [dict enumerateKeysAndRawValuesUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE aValue, BOOL *stop) {
+//% #pragma unused(aKey, aValue)
+//% if (idx == 1) *stop = YES;
+//% XCTAssertNotEqual(idx, 2U);
+//% ++idx;
+//% }];
+//% [dict release];
+//%}
+//%
+//%- (void)testEqualityWithUnknowns {
+//% const KEY_TYPE KisP##kKeys1[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const KEY_TYPE KisP##kKeys2[] = { KEY2, KEY1, KEY4 };
+//% const VALUE_TYPE kValues1[] = { VAL1, VAL2, VAL3 }; // Unknown
+//% const VALUE_TYPE kValues2[] = { VAL1, VAL4, VAL3 }; // Unknown
+//% const VALUE_TYPE kValues3[] = { VAL1, VAL2, VAL3, VAL4 }; // Unknowns
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues1
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues1)];
+//% XCTAssertNotNil(dict1);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1prime =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues1
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues1)];
+//% XCTAssertNotNil(dict1prime);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues2
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues2)];
+//% XCTAssertNotNil(dict2);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict3 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues1
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys2
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues1)];
+//% XCTAssertNotNil(dict3);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict4 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues3
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues3)];
+//% XCTAssertNotNil(dict4);
+//%
+//% // 1/1Prime should be different objects, but equal.
+//% XCTAssertNotEqual(dict1, dict1prime);
+//% XCTAssertEqualObjects(dict1, dict1prime);
+//% // Equal, so they must have same hash.
+//% XCTAssertEqual([dict1 hash], [dict1prime hash]);
+//%
+//% // 2 is same keys, different values; not equal.
+//% XCTAssertNotEqualObjects(dict1, dict2);
+//%
+//% // 3 is different keys, same values; not equal.
+//% XCTAssertNotEqualObjects(dict1, dict3);
+//%
+//% // 4 extra pair; not equal
+//% XCTAssertNotEqualObjects(dict1, dict4);
+//%
+//% [dict1 release];
+//% [dict1prime release];
+//% [dict2 release];
+//% [dict3 release];
+//% [dict4 release];
+//%}
+//%
+//%- (void)testCopyWithUnknowns {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 }; // Unknown
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(dict);
+//%
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = [dict copy];
+//% XCTAssertNotNil(dict2);
+//%
+//% // Should be new pointer, but equal objects.
+//% XCTAssertNotEqual(dict, dict2);
+//% XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+//% XCTAssertEqualObjects(dict, dict2);
+//%
+//% [dict2 release];
+//% [dict release];
+//%}
+//%
+//%- (void)testDictionaryFromDictionary {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 }; // Unknowns
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(dict);
+//%
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWithDictionary:dict];
+//% XCTAssertNotNil(dict2);
+//%
+//% // Should be new pointer, but equal objects.
+//% XCTAssertNotEqual(dict, dict2);
+//% XCTAssertEqualObjects(dict, dict2);
+//% XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+//% [dict release];
+//%}
+//%
+//%- (void)testUnknownAdds {
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWithValidationFunction:TestingEnum_IsValidValue];
+//% XCTAssertNotNil(dict);
+//%
+//% XCTAssertEqual(dict.count, 0U);
+//% XCTAssertThrowsSpecificNamed([dict setEnum:VAL2 forKey:KEY2], // Unknown
+//% NSException, NSInvalidArgumentException);
+//% XCTAssertEqual(dict.count, 0U);
+//% [dict setRawValue:VAL2 forKey:KEY2]; // Unknown
+//% XCTAssertEqual(dict.count, 1U);
+//%
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY3, KEY4 };
+//% const VALUE_TYPE kValues[] = { VAL1, VAL3, VAL4 }; // Unknown
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithEnums:kValues
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(dict2);
+//% [dict addRawEntriesFromDictionary:dict2];
+//% XCTAssertEqual(dict.count, 4U);
+//%
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, value)TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY2, kGPBUnrecognizedEnumeratorValue)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY3, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY4, kGPBUnrecognizedEnumeratorValue)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY4, VAL4)
+//% [dict2 release];
+//%}
+//%
+//%- (void)testUnknownRemove {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 }; // Unknowns
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 4U);
+//%
+//% [dict removeEnumForKey:KEY2];
+//% XCTAssertEqual(dict.count, 3U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, value)TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY3, VAL3)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY4, VAL4)
+//%
+//% // Remove again does nothing.
+//% [dict removeEnumForKey:KEY2];
+//% XCTAssertEqual(dict.count, 3U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY3, VAL3)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY4, VAL4)
+//%
+//% [dict removeEnumForKey:KEY4];
+//% XCTAssertEqual(dict.count, 2U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY3, VAL3)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY4)
+//%
+//% [dict removeAll];
+//% XCTAssertEqual(dict.count, 0U);
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY3)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY4)
+//% [dict release];
+//%}
+//%
+//%- (void)testInplaceMutationUnknowns {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 }; // Unknowns
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 4U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, value)TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY1, VAL1)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY3, VAL3)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY4, VAL4)
+//%
+//% XCTAssertThrowsSpecificNamed([dict setEnum:VAL4 forKey:KEY1], // Unknown
+//% NSException, NSInvalidArgumentException);
+//% XCTAssertEqual(dict.count, 4U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY1, VAL1)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY3, VAL3)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY4, VAL4)
+//%
+//% [dict setRawValue:VAL4 forKey:KEY1]; // Unknown
+//% XCTAssertEqual(dict.count, 4U);
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY1, VAL4)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY3, VAL3)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY4, VAL4)
+//%
+//% [dict setRawValue:VAL1 forKey:KEY4];
+//% XCTAssertEqual(dict.count, 4U);
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY1, VAL4)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY2, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY3, VAL3)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY4, VAL1)
+//%
+//% const KEY_TYPE KisP##kKeys2[] = { KEY2, KEY3 };
+//% const VALUE_TYPE kValues2[] = { VAL3, VAL2 }; // Unknown
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues2
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys2
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues2)];
+//% XCTAssertNotNil(dict2);
+//% [dict addRawEntriesFromDictionary:dict2];
+//% XCTAssertEqual(dict.count, 4U);
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY1, VAL4)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY2, VAL3)
+//%TEST_RAW_VALUE##VHELPER(dict, value, KEY3, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, value, KEY4, VAL1)
+//%
+//% [dict2 release];
+//% [dict release];
+//%}
+//%
+//%- (void)testCopyUnknowns {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2, KEY3, KEY4 };
+//% const VALUE_TYPE kValues[] = { VAL1, VAL2, VAL3, VAL4 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S VALUE_NAME$S rawValues:kValues
+//% KEY_NAME$S VALUE_NAME$S forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S count:GPBARRAYSIZE(kValues)];
+//% XCTAssertNotNil(dict);
+//%
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = [dict copy];
+//% XCTAssertNotNil(dict2);
+//%
+//% // Should be new pointer, but equal objects.
+//% XCTAssertNotEqual(dict, dict2);
+//% XCTAssertEqualObjects(dict, dict2);
+//% XCTAssertEqual(dict.validationFunc, dict2.validationFunc); // Pointer comparison
+//% XCTAssertTrue([dict2 isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]);
+//%
+//% [dict2 release];
+//% [dict release];
+//%}
+//%
+//%@end
+//%
+
+//
+// Helpers for PODs
+//
+
+//%PDDM-DEFINE DECLARE_VALUE_STORAGEPOD(VALUE_TYPE, NAME)
+//% VALUE_TYPE NAME;
+//%
+//%PDDM-DEFINE VALUE_NOT_FOUNDPOD(VALUE_NAME, DICT, KEY)
+//% XCTAssertFalse([DICT get##VALUE_NAME##:NULL forKey:KEY]);
+//%PDDM-DEFINE TEST_VALUEPOD(VALUE_NAME, DICT, STORAGE, KEY, VALUE)
+//% XCTAssertTrue([DICT get##VALUE_NAME##:NULL forKey:KEY]);
+//% XCTAssertTrue([DICT get##VALUE_NAME##:&STORAGE forKey:KEY]);
+//% XCTAssertEqual(STORAGE, VALUE);
+//%PDDM-DEFINE COMPARE_KEYS(KEY1, KEY2)
+//%KEY1 == KEY2
+//%PDDM-DEFINE RAW_VALUE_NOT_FOUNDPOD(VALUE_NAME, DICT, KEY)
+//% XCTAssertFalse([DICT getRawValue:NULL forKey:KEY]);
+//%PDDM-DEFINE TEST_RAW_VALUEPOD(DICT, STORAGE, KEY, VALUE)
+//% XCTAssertTrue([DICT getRawValue:NULL forKey:KEY]);
+//% XCTAssertTrue([DICT getRawValue:&STORAGE forKey:KEY]);
+//% XCTAssertEqual(STORAGE, VALUE);
+
+//
+// Helpers for Objects
+//
+
+//%PDDM-DEFINE DECLARE_VALUE_STORAGEOBJECT(VALUE_TYPE, NAME)
+// Empty
+//%PDDM-DEFINE VALUE_NOT_FOUNDOBJECT(VALUE_NAME, DICT, KEY)
+//% XCTAssertNil([DICT objectForKey:KEY]);
+//%PDDM-DEFINE TEST_VALUEOBJECT(VALUE_NAME, DICT, STORAGE, KEY, VALUE)
+//% XCTAssertEqualObjects([DICT objectForKey:KEY], VALUE);
+//%PDDM-DEFINE COMPARE_KEYSObjects(KEY1, KEY2)
+//%[KEY1 isEqual:KEY2]
+
+//
+// Helpers for tests.
+//
+
+//%PDDM-DEFINE TEST_HELPERS(KEY_NAME, KEY_TYPE, KisP)
+//%// To let the testing macros work, add some extra methods to simplify things.
+//%@interface GPB##KEY_NAME##EnumDictionary (TestingTweak)
+//%+ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(KEY_TYPE##KisP$S##KisP)key;
+//%- (instancetype)initWithEnums:(const int32_t [])values
+//% forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
+//% count:(NSUInteger)count;
+//%@end
+//%
+//%static BOOL TestingEnum_IsValidValue(int32_t value) {
+//% switch (value) {
+//% case 700:
+//% case 701:
+//% case 702:
+//% case 703:
+//% return YES;
+//% default:
+//% return NO;
+//% }
+//%}
+//%
+//%@implementation GPB##KEY_NAME##EnumDictionary (TestingTweak)
+//%+ (instancetype)dictionaryWithEnum:(int32_t)value forKey:(KEY_TYPE##KisP$S##KisP)key {
+//% // Cast is needed to compiler knows what class we are invoking initWithValues: on to get the
+//% // type correct.
+//% return [[(GPB##KEY_NAME##EnumDictionary*)[self alloc] initWithValidationFunction:TestingEnum_IsValidValue
+//% KEY_NAME$S rawValues:&value
+//% KEY_NAME$S forKeys:&key
+//% KEY_NAME$S count:1] autorelease];
+//%}
+//%- (instancetype)initWithEnums:(const int32_t [])values
+//% forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
+//% count:(NSUInteger)count {
+//% return [self initWithValidationFunction:TestingEnum_IsValidValue
+//% rawValues:values
+//% forKeys:keys
+//% count:count];
+//%}
+//%@end
+//%
+//%
+
+
+//
+// BOOL test macros
+//
+//TODO(thomasvl): enum tests
+
+//%PDDM-DEFINE BOOL_TESTS_FOR_POD_VALUE(VALUE_NAME, VALUE_TYPE, VAL1, VAL2)
+//%BOOL_TESTS_COMMON(Bool, BOOL, , , YES, NO, VALUE_NAME, VALUE_TYPE, , value, POD, VAL1, VAL2)
+
+//%PDDM-DEFINE TESTS_FOR_BOOL_KEY_OBJECT_VALUE(VALUE_NAME, VALUE_TYPE, VAL1, VAL2)
+//%BOOL_TESTS_COMMON(Bool, BOOL, , , YES, NO, VALUE_NAME, VALUE_TYPE, Objects, object, OBJECT, VAL1, VAL2)
+
+//%PDDM-DEFINE BOOL_TESTS_COMMON(KEY_NAME, KEY_TYPE, KisP, KSUFFIX, KEY1, KEY2, VALUE_NAME, VALUE_TYPE, VSUFFIX, VNAME, VHELPER, VAL1, VAL2)
+//%#pragma mark - KEY_NAME -> VALUE_NAME
+//%
+//%@interface GPB##KEY_NAME##VALUE_NAME##DictionaryTests : XCTestCase
+//%@end
+//%
+//%@implementation GPB##KEY_NAME##VALUE_NAME##DictionaryTests
+//%
+//%- (void)testEmpty {
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 0U);
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY1)
+//% [dict enumerateKeysAnd##VALUE_NAME##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u##, BOOL *stop) {
+//% #pragma unused(aKey, a##VNAME$u##, stop)
+//% XCTFail(@"Shouldn't get here!");
+//% }];
+//% [dict release];
+//%}
+//%
+//%- (void)testOne {
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWith##VALUE_NAME$u##:VAL1 forKey:KEY1];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 1U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u, BOOL *stop) {
+//% XCTAssertEqual##KSUFFIX(aKey, KEY1);
+//% XCTAssertEqual##VSUFFIX(a##VNAME$u, VAL1);
+//% XCTAssertNotEqual(stop, NULL);
+//% }];
+//%}
+//%
+//%- (void)testBasics {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 2U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%
+//% __block NSUInteger idx = 0;
+//% KEY_TYPE KisP##*seenKeys = malloc(2 * sizeof(KEY_TYPE##KisP));
+//% VALUE_TYPE *seen##VNAME$u##s = malloc(2 * sizeof(VALUE_TYPE));
+//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u##, BOOL *stop) {
+//% XCTAssertLessThan(idx, 2U);
+//% seenKeys[idx] = aKey;
+//% seen##VNAME$u##s[idx] = a##VNAME$u;
+//% XCTAssertNotEqual(stop, NULL);
+//% ++idx;
+//% }];
+//% for (int i = 0; i < 2; ++i) {
+//% BOOL foundKey = NO;
+//% for (int j = 0; (j < 2) && !foundKey; ++j) {
+//% if (COMPARE_KEYS##KSUFFIX(kKeys[i], seenKeys[j])) {
+//% foundKey = YES;
+//% XCTAssertEqual##VSUFFIX(k##VNAME$u##s[i], seen##VNAME$u##s[j], @"i = %d, j = %d", i, j);
+//% }
+//% }
+//% XCTAssertTrue(foundKey, @"i = %d", i);
+//% }
+//% free(seenKeys);
+//% free(seen##VNAME$u##s);
+//%
+//% // Stopping the enumeration.
+//% idx = 0;
+//% [dict enumerateKeysAnd##VALUE_NAME$u##sUsingBlock:^(KEY_TYPE KisP##aKey, VALUE_TYPE a##VNAME$u##, BOOL *stop) {
+//% #pragma unused(aKey, a##VNAME$u)
+//% if (idx == 0) *stop = YES;
+//% XCTAssertNotEqual(idx, 2U);
+//% ++idx;
+//% }];
+//% [dict release];
+//%}
+//%
+//%- (void)testEquality {
+//% const KEY_TYPE KisP##kKeys1[] = { KEY1, KEY2 };
+//% const KEY_TYPE KisP##kKeys2[] = { KEY2, KEY1 };
+//% const VALUE_TYPE k##VNAME$u##s1[] = { VAL1, VAL2 };
+//% const VALUE_TYPE k##VNAME$u##s2[] = { VAL2, VAL1 };
+//% const VALUE_TYPE k##VNAME$u##s3[] = { VAL2 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)];
+//% XCTAssertNotNil(dict1);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict1prime =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)];
+//% XCTAssertNotNil(dict1prime);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s2
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s2)];
+//% XCTAssertNotNil(dict2);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict3 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys2
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s1)];
+//% XCTAssertNotNil(dict3);
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict4 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s3
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys1
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s3)];
+//% XCTAssertNotNil(dict4);
+//%
+//% // 1/1Prime should be different objects, but equal.
+//% XCTAssertNotEqual(dict1, dict1prime);
+//% XCTAssertEqualObjects(dict1, dict1prime);
+//% // Equal, so they must have same hash.
+//% XCTAssertEqual([dict1 hash], [dict1prime hash]);
+//%
+//% // 2 is same keys, different ##VNAME##s; not equal.
+//% XCTAssertNotEqualObjects(dict1, dict2);
+//%
+//% // 3 is different keys, same ##VNAME##s; not equal.
+//% XCTAssertNotEqualObjects(dict1, dict3);
+//%
+//% // 4 Fewer pairs; not equal
+//% XCTAssertNotEqualObjects(dict1, dict4);
+//%
+//% [dict1 release];
+//% [dict1prime release];
+//% [dict2 release];
+//% [dict3 release];
+//% [dict4 release];
+//%}
+//%
+//%- (void)testCopy {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//%
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 = [dict copy];
+//% XCTAssertNotNil(dict2);
+//%
+//% // Should be new object but equal.
+//% XCTAssertNotEqual(dict, dict2);
+//% XCTAssertEqualObjects(dict, dict2);
+//% XCTAssertTrue([dict2 isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]);
+//%
+//% [dict2 release];
+//% [dict release];
+//%}
+//%
+//%- (void)testDictionaryFromDictionary {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//%
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionaryWithDictionary:dict];
+//% XCTAssertNotNil(dict2);
+//%
+//% // Should be new pointer, but equal objects.
+//% XCTAssertNotEqual(dict, dict2);
+//% XCTAssertEqualObjects(dict, dict2);
+//% [dict release];
+//%}
+//%
+//%- (void)testAdds {
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict = [GPB##KEY_NAME##VALUE_NAME##Dictionary dictionary];
+//% XCTAssertNotNil(dict);
+//%
+//% XCTAssertEqual(dict.count, 0U);
+//% [dict set##VALUE_NAME:VAL1 forKey:KEY1];
+//% XCTAssertEqual(dict.count, 1U);
+//%
+//% const KEY_TYPE KisP##kKeys[] = { KEY2 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL2 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict2);
+//% [dict addEntriesFromDictionary:dict2];
+//% XCTAssertEqual(dict.count, 2U);
+//%
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//% [dict2 release];
+//%}
+//%
+//%- (void)testRemove {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2};
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 2U);
+//%
+//% [dict remove##VALUE_NAME##ForKey:KEY2];
+//% XCTAssertEqual(dict.count, 1U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%
+//% // Remove again does nothing.
+//% [dict remove##VALUE_NAME##ForKey:KEY2];
+//% XCTAssertEqual(dict.count, 1U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//%
+//% [dict removeAll];
+//% XCTAssertEqual(dict.count, 0U);
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY1)
+//%VALUE_NOT_FOUND##VHELPER(VALUE_NAME, dict, KEY2)
+//% [dict release];
+//%}
+//%
+//%- (void)testInplaceMutation {
+//% const KEY_TYPE KisP##kKeys[] = { KEY1, KEY2 };
+//% const VALUE_TYPE k##VNAME$u##s[] = { VAL1, VAL2 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s)];
+//% XCTAssertNotNil(dict);
+//% XCTAssertEqual(dict.count, 2U);
+//%DECLARE_VALUE_STORAGE##VHELPER(VALUE_TYPE, VNAME)TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%
+//% [dict set##VALUE_NAME##:VAL2 forKey:KEY1];
+//% XCTAssertEqual(dict.count, 2U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%
+//% [dict set##VALUE_NAME##:VAL1 forKey:KEY2];
+//% XCTAssertEqual(dict.count, 2U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL2)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL1)
+//%
+//% const KEY_TYPE KisP##kKeys2[] = { KEY2, KEY1 };
+//% const VALUE_TYPE k##VNAME$u##s2[] = { VAL2, VAL1 };
+//% DICTIONARY_CLASS_DECL##VHELPER(KEY_NAME, VALUE_NAME, VALUE_TYPE) *dict2 =
+//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] initWith##VALUE_NAME##s:k##VNAME$u##s2
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## forKeys:kKeys2
+//% KEY_NAME$S VALUE_NAME$S ##VALUE_NAME$S## count:GPBARRAYSIZE(k##VNAME$u##s2)];
+//% XCTAssertNotNil(dict2);
+//% [dict addEntriesFromDictionary:dict2];
+//% XCTAssertEqual(dict.count, 2U);
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY1, VAL1)
+//%TEST_VALUE##VHELPER(VALUE_NAME, dict, VNAME, KEY2, VAL2)
+//%
+//% [dict2 release];
+//% [dict release];
+//%}
+//%
+//%@end
+//%
+
diff --git a/third_party/protobuf/objectivec/Tests/GPBMessageTests+Merge.m b/third_party/protobuf/objectivec/Tests/GPBMessageTests+Merge.m
new file mode 100644
index 0000000000..c0bd5897a4
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBMessageTests+Merge.m
@@ -0,0 +1,700 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import <objc/runtime.h>
+
+#import "GPBMessage.h"
+
+#import "google/protobuf/MapUnittest.pbobjc.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h"
+
+@interface MessageMergeTests : GPBTestCase
+@end
+
+@implementation MessageMergeTests
+
+// TODO(thomasvl): Pull tests over from GPBMessageTests that are merge specific.
+
+- (void)testProto3MergingAndZeroValues {
+ // Proto2 covered in other tests.
+
+ Message3 *src = [[Message3 alloc] init];
+ Message3 *dst = [[Message3 alloc] init];
+ NSData *testData1 = [@"abc" dataUsingEncoding:NSUTF8StringEncoding];
+ NSData *testData2 = [@"def" dataUsingEncoding:NSUTF8StringEncoding];
+
+ dst.optionalInt32 = 1;
+ dst.optionalInt64 = 1;
+ dst.optionalUint32 = 1;
+ dst.optionalUint64 = 1;
+ dst.optionalSint32 = 1;
+ dst.optionalSint64 = 1;
+ dst.optionalFixed32 = 1;
+ dst.optionalFixed64 = 1;
+ dst.optionalSfixed32 = 1;
+ dst.optionalSfixed64 = 1;
+ dst.optionalFloat = 1.0f;
+ dst.optionalDouble = 1.0;
+ dst.optionalBool = YES;
+ dst.optionalString = @"bar";
+ dst.optionalBytes = testData1;
+ dst.optionalEnum = Message3_Enum_Bar;
+
+ // All zeros, nothing should overright.
+
+ src.optionalInt32 = 0;
+ src.optionalInt64 = 0;
+ src.optionalUint32 = 0;
+ src.optionalUint64 = 0;
+ src.optionalSint32 = 0;
+ src.optionalSint64 = 0;
+ src.optionalFixed32 = 0;
+ src.optionalFixed64 = 0;
+ src.optionalSfixed32 = 0;
+ src.optionalSfixed64 = 0;
+ src.optionalFloat = 0.0f;
+ src.optionalDouble = 0.0;
+ src.optionalBool = NO;
+ src.optionalString = @"";
+ src.optionalBytes = [NSData data];
+ src.optionalEnum = Message3_Enum_Foo; // first value
+
+ [dst mergeFrom:src];
+
+ XCTAssertEqual(dst.optionalInt32, 1);
+ XCTAssertEqual(dst.optionalInt64, 1);
+ XCTAssertEqual(dst.optionalUint32, 1U);
+ XCTAssertEqual(dst.optionalUint64, 1U);
+ XCTAssertEqual(dst.optionalSint32, 1);
+ XCTAssertEqual(dst.optionalSint64, 1);
+ XCTAssertEqual(dst.optionalFixed32, 1U);
+ XCTAssertEqual(dst.optionalFixed64, 1U);
+ XCTAssertEqual(dst.optionalSfixed32, 1);
+ XCTAssertEqual(dst.optionalSfixed64, 1);
+ XCTAssertEqual(dst.optionalFloat, 1.0f);
+ XCTAssertEqual(dst.optionalDouble, 1.0);
+ XCTAssertEqual(dst.optionalBool, YES);
+ XCTAssertEqualObjects(dst.optionalString, @"bar");
+ XCTAssertEqualObjects(dst.optionalBytes, testData1);
+ XCTAssertEqual(dst.optionalEnum, Message3_Enum_Bar);
+
+ // Half the values that will replace.
+
+ src.optionalInt32 = 0;
+ src.optionalInt64 = 2;
+ src.optionalUint32 = 0;
+ src.optionalUint64 = 2;
+ src.optionalSint32 = 0;
+ src.optionalSint64 = 2;
+ src.optionalFixed32 = 0;
+ src.optionalFixed64 = 2;
+ src.optionalSfixed32 = 0;
+ src.optionalSfixed64 = 2;
+ src.optionalFloat = 0.0f;
+ src.optionalDouble = 2.0;
+ src.optionalBool = YES; // No other value to use. :(
+ src.optionalString = @"baz";
+ src.optionalBytes = nil;
+ src.optionalEnum = Message3_Enum_Baz;
+
+ [dst mergeFrom:src];
+
+ XCTAssertEqual(dst.optionalInt32, 1);
+ XCTAssertEqual(dst.optionalInt64, 2);
+ XCTAssertEqual(dst.optionalUint32, 1U);
+ XCTAssertEqual(dst.optionalUint64, 2U);
+ XCTAssertEqual(dst.optionalSint32, 1);
+ XCTAssertEqual(dst.optionalSint64, 2);
+ XCTAssertEqual(dst.optionalFixed32, 1U);
+ XCTAssertEqual(dst.optionalFixed64, 2U);
+ XCTAssertEqual(dst.optionalSfixed32, 1);
+ XCTAssertEqual(dst.optionalSfixed64, 2);
+ XCTAssertEqual(dst.optionalFloat, 1.0f);
+ XCTAssertEqual(dst.optionalDouble, 2.0);
+ XCTAssertEqual(dst.optionalBool, YES);
+ XCTAssertEqualObjects(dst.optionalString, @"baz");
+ XCTAssertEqualObjects(dst.optionalBytes, testData1);
+ XCTAssertEqual(dst.optionalEnum, Message3_Enum_Baz);
+
+ // Other half the values that will replace.
+
+ src.optionalInt32 = 3;
+ src.optionalInt64 = 0;
+ src.optionalUint32 = 3;
+ src.optionalUint64 = 0;
+ src.optionalSint32 = 3;
+ src.optionalSint64 = 0;
+ src.optionalFixed32 = 3;
+ src.optionalFixed64 = 0;
+ src.optionalSfixed32 = 3;
+ src.optionalSfixed64 = 0;
+ src.optionalFloat = 3.0f;
+ src.optionalDouble = 0.0;
+ src.optionalBool = YES; // No other value to use. :(
+ src.optionalString = nil;
+ src.optionalBytes = testData2;
+ src.optionalEnum = Message3_Enum_Foo;
+
+ [dst mergeFrom:src];
+
+ XCTAssertEqual(dst.optionalInt32, 3);
+ XCTAssertEqual(dst.optionalInt64, 2);
+ XCTAssertEqual(dst.optionalUint32, 3U);
+ XCTAssertEqual(dst.optionalUint64, 2U);
+ XCTAssertEqual(dst.optionalSint32, 3);
+ XCTAssertEqual(dst.optionalSint64, 2);
+ XCTAssertEqual(dst.optionalFixed32, 3U);
+ XCTAssertEqual(dst.optionalFixed64, 2U);
+ XCTAssertEqual(dst.optionalSfixed32, 3);
+ XCTAssertEqual(dst.optionalSfixed64, 2);
+ XCTAssertEqual(dst.optionalFloat, 3.0f);
+ XCTAssertEqual(dst.optionalDouble, 2.0);
+ XCTAssertEqual(dst.optionalBool, YES);
+ XCTAssertEqualObjects(dst.optionalString, @"baz");
+ XCTAssertEqualObjects(dst.optionalBytes, testData2);
+ XCTAssertEqual(dst.optionalEnum, Message3_Enum_Baz);
+
+ [src release];
+ [dst release];
+}
+
+- (void)testProto3MergingEnums {
+ UnknownEnumsMyMessage *src = [UnknownEnumsMyMessage message];
+ UnknownEnumsMyMessage *dst = [UnknownEnumsMyMessage message];
+
+ // Known value.
+
+ src.e = UnknownEnumsMyEnum_Bar;
+ src.repeatedEArray =
+ [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue
+ rawValue:UnknownEnumsMyEnum_Bar];
+ src.repeatedPackedEArray =
+ [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue
+ rawValue:UnknownEnumsMyEnum_Bar];
+ src.oneofE1 = UnknownEnumsMyEnum_Bar;
+
+ [dst mergeFrom:src];
+
+ XCTAssertEqual(dst.e, UnknownEnumsMyEnum_Bar);
+ XCTAssertEqual(dst.repeatedEArray.count, 1U);
+ XCTAssertEqual([dst.repeatedEArray valueAtIndex:0], UnknownEnumsMyEnum_Bar);
+ XCTAssertEqual(dst.repeatedPackedEArray.count, 1U);
+ XCTAssertEqual([dst.repeatedPackedEArray valueAtIndex:0],
+ UnknownEnumsMyEnum_Bar);
+ XCTAssertEqual(dst.oneofE1, UnknownEnumsMyEnum_Bar);
+
+ // Unknown value.
+
+ const int32_t kUnknownValue = 666;
+
+ SetUnknownEnumsMyMessage_E_RawValue(src, kUnknownValue);
+ src.repeatedEArray =
+ [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue
+ rawValue:kUnknownValue];
+ src.repeatedPackedEArray =
+ [GPBEnumArray arrayWithValidationFunction:UnknownEnumsMyEnum_IsValidValue
+ rawValue:kUnknownValue];
+ SetUnknownEnumsMyMessage_OneofE1_RawValue(src, kUnknownValue);
+
+ [dst mergeFrom:src];
+
+ XCTAssertEqual(dst.e, UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual(UnknownEnumsMyMessage_E_RawValue(dst), kUnknownValue);
+ XCTAssertEqual(dst.repeatedEArray.count, 2U);
+ XCTAssertEqual([dst.repeatedEArray valueAtIndex:0], UnknownEnumsMyEnum_Bar);
+ XCTAssertEqual([dst.repeatedEArray valueAtIndex:1],
+ UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([dst.repeatedEArray rawValueAtIndex:1], kUnknownValue);
+ XCTAssertEqual(dst.repeatedPackedEArray.count, 2U);
+ XCTAssertEqual([dst.repeatedPackedEArray valueAtIndex:0],
+ UnknownEnumsMyEnum_Bar);
+ XCTAssertEqual([dst.repeatedPackedEArray valueAtIndex:1],
+ UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([dst.repeatedPackedEArray rawValueAtIndex:1], kUnknownValue);
+ XCTAssertEqual(dst.oneofE1,
+ UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual(UnknownEnumsMyMessage_OneofE1_RawValue(dst), kUnknownValue);
+}
+
+- (void)testProto2MergeOneof {
+ Message2 *src = [Message2 message];
+ Message2 *dst = [Message2 message];
+
+ //
+ // Make sure whatever is in dst gets cleared out be merging in something else.
+ //
+
+ dst.oneofEnum = Message2_Enum_Bar;
+
+//%PDDM-DEFINE MERGE2_TEST(SET_NAME, SET_VALUE, CLEARED_NAME, CLEARED_DEFAULT)
+//% src.oneof##SET_NAME = SET_VALUE;
+//% [dst mergeFrom:src];
+//% XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_Oneof##SET_NAME);
+//% XCTAssertEqual(dst.oneof##SET_NAME, SET_VALUE);
+//% XCTAssertEqual(dst.oneof##CLEARED_NAME, CLEARED_DEFAULT);
+//%
+//%PDDM-EXPAND MERGE2_TEST(Int32, 10, Enum, Message2_Enum_Baz)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofInt32 = 10;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofInt32);
+ XCTAssertEqual(dst.oneofInt32, 10);
+ XCTAssertEqual(dst.oneofEnum, Message2_Enum_Baz);
+
+//%PDDM-EXPAND MERGE2_TEST(Int64, 11, Int32, 100)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofInt64 = 11;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofInt64);
+ XCTAssertEqual(dst.oneofInt64, 11);
+ XCTAssertEqual(dst.oneofInt32, 100);
+
+//%PDDM-EXPAND MERGE2_TEST(Uint32, 12U, Int64, 101)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofUint32 = 12U;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofUint32);
+ XCTAssertEqual(dst.oneofUint32, 12U);
+ XCTAssertEqual(dst.oneofInt64, 101);
+
+//%PDDM-EXPAND MERGE2_TEST(Uint64, 13U, Uint32, 102U)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofUint64 = 13U;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofUint64);
+ XCTAssertEqual(dst.oneofUint64, 13U);
+ XCTAssertEqual(dst.oneofUint32, 102U);
+
+//%PDDM-EXPAND MERGE2_TEST(Sint32, 14, Uint64, 103U)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofSint32 = 14;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofSint32);
+ XCTAssertEqual(dst.oneofSint32, 14);
+ XCTAssertEqual(dst.oneofUint64, 103U);
+
+//%PDDM-EXPAND MERGE2_TEST(Sint64, 15, Sint32, 104)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofSint64 = 15;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofSint64);
+ XCTAssertEqual(dst.oneofSint64, 15);
+ XCTAssertEqual(dst.oneofSint32, 104);
+
+//%PDDM-EXPAND MERGE2_TEST(Fixed32, 16U, Sint64, 105)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofFixed32 = 16U;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofFixed32);
+ XCTAssertEqual(dst.oneofFixed32, 16U);
+ XCTAssertEqual(dst.oneofSint64, 105);
+
+//%PDDM-EXPAND MERGE2_TEST(Fixed64, 17U, Fixed32, 106U)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofFixed64 = 17U;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofFixed64);
+ XCTAssertEqual(dst.oneofFixed64, 17U);
+ XCTAssertEqual(dst.oneofFixed32, 106U);
+
+//%PDDM-EXPAND MERGE2_TEST(Sfixed32, 18, Fixed64, 107U)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofSfixed32 = 18;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofSfixed32);
+ XCTAssertEqual(dst.oneofSfixed32, 18);
+ XCTAssertEqual(dst.oneofFixed64, 107U);
+
+//%PDDM-EXPAND MERGE2_TEST(Sfixed64, 19, Sfixed32, 108)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofSfixed64 = 19;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofSfixed64);
+ XCTAssertEqual(dst.oneofSfixed64, 19);
+ XCTAssertEqual(dst.oneofSfixed32, 108);
+
+//%PDDM-EXPAND MERGE2_TEST(Float, 20.0f, Sfixed64, 109)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofFloat = 20.0f;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofFloat);
+ XCTAssertEqual(dst.oneofFloat, 20.0f);
+ XCTAssertEqual(dst.oneofSfixed64, 109);
+
+//%PDDM-EXPAND MERGE2_TEST(Double, 21.0, Float, 110.0f)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofDouble = 21.0;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofDouble);
+ XCTAssertEqual(dst.oneofDouble, 21.0);
+ XCTAssertEqual(dst.oneofFloat, 110.0f);
+
+//%PDDM-EXPAND MERGE2_TEST(Bool, NO, Double, 111.0)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofBool = NO;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofBool);
+ XCTAssertEqual(dst.oneofBool, NO);
+ XCTAssertEqual(dst.oneofDouble, 111.0);
+
+//%PDDM-EXPAND MERGE2_TEST(Enum, Message2_Enum_Bar, Bool, YES)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofEnum = Message2_Enum_Bar;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofEnum);
+ XCTAssertEqual(dst.oneofEnum, Message2_Enum_Bar);
+ XCTAssertEqual(dst.oneofBool, YES);
+
+//%PDDM-EXPAND-END (14 expansions)
+
+ NSString *oneofStringDefault = @"string";
+ NSData *oneofBytesDefault = [@"data" dataUsingEncoding:NSUTF8StringEncoding];
+
+ src.oneofString = @"foo";
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofString);
+ XCTAssertEqualObjects(dst.oneofString, @"foo");
+ XCTAssertEqual(dst.oneofEnum, Message2_Enum_Baz);
+
+ src.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofBytes);
+ XCTAssertEqualObjects(dst.oneofBytes,
+ [@"bar" dataUsingEncoding:NSUTF8StringEncoding]);
+ XCTAssertEqualObjects(dst.oneofString, oneofStringDefault);
+
+ Message2_OneofGroup *group = [Message2_OneofGroup message];
+ group.a = 666;
+ src.oneofGroup = group;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofGroup);
+ Message2_OneofGroup *mergedGroup = [[dst.oneofGroup retain] autorelease];
+ XCTAssertNotNil(mergedGroup);
+ XCTAssertNotEqual(mergedGroup, group); // Pointer comparision.
+ XCTAssertEqualObjects(mergedGroup, group);
+ XCTAssertEqualObjects(dst.oneofBytes, oneofBytesDefault);
+
+ Message2 *subMessage = [Message2 message];
+ subMessage.optionalInt32 = 777;
+ src.oneofMessage = subMessage;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofMessage);
+ Message2 *mergedSubMessage = [[dst.oneofMessage retain] autorelease];
+ XCTAssertNotNil(mergedSubMessage);
+ XCTAssertNotEqual(mergedSubMessage, subMessage); // Pointer comparision.
+ XCTAssertEqualObjects(mergedSubMessage, subMessage);
+ XCTAssertNotNil(dst.oneofGroup);
+ XCTAssertNotEqual(dst.oneofGroup, mergedGroup); // Pointer comparision.
+
+ // Back to something else to make sure message clears out ok.
+
+ src.oneofInt32 = 10;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofInt32);
+ XCTAssertNotNil(dst.oneofMessage);
+ XCTAssertNotEqual(dst.oneofMessage,
+ mergedSubMessage); // Pointer comparision.
+
+ //
+ // Test merging in to message/group when they already had something.
+ //
+
+ src.oneofGroup = group;
+ mergedGroup = [Message2_OneofGroup message];
+ mergedGroup.b = 888;
+ dst.oneofGroup = mergedGroup;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofGroup);
+ // Shouldn't have been a new object.
+ XCTAssertEqual(dst.oneofGroup, mergedGroup); // Pointer comparision.
+ XCTAssertEqual(dst.oneofGroup.a, 666); // Pointer comparision.
+ XCTAssertEqual(dst.oneofGroup.b, 888); // Pointer comparision.
+
+ src.oneofMessage = subMessage;
+ mergedSubMessage = [Message2 message];
+ mergedSubMessage.optionalInt64 = 999;
+ dst.oneofMessage = mergedSubMessage;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message2_O_OneOfCase_OneofMessage);
+ // Shouldn't have been a new object.
+ XCTAssertEqual(dst.oneofMessage, mergedSubMessage); // Pointer comparision.
+ XCTAssertEqual(dst.oneofMessage.optionalInt32, 777); // Pointer comparision.
+ XCTAssertEqual(dst.oneofMessage.optionalInt64, 999); // Pointer comparision.
+}
+
+- (void)testProto3MergeOneof {
+ Message3 *src = [Message3 message];
+ Message3 *dst = [Message3 message];
+
+ //
+ // Make sure whatever is in dst gets cleared out be merging in something else.
+ //
+
+ dst.oneofEnum = Message3_Enum_Bar;
+
+//%PDDM-DEFINE MERGE3_TEST(SET_NAME, SET_VALUE, CLEARED_NAME, CLEARED_DEFAULT)
+//% src.oneof##SET_NAME = SET_VALUE;
+//% [dst mergeFrom:src];
+//% XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_Oneof##SET_NAME);
+//% XCTAssertEqual(dst.oneof##SET_NAME, SET_VALUE);
+//% XCTAssertEqual(dst.oneof##CLEARED_NAME, CLEARED_DEFAULT);
+//%
+//%PDDM-EXPAND MERGE3_TEST(Int32, 10, Enum, Message3_Enum_Foo)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofInt32 = 10;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofInt32);
+ XCTAssertEqual(dst.oneofInt32, 10);
+ XCTAssertEqual(dst.oneofEnum, Message3_Enum_Foo);
+
+//%PDDM-EXPAND MERGE3_TEST(Int64, 11, Int32, 0)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofInt64 = 11;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofInt64);
+ XCTAssertEqual(dst.oneofInt64, 11);
+ XCTAssertEqual(dst.oneofInt32, 0);
+
+//%PDDM-EXPAND MERGE3_TEST(Uint32, 12U, Int64, 0)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofUint32 = 12U;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofUint32);
+ XCTAssertEqual(dst.oneofUint32, 12U);
+ XCTAssertEqual(dst.oneofInt64, 0);
+
+//%PDDM-EXPAND MERGE3_TEST(Uint64, 13U, Uint32, 0U)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofUint64 = 13U;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofUint64);
+ XCTAssertEqual(dst.oneofUint64, 13U);
+ XCTAssertEqual(dst.oneofUint32, 0U);
+
+//%PDDM-EXPAND MERGE3_TEST(Sint32, 14, Uint64, 0U)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofSint32 = 14;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofSint32);
+ XCTAssertEqual(dst.oneofSint32, 14);
+ XCTAssertEqual(dst.oneofUint64, 0U);
+
+//%PDDM-EXPAND MERGE3_TEST(Sint64, 15, Sint32, 0)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofSint64 = 15;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofSint64);
+ XCTAssertEqual(dst.oneofSint64, 15);
+ XCTAssertEqual(dst.oneofSint32, 0);
+
+//%PDDM-EXPAND MERGE3_TEST(Fixed32, 16U, Sint64, 0)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofFixed32 = 16U;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofFixed32);
+ XCTAssertEqual(dst.oneofFixed32, 16U);
+ XCTAssertEqual(dst.oneofSint64, 0);
+
+//%PDDM-EXPAND MERGE3_TEST(Fixed64, 17U, Fixed32, 0U)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofFixed64 = 17U;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofFixed64);
+ XCTAssertEqual(dst.oneofFixed64, 17U);
+ XCTAssertEqual(dst.oneofFixed32, 0U);
+
+//%PDDM-EXPAND MERGE3_TEST(Sfixed32, 18, Fixed64, 0U)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofSfixed32 = 18;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofSfixed32);
+ XCTAssertEqual(dst.oneofSfixed32, 18);
+ XCTAssertEqual(dst.oneofFixed64, 0U);
+
+//%PDDM-EXPAND MERGE3_TEST(Sfixed64, 19, Sfixed32, 0)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofSfixed64 = 19;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofSfixed64);
+ XCTAssertEqual(dst.oneofSfixed64, 19);
+ XCTAssertEqual(dst.oneofSfixed32, 0);
+
+//%PDDM-EXPAND MERGE3_TEST(Float, 20.0f, Sfixed64, 0)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofFloat = 20.0f;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofFloat);
+ XCTAssertEqual(dst.oneofFloat, 20.0f);
+ XCTAssertEqual(dst.oneofSfixed64, 0);
+
+//%PDDM-EXPAND MERGE3_TEST(Double, 21.0, Float, 0.0f)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofDouble = 21.0;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofDouble);
+ XCTAssertEqual(dst.oneofDouble, 21.0);
+ XCTAssertEqual(dst.oneofFloat, 0.0f);
+
+//%PDDM-EXPAND MERGE3_TEST(Bool, YES, Double, 0.0)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofBool = YES;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofBool);
+ XCTAssertEqual(dst.oneofBool, YES);
+ XCTAssertEqual(dst.oneofDouble, 0.0);
+
+//%PDDM-EXPAND MERGE3_TEST(Enum, Message3_Enum_Bar, Bool, NO)
+// This block of code is generated, do not edit it directly.
+
+ src.oneofEnum = Message3_Enum_Bar;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofEnum);
+ XCTAssertEqual(dst.oneofEnum, Message3_Enum_Bar);
+ XCTAssertEqual(dst.oneofBool, NO);
+
+//%PDDM-EXPAND-END (14 expansions)
+
+ NSString *oneofStringDefault = @"";
+ NSData *oneofBytesDefault = [NSData data];
+
+ src.oneofString = @"foo";
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofString);
+ XCTAssertEqualObjects(dst.oneofString, @"foo");
+ XCTAssertEqual(dst.oneofEnum, Message3_Enum_Foo);
+
+ src.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofBytes);
+ XCTAssertEqualObjects(dst.oneofBytes,
+ [@"bar" dataUsingEncoding:NSUTF8StringEncoding]);
+ XCTAssertEqualObjects(dst.oneofString, oneofStringDefault);
+
+
+ Message3 *subMessage = [Message3 message];
+ subMessage.optionalInt32 = 777;
+ src.oneofMessage = subMessage;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofMessage);
+ Message3 *mergedSubMessage = [[dst.oneofMessage retain] autorelease];
+ XCTAssertNotNil(mergedSubMessage);
+ XCTAssertNotEqual(mergedSubMessage, subMessage); // Pointer comparision.
+ XCTAssertEqualObjects(mergedSubMessage, subMessage);
+ XCTAssertEqualObjects(dst.oneofBytes, oneofBytesDefault);
+
+ // Back to something else to make sure message clears out ok.
+
+ src.oneofInt32 = 10;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofInt32);
+ XCTAssertNotNil(dst.oneofMessage);
+ XCTAssertNotEqual(dst.oneofMessage,
+ mergedSubMessage); // Pointer comparision.
+
+ //
+ // Test merging in to message when they already had something.
+ //
+
+ src.oneofMessage = subMessage;
+ mergedSubMessage = [Message3 message];
+ mergedSubMessage.optionalInt64 = 999;
+ dst.oneofMessage = mergedSubMessage;
+ [dst mergeFrom:src];
+ XCTAssertEqual(dst.oOneOfCase, Message3_O_OneOfCase_OneofMessage);
+ // Shouldn't have been a new object.
+ XCTAssertEqual(dst.oneofMessage, mergedSubMessage); // Pointer comparision.
+ XCTAssertEqual(dst.oneofMessage.optionalInt32, 777); // Pointer comparision.
+ XCTAssertEqual(dst.oneofMessage.optionalInt64, 999); // Pointer comparision.
+}
+
+#pragma mark - Subset from from map_tests.cc
+
+// TEST(GeneratedMapFieldTest, CopyFromMessageMap)
+- (void)testMap_CopyFromMessageMap {
+ TestMessageMap *msg1 = [[TestMessageMap alloc] init];
+ TestMessageMap *msg2 = [[TestMessageMap alloc] init];
+
+ TestAllTypes *subMsg = [TestAllTypes message];
+ subMsg.repeatedInt32Array = [GPBInt32Array arrayWithValue:100];
+ [msg1.mapInt32Message setObject:subMsg forKey:0];
+ subMsg = nil;
+
+ subMsg = [TestAllTypes message];
+ subMsg.repeatedInt32Array = [GPBInt32Array arrayWithValue:101];
+
+ [msg2.mapInt32Message setObject:subMsg forKey:0];
+ subMsg = nil;
+
+ [msg1 mergeFrom:msg2];
+
+ // Checks repeated field is overwritten.
+ XCTAssertEqual(msg1.mapInt32Message.count, 1U);
+ subMsg = [msg1.mapInt32Message objectForKey:0];
+ XCTAssertNotNil(subMsg);
+ XCTAssertEqual(subMsg.repeatedInt32Array.count, 1U);
+ XCTAssertEqual([subMsg.repeatedInt32Array valueAtIndex:0], 101);
+
+ [msg2 release];
+ [msg1 release];
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBMessageTests+Runtime.m b/third_party/protobuf/objectivec/Tests/GPBMessageTests+Runtime.m
new file mode 100644
index 0000000000..0058311b3b
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBMessageTests+Runtime.m
@@ -0,0 +1,2515 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import <objc/runtime.h>
+
+#import "GPBMessage.h"
+
+#import "google/protobuf/MapUnittest.pbobjc.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestCycle.pbobjc.h"
+#import "google/protobuf/UnittestObjcStartup.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h"
+
+@interface MessageRuntimeTests : GPBTestCase
+@end
+
+@implementation MessageRuntimeTests
+
+// TODO(thomasvl): Pull tests over from GPBMessageTests that are runtime
+// specific.
+
+- (void)testStartupOrdering {
+ // Message class/Root class initialization is a little tricky, so these just
+ // create some possible patterns that can be a problem. The messages don't
+ // have to be exercised, just creating them is enough to test. If there
+ // is a problem, the runtime should assert or hang.
+ //
+ // Note: the messages from these proto files should not be used in any other
+ // tests, that way when they are referenced here it will be the first use and
+ // initialization will take place now.
+
+ TestObjCStartupMessage *message = [TestObjCStartupMessage message];
+ XCTAssertNotNil(message);
+
+ CycleBaz *baz = [CycleBaz message];
+ CycleBar *bar = [CycleBar message];
+ CycleFoo *foo = [CycleFoo message];
+ XCTAssertNotNil(baz);
+ XCTAssertNotNil(bar);
+ XCTAssertNotNil(foo);
+}
+
+- (void)testProto2HasMethodSupport {
+ NSArray *names = @[
+ @"Int32",
+ @"Int64",
+ @"Uint32",
+ @"Uint64",
+ @"Sint32",
+ @"Sint64",
+ @"Fixed32",
+ @"Fixed64",
+ @"Sfixed32",
+ @"Sfixed64",
+ @"Float",
+ @"Double",
+ @"Bool",
+ @"String",
+ @"Bytes",
+ @"Group",
+ @"Message",
+ @"Enum",
+ ];
+
+ // Proto2 gets:
+
+ // Single fields - has*/setHas* is valid.
+
+ for (NSString *name in names) {
+ // build the selector, i.e. - hasOptionalInt32/setHasOptionalInt32:
+ SEL hasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"hasOptional%@", name]);
+ SEL setHasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"setHasOptional%@:", name]);
+ XCTAssertTrue([Message2 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertTrue([Message2 instancesRespondToSelector:setHasSel], @"field: %@",
+ name);
+ }
+
+ // Repeated fields
+ // - no has*/setHas*
+ // - *Count
+
+ for (NSString *name in names) {
+ // build the selector, i.e. - hasRepeatedInt32Array/setHasRepeatedInt32Array:
+ SEL hasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"hasRepeated%@Array", name]);
+ SEL setHasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"setHasRepeated%@Array:", name]);
+ XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel],
+ @"field: %@", name);
+ // build the selector, i.e. - repeatedInt32Array_Count
+ SEL countSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"repeated%@Array_Count", name]);
+ XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@",
+ name);
+ }
+
+ // OneOf fields - no has*/setHas*
+
+ for (NSString *name in names) {
+ // build the selector, i.e. - hasOneofInt32/setHasOneofInt32:
+ SEL hasSel =
+ NSSelectorFromString([NSString stringWithFormat:@"hasOneof%@", name]);
+ SEL setHasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"setHasOneof%@:", name]);
+ XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel],
+ @"field: %@", name);
+ }
+
+ // map<> fields
+ // - no has*/setHas*
+ // - *Count
+
+ NSArray *mapNames = @[
+ @"Int32Int32",
+ @"Int64Int64",
+ @"Uint32Uint32",
+ @"Uint64Uint64",
+ @"Sint32Sint32",
+ @"Sint64Sint64",
+ @"Fixed32Fixed32",
+ @"Fixed64Fixed64",
+ @"Sfixed32Sfixed32",
+ @"Sfixed64Sfixed64",
+ @"Int32Float",
+ @"Int32Double",
+ @"BoolBool",
+ @"StringString",
+ @"StringBytes",
+ @"StringMessage",
+ @"Int32Bytes",
+ @"Int32Enum",
+ @"Int32Message",
+ ];
+
+ for (NSString *name in mapNames) {
+ // build the selector, i.e. - hasMapInt32Int32/setHasMapInt32Int32:
+ SEL hasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"hasMap%@", name]);
+ SEL setHasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"setHasMap%@:", name]);
+ XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel],
+ @"field: %@", name);
+ // build the selector, i.e. - mapInt32Int32Count
+ SEL countSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"map%@_Count", name]);
+ XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@",
+ name);
+ }
+
+}
+
+- (void)testProto3HasMethodSupport {
+ NSArray *names = @[
+ @"Int32",
+ @"Int64",
+ @"Uint32",
+ @"Uint64",
+ @"Sint32",
+ @"Sint64",
+ @"Fixed32",
+ @"Fixed64",
+ @"Sfixed32",
+ @"Sfixed64",
+ @"Float",
+ @"Double",
+ @"Bool",
+ @"String",
+ @"Bytes",
+ @"Message",
+ @"Enum",
+ ];
+
+ // Proto3 gets:
+
+ // Single fields
+ // - has*/setHas* invalid for primative types.
+ // - has*/setHas* valid for Message.
+
+ for (NSString *name in names) {
+ // build the selector, i.e. - hasOptionalInt32/setHasOptionalInt32:
+ SEL hasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"hasOptional%@", name]);
+ SEL setHasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"setHasOptional%@:", name]);
+ if ([name isEqual:@"Message"]) {
+ // Sub messages/groups are the exception.
+ XCTAssertTrue([Message3 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertTrue([Message3 instancesRespondToSelector:setHasSel],
+ @"field: %@", name);
+ } else {
+ XCTAssertFalse([Message3 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertFalse([Message3 instancesRespondToSelector:setHasSel],
+ @"field: %@", name);
+ }
+ }
+
+ // Repeated fields
+ // - no has*/setHas*
+ // - *Count
+
+ for (NSString *name in names) {
+ // build the selector, i.e. - hasRepeatedInt32Array/setHasRepeatedInt32Array:
+ SEL hasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"hasRepeated%@Array", name]);
+ SEL setHasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"setHasRepeated%@Array:", name]);
+ XCTAssertFalse([Message3 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertFalse([Message3 instancesRespondToSelector:setHasSel],
+ @"field: %@", name);
+ // build the selector, i.e. - repeatedInt32Array_Count
+ SEL countSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"repeated%@Array_Count", name]);
+ XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@",
+ name);
+ }
+
+ // OneOf fields - no has*/setHas*
+
+ for (NSString *name in names) {
+ // build the selector, i.e. - hasOneofInt32/setHasOneofInt32:
+ SEL hasSel =
+ NSSelectorFromString([NSString stringWithFormat:@"hasOneof%@", name]);
+ SEL setHasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"setHasOneof%@:", name]);
+ XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel],
+ @"field: %@", name);
+ }
+
+ // map<> fields
+ // - no has*/setHas*
+ // - *Count
+
+ NSArray *mapNames = @[
+ @"Int32Int32",
+ @"Int64Int64",
+ @"Uint32Uint32",
+ @"Uint64Uint64",
+ @"Sint32Sint32",
+ @"Sint64Sint64",
+ @"Fixed32Fixed32",
+ @"Fixed64Fixed64",
+ @"Sfixed32Sfixed32",
+ @"Sfixed64Sfixed64",
+ @"Int32Float",
+ @"Int32Double",
+ @"BoolBool",
+ @"StringString",
+ @"StringBytes",
+ @"StringMessage",
+ @"Int32Bytes",
+ @"Int32Enum",
+ @"Int32Message",
+ ];
+
+ for (NSString *name in mapNames) {
+ // build the selector, i.e. - hasMapInt32Int32/setHasMapInt32Int32:
+ SEL hasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"hasMap%@", name]);
+ SEL setHasSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"setHasMap%@:", name]);
+ XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@",
+ name);
+ XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel],
+ @"field: %@", name);
+ // build the selector, i.e. - mapInt32Int32Count
+ SEL countSel = NSSelectorFromString(
+ [NSString stringWithFormat:@"map%@_Count", name]);
+ XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@",
+ name);
+ }
+}
+
+- (void)testProto2SingleFieldHasBehavior {
+ //
+ // Setting to any value including the default value (0) should result has*
+ // being true.
+ //
+
+//%PDDM-DEFINE PROTO2_TEST_HAS_FIELD(FIELD, NON_ZERO_VALUE, ZERO_VALUE)
+//% { // optional##FIELD :: NON_ZERO_VALUE
+//% Message2 *msg = [[Message2 alloc] init];
+//% XCTAssertFalse(msg.hasOptional##FIELD);
+//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_Optional##FIELD));
+//% msg.optional##FIELD = NON_ZERO_VALUE;
+//% XCTAssertTrue(msg.hasOptional##FIELD);
+//% XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_Optional##FIELD));
+//% [msg release];
+//% }
+//% { // optional##FIELD :: ZERO_VALUE
+//% Message2 *msg = [[Message2 alloc] init];
+//% XCTAssertFalse(msg.hasOptional##FIELD);
+//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_Optional##FIELD));
+//% msg.optional##FIELD = ZERO_VALUE;
+//% XCTAssertTrue(msg.hasOptional##FIELD);
+//% XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_Optional##FIELD));
+//% [msg release];
+//% }
+//%
+//%PDDM-DEFINE PROTO2_TEST_CLEAR_FIELD_WITH_NIL(FIELD, VALUE)
+//% { // optional##FIELD
+//% Message2 *msg = [[Message2 alloc] init];
+//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_Optional##FIELD));
+//% msg.optional##FIELD = VALUE;
+//% XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_Optional##FIELD));
+//% msg.optional##FIELD = nil;
+//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_Optional##FIELD));
+//% [msg release];
+//% }
+//%
+//%PDDM-DEFINE PROTO2_TEST_HAS_FIELDS()
+//%PROTO2_TEST_HAS_FIELD(Int32, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Int64, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Uint32, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Uint64, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Sint32, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Sint64, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Fixed32, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Fixed64, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Sfixed32, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Sfixed64, 1, 0)
+//%PROTO2_TEST_HAS_FIELD(Float, 1.0f, 0.0f)
+//%PROTO2_TEST_HAS_FIELD(Double, 1.0, 0.0)
+//%PROTO2_TEST_HAS_FIELD(Bool, YES, NO)
+//%PROTO2_TEST_HAS_FIELD(String, @"foo", @"")
+//%PROTO2_TEST_HAS_FIELD(Bytes, [@"foo" dataUsingEncoding:NSUTF8StringEncoding], [NSData data])
+//% //
+//% // Test doesn't apply to optionalGroup/optionalMessage.
+//% //
+//%
+//%PROTO2_TEST_HAS_FIELD(Enum, Message2_Enum_Bar, Message2_Enum_Foo)
+//% //
+//% // Nil can also be used to clear strings, bytes, groups, and messages.
+//% //
+//%
+//%PROTO2_TEST_CLEAR_FIELD_WITH_NIL(String, @"foo")
+//%PROTO2_TEST_CLEAR_FIELD_WITH_NIL(Bytes, [@"foo" dataUsingEncoding:NSUTF8StringEncoding])
+//%PROTO2_TEST_CLEAR_FIELD_WITH_NIL(Group, [Message2_OptionalGroup message])
+//%PROTO2_TEST_CLEAR_FIELD_WITH_NIL(Message, [Message2 message])
+//%PDDM-EXPAND PROTO2_TEST_HAS_FIELDS()
+// This block of code is generated, do not edit it directly.
+
+ { // optionalInt32 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalInt32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalInt32));
+ msg.optionalInt32 = 1;
+ XCTAssertTrue(msg.hasOptionalInt32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalInt32));
+ [msg release];
+ }
+ { // optionalInt32 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalInt32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalInt32));
+ msg.optionalInt32 = 0;
+ XCTAssertTrue(msg.hasOptionalInt32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalInt32));
+ [msg release];
+ }
+
+ { // optionalInt64 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalInt64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalInt64));
+ msg.optionalInt64 = 1;
+ XCTAssertTrue(msg.hasOptionalInt64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalInt64));
+ [msg release];
+ }
+ { // optionalInt64 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalInt64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalInt64));
+ msg.optionalInt64 = 0;
+ XCTAssertTrue(msg.hasOptionalInt64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalInt64));
+ [msg release];
+ }
+
+ { // optionalUint32 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalUint32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalUint32));
+ msg.optionalUint32 = 1;
+ XCTAssertTrue(msg.hasOptionalUint32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalUint32));
+ [msg release];
+ }
+ { // optionalUint32 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalUint32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalUint32));
+ msg.optionalUint32 = 0;
+ XCTAssertTrue(msg.hasOptionalUint32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalUint32));
+ [msg release];
+ }
+
+ { // optionalUint64 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalUint64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalUint64));
+ msg.optionalUint64 = 1;
+ XCTAssertTrue(msg.hasOptionalUint64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalUint64));
+ [msg release];
+ }
+ { // optionalUint64 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalUint64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalUint64));
+ msg.optionalUint64 = 0;
+ XCTAssertTrue(msg.hasOptionalUint64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalUint64));
+ [msg release];
+ }
+
+ { // optionalSint32 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalSint32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSint32));
+ msg.optionalSint32 = 1;
+ XCTAssertTrue(msg.hasOptionalSint32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSint32));
+ [msg release];
+ }
+ { // optionalSint32 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalSint32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSint32));
+ msg.optionalSint32 = 0;
+ XCTAssertTrue(msg.hasOptionalSint32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSint32));
+ [msg release];
+ }
+
+ { // optionalSint64 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalSint64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSint64));
+ msg.optionalSint64 = 1;
+ XCTAssertTrue(msg.hasOptionalSint64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSint64));
+ [msg release];
+ }
+ { // optionalSint64 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalSint64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSint64));
+ msg.optionalSint64 = 0;
+ XCTAssertTrue(msg.hasOptionalSint64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSint64));
+ [msg release];
+ }
+
+ { // optionalFixed32 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalFixed32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFixed32));
+ msg.optionalFixed32 = 1;
+ XCTAssertTrue(msg.hasOptionalFixed32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFixed32));
+ [msg release];
+ }
+ { // optionalFixed32 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalFixed32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFixed32));
+ msg.optionalFixed32 = 0;
+ XCTAssertTrue(msg.hasOptionalFixed32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFixed32));
+ [msg release];
+ }
+
+ { // optionalFixed64 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalFixed64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFixed64));
+ msg.optionalFixed64 = 1;
+ XCTAssertTrue(msg.hasOptionalFixed64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFixed64));
+ [msg release];
+ }
+ { // optionalFixed64 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalFixed64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFixed64));
+ msg.optionalFixed64 = 0;
+ XCTAssertTrue(msg.hasOptionalFixed64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFixed64));
+ [msg release];
+ }
+
+ { // optionalSfixed32 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalSfixed32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSfixed32));
+ msg.optionalSfixed32 = 1;
+ XCTAssertTrue(msg.hasOptionalSfixed32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSfixed32));
+ [msg release];
+ }
+ { // optionalSfixed32 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalSfixed32);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSfixed32));
+ msg.optionalSfixed32 = 0;
+ XCTAssertTrue(msg.hasOptionalSfixed32);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSfixed32));
+ [msg release];
+ }
+
+ { // optionalSfixed64 :: 1
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalSfixed64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSfixed64));
+ msg.optionalSfixed64 = 1;
+ XCTAssertTrue(msg.hasOptionalSfixed64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSfixed64));
+ [msg release];
+ }
+ { // optionalSfixed64 :: 0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalSfixed64);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSfixed64));
+ msg.optionalSfixed64 = 0;
+ XCTAssertTrue(msg.hasOptionalSfixed64);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalSfixed64));
+ [msg release];
+ }
+
+ { // optionalFloat :: 1.0f
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalFloat);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFloat));
+ msg.optionalFloat = 1.0f;
+ XCTAssertTrue(msg.hasOptionalFloat);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFloat));
+ [msg release];
+ }
+ { // optionalFloat :: 0.0f
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalFloat);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFloat));
+ msg.optionalFloat = 0.0f;
+ XCTAssertTrue(msg.hasOptionalFloat);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalFloat));
+ [msg release];
+ }
+
+ { // optionalDouble :: 1.0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalDouble);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalDouble));
+ msg.optionalDouble = 1.0;
+ XCTAssertTrue(msg.hasOptionalDouble);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalDouble));
+ [msg release];
+ }
+ { // optionalDouble :: 0.0
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalDouble);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalDouble));
+ msg.optionalDouble = 0.0;
+ XCTAssertTrue(msg.hasOptionalDouble);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalDouble));
+ [msg release];
+ }
+
+ { // optionalBool :: YES
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalBool);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBool));
+ msg.optionalBool = YES;
+ XCTAssertTrue(msg.hasOptionalBool);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBool));
+ [msg release];
+ }
+ { // optionalBool :: NO
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalBool);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBool));
+ msg.optionalBool = NO;
+ XCTAssertTrue(msg.hasOptionalBool);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBool));
+ [msg release];
+ }
+
+ { // optionalString :: @"foo"
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalString);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalString));
+ msg.optionalString = @"foo";
+ XCTAssertTrue(msg.hasOptionalString);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalString));
+ [msg release];
+ }
+ { // optionalString :: @""
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalString);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalString));
+ msg.optionalString = @"";
+ XCTAssertTrue(msg.hasOptionalString);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalString));
+ [msg release];
+ }
+
+ { // optionalBytes :: [@"foo" dataUsingEncoding:NSUTF8StringEncoding]
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalBytes);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBytes));
+ msg.optionalBytes = [@"foo" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertTrue(msg.hasOptionalBytes);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBytes));
+ [msg release];
+ }
+ { // optionalBytes :: [NSData data]
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalBytes);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBytes));
+ msg.optionalBytes = [NSData data];
+ XCTAssertTrue(msg.hasOptionalBytes);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBytes));
+ [msg release];
+ }
+
+ //
+ // Test doesn't apply to optionalGroup/optionalMessage.
+ //
+
+ { // optionalEnum :: Message2_Enum_Bar
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalEnum);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalEnum));
+ msg.optionalEnum = Message2_Enum_Bar;
+ XCTAssertTrue(msg.hasOptionalEnum);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalEnum));
+ [msg release];
+ }
+ { // optionalEnum :: Message2_Enum_Foo
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(msg.hasOptionalEnum);
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalEnum));
+ msg.optionalEnum = Message2_Enum_Foo;
+ XCTAssertTrue(msg.hasOptionalEnum);
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalEnum));
+ [msg release];
+ }
+
+ //
+ // Nil can also be used to clear strings, bytes, groups, and messages.
+ //
+
+ { // optionalString
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalString));
+ msg.optionalString = @"foo";
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalString));
+ msg.optionalString = nil;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalString));
+ [msg release];
+ }
+
+ { // optionalBytes
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBytes));
+ msg.optionalBytes = [@"foo" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBytes));
+ msg.optionalBytes = nil;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalBytes));
+ [msg release];
+ }
+
+ { // optionalGroup
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalGroup));
+ msg.optionalGroup = [Message2_OptionalGroup message];
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalGroup));
+ msg.optionalGroup = nil;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalGroup));
+ [msg release];
+ }
+
+ { // optionalMessage
+ Message2 *msg = [[Message2 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalMessage));
+ msg.optionalMessage = [Message2 message];
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalMessage));
+ msg.optionalMessage = nil;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message2_FieldNumber_OptionalMessage));
+ [msg release];
+ }
+
+//%PDDM-EXPAND-END PROTO2_TEST_HAS_FIELDS()
+}
+
+- (void)testProto3SingleFieldHasBehavior {
+ //
+ // Setting to any value but the default value (0) should result has*
+ // being true. When set to the default, shouldn't be true.
+ //
+
+//%PDDM-DEFINE PROTO3_TEST_HAS_FIELD(FIELD, NON_ZERO_VALUE, ZERO_VALUE)
+//% { // optional##FIELD
+//% Message3 *msg = [[Message3 alloc] init];
+//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_Optional##FIELD));
+//% msg.optional##FIELD = NON_ZERO_VALUE;
+//% XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_Optional##FIELD));
+//% msg.optional##FIELD = ZERO_VALUE;
+//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_Optional##FIELD));
+//% [msg release];
+//% }
+//%
+//%PDDM-DEFINE PROTO3_TEST_CLEAR_FIELD_WITH_NIL(FIELD, VALUE)
+//% { // optional##FIELD
+//% Message3 *msg = [[Message3 alloc] init];
+//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_Optional##FIELD));
+//% msg.optional##FIELD = VALUE;
+//% XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_Optional##FIELD));
+//% msg.optional##FIELD = nil;
+//% XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_Optional##FIELD));
+//% [msg release];
+//% }
+//%
+//%PDDM-DEFINE PROTO3_TEST_HAS_FIELDS()
+//%PROTO3_TEST_HAS_FIELD(Int32, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Int64, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Uint32, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Uint64, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Sint32, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Sint64, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Fixed32, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Fixed64, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Sfixed32, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Sfixed64, 1, 0)
+//%PROTO3_TEST_HAS_FIELD(Float, 1.0f, 0.0f)
+//%PROTO3_TEST_HAS_FIELD(Double, 1.0, 0.0)
+//%PROTO3_TEST_HAS_FIELD(Bool, YES, NO)
+//%PROTO3_TEST_HAS_FIELD(String, @"foo", @"")
+//%PROTO3_TEST_HAS_FIELD(Bytes, [@"foo" dataUsingEncoding:NSUTF8StringEncoding], [NSData data])
+//% //
+//% // Test doesn't apply to optionalMessage (no groups in proto3).
+//% //
+//%
+//%PROTO3_TEST_HAS_FIELD(Enum, Message3_Enum_Bar, Message3_Enum_Foo)
+//% //
+//% // Nil can also be used to clear strings, bytes, and messages (no groups in proto3).
+//% //
+//%
+//%PROTO3_TEST_CLEAR_FIELD_WITH_NIL(String, @"foo")
+//%PROTO3_TEST_CLEAR_FIELD_WITH_NIL(Bytes, [@"foo" dataUsingEncoding:NSUTF8StringEncoding])
+//%PROTO3_TEST_CLEAR_FIELD_WITH_NIL(Message, [Message3 message])
+//%PDDM-EXPAND PROTO3_TEST_HAS_FIELDS()
+// This block of code is generated, do not edit it directly.
+
+ { // optionalInt32
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalInt32));
+ msg.optionalInt32 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalInt32));
+ msg.optionalInt32 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalInt32));
+ [msg release];
+ }
+
+ { // optionalInt64
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalInt64));
+ msg.optionalInt64 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalInt64));
+ msg.optionalInt64 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalInt64));
+ [msg release];
+ }
+
+ { // optionalUint32
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalUint32));
+ msg.optionalUint32 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalUint32));
+ msg.optionalUint32 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalUint32));
+ [msg release];
+ }
+
+ { // optionalUint64
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalUint64));
+ msg.optionalUint64 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalUint64));
+ msg.optionalUint64 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalUint64));
+ [msg release];
+ }
+
+ { // optionalSint32
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSint32));
+ msg.optionalSint32 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSint32));
+ msg.optionalSint32 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSint32));
+ [msg release];
+ }
+
+ { // optionalSint64
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSint64));
+ msg.optionalSint64 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSint64));
+ msg.optionalSint64 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSint64));
+ [msg release];
+ }
+
+ { // optionalFixed32
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFixed32));
+ msg.optionalFixed32 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFixed32));
+ msg.optionalFixed32 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFixed32));
+ [msg release];
+ }
+
+ { // optionalFixed64
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFixed64));
+ msg.optionalFixed64 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFixed64));
+ msg.optionalFixed64 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFixed64));
+ [msg release];
+ }
+
+ { // optionalSfixed32
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSfixed32));
+ msg.optionalSfixed32 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSfixed32));
+ msg.optionalSfixed32 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSfixed32));
+ [msg release];
+ }
+
+ { // optionalSfixed64
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSfixed64));
+ msg.optionalSfixed64 = 1;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSfixed64));
+ msg.optionalSfixed64 = 0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalSfixed64));
+ [msg release];
+ }
+
+ { // optionalFloat
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFloat));
+ msg.optionalFloat = 1.0f;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFloat));
+ msg.optionalFloat = 0.0f;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalFloat));
+ [msg release];
+ }
+
+ { // optionalDouble
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalDouble));
+ msg.optionalDouble = 1.0;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalDouble));
+ msg.optionalDouble = 0.0;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalDouble));
+ [msg release];
+ }
+
+ { // optionalBool
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBool));
+ msg.optionalBool = YES;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBool));
+ msg.optionalBool = NO;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBool));
+ [msg release];
+ }
+
+ { // optionalString
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalString));
+ msg.optionalString = @"foo";
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalString));
+ msg.optionalString = @"";
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalString));
+ [msg release];
+ }
+
+ { // optionalBytes
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBytes));
+ msg.optionalBytes = [@"foo" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBytes));
+ msg.optionalBytes = [NSData data];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBytes));
+ [msg release];
+ }
+
+ //
+ // Test doesn't apply to optionalMessage (no groups in proto3).
+ //
+
+ { // optionalEnum
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalEnum));
+ msg.optionalEnum = Message3_Enum_Bar;
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalEnum));
+ msg.optionalEnum = Message3_Enum_Foo;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalEnum));
+ [msg release];
+ }
+
+ //
+ // Nil can also be used to clear strings, bytes, and messages (no groups in proto3).
+ //
+
+ { // optionalString
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalString));
+ msg.optionalString = @"foo";
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalString));
+ msg.optionalString = nil;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalString));
+ [msg release];
+ }
+
+ { // optionalBytes
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBytes));
+ msg.optionalBytes = [@"foo" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBytes));
+ msg.optionalBytes = nil;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalBytes));
+ [msg release];
+ }
+
+ { // optionalMessage
+ Message3 *msg = [[Message3 alloc] init];
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalMessage));
+ msg.optionalMessage = [Message3 message];
+ XCTAssertTrue(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalMessage));
+ msg.optionalMessage = nil;
+ XCTAssertFalse(GPBMessageHasFieldNumberSet(msg, Message3_FieldNumber_OptionalMessage));
+ [msg release];
+ }
+
+//%PDDM-EXPAND-END PROTO3_TEST_HAS_FIELDS()
+}
+
+- (void)testAccessingProto2UnknownEnumValues {
+ Message2 *msg = [[Message2 alloc] init];
+
+ // Set it to something non zero, try and confirm it doesn't change.
+
+ msg.optionalEnum = Message2_Enum_Bar;
+ XCTAssertThrowsSpecificNamed(msg.optionalEnum = 666, NSException,
+ NSInvalidArgumentException);
+ XCTAssertEqual(msg.optionalEnum, Message2_Enum_Bar);
+
+ msg.oneofEnum = Message2_Enum_Bar;
+ XCTAssertThrowsSpecificNamed(msg.oneofEnum = 666, NSException,
+ NSInvalidArgumentException);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Bar);
+
+ [msg release];
+}
+
+- (void)testAccessingProto3UnknownEnumValues {
+ Message3 *msg = [[Message3 alloc] init];
+
+ // Set it to something non zero, try and confirm it doesn't change.
+
+ msg.optionalEnum = Message3_Enum_Bar;
+ XCTAssertThrowsSpecificNamed(msg.optionalEnum = 666, NSException,
+ NSInvalidArgumentException);
+ XCTAssertEqual(msg.optionalEnum, Message3_Enum_Bar);
+
+ msg.oneofEnum = Message3_Enum_Bar;
+ XCTAssertThrowsSpecificNamed(msg.oneofEnum = 666, NSException,
+ NSInvalidArgumentException);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Bar);
+
+ // Set via raw api to confirm it works.
+
+ SetMessage3_OptionalEnum_RawValue(msg, 666);
+ XCTAssertEqual(msg.optionalEnum,
+ Message3_Enum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual(Message3_OptionalEnum_RawValue(msg), 666);
+
+ SetMessage3_OneofEnum_RawValue(msg, 666);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual(Message3_OneofEnum_RawValue(msg), 666);
+
+ [msg release];
+}
+
+- (void)testProto2OneofBasicBehaviors {
+ Message2 *msg = [[Message2 alloc] init];
+
+ NSString *oneofStringDefault = @"string";
+ NSData *oneofBytesDefault = [@"data" dataUsingEncoding:NSUTF8StringEncoding];
+
+ // Nothing set.
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_GPBUnsetOneOfCase);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+
+ // Set, check the case, check everyone has default but the one, confirm case
+ // didn't change.
+
+ msg.oneofInt32 = 1;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofInt32);
+ XCTAssertEqual(msg.oneofInt32, 1);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofInt32);
+
+ msg.oneofInt64 = 2;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofInt64);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 2);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofInt64);
+
+ msg.oneofUint32 = 3;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofUint32);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 3U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofUint32);
+
+ msg.oneofUint64 = 4;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofUint64);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 4U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofUint64);
+
+ msg.oneofSint32 = 5;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSint32);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 5);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSint32);
+
+ msg.oneofSint64 = 6;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSint64);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 6);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSint64);
+
+ msg.oneofFixed32 = 7;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFixed32);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 7U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFixed32);
+
+ msg.oneofFixed64 = 8;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFixed64);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 8U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFixed64);
+
+ msg.oneofSfixed32 = 9;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSfixed32);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 9);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSfixed32);
+
+ msg.oneofSfixed64 = 10;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSfixed64);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 10);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSfixed64);
+
+ msg.oneofFloat = 11.0f;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFloat);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 11.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFloat);
+
+ msg.oneofDouble = 12.0;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofDouble);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 12.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofDouble);
+
+ msg.oneofBool = NO;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofBool);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofBool);
+
+ msg.oneofString = @"foo";
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofString);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, @"foo");
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofString);
+
+ msg.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofBytes);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes,
+ [@"bar" dataUsingEncoding:NSUTF8StringEncoding]);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofBytes);
+
+ Message2_OneofGroup *group = [Message2_OneofGroup message];
+ msg.oneofGroup = group;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofGroup);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertEqual(msg.oneofGroup, group); // Pointer compare.
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofGroup);
+
+ Message2 *subMessage = [Message2 message];
+ msg.oneofMessage = subMessage;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofMessage);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotEqual(msg.oneofGroup, group); // Pointer compare.
+ XCTAssertEqual(msg.oneofMessage, subMessage); // Pointer compare.
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofMessage);
+
+ msg.oneofEnum = Message2_Enum_Bar;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofEnum);
+ XCTAssertEqual(msg.oneofInt32, 100);
+ XCTAssertEqual(msg.oneofInt64, 101);
+ XCTAssertEqual(msg.oneofUint32, 102U);
+ XCTAssertEqual(msg.oneofUint64, 103U);
+ XCTAssertEqual(msg.oneofSint32, 104);
+ XCTAssertEqual(msg.oneofSint64, 105);
+ XCTAssertEqual(msg.oneofFixed32, 106U);
+ XCTAssertEqual(msg.oneofFixed64, 107U);
+ XCTAssertEqual(msg.oneofSfixed32, 108);
+ XCTAssertEqual(msg.oneofSfixed64, 109);
+ XCTAssertEqual(msg.oneofFloat, 110.0f);
+ XCTAssertEqual(msg.oneofDouble, 111.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofGroup);
+ XCTAssertNotEqual(msg.oneofGroup, group); // Pointer compare.
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertNotEqual(msg.oneofMessage, subMessage); // Pointer compare.
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Bar);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofEnum);
+
+ // Test setting/calling clear clearing.
+
+ [msg release];
+ msg = [[Message2 alloc] init];
+
+ uint32_t values[] = {
+ Message2_O_OneOfCase_OneofInt32,
+ Message2_O_OneOfCase_OneofInt64,
+ Message2_O_OneOfCase_OneofUint32,
+ Message2_O_OneOfCase_OneofUint64,
+ Message2_O_OneOfCase_OneofSint32,
+ Message2_O_OneOfCase_OneofSint64,
+ Message2_O_OneOfCase_OneofFixed32,
+ Message2_O_OneOfCase_OneofFixed64,
+ Message2_O_OneOfCase_OneofSfixed32,
+ Message2_O_OneOfCase_OneofSfixed64,
+ Message2_O_OneOfCase_OneofFloat,
+ Message2_O_OneOfCase_OneofDouble,
+ Message2_O_OneOfCase_OneofBool,
+ Message2_O_OneOfCase_OneofString,
+ Message2_O_OneOfCase_OneofBytes,
+ Message2_O_OneOfCase_OneofGroup,
+ Message2_O_OneOfCase_OneofMessage,
+ Message2_O_OneOfCase_OneofEnum,
+ };
+
+ for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) {
+ switch (values[i]) {
+ case Message2_O_OneOfCase_OneofInt32:
+ msg.oneofInt32 = 1;
+ break;
+ case Message2_O_OneOfCase_OneofInt64:
+ msg.oneofInt64 = 2;
+ break;
+ case Message2_O_OneOfCase_OneofUint32:
+ msg.oneofUint32 = 3;
+ break;
+ case Message2_O_OneOfCase_OneofUint64:
+ msg.oneofUint64 = 4;
+ break;
+ case Message2_O_OneOfCase_OneofSint32:
+ msg.oneofSint32 = 5;
+ break;
+ case Message2_O_OneOfCase_OneofSint64:
+ msg.oneofSint64 = 6;
+ break;
+ case Message2_O_OneOfCase_OneofFixed32:
+ msg.oneofFixed32 = 7;
+ break;
+ case Message2_O_OneOfCase_OneofFixed64:
+ msg.oneofFixed64 = 8;
+ break;
+ case Message2_O_OneOfCase_OneofSfixed32:
+ msg.oneofSfixed32 = 9;
+ break;
+ case Message2_O_OneOfCase_OneofSfixed64:
+ msg.oneofSfixed64 = 10;
+ break;
+ case Message2_O_OneOfCase_OneofFloat:
+ msg.oneofFloat = 11.0f;
+ break;
+ case Message2_O_OneOfCase_OneofDouble:
+ msg.oneofDouble = 12.0;
+ break;
+ case Message2_O_OneOfCase_OneofBool:
+ msg.oneofBool = YES;
+ break;
+ case Message2_O_OneOfCase_OneofString:
+ msg.oneofString = @"foo";
+ break;
+ case Message2_O_OneOfCase_OneofBytes:
+ msg.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
+ break;
+ case Message2_O_OneOfCase_OneofGroup:
+ msg.oneofGroup = group;
+ break;
+ case Message2_O_OneOfCase_OneofMessage:
+ msg.oneofMessage = subMessage;
+ break;
+ case Message2_O_OneOfCase_OneofEnum:
+ msg.oneofEnum = Message2_Enum_Bar;
+ break;
+ default:
+ XCTFail(@"shouldn't happen, loop: %zd, value: %d", i, values[i]);
+ break;
+ }
+
+ XCTAssertEqual(msg.oOneOfCase, values[i], "Loop: %zd", i);
+ // No need to check the value was set, the above tests did that.
+ Message2_ClearOOneOfCase(msg);
+ // Nothing in the case.
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_GPBUnsetOneOfCase,
+ "Loop: %zd", i);
+ // Confirm everything is back to defaults after a clear.
+ XCTAssertEqual(msg.oneofInt32, 100, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofInt64, 101, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofUint32, 102U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofUint64, 103U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSint32, 104, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSint64, 105, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFixed32, 106U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFixed64, 107U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSfixed32, 108, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSfixed64, 109, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFloat, 110.0f, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofDouble, 111.0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofBool, YES, "Loop: %zd", i);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault, "Loop: %zd", i);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault, "Loop: %zd", i);
+ XCTAssertNotNil(msg.oneofGroup, "Loop: %zd", i);
+ XCTAssertNotEqual(msg.oneofGroup, group, "Loop: %zd",
+ i); // Pointer compare.
+ XCTAssertNotNil(msg.oneofMessage, "Loop: %zd", i);
+ XCTAssertNotEqual(msg.oneofMessage, subMessage, "Loop: %zd",
+ i); // Pointer compare.
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz, "Loop: %zd", i);
+ }
+
+ [msg release];
+}
+
+- (void)testProto3OneofBasicBehaviors {
+ Message3 *msg = [[Message3 alloc] init];
+
+ NSString *oneofStringDefault = @"";
+ NSData *oneofBytesDefault = [NSData data];
+
+ // Nothing set.
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_GPBUnsetOneOfCase);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+
+ // Set, check the case, check everyone has default but the one, confirm case
+ // didn't change.
+
+ msg.oneofInt32 = 1;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofInt32);
+ XCTAssertEqual(msg.oneofInt32, 1);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofInt32);
+
+ msg.oneofInt64 = 2;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofInt64);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 2);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofInt64);
+
+ msg.oneofUint32 = 3;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofUint32);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 3U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofUint32);
+
+ msg.oneofUint64 = 4;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofUint64);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 4U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofUint64);
+
+ msg.oneofSint32 = 5;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSint32);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 5);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSint32);
+
+ msg.oneofSint64 = 6;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSint64);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 6);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSint64);
+
+ msg.oneofFixed32 = 7;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFixed32);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 7U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFixed32);
+
+ msg.oneofFixed64 = 8;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFixed64);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 8U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFixed64);
+
+ msg.oneofSfixed32 = 9;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSfixed32);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 9);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSfixed32);
+
+ msg.oneofSfixed64 = 10;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSfixed64);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 10);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSfixed64);
+
+ msg.oneofFloat = 11.0f;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFloat);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 11.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFloat);
+
+ msg.oneofDouble = 12.0;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofDouble);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 12.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofDouble);
+
+ msg.oneofBool = YES;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofBool);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, YES);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofBool);
+
+ msg.oneofString = @"foo";
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofString);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, @"foo");
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofString);
+
+ msg.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofBytes);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes,
+ [@"bar" dataUsingEncoding:NSUTF8StringEncoding]);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofBytes);
+
+ Message3 *subMessage = [Message3 message];
+ msg.oneofMessage = subMessage;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofMessage);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertEqual(msg.oneofMessage, subMessage); // Pointer compare.
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofMessage);
+
+ msg.oneofEnum = Message3_Enum_Bar;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofEnum);
+ XCTAssertEqual(msg.oneofInt32, 0);
+ XCTAssertEqual(msg.oneofInt64, 0);
+ XCTAssertEqual(msg.oneofUint32, 0U);
+ XCTAssertEqual(msg.oneofUint64, 0U);
+ XCTAssertEqual(msg.oneofSint32, 0);
+ XCTAssertEqual(msg.oneofSint64, 0);
+ XCTAssertEqual(msg.oneofFixed32, 0U);
+ XCTAssertEqual(msg.oneofFixed64, 0U);
+ XCTAssertEqual(msg.oneofSfixed32, 0);
+ XCTAssertEqual(msg.oneofSfixed64, 0);
+ XCTAssertEqual(msg.oneofFloat, 0.0f);
+ XCTAssertEqual(msg.oneofDouble, 0.0);
+ XCTAssertEqual(msg.oneofBool, NO);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ XCTAssertNotNil(msg.oneofMessage);
+ XCTAssertNotEqual(msg.oneofMessage, subMessage); // Pointer compare.
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Bar);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofEnum);
+
+ // Test setting/calling clear clearing.
+
+ [msg release];
+ msg = [[Message3 alloc] init];
+
+ uint32_t values[] = {
+ Message3_O_OneOfCase_OneofInt32,
+ Message3_O_OneOfCase_OneofInt64,
+ Message3_O_OneOfCase_OneofUint32,
+ Message3_O_OneOfCase_OneofUint64,
+ Message3_O_OneOfCase_OneofSint32,
+ Message3_O_OneOfCase_OneofSint64,
+ Message3_O_OneOfCase_OneofFixed32,
+ Message3_O_OneOfCase_OneofFixed64,
+ Message3_O_OneOfCase_OneofSfixed32,
+ Message3_O_OneOfCase_OneofSfixed64,
+ Message3_O_OneOfCase_OneofFloat,
+ Message3_O_OneOfCase_OneofDouble,
+ Message3_O_OneOfCase_OneofBool,
+ Message3_O_OneOfCase_OneofString,
+ Message3_O_OneOfCase_OneofBytes,
+ Message3_O_OneOfCase_OneofMessage,
+ Message3_O_OneOfCase_OneofEnum,
+ };
+
+ for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) {
+ switch (values[i]) {
+ case Message3_O_OneOfCase_OneofInt32:
+ msg.oneofInt32 = 1;
+ break;
+ case Message3_O_OneOfCase_OneofInt64:
+ msg.oneofInt64 = 2;
+ break;
+ case Message3_O_OneOfCase_OneofUint32:
+ msg.oneofUint32 = 3;
+ break;
+ case Message3_O_OneOfCase_OneofUint64:
+ msg.oneofUint64 = 4;
+ break;
+ case Message3_O_OneOfCase_OneofSint32:
+ msg.oneofSint32 = 5;
+ break;
+ case Message3_O_OneOfCase_OneofSint64:
+ msg.oneofSint64 = 6;
+ break;
+ case Message3_O_OneOfCase_OneofFixed32:
+ msg.oneofFixed32 = 7;
+ break;
+ case Message3_O_OneOfCase_OneofFixed64:
+ msg.oneofFixed64 = 8;
+ break;
+ case Message3_O_OneOfCase_OneofSfixed32:
+ msg.oneofSfixed32 = 9;
+ break;
+ case Message3_O_OneOfCase_OneofSfixed64:
+ msg.oneofSfixed64 = 10;
+ break;
+ case Message3_O_OneOfCase_OneofFloat:
+ msg.oneofFloat = 11.0f;
+ break;
+ case Message3_O_OneOfCase_OneofDouble:
+ msg.oneofDouble = 12.0;
+ break;
+ case Message3_O_OneOfCase_OneofBool:
+ msg.oneofBool = YES;
+ break;
+ case Message3_O_OneOfCase_OneofString:
+ msg.oneofString = @"foo";
+ break;
+ case Message3_O_OneOfCase_OneofBytes:
+ msg.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
+ break;
+ case Message3_O_OneOfCase_OneofMessage:
+ msg.oneofMessage = subMessage;
+ break;
+ case Message3_O_OneOfCase_OneofEnum:
+ msg.oneofEnum = Message3_Enum_Baz;
+ break;
+ default:
+ XCTFail(@"shouldn't happen, loop: %zd, value: %d", i, values[i]);
+ break;
+ }
+
+ XCTAssertEqual(msg.oOneOfCase, values[i], "Loop: %zd", i);
+ // No need to check the value was set, the above tests did that.
+ Message3_ClearOOneOfCase(msg);
+ // Nothing in the case.
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_GPBUnsetOneOfCase,
+ "Loop: %zd", i);
+ // Confirm everything is back to defaults after a clear.
+ XCTAssertEqual(msg.oneofInt32, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofInt64, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofUint32, 0U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofUint64, 0U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSint32, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSint64, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFixed32, 0U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFixed64, 0U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSfixed32, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSfixed64, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFloat, 0.0f, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofDouble, 0.0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofBool, NO, "Loop: %zd", i);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault, "Loop: %zd", i);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault, "Loop: %zd", i);
+ XCTAssertNotNil(msg.oneofMessage, "Loop: %zd", i);
+ XCTAssertNotEqual(msg.oneofMessage, subMessage, "Loop: %zd",
+ i); // Pointer compare.
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo, "Loop: %zd", i);
+ }
+
+ [msg release];
+}
+
+- (void)testProto2OneofSetToDefault {
+
+ // proto3 doesn't normally write out zero (default) fields, but if they are
+ // in a oneof it does. proto2 doesn't have this special behavior, but we
+ // still confirm setting to the explicit default does set the case to be
+ // sure the runtime is working correctly.
+
+ NSString *oneofStringDefault = @"string";
+ NSData *oneofBytesDefault = [@"data" dataUsingEncoding:NSUTF8StringEncoding];
+
+ Message2 *msg = [[Message2 alloc] init];
+
+ uint32_t values[] = {
+ Message2_O_OneOfCase_OneofInt32,
+ Message2_O_OneOfCase_OneofInt64,
+ Message2_O_OneOfCase_OneofUint32,
+ Message2_O_OneOfCase_OneofUint64,
+ Message2_O_OneOfCase_OneofSint32,
+ Message2_O_OneOfCase_OneofSint64,
+ Message2_O_OneOfCase_OneofFixed32,
+ Message2_O_OneOfCase_OneofFixed64,
+ Message2_O_OneOfCase_OneofSfixed32,
+ Message2_O_OneOfCase_OneofSfixed64,
+ Message2_O_OneOfCase_OneofFloat,
+ Message2_O_OneOfCase_OneofDouble,
+ Message2_O_OneOfCase_OneofBool,
+ Message2_O_OneOfCase_OneofString,
+ Message2_O_OneOfCase_OneofBytes,
+ // Skip group
+ // Skip message
+ Message2_O_OneOfCase_OneofEnum,
+ };
+
+ for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) {
+ switch (values[i]) {
+ case Message2_O_OneOfCase_OneofInt32:
+ msg.oneofInt32 = 100;
+ break;
+ case Message2_O_OneOfCase_OneofInt64:
+ msg.oneofInt64 = 101;
+ break;
+ case Message2_O_OneOfCase_OneofUint32:
+ msg.oneofUint32 = 102;
+ break;
+ case Message2_O_OneOfCase_OneofUint64:
+ msg.oneofUint64 = 103;
+ break;
+ case Message2_O_OneOfCase_OneofSint32:
+ msg.oneofSint32 = 104;
+ break;
+ case Message2_O_OneOfCase_OneofSint64:
+ msg.oneofSint64 = 105;
+ break;
+ case Message2_O_OneOfCase_OneofFixed32:
+ msg.oneofFixed32 = 106;
+ break;
+ case Message2_O_OneOfCase_OneofFixed64:
+ msg.oneofFixed64 = 107;
+ break;
+ case Message2_O_OneOfCase_OneofSfixed32:
+ msg.oneofSfixed32 = 108;
+ break;
+ case Message2_O_OneOfCase_OneofSfixed64:
+ msg.oneofSfixed64 = 109;
+ break;
+ case Message2_O_OneOfCase_OneofFloat:
+ msg.oneofFloat = 110.0f;
+ break;
+ case Message2_O_OneOfCase_OneofDouble:
+ msg.oneofDouble = 111.0;
+ break;
+ case Message2_O_OneOfCase_OneofBool:
+ msg.oneofBool = YES;
+ break;
+ case Message2_O_OneOfCase_OneofString:
+ msg.oneofString = oneofStringDefault;
+ break;
+ case Message2_O_OneOfCase_OneofBytes:
+ msg.oneofBytes = oneofBytesDefault;
+ break;
+ case Message2_O_OneOfCase_OneofEnum:
+ msg.oneofEnum = Message3_Enum_Baz;
+ break;
+ default:
+ XCTFail(@"shouldn't happen, loop: %zd, value: %d", i, values[i]);
+ break;
+ }
+
+ // Should be set to the correct case.
+ XCTAssertEqual(msg.oOneOfCase, values[i], "Loop: %zd", i);
+
+ // Confirm everything is the defaults.
+ XCTAssertEqual(msg.oneofInt32, 100, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofInt64, 101, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofUint32, 102U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofUint64, 103U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSint32, 104, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSint64, 105, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFixed32, 106U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFixed64, 107U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSfixed32, 108, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSfixed64, 109, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFloat, 110.0f, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofDouble, 111.0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofBool, YES, "Loop: %zd", i);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault, "Loop: %zd", i);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault, "Loop: %zd", i);
+ // Skip group, no default to consider.
+ // Skip message, no default to consider.
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Baz, "Loop: %zd", i);
+ }
+
+ // We special case nil on string, data, group, and message, ensure they work
+ // as expected. i.e. - it clears the case.
+ msg.oneofString = nil;
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_GPBUnsetOneOfCase);
+ msg.oneofBytes = nil;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_GPBUnsetOneOfCase);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ msg.oneofGroup = nil;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_GPBUnsetOneOfCase);
+ XCTAssertNotNil(msg.oneofGroup);
+ msg.oneofMessage = nil;
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_GPBUnsetOneOfCase);
+ XCTAssertNotNil(msg.oneofMessage);
+
+ [msg release];
+}
+
+- (void)testProto3OneofSetToZero {
+
+ // Normally setting a proto3 field to the zero value should result in it being
+ // reset/cleared. But in a oneof, it still gets recored so it can go out
+ // over the wire and the other side can see what was set in the oneof.
+
+ NSString *oneofStringDefault = @"";
+ NSData *oneofBytesDefault = [NSData data];
+
+ Message3 *msg = [[Message3 alloc] init];
+
+ uint32_t values[] = {
+ Message3_O_OneOfCase_OneofInt32,
+ Message3_O_OneOfCase_OneofInt64,
+ Message3_O_OneOfCase_OneofUint32,
+ Message3_O_OneOfCase_OneofUint64,
+ Message3_O_OneOfCase_OneofSint32,
+ Message3_O_OneOfCase_OneofSint64,
+ Message3_O_OneOfCase_OneofFixed32,
+ Message3_O_OneOfCase_OneofFixed64,
+ Message3_O_OneOfCase_OneofSfixed32,
+ Message3_O_OneOfCase_OneofSfixed64,
+ Message3_O_OneOfCase_OneofFloat,
+ Message3_O_OneOfCase_OneofDouble,
+ Message3_O_OneOfCase_OneofBool,
+ Message3_O_OneOfCase_OneofString,
+ Message3_O_OneOfCase_OneofBytes,
+ Message3_O_OneOfCase_OneofMessage,
+ Message3_O_OneOfCase_OneofEnum,
+ };
+
+ for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) {
+ switch (values[i]) {
+ case Message3_O_OneOfCase_OneofInt32:
+ msg.oneofInt32 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofInt64:
+ msg.oneofInt64 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofUint32:
+ msg.oneofUint32 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofUint64:
+ msg.oneofUint64 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofSint32:
+ msg.oneofSint32 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofSint64:
+ msg.oneofSint64 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofFixed32:
+ msg.oneofFixed32 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofFixed64:
+ msg.oneofFixed64 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofSfixed32:
+ msg.oneofSfixed32 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofSfixed64:
+ msg.oneofSfixed64 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofFloat:
+ msg.oneofFloat = 0.0f;
+ break;
+ case Message3_O_OneOfCase_OneofDouble:
+ msg.oneofDouble = 0.0;
+ break;
+ case Message3_O_OneOfCase_OneofBool:
+ msg.oneofBool = NO;
+ break;
+ case Message3_O_OneOfCase_OneofString:
+ msg.oneofString = oneofStringDefault;
+ break;
+ case Message3_O_OneOfCase_OneofBytes:
+ msg.oneofBytes = oneofBytesDefault;
+ break;
+ case Message3_O_OneOfCase_OneofMessage:
+ msg.oneofMessage.optionalInt32 = 0;
+ break;
+ case Message3_O_OneOfCase_OneofEnum:
+ msg.oneofEnum = Message3_Enum_Foo;
+ break;
+ default:
+ XCTFail(@"shouldn't happen, loop: %zd, value: %d", i, values[i]);
+ break;
+ }
+
+ // Should be set to the correct case.
+ XCTAssertEqual(msg.oOneOfCase, values[i], "Loop: %zd", i);
+
+ // Confirm everything is still zeros.
+ XCTAssertEqual(msg.oneofInt32, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofInt64, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofUint32, 0U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofUint64, 0U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSint32, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSint64, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFixed32, 0U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFixed64, 0U, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSfixed32, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofSfixed64, 0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofFloat, 0.0f, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofDouble, 0.0, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofBool, NO, "Loop: %zd", i);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault, "Loop: %zd", i);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault, "Loop: %zd", i);
+ XCTAssertNotNil(msg.oneofMessage, "Loop: %zd", i);
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum_Foo, "Loop: %zd", i);
+ }
+
+ // We special case nil on string, data, message, ensure they work as expected.
+ msg.oneofString = nil;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_GPBUnsetOneOfCase);
+ XCTAssertEqualObjects(msg.oneofString, oneofStringDefault);
+ msg.oneofBytes = nil;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_GPBUnsetOneOfCase);
+ XCTAssertEqualObjects(msg.oneofBytes, oneofBytesDefault);
+ msg.oneofMessage = nil;
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_GPBUnsetOneOfCase);
+ XCTAssertNotNil(msg.oneofMessage);
+
+ [msg release];
+}
+
+- (void)testCopyingMakesUniqueObjects {
+ const int repeatCount = 5;
+ TestAllTypes *msg1 = [TestAllTypes message];
+ [self setAllFields:msg1 repeatedCount:repeatCount];
+
+ TestAllTypes *msg2 = [[msg1 copy] autorelease];
+
+ XCTAssertNotEqual(msg1, msg2); // Ptr compare, new object.
+ XCTAssertEqualObjects(msg1, msg2); // Equal values.
+
+ // Pointer comparisions, different objects.
+
+ XCTAssertNotEqual(msg1.optionalGroup, msg2.optionalGroup);
+ XCTAssertNotEqual(msg1.optionalNestedMessage, msg2.optionalNestedMessage);
+ XCTAssertNotEqual(msg1.optionalForeignMessage, msg2.optionalForeignMessage);
+ XCTAssertNotEqual(msg1.optionalImportMessage, msg2.optionalImportMessage);
+
+ XCTAssertNotEqual(msg1.repeatedInt32Array, msg2.repeatedInt32Array);
+ XCTAssertNotEqual(msg1.repeatedInt64Array, msg2.repeatedInt64Array);
+ XCTAssertNotEqual(msg1.repeatedUint32Array, msg2.repeatedUint32Array);
+ XCTAssertNotEqual(msg1.repeatedUint64Array, msg2.repeatedUint64Array);
+ XCTAssertNotEqual(msg1.repeatedSint32Array, msg2.repeatedSint32Array);
+ XCTAssertNotEqual(msg1.repeatedSint64Array, msg2.repeatedSint64Array);
+ XCTAssertNotEqual(msg1.repeatedFixed32Array, msg2.repeatedFixed32Array);
+ XCTAssertNotEqual(msg1.repeatedFixed64Array, msg2.repeatedFixed64Array);
+ XCTAssertNotEqual(msg1.repeatedSfixed32Array, msg2.repeatedSfixed32Array);
+ XCTAssertNotEqual(msg1.repeatedSfixed64Array, msg2.repeatedSfixed64Array);
+ XCTAssertNotEqual(msg1.repeatedFloatArray, msg2.repeatedFloatArray);
+ XCTAssertNotEqual(msg1.repeatedDoubleArray, msg2.repeatedDoubleArray);
+ XCTAssertNotEqual(msg1.repeatedBoolArray, msg2.repeatedBoolArray);
+ XCTAssertNotEqual(msg1.repeatedStringArray, msg2.repeatedStringArray);
+ XCTAssertNotEqual(msg1.repeatedBytesArray, msg2.repeatedBytesArray);
+ XCTAssertNotEqual(msg1.repeatedGroupArray, msg2.repeatedGroupArray);
+ XCTAssertNotEqual(msg1.repeatedNestedMessageArray,
+ msg2.repeatedNestedMessageArray);
+ XCTAssertNotEqual(msg1.repeatedForeignMessageArray,
+ msg2.repeatedForeignMessageArray);
+ XCTAssertNotEqual(msg1.repeatedImportMessageArray,
+ msg2.repeatedImportMessageArray);
+ XCTAssertNotEqual(msg1.repeatedNestedEnumArray, msg2.repeatedNestedEnumArray);
+ XCTAssertNotEqual(msg1.repeatedForeignEnumArray,
+ msg2.repeatedForeignEnumArray);
+ XCTAssertNotEqual(msg1.repeatedImportEnumArray, msg2.repeatedImportEnumArray);
+ XCTAssertNotEqual(msg1.repeatedStringPieceArray,
+ msg2.repeatedStringPieceArray);
+ XCTAssertNotEqual(msg1.repeatedCordArray, msg2.repeatedCordArray);
+
+ for (int i = 0; i < repeatCount; i++) {
+ XCTAssertNotEqual(msg1.repeatedNestedMessageArray[i],
+ msg2.repeatedNestedMessageArray[i]);
+ XCTAssertNotEqual(msg1.repeatedForeignMessageArray[i],
+ msg2.repeatedForeignMessageArray[i]);
+ XCTAssertNotEqual(msg1.repeatedImportMessageArray[i],
+ msg2.repeatedImportMessageArray[i]);
+ }
+}
+
+- (void)testCopyingMapsMakesUniqueObjects {
+ TestMap *msg1 = [TestMap message];
+ [self setAllMapFields:msg1 numEntries:5];
+
+ TestMap *msg2 = [[msg1 copy] autorelease];
+
+ XCTAssertNotEqual(msg1, msg2); // Ptr compare, new object.
+ XCTAssertEqualObjects(msg1, msg2); // Equal values.
+
+ // Pointer comparisions, different objects.
+ XCTAssertNotEqual(msg1.mapInt32Int32, msg2.mapInt32Int32);
+ XCTAssertNotEqual(msg1.mapInt64Int64, msg2.mapInt64Int64);
+ XCTAssertNotEqual(msg1.mapUint32Uint32, msg2.mapUint32Uint32);
+ XCTAssertNotEqual(msg1.mapUint64Uint64, msg2.mapUint64Uint64);
+ XCTAssertNotEqual(msg1.mapSint32Sint32, msg2.mapSint32Sint32);
+ XCTAssertNotEqual(msg1.mapSint64Sint64, msg2.mapSint64Sint64);
+ XCTAssertNotEqual(msg1.mapFixed32Fixed32, msg2.mapFixed32Fixed32);
+ XCTAssertNotEqual(msg1.mapFixed64Fixed64, msg2.mapFixed64Fixed64);
+ XCTAssertNotEqual(msg1.mapSfixed32Sfixed32, msg2.mapSfixed32Sfixed32);
+ XCTAssertNotEqual(msg1.mapSfixed64Sfixed64, msg2.mapSfixed64Sfixed64);
+ XCTAssertNotEqual(msg1.mapInt32Float, msg2.mapInt32Float);
+ XCTAssertNotEqual(msg1.mapInt32Double, msg2.mapInt32Double);
+ XCTAssertNotEqual(msg1.mapBoolBool, msg2.mapBoolBool);
+ XCTAssertNotEqual(msg1.mapStringString, msg2.mapStringString);
+ XCTAssertNotEqual(msg1.mapInt32Bytes, msg2.mapInt32Bytes);
+ XCTAssertNotEqual(msg1.mapInt32Enum, msg2.mapInt32Enum);
+ XCTAssertNotEqual(msg1.mapInt32ForeignMessage, msg2.mapInt32ForeignMessage);
+
+ // Ensure the messages are unique per map.
+ [msg1.mapInt32ForeignMessage
+ enumerateKeysAndObjectsUsingBlock:^(int32_t key, id value, BOOL *stop) {
+#pragma unused(stop)
+ ForeignMessage *subMsg2 = [msg2.mapInt32ForeignMessage objectForKey:key];
+ XCTAssertNotEqual(value, subMsg2); // Ptr compare, new object.
+ }];
+}
+
+- (void)test_GPBGetMessageRepeatedField {
+ TestAllTypes *message = [TestAllTypes message];
+ GPBFieldDescriptor *fieldDescriptor = [[message descriptor] fieldWithName:@"repeatedStringArray"];
+ XCTAssertNotNil(fieldDescriptor);
+ NSMutableArray *fieldArray = GPBGetMessageRepeatedField(message, fieldDescriptor);
+ XCTAssertNotNil(fieldArray); // Should have autocreated.
+ XCTAssertTrue(fieldArray == message.repeatedStringArray); // Same pointer
+}
+
+- (void)test_GPBSetMessageRepeatedField {
+ TestAllTypes *message = [TestAllTypes message];
+ GPBFieldDescriptor *fieldDescriptor = [[message descriptor] fieldWithName:@"repeatedStringArray"];
+ XCTAssertNotNil(fieldDescriptor);
+
+ NSMutableArray *fieldArray = [NSMutableArray arrayWithObject:@"foo"];
+ GPBSetMessageRepeatedField(message, fieldDescriptor, fieldArray);
+ XCTAssertTrue(fieldArray == message.repeatedStringArray); // Same pointer
+ XCTAssertEqualObjects(@"foo", message.repeatedStringArray.firstObject);
+}
+
+- (void)test_GPBGetMessageMapField {
+ TestMap *message = [TestMap message];
+ GPBFieldDescriptor *fieldDescriptor = [[message descriptor] fieldWithName:@"mapStringString"];
+ XCTAssertNotNil(fieldDescriptor);
+ NSMutableDictionary *fieldMap = GPBGetMessageMapField(message, fieldDescriptor);
+ XCTAssertNotNil(fieldMap); // Should have autocreated.
+ XCTAssertTrue(fieldMap == message.mapStringString); // Same pointer
+}
+
+- (void)test_GPBSetMessageMapField {
+ TestMap *message = [TestMap message];
+ GPBFieldDescriptor *fieldDescriptor = [[message descriptor] fieldWithName:@"mapStringString"];
+ XCTAssertNotNil(fieldDescriptor);
+
+ NSMutableDictionary *fieldMap = [NSMutableDictionary dictionaryWithObject:@"bar" forKey:@"foo"];
+ GPBSetMessageMapField(message, fieldDescriptor, fieldMap);
+ XCTAssertTrue(fieldMap == message.mapStringString); // Same pointer
+ XCTAssertEqualObjects(@"bar", message.mapStringString[@"foo"]);
+}
+
+#pragma mark - Subset from from map_tests.cc
+
+// TEST(GeneratedMapFieldTest, IsInitialized)
+- (void)testMap_IsInitialized {
+ TestRequiredMessageMap *msg = [[TestRequiredMessageMap alloc] init];
+
+ // Add an uninitialized message.
+ TestRequired *subMsg = [[TestRequired alloc] init];
+ [msg.mapField setObject:subMsg forKey:0];
+ XCTAssertFalse(msg.initialized);
+
+ // Initialize uninitialized message
+ subMsg.a = 0;
+ subMsg.b = 0;
+ subMsg.c = 0;
+ XCTAssertTrue(msg.initialized);
+
+ [subMsg release];
+ [msg release];
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBMessageTests+Serialization.m b/third_party/protobuf/objectivec/Tests/GPBMessageTests+Serialization.m
new file mode 100644
index 0000000000..3c861fefdd
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBMessageTests+Serialization.m
@@ -0,0 +1,1210 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import <objc/runtime.h>
+
+#import "GPBMessage.h"
+
+#import "google/protobuf/MapProto2Unittest.pbobjc.h"
+#import "google/protobuf/MapUnittest.pbobjc.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestDropUnknownFields.pbobjc.h"
+#import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h"
+
+static NSData *DataFromCStr(const char *str) {
+ return [NSData dataWithBytes:str length:strlen(str)];
+}
+
+@interface MessageSerializationTests : GPBTestCase
+@end
+
+@implementation MessageSerializationTests
+
+// TODO(thomasvl): Pull tests over from GPBMessageTests that are serialization
+// specific.
+
+- (void)testProto3SerializationHandlingDefaults {
+ // Proto2 covered in other tests.
+
+ Message3 *msg = [[Message3 alloc] init];
+
+ // Add defaults, no output.
+
+ NSData *data = [msg data];
+ XCTAssertEqual([data length], 0U);
+
+ // All zeros, still nothing.
+
+ msg.optionalInt32 = 0;
+ msg.optionalInt64 = 0;
+ msg.optionalUint32 = 0;
+ msg.optionalUint64 = 0;
+ msg.optionalSint32 = 0;
+ msg.optionalSint64 = 0;
+ msg.optionalFixed32 = 0;
+ msg.optionalFixed64 = 0;
+ msg.optionalSfixed32 = 0;
+ msg.optionalSfixed64 = 0;
+ msg.optionalFloat = 0.0f;
+ msg.optionalDouble = 0.0;
+ msg.optionalBool = NO;
+ msg.optionalString = @"";
+ msg.optionalBytes = [NSData data];
+ msg.optionalEnum = Message3_Enum_Foo; // first value
+
+ data = [msg data];
+ XCTAssertEqual([data length], 0U);
+
+ // The two that also take nil as nothing.
+
+ msg.optionalString = nil;
+ msg.optionalBytes = nil;
+
+ data = [msg data];
+ XCTAssertEqual([data length], 0U);
+
+ // Set one field...
+
+ msg.optionalInt32 = 1;
+
+ data = [msg data];
+ const uint8_t expectedBytes[] = {0x08, 0x01};
+ NSData *expected = [NSData dataWithBytes:expectedBytes length:2];
+ XCTAssertEqualObjects(data, expected);
+
+ // Back to zero...
+
+ msg.optionalInt32 = 0;
+
+ data = [msg data];
+ XCTAssertEqual([data length], 0U);
+
+ [msg release];
+}
+
+- (void)testProto3DroppingUnknownFields {
+ DropUnknownsFooWithExtraFields *fooWithExtras =
+ [[DropUnknownsFooWithExtraFields alloc] init];
+
+ fooWithExtras.int32Value = 1;
+ fooWithExtras.enumValue = DropUnknownsFooWithExtraFields_NestedEnum_Baz;
+ fooWithExtras.extraInt32Value = 2;
+
+ NSData *data = [fooWithExtras data];
+ XCTAssertNotNil(data);
+ DropUnknownsFoo *foo = [DropUnknownsFoo parseFromData:data error:NULL];
+
+ XCTAssertEqual(foo.int32Value, 1);
+ XCTAssertEqual(foo.enumValue, DropUnknownsFoo_NestedEnum_Baz);
+ // Nothing should end up in the unknowns.
+ XCTAssertEqual([foo.unknownFields countOfFields], 0U);
+
+ [fooWithExtras release];
+ data = [foo data];
+ fooWithExtras =
+ [DropUnknownsFooWithExtraFields parseFromData:data error:NULL];
+ XCTAssertEqual(fooWithExtras.int32Value, 1);
+ XCTAssertEqual(fooWithExtras.enumValue,
+ DropUnknownsFooWithExtraFields_NestedEnum_Baz);
+ // And the extra value is gone (back to the default).
+ XCTAssertEqual(fooWithExtras.extraInt32Value, 0);
+ XCTAssertEqual([foo.unknownFields countOfFields], 0U);
+}
+
+- (void)testProto2UnknownEnumToUnknownField {
+ Message3 *orig = [[Message3 alloc] init];
+
+ orig.optionalEnum = Message3_Enum_Extra3;
+ orig.repeatedEnumArray =
+ [GPBEnumArray arrayWithValidationFunction:Message3_Enum_IsValidValue
+ rawValue:Message3_Enum_Extra3];
+ orig.oneofEnum = Message3_Enum_Extra3;
+
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [[Message2 alloc] initWithData:data error:NULL];
+
+ // None of the fields should be set.
+
+ XCTAssertFalse(msg.hasOptionalEnum);
+ XCTAssertEqual(msg.repeatedEnumArray.count, 0U);
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_GPBUnsetOneOfCase);
+
+ // All the values should be in unknown fields.
+
+ GPBUnknownFieldSet *unknownFields = msg.unknownFields;
+
+ XCTAssertEqual([unknownFields countOfFields], 3U);
+ XCTAssertTrue([unknownFields hasField:Message2_FieldNumber_OptionalEnum]);
+ XCTAssertTrue(
+ [unknownFields hasField:Message2_FieldNumber_RepeatedEnumArray]);
+ XCTAssertTrue([unknownFields hasField:Message2_FieldNumber_OneofEnum]);
+
+ GPBUnknownField *field =
+ [unknownFields getField:Message2_FieldNumber_OptionalEnum];
+ XCTAssertEqual(field.varintList.count, 1U);
+ XCTAssertEqual([field.varintList valueAtIndex:0],
+ (uint64_t)Message3_Enum_Extra3);
+
+ field = [unknownFields getField:Message2_FieldNumber_RepeatedEnumArray];
+ XCTAssertEqual(field.varintList.count, 1U);
+ XCTAssertEqual([field.varintList valueAtIndex:0], (uint64_t)Message3_Enum_Extra3);
+
+ field = [unknownFields getField:Message2_FieldNumber_OneofEnum];
+ XCTAssertEqual(field.varintList.count, 1U);
+ XCTAssertEqual([field.varintList valueAtIndex:0],
+ (uint64_t)Message3_Enum_Extra3);
+
+ [msg release];
+ [orig release];
+}
+
+- (void)testProto3UnknownEnumPreserving {
+ UnknownEnumsMyMessagePlusExtra *orig =
+ [UnknownEnumsMyMessagePlusExtra message];
+
+ orig.e = UnknownEnumsMyEnumPlusExtra_EExtra;
+ orig.repeatedEArray = [GPBEnumArray
+ arrayWithValidationFunction:UnknownEnumsMyEnumPlusExtra_IsValidValue
+ rawValue:UnknownEnumsMyEnumPlusExtra_EExtra];
+ orig.repeatedPackedEArray = [GPBEnumArray
+ arrayWithValidationFunction:UnknownEnumsMyEnumPlusExtra_IsValidValue
+ rawValue:UnknownEnumsMyEnumPlusExtra_EExtra];
+ orig.oneofE1 = UnknownEnumsMyEnumPlusExtra_EExtra;
+
+ // Everything should be there via raw values.
+
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ UnknownEnumsMyMessage *msg =
+ [UnknownEnumsMyMessage parseFromData:data error:NULL];
+
+ XCTAssertEqual(msg.e, UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual(UnknownEnumsMyMessage_E_RawValue(msg),
+ UnknownEnumsMyEnumPlusExtra_EExtra);
+ XCTAssertEqual(msg.repeatedEArray.count, 1U);
+ XCTAssertEqual([msg.repeatedEArray valueAtIndex:0],
+ UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([msg.repeatedEArray rawValueAtIndex:0],
+ (UnknownEnumsMyEnum)UnknownEnumsMyEnumPlusExtra_EExtra);
+ XCTAssertEqual(msg.repeatedPackedEArray.count, 1U);
+ XCTAssertEqual([msg.repeatedPackedEArray valueAtIndex:0],
+ UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual([msg.repeatedPackedEArray rawValueAtIndex:0],
+ (UnknownEnumsMyEnum)UnknownEnumsMyEnumPlusExtra_EExtra);
+ XCTAssertEqual(msg.oneofE1,
+ UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
+ XCTAssertEqual(UnknownEnumsMyMessage_OneofE1_RawValue(msg),
+ UnknownEnumsMyEnumPlusExtra_EExtra);
+
+ // Everything should go out and come back.
+
+ data = [msg data];
+ orig = [UnknownEnumsMyMessagePlusExtra parseFromData:data error:NULL];
+
+ XCTAssertEqual(orig.e, UnknownEnumsMyEnumPlusExtra_EExtra);
+ XCTAssertEqual(orig.repeatedEArray.count, 1U);
+ XCTAssertEqual([orig.repeatedEArray valueAtIndex:0],
+ UnknownEnumsMyEnumPlusExtra_EExtra);
+ XCTAssertEqual(orig.repeatedPackedEArray.count, 1U);
+ XCTAssertEqual([orig.repeatedPackedEArray valueAtIndex:0],
+ UnknownEnumsMyEnumPlusExtra_EExtra);
+ XCTAssertEqual(orig.oneofE1, UnknownEnumsMyEnumPlusExtra_EExtra);
+}
+
+//%PDDM-DEFINE TEST_ROUNDTRIP_ONEOF(MESSAGE, FIELD, VALUE)
+//%TEST_ROUNDTRIP_ONEOF_ADV(MESSAGE, FIELD, VALUE, )
+//%PDDM-DEFINE TEST_ROUNDTRIP_ONEOF_ADV(MESSAGE, FIELD, VALUE, EQ_SUFFIX)
+//% { // oneof##FIELD
+//% MESSAGE *orig = [[MESSAGE alloc] init];
+//% orig.oneof##FIELD = VALUE;
+//% XCTAssertEqual(orig.oOneOfCase, MESSAGE##_O_OneOfCase_Oneof##FIELD);
+//% NSData *data = [orig data];
+//% XCTAssertNotNil(data);
+//% MESSAGE *msg = [MESSAGE parseFromData:data error:NULL];
+//% XCTAssertEqual(msg.oOneOfCase, MESSAGE##_O_OneOfCase_Oneof##FIELD);
+//% XCTAssertEqual##EQ_SUFFIX(msg.oneof##FIELD, VALUE);
+//% [orig release];
+//% }
+//%
+//%PDDM-DEFINE TEST_ROUNDTRIP_ONEOFS(SYNTAX, BOOL_NON_DEFAULT)
+//%- (void)testProto##SYNTAX##RoundTripOneof {
+//%
+//%GROUP_INIT##SYNTAX() Message##SYNTAX *subMessage = [[Message##SYNTAX alloc] init];
+//% XCTAssertNotNil(subMessage);
+//% subMessage.optionalInt32 = 666;
+//%
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Int32, 1)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Int64, 2)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Uint32, 3U)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Uint64, 4U)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Sint32, 5)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Sint64, 6)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Fixed32, 7U)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Fixed64, 8U)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Sfixed32, 9)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Sfixed64, 10)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Float, 11.0f)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Double, 12.0)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Bool, BOOL_NON_DEFAULT)
+//%TEST_ROUNDTRIP_ONEOF_ADV(Message##SYNTAX, String, @"foo", Objects)
+//%TEST_ROUNDTRIP_ONEOF_ADV(Message##SYNTAX, Bytes, [@"bar" dataUsingEncoding:NSUTF8StringEncoding], Objects)
+//%GROUP_TEST##SYNTAX()TEST_ROUNDTRIP_ONEOF_ADV(Message##SYNTAX, Message, subMessage, Objects)
+//%TEST_ROUNDTRIP_ONEOF(Message##SYNTAX, Enum, Message2_Enum_Bar)
+//%GROUP_CLEANUP##SYNTAX() [subMessage release];
+//%}
+//%
+//%PDDM-DEFINE GROUP_INIT2()
+//% Message2_OneofGroup *group = [[Message2_OneofGroup alloc] init];
+//% XCTAssertNotNil(group);
+//% group.a = 777;
+//%
+//%PDDM-DEFINE GROUP_CLEANUP2()
+//% [group release];
+//%
+//%PDDM-DEFINE GROUP_TEST2()
+//%TEST_ROUNDTRIP_ONEOF_ADV(Message2, Group, group, Objects)
+//%
+//%PDDM-DEFINE GROUP_INIT3()
+// Empty
+//%PDDM-DEFINE GROUP_CLEANUP3()
+// Empty
+//%PDDM-DEFINE GROUP_TEST3()
+//% // Not "group" in proto3.
+//%
+//%
+//%PDDM-EXPAND TEST_ROUNDTRIP_ONEOFS(2, NO)
+// This block of code is generated, do not edit it directly.
+
+- (void)testProto2RoundTripOneof {
+
+ Message2_OneofGroup *group = [[Message2_OneofGroup alloc] init];
+ XCTAssertNotNil(group);
+ group.a = 777;
+ Message2 *subMessage = [[Message2 alloc] init];
+ XCTAssertNotNil(subMessage);
+ subMessage.optionalInt32 = 666;
+
+ { // oneofInt32
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofInt32 = 1;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofInt32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofInt32);
+ XCTAssertEqual(msg.oneofInt32, 1);
+ [orig release];
+ }
+
+ { // oneofInt64
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofInt64 = 2;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofInt64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofInt64);
+ XCTAssertEqual(msg.oneofInt64, 2);
+ [orig release];
+ }
+
+ { // oneofUint32
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofUint32 = 3U;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofUint32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofUint32);
+ XCTAssertEqual(msg.oneofUint32, 3U);
+ [orig release];
+ }
+
+ { // oneofUint64
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofUint64 = 4U;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofUint64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofUint64);
+ XCTAssertEqual(msg.oneofUint64, 4U);
+ [orig release];
+ }
+
+ { // oneofSint32
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofSint32 = 5;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofSint32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSint32);
+ XCTAssertEqual(msg.oneofSint32, 5);
+ [orig release];
+ }
+
+ { // oneofSint64
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofSint64 = 6;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofSint64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSint64);
+ XCTAssertEqual(msg.oneofSint64, 6);
+ [orig release];
+ }
+
+ { // oneofFixed32
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofFixed32 = 7U;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofFixed32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFixed32);
+ XCTAssertEqual(msg.oneofFixed32, 7U);
+ [orig release];
+ }
+
+ { // oneofFixed64
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofFixed64 = 8U;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofFixed64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFixed64);
+ XCTAssertEqual(msg.oneofFixed64, 8U);
+ [orig release];
+ }
+
+ { // oneofSfixed32
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofSfixed32 = 9;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofSfixed32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSfixed32);
+ XCTAssertEqual(msg.oneofSfixed32, 9);
+ [orig release];
+ }
+
+ { // oneofSfixed64
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofSfixed64 = 10;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofSfixed64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSfixed64);
+ XCTAssertEqual(msg.oneofSfixed64, 10);
+ [orig release];
+ }
+
+ { // oneofFloat
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofFloat = 11.0f;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofFloat);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFloat);
+ XCTAssertEqual(msg.oneofFloat, 11.0f);
+ [orig release];
+ }
+
+ { // oneofDouble
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofDouble = 12.0;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofDouble);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofDouble);
+ XCTAssertEqual(msg.oneofDouble, 12.0);
+ [orig release];
+ }
+
+ { // oneofBool
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofBool = NO;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofBool);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofBool);
+ XCTAssertEqual(msg.oneofBool, NO);
+ [orig release];
+ }
+
+ { // oneofString
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofString = @"foo";
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofString);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofString);
+ XCTAssertEqualObjects(msg.oneofString, @"foo");
+ [orig release];
+ }
+
+ { // oneofBytes
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofBytes);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofBytes);
+ XCTAssertEqualObjects(msg.oneofBytes, [@"bar" dataUsingEncoding:NSUTF8StringEncoding]);
+ [orig release];
+ }
+
+ { // oneofGroup
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofGroup = group;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofGroup);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofGroup);
+ XCTAssertEqualObjects(msg.oneofGroup, group);
+ [orig release];
+ }
+
+ { // oneofMessage
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofMessage = subMessage;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofMessage);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofMessage);
+ XCTAssertEqualObjects(msg.oneofMessage, subMessage);
+ [orig release];
+ }
+
+ { // oneofEnum
+ Message2 *orig = [[Message2 alloc] init];
+ orig.oneofEnum = Message2_Enum_Bar;
+ XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofEnum);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofEnum);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Bar);
+ [orig release];
+ }
+
+ [group release];
+ [subMessage release];
+}
+
+//%PDDM-EXPAND TEST_ROUNDTRIP_ONEOFS(3, YES)
+// This block of code is generated, do not edit it directly.
+
+- (void)testProto3RoundTripOneof {
+
+ Message3 *subMessage = [[Message3 alloc] init];
+ XCTAssertNotNil(subMessage);
+ subMessage.optionalInt32 = 666;
+
+ { // oneofInt32
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofInt32 = 1;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofInt32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofInt32);
+ XCTAssertEqual(msg.oneofInt32, 1);
+ [orig release];
+ }
+
+ { // oneofInt64
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofInt64 = 2;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofInt64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofInt64);
+ XCTAssertEqual(msg.oneofInt64, 2);
+ [orig release];
+ }
+
+ { // oneofUint32
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofUint32 = 3U;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofUint32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofUint32);
+ XCTAssertEqual(msg.oneofUint32, 3U);
+ [orig release];
+ }
+
+ { // oneofUint64
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofUint64 = 4U;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofUint64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofUint64);
+ XCTAssertEqual(msg.oneofUint64, 4U);
+ [orig release];
+ }
+
+ { // oneofSint32
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofSint32 = 5;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofSint32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSint32);
+ XCTAssertEqual(msg.oneofSint32, 5);
+ [orig release];
+ }
+
+ { // oneofSint64
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofSint64 = 6;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofSint64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSint64);
+ XCTAssertEqual(msg.oneofSint64, 6);
+ [orig release];
+ }
+
+ { // oneofFixed32
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofFixed32 = 7U;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofFixed32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFixed32);
+ XCTAssertEqual(msg.oneofFixed32, 7U);
+ [orig release];
+ }
+
+ { // oneofFixed64
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofFixed64 = 8U;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofFixed64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFixed64);
+ XCTAssertEqual(msg.oneofFixed64, 8U);
+ [orig release];
+ }
+
+ { // oneofSfixed32
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofSfixed32 = 9;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofSfixed32);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSfixed32);
+ XCTAssertEqual(msg.oneofSfixed32, 9);
+ [orig release];
+ }
+
+ { // oneofSfixed64
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofSfixed64 = 10;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofSfixed64);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSfixed64);
+ XCTAssertEqual(msg.oneofSfixed64, 10);
+ [orig release];
+ }
+
+ { // oneofFloat
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofFloat = 11.0f;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofFloat);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFloat);
+ XCTAssertEqual(msg.oneofFloat, 11.0f);
+ [orig release];
+ }
+
+ { // oneofDouble
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofDouble = 12.0;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofDouble);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofDouble);
+ XCTAssertEqual(msg.oneofDouble, 12.0);
+ [orig release];
+ }
+
+ { // oneofBool
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofBool = YES;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofBool);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofBool);
+ XCTAssertEqual(msg.oneofBool, YES);
+ [orig release];
+ }
+
+ { // oneofString
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofString = @"foo";
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofString);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofString);
+ XCTAssertEqualObjects(msg.oneofString, @"foo");
+ [orig release];
+ }
+
+ { // oneofBytes
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofBytes);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofBytes);
+ XCTAssertEqualObjects(msg.oneofBytes, [@"bar" dataUsingEncoding:NSUTF8StringEncoding]);
+ [orig release];
+ }
+
+ // Not "group" in proto3.
+
+ { // oneofMessage
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofMessage = subMessage;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofMessage);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofMessage);
+ XCTAssertEqualObjects(msg.oneofMessage, subMessage);
+ [orig release];
+ }
+
+ { // oneofEnum
+ Message3 *orig = [[Message3 alloc] init];
+ orig.oneofEnum = Message2_Enum_Bar;
+ XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofEnum);
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofEnum);
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum_Bar);
+ [orig release];
+ }
+
+ [subMessage release];
+}
+
+//%PDDM-EXPAND-END (2 expansions)
+
+- (void)testPackedUnpackedMessageParsing {
+ // packed is optional, a repeated field should parse when packed or unpacked.
+
+ TestPackedTypes *packedOrig = [TestPackedTypes message];
+ TestUnpackedTypes *unpackedOrig = [TestUnpackedTypes message];
+ [self setPackedFields:packedOrig repeatedCount:4];
+ [self setUnpackedFields:unpackedOrig repeatedCount:4];
+
+ NSData *packedData = [packedOrig data];
+ NSData *unpackedData = [unpackedOrig data];
+ XCTAssertNotNil(packedData);
+ XCTAssertNotNil(unpackedData);
+ XCTAssertNotEqualObjects(packedData, unpackedData,
+ @"Data should differ (packed vs unpacked) use");
+
+ NSError *error = nil;
+ TestPackedTypes *packedParse =
+ [TestPackedTypes parseFromData:unpackedData error:&error];
+ XCTAssertNotNil(packedParse);
+ XCTAssertNil(error);
+ XCTAssertEqualObjects(packedParse, packedOrig);
+
+ error = nil;
+ TestUnpackedTypes *unpackedParsed =
+ [TestUnpackedTypes parseFromData:packedData error:&error];
+ XCTAssertNotNil(unpackedParsed);
+ XCTAssertNil(error);
+ XCTAssertEqualObjects(unpackedParsed, unpackedOrig);
+}
+
+- (void)testPackedUnpackedExtensionParsing {
+ // packed is optional, a repeated extension should parse when packed or
+ // unpacked.
+
+ TestPackedExtensions *packedOrig = [TestPackedExtensions message];
+ TestUnpackedExtensions *unpackedOrig = [TestUnpackedExtensions message];
+ [self setPackedExtensions:packedOrig repeatedCount:kGPBDefaultRepeatCount];
+ [self setUnpackedExtensions:unpackedOrig repeatedCount:kGPBDefaultRepeatCount];
+
+ NSData *packedData = [packedOrig data];
+ NSData *unpackedData = [unpackedOrig data];
+ XCTAssertNotNil(packedData);
+ XCTAssertNotNil(unpackedData);
+ XCTAssertNotEqualObjects(packedData, unpackedData,
+ @"Data should differ (packed vs unpacked) use");
+
+ NSError *error = nil;
+ TestPackedExtensions *packedParse =
+ [TestPackedExtensions parseFromData:unpackedData
+ extensionRegistry:[UnittestRoot extensionRegistry]
+ error:&error];
+ XCTAssertNotNil(packedParse);
+ XCTAssertNil(error);
+ XCTAssertEqualObjects(packedParse, packedOrig);
+
+ error = nil;
+ TestUnpackedExtensions *unpackedParsed =
+ [TestUnpackedExtensions parseFromData:packedData
+ extensionRegistry:[UnittestRoot extensionRegistry]
+ error:&error];
+ XCTAssertNotNil(unpackedParsed);
+ XCTAssertNil(error);
+ XCTAssertEqualObjects(unpackedParsed, unpackedOrig);
+}
+
+- (void)testPackedExtensionVsFieldParsing {
+ // Extensions and fields end up on the wire the same way, so they can parse
+ // each other.
+
+ TestPackedTypes *fieldsOrig = [TestPackedTypes message];
+ TestPackedExtensions *extsOrig = [TestPackedExtensions message];
+ [self setPackedFields:fieldsOrig repeatedCount:kGPBDefaultRepeatCount];
+ [self setPackedExtensions:extsOrig repeatedCount:kGPBDefaultRepeatCount];
+
+ NSData *fieldsData = [fieldsOrig data];
+ NSData *extsData = [extsOrig data];
+ XCTAssertNotNil(fieldsData);
+ XCTAssertNotNil(extsData);
+ XCTAssertEqualObjects(fieldsData, extsData);
+
+ NSError *error = nil;
+ TestPackedTypes *fieldsParse =
+ [TestPackedTypes parseFromData:extsData error:&error];
+ XCTAssertNotNil(fieldsParse);
+ XCTAssertNil(error);
+ XCTAssertEqualObjects(fieldsParse, fieldsOrig);
+
+ error = nil;
+ TestPackedExtensions *extsParse =
+ [TestPackedExtensions parseFromData:fieldsData
+ extensionRegistry:[UnittestRoot extensionRegistry]
+ error:&error];
+ XCTAssertNotNil(extsParse);
+ XCTAssertNil(error);
+ XCTAssertEqualObjects(extsParse, extsOrig);
+}
+
+- (void)testUnpackedExtensionVsFieldParsing {
+ // Extensions and fields end up on the wire the same way, so they can parse
+ // each other.
+
+ TestUnpackedTypes *fieldsOrig = [TestUnpackedTypes message];
+ TestUnpackedExtensions *extsOrig = [TestUnpackedExtensions message];
+ [self setUnpackedFields:fieldsOrig repeatedCount:3];
+ [self setUnpackedExtensions:extsOrig repeatedCount:3];
+
+ NSData *fieldsData = [fieldsOrig data];
+ NSData *extsData = [extsOrig data];
+ XCTAssertNotNil(fieldsData);
+ XCTAssertNotNil(extsData);
+ XCTAssertEqualObjects(fieldsData, extsData);
+
+ TestUnpackedTypes *fieldsParse =
+ [TestUnpackedTypes parseFromData:extsData error:NULL];
+ XCTAssertNotNil(fieldsParse);
+ XCTAssertEqualObjects(fieldsParse, fieldsOrig);
+
+ TestUnpackedExtensions *extsParse =
+ [TestUnpackedExtensions parseFromData:fieldsData
+ extensionRegistry:[UnittestRoot extensionRegistry]
+ error:NULL];
+ XCTAssertNotNil(extsParse);
+ XCTAssertEqualObjects(extsParse, extsOrig);
+}
+
+- (void)testErrorSubsectionInvalidLimit {
+ NSData *data = DataFromCStr(
+ "\x0A\x08\x0A\x07\x12\x04\x72\x02\x4B\x50\x12\x04\x72\x02\x4B\x50");
+ NSError *error = nil;
+ NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data
+ error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain);
+ XCTAssertEqual(error.code, GPBCodedInputStreamErrorInvalidSubsectionLimit);
+}
+
+- (void)testErrorSubsectionLimitReached {
+ NSData *data = DataFromCStr("\x0A\x06\x12\x03\x72\x02\x4B\x50");
+ NSError *error = nil;
+ NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data
+ error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain);
+ XCTAssertEqual(error.code, GPBCodedInputStreamErrorSubsectionLimitReached);
+}
+
+- (void)testErrorInvalidVarint {
+ NSData *data = DataFromCStr("\x72\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF");
+ NSError *error = nil;
+ TestAllTypes *msg = [TestAllTypes parseFromData:data error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain);
+ XCTAssertEqual(error.code, GPBCodedInputStreamErrorInvalidVarInt);
+}
+
+- (void)testErrorInvalidUTF8 {
+ NSData *data = DataFromCStr("\x72\x04\xF4\xFF\xFF\xFF");
+ NSError *error = nil;
+ TestAllTypes *msg = [TestAllTypes parseFromData:data error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain);
+ XCTAssertEqual(error.code, GPBCodedInputStreamErrorInvalidUTF8);
+}
+
+- (void)testErrorInvalidSize {
+ NSData *data = DataFromCStr("\x72\x03\x4B\x50");
+ NSError *error = nil;
+ NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data
+ error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain);
+ XCTAssertEqual(error.code, GPBCodedInputStreamErrorInvalidSize);
+}
+
+- (void)testErrorInvalidTag {
+ NSData *data = DataFromCStr("\x0F");
+ NSError *error = nil;
+ NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data
+ error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain);
+ XCTAssertEqual(error.code, GPBCodedInputStreamErrorInvalidTag);
+}
+
+- (void)testErrorRecursionDepthReached {
+ NSData *data = DataFromCStr(
+ "\x0A\xF2\x01\x0A\xEF\x01\x0A\xEC\x01\x0A\xE9\x01\x0A\xE6\x01"
+ "\x0A\xE3\x01\x0A\xE0\x01\x0A\xDD\x01\x0A\xDA\x01\x0A\xD7\x01"
+ "\x0A\xD4\x01\x0A\xD1\x01\x0A\xCE\x01\x0A\xCB\x01\x0A\xC8\x01"
+ "\x0A\xC5\x01\x0A\xC2\x01\x0A\xBF\x01\x0A\xBC\x01\x0A\xB9\x01"
+ "\x0A\xB6\x01\x0A\xB3\x01\x0A\xB0\x01\x0A\xAD\x01\x0A\xAA\x01"
+ "\x0A\xA7\x01\x0A\xA4\x01\x0A\xA1\x01\x0A\x9E\x01\x0A\x9B\x01"
+ "\x0A\x98\x01\x0A\x95\x01\x0A\x92\x01\x0A\x8F\x01\x0A\x8C\x01"
+ "\x0A\x89\x01\x0A\x86\x01\x0A\x83\x01\x0A\x80\x01\x0A\x7E"
+ "\x0A\x7C\x0A\x7A\x0A\x78\x0A\x76\x0A\x74\x0A\x72\x0A\x70"
+ "\x0A\x6E\x0A\x6C\x0A\x6A\x0A\x68\x0A\x66\x0A\x64\x0A\x62"
+ "\x0A\x60\x0A\x5E\x0A\x5C\x0A\x5A\x0A\x58\x0A\x56\x0A\x54"
+ "\x0A\x52\x0A\x50\x0A\x4E\x0A\x4C\x0A\x4A\x0A\x48\x0A\x46"
+ "\x0A\x44\x0A\x42\x0A\x40\x0A\x3E\x0A\x3C\x0A\x3A\x0A\x38"
+ "\x0A\x36\x0A\x34\x0A\x32\x0A\x30\x0A\x2E\x0A\x2C\x0A\x2A"
+ "\x0A\x28\x0A\x26\x0A\x24\x0A\x22\x0A\x20\x0A\x1E\x0A\x1C"
+ "\x0A\x1A\x0A\x18\x0A\x16\x0A\x14\x0A\x12\x0A\x10\x0A\x0E"
+ "\x0A\x0C\x0A\x0A\x0A\x08\x0A\x06\x12\x04\x72\x02\x4B\x50");
+ NSError *error = nil;
+ NestedTestAllTypes *msg = [NestedTestAllTypes parseFromData:data
+ error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain);
+ XCTAssertEqual(error.code, GPBCodedInputStreamErrorRecursionDepthExceeded);
+}
+
+#ifdef DEBUG
+- (void)testErrorMissingRequiredField {
+ NSData *data = DataFromCStr("");
+ NSError *error = nil;
+ TestRequired *msg = [TestRequired parseFromData:data error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBMessageErrorDomain);
+ XCTAssertEqual(error.code, GPBMessageErrorCodeMissingRequiredField);
+}
+#endif
+
+#pragma mark - Subset from from map_tests.cc
+
+// TEST(GeneratedMapFieldTest, StandardWireFormat)
+- (void)testMap_StandardWireFormat {
+ NSData *data = DataFromCStr("\x0A\x04\x08\x01\x10\x01");
+
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
+ XCTAssertEqual(msg.mapInt32Int32.count, 1U);
+ int32_t val = 666;
+ XCTAssertTrue([msg.mapInt32Int32 getInt32:&val forKey:1]);
+ XCTAssertEqual(val, 1);
+
+ [msg release];
+}
+
+// TEST(GeneratedMapFieldTest, UnorderedWireFormat)
+- (void)testMap_UnorderedWireFormat {
+ // put value before key in wire format
+ NSData *data = DataFromCStr("\x0A\x04\x10\x01\x08\x02");
+
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
+ XCTAssertEqual(msg.mapInt32Int32.count, 1U);
+ int32_t val = 666;
+ XCTAssertTrue([msg.mapInt32Int32 getInt32:&val forKey:2]);
+ XCTAssertEqual(val, 1);
+
+ [msg release];
+}
+
+// TEST(GeneratedMapFieldTest, DuplicatedKeyWireFormat)
+- (void)testMap_DuplicatedKeyWireFormat {
+ // Two key fields in wire format
+ NSData *data = DataFromCStr("\x0A\x06\x08\x01\x08\x02\x10\x01");
+
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
+ XCTAssertEqual(msg.mapInt32Int32.count, 1U);
+ int32_t val = 666;
+ XCTAssertTrue([msg.mapInt32Int32 getInt32:&val forKey:2]);
+ XCTAssertEqual(val, 1);
+
+ [msg release];
+}
+
+// TEST(GeneratedMapFieldTest, DuplicatedValueWireFormat)
+- (void)testMap_DuplicatedValueWireFormat {
+ // Two value fields in wire format
+ NSData *data = DataFromCStr("\x0A\x06\x08\x01\x10\x01\x10\x02");
+
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
+ XCTAssertEqual(msg.mapInt32Int32.count, 1U);
+ int32_t val = 666;
+ XCTAssertTrue([msg.mapInt32Int32 getInt32:&val forKey:1]);
+ XCTAssertEqual(val, 2);
+
+ [msg release];
+}
+
+// TEST(GeneratedMapFieldTest, MissedKeyWireFormat)
+- (void)testMap_MissedKeyWireFormat {
+ // No key field in wire format
+ NSData *data = DataFromCStr("\x0A\x02\x10\x01");
+
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
+ XCTAssertEqual(msg.mapInt32Int32.count, 1U);
+ int32_t val = 666;
+ XCTAssertTrue([msg.mapInt32Int32 getInt32:&val forKey:0]);
+ XCTAssertEqual(val, 1);
+
+ [msg release];
+}
+
+// TEST(GeneratedMapFieldTest, MissedValueWireFormat)
+- (void)testMap_MissedValueWireFormat {
+ // No value field in wire format
+ NSData *data = DataFromCStr("\x0A\x02\x08\x01");
+
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
+ XCTAssertEqual(msg.mapInt32Int32.count, 1U);
+ int32_t val = 666;
+ XCTAssertTrue([msg.mapInt32Int32 getInt32:&val forKey:1]);
+ XCTAssertEqual(val, 0);
+
+ [msg release];
+}
+
+// TEST(GeneratedMapFieldTest, UnknownFieldWireFormat)
+- (void)testMap_UnknownFieldWireFormat {
+ // Unknown field in wire format
+ NSData *data = DataFromCStr("\x0A\x06\x08\x02\x10\x03\x18\x01");
+
+ TestMap *msg = [[TestMap alloc] initWithData:data error:NULL];
+ XCTAssertEqual(msg.mapInt32Int32.count, 1U);
+ int32_t val = 666;
+ XCTAssertTrue([msg.mapInt32Int32 getInt32:&val forKey:2]);
+ XCTAssertEqual(val, 3);
+
+ [msg release];
+}
+
+// TEST(GeneratedMapFieldTest, CorruptedWireFormat)
+- (void)testMap_CorruptedWireFormat {
+ // corrupted data in wire format
+ NSData *data = DataFromCStr("\x0A\x06\x08\x02\x11\x03");
+
+ NSError *error = nil;
+ TestMap *msg = [TestMap parseFromData:data error:&error];
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBCodedInputStreamErrorDomain);
+ XCTAssertEqual(error.code, GPBCodedInputStreamErrorInvalidSubsectionLimit);
+}
+
+// TEST(GeneratedMapFieldTest, Proto2UnknownEnum)
+- (void)testMap_Proto2UnknownEnum {
+ TestEnumMapPlusExtra *orig = [[TestEnumMapPlusExtra alloc] init];
+
+ orig.knownMapField = [GPBInt32EnumDictionary
+ dictionaryWithValidationFunction:Proto2MapEnumPlusExtra_IsValidValue];
+ orig.unknownMapField = [GPBInt32EnumDictionary
+ dictionaryWithValidationFunction:Proto2MapEnumPlusExtra_IsValidValue];
+ [orig.knownMapField setEnum:Proto2MapEnumPlusExtra_EProto2MapEnumFoo
+ forKey:0];
+ [orig.unknownMapField setEnum:Proto2MapEnumPlusExtra_EProto2MapEnumExtra
+ forKey:0];
+
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ TestEnumMap *msg1 = [TestEnumMap parseFromData:data error:NULL];
+ XCTAssertEqual(msg1.knownMapField.count, 1U);
+ int32_t val = -1;
+ XCTAssertTrue([msg1.knownMapField getEnum:&val forKey:0]);
+ XCTAssertEqual(val, Proto2MapEnum_Proto2MapEnumFoo);
+ XCTAssertEqual(msg1.unknownFields.countOfFields, 1U);
+
+ data = [msg1 data];
+ TestEnumMapPlusExtra *msg2 =
+ [TestEnumMapPlusExtra parseFromData:data error:NULL];
+ val = -1;
+ XCTAssertEqual(msg2.knownMapField.count, 1U);
+ XCTAssertTrue([msg2.knownMapField getEnum:&val forKey:0]);
+ XCTAssertEqual(val, Proto2MapEnumPlusExtra_EProto2MapEnumFoo);
+ val = -1;
+ XCTAssertEqual(msg2.unknownMapField.count, 1U);
+ XCTAssertTrue([msg2.unknownMapField getEnum:&val forKey:0]);
+ XCTAssertEqual(val, Proto2MapEnumPlusExtra_EProto2MapEnumExtra);
+ XCTAssertEqual(msg2.unknownFields.countOfFields, 0U);
+
+ XCTAssertEqualObjects(orig, msg2);
+
+ [orig release];
+}
+
+#pragma mark - Map Round Tripping
+
+- (void)testProto2MapRoundTripping {
+ Message2 *msg = [[Message2 alloc] init];
+
+ // Key/Value data should result in different byte lengths on wire to ensure
+ // everything is right.
+ [msg.mapInt32Int32 setInt32:1000 forKey:200];
+ [msg.mapInt32Int32 setInt32:101 forKey:2001];
+ [msg.mapInt64Int64 setInt64:1002 forKey:202];
+ [msg.mapInt64Int64 setInt64:103 forKey:2003];
+ [msg.mapUint32Uint32 setUInt32:1004 forKey:204];
+ [msg.mapUint32Uint32 setUInt32:105 forKey:2005];
+ [msg.mapUint64Uint64 setUInt64:1006 forKey:206];
+ [msg.mapUint64Uint64 setUInt64:107 forKey:2007];
+ [msg.mapSint32Sint32 setInt32:1008 forKey:208];
+ [msg.mapSint32Sint32 setInt32:109 forKey:2009];
+ [msg.mapSint64Sint64 setInt64:1010 forKey:210];
+ [msg.mapSint64Sint64 setInt64:111 forKey:2011];
+ [msg.mapFixed32Fixed32 setUInt32:1012 forKey:212];
+ [msg.mapFixed32Fixed32 setUInt32:113 forKey:2013];
+ [msg.mapFixed64Fixed64 setUInt64:1014 forKey:214];
+ [msg.mapFixed64Fixed64 setUInt64:115 forKey:2015];
+ [msg.mapSfixed32Sfixed32 setInt32:1016 forKey:216];
+ [msg.mapSfixed32Sfixed32 setInt32:117 forKey:2017];
+ [msg.mapSfixed64Sfixed64 setInt64:1018 forKey:218];
+ [msg.mapSfixed64Sfixed64 setInt64:119 forKey:2019];
+ [msg.mapInt32Float setFloat:1020.f forKey:220];
+ [msg.mapInt32Float setFloat:121.f forKey:2021];
+ [msg.mapInt32Double setDouble:1022. forKey:222];
+ [msg.mapInt32Double setDouble:123. forKey:2023];
+ [msg.mapBoolBool setBool:false forKey:true];
+ [msg.mapBoolBool setBool:true forKey:false];
+ msg.mapStringString[@"224"] = @"1024";
+ msg.mapStringString[@"2025"] = @"125";
+ msg.mapStringBytes[@"226"] = DataFromCStr("1026");
+ msg.mapStringBytes[@"2027"] = DataFromCStr("127");
+ Message2 *val1 = [[Message2 alloc] init];
+ val1.optionalInt32 = 1028;
+ Message2 *val2 = [[Message2 alloc] init];
+ val2.optionalInt32 = 129;
+ [msg.mapStringMessage setObject:val1 forKey:@"228"];
+ [msg.mapStringMessage setObject:val2 forKey:@"2029"];
+ [msg.mapInt32Bytes setObject:DataFromCStr("1030 bytes") forKey:230];
+ [msg.mapInt32Bytes setObject:DataFromCStr("131") forKey:2031];
+ [msg.mapInt32Enum setEnum:Message2_Enum_Bar forKey:232];
+ [msg.mapInt32Enum setEnum:Message2_Enum_Baz forKey:2033];
+ Message2 *val3 = [[Message2 alloc] init];
+ val3.optionalInt32 = 1034;
+ Message2 *val4 = [[Message2 alloc] init];
+ val4.optionalInt32 = 135;
+ [msg.mapInt32Message setObject:val3 forKey:234];
+ [msg.mapInt32Message setObject:val4 forKey:2035];
+
+ NSData *data = [msg data];
+ XCTAssertNotNil(data);
+ Message2 *msg2 = [[Message2 alloc] initWithData:data error:NULL];
+
+ XCTAssertNotEqual(msg2, msg); // Pointer comparison
+ XCTAssertEqualObjects(msg2, msg);
+
+ [val4 release];
+ [val3 release];
+ [val2 release];
+ [val1 release];
+ [msg2 release];
+ [msg release];
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBMessageTests.m b/third_party/protobuf/objectivec/Tests/GPBMessageTests.m
new file mode 100644
index 0000000000..c15535c508
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBMessageTests.m
@@ -0,0 +1,2053 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import <objc/runtime.h>
+
+#import "GPBArray_PackagePrivate.h"
+#import "GPBDescriptor.h"
+#import "GPBDictionary_PackagePrivate.h"
+#import "GPBMessage_PackagePrivate.h"
+#import "GPBUnknownField_PackagePrivate.h"
+#import "GPBUnknownFieldSet_PackagePrivate.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestObjc.pbobjc.h"
+
+@interface MessageTests : GPBTestCase
+@end
+
+@implementation MessageTests
+
+// TODO(thomasvl): this should get split into a few files of logic junks, it is
+// a jumble of things at the moment (and the testutils have a bunch of the real
+// assertions).
+
+- (TestAllTypes *)mergeSource {
+ TestAllTypes *message = [TestAllTypes message];
+ [message setOptionalInt32:1];
+ [message setOptionalString:@"foo"];
+ [message setOptionalForeignMessage:[ForeignMessage message]];
+ [message.repeatedStringArray addObject:@"bar"];
+ return message;
+}
+
+- (TestAllTypes *)mergeDestination {
+ TestAllTypes *message = [TestAllTypes message];
+ [message setOptionalInt64:2];
+ [message setOptionalString:@"baz"];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ [foreignMessage setC:3];
+ [message setOptionalForeignMessage:foreignMessage];
+ [message.repeatedStringArray addObject:@"qux"];
+ return message;
+}
+
+- (TestAllTypes *)mergeDestinationWithoutForeignMessageIvar {
+ TestAllTypes *message = [TestAllTypes message];
+ [message setOptionalInt64:2];
+ [message setOptionalString:@"baz"];
+ [message.repeatedStringArray addObject:@"qux"];
+ return message;
+}
+
+- (TestAllTypes *)mergeResult {
+ TestAllTypes *message = [TestAllTypes message];
+ [message setOptionalInt32:1];
+ [message setOptionalInt64:2];
+ [message setOptionalString:@"foo"];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ [foreignMessage setC:3];
+ [message setOptionalForeignMessage:foreignMessage];
+ [message.repeatedStringArray addObject:@"qux"];
+ [message.repeatedStringArray addObject:@"bar"];
+ return message;
+}
+
+- (TestAllTypes *)mergeResultForDestinationWithoutForeignMessageIvar {
+ TestAllTypes *message = [TestAllTypes message];
+ [message setOptionalInt32:1];
+ [message setOptionalInt64:2];
+ [message setOptionalString:@"foo"];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ [message setOptionalForeignMessage:foreignMessage];
+ [message.repeatedStringArray addObject:@"qux"];
+ [message.repeatedStringArray addObject:@"bar"];
+ return message;
+}
+
+- (TestAllExtensions *)mergeExtensionsDestination {
+ TestAllExtensions *message = [TestAllExtensions message];
+ [message setExtension:[UnittestRoot optionalInt32Extension] value:@5];
+ [message setExtension:[UnittestRoot optionalStringExtension] value:@"foo"];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ foreignMessage.c = 4;
+ [message setExtension:[UnittestRoot optionalForeignMessageExtension]
+ value:foreignMessage];
+ TestAllTypes_NestedMessage *nestedMessage =
+ [TestAllTypes_NestedMessage message];
+ [message setExtension:[UnittestRoot optionalNestedMessageExtension]
+ value:nestedMessage];
+ return message;
+}
+
+- (TestAllExtensions *)mergeExtensionsSource {
+ TestAllExtensions *message = [TestAllExtensions message];
+ [message setExtension:[UnittestRoot optionalInt64Extension] value:@6];
+ [message setExtension:[UnittestRoot optionalStringExtension] value:@"bar"];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ [message setExtension:[UnittestRoot optionalForeignMessageExtension]
+ value:foreignMessage];
+ TestAllTypes_NestedMessage *nestedMessage =
+ [TestAllTypes_NestedMessage message];
+ nestedMessage.bb = 7;
+ [message setExtension:[UnittestRoot optionalNestedMessageExtension]
+ value:nestedMessage];
+ return message;
+}
+
+- (TestAllExtensions *)mergeExtensionsResult {
+ TestAllExtensions *message = [TestAllExtensions message];
+ [message setExtension:[UnittestRoot optionalInt32Extension] value:@5];
+ [message setExtension:[UnittestRoot optionalInt64Extension] value:@6];
+ [message setExtension:[UnittestRoot optionalStringExtension] value:@"bar"];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ foreignMessage.c = 4;
+ [message setExtension:[UnittestRoot optionalForeignMessageExtension]
+ value:foreignMessage];
+ TestAllTypes_NestedMessage *nestedMessage =
+ [TestAllTypes_NestedMessage message];
+ nestedMessage.bb = 7;
+ [message setExtension:[UnittestRoot optionalNestedMessageExtension]
+ value:nestedMessage];
+ return message;
+}
+
+- (void)testMergeFrom {
+ TestAllTypes *result = [[self.mergeDestination copy] autorelease];
+ [result mergeFrom:self.mergeSource];
+ NSData *resultData = [result data];
+ NSData *mergeResultData = [self.mergeResult data];
+ XCTAssertEqualObjects(resultData, mergeResultData);
+ XCTAssertEqualObjects(result, self.mergeResult);
+
+ // Test when destination does not have an Ivar (type is an object) but source
+ // has such Ivar.
+ // The result must has the Ivar which is same as the one in source.
+ result = [[self.mergeDestinationWithoutForeignMessageIvar copy] autorelease];
+ [result mergeFrom:self.mergeSource];
+ resultData = [result data];
+ mergeResultData =
+ [self.mergeResultForDestinationWithoutForeignMessageIvar data];
+ XCTAssertEqualObjects(resultData, mergeResultData);
+ XCTAssertEqualObjects(
+ result, self.mergeResultForDestinationWithoutForeignMessageIvar);
+
+ // Test when destination is empty.
+ // The result must is same as the source.
+ result = [TestAllTypes message];
+ [result mergeFrom:self.mergeSource];
+ resultData = [result data];
+ mergeResultData = [self.mergeSource data];
+ XCTAssertEqualObjects(resultData, mergeResultData);
+ XCTAssertEqualObjects(result, self.mergeSource);
+}
+
+- (void)testMergeFromWithExtensions {
+ TestAllExtensions *result = [self mergeExtensionsDestination];
+ [result mergeFrom:[self mergeExtensionsSource]];
+ NSData *resultData = [result data];
+ NSData *mergeResultData = [[self mergeExtensionsResult] data];
+ XCTAssertEqualObjects(resultData, mergeResultData);
+ XCTAssertEqualObjects(result, [self mergeExtensionsResult]);
+
+ // Test merging from data.
+ result = [self mergeExtensionsDestination];
+ NSData *data = [[self mergeExtensionsSource] data];
+ XCTAssertNotNil(data);
+ [result mergeFromData:data
+ extensionRegistry:[UnittestRoot extensionRegistry]];
+ resultData = [result data];
+ XCTAssertEqualObjects(resultData, mergeResultData);
+ XCTAssertEqualObjects(result, [self mergeExtensionsResult]);
+}
+
+- (void)testIsEquals {
+ TestAllTypes *result = [[self.mergeDestination copy] autorelease];
+ [result mergeFrom:self.mergeSource];
+ XCTAssertEqualObjects(result.data, self.mergeResult.data);
+ XCTAssertEqualObjects(result, self.mergeResult);
+ TestAllTypes *result2 = [[self.mergeDestination copy] autorelease];
+ XCTAssertNotEqualObjects(result2.data, self.mergeResult.data);
+ XCTAssertNotEqualObjects(result2, self.mergeResult);
+}
+
+// =================================================================
+// Required-field-related tests.
+
+- (TestRequired *)testRequiredInitialized {
+ TestRequired *message = [TestRequired message];
+ [message setA:1];
+ [message setB:2];
+ [message setC:3];
+ return message;
+}
+
+- (void)testRequired {
+ TestRequired *message = [TestRequired message];
+
+ XCTAssertFalse(message.initialized);
+ [message setA:1];
+ XCTAssertFalse(message.initialized);
+ [message setB:1];
+ XCTAssertFalse(message.initialized);
+ [message setC:1];
+ XCTAssertTrue(message.initialized);
+}
+
+- (void)testRequiredForeign {
+ TestRequiredForeign *message = [TestRequiredForeign message];
+
+ XCTAssertTrue(message.initialized);
+
+ [message setOptionalMessage:[TestRequired message]];
+ XCTAssertFalse(message.initialized);
+
+ [message setOptionalMessage:self.testRequiredInitialized];
+ XCTAssertTrue(message.initialized);
+
+ [message.repeatedMessageArray addObject:[TestRequired message]];
+ XCTAssertFalse(message.initialized);
+
+ [message.repeatedMessageArray removeAllObjects];
+ [message.repeatedMessageArray addObject:self.testRequiredInitialized];
+ XCTAssertTrue(message.initialized);
+}
+
+- (void)testRequiredExtension {
+ TestAllExtensions *message = [TestAllExtensions message];
+
+ XCTAssertTrue(message.initialized);
+
+ [message setExtension:[TestRequired single] value:[TestRequired message]];
+ XCTAssertFalse(message.initialized);
+
+ [message setExtension:[TestRequired single]
+ value:self.testRequiredInitialized];
+ XCTAssertTrue(message.initialized);
+
+ [message addExtension:[TestRequired multi] value:[TestRequired message]];
+ XCTAssertFalse(message.initialized);
+
+ [message setExtension:[TestRequired multi]
+ index:0
+ value:self.testRequiredInitialized];
+ XCTAssertTrue(message.initialized);
+}
+
+- (void)testDataFromUninitialized {
+ TestRequired *message = [TestRequired message];
+ NSData *data = [message data];
+ // In DEBUG, the data generation will fail, but in non DEBUG, it passes
+ // because the check isn't done (for speed).
+#ifdef DEBUG
+ XCTAssertNil(data);
+#else
+ XCTAssertNotNil(data);
+ XCTAssertFalse(message.initialized);
+#endif // DEBUG
+}
+
+- (void)testInitialized {
+ // We're mostly testing that no exception is thrown.
+ TestRequired *message = [TestRequired message];
+ XCTAssertFalse(message.initialized);
+}
+
+- (void)testDataFromNestedUninitialized {
+ TestRequiredForeign *message = [TestRequiredForeign message];
+ [message setOptionalMessage:[TestRequired message]];
+ [message.repeatedMessageArray addObject:[TestRequired message]];
+ [message.repeatedMessageArray addObject:[TestRequired message]];
+ NSData *data = [message data];
+ // In DEBUG, the data generation will fail, but in non DEBUG, it passes
+ // because the check isn't done (for speed).
+#ifdef DEBUG
+ XCTAssertNil(data);
+#else
+ XCTAssertNotNil(data);
+ XCTAssertFalse(message.initialized);
+#endif // DEBUG
+}
+
+- (void)testNestedInitialized {
+ // We're mostly testing that no exception is thrown.
+
+ TestRequiredForeign *message = [TestRequiredForeign message];
+ [message setOptionalMessage:[TestRequired message]];
+ [message.repeatedMessageArray addObject:[TestRequired message]];
+ [message.repeatedMessageArray addObject:[TestRequired message]];
+
+ XCTAssertFalse(message.initialized);
+}
+
+- (void)testParseUninitialized {
+ NSError *error = nil;
+ TestRequired *msg =
+ [TestRequired parseFromData:GPBEmptyNSData() error:&error];
+ // In DEBUG, the parse will fail, but in non DEBUG, it passes because
+ // the check isn't done (for speed).
+#ifdef DEBUG
+ XCTAssertNil(msg);
+ XCTAssertNotNil(error);
+ XCTAssertEqualObjects(error.domain, GPBMessageErrorDomain);
+ XCTAssertEqual(error.code, GPBMessageErrorCodeMissingRequiredField);
+#else
+ XCTAssertNotNil(msg);
+ XCTAssertNil(error);
+ XCTAssertFalse(msg.initialized);
+#endif // DEBUG
+}
+
+- (void)testCoding {
+ NSData *data =
+ [NSKeyedArchiver archivedDataWithRootObject:[self mergeResult]];
+ id unarchivedObject = [NSKeyedUnarchiver unarchiveObjectWithData:data];
+
+ XCTAssertEqualObjects(unarchivedObject, [self mergeResult]);
+
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual(unarchivedObject, [self mergeResult]);
+}
+
+- (void)testObjectReset {
+ // Tests a failure where clearing out defaults values caused an over release.
+ TestAllTypes *message = [TestAllTypes message];
+ message.hasOptionalNestedMessage = NO;
+ [message setOptionalNestedMessage:[TestAllTypes_NestedMessage message]];
+ message.hasOptionalNestedMessage = NO;
+ [message setOptionalNestedMessage:[TestAllTypes_NestedMessage message]];
+ [message setOptionalNestedMessage:nil];
+ message.hasOptionalNestedMessage = NO;
+}
+
+- (void)testSettingHasToYes {
+ TestAllTypes *message = [TestAllTypes message];
+ XCTAssertThrows([message setHasOptionalNestedMessage:YES]);
+}
+
+- (void)testRoot {
+ XCTAssertNotNil([UnittestRoot extensionRegistry]);
+}
+
+- (void)testGPBMessageSize {
+ // See the note in GPBMessage_PackagePrivate.h about why we want to keep the
+ // base instance size pointer size aligned.
+ size_t messageSize = class_getInstanceSize([GPBMessage class]);
+ XCTAssertEqual((messageSize % sizeof(void *)), (size_t)0,
+ @"Base size isn't pointer size aligned");
+
+ // Since we add storage ourselves (see +allocWithZone: in GPBMessage), confirm
+ // that the size of some generated classes is still the same as the base for
+ // that logic to work as desired.
+ size_t testMessageSize = class_getInstanceSize([TestAllTypes class]);
+ XCTAssertEqual(testMessageSize, messageSize);
+}
+
+- (void)testInit {
+ TestAllTypes *message = [TestAllTypes message];
+ [self assertClear:message];
+}
+
+- (void)testAccessors {
+ TestAllTypes *message = [TestAllTypes message];
+ [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount];
+ [self assertAllFieldsSet:message repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testKVC_ValueForKey {
+ TestAllTypes *message = [TestAllTypes message];
+ [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount];
+ [self assertAllFieldsKVCMatch:message];
+}
+
+- (void)testKVC_SetValue_ForKey {
+ TestAllTypes *message = [TestAllTypes message];
+ [self setAllFieldsViaKVC:message repeatedCount:kGPBDefaultRepeatCount];
+ [self assertAllFieldsKVCMatch:message];
+ [self assertAllFieldsSet:message repeatedCount:kGPBDefaultRepeatCount];
+ [self assertAllFieldsKVCMatch:message];
+}
+
+- (void)testDescription {
+ // No real test, just exercise code
+ TestAllTypes *message = [TestAllTypes message];
+ [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount];
+
+ GPBUnknownFieldSet *unknownFields =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+ GPBUnknownField *field =
+ [[[GPBUnknownField alloc] initWithNumber:2] autorelease];
+ [field addVarint:2];
+ [unknownFields addField:field];
+ field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease];
+ [field addVarint:4];
+ [unknownFields addField:field];
+
+ [message setUnknownFields:unknownFields];
+
+ NSString *description = [message description];
+ XCTAssertGreaterThan([description length], 0U);
+
+ GPBMessage *message2 = [TestAllExtensions message];
+ [message2 setExtension:[UnittestRoot optionalInt32Extension] value:@1];
+
+ [message2 addExtension:[UnittestRoot repeatedInt32Extension] value:@2];
+
+ description = [message2 description];
+ XCTAssertGreaterThan([description length], 0U);
+}
+
+- (void)testSetter {
+ // Test to make sure that if we set a value that has a default value
+ // with the default, that the has is set, and the value gets put into the
+ // message correctly.
+ TestAllTypes *message = [TestAllTypes message];
+ GPBDescriptor *descriptor = [[message class] descriptor];
+ XCTAssertNotNil(descriptor);
+ GPBFieldDescriptor *fieldDescriptor =
+ [descriptor fieldWithName:@"defaultInt32"];
+ XCTAssertNotNil(fieldDescriptor);
+ GPBGenericValue defaultValue = [fieldDescriptor defaultValue];
+ [message setDefaultInt32:defaultValue.valueInt32];
+ XCTAssertTrue(message.hasDefaultInt32);
+ XCTAssertEqual(message.defaultInt32, defaultValue.valueInt32);
+
+ // Do the same thing with an object type.
+ message = [TestAllTypes message];
+ fieldDescriptor = [descriptor fieldWithName:@"defaultString"];
+ XCTAssertNotNil(fieldDescriptor);
+ defaultValue = [fieldDescriptor defaultValue];
+ [message setDefaultString:defaultValue.valueString];
+ XCTAssertTrue(message.hasDefaultString);
+ XCTAssertEqualObjects(message.defaultString, defaultValue.valueString);
+
+ // Test default string type.
+ message = [TestAllTypes message];
+ XCTAssertEqualObjects(message.defaultString, @"hello");
+ XCTAssertFalse(message.hasDefaultString);
+ fieldDescriptor = [descriptor fieldWithName:@"defaultString"];
+ XCTAssertNotNil(fieldDescriptor);
+ defaultValue = [fieldDescriptor defaultValue];
+ [message setDefaultString:defaultValue.valueString];
+ XCTAssertEqualObjects(message.defaultString, @"hello");
+ XCTAssertTrue(message.hasDefaultString);
+ [message setDefaultString:nil];
+ XCTAssertEqualObjects(message.defaultString, @"hello");
+ XCTAssertFalse(message.hasDefaultString);
+ message.hasDefaultString = NO;
+ XCTAssertFalse(message.hasDefaultString);
+ XCTAssertEqualObjects(message.defaultString, @"hello");
+
+ // Test default bytes type.
+ NSData *defaultBytes = [@"world" dataUsingEncoding:NSUTF8StringEncoding];
+ XCTAssertEqualObjects(message.defaultBytes, defaultBytes);
+ XCTAssertFalse(message.hasDefaultString);
+ fieldDescriptor = [descriptor fieldWithName:@"defaultBytes"];
+ XCTAssertNotNil(fieldDescriptor);
+ defaultValue = [fieldDescriptor defaultValue];
+ [message setDefaultBytes:defaultValue.valueData];
+ XCTAssertEqualObjects(message.defaultBytes, defaultBytes);
+ XCTAssertTrue(message.hasDefaultBytes);
+ [message setDefaultBytes:nil];
+ XCTAssertEqualObjects(message.defaultBytes, defaultBytes);
+ XCTAssertFalse(message.hasDefaultBytes);
+ message.hasDefaultBytes = NO;
+ XCTAssertFalse(message.hasDefaultBytes);
+ XCTAssertEqualObjects(message.defaultBytes, defaultBytes);
+
+ // Test optional string.
+ XCTAssertFalse(message.hasOptionalString);
+ XCTAssertEqualObjects(message.optionalString, @"");
+ XCTAssertFalse(message.hasOptionalString);
+ message.optionalString = nil;
+ XCTAssertFalse(message.hasOptionalString);
+ XCTAssertEqualObjects(message.optionalString, @"");
+ NSString *string = @"string";
+ message.optionalString = string;
+ XCTAssertEqualObjects(message.optionalString, string);
+ XCTAssertTrue(message.hasOptionalString);
+ message.optionalString = nil;
+ XCTAssertFalse(message.hasOptionalString);
+ XCTAssertEqualObjects(message.optionalString, @"");
+
+ // Test optional data.
+ XCTAssertFalse(message.hasOptionalBytes);
+ XCTAssertEqualObjects(message.optionalBytes, GPBEmptyNSData());
+ XCTAssertFalse(message.hasOptionalBytes);
+ message.optionalBytes = nil;
+ XCTAssertFalse(message.hasOptionalBytes);
+ XCTAssertEqualObjects(message.optionalBytes, GPBEmptyNSData());
+ NSData *data = [@"bytes" dataUsingEncoding:NSUTF8StringEncoding];
+ message.optionalBytes = data;
+ XCTAssertEqualObjects(message.optionalBytes, data);
+ XCTAssertTrue(message.hasOptionalBytes);
+ message.optionalBytes = nil;
+ XCTAssertFalse(message.hasOptionalBytes);
+ XCTAssertEqualObjects(message.optionalBytes, GPBEmptyNSData());
+
+ // Test lazy message setting
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+ XCTAssertNotNil(message.optionalLazyMessage);
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+ message.hasOptionalLazyMessage = NO;
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+ XCTAssertNotNil(message.optionalLazyMessage);
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+ message.optionalLazyMessage = nil;
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+
+ // Test nested messages
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+ message.optionalLazyMessage.bb = 1;
+ XCTAssertTrue(message.hasOptionalLazyMessage);
+ XCTAssertEqual(message.optionalLazyMessage.bb, 1);
+ XCTAssertNotNil(message.optionalLazyMessage);
+ message.optionalLazyMessage = nil;
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+ XCTAssertEqual(message.optionalLazyMessage.bb, 0);
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+ XCTAssertNotNil(message.optionalLazyMessage);
+
+ // -testDefaultSubMessages tests the "defaulting" handling of fields
+ // containing messages.
+}
+
+- (void)testRepeatedSetters {
+ TestAllTypes *message = [TestAllTypes message];
+ [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount];
+ [self modifyRepeatedFields:message];
+ [self assertRepeatedFieldsModified:message
+ repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testClear {
+ TestAllTypes *message = [TestAllTypes message];
+ [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount];
+ [self clearAllFields:message];
+ [self assertClear:message];
+ TestAllTypes *message2 = [TestAllTypes message];
+ XCTAssertEqualObjects(message, message2);
+}
+
+- (void)testClearKVC {
+ TestAllTypes *message = [TestAllTypes message];
+ [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount];
+ [self clearAllFields:message];
+ [self assertClear:message];
+ [self assertClearKVC:message];
+}
+
+- (void)testClearExtension {
+ // clearExtension() is not actually used in TestUtil, so try it manually.
+ GPBMessage *message1 = [TestAllExtensions message];
+ [message1 setExtension:[UnittestRoot optionalInt32Extension] value:@1];
+
+ XCTAssertTrue([message1 hasExtension:[UnittestRoot optionalInt32Extension]]);
+ [message1 clearExtension:[UnittestRoot optionalInt32Extension]];
+ XCTAssertFalse([message1 hasExtension:[UnittestRoot optionalInt32Extension]]);
+
+ GPBMessage *message2 = [TestAllExtensions message];
+ [message2 addExtension:[UnittestRoot repeatedInt32Extension] value:@1];
+
+ XCTAssertEqual(
+ [[message2 getExtension:[UnittestRoot repeatedInt32Extension]] count],
+ (NSUInteger)1);
+ [message2 clearExtension:[UnittestRoot repeatedInt32Extension]];
+ XCTAssertEqual(
+ [[message2 getExtension:[UnittestRoot repeatedInt32Extension]] count],
+ (NSUInteger)0);
+
+ // Clearing an unset extension field shouldn't make the target message
+ // visible.
+ GPBMessage *message3 = [TestAllExtensions message];
+ GPBMessage *extension_msg =
+ [message3 getExtension:[UnittestObjcRoot recursiveExtension]];
+ XCTAssertFalse([message3 hasExtension:[UnittestObjcRoot recursiveExtension]]);
+ [extension_msg clearExtension:[UnittestRoot optionalInt32Extension]];
+ XCTAssertFalse([message3 hasExtension:[UnittestObjcRoot recursiveExtension]]);
+}
+
+- (void)testDefaultingSubMessages {
+ TestAllTypes *message = [TestAllTypes message];
+
+ // Initially they should all not have values.
+
+ XCTAssertFalse(message.hasOptionalGroup);
+ XCTAssertFalse(message.hasOptionalNestedMessage);
+ XCTAssertFalse(message.hasOptionalForeignMessage);
+ XCTAssertFalse(message.hasOptionalImportMessage);
+ XCTAssertFalse(message.hasOptionalPublicImportMessage);
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+
+ // They should auto create something when fetched.
+
+ TestAllTypes_OptionalGroup *optionalGroup = [message.optionalGroup retain];
+ TestAllTypes_NestedMessage *optionalNestedMessage =
+ [message.optionalNestedMessage retain];
+ ForeignMessage *optionalForeignMessage =
+ [message.optionalForeignMessage retain];
+ ImportMessage *optionalImportMessage = [message.optionalImportMessage retain];
+ PublicImportMessage *optionalPublicImportMessage =
+ [message.optionalPublicImportMessage retain];
+ TestAllTypes_NestedMessage *optionalLazyMessage =
+ [message.optionalLazyMessage retain];
+
+ XCTAssertNotNil(optionalGroup);
+ XCTAssertNotNil(optionalNestedMessage);
+ XCTAssertNotNil(optionalForeignMessage);
+ XCTAssertNotNil(optionalImportMessage);
+ XCTAssertNotNil(optionalPublicImportMessage);
+ XCTAssertNotNil(optionalLazyMessage);
+
+ // Although they were created, they should not respond to hasValue until that
+ // submessage is mutated.
+
+ XCTAssertFalse(message.hasOptionalGroup);
+ XCTAssertFalse(message.hasOptionalNestedMessage);
+ XCTAssertFalse(message.hasOptionalForeignMessage);
+ XCTAssertFalse(message.hasOptionalImportMessage);
+ XCTAssertFalse(message.hasOptionalPublicImportMessage);
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+
+ // And they set that value back in to the message since the value created was
+ // mutable (so a second fetch should give the same object).
+
+ XCTAssertEqual(message.optionalGroup, optionalGroup);
+ XCTAssertEqual(message.optionalNestedMessage, optionalNestedMessage);
+ XCTAssertEqual(message.optionalForeignMessage, optionalForeignMessage);
+ XCTAssertEqual(message.optionalImportMessage, optionalImportMessage);
+ XCTAssertEqual(message.optionalPublicImportMessage,
+ optionalPublicImportMessage);
+ XCTAssertEqual(message.optionalLazyMessage, optionalLazyMessage);
+
+ // And the default objects for a second message should be distinct (again,
+ // since they are mutable, each needs their own copy).
+
+ TestAllTypes *message2 = [TestAllTypes message];
+
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual(message2.optionalGroup, optionalGroup);
+ XCTAssertNotEqual(message2.optionalNestedMessage, optionalNestedMessage);
+ XCTAssertNotEqual(message2.optionalForeignMessage, optionalForeignMessage);
+ XCTAssertNotEqual(message2.optionalImportMessage, optionalImportMessage);
+ XCTAssertNotEqual(message2.optionalPublicImportMessage,
+ optionalPublicImportMessage);
+ XCTAssertNotEqual(message2.optionalLazyMessage, optionalLazyMessage);
+
+ // Setting the values to nil will clear the has flag, and on next access you
+ // get back new submessages.
+
+ message.optionalGroup = nil;
+ message.optionalNestedMessage = nil;
+ message.optionalForeignMessage = nil;
+ message.optionalImportMessage = nil;
+ message.optionalPublicImportMessage = nil;
+ message.optionalLazyMessage = nil;
+
+ XCTAssertFalse(message.hasOptionalGroup);
+ XCTAssertFalse(message.hasOptionalNestedMessage);
+ XCTAssertFalse(message.hasOptionalForeignMessage);
+ XCTAssertFalse(message.hasOptionalImportMessage);
+ XCTAssertFalse(message.hasOptionalPublicImportMessage);
+ XCTAssertFalse(message.hasOptionalLazyMessage);
+
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual(message.optionalGroup, optionalGroup);
+ XCTAssertNotEqual(message.optionalNestedMessage, optionalNestedMessage);
+ XCTAssertNotEqual(message.optionalForeignMessage, optionalForeignMessage);
+ XCTAssertNotEqual(message.optionalImportMessage, optionalImportMessage);
+ XCTAssertNotEqual(message.optionalPublicImportMessage,
+ optionalPublicImportMessage);
+ XCTAssertNotEqual(message.optionalLazyMessage, optionalLazyMessage);
+
+ [optionalGroup release];
+ [optionalNestedMessage release];
+ [optionalForeignMessage release];
+ [optionalImportMessage release];
+ [optionalPublicImportMessage release];
+ [optionalLazyMessage release];
+}
+
+- (void)testMultiplePointersToAutocreatedMessage {
+ // Multiple objects pointing to the same autocreated message.
+ TestAllTypes *message = [TestAllTypes message];
+ TestAllTypes *message2 = [TestAllTypes message];
+ message2.optionalGroup = message.optionalGroup;
+ XCTAssertTrue([message2 hasOptionalGroup]);
+ XCTAssertFalse([message hasOptionalGroup]);
+ message2.optionalGroup.a = 42;
+ XCTAssertTrue([message hasOptionalGroup]);
+ XCTAssertTrue([message2 hasOptionalGroup]);
+}
+
+- (void)testCopyWithAutocreatedMessage {
+ // Mutable copy should not copy autocreated messages.
+ TestAllTypes *message = [TestAllTypes message];
+ message.optionalGroup.a = 42;
+ XCTAssertNotNil(message.optionalNestedMessage);
+ TestAllTypes *message2 = [[message copy] autorelease];
+ XCTAssertTrue([message2 hasOptionalGroup]);
+ XCTAssertFalse([message2 hasOptionalNestedMessage]);
+
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual(message.optionalNestedMessage,
+ message2.optionalNestedMessage);
+}
+
+- (void)testClearAutocreatedSubmessage {
+ // Call clear on an intermediate submessage should cause it to get recreated
+ // on the next call.
+ TestRecursiveMessage *message = [TestRecursiveMessage message];
+ TestRecursiveMessage *message_inner = [message.a.a.a retain];
+ XCTAssertNotNil(message_inner);
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(message_inner, message.a.a));
+ [message.a.a clear];
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(message_inner, message.a.a));
+
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual(message.a.a.a, message_inner);
+ [message_inner release];
+}
+
+- (void)testRetainAutocreatedSubmessage {
+ // Should be able to retain autocreated submessage while the creator is
+ // dealloced.
+ TestAllTypes *message = [TestAllTypes message];
+
+ ForeignMessage *subMessage;
+ @autoreleasepool {
+ TestAllTypes *message2 = [TestAllTypes message];
+ subMessage = message2.optionalForeignMessage; // Autocreated
+ message.optionalForeignMessage = subMessage;
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(message.optionalForeignMessage,
+ message2));
+ }
+
+ // Should be the same object, and should still be live.
+ XCTAssertEqual(message.optionalForeignMessage, subMessage);
+ XCTAssertNotNil([subMessage description]);
+}
+
+- (void)testSetNilAutocreatedSubmessage {
+ TestRecursiveMessage *message = [TestRecursiveMessage message];
+ TestRecursiveMessage *message_inner = [message.a.a retain];
+ XCTAssertFalse([message hasA]);
+ XCTAssertFalse([message.a hasA]);
+ message.a.a = nil;
+
+ // |message.a| has to be made visible, but |message.a.a| was set to nil so
+ // shouldn't be.
+ XCTAssertTrue([message hasA]);
+ XCTAssertFalse([message.a hasA]);
+
+ // Setting submessage to nil should cause it to lose its creator.
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(message_inner, message.a));
+
+ // After setting to nil, getting it again should create a new autocreated
+ // message.
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual(message.a.a, message_inner);
+
+ [message_inner release];
+}
+
+- (void)testSetDoesntHaveAutocreatedSubmessage {
+ // Clearing submessage (set has == NO) should NOT cause it to lose its
+ // creator.
+ TestAllTypes *message = [TestAllTypes message];
+ TestAllTypes_NestedMessage *nestedMessage = message.optionalNestedMessage;
+ XCTAssertFalse([message hasOptionalNestedMessage]);
+ [message setHasOptionalNestedMessage:NO];
+ XCTAssertFalse([message hasOptionalNestedMessage]);
+ XCTAssertEqual(message.optionalNestedMessage, nestedMessage);
+}
+
+- (void)testSetAutocreatedMessageBecomesVisible {
+ // Setting a value should cause the submessage to appear to its creator.
+ // Test this several levels deep.
+ TestRecursiveMessage *message = [TestRecursiveMessage message];
+ message.a.a.a.a.i = 42;
+ XCTAssertTrue([message hasA]);
+ XCTAssertTrue([message.a hasA]);
+ XCTAssertTrue([message.a.a hasA]);
+ XCTAssertTrue([message.a.a.a hasA]);
+ XCTAssertFalse([message.a.a.a.a hasA]);
+ XCTAssertEqual(message.a.a.a.a.i, 42);
+}
+
+- (void)testClearUnsetFieldOfAutocreatedMessage {
+ // Clearing an unset field should not cause the submessage to appear to its
+ // creator.
+ TestRecursiveMessage *message = [TestRecursiveMessage message];
+ message.a.a.a.a.hasI = NO;
+ XCTAssertFalse([message hasA]);
+ XCTAssertFalse([message.a hasA]);
+ XCTAssertFalse([message.a.a hasA]);
+ XCTAssertFalse([message.a.a.a hasA]);
+}
+
+- (void)testAutocreatedSubmessageAssignSkip {
+ TestRecursiveMessage *message = [TestRecursiveMessage message];
+ TestRecursiveMessage *messageLevel1 = [message.a retain];
+ TestRecursiveMessage *messageLevel2 = [message.a.a retain];
+ TestRecursiveMessage *messageLevel3 = [message.a.a.a retain];
+ TestRecursiveMessage *messageLevel4 = [message.a.a.a.a retain];
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel1, message));
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel2, messageLevel1));
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel3, messageLevel2));
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel4, messageLevel3));
+
+ // Test skipping over an autocreated submessage and ensure it gets unset.
+ message.a = message.a.a;
+ XCTAssertEqual(message.a, messageLevel2);
+ XCTAssertTrue([message hasA]);
+ XCTAssertEqual(message.a.a, messageLevel3);
+ XCTAssertFalse([message.a hasA]);
+ XCTAssertEqual(message.a.a.a, messageLevel4);
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(messageLevel1,
+ message)); // Because it was orphaned.
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel2, messageLevel1));
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel3, messageLevel2));
+
+ [messageLevel1 release];
+ [messageLevel2 release];
+ [messageLevel3 release];
+ [messageLevel4 release];
+}
+
+- (void)testAutocreatedSubmessageAssignLoop {
+ TestRecursiveMessage *message = [TestRecursiveMessage message];
+ TestRecursiveMessage *messageLevel1 = [message.a retain];
+ TestRecursiveMessage *messageLevel2 = [message.a.a retain];
+ TestRecursiveMessage *messageLevel3 = [message.a.a.a retain];
+ TestRecursiveMessage *messageLevel4 = [message.a.a.a.a retain];
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel1, message));
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel2, messageLevel1));
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel3, messageLevel2));
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(messageLevel4, messageLevel3));
+
+ // Test a property with a loop. You'd never do this but at least ensure the
+ // autocreated submessages behave sanely.
+ message.a.a = message.a;
+ XCTAssertTrue([message hasA]);
+ XCTAssertEqual(message.a, messageLevel1);
+ XCTAssertTrue([message.a hasA]);
+ XCTAssertEqual(message.a.a, messageLevel1);
+ XCTAssertTrue([message.a.a hasA]);
+ XCTAssertEqual(message.a.a.a, messageLevel1);
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(messageLevel1,
+ message)); // Because it was assigned.
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(messageLevel2,
+ messageLevel1)); // Because it was orphaned.
+ XCTAssertFalse([messageLevel2 hasA]);
+
+ // Break the retain loop.
+ message.a.a = nil;
+ XCTAssertTrue([message hasA]);
+ XCTAssertFalse([message.a hasA]);
+
+ [messageLevel1 release];
+ [messageLevel2 release];
+ [messageLevel3 release];
+ [messageLevel4 release];
+}
+
+- (void)testSetAutocreatedSubmessage {
+ // Setting autocreated submessage to another value should cause the old one to
+ // lose its creator.
+ TestAllTypes *message = [TestAllTypes message];
+ TestAllTypes_NestedMessage *nestedMessage =
+ [message.optionalNestedMessage retain];
+
+ message.optionalNestedMessage = [TestAllTypes_NestedMessage message];
+ XCTAssertTrue([message hasOptionalNestedMessage]);
+ XCTAssertTrue(message.optionalNestedMessage != nestedMessage);
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(nestedMessage, message));
+
+ [nestedMessage release];
+}
+
+- (void)testAutocreatedUnknownFields {
+ // Doing anything with (except reading) unknown fields should cause the
+ // submessage to become visible.
+ TestAllTypes *message = [TestAllTypes message];
+ XCTAssertNotNil(message.optionalNestedMessage);
+ XCTAssertFalse([message hasOptionalNestedMessage]);
+ XCTAssertNil(message.optionalNestedMessage.unknownFields);
+ XCTAssertFalse([message hasOptionalNestedMessage]);
+
+ GPBUnknownFieldSet *unknownFields =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+ message.optionalNestedMessage.unknownFields = unknownFields;
+ XCTAssertTrue([message hasOptionalNestedMessage]);
+
+ message.optionalNestedMessage = nil;
+ XCTAssertFalse([message hasOptionalNestedMessage]);
+ [message.optionalNestedMessage setUnknownFields:unknownFields];
+ XCTAssertTrue([message hasOptionalNestedMessage]);
+}
+
+- (void)testSetAutocreatedSubmessageToSelf {
+ // Setting submessage to itself should cause it to become visible.
+ TestAllTypes *message = [TestAllTypes message];
+ XCTAssertNotNil(message.optionalNestedMessage);
+ XCTAssertFalse([message hasOptionalNestedMessage]);
+ message.optionalNestedMessage = message.optionalNestedMessage;
+ XCTAssertTrue([message hasOptionalNestedMessage]);
+}
+
+- (void)testAutocreatedSubmessageMemoryLeaks {
+ // Test for memory leaks with autocreated submessages.
+ TestRecursiveMessage *message;
+ TestRecursiveMessage *messageLevel1;
+ TestRecursiveMessage *messageLevel2;
+ TestRecursiveMessage *messageLevel3;
+ TestRecursiveMessage *messageLevel4;
+ @autoreleasepool {
+ message = [[TestRecursiveMessage alloc] init];
+ messageLevel1 = [message.a retain];
+ messageLevel2 = [message.a.a retain];
+ messageLevel3 = [message.a.a.a retain];
+ messageLevel4 = [message.a.a.a.a retain];
+ message.a.i = 1;
+ }
+
+ XCTAssertEqual(message.retainCount, (NSUInteger)1);
+ [message release];
+ XCTAssertEqual(messageLevel1.retainCount, (NSUInteger)1);
+ [messageLevel1 release];
+ XCTAssertEqual(messageLevel2.retainCount, (NSUInteger)1);
+ [messageLevel2 release];
+ XCTAssertEqual(messageLevel3.retainCount, (NSUInteger)1);
+ [messageLevel3 release];
+ XCTAssertEqual(messageLevel4.retainCount, (NSUInteger)1);
+ [messageLevel4 release];
+}
+
+- (void)testDefaultingArrays {
+ // Basic tests for default creation of arrays in a message.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ TestRecursiveMessageWithRepeatedField *message2 =
+ [TestRecursiveMessageWithRepeatedField message];
+
+ // Simply accessing the array should not make any fields visible.
+ XCTAssertNotNil(message.a.a.iArray);
+ XCTAssertFalse([message hasA]);
+ XCTAssertFalse([message.a hasA]);
+ XCTAssertNotNil(message2.a.a.strArray);
+ XCTAssertFalse([message2 hasA]);
+ XCTAssertFalse([message2.a hasA]);
+
+ // But adding an element to the array should.
+ [message.a.a.iArray addValue:42];
+ XCTAssertTrue([message hasA]);
+ XCTAssertTrue([message.a hasA]);
+ XCTAssertEqual([message.a.a.iArray count], (NSUInteger)1);
+ [message2.a.a.strArray addObject:@"foo"];
+ XCTAssertTrue([message2 hasA]);
+ XCTAssertTrue([message2.a hasA]);
+ XCTAssertEqual([message2.a.a.strArray count], (NSUInteger)1);
+}
+
+- (void)testAutocreatedArrayShared {
+ // Multiple objects pointing to the same array.
+ TestRecursiveMessageWithRepeatedField *message1a =
+ [TestRecursiveMessageWithRepeatedField message];
+ TestRecursiveMessageWithRepeatedField *message1b =
+ [TestRecursiveMessageWithRepeatedField message];
+ message1a.a.iArray = message1b.a.iArray;
+ XCTAssertTrue([message1a hasA]);
+ XCTAssertFalse([message1b hasA]);
+ [message1a.a.iArray addValue:1];
+ XCTAssertTrue([message1a hasA]);
+ XCTAssertTrue([message1b hasA]);
+ XCTAssertEqual(message1a.a.iArray, message1b.a.iArray);
+
+ TestRecursiveMessageWithRepeatedField *message2a =
+ [TestRecursiveMessageWithRepeatedField message];
+ TestRecursiveMessageWithRepeatedField *message2b =
+ [TestRecursiveMessageWithRepeatedField message];
+ message2a.a.strArray = message2b.a.strArray;
+ XCTAssertTrue([message2a hasA]);
+ XCTAssertFalse([message2b hasA]);
+ [message2a.a.strArray addObject:@"bar"];
+ XCTAssertTrue([message2a hasA]);
+ XCTAssertTrue([message2b hasA]);
+ XCTAssertEqual(message2a.a.strArray, message2b.a.strArray);
+}
+
+- (void)testAutocreatedArrayCopy {
+ // Copy should not copy autocreated arrays.
+ TestAllTypes *message = [TestAllTypes message];
+ XCTAssertNotNil(message.repeatedStringArray);
+ XCTAssertNotNil(message.repeatedInt32Array);
+ TestAllTypes *message2 = [[message copy] autorelease];
+ // Pointer conparisions.
+ XCTAssertNotEqual(message.repeatedStringArray, message2.repeatedStringArray);
+ XCTAssertNotEqual(message.repeatedInt32Array, message2.repeatedInt32Array);
+
+ // Mutable copy should copy empty arrays that were explicitly set (end up
+ // with different objects that are equal).
+ TestAllTypes *message3 = [TestAllTypes message];
+ message3.repeatedInt32Array = [GPBInt32Array arrayWithValue:42];
+ message3.repeatedStringArray = [NSMutableArray arrayWithObject:@"wee"];
+ XCTAssertNotNil(message.repeatedInt32Array);
+ XCTAssertNotNil(message.repeatedStringArray);
+ TestAllTypes *message4 = [[message3 copy] autorelease];
+ XCTAssertNotEqual(message3.repeatedInt32Array, message4.repeatedInt32Array);
+ XCTAssertEqualObjects(message3.repeatedInt32Array,
+ message4.repeatedInt32Array);
+ XCTAssertNotEqual(message3.repeatedStringArray, message4.repeatedStringArray);
+ XCTAssertEqualObjects(message3.repeatedStringArray,
+ message4.repeatedStringArray);
+}
+
+- (void)testAutocreatedArrayRetain {
+ // Should be able to retain autocreated array while the creator is dealloced.
+ TestAllTypes *message = [TestAllTypes message];
+
+ @autoreleasepool {
+ TestAllTypes *message2 = [TestAllTypes message];
+ message.repeatedInt32Array = message2.repeatedInt32Array;
+ message.repeatedStringArray = message2.repeatedStringArray;
+ // Pointer conparision
+ XCTAssertEqual(message.repeatedInt32Array->_autocreator, message2);
+ XCTAssertTrue([message.repeatedStringArray
+ isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(
+ ((GPBAutocreatedArray *)message.repeatedStringArray)->_autocreator,
+ message2);
+ }
+
+ XCTAssertNil(message.repeatedInt32Array->_autocreator);
+ XCTAssertTrue(
+ [message.repeatedStringArray isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertNil(
+ ((GPBAutocreatedArray *)message.repeatedStringArray)->_autocreator);
+}
+
+- (void)testSetNilAutocreatedArray {
+ // Setting array to nil should cause it to lose its delegate.
+ TestAllTypes *message = [TestAllTypes message];
+ GPBInt32Array *repeatedInt32Array = [message.repeatedInt32Array retain];
+ GPBAutocreatedArray *repeatedStringArray =
+ (GPBAutocreatedArray *)[message.repeatedStringArray retain];
+ XCTAssertTrue([repeatedStringArray isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(repeatedInt32Array->_autocreator, message);
+ XCTAssertEqual(repeatedStringArray->_autocreator, message);
+ message.repeatedInt32Array = nil;
+ message.repeatedStringArray = nil;
+ XCTAssertNil(repeatedInt32Array->_autocreator);
+ XCTAssertNil(repeatedStringArray->_autocreator);
+ [repeatedInt32Array release];
+ [repeatedStringArray release];
+}
+
+- (void)testSetOverAutocreatedArrayAndSetAgain {
+ // Ensure when dealing with replacing an array it is handled being either
+ // an autocreated one or a straight NSArray.
+
+ // The real test here is that nothing crashes while doing the work.
+ TestAllTypes *message = [TestAllTypes message];
+ [message.repeatedStringArray addObject:@"foo"];
+ XCTAssertEqual(message.repeatedStringArray_Count, (NSUInteger)1);
+ message.repeatedStringArray = [NSMutableArray arrayWithObjects:@"bar", @"bar2", nil];
+ XCTAssertEqual(message.repeatedStringArray_Count, (NSUInteger)2);
+ message.repeatedStringArray = [NSMutableArray arrayWithObject:@"baz"];
+ XCTAssertEqual(message.repeatedStringArray_Count, (NSUInteger)1);
+}
+
+- (void)testReplaceAutocreatedArray {
+ // Replacing array should orphan the old one and cause its creator to become
+ // visible.
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.iArray);
+ XCTAssertFalse([message hasA]);
+ GPBInt32Array *iArray = [message.a.iArray retain];
+ XCTAssertEqual(iArray->_autocreator, message.a); // Pointer comparision
+ message.a.iArray = [GPBInt32Array arrayWithValue:1];
+ XCTAssertTrue([message hasA]);
+ XCTAssertNotEqual(message.a.iArray, iArray); // Pointer comparision
+ XCTAssertNil(iArray->_autocreator);
+ [iArray release];
+ }
+
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.strArray);
+ XCTAssertFalse([message hasA]);
+ GPBAutocreatedArray *strArray =
+ (GPBAutocreatedArray *)[message.a.strArray retain];
+ XCTAssertTrue([strArray isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertEqual(strArray->_autocreator, message.a); // Pointer comparision
+ message.a.strArray = [NSMutableArray arrayWithObject:@"foo"];
+ XCTAssertTrue([message hasA]);
+ XCTAssertNotEqual(message.a.strArray, strArray); // Pointer comparision
+ XCTAssertNil(strArray->_autocreator);
+ [strArray release];
+ }
+}
+
+- (void)testSetAutocreatedArrayToSelf {
+ // Setting array to itself should cause it to become visible.
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.iArray);
+ XCTAssertFalse([message hasA]);
+ message.a.iArray = message.a.iArray;
+ XCTAssertTrue([message hasA]);
+ XCTAssertNil(message.a.iArray->_autocreator);
+ }
+
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.strArray);
+ XCTAssertFalse([message hasA]);
+ message.a.strArray = message.a.strArray;
+ XCTAssertTrue([message hasA]);
+ XCTAssertTrue([message.a.strArray isKindOfClass:[GPBAutocreatedArray class]]);
+ XCTAssertNil(((GPBAutocreatedArray *)message.a.strArray)->_autocreator);
+ }
+}
+
+- (void)testAutocreatedArrayRemoveAllValues {
+ // Calling removeAllValues on autocreated array should not cause it to be
+ // visible.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ [message.a.iArray removeAll];
+ XCTAssertFalse([message hasA]);
+ [message.a.strArray removeAllObjects];
+ XCTAssertFalse([message hasA]);
+}
+
+- (void)testDefaultingMaps {
+ // Basic tests for default creation of maps in a message.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ TestRecursiveMessageWithRepeatedField *message2 =
+ [TestRecursiveMessageWithRepeatedField message];
+
+ // Simply accessing the map should not make any fields visible.
+ XCTAssertNotNil(message.a.a.iToI);
+ XCTAssertFalse([message hasA]);
+ XCTAssertFalse([message.a hasA]);
+ XCTAssertNotNil(message2.a.a.strToStr);
+ XCTAssertFalse([message2 hasA]);
+ XCTAssertFalse([message2.a hasA]);
+
+ // But adding an element to the map should.
+ [message.a.a.iToI setInt32:100 forKey:200];
+ XCTAssertTrue([message hasA]);
+ XCTAssertTrue([message.a hasA]);
+ XCTAssertEqual([message.a.a.iToI count], (NSUInteger)1);
+ [message2.a.a.strToStr setObject:@"foo" forKey:@"bar"];
+ XCTAssertTrue([message2 hasA]);
+ XCTAssertTrue([message2.a hasA]);
+ XCTAssertEqual([message2.a.a.strToStr count], (NSUInteger)1);
+}
+
+- (void)testAutocreatedMapShared {
+ // Multiple objects pointing to the same map.
+ TestRecursiveMessageWithRepeatedField *message1a =
+ [TestRecursiveMessageWithRepeatedField message];
+ TestRecursiveMessageWithRepeatedField *message1b =
+ [TestRecursiveMessageWithRepeatedField message];
+ message1a.a.iToI = message1b.a.iToI;
+ XCTAssertTrue([message1a hasA]);
+ XCTAssertFalse([message1b hasA]);
+ [message1a.a.iToI setInt32:1 forKey:2];
+ XCTAssertTrue([message1a hasA]);
+ XCTAssertTrue([message1b hasA]);
+ XCTAssertEqual(message1a.a.iToI, message1b.a.iToI);
+
+ TestRecursiveMessageWithRepeatedField *message2a =
+ [TestRecursiveMessageWithRepeatedField message];
+ TestRecursiveMessageWithRepeatedField *message2b =
+ [TestRecursiveMessageWithRepeatedField message];
+ message2a.a.strToStr = message2b.a.strToStr;
+ XCTAssertTrue([message2a hasA]);
+ XCTAssertFalse([message2b hasA]);
+ [message2a.a.strToStr setObject:@"bar" forKey:@"foo"];
+ XCTAssertTrue([message2a hasA]);
+ XCTAssertTrue([message2b hasA]);
+ XCTAssertEqual(message2a.a.strToStr, message2b.a.strToStr);
+}
+
+- (void)testAutocreatedMapCopy {
+ // Copy should not copy autocreated maps.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.strToStr);
+ XCTAssertNotNil(message.iToI);
+ TestRecursiveMessageWithRepeatedField *message2 =
+ [[message copy] autorelease];
+ // Pointer conparisions.
+ XCTAssertNotEqual(message.strToStr, message2.strToStr);
+ XCTAssertNotEqual(message.iToI, message2.iToI);
+
+ // Mutable copy should copy empty arrays that were explicitly set (end up
+ // with different objects that are equal).
+ TestRecursiveMessageWithRepeatedField *message3 =
+ [TestRecursiveMessageWithRepeatedField message];
+ message3.iToI = [GPBInt32Int32Dictionary dictionaryWithInt32:10 forKey:20];
+ message3.strToStr =
+ [NSMutableDictionary dictionaryWithObject:@"abc" forKey:@"123"];
+ XCTAssertNotNil(message.iToI);
+ XCTAssertNotNil(message.iToI);
+ TestRecursiveMessageWithRepeatedField *message4 =
+ [[message3 copy] autorelease];
+ XCTAssertNotEqual(message3.iToI, message4.iToI);
+ XCTAssertEqualObjects(message3.iToI, message4.iToI);
+ XCTAssertNotEqual(message3.strToStr, message4.strToStr);
+ XCTAssertEqualObjects(message3.strToStr, message4.strToStr);
+}
+
+- (void)testAutocreatedMapRetain {
+ // Should be able to retain autocreated map while the creator is dealloced.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+
+ @autoreleasepool {
+ TestRecursiveMessageWithRepeatedField *message2 =
+ [TestRecursiveMessageWithRepeatedField message];
+ message.iToI = message2.iToI;
+ message.strToStr = message2.strToStr;
+ // Pointer conparision
+ XCTAssertEqual(message.iToI->_autocreator, message2);
+ XCTAssertTrue([message.strToStr
+ isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(
+ ((GPBAutocreatedDictionary *)message.strToStr)->_autocreator,
+ message2);
+ }
+
+ XCTAssertNil(message.iToI->_autocreator);
+ XCTAssertTrue(
+ [message.strToStr isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertNil(
+ ((GPBAutocreatedDictionary *)message.strToStr)->_autocreator);
+}
+
+- (void)testSetNilAutocreatedMap {
+ // Setting map to nil should cause it to lose its delegate.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ GPBInt32Int32Dictionary *iToI = [message.iToI retain];
+ GPBAutocreatedDictionary *strToStr =
+ (GPBAutocreatedDictionary *)[message.strToStr retain];
+ XCTAssertTrue([strToStr isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(iToI->_autocreator, message);
+ XCTAssertEqual(strToStr->_autocreator, message);
+ message.iToI = nil;
+ message.strToStr = nil;
+ XCTAssertNil(iToI->_autocreator);
+ XCTAssertNil(strToStr->_autocreator);
+ [iToI release];
+ [strToStr release];
+}
+
+- (void)testSetOverAutocreatedMapAndSetAgain {
+ // Ensure when dealing with replacing a map it is handled being either
+ // an autocreated one or a straight NSDictionary.
+
+ // The real test here is that nothing crashes while doing the work.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ message.strToStr[@"foo"] = @"bar";
+ XCTAssertEqual(message.strToStr_Count, (NSUInteger)1);
+ message.strToStr =
+ [NSMutableDictionary dictionaryWithObjectsAndKeys:@"bar", @"key1", @"baz", @"key2", nil];
+ XCTAssertEqual(message.strToStr_Count, (NSUInteger)2);
+ message.strToStr =
+ [NSMutableDictionary dictionaryWithObject:@"baz" forKey:@"mumble"];
+ XCTAssertEqual(message.strToStr_Count, (NSUInteger)1);
+}
+
+- (void)testReplaceAutocreatedMap {
+ // Replacing map should orphan the old one and cause its creator to become
+ // visible.
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.iToI);
+ XCTAssertFalse([message hasA]);
+ GPBInt32Int32Dictionary *iToI = [message.a.iToI retain];
+ XCTAssertEqual(iToI->_autocreator, message.a); // Pointer comparision
+ message.a.iToI = [GPBInt32Int32Dictionary dictionaryWithInt32:6 forKey:7];
+ XCTAssertTrue([message hasA]);
+ XCTAssertNotEqual(message.a.iToI, iToI); // Pointer comparision
+ XCTAssertNil(iToI->_autocreator);
+ [iToI release];
+ }
+
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.strToStr);
+ XCTAssertFalse([message hasA]);
+ GPBAutocreatedDictionary *strToStr =
+ (GPBAutocreatedDictionary *)[message.a.strToStr retain];
+ XCTAssertTrue([strToStr isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertEqual(strToStr->_autocreator, message.a); // Pointer comparision
+ message.a.strToStr =
+ [NSMutableDictionary dictionaryWithObject:@"abc" forKey:@"def"];
+ XCTAssertTrue([message hasA]);
+ XCTAssertNotEqual(message.a.strToStr, strToStr); // Pointer comparision
+ XCTAssertNil(strToStr->_autocreator);
+ [strToStr release];
+ }
+}
+
+- (void)testSetAutocreatedMapToSelf {
+ // Setting map to itself should cause it to become visible.
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.iToI);
+ XCTAssertFalse([message hasA]);
+ message.a.iToI = message.a.iToI;
+ XCTAssertTrue([message hasA]);
+ XCTAssertNil(message.a.iToI->_autocreator);
+ }
+
+ {
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.strToStr);
+ XCTAssertFalse([message hasA]);
+ message.a.strToStr = message.a.strToStr;
+ XCTAssertTrue([message hasA]);
+ XCTAssertTrue([message.a.strToStr isKindOfClass:[GPBAutocreatedDictionary class]]);
+ XCTAssertNil(((GPBAutocreatedDictionary *)message.a.strToStr)->_autocreator);
+ }
+}
+
+- (void)testAutocreatedMapRemoveAllValues {
+ // Calling removeAll on autocreated map should not cause it to be visible.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ [message.a.iToI removeAll];
+ XCTAssertFalse([message hasA]);
+ [message.a.strToStr removeAllObjects];
+ XCTAssertFalse([message hasA]);
+}
+
+- (void)testExtensionAccessors {
+ TestAllExtensions *message = [TestAllExtensions message];
+ [self setAllExtensions:message repeatedCount:kGPBDefaultRepeatCount];
+ [self assertAllExtensionsSet:message repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testExtensionRepeatedSetters {
+ TestAllExtensions *message = [TestAllExtensions message];
+ [self setAllExtensions:message repeatedCount:kGPBDefaultRepeatCount];
+ [self modifyRepeatedExtensions:message];
+ [self assertRepeatedExtensionsModified:message
+ repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testExtensionDefaults {
+ [self assertExtensionsClear:[TestAllExtensions message]];
+}
+
+- (void)testExtensionIsEquals {
+ TestAllExtensions *message = [TestAllExtensions message];
+ [self setAllExtensions:message repeatedCount:kGPBDefaultRepeatCount];
+ [self modifyRepeatedExtensions:message];
+ TestAllExtensions *message2 = [TestAllExtensions message];
+ [self setAllExtensions:message2 repeatedCount:kGPBDefaultRepeatCount];
+ XCTAssertFalse([message isEqual:message2]);
+ message2 = [TestAllExtensions message];
+ [self setAllExtensions:message2 repeatedCount:kGPBDefaultRepeatCount];
+ [self modifyRepeatedExtensions:message2];
+ XCTAssertEqualObjects(message, message2);
+}
+
+- (void)testExtensionsMergeFrom {
+ TestAllExtensions *message = [TestAllExtensions message];
+ [self setAllExtensions:message repeatedCount:kGPBDefaultRepeatCount];
+ [self modifyRepeatedExtensions:message];
+
+ message = [TestAllExtensions message];
+ [self setAllExtensions:message repeatedCount:kGPBDefaultRepeatCount];
+ TestAllExtensions *message2 = [TestAllExtensions message];
+ [self modifyRepeatedExtensions:message2];
+ [message2 mergeFrom:message];
+
+ XCTAssertEqualObjects(message, message2);
+}
+
+- (void)testDefaultingExtensionMessages {
+ TestAllExtensions *message = [TestAllExtensions message];
+
+ // Initially they should all not have values.
+
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ XCTAssertFalse(
+ [message hasExtension:[UnittestRoot optionalNestedMessageExtension]]);
+ XCTAssertFalse(
+ [message hasExtension:[UnittestRoot optionalForeignMessageExtension]]);
+ XCTAssertFalse(
+ [message hasExtension:[UnittestRoot optionalImportMessageExtension]]);
+ XCTAssertFalse([message
+ hasExtension:[UnittestRoot optionalPublicImportMessageExtension]]);
+ XCTAssertFalse(
+ [message hasExtension:[UnittestRoot optionalLazyMessageExtension]]);
+
+ // They should auto create something when fetched.
+
+ TestAllTypes_OptionalGroup *optionalGroup =
+ [message getExtension:[UnittestRoot optionalGroupExtension]];
+ TestAllTypes_NestedMessage *optionalNestedMessage =
+ [message getExtension:[UnittestRoot optionalNestedMessageExtension]];
+ ForeignMessage *optionalForeignMessage =
+ [message getExtension:[UnittestRoot optionalForeignMessageExtension]];
+ ImportMessage *optionalImportMessage =
+ [message getExtension:[UnittestRoot optionalImportMessageExtension]];
+ PublicImportMessage *optionalPublicImportMessage = [message
+ getExtension:[UnittestRoot optionalPublicImportMessageExtension]];
+ TestAllTypes_NestedMessage *optionalLazyMessage =
+ [message getExtension:[UnittestRoot optionalLazyMessageExtension]];
+
+ XCTAssertNotNil(optionalGroup);
+ XCTAssertNotNil(optionalNestedMessage);
+ XCTAssertNotNil(optionalForeignMessage);
+ XCTAssertNotNil(optionalImportMessage);
+ XCTAssertNotNil(optionalPublicImportMessage);
+ XCTAssertNotNil(optionalLazyMessage);
+
+ // Although it auto-created empty messages, it should not show that it has
+ // them.
+
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalNestedMessageExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalForeignMessageExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalImportMessageExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalPublicImportMessageExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalLazyMessageExtension]]);
+
+ // And they set that value back in to the message since the value created was
+ // mutable (so a second fetch should give the same object).
+
+ XCTAssertEqual([message getExtension:[UnittestRoot optionalGroupExtension]],
+ optionalGroup);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalNestedMessageExtension]],
+ optionalNestedMessage);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalForeignMessageExtension]],
+ optionalForeignMessage);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalImportMessageExtension]],
+ optionalImportMessage);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalPublicImportMessageExtension]],
+ optionalPublicImportMessage);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalLazyMessageExtension]],
+ optionalLazyMessage);
+
+ // And the default objects for a second message should be distinct (again,
+ // since they are mutable, each needs their own copy).
+
+ TestAllExtensions *message2 = [TestAllExtensions message];
+
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual(
+ [message2 getExtension:[UnittestRoot optionalGroupExtension]],
+ optionalGroup);
+ XCTAssertNotEqual(
+ [message2 getExtension:[UnittestRoot optionalNestedMessageExtension]],
+ optionalNestedMessage);
+ XCTAssertNotEqual(
+ [message2 getExtension:[UnittestRoot optionalForeignMessageExtension]],
+ optionalForeignMessage);
+ XCTAssertNotEqual(
+ [message2 getExtension:[UnittestRoot optionalImportMessageExtension]],
+ optionalImportMessage);
+ XCTAssertNotEqual(
+ [message2 getExtension:[UnittestRoot optionalPublicImportMessageExtension]],
+ optionalPublicImportMessage);
+ XCTAssertNotEqual(
+ [message2 getExtension:[UnittestRoot optionalLazyMessageExtension]],
+ optionalLazyMessage);
+
+ // Clear values, and on next access you get back new submessages.
+
+ [message setExtension:[UnittestRoot optionalGroupExtension] value:nil];
+ [message setExtension:[UnittestRoot optionalGroupExtension] value:nil];
+ [message setExtension:[UnittestRoot optionalNestedMessageExtension]
+ value:nil];
+ [message setExtension:[UnittestRoot optionalForeignMessageExtension]
+ value:nil];
+ [message setExtension:[UnittestRoot optionalImportMessageExtension]
+ value:nil];
+ [message setExtension:[UnittestRoot optionalPublicImportMessageExtension]
+ value:nil];
+ [message setExtension:[UnittestRoot optionalLazyMessageExtension] value:nil];
+
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ XCTAssertFalse(
+ [message hasExtension:[UnittestRoot optionalNestedMessageExtension]]);
+ XCTAssertFalse(
+ [message hasExtension:[UnittestRoot optionalForeignMessageExtension]]);
+ XCTAssertFalse(
+ [message hasExtension:[UnittestRoot optionalImportMessageExtension]]);
+ XCTAssertFalse([message
+ hasExtension:[UnittestRoot optionalPublicImportMessageExtension]]);
+ XCTAssertFalse(
+ [message hasExtension:[UnittestRoot optionalLazyMessageExtension]]);
+
+ XCTAssertEqual([message getExtension:[UnittestRoot optionalGroupExtension]],
+ optionalGroup);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalNestedMessageExtension]],
+ optionalNestedMessage);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalForeignMessageExtension]],
+ optionalForeignMessage);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalImportMessageExtension]],
+ optionalImportMessage);
+ XCTAssertEqual(
+ [message
+ getExtension:[UnittestRoot optionalPublicImportMessageExtension]],
+ optionalPublicImportMessage);
+ XCTAssertEqual(
+ [message getExtension:[UnittestRoot optionalLazyMessageExtension]],
+ optionalLazyMessage);
+}
+
+- (void)testMultiplePointersToAutocreatedExtension {
+ // 2 objects point to the same auto-created extension. One should "has" it.
+ // The other should not.
+ TestAllExtensions *message = [TestAllExtensions message];
+ TestAllExtensions *message2 = [TestAllExtensions message];
+ GPBExtensionDescriptor *extension = [UnittestRoot optionalGroupExtension];
+ [message setExtension:extension value:[message2 getExtension:extension]];
+ XCTAssertEqual([message getExtension:extension],
+ [message2 getExtension:extension]);
+ XCTAssertFalse([message2 hasExtension:extension]);
+ XCTAssertTrue([message hasExtension:extension]);
+
+ TestAllTypes_OptionalGroup *extensionValue =
+ [message2 getExtension:extension];
+ extensionValue.a = 1;
+ XCTAssertTrue([message2 hasExtension:extension]);
+ XCTAssertTrue([message hasExtension:extension]);
+}
+
+- (void)testCopyWithAutocreatedExtension {
+ // Mutable copy shouldn't copy autocreated extensions.
+ TestAllExtensions *message = [TestAllExtensions message];
+ GPBExtensionDescriptor *optionalGroupExtension =
+ [UnittestRoot optionalGroupExtension];
+ GPBExtensionDescriptor *optionalNestedMessageExtesion =
+ [UnittestRoot optionalNestedMessageExtension];
+ TestAllTypes_OptionalGroup *optionalGroup =
+ [message getExtension:optionalGroupExtension];
+ optionalGroup.a = 42;
+ XCTAssertNotNil(optionalGroup);
+ XCTAssertNotNil([message getExtension:optionalNestedMessageExtesion]);
+ XCTAssertTrue([message hasExtension:optionalGroupExtension]);
+ XCTAssertFalse([message hasExtension:optionalNestedMessageExtesion]);
+
+ TestAllExtensions *message2 = [[message copy] autorelease];
+
+ // message2 should end up with its own copy of the optional group.
+ XCTAssertTrue([message2 hasExtension:optionalGroupExtension]);
+ XCTAssertEqualObjects([message getExtension:optionalGroupExtension],
+ [message2 getExtension:optionalGroupExtension]);
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual([message getExtension:optionalGroupExtension],
+ [message2 getExtension:optionalGroupExtension]);
+
+ XCTAssertFalse([message2 hasExtension:optionalNestedMessageExtesion]);
+ // Intentionally doing a pointer comparison (auto creation should be
+ // different)
+ XCTAssertNotEqual([message getExtension:optionalNestedMessageExtesion],
+ [message2 getExtension:optionalNestedMessageExtesion]);
+}
+
+- (void)testClearMessageAutocreatedExtension {
+ // Call clear should cause it to recreate its autocreated extensions.
+ TestAllExtensions *message = [TestAllExtensions message];
+ GPBExtensionDescriptor *optionalGroupExtension =
+ [UnittestRoot optionalGroupExtension];
+ TestAllTypes_OptionalGroup *optionalGroup =
+ [[message getExtension:optionalGroupExtension] retain];
+ [message clear];
+ TestAllTypes_OptionalGroup *optionalGroupNew =
+ [message getExtension:optionalGroupExtension];
+
+ // Intentionally doing a pointer comparison.
+ XCTAssertNotEqual(optionalGroup, optionalGroupNew);
+ [optionalGroup release];
+}
+
+- (void)testRetainAutocreatedExtension {
+ // Should be able to retain autocreated extension while the creator is
+ // dealloced.
+ TestAllExtensions *message = [TestAllExtensions message];
+ GPBExtensionDescriptor *optionalGroupExtension =
+ [UnittestRoot optionalGroupExtension];
+
+ @autoreleasepool {
+ TestAllExtensions *message2 = [TestAllExtensions message];
+ [message setExtension:optionalGroupExtension
+ value:[message2 getExtension:optionalGroupExtension]];
+ XCTAssertTrue(GPBWasMessageAutocreatedBy(
+ [message getExtension:optionalGroupExtension], message2));
+ }
+
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(
+ [message getExtension:optionalGroupExtension], message));
+}
+
+- (void)testClearAutocreatedExtension {
+ // Clearing autocreated extension should NOT cause it to lose its creator.
+ TestAllExtensions *message = [TestAllExtensions message];
+ GPBExtensionDescriptor *optionalGroupExtension =
+ [UnittestRoot optionalGroupExtension];
+ TestAllTypes_OptionalGroup *optionalGroup =
+ [[message getExtension:optionalGroupExtension] retain];
+ [message clearExtension:optionalGroupExtension];
+ TestAllTypes_OptionalGroup *optionalGroupNew =
+ [message getExtension:optionalGroupExtension];
+ XCTAssertEqual(optionalGroup, optionalGroupNew);
+ XCTAssertFalse([message hasExtension:optionalGroupExtension]);
+ [optionalGroup release];
+
+ // Clearing autocreated extension should not cause its creator to become
+ // visible
+ GPBExtensionDescriptor *recursiveExtension =
+ [UnittestObjcRoot recursiveExtension];
+ TestAllExtensions *message_lvl2 = [message getExtension:recursiveExtension];
+ TestAllExtensions *message_lvl3 =
+ [message_lvl2 getExtension:recursiveExtension];
+ [message_lvl3 clearExtension:recursiveExtension];
+ XCTAssertFalse([message hasExtension:recursiveExtension]);
+}
+
+- (void)testSetAutocreatedExtensionBecomesVisible {
+ // Setting an extension should cause the extension to appear to its creator.
+ // Test this several levels deep.
+ TestAllExtensions *message = [TestAllExtensions message];
+ GPBExtensionDescriptor *recursiveExtension =
+ [UnittestObjcRoot recursiveExtension];
+ TestAllExtensions *message_lvl2 = [message getExtension:recursiveExtension];
+ TestAllExtensions *message_lvl3 =
+ [message_lvl2 getExtension:recursiveExtension];
+ TestAllExtensions *message_lvl4 =
+ [message_lvl3 getExtension:recursiveExtension];
+ XCTAssertFalse([message hasExtension:recursiveExtension]);
+ XCTAssertFalse([message_lvl2 hasExtension:recursiveExtension]);
+ XCTAssertFalse([message_lvl3 hasExtension:recursiveExtension]);
+ XCTAssertFalse([message_lvl4 hasExtension:recursiveExtension]);
+ [message_lvl4 setExtension:[UnittestRoot optionalInt32Extension] value:@(1)];
+ XCTAssertTrue([message hasExtension:recursiveExtension]);
+ XCTAssertTrue([message_lvl2 hasExtension:recursiveExtension]);
+ XCTAssertTrue([message_lvl3 hasExtension:recursiveExtension]);
+ XCTAssertFalse([message_lvl4 hasExtension:recursiveExtension]);
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(message_lvl4, message_lvl3));
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(message_lvl3, message_lvl2));
+ XCTAssertFalse(GPBWasMessageAutocreatedBy(message_lvl2, message));
+}
+
+- (void)testSetAutocreatedExtensionToSelf {
+ // Setting extension to itself should cause it to become visible.
+ TestAllExtensions *message = [TestAllExtensions message];
+ GPBExtensionDescriptor *optionalGroupExtension =
+ [UnittestRoot optionalGroupExtension];
+ XCTAssertNotNil([message getExtension:optionalGroupExtension]);
+ XCTAssertFalse([message hasExtension:optionalGroupExtension]);
+ [message setExtension:optionalGroupExtension
+ value:[message getExtension:optionalGroupExtension]];
+ XCTAssertTrue([message hasExtension:optionalGroupExtension]);
+}
+
+- (void)testAutocreatedExtensionMemoryLeaks {
+ GPBExtensionDescriptor *recursiveExtension =
+ [UnittestObjcRoot recursiveExtension];
+
+ // Test for memory leaks with autocreated extensions.
+ TestAllExtensions *message;
+ TestAllExtensions *message_lvl2;
+ TestAllExtensions *message_lvl3;
+ TestAllExtensions *message_lvl4;
+ @autoreleasepool {
+ message = [[TestAllExtensions alloc] init];
+ message_lvl2 = [[message getExtension:recursiveExtension] retain];
+ message_lvl3 = [[message_lvl2 getExtension:recursiveExtension] retain];
+ message_lvl4 = [[message_lvl3 getExtension:recursiveExtension] retain];
+ [message_lvl2 setExtension:[UnittestRoot optionalInt32Extension]
+ value:@(1)];
+ }
+
+ XCTAssertEqual(message.retainCount, (NSUInteger)1);
+ @autoreleasepool {
+ [message release];
+ }
+ XCTAssertEqual(message_lvl2.retainCount, (NSUInteger)1);
+ @autoreleasepool {
+ [message_lvl2 release];
+ }
+ XCTAssertEqual(message_lvl3.retainCount, (NSUInteger)1);
+ @autoreleasepool {
+ [message_lvl3 release];
+ }
+ XCTAssertEqual(message_lvl4.retainCount, (NSUInteger)1);
+ [message_lvl4 release];
+}
+
+- (void)testSetExtensionWithAutocreatedValue {
+ GPBExtensionDescriptor *recursiveExtension =
+ [UnittestObjcRoot recursiveExtension];
+
+ TestAllExtensions *message;
+ @autoreleasepool {
+ message = [[TestAllExtensions alloc] init];
+ [message getExtension:recursiveExtension];
+ }
+
+ // This statements checks that the extension value isn't accidentally
+ // dealloced when removing it from the autocreated map.
+ [message setExtension:recursiveExtension
+ value:[message getExtension:recursiveExtension]];
+ XCTAssertTrue([message hasExtension:recursiveExtension]);
+ [message release];
+}
+
+- (void)testRecursion {
+ TestRecursiveMessage *message = [TestRecursiveMessage message];
+ XCTAssertNotNil(message.a);
+ XCTAssertNotNil(message.a.a);
+ XCTAssertEqual(message.a.a.i, 0);
+}
+
+- (void)testGenerateAndParseUnknownMessage {
+ GPBUnknownFieldSet *unknowns =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+ [unknowns mergeVarintField:123 value:456];
+ GPBMessage *message = [GPBMessage message];
+ [message setUnknownFields:unknowns];
+ NSData *data = [message data];
+ GPBMessage *message2 =
+ [GPBMessage parseFromData:data extensionRegistry:nil error:NULL];
+ XCTAssertEqualObjects(message, message2);
+}
+
+- (void)testDelimitedWriteAndParseMultipleMessages {
+ GPBUnknownFieldSet *unknowns1 =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+ [unknowns1 mergeVarintField:123 value:456];
+ GPBMessage *message1 = [GPBMessage message];
+ [message1 setUnknownFields:unknowns1];
+
+ GPBUnknownFieldSet *unknowns2 =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+ [unknowns2 mergeVarintField:789 value:987];
+ [unknowns2 mergeVarintField:654 value:321];
+ GPBMessage *message2 = [GPBMessage message];
+ [message2 setUnknownFields:unknowns2];
+
+ NSMutableData *delimitedData = [NSMutableData data];
+ [delimitedData appendData:[message1 delimitedData]];
+ [delimitedData appendData:[message2 delimitedData]];
+ GPBCodedInputStream *input =
+ [GPBCodedInputStream streamWithData:delimitedData];
+ GPBMessage *message3 = [GPBMessage parseDelimitedFromCodedInputStream:input
+ extensionRegistry:nil
+ error:NULL];
+ GPBMessage *message4 = [GPBMessage parseDelimitedFromCodedInputStream:input
+ extensionRegistry:nil
+ error:NULL];
+ XCTAssertEqualObjects(message1, message3);
+ XCTAssertEqualObjects(message2, message4);
+}
+
+- (void)testDuplicateEnums {
+ XCTAssertEqual(TestEnumWithDupValue_Foo1, TestEnumWithDupValue_Foo2);
+}
+
+- (void)testWeirdDefaults {
+ ObjcWeirdDefaults *message = [ObjcWeirdDefaults message];
+ GPBDescriptor *descriptor = [[message class] descriptor];
+ GPBFieldDescriptor *fieldDesc = [descriptor fieldWithName:@"foo"];
+ XCTAssertNotNil(fieldDesc);
+ XCTAssertTrue(fieldDesc.hasDefaultValue);
+ XCTAssertFalse(message.hasFoo);
+ XCTAssertEqualObjects(message.foo, @"");
+
+ fieldDesc = [descriptor fieldWithName:@"bar"];
+ XCTAssertNotNil(fieldDesc);
+ XCTAssertTrue(fieldDesc.hasDefaultValue);
+ XCTAssertFalse(message.hasBar);
+ XCTAssertEqualObjects(message.bar, GPBEmptyNSData());
+}
+
+- (void)testEnumDescriptorFromExtensionDescriptor {
+ GPBExtensionDescriptor *extDescriptor =
+ [UnittestRoot optionalForeignEnumExtension];
+ XCTAssertEqual(extDescriptor.dataType, GPBDataTypeEnum);
+ GPBEnumDescriptor *enumDescriptor = extDescriptor.enumDescriptor;
+ GPBEnumDescriptor *expectedDescriptor = ForeignEnum_EnumDescriptor();
+ XCTAssertEqualObjects(enumDescriptor, expectedDescriptor);
+}
+
+- (void)testPropertyNaming {
+ // objectivec_helpers.cc has some special handing to get proper all caps
+ // for a few cases to meet objc developer expectations.
+ //
+ // This "test" confirms that the expected names are generated, otherwise the
+ // test itself will fail to compile.
+ ObjCPropertyNaming *msg = [ObjCPropertyNaming message];
+ // On their own, at the end, in the middle.
+ msg.URL = @"good";
+ msg.thumbnailURL = @"good";
+ msg.URLFoo = @"good";
+ msg.someURLBlah = @"good";
+ msg.HTTP = @"good";
+ msg.HTTPS = @"good";
+ // No caps since it was "urls".
+ [msg.urlsArray addObject:@"good"];
+}
+
+- (void)testEnumNaming {
+ // objectivec_helpers.cc has some interesting cases to deal with in
+ // EnumValueName/EnumValueShortName. Confirm that things generated as
+ // expected.
+
+ // This block just has to compile to confirm we got the expected types/names.
+ // The *_IsValidValue() calls are just there to keep the projects warnings
+ // flags happy by providing use of the variables/values.
+
+ Foo aFoo = Foo_SerializedSize;
+ Foo_IsValidValue(aFoo);
+ aFoo = Foo_Size;
+ Foo_IsValidValue(aFoo);
+
+ Category_Enum aCat = Category_Enum_Red;
+ Category_Enum_IsValidValue(aCat);
+
+ Time aTime = Time_Base;
+ Time_IsValidValue(aTime);
+ aTime = Time_SomethingElse;
+ Time_IsValidValue(aTime);
+
+ // This block confirms the names in the decriptors is what we wanted.
+
+ GPBEnumDescriptor *descriptor;
+ NSString *valueName;
+
+ descriptor = Foo_EnumDescriptor();
+ XCTAssertNotNil(descriptor);
+ XCTAssertEqualObjects(@"Foo", descriptor.name);
+ valueName = [descriptor enumNameForValue:Foo_SerializedSize];
+ XCTAssertEqualObjects(@"Foo_SerializedSize", valueName);
+ valueName = [descriptor enumNameForValue:Foo_Size];
+ XCTAssertEqualObjects(@"Foo_Size", valueName);
+
+ descriptor = Category_Enum_EnumDescriptor();
+ XCTAssertNotNil(descriptor);
+ XCTAssertEqualObjects(@"Category_Enum", descriptor.name);
+ valueName = [descriptor enumNameForValue:Category_Enum_Red];
+ XCTAssertEqualObjects(@"Category_Enum_Red", valueName);
+
+ descriptor = Time_EnumDescriptor();
+ XCTAssertNotNil(descriptor);
+ XCTAssertEqualObjects(@"Time", descriptor.name);
+ valueName = [descriptor enumNameForValue:Time_Base];
+ XCTAssertEqualObjects(@"Time_Base", valueName);
+ valueName = [descriptor enumNameForValue:Time_SomethingElse];
+ XCTAssertEqualObjects(@"Time_SomethingElse", valueName);
+}
+
+- (void)testNegativeEnums {
+ EnumTestMsg *msg = [EnumTestMsg message];
+
+ // Defaults
+ XCTAssertEqual(msg.foo, EnumTestMsg_MyEnum_Zero);
+ XCTAssertEqual(msg.bar, EnumTestMsg_MyEnum_One);
+ XCTAssertEqual(msg.baz, EnumTestMsg_MyEnum_NegOne);
+ // Bounce to wire and back.
+ NSData *data = [msg data];
+ XCTAssertNotNil(data);
+ EnumTestMsg *msgPrime = [EnumTestMsg parseFromData:data error:NULL];
+ XCTAssertEqualObjects(msgPrime, msg);
+ XCTAssertEqual(msgPrime.foo, EnumTestMsg_MyEnum_Zero);
+ XCTAssertEqual(msgPrime.bar, EnumTestMsg_MyEnum_One);
+ XCTAssertEqual(msgPrime.baz, EnumTestMsg_MyEnum_NegOne);
+
+ // Other values
+ msg.bar = EnumTestMsg_MyEnum_Two;
+ msg.baz = EnumTestMsg_MyEnum_NegTwo;
+ XCTAssertEqual(msg.bar, EnumTestMsg_MyEnum_Two);
+ XCTAssertEqual(msg.baz, EnumTestMsg_MyEnum_NegTwo);
+ // Bounce to wire and back.
+ data = [msg data];
+ XCTAssertNotNil(data);
+ msgPrime = [EnumTestMsg parseFromData:data error:NULL];
+ XCTAssertEqualObjects(msgPrime, msg);
+ XCTAssertEqual(msgPrime.foo, EnumTestMsg_MyEnum_Zero);
+ XCTAssertEqual(msgPrime.bar, EnumTestMsg_MyEnum_Two);
+ XCTAssertEqual(msgPrime.baz, EnumTestMsg_MyEnum_NegTwo);
+
+ // Repeated field (shouldn't ever be an issue since developer has to use the
+ // right GPBArray methods themselves).
+ msg.mumbleArray = [GPBEnumArray
+ arrayWithValidationFunction:EnumTestMsg_MyEnum_IsValidValue];
+ [msg.mumbleArray addValue:EnumTestMsg_MyEnum_Zero];
+ [msg.mumbleArray addValue:EnumTestMsg_MyEnum_One];
+ [msg.mumbleArray addValue:EnumTestMsg_MyEnum_Two];
+ [msg.mumbleArray addValue:EnumTestMsg_MyEnum_NegOne];
+ [msg.mumbleArray addValue:EnumTestMsg_MyEnum_NegTwo];
+ XCTAssertEqual([msg.mumbleArray valueAtIndex:0], EnumTestMsg_MyEnum_Zero);
+ XCTAssertEqual([msg.mumbleArray valueAtIndex:1], EnumTestMsg_MyEnum_One);
+ XCTAssertEqual([msg.mumbleArray valueAtIndex:2], EnumTestMsg_MyEnum_Two);
+ XCTAssertEqual([msg.mumbleArray valueAtIndex:3], EnumTestMsg_MyEnum_NegOne);
+ XCTAssertEqual([msg.mumbleArray valueAtIndex:4], EnumTestMsg_MyEnum_NegTwo);
+ // Bounce to wire and back.
+ data = [msg data];
+ XCTAssertNotNil(data);
+ msgPrime = [EnumTestMsg parseFromData:data error:NULL];
+ XCTAssertEqualObjects(msgPrime, msg);
+ XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:0],
+ EnumTestMsg_MyEnum_Zero);
+ XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:1], EnumTestMsg_MyEnum_One);
+ XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:2], EnumTestMsg_MyEnum_Two);
+ XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:3],
+ EnumTestMsg_MyEnum_NegOne);
+ XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:4],
+ EnumTestMsg_MyEnum_NegTwo);
+}
+
+- (void)testOneBasedEnumHolder {
+ // Test case for https://github.com/google/protobuf/issues/1453
+ // Message with no explicit defaults, but a non zero default for an enum.
+ MessageWithOneBasedEnum *enumMsg = [MessageWithOneBasedEnum message];
+ XCTAssertEqual(enumMsg.enumField, MessageWithOneBasedEnum_OneBasedEnum_One);
+}
+
+- (void)testBoolOffsetUsage {
+ // Bools use storage within has_bits; this test ensures that this is honored
+ // in all places where things should crash or fail based on reading out of
+ // field storage instead.
+ BoolOnlyMessage *msg1 = [BoolOnlyMessage message];
+ BoolOnlyMessage *msg2 = [BoolOnlyMessage message];
+
+ msg1.boolField1 = YES;
+ msg2.boolField1 = YES;
+ msg1.boolField3 = YES;
+ msg2.boolField3 = YES;
+ msg1.boolField5 = YES;
+ msg2.boolField5 = YES;
+ msg1.boolField7 = YES;
+ msg2.boolField7 = YES;
+ msg1.boolField9 = YES;
+ msg2.boolField9 = YES;
+ msg1.boolField11 = YES;
+ msg2.boolField11 = YES;
+ msg1.boolField13 = YES;
+ msg2.boolField13 = YES;
+ msg1.boolField15 = YES;
+ msg2.boolField15 = YES;
+ msg1.boolField17 = YES;
+ msg2.boolField17 = YES;
+ msg1.boolField19 = YES;
+ msg2.boolField19 = YES;
+ msg1.boolField21 = YES;
+ msg2.boolField21 = YES;
+ msg1.boolField23 = YES;
+ msg2.boolField23 = YES;
+ msg1.boolField25 = YES;
+ msg2.boolField25 = YES;
+ msg1.boolField27 = YES;
+ msg2.boolField27 = YES;
+ msg1.boolField29 = YES;
+ msg2.boolField29 = YES;
+ msg1.boolField31 = YES;
+ msg2.boolField31 = YES;
+
+ msg1.boolField32 = YES;
+ msg2.boolField32 = YES;
+
+ XCTAssertTrue(msg1 != msg2); // Different pointers.
+ XCTAssertEqual([msg1 hash], [msg2 hash]);
+ XCTAssertEqualObjects(msg1, msg2);
+
+ BoolOnlyMessage *msg1Prime = [[msg1 copy] autorelease];
+ XCTAssertTrue(msg1Prime != msg1); // Different pointers.
+ XCTAssertEqual([msg1 hash], [msg1Prime hash]);
+ XCTAssertEqualObjects(msg1, msg1Prime);
+
+ // Field set in one, but not the other means they don't match (even if
+ // set to default value).
+ msg1Prime.boolField2 = NO;
+ XCTAssertNotEqualObjects(msg1Prime, msg1);
+ // And when set to different values.
+ msg1.boolField2 = YES;
+ XCTAssertNotEqualObjects(msg1Prime, msg1);
+ // And then they match again.
+ msg1.boolField2 = NO;
+ XCTAssertEqualObjects(msg1Prime, msg1);
+ XCTAssertEqual([msg1 hash], [msg1Prime hash]);
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBObjectiveCPlusPlusTest.mm b/third_party/protobuf/objectivec/Tests/GPBObjectiveCPlusPlusTest.mm
new file mode 100644
index 0000000000..9ba8fd0b90
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBObjectiveCPlusPlusTest.mm
@@ -0,0 +1,69 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2013 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+#import "GPBTestUtilities.h"
+
+
+//
+// This is just a compile test (here to make sure things never regress).
+//
+// Objective C++ can run into issues with how the NS_ENUM/CF_ENUM declartion
+// works because of the C++ spec being used for that compilation unit. So
+// the fact that these imports all work without errors/warning means things
+// are still good.
+//
+// The "well know types" should have cross file enums needing imports.
+#import "GPBProtocolBuffers.h"
+// Some of the tests explicitly use cross file enums also.
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestImport.pbobjc.h"
+
+// Sanity check the conditions of the test within the Xcode project.
+#if !__cplusplus
+ #error This isn't compiled as Objective C++?
+#elif __cplusplus >= 201103L
+ // If this trips, it means the Xcode default might have change (or someone
+ // edited the testing project) and it might be time to revisit the GPB_ENUM
+ // define in GPBBootstrap.h.
+ #warning Did the Xcode default for C++ spec change?
+#endif
+
+
+// Dummy XCTest.
+@interface GPBObjectiveCPlusPlusTests : GPBTestCase
+@end
+
+@implementation GPBObjectiveCPlusPlusTests
+- (void)testCPlusPlus {
+ // Nothing, This was a compile test.
+ XCTAssertTrue(YES);
+}
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBPerfTests.m b/third_party/protobuf/objectivec/Tests/GPBPerfTests.m
new file mode 100644
index 0000000000..1259d1460f
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBPerfTests.m
@@ -0,0 +1,307 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2013 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestImport.pbobjc.h"
+#import "google/protobuf/UnittestObjc.pbobjc.h"
+
+//
+// This file really just uses the unittests framework as a testbed to
+// run some simple performance tests. The data can then be used to help
+// evaluate changes to the runtime.
+//
+
+static const uint32_t kRepeatedCount = 100;
+
+@interface PerfTests : GPBTestCase
+@end
+
+@implementation PerfTests
+
+- (void)setUp {
+ // A convenient place to put a break point if you want to connect instruments.
+ [super setUp];
+}
+
+- (void)testMessagePerformance {
+ [self measureBlock:^{
+ for (int i = 0; i < 200; ++i) {
+ TestAllTypes* message = [[TestAllTypes alloc] init];
+ [self setAllFields:message repeatedCount:kRepeatedCount];
+ NSData* rawBytes = [message data];
+ [message release];
+ message = [[TestAllTypes alloc] initWithData:rawBytes error:NULL];
+ [message release];
+ }
+ }];
+}
+
+- (void)testExtensionsPerformance {
+ [self measureBlock:^{
+ for (int i = 0; i < 200; ++i) {
+ TestAllExtensions* message = [[TestAllExtensions alloc] init];
+ [self setAllExtensions:message repeatedCount:kRepeatedCount];
+ NSData* rawBytes = [message data];
+ [message release];
+ TestAllExtensions* message2 =
+ [[TestAllExtensions alloc] initWithData:rawBytes error:NULL];
+ [message2 release];
+ }
+ }];
+}
+
+- (void)testPackedTypesPerformance {
+ [self measureBlock:^{
+ for (int i = 0; i < 1000; ++i) {
+ TestPackedTypes* message = [[TestPackedTypes alloc] init];
+ [self setPackedFields:message repeatedCount:kRepeatedCount];
+ NSData* rawBytes = [message data];
+ [message release];
+ message = [[TestPackedTypes alloc] initWithData:rawBytes error:NULL];
+ [message release];
+ }
+ }];
+}
+
+- (void)testPackedExtensionsPerformance {
+ [self measureBlock:^{
+ for (int i = 0; i < 1000; ++i) {
+ TestPackedExtensions* message = [[TestPackedExtensions alloc] init];
+ [self setPackedExtensions:message repeatedCount:kRepeatedCount];
+ NSData* rawBytes = [message data];
+ [message release];
+ TestPackedExtensions* message2 =
+ [[TestPackedExtensions alloc] initWithData:rawBytes error:NULL];
+ [message2 release];
+ }
+ }];
+}
+
+- (void)testHas {
+ TestAllTypes* message = [self allSetRepeatedCount:1];
+ [self measureBlock:^{
+ for (int i = 0; i < 10000; ++i) {
+ [message hasOptionalInt32];
+ message.hasOptionalInt32 = NO;
+ [message hasOptionalInt32];
+
+ [message hasOptionalInt64];
+ message.hasOptionalInt64 = NO;
+ [message hasOptionalInt64];
+
+ [message hasOptionalUint32];
+ message.hasOptionalUint32 = NO;
+ [message hasOptionalUint32];
+
+ [message hasOptionalUint64];
+ message.hasOptionalUint64 = NO;
+ [message hasOptionalUint64];
+
+ [message hasOptionalSint32];
+ message.hasOptionalSint32 = NO;
+ [message hasOptionalSint32];
+
+ [message hasOptionalSint64];
+ message.hasOptionalSint64 = NO;
+ [message hasOptionalSint64];
+
+ [message hasOptionalFixed32];
+ message.hasOptionalFixed32 = NO;
+ [message hasOptionalFixed32];
+
+ [message hasOptionalFixed64];
+ message.hasOptionalFixed64 = NO;
+ [message hasOptionalFixed64];
+
+ [message hasOptionalSfixed32];
+ message.hasOptionalSfixed32 = NO;
+ [message hasOptionalSfixed32];
+
+ [message hasOptionalSfixed64];
+ message.hasOptionalSfixed64 = NO;
+ [message hasOptionalSfixed64];
+
+ [message hasOptionalFloat];
+ message.hasOptionalFloat = NO;
+ [message hasOptionalFloat];
+
+ [message hasOptionalDouble];
+ message.hasOptionalDouble = NO;
+ [message hasOptionalDouble];
+
+ [message hasOptionalBool];
+ message.hasOptionalBool = NO;
+ [message hasOptionalBool];
+
+ [message hasOptionalString];
+ message.hasOptionalString = NO;
+ [message hasOptionalString];
+
+ [message hasOptionalBytes];
+ message.hasOptionalBytes = NO;
+ [message hasOptionalBytes];
+
+ [message hasOptionalGroup];
+ message.hasOptionalGroup = NO;
+ [message hasOptionalGroup];
+
+ [message hasOptionalNestedMessage];
+ message.hasOptionalNestedMessage = NO;
+ [message hasOptionalNestedMessage];
+
+ [message hasOptionalForeignMessage];
+ message.hasOptionalForeignMessage = NO;
+ [message hasOptionalForeignMessage];
+
+ [message hasOptionalImportMessage];
+ message.hasOptionalImportMessage = NO;
+ [message hasOptionalImportMessage];
+
+ [message.optionalGroup hasA];
+ message.optionalGroup.hasA = NO;
+ [message.optionalGroup hasA];
+
+ [message.optionalNestedMessage hasBb];
+ message.optionalNestedMessage.hasBb = NO;
+ [message.optionalNestedMessage hasBb];
+
+ [message.optionalForeignMessage hasC];
+ message.optionalForeignMessage.hasC = NO;
+ [message.optionalForeignMessage hasC];
+
+ [message.optionalImportMessage hasD];
+ message.optionalImportMessage.hasD = NO;
+ [message.optionalImportMessage hasD];
+
+ [message hasOptionalNestedEnum];
+ message.hasOptionalNestedEnum = NO;
+ [message hasOptionalNestedEnum];
+
+ [message hasOptionalForeignEnum];
+ message.hasOptionalForeignEnum = NO;
+ [message hasOptionalForeignEnum];
+
+ [message hasOptionalImportEnum];
+ message.hasOptionalImportEnum = NO;
+ [message hasOptionalImportEnum];
+
+ [message hasOptionalStringPiece];
+ message.hasOptionalStringPiece = NO;
+ [message hasOptionalStringPiece];
+
+ [message hasOptionalCord];
+ message.hasOptionalCord = NO;
+ [message hasOptionalCord];
+
+ [message hasDefaultInt32];
+ message.hasDefaultInt32 = NO;
+ [message hasDefaultInt32];
+
+ [message hasDefaultInt64];
+ message.hasDefaultInt64 = NO;
+ [message hasDefaultInt64];
+
+ [message hasDefaultUint32];
+ message.hasDefaultUint32 = NO;
+ [message hasDefaultUint32];
+
+ [message hasDefaultUint64];
+ message.hasDefaultUint64 = NO;
+ [message hasDefaultUint64];
+
+ [message hasDefaultSint32];
+ message.hasDefaultSint32 = NO;
+ [message hasDefaultSint32];
+
+ [message hasDefaultSint64];
+ message.hasDefaultSint64 = NO;
+ [message hasDefaultSint64];
+
+ [message hasDefaultFixed32];
+ message.hasDefaultFixed32 = NO;
+ [message hasDefaultFixed32];
+
+ [message hasDefaultFixed64];
+ message.hasDefaultFixed64 = NO;
+ [message hasDefaultFixed64];
+
+ [message hasDefaultSfixed32];
+ message.hasDefaultSfixed32 = NO;
+ [message hasDefaultSfixed32];
+
+ [message hasDefaultSfixed64];
+ message.hasDefaultSfixed64 = NO;
+ [message hasDefaultSfixed64];
+
+ [message hasDefaultFloat];
+ message.hasDefaultFloat = NO;
+ [message hasDefaultFloat];
+
+ [message hasDefaultDouble];
+ message.hasDefaultDouble = NO;
+ [message hasDefaultDouble];
+
+ [message hasDefaultBool];
+ message.hasDefaultBool = NO;
+ [message hasDefaultBool];
+
+ [message hasDefaultString];
+ message.hasDefaultString = NO;
+ [message hasDefaultString];
+
+ [message hasDefaultBytes];
+ message.hasDefaultBytes = NO;
+ [message hasDefaultBytes];
+
+ [message hasDefaultNestedEnum];
+ message.hasDefaultNestedEnum = NO;
+ [message hasDefaultNestedEnum];
+
+ [message hasDefaultForeignEnum];
+ message.hasDefaultForeignEnum = NO;
+ [message hasDefaultForeignEnum];
+
+ [message hasDefaultImportEnum];
+ message.hasDefaultImportEnum = NO;
+ [message hasDefaultImportEnum];
+
+ [message hasDefaultStringPiece];
+ message.hasDefaultStringPiece = NO;
+ [message hasDefaultStringPiece];
+
+ [message hasDefaultCord];
+ message.hasDefaultCord = NO;
+ [message hasDefaultCord];
+ }
+ }];
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBSwiftTests.swift b/third_party/protobuf/objectivec/Tests/GPBSwiftTests.swift
new file mode 100644
index 0000000000..9d8a0faeb0
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBSwiftTests.swift
@@ -0,0 +1,460 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import Foundation
+import XCTest
+
+// Test some usage of the ObjC library from Swift.
+
+class GPBBridgeTests: XCTestCase {
+
+ func testProto2Basics() {
+ let msg = Message2()
+ let msg2 = Message2()
+ let msg3 = Message2_OptionalGroup()
+
+ msg.optionalInt32 = 100
+ msg.optionalString = "abc"
+ msg.optionalEnum = .bar
+ msg2.optionalString = "other"
+ msg.optional = msg2
+ msg3.a = 200
+ msg.optionalGroup = msg3
+ msg.repeatedInt32Array.addValue(300)
+ msg.repeatedInt32Array.addValue(301)
+ msg.repeatedStringArray.add("mno")
+ msg.repeatedStringArray.add("pqr")
+ msg.repeatedEnumArray.addValue(Message2_Enum.bar.rawValue)
+ msg.repeatedEnumArray.addValue(Message2_Enum.baz.rawValue)
+ msg.mapInt32Int32.setInt32(400, forKey:500)
+ msg.mapInt32Int32.setInt32(401, forKey:501)
+ msg.mapStringString.setObject("foo", forKey:"bar" as NSString)
+ msg.mapStringString.setObject("abc", forKey:"xyz" as NSString)
+ msg.mapInt32Enum.setEnum(Message2_Enum.bar.rawValue, forKey:600)
+ msg.mapInt32Enum.setEnum(Message2_Enum.baz.rawValue, forKey:601)
+
+ // Check has*.
+ XCTAssertTrue(msg.hasOptionalInt32)
+ XCTAssertTrue(msg.hasOptionalString)
+ XCTAssertTrue(msg.hasOptionalEnum)
+ XCTAssertTrue(msg2.hasOptionalString)
+ XCTAssertTrue(msg.hasOptionalMessage)
+ XCTAssertTrue(msg3.hasA)
+ XCTAssertTrue(msg.hasOptionalGroup)
+ XCTAssertFalse(msg.hasOptionalInt64)
+ XCTAssertFalse(msg.hasOptionalFloat)
+
+ // Check values.
+ XCTAssertEqual(msg.optionalInt32, Int32(100))
+ XCTAssertEqual(msg.optionalString, "abc")
+ XCTAssertEqual(msg2.optionalString, "other")
+ XCTAssertTrue(msg.optional === msg2)
+ XCTAssertEqual(msg.optionalEnum, Message2_Enum.bar)
+ XCTAssertEqual(msg3.a, Int32(200))
+ XCTAssertTrue(msg.optionalGroup === msg3)
+ XCTAssertEqual(msg.repeatedInt32Array.count, UInt(2))
+ XCTAssertEqual(msg.repeatedInt32Array.value(at: 0), Int32(300))
+ XCTAssertEqual(msg.repeatedInt32Array.value(at: 1), Int32(301))
+ XCTAssertEqual(msg.repeatedStringArray.count, Int(2))
+ XCTAssertEqual(msg.repeatedStringArray.object(at: 0) as? String, "mno")
+ XCTAssertEqual(msg.repeatedStringArray.object(at: 1) as? String, "pqr")
+ XCTAssertEqual(msg.repeatedEnumArray.count, UInt(2))
+ XCTAssertEqual(msg.repeatedEnumArray.value(at: 0), Message2_Enum.bar.rawValue)
+ XCTAssertEqual(msg.repeatedEnumArray.value(at: 1), Message2_Enum.baz.rawValue)
+ XCTAssertEqual(msg.repeatedInt64Array.count, UInt(0))
+ XCTAssertEqual(msg.mapInt32Int32.count, UInt(2))
+ var intValue: Int32 = 0
+ XCTAssertTrue(msg.mapInt32Int32.getInt32(&intValue, forKey: 500))
+ XCTAssertEqual(intValue, Int32(400))
+ XCTAssertTrue(msg.mapInt32Int32.getInt32(&intValue, forKey: 501))
+ XCTAssertEqual(intValue, Int32(401))
+ XCTAssertEqual(msg.mapStringString.count, Int(2))
+ XCTAssertEqual(msg.mapStringString.object(forKey: "bar") as? String, "foo")
+ XCTAssertEqual(msg.mapStringString.object(forKey: "xyz") as? String, "abc")
+ XCTAssertEqual(msg.mapInt32Enum.count, UInt(2))
+ XCTAssertTrue(msg.mapInt32Enum.getEnum(&intValue, forKey:600))
+ XCTAssertEqual(intValue, Message2_Enum.bar.rawValue)
+ XCTAssertTrue(msg.mapInt32Enum.getEnum(&intValue, forKey:601))
+ XCTAssertEqual(intValue, Message2_Enum.baz.rawValue)
+
+ // Clearing a string with nil.
+ msg2.optionalString = nil
+ XCTAssertFalse(msg2.hasOptionalString)
+ XCTAssertEqual(msg2.optionalString, "")
+
+ // Clearing a message with nil.
+ msg.optionalGroup = nil
+ XCTAssertFalse(msg.hasOptionalGroup)
+ XCTAssertTrue(msg.optionalGroup !== msg3) // New instance
+
+ // Clear.
+ msg.clear()
+ XCTAssertFalse(msg.hasOptionalInt32)
+ XCTAssertFalse(msg.hasOptionalString)
+ XCTAssertFalse(msg.hasOptionalEnum)
+ XCTAssertFalse(msg.hasOptionalMessage)
+ XCTAssertFalse(msg.hasOptionalInt64)
+ XCTAssertFalse(msg.hasOptionalFloat)
+ XCTAssertEqual(msg.optionalInt32, Int32(0))
+ XCTAssertEqual(msg.optionalString, "")
+ XCTAssertTrue(msg.optional !== msg2) // New instance
+ XCTAssertEqual(msg.optionalEnum, Message2_Enum.foo) // Default
+ XCTAssertEqual(msg.repeatedInt32Array.count, UInt(0))
+ XCTAssertEqual(msg.repeatedStringArray.count, Int(0))
+ XCTAssertEqual(msg.repeatedEnumArray.count, UInt(0))
+ XCTAssertEqual(msg.mapInt32Int32.count, UInt(0))
+ XCTAssertEqual(msg.mapStringString.count, Int(0))
+ XCTAssertEqual(msg.mapInt32Enum.count, UInt(0))
+ }
+
+ func testProto3Basics() {
+ let msg = Message3()
+ let msg2 = Message3()
+
+ msg.optionalInt32 = 100
+ msg.optionalString = "abc"
+ msg.optionalEnum = .bar
+ msg2.optionalString = "other"
+ msg.optional = msg2
+ msg.repeatedInt32Array.addValue(300)
+ msg.repeatedInt32Array.addValue(301)
+ msg.repeatedStringArray.add("mno")
+ msg.repeatedStringArray.add("pqr")
+ // "proto3" syntax lets enum get unknown values.
+ msg.repeatedEnumArray.addValue(Message3_Enum.bar.rawValue)
+ msg.repeatedEnumArray.addRawValue(666)
+ SetMessage3_OptionalEnum_RawValue(msg2, 666)
+ msg.mapInt32Int32.setInt32(400, forKey:500)
+ msg.mapInt32Int32.setInt32(401, forKey:501)
+ msg.mapStringString.setObject("foo", forKey:"bar" as NSString)
+ msg.mapStringString.setObject("abc", forKey:"xyz" as NSString)
+ msg.mapInt32Enum.setEnum(Message2_Enum.bar.rawValue, forKey:600)
+ // "proto3" syntax lets enum get unknown values.
+ msg.mapInt32Enum.setRawValue(666, forKey:601)
+
+ // Has only exists on for message fields.
+ XCTAssertTrue(msg.hasOptionalMessage)
+ XCTAssertFalse(msg2.hasOptionalMessage)
+
+ // Check values.
+ XCTAssertEqual(msg.optionalInt32, Int32(100))
+ XCTAssertEqual(msg.optionalString, "abc")
+ XCTAssertEqual(msg2.optionalString, "other")
+ XCTAssertTrue(msg.optional === msg2)
+ XCTAssertEqual(msg.optionalEnum, Message3_Enum.bar)
+ XCTAssertEqual(msg.repeatedInt32Array.count, UInt(2))
+ XCTAssertEqual(msg.repeatedInt32Array.value(at: 0), Int32(300))
+ XCTAssertEqual(msg.repeatedInt32Array.value(at: 1), Int32(301))
+ XCTAssertEqual(msg.repeatedStringArray.count, Int(2))
+ XCTAssertEqual(msg.repeatedStringArray.object(at: 0) as? String, "mno")
+ XCTAssertEqual(msg.repeatedStringArray.object(at: 1) as? String, "pqr")
+ XCTAssertEqual(msg.repeatedInt64Array.count, UInt(0))
+ XCTAssertEqual(msg.repeatedEnumArray.count, UInt(2))
+ XCTAssertEqual(msg.repeatedEnumArray.value(at: 0), Message3_Enum.bar.rawValue)
+ XCTAssertEqual(msg.repeatedEnumArray.value(at: 1), Message3_Enum.gpbUnrecognizedEnumeratorValue.rawValue)
+ XCTAssertEqual(msg.repeatedEnumArray.rawValue(at: 1), 666)
+ XCTAssertEqual(msg2.optionalEnum, Message3_Enum.gpbUnrecognizedEnumeratorValue)
+ XCTAssertEqual(Message3_OptionalEnum_RawValue(msg2), Int32(666))
+ XCTAssertEqual(msg.mapInt32Int32.count, UInt(2))
+ var intValue: Int32 = 0
+ XCTAssertTrue(msg.mapInt32Int32.getInt32(&intValue, forKey:500))
+ XCTAssertEqual(intValue, Int32(400))
+ XCTAssertTrue(msg.mapInt32Int32.getInt32(&intValue, forKey:501))
+ XCTAssertEqual(intValue, Int32(401))
+ XCTAssertEqual(msg.mapStringString.count, Int(2))
+ XCTAssertEqual(msg.mapStringString.object(forKey: "bar") as? String, "foo")
+ XCTAssertEqual(msg.mapStringString.object(forKey: "xyz") as? String, "abc")
+ XCTAssertEqual(msg.mapInt32Enum.count, UInt(2))
+ XCTAssertTrue(msg.mapInt32Enum.getEnum(&intValue, forKey:600))
+ XCTAssertEqual(intValue, Message2_Enum.bar.rawValue)
+ XCTAssertTrue(msg.mapInt32Enum.getEnum(&intValue, forKey:601))
+ XCTAssertEqual(intValue, Message3_Enum.gpbUnrecognizedEnumeratorValue.rawValue)
+ XCTAssertTrue(msg.mapInt32Enum.getRawValue(&intValue, forKey:601))
+ XCTAssertEqual(intValue, 666)
+
+ // Clearing a string with nil.
+ msg2.optionalString = nil
+ XCTAssertEqual(msg2.optionalString, "")
+
+ // Clearing a message with nil.
+ msg.optional = nil
+ XCTAssertFalse(msg.hasOptionalMessage)
+ XCTAssertTrue(msg.optional !== msg2) // New instance
+
+ // Clear.
+ msg.clear()
+ XCTAssertFalse(msg.hasOptionalMessage)
+ XCTAssertEqual(msg.optionalInt32, Int32(0))
+ XCTAssertEqual(msg.optionalString, "")
+ XCTAssertTrue(msg.optional !== msg2) // New instance
+ XCTAssertEqual(msg.optionalEnum, Message3_Enum.foo) // Default
+ XCTAssertEqual(msg.repeatedInt32Array.count, UInt(0))
+ XCTAssertEqual(msg.repeatedStringArray.count, Int(0))
+ XCTAssertEqual(msg.repeatedEnumArray.count, UInt(0))
+ msg2.clear()
+ XCTAssertEqual(msg2.optionalEnum, Message3_Enum.foo) // Default
+ XCTAssertEqual(Message3_OptionalEnum_RawValue(msg2), Message3_Enum.foo.rawValue)
+ XCTAssertEqual(msg.mapInt32Int32.count, UInt(0))
+ XCTAssertEqual(msg.mapStringString.count, Int(0))
+ XCTAssertEqual(msg.mapInt32Enum.count, UInt(0))
+ }
+
+ func testAutoCreation() {
+ let msg = Message2()
+
+ XCTAssertFalse(msg.hasOptionalGroup)
+ XCTAssertFalse(msg.hasOptionalMessage)
+
+ // Access shouldn't result in has* but should return objects.
+ let msg2 = msg.optionalGroup
+ let msg3 = msg.optional.optional
+ let msg4 = msg.optional
+ XCTAssertNotNil(msg2)
+ XCTAssertNotNil(msg3)
+ XCTAssertFalse(msg.hasOptionalGroup)
+ XCTAssertFalse(msg.optional.hasOptionalMessage)
+ XCTAssertFalse(msg.hasOptionalMessage)
+
+ // Setting things should trigger has* getting set.
+ msg.optionalGroup.a = 10
+ msg.optional.optional.optionalInt32 = 100
+ XCTAssertTrue(msg.hasOptionalGroup)
+ XCTAssertTrue(msg.optional.hasOptionalMessage)
+ XCTAssertTrue(msg.hasOptionalMessage)
+
+ // And they should be the same pointer as before.
+ XCTAssertTrue(msg2 === msg.optionalGroup)
+ XCTAssertTrue(msg3 === msg.optional.optional)
+ XCTAssertTrue(msg4 === msg.optional)
+
+ // Clear gets us new objects next time around.
+ msg.clear()
+ XCTAssertFalse(msg.hasOptionalGroup)
+ XCTAssertFalse(msg.optional.hasOptionalMessage)
+ XCTAssertFalse(msg.hasOptionalMessage)
+ msg.optionalGroup.a = 20
+ msg.optional.optional.optionalInt32 = 200
+ XCTAssertTrue(msg.hasOptionalGroup)
+ XCTAssertTrue(msg.optional.hasOptionalMessage)
+ XCTAssertTrue(msg.hasOptionalMessage)
+ XCTAssertTrue(msg2 !== msg.optionalGroup)
+ XCTAssertTrue(msg3 !== msg.optional.optional)
+ XCTAssertTrue(msg4 !== msg.optional)
+
+ // Explicit set of a message, means autocreated object doesn't bind.
+ msg.clear()
+ let autoCreated = msg.optional
+ XCTAssertFalse(msg.hasOptionalMessage)
+ let msg5 = Message2()
+ msg5.optionalInt32 = 123
+ msg.optional = msg5
+ XCTAssertTrue(msg.hasOptionalMessage)
+ // Modifing the autocreated doesn't replaced the explicit set one.
+ autoCreated?.optionalInt32 = 456
+ XCTAssertTrue(msg.hasOptionalMessage)
+ XCTAssertTrue(msg.optional === msg5)
+ XCTAssertEqual(msg.optional.optionalInt32, Int32(123))
+ }
+
+ func testProto2OneOfSupport() {
+ let msg = Message2()
+
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.gpbUnsetOneOfCase)
+ XCTAssertEqual(msg.oneofInt32, Int32(100)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(110.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum.baz) // Default
+ let autoCreated = msg.oneof // Default create one.
+ XCTAssertNotNil(autoCreated)
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.gpbUnsetOneOfCase)
+
+ msg.oneofInt32 = 10
+ XCTAssertEqual(msg.oneofInt32, Int32(10))
+ XCTAssertEqual(msg.oneofFloat, Float(110.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum.baz) // Default
+ XCTAssertTrue(msg.oneof === autoCreated) // Still the same
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.oneofInt32)
+
+ msg.oneofFloat = 20.0
+ XCTAssertEqual(msg.oneofInt32, Int32(100)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(20.0))
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum.baz) // Default
+ XCTAssertTrue(msg.oneof === autoCreated) // Still the same
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.oneofFloat)
+
+ msg.oneofEnum = .bar
+ XCTAssertEqual(msg.oneofInt32, Int32(100)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(110.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum.bar)
+ XCTAssertTrue(msg.oneof === autoCreated) // Still the same
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.oneofEnum)
+
+ // Sets via the autocreated instance.
+ msg.oneof.optionalInt32 = 200
+ XCTAssertEqual(msg.oneofInt32, Int32(100)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(110.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum.baz) // Default
+ XCTAssertTrue(msg.oneof === autoCreated) // Still the same
+ XCTAssertEqual(msg.oneof.optionalInt32, Int32(200))
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.oneofMessage)
+
+ // Clear the oneof.
+ Message2_ClearOOneOfCase(msg)
+ XCTAssertEqual(msg.oneofInt32, Int32(100)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(110.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message2_Enum.baz) // Default
+ let autoCreated2 = msg.oneof // Default create one
+ XCTAssertNotNil(autoCreated2)
+ XCTAssertTrue(autoCreated2 !== autoCreated) // New instance
+ XCTAssertEqual(msg.oneof.optionalInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.gpbUnsetOneOfCase)
+
+ msg.oneofInt32 = 10
+ XCTAssertEqual(msg.oneofInt32, Int32(10))
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.oneofInt32)
+
+ // Confirm Message.clear() handles the oneof correctly.
+ msg.clear()
+ XCTAssertEqual(msg.oneofInt32, Int32(100)) // Default
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.gpbUnsetOneOfCase)
+
+ // Sets via the autocreated instance.
+ msg.oneof.optionalInt32 = 300
+ XCTAssertTrue(msg.oneof !== autoCreated) // New instance
+ XCTAssertTrue(msg.oneof !== autoCreated2) // New instance
+ XCTAssertEqual(msg.oneof.optionalInt32, Int32(300))
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.oneofMessage)
+
+ // Set message to nil clears the oneof.
+ msg.oneof = nil
+ XCTAssertEqual(msg.oneof.optionalInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.gpbUnsetOneOfCase)
+}
+
+ func testProto3OneOfSupport() {
+ let msg = Message3()
+
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.gpbUnsetOneOfCase)
+ XCTAssertEqual(msg.oneofInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(0.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum.foo) // Default
+ let autoCreated = msg.oneof // Default create one.
+ XCTAssertNotNil(autoCreated)
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.gpbUnsetOneOfCase)
+
+ msg.oneofInt32 = 10
+ XCTAssertEqual(msg.oneofInt32, Int32(10))
+ XCTAssertEqual(msg.oneofFloat, Float(0.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum.foo) // Default
+ XCTAssertTrue(msg.oneof === autoCreated) // Still the same
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.oneofInt32)
+
+ msg.oneofFloat = 20.0
+ XCTAssertEqual(msg.oneofInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(20.0))
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum.foo) // Default
+ XCTAssertTrue(msg.oneof === autoCreated) // Still the same
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.oneofFloat)
+
+ msg.oneofEnum = .bar
+ XCTAssertEqual(msg.oneofInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(0.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum.bar)
+ XCTAssertTrue(msg.oneof === autoCreated) // Still the same
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.oneofEnum)
+
+ // Sets via the autocreated instance.
+ msg.oneof.optionalInt32 = 200
+ XCTAssertEqual(msg.oneofInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(0.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum.foo) // Default
+ XCTAssertTrue(msg.oneof === autoCreated) // Still the same
+ XCTAssertEqual(msg.oneof.optionalInt32, Int32(200))
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.oneofMessage)
+
+ // Clear the oneof.
+ Message3_ClearOOneOfCase(msg)
+ XCTAssertEqual(msg.oneofInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oneofFloat, Float(0.0)) // Default
+ XCTAssertEqual(msg.oneofEnum, Message3_Enum.foo) // Default
+ let autoCreated2 = msg.oneof // Default create one
+ XCTAssertNotNil(autoCreated2)
+ XCTAssertTrue(autoCreated2 !== autoCreated) // New instance
+ XCTAssertEqual(msg.oneof.optionalInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.gpbUnsetOneOfCase)
+
+ msg.oneofInt32 = 10
+ XCTAssertEqual(msg.oneofInt32, Int32(10))
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.oneofInt32)
+
+ // Confirm Message.clear() handles the oneof correctly.
+ msg.clear()
+ XCTAssertEqual(msg.oneofInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.gpbUnsetOneOfCase)
+
+ // Sets via the autocreated instance.
+ msg.oneof.optionalInt32 = 300
+ XCTAssertTrue(msg.oneof !== autoCreated) // New instance
+ XCTAssertTrue(msg.oneof !== autoCreated2) // New instance
+ XCTAssertEqual(msg.oneof.optionalInt32, Int32(300))
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.oneofMessage)
+
+ // Set message to nil clears the oneof.
+ msg.oneof = nil
+ XCTAssertEqual(msg.oneof.optionalInt32, Int32(0)) // Default
+ XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase.gpbUnsetOneOfCase)
+ }
+
+ func testSerialization() {
+ let msg = Message2()
+
+ msg.optionalInt32 = 100
+ msg.optionalInt64 = 101
+ msg.optionalGroup.a = 102
+ msg.repeatedStringArray.add("abc")
+ msg.repeatedStringArray.add("def")
+ msg.mapInt32Int32.setInt32(200, forKey:300)
+ msg.mapInt32Int32.setInt32(201, forKey:201)
+ msg.mapStringString.setObject("foo", forKey:"bar" as NSString)
+ msg.mapStringString.setObject("abc", forKey:"xyz" as NSString)
+
+ let data = msg.data()
+
+ let msg2 = try! Message2(data: data!)
+ XCTAssertTrue(msg2 !== msg) // New instance
+ XCTAssertEqual(msg.optionalInt32, Int32(100))
+ XCTAssertEqual(msg.optionalInt64, Int64(101))
+ XCTAssertEqual(msg.optionalGroup.a, Int32(102))
+ XCTAssertEqual(msg.repeatedStringArray.count, Int(2))
+ XCTAssertEqual(msg.mapInt32Int32.count, UInt(2))
+ XCTAssertEqual(msg.mapStringString.count, Int(2))
+ XCTAssertEqual(msg2, msg)
+ }
+
+}
diff --git a/third_party/protobuf/objectivec/Tests/GPBTestUtilities.h b/third_party/protobuf/objectivec/Tests/GPBTestUtilities.h
new file mode 100644
index 0000000000..44c808449d
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBTestUtilities.h
@@ -0,0 +1,100 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <XCTest/XCTest.h>
+
+@class TestAllExtensions;
+@class TestAllTypes;
+@class TestMap;
+@class TestPackedTypes;
+@class TestPackedExtensions;
+@class TestUnpackedTypes;
+@class TestUnpackedExtensions;
+@class GPBExtensionRegistry;
+
+
+// Helper for uses of C arrays in tests cases.
+#ifndef GPBARRAYSIZE
+#define GPBARRAYSIZE(a) ((sizeof(a) / sizeof((a[0]))))
+#endif // GPBARRAYSIZE
+
+
+// The number of repetitions of any repeated objects inside of test messages.
+extern const uint32_t kGPBDefaultRepeatCount;
+
+@interface GPBTestCase : XCTestCase
+
+- (void)setAllFields:(TestAllTypes *)message repeatedCount:(uint32_t)count;
+- (void)clearAllFields:(TestAllTypes *)message;
+- (void)setAllExtensions:(TestAllExtensions *)message
+ repeatedCount:(uint32_t)count;
+- (void)setPackedFields:(TestPackedTypes *)message
+ repeatedCount:(uint32_t)count;
+- (void)setUnpackedFields:(TestUnpackedTypes *)message
+ repeatedCount:(uint32_t)count;
+- (void)setPackedExtensions:(TestPackedExtensions *)message
+ repeatedCount:(uint32_t)count;
+- (void)setUnpackedExtensions:(TestUnpackedExtensions *)message
+ repeatedCount:(uint32_t)count;
+- (void)setAllMapFields:(TestMap *)message numEntries:(uint32_t)count;
+
+- (TestAllTypes *)allSetRepeatedCount:(uint32_t)count;
+- (TestAllExtensions *)allExtensionsSetRepeatedCount:(uint32_t)count;
+- (TestPackedTypes *)packedSetRepeatedCount:(uint32_t)count;
+- (TestPackedExtensions *)packedExtensionsSetRepeatedCount:(uint32_t)count;
+
+- (void)assertAllFieldsSet:(TestAllTypes *)message
+ repeatedCount:(uint32_t)count;
+- (void)assertAllExtensionsSet:(TestAllExtensions *)message
+ repeatedCount:(uint32_t)count;
+- (void)assertRepeatedFieldsModified:(TestAllTypes *)message
+ repeatedCount:(uint32_t)count;
+- (void)assertRepeatedExtensionsModified:(TestAllExtensions *)message
+ repeatedCount:(uint32_t)count;
+- (void)assertExtensionsClear:(TestAllExtensions *)message;
+- (void)assertClear:(TestAllTypes *)message;
+- (void)assertPackedFieldsSet:(TestPackedTypes *)message
+ repeatedCount:(uint32_t)count;
+- (void)assertPackedExtensionsSet:(TestPackedExtensions *)message
+ repeatedCount:(uint32_t)count;
+
+- (void)modifyRepeatedExtensions:(TestAllExtensions *)message;
+- (void)modifyRepeatedFields:(TestAllTypes *)message;
+
+- (GPBExtensionRegistry *)extensionRegistry;
+
+- (NSData *)getDataFileNamed:(NSString *)name dataToWrite:(NSData *)dataToWrite;
+
+- (void)assertAllFieldsKVCMatch:(TestAllTypes *)message;
+- (void)setAllFieldsViaKVC:(TestAllTypes *)message
+ repeatedCount:(uint32_t)count;
+- (void)assertClearKVC:(TestAllTypes *)message;
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBTestUtilities.m b/third_party/protobuf/objectivec/Tests/GPBTestUtilities.m
new file mode 100644
index 0000000000..ebccaac9c7
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBTestUtilities.m
@@ -0,0 +1,2546 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import "google/protobuf/MapUnittest.pbobjc.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestImport.pbobjc.h"
+
+const uint32_t kGPBDefaultRepeatCount = 2;
+
+// Small category to easily turn a CString into an NSData.
+@interface NSData (GPBTestCase)
++ (NSData *)gpbtu_dataWithCString:(char *)buffer;
++ (instancetype)gpbtu_dataWithEmbeddedNulls;
+@end
+
+@implementation NSData (GPBTestCase)
++ (NSData *)gpbtu_dataWithCString:(char *)buffer {
+ return [NSData dataWithBytes:buffer length:strlen(buffer)];
+}
+
++ (instancetype)gpbtu_dataWithUint32:(uint32_t)value {
+ return [[[self alloc] initWithUint32_gpbtu:value] autorelease];
+}
+
+- (instancetype)initWithUint32_gpbtu:(uint32_t)value {
+ value = CFSwapInt32HostToLittle(value);
+ return [self initWithBytes:&value length:sizeof(value)];
+}
+
++ (instancetype)gpbtu_dataWithEmbeddedNulls {
+ char bytes[6] = "\1\0\2\3\0\5";
+ return [self dataWithBytes:bytes length:sizeof(bytes)];
+}
+@end
+
+@implementation GPBTestCase
+
+// Return data for name. Optionally (based on #if setting) write out dataToWrite
+// to replace that data. Useful for setting golden masters.
+- (NSData *)getDataFileNamed:(NSString *)name
+ dataToWrite:(NSData *)dataToWrite {
+ NSBundle *bundle = [NSBundle bundleForClass:[self class]];
+ NSString *path = [bundle pathForResource:[name stringByDeletingPathExtension]
+ ofType:[name pathExtension]];
+ XCTAssertNotNil(path, @"Unable to find %@", name);
+ NSData *data = [NSData dataWithContentsOfFile:path];
+ XCTAssertNotNil(data, @"Unable to load from %@", path);
+#if 0
+ // Enable to write out golden master files.
+ if (!path) {
+ path = [[bundle resourcePath] stringByAppendingPathComponent:name];
+ }
+ NSError *error = nil;
+ BOOL wrote = [dataToWrite writeToFile:path options:NSDataWritingAtomic error:&error];
+ XCTAssertTrue(wrote, @"Unable to write %@ (%@)", path, error);
+ NSLog(@"Wrote data file to %@", path);
+#else
+ // Kill off the unused variable warning.
+ dataToWrite = dataToWrite;
+#endif
+ return data;
+}
+
+// -------------------------------------------------------------------
+
+- (void)modifyRepeatedExtensions:(TestAllExtensions *)message {
+ [message setExtension:[UnittestRoot repeatedInt32Extension]
+ index:1
+ value:@501];
+ [message setExtension:[UnittestRoot repeatedInt64Extension]
+ index:1
+ value:@502];
+ [message setExtension:[UnittestRoot repeatedUint32Extension]
+ index:1
+ value:@503];
+ [message setExtension:[UnittestRoot repeatedUint64Extension]
+ index:1
+ value:@504];
+ [message setExtension:[UnittestRoot repeatedSint32Extension]
+ index:1
+ value:@505];
+ [message setExtension:[UnittestRoot repeatedSint64Extension]
+ index:1
+ value:@506];
+ [message setExtension:[UnittestRoot repeatedFixed32Extension]
+ index:1
+ value:@507];
+ [message setExtension:[UnittestRoot repeatedFixed64Extension]
+ index:1
+ value:@508];
+ [message setExtension:[UnittestRoot repeatedSfixed32Extension]
+ index:1
+ value:@509];
+ [message setExtension:[UnittestRoot repeatedSfixed64Extension]
+ index:1
+ value:@510];
+ [message setExtension:[UnittestRoot repeatedFloatExtension]
+ index:1
+ value:@511.0f];
+ [message setExtension:[UnittestRoot repeatedDoubleExtension]
+ index:1
+ value:@512.0];
+ [message setExtension:[UnittestRoot repeatedBoolExtension]
+ index:1
+ value:@YES];
+ [message setExtension:[UnittestRoot repeatedStringExtension]
+ index:1
+ value:@"515"];
+ [message setExtension:[UnittestRoot repeatedBytesExtension]
+ index:1
+ value:[NSData gpbtu_dataWithUint32:516]];
+
+ RepeatedGroup_extension *repeatedGroup = [RepeatedGroup_extension message];
+ [repeatedGroup setA:517];
+ [message setExtension:[UnittestRoot repeatedGroupExtension]
+ index:1
+ value:repeatedGroup];
+ TestAllTypes_NestedMessage *nestedMessage =
+ [TestAllTypes_NestedMessage message];
+ [nestedMessage setBb:518];
+ [message setExtension:[UnittestRoot repeatedNestedMessageExtension]
+ index:1
+ value:nestedMessage];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ [foreignMessage setC:519];
+ [message setExtension:[UnittestRoot repeatedForeignMessageExtension]
+ index:1
+ value:foreignMessage];
+ ImportMessage *importMessage = [ImportMessage message];
+ [importMessage setD:520];
+ [message setExtension:[UnittestRoot repeatedImportMessageExtension]
+ index:1
+ value:importMessage];
+
+ [message setExtension:[UnittestRoot repeatedNestedEnumExtension]
+ index:1
+ value:@(TestAllTypes_NestedEnum_Foo)];
+ [message setExtension:[UnittestRoot repeatedForeignEnumExtension]
+ index:1
+ value:@(ForeignEnum_ForeignFoo)];
+ [message setExtension:[UnittestRoot repeatedImportEnumExtension]
+ index:1
+ value:@(ImportEnum_ImportFoo)];
+
+ [message setExtension:[UnittestRoot repeatedStringPieceExtension]
+ index:1
+ value:@"524"];
+ [message setExtension:[UnittestRoot repeatedCordExtension]
+ index:1
+ value:@"525"];
+}
+
+- (void)assertAllExtensionsSet:(TestAllExtensions *)message
+ repeatedCount:(uint32_t)count {
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalInt32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalInt64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalUint32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalUint64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalSint32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalSint64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalFixed32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalFixed64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalSfixed32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalSfixed64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalFloatExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalDoubleExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalBoolExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalStringExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalBytesExtension]]);
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalNestedMessageExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalForeignMessageExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalImportMessageExtension]]);
+
+ XCTAssertTrue([[message getExtension:[UnittestRoot optionalGroupExtension]] hasA]);
+ XCTAssertTrue([[message getExtension:[UnittestRoot optionalNestedMessageExtension]] hasBb]);
+ XCTAssertTrue([[message getExtension:[UnittestRoot optionalForeignMessageExtension]] hasC]);
+ XCTAssertTrue([[message getExtension:[UnittestRoot optionalImportMessageExtension]] hasD]);
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalNestedEnumExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalForeignEnumExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalImportEnumExtension]]);
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalStringPieceExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalCordExtension]]);
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultInt32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultInt64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultUint32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultUint64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultSint32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultSint64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultFixed32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultFixed64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultSfixed32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultSfixed64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultFloatExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultDoubleExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultBoolExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultStringExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultBytesExtension]]);
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultNestedEnumExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultForeignEnumExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultImportEnumExtension]]);
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultStringPieceExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultCordExtension]]);
+
+ XCTAssertEqual(101, [[message getExtension:[UnittestRoot optionalInt32Extension]] intValue]);
+ XCTAssertEqual(102LL, [[message getExtension:[UnittestRoot optionalInt64Extension]] longLongValue]);
+ XCTAssertEqual(103U, [[message getExtension:[UnittestRoot optionalUint32Extension]] unsignedIntValue]);
+ XCTAssertEqual(104ULL, [[message getExtension:[UnittestRoot optionalUint64Extension]] unsignedLongLongValue]);
+ XCTAssertEqual(105, [[message getExtension:[UnittestRoot optionalSint32Extension]] intValue]);
+ XCTAssertEqual(106LL, [[message getExtension:[UnittestRoot optionalSint64Extension]] longLongValue]);
+ XCTAssertEqual(107U, [[message getExtension:[UnittestRoot optionalFixed32Extension]] unsignedIntValue]);
+ XCTAssertEqual(108ULL, [[message getExtension:[UnittestRoot optionalFixed64Extension]] unsignedLongLongValue]);
+ XCTAssertEqual(109, [[message getExtension:[UnittestRoot optionalSfixed32Extension]] intValue]);
+ XCTAssertEqual(110LL, [[message getExtension:[UnittestRoot optionalSfixed64Extension]] longLongValue]);
+ XCTAssertEqualWithAccuracy(111.0f, [[message getExtension:[UnittestRoot optionalFloatExtension]] floatValue], 0.01);
+ XCTAssertEqualWithAccuracy(112.0, [[message getExtension:[UnittestRoot optionalDoubleExtension]] doubleValue], 0.01);
+ XCTAssertTrue([[message getExtension:[UnittestRoot optionalBoolExtension]] boolValue]);
+ XCTAssertEqualObjects(@"115", [message getExtension:[UnittestRoot optionalStringExtension]]);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithEmbeddedNulls], [message getExtension:[UnittestRoot optionalBytesExtension]]);
+
+ XCTAssertEqual(117, [(TestAllTypes_OptionalGroup*)[message getExtension:[UnittestRoot optionalGroupExtension]] a]);
+ XCTAssertEqual(118, [(TestAllTypes_NestedMessage*)[message getExtension:[UnittestRoot optionalNestedMessageExtension]] bb]);
+ XCTAssertEqual(119, [[message getExtension:[UnittestRoot optionalForeignMessageExtension]] c]);
+ XCTAssertEqual(120, [[message getExtension:[UnittestRoot optionalImportMessageExtension]] d]);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Baz, [[message getExtension:[UnittestRoot optionalNestedEnumExtension]] intValue]);
+ XCTAssertEqual(ForeignEnum_ForeignBaz, [[message getExtension:[UnittestRoot optionalForeignEnumExtension]] intValue]);
+ XCTAssertEqual(ImportEnum_ImportBaz, [[message getExtension:[UnittestRoot optionalImportEnumExtension]] intValue]);
+
+ XCTAssertEqualObjects(@"124", [message getExtension:[UnittestRoot optionalStringPieceExtension]]);
+ XCTAssertEqualObjects(@"125", [message getExtension:[UnittestRoot optionalCordExtension]]);
+
+ // -----------------------------------------------------------------
+
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedInt32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedInt64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedUint32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedUint64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSint32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSint64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFixed32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFixed64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSfixed32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFloatExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedDoubleExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedBoolExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedStringExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedBytesExtension]] count]);
+
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedGroupExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedNestedMessageExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedNestedEnumExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedForeignEnumExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedImportEnumExtension]] count]);
+
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedStringPieceExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedCordExtension]] count]);
+
+ for (uint32_t i = 0; i < count; ++i) {
+ id extension = [message getExtension:[UnittestRoot repeatedInt32Extension]];
+ XCTAssertEqual((int)(201 + i * 100), [extension[i] intValue]);
+ extension = [message getExtension:[UnittestRoot repeatedInt64Extension]];
+ XCTAssertEqual(202 + i * 100, [extension[i] longLongValue]);
+ extension = [message getExtension:[UnittestRoot repeatedUint32Extension]];
+ XCTAssertEqual(203 + i * 100, [extension[i] unsignedIntValue]);
+ extension = [message getExtension:[UnittestRoot repeatedUint64Extension]];
+ XCTAssertEqual(204 + i * 100, [extension[i] unsignedLongLongValue]);
+ extension = [message getExtension:[UnittestRoot repeatedSint32Extension]];
+ XCTAssertEqual((int)(205 + i * 100), [extension[i] intValue]);
+ extension = [message getExtension:[UnittestRoot repeatedSint64Extension]];
+ XCTAssertEqual(206 + i * 100, [extension[i] longLongValue]);
+ extension = [message getExtension:[UnittestRoot repeatedFixed32Extension]];
+ XCTAssertEqual(207 + i * 100, [extension[i] unsignedIntValue]);
+ extension = [message getExtension:[UnittestRoot repeatedFixed64Extension]];
+ XCTAssertEqual(208 + i * 100, [extension[i] unsignedLongLongValue]);
+ extension = [message getExtension:[UnittestRoot repeatedSfixed32Extension]];
+ XCTAssertEqual((int)(209 + i * 100), [extension[i] intValue]);
+ extension = [message getExtension:[UnittestRoot repeatedSfixed64Extension]];
+ XCTAssertEqual(210 + i * 100, [extension[i] longLongValue]);
+ extension = [message getExtension:[UnittestRoot repeatedFloatExtension]];
+ XCTAssertEqualWithAccuracy(211 + i * 100, [extension[i] floatValue], 0.01);
+ extension = [message getExtension:[UnittestRoot repeatedDoubleExtension]];
+ XCTAssertEqualWithAccuracy(212 + i * 100, [extension[i] doubleValue], 0.01);
+ extension = [message getExtension:[UnittestRoot repeatedBoolExtension]];
+ XCTAssertEqual((i % 2) ? YES : NO, [extension[i] boolValue]);
+
+ NSString *string = [[NSString alloc] initWithFormat:@"%d", 215 + i * 100];
+ extension = [message getExtension:[UnittestRoot repeatedStringExtension]];
+ XCTAssertEqualObjects(string, extension[i]);
+ [string release];
+
+ NSData *data = [[NSData alloc] initWithUint32_gpbtu:216 + i * 100];
+ extension = [message getExtension:[UnittestRoot repeatedBytesExtension]];
+ XCTAssertEqualObjects(data, extension[i]);
+ [data release];
+
+ extension = [message getExtension:[UnittestRoot repeatedGroupExtension]];
+ XCTAssertEqual((int)(217 + i * 100), [(TestAllTypes_OptionalGroup*)extension[i] a]);
+ extension = [message getExtension:[UnittestRoot repeatedNestedMessageExtension]];
+ XCTAssertEqual((int)(218 + i * 100), [(TestAllTypes_NestedMessage*)extension[i] bb]);
+ extension = [message getExtension:[UnittestRoot repeatedForeignMessageExtension]];
+ XCTAssertEqual((int)(219 + i * 100), [extension[i] c]);
+ extension = [message getExtension:[UnittestRoot repeatedImportMessageExtension]];
+ XCTAssertEqual((int)(220 + i * 100), [extension[i] d]);
+
+ extension = [message getExtension:[UnittestRoot repeatedNestedEnumExtension]];
+ XCTAssertEqual((i % 2) ? TestAllTypes_NestedEnum_Bar : TestAllTypes_NestedEnum_Baz, [extension[i] intValue]);
+ extension = [message getExtension:[UnittestRoot repeatedForeignEnumExtension]];
+ XCTAssertEqual((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz, [extension[i] intValue]);
+ extension = [message getExtension:[UnittestRoot repeatedImportEnumExtension]];
+ XCTAssertEqual((i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz, [extension[i] intValue]);
+
+ string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100];
+ extension = [message getExtension:[UnittestRoot repeatedStringPieceExtension]];
+ XCTAssertEqualObjects(string, extension[i]);
+ [string release];
+
+ string = [[NSString alloc] initWithFormat:@"%d", 225 + i * 100];
+ extension = [message getExtension:[UnittestRoot repeatedCordExtension]];
+ XCTAssertEqualObjects(string, extension[i]);
+ [string release];
+ }
+
+ // -----------------------------------------------------------------
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultInt32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultInt64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultUint32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultUint64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultSint32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultSint64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultFixed32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultFixed64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultSfixed32Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultSfixed64Extension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultFloatExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultDoubleExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultBoolExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultStringExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultBytesExtension]]);
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultNestedEnumExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultForeignEnumExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultImportEnumExtension]]);
+
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultStringPieceExtension]]);
+ XCTAssertTrue([message hasExtension:[UnittestRoot defaultCordExtension]]);
+
+ XCTAssertEqual(401, [[message getExtension:[UnittestRoot defaultInt32Extension]] intValue]);
+ XCTAssertEqual(402LL, [[message getExtension:[UnittestRoot defaultInt64Extension]] longLongValue]);
+ XCTAssertEqual(403U, [[message getExtension:[UnittestRoot defaultUint32Extension]] unsignedIntValue]);
+ XCTAssertEqual(404ULL, [[message getExtension:[UnittestRoot defaultUint64Extension]] unsignedLongLongValue]);
+ XCTAssertEqual(405, [[message getExtension:[UnittestRoot defaultSint32Extension]] intValue]);
+ XCTAssertEqual(406LL, [[message getExtension:[UnittestRoot defaultSint64Extension]] longLongValue]);
+ XCTAssertEqual(407U, [[message getExtension:[UnittestRoot defaultFixed32Extension]] unsignedIntValue]);
+ XCTAssertEqual(408ULL, [[message getExtension:[UnittestRoot defaultFixed64Extension]] unsignedLongLongValue]);
+ XCTAssertEqual(409, [[message getExtension:[UnittestRoot defaultSfixed32Extension]] intValue]);
+ XCTAssertEqual(410LL,[[message getExtension:[UnittestRoot defaultSfixed64Extension]] longLongValue]);
+ XCTAssertEqualWithAccuracy(411.0f, [[message getExtension:[UnittestRoot defaultFloatExtension]] floatValue], 0.01);
+ XCTAssertEqualWithAccuracy(412.0, [[message getExtension:[UnittestRoot defaultDoubleExtension]] doubleValue], 0.01);
+ XCTAssertFalse([[message getExtension:[UnittestRoot defaultBoolExtension]] boolValue]);
+ XCTAssertEqualObjects(@"415", [message getExtension:[UnittestRoot defaultStringExtension]]);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:416], [message getExtension:[UnittestRoot defaultBytesExtension]]);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Foo, [[message getExtension:[UnittestRoot defaultNestedEnumExtension]] intValue]);
+ XCTAssertEqual(ForeignEnum_ForeignFoo, [[message getExtension:[UnittestRoot defaultForeignEnumExtension]] intValue]);
+ XCTAssertEqual(ImportEnum_ImportFoo, [[message getExtension:[UnittestRoot defaultImportEnumExtension]] intValue]);
+
+ XCTAssertEqualObjects(@"424", [message getExtension:[UnittestRoot defaultStringPieceExtension]]);
+ XCTAssertEqualObjects(@"425", [message getExtension:[UnittestRoot defaultCordExtension]]);
+}
+
+- (void)assertRepeatedExtensionsModified:(TestAllExtensions *)message
+ repeatedCount:(uint32_t)count {
+ // ModifyRepeatedFields only sets the second repeated element of each
+ // field. In addition to verifying this, we also verify that the first
+ // element and size were *not* modified.
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedInt32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedInt64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedUint32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedUint64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSint32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSint64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFixed32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFixed64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSfixed32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFloatExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedDoubleExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedBoolExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedStringExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedBytesExtension]] count]);
+
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedGroupExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedNestedMessageExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedNestedEnumExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedForeignEnumExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedImportEnumExtension]] count]);
+
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedStringPieceExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedCordExtension]] count]);
+
+ XCTAssertEqual(201,[[message getExtension:[UnittestRoot repeatedInt32Extension]][0] intValue]);
+ XCTAssertEqual(202LL, [[message getExtension:[UnittestRoot repeatedInt64Extension]][0] longLongValue]);
+ XCTAssertEqual(203U, [[message getExtension:[UnittestRoot repeatedUint32Extension]][0] unsignedIntValue]);
+ XCTAssertEqual(204ULL, [[message getExtension:[UnittestRoot repeatedUint64Extension]][0] unsignedLongLongValue]);
+ XCTAssertEqual(205, [[message getExtension:[UnittestRoot repeatedSint32Extension]][0] intValue]);
+ XCTAssertEqual(206LL, [[message getExtension:[UnittestRoot repeatedSint64Extension]][0] longLongValue]);
+ XCTAssertEqual(207U, [[message getExtension:[UnittestRoot repeatedFixed32Extension]][0] unsignedIntValue]);
+ XCTAssertEqual(208ULL, [[message getExtension:[UnittestRoot repeatedFixed64Extension]][0] unsignedLongLongValue]);
+ XCTAssertEqual(209, [[message getExtension:[UnittestRoot repeatedSfixed32Extension]][0] intValue]);
+ XCTAssertEqual(210LL, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]][0] longLongValue]);
+ XCTAssertEqualWithAccuracy(211.0f, [[message getExtension:[UnittestRoot repeatedFloatExtension]][0] floatValue], 0.01);
+ XCTAssertEqualWithAccuracy(212.0, [[message getExtension:[UnittestRoot repeatedDoubleExtension]][0] doubleValue], 0.01);
+ XCTAssertFalse([[message getExtension:[UnittestRoot repeatedBoolExtension]][0] boolValue]);
+ XCTAssertEqualObjects(@"215", [message getExtension:[UnittestRoot repeatedStringExtension]][0]);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:216], [message getExtension:[UnittestRoot repeatedBytesExtension]][0]);
+
+ XCTAssertEqual(217, [(TestAllTypes_OptionalGroup*)[message getExtension:[UnittestRoot repeatedGroupExtension]][0] a]);
+ XCTAssertEqual(218, [(TestAllTypes_NestedMessage*)[message getExtension:[UnittestRoot repeatedNestedMessageExtension]][0] bb]);
+ XCTAssertEqual(219, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]][0] c]);
+ XCTAssertEqual(220, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]][0] d]);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Baz,
+ [[message getExtension:[UnittestRoot repeatedNestedEnumExtension]][0] intValue]);
+ XCTAssertEqual(ForeignEnum_ForeignBaz,
+ [[message getExtension:[UnittestRoot repeatedForeignEnumExtension]][0] intValue]);
+ XCTAssertEqual(ImportEnum_ImportBaz,
+ [[message getExtension:[UnittestRoot repeatedImportEnumExtension]][0] intValue]);
+
+ XCTAssertEqualObjects(@"224", [message getExtension:[UnittestRoot repeatedStringPieceExtension]][0]);
+ XCTAssertEqualObjects(@"225", [message getExtension:[UnittestRoot repeatedCordExtension]][0]);
+
+ // Actually verify the second (modified) elements now.
+ XCTAssertEqual(501, [[message getExtension:[UnittestRoot repeatedInt32Extension]][1] intValue]);
+ XCTAssertEqual(502LL, [[message getExtension:[UnittestRoot repeatedInt64Extension]][1] longLongValue]);
+ XCTAssertEqual(503U, [[message getExtension:[UnittestRoot repeatedUint32Extension]][1] unsignedIntValue]);
+ XCTAssertEqual(504ULL, [[message getExtension:[UnittestRoot repeatedUint64Extension]][1] unsignedLongLongValue]);
+ XCTAssertEqual(505, [[message getExtension:[UnittestRoot repeatedSint32Extension]][1] intValue]);
+ XCTAssertEqual(506LL, [[message getExtension:[UnittestRoot repeatedSint64Extension]][1] longLongValue]);
+ XCTAssertEqual(507U, [[message getExtension:[UnittestRoot repeatedFixed32Extension]][1] unsignedIntValue]);
+ XCTAssertEqual(508ULL, [[message getExtension:[UnittestRoot repeatedFixed64Extension]][1] unsignedLongLongValue]);
+ XCTAssertEqual(509, [[message getExtension:[UnittestRoot repeatedSfixed32Extension]][1] intValue]);
+ XCTAssertEqual(510LL, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]][1] longLongValue]);
+ XCTAssertEqualWithAccuracy(511.0f, [[message getExtension:[UnittestRoot repeatedFloatExtension]][1] floatValue], 0.01);
+ XCTAssertEqualWithAccuracy(512.0, [[message getExtension:[UnittestRoot repeatedDoubleExtension]][1] doubleValue], 0.01);
+ XCTAssertTrue([[message getExtension:[UnittestRoot repeatedBoolExtension]][1] boolValue]);
+ XCTAssertEqualObjects(@"515", [message getExtension:[UnittestRoot repeatedStringExtension]][1]);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:516], [message getExtension:[UnittestRoot repeatedBytesExtension]][1]);
+
+ XCTAssertEqual(517, [(TestAllTypes_OptionalGroup*)[message getExtension:[UnittestRoot repeatedGroupExtension]][1] a]);
+ XCTAssertEqual(518, [(TestAllTypes_NestedMessage*)[message getExtension:[UnittestRoot repeatedNestedMessageExtension]][1] bb]);
+ XCTAssertEqual(519, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]][1] c]);
+ XCTAssertEqual(520, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]][1] d]);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Foo,
+ [[message getExtension:[UnittestRoot repeatedNestedEnumExtension]][1] intValue]);
+ XCTAssertEqual(ForeignEnum_ForeignFoo,
+ [[message getExtension:[UnittestRoot repeatedForeignEnumExtension]][1] intValue]);
+ XCTAssertEqual(ImportEnum_ImportFoo,
+ [[message getExtension:[UnittestRoot repeatedImportEnumExtension]][1] intValue]);
+
+ XCTAssertEqualObjects(@"524", [message getExtension:[UnittestRoot repeatedStringPieceExtension]][1]);
+ XCTAssertEqualObjects(@"525", [message getExtension:[UnittestRoot repeatedCordExtension]][1]);
+}
+
+// -------------------------------------------------------------------
+
+- (void)assertAllFieldsSet:(TestAllTypes *)message
+ repeatedCount:(uint32_t)count {
+ XCTAssertTrue(message.hasOptionalInt32);
+ XCTAssertTrue(message.hasOptionalInt64);
+ XCTAssertTrue(message.hasOptionalUint32);
+ XCTAssertTrue(message.hasOptionalUint64);
+ XCTAssertTrue(message.hasOptionalSint32);
+ XCTAssertTrue(message.hasOptionalSint64);
+ XCTAssertTrue(message.hasOptionalFixed32);
+ XCTAssertTrue(message.hasOptionalFixed64);
+ XCTAssertTrue(message.hasOptionalSfixed32);
+ XCTAssertTrue(message.hasOptionalSfixed64);
+ XCTAssertTrue(message.hasOptionalFloat);
+ XCTAssertTrue(message.hasOptionalDouble);
+ XCTAssertTrue(message.hasOptionalBool);
+ XCTAssertTrue(message.hasOptionalString);
+ XCTAssertTrue(message.hasOptionalBytes);
+
+ XCTAssertTrue(message.hasOptionalGroup);
+ XCTAssertTrue(message.hasOptionalNestedMessage);
+ XCTAssertTrue(message.hasOptionalForeignMessage);
+ XCTAssertTrue(message.hasOptionalImportMessage);
+
+ XCTAssertTrue(message.optionalGroup.hasA);
+ XCTAssertTrue(message.optionalNestedMessage.hasBb);
+ XCTAssertTrue(message.optionalForeignMessage.hasC);
+ XCTAssertTrue(message.optionalImportMessage.hasD);
+
+ XCTAssertTrue(message.hasOptionalNestedEnum);
+ XCTAssertTrue(message.hasOptionalForeignEnum);
+ XCTAssertTrue(message.hasOptionalImportEnum);
+
+ XCTAssertTrue(message.hasOptionalStringPiece);
+ XCTAssertTrue(message.hasOptionalCord);
+
+ XCTAssertEqual(101, message.optionalInt32);
+ XCTAssertEqual(102LL, message.optionalInt64);
+ XCTAssertEqual(103U, message.optionalUint32);
+ XCTAssertEqual(104ULL, message.optionalUint64);
+ XCTAssertEqual(105, message.optionalSint32);
+ XCTAssertEqual(106LL, message.optionalSint64);
+ XCTAssertEqual(107U, message.optionalFixed32);
+ XCTAssertEqual(108ULL, message.optionalFixed64);
+ XCTAssertEqual(109, message.optionalSfixed32);
+ XCTAssertEqual(110LL, message.optionalSfixed64);
+ XCTAssertEqualWithAccuracy(111.0f, message.optionalFloat, 0.1);
+ XCTAssertEqualWithAccuracy(112.0, message.optionalDouble, 0.1);
+ XCTAssertTrue(message.optionalBool);
+ XCTAssertEqualObjects(@"115", message.optionalString);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithEmbeddedNulls],
+ message.optionalBytes);
+
+ XCTAssertEqual(117, message.optionalGroup.a);
+ XCTAssertEqual(118, message.optionalNestedMessage.bb);
+ XCTAssertEqual(119, message.optionalForeignMessage.c);
+ XCTAssertEqual(120, message.optionalImportMessage.d);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Baz, message.optionalNestedEnum);
+ XCTAssertEqual(ForeignEnum_ForeignBaz, message.optionalForeignEnum);
+ XCTAssertEqual(ImportEnum_ImportBaz, message.optionalImportEnum);
+
+ XCTAssertEqualObjects(@"124", message.optionalStringPiece);
+ XCTAssertEqualObjects(@"125", message.optionalCord);
+
+ // -----------------------------------------------------------------
+
+ XCTAssertEqual(count, message.repeatedInt32Array.count);
+ XCTAssertEqual(count, message.repeatedInt64Array.count);
+ XCTAssertEqual(count, message.repeatedUint32Array.count);
+ XCTAssertEqual(count, message.repeatedUint64Array.count);
+ XCTAssertEqual(count, message.repeatedSint32Array.count);
+ XCTAssertEqual(count, message.repeatedSint64Array.count);
+ XCTAssertEqual(count, message.repeatedFixed32Array.count);
+ XCTAssertEqual(count, message.repeatedFixed64Array.count);
+ XCTAssertEqual(count, message.repeatedSfixed32Array.count);
+ XCTAssertEqual(count, message.repeatedSfixed64Array.count);
+ XCTAssertEqual(count, message.repeatedFloatArray.count);
+ XCTAssertEqual(count, message.repeatedDoubleArray.count);
+ XCTAssertEqual(count, message.repeatedBoolArray.count);
+ XCTAssertEqual(count, message.repeatedStringArray.count);
+ XCTAssertEqual(count, message.repeatedBytesArray.count);
+
+ XCTAssertEqual(count, message.repeatedGroupArray.count);
+ XCTAssertEqual(count, message.repeatedNestedMessageArray.count);
+ XCTAssertEqual(count, message.repeatedForeignMessageArray.count);
+ XCTAssertEqual(count, message.repeatedImportMessageArray.count);
+ XCTAssertEqual(count, message.repeatedNestedEnumArray.count);
+ XCTAssertEqual(count, message.repeatedForeignEnumArray.count);
+ XCTAssertEqual(count, message.repeatedImportEnumArray.count);
+
+ XCTAssertEqual(count, message.repeatedStringPieceArray.count);
+ XCTAssertEqual(count, message.repeatedCordArray.count);
+
+ XCTAssertEqual(count, message.repeatedInt32Array_Count);
+ XCTAssertEqual(count, message.repeatedInt64Array_Count);
+ XCTAssertEqual(count, message.repeatedUint32Array_Count);
+ XCTAssertEqual(count, message.repeatedUint64Array_Count);
+ XCTAssertEqual(count, message.repeatedSint32Array_Count);
+ XCTAssertEqual(count, message.repeatedSint64Array_Count);
+ XCTAssertEqual(count, message.repeatedFixed32Array_Count);
+ XCTAssertEqual(count, message.repeatedFixed64Array_Count);
+ XCTAssertEqual(count, message.repeatedSfixed32Array_Count);
+ XCTAssertEqual(count, message.repeatedSfixed64Array_Count);
+ XCTAssertEqual(count, message.repeatedFloatArray_Count);
+ XCTAssertEqual(count, message.repeatedDoubleArray_Count);
+ XCTAssertEqual(count, message.repeatedBoolArray_Count);
+ XCTAssertEqual(count, message.repeatedStringArray_Count);
+ XCTAssertEqual(count, message.repeatedBytesArray_Count);
+
+ XCTAssertEqual(count, message.repeatedGroupArray_Count);
+ XCTAssertEqual(count, message.repeatedNestedMessageArray_Count);
+ XCTAssertEqual(count, message.repeatedForeignMessageArray_Count);
+ XCTAssertEqual(count, message.repeatedImportMessageArray_Count);
+ XCTAssertEqual(count, message.repeatedNestedEnumArray_Count);
+ XCTAssertEqual(count, message.repeatedForeignEnumArray_Count);
+ XCTAssertEqual(count, message.repeatedImportEnumArray_Count);
+
+ XCTAssertEqual(count, message.repeatedStringPieceArray_Count);
+ XCTAssertEqual(count, message.repeatedCordArray_Count);
+
+ for (uint32_t i = 0; i < count; ++i) {
+ XCTAssertEqual((int)(201 + i * 100),
+ [message.repeatedInt32Array valueAtIndex:i]);
+ XCTAssertEqual(202 + i * 100, [message.repeatedInt64Array valueAtIndex:i]);
+ XCTAssertEqual(203 + i * 100, [message.repeatedUint32Array valueAtIndex:i]);
+ XCTAssertEqual(204 + i * 100, [message.repeatedUint64Array valueAtIndex:i]);
+ XCTAssertEqual((int)(205 + i * 100),
+ [message.repeatedSint32Array valueAtIndex:i]);
+ XCTAssertEqual(206 + i * 100, [message.repeatedSint64Array valueAtIndex:i]);
+ XCTAssertEqual(207 + i * 100,
+ [message.repeatedFixed32Array valueAtIndex:i]);
+ XCTAssertEqual(208 + i * 100,
+ [message.repeatedFixed64Array valueAtIndex:i]);
+ XCTAssertEqual((int)(209 + i * 100),
+ [message.repeatedSfixed32Array valueAtIndex:i]);
+ XCTAssertEqual(210 + i * 100,
+ [message.repeatedSfixed64Array valueAtIndex:i]);
+ XCTAssertEqualWithAccuracy(
+ 211 + i * 100, [message.repeatedFloatArray valueAtIndex:i], 0.1);
+ XCTAssertEqualWithAccuracy(
+ 212 + i * 100, [message.repeatedDoubleArray valueAtIndex:i], 0.1);
+ XCTAssertEqual((i % 2) ? YES : NO,
+ [message.repeatedBoolArray valueAtIndex:i]);
+
+ NSString *string = [[NSString alloc] initWithFormat:@"%d", 215 + i * 100];
+ XCTAssertEqualObjects(string, message.repeatedStringArray[i]);
+ [string release];
+
+ NSData *data = [[NSData alloc] initWithUint32_gpbtu:216 + i * 100];
+ XCTAssertEqualObjects(data, message.repeatedBytesArray[i]);
+ [data release];
+
+ XCTAssertEqual((int)(217 + i * 100), ((TestAllTypes_RepeatedGroup*)message.repeatedGroupArray[i]).a);
+ XCTAssertEqual((int)(218 + i * 100), ((TestAllTypes_NestedMessage*)message.repeatedNestedMessageArray[i]).bb);
+ XCTAssertEqual((int)(219 + i * 100), ((ForeignMessage*)message.repeatedForeignMessageArray[i]).c);
+ XCTAssertEqual((int)(220 + i * 100), ((ImportMessage*)message.repeatedImportMessageArray[i]).d);
+
+ XCTAssertEqual((i % 2) ? TestAllTypes_NestedEnum_Bar : TestAllTypes_NestedEnum_Baz, [message.repeatedNestedEnumArray valueAtIndex:i]);
+ XCTAssertEqual((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz, [message.repeatedForeignEnumArray valueAtIndex:i]);
+ XCTAssertEqual((i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz, [message.repeatedImportEnumArray valueAtIndex:i]);
+
+ string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100];
+ XCTAssertEqualObjects(string, message.repeatedStringPieceArray[i]);
+ [string release];
+
+ string = [[NSString alloc] initWithFormat:@"%d", 225 + i * 100];
+ XCTAssertEqualObjects(string, message.repeatedCordArray[i]);
+ [string release];
+ }
+
+ // -----------------------------------------------------------------
+
+ XCTAssertTrue(message.hasDefaultInt32);
+ XCTAssertTrue(message.hasDefaultInt64);
+ XCTAssertTrue(message.hasDefaultUint32);
+ XCTAssertTrue(message.hasDefaultUint64);
+ XCTAssertTrue(message.hasDefaultSint32);
+ XCTAssertTrue(message.hasDefaultSint64);
+ XCTAssertTrue(message.hasDefaultFixed32);
+ XCTAssertTrue(message.hasDefaultFixed64);
+ XCTAssertTrue(message.hasDefaultSfixed32);
+ XCTAssertTrue(message.hasDefaultSfixed64);
+ XCTAssertTrue(message.hasDefaultFloat);
+ XCTAssertTrue(message.hasDefaultDouble);
+ XCTAssertTrue(message.hasDefaultBool);
+ XCTAssertTrue(message.hasDefaultString);
+ XCTAssertTrue(message.hasDefaultBytes);
+
+ XCTAssertTrue(message.hasDefaultNestedEnum);
+ XCTAssertTrue(message.hasDefaultForeignEnum);
+ XCTAssertTrue(message.hasDefaultImportEnum);
+
+ XCTAssertTrue(message.hasDefaultStringPiece);
+ XCTAssertTrue(message.hasDefaultCord);
+
+ XCTAssertEqual(401, message.defaultInt32);
+ XCTAssertEqual(402LL, message.defaultInt64);
+ XCTAssertEqual(403U, message.defaultUint32);
+ XCTAssertEqual(404ULL, message.defaultUint64);
+ XCTAssertEqual(405, message.defaultSint32);
+ XCTAssertEqual(406LL, message.defaultSint64);
+ XCTAssertEqual(407U, message.defaultFixed32);
+ XCTAssertEqual(408ULL, message.defaultFixed64);
+ XCTAssertEqual(409, message.defaultSfixed32);
+ XCTAssertEqual(410LL, message.defaultSfixed64);
+ XCTAssertEqualWithAccuracy(411.0f, message.defaultFloat, 0.1);
+ XCTAssertEqualWithAccuracy(412.0, message.defaultDouble, 0.1);
+ XCTAssertFalse(message.defaultBool);
+ XCTAssertEqualObjects(@"415", message.defaultString);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:416],
+ message.defaultBytes);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Foo, message.defaultNestedEnum);
+ XCTAssertEqual(ForeignEnum_ForeignFoo, message.defaultForeignEnum);
+ XCTAssertEqual(ImportEnum_ImportFoo, message.defaultImportEnum);
+
+ XCTAssertEqualObjects(@"424", message.defaultStringPiece);
+ XCTAssertEqualObjects(@"425", message.defaultCord);
+}
+
+- (void)setAllFields:(TestAllTypes *)message repeatedCount:(uint32_t)count {
+ [message setOptionalInt32:101];
+ [message setOptionalInt64:102];
+ [message setOptionalUint32:103];
+ [message setOptionalUint64:104];
+ [message setOptionalSint32:105];
+ [message setOptionalSint64:106];
+ [message setOptionalFixed32:107];
+ [message setOptionalFixed64:108];
+ [message setOptionalSfixed32:109];
+ [message setOptionalSfixed64:110];
+ [message setOptionalFloat:111];
+ [message setOptionalDouble:112];
+ [message setOptionalBool:YES];
+ [message setOptionalString:@"115"];
+ [message setOptionalBytes:[NSData gpbtu_dataWithEmbeddedNulls]];
+
+ TestAllTypes_OptionalGroup *allTypes = [TestAllTypes_OptionalGroup message];
+ [allTypes setA:117];
+ [message setOptionalGroup:allTypes];
+ TestAllTypes_NestedMessage *nestedMessage =
+ [TestAllTypes_NestedMessage message];
+ [nestedMessage setBb:118];
+ [message setOptionalNestedMessage:nestedMessage];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ [foreignMessage setC:119];
+ [message setOptionalForeignMessage:foreignMessage];
+ ImportMessage *importMessage = [ImportMessage message];
+ [importMessage setD:120];
+ [message setOptionalImportMessage:importMessage];
+
+ [message setOptionalNestedEnum:TestAllTypes_NestedEnum_Baz];
+ [message setOptionalForeignEnum:ForeignEnum_ForeignBaz];
+ [message setOptionalImportEnum:ImportEnum_ImportBaz];
+
+ [message setOptionalStringPiece:@"124"];
+ [message setOptionalCord:@"125"];
+
+ // -----------------------------------------------------------------
+
+ for (uint32_t i = 0; i < count; i++) {
+ [message.repeatedInt32Array addValue:201 + i * 100];
+ [message.repeatedInt64Array addValue:202 + i * 100];
+ [message.repeatedUint32Array addValue:203 + i * 100];
+ [message.repeatedUint64Array addValue:204 + i * 100];
+ [message.repeatedSint32Array addValue:205 + i * 100];
+ [message.repeatedSint64Array addValue:206 + i * 100];
+ [message.repeatedFixed32Array addValue:207 + i * 100];
+ [message.repeatedFixed64Array addValue:208 + i * 100];
+ [message.repeatedSfixed32Array addValue:209 + i * 100];
+ [message.repeatedSfixed64Array addValue:210 + i * 100];
+ [message.repeatedFloatArray addValue:211 + i * 100];
+ [message.repeatedDoubleArray addValue:212 + i * 100];
+ [message.repeatedBoolArray addValue:(i % 2)];
+ NSString *string = [[NSString alloc] initWithFormat:@"%d", 215 + i * 100];
+ [message.repeatedStringArray addObject:string];
+ [string release];
+
+ NSData *data = [[NSData alloc] initWithUint32_gpbtu:216 + i * 100];
+ [message.repeatedBytesArray addObject:data];
+ [data release];
+
+ TestAllTypes_RepeatedGroup *testAll =
+ [[TestAllTypes_RepeatedGroup alloc] init];
+ [testAll setA:217 + i * 100];
+ [message.repeatedGroupArray addObject:testAll];
+ [testAll release];
+
+ nestedMessage = [[TestAllTypes_NestedMessage alloc] init];
+ [nestedMessage setBb:218 + i * 100];
+ [message.repeatedNestedMessageArray addObject:nestedMessage];
+ [nestedMessage release];
+
+ foreignMessage = [[ForeignMessage alloc] init];
+ [foreignMessage setC:219 + i * 100];
+ [message.repeatedForeignMessageArray addObject:foreignMessage];
+ [foreignMessage release];
+
+ importMessage = [[ImportMessage alloc] init];
+ [importMessage setD:220 + i * 100];
+ [message.repeatedImportMessageArray addObject:importMessage];
+ [importMessage release];
+
+ [message.repeatedNestedEnumArray addValue:(i % 2) ? TestAllTypes_NestedEnum_Bar : TestAllTypes_NestedEnum_Baz];
+
+ [message.repeatedForeignEnumArray addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz];
+ [message.repeatedImportEnumArray addValue:(i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz];
+
+ string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100];
+ [message.repeatedStringPieceArray addObject:string];
+ [string release];
+
+ string = [[NSString alloc] initWithFormat:@"%d", 225 + i * 100];
+ [message.repeatedCordArray addObject:string];
+ [string release];
+ }
+ // -----------------------------------------------------------------
+
+ message.defaultInt32 = 401;
+ message.defaultInt64 = 402;
+ message.defaultUint32 = 403;
+ message.defaultUint64 = 404;
+ message.defaultSint32 = 405;
+ message.defaultSint64 = 406;
+ message.defaultFixed32 = 407;
+ message.defaultFixed64 = 408;
+ message.defaultSfixed32 = 409;
+ message.defaultSfixed64 = 410;
+ message.defaultFloat = 411;
+ message.defaultDouble = 412;
+ message.defaultBool = NO;
+ message.defaultString = @"415";
+ message.defaultBytes = [NSData gpbtu_dataWithUint32:416];
+
+ message.defaultNestedEnum = TestAllTypes_NestedEnum_Foo;
+ message.defaultForeignEnum = ForeignEnum_ForeignFoo;
+ message.defaultImportEnum = ImportEnum_ImportFoo;
+
+ message.defaultStringPiece = @"424";
+ message.defaultCord = @"425";
+}
+
+- (void)clearAllFields:(TestAllTypes *)message {
+ message.hasOptionalInt32 = NO;
+ message.hasOptionalInt64 = NO;
+ message.hasOptionalUint32 = NO;
+ message.hasOptionalUint64 = NO;
+ message.hasOptionalSint32 = NO;
+ message.hasOptionalSint64 = NO;
+ message.hasOptionalFixed32 = NO;
+ message.hasOptionalFixed64 = NO;
+ message.hasOptionalSfixed32 = NO;
+ message.hasOptionalSfixed64 = NO;
+ message.hasOptionalFloat = NO;
+ message.hasOptionalDouble = NO;
+ message.hasOptionalBool = NO;
+ message.hasOptionalString = NO;
+ message.hasOptionalBytes = NO;
+
+ message.hasOptionalGroup = NO;
+ message.hasOptionalNestedMessage = NO;
+ message.hasOptionalForeignMessage = NO;
+ message.hasOptionalImportMessage = NO;
+
+ message.hasOptionalNestedEnum = NO;
+ message.hasOptionalForeignEnum = NO;
+ message.hasOptionalImportEnum = NO;
+
+ message.hasOptionalStringPiece = NO;
+ message.hasOptionalCord = NO;
+
+ // -----------------------------------------------------------------
+
+ [message.repeatedInt32Array removeAll];
+ [message.repeatedInt64Array removeAll];
+ [message.repeatedUint32Array removeAll];
+ [message.repeatedUint64Array removeAll];
+ [message.repeatedSint32Array removeAll];
+ [message.repeatedSint64Array removeAll];
+ [message.repeatedFixed32Array removeAll];
+ [message.repeatedFixed64Array removeAll];
+ [message.repeatedSfixed32Array removeAll];
+ [message.repeatedSfixed64Array removeAll];
+ [message.repeatedFloatArray removeAll];
+ [message.repeatedDoubleArray removeAll];
+ [message.repeatedBoolArray removeAll];
+ [message.repeatedStringArray removeAllObjects];
+ [message.repeatedBytesArray removeAllObjects];
+
+ [message.repeatedGroupArray removeAllObjects];
+ [message.repeatedNestedMessageArray removeAllObjects];
+ [message.repeatedForeignMessageArray removeAllObjects];
+ [message.repeatedImportMessageArray removeAllObjects];
+
+ [message.repeatedNestedEnumArray removeAll];
+ [message.repeatedForeignEnumArray removeAll];
+ [message.repeatedImportEnumArray removeAll];
+
+ [message.repeatedStringPieceArray removeAllObjects];
+ [message.repeatedCordArray removeAllObjects];
+
+ // -----------------------------------------------------------------
+
+ message.hasDefaultInt32 = NO;
+ message.hasDefaultInt64 = NO;
+ message.hasDefaultUint32 = NO;
+ message.hasDefaultUint64 = NO;
+ message.hasDefaultSint32 = NO;
+ message.hasDefaultSint64 = NO;
+ message.hasDefaultFixed32 = NO;
+ message.hasDefaultFixed64 = NO;
+ message.hasDefaultSfixed32 = NO;
+ message.hasDefaultSfixed64 = NO;
+ message.hasDefaultFloat = NO;
+ message.hasDefaultDouble = NO;
+ message.hasDefaultBool = NO;
+ message.hasDefaultString = NO;
+ message.hasDefaultBytes = NO;
+
+ message.hasDefaultNestedEnum = NO;
+ message.hasDefaultForeignEnum = NO;
+ message.hasDefaultImportEnum = NO;
+
+ message.hasDefaultStringPiece = NO;
+ message.hasDefaultCord = NO;
+}
+
+- (void)setAllExtensions:(TestAllExtensions *)message
+ repeatedCount:(uint32_t)count {
+ [message setExtension:[UnittestRoot optionalInt32Extension] value:@101];
+ [message setExtension:[UnittestRoot optionalInt64Extension] value:@102L];
+ [message setExtension:[UnittestRoot optionalUint32Extension] value:@103];
+ [message setExtension:[UnittestRoot optionalUint64Extension] value:@104L];
+ [message setExtension:[UnittestRoot optionalSint32Extension] value:@105];
+ [message setExtension:[UnittestRoot optionalSint64Extension] value:@106L];
+ [message setExtension:[UnittestRoot optionalFixed32Extension] value:@107];
+ [message setExtension:[UnittestRoot optionalFixed64Extension] value:@108L];
+ [message setExtension:[UnittestRoot optionalSfixed32Extension] value:@109];
+ [message setExtension:[UnittestRoot optionalSfixed64Extension] value:@110L];
+ [message setExtension:[UnittestRoot optionalFloatExtension] value:@111.0f];
+ [message setExtension:[UnittestRoot optionalDoubleExtension] value:@112.0];
+ [message setExtension:[UnittestRoot optionalBoolExtension] value:@YES];
+ [message setExtension:[UnittestRoot optionalStringExtension] value:@"115"];
+ [message setExtension:[UnittestRoot optionalBytesExtension]
+ value:[NSData gpbtu_dataWithEmbeddedNulls]];
+
+ OptionalGroup_extension *optionalGroup = [OptionalGroup_extension message];
+ [optionalGroup setA:117];
+ [message setExtension:[UnittestRoot optionalGroupExtension]
+ value:optionalGroup];
+ TestAllTypes_NestedMessage *nestedMessage =
+ [TestAllTypes_NestedMessage message];
+ [nestedMessage setBb:118];
+ [message setExtension:[UnittestRoot optionalNestedMessageExtension]
+ value:nestedMessage];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ [foreignMessage setC:119];
+ [message setExtension:[UnittestRoot optionalForeignMessageExtension]
+ value:foreignMessage];
+ ImportMessage *importMessage = [ImportMessage message];
+ [importMessage setD:120];
+ [message setExtension:[UnittestRoot optionalImportMessageExtension]
+ value:importMessage];
+
+ [message setExtension:[UnittestRoot optionalNestedEnumExtension]
+ value:@(TestAllTypes_NestedEnum_Baz)];
+ [message setExtension:[UnittestRoot optionalForeignEnumExtension]
+ value:@(ForeignEnum_ForeignBaz)];
+ [message setExtension:[UnittestRoot optionalImportEnumExtension]
+ value:@(ImportEnum_ImportBaz)];
+
+ [message setExtension:[UnittestRoot optionalStringPieceExtension]
+ value:@"124"];
+ [message setExtension:[UnittestRoot optionalCordExtension] value:@"125"];
+
+ for (uint32_t i = 0; i < count; ++i) {
+ [message addExtension:[UnittestRoot repeatedInt32Extension]
+ value:@(201 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedInt64Extension]
+ value:@(202 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedUint32Extension]
+ value:@(203 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedUint64Extension]
+ value:@(204 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedSint32Extension]
+ value:@(205 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedSint64Extension]
+ value:@(206 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedFixed32Extension]
+ value:@(207 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedFixed64Extension]
+ value:@(208 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedSfixed32Extension]
+ value:@(209 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedSfixed64Extension]
+ value:@(210 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedFloatExtension]
+ value:@(211 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedDoubleExtension]
+ value:@(212 + i * 100)];
+ [message addExtension:[UnittestRoot repeatedBoolExtension]
+ value:@((i % 2) ? YES : NO)];
+ NSString *string = [[NSString alloc] initWithFormat:@"%d", 215 + i * 100];
+ [message addExtension:[UnittestRoot repeatedStringExtension] value:string];
+ [string release];
+ NSData *data = [[NSData alloc] initWithUint32_gpbtu:216 + i * 100];
+ [message addExtension:[UnittestRoot repeatedBytesExtension] value:data];
+ [data release];
+
+ RepeatedGroup_extension *repeatedGroup =
+ [[RepeatedGroup_extension alloc] init];
+ [repeatedGroup setA:217 + i * 100];
+ [message addExtension:[UnittestRoot repeatedGroupExtension]
+ value:repeatedGroup];
+ [repeatedGroup release];
+ nestedMessage = [[TestAllTypes_NestedMessage alloc] init];
+ [nestedMessage setBb:218 + i * 100];
+ [message addExtension:[UnittestRoot repeatedNestedMessageExtension]
+ value:nestedMessage];
+ [nestedMessage release];
+ foreignMessage = [[ForeignMessage alloc] init];
+ [foreignMessage setC:219 + i * 100];
+ [message addExtension:[UnittestRoot repeatedForeignMessageExtension]
+ value:foreignMessage];
+ [foreignMessage release];
+ importMessage = [[ImportMessage alloc] init];
+ [importMessage setD:220 + i * 100];
+ [message addExtension:[UnittestRoot repeatedImportMessageExtension]
+ value:importMessage];
+ [importMessage release];
+ [message addExtension:[UnittestRoot repeatedNestedEnumExtension]
+ value:@((i % 2) ? TestAllTypes_NestedEnum_Bar
+ : TestAllTypes_NestedEnum_Baz)];
+ [message addExtension:[UnittestRoot repeatedForeignEnumExtension]
+ value:@((i % 2) ? ForeignEnum_ForeignBar
+ : ForeignEnum_ForeignBaz)];
+ [message
+ addExtension:[UnittestRoot repeatedImportEnumExtension]
+ value:@((i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz)];
+
+ string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100];
+ [message addExtension:[UnittestRoot repeatedStringPieceExtension]
+ value:string];
+ [string release];
+
+ string = [[NSString alloc] initWithFormat:@"%d", 225 + i * 100];
+ [message addExtension:[UnittestRoot repeatedCordExtension] value:string];
+ [string release];
+ }
+
+ // -----------------------------------------------------------------
+
+ [message setExtension:[UnittestRoot defaultInt32Extension] value:@401];
+ [message setExtension:[UnittestRoot defaultInt64Extension] value:@402L];
+ [message setExtension:[UnittestRoot defaultUint32Extension] value:@403];
+ [message setExtension:[UnittestRoot defaultUint64Extension] value:@404L];
+ [message setExtension:[UnittestRoot defaultSint32Extension] value:@405];
+ [message setExtension:[UnittestRoot defaultSint64Extension] value:@406L];
+ [message setExtension:[UnittestRoot defaultFixed32Extension] value:@407];
+ [message setExtension:[UnittestRoot defaultFixed64Extension] value:@408L];
+ [message setExtension:[UnittestRoot defaultSfixed32Extension] value:@409];
+ [message setExtension:[UnittestRoot defaultSfixed64Extension] value:@410L];
+ [message setExtension:[UnittestRoot defaultFloatExtension] value:@411.0f];
+ [message setExtension:[UnittestRoot defaultDoubleExtension] value:@412.0];
+ [message setExtension:[UnittestRoot defaultBoolExtension] value:@NO];
+ [message setExtension:[UnittestRoot defaultStringExtension] value:@"415"];
+ [message setExtension:[UnittestRoot defaultBytesExtension]
+ value:[NSData gpbtu_dataWithUint32:416]];
+
+ [message setExtension:[UnittestRoot defaultNestedEnumExtension]
+ value:@(TestAllTypes_NestedEnum_Foo)];
+ [message setExtension:[UnittestRoot defaultForeignEnumExtension]
+ value:@(ForeignEnum_ForeignFoo)];
+ [message setExtension:[UnittestRoot defaultImportEnumExtension]
+ value:@(ImportEnum_ImportFoo)];
+
+ [message setExtension:[UnittestRoot defaultStringPieceExtension]
+ value:@"424"];
+ [message setExtension:[UnittestRoot defaultCordExtension] value:@"425"];
+}
+
+- (void)setAllMapFields:(TestMap *)message numEntries:(uint32_t)count {
+ for (uint32_t i = 0; i < count; i++) {
+ [message.mapInt32Int32 setInt32:(i + 1) forKey:100 + i * 100];
+ [message.mapInt64Int64 setInt64:(i + 1) forKey:101 + i * 100];
+ [message.mapUint32Uint32 setUInt32:(i + 1) forKey:102 + i * 100];
+ [message.mapUint64Uint64 setUInt64:(i + 1) forKey:103 + i * 100];
+ [message.mapSint32Sint32 setInt32:(i + 1) forKey:104 + i * 100];
+ [message.mapSint64Sint64 setInt64:(i + 1) forKey:105 + i * 100];
+ [message.mapFixed32Fixed32 setUInt32:(i + 1) forKey:106 + i * 100];
+ [message.mapFixed64Fixed64 setUInt64:(i + 1) forKey:107 + i * 100];
+ [message.mapSfixed32Sfixed32 setInt32:(i + 1) forKey:108 + i * 100];
+ [message.mapSfixed64Sfixed64 setInt64:(i + 1) forKey:109 + i * 100];
+ [message.mapInt32Float setFloat:(i + 1) forKey:110 + i * 100];
+ [message.mapInt32Double setDouble:(i + 1) forKey:111 + i * 100];
+ [message.mapBoolBool setBool:((i % 2) == 1) forKey:((i % 2) == 0)];
+
+ NSString *keyStr = [[NSString alloc] initWithFormat:@"%d", 112 + i * 100];
+ NSString *dataStr = [[NSString alloc] initWithFormat:@"%d", i + 1];
+ [message.mapStringString setObject:dataStr forKey:keyStr];
+ [keyStr release];
+ [dataStr release];
+
+ NSData *data = [[NSData alloc] initWithUint32_gpbtu:i + 1];
+ [message.mapInt32Bytes setObject:data forKey:113 + i * 100];
+ [data release];
+
+ [message.mapInt32Enum
+ setEnum:(i % 2) ? MapEnum_MapEnumBar : MapEnum_MapEnumBaz
+ forKey:114 + i * 100];
+
+ ForeignMessage *subMsg = [[ForeignMessage alloc] init];
+ subMsg.c = i + 1;
+ [message.mapInt32ForeignMessage setObject:subMsg forKey:115 + i * 100];
+ [subMsg release];
+ }
+}
+
+- (void)setAllTestPackedFields:(TestPackedTypes *)message {
+ // Must match -setAllTestUnpackedFields:
+ [message.packedInt32Array addValue:101];
+ [message.packedInt64Array addValue:102];
+ [message.packedUint32Array addValue:103];
+ [message.packedUint64Array addValue:104];
+ [message.packedSint32Array addValue:105];
+ [message.packedSint64Array addValue:106];
+ [message.packedFixed32Array addValue:107];
+ [message.packedFixed64Array addValue:108];
+ [message.packedSfixed32Array addValue:109];
+ [message.packedSfixed64Array addValue:110];
+ [message.packedFloatArray addValue:111.f];
+ [message.packedDoubleArray addValue:112.];
+ [message.packedBoolArray addValue:YES];
+ [message.packedEnumArray addValue:ForeignEnum_ForeignBar];
+
+ [message.packedInt32Array addValue:201];
+ [message.packedInt64Array addValue:302];
+ [message.packedUint32Array addValue:203];
+ [message.packedUint64Array addValue:204];
+ [message.packedSint32Array addValue:205];
+ [message.packedSint64Array addValue:206];
+ [message.packedFixed32Array addValue:207];
+ [message.packedFixed64Array addValue:208];
+ [message.packedSfixed32Array addValue:209];
+ [message.packedSfixed64Array addValue:210];
+ [message.packedFloatArray addValue:211.f];
+ [message.packedDoubleArray addValue:212.];
+ [message.packedBoolArray addValue:NO];
+ [message.packedEnumArray addValue:ForeignEnum_ForeignBaz];
+}
+
+- (void)setAllTestUnpackedFields:(TestUnpackedTypes *)message {
+ // Must match -setAllTestPackedFields:
+ [message.unpackedInt32Array addValue:101];
+ [message.unpackedInt64Array addValue:102];
+ [message.unpackedUint32Array addValue:103];
+ [message.unpackedUint64Array addValue:104];
+ [message.unpackedSint32Array addValue:105];
+ [message.unpackedSint64Array addValue:106];
+ [message.unpackedFixed32Array addValue:107];
+ [message.unpackedFixed64Array addValue:108];
+ [message.unpackedSfixed32Array addValue:109];
+ [message.unpackedSfixed64Array addValue:110];
+ [message.unpackedFloatArray addValue:111.f];
+ [message.unpackedDoubleArray addValue:112.];
+ [message.unpackedBoolArray addValue:YES];
+ [message.unpackedEnumArray addValue:ForeignEnum_ForeignBar];
+
+ [message.unpackedInt32Array addValue:201];
+ [message.unpackedInt64Array addValue:302];
+ [message.unpackedUint32Array addValue:203];
+ [message.unpackedUint64Array addValue:204];
+ [message.unpackedSint32Array addValue:205];
+ [message.unpackedSint64Array addValue:206];
+ [message.unpackedFixed32Array addValue:207];
+ [message.unpackedFixed64Array addValue:208];
+ [message.unpackedSfixed32Array addValue:209];
+ [message.unpackedSfixed64Array addValue:210];
+ [message.unpackedFloatArray addValue:211.f];
+ [message.unpackedDoubleArray addValue:212.];
+ [message.unpackedBoolArray addValue:NO];
+ [message.unpackedEnumArray addValue:ForeignEnum_ForeignBaz];
+}
+
+- (GPBExtensionRegistry *)extensionRegistry {
+ return [UnittestRoot extensionRegistry];
+}
+
+- (TestAllTypes *)allSetRepeatedCount:(uint32_t)count {
+ TestAllTypes *message = [TestAllTypes message];
+ [self setAllFields:message repeatedCount:count];
+ return message;
+}
+
+- (TestAllExtensions *)allExtensionsSetRepeatedCount:(uint32_t)count {
+ TestAllExtensions *message = [TestAllExtensions message];
+ [self setAllExtensions:message repeatedCount:count];
+ return message;
+}
+
+- (TestPackedTypes *)packedSetRepeatedCount:(uint32_t)count {
+ TestPackedTypes *message = [TestPackedTypes message];
+ [self setPackedFields:message repeatedCount:count];
+ return message;
+}
+
+- (TestPackedExtensions *)packedExtensionsSetRepeatedCount:(uint32_t)count {
+ TestPackedExtensions *message = [TestPackedExtensions message];
+ [self setPackedExtensions:message repeatedCount:count];
+ return message;
+}
+
+// -------------------------------------------------------------------
+
+- (void)assertClear:(TestAllTypes *)message {
+ // hasBlah() should initially be NO for all optional fields.
+ XCTAssertFalse(message.hasOptionalInt32);
+ XCTAssertFalse(message.hasOptionalInt64);
+ XCTAssertFalse(message.hasOptionalUint32);
+ XCTAssertFalse(message.hasOptionalUint64);
+ XCTAssertFalse(message.hasOptionalSint32);
+ XCTAssertFalse(message.hasOptionalSint64);
+ XCTAssertFalse(message.hasOptionalFixed32);
+ XCTAssertFalse(message.hasOptionalFixed64);
+ XCTAssertFalse(message.hasOptionalSfixed32);
+ XCTAssertFalse(message.hasOptionalSfixed64);
+ XCTAssertFalse(message.hasOptionalFloat);
+ XCTAssertFalse(message.hasOptionalDouble);
+ XCTAssertFalse(message.hasOptionalBool);
+ XCTAssertFalse(message.hasOptionalString);
+ XCTAssertFalse(message.hasOptionalBytes);
+
+ XCTAssertFalse(message.hasOptionalGroup);
+ XCTAssertFalse(message.hasOptionalNestedMessage);
+ XCTAssertFalse(message.hasOptionalForeignMessage);
+ XCTAssertFalse(message.hasOptionalImportMessage);
+
+ XCTAssertFalse(message.hasOptionalNestedEnum);
+ XCTAssertFalse(message.hasOptionalForeignEnum);
+ XCTAssertFalse(message.hasOptionalImportEnum);
+
+ XCTAssertFalse(message.hasOptionalStringPiece);
+ XCTAssertFalse(message.hasOptionalCord);
+
+ // Optional fields without defaults are set to zero or something like it.
+ XCTAssertEqual(0, message.optionalInt32);
+ XCTAssertEqual(0LL, message.optionalInt64);
+ XCTAssertEqual(0U, message.optionalUint32);
+ XCTAssertEqual(0ULL, message.optionalUint64);
+ XCTAssertEqual(0, message.optionalSint32);
+ XCTAssertEqual(0LL, message.optionalSint64);
+ XCTAssertEqual(0U, message.optionalFixed32);
+ XCTAssertEqual(0ULL, message.optionalFixed64);
+ XCTAssertEqual(0, message.optionalSfixed32);
+ XCTAssertEqual(0LL, message.optionalSfixed64);
+ XCTAssertEqual(0.0f, message.optionalFloat);
+ XCTAssertEqual(0.0, message.optionalDouble);
+ XCTAssertFalse(message.optionalBool);
+ XCTAssertEqualObjects(message.optionalString, @"");
+ XCTAssertEqualObjects(message.optionalBytes, GPBEmptyNSData());
+
+ // Embedded messages should also be clear.
+ XCTAssertFalse(message.hasOptionalGroup);
+ XCTAssertFalse(message.hasOptionalNestedMessage);
+ XCTAssertFalse(message.hasOptionalForeignMessage);
+ XCTAssertFalse(message.hasOptionalImportMessage);
+
+ // Enums without defaults are set to the first value in the enum.
+ XCTAssertEqual(TestAllTypes_NestedEnum_Foo, message.optionalNestedEnum);
+ XCTAssertEqual(ForeignEnum_ForeignFoo, message.optionalForeignEnum);
+ XCTAssertEqual(ImportEnum_ImportFoo, message.optionalImportEnum);
+
+ XCTAssertEqualObjects(message.optionalStringPiece, @"");
+ XCTAssertEqualObjects(message.optionalCord, @"");
+
+ // Repeated fields are empty.
+
+ XCTAssertEqual(0U, message.repeatedInt32Array.count);
+ XCTAssertEqual(0U, message.repeatedInt64Array.count);
+ XCTAssertEqual(0U, message.repeatedUint32Array.count);
+ XCTAssertEqual(0U, message.repeatedUint64Array.count);
+ XCTAssertEqual(0U, message.repeatedSint32Array.count);
+ XCTAssertEqual(0U, message.repeatedSint64Array.count);
+ XCTAssertEqual(0U, message.repeatedFixed32Array.count);
+ XCTAssertEqual(0U, message.repeatedFixed64Array.count);
+ XCTAssertEqual(0U, message.repeatedSfixed32Array.count);
+ XCTAssertEqual(0U, message.repeatedSfixed64Array.count);
+ XCTAssertEqual(0U, message.repeatedFloatArray.count);
+ XCTAssertEqual(0U, message.repeatedDoubleArray.count);
+ XCTAssertEqual(0U, message.repeatedBoolArray.count);
+ XCTAssertEqual(0U, message.repeatedStringArray.count);
+ XCTAssertEqual(0U, message.repeatedBytesArray.count);
+
+ XCTAssertEqual(0U, message.repeatedGroupArray.count);
+ XCTAssertEqual(0U, message.repeatedNestedMessageArray.count);
+ XCTAssertEqual(0U, message.repeatedForeignMessageArray.count);
+ XCTAssertEqual(0U, message.repeatedImportMessageArray.count);
+ XCTAssertEqual(0U, message.repeatedNestedEnumArray.count);
+ XCTAssertEqual(0U, message.repeatedForeignEnumArray.count);
+ XCTAssertEqual(0U, message.repeatedImportEnumArray.count);
+
+ XCTAssertEqual(0U, message.repeatedStringPieceArray.count);
+ XCTAssertEqual(0U, message.repeatedCordArray.count);
+
+ XCTAssertEqual(0U, message.repeatedInt32Array_Count);
+ XCTAssertEqual(0U, message.repeatedInt64Array_Count);
+ XCTAssertEqual(0U, message.repeatedUint32Array_Count);
+ XCTAssertEqual(0U, message.repeatedUint64Array_Count);
+ XCTAssertEqual(0U, message.repeatedSint32Array_Count);
+ XCTAssertEqual(0U, message.repeatedSint64Array_Count);
+ XCTAssertEqual(0U, message.repeatedFixed32Array_Count);
+ XCTAssertEqual(0U, message.repeatedFixed64Array_Count);
+ XCTAssertEqual(0U, message.repeatedSfixed32Array_Count);
+ XCTAssertEqual(0U, message.repeatedSfixed64Array_Count);
+ XCTAssertEqual(0U, message.repeatedFloatArray_Count);
+ XCTAssertEqual(0U, message.repeatedDoubleArray_Count);
+ XCTAssertEqual(0U, message.repeatedBoolArray_Count);
+ XCTAssertEqual(0U, message.repeatedStringArray_Count);
+ XCTAssertEqual(0U, message.repeatedBytesArray_Count);
+
+ XCTAssertEqual(0U, message.repeatedGroupArray_Count);
+ XCTAssertEqual(0U, message.repeatedNestedMessageArray_Count);
+ XCTAssertEqual(0U, message.repeatedForeignMessageArray_Count);
+ XCTAssertEqual(0U, message.repeatedImportMessageArray_Count);
+ XCTAssertEqual(0U, message.repeatedNestedEnumArray_Count);
+ XCTAssertEqual(0U, message.repeatedForeignEnumArray_Count);
+ XCTAssertEqual(0U, message.repeatedImportEnumArray_Count);
+
+ XCTAssertEqual(0U, message.repeatedStringPieceArray_Count);
+ XCTAssertEqual(0U, message.repeatedCordArray_Count);
+
+ // hasBlah() should also be NO for all default fields.
+ XCTAssertFalse(message.hasDefaultInt32);
+ XCTAssertFalse(message.hasDefaultInt64);
+ XCTAssertFalse(message.hasDefaultUint32);
+ XCTAssertFalse(message.hasDefaultUint64);
+ XCTAssertFalse(message.hasDefaultSint32);
+ XCTAssertFalse(message.hasDefaultSint64);
+ XCTAssertFalse(message.hasDefaultFixed32);
+ XCTAssertFalse(message.hasDefaultFixed64);
+ XCTAssertFalse(message.hasDefaultSfixed32);
+ XCTAssertFalse(message.hasDefaultSfixed64);
+ XCTAssertFalse(message.hasDefaultFloat);
+ XCTAssertFalse(message.hasDefaultDouble);
+ XCTAssertFalse(message.hasDefaultBool);
+ XCTAssertFalse(message.hasDefaultString);
+ XCTAssertFalse(message.hasDefaultBytes);
+
+ XCTAssertFalse(message.hasDefaultNestedEnum);
+ XCTAssertFalse(message.hasDefaultForeignEnum);
+ XCTAssertFalse(message.hasDefaultImportEnum);
+
+ XCTAssertFalse(message.hasDefaultStringPiece);
+ XCTAssertFalse(message.hasDefaultCord);
+
+ // Fields with defaults have their default values (duh).
+ XCTAssertEqual(41, message.defaultInt32);
+ XCTAssertEqual(42LL, message.defaultInt64);
+ XCTAssertEqual(43U, message.defaultUint32);
+ XCTAssertEqual(44ULL, message.defaultUint64);
+ XCTAssertEqual(-45, message.defaultSint32);
+ XCTAssertEqual(46LL, message.defaultSint64);
+ XCTAssertEqual(47U, message.defaultFixed32);
+ XCTAssertEqual(48ULL, message.defaultFixed64);
+ XCTAssertEqual(49, message.defaultSfixed32);
+ XCTAssertEqual(-50LL, message.defaultSfixed64);
+ XCTAssertEqualWithAccuracy(51.5f, message.defaultFloat, 0.1);
+ XCTAssertEqualWithAccuracy(52e3, message.defaultDouble, 0.1);
+ XCTAssertTrue(message.defaultBool);
+ XCTAssertEqualObjects(@"hello", message.defaultString);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithCString:"world"],
+ message.defaultBytes);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Bar, message.defaultNestedEnum);
+ XCTAssertEqual(ForeignEnum_ForeignBar, message.defaultForeignEnum);
+ XCTAssertEqual(ImportEnum_ImportBar, message.defaultImportEnum);
+
+ XCTAssertEqualObjects(@"abc", message.defaultStringPiece);
+ XCTAssertEqualObjects(@"123", message.defaultCord);
+}
+
+- (void)assertExtensionsClear:(TestAllExtensions *)message {
+ // hasBlah() should initially be NO for all optional fields.
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalInt32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalInt64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalUint32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalUint64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalSint32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalSint64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalFixed32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalFixed64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalSfixed32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalSfixed64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalFloatExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalDoubleExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalBoolExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalStringExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalBytesExtension]]);
+
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalNestedMessageExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalForeignMessageExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalImportMessageExtension]]);
+
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalNestedEnumExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalForeignEnumExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalImportEnumExtension]]);
+
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalStringPieceExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot optionalCordExtension]]);
+
+ // Optional fields without defaults are set to zero or something like it.
+ XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalInt32Extension]] intValue]);
+ XCTAssertEqual(0LL,[[message getExtension:[UnittestRoot optionalInt64Extension]] longLongValue]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot optionalUint32Extension]] unsignedIntValue]);
+ XCTAssertEqual(0ULL, [[message getExtension:[UnittestRoot optionalUint64Extension]] unsignedLongLongValue]);
+ XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalSint32Extension]] intValue]);
+ XCTAssertEqual(0LL, [[message getExtension:[UnittestRoot optionalSint64Extension]] longLongValue]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot optionalFixed32Extension]] unsignedIntValue]);
+ XCTAssertEqual(0ULL, [[message getExtension:[UnittestRoot optionalFixed64Extension]] unsignedLongLongValue]);
+ XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalSfixed32Extension]] intValue]);
+ XCTAssertEqual(0LL, [[message getExtension:[UnittestRoot optionalSfixed64Extension]] longLongValue]);
+ XCTAssertEqualWithAccuracy(0.0f, [[message getExtension:[UnittestRoot optionalFloatExtension]] floatValue], 0.01);
+ XCTAssertEqualWithAccuracy(0.0, [[message getExtension:[UnittestRoot optionalDoubleExtension]] doubleValue], 0.01);
+ XCTAssertFalse([[message getExtension:[UnittestRoot optionalBoolExtension]] boolValue]);
+ XCTAssertEqualObjects(@"", [message getExtension:[UnittestRoot optionalStringExtension]]);
+ XCTAssertEqualObjects(GPBEmptyNSData(), [message getExtension:[UnittestRoot optionalBytesExtension]]);
+
+ // Embedded messages should also be clear.
+
+ XCTAssertFalse([[message getExtension:[UnittestRoot optionalGroupExtension]] hasA]);
+ XCTAssertFalse([[message getExtension:[UnittestRoot optionalNestedMessageExtension]] hasBb]);
+ XCTAssertFalse([[message getExtension:[UnittestRoot optionalForeignMessageExtension]] hasC]);
+ XCTAssertFalse([[message getExtension:[UnittestRoot optionalImportMessageExtension]] hasD]);
+
+ XCTAssertEqual(0, [(TestAllTypes_OptionalGroup*)[message getExtension:[UnittestRoot optionalGroupExtension]] a]);
+ XCTAssertEqual(0, [(TestAllTypes_NestedMessage*)[message getExtension:[UnittestRoot optionalNestedMessageExtension]] bb]);
+ XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalForeignMessageExtension]] c]);
+ XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalImportMessageExtension]] d]);
+
+ // Enums without defaults are set to the first value in the enum.
+ XCTAssertEqual(TestAllTypes_NestedEnum_Foo,
+ [[message getExtension:[UnittestRoot optionalNestedEnumExtension]] intValue]);
+ XCTAssertEqual(ForeignEnum_ForeignFoo,
+ [[message getExtension:[UnittestRoot optionalForeignEnumExtension]] intValue]);
+ XCTAssertEqual(ImportEnum_ImportFoo,
+ [[message getExtension:[UnittestRoot optionalImportEnumExtension]] intValue]);
+
+ XCTAssertEqualObjects(@"", [message getExtension:[UnittestRoot optionalStringPieceExtension]]);
+ XCTAssertEqualObjects(@"", [message getExtension:[UnittestRoot optionalCordExtension]]);
+
+ // Repeated fields are empty.
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedInt32Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedInt64Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedUint32Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedUint64Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedSint32Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedSint64Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedFixed32Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedFixed64Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedSfixed32Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedFloatExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedDoubleExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedBoolExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedStringExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedBytesExtension]] count]);
+
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedGroupExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedNestedMessageExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedNestedEnumExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedForeignEnumExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedImportEnumExtension]] count]);
+
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedStringPieceExtension]] count]);
+ XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedCordExtension]] count]);
+
+ // hasBlah() should also be NO for all default fields.
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultInt32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultInt64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultUint32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultUint64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultSint32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultSint64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultFixed32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultFixed64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultSfixed32Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultSfixed64Extension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultFloatExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultDoubleExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultBoolExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultStringExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultBytesExtension]]);
+
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultNestedEnumExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultForeignEnumExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultImportEnumExtension]]);
+
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultStringPieceExtension]]);
+ XCTAssertFalse([message hasExtension:[UnittestRoot defaultCordExtension]]);
+
+ // Fields with defaults have their default values (duh).
+ XCTAssertEqual( 41, [[message getExtension:[UnittestRoot defaultInt32Extension]] intValue]);
+ XCTAssertEqual( 42LL, [[message getExtension:[UnittestRoot defaultInt64Extension]] longLongValue]);
+ XCTAssertEqual( 43U, [[message getExtension:[UnittestRoot defaultUint32Extension]] unsignedIntValue]);
+ XCTAssertEqual( 44ULL, [[message getExtension:[UnittestRoot defaultUint64Extension]] unsignedLongLongValue]);
+ XCTAssertEqual(-45, [[message getExtension:[UnittestRoot defaultSint32Extension]] intValue]);
+ XCTAssertEqual( 46LL, [[message getExtension:[UnittestRoot defaultSint64Extension]] longLongValue]);
+ XCTAssertEqual( 47, [[message getExtension:[UnittestRoot defaultFixed32Extension]] intValue]);
+ XCTAssertEqual( 48ULL, [[message getExtension:[UnittestRoot defaultFixed64Extension]] unsignedLongLongValue]);
+ XCTAssertEqual( 49, [[message getExtension:[UnittestRoot defaultSfixed32Extension]] intValue]);
+ XCTAssertEqual(-50LL, [[message getExtension:[UnittestRoot defaultSfixed64Extension]] longLongValue]);
+ XCTAssertEqualWithAccuracy( 51.5f, [[message getExtension:[UnittestRoot defaultFloatExtension]] floatValue], 0.01);
+ XCTAssertEqualWithAccuracy( 52e3, [[message getExtension:[UnittestRoot defaultDoubleExtension]] doubleValue], 0.01);
+ XCTAssertTrue([[message getExtension:[UnittestRoot defaultBoolExtension]] boolValue]);
+ XCTAssertEqualObjects(@"hello", [message getExtension:[UnittestRoot defaultStringExtension]]);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithCString:"world"], [message getExtension:[UnittestRoot defaultBytesExtension]]);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Bar,
+ [[message getExtension:[UnittestRoot defaultNestedEnumExtension]] intValue]);
+ XCTAssertEqual(ForeignEnum_ForeignBar,
+ [[message getExtension:[UnittestRoot defaultForeignEnumExtension]] intValue]);
+ XCTAssertEqual(ImportEnum_ImportBar,
+ [[message getExtension:[UnittestRoot defaultImportEnumExtension]] intValue]);
+
+ XCTAssertEqualObjects(@"abc", [message getExtension:[UnittestRoot defaultStringPieceExtension]]);
+ XCTAssertEqualObjects(@"123", [message getExtension:[UnittestRoot defaultCordExtension]]);
+}
+
+- (void)modifyRepeatedFields:(TestAllTypes *)message {
+ [message.repeatedInt32Array replaceValueAtIndex:1 withValue:501];
+ [message.repeatedInt64Array replaceValueAtIndex:1 withValue:502];
+ [message.repeatedUint32Array replaceValueAtIndex:1 withValue:503];
+ [message.repeatedUint64Array replaceValueAtIndex:1 withValue:504];
+ [message.repeatedSint32Array replaceValueAtIndex:1 withValue:505];
+ [message.repeatedSint64Array replaceValueAtIndex:1 withValue:506];
+ [message.repeatedFixed32Array replaceValueAtIndex:1 withValue:507];
+ [message.repeatedFixed64Array replaceValueAtIndex:1 withValue:508];
+ [message.repeatedSfixed32Array replaceValueAtIndex:1 withValue:509];
+ [message.repeatedSfixed64Array replaceValueAtIndex:1 withValue:510];
+ [message.repeatedFloatArray replaceValueAtIndex:1 withValue:511];
+ [message.repeatedDoubleArray replaceValueAtIndex:1 withValue:512];
+ [message.repeatedBoolArray replaceValueAtIndex:1 withValue:YES];
+ [message.repeatedStringArray replaceObjectAtIndex:1 withObject:@"515"];
+
+ NSData *data = [[NSData alloc] initWithUint32_gpbtu:516];
+ [message.repeatedBytesArray replaceObjectAtIndex:1 withObject:data];
+ [data release];
+
+ TestAllTypes_RepeatedGroup *testAll =
+ [[TestAllTypes_RepeatedGroup alloc] init];
+ [testAll setA:517];
+ [message.repeatedGroupArray replaceObjectAtIndex:1 withObject:testAll];
+ [testAll release];
+
+ TestAllTypes_NestedMessage *nestedMessage =
+ [[TestAllTypes_NestedMessage alloc] init];
+ [nestedMessage setBb:518];
+ [message.repeatedNestedMessageArray replaceObjectAtIndex:1
+ withObject:nestedMessage];
+ [nestedMessage release];
+
+ ForeignMessage *foreignMessage = [[ForeignMessage alloc] init];
+ [foreignMessage setC:519];
+ [message.repeatedForeignMessageArray replaceObjectAtIndex:1
+ withObject:foreignMessage];
+ [foreignMessage release];
+
+ ImportMessage *importMessage = [[ImportMessage alloc] init];
+ [importMessage setD:520];
+ [message.repeatedImportMessageArray replaceObjectAtIndex:1
+ withObject:importMessage];
+ [importMessage release];
+
+ [message.repeatedNestedEnumArray replaceValueAtIndex:1 withValue:TestAllTypes_NestedEnum_Foo];
+ [message.repeatedForeignEnumArray replaceValueAtIndex:1 withValue:ForeignEnum_ForeignFoo];
+ [message.repeatedImportEnumArray replaceValueAtIndex:1 withValue:ImportEnum_ImportFoo];
+
+ [message.repeatedStringPieceArray replaceObjectAtIndex:1 withObject:@"524"];
+ [message.repeatedCordArray replaceObjectAtIndex:1 withObject:@"525"];
+}
+
+- (void)assertRepeatedFieldsModified:(TestAllTypes *)message
+ repeatedCount:(uint32_t)count {
+ // ModifyRepeatedFields only sets the second repeated element of each
+ // field. In addition to verifying this, we also verify that the first
+ // element and size were *not* modified.
+
+ XCTAssertEqual(count, message.repeatedInt32Array.count);
+ XCTAssertEqual(count, message.repeatedInt64Array.count);
+ XCTAssertEqual(count, message.repeatedUint32Array.count);
+ XCTAssertEqual(count, message.repeatedUint64Array.count);
+ XCTAssertEqual(count, message.repeatedSint32Array.count);
+ XCTAssertEqual(count, message.repeatedSint64Array.count);
+ XCTAssertEqual(count, message.repeatedFixed32Array.count);
+ XCTAssertEqual(count, message.repeatedFixed64Array.count);
+ XCTAssertEqual(count, message.repeatedSfixed32Array.count);
+ XCTAssertEqual(count, message.repeatedSfixed64Array.count);
+ XCTAssertEqual(count, message.repeatedFloatArray.count);
+ XCTAssertEqual(count, message.repeatedDoubleArray.count);
+ XCTAssertEqual(count, message.repeatedBoolArray.count);
+ XCTAssertEqual(count, message.repeatedStringArray.count);
+ XCTAssertEqual(count, message.repeatedBytesArray.count);
+
+ XCTAssertEqual(count, message.repeatedGroupArray.count);
+ XCTAssertEqual(count, message.repeatedNestedMessageArray.count);
+ XCTAssertEqual(count, message.repeatedForeignMessageArray.count);
+ XCTAssertEqual(count, message.repeatedImportMessageArray.count);
+ XCTAssertEqual(count, message.repeatedNestedEnumArray.count);
+ XCTAssertEqual(count, message.repeatedForeignEnumArray.count);
+ XCTAssertEqual(count, message.repeatedImportEnumArray.count);
+
+ XCTAssertEqual(count, message.repeatedStringPieceArray.count);
+ XCTAssertEqual(count, message.repeatedCordArray.count);
+
+ XCTAssertEqual(count, message.repeatedInt32Array_Count);
+ XCTAssertEqual(count, message.repeatedInt64Array_Count);
+ XCTAssertEqual(count, message.repeatedUint32Array_Count);
+ XCTAssertEqual(count, message.repeatedUint64Array_Count);
+ XCTAssertEqual(count, message.repeatedSint32Array_Count);
+ XCTAssertEqual(count, message.repeatedSint64Array_Count);
+ XCTAssertEqual(count, message.repeatedFixed32Array_Count);
+ XCTAssertEqual(count, message.repeatedFixed64Array_Count);
+ XCTAssertEqual(count, message.repeatedSfixed32Array_Count);
+ XCTAssertEqual(count, message.repeatedSfixed64Array_Count);
+ XCTAssertEqual(count, message.repeatedFloatArray_Count);
+ XCTAssertEqual(count, message.repeatedDoubleArray_Count);
+ XCTAssertEqual(count, message.repeatedBoolArray_Count);
+ XCTAssertEqual(count, message.repeatedStringArray_Count);
+ XCTAssertEqual(count, message.repeatedBytesArray_Count);
+
+ XCTAssertEqual(count, message.repeatedGroupArray_Count);
+ XCTAssertEqual(count, message.repeatedNestedMessageArray_Count);
+ XCTAssertEqual(count, message.repeatedForeignMessageArray_Count);
+ XCTAssertEqual(count, message.repeatedImportMessageArray_Count);
+ XCTAssertEqual(count, message.repeatedNestedEnumArray_Count);
+ XCTAssertEqual(count, message.repeatedForeignEnumArray_Count);
+ XCTAssertEqual(count, message.repeatedImportEnumArray_Count);
+
+ XCTAssertEqual(count, message.repeatedStringPieceArray_Count);
+ XCTAssertEqual(count, message.repeatedCordArray_Count);
+
+ XCTAssertEqual(201, [message.repeatedInt32Array valueAtIndex:0]);
+ XCTAssertEqual(202LL, [message.repeatedInt64Array valueAtIndex:0]);
+ XCTAssertEqual(203U, [message.repeatedUint32Array valueAtIndex:0]);
+ XCTAssertEqual(204ULL, [message.repeatedUint64Array valueAtIndex:0]);
+ XCTAssertEqual(205, [message.repeatedSint32Array valueAtIndex:0]);
+ XCTAssertEqual(206LL, [message.repeatedSint64Array valueAtIndex:0]);
+ XCTAssertEqual(207U, [message.repeatedFixed32Array valueAtIndex:0]);
+ XCTAssertEqual(208ULL, [message.repeatedFixed64Array valueAtIndex:0]);
+ XCTAssertEqual(209, [message.repeatedSfixed32Array valueAtIndex:0]);
+ XCTAssertEqual(210LL, [message.repeatedSfixed64Array valueAtIndex:0]);
+ XCTAssertEqualWithAccuracy(211.0f, [message.repeatedFloatArray valueAtIndex:0], 0.01);
+ XCTAssertEqualWithAccuracy(212.0, [message.repeatedDoubleArray valueAtIndex:0], 0.01);
+ XCTAssertFalse([message.repeatedBoolArray valueAtIndex:0]);
+ XCTAssertEqualObjects(@"215", message.repeatedStringArray[0]);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:216],
+ message.repeatedBytesArray[0]);
+
+ XCTAssertEqual(217, ((TestAllTypes_RepeatedGroup*)message.repeatedGroupArray[0]).a);
+ XCTAssertEqual(218, ((TestAllTypes_NestedMessage*)message.repeatedNestedMessageArray[0]).bb);
+ XCTAssertEqual(219, ((ForeignMessage*)message.repeatedForeignMessageArray[0]).c);
+ XCTAssertEqual(220, ((ImportMessage*)message.repeatedImportMessageArray[0]).d);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Baz, [message.repeatedNestedEnumArray valueAtIndex:0]);
+ XCTAssertEqual(ForeignEnum_ForeignBaz, [message.repeatedForeignEnumArray valueAtIndex:0]);
+ XCTAssertEqual(ImportEnum_ImportBaz, [message.repeatedImportEnumArray valueAtIndex:0]);
+
+ XCTAssertEqualObjects(@"224", message.repeatedStringPieceArray[0]);
+ XCTAssertEqualObjects(@"225", message.repeatedCordArray[0]);
+
+ // Actually verify the second (modified) elements now.
+ XCTAssertEqual(501, [message.repeatedInt32Array valueAtIndex:1]);
+ XCTAssertEqual(502LL, [message.repeatedInt64Array valueAtIndex:1]);
+ XCTAssertEqual(503U, [message.repeatedUint32Array valueAtIndex:1]);
+ XCTAssertEqual(504ULL, [message.repeatedUint64Array valueAtIndex:1]);
+ XCTAssertEqual(505, [message.repeatedSint32Array valueAtIndex:1]);
+ XCTAssertEqual(506LL, [message.repeatedSint64Array valueAtIndex:1]);
+ XCTAssertEqual(507U, [message.repeatedFixed32Array valueAtIndex:1]);
+ XCTAssertEqual(508ULL, [message.repeatedFixed64Array valueAtIndex:1]);
+ XCTAssertEqual(509, [message.repeatedSfixed32Array valueAtIndex:1]);
+ XCTAssertEqual(510LL, [message.repeatedSfixed64Array valueAtIndex:1]);
+ XCTAssertEqualWithAccuracy(511.0f, [message.repeatedFloatArray valueAtIndex:1], 0.01);
+ XCTAssertEqualWithAccuracy(512.0, [message.repeatedDoubleArray valueAtIndex:1], 0.01);
+ XCTAssertTrue([message.repeatedBoolArray valueAtIndex:1]);
+ XCTAssertEqualObjects(@"515", message.repeatedStringArray[1]);
+ XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:516],
+ message.repeatedBytesArray[1]);
+
+ XCTAssertEqual(517, ((TestAllTypes_RepeatedGroup*)message.repeatedGroupArray[1]).a);
+ XCTAssertEqual(518, ((TestAllTypes_NestedMessage*)message.repeatedNestedMessageArray[1]).bb);
+ XCTAssertEqual(519, ((ForeignMessage*)message.repeatedForeignMessageArray[1]).c);
+ XCTAssertEqual(520, ((ImportMessage*)message.repeatedImportMessageArray[1]).d);
+
+ XCTAssertEqual(TestAllTypes_NestedEnum_Foo, [message.repeatedNestedEnumArray valueAtIndex:1]);
+ XCTAssertEqual(ForeignEnum_ForeignFoo, [message.repeatedForeignEnumArray valueAtIndex:1]);
+ XCTAssertEqual(ImportEnum_ImportFoo, [message.repeatedImportEnumArray valueAtIndex:1]);
+
+ XCTAssertEqualObjects(@"524", message.repeatedStringPieceArray[1]);
+ XCTAssertEqualObjects(@"525", message.repeatedCordArray[1]);
+}
+
+- (void)setPackedFields:(TestPackedTypes *)message
+ repeatedCount:(uint32_t)count {
+ // Must match -setUnpackedFields:repeatedCount:
+ // Must match -setPackedExtensions:repeatedCount:
+ // Must match -setUnpackedExtensions:repeatedCount:
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedInt32Array addValue:601 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedInt64Array addValue:602 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedUint32Array addValue:603 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedUint64Array addValue:604 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedSint32Array addValue:605 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedSint64Array addValue:606 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedFixed32Array addValue:607 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedFixed64Array addValue:608 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedSfixed32Array addValue:609 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedSfixed64Array addValue:610 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedFloatArray addValue:611 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedDoubleArray addValue:612 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedBoolArray addValue:(i % 2) ? YES : NO];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.packedEnumArray
+ addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz];
+ }
+}
+
+- (void)setUnpackedFields:(TestUnpackedTypes *)message
+ repeatedCount:(uint32_t)count {
+ // Must match -setPackedFields:repeatedCount:
+ // Must match -setPackedExtensions:repeatedCount:
+ // Must match -setUnpackedExtensions:repeatedCount:
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedInt32Array addValue:601 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedInt64Array addValue:602 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedUint32Array addValue:603 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedUint64Array addValue:604 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedSint32Array addValue:605 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedSint64Array addValue:606 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedFixed32Array addValue:607 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedFixed64Array addValue:608 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedSfixed32Array addValue:609 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedSfixed64Array addValue:610 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedFloatArray addValue:611 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedDoubleArray addValue:612 + i * 100];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedBoolArray addValue:(i % 2) ? YES : NO];
+ }
+ for (uint32_t i = 0; i < count; ++i) {
+ [message.unpackedEnumArray
+ addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz];
+ }
+}
+
+- (void)assertPackedFieldsSet:(TestPackedTypes *)message
+ repeatedCount:(uint32_t)count {
+ XCTAssertEqual(count, message.packedInt32Array.count);
+ XCTAssertEqual(count, message.packedInt64Array.count);
+ XCTAssertEqual(count, message.packedUint32Array.count);
+ XCTAssertEqual(count, message.packedUint64Array.count);
+ XCTAssertEqual(count, message.packedSint32Array.count);
+ XCTAssertEqual(count, message.packedSint64Array.count);
+ XCTAssertEqual(count, message.packedFixed32Array.count);
+ XCTAssertEqual(count, message.packedFixed64Array.count);
+ XCTAssertEqual(count, message.packedSfixed32Array.count);
+ XCTAssertEqual(count, message.packedSfixed64Array.count);
+ XCTAssertEqual(count, message.packedFloatArray.count);
+ XCTAssertEqual(count, message.packedDoubleArray.count);
+ XCTAssertEqual(count, message.packedBoolArray.count);
+ XCTAssertEqual(count, message.packedEnumArray.count);
+ for (uint32_t i = 0; i < count; ++i) {
+ XCTAssertEqual((int)(601 + i * 100),
+ [message.packedInt32Array valueAtIndex:i]);
+ XCTAssertEqual(602 + i * 100, [message.packedInt64Array valueAtIndex:i]);
+ XCTAssertEqual(603 + i * 100, [message.packedUint32Array valueAtIndex:i]);
+ XCTAssertEqual(604 + i * 100, [message.packedUint64Array valueAtIndex:i]);
+ XCTAssertEqual((int)(605 + i * 100),
+ [message.packedSint32Array valueAtIndex:i]);
+ XCTAssertEqual(606 + i * 100, [message.packedSint64Array valueAtIndex:i]);
+ XCTAssertEqual(607 + i * 100, [message.packedFixed32Array valueAtIndex:i]);
+ XCTAssertEqual(608 + i * 100, [message.packedFixed64Array valueAtIndex:i]);
+ XCTAssertEqual((int)(609 + i * 100),
+ [message.packedSfixed32Array valueAtIndex:i]);
+ XCTAssertEqual(610 + i * 100, [message.packedSfixed64Array valueAtIndex:i]);
+ XCTAssertEqualWithAccuracy(611 + i * 100,
+ [message.packedFloatArray valueAtIndex:i], 0.01);
+ XCTAssertEqualWithAccuracy(
+ 612 + i * 100, [message.packedDoubleArray valueAtIndex:i], 0.01);
+ XCTAssertEqual((i % 2) ? YES : NO,
+ [message.packedBoolArray valueAtIndex:i]);
+ XCTAssertEqual((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz,
+ [message.packedEnumArray valueAtIndex:i]);
+ }
+}
+
+- (void)setPackedExtensions:(TestPackedExtensions *)message
+ repeatedCount:(uint32_t)count {
+ // Must match -setPackedFields:repeatedCount:
+ // Must match -setUnpackedFields:repeatedCount:
+ // Must match -setUnpackedExtensions:repeatedCount:
+ for (uint32_t i = 0; i < count; i++) {
+ [message addExtension:[UnittestRoot packedInt32Extension]
+ value:@(601 + i * 100)];
+ [message addExtension:[UnittestRoot packedInt64Extension]
+ value:@(602 + i * 100)];
+ [message addExtension:[UnittestRoot packedUint32Extension]
+ value:@(603 + i * 100)];
+ [message addExtension:[UnittestRoot packedUint64Extension]
+ value:@(604 + i * 100)];
+ [message addExtension:[UnittestRoot packedSint32Extension]
+ value:@(605 + i * 100)];
+ [message addExtension:[UnittestRoot packedSint64Extension]
+ value:@(606 + i * 100)];
+ [message addExtension:[UnittestRoot packedFixed32Extension]
+ value:@(607 + i * 100)];
+ [message addExtension:[UnittestRoot packedFixed64Extension]
+ value:@(608 + i * 100)];
+ [message addExtension:[UnittestRoot packedSfixed32Extension]
+ value:@(609 + i * 100)];
+ [message addExtension:[UnittestRoot packedSfixed64Extension]
+ value:@(610 + i * 100)];
+ [message addExtension:[UnittestRoot packedFloatExtension]
+ value:@(611 + i * 100)];
+ [message addExtension:[UnittestRoot packedDoubleExtension]
+ value:@(612 + i * 100)];
+ [message addExtension:[UnittestRoot packedBoolExtension]
+ value:@((i % 2) ? YES : NO)];
+ [message addExtension:[UnittestRoot packedEnumExtension]
+ value:@((i % 2) ? ForeignEnum_ForeignBar
+ : ForeignEnum_ForeignBaz)];
+ }
+}
+
+- (void)setUnpackedExtensions:(TestUnpackedExtensions *)message
+ repeatedCount:(uint32_t)count {
+ // Must match -setPackedFields:repeatedCount:
+ // Must match -setUnpackedFields:repeatedCount:
+ // Must match -setPackedExtensions:repeatedCount:
+ for (uint32_t i = 0; i < count; i++) {
+ [message addExtension:[UnittestRoot unpackedInt32Extension]
+ value:@(601 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedInt64Extension]
+ value:@(602 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedUint32Extension]
+ value:@(603 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedUint64Extension]
+ value:@(604 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedSint32Extension]
+ value:@(605 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedSint64Extension]
+ value:@(606 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedFixed32Extension]
+ value:@(607 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedFixed64Extension]
+ value:@(608 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedSfixed32Extension]
+ value:@(609 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedSfixed64Extension]
+ value:@(610 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedFloatExtension]
+ value:@(611 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedDoubleExtension]
+ value:@(612 + i * 100)];
+ [message addExtension:[UnittestRoot unpackedBoolExtension]
+ value:@((i % 2) ? YES : NO)];
+ [message addExtension:[UnittestRoot unpackedEnumExtension]
+ value:@((i % 2) ? ForeignEnum_ForeignBar
+ : ForeignEnum_ForeignBaz)];
+ }
+}
+
+- (void)assertPackedExtensionsSet:(TestPackedExtensions *)message
+ repeatedCount:(uint32_t)count{
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedInt32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedInt64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedUint32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedUint64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedSint32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedSint64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedFixed32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedFixed64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedSfixed32Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedSfixed64Extension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedFloatExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedDoubleExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedBoolExtension]] count]);
+ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedEnumExtension]] count]);
+
+ for (uint32_t i = 0; i < count; ++i) {
+ id extension = [message getExtension:[UnittestRoot packedInt32Extension]];
+ XCTAssertEqual((int)(601 + i * 100), [extension[i] intValue]);
+ extension = [message getExtension:[UnittestRoot packedInt64Extension]];
+ XCTAssertEqual(602 + i * 100, [extension[i] longLongValue]);
+ extension = [message getExtension:[UnittestRoot packedUint32Extension]];
+ XCTAssertEqual(603 + i * 100, [extension[i] unsignedIntValue]);
+ extension = [message getExtension:[UnittestRoot packedUint64Extension]];
+ XCTAssertEqual(604 + i * 100, [extension[i] unsignedLongLongValue]);
+ extension = [message getExtension:[UnittestRoot packedSint32Extension]];
+ XCTAssertEqual((int)(605 + i * 100), [extension[i] intValue]);
+ extension = [message getExtension:[UnittestRoot packedSint64Extension]];
+ XCTAssertEqual(606 + i * 100, [extension[i] longLongValue]);
+ extension = [message getExtension:[UnittestRoot packedFixed32Extension]];
+ XCTAssertEqual(607 + i * 100, [extension[i] unsignedIntValue]);
+ extension = [message getExtension:[UnittestRoot packedFixed64Extension]];
+ XCTAssertEqual(608 + i * 100, [extension[i] unsignedLongLongValue]);
+ extension = [message getExtension:[UnittestRoot packedSfixed32Extension]];
+ XCTAssertEqual((int)(609 + i * 100), [extension[i] intValue]);
+ extension = [message getExtension:[UnittestRoot packedSfixed64Extension]];
+ XCTAssertEqual(610 + i * 100, [extension[i] longLongValue]);
+ extension = [message getExtension:[UnittestRoot packedFloatExtension]];
+ XCTAssertEqualWithAccuracy(611 + i * 100, [extension[i] floatValue], 0.01);
+ extension = [message getExtension:[UnittestRoot packedDoubleExtension]];
+ XCTAssertEqualWithAccuracy(612 + i * 100, [extension[i] doubleValue], 0.01);
+ extension = [message getExtension:[UnittestRoot packedBoolExtension]];
+ XCTAssertEqual((i % 2) ? YES : NO, [extension[i] boolValue]);
+ extension = [message getExtension:[UnittestRoot packedEnumExtension]];
+ XCTAssertEqual((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz,
+ [extension[i] intValue]);
+ }
+}
+
+- (void)assertAllFieldsKVCMatch:(TestAllTypes *)message {
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalInt32"], @YES);
+ XCTAssertEqualObjects(@(message.optionalInt32), [message valueForKey:@"optionalInt32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalInt64"], @YES);
+ XCTAssertEqualObjects(@(message.optionalInt64), [message valueForKey:@"optionalInt64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalUint32"], @YES);
+ XCTAssertEqualObjects(@(message.optionalUint32), [message valueForKey:@"optionalUint32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalUint64"], @YES);
+ XCTAssertEqualObjects(@(message.optionalUint64), [message valueForKey:@"optionalUint64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalSint32"], @YES);
+ XCTAssertEqualObjects(@(message.optionalSint32), [message valueForKey:@"optionalSint32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalSint64"], @YES);
+ XCTAssertEqualObjects(@(message.optionalSint64), [message valueForKey:@"optionalSint64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalFixed32"], @YES);
+ XCTAssertEqualObjects(@(message.optionalFixed32), [message valueForKey:@"optionalFixed32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalFixed64"], @YES);
+ XCTAssertEqualObjects(@(message.optionalFixed64), [message valueForKey:@"optionalFixed64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalSfixed32"], @YES);
+ XCTAssertEqualObjects(@(message.optionalSfixed32), [message valueForKey:@"optionalSfixed32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalSfixed64"], @YES);
+ XCTAssertEqualObjects(@(message.optionalSfixed64), [message valueForKey:@"optionalSfixed64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalFloat"], @YES);
+ XCTAssertEqualObjects(@(message.optionalFloat), [message valueForKey:@"optionalFloat"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalDouble"], @YES);
+ XCTAssertEqualObjects(@(message.optionalDouble), [message valueForKey:@"optionalDouble"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalBool"], @YES);
+ XCTAssertEqualObjects(@(message.optionalBool), [message valueForKey:@"optionalBool"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalString"], @YES);
+ XCTAssertEqualObjects(message.optionalString, [message valueForKey:@"optionalString"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalBytes"], @YES);
+ XCTAssertEqualObjects(message.optionalBytes, [message valueForKey:@"optionalBytes"]);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalGroup"], @YES);
+ XCTAssertNotNil(message.optionalGroup);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalGroup.hasA"], @YES);
+ XCTAssertEqualObjects(@(message.optionalGroup.a), [message valueForKeyPath:@"optionalGroup.a"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalNestedMessage"], @YES);
+ XCTAssertNotNil(message.optionalNestedMessage);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalNestedMessage.hasBb"], @YES);
+ XCTAssertEqualObjects(@(message.optionalNestedMessage.bb), [message valueForKeyPath:@"optionalNestedMessage.bb"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalForeignMessage"], @YES);
+ XCTAssertNotNil(message.optionalForeignMessage);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalForeignMessage.hasC"], @YES);
+ XCTAssertEqualObjects(@(message.optionalForeignMessage.c), [message valueForKeyPath:@"optionalForeignMessage.c"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalImportMessage"], @YES);
+ XCTAssertNotNil(message.optionalForeignMessage);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalImportMessage.hasD"], @YES);
+ XCTAssertEqualObjects(@(message.optionalImportMessage.d), [message valueForKeyPath:@"optionalImportMessage.d"]);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalNestedEnum"], @YES);
+ XCTAssertEqualObjects(@(message.optionalNestedEnum), [message valueForKey:@"optionalNestedEnum"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalForeignEnum"], @YES);
+ XCTAssertEqualObjects(@(message.optionalForeignEnum), [message valueForKey:@"optionalForeignEnum"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalImportEnum"], @YES);
+ XCTAssertEqualObjects(@(message.optionalImportEnum), [message valueForKey:@"optionalImportEnum"]);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalStringPiece"], @YES);
+ XCTAssertEqualObjects(message.optionalStringPiece, [message valueForKey:@"optionalStringPiece"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalCord"], @YES);
+ XCTAssertEqualObjects(message.optionalCord, [message valueForKey:@"optionalCord"]);
+
+ // -----------------------------------------------------------------
+
+ // GPBArray interface for repeated
+
+ XCTAssertEqualObjects(message.repeatedInt32Array, [message valueForKey:@"repeatedInt32Array"]);
+ XCTAssertEqualObjects(message.repeatedInt64Array, [message valueForKey:@"repeatedInt64Array"]);
+ XCTAssertEqualObjects(message.repeatedUint32Array, [message valueForKey:@"repeatedUint32Array"]);
+ XCTAssertEqualObjects(message.repeatedUint64Array, [message valueForKey:@"repeatedUint64Array"]);
+ XCTAssertEqualObjects(message.repeatedSint32Array, [message valueForKey:@"repeatedSint32Array"]);
+ XCTAssertEqualObjects(message.repeatedSint64Array, [message valueForKey:@"repeatedSint64Array"]);
+ XCTAssertEqualObjects(message.repeatedFixed32Array, [message valueForKey:@"repeatedFixed32Array"]);
+ XCTAssertEqualObjects(message.repeatedFixed64Array, [message valueForKey:@"repeatedFixed64Array"]);
+ XCTAssertEqualObjects(message.repeatedSfixed32Array, [message valueForKey:@"repeatedSfixed32Array"]);
+ XCTAssertEqualObjects(message.repeatedSfixed64Array, [message valueForKey:@"repeatedSfixed64Array"]);
+ XCTAssertEqualObjects(message.repeatedFloatArray, [message valueForKey:@"repeatedFloatArray"]);
+ XCTAssertEqualObjects(message.repeatedDoubleArray, [message valueForKey:@"repeatedDoubleArray"]);
+ XCTAssertEqualObjects(message.repeatedBoolArray, [message valueForKey:@"repeatedBoolArray"]);
+ XCTAssertEqualObjects(message.repeatedStringArray, [message valueForKey:@"repeatedStringArray"]);
+ XCTAssertEqualObjects(message.repeatedBytesArray, [message valueForKey:@"repeatedBytesArray"]);
+
+ XCTAssertEqualObjects(message.repeatedGroupArray, [message valueForKey:@"repeatedGroupArray"]);
+ XCTAssertEqualObjects(message.repeatedNestedMessageArray, [message valueForKey:@"repeatedNestedMessageArray"]);
+ XCTAssertEqualObjects(message.repeatedForeignMessageArray, [message valueForKey:@"repeatedForeignMessageArray"]);
+ XCTAssertEqualObjects(message.repeatedImportMessageArray, [message valueForKey:@"repeatedImportMessageArray"]);
+
+ XCTAssertEqualObjects(message.repeatedNestedEnumArray, [message valueForKey:@"repeatedNestedEnumArray"]);
+ XCTAssertEqualObjects(message.repeatedForeignEnumArray, [message valueForKey:@"repeatedForeignEnumArray"]);
+ XCTAssertEqualObjects(message.repeatedImportEnumArray, [message valueForKey:@"repeatedImportEnumArray"]);
+
+ XCTAssertEqualObjects(message.repeatedStringPieceArray, [message valueForKey:@"repeatedStringPieceArray"]);
+ XCTAssertEqualObjects(message.repeatedCordArray, [message valueForKey:@"repeatedCordArray"]);
+
+ XCTAssertEqualObjects(@(message.repeatedInt32Array_Count), [message valueForKey:@"repeatedInt32Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedInt64Array_Count), [message valueForKey:@"repeatedInt64Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedUint32Array_Count), [message valueForKey:@"repeatedUint32Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedUint64Array_Count), [message valueForKey:@"repeatedUint64Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedSint32Array_Count), [message valueForKey:@"repeatedSint32Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedSint64Array_Count), [message valueForKey:@"repeatedSint64Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedFixed32Array_Count), [message valueForKey:@"repeatedFixed32Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedFixed64Array_Count), [message valueForKey:@"repeatedFixed64Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedSfixed32Array_Count), [message valueForKey:@"repeatedSfixed32Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedSfixed64Array_Count), [message valueForKey:@"repeatedSfixed64Array_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedFloatArray_Count), [message valueForKey:@"repeatedFloatArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedDoubleArray_Count), [message valueForKey:@"repeatedDoubleArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedBoolArray_Count), [message valueForKey:@"repeatedBoolArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedStringArray_Count), [message valueForKey:@"repeatedStringArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedBytesArray_Count), [message valueForKey:@"repeatedBytesArray_Count"]);
+
+ XCTAssertEqualObjects(@(message.repeatedGroupArray_Count), [message valueForKey:@"repeatedGroupArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedNestedMessageArray_Count), [message valueForKey:@"repeatedNestedMessageArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedForeignMessageArray_Count), [message valueForKey:@"repeatedForeignMessageArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedImportMessageArray_Count), [message valueForKey:@"repeatedImportMessageArray_Count"]);
+
+ XCTAssertEqualObjects(@(message.repeatedNestedEnumArray_Count), [message valueForKey:@"repeatedNestedEnumArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedForeignEnumArray_Count), [message valueForKey:@"repeatedForeignEnumArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedImportEnumArray_Count), [message valueForKey:@"repeatedImportEnumArray_Count"]);
+
+ XCTAssertEqualObjects(@(message.repeatedStringPieceArray_Count), [message valueForKey:@"repeatedStringPieceArray_Count"]);
+ XCTAssertEqualObjects(@(message.repeatedCordArray_Count), [message valueForKey:@"repeatedCordArray_Count"]);
+
+ // -----------------------------------------------------------------
+
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultInt32"], @YES);
+ XCTAssertEqualObjects(@(message.defaultInt32), [message valueForKey:@"defaultInt32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultInt64"], @YES);
+ XCTAssertEqualObjects(@(message.defaultInt64), [message valueForKey:@"defaultInt64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultUint32"], @YES);
+ XCTAssertEqualObjects(@(message.defaultUint32), [message valueForKey:@"defaultUint32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultUint64"], @YES);
+ XCTAssertEqualObjects(@(message.defaultUint64), [message valueForKey:@"defaultUint64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultSint32"], @YES);
+ XCTAssertEqualObjects(@(message.defaultSint32), [message valueForKey:@"defaultSint32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultSint64"], @YES);
+ XCTAssertEqualObjects(@(message.defaultSint64), [message valueForKey:@"defaultSint64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultFixed32"], @YES);
+ XCTAssertEqualObjects(@(message.defaultFixed32), [message valueForKey:@"defaultFixed32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultFixed64"], @YES);
+ XCTAssertEqualObjects(@(message.defaultFixed64), [message valueForKey:@"defaultFixed64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultSfixed32"], @YES);
+ XCTAssertEqualObjects(@(message.defaultSfixed32), [message valueForKey:@"defaultSfixed32"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultSfixed64"], @YES);
+ XCTAssertEqualObjects(@(message.defaultSfixed64), [message valueForKey:@"defaultSfixed64"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultFloat"], @YES);
+ XCTAssertEqualObjects(@(message.defaultFloat), [message valueForKey:@"defaultFloat"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultDouble"], @YES);
+ XCTAssertEqualObjects(@(message.defaultDouble), [message valueForKey:@"defaultDouble"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultBool"], @YES);
+ XCTAssertEqualObjects(@(message.defaultBool), [message valueForKey:@"defaultBool"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultString"], @YES);
+ XCTAssertEqualObjects(message.defaultString, [message valueForKey:@"defaultString"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultBytes"], @YES);
+ XCTAssertEqualObjects(message.defaultBytes, [message valueForKey:@"defaultBytes"]);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultNestedEnum"], @YES);
+ XCTAssertEqualObjects(@(message.defaultNestedEnum), [message valueForKey:@"defaultNestedEnum"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultForeignEnum"], @YES);
+ XCTAssertEqualObjects(@(message.defaultForeignEnum), [message valueForKey:@"defaultForeignEnum"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultImportEnum"], @YES);
+ XCTAssertEqualObjects(@(message.defaultImportEnum), [message valueForKey:@"defaultImportEnum"]);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultStringPiece"], @YES);
+ XCTAssertEqualObjects(message.defaultStringPiece, [message valueForKey:@"defaultStringPiece"]);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultCord"], @YES);
+ XCTAssertEqualObjects(message.defaultCord, [message valueForKey:@"defaultCord"]);
+}
+
+- (void)setAllFieldsViaKVC:(TestAllTypes *)message
+ repeatedCount:(uint32_t)count {
+ [message setValue:@101 forKey:@"optionalInt32"];
+ [message setValue:@102 forKey:@"optionalInt64"];
+ [message setValue:@103 forKey:@"optionalUint32"];
+ [message setValue:@104 forKey:@"optionalUint64"];
+ [message setValue:@105 forKey:@"optionalSint32"];
+ [message setValue:@106 forKey:@"optionalSint64"];
+ [message setValue:@107 forKey:@"optionalFixed32"];
+ [message setValue:@108 forKey:@"optionalFixed64"];
+ [message setValue:@109 forKey:@"optionalSfixed32"];
+ [message setValue:@110 forKey:@"optionalSfixed64"];
+ [message setValue:@111 forKey:@"optionalFloat"];
+ [message setValue:@112 forKey:@"optionalDouble"];
+ [message setValue:@YES forKey:@"optionalBool"];
+ [message setValue:@"115" forKey:@"optionalString"];
+ [message setValue:[NSData gpbtu_dataWithEmbeddedNulls]
+ forKey:@"optionalBytes"];
+
+ TestAllTypes_OptionalGroup *allTypes = [TestAllTypes_OptionalGroup message];
+ [allTypes setValue:@117 forKey:@"a"];
+ [message setValue:allTypes forKey:@"optionalGroup"];
+ TestAllTypes_NestedMessage *nestedMessage =
+ [TestAllTypes_NestedMessage message];
+ [nestedMessage setValue:@118 forKey:@"bb"];
+ [message setValue:nestedMessage forKey:@"optionalNestedMessage"];
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ [foreignMessage setValue:@119 forKey:@"c"];
+ [message setValue:foreignMessage forKey:@"optionalForeignMessage"];
+ ImportMessage *importMessage = [ImportMessage message];
+ [importMessage setValue:@120 forKey:@"d"];
+ [message setValue:importMessage forKey:@"optionalImportMessage"];
+
+ [message setValue:@(TestAllTypes_NestedEnum_Baz)
+ forKey:@"optionalNestedEnum"];
+ [message setValue:@(ForeignEnum_ForeignBaz) forKey:@"optionalForeignEnum"];
+ [message setValue:@(ImportEnum_ImportBaz) forKey:@"optionalImportEnum"];
+
+ [message setValue:@"124" forKey:@"optionalStringPiece"];
+ [message setValue:@"125" forKey:@"optionalCord"];
+
+ // -----------------------------------------------------------------
+
+ {
+ GPBInt32Array *scratch = [GPBInt32Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:201 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedInt32Array"];
+ }
+ {
+ GPBInt64Array *scratch = [GPBInt64Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:202 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedInt64Array"];
+ }
+ {
+ GPBUInt32Array *scratch = [GPBUInt32Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:203 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedUint32Array"];
+ }
+ {
+ GPBUInt64Array *scratch = [GPBUInt64Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:204 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedUint64Array"];
+ }
+ {
+ GPBInt32Array *scratch = [GPBInt32Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:205 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedSint32Array"];
+ }
+ {
+ GPBInt64Array *scratch = [GPBInt64Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:206 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedSint64Array"];
+ }
+ {
+ GPBUInt32Array *scratch = [GPBUInt32Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:207 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedFixed32Array"];
+ }
+ {
+ GPBUInt64Array *scratch = [GPBUInt64Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:208 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedFixed64Array"];
+ }
+ {
+ GPBInt32Array *scratch = [GPBInt32Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:209 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedSfixed32Array"];
+ }
+ {
+ GPBInt64Array *scratch = [GPBInt64Array array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:210 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedSfixed64Array"];
+ }
+ {
+ GPBFloatArray *scratch = [GPBFloatArray array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:211 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedFloatArray"];
+ }
+ {
+ GPBDoubleArray *scratch = [GPBDoubleArray array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:212 + i * 100];
+ }
+ [message setValue:scratch forKey:@"repeatedDoubleArray"];
+ }
+ {
+ GPBBoolArray *scratch = [GPBBoolArray array];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:(i % 2) ? YES : NO];
+ }
+ [message setValue:scratch forKey:@"repeatedBoolArray"];
+ }
+
+ NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0; i < count; ++i) {
+ NSString *string = [[NSString alloc] initWithFormat:@"%d", 215 + i * 100];
+ [array addObject:string];
+ [string release];
+ }
+ [message setValue:array forKey:@"repeatedStringArray"];
+ [array release];
+
+ array = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0; i < count; ++i) {
+ NSData *data = [[NSData alloc] initWithUint32_gpbtu:216 + i * 100];
+ [array addObject:data];
+ [data release];
+ }
+ [message setValue:array forKey:@"repeatedBytesArray"];
+ [array release];
+
+ array = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0; i < count; ++i) {
+ TestAllTypes_RepeatedGroup *testAll =
+ [[TestAllTypes_RepeatedGroup alloc] init];
+ [testAll setA:217 + i * 100];
+ [array addObject:testAll];
+ [testAll release];
+ }
+ [message setValue:array forKey:@"repeatedGroupArray"];
+ [array release];
+
+ array = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0; i < count; ++i) {
+ nestedMessage = [[TestAllTypes_NestedMessage alloc] init];
+ [nestedMessage setBb:218 + i * 100];
+ [array addObject:nestedMessage];
+ [nestedMessage release];
+ }
+ [message setValue:array forKey:@"repeatedNestedMessageArray"];
+ [array release];
+
+ array = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0; i < count; ++i) {
+ foreignMessage = [[ForeignMessage alloc] init];
+ [foreignMessage setC:219 + i * 100];
+ [array addObject:foreignMessage];
+ [foreignMessage release];
+ }
+ [message setValue:array forKey:@"repeatedForeignMessageArray"];
+ [array release];
+
+ array = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0; i < count; ++i) {
+ importMessage = [[ImportMessage alloc] init];
+ [importMessage setD:220 + i * 100];
+ [array addObject:importMessage];
+ [importMessage release];
+ }
+ [message setValue:array forKey:@"repeatedImportMessageArray"];
+ [array release];
+
+ {
+ GPBEnumArray *scratch = [GPBEnumArray
+ arrayWithValidationFunction:TestAllTypes_NestedEnum_IsValidValue];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:(i % 2) ? TestAllTypes_NestedEnum_Bar
+ : TestAllTypes_NestedEnum_Baz];
+ }
+ [message setValue:scratch forKey:@"repeatedNestedEnumArray"];
+ }
+ {
+ GPBEnumArray *scratch =
+ [GPBEnumArray arrayWithValidationFunction:ForeignEnum_IsValidValue];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch
+ addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz];
+ }
+ [message setValue:scratch forKey:@"repeatedForeignEnumArray"];
+ }
+ {
+ GPBEnumArray *scratch =
+ [GPBEnumArray arrayWithValidationFunction:ImportEnum_IsValidValue];
+ for (uint32_t i = 0; i < count; ++i) {
+ [scratch addValue:(i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz];
+ }
+ [message setValue:scratch forKey:@"repeatedImportEnumArray"];
+ }
+
+ array = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0; i < count; ++i) {
+ NSString *string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100];
+ [array addObject:string];
+ [string release];
+ }
+ [message setValue:array forKey:@"repeatedStringPieceArray"];
+ [array release];
+
+ array = [[NSMutableArray alloc] initWithCapacity:count];
+ for (uint32_t i = 0; i < count; ++i) {
+ NSString *string = [[NSString alloc] initWithFormat:@"%d", 225 + i * 100];
+ [array addObject:string];
+ [string release];
+ }
+ [message setValue:array forKey:@"repeatedCordArray"];
+ [array release];
+
+ // -----------------------------------------------------------------
+
+ [message setValue:@401 forKey:@"defaultInt32"];
+ [message setValue:@402 forKey:@"defaultInt64"];
+ [message setValue:@403 forKey:@"defaultUint32"];
+ [message setValue:@404 forKey:@"defaultUint64"];
+ [message setValue:@405 forKey:@"defaultSint32"];
+ [message setValue:@406 forKey:@"defaultSint64"];
+ [message setValue:@407 forKey:@"defaultFixed32"];
+ [message setValue:@408 forKey:@"defaultFixed64"];
+ [message setValue:@409 forKey:@"defaultSfixed32"];
+ [message setValue:@410 forKey:@"defaultSfixed64"];
+ [message setValue:@411 forKey:@"defaultFloat"];
+ [message setValue:@412 forKey:@"defaultDouble"];
+ [message setValue:@NO forKey:@"defaultBool"];
+ [message setValue:@"415" forKey:@"defaultString"];
+ [message setValue:[NSData gpbtu_dataWithUint32:416] forKey:@"defaultBytes"];
+
+ [message setValue:@(TestAllTypes_NestedEnum_Foo) forKey:@"defaultNestedEnum"];
+ [message setValue:@(ForeignEnum_ForeignFoo) forKey:@"defaultForeignEnum"];
+ [message setValue:@(ImportEnum_ImportFoo) forKey:@"defaultImportEnum"];
+
+ [message setValue:@"424" forKey:@"defaultStringPiece"];
+ [message setValue:@"425" forKey:@"defaultCord"];
+}
+
+- (void)assertClearKVC:(TestAllTypes *)message {
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalInt32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalInt64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalUint32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalUint64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalSint32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalSint64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalFixed32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalFixed64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalSfixed32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalSfixed64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalFloat"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalDouble"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalBool"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalString"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalBytes"], @NO);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalGroup"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalNestedMessage"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalForeignMessage"],
+ @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalImportMessage"], @NO);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalNestedEnum"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalForeignEnum"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalImportEnum"], @NO);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalStringPiece"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasOptionalCord"], @NO);
+
+ // Optional fields without defaults are set to zero or something like it.
+ XCTAssertEqualObjects([message valueForKey:@"optionalInt32"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalInt64"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalUint32"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalUint64"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalSint32"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalSint64"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalFixed32"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalFixed64"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalSfixed32"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalSfixed64"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalFloat"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalDouble"], @0);
+ XCTAssertEqualObjects([message valueForKey:@"optionalBool"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"optionalString"], @"");
+ XCTAssertEqualObjects([message valueForKey:@"optionalBytes"],
+ GPBEmptyNSData());
+
+ // Embedded messages should also be exist, but be clear.
+ XCTAssertNotNil([message valueForKeyPath:@"optionalGroup"]);
+ XCTAssertNotNil([message valueForKeyPath:@"optionalNestedMessage"]);
+ XCTAssertNotNil([message valueForKeyPath:@"optionalForeignMessage"]);
+ XCTAssertNotNil([message valueForKeyPath:@"optionalImportMessage"]);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalGroup.hasA"], @NO);
+ XCTAssertEqualObjects(
+ [message valueForKeyPath:@"optionalNestedMessage.hasBb"], @NO);
+ XCTAssertEqualObjects(
+ [message valueForKeyPath:@"optionalForeignMessage.hasC"], @NO);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalImportMessage.hasD"],
+ @NO);
+
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalGroup.a"], @0);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalNestedMessage.bb"],
+ @0);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalForeignMessage.c"],
+ @0);
+ XCTAssertEqualObjects([message valueForKeyPath:@"optionalImportMessage.d"],
+ @0);
+
+ // Enums without defaults are set to the first value in the enum.
+ XCTAssertEqualObjects([message valueForKey:@"optionalNestedEnum"],
+ @(TestAllTypes_NestedEnum_Foo));
+ XCTAssertEqualObjects([message valueForKey:@"optionalForeignEnum"],
+ @(ForeignEnum_ForeignFoo));
+ XCTAssertEqualObjects([message valueForKey:@"optionalImportEnum"],
+ @(ImportEnum_ImportFoo));
+
+ XCTAssertEqualObjects([message valueForKey:@"optionalStringPiece"], @"");
+ XCTAssertEqualObjects([message valueForKey:@"optionalCord"], @"");
+
+ // NSArray interface for repeated doesn't have has*, nil means no value.
+
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultInt32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultInt64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultUint32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultUint64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultSint32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultSint64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultFixed32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultFixed64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultSfixed32"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultSfixed64"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultFloat"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultDouble"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultBool"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultString"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultBytes"], @NO);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultNestedEnum"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultForeignEnum"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultImportEnum"], @NO);
+
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultStringPiece"], @NO);
+ XCTAssertEqualObjects([message valueForKey:@"hasDefaultCord"], @NO);
+
+ // Fields with defaults have their default values (duh).
+ XCTAssertEqualObjects([message valueForKey:@"defaultInt32"], @41);
+ XCTAssertEqualObjects([message valueForKey:@"defaultInt64"], @42);
+ XCTAssertEqualObjects([message valueForKey:@"defaultUint32"], @43);
+ XCTAssertEqualObjects([message valueForKey:@"defaultUint64"], @44);
+ XCTAssertEqualObjects([message valueForKey:@"defaultSint32"], @-45);
+ XCTAssertEqualObjects([message valueForKey:@"defaultSint64"], @46);
+ XCTAssertEqualObjects([message valueForKey:@"defaultFixed32"], @47);
+ XCTAssertEqualObjects([message valueForKey:@"defaultFixed64"], @48);
+ XCTAssertEqualObjects([message valueForKey:@"defaultSfixed32"], @49);
+ XCTAssertEqualObjects([message valueForKey:@"defaultSfixed64"], @-50);
+ XCTAssertEqualObjects([message valueForKey:@"defaultFloat"], @51.5);
+ XCTAssertEqualObjects([message valueForKey:@"defaultDouble"], @52e3);
+ XCTAssertEqualObjects([message valueForKey:@"defaultBool"], @YES);
+ XCTAssertEqualObjects([message valueForKey:@"defaultString"], @"hello");
+ XCTAssertEqualObjects([message valueForKey:@"defaultBytes"],
+ [NSData gpbtu_dataWithCString:"world"]);
+
+ XCTAssertEqualObjects([message valueForKey:@"defaultNestedEnum"],
+ @(TestAllTypes_NestedEnum_Bar));
+ XCTAssertEqualObjects([message valueForKey:@"defaultForeignEnum"],
+ @(ForeignEnum_ForeignBar));
+ XCTAssertEqualObjects([message valueForKey:@"defaultImportEnum"],
+ @(ImportEnum_ImportBar));
+
+ XCTAssertEqualObjects([message valueForKey:@"defaultStringPiece"], @"abc");
+ XCTAssertEqualObjects([message valueForKey:@"defaultCord"], @"123");
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBUnittestProtos.m b/third_party/protobuf/objectivec/Tests/GPBUnittestProtos.m
new file mode 100644
index 0000000000..756bd99ef7
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBUnittestProtos.m
@@ -0,0 +1,75 @@
+// 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.
+
+// Collects all the compiled protos into one file and compiles them to make sure
+// the compiler is generating valid code.
+
+// The unittest_custom_options.proto extends the messages in descriptor.proto
+// so we build it in to test extending in general. The library doesn't provide
+// a descriptor as it doesn't use the classes/enums.
+#import "google/protobuf/Descriptor.pbobjc.m"
+
+#import "google/protobuf/AnyTest.pbobjc.m"
+#import "google/protobuf/MapProto2Unittest.pbobjc.m"
+#import "google/protobuf/MapUnittest.pbobjc.m"
+#import "google/protobuf/Unittest.pbobjc.m"
+#import "google/protobuf/UnittestArena.pbobjc.m"
+#import "google/protobuf/UnittestCustomOptions.pbobjc.m"
+#import "google/protobuf/UnittestCycle.pbobjc.m"
+#import "google/protobuf/UnittestDeprecated.pbobjc.m"
+#import "google/protobuf/UnittestDeprecatedFile.pbobjc.m"
+#import "google/protobuf/UnittestDropUnknownFields.pbobjc.m"
+#import "google/protobuf/UnittestEmbedOptimizeFor.pbobjc.m"
+#import "google/protobuf/UnittestEmpty.pbobjc.m"
+#import "google/protobuf/UnittestEnormousDescriptor.pbobjc.m"
+#import "google/protobuf/UnittestImport.pbobjc.m"
+#import "google/protobuf/UnittestImportLite.pbobjc.m"
+#import "google/protobuf/UnittestImportPublic.pbobjc.m"
+#import "google/protobuf/UnittestImportPublicLite.pbobjc.m"
+#import "google/protobuf/UnittestLite.pbobjc.m"
+#import "google/protobuf/UnittestMset.pbobjc.m"
+#import "google/protobuf/UnittestMsetWireFormat.pbobjc.m"
+#import "google/protobuf/UnittestNoArena.pbobjc.m"
+#import "google/protobuf/UnittestNoArenaImport.pbobjc.m"
+#import "google/protobuf/UnittestNoGenericServices.pbobjc.m"
+#import "google/protobuf/UnittestObjc.pbobjc.m"
+#import "google/protobuf/UnittestObjcStartup.pbobjc.m"
+#import "google/protobuf/UnittestOptimizeFor.pbobjc.m"
+#import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.m"
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.m"
+#import "google/protobuf/UnittestRuntimeProto3.pbobjc.m"
+
+#import "google/protobuf/UnittestExtensionChainA.pbobjc.m"
+#import "google/protobuf/UnittestExtensionChainB.pbobjc.m"
+#import "google/protobuf/UnittestExtensionChainC.pbobjc.m"
+#import "google/protobuf/UnittestExtensionChainD.pbobjc.m"
+#import "google/protobuf/UnittestExtensionChainE.pbobjc.m"
+// See GPBUnittestProtos2.m for for "UnittestExtensionChainF.pbobjc.m"
+#import "google/protobuf/UnittestExtensionChainG.pbobjc.m"
diff --git a/third_party/protobuf/objectivec/Tests/GPBUnittestProtos2.m b/third_party/protobuf/objectivec/Tests/GPBUnittestProtos2.m
new file mode 100644
index 0000000000..ef9f070222
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBUnittestProtos2.m
@@ -0,0 +1,34 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 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.
+
+// This one file in the chain tests is compiled by itself to ensure if was
+// generated with the extra #imports needed to pull in the indirect Root class
+// used in its Root registry.
+#import "google/protobuf/UnittestExtensionChainF.pbobjc.m"
diff --git a/third_party/protobuf/objectivec/Tests/GPBUnknownFieldSetTest.m b/third_party/protobuf/objectivec/Tests/GPBUnknownFieldSetTest.m
new file mode 100644
index 0000000000..b2b5b21e61
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBUnknownFieldSetTest.m
@@ -0,0 +1,255 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBTestUtilities.h"
+
+#import "GPBUnknownField_PackagePrivate.h"
+#import "GPBUnknownFieldSet_PackagePrivate.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+
+@interface GPBUnknownFieldSet (GPBUnknownFieldSetTest)
+- (void)getTags:(int32_t*)tags;
+@end
+
+@interface UnknownFieldSetTest : GPBTestCase {
+ @private
+ TestAllTypes* allFields_;
+ NSData* allFieldsData_;
+
+ // An empty message that has been parsed from allFieldsData. So, it has
+ // unknown fields of every type.
+ TestEmptyMessage* emptyMessage_;
+ GPBUnknownFieldSet* unknownFields_;
+}
+
+@end
+
+@implementation UnknownFieldSetTest
+
+- (void)setUp {
+ allFields_ = [self allSetRepeatedCount:kGPBDefaultRepeatCount];
+ allFieldsData_ = [allFields_ data];
+ emptyMessage_ = [TestEmptyMessage parseFromData:allFieldsData_ error:NULL];
+ unknownFields_ = emptyMessage_.unknownFields;
+}
+
+// Constructs a protocol buffer which contains fields with all the same
+// numbers as allFieldsData except that each field is some other wire
+// type.
+- (NSData*)getBizarroData {
+ GPBUnknownFieldSet* bizarroFields =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+ NSUInteger count = [unknownFields_ countOfFields];
+ int32_t tags[count];
+ [unknownFields_ getTags:tags];
+ for (NSUInteger i = 0; i < count; ++i) {
+ int32_t tag = tags[i];
+ GPBUnknownField* field = [unknownFields_ getField:tag];
+ if (field.varintList.count == 0) {
+ // Original field is not a varint, so use a varint.
+ GPBUnknownField* varintField =
+ [[[GPBUnknownField alloc] initWithNumber:tag] autorelease];
+ [varintField addVarint:1];
+ [bizarroFields addField:varintField];
+ } else {
+ // Original field *is* a varint, so use something else.
+ GPBUnknownField* fixed32Field =
+ [[[GPBUnknownField alloc] initWithNumber:tag] autorelease];
+ [fixed32Field addFixed32:1];
+ [bizarroFields addField:fixed32Field];
+ }
+ }
+
+ return [bizarroFields data];
+}
+
+- (void)testSerialize {
+ // Check that serializing the UnknownFieldSet produces the original data
+ // again.
+ NSData* data = [emptyMessage_ data];
+ XCTAssertEqualObjects(allFieldsData_, data);
+}
+
+- (void)testCopyFrom {
+ TestEmptyMessage* message = [TestEmptyMessage message];
+ [message mergeFrom:emptyMessage_];
+
+ XCTAssertEqualObjects(emptyMessage_.data, message.data);
+}
+
+- (void)testMergeFrom {
+ GPBUnknownFieldSet* set1 = [[[GPBUnknownFieldSet alloc] init] autorelease];
+ GPBUnknownField* field = [[[GPBUnknownField alloc] initWithNumber:2] autorelease];
+ [field addVarint:2];
+ [set1 addField:field];
+ field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease];
+ [field addVarint:4];
+ [set1 addField:field];
+
+ GPBUnknownFieldSet* set2 = [[[GPBUnknownFieldSet alloc] init] autorelease];
+ field = [[[GPBUnknownField alloc] initWithNumber:1] autorelease];
+ [field addVarint:1];
+ [set2 addField:field];
+ field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease];
+ [field addVarint:3];
+ [set2 addField:field];
+
+ GPBUnknownFieldSet* set3 = [[[GPBUnknownFieldSet alloc] init] autorelease];
+ field = [[[GPBUnknownField alloc] initWithNumber:1] autorelease];
+ [field addVarint:1];
+ [set3 addField:field];
+ field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease];
+ [field addVarint:4];
+ [set3 addField:field];
+
+ GPBUnknownFieldSet* set4 = [[[GPBUnknownFieldSet alloc] init] autorelease];
+ field = [[[GPBUnknownField alloc] initWithNumber:2] autorelease];
+ [field addVarint:2];
+ [set4 addField:field];
+ field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease];
+ [field addVarint:3];
+ [set4 addField:field];
+
+ TestEmptyMessage* source1 = [TestEmptyMessage message];
+ [source1 setUnknownFields:set1];
+ TestEmptyMessage* source2 = [TestEmptyMessage message];
+ [source2 setUnknownFields:set2];
+ TestEmptyMessage* source3 = [TestEmptyMessage message];
+ [source3 setUnknownFields:set3];
+ TestEmptyMessage* source4 = [TestEmptyMessage message];
+ [source4 setUnknownFields:set4];
+
+ TestEmptyMessage* destination1 = [TestEmptyMessage message];
+ [destination1 mergeFrom:source1];
+ [destination1 mergeFrom:source2];
+
+ TestEmptyMessage* destination2 = [TestEmptyMessage message];
+ [destination2 mergeFrom:source3];
+ [destination2 mergeFrom:source4];
+
+ XCTAssertEqualObjects(destination1.data, destination2.data);
+}
+
+- (void)testClearMessage {
+ TestEmptyMessage *message = [TestEmptyMessage message];
+ [message mergeFrom:emptyMessage_];
+ [message clear];
+ XCTAssertEqual(message.serializedSize, (size_t)0);
+}
+
+- (void)testParseKnownAndUnknown {
+ // Test mixing known and unknown fields when parsing.
+ GPBUnknownFieldSet *fields = [[unknownFields_ copy] autorelease];
+ GPBUnknownField *field =
+ [[[GPBUnknownField alloc] initWithNumber:123456] autorelease];
+ [field addVarint:654321];
+ [fields addField:field];
+
+ NSData* data = fields.data;
+ TestAllTypes* destination = [TestAllTypes parseFromData:data error:NULL];
+
+ [self assertAllFieldsSet:destination repeatedCount:kGPBDefaultRepeatCount];
+ XCTAssertEqual(destination.unknownFields.countOfFields, (NSUInteger)1);
+
+ GPBUnknownField* field2 = [destination.unknownFields getField:123456];
+ XCTAssertEqual(field2.varintList.count, (NSUInteger)1);
+ XCTAssertEqual(654321ULL, [field2.varintList valueAtIndex:0]);
+}
+
+- (void)testWrongTypeTreatedAsUnknown {
+ // Test that fields of the wrong wire type are treated like unknown fields
+ // when parsing.
+
+ NSData* bizarroData = [self getBizarroData];
+ TestAllTypes* allTypesMessage =
+ [TestAllTypes parseFromData:bizarroData error:NULL];
+ TestEmptyMessage* emptyMessage =
+ [TestEmptyMessage parseFromData:bizarroData error:NULL];
+
+ // All fields should have been interpreted as unknown, so the debug strings
+ // should be the same.
+ XCTAssertEqualObjects(emptyMessage.data, allTypesMessage.data);
+}
+
+- (void)testUnknownExtensions {
+ // Make sure fields are properly parsed to the UnknownFieldSet even when
+ // they are declared as extension numbers.
+
+ TestEmptyMessageWithExtensions* message =
+ [TestEmptyMessageWithExtensions parseFromData:allFieldsData_ error:NULL];
+
+ XCTAssertEqual(unknownFields_.countOfFields,
+ message.unknownFields.countOfFields);
+ XCTAssertEqualObjects(allFieldsData_, message.data);
+}
+
+- (void)testWrongExtensionTypeTreatedAsUnknown {
+ // Test that fields of the wrong wire type are treated like unknown fields
+ // when parsing extensions.
+
+ NSData* bizarroData = [self getBizarroData];
+ TestAllExtensions* allExtensionsMessage =
+ [TestAllExtensions parseFromData:bizarroData error:NULL];
+ TestEmptyMessage* emptyMessage =
+ [TestEmptyMessage parseFromData:bizarroData error:NULL];
+
+ // All fields should have been interpreted as unknown, so the debug strings
+ // should be the same.
+ XCTAssertEqualObjects(emptyMessage.data, allExtensionsMessage.data);
+}
+
+- (void)testLargeVarint {
+ GPBUnknownFieldSet* fields = [[unknownFields_ copy] autorelease];
+ GPBUnknownField* field = [[[GPBUnknownField alloc] initWithNumber:1] autorelease];
+ [field addVarint:0x7FFFFFFFFFFFFFFFL];
+ [fields addField:field];
+
+ NSData* data = [fields data];
+
+ GPBUnknownFieldSet* parsed = [[[GPBUnknownFieldSet alloc] init] autorelease];
+ [parsed mergeFromData:data];
+ GPBUnknownField* field2 = [parsed getField:1];
+ XCTAssertEqual(field2.varintList.count, (NSUInteger)1);
+ XCTAssertEqual(0x7FFFFFFFFFFFFFFFULL, [field2.varintList valueAtIndex:0]);
+}
+
+- (void)testMergingFields {
+ GPBUnknownField* field1 = [[[GPBUnknownField alloc] initWithNumber:1] autorelease];
+ [field1 addVarint:1];
+ [field1 addFixed32:2];
+ [field1 addFixed64:3];
+ [field1 addLengthDelimited:[NSData dataWithBytes:"hello" length:5]];
+ [field1 addGroup:[[unknownFields_ copy] autorelease]];
+ GPBUnknownField* field2 = [[[GPBUnknownField alloc] initWithNumber:2] autorelease];
+ [field2 mergeFromField:field1];
+ XCTAssertEqualObjects(field1, field2);
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBUtilitiesTests.m b/third_party/protobuf/objectivec/Tests/GPBUtilitiesTests.m
new file mode 100644
index 0000000000..2e206a54ea
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBUtilitiesTests.m
@@ -0,0 +1,400 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import <XCTest/XCTest.h>
+
+#import "GPBUtilities_PackagePrivate.h"
+
+#import <objc/runtime.h>
+
+#import "GPBTestUtilities.h"
+
+#import "GPBDescriptor.h"
+#import "GPBDescriptor_PackagePrivate.h"
+#import "GPBMessage.h"
+#import "GPBUnknownField_PackagePrivate.h"
+
+#import "google/protobuf/MapUnittest.pbobjc.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestObjc.pbobjc.h"
+
+@interface UtilitiesTests : GPBTestCase
+@end
+
+@implementation UtilitiesTests
+
+- (void)testRightShiftFunctions {
+ XCTAssertEqual((1UL << 31) >> 31, 1UL);
+ XCTAssertEqual((1 << 31) >> 31, -1);
+ XCTAssertEqual((1ULL << 63) >> 63, 1ULL);
+ XCTAssertEqual((1LL << 63) >> 63, -1LL);
+
+ XCTAssertEqual(GPBLogicalRightShift32((1 << 31), 31), 1);
+ XCTAssertEqual(GPBLogicalRightShift64((1LL << 63), 63), 1LL);
+}
+
+- (void)testGPBDecodeTextFormatName {
+ uint8_t decodeData[] = {
+ 0x6,
+ // An inlined string (first to make sure the leading null is handled
+ // correctly, and with a key of zero to check that).
+ 0x0, 0x0, 'z', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'I', 'J', 0x0,
+ // All as is (00 op)
+ 0x1, 0x0A, 0x0,
+ // Underscore, upper + 9 (10 op)
+ 0x3, 0xCA, 0x0,
+ // Upper + 3 (10 op), underscore, upper + 5 (10 op)
+ 0x2, 0x44, 0xC6, 0x0,
+ // All Upper for 4 (11 op), underscore, underscore, upper + 5 (10 op),
+ // underscore, lower + 0 (01 op)
+ 0x4, 0x64, 0x80, 0xC5, 0xA1, 0x0,
+ // 2 byte key: as is + 3 (00 op), underscore, lower + 4 (01 op),
+ // underscore, lower + 3 (01 op), underscore, lower + 1 (01 op),
+ // underscore, lower + 30 (01 op), as is + 30 (00 op), as is + 13 (00 op),
+ // underscore, as is + 3 (00 op)
+ 0xE8, 0x07, 0x04, 0xA5, 0xA4, 0xA2, 0xBF, 0x1F, 0x0E, 0x84, 0x0,
+ };
+ NSString *inputStr = @"abcdefghIJ";
+
+ // Empty inputs
+
+ XCTAssertNil(GPBDecodeTextFormatName(nil, 1, NULL));
+ XCTAssertNil(GPBDecodeTextFormatName(decodeData, 1, NULL));
+ XCTAssertNil(GPBDecodeTextFormatName(nil, 1, inputStr));
+
+ // Keys not found.
+
+ XCTAssertNil(GPBDecodeTextFormatName(decodeData, 5, inputStr));
+ XCTAssertNil(GPBDecodeTextFormatName(decodeData, -1, inputStr));
+
+ // Some name decodes.
+
+ XCTAssertEqualObjects(GPBDecodeTextFormatName(decodeData, 1, inputStr), @"abcdefghIJ");
+ XCTAssertEqualObjects(GPBDecodeTextFormatName(decodeData, 2, inputStr), @"Abcd_EfghIJ");
+ XCTAssertEqualObjects(GPBDecodeTextFormatName(decodeData, 3, inputStr), @"_AbcdefghIJ");
+ XCTAssertEqualObjects(GPBDecodeTextFormatName(decodeData, 4, inputStr), @"ABCD__EfghI_j");
+
+ // An inlined string (and key of zero).
+ XCTAssertEqualObjects(GPBDecodeTextFormatName(decodeData, 0, inputStr), @"zbcdefghIJ");
+
+ // Long name so multiple decode ops are needed.
+ inputStr = @"longFieldNameIsLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong1000";
+ XCTAssertEqualObjects(GPBDecodeTextFormatName(decodeData, 1000, inputStr),
+ @"long_field_name_is_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_1000");
+}
+
+- (void)testTextFormat {
+ TestAllTypes *message = [TestAllTypes message];
+
+ // Not kGPBDefaultRepeatCount because we are comparing to golden master file
+ // which was generated with 2.
+ [self setAllFields:message repeatedCount:2];
+
+ NSString *result = GPBTextFormatForMessage(message, nil);
+
+ NSString *fileName = @"text_format_unittest_data.txt";
+ NSData *resultData = [result dataUsingEncoding:NSUTF8StringEncoding];
+ NSData *expectedData =
+ [self getDataFileNamed:fileName dataToWrite:resultData];
+ NSString *expected = [[NSString alloc] initWithData:expectedData
+ encoding:NSUTF8StringEncoding];
+ XCTAssertEqualObjects(expected, result);
+ [expected release];
+}
+
+- (void)testTextFormatExtra {
+ // -testTextFormat uses all protos with fields that don't require special
+ // handing for figuring out the names. The ObjC proto has a bunch of oddball
+ // field and enum names that require the decode info to get right, so this
+ // confirms they generated and decoded correctly.
+
+ self_Class *message = [self_Class message];
+ message.cmd = YES;
+ message.isProxy_p = YES;
+ message.subEnum = self_autorelease_RetainCount;
+ message.new_p.copy_p = @"foo";
+
+ NSString *expected = @"_cmd: true\n"
+ @"isProxy: true\n"
+ @"SubEnum: retainCount\n"
+ @"New {\n"
+ @" copy: \"foo\"\n"
+ @"}\n";
+ NSString *result = GPBTextFormatForMessage(message, nil);
+ XCTAssertEqualObjects(expected, result);
+}
+
+- (void)testTextFormatMaps {
+ TestMap *message = [TestMap message];
+
+ // Map iteration order doesn't have to be stable, so use only one entry.
+ [self setAllMapFields:message numEntries:1];
+
+ NSString *result = GPBTextFormatForMessage(message, nil);
+
+ NSString *fileName = @"text_format_map_unittest_data.txt";
+ NSData *resultData = [result dataUsingEncoding:NSUTF8StringEncoding];
+ NSData *expectedData =
+ [self getDataFileNamed:fileName dataToWrite:resultData];
+ NSString *expected = [[NSString alloc] initWithData:expectedData
+ encoding:NSUTF8StringEncoding];
+ XCTAssertEqualObjects(expected, result);
+ [expected release];
+}
+
+// TODO(thomasvl): add test with extensions once those format with correct names.
+
+- (void)testSetRepeatedFields {
+ TestAllTypes *message = [TestAllTypes message];
+
+ NSDictionary *repeatedFieldValues = @{
+ @"repeatedStringArray" : [@[@"foo", @"bar"] mutableCopy],
+ @"repeatedBoolArray" : [GPBBoolArray arrayWithValue:YES],
+ @"repeatedInt32Array" : [GPBInt32Array arrayWithValue:14],
+ @"repeatedInt64Array" : [GPBInt64Array arrayWithValue:15],
+ @"repeatedUint32Array" : [GPBUInt32Array arrayWithValue:16],
+ @"repeatedUint64Array" : [GPBUInt64Array arrayWithValue:16],
+ @"repeatedFloatArray" : [GPBFloatArray arrayWithValue:16],
+ @"repeatedDoubleArray" : [GPBDoubleArray arrayWithValue:16],
+ @"repeatedNestedEnumArray" :
+ [GPBEnumArray arrayWithValidationFunction:TestAllTypes_NestedEnum_IsValidValue
+ rawValue:TestAllTypes_NestedEnum_Foo],
+ };
+ for (NSString *fieldName in repeatedFieldValues) {
+ GPBFieldDescriptor *field =
+ [message.descriptor fieldWithName:fieldName];
+ XCTAssertNotNil(field, @"No field with name: %@", fieldName);
+ id expectedValues = repeatedFieldValues[fieldName];
+ GPBSetMessageRepeatedField(message, field, expectedValues);
+ XCTAssertEqualObjects(expectedValues,
+ [message valueForKeyPath:fieldName]);
+ }
+}
+
+// Helper to make an unknown field set with something in it.
+static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) {
+ GPBUnknownFieldSet *result =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+
+ GPBUnknownField *field =
+ [[[GPBUnknownField alloc] initWithNumber:num] autorelease];
+ [field addVarint:num];
+ [result addField:field];
+
+ return result;
+}
+
+- (void)testDropMessageUnknownFieldsRecursively {
+ TestAllExtensions *message = [TestAllExtensions message];
+
+ // Give it unknownFields.
+ message.unknownFields = UnknownFieldsSetHelper(777);
+
+ // Given it extensions that include a message with unknown fields of its own.
+ {
+ // Int
+ [message setExtension:[UnittestRoot optionalInt32Extension] value:@5];
+
+ // Group
+ OptionalGroup_extension *optionalGroup = [OptionalGroup_extension message];
+ optionalGroup.a = 123;
+ optionalGroup.unknownFields = UnknownFieldsSetHelper(779);
+ [message setExtension:[UnittestRoot optionalGroupExtension]
+ value:optionalGroup];
+
+ // Message
+ TestAllTypes_NestedMessage *nestedMessage =
+ [TestAllTypes_NestedMessage message];
+ nestedMessage.bb = 456;
+ nestedMessage.unknownFields = UnknownFieldsSetHelper(778);
+ [message setExtension:[UnittestRoot optionalNestedMessageExtension]
+ value:nestedMessage];
+
+ // Repeated Group
+ RepeatedGroup_extension *repeatedGroup =
+ [[RepeatedGroup_extension alloc] init];
+ repeatedGroup.a = 567;
+ repeatedGroup.unknownFields = UnknownFieldsSetHelper(780);
+ [message addExtension:[UnittestRoot repeatedGroupExtension]
+ value:repeatedGroup];
+ [repeatedGroup release];
+
+ // Repeated Message
+ nestedMessage = [[TestAllTypes_NestedMessage alloc] init];
+ nestedMessage.bb = 678;
+ nestedMessage.unknownFields = UnknownFieldsSetHelper(781);
+ [message addExtension:[UnittestRoot repeatedNestedMessageExtension]
+ value:nestedMessage];
+ [nestedMessage release];
+ }
+
+ // Confirm everything is there.
+
+ XCTAssertNotNil(message);
+ XCTAssertNotNil(message.unknownFields);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalInt32Extension]]);
+
+ {
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ OptionalGroup_extension *optionalGroup =
+ [message getExtension:[UnittestRoot optionalGroupExtension]];
+ XCTAssertNotNil(optionalGroup);
+ XCTAssertEqual(optionalGroup.a, 123);
+ XCTAssertNotNil(optionalGroup.unknownFields);
+ }
+
+ {
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalNestedMessageExtension]]);
+ TestAllTypes_NestedMessage *nestedMessage =
+ [message getExtension:[UnittestRoot optionalNestedMessageExtension]];
+ XCTAssertNotNil(nestedMessage);
+ XCTAssertEqual(nestedMessage.bb, 456);
+ XCTAssertNotNil(nestedMessage.unknownFields);
+ }
+
+ {
+ XCTAssertTrue([message hasExtension:[UnittestRoot repeatedGroupExtension]]);
+ NSArray *repeatedGroups = [message getExtension:[UnittestRoot repeatedGroupExtension]];
+ XCTAssertEqual(repeatedGroups.count, (NSUInteger)1);
+ RepeatedGroup_extension *repeatedGroup = repeatedGroups.firstObject;
+ XCTAssertNotNil(repeatedGroup);
+ XCTAssertEqual(repeatedGroup.a, 567);
+ XCTAssertNotNil(repeatedGroup.unknownFields);
+ }
+
+ {
+ XCTAssertTrue([message hasExtension:[UnittestRoot repeatedNestedMessageExtension]]);
+ NSArray *repeatedNestedMessages = [message getExtension:[UnittestRoot repeatedNestedMessageExtension]];
+ XCTAssertEqual(repeatedNestedMessages.count, (NSUInteger)1);
+ TestAllTypes_NestedMessage *repeatedNestedMessage = repeatedNestedMessages.firstObject;
+ XCTAssertNotNil(repeatedNestedMessage);
+ XCTAssertEqual(repeatedNestedMessage.bb, 678);
+ XCTAssertNotNil(repeatedNestedMessage.unknownFields);
+ }
+
+ // Drop them.
+ GPBMessageDropUnknownFieldsRecursively(message);
+
+ // Confirm unknowns are gone from within the messages.
+
+ XCTAssertNotNil(message);
+ XCTAssertNil(message.unknownFields);
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalInt32Extension]]);
+
+ {
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalGroupExtension]]);
+ OptionalGroup_extension *optionalGroup =
+ [message getExtension:[UnittestRoot optionalGroupExtension]];
+ XCTAssertNotNil(optionalGroup);
+ XCTAssertEqual(optionalGroup.a, 123);
+ XCTAssertNil(optionalGroup.unknownFields);
+ }
+
+ {
+ XCTAssertTrue([message hasExtension:[UnittestRoot optionalNestedMessageExtension]]);
+ TestAllTypes_NestedMessage *nestedMessage =
+ [message getExtension:[UnittestRoot optionalNestedMessageExtension]];
+ XCTAssertNotNil(nestedMessage);
+ XCTAssertEqual(nestedMessage.bb, 456);
+ XCTAssertNil(nestedMessage.unknownFields);
+ }
+
+ {
+ XCTAssertTrue([message hasExtension:[UnittestRoot repeatedGroupExtension]]);
+ NSArray *repeatedGroups = [message getExtension:[UnittestRoot repeatedGroupExtension]];
+ XCTAssertEqual(repeatedGroups.count, (NSUInteger)1);
+ RepeatedGroup_extension *repeatedGroup = repeatedGroups.firstObject;
+ XCTAssertNotNil(repeatedGroup);
+ XCTAssertEqual(repeatedGroup.a, 567);
+ XCTAssertNil(repeatedGroup.unknownFields);
+ }
+
+ {
+ XCTAssertTrue([message hasExtension:[UnittestRoot repeatedNestedMessageExtension]]);
+ NSArray *repeatedNestedMessages = [message getExtension:[UnittestRoot repeatedNestedMessageExtension]];
+ XCTAssertEqual(repeatedNestedMessages.count, (NSUInteger)1);
+ TestAllTypes_NestedMessage *repeatedNestedMessage = repeatedNestedMessages.firstObject;
+ XCTAssertNotNil(repeatedNestedMessage);
+ XCTAssertEqual(repeatedNestedMessage.bb, 678);
+ XCTAssertNil(repeatedNestedMessage.unknownFields);
+ }
+
+}
+
+- (void)testDropMessageUnknownFieldsRecursively_Maps {
+ TestMap *message = [TestMap message];
+
+ {
+ ForeignMessage *foreignMessage = [ForeignMessage message];
+ foreignMessage.unknownFields = UnknownFieldsSetHelper(100);
+ [message.mapInt32ForeignMessage setObject:foreignMessage forKey:100];
+
+ foreignMessage = [ForeignMessage message];
+ foreignMessage.unknownFields = UnknownFieldsSetHelper(101);
+ [message.mapStringForeignMessage setObject:foreignMessage forKey:@"101"];
+ }
+
+ // Confirm everything is there.
+
+ XCTAssertNotNil(message);
+
+ {
+ ForeignMessage *foreignMessage = [message.mapInt32ForeignMessage objectForKey:100];
+ XCTAssertNotNil(foreignMessage);
+ XCTAssertNotNil(foreignMessage.unknownFields);
+ }
+
+ {
+ ForeignMessage *foreignMessage = [message.mapStringForeignMessage objectForKey:@"101"];
+ XCTAssertNotNil(foreignMessage);
+ XCTAssertNotNil(foreignMessage.unknownFields);
+ }
+
+ GPBMessageDropUnknownFieldsRecursively(message);
+
+ // Confirm unknowns are gone from within the messages.
+
+ XCTAssertNotNil(message);
+
+ {
+ ForeignMessage *foreignMessage = [message.mapInt32ForeignMessage objectForKey:100];
+ XCTAssertNotNil(foreignMessage);
+ XCTAssertNil(foreignMessage.unknownFields);
+ }
+
+ {
+ ForeignMessage *foreignMessage = [message.mapStringForeignMessage objectForKey:@"101"];
+ XCTAssertNotNil(foreignMessage);
+ XCTAssertNil(foreignMessage.unknownFields);
+ }
+
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBWellKnownTypesTest.m b/third_party/protobuf/objectivec/Tests/GPBWellKnownTypesTest.m
new file mode 100644
index 0000000000..592d5afd4b
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBWellKnownTypesTest.m
@@ -0,0 +1,214 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#import "GPBWellKnownTypes.h"
+
+#import <XCTest/XCTest.h>
+
+#import "GPBTestUtilities.h"
+#import "google/protobuf/AnyTest.pbobjc.h"
+
+// Nanosecond time accuracy
+static const NSTimeInterval kTimeAccuracy = 1e-9;
+
+@interface WellKnownTypesTest : XCTestCase
+@end
+
+@implementation WellKnownTypesTest
+
+- (void)testTimeStamp {
+ // Test negative and positive values.
+ NSTimeInterval values[] = {
+ -428027599.483999967, -1234567.0, -0.5, 0, 0.75, 54321.0, 2468086,483999967
+ };
+ for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) {
+ NSTimeInterval value = values[i];
+
+ // Test Creation - date.
+ NSDate *date = [NSDate dateWithTimeIntervalSince1970:value];
+ GPBTimestamp *timeStamp = [[GPBTimestamp alloc] initWithDate:date];
+
+ XCTAssertGreaterThanOrEqual(timeStamp.nanos, 0,
+ @"Offset %f - Date: %@", (double)value, date);
+ XCTAssertLessThan(timeStamp.nanos, 1e9,
+ @"Offset %f - Date: %@", (double)value, date);
+
+ // Comparing timeIntervals instead of directly comparing dates because date
+ // equality requires the time intervals to be exactly the same, and the
+ // timeintervals go through a bit of floating point error as they are
+ // converted back and forth from the internal representation.
+ XCTAssertEqualWithAccuracy(value, timeStamp.date.timeIntervalSince1970,
+ kTimeAccuracy,
+ @"Offset %f - Date: %@", (double)value, date);
+ [timeStamp release];
+
+ // Test Creation - timeIntervalSince1970.
+ timeStamp = [[GPBTimestamp alloc] initWithTimeIntervalSince1970:value];
+
+ XCTAssertGreaterThanOrEqual(timeStamp.nanos, 0,
+ @"Offset %f - Date: %@", (double)value, date);
+ XCTAssertLessThan(timeStamp.nanos, 1e9,
+ @"Offset %f - Date: %@", (double)value, date);
+
+ XCTAssertEqualWithAccuracy(value, timeStamp.timeIntervalSince1970,
+ kTimeAccuracy,
+ @"Offset %f - Date: %@", (double)value, date);
+ [timeStamp release];
+
+ // Test Mutation - date.
+ timeStamp = [[GPBTimestamp alloc] init];
+ timeStamp.date = date;
+
+ XCTAssertGreaterThanOrEqual(timeStamp.nanos, 0,
+ @"Offset %f - Date: %@", (double)value, date);
+ XCTAssertLessThan(timeStamp.nanos, 1e9,
+ @"Offset %f - Date: %@", (double)value, date);
+
+ XCTAssertEqualWithAccuracy(value, timeStamp.date.timeIntervalSince1970,
+ kTimeAccuracy,
+ @"Offset %f - Date: %@", (double)value, date);
+ [timeStamp release];
+
+ // Test Mutation - timeIntervalSince1970.
+ timeStamp = [[GPBTimestamp alloc] init];
+ timeStamp.timeIntervalSince1970 = value;
+
+ XCTAssertGreaterThanOrEqual(timeStamp.nanos, 0,
+ @"Offset %f - Date: %@", (double)value, date);
+ XCTAssertLessThan(timeStamp.nanos, 1e9,
+ @"Offset %f - Date: %@", (double)value, date);
+
+ XCTAssertEqualWithAccuracy(value, timeStamp.date.timeIntervalSince1970,
+ kTimeAccuracy,
+ @"Offset %f - Date: %@", (double)value, date);
+
+ [timeStamp release];
+ }
+}
+
+- (void)testDuration {
+ // Test negative and positive values.
+ NSTimeInterval values[] = { -1000.0001, -500.0, -0.5, 0, 0.75, 1000.0, 2000.0002 };
+ for (size_t i = 0; i < GPBARRAYSIZE(values); ++i) {
+ NSTimeInterval value = values[i];
+
+ // Test Creation.
+ GPBDuration *duration =
+ [[GPBDuration alloc] initWithTimeInterval:value];
+ XCTAssertEqualWithAccuracy(value, duration.timeInterval, kTimeAccuracy,
+ @"For interval %f", (double)value);
+ if (value > 0) {
+ XCTAssertGreaterThanOrEqual(duration.seconds, 0,
+ @"For interval %f", (double)value);
+ XCTAssertGreaterThanOrEqual(duration.nanos, 0,
+ @"For interval %f", (double)value);
+ } else {
+ XCTAssertLessThanOrEqual(duration.seconds, 0,
+ @"For interval %f", (double)value);
+ XCTAssertLessThanOrEqual(duration.nanos, 0,
+ @"For interval %f", (double)value);
+ }
+ [duration release];
+
+ // Test Mutation.
+ duration = [[GPBDuration alloc] init];
+ duration.timeInterval = value;
+ XCTAssertEqualWithAccuracy(value, duration.timeInterval, kTimeAccuracy,
+ @"For interval %f", (double)value);
+ if (value > 0) {
+ XCTAssertGreaterThanOrEqual(duration.seconds, 0,
+ @"For interval %f", (double)value);
+ XCTAssertGreaterThanOrEqual(duration.nanos, 0,
+ @"For interval %f", (double)value);
+ } else {
+ XCTAssertLessThanOrEqual(duration.seconds, 0,
+ @"For interval %f", (double)value);
+ XCTAssertLessThanOrEqual(duration.nanos, 0,
+ @"For interval %f", (double)value);
+ }
+ [duration release];
+ }
+}
+
+- (void)testAnyHelpers {
+
+ // Set and extract covers most of the code.
+
+ TestAny *subMessage = [TestAny message];
+ subMessage.int32Value = 12345;
+ TestAny *message = [TestAny message];
+ NSError *err = nil;
+ message.anyValue = [GPBAny anyWithMessage:subMessage error:&err];
+ XCTAssertNil(err);
+
+ NSData *data = message.data;
+ XCTAssertNotNil(data);
+
+ TestAny *message2 = [TestAny parseFromData:data error:&err];
+ XCTAssertNil(err);
+ XCTAssertNotNil(message2);
+ XCTAssertTrue(message2.hasAnyValue);
+
+ TestAny *subMessage2 =
+ (TestAny *)[message.anyValue unpackMessageClass:[TestAny class]
+ error:&err];
+ XCTAssertNil(err);
+ XCTAssertNotNil(subMessage2);
+ XCTAssertEqual(subMessage2.int32Value, 12345);
+
+ // NULL errorPtr in the two calls.
+
+ message.anyValue = [GPBAny anyWithMessage:subMessage error:NULL];
+ NSData *data2 = message.data;
+ XCTAssertEqualObjects(data2, data);
+
+ TestAny *subMessage3 =
+ (TestAny *)[message.anyValue unpackMessageClass:[TestAny class]
+ error:NULL];
+ XCTAssertNotNil(subMessage3);
+ XCTAssertEqualObjects(subMessage2, subMessage3);
+
+ // Try to extract wrong type.
+
+ GPBTimestamp *wrongMessage =
+ (GPBTimestamp *)[message.anyValue unpackMessageClass:[GPBTimestamp class]
+ error:&err];
+ XCTAssertNotNil(err);
+ XCTAssertNil(wrongMessage);
+ XCTAssertEqualObjects(err.domain, GPBWellKnownTypesErrorDomain);
+ XCTAssertEqual(err.code, GPBWellKnownTypesErrorCodeTypeURLMismatch);
+
+ wrongMessage =
+ (GPBTimestamp *)[message.anyValue unpackMessageClass:[GPBTimestamp class]
+ error:NULL];
+ XCTAssertNil(wrongMessage);
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/GPBWireFormatTests.m b/third_party/protobuf/objectivec/Tests/GPBWireFormatTests.m
new file mode 100644
index 0000000000..dbeab21564
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/GPBWireFormatTests.m
@@ -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.
+
+#import "GPBTestUtilities.h"
+
+#import "GPBCodedInputStream.h"
+#import "GPBMessage_PackagePrivate.h"
+#import "GPBUnknownField_PackagePrivate.h"
+#import "google/protobuf/Unittest.pbobjc.h"
+#import "google/protobuf/UnittestMset.pbobjc.h"
+#import "google/protobuf/UnittestMsetWireFormat.pbobjc.h"
+
+@interface WireFormatTests : GPBTestCase
+@end
+
+@implementation WireFormatTests
+
+- (void)testSerialization {
+ TestAllTypes* message = [self allSetRepeatedCount:kGPBDefaultRepeatCount];
+
+ NSData* rawBytes = message.data;
+ [self assertFieldsInOrder:rawBytes];
+ XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length);
+
+ TestAllTypes* message2 = [TestAllTypes parseFromData:rawBytes error:NULL];
+
+ [self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testSerializationPacked {
+ TestPackedTypes* message =
+ [self packedSetRepeatedCount:kGPBDefaultRepeatCount];
+
+ NSData* rawBytes = message.data;
+ [self assertFieldsInOrder:rawBytes];
+ XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length);
+
+ TestPackedTypes* message2 =
+ [TestPackedTypes parseFromData:rawBytes error:NULL];
+
+ [self assertPackedFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testSerializeExtensions {
+ // TestAllTypes and TestAllExtensions should have compatible wire formats,
+ // so if we serealize a TestAllExtensions then parse it as TestAllTypes
+ // it should work.
+
+ TestAllExtensions* message =
+ [self allExtensionsSetRepeatedCount:kGPBDefaultRepeatCount];
+ NSData* rawBytes = message.data;
+ [self assertFieldsInOrder:rawBytes];
+ XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length);
+
+ TestAllTypes* message2 = [TestAllTypes parseFromData:rawBytes error:NULL];
+
+ [self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount];
+}
+
+- (void)testSerializePackedExtensions {
+ // TestPackedTypes and TestPackedExtensions should have compatible wire
+ // formats; check that they serialize to the same string.
+ TestPackedExtensions* message =
+ [self packedExtensionsSetRepeatedCount:kGPBDefaultRepeatCount];
+ NSData* rawBytes = message.data;
+ [self assertFieldsInOrder:rawBytes];
+
+ TestPackedTypes* message2 =
+ [self packedSetRepeatedCount:kGPBDefaultRepeatCount];
+ NSData* rawBytes2 = message2.data;
+
+ XCTAssertEqualObjects(rawBytes, rawBytes2);
+}
+
+- (void)testParseExtensions {
+ // TestAllTypes and TestAllExtensions should have compatible wire formats,
+ // so if we serialize a TestAllTypes then parse it as TestAllExtensions
+ // it should work.
+
+ TestAllTypes* message = [self allSetRepeatedCount:kGPBDefaultRepeatCount];
+ NSData* rawBytes = message.data;
+ [self assertFieldsInOrder:rawBytes];
+
+ GPBExtensionRegistry* registry = [self extensionRegistry];
+
+ TestAllExtensions* message2 = [TestAllExtensions parseFromData:rawBytes
+ extensionRegistry:registry
+ error:NULL];
+
+ [self assertAllExtensionsSet:message2 repeatedCount:kGPBDefaultRepeatCount];
+}
+
+
+- (void)testExtensionsSerializedSize {
+ size_t allSet = [self allSetRepeatedCount:kGPBDefaultRepeatCount].serializedSize;
+ size_t extensionSet = [self allExtensionsSetRepeatedCount:kGPBDefaultRepeatCount].serializedSize;
+ XCTAssertEqual(allSet, extensionSet);
+}
+
+- (void)testParsePackedExtensions {
+ // Ensure that packed extensions can be properly parsed.
+ TestPackedExtensions* message =
+ [self packedExtensionsSetRepeatedCount:kGPBDefaultRepeatCount];
+ NSData* rawBytes = message.data;
+ [self assertFieldsInOrder:rawBytes];
+
+ GPBExtensionRegistry* registry = [self extensionRegistry];
+
+ TestPackedExtensions* message2 = [TestPackedExtensions parseFromData:rawBytes
+ extensionRegistry:registry
+ error:NULL];
+
+ [self assertPackedExtensionsSet:message2
+ repeatedCount:kGPBDefaultRepeatCount];
+}
+
+const int kUnknownTypeId = 1550055;
+
+- (void)testSerializeMessageSet {
+ // Set up a TestMessageSet with two known messages and an unknown one.
+ TestMessageSet* message_set = [TestMessageSet message];
+ [[message_set getExtension:[TestMessageSetExtension1 messageSetExtension]]
+ setI:123];
+ [[message_set getExtension:[TestMessageSetExtension2 messageSetExtension]]
+ setStr:@"foo"];
+ GPBUnknownField* unknownField =
+ [[[GPBUnknownField alloc] initWithNumber:kUnknownTypeId] autorelease];
+ [unknownField addLengthDelimited:[NSData dataWithBytes:"bar" length:3]];
+ GPBUnknownFieldSet* unknownFieldSet =
+ [[[GPBUnknownFieldSet alloc] init] autorelease];
+ [unknownFieldSet addField:unknownField];
+ [message_set setUnknownFields:unknownFieldSet];
+
+ NSData* data = [message_set data];
+
+ // Parse back using RawMessageSet and check the contents.
+ RawMessageSet* raw = [RawMessageSet parseFromData:data error:NULL];
+
+ XCTAssertEqual([raw.unknownFields countOfFields], (NSUInteger)0);
+
+ XCTAssertEqual(raw.itemArray.count, (NSUInteger)3);
+ XCTAssertEqual((uint32_t)[raw.itemArray[0] typeId],
+ [TestMessageSetExtension1 messageSetExtension].fieldNumber);
+ XCTAssertEqual((uint32_t)[raw.itemArray[1] typeId],
+ [TestMessageSetExtension2 messageSetExtension].fieldNumber);
+ XCTAssertEqual([raw.itemArray[2] typeId], kUnknownTypeId);
+
+ TestMessageSetExtension1* message1 =
+ [TestMessageSetExtension1 parseFromData:[((RawMessageSet_Item*)raw.itemArray[0]) message]
+ error:NULL];
+ XCTAssertEqual(message1.i, 123);
+
+ TestMessageSetExtension2* message2 =
+ [TestMessageSetExtension2 parseFromData:[((RawMessageSet_Item*)raw.itemArray[1]) message]
+ error:NULL];
+ XCTAssertEqualObjects(message2.str, @"foo");
+
+ XCTAssertEqualObjects([raw.itemArray[2] message],
+ [NSData dataWithBytes:"bar" length:3]);
+}
+
+- (void)testParseMessageSet {
+ // Set up a RawMessageSet with two known messages and an unknown one.
+ RawMessageSet* raw = [RawMessageSet message];
+
+ {
+ RawMessageSet_Item* item = [RawMessageSet_Item message];
+ item.typeId = [TestMessageSetExtension1 messageSetExtension].fieldNumber;
+ TestMessageSetExtension1* message = [TestMessageSetExtension1 message];
+ message.i = 123;
+ item.message = [message data];
+ [raw.itemArray addObject:item];
+ }
+
+ {
+ RawMessageSet_Item* item = [RawMessageSet_Item message];
+ item.typeId = [TestMessageSetExtension2 messageSetExtension].fieldNumber;
+ TestMessageSetExtension2* message = [TestMessageSetExtension2 message];
+ message.str = @"foo";
+ item.message = [message data];
+ [raw.itemArray addObject:item];
+ }
+
+ {
+ RawMessageSet_Item* item = [RawMessageSet_Item message];
+ item.typeId = kUnknownTypeId;
+ item.message = [NSData dataWithBytes:"bar" length:3];
+ [raw.itemArray addObject:item];
+ }
+
+ NSData* data = [raw data];
+
+ // Parse as a TestMessageSet and check the contents.
+ TestMessageSet* messageSet =
+ [TestMessageSet parseFromData:data
+ extensionRegistry:[UnittestMsetRoot extensionRegistry]
+ error:NULL];
+
+ XCTAssertEqual(
+ [[messageSet
+ getExtension:[TestMessageSetExtension1 messageSetExtension]] i],
+ 123);
+ XCTAssertEqualObjects(
+ [[messageSet
+ getExtension:[TestMessageSetExtension2 messageSetExtension]] str],
+ @"foo");
+
+ XCTAssertEqual([messageSet.unknownFields countOfFields], (NSUInteger)1);
+ GPBUnknownField* unknownField = [messageSet.unknownFields getField:kUnknownTypeId];
+ XCTAssertNotNil(unknownField);
+ XCTAssertEqual(unknownField.lengthDelimitedList.count, (NSUInteger)1);
+ XCTAssertEqualObjects(unknownField.lengthDelimitedList[0],
+ [NSData dataWithBytes:"bar" length:3]);
+}
+
+- (void)assertFieldsInOrder:(NSData*)data {
+ GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
+ int32_t previousTag = 0;
+
+ while (YES) {
+ int32_t tag = [input readTag];
+ if (tag == 0) {
+ break;
+ }
+
+ XCTAssertGreaterThan(tag, previousTag);
+ [input skipField:tag];
+ }
+}
+
+@end
diff --git a/third_party/protobuf/objectivec/Tests/UnitTests-Bridging-Header.h b/third_party/protobuf/objectivec/Tests/UnitTests-Bridging-Header.h
new file mode 100644
index 0000000000..46292fce73
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/UnitTests-Bridging-Header.h
@@ -0,0 +1,6 @@
+//
+// Use this file to import your target's public headers that you would like to expose to Swift.
+//
+
+#import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
+#import "google/protobuf/UnittestRuntimeProto3.pbobjc.h"
diff --git a/third_party/protobuf/objectivec/Tests/UnitTests-Info.plist b/third_party/protobuf/objectivec/Tests/UnitTests-Info.plist
new file mode 100644
index 0000000000..460a7d931c
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/UnitTests-Info.plist
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>BNDL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+</dict>
+</plist>
diff --git a/third_party/protobuf/objectivec/Tests/golden_message b/third_party/protobuf/objectivec/Tests/golden_message
new file mode 100644
index 0000000000..7bceab4138
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/golden_message
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/golden_packed_fields_message b/third_party/protobuf/objectivec/Tests/golden_packed_fields_message
new file mode 100644
index 0000000000..7bceab4138
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/golden_packed_fields_message
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/AppDelegate.m b/third_party/protobuf/objectivec/Tests/iOSTestHarness/AppDelegate.m
new file mode 100644
index 0000000000..8c4a586bbd
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/AppDelegate.m
@@ -0,0 +1,35 @@
+#import <UIKit/UIKit.h>
+
+@interface AppDelegate : UIResponder <UIApplicationDelegate>
+@property (strong, nonatomic) UIWindow *window;
+@end
+
+@implementation AppDelegate
+
+@synthesize window;
+
+- (BOOL)application:(UIApplication *)application
+ didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+ #pragma unused (application, launchOptions)
+
+ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ self.window.backgroundColor = [UIColor whiteColor];
+ [self.window makeKeyAndVisible];
+ self.window.rootViewController = [[UIViewController alloc] init];
+
+ UILabel *label =
+ [[UILabel alloc] initWithFrame:CGRectMake(0, 200, CGRectGetWidth(self.window.frame), 40)];
+ label.text = @"Protocol Buffer Test Harness";
+ label.textAlignment = NSTextAlignmentCenter;
+ [self.window addSubview:label];
+
+ return YES;
+}
+
+@end
+
+int main(int argc, char * argv[]) {
+ @autoreleasepool {
+ return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
+ }
+}
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/Contents.json b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/Contents.json
new file mode 100644
index 0000000000..0cbf9acc1c
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/Contents.json
@@ -0,0 +1,116 @@
+{
+ "images" : [
+ {
+ "idiom" : "iphone",
+ "size" : "29x29",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "29x29",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "29x29",
+ "scale" : "3x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "40x40",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "iphone",
+ "size" : "40x40",
+ "scale" : "3x"
+ },
+ {
+ "size" : "57x57",
+ "idiom" : "iphone",
+ "filename" : "iPhone6.png",
+ "scale" : "1x"
+ },
+ {
+ "size" : "57x57",
+ "idiom" : "iphone",
+ "filename" : "iPhone6_2x.png",
+ "scale" : "2x"
+ },
+ {
+ "size" : "60x60",
+ "idiom" : "iphone",
+ "filename" : "iPhone7_2x.png",
+ "scale" : "2x"
+ },
+ {
+ "size" : "60x60",
+ "idiom" : "iphone",
+ "filename" : "iPhone7_3x.png",
+ "scale" : "3x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "29x29",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "29x29",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "40x40",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "40x40",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "50x50",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "ipad",
+ "size" : "50x50",
+ "scale" : "2x"
+ },
+ {
+ "size" : "72x72",
+ "idiom" : "ipad",
+ "filename" : "iPad6.png",
+ "scale" : "1x"
+ },
+ {
+ "size" : "72x72",
+ "idiom" : "ipad",
+ "filename" : "iPad6_2x.png",
+ "scale" : "2x"
+ },
+ {
+ "size" : "76x76",
+ "idiom" : "ipad",
+ "filename" : "iPad7.png",
+ "scale" : "1x"
+ },
+ {
+ "size" : "76x76",
+ "idiom" : "ipad",
+ "filename" : "iPad7_2x.png",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "car",
+ "size" : "120x120",
+ "scale" : "1x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+}
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6.png b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6.png
new file mode 100644
index 0000000000..43da2ee434
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6.png
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6_2x.png b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6_2x.png
new file mode 100644
index 0000000000..2ec93704ca
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad6_2x.png
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7.png b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7.png
new file mode 100644
index 0000000000..aec8bc1b1b
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7.png
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7_2x.png b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7_2x.png
new file mode 100644
index 0000000000..e39cc3e754
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPad7_2x.png
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6.png b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6.png
new file mode 100644
index 0000000000..5572d79f6f
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6.png
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6_2x.png b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6_2x.png
new file mode 100644
index 0000000000..2424997f93
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone6_2x.png
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_2x.png b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_2x.png
new file mode 100644
index 0000000000..10bfc3cfae
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_2x.png
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_3x.png b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_3x.png
new file mode 100644
index 0000000000..8d16f14dcc
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/AppIcon.appiconset/iPhone7_3x.png
Binary files differ
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/LaunchImage.launchimage/Contents.json b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/LaunchImage.launchimage/Contents.json
new file mode 100644
index 0000000000..5a2966687a
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Images.xcassets/LaunchImage.launchimage/Contents.json
@@ -0,0 +1,49 @@
+{
+ "images" : [
+ {
+ "orientation" : "portrait",
+ "idiom" : "ipad",
+ "minimum-system-version" : "7.0",
+ "extent" : "full-screen",
+ "scale" : "2x"
+ },
+ {
+ "orientation" : "landscape",
+ "idiom" : "ipad",
+ "minimum-system-version" : "7.0",
+ "extent" : "full-screen",
+ "scale" : "1x"
+ },
+ {
+ "orientation" : "landscape",
+ "idiom" : "ipad",
+ "minimum-system-version" : "7.0",
+ "extent" : "full-screen",
+ "scale" : "2x"
+ },
+ {
+ "orientation" : "portrait",
+ "idiom" : "iphone",
+ "minimum-system-version" : "7.0",
+ "scale" : "2x"
+ },
+ {
+ "orientation" : "portrait",
+ "idiom" : "iphone",
+ "minimum-system-version" : "7.0",
+ "subtype" : "retina4",
+ "scale" : "2x"
+ },
+ {
+ "orientation" : "portrait",
+ "idiom" : "ipad",
+ "minimum-system-version" : "7.0",
+ "extent" : "full-screen",
+ "scale" : "1x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+} \ No newline at end of file
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/Info.plist b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Info.plist
new file mode 100644
index 0000000000..24bd333d0b
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/Info.plist
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleDisplayName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>UILaunchStoryboardName</key>
+ <string>LaunchScreen</string>
+ <key>UISupportedInterfaceOrientations</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
+ <key>UISupportedInterfaceOrientations~ipad</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ <string>UIInterfaceOrientationPortraitUpsideDown</string>
+ </array>
+</dict>
+</plist>
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/LaunchScreen.xib b/third_party/protobuf/objectivec/Tests/iOSTestHarness/LaunchScreen.xib
new file mode 100644
index 0000000000..22204bfe44
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/LaunchScreen.xib
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6254" systemVersion="13F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
+ <dependencies>
+ <deployment identifier="iOS"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
+ <capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
+ </dependencies>
+ <objects>
+ <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
+ <view contentMode="scaleToFill" id="iN0-l3-epB">
+ <rect key="frame" x="0.0" y="0.0" width="630" height="503"/>
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+ <subviews>
+ <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Protocol Buffer Test Harness" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
+ <rect key="frame" x="20" y="147" width="591" height="43"/>
+ <fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
+ <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+ <nil key="highlightedColor"/>
+ </label>
+ </subviews>
+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
+ <constraints>
+ <constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="Kid-kn-2rF"/>
+ <constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
+ <constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/>
+ </constraints>
+ <nil key="simulatedStatusBarMetrics"/>
+ <freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
+ <point key="canvasLocation" x="479" y="456.5"/>
+ </view>
+ </objects>
+</document>
diff --git a/third_party/protobuf/objectivec/Tests/iOSTestHarness/en.lproj/InfoPlist.strings b/third_party/protobuf/objectivec/Tests/iOSTestHarness/en.lproj/InfoPlist.strings
new file mode 100644
index 0000000000..477b28ff8f
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/iOSTestHarness/en.lproj/InfoPlist.strings
@@ -0,0 +1,2 @@
+/* Localized versions of Info.plist keys */
+
diff --git a/third_party/protobuf/objectivec/Tests/text_format_map_unittest_data.txt b/third_party/protobuf/objectivec/Tests/text_format_map_unittest_data.txt
new file mode 100644
index 0000000000..ad1195e2f9
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/text_format_map_unittest_data.txt
@@ -0,0 +1,70 @@
+map_int32_int32 {
+ key: 100
+ value: 1
+}
+map_int64_int64 {
+ key: 101
+ value: 1
+}
+map_uint32_uint32 {
+ key: 102
+ value: 1
+}
+map_uint64_uint64 {
+ key: 103
+ value: 1
+}
+map_sint32_sint32 {
+ key: 104
+ value: 1
+}
+map_sint64_sint64 {
+ key: 105
+ value: 1
+}
+map_fixed32_fixed32 {
+ key: 106
+ value: 1
+}
+map_fixed64_fixed64 {
+ key: 107
+ value: 1
+}
+map_sfixed32_sfixed32 {
+ key: 108
+ value: 1
+}
+map_sfixed64_sfixed64 {
+ key: 109
+ value: 1
+}
+map_int32_float {
+ key: 110
+ value: 1
+}
+map_int32_double {
+ key: 111
+ value: 1
+}
+map_bool_bool {
+ key: true
+ value: false
+}
+map_string_string {
+ key: "112"
+ value: "1"
+}
+map_int32_bytes {
+ key: 113
+ value: "\001\000\000\000"
+}
+map_int32_enum {
+ key: 114
+ value: MAP_ENUM_BAZ
+}
+map_int32_foreign_message {
+ key: 115
+ value {
+ c: 1
+ }
+}
diff --git a/third_party/protobuf/objectivec/Tests/text_format_unittest_data.txt b/third_party/protobuf/objectivec/Tests/text_format_unittest_data.txt
new file mode 100644
index 0000000000..d10f10006a
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/text_format_unittest_data.txt
@@ -0,0 +1,116 @@
+optional_int32: 101
+optional_int64: 102
+optional_uint32: 103
+optional_uint64: 104
+optional_sint32: 105
+optional_sint64: 106
+optional_fixed32: 107
+optional_fixed64: 108
+optional_sfixed32: 109
+optional_sfixed64: 110
+optional_float: 111
+optional_double: 112
+optional_bool: true
+optional_string: "115"
+optional_bytes: "\001\000\002\003\000\005"
+OptionalGroup {
+ a: 117
+}
+optional_nested_message {
+ bb: 118
+}
+optional_foreign_message {
+ c: 119
+}
+optional_import_message {
+ d: 120
+}
+optional_nested_enum: BAZ
+optional_foreign_enum: FOREIGN_BAZ
+optional_import_enum: IMPORT_BAZ
+optional_string_piece: "124"
+optional_cord: "125"
+repeated_int32: 201
+repeated_int32: 301
+repeated_int64: 202
+repeated_int64: 302
+repeated_uint32: 203
+repeated_uint32: 303
+repeated_uint64: 204
+repeated_uint64: 304
+repeated_sint32: 205
+repeated_sint32: 305
+repeated_sint64: 206
+repeated_sint64: 306
+repeated_fixed32: 207
+repeated_fixed32: 307
+repeated_fixed64: 208
+repeated_fixed64: 308
+repeated_sfixed32: 209
+repeated_sfixed32: 309
+repeated_sfixed64: 210
+repeated_sfixed64: 310
+repeated_float: 211
+repeated_float: 311
+repeated_double: 212
+repeated_double: 312
+repeated_bool: false
+repeated_bool: true
+repeated_string: "215"
+repeated_string: "315"
+repeated_bytes: "\330\000\000\000"
+repeated_bytes: "<\001\000\000"
+RepeatedGroup {
+ a: 217
+}
+RepeatedGroup {
+ a: 317
+}
+repeated_nested_message {
+ bb: 218
+}
+repeated_nested_message {
+ bb: 318
+}
+repeated_foreign_message {
+ c: 219
+}
+repeated_foreign_message {
+ c: 319
+}
+repeated_import_message {
+ d: 220
+}
+repeated_import_message {
+ d: 320
+}
+repeated_nested_enum: BAZ
+repeated_nested_enum: BAR
+repeated_foreign_enum: FOREIGN_BAZ
+repeated_foreign_enum: FOREIGN_BAR
+repeated_import_enum: IMPORT_BAZ
+repeated_import_enum: IMPORT_BAR
+repeated_string_piece: "224"
+repeated_string_piece: "324"
+repeated_cord: "225"
+repeated_cord: "325"
+default_int32: 401
+default_int64: 402
+default_uint32: 403
+default_uint64: 404
+default_sint32: 405
+default_sint64: 406
+default_fixed32: 407
+default_fixed64: 408
+default_sfixed32: 409
+default_sfixed64: 410
+default_float: 411
+default_double: 412
+default_bool: false
+default_string: "415"
+default_bytes: "\240\001\000\000"
+default_nested_enum: FOO
+default_foreign_enum: FOREIGN_FOO
+default_import_enum: IMPORT_FOO
+default_string_piece: "424"
+default_cord: "425"
diff --git a/third_party/protobuf/objectivec/Tests/unittest_cycle.proto b/third_party/protobuf/objectivec/Tests/unittest_cycle.proto
new file mode 100644
index 0000000000..afc1b0fe27
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_cycle.proto
@@ -0,0 +1,56 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// 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.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+// Cycles in the Message graph can cause problems for message class
+// initialization order.
+
+// You can't make a object graph that spans files, so this can only be done
+// within a single proto file.
+
+message CycleFoo {
+ optional CycleFoo a_foo = 1;
+ optional CycleBar a_bar = 2;
+ optional CycleBaz a_baz = 3;
+}
+
+message CycleBar {
+ optional CycleBar a_bar = 1;
+ optional CycleBaz a_baz = 2;
+ optional CycleFoo a_foo = 3;
+}
+
+message CycleBaz {
+ optional CycleBaz a_baz = 1;
+ optional CycleFoo a_foo = 2;
+ optional CycleBar a_bar = 3;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_deprecated.proto b/third_party/protobuf/objectivec/Tests/unittest_deprecated.proto
new file mode 100644
index 0000000000..96a52bbbe2
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_deprecated.proto
@@ -0,0 +1,95 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// 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.
+
+syntax = "proto2";
+
+package protobuf_deprecated;
+option objc_class_prefix = "Dep";
+
+//
+// This file is like unittest_deprecated_file.proto, but uses message, enum,
+// enum value, and field level deprecation.
+//
+// The source generated from this file needs to be inspect to confirm it has
+// all of the expected annotations. It also will be compiled into the unittest
+// and that compile should be clean without errors.
+//
+
+// Mix of field types marked as deprecated.
+message Msg1 {
+ extensions 100 to max;
+
+ optional string string_field = 1 [deprecated=true];
+ required int32 int_field = 2 [deprecated=true];
+ repeated fixed32 fixed_field = 3 [deprecated=true];
+ optional Msg1 msg_field = 4 [deprecated=true];
+}
+
+// Mix of extension field types marked as deprecated.
+extend Msg1 {
+ optional string string_ext_field = 101 [deprecated=true];
+ optional int32 int_ext_field = 102 [deprecated=true];
+ repeated fixed32 fixed_ext_field = 103 [deprecated=true];
+ optional Msg1 msg_ext_field = 104 [deprecated=true];
+}
+
+// Mix of extension field types (scoped to a message) marked as deprecated.
+message Msg1A {
+ extend Msg1 {
+ optional string string_ext2_field = 201 [deprecated=true];
+ optional int32 int_ext2_field = 202 [deprecated=true];
+ repeated fixed32 fixed_ext2_field = 203 [deprecated=true];
+ optional Msg1 msg_ext2_field = 204 [deprecated=true];
+ }
+}
+
+// Enum value marked as deprecated.
+enum Enum1 {
+ ENUM1_ONE = 1;
+ ENUM1_TWO = 2;
+ ENUM1_THREE = 3 [deprecated=true];
+}
+
+// Message marked as deprecated.
+message Msg2 {
+ option deprecated = true;
+
+ optional string string_field = 1;
+ required int32 int_field = 2;
+ repeated fixed32 fixed_field = 3;
+}
+
+// Enum marked as deprecated.
+enum Enum2 {
+ option deprecated = true;
+
+ ENUM2_ONE = 1;
+ ENUM2_TWO = 2;
+ ENUM2_THREE = 3;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_deprecated_file.proto b/third_party/protobuf/objectivec/Tests/unittest_deprecated_file.proto
new file mode 100644
index 0000000000..ef92e7de1a
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_deprecated_file.proto
@@ -0,0 +1,76 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// 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.
+
+syntax = "proto2";
+
+package protobuf_deprecated_file;
+option objc_class_prefix = "FileDep";
+
+//
+// This file is like unittest_deprecated.proto, but does NOT use message, enum,
+// enum value, or field level deprecation; instead it uses the file level option
+// to mark everything.
+//
+// The source generated from this file needs to be inspect to confirm it has
+// all of the expected annotations. It also will be compiled into the unittest
+// and that compile should be clean without errors.
+//
+option deprecated = true;
+
+// Message to catch the deprecation.
+message Msg1 {
+ extensions 100 to max;
+
+ optional string string_field = 1;
+}
+
+// Mix of extension field types to catch the deprecation.
+extend Msg1 {
+ optional string string_ext_field = 101;
+ optional int32 int_ext_field = 102;
+ repeated fixed32 fixed_ext_field = 103;
+ optional Msg1 msg_ext_field = 104;
+}
+
+// Mix of extension field types (scoped to a message) to catch the deprecation.
+message Msg1A {
+ extend Msg1 {
+ optional string string_ext2_field = 201;
+ optional int32 int_ext2_field = 202;
+ repeated fixed32 fixed_ext2_field = 203;
+ optional Msg1 msg_ext2_field = 204;
+ }
+}
+
+// Enum to catch the deprecation.
+enum Enum1 {
+ ENUM1_ONE = 1;
+ ENUM1_TWO = 2;
+ ENUM1_THREE = 3;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_extension_chain_a.proto b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_a.proto
new file mode 100644
index 0000000000..6a227eb977
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_a.proto
@@ -0,0 +1,51 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// 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.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+import "google/protobuf/unittest.proto";
+
+import "unittest_extension_chain_b.proto";
+import "unittest_extension_chain_c.proto";
+import "unittest_extension_chain_d.proto";
+
+// The Root for this file should end up adding the local extension and merging
+// in the extensions from D's Root (unittest and C will come via D's).
+
+message ChainAMessage {
+ optional ChainBMessage b = 1;
+ optional ChainCMessage c = 2;
+ optional ChainDMessage d = 3;
+}
+
+extend TestAllExtensions {
+ optional int32 chain_a_extension = 10001;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_extension_chain_b.proto b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_b.proto
new file mode 100644
index 0000000000..0da7ed3e4c
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_b.proto
@@ -0,0 +1,47 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// 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.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+import "google/protobuf/unittest.proto";
+
+import "unittest_extension_chain_c.proto";
+
+// The Root for this file should end up adding the local extension and merging
+// in the extensions from C's Root (unittest will come via C's).
+
+message ChainBMessage {
+ optional ChainCMessage c = 1;
+}
+
+extend TestAllExtensions {
+ optional int32 chain_b_extension = 10002;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_extension_chain_c.proto b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_c.proto
new file mode 100644
index 0000000000..c702900a4a
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_c.proto
@@ -0,0 +1,45 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// 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.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+import "google/protobuf/unittest.proto";
+
+// The Root for this file should end up adding the local extension and merging
+// in the extensions from unittest.proto's Root.
+
+message ChainCMessage {
+ optional int32 my_field = 1;
+}
+
+extend TestAllExtensions {
+ optional int32 chain_c_extension = 10003;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_extension_chain_d.proto b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_d.proto
new file mode 100644
index 0000000000..f9abe3ba59
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_d.proto
@@ -0,0 +1,49 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// 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.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+import "google/protobuf/unittest.proto";
+
+import "unittest_extension_chain_b.proto";
+import "unittest_extension_chain_c.proto";
+
+// The root should end up needing to merge B (C will be merged into B, so it
+// doesn't need to be directly merged).
+
+message ChainDMessage {
+ optional ChainBMessage b = 1;
+ optional ChainCMessage c = 2;
+}
+
+extend TestAllExtensions {
+ optional int32 chain_d_extension = 10004;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_extension_chain_e.proto b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_e.proto
new file mode 100644
index 0000000000..fe11663180
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_e.proto
@@ -0,0 +1,40 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// 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.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+import "google/protobuf/unittest.proto";
+
+// The Root for this file should end up just merging in unittest's Root.
+
+message ChainEMessage {
+ optional TestAllTypes my_field = 1;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_extension_chain_f.proto b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_f.proto
new file mode 100644
index 0000000000..b9bed7239b
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_f.proto
@@ -0,0 +1,44 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// 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.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+import "unittest_extension_chain_g.proto";
+
+// The Root for this file should just be merging in the extensions from C's
+// Root (because G doens't define anything itself).
+
+// The generated source will also have to directly import C's .h file so it can
+// compile the reference to C's Root class.
+
+message ChainFMessage {
+ optional ChainGMessage g = 1;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_extension_chain_g.proto b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_g.proto
new file mode 100644
index 0000000000..aee827b176
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_extension_chain_g.proto
@@ -0,0 +1,41 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// 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.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+import "unittest_extension_chain_c.proto";
+
+// The Root for this file should just be merging in the extensions from C's
+// Root.
+
+message ChainGMessage {
+ optional ChainCMessage c = 1;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_objc.proto b/third_party/protobuf/objectivec/Tests/unittest_objc.proto
new file mode 100644
index 0000000000..e5577faf0d
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_objc.proto
@@ -0,0 +1,467 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2011 Google Inc. All rights reserved.
+//
+// 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.
+
+syntax = "proto2";
+
+import "google/protobuf/any.proto";
+import "google/protobuf/unittest.proto";
+
+package protobuf_unittest;
+
+// Used to check that Headerdocs and appledoc work correctly. If these comments
+// are not handled correctly, Xcode will fail to build the tests.
+message TestGeneratedComments {
+ // This is a string that could contain stuff like
+ // mime types as image/* or */plain. Maybe twitter usernames
+ // like @protobuf, @google or @something.
+ optional string string_field = 1;
+}
+
+// Using the messages in unittest.proto, setup for recursive cases for testing
+// extensions at various depths.
+extend TestAllExtensions {
+ optional TestAllExtensions recursive_extension = 86;
+}
+
+// Recursive message to for testing autocreators at different depths.
+message TestRecursiveMessageWithRepeatedField {
+ optional TestRecursiveMessageWithRepeatedField a = 1;
+ repeated int32 i = 2;
+ repeated string str = 3;
+ map<int32, int32> i_to_i = 4;
+ map<string, string> str_to_str = 5;
+}
+
+// Recursive message and extension to for testing autocreators at different
+// depths.
+message TestRecursiveExtension {
+ optional TestRecursiveExtension recursive_sub_message = 1;
+ repeated int32 repeated_value = 2;
+ extensions 1000 to max;
+}
+
+extend TestRecursiveExtension {
+ optional TestRecursiveExtension recursive_message_extension = 1000;
+}
+
+message self {
+ message super {
+ optional int32 description = 1;
+ }
+
+ enum autorelease {
+ retain = 1;
+ release = 2;
+ retainCount = 3;
+ }
+
+ // Singular
+ optional bool id = 1;
+ optional bool _cmd = 2;
+ optional bool in = 3;
+ optional bool out = 4;
+ optional bool inout = 5;
+ optional bool bycopy = 6;
+ optional bool byref = 7;
+ optional bool oneway = 8;
+ optional bool dealloc = 9;
+ optional bool zone = 10;
+ optional bool isProxy = 11;
+ optional bool copy = 12;
+ optional bool readonly = 13;
+ optional bool default = 14;
+ optional bool assign = 15;
+ optional bool getter = 16;
+ optional bool setter = 17;
+ optional bool weak = 18;
+ optional bool public = 19;
+ optional bool case = 20;
+
+ optional autorelease SubEnum = 25;
+
+ optional group New = 50 {
+ optional string copy = 51;
+ }
+ optional group MutableCopy = 60 {
+ optional int32 extensionRegistry = 61;
+ }
+
+ extensions 90 to 94;
+
+}
+
+enum retain {
+ count = 4;
+ initialized = 5;
+ serializedSize = 6;
+}
+
+message ObjCPropertyNaming {
+ // Test that the properties properly get things all caps.
+ optional string url = 1;
+ optional string thumbnail_url = 2;
+ optional string url_foo = 3;
+ optional string some_url_blah = 4;
+ optional string http = 5;
+ optional string https = 6;
+ // This one doesn't.
+ repeated string urls = 7;
+}
+
+// EnumValueShortName: The short names shouldn't get suffixes/prefixes.
+enum Foo {
+ SERIALIZED_SIZE = 1;
+ SIZE = 2;
+ OTHER = 3;
+}
+
+// EnumValueShortName: The enum name gets a prefix.
+enum Category {
+ RED = 1;
+ BLUE = 2;
+}
+
+// EnumValueShortName: Twist case, full name gets PB, but the short names
+// should still end up correct.
+enum Time {
+ BASE = 1;
+ RECORD = 2;
+ SOMETHING_ELSE = 3;
+}
+
+extend self {
+ repeated int32 debugDescription = 90 [packed = true];
+ repeated int64 finalize = 91 [packed = true];
+ repeated uint32 hash = 92 [packed = true];
+ repeated uint64 classForCoder = 93 [packed = true];
+ repeated sint32 byref = 94 [packed = true];
+}
+
+// Test handing of fields that start with init* since Xcode 5's ARC support
+// doesn't like messages that look like initializers but aren't.
+message ObjCInitFoo {
+ optional string init_val = 11;
+ optional int32 init_size = 12;
+ optional self init_self = 13;
+
+ repeated string init_vals = 21;
+ repeated int32 init_sizes = 22;
+ repeated self init_selfs = 23;
+}
+
+// Test handling of fields that start with retained names.
+message ObjCRetainedFoo {
+ optional string new_val_lower_complex = 11;
+ optional string new_Val_upper_complex = 12;
+ optional string newvalue_lower_no_underscore_complex = 13;
+ optional string newValue_upper_no_underscore_complex = 14;
+
+ optional int32 new_val_lower_primitive = 15;
+ optional int32 new_Val_upper_primitive = 16;
+ optional int32 newvalue_lower_no_underscore_primitive = 17;
+ optional int32 newValue_upper_no_underscore_primitive = 18;
+
+ optional self new_val_lower_message = 19;
+ optional self new_Val_upper_message = 20;
+ optional self newvalue_lower_no_underscore_message = 21;
+ optional self newValue_upper_no_underscore_message = 22;
+
+ optional Foo new_val_lower_enum = 23;
+ optional Foo new_Val_upper_enum = 24;
+ optional Foo newvalue_lower_no_underscore_enum = 25;
+ optional Foo newValue_upper_no_underscore_enum = 26;
+
+ repeated string new_val_lower_complex_repeated = 111;
+ repeated string new_Val_upper_complex_repeated = 112;
+ repeated string newvalue_lower_no_underscore_complex_repeated = 113;
+ repeated string newValue_upper_no_underscore_complex_repeated = 114;
+
+ repeated int32 new_val_lower_primitive_repeated = 115;
+ repeated int32 new_Val_upper_primitive_repeated = 116;
+ repeated int32 newvalue_lower_no_underscore_primitive_repeated = 117;
+ repeated int32 newValue_upper_no_underscore_primitive_repeated = 118;
+
+ repeated self new_val_lower_message_repeated = 119;
+ repeated self new_Val_upper_message_repeated = 120;
+ repeated self newvalue_lower_no_underscore_message_repeated = 121;
+ repeated self newValue_upper_no_underscore_message_repeated = 122;
+
+ repeated Foo new_val_lower_enum_repeated = 123;
+ repeated Foo new_Val_upper_enum_repeated = 124;
+ repeated Foo newvalue_lower_no_underscore_enum_repeated = 125;
+ repeated Foo newValue_upper_no_underscore_enum_repeated = 126;
+
+ optional string alloc_val_lower_complex = 211;
+ optional string alloc_Val_upper_complex = 212;
+ optional string allocvalue_lower_no_underscore_complex = 213;
+ optional string allocValue_upper_no_underscore_complex = 214;
+
+ optional int32 alloc_val_lower_primitive = 215;
+ optional int32 alloc_Val_upper_primitive = 216;
+ optional int32 allocvalue_lower_no_underscore_primitive = 217;
+ optional int32 allocValue_upper_no_underscore_primitive = 218;
+
+ optional self alloc_val_lower_message = 219;
+ optional self alloc_Val_upper_message = 220;
+ optional self allocvalue_lower_no_underscore_message = 221;
+ optional self allocValue_upper_no_underscore_message = 222;
+
+ optional Foo alloc_val_lower_enum = 223;
+ optional Foo alloc_Val_upper_enum = 224;
+ optional Foo allocvalue_lower_no_underscore_enum = 225;
+ optional Foo allocValue_upper_no_underscore_enum = 226;
+
+ repeated string alloc_val_lower_complex_repeated = 311;
+ repeated string alloc_Val_upper_complex_repeated = 312;
+ repeated string allocvalue_lower_no_underscore_complex_repeated = 313;
+ repeated string allocValue_upper_no_underscore_complex_repeated = 314;
+
+ repeated int32 alloc_val_lower_primitive_repeated = 315;
+ repeated int32 alloc_Val_upper_primitive_repeated = 316;
+ repeated int32 allocvalue_lower_no_underscore_primitive_repeated = 317;
+ repeated int32 allocValue_upper_no_underscore_primitive_repeated = 318;
+
+ repeated self alloc_val_lower_message_repeated = 319;
+ repeated self alloc_Val_upper_message_repeated = 320;
+ repeated self allocvalue_lower_no_underscore_message_repeated = 321;
+ repeated self allocValue_upper_no_underscore_message_repeated = 322;
+
+ repeated Foo alloc_val_lower_enum_repeated = 323;
+ repeated Foo alloc_Val_upper_enum_repeated = 324;
+ repeated Foo allocvalue_lower_no_underscore_enum_repeated = 325;
+ repeated Foo allocValue_upper_no_underscore_enum_repeated = 326;
+
+ optional string copy_val_lower_complex = 411;
+ optional string copy_Val_upper_complex = 412;
+ optional string copyvalue_lower_no_underscore_complex = 413;
+ optional string copyValue_upper_no_underscore_complex = 414;
+
+ optional int32 copy_val_lower_primitive = 415;
+ optional int32 copy_Val_upper_primitive = 416;
+ optional int32 copyvalue_lower_no_underscore_primitive = 417;
+ optional int32 copyValue_upper_no_underscore_primitive = 418;
+
+ optional self copy_val_lower_message = 419;
+ optional self copy_Val_upper_message = 420;
+ optional self copyvalue_lower_no_underscore_message = 421;
+ optional self copyValue_upper_no_underscore_message = 422;
+
+ optional Foo copy_val_lower_enum = 423;
+ optional Foo copy_Val_upper_enum = 424;
+ optional Foo copyvalue_lower_no_underscore_enum = 425;
+ optional Foo copyValue_upper_no_underscore_enum = 426;
+
+ repeated string copy_val_lower_complex_repeated = 511;
+ repeated string copy_Val_upper_complex_repeated = 512;
+ repeated string copyvalue_lower_no_underscore_complex_repeated = 513;
+ repeated string copyValue_upper_no_underscore_complex_repeated = 514;
+
+ repeated int32 copy_val_lower_primitive_repeated = 515;
+ repeated int32 copy_Val_upper_primitive_repeated = 516;
+ repeated int32 copyvalue_lower_no_underscore_primitive_repeated = 517;
+ repeated int32 copyValue_upper_no_underscore_primitive_repeated = 518;
+
+ repeated self copy_val_lower_message_repeated = 519;
+ repeated self copy_Val_upper_message_repeated = 520;
+ repeated self copyvalue_lower_no_underscore_message_repeated = 521;
+ repeated self copyValue_upper_no_underscore_message_repeated = 522;
+
+ repeated Foo copy_val_lower_enum_repeated = 523;
+ repeated Foo copy_Val_upper_enum_repeated = 524;
+ repeated Foo copyvalue_lower_no_underscore_enum_repeated = 525;
+ repeated Foo copyValue_upper_no_underscore_enum_repeated = 526;
+
+ optional string mutableCopy_val_lower_complex = 611;
+ optional string mutableCopy_Val_upper_complex = 612;
+ optional string mutableCopyvalue_lower_no_underscore_complex = 613;
+ optional string mutableCopyValue_upper_no_underscore_complex = 614;
+
+ optional int32 mutableCopy_val_lower_primitive = 615;
+ optional int32 mutableCopy_Val_upper_primitive = 616;
+ optional int32 mutableCopyvalue_lower_no_underscore_primitive = 617;
+ optional int32 mutableCopyValue_upper_no_underscore_primitive = 618;
+
+ optional self mutableCopy_val_lower_message = 619;
+ optional self mutableCopy_Val_upper_message = 620;
+ optional self mutableCopyvalue_lower_no_underscore_message = 621;
+ optional self mutableCopyValue_upper_no_underscore_message = 622;
+
+ optional Foo mutableCopy_val_lower_enum = 623;
+ optional Foo mutableCopy_Val_upper_enum = 624;
+ optional Foo mutableCopyvalue_lower_no_underscore_enum = 625;
+ optional Foo mutableCopyValue_upper_no_underscore_enum = 626;
+
+ repeated string mutableCopy_val_lower_complex_repeated = 711;
+ repeated string mutableCopy_Val_upper_complex_repeated = 712;
+ repeated string mutableCopyvalue_lower_no_underscore_complex_repeated = 713;
+ repeated string mutableCopyValue_upper_no_underscore_complex_repeated = 714;
+
+ repeated int32 mutableCopy_val_lower_primitive_repeated = 715;
+ repeated int32 mutableCopy_Val_upper_primitive_repeated = 716;
+ repeated int32 mutableCopyvalue_lower_no_underscore_primitive_repeated = 717;
+ repeated int32 mutableCopyValue_upper_no_underscore_primitive_repeated = 718;
+
+ repeated self mutableCopy_val_lower_message_repeated = 719;
+ repeated self mutableCopy_Val_upper_message_repeated = 720;
+ repeated self mutableCopyvalue_lower_no_underscore_message_repeated = 721;
+ repeated self mutableCopyValue_upper_no_underscore_message_repeated = 722;
+
+ repeated Foo mutableCopy_val_lower_enum_repeated = 723;
+ repeated Foo mutableCopy_Val_upper_enum_repeated = 724;
+ repeated Foo mutableCopyvalue_lower_no_underscore_enum_repeated = 725;
+ repeated Foo mutableCopyValue_upper_no_underscore_enum_repeated = 726;
+}
+
+// Test handling of fields that are the retained names.
+message ObjCRetainedComplex {
+ optional string new = 1;
+ optional string alloc = 2;
+ optional string copy = 3;
+ optional string mutableCopy = 4;
+}
+
+message ObjCRetainedComplexRepeated {
+ repeated string new = 1;
+ repeated string alloc = 2;
+ repeated string copy = 3;
+ repeated string mutableCopy = 4;
+}
+
+message ObjCRetainedPrimitive {
+ optional int32 new = 1;
+ optional int32 alloc = 2;
+ optional int32 copy = 3;
+ optional int32 mutableCopy = 4;
+}
+
+message ObjCRetainedPrimitiveRepeated {
+ repeated int32 new = 1;
+ repeated int32 alloc = 2;
+ repeated int32 copy = 3;
+ repeated int32 mutableCopy = 4;
+}
+
+message ObjCRetainedMessage {
+ optional self new = 1;
+ optional self alloc = 2;
+ optional self copy = 3;
+ optional self mutableCopy = 4;
+}
+
+message ObjCRetainedMessageRepeated {
+ repeated self new = 1;
+ repeated self alloc = 2;
+ repeated self copy = 3;
+ repeated self mutableCopy = 4;
+}
+
+// Test Handling some MacTypes
+message Point {
+ message Rect {
+ optional int32 TimeValue = 1;
+ }
+}
+
+// Test some weird defaults that we see in protos.
+message ObjcWeirdDefaults {
+ // Set default values that match the protocol buffer defined defaults to
+ // confirm hasDefault and the default values are set correctly.
+ optional string foo = 1 [default = ""];
+ optional bytes bar = 2 [default = ""];
+}
+
+// Used to confirm negative enum values work as expected.
+message EnumTestMsg {
+ enum MyEnum {
+ ZERO = 0;
+ ONE = 1;
+ TWO = 2;
+ NEG_ONE = -1;
+ NEG_TWO = -2;
+ }
+ optional MyEnum foo = 1;
+ optional MyEnum bar = 2 [default = ONE];
+ optional MyEnum baz = 3 [default = NEG_ONE];
+
+ repeated MyEnum mumble = 4;
+}
+
+// Test case for https://github.com/google/protobuf/issues/1453
+// Message with no explicit defaults, but a non zero default for an enum.
+message MessageWithOneBasedEnum {
+ enum OneBasedEnum {
+ ONE = 1;
+ TWO = 2;
+ }
+ optional OneBasedEnum enum_field = 1;
+}
+
+// Message with all bools for testing things related to bool storage.
+message BoolOnlyMessage {
+ optional bool bool_field_1 = 1;
+ optional bool bool_field_2 = 2;
+ optional bool bool_field_3 = 3;
+ optional bool bool_field_4 = 4;
+ optional bool bool_field_5 = 5;
+ optional bool bool_field_6 = 6;
+ optional bool bool_field_7 = 7;
+ optional bool bool_field_8 = 8;
+ optional bool bool_field_9 = 9;
+ optional bool bool_field_10 = 10;
+ optional bool bool_field_11 = 11;
+ optional bool bool_field_12 = 12;
+ optional bool bool_field_13 = 13;
+ optional bool bool_field_14 = 14;
+ optional bool bool_field_15 = 15;
+ optional bool bool_field_16 = 16;
+ optional bool bool_field_17 = 17;
+ optional bool bool_field_18 = 18;
+ optional bool bool_field_19 = 19;
+ optional bool bool_field_20 = 20;
+ optional bool bool_field_21 = 21;
+ optional bool bool_field_22 = 22;
+ optional bool bool_field_23 = 23;
+ optional bool bool_field_24 = 24;
+ optional bool bool_field_25 = 25;
+ optional bool bool_field_26 = 26;
+ optional bool bool_field_27 = 27;
+ optional bool bool_field_28 = 28;
+ optional bool bool_field_29 = 29;
+ optional bool bool_field_30 = 30;
+ optional bool bool_field_31 = 31;
+ optional bool bool_field_32 = 32;
+}
+
+// Reference to a WKT to test (via generated code inspection), the handling
+// of #imports. Within the WKTs, references to each other are just path
+// based imports, but when reference from another proto file, they should be
+// conditional to support the framework import style.
+message WKTRefereceMessage {
+ optional google.protobuf.Any an_any = 1;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_objc_startup.proto b/third_party/protobuf/objectivec/Tests/unittest_objc_startup.proto
new file mode 100644
index 0000000000..aee7bd556b
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_objc_startup.proto
@@ -0,0 +1,49 @@
+// 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.
+
+syntax = "proto2";
+
+package protobuf_objc_unittest;
+
+message TestObjCStartupMessage {
+ extensions 1 to max;
+}
+
+extend TestObjCStartupMessage {
+ // Singular
+ optional int32 optional_int32_extension = 1;
+ repeated int32 repeated_int32_extension = 2;
+}
+
+message TestObjCStartupNested {
+ extend TestObjCStartupMessage {
+ optional string nested_string_extension = 3;
+ }
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_runtime_proto2.proto b/third_party/protobuf/objectivec/Tests/unittest_runtime_proto2.proto
new file mode 100644
index 0000000000..ed835020af
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_runtime_proto2.proto
@@ -0,0 +1,128 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// 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.
+
+syntax = "proto2";
+
+package protobuf_unittest;
+
+message Message2 {
+ enum Enum {
+ FOO = 0;
+ BAR = 1;
+ BAZ = 2;
+ EXTRA_2 = 20;
+ }
+
+ optional int32 optional_int32 = 1;
+ optional int64 optional_int64 = 2;
+ optional uint32 optional_uint32 = 3;
+ optional uint64 optional_uint64 = 4;
+ optional sint32 optional_sint32 = 5;
+ optional sint64 optional_sint64 = 6;
+ optional fixed32 optional_fixed32 = 7;
+ optional fixed64 optional_fixed64 = 8;
+ optional sfixed32 optional_sfixed32 = 9;
+ optional sfixed64 optional_sfixed64 = 10;
+ optional float optional_float = 11;
+ optional double optional_double = 12;
+ optional bool optional_bool = 13;
+ optional string optional_string = 14;
+ optional bytes optional_bytes = 15;
+ optional group OptionalGroup = 16 {
+ optional int32 a = 17;
+ }
+ optional Message2 optional_message = 18;
+ optional Enum optional_enum = 19;
+
+ repeated int32 repeated_int32 = 31;
+ repeated int64 repeated_int64 = 32;
+ repeated uint32 repeated_uint32 = 33;
+ repeated uint64 repeated_uint64 = 34;
+ repeated sint32 repeated_sint32 = 35;
+ repeated sint64 repeated_sint64 = 36;
+ repeated fixed32 repeated_fixed32 = 37;
+ repeated fixed64 repeated_fixed64 = 38;
+ repeated sfixed32 repeated_sfixed32 = 39;
+ repeated sfixed64 repeated_sfixed64 = 40;
+ repeated float repeated_float = 41;
+ repeated double repeated_double = 42;
+ repeated bool repeated_bool = 43;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+ repeated group RepeatedGroup = 46 {
+ optional int32 a = 47;
+ }
+ repeated Message2 repeated_message = 48;
+ repeated Enum repeated_enum = 49;
+
+ oneof o {
+ int32 oneof_int32 = 51 [default = 100];
+ int64 oneof_int64 = 52 [default = 101];
+ uint32 oneof_uint32 = 53 [default = 102];
+ uint64 oneof_uint64 = 54 [default = 103];
+ sint32 oneof_sint32 = 55 [default = 104];
+ sint64 oneof_sint64 = 56 [default = 105];
+ fixed32 oneof_fixed32 = 57 [default = 106];
+ fixed64 oneof_fixed64 = 58 [default = 107];
+ sfixed32 oneof_sfixed32 = 59 [default = 108];
+ sfixed64 oneof_sfixed64 = 60 [default = 109];
+ float oneof_float = 61 [default = 110];
+ double oneof_double = 62 [default = 111];
+ bool oneof_bool = 63 [default = true];
+ string oneof_string = 64 [default = "string"];
+ bytes oneof_bytes = 65 [default = "data"];
+ group OneofGroup = 66 {
+ optional int32 a = 67;
+ optional int32 b = 167;
+ }
+ Message2 oneof_message = 68;
+ Enum oneof_enum = 69 [default = BAZ];
+ }
+
+ // Some token map cases, too many combinations to list them all.
+ map<int32 , int32 > map_int32_int32 = 70;
+ map<int64 , int64 > map_int64_int64 = 71;
+ map<uint32 , uint32 > map_uint32_uint32 = 72;
+ map<uint64 , uint64 > map_uint64_uint64 = 73;
+ map<sint32 , sint32 > map_sint32_sint32 = 74;
+ map<sint64 , sint64 > map_sint64_sint64 = 75;
+ map<fixed32 , fixed32 > map_fixed32_fixed32 = 76;
+ map<fixed64 , fixed64 > map_fixed64_fixed64 = 77;
+ map<sfixed32, sfixed32> map_sfixed32_sfixed32 = 78;
+ map<sfixed64, sfixed64> map_sfixed64_sfixed64 = 79;
+ map<int32 , float > map_int32_float = 80;
+ map<int32 , double > map_int32_double = 81;
+ map<bool , bool > map_bool_bool = 82;
+ map<string , string > map_string_string = 83;
+ map<string , bytes > map_string_bytes = 84;
+ map<string , Message2> map_string_message = 85;
+ map<int32 , bytes > map_int32_bytes = 86;
+ map<int32 , Enum > map_int32_enum = 87;
+ map<int32 , Message2> map_int32_message = 88;
+}
diff --git a/third_party/protobuf/objectivec/Tests/unittest_runtime_proto3.proto b/third_party/protobuf/objectivec/Tests/unittest_runtime_proto3.proto
new file mode 100644
index 0000000000..ad2e3620d3
--- /dev/null
+++ b/third_party/protobuf/objectivec/Tests/unittest_runtime_proto3.proto
@@ -0,0 +1,121 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2015 Google Inc. All rights reserved.
+//
+// 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.
+
+syntax = "proto3";
+
+package protobuf_unittest;
+
+message Message3 {
+ enum Enum {
+ FOO = 0;
+ BAR = 1;
+ BAZ = 2;
+ EXTRA_3 = 30;
+ }
+
+ int32 optional_int32 = 1;
+ int64 optional_int64 = 2;
+ uint32 optional_uint32 = 3;
+ uint64 optional_uint64 = 4;
+ sint32 optional_sint32 = 5;
+ sint64 optional_sint64 = 6;
+ fixed32 optional_fixed32 = 7;
+ fixed64 optional_fixed64 = 8;
+ sfixed32 optional_sfixed32 = 9;
+ sfixed64 optional_sfixed64 = 10;
+ float optional_float = 11;
+ double optional_double = 12;
+ bool optional_bool = 13;
+ string optional_string = 14;
+ bytes optional_bytes = 15;
+ // No 'group' in proto3.
+ Message3 optional_message = 18;
+ Enum optional_enum = 19;
+
+ repeated int32 repeated_int32 = 31;
+ repeated int64 repeated_int64 = 32;
+ repeated uint32 repeated_uint32 = 33;
+ repeated uint64 repeated_uint64 = 34;
+ repeated sint32 repeated_sint32 = 35;
+ repeated sint64 repeated_sint64 = 36;
+ repeated fixed32 repeated_fixed32 = 37;
+ repeated fixed64 repeated_fixed64 = 38;
+ repeated sfixed32 repeated_sfixed32 = 39;
+ repeated sfixed64 repeated_sfixed64 = 40;
+ repeated float repeated_float = 41;
+ repeated double repeated_double = 42;
+ repeated bool repeated_bool = 43;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+ // No 'group' in proto3.
+ repeated Message3 repeated_message = 48;
+ repeated Enum repeated_enum = 49;
+
+ oneof o {
+ int32 oneof_int32 = 51;
+ int64 oneof_int64 = 52;
+ uint32 oneof_uint32 = 53;
+ uint64 oneof_uint64 = 54;
+ sint32 oneof_sint32 = 55;
+ sint64 oneof_sint64 = 56;
+ fixed32 oneof_fixed32 = 57;
+ fixed64 oneof_fixed64 = 58;
+ sfixed32 oneof_sfixed32 = 59;
+ sfixed64 oneof_sfixed64 = 60;
+ float oneof_float = 61;
+ double oneof_double = 62;
+ bool oneof_bool = 63;
+ string oneof_string = 64;
+ bytes oneof_bytes = 65;
+ // No 'group' in proto3.
+ Message3 oneof_message = 68;
+ Enum oneof_enum = 69;
+ }
+
+ // Some token map cases, too many combinations to list them all.
+ map<int32 , int32 > map_int32_int32 = 70;
+ map<int64 , int64 > map_int64_int64 = 71;
+ map<uint32 , uint32 > map_uint32_uint32 = 72;
+ map<uint64 , uint64 > map_uint64_uint64 = 73;
+ map<sint32 , sint32 > map_sint32_sint32 = 74;
+ map<sint64 , sint64 > map_sint64_sint64 = 75;
+ map<fixed32 , fixed32 > map_fixed32_fixed32 = 76;
+ map<fixed64 , fixed64 > map_fixed64_fixed64 = 77;
+ map<sfixed32, sfixed32> map_sfixed32_sfixed32 = 78;
+ map<sfixed64, sfixed64> map_sfixed64_sfixed64 = 79;
+ map<int32 , float > map_int32_float = 80;
+ map<int32 , double > map_int32_double = 81;
+ map<bool , bool > map_bool_bool = 82;
+ map<string , string > map_string_string = 83;
+ map<string , bytes > map_string_bytes = 84;
+ map<string , Message3> map_string_message = 85;
+ map<int32 , bytes > map_int32_bytes = 86;
+ map<int32 , Enum > map_int32_enum = 87;
+ map<int32 , Message3> map_int32_message = 88;
+}
diff --git a/third_party/protobuf/objectivec/generate_well_known_types.sh b/third_party/protobuf/objectivec/generate_well_known_types.sh
new file mode 100755
index 0000000000..36c346031c
--- /dev/null
+++ b/third_party/protobuf/objectivec/generate_well_known_types.sh
@@ -0,0 +1,76 @@
+#!/bin/bash
+
+# Run this script to regenerate *.pbobjc.{h,m} for the well known types after
+# the protocol compiler changes.
+
+# HINT: Flags passed to generate_well_known_types.sh will be passed directly
+# to make when building protoc. This is particularly useful for passing
+# -j4 to run 4 jobs simultaneously.
+
+set -eu
+
+readonly ScriptDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
+readonly ProtoRootDir="${ScriptDir}/.."
+
+# Flag for continuous integration to check that everything is current.
+CHECK_ONLY=0
+if [[ $# -ge 1 && ( "$1" == "--check-only" ) ]] ; then
+ CHECK_ONLY=1
+ shift
+fi
+
+pushd "${ProtoRootDir}" > /dev/null
+
+if test ! -e src/google/protobuf/stubs/common.h; then
+ cat >&2 << __EOF__
+Could not find source code. Make sure you are running this script from the
+root of the distribution tree.
+__EOF__
+ exit 1
+fi
+
+if test ! -e src/Makefile; then
+ cat >&2 << __EOF__
+Could not find src/Makefile. You must run ./configure (and perhaps
+./autogen.sh) first.
+__EOF__
+ exit 1
+fi
+
+# Make sure the compiler is current.
+cd src
+make $@ protoc
+
+declare -a RUNTIME_PROTO_FILES=( \
+ google/protobuf/any.proto \
+ google/protobuf/api.proto \
+ google/protobuf/duration.proto \
+ google/protobuf/empty.proto \
+ google/protobuf/field_mask.proto \
+ google/protobuf/source_context.proto \
+ google/protobuf/struct.proto \
+ google/protobuf/timestamp.proto \
+ google/protobuf/type.proto \
+ google/protobuf/wrappers.proto)
+
+# Generate to a temp directory to see if they match.
+TMP_DIR=$(mktemp -d)
+trap "rm -rf ${TMP_DIR}" EXIT
+./protoc --objc_out="${TMP_DIR}" ${RUNTIME_PROTO_FILES[@]}
+set +e
+diff -r "${TMP_DIR}/google" "${ProtoRootDir}/objectivec/google" > /dev/null
+if [[ $? -eq 0 ]] ; then
+ echo "Generated source for WellKnownTypes is current."
+ exit 0
+fi
+set -e
+
+# If check only mode, error out.
+if [[ "${CHECK_ONLY}" == 1 ]] ; then
+ echo "ERROR: The WKTs need to be regenerated! Run $0"
+ exit 1
+fi
+
+# Copy them over.
+echo "Copying over updated WellKnownType sources."
+cp -r "${TMP_DIR}/google/." "${ProtoRootDir}/objectivec/google/"
diff --git a/third_party/protobuf/objectivec/google/protobuf/Any.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/Any.pbobjc.h
new file mode 100644
index 0000000000..d236e4b20e
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Any.pbobjc.h
@@ -0,0 +1,163 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/any.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - GPBAnyRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBAnyRoot : GPBRootObject
+@end
+
+#pragma mark - GPBAny
+
+typedef GPB_ENUM(GPBAny_FieldNumber) {
+ GPBAny_FieldNumber_TypeURL = 1,
+ GPBAny_FieldNumber_Value = 2,
+};
+
+/**
+ * `Any` contains an arbitrary serialized protocol buffer message along with a
+ * URL that describes the type of the serialized message.
+ *
+ * Protobuf library provides support to pack/unpack Any values in the form
+ * of utility functions or additional generated methods of the Any type.
+ *
+ * Example 1: Pack and unpack a message in C++.
+ *
+ * Foo foo = ...;
+ * Any any;
+ * any.PackFrom(foo);
+ * ...
+ * if (any.UnpackTo(&foo)) {
+ * ...
+ * }
+ *
+ * Example 2: Pack and unpack a message in Java.
+ *
+ * Foo foo = ...;
+ * Any any = Any.pack(foo);
+ * ...
+ * if (any.is(Foo.class)) {
+ * foo = any.unpack(Foo.class);
+ * }
+ *
+ * Example 3: Pack and unpack a message in Python.
+ *
+ * foo = Foo(...)
+ * any = Any()
+ * any.Pack(foo)
+ * ...
+ * if any.Is(Foo.DESCRIPTOR):
+ * any.Unpack(foo)
+ * ...
+ *
+ * The pack methods provided by protobuf library will by default use
+ * 'type.googleapis.com/full.type.name' as the type URL and the unpack
+ * methods only use the fully qualified type name after the last '/'
+ * in the type URL, for example "foo.bar.com/x/y.z" will yield type
+ * name "y.z".
+ *
+ *
+ * JSON
+ * ====
+ * The JSON representation of an `Any` value uses the regular
+ * representation of the deserialized, embedded message, with an
+ * additional field `\@type` which contains the type URL. Example:
+ *
+ * package google.profile;
+ * message Person {
+ * string first_name = 1;
+ * string last_name = 2;
+ * }
+ *
+ * {
+ * "\@type": "type.googleapis.com/google.profile.Person",
+ * "firstName": <string>,
+ * "lastName": <string>
+ * }
+ *
+ * If the embedded message type is well-known and has a custom JSON
+ * representation, that representation will be embedded adding a field
+ * `value` which holds the custom JSON in addition to the `\@type`
+ * field. Example (for message [google.protobuf.Duration][]):
+ *
+ * {
+ * "\@type": "type.googleapis.com/google.protobuf.Duration",
+ * "value": "1.212s"
+ * }
+ **/
+@interface GPBAny : GPBMessage
+
+/**
+ * A URL/resource name whose content describes the type of the
+ * serialized protocol buffer message.
+ *
+ * For URLs which use the scheme `http`, `https`, or no scheme, the
+ * following restrictions and interpretations apply:
+ *
+ * * If no scheme is provided, `https` is assumed.
+ * * The last segment of the URL's path must represent the fully
+ * qualified name of the type (as in `path/google.protobuf.Duration`).
+ * The name should be in a canonical form (e.g., leading "." is
+ * not accepted).
+ * * An HTTP GET on the URL must yield a [google.protobuf.Type][]
+ * value in binary format, or produce an error.
+ * * Applications are allowed to cache lookup results based on the
+ * URL, or have them precompiled into a binary to avoid any
+ * lookup. Therefore, binary compatibility needs to be preserved
+ * on changes to types. (Use versioned type names to manage
+ * breaking changes.)
+ *
+ * Schemes other than `http`, `https` (or the empty scheme) might be
+ * used with implementation specific semantics.
+ **/
+@property(nonatomic, readwrite, copy, null_resettable) NSString *typeURL;
+
+/** Must be a valid serialized protocol buffer of the above specified type. */
+@property(nonatomic, readwrite, copy, null_resettable) NSData *value;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Any.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/Any.pbobjc.m
new file mode 100644
index 0000000000..d210643f05
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Any.pbobjc.m
@@ -0,0 +1,112 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/any.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Any.pbobjc.h>
+#else
+ #import "google/protobuf/Any.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBAnyRoot
+
+@implementation GPBAnyRoot
+
+// No extensions in the file and no imports, so no need to generate
+// +extensionRegistry.
+
+@end
+
+#pragma mark - GPBAnyRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBAnyRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - GPBAny
+
+@implementation GPBAny
+
+@dynamic typeURL;
+@dynamic value;
+
+typedef struct GPBAny__storage_ {
+ uint32_t _has_storage_[1];
+ NSString *typeURL;
+ NSData *value;
+} GPBAny__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "typeURL",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBAny_FieldNumber_TypeURL,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBAny__storage_, typeURL),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom),
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBAny_FieldNumber_Value,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBAny__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeBytes,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBAny class]
+ rootClass:[GPBAnyRoot class]
+ file:GPBAnyRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBAny__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+#if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
+ static const char *extraTextFormatInfo =
+ "\001\001\004\241!!\000";
+ [localDescriptor setupExtraTextInfo:extraTextFormatInfo];
+#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Api.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/Api.pbobjc.h
new file mode 100644
index 0000000000..742a812211
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Api.pbobjc.h
@@ -0,0 +1,299 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/api.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+@class GPBMethod;
+@class GPBMixin;
+@class GPBOption;
+@class GPBSourceContext;
+GPB_ENUM_FWD_DECLARE(GPBSyntax);
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - GPBApiRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBApiRoot : GPBRootObject
+@end
+
+#pragma mark - GPBApi
+
+typedef GPB_ENUM(GPBApi_FieldNumber) {
+ GPBApi_FieldNumber_Name = 1,
+ GPBApi_FieldNumber_MethodsArray = 2,
+ GPBApi_FieldNumber_OptionsArray = 3,
+ GPBApi_FieldNumber_Version = 4,
+ GPBApi_FieldNumber_SourceContext = 5,
+ GPBApi_FieldNumber_MixinsArray = 6,
+ GPBApi_FieldNumber_Syntax = 7,
+};
+
+/**
+ * Api is a light-weight descriptor for a protocol buffer service.
+ **/
+@interface GPBApi : GPBMessage
+
+/**
+ * The fully qualified name of this api, including package name
+ * followed by the api's simple name.
+ **/
+@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
+
+/** The methods of this api, in unspecified order. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBMethod*> *methodsArray;
+/** The number of items in @c methodsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger methodsArray_Count;
+
+/** Any metadata attached to the API. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray;
+/** The number of items in @c optionsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger optionsArray_Count;
+
+/**
+ * A version string for this api. If specified, must have the form
+ * `major-version.minor-version`, as in `1.10`. If the minor version
+ * is omitted, it defaults to zero. If the entire version field is
+ * empty, the major version is derived from the package name, as
+ * outlined below. If the field is not empty, the version in the
+ * package name will be verified to be consistent with what is
+ * provided here.
+ *
+ * The versioning schema uses [semantic
+ * versioning](http://semver.org) where the major version number
+ * indicates a breaking change and the minor version an additive,
+ * non-breaking change. Both version numbers are signals to users
+ * what to expect from different versions, and should be carefully
+ * chosen based on the product plan.
+ *
+ * The major version is also reflected in the package name of the
+ * API, which must end in `v<major-version>`, as in
+ * `google.feature.v1`. For major versions 0 and 1, the suffix can
+ * be omitted. Zero major versions must only be used for
+ * experimental, none-GA apis.
+ **/
+@property(nonatomic, readwrite, copy, null_resettable) NSString *version;
+
+/**
+ * Source context for the protocol buffer service represented by this
+ * message.
+ **/
+@property(nonatomic, readwrite, strong, null_resettable) GPBSourceContext *sourceContext;
+/** Test to see if @c sourceContext has been set. */
+@property(nonatomic, readwrite) BOOL hasSourceContext;
+
+/** Included APIs. See [Mixin][]. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBMixin*> *mixinsArray;
+/** The number of items in @c mixinsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger mixinsArray_Count;
+
+/** The source syntax of the service. */
+@property(nonatomic, readwrite) enum GPBSyntax syntax;
+
+@end
+
+/**
+ * Fetches the raw value of a @c GPBApi's @c syntax property, even
+ * if the value was not defined by the enum at the time the code was generated.
+ **/
+int32_t GPBApi_Syntax_RawValue(GPBApi *message);
+/**
+ * Sets the raw value of an @c GPBApi's @c syntax property, allowing
+ * it to be set to a value that was not defined by the enum at the time the code
+ * was generated.
+ **/
+void SetGPBApi_Syntax_RawValue(GPBApi *message, int32_t value);
+
+#pragma mark - GPBMethod
+
+typedef GPB_ENUM(GPBMethod_FieldNumber) {
+ GPBMethod_FieldNumber_Name = 1,
+ GPBMethod_FieldNumber_RequestTypeURL = 2,
+ GPBMethod_FieldNumber_RequestStreaming = 3,
+ GPBMethod_FieldNumber_ResponseTypeURL = 4,
+ GPBMethod_FieldNumber_ResponseStreaming = 5,
+ GPBMethod_FieldNumber_OptionsArray = 6,
+ GPBMethod_FieldNumber_Syntax = 7,
+};
+
+/**
+ * Method represents a method of an api.
+ **/
+@interface GPBMethod : GPBMessage
+
+/** The simple name of this method. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
+
+/** A URL of the input message type. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *requestTypeURL;
+
+/** If true, the request is streamed. */
+@property(nonatomic, readwrite) BOOL requestStreaming;
+
+/** The URL of the output message type. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *responseTypeURL;
+
+/** If true, the response is streamed. */
+@property(nonatomic, readwrite) BOOL responseStreaming;
+
+/** Any metadata attached to the method. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray;
+/** The number of items in @c optionsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger optionsArray_Count;
+
+/** The source syntax of this method. */
+@property(nonatomic, readwrite) enum GPBSyntax syntax;
+
+@end
+
+/**
+ * Fetches the raw value of a @c GPBMethod's @c syntax property, even
+ * if the value was not defined by the enum at the time the code was generated.
+ **/
+int32_t GPBMethod_Syntax_RawValue(GPBMethod *message);
+/**
+ * Sets the raw value of an @c GPBMethod's @c syntax property, allowing
+ * it to be set to a value that was not defined by the enum at the time the code
+ * was generated.
+ **/
+void SetGPBMethod_Syntax_RawValue(GPBMethod *message, int32_t value);
+
+#pragma mark - GPBMixin
+
+typedef GPB_ENUM(GPBMixin_FieldNumber) {
+ GPBMixin_FieldNumber_Name = 1,
+ GPBMixin_FieldNumber_Root = 2,
+};
+
+/**
+ * Declares an API to be included in this API. The including API must
+ * redeclare all the methods from the included API, but documentation
+ * and options are inherited as follows:
+ *
+ * - If after comment and whitespace stripping, the documentation
+ * string of the redeclared method is empty, it will be inherited
+ * from the original method.
+ *
+ * - Each annotation belonging to the service config (http,
+ * visibility) which is not set in the redeclared method will be
+ * inherited.
+ *
+ * - If an http annotation is inherited, the path pattern will be
+ * modified as follows. Any version prefix will be replaced by the
+ * version of the including API plus the [root][] path if specified.
+ *
+ * Example of a simple mixin:
+ *
+ * package google.acl.v1;
+ * service AccessControl {
+ * // Get the underlying ACL object.
+ * rpc GetAcl(GetAclRequest) returns (Acl) {
+ * option (google.api.http).get = "/v1/{resource=**}:getAcl";
+ * }
+ * }
+ *
+ * package google.storage.v2;
+ * service Storage {
+ * rpc GetAcl(GetAclRequest) returns (Acl);
+ *
+ * // Get a data record.
+ * rpc GetData(GetDataRequest) returns (Data) {
+ * option (google.api.http).get = "/v2/{resource=**}";
+ * }
+ * }
+ *
+ * Example of a mixin configuration:
+ *
+ * apis:
+ * - name: google.storage.v2.Storage
+ * mixins:
+ * - name: google.acl.v1.AccessControl
+ *
+ * The mixin construct implies that all methods in `AccessControl` are
+ * also declared with same name and request/response types in
+ * `Storage`. A documentation generator or annotation processor will
+ * see the effective `Storage.GetAcl` method after inherting
+ * documentation and annotations as follows:
+ *
+ * service Storage {
+ * // Get the underlying ACL object.
+ * rpc GetAcl(GetAclRequest) returns (Acl) {
+ * option (google.api.http).get = "/v2/{resource=**}:getAcl";
+ * }
+ * ...
+ * }
+ *
+ * Note how the version in the path pattern changed from `v1` to `v2`.
+ *
+ * If the `root` field in the mixin is specified, it should be a
+ * relative path under which inherited HTTP paths are placed. Example:
+ *
+ * apis:
+ * - name: google.storage.v2.Storage
+ * mixins:
+ * - name: google.acl.v1.AccessControl
+ * root: acls
+ *
+ * This implies the following inherited HTTP annotation:
+ *
+ * service Storage {
+ * // Get the underlying ACL object.
+ * rpc GetAcl(GetAclRequest) returns (Acl) {
+ * option (google.api.http).get = "/v2/acls/{resource=**}:getAcl";
+ * }
+ * ...
+ * }
+ **/
+@interface GPBMixin : GPBMessage
+
+/** The fully qualified name of the API which is included. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
+
+/**
+ * If non-empty specifies a path under which inherited HTTP paths
+ * are rooted.
+ **/
+@property(nonatomic, readwrite, copy, null_resettable) NSString *root;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Api.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/Api.pbobjc.m
new file mode 100644
index 0000000000..58b47157de
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Api.pbobjc.m
@@ -0,0 +1,356 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/api.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Api.pbobjc.h>
+ #import <Protobuf/SourceContext.pbobjc.h>
+ #import <Protobuf/Type.pbobjc.h>
+#else
+ #import "google/protobuf/Api.pbobjc.h"
+ #import "google/protobuf/SourceContext.pbobjc.h"
+ #import "google/protobuf/Type.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBApiRoot
+
+@implementation GPBApiRoot
+
+// No extensions in the file and none of the imports (direct or indirect)
+// defined extensions, so no need to generate +extensionRegistry.
+
+@end
+
+#pragma mark - GPBApiRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBApiRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - GPBApi
+
+@implementation GPBApi
+
+@dynamic name;
+@dynamic methodsArray, methodsArray_Count;
+@dynamic optionsArray, optionsArray_Count;
+@dynamic version;
+@dynamic hasSourceContext, sourceContext;
+@dynamic mixinsArray, mixinsArray_Count;
+@dynamic syntax;
+
+typedef struct GPBApi__storage_ {
+ uint32_t _has_storage_[1];
+ GPBSyntax syntax;
+ NSString *name;
+ NSMutableArray *methodsArray;
+ NSMutableArray *optionsArray;
+ NSString *version;
+ GPBSourceContext *sourceContext;
+ NSMutableArray *mixinsArray;
+} GPBApi__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "name",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBApi_FieldNumber_Name,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBApi__storage_, name),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "methodsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBMethod),
+ .number = GPBApi_FieldNumber_MethodsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBApi__storage_, methodsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "optionsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBOption),
+ .number = GPBApi_FieldNumber_OptionsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBApi__storage_, optionsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "version",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBApi_FieldNumber_Version,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBApi__storage_, version),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "sourceContext",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBSourceContext),
+ .number = GPBApi_FieldNumber_SourceContext,
+ .hasIndex = 2,
+ .offset = (uint32_t)offsetof(GPBApi__storage_, sourceContext),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "mixinsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBMixin),
+ .number = GPBApi_FieldNumber_MixinsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBApi__storage_, mixinsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "syntax",
+ .dataTypeSpecific.enumDescFunc = GPBSyntax_EnumDescriptor,
+ .number = GPBApi_FieldNumber_Syntax,
+ .hasIndex = 3,
+ .offset = (uint32_t)offsetof(GPBApi__storage_, syntax),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldHasEnumDescriptor),
+ .dataType = GPBDataTypeEnum,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBApi class]
+ rootClass:[GPBApiRoot class]
+ file:GPBApiRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBApi__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+int32_t GPBApi_Syntax_RawValue(GPBApi *message) {
+ GPBDescriptor *descriptor = [GPBApi descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBApi_FieldNumber_Syntax];
+ return GPBGetMessageInt32Field(message, field);
+}
+
+void SetGPBApi_Syntax_RawValue(GPBApi *message, int32_t value) {
+ GPBDescriptor *descriptor = [GPBApi descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBApi_FieldNumber_Syntax];
+ GPBSetInt32IvarWithFieldInternal(message, field, value, descriptor.file.syntax);
+}
+
+#pragma mark - GPBMethod
+
+@implementation GPBMethod
+
+@dynamic name;
+@dynamic requestTypeURL;
+@dynamic requestStreaming;
+@dynamic responseTypeURL;
+@dynamic responseStreaming;
+@dynamic optionsArray, optionsArray_Count;
+@dynamic syntax;
+
+typedef struct GPBMethod__storage_ {
+ uint32_t _has_storage_[1];
+ GPBSyntax syntax;
+ NSString *name;
+ NSString *requestTypeURL;
+ NSString *responseTypeURL;
+ NSMutableArray *optionsArray;
+} GPBMethod__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "name",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBMethod_FieldNumber_Name,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBMethod__storage_, name),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "requestTypeURL",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBMethod_FieldNumber_RequestTypeURL,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBMethod__storage_, requestTypeURL),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom),
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "requestStreaming",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBMethod_FieldNumber_RequestStreaming,
+ .hasIndex = 2,
+ .offset = 3, // Stored in _has_storage_ to save space.
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeBool,
+ },
+ {
+ .name = "responseTypeURL",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBMethod_FieldNumber_ResponseTypeURL,
+ .hasIndex = 4,
+ .offset = (uint32_t)offsetof(GPBMethod__storage_, responseTypeURL),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom),
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "responseStreaming",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBMethod_FieldNumber_ResponseStreaming,
+ .hasIndex = 5,
+ .offset = 6, // Stored in _has_storage_ to save space.
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeBool,
+ },
+ {
+ .name = "optionsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBOption),
+ .number = GPBMethod_FieldNumber_OptionsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBMethod__storage_, optionsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "syntax",
+ .dataTypeSpecific.enumDescFunc = GPBSyntax_EnumDescriptor,
+ .number = GPBMethod_FieldNumber_Syntax,
+ .hasIndex = 7,
+ .offset = (uint32_t)offsetof(GPBMethod__storage_, syntax),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldHasEnumDescriptor),
+ .dataType = GPBDataTypeEnum,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBMethod class]
+ rootClass:[GPBApiRoot class]
+ file:GPBApiRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBMethod__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+#if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
+ static const char *extraTextFormatInfo =
+ "\002\002\007\244\241!!\000\004\010\244\241!!\000";
+ [localDescriptor setupExtraTextInfo:extraTextFormatInfo];
+#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+int32_t GPBMethod_Syntax_RawValue(GPBMethod *message) {
+ GPBDescriptor *descriptor = [GPBMethod descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBMethod_FieldNumber_Syntax];
+ return GPBGetMessageInt32Field(message, field);
+}
+
+void SetGPBMethod_Syntax_RawValue(GPBMethod *message, int32_t value) {
+ GPBDescriptor *descriptor = [GPBMethod descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBMethod_FieldNumber_Syntax];
+ GPBSetInt32IvarWithFieldInternal(message, field, value, descriptor.file.syntax);
+}
+
+#pragma mark - GPBMixin
+
+@implementation GPBMixin
+
+@dynamic name;
+@dynamic root;
+
+typedef struct GPBMixin__storage_ {
+ uint32_t _has_storage_[1];
+ NSString *name;
+ NSString *root;
+} GPBMixin__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "name",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBMixin_FieldNumber_Name,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBMixin__storage_, name),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "root",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBMixin_FieldNumber_Root,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBMixin__storage_, root),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBMixin class]
+ rootClass:[GPBApiRoot class]
+ file:GPBApiRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBMixin__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Duration.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/Duration.pbobjc.h
new file mode 100644
index 0000000000..e70138a01e
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Duration.pbobjc.h
@@ -0,0 +1,128 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/duration.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - GPBDurationRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBDurationRoot : GPBRootObject
+@end
+
+#pragma mark - GPBDuration
+
+typedef GPB_ENUM(GPBDuration_FieldNumber) {
+ GPBDuration_FieldNumber_Seconds = 1,
+ GPBDuration_FieldNumber_Nanos = 2,
+};
+
+/**
+ * A Duration represents a signed, fixed-length span of time represented
+ * as a count of seconds and fractions of seconds at nanosecond
+ * resolution. It is independent of any calendar and concepts like "day"
+ * or "month". It is related to Timestamp in that the difference between
+ * two Timestamp values is a Duration and it can be added or subtracted
+ * from a Timestamp. Range is approximately +-10,000 years.
+ *
+ * Example 1: Compute Duration from two Timestamps in pseudo code.
+ *
+ * Timestamp start = ...;
+ * Timestamp end = ...;
+ * Duration duration = ...;
+ *
+ * duration.seconds = end.seconds - start.seconds;
+ * duration.nanos = end.nanos - start.nanos;
+ *
+ * if (duration.seconds < 0 && duration.nanos > 0) {
+ * duration.seconds += 1;
+ * duration.nanos -= 1000000000;
+ * } else if (durations.seconds > 0 && duration.nanos < 0) {
+ * duration.seconds -= 1;
+ * duration.nanos += 1000000000;
+ * }
+ *
+ * Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
+ *
+ * Timestamp start = ...;
+ * Duration duration = ...;
+ * Timestamp end = ...;
+ *
+ * end.seconds = start.seconds + duration.seconds;
+ * end.nanos = start.nanos + duration.nanos;
+ *
+ * if (end.nanos < 0) {
+ * end.seconds -= 1;
+ * end.nanos += 1000000000;
+ * } else if (end.nanos >= 1000000000) {
+ * 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
+
+/**
+ * Signed seconds of the span of time. Must be from -315,576,000,000
+ * to +315,576,000,000 inclusive.
+ **/
+@property(nonatomic, readwrite) int64_t seconds;
+
+/**
+ * Signed fractions of a second at nanosecond resolution of the span
+ * of time. Durations less than one second are represented with a 0
+ * `seconds` field and a positive or negative `nanos` field. For durations
+ * of one second or more, a non-zero value for the `nanos` field must be
+ * of the same sign as the `seconds` field. Must be from -999,999,999
+ * to +999,999,999 inclusive.
+ **/
+@property(nonatomic, readwrite) int32_t nanos;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Duration.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/Duration.pbobjc.m
new file mode 100644
index 0000000000..bafb64a04f
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Duration.pbobjc.m
@@ -0,0 +1,107 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/duration.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Duration.pbobjc.h>
+#else
+ #import "google/protobuf/Duration.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBDurationRoot
+
+@implementation GPBDurationRoot
+
+// No extensions in the file and no imports, so no need to generate
+// +extensionRegistry.
+
+@end
+
+#pragma mark - GPBDurationRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBDurationRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - GPBDuration
+
+@implementation GPBDuration
+
+@dynamic seconds;
+@dynamic nanos;
+
+typedef struct GPBDuration__storage_ {
+ uint32_t _has_storage_[1];
+ int32_t nanos;
+ int64_t seconds;
+} GPBDuration__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "seconds",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBDuration_FieldNumber_Seconds,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBDuration__storage_, seconds),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt64,
+ },
+ {
+ .name = "nanos",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBDuration_FieldNumber_Nanos,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBDuration__storage_, nanos),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt32,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBDuration class]
+ rootClass:[GPBDurationRoot class]
+ file:GPBDurationRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBDuration__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Empty.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/Empty.pbobjc.h
new file mode 100644
index 0000000000..bd49cfdbc3
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Empty.pbobjc.h
@@ -0,0 +1,70 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/empty.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - GPBEmptyRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBEmptyRoot : GPBRootObject
+@end
+
+#pragma mark - GPBEmpty
+
+/**
+ * A generic empty message that you can re-use to avoid defining duplicated
+ * empty messages in your APIs. A typical example is to use it as the request
+ * or the response type of an API method. For instance:
+ *
+ * service Foo {
+ * rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
+ * }
+ *
+ * The JSON representation for `Empty` is empty JSON object `{}`.
+ **/
+@interface GPBEmpty : GPBMessage
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Empty.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/Empty.pbobjc.m
new file mode 100644
index 0000000000..506b500e04
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Empty.pbobjc.m
@@ -0,0 +1,83 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/empty.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Empty.pbobjc.h>
+#else
+ #import "google/protobuf/Empty.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBEmptyRoot
+
+@implementation GPBEmptyRoot
+
+// No extensions in the file and no imports, so no need to generate
+// +extensionRegistry.
+
+@end
+
+#pragma mark - GPBEmptyRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBEmptyRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - GPBEmpty
+
+@implementation GPBEmpty
+
+
+typedef struct GPBEmpty__storage_ {
+ uint32_t _has_storage_[1];
+} GPBEmpty__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBEmpty class]
+ rootClass:[GPBEmptyRoot class]
+ file:GPBEmptyRoot_FileDescriptor()
+ fields:NULL
+ fieldCount:0
+ storageSize:sizeof(GPBEmpty__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/FieldMask.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/FieldMask.pbobjc.h
new file mode 100644
index 0000000000..07e6081852
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/FieldMask.pbobjc.h
@@ -0,0 +1,271 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/field_mask.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - GPBFieldMaskRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBFieldMaskRoot : GPBRootObject
+@end
+
+#pragma mark - GPBFieldMask
+
+typedef GPB_ENUM(GPBFieldMask_FieldNumber) {
+ GPBFieldMask_FieldNumber_PathsArray = 1,
+};
+
+/**
+ * `FieldMask` represents a set of symbolic field paths, for example:
+ *
+ * paths: "f.a"
+ * paths: "f.b.d"
+ *
+ * Here `f` represents a field in some root message, `a` and `b`
+ * fields in the message found in `f`, and `d` a field found in the
+ * message in `f.b`.
+ *
+ * Field masks are used to specify a subset of fields that should be
+ * returned by a get operation or modified by an update operation.
+ * Field masks also have a custom JSON encoding (see below).
+ *
+ * # Field Masks in Projections
+ *
+ * When used in the context of a projection, a response message or
+ * sub-message is filtered by the API to only contain those fields as
+ * specified in the mask. For example, if the mask in the previous
+ * example is applied to a response message as follows:
+ *
+ * f {
+ * a : 22
+ * b {
+ * d : 1
+ * x : 2
+ * }
+ * y : 13
+ * }
+ * z: 8
+ *
+ * The result will not contain specific values for fields x,y and z
+ * (their value will be set to the default, and omitted in proto text
+ * output):
+ *
+ *
+ * f {
+ * a : 22
+ * b {
+ * d : 1
+ * }
+ * }
+ *
+ * A repeated field is not allowed except at the last position of a
+ * 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
+ * had been specified).
+ *
+ * Note that a field mask does not necessarily apply to the
+ * top-level response message. In case of a REST get operation, the
+ * field mask applies directly to the response, but in case of a REST
+ * list operation, the mask instead applies to each individual message
+ * in the returned resource list. In case of a REST custom method,
+ * other definitions may be used. Where the mask applies will be
+ * clearly documented together with its declaration in the API. In
+ * any case, the effect on the returned resource/resources is required
+ * behavior for APIs.
+ *
+ * # Field Masks in Update Operations
+ *
+ * A field mask in update operations specifies which fields of the
+ * targeted resource are going to be updated. The API is required
+ * to only change the values of the fields as specified in the mask
+ * and leave the others untouched. If a resource is passed in to
+ * describe the updated values, the API ignores the values of all
+ * fields not covered by the mask.
+ *
+ * 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 `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
+ * overwritten. Given the target message:
+ *
+ * f {
+ * b {
+ * d : 1
+ * x : 2
+ * }
+ * c : 1
+ * }
+ *
+ * And an update message:
+ *
+ * f {
+ * b {
+ * d : 10
+ * }
+ * }
+ *
+ * then if the field mask is:
+ *
+ * paths: "f.b"
+ *
+ * then the result will be:
+ *
+ * f {
+ * b {
+ * d : 10
+ * }
+ * c : 1
+ * }
+ *
+ * However, if the update mask was:
+ *
+ * paths: "f.b.d"
+ *
+ * then the result would be:
+ *
+ * f {
+ * b {
+ * d : 10
+ * x : 2
+ * }
+ * c : 1
+ * }
+ *
+ * In order to reset a field's value to the default, the field must
+ * be in the mask and set to the default value in the provided resource.
+ * Hence, in order to reset all fields of a resource, provide a default
+ * instance of the resource and set all fields in the mask, or do
+ * not provide a mask as described below.
+ *
+ * If a field mask is not present on update, the operation applies to
+ * all fields (as if a field mask of all fields has been specified).
+ * Note that in the presence of schema evolution, this may mean that
+ * fields the client does not know and has therefore not filled into
+ * the request will be reset to their default. If this is unwanted
+ * behavior, a specific service may require a client to always specify
+ * a field mask, producing an error if not.
+ *
+ * As with get operations, the location of the resource which
+ * describes the updated values in the request message depends on the
+ * operation kind. In any case, the effect of the field mask is
+ * required to be honored by the API.
+ *
+ * ## Considerations for HTTP REST
+ *
+ * The HTTP kind of an update operation which uses a field mask must
+ * be set to PATCH instead of PUT in order to satisfy HTTP semantics
+ * (PUT must only be used for full updates).
+ *
+ * # JSON Encoding of Field Masks
+ *
+ * In JSON, a field mask is encoded as a single string where paths are
+ * separated by a comma. Fields name in each path are converted
+ * to/from lower-camel naming conventions.
+ *
+ * As an example, consider the following message declarations:
+ *
+ * message Profile {
+ * User user = 1;
+ * Photo photo = 2;
+ * }
+ * message User {
+ * string display_name = 1;
+ * string address = 2;
+ * }
+ *
+ * In proto a field mask for `Profile` may look as such:
+ *
+ * mask {
+ * paths: "user.display_name"
+ * paths: "photo"
+ * }
+ *
+ * In JSON, the same mask is represented as below:
+ *
+ * {
+ * mask: "user.displayName,photo"
+ * }
+ *
+ * # Field Masks and Oneof Fields
+ *
+ * Field masks treat fields in oneofs just as regular fields. Consider the
+ * following message:
+ *
+ * message SampleMessage {
+ * oneof test_oneof {
+ * string name = 4;
+ * SubMessage sub_message = 9;
+ * }
+ * }
+ *
+ * The field mask can be:
+ *
+ * mask {
+ * paths: "name"
+ * }
+ *
+ * Or:
+ *
+ * mask {
+ * paths: "sub_message"
+ * }
+ *
+ * Note that oneof type names ("test_oneof" in this case) cannot be used in
+ * paths.
+ **/
+@interface GPBFieldMask : GPBMessage
+
+/** The set of field mask paths. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<NSString*> *pathsArray;
+/** The number of items in @c pathsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger pathsArray_Count;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/FieldMask.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/FieldMask.pbobjc.m
new file mode 100644
index 0000000000..b0915af450
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/FieldMask.pbobjc.m
@@ -0,0 +1,96 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/field_mask.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/FieldMask.pbobjc.h>
+#else
+ #import "google/protobuf/FieldMask.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBFieldMaskRoot
+
+@implementation GPBFieldMaskRoot
+
+// No extensions in the file and no imports, so no need to generate
+// +extensionRegistry.
+
+@end
+
+#pragma mark - GPBFieldMaskRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBFieldMaskRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - GPBFieldMask
+
+@implementation GPBFieldMask
+
+@dynamic pathsArray, pathsArray_Count;
+
+typedef struct GPBFieldMask__storage_ {
+ uint32_t _has_storage_[1];
+ NSMutableArray *pathsArray;
+} GPBFieldMask__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "pathsArray",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBFieldMask_FieldNumber_PathsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBFieldMask__storage_, pathsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeString,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBFieldMask class]
+ rootClass:[GPBFieldMaskRoot class]
+ file:GPBFieldMaskRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBFieldMask__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/SourceContext.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/SourceContext.pbobjc.h
new file mode 100644
index 0000000000..799d190ac6
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/SourceContext.pbobjc.h
@@ -0,0 +1,73 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/source_context.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - GPBSourceContextRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBSourceContextRoot : GPBRootObject
+@end
+
+#pragma mark - GPBSourceContext
+
+typedef GPB_ENUM(GPBSourceContext_FieldNumber) {
+ GPBSourceContext_FieldNumber_FileName = 1,
+};
+
+/**
+ * `SourceContext` represents information about the source of a
+ * protobuf element, like the file in which it is defined.
+ **/
+@interface GPBSourceContext : GPBMessage
+
+/**
+ * The path-qualified name of the .proto file that contained the associated
+ * protobuf element. For example: `"google/protobuf/source_context.proto"`.
+ **/
+@property(nonatomic, readwrite, copy, null_resettable) NSString *fileName;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/SourceContext.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/SourceContext.pbobjc.m
new file mode 100644
index 0000000000..83bfa3460b
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/SourceContext.pbobjc.m
@@ -0,0 +1,96 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/source_context.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/SourceContext.pbobjc.h>
+#else
+ #import "google/protobuf/SourceContext.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBSourceContextRoot
+
+@implementation GPBSourceContextRoot
+
+// No extensions in the file and no imports, so no need to generate
+// +extensionRegistry.
+
+@end
+
+#pragma mark - GPBSourceContextRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBSourceContextRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - GPBSourceContext
+
+@implementation GPBSourceContext
+
+@dynamic fileName;
+
+typedef struct GPBSourceContext__storage_ {
+ uint32_t _has_storage_[1];
+ NSString *fileName;
+} GPBSourceContext__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "fileName",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBSourceContext_FieldNumber_FileName,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBSourceContext__storage_, fileName),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBSourceContext class]
+ rootClass:[GPBSourceContextRoot class]
+ file:GPBSourceContextRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBSourceContext__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Struct.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/Struct.pbobjc.h
new file mode 100644
index 0000000000..3fc80caa5a
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Struct.pbobjc.h
@@ -0,0 +1,200 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/struct.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+@class GPBListValue;
+@class GPBStruct;
+@class GPBValue;
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - Enum GPBNullValue
+
+/**
+ * `NullValue` is a singleton enumeration to represent the null value for the
+ * `Value` type union.
+ *
+ * The JSON representation for `NullValue` is JSON `null`.
+ **/
+typedef GPB_ENUM(GPBNullValue) {
+ /**
+ * Value used if any message's field encounters a value that is not defined
+ * by this enum. The message will also have C functions to get/set the rawValue
+ * of the field.
+ **/
+ GPBNullValue_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue,
+ /** Null value. */
+ GPBNullValue_NullValue = 0,
+};
+
+GPBEnumDescriptor *GPBNullValue_EnumDescriptor(void);
+
+/**
+ * Checks to see if the given value is defined by the enum or was not known at
+ * the time this source was generated.
+ **/
+BOOL GPBNullValue_IsValidValue(int32_t value);
+
+#pragma mark - GPBStructRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBStructRoot : GPBRootObject
+@end
+
+#pragma mark - GPBStruct
+
+typedef GPB_ENUM(GPBStruct_FieldNumber) {
+ GPBStruct_FieldNumber_Fields = 1,
+};
+
+/**
+ * `Struct` represents a structured data value, consisting of fields
+ * which map to dynamically typed values. In some languages, `Struct`
+ * might be supported by a native representation. For example, in
+ * scripting languages like JS a struct is represented as an
+ * object. The details of that representation are described together
+ * with the proto support for the language.
+ *
+ * The JSON representation for `Struct` is JSON object.
+ **/
+@interface GPBStruct : GPBMessage
+
+/** Unordered map of dynamically typed values. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableDictionary<NSString*, GPBValue*> *fields;
+/** The number of items in @c fields without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger fields_Count;
+
+@end
+
+#pragma mark - GPBValue
+
+typedef GPB_ENUM(GPBValue_FieldNumber) {
+ GPBValue_FieldNumber_NullValue = 1,
+ GPBValue_FieldNumber_NumberValue = 2,
+ GPBValue_FieldNumber_StringValue = 3,
+ GPBValue_FieldNumber_BoolValue = 4,
+ GPBValue_FieldNumber_StructValue = 5,
+ GPBValue_FieldNumber_ListValue = 6,
+};
+
+typedef GPB_ENUM(GPBValue_Kind_OneOfCase) {
+ GPBValue_Kind_OneOfCase_GPBUnsetOneOfCase = 0,
+ GPBValue_Kind_OneOfCase_NullValue = 1,
+ GPBValue_Kind_OneOfCase_NumberValue = 2,
+ GPBValue_Kind_OneOfCase_StringValue = 3,
+ GPBValue_Kind_OneOfCase_BoolValue = 4,
+ GPBValue_Kind_OneOfCase_StructValue = 5,
+ GPBValue_Kind_OneOfCase_ListValue = 6,
+};
+
+/**
+ * `Value` represents a dynamically typed value which can be either
+ * null, a number, a string, a boolean, a recursive struct value, or a
+ * list of values. A producer of value is expected to set one of that
+ * variants, absence of any variant indicates an error.
+ *
+ * The JSON representation for `Value` is JSON value.
+ **/
+@interface GPBValue : GPBMessage
+
+/** The kind of value. */
+@property(nonatomic, readonly) GPBValue_Kind_OneOfCase kindOneOfCase;
+
+/** Represents a null value. */
+@property(nonatomic, readwrite) GPBNullValue nullValue;
+
+/** Represents a double value. */
+@property(nonatomic, readwrite) double numberValue;
+
+/** Represents a string value. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *stringValue;
+
+/** Represents a boolean value. */
+@property(nonatomic, readwrite) BOOL boolValue;
+
+/** Represents a structured value. */
+@property(nonatomic, readwrite, strong, null_resettable) GPBStruct *structValue;
+
+/** Represents a repeated `Value`. */
+@property(nonatomic, readwrite, strong, null_resettable) GPBListValue *listValue;
+
+@end
+
+/**
+ * Fetches the raw value of a @c GPBValue's @c nullValue property, even
+ * if the value was not defined by the enum at the time the code was generated.
+ **/
+int32_t GPBValue_NullValue_RawValue(GPBValue *message);
+/**
+ * Sets the raw value of an @c GPBValue's @c nullValue property, allowing
+ * it to be set to a value that was not defined by the enum at the time the code
+ * was generated.
+ **/
+void SetGPBValue_NullValue_RawValue(GPBValue *message, int32_t value);
+
+/**
+ * Clears whatever value was set for the oneof 'kind'.
+ **/
+void GPBValue_ClearKindOneOfCase(GPBValue *message);
+
+#pragma mark - GPBListValue
+
+typedef GPB_ENUM(GPBListValue_FieldNumber) {
+ GPBListValue_FieldNumber_ValuesArray = 1,
+};
+
+/**
+ * `ListValue` is a wrapper around a repeated field of values.
+ *
+ * The JSON representation for `ListValue` is JSON array.
+ **/
+@interface GPBListValue : GPBMessage
+
+/** Repeated field of dynamically typed values. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBValue*> *valuesArray;
+/** The number of items in @c valuesArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger valuesArray_Count;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Struct.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/Struct.pbobjc.m
new file mode 100644
index 0000000000..f36ec582f9
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Struct.pbobjc.m
@@ -0,0 +1,293 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/struct.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Struct.pbobjc.h>
+#else
+ #import "google/protobuf/Struct.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#pragma clang diagnostic ignored "-Wdirect-ivar-access"
+
+#pragma mark - GPBStructRoot
+
+@implementation GPBStructRoot
+
+// No extensions in the file and no imports, so no need to generate
+// +extensionRegistry.
+
+@end
+
+#pragma mark - GPBStructRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBStructRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - Enum GPBNullValue
+
+GPBEnumDescriptor *GPBNullValue_EnumDescriptor(void) {
+ static GPBEnumDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ static const char *valueNames =
+ "NullValue\000";
+ static const int32_t values[] = {
+ GPBNullValue_NullValue,
+ };
+ GPBEnumDescriptor *worker =
+ [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol(GPBNullValue)
+ valueNames:valueNames
+ values:values
+ count:(uint32_t)(sizeof(values) / sizeof(int32_t))
+ enumVerifier:GPBNullValue_IsValidValue];
+ if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) {
+ [worker release];
+ }
+ }
+ return descriptor;
+}
+
+BOOL GPBNullValue_IsValidValue(int32_t value__) {
+ switch (value__) {
+ case GPBNullValue_NullValue:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+#pragma mark - GPBStruct
+
+@implementation GPBStruct
+
+@dynamic fields, fields_Count;
+
+typedef struct GPBStruct__storage_ {
+ uint32_t _has_storage_[1];
+ NSMutableDictionary *fields;
+} GPBStruct__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "fields",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBValue),
+ .number = GPBStruct_FieldNumber_Fields,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBStruct__storage_, fields),
+ .flags = GPBFieldMapKeyString,
+ .dataType = GPBDataTypeMessage,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBStruct class]
+ rootClass:[GPBStructRoot class]
+ file:GPBStructRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBStruct__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBValue
+
+@implementation GPBValue
+
+@dynamic kindOneOfCase;
+@dynamic nullValue;
+@dynamic numberValue;
+@dynamic stringValue;
+@dynamic boolValue;
+@dynamic structValue;
+@dynamic listValue;
+
+typedef struct GPBValue__storage_ {
+ uint32_t _has_storage_[2];
+ GPBNullValue nullValue;
+ NSString *stringValue;
+ GPBStruct *structValue;
+ GPBListValue *listValue;
+ double numberValue;
+} GPBValue__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "nullValue",
+ .dataTypeSpecific.enumDescFunc = GPBNullValue_EnumDescriptor,
+ .number = GPBValue_FieldNumber_NullValue,
+ .hasIndex = -1,
+ .offset = (uint32_t)offsetof(GPBValue__storage_, nullValue),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldHasEnumDescriptor),
+ .dataType = GPBDataTypeEnum,
+ },
+ {
+ .name = "numberValue",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBValue_FieldNumber_NumberValue,
+ .hasIndex = -1,
+ .offset = (uint32_t)offsetof(GPBValue__storage_, numberValue),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeDouble,
+ },
+ {
+ .name = "stringValue",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBValue_FieldNumber_StringValue,
+ .hasIndex = -1,
+ .offset = (uint32_t)offsetof(GPBValue__storage_, stringValue),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "boolValue",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBValue_FieldNumber_BoolValue,
+ .hasIndex = -1,
+ .offset = 0, // Stored in _has_storage_ to save space.
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeBool,
+ },
+ {
+ .name = "structValue",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBStruct),
+ .number = GPBValue_FieldNumber_StructValue,
+ .hasIndex = -1,
+ .offset = (uint32_t)offsetof(GPBValue__storage_, structValue),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "listValue",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBListValue),
+ .number = GPBValue_FieldNumber_ListValue,
+ .hasIndex = -1,
+ .offset = (uint32_t)offsetof(GPBValue__storage_, listValue),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeMessage,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBValue class]
+ rootClass:[GPBStructRoot class]
+ file:GPBStructRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBValue__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ static const char *oneofs[] = {
+ "kind",
+ };
+ [localDescriptor setupOneofs:oneofs
+ count:(uint32_t)(sizeof(oneofs) / sizeof(char*))
+ firstHasIndex:-1];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+int32_t GPBValue_NullValue_RawValue(GPBValue *message) {
+ GPBDescriptor *descriptor = [GPBValue descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBValue_FieldNumber_NullValue];
+ return GPBGetMessageInt32Field(message, field);
+}
+
+void SetGPBValue_NullValue_RawValue(GPBValue *message, int32_t value) {
+ GPBDescriptor *descriptor = [GPBValue descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBValue_FieldNumber_NullValue];
+ GPBSetInt32IvarWithFieldInternal(message, field, value, descriptor.file.syntax);
+}
+
+void GPBValue_ClearKindOneOfCase(GPBValue *message) {
+ GPBDescriptor *descriptor = [message descriptor];
+ GPBOneofDescriptor *oneof = [descriptor.oneofs objectAtIndex:0];
+ GPBMaybeClearOneof(message, oneof, -1, 0);
+}
+#pragma mark - GPBListValue
+
+@implementation GPBListValue
+
+@dynamic valuesArray, valuesArray_Count;
+
+typedef struct GPBListValue__storage_ {
+ uint32_t _has_storage_[1];
+ NSMutableArray *valuesArray;
+} GPBListValue__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "valuesArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBValue),
+ .number = GPBListValue_FieldNumber_ValuesArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBListValue__storage_, valuesArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBListValue class]
+ rootClass:[GPBStructRoot class]
+ file:GPBStructRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBListValue__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Timestamp.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/Timestamp.pbobjc.h
new file mode 100644
index 0000000000..9c83d0945e
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Timestamp.pbobjc.h
@@ -0,0 +1,132 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/timestamp.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - GPBTimestampRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBTimestampRoot : GPBRootObject
+@end
+
+#pragma mark - GPBTimestamp
+
+typedef GPB_ENUM(GPBTimestamp_FieldNumber) {
+ GPBTimestamp_FieldNumber_Seconds = 1,
+ GPBTimestamp_FieldNumber_Nanos = 2,
+};
+
+/**
+ * A Timestamp represents a point in time independent of any time zone
+ * or calendar, represented as seconds and fractions of seconds at
+ * nanosecond resolution in UTC Epoch time. It is encoded using the
+ * Proleptic Gregorian Calendar which extends the Gregorian calendar
+ * backwards to year one. It is encoded assuming all minutes are 60
+ * seconds long, i.e. leap seconds are "smeared" so that no leap second
+ * table is needed for interpretation. Range is from
+ * 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.
+ * By restricting to that range, we ensure that we can convert to
+ * and from RFC 3339 date strings.
+ * See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt).
+ *
+ * Example 1: Compute Timestamp from POSIX `time()`.
+ *
+ * Timestamp timestamp;
+ * timestamp.set_seconds(time(NULL));
+ * timestamp.set_nanos(0);
+ *
+ * Example 2: Compute Timestamp from POSIX `gettimeofday()`.
+ *
+ * struct timeval tv;
+ * gettimeofday(&tv, NULL);
+ *
+ * Timestamp timestamp;
+ * timestamp.set_seconds(tv.tv_sec);
+ * timestamp.set_nanos(tv.tv_usec * 1000);
+ *
+ * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
+ *
+ * FILETIME ft;
+ * GetSystemTimeAsFileTime(&ft);
+ * UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
+ *
+ * // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
+ * // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
+ * Timestamp timestamp;
+ * timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
+ * timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
+ *
+ * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
+ *
+ * long millis = System.currentTimeMillis();
+ *
+ * Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
+ * .setNanos((int) ((millis % 1000) * 1000000)).build();
+ *
+ *
+ * Example 5: Compute Timestamp from current time in Python.
+ *
+ * timestamp = Timestamp()
+ * timestamp.GetCurrentTime()
+ **/
+@interface GPBTimestamp : GPBMessage
+
+/**
+ * Represents seconds of UTC time since Unix epoch
+ * 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;
+
+/**
+ * Non-negative fractions of a second at nanosecond resolution. Negative
+ * second values with fractions must still have non-negative nanos values
+ * that count forward in time. Must be from 0 to 999,999,999
+ * inclusive.
+ **/
+@property(nonatomic, readwrite) int32_t nanos;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Timestamp.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/Timestamp.pbobjc.m
new file mode 100644
index 0000000000..4ab159fb9c
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Timestamp.pbobjc.m
@@ -0,0 +1,107 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/timestamp.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Timestamp.pbobjc.h>
+#else
+ #import "google/protobuf/Timestamp.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBTimestampRoot
+
+@implementation GPBTimestampRoot
+
+// No extensions in the file and no imports, so no need to generate
+// +extensionRegistry.
+
+@end
+
+#pragma mark - GPBTimestampRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBTimestampRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - GPBTimestamp
+
+@implementation GPBTimestamp
+
+@dynamic seconds;
+@dynamic nanos;
+
+typedef struct GPBTimestamp__storage_ {
+ uint32_t _has_storage_[1];
+ int32_t nanos;
+ int64_t seconds;
+} GPBTimestamp__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "seconds",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBTimestamp_FieldNumber_Seconds,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBTimestamp__storage_, seconds),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt64,
+ },
+ {
+ .name = "nanos",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBTimestamp_FieldNumber_Nanos,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBTimestamp__storage_, nanos),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt32,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBTimestamp class]
+ rootClass:[GPBTimestampRoot class]
+ file:GPBTimestampRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBTimestamp__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Type.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/Type.pbobjc.h
new file mode 100644
index 0000000000..1798697080
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Type.pbobjc.h
@@ -0,0 +1,440 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/type.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+@class GPBAny;
+@class GPBEnumValue;
+@class GPBField;
+@class GPBOption;
+@class GPBSourceContext;
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - Enum GPBSyntax
+
+/** The syntax in which a protocol buffer element is defined. */
+typedef GPB_ENUM(GPBSyntax) {
+ /**
+ * Value used if any message's field encounters a value that is not defined
+ * by this enum. The message will also have C functions to get/set the rawValue
+ * of the field.
+ **/
+ GPBSyntax_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue,
+ /** Syntax `proto2`. */
+ GPBSyntax_SyntaxProto2 = 0,
+
+ /** Syntax `proto3`. */
+ GPBSyntax_SyntaxProto3 = 1,
+};
+
+GPBEnumDescriptor *GPBSyntax_EnumDescriptor(void);
+
+/**
+ * Checks to see if the given value is defined by the enum or was not known at
+ * the time this source was generated.
+ **/
+BOOL GPBSyntax_IsValidValue(int32_t value);
+
+#pragma mark - Enum GPBField_Kind
+
+/** Basic field types. */
+typedef GPB_ENUM(GPBField_Kind) {
+ /**
+ * Value used if any message's field encounters a value that is not defined
+ * by this enum. The message will also have C functions to get/set the rawValue
+ * of the field.
+ **/
+ GPBField_Kind_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue,
+ /** Field type unknown. */
+ GPBField_Kind_TypeUnknown = 0,
+
+ /** Field type double. */
+ GPBField_Kind_TypeDouble = 1,
+
+ /** Field type float. */
+ GPBField_Kind_TypeFloat = 2,
+
+ /** Field type int64. */
+ GPBField_Kind_TypeInt64 = 3,
+
+ /** Field type uint64. */
+ GPBField_Kind_TypeUint64 = 4,
+
+ /** Field type int32. */
+ GPBField_Kind_TypeInt32 = 5,
+
+ /** Field type fixed64. */
+ GPBField_Kind_TypeFixed64 = 6,
+
+ /** Field type fixed32. */
+ GPBField_Kind_TypeFixed32 = 7,
+
+ /** Field type bool. */
+ GPBField_Kind_TypeBool = 8,
+
+ /** Field type string. */
+ GPBField_Kind_TypeString = 9,
+
+ /** Field type group. Proto2 syntax only, and deprecated. */
+ GPBField_Kind_TypeGroup = 10,
+
+ /** Field type message. */
+ GPBField_Kind_TypeMessage = 11,
+
+ /** Field type bytes. */
+ GPBField_Kind_TypeBytes = 12,
+
+ /** Field type uint32. */
+ GPBField_Kind_TypeUint32 = 13,
+
+ /** Field type enum. */
+ GPBField_Kind_TypeEnum = 14,
+
+ /** Field type sfixed32. */
+ GPBField_Kind_TypeSfixed32 = 15,
+
+ /** Field type sfixed64. */
+ GPBField_Kind_TypeSfixed64 = 16,
+
+ /** Field type sint32. */
+ GPBField_Kind_TypeSint32 = 17,
+
+ /** Field type sint64. */
+ GPBField_Kind_TypeSint64 = 18,
+};
+
+GPBEnumDescriptor *GPBField_Kind_EnumDescriptor(void);
+
+/**
+ * Checks to see if the given value is defined by the enum or was not known at
+ * the time this source was generated.
+ **/
+BOOL GPBField_Kind_IsValidValue(int32_t value);
+
+#pragma mark - Enum GPBField_Cardinality
+
+/** Whether a field is optional, required, or repeated. */
+typedef GPB_ENUM(GPBField_Cardinality) {
+ /**
+ * Value used if any message's field encounters a value that is not defined
+ * by this enum. The message will also have C functions to get/set the rawValue
+ * of the field.
+ **/
+ GPBField_Cardinality_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue,
+ /** For fields with unknown cardinality. */
+ GPBField_Cardinality_CardinalityUnknown = 0,
+
+ /** For optional fields. */
+ GPBField_Cardinality_CardinalityOptional = 1,
+
+ /** For required fields. Proto2 syntax only. */
+ GPBField_Cardinality_CardinalityRequired = 2,
+
+ /** For repeated fields. */
+ GPBField_Cardinality_CardinalityRepeated = 3,
+};
+
+GPBEnumDescriptor *GPBField_Cardinality_EnumDescriptor(void);
+
+/**
+ * Checks to see if the given value is defined by the enum or was not known at
+ * the time this source was generated.
+ **/
+BOOL GPBField_Cardinality_IsValidValue(int32_t value);
+
+#pragma mark - GPBTypeRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBTypeRoot : GPBRootObject
+@end
+
+#pragma mark - GPBType
+
+typedef GPB_ENUM(GPBType_FieldNumber) {
+ GPBType_FieldNumber_Name = 1,
+ GPBType_FieldNumber_FieldsArray = 2,
+ GPBType_FieldNumber_OneofsArray = 3,
+ GPBType_FieldNumber_OptionsArray = 4,
+ GPBType_FieldNumber_SourceContext = 5,
+ GPBType_FieldNumber_Syntax = 6,
+};
+
+/**
+ * A protocol buffer message type.
+ **/
+@interface GPBType : GPBMessage
+
+/** The fully qualified message name. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
+
+/** The list of fields. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBField*> *fieldsArray;
+/** The number of items in @c fieldsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger fieldsArray_Count;
+
+/** The list of types appearing in `oneof` definitions in this type. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<NSString*> *oneofsArray;
+/** The number of items in @c oneofsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger oneofsArray_Count;
+
+/** The protocol buffer options. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray;
+/** The number of items in @c optionsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger optionsArray_Count;
+
+/** The source context. */
+@property(nonatomic, readwrite, strong, null_resettable) GPBSourceContext *sourceContext;
+/** Test to see if @c sourceContext has been set. */
+@property(nonatomic, readwrite) BOOL hasSourceContext;
+
+/** The source syntax. */
+@property(nonatomic, readwrite) GPBSyntax syntax;
+
+@end
+
+/**
+ * Fetches the raw value of a @c GPBType's @c syntax property, even
+ * if the value was not defined by the enum at the time the code was generated.
+ **/
+int32_t GPBType_Syntax_RawValue(GPBType *message);
+/**
+ * Sets the raw value of an @c GPBType's @c syntax property, allowing
+ * it to be set to a value that was not defined by the enum at the time the code
+ * was generated.
+ **/
+void SetGPBType_Syntax_RawValue(GPBType *message, int32_t value);
+
+#pragma mark - GPBField
+
+typedef GPB_ENUM(GPBField_FieldNumber) {
+ GPBField_FieldNumber_Kind = 1,
+ GPBField_FieldNumber_Cardinality = 2,
+ GPBField_FieldNumber_Number = 3,
+ GPBField_FieldNumber_Name = 4,
+ GPBField_FieldNumber_TypeURL = 6,
+ GPBField_FieldNumber_OneofIndex = 7,
+ GPBField_FieldNumber_Packed = 8,
+ GPBField_FieldNumber_OptionsArray = 9,
+ GPBField_FieldNumber_JsonName = 10,
+ GPBField_FieldNumber_DefaultValue = 11,
+};
+
+/**
+ * A single field of a message type.
+ **/
+@interface GPBField : GPBMessage
+
+/** The field type. */
+@property(nonatomic, readwrite) GPBField_Kind kind;
+
+/** The field cardinality. */
+@property(nonatomic, readwrite) GPBField_Cardinality cardinality;
+
+/** The field number. */
+@property(nonatomic, readwrite) int32_t number;
+
+/** The field name. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
+
+/**
+ * The field type URL, without the scheme, for message or enumeration
+ * types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`.
+ **/
+@property(nonatomic, readwrite, copy, null_resettable) NSString *typeURL;
+
+/**
+ * The index of the field type in `Type.oneofs`, for message or enumeration
+ * types. The first type has index 1; zero means the type is not in the list.
+ **/
+@property(nonatomic, readwrite) int32_t oneofIndex;
+
+/** Whether to use alternative packed wire representation. */
+@property(nonatomic, readwrite) BOOL packed;
+
+/** The protocol buffer options. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray;
+/** The number of items in @c optionsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger optionsArray_Count;
+
+/** The field JSON name. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *jsonName;
+
+/** The string value of the default value of this field. Proto2 syntax only. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *defaultValue;
+
+@end
+
+/**
+ * Fetches the raw value of a @c GPBField's @c kind property, even
+ * if the value was not defined by the enum at the time the code was generated.
+ **/
+int32_t GPBField_Kind_RawValue(GPBField *message);
+/**
+ * Sets the raw value of an @c GPBField's @c kind property, allowing
+ * it to be set to a value that was not defined by the enum at the time the code
+ * was generated.
+ **/
+void SetGPBField_Kind_RawValue(GPBField *message, int32_t value);
+
+/**
+ * Fetches the raw value of a @c GPBField's @c cardinality property, even
+ * if the value was not defined by the enum at the time the code was generated.
+ **/
+int32_t GPBField_Cardinality_RawValue(GPBField *message);
+/**
+ * Sets the raw value of an @c GPBField's @c cardinality property, allowing
+ * it to be set to a value that was not defined by the enum at the time the code
+ * was generated.
+ **/
+void SetGPBField_Cardinality_RawValue(GPBField *message, int32_t value);
+
+#pragma mark - GPBEnum
+
+typedef GPB_ENUM(GPBEnum_FieldNumber) {
+ GPBEnum_FieldNumber_Name = 1,
+ GPBEnum_FieldNumber_EnumvalueArray = 2,
+ GPBEnum_FieldNumber_OptionsArray = 3,
+ GPBEnum_FieldNumber_SourceContext = 4,
+ GPBEnum_FieldNumber_Syntax = 5,
+};
+
+/**
+ * Enum type definition.
+ **/
+@interface GPBEnum : GPBMessage
+
+/** Enum type name. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
+
+/** Enum value definitions. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBEnumValue*> *enumvalueArray;
+/** The number of items in @c enumvalueArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger enumvalueArray_Count;
+
+/** Protocol buffer options. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray;
+/** The number of items in @c optionsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger optionsArray_Count;
+
+/** The source context. */
+@property(nonatomic, readwrite, strong, null_resettable) GPBSourceContext *sourceContext;
+/** Test to see if @c sourceContext has been set. */
+@property(nonatomic, readwrite) BOOL hasSourceContext;
+
+/** The source syntax. */
+@property(nonatomic, readwrite) GPBSyntax syntax;
+
+@end
+
+/**
+ * Fetches the raw value of a @c GPBEnum's @c syntax property, even
+ * if the value was not defined by the enum at the time the code was generated.
+ **/
+int32_t GPBEnum_Syntax_RawValue(GPBEnum *message);
+/**
+ * Sets the raw value of an @c GPBEnum's @c syntax property, allowing
+ * it to be set to a value that was not defined by the enum at the time the code
+ * was generated.
+ **/
+void SetGPBEnum_Syntax_RawValue(GPBEnum *message, int32_t value);
+
+#pragma mark - GPBEnumValue
+
+typedef GPB_ENUM(GPBEnumValue_FieldNumber) {
+ GPBEnumValue_FieldNumber_Name = 1,
+ GPBEnumValue_FieldNumber_Number = 2,
+ GPBEnumValue_FieldNumber_OptionsArray = 3,
+};
+
+/**
+ * Enum value definition.
+ **/
+@interface GPBEnumValue : GPBMessage
+
+/** Enum value name. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
+
+/** Enum value number. */
+@property(nonatomic, readwrite) int32_t number;
+
+/** Protocol buffer options. */
+@property(nonatomic, readwrite, strong, null_resettable) NSMutableArray<GPBOption*> *optionsArray;
+/** The number of items in @c optionsArray without causing the array to be created. */
+@property(nonatomic, readonly) NSUInteger optionsArray_Count;
+
+@end
+
+#pragma mark - GPBOption
+
+typedef GPB_ENUM(GPBOption_FieldNumber) {
+ GPBOption_FieldNumber_Name = 1,
+ GPBOption_FieldNumber_Value = 2,
+};
+
+/**
+ * A protocol buffer option, which can be attached to a message, field,
+ * enumeration, etc.
+ **/
+@interface GPBOption : GPBMessage
+
+/**
+ * The option's name. For protobuf built-in options (options defined in
+ * descriptor.proto), this is the short name. For example, `"map_entry"`.
+ * For custom options, it should be the fully-qualified name. For example,
+ * `"google.api.http"`.
+ **/
+@property(nonatomic, readwrite, copy, null_resettable) NSString *name;
+
+/**
+ * The option's value packed in an Any message. If the value is a primitive,
+ * the corresponding wrapper type defined in google/protobuf/wrappers.proto
+ * should be used. If the value is an enum, it should be stored as an int32
+ * value using the google.protobuf.Int32Value type.
+ **/
+@property(nonatomic, readwrite, strong, null_resettable) GPBAny *value;
+/** Test to see if @c value has been set. */
+@property(nonatomic, readwrite) BOOL hasValue;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Type.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/Type.pbobjc.m
new file mode 100644
index 0000000000..7a949388f8
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Type.pbobjc.m
@@ -0,0 +1,701 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/type.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Type.pbobjc.h>
+ #import <Protobuf/Any.pbobjc.h>
+ #import <Protobuf/SourceContext.pbobjc.h>
+#else
+ #import "google/protobuf/Type.pbobjc.h"
+ #import "google/protobuf/Any.pbobjc.h"
+ #import "google/protobuf/SourceContext.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBTypeRoot
+
+@implementation GPBTypeRoot
+
+// No extensions in the file and none of the imports (direct or indirect)
+// defined extensions, so no need to generate +extensionRegistry.
+
+@end
+
+#pragma mark - GPBTypeRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBTypeRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - Enum GPBSyntax
+
+GPBEnumDescriptor *GPBSyntax_EnumDescriptor(void) {
+ static GPBEnumDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ static const char *valueNames =
+ "SyntaxProto2\000SyntaxProto3\000";
+ static const int32_t values[] = {
+ GPBSyntax_SyntaxProto2,
+ GPBSyntax_SyntaxProto3,
+ };
+ GPBEnumDescriptor *worker =
+ [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol(GPBSyntax)
+ valueNames:valueNames
+ values:values
+ count:(uint32_t)(sizeof(values) / sizeof(int32_t))
+ enumVerifier:GPBSyntax_IsValidValue];
+ if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) {
+ [worker release];
+ }
+ }
+ return descriptor;
+}
+
+BOOL GPBSyntax_IsValidValue(int32_t value__) {
+ switch (value__) {
+ case GPBSyntax_SyntaxProto2:
+ case GPBSyntax_SyntaxProto3:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+#pragma mark - GPBType
+
+@implementation GPBType
+
+@dynamic name;
+@dynamic fieldsArray, fieldsArray_Count;
+@dynamic oneofsArray, oneofsArray_Count;
+@dynamic optionsArray, optionsArray_Count;
+@dynamic hasSourceContext, sourceContext;
+@dynamic syntax;
+
+typedef struct GPBType__storage_ {
+ uint32_t _has_storage_[1];
+ GPBSyntax syntax;
+ NSString *name;
+ NSMutableArray *fieldsArray;
+ NSMutableArray *oneofsArray;
+ NSMutableArray *optionsArray;
+ GPBSourceContext *sourceContext;
+} GPBType__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "name",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBType_FieldNumber_Name,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBType__storage_, name),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "fieldsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBField),
+ .number = GPBType_FieldNumber_FieldsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBType__storage_, fieldsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "oneofsArray",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBType_FieldNumber_OneofsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBType__storage_, oneofsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "optionsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBOption),
+ .number = GPBType_FieldNumber_OptionsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBType__storage_, optionsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "sourceContext",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBSourceContext),
+ .number = GPBType_FieldNumber_SourceContext,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBType__storage_, sourceContext),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "syntax",
+ .dataTypeSpecific.enumDescFunc = GPBSyntax_EnumDescriptor,
+ .number = GPBType_FieldNumber_Syntax,
+ .hasIndex = 2,
+ .offset = (uint32_t)offsetof(GPBType__storage_, syntax),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldHasEnumDescriptor),
+ .dataType = GPBDataTypeEnum,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBType class]
+ rootClass:[GPBTypeRoot class]
+ file:GPBTypeRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBType__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+int32_t GPBType_Syntax_RawValue(GPBType *message) {
+ GPBDescriptor *descriptor = [GPBType descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBType_FieldNumber_Syntax];
+ return GPBGetMessageInt32Field(message, field);
+}
+
+void SetGPBType_Syntax_RawValue(GPBType *message, int32_t value) {
+ GPBDescriptor *descriptor = [GPBType descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBType_FieldNumber_Syntax];
+ GPBSetInt32IvarWithFieldInternal(message, field, value, descriptor.file.syntax);
+}
+
+#pragma mark - GPBField
+
+@implementation GPBField
+
+@dynamic kind;
+@dynamic cardinality;
+@dynamic number;
+@dynamic name;
+@dynamic typeURL;
+@dynamic oneofIndex;
+@dynamic packed;
+@dynamic optionsArray, optionsArray_Count;
+@dynamic jsonName;
+@dynamic defaultValue;
+
+typedef struct GPBField__storage_ {
+ uint32_t _has_storage_[1];
+ GPBField_Kind kind;
+ GPBField_Cardinality cardinality;
+ int32_t number;
+ int32_t oneofIndex;
+ NSString *name;
+ NSString *typeURL;
+ NSMutableArray *optionsArray;
+ NSString *jsonName;
+ NSString *defaultValue;
+} GPBField__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "kind",
+ .dataTypeSpecific.enumDescFunc = GPBField_Kind_EnumDescriptor,
+ .number = GPBField_FieldNumber_Kind,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBField__storage_, kind),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldHasEnumDescriptor),
+ .dataType = GPBDataTypeEnum,
+ },
+ {
+ .name = "cardinality",
+ .dataTypeSpecific.enumDescFunc = GPBField_Cardinality_EnumDescriptor,
+ .number = GPBField_FieldNumber_Cardinality,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBField__storage_, cardinality),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldHasEnumDescriptor),
+ .dataType = GPBDataTypeEnum,
+ },
+ {
+ .name = "number",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBField_FieldNumber_Number,
+ .hasIndex = 2,
+ .offset = (uint32_t)offsetof(GPBField__storage_, number),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt32,
+ },
+ {
+ .name = "name",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBField_FieldNumber_Name,
+ .hasIndex = 3,
+ .offset = (uint32_t)offsetof(GPBField__storage_, name),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "typeURL",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBField_FieldNumber_TypeURL,
+ .hasIndex = 4,
+ .offset = (uint32_t)offsetof(GPBField__storage_, typeURL),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldTextFormatNameCustom),
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "oneofIndex",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBField_FieldNumber_OneofIndex,
+ .hasIndex = 5,
+ .offset = (uint32_t)offsetof(GPBField__storage_, oneofIndex),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt32,
+ },
+ {
+ .name = "packed",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBField_FieldNumber_Packed,
+ .hasIndex = 6,
+ .offset = 7, // Stored in _has_storage_ to save space.
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeBool,
+ },
+ {
+ .name = "optionsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBOption),
+ .number = GPBField_FieldNumber_OptionsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBField__storage_, optionsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "jsonName",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBField_FieldNumber_JsonName,
+ .hasIndex = 8,
+ .offset = (uint32_t)offsetof(GPBField__storage_, jsonName),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "defaultValue",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBField_FieldNumber_DefaultValue,
+ .hasIndex = 9,
+ .offset = (uint32_t)offsetof(GPBField__storage_, defaultValue),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBField class]
+ rootClass:[GPBTypeRoot class]
+ file:GPBTypeRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBField__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+#if !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
+ static const char *extraTextFormatInfo =
+ "\001\006\004\241!!\000";
+ [localDescriptor setupExtraTextInfo:extraTextFormatInfo];
+#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+int32_t GPBField_Kind_RawValue(GPBField *message) {
+ GPBDescriptor *descriptor = [GPBField descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBField_FieldNumber_Kind];
+ return GPBGetMessageInt32Field(message, field);
+}
+
+void SetGPBField_Kind_RawValue(GPBField *message, int32_t value) {
+ GPBDescriptor *descriptor = [GPBField descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBField_FieldNumber_Kind];
+ GPBSetInt32IvarWithFieldInternal(message, field, value, descriptor.file.syntax);
+}
+
+int32_t GPBField_Cardinality_RawValue(GPBField *message) {
+ GPBDescriptor *descriptor = [GPBField descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBField_FieldNumber_Cardinality];
+ return GPBGetMessageInt32Field(message, field);
+}
+
+void SetGPBField_Cardinality_RawValue(GPBField *message, int32_t value) {
+ GPBDescriptor *descriptor = [GPBField descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBField_FieldNumber_Cardinality];
+ GPBSetInt32IvarWithFieldInternal(message, field, value, descriptor.file.syntax);
+}
+
+#pragma mark - Enum GPBField_Kind
+
+GPBEnumDescriptor *GPBField_Kind_EnumDescriptor(void) {
+ static GPBEnumDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ static const char *valueNames =
+ "TypeUnknown\000TypeDouble\000TypeFloat\000TypeInt"
+ "64\000TypeUint64\000TypeInt32\000TypeFixed64\000Type"
+ "Fixed32\000TypeBool\000TypeString\000TypeGroup\000Ty"
+ "peMessage\000TypeBytes\000TypeUint32\000TypeEnum\000"
+ "TypeSfixed32\000TypeSfixed64\000TypeSint32\000Typ"
+ "eSint64\000";
+ static const int32_t values[] = {
+ GPBField_Kind_TypeUnknown,
+ GPBField_Kind_TypeDouble,
+ GPBField_Kind_TypeFloat,
+ GPBField_Kind_TypeInt64,
+ GPBField_Kind_TypeUint64,
+ GPBField_Kind_TypeInt32,
+ GPBField_Kind_TypeFixed64,
+ GPBField_Kind_TypeFixed32,
+ GPBField_Kind_TypeBool,
+ GPBField_Kind_TypeString,
+ GPBField_Kind_TypeGroup,
+ GPBField_Kind_TypeMessage,
+ GPBField_Kind_TypeBytes,
+ GPBField_Kind_TypeUint32,
+ GPBField_Kind_TypeEnum,
+ GPBField_Kind_TypeSfixed32,
+ GPBField_Kind_TypeSfixed64,
+ GPBField_Kind_TypeSint32,
+ GPBField_Kind_TypeSint64,
+ };
+ GPBEnumDescriptor *worker =
+ [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol(GPBField_Kind)
+ valueNames:valueNames
+ values:values
+ count:(uint32_t)(sizeof(values) / sizeof(int32_t))
+ enumVerifier:GPBField_Kind_IsValidValue];
+ if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) {
+ [worker release];
+ }
+ }
+ return descriptor;
+}
+
+BOOL GPBField_Kind_IsValidValue(int32_t value__) {
+ switch (value__) {
+ case GPBField_Kind_TypeUnknown:
+ case GPBField_Kind_TypeDouble:
+ case GPBField_Kind_TypeFloat:
+ case GPBField_Kind_TypeInt64:
+ case GPBField_Kind_TypeUint64:
+ case GPBField_Kind_TypeInt32:
+ case GPBField_Kind_TypeFixed64:
+ case GPBField_Kind_TypeFixed32:
+ case GPBField_Kind_TypeBool:
+ case GPBField_Kind_TypeString:
+ case GPBField_Kind_TypeGroup:
+ case GPBField_Kind_TypeMessage:
+ case GPBField_Kind_TypeBytes:
+ case GPBField_Kind_TypeUint32:
+ case GPBField_Kind_TypeEnum:
+ case GPBField_Kind_TypeSfixed32:
+ case GPBField_Kind_TypeSfixed64:
+ case GPBField_Kind_TypeSint32:
+ case GPBField_Kind_TypeSint64:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+#pragma mark - Enum GPBField_Cardinality
+
+GPBEnumDescriptor *GPBField_Cardinality_EnumDescriptor(void) {
+ static GPBEnumDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ static const char *valueNames =
+ "CardinalityUnknown\000CardinalityOptional\000C"
+ "ardinalityRequired\000CardinalityRepeated\000";
+ static const int32_t values[] = {
+ GPBField_Cardinality_CardinalityUnknown,
+ GPBField_Cardinality_CardinalityOptional,
+ GPBField_Cardinality_CardinalityRequired,
+ GPBField_Cardinality_CardinalityRepeated,
+ };
+ GPBEnumDescriptor *worker =
+ [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol(GPBField_Cardinality)
+ valueNames:valueNames
+ values:values
+ count:(uint32_t)(sizeof(values) / sizeof(int32_t))
+ enumVerifier:GPBField_Cardinality_IsValidValue];
+ if (!OSAtomicCompareAndSwapPtrBarrier(nil, worker, (void * volatile *)&descriptor)) {
+ [worker release];
+ }
+ }
+ return descriptor;
+}
+
+BOOL GPBField_Cardinality_IsValidValue(int32_t value__) {
+ switch (value__) {
+ case GPBField_Cardinality_CardinalityUnknown:
+ case GPBField_Cardinality_CardinalityOptional:
+ case GPBField_Cardinality_CardinalityRequired:
+ case GPBField_Cardinality_CardinalityRepeated:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+#pragma mark - GPBEnum
+
+@implementation GPBEnum
+
+@dynamic name;
+@dynamic enumvalueArray, enumvalueArray_Count;
+@dynamic optionsArray, optionsArray_Count;
+@dynamic hasSourceContext, sourceContext;
+@dynamic syntax;
+
+typedef struct GPBEnum__storage_ {
+ uint32_t _has_storage_[1];
+ GPBSyntax syntax;
+ NSString *name;
+ NSMutableArray *enumvalueArray;
+ NSMutableArray *optionsArray;
+ GPBSourceContext *sourceContext;
+} GPBEnum__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "name",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBEnum_FieldNumber_Name,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBEnum__storage_, name),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "enumvalueArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBEnumValue),
+ .number = GPBEnum_FieldNumber_EnumvalueArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBEnum__storage_, enumvalueArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "optionsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBOption),
+ .number = GPBEnum_FieldNumber_OptionsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBEnum__storage_, optionsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "sourceContext",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBSourceContext),
+ .number = GPBEnum_FieldNumber_SourceContext,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBEnum__storage_, sourceContext),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeMessage,
+ },
+ {
+ .name = "syntax",
+ .dataTypeSpecific.enumDescFunc = GPBSyntax_EnumDescriptor,
+ .number = GPBEnum_FieldNumber_Syntax,
+ .hasIndex = 2,
+ .offset = (uint32_t)offsetof(GPBEnum__storage_, syntax),
+ .flags = (GPBFieldFlags)(GPBFieldOptional | GPBFieldHasEnumDescriptor),
+ .dataType = GPBDataTypeEnum,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBEnum class]
+ rootClass:[GPBTypeRoot class]
+ file:GPBTypeRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBEnum__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+int32_t GPBEnum_Syntax_RawValue(GPBEnum *message) {
+ GPBDescriptor *descriptor = [GPBEnum descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBEnum_FieldNumber_Syntax];
+ return GPBGetMessageInt32Field(message, field);
+}
+
+void SetGPBEnum_Syntax_RawValue(GPBEnum *message, int32_t value) {
+ GPBDescriptor *descriptor = [GPBEnum descriptor];
+ GPBFieldDescriptor *field = [descriptor fieldWithNumber:GPBEnum_FieldNumber_Syntax];
+ GPBSetInt32IvarWithFieldInternal(message, field, value, descriptor.file.syntax);
+}
+
+#pragma mark - GPBEnumValue
+
+@implementation GPBEnumValue
+
+@dynamic name;
+@dynamic number;
+@dynamic optionsArray, optionsArray_Count;
+
+typedef struct GPBEnumValue__storage_ {
+ uint32_t _has_storage_[1];
+ int32_t number;
+ NSString *name;
+ NSMutableArray *optionsArray;
+} GPBEnumValue__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "name",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBEnumValue_FieldNumber_Name,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBEnumValue__storage_, name),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "number",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBEnumValue_FieldNumber_Number,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBEnumValue__storage_, number),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt32,
+ },
+ {
+ .name = "optionsArray",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBOption),
+ .number = GPBEnumValue_FieldNumber_OptionsArray,
+ .hasIndex = GPBNoHasBit,
+ .offset = (uint32_t)offsetof(GPBEnumValue__storage_, optionsArray),
+ .flags = GPBFieldRepeated,
+ .dataType = GPBDataTypeMessage,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBEnumValue class]
+ rootClass:[GPBTypeRoot class]
+ file:GPBTypeRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBEnumValue__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBOption
+
+@implementation GPBOption
+
+@dynamic name;
+@dynamic hasValue, value;
+
+typedef struct GPBOption__storage_ {
+ uint32_t _has_storage_[1];
+ NSString *name;
+ GPBAny *value;
+} GPBOption__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "name",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBOption_FieldNumber_Name,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBOption__storage_, name),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ {
+ .name = "value",
+ .dataTypeSpecific.className = GPBStringifySymbol(GPBAny),
+ .number = GPBOption_FieldNumber_Value,
+ .hasIndex = 1,
+ .offset = (uint32_t)offsetof(GPBOption__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeMessage,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBOption class]
+ rootClass:[GPBTypeRoot class]
+ file:GPBTypeRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBOption__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Wrappers.pbobjc.h b/third_party/protobuf/objectivec/google/protobuf/Wrappers.pbobjc.h
new file mode 100644
index 0000000000..3cb9fe77dc
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Wrappers.pbobjc.h
@@ -0,0 +1,215 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/wrappers.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers.h>
+#else
+ #import "GPBProtocolBuffers.h"
+#endif
+
+#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002
+#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+#if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION
+#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.
+#endif
+
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+CF_EXTERN_C_BEGIN
+
+NS_ASSUME_NONNULL_BEGIN
+
+#pragma mark - GPBWrappersRoot
+
+/**
+ * Exposes the extension registry for this file.
+ *
+ * The base class provides:
+ * @code
+ * + (GPBExtensionRegistry *)extensionRegistry;
+ * @endcode
+ * which is a @c GPBExtensionRegistry that includes all the extensions defined by
+ * this file and all files that it depends on.
+ **/
+@interface GPBWrappersRoot : GPBRootObject
+@end
+
+#pragma mark - GPBDoubleValue
+
+typedef GPB_ENUM(GPBDoubleValue_FieldNumber) {
+ GPBDoubleValue_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `double`.
+ *
+ * The JSON representation for `DoubleValue` is JSON number.
+ **/
+@interface GPBDoubleValue : GPBMessage
+
+/** The double value. */
+@property(nonatomic, readwrite) double value;
+
+@end
+
+#pragma mark - GPBFloatValue
+
+typedef GPB_ENUM(GPBFloatValue_FieldNumber) {
+ GPBFloatValue_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `float`.
+ *
+ * The JSON representation for `FloatValue` is JSON number.
+ **/
+@interface GPBFloatValue : GPBMessage
+
+/** The float value. */
+@property(nonatomic, readwrite) float value;
+
+@end
+
+#pragma mark - GPBInt64Value
+
+typedef GPB_ENUM(GPBInt64Value_FieldNumber) {
+ GPBInt64Value_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `int64`.
+ *
+ * The JSON representation for `Int64Value` is JSON string.
+ **/
+@interface GPBInt64Value : GPBMessage
+
+/** The int64 value. */
+@property(nonatomic, readwrite) int64_t value;
+
+@end
+
+#pragma mark - GPBUInt64Value
+
+typedef GPB_ENUM(GPBUInt64Value_FieldNumber) {
+ GPBUInt64Value_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `uint64`.
+ *
+ * The JSON representation for `UInt64Value` is JSON string.
+ **/
+@interface GPBUInt64Value : GPBMessage
+
+/** The uint64 value. */
+@property(nonatomic, readwrite) uint64_t value;
+
+@end
+
+#pragma mark - GPBInt32Value
+
+typedef GPB_ENUM(GPBInt32Value_FieldNumber) {
+ GPBInt32Value_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `int32`.
+ *
+ * The JSON representation for `Int32Value` is JSON number.
+ **/
+@interface GPBInt32Value : GPBMessage
+
+/** The int32 value. */
+@property(nonatomic, readwrite) int32_t value;
+
+@end
+
+#pragma mark - GPBUInt32Value
+
+typedef GPB_ENUM(GPBUInt32Value_FieldNumber) {
+ GPBUInt32Value_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `uint32`.
+ *
+ * The JSON representation for `UInt32Value` is JSON number.
+ **/
+@interface GPBUInt32Value : GPBMessage
+
+/** The uint32 value. */
+@property(nonatomic, readwrite) uint32_t value;
+
+@end
+
+#pragma mark - GPBBoolValue
+
+typedef GPB_ENUM(GPBBoolValue_FieldNumber) {
+ GPBBoolValue_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `bool`.
+ *
+ * The JSON representation for `BoolValue` is JSON `true` and `false`.
+ **/
+@interface GPBBoolValue : GPBMessage
+
+/** The bool value. */
+@property(nonatomic, readwrite) BOOL value;
+
+@end
+
+#pragma mark - GPBStringValue
+
+typedef GPB_ENUM(GPBStringValue_FieldNumber) {
+ GPBStringValue_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `string`.
+ *
+ * The JSON representation for `StringValue` is JSON string.
+ **/
+@interface GPBStringValue : GPBMessage
+
+/** The string value. */
+@property(nonatomic, readwrite, copy, null_resettable) NSString *value;
+
+@end
+
+#pragma mark - GPBBytesValue
+
+typedef GPB_ENUM(GPBBytesValue_FieldNumber) {
+ GPBBytesValue_FieldNumber_Value = 1,
+};
+
+/**
+ * Wrapper message for `bytes`.
+ *
+ * The JSON representation for `BytesValue` is JSON string.
+ **/
+@interface GPBBytesValue : GPBMessage
+
+/** The bytes value. */
+@property(nonatomic, readwrite, copy, null_resettable) NSData *value;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+CF_EXTERN_C_END
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/objectivec/google/protobuf/Wrappers.pbobjc.m b/third_party/protobuf/objectivec/google/protobuf/Wrappers.pbobjc.m
new file mode 100644
index 0000000000..5479eb127b
--- /dev/null
+++ b/third_party/protobuf/objectivec/google/protobuf/Wrappers.pbobjc.m
@@ -0,0 +1,439 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: google/protobuf/wrappers.proto
+
+// This CPP symbol can be defined to use imports that match up to the framework
+// imports needed when using CocoaPods.
+#if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS)
+ #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/GPBProtocolBuffers_RuntimeSupport.h>
+#else
+ #import "GPBProtocolBuffers_RuntimeSupport.h"
+#endif
+
+#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS
+ #import <Protobuf/Wrappers.pbobjc.h>
+#else
+ #import "google/protobuf/Wrappers.pbobjc.h"
+#endif
+// @@protoc_insertion_point(imports)
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+
+#pragma mark - GPBWrappersRoot
+
+@implementation GPBWrappersRoot
+
+// No extensions in the file and no imports, so no need to generate
+// +extensionRegistry.
+
+@end
+
+#pragma mark - GPBWrappersRoot_FileDescriptor
+
+static GPBFileDescriptor *GPBWrappersRoot_FileDescriptor(void) {
+ // This is called by +initialize so there is no need to worry
+ // about thread safety of the singleton.
+ static GPBFileDescriptor *descriptor = NULL;
+ if (!descriptor) {
+ GPB_DEBUG_CHECK_RUNTIME_VERSIONS();
+ descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"google.protobuf"
+ objcPrefix:@"GPB"
+ syntax:GPBFileSyntaxProto3];
+ }
+ return descriptor;
+}
+
+#pragma mark - GPBDoubleValue
+
+@implementation GPBDoubleValue
+
+@dynamic value;
+
+typedef struct GPBDoubleValue__storage_ {
+ uint32_t _has_storage_[1];
+ double value;
+} GPBDoubleValue__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBDoubleValue_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBDoubleValue__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeDouble,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBDoubleValue class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBDoubleValue__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBFloatValue
+
+@implementation GPBFloatValue
+
+@dynamic value;
+
+typedef struct GPBFloatValue__storage_ {
+ uint32_t _has_storage_[1];
+ float value;
+} GPBFloatValue__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBFloatValue_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBFloatValue__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeFloat,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBFloatValue class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBFloatValue__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBInt64Value
+
+@implementation GPBInt64Value
+
+@dynamic value;
+
+typedef struct GPBInt64Value__storage_ {
+ uint32_t _has_storage_[1];
+ int64_t value;
+} GPBInt64Value__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBInt64Value_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBInt64Value__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt64,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBInt64Value class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBInt64Value__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBUInt64Value
+
+@implementation GPBUInt64Value
+
+@dynamic value;
+
+typedef struct GPBUInt64Value__storage_ {
+ uint32_t _has_storage_[1];
+ uint64_t value;
+} GPBUInt64Value__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBUInt64Value_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBUInt64Value__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeUInt64,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBUInt64Value class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBUInt64Value__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBInt32Value
+
+@implementation GPBInt32Value
+
+@dynamic value;
+
+typedef struct GPBInt32Value__storage_ {
+ uint32_t _has_storage_[1];
+ int32_t value;
+} GPBInt32Value__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBInt32Value_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBInt32Value__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeInt32,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBInt32Value class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBInt32Value__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBUInt32Value
+
+@implementation GPBUInt32Value
+
+@dynamic value;
+
+typedef struct GPBUInt32Value__storage_ {
+ uint32_t _has_storage_[1];
+ uint32_t value;
+} GPBUInt32Value__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBUInt32Value_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBUInt32Value__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeUInt32,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBUInt32Value class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBUInt32Value__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBBoolValue
+
+@implementation GPBBoolValue
+
+@dynamic value;
+
+typedef struct GPBBoolValue__storage_ {
+ uint32_t _has_storage_[1];
+} GPBBoolValue__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBBoolValue_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = 1, // Stored in _has_storage_ to save space.
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeBool,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBBoolValue class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBBoolValue__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBStringValue
+
+@implementation GPBStringValue
+
+@dynamic value;
+
+typedef struct GPBStringValue__storage_ {
+ uint32_t _has_storage_[1];
+ NSString *value;
+} GPBStringValue__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBStringValue_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBStringValue__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeString,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBStringValue class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBStringValue__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+#pragma mark - GPBBytesValue
+
+@implementation GPBBytesValue
+
+@dynamic value;
+
+typedef struct GPBBytesValue__storage_ {
+ uint32_t _has_storage_[1];
+ NSData *value;
+} GPBBytesValue__storage_;
+
+// This method is threadsafe because it is initially called
+// in +initialize for each subclass.
++ (GPBDescriptor *)descriptor {
+ static GPBDescriptor *descriptor = nil;
+ if (!descriptor) {
+ static GPBMessageFieldDescription fields[] = {
+ {
+ .name = "value",
+ .dataTypeSpecific.className = NULL,
+ .number = GPBBytesValue_FieldNumber_Value,
+ .hasIndex = 0,
+ .offset = (uint32_t)offsetof(GPBBytesValue__storage_, value),
+ .flags = GPBFieldOptional,
+ .dataType = GPBDataTypeBytes,
+ },
+ };
+ GPBDescriptor *localDescriptor =
+ [GPBDescriptor allocDescriptorForClass:[GPBBytesValue class]
+ rootClass:[GPBWrappersRoot class]
+ file:GPBWrappersRoot_FileDescriptor()
+ fields:fields
+ fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
+ storageSize:sizeof(GPBBytesValue__storage_)
+ flags:GPBDescriptorInitializationFlag_None];
+ NSAssert(descriptor == nil, @"Startup recursed!");
+ descriptor = localDescriptor;
+ }
+ return descriptor;
+}
+
+@end
+
+
+#pragma clang diagnostic pop
+
+// @@protoc_insertion_point(global_scope)
diff --git a/third_party/protobuf/php/README.md b/third_party/protobuf/php/README.md
new file mode 100644
index 0000000000..cebeb3e5a2
--- /dev/null
+++ b/third_party/protobuf/php/README.md
@@ -0,0 +1,97 @@
+This directory contains the Protocol Buffers runtime implementation via both a
+pure PHP package and a native c extension. The pure PHP package is intended to
+provide usability to wider range of PHP platforms, while the c extension is
+intended to provide higher performance. Both implementations provide the same
+runtime APIs and share the same generated code. Users don’t need to re-generate
+code for the same proto definition when they want to switch the implementation
+later.
+
+Both implementations make use of generated PHP code that defines message and
+enum types in PHP. We strongly recommend using protoc's PHP generation support
+with .proto files. The build process in this directory only installs the
+extension/package; you need to install protoc as well to have PHP code
+generation functionality.
+
+## Requirements
+
+To use PHP runtime library requires:
+
+- C extension: PHP 5.5.x or 5.6.x.
+- PHP package: PHP 5.5, 5.6 or 7.
+
+## Installation
+
+### C Extension
+
+#### Prerequirements
+
+To install the c extension, the following tools are needed:
+* autoconf
+* automake
+* libtool
+* make
+* gcc
+* pear
+* pecl
+
+On Ubuntu, you can install them with:
+```
+sudo apt-get install php-pear php5-dev autoconf automake libtool make gcc
+```
+On other platforms, please use the corresponding package managing tool to
+install them before proceeding.
+
+#### Installation from Source (Building extension)
+
+To build the c extension, run the following command:
+```
+cd ext/google/protobuf
+pear package
+sudo pecl install protobuf-{VERSION}.tgz
+```
+
+#### Installation from PECL
+
+When we release a version of Protocol Buffers, we will upload the extension to
+[PECL](https://pecl.php.net/). To use this pre-packaged extension, simply
+install it as you would any other extension:
+
+```
+sudo pecl install protobuf-{VERSION}
+```
+
+### PHP Package
+
+#### Installation from composer
+
+Simply add "google/protobuf" to the 'require' section of composer.json in your
+project.
+
+### Protoc
+
+Once the extension or package is installed, if you wish to generate PHP code
+from a `.proto` file, you will also want to install the Protocol Buffers
+compiler (protoc), as described in this repository's main `README` file. The
+version of `protoc` included in the latest release supports the `--php_out`
+option to generate PHP code:
+```
+protoc --php_out=out_dir test.proto
+```
+
+## Usage
+
+For generated code:
+ https://developers.google.com/protocol-buffers/docs/reference/php-generated
+
+Known Issues
+------------
+
+* Missing native support for well known types.
+* Missing support for proto2.
+* No API provided for clear/copy messages.
+* No API provided for encoding/decoding with stream.
+* Map fields may not be garbage-collected if there is cycle reference.
+* No debug information for messages in c extension.
+* HHVM not tested.
+* C extension not tested on windows, mac, php 7.0.
+* Message name cannot be Empty.
diff --git a/third_party/protobuf/php/composer.json b/third_party/protobuf/php/composer.json
new file mode 100644
index 0000000000..32b0f44c1b
--- /dev/null
+++ b/third_party/protobuf/php/composer.json
@@ -0,0 +1,28 @@
+{
+ "name": "google/protobuf",
+ "type": "library",
+ "description": "proto library for PHP",
+ "keywords": ["proto"],
+ "homepage": "https://developers.google.com/protocol-buffers/",
+ "license": "BSD-3-Clause",
+ "require": {
+ "php": ">=5.5.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": ">=4.8.0"
+ },
+ "autoload": {
+ "psr-4": {
+ "Foo\\": "tests/generated/Foo",
+ "Bar\\": "tests/generated/Bar",
+ "Google\\Protobuf\\": "tests/generated/Google/Protobuf",
+ "Google\\Protobuf\\Internal\\": "src/Google/Protobuf/Internal",
+ "GPBMetadata\\": "tests/generated/GPBMetadata",
+ "GPBMetadata\\Google\\Protobuf\\Internal\\": "src/GPBMetadata/Google/Protobuf/Internal",
+ "": "tests/generated"
+ },
+ "files": [
+ "src/Google/Protobuf/descriptor.php"
+ ]
+ }
+}
diff --git a/third_party/protobuf/php/ext/google/protobuf/array.c b/third_party/protobuf/php/ext/google/protobuf/array.c
new file mode 100644
index 0000000000..2186ab1f5d
--- /dev/null
+++ b/third_party/protobuf/php/ext/google/protobuf/array.c
@@ -0,0 +1,516 @@
+// 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 <ext/spl/spl_iterators.h>
+#include <Zend/zend_API.h>
+#include <Zend/zend_interfaces.h>
+
+#include "protobuf.h"
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1)
+ ZEND_ARG_INFO(0, index)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2)
+ ZEND_ARG_INFO(0, index)
+ ZEND_ARG_INFO(0, newval)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
+ZEND_END_ARG_INFO()
+
+static zend_function_entry repeated_field_methods[] = {
+ PHP_ME(RepeatedField, __construct, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedField, append, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedField, count, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedField, getIterator, arginfo_void, ZEND_ACC_PUBLIC)
+ ZEND_FE_END
+};
+
+static zend_function_entry repeated_field_iter_methods[] = {
+ PHP_ME(RepeatedFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC)
+ ZEND_FE_END
+};
+
+// Forward declare static functions.
+
+static zend_object_value repeated_field_create(zend_class_entry *ce TSRMLS_DC);
+static void repeated_field_free(void *object TSRMLS_DC);
+static int repeated_field_array_init(zval *array, upb_fieldtype_t type,
+ uint size ZEND_FILE_LINE_DC);
+static void repeated_field_free_element(void *object);
+static void repeated_field_write_dimension(zval *object, zval *offset,
+ zval *value TSRMLS_DC);
+static int repeated_field_has_dimension(zval *object, zval *offset TSRMLS_DC);
+static HashTable *repeated_field_get_gc(zval *object, zval ***table,
+ int *n TSRMLS_DC);
+
+static zend_object_value repeated_field_iter_create(zend_class_entry *ce TSRMLS_DC);
+static void repeated_field_iter_free(void *object TSRMLS_DC);
+
+// -----------------------------------------------------------------------------
+// RepeatedField creation/desctruction
+// -----------------------------------------------------------------------------
+
+zend_class_entry* repeated_field_type;
+zend_class_entry* repeated_field_iter_type;
+zend_object_handlers* repeated_field_handlers;
+
+void repeated_field_init(TSRMLS_D) {
+ zend_class_entry class_type;
+ const char* class_name = "Google\\Protobuf\\Internal\\RepeatedField";
+ INIT_CLASS_ENTRY_EX(class_type, class_name, strlen(class_name),
+ repeated_field_methods);
+
+ repeated_field_type = zend_register_internal_class(&class_type TSRMLS_CC);
+ repeated_field_type->create_object = repeated_field_create;
+
+ zend_class_implements(repeated_field_type TSRMLS_CC, 3, spl_ce_ArrayAccess,
+ zend_ce_aggregate, spl_ce_Countable);
+
+ repeated_field_handlers = PEMALLOC(zend_object_handlers);
+ memcpy(repeated_field_handlers, zend_get_std_object_handlers(),
+ sizeof(zend_object_handlers));
+ repeated_field_handlers->write_dimension = repeated_field_write_dimension;
+ repeated_field_handlers->get_gc = repeated_field_get_gc;
+}
+
+static zend_object_value repeated_field_create(zend_class_entry *ce TSRMLS_DC) {
+ zend_object_value retval = {0};
+ RepeatedField *intern;
+
+ intern = emalloc(sizeof(RepeatedField));
+ memset(intern, 0, sizeof(RepeatedField));
+
+ zend_object_std_init(&intern->std, ce TSRMLS_CC);
+ object_properties_init(&intern->std, ce);
+
+ intern->array = NULL;
+ intern->type = 0;
+ intern->msg_ce = NULL;
+
+ retval.handle = zend_objects_store_put(
+ intern, (zend_objects_store_dtor_t)zend_objects_destroy_object,
+ (zend_objects_free_object_storage_t)repeated_field_free, NULL TSRMLS_CC);
+ retval.handlers = repeated_field_handlers;
+
+ return retval;
+}
+
+static void repeated_field_free(void *object TSRMLS_DC) {
+ RepeatedField *intern = object;
+ zend_object_std_dtor(&intern->std TSRMLS_CC);
+ zval_ptr_dtor(&intern->array);
+ efree(object);
+}
+
+static int repeated_field_array_init(zval *array, upb_fieldtype_t type,
+ uint size ZEND_FILE_LINE_DC) {
+ ALLOC_HASHTABLE(Z_ARRVAL_P(array));
+
+ switch (type) {
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_MESSAGE:
+ zend_hash_init(Z_ARRVAL_P(array), size, NULL, ZVAL_PTR_DTOR, 0);
+ break;
+ default:
+ zend_hash_init(Z_ARRVAL_P(array), size, NULL, repeated_field_free_element,
+ 0);
+ }
+ Z_TYPE_P(array) = IS_ARRAY;
+ return SUCCESS;
+}
+
+static void repeated_field_free_element(void *object) {
+}
+
+// -----------------------------------------------------------------------------
+// RepeatedField Handlers
+// -----------------------------------------------------------------------------
+
+static void repeated_field_write_dimension(zval *object, zval *offset,
+ zval *value TSRMLS_DC) {
+ uint64_t index;
+
+ RepeatedField *intern = zend_object_store_get_object(object TSRMLS_CC);
+ HashTable *ht = HASH_OF(intern->array);
+ int size = native_slot_size(intern->type);
+
+ unsigned char memory[NATIVE_SLOT_MAX_SIZE];
+ memset(memory, 0, NATIVE_SLOT_MAX_SIZE);
+
+ if (!native_slot_set(intern->type, intern->msg_ce, memory, value TSRMLS_CC)) {
+ return;
+ }
+
+ if (!offset || Z_TYPE_P(offset) == IS_NULL) {
+ index = zend_hash_num_elements(HASH_OF(intern->array));
+ } else {
+ if (protobuf_convert_to_uint64(offset, &index)) {
+ if (!zend_hash_index_exists(ht, index)) {
+ zend_error(E_USER_ERROR, "Element at %llu doesn't exist.\n", index);
+ return;
+ }
+ } else {
+ return;
+ }
+ }
+
+ zend_hash_index_update(ht, index, memory, size, NULL);
+}
+
+static HashTable *repeated_field_get_gc(zval *object, zval ***table,
+ int *n TSRMLS_DC) {
+ *table = NULL;
+ *n = 0;
+ RepeatedField *intern = zend_object_store_get_object(object TSRMLS_CC);
+ return HASH_OF(intern->array);
+}
+
+// -----------------------------------------------------------------------------
+// C RepeatedField Utilities
+// -----------------------------------------------------------------------------
+
+void *repeated_field_index_native(RepeatedField *intern, int index TSRMLS_DC) {
+ HashTable *ht = HASH_OF(intern->array);
+ void *value;
+
+ if (zend_hash_index_find(ht, index, (void **)&value) == FAILURE) {
+ zend_error(E_USER_ERROR, "Element at %d doesn't exist.\n", index);
+ return NULL;
+ }
+
+ return value;
+}
+
+void repeated_field_push_native(RepeatedField *intern, void *value TSRMLS_DC) {
+ HashTable *ht = HASH_OF(intern->array);
+ int size = native_slot_size(intern->type);
+ zend_hash_next_index_insert(ht, (void **)value, size, NULL);
+}
+
+void repeated_field_create_with_field(zend_class_entry *ce,
+ const upb_fielddef *field,
+ zval **repeated_field TSRMLS_DC) {
+ upb_fieldtype_t type = upb_fielddef_type(field);
+ const zend_class_entry *msg_ce = field_type_class(field TSRMLS_CC);
+ repeated_field_create_with_type(ce, type, msg_ce, repeated_field TSRMLS_CC);
+}
+
+void repeated_field_create_with_type(zend_class_entry *ce,
+ upb_fieldtype_t type,
+ const zend_class_entry* msg_ce,
+ zval **repeated_field TSRMLS_DC) {
+ MAKE_STD_ZVAL(*repeated_field);
+ Z_TYPE_PP(repeated_field) = IS_OBJECT;
+ Z_OBJVAL_PP(repeated_field) =
+ repeated_field_type->create_object(repeated_field_type TSRMLS_CC);
+
+ RepeatedField *intern =
+ zend_object_store_get_object(*repeated_field TSRMLS_CC);
+ intern->type = type;
+ intern->msg_ce = msg_ce;
+ MAKE_STD_ZVAL(intern->array);
+ repeated_field_array_init(intern->array, intern->type, 0 ZEND_FILE_LINE_CC);
+
+ // TODO(teboring): Link class entry for message and enum
+}
+
+
+// -----------------------------------------------------------------------------
+// PHP RepeatedField Methods
+// -----------------------------------------------------------------------------
+
+/**
+ * Constructs an instance of RepeatedField.
+ * @param long Type of the stored element.
+ * @param string Message/Enum class name (message/enum fields only).
+ */
+PHP_METHOD(RepeatedField, __construct) {
+ long type;
+ zend_class_entry* klass = NULL;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|C", &type, &klass) ==
+ FAILURE) {
+ return;
+ }
+
+ RepeatedField *intern = zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern->type = to_fieldtype(type);
+ intern->msg_ce = klass;
+
+ MAKE_STD_ZVAL(intern->array);
+ repeated_field_array_init(intern->array, intern->type, 0 ZEND_FILE_LINE_CC);
+
+ if (intern->type == UPB_TYPE_MESSAGE && klass == NULL) {
+ zend_error(E_USER_ERROR, "Message type must have concrete class.");
+ return;
+ }
+
+ // TODO(teboring): Consider enum.
+}
+
+/**
+ * Append element to the end of the repeated field.
+ * @param object The element to be added.
+ */
+PHP_METHOD(RepeatedField, append) {
+ zval *value;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) ==
+ FAILURE) {
+ return;
+ }
+ repeated_field_write_dimension(getThis(), NULL, value TSRMLS_CC);
+}
+
+/**
+ * Check whether the element at given index exists.
+ * @param long The index to be checked.
+ * @return bool True if the element at the given index exists.
+ */
+PHP_METHOD(RepeatedField, offsetExists) {
+ long index;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) ==
+ FAILURE) {
+ return;
+ }
+
+ RepeatedField *intern = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ RETURN_BOOL(index >= 0 &&
+ index < zend_hash_num_elements(HASH_OF(intern->array)));
+}
+
+/**
+ * Return the element at the given index.
+ * This will also be called for: $ele = $arr[0]
+ * @param long The index of the element to be fetched.
+ * @return object The stored element at given index.
+ * @exception Invalid type for index.
+ * @exception Non-existing index.
+ */
+PHP_METHOD(RepeatedField, offsetGet) {
+ long index;
+ void *memory;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) ==
+ FAILURE) {
+ return;
+ }
+
+ RepeatedField *intern = zend_object_store_get_object(getThis() TSRMLS_CC);
+ HashTable *table = HASH_OF(intern->array);
+
+ if (zend_hash_index_find(table, index, (void **)&memory) == FAILURE) {
+ zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index);
+ return;
+ }
+
+ native_slot_get(intern->type, memory, return_value_ptr TSRMLS_CC);
+}
+
+/**
+ * Assign the element at the given index.
+ * This will also be called for: $arr []= $ele and $arr[0] = ele
+ * @param long The index of the element to be assigned.
+ * @param object The element to be assigned.
+ * @exception Invalid type for index.
+ * @exception Non-existing index.
+ * @exception Incorrect type of the element.
+ */
+PHP_METHOD(RepeatedField, offsetSet) {
+ zval *index, *value;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &index, &value) ==
+ FAILURE) {
+ return;
+ }
+ repeated_field_write_dimension(getThis(), index, value TSRMLS_CC);
+}
+
+/**
+ * Remove the element at the given index.
+ * This will also be called for: unset($arr)
+ * @param long The index of the element to be removed.
+ * @exception Invalid type for index.
+ * @exception The element to be removed is not at the end of the RepeatedField.
+ */
+PHP_METHOD(RepeatedField, offsetUnset) {
+ long index;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) ==
+ FAILURE) {
+ return;
+ }
+
+ RepeatedField *intern = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ // Only the element at the end of the array can be removed.
+ if (index == -1 ||
+ index != (zend_hash_num_elements(HASH_OF(intern->array)) - 1)) {
+ zend_error(E_USER_ERROR, "Cannot remove element at %ld.\n", index);
+ return;
+ }
+
+ zend_hash_index_del(HASH_OF(intern->array), index);
+}
+
+/**
+ * Return the number of stored elements.
+ * This will also be called for: count($arr)
+ * @return long The number of stored elements.
+ */
+PHP_METHOD(RepeatedField, count) {
+ RepeatedField *intern = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ RETURN_LONG(zend_hash_num_elements(HASH_OF(intern->array)));
+}
+
+/**
+ * Return the beginning iterator.
+ * This will also be called for: foreach($arr)
+ * @return object Beginning iterator.
+ */
+PHP_METHOD(RepeatedField, getIterator) {
+ zval *iter_php = NULL;
+ MAKE_STD_ZVAL(iter_php);
+ Z_TYPE_P(iter_php) = IS_OBJECT;
+ Z_OBJVAL_P(iter_php) = repeated_field_iter_type->create_object(
+ repeated_field_iter_type TSRMLS_CC);
+
+ RepeatedField *intern = zend_object_store_get_object(getThis() TSRMLS_CC);
+ RepeatedFieldIter *iter = zend_object_store_get_object(iter_php TSRMLS_CC);
+ iter->repeated_field = intern;
+ iter->position = 0;
+
+ RETURN_ZVAL(iter_php, 1, 1);
+}
+
+// -----------------------------------------------------------------------------
+// RepeatedFieldIter creation/desctruction
+// -----------------------------------------------------------------------------
+
+void repeated_field_iter_init(TSRMLS_D) {
+ zend_class_entry class_type;
+ const char* class_name = "Google\\Protobuf\\Internal\\RepeatedFieldIter";
+ INIT_CLASS_ENTRY_EX(class_type, class_name, strlen(class_name),
+ repeated_field_iter_methods);
+
+ repeated_field_iter_type =
+ zend_register_internal_class(&class_type TSRMLS_CC);
+ repeated_field_iter_type->create_object = repeated_field_iter_create;
+
+ zend_class_implements(repeated_field_iter_type TSRMLS_CC, 1,
+ zend_ce_iterator);
+}
+
+static zend_object_value repeated_field_iter_create(
+ zend_class_entry *ce TSRMLS_DC) {
+ zend_object_value retval = {0};
+ RepeatedFieldIter *intern;
+
+ intern = emalloc(sizeof(RepeatedFieldIter));
+ memset(intern, 0, sizeof(RepeatedFieldIter));
+
+ zend_object_std_init(&intern->std, ce TSRMLS_CC);
+ object_properties_init(&intern->std, ce);
+
+ intern->repeated_field = NULL;
+ intern->position = 0;
+
+ retval.handle = zend_objects_store_put(
+ intern, (zend_objects_store_dtor_t)zend_objects_destroy_object,
+ (zend_objects_free_object_storage_t)repeated_field_iter_free,
+ NULL TSRMLS_CC);
+ retval.handlers = zend_get_std_object_handlers();
+
+ return retval;
+}
+
+static void repeated_field_iter_free(void *object TSRMLS_DC) {
+ RepeatedFieldIter *intern = object;
+ zend_object_std_dtor(&intern->std TSRMLS_CC);
+ efree(object);
+}
+
+// -----------------------------------------------------------------------------
+// PHP RepeatedFieldIter Methods
+// -----------------------------------------------------------------------------
+
+PHP_METHOD(RepeatedFieldIter, rewind) {
+ RepeatedFieldIter *intern = zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern->position = 0;
+}
+
+PHP_METHOD(RepeatedFieldIter, current) {
+ RepeatedFieldIter *intern = zend_object_store_get_object(getThis() TSRMLS_CC);
+ RepeatedField *repeated_field = intern->repeated_field;
+
+ long index;
+ void *memory;
+
+ HashTable *table = HASH_OF(repeated_field->array);
+
+ if (zend_hash_index_find(table, intern->position, (void **)&memory) ==
+ FAILURE) {
+ zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index);
+ return;
+ }
+ native_slot_get(repeated_field->type, memory, return_value_ptr TSRMLS_CC);
+}
+
+PHP_METHOD(RepeatedFieldIter, key) {
+ RepeatedFieldIter *intern = zend_object_store_get_object(getThis() TSRMLS_CC);
+ RETURN_LONG(intern->position);
+}
+
+PHP_METHOD(RepeatedFieldIter, next) {
+ RepeatedFieldIter *intern = zend_object_store_get_object(getThis() TSRMLS_CC);
+ ++intern->position;
+}
+
+PHP_METHOD(RepeatedFieldIter, valid) {
+ RepeatedFieldIter *intern = zend_object_store_get_object(getThis() TSRMLS_CC);
+ RETURN_BOOL(zend_hash_num_elements(HASH_OF(intern->repeated_field->array)) >
+ intern->position);
+}
diff --git a/third_party/protobuf/php/ext/google/protobuf/config.m4 b/third_party/protobuf/php/ext/google/protobuf/config.m4
new file mode 100644
index 0000000000..ab032e466b
--- /dev/null
+++ b/third_party/protobuf/php/ext/google/protobuf/config.m4
@@ -0,0 +1,10 @@
+PHP_ARG_ENABLE(protobuf, whether to enable Protobuf extension, [ --enable-protobuf Enable Protobuf extension])
+
+if test "$PHP_PROTOBUF" != "no"; then
+
+ PHP_NEW_EXTENSION(
+ protobuf,
+ array.c def.c encode_decode.c map.c message.c protobuf.c storage.c type_check.c upb.c utf8.c,
+ $ext_shared)
+
+fi
diff --git a/third_party/protobuf/php/ext/google/protobuf/def.c b/third_party/protobuf/php/ext/google/protobuf/def.c
new file mode 100644
index 0000000000..52b9e88568
--- /dev/null
+++ b/third_party/protobuf/php/ext/google/protobuf/def.c
@@ -0,0 +1,507 @@
+// 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 "protobuf.h"
+
+// Forward declare.
+static zend_object_value descriptor_create(zend_class_entry *ce TSRMLS_DC);
+static void descriptor_init_c_instance(Descriptor* intern TSRMLS_DC);
+static void descriptor_free_c(Descriptor* object TSRMLS_DC);
+static void descriptor_free(void* object TSRMLS_DC);
+
+static zend_object_value enum_descriptor_create(zend_class_entry *ce TSRMLS_DC);
+static void enum_descriptor_init_c_instance(EnumDescriptor* intern TSRMLS_DC);
+static void enum_descriptor_free_c(EnumDescriptor* object TSRMLS_DC);
+static void enum_descriptor_free(void* object TSRMLS_DC);
+
+static zend_object_value descriptor_pool_create(zend_class_entry *ce TSRMLS_DC);
+static void descriptor_pool_free_c(DescriptorPool* object TSRMLS_DC);
+static void descriptor_pool_free(void* object TSRMLS_DC);
+static void descriptor_pool_init_c_instance(DescriptorPool* pool TSRMLS_DC);
+
+// -----------------------------------------------------------------------------
+// Common Utilities
+// -----------------------------------------------------------------------------
+
+static void check_upb_status(const upb_status* status, const char* msg) {
+ if (!upb_ok(status)) {
+ zend_error(E_ERROR, "%s: %s\n", msg, upb_status_errmsg(status));
+ }
+}
+
+static void upb_filedef_free(void *r) {
+ upb_filedef *f = *(upb_filedef **)r;
+ size_t i;
+
+ for (i = 0; i < upb_filedef_depcount(f); i++) {
+ upb_filedef_unref(upb_filedef_dep(f, i), f);
+ }
+
+ upb_inttable_uninit(&f->defs);
+ upb_inttable_uninit(&f->deps);
+ upb_gfree((void *)f->name);
+ upb_gfree((void *)f->package);
+ upb_gfree(f);
+}
+
+// Camel-case the field name and append "Entry" for generated map entry name.
+// e.g. map<KeyType, ValueType> foo_map => FooMapEntry
+static void append_map_entry_name(char *result, const char *field_name,
+ int pos) {
+ bool cap_next = true;
+ int i;
+
+ for (i = 0; i < strlen(field_name); ++i) {
+ if (field_name[i] == '_') {
+ cap_next = true;
+ } else if (cap_next) {
+ // Note: Do not use ctype.h due to locales.
+ if ('a' <= field_name[i] && field_name[i] <= 'z') {
+ result[pos++] = field_name[i] - 'a' + 'A';
+ } else {
+ result[pos++] = field_name[i];
+ }
+ cap_next = false;
+ } else {
+ result[pos++] = field_name[i];
+ }
+ }
+ strcat(result, "Entry");
+}
+
+#define CHECK_UPB(code, msg) \
+ do { \
+ upb_status status = UPB_STATUS_INIT; \
+ code; \
+ check_upb_status(&status, msg); \
+ } while (0)
+
+// Define PHP class
+#define DEFINE_PROTOBUF_INIT_CLASS(name_lower, string_name) \
+ void name_lower##_init(TSRMLS_D) { \
+ zend_class_entry class_type; \
+ INIT_CLASS_ENTRY(class_type, string_name, name_lower##_methods); \
+ name_lower##_type = zend_register_internal_class(&class_type TSRMLS_CC); \
+ name_lower##_type->create_object = name_lower##_create; \
+ }
+
+#define DEFINE_PROTOBUF_CREATE(name, name_lower) \
+ static zend_object_value name_lower##_create( \
+ zend_class_entry* ce TSRMLS_DC) { \
+ zend_object_value return_value; \
+ name* intern = (name*)emalloc(sizeof(name)); \
+ memset(intern, 0, sizeof(name)); \
+ name_lower##_init_c_instance(intern TSRMLS_CC); \
+ return_value.handle = zend_objects_store_put( \
+ intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, \
+ name_lower##_free, NULL TSRMLS_CC); \
+ return_value.handlers = zend_get_std_object_handlers(); \
+ return return_value; \
+ }
+
+#define DEFINE_PROTOBUF_FREE(name, name_lower) \
+ static void name_lower##_free(void* object TSRMLS_DC) { \
+ name* intern = (name*)object; \
+ name_lower##_free_c(intern TSRMLS_CC); \
+ efree(object); \
+ }
+
+#define DEFINE_CLASS(name, name_lower, string_name) \
+ zend_class_entry* name_lower##_type; \
+ DEFINE_PROTOBUF_FREE(name, name_lower) \
+ DEFINE_PROTOBUF_CREATE(name, name_lower) \
+ DEFINE_PROTOBUF_INIT_CLASS(name_lower, string_name)
+
+// -----------------------------------------------------------------------------
+// GPBType
+// -----------------------------------------------------------------------------
+
+zend_class_entry* gpb_type_type;
+
+static zend_function_entry gpb_type_methods[] = {
+ ZEND_FE_END
+};
+
+void gpb_type_init(TSRMLS_D) {
+ zend_class_entry class_type;
+ INIT_CLASS_ENTRY(class_type, "Google\\Protobuf\\Internal\\GPBType",
+ gpb_type_methods);
+ gpb_type_type = zend_register_internal_class(&class_type TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("DOUBLE"), 1 TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("FLOAT"), 2 TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("INT64"), 3 TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("UINT64"), 4 TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("INT32"), 5 TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("FIXED64"), 6 TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("FIXED32"), 7 TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("BOOL"), 8 TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("STRING"), 9 TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("GROUP"), 10 TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("MESSAGE"), 11 TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("BYTES"), 12 TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("UINT32"), 13 TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("ENUM"), 14 TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("SFIXED32"),
+ 15 TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("SFIXED64"),
+ 16 TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("SINT32"), 17 TSRMLS_CC);
+ zend_declare_class_constant_long(gpb_type_type, STR("SINT64"), 18 TSRMLS_CC);
+}
+
+// -----------------------------------------------------------------------------
+// DescriptorPool
+// -----------------------------------------------------------------------------
+
+static zend_function_entry descriptor_pool_methods[] = {
+ PHP_ME(DescriptorPool, getGeneratedPool, NULL,
+ ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(DescriptorPool, internalAddGeneratedFile, NULL, ZEND_ACC_PUBLIC)
+ ZEND_FE_END
+};
+
+DEFINE_CLASS(DescriptorPool, descriptor_pool,
+ "Google\\Protobuf\\Internal\\DescriptorPool");
+
+zval* generated_pool_php; // wrapper of generated pool
+DescriptorPool *generated_pool; // The actual generated pool
+
+static void init_generated_pool_once(TSRMLS_D) {
+ if (generated_pool_php == NULL) {
+ MAKE_STD_ZVAL(generated_pool_php);
+ Z_TYPE_P(generated_pool_php) = IS_OBJECT;
+ generated_pool = ALLOC(DescriptorPool);
+ descriptor_pool_init_c_instance(generated_pool TSRMLS_CC);
+ Z_OBJ_HANDLE_P(generated_pool_php) = zend_objects_store_put(
+ generated_pool, NULL,
+ (zend_objects_free_object_storage_t)descriptor_pool_free,
+ NULL TSRMLS_CC);
+ Z_OBJ_HT_P(generated_pool_php) = zend_get_std_object_handlers();
+ }
+}
+
+static void descriptor_pool_init_c_instance(DescriptorPool *pool TSRMLS_DC) {
+ zend_object_std_init(&pool->std, descriptor_pool_type TSRMLS_CC);
+ pool->symtab = upb_symtab_new();
+
+ ALLOC_HASHTABLE(pool->pending_list);
+ zend_hash_init(pool->pending_list, 1, NULL, ZVAL_PTR_DTOR, 0);
+}
+
+static void descriptor_pool_free_c(DescriptorPool *pool TSRMLS_DC) {
+ upb_symtab_free(pool->symtab);
+
+ zend_hash_destroy(pool->pending_list);
+ FREE_HASHTABLE(pool->pending_list);
+}
+
+static void validate_enumdef(const upb_enumdef *enumdef) {
+ // Verify that an entry exists with integer value 0. (This is the default
+ // value.)
+ const char *lookup = upb_enumdef_iton(enumdef, 0);
+ if (lookup == NULL) {
+ zend_error(E_USER_ERROR,
+ "Enum definition does not contain a value for '0'.");
+ }
+}
+
+static void validate_msgdef(const upb_msgdef* msgdef) {
+ // Verify that no required fields exist. proto3 does not support these.
+ upb_msg_field_iter it;
+ for (upb_msg_field_begin(&it, msgdef);
+ !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* field = upb_msg_iter_field(&it);
+ if (upb_fielddef_label(field) == UPB_LABEL_REQUIRED) {
+ zend_error(E_ERROR, "Required fields are unsupported in proto3.");
+ }
+ }
+}
+
+PHP_METHOD(DescriptorPool, getGeneratedPool) {
+ init_generated_pool_once(TSRMLS_C);
+ RETURN_ZVAL(generated_pool_php, 1, 0);
+}
+
+static void convert_to_class_name_inplace(char *class_name,
+ const char* fullname,
+ const char* prefix,
+ const char* package_name) {
+ size_t i = 0, j;
+ bool first_char = true;
+ size_t pkg_name_len = package_name == NULL ? 0 : strlen(package_name);
+ size_t prefix_len = prefix == NULL ? 0 : strlen(prefix);
+ size_t message_name_start = package_name == NULL ? 0 : pkg_name_len + 1;
+ size_t message_len = (strlen(fullname) - message_name_start);
+
+ // In php, class name cannot be Empty.
+ if (strcmp("google.protobuf.Empty", fullname) == 0) {
+ strcpy(class_name, "\\Google\\Protobuf\\GPBEmpty");
+ return;
+ }
+
+ if (pkg_name_len != 0) {
+ class_name[i++] = '\\';
+ for (j = 0; j < pkg_name_len; j++) {
+ // php packages are divided by '\'.
+ if (package_name[j] == '.') {
+ class_name[i++] = '\\';
+ first_char = true;
+ } else if (first_char) {
+ // PHP package uses camel case.
+ if (package_name[j] < 'A' || package_name[j] > 'Z') {
+ class_name[i++] = package_name[j] + 'A' - 'a';
+ } else {
+ class_name[i++] = package_name[j];
+ }
+ first_char = false;
+ } else {
+ class_name[i++] = package_name[j];
+ }
+ }
+ class_name[i++] = '\\';
+ }
+
+ if (prefix_len > 0) {
+ strcpy(class_name + i, prefix);
+ i += prefix_len;
+ }
+
+ // Submessage is concatenated with its containing messages by '_'.
+ for (j = message_name_start; j < message_name_start + message_len; j++) {
+ if (fullname[j] == '.') {
+ class_name[i++] = '_';
+ } else {
+ class_name[i++] = fullname[j];
+ }
+ }
+}
+
+PHP_METHOD(DescriptorPool, internalAddGeneratedFile) {
+ char *data = NULL;
+ int data_len;
+ upb_filedef **files;
+ size_t i;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len) ==
+ FAILURE) {
+ return;
+ }
+
+ DescriptorPool *pool = UNBOX(DescriptorPool, getThis());
+ CHECK_UPB(files = upb_loaddescriptor(data, data_len, &pool, &status),
+ "Parse binary descriptors to internal descriptors failed");
+
+ // This method is called only once in each file.
+ assert(files[0] != NULL);
+ assert(files[1] == NULL);
+
+ CHECK_UPB(upb_symtab_addfile(pool->symtab, files[0], &status),
+ "Unable to add file to DescriptorPool");
+
+ // For each enum/message, we need its PHP class, upb descriptor and its PHP
+ // wrapper. These information are needed later for encoding, decoding and type
+ // checking. However, sometimes we just have one of them. In order to find
+ // them quickly, here, we store the mapping for them.
+ for (i = 0; i < upb_filedef_defcount(files[0]); i++) {
+ const upb_def *def = upb_filedef_def(files[0], i);
+ switch (upb_def_type(def)) {
+#define CASE_TYPE(def_type, def_type_lower, desc_type, desc_type_lower) \
+ case UPB_DEF_##def_type: { \
+ desc_type *desc; \
+ zval *desc_php; \
+ CREATE(desc_type, desc, desc_type_lower##_init_c_instance); \
+ BOX(desc_type, desc_php, desc, desc_type_lower##_free); \
+ Z_DELREF_P(desc_php); \
+ const upb_##def_type_lower *def_type_lower = \
+ upb_downcast_##def_type_lower(def); \
+ desc->def_type_lower = def_type_lower; \
+ add_def_obj(desc->def_type_lower, desc_php); \
+ /* Unlike other messages, MapEntry is shared by all map fields and doesn't \
+ * have generated PHP class.*/ \
+ if (upb_def_type(def) == UPB_DEF_MSG && \
+ upb_msgdef_mapentry(upb_downcast_msgdef(def))) { \
+ break; \
+ } \
+ /* Prepend '.' to package name to make it absolute. In the 5 additional \
+ * bytes allocated, one for '.', one for trailing 0, and 3 for 'GPB' if \
+ * given message is google.protobuf.Empty.*/ \
+ const char *fullname = upb_##def_type_lower##_fullname(def_type_lower); \
+ const char *prefix = upb_filedef_phpprefix(files[0]); \
+ size_t klass_name_len = strlen(fullname) + 5; \
+ if (prefix != NULL) { \
+ klass_name_len += strlen(prefix); \
+ } \
+ char *klass_name = ecalloc(sizeof(char), klass_name_len); \
+ convert_to_class_name_inplace(klass_name, fullname, prefix, \
+ upb_filedef_package(files[0])); \
+ zend_class_entry **pce; \
+ if (zend_lookup_class(klass_name, strlen(klass_name), &pce TSRMLS_CC) == \
+ FAILURE) { \
+ zend_error(E_ERROR, "Generated message class %s hasn't been defined", \
+ klass_name); \
+ return; \
+ } else { \
+ desc->klass = *pce; \
+ } \
+ add_ce_obj(desc->klass, desc_php); \
+ efree(klass_name); \
+ break; \
+ }
+
+ CASE_TYPE(MSG, msgdef, Descriptor, descriptor)
+ CASE_TYPE(ENUM, enumdef, EnumDescriptor, enum_descriptor)
+#undef CASE_TYPE
+
+ default:
+ break;
+ }
+ }
+
+ for (i = 0; i < upb_filedef_defcount(files[0]); i++) {
+ const upb_def *def = upb_filedef_def(files[0], i);
+ if (upb_def_type(def) == UPB_DEF_MSG) {
+ const upb_msgdef *msgdef = upb_downcast_msgdef(def);
+ zval *desc_php = get_def_obj(msgdef);
+ build_class_from_descriptor(desc_php TSRMLS_CC);
+ }
+ }
+
+ upb_filedef_unref(files[0], &pool);
+ upb_gfree(files);
+}
+
+// -----------------------------------------------------------------------------
+// Descriptor
+// -----------------------------------------------------------------------------
+
+static zend_function_entry descriptor_methods[] = {
+ ZEND_FE_END
+};
+
+DEFINE_CLASS(Descriptor, descriptor, "Google\\Protobuf\\Internal\\Descriptor");
+
+static void descriptor_free_c(Descriptor *self TSRMLS_DC) {
+ if (self->layout) {
+ free_layout(self->layout);
+ }
+ if (self->fill_handlers) {
+ upb_handlers_unref(self->fill_handlers, &self->fill_handlers);
+ }
+ if (self->fill_method) {
+ upb_pbdecodermethod_unref(self->fill_method, &self->fill_method);
+ }
+ if (self->json_fill_method) {
+ upb_json_parsermethod_unref(self->json_fill_method,
+ &self->json_fill_method);
+ }
+ if (self->pb_serialize_handlers) {
+ upb_handlers_unref(self->pb_serialize_handlers,
+ &self->pb_serialize_handlers);
+ }
+ if (self->json_serialize_handlers) {
+ upb_handlers_unref(self->json_serialize_handlers,
+ &self->json_serialize_handlers);
+ }
+ if (self->json_serialize_handlers_preserve) {
+ upb_handlers_unref(self->json_serialize_handlers_preserve,
+ &self->json_serialize_handlers_preserve);
+ }
+}
+
+static void descriptor_init_c_instance(Descriptor *desc TSRMLS_DC) {
+ zend_object_std_init(&desc->std, descriptor_type TSRMLS_CC);
+ desc->msgdef = NULL;
+ desc->layout = NULL;
+ desc->klass = NULL;
+ desc->fill_handlers = NULL;
+ desc->fill_method = NULL;
+ desc->json_fill_method = NULL;
+ desc->pb_serialize_handlers = NULL;
+ desc->json_serialize_handlers = NULL;
+ desc->json_serialize_handlers_preserve = NULL;
+}
+
+// -----------------------------------------------------------------------------
+// EnumDescriptor
+// -----------------------------------------------------------------------------
+
+static zend_function_entry enum_descriptor_methods[] = {
+ ZEND_FE_END
+};
+
+DEFINE_CLASS(EnumDescriptor, enum_descriptor,
+ "Google\\Protobuf\\Internal\\EnumDescriptor");
+
+static void enum_descriptor_free_c(EnumDescriptor *self TSRMLS_DC) {
+}
+
+static void enum_descriptor_init_c_instance(EnumDescriptor *self TSRMLS_DC) {
+ zend_object_std_init(&self->std, enum_descriptor_type TSRMLS_CC);
+ self->enumdef = NULL;
+ self->klass = NULL;
+}
+
+// -----------------------------------------------------------------------------
+// FieldDescriptor
+// -----------------------------------------------------------------------------
+
+upb_fieldtype_t to_fieldtype(upb_descriptortype_t type) {
+ switch (type) {
+#define CASE(descriptor_type, type) \
+ case UPB_DESCRIPTOR_TYPE_##descriptor_type: \
+ return UPB_TYPE_##type;
+
+ CASE(FLOAT, FLOAT);
+ CASE(DOUBLE, DOUBLE);
+ CASE(BOOL, BOOL);
+ CASE(STRING, STRING);
+ CASE(BYTES, BYTES);
+ CASE(MESSAGE, MESSAGE);
+ CASE(GROUP, MESSAGE);
+ CASE(ENUM, ENUM);
+ CASE(INT32, INT32);
+ CASE(INT64, INT64);
+ CASE(UINT32, UINT32);
+ CASE(UINT64, UINT64);
+ CASE(SINT32, INT32);
+ CASE(SINT64, INT64);
+ CASE(FIXED32, UINT32);
+ CASE(FIXED64, UINT64);
+ CASE(SFIXED32, INT32);
+ CASE(SFIXED64, INT64);
+
+#undef CONVERT
+
+ }
+
+ zend_error(E_ERROR, "Unknown field type.");
+ return 0;
+}
diff --git a/third_party/protobuf/php/ext/google/protobuf/encode_decode.c b/third_party/protobuf/php/ext/google/protobuf/encode_decode.c
new file mode 100644
index 0000000000..e5a5f307cc
--- /dev/null
+++ b/third_party/protobuf/php/ext/google/protobuf/encode_decode.c
@@ -0,0 +1,1356 @@
+// 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 "protobuf.h"
+#include "utf8.h"
+
+/* stringsink *****************************************************************/
+
+typedef struct {
+ upb_byteshandler handler;
+ upb_bytessink sink;
+ char *ptr;
+ size_t len, size;
+} stringsink;
+
+
+static void *stringsink_start(void *_sink, const void *hd, size_t size_hint) {
+ stringsink *sink = _sink;
+ sink->len = 0;
+ return sink;
+}
+
+static size_t stringsink_string(void *_sink, const void *hd, const char *ptr,
+ size_t len, const upb_bufhandle *handle) {
+ stringsink *sink = _sink;
+ size_t new_size = sink->size;
+
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ while (sink->len + len > new_size) {
+ new_size *= 2;
+ }
+
+ if (new_size != sink->size) {
+ sink->ptr = realloc(sink->ptr, new_size);
+ sink->size = new_size;
+ }
+
+ memcpy(sink->ptr + sink->len, ptr, len);
+ sink->len += len;
+
+ return len;
+}
+
+void stringsink_init(stringsink *sink) {
+ upb_byteshandler_init(&sink->handler);
+ upb_byteshandler_setstartstr(&sink->handler, stringsink_start, NULL);
+ upb_byteshandler_setstring(&sink->handler, stringsink_string, NULL);
+
+ upb_bytessink_reset(&sink->sink, &sink->handler, sink);
+
+ sink->size = 32;
+ sink->ptr = malloc(sink->size);
+ sink->len = 0;
+}
+
+void stringsink_uninit(stringsink *sink) { free(sink->ptr); }
+
+/* stackenv *****************************************************************/
+
+// Stack-allocated context during an encode/decode operation. Contains the upb
+// environment and its stack-based allocator, an initial buffer for allocations
+// to avoid malloc() when possible, and a template for PHP exception messages
+// if any error occurs.
+#define STACK_ENV_STACKBYTES 4096
+typedef struct {
+ upb_env env;
+ const char *php_error_template;
+ char allocbuf[STACK_ENV_STACKBYTES];
+} stackenv;
+
+
+static void stackenv_init(stackenv* se, const char* errmsg);
+static void stackenv_uninit(stackenv* se);
+
+// Callback invoked by upb if any error occurs during parsing or serialization.
+static bool env_error_func(void* ud, const upb_status* status) {
+ char err_msg[100] = "";
+ stackenv* se = ud;
+ // Free the env -- zend_error will longjmp up the stack past the
+ // encode/decode function so it would not otherwise have been freed.
+ stackenv_uninit(se);
+
+ // TODO(teboring): have a way to verify that this is actually a parse error,
+ // instead of just throwing "parse error" unconditionally.
+ sprintf(err_msg, se->php_error_template, upb_status_errmsg(status));
+ TSRMLS_FETCH();
+ zend_throw_exception(NULL, err_msg, 0 TSRMLS_CC);
+ // Never reached.
+ return false;
+}
+
+static void stackenv_init(stackenv* se, const char* errmsg) {
+ se->php_error_template = errmsg;
+ upb_env_init2(&se->env, se->allocbuf, sizeof(se->allocbuf), NULL);
+ upb_env_seterrorfunc(&se->env, env_error_func, se);
+}
+
+static void stackenv_uninit(stackenv* se) {
+ upb_env_uninit(&se->env);
+}
+
+// -----------------------------------------------------------------------------
+// Parsing.
+// -----------------------------------------------------------------------------
+
+#define DEREF(msg, ofs, type) *(type*)(((uint8_t *)msg) + ofs)
+
+// Creates a handlerdata that simply contains the offset for this field.
+static const void* newhandlerdata(upb_handlers* h, uint32_t ofs) {
+ size_t* hd_ofs = (size_t*)malloc(sizeof(size_t));
+ *hd_ofs = ofs;
+ upb_handlers_addcleanup(h, hd_ofs, free);
+ return hd_ofs;
+}
+
+typedef struct {
+ size_t ofs;
+ const upb_msgdef *md;
+} submsg_handlerdata_t;
+
+// Creates a handlerdata that contains offset and submessage type information.
+static const void *newsubmsghandlerdata(upb_handlers* h, uint32_t ofs,
+ const upb_fielddef* f) {
+ submsg_handlerdata_t* hd =
+ (submsg_handlerdata_t*)malloc(sizeof(submsg_handlerdata_t));
+ hd->ofs = ofs;
+ hd->md = upb_fielddef_msgsubdef(f);
+ upb_handlers_addcleanup(h, hd, free);
+ return hd;
+}
+
+typedef struct {
+ size_t ofs; // union data slot
+ size_t case_ofs; // oneof_case field
+ int property_ofs; // properties table cache
+ uint32_t oneof_case_num; // oneof-case number to place in oneof_case field
+ const upb_msgdef *md; // msgdef, for oneof submessage handler
+} oneof_handlerdata_t;
+
+static const void *newoneofhandlerdata(upb_handlers *h,
+ uint32_t ofs,
+ uint32_t case_ofs,
+ int property_ofs,
+ const upb_fielddef *f) {
+ oneof_handlerdata_t* hd =
+ (oneof_handlerdata_t*)malloc(sizeof(oneof_handlerdata_t));
+ hd->ofs = ofs;
+ hd->case_ofs = case_ofs;
+ hd->property_ofs = property_ofs;
+ // We reuse the field tag number as a oneof union discriminant tag. Note that
+ // we don't expose these numbers to the user, so the only requirement is that
+ // we have some unique ID for each union case/possibility. The field tag
+ // numbers are already present and are easy to use so there's no reason to
+ // create a separate ID space. In addition, using the field tag number here
+ // lets us easily look up the field in the oneof accessor.
+ hd->oneof_case_num = upb_fielddef_number(f);
+ if (upb_fielddef_type(f) == UPB_TYPE_MESSAGE) {
+ hd->md = upb_fielddef_msgsubdef(f);
+ } else {
+ hd->md = NULL;
+ }
+ upb_handlers_addcleanup(h, hd, free);
+ return hd;
+}
+
+// A handler that starts a repeated field. Gets the Repeated*Field instance for
+// this field (such an instance always exists even in an empty message).
+static void *startseq_handler(void* closure, const void* hd) {
+ MessageHeader* msg = closure;
+ const size_t *ofs = hd;
+ return (void*)(*DEREF(msg, *ofs, zval**));
+}
+
+// Handlers that append primitive values to a repeated field.
+#define DEFINE_APPEND_HANDLER(type, ctype) \
+ static bool append##type##_handler(void* closure, const void* hd, \
+ ctype val) { \
+ zval* array = (zval*)closure; \
+ TSRMLS_FETCH(); \
+ RepeatedField* intern = \
+ (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); \
+ repeated_field_push_native(intern, &val TSRMLS_CC); \
+ return true; \
+ }
+
+DEFINE_APPEND_HANDLER(bool, bool)
+DEFINE_APPEND_HANDLER(int32, int32_t)
+DEFINE_APPEND_HANDLER(uint32, uint32_t)
+DEFINE_APPEND_HANDLER(float, float)
+DEFINE_APPEND_HANDLER(int64, int64_t)
+DEFINE_APPEND_HANDLER(uint64, uint64_t)
+DEFINE_APPEND_HANDLER(double, double)
+
+// Appends a string to a repeated field.
+static void* appendstr_handler(void *closure,
+ const void *hd,
+ size_t size_hint) {
+ zval* array = (zval*)closure;
+ TSRMLS_FETCH();
+ RepeatedField* intern =
+ (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC);
+
+ zval* str;
+ MAKE_STD_ZVAL(str);
+ ZVAL_STRING(str, "", 1);
+
+ repeated_field_push_native(intern, &str TSRMLS_CC);
+ return (void*)str;
+}
+
+// Appends a 'bytes' string to a repeated field.
+static void* appendbytes_handler(void *closure,
+ const void *hd,
+ size_t size_hint) {
+ zval* array = (zval*)closure;
+ TSRMLS_FETCH();
+ RepeatedField* intern =
+ (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC);
+
+ zval* str;
+ MAKE_STD_ZVAL(str);
+ ZVAL_STRING(str, "", 1);
+
+ repeated_field_push_native(intern, &str TSRMLS_CC);
+ return (void*)str;
+}
+
+static void *empty_php_string(zval** value_ptr) {
+ SEPARATE_ZVAL_IF_NOT_REF(value_ptr);
+ zval* str = *value_ptr;
+ zval_dtor(str);
+ ZVAL_STRINGL(str, "", 0, 1);
+ return (void*)str;
+}
+
+// Sets a non-repeated string field in a message.
+static void* str_handler(void *closure,
+ const void *hd,
+ size_t size_hint) {
+ MessageHeader* msg = closure;
+ const size_t *ofs = hd;
+ return empty_php_string(DEREF(msg, *ofs, zval**));
+}
+
+// Sets a non-repeated 'bytes' field in a message.
+static void* bytes_handler(void *closure,
+ const void *hd,
+ size_t size_hint) {
+ MessageHeader* msg = closure;
+ const size_t *ofs = hd;
+ return empty_php_string(DEREF(msg, *ofs, zval**));
+}
+
+static size_t stringdata_handler(void* closure, const void* hd,
+ const char* str, size_t len,
+ const upb_bufhandle* handle) {
+ zval* php_str = (zval*)closure;
+
+ char* old_str = Z_STRVAL_P(php_str);
+ size_t old_len = Z_STRLEN_P(php_str);
+ assert(old_str != NULL);
+
+ char* new_str = emalloc(old_len + len + 1);
+
+ memcpy(new_str, old_str, old_len);
+ memcpy(new_str + old_len, str, len);
+ new_str[old_len + len] = 0;
+ FREE(old_str);
+
+ Z_STRVAL_P(php_str) = new_str;
+ Z_STRLEN_P(php_str) = old_len + len;
+
+ return len;
+}
+
+// Appends a submessage to a repeated field.
+static void *appendsubmsg_handler(void *closure, const void *hd) {
+ zval* array = (zval*)closure;
+ TSRMLS_FETCH();
+ RepeatedField* intern =
+ (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC);
+
+ const submsg_handlerdata_t *submsgdata = hd;
+ zval* subdesc_php = get_def_obj((void*)submsgdata->md);
+ Descriptor* subdesc = zend_object_store_get_object(subdesc_php TSRMLS_CC);
+ zend_class_entry* subklass = subdesc->klass;
+ MessageHeader* submsg;
+
+ zval* val = NULL;
+ MAKE_STD_ZVAL(val);
+ Z_TYPE_P(val) = IS_OBJECT;
+ Z_OBJVAL_P(val) = subklass->create_object(subklass TSRMLS_CC);
+
+ repeated_field_push_native(intern, &val TSRMLS_CC);
+
+ submsg = zend_object_store_get_object(val TSRMLS_CC);
+ return submsg;
+}
+
+// Sets a non-repeated submessage field in a message.
+static void *submsg_handler(void *closure, const void *hd) {
+ MessageHeader* msg = closure;
+ const submsg_handlerdata_t* submsgdata = hd;
+ zval* subdesc_php = get_def_obj((void*)submsgdata->md);
+ TSRMLS_FETCH();
+ Descriptor* subdesc = zend_object_store_get_object(subdesc_php TSRMLS_CC);
+ zend_class_entry* subklass = subdesc->klass;
+ zval* submsg_php;
+ MessageHeader* submsg;
+
+ if (Z_TYPE_P(*DEREF(msg, submsgdata->ofs, zval**)) == IS_NULL) {
+ zval* val = NULL;
+ MAKE_STD_ZVAL(val);
+ Z_TYPE_P(val) = IS_OBJECT;
+ Z_OBJVAL_P(val) = subklass->create_object(subklass TSRMLS_CC);
+
+ zval_ptr_dtor(DEREF(msg, submsgdata->ofs, zval**));
+ *DEREF(msg, submsgdata->ofs, zval**) = val;
+ }
+
+ submsg_php = *DEREF(msg, submsgdata->ofs, zval**);
+
+ submsg = zend_object_store_get_object(submsg_php TSRMLS_CC);
+ return submsg;
+}
+
+// Handler data for startmap/endmap handlers.
+typedef struct {
+ size_t ofs;
+ upb_fieldtype_t key_field_type;
+ upb_fieldtype_t value_field_type;
+
+ // We know that we can hold this reference because the handlerdata has the
+ // same lifetime as the upb_handlers struct, and the upb_handlers struct holds
+ // a reference to the upb_msgdef, which in turn has references to its subdefs.
+ const upb_def* value_field_subdef;
+} map_handlerdata_t;
+
+// Temporary frame for map parsing: at the beginning of a map entry message, a
+// submsg handler allocates a frame to hold (i) a reference to the Map object
+// into which this message will be inserted and (ii) storage slots to
+// temporarily hold the key and value for this map entry until the end of the
+// submessage. When the submessage ends, another handler is called to insert the
+// value into the map.
+typedef struct {
+ zval* map;
+ char key_storage[NATIVE_SLOT_MAX_SIZE];
+ char value_storage[NATIVE_SLOT_MAX_SIZE];
+} map_parse_frame_t;
+
+static void map_slot_init(void* memory, upb_fieldtype_t type) {
+ switch (type) {
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ // Store zval** in memory in order to be consistent with the layout of
+ // singular fields.
+ zval** holder = ALLOC(zval*);
+ zval* tmp;
+ MAKE_STD_ZVAL(tmp);
+ ZVAL_STRINGL(tmp, "", 0, 1);
+ *holder = tmp;
+ *(zval***)memory = holder;
+ break;
+ }
+ case UPB_TYPE_MESSAGE: {
+ zval** holder = ALLOC(zval*);
+ zval* tmp;
+ MAKE_STD_ZVAL(tmp);
+ ZVAL_NULL(tmp);
+ *holder = tmp;
+ *(zval***)memory = holder;
+ break;
+ }
+ default:
+ native_slot_init(type, memory, NULL);
+ }
+}
+
+static void map_slot_uninit(void* memory, upb_fieldtype_t type) {
+ switch (type) {
+ case UPB_TYPE_MESSAGE:
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ zval** holder = *(zval***)memory;
+ zval_ptr_dtor(holder);
+ FREE(holder);
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+static void map_slot_key(upb_fieldtype_t type, const void* from,
+ const char** keyval,
+ size_t* length) {
+ if (type == UPB_TYPE_STRING) {
+ zval* key_php = **(zval***)from;
+ *keyval = Z_STRVAL_P(key_php);
+ *length = Z_STRLEN_P(key_php);
+ } else {
+ *keyval = from;
+ *length = native_slot_size(type);
+ }
+}
+
+static void map_slot_value(upb_fieldtype_t type, const void* from,
+ upb_value* v) {
+ size_t len;
+ void* to = upb_value_memory(v);
+#ifndef NDEBUG
+ v->ctype = UPB_CTYPE_UINT64;
+#endif
+
+ memset(to, 0, native_slot_size(type));
+
+ switch (type) {
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_MESSAGE: {
+ *(zval**)to = **(zval***)from;
+ Z_ADDREF_PP((zval**)to);
+ break;
+ }
+ default:
+ len = native_slot_size(type);
+ memcpy(to, from, len);
+ }
+}
+
+// Handler to begin a map entry: allocates a temporary frame. This is the
+// 'startsubmsg' handler on the msgdef that contains the map field.
+static void *startmapentry_handler(void *closure, const void *hd) {
+ MessageHeader* msg = closure;
+ const map_handlerdata_t* mapdata = hd;
+ zval* map = *DEREF(msg, mapdata->ofs, zval**);
+
+ map_parse_frame_t* frame = ALLOC(map_parse_frame_t);
+ frame->map = map;
+
+ map_slot_init(&frame->key_storage, mapdata->key_field_type);
+ map_slot_init(&frame->value_storage, mapdata->value_field_type);
+
+ return frame;
+}
+
+// Handler to end a map entry: inserts the value defined during the message into
+// the map. This is the 'endmsg' handler on the map entry msgdef.
+static bool endmap_handler(void* closure, const void* hd, upb_status* s) {
+ map_parse_frame_t* frame = closure;
+ const map_handlerdata_t* mapdata = hd;
+
+ TSRMLS_FETCH();
+ Map *map = (Map *)zend_object_store_get_object(frame->map TSRMLS_CC);
+
+ const char* keyval = NULL;
+ upb_value v;
+ size_t length;
+
+ map_slot_key(map->key_type, &frame->key_storage, &keyval, &length);
+ map_slot_value(map->value_type, &frame->value_storage, &v);
+
+ map_index_set(map, keyval, length, v);
+
+ map_slot_uninit(&frame->key_storage, mapdata->key_field_type);
+ map_slot_uninit(&frame->value_storage, mapdata->value_field_type);
+ FREE(frame);
+
+ return true;
+}
+
+// Allocates a new map_handlerdata_t given the map entry message definition. If
+// the offset of the field within the parent message is also given, that is
+// added to the handler data as well. Note that this is called *twice* per map
+// field: once in the parent message handler setup when setting the startsubmsg
+// handler and once in the map entry message handler setup when setting the
+// key/value and endmsg handlers. The reason is that there is no easy way to
+// pass the handlerdata down to the sub-message handler setup.
+static map_handlerdata_t* new_map_handlerdata(
+ size_t ofs,
+ const upb_msgdef* mapentry_def,
+ Descriptor* desc) {
+ const upb_fielddef* key_field;
+ const upb_fielddef* value_field;
+ // TODO(teboring): Use emalloc and efree.
+ map_handlerdata_t* hd =
+ (map_handlerdata_t*)malloc(sizeof(map_handlerdata_t));
+
+ hd->ofs = ofs;
+ key_field = upb_msgdef_itof(mapentry_def, MAP_KEY_FIELD);
+ assert(key_field != NULL);
+ hd->key_field_type = upb_fielddef_type(key_field);
+ value_field = upb_msgdef_itof(mapentry_def, MAP_VALUE_FIELD);
+ assert(value_field != NULL);
+ hd->value_field_type = upb_fielddef_type(value_field);
+ hd->value_field_subdef = upb_fielddef_subdef(value_field);
+
+ return hd;
+}
+
+// Handlers that set primitive values in oneofs.
+#define DEFINE_ONEOF_HANDLER(type, ctype) \
+ static bool oneof##type##_handler(void *closure, const void *hd, \
+ ctype val) { \
+ const oneof_handlerdata_t *oneofdata = hd; \
+ DEREF(closure, oneofdata->case_ofs, uint32_t) = \
+ oneofdata->oneof_case_num; \
+ DEREF(closure, oneofdata->ofs, ctype) = val; \
+ return true; \
+ }
+
+DEFINE_ONEOF_HANDLER(bool, bool)
+DEFINE_ONEOF_HANDLER(int32, int32_t)
+DEFINE_ONEOF_HANDLER(uint32, uint32_t)
+DEFINE_ONEOF_HANDLER(float, float)
+DEFINE_ONEOF_HANDLER(int64, int64_t)
+DEFINE_ONEOF_HANDLER(uint64, uint64_t)
+DEFINE_ONEOF_HANDLER(double, double)
+
+#undef DEFINE_ONEOF_HANDLER
+
+// Handlers for strings in a oneof.
+static void *oneofstr_handler(void *closure,
+ const void *hd,
+ size_t size_hint) {
+ MessageHeader* msg = closure;
+ const oneof_handlerdata_t *oneofdata = hd;
+
+ DEREF(msg, oneofdata->case_ofs, uint32_t) =
+ oneofdata->oneof_case_num;
+ DEREF(msg, oneofdata->ofs, zval**) =
+ &(msg->std.properties_table)[oneofdata->property_ofs];
+
+ return empty_php_string(DEREF(msg, oneofdata->ofs, zval**));
+}
+
+static void *oneofbytes_handler(void *closure,
+ const void *hd,
+ size_t size_hint) {
+ MessageHeader* msg = closure;
+ const oneof_handlerdata_t *oneofdata = hd;
+
+ DEREF(msg, oneofdata->case_ofs, uint32_t) =
+ oneofdata->oneof_case_num;
+ DEREF(msg, oneofdata->ofs, zval**) =
+ &(msg->std.properties_table)[oneofdata->property_ofs];
+
+ // TODO(teboring): Add it back.
+ // rb_enc_associate(str, kRubyString8bitEncoding);
+
+ SEPARATE_ZVAL_IF_NOT_REF(DEREF(msg, oneofdata->ofs, zval**));
+ zval* str = *DEREF(msg, oneofdata->ofs, zval**);
+ zval_dtor(str);
+ ZVAL_STRINGL(str, "", 0, 1);
+ return (void*)str;
+}
+
+// Handler for a submessage field in a oneof.
+static void* oneofsubmsg_handler(void* closure, const void* hd) {
+ MessageHeader* msg = closure;
+ const oneof_handlerdata_t *oneofdata = hd;
+ uint32_t oldcase = DEREF(msg, oneofdata->case_ofs, uint32_t);
+ zval* subdesc_php = get_def_obj((void*)oneofdata->md);
+ TSRMLS_FETCH();
+ Descriptor* subdesc = zend_object_store_get_object(subdesc_php TSRMLS_CC);
+ zend_class_entry* subklass = subdesc->klass;
+ zval* submsg_php;
+ MessageHeader* submsg;
+
+ if (oldcase != oneofdata->oneof_case_num) {
+ DEREF(msg, oneofdata->ofs, zval**) =
+ &(msg->std.properties_table)[oneofdata->property_ofs];
+ }
+
+ if (Z_TYPE_P(*DEREF(msg, oneofdata->ofs, zval**)) == IS_NULL) {
+ zval* val = NULL;
+ MAKE_STD_ZVAL(val);
+ Z_TYPE_P(val) = IS_OBJECT;
+ Z_OBJVAL_P(val) = subklass->create_object(subklass TSRMLS_CC);
+
+ zval_ptr_dtor(DEREF(msg, oneofdata->ofs, zval**));
+ *DEREF(msg, oneofdata->ofs, zval**) = val;
+ }
+
+ DEREF(msg, oneofdata->case_ofs, uint32_t) =
+ oneofdata->oneof_case_num;
+
+ submsg_php = *DEREF(msg, oneofdata->ofs, zval**);
+ submsg = zend_object_store_get_object(submsg_php TSRMLS_CC);
+ return submsg;
+}
+
+// Set up handlers for a repeated field.
+static void add_handlers_for_repeated_field(upb_handlers *h,
+ const upb_fielddef *f,
+ size_t offset) {
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_handlerattr_sethandlerdata(&attr, newhandlerdata(h, offset));
+ upb_handlers_setstartseq(h, f, startseq_handler, &attr);
+ upb_handlerattr_uninit(&attr);
+
+ switch (upb_fielddef_type(f)) {
+
+#define SET_HANDLER(utype, ltype) \
+ case utype: \
+ upb_handlers_set##ltype(h, f, append##ltype##_handler, NULL); \
+ break;
+
+ SET_HANDLER(UPB_TYPE_BOOL, bool);
+ SET_HANDLER(UPB_TYPE_INT32, int32);
+ SET_HANDLER(UPB_TYPE_UINT32, uint32);
+ SET_HANDLER(UPB_TYPE_ENUM, int32);
+ SET_HANDLER(UPB_TYPE_FLOAT, float);
+ SET_HANDLER(UPB_TYPE_INT64, int64);
+ SET_HANDLER(UPB_TYPE_UINT64, uint64);
+ SET_HANDLER(UPB_TYPE_DOUBLE, double);
+
+#undef SET_HANDLER
+
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ bool is_bytes = upb_fielddef_type(f) == UPB_TYPE_BYTES;
+ upb_handlers_setstartstr(h, f, is_bytes ?
+ appendbytes_handler : appendstr_handler,
+ NULL);
+ upb_handlers_setstring(h, f, stringdata_handler, NULL);
+ break;
+ }
+ case UPB_TYPE_MESSAGE: {
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_handlerattr_sethandlerdata(&attr, newsubmsghandlerdata(h, 0, f));
+ upb_handlers_setstartsubmsg(h, f, appendsubmsg_handler, &attr);
+ upb_handlerattr_uninit(&attr);
+ break;
+ }
+ }
+}
+
+// Set up handlers for a singular field.
+static void add_handlers_for_singular_field(upb_handlers *h,
+ const upb_fielddef *f,
+ size_t offset) {
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_BOOL:
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_FLOAT:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT64:
+ case UPB_TYPE_DOUBLE:
+ upb_msg_setscalarhandler(h, f, offset, -1);
+ break;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ bool is_bytes = upb_fielddef_type(f) == UPB_TYPE_BYTES;
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_handlerattr_sethandlerdata(&attr, newhandlerdata(h, offset));
+ upb_handlers_setstartstr(h, f,
+ is_bytes ? bytes_handler : str_handler,
+ &attr);
+ upb_handlers_setstring(h, f, stringdata_handler, &attr);
+ upb_handlerattr_uninit(&attr);
+ break;
+ }
+ case UPB_TYPE_MESSAGE: {
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_handlerattr_sethandlerdata(&attr, newsubmsghandlerdata(h, offset, f));
+ upb_handlers_setstartsubmsg(h, f, submsg_handler, &attr);
+ upb_handlerattr_uninit(&attr);
+ break;
+ }
+ }
+}
+
+// Adds handlers to a map field.
+static void add_handlers_for_mapfield(upb_handlers* h,
+ const upb_fielddef* fielddef,
+ size_t offset,
+ Descriptor* desc) {
+ const upb_msgdef* map_msgdef = upb_fielddef_msgsubdef(fielddef);
+ map_handlerdata_t* hd = new_map_handlerdata(offset, map_msgdef, desc);
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+
+ upb_handlers_addcleanup(h, hd, free);
+ upb_handlerattr_sethandlerdata(&attr, hd);
+ upb_handlers_setstartsubmsg(h, fielddef, startmapentry_handler, &attr);
+ upb_handlerattr_uninit(&attr);
+}
+
+// Adds handlers to a map-entry msgdef.
+static void add_handlers_for_mapentry(const upb_msgdef* msgdef, upb_handlers* h,
+ Descriptor* desc) {
+ const upb_fielddef* key_field = map_entry_key(msgdef);
+ const upb_fielddef* value_field = map_entry_value(msgdef);
+ map_handlerdata_t* hd = new_map_handlerdata(0, msgdef, desc);
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+
+ upb_handlers_addcleanup(h, hd, free);
+ upb_handlerattr_sethandlerdata(&attr, hd);
+ upb_handlers_setendmsg(h, endmap_handler, &attr);
+
+ add_handlers_for_singular_field(h, key_field,
+ offsetof(map_parse_frame_t, key_storage));
+ add_handlers_for_singular_field(h, value_field,
+ offsetof(map_parse_frame_t, value_storage));
+}
+
+// Set up handlers for a oneof field.
+static void add_handlers_for_oneof_field(upb_handlers *h,
+ const upb_fielddef *f,
+ size_t offset,
+ size_t oneof_case_offset,
+ int property_cache_offset) {
+
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_handlerattr_sethandlerdata(
+ &attr, newoneofhandlerdata(h, offset, oneof_case_offset,
+ property_cache_offset, f));
+
+ switch (upb_fielddef_type(f)) {
+
+#define SET_HANDLER(utype, ltype) \
+ case utype: \
+ upb_handlers_set##ltype(h, f, oneof##ltype##_handler, &attr); \
+ break;
+
+ SET_HANDLER(UPB_TYPE_BOOL, bool);
+ SET_HANDLER(UPB_TYPE_INT32, int32);
+ SET_HANDLER(UPB_TYPE_UINT32, uint32);
+ SET_HANDLER(UPB_TYPE_ENUM, int32);
+ SET_HANDLER(UPB_TYPE_FLOAT, float);
+ SET_HANDLER(UPB_TYPE_INT64, int64);
+ SET_HANDLER(UPB_TYPE_UINT64, uint64);
+ SET_HANDLER(UPB_TYPE_DOUBLE, double);
+
+#undef SET_HANDLER
+
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ bool is_bytes = upb_fielddef_type(f) == UPB_TYPE_BYTES;
+ upb_handlers_setstartstr(h, f, is_bytes ?
+ oneofbytes_handler : oneofstr_handler,
+ &attr);
+ upb_handlers_setstring(h, f, stringdata_handler, NULL);
+ break;
+ }
+ case UPB_TYPE_MESSAGE: {
+ upb_handlers_setstartsubmsg(h, f, oneofsubmsg_handler, &attr);
+ break;
+ }
+ }
+
+ upb_handlerattr_uninit(&attr);
+}
+
+static void add_handlers_for_message(const void* closure,
+ upb_handlers* h) {
+ const upb_msgdef* msgdef = upb_handlers_msgdef(h);
+ TSRMLS_FETCH();
+ Descriptor* desc = (Descriptor*)zend_object_store_get_object(
+ get_def_obj((void*)msgdef) TSRMLS_CC);
+ upb_msg_field_iter i;
+
+ // If this is a mapentry message type, set up a special set of handlers and
+ // bail out of the normal (user-defined) message type handling.
+ if (upb_msgdef_mapentry(msgdef)) {
+ add_handlers_for_mapentry(msgdef, h, desc);
+ return;
+ }
+
+ // Ensure layout exists. We may be invoked to create handlers for a given
+ // message if we are included as a submsg of another message type before our
+ // class is actually built, so to work around this, we just create the layout
+ // (and handlers, in the class-building function) on-demand.
+ if (desc->layout == NULL) {
+ desc->layout = create_layout(desc->msgdef);
+ }
+
+ for (upb_msg_field_begin(&i, desc->msgdef);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ const upb_fielddef *f = upb_msg_iter_field(&i);
+ size_t offset = desc->layout->fields[upb_fielddef_index(f)].offset +
+ sizeof(MessageHeader);
+
+ if (upb_fielddef_containingoneof(f)) {
+ size_t oneof_case_offset =
+ desc->layout->fields[upb_fielddef_index(f)].case_offset +
+ sizeof(MessageHeader);
+ int property_cache_index =
+ desc->layout->fields[upb_fielddef_index(f)].cache_index;
+ add_handlers_for_oneof_field(h, f, offset, oneof_case_offset,
+ property_cache_index);
+ } else if (is_map_field(f)) {
+ add_handlers_for_mapfield(h, f, offset, desc);
+ } else if (upb_fielddef_isseq(f)) {
+ add_handlers_for_repeated_field(h, f, offset);
+ } else {
+ add_handlers_for_singular_field(h, f, offset);
+ }
+ }
+}
+
+// Creates upb handlers for populating a message.
+static const upb_handlers *new_fill_handlers(Descriptor* desc,
+ const void* owner) {
+ // TODO(cfallin, haberman): once upb gets a caching/memoization layer for
+ // handlers, reuse subdef handlers so that e.g. if we already parse
+ // B-with-field-of-type-C, we don't have to rebuild the whole hierarchy to
+ // parse A-with-field-of-type-B-with-field-of-type-C.
+ return upb_handlers_newfrozen(desc->msgdef, owner,
+ add_handlers_for_message, NULL);
+}
+
+// Constructs the handlers for filling a message's data into an in-memory
+// object.
+const upb_handlers* get_fill_handlers(Descriptor* desc) {
+ if (!desc->fill_handlers) {
+ desc->fill_handlers =
+ new_fill_handlers(desc, &desc->fill_handlers);
+ }
+ return desc->fill_handlers;
+}
+
+const upb_pbdecodermethod *new_fillmsg_decodermethod(Descriptor* desc,
+ const void* owner) {
+ const upb_handlers* handlers = get_fill_handlers(desc);
+ upb_pbdecodermethodopts opts;
+ upb_pbdecodermethodopts_init(&opts, handlers);
+
+ return upb_pbdecodermethod_new(&opts, owner);
+}
+
+static const upb_pbdecodermethod *msgdef_decodermethod(Descriptor* desc) {
+ if (desc->fill_method == NULL) {
+ desc->fill_method = new_fillmsg_decodermethod(
+ desc, &desc->fill_method);
+ }
+ return desc->fill_method;
+}
+
+static const upb_json_parsermethod *msgdef_jsonparsermethod(Descriptor* desc) {
+ if (desc->json_fill_method == NULL) {
+ desc->json_fill_method =
+ upb_json_parsermethod_new(desc->msgdef, &desc->json_fill_method);
+ }
+ return desc->json_fill_method;
+}
+
+// -----------------------------------------------------------------------------
+// Serializing.
+// -----------------------------------------------------------------------------
+
+static void putmsg(zval* msg, const Descriptor* desc, upb_sink* sink,
+ int depth TSRMLS_DC);
+
+static void putstr(zval* str, const upb_fielddef* f, upb_sink* sink);
+
+static void putrawstr(const char* str, int len, const upb_fielddef* f,
+ upb_sink* sink);
+
+static void putsubmsg(zval* submsg, const upb_fielddef* f, upb_sink* sink,
+ int depth TSRMLS_DC);
+
+static void putarray(zval* array, const upb_fielddef* f, upb_sink* sink,
+ int depth TSRMLS_DC);
+static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink,
+ int depth TSRMLS_DC);
+
+static upb_selector_t getsel(const upb_fielddef* f, upb_handlertype_t type) {
+ upb_selector_t ret;
+ bool ok = upb_handlers_getselector(f, type, &ret);
+ UPB_ASSERT(ok);
+ return ret;
+}
+
+static void put_optional_value(const void* memory, int len, const upb_fielddef* f,
+ int depth, upb_sink* sink TSRMLS_DC) {
+ assert(upb_fielddef_label(f) == UPB_LABEL_OPTIONAL);
+
+ switch (upb_fielddef_type(f)) {
+#define T(upbtypeconst, upbtype, ctype, default_value) \
+ case upbtypeconst: { \
+ ctype value = DEREF(memory, 0, ctype); \
+ if (value != default_value) { \
+ upb_selector_t sel = getsel(f, upb_handlers_getprimitivehandlertype(f)); \
+ upb_sink_put##upbtype(sink, sel, value); \
+ } \
+ } break;
+
+ T(UPB_TYPE_FLOAT, float, float, 0.0)
+ T(UPB_TYPE_DOUBLE, double, double, 0.0)
+ T(UPB_TYPE_BOOL, bool, uint8_t, 0)
+ T(UPB_TYPE_ENUM, int32, int32_t, 0)
+ T(UPB_TYPE_INT32, int32, int32_t, 0)
+ T(UPB_TYPE_UINT32, uint32, uint32_t, 0)
+ T(UPB_TYPE_INT64, int64, int64_t, 0)
+ T(UPB_TYPE_UINT64, uint64, uint64_t, 0)
+
+#undef T
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ putrawstr(memory, len, f, sink);
+ break;
+ case UPB_TYPE_MESSAGE: {
+ zval* submsg = *(zval**)memory;
+ putsubmsg(submsg, f, sink, depth TSRMLS_CC);
+ break;
+ }
+ default:
+ assert(false);
+ }
+}
+
+// Only string/bytes fields are stored as zval.
+static const char* raw_value(void* memory, const upb_fielddef* f) {
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ return Z_STRVAL_PP((zval**)memory);
+ break;
+ default:
+ return memory;
+ }
+}
+
+static int raw_value_len(void* memory, int len, const upb_fielddef* f) {
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ return Z_STRLEN_PP((zval**)memory);
+ break;
+ default:
+ return len;
+ }
+}
+
+static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink,
+ int depth TSRMLS_DC) {
+ Map* self;
+ upb_sink subsink;
+ const upb_fielddef* key_field;
+ const upb_fielddef* value_field;
+ MapIter it;
+ int len, size;
+
+ assert(map != NULL);
+ Map* intern =
+ (Map*)zend_object_store_get_object(map TSRMLS_CC);
+ size = upb_strtable_count(&intern->table);
+ if (size == 0) return;
+
+ upb_sink_startseq(sink, getsel(f, UPB_HANDLER_STARTSEQ), &subsink);
+
+ assert(upb_fielddef_type(f) == UPB_TYPE_MESSAGE);
+ key_field = map_field_key(f);
+ value_field = map_field_value(f);
+
+ for (map_begin(map, &it TSRMLS_CC); !map_done(&it); map_next(&it)) {
+ upb_status status;
+
+ upb_sink entry_sink;
+ upb_sink_startsubmsg(&subsink, getsel(f, UPB_HANDLER_STARTSUBMSG),
+ &entry_sink);
+ upb_sink_startmsg(&entry_sink);
+
+ // Serialize key.
+ const char *key = map_iter_key(&it, &len);
+ put_optional_value(key, len, key_field, depth + 1, &entry_sink TSRMLS_CC);
+
+ // Serialize value.
+ upb_value value = map_iter_value(&it, &len);
+ put_optional_value(raw_value(upb_value_memory(&value), value_field),
+ raw_value_len(upb_value_memory(&value), len, value_field),
+ value_field, depth + 1, &entry_sink TSRMLS_CC);
+
+ upb_sink_endmsg(&entry_sink, &status);
+ upb_sink_endsubmsg(&subsink, getsel(f, UPB_HANDLER_ENDSUBMSG));
+ }
+
+ upb_sink_endseq(sink, getsel(f, UPB_HANDLER_ENDSEQ));
+}
+
+static void putmsg(zval* msg_php, const Descriptor* desc, upb_sink* sink,
+ int depth TSRMLS_DC) {
+ upb_msg_field_iter i;
+ upb_status status;
+
+ upb_sink_startmsg(sink);
+
+ // Protect against cycles (possible because users may freely reassign message
+ // and repeated fields) by imposing a maximum recursion depth.
+ if (depth > ENCODE_MAX_NESTING) {
+ zend_error(E_ERROR,
+ "Maximum recursion depth exceeded during encoding.");
+ }
+
+ MessageHeader* msg = zend_object_store_get_object(msg_php TSRMLS_CC);
+
+ for (upb_msg_field_begin(&i, desc->msgdef); !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ upb_fielddef* f = upb_msg_iter_field(&i);
+ uint32_t offset = desc->layout->fields[upb_fielddef_index(f)].offset +
+ sizeof(MessageHeader);
+
+ if (upb_fielddef_containingoneof(f)) {
+ uint32_t oneof_case_offset =
+ desc->layout->fields[upb_fielddef_index(f)].case_offset +
+ sizeof(MessageHeader);
+ // For a oneof, check that this field is actually present -- skip all the
+ // below if not.
+ if (DEREF(msg, oneof_case_offset, uint32_t) != upb_fielddef_number(f)) {
+ continue;
+ }
+ // Otherwise, fall through to the appropriate singular-field handler
+ // below.
+ }
+
+ if (is_map_field(f)) {
+ zval* map = *DEREF(msg, offset, zval**);
+ if (map != NULL) {
+ putmap(map, f, sink, depth TSRMLS_CC);
+ }
+ } else if (upb_fielddef_isseq(f)) {
+ zval* array = *DEREF(msg, offset, zval**);
+ if (array != NULL) {
+ putarray(array, f, sink, depth TSRMLS_CC);
+ }
+ } else if (upb_fielddef_isstring(f)) {
+ zval* str = *DEREF(msg, offset, zval**);
+ if (Z_STRLEN_P(str) > 0) {
+ putstr(str, f, sink);
+ }
+ } else if (upb_fielddef_issubmsg(f)) {
+ putsubmsg(*DEREF(msg, offset, zval**), f, sink, depth TSRMLS_CC);
+ } else {
+ upb_selector_t sel = getsel(f, upb_handlers_getprimitivehandlertype(f));
+
+#define T(upbtypeconst, upbtype, ctype, default_value) \
+ case upbtypeconst: { \
+ ctype value = DEREF(msg, offset, ctype); \
+ if (value != default_value) { \
+ upb_sink_put##upbtype(sink, sel, value); \
+ } \
+ } break;
+
+ switch (upb_fielddef_type(f)) {
+ T(UPB_TYPE_FLOAT, float, float, 0.0)
+ T(UPB_TYPE_DOUBLE, double, double, 0.0)
+ T(UPB_TYPE_BOOL, bool, uint8_t, 0)
+ case UPB_TYPE_ENUM:
+ T(UPB_TYPE_INT32, int32, int32_t, 0)
+ T(UPB_TYPE_UINT32, uint32, uint32_t, 0)
+ T(UPB_TYPE_INT64, int64, int64_t, 0)
+ T(UPB_TYPE_UINT64, uint64, uint64_t, 0)
+
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_MESSAGE:
+ zend_error(E_ERROR, "Internal error.");
+ }
+
+#undef T
+ }
+ }
+
+ upb_sink_endmsg(sink, &status);
+}
+
+static void putstr(zval* str, const upb_fielddef *f, upb_sink *sink) {
+ upb_sink subsink;
+
+ if (ZVAL_IS_NULL(str)) return;
+
+ assert(Z_TYPE_P(str) == IS_STRING);
+
+ // Ensure that the string has the correct encoding. We also check at field-set
+ // time, but the user may have mutated the string object since then.
+ if (upb_fielddef_type(f) == UPB_TYPE_STRING &&
+ !is_structurally_valid_utf8(Z_STRVAL_P(str), Z_STRLEN_P(str))) {
+ zend_error(E_USER_ERROR, "Given string is not UTF8 encoded.");
+ return;
+ }
+
+ upb_sink_startstr(sink, getsel(f, UPB_HANDLER_STARTSTR), Z_STRLEN_P(str),
+ &subsink);
+ upb_sink_putstring(&subsink, getsel(f, UPB_HANDLER_STRING), Z_STRVAL_P(str),
+ Z_STRLEN_P(str), NULL);
+ upb_sink_endstr(sink, getsel(f, UPB_HANDLER_ENDSTR));
+}
+
+static void putrawstr(const char* str, int len, const upb_fielddef* f,
+ upb_sink* sink) {
+ upb_sink subsink;
+
+ if (len == 0) return;
+
+ // Ensure that the string has the correct encoding. We also check at field-set
+ // time, but the user may have mutated the string object since then.
+ if (upb_fielddef_type(f) == UPB_TYPE_STRING &&
+ !is_structurally_valid_utf8(str, len)) {
+ zend_error(E_USER_ERROR, "Given string is not UTF8 encoded.");
+ return;
+ }
+
+ upb_sink_startstr(sink, getsel(f, UPB_HANDLER_STARTSTR), len, &subsink);
+ upb_sink_putstring(&subsink, getsel(f, UPB_HANDLER_STRING), str, len, NULL);
+ upb_sink_endstr(sink, getsel(f, UPB_HANDLER_ENDSTR));
+}
+
+static void putsubmsg(zval* submsg, const upb_fielddef* f, upb_sink* sink,
+ int depth TSRMLS_DC) {
+ upb_sink subsink;
+
+ if (Z_TYPE_P(submsg) == IS_NULL) return;
+
+ zval* php_descriptor = get_def_obj(upb_fielddef_msgsubdef(f));
+ Descriptor* subdesc =
+ (Descriptor*)zend_object_store_get_object(php_descriptor TSRMLS_CC);
+
+ upb_sink_startsubmsg(sink, getsel(f, UPB_HANDLER_STARTSUBMSG), &subsink);
+ putmsg(submsg, subdesc, &subsink, depth + 1 TSRMLS_CC);
+ upb_sink_endsubmsg(sink, getsel(f, UPB_HANDLER_ENDSUBMSG));
+}
+
+static void putarray(zval* array, const upb_fielddef* f, upb_sink* sink,
+ int depth TSRMLS_DC) {
+ upb_sink subsink;
+ upb_fieldtype_t type = upb_fielddef_type(f);
+ upb_selector_t sel = 0;
+ int size, i;
+
+ assert(array != NULL);
+ RepeatedField* intern =
+ (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC);
+ size = zend_hash_num_elements(HASH_OF(intern->array));
+ if (size == 0) return;
+
+ upb_sink_startseq(sink, getsel(f, UPB_HANDLER_STARTSEQ), &subsink);
+
+ if (upb_fielddef_isprimitive(f)) {
+ sel = getsel(f, upb_handlers_getprimitivehandlertype(f));
+ }
+
+ for (i = 0; i < size; i++) {
+ void* memory = repeated_field_index_native(intern, i TSRMLS_CC);
+ switch (type) {
+#define T(upbtypeconst, upbtype, ctype) \
+ case upbtypeconst: \
+ upb_sink_put##upbtype(&subsink, sel, *((ctype*)memory)); \
+ break;
+
+ T(UPB_TYPE_FLOAT, float, float)
+ T(UPB_TYPE_DOUBLE, double, double)
+ T(UPB_TYPE_BOOL, bool, int8_t)
+ case UPB_TYPE_ENUM:
+ T(UPB_TYPE_INT32, int32, int32_t)
+ T(UPB_TYPE_UINT32, uint32, uint32_t)
+ T(UPB_TYPE_INT64, int64, int64_t)
+ T(UPB_TYPE_UINT64, uint64, uint64_t)
+
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ putstr(*((zval**)memory), f, &subsink);
+ break;
+ case UPB_TYPE_MESSAGE:
+ putsubmsg(*((zval**)memory), f, &subsink, depth TSRMLS_CC);
+ break;
+
+#undef T
+ }
+ }
+ upb_sink_endseq(sink, getsel(f, UPB_HANDLER_ENDSEQ));
+}
+
+static const upb_handlers* msgdef_pb_serialize_handlers(Descriptor* desc) {
+ if (desc->pb_serialize_handlers == NULL) {
+ desc->pb_serialize_handlers =
+ upb_pb_encoder_newhandlers(desc->msgdef, &desc->pb_serialize_handlers);
+ }
+ return desc->pb_serialize_handlers;
+}
+
+static const upb_handlers* msgdef_json_serialize_handlers(
+ Descriptor* desc, bool preserve_proto_fieldnames) {
+ if (preserve_proto_fieldnames) {
+ if (desc->json_serialize_handlers == NULL) {
+ desc->json_serialize_handlers =
+ upb_json_printer_newhandlers(
+ desc->msgdef, true, &desc->json_serialize_handlers);
+ }
+ return desc->json_serialize_handlers;
+ } else {
+ if (desc->json_serialize_handlers_preserve == NULL) {
+ desc->json_serialize_handlers_preserve =
+ upb_json_printer_newhandlers(
+ desc->msgdef, false, &desc->json_serialize_handlers_preserve);
+ }
+ return desc->json_serialize_handlers_preserve;
+ }
+}
+
+// -----------------------------------------------------------------------------
+// PHP encode/decode methods
+// -----------------------------------------------------------------------------
+
+PHP_METHOD(Message, serializeToString) {
+ zval* php_descriptor = get_ce_obj(Z_OBJCE_P(getThis()));
+ Descriptor* desc =
+ (Descriptor*)zend_object_store_get_object(php_descriptor TSRMLS_CC);
+
+ stringsink sink;
+ stringsink_init(&sink);
+
+ {
+ const upb_handlers* serialize_handlers = msgdef_pb_serialize_handlers(desc);
+
+ stackenv se;
+ upb_pb_encoder* encoder;
+
+ stackenv_init(&se, "Error occurred during encoding: %s");
+ encoder = upb_pb_encoder_create(&se.env, serialize_handlers, &sink.sink);
+
+ putmsg(getThis(), desc, upb_pb_encoder_input(encoder), 0 TSRMLS_CC);
+
+ RETVAL_STRINGL(sink.ptr, sink.len, 1);
+
+ stackenv_uninit(&se);
+ stringsink_uninit(&sink);
+ }
+}
+
+PHP_METHOD(Message, mergeFromString) {
+ zval* php_descriptor = get_ce_obj(Z_OBJCE_P(getThis()));
+ Descriptor* desc =
+ (Descriptor*)zend_object_store_get_object(php_descriptor TSRMLS_CC);
+ MessageHeader* msg = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ char *data = NULL;
+ int data_len;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len) ==
+ FAILURE) {
+ return;
+ }
+
+ {
+ const upb_pbdecodermethod* method = msgdef_decodermethod(desc);
+ const upb_handlers* h = upb_pbdecodermethod_desthandlers(method);
+ stackenv se;
+ upb_sink sink;
+ upb_pbdecoder* decoder;
+ stackenv_init(&se, "Error occurred during parsing: %s");
+
+ upb_sink_reset(&sink, h, msg);
+ decoder = upb_pbdecoder_create(&se.env, method, &sink);
+ upb_bufsrc_putbuf(data, data_len, upb_pbdecoder_input(decoder));
+
+ stackenv_uninit(&se);
+ }
+}
+
+PHP_METHOD(Message, jsonEncode) {
+ zval* php_descriptor = get_ce_obj(Z_OBJCE_P(getThis()));
+ Descriptor* desc =
+ (Descriptor*)zend_object_store_get_object(php_descriptor TSRMLS_CC);
+
+ zend_bool preserve_proto_fieldnames = false;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b",
+ &preserve_proto_fieldnames) == FAILURE) {
+ return;
+ }
+
+ stringsink sink;
+ stringsink_init(&sink);
+
+ {
+ const upb_handlers* serialize_handlers =
+ msgdef_json_serialize_handlers(desc, preserve_proto_fieldnames);
+ upb_json_printer* printer;
+ stackenv se;
+
+ stackenv_init(&se, "Error occurred during encoding: %s");
+ printer = upb_json_printer_create(&se.env, serialize_handlers, &sink.sink);
+
+ putmsg(getThis(), desc, upb_json_printer_input(printer), 0 TSRMLS_CC);
+
+ RETVAL_STRINGL(sink.ptr, sink.len, 1);
+
+ stackenv_uninit(&se);
+ stringsink_uninit(&sink);
+ }
+}
+
+PHP_METHOD(Message, jsonDecode) {
+ zval* php_descriptor = get_ce_obj(Z_OBJCE_P(getThis()));
+ Descriptor* desc =
+ (Descriptor*)zend_object_store_get_object(php_descriptor TSRMLS_CC);
+ MessageHeader* msg = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ char *data = NULL;
+ int data_len;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len) ==
+ FAILURE) {
+ return;
+ }
+
+ // TODO(teboring): Check and respect string encoding. If not UTF-8, we need to
+ // convert, because string handlers pass data directly to message string
+ // fields.
+
+ // TODO(teboring): Clear message.
+
+ {
+ const upb_json_parsermethod* method = msgdef_jsonparsermethod(desc);
+ stackenv se;
+ upb_sink sink;
+ upb_json_parser* parser;
+ stackenv_init(&se, "Error occurred during parsing: %s");
+
+ upb_sink_reset(&sink, get_fill_handlers(desc), msg);
+ parser = upb_json_parser_create(&se.env, method, &sink);
+ upb_bufsrc_putbuf(data, data_len, upb_json_parser_input(parser));
+
+ stackenv_uninit(&se);
+ }
+}
diff --git a/third_party/protobuf/php/ext/google/protobuf/map.c b/third_party/protobuf/php/ext/google/protobuf/map.c
new file mode 100644
index 0000000000..fae152e3fe
--- /dev/null
+++ b/third_party/protobuf/php/ext/google/protobuf/map.c
@@ -0,0 +1,487 @@
+// 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 <ext/spl/spl_iterators.h>
+#include <Zend/zend_API.h>
+#include <Zend/zend_interfaces.h>
+
+#include "protobuf.h"
+#include "utf8.h"
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1)
+ ZEND_ARG_INFO(0, index)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2)
+ ZEND_ARG_INFO(0, index)
+ ZEND_ARG_INFO(0, newval)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
+ZEND_END_ARG_INFO()
+
+// Utilities
+
+void* upb_value_memory(upb_value* v) {
+ return (void*)(&v->val);
+}
+
+// -----------------------------------------------------------------------------
+// Basic map operations on top of upb's strtable.
+//
+// Note that we roll our own `Map` container here because, as for
+// `RepeatedField`, we want a strongly-typed container. This is so that any user
+// errors due to incorrect map key or value types are raised as close as
+// possible to the error site, rather than at some deferred point (e.g.,
+// serialization).
+//
+// We build our `Map` on top of upb_strtable so that we're able to take
+// advantage of the native_slot storage abstraction, as RepeatedField does.
+// (This is not quite a perfect mapping -- see the key conversions below -- but
+// gives us full support and error-checking for all value types for free.)
+// -----------------------------------------------------------------------------
+
+// Map values are stored using the native_slot abstraction (as with repeated
+// field values), but keys are a bit special. Since we use a strtable, we need
+// to store keys as sequences of bytes such that equality of those bytes maps
+// one-to-one to equality of keys. We store strings directly (i.e., they map to
+// their own bytes) and integers as native integers (using the native_slot
+// abstraction).
+
+// Note that there is another tradeoff here in keeping string keys as native
+// strings rather than PHP strings: traversing the Map requires conversion to
+// PHP string values on every traversal, potentially creating more garbage. We
+// should consider ways to cache a PHP version of the key if this becomes an
+// issue later.
+
+// Forms a key to use with the underlying strtable from a PHP key value. |buf|
+// must point to TABLE_KEY_BUF_LENGTH bytes of temporary space, used to
+// construct a key byte sequence if needed. |out_key| and |out_length| provide
+// the resulting key data/length.
+#define TABLE_KEY_BUF_LENGTH 8 // sizeof(uint64_t)
+static bool table_key(Map* self, zval* key,
+ char* buf,
+ const char** out_key,
+ size_t* out_length TSRMLS_DC) {
+ switch (self->key_type) {
+ case UPB_TYPE_STRING:
+ if (!protobuf_convert_to_string(key)) {
+ return false;
+ }
+ if (!is_structurally_valid_utf8(Z_STRVAL_P(key), Z_STRLEN_P(key))) {
+ zend_error(E_USER_ERROR, "Given key is not UTF8 encoded.");
+ return false;
+ }
+ *out_key = Z_STRVAL_P(key);
+ *out_length = Z_STRLEN_P(key);
+ break;
+
+#define CASE_TYPE(upb_type, type, c_type, php_type) \
+ case UPB_TYPE_##upb_type: { \
+ c_type type##_value; \
+ if (!protobuf_convert_to_##type(key, &type##_value)) { \
+ return false; \
+ } \
+ native_slot_set(self->key_type, NULL, buf, key TSRMLS_CC); \
+ *out_key = buf; \
+ *out_length = native_slot_size(self->key_type); \
+ break; \
+ }
+ CASE_TYPE(BOOL, bool, int8_t, BOOL)
+ CASE_TYPE(INT32, int32, int32_t, LONG)
+ CASE_TYPE(INT64, int64, int64_t, LONG)
+ CASE_TYPE(UINT32, uint32, uint32_t, LONG)
+ CASE_TYPE(UINT64, uint64, uint64_t, LONG)
+
+#undef CASE_TYPE
+
+ default:
+ // Map constructor should not allow a Map with another key type to be
+ // constructed.
+ assert(false);
+ break;
+ }
+
+ return true;
+}
+
+// -----------------------------------------------------------------------------
+// MapField methods
+// -----------------------------------------------------------------------------
+
+static zend_function_entry map_field_methods[] = {
+ PHP_ME(MapField, __construct, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(MapField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC)
+ PHP_ME(MapField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC)
+ PHP_ME(MapField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC)
+ PHP_ME(MapField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC)
+ PHP_ME(MapField, count, arginfo_void, ZEND_ACC_PUBLIC)
+ ZEND_FE_END
+};
+
+// Forward declare static functions.
+
+static bool map_field_write_dimension(zval *object, zval *key,
+ zval *value TSRMLS_DC);
+
+// -----------------------------------------------------------------------------
+// MapField creation/desctruction
+// -----------------------------------------------------------------------------
+
+zend_class_entry* map_field_type;
+zend_object_handlers* map_field_handlers;
+
+static void map_begin_internal(Map *map, MapIter *iter) {
+ iter->self = map;
+ upb_strtable_begin(&iter->it, &map->table);
+}
+
+static HashTable *map_field_get_gc(zval *object, zval ***table,
+ int *n TSRMLS_DC) {
+ // TODO(teboring): Unfortunately, zend engine does not support garbage
+ // collection for custom array. We have to use zend engine's native array
+ // instead.
+ *table = NULL;
+ *n = 0;
+ return NULL;
+}
+
+void map_field_init(TSRMLS_D) {
+ zend_class_entry class_type;
+ const char* class_name = "Google\\Protobuf\\Internal\\MapField";
+ INIT_CLASS_ENTRY_EX(class_type, class_name, strlen(class_name),
+ map_field_methods);
+
+ map_field_type = zend_register_internal_class(&class_type TSRMLS_CC);
+ map_field_type->create_object = map_field_create;
+
+ zend_class_implements(map_field_type TSRMLS_CC, 2, spl_ce_ArrayAccess,
+ spl_ce_Countable);
+
+ map_field_handlers = PEMALLOC(zend_object_handlers);
+ memcpy(map_field_handlers, zend_get_std_object_handlers(),
+ sizeof(zend_object_handlers));
+ map_field_handlers->write_dimension = map_field_write_dimension;
+ map_field_handlers->get_gc = map_field_get_gc;
+}
+
+zend_object_value map_field_create(zend_class_entry *ce TSRMLS_DC) {
+ zend_object_value retval = {0};
+ Map *intern;
+
+ intern = emalloc(sizeof(Map));
+ memset(intern, 0, sizeof(Map));
+
+ zend_object_std_init(&intern->std, ce TSRMLS_CC);
+ object_properties_init(&intern->std, ce);
+
+ // Table value type is always UINT64: this ensures enough space to store the
+ // native_slot value.
+ if (!upb_strtable_init(&intern->table, UPB_CTYPE_UINT64)) {
+ zend_error(E_USER_ERROR, "Could not allocate table.");
+ }
+
+ retval.handle = zend_objects_store_put(
+ intern, (zend_objects_store_dtor_t)zend_objects_destroy_object,
+ (zend_objects_free_object_storage_t)map_field_free, NULL TSRMLS_CC);
+ retval.handlers = map_field_handlers;
+
+ return retval;
+}
+
+void map_field_free(void *object TSRMLS_DC) {
+ Map *map = (Map *)object;
+
+ switch (map->value_type) {
+ case UPB_TYPE_MESSAGE:
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ MapIter it;
+ int len;
+ for (map_begin_internal(map, &it); !map_done(&it); map_next(&it)) {
+ upb_value value = map_iter_value(&it, &len);
+ void *mem = upb_value_memory(&value);
+ zval_ptr_dtor(mem);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+
+ upb_strtable_uninit(&map->table);
+ zend_object_std_dtor(&map->std TSRMLS_CC);
+ efree(object);
+}
+
+void map_field_create_with_field(zend_class_entry *ce, const upb_fielddef *field,
+ zval **map_field TSRMLS_DC) {
+ const upb_fielddef *key_field = map_field_key(field);
+ const upb_fielddef *value_field = map_field_value(field);
+ map_field_create_with_type(
+ ce, upb_fielddef_type(key_field), upb_fielddef_type(value_field),
+ field_type_class(value_field TSRMLS_CC), map_field TSRMLS_CC);
+}
+
+void map_field_create_with_type(zend_class_entry *ce, upb_fieldtype_t key_type,
+ upb_fieldtype_t value_type,
+ const zend_class_entry *msg_ce,
+ zval **map_field TSRMLS_DC) {
+ MAKE_STD_ZVAL(*map_field);
+ Z_TYPE_PP(map_field) = IS_OBJECT;
+ Z_OBJVAL_PP(map_field) =
+ map_field_type->create_object(map_field_type TSRMLS_CC);
+
+ Map* intern =
+ (Map*)zend_object_store_get_object(*map_field TSRMLS_CC);
+
+ intern->key_type = key_type;
+ intern->value_type = value_type;
+ intern->msg_ce = msg_ce;
+}
+
+static void map_field_free_element(void *object) {
+}
+
+// -----------------------------------------------------------------------------
+// MapField Handlers
+// -----------------------------------------------------------------------------
+
+static bool map_field_read_dimension(zval *object, zval *key, int type,
+ zval **retval TSRMLS_DC) {
+ Map *intern =
+ (Map *)zend_object_store_get_object(object TSRMLS_CC);
+
+ char keybuf[TABLE_KEY_BUF_LENGTH];
+ const char* keyval = NULL;
+ size_t length = 0;
+ upb_value v;
+#ifndef NDEBUG
+ v.ctype = UPB_CTYPE_UINT64;
+#endif
+ if (!table_key(intern, key, keybuf, &keyval, &length TSRMLS_CC)) {
+ return false;
+ }
+
+ if (upb_strtable_lookup2(&intern->table, keyval, length, &v)) {
+ void* mem = upb_value_memory(&v);
+ native_slot_get(intern->value_type, mem, retval TSRMLS_CC);
+ return true;
+ } else {
+ zend_error(E_USER_ERROR, "Given key doesn't exist.");
+ return false;
+ }
+}
+
+bool map_index_set(Map *intern, const char* keyval, int length, upb_value v) {
+ // Replace any existing value by issuing a 'remove' operation first.
+ upb_strtable_remove2(&intern->table, keyval, length, NULL);
+ if (!upb_strtable_insert2(&intern->table, keyval, length, v)) {
+ zend_error(E_USER_ERROR, "Could not insert into table");
+ return false;
+ }
+ return true;
+}
+
+static bool map_field_write_dimension(zval *object, zval *key,
+ zval *value TSRMLS_DC) {
+ Map *intern = (Map *)zend_object_store_get_object(object TSRMLS_CC);
+
+ char keybuf[TABLE_KEY_BUF_LENGTH];
+ const char* keyval = NULL;
+ size_t length = 0;
+ upb_value v;
+ void* mem;
+ if (!table_key(intern, key, keybuf, &keyval, &length TSRMLS_CC)) {
+ return false;
+ }
+
+ mem = upb_value_memory(&v);
+ memset(mem, 0, native_slot_size(intern->value_type));
+ if (!native_slot_set(intern->value_type, intern->msg_ce, mem,
+ value TSRMLS_CC)) {
+ return false;
+ }
+#ifndef NDEBUG
+ v.ctype = UPB_CTYPE_UINT64;
+#endif
+
+ // Replace any existing value by issuing a 'remove' operation first.
+ upb_strtable_remove2(&intern->table, keyval, length, NULL);
+ if (!upb_strtable_insert2(&intern->table, keyval, length, v)) {
+ zend_error(E_USER_ERROR, "Could not insert into table");
+ return false;
+ }
+
+ return true;
+}
+
+static bool map_field_unset_dimension(zval *object, zval *key TSRMLS_DC) {
+ Map *intern = (Map *)zend_object_store_get_object(object TSRMLS_CC);
+
+ char keybuf[TABLE_KEY_BUF_LENGTH];
+ const char* keyval = NULL;
+ size_t length = 0;
+ upb_value v;
+ if (!table_key(intern, key, keybuf, &keyval, &length TSRMLS_CC)) {
+ return false;
+ }
+#ifndef NDEBUG
+ v.ctype = UPB_CTYPE_UINT64;
+#endif
+
+ upb_strtable_remove2(&intern->table, keyval, length, &v);
+
+ return true;
+}
+
+// -----------------------------------------------------------------------------
+// PHP MapField Methods
+// -----------------------------------------------------------------------------
+
+PHP_METHOD(MapField, __construct) {
+ long key_type, value_type;
+ zend_class_entry* klass = NULL;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|C", &key_type,
+ &value_type, &klass) == FAILURE) {
+ return;
+ }
+
+ Map* intern =
+ (Map*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ intern->key_type = to_fieldtype(key_type);
+ intern->value_type = to_fieldtype(value_type);
+ intern->msg_ce = klass;
+
+ // Check that the key type is an allowed type.
+ switch (intern->key_type) {
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_UINT64:
+ case UPB_TYPE_BOOL:
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ // These are OK.
+ break;
+ default:
+ zend_error(E_USER_ERROR, "Invalid key type for map.");
+ }
+}
+
+PHP_METHOD(MapField, offsetExists) {
+ zval *key;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &key) ==
+ FAILURE) {
+ return;
+ }
+
+ Map *intern = (Map *)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ char keybuf[TABLE_KEY_BUF_LENGTH];
+ const char* keyval = NULL;
+ size_t length = 0;
+ upb_value v;
+#ifndef NDEBUG
+ v.ctype = UPB_CTYPE_UINT64;
+#endif
+ if (!table_key(intern, key, keybuf, &keyval, &length TSRMLS_CC)) {
+ RETURN_BOOL(false);
+ }
+
+ RETURN_BOOL(upb_strtable_lookup2(&intern->table, keyval, length, &v));
+}
+
+PHP_METHOD(MapField, offsetGet) {
+ zval *index, *value;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &index) ==
+ FAILURE) {
+ return;
+ }
+ map_field_read_dimension(getThis(), index, BP_VAR_R,
+ return_value_ptr TSRMLS_CC);
+}
+
+PHP_METHOD(MapField, offsetSet) {
+ zval *index, *value;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &index, &value) ==
+ FAILURE) {
+ return;
+ }
+ map_field_write_dimension(getThis(), index, value TSRMLS_CC);
+}
+
+PHP_METHOD(MapField, offsetUnset) {
+ zval *index;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &index) ==
+ FAILURE) {
+ return;
+ }
+ map_field_unset_dimension(getThis(), index TSRMLS_CC);
+}
+
+PHP_METHOD(MapField, count) {
+ Map *intern =
+ (Map *)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ RETURN_LONG(upb_strtable_count(&intern->table));
+}
+
+// -----------------------------------------------------------------------------
+// Map Iterator
+// -----------------------------------------------------------------------------
+
+void map_begin(zval *map_php, MapIter *iter TSRMLS_DC) {
+ Map *self = UNBOX(Map, map_php);
+ map_begin_internal(self, iter);
+}
+
+void map_next(MapIter *iter) {
+ upb_strtable_next(&iter->it);
+}
+
+bool map_done(MapIter *iter) {
+ return upb_strtable_done(&iter->it);
+}
+
+const char *map_iter_key(MapIter *iter, int *len) {
+ *len = upb_strtable_iter_keylength(&iter->it);
+ return upb_strtable_iter_key(&iter->it);
+}
+
+upb_value map_iter_value(MapIter *iter, int *len) {
+ *len = native_slot_size(iter->self->value_type);
+ return upb_strtable_iter_value(&iter->it);
+}
diff --git a/third_party/protobuf/php/ext/google/protobuf/message.c b/third_party/protobuf/php/ext/google/protobuf/message.c
new file mode 100644
index 0000000000..59ce6ae6d9
--- /dev/null
+++ b/third_party/protobuf/php/ext/google/protobuf/message.c
@@ -0,0 +1,345 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 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 <php.h>
+#include <stdlib.h>
+#include <ext/json/php_json.h>
+
+#include "protobuf.h"
+
+static zend_class_entry* message_type;
+zend_object_handlers* message_handlers;
+
+static zend_function_entry message_methods[] = {
+ PHP_ME(Message, clear, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Message, serializeToString, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Message, mergeFromString, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Message, jsonEncode, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Message, jsonDecode, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Message, mergeFrom, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Message, readOneof, NULL, ZEND_ACC_PROTECTED)
+ PHP_ME(Message, writeOneof, NULL, ZEND_ACC_PROTECTED)
+ PHP_ME(Message, whichOneof, NULL, ZEND_ACC_PROTECTED)
+ PHP_ME(Message, __construct, NULL, ZEND_ACC_PROTECTED)
+ {NULL, NULL, NULL}
+};
+
+// Forward declare static functions.
+
+static void message_set_property(zval* object, zval* member, zval* value,
+ const zend_literal* key TSRMLS_DC);
+static zval* message_get_property(zval* object, zval* member, int type,
+ const zend_literal* key TSRMLS_DC);
+static zval** message_get_property_ptr_ptr(zval* object, zval* member, int type,
+ const zend_literal* key TSRMLS_DC);
+static HashTable* message_get_properties(zval* object TSRMLS_DC);
+static HashTable* message_get_gc(zval* object, zval*** table, int* n TSRMLS_DC);
+
+static zend_object_value message_create(zend_class_entry* ce TSRMLS_DC);
+static void message_free(void* object TSRMLS_DC);
+
+// -----------------------------------------------------------------------------
+// PHP Message Handlers
+// -----------------------------------------------------------------------------
+
+void message_init(TSRMLS_D) {
+ zend_class_entry class_type;
+ INIT_CLASS_ENTRY(class_type, "Google\\Protobuf\\Internal\\Message",
+ message_methods);
+ message_type = zend_register_internal_class(&class_type TSRMLS_CC);
+
+ message_handlers = PEMALLOC(zend_object_handlers);
+ memcpy(message_handlers, zend_get_std_object_handlers(),
+ sizeof(zend_object_handlers));
+ message_handlers->write_property = message_set_property;
+ message_handlers->read_property = message_get_property;
+ message_handlers->get_property_ptr_ptr = message_get_property_ptr_ptr;
+ message_handlers->get_properties = message_get_properties;
+ message_handlers->get_gc = message_get_gc;
+}
+
+static void message_set_property(zval* object, zval* member, zval* value,
+ const zend_literal* key TSRMLS_DC) {
+ if (Z_TYPE_P(member) != IS_STRING) {
+ zend_error(E_USER_ERROR, "Unexpected type for field name");
+ return;
+ }
+
+ if (Z_OBJCE_P(object) != EG(scope)) {
+ // User cannot set property directly (e.g., $m->a = 1)
+ zend_error(E_USER_ERROR, "Cannot access private property.");
+ return;
+ }
+
+ const upb_fielddef* field;
+
+ MessageHeader* self = zend_object_store_get_object(object TSRMLS_CC);
+
+ field = upb_msgdef_ntofz(self->descriptor->msgdef, Z_STRVAL_P(member));
+ if (field == NULL) {
+ zend_error(E_USER_ERROR, "Unknown field: %s", Z_STRVAL_P(member));
+ }
+
+ layout_set(self->descriptor->layout, self, field, value TSRMLS_CC);
+}
+
+static zval* message_get_property(zval* object, zval* member, int type,
+ const zend_literal* key TSRMLS_DC) {
+ if (Z_TYPE_P(member) != IS_STRING) {
+ zend_error(E_USER_ERROR, "Property name has to be a string.");
+ return EG(uninitialized_zval_ptr);
+ }
+
+ if (Z_OBJCE_P(object) != EG(scope)) {
+ // User cannot get property directly (e.g., $a = $m->a)
+ zend_error(E_USER_ERROR, "Cannot access private property.");
+ return EG(uninitialized_zval_ptr);
+ }
+
+ zend_property_info* property_info = NULL;
+
+ // All properties should have been declared in the generated code and have
+ // corresponding zvals in properties_table.
+ ulong h = zend_get_hash_value(Z_STRVAL_P(member), Z_STRLEN_P(member) + 1);
+ if (zend_hash_quick_find(&Z_OBJCE_P(object)->properties_info,
+ Z_STRVAL_P(member), Z_STRLEN_P(member) + 1, h,
+ (void**)&property_info) != SUCCESS) {
+ zend_error(E_USER_ERROR, "Property does not exist.");
+ return EG(uninitialized_zval_ptr);
+ }
+
+ MessageHeader* self =
+ (MessageHeader*)zend_object_store_get_object(object TSRMLS_CC);
+
+ const upb_fielddef* field;
+ field = upb_msgdef_ntofz(self->descriptor->msgdef, Z_STRVAL_P(member));
+ if (field == NULL) {
+ return EG(uninitialized_zval_ptr);
+ }
+ return layout_get(
+ self->descriptor->layout, message_data(self), field,
+ &Z_OBJ_P(object)->properties_table[property_info->offset] TSRMLS_CC);
+}
+
+static zval** message_get_property_ptr_ptr(zval* object, zval* member, int type,
+ const zend_literal* key TSRMLS_DC) {
+ return NULL;
+}
+
+static HashTable* message_get_properties(zval* object TSRMLS_DC) {
+ return NULL;
+}
+
+static HashTable* message_get_gc(zval* object, zval*** table, int* n TSRMLS_DC) {
+ zend_object* zobj = Z_OBJ_P(object);
+ *table = zobj->properties_table;
+ *n = zobj->ce->default_properties_count;
+ return NULL;
+}
+
+// -----------------------------------------------------------------------------
+// C Message Utilities
+// -----------------------------------------------------------------------------
+
+void* message_data(void* msg) {
+ return ((uint8_t*)msg) + sizeof(MessageHeader);
+}
+
+static void message_free(void* object TSRMLS_DC) {
+ MessageHeader* msg = (MessageHeader*)object;
+ int i;
+
+ for (i = 0; i < msg->std.ce->default_properties_count; i++) {
+ zval_ptr_dtor(&msg->std.properties_table[i]);
+ }
+ efree(msg->std.properties_table);
+ efree(msg);
+}
+
+static zend_object_value message_create(zend_class_entry* ce TSRMLS_DC) {
+ zend_object_value return_value;
+
+ zval* php_descriptor = get_ce_obj(ce);
+
+ Descriptor* desc = zend_object_store_get_object(php_descriptor TSRMLS_CC);
+ MessageHeader* msg = (MessageHeader*)ALLOC_N(
+ uint8_t, sizeof(MessageHeader) + desc->layout->size);
+ memset(message_data(msg), 0, desc->layout->size);
+
+ // We wrap first so that everything in the message object is GC-rooted in
+ // case a collection happens during object creation in layout_init().
+ msg->descriptor = desc;
+
+ zend_object_std_init(&msg->std, ce TSRMLS_CC);
+ object_properties_init(&msg->std, ce);
+ layout_init(desc->layout, message_data(msg),
+ msg->std.properties_table TSRMLS_CC);
+
+ return_value.handle = zend_objects_store_put(
+ msg, (zend_objects_store_dtor_t)zend_objects_destroy_object, message_free,
+ NULL TSRMLS_CC);
+
+ return_value.handlers = message_handlers;
+ return return_value;
+}
+
+void message_create_with_type(zend_class_entry* ce, zval** message TSRMLS_DC) {
+ MAKE_STD_ZVAL(*message);
+ Z_TYPE_PP(message) = IS_OBJECT;
+ Z_OBJVAL_PP(message) = ce->create_object(ce TSRMLS_CC);
+ Z_DELREF_PP(message);
+}
+
+void build_class_from_descriptor(zval* php_descriptor TSRMLS_DC) {
+ Descriptor* desc = UNBOX(Descriptor, php_descriptor);
+
+ // Map entries don't have existing php class.
+ if (upb_msgdef_mapentry(desc->msgdef)) {
+ return;
+ }
+
+ zend_class_entry* registered_ce = desc->klass;
+
+ if (desc->layout == NULL) {
+ MessageLayout* layout = create_layout(desc->msgdef);
+ desc->layout = layout;
+ }
+
+ registered_ce->create_object = message_create;
+}
+
+// -----------------------------------------------------------------------------
+// PHP Methods
+// -----------------------------------------------------------------------------
+
+// At the first time the message is created, the class entry hasn't been
+// modified. As a result, the first created instance will be a normal zend
+// object. Here, we manually modify it to our message in such a case.
+PHP_METHOD(Message, __construct) {
+ if (Z_OBJVAL_P(getThis()).handlers != message_handlers) {
+ zend_class_entry* ce = Z_OBJCE_P(getThis());
+ zval_dtor(getThis());
+ Z_OBJVAL_P(getThis()) = message_create(ce TSRMLS_CC);
+ }
+}
+
+PHP_METHOD(Message, clear) {
+ MessageHeader* msg =
+ (MessageHeader*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ Descriptor* desc = msg->descriptor;
+ zend_class_entry* ce = desc->klass;
+ int i;
+
+ for (i = 0; i < msg->std.ce->default_properties_count; i++) {
+ zval_ptr_dtor(&msg->std.properties_table[i]);
+ }
+ efree(msg->std.properties_table);
+
+ zend_object_std_init(&msg->std, ce TSRMLS_CC);
+ object_properties_init(&msg->std, ce);
+ layout_init(desc->layout, message_data(msg),
+ msg->std.properties_table TSRMLS_CC);
+}
+
+PHP_METHOD(Message, mergeFrom) {
+ zval* value;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &value,
+ message_type) == FAILURE) {
+ return;
+ }
+
+ MessageHeader* from =
+ (MessageHeader*)zend_object_store_get_object(value TSRMLS_CC);
+ MessageHeader* to =
+ (MessageHeader*)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if(from->descriptor != to->descriptor) {
+ zend_error(E_USER_ERROR, "Cannot merge messages with different class.");
+ return;
+ }
+
+ layout_merge(from->descriptor->layout, from, to TSRMLS_CC);
+}
+
+PHP_METHOD(Message, readOneof) {
+ long index;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) ==
+ FAILURE) {
+ return;
+ }
+
+ MessageHeader* msg =
+ (MessageHeader*)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ const upb_fielddef* field = upb_msgdef_itof(msg->descriptor->msgdef, index);
+
+ int property_cache_index =
+ msg->descriptor->layout->fields[upb_fielddef_index(field)].cache_index;
+ zval** cache_ptr = &(msg->std.properties_table)[property_cache_index];
+
+ layout_get(msg->descriptor->layout, message_data(msg), field,
+ &return_value TSRMLS_CC);
+}
+
+PHP_METHOD(Message, writeOneof) {
+ long index;
+ zval* value;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz", &index, &value) ==
+ FAILURE) {
+ return;
+ }
+
+ MessageHeader* msg =
+ (MessageHeader*)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ const upb_fielddef* field = upb_msgdef_itof(msg->descriptor->msgdef, index);
+
+ layout_set(msg->descriptor->layout, msg, field, value TSRMLS_CC);
+}
+
+PHP_METHOD(Message, whichOneof) {
+ char* oneof_name;
+ int length;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &oneof_name,
+ &length) == FAILURE) {
+ return;
+ }
+
+ MessageHeader* msg =
+ (MessageHeader*)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ const upb_oneofdef* oneof =
+ upb_msgdef_ntoo(msg->descriptor->msgdef, oneof_name, length);
+ const char* oneof_case_name = layout_get_oneof_case(
+ msg->descriptor->layout, message_data(msg), oneof TSRMLS_CC);
+ RETURN_STRING(oneof_case_name, 1);
+}
diff --git a/third_party/protobuf/php/ext/google/protobuf/package.xml b/third_party/protobuf/php/ext/google/protobuf/package.xml
new file mode 100644
index 0000000000..aac73d0511
--- /dev/null
+++ b/third_party/protobuf/php/ext/google/protobuf/package.xml
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.9.5" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
+ <name>protobuf</name>
+ <channel>pecl.php.net</channel>
+ <summary>Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data.</summary>
+ <description>https://developers.google.com/protocol-buffers/</description>
+ <lead>
+ <name>Bo Yang</name>
+ <user>stanleycheung</user>
+ <email>protobuf-opensource@google.com</email>
+ <active>yes</active>
+ </lead>
+ <date>2017-01-13</date>
+ <time>16:06:07</time>
+ <version>
+ <release>3.2.0a1</release>
+ <api>3.2.0a1</api>
+ </version>
+ <stability>
+ <release>alpha</release>
+ <api>alpha</api>
+ </stability>
+ <license uri="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</license>
+ <notes>
+Second alpha release.
+ </notes>
+ <contents>
+ <dir baseinstalldir="/" name="/">
+ <file baseinstalldir="/" name="config.m4" role="src" />
+ <file baseinstalldir="/" name="array.c" role="src" />
+ <file baseinstalldir="/" name="def.c" role="src" />
+ <file baseinstalldir="/" name="encode_decode.c" role="src" />
+ <file baseinstalldir="/" name="map.c" role="src" />
+ <file baseinstalldir="/" name="message.c" role="src" />
+ <file baseinstalldir="/" name="protobuf.c" role="src" />
+ <file baseinstalldir="/" name="protobuf.h" role="src" />
+ <file baseinstalldir="/" name="storage.c" role="src" />
+ <file baseinstalldir="/" name="type_check.c" role="src" />
+ <file baseinstalldir="/" name="upb.c" role="src" />
+ <file baseinstalldir="/" name="upb.h" role="src" />
+ <file baseinstalldir="/" name="utf8.c" role="src" />
+ <file baseinstalldir="/" name="utf8.h" role="src" />
+ </dir>
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>5.5.9</min>
+ </php>
+ <pearinstaller>
+ <min>1.4.0</min>
+ </pearinstaller>
+ </required>
+ </dependencies>
+ <providesextension>protobuf</providesextension>
+ <extsrcrelease />
+ <changelog>
+ <release>
+ <version>
+ <release>3.1.0a1</release>
+ <api>3.1.0a1</api>
+ </version>
+ <stability>
+ <release>alpha</release>
+ <api>alpha</api>
+ </stability>
+ <date>2016-09-23</date>
+ <time>16:06:07</time>
+ <license uri="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</license>
+ <notes>
+First alpha release
+ </notes>
+ </release>
+ <release>
+ <version>
+ <release>3.2.0a1</release>
+ <api>3.2.0a1</api>
+ </version>
+ <stability>
+ <release>alpha</release>
+ <api>alpha</api>
+ </stability>
+ <date>2017-01-13</date>
+ <time>16:06:07</time>
+ <license uri="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</license>
+ <notes>
+Second alpha release.
+ </notes>
+ </release>
+ </changelog>
+</package>
diff --git a/third_party/protobuf/php/ext/google/protobuf/protobuf.c b/third_party/protobuf/php/ext/google/protobuf/protobuf.c
new file mode 100644
index 0000000000..ea85b999f8
--- /dev/null
+++ b/third_party/protobuf/php/ext/google/protobuf/protobuf.c
@@ -0,0 +1,176 @@
+// 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 "protobuf.h"
+
+#include <zend_hash.h>
+
+ZEND_DECLARE_MODULE_GLOBALS(protobuf)
+static PHP_GINIT_FUNCTION(protobuf);
+static PHP_GSHUTDOWN_FUNCTION(protobuf);
+static PHP_RINIT_FUNCTION(protobuf);
+static PHP_RSHUTDOWN_FUNCTION(protobuf);
+static PHP_MINIT_FUNCTION(protobuf);
+static PHP_MSHUTDOWN_FUNCTION(protobuf);
+
+// Global map from upb {msg,enum}defs to wrapper Descriptor/EnumDescriptor
+// instances.
+static HashTable* upb_def_to_php_obj_map;
+// Global map from message/enum's php class entry to corresponding wrapper
+// Descriptor/EnumDescriptor instances.
+static HashTable* ce_to_php_obj_map;
+
+// -----------------------------------------------------------------------------
+// Global maps.
+// -----------------------------------------------------------------------------
+
+static void add_to_table(HashTable* t, const void* def, void* value) {
+ uint nIndex = (ulong)def & t->nTableMask;
+
+ zval* pDest = NULL;
+ zend_hash_index_update(t, (zend_ulong)def, &value, sizeof(zval*), (void**)&pDest);
+}
+
+static void* get_from_table(const HashTable* t, const void* def) {
+ void** value;
+ if (zend_hash_index_find(t, (zend_ulong)def, (void**)&value) == FAILURE) {
+ zend_error(E_ERROR, "PHP object not found for given definition.\n");
+ return NULL;
+ }
+ return *value;
+}
+
+static void add_to_list(HashTable* t, void* value) {
+ zval* pDest = NULL;
+ zend_hash_next_index_insert(t, &value, sizeof(void*), (void**)&pDest);
+}
+
+void add_def_obj(const void* def, zval* value) {
+ Z_ADDREF_P(value);
+ add_to_table(upb_def_to_php_obj_map, def, value);
+}
+
+zval* get_def_obj(const void* def) {
+ return (zval*)get_from_table(upb_def_to_php_obj_map, def);
+}
+
+void add_ce_obj(const void* ce, zval* value) {
+ Z_ADDREF_P(value);
+ add_to_table(ce_to_php_obj_map, ce, value);
+}
+
+zval* get_ce_obj(const void* ce) {
+ return (zval*)get_from_table(ce_to_php_obj_map, ce);
+}
+
+// -----------------------------------------------------------------------------
+// Utilities.
+// -----------------------------------------------------------------------------
+
+zend_function_entry protobuf_functions[] = {
+ ZEND_FE_END
+};
+
+zend_module_entry protobuf_module_entry = {
+ STANDARD_MODULE_HEADER,
+ PHP_PROTOBUF_EXTNAME, // extension name
+ protobuf_functions, // function list
+ PHP_MINIT(protobuf), // process startup
+ PHP_MSHUTDOWN(protobuf), // process shutdown
+ PHP_RINIT(protobuf), // request shutdown
+ PHP_RSHUTDOWN(protobuf), // request shutdown
+ NULL, // extension info
+ PHP_PROTOBUF_VERSION, // extension version
+ PHP_MODULE_GLOBALS(protobuf), // globals descriptor
+ PHP_GINIT(protobuf), // globals ctor
+ PHP_GSHUTDOWN(protobuf), // globals dtor
+ NULL, // post deactivate
+ STANDARD_MODULE_PROPERTIES_EX
+};
+
+// install module
+ZEND_GET_MODULE(protobuf)
+
+// global variables
+static PHP_GINIT_FUNCTION(protobuf) {
+}
+
+static PHP_GSHUTDOWN_FUNCTION(protobuf) {
+}
+
+static PHP_RINIT_FUNCTION(protobuf) {
+ ALLOC_HASHTABLE(upb_def_to_php_obj_map);
+ zend_hash_init(upb_def_to_php_obj_map, 16, NULL, ZVAL_PTR_DTOR, 0);
+
+ ALLOC_HASHTABLE(ce_to_php_obj_map);
+ zend_hash_init(ce_to_php_obj_map, 16, NULL, ZVAL_PTR_DTOR, 0);
+
+ generated_pool = NULL;
+ generated_pool_php = NULL;
+
+ return 0;
+}
+
+static PHP_RSHUTDOWN_FUNCTION(protobuf) {
+ zend_hash_destroy(upb_def_to_php_obj_map);
+ FREE_HASHTABLE(upb_def_to_php_obj_map);
+
+ zend_hash_destroy(ce_to_php_obj_map);
+ FREE_HASHTABLE(ce_to_php_obj_map);
+
+ if (generated_pool_php != NULL) {
+ zval_dtor(generated_pool_php);
+ FREE_ZVAL(generated_pool_php);
+ }
+
+ return 0;
+}
+
+static PHP_MINIT_FUNCTION(protobuf) {
+ map_field_init(TSRMLS_C);
+ repeated_field_init(TSRMLS_C);
+ repeated_field_iter_init(TSRMLS_C);
+ gpb_type_init(TSRMLS_C);
+ message_init(TSRMLS_C);
+ descriptor_pool_init(TSRMLS_C);
+ descriptor_init(TSRMLS_C);
+ enum_descriptor_init(TSRMLS_C);
+ util_init(TSRMLS_C);
+
+ return 0;
+}
+
+static PHP_MSHUTDOWN_FUNCTION(protobuf) {
+ PEFREE(message_handlers);
+ PEFREE(repeated_field_handlers);
+ PEFREE(map_field_handlers);
+
+ return 0;
+}
diff --git a/third_party/protobuf/php/ext/google/protobuf/protobuf.h b/third_party/protobuf/php/ext/google/protobuf/protobuf.h
new file mode 100644
index 0000000000..2287f7e617
--- /dev/null
+++ b/third_party/protobuf/php/ext/google/protobuf/protobuf.h
@@ -0,0 +1,489 @@
+// 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_PHP_PROTOBUF_H__
+#define __GOOGLE_PROTOBUF_PHP_PROTOBUF_H__
+
+#include <php.h>
+
+// ubp.h has to be placed after php.h. Othwise, php.h will introduce NDEBUG.
+#include "upb.h"
+
+#define PHP_PROTOBUF_EXTNAME "protobuf"
+#define PHP_PROTOBUF_VERSION "3.2.0a1"
+
+#define MAX_LENGTH_OF_INT64 20
+#define SIZEOF_INT64 8
+
+// -----------------------------------------------------------------------------
+// Forward Declaration
+// ----------------------------------------------------------------------------
+
+struct DescriptorPool;
+struct Descriptor;
+struct EnumDescriptor;
+struct FieldDescriptor;
+struct MessageField;
+struct MessageHeader;
+struct MessageLayout;
+struct RepeatedField;
+struct RepeatedFieldIter;
+struct MapField;
+
+typedef struct DescriptorPool DescriptorPool;
+typedef struct Descriptor Descriptor;
+typedef struct EnumDescriptor EnumDescriptor;
+typedef struct FieldDescriptor FieldDescriptor;
+typedef struct MessageField MessageField;
+typedef struct MessageHeader MessageHeader;
+typedef struct MessageLayout MessageLayout;
+typedef struct RepeatedField RepeatedField;
+typedef struct RepeatedFieldIter RepeatedFieldIter;
+typedef struct MapField MapField;
+
+// -----------------------------------------------------------------------------
+// Globals.
+// -----------------------------------------------------------------------------
+
+ZEND_BEGIN_MODULE_GLOBALS(protobuf)
+ZEND_END_MODULE_GLOBALS(protobuf)
+
+// Init module and PHP classes.
+void descriptor_init(TSRMLS_D);
+void enum_descriptor_init(TSRMLS_D);
+void descriptor_pool_init(TSRMLS_D);
+void gpb_type_init(TSRMLS_D);
+void map_field_init(TSRMLS_D);
+void repeated_field_init(TSRMLS_D);
+void repeated_field_iter_init(TSRMLS_D);
+void util_init(TSRMLS_D);
+void message_init(TSRMLS_D);
+
+// Global map from upb {msg,enum}defs to wrapper Descriptor/EnumDescriptor
+// instances.
+void add_def_obj(const void* def, zval* value);
+zval* get_def_obj(const void* def);
+
+// Global map from PHP class entries to wrapper Descriptor/EnumDescriptor
+// instances.
+void add_ce_obj(const void* ce, zval* value);
+zval* get_ce_obj(const void* ce);
+
+extern zend_class_entry* map_field_type;
+extern zend_class_entry* repeated_field_type;
+
+// -----------------------------------------------------------------------------
+// Descriptor.
+// -----------------------------------------------------------------------------
+
+struct DescriptorPool {
+ zend_object std;
+ upb_symtab* symtab;
+ HashTable* pending_list;
+};
+
+PHP_METHOD(DescriptorPool, getGeneratedPool);
+PHP_METHOD(DescriptorPool, internalAddGeneratedFile);
+
+extern zval* generated_pool_php; // wrapper of generated pool
+extern DescriptorPool* generated_pool; // The actual generated pool
+
+struct Descriptor {
+ zend_object std;
+ const upb_msgdef* msgdef;
+ MessageLayout* layout;
+ zend_class_entry* klass; // begins as NULL
+ const upb_handlers* fill_handlers;
+ const upb_pbdecodermethod* fill_method;
+ const upb_json_parsermethod* json_fill_method;
+ const upb_handlers* pb_serialize_handlers;
+ const upb_handlers* json_serialize_handlers;
+ const upb_handlers* json_serialize_handlers_preserve;
+};
+
+extern zend_class_entry* descriptor_type;
+
+void descriptor_name_set(Descriptor *desc, const char *name);
+
+struct FieldDescriptor {
+ zend_object std;
+ const upb_fielddef* fielddef;
+};
+
+struct EnumDescriptor {
+ zend_object std;
+ const upb_enumdef* enumdef;
+ zend_class_entry* klass; // begins as NULL
+ // VALUE module; // begins as nil
+};
+
+extern zend_class_entry* enum_descriptor_type;
+
+// -----------------------------------------------------------------------------
+// Message class creation.
+// -----------------------------------------------------------------------------
+
+void* message_data(void* msg);
+void message_create_with_type(zend_class_entry* ce, zval** message TSRMLS_DC);
+
+// Build PHP class for given descriptor. Instead of building from scratch, this
+// function modifies existing class which has been partially defined in PHP
+// code.
+void build_class_from_descriptor(zval* php_descriptor TSRMLS_DC);
+
+extern zend_object_handlers* message_handlers;
+
+// -----------------------------------------------------------------------------
+// Message layout / storage.
+// -----------------------------------------------------------------------------
+
+/*
+ * In c extension, each protobuf message is a zval instance. The zval instance
+ * is like union, which can be used to store int, string, zend_object_value and
+ * etc. For protobuf message, the zval instance is used to store the
+ * zend_object_value.
+ *
+ * The zend_object_value is composed of handlers and a handle to look up the
+ * actual stored data. The handlers are pointers to functions, e.g., read,
+ * write, and etc, to access properties.
+ *
+ * The actual data of protobuf messages is stored as MessageHeader in zend
+ * engine's central repository. Each MessageHeader instance is composed of a
+ * zend_object, a Descriptor instance and the real message data.
+ *
+ * For the reason that PHP's native types may not be large enough to store
+ * protobuf message's field (e.g., int64), all message's data is stored in
+ * custom memory layout and is indexed by the Descriptor instance.
+ *
+ * The zend_object contains the zend class entry and the properties table. The
+ * zend class entry contains all information about protobuf message's
+ * corresponding PHP class. The most useful information is the offset table of
+ * properties. Because read access to properties requires returning zval
+ * instance, we need to convert data from the custom layout to zval instance.
+ * Instead of creating zval instance for every read access, we use the zval
+ * instances in the properties table in the zend_object as cache. When
+ * accessing properties, the offset is needed to find the zval property in
+ * zend_object's properties table. These properties will be updated using the
+ * data from custom memory layout only when reading these properties.
+ *
+ * zval
+ * |-zend_object_value obj
+ * |-zend_object_handlers* handlers -> |-read_property_handler
+ * | |-write_property_handler
+ * | ++++++++++++++++++++++
+ * |-zend_object_handle handle -> + central repository +
+ * ++++++++++++++++++++++
+ * MessageHeader <-----------------|
+ * |-zend_object std
+ * | |-class_entry* ce -> class_entry
+ * | | |-HashTable properties_table (name->offset)
+ * | |-zval** properties_table <------------------------------|
+ * | |------> zval* property(cache)
+ * |-Descriptor* desc (name->offset)
+ * |-void** data <-----------|
+ * |-----------------------> void* property(data)
+ *
+ */
+
+#define MESSAGE_FIELD_NO_CASE ((size_t)-1)
+
+struct MessageField {
+ size_t offset;
+ int cache_index; // Each field except oneof field has a zval cache to avoid
+ // multiple creation when being accessed.
+ size_t case_offset; // for oneofs, a uint32. Else, MESSAGE_FIELD_NO_CASE.
+};
+
+struct MessageLayout {
+ const upb_msgdef* msgdef;
+ MessageField* fields;
+ size_t size;
+};
+
+struct MessageHeader {
+ zend_object std; // Stores properties table and class info of PHP instance.
+ // This is needed for MessageHeader to be accessed via PHP.
+ Descriptor* descriptor; // Kept alive by self.class.descriptor reference.
+ // The real message data is appended after MessageHeader.
+};
+
+MessageLayout* create_layout(const upb_msgdef* msgdef);
+void layout_init(MessageLayout* layout, void* storage,
+ zval** properties_table TSRMLS_DC);
+zval* layout_get(MessageLayout* layout, const void* storage,
+ const upb_fielddef* field, zval** cache TSRMLS_DC);
+void layout_set(MessageLayout* layout, MessageHeader* header,
+ const upb_fielddef* field, zval* val TSRMLS_DC);
+void layout_merge(MessageLayout* layout, MessageHeader* from,
+ MessageHeader* to TSRMLS_DC);
+const char* layout_get_oneof_case(MessageLayout* layout, const void* storage,
+ const upb_oneofdef* oneof TSRMLS_DC);
+void free_layout(MessageLayout* layout);
+
+PHP_METHOD(Message, clear);
+PHP_METHOD(Message, mergeFrom);
+PHP_METHOD(Message, readOneof);
+PHP_METHOD(Message, writeOneof);
+PHP_METHOD(Message, whichOneof);
+PHP_METHOD(Message, __construct);
+
+// -----------------------------------------------------------------------------
+// Encode / Decode.
+// -----------------------------------------------------------------------------
+
+// Maximum depth allowed during encoding, to avoid stack overflows due to
+// cycles.
+#define ENCODE_MAX_NESTING 63
+
+// Constructs the upb decoder method for parsing messages of this type.
+// This is called from the message class creation code.
+const upb_pbdecodermethod *new_fillmsg_decodermethod(Descriptor *desc,
+ const void *owner);
+
+PHP_METHOD(Message, serializeToString);
+PHP_METHOD(Message, mergeFromString);
+PHP_METHOD(Message, jsonEncode);
+PHP_METHOD(Message, jsonDecode);
+
+// -----------------------------------------------------------------------------
+// Type check / conversion.
+// -----------------------------------------------------------------------------
+
+bool protobuf_convert_to_int32(zval* from, int32_t* to);
+bool protobuf_convert_to_uint32(zval* from, uint32_t* to);
+bool protobuf_convert_to_int64(zval* from, int64_t* to);
+bool protobuf_convert_to_uint64(zval* from, uint64_t* to);
+bool protobuf_convert_to_float(zval* from, float* to);
+bool protobuf_convert_to_double(zval* from, double* to);
+bool protobuf_convert_to_bool(zval* from, int8_t* to);
+bool protobuf_convert_to_string(zval* from);
+
+PHP_METHOD(Util, checkInt32);
+PHP_METHOD(Util, checkUint32);
+PHP_METHOD(Util, checkInt64);
+PHP_METHOD(Util, checkUint64);
+PHP_METHOD(Util, checkEnum);
+PHP_METHOD(Util, checkFloat);
+PHP_METHOD(Util, checkDouble);
+PHP_METHOD(Util, checkBool);
+PHP_METHOD(Util, checkString);
+PHP_METHOD(Util, checkBytes);
+PHP_METHOD(Util, checkMessage);
+PHP_METHOD(Util, checkMapField);
+PHP_METHOD(Util, checkRepeatedField);
+
+// -----------------------------------------------------------------------------
+// Native slot storage abstraction.
+// -----------------------------------------------------------------------------
+
+#define NATIVE_SLOT_MAX_SIZE sizeof(uint64_t)
+
+size_t native_slot_size(upb_fieldtype_t type);
+bool native_slot_set(upb_fieldtype_t type, const zend_class_entry* klass,
+ void* memory, zval* value TSRMLS_DC);
+void native_slot_init(upb_fieldtype_t type, void* memory, zval** cache);
+// For each property, in order to avoid conversion between the zval object and
+// the actual data type during parsing/serialization, the containing message
+// object use the custom memory layout to store the actual data type for each
+// property inside of it. To access a property from php code, the property
+// needs to be converted to a zval object. The message object is not responsible
+// for providing such a zval object. Instead the caller needs to provide one
+// (cache) and update it with the actual data (memory).
+void native_slot_get(upb_fieldtype_t type, const void* memory,
+ zval** cache TSRMLS_DC);
+void native_slot_get_default(upb_fieldtype_t type, zval** cache TSRMLS_DC);
+
+// -----------------------------------------------------------------------------
+// Map Field.
+// -----------------------------------------------------------------------------
+
+extern zend_object_handlers* map_field_handlers;
+
+typedef struct {
+ zend_object std;
+ upb_fieldtype_t key_type;
+ upb_fieldtype_t value_type;
+ const zend_class_entry* msg_ce; // class entry for value message
+ upb_strtable table;
+} Map;
+
+typedef struct {
+ Map* self;
+ upb_strtable_iter it;
+} MapIter;
+
+void map_begin(zval* self, MapIter* iter TSRMLS_DC);
+void map_next(MapIter* iter);
+bool map_done(MapIter* iter);
+const char* map_iter_key(MapIter* iter, int* len);
+upb_value map_iter_value(MapIter* iter, int* len);
+
+// These operate on a map-entry msgdef.
+const upb_fielddef* map_entry_key(const upb_msgdef* msgdef);
+const upb_fielddef* map_entry_value(const upb_msgdef* msgdef);
+
+zend_object_value map_field_create(zend_class_entry *ce TSRMLS_DC);
+void map_field_create_with_field(zend_class_entry *ce, const upb_fielddef *field,
+ zval **map_field TSRMLS_DC);
+void map_field_create_with_type(zend_class_entry *ce, upb_fieldtype_t key_type,
+ upb_fieldtype_t value_type,
+ const zend_class_entry *msg_ce,
+ zval **map_field TSRMLS_DC);
+void map_field_free(void* object TSRMLS_DC);
+void* upb_value_memory(upb_value* v);
+
+#define MAP_KEY_FIELD 1
+#define MAP_VALUE_FIELD 2
+
+// These operate on a map field (i.e., a repeated field of submessages whose
+// submessage type is a map-entry msgdef).
+bool is_map_field(const upb_fielddef* field);
+const upb_fielddef* map_field_key(const upb_fielddef* field);
+const upb_fielddef* map_field_value(const upb_fielddef* field);
+
+bool map_index_set(Map *intern, const char* keyval, int length, upb_value v);
+
+PHP_METHOD(MapField, __construct);
+PHP_METHOD(MapField, offsetExists);
+PHP_METHOD(MapField, offsetGet);
+PHP_METHOD(MapField, offsetSet);
+PHP_METHOD(MapField, offsetUnset);
+PHP_METHOD(MapField, count);
+
+// -----------------------------------------------------------------------------
+// Repeated Field.
+// -----------------------------------------------------------------------------
+
+extern zend_object_handlers* repeated_field_handlers;
+
+struct RepeatedField {
+ zend_object std;
+ zval* array;
+ upb_fieldtype_t type;
+ const zend_class_entry* msg_ce; // class entry for containing message
+ // (for message field only).
+};
+
+struct RepeatedFieldIter {
+ zend_object std;
+ RepeatedField* repeated_field;
+ long position;
+};
+
+void repeated_field_create_with_field(zend_class_entry* ce,
+ const upb_fielddef* field,
+ zval** repeated_field TSRMLS_DC);
+void repeated_field_create_with_type(zend_class_entry* ce, upb_fieldtype_t type,
+ const zend_class_entry* msg_ce,
+ zval** repeated_field TSRMLS_DC);
+// Return the element at the index position from the repeated field. There is
+// not restriction on the type of stored elements.
+void *repeated_field_index_native(RepeatedField *intern, int index TSRMLS_DC);
+// Add the element to the end of the repeated field. There is not restriction on
+// the type of stored elements.
+void repeated_field_push_native(RepeatedField *intern, void *value TSRMLS_DC);
+
+PHP_METHOD(RepeatedField, __construct);
+PHP_METHOD(RepeatedField, append);
+PHP_METHOD(RepeatedField, offsetExists);
+PHP_METHOD(RepeatedField, offsetGet);
+PHP_METHOD(RepeatedField, offsetSet);
+PHP_METHOD(RepeatedField, offsetUnset);
+PHP_METHOD(RepeatedField, count);
+PHP_METHOD(RepeatedField, getIterator);
+
+PHP_METHOD(RepeatedFieldIter, rewind);
+PHP_METHOD(RepeatedFieldIter, current);
+PHP_METHOD(RepeatedFieldIter, key);
+PHP_METHOD(RepeatedFieldIter, next);
+PHP_METHOD(RepeatedFieldIter, valid);
+
+// -----------------------------------------------------------------------------
+// Oneof Field.
+// -----------------------------------------------------------------------------
+
+typedef struct {
+ zend_object std;
+ upb_oneofdef* oneofdef;
+ int index; // Index of field in oneof. -1 if not set.
+ char value[NATIVE_SLOT_MAX_SIZE];
+} Oneof;
+
+// Oneof case slot value to indicate that no oneof case is set. The value `0` is
+// safe because field numbers are used as case identifiers, and no field can
+// have a number of 0.
+#define ONEOF_CASE_NONE 0
+
+// -----------------------------------------------------------------------------
+// Upb.
+// -----------------------------------------------------------------------------
+
+upb_fieldtype_t to_fieldtype(upb_descriptortype_t type);
+const zend_class_entry *field_type_class(const upb_fielddef *field TSRMLS_DC);
+
+// -----------------------------------------------------------------------------
+// Utilities.
+// -----------------------------------------------------------------------------
+
+// PHP <-> C conversion.
+#define UNBOX(class_name, val) \
+ (class_name*)zend_object_store_get_object(val TSRMLS_CC);
+
+#define BOX(class_name, wrapper, intern, free_func) \
+ MAKE_STD_ZVAL(wrapper); \
+ Z_TYPE_P(wrapper) = IS_OBJECT; \
+ Z_OBJVAL_P(wrapper) \
+ .handle = \
+ zend_objects_store_put(intern, NULL, free_func, NULL TSRMLS_CC); \
+ Z_OBJVAL_P(wrapper).handlers = zend_get_std_object_handlers();
+
+// Memory management
+#define ALLOC(class_name) (class_name*) emalloc(sizeof(class_name))
+#define PEMALLOC(class_name) (class_name*) pemalloc(sizeof(class_name), 1)
+#define ALLOC_N(class_name, n) (class_name*) emalloc(sizeof(class_name) * n)
+#define FREE(object) efree(object)
+#define PEFREE(object) pefree(object, 1)
+
+// Create PHP internal instance.
+#define CREATE(class_name, intern, init_func) \
+ intern = ALLOC(class_name); \
+ memset(intern, 0, sizeof(class_name)); \
+ init_func(intern TSRMLS_CC);
+
+// String argument.
+#define STR(str) (str), strlen(str)
+
+// Zend Value
+#define Z_OBJ_P(zval_p) \
+ ((zend_object*)(EG(objects_store) \
+ .object_buckets[Z_OBJ_HANDLE_P(zval_p)] \
+ .bucket.obj.object))
+
+#endif // __GOOGLE_PROTOBUF_PHP_PROTOBUF_H__
diff --git a/third_party/protobuf/php/ext/google/protobuf/storage.c b/third_party/protobuf/php/ext/google/protobuf/storage.c
new file mode 100644
index 0000000000..af7c292f0f
--- /dev/null
+++ b/third_party/protobuf/php/ext/google/protobuf/storage.c
@@ -0,0 +1,835 @@
+// 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 <stdint.h>
+#include <protobuf.h>
+#include <Zend/zend.h>
+
+#include "utf8.h"
+
+// -----------------------------------------------------------------------------
+// Native slot storage.
+// -----------------------------------------------------------------------------
+
+#define DEREF(memory, type) *(type*)(memory)
+
+size_t native_slot_size(upb_fieldtype_t type) {
+ switch (type) {
+ case UPB_TYPE_FLOAT: return 4;
+ case UPB_TYPE_DOUBLE: return 8;
+ case UPB_TYPE_BOOL: return 1;
+ case UPB_TYPE_STRING: return sizeof(void*);
+ case UPB_TYPE_BYTES: return sizeof(void*);
+ case UPB_TYPE_MESSAGE: return sizeof(void*);
+ case UPB_TYPE_ENUM: return 4;
+ case UPB_TYPE_INT32: return 4;
+ case UPB_TYPE_INT64: return 8;
+ case UPB_TYPE_UINT32: return 4;
+ case UPB_TYPE_UINT64: return 8;
+ default: return 0;
+ }
+}
+
+static bool native_slot_is_default(upb_fieldtype_t type, void* memory) {
+ switch (type) {
+#define CASE_TYPE(upb_type, c_type) \
+ case UPB_TYPE_##upb_type: { \
+ return DEREF(memory, c_type) == 0; \
+ }
+ CASE_TYPE(INT32, int32_t )
+ CASE_TYPE(UINT32, uint32_t)
+ CASE_TYPE(ENUM, int32_t )
+ CASE_TYPE(INT64, int64_t )
+ CASE_TYPE(UINT64, uint64_t)
+ CASE_TYPE(FLOAT, float )
+ CASE_TYPE(DOUBLE, double )
+ CASE_TYPE(BOOL, int8_t )
+
+#undef CASE_TYPE
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ return Z_STRLEN_PP(DEREF(memory, zval**)) == 0;
+ case UPB_TYPE_MESSAGE:
+ return Z_TYPE_PP(DEREF(memory, zval**)) == IS_NULL;
+ default: return false;
+ }
+}
+
+bool native_slot_set(upb_fieldtype_t type, const zend_class_entry* klass,
+ void* memory, zval* value TSRMLS_DC) {
+ switch (type) {
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ if (!protobuf_convert_to_string(value)) {
+ return false;
+ }
+ if (type == UPB_TYPE_STRING &&
+ !is_structurally_valid_utf8(Z_STRVAL_P(value), Z_STRLEN_P(value))) {
+ zend_error(E_USER_ERROR, "Given string is not UTF8 encoded.");
+ return false;
+ }
+ if (*(zval**)memory != NULL) {
+ REPLACE_ZVAL_VALUE((zval**)memory, value, 1);
+ } else {
+ // Handles repeated/map string field. Memory provided by
+ // RepeatedField/Map is not initialized.
+ MAKE_STD_ZVAL(DEREF(memory, zval*));
+ ZVAL_STRINGL(DEREF(memory, zval*), Z_STRVAL_P(value), Z_STRLEN_P(value),
+ 1);
+ }
+ break;
+ }
+ case UPB_TYPE_MESSAGE: {
+ if (Z_TYPE_P(value) != IS_OBJECT && Z_TYPE_P(value) != IS_NULL) {
+ zend_error(E_USER_ERROR, "Given value is not message.");
+ return false;
+ }
+ if (Z_TYPE_P(value) == IS_OBJECT && klass != Z_OBJCE_P(value)) {
+ zend_error(E_USER_ERROR, "Given message does not have correct class.");
+ return false;
+ }
+ if (EXPECTED(DEREF(memory, zval*) != value)) {
+ if (DEREF(memory, zval*) != NULL) {
+ zval_ptr_dtor((zval**)memory);
+ }
+ DEREF(memory, zval*) = value;
+ Z_ADDREF_P(value);
+ }
+ break;
+ }
+
+#define CASE_TYPE(upb_type, type, c_type, php_type) \
+ case UPB_TYPE_##upb_type: { \
+ c_type type##_value; \
+ if (protobuf_convert_to_##type(value, &type##_value)) { \
+ DEREF(memory, c_type) = type##_value; \
+ } \
+ break; \
+ }
+ CASE_TYPE(INT32, int32, int32_t, LONG)
+ CASE_TYPE(UINT32, uint32, uint32_t, LONG)
+ CASE_TYPE(ENUM, int32, int32_t, LONG)
+ CASE_TYPE(INT64, int64, int64_t, LONG)
+ CASE_TYPE(UINT64, uint64, uint64_t, LONG)
+ CASE_TYPE(FLOAT, float, float, DOUBLE)
+ CASE_TYPE(DOUBLE, double, double, DOUBLE)
+ CASE_TYPE(BOOL, bool, int8_t, BOOL)
+
+#undef CASE_TYPE
+
+ default:
+ break;
+ }
+
+ return true;
+}
+
+void native_slot_init(upb_fieldtype_t type, void* memory, zval** cache) {
+ zval* tmp = NULL;
+ switch (type) {
+ case UPB_TYPE_FLOAT:
+ DEREF(memory, float) = 0.0;
+ break;
+ case UPB_TYPE_DOUBLE:
+ DEREF(memory, double) = 0.0;
+ break;
+ case UPB_TYPE_BOOL:
+ DEREF(memory, int8_t) = 0;
+ break;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_MESSAGE:
+ DEREF(memory, zval**) = cache;
+ break;
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32:
+ DEREF(memory, int32_t) = 0;
+ break;
+ case UPB_TYPE_INT64:
+ DEREF(memory, int64_t) = 0;
+ break;
+ case UPB_TYPE_UINT32:
+ DEREF(memory, uint32_t) = 0;
+ break;
+ case UPB_TYPE_UINT64:
+ DEREF(memory, uint64_t) = 0;
+ break;
+ default:
+ break;
+ }
+}
+
+void native_slot_get(upb_fieldtype_t type, const void* memory,
+ zval** cache TSRMLS_DC) {
+ switch (type) {
+#define CASE(upb_type, php_type, c_type) \
+ case UPB_TYPE_##upb_type: \
+ SEPARATE_ZVAL_IF_NOT_REF(cache); \
+ ZVAL_##php_type(*cache, DEREF(memory, c_type)); \
+ return;
+
+CASE(FLOAT, DOUBLE, float)
+CASE(DOUBLE, DOUBLE, double)
+CASE(BOOL, BOOL, int8_t)
+CASE(INT32, LONG, int32_t)
+CASE(ENUM, LONG, uint32_t)
+
+#undef CASE
+
+#if SIZEOF_LONG == 4
+#define CASE(upb_type, c_type) \
+ case UPB_TYPE_##upb_type: { \
+ SEPARATE_ZVAL_IF_NOT_REF(cache); \
+ char buffer[MAX_LENGTH_OF_INT64]; \
+ sprintf(buffer, "%lld", DEREF(memory, c_type)); \
+ ZVAL_STRING(*cache, buffer, 1); \
+ return; \
+ }
+#else
+#define CASE(upb_type, c_type) \
+ case UPB_TYPE_##upb_type: { \
+ SEPARATE_ZVAL_IF_NOT_REF(cache); \
+ ZVAL_LONG(*cache, DEREF(memory, c_type)); \
+ return; \
+ }
+#endif
+CASE(UINT64, uint64_t)
+CASE(INT64, int64_t)
+#undef CASE
+
+ case UPB_TYPE_UINT32: {
+ // Prepend bit-1 for negative numbers, so that uint32 value will be
+ // consistent on both 32-bit and 64-bit architectures.
+ SEPARATE_ZVAL_IF_NOT_REF(cache);
+ int value = DEREF(memory, int32_t);
+ if (sizeof(int) == 8) {
+ value |= (-((value >> 31) & 0x1) & 0xFFFFFFFF00000000);
+ }
+ ZVAL_LONG(*cache, value);
+ return;
+ }
+
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ // For optional string/bytes fields, the cache is owned by the containing
+ // message and should have been updated during setting/decoding. However,
+ // for repeated string/bytes fields, the cache is provided by zend engine
+ // and has not been updated.
+ zval* value = DEREF(memory, zval*);
+ if (*cache != value) {
+ ZVAL_STRINGL(*cache, Z_STRVAL_P(value), Z_STRLEN_P(value), 1);
+ }
+ break;
+ }
+ case UPB_TYPE_MESSAGE: {
+ // Same as above for string/bytes fields.
+ zval* value = DEREF(memory, zval*);
+ if (*cache != value) {
+ ZVAL_ZVAL(*cache, value, 1, 0);
+ }
+ return;
+ }
+ default:
+ return;
+ }
+}
+
+void native_slot_get_default(upb_fieldtype_t type, zval** cache TSRMLS_DC) {
+ switch (type) {
+#define CASE(upb_type, php_type) \
+ case UPB_TYPE_##upb_type: \
+ SEPARATE_ZVAL_IF_NOT_REF(cache); \
+ ZVAL_##php_type(*cache, 0); \
+ return;
+
+ CASE(FLOAT, DOUBLE)
+ CASE(DOUBLE, DOUBLE)
+ CASE(BOOL, BOOL)
+ CASE(INT32, LONG)
+ CASE(UINT32, LONG)
+ CASE(ENUM, LONG)
+
+#undef CASE
+
+#if SIZEOF_LONG == 4
+#define CASE(upb_type) \
+ case UPB_TYPE_##upb_type: { \
+ SEPARATE_ZVAL_IF_NOT_REF(cache); \
+ ZVAL_STRING(*cache, "0", 1); \
+ return; \
+ }
+#else
+#define CASE(upb_type) \
+ case UPB_TYPE_##upb_type: { \
+ SEPARATE_ZVAL_IF_NOT_REF(cache); \
+ ZVAL_LONG(*cache, 0); \
+ return; \
+ }
+#endif
+CASE(UINT64)
+CASE(INT64)
+#undef CASE
+
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ SEPARATE_ZVAL_IF_NOT_REF(cache);
+ ZVAL_STRINGL(*cache, "", 0, 1);
+ break;
+ }
+ case UPB_TYPE_MESSAGE: {
+ SEPARATE_ZVAL_IF_NOT_REF(cache);
+ ZVAL_NULL(*cache);
+ return;
+ }
+ default:
+ return;
+ }
+}
+
+// -----------------------------------------------------------------------------
+// Map field utilities.
+// ----------------------------------------------------------------------------
+
+const upb_msgdef* tryget_map_entry_msgdef(const upb_fielddef* field) {
+ const upb_msgdef* subdef;
+ if (upb_fielddef_label(field) != UPB_LABEL_REPEATED ||
+ upb_fielddef_type(field) != UPB_TYPE_MESSAGE) {
+ return NULL;
+ }
+ subdef = upb_fielddef_msgsubdef(field);
+ return upb_msgdef_mapentry(subdef) ? subdef : NULL;
+}
+
+const upb_msgdef* map_entry_msgdef(const upb_fielddef* field) {
+ const upb_msgdef* subdef = tryget_map_entry_msgdef(field);
+ assert(subdef);
+ return subdef;
+}
+
+bool is_map_field(const upb_fielddef* field) {
+ return tryget_map_entry_msgdef(field) != NULL;
+}
+
+const upb_fielddef* map_field_key(const upb_fielddef* field) {
+ const upb_msgdef* subdef = map_entry_msgdef(field);
+ return map_entry_key(subdef);
+}
+
+const upb_fielddef* map_field_value(const upb_fielddef* field) {
+ const upb_msgdef* subdef = map_entry_msgdef(field);
+ return map_entry_value(subdef);
+}
+
+const upb_fielddef* map_entry_key(const upb_msgdef* msgdef) {
+ const upb_fielddef* key_field = upb_msgdef_itof(msgdef, MAP_KEY_FIELD);
+ assert(key_field != NULL);
+ return key_field;
+}
+
+const upb_fielddef* map_entry_value(const upb_msgdef* msgdef) {
+ const upb_fielddef* value_field = upb_msgdef_itof(msgdef, MAP_VALUE_FIELD);
+ assert(value_field != NULL);
+ return value_field;
+}
+
+const zend_class_entry* field_type_class(const upb_fielddef* field TSRMLS_DC) {
+ if (upb_fielddef_type(field) == UPB_TYPE_MESSAGE) {
+ zval* desc_php = get_def_obj(upb_fielddef_subdef(field));
+ Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC);
+ return desc->klass;
+ } else if (upb_fielddef_type(field) == UPB_TYPE_ENUM) {
+ zval* desc_php = get_def_obj(upb_fielddef_subdef(field));
+ EnumDescriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC);
+ return desc->klass;
+ }
+ return NULL;
+}
+
+// -----------------------------------------------------------------------------
+// Memory layout management.
+// -----------------------------------------------------------------------------
+
+static size_t align_up_to(size_t offset, size_t granularity) {
+ // Granularity must be a power of two.
+ return (offset + granularity - 1) & ~(granularity - 1);
+}
+
+static void* slot_memory(MessageLayout* layout, const void* storage,
+ const upb_fielddef* field) {
+ return ((uint8_t*)storage) + layout->fields[upb_fielddef_index(field)].offset;
+}
+
+static uint32_t* slot_oneof_case(MessageLayout* layout, const void* storage,
+ const upb_fielddef* field) {
+ return (uint32_t*)(((uint8_t*)storage) +
+ layout->fields[upb_fielddef_index(field)].case_offset);
+}
+
+static int slot_property_cache(MessageLayout* layout, const void* storage,
+ const upb_fielddef* field) {
+ return layout->fields[upb_fielddef_index(field)].cache_index;
+}
+
+MessageLayout* create_layout(const upb_msgdef* msgdef) {
+ MessageLayout* layout = ALLOC(MessageLayout);
+ int nfields = upb_msgdef_numfields(msgdef);
+ upb_msg_field_iter it;
+ upb_msg_oneof_iter oit;
+ size_t off = 0;
+ int i = 0;
+
+ layout->fields = ALLOC_N(MessageField, nfields);
+
+ for (upb_msg_field_begin(&it, msgdef); !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* field = upb_msg_iter_field(&it);
+ size_t field_size;
+
+ if (upb_fielddef_containingoneof(field)) {
+ // Oneofs are handled separately below.
+ continue;
+ }
+
+ // Allocate |field_size| bytes for this field in the layout.
+ field_size = 0;
+ if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
+ field_size = sizeof(zval*);
+ } else {
+ field_size = native_slot_size(upb_fielddef_type(field));
+ }
+
+ // Align current offset up to | size | granularity.
+ off = align_up_to(off, field_size);
+ layout->fields[upb_fielddef_index(field)].offset = off;
+ layout->fields[upb_fielddef_index(field)].case_offset =
+ MESSAGE_FIELD_NO_CASE;
+ layout->fields[upb_fielddef_index(field)].cache_index = i++;
+ off += field_size;
+ }
+
+ // Handle oneofs now -- we iterate over oneofs specifically and allocate only
+ // one slot per oneof.
+ //
+ // We assign all value slots first, then pack the 'case' fields at the end,
+ // since in the common case (modern 64-bit platform) these are 8 bytes and 4
+ // bytes respectively and we want to avoid alignment overhead.
+ //
+ // Note that we reserve 4 bytes (a uint32) per 'case' slot because the value
+ // space for oneof cases is conceptually as wide as field tag numbers. In
+ // practice, it's unlikely that a oneof would have more than e.g. 256 or 64K
+ // members (8 or 16 bits respectively), so conceivably we could assign
+ // consecutive case numbers and then pick a smaller oneof case slot size, but
+ // the complexity to implement this indirection is probably not worthwhile.
+ for (upb_msg_oneof_begin(&oit, msgdef); !upb_msg_oneof_done(&oit);
+ upb_msg_oneof_next(&oit)) {
+ const upb_oneofdef* oneof = upb_msg_iter_oneof(&oit);
+ upb_oneof_iter fit;
+
+ // Always allocate NATIVE_SLOT_MAX_SIZE bytes, but share the slot between
+ // all fields.
+ size_t field_size = NATIVE_SLOT_MAX_SIZE;
+ // Align the offset .
+ off = align_up_to( off, field_size);
+ // Assign all fields in the oneof this same offset.
+ for (upb_oneof_begin(&fit, oneof); !upb_oneof_done(&fit);
+ upb_oneof_next(&fit)) {
+ const upb_fielddef* field = upb_oneof_iter_field(&fit);
+ layout->fields[upb_fielddef_index(field)].offset = off;
+ layout->fields[upb_fielddef_index(field)].cache_index = i;
+ }
+ i++;
+ off += field_size;
+ }
+
+ // Now the case offset.
+ for (upb_msg_oneof_begin(&oit, msgdef); !upb_msg_oneof_done(&oit);
+ upb_msg_oneof_next(&oit)) {
+ const upb_oneofdef* oneof = upb_msg_iter_oneof(&oit);
+ upb_oneof_iter fit;
+
+ size_t field_size = sizeof(uint32_t);
+ // Align the offset .
+ off = (off + field_size - 1) & ~(field_size - 1);
+ // Assign all fields in the oneof this same offset.
+ for (upb_oneof_begin(&fit, oneof); !upb_oneof_done(&fit);
+ upb_oneof_next(&fit)) {
+ const upb_fielddef* field = upb_oneof_iter_field(&fit);
+ layout->fields[upb_fielddef_index(field)].case_offset = off;
+ }
+ off += field_size;
+ }
+
+ layout->size = off;
+
+ layout->msgdef = msgdef;
+ upb_msgdef_ref(layout->msgdef, &layout->msgdef);
+
+ return layout;
+}
+
+void free_layout(MessageLayout* layout) {
+ FREE(layout->fields);
+ upb_msgdef_unref(layout->msgdef, &layout->msgdef);
+ FREE(layout);
+}
+
+void layout_init(MessageLayout* layout, void* storage,
+ zval** properties_table TSRMLS_DC) {
+ int i;
+ upb_msg_field_iter it;
+ for (upb_msg_field_begin(&it, layout->msgdef), i = 0; !upb_msg_field_done(&it);
+ upb_msg_field_next(&it), i++) {
+ const upb_fielddef* field = upb_msg_iter_field(&it);
+ void* memory = slot_memory(layout, storage, field);
+ uint32_t* oneof_case = slot_oneof_case(layout, storage, field);
+ int cache_index = slot_property_cache(layout, storage, field);
+ zval** property_ptr = &properties_table[cache_index];
+
+ if (upb_fielddef_containingoneof(field)) {
+ memset(memory, 0, NATIVE_SLOT_MAX_SIZE);
+ *oneof_case = ONEOF_CASE_NONE;
+ } else if (is_map_field(field)) {
+ zval_ptr_dtor(property_ptr);
+ map_field_create_with_field(map_field_type, field, property_ptr TSRMLS_CC);
+ DEREF(memory, zval**) = property_ptr;
+ } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
+ zval_ptr_dtor(property_ptr);
+ repeated_field_create_with_field(repeated_field_type, field,
+ property_ptr TSRMLS_CC);
+ DEREF(memory, zval**) = property_ptr;
+ } else {
+ native_slot_init(upb_fielddef_type(field), memory, property_ptr);
+ }
+ }
+}
+
+// For non-singular fields, the related memory needs to point to the actual
+// zval in properties table first.
+static void* value_memory(const upb_fielddef* field, void* memory) {
+ switch (upb_fielddef_type(field)) {
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_MESSAGE:
+ memory = DEREF(memory, zval**);
+ break;
+ default:
+ // No operation
+ break;
+ }
+ return memory;
+}
+
+zval* layout_get(MessageLayout* layout, const void* storage,
+ const upb_fielddef* field, zval** cache TSRMLS_DC) {
+ void* memory = slot_memory(layout, storage, field);
+ uint32_t* oneof_case = slot_oneof_case(layout, storage, field);
+
+ if (upb_fielddef_containingoneof(field)) {
+ if (*oneof_case != upb_fielddef_number(field)) {
+ native_slot_get_default(upb_fielddef_type(field), cache TSRMLS_CC);
+ } else {
+ native_slot_get(upb_fielddef_type(field), value_memory(field, memory),
+ cache TSRMLS_CC);
+ }
+ return *cache;
+ } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
+ return *cache;
+ } else {
+ native_slot_get(upb_fielddef_type(field), value_memory(field, memory),
+ cache TSRMLS_CC);
+ return *cache;
+ }
+}
+
+void layout_set(MessageLayout* layout, MessageHeader* header,
+ const upb_fielddef* field, zval* val TSRMLS_DC) {
+ void* storage = message_data(header);
+ void* memory = slot_memory(layout, storage, field);
+ uint32_t* oneof_case = slot_oneof_case(layout, storage, field);
+
+ if (upb_fielddef_containingoneof(field)) {
+ upb_fieldtype_t type = upb_fielddef_type(field);
+ zend_class_entry *ce = NULL;
+
+ // For non-singular fields, the related memory needs to point to the actual
+ // zval in properties table first.
+ switch (type) {
+ case UPB_TYPE_MESSAGE: {
+ const upb_msgdef* msg = upb_fielddef_msgsubdef(field);
+ zval* desc_php = get_def_obj(msg);
+ Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC);
+ ce = desc->klass;
+ // Intentionally fall through.
+ }
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ int property_cache_index =
+ header->descriptor->layout->fields[upb_fielddef_index(field)]
+ .cache_index;
+ DEREF(memory, zval**) =
+ &(header->std.properties_table)[property_cache_index];
+ memory = DEREF(memory, zval**);
+ break;
+ }
+ default:
+ break;
+ }
+
+ native_slot_set(type, ce, memory, val TSRMLS_CC);
+ *oneof_case = upb_fielddef_number(field);
+ } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
+ // Works for both repeated and map fields
+ memory = DEREF(memory, zval**);
+ if (EXPECTED(DEREF(memory, zval*) != val)) {
+ zval_ptr_dtor(memory);
+ DEREF(memory, zval*) = val;
+ Z_ADDREF_P(val);
+ }
+ } else {
+ upb_fieldtype_t type = upb_fielddef_type(field);
+ zend_class_entry *ce = NULL;
+ if (type == UPB_TYPE_MESSAGE) {
+ const upb_msgdef* msg = upb_fielddef_msgsubdef(field);
+ zval* desc_php = get_def_obj(msg);
+ Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC);
+ ce = desc->klass;
+ }
+ native_slot_set(type, ce, value_memory(field, memory), val TSRMLS_CC);
+ }
+}
+
+void layout_merge(MessageLayout* layout, MessageHeader* from,
+ MessageHeader* to TSRMLS_DC) {
+ int i, j;
+ upb_msg_field_iter it;
+
+ for (upb_msg_field_begin(&it, layout->msgdef), i = 0; !upb_msg_field_done(&it);
+ upb_msg_field_next(&it), i++) {
+ const upb_fielddef* field = upb_msg_iter_field(&it);
+
+ void* to_memory = slot_memory(layout, message_data(to), field);
+ void* from_memory = slot_memory(layout, message_data(from), field);
+
+ if (upb_fielddef_containingoneof(field)) {
+ uint32_t oneof_case_offset =
+ layout->fields[upb_fielddef_index(field)].case_offset +
+ sizeof(MessageHeader);
+ // For a oneof, check that this field is actually present -- skip all the
+ // below if not.
+ if (DEREF(((uint8_t*)from + oneof_case_offset), uint32_t) !=
+ upb_fielddef_number(field)) {
+ continue;
+ }
+ uint32_t* from_oneof_case = slot_oneof_case(layout, message_data(from), field);
+ uint32_t* to_oneof_case = slot_oneof_case(layout, message_data(to), field);
+
+ // For non-singular fields, the related memory needs to point to the
+ // actual zval in properties table first.
+ switch (upb_fielddef_type(field)) {
+ case UPB_TYPE_MESSAGE:
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ int property_cache_index =
+ layout->fields[upb_fielddef_index(field)].cache_index;
+ DEREF(to_memory, zval**) =
+ &(to->std.properties_table)[property_cache_index];
+ break;
+ }
+ default:
+ break;
+ }
+
+ *to_oneof_case = *from_oneof_case;
+
+ // Otherwise, fall through to the appropriate singular-field handler
+ // below.
+ }
+
+ if (is_map_field(field)) {
+ int size, key_length, value_length;
+ MapIter map_it;
+
+ zval* to_map_php = *DEREF(to_memory, zval**);
+ zval* from_map_php = *DEREF(from_memory, zval**);
+ Map* to_map = zend_object_store_get_object(to_map_php TSRMLS_CC);
+ Map* from_map = zend_object_store_get_object(from_map_php TSRMLS_CC);
+
+ size = upb_strtable_count(&from_map->table);
+ if (size == 0) continue;
+
+ for (map_begin(from_map_php, &map_it TSRMLS_CC); !map_done(&map_it);
+ map_next(&map_it)) {
+ const char* key = map_iter_key(&map_it, &key_length);
+ upb_value value = map_iter_value(&map_it, &value_length);
+ void* mem = upb_value_memory(&value);
+ switch (to_map->value_type) {
+ case UPB_TYPE_MESSAGE: {
+ zval* new_message;
+ message_create_with_type(to_map->msg_ce, &new_message TSRMLS_CC);
+ Z_ADDREF_P(new_message);
+
+ zval* subdesc_php = get_ce_obj(to_map->msg_ce);
+ Descriptor* subdesc =
+ zend_object_store_get_object(subdesc_php TSRMLS_CC);
+ MessageHeader* sub_from =
+ (MessageHeader*)zend_object_store_get_object(DEREF(mem, zval*)
+ TSRMLS_CC);
+ MessageHeader* sub_to =
+ (MessageHeader*)zend_object_store_get_object(
+ new_message TSRMLS_CC);
+ layout_merge(subdesc->layout, sub_from, sub_to TSRMLS_CC);
+ DEREF(mem, zval*) = new_message;
+ break;
+ }
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_STRING:
+ Z_ADDREF_PP((zval**)mem);
+ break;
+ default:
+ break;
+ }
+ map_index_set(to_map, key, key_length, value);
+ }
+
+ } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
+ zval* to_array_php = *DEREF(to_memory, zval**);
+ zval* from_array_php = *DEREF(from_memory, zval**);
+ RepeatedField* to_array =
+ zend_object_store_get_object(to_array_php TSRMLS_CC);
+ RepeatedField* from_array =
+ zend_object_store_get_object(from_array_php TSRMLS_CC);
+
+ int size = zend_hash_num_elements(HASH_OF(from_array->array));
+ if (size > 0) {
+ for (j = 0; j < size; j++) {
+ void* memory = NULL;
+ zend_hash_index_find(HASH_OF(from_array->array), j, (void**)&memory);
+ switch (to_array->type) {
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ zval* str;
+ MAKE_STD_ZVAL(str);
+ ZVAL_STRINGL(str, Z_STRVAL_PP((zval**)memory),
+ Z_STRLEN_PP((zval**)memory), 1);
+ memory = &str;
+ break;
+ }
+ case UPB_TYPE_MESSAGE: {
+ zval* new_message;
+ message_create_with_type(from_array->msg_ce, &new_message TSRMLS_CC);
+ Z_ADDREF_P(new_message);
+
+ zval* subdesc_php = get_ce_obj(from_array->msg_ce);
+ Descriptor* subdesc =
+ zend_object_store_get_object(subdesc_php TSRMLS_CC);
+ MessageHeader* sub_from =
+ (MessageHeader*)zend_object_store_get_object(
+ DEREF(memory, zval*) TSRMLS_CC);
+ MessageHeader* sub_to =
+ (MessageHeader*)zend_object_store_get_object(
+ new_message TSRMLS_CC);
+ layout_merge(subdesc->layout, sub_from, sub_to TSRMLS_CC);
+
+ memory = &new_message;
+ }
+ default:
+ break;
+ }
+ repeated_field_push_native(to_array, memory TSRMLS_CC);
+ }
+ }
+ } else {
+ upb_fieldtype_t type = upb_fielddef_type(field);
+ zend_class_entry *ce = NULL;
+ if (!native_slot_is_default(type, from_memory)) {
+ switch (type) {
+#define CASE_TYPE(upb_type, c_type) \
+ case UPB_TYPE_##upb_type: { \
+ DEREF(to_memory, c_type) = DEREF(from_memory, c_type); \
+ break; \
+ }
+ CASE_TYPE(INT32, int32_t)
+ CASE_TYPE(UINT32, uint32_t)
+ CASE_TYPE(ENUM, int32_t)
+ CASE_TYPE(INT64, int64_t)
+ CASE_TYPE(UINT64, uint64_t)
+ CASE_TYPE(FLOAT, float)
+ CASE_TYPE(DOUBLE, double)
+ CASE_TYPE(BOOL, int8_t)
+
+#undef CASE_TYPE
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ native_slot_set(type, NULL, value_memory(field, to_memory),
+ *DEREF(from_memory, zval**) TSRMLS_CC);
+ break;
+ case UPB_TYPE_MESSAGE: {
+ const upb_msgdef* msg = upb_fielddef_msgsubdef(field);
+ zval* desc_php = get_def_obj(msg);
+ Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC);
+ ce = desc->klass;
+ if (native_slot_is_default(type, to_memory)) {
+ zval* new_message = NULL;
+ message_create_with_type(ce, &new_message TSRMLS_CC);
+ native_slot_set(type, ce, value_memory(field, to_memory),
+ new_message TSRMLS_CC);
+ }
+ MessageHeader* sub_from =
+ (MessageHeader*)zend_object_store_get_object(
+ *DEREF(from_memory, zval**) TSRMLS_CC);
+ MessageHeader* sub_to =
+ (MessageHeader*)zend_object_store_get_object(
+ *DEREF(to_memory, zval**) TSRMLS_CC);
+ layout_merge(desc->layout, sub_from, sub_to TSRMLS_CC);
+ }
+ }
+ }
+ }
+ }
+}
+
+const char* layout_get_oneof_case(MessageLayout* layout, const void* storage,
+ const upb_oneofdef* oneof TSRMLS_DC) {
+ upb_oneof_iter i;
+ const upb_fielddef* first_field;
+
+ // Oneof is guaranteed to have at least one field. Get the first field.
+ for(upb_oneof_begin(&i, oneof); !upb_oneof_done(&i); upb_oneof_next(&i)) {
+ first_field = upb_oneof_iter_field(&i);
+ break;
+ }
+
+ uint32_t* oneof_case = slot_oneof_case(layout, storage, first_field);
+ if (*oneof_case == 0) {
+ return "";
+ }
+ const upb_fielddef* field = upb_oneofdef_itof(oneof, *oneof_case);
+ return upb_fielddef_name(field);
+}
diff --git a/third_party/protobuf/php/ext/google/protobuf/type_check.c b/third_party/protobuf/php/ext/google/protobuf/type_check.c
new file mode 100644
index 0000000000..fe9b18f0e3
--- /dev/null
+++ b/third_party/protobuf/php/ext/google/protobuf/type_check.c
@@ -0,0 +1,532 @@
+// 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 <Zend/zend_operators.h>
+
+#include "protobuf.h"
+#include "utf8.h"
+
+static zend_class_entry* util_type;
+static const char int64_min_digits[] = "9223372036854775808";
+
+ZEND_BEGIN_ARG_INFO_EX(arg_check_optional, 0, 0, 1)
+ ZEND_ARG_INFO(1, val)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arg_check_message, 0, 0, 2)
+ ZEND_ARG_INFO(1, val)
+ ZEND_ARG_INFO(0, klass)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arg_check_repeated, 0, 0, 2)
+ ZEND_ARG_INFO(1, val)
+ ZEND_ARG_INFO(0, type)
+ ZEND_ARG_INFO(0, klass)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arg_check_map, 0, 0, 3)
+ ZEND_ARG_INFO(1, val)
+ ZEND_ARG_INFO(0, key_type)
+ ZEND_ARG_INFO(0, value_type)
+ ZEND_ARG_INFO(0, klass)
+ZEND_END_ARG_INFO()
+
+static zend_function_entry util_methods[] = {
+ PHP_ME(Util, checkInt32, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkUint32, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkInt64, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkUint64, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkEnum, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkFloat, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkDouble, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkBool, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkString, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkBytes, arg_check_optional, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkMessage, arg_check_message, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkMapField, arg_check_map, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkRepeatedField, arg_check_repeated,
+ ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ ZEND_FE_END
+};
+
+void util_init(TSRMLS_D) {
+ zend_class_entry class_type;
+ INIT_CLASS_ENTRY(class_type, "Google\\Protobuf\\Internal\\GPBUtil",
+ util_methods);
+ util_type = zend_register_internal_class(&class_type TSRMLS_CC);
+}
+
+// -----------------------------------------------------------------------------
+// Type checking/conversion.
+// -----------------------------------------------------------------------------
+
+// This is modified from is_numeric_string in zend_operators.h. The behavior of
+// this function is the same as is_numeric_string, except that this takes
+// int64_t as input instead of long.
+static zend_uchar convert_numeric_string(
+ const char *str, int length, int64_t *lval, double *dval) {
+ const char *ptr;
+ int base = 10, digits = 0, dp_or_e = 0;
+ double local_dval = 0.0;
+ zend_uchar type;
+
+ if (length == 0) {
+ return IS_NULL;
+ }
+
+ while (*str == ' ' || *str == '\t' || *str == '\n' ||
+ *str == '\r' || *str == '\v' || *str == '\f') {
+ str++;
+ length--;
+ }
+ ptr = str;
+
+ if (*ptr == '-' || *ptr == '+') {
+ ptr++;
+ }
+
+ if (ZEND_IS_DIGIT(*ptr)) {
+ // Handle hex numbers
+ // str is used instead of ptr to disallow signs and keep old behavior.
+ if (length > 2 && *str == '0' && (str[1] == 'x' || str[1] == 'X')) {
+ base = 16;
+ ptr += 2;
+ }
+
+ // Skip any leading 0s.
+ while (*ptr == '0') {
+ ptr++;
+ }
+
+ // Count the number of digits. If a decimal point/exponent is found,
+ // it's a double. Otherwise, if there's a dval or no need to check for
+ // a full match, stop when there are too many digits for a int64 */
+ for (type = IS_LONG;
+ !(digits >= MAX_LENGTH_OF_INT64 && dval);
+ digits++, ptr++) {
+check_digits:
+ if (ZEND_IS_DIGIT(*ptr) || (base == 16 && ZEND_IS_XDIGIT(*ptr))) {
+ continue;
+ } else if (base == 10) {
+ if (*ptr == '.' && dp_or_e < 1) {
+ goto process_double;
+ } else if ((*ptr == 'e' || *ptr == 'E') && dp_or_e < 2) {
+ const char *e = ptr + 1;
+
+ if (*e == '-' || *e == '+') {
+ ptr = e++;
+ }
+ if (ZEND_IS_DIGIT(*e)) {
+ goto process_double;
+ }
+ }
+ }
+ break;
+ }
+
+ if (base == 10) {
+ if (digits >= MAX_LENGTH_OF_INT64) {
+ dp_or_e = -1;
+ goto process_double;
+ }
+ } else if (!(digits < SIZEOF_INT64 * 2 ||
+ (digits == SIZEOF_INT64 * 2 && ptr[-digits] <= '7'))) {
+ if (dval) {
+ local_dval = zend_hex_strtod(str, &ptr);
+ }
+ type = IS_DOUBLE;
+ }
+ } else if (*ptr == '.' && ZEND_IS_DIGIT(ptr[1])) {
+process_double:
+ type = IS_DOUBLE;
+
+ // If there's a dval, do the conversion; else continue checking
+ // the digits if we need to check for a full match.
+ if (dval) {
+ local_dval = zend_strtod(str, &ptr);
+ } else if (dp_or_e != -1) {
+ dp_or_e = (*ptr++ == '.') ? 1 : 2;
+ goto check_digits;
+ }
+ } else {
+ return IS_NULL;
+ }
+ if (ptr != str + length) {
+ zend_error(E_NOTICE, "A non well formed numeric value encountered");
+ return 0;
+ }
+
+ if (type == IS_LONG) {
+ if (digits == MAX_LENGTH_OF_INT64 - 1) {
+ int cmp = strcmp(&ptr[-digits], int64_min_digits);
+
+ if (!(cmp < 0 || (cmp == 0 && *str == '-'))) {
+ if (dval) {
+ *dval = zend_strtod(str, NULL);
+ }
+
+ return IS_DOUBLE;
+ }
+ }
+ if (lval) {
+ *lval = strtoll(str, NULL, base);
+ }
+ return IS_LONG;
+ } else {
+ if (dval) {
+ *dval = local_dval;
+ }
+ return IS_DOUBLE;
+ }
+}
+
+#define CONVERT_TO_INTEGER(type) \
+ static bool convert_int64_to_##type(int64_t val, type##_t* type##_value) { \
+ *type##_value = (type##_t)val; \
+ return true; \
+ } \
+ \
+ static bool convert_double_to_##type(double val, type##_t* type##_value) { \
+ *type##_value = (type##_t)zend_dval_to_lval(val); \
+ return true; \
+ } \
+ \
+ static bool convert_string_to_##type(const char* val, int len, \
+ type##_t* type##_value) { \
+ int64_t lval; \
+ double dval; \
+ \
+ switch (convert_numeric_string(val, len, &lval, &dval)) { \
+ case IS_DOUBLE: { \
+ return convert_double_to_##type(dval, type##_value); \
+ } \
+ case IS_LONG: { \
+ return convert_int64_to_##type(lval, type##_value); \
+ } \
+ default: \
+ zend_error(E_USER_ERROR, \
+ "Given string value cannot be converted to integer."); \
+ return false; \
+ } \
+ } \
+ \
+ bool protobuf_convert_to_##type(zval* from, type##_t* to) { \
+ switch (Z_TYPE_P(from)) { \
+ case IS_LONG: { \
+ return convert_int64_to_##type(Z_LVAL_P(from), to); \
+ } \
+ case IS_DOUBLE: { \
+ return convert_double_to_##type(Z_DVAL_P(from), to); \
+ } \
+ case IS_STRING: { \
+ return convert_string_to_##type(Z_STRVAL_P(from), Z_STRLEN_P(from), \
+ to); \
+ } \
+ default: { \
+ zend_error(E_USER_ERROR, \
+ "Given value cannot be converted to integer."); \
+ return false; \
+ } \
+ } \
+ return false; \
+ }
+
+CONVERT_TO_INTEGER(int32);
+CONVERT_TO_INTEGER(uint32);
+CONVERT_TO_INTEGER(int64);
+CONVERT_TO_INTEGER(uint64);
+
+#undef CONVERT_TO_INTEGER
+
+#define CONVERT_TO_FLOAT(type) \
+ static bool convert_int64_to_##type(int64_t val, type* type##_value) { \
+ *type##_value = (type)val; \
+ return true; \
+ } \
+ \
+ static bool convert_double_to_##type(double val, type* type##_value) { \
+ *type##_value = (type)val; \
+ return true; \
+ } \
+ \
+ static bool convert_string_to_##type(const char* val, int len, \
+ type* type##_value) { \
+ int64_t lval; \
+ double dval; \
+ \
+ switch (convert_numeric_string(val, len, &lval, &dval)) { \
+ case IS_DOUBLE: { \
+ *type##_value = (type)dval; \
+ return true; \
+ } \
+ case IS_LONG: { \
+ *type##_value = (type)lval; \
+ return true; \
+ } \
+ default: \
+ zend_error(E_USER_ERROR, \
+ "Given string value cannot be converted to integer."); \
+ return false; \
+ } \
+ } \
+ \
+ bool protobuf_convert_to_##type(zval* from, type* to) { \
+ switch (Z_TYPE_P(from)) { \
+ case IS_LONG: { \
+ return convert_int64_to_##type(Z_LVAL_P(from), to); \
+ } \
+ case IS_DOUBLE: { \
+ return convert_double_to_##type(Z_DVAL_P(from), to); \
+ } \
+ case IS_STRING: { \
+ return convert_string_to_##type(Z_STRVAL_P(from), Z_STRLEN_P(from), \
+ to); \
+ } \
+ default: { \
+ zend_error(E_USER_ERROR, \
+ "Given value cannot be converted to integer."); \
+ return false; \
+ } \
+ } \
+ return false; \
+ }
+
+CONVERT_TO_FLOAT(float);
+CONVERT_TO_FLOAT(double);
+
+#undef CONVERT_TO_FLOAT
+
+bool protobuf_convert_to_bool(zval* from, int8_t* to) {
+ switch (Z_TYPE_P(from)) {
+ case IS_BOOL:
+ *to = (int8_t)Z_BVAL_P(from);
+ break;
+ case IS_LONG:
+ *to = (int8_t)(Z_LVAL_P(from) != 0);
+ break;
+ case IS_DOUBLE:
+ *to = (int8_t)(Z_LVAL_P(from) != 0);
+ break;
+ case IS_STRING: {
+ char* strval = Z_STRVAL_P(from);
+
+ if (Z_STRLEN_P(from) == 0 ||
+ (Z_STRLEN_P(from) == 1 && Z_STRVAL_P(from)[0] == '0')) {
+ *to = 0;
+ } else {
+ *to = 1;
+ }
+ } break;
+ default: {
+ zend_error(E_USER_ERROR, "Given value cannot be converted to bool.");
+ return false;
+ }
+ }
+ return true;
+}
+
+bool protobuf_convert_to_string(zval* from) {
+ switch (Z_TYPE_P(from)) {
+ case IS_STRING: {
+ return true;
+ }
+ case IS_BOOL:
+ case IS_LONG:
+ case IS_DOUBLE: {
+ int use_copy;
+ zval tmp;
+ zend_make_printable_zval(from, &tmp, &use_copy);
+ ZVAL_COPY_VALUE(from, &tmp);
+ return true;
+ }
+ default:
+ zend_error(E_USER_ERROR, "Given value cannot be converted to string.");
+ return false;
+ }
+}
+
+// -----------------------------------------------------------------------------
+// PHP Functions.
+// -----------------------------------------------------------------------------
+
+// The implementation of type checking for primitive fields is empty. This is
+// because type checking is done when direct assigning message fields (e.g.,
+// foo->a = 1). Functions defined here are place holders in generated code for
+// pure PHP implementation (c extension and pure PHP share the same generated
+// code).
+#define PHP_TYPE_CHECK(type) \
+ PHP_METHOD(Util, check##type) {}
+
+PHP_TYPE_CHECK(Int32)
+PHP_TYPE_CHECK(Uint32)
+PHP_TYPE_CHECK(Int64)
+PHP_TYPE_CHECK(Uint64)
+PHP_TYPE_CHECK(Enum)
+PHP_TYPE_CHECK(Float)
+PHP_TYPE_CHECK(Double)
+PHP_TYPE_CHECK(Bool)
+PHP_TYPE_CHECK(String)
+PHP_TYPE_CHECK(Bytes)
+
+#undef PHP_TYPE_CHECK
+
+PHP_METHOD(Util, checkMessage) {
+ zval* val;
+ zend_class_entry* klass = NULL;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o!C", &val, &klass) ==
+ FAILURE) {
+ return;
+ }
+ if (val == NULL) {
+ RETURN_NULL();
+ }
+ if (!instanceof_function(Z_OBJCE_P(val), klass TSRMLS_CC)) {
+ zend_error(E_USER_ERROR, "Given value is not an instance of %s.",
+ klass->name);
+ return;
+ }
+ RETURN_ZVAL(val, 1, 0);
+}
+
+PHP_METHOD(Util, checkRepeatedField) {
+ zval* val;
+ long type;
+ const zend_class_entry* klass = NULL;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zl|C", &val, &type,
+ &klass) == FAILURE) {
+ return;
+ }
+
+ if (Z_TYPE_P(val) == IS_ARRAY) {
+ HashTable* table = Z_ARRVAL_P(val);
+ HashPosition pointer;
+ void* memory;
+ zval* repeated_field;
+
+ repeated_field_create_with_type(repeated_field_type, to_fieldtype(type),
+ klass, &repeated_field TSRMLS_CC);
+ RepeatedField* intern =
+ (RepeatedField*)zend_object_store_get_object(repeated_field TSRMLS_CC);
+
+ for (zend_hash_internal_pointer_reset_ex(table, &pointer);
+ zend_hash_get_current_data_ex(table, (void**)&memory, &pointer) ==
+ SUCCESS;
+ zend_hash_move_forward_ex(table, &pointer)) {
+ repeated_field_handlers->write_dimension(repeated_field, NULL,
+ *(zval**)memory TSRMLS_CC);
+ }
+
+ Z_DELREF_P(repeated_field);
+ RETURN_ZVAL(repeated_field, 1, 0);
+
+ } else if (Z_TYPE_P(val) == IS_OBJECT) {
+ if (!instanceof_function(Z_OBJCE_P(val), repeated_field_type TSRMLS_CC)) {
+ zend_error(E_USER_ERROR, "Given value is not an instance of %s.",
+ repeated_field_type->name);
+ return;
+ }
+ RepeatedField* intern =
+ (RepeatedField*)zend_object_store_get_object(val TSRMLS_CC);
+ if (to_fieldtype(type) != intern->type) {
+ zend_error(E_USER_ERROR, "Incorrect repeated field type.");
+ return;
+ }
+ if (klass != NULL && intern->msg_ce != klass) {
+ zend_error(E_USER_ERROR,
+ "Expect a repeated field of %s, but %s is given.", klass->name,
+ intern->msg_ce->name);
+ return;
+ }
+ RETURN_ZVAL(val, 1, 0);
+ } else {
+ zend_error(E_USER_ERROR, "Incorrect repeated field type.");
+ return;
+ }
+
+}
+
+PHP_METHOD(Util, checkMapField) {
+ zval* val;
+ long key_type, value_type;
+ const zend_class_entry* klass = NULL;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zll|C", &val, &key_type,
+ &value_type, &klass) == FAILURE) {
+ return;
+ }
+
+ if (Z_TYPE_P(val) == IS_ARRAY) {
+ HashTable* table = Z_ARRVAL_P(val);
+ HashPosition pointer;
+ zval key, *map_field;
+ void* value;
+
+ map_field_create_with_type(map_field_type, to_fieldtype(key_type),
+ to_fieldtype(value_type), klass,
+ &map_field TSRMLS_CC);
+ Map* intern =
+ (Map*)zend_object_store_get_object(map_field TSRMLS_CC);
+
+ for (zend_hash_internal_pointer_reset_ex(table, &pointer);
+ zend_hash_get_current_data_ex(table, (void**)&value, &pointer) ==
+ SUCCESS;
+ zend_hash_move_forward_ex(table, &pointer)) {
+ zend_hash_get_current_key_zval_ex(table, &key, &pointer);
+ map_field_handlers->write_dimension(map_field, &key,
+ *(zval**)value TSRMLS_CC);
+ }
+
+ Z_DELREF_P(map_field);
+ RETURN_ZVAL(map_field, 1, 0);
+ } else if (Z_TYPE_P(val) == IS_OBJECT) {
+ if (!instanceof_function(Z_OBJCE_P(val), map_field_type TSRMLS_CC)) {
+ zend_error(E_USER_ERROR, "Given value is not an instance of %s.",
+ map_field_type->name);
+ return;
+ }
+ Map* intern = (Map*)zend_object_store_get_object(val TSRMLS_CC);
+ if (to_fieldtype(key_type) != intern->key_type) {
+ zend_error(E_USER_ERROR, "Incorrect map field key type.");
+ return;
+ }
+ if (to_fieldtype(value_type) != intern->value_type) {
+ zend_error(E_USER_ERROR, "Incorrect map field value type.");
+ return;
+ }
+ if (klass != NULL && intern->msg_ce != klass) {
+ zend_error(E_USER_ERROR, "Expect a map field of %s, but %s is given.",
+ klass->name, intern->msg_ce->name);
+ return;
+ }
+ RETURN_ZVAL(val, 1, 0);
+ } else {
+ zend_error(E_USER_ERROR, "Incorrect map field type.");
+ return;
+ }
+}
diff --git a/third_party/protobuf/php/ext/google/protobuf/upb.c b/third_party/protobuf/php/ext/google/protobuf/upb.c
new file mode 100644
index 0000000000..70983016cb
--- /dev/null
+++ b/third_party/protobuf/php/ext/google/protobuf/upb.c
@@ -0,0 +1,13847 @@
+// Amalgamated source file
+#include "upb.h"
+
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+typedef struct {
+ size_t len;
+ char str[1]; /* Null-terminated string data follows. */
+} str_t;
+
+static str_t *newstr(const char *data, size_t len) {
+ str_t *ret = upb_gmalloc(sizeof(*ret) + len);
+ if (!ret) return NULL;
+ ret->len = len;
+ memcpy(ret->str, data, len);
+ ret->str[len] = '\0';
+ return ret;
+}
+
+static void freestr(str_t *s) { upb_gfree(s); }
+
+/* isalpha() etc. from <ctype.h> are locale-dependent, which we don't want. */
+static bool upb_isbetween(char c, char low, char high) {
+ return c >= low && c <= high;
+}
+
+static bool upb_isletter(char c) {
+ return upb_isbetween(c, 'A', 'Z') || upb_isbetween(c, 'a', 'z') || c == '_';
+}
+
+static bool upb_isalphanum(char c) {
+ return upb_isletter(c) || upb_isbetween(c, '0', '9');
+}
+
+static bool upb_isident(const char *str, size_t len, bool full, upb_status *s) {
+ bool start = true;
+ size_t i;
+ for (i = 0; i < len; i++) {
+ char c = str[i];
+ if (c == '.') {
+ if (start || !full) {
+ upb_status_seterrf(s, "invalid name: unexpected '.' (%s)", str);
+ return false;
+ }
+ start = true;
+ } else if (start) {
+ if (!upb_isletter(c)) {
+ upb_status_seterrf(
+ s, "invalid name: path components must start with a letter (%s)",
+ str);
+ return false;
+ }
+ start = false;
+ } else {
+ if (!upb_isalphanum(c)) {
+ upb_status_seterrf(s, "invalid name: non-alphanumeric character (%s)",
+ str);
+ return false;
+ }
+ }
+ }
+ return !start;
+}
+
+static bool upb_isoneof(const upb_refcounted *def) {
+ return def->vtbl == &upb_oneofdef_vtbl;
+}
+
+static bool upb_isfield(const upb_refcounted *def) {
+ return def->vtbl == &upb_fielddef_vtbl;
+}
+
+static const upb_oneofdef *upb_trygetoneof(const upb_refcounted *def) {
+ return upb_isoneof(def) ? (const upb_oneofdef*)def : NULL;
+}
+
+static const upb_fielddef *upb_trygetfield(const upb_refcounted *def) {
+ return upb_isfield(def) ? (const upb_fielddef*)def : NULL;
+}
+
+
+/* upb_def ********************************************************************/
+
+upb_deftype_t upb_def_type(const upb_def *d) { return d->type; }
+
+const char *upb_def_fullname(const upb_def *d) { return d->fullname; }
+
+const char *upb_def_name(const upb_def *d) {
+ const char *p;
+
+ if (d->fullname == NULL) {
+ return NULL;
+ } else if ((p = strrchr(d->fullname, '.')) == NULL) {
+ /* No '.' in the name, return the full string. */
+ return d->fullname;
+ } else {
+ /* Return one past the last '.'. */
+ return p + 1;
+ }
+}
+
+bool upb_def_setfullname(upb_def *def, const char *fullname, upb_status *s) {
+ UPB_ASSERT(!upb_def_isfrozen(def));
+ if (!upb_isident(fullname, strlen(fullname), true, s)) {
+ return false;
+ }
+
+ fullname = upb_gstrdup(fullname);
+ if (!fullname) {
+ upb_upberr_setoom(s);
+ return false;
+ }
+
+ upb_gfree((void*)def->fullname);
+ def->fullname = fullname;
+ return true;
+}
+
+const upb_filedef *upb_def_file(const upb_def *d) { return d->file; }
+
+static bool upb_def_init(upb_def *def, upb_deftype_t type,
+ const struct upb_refcounted_vtbl *vtbl,
+ const void *owner) {
+ if (!upb_refcounted_init(upb_def_upcast_mutable(def), vtbl, owner)) return false;
+ def->type = type;
+ def->fullname = NULL;
+ def->came_from_user = false;
+ def->file = NULL;
+ return true;
+}
+
+static void upb_def_uninit(upb_def *def) {
+ upb_gfree((void*)def->fullname);
+}
+
+static const char *msgdef_name(const upb_msgdef *m) {
+ const char *name = upb_def_fullname(upb_msgdef_upcast(m));
+ return name ? name : "(anonymous)";
+}
+
+static bool upb_validate_field(upb_fielddef *f, upb_status *s) {
+ if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) {
+ upb_status_seterrmsg(s, "fielddef must have name and number set");
+ return false;
+ }
+
+ if (!f->type_is_set_) {
+ upb_status_seterrmsg(s, "fielddef type was not initialized");
+ return false;
+ }
+
+ if (upb_fielddef_lazy(f) &&
+ upb_fielddef_descriptortype(f) != UPB_DESCRIPTOR_TYPE_MESSAGE) {
+ upb_status_seterrmsg(s,
+ "only length-delimited submessage fields may be lazy");
+ return false;
+ }
+
+ if (upb_fielddef_hassubdef(f)) {
+ const upb_def *subdef;
+
+ if (f->subdef_is_symbolic) {
+ upb_status_seterrf(s, "field '%s.%s' has not been resolved",
+ msgdef_name(f->msg.def), upb_fielddef_name(f));
+ return false;
+ }
+
+ subdef = upb_fielddef_subdef(f);
+ if (subdef == NULL) {
+ upb_status_seterrf(s, "field %s.%s is missing required subdef",
+ msgdef_name(f->msg.def), upb_fielddef_name(f));
+ return false;
+ }
+
+ if (!upb_def_isfrozen(subdef) && !subdef->came_from_user) {
+ upb_status_seterrf(s,
+ "subdef of field %s.%s is not frozen or being frozen",
+ msgdef_name(f->msg.def), upb_fielddef_name(f));
+ return false;
+ }
+ }
+
+ if (upb_fielddef_type(f) == UPB_TYPE_ENUM) {
+ bool has_default_name = upb_fielddef_enumhasdefaultstr(f);
+ bool has_default_number = upb_fielddef_enumhasdefaultint32(f);
+
+ /* Previously verified by upb_validate_enumdef(). */
+ UPB_ASSERT(upb_enumdef_numvals(upb_fielddef_enumsubdef(f)) > 0);
+
+ /* We've already validated that we have an associated enumdef and that it
+ * has at least one member, so at least one of these should be true.
+ * Because if the user didn't set anything, we'll pick up the enum's
+ * default, but if the user *did* set something we should at least pick up
+ * the one they set (int32 or string). */
+ UPB_ASSERT(has_default_name || has_default_number);
+
+ if (!has_default_name) {
+ upb_status_seterrf(s,
+ "enum default for field %s.%s (%d) is not in the enum",
+ msgdef_name(f->msg.def), upb_fielddef_name(f),
+ upb_fielddef_defaultint32(f));
+ return false;
+ }
+
+ if (!has_default_number) {
+ upb_status_seterrf(s,
+ "enum default for field %s.%s (%s) is not in the enum",
+ msgdef_name(f->msg.def), upb_fielddef_name(f),
+ upb_fielddef_defaultstr(f, NULL));
+ return false;
+ }
+
+ /* Lift the effective numeric default into the field's default slot, in case
+ * we were only getting it "by reference" from the enumdef. */
+ upb_fielddef_setdefaultint32(f, upb_fielddef_defaultint32(f));
+ }
+
+ /* Ensure that MapEntry submessages only appear as repeated fields, not
+ * optional/required (singular) fields. */
+ if (upb_fielddef_type(f) == UPB_TYPE_MESSAGE &&
+ upb_fielddef_msgsubdef(f) != NULL) {
+ const upb_msgdef *subdef = upb_fielddef_msgsubdef(f);
+ if (upb_msgdef_mapentry(subdef) && !upb_fielddef_isseq(f)) {
+ upb_status_seterrf(s,
+ "Field %s refers to mapentry message but is not "
+ "a repeated field",
+ upb_fielddef_name(f) ? upb_fielddef_name(f) :
+ "(unnamed)");
+ return false;
+ }
+ }
+
+ return true;
+}
+
+static bool upb_validate_enumdef(const upb_enumdef *e, upb_status *s) {
+ if (upb_enumdef_numvals(e) == 0) {
+ upb_status_seterrf(s, "enum %s has no members (must have at least one)",
+ upb_enumdef_fullname(e));
+ return false;
+ }
+
+ return true;
+}
+
+/* All submessage fields are lower than all other fields.
+ * Secondly, fields are increasing in order. */
+uint32_t field_rank(const upb_fielddef *f) {
+ uint32_t ret = upb_fielddef_number(f);
+ const uint32_t high_bit = 1 << 30;
+ UPB_ASSERT(ret < high_bit);
+ if (!upb_fielddef_issubmsg(f))
+ ret |= high_bit;
+ return ret;
+}
+
+int cmp_fields(const void *p1, const void *p2) {
+ const upb_fielddef *f1 = *(upb_fielddef*const*)p1;
+ const upb_fielddef *f2 = *(upb_fielddef*const*)p2;
+ return field_rank(f1) - field_rank(f2);
+}
+
+static bool assign_msg_indices(upb_msgdef *m, upb_status *s) {
+ /* Sort fields. upb internally relies on UPB_TYPE_MESSAGE fields having the
+ * lowest indexes, but we do not publicly guarantee this. */
+ upb_msg_field_iter j;
+ upb_msg_oneof_iter k;
+ int i;
+ uint32_t selector;
+ int n = upb_msgdef_numfields(m);
+ upb_fielddef **fields;
+
+ if (n == 0) {
+ m->selector_count = UPB_STATIC_SELECTOR_COUNT;
+ m->submsg_field_count = 0;
+ return true;
+ }
+
+ fields = upb_gmalloc(n * sizeof(*fields));
+ if (!fields) {
+ upb_upberr_setoom(s);
+ return false;
+ }
+
+ m->submsg_field_count = 0;
+ for(i = 0, upb_msg_field_begin(&j, m);
+ !upb_msg_field_done(&j);
+ upb_msg_field_next(&j), i++) {
+ upb_fielddef *f = upb_msg_iter_field(&j);
+ UPB_ASSERT(f->msg.def == m);
+ if (!upb_validate_field(f, s)) {
+ upb_gfree(fields);
+ return false;
+ }
+ if (upb_fielddef_issubmsg(f)) {
+ m->submsg_field_count++;
+ }
+ fields[i] = f;
+ }
+
+ qsort(fields, n, sizeof(*fields), cmp_fields);
+
+ selector = UPB_STATIC_SELECTOR_COUNT + m->submsg_field_count;
+ for (i = 0; i < n; i++) {
+ upb_fielddef *f = fields[i];
+ f->index_ = i;
+ f->selector_base = selector + upb_handlers_selectorbaseoffset(f);
+ selector += upb_handlers_selectorcount(f);
+ }
+ m->selector_count = selector;
+
+#ifndef NDEBUG
+ {
+ /* Verify that all selectors for the message are distinct. */
+#define TRY(type) \
+ if (upb_handlers_getselector(f, type, &sel)) upb_inttable_insert(&t, sel, v);
+
+ upb_inttable t;
+ upb_value v;
+ upb_selector_t sel;
+
+ upb_inttable_init(&t, UPB_CTYPE_BOOL);
+ v = upb_value_bool(true);
+ upb_inttable_insert(&t, UPB_STARTMSG_SELECTOR, v);
+ upb_inttable_insert(&t, UPB_ENDMSG_SELECTOR, v);
+ for(upb_msg_field_begin(&j, m);
+ !upb_msg_field_done(&j);
+ upb_msg_field_next(&j)) {
+ upb_fielddef *f = upb_msg_iter_field(&j);
+ /* These calls will assert-fail in upb_table if the value already
+ * exists. */
+ TRY(UPB_HANDLER_INT32);
+ TRY(UPB_HANDLER_INT64)
+ TRY(UPB_HANDLER_UINT32)
+ TRY(UPB_HANDLER_UINT64)
+ TRY(UPB_HANDLER_FLOAT)
+ TRY(UPB_HANDLER_DOUBLE)
+ TRY(UPB_HANDLER_BOOL)
+ TRY(UPB_HANDLER_STARTSTR)
+ TRY(UPB_HANDLER_STRING)
+ TRY(UPB_HANDLER_ENDSTR)
+ TRY(UPB_HANDLER_STARTSUBMSG)
+ TRY(UPB_HANDLER_ENDSUBMSG)
+ TRY(UPB_HANDLER_STARTSEQ)
+ TRY(UPB_HANDLER_ENDSEQ)
+ }
+ upb_inttable_uninit(&t);
+ }
+#undef TRY
+#endif
+
+ for(upb_msg_oneof_begin(&k, m), i = 0;
+ !upb_msg_oneof_done(&k);
+ upb_msg_oneof_next(&k), i++) {
+ upb_oneofdef *o = upb_msg_iter_oneof(&k);
+ o->index = i;
+ }
+
+ upb_gfree(fields);
+ return true;
+}
+
+bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s) {
+ size_t i;
+
+ /* First perform validation, in two passes so we can check that we have a
+ * transitive closure without needing to search. */
+ for (i = 0; i < n; i++) {
+ upb_def *def = defs[i];
+ if (upb_def_isfrozen(def)) {
+ /* Could relax this requirement if it's annoying. */
+ upb_status_seterrmsg(s, "def is already frozen");
+ goto err;
+ } else if (def->type == UPB_DEF_FIELD) {
+ upb_status_seterrmsg(s, "standalone fielddefs can not be frozen");
+ goto err;
+ } else {
+ /* Set now to detect transitive closure in the second pass. */
+ def->came_from_user = true;
+
+ if (def->type == UPB_DEF_ENUM &&
+ !upb_validate_enumdef(upb_dyncast_enumdef(def), s)) {
+ goto err;
+ }
+ }
+ }
+
+ /* Second pass of validation. Also assign selector bases and indexes, and
+ * compact tables. */
+ for (i = 0; i < n; i++) {
+ upb_def *def = defs[i];
+ upb_msgdef *m = upb_dyncast_msgdef_mutable(def);
+ upb_enumdef *e = upb_dyncast_enumdef_mutable(def);
+ if (m) {
+ upb_inttable_compact(&m->itof);
+ if (!assign_msg_indices(m, s)) {
+ goto err;
+ }
+ } else if (e) {
+ upb_inttable_compact(&e->iton);
+ }
+ }
+
+ return true;
+
+err:
+ for (i = 0; i < n; i++) {
+ upb_def *def = defs[i];
+ def->came_from_user = false;
+ }
+ UPB_ASSERT(!(s && upb_ok(s)));
+ return false;
+}
+
+bool upb_def_freeze(upb_def *const* defs, size_t n, upb_status *s) {
+ /* Def graph contains FieldDefs between each MessageDef, so double the
+ * limit. */
+ const size_t maxdepth = UPB_MAX_MESSAGE_DEPTH * 2;
+
+ if (!_upb_def_validate(defs, n, s)) {
+ return false;
+ }
+
+
+ /* Validation all passed; freeze the objects. */
+ return upb_refcounted_freeze((upb_refcounted *const*)defs, n, s, maxdepth);
+}
+
+
+/* upb_enumdef ****************************************************************/
+
+static void visitenum(const upb_refcounted *r, upb_refcounted_visit *visit,
+ void *closure) {
+ const upb_enumdef *e = (const upb_enumdef*)r;
+ const upb_def *def = upb_enumdef_upcast(e);
+ if (upb_def_file(def)) {
+ visit(r, upb_filedef_upcast(upb_def_file(def)), closure);
+ }
+}
+
+static void freeenum(upb_refcounted *r) {
+ upb_enumdef *e = (upb_enumdef*)r;
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, &e->iton);
+ for( ; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ /* To clean up the upb_gstrdup() from upb_enumdef_addval(). */
+ upb_gfree(upb_value_getcstr(upb_inttable_iter_value(&i)));
+ }
+ upb_strtable_uninit(&e->ntoi);
+ upb_inttable_uninit(&e->iton);
+ upb_def_uninit(upb_enumdef_upcast_mutable(e));
+ upb_gfree(e);
+}
+
+const struct upb_refcounted_vtbl upb_enumdef_vtbl = {&visitenum, &freeenum};
+
+upb_enumdef *upb_enumdef_new(const void *owner) {
+ upb_enumdef *e = upb_gmalloc(sizeof(*e));
+ if (!e) return NULL;
+
+ if (!upb_def_init(upb_enumdef_upcast_mutable(e), UPB_DEF_ENUM,
+ &upb_enumdef_vtbl, owner)) {
+ goto err2;
+ }
+
+ if (!upb_strtable_init(&e->ntoi, UPB_CTYPE_INT32)) goto err2;
+ if (!upb_inttable_init(&e->iton, UPB_CTYPE_CSTR)) goto err1;
+ return e;
+
+err1:
+ upb_strtable_uninit(&e->ntoi);
+err2:
+ upb_gfree(e);
+ return NULL;
+}
+
+bool upb_enumdef_freeze(upb_enumdef *e, upb_status *status) {
+ upb_def *d = upb_enumdef_upcast_mutable(e);
+ return upb_def_freeze(&d, 1, status);
+}
+
+const char *upb_enumdef_fullname(const upb_enumdef *e) {
+ return upb_def_fullname(upb_enumdef_upcast(e));
+}
+
+const char *upb_enumdef_name(const upb_enumdef *e) {
+ return upb_def_name(upb_enumdef_upcast(e));
+}
+
+bool upb_enumdef_setfullname(upb_enumdef *e, const char *fullname,
+ upb_status *s) {
+ return upb_def_setfullname(upb_enumdef_upcast_mutable(e), fullname, s);
+}
+
+bool upb_enumdef_addval(upb_enumdef *e, const char *name, int32_t num,
+ upb_status *status) {
+ char *name2;
+
+ if (!upb_isident(name, strlen(name), false, status)) {
+ return false;
+ }
+
+ if (upb_enumdef_ntoiz(e, name, NULL)) {
+ upb_status_seterrf(status, "name '%s' is already defined", name);
+ return false;
+ }
+
+ if (!upb_strtable_insert(&e->ntoi, name, upb_value_int32(num))) {
+ upb_status_seterrmsg(status, "out of memory");
+ return false;
+ }
+
+ if (!upb_inttable_lookup(&e->iton, num, NULL)) {
+ name2 = upb_gstrdup(name);
+ if (!name2 || !upb_inttable_insert(&e->iton, num, upb_value_cstr(name2))) {
+ upb_status_seterrmsg(status, "out of memory");
+ upb_strtable_remove(&e->ntoi, name, NULL);
+ return false;
+ }
+ }
+
+ if (upb_enumdef_numvals(e) == 1) {
+ bool ok = upb_enumdef_setdefault(e, num, NULL);
+ UPB_ASSERT(ok);
+ }
+
+ return true;
+}
+
+int32_t upb_enumdef_default(const upb_enumdef *e) {
+ UPB_ASSERT(upb_enumdef_iton(e, e->defaultval));
+ return e->defaultval;
+}
+
+bool upb_enumdef_setdefault(upb_enumdef *e, int32_t val, upb_status *s) {
+ UPB_ASSERT(!upb_enumdef_isfrozen(e));
+ if (!upb_enumdef_iton(e, val)) {
+ upb_status_seterrf(s, "number '%d' is not in the enum.", val);
+ return false;
+ }
+ e->defaultval = val;
+ return true;
+}
+
+int upb_enumdef_numvals(const upb_enumdef *e) {
+ return upb_strtable_count(&e->ntoi);
+}
+
+void upb_enum_begin(upb_enum_iter *i, const upb_enumdef *e) {
+ /* We iterate over the ntoi table, to account for duplicate numbers. */
+ upb_strtable_begin(i, &e->ntoi);
+}
+
+void upb_enum_next(upb_enum_iter *iter) { upb_strtable_next(iter); }
+bool upb_enum_done(upb_enum_iter *iter) { return upb_strtable_done(iter); }
+
+bool upb_enumdef_ntoi(const upb_enumdef *def, const char *name,
+ size_t len, int32_t *num) {
+ upb_value v;
+ if (!upb_strtable_lookup2(&def->ntoi, name, len, &v)) {
+ return false;
+ }
+ if (num) *num = upb_value_getint32(v);
+ return true;
+}
+
+const char *upb_enumdef_iton(const upb_enumdef *def, int32_t num) {
+ upb_value v;
+ return upb_inttable_lookup32(&def->iton, num, &v) ?
+ upb_value_getcstr(v) : NULL;
+}
+
+const char *upb_enum_iter_name(upb_enum_iter *iter) {
+ return upb_strtable_iter_key(iter);
+}
+
+int32_t upb_enum_iter_number(upb_enum_iter *iter) {
+ return upb_value_getint32(upb_strtable_iter_value(iter));
+}
+
+
+/* upb_fielddef ***************************************************************/
+
+static void upb_fielddef_init_default(upb_fielddef *f);
+
+static void upb_fielddef_uninit_default(upb_fielddef *f) {
+ if (f->type_is_set_ && f->default_is_string && f->defaultval.bytes)
+ freestr(f->defaultval.bytes);
+}
+
+const char *upb_fielddef_fullname(const upb_fielddef *e) {
+ return upb_def_fullname(upb_fielddef_upcast(e));
+}
+
+static void visitfield(const upb_refcounted *r, upb_refcounted_visit *visit,
+ void *closure) {
+ const upb_fielddef *f = (const upb_fielddef*)r;
+ const upb_def *def = upb_fielddef_upcast(f);
+ if (upb_fielddef_containingtype(f)) {
+ visit(r, upb_msgdef_upcast2(upb_fielddef_containingtype(f)), closure);
+ }
+ if (upb_fielddef_containingoneof(f)) {
+ visit(r, upb_oneofdef_upcast(upb_fielddef_containingoneof(f)), closure);
+ }
+ if (upb_fielddef_subdef(f)) {
+ visit(r, upb_def_upcast(upb_fielddef_subdef(f)), closure);
+ }
+ if (upb_def_file(def)) {
+ visit(r, upb_filedef_upcast(upb_def_file(def)), closure);
+ }
+}
+
+static void freefield(upb_refcounted *r) {
+ upb_fielddef *f = (upb_fielddef*)r;
+ upb_fielddef_uninit_default(f);
+ if (f->subdef_is_symbolic)
+ upb_gfree(f->sub.name);
+ upb_def_uninit(upb_fielddef_upcast_mutable(f));
+ upb_gfree(f);
+}
+
+static const char *enumdefaultstr(const upb_fielddef *f) {
+ const upb_enumdef *e;
+ UPB_ASSERT(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM);
+ e = upb_fielddef_enumsubdef(f);
+ if (f->default_is_string && f->defaultval.bytes) {
+ /* Default was explicitly set as a string. */
+ str_t *s = f->defaultval.bytes;
+ return s->str;
+ } else if (e) {
+ if (!f->default_is_string) {
+ /* Default was explicitly set as an integer; look it up in enumdef. */
+ const char *name = upb_enumdef_iton(e, f->defaultval.sint);
+ if (name) {
+ return name;
+ }
+ } else {
+ /* Default is completely unset; pull enumdef default. */
+ if (upb_enumdef_numvals(e) > 0) {
+ const char *name = upb_enumdef_iton(e, upb_enumdef_default(e));
+ UPB_ASSERT(name);
+ return name;
+ }
+ }
+ }
+ return NULL;
+}
+
+static bool enumdefaultint32(const upb_fielddef *f, int32_t *val) {
+ const upb_enumdef *e;
+ UPB_ASSERT(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM);
+ e = upb_fielddef_enumsubdef(f);
+ if (!f->default_is_string) {
+ /* Default was explicitly set as an integer. */
+ *val = f->defaultval.sint;
+ return true;
+ } else if (e) {
+ if (f->defaultval.bytes) {
+ /* Default was explicitly set as a str; try to lookup corresponding int. */
+ str_t *s = f->defaultval.bytes;
+ if (upb_enumdef_ntoiz(e, s->str, val)) {
+ return true;
+ }
+ } else {
+ /* Default is unset; try to pull in enumdef default. */
+ if (upb_enumdef_numvals(e) > 0) {
+ *val = upb_enumdef_default(e);
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+const struct upb_refcounted_vtbl upb_fielddef_vtbl = {visitfield, freefield};
+
+upb_fielddef *upb_fielddef_new(const void *o) {
+ upb_fielddef *f = upb_gmalloc(sizeof(*f));
+ if (!f) return NULL;
+ if (!upb_def_init(upb_fielddef_upcast_mutable(f), UPB_DEF_FIELD,
+ &upb_fielddef_vtbl, o)) {
+ upb_gfree(f);
+ return NULL;
+ }
+ f->msg.def = NULL;
+ f->sub.def = NULL;
+ f->oneof = NULL;
+ f->subdef_is_symbolic = false;
+ f->msg_is_symbolic = false;
+ f->label_ = UPB_LABEL_OPTIONAL;
+ f->type_ = UPB_TYPE_INT32;
+ f->number_ = 0;
+ f->type_is_set_ = false;
+ f->tagdelim = false;
+ f->is_extension_ = false;
+ f->lazy_ = false;
+ f->packed_ = true;
+
+ /* For the moment we default this to UPB_INTFMT_VARIABLE, since it will work
+ * with all integer types and is in some since more "default" since the most
+ * normal-looking proto2 types int32/int64/uint32/uint64 use variable.
+ *
+ * Other options to consider:
+ * - there is no default; users must set this manually (like type).
+ * - default signed integers to UPB_INTFMT_ZIGZAG, since it's more likely to
+ * be an optimal default for signed integers. */
+ f->intfmt = UPB_INTFMT_VARIABLE;
+ return f;
+}
+
+bool upb_fielddef_typeisset(const upb_fielddef *f) {
+ return f->type_is_set_;
+}
+
+upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f) {
+ UPB_ASSERT(f->type_is_set_);
+ return f->type_;
+}
+
+uint32_t upb_fielddef_index(const upb_fielddef *f) {
+ return f->index_;
+}
+
+upb_label_t upb_fielddef_label(const upb_fielddef *f) {
+ return f->label_;
+}
+
+upb_intfmt_t upb_fielddef_intfmt(const upb_fielddef *f) {
+ return f->intfmt;
+}
+
+bool upb_fielddef_istagdelim(const upb_fielddef *f) {
+ return f->tagdelim;
+}
+
+uint32_t upb_fielddef_number(const upb_fielddef *f) {
+ return f->number_;
+}
+
+bool upb_fielddef_isextension(const upb_fielddef *f) {
+ return f->is_extension_;
+}
+
+bool upb_fielddef_lazy(const upb_fielddef *f) {
+ return f->lazy_;
+}
+
+bool upb_fielddef_packed(const upb_fielddef *f) {
+ return f->packed_;
+}
+
+const char *upb_fielddef_name(const upb_fielddef *f) {
+ return upb_def_fullname(upb_fielddef_upcast(f));
+}
+
+size_t upb_fielddef_getjsonname(const upb_fielddef *f, char *buf, size_t len) {
+ const char *name = upb_fielddef_name(f);
+ size_t src, dst = 0;
+ bool ucase_next = false;
+
+#define WRITE(byte) \
+ ++dst; \
+ if (dst < len) buf[dst - 1] = byte; \
+ else if (dst == len) buf[dst - 1] = '\0'
+
+ if (!name) {
+ WRITE('\0');
+ return 0;
+ }
+
+ /* Implement the transformation as described in the spec:
+ * 1. upper case all letters after an underscore.
+ * 2. remove all underscores.
+ */
+ for (src = 0; name[src]; src++) {
+ if (name[src] == '_') {
+ ucase_next = true;
+ continue;
+ }
+
+ if (ucase_next) {
+ WRITE(toupper(name[src]));
+ ucase_next = false;
+ } else {
+ WRITE(name[src]);
+ }
+ }
+
+ WRITE('\0');
+ return dst;
+
+#undef WRITE
+}
+
+const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f) {
+ return f->msg_is_symbolic ? NULL : f->msg.def;
+}
+
+const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f) {
+ return f->oneof;
+}
+
+upb_msgdef *upb_fielddef_containingtype_mutable(upb_fielddef *f) {
+ return (upb_msgdef*)upb_fielddef_containingtype(f);
+}
+
+const char *upb_fielddef_containingtypename(upb_fielddef *f) {
+ return f->msg_is_symbolic ? f->msg.name : NULL;
+}
+
+static void release_containingtype(upb_fielddef *f) {
+ if (f->msg_is_symbolic) upb_gfree(f->msg.name);
+}
+
+bool upb_fielddef_setcontainingtypename(upb_fielddef *f, const char *name,
+ upb_status *s) {
+ char *name_copy;
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ if (upb_fielddef_containingtype(f)) {
+ upb_status_seterrmsg(s, "field has already been added to a message.");
+ return false;
+ }
+ /* TODO: validate name (upb_isident() doesn't quite work atm because this name
+ * may have a leading "."). */
+
+ name_copy = upb_gstrdup(name);
+ if (!name_copy) {
+ upb_upberr_setoom(s);
+ return false;
+ }
+
+ release_containingtype(f);
+ f->msg.name = name_copy;
+ f->msg_is_symbolic = true;
+ return true;
+}
+
+bool upb_fielddef_setname(upb_fielddef *f, const char *name, upb_status *s) {
+ if (upb_fielddef_containingtype(f) || upb_fielddef_containingoneof(f)) {
+ upb_status_seterrmsg(s, "Already added to message or oneof");
+ return false;
+ }
+ return upb_def_setfullname(upb_fielddef_upcast_mutable(f), name, s);
+}
+
+static void chkdefaulttype(const upb_fielddef *f, upb_fieldtype_t type) {
+ UPB_UNUSED(f);
+ UPB_UNUSED(type);
+ UPB_ASSERT(f->type_is_set_ && upb_fielddef_type(f) == type);
+}
+
+int64_t upb_fielddef_defaultint64(const upb_fielddef *f) {
+ chkdefaulttype(f, UPB_TYPE_INT64);
+ return f->defaultval.sint;
+}
+
+int32_t upb_fielddef_defaultint32(const upb_fielddef *f) {
+ if (f->type_is_set_ && upb_fielddef_type(f) == UPB_TYPE_ENUM) {
+ int32_t val;
+ bool ok = enumdefaultint32(f, &val);
+ UPB_ASSERT(ok);
+ return val;
+ } else {
+ chkdefaulttype(f, UPB_TYPE_INT32);
+ return f->defaultval.sint;
+ }
+}
+
+uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f) {
+ chkdefaulttype(f, UPB_TYPE_UINT64);
+ return f->defaultval.uint;
+}
+
+uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f) {
+ chkdefaulttype(f, UPB_TYPE_UINT32);
+ return f->defaultval.uint;
+}
+
+bool upb_fielddef_defaultbool(const upb_fielddef *f) {
+ chkdefaulttype(f, UPB_TYPE_BOOL);
+ return f->defaultval.uint;
+}
+
+float upb_fielddef_defaultfloat(const upb_fielddef *f) {
+ chkdefaulttype(f, UPB_TYPE_FLOAT);
+ return f->defaultval.flt;
+}
+
+double upb_fielddef_defaultdouble(const upb_fielddef *f) {
+ chkdefaulttype(f, UPB_TYPE_DOUBLE);
+ return f->defaultval.dbl;
+}
+
+const char *upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len) {
+ UPB_ASSERT(f->type_is_set_);
+ UPB_ASSERT(upb_fielddef_type(f) == UPB_TYPE_STRING ||
+ upb_fielddef_type(f) == UPB_TYPE_BYTES ||
+ upb_fielddef_type(f) == UPB_TYPE_ENUM);
+
+ if (upb_fielddef_type(f) == UPB_TYPE_ENUM) {
+ const char *ret = enumdefaultstr(f);
+ UPB_ASSERT(ret);
+ /* Enum defaults can't have embedded NULLs. */
+ if (len) *len = strlen(ret);
+ return ret;
+ }
+
+ if (f->default_is_string) {
+ str_t *str = f->defaultval.bytes;
+ if (len) *len = str->len;
+ return str->str;
+ }
+
+ return NULL;
+}
+
+static void upb_fielddef_init_default(upb_fielddef *f) {
+ f->default_is_string = false;
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_DOUBLE: f->defaultval.dbl = 0; break;
+ case UPB_TYPE_FLOAT: f->defaultval.flt = 0; break;
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_INT64: f->defaultval.sint = 0; break;
+ case UPB_TYPE_UINT64:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_BOOL: f->defaultval.uint = 0; break;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ f->defaultval.bytes = newstr("", 0);
+ f->default_is_string = true;
+ break;
+ case UPB_TYPE_MESSAGE: break;
+ case UPB_TYPE_ENUM:
+ /* This is our special sentinel that indicates "not set" for an enum. */
+ f->default_is_string = true;
+ f->defaultval.bytes = NULL;
+ break;
+ }
+}
+
+const upb_def *upb_fielddef_subdef(const upb_fielddef *f) {
+ return f->subdef_is_symbolic ? NULL : f->sub.def;
+}
+
+const upb_msgdef *upb_fielddef_msgsubdef(const upb_fielddef *f) {
+ const upb_def *def = upb_fielddef_subdef(f);
+ return def ? upb_dyncast_msgdef(def) : NULL;
+}
+
+const upb_enumdef *upb_fielddef_enumsubdef(const upb_fielddef *f) {
+ const upb_def *def = upb_fielddef_subdef(f);
+ return def ? upb_dyncast_enumdef(def) : NULL;
+}
+
+upb_def *upb_fielddef_subdef_mutable(upb_fielddef *f) {
+ return (upb_def*)upb_fielddef_subdef(f);
+}
+
+const char *upb_fielddef_subdefname(const upb_fielddef *f) {
+ if (f->subdef_is_symbolic) {
+ return f->sub.name;
+ } else if (f->sub.def) {
+ return upb_def_fullname(f->sub.def);
+ } else {
+ return NULL;
+ }
+}
+
+bool upb_fielddef_setnumber(upb_fielddef *f, uint32_t number, upb_status *s) {
+ if (upb_fielddef_containingtype(f)) {
+ upb_status_seterrmsg(
+ s, "cannot change field number after adding to a message");
+ return false;
+ }
+ if (number == 0 || number > UPB_MAX_FIELDNUMBER) {
+ upb_status_seterrf(s, "invalid field number (%u)", number);
+ return false;
+ }
+ f->number_ = number;
+ return true;
+}
+
+void upb_fielddef_settype(upb_fielddef *f, upb_fieldtype_t type) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ UPB_ASSERT(upb_fielddef_checktype(type));
+ upb_fielddef_uninit_default(f);
+ f->type_ = type;
+ f->type_is_set_ = true;
+ upb_fielddef_init_default(f);
+}
+
+void upb_fielddef_setdescriptortype(upb_fielddef *f, int type) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ switch (type) {
+ case UPB_DESCRIPTOR_TYPE_DOUBLE:
+ upb_fielddef_settype(f, UPB_TYPE_DOUBLE);
+ break;
+ case UPB_DESCRIPTOR_TYPE_FLOAT:
+ upb_fielddef_settype(f, UPB_TYPE_FLOAT);
+ break;
+ case UPB_DESCRIPTOR_TYPE_INT64:
+ case UPB_DESCRIPTOR_TYPE_SFIXED64:
+ case UPB_DESCRIPTOR_TYPE_SINT64:
+ upb_fielddef_settype(f, UPB_TYPE_INT64);
+ break;
+ case UPB_DESCRIPTOR_TYPE_UINT64:
+ case UPB_DESCRIPTOR_TYPE_FIXED64:
+ upb_fielddef_settype(f, UPB_TYPE_UINT64);
+ break;
+ case UPB_DESCRIPTOR_TYPE_INT32:
+ case UPB_DESCRIPTOR_TYPE_SFIXED32:
+ case UPB_DESCRIPTOR_TYPE_SINT32:
+ upb_fielddef_settype(f, UPB_TYPE_INT32);
+ break;
+ case UPB_DESCRIPTOR_TYPE_UINT32:
+ case UPB_DESCRIPTOR_TYPE_FIXED32:
+ upb_fielddef_settype(f, UPB_TYPE_UINT32);
+ break;
+ case UPB_DESCRIPTOR_TYPE_BOOL:
+ upb_fielddef_settype(f, UPB_TYPE_BOOL);
+ break;
+ case UPB_DESCRIPTOR_TYPE_STRING:
+ upb_fielddef_settype(f, UPB_TYPE_STRING);
+ break;
+ case UPB_DESCRIPTOR_TYPE_BYTES:
+ upb_fielddef_settype(f, UPB_TYPE_BYTES);
+ break;
+ case UPB_DESCRIPTOR_TYPE_GROUP:
+ case UPB_DESCRIPTOR_TYPE_MESSAGE:
+ upb_fielddef_settype(f, UPB_TYPE_MESSAGE);
+ break;
+ case UPB_DESCRIPTOR_TYPE_ENUM:
+ upb_fielddef_settype(f, UPB_TYPE_ENUM);
+ break;
+ default: UPB_ASSERT(false);
+ }
+
+ if (type == UPB_DESCRIPTOR_TYPE_FIXED64 ||
+ type == UPB_DESCRIPTOR_TYPE_FIXED32 ||
+ type == UPB_DESCRIPTOR_TYPE_SFIXED64 ||
+ type == UPB_DESCRIPTOR_TYPE_SFIXED32) {
+ upb_fielddef_setintfmt(f, UPB_INTFMT_FIXED);
+ } else if (type == UPB_DESCRIPTOR_TYPE_SINT64 ||
+ type == UPB_DESCRIPTOR_TYPE_SINT32) {
+ upb_fielddef_setintfmt(f, UPB_INTFMT_ZIGZAG);
+ } else {
+ upb_fielddef_setintfmt(f, UPB_INTFMT_VARIABLE);
+ }
+
+ upb_fielddef_settagdelim(f, type == UPB_DESCRIPTOR_TYPE_GROUP);
+}
+
+upb_descriptortype_t upb_fielddef_descriptortype(const upb_fielddef *f) {
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_FLOAT: return UPB_DESCRIPTOR_TYPE_FLOAT;
+ case UPB_TYPE_DOUBLE: return UPB_DESCRIPTOR_TYPE_DOUBLE;
+ case UPB_TYPE_BOOL: return UPB_DESCRIPTOR_TYPE_BOOL;
+ case UPB_TYPE_STRING: return UPB_DESCRIPTOR_TYPE_STRING;
+ case UPB_TYPE_BYTES: return UPB_DESCRIPTOR_TYPE_BYTES;
+ case UPB_TYPE_ENUM: return UPB_DESCRIPTOR_TYPE_ENUM;
+ case UPB_TYPE_INT32:
+ switch (upb_fielddef_intfmt(f)) {
+ case UPB_INTFMT_VARIABLE: return UPB_DESCRIPTOR_TYPE_INT32;
+ case UPB_INTFMT_FIXED: return UPB_DESCRIPTOR_TYPE_SFIXED32;
+ case UPB_INTFMT_ZIGZAG: return UPB_DESCRIPTOR_TYPE_SINT32;
+ }
+ case UPB_TYPE_INT64:
+ switch (upb_fielddef_intfmt(f)) {
+ case UPB_INTFMT_VARIABLE: return UPB_DESCRIPTOR_TYPE_INT64;
+ case UPB_INTFMT_FIXED: return UPB_DESCRIPTOR_TYPE_SFIXED64;
+ case UPB_INTFMT_ZIGZAG: return UPB_DESCRIPTOR_TYPE_SINT64;
+ }
+ case UPB_TYPE_UINT32:
+ switch (upb_fielddef_intfmt(f)) {
+ case UPB_INTFMT_VARIABLE: return UPB_DESCRIPTOR_TYPE_UINT32;
+ case UPB_INTFMT_FIXED: return UPB_DESCRIPTOR_TYPE_FIXED32;
+ case UPB_INTFMT_ZIGZAG: return -1;
+ }
+ case UPB_TYPE_UINT64:
+ switch (upb_fielddef_intfmt(f)) {
+ case UPB_INTFMT_VARIABLE: return UPB_DESCRIPTOR_TYPE_UINT64;
+ case UPB_INTFMT_FIXED: return UPB_DESCRIPTOR_TYPE_FIXED64;
+ case UPB_INTFMT_ZIGZAG: return -1;
+ }
+ case UPB_TYPE_MESSAGE:
+ return upb_fielddef_istagdelim(f) ?
+ UPB_DESCRIPTOR_TYPE_GROUP : UPB_DESCRIPTOR_TYPE_MESSAGE;
+ }
+ return 0;
+}
+
+void upb_fielddef_setisextension(upb_fielddef *f, bool is_extension) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ f->is_extension_ = is_extension;
+}
+
+void upb_fielddef_setlazy(upb_fielddef *f, bool lazy) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ f->lazy_ = lazy;
+}
+
+void upb_fielddef_setpacked(upb_fielddef *f, bool packed) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ f->packed_ = packed;
+}
+
+void upb_fielddef_setlabel(upb_fielddef *f, upb_label_t label) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ UPB_ASSERT(upb_fielddef_checklabel(label));
+ f->label_ = label;
+}
+
+void upb_fielddef_setintfmt(upb_fielddef *f, upb_intfmt_t fmt) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ UPB_ASSERT(upb_fielddef_checkintfmt(fmt));
+ f->intfmt = fmt;
+}
+
+void upb_fielddef_settagdelim(upb_fielddef *f, bool tag_delim) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ f->tagdelim = tag_delim;
+ f->tagdelim = tag_delim;
+}
+
+static bool checksetdefault(upb_fielddef *f, upb_fieldtype_t type) {
+ if (!f->type_is_set_ || upb_fielddef_isfrozen(f) ||
+ upb_fielddef_type(f) != type) {
+ UPB_ASSERT(false);
+ return false;
+ }
+ if (f->default_is_string) {
+ str_t *s = f->defaultval.bytes;
+ UPB_ASSERT(s || type == UPB_TYPE_ENUM);
+ if (s) freestr(s);
+ }
+ f->default_is_string = false;
+ return true;
+}
+
+void upb_fielddef_setdefaultint64(upb_fielddef *f, int64_t value) {
+ if (checksetdefault(f, UPB_TYPE_INT64))
+ f->defaultval.sint = value;
+}
+
+void upb_fielddef_setdefaultint32(upb_fielddef *f, int32_t value) {
+ if ((upb_fielddef_type(f) == UPB_TYPE_ENUM &&
+ checksetdefault(f, UPB_TYPE_ENUM)) ||
+ checksetdefault(f, UPB_TYPE_INT32)) {
+ f->defaultval.sint = value;
+ }
+}
+
+void upb_fielddef_setdefaultuint64(upb_fielddef *f, uint64_t value) {
+ if (checksetdefault(f, UPB_TYPE_UINT64))
+ f->defaultval.uint = value;
+}
+
+void upb_fielddef_setdefaultuint32(upb_fielddef *f, uint32_t value) {
+ if (checksetdefault(f, UPB_TYPE_UINT32))
+ f->defaultval.uint = value;
+}
+
+void upb_fielddef_setdefaultbool(upb_fielddef *f, bool value) {
+ if (checksetdefault(f, UPB_TYPE_BOOL))
+ f->defaultval.uint = value;
+}
+
+void upb_fielddef_setdefaultfloat(upb_fielddef *f, float value) {
+ if (checksetdefault(f, UPB_TYPE_FLOAT))
+ f->defaultval.flt = value;
+}
+
+void upb_fielddef_setdefaultdouble(upb_fielddef *f, double value) {
+ if (checksetdefault(f, UPB_TYPE_DOUBLE))
+ f->defaultval.dbl = value;
+}
+
+bool upb_fielddef_setdefaultstr(upb_fielddef *f, const void *str, size_t len,
+ upb_status *s) {
+ str_t *str2;
+ UPB_ASSERT(upb_fielddef_isstring(f) || f->type_ == UPB_TYPE_ENUM);
+ if (f->type_ == UPB_TYPE_ENUM && !upb_isident(str, len, false, s))
+ return false;
+
+ if (f->default_is_string) {
+ str_t *s = f->defaultval.bytes;
+ UPB_ASSERT(s || f->type_ == UPB_TYPE_ENUM);
+ if (s) freestr(s);
+ } else {
+ UPB_ASSERT(f->type_ == UPB_TYPE_ENUM);
+ }
+
+ str2 = newstr(str, len);
+ f->defaultval.bytes = str2;
+ f->default_is_string = true;
+ return true;
+}
+
+void upb_fielddef_setdefaultcstr(upb_fielddef *f, const char *str,
+ upb_status *s) {
+ UPB_ASSERT(f->type_is_set_);
+ upb_fielddef_setdefaultstr(f, str, str ? strlen(str) : 0, s);
+}
+
+bool upb_fielddef_enumhasdefaultint32(const upb_fielddef *f) {
+ int32_t val;
+ UPB_ASSERT(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM);
+ return enumdefaultint32(f, &val);
+}
+
+bool upb_fielddef_enumhasdefaultstr(const upb_fielddef *f) {
+ UPB_ASSERT(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM);
+ return enumdefaultstr(f) != NULL;
+}
+
+static bool upb_subdef_typecheck(upb_fielddef *f, const upb_def *subdef,
+ upb_status *s) {
+ if (f->type_ == UPB_TYPE_MESSAGE) {
+ if (upb_dyncast_msgdef(subdef)) return true;
+ upb_status_seterrmsg(s, "invalid subdef type for this submessage field");
+ return false;
+ } else if (f->type_ == UPB_TYPE_ENUM) {
+ if (upb_dyncast_enumdef(subdef)) return true;
+ upb_status_seterrmsg(s, "invalid subdef type for this enum field");
+ return false;
+ } else {
+ upb_status_seterrmsg(s, "only message and enum fields can have a subdef");
+ return false;
+ }
+}
+
+static void release_subdef(upb_fielddef *f) {
+ if (f->subdef_is_symbolic) {
+ upb_gfree(f->sub.name);
+ } else if (f->sub.def) {
+ upb_unref2(f->sub.def, f);
+ }
+}
+
+bool upb_fielddef_setsubdef(upb_fielddef *f, const upb_def *subdef,
+ upb_status *s) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ UPB_ASSERT(upb_fielddef_hassubdef(f));
+ if (subdef && !upb_subdef_typecheck(f, subdef, s)) return false;
+ release_subdef(f);
+ f->sub.def = subdef;
+ f->subdef_is_symbolic = false;
+ if (f->sub.def) upb_ref2(f->sub.def, f);
+ return true;
+}
+
+bool upb_fielddef_setmsgsubdef(upb_fielddef *f, const upb_msgdef *subdef,
+ upb_status *s) {
+ return upb_fielddef_setsubdef(f, upb_msgdef_upcast(subdef), s);
+}
+
+bool upb_fielddef_setenumsubdef(upb_fielddef *f, const upb_enumdef *subdef,
+ upb_status *s) {
+ return upb_fielddef_setsubdef(f, upb_enumdef_upcast(subdef), s);
+}
+
+bool upb_fielddef_setsubdefname(upb_fielddef *f, const char *name,
+ upb_status *s) {
+ char *name_copy;
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ if (!upb_fielddef_hassubdef(f)) {
+ upb_status_seterrmsg(s, "field type does not accept a subdef");
+ return false;
+ }
+
+ name_copy = upb_gstrdup(name);
+ if (!name_copy) {
+ upb_upberr_setoom(s);
+ return false;
+ }
+
+ /* TODO: validate name (upb_isident() doesn't quite work atm because this name
+ * may have a leading "."). */
+ release_subdef(f);
+ f->sub.name = name_copy;
+ f->subdef_is_symbolic = true;
+ return true;
+}
+
+bool upb_fielddef_issubmsg(const upb_fielddef *f) {
+ return upb_fielddef_type(f) == UPB_TYPE_MESSAGE;
+}
+
+bool upb_fielddef_isstring(const upb_fielddef *f) {
+ return upb_fielddef_type(f) == UPB_TYPE_STRING ||
+ upb_fielddef_type(f) == UPB_TYPE_BYTES;
+}
+
+bool upb_fielddef_isseq(const upb_fielddef *f) {
+ return upb_fielddef_label(f) == UPB_LABEL_REPEATED;
+}
+
+bool upb_fielddef_isprimitive(const upb_fielddef *f) {
+ return !upb_fielddef_isstring(f) && !upb_fielddef_issubmsg(f);
+}
+
+bool upb_fielddef_ismap(const upb_fielddef *f) {
+ return upb_fielddef_isseq(f) && upb_fielddef_issubmsg(f) &&
+ upb_msgdef_mapentry(upb_fielddef_msgsubdef(f));
+}
+
+bool upb_fielddef_haspresence(const upb_fielddef *f) {
+ if (upb_fielddef_isseq(f)) return false;
+ if (upb_fielddef_issubmsg(f)) return true;
+
+ /* Primitive field: return true unless there is a message that specifies
+ * presence should not exist. */
+ if (f->msg_is_symbolic || !f->msg.def) return true;
+ return f->msg.def->syntax == UPB_SYNTAX_PROTO2;
+}
+
+bool upb_fielddef_hassubdef(const upb_fielddef *f) {
+ return upb_fielddef_issubmsg(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM;
+}
+
+static bool between(int32_t x, int32_t low, int32_t high) {
+ return x >= low && x <= high;
+}
+
+bool upb_fielddef_checklabel(int32_t label) { return between(label, 1, 3); }
+bool upb_fielddef_checktype(int32_t type) { return between(type, 1, 11); }
+bool upb_fielddef_checkintfmt(int32_t fmt) { return between(fmt, 1, 3); }
+
+bool upb_fielddef_checkdescriptortype(int32_t type) {
+ return between(type, 1, 18);
+}
+
+/* upb_msgdef *****************************************************************/
+
+static void visitmsg(const upb_refcounted *r, upb_refcounted_visit *visit,
+ void *closure) {
+ upb_msg_oneof_iter o;
+ const upb_msgdef *m = (const upb_msgdef*)r;
+ const upb_def *def = upb_msgdef_upcast(m);
+ upb_msg_field_iter i;
+ for(upb_msg_field_begin(&i, m);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ upb_fielddef *f = upb_msg_iter_field(&i);
+ visit(r, upb_fielddef_upcast2(f), closure);
+ }
+ for(upb_msg_oneof_begin(&o, m);
+ !upb_msg_oneof_done(&o);
+ upb_msg_oneof_next(&o)) {
+ upb_oneofdef *f = upb_msg_iter_oneof(&o);
+ visit(r, upb_oneofdef_upcast(f), closure);
+ }
+ if (upb_def_file(def)) {
+ visit(r, upb_filedef_upcast(upb_def_file(def)), closure);
+ }
+}
+
+static void freemsg(upb_refcounted *r) {
+ upb_msgdef *m = (upb_msgdef*)r;
+ upb_strtable_uninit(&m->ntof);
+ upb_inttable_uninit(&m->itof);
+ upb_def_uninit(upb_msgdef_upcast_mutable(m));
+ upb_gfree(m);
+}
+
+const struct upb_refcounted_vtbl upb_msgdef_vtbl = {visitmsg, freemsg};
+
+upb_msgdef *upb_msgdef_new(const void *owner) {
+ upb_msgdef *m = upb_gmalloc(sizeof(*m));
+ if (!m) return NULL;
+
+ if (!upb_def_init(upb_msgdef_upcast_mutable(m), UPB_DEF_MSG, &upb_msgdef_vtbl,
+ owner)) {
+ goto err2;
+ }
+
+ if (!upb_inttable_init(&m->itof, UPB_CTYPE_PTR)) goto err2;
+ if (!upb_strtable_init(&m->ntof, UPB_CTYPE_PTR)) goto err1;
+ m->map_entry = false;
+ m->syntax = UPB_SYNTAX_PROTO2;
+ return m;
+
+err1:
+ upb_inttable_uninit(&m->itof);
+err2:
+ upb_gfree(m);
+ return NULL;
+}
+
+bool upb_msgdef_freeze(upb_msgdef *m, upb_status *status) {
+ upb_def *d = upb_msgdef_upcast_mutable(m);
+ return upb_def_freeze(&d, 1, status);
+}
+
+const char *upb_msgdef_fullname(const upb_msgdef *m) {
+ return upb_def_fullname(upb_msgdef_upcast(m));
+}
+
+const char *upb_msgdef_name(const upb_msgdef *m) {
+ return upb_def_name(upb_msgdef_upcast(m));
+}
+
+bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname,
+ upb_status *s) {
+ return upb_def_setfullname(upb_msgdef_upcast_mutable(m), fullname, s);
+}
+
+bool upb_msgdef_setsyntax(upb_msgdef *m, upb_syntax_t syntax) {
+ if (syntax != UPB_SYNTAX_PROTO2 && syntax != UPB_SYNTAX_PROTO3) {
+ return false;
+ }
+
+ m->syntax = syntax;
+ return true;
+}
+
+upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m) {
+ return m->syntax;
+}
+
+/* Helper: check that the field |f| is safe to add to msgdef |m|. Set an error
+ * on status |s| and return false if not. */
+static bool check_field_add(const upb_msgdef *m, const upb_fielddef *f,
+ upb_status *s) {
+ if (upb_fielddef_containingtype(f) != NULL) {
+ upb_status_seterrmsg(s, "fielddef already belongs to a message");
+ return false;
+ } else if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) {
+ upb_status_seterrmsg(s, "field name or number were not set");
+ return false;
+ } else if (upb_msgdef_itof(m, upb_fielddef_number(f))) {
+ upb_status_seterrmsg(s, "duplicate field number");
+ return false;
+ } else if (upb_strtable_lookup(&m->ntof, upb_fielddef_name(f), NULL)) {
+ upb_status_seterrmsg(s, "name conflicts with existing field or oneof");
+ return false;
+ }
+ return true;
+}
+
+static void add_field(upb_msgdef *m, upb_fielddef *f, const void *ref_donor) {
+ release_containingtype(f);
+ f->msg.def = m;
+ f->msg_is_symbolic = false;
+ upb_inttable_insert(&m->itof, upb_fielddef_number(f), upb_value_ptr(f));
+ upb_strtable_insert(&m->ntof, upb_fielddef_name(f), upb_value_ptr(f));
+ upb_ref2(f, m);
+ upb_ref2(m, f);
+ if (ref_donor) upb_fielddef_unref(f, ref_donor);
+}
+
+bool upb_msgdef_addfield(upb_msgdef *m, upb_fielddef *f, const void *ref_donor,
+ upb_status *s) {
+ /* TODO: extensions need to have a separate namespace, because proto2 allows a
+ * top-level extension (ie. one not in any package) to have the same name as a
+ * field from the message.
+ *
+ * This also implies that there needs to be a separate lookup-by-name method
+ * for extensions. It seems desirable for iteration to return both extensions
+ * and non-extensions though.
+ *
+ * We also need to validate that the field number is in an extension range iff
+ * it is an extension.
+ *
+ * This method is idempotent. Check if |f| is already part of this msgdef and
+ * return immediately if so. */
+ if (upb_fielddef_containingtype(f) == m) {
+ if (ref_donor) upb_fielddef_unref(f, ref_donor);
+ return true;
+ }
+
+ /* Check constraints for all fields before performing any action. */
+ if (!check_field_add(m, f, s)) {
+ return false;
+ } else if (upb_fielddef_containingoneof(f) != NULL) {
+ /* Fields in a oneof can only be added by adding the oneof to the msgdef. */
+ upb_status_seterrmsg(s, "fielddef is part of a oneof");
+ return false;
+ }
+
+ /* Constraint checks ok, perform the action. */
+ add_field(m, f, ref_donor);
+ return true;
+}
+
+bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor,
+ upb_status *s) {
+ upb_oneof_iter it;
+
+ /* Check various conditions that would prevent this oneof from being added. */
+ if (upb_oneofdef_containingtype(o)) {
+ upb_status_seterrmsg(s, "oneofdef already belongs to a message");
+ return false;
+ } else if (upb_oneofdef_name(o) == NULL) {
+ upb_status_seterrmsg(s, "oneofdef name was not set");
+ return false;
+ } else if (upb_strtable_lookup(&m->ntof, upb_oneofdef_name(o), NULL)) {
+ upb_status_seterrmsg(s, "name conflicts with existing field or oneof");
+ return false;
+ }
+
+ /* Check that all of the oneof's fields do not conflict with names or numbers
+ * of fields already in the message. */
+ for (upb_oneof_begin(&it, o); !upb_oneof_done(&it); upb_oneof_next(&it)) {
+ const upb_fielddef *f = upb_oneof_iter_field(&it);
+ if (!check_field_add(m, f, s)) {
+ return false;
+ }
+ }
+
+ /* Everything checks out -- commit now. */
+
+ /* Add oneof itself first. */
+ o->parent = m;
+ upb_strtable_insert(&m->ntof, upb_oneofdef_name(o), upb_value_ptr(o));
+ upb_ref2(o, m);
+ upb_ref2(m, o);
+
+ /* Add each field of the oneof directly to the msgdef. */
+ for (upb_oneof_begin(&it, o); !upb_oneof_done(&it); upb_oneof_next(&it)) {
+ upb_fielddef *f = upb_oneof_iter_field(&it);
+ add_field(m, f, NULL);
+ }
+
+ if (ref_donor) upb_oneofdef_unref(o, ref_donor);
+
+ return true;
+}
+
+const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i) {
+ upb_value val;
+ return upb_inttable_lookup32(&m->itof, i, &val) ?
+ upb_value_getptr(val) : NULL;
+}
+
+const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name,
+ size_t len) {
+ upb_value val;
+
+ if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) {
+ return NULL;
+ }
+
+ return upb_trygetfield(upb_value_getptr(val));
+}
+
+const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name,
+ size_t len) {
+ upb_value val;
+
+ if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) {
+ return NULL;
+ }
+
+ return upb_trygetoneof(upb_value_getptr(val));
+}
+
+bool upb_msgdef_lookupname(const upb_msgdef *m, const char *name, size_t len,
+ const upb_fielddef **f, const upb_oneofdef **o) {
+ upb_value val;
+
+ if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) {
+ return false;
+ }
+
+ *o = upb_trygetoneof(upb_value_getptr(val));
+ *f = upb_trygetfield(upb_value_getptr(val));
+ UPB_ASSERT((*o != NULL) ^ (*f != NULL)); /* Exactly one of the two should be set. */
+ return true;
+}
+
+int upb_msgdef_numfields(const upb_msgdef *m) {
+ /* The number table contains only fields. */
+ return upb_inttable_count(&m->itof);
+}
+
+int upb_msgdef_numoneofs(const upb_msgdef *m) {
+ /* The name table includes oneofs, and the number table does not. */
+ return upb_strtable_count(&m->ntof) - upb_inttable_count(&m->itof);
+}
+
+void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry) {
+ UPB_ASSERT(!upb_msgdef_isfrozen(m));
+ m->map_entry = map_entry;
+}
+
+bool upb_msgdef_mapentry(const upb_msgdef *m) {
+ return m->map_entry;
+}
+
+void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m) {
+ upb_inttable_begin(iter, &m->itof);
+}
+
+void upb_msg_field_next(upb_msg_field_iter *iter) { upb_inttable_next(iter); }
+
+bool upb_msg_field_done(const upb_msg_field_iter *iter) {
+ return upb_inttable_done(iter);
+}
+
+upb_fielddef *upb_msg_iter_field(const upb_msg_field_iter *iter) {
+ return (upb_fielddef*)upb_value_getptr(upb_inttable_iter_value(iter));
+}
+
+void upb_msg_field_iter_setdone(upb_msg_field_iter *iter) {
+ upb_inttable_iter_setdone(iter);
+}
+
+void upb_msg_oneof_begin(upb_msg_oneof_iter *iter, const upb_msgdef *m) {
+ upb_strtable_begin(iter, &m->ntof);
+ /* We need to skip past any initial fields. */
+ while (!upb_strtable_done(iter) &&
+ !upb_isoneof(upb_value_getptr(upb_strtable_iter_value(iter)))) {
+ upb_strtable_next(iter);
+ }
+}
+
+void upb_msg_oneof_next(upb_msg_oneof_iter *iter) {
+ /* We need to skip past fields to return only oneofs. */
+ do {
+ upb_strtable_next(iter);
+ } while (!upb_strtable_done(iter) &&
+ !upb_isoneof(upb_value_getptr(upb_strtable_iter_value(iter))));
+}
+
+bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter) {
+ return upb_strtable_done(iter);
+}
+
+upb_oneofdef *upb_msg_iter_oneof(const upb_msg_oneof_iter *iter) {
+ return (upb_oneofdef*)upb_value_getptr(upb_strtable_iter_value(iter));
+}
+
+void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter *iter) {
+ upb_strtable_iter_setdone(iter);
+}
+
+/* upb_oneofdef ***************************************************************/
+
+static void visitoneof(const upb_refcounted *r, upb_refcounted_visit *visit,
+ void *closure) {
+ const upb_oneofdef *o = (const upb_oneofdef*)r;
+ upb_oneof_iter i;
+ for (upb_oneof_begin(&i, o); !upb_oneof_done(&i); upb_oneof_next(&i)) {
+ const upb_fielddef *f = upb_oneof_iter_field(&i);
+ visit(r, upb_fielddef_upcast2(f), closure);
+ }
+ if (o->parent) {
+ visit(r, upb_msgdef_upcast2(o->parent), closure);
+ }
+}
+
+static void freeoneof(upb_refcounted *r) {
+ upb_oneofdef *o = (upb_oneofdef*)r;
+ upb_strtable_uninit(&o->ntof);
+ upb_inttable_uninit(&o->itof);
+ upb_gfree((void*)o->name);
+ upb_gfree(o);
+}
+
+const struct upb_refcounted_vtbl upb_oneofdef_vtbl = {visitoneof, freeoneof};
+
+upb_oneofdef *upb_oneofdef_new(const void *owner) {
+ upb_oneofdef *o = upb_gmalloc(sizeof(*o));
+
+ if (!o) {
+ return NULL;
+ }
+
+ o->parent = NULL;
+ o->name = NULL;
+
+ if (!upb_refcounted_init(upb_oneofdef_upcast_mutable(o), &upb_oneofdef_vtbl,
+ owner)) {
+ goto err2;
+ }
+
+ if (!upb_inttable_init(&o->itof, UPB_CTYPE_PTR)) goto err2;
+ if (!upb_strtable_init(&o->ntof, UPB_CTYPE_PTR)) goto err1;
+
+ return o;
+
+err1:
+ upb_inttable_uninit(&o->itof);
+err2:
+ upb_gfree(o);
+ return NULL;
+}
+
+const char *upb_oneofdef_name(const upb_oneofdef *o) { return o->name; }
+
+bool upb_oneofdef_setname(upb_oneofdef *o, const char *name, upb_status *s) {
+ UPB_ASSERT(!upb_oneofdef_isfrozen(o));
+ if (upb_oneofdef_containingtype(o)) {
+ upb_status_seterrmsg(s, "oneof already added to a message");
+ return false;
+ }
+
+ if (!upb_isident(name, strlen(name), true, s)) {
+ return false;
+ }
+
+ name = upb_gstrdup(name);
+ if (!name) {
+ upb_status_seterrmsg(s, "One of memory");
+ return false;
+ }
+
+ upb_gfree((void*)o->name);
+ o->name = name;
+ return true;
+}
+
+const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o) {
+ return o->parent;
+}
+
+int upb_oneofdef_numfields(const upb_oneofdef *o) {
+ return upb_strtable_count(&o->ntof);
+}
+
+uint32_t upb_oneofdef_index(const upb_oneofdef *o) {
+ return o->index;
+}
+
+bool upb_oneofdef_addfield(upb_oneofdef *o, upb_fielddef *f,
+ const void *ref_donor,
+ upb_status *s) {
+ UPB_ASSERT(!upb_oneofdef_isfrozen(o));
+ UPB_ASSERT(!o->parent || !upb_msgdef_isfrozen(o->parent));
+
+ /* This method is idempotent. Check if |f| is already part of this oneofdef
+ * and return immediately if so. */
+ if (upb_fielddef_containingoneof(f) == o) {
+ return true;
+ }
+
+ /* The field must have an OPTIONAL label. */
+ if (upb_fielddef_label(f) != UPB_LABEL_OPTIONAL) {
+ upb_status_seterrmsg(s, "fields in oneof must have OPTIONAL label");
+ return false;
+ }
+
+ /* Check that no field with this name or number exists already in the oneof.
+ * Also check that the field is not already part of a oneof. */
+ if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) {
+ upb_status_seterrmsg(s, "field name or number were not set");
+ return false;
+ } else if (upb_oneofdef_itof(o, upb_fielddef_number(f)) ||
+ upb_oneofdef_ntofz(o, upb_fielddef_name(f))) {
+ upb_status_seterrmsg(s, "duplicate field name or number");
+ return false;
+ } else if (upb_fielddef_containingoneof(f) != NULL) {
+ upb_status_seterrmsg(s, "fielddef already belongs to a oneof");
+ return false;
+ }
+
+ /* We allow adding a field to the oneof either if the field is not part of a
+ * msgdef, or if it is and we are also part of the same msgdef. */
+ if (o->parent == NULL) {
+ /* If we're not in a msgdef, the field cannot be either. Otherwise we would
+ * need to magically add this oneof to a msgdef to remain consistent, which
+ * is surprising behavior. */
+ if (upb_fielddef_containingtype(f) != NULL) {
+ upb_status_seterrmsg(s, "fielddef already belongs to a message, but "
+ "oneof does not");
+ return false;
+ }
+ } else {
+ /* If we're in a msgdef, the user can add fields that either aren't in any
+ * msgdef (in which case they're added to our msgdef) or already a part of
+ * our msgdef. */
+ if (upb_fielddef_containingtype(f) != NULL &&
+ upb_fielddef_containingtype(f) != o->parent) {
+ upb_status_seterrmsg(s, "fielddef belongs to a different message "
+ "than oneof");
+ return false;
+ }
+ }
+
+ /* Commit phase. First add the field to our parent msgdef, if any, because
+ * that may fail; then add the field to our own tables. */
+
+ if (o->parent != NULL && upb_fielddef_containingtype(f) == NULL) {
+ if (!upb_msgdef_addfield((upb_msgdef*)o->parent, f, NULL, s)) {
+ return false;
+ }
+ }
+
+ release_containingtype(f);
+ f->oneof = o;
+ upb_inttable_insert(&o->itof, upb_fielddef_number(f), upb_value_ptr(f));
+ upb_strtable_insert(&o->ntof, upb_fielddef_name(f), upb_value_ptr(f));
+ upb_ref2(f, o);
+ upb_ref2(o, f);
+ if (ref_donor) upb_fielddef_unref(f, ref_donor);
+
+ return true;
+}
+
+const upb_fielddef *upb_oneofdef_ntof(const upb_oneofdef *o,
+ const char *name, size_t length) {
+ upb_value val;
+ return upb_strtable_lookup2(&o->ntof, name, length, &val) ?
+ upb_value_getptr(val) : NULL;
+}
+
+const upb_fielddef *upb_oneofdef_itof(const upb_oneofdef *o, uint32_t num) {
+ upb_value val;
+ return upb_inttable_lookup32(&o->itof, num, &val) ?
+ upb_value_getptr(val) : NULL;
+}
+
+void upb_oneof_begin(upb_oneof_iter *iter, const upb_oneofdef *o) {
+ upb_inttable_begin(iter, &o->itof);
+}
+
+void upb_oneof_next(upb_oneof_iter *iter) {
+ upb_inttable_next(iter);
+}
+
+bool upb_oneof_done(upb_oneof_iter *iter) {
+ return upb_inttable_done(iter);
+}
+
+upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter) {
+ return (upb_fielddef*)upb_value_getptr(upb_inttable_iter_value(iter));
+}
+
+void upb_oneof_iter_setdone(upb_oneof_iter *iter) {
+ upb_inttable_iter_setdone(iter);
+}
+
+/* upb_filedef ****************************************************************/
+
+static void visitfiledef(const upb_refcounted *r, upb_refcounted_visit *visit,
+ void *closure) {
+ const upb_filedef *f = (const upb_filedef*)r;
+ size_t i;
+
+ for(i = 0; i < upb_filedef_defcount(f); i++) {
+ visit(r, upb_def_upcast(upb_filedef_def(f, i)), closure);
+ }
+}
+
+static void freefiledef(upb_refcounted *r) {
+ upb_filedef *f = (upb_filedef*)r;
+ size_t i;
+
+ for(i = 0; i < upb_filedef_depcount(f); i++) {
+ upb_filedef_unref(upb_filedef_dep(f, i), f);
+ }
+
+ upb_inttable_uninit(&f->defs);
+ upb_inttable_uninit(&f->deps);
+ upb_gfree((void*)f->name);
+ upb_gfree((void*)f->package);
+ upb_gfree((void*)f->phpprefix);
+ upb_gfree(f);
+}
+
+const struct upb_refcounted_vtbl upb_filedef_vtbl = {visitfiledef, freefiledef};
+
+upb_filedef *upb_filedef_new(const void *owner) {
+ upb_filedef *f = upb_gmalloc(sizeof(*f));
+
+ if (!f) {
+ return NULL;
+ }
+
+ f->package = NULL;
+ f->name = NULL;
+ f->phpprefix = NULL;
+ f->syntax = UPB_SYNTAX_PROTO2;
+
+ if (!upb_refcounted_init(upb_filedef_upcast_mutable(f), &upb_filedef_vtbl,
+ owner)) {
+ goto err;
+ }
+
+ if (!upb_inttable_init(&f->defs, UPB_CTYPE_CONSTPTR)) {
+ goto err;
+ }
+
+ if (!upb_inttable_init(&f->deps, UPB_CTYPE_CONSTPTR)) {
+ goto err2;
+ }
+
+ return f;
+
+
+err2:
+ upb_inttable_uninit(&f->defs);
+
+err:
+ upb_gfree(f);
+ return NULL;
+}
+
+const char *upb_filedef_name(const upb_filedef *f) {
+ return f->name;
+}
+
+const char *upb_filedef_package(const upb_filedef *f) {
+ return f->package;
+}
+
+const char *upb_filedef_phpprefix(const upb_filedef *f) {
+ return f->phpprefix;
+}
+
+upb_syntax_t upb_filedef_syntax(const upb_filedef *f) {
+ return f->syntax;
+}
+
+size_t upb_filedef_defcount(const upb_filedef *f) {
+ return upb_inttable_count(&f->defs);
+}
+
+size_t upb_filedef_depcount(const upb_filedef *f) {
+ return upb_inttable_count(&f->deps);
+}
+
+const upb_def *upb_filedef_def(const upb_filedef *f, size_t i) {
+ upb_value v;
+
+ if (upb_inttable_lookup32(&f->defs, i, &v)) {
+ return upb_value_getconstptr(v);
+ } else {
+ return NULL;
+ }
+}
+
+const upb_filedef *upb_filedef_dep(const upb_filedef *f, size_t i) {
+ upb_value v;
+
+ if (upb_inttable_lookup32(&f->deps, i, &v)) {
+ return upb_value_getconstptr(v);
+ } else {
+ return NULL;
+ }
+}
+
+bool upb_filedef_setname(upb_filedef *f, const char *name, upb_status *s) {
+ name = upb_gstrdup(name);
+ if (!name) {
+ upb_upberr_setoom(s);
+ return false;
+ }
+ upb_gfree((void*)f->name);
+ f->name = name;
+ return true;
+}
+
+bool upb_filedef_setpackage(upb_filedef *f, const char *package,
+ upb_status *s) {
+ if (!upb_isident(package, strlen(package), true, s)) return false;
+ package = upb_gstrdup(package);
+ if (!package) {
+ upb_upberr_setoom(s);
+ return false;
+ }
+ upb_gfree((void*)f->package);
+ f->package = package;
+ return true;
+}
+
+bool upb_filedef_setphpprefix(upb_filedef *f, const char *phpprefix,
+ upb_status *s) {
+ phpprefix = upb_gstrdup(phpprefix);
+ if (!phpprefix) {
+ upb_upberr_setoom(s);
+ return false;
+ }
+ upb_gfree((void*)f->phpprefix);
+ f->phpprefix = phpprefix;
+ return true;
+}
+
+bool upb_filedef_setsyntax(upb_filedef *f, upb_syntax_t syntax,
+ upb_status *s) {
+ UPB_UNUSED(s);
+ if (syntax != UPB_SYNTAX_PROTO2 &&
+ syntax != UPB_SYNTAX_PROTO3) {
+ upb_status_seterrmsg(s, "Unknown syntax value.");
+ return false;
+ }
+ f->syntax = syntax;
+
+ {
+ /* Set all messages in this file to match. */
+ size_t i;
+ for (i = 0; i < upb_filedef_defcount(f); i++) {
+ /* Casting const away is safe since all defs in mutable filedef must
+ * also be mutable. */
+ upb_def *def = (upb_def*)upb_filedef_def(f, i);
+
+ upb_msgdef *m = upb_dyncast_msgdef_mutable(def);
+ if (m) {
+ m->syntax = syntax;
+ }
+ }
+ }
+
+ return true;
+}
+
+bool upb_filedef_adddef(upb_filedef *f, upb_def *def, const void *ref_donor,
+ upb_status *s) {
+ if (def->file) {
+ upb_status_seterrmsg(s, "Def is already part of another filedef.");
+ return false;
+ }
+
+ if (upb_inttable_push(&f->defs, upb_value_constptr(def))) {
+ def->file = f;
+ upb_ref2(def, f);
+ upb_ref2(f, def);
+ if (ref_donor) upb_def_unref(def, ref_donor);
+ if (def->type == UPB_DEF_MSG) {
+ upb_downcast_msgdef_mutable(def)->syntax = f->syntax;
+ }
+ return true;
+ } else {
+ upb_upberr_setoom(s);
+ return false;
+ }
+}
+
+bool upb_filedef_adddep(upb_filedef *f, const upb_filedef *dep) {
+ if (upb_inttable_push(&f->deps, upb_value_constptr(dep))) {
+ /* Regular ref instead of ref2 because files can't form cycles. */
+ upb_filedef_ref(dep, f);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+void upb_symtab_free(upb_symtab *s) {
+ upb_strtable_iter i;
+ upb_strtable_begin(&i, &s->symtab);
+ for (; !upb_strtable_done(&i); upb_strtable_next(&i)) {
+ const upb_def *def = upb_value_getptr(upb_strtable_iter_value(&i));
+ upb_def_unref(def, s);
+ }
+ upb_strtable_uninit(&s->symtab);
+ upb_gfree(s);
+}
+
+upb_symtab *upb_symtab_new() {
+ upb_symtab *s = upb_gmalloc(sizeof(*s));
+ if (!s) {
+ return NULL;
+ }
+
+ upb_strtable_init(&s->symtab, UPB_CTYPE_PTR);
+ return s;
+}
+
+const upb_def *upb_symtab_lookup(const upb_symtab *s, const char *sym) {
+ upb_value v;
+ upb_def *ret = upb_strtable_lookup(&s->symtab, sym, &v) ?
+ upb_value_getptr(v) : NULL;
+ return ret;
+}
+
+const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym) {
+ upb_value v;
+ upb_def *def = upb_strtable_lookup(&s->symtab, sym, &v) ?
+ upb_value_getptr(v) : NULL;
+ return def ? upb_dyncast_msgdef(def) : NULL;
+}
+
+const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym) {
+ upb_value v;
+ upb_def *def = upb_strtable_lookup(&s->symtab, sym, &v) ?
+ upb_value_getptr(v) : NULL;
+ return def ? upb_dyncast_enumdef(def) : NULL;
+}
+
+/* Given a symbol and the base symbol inside which it is defined, find the
+ * symbol's definition in t. */
+static upb_def *upb_resolvename(const upb_strtable *t,
+ const char *base, const char *sym) {
+ if(strlen(sym) == 0) return NULL;
+ if(sym[0] == '.') {
+ /* Symbols starting with '.' are absolute, so we do a single lookup.
+ * Slice to omit the leading '.' */
+ upb_value v;
+ return upb_strtable_lookup(t, sym + 1, &v) ? upb_value_getptr(v) : NULL;
+ } else {
+ /* Remove components from base until we find an entry or run out.
+ * TODO: This branch is totally broken, but currently not used. */
+ (void)base;
+ UPB_ASSERT(false);
+ return NULL;
+ }
+}
+
+const upb_def *upb_symtab_resolve(const upb_symtab *s, const char *base,
+ const char *sym) {
+ upb_def *ret = upb_resolvename(&s->symtab, base, sym);
+ return ret;
+}
+
+/* TODO(haberman): we need a lot more testing of error conditions. */
+static bool symtab_add(upb_symtab *s, upb_def *const*defs, size_t n,
+ void *ref_donor, upb_refcounted *freeze_also,
+ upb_status *status) {
+ size_t i;
+ size_t add_n;
+ size_t freeze_n;
+ upb_strtable_iter iter;
+ upb_refcounted **add_objs = NULL;
+ upb_def **add_defs = NULL;
+ size_t add_objs_size;
+ upb_strtable addtab;
+
+ if (n == 0 && !freeze_also) {
+ return true;
+ }
+
+ if (!upb_strtable_init(&addtab, UPB_CTYPE_PTR)) {
+ upb_status_seterrmsg(status, "out of memory");
+ return false;
+ }
+
+ /* Add new defs to our "add" set. */
+ for (i = 0; i < n; i++) {
+ upb_def *def = defs[i];
+ const char *fullname;
+ upb_fielddef *f;
+
+ if (upb_def_isfrozen(def)) {
+ upb_status_seterrmsg(status, "added defs must be mutable");
+ goto err;
+ }
+ UPB_ASSERT(!upb_def_isfrozen(def));
+ fullname = upb_def_fullname(def);
+ if (!fullname) {
+ upb_status_seterrmsg(
+ status, "Anonymous defs cannot be added to a symtab");
+ goto err;
+ }
+
+ f = upb_dyncast_fielddef_mutable(def);
+
+ if (f) {
+ if (!upb_fielddef_containingtypename(f)) {
+ upb_status_seterrmsg(status,
+ "Standalone fielddefs must have a containing type "
+ "(extendee) name set");
+ goto err;
+ }
+ } else {
+ if (upb_strtable_lookup(&addtab, fullname, NULL)) {
+ upb_status_seterrf(status, "Conflicting defs named '%s'", fullname);
+ goto err;
+ }
+ if (upb_strtable_lookup(&s->symtab, fullname, NULL)) {
+ upb_status_seterrf(status, "Symtab already has a def named '%s'",
+ fullname);
+ goto err;
+ }
+ if (!upb_strtable_insert(&addtab, fullname, upb_value_ptr(def)))
+ goto oom_err;
+ upb_def_donateref(def, ref_donor, s);
+ }
+
+ if (upb_dyncast_fielddef_mutable(def)) {
+ /* TODO(haberman): allow adding extensions attached to files. */
+ upb_status_seterrf(status, "Can't add extensions to symtab.\n");
+ goto err;
+ }
+ }
+
+ /* Now using the table, resolve symbolic references for subdefs. */
+ upb_strtable_begin(&iter, &addtab);
+ for (; !upb_strtable_done(&iter); upb_strtable_next(&iter)) {
+ const char *base;
+ upb_def *def = upb_value_getptr(upb_strtable_iter_value(&iter));
+ upb_msgdef *m = upb_dyncast_msgdef_mutable(def);
+ upb_msg_field_iter j;
+
+ if (!m) continue;
+ /* Type names are resolved relative to the message in which they appear. */
+ base = upb_msgdef_fullname(m);
+
+ for(upb_msg_field_begin(&j, m);
+ !upb_msg_field_done(&j);
+ upb_msg_field_next(&j)) {
+ upb_fielddef *f = upb_msg_iter_field(&j);
+ const char *name = upb_fielddef_subdefname(f);
+ if (name && !upb_fielddef_subdef(f)) {
+ /* Try the lookup in the current set of to-be-added defs first. If not
+ * there, try existing defs. */
+ upb_def *subdef = upb_resolvename(&addtab, base, name);
+ if (subdef == NULL) {
+ subdef = upb_resolvename(&s->symtab, base, name);
+ }
+ if (subdef == NULL) {
+ upb_status_seterrf(
+ status, "couldn't resolve name '%s' in message '%s'", name, base);
+ goto err;
+ } else if (!upb_fielddef_setsubdef(f, subdef, status)) {
+ goto err;
+ }
+ }
+ }
+ }
+
+ /* We need an array of the defs in addtab, for passing to
+ * upb_refcounted_freeze(). */
+ add_objs_size = upb_strtable_count(&addtab);
+ if (freeze_also) {
+ add_objs_size++;
+ }
+
+ add_defs = upb_gmalloc(sizeof(void*) * add_objs_size);
+ if (add_defs == NULL) goto oom_err;
+ upb_strtable_begin(&iter, &addtab);
+ for (add_n = 0; !upb_strtable_done(&iter); upb_strtable_next(&iter)) {
+ add_defs[add_n++] = upb_value_getptr(upb_strtable_iter_value(&iter));
+ }
+
+ /* Validate defs. */
+ if (!_upb_def_validate(add_defs, add_n, status)) {
+ goto err;
+ }
+
+ /* Cheat a little and give the array a new type.
+ * This is probably undefined behavior, but this code will be deleted soon. */
+ add_objs = (upb_refcounted**)add_defs;
+
+ freeze_n = add_n;
+ if (freeze_also) {
+ add_objs[freeze_n++] = freeze_also;
+ }
+
+ if (!upb_refcounted_freeze(add_objs, freeze_n, status,
+ UPB_MAX_MESSAGE_DEPTH * 2)) {
+ goto err;
+ }
+
+ /* This must be delayed until all errors have been detected, since error
+ * recovery code uses this table to cleanup defs. */
+ upb_strtable_uninit(&addtab);
+
+ /* TODO(haberman) we don't properly handle errors after this point (like
+ * OOM in upb_strtable_insert() below). */
+ for (i = 0; i < add_n; i++) {
+ upb_def *def = (upb_def*)add_objs[i];
+ const char *name = upb_def_fullname(def);
+ bool success;
+ success = upb_strtable_insert(&s->symtab, name, upb_value_ptr(def));
+ UPB_ASSERT(success);
+ }
+ upb_gfree(add_defs);
+ return true;
+
+oom_err:
+ upb_status_seterrmsg(status, "out of memory");
+err: {
+ /* We need to donate the refs back. */
+ upb_strtable_begin(&iter, &addtab);
+ for (; !upb_strtable_done(&iter); upb_strtable_next(&iter)) {
+ upb_def *def = upb_value_getptr(upb_strtable_iter_value(&iter));
+ upb_def_donateref(def, s, ref_donor);
+ }
+ }
+ upb_strtable_uninit(&addtab);
+ upb_gfree(add_defs);
+ UPB_ASSERT(!upb_ok(status));
+ return false;
+}
+
+bool upb_symtab_add(upb_symtab *s, upb_def *const*defs, size_t n,
+ void *ref_donor, upb_status *status) {
+ return symtab_add(s, defs, n, ref_donor, NULL, status);
+}
+
+bool upb_symtab_addfile(upb_symtab *s, upb_filedef *file, upb_status *status) {
+ size_t n;
+ size_t i;
+ upb_def **defs;
+ bool ret;
+
+ n = upb_filedef_defcount(file);
+ defs = upb_gmalloc(sizeof(*defs) * n);
+
+ if (defs == NULL) {
+ upb_status_seterrmsg(status, "Out of memory");
+ return false;
+ }
+
+ for (i = 0; i < n; i++) {
+ defs[i] = upb_filedef_mutabledef(file, i);
+ }
+
+ ret = symtab_add(s, defs, n, NULL, upb_filedef_upcast_mutable(file), status);
+
+ upb_gfree(defs);
+ return ret;
+}
+
+/* Iteration. */
+
+static void advance_to_matching(upb_symtab_iter *iter) {
+ if (iter->type == UPB_DEF_ANY)
+ return;
+
+ while (!upb_strtable_done(&iter->iter) &&
+ iter->type != upb_symtab_iter_def(iter)->type) {
+ upb_strtable_next(&iter->iter);
+ }
+}
+
+void upb_symtab_begin(upb_symtab_iter *iter, const upb_symtab *s,
+ upb_deftype_t type) {
+ upb_strtable_begin(&iter->iter, &s->symtab);
+ iter->type = type;
+ advance_to_matching(iter);
+}
+
+void upb_symtab_next(upb_symtab_iter *iter) {
+ upb_strtable_next(&iter->iter);
+ advance_to_matching(iter);
+}
+
+bool upb_symtab_done(const upb_symtab_iter *iter) {
+ return upb_strtable_done(&iter->iter);
+}
+
+const upb_def *upb_symtab_iter_def(const upb_symtab_iter *iter) {
+ return upb_value_getptr(upb_strtable_iter_value(&iter->iter));
+}
+/*
+** TODO(haberman): it's unclear whether a lot of the consistency checks should
+** UPB_ASSERT() or return false.
+*/
+
+
+#include <string.h>
+
+
+static void *upb_calloc(size_t size) {
+ void *mem = upb_gmalloc(size);
+ if (mem) {
+ memset(mem, 0, size);
+ }
+ return mem;
+}
+
+/* Defined for the sole purpose of having a unique pointer value for
+ * UPB_NO_CLOSURE. */
+char _upb_noclosure;
+
+static void freehandlers(upb_refcounted *r) {
+ upb_handlers *h = (upb_handlers*)r;
+
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, &h->cleanup_);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ void *val = (void*)upb_inttable_iter_key(&i);
+ upb_value func_val = upb_inttable_iter_value(&i);
+ upb_handlerfree *func = upb_value_getfptr(func_val);
+ func(val);
+ }
+
+ upb_inttable_uninit(&h->cleanup_);
+ upb_msgdef_unref(h->msg, h);
+ upb_gfree(h->sub);
+ upb_gfree(h);
+}
+
+static void visithandlers(const upb_refcounted *r, upb_refcounted_visit *visit,
+ void *closure) {
+ const upb_handlers *h = (const upb_handlers*)r;
+ upb_msg_field_iter i;
+ for(upb_msg_field_begin(&i, h->msg);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ upb_fielddef *f = upb_msg_iter_field(&i);
+ const upb_handlers *sub;
+ if (!upb_fielddef_issubmsg(f)) continue;
+ sub = upb_handlers_getsubhandlers(h, f);
+ if (sub) visit(r, upb_handlers_upcast(sub), closure);
+ }
+}
+
+static const struct upb_refcounted_vtbl vtbl = {visithandlers, freehandlers};
+
+typedef struct {
+ upb_inttable tab; /* maps upb_msgdef* -> upb_handlers*. */
+ upb_handlers_callback *callback;
+ const void *closure;
+} dfs_state;
+
+/* TODO(haberman): discard upb_handlers* objects that do not actually have any
+ * handlers set and cannot reach any upb_handlers* object that does. This is
+ * slightly tricky to do correctly. */
+static upb_handlers *newformsg(const upb_msgdef *m, const void *owner,
+ dfs_state *s) {
+ upb_msg_field_iter i;
+ upb_handlers *h = upb_handlers_new(m, owner);
+ if (!h) return NULL;
+ if (!upb_inttable_insertptr(&s->tab, m, upb_value_ptr(h))) goto oom;
+
+ s->callback(s->closure, h);
+
+ /* For each submessage field, get or create a handlers object and set it as
+ * the subhandlers. */
+ for(upb_msg_field_begin(&i, m);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ upb_fielddef *f = upb_msg_iter_field(&i);
+ const upb_msgdef *subdef;
+ upb_value subm_ent;
+
+ if (!upb_fielddef_issubmsg(f)) continue;
+
+ subdef = upb_downcast_msgdef(upb_fielddef_subdef(f));
+ if (upb_inttable_lookupptr(&s->tab, subdef, &subm_ent)) {
+ upb_handlers_setsubhandlers(h, f, upb_value_getptr(subm_ent));
+ } else {
+ upb_handlers *sub_mh = newformsg(subdef, &sub_mh, s);
+ if (!sub_mh) goto oom;
+ upb_handlers_setsubhandlers(h, f, sub_mh);
+ upb_handlers_unref(sub_mh, &sub_mh);
+ }
+ }
+ return h;
+
+oom:
+ upb_handlers_unref(h, owner);
+ return NULL;
+}
+
+/* Given a selector for a STARTSUBMSG handler, resolves to a pointer to the
+ * subhandlers for this submessage field. */
+#define SUBH(h, selector) (h->sub[selector])
+
+/* The selector for a submessage field is the field index. */
+#define SUBH_F(h, f) SUBH(h, f->index_)
+
+static int32_t trygetsel(upb_handlers *h, const upb_fielddef *f,
+ upb_handlertype_t type) {
+ upb_selector_t sel;
+ UPB_ASSERT(!upb_handlers_isfrozen(h));
+ if (upb_handlers_msgdef(h) != upb_fielddef_containingtype(f)) {
+ upb_status_seterrf(
+ &h->status_, "type mismatch: field %s does not belong to message %s",
+ upb_fielddef_name(f), upb_msgdef_fullname(upb_handlers_msgdef(h)));
+ return -1;
+ }
+ if (!upb_handlers_getselector(f, type, &sel)) {
+ upb_status_seterrf(
+ &h->status_,
+ "type mismatch: cannot register handler type %d for field %s",
+ type, upb_fielddef_name(f));
+ return -1;
+ }
+ return sel;
+}
+
+static upb_selector_t handlers_getsel(upb_handlers *h, const upb_fielddef *f,
+ upb_handlertype_t type) {
+ int32_t sel = trygetsel(h, f, type);
+ UPB_ASSERT(sel >= 0);
+ return sel;
+}
+
+static const void **returntype(upb_handlers *h, const upb_fielddef *f,
+ upb_handlertype_t type) {
+ return &h->table[handlers_getsel(h, f, type)].attr.return_closure_type_;
+}
+
+static bool doset(upb_handlers *h, int32_t sel, const upb_fielddef *f,
+ upb_handlertype_t type, upb_func *func,
+ upb_handlerattr *attr) {
+ upb_handlerattr set_attr = UPB_HANDLERATTR_INITIALIZER;
+ const void *closure_type;
+ const void **context_closure_type;
+
+ UPB_ASSERT(!upb_handlers_isfrozen(h));
+
+ if (sel < 0) {
+ upb_status_seterrmsg(&h->status_,
+ "incorrect handler type for this field.");
+ return false;
+ }
+
+ if (h->table[sel].func) {
+ upb_status_seterrmsg(&h->status_,
+ "cannot change handler once it has been set.");
+ return false;
+ }
+
+ if (attr) {
+ set_attr = *attr;
+ }
+
+ /* Check that the given closure type matches the closure type that has been
+ * established for this context (if any). */
+ closure_type = upb_handlerattr_closuretype(&set_attr);
+
+ if (type == UPB_HANDLER_STRING) {
+ context_closure_type = returntype(h, f, UPB_HANDLER_STARTSTR);
+ } else if (f && upb_fielddef_isseq(f) &&
+ type != UPB_HANDLER_STARTSEQ &&
+ type != UPB_HANDLER_ENDSEQ) {
+ context_closure_type = returntype(h, f, UPB_HANDLER_STARTSEQ);
+ } else {
+ context_closure_type = &h->top_closure_type;
+ }
+
+ if (closure_type && *context_closure_type &&
+ closure_type != *context_closure_type) {
+ /* TODO(haberman): better message for debugging. */
+ if (f) {
+ upb_status_seterrf(&h->status_,
+ "closure type does not match for field %s",
+ upb_fielddef_name(f));
+ } else {
+ upb_status_seterrmsg(
+ &h->status_, "closure type does not match for message-level handler");
+ }
+ return false;
+ }
+
+ if (closure_type)
+ *context_closure_type = closure_type;
+
+ /* If this is a STARTSEQ or STARTSTR handler, check that the returned pointer
+ * matches any pre-existing expectations about what type is expected. */
+ if (type == UPB_HANDLER_STARTSEQ || type == UPB_HANDLER_STARTSTR) {
+ const void *return_type = upb_handlerattr_returnclosuretype(&set_attr);
+ const void *table_return_type =
+ upb_handlerattr_returnclosuretype(&h->table[sel].attr);
+ if (return_type && table_return_type && return_type != table_return_type) {
+ upb_status_seterrmsg(&h->status_, "closure return type does not match");
+ return false;
+ }
+
+ if (table_return_type && !return_type)
+ upb_handlerattr_setreturnclosuretype(&set_attr, table_return_type);
+ }
+
+ h->table[sel].func = (upb_func*)func;
+ h->table[sel].attr = set_attr;
+ return true;
+}
+
+/* Returns the effective closure type for this handler (which will propagate
+ * from outer frames if this frame has no START* handler). Not implemented for
+ * UPB_HANDLER_STRING at the moment since this is not needed. Returns NULL is
+ * the effective closure type is unspecified (either no handler was registered
+ * to specify it or the handler that was registered did not specify the closure
+ * type). */
+const void *effective_closure_type(upb_handlers *h, const upb_fielddef *f,
+ upb_handlertype_t type) {
+ const void *ret;
+ upb_selector_t sel;
+
+ UPB_ASSERT(type != UPB_HANDLER_STRING);
+ ret = h->top_closure_type;
+
+ if (upb_fielddef_isseq(f) &&
+ type != UPB_HANDLER_STARTSEQ &&
+ type != UPB_HANDLER_ENDSEQ &&
+ h->table[sel = handlers_getsel(h, f, UPB_HANDLER_STARTSEQ)].func) {
+ ret = upb_handlerattr_returnclosuretype(&h->table[sel].attr);
+ }
+
+ if (type == UPB_HANDLER_STRING &&
+ h->table[sel = handlers_getsel(h, f, UPB_HANDLER_STARTSTR)].func) {
+ ret = upb_handlerattr_returnclosuretype(&h->table[sel].attr);
+ }
+
+ /* The effective type of the submessage; not used yet.
+ * if (type == SUBMESSAGE &&
+ * h->table[sel = handlers_getsel(h, f, UPB_HANDLER_STARTSUBMSG)].func) {
+ * ret = upb_handlerattr_returnclosuretype(&h->table[sel].attr);
+ * } */
+
+ return ret;
+}
+
+/* Checks whether the START* handler specified by f & type is missing even
+ * though it is required to convert the established type of an outer frame
+ * ("closure_type") into the established type of an inner frame (represented in
+ * the return closure type of this handler's attr. */
+bool checkstart(upb_handlers *h, const upb_fielddef *f, upb_handlertype_t type,
+ upb_status *status) {
+ const void *closure_type;
+ const upb_handlerattr *attr;
+ const void *return_closure_type;
+
+ upb_selector_t sel = handlers_getsel(h, f, type);
+ if (h->table[sel].func) return true;
+ closure_type = effective_closure_type(h, f, type);
+ attr = &h->table[sel].attr;
+ return_closure_type = upb_handlerattr_returnclosuretype(attr);
+ if (closure_type && return_closure_type &&
+ closure_type != return_closure_type) {
+ upb_status_seterrf(status,
+ "expected start handler to return sub type for field %f",
+ upb_fielddef_name(f));
+ return false;
+ }
+ return true;
+}
+
+/* Public interface ***********************************************************/
+
+upb_handlers *upb_handlers_new(const upb_msgdef *md, const void *owner) {
+ int extra;
+ upb_handlers *h;
+
+ UPB_ASSERT(upb_msgdef_isfrozen(md));
+
+ extra = sizeof(upb_handlers_tabent) * (md->selector_count - 1);
+ h = upb_calloc(sizeof(*h) + extra);
+ if (!h) return NULL;
+
+ h->msg = md;
+ upb_msgdef_ref(h->msg, h);
+ upb_status_clear(&h->status_);
+
+ if (md->submsg_field_count > 0) {
+ h->sub = upb_calloc(md->submsg_field_count * sizeof(*h->sub));
+ if (!h->sub) goto oom;
+ } else {
+ h->sub = 0;
+ }
+
+ if (!upb_refcounted_init(upb_handlers_upcast_mutable(h), &vtbl, owner))
+ goto oom;
+ if (!upb_inttable_init(&h->cleanup_, UPB_CTYPE_FPTR)) goto oom;
+
+ /* calloc() above initialized all handlers to NULL. */
+ return h;
+
+oom:
+ freehandlers(upb_handlers_upcast_mutable(h));
+ return NULL;
+}
+
+const upb_handlers *upb_handlers_newfrozen(const upb_msgdef *m,
+ const void *owner,
+ upb_handlers_callback *callback,
+ const void *closure) {
+ dfs_state state;
+ upb_handlers *ret;
+ bool ok;
+ upb_refcounted *r;
+
+ state.callback = callback;
+ state.closure = closure;
+ if (!upb_inttable_init(&state.tab, UPB_CTYPE_PTR)) return NULL;
+
+ ret = newformsg(m, owner, &state);
+
+ upb_inttable_uninit(&state.tab);
+ if (!ret) return NULL;
+
+ r = upb_handlers_upcast_mutable(ret);
+ ok = upb_refcounted_freeze(&r, 1, NULL, UPB_MAX_HANDLER_DEPTH);
+ UPB_ASSERT(ok);
+
+ return ret;
+}
+
+const upb_status *upb_handlers_status(upb_handlers *h) {
+ UPB_ASSERT(!upb_handlers_isfrozen(h));
+ return &h->status_;
+}
+
+void upb_handlers_clearerr(upb_handlers *h) {
+ UPB_ASSERT(!upb_handlers_isfrozen(h));
+ upb_status_clear(&h->status_);
+}
+
+#define SETTER(name, handlerctype, handlertype) \
+ bool upb_handlers_set ## name(upb_handlers *h, const upb_fielddef *f, \
+ handlerctype func, upb_handlerattr *attr) { \
+ int32_t sel = trygetsel(h, f, handlertype); \
+ return doset(h, sel, f, handlertype, (upb_func*)func, attr); \
+ }
+
+SETTER(int32, upb_int32_handlerfunc*, UPB_HANDLER_INT32)
+SETTER(int64, upb_int64_handlerfunc*, UPB_HANDLER_INT64)
+SETTER(uint32, upb_uint32_handlerfunc*, UPB_HANDLER_UINT32)
+SETTER(uint64, upb_uint64_handlerfunc*, UPB_HANDLER_UINT64)
+SETTER(float, upb_float_handlerfunc*, UPB_HANDLER_FLOAT)
+SETTER(double, upb_double_handlerfunc*, UPB_HANDLER_DOUBLE)
+SETTER(bool, upb_bool_handlerfunc*, UPB_HANDLER_BOOL)
+SETTER(startstr, upb_startstr_handlerfunc*, UPB_HANDLER_STARTSTR)
+SETTER(string, upb_string_handlerfunc*, UPB_HANDLER_STRING)
+SETTER(endstr, upb_endfield_handlerfunc*, UPB_HANDLER_ENDSTR)
+SETTER(startseq, upb_startfield_handlerfunc*, UPB_HANDLER_STARTSEQ)
+SETTER(startsubmsg, upb_startfield_handlerfunc*, UPB_HANDLER_STARTSUBMSG)
+SETTER(endsubmsg, upb_endfield_handlerfunc*, UPB_HANDLER_ENDSUBMSG)
+SETTER(endseq, upb_endfield_handlerfunc*, UPB_HANDLER_ENDSEQ)
+
+#undef SETTER
+
+bool upb_handlers_setstartmsg(upb_handlers *h, upb_startmsg_handlerfunc *func,
+ upb_handlerattr *attr) {
+ return doset(h, UPB_STARTMSG_SELECTOR, NULL, UPB_HANDLER_INT32,
+ (upb_func *)func, attr);
+}
+
+bool upb_handlers_setendmsg(upb_handlers *h, upb_endmsg_handlerfunc *func,
+ upb_handlerattr *attr) {
+ UPB_ASSERT(!upb_handlers_isfrozen(h));
+ return doset(h, UPB_ENDMSG_SELECTOR, NULL, UPB_HANDLER_INT32,
+ (upb_func *)func, attr);
+}
+
+bool upb_handlers_setsubhandlers(upb_handlers *h, const upb_fielddef *f,
+ const upb_handlers *sub) {
+ UPB_ASSERT(sub);
+ UPB_ASSERT(!upb_handlers_isfrozen(h));
+ UPB_ASSERT(upb_fielddef_issubmsg(f));
+ if (SUBH_F(h, f)) return false; /* Can't reset. */
+ if (upb_msgdef_upcast(upb_handlers_msgdef(sub)) != upb_fielddef_subdef(f)) {
+ return false;
+ }
+ SUBH_F(h, f) = sub;
+ upb_ref2(sub, h);
+ return true;
+}
+
+const upb_handlers *upb_handlers_getsubhandlers(const upb_handlers *h,
+ const upb_fielddef *f) {
+ UPB_ASSERT(upb_fielddef_issubmsg(f));
+ return SUBH_F(h, f);
+}
+
+bool upb_handlers_getattr(const upb_handlers *h, upb_selector_t sel,
+ upb_handlerattr *attr) {
+ if (!upb_handlers_gethandler(h, sel))
+ return false;
+ *attr = h->table[sel].attr;
+ return true;
+}
+
+const upb_handlers *upb_handlers_getsubhandlers_sel(const upb_handlers *h,
+ upb_selector_t sel) {
+ /* STARTSUBMSG selector in sel is the field's selector base. */
+ return SUBH(h, sel - UPB_STATIC_SELECTOR_COUNT);
+}
+
+const upb_msgdef *upb_handlers_msgdef(const upb_handlers *h) { return h->msg; }
+
+bool upb_handlers_addcleanup(upb_handlers *h, void *p, upb_handlerfree *func) {
+ bool ok;
+ if (upb_inttable_lookupptr(&h->cleanup_, p, NULL)) {
+ return false;
+ }
+ ok = upb_inttable_insertptr(&h->cleanup_, p, upb_value_fptr(func));
+ UPB_ASSERT(ok);
+ return true;
+}
+
+
+/* "Static" methods ***********************************************************/
+
+bool upb_handlers_freeze(upb_handlers *const*handlers, int n, upb_status *s) {
+ /* TODO: verify we have a transitive closure. */
+ int i;
+ for (i = 0; i < n; i++) {
+ upb_msg_field_iter j;
+ upb_handlers *h = handlers[i];
+
+ if (!upb_ok(&h->status_)) {
+ upb_status_seterrf(s, "handlers for message %s had error status: %s",
+ upb_msgdef_fullname(upb_handlers_msgdef(h)),
+ upb_status_errmsg(&h->status_));
+ return false;
+ }
+
+ /* Check that there are no closure mismatches due to missing Start* handlers
+ * or subhandlers with different type-level types. */
+ for(upb_msg_field_begin(&j, h->msg);
+ !upb_msg_field_done(&j);
+ upb_msg_field_next(&j)) {
+
+ const upb_fielddef *f = upb_msg_iter_field(&j);
+ if (upb_fielddef_isseq(f)) {
+ if (!checkstart(h, f, UPB_HANDLER_STARTSEQ, s))
+ return false;
+ }
+
+ if (upb_fielddef_isstring(f)) {
+ if (!checkstart(h, f, UPB_HANDLER_STARTSTR, s))
+ return false;
+ }
+
+ if (upb_fielddef_issubmsg(f)) {
+ bool hashandler = false;
+ if (upb_handlers_gethandler(
+ h, handlers_getsel(h, f, UPB_HANDLER_STARTSUBMSG)) ||
+ upb_handlers_gethandler(
+ h, handlers_getsel(h, f, UPB_HANDLER_ENDSUBMSG))) {
+ hashandler = true;
+ }
+
+ if (upb_fielddef_isseq(f) &&
+ (upb_handlers_gethandler(
+ h, handlers_getsel(h, f, UPB_HANDLER_STARTSEQ)) ||
+ upb_handlers_gethandler(
+ h, handlers_getsel(h, f, UPB_HANDLER_ENDSEQ)))) {
+ hashandler = true;
+ }
+
+ if (hashandler && !upb_handlers_getsubhandlers(h, f)) {
+ /* For now we add an empty subhandlers in this case. It makes the
+ * decoder code generator simpler, because it only has to handle two
+ * cases (submessage has handlers or not) as opposed to three
+ * (submessage has handlers in enclosing message but no subhandlers).
+ *
+ * This makes parsing less efficient in the case that we want to
+ * notice a submessage but skip its contents (like if we're testing
+ * for submessage presence or counting the number of repeated
+ * submessages). In this case we will end up parsing the submessage
+ * field by field and throwing away the results for each, instead of
+ * skipping the whole delimited thing at once. If this is an issue we
+ * can revisit it, but do remember that this only arises when you have
+ * handlers (startseq/startsubmsg/endsubmsg/endseq) set for the
+ * submessage but no subhandlers. The uses cases for this are
+ * limited. */
+ upb_handlers *sub = upb_handlers_new(upb_fielddef_msgsubdef(f), &sub);
+ upb_handlers_setsubhandlers(h, f, sub);
+ upb_handlers_unref(sub, &sub);
+ }
+
+ /* TODO(haberman): check type of submessage.
+ * This is slightly tricky; also consider whether we should check that
+ * they match at setsubhandlers time. */
+ }
+ }
+ }
+
+ if (!upb_refcounted_freeze((upb_refcounted*const*)handlers, n, s,
+ UPB_MAX_HANDLER_DEPTH)) {
+ return false;
+ }
+
+ return true;
+}
+
+upb_handlertype_t upb_handlers_getprimitivehandlertype(const upb_fielddef *f) {
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_ENUM: return UPB_HANDLER_INT32;
+ case UPB_TYPE_INT64: return UPB_HANDLER_INT64;
+ case UPB_TYPE_UINT32: return UPB_HANDLER_UINT32;
+ case UPB_TYPE_UINT64: return UPB_HANDLER_UINT64;
+ case UPB_TYPE_FLOAT: return UPB_HANDLER_FLOAT;
+ case UPB_TYPE_DOUBLE: return UPB_HANDLER_DOUBLE;
+ case UPB_TYPE_BOOL: return UPB_HANDLER_BOOL;
+ default: UPB_ASSERT(false); return -1; /* Invalid input. */
+ }
+}
+
+bool upb_handlers_getselector(const upb_fielddef *f, upb_handlertype_t type,
+ upb_selector_t *s) {
+ switch (type) {
+ case UPB_HANDLER_INT32:
+ case UPB_HANDLER_INT64:
+ case UPB_HANDLER_UINT32:
+ case UPB_HANDLER_UINT64:
+ case UPB_HANDLER_FLOAT:
+ case UPB_HANDLER_DOUBLE:
+ case UPB_HANDLER_BOOL:
+ if (!upb_fielddef_isprimitive(f) ||
+ upb_handlers_getprimitivehandlertype(f) != type)
+ return false;
+ *s = f->selector_base;
+ break;
+ case UPB_HANDLER_STRING:
+ if (upb_fielddef_isstring(f)) {
+ *s = f->selector_base;
+ } else if (upb_fielddef_lazy(f)) {
+ *s = f->selector_base + 3;
+ } else {
+ return false;
+ }
+ break;
+ case UPB_HANDLER_STARTSTR:
+ if (upb_fielddef_isstring(f) || upb_fielddef_lazy(f)) {
+ *s = f->selector_base + 1;
+ } else {
+ return false;
+ }
+ break;
+ case UPB_HANDLER_ENDSTR:
+ if (upb_fielddef_isstring(f) || upb_fielddef_lazy(f)) {
+ *s = f->selector_base + 2;
+ } else {
+ return false;
+ }
+ break;
+ case UPB_HANDLER_STARTSEQ:
+ if (!upb_fielddef_isseq(f)) return false;
+ *s = f->selector_base - 2;
+ break;
+ case UPB_HANDLER_ENDSEQ:
+ if (!upb_fielddef_isseq(f)) return false;
+ *s = f->selector_base - 1;
+ break;
+ case UPB_HANDLER_STARTSUBMSG:
+ if (!upb_fielddef_issubmsg(f)) return false;
+ /* Selectors for STARTSUBMSG are at the beginning of the table so that the
+ * selector can also be used as an index into the "sub" array of
+ * subhandlers. The indexes for the two into these two tables are the
+ * same, except that in the handler table the static selectors come first. */
+ *s = f->index_ + UPB_STATIC_SELECTOR_COUNT;
+ break;
+ case UPB_HANDLER_ENDSUBMSG:
+ if (!upb_fielddef_issubmsg(f)) return false;
+ *s = f->selector_base;
+ break;
+ }
+ UPB_ASSERT((size_t)*s < upb_fielddef_containingtype(f)->selector_count);
+ return true;
+}
+
+uint32_t upb_handlers_selectorbaseoffset(const upb_fielddef *f) {
+ return upb_fielddef_isseq(f) ? 2 : 0;
+}
+
+uint32_t upb_handlers_selectorcount(const upb_fielddef *f) {
+ uint32_t ret = 1;
+ if (upb_fielddef_isseq(f)) ret += 2; /* STARTSEQ/ENDSEQ */
+ if (upb_fielddef_isstring(f)) ret += 2; /* [STRING]/STARTSTR/ENDSTR */
+ if (upb_fielddef_issubmsg(f)) {
+ /* ENDSUBMSG (STARTSUBMSG is at table beginning) */
+ ret += 0;
+ if (upb_fielddef_lazy(f)) {
+ /* STARTSTR/ENDSTR/STRING (for lazy) */
+ ret += 3;
+ }
+ }
+ return ret;
+}
+
+
+/* upb_handlerattr ************************************************************/
+
+void upb_handlerattr_init(upb_handlerattr *attr) {
+ upb_handlerattr from = UPB_HANDLERATTR_INITIALIZER;
+ memcpy(attr, &from, sizeof(*attr));
+}
+
+void upb_handlerattr_uninit(upb_handlerattr *attr) {
+ UPB_UNUSED(attr);
+}
+
+bool upb_handlerattr_sethandlerdata(upb_handlerattr *attr, const void *hd) {
+ attr->handler_data_ = hd;
+ return true;
+}
+
+bool upb_handlerattr_setclosuretype(upb_handlerattr *attr, const void *type) {
+ attr->closure_type_ = type;
+ return true;
+}
+
+const void *upb_handlerattr_closuretype(const upb_handlerattr *attr) {
+ return attr->closure_type_;
+}
+
+bool upb_handlerattr_setreturnclosuretype(upb_handlerattr *attr,
+ const void *type) {
+ attr->return_closure_type_ = type;
+ return true;
+}
+
+const void *upb_handlerattr_returnclosuretype(const upb_handlerattr *attr) {
+ return attr->return_closure_type_;
+}
+
+bool upb_handlerattr_setalwaysok(upb_handlerattr *attr, bool alwaysok) {
+ attr->alwaysok_ = alwaysok;
+ return true;
+}
+
+bool upb_handlerattr_alwaysok(const upb_handlerattr *attr) {
+ return attr->alwaysok_;
+}
+
+/* upb_bufhandle **************************************************************/
+
+size_t upb_bufhandle_objofs(const upb_bufhandle *h) {
+ return h->objofs_;
+}
+
+/* upb_byteshandler ***********************************************************/
+
+void upb_byteshandler_init(upb_byteshandler* h) {
+ memset(h, 0, sizeof(*h));
+}
+
+/* For when we support handlerfree callbacks. */
+void upb_byteshandler_uninit(upb_byteshandler* h) {
+ UPB_UNUSED(h);
+}
+
+bool upb_byteshandler_setstartstr(upb_byteshandler *h,
+ upb_startstr_handlerfunc *func, void *d) {
+ h->table[UPB_STARTSTR_SELECTOR].func = (upb_func*)func;
+ h->table[UPB_STARTSTR_SELECTOR].attr.handler_data_ = d;
+ return true;
+}
+
+bool upb_byteshandler_setstring(upb_byteshandler *h,
+ upb_string_handlerfunc *func, void *d) {
+ h->table[UPB_STRING_SELECTOR].func = (upb_func*)func;
+ h->table[UPB_STRING_SELECTOR].attr.handler_data_ = d;
+ return true;
+}
+
+bool upb_byteshandler_setendstr(upb_byteshandler *h,
+ upb_endfield_handlerfunc *func, void *d) {
+ h->table[UPB_ENDSTR_SELECTOR].func = (upb_func*)func;
+ h->table[UPB_ENDSTR_SELECTOR].attr.handler_data_ = d;
+ return true;
+}
+
+
+static bool is_power_of_two(size_t val) {
+ return (val & (val - 1)) == 0;
+}
+
+/* Align up to the given power of 2. */
+static size_t align_up(size_t val, size_t align) {
+ UPB_ASSERT(is_power_of_two(align));
+ return (val + align - 1) & ~(align - 1);
+}
+
+static size_t div_round_up(size_t n, size_t d) {
+ return (n + d - 1) / d;
+}
+
+bool upb_fieldtype_mapkeyok(upb_fieldtype_t type) {
+ return type == UPB_TYPE_BOOL || type == UPB_TYPE_INT32 ||
+ type == UPB_TYPE_UINT32 || type == UPB_TYPE_INT64 ||
+ type == UPB_TYPE_UINT64 || type == UPB_TYPE_STRING;
+}
+
+void *upb_array_pack(const upb_array *arr, void *p, size_t *ofs, size_t size);
+void *upb_map_pack(const upb_map *map, void *p, size_t *ofs, size_t size);
+
+#define CHARPTR_AT(msg, ofs) ((char*)msg + ofs)
+#define ENCODE_MAX_NESTING 64
+#define CHECK_TRUE(x) if (!(x)) { return false; }
+
+/** upb_msgval ****************************************************************/
+
+#define upb_alignof(t) offsetof(struct { char c; t x; }, x)
+
+/* These functions will generate real memcpy() calls on ARM sadly, because
+ * the compiler assumes they might not be aligned. */
+
+static upb_msgval upb_msgval_read(const void *p, size_t ofs,
+ uint8_t size) {
+ upb_msgval val;
+ p = (char*)p + ofs;
+ memcpy(&val, p, size);
+ return val;
+}
+
+static void upb_msgval_write(void *p, size_t ofs, upb_msgval val,
+ uint8_t size) {
+ p = (char*)p + ofs;
+ memcpy(p, &val, size);
+}
+
+static size_t upb_msgval_sizeof(upb_fieldtype_t type) {
+ switch (type) {
+ case UPB_TYPE_DOUBLE:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT64:
+ return 8;
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_FLOAT:
+ return 4;
+ case UPB_TYPE_BOOL:
+ return 1;
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_MESSAGE:
+ return sizeof(void*);
+ case UPB_TYPE_STRING:
+ return sizeof(char*) + sizeof(size_t);
+ }
+ UPB_UNREACHABLE();
+}
+
+static uint8_t upb_msg_fieldsize(const upb_fielddef *f) {
+ if (upb_fielddef_isseq(f)) {
+ return sizeof(void*);
+ } else {
+ return upb_msgval_sizeof(upb_fielddef_type(f));
+ }
+}
+
+/* TODO(haberman): this is broken right now because upb_msgval can contain
+ * a char* / size_t pair, which is too big for a upb_value. To fix this
+ * we'll probably need to dynamically allocate a upb_msgval and store a
+ * pointer to that in the tables for extensions/maps. */
+static upb_value upb_toval(upb_msgval val) {
+ upb_value ret;
+ UPB_UNUSED(val);
+ memset(&ret, 0, sizeof(upb_value)); /* XXX */
+ return ret;
+}
+
+static upb_msgval upb_msgval_fromval(upb_value val) {
+ upb_msgval ret;
+ UPB_UNUSED(val);
+ memset(&ret, 0, sizeof(upb_msgval)); /* XXX */
+ return ret;
+}
+
+static upb_ctype_t upb_fieldtotabtype(upb_fieldtype_t type) {
+ switch (type) {
+ case UPB_TYPE_FLOAT: return UPB_CTYPE_FLOAT;
+ case UPB_TYPE_DOUBLE: return UPB_CTYPE_DOUBLE;
+ case UPB_TYPE_BOOL: return UPB_CTYPE_BOOL;
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_MESSAGE:
+ case UPB_TYPE_STRING: return UPB_CTYPE_CONSTPTR;
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32: return UPB_CTYPE_INT32;
+ case UPB_TYPE_UINT32: return UPB_CTYPE_UINT32;
+ case UPB_TYPE_INT64: return UPB_CTYPE_INT64;
+ case UPB_TYPE_UINT64: return UPB_CTYPE_UINT64;
+ default: UPB_ASSERT(false); return 0;
+ }
+}
+
+static upb_msgval upb_msgval_fromdefault(const upb_fielddef *f) {
+ /* TODO(haberman): improve/optimize this (maybe use upb_msgval in fielddef) */
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_FLOAT:
+ return upb_msgval_float(upb_fielddef_defaultfloat(f));
+ case UPB_TYPE_DOUBLE:
+ return upb_msgval_double(upb_fielddef_defaultdouble(f));
+ case UPB_TYPE_BOOL:
+ return upb_msgval_bool(upb_fielddef_defaultbool(f));
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ size_t len;
+ const char *ptr = upb_fielddef_defaultstr(f, &len);
+ return upb_msgval_str(ptr, len);
+ }
+ case UPB_TYPE_MESSAGE:
+ return upb_msgval_msg(NULL);
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32:
+ return upb_msgval_int32(upb_fielddef_defaultint32(f));
+ case UPB_TYPE_UINT32:
+ return upb_msgval_uint32(upb_fielddef_defaultuint32(f));
+ case UPB_TYPE_INT64:
+ return upb_msgval_int64(upb_fielddef_defaultint64(f));
+ case UPB_TYPE_UINT64:
+ return upb_msgval_uint64(upb_fielddef_defaultuint64(f));
+ default:
+ UPB_ASSERT(false);
+ return upb_msgval_msg(NULL);
+ }
+}
+
+
+/** upb_msglayout *************************************************************/
+
+struct upb_msglayout {
+ upb_msgfactory *factory;
+ const upb_msgdef *msgdef;
+ size_t size;
+ size_t extdict_offset;
+ void *default_msg;
+ uint32_t *field_offsets;
+ uint32_t *case_offsets;
+ uint32_t *hasbits;
+ bool has_extdict;
+ uint8_t align;
+};
+
+static void upb_msg_checkfield(const upb_msglayout *l, const upb_fielddef *f) {
+ UPB_ASSERT(l->msgdef == upb_fielddef_containingtype(f));
+}
+
+static void upb_msglayout_free(upb_msglayout *l) {
+ upb_gfree(l->default_msg);
+ upb_gfree(l);
+}
+
+const upb_msgdef *upb_msglayout_msgdef(const upb_msglayout *l) {
+ return l->msgdef;
+}
+
+static size_t upb_msglayout_place(upb_msglayout *l, size_t size) {
+ size_t ret;
+
+ l->size = align_up(l->size, size);
+ l->align = align_up(l->align, size);
+ ret = l->size;
+ l->size += size;
+ return ret;
+}
+
+static uint32_t upb_msglayout_offset(const upb_msglayout *l,
+ const upb_fielddef *f) {
+ return l->field_offsets[upb_fielddef_index(f)];
+}
+
+static uint32_t upb_msglayout_hasbit(const upb_msglayout *l,
+ const upb_fielddef *f) {
+ return l->hasbits[upb_fielddef_index(f)];
+}
+
+static bool upb_msglayout_initdefault(upb_msglayout *l) {
+ const upb_msgdef *m = l->msgdef;
+ upb_msg_field_iter it;
+
+ if (upb_msgdef_syntax(m) == UPB_SYNTAX_PROTO2 && l->size) {
+ /* Allocate default message and set default values in it. */
+ l->default_msg = upb_gmalloc(l->size);
+ if (!l->default_msg) {
+ return false;
+ }
+
+ memset(l->default_msg, 0, l->size);
+
+ for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* f = upb_msg_iter_field(&it);
+
+ if (upb_fielddef_containingoneof(f)) {
+ continue;
+ }
+
+ if (!upb_fielddef_isstring(f) &&
+ !upb_fielddef_issubmsg(f) &&
+ !upb_fielddef_isseq(f)) {
+ upb_msg_set(l->default_msg, f, upb_msgval_fromdefault(f), l);
+ }
+ }
+ }
+
+ return true;
+}
+
+static upb_msglayout *upb_msglayout_new(const upb_msgdef *m) {
+ upb_msg_field_iter it;
+ upb_msg_oneof_iter oit;
+ upb_msglayout *l;
+ size_t hasbit;
+ size_t array_size = upb_msgdef_numfields(m) + upb_msgdef_numoneofs(m);
+
+ if (upb_msgdef_syntax(m) == UPB_SYNTAX_PROTO2) {
+ array_size += upb_msgdef_numfields(m); /* hasbits. */
+ }
+
+ l = upb_gmalloc(sizeof(*l) + (sizeof(uint32_t) * array_size));
+ if (!l) return NULL;
+
+ memset(l, 0, sizeof(*l));
+
+ l->msgdef = m;
+ l->align = 1;
+ l->field_offsets = (uint32_t*)CHARPTR_AT(l, sizeof(*l));
+ l->case_offsets = l->field_offsets + upb_msgdef_numfields(m);
+ l->hasbits = l->case_offsets + upb_msgdef_numoneofs(m);
+
+ /* Allocate data offsets in three stages:
+ *
+ * 1. hasbits.
+ * 2. regular fields.
+ * 3. oneof fields.
+ *
+ * OPT: There is a lot of room for optimization here to minimize the size.
+ */
+
+ /* Allocate hasbits. Start at sizeof(void*) for upb_alloc*. */
+ for (upb_msg_field_begin(&it, m), hasbit = sizeof(void*) * 8;
+ !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* f = upb_msg_iter_field(&it);
+
+ if (upb_fielddef_haspresence(f) && !upb_fielddef_containingoneof(f)) {
+ l->hasbits[upb_fielddef_index(f)] = hasbit++;
+ }
+ }
+
+ /* Account for space used by hasbits. */
+ l->size = div_round_up(hasbit, 8);
+
+ /* Allocate non-oneof fields. */
+ for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* f = upb_msg_iter_field(&it);
+ size_t field_size = upb_msg_fieldsize(f);
+ size_t index = upb_fielddef_index(f);
+
+
+ if (upb_fielddef_containingoneof(f)) {
+ /* Oneofs are handled separately below. */
+ continue;
+ }
+
+ l->field_offsets[index] = upb_msglayout_place(l, field_size);
+ }
+
+ /* Allocate oneof fields. Each oneof field consists of a uint32 for the case
+ * and space for the actual data. */
+ for (upb_msg_oneof_begin(&oit, m); !upb_msg_oneof_done(&oit);
+ upb_msg_oneof_next(&oit)) {
+ const upb_oneofdef* oneof = upb_msg_iter_oneof(&oit);
+ upb_oneof_iter fit;
+ size_t case_size = sizeof(uint32_t); /* Could potentially optimize this. */
+ size_t field_size = 0;
+ size_t case_offset;
+ size_t val_offset;
+
+ /* Calculate field size: the max of all field sizes. */
+ for (upb_oneof_begin(&fit, oneof);
+ !upb_oneof_done(&fit);
+ upb_oneof_next(&fit)) {
+ const upb_fielddef* f = upb_oneof_iter_field(&fit);
+ field_size = UPB_MAX(field_size, upb_msg_fieldsize(f));
+ }
+
+ /* Align and allocate case offset. */
+ case_offset = upb_msglayout_place(l, case_size);
+ val_offset = upb_msglayout_place(l, field_size);
+
+ l->case_offsets[upb_oneofdef_index(oneof)] = case_offset;
+
+ /* Assign all fields in the oneof this same offset. */
+ for (upb_oneof_begin(&fit, oneof); !upb_oneof_done(&fit);
+ upb_oneof_next(&fit)) {
+ const upb_fielddef* f = upb_oneof_iter_field(&fit);
+ l->field_offsets[upb_fielddef_index(f)] = val_offset;
+ }
+ }
+
+ /* Size of the entire structure should be a multiple of its greatest
+ * alignment. */
+ l->size = align_up(l->size, l->align);
+
+ if (upb_msglayout_initdefault(l)) {
+ return l;
+ } else {
+ upb_msglayout_free(l);
+ return NULL;
+ }
+}
+
+upb_msgfactory *upb_msglayout_factory(const upb_msglayout *layout) {
+ return layout->factory;
+}
+
+
+/** upb_msgfactory ************************************************************/
+
+struct upb_msgfactory {
+ const upb_symtab *symtab; /* We own a ref. */
+ upb_inttable layouts;
+ upb_inttable mergehandlers;
+};
+
+upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab) {
+ upb_msgfactory *ret = upb_gmalloc(sizeof(*ret));
+
+ ret->symtab = symtab;
+ upb_inttable_init(&ret->layouts, UPB_CTYPE_PTR);
+ upb_inttable_init(&ret->mergehandlers, UPB_CTYPE_CONSTPTR);
+
+ return ret;
+}
+
+void upb_msgfactory_free(upb_msgfactory *f) {
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, &f->layouts);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ upb_msglayout *l = upb_value_getptr(upb_inttable_iter_value(&i));
+ upb_msglayout_free(l);
+ }
+
+ upb_inttable_begin(&i, &f->mergehandlers);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ const upb_handlers *h = upb_value_getconstptr(upb_inttable_iter_value(&i));
+ upb_handlers_unref(h, f);
+ }
+
+ upb_inttable_uninit(&f->layouts);
+ upb_inttable_uninit(&f->mergehandlers);
+ upb_gfree(f);
+}
+
+const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f) {
+ return f->symtab;
+}
+
+const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f,
+ const upb_msgdef *m) {
+ upb_value v;
+ UPB_ASSERT(upb_symtab_lookupmsg(f->symtab, upb_msgdef_fullname(m)) == m);
+ UPB_ASSERT(!upb_msgdef_mapentry(m));
+
+ if (upb_inttable_lookupptr(&f->layouts, m, &v)) {
+ UPB_ASSERT(upb_value_getptr(v));
+ return upb_value_getptr(v);
+ } else {
+ upb_msgfactory *mutable_f = (void*)f;
+ upb_msglayout *l = upb_msglayout_new(m);
+ upb_inttable_insertptr(&mutable_f->layouts, m, upb_value_ptr(l));
+ UPB_ASSERT(l);
+ l->factory = f;
+ return l;
+ }
+}
+
+/* Our handlers that we don't expose externally. */
+
+void *upb_msg_startstr(void *msg, const void *hd, size_t size_hint) {
+ uint32_t ofs = (uintptr_t)hd;
+ /* We pass NULL here because we know we can get away with it. */
+ upb_alloc *alloc = upb_msg_alloc(msg, NULL);
+ upb_msgval val;
+ UPB_UNUSED(size_hint);
+
+ val = upb_msgval_read(msg, ofs, upb_msgval_sizeof(UPB_TYPE_STRING));
+
+ upb_free(alloc, (void*)val.str.ptr);
+ val.str.ptr = NULL;
+ val.str.len = 0;
+
+ upb_msgval_write(msg, ofs, val, upb_msgval_sizeof(UPB_TYPE_STRING));
+ return msg;
+}
+
+size_t upb_msg_str(void *msg, const void *hd, const char *ptr, size_t size,
+ const upb_bufhandle *handle) {
+ uint32_t ofs = (uintptr_t)hd;
+ /* We pass NULL here because we know we can get away with it. */
+ upb_alloc *alloc = upb_msg_alloc(msg, NULL);
+ upb_msgval val;
+ size_t newsize;
+ UPB_UNUSED(handle);
+
+ val = upb_msgval_read(msg, ofs, upb_msgval_sizeof(UPB_TYPE_STRING));
+
+ newsize = val.str.len + size;
+ val.str.ptr = upb_realloc(alloc, (void*)val.str.ptr, val.str.len, newsize);
+
+ if (!val.str.ptr) {
+ return false;
+ }
+
+ memcpy((char*)val.str.ptr + val.str.len, ptr, size);
+ val.str.len = newsize;
+ upb_msgval_write(msg, ofs, val, upb_msgval_sizeof(UPB_TYPE_STRING));
+ return size;
+}
+
+static void callback(const void *closure, upb_handlers *h) {
+ upb_msgfactory *factory = (upb_msgfactory*)closure;
+ const upb_msgdef *md = upb_handlers_msgdef(h);
+ const upb_msglayout* layout = upb_msgfactory_getlayout(factory, md);
+ upb_msg_field_iter i;
+ UPB_UNUSED(factory);
+
+ for(upb_msg_field_begin(&i, md);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ const upb_fielddef *f = upb_msg_iter_field(&i);
+ size_t offset = upb_msglayout_offset(layout, f);
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_handlerattr_sethandlerdata(&attr, (void*)offset);
+
+ if (upb_fielddef_isseq(f)) {
+ } else if (upb_fielddef_isstring(f)) {
+ upb_handlers_setstartstr(h, f, upb_msg_startstr, &attr);
+ upb_handlers_setstring(h, f, upb_msg_str, &attr);
+ } else {
+ upb_msg_setscalarhandler(
+ h, f, offset, upb_msglayout_hasbit(layout, f));
+ }
+ }
+}
+
+const upb_handlers *upb_msgfactory_getmergehandlers(upb_msgfactory *f,
+ const upb_msgdef *m) {
+ upb_msgfactory *mutable_f = (void*)f;
+
+ /* TODO(haberman): properly cache these. */
+ const upb_handlers *ret = upb_handlers_newfrozen(m, f, callback, f);
+ upb_inttable_push(&mutable_f->mergehandlers, upb_value_constptr(ret));
+
+ return ret;
+}
+
+const upb_visitorplan *upb_msgfactory_getvisitorplan(upb_msgfactory *f,
+ const upb_handlers *h) {
+ const upb_msgdef *md = upb_handlers_msgdef(h);
+ return (const upb_visitorplan*)upb_msgfactory_getlayout(f, md);
+}
+
+
+/** upb_visitor ***************************************************************/
+
+struct upb_visitor {
+ const upb_msglayout *layout;
+ upb_sink *sink;
+};
+
+static upb_selector_t getsel2(const upb_fielddef *f, upb_handlertype_t type) {
+ upb_selector_t ret;
+ bool ok = upb_handlers_getselector(f, type, &ret);
+ UPB_ASSERT(ok);
+ return ret;
+}
+
+static bool upb_visitor_hasfield(const upb_msg *msg, const upb_fielddef *f,
+ const upb_msglayout *layout) {
+ if (upb_fielddef_isseq(f)) {
+ return upb_msgval_getarr(upb_msg_get(msg, f, layout)) != NULL;
+ } else if (upb_msgdef_syntax(upb_fielddef_containingtype(f)) ==
+ UPB_SYNTAX_PROTO2) {
+ return upb_msg_has(msg, f, layout);
+ } else {
+ upb_msgval val = upb_msg_get(msg, f, layout);
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_FLOAT:
+ return upb_msgval_getfloat(val) != 0;
+ case UPB_TYPE_DOUBLE:
+ return upb_msgval_getdouble(val) != 0;
+ case UPB_TYPE_BOOL:
+ return upb_msgval_getbool(val);
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32:
+ return upb_msgval_getint32(val) != 0;
+ case UPB_TYPE_UINT32:
+ return upb_msgval_getuint32(val) != 0;
+ case UPB_TYPE_INT64:
+ return upb_msgval_getint64(val) != 0;
+ case UPB_TYPE_UINT64:
+ return upb_msgval_getuint64(val) != 0;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ return upb_msgval_getstr(val) && upb_msgval_getstrlen(val) > 0;
+ case UPB_TYPE_MESSAGE:
+ return upb_msgval_getmsg(val) != NULL;
+ }
+ UPB_UNREACHABLE();
+ }
+}
+
+static bool upb_visitor_visitmsg2(const upb_msg *msg,
+ const upb_msglayout *layout, upb_sink *sink,
+ int depth) {
+ const upb_msgdef *md = upb_msglayout_msgdef(layout);
+ upb_msg_field_iter i;
+ upb_status status;
+
+ upb_sink_startmsg(sink);
+
+ /* Protect against cycles (possible because users may freely reassign message
+ * and repeated fields) by imposing a maximum recursion depth. */
+ if (depth > ENCODE_MAX_NESTING) {
+ return false;
+ }
+
+ for (upb_msg_field_begin(&i, md);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ upb_fielddef *f = upb_msg_iter_field(&i);
+ upb_msgval val;
+
+ if (!upb_visitor_hasfield(msg, f, layout)) {
+ continue;
+ }
+
+ val = upb_msg_get(msg, f, layout);
+
+ if (upb_fielddef_isseq(f)) {
+ const upb_array *arr = upb_msgval_getarr(val);
+ UPB_ASSERT(arr);
+ /* TODO: putary(ary, f, sink, depth);*/
+ } else if (upb_fielddef_issubmsg(f)) {
+ const upb_map *map = upb_msgval_getmap(val);
+ UPB_ASSERT(map);
+ /* TODO: putmap(map, f, sink, depth);*/
+ } else if (upb_fielddef_isstring(f)) {
+ /* TODO putstr(); */
+ } else {
+ upb_selector_t sel = getsel2(f, upb_handlers_getprimitivehandlertype(f));
+ UPB_ASSERT(upb_fielddef_isprimitive(f));
+
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_FLOAT:
+ CHECK_TRUE(upb_sink_putfloat(sink, sel, upb_msgval_getfloat(val)));
+ break;
+ case UPB_TYPE_DOUBLE:
+ CHECK_TRUE(upb_sink_putdouble(sink, sel, upb_msgval_getdouble(val)));
+ break;
+ case UPB_TYPE_BOOL:
+ CHECK_TRUE(upb_sink_putbool(sink, sel, upb_msgval_getbool(val)));
+ break;
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32:
+ CHECK_TRUE(upb_sink_putint32(sink, sel, upb_msgval_getint32(val)));
+ break;
+ case UPB_TYPE_UINT32:
+ CHECK_TRUE(upb_sink_putuint32(sink, sel, upb_msgval_getuint32(val)));
+ break;
+ case UPB_TYPE_INT64:
+ CHECK_TRUE(upb_sink_putint64(sink, sel, upb_msgval_getint64(val)));
+ break;
+ case UPB_TYPE_UINT64:
+ CHECK_TRUE(upb_sink_putuint64(sink, sel, upb_msgval_getuint64(val)));
+ break;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_MESSAGE:
+ UPB_UNREACHABLE();
+ }
+ }
+ }
+
+ upb_sink_endmsg(sink, &status);
+ return true;
+}
+
+upb_visitor *upb_visitor_create(upb_env *e, const upb_visitorplan *vp,
+ upb_sink *output) {
+ upb_visitor *visitor = upb_env_malloc(e, sizeof(*visitor));
+ visitor->layout = (const upb_msglayout*)vp;
+ visitor->sink = output;
+ return visitor;
+}
+
+bool upb_visitor_visitmsg(upb_visitor *visitor, const upb_msg *msg) {
+ return upb_visitor_visitmsg2(msg, visitor->layout, visitor->sink, 0);
+}
+
+
+/** upb_msg *******************************************************************/
+
+/* If we always read/write as a consistent type to each address, this shouldn't
+ * violate aliasing.
+ */
+#define DEREF(msg, ofs, type) *(type*)CHARPTR_AT(msg, ofs)
+
+static upb_inttable *upb_msg_trygetextdict(const upb_msg *msg,
+ const upb_msglayout *l) {
+ return l->has_extdict ? DEREF(msg, l->extdict_offset, upb_inttable*) : NULL;
+}
+
+static upb_inttable *upb_msg_getextdict(upb_msg *msg,
+ const upb_msglayout *l,
+ upb_alloc *a) {
+ upb_inttable *ext_dict;
+ UPB_ASSERT(l->has_extdict);
+
+ ext_dict = upb_msg_trygetextdict(msg, l);
+
+ if (!ext_dict) {
+ ext_dict = upb_malloc(a, sizeof(upb_inttable));
+
+ if (!ext_dict) {
+ return NULL;
+ }
+
+ /* Use an 8-byte type to ensure all bytes are copied. */
+ if (!upb_inttable_init2(ext_dict, UPB_CTYPE_INT64, a)) {
+ upb_free(a, ext_dict);
+ return NULL;
+ }
+
+ DEREF(msg, l->extdict_offset, upb_inttable*) = ext_dict;
+ }
+
+ return ext_dict;
+}
+
+static uint32_t upb_msg_getoneofint(const upb_msg *msg,
+ const upb_oneofdef *o,
+ const upb_msglayout *l) {
+ size_t oneof_ofs = l->case_offsets[upb_oneofdef_index(o)];
+ return DEREF(msg, oneof_ofs, uint8_t);
+}
+
+static void upb_msg_setoneofcase(const upb_msg *msg,
+ const upb_oneofdef *o,
+ const upb_msglayout *l,
+ uint32_t val) {
+ size_t oneof_ofs = l->case_offsets[upb_oneofdef_index(o)];
+ DEREF(msg, oneof_ofs, uint8_t) = val;
+}
+
+
+static bool upb_msg_oneofis(const upb_msg *msg, const upb_msglayout *l,
+ const upb_oneofdef *o, const upb_fielddef *f) {
+ return upb_msg_getoneofint(msg, o, l) == upb_fielddef_number(f);
+}
+
+size_t upb_msg_sizeof(const upb_msglayout *l) { return l->size; }
+
+void upb_msg_init(upb_msg *msg, const upb_msglayout *l, upb_alloc *a) {
+ if (l->default_msg) {
+ memcpy(msg, l->default_msg, l->size);
+ } else {
+ memset(msg, 0, l->size);
+ }
+
+ /* Set arena pointer. */
+ memcpy(msg, &a, sizeof(a));
+}
+
+void upb_msg_uninit(upb_msg *msg, const upb_msglayout *l) {
+ upb_inttable *ext_dict = upb_msg_trygetextdict(msg, l);
+ if (ext_dict) {
+ upb_inttable_uninit2(ext_dict, upb_msg_alloc(msg, l));
+ }
+}
+
+upb_msg *upb_msg_new(const upb_msglayout *l, upb_alloc *a) {
+ upb_msg *msg = upb_malloc(a, upb_msg_sizeof(l));
+
+ if (msg) {
+ upb_msg_init(msg, l, a);
+ }
+
+ return msg;
+}
+
+void upb_msg_free(upb_msg *msg, const upb_msglayout *l) {
+ upb_msg_uninit(msg, l);
+ upb_free(upb_msg_alloc(msg, l), msg);
+}
+
+upb_alloc *upb_msg_alloc(const upb_msg *msg, const upb_msglayout *l) {
+ upb_alloc *alloc;
+ UPB_UNUSED(l);
+ memcpy(&alloc, msg, sizeof(alloc));
+ return alloc;
+}
+
+bool upb_msg_has(const upb_msg *msg,
+ const upb_fielddef *f,
+ const upb_msglayout *l) {
+ const upb_oneofdef *o;
+ upb_msg_checkfield(l, f);
+ UPB_ASSERT(upb_fielddef_haspresence(f));
+
+ if (upb_fielddef_isextension(f)) {
+ /* Extensions are set when they are present in the extension dict. */
+ upb_inttable *ext_dict = upb_msg_trygetextdict(msg, l);
+ upb_value v;
+ return ext_dict != NULL &&
+ upb_inttable_lookup32(ext_dict, upb_fielddef_number(f), &v);
+ } else if ((o = upb_fielddef_containingoneof(f)) != NULL) {
+ /* Oneofs are set when the oneof number is set to this field. */
+ return upb_msg_getoneofint(msg, o, l) == upb_fielddef_number(f);
+ } else {
+ /* Other fields are set when their hasbit is set. */
+ uint32_t hasbit = l->hasbits[upb_fielddef_index(f)];
+ return DEREF(msg, hasbit / 8, char) | (1 << (hasbit % 8));
+ }
+}
+
+upb_msgval upb_msg_get(const upb_msg *msg, const upb_fielddef *f,
+ const upb_msglayout *l) {
+ upb_msg_checkfield(l, f);
+
+ if (upb_fielddef_isextension(f)) {
+ upb_inttable *ext_dict = upb_msg_trygetextdict(msg, l);
+ upb_value val;
+ if (upb_inttable_lookup32(ext_dict, upb_fielddef_number(f), &val)) {
+ return upb_msgval_fromval(val);
+ } else {
+ return upb_msgval_fromdefault(f);
+ }
+ } else {
+ size_t ofs = l->field_offsets[upb_fielddef_index(f)];
+ const upb_oneofdef *o = upb_fielddef_containingoneof(f);
+ upb_msgval ret;
+
+ if (o && !upb_msg_oneofis(msg, l, o, f)) {
+ /* Oneof defaults can't come from the message because the memory is reused
+ * by all types in the oneof. */
+ return upb_msgval_fromdefault(f);
+ }
+
+ ret = upb_msgval_read(msg, ofs, upb_msg_fieldsize(f));
+ return ret;
+ }
+}
+
+bool upb_msg_set(upb_msg *msg,
+ const upb_fielddef *f,
+ upb_msgval val,
+ const upb_msglayout *l) {
+ upb_alloc *a = upb_msg_alloc(msg, l);
+ upb_msg_checkfield(l, f);
+
+ if (upb_fielddef_isextension(f)) {
+ /* TODO(haberman): introduce table API that can do this in one call. */
+ upb_inttable *ext = upb_msg_getextdict(msg, l, a);
+ upb_value val2 = upb_toval(val);
+ if (!upb_inttable_replace(ext, upb_fielddef_number(f), val2) &&
+ !upb_inttable_insert2(ext, upb_fielddef_number(f), val2, a)) {
+ return false;
+ }
+ } else {
+ size_t ofs = l->field_offsets[upb_fielddef_index(f)];
+ const upb_oneofdef *o = upb_fielddef_containingoneof(f);
+
+ if (o) {
+ upb_msg_setoneofcase(msg, o, l, upb_fielddef_number(f));
+ }
+
+ upb_msgval_write(msg, ofs, val, upb_msg_fieldsize(f));
+ }
+ return true;
+}
+
+
+/** upb_array *****************************************************************/
+
+struct upb_array {
+ upb_fieldtype_t type;
+ uint8_t element_size;
+ void *data; /* Each element is element_size. */
+ size_t len; /* Measured in elements. */
+ size_t size; /* Measured in elements. */
+ upb_alloc *alloc;
+};
+
+#define DEREF_ARR(arr, i, type) ((type*)arr->data)[i]
+
+size_t upb_array_sizeof(upb_fieldtype_t type) {
+ UPB_UNUSED(type);
+ return sizeof(upb_array);
+}
+
+void upb_array_init(upb_array *arr, upb_fieldtype_t type, upb_alloc *alloc) {
+ arr->type = type;
+ arr->data = NULL;
+ arr->len = 0;
+ arr->size = 0;
+ arr->element_size = upb_msgval_sizeof(type);
+ arr->alloc = alloc;
+}
+
+void upb_array_uninit(upb_array *arr) {
+ upb_free(arr->alloc, arr->data);
+}
+
+upb_array *upb_array_new(upb_fieldtype_t type, upb_alloc *a) {
+ upb_array *ret = upb_malloc(a, upb_array_sizeof(type));
+
+ if (ret) {
+ upb_array_init(ret, type, a);
+ }
+
+ return ret;
+}
+
+void upb_array_free(upb_array *arr) {
+ upb_array_uninit(arr);
+ upb_free(arr->alloc, arr);
+}
+
+size_t upb_array_size(const upb_array *arr) {
+ return arr->len;
+}
+
+upb_fieldtype_t upb_array_type(const upb_array *arr) {
+ return arr->type;
+}
+
+upb_msgval upb_array_get(const upb_array *arr, size_t i) {
+ UPB_ASSERT(i < arr->len);
+ return upb_msgval_read(arr->data, i * arr->element_size, arr->element_size);
+}
+
+bool upb_array_set(upb_array *arr, size_t i, upb_msgval val) {
+ UPB_ASSERT(i <= arr->len);
+
+ if (i == arr->len) {
+ /* Extending the array. */
+
+ if (i == arr->size) {
+ /* Need to reallocate. */
+ size_t new_size = UPB_MAX(arr->size * 2, 8);
+ size_t new_bytes = new_size * arr->element_size;
+ size_t old_bytes = arr->size * arr->element_size;
+ upb_msgval *new_data =
+ upb_realloc(arr->alloc, arr->data, old_bytes, new_bytes);
+
+ if (!new_data) {
+ return false;
+ }
+
+ arr->data = new_data;
+ arr->size = new_size;
+ }
+
+ arr->len = i + 1;
+ }
+
+ upb_msgval_write(arr->data, i * arr->element_size, val, arr->element_size);
+ return true;
+}
+
+
+/** upb_map *******************************************************************/
+
+struct upb_map {
+ upb_fieldtype_t key_type;
+ upb_fieldtype_t val_type;
+ /* We may want to optimize this to use inttable where possible, for greater
+ * efficiency and lower memory footprint. */
+ upb_strtable strtab;
+ upb_alloc *alloc;
+};
+
+static void upb_map_tokey(upb_fieldtype_t type, upb_msgval *key,
+ const char **out_key, size_t *out_len) {
+ switch (type) {
+ case UPB_TYPE_STRING:
+ /* Point to string data of the input key. */
+ *out_key = key->str.ptr;
+ *out_len = key->str.len;
+ return;
+ case UPB_TYPE_BOOL:
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT64:
+ /* Point to the key itself. XXX: big-endian. */
+ *out_key = (const char*)key;
+ *out_len = upb_msgval_sizeof(type);
+ return;
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_DOUBLE:
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_FLOAT:
+ case UPB_TYPE_MESSAGE:
+ break; /* Cannot be a map key. */
+ }
+ UPB_UNREACHABLE();
+}
+
+static upb_msgval upb_map_fromkey(upb_fieldtype_t type, const char *key,
+ size_t len) {
+ switch (type) {
+ case UPB_TYPE_STRING:
+ return upb_msgval_str(key, len);
+ case UPB_TYPE_BOOL:
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT64:
+ return upb_msgval_read(key, 0, upb_msgval_sizeof(type));
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_DOUBLE:
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_FLOAT:
+ case UPB_TYPE_MESSAGE:
+ break; /* Cannot be a map key. */
+ }
+ UPB_UNREACHABLE();
+}
+
+size_t upb_map_sizeof(upb_fieldtype_t ktype, upb_fieldtype_t vtype) {
+ /* Size does not currently depend on key/value type. */
+ UPB_UNUSED(ktype);
+ UPB_UNUSED(vtype);
+ return sizeof(upb_map);
+}
+
+bool upb_map_init(upb_map *map, upb_fieldtype_t ktype, upb_fieldtype_t vtype,
+ upb_alloc *a) {
+ upb_ctype_t vtabtype = upb_fieldtotabtype(vtype);
+ UPB_ASSERT(upb_fieldtype_mapkeyok(ktype));
+ map->key_type = ktype;
+ map->val_type = vtype;
+ map->alloc = a;
+
+ if (!upb_strtable_init2(&map->strtab, vtabtype, a)) {
+ return false;
+ }
+
+ return true;
+}
+
+void upb_map_uninit(upb_map *map) {
+ upb_strtable_uninit2(&map->strtab, map->alloc);
+}
+
+upb_map *upb_map_new(upb_fieldtype_t ktype, upb_fieldtype_t vtype,
+ upb_alloc *a) {
+ upb_map *map = upb_malloc(a, upb_map_sizeof(ktype, vtype));
+
+ if (!map) {
+ return NULL;
+ }
+
+ if (!upb_map_init(map, ktype, vtype, a)) {
+ return NULL;
+ }
+
+ return map;
+}
+
+void upb_map_free(upb_map *map) {
+ upb_map_uninit(map);
+ upb_free(map->alloc, map);
+}
+
+size_t upb_map_size(const upb_map *map) {
+ return upb_strtable_count(&map->strtab);
+}
+
+upb_fieldtype_t upb_map_keytype(const upb_map *map) {
+ return map->key_type;
+}
+
+upb_fieldtype_t upb_map_valuetype(const upb_map *map) {
+ return map->val_type;
+}
+
+bool upb_map_get(const upb_map *map, upb_msgval key, upb_msgval *val) {
+ upb_value tabval;
+ const char *key_str;
+ size_t key_len;
+ bool ret;
+
+ upb_map_tokey(map->key_type, &key, &key_str, &key_len);
+ ret = upb_strtable_lookup2(&map->strtab, key_str, key_len, &tabval);
+ if (ret) {
+ memcpy(val, &tabval, sizeof(tabval));
+ }
+
+ return ret;
+}
+
+bool upb_map_set(upb_map *map, upb_msgval key, upb_msgval val,
+ upb_msgval *removed) {
+ const char *key_str;
+ size_t key_len;
+ upb_value tabval = upb_toval(val);
+ upb_value removedtabval;
+ upb_alloc *a = map->alloc;
+
+ upb_map_tokey(map->key_type, &key, &key_str, &key_len);
+
+ /* TODO(haberman): add overwrite operation to minimize number of lookups. */
+ if (upb_strtable_lookup2(&map->strtab, key_str, key_len, NULL)) {
+ upb_strtable_remove3(&map->strtab, key_str, key_len, &removedtabval, a);
+ memcpy(&removed, &removedtabval, sizeof(removed));
+ }
+
+ return upb_strtable_insert3(&map->strtab, key_str, key_len, tabval, a);
+}
+
+bool upb_map_del(upb_map *map, upb_msgval key) {
+ const char *key_str;
+ size_t key_len;
+ upb_alloc *a = map->alloc;
+
+ upb_map_tokey(map->key_type, &key, &key_str, &key_len);
+ return upb_strtable_remove3(&map->strtab, key_str, key_len, NULL, a);
+}
+
+
+/** upb_mapiter ***************************************************************/
+
+struct upb_mapiter {
+ upb_strtable_iter iter;
+ upb_fieldtype_t key_type;
+};
+
+size_t upb_mapiter_sizeof() {
+ return sizeof(upb_mapiter);
+}
+
+void upb_mapiter_begin(upb_mapiter *i, const upb_map *map) {
+ upb_strtable_begin(&i->iter, &map->strtab);
+ i->key_type = map->key_type;
+}
+
+upb_mapiter *upb_mapiter_new(const upb_map *t, upb_alloc *a) {
+ upb_mapiter *ret = upb_malloc(a, upb_mapiter_sizeof());
+
+ if (!ret) {
+ return NULL;
+ }
+
+ upb_mapiter_begin(ret, t);
+ return ret;
+}
+
+void upb_mapiter_free(upb_mapiter *i, upb_alloc *a) {
+ upb_free(a, i);
+}
+
+void upb_mapiter_next(upb_mapiter *i) {
+ upb_strtable_next(&i->iter);
+}
+
+bool upb_mapiter_done(const upb_mapiter *i) {
+ return upb_strtable_done(&i->iter);
+}
+
+upb_msgval upb_mapiter_key(const upb_mapiter *i) {
+ return upb_map_fromkey(i->key_type, upb_strtable_iter_key(&i->iter),
+ upb_strtable_iter_keylength(&i->iter));
+}
+
+upb_msgval upb_mapiter_value(const upb_mapiter *i) {
+ return upb_msgval_fromval(upb_strtable_iter_value(&i->iter));
+}
+
+void upb_mapiter_setdone(upb_mapiter *i) {
+ upb_strtable_iter_setdone(&i->iter);
+}
+
+bool upb_mapiter_isequal(const upb_mapiter *i1, const upb_mapiter *i2) {
+ return upb_strtable_iter_isequal(&i1->iter, &i2->iter);
+}
+
+
+/** Handlers for upb_msg ******************************************************/
+
+typedef struct {
+ size_t offset;
+ int32_t hasbit;
+} upb_msg_handlerdata;
+
+/* Fallback implementation if the handler is not specialized by the producer. */
+#define MSG_WRITER(type, ctype) \
+ bool upb_msg_set ## type (void *c, const void *hd, ctype val) { \
+ uint8_t *m = c; \
+ const upb_msg_handlerdata *d = hd; \
+ if (d->hasbit > 0) \
+ *(uint8_t*)&m[d->hasbit / 8] |= 1 << (d->hasbit % 8); \
+ *(ctype*)&m[d->offset] = val; \
+ return true; \
+ } \
+
+MSG_WRITER(double, double)
+MSG_WRITER(float, float)
+MSG_WRITER(int32, int32_t)
+MSG_WRITER(int64, int64_t)
+MSG_WRITER(uint32, uint32_t)
+MSG_WRITER(uint64, uint64_t)
+MSG_WRITER(bool, bool)
+
+bool upb_msg_setscalarhandler(upb_handlers *h, const upb_fielddef *f,
+ size_t offset, int32_t hasbit) {
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ bool ok;
+
+ upb_msg_handlerdata *d = upb_gmalloc(sizeof(*d));
+ if (!d) return false;
+ d->offset = offset;
+ d->hasbit = hasbit;
+
+ upb_handlerattr_sethandlerdata(&attr, d);
+ upb_handlerattr_setalwaysok(&attr, true);
+ upb_handlers_addcleanup(h, d, upb_gfree);
+
+#define TYPE(u, l) \
+ case UPB_TYPE_##u: \
+ ok = upb_handlers_set##l(h, f, upb_msg_set##l, &attr); break;
+
+ ok = false;
+
+ switch (upb_fielddef_type(f)) {
+ TYPE(INT64, int64);
+ TYPE(INT32, int32);
+ TYPE(ENUM, int32);
+ TYPE(UINT64, uint64);
+ TYPE(UINT32, uint32);
+ TYPE(DOUBLE, double);
+ TYPE(FLOAT, float);
+ TYPE(BOOL, bool);
+ default: UPB_ASSERT(false); break;
+ }
+#undef TYPE
+
+ upb_handlerattr_uninit(&attr);
+ return ok;
+}
+
+bool upb_msg_getscalarhandlerdata(const upb_handlers *h,
+ upb_selector_t s,
+ upb_fieldtype_t *type,
+ size_t *offset,
+ int32_t *hasbit) {
+ const upb_msg_handlerdata *d;
+ upb_func *f = upb_handlers_gethandler(h, s);
+
+ if ((upb_int64_handlerfunc*)f == upb_msg_setint64) {
+ *type = UPB_TYPE_INT64;
+ } else if ((upb_int32_handlerfunc*)f == upb_msg_setint32) {
+ *type = UPB_TYPE_INT32;
+ } else if ((upb_uint64_handlerfunc*)f == upb_msg_setuint64) {
+ *type = UPB_TYPE_UINT64;
+ } else if ((upb_uint32_handlerfunc*)f == upb_msg_setuint32) {
+ *type = UPB_TYPE_UINT32;
+ } else if ((upb_double_handlerfunc*)f == upb_msg_setdouble) {
+ *type = UPB_TYPE_DOUBLE;
+ } else if ((upb_float_handlerfunc*)f == upb_msg_setfloat) {
+ *type = UPB_TYPE_FLOAT;
+ } else if ((upb_bool_handlerfunc*)f == upb_msg_setbool) {
+ *type = UPB_TYPE_BOOL;
+ } else {
+ return false;
+ }
+
+ d = upb_handlers_gethandlerdata(h, s);
+ *offset = d->offset;
+ *hasbit = d->hasbit;
+ return true;
+}
+/*
+** upb::RefCounted Implementation
+**
+** Our key invariants are:
+** 1. reference cycles never span groups
+** 2. for ref2(to, from), we increment to's count iff group(from) != group(to)
+**
+** The previous two are how we avoid leaking cycles. Other important
+** invariants are:
+** 3. for mutable objects "from" and "to", if there exists a ref2(to, from)
+** this implies group(from) == group(to). (In practice, what we implement
+** is even stronger; "from" and "to" will share a group if there has *ever*
+** been a ref2(to, from), but all that is necessary for correctness is the
+** weaker one).
+** 4. mutable and immutable objects are never in the same group.
+*/
+
+
+#include <setjmp.h>
+
+static void freeobj(upb_refcounted *o);
+
+const char untracked_val;
+const void *UPB_UNTRACKED_REF = &untracked_val;
+
+/* arch-specific atomic primitives *******************************************/
+
+#ifdef UPB_THREAD_UNSAFE /*---------------------------------------------------*/
+
+static void atomic_inc(uint32_t *a) { (*a)++; }
+static bool atomic_dec(uint32_t *a) { return --(*a) == 0; }
+
+#elif defined(__GNUC__) || defined(__clang__) /*------------------------------*/
+
+static void atomic_inc(uint32_t *a) { __sync_fetch_and_add(a, 1); }
+static bool atomic_dec(uint32_t *a) { return __sync_sub_and_fetch(a, 1) == 0; }
+
+#elif defined(WIN32) /*-------------------------------------------------------*/
+
+#include <Windows.h>
+
+static void atomic_inc(upb_atomic_t *a) { InterlockedIncrement(&a->val); }
+static bool atomic_dec(upb_atomic_t *a) {
+ return InterlockedDecrement(&a->val) == 0;
+}
+
+#else
+#error Atomic primitives not defined for your platform/CPU. \
+ Implement them or compile with UPB_THREAD_UNSAFE.
+#endif
+
+/* All static objects point to this refcount.
+ * It is special-cased in ref/unref below. */
+uint32_t static_refcount = -1;
+
+/* We can avoid atomic ops for statically-declared objects.
+ * This is a minor optimization but nice since we can avoid degrading under
+ * contention in this case. */
+
+static void refgroup(uint32_t *group) {
+ if (group != &static_refcount)
+ atomic_inc(group);
+}
+
+static bool unrefgroup(uint32_t *group) {
+ if (group == &static_refcount) {
+ return false;
+ } else {
+ return atomic_dec(group);
+ }
+}
+
+
+/* Reference tracking (debug only) ********************************************/
+
+#ifdef UPB_DEBUG_REFS
+
+#ifdef UPB_THREAD_UNSAFE
+
+static void upb_lock() {}
+static void upb_unlock() {}
+
+#else
+
+/* User must define functions that lock/unlock a global mutex and link this
+ * file against them. */
+void upb_lock();
+void upb_unlock();
+
+#endif
+
+/* UPB_DEBUG_REFS mode counts on being able to malloc() memory in some
+ * code-paths that can normally never fail, like upb_refcounted_ref(). Since
+ * we have no way to propagage out-of-memory errors back to the user, and since
+ * these errors can only occur in UPB_DEBUG_REFS mode, we use an allocator that
+ * immediately aborts on failure (avoiding the global allocator, which might
+ * inject failures). */
+
+#include <stdlib.h>
+
+static void *upb_debugrefs_allocfunc(upb_alloc *alloc, void *ptr,
+ size_t oldsize, size_t size) {
+ UPB_UNUSED(alloc);
+ UPB_UNUSED(oldsize);
+ if (size == 0) {
+ free(ptr);
+ return NULL;
+ } else {
+ void *ret = realloc(ptr, size);
+
+ if (!ret) {
+ abort();
+ }
+
+ return ret;
+ }
+}
+
+upb_alloc upb_alloc_debugrefs = {&upb_debugrefs_allocfunc};
+
+typedef struct {
+ int count; /* How many refs there are (duplicates only allowed for ref2). */
+ bool is_ref2;
+} trackedref;
+
+static trackedref *trackedref_new(bool is_ref2) {
+ trackedref *ret = upb_malloc(&upb_alloc_debugrefs, sizeof(*ret));
+ ret->count = 1;
+ ret->is_ref2 = is_ref2;
+ return ret;
+}
+
+static void track(const upb_refcounted *r, const void *owner, bool ref2) {
+ upb_value v;
+
+ UPB_ASSERT(owner);
+ if (owner == UPB_UNTRACKED_REF) return;
+
+ upb_lock();
+ if (upb_inttable_lookupptr(r->refs, owner, &v)) {
+ trackedref *ref = upb_value_getptr(v);
+ /* Since we allow multiple ref2's for the same to/from pair without
+ * allocating separate memory for each one, we lose the fine-grained
+ * tracking behavior we get with regular refs. Since ref2s only happen
+ * inside upb, we'll accept this limitation until/unless there is a really
+ * difficult upb-internal bug that can't be figured out without it. */
+ UPB_ASSERT(ref2);
+ UPB_ASSERT(ref->is_ref2);
+ ref->count++;
+ } else {
+ trackedref *ref = trackedref_new(ref2);
+ upb_inttable_insertptr2(r->refs, owner, upb_value_ptr(ref),
+ &upb_alloc_debugrefs);
+ if (ref2) {
+ /* We know this cast is safe when it is a ref2, because it's coming from
+ * another refcounted object. */
+ const upb_refcounted *from = owner;
+ UPB_ASSERT(!upb_inttable_lookupptr(from->ref2s, r, NULL));
+ upb_inttable_insertptr2(from->ref2s, r, upb_value_ptr(NULL),
+ &upb_alloc_debugrefs);
+ }
+ }
+ upb_unlock();
+}
+
+static void untrack(const upb_refcounted *r, const void *owner, bool ref2) {
+ upb_value v;
+ bool found;
+ trackedref *ref;
+
+ UPB_ASSERT(owner);
+ if (owner == UPB_UNTRACKED_REF) return;
+
+ upb_lock();
+ found = upb_inttable_lookupptr(r->refs, owner, &v);
+ /* This assert will fail if an owner attempts to release a ref it didn't have. */
+ UPB_ASSERT(found);
+ ref = upb_value_getptr(v);
+ UPB_ASSERT(ref->is_ref2 == ref2);
+ if (--ref->count == 0) {
+ free(ref);
+ upb_inttable_removeptr(r->refs, owner, NULL);
+ if (ref2) {
+ /* We know this cast is safe when it is a ref2, because it's coming from
+ * another refcounted object. */
+ const upb_refcounted *from = owner;
+ bool removed = upb_inttable_removeptr(from->ref2s, r, NULL);
+ UPB_ASSERT(removed);
+ }
+ }
+ upb_unlock();
+}
+
+static void checkref(const upb_refcounted *r, const void *owner, bool ref2) {
+ upb_value v;
+ bool found;
+ trackedref *ref;
+
+ upb_lock();
+ found = upb_inttable_lookupptr(r->refs, owner, &v);
+ UPB_ASSERT(found);
+ ref = upb_value_getptr(v);
+ UPB_ASSERT(ref->is_ref2 == ref2);
+ upb_unlock();
+}
+
+/* Populates the given UPB_CTYPE_INT32 inttable with counts of ref2's that
+ * originate from the given owner. */
+static void getref2s(const upb_refcounted *owner, upb_inttable *tab) {
+ upb_inttable_iter i;
+
+ upb_lock();
+ upb_inttable_begin(&i, owner->ref2s);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ upb_value v;
+ upb_value count;
+ trackedref *ref;
+ bool found;
+
+ upb_refcounted *to = (upb_refcounted*)upb_inttable_iter_key(&i);
+
+ /* To get the count we need to look in the target's table. */
+ found = upb_inttable_lookupptr(to->refs, owner, &v);
+ UPB_ASSERT(found);
+ ref = upb_value_getptr(v);
+ count = upb_value_int32(ref->count);
+
+ upb_inttable_insertptr2(tab, to, count, &upb_alloc_debugrefs);
+ }
+ upb_unlock();
+}
+
+typedef struct {
+ upb_inttable ref2;
+ const upb_refcounted *obj;
+} check_state;
+
+static void visit_check(const upb_refcounted *obj, const upb_refcounted *subobj,
+ void *closure) {
+ check_state *s = closure;
+ upb_inttable *ref2 = &s->ref2;
+ upb_value v;
+ bool removed;
+ int32_t newcount;
+
+ UPB_ASSERT(obj == s->obj);
+ UPB_ASSERT(subobj);
+ removed = upb_inttable_removeptr(ref2, subobj, &v);
+ /* The following assertion will fail if the visit() function visits a subobj
+ * that it did not have a ref2 on, or visits the same subobj too many times. */
+ UPB_ASSERT(removed);
+ newcount = upb_value_getint32(v) - 1;
+ if (newcount > 0) {
+ upb_inttable_insert2(ref2, (uintptr_t)subobj, upb_value_int32(newcount),
+ &upb_alloc_debugrefs);
+ }
+}
+
+static void visit(const upb_refcounted *r, upb_refcounted_visit *v,
+ void *closure) {
+ /* In DEBUG_REFS mode we know what existing ref2 refs there are, so we know
+ * exactly the set of nodes that visit() should visit. So we verify visit()'s
+ * correctness here. */
+ check_state state;
+ state.obj = r;
+ upb_inttable_init2(&state.ref2, UPB_CTYPE_INT32, &upb_alloc_debugrefs);
+ getref2s(r, &state.ref2);
+
+ /* This should visit any children in the ref2 table. */
+ if (r->vtbl->visit) r->vtbl->visit(r, visit_check, &state);
+
+ /* This assertion will fail if the visit() function missed any children. */
+ UPB_ASSERT(upb_inttable_count(&state.ref2) == 0);
+ upb_inttable_uninit2(&state.ref2, &upb_alloc_debugrefs);
+ if (r->vtbl->visit) r->vtbl->visit(r, v, closure);
+}
+
+static void trackinit(upb_refcounted *r) {
+ r->refs = upb_malloc(&upb_alloc_debugrefs, sizeof(*r->refs));
+ r->ref2s = upb_malloc(&upb_alloc_debugrefs, sizeof(*r->ref2s));
+ upb_inttable_init2(r->refs, UPB_CTYPE_PTR, &upb_alloc_debugrefs);
+ upb_inttable_init2(r->ref2s, UPB_CTYPE_PTR, &upb_alloc_debugrefs);
+}
+
+static void trackfree(const upb_refcounted *r) {
+ upb_inttable_uninit2(r->refs, &upb_alloc_debugrefs);
+ upb_inttable_uninit2(r->ref2s, &upb_alloc_debugrefs);
+ upb_free(&upb_alloc_debugrefs, r->refs);
+ upb_free(&upb_alloc_debugrefs, r->ref2s);
+}
+
+#else
+
+static void track(const upb_refcounted *r, const void *owner, bool ref2) {
+ UPB_UNUSED(r);
+ UPB_UNUSED(owner);
+ UPB_UNUSED(ref2);
+}
+
+static void untrack(const upb_refcounted *r, const void *owner, bool ref2) {
+ UPB_UNUSED(r);
+ UPB_UNUSED(owner);
+ UPB_UNUSED(ref2);
+}
+
+static void checkref(const upb_refcounted *r, const void *owner, bool ref2) {
+ UPB_UNUSED(r);
+ UPB_UNUSED(owner);
+ UPB_UNUSED(ref2);
+}
+
+static void trackinit(upb_refcounted *r) {
+ UPB_UNUSED(r);
+}
+
+static void trackfree(const upb_refcounted *r) {
+ UPB_UNUSED(r);
+}
+
+static void visit(const upb_refcounted *r, upb_refcounted_visit *v,
+ void *closure) {
+ if (r->vtbl->visit) r->vtbl->visit(r, v, closure);
+}
+
+#endif /* UPB_DEBUG_REFS */
+
+
+/* freeze() *******************************************************************/
+
+/* The freeze() operation is by far the most complicated part of this scheme.
+ * We compute strongly-connected components and then mutate the graph such that
+ * we preserve the invariants documented at the top of this file. And we must
+ * handle out-of-memory errors gracefully (without leaving the graph
+ * inconsistent), which adds to the fun. */
+
+/* The state used by the freeze operation (shared across many functions). */
+typedef struct {
+ int depth;
+ int maxdepth;
+ uint64_t index;
+ /* Maps upb_refcounted* -> attributes (color, etc). attr layout varies by
+ * color. */
+ upb_inttable objattr;
+ upb_inttable stack; /* stack of upb_refcounted* for Tarjan's algorithm. */
+ upb_inttable groups; /* array of uint32_t*, malloc'd refcounts for new groups */
+ upb_status *status;
+ jmp_buf err;
+} tarjan;
+
+static void release_ref2(const upb_refcounted *obj,
+ const upb_refcounted *subobj,
+ void *closure);
+
+/* Node attributes -----------------------------------------------------------*/
+
+/* After our analysis phase all nodes will be either GRAY or WHITE. */
+
+typedef enum {
+ BLACK = 0, /* Object has not been seen. */
+ GRAY, /* Object has been found via a refgroup but may not be reachable. */
+ GREEN, /* Object is reachable and is currently on the Tarjan stack. */
+ WHITE /* Object is reachable and has been assigned a group (SCC). */
+} color_t;
+
+UPB_NORETURN static void err(tarjan *t) { longjmp(t->err, 1); }
+UPB_NORETURN static void oom(tarjan *t) {
+ upb_status_seterrmsg(t->status, "out of memory");
+ err(t);
+}
+
+static uint64_t trygetattr(const tarjan *t, const upb_refcounted *r) {
+ upb_value v;
+ return upb_inttable_lookupptr(&t->objattr, r, &v) ?
+ upb_value_getuint64(v) : 0;
+}
+
+static uint64_t getattr(const tarjan *t, const upb_refcounted *r) {
+ upb_value v;
+ bool found = upb_inttable_lookupptr(&t->objattr, r, &v);
+ UPB_ASSERT(found);
+ return upb_value_getuint64(v);
+}
+
+static void setattr(tarjan *t, const upb_refcounted *r, uint64_t attr) {
+ upb_inttable_removeptr(&t->objattr, r, NULL);
+ upb_inttable_insertptr(&t->objattr, r, upb_value_uint64(attr));
+}
+
+static color_t color(tarjan *t, const upb_refcounted *r) {
+ return trygetattr(t, r) & 0x3; /* Color is always stored in the low 2 bits. */
+}
+
+static void set_gray(tarjan *t, const upb_refcounted *r) {
+ UPB_ASSERT(color(t, r) == BLACK);
+ setattr(t, r, GRAY);
+}
+
+/* Pushes an obj onto the Tarjan stack and sets it to GREEN. */
+static void push(tarjan *t, const upb_refcounted *r) {
+ UPB_ASSERT(color(t, r) == BLACK || color(t, r) == GRAY);
+ /* This defines the attr layout for the GREEN state. "index" and "lowlink"
+ * get 31 bits, which is plenty (limit of 2B objects frozen at a time). */
+ setattr(t, r, GREEN | (t->index << 2) | (t->index << 33));
+ if (++t->index == 0x80000000) {
+ upb_status_seterrmsg(t->status, "too many objects to freeze");
+ err(t);
+ }
+ upb_inttable_push(&t->stack, upb_value_ptr((void*)r));
+}
+
+/* Pops an obj from the Tarjan stack and sets it to WHITE, with a ptr to its
+ * SCC group. */
+static upb_refcounted *pop(tarjan *t) {
+ upb_refcounted *r = upb_value_getptr(upb_inttable_pop(&t->stack));
+ UPB_ASSERT(color(t, r) == GREEN);
+ /* This defines the attr layout for nodes in the WHITE state.
+ * Top of group stack is [group, NULL]; we point at group. */
+ setattr(t, r, WHITE | (upb_inttable_count(&t->groups) - 2) << 8);
+ return r;
+}
+
+static void tarjan_newgroup(tarjan *t) {
+ uint32_t *group = upb_gmalloc(sizeof(*group));
+ if (!group) oom(t);
+ /* Push group and empty group leader (we'll fill in leader later). */
+ if (!upb_inttable_push(&t->groups, upb_value_ptr(group)) ||
+ !upb_inttable_push(&t->groups, upb_value_ptr(NULL))) {
+ upb_gfree(group);
+ oom(t);
+ }
+ *group = 0;
+}
+
+static uint32_t idx(tarjan *t, const upb_refcounted *r) {
+ UPB_ASSERT(color(t, r) == GREEN);
+ return (getattr(t, r) >> 2) & 0x7FFFFFFF;
+}
+
+static uint32_t lowlink(tarjan *t, const upb_refcounted *r) {
+ if (color(t, r) == GREEN) {
+ return getattr(t, r) >> 33;
+ } else {
+ return UINT32_MAX;
+ }
+}
+
+static void set_lowlink(tarjan *t, const upb_refcounted *r, uint32_t lowlink) {
+ UPB_ASSERT(color(t, r) == GREEN);
+ setattr(t, r, ((uint64_t)lowlink << 33) | (getattr(t, r) & 0x1FFFFFFFF));
+}
+
+static uint32_t *group(tarjan *t, upb_refcounted *r) {
+ uint64_t groupnum;
+ upb_value v;
+ bool found;
+
+ UPB_ASSERT(color(t, r) == WHITE);
+ groupnum = getattr(t, r) >> 8;
+ found = upb_inttable_lookup(&t->groups, groupnum, &v);
+ UPB_ASSERT(found);
+ return upb_value_getptr(v);
+}
+
+/* If the group leader for this object's group has not previously been set,
+ * the given object is assigned to be its leader. */
+static upb_refcounted *groupleader(tarjan *t, upb_refcounted *r) {
+ uint64_t leader_slot;
+ upb_value v;
+ bool found;
+
+ UPB_ASSERT(color(t, r) == WHITE);
+ leader_slot = (getattr(t, r) >> 8) + 1;
+ found = upb_inttable_lookup(&t->groups, leader_slot, &v);
+ UPB_ASSERT(found);
+ if (upb_value_getptr(v)) {
+ return upb_value_getptr(v);
+ } else {
+ upb_inttable_remove(&t->groups, leader_slot, NULL);
+ upb_inttable_insert(&t->groups, leader_slot, upb_value_ptr(r));
+ return r;
+ }
+}
+
+
+/* Tarjan's algorithm --------------------------------------------------------*/
+
+/* See:
+ * http://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm */
+static void do_tarjan(const upb_refcounted *obj, tarjan *t);
+
+static void tarjan_visit(const upb_refcounted *obj,
+ const upb_refcounted *subobj,
+ void *closure) {
+ tarjan *t = closure;
+ if (++t->depth > t->maxdepth) {
+ upb_status_seterrf(t->status, "graph too deep to freeze (%d)", t->maxdepth);
+ err(t);
+ } else if (subobj->is_frozen || color(t, subobj) == WHITE) {
+ /* Do nothing: we don't want to visit or color already-frozen nodes,
+ * and WHITE nodes have already been assigned a SCC. */
+ } else if (color(t, subobj) < GREEN) {
+ /* Subdef has not yet been visited; recurse on it. */
+ do_tarjan(subobj, t);
+ set_lowlink(t, obj, UPB_MIN(lowlink(t, obj), lowlink(t, subobj)));
+ } else if (color(t, subobj) == GREEN) {
+ /* Subdef is in the stack and hence in the current SCC. */
+ set_lowlink(t, obj, UPB_MIN(lowlink(t, obj), idx(t, subobj)));
+ }
+ --t->depth;
+}
+
+static void do_tarjan(const upb_refcounted *obj, tarjan *t) {
+ if (color(t, obj) == BLACK) {
+ /* We haven't seen this object's group; mark the whole group GRAY. */
+ const upb_refcounted *o = obj;
+ do { set_gray(t, o); } while ((o = o->next) != obj);
+ }
+
+ push(t, obj);
+ visit(obj, tarjan_visit, t);
+ if (lowlink(t, obj) == idx(t, obj)) {
+ tarjan_newgroup(t);
+ while (pop(t) != obj)
+ ;
+ }
+}
+
+
+/* freeze() ------------------------------------------------------------------*/
+
+static void crossref(const upb_refcounted *r, const upb_refcounted *subobj,
+ void *_t) {
+ tarjan *t = _t;
+ UPB_ASSERT(color(t, r) > BLACK);
+ if (color(t, subobj) > BLACK && r->group != subobj->group) {
+ /* Previously this ref was not reflected in subobj->group because they
+ * were in the same group; now that they are split a ref must be taken. */
+ refgroup(subobj->group);
+ }
+}
+
+static bool freeze(upb_refcounted *const*roots, int n, upb_status *s,
+ int maxdepth) {
+ volatile bool ret = false;
+ int i;
+ upb_inttable_iter iter;
+
+ /* We run in two passes so that we can allocate all memory before performing
+ * any mutation of the input -- this allows us to leave the input unchanged
+ * in the case of memory allocation failure. */
+ tarjan t;
+ t.index = 0;
+ t.depth = 0;
+ t.maxdepth = maxdepth;
+ t.status = s;
+ if (!upb_inttable_init(&t.objattr, UPB_CTYPE_UINT64)) goto err1;
+ if (!upb_inttable_init(&t.stack, UPB_CTYPE_PTR)) goto err2;
+ if (!upb_inttable_init(&t.groups, UPB_CTYPE_PTR)) goto err3;
+ if (setjmp(t.err) != 0) goto err4;
+
+
+ for (i = 0; i < n; i++) {
+ if (color(&t, roots[i]) < GREEN) {
+ do_tarjan(roots[i], &t);
+ }
+ }
+
+ /* If we've made it this far, no further errors are possible so it's safe to
+ * mutate the objects without risk of leaving them in an inconsistent state. */
+ ret = true;
+
+ /* The transformation that follows requires care. The preconditions are:
+ * - all objects in attr map are WHITE or GRAY, and are in mutable groups
+ * (groups of all mutable objs)
+ * - no ref2(to, from) refs have incremented count(to) if both "to" and
+ * "from" are in our attr map (this follows from invariants (2) and (3)) */
+
+ /* Pass 1: we remove WHITE objects from their mutable groups, and add them to
+ * new groups according to the SCC's we computed. These new groups will
+ * consist of only frozen objects. None will be immediately collectible,
+ * because WHITE objects are by definition reachable from one of "roots",
+ * which the caller must own refs on. */
+ upb_inttable_begin(&iter, &t.objattr);
+ for(; !upb_inttable_done(&iter); upb_inttable_next(&iter)) {
+ upb_refcounted *obj = (upb_refcounted*)upb_inttable_iter_key(&iter);
+ /* Since removal from a singly-linked list requires access to the object's
+ * predecessor, we consider obj->next instead of obj for moving. With the
+ * while() loop we guarantee that we will visit every node's predecessor.
+ * Proof:
+ * 1. every node's predecessor is in our attr map.
+ * 2. though the loop body may change a node's predecessor, it will only
+ * change it to be the node we are currently operating on, so with a
+ * while() loop we guarantee ourselves the chance to remove each node. */
+ while (color(&t, obj->next) == WHITE &&
+ group(&t, obj->next) != obj->next->group) {
+ upb_refcounted *leader;
+
+ /* Remove from old group. */
+ upb_refcounted *move = obj->next;
+ if (obj == move) {
+ /* Removing the last object from a group. */
+ UPB_ASSERT(*obj->group == obj->individual_count);
+ upb_gfree(obj->group);
+ } else {
+ obj->next = move->next;
+ /* This may decrease to zero; we'll collect GRAY objects (if any) that
+ * remain in the group in the third pass. */
+ UPB_ASSERT(*move->group >= move->individual_count);
+ *move->group -= move->individual_count;
+ }
+
+ /* Add to new group. */
+ leader = groupleader(&t, move);
+ if (move == leader) {
+ /* First object added to new group is its leader. */
+ move->group = group(&t, move);
+ move->next = move;
+ *move->group = move->individual_count;
+ } else {
+ /* Group already has at least one object in it. */
+ UPB_ASSERT(leader->group == group(&t, move));
+ move->group = group(&t, move);
+ move->next = leader->next;
+ leader->next = move;
+ *move->group += move->individual_count;
+ }
+
+ move->is_frozen = true;
+ }
+ }
+
+ /* Pass 2: GRAY and WHITE objects "obj" with ref2(to, obj) references must
+ * increment count(to) if group(obj) != group(to) (which could now be the
+ * case if "to" was just frozen). */
+ upb_inttable_begin(&iter, &t.objattr);
+ for(; !upb_inttable_done(&iter); upb_inttable_next(&iter)) {
+ upb_refcounted *obj = (upb_refcounted*)upb_inttable_iter_key(&iter);
+ visit(obj, crossref, &t);
+ }
+
+ /* Pass 3: GRAY objects are collected if their group's refcount dropped to
+ * zero when we removed its white nodes. This can happen if they had only
+ * been kept alive by virtue of sharing a group with an object that was just
+ * frozen.
+ *
+ * It is important that we do this last, since the GRAY object's free()
+ * function could call unref2() on just-frozen objects, which will decrement
+ * refs that were added in pass 2. */
+ upb_inttable_begin(&iter, &t.objattr);
+ for(; !upb_inttable_done(&iter); upb_inttable_next(&iter)) {
+ upb_refcounted *obj = (upb_refcounted*)upb_inttable_iter_key(&iter);
+ if (obj->group == NULL || *obj->group == 0) {
+ if (obj->group) {
+ upb_refcounted *o;
+
+ /* We eagerly free() the group's count (since we can't easily determine
+ * the group's remaining size it's the easiest way to ensure it gets
+ * done). */
+ upb_gfree(obj->group);
+
+ /* Visit to release ref2's (done in a separate pass since release_ref2
+ * depends on o->group being unmodified so it can test merged()). */
+ o = obj;
+ do { visit(o, release_ref2, NULL); } while ((o = o->next) != obj);
+
+ /* Mark "group" fields as NULL so we know to free the objects later in
+ * this loop, but also don't try to delete the group twice. */
+ o = obj;
+ do { o->group = NULL; } while ((o = o->next) != obj);
+ }
+ freeobj(obj);
+ }
+ }
+
+err4:
+ if (!ret) {
+ upb_inttable_begin(&iter, &t.groups);
+ for(; !upb_inttable_done(&iter); upb_inttable_next(&iter))
+ upb_gfree(upb_value_getptr(upb_inttable_iter_value(&iter)));
+ }
+ upb_inttable_uninit(&t.groups);
+err3:
+ upb_inttable_uninit(&t.stack);
+err2:
+ upb_inttable_uninit(&t.objattr);
+err1:
+ return ret;
+}
+
+
+/* Misc internal functions ***************************************************/
+
+static bool merged(const upb_refcounted *r, const upb_refcounted *r2) {
+ return r->group == r2->group;
+}
+
+static void merge(upb_refcounted *r, upb_refcounted *from) {
+ upb_refcounted *base;
+ upb_refcounted *tmp;
+
+ if (merged(r, from)) return;
+ *r->group += *from->group;
+ upb_gfree(from->group);
+ base = from;
+
+ /* Set all refcount pointers in the "from" chain to the merged refcount.
+ *
+ * TODO(haberman): this linear algorithm can result in an overall O(n^2) bound
+ * if the user continuously extends a group by one object. Prevent this by
+ * using one of the techniques in this paper:
+ * http://bioinfo.ict.ac.cn/~dbu/AlgorithmCourses/Lectures/Union-Find-Tarjan.pdf */
+ do { from->group = r->group; } while ((from = from->next) != base);
+
+ /* Merge the two circularly linked lists by swapping their next pointers. */
+ tmp = r->next;
+ r->next = base->next;
+ base->next = tmp;
+}
+
+static void unref(const upb_refcounted *r);
+
+static void release_ref2(const upb_refcounted *obj,
+ const upb_refcounted *subobj,
+ void *closure) {
+ UPB_UNUSED(closure);
+ untrack(subobj, obj, true);
+ if (!merged(obj, subobj)) {
+ UPB_ASSERT(subobj->is_frozen);
+ unref(subobj);
+ }
+}
+
+static void unref(const upb_refcounted *r) {
+ if (unrefgroup(r->group)) {
+ const upb_refcounted *o;
+
+ upb_gfree(r->group);
+
+ /* In two passes, since release_ref2 needs a guarantee that any subobjs
+ * are alive. */
+ o = r;
+ do { visit(o, release_ref2, NULL); } while((o = o->next) != r);
+
+ o = r;
+ do {
+ const upb_refcounted *next = o->next;
+ UPB_ASSERT(o->is_frozen || o->individual_count == 0);
+ freeobj((upb_refcounted*)o);
+ o = next;
+ } while(o != r);
+ }
+}
+
+static void freeobj(upb_refcounted *o) {
+ trackfree(o);
+ o->vtbl->free((upb_refcounted*)o);
+}
+
+
+/* Public interface ***********************************************************/
+
+bool upb_refcounted_init(upb_refcounted *r,
+ const struct upb_refcounted_vtbl *vtbl,
+ const void *owner) {
+#ifndef NDEBUG
+ /* Endianness check. This is unrelated to upb_refcounted, it's just a
+ * convenient place to put the check that we can be assured will run for
+ * basically every program using upb. */
+ const int x = 1;
+#ifdef UPB_BIG_ENDIAN
+ UPB_ASSERT(*(char*)&x != 1);
+#else
+ UPB_ASSERT(*(char*)&x == 1);
+#endif
+#endif
+
+ r->next = r;
+ r->vtbl = vtbl;
+ r->individual_count = 0;
+ r->is_frozen = false;
+ r->group = upb_gmalloc(sizeof(*r->group));
+ if (!r->group) return false;
+ *r->group = 0;
+ trackinit(r);
+ upb_refcounted_ref(r, owner);
+ return true;
+}
+
+bool upb_refcounted_isfrozen(const upb_refcounted *r) {
+ return r->is_frozen;
+}
+
+void upb_refcounted_ref(const upb_refcounted *r, const void *owner) {
+ track(r, owner, false);
+ if (!r->is_frozen)
+ ((upb_refcounted*)r)->individual_count++;
+ refgroup(r->group);
+}
+
+void upb_refcounted_unref(const upb_refcounted *r, const void *owner) {
+ untrack(r, owner, false);
+ if (!r->is_frozen)
+ ((upb_refcounted*)r)->individual_count--;
+ unref(r);
+}
+
+void upb_refcounted_ref2(const upb_refcounted *r, upb_refcounted *from) {
+ UPB_ASSERT(!from->is_frozen); /* Non-const pointer implies this. */
+ track(r, from, true);
+ if (r->is_frozen) {
+ refgroup(r->group);
+ } else {
+ merge((upb_refcounted*)r, from);
+ }
+}
+
+void upb_refcounted_unref2(const upb_refcounted *r, upb_refcounted *from) {
+ UPB_ASSERT(!from->is_frozen); /* Non-const pointer implies this. */
+ untrack(r, from, true);
+ if (r->is_frozen) {
+ unref(r);
+ } else {
+ UPB_ASSERT(merged(r, from));
+ }
+}
+
+void upb_refcounted_donateref(
+ const upb_refcounted *r, const void *from, const void *to) {
+ UPB_ASSERT(from != to);
+ if (to != NULL)
+ upb_refcounted_ref(r, to);
+ if (from != NULL)
+ upb_refcounted_unref(r, from);
+}
+
+void upb_refcounted_checkref(const upb_refcounted *r, const void *owner) {
+ checkref(r, owner, false);
+}
+
+bool upb_refcounted_freeze(upb_refcounted *const*roots, int n, upb_status *s,
+ int maxdepth) {
+ int i;
+ bool ret;
+ for (i = 0; i < n; i++) {
+ UPB_ASSERT(!roots[i]->is_frozen);
+ }
+ ret = freeze(roots, n, s, maxdepth);
+ UPB_ASSERT(!s || ret == upb_ok(s));
+ return ret;
+}
+
+
+bool upb_bufsrc_putbuf(const char *buf, size_t len, upb_bytessink *sink) {
+ void *subc;
+ bool ret;
+ upb_bufhandle handle;
+ upb_bufhandle_init(&handle);
+ upb_bufhandle_setbuf(&handle, buf, 0);
+ ret = upb_bytessink_start(sink, len, &subc);
+ if (ret && len != 0) {
+ ret = (upb_bytessink_putbuf(sink, subc, buf, len, &handle) >= len);
+ }
+ if (ret) {
+ ret = upb_bytessink_end(sink);
+ }
+ upb_bufhandle_uninit(&handle);
+ return ret;
+}
+
+struct upb_bufsink {
+ upb_byteshandler handler;
+ upb_bytessink sink;
+ upb_env *env;
+ char *ptr;
+ size_t len, size;
+};
+
+static void *upb_bufsink_start(void *_sink, const void *hd, size_t size_hint) {
+ upb_bufsink *sink = _sink;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(size_hint);
+ sink->len = 0;
+ return sink;
+}
+
+static size_t upb_bufsink_string(void *_sink, const void *hd, const char *ptr,
+ size_t len, const upb_bufhandle *handle) {
+ upb_bufsink *sink = _sink;
+ size_t new_size = sink->size;
+
+ UPB_ASSERT(new_size > 0);
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ while (sink->len + len > new_size) {
+ new_size *= 2;
+ }
+
+ if (new_size != sink->size) {
+ sink->ptr = upb_env_realloc(sink->env, sink->ptr, sink->size, new_size);
+ sink->size = new_size;
+ }
+
+ memcpy(sink->ptr + sink->len, ptr, len);
+ sink->len += len;
+
+ return len;
+}
+
+upb_bufsink *upb_bufsink_new(upb_env *env) {
+ upb_bufsink *sink = upb_env_malloc(env, sizeof(upb_bufsink));
+ upb_byteshandler_init(&sink->handler);
+ upb_byteshandler_setstartstr(&sink->handler, upb_bufsink_start, NULL);
+ upb_byteshandler_setstring(&sink->handler, upb_bufsink_string, NULL);
+
+ upb_bytessink_reset(&sink->sink, &sink->handler, sink);
+
+ sink->env = env;
+ sink->size = 32;
+ sink->ptr = upb_env_malloc(env, sink->size);
+ sink->len = 0;
+
+ return sink;
+}
+
+void upb_bufsink_free(upb_bufsink *sink) {
+ upb_env_free(sink->env, sink->ptr);
+ upb_env_free(sink->env, sink);
+}
+
+upb_bytessink *upb_bufsink_sink(upb_bufsink *sink) {
+ return &sink->sink;
+}
+
+const char *upb_bufsink_getdata(const upb_bufsink *sink, size_t *len) {
+ *len = sink->len;
+ return sink->ptr;
+}
+/*
+** upb_table Implementation
+**
+** Implementation is heavily inspired by Lua's ltable.c.
+*/
+
+
+#include <string.h>
+
+#define UPB_MAXARRSIZE 16 /* 64k. */
+
+/* From Chromium. */
+#define ARRAY_SIZE(x) \
+ ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
+
+static void upb_check_alloc(upb_table *t, upb_alloc *a) {
+ UPB_UNUSED(t);
+ UPB_UNUSED(a);
+ UPB_ASSERT_DEBUGVAR(t->alloc == a);
+}
+
+static const double MAX_LOAD = 0.85;
+
+/* The minimum utilization of the array part of a mixed hash/array table. This
+ * is a speed/memory-usage tradeoff (though it's not straightforward because of
+ * cache effects). The lower this is, the more memory we'll use. */
+static const double MIN_DENSITY = 0.1;
+
+bool is_pow2(uint64_t v) { return v == 0 || (v & (v - 1)) == 0; }
+
+int log2ceil(uint64_t v) {
+ int ret = 0;
+ bool pow2 = is_pow2(v);
+ while (v >>= 1) ret++;
+ ret = pow2 ? ret : ret + 1; /* Ceiling. */
+ return UPB_MIN(UPB_MAXARRSIZE, ret);
+}
+
+char *upb_strdup(const char *s, upb_alloc *a) {
+ return upb_strdup2(s, strlen(s), a);
+}
+
+char *upb_strdup2(const char *s, size_t len, upb_alloc *a) {
+ size_t n;
+ char *p;
+
+ /* Prevent overflow errors. */
+ if (len == SIZE_MAX) return NULL;
+ /* Always null-terminate, even if binary data; but don't rely on the input to
+ * have a null-terminating byte since it may be a raw binary buffer. */
+ n = len + 1;
+ p = upb_malloc(a, n);
+ if (p) {
+ memcpy(p, s, len);
+ p[len] = 0;
+ }
+ return p;
+}
+
+/* A type to represent the lookup key of either a strtable or an inttable. */
+typedef union {
+ uintptr_t num;
+ struct {
+ const char *str;
+ size_t len;
+ } str;
+} lookupkey_t;
+
+static lookupkey_t strkey2(const char *str, size_t len) {
+ lookupkey_t k;
+ k.str.str = str;
+ k.str.len = len;
+ return k;
+}
+
+static lookupkey_t intkey(uintptr_t key) {
+ lookupkey_t k;
+ k.num = key;
+ return k;
+}
+
+typedef uint32_t hashfunc_t(upb_tabkey key);
+typedef bool eqlfunc_t(upb_tabkey k1, lookupkey_t k2);
+
+/* Base table (shared code) ***************************************************/
+
+/* For when we need to cast away const. */
+static upb_tabent *mutable_entries(upb_table *t) {
+ return (upb_tabent*)t->entries;
+}
+
+static bool isfull(upb_table *t) {
+ if (upb_table_size(t) == 0) {
+ return true;
+ } else {
+ return ((double)(t->count + 1) / upb_table_size(t)) > MAX_LOAD;
+ }
+}
+
+static bool init(upb_table *t, upb_ctype_t ctype, uint8_t size_lg2,
+ upb_alloc *a) {
+ size_t bytes;
+
+ t->count = 0;
+ t->ctype = ctype;
+ t->size_lg2 = size_lg2;
+ t->mask = upb_table_size(t) ? upb_table_size(t) - 1 : 0;
+#ifndef NDEBUG
+ t->alloc = a;
+#endif
+ bytes = upb_table_size(t) * sizeof(upb_tabent);
+ if (bytes > 0) {
+ t->entries = upb_malloc(a, bytes);
+ if (!t->entries) return false;
+ memset(mutable_entries(t), 0, bytes);
+ } else {
+ t->entries = NULL;
+ }
+ return true;
+}
+
+static void uninit(upb_table *t, upb_alloc *a) {
+ upb_check_alloc(t, a);
+ upb_free(a, mutable_entries(t));
+}
+
+static upb_tabent *emptyent(upb_table *t) {
+ upb_tabent *e = mutable_entries(t) + upb_table_size(t);
+ while (1) { if (upb_tabent_isempty(--e)) return e; UPB_ASSERT(e > t->entries); }
+}
+
+static upb_tabent *getentry_mutable(upb_table *t, uint32_t hash) {
+ return (upb_tabent*)upb_getentry(t, hash);
+}
+
+static const upb_tabent *findentry(const upb_table *t, lookupkey_t key,
+ uint32_t hash, eqlfunc_t *eql) {
+ const upb_tabent *e;
+
+ if (t->size_lg2 == 0) return NULL;
+ e = upb_getentry(t, hash);
+ if (upb_tabent_isempty(e)) return NULL;
+ while (1) {
+ if (eql(e->key, key)) return e;
+ if ((e = e->next) == NULL) return NULL;
+ }
+}
+
+static upb_tabent *findentry_mutable(upb_table *t, lookupkey_t key,
+ uint32_t hash, eqlfunc_t *eql) {
+ return (upb_tabent*)findentry(t, key, hash, eql);
+}
+
+static bool lookup(const upb_table *t, lookupkey_t key, upb_value *v,
+ uint32_t hash, eqlfunc_t *eql) {
+ const upb_tabent *e = findentry(t, key, hash, eql);
+ if (e) {
+ if (v) {
+ _upb_value_setval(v, e->val.val, t->ctype);
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/* The given key must not already exist in the table. */
+static void insert(upb_table *t, lookupkey_t key, upb_tabkey tabkey,
+ upb_value val, uint32_t hash,
+ hashfunc_t *hashfunc, eqlfunc_t *eql) {
+ upb_tabent *mainpos_e;
+ upb_tabent *our_e;
+
+ UPB_ASSERT(findentry(t, key, hash, eql) == NULL);
+ UPB_ASSERT_DEBUGVAR(val.ctype == t->ctype);
+
+ t->count++;
+ mainpos_e = getentry_mutable(t, hash);
+ our_e = mainpos_e;
+
+ if (upb_tabent_isempty(mainpos_e)) {
+ /* Our main position is empty; use it. */
+ our_e->next = NULL;
+ } else {
+ /* Collision. */
+ upb_tabent *new_e = emptyent(t);
+ /* Head of collider's chain. */
+ upb_tabent *chain = getentry_mutable(t, hashfunc(mainpos_e->key));
+ if (chain == mainpos_e) {
+ /* Existing ent is in its main posisiton (it has the same hash as us, and
+ * is the head of our chain). Insert to new ent and append to this chain. */
+ new_e->next = mainpos_e->next;
+ mainpos_e->next = new_e;
+ our_e = new_e;
+ } else {
+ /* Existing ent is not in its main position (it is a node in some other
+ * chain). This implies that no existing ent in the table has our hash.
+ * Evict it (updating its chain) and use its ent for head of our chain. */
+ *new_e = *mainpos_e; /* copies next. */
+ while (chain->next != mainpos_e) {
+ chain = (upb_tabent*)chain->next;
+ UPB_ASSERT(chain);
+ }
+ chain->next = new_e;
+ our_e = mainpos_e;
+ our_e->next = NULL;
+ }
+ }
+ our_e->key = tabkey;
+ our_e->val.val = val.val;
+ UPB_ASSERT(findentry(t, key, hash, eql) == our_e);
+}
+
+static bool rm(upb_table *t, lookupkey_t key, upb_value *val,
+ upb_tabkey *removed, uint32_t hash, eqlfunc_t *eql) {
+ upb_tabent *chain = getentry_mutable(t, hash);
+ if (upb_tabent_isempty(chain)) return false;
+ if (eql(chain->key, key)) {
+ /* Element to remove is at the head of its chain. */
+ t->count--;
+ if (val) _upb_value_setval(val, chain->val.val, t->ctype);
+ if (removed) *removed = chain->key;
+ if (chain->next) {
+ upb_tabent *move = (upb_tabent*)chain->next;
+ *chain = *move;
+ move->key = 0; /* Make the slot empty. */
+ } else {
+ chain->key = 0; /* Make the slot empty. */
+ }
+ return true;
+ } else {
+ /* Element to remove is either in a non-head position or not in the
+ * table. */
+ while (chain->next && !eql(chain->next->key, key)) {
+ chain = (upb_tabent*)chain->next;
+ }
+ if (chain->next) {
+ /* Found element to remove. */
+ upb_tabent *rm = (upb_tabent*)chain->next;
+ t->count--;
+ if (val) _upb_value_setval(val, chain->next->val.val, t->ctype);
+ if (removed) *removed = rm->key;
+ rm->key = 0; /* Make the slot empty. */
+ chain->next = rm->next;
+ return true;
+ } else {
+ /* Element to remove is not in the table. */
+ return false;
+ }
+ }
+}
+
+static size_t next(const upb_table *t, size_t i) {
+ do {
+ if (++i >= upb_table_size(t))
+ return SIZE_MAX;
+ } while(upb_tabent_isempty(&t->entries[i]));
+
+ return i;
+}
+
+static size_t begin(const upb_table *t) {
+ return next(t, -1);
+}
+
+
+/* upb_strtable ***************************************************************/
+
+/* A simple "subclass" of upb_table that only adds a hash function for strings. */
+
+static upb_tabkey strcopy(lookupkey_t k2, upb_alloc *a) {
+ char *str = upb_malloc(a, k2.str.len + sizeof(uint32_t) + 1);
+ if (str == NULL) return 0;
+ memcpy(str, &k2.str.len, sizeof(uint32_t));
+ memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len + 1);
+ return (uintptr_t)str;
+}
+
+static uint32_t strhash(upb_tabkey key) {
+ uint32_t len;
+ char *str = upb_tabstr(key, &len);
+ return MurmurHash2(str, len, 0);
+}
+
+static bool streql(upb_tabkey k1, lookupkey_t k2) {
+ uint32_t len;
+ char *str = upb_tabstr(k1, &len);
+ return len == k2.str.len && memcmp(str, k2.str.str, len) == 0;
+}
+
+bool upb_strtable_init2(upb_strtable *t, upb_ctype_t ctype, upb_alloc *a) {
+ return init(&t->t, ctype, 2, a);
+}
+
+void upb_strtable_uninit2(upb_strtable *t, upb_alloc *a) {
+ size_t i;
+ for (i = 0; i < upb_table_size(&t->t); i++)
+ upb_free(a, (void*)t->t.entries[i].key);
+ uninit(&t->t, a);
+}
+
+bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_alloc *a) {
+ upb_strtable new_table;
+ upb_strtable_iter i;
+
+ upb_check_alloc(&t->t, a);
+
+ if (!init(&new_table.t, t->t.ctype, size_lg2, a))
+ return false;
+ upb_strtable_begin(&i, t);
+ for ( ; !upb_strtable_done(&i); upb_strtable_next(&i)) {
+ upb_strtable_insert3(
+ &new_table,
+ upb_strtable_iter_key(&i),
+ upb_strtable_iter_keylength(&i),
+ upb_strtable_iter_value(&i),
+ a);
+ }
+ upb_strtable_uninit2(t, a);
+ *t = new_table;
+ return true;
+}
+
+bool upb_strtable_insert3(upb_strtable *t, const char *k, size_t len,
+ upb_value v, upb_alloc *a) {
+ lookupkey_t key;
+ upb_tabkey tabkey;
+ uint32_t hash;
+
+ upb_check_alloc(&t->t, a);
+
+ if (isfull(&t->t)) {
+ /* Need to resize. New table of double the size, add old elements to it. */
+ if (!upb_strtable_resize(t, t->t.size_lg2 + 1, a)) {
+ return false;
+ }
+ }
+
+ key = strkey2(k, len);
+ tabkey = strcopy(key, a);
+ if (tabkey == 0) return false;
+
+ hash = MurmurHash2(key.str.str, key.str.len, 0);
+ insert(&t->t, key, tabkey, v, hash, &strhash, &streql);
+ return true;
+}
+
+bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len,
+ upb_value *v) {
+ uint32_t hash = MurmurHash2(key, len, 0);
+ return lookup(&t->t, strkey2(key, len), v, hash, &streql);
+}
+
+bool upb_strtable_remove3(upb_strtable *t, const char *key, size_t len,
+ upb_value *val, upb_alloc *alloc) {
+ uint32_t hash = MurmurHash2(key, len, 0);
+ upb_tabkey tabkey;
+ if (rm(&t->t, strkey2(key, len), val, &tabkey, hash, &streql)) {
+ upb_free(alloc, (void*)tabkey);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/* Iteration */
+
+static const upb_tabent *str_tabent(const upb_strtable_iter *i) {
+ return &i->t->t.entries[i->index];
+}
+
+void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t) {
+ i->t = t;
+ i->index = begin(&t->t);
+}
+
+void upb_strtable_next(upb_strtable_iter *i) {
+ i->index = next(&i->t->t, i->index);
+}
+
+bool upb_strtable_done(const upb_strtable_iter *i) {
+ return i->index >= upb_table_size(&i->t->t) ||
+ upb_tabent_isempty(str_tabent(i));
+}
+
+const char *upb_strtable_iter_key(const upb_strtable_iter *i) {
+ UPB_ASSERT(!upb_strtable_done(i));
+ return upb_tabstr(str_tabent(i)->key, NULL);
+}
+
+size_t upb_strtable_iter_keylength(const upb_strtable_iter *i) {
+ uint32_t len;
+ UPB_ASSERT(!upb_strtable_done(i));
+ upb_tabstr(str_tabent(i)->key, &len);
+ return len;
+}
+
+upb_value upb_strtable_iter_value(const upb_strtable_iter *i) {
+ UPB_ASSERT(!upb_strtable_done(i));
+ return _upb_value_val(str_tabent(i)->val.val, i->t->t.ctype);
+}
+
+void upb_strtable_iter_setdone(upb_strtable_iter *i) {
+ i->index = SIZE_MAX;
+}
+
+bool upb_strtable_iter_isequal(const upb_strtable_iter *i1,
+ const upb_strtable_iter *i2) {
+ if (upb_strtable_done(i1) && upb_strtable_done(i2))
+ return true;
+ return i1->t == i2->t && i1->index == i2->index;
+}
+
+
+/* upb_inttable ***************************************************************/
+
+/* For inttables we use a hybrid structure where small keys are kept in an
+ * array and large keys are put in the hash table. */
+
+static uint32_t inthash(upb_tabkey key) { return upb_inthash(key); }
+
+static bool inteql(upb_tabkey k1, lookupkey_t k2) {
+ return k1 == k2.num;
+}
+
+static upb_tabval *mutable_array(upb_inttable *t) {
+ return (upb_tabval*)t->array;
+}
+
+static upb_tabval *inttable_val(upb_inttable *t, uintptr_t key) {
+ if (key < t->array_size) {
+ return upb_arrhas(t->array[key]) ? &(mutable_array(t)[key]) : NULL;
+ } else {
+ upb_tabent *e =
+ findentry_mutable(&t->t, intkey(key), upb_inthash(key), &inteql);
+ return e ? &e->val : NULL;
+ }
+}
+
+static const upb_tabval *inttable_val_const(const upb_inttable *t,
+ uintptr_t key) {
+ return inttable_val((upb_inttable*)t, key);
+}
+
+size_t upb_inttable_count(const upb_inttable *t) {
+ return t->t.count + t->array_count;
+}
+
+static void check(upb_inttable *t) {
+ UPB_UNUSED(t);
+#if defined(UPB_DEBUG_TABLE) && !defined(NDEBUG)
+ {
+ /* This check is very expensive (makes inserts/deletes O(N)). */
+ size_t count = 0;
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, t);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i), count++) {
+ UPB_ASSERT(upb_inttable_lookup(t, upb_inttable_iter_key(&i), NULL));
+ }
+ UPB_ASSERT(count == upb_inttable_count(t));
+ }
+#endif
+}
+
+bool upb_inttable_sizedinit(upb_inttable *t, upb_ctype_t ctype,
+ size_t asize, int hsize_lg2, upb_alloc *a) {
+ size_t array_bytes;
+
+ if (!init(&t->t, ctype, hsize_lg2, a)) return false;
+ /* Always make the array part at least 1 long, so that we know key 0
+ * won't be in the hash part, which simplifies things. */
+ t->array_size = UPB_MAX(1, asize);
+ t->array_count = 0;
+ array_bytes = t->array_size * sizeof(upb_value);
+ t->array = upb_malloc(a, array_bytes);
+ if (!t->array) {
+ uninit(&t->t, a);
+ return false;
+ }
+ memset(mutable_array(t), 0xff, array_bytes);
+ check(t);
+ return true;
+}
+
+bool upb_inttable_init2(upb_inttable *t, upb_ctype_t ctype, upb_alloc *a) {
+ return upb_inttable_sizedinit(t, ctype, 0, 4, a);
+}
+
+void upb_inttable_uninit2(upb_inttable *t, upb_alloc *a) {
+ uninit(&t->t, a);
+ upb_free(a, mutable_array(t));
+}
+
+bool upb_inttable_insert2(upb_inttable *t, uintptr_t key, upb_value val,
+ upb_alloc *a) {
+ upb_tabval tabval;
+ tabval.val = val.val;
+ UPB_ASSERT(upb_arrhas(tabval)); /* This will reject (uint64_t)-1. Fix this. */
+
+ upb_check_alloc(&t->t, a);
+
+ if (key < t->array_size) {
+ UPB_ASSERT(!upb_arrhas(t->array[key]));
+ t->array_count++;
+ mutable_array(t)[key].val = val.val;
+ } else {
+ if (isfull(&t->t)) {
+ /* Need to resize the hash part, but we re-use the array part. */
+ size_t i;
+ upb_table new_table;
+
+ if (!init(&new_table, t->t.ctype, t->t.size_lg2 + 1, a)) {
+ return false;
+ }
+
+ for (i = begin(&t->t); i < upb_table_size(&t->t); i = next(&t->t, i)) {
+ const upb_tabent *e = &t->t.entries[i];
+ uint32_t hash;
+ upb_value v;
+
+ _upb_value_setval(&v, e->val.val, t->t.ctype);
+ hash = upb_inthash(e->key);
+ insert(&new_table, intkey(e->key), e->key, v, hash, &inthash, &inteql);
+ }
+
+ UPB_ASSERT(t->t.count == new_table.count);
+
+ uninit(&t->t, a);
+ t->t = new_table;
+ }
+ insert(&t->t, intkey(key), key, val, upb_inthash(key), &inthash, &inteql);
+ }
+ check(t);
+ return true;
+}
+
+bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v) {
+ const upb_tabval *table_v = inttable_val_const(t, key);
+ if (!table_v) return false;
+ if (v) _upb_value_setval(v, table_v->val, t->t.ctype);
+ return true;
+}
+
+bool upb_inttable_replace(upb_inttable *t, uintptr_t key, upb_value val) {
+ upb_tabval *table_v = inttable_val(t, key);
+ if (!table_v) return false;
+ table_v->val = val.val;
+ return true;
+}
+
+bool upb_inttable_remove(upb_inttable *t, uintptr_t key, upb_value *val) {
+ bool success;
+ if (key < t->array_size) {
+ if (upb_arrhas(t->array[key])) {
+ upb_tabval empty = UPB_TABVALUE_EMPTY_INIT;
+ t->array_count--;
+ if (val) {
+ _upb_value_setval(val, t->array[key].val, t->t.ctype);
+ }
+ mutable_array(t)[key] = empty;
+ success = true;
+ } else {
+ success = false;
+ }
+ } else {
+ success = rm(&t->t, intkey(key), val, NULL, upb_inthash(key), &inteql);
+ }
+ check(t);
+ return success;
+}
+
+bool upb_inttable_push2(upb_inttable *t, upb_value val, upb_alloc *a) {
+ upb_check_alloc(&t->t, a);
+ return upb_inttable_insert2(t, upb_inttable_count(t), val, a);
+}
+
+upb_value upb_inttable_pop(upb_inttable *t) {
+ upb_value val;
+ bool ok = upb_inttable_remove(t, upb_inttable_count(t) - 1, &val);
+ UPB_ASSERT(ok);
+ return val;
+}
+
+bool upb_inttable_insertptr2(upb_inttable *t, const void *key, upb_value val,
+ upb_alloc *a) {
+ upb_check_alloc(&t->t, a);
+ return upb_inttable_insert2(t, (uintptr_t)key, val, a);
+}
+
+bool upb_inttable_lookupptr(const upb_inttable *t, const void *key,
+ upb_value *v) {
+ return upb_inttable_lookup(t, (uintptr_t)key, v);
+}
+
+bool upb_inttable_removeptr(upb_inttable *t, const void *key, upb_value *val) {
+ return upb_inttable_remove(t, (uintptr_t)key, val);
+}
+
+void upb_inttable_compact2(upb_inttable *t, upb_alloc *a) {
+ /* A power-of-two histogram of the table keys. */
+ size_t counts[UPB_MAXARRSIZE + 1] = {0};
+
+ /* The max key in each bucket. */
+ uintptr_t max[UPB_MAXARRSIZE + 1] = {0};
+
+ upb_inttable_iter i;
+ size_t arr_count;
+ int size_lg2;
+ upb_inttable new_t;
+
+ upb_check_alloc(&t->t, a);
+
+ upb_inttable_begin(&i, t);
+ for (; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ uintptr_t key = upb_inttable_iter_key(&i);
+ int bucket = log2ceil(key);
+ max[bucket] = UPB_MAX(max[bucket], key);
+ counts[bucket]++;
+ }
+
+ /* Find the largest power of two that satisfies the MIN_DENSITY
+ * definition (while actually having some keys). */
+ arr_count = upb_inttable_count(t);
+
+ for (size_lg2 = ARRAY_SIZE(counts) - 1; size_lg2 > 0; size_lg2--) {
+ if (counts[size_lg2] == 0) {
+ /* We can halve again without losing any entries. */
+ continue;
+ } else if (arr_count >= (1 << size_lg2) * MIN_DENSITY) {
+ break;
+ }
+
+ arr_count -= counts[size_lg2];
+ }
+
+ UPB_ASSERT(arr_count <= upb_inttable_count(t));
+
+ {
+ /* Insert all elements into new, perfectly-sized table. */
+ size_t arr_size = max[size_lg2] + 1; /* +1 so arr[max] will fit. */
+ size_t hash_count = upb_inttable_count(t) - arr_count;
+ size_t hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0;
+ size_t hashsize_lg2 = log2ceil(hash_size);
+
+ upb_inttable_sizedinit(&new_t, t->t.ctype, arr_size, hashsize_lg2, a);
+ upb_inttable_begin(&i, t);
+ for (; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ uintptr_t k = upb_inttable_iter_key(&i);
+ upb_inttable_insert2(&new_t, k, upb_inttable_iter_value(&i), a);
+ }
+ UPB_ASSERT(new_t.array_size == arr_size);
+ UPB_ASSERT(new_t.t.size_lg2 == hashsize_lg2);
+ }
+ upb_inttable_uninit2(t, a);
+ *t = new_t;
+}
+
+/* Iteration. */
+
+static const upb_tabent *int_tabent(const upb_inttable_iter *i) {
+ UPB_ASSERT(!i->array_part);
+ return &i->t->t.entries[i->index];
+}
+
+static upb_tabval int_arrent(const upb_inttable_iter *i) {
+ UPB_ASSERT(i->array_part);
+ return i->t->array[i->index];
+}
+
+void upb_inttable_begin(upb_inttable_iter *i, const upb_inttable *t) {
+ i->t = t;
+ i->index = -1;
+ i->array_part = true;
+ upb_inttable_next(i);
+}
+
+void upb_inttable_next(upb_inttable_iter *iter) {
+ const upb_inttable *t = iter->t;
+ if (iter->array_part) {
+ while (++iter->index < t->array_size) {
+ if (upb_arrhas(int_arrent(iter))) {
+ return;
+ }
+ }
+ iter->array_part = false;
+ iter->index = begin(&t->t);
+ } else {
+ iter->index = next(&t->t, iter->index);
+ }
+}
+
+bool upb_inttable_done(const upb_inttable_iter *i) {
+ if (i->array_part) {
+ return i->index >= i->t->array_size ||
+ !upb_arrhas(int_arrent(i));
+ } else {
+ return i->index >= upb_table_size(&i->t->t) ||
+ upb_tabent_isempty(int_tabent(i));
+ }
+}
+
+uintptr_t upb_inttable_iter_key(const upb_inttable_iter *i) {
+ UPB_ASSERT(!upb_inttable_done(i));
+ return i->array_part ? i->index : int_tabent(i)->key;
+}
+
+upb_value upb_inttable_iter_value(const upb_inttable_iter *i) {
+ UPB_ASSERT(!upb_inttable_done(i));
+ return _upb_value_val(
+ i->array_part ? i->t->array[i->index].val : int_tabent(i)->val.val,
+ i->t->t.ctype);
+}
+
+void upb_inttable_iter_setdone(upb_inttable_iter *i) {
+ i->index = SIZE_MAX;
+ i->array_part = false;
+}
+
+bool upb_inttable_iter_isequal(const upb_inttable_iter *i1,
+ const upb_inttable_iter *i2) {
+ if (upb_inttable_done(i1) && upb_inttable_done(i2))
+ return true;
+ return i1->t == i2->t && i1->index == i2->index &&
+ i1->array_part == i2->array_part;
+}
+
+#ifdef UPB_UNALIGNED_READS_OK
+/* -----------------------------------------------------------------------------
+ * MurmurHash2, by Austin Appleby (released as public domain).
+ * Reformatted and C99-ified by Joshua Haberman.
+ * Note - This code makes a few assumptions about how your machine behaves -
+ * 1. We can read a 4-byte value from any address without crashing
+ * 2. sizeof(int) == 4 (in upb this limitation is removed by using uint32_t
+ * And it has a few limitations -
+ * 1. It will not work incrementally.
+ * 2. It will not produce the same results on little-endian and big-endian
+ * machines. */
+uint32_t MurmurHash2(const void *key, size_t len, uint32_t seed) {
+ /* 'm' and 'r' are mixing constants generated offline.
+ * They're not really 'magic', they just happen to work well. */
+ const uint32_t m = 0x5bd1e995;
+ const int32_t r = 24;
+
+ /* Initialize the hash to a 'random' value */
+ uint32_t h = seed ^ len;
+
+ /* Mix 4 bytes at a time into the hash */
+ const uint8_t * data = (const uint8_t *)key;
+ while(len >= 4) {
+ uint32_t k = *(uint32_t *)data;
+
+ k *= m;
+ k ^= k >> r;
+ k *= m;
+
+ h *= m;
+ h ^= k;
+
+ data += 4;
+ len -= 4;
+ }
+
+ /* Handle the last few bytes of the input array */
+ switch(len) {
+ case 3: h ^= data[2] << 16;
+ case 2: h ^= data[1] << 8;
+ case 1: h ^= data[0]; h *= m;
+ };
+
+ /* Do a few final mixes of the hash to ensure the last few
+ * bytes are well-incorporated. */
+ h ^= h >> 13;
+ h *= m;
+ h ^= h >> 15;
+
+ return h;
+}
+
+#else /* !UPB_UNALIGNED_READS_OK */
+
+/* -----------------------------------------------------------------------------
+ * MurmurHashAligned2, by Austin Appleby
+ * Same algorithm as MurmurHash2, but only does aligned reads - should be safer
+ * on certain platforms.
+ * Performance will be lower than MurmurHash2 */
+
+#define MIX(h,k,m) { k *= m; k ^= k >> r; k *= m; h *= m; h ^= k; }
+
+uint32_t MurmurHash2(const void * key, size_t len, uint32_t seed) {
+ const uint32_t m = 0x5bd1e995;
+ const int32_t r = 24;
+ const uint8_t * data = (const uint8_t *)key;
+ uint32_t h = seed ^ len;
+ uint8_t align = (uintptr_t)data & 3;
+
+ if(align && (len >= 4)) {
+ /* Pre-load the temp registers */
+ uint32_t t = 0, d = 0;
+ int32_t sl;
+ int32_t sr;
+
+ switch(align) {
+ case 1: t |= data[2] << 16;
+ case 2: t |= data[1] << 8;
+ case 3: t |= data[0];
+ }
+
+ t <<= (8 * align);
+
+ data += 4-align;
+ len -= 4-align;
+
+ sl = 8 * (4-align);
+ sr = 8 * align;
+
+ /* Mix */
+
+ while(len >= 4) {
+ uint32_t k;
+
+ d = *(uint32_t *)data;
+ t = (t >> sr) | (d << sl);
+
+ k = t;
+
+ MIX(h,k,m);
+
+ t = d;
+
+ data += 4;
+ len -= 4;
+ }
+
+ /* Handle leftover data in temp registers */
+
+ d = 0;
+
+ if(len >= align) {
+ uint32_t k;
+
+ switch(align) {
+ case 3: d |= data[2] << 16;
+ case 2: d |= data[1] << 8;
+ case 1: d |= data[0];
+ }
+
+ k = (t >> sr) | (d << sl);
+ MIX(h,k,m);
+
+ data += align;
+ len -= align;
+
+ /* ----------
+ * Handle tail bytes */
+
+ switch(len) {
+ case 3: h ^= data[2] << 16;
+ case 2: h ^= data[1] << 8;
+ case 1: h ^= data[0]; h *= m;
+ };
+ } else {
+ switch(len) {
+ case 3: d |= data[2] << 16;
+ case 2: d |= data[1] << 8;
+ case 1: d |= data[0];
+ case 0: h ^= (t >> sr) | (d << sl); h *= m;
+ }
+ }
+
+ h ^= h >> 13;
+ h *= m;
+ h ^= h >> 15;
+
+ return h;
+ } else {
+ while(len >= 4) {
+ uint32_t k = *(uint32_t *)data;
+
+ MIX(h,k,m);
+
+ data += 4;
+ len -= 4;
+ }
+
+ /* ----------
+ * Handle tail bytes */
+
+ switch(len) {
+ case 3: h ^= data[2] << 16;
+ case 2: h ^= data[1] << 8;
+ case 1: h ^= data[0]; h *= m;
+ };
+
+ h ^= h >> 13;
+ h *= m;
+ h ^= h >> 15;
+
+ return h;
+ }
+}
+#undef MIX
+
+#endif /* UPB_UNALIGNED_READS_OK */
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+bool upb_dumptostderr(void *closure, const upb_status* status) {
+ UPB_UNUSED(closure);
+ fprintf(stderr, "%s\n", upb_status_errmsg(status));
+ return false;
+}
+
+/* Guarantee null-termination and provide ellipsis truncation.
+ * It may be tempting to "optimize" this by initializing these final
+ * four bytes up-front and then being careful never to overwrite them,
+ * this is safer and simpler. */
+static void nullz(upb_status *status) {
+ const char *ellipsis = "...";
+ size_t len = strlen(ellipsis);
+ UPB_ASSERT(sizeof(status->msg) > len);
+ memcpy(status->msg + sizeof(status->msg) - len, ellipsis, len);
+}
+
+
+/* upb_upberr *****************************************************************/
+
+upb_errorspace upb_upberr = {"upb error"};
+
+void upb_upberr_setoom(upb_status *status) {
+ status->error_space_ = &upb_upberr;
+ upb_status_seterrmsg(status, "Out of memory");
+}
+
+
+/* upb_status *****************************************************************/
+
+void upb_status_clear(upb_status *status) {
+ if (!status) return;
+ status->ok_ = true;
+ status->code_ = 0;
+ status->msg[0] = '\0';
+}
+
+bool upb_ok(const upb_status *status) { return status->ok_; }
+
+upb_errorspace *upb_status_errspace(const upb_status *status) {
+ return status->error_space_;
+}
+
+int upb_status_errcode(const upb_status *status) { return status->code_; }
+
+const char *upb_status_errmsg(const upb_status *status) { return status->msg; }
+
+void upb_status_seterrmsg(upb_status *status, const char *msg) {
+ if (!status) return;
+ status->ok_ = false;
+ strncpy(status->msg, msg, sizeof(status->msg));
+ nullz(status);
+}
+
+void upb_status_seterrf(upb_status *status, const char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ upb_status_vseterrf(status, fmt, args);
+ va_end(args);
+}
+
+void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args) {
+ if (!status) return;
+ status->ok_ = false;
+ _upb_vsnprintf(status->msg, sizeof(status->msg), fmt, args);
+ nullz(status);
+}
+
+void upb_status_copy(upb_status *to, const upb_status *from) {
+ if (!to) return;
+ *to = *from;
+}
+
+
+/* upb_alloc ******************************************************************/
+
+static void *upb_global_allocfunc(upb_alloc *alloc, void *ptr, size_t oldsize,
+ size_t size) {
+ UPB_UNUSED(alloc);
+ UPB_UNUSED(oldsize);
+ if (size == 0) {
+ free(ptr);
+ return NULL;
+ } else {
+ return realloc(ptr, size);
+ }
+}
+
+upb_alloc upb_alloc_global = {&upb_global_allocfunc};
+
+
+/* upb_arena ******************************************************************/
+
+/* Be conservative and choose 16 in case anyone is using SSE. */
+static const size_t maxalign = 16;
+
+static size_t align_up_max(size_t size) {
+ return ((size + maxalign - 1) / maxalign) * maxalign;
+}
+
+typedef struct mem_block {
+ struct mem_block *next;
+ size_t size;
+ size_t used;
+ bool owned;
+ /* Data follows. */
+} mem_block;
+
+typedef struct cleanup_ent {
+ struct cleanup_ent *next;
+ upb_cleanup_func *cleanup;
+ void *ud;
+} cleanup_ent;
+
+static void upb_arena_addblock(upb_arena *a, void *ptr, size_t size,
+ bool owned) {
+ mem_block *block = ptr;
+
+ block->next = a->block_head;
+ block->size = size;
+ block->used = align_up_max(sizeof(mem_block));
+ block->owned = owned;
+
+ a->block_head = block;
+
+ /* TODO(haberman): ASAN poison. */
+}
+
+
+static mem_block *upb_arena_allocblock(upb_arena *a, size_t size) {
+ size_t block_size = UPB_MAX(size, a->next_block_size) + sizeof(mem_block);
+ mem_block *block = upb_malloc(a->block_alloc, block_size);
+
+ if (!block) {
+ return NULL;
+ }
+
+ upb_arena_addblock(a, block, block_size, true);
+ a->next_block_size = UPB_MIN(block_size * 2, a->max_block_size);
+
+ return block;
+}
+
+static void *upb_arena_doalloc(upb_alloc *alloc, void *ptr, size_t oldsize,
+ size_t size) {
+ upb_arena *a = (upb_arena*)alloc; /* upb_alloc is initial member. */
+ mem_block *block = a->block_head;
+ void *ret;
+
+ if (size == 0) {
+ return NULL; /* We are an arena, don't need individual frees. */
+ }
+
+ size = align_up_max(size);
+
+ /* TODO(haberman): special-case if this is a realloc of the last alloc? */
+
+ if (!block || block->size - block->used < size) {
+ /* Slow path: have to allocate a new block. */
+ block = upb_arena_allocblock(a, size);
+
+ if (!block) {
+ return NULL; /* Out of memory. */
+ }
+ }
+
+ ret = (char*)block + block->used;
+ block->used += size;
+
+ if (oldsize > 0) {
+ memcpy(ret, ptr, oldsize); /* Preserve existing data. */
+ }
+
+ /* TODO(haberman): ASAN unpoison. */
+
+ a->bytes_allocated += size;
+ return ret;
+}
+
+/* Public Arena API ***********************************************************/
+
+void upb_arena_init(upb_arena *a) {
+ a->alloc.func = &upb_arena_doalloc;
+ a->block_alloc = &upb_alloc_global;
+ a->bytes_allocated = 0;
+ a->next_block_size = 256;
+ a->max_block_size = 16384;
+ a->cleanup_head = NULL;
+ a->block_head = NULL;
+}
+
+void upb_arena_init2(upb_arena *a, void *mem, size_t size, upb_alloc *alloc) {
+ upb_arena_init(a);
+
+ if (size > sizeof(mem_block)) {
+ upb_arena_addblock(a, mem, size, false);
+ }
+
+ if (alloc) {
+ a->block_alloc = alloc;
+ }
+}
+
+void upb_arena_uninit(upb_arena *a) {
+ cleanup_ent *ent = a->cleanup_head;
+ mem_block *block = a->block_head;
+
+ while (ent) {
+ ent->cleanup(ent->ud);
+ ent = ent->next;
+ }
+
+ /* Must do this after running cleanup functions, because this will delete
+ * the memory we store our cleanup entries in! */
+ while (block) {
+ mem_block *next = block->next;
+
+ if (block->owned) {
+ upb_free(a->block_alloc, block);
+ }
+
+ block = next;
+ }
+
+ /* Protect against multiple-uninit. */
+ a->cleanup_head = NULL;
+ a->block_head = NULL;
+}
+
+bool upb_arena_addcleanup(upb_arena *a, upb_cleanup_func *func, void *ud) {
+ cleanup_ent *ent = upb_malloc(&a->alloc, sizeof(cleanup_ent));
+ if (!ent) {
+ return false; /* Out of memory. */
+ }
+
+ ent->cleanup = func;
+ ent->ud = ud;
+ ent->next = a->cleanup_head;
+ a->cleanup_head = ent;
+
+ return true;
+}
+
+size_t upb_arena_bytesallocated(const upb_arena *a) {
+ return a->bytes_allocated;
+}
+
+
+/* Standard error functions ***************************************************/
+
+static bool default_err(void *ud, const upb_status *status) {
+ UPB_UNUSED(ud);
+ UPB_UNUSED(status);
+ return false;
+}
+
+static bool write_err_to(void *ud, const upb_status *status) {
+ upb_status *copy_to = ud;
+ upb_status_copy(copy_to, status);
+ return false;
+}
+
+
+/* upb_env ********************************************************************/
+
+void upb_env_initonly(upb_env *e) {
+ e->ok_ = true;
+ e->error_func_ = &default_err;
+ e->error_ud_ = NULL;
+}
+
+void upb_env_init(upb_env *e) {
+ upb_arena_init(&e->arena_);
+ upb_env_initonly(e);
+}
+
+void upb_env_init2(upb_env *e, void *mem, size_t n, upb_alloc *alloc) {
+ upb_arena_init2(&e->arena_, mem, n, alloc);
+ upb_env_initonly(e);
+}
+
+void upb_env_uninit(upb_env *e) {
+ upb_arena_uninit(&e->arena_);
+}
+
+void upb_env_seterrorfunc(upb_env *e, upb_error_func *func, void *ud) {
+ e->error_func_ = func;
+ e->error_ud_ = ud;
+}
+
+void upb_env_reporterrorsto(upb_env *e, upb_status *s) {
+ e->error_func_ = &write_err_to;
+ e->error_ud_ = s;
+}
+
+bool upb_env_reporterror(upb_env *e, const upb_status *status) {
+ e->ok_ = false;
+ return e->error_func_(e->error_ud_, status);
+}
+
+void *upb_env_malloc(upb_env *e, size_t size) {
+ return upb_malloc(&e->arena_.alloc, size);
+}
+
+void *upb_env_realloc(upb_env *e, void *ptr, size_t oldsize, size_t size) {
+ return upb_realloc(&e->arena_.alloc, ptr, oldsize, size);
+}
+
+void upb_env_free(upb_env *e, void *ptr) {
+ upb_free(&e->arena_.alloc, ptr);
+}
+
+bool upb_env_addcleanup(upb_env *e, upb_cleanup_func *func, void *ud) {
+ return upb_arena_addcleanup(&e->arena_, func, ud);
+}
+
+size_t upb_env_bytesallocated(const upb_env *e) {
+ return upb_arena_bytesallocated(&e->arena_);
+}
+/* This file was generated by upbc (the upb compiler) from the input
+ * file:
+ *
+ * upb/descriptor/descriptor.proto
+ *
+ * Do not edit -- your changes will be discarded when the file is
+ * regenerated. */
+
+
+static const upb_msgdef msgs[22];
+static const upb_fielddef fields[106];
+static const upb_enumdef enums[5];
+static const upb_tabent strentries[236];
+static const upb_tabent intentries[18];
+static const upb_tabval arrays[186];
+
+#ifdef UPB_DEBUG_REFS
+static upb_inttable reftables[266];
+#endif
+
+static const upb_msgdef msgs[22] = {
+ UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 40, 8, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[0], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[0]), false, UPB_SYNTAX_PROTO2, &reftables[0], &reftables[1]),
+ UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 4, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[11], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[16]), false, UPB_SYNTAX_PROTO2, &reftables[2], &reftables[3]),
+ UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ReservedRange", 4, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[14], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[20]), false, UPB_SYNTAX_PROTO2, &reftables[4], &reftables[5]),
+ UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 11, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[17], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[24]), false, UPB_SYNTAX_PROTO2, &reftables[6], &reftables[7]),
+ UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 8, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[0], &arrays[21], 4, 2), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[28]), false, UPB_SYNTAX_PROTO2, &reftables[8], &reftables[9]),
+ UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 8, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[25], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[32]), false, UPB_SYNTAX_PROTO2, &reftables[10], &reftables[11]),
+ UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 7, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[2], &arrays[29], 2, 1), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[36]), false, UPB_SYNTAX_PROTO2, &reftables[12], &reftables[13]),
+ UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 23, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[31], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[40]), false, UPB_SYNTAX_PROTO2, &reftables[14], &reftables[15]),
+ UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 12, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[4], &arrays[42], 11, 6), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[56]), false, UPB_SYNTAX_PROTO2, &reftables[16], &reftables[17]),
+ UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 42, 6, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[53], 13, 12), UPB_STRTABLE_INIT(12, 15, UPB_CTYPE_PTR, 4, &strentries[72]), false, UPB_SYNTAX_PROTO2, &reftables[18], &reftables[19]),
+ UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 6, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[66], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[88]), false, UPB_SYNTAX_PROTO2, &reftables[20], &reftables[21]),
+ UPB_MSGDEF_INIT("google.protobuf.FileOptions", 34, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[68], 41, 16), UPB_STRTABLE_INIT(17, 31, UPB_CTYPE_PTR, 5, &strentries[92]), false, UPB_SYNTAX_PROTO2, &reftables[22], &reftables[23]),
+ UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 10, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[8], &arrays[109], 8, 4), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[124]), false, UPB_SYNTAX_PROTO2, &reftables[24], &reftables[25]),
+ UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 15, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[117], 7, 6), UPB_STRTABLE_INIT(6, 7, UPB_CTYPE_PTR, 3, &strentries[132]), false, UPB_SYNTAX_PROTO2, &reftables[26], &reftables[27]),
+ UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 7, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[10], &arrays[124], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[140]), false, UPB_SYNTAX_PROTO2, &reftables[28], &reftables[29]),
+ UPB_MSGDEF_INIT("google.protobuf.OneofDescriptorProto", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[125], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[144]), false, UPB_SYNTAX_PROTO2, &reftables[30], &reftables[31]),
+ UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 11, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[127], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[148]), false, UPB_SYNTAX_PROTO2, &reftables[32], &reftables[33]),
+ UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 7, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[14], &arrays[131], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[152]), false, UPB_SYNTAX_PROTO2, &reftables[34], &reftables[35]),
+ UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 6, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[132], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[156]), false, UPB_SYNTAX_PROTO2, &reftables[36], &reftables[37]),
+ UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 19, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[134], 7, 5), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[160]), false, UPB_SYNTAX_PROTO2, &reftables[38], &reftables[39]),
+ UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 18, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[141], 9, 7), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[168]), false, UPB_SYNTAX_PROTO2, &reftables[40], &reftables[41]),
+ UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 6, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[150], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[184]), false, UPB_SYNTAX_PROTO2, &reftables[42], &reftables[43]),
+};
+
+static const upb_fielddef fields[106] = {
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "aggregate_value", 8, &msgs[20], NULL, 15, 6, {0},&reftables[44], &reftables[45]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "allow_alias", 2, &msgs[4], NULL, 6, 1, {0},&reftables[46], &reftables[47]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "cc_enable_arenas", 31, &msgs[11], NULL, 23, 12, {0},&reftables[48], &reftables[49]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "cc_generic_services", 16, &msgs[11], NULL, 17, 6, {0},&reftables[50], &reftables[51]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "client_streaming", 5, &msgs[13], NULL, 13, 4, {0},&reftables[52], &reftables[53]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "csharp_namespace", 37, &msgs[11], NULL, 27, 14, {0},&reftables[54], &reftables[55]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "ctype", 1, &msgs[8], (const upb_def*)(&enums[2]), 6, 1, {0},&reftables[56], &reftables[57]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "default_value", 7, &msgs[7], NULL, 16, 7, {0},&reftables[58], &reftables[59]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "dependency", 3, &msgs[9], NULL, 30, 8, {0},&reftables[60], &reftables[61]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 3, &msgs[8], NULL, 8, 3, {0},&reftables[62], &reftables[63]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 33, &msgs[14], NULL, 6, 1, {0},&reftables[64], &reftables[65]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 3, &msgs[12], NULL, 8, 3, {0},&reftables[66], &reftables[67]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 23, &msgs[11], NULL, 21, 10, {0},&reftables[68], &reftables[69]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 1, &msgs[6], NULL, 6, 1, {0},&reftables[70], &reftables[71]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 3, &msgs[4], NULL, 7, 2, {0},&reftables[72], &reftables[73]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 33, &msgs[17], NULL, 6, 1, {0},&reftables[74], &reftables[75]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_DOUBLE, 0, false, false, false, false, "double_value", 6, &msgs[20], NULL, 11, 4, {0},&reftables[76], &reftables[77]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "end", 2, &msgs[2], NULL, 3, 1, {0},&reftables[78], &reftables[79]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "end", 2, &msgs[1], NULL, 3, 1, {0},&reftables[80], &reftables[81]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "enum_type", 5, &msgs[9], (const upb_def*)(&msgs[3]), 13, 1, {0},&reftables[82], &reftables[83]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "enum_type", 4, &msgs[0], (const upb_def*)(&msgs[3]), 18, 2, {0},&reftables[84], &reftables[85]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "extendee", 2, &msgs[7], NULL, 7, 2, {0},&reftables[86], &reftables[87]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension", 6, &msgs[0], (const upb_def*)(&msgs[7]), 24, 4, {0},&reftables[88], &reftables[89]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension", 7, &msgs[9], (const upb_def*)(&msgs[7]), 19, 3, {0},&reftables[90], &reftables[91]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension_range", 5, &msgs[0], (const upb_def*)(&msgs[1]), 21, 3, {0},&reftables[92], &reftables[93]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "field", 2, &msgs[0], (const upb_def*)(&msgs[7]), 12, 0, {0},&reftables[94], &reftables[95]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "file", 1, &msgs[10], (const upb_def*)(&msgs[9]), 5, 0, {0},&reftables[96], &reftables[97]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "go_package", 11, &msgs[11], NULL, 14, 5, {0},&reftables[98], &reftables[99]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "identifier_value", 3, &msgs[20], NULL, 6, 1, {0},&reftables[100], &reftables[101]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "input_type", 2, &msgs[13], NULL, 7, 2, {0},&reftables[102], &reftables[103]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REQUIRED, UPB_TYPE_BOOL, 0, false, false, false, false, "is_extension", 2, &msgs[21], NULL, 5, 1, {0},&reftables[104], &reftables[105]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_generate_equals_and_hash", 20, &msgs[11], NULL, 20, 9, {0},&reftables[106], &reftables[107]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_generic_services", 17, &msgs[11], NULL, 18, 7, {0},&reftables[108], &reftables[109]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_multiple_files", 10, &msgs[11], NULL, 13, 4, {0},&reftables[110], &reftables[111]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "java_outer_classname", 8, &msgs[11], NULL, 9, 2, {0},&reftables[112], &reftables[113]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "java_package", 1, &msgs[11], NULL, 6, 1, {0},&reftables[114], &reftables[115]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_string_check_utf8", 27, &msgs[11], NULL, 22, 11, {0},&reftables[116], &reftables[117]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "javanano_use_deprecated_package", 38, &msgs[11], NULL, 30, 15, {0},&reftables[118], &reftables[119]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "json_name", 10, &msgs[7], NULL, 20, 9, {0},&reftables[120], &reftables[121]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "jstype", 6, &msgs[8], (const upb_def*)(&enums[3]), 10, 5, {0},&reftables[122], &reftables[123]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "label", 4, &msgs[7], (const upb_def*)(&enums[0]), 11, 4, {0},&reftables[124], &reftables[125]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "lazy", 5, &msgs[8], NULL, 9, 4, {0},&reftables[126], &reftables[127]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "leading_comments", 3, &msgs[19], NULL, 8, 2, {0},&reftables[128], &reftables[129]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "leading_detached_comments", 6, &msgs[19], NULL, 16, 4, {0},&reftables[130], &reftables[131]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "location", 1, &msgs[18], (const upb_def*)(&msgs[19]), 5, 0, {0},&reftables[132], &reftables[133]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "map_entry", 7, &msgs[12], NULL, 9, 4, {0},&reftables[134], &reftables[135]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "message_set_wire_format", 1, &msgs[12], NULL, 6, 1, {0},&reftables[136], &reftables[137]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "message_type", 4, &msgs[9], (const upb_def*)(&msgs[0]), 10, 0, {0},&reftables[138], &reftables[139]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "method", 2, &msgs[16], (const upb_def*)(&msgs[13]), 6, 0, {0},&reftables[140], &reftables[141]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "name", 2, &msgs[20], (const upb_def*)(&msgs[21]), 5, 0, {0},&reftables[142], &reftables[143]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[0], NULL, 32, 8, {0},&reftables[144], &reftables[145]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[5], NULL, 4, 1, {0},&reftables[146], &reftables[147]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[13], NULL, 4, 1, {0},&reftables[148], &reftables[149]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[16], NULL, 8, 2, {0},&reftables[150], &reftables[151]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[3], NULL, 8, 2, {0},&reftables[152], &reftables[153]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[15], NULL, 2, 0, {0},&reftables[154], &reftables[155]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[7], NULL, 4, 1, {0},&reftables[156], &reftables[157]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[9], NULL, 22, 6, {0},&reftables[158], &reftables[159]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REQUIRED, UPB_TYPE_STRING, 0, false, false, false, false, "name_part", 1, &msgs[21], NULL, 2, 0, {0},&reftables[160], &reftables[161]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT64, UPB_INTFMT_VARIABLE, false, false, false, false, "negative_int_value", 5, &msgs[20], NULL, 10, 3, {0},&reftables[162], &reftables[163]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "nested_type", 3, &msgs[0], (const upb_def*)(&msgs[0]), 15, 1, {0},&reftables[164], &reftables[165]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "no_standard_descriptor_accessor", 2, &msgs[12], NULL, 7, 2, {0},&reftables[166], &reftables[167]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "number", 2, &msgs[5], NULL, 7, 2, {0},&reftables[168], &reftables[169]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "number", 3, &msgs[7], NULL, 10, 3, {0},&reftables[170], &reftables[171]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "objc_class_prefix", 36, &msgs[11], NULL, 24, 13, {0},&reftables[172], &reftables[173]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "oneof_decl", 8, &msgs[0], (const upb_def*)(&msgs[15]), 28, 6, {0},&reftables[174], &reftables[175]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "oneof_index", 9, &msgs[7], NULL, 19, 8, {0},&reftables[176], &reftables[177]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "optimize_for", 9, &msgs[11], (const upb_def*)(&enums[4]), 12, 3, {0},&reftables[178], &reftables[179]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 8, &msgs[9], (const upb_def*)(&msgs[11]), 20, 4, {0},&reftables[180], &reftables[181]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 7, &msgs[0], (const upb_def*)(&msgs[12]), 25, 5, {0},&reftables[182], &reftables[183]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 4, &msgs[13], (const upb_def*)(&msgs[14]), 3, 0, {0},&reftables[184], &reftables[185]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 8, &msgs[7], (const upb_def*)(&msgs[8]), 3, 0, {0},&reftables[186], &reftables[187]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[5], (const upb_def*)(&msgs[6]), 3, 0, {0},&reftables[188], &reftables[189]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[16], (const upb_def*)(&msgs[17]), 7, 1, {0},&reftables[190], &reftables[191]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[3], (const upb_def*)(&msgs[4]), 7, 1, {0},&reftables[192], &reftables[193]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "output_type", 3, &msgs[13], NULL, 10, 3, {0},&reftables[194], &reftables[195]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "package", 2, &msgs[9], NULL, 25, 7, {0},&reftables[196], &reftables[197]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "packed", 2, &msgs[8], NULL, 7, 2, {0},&reftables[198], &reftables[199]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, true, "path", 1, &msgs[19], NULL, 4, 0, {0},&reftables[200], &reftables[201]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "php_class_prefix", 40, &msgs[11], NULL, 31, 16, {0},&reftables[202], &reftables[203]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_UINT64, UPB_INTFMT_VARIABLE, false, false, false, false, "positive_int_value", 4, &msgs[20], NULL, 9, 2, {0},&reftables[204], &reftables[205]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "public_dependency", 10, &msgs[9], NULL, 35, 9, {0},&reftables[206], &reftables[207]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "py_generic_services", 18, &msgs[11], NULL, 19, 8, {0},&reftables[208], &reftables[209]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "reserved_name", 10, &msgs[0], NULL, 37, 9, {0},&reftables[210], &reftables[211]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "reserved_range", 9, &msgs[0], (const upb_def*)(&msgs[2]), 31, 7, {0},&reftables[212], &reftables[213]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "server_streaming", 6, &msgs[13], NULL, 14, 5, {0},&reftables[214], &reftables[215]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "service", 6, &msgs[9], (const upb_def*)(&msgs[16]), 16, 2, {0},&reftables[216], &reftables[217]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "source_code_info", 9, &msgs[9], (const upb_def*)(&msgs[18]), 21, 5, {0},&reftables[218], &reftables[219]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, true, "span", 2, &msgs[19], NULL, 7, 1, {0},&reftables[220], &reftables[221]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "start", 1, &msgs[2], NULL, 2, 0, {0},&reftables[222], &reftables[223]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "start", 1, &msgs[1], NULL, 2, 0, {0},&reftables[224], &reftables[225]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BYTES, 0, false, false, false, false, "string_value", 7, &msgs[20], NULL, 12, 5, {0},&reftables[226], &reftables[227]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "syntax", 12, &msgs[9], NULL, 39, 11, {0},&reftables[228], &reftables[229]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "trailing_comments", 4, &msgs[19], NULL, 11, 3, {0},&reftables[230], &reftables[231]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "type", 5, &msgs[7], (const upb_def*)(&enums[1]), 12, 5, {0},&reftables[232], &reftables[233]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "type_name", 6, &msgs[7], NULL, 13, 6, {0},&reftables[234], &reftables[235]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[14], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[236], &reftables[237]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[12], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[238], &reftables[239]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[17], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[240], &reftables[241]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[8], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[242], &reftables[243]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[11], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[244], &reftables[245]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[6], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[246], &reftables[247]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[4], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[248], &reftables[249]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "value", 2, &msgs[3], (const upb_def*)(&msgs[5]), 6, 0, {0},&reftables[250], &reftables[251]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "weak", 10, &msgs[8], NULL, 11, 6, {0},&reftables[252], &reftables[253]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "weak_dependency", 11, &msgs[9], NULL, 38, 10, {0},&reftables[254], &reftables[255]),
+};
+
+static const upb_enumdef enums[5] = {
+ UPB_ENUMDEF_INIT("google.protobuf.FieldDescriptorProto.Label", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[188]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[153], 4, 3), 0, &reftables[256], &reftables[257]),
+ UPB_ENUMDEF_INIT("google.protobuf.FieldDescriptorProto.Type", UPB_STRTABLE_INIT(18, 31, UPB_CTYPE_INT32, 5, &strentries[192]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[157], 19, 18), 0, &reftables[258], &reftables[259]),
+ UPB_ENUMDEF_INIT("google.protobuf.FieldOptions.CType", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[224]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[176], 3, 3), 0, &reftables[260], &reftables[261]),
+ UPB_ENUMDEF_INIT("google.protobuf.FieldOptions.JSType", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[228]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[179], 3, 3), 0, &reftables[262], &reftables[263]),
+ UPB_ENUMDEF_INIT("google.protobuf.FileOptions.OptimizeMode", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[232]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[182], 4, 3), 0, &reftables[264], &reftables[265]),
+};
+
+static const upb_tabent strentries[236] = {
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR_INIT(&fields[22]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "reserved_name"), UPB_TABVALUE_PTR_INIT(&fields[83]), NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[50]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "field"), UPB_TABVALUE_PTR_INIT(&fields[25]), &strentries[12]},
+ {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "extension_range"), UPB_TABVALUE_PTR_INIT(&fields[24]), &strentries[14]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "nested_type"), UPB_TABVALUE_PTR_INIT(&fields[60]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "reserved_range"), UPB_TABVALUE_PTR_INIT(&fields[84]), NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[69]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "oneof_decl"), UPB_TABVALUE_PTR_INIT(&fields[65]), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "enum_type"), UPB_TABVALUE_PTR_INIT(&fields[20]), &strentries[13]},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "start"), UPB_TABVALUE_PTR_INIT(&fields[90]), NULL},
+ {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "end"), UPB_TABVALUE_PTR_INIT(&fields[18]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "start"), UPB_TABVALUE_PTR_INIT(&fields[89]), NULL},
+ {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "end"), UPB_TABVALUE_PTR_INIT(&fields[17]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "value"), UPB_TABVALUE_PTR_INIT(&fields[103]), NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[74]), NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[54]), &strentries[26]},
+ {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[102]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[14]), NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "allow_alias"), UPB_TABVALUE_PTR_INIT(&fields[1]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "number"), UPB_TABVALUE_PTR_INIT(&fields[62]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[72]), NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[51]), &strentries[34]},
+ {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[101]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[13]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "oneof_index"), UPB_TABVALUE_PTR_INIT(&fields[66]), NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "label"), UPB_TABVALUE_PTR_INIT(&fields[40]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[56]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "number"), UPB_TABVALUE_PTR_INIT(&fields[63]), &strentries[53]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\010", "\000", "\000", "\000", "extendee"), UPB_TABVALUE_PTR_INIT(&fields[21]), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "type_name"), UPB_TABVALUE_PTR_INIT(&fields[95]), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "json_name"), UPB_TABVALUE_PTR_INIT(&fields[38]), NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "type"), UPB_TABVALUE_PTR_INIT(&fields[94]), &strentries[50]},
+ {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "default_value"), UPB_TABVALUE_PTR_INIT(&fields[7]), NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[71]), NULL},
+ {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[99]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "weak"), UPB_TABVALUE_PTR_INIT(&fields[104]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "packed"), UPB_TABVALUE_PTR_INIT(&fields[77]), NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "lazy"), UPB_TABVALUE_PTR_INIT(&fields[41]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "ctype"), UPB_TABVALUE_PTR_INIT(&fields[6]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "jstype"), UPB_TABVALUE_PTR_INIT(&fields[39]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[9]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR_INIT(&fields[23]), NULL},
+ {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "weak_dependency"), UPB_TABVALUE_PTR_INIT(&fields[105]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[57]), NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "service"), UPB_TABVALUE_PTR_INIT(&fields[86]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "source_code_info"), UPB_TABVALUE_PTR_INIT(&fields[87]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "syntax"), UPB_TABVALUE_PTR_INIT(&fields[92]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "dependency"), UPB_TABVALUE_PTR_INIT(&fields[8]), NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "message_type"), UPB_TABVALUE_PTR_INIT(&fields[47]), NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "package"), UPB_TABVALUE_PTR_INIT(&fields[76]), NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[68]), &strentries[86]},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "enum_type"), UPB_TABVALUE_PTR_INIT(&fields[19]), NULL},
+ {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "public_dependency"), UPB_TABVALUE_PTR_INIT(&fields[81]), &strentries[85]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "file"), UPB_TABVALUE_PTR_INIT(&fields[26]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "cc_generic_services"), UPB_TABVALUE_PTR_INIT(&fields[3]), NULL},
+ {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "csharp_namespace"), UPB_TABVALUE_PTR_INIT(&fields[5]), &strentries[116]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "go_package"), UPB_TABVALUE_PTR_INIT(&fields[27]), NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "java_package"), UPB_TABVALUE_PTR_INIT(&fields[35]), &strentries[120]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "java_outer_classname"), UPB_TABVALUE_PTR_INIT(&fields[34]), NULL},
+ {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[100]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "java_multiple_files"), UPB_TABVALUE_PTR_INIT(&fields[33]), &strentries[117]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\025", "\000", "\000", "\000", "java_generic_services"), UPB_TABVALUE_PTR_INIT(&fields[32]), &strentries[118]},
+ {UPB_TABKEY_STR("\035", "\000", "\000", "\000", "java_generate_equals_and_hash"), UPB_TABVALUE_PTR_INIT(&fields[31]), NULL},
+ {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "php_class_prefix"), UPB_TABVALUE_PTR_INIT(&fields[79]), NULL},
+ {UPB_TABKEY_STR("\037", "\000", "\000", "\000", "javanano_use_deprecated_package"), UPB_TABVALUE_PTR_INIT(&fields[37]), &strentries[123]},
+ {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "py_generic_services"), UPB_TABVALUE_PTR_INIT(&fields[82]), NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "optimize_for"), UPB_TABVALUE_PTR_INIT(&fields[67]), NULL},
+ {UPB_TABKEY_STR("\026", "\000", "\000", "\000", "java_string_check_utf8"), UPB_TABVALUE_PTR_INIT(&fields[36]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[12]), &strentries[119]},
+ {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "objc_class_prefix"), UPB_TABVALUE_PTR_INIT(&fields[64]), NULL},
+ {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "cc_enable_arenas"), UPB_TABVALUE_PTR_INIT(&fields[2]), NULL},
+ {UPB_TABKEY_STR("\027", "\000", "\000", "\000", "message_set_wire_format"), UPB_TABVALUE_PTR_INIT(&fields[46]), &strentries[128]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[97]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[11]), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "map_entry"), UPB_TABVALUE_PTR_INIT(&fields[45]), NULL},
+ {UPB_TABKEY_STR("\037", "\000", "\000", "\000", "no_standard_descriptor_accessor"), UPB_TABVALUE_PTR_INIT(&fields[61]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "client_streaming"), UPB_TABVALUE_PTR_INIT(&fields[4]), NULL},
+ {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "server_streaming"), UPB_TABVALUE_PTR_INIT(&fields[85]), NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[52]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "input_type"), UPB_TABVALUE_PTR_INIT(&fields[29]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "output_type"), UPB_TABVALUE_PTR_INIT(&fields[75]), NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[70]), NULL},
+ {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[96]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[10]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[55]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[73]), &strentries[150]},
+ {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "method"), UPB_TABVALUE_PTR_INIT(&fields[48]), NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[53]), &strentries[149]},
+ {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[98]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[15]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\010", "\000", "\000", "\000", "location"), UPB_TABVALUE_PTR_INIT(&fields[44]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "span"), UPB_TABVALUE_PTR_INIT(&fields[88]), &strentries[167]},
+ {UPB_TABKEY_STR("\031", "\000", "\000", "\000", "leading_detached_comments"), UPB_TABVALUE_PTR_INIT(&fields[43]), &strentries[165]},
+ {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "trailing_comments"), UPB_TABVALUE_PTR_INIT(&fields[93]), NULL},
+ {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "leading_comments"), UPB_TABVALUE_PTR_INIT(&fields[42]), &strentries[164]},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "path"), UPB_TABVALUE_PTR_INIT(&fields[78]), NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "double_value"), UPB_TABVALUE_PTR_INIT(&fields[16]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[49]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\022", "\000", "\000", "\000", "negative_int_value"), UPB_TABVALUE_PTR_INIT(&fields[59]), NULL},
+ {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "aggregate_value"), UPB_TABVALUE_PTR_INIT(&fields[0]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\022", "\000", "\000", "\000", "positive_int_value"), UPB_TABVALUE_PTR_INIT(&fields[80]), NULL},
+ {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "identifier_value"), UPB_TABVALUE_PTR_INIT(&fields[28]), NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "string_value"), UPB_TABVALUE_PTR_INIT(&fields[91]), &strentries[182]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "is_extension"), UPB_TABVALUE_PTR_INIT(&fields[30]), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "name_part"), UPB_TABVALUE_PTR_INIT(&fields[58]), NULL},
+ {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_REQUIRED"), UPB_TABVALUE_INT_INIT(2), &strentries[190]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_REPEATED"), UPB_TABVALUE_INT_INIT(3), NULL},
+ {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_OPTIONAL"), UPB_TABVALUE_INT_INIT(1), NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_FIXED64"), UPB_TABVALUE_INT_INIT(6), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_STRING"), UPB_TABVALUE_INT_INIT(9), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_FLOAT"), UPB_TABVALUE_INT_INIT(2), &strentries[221]},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_DOUBLE"), UPB_TABVALUE_INT_INIT(1), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_INT32"), UPB_TABVALUE_INT_INIT(5), NULL},
+ {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "TYPE_SFIXED32"), UPB_TABVALUE_INT_INIT(15), NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_FIXED32"), UPB_TABVALUE_INT_INIT(7), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_MESSAGE"), UPB_TABVALUE_INT_INIT(11), &strentries[222]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_INT64"), UPB_TABVALUE_INT_INIT(3), &strentries[219]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "TYPE_ENUM"), UPB_TABVALUE_INT_INIT(14), NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_UINT32"), UPB_TABVALUE_INT_INIT(13), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_UINT64"), UPB_TABVALUE_INT_INIT(4), &strentries[218]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "TYPE_SFIXED64"), UPB_TABVALUE_INT_INIT(16), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_BYTES"), UPB_TABVALUE_INT_INIT(12), NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_SINT64"), UPB_TABVALUE_INT_INIT(18), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "TYPE_BOOL"), UPB_TABVALUE_INT_INIT(8), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_GROUP"), UPB_TABVALUE_INT_INIT(10), NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_SINT32"), UPB_TABVALUE_INT_INIT(17), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "CORD"), UPB_TABVALUE_INT_INIT(1), NULL},
+ {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "STRING"), UPB_TABVALUE_INT_INIT(0), &strentries[225]},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "STRING_PIECE"), UPB_TABVALUE_INT_INIT(2), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "JS_NORMAL"), UPB_TABVALUE_INT_INIT(0), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "JS_NUMBER"), UPB_TABVALUE_INT_INIT(2), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "JS_STRING"), UPB_TABVALUE_INT_INIT(1), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "CODE_SIZE"), UPB_TABVALUE_INT_INIT(2), NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "SPEED"), UPB_TABVALUE_INT_INIT(1), &strentries[235]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "LITE_RUNTIME"), UPB_TABVALUE_INT_INIT(3), NULL},
+};
+
+static const upb_tabent intentries[18] = {
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[102]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[101]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[99]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[100]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[97]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(33), UPB_TABVALUE_PTR_INIT(&fields[10]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[96]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(33), UPB_TABVALUE_PTR_INIT(&fields[15]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[98]), NULL},
+};
+
+static const upb_tabval arrays[186] = {
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[50]),
+ UPB_TABVALUE_PTR_INIT(&fields[25]),
+ UPB_TABVALUE_PTR_INIT(&fields[60]),
+ UPB_TABVALUE_PTR_INIT(&fields[20]),
+ UPB_TABVALUE_PTR_INIT(&fields[24]),
+ UPB_TABVALUE_PTR_INIT(&fields[22]),
+ UPB_TABVALUE_PTR_INIT(&fields[69]),
+ UPB_TABVALUE_PTR_INIT(&fields[65]),
+ UPB_TABVALUE_PTR_INIT(&fields[84]),
+ UPB_TABVALUE_PTR_INIT(&fields[83]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[90]),
+ UPB_TABVALUE_PTR_INIT(&fields[18]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[89]),
+ UPB_TABVALUE_PTR_INIT(&fields[17]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[54]),
+ UPB_TABVALUE_PTR_INIT(&fields[103]),
+ UPB_TABVALUE_PTR_INIT(&fields[74]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[1]),
+ UPB_TABVALUE_PTR_INIT(&fields[14]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[51]),
+ UPB_TABVALUE_PTR_INIT(&fields[62]),
+ UPB_TABVALUE_PTR_INIT(&fields[72]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[13]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[56]),
+ UPB_TABVALUE_PTR_INIT(&fields[21]),
+ UPB_TABVALUE_PTR_INIT(&fields[63]),
+ UPB_TABVALUE_PTR_INIT(&fields[40]),
+ UPB_TABVALUE_PTR_INIT(&fields[94]),
+ UPB_TABVALUE_PTR_INIT(&fields[95]),
+ UPB_TABVALUE_PTR_INIT(&fields[7]),
+ UPB_TABVALUE_PTR_INIT(&fields[71]),
+ UPB_TABVALUE_PTR_INIT(&fields[66]),
+ UPB_TABVALUE_PTR_INIT(&fields[38]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[6]),
+ UPB_TABVALUE_PTR_INIT(&fields[77]),
+ UPB_TABVALUE_PTR_INIT(&fields[9]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[41]),
+ UPB_TABVALUE_PTR_INIT(&fields[39]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[104]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[57]),
+ UPB_TABVALUE_PTR_INIT(&fields[76]),
+ UPB_TABVALUE_PTR_INIT(&fields[8]),
+ UPB_TABVALUE_PTR_INIT(&fields[47]),
+ UPB_TABVALUE_PTR_INIT(&fields[19]),
+ UPB_TABVALUE_PTR_INIT(&fields[86]),
+ UPB_TABVALUE_PTR_INIT(&fields[23]),
+ UPB_TABVALUE_PTR_INIT(&fields[68]),
+ UPB_TABVALUE_PTR_INIT(&fields[87]),
+ UPB_TABVALUE_PTR_INIT(&fields[81]),
+ UPB_TABVALUE_PTR_INIT(&fields[105]),
+ UPB_TABVALUE_PTR_INIT(&fields[92]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[26]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[35]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[34]),
+ UPB_TABVALUE_PTR_INIT(&fields[67]),
+ UPB_TABVALUE_PTR_INIT(&fields[33]),
+ UPB_TABVALUE_PTR_INIT(&fields[27]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[3]),
+ UPB_TABVALUE_PTR_INIT(&fields[32]),
+ UPB_TABVALUE_PTR_INIT(&fields[82]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[31]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[12]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[36]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[2]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[64]),
+ UPB_TABVALUE_PTR_INIT(&fields[5]),
+ UPB_TABVALUE_PTR_INIT(&fields[37]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[79]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[46]),
+ UPB_TABVALUE_PTR_INIT(&fields[61]),
+ UPB_TABVALUE_PTR_INIT(&fields[11]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[45]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[52]),
+ UPB_TABVALUE_PTR_INIT(&fields[29]),
+ UPB_TABVALUE_PTR_INIT(&fields[75]),
+ UPB_TABVALUE_PTR_INIT(&fields[70]),
+ UPB_TABVALUE_PTR_INIT(&fields[4]),
+ UPB_TABVALUE_PTR_INIT(&fields[85]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[55]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[53]),
+ UPB_TABVALUE_PTR_INIT(&fields[48]),
+ UPB_TABVALUE_PTR_INIT(&fields[73]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[44]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[78]),
+ UPB_TABVALUE_PTR_INIT(&fields[88]),
+ UPB_TABVALUE_PTR_INIT(&fields[42]),
+ UPB_TABVALUE_PTR_INIT(&fields[93]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[43]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[49]),
+ UPB_TABVALUE_PTR_INIT(&fields[28]),
+ UPB_TABVALUE_PTR_INIT(&fields[80]),
+ UPB_TABVALUE_PTR_INIT(&fields[59]),
+ UPB_TABVALUE_PTR_INIT(&fields[16]),
+ UPB_TABVALUE_PTR_INIT(&fields[91]),
+ UPB_TABVALUE_PTR_INIT(&fields[0]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[58]),
+ UPB_TABVALUE_PTR_INIT(&fields[30]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT("LABEL_OPTIONAL"),
+ UPB_TABVALUE_PTR_INIT("LABEL_REQUIRED"),
+ UPB_TABVALUE_PTR_INIT("LABEL_REPEATED"),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT("TYPE_DOUBLE"),
+ UPB_TABVALUE_PTR_INIT("TYPE_FLOAT"),
+ UPB_TABVALUE_PTR_INIT("TYPE_INT64"),
+ UPB_TABVALUE_PTR_INIT("TYPE_UINT64"),
+ UPB_TABVALUE_PTR_INIT("TYPE_INT32"),
+ UPB_TABVALUE_PTR_INIT("TYPE_FIXED64"),
+ UPB_TABVALUE_PTR_INIT("TYPE_FIXED32"),
+ UPB_TABVALUE_PTR_INIT("TYPE_BOOL"),
+ UPB_TABVALUE_PTR_INIT("TYPE_STRING"),
+ UPB_TABVALUE_PTR_INIT("TYPE_GROUP"),
+ UPB_TABVALUE_PTR_INIT("TYPE_MESSAGE"),
+ UPB_TABVALUE_PTR_INIT("TYPE_BYTES"),
+ UPB_TABVALUE_PTR_INIT("TYPE_UINT32"),
+ UPB_TABVALUE_PTR_INIT("TYPE_ENUM"),
+ UPB_TABVALUE_PTR_INIT("TYPE_SFIXED32"),
+ UPB_TABVALUE_PTR_INIT("TYPE_SFIXED64"),
+ UPB_TABVALUE_PTR_INIT("TYPE_SINT32"),
+ UPB_TABVALUE_PTR_INIT("TYPE_SINT64"),
+ UPB_TABVALUE_PTR_INIT("STRING"),
+ UPB_TABVALUE_PTR_INIT("CORD"),
+ UPB_TABVALUE_PTR_INIT("STRING_PIECE"),
+ UPB_TABVALUE_PTR_INIT("JS_NORMAL"),
+ UPB_TABVALUE_PTR_INIT("JS_STRING"),
+ UPB_TABVALUE_PTR_INIT("JS_NUMBER"),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT("SPEED"),
+ UPB_TABVALUE_PTR_INIT("CODE_SIZE"),
+ UPB_TABVALUE_PTR_INIT("LITE_RUNTIME"),
+};
+
+#ifdef UPB_DEBUG_REFS
+static upb_inttable reftables[266] = {
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+};
+#endif
+
+static const upb_msgdef *refm(const upb_msgdef *m, const void *owner) {
+ upb_msgdef_ref(m, owner);
+ return m;
+}
+
+static const upb_enumdef *refe(const upb_enumdef *e, const void *owner) {
+ upb_enumdef_ref(e, owner);
+ return e;
+}
+
+/* Public API. */
+const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_get(const void *owner) { return refm(&msgs[0], owner); }
+const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_get(const void *owner) { return refm(&msgs[1], owner); }
+const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ReservedRange_get(const void *owner) { return refm(&msgs[2], owner); }
+const upb_msgdef *upbdefs_google_protobuf_EnumDescriptorProto_get(const void *owner) { return refm(&msgs[3], owner); }
+const upb_msgdef *upbdefs_google_protobuf_EnumOptions_get(const void *owner) { return refm(&msgs[4], owner); }
+const upb_msgdef *upbdefs_google_protobuf_EnumValueDescriptorProto_get(const void *owner) { return refm(&msgs[5], owner); }
+const upb_msgdef *upbdefs_google_protobuf_EnumValueOptions_get(const void *owner) { return refm(&msgs[6], owner); }
+const upb_msgdef *upbdefs_google_protobuf_FieldDescriptorProto_get(const void *owner) { return refm(&msgs[7], owner); }
+const upb_msgdef *upbdefs_google_protobuf_FieldOptions_get(const void *owner) { return refm(&msgs[8], owner); }
+const upb_msgdef *upbdefs_google_protobuf_FileDescriptorProto_get(const void *owner) { return refm(&msgs[9], owner); }
+const upb_msgdef *upbdefs_google_protobuf_FileDescriptorSet_get(const void *owner) { return refm(&msgs[10], owner); }
+const upb_msgdef *upbdefs_google_protobuf_FileOptions_get(const void *owner) { return refm(&msgs[11], owner); }
+const upb_msgdef *upbdefs_google_protobuf_MessageOptions_get(const void *owner) { return refm(&msgs[12], owner); }
+const upb_msgdef *upbdefs_google_protobuf_MethodDescriptorProto_get(const void *owner) { return refm(&msgs[13], owner); }
+const upb_msgdef *upbdefs_google_protobuf_MethodOptions_get(const void *owner) { return refm(&msgs[14], owner); }
+const upb_msgdef *upbdefs_google_protobuf_OneofDescriptorProto_get(const void *owner) { return refm(&msgs[15], owner); }
+const upb_msgdef *upbdefs_google_protobuf_ServiceDescriptorProto_get(const void *owner) { return refm(&msgs[16], owner); }
+const upb_msgdef *upbdefs_google_protobuf_ServiceOptions_get(const void *owner) { return refm(&msgs[17], owner); }
+const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo_get(const void *owner) { return refm(&msgs[18], owner); }
+const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo_Location_get(const void *owner) { return refm(&msgs[19], owner); }
+const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption_get(const void *owner) { return refm(&msgs[20], owner); }
+const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption_NamePart_get(const void *owner) { return refm(&msgs[21], owner); }
+
+const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Label_get(const void *owner) { return refe(&enums[0], owner); }
+const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Type_get(const void *owner) { return refe(&enums[1], owner); }
+const upb_enumdef *upbdefs_google_protobuf_FieldOptions_CType_get(const void *owner) { return refe(&enums[2], owner); }
+const upb_enumdef *upbdefs_google_protobuf_FieldOptions_JSType_get(const void *owner) { return refe(&enums[3], owner); }
+const upb_enumdef *upbdefs_google_protobuf_FileOptions_OptimizeMode_get(const void *owner) { return refe(&enums[4], owner); }
+/*
+** XXX: The routines in this file that consume a string do not currently
+** support having the string span buffers. In the future, as upb_sink and
+** its buffering/sharing functionality evolve there should be an easy and
+** idiomatic way of correctly handling this case. For now, we accept this
+** limitation since we currently only parse descriptors from single strings.
+*/
+
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* Compares a NULL-terminated string with a non-NULL-terminated string. */
+static bool upb_streq(const char *str, const char *buf, size_t n) {
+ return strlen(str) == n && memcmp(str, buf, n) == 0;
+}
+
+/* We keep a stack of all the messages scopes we are currently in, as well as
+ * the top-level file scope. This is necessary to correctly qualify the
+ * definitions that are contained inside. "name" tracks the name of the
+ * message or package (a bare name -- not qualified by any enclosing scopes). */
+typedef struct {
+ char *name;
+ /* Index of the first def that is under this scope. For msgdefs, the
+ * msgdef itself is at start-1. */
+ int start;
+ uint32_t oneof_start;
+ uint32_t oneof_index;
+} upb_descreader_frame;
+
+/* The maximum number of nested declarations that are allowed, ie.
+ * message Foo {
+ * message Bar {
+ * message Baz {
+ * }
+ * }
+ * }
+ *
+ * This is a resource limit that affects how big our runtime stack can grow.
+ * TODO: make this a runtime-settable property of the Reader instance. */
+#define UPB_MAX_MESSAGE_NESTING 64
+
+struct upb_descreader {
+ upb_sink sink;
+ upb_inttable files;
+ upb_filedef *file; /* The last file in files. */
+ upb_descreader_frame stack[UPB_MAX_MESSAGE_NESTING];
+ int stack_len;
+ upb_inttable oneofs;
+
+ uint32_t number;
+ char *name;
+ bool saw_number;
+ bool saw_name;
+
+ char *default_string;
+
+ upb_fielddef *f;
+};
+
+static char *upb_gstrndup(const char *buf, size_t n) {
+ char *ret = upb_gmalloc(n + 1);
+ if (!ret) return NULL;
+ memcpy(ret, buf, n);
+ ret[n] = '\0';
+ return ret;
+}
+
+/* Returns a newly allocated string that joins input strings together, for
+ * example:
+ * join("Foo.Bar", "Baz") -> "Foo.Bar.Baz"
+ * join("", "Baz") -> "Baz"
+ * Caller owns a ref on the returned string. */
+static char *upb_join(const char *base, const char *name) {
+ if (!base || strlen(base) == 0) {
+ return upb_gstrdup(name);
+ } else {
+ char *ret = upb_gmalloc(strlen(base) + strlen(name) + 2);
+ if (!ret) {
+ return NULL;
+ }
+ ret[0] = '\0';
+ strcat(ret, base);
+ strcat(ret, ".");
+ strcat(ret, name);
+ return ret;
+ }
+}
+
+/* Qualify the defname for all defs starting with offset "start" with "str". */
+static bool upb_descreader_qualify(upb_filedef *f, char *str, int32_t start) {
+ size_t i;
+ for (i = start; i < upb_filedef_defcount(f); i++) {
+ upb_def *def = upb_filedef_mutabledef(f, i);
+ char *name = upb_join(str, upb_def_fullname(def));
+ if (!name) {
+ /* Need better logic here; at this point we've qualified some names but
+ * not others. */
+ return false;
+ }
+ upb_def_setfullname(def, name, NULL);
+ upb_gfree(name);
+ }
+ return true;
+}
+
+
+/* upb_descreader ************************************************************/
+
+static upb_msgdef *upb_descreader_top(upb_descreader *r) {
+ int index;
+ UPB_ASSERT(r->stack_len > 1);
+ index = r->stack[r->stack_len-1].start - 1;
+ UPB_ASSERT(index >= 0);
+ return upb_downcast_msgdef_mutable(upb_filedef_mutabledef(r->file, index));
+}
+
+static upb_def *upb_descreader_last(upb_descreader *r) {
+ return upb_filedef_mutabledef(r->file, upb_filedef_defcount(r->file) - 1);
+}
+
+/* Start/end handlers for FileDescriptorProto and DescriptorProto (the two
+ * entities that have names and can contain sub-definitions. */
+void upb_descreader_startcontainer(upb_descreader *r) {
+ upb_descreader_frame *f = &r->stack[r->stack_len++];
+ f->start = upb_filedef_defcount(r->file);
+ f->oneof_start = upb_inttable_count(&r->oneofs);
+ f->oneof_index = 0;
+ f->name = NULL;
+}
+
+bool upb_descreader_endcontainer(upb_descreader *r) {
+ upb_descreader_frame *f = &r->stack[r->stack_len - 1];
+
+ while (upb_inttable_count(&r->oneofs) > f->oneof_start) {
+ upb_oneofdef *o = upb_value_getptr(upb_inttable_pop(&r->oneofs));
+ bool ok = upb_msgdef_addoneof(upb_descreader_top(r), o, &r->oneofs, NULL);
+ UPB_ASSERT(ok);
+ }
+
+ if (!upb_descreader_qualify(r->file, f->name, f->start)) {
+ return false;
+ }
+ upb_gfree(f->name);
+ f->name = NULL;
+
+ r->stack_len--;
+ return true;
+}
+
+void upb_descreader_setscopename(upb_descreader *r, char *str) {
+ upb_descreader_frame *f = &r->stack[r->stack_len-1];
+ upb_gfree(f->name);
+ f->name = str;
+}
+
+static upb_oneofdef *upb_descreader_getoneof(upb_descreader *r,
+ uint32_t index) {
+ bool found;
+ upb_value val;
+ upb_descreader_frame *f = &r->stack[r->stack_len-1];
+
+ /* DescriptorProto messages can be nested, so we will see the nested messages
+ * between when we see the FieldDescriptorProto and the OneofDescriptorProto.
+ * We need to preserve the oneofs in between these two things. */
+ index += f->oneof_start;
+
+ while (upb_inttable_count(&r->oneofs) <= index) {
+ upb_inttable_push(&r->oneofs, upb_value_ptr(upb_oneofdef_new(&r->oneofs)));
+ }
+
+ found = upb_inttable_lookup(&r->oneofs, index, &val);
+ UPB_ASSERT(found);
+ return upb_value_getptr(val);
+}
+
+/** Handlers for google.protobuf.FileDescriptorSet. ***************************/
+
+static void *fileset_startfile(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+ r->file = upb_filedef_new(&r->files);
+ upb_inttable_push(&r->files, upb_value_ptr(r->file));
+ return r;
+}
+
+/** Handlers for google.protobuf.FileDescriptorProto. *************************/
+
+static bool file_start(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+ upb_descreader_startcontainer(r);
+ return true;
+}
+
+static bool file_end(void *closure, const void *hd, upb_status *status) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(status);
+ return upb_descreader_endcontainer(r);
+}
+
+static size_t file_onname(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ char *name;
+ bool ok;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ name = upb_gstrndup(buf, n);
+ /* XXX: see comment at the top of the file. */
+ ok = upb_filedef_setname(r->file, name, NULL);
+ upb_gfree(name);
+ UPB_ASSERT(ok);
+ return n;
+}
+
+static size_t file_onpackage(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ char *package;
+ bool ok;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ package = upb_gstrndup(buf, n);
+ /* XXX: see comment at the top of the file. */
+ upb_descreader_setscopename(r, package);
+ ok = upb_filedef_setpackage(r->file, package, NULL);
+ UPB_ASSERT(ok);
+ return n;
+}
+
+static size_t file_onphpprefix(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ char *prefix;
+ bool ok;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ prefix = upb_gstrndup(buf, n);
+ ok = upb_filedef_setphpprefix(r->file, prefix, NULL);
+ upb_gfree(prefix);
+ UPB_ASSERT(ok);
+ return n;
+}
+
+static size_t file_onsyntax(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ bool ok;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+ /* XXX: see comment at the top of the file. */
+ if (upb_streq("proto2", buf, n)) {
+ ok = upb_filedef_setsyntax(r->file, UPB_SYNTAX_PROTO2, NULL);
+ } else if (upb_streq("proto3", buf, n)) {
+ ok = upb_filedef_setsyntax(r->file, UPB_SYNTAX_PROTO3, NULL);
+ } else {
+ ok = false;
+ }
+
+ UPB_ASSERT(ok);
+ return n;
+}
+
+static void *file_startmsg(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ upb_msgdef *m = upb_msgdef_new(&m);
+ bool ok = upb_filedef_addmsg(r->file, m, &m, NULL);
+ UPB_UNUSED(hd);
+ UPB_ASSERT(ok);
+ return r;
+}
+
+static void *file_startenum(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ upb_enumdef *e = upb_enumdef_new(&e);
+ bool ok = upb_filedef_addenum(r->file, e, &e, NULL);
+ UPB_UNUSED(hd);
+ UPB_ASSERT(ok);
+ return r;
+}
+
+static void *file_startext(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ bool ok;
+ r->f = upb_fielddef_new(r);
+ ok = upb_filedef_addext(r->file, r->f, r, NULL);
+ UPB_UNUSED(hd);
+ UPB_ASSERT(ok);
+ return r;
+}
+
+/** Handlers for google.protobuf.EnumValueDescriptorProto. *********************/
+
+static bool enumval_startmsg(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+ r->saw_number = false;
+ r->saw_name = false;
+ return true;
+}
+
+static size_t enumval_onname(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+ /* XXX: see comment at the top of the file. */
+ upb_gfree(r->name);
+ r->name = upb_gstrndup(buf, n);
+ r->saw_name = true;
+ return n;
+}
+
+static bool enumval_onnumber(void *closure, const void *hd, int32_t val) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+ r->number = val;
+ r->saw_number = true;
+ return true;
+}
+
+static bool enumval_endmsg(void *closure, const void *hd, upb_status *status) {
+ upb_descreader *r = closure;
+ upb_enumdef *e;
+ UPB_UNUSED(hd);
+
+ if(!r->saw_number || !r->saw_name) {
+ upb_status_seterrmsg(status, "Enum value missing name or number.");
+ return false;
+ }
+ e = upb_downcast_enumdef_mutable(upb_descreader_last(r));
+ upb_enumdef_addval(e, r->name, r->number, status);
+ upb_gfree(r->name);
+ r->name = NULL;
+ return true;
+}
+
+/** Handlers for google.protobuf.EnumDescriptorProto. *************************/
+
+static bool enum_endmsg(void *closure, const void *hd, upb_status *status) {
+ upb_descreader *r = closure;
+ upb_enumdef *e;
+ UPB_UNUSED(hd);
+
+ e = upb_downcast_enumdef_mutable(upb_descreader_last(r));
+ if (upb_def_fullname(upb_descreader_last(r)) == NULL) {
+ upb_status_seterrmsg(status, "Enum had no name.");
+ return false;
+ }
+ if (upb_enumdef_numvals(e) == 0) {
+ upb_status_seterrmsg(status, "Enum had no values.");
+ return false;
+ }
+ return true;
+}
+
+static size_t enum_onname(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ char *fullname = upb_gstrndup(buf, n);
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+ /* XXX: see comment at the top of the file. */
+ upb_def_setfullname(upb_descreader_last(r), fullname, NULL);
+ upb_gfree(fullname);
+ return n;
+}
+
+/** Handlers for google.protobuf.FieldDescriptorProto *************************/
+
+static bool field_startmsg(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+ UPB_ASSERT(r->f);
+ upb_gfree(r->default_string);
+ r->default_string = NULL;
+
+ /* fielddefs default to packed, but descriptors default to non-packed. */
+ upb_fielddef_setpacked(r->f, false);
+ return true;
+}
+
+/* Converts the default value in string "str" into "d". Passes a ref on str.
+ * Returns true on success. */
+static bool parse_default(char *str, upb_fielddef *f) {
+ bool success = true;
+ char *end;
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_INT32: {
+ long val = strtol(str, &end, 0);
+ if (val > INT32_MAX || val < INT32_MIN || errno == ERANGE || *end)
+ success = false;
+ else
+ upb_fielddef_setdefaultint32(f, val);
+ break;
+ }
+ case UPB_TYPE_INT64: {
+ /* XXX: Need to write our own strtoll, since it's not available in c89. */
+ long long val = strtol(str, &end, 0);
+ if (val > INT64_MAX || val < INT64_MIN || errno == ERANGE || *end)
+ success = false;
+ else
+ upb_fielddef_setdefaultint64(f, val);
+ break;
+ }
+ case UPB_TYPE_UINT32: {
+ unsigned long val = strtoul(str, &end, 0);
+ if (val > UINT32_MAX || errno == ERANGE || *end)
+ success = false;
+ else
+ upb_fielddef_setdefaultuint32(f, val);
+ break;
+ }
+ case UPB_TYPE_UINT64: {
+ /* XXX: Need to write our own strtoull, since it's not available in c89. */
+ unsigned long long val = strtoul(str, &end, 0);
+ if (val > UINT64_MAX || errno == ERANGE || *end)
+ success = false;
+ else
+ upb_fielddef_setdefaultuint64(f, val);
+ break;
+ }
+ case UPB_TYPE_DOUBLE: {
+ double val = strtod(str, &end);
+ if (errno == ERANGE || *end)
+ success = false;
+ else
+ upb_fielddef_setdefaultdouble(f, val);
+ break;
+ }
+ case UPB_TYPE_FLOAT: {
+ /* XXX: Need to write our own strtof, since it's not available in c89. */
+ float val = strtod(str, &end);
+ if (errno == ERANGE || *end)
+ success = false;
+ else
+ upb_fielddef_setdefaultfloat(f, val);
+ break;
+ }
+ case UPB_TYPE_BOOL: {
+ if (strcmp(str, "false") == 0)
+ upb_fielddef_setdefaultbool(f, false);
+ else if (strcmp(str, "true") == 0)
+ upb_fielddef_setdefaultbool(f, true);
+ else
+ success = false;
+ break;
+ }
+ default: abort();
+ }
+ return success;
+}
+
+static bool field_endmsg(void *closure, const void *hd, upb_status *status) {
+ upb_descreader *r = closure;
+ upb_fielddef *f = r->f;
+ UPB_UNUSED(hd);
+
+ /* TODO: verify that all required fields were present. */
+ UPB_ASSERT(upb_fielddef_number(f) != 0);
+ UPB_ASSERT(upb_fielddef_name(f) != NULL);
+ UPB_ASSERT((upb_fielddef_subdefname(f) != NULL) == upb_fielddef_hassubdef(f));
+
+ if (r->default_string) {
+ if (upb_fielddef_issubmsg(f)) {
+ upb_status_seterrmsg(status, "Submessages cannot have defaults.");
+ return false;
+ }
+ if (upb_fielddef_isstring(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM) {
+ upb_fielddef_setdefaultcstr(f, r->default_string, NULL);
+ } else {
+ if (r->default_string && !parse_default(r->default_string, f)) {
+ /* We don't worry too much about giving a great error message since the
+ * compiler should have ensured this was correct. */
+ upb_status_seterrmsg(status, "Error converting default value.");
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+static bool field_onlazy(void *closure, const void *hd, bool val) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+
+ upb_fielddef_setlazy(r->f, val);
+ return true;
+}
+
+static bool field_onpacked(void *closure, const void *hd, bool val) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+
+ upb_fielddef_setpacked(r->f, val);
+ return true;
+}
+
+static bool field_ontype(void *closure, const void *hd, int32_t val) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+
+ upb_fielddef_setdescriptortype(r->f, val);
+ return true;
+}
+
+static bool field_onlabel(void *closure, const void *hd, int32_t val) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+
+ upb_fielddef_setlabel(r->f, val);
+ return true;
+}
+
+static bool field_onnumber(void *closure, const void *hd, int32_t val) {
+ upb_descreader *r = closure;
+ bool ok;
+ UPB_UNUSED(hd);
+
+ ok = upb_fielddef_setnumber(r->f, val, NULL);
+ UPB_ASSERT(ok);
+ return true;
+}
+
+static size_t field_onname(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ char *name = upb_gstrndup(buf, n);
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ /* XXX: see comment at the top of the file. */
+ upb_fielddef_setname(r->f, name, NULL);
+ upb_gfree(name);
+ return n;
+}
+
+static size_t field_ontypename(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ char *name = upb_gstrndup(buf, n);
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ /* XXX: see comment at the top of the file. */
+ upb_fielddef_setsubdefname(r->f, name, NULL);
+ upb_gfree(name);
+ return n;
+}
+
+static size_t field_onextendee(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ char *name = upb_gstrndup(buf, n);
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ /* XXX: see comment at the top of the file. */
+ upb_fielddef_setcontainingtypename(r->f, name, NULL);
+ upb_gfree(name);
+ return n;
+}
+
+static size_t field_ondefaultval(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ /* Have to convert from string to the correct type, but we might not know the
+ * type yet, so we save it as a string until the end of the field.
+ * XXX: see comment at the top of the file. */
+ upb_gfree(r->default_string);
+ r->default_string = upb_gstrndup(buf, n);
+ return n;
+}
+
+static bool field_ononeofindex(void *closure, const void *hd, int32_t index) {
+ upb_descreader *r = closure;
+ upb_oneofdef *o = upb_descreader_getoneof(r, index);
+ bool ok = upb_oneofdef_addfield(o, r->f, &r->f, NULL);
+ UPB_UNUSED(hd);
+
+ UPB_ASSERT(ok);
+ return true;
+}
+
+/** Handlers for google.protobuf.OneofDescriptorProto. ************************/
+
+static size_t oneof_name(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ upb_descreader_frame *f = &r->stack[r->stack_len-1];
+ upb_oneofdef *o = upb_descreader_getoneof(r, f->oneof_index++);
+ char *name_null_terminated = upb_gstrndup(buf, n);
+ bool ok = upb_oneofdef_setname(o, name_null_terminated, NULL);
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ UPB_ASSERT(ok);
+ free(name_null_terminated);
+ return n;
+}
+
+/** Handlers for google.protobuf.DescriptorProto ******************************/
+
+static bool msg_start(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+
+ upb_descreader_startcontainer(r);
+ return true;
+}
+
+static bool msg_end(void *closure, const void *hd, upb_status *status) {
+ upb_descreader *r = closure;
+ upb_msgdef *m = upb_descreader_top(r);
+ UPB_UNUSED(hd);
+
+ if(!upb_def_fullname(upb_msgdef_upcast_mutable(m))) {
+ upb_status_seterrmsg(status, "Encountered message with no name.");
+ return false;
+ }
+ return upb_descreader_endcontainer(r);
+}
+
+static size_t msg_name(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ upb_msgdef *m = upb_descreader_top(r);
+ /* XXX: see comment at the top of the file. */
+ char *name = upb_gstrndup(buf, n);
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ upb_def_setfullname(upb_msgdef_upcast_mutable(m), name, NULL);
+ upb_descreader_setscopename(r, name); /* Passes ownership of name. */
+ return n;
+}
+
+static void *msg_startmsg(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ upb_msgdef *m = upb_msgdef_new(&m);
+ bool ok = upb_filedef_addmsg(r->file, m, &m, NULL);
+ UPB_UNUSED(hd);
+ UPB_ASSERT(ok);
+ return r;
+}
+
+static void *msg_startext(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ upb_fielddef *f = upb_fielddef_new(&f);
+ bool ok = upb_filedef_addext(r->file, f, &f, NULL);
+ UPB_UNUSED(hd);
+ UPB_ASSERT(ok);
+ return r;
+}
+
+static void *msg_startfield(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ r->f = upb_fielddef_new(&r->f);
+ /* We can't add the new field to the message until its name/number are
+ * filled in. */
+ UPB_UNUSED(hd);
+ return r;
+}
+
+static bool msg_endfield(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ upb_msgdef *m = upb_descreader_top(r);
+ bool ok;
+ UPB_UNUSED(hd);
+
+ /* Oneof fields are added to the msgdef through their oneof, so don't need to
+ * be added here. */
+ if (upb_fielddef_containingoneof(r->f) == NULL) {
+ ok = upb_msgdef_addfield(m, r->f, &r->f, NULL);
+ UPB_ASSERT(ok);
+ }
+ r->f = NULL;
+ return true;
+}
+
+static bool msg_onmapentry(void *closure, const void *hd, bool mapentry) {
+ upb_descreader *r = closure;
+ upb_msgdef *m = upb_descreader_top(r);
+ UPB_UNUSED(hd);
+
+ upb_msgdef_setmapentry(m, mapentry);
+ r->f = NULL;
+ return true;
+}
+
+
+
+/** Code to register handlers *************************************************/
+
+#define F(msg, field) upbdefs_google_protobuf_ ## msg ## _f_ ## field(m)
+
+static void reghandlers(const void *closure, upb_handlers *h) {
+ const upb_msgdef *m = upb_handlers_msgdef(h);
+ UPB_UNUSED(closure);
+
+ if (upbdefs_google_protobuf_FileDescriptorSet_is(m)) {
+ upb_handlers_setstartsubmsg(h, F(FileDescriptorSet, file),
+ &fileset_startfile, NULL);
+ } else if (upbdefs_google_protobuf_DescriptorProto_is(m)) {
+ upb_handlers_setstartmsg(h, &msg_start, NULL);
+ upb_handlers_setendmsg(h, &msg_end, NULL);
+ upb_handlers_setstring(h, F(DescriptorProto, name), &msg_name, NULL);
+ upb_handlers_setstartsubmsg(h, F(DescriptorProto, extension), &msg_startext,
+ NULL);
+ upb_handlers_setstartsubmsg(h, F(DescriptorProto, nested_type),
+ &msg_startmsg, NULL);
+ upb_handlers_setstartsubmsg(h, F(DescriptorProto, field),
+ &msg_startfield, NULL);
+ upb_handlers_setendsubmsg(h, F(DescriptorProto, field),
+ &msg_endfield, NULL);
+ upb_handlers_setstartsubmsg(h, F(DescriptorProto, enum_type),
+ &file_startenum, NULL);
+ } else if (upbdefs_google_protobuf_FileDescriptorProto_is(m)) {
+ upb_handlers_setstartmsg(h, &file_start, NULL);
+ upb_handlers_setendmsg(h, &file_end, NULL);
+ upb_handlers_setstring(h, F(FileDescriptorProto, name), &file_onname,
+ NULL);
+ upb_handlers_setstring(h, F(FileDescriptorProto, package), &file_onpackage,
+ NULL);
+ upb_handlers_setstring(h, F(FileDescriptorProto, syntax), &file_onsyntax,
+ NULL);
+ upb_handlers_setstartsubmsg(h, F(FileDescriptorProto, message_type),
+ &file_startmsg, NULL);
+ upb_handlers_setstartsubmsg(h, F(FileDescriptorProto, enum_type),
+ &file_startenum, NULL);
+ upb_handlers_setstartsubmsg(h, F(FileDescriptorProto, extension),
+ &file_startext, NULL);
+ } else if (upbdefs_google_protobuf_EnumValueDescriptorProto_is(m)) {
+ upb_handlers_setstartmsg(h, &enumval_startmsg, NULL);
+ upb_handlers_setendmsg(h, &enumval_endmsg, NULL);
+ upb_handlers_setstring(h, F(EnumValueDescriptorProto, name), &enumval_onname, NULL);
+ upb_handlers_setint32(h, F(EnumValueDescriptorProto, number), &enumval_onnumber,
+ NULL);
+ } else if (upbdefs_google_protobuf_EnumDescriptorProto_is(m)) {
+ upb_handlers_setendmsg(h, &enum_endmsg, NULL);
+ upb_handlers_setstring(h, F(EnumDescriptorProto, name), &enum_onname, NULL);
+ } else if (upbdefs_google_protobuf_FieldDescriptorProto_is(m)) {
+ upb_handlers_setstartmsg(h, &field_startmsg, NULL);
+ upb_handlers_setendmsg(h, &field_endmsg, NULL);
+ upb_handlers_setint32(h, F(FieldDescriptorProto, type), &field_ontype,
+ NULL);
+ upb_handlers_setint32(h, F(FieldDescriptorProto, label), &field_onlabel,
+ NULL);
+ upb_handlers_setint32(h, F(FieldDescriptorProto, number), &field_onnumber,
+ NULL);
+ upb_handlers_setstring(h, F(FieldDescriptorProto, name), &field_onname,
+ NULL);
+ upb_handlers_setstring(h, F(FieldDescriptorProto, type_name),
+ &field_ontypename, NULL);
+ upb_handlers_setstring(h, F(FieldDescriptorProto, extendee),
+ &field_onextendee, NULL);
+ upb_handlers_setstring(h, F(FieldDescriptorProto, default_value),
+ &field_ondefaultval, NULL);
+ upb_handlers_setint32(h, F(FieldDescriptorProto, oneof_index),
+ &field_ononeofindex, NULL);
+ } else if (upbdefs_google_protobuf_OneofDescriptorProto_is(m)) {
+ upb_handlers_setstring(h, F(OneofDescriptorProto, name), &oneof_name, NULL);
+ } else if (upbdefs_google_protobuf_FieldOptions_is(m)) {
+ upb_handlers_setbool(h, F(FieldOptions, lazy), &field_onlazy, NULL);
+ upb_handlers_setbool(h, F(FieldOptions, packed), &field_onpacked, NULL);
+ } else if (upbdefs_google_protobuf_MessageOptions_is(m)) {
+ upb_handlers_setbool(h, F(MessageOptions, map_entry), &msg_onmapentry, NULL);
+ } else if (upbdefs_google_protobuf_FileOptions_is(m)) {
+ upb_handlers_setstring(h, F(FileOptions, php_class_prefix),
+ &file_onphpprefix, NULL);
+ }
+
+ UPB_ASSERT(upb_ok(upb_handlers_status(h)));
+}
+
+#undef F
+
+void descreader_cleanup(void *_r) {
+ upb_descreader *r = _r;
+ size_t i;
+
+ for (i = 0; i < upb_descreader_filecount(r); i++) {
+ upb_filedef_unref(upb_descreader_file(r, i), &r->files);
+ }
+
+ upb_gfree(r->name);
+ upb_inttable_uninit(&r->files);
+ upb_inttable_uninit(&r->oneofs);
+ upb_gfree(r->default_string);
+ while (r->stack_len > 0) {
+ upb_descreader_frame *f = &r->stack[--r->stack_len];
+ upb_gfree(f->name);
+ }
+}
+
+
+/* Public API ****************************************************************/
+
+upb_descreader *upb_descreader_create(upb_env *e, const upb_handlers *h) {
+ upb_descreader *r = upb_env_malloc(e, sizeof(upb_descreader));
+ if (!r || !upb_env_addcleanup(e, descreader_cleanup, r)) {
+ return NULL;
+ }
+
+ upb_inttable_init(&r->files, UPB_CTYPE_PTR);
+ upb_inttable_init(&r->oneofs, UPB_CTYPE_PTR);
+ upb_sink_reset(upb_descreader_input(r), h, r);
+ r->stack_len = 0;
+ r->name = NULL;
+ r->default_string = NULL;
+
+ return r;
+}
+
+size_t upb_descreader_filecount(const upb_descreader *r) {
+ return upb_inttable_count(&r->files);
+}
+
+upb_filedef *upb_descreader_file(const upb_descreader *r, size_t i) {
+ upb_value v;
+ if (upb_inttable_lookup(&r->files, i, &v)) {
+ return upb_value_getptr(v);
+ } else {
+ return NULL;
+ }
+}
+
+upb_sink *upb_descreader_input(upb_descreader *r) {
+ return &r->sink;
+}
+
+const upb_handlers *upb_descreader_newhandlers(const void *owner) {
+ const upb_msgdef *m = upbdefs_google_protobuf_FileDescriptorSet_get(&m);
+ const upb_handlers *h = upb_handlers_newfrozen(m, owner, reghandlers, NULL);
+ upb_msgdef_unref(m, &m);
+ return h;
+}
+/*
+** protobuf decoder bytecode compiler
+**
+** Code to compile a upb::Handlers into bytecode for decoding a protobuf
+** according to that specific schema and destination handlers.
+**
+** Compiling to bytecode is always the first step. If we are using the
+** interpreted decoder we leave it as bytecode and interpret that. If we are
+** using a JIT decoder we use a code generator to turn the bytecode into native
+** code, LLVM IR, etc.
+**
+** Bytecode definition is in decoder.int.h.
+*/
+
+#include <stdarg.h>
+
+#ifdef UPB_DUMP_BYTECODE
+#include <stdio.h>
+#endif
+
+#define MAXLABEL 5
+#define EMPTYLABEL -1
+
+/* mgroup *********************************************************************/
+
+static void freegroup(upb_refcounted *r) {
+ mgroup *g = (mgroup*)r;
+ upb_inttable_uninit(&g->methods);
+#ifdef UPB_USE_JIT_X64
+ upb_pbdecoder_freejit(g);
+#endif
+ upb_gfree(g->bytecode);
+ upb_gfree(g);
+}
+
+static void visitgroup(const upb_refcounted *r, upb_refcounted_visit *visit,
+ void *closure) {
+ const mgroup *g = (const mgroup*)r;
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, &g->methods);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ upb_pbdecodermethod *method = upb_value_getptr(upb_inttable_iter_value(&i));
+ visit(r, upb_pbdecodermethod_upcast(method), closure);
+ }
+}
+
+mgroup *newgroup(const void *owner) {
+ mgroup *g = upb_gmalloc(sizeof(*g));
+ static const struct upb_refcounted_vtbl vtbl = {visitgroup, freegroup};
+ upb_refcounted_init(mgroup_upcast_mutable(g), &vtbl, owner);
+ upb_inttable_init(&g->methods, UPB_CTYPE_PTR);
+ g->bytecode = NULL;
+ g->bytecode_end = NULL;
+ return g;
+}
+
+
+/* upb_pbdecodermethod ********************************************************/
+
+static void freemethod(upb_refcounted *r) {
+ upb_pbdecodermethod *method = (upb_pbdecodermethod*)r;
+
+ if (method->dest_handlers_) {
+ upb_handlers_unref(method->dest_handlers_, method);
+ }
+
+ upb_inttable_uninit(&method->dispatch);
+ upb_gfree(method);
+}
+
+static void visitmethod(const upb_refcounted *r, upb_refcounted_visit *visit,
+ void *closure) {
+ const upb_pbdecodermethod *m = (const upb_pbdecodermethod*)r;
+ visit(r, m->group, closure);
+}
+
+static upb_pbdecodermethod *newmethod(const upb_handlers *dest_handlers,
+ mgroup *group) {
+ static const struct upb_refcounted_vtbl vtbl = {visitmethod, freemethod};
+ upb_pbdecodermethod *ret = upb_gmalloc(sizeof(*ret));
+ upb_refcounted_init(upb_pbdecodermethod_upcast_mutable(ret), &vtbl, &ret);
+ upb_byteshandler_init(&ret->input_handler_);
+
+ /* The method references the group and vice-versa, in a circular reference. */
+ upb_ref2(ret, group);
+ upb_ref2(group, ret);
+ upb_inttable_insertptr(&group->methods, dest_handlers, upb_value_ptr(ret));
+ upb_pbdecodermethod_unref(ret, &ret);
+
+ ret->group = mgroup_upcast_mutable(group);
+ ret->dest_handlers_ = dest_handlers;
+ ret->is_native_ = false; /* If we JIT, it will update this later. */
+ upb_inttable_init(&ret->dispatch, UPB_CTYPE_UINT64);
+
+ if (ret->dest_handlers_) {
+ upb_handlers_ref(ret->dest_handlers_, ret);
+ }
+ return ret;
+}
+
+const upb_handlers *upb_pbdecodermethod_desthandlers(
+ const upb_pbdecodermethod *m) {
+ return m->dest_handlers_;
+}
+
+const upb_byteshandler *upb_pbdecodermethod_inputhandler(
+ const upb_pbdecodermethod *m) {
+ return &m->input_handler_;
+}
+
+bool upb_pbdecodermethod_isnative(const upb_pbdecodermethod *m) {
+ return m->is_native_;
+}
+
+const upb_pbdecodermethod *upb_pbdecodermethod_new(
+ const upb_pbdecodermethodopts *opts, const void *owner) {
+ const upb_pbdecodermethod *ret;
+ upb_pbcodecache cache;
+
+ upb_pbcodecache_init(&cache);
+ ret = upb_pbcodecache_getdecodermethod(&cache, opts);
+ upb_pbdecodermethod_ref(ret, owner);
+ upb_pbcodecache_uninit(&cache);
+ return ret;
+}
+
+
+/* bytecode compiler **********************************************************/
+
+/* Data used only at compilation time. */
+typedef struct {
+ mgroup *group;
+
+ uint32_t *pc;
+ int fwd_labels[MAXLABEL];
+ int back_labels[MAXLABEL];
+
+ /* For fields marked "lazy", parse them lazily or eagerly? */
+ bool lazy;
+} compiler;
+
+static compiler *newcompiler(mgroup *group, bool lazy) {
+ compiler *ret = upb_gmalloc(sizeof(*ret));
+ int i;
+
+ ret->group = group;
+ ret->lazy = lazy;
+ for (i = 0; i < MAXLABEL; i++) {
+ ret->fwd_labels[i] = EMPTYLABEL;
+ ret->back_labels[i] = EMPTYLABEL;
+ }
+ return ret;
+}
+
+static void freecompiler(compiler *c) {
+ upb_gfree(c);
+}
+
+const size_t ptr_words = sizeof(void*) / sizeof(uint32_t);
+
+/* How many words an instruction is. */
+static int instruction_len(uint32_t instr) {
+ switch (getop(instr)) {
+ case OP_SETDISPATCH: return 1 + ptr_words;
+ case OP_TAGN: return 3;
+ case OP_SETBIGGROUPNUM: return 2;
+ default: return 1;
+ }
+}
+
+bool op_has_longofs(int32_t instruction) {
+ switch (getop(instruction)) {
+ case OP_CALL:
+ case OP_BRANCH:
+ case OP_CHECKDELIM:
+ return true;
+ /* The "tag" instructions only have 8 bytes available for the jump target,
+ * but that is ok because these opcodes only require short jumps. */
+ case OP_TAG1:
+ case OP_TAG2:
+ case OP_TAGN:
+ return false;
+ default:
+ UPB_ASSERT(false);
+ return false;
+ }
+}
+
+static int32_t getofs(uint32_t instruction) {
+ if (op_has_longofs(instruction)) {
+ return (int32_t)instruction >> 8;
+ } else {
+ return (int8_t)(instruction >> 8);
+ }
+}
+
+static void setofs(uint32_t *instruction, int32_t ofs) {
+ if (op_has_longofs(*instruction)) {
+ *instruction = getop(*instruction) | ofs << 8;
+ } else {
+ *instruction = (*instruction & ~0xff00) | ((ofs & 0xff) << 8);
+ }
+ UPB_ASSERT(getofs(*instruction) == ofs); /* Would fail in cases of overflow. */
+}
+
+static uint32_t pcofs(compiler *c) { return c->pc - c->group->bytecode; }
+
+/* Defines a local label at the current PC location. All previous forward
+ * references are updated to point to this location. The location is noted
+ * for any future backward references. */
+static void label(compiler *c, unsigned int label) {
+ int val;
+ uint32_t *codep;
+
+ UPB_ASSERT(label < MAXLABEL);
+ val = c->fwd_labels[label];
+ codep = (val == EMPTYLABEL) ? NULL : c->group->bytecode + val;
+ while (codep) {
+ int ofs = getofs(*codep);
+ setofs(codep, c->pc - codep - instruction_len(*codep));
+ codep = ofs ? codep + ofs : NULL;
+ }
+ c->fwd_labels[label] = EMPTYLABEL;
+ c->back_labels[label] = pcofs(c);
+}
+
+/* Creates a reference to a numbered label; either a forward reference
+ * (positive arg) or backward reference (negative arg). For forward references
+ * the value returned now is actually a "next" pointer into a linked list of all
+ * instructions that use this label and will be patched later when the label is
+ * defined with label().
+ *
+ * The returned value is the offset that should be written into the instruction.
+ */
+static int32_t labelref(compiler *c, int label) {
+ UPB_ASSERT(label < MAXLABEL);
+ if (label == LABEL_DISPATCH) {
+ /* No resolving required. */
+ return 0;
+ } else if (label < 0) {
+ /* Backward local label. Relative to the next instruction. */
+ uint32_t from = (c->pc + 1) - c->group->bytecode;
+ return c->back_labels[-label] - from;
+ } else {
+ /* Forward local label: prepend to (possibly-empty) linked list. */
+ int *lptr = &c->fwd_labels[label];
+ int32_t ret = (*lptr == EMPTYLABEL) ? 0 : *lptr - pcofs(c);
+ *lptr = pcofs(c);
+ return ret;
+ }
+}
+
+static void put32(compiler *c, uint32_t v) {
+ mgroup *g = c->group;
+ if (c->pc == g->bytecode_end) {
+ int ofs = pcofs(c);
+ size_t oldsize = g->bytecode_end - g->bytecode;
+ size_t newsize = UPB_MAX(oldsize * 2, 64);
+ /* TODO(haberman): handle OOM. */
+ g->bytecode = upb_grealloc(g->bytecode, oldsize * sizeof(uint32_t),
+ newsize * sizeof(uint32_t));
+ g->bytecode_end = g->bytecode + newsize;
+ c->pc = g->bytecode + ofs;
+ }
+ *c->pc++ = v;
+}
+
+static void putop(compiler *c, opcode op, ...) {
+ va_list ap;
+ va_start(ap, op);
+
+ switch (op) {
+ case OP_SETDISPATCH: {
+ uintptr_t ptr = (uintptr_t)va_arg(ap, void*);
+ put32(c, OP_SETDISPATCH);
+ put32(c, ptr);
+ if (sizeof(uintptr_t) > sizeof(uint32_t))
+ put32(c, (uint64_t)ptr >> 32);
+ break;
+ }
+ case OP_STARTMSG:
+ case OP_ENDMSG:
+ case OP_PUSHLENDELIM:
+ case OP_POP:
+ case OP_SETDELIM:
+ case OP_HALT:
+ case OP_RET:
+ case OP_DISPATCH:
+ put32(c, op);
+ break;
+ case OP_PARSE_DOUBLE:
+ case OP_PARSE_FLOAT:
+ case OP_PARSE_INT64:
+ case OP_PARSE_UINT64:
+ case OP_PARSE_INT32:
+ case OP_PARSE_FIXED64:
+ case OP_PARSE_FIXED32:
+ case OP_PARSE_BOOL:
+ case OP_PARSE_UINT32:
+ case OP_PARSE_SFIXED32:
+ case OP_PARSE_SFIXED64:
+ case OP_PARSE_SINT32:
+ case OP_PARSE_SINT64:
+ case OP_STARTSEQ:
+ case OP_ENDSEQ:
+ case OP_STARTSUBMSG:
+ case OP_ENDSUBMSG:
+ case OP_STARTSTR:
+ case OP_STRING:
+ case OP_ENDSTR:
+ case OP_PUSHTAGDELIM:
+ put32(c, op | va_arg(ap, upb_selector_t) << 8);
+ break;
+ case OP_SETBIGGROUPNUM:
+ put32(c, op);
+ put32(c, va_arg(ap, int));
+ break;
+ case OP_CALL: {
+ const upb_pbdecodermethod *method = va_arg(ap, upb_pbdecodermethod *);
+ put32(c, op | (method->code_base.ofs - (pcofs(c) + 1)) << 8);
+ break;
+ }
+ case OP_CHECKDELIM:
+ case OP_BRANCH: {
+ uint32_t instruction = op;
+ int label = va_arg(ap, int);
+ setofs(&instruction, labelref(c, label));
+ put32(c, instruction);
+ break;
+ }
+ case OP_TAG1:
+ case OP_TAG2: {
+ int label = va_arg(ap, int);
+ uint64_t tag = va_arg(ap, uint64_t);
+ uint32_t instruction = op | (tag << 16);
+ UPB_ASSERT(tag <= 0xffff);
+ setofs(&instruction, labelref(c, label));
+ put32(c, instruction);
+ break;
+ }
+ case OP_TAGN: {
+ int label = va_arg(ap, int);
+ uint64_t tag = va_arg(ap, uint64_t);
+ uint32_t instruction = op | (upb_value_size(tag) << 16);
+ setofs(&instruction, labelref(c, label));
+ put32(c, instruction);
+ put32(c, tag);
+ put32(c, tag >> 32);
+ break;
+ }
+ }
+
+ va_end(ap);
+}
+
+#if defined(UPB_USE_JIT_X64) || defined(UPB_DUMP_BYTECODE)
+
+const char *upb_pbdecoder_getopname(unsigned int op) {
+#define QUOTE(x) #x
+#define EXPAND_AND_QUOTE(x) QUOTE(x)
+#define OPNAME(x) OP_##x
+#define OP(x) case OPNAME(x): return EXPAND_AND_QUOTE(OPNAME(x));
+#define T(x) OP(PARSE_##x)
+ /* Keep in sync with list in decoder.int.h. */
+ switch ((opcode)op) {
+ T(DOUBLE) T(FLOAT) T(INT64) T(UINT64) T(INT32) T(FIXED64) T(FIXED32)
+ T(BOOL) T(UINT32) T(SFIXED32) T(SFIXED64) T(SINT32) T(SINT64)
+ OP(STARTMSG) OP(ENDMSG) OP(STARTSEQ) OP(ENDSEQ) OP(STARTSUBMSG)
+ OP(ENDSUBMSG) OP(STARTSTR) OP(STRING) OP(ENDSTR) OP(CALL) OP(RET)
+ OP(PUSHLENDELIM) OP(PUSHTAGDELIM) OP(SETDELIM) OP(CHECKDELIM)
+ OP(BRANCH) OP(TAG1) OP(TAG2) OP(TAGN) OP(SETDISPATCH) OP(POP)
+ OP(SETBIGGROUPNUM) OP(DISPATCH) OP(HALT)
+ }
+ return "<unknown op>";
+#undef OP
+#undef T
+}
+
+#endif
+
+#ifdef UPB_DUMP_BYTECODE
+
+static void dumpbc(uint32_t *p, uint32_t *end, FILE *f) {
+
+ uint32_t *begin = p;
+
+ while (p < end) {
+ fprintf(f, "%p %8tx", p, p - begin);
+ uint32_t instr = *p++;
+ uint8_t op = getop(instr);
+ fprintf(f, " %s", upb_pbdecoder_getopname(op));
+ switch ((opcode)op) {
+ case OP_SETDISPATCH: {
+ const upb_inttable *dispatch;
+ memcpy(&dispatch, p, sizeof(void*));
+ p += ptr_words;
+ const upb_pbdecodermethod *method =
+ (void *)((char *)dispatch -
+ offsetof(upb_pbdecodermethod, dispatch));
+ fprintf(f, " %s", upb_msgdef_fullname(
+ upb_handlers_msgdef(method->dest_handlers_)));
+ break;
+ }
+ case OP_DISPATCH:
+ case OP_STARTMSG:
+ case OP_ENDMSG:
+ case OP_PUSHLENDELIM:
+ case OP_POP:
+ case OP_SETDELIM:
+ case OP_HALT:
+ case OP_RET:
+ break;
+ case OP_PARSE_DOUBLE:
+ case OP_PARSE_FLOAT:
+ case OP_PARSE_INT64:
+ case OP_PARSE_UINT64:
+ case OP_PARSE_INT32:
+ case OP_PARSE_FIXED64:
+ case OP_PARSE_FIXED32:
+ case OP_PARSE_BOOL:
+ case OP_PARSE_UINT32:
+ case OP_PARSE_SFIXED32:
+ case OP_PARSE_SFIXED64:
+ case OP_PARSE_SINT32:
+ case OP_PARSE_SINT64:
+ case OP_STARTSEQ:
+ case OP_ENDSEQ:
+ case OP_STARTSUBMSG:
+ case OP_ENDSUBMSG:
+ case OP_STARTSTR:
+ case OP_STRING:
+ case OP_ENDSTR:
+ case OP_PUSHTAGDELIM:
+ fprintf(f, " %d", instr >> 8);
+ break;
+ case OP_SETBIGGROUPNUM:
+ fprintf(f, " %d", *p++);
+ break;
+ case OP_CHECKDELIM:
+ case OP_CALL:
+ case OP_BRANCH:
+ fprintf(f, " =>0x%tx", p + getofs(instr) - begin);
+ break;
+ case OP_TAG1:
+ case OP_TAG2: {
+ fprintf(f, " tag:0x%x", instr >> 16);
+ if (getofs(instr)) {
+ fprintf(f, " =>0x%tx", p + getofs(instr) - begin);
+ }
+ break;
+ }
+ case OP_TAGN: {
+ uint64_t tag = *p++;
+ tag |= (uint64_t)*p++ << 32;
+ fprintf(f, " tag:0x%llx", (long long)tag);
+ fprintf(f, " n:%d", instr >> 16);
+ if (getofs(instr)) {
+ fprintf(f, " =>0x%tx", p + getofs(instr) - begin);
+ }
+ break;
+ }
+ }
+ fputs("\n", f);
+ }
+}
+
+#endif
+
+static uint64_t get_encoded_tag(const upb_fielddef *f, int wire_type) {
+ uint32_t tag = (upb_fielddef_number(f) << 3) | wire_type;
+ uint64_t encoded_tag = upb_vencode32(tag);
+ /* No tag should be greater than 5 bytes. */
+ UPB_ASSERT(encoded_tag <= 0xffffffffff);
+ return encoded_tag;
+}
+
+static void putchecktag(compiler *c, const upb_fielddef *f,
+ int wire_type, int dest) {
+ uint64_t tag = get_encoded_tag(f, wire_type);
+ switch (upb_value_size(tag)) {
+ case 1:
+ putop(c, OP_TAG1, dest, tag);
+ break;
+ case 2:
+ putop(c, OP_TAG2, dest, tag);
+ break;
+ default:
+ putop(c, OP_TAGN, dest, tag);
+ break;
+ }
+}
+
+static upb_selector_t getsel(const upb_fielddef *f, upb_handlertype_t type) {
+ upb_selector_t selector;
+ bool ok = upb_handlers_getselector(f, type, &selector);
+ UPB_ASSERT(ok);
+ return selector;
+}
+
+/* Takes an existing, primary dispatch table entry and repacks it with a
+ * different alternate wire type. Called when we are inserting a secondary
+ * dispatch table entry for an alternate wire type. */
+static uint64_t repack(uint64_t dispatch, int new_wt2) {
+ uint64_t ofs;
+ uint8_t wt1;
+ uint8_t old_wt2;
+ upb_pbdecoder_unpackdispatch(dispatch, &ofs, &wt1, &old_wt2);
+ UPB_ASSERT(old_wt2 == NO_WIRE_TYPE); /* wt2 should not be set yet. */
+ return upb_pbdecoder_packdispatch(ofs, wt1, new_wt2);
+}
+
+/* Marks the current bytecode position as the dispatch target for this message,
+ * field, and wire type. */
+static void dispatchtarget(compiler *c, upb_pbdecodermethod *method,
+ const upb_fielddef *f, int wire_type) {
+ /* Offset is relative to msg base. */
+ uint64_t ofs = pcofs(c) - method->code_base.ofs;
+ uint32_t fn = upb_fielddef_number(f);
+ upb_inttable *d = &method->dispatch;
+ upb_value v;
+ if (upb_inttable_remove(d, fn, &v)) {
+ /* TODO: prioritize based on packed setting in .proto file. */
+ uint64_t repacked = repack(upb_value_getuint64(v), wire_type);
+ upb_inttable_insert(d, fn, upb_value_uint64(repacked));
+ upb_inttable_insert(d, fn + UPB_MAX_FIELDNUMBER, upb_value_uint64(ofs));
+ } else {
+ uint64_t val = upb_pbdecoder_packdispatch(ofs, wire_type, NO_WIRE_TYPE);
+ upb_inttable_insert(d, fn, upb_value_uint64(val));
+ }
+}
+
+static void putpush(compiler *c, const upb_fielddef *f) {
+ if (upb_fielddef_descriptortype(f) == UPB_DESCRIPTOR_TYPE_MESSAGE) {
+ putop(c, OP_PUSHLENDELIM);
+ } else {
+ uint32_t fn = upb_fielddef_number(f);
+ if (fn >= 1 << 24) {
+ putop(c, OP_PUSHTAGDELIM, 0);
+ putop(c, OP_SETBIGGROUPNUM, fn);
+ } else {
+ putop(c, OP_PUSHTAGDELIM, fn);
+ }
+ }
+}
+
+static upb_pbdecodermethod *find_submethod(const compiler *c,
+ const upb_pbdecodermethod *method,
+ const upb_fielddef *f) {
+ const upb_handlers *sub =
+ upb_handlers_getsubhandlers(method->dest_handlers_, f);
+ upb_value v;
+ return upb_inttable_lookupptr(&c->group->methods, sub, &v)
+ ? upb_value_getptr(v)
+ : NULL;
+}
+
+static void putsel(compiler *c, opcode op, upb_selector_t sel,
+ const upb_handlers *h) {
+ if (upb_handlers_gethandler(h, sel)) {
+ putop(c, op, sel);
+ }
+}
+
+/* Puts an opcode to call a callback, but only if a callback actually exists for
+ * this field and handler type. */
+static void maybeput(compiler *c, opcode op, const upb_handlers *h,
+ const upb_fielddef *f, upb_handlertype_t type) {
+ putsel(c, op, getsel(f, type), h);
+}
+
+static bool haslazyhandlers(const upb_handlers *h, const upb_fielddef *f) {
+ if (!upb_fielddef_lazy(f))
+ return false;
+
+ return upb_handlers_gethandler(h, getsel(f, UPB_HANDLER_STARTSTR)) ||
+ upb_handlers_gethandler(h, getsel(f, UPB_HANDLER_STRING)) ||
+ upb_handlers_gethandler(h, getsel(f, UPB_HANDLER_ENDSTR));
+}
+
+
+/* bytecode compiler code generation ******************************************/
+
+/* Symbolic names for our local labels. */
+#define LABEL_LOOPSTART 1 /* Top of a repeated field loop. */
+#define LABEL_LOOPBREAK 2 /* To jump out of a repeated loop */
+#define LABEL_FIELD 3 /* Jump backward to find the most recent field. */
+#define LABEL_ENDMSG 4 /* To reach the OP_ENDMSG instr for this msg. */
+
+/* Generates bytecode to parse a single non-lazy message field. */
+static void generate_msgfield(compiler *c, const upb_fielddef *f,
+ upb_pbdecodermethod *method) {
+ const upb_handlers *h = upb_pbdecodermethod_desthandlers(method);
+ const upb_pbdecodermethod *sub_m = find_submethod(c, method, f);
+ int wire_type;
+
+ if (!sub_m) {
+ /* Don't emit any code for this field at all; it will be parsed as an
+ * unknown field.
+ *
+ * TODO(haberman): we should change this to parse it as a string field
+ * instead. It will probably be faster, but more importantly, once we
+ * start vending unknown fields, a field shouldn't be treated as unknown
+ * just because it doesn't have subhandlers registered. */
+ return;
+ }
+
+ label(c, LABEL_FIELD);
+
+ wire_type =
+ (upb_fielddef_descriptortype(f) == UPB_DESCRIPTOR_TYPE_MESSAGE)
+ ? UPB_WIRE_TYPE_DELIMITED
+ : UPB_WIRE_TYPE_START_GROUP;
+
+ if (upb_fielddef_isseq(f)) {
+ putop(c, OP_CHECKDELIM, LABEL_ENDMSG);
+ putchecktag(c, f, wire_type, LABEL_DISPATCH);
+ dispatchtarget(c, method, f, wire_type);
+ putop(c, OP_PUSHTAGDELIM, 0);
+ putop(c, OP_STARTSEQ, getsel(f, UPB_HANDLER_STARTSEQ));
+ label(c, LABEL_LOOPSTART);
+ putpush(c, f);
+ putop(c, OP_STARTSUBMSG, getsel(f, UPB_HANDLER_STARTSUBMSG));
+ putop(c, OP_CALL, sub_m);
+ putop(c, OP_POP);
+ maybeput(c, OP_ENDSUBMSG, h, f, UPB_HANDLER_ENDSUBMSG);
+ if (wire_type == UPB_WIRE_TYPE_DELIMITED) {
+ putop(c, OP_SETDELIM);
+ }
+ putop(c, OP_CHECKDELIM, LABEL_LOOPBREAK);
+ putchecktag(c, f, wire_type, LABEL_LOOPBREAK);
+ putop(c, OP_BRANCH, -LABEL_LOOPSTART);
+ label(c, LABEL_LOOPBREAK);
+ putop(c, OP_POP);
+ maybeput(c, OP_ENDSEQ, h, f, UPB_HANDLER_ENDSEQ);
+ } else {
+ putop(c, OP_CHECKDELIM, LABEL_ENDMSG);
+ putchecktag(c, f, wire_type, LABEL_DISPATCH);
+ dispatchtarget(c, method, f, wire_type);
+ putpush(c, f);
+ putop(c, OP_STARTSUBMSG, getsel(f, UPB_HANDLER_STARTSUBMSG));
+ putop(c, OP_CALL, sub_m);
+ putop(c, OP_POP);
+ maybeput(c, OP_ENDSUBMSG, h, f, UPB_HANDLER_ENDSUBMSG);
+ if (wire_type == UPB_WIRE_TYPE_DELIMITED) {
+ putop(c, OP_SETDELIM);
+ }
+ }
+}
+
+/* Generates bytecode to parse a single string or lazy submessage field. */
+static void generate_delimfield(compiler *c, const upb_fielddef *f,
+ upb_pbdecodermethod *method) {
+ const upb_handlers *h = upb_pbdecodermethod_desthandlers(method);
+
+ label(c, LABEL_FIELD);
+ if (upb_fielddef_isseq(f)) {
+ putop(c, OP_CHECKDELIM, LABEL_ENDMSG);
+ putchecktag(c, f, UPB_WIRE_TYPE_DELIMITED, LABEL_DISPATCH);
+ dispatchtarget(c, method, f, UPB_WIRE_TYPE_DELIMITED);
+ putop(c, OP_PUSHTAGDELIM, 0);
+ putop(c, OP_STARTSEQ, getsel(f, UPB_HANDLER_STARTSEQ));
+ label(c, LABEL_LOOPSTART);
+ putop(c, OP_PUSHLENDELIM);
+ putop(c, OP_STARTSTR, getsel(f, UPB_HANDLER_STARTSTR));
+ /* Need to emit even if no handler to skip past the string. */
+ putop(c, OP_STRING, getsel(f, UPB_HANDLER_STRING));
+ putop(c, OP_POP);
+ maybeput(c, OP_ENDSTR, h, f, UPB_HANDLER_ENDSTR);
+ putop(c, OP_SETDELIM);
+ putop(c, OP_CHECKDELIM, LABEL_LOOPBREAK);
+ putchecktag(c, f, UPB_WIRE_TYPE_DELIMITED, LABEL_LOOPBREAK);
+ putop(c, OP_BRANCH, -LABEL_LOOPSTART);
+ label(c, LABEL_LOOPBREAK);
+ putop(c, OP_POP);
+ maybeput(c, OP_ENDSEQ, h, f, UPB_HANDLER_ENDSEQ);
+ } else {
+ putop(c, OP_CHECKDELIM, LABEL_ENDMSG);
+ putchecktag(c, f, UPB_WIRE_TYPE_DELIMITED, LABEL_DISPATCH);
+ dispatchtarget(c, method, f, UPB_WIRE_TYPE_DELIMITED);
+ putop(c, OP_PUSHLENDELIM);
+ putop(c, OP_STARTSTR, getsel(f, UPB_HANDLER_STARTSTR));
+ putop(c, OP_STRING, getsel(f, UPB_HANDLER_STRING));
+ putop(c, OP_POP);
+ maybeput(c, OP_ENDSTR, h, f, UPB_HANDLER_ENDSTR);
+ putop(c, OP_SETDELIM);
+ }
+}
+
+/* Generates bytecode to parse a single primitive field. */
+static void generate_primitivefield(compiler *c, const upb_fielddef *f,
+ upb_pbdecodermethod *method) {
+ const upb_handlers *h = upb_pbdecodermethod_desthandlers(method);
+ upb_descriptortype_t descriptor_type = upb_fielddef_descriptortype(f);
+ opcode parse_type;
+ upb_selector_t sel;
+ int wire_type;
+
+ label(c, LABEL_FIELD);
+
+ /* From a decoding perspective, ENUM is the same as INT32. */
+ if (descriptor_type == UPB_DESCRIPTOR_TYPE_ENUM)
+ descriptor_type = UPB_DESCRIPTOR_TYPE_INT32;
+
+ parse_type = (opcode)descriptor_type;
+
+ /* TODO(haberman): generate packed or non-packed first depending on "packed"
+ * setting in the fielddef. This will favor (in speed) whichever was
+ * specified. */
+
+ UPB_ASSERT((int)parse_type >= 0 && parse_type <= OP_MAX);
+ sel = getsel(f, upb_handlers_getprimitivehandlertype(f));
+ wire_type = upb_pb_native_wire_types[upb_fielddef_descriptortype(f)];
+ if (upb_fielddef_isseq(f)) {
+ putop(c, OP_CHECKDELIM, LABEL_ENDMSG);
+ putchecktag(c, f, UPB_WIRE_TYPE_DELIMITED, LABEL_DISPATCH);
+ dispatchtarget(c, method, f, UPB_WIRE_TYPE_DELIMITED);
+ putop(c, OP_PUSHLENDELIM);
+ putop(c, OP_STARTSEQ, getsel(f, UPB_HANDLER_STARTSEQ)); /* Packed */
+ label(c, LABEL_LOOPSTART);
+ putop(c, parse_type, sel);
+ putop(c, OP_CHECKDELIM, LABEL_LOOPBREAK);
+ putop(c, OP_BRANCH, -LABEL_LOOPSTART);
+ dispatchtarget(c, method, f, wire_type);
+ putop(c, OP_PUSHTAGDELIM, 0);
+ putop(c, OP_STARTSEQ, getsel(f, UPB_HANDLER_STARTSEQ)); /* Non-packed */
+ label(c, LABEL_LOOPSTART);
+ putop(c, parse_type, sel);
+ putop(c, OP_CHECKDELIM, LABEL_LOOPBREAK);
+ putchecktag(c, f, wire_type, LABEL_LOOPBREAK);
+ putop(c, OP_BRANCH, -LABEL_LOOPSTART);
+ label(c, LABEL_LOOPBREAK);
+ putop(c, OP_POP); /* Packed and non-packed join. */
+ maybeput(c, OP_ENDSEQ, h, f, UPB_HANDLER_ENDSEQ);
+ putop(c, OP_SETDELIM); /* Could remove for non-packed by dup ENDSEQ. */
+ } else {
+ putop(c, OP_CHECKDELIM, LABEL_ENDMSG);
+ putchecktag(c, f, wire_type, LABEL_DISPATCH);
+ dispatchtarget(c, method, f, wire_type);
+ putop(c, parse_type, sel);
+ }
+}
+
+/* Adds bytecode for parsing the given message to the given decoderplan,
+ * while adding all dispatch targets to this message's dispatch table. */
+static void compile_method(compiler *c, upb_pbdecodermethod *method) {
+ const upb_handlers *h;
+ const upb_msgdef *md;
+ uint32_t* start_pc;
+ upb_msg_field_iter i;
+ upb_value val;
+
+ UPB_ASSERT(method);
+
+ /* Clear all entries in the dispatch table. */
+ upb_inttable_uninit(&method->dispatch);
+ upb_inttable_init(&method->dispatch, UPB_CTYPE_UINT64);
+
+ h = upb_pbdecodermethod_desthandlers(method);
+ md = upb_handlers_msgdef(h);
+
+ method->code_base.ofs = pcofs(c);
+ putop(c, OP_SETDISPATCH, &method->dispatch);
+ putsel(c, OP_STARTMSG, UPB_STARTMSG_SELECTOR, h);
+ label(c, LABEL_FIELD);
+ start_pc = c->pc;
+ for(upb_msg_field_begin(&i, md);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ const upb_fielddef *f = upb_msg_iter_field(&i);
+ upb_fieldtype_t type = upb_fielddef_type(f);
+
+ if (type == UPB_TYPE_MESSAGE && !(haslazyhandlers(h, f) && c->lazy)) {
+ generate_msgfield(c, f, method);
+ } else if (type == UPB_TYPE_STRING || type == UPB_TYPE_BYTES ||
+ type == UPB_TYPE_MESSAGE) {
+ generate_delimfield(c, f, method);
+ } else {
+ generate_primitivefield(c, f, method);
+ }
+ }
+
+ /* If there were no fields, or if no handlers were defined, we need to
+ * generate a non-empty loop body so that we can at least dispatch for unknown
+ * fields and check for the end of the message. */
+ if (c->pc == start_pc) {
+ /* Check for end-of-message. */
+ putop(c, OP_CHECKDELIM, LABEL_ENDMSG);
+ /* Unconditionally dispatch. */
+ putop(c, OP_DISPATCH, 0);
+ }
+
+ /* For now we just loop back to the last field of the message (or if none,
+ * the DISPATCH opcode for the message). */
+ putop(c, OP_BRANCH, -LABEL_FIELD);
+
+ /* Insert both a label and a dispatch table entry for this end-of-msg. */
+ label(c, LABEL_ENDMSG);
+ val = upb_value_uint64(pcofs(c) - method->code_base.ofs);
+ upb_inttable_insert(&method->dispatch, DISPATCH_ENDMSG, val);
+
+ putsel(c, OP_ENDMSG, UPB_ENDMSG_SELECTOR, h);
+ putop(c, OP_RET);
+
+ upb_inttable_compact(&method->dispatch);
+}
+
+/* Populate "methods" with new upb_pbdecodermethod objects reachable from "h".
+ * Returns the method for these handlers.
+ *
+ * Generates a new method for every destination handlers reachable from "h". */
+static void find_methods(compiler *c, const upb_handlers *h) {
+ upb_value v;
+ upb_msg_field_iter i;
+ const upb_msgdef *md;
+
+ if (upb_inttable_lookupptr(&c->group->methods, h, &v))
+ return;
+ newmethod(h, c->group);
+
+ /* Find submethods. */
+ md = upb_handlers_msgdef(h);
+ for(upb_msg_field_begin(&i, md);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ const upb_fielddef *f = upb_msg_iter_field(&i);
+ const upb_handlers *sub_h;
+ if (upb_fielddef_type(f) == UPB_TYPE_MESSAGE &&
+ (sub_h = upb_handlers_getsubhandlers(h, f)) != NULL) {
+ /* We only generate a decoder method for submessages with handlers.
+ * Others will be parsed as unknown fields. */
+ find_methods(c, sub_h);
+ }
+ }
+}
+
+/* (Re-)compile bytecode for all messages in "msgs."
+ * Overwrites any existing bytecode in "c". */
+static void compile_methods(compiler *c) {
+ upb_inttable_iter i;
+
+ /* Start over at the beginning of the bytecode. */
+ c->pc = c->group->bytecode;
+
+ upb_inttable_begin(&i, &c->group->methods);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ upb_pbdecodermethod *method = upb_value_getptr(upb_inttable_iter_value(&i));
+ compile_method(c, method);
+ }
+}
+
+static void set_bytecode_handlers(mgroup *g) {
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, &g->methods);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ upb_pbdecodermethod *m = upb_value_getptr(upb_inttable_iter_value(&i));
+ upb_byteshandler *h = &m->input_handler_;
+
+ m->code_base.ptr = g->bytecode + m->code_base.ofs;
+
+ upb_byteshandler_setstartstr(h, upb_pbdecoder_startbc, m->code_base.ptr);
+ upb_byteshandler_setstring(h, upb_pbdecoder_decode, g);
+ upb_byteshandler_setendstr(h, upb_pbdecoder_end, m);
+ }
+}
+
+
+/* JIT setup. *****************************************************************/
+
+#ifdef UPB_USE_JIT_X64
+
+static void sethandlers(mgroup *g, bool allowjit) {
+ g->jit_code = NULL;
+ if (allowjit) {
+ /* Compile byte-code into machine code, create handlers. */
+ upb_pbdecoder_jit(g);
+ } else {
+ set_bytecode_handlers(g);
+ }
+}
+
+#else /* UPB_USE_JIT_X64 */
+
+static void sethandlers(mgroup *g, bool allowjit) {
+ /* No JIT compiled in; use bytecode handlers unconditionally. */
+ UPB_UNUSED(allowjit);
+ set_bytecode_handlers(g);
+}
+
+#endif /* UPB_USE_JIT_X64 */
+
+
+/* TODO(haberman): allow this to be constructed for an arbitrary set of dest
+ * handlers and other mgroups (but verify we have a transitive closure). */
+const mgroup *mgroup_new(const upb_handlers *dest, bool allowjit, bool lazy,
+ const void *owner) {
+ mgroup *g;
+ compiler *c;
+
+ UPB_UNUSED(allowjit);
+ UPB_ASSERT(upb_handlers_isfrozen(dest));
+
+ g = newgroup(owner);
+ c = newcompiler(g, lazy);
+ find_methods(c, dest);
+
+ /* We compile in two passes:
+ * 1. all messages are assigned relative offsets from the beginning of the
+ * bytecode (saved in method->code_base).
+ * 2. forwards OP_CALL instructions can be correctly linked since message
+ * offsets have been previously assigned.
+ *
+ * Could avoid the second pass by linking OP_CALL instructions somehow. */
+ compile_methods(c);
+ compile_methods(c);
+ g->bytecode_end = c->pc;
+ freecompiler(c);
+
+#ifdef UPB_DUMP_BYTECODE
+ {
+ FILE *f = fopen("/tmp/upb-bytecode", "w");
+ UPB_ASSERT(f);
+ dumpbc(g->bytecode, g->bytecode_end, stderr);
+ dumpbc(g->bytecode, g->bytecode_end, f);
+ fclose(f);
+
+ f = fopen("/tmp/upb-bytecode.bin", "wb");
+ UPB_ASSERT(f);
+ fwrite(g->bytecode, 1, g->bytecode_end - g->bytecode, f);
+ fclose(f);
+ }
+#endif
+
+ sethandlers(g, allowjit);
+ return g;
+}
+
+
+/* upb_pbcodecache ************************************************************/
+
+void upb_pbcodecache_init(upb_pbcodecache *c) {
+ upb_inttable_init(&c->groups, UPB_CTYPE_CONSTPTR);
+ c->allow_jit_ = true;
+}
+
+void upb_pbcodecache_uninit(upb_pbcodecache *c) {
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, &c->groups);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ const mgroup *group = upb_value_getconstptr(upb_inttable_iter_value(&i));
+ mgroup_unref(group, c);
+ }
+ upb_inttable_uninit(&c->groups);
+}
+
+bool upb_pbcodecache_allowjit(const upb_pbcodecache *c) {
+ return c->allow_jit_;
+}
+
+bool upb_pbcodecache_setallowjit(upb_pbcodecache *c, bool allow) {
+ if (upb_inttable_count(&c->groups) > 0)
+ return false;
+ c->allow_jit_ = allow;
+ return true;
+}
+
+const upb_pbdecodermethod *upb_pbcodecache_getdecodermethod(
+ upb_pbcodecache *c, const upb_pbdecodermethodopts *opts) {
+ upb_value v;
+ bool ok;
+
+ /* Right now we build a new DecoderMethod every time.
+ * TODO(haberman): properly cache methods by their true key. */
+ const mgroup *g = mgroup_new(opts->handlers, c->allow_jit_, opts->lazy, c);
+ upb_inttable_push(&c->groups, upb_value_constptr(g));
+
+ ok = upb_inttable_lookupptr(&g->methods, opts->handlers, &v);
+ UPB_ASSERT(ok);
+ return upb_value_getptr(v);
+}
+
+
+/* upb_pbdecodermethodopts ****************************************************/
+
+void upb_pbdecodermethodopts_init(upb_pbdecodermethodopts *opts,
+ const upb_handlers *h) {
+ opts->handlers = h;
+ opts->lazy = false;
+}
+
+void upb_pbdecodermethodopts_setlazy(upb_pbdecodermethodopts *opts, bool lazy) {
+ opts->lazy = lazy;
+}
+/*
+** upb::Decoder (Bytecode Decoder VM)
+**
+** Bytecode must previously have been generated using the bytecode compiler in
+** compile_decoder.c. This decoder then walks through the bytecode op-by-op to
+** parse the input.
+**
+** Decoding is fully resumable; we just keep a pointer to the current bytecode
+** instruction and resume from there. A fair amount of the logic here is to
+** handle the fact that values can span buffer seams and we have to be able to
+** be capable of suspending/resuming from any byte in the stream. This
+** sometimes requires keeping a few trailing bytes from the last buffer around
+** in the "residual" buffer.
+*/
+
+#include <inttypes.h>
+#include <stddef.h>
+
+#ifdef UPB_DUMP_BYTECODE
+#include <stdio.h>
+#endif
+
+#define CHECK_SUSPEND(x) if (!(x)) return upb_pbdecoder_suspend(d);
+
+/* Error messages that are shared between the bytecode and JIT decoders. */
+const char *kPbDecoderStackOverflow = "Nesting too deep.";
+const char *kPbDecoderSubmessageTooLong =
+ "Submessage end extends past enclosing submessage.";
+
+/* Error messages shared within this file. */
+static const char *kUnterminatedVarint = "Unterminated varint.";
+
+/* upb_pbdecoder **************************************************************/
+
+static opcode halt = OP_HALT;
+
+/* A dummy character we can point to when the user passes us a NULL buffer.
+ * We need this because in C (NULL + 0) and (NULL - NULL) are undefined
+ * behavior, which would invalidate functions like curbufleft(). */
+static const char dummy_char;
+
+/* Whether an op consumes any of the input buffer. */
+static bool consumes_input(opcode op) {
+ switch (op) {
+ case OP_SETDISPATCH:
+ case OP_STARTMSG:
+ case OP_ENDMSG:
+ case OP_STARTSEQ:
+ case OP_ENDSEQ:
+ case OP_STARTSUBMSG:
+ case OP_ENDSUBMSG:
+ case OP_STARTSTR:
+ case OP_ENDSTR:
+ case OP_PUSHTAGDELIM:
+ case OP_POP:
+ case OP_SETDELIM:
+ case OP_SETBIGGROUPNUM:
+ case OP_CHECKDELIM:
+ case OP_CALL:
+ case OP_RET:
+ case OP_BRANCH:
+ return false;
+ default:
+ return true;
+ }
+}
+
+static size_t stacksize(upb_pbdecoder *d, size_t entries) {
+ UPB_UNUSED(d);
+ return entries * sizeof(upb_pbdecoder_frame);
+}
+
+static size_t callstacksize(upb_pbdecoder *d, size_t entries) {
+ UPB_UNUSED(d);
+
+#ifdef UPB_USE_JIT_X64
+ if (d->method_->is_native_) {
+ /* Each native stack frame needs two pointers, plus we need a few frames for
+ * the enter/exit trampolines. */
+ size_t ret = entries * sizeof(void*) * 2;
+ ret += sizeof(void*) * 10;
+ return ret;
+ }
+#endif
+
+ return entries * sizeof(uint32_t*);
+}
+
+
+static bool in_residual_buf(const upb_pbdecoder *d, const char *p);
+
+/* It's unfortunate that we have to micro-manage the compiler with
+ * UPB_FORCEINLINE and UPB_NOINLINE, especially since this tuning is necessarily
+ * specific to one hardware configuration. But empirically on a Core i7,
+ * performance increases 30-50% with these annotations. Every instance where
+ * these appear, gcc 4.2.1 made the wrong decision and degraded performance in
+ * benchmarks. */
+
+static void seterr(upb_pbdecoder *d, const char *msg) {
+ upb_status status = UPB_STATUS_INIT;
+ upb_status_seterrmsg(&status, msg);
+ upb_env_reporterror(d->env, &status);
+}
+
+void upb_pbdecoder_seterr(upb_pbdecoder *d, const char *msg) {
+ seterr(d, msg);
+}
+
+
+/* Buffering ******************************************************************/
+
+/* We operate on one buffer at a time, which is either the user's buffer passed
+ * to our "decode" callback or some residual bytes from the previous buffer. */
+
+/* How many bytes can be safely read from d->ptr without reading past end-of-buf
+ * or past the current delimited end. */
+static size_t curbufleft(const upb_pbdecoder *d) {
+ UPB_ASSERT(d->data_end >= d->ptr);
+ return d->data_end - d->ptr;
+}
+
+/* How many bytes are available before end-of-buffer. */
+static size_t bufleft(const upb_pbdecoder *d) {
+ return d->end - d->ptr;
+}
+
+/* Overall stream offset of d->ptr. */
+uint64_t offset(const upb_pbdecoder *d) {
+ return d->bufstart_ofs + (d->ptr - d->buf);
+}
+
+/* How many bytes are available before the end of this delimited region. */
+size_t delim_remaining(const upb_pbdecoder *d) {
+ return d->top->end_ofs - offset(d);
+}
+
+/* Advances d->ptr. */
+static void advance(upb_pbdecoder *d, size_t len) {
+ UPB_ASSERT(curbufleft(d) >= len);
+ d->ptr += len;
+}
+
+static bool in_buf(const char *p, const char *buf, const char *end) {
+ return p >= buf && p <= end;
+}
+
+static bool in_residual_buf(const upb_pbdecoder *d, const char *p) {
+ return in_buf(p, d->residual, d->residual_end);
+}
+
+/* Calculates the delim_end value, which is affected by both the current buffer
+ * and the parsing stack, so must be called whenever either is updated. */
+static void set_delim_end(upb_pbdecoder *d) {
+ size_t delim_ofs = d->top->end_ofs - d->bufstart_ofs;
+ if (delim_ofs <= (size_t)(d->end - d->buf)) {
+ d->delim_end = d->buf + delim_ofs;
+ d->data_end = d->delim_end;
+ } else {
+ d->data_end = d->end;
+ d->delim_end = NULL;
+ }
+}
+
+static void switchtobuf(upb_pbdecoder *d, const char *buf, const char *end) {
+ d->ptr = buf;
+ d->buf = buf;
+ d->end = end;
+ set_delim_end(d);
+}
+
+static void advancetobuf(upb_pbdecoder *d, const char *buf, size_t len) {
+ UPB_ASSERT(curbufleft(d) == 0);
+ d->bufstart_ofs += (d->end - d->buf);
+ switchtobuf(d, buf, buf + len);
+}
+
+static void checkpoint(upb_pbdecoder *d) {
+ /* The assertion here is in the interests of efficiency, not correctness.
+ * We are trying to ensure that we don't checkpoint() more often than
+ * necessary. */
+ UPB_ASSERT(d->checkpoint != d->ptr);
+ d->checkpoint = d->ptr;
+}
+
+/* Skips "bytes" bytes in the stream, which may be more than available. If we
+ * skip more bytes than are available, we return a long read count to the caller
+ * indicating how many bytes can be skipped over before passing actual data
+ * again. Skipped bytes can pass a NULL buffer and the decoder guarantees they
+ * won't actually be read.
+ */
+static int32_t skip(upb_pbdecoder *d, size_t bytes) {
+ UPB_ASSERT(!in_residual_buf(d, d->ptr) || d->size_param == 0);
+ UPB_ASSERT(d->skip == 0);
+ if (bytes > delim_remaining(d)) {
+ seterr(d, "Skipped value extended beyond enclosing submessage.");
+ return upb_pbdecoder_suspend(d);
+ } else if (bufleft(d) >= bytes) {
+ /* Skipped data is all in current buffer, and more is still available. */
+ advance(d, bytes);
+ d->skip = 0;
+ return DECODE_OK;
+ } else {
+ /* Skipped data extends beyond currently available buffers. */
+ d->pc = d->last;
+ d->skip = bytes - curbufleft(d);
+ d->bufstart_ofs += (d->end - d->buf);
+ d->residual_end = d->residual;
+ switchtobuf(d, d->residual, d->residual_end);
+ return d->size_param + d->skip;
+ }
+}
+
+
+/* Resumes the decoder from an initial state or from a previous suspend. */
+int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf,
+ size_t size, const upb_bufhandle *handle) {
+ UPB_UNUSED(p); /* Useless; just for the benefit of the JIT. */
+
+ /* d->skip and d->residual_end could probably elegantly be represented
+ * as a single variable, to more easily represent this invariant. */
+ UPB_ASSERT(!(d->skip && d->residual_end > d->residual));
+
+ /* We need to remember the original size_param, so that the value we return
+ * is relative to it, even if we do some skipping first. */
+ d->size_param = size;
+ d->handle = handle;
+
+ /* Have to handle this case specially (ie. not with skip()) because the user
+ * is allowed to pass a NULL buffer here, which won't allow us to safely
+ * calculate a d->end or use our normal functions like curbufleft(). */
+ if (d->skip && d->skip >= size) {
+ d->skip -= size;
+ d->bufstart_ofs += size;
+ buf = &dummy_char;
+ size = 0;
+
+ /* We can't just return now, because we might need to execute some ops
+ * like CHECKDELIM, which could call some callbacks and pop the stack. */
+ }
+
+ /* We need to pretend that this was the actual buffer param, since some of the
+ * calculations assume that d->ptr/d->buf is relative to this. */
+ d->buf_param = buf;
+
+ if (!buf) {
+ /* NULL buf is ok if its entire span is covered by the "skip" above, but
+ * by this point we know that "skip" doesn't cover the buffer. */
+ seterr(d, "Passed NULL buffer over non-skippable region.");
+ return upb_pbdecoder_suspend(d);
+ }
+
+ if (d->residual_end > d->residual) {
+ /* We have residual bytes from the last buffer. */
+ UPB_ASSERT(d->ptr == d->residual);
+ } else {
+ switchtobuf(d, buf, buf + size);
+ }
+
+ d->checkpoint = d->ptr;
+
+ /* Handle skips that don't cover the whole buffer (as above). */
+ if (d->skip) {
+ size_t skip_bytes = d->skip;
+ d->skip = 0;
+ CHECK_RETURN(skip(d, skip_bytes));
+ checkpoint(d);
+ }
+
+ /* If we're inside an unknown group, continue to parse unknown values. */
+ if (d->top->groupnum < 0) {
+ CHECK_RETURN(upb_pbdecoder_skipunknown(d, -1, 0));
+ checkpoint(d);
+ }
+
+ return DECODE_OK;
+}
+
+/* Suspends the decoder at the last checkpoint, without saving any residual
+ * bytes. If there are any unconsumed bytes, returns a short byte count. */
+size_t upb_pbdecoder_suspend(upb_pbdecoder *d) {
+ d->pc = d->last;
+ if (d->checkpoint == d->residual) {
+ /* Checkpoint was in residual buf; no user bytes were consumed. */
+ d->ptr = d->residual;
+ return 0;
+ } else {
+ size_t ret = d->size_param - (d->end - d->checkpoint);
+ UPB_ASSERT(!in_residual_buf(d, d->checkpoint));
+ UPB_ASSERT(d->buf == d->buf_param || d->buf == &dummy_char);
+
+ d->bufstart_ofs += (d->checkpoint - d->buf);
+ d->residual_end = d->residual;
+ switchtobuf(d, d->residual, d->residual_end);
+ return ret;
+ }
+}
+
+/* Suspends the decoder at the last checkpoint, and saves any unconsumed
+ * bytes in our residual buffer. This is necessary if we need more user
+ * bytes to form a complete value, which might not be contiguous in the
+ * user's buffers. Always consumes all user bytes. */
+static size_t suspend_save(upb_pbdecoder *d) {
+ /* We hit end-of-buffer before we could parse a full value.
+ * Save any unconsumed bytes (if any) to the residual buffer. */
+ d->pc = d->last;
+
+ if (d->checkpoint == d->residual) {
+ /* Checkpoint was in residual buf; append user byte(s) to residual buf. */
+ UPB_ASSERT((d->residual_end - d->residual) + d->size_param <=
+ sizeof(d->residual));
+ if (!in_residual_buf(d, d->ptr)) {
+ d->bufstart_ofs -= (d->residual_end - d->residual);
+ }
+ memcpy(d->residual_end, d->buf_param, d->size_param);
+ d->residual_end += d->size_param;
+ } else {
+ /* Checkpoint was in user buf; old residual bytes not needed. */
+ size_t save;
+ UPB_ASSERT(!in_residual_buf(d, d->checkpoint));
+
+ d->ptr = d->checkpoint;
+ save = curbufleft(d);
+ UPB_ASSERT(save <= sizeof(d->residual));
+ memcpy(d->residual, d->ptr, save);
+ d->residual_end = d->residual + save;
+ d->bufstart_ofs = offset(d);
+ }
+
+ switchtobuf(d, d->residual, d->residual_end);
+ return d->size_param;
+}
+
+/* Copies the next "bytes" bytes into "buf" and advances the stream.
+ * Requires that this many bytes are available in the current buffer. */
+UPB_FORCEINLINE static void consumebytes(upb_pbdecoder *d, void *buf,
+ size_t bytes) {
+ UPB_ASSERT(bytes <= curbufleft(d));
+ memcpy(buf, d->ptr, bytes);
+ advance(d, bytes);
+}
+
+/* Slow path for getting the next "bytes" bytes, regardless of whether they are
+ * available in the current buffer or not. Returns a status code as described
+ * in decoder.int.h. */
+UPB_NOINLINE static int32_t getbytes_slow(upb_pbdecoder *d, void *buf,
+ size_t bytes) {
+ const size_t avail = curbufleft(d);
+ consumebytes(d, buf, avail);
+ bytes -= avail;
+ UPB_ASSERT(bytes > 0);
+ if (in_residual_buf(d, d->ptr)) {
+ advancetobuf(d, d->buf_param, d->size_param);
+ }
+ if (curbufleft(d) >= bytes) {
+ consumebytes(d, (char *)buf + avail, bytes);
+ return DECODE_OK;
+ } else if (d->data_end == d->delim_end) {
+ seterr(d, "Submessage ended in the middle of a value or group");
+ return upb_pbdecoder_suspend(d);
+ } else {
+ return suspend_save(d);
+ }
+}
+
+/* Gets the next "bytes" bytes, regardless of whether they are available in the
+ * current buffer or not. Returns a status code as described in decoder.int.h.
+ */
+UPB_FORCEINLINE static int32_t getbytes(upb_pbdecoder *d, void *buf,
+ size_t bytes) {
+ if (curbufleft(d) >= bytes) {
+ /* Buffer has enough data to satisfy. */
+ consumebytes(d, buf, bytes);
+ return DECODE_OK;
+ } else {
+ return getbytes_slow(d, buf, bytes);
+ }
+}
+
+UPB_NOINLINE static size_t peekbytes_slow(upb_pbdecoder *d, void *buf,
+ size_t bytes) {
+ size_t ret = curbufleft(d);
+ memcpy(buf, d->ptr, ret);
+ if (in_residual_buf(d, d->ptr)) {
+ size_t copy = UPB_MIN(bytes - ret, d->size_param);
+ memcpy((char *)buf + ret, d->buf_param, copy);
+ ret += copy;
+ }
+ return ret;
+}
+
+UPB_FORCEINLINE static size_t peekbytes(upb_pbdecoder *d, void *buf,
+ size_t bytes) {
+ if (curbufleft(d) >= bytes) {
+ memcpy(buf, d->ptr, bytes);
+ return bytes;
+ } else {
+ return peekbytes_slow(d, buf, bytes);
+ }
+}
+
+
+/* Decoding of wire types *****************************************************/
+
+/* Slow path for decoding a varint from the current buffer position.
+ * Returns a status code as described in decoder.int.h. */
+UPB_NOINLINE int32_t upb_pbdecoder_decode_varint_slow(upb_pbdecoder *d,
+ uint64_t *u64) {
+ uint8_t byte = 0x80;
+ int bitpos;
+ *u64 = 0;
+ for(bitpos = 0; bitpos < 70 && (byte & 0x80); bitpos += 7) {
+ CHECK_RETURN(getbytes(d, &byte, 1));
+ *u64 |= (uint64_t)(byte & 0x7F) << bitpos;
+ }
+ if(bitpos == 70 && (byte & 0x80)) {
+ seterr(d, kUnterminatedVarint);
+ return upb_pbdecoder_suspend(d);
+ }
+ return DECODE_OK;
+}
+
+/* Decodes a varint from the current buffer position.
+ * Returns a status code as described in decoder.int.h. */
+UPB_FORCEINLINE static int32_t decode_varint(upb_pbdecoder *d, uint64_t *u64) {
+ if (curbufleft(d) > 0 && !(*d->ptr & 0x80)) {
+ *u64 = *d->ptr;
+ advance(d, 1);
+ return DECODE_OK;
+ } else if (curbufleft(d) >= 10) {
+ /* Fast case. */
+ upb_decoderet r = upb_vdecode_fast(d->ptr);
+ if (r.p == NULL) {
+ seterr(d, kUnterminatedVarint);
+ return upb_pbdecoder_suspend(d);
+ }
+ advance(d, r.p - d->ptr);
+ *u64 = r.val;
+ return DECODE_OK;
+ } else {
+ /* Slow case -- varint spans buffer seam. */
+ return upb_pbdecoder_decode_varint_slow(d, u64);
+ }
+}
+
+/* Decodes a 32-bit varint from the current buffer position.
+ * Returns a status code as described in decoder.int.h. */
+UPB_FORCEINLINE static int32_t decode_v32(upb_pbdecoder *d, uint32_t *u32) {
+ uint64_t u64;
+ int32_t ret = decode_varint(d, &u64);
+ if (ret >= 0) return ret;
+ if (u64 > UINT32_MAX) {
+ seterr(d, "Unterminated 32-bit varint");
+ /* TODO(haberman) guarantee that this function return is >= 0 somehow,
+ * so we know this path will always be treated as error by our caller.
+ * Right now the size_t -> int32_t can overflow and produce negative values.
+ */
+ *u32 = 0;
+ return upb_pbdecoder_suspend(d);
+ }
+ *u32 = u64;
+ return DECODE_OK;
+}
+
+/* Decodes a fixed32 from the current buffer position.
+ * Returns a status code as described in decoder.int.h.
+ * TODO: proper byte swapping for big-endian machines. */
+UPB_FORCEINLINE static int32_t decode_fixed32(upb_pbdecoder *d, uint32_t *u32) {
+ return getbytes(d, u32, 4);
+}
+
+/* Decodes a fixed64 from the current buffer position.
+ * Returns a status code as described in decoder.int.h.
+ * TODO: proper byte swapping for big-endian machines. */
+UPB_FORCEINLINE static int32_t decode_fixed64(upb_pbdecoder *d, uint64_t *u64) {
+ return getbytes(d, u64, 8);
+}
+
+/* Non-static versions of the above functions.
+ * These are called by the JIT for fallback paths. */
+int32_t upb_pbdecoder_decode_f32(upb_pbdecoder *d, uint32_t *u32) {
+ return decode_fixed32(d, u32);
+}
+
+int32_t upb_pbdecoder_decode_f64(upb_pbdecoder *d, uint64_t *u64) {
+ return decode_fixed64(d, u64);
+}
+
+static double as_double(uint64_t n) { double d; memcpy(&d, &n, 8); return d; }
+static float as_float(uint32_t n) { float f; memcpy(&f, &n, 4); return f; }
+
+/* Pushes a frame onto the decoder stack. */
+static bool decoder_push(upb_pbdecoder *d, uint64_t end) {
+ upb_pbdecoder_frame *fr = d->top;
+
+ if (end > fr->end_ofs) {
+ seterr(d, kPbDecoderSubmessageTooLong);
+ return false;
+ } else if (fr == d->limit) {
+ seterr(d, kPbDecoderStackOverflow);
+ return false;
+ }
+
+ fr++;
+ fr->end_ofs = end;
+ fr->dispatch = NULL;
+ fr->groupnum = 0;
+ d->top = fr;
+ return true;
+}
+
+static bool pushtagdelim(upb_pbdecoder *d, uint32_t arg) {
+ /* While we expect to see an "end" tag (either ENDGROUP or a non-sequence
+ * field number) prior to hitting any enclosing submessage end, pushing our
+ * existing delim end prevents us from continuing to parse values from a
+ * corrupt proto that doesn't give us an END tag in time. */
+ if (!decoder_push(d, d->top->end_ofs))
+ return false;
+ d->top->groupnum = arg;
+ return true;
+}
+
+/* Pops a frame from the decoder stack. */
+static void decoder_pop(upb_pbdecoder *d) { d->top--; }
+
+UPB_NOINLINE int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d,
+ uint64_t expected) {
+ uint64_t data = 0;
+ size_t bytes = upb_value_size(expected);
+ size_t read = peekbytes(d, &data, bytes);
+ if (read == bytes && data == expected) {
+ /* Advance past matched bytes. */
+ int32_t ok = getbytes(d, &data, read);
+ UPB_ASSERT(ok < 0);
+ return DECODE_OK;
+ } else if (read < bytes && memcmp(&data, &expected, read) == 0) {
+ return suspend_save(d);
+ } else {
+ return DECODE_MISMATCH;
+ }
+}
+
+int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum,
+ uint8_t wire_type) {
+ if (fieldnum >= 0)
+ goto have_tag;
+
+ while (true) {
+ uint32_t tag;
+ CHECK_RETURN(decode_v32(d, &tag));
+ wire_type = tag & 0x7;
+ fieldnum = tag >> 3;
+
+have_tag:
+ if (fieldnum == 0) {
+ seterr(d, "Saw invalid field number (0)");
+ return upb_pbdecoder_suspend(d);
+ }
+
+ /* TODO: deliver to unknown field callback. */
+ switch (wire_type) {
+ case UPB_WIRE_TYPE_32BIT:
+ CHECK_RETURN(skip(d, 4));
+ break;
+ case UPB_WIRE_TYPE_64BIT:
+ CHECK_RETURN(skip(d, 8));
+ break;
+ case UPB_WIRE_TYPE_VARINT: {
+ uint64_t u64;
+ CHECK_RETURN(decode_varint(d, &u64));
+ break;
+ }
+ case UPB_WIRE_TYPE_DELIMITED: {
+ uint32_t len;
+ CHECK_RETURN(decode_v32(d, &len));
+ CHECK_RETURN(skip(d, len));
+ break;
+ }
+ case UPB_WIRE_TYPE_START_GROUP:
+ CHECK_SUSPEND(pushtagdelim(d, -fieldnum));
+ break;
+ case UPB_WIRE_TYPE_END_GROUP:
+ if (fieldnum == -d->top->groupnum) {
+ decoder_pop(d);
+ } else if (fieldnum == d->top->groupnum) {
+ return DECODE_ENDGROUP;
+ } else {
+ seterr(d, "Unmatched ENDGROUP tag.");
+ return upb_pbdecoder_suspend(d);
+ }
+ break;
+ default:
+ seterr(d, "Invalid wire type");
+ return upb_pbdecoder_suspend(d);
+ }
+
+ if (d->top->groupnum >= 0) {
+ return DECODE_OK;
+ }
+
+ /* Unknown group -- continue looping over unknown fields. */
+ checkpoint(d);
+ }
+}
+
+static void goto_endmsg(upb_pbdecoder *d) {
+ upb_value v;
+ bool found = upb_inttable_lookup32(d->top->dispatch, DISPATCH_ENDMSG, &v);
+ UPB_ASSERT(found);
+ d->pc = d->top->base + upb_value_getuint64(v);
+}
+
+/* Parses a tag and jumps to the corresponding bytecode instruction for this
+ * field.
+ *
+ * If the tag is unknown (or the wire type doesn't match), parses the field as
+ * unknown. If the tag is a valid ENDGROUP tag, jumps to the bytecode
+ * instruction for the end of message. */
+static int32_t dispatch(upb_pbdecoder *d) {
+ upb_inttable *dispatch = d->top->dispatch;
+ uint32_t tag;
+ uint8_t wire_type;
+ uint32_t fieldnum;
+ upb_value val;
+ int32_t retval;
+
+ /* Decode tag. */
+ CHECK_RETURN(decode_v32(d, &tag));
+ wire_type = tag & 0x7;
+ fieldnum = tag >> 3;
+
+ /* Lookup tag. Because of packed/non-packed compatibility, we have to
+ * check the wire type against two possibilities. */
+ if (fieldnum != DISPATCH_ENDMSG &&
+ upb_inttable_lookup32(dispatch, fieldnum, &val)) {
+ uint64_t v = upb_value_getuint64(val);
+ if (wire_type == (v & 0xff)) {
+ d->pc = d->top->base + (v >> 16);
+ return DECODE_OK;
+ } else if (wire_type == ((v >> 8) & 0xff)) {
+ bool found =
+ upb_inttable_lookup(dispatch, fieldnum + UPB_MAX_FIELDNUMBER, &val);
+ UPB_ASSERT(found);
+ d->pc = d->top->base + upb_value_getuint64(val);
+ return DECODE_OK;
+ }
+ }
+
+ /* We have some unknown fields (or ENDGROUP) to parse. The DISPATCH or TAG
+ * bytecode that triggered this is preceded by a CHECKDELIM bytecode which
+ * we need to back up to, so that when we're done skipping unknown data we
+ * can re-check the delimited end. */
+ d->last--; /* Necessary if we get suspended */
+ d->pc = d->last;
+ UPB_ASSERT(getop(*d->last) == OP_CHECKDELIM);
+
+ /* Unknown field or ENDGROUP. */
+ retval = upb_pbdecoder_skipunknown(d, fieldnum, wire_type);
+
+ CHECK_RETURN(retval);
+
+ if (retval == DECODE_ENDGROUP) {
+ goto_endmsg(d);
+ return DECODE_OK;
+ }
+
+ return DECODE_OK;
+}
+
+/* Callers know that the stack is more than one deep because the opcodes that
+ * call this only occur after PUSH operations. */
+upb_pbdecoder_frame *outer_frame(upb_pbdecoder *d) {
+ UPB_ASSERT(d->top != d->stack);
+ return d->top - 1;
+}
+
+
+/* The main decoding loop *****************************************************/
+
+/* The main decoder VM function. Uses traditional bytecode dispatch loop with a
+ * switch() statement. */
+size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group,
+ const upb_bufhandle* handle) {
+
+#define VMCASE(op, code) \
+ case op: { code; if (consumes_input(op)) checkpoint(d); break; }
+#define PRIMITIVE_OP(type, wt, name, convfunc, ctype) \
+ VMCASE(OP_PARSE_ ## type, { \
+ ctype val; \
+ CHECK_RETURN(decode_ ## wt(d, &val)); \
+ upb_sink_put ## name(&d->top->sink, arg, (convfunc)(val)); \
+ })
+
+ while(1) {
+ int32_t instruction;
+ opcode op;
+ uint32_t arg;
+ int32_t longofs;
+
+ d->last = d->pc;
+ instruction = *d->pc++;
+ op = getop(instruction);
+ arg = instruction >> 8;
+ longofs = arg;
+ UPB_ASSERT(d->ptr != d->residual_end);
+ UPB_UNUSED(group);
+#ifdef UPB_DUMP_BYTECODE
+ fprintf(stderr, "s_ofs=%d buf_ofs=%d data_rem=%d buf_rem=%d delim_rem=%d "
+ "%x %s (%d)\n",
+ (int)offset(d),
+ (int)(d->ptr - d->buf),
+ (int)(d->data_end - d->ptr),
+ (int)(d->end - d->ptr),
+ (int)((d->top->end_ofs - d->bufstart_ofs) - (d->ptr - d->buf)),
+ (int)(d->pc - 1 - group->bytecode),
+ upb_pbdecoder_getopname(op),
+ arg);
+#endif
+ switch (op) {
+ /* Technically, we are losing data if we see a 32-bit varint that is not
+ * properly sign-extended. We could detect this and error about the data
+ * loss, but proto2 does not do this, so we pass. */
+ PRIMITIVE_OP(INT32, varint, int32, int32_t, uint64_t)
+ PRIMITIVE_OP(INT64, varint, int64, int64_t, uint64_t)
+ PRIMITIVE_OP(UINT32, varint, uint32, uint32_t, uint64_t)
+ PRIMITIVE_OP(UINT64, varint, uint64, uint64_t, uint64_t)
+ PRIMITIVE_OP(FIXED32, fixed32, uint32, uint32_t, uint32_t)
+ PRIMITIVE_OP(FIXED64, fixed64, uint64, uint64_t, uint64_t)
+ PRIMITIVE_OP(SFIXED32, fixed32, int32, int32_t, uint32_t)
+ PRIMITIVE_OP(SFIXED64, fixed64, int64, int64_t, uint64_t)
+ PRIMITIVE_OP(BOOL, varint, bool, bool, uint64_t)
+ PRIMITIVE_OP(DOUBLE, fixed64, double, as_double, uint64_t)
+ PRIMITIVE_OP(FLOAT, fixed32, float, as_float, uint32_t)
+ PRIMITIVE_OP(SINT32, varint, int32, upb_zzdec_32, uint64_t)
+ PRIMITIVE_OP(SINT64, varint, int64, upb_zzdec_64, uint64_t)
+
+ VMCASE(OP_SETDISPATCH,
+ d->top->base = d->pc - 1;
+ memcpy(&d->top->dispatch, d->pc, sizeof(void*));
+ d->pc += sizeof(void*) / sizeof(uint32_t);
+ )
+ VMCASE(OP_STARTMSG,
+ CHECK_SUSPEND(upb_sink_startmsg(&d->top->sink));
+ )
+ VMCASE(OP_ENDMSG,
+ CHECK_SUSPEND(upb_sink_endmsg(&d->top->sink, d->status));
+ )
+ VMCASE(OP_STARTSEQ,
+ upb_pbdecoder_frame *outer = outer_frame(d);
+ CHECK_SUSPEND(upb_sink_startseq(&outer->sink, arg, &d->top->sink));
+ )
+ VMCASE(OP_ENDSEQ,
+ CHECK_SUSPEND(upb_sink_endseq(&d->top->sink, arg));
+ )
+ VMCASE(OP_STARTSUBMSG,
+ upb_pbdecoder_frame *outer = outer_frame(d);
+ CHECK_SUSPEND(upb_sink_startsubmsg(&outer->sink, arg, &d->top->sink));
+ )
+ VMCASE(OP_ENDSUBMSG,
+ CHECK_SUSPEND(upb_sink_endsubmsg(&d->top->sink, arg));
+ )
+ VMCASE(OP_STARTSTR,
+ uint32_t len = delim_remaining(d);
+ upb_pbdecoder_frame *outer = outer_frame(d);
+ CHECK_SUSPEND(upb_sink_startstr(&outer->sink, arg, len, &d->top->sink));
+ if (len == 0) {
+ d->pc++; /* Skip OP_STRING. */
+ }
+ )
+ VMCASE(OP_STRING,
+ uint32_t len = curbufleft(d);
+ size_t n = upb_sink_putstring(&d->top->sink, arg, d->ptr, len, handle);
+ if (n > len) {
+ if (n > delim_remaining(d)) {
+ seterr(d, "Tried to skip past end of string.");
+ return upb_pbdecoder_suspend(d);
+ } else {
+ int32_t ret = skip(d, n);
+ /* This shouldn't return DECODE_OK, because n > len. */
+ UPB_ASSERT(ret >= 0);
+ return ret;
+ }
+ }
+ advance(d, n);
+ if (n < len || d->delim_end == NULL) {
+ /* We aren't finished with this string yet. */
+ d->pc--; /* Repeat OP_STRING. */
+ if (n > 0) checkpoint(d);
+ return upb_pbdecoder_suspend(d);
+ }
+ )
+ VMCASE(OP_ENDSTR,
+ CHECK_SUSPEND(upb_sink_endstr(&d->top->sink, arg));
+ )
+ VMCASE(OP_PUSHTAGDELIM,
+ CHECK_SUSPEND(pushtagdelim(d, arg));
+ )
+ VMCASE(OP_SETBIGGROUPNUM,
+ d->top->groupnum = *d->pc++;
+ )
+ VMCASE(OP_POP,
+ UPB_ASSERT(d->top > d->stack);
+ decoder_pop(d);
+ )
+ VMCASE(OP_PUSHLENDELIM,
+ uint32_t len;
+ CHECK_RETURN(decode_v32(d, &len));
+ CHECK_SUSPEND(decoder_push(d, offset(d) + len));
+ set_delim_end(d);
+ )
+ VMCASE(OP_SETDELIM,
+ set_delim_end(d);
+ )
+ VMCASE(OP_CHECKDELIM,
+ /* We are guaranteed of this assert because we never allow ourselves to
+ * consume bytes beyond data_end, which covers delim_end when non-NULL.
+ */
+ UPB_ASSERT(!(d->delim_end && d->ptr > d->delim_end));
+ if (d->ptr == d->delim_end)
+ d->pc += longofs;
+ )
+ VMCASE(OP_CALL,
+ d->callstack[d->call_len++] = d->pc;
+ d->pc += longofs;
+ )
+ VMCASE(OP_RET,
+ UPB_ASSERT(d->call_len > 0);
+ d->pc = d->callstack[--d->call_len];
+ )
+ VMCASE(OP_BRANCH,
+ d->pc += longofs;
+ )
+ VMCASE(OP_TAG1,
+ uint8_t expected;
+ CHECK_SUSPEND(curbufleft(d) > 0);
+ expected = (arg >> 8) & 0xff;
+ if (*d->ptr == expected) {
+ advance(d, 1);
+ } else {
+ int8_t shortofs;
+ badtag:
+ shortofs = arg;
+ if (shortofs == LABEL_DISPATCH) {
+ CHECK_RETURN(dispatch(d));
+ } else {
+ d->pc += shortofs;
+ break; /* Avoid checkpoint(). */
+ }
+ }
+ )
+ VMCASE(OP_TAG2,
+ uint16_t expected;
+ CHECK_SUSPEND(curbufleft(d) > 0);
+ expected = (arg >> 8) & 0xffff;
+ if (curbufleft(d) >= 2) {
+ uint16_t actual;
+ memcpy(&actual, d->ptr, 2);
+ if (expected == actual) {
+ advance(d, 2);
+ } else {
+ goto badtag;
+ }
+ } else {
+ int32_t result = upb_pbdecoder_checktag_slow(d, expected);
+ if (result == DECODE_MISMATCH) goto badtag;
+ if (result >= 0) return result;
+ }
+ )
+ VMCASE(OP_TAGN, {
+ uint64_t expected;
+ int32_t result;
+ memcpy(&expected, d->pc, 8);
+ d->pc += 2;
+ result = upb_pbdecoder_checktag_slow(d, expected);
+ if (result == DECODE_MISMATCH) goto badtag;
+ if (result >= 0) return result;
+ })
+ VMCASE(OP_DISPATCH, {
+ CHECK_RETURN(dispatch(d));
+ })
+ VMCASE(OP_HALT, {
+ return d->size_param;
+ })
+ }
+ }
+}
+
+
+/* BytesHandler handlers ******************************************************/
+
+void *upb_pbdecoder_startbc(void *closure, const void *pc, size_t size_hint) {
+ upb_pbdecoder *d = closure;
+ UPB_UNUSED(size_hint);
+ d->top->end_ofs = UINT64_MAX;
+ d->bufstart_ofs = 0;
+ d->call_len = 1;
+ d->callstack[0] = &halt;
+ d->pc = pc;
+ d->skip = 0;
+ return d;
+}
+
+void *upb_pbdecoder_startjit(void *closure, const void *hd, size_t size_hint) {
+ upb_pbdecoder *d = closure;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(size_hint);
+ d->top->end_ofs = UINT64_MAX;
+ d->bufstart_ofs = 0;
+ d->call_len = 0;
+ d->skip = 0;
+ return d;
+}
+
+bool upb_pbdecoder_end(void *closure, const void *handler_data) {
+ upb_pbdecoder *d = closure;
+ const upb_pbdecodermethod *method = handler_data;
+ uint64_t end;
+ char dummy;
+
+ if (d->residual_end > d->residual) {
+ seterr(d, "Unexpected EOF: decoder still has buffered unparsed data");
+ return false;
+ }
+
+ if (d->skip) {
+ seterr(d, "Unexpected EOF inside skipped data");
+ return false;
+ }
+
+ if (d->top->end_ofs != UINT64_MAX) {
+ seterr(d, "Unexpected EOF inside delimited string");
+ return false;
+ }
+
+ /* The user's end() call indicates that the message ends here. */
+ end = offset(d);
+ d->top->end_ofs = end;
+
+#ifdef UPB_USE_JIT_X64
+ if (method->is_native_) {
+ const mgroup *group = (const mgroup*)method->group;
+ if (d->top != d->stack)
+ d->stack->end_ofs = 0;
+ group->jit_code(closure, method->code_base.ptr, &dummy, 0, NULL);
+ } else
+#endif
+ {
+ const uint32_t *p = d->pc;
+ d->stack->end_ofs = end;
+ /* Check the previous bytecode, but guard against beginning. */
+ if (p != method->code_base.ptr) p--;
+ if (getop(*p) == OP_CHECKDELIM) {
+ /* Rewind from OP_TAG* to OP_CHECKDELIM. */
+ UPB_ASSERT(getop(*d->pc) == OP_TAG1 ||
+ getop(*d->pc) == OP_TAG2 ||
+ getop(*d->pc) == OP_TAGN ||
+ getop(*d->pc) == OP_DISPATCH);
+ d->pc = p;
+ }
+ upb_pbdecoder_decode(closure, handler_data, &dummy, 0, NULL);
+ }
+
+ if (d->call_len != 0) {
+ seterr(d, "Unexpected EOF inside submessage or group");
+ return false;
+ }
+
+ return true;
+}
+
+size_t upb_pbdecoder_decode(void *decoder, const void *group, const char *buf,
+ size_t size, const upb_bufhandle *handle) {
+ int32_t result = upb_pbdecoder_resume(decoder, NULL, buf, size, handle);
+
+ if (result == DECODE_ENDGROUP) goto_endmsg(decoder);
+ CHECK_RETURN(result);
+
+ return run_decoder_vm(decoder, group, handle);
+}
+
+
+/* Public API *****************************************************************/
+
+void upb_pbdecoder_reset(upb_pbdecoder *d) {
+ d->top = d->stack;
+ d->top->groupnum = 0;
+ d->ptr = d->residual;
+ d->buf = d->residual;
+ d->end = d->residual;
+ d->residual_end = d->residual;
+}
+
+upb_pbdecoder *upb_pbdecoder_create(upb_env *e, const upb_pbdecodermethod *m,
+ upb_sink *sink) {
+ const size_t default_max_nesting = 64;
+#ifndef NDEBUG
+ size_t size_before = upb_env_bytesallocated(e);
+#endif
+
+ upb_pbdecoder *d = upb_env_malloc(e, sizeof(upb_pbdecoder));
+ if (!d) return NULL;
+
+ d->method_ = m;
+ d->callstack = upb_env_malloc(e, callstacksize(d, default_max_nesting));
+ d->stack = upb_env_malloc(e, stacksize(d, default_max_nesting));
+ if (!d->stack || !d->callstack) {
+ return NULL;
+ }
+
+ d->env = e;
+ d->limit = d->stack + default_max_nesting - 1;
+ d->stack_size = default_max_nesting;
+ d->status = NULL;
+
+ upb_pbdecoder_reset(d);
+ upb_bytessink_reset(&d->input_, &m->input_handler_, d);
+
+ UPB_ASSERT(sink);
+ if (d->method_->dest_handlers_) {
+ if (sink->handlers != d->method_->dest_handlers_)
+ return NULL;
+ }
+ upb_sink_reset(&d->top->sink, sink->handlers, sink->closure);
+
+ /* If this fails, increase the value in decoder.h. */
+ UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(e) - size_before <=
+ UPB_PB_DECODER_SIZE);
+ return d;
+}
+
+uint64_t upb_pbdecoder_bytesparsed(const upb_pbdecoder *d) {
+ return offset(d);
+}
+
+const upb_pbdecodermethod *upb_pbdecoder_method(const upb_pbdecoder *d) {
+ return d->method_;
+}
+
+upb_bytessink *upb_pbdecoder_input(upb_pbdecoder *d) {
+ return &d->input_;
+}
+
+size_t upb_pbdecoder_maxnesting(const upb_pbdecoder *d) {
+ return d->stack_size;
+}
+
+bool upb_pbdecoder_setmaxnesting(upb_pbdecoder *d, size_t max) {
+ UPB_ASSERT(d->top >= d->stack);
+
+ if (max < (size_t)(d->top - d->stack)) {
+ /* Can't set a limit smaller than what we are currently at. */
+ return false;
+ }
+
+ if (max > d->stack_size) {
+ /* Need to reallocate stack and callstack to accommodate. */
+ size_t old_size = stacksize(d, d->stack_size);
+ size_t new_size = stacksize(d, max);
+ void *p = upb_env_realloc(d->env, d->stack, old_size, new_size);
+ if (!p) {
+ return false;
+ }
+ d->stack = p;
+
+ old_size = callstacksize(d, d->stack_size);
+ new_size = callstacksize(d, max);
+ p = upb_env_realloc(d->env, d->callstack, old_size, new_size);
+ if (!p) {
+ return false;
+ }
+ d->callstack = p;
+
+ d->stack_size = max;
+ }
+
+ d->limit = d->stack + max - 1;
+ return true;
+}
+/*
+** upb::Encoder
+**
+** Since we are implementing pure handlers (ie. without any out-of-band access
+** to pre-computed lengths), we have to buffer all submessages before we can
+** emit even their first byte.
+**
+** Not knowing the size of submessages also means we can't write a perfect
+** zero-copy implementation, even with buffering. Lengths are stored as
+** varints, which means that we don't know how many bytes to reserve for the
+** length until we know what the length is.
+**
+** This leaves us with three main choices:
+**
+** 1. buffer all submessage data in a temporary buffer, then copy it exactly
+** once into the output buffer.
+**
+** 2. attempt to buffer data directly into the output buffer, estimating how
+** many bytes each length will take. When our guesses are wrong, use
+** memmove() to grow or shrink the allotted space.
+**
+** 3. buffer directly into the output buffer, allocating a max length
+** ahead-of-time for each submessage length. If we overallocated, we waste
+** space, but no memcpy() or memmove() is required. This approach requires
+** defining a maximum size for submessages and rejecting submessages that
+** exceed that size.
+**
+** (2) and (3) have the potential to have better performance, but they are more
+** complicated and subtle to implement:
+**
+** (3) requires making an arbitrary choice of the maximum message size; it
+** wastes space when submessages are shorter than this and fails
+** completely when they are longer. This makes it more finicky and
+** requires configuration based on the input. It also makes it impossible
+** to perfectly match the output of reference encoders that always use the
+** optimal amount of space for each length.
+**
+** (2) requires guessing the the size upfront, and if multiple lengths are
+** guessed wrong the minimum required number of memmove() operations may
+** be complicated to compute correctly. Implemented properly, it may have
+** a useful amortized or average cost, but more investigation is required
+** to determine this and what the optimal algorithm is to achieve it.
+**
+** (1) makes you always pay for exactly one copy, but its implementation is
+** the simplest and its performance is predictable.
+**
+** So for now, we implement (1) only. If we wish to optimize later, we should
+** be able to do it without affecting users.
+**
+** The strategy is to buffer the segments of data that do *not* depend on
+** unknown lengths in one buffer, and keep a separate buffer of segment pointers
+** and lengths. When the top-level submessage ends, we can go beginning to end,
+** alternating the writing of lengths with memcpy() of the rest of the data.
+** At the top level though, no buffering is required.
+*/
+
+
+
+/* The output buffer is divided into segments; a segment is a string of data
+ * that is "ready to go" -- it does not need any varint lengths inserted into
+ * the middle. The seams between segments are where varints will be inserted
+ * once they are known.
+ *
+ * We also use the concept of a "run", which is a range of encoded bytes that
+ * occur at a single submessage level. Every segment contains one or more runs.
+ *
+ * A segment can span messages. Consider:
+ *
+ * .--Submessage lengths---------.
+ * | | |
+ * | V V
+ * V | |--------------- | |-----------------
+ * Submessages: | |-----------------------------------------------
+ * Top-level msg: ------------------------------------------------------------
+ *
+ * Segments: ----- ------------------- -----------------
+ * Runs: *---- *--------------*--- *----------------
+ * (* marks the start)
+ *
+ * Note that the top-level menssage is not in any segment because it does not
+ * have any length preceding it.
+ *
+ * A segment is only interrupted when another length needs to be inserted. So
+ * observe how the second segment spans both the inner submessage and part of
+ * the next enclosing message. */
+typedef struct {
+ uint32_t msglen; /* The length to varint-encode before this segment. */
+ uint32_t seglen; /* Length of the segment. */
+} upb_pb_encoder_segment;
+
+struct upb_pb_encoder {
+ upb_env *env;
+
+ /* Our input and output. */
+ upb_sink input_;
+ upb_bytessink *output_;
+
+ /* The "subclosure" -- used as the inner closure as part of the bytessink
+ * protocol. */
+ void *subc;
+
+ /* The output buffer and limit, and our current write position. "buf"
+ * initially points to "initbuf", but is dynamically allocated if we need to
+ * grow beyond the initial size. */
+ char *buf, *ptr, *limit;
+
+ /* The beginning of the current run, or undefined if we are at the top
+ * level. */
+ char *runbegin;
+
+ /* The list of segments we are accumulating. */
+ upb_pb_encoder_segment *segbuf, *segptr, *seglimit;
+
+ /* The stack of enclosing submessages. Each entry in the stack points to the
+ * segment where this submessage's length is being accumulated. */
+ int *stack, *top, *stacklimit;
+
+ /* Depth of startmsg/endmsg calls. */
+ int depth;
+};
+
+/* low-level buffering ********************************************************/
+
+/* Low-level functions for interacting with the output buffer. */
+
+/* TODO(haberman): handle pushback */
+static void putbuf(upb_pb_encoder *e, const char *buf, size_t len) {
+ size_t n = upb_bytessink_putbuf(e->output_, e->subc, buf, len, NULL);
+ UPB_ASSERT(n == len);
+}
+
+static upb_pb_encoder_segment *top(upb_pb_encoder *e) {
+ return &e->segbuf[*e->top];
+}
+
+/* Call to ensure that at least "bytes" bytes are available for writing at
+ * e->ptr. Returns false if the bytes could not be allocated. */
+static bool reserve(upb_pb_encoder *e, size_t bytes) {
+ if ((size_t)(e->limit - e->ptr) < bytes) {
+ /* Grow buffer. */
+ char *new_buf;
+ size_t needed = bytes + (e->ptr - e->buf);
+ size_t old_size = e->limit - e->buf;
+
+ size_t new_size = old_size;
+
+ while (new_size < needed) {
+ new_size *= 2;
+ }
+
+ new_buf = upb_env_realloc(e->env, e->buf, old_size, new_size);
+
+ if (new_buf == NULL) {
+ return false;
+ }
+
+ e->ptr = new_buf + (e->ptr - e->buf);
+ e->runbegin = new_buf + (e->runbegin - e->buf);
+ e->limit = new_buf + new_size;
+ e->buf = new_buf;
+ }
+
+ return true;
+}
+
+/* Call when "bytes" bytes have been writte at e->ptr. The caller *must* have
+ * previously called reserve() with at least this many bytes. */
+static void encoder_advance(upb_pb_encoder *e, size_t bytes) {
+ UPB_ASSERT((size_t)(e->limit - e->ptr) >= bytes);
+ e->ptr += bytes;
+}
+
+/* Call when all of the bytes for a handler have been written. Flushes the
+ * bytes if possible and necessary, returning false if this failed. */
+static bool commit(upb_pb_encoder *e) {
+ if (!e->top) {
+ /* We aren't inside a delimited region. Flush our accumulated bytes to
+ * the output.
+ *
+ * TODO(haberman): in the future we may want to delay flushing for
+ * efficiency reasons. */
+ putbuf(e, e->buf, e->ptr - e->buf);
+ e->ptr = e->buf;
+ }
+
+ return true;
+}
+
+/* Writes the given bytes to the buffer, handling reserve/advance. */
+static bool encode_bytes(upb_pb_encoder *e, const void *data, size_t len) {
+ if (!reserve(e, len)) {
+ return false;
+ }
+
+ memcpy(e->ptr, data, len);
+ encoder_advance(e, len);
+ return true;
+}
+
+/* Finish the current run by adding the run totals to the segment and message
+ * length. */
+static void accumulate(upb_pb_encoder *e) {
+ size_t run_len;
+ UPB_ASSERT(e->ptr >= e->runbegin);
+ run_len = e->ptr - e->runbegin;
+ e->segptr->seglen += run_len;
+ top(e)->msglen += run_len;
+ e->runbegin = e->ptr;
+}
+
+/* Call to indicate the start of delimited region for which the full length is
+ * not yet known. All data will be buffered until the length is known.
+ * Delimited regions may be nested; their lengths will all be tracked properly. */
+static bool start_delim(upb_pb_encoder *e) {
+ if (e->top) {
+ /* We are already buffering, advance to the next segment and push it on the
+ * stack. */
+ accumulate(e);
+
+ if (++e->top == e->stacklimit) {
+ /* TODO(haberman): grow stack? */
+ return false;
+ }
+
+ if (++e->segptr == e->seglimit) {
+ /* Grow segment buffer. */
+ size_t old_size =
+ (e->seglimit - e->segbuf) * sizeof(upb_pb_encoder_segment);
+ size_t new_size = old_size * 2;
+ upb_pb_encoder_segment *new_buf =
+ upb_env_realloc(e->env, e->segbuf, old_size, new_size);
+
+ if (new_buf == NULL) {
+ return false;
+ }
+
+ e->segptr = new_buf + (e->segptr - e->segbuf);
+ e->seglimit = new_buf + (new_size / sizeof(upb_pb_encoder_segment));
+ e->segbuf = new_buf;
+ }
+ } else {
+ /* We were previously at the top level, start buffering. */
+ e->segptr = e->segbuf;
+ e->top = e->stack;
+ e->runbegin = e->ptr;
+ }
+
+ *e->top = e->segptr - e->segbuf;
+ e->segptr->seglen = 0;
+ e->segptr->msglen = 0;
+
+ return true;
+}
+
+/* Call to indicate the end of a delimited region. We now know the length of
+ * the delimited region. If we are not nested inside any other delimited
+ * regions, we can now emit all of the buffered data we accumulated. */
+static bool end_delim(upb_pb_encoder *e) {
+ size_t msglen;
+ accumulate(e);
+ msglen = top(e)->msglen;
+
+ if (e->top == e->stack) {
+ /* All lengths are now available, emit all buffered data. */
+ char buf[UPB_PB_VARINT_MAX_LEN];
+ upb_pb_encoder_segment *s;
+ const char *ptr = e->buf;
+ for (s = e->segbuf; s <= e->segptr; s++) {
+ size_t lenbytes = upb_vencode64(s->msglen, buf);
+ putbuf(e, buf, lenbytes);
+ putbuf(e, ptr, s->seglen);
+ ptr += s->seglen;
+ }
+
+ e->ptr = e->buf;
+ e->top = NULL;
+ } else {
+ /* Need to keep buffering; propagate length info into enclosing
+ * submessages. */
+ --e->top;
+ top(e)->msglen += msglen + upb_varint_size(msglen);
+ }
+
+ return true;
+}
+
+
+/* tag_t **********************************************************************/
+
+/* A precomputed (pre-encoded) tag and length. */
+
+typedef struct {
+ uint8_t bytes;
+ char tag[7];
+} tag_t;
+
+/* Allocates a new tag for this field, and sets it in these handlerattr. */
+static void new_tag(upb_handlers *h, const upb_fielddef *f, upb_wiretype_t wt,
+ upb_handlerattr *attr) {
+ uint32_t n = upb_fielddef_number(f);
+
+ tag_t *tag = upb_gmalloc(sizeof(tag_t));
+ tag->bytes = upb_vencode64((n << 3) | wt, tag->tag);
+
+ upb_handlerattr_init(attr);
+ upb_handlerattr_sethandlerdata(attr, tag);
+ upb_handlers_addcleanup(h, tag, upb_gfree);
+}
+
+static bool encode_tag(upb_pb_encoder *e, const tag_t *tag) {
+ return encode_bytes(e, tag->tag, tag->bytes);
+}
+
+
+/* encoding of wire types *****************************************************/
+
+static bool encode_fixed64(upb_pb_encoder *e, uint64_t val) {
+ /* TODO(haberman): byte-swap for big endian. */
+ return encode_bytes(e, &val, sizeof(uint64_t));
+}
+
+static bool encode_fixed32(upb_pb_encoder *e, uint32_t val) {
+ /* TODO(haberman): byte-swap for big endian. */
+ return encode_bytes(e, &val, sizeof(uint32_t));
+}
+
+static bool encode_varint(upb_pb_encoder *e, uint64_t val) {
+ if (!reserve(e, UPB_PB_VARINT_MAX_LEN)) {
+ return false;
+ }
+
+ encoder_advance(e, upb_vencode64(val, e->ptr));
+ return true;
+}
+
+static uint64_t dbl2uint64(double d) {
+ uint64_t ret;
+ memcpy(&ret, &d, sizeof(uint64_t));
+ return ret;
+}
+
+static uint32_t flt2uint32(float d) {
+ uint32_t ret;
+ memcpy(&ret, &d, sizeof(uint32_t));
+ return ret;
+}
+
+
+/* encoding of proto types ****************************************************/
+
+static bool startmsg(void *c, const void *hd) {
+ upb_pb_encoder *e = c;
+ UPB_UNUSED(hd);
+ if (e->depth++ == 0) {
+ upb_bytessink_start(e->output_, 0, &e->subc);
+ }
+ return true;
+}
+
+static bool endmsg(void *c, const void *hd, upb_status *status) {
+ upb_pb_encoder *e = c;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(status);
+ if (--e->depth == 0) {
+ upb_bytessink_end(e->output_);
+ }
+ return true;
+}
+
+static void *encode_startdelimfield(void *c, const void *hd) {
+ bool ok = encode_tag(c, hd) && commit(c) && start_delim(c);
+ return ok ? c : UPB_BREAK;
+}
+
+static bool encode_enddelimfield(void *c, const void *hd) {
+ UPB_UNUSED(hd);
+ return end_delim(c);
+}
+
+static void *encode_startgroup(void *c, const void *hd) {
+ return (encode_tag(c, hd) && commit(c)) ? c : UPB_BREAK;
+}
+
+static bool encode_endgroup(void *c, const void *hd) {
+ return encode_tag(c, hd) && commit(c);
+}
+
+static void *encode_startstr(void *c, const void *hd, size_t size_hint) {
+ UPB_UNUSED(size_hint);
+ return encode_startdelimfield(c, hd);
+}
+
+static size_t encode_strbuf(void *c, const void *hd, const char *buf,
+ size_t len, const upb_bufhandle *h) {
+ UPB_UNUSED(hd);
+ UPB_UNUSED(h);
+ return encode_bytes(c, buf, len) ? len : 0;
+}
+
+#define T(type, ctype, convert, encode) \
+ static bool encode_scalar_##type(void *e, const void *hd, ctype val) { \
+ return encode_tag(e, hd) && encode(e, (convert)(val)) && commit(e); \
+ } \
+ static bool encode_packed_##type(void *e, const void *hd, ctype val) { \
+ UPB_UNUSED(hd); \
+ return encode(e, (convert)(val)); \
+ }
+
+T(double, double, dbl2uint64, encode_fixed64)
+T(float, float, flt2uint32, encode_fixed32)
+T(int64, int64_t, uint64_t, encode_varint)
+T(int32, int32_t, int64_t, encode_varint)
+T(fixed64, uint64_t, uint64_t, encode_fixed64)
+T(fixed32, uint32_t, uint32_t, encode_fixed32)
+T(bool, bool, bool, encode_varint)
+T(uint32, uint32_t, uint32_t, encode_varint)
+T(uint64, uint64_t, uint64_t, encode_varint)
+T(enum, int32_t, uint32_t, encode_varint)
+T(sfixed32, int32_t, uint32_t, encode_fixed32)
+T(sfixed64, int64_t, uint64_t, encode_fixed64)
+T(sint32, int32_t, upb_zzenc_32, encode_varint)
+T(sint64, int64_t, upb_zzenc_64, encode_varint)
+
+#undef T
+
+
+/* code to build the handlers *************************************************/
+
+static void newhandlers_callback(const void *closure, upb_handlers *h) {
+ const upb_msgdef *m;
+ upb_msg_field_iter i;
+
+ UPB_UNUSED(closure);
+
+ upb_handlers_setstartmsg(h, startmsg, NULL);
+ upb_handlers_setendmsg(h, endmsg, NULL);
+
+ m = upb_handlers_msgdef(h);
+ for(upb_msg_field_begin(&i, m);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ const upb_fielddef *f = upb_msg_iter_field(&i);
+ bool packed = upb_fielddef_isseq(f) && upb_fielddef_isprimitive(f) &&
+ upb_fielddef_packed(f);
+ upb_handlerattr attr;
+ upb_wiretype_t wt =
+ packed ? UPB_WIRE_TYPE_DELIMITED
+ : upb_pb_native_wire_types[upb_fielddef_descriptortype(f)];
+
+ /* Pre-encode the tag for this field. */
+ new_tag(h, f, wt, &attr);
+
+ if (packed) {
+ upb_handlers_setstartseq(h, f, encode_startdelimfield, &attr);
+ upb_handlers_setendseq(h, f, encode_enddelimfield, &attr);
+ }
+
+#define T(upper, lower, upbtype) \
+ case UPB_DESCRIPTOR_TYPE_##upper: \
+ if (packed) { \
+ upb_handlers_set##upbtype(h, f, encode_packed_##lower, &attr); \
+ } else { \
+ upb_handlers_set##upbtype(h, f, encode_scalar_##lower, &attr); \
+ } \
+ break;
+
+ switch (upb_fielddef_descriptortype(f)) {
+ T(DOUBLE, double, double);
+ T(FLOAT, float, float);
+ T(INT64, int64, int64);
+ T(INT32, int32, int32);
+ T(FIXED64, fixed64, uint64);
+ T(FIXED32, fixed32, uint32);
+ T(BOOL, bool, bool);
+ T(UINT32, uint32, uint32);
+ T(UINT64, uint64, uint64);
+ T(ENUM, enum, int32);
+ T(SFIXED32, sfixed32, int32);
+ T(SFIXED64, sfixed64, int64);
+ T(SINT32, sint32, int32);
+ T(SINT64, sint64, int64);
+ case UPB_DESCRIPTOR_TYPE_STRING:
+ case UPB_DESCRIPTOR_TYPE_BYTES:
+ upb_handlers_setstartstr(h, f, encode_startstr, &attr);
+ upb_handlers_setendstr(h, f, encode_enddelimfield, &attr);
+ upb_handlers_setstring(h, f, encode_strbuf, &attr);
+ break;
+ case UPB_DESCRIPTOR_TYPE_MESSAGE:
+ upb_handlers_setstartsubmsg(h, f, encode_startdelimfield, &attr);
+ upb_handlers_setendsubmsg(h, f, encode_enddelimfield, &attr);
+ break;
+ case UPB_DESCRIPTOR_TYPE_GROUP: {
+ /* Endgroup takes a different tag (wire_type = END_GROUP). */
+ upb_handlerattr attr2;
+ new_tag(h, f, UPB_WIRE_TYPE_END_GROUP, &attr2);
+
+ upb_handlers_setstartsubmsg(h, f, encode_startgroup, &attr);
+ upb_handlers_setendsubmsg(h, f, encode_endgroup, &attr2);
+
+ upb_handlerattr_uninit(&attr2);
+ break;
+ }
+ }
+
+#undef T
+
+ upb_handlerattr_uninit(&attr);
+ }
+}
+
+void upb_pb_encoder_reset(upb_pb_encoder *e) {
+ e->segptr = NULL;
+ e->top = NULL;
+ e->depth = 0;
+}
+
+
+/* public API *****************************************************************/
+
+const upb_handlers *upb_pb_encoder_newhandlers(const upb_msgdef *m,
+ const void *owner) {
+ return upb_handlers_newfrozen(m, owner, newhandlers_callback, NULL);
+}
+
+upb_pb_encoder *upb_pb_encoder_create(upb_env *env, const upb_handlers *h,
+ upb_bytessink *output) {
+ const size_t initial_bufsize = 256;
+ const size_t initial_segbufsize = 16;
+ /* TODO(haberman): make this configurable. */
+ const size_t stack_size = 64;
+#ifndef NDEBUG
+ const size_t size_before = upb_env_bytesallocated(env);
+#endif
+
+ upb_pb_encoder *e = upb_env_malloc(env, sizeof(upb_pb_encoder));
+ if (!e) return NULL;
+
+ e->buf = upb_env_malloc(env, initial_bufsize);
+ e->segbuf = upb_env_malloc(env, initial_segbufsize * sizeof(*e->segbuf));
+ e->stack = upb_env_malloc(env, stack_size * sizeof(*e->stack));
+
+ if (!e->buf || !e->segbuf || !e->stack) {
+ return NULL;
+ }
+
+ e->limit = e->buf + initial_bufsize;
+ e->seglimit = e->segbuf + initial_segbufsize;
+ e->stacklimit = e->stack + stack_size;
+
+ upb_pb_encoder_reset(e);
+ upb_sink_reset(&e->input_, h, e);
+
+ e->env = env;
+ e->output_ = output;
+ e->subc = output->closure;
+ e->ptr = e->buf;
+
+ /* If this fails, increase the value in encoder.h. */
+ UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(env) - size_before <=
+ UPB_PB_ENCODER_SIZE);
+ return e;
+}
+
+upb_sink *upb_pb_encoder_input(upb_pb_encoder *e) { return &e->input_; }
+
+
+
+upb_filedef **upb_loaddescriptor(const char *buf, size_t n, const void *owner,
+ upb_status *status) {
+ /* Create handlers. */
+ const upb_pbdecodermethod *decoder_m;
+ const upb_handlers *reader_h = upb_descreader_newhandlers(&reader_h);
+ upb_env env;
+ upb_pbdecodermethodopts opts;
+ upb_pbdecoder *decoder;
+ upb_descreader *reader;
+ bool ok;
+ size_t i;
+ upb_filedef **ret = NULL;
+
+ upb_pbdecodermethodopts_init(&opts, reader_h);
+ decoder_m = upb_pbdecodermethod_new(&opts, &decoder_m);
+
+ upb_env_init(&env);
+ upb_env_reporterrorsto(&env, status);
+
+ reader = upb_descreader_create(&env, reader_h);
+ decoder = upb_pbdecoder_create(&env, decoder_m, upb_descreader_input(reader));
+
+ /* Push input data. */
+ ok = upb_bufsrc_putbuf(buf, n, upb_pbdecoder_input(decoder));
+
+ if (!ok) {
+ goto cleanup;
+ }
+
+ ret = upb_gmalloc(sizeof (*ret) * (upb_descreader_filecount(reader) + 1));
+
+ if (!ret) {
+ goto cleanup;
+ }
+
+ for (i = 0; i < upb_descreader_filecount(reader); i++) {
+ ret[i] = upb_descreader_file(reader, i);
+ upb_filedef_ref(ret[i], owner);
+ }
+
+ ret[i] = NULL;
+
+cleanup:
+ upb_env_uninit(&env);
+ upb_handlers_unref(reader_h, &reader_h);
+ upb_pbdecodermethod_unref(decoder_m, &decoder_m);
+ return ret;
+}
+/*
+ * upb::pb::TextPrinter
+ *
+ * OPT: This is not optimized at all. It uses printf() which parses the format
+ * string every time, and it allocates memory for every put.
+ */
+
+
+#include <ctype.h>
+#include <float.h>
+#include <inttypes.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+
+
+struct upb_textprinter {
+ upb_sink input_;
+ upb_bytessink *output_;
+ int indent_depth_;
+ bool single_line_;
+ void *subc;
+};
+
+#define CHECK(x) if ((x) < 0) goto err;
+
+static const char *shortname(const char *longname) {
+ const char *last = strrchr(longname, '.');
+ return last ? last + 1 : longname;
+}
+
+static int indent(upb_textprinter *p) {
+ int i;
+ if (!p->single_line_)
+ for (i = 0; i < p->indent_depth_; i++)
+ upb_bytessink_putbuf(p->output_, p->subc, " ", 2, NULL);
+ return 0;
+}
+
+static int endfield(upb_textprinter *p) {
+ const char ch = (p->single_line_ ? ' ' : '\n');
+ upb_bytessink_putbuf(p->output_, p->subc, &ch, 1, NULL);
+ return 0;
+}
+
+static int putescaped(upb_textprinter *p, const char *buf, size_t len,
+ bool preserve_utf8) {
+ /* Based on CEscapeInternal() from Google's protobuf release. */
+ char dstbuf[4096], *dst = dstbuf, *dstend = dstbuf + sizeof(dstbuf);
+ const char *end = buf + len;
+
+ /* I think hex is prettier and more useful, but proto2 uses octal; should
+ * investigate whether it can parse hex also. */
+ const bool use_hex = false;
+ bool last_hex_escape = false; /* true if last output char was \xNN */
+
+ for (; buf < end; buf++) {
+ bool is_hex_escape;
+
+ if (dstend - dst < 4) {
+ upb_bytessink_putbuf(p->output_, p->subc, dstbuf, dst - dstbuf, NULL);
+ dst = dstbuf;
+ }
+
+ is_hex_escape = false;
+ switch (*buf) {
+ case '\n': *(dst++) = '\\'; *(dst++) = 'n'; break;
+ case '\r': *(dst++) = '\\'; *(dst++) = 'r'; break;
+ case '\t': *(dst++) = '\\'; *(dst++) = 't'; break;
+ case '\"': *(dst++) = '\\'; *(dst++) = '\"'; break;
+ case '\'': *(dst++) = '\\'; *(dst++) = '\''; break;
+ case '\\': *(dst++) = '\\'; *(dst++) = '\\'; break;
+ default:
+ /* Note that if we emit \xNN and the buf character after that is a hex
+ * digit then that digit must be escaped too to prevent it being
+ * interpreted as part of the character code by C. */
+ if ((!preserve_utf8 || (uint8_t)*buf < 0x80) &&
+ (!isprint(*buf) || (last_hex_escape && isxdigit(*buf)))) {
+ sprintf(dst, (use_hex ? "\\x%02x" : "\\%03o"), (uint8_t)*buf);
+ is_hex_escape = use_hex;
+ dst += 4;
+ } else {
+ *(dst++) = *buf; break;
+ }
+ }
+ last_hex_escape = is_hex_escape;
+ }
+ /* Flush remaining data. */
+ upb_bytessink_putbuf(p->output_, p->subc, dstbuf, dst - dstbuf, NULL);
+ return 0;
+}
+
+bool putf(upb_textprinter *p, const char *fmt, ...) {
+ va_list args;
+ va_list args_copy;
+ char *str;
+ int written;
+ int len;
+ bool ok;
+
+ va_start(args, fmt);
+
+ /* Run once to get the length of the string. */
+ _upb_va_copy(args_copy, args);
+ len = _upb_vsnprintf(NULL, 0, fmt, args_copy);
+ va_end(args_copy);
+
+ /* + 1 for NULL terminator (vsprintf() requires it even if we don't). */
+ str = upb_gmalloc(len + 1);
+ if (!str) return false;
+ written = vsprintf(str, fmt, args);
+ va_end(args);
+ UPB_ASSERT(written == len);
+
+ ok = upb_bytessink_putbuf(p->output_, p->subc, str, len, NULL);
+ upb_gfree(str);
+ return ok;
+}
+
+
+/* handlers *******************************************************************/
+
+static bool textprinter_startmsg(void *c, const void *hd) {
+ upb_textprinter *p = c;
+ UPB_UNUSED(hd);
+ if (p->indent_depth_ == 0) {
+ upb_bytessink_start(p->output_, 0, &p->subc);
+ }
+ return true;
+}
+
+static bool textprinter_endmsg(void *c, const void *hd, upb_status *s) {
+ upb_textprinter *p = c;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(s);
+ if (p->indent_depth_ == 0) {
+ upb_bytessink_end(p->output_);
+ }
+ return true;
+}
+
+#define TYPE(name, ctype, fmt) \
+ static bool textprinter_put ## name(void *closure, const void *handler_data, \
+ ctype val) { \
+ upb_textprinter *p = closure; \
+ const upb_fielddef *f = handler_data; \
+ CHECK(indent(p)); \
+ putf(p, "%s: " fmt, upb_fielddef_name(f), val); \
+ CHECK(endfield(p)); \
+ return true; \
+ err: \
+ return false; \
+}
+
+static bool textprinter_putbool(void *closure, const void *handler_data,
+ bool val) {
+ upb_textprinter *p = closure;
+ const upb_fielddef *f = handler_data;
+ CHECK(indent(p));
+ putf(p, "%s: %s", upb_fielddef_name(f), val ? "true" : "false");
+ CHECK(endfield(p));
+ return true;
+err:
+ return false;
+}
+
+#define STRINGIFY_HELPER(x) #x
+#define STRINGIFY_MACROVAL(x) STRINGIFY_HELPER(x)
+
+TYPE(int32, int32_t, "%" PRId32)
+TYPE(int64, int64_t, "%" PRId64)
+TYPE(uint32, uint32_t, "%" PRIu32)
+TYPE(uint64, uint64_t, "%" PRIu64)
+TYPE(float, float, "%." STRINGIFY_MACROVAL(FLT_DIG) "g")
+TYPE(double, double, "%." STRINGIFY_MACROVAL(DBL_DIG) "g")
+
+#undef TYPE
+
+/* Output a symbolic value from the enum if found, else just print as int32. */
+static bool textprinter_putenum(void *closure, const void *handler_data,
+ int32_t val) {
+ upb_textprinter *p = closure;
+ const upb_fielddef *f = handler_data;
+ const upb_enumdef *enum_def = upb_downcast_enumdef(upb_fielddef_subdef(f));
+ const char *label = upb_enumdef_iton(enum_def, val);
+ if (label) {
+ indent(p);
+ putf(p, "%s: %s", upb_fielddef_name(f), label);
+ endfield(p);
+ } else {
+ if (!textprinter_putint32(closure, handler_data, val))
+ return false;
+ }
+ return true;
+}
+
+static void *textprinter_startstr(void *closure, const void *handler_data,
+ size_t size_hint) {
+ upb_textprinter *p = closure;
+ const upb_fielddef *f = handler_data;
+ UPB_UNUSED(size_hint);
+ indent(p);
+ putf(p, "%s: \"", upb_fielddef_name(f));
+ return p;
+}
+
+static bool textprinter_endstr(void *closure, const void *handler_data) {
+ upb_textprinter *p = closure;
+ UPB_UNUSED(handler_data);
+ putf(p, "\"");
+ endfield(p);
+ return true;
+}
+
+static size_t textprinter_putstr(void *closure, const void *hd, const char *buf,
+ size_t len, const upb_bufhandle *handle) {
+ upb_textprinter *p = closure;
+ const upb_fielddef *f = hd;
+ UPB_UNUSED(handle);
+ CHECK(putescaped(p, buf, len, upb_fielddef_type(f) == UPB_TYPE_STRING));
+ return len;
+err:
+ return 0;
+}
+
+static void *textprinter_startsubmsg(void *closure, const void *handler_data) {
+ upb_textprinter *p = closure;
+ const char *name = handler_data;
+ CHECK(indent(p));
+ putf(p, "%s {%c", name, p->single_line_ ? ' ' : '\n');
+ p->indent_depth_++;
+ return p;
+err:
+ return UPB_BREAK;
+}
+
+static bool textprinter_endsubmsg(void *closure, const void *handler_data) {
+ upb_textprinter *p = closure;
+ UPB_UNUSED(handler_data);
+ p->indent_depth_--;
+ CHECK(indent(p));
+ upb_bytessink_putbuf(p->output_, p->subc, "}", 1, NULL);
+ CHECK(endfield(p));
+ return true;
+err:
+ return false;
+}
+
+static void onmreg(const void *c, upb_handlers *h) {
+ const upb_msgdef *m = upb_handlers_msgdef(h);
+ upb_msg_field_iter i;
+ UPB_UNUSED(c);
+
+ upb_handlers_setstartmsg(h, textprinter_startmsg, NULL);
+ upb_handlers_setendmsg(h, textprinter_endmsg, NULL);
+
+ for(upb_msg_field_begin(&i, m);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ upb_fielddef *f = upb_msg_iter_field(&i);
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_handlerattr_sethandlerdata(&attr, f);
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_INT32:
+ upb_handlers_setint32(h, f, textprinter_putint32, &attr);
+ break;
+ case UPB_TYPE_INT64:
+ upb_handlers_setint64(h, f, textprinter_putint64, &attr);
+ break;
+ case UPB_TYPE_UINT32:
+ upb_handlers_setuint32(h, f, textprinter_putuint32, &attr);
+ break;
+ case UPB_TYPE_UINT64:
+ upb_handlers_setuint64(h, f, textprinter_putuint64, &attr);
+ break;
+ case UPB_TYPE_FLOAT:
+ upb_handlers_setfloat(h, f, textprinter_putfloat, &attr);
+ break;
+ case UPB_TYPE_DOUBLE:
+ upb_handlers_setdouble(h, f, textprinter_putdouble, &attr);
+ break;
+ case UPB_TYPE_BOOL:
+ upb_handlers_setbool(h, f, textprinter_putbool, &attr);
+ break;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ upb_handlers_setstartstr(h, f, textprinter_startstr, &attr);
+ upb_handlers_setstring(h, f, textprinter_putstr, &attr);
+ upb_handlers_setendstr(h, f, textprinter_endstr, &attr);
+ break;
+ case UPB_TYPE_MESSAGE: {
+ const char *name =
+ upb_fielddef_istagdelim(f)
+ ? shortname(upb_msgdef_fullname(upb_fielddef_msgsubdef(f)))
+ : upb_fielddef_name(f);
+ upb_handlerattr_sethandlerdata(&attr, name);
+ upb_handlers_setstartsubmsg(h, f, textprinter_startsubmsg, &attr);
+ upb_handlers_setendsubmsg(h, f, textprinter_endsubmsg, &attr);
+ break;
+ }
+ case UPB_TYPE_ENUM:
+ upb_handlers_setint32(h, f, textprinter_putenum, &attr);
+ break;
+ }
+ }
+}
+
+static void textprinter_reset(upb_textprinter *p, bool single_line) {
+ p->single_line_ = single_line;
+ p->indent_depth_ = 0;
+}
+
+
+/* Public API *****************************************************************/
+
+upb_textprinter *upb_textprinter_create(upb_env *env, const upb_handlers *h,
+ upb_bytessink *output) {
+ upb_textprinter *p = upb_env_malloc(env, sizeof(upb_textprinter));
+ if (!p) return NULL;
+
+ p->output_ = output;
+ upb_sink_reset(&p->input_, h, p);
+ textprinter_reset(p, false);
+
+ return p;
+}
+
+const upb_handlers *upb_textprinter_newhandlers(const upb_msgdef *m,
+ const void *owner) {
+ return upb_handlers_newfrozen(m, owner, &onmreg, NULL);
+}
+
+upb_sink *upb_textprinter_input(upb_textprinter *p) { return &p->input_; }
+
+void upb_textprinter_setsingleline(upb_textprinter *p, bool single_line) {
+ p->single_line_ = single_line;
+}
+
+
+/* Index is descriptor type. */
+const uint8_t upb_pb_native_wire_types[] = {
+ UPB_WIRE_TYPE_END_GROUP, /* ENDGROUP */
+ UPB_WIRE_TYPE_64BIT, /* DOUBLE */
+ UPB_WIRE_TYPE_32BIT, /* FLOAT */
+ UPB_WIRE_TYPE_VARINT, /* INT64 */
+ UPB_WIRE_TYPE_VARINT, /* UINT64 */
+ UPB_WIRE_TYPE_VARINT, /* INT32 */
+ UPB_WIRE_TYPE_64BIT, /* FIXED64 */
+ UPB_WIRE_TYPE_32BIT, /* FIXED32 */
+ UPB_WIRE_TYPE_VARINT, /* BOOL */
+ UPB_WIRE_TYPE_DELIMITED, /* STRING */
+ UPB_WIRE_TYPE_START_GROUP, /* GROUP */
+ UPB_WIRE_TYPE_DELIMITED, /* MESSAGE */
+ UPB_WIRE_TYPE_DELIMITED, /* BYTES */
+ UPB_WIRE_TYPE_VARINT, /* UINT32 */
+ UPB_WIRE_TYPE_VARINT, /* ENUM */
+ UPB_WIRE_TYPE_32BIT, /* SFIXED32 */
+ UPB_WIRE_TYPE_64BIT, /* SFIXED64 */
+ UPB_WIRE_TYPE_VARINT, /* SINT32 */
+ UPB_WIRE_TYPE_VARINT, /* SINT64 */
+};
+
+/* A basic branch-based decoder, uses 32-bit values to get good performance
+ * on 32-bit architectures (but performs well on 64-bits also).
+ * This scheme comes from the original Google Protobuf implementation
+ * (proto2). */
+upb_decoderet upb_vdecode_max8_branch32(upb_decoderet r) {
+ upb_decoderet err = {NULL, 0};
+ const char *p = r.p;
+ uint32_t low = (uint32_t)r.val;
+ uint32_t high = 0;
+ uint32_t b;
+ b = *(p++); low |= (b & 0x7fU) << 14; if (!(b & 0x80)) goto done;
+ b = *(p++); low |= (b & 0x7fU) << 21; if (!(b & 0x80)) goto done;
+ b = *(p++); low |= (b & 0x7fU) << 28;
+ high = (b & 0x7fU) >> 4; if (!(b & 0x80)) goto done;
+ b = *(p++); high |= (b & 0x7fU) << 3; if (!(b & 0x80)) goto done;
+ b = *(p++); high |= (b & 0x7fU) << 10; if (!(b & 0x80)) goto done;
+ b = *(p++); high |= (b & 0x7fU) << 17; if (!(b & 0x80)) goto done;
+ b = *(p++); high |= (b & 0x7fU) << 24; if (!(b & 0x80)) goto done;
+ b = *(p++); high |= (b & 0x7fU) << 31; if (!(b & 0x80)) goto done;
+ return err;
+
+done:
+ r.val = ((uint64_t)high << 32) | low;
+ r.p = p;
+ return r;
+}
+
+/* Like the previous, but uses 64-bit values. */
+upb_decoderet upb_vdecode_max8_branch64(upb_decoderet r) {
+ const char *p = r.p;
+ uint64_t val = r.val;
+ uint64_t b;
+ upb_decoderet err = {NULL, 0};
+ b = *(p++); val |= (b & 0x7fU) << 14; if (!(b & 0x80)) goto done;
+ b = *(p++); val |= (b & 0x7fU) << 21; if (!(b & 0x80)) goto done;
+ b = *(p++); val |= (b & 0x7fU) << 28; if (!(b & 0x80)) goto done;
+ b = *(p++); val |= (b & 0x7fU) << 35; if (!(b & 0x80)) goto done;
+ b = *(p++); val |= (b & 0x7fU) << 42; if (!(b & 0x80)) goto done;
+ b = *(p++); val |= (b & 0x7fU) << 49; if (!(b & 0x80)) goto done;
+ b = *(p++); val |= (b & 0x7fU) << 56; if (!(b & 0x80)) goto done;
+ b = *(p++); val |= (b & 0x7fU) << 63; if (!(b & 0x80)) goto done;
+ return err;
+
+done:
+ r.val = val;
+ r.p = p;
+ return r;
+}
+
+/* Given an encoded varint v, returns an integer with a single bit set that
+ * indicates the end of the varint. Subtracting one from this value will
+ * yield a mask that leaves only bits that are part of the varint. Returns
+ * 0 if the varint is unterminated. */
+static uint64_t upb_get_vstopbit(uint64_t v) {
+ uint64_t cbits = v | 0x7f7f7f7f7f7f7f7fULL;
+ return ~cbits & (cbits+1);
+}
+
+/* A branchless decoder. Credit to Pascal Massimino for the bit-twiddling. */
+upb_decoderet upb_vdecode_max8_massimino(upb_decoderet r) {
+ uint64_t b;
+ uint64_t stop_bit;
+ upb_decoderet my_r;
+ memcpy(&b, r.p, sizeof(b));
+ stop_bit = upb_get_vstopbit(b);
+ b = (b & 0x7f7f7f7f7f7f7f7fULL) & (stop_bit - 1);
+ b += b & 0x007f007f007f007fULL;
+ b += 3 * (b & 0x0000ffff0000ffffULL);
+ b += 15 * (b & 0x00000000ffffffffULL);
+ if (stop_bit == 0) {
+ /* Error: unterminated varint. */
+ upb_decoderet err_r = {(void*)0, 0};
+ return err_r;
+ }
+ my_r = upb_decoderet_make(r.p + ((__builtin_ctzll(stop_bit) + 1) / 8),
+ r.val | (b << 7));
+ return my_r;
+}
+
+/* A branchless decoder. Credit to Daniel Wright for the bit-twiddling. */
+upb_decoderet upb_vdecode_max8_wright(upb_decoderet r) {
+ uint64_t b;
+ uint64_t stop_bit;
+ upb_decoderet my_r;
+ memcpy(&b, r.p, sizeof(b));
+ stop_bit = upb_get_vstopbit(b);
+ b &= (stop_bit - 1);
+ b = ((b & 0x7f007f007f007f00ULL) >> 1) | (b & 0x007f007f007f007fULL);
+ b = ((b & 0xffff0000ffff0000ULL) >> 2) | (b & 0x0000ffff0000ffffULL);
+ b = ((b & 0xffffffff00000000ULL) >> 4) | (b & 0x00000000ffffffffULL);
+ if (stop_bit == 0) {
+ /* Error: unterminated varint. */
+ upb_decoderet err_r = {(void*)0, 0};
+ return err_r;
+ }
+ my_r = upb_decoderet_make(r.p + ((__builtin_ctzll(stop_bit) + 1) / 8),
+ r.val | (b << 14));
+ return my_r;
+}
+
+#line 1 "upb/json/parser.rl"
+/*
+** upb::json::Parser (upb_json_parser)
+**
+** A parser that uses the Ragel State Machine Compiler to generate
+** the finite automata.
+**
+** Ragel only natively handles regular languages, but we can manually
+** program it a bit to handle context-free languages like JSON, by using
+** the "fcall" and "fret" constructs.
+**
+** This parser can handle the basics, but needs several things to be fleshed
+** out:
+**
+** - handling of unicode escape sequences (including high surrogate pairs).
+** - properly check and report errors for unknown fields, stack overflow,
+** improper array nesting (or lack of nesting).
+** - handling of base64 sequences with padding characters.
+** - handling of push-back (non-success returns from sink functions).
+** - handling of keys/escape-sequences/etc that span input buffers.
+*/
+
+#include <assert.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+#define UPB_JSON_MAX_DEPTH 64
+
+typedef struct {
+ upb_sink sink;
+
+ /* The current message in which we're parsing, and the field whose value we're
+ * expecting next. */
+ const upb_msgdef *m;
+ const upb_fielddef *f;
+
+ /* The table mapping json name to fielddef for this message. */
+ upb_strtable *name_table;
+
+ /* We are in a repeated-field context, ready to emit mapentries as
+ * submessages. This flag alters the start-of-object (open-brace) behavior to
+ * begin a sequence of mapentry messages rather than a single submessage. */
+ bool is_map;
+
+ /* We are in a map-entry message context. This flag is set when parsing the
+ * value field of a single map entry and indicates to all value-field parsers
+ * (subobjects, strings, numbers, and bools) that the map-entry submessage
+ * should end as soon as the value is parsed. */
+ bool is_mapentry;
+
+ /* If |is_map| or |is_mapentry| is true, |mapfield| refers to the parent
+ * message's map field that we're currently parsing. This differs from |f|
+ * because |f| is the field in the *current* message (i.e., the map-entry
+ * message itself), not the parent's field that leads to this map. */
+ const upb_fielddef *mapfield;
+} upb_jsonparser_frame;
+
+struct upb_json_parser {
+ upb_env *env;
+ const upb_json_parsermethod *method;
+ upb_bytessink input_;
+
+ /* Stack to track the JSON scopes we are in. */
+ upb_jsonparser_frame stack[UPB_JSON_MAX_DEPTH];
+ upb_jsonparser_frame *top;
+ upb_jsonparser_frame *limit;
+
+ upb_status status;
+
+ /* Ragel's internal parsing stack for the parsing state machine. */
+ int current_state;
+ int parser_stack[UPB_JSON_MAX_DEPTH];
+ int parser_top;
+
+ /* The handle for the current buffer. */
+ const upb_bufhandle *handle;
+
+ /* Accumulate buffer. See details in parser.rl. */
+ const char *accumulated;
+ size_t accumulated_len;
+ char *accumulate_buf;
+ size_t accumulate_buf_size;
+
+ /* Multi-part text data. See details in parser.rl. */
+ int multipart_state;
+ upb_selector_t string_selector;
+
+ /* Input capture. See details in parser.rl. */
+ const char *capture;
+
+ /* Intermediate result of parsing a unicode escape sequence. */
+ uint32_t digit;
+};
+
+struct upb_json_parsermethod {
+ upb_refcounted base;
+
+ upb_byteshandler input_handler_;
+
+ /* Mainly for the purposes of refcounting, so all the fielddefs we point
+ * to stay alive. */
+ const upb_msgdef *msg;
+
+ /* Keys are upb_msgdef*, values are upb_strtable (json_name -> fielddef) */
+ upb_inttable name_tables;
+};
+
+#define PARSER_CHECK_RETURN(x) if (!(x)) return false
+
+/* Used to signal that a capture has been suspended. */
+static char suspend_capture;
+
+static upb_selector_t getsel_for_handlertype(upb_json_parser *p,
+ upb_handlertype_t type) {
+ upb_selector_t sel;
+ bool ok = upb_handlers_getselector(p->top->f, type, &sel);
+ UPB_ASSERT(ok);
+ return sel;
+}
+
+static upb_selector_t parser_getsel(upb_json_parser *p) {
+ return getsel_for_handlertype(
+ p, upb_handlers_getprimitivehandlertype(p->top->f));
+}
+
+static bool check_stack(upb_json_parser *p) {
+ if ((p->top + 1) == p->limit) {
+ upb_status_seterrmsg(&p->status, "Nesting too deep");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ return true;
+}
+
+static void set_name_table(upb_json_parser *p, upb_jsonparser_frame *frame) {
+ upb_value v;
+ bool ok = upb_inttable_lookupptr(&p->method->name_tables, frame->m, &v);
+ UPB_ASSERT(ok);
+ frame->name_table = upb_value_getptr(v);
+}
+
+/* There are GCC/Clang built-ins for overflow checking which we could start
+ * using if there was any performance benefit to it. */
+
+static bool checked_add(size_t a, size_t b, size_t *c) {
+ if (SIZE_MAX - a < b) return false;
+ *c = a + b;
+ return true;
+}
+
+static size_t saturating_multiply(size_t a, size_t b) {
+ /* size_t is unsigned, so this is defined behavior even on overflow. */
+ size_t ret = a * b;
+ if (b != 0 && ret / b != a) {
+ ret = SIZE_MAX;
+ }
+ return ret;
+}
+
+
+/* Base64 decoding ************************************************************/
+
+/* TODO(haberman): make this streaming. */
+
+static const signed char b64table[] = {
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 62/*+*/, -1, -1, -1, 63/*/ */,
+ 52/*0*/, 53/*1*/, 54/*2*/, 55/*3*/, 56/*4*/, 57/*5*/, 58/*6*/, 59/*7*/,
+ 60/*8*/, 61/*9*/, -1, -1, -1, -1, -1, -1,
+ -1, 0/*A*/, 1/*B*/, 2/*C*/, 3/*D*/, 4/*E*/, 5/*F*/, 6/*G*/,
+ 07/*H*/, 8/*I*/, 9/*J*/, 10/*K*/, 11/*L*/, 12/*M*/, 13/*N*/, 14/*O*/,
+ 15/*P*/, 16/*Q*/, 17/*R*/, 18/*S*/, 19/*T*/, 20/*U*/, 21/*V*/, 22/*W*/,
+ 23/*X*/, 24/*Y*/, 25/*Z*/, -1, -1, -1, -1, -1,
+ -1, 26/*a*/, 27/*b*/, 28/*c*/, 29/*d*/, 30/*e*/, 31/*f*/, 32/*g*/,
+ 33/*h*/, 34/*i*/, 35/*j*/, 36/*k*/, 37/*l*/, 38/*m*/, 39/*n*/, 40/*o*/,
+ 41/*p*/, 42/*q*/, 43/*r*/, 44/*s*/, 45/*t*/, 46/*u*/, 47/*v*/, 48/*w*/,
+ 49/*x*/, 50/*y*/, 51/*z*/, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1
+};
+
+/* Returns the table value sign-extended to 32 bits. Knowing that the upper
+ * bits will be 1 for unrecognized characters makes it easier to check for
+ * this error condition later (see below). */
+int32_t b64lookup(unsigned char ch) { return b64table[ch]; }
+
+/* Returns true if the given character is not a valid base64 character or
+ * padding. */
+bool nonbase64(unsigned char ch) { return b64lookup(ch) == -1 && ch != '='; }
+
+static bool base64_push(upb_json_parser *p, upb_selector_t sel, const char *ptr,
+ size_t len) {
+ const char *limit = ptr + len;
+ for (; ptr < limit; ptr += 4) {
+ uint32_t val;
+ char output[3];
+
+ if (limit - ptr < 4) {
+ upb_status_seterrf(&p->status,
+ "Base64 input for bytes field not a multiple of 4: %s",
+ upb_fielddef_name(p->top->f));
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ val = b64lookup(ptr[0]) << 18 |
+ b64lookup(ptr[1]) << 12 |
+ b64lookup(ptr[2]) << 6 |
+ b64lookup(ptr[3]);
+
+ /* Test the upper bit; returns true if any of the characters returned -1. */
+ if (val & 0x80000000) {
+ goto otherchar;
+ }
+
+ output[0] = val >> 16;
+ output[1] = (val >> 8) & 0xff;
+ output[2] = val & 0xff;
+ upb_sink_putstring(&p->top->sink, sel, output, 3, NULL);
+ }
+ return true;
+
+otherchar:
+ if (nonbase64(ptr[0]) || nonbase64(ptr[1]) || nonbase64(ptr[2]) ||
+ nonbase64(ptr[3]) ) {
+ upb_status_seterrf(&p->status,
+ "Non-base64 characters in bytes field: %s",
+ upb_fielddef_name(p->top->f));
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ } if (ptr[2] == '=') {
+ uint32_t val;
+ char output;
+
+ /* Last group contains only two input bytes, one output byte. */
+ if (ptr[0] == '=' || ptr[1] == '=' || ptr[3] != '=') {
+ goto badpadding;
+ }
+
+ val = b64lookup(ptr[0]) << 18 |
+ b64lookup(ptr[1]) << 12;
+
+ UPB_ASSERT(!(val & 0x80000000));
+ output = val >> 16;
+ upb_sink_putstring(&p->top->sink, sel, &output, 1, NULL);
+ return true;
+ } else {
+ uint32_t val;
+ char output[2];
+
+ /* Last group contains only three input bytes, two output bytes. */
+ if (ptr[0] == '=' || ptr[1] == '=' || ptr[2] == '=') {
+ goto badpadding;
+ }
+
+ val = b64lookup(ptr[0]) << 18 |
+ b64lookup(ptr[1]) << 12 |
+ b64lookup(ptr[2]) << 6;
+
+ output[0] = val >> 16;
+ output[1] = (val >> 8) & 0xff;
+ upb_sink_putstring(&p->top->sink, sel, output, 2, NULL);
+ return true;
+ }
+
+badpadding:
+ upb_status_seterrf(&p->status,
+ "Incorrect base64 padding for field: %s (%.*s)",
+ upb_fielddef_name(p->top->f),
+ 4, ptr);
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+}
+
+
+/* Accumulate buffer **********************************************************/
+
+/* Functionality for accumulating a buffer.
+ *
+ * Some parts of the parser need an entire value as a contiguous string. For
+ * example, to look up a member name in a hash table, or to turn a string into
+ * a number, the relevant library routines need the input string to be in
+ * contiguous memory, even if the value spanned two or more buffers in the
+ * input. These routines handle that.
+ *
+ * In the common case we can just point to the input buffer to get this
+ * contiguous string and avoid any actual copy. So we optimistically begin
+ * this way. But there are a few cases where we must instead copy into a
+ * separate buffer:
+ *
+ * 1. The string was not contiguous in the input (it spanned buffers).
+ *
+ * 2. The string included escape sequences that need to be interpreted to get
+ * the true value in a contiguous buffer. */
+
+static void assert_accumulate_empty(upb_json_parser *p) {
+ UPB_ASSERT(p->accumulated == NULL);
+ UPB_ASSERT(p->accumulated_len == 0);
+}
+
+static void accumulate_clear(upb_json_parser *p) {
+ p->accumulated = NULL;
+ p->accumulated_len = 0;
+}
+
+/* Used internally by accumulate_append(). */
+static bool accumulate_realloc(upb_json_parser *p, size_t need) {
+ void *mem;
+ size_t old_size = p->accumulate_buf_size;
+ size_t new_size = UPB_MAX(old_size, 128);
+ while (new_size < need) {
+ new_size = saturating_multiply(new_size, 2);
+ }
+
+ mem = upb_env_realloc(p->env, p->accumulate_buf, old_size, new_size);
+ if (!mem) {
+ upb_status_seterrmsg(&p->status, "Out of memory allocating buffer.");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ p->accumulate_buf = mem;
+ p->accumulate_buf_size = new_size;
+ return true;
+}
+
+/* Logically appends the given data to the append buffer.
+ * If "can_alias" is true, we will try to avoid actually copying, but the buffer
+ * must be valid until the next accumulate_append() call (if any). */
+static bool accumulate_append(upb_json_parser *p, const char *buf, size_t len,
+ bool can_alias) {
+ size_t need;
+
+ if (!p->accumulated && can_alias) {
+ p->accumulated = buf;
+ p->accumulated_len = len;
+ return true;
+ }
+
+ if (!checked_add(p->accumulated_len, len, &need)) {
+ upb_status_seterrmsg(&p->status, "Integer overflow.");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ if (need > p->accumulate_buf_size && !accumulate_realloc(p, need)) {
+ return false;
+ }
+
+ if (p->accumulated != p->accumulate_buf) {
+ memcpy(p->accumulate_buf, p->accumulated, p->accumulated_len);
+ p->accumulated = p->accumulate_buf;
+ }
+
+ memcpy(p->accumulate_buf + p->accumulated_len, buf, len);
+ p->accumulated_len += len;
+ return true;
+}
+
+/* Returns a pointer to the data accumulated since the last accumulate_clear()
+ * call, and writes the length to *len. This with point either to the input
+ * buffer or a temporary accumulate buffer. */
+static const char *accumulate_getptr(upb_json_parser *p, size_t *len) {
+ UPB_ASSERT(p->accumulated);
+ *len = p->accumulated_len;
+ return p->accumulated;
+}
+
+
+/* Mult-part text data ********************************************************/
+
+/* When we have text data in the input, it can often come in multiple segments.
+ * For example, there may be some raw string data followed by an escape
+ * sequence. The two segments are processed with different logic. Also buffer
+ * seams in the input can cause multiple segments.
+ *
+ * As we see segments, there are two main cases for how we want to process them:
+ *
+ * 1. we want to push the captured input directly to string handlers.
+ *
+ * 2. we need to accumulate all the parts into a contiguous buffer for further
+ * processing (field name lookup, string->number conversion, etc). */
+
+/* This is the set of states for p->multipart_state. */
+enum {
+ /* We are not currently processing multipart data. */
+ MULTIPART_INACTIVE = 0,
+
+ /* We are processing multipart data by accumulating it into a contiguous
+ * buffer. */
+ MULTIPART_ACCUMULATE = 1,
+
+ /* We are processing multipart data by pushing each part directly to the
+ * current string handlers. */
+ MULTIPART_PUSHEAGERLY = 2
+};
+
+/* Start a multi-part text value where we accumulate the data for processing at
+ * the end. */
+static void multipart_startaccum(upb_json_parser *p) {
+ assert_accumulate_empty(p);
+ UPB_ASSERT(p->multipart_state == MULTIPART_INACTIVE);
+ p->multipart_state = MULTIPART_ACCUMULATE;
+}
+
+/* Start a multi-part text value where we immediately push text data to a string
+ * value with the given selector. */
+static void multipart_start(upb_json_parser *p, upb_selector_t sel) {
+ assert_accumulate_empty(p);
+ UPB_ASSERT(p->multipart_state == MULTIPART_INACTIVE);
+ p->multipart_state = MULTIPART_PUSHEAGERLY;
+ p->string_selector = sel;
+}
+
+static bool multipart_text(upb_json_parser *p, const char *buf, size_t len,
+ bool can_alias) {
+ switch (p->multipart_state) {
+ case MULTIPART_INACTIVE:
+ upb_status_seterrmsg(
+ &p->status, "Internal error: unexpected state MULTIPART_INACTIVE");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+
+ case MULTIPART_ACCUMULATE:
+ if (!accumulate_append(p, buf, len, can_alias)) {
+ return false;
+ }
+ break;
+
+ case MULTIPART_PUSHEAGERLY: {
+ const upb_bufhandle *handle = can_alias ? p->handle : NULL;
+ upb_sink_putstring(&p->top->sink, p->string_selector, buf, len, handle);
+ break;
+ }
+ }
+
+ return true;
+}
+
+/* Note: this invalidates the accumulate buffer! Call only after reading its
+ * contents. */
+static void multipart_end(upb_json_parser *p) {
+ UPB_ASSERT(p->multipart_state != MULTIPART_INACTIVE);
+ p->multipart_state = MULTIPART_INACTIVE;
+ accumulate_clear(p);
+}
+
+
+/* Input capture **************************************************************/
+
+/* Functionality for capturing a region of the input as text. Gracefully
+ * handles the case where a buffer seam occurs in the middle of the captured
+ * region. */
+
+static void capture_begin(upb_json_parser *p, const char *ptr) {
+ UPB_ASSERT(p->multipart_state != MULTIPART_INACTIVE);
+ UPB_ASSERT(p->capture == NULL);
+ p->capture = ptr;
+}
+
+static bool capture_end(upb_json_parser *p, const char *ptr) {
+ UPB_ASSERT(p->capture);
+ if (multipart_text(p, p->capture, ptr - p->capture, true)) {
+ p->capture = NULL;
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/* This is called at the end of each input buffer (ie. when we have hit a
+ * buffer seam). If we are in the middle of capturing the input, this
+ * processes the unprocessed capture region. */
+static void capture_suspend(upb_json_parser *p, const char **ptr) {
+ if (!p->capture) return;
+
+ if (multipart_text(p, p->capture, *ptr - p->capture, false)) {
+ /* We use this as a signal that we were in the middle of capturing, and
+ * that capturing should resume at the beginning of the next buffer.
+ *
+ * We can't use *ptr here, because we have no guarantee that this pointer
+ * will be valid when we resume (if the underlying memory is freed, then
+ * using the pointer at all, even to compare to NULL, is likely undefined
+ * behavior). */
+ p->capture = &suspend_capture;
+ } else {
+ /* Need to back up the pointer to the beginning of the capture, since
+ * we were not able to actually preserve it. */
+ *ptr = p->capture;
+ }
+}
+
+static void capture_resume(upb_json_parser *p, const char *ptr) {
+ if (p->capture) {
+ UPB_ASSERT(p->capture == &suspend_capture);
+ p->capture = ptr;
+ }
+}
+
+
+/* Callbacks from the parser **************************************************/
+
+/* These are the functions called directly from the parser itself.
+ * We define these in the same order as their declarations in the parser. */
+
+static char escape_char(char in) {
+ switch (in) {
+ case 'r': return '\r';
+ case 't': return '\t';
+ case 'n': return '\n';
+ case 'f': return '\f';
+ case 'b': return '\b';
+ case '/': return '/';
+ case '"': return '"';
+ case '\\': return '\\';
+ default:
+ UPB_ASSERT(0);
+ return 'x';
+ }
+}
+
+static bool escape(upb_json_parser *p, const char *ptr) {
+ char ch = escape_char(*ptr);
+ return multipart_text(p, &ch, 1, false);
+}
+
+static void start_hex(upb_json_parser *p) {
+ p->digit = 0;
+}
+
+static void hexdigit(upb_json_parser *p, const char *ptr) {
+ char ch = *ptr;
+
+ p->digit <<= 4;
+
+ if (ch >= '0' && ch <= '9') {
+ p->digit += (ch - '0');
+ } else if (ch >= 'a' && ch <= 'f') {
+ p->digit += ((ch - 'a') + 10);
+ } else {
+ UPB_ASSERT(ch >= 'A' && ch <= 'F');
+ p->digit += ((ch - 'A') + 10);
+ }
+}
+
+static bool end_hex(upb_json_parser *p) {
+ uint32_t codepoint = p->digit;
+
+ /* emit the codepoint as UTF-8. */
+ char utf8[3]; /* support \u0000 -- \uFFFF -- need only three bytes. */
+ int length = 0;
+ if (codepoint <= 0x7F) {
+ utf8[0] = codepoint;
+ length = 1;
+ } else if (codepoint <= 0x07FF) {
+ utf8[1] = (codepoint & 0x3F) | 0x80;
+ codepoint >>= 6;
+ utf8[0] = (codepoint & 0x1F) | 0xC0;
+ length = 2;
+ } else /* codepoint <= 0xFFFF */ {
+ utf8[2] = (codepoint & 0x3F) | 0x80;
+ codepoint >>= 6;
+ utf8[1] = (codepoint & 0x3F) | 0x80;
+ codepoint >>= 6;
+ utf8[0] = (codepoint & 0x0F) | 0xE0;
+ length = 3;
+ }
+ /* TODO(haberman): Handle high surrogates: if codepoint is a high surrogate
+ * we have to wait for the next escape to get the full code point). */
+
+ return multipart_text(p, utf8, length, false);
+}
+
+static void start_text(upb_json_parser *p, const char *ptr) {
+ capture_begin(p, ptr);
+}
+
+static bool end_text(upb_json_parser *p, const char *ptr) {
+ return capture_end(p, ptr);
+}
+
+static void start_number(upb_json_parser *p, const char *ptr) {
+ multipart_startaccum(p);
+ capture_begin(p, ptr);
+}
+
+static bool parse_number(upb_json_parser *p);
+
+static bool end_number(upb_json_parser *p, const char *ptr) {
+ if (!capture_end(p, ptr)) {
+ return false;
+ }
+
+ return parse_number(p);
+}
+
+static bool parse_number(upb_json_parser *p) {
+ size_t len;
+ const char *buf;
+ const char *myend;
+ char *end;
+
+ /* strtol() and friends unfortunately do not support specifying the length of
+ * the input string, so we need to force a copy into a NULL-terminated buffer. */
+ if (!multipart_text(p, "\0", 1, false)) {
+ return false;
+ }
+
+ buf = accumulate_getptr(p, &len);
+ myend = buf + len - 1; /* One for NULL. */
+
+ /* XXX: We are using strtol to parse integers, but this is wrong as even
+ * integers can be represented as 1e6 (for example), which strtol can't
+ * handle correctly.
+ *
+ * XXX: Also, we can't handle large integers properly because strto[u]ll
+ * isn't in C89.
+ *
+ * XXX: Also, we don't properly check floats for overflow, since strtof
+ * isn't in C89. */
+ switch (upb_fielddef_type(p->top->f)) {
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32: {
+ long val = strtol(p->accumulated, &end, 0);
+ if (val > INT32_MAX || val < INT32_MIN || errno == ERANGE || end != myend)
+ goto err;
+ else
+ upb_sink_putint32(&p->top->sink, parser_getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_INT64: {
+ long long val = strtol(p->accumulated, &end, 0);
+ if (val > INT64_MAX || val < INT64_MIN || errno == ERANGE || end != myend)
+ goto err;
+ else
+ upb_sink_putint64(&p->top->sink, parser_getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_UINT32: {
+ unsigned long val = strtoul(p->accumulated, &end, 0);
+ if (val > UINT32_MAX || errno == ERANGE || end != myend)
+ goto err;
+ else
+ upb_sink_putuint32(&p->top->sink, parser_getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_UINT64: {
+ unsigned long long val = strtoul(p->accumulated, &end, 0);
+ if (val > UINT64_MAX || errno == ERANGE || end != myend)
+ goto err;
+ else
+ upb_sink_putuint64(&p->top->sink, parser_getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_DOUBLE: {
+ double val = strtod(p->accumulated, &end);
+ if (errno == ERANGE || end != myend)
+ goto err;
+ else
+ upb_sink_putdouble(&p->top->sink, parser_getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_FLOAT: {
+ float val = strtod(p->accumulated, &end);
+ if (errno == ERANGE || end != myend)
+ goto err;
+ else
+ upb_sink_putfloat(&p->top->sink, parser_getsel(p), val);
+ break;
+ }
+ default:
+ UPB_ASSERT(false);
+ }
+
+ multipart_end(p);
+
+ return true;
+
+err:
+ upb_status_seterrf(&p->status, "error parsing number: %s", buf);
+ upb_env_reporterror(p->env, &p->status);
+ multipart_end(p);
+ return false;
+}
+
+static bool parser_putbool(upb_json_parser *p, bool val) {
+ bool ok;
+
+ if (upb_fielddef_type(p->top->f) != UPB_TYPE_BOOL) {
+ upb_status_seterrf(&p->status,
+ "Boolean value specified for non-bool field: %s",
+ upb_fielddef_name(p->top->f));
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ ok = upb_sink_putbool(&p->top->sink, parser_getsel(p), val);
+ UPB_ASSERT(ok);
+
+ return true;
+}
+
+static bool start_stringval(upb_json_parser *p) {
+ UPB_ASSERT(p->top->f);
+
+ if (upb_fielddef_isstring(p->top->f)) {
+ upb_jsonparser_frame *inner;
+ upb_selector_t sel;
+
+ if (!check_stack(p)) return false;
+
+ /* Start a new parser frame: parser frames correspond one-to-one with
+ * handler frames, and string events occur in a sub-frame. */
+ inner = p->top + 1;
+ sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR);
+ upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink);
+ inner->m = p->top->m;
+ inner->f = p->top->f;
+ inner->name_table = NULL;
+ inner->is_map = false;
+ inner->is_mapentry = false;
+ p->top = inner;
+
+ if (upb_fielddef_type(p->top->f) == UPB_TYPE_STRING) {
+ /* For STRING fields we push data directly to the handlers as it is
+ * parsed. We don't do this yet for BYTES fields, because our base64
+ * decoder is not streaming.
+ *
+ * TODO(haberman): make base64 decoding streaming also. */
+ multipart_start(p, getsel_for_handlertype(p, UPB_HANDLER_STRING));
+ return true;
+ } else {
+ multipart_startaccum(p);
+ return true;
+ }
+ } else if (upb_fielddef_type(p->top->f) == UPB_TYPE_ENUM) {
+ /* No need to push a frame -- symbolic enum names in quotes remain in the
+ * current parser frame.
+ *
+ * Enum string values must accumulate so we can look up the value in a table
+ * once it is complete. */
+ multipart_startaccum(p);
+ return true;
+ } else {
+ upb_status_seterrf(&p->status,
+ "String specified for non-string/non-enum field: %s",
+ upb_fielddef_name(p->top->f));
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+}
+
+static bool end_stringval(upb_json_parser *p) {
+ bool ok = true;
+
+ switch (upb_fielddef_type(p->top->f)) {
+ case UPB_TYPE_BYTES:
+ if (!base64_push(p, getsel_for_handlertype(p, UPB_HANDLER_STRING),
+ p->accumulated, p->accumulated_len)) {
+ return false;
+ }
+ /* Fall through. */
+
+ case UPB_TYPE_STRING: {
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR);
+ p->top--;
+ upb_sink_endstr(&p->top->sink, sel);
+ break;
+ }
+
+ case UPB_TYPE_ENUM: {
+ /* Resolve enum symbolic name to integer value. */
+ const upb_enumdef *enumdef =
+ (const upb_enumdef*)upb_fielddef_subdef(p->top->f);
+
+ size_t len;
+ const char *buf = accumulate_getptr(p, &len);
+
+ int32_t int_val = 0;
+ ok = upb_enumdef_ntoi(enumdef, buf, len, &int_val);
+
+ if (ok) {
+ upb_selector_t sel = parser_getsel(p);
+ upb_sink_putint32(&p->top->sink, sel, int_val);
+ } else {
+ upb_status_seterrf(&p->status, "Enum value unknown: '%.*s'", len, buf);
+ upb_env_reporterror(p->env, &p->status);
+ }
+
+ break;
+ }
+
+ default:
+ UPB_ASSERT(false);
+ upb_status_seterrmsg(&p->status, "Internal error in JSON decoder");
+ upb_env_reporterror(p->env, &p->status);
+ ok = false;
+ break;
+ }
+
+ multipart_end(p);
+
+ return ok;
+}
+
+static void start_member(upb_json_parser *p) {
+ UPB_ASSERT(!p->top->f);
+ multipart_startaccum(p);
+}
+
+/* Helper: invoked during parse_mapentry() to emit the mapentry message's key
+ * field based on the current contents of the accumulate buffer. */
+static bool parse_mapentry_key(upb_json_parser *p) {
+
+ size_t len;
+ const char *buf = accumulate_getptr(p, &len);
+
+ /* Emit the key field. We do a bit of ad-hoc parsing here because the
+ * parser state machine has already decided that this is a string field
+ * name, and we are reinterpreting it as some arbitrary key type. In
+ * particular, integer and bool keys are quoted, so we need to parse the
+ * quoted string contents here. */
+
+ p->top->f = upb_msgdef_itof(p->top->m, UPB_MAPENTRY_KEY);
+ if (p->top->f == NULL) {
+ upb_status_seterrmsg(&p->status, "mapentry message has no key");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+ switch (upb_fielddef_type(p->top->f)) {
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_UINT64:
+ /* Invoke end_number. The accum buffer has the number's text already. */
+ if (!parse_number(p)) {
+ return false;
+ }
+ break;
+ case UPB_TYPE_BOOL:
+ if (len == 4 && !strncmp(buf, "true", 4)) {
+ if (!parser_putbool(p, true)) {
+ return false;
+ }
+ } else if (len == 5 && !strncmp(buf, "false", 5)) {
+ if (!parser_putbool(p, false)) {
+ return false;
+ }
+ } else {
+ upb_status_seterrmsg(&p->status,
+ "Map bool key not 'true' or 'false'");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+ multipart_end(p);
+ break;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ upb_sink subsink;
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR);
+ upb_sink_startstr(&p->top->sink, sel, len, &subsink);
+ sel = getsel_for_handlertype(p, UPB_HANDLER_STRING);
+ upb_sink_putstring(&subsink, sel, buf, len, NULL);
+ sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR);
+ upb_sink_endstr(&p->top->sink, sel);
+ multipart_end(p);
+ break;
+ }
+ default:
+ upb_status_seterrmsg(&p->status, "Invalid field type for map key");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ return true;
+}
+
+/* Helper: emit one map entry (as a submessage in the map field sequence). This
+ * is invoked from end_membername(), at the end of the map entry's key string,
+ * with the map key in the accumulate buffer. It parses the key from that
+ * buffer, emits the handler calls to start the mapentry submessage (setting up
+ * its subframe in the process), and sets up state in the subframe so that the
+ * value parser (invoked next) will emit the mapentry's value field and then
+ * end the mapentry message. */
+
+static bool handle_mapentry(upb_json_parser *p) {
+ const upb_fielddef *mapfield;
+ const upb_msgdef *mapentrymsg;
+ upb_jsonparser_frame *inner;
+ upb_selector_t sel;
+
+ /* Map entry: p->top->sink is the seq frame, so we need to start a frame
+ * for the mapentry itself, and then set |f| in that frame so that the map
+ * value field is parsed, and also set a flag to end the frame after the
+ * map-entry value is parsed. */
+ if (!check_stack(p)) return false;
+
+ mapfield = p->top->mapfield;
+ mapentrymsg = upb_fielddef_msgsubdef(mapfield);
+
+ inner = p->top + 1;
+ p->top->f = mapfield;
+ sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG);
+ upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink);
+ inner->m = mapentrymsg;
+ inner->name_table = NULL;
+ inner->mapfield = mapfield;
+ inner->is_map = false;
+
+ /* Don't set this to true *yet* -- we reuse parsing handlers below to push
+ * the key field value to the sink, and these handlers will pop the frame
+ * if they see is_mapentry (when invoked by the parser state machine, they
+ * would have just seen the map-entry value, not key). */
+ inner->is_mapentry = false;
+ p->top = inner;
+
+ /* send STARTMSG in submsg frame. */
+ upb_sink_startmsg(&p->top->sink);
+
+ parse_mapentry_key(p);
+
+ /* Set up the value field to receive the map-entry value. */
+ p->top->f = upb_msgdef_itof(p->top->m, UPB_MAPENTRY_VALUE);
+ p->top->is_mapentry = true; /* set up to pop frame after value is parsed. */
+ p->top->mapfield = mapfield;
+ if (p->top->f == NULL) {
+ upb_status_seterrmsg(&p->status, "mapentry message has no value");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ return true;
+}
+
+static bool end_membername(upb_json_parser *p) {
+ UPB_ASSERT(!p->top->f);
+
+ if (p->top->is_map) {
+ return handle_mapentry(p);
+ } else {
+ size_t len;
+ const char *buf = accumulate_getptr(p, &len);
+ upb_value v;
+
+ if (upb_strtable_lookup2(p->top->name_table, buf, len, &v)) {
+ p->top->f = upb_value_getconstptr(v);
+ multipart_end(p);
+
+ return true;
+ } else {
+ /* TODO(haberman): Ignore unknown fields if requested/configured to do
+ * so. */
+ upb_status_seterrf(&p->status, "No such field: %.*s\n", (int)len, buf);
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+ }
+}
+
+static void end_member(upb_json_parser *p) {
+ /* If we just parsed a map-entry value, end that frame too. */
+ if (p->top->is_mapentry) {
+ upb_status s = UPB_STATUS_INIT;
+ upb_selector_t sel;
+ bool ok;
+ const upb_fielddef *mapfield;
+
+ UPB_ASSERT(p->top > p->stack);
+ /* send ENDMSG on submsg. */
+ upb_sink_endmsg(&p->top->sink, &s);
+ mapfield = p->top->mapfield;
+
+ /* send ENDSUBMSG in repeated-field-of-mapentries frame. */
+ p->top--;
+ ok = upb_handlers_getselector(mapfield, UPB_HANDLER_ENDSUBMSG, &sel);
+ UPB_ASSERT(ok);
+ upb_sink_endsubmsg(&p->top->sink, sel);
+ }
+
+ p->top->f = NULL;
+}
+
+static bool start_subobject(upb_json_parser *p) {
+ UPB_ASSERT(p->top->f);
+
+ if (upb_fielddef_ismap(p->top->f)) {
+ upb_jsonparser_frame *inner;
+ upb_selector_t sel;
+
+ /* Beginning of a map. Start a new parser frame in a repeated-field
+ * context. */
+ if (!check_stack(p)) return false;
+
+ inner = p->top + 1;
+ sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ);
+ upb_sink_startseq(&p->top->sink, sel, &inner->sink);
+ inner->m = upb_fielddef_msgsubdef(p->top->f);
+ inner->name_table = NULL;
+ inner->mapfield = p->top->f;
+ inner->f = NULL;
+ inner->is_map = true;
+ inner->is_mapentry = false;
+ p->top = inner;
+
+ return true;
+ } else if (upb_fielddef_issubmsg(p->top->f)) {
+ upb_jsonparser_frame *inner;
+ upb_selector_t sel;
+
+ /* Beginning of a subobject. Start a new parser frame in the submsg
+ * context. */
+ if (!check_stack(p)) return false;
+
+ inner = p->top + 1;
+
+ sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG);
+ upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink);
+ inner->m = upb_fielddef_msgsubdef(p->top->f);
+ set_name_table(p, inner);
+ inner->f = NULL;
+ inner->is_map = false;
+ inner->is_mapentry = false;
+ p->top = inner;
+
+ return true;
+ } else {
+ upb_status_seterrf(&p->status,
+ "Object specified for non-message/group field: %s",
+ upb_fielddef_name(p->top->f));
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+}
+
+static void end_subobject(upb_json_parser *p) {
+ if (p->top->is_map) {
+ upb_selector_t sel;
+ p->top--;
+ sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ);
+ upb_sink_endseq(&p->top->sink, sel);
+ } else {
+ upb_selector_t sel;
+ p->top--;
+ sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSUBMSG);
+ upb_sink_endsubmsg(&p->top->sink, sel);
+ }
+}
+
+static bool start_array(upb_json_parser *p) {
+ upb_jsonparser_frame *inner;
+ upb_selector_t sel;
+
+ UPB_ASSERT(p->top->f);
+
+ if (!upb_fielddef_isseq(p->top->f)) {
+ upb_status_seterrf(&p->status,
+ "Array specified for non-repeated field: %s",
+ upb_fielddef_name(p->top->f));
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ if (!check_stack(p)) return false;
+
+ inner = p->top + 1;
+ sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ);
+ upb_sink_startseq(&p->top->sink, sel, &inner->sink);
+ inner->m = p->top->m;
+ inner->name_table = NULL;
+ inner->f = p->top->f;
+ inner->is_map = false;
+ inner->is_mapentry = false;
+ p->top = inner;
+
+ return true;
+}
+
+static void end_array(upb_json_parser *p) {
+ upb_selector_t sel;
+
+ UPB_ASSERT(p->top > p->stack);
+
+ p->top--;
+ sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ);
+ upb_sink_endseq(&p->top->sink, sel);
+}
+
+static void start_object(upb_json_parser *p) {
+ if (!p->top->is_map) {
+ upb_sink_startmsg(&p->top->sink);
+ }
+}
+
+static void end_object(upb_json_parser *p) {
+ if (!p->top->is_map) {
+ upb_status status;
+ upb_status_clear(&status);
+ upb_sink_endmsg(&p->top->sink, &status);
+ if (!upb_ok(&status)) {
+ upb_env_reporterror(p->env, &status);
+ }
+ }
+}
+
+
+#define CHECK_RETURN_TOP(x) if (!(x)) goto error
+
+
+/* The actual parser **********************************************************/
+
+/* What follows is the Ragel parser itself. The language is specified in Ragel
+ * and the actions call our C functions above.
+ *
+ * Ragel has an extensive set of functionality, and we use only a small part of
+ * it. There are many action types but we only use a few:
+ *
+ * ">" -- transition into a machine
+ * "%" -- transition out of a machine
+ * "@" -- transition into a final state of a machine.
+ *
+ * "@" transitions are tricky because a machine can transition into a final
+ * state repeatedly. But in some cases we know this can't happen, for example
+ * a string which is delimited by a final '"' can only transition into its
+ * final state once, when the closing '"' is seen. */
+
+
+#line 1244 "upb/json/parser.rl"
+
+
+
+#line 1156 "upb/json/parser.c"
+static const char _json_actions[] = {
+ 0, 1, 0, 1, 2, 1, 3, 1,
+ 5, 1, 6, 1, 7, 1, 8, 1,
+ 10, 1, 12, 1, 13, 1, 14, 1,
+ 15, 1, 16, 1, 17, 1, 21, 1,
+ 25, 1, 27, 2, 3, 8, 2, 4,
+ 5, 2, 6, 2, 2, 6, 8, 2,
+ 11, 9, 2, 13, 15, 2, 14, 15,
+ 2, 18, 1, 2, 19, 27, 2, 20,
+ 9, 2, 22, 27, 2, 23, 27, 2,
+ 24, 27, 2, 26, 27, 3, 14, 11,
+ 9
+};
+
+static const unsigned char _json_key_offsets[] = {
+ 0, 0, 4, 9, 14, 15, 19, 24,
+ 29, 34, 38, 42, 45, 48, 50, 54,
+ 58, 60, 62, 67, 69, 71, 80, 86,
+ 92, 98, 104, 106, 115, 116, 116, 116,
+ 121, 126, 131, 132, 133, 134, 135, 135,
+ 136, 137, 138, 138, 139, 140, 141, 141,
+ 146, 151, 152, 156, 161, 166, 171, 175,
+ 175, 178, 178, 178
+};
+
+static const char _json_trans_keys[] = {
+ 32, 123, 9, 13, 32, 34, 125, 9,
+ 13, 32, 34, 125, 9, 13, 34, 32,
+ 58, 9, 13, 32, 93, 125, 9, 13,
+ 32, 44, 125, 9, 13, 32, 44, 125,
+ 9, 13, 32, 34, 9, 13, 45, 48,
+ 49, 57, 48, 49, 57, 46, 69, 101,
+ 48, 57, 69, 101, 48, 57, 43, 45,
+ 48, 57, 48, 57, 48, 57, 46, 69,
+ 101, 48, 57, 34, 92, 34, 92, 34,
+ 47, 92, 98, 102, 110, 114, 116, 117,
+ 48, 57, 65, 70, 97, 102, 48, 57,
+ 65, 70, 97, 102, 48, 57, 65, 70,
+ 97, 102, 48, 57, 65, 70, 97, 102,
+ 34, 92, 34, 45, 91, 102, 110, 116,
+ 123, 48, 57, 34, 32, 93, 125, 9,
+ 13, 32, 44, 93, 9, 13, 32, 93,
+ 125, 9, 13, 97, 108, 115, 101, 117,
+ 108, 108, 114, 117, 101, 32, 34, 125,
+ 9, 13, 32, 34, 125, 9, 13, 34,
+ 32, 58, 9, 13, 32, 93, 125, 9,
+ 13, 32, 44, 125, 9, 13, 32, 44,
+ 125, 9, 13, 32, 34, 9, 13, 32,
+ 9, 13, 0
+};
+
+static const char _json_single_lengths[] = {
+ 0, 2, 3, 3, 1, 2, 3, 3,
+ 3, 2, 2, 1, 3, 0, 2, 2,
+ 0, 0, 3, 2, 2, 9, 0, 0,
+ 0, 0, 2, 7, 1, 0, 0, 3,
+ 3, 3, 1, 1, 1, 1, 0, 1,
+ 1, 1, 0, 1, 1, 1, 0, 3,
+ 3, 1, 2, 3, 3, 3, 2, 0,
+ 1, 0, 0, 0
+};
+
+static const char _json_range_lengths[] = {
+ 0, 1, 1, 1, 0, 1, 1, 1,
+ 1, 1, 1, 1, 0, 1, 1, 1,
+ 1, 1, 1, 0, 0, 0, 3, 3,
+ 3, 3, 0, 1, 0, 0, 0, 1,
+ 1, 1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 0, 1, 1, 1, 1, 1, 0,
+ 1, 0, 0, 0
+};
+
+static const short _json_index_offsets[] = {
+ 0, 0, 4, 9, 14, 16, 20, 25,
+ 30, 35, 39, 43, 46, 50, 52, 56,
+ 60, 62, 64, 69, 72, 75, 85, 89,
+ 93, 97, 101, 104, 113, 115, 116, 117,
+ 122, 127, 132, 134, 136, 138, 140, 141,
+ 143, 145, 147, 148, 150, 152, 154, 155,
+ 160, 165, 167, 171, 176, 181, 186, 190,
+ 191, 194, 195, 196
+};
+
+static const char _json_indicies[] = {
+ 0, 2, 0, 1, 3, 4, 5, 3,
+ 1, 6, 7, 8, 6, 1, 9, 1,
+ 10, 11, 10, 1, 11, 1, 1, 11,
+ 12, 13, 14, 15, 13, 1, 16, 17,
+ 8, 16, 1, 17, 7, 17, 1, 18,
+ 19, 20, 1, 19, 20, 1, 22, 23,
+ 23, 21, 24, 1, 23, 23, 24, 21,
+ 25, 25, 26, 1, 26, 1, 26, 21,
+ 22, 23, 23, 20, 21, 28, 29, 27,
+ 31, 32, 30, 33, 33, 33, 33, 33,
+ 33, 33, 33, 34, 1, 35, 35, 35,
+ 1, 36, 36, 36, 1, 37, 37, 37,
+ 1, 38, 38, 38, 1, 40, 41, 39,
+ 42, 43, 44, 45, 46, 47, 48, 43,
+ 1, 49, 1, 50, 51, 53, 54, 1,
+ 53, 52, 55, 56, 54, 55, 1, 56,
+ 1, 1, 56, 52, 57, 1, 58, 1,
+ 59, 1, 60, 1, 61, 62, 1, 63,
+ 1, 64, 1, 65, 66, 1, 67, 1,
+ 68, 1, 69, 70, 71, 72, 70, 1,
+ 73, 74, 75, 73, 1, 76, 1, 77,
+ 78, 77, 1, 78, 1, 1, 78, 79,
+ 80, 81, 82, 80, 1, 83, 84, 75,
+ 83, 1, 84, 74, 84, 1, 85, 86,
+ 86, 1, 1, 1, 1, 0
+};
+
+static const char _json_trans_targs[] = {
+ 1, 0, 2, 3, 4, 56, 3, 4,
+ 56, 5, 5, 6, 7, 8, 9, 56,
+ 8, 9, 11, 12, 18, 57, 13, 15,
+ 14, 16, 17, 20, 58, 21, 20, 58,
+ 21, 19, 22, 23, 24, 25, 26, 20,
+ 58, 21, 28, 30, 31, 34, 39, 43,
+ 47, 29, 59, 59, 32, 31, 29, 32,
+ 33, 35, 36, 37, 38, 59, 40, 41,
+ 42, 59, 44, 45, 46, 59, 48, 49,
+ 55, 48, 49, 55, 50, 50, 51, 52,
+ 53, 54, 55, 53, 54, 59, 56
+};
+
+static const char _json_trans_actions[] = {
+ 0, 0, 0, 21, 77, 53, 0, 47,
+ 23, 17, 0, 0, 15, 19, 19, 50,
+ 0, 0, 0, 0, 0, 1, 0, 0,
+ 0, 0, 0, 3, 13, 0, 0, 35,
+ 5, 11, 0, 38, 7, 7, 7, 41,
+ 44, 9, 62, 56, 25, 0, 0, 0,
+ 31, 29, 33, 59, 15, 0, 27, 0,
+ 0, 0, 0, 0, 0, 68, 0, 0,
+ 0, 71, 0, 0, 0, 65, 21, 77,
+ 53, 0, 47, 23, 17, 0, 0, 15,
+ 19, 19, 50, 0, 0, 74, 0
+};
+
+static const int json_start = 1;
+
+static const int json_en_number_machine = 10;
+static const int json_en_string_machine = 19;
+static const int json_en_value_machine = 27;
+static const int json_en_main = 1;
+
+
+#line 1247 "upb/json/parser.rl"
+
+size_t parse(void *closure, const void *hd, const char *buf, size_t size,
+ const upb_bufhandle *handle) {
+ upb_json_parser *parser = closure;
+
+ /* Variables used by Ragel's generated code. */
+ int cs = parser->current_state;
+ int *stack = parser->parser_stack;
+ int top = parser->parser_top;
+
+ const char *p = buf;
+ const char *pe = buf + size;
+
+ parser->handle = handle;
+
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ capture_resume(parser, buf);
+
+
+#line 1327 "upb/json/parser.c"
+ {
+ int _klen;
+ unsigned int _trans;
+ const char *_acts;
+ unsigned int _nacts;
+ const char *_keys;
+
+ if ( p == pe )
+ goto _test_eof;
+ if ( cs == 0 )
+ goto _out;
+_resume:
+ _keys = _json_trans_keys + _json_key_offsets[cs];
+ _trans = _json_index_offsets[cs];
+
+ _klen = _json_single_lengths[cs];
+ if ( _klen > 0 ) {
+ const char *_lower = _keys;
+ const char *_mid;
+ const char *_upper = _keys + _klen - 1;
+ while (1) {
+ if ( _upper < _lower )
+ break;
+
+ _mid = _lower + ((_upper-_lower) >> 1);
+ if ( (*p) < *_mid )
+ _upper = _mid - 1;
+ else if ( (*p) > *_mid )
+ _lower = _mid + 1;
+ else {
+ _trans += (unsigned int)(_mid - _keys);
+ goto _match;
+ }
+ }
+ _keys += _klen;
+ _trans += _klen;
+ }
+
+ _klen = _json_range_lengths[cs];
+ if ( _klen > 0 ) {
+ const char *_lower = _keys;
+ const char *_mid;
+ const char *_upper = _keys + (_klen<<1) - 2;
+ while (1) {
+ if ( _upper < _lower )
+ break;
+
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1);
+ if ( (*p) < _mid[0] )
+ _upper = _mid - 2;
+ else if ( (*p) > _mid[1] )
+ _lower = _mid + 2;
+ else {
+ _trans += (unsigned int)((_mid - _keys)>>1);
+ goto _match;
+ }
+ }
+ _trans += _klen;
+ }
+
+_match:
+ _trans = _json_indicies[_trans];
+ cs = _json_trans_targs[_trans];
+
+ if ( _json_trans_actions[_trans] == 0 )
+ goto _again;
+
+ _acts = _json_actions + _json_trans_actions[_trans];
+ _nacts = (unsigned int) *_acts++;
+ while ( _nacts-- > 0 )
+ {
+ switch ( *_acts++ )
+ {
+ case 0:
+#line 1159 "upb/json/parser.rl"
+ { p--; {cs = stack[--top]; goto _again;} }
+ break;
+ case 1:
+#line 1160 "upb/json/parser.rl"
+ { p--; {stack[top++] = cs; cs = 10; goto _again;} }
+ break;
+ case 2:
+#line 1164 "upb/json/parser.rl"
+ { start_text(parser, p); }
+ break;
+ case 3:
+#line 1165 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_text(parser, p)); }
+ break;
+ case 4:
+#line 1171 "upb/json/parser.rl"
+ { start_hex(parser); }
+ break;
+ case 5:
+#line 1172 "upb/json/parser.rl"
+ { hexdigit(parser, p); }
+ break;
+ case 6:
+#line 1173 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_hex(parser)); }
+ break;
+ case 7:
+#line 1179 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(escape(parser, p)); }
+ break;
+ case 8:
+#line 1185 "upb/json/parser.rl"
+ { p--; {cs = stack[--top]; goto _again;} }
+ break;
+ case 9:
+#line 1188 "upb/json/parser.rl"
+ { {stack[top++] = cs; cs = 19; goto _again;} }
+ break;
+ case 10:
+#line 1190 "upb/json/parser.rl"
+ { p--; {stack[top++] = cs; cs = 27; goto _again;} }
+ break;
+ case 11:
+#line 1195 "upb/json/parser.rl"
+ { start_member(parser); }
+ break;
+ case 12:
+#line 1196 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_membername(parser)); }
+ break;
+ case 13:
+#line 1199 "upb/json/parser.rl"
+ { end_member(parser); }
+ break;
+ case 14:
+#line 1205 "upb/json/parser.rl"
+ { start_object(parser); }
+ break;
+ case 15:
+#line 1208 "upb/json/parser.rl"
+ { end_object(parser); }
+ break;
+ case 16:
+#line 1214 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(start_array(parser)); }
+ break;
+ case 17:
+#line 1218 "upb/json/parser.rl"
+ { end_array(parser); }
+ break;
+ case 18:
+#line 1223 "upb/json/parser.rl"
+ { start_number(parser, p); }
+ break;
+ case 19:
+#line 1224 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_number(parser, p)); }
+ break;
+ case 20:
+#line 1226 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(start_stringval(parser)); }
+ break;
+ case 21:
+#line 1227 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_stringval(parser)); }
+ break;
+ case 22:
+#line 1229 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(parser_putbool(parser, true)); }
+ break;
+ case 23:
+#line 1231 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(parser_putbool(parser, false)); }
+ break;
+ case 24:
+#line 1233 "upb/json/parser.rl"
+ { /* null value */ }
+ break;
+ case 25:
+#line 1235 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(start_subobject(parser)); }
+ break;
+ case 26:
+#line 1236 "upb/json/parser.rl"
+ { end_subobject(parser); }
+ break;
+ case 27:
+#line 1241 "upb/json/parser.rl"
+ { p--; {cs = stack[--top]; goto _again;} }
+ break;
+#line 1513 "upb/json/parser.c"
+ }
+ }
+
+_again:
+ if ( cs == 0 )
+ goto _out;
+ if ( ++p != pe )
+ goto _resume;
+ _test_eof: {}
+ _out: {}
+ }
+
+#line 1268 "upb/json/parser.rl"
+
+ if (p != pe) {
+ upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p);
+ upb_env_reporterror(parser->env, &parser->status);
+ } else {
+ capture_suspend(parser, &p);
+ }
+
+error:
+ /* Save parsing state back to parser. */
+ parser->current_state = cs;
+ parser->parser_top = top;
+
+ return p - buf;
+}
+
+bool end(void *closure, const void *hd) {
+ UPB_UNUSED(closure);
+ UPB_UNUSED(hd);
+
+ /* Prevent compile warning on unused static constants. */
+ UPB_UNUSED(json_start);
+ UPB_UNUSED(json_en_number_machine);
+ UPB_UNUSED(json_en_string_machine);
+ UPB_UNUSED(json_en_value_machine);
+ UPB_UNUSED(json_en_main);
+ return true;
+}
+
+static void json_parser_reset(upb_json_parser *p) {
+ int cs;
+ int top;
+
+ p->top = p->stack;
+ p->top->f = NULL;
+ p->top->is_map = false;
+ p->top->is_mapentry = false;
+
+ /* Emit Ragel initialization of the parser. */
+
+#line 1567 "upb/json/parser.c"
+ {
+ cs = json_start;
+ top = 0;
+ }
+
+#line 1308 "upb/json/parser.rl"
+ p->current_state = cs;
+ p->parser_top = top;
+ accumulate_clear(p);
+ p->multipart_state = MULTIPART_INACTIVE;
+ p->capture = NULL;
+ p->accumulated = NULL;
+ upb_status_clear(&p->status);
+}
+
+static void visit_json_parsermethod(const upb_refcounted *r,
+ upb_refcounted_visit *visit,
+ void *closure) {
+ const upb_json_parsermethod *method = (upb_json_parsermethod*)r;
+ visit(r, upb_msgdef_upcast2(method->msg), closure);
+}
+
+static void free_json_parsermethod(upb_refcounted *r) {
+ upb_json_parsermethod *method = (upb_json_parsermethod*)r;
+
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, &method->name_tables);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ upb_value val = upb_inttable_iter_value(&i);
+ upb_strtable *t = upb_value_getptr(val);
+ upb_strtable_uninit(t);
+ upb_gfree(t);
+ }
+
+ upb_inttable_uninit(&method->name_tables);
+
+ upb_gfree(r);
+}
+
+static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) {
+ upb_msg_field_iter i;
+ upb_strtable *t;
+
+ /* It would be nice to stack-allocate this, but protobufs do not limit the
+ * length of fields to any reasonable limit. */
+ char *buf = NULL;
+ size_t len = 0;
+
+ if (upb_inttable_lookupptr(&m->name_tables, md, NULL)) {
+ return;
+ }
+
+ /* TODO(haberman): handle malloc failure. */
+ t = upb_gmalloc(sizeof(*t));
+ upb_strtable_init(t, UPB_CTYPE_CONSTPTR);
+ upb_inttable_insertptr(&m->name_tables, md, upb_value_ptr(t));
+
+ for(upb_msg_field_begin(&i, md);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ const upb_fielddef *f = upb_msg_iter_field(&i);
+
+ /* Add an entry for the JSON name. */
+ size_t field_len = upb_fielddef_getjsonname(f, buf, len);
+ if (field_len > len) {
+ size_t len2;
+ buf = upb_grealloc(buf, 0, field_len);
+ len = field_len;
+ len2 = upb_fielddef_getjsonname(f, buf, len);
+ UPB_ASSERT(len == len2);
+ }
+ upb_strtable_insert(t, buf, upb_value_constptr(f));
+
+ if (strcmp(buf, upb_fielddef_name(f)) != 0) {
+ /* Since the JSON name is different from the regular field name, add an
+ * entry for the raw name (compliant proto3 JSON parsers must accept
+ * both). */
+ upb_strtable_insert(t, upb_fielddef_name(f), upb_value_constptr(f));
+ }
+
+ if (upb_fielddef_issubmsg(f)) {
+ add_jsonname_table(m, upb_fielddef_msgsubdef(f));
+ }
+ }
+
+ upb_gfree(buf);
+}
+
+/* Public API *****************************************************************/
+
+upb_json_parser *upb_json_parser_create(upb_env *env,
+ const upb_json_parsermethod *method,
+ upb_sink *output) {
+#ifndef NDEBUG
+ const size_t size_before = upb_env_bytesallocated(env);
+#endif
+ upb_json_parser *p = upb_env_malloc(env, sizeof(upb_json_parser));
+ if (!p) return false;
+
+ p->env = env;
+ p->method = method;
+ p->limit = p->stack + UPB_JSON_MAX_DEPTH;
+ p->accumulate_buf = NULL;
+ p->accumulate_buf_size = 0;
+ upb_bytessink_reset(&p->input_, &method->input_handler_, p);
+
+ json_parser_reset(p);
+ upb_sink_reset(&p->top->sink, output->handlers, output->closure);
+ p->top->m = upb_handlers_msgdef(output->handlers);
+ set_name_table(p, p->top);
+
+ /* If this fails, uncomment and increase the value in parser.h. */
+ /* fprintf(stderr, "%zd\n", upb_env_bytesallocated(env) - size_before); */
+ UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(env) - size_before <=
+ UPB_JSON_PARSER_SIZE);
+ return p;
+}
+
+upb_bytessink *upb_json_parser_input(upb_json_parser *p) {
+ return &p->input_;
+}
+
+upb_json_parsermethod *upb_json_parsermethod_new(const upb_msgdef* md,
+ const void* owner) {
+ static const struct upb_refcounted_vtbl vtbl = {visit_json_parsermethod,
+ free_json_parsermethod};
+ upb_json_parsermethod *ret = upb_gmalloc(sizeof(*ret));
+ upb_refcounted_init(upb_json_parsermethod_upcast_mutable(ret), &vtbl, owner);
+
+ ret->msg = md;
+ upb_ref2(md, ret);
+
+ upb_byteshandler_init(&ret->input_handler_);
+ upb_byteshandler_setstring(&ret->input_handler_, parse, ret);
+ upb_byteshandler_setendstr(&ret->input_handler_, end, ret);
+
+ upb_inttable_init(&ret->name_tables, UPB_CTYPE_PTR);
+
+ add_jsonname_table(ret, md);
+
+ return ret;
+}
+
+const upb_byteshandler *upb_json_parsermethod_inputhandler(
+ const upb_json_parsermethod *m) {
+ return &m->input_handler_;
+}
+/*
+** This currently uses snprintf() to format primitives, and could be optimized
+** further.
+*/
+
+
+#include <string.h>
+#include <stdint.h>
+
+struct upb_json_printer {
+ upb_sink input_;
+ /* BytesSink closure. */
+ void *subc_;
+ upb_bytessink *output_;
+
+ /* We track the depth so that we know when to emit startstr/endstr on the
+ * output. */
+ int depth_;
+
+ /* Have we emitted the first element? This state is necessary to emit commas
+ * without leaving a trailing comma in arrays/maps. We keep this state per
+ * frame depth.
+ *
+ * Why max_depth * 2? UPB_MAX_HANDLER_DEPTH counts depth as nested messages.
+ * We count frames (contexts in which we separate elements by commas) as both
+ * repeated fields and messages (maps), and the worst case is a
+ * message->repeated field->submessage->repeated field->... nesting. */
+ bool first_elem_[UPB_MAX_HANDLER_DEPTH * 2];
+};
+
+/* StringPiece; a pointer plus a length. */
+typedef struct {
+ char *ptr;
+ size_t len;
+} strpc;
+
+void freestrpc(void *ptr) {
+ strpc *pc = ptr;
+ upb_gfree(pc->ptr);
+ upb_gfree(pc);
+}
+
+/* Convert fielddef name to JSON name and return as a string piece. */
+strpc *newstrpc(upb_handlers *h, const upb_fielddef *f,
+ bool preserve_fieldnames) {
+ /* TODO(haberman): handle malloc failure. */
+ strpc *ret = upb_gmalloc(sizeof(*ret));
+ if (preserve_fieldnames) {
+ ret->ptr = upb_gstrdup(upb_fielddef_name(f));
+ ret->len = strlen(ret->ptr);
+ } else {
+ size_t len;
+ ret->len = upb_fielddef_getjsonname(f, NULL, 0);
+ ret->ptr = upb_gmalloc(ret->len);
+ len = upb_fielddef_getjsonname(f, ret->ptr, ret->len);
+ UPB_ASSERT(len == ret->len);
+ ret->len--; /* NULL */
+ }
+
+ upb_handlers_addcleanup(h, ret, freestrpc);
+ return ret;
+}
+
+/* ------------ JSON string printing: values, maps, arrays ------------------ */
+
+static void print_data(
+ upb_json_printer *p, const char *buf, unsigned int len) {
+ /* TODO: Will need to change if we support pushback from the sink. */
+ size_t n = upb_bytessink_putbuf(p->output_, p->subc_, buf, len, NULL);
+ UPB_ASSERT(n == len);
+}
+
+static void print_comma(upb_json_printer *p) {
+ if (!p->first_elem_[p->depth_]) {
+ print_data(p, ",", 1);
+ }
+ p->first_elem_[p->depth_] = false;
+}
+
+/* Helpers that print properly formatted elements to the JSON output stream. */
+
+/* Used for escaping control chars in strings. */
+static const char kControlCharLimit = 0x20;
+
+UPB_INLINE bool is_json_escaped(char c) {
+ /* See RFC 4627. */
+ unsigned char uc = (unsigned char)c;
+ return uc < kControlCharLimit || uc == '"' || uc == '\\';
+}
+
+UPB_INLINE const char* json_nice_escape(char c) {
+ switch (c) {
+ case '"': return "\\\"";
+ case '\\': return "\\\\";
+ case '\b': return "\\b";
+ case '\f': return "\\f";
+ case '\n': return "\\n";
+ case '\r': return "\\r";
+ case '\t': return "\\t";
+ default: return NULL;
+ }
+}
+
+/* Write a properly escaped string chunk. The surrounding quotes are *not*
+ * printed; this is so that the caller has the option of emitting the string
+ * content in chunks. */
+static void putstring(upb_json_printer *p, const char *buf, unsigned int len) {
+ const char* unescaped_run = NULL;
+ unsigned int i;
+ for (i = 0; i < len; i++) {
+ char c = buf[i];
+ /* Handle escaping. */
+ if (is_json_escaped(c)) {
+ /* Use a "nice" escape, like \n, if one exists for this character. */
+ const char* escape = json_nice_escape(c);
+ /* If we don't have a specific 'nice' escape code, use a \uXXXX-style
+ * escape. */
+ char escape_buf[8];
+ if (!escape) {
+ unsigned char byte = (unsigned char)c;
+ _upb_snprintf(escape_buf, sizeof(escape_buf), "\\u%04x", (int)byte);
+ escape = escape_buf;
+ }
+
+ /* N.B. that we assume that the input encoding is equal to the output
+ * encoding (both UTF-8 for now), so for chars >= 0x20 and != \, ", we
+ * can simply pass the bytes through. */
+
+ /* If there's a current run of unescaped chars, print that run first. */
+ if (unescaped_run) {
+ print_data(p, unescaped_run, &buf[i] - unescaped_run);
+ unescaped_run = NULL;
+ }
+ /* Then print the escape code. */
+ print_data(p, escape, strlen(escape));
+ } else {
+ /* Add to the current unescaped run of characters. */
+ if (unescaped_run == NULL) {
+ unescaped_run = &buf[i];
+ }
+ }
+ }
+
+ /* If the string ended in a run of unescaped characters, print that last run. */
+ if (unescaped_run) {
+ print_data(p, unescaped_run, &buf[len] - unescaped_run);
+ }
+}
+
+#define CHKLENGTH(x) if (!(x)) return -1;
+
+/* Helpers that format floating point values according to our custom formats.
+ * Right now we use %.8g and %.17g for float/double, respectively, to match
+ * proto2::util::JsonFormat's defaults. May want to change this later. */
+
+static size_t fmt_double(double val, char* buf, size_t length) {
+ size_t n = _upb_snprintf(buf, length, "%.17g", val);
+ CHKLENGTH(n > 0 && n < length);
+ return n;
+}
+
+static size_t fmt_float(float val, char* buf, size_t length) {
+ size_t n = _upb_snprintf(buf, length, "%.8g", val);
+ CHKLENGTH(n > 0 && n < length);
+ return n;
+}
+
+static size_t fmt_bool(bool val, char* buf, size_t length) {
+ size_t n = _upb_snprintf(buf, length, "%s", (val ? "true" : "false"));
+ CHKLENGTH(n > 0 && n < length);
+ return n;
+}
+
+static size_t fmt_int64(long val, char* buf, size_t length) {
+ size_t n = _upb_snprintf(buf, length, "%ld", val);
+ CHKLENGTH(n > 0 && n < length);
+ return n;
+}
+
+static size_t fmt_uint64(unsigned long long val, char* buf, size_t length) {
+ size_t n = _upb_snprintf(buf, length, "%llu", val);
+ CHKLENGTH(n > 0 && n < length);
+ return n;
+}
+
+/* Print a map key given a field name. Called by scalar field handlers and by
+ * startseq for repeated fields. */
+static bool putkey(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ const strpc *key = handler_data;
+ print_comma(p);
+ print_data(p, "\"", 1);
+ putstring(p, key->ptr, key->len);
+ print_data(p, "\":", 2);
+ return true;
+}
+
+#define CHKFMT(val) if ((val) == (size_t)-1) return false;
+#define CHK(val) if (!(val)) return false;
+
+#define TYPE_HANDLERS(type, fmt_func) \
+ static bool put##type(void *closure, const void *handler_data, type val) { \
+ upb_json_printer *p = closure; \
+ char data[64]; \
+ size_t length = fmt_func(val, data, sizeof(data)); \
+ UPB_UNUSED(handler_data); \
+ CHKFMT(length); \
+ print_data(p, data, length); \
+ return true; \
+ } \
+ static bool scalar_##type(void *closure, const void *handler_data, \
+ type val) { \
+ CHK(putkey(closure, handler_data)); \
+ CHK(put##type(closure, handler_data, val)); \
+ return true; \
+ } \
+ static bool repeated_##type(void *closure, const void *handler_data, \
+ type val) { \
+ upb_json_printer *p = closure; \
+ print_comma(p); \
+ CHK(put##type(closure, handler_data, val)); \
+ return true; \
+ }
+
+#define TYPE_HANDLERS_MAPKEY(type, fmt_func) \
+ static bool putmapkey_##type(void *closure, const void *handler_data, \
+ type val) { \
+ upb_json_printer *p = closure; \
+ print_data(p, "\"", 1); \
+ CHK(put##type(closure, handler_data, val)); \
+ print_data(p, "\":", 2); \
+ return true; \
+ }
+
+TYPE_HANDLERS(double, fmt_double)
+TYPE_HANDLERS(float, fmt_float)
+TYPE_HANDLERS(bool, fmt_bool)
+TYPE_HANDLERS(int32_t, fmt_int64)
+TYPE_HANDLERS(uint32_t, fmt_int64)
+TYPE_HANDLERS(int64_t, fmt_int64)
+TYPE_HANDLERS(uint64_t, fmt_uint64)
+
+/* double and float are not allowed to be map keys. */
+TYPE_HANDLERS_MAPKEY(bool, fmt_bool)
+TYPE_HANDLERS_MAPKEY(int32_t, fmt_int64)
+TYPE_HANDLERS_MAPKEY(uint32_t, fmt_int64)
+TYPE_HANDLERS_MAPKEY(int64_t, fmt_int64)
+TYPE_HANDLERS_MAPKEY(uint64_t, fmt_uint64)
+
+#undef TYPE_HANDLERS
+#undef TYPE_HANDLERS_MAPKEY
+
+typedef struct {
+ void *keyname;
+ const upb_enumdef *enumdef;
+} EnumHandlerData;
+
+static bool scalar_enum(void *closure, const void *handler_data,
+ int32_t val) {
+ const EnumHandlerData *hd = handler_data;
+ upb_json_printer *p = closure;
+ const char *symbolic_name;
+
+ CHK(putkey(closure, hd->keyname));
+
+ symbolic_name = upb_enumdef_iton(hd->enumdef, val);
+ if (symbolic_name) {
+ print_data(p, "\"", 1);
+ putstring(p, symbolic_name, strlen(symbolic_name));
+ print_data(p, "\"", 1);
+ } else {
+ putint32_t(closure, NULL, val);
+ }
+
+ return true;
+}
+
+static void print_enum_symbolic_name(upb_json_printer *p,
+ const upb_enumdef *def,
+ int32_t val) {
+ const char *symbolic_name = upb_enumdef_iton(def, val);
+ if (symbolic_name) {
+ print_data(p, "\"", 1);
+ putstring(p, symbolic_name, strlen(symbolic_name));
+ print_data(p, "\"", 1);
+ } else {
+ putint32_t(p, NULL, val);
+ }
+}
+
+static bool repeated_enum(void *closure, const void *handler_data,
+ int32_t val) {
+ const EnumHandlerData *hd = handler_data;
+ upb_json_printer *p = closure;
+ print_comma(p);
+
+ print_enum_symbolic_name(p, hd->enumdef, val);
+
+ return true;
+}
+
+static bool mapvalue_enum(void *closure, const void *handler_data,
+ int32_t val) {
+ const EnumHandlerData *hd = handler_data;
+ upb_json_printer *p = closure;
+
+ print_enum_symbolic_name(p, hd->enumdef, val);
+
+ return true;
+}
+
+static void *scalar_startsubmsg(void *closure, const void *handler_data) {
+ return putkey(closure, handler_data) ? closure : UPB_BREAK;
+}
+
+static void *repeated_startsubmsg(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ print_comma(p);
+ return closure;
+}
+
+static void start_frame(upb_json_printer *p) {
+ p->depth_++;
+ p->first_elem_[p->depth_] = true;
+ print_data(p, "{", 1);
+}
+
+static void end_frame(upb_json_printer *p) {
+ print_data(p, "}", 1);
+ p->depth_--;
+}
+
+static bool printer_startmsg(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ if (p->depth_ == 0) {
+ upb_bytessink_start(p->output_, 0, &p->subc_);
+ }
+ start_frame(p);
+ return true;
+}
+
+static bool printer_endmsg(void *closure, const void *handler_data, upb_status *s) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ UPB_UNUSED(s);
+ end_frame(p);
+ if (p->depth_ == 0) {
+ upb_bytessink_end(p->output_);
+ }
+ return true;
+}
+
+static void *startseq(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ CHK(putkey(closure, handler_data));
+ p->depth_++;
+ p->first_elem_[p->depth_] = true;
+ print_data(p, "[", 1);
+ return closure;
+}
+
+static bool endseq(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ print_data(p, "]", 1);
+ p->depth_--;
+ return true;
+}
+
+static void *startmap(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ CHK(putkey(closure, handler_data));
+ p->depth_++;
+ p->first_elem_[p->depth_] = true;
+ print_data(p, "{", 1);
+ return closure;
+}
+
+static bool endmap(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ print_data(p, "}", 1);
+ p->depth_--;
+ return true;
+}
+
+static size_t putstr(void *closure, const void *handler_data, const char *str,
+ size_t len, const upb_bufhandle *handle) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ UPB_UNUSED(handle);
+ putstring(p, str, len);
+ return len;
+}
+
+/* This has to Base64 encode the bytes, because JSON has no "bytes" type. */
+static size_t putbytes(void *closure, const void *handler_data, const char *str,
+ size_t len, const upb_bufhandle *handle) {
+ upb_json_printer *p = closure;
+
+ /* This is the regular base64, not the "web-safe" version. */
+ static const char base64[] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+ /* Base64-encode. */
+ char data[16000];
+ const char *limit = data + sizeof(data);
+ const unsigned char *from = (const unsigned char*)str;
+ char *to = data;
+ size_t remaining = len;
+ size_t bytes;
+
+ UPB_UNUSED(handler_data);
+ UPB_UNUSED(handle);
+
+ while (remaining > 2) {
+ /* TODO(haberman): handle encoded lengths > sizeof(data) */
+ UPB_ASSERT((limit - to) >= 4);
+
+ to[0] = base64[from[0] >> 2];
+ to[1] = base64[((from[0] & 0x3) << 4) | (from[1] >> 4)];
+ to[2] = base64[((from[1] & 0xf) << 2) | (from[2] >> 6)];
+ to[3] = base64[from[2] & 0x3f];
+
+ remaining -= 3;
+ to += 4;
+ from += 3;
+ }
+
+ switch (remaining) {
+ case 2:
+ to[0] = base64[from[0] >> 2];
+ to[1] = base64[((from[0] & 0x3) << 4) | (from[1] >> 4)];
+ to[2] = base64[(from[1] & 0xf) << 2];
+ to[3] = '=';
+ to += 4;
+ from += 2;
+ break;
+ case 1:
+ to[0] = base64[from[0] >> 2];
+ to[1] = base64[((from[0] & 0x3) << 4)];
+ to[2] = '=';
+ to[3] = '=';
+ to += 4;
+ from += 1;
+ break;
+ }
+
+ bytes = to - data;
+ print_data(p, "\"", 1);
+ putstring(p, data, bytes);
+ print_data(p, "\"", 1);
+ return len;
+}
+
+static void *scalar_startstr(void *closure, const void *handler_data,
+ size_t size_hint) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ UPB_UNUSED(size_hint);
+ CHK(putkey(closure, handler_data));
+ print_data(p, "\"", 1);
+ return p;
+}
+
+static size_t scalar_str(void *closure, const void *handler_data,
+ const char *str, size_t len,
+ const upb_bufhandle *handle) {
+ CHK(putstr(closure, handler_data, str, len, handle));
+ return len;
+}
+
+static bool scalar_endstr(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ print_data(p, "\"", 1);
+ return true;
+}
+
+static void *repeated_startstr(void *closure, const void *handler_data,
+ size_t size_hint) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ UPB_UNUSED(size_hint);
+ print_comma(p);
+ print_data(p, "\"", 1);
+ return p;
+}
+
+static size_t repeated_str(void *closure, const void *handler_data,
+ const char *str, size_t len,
+ const upb_bufhandle *handle) {
+ CHK(putstr(closure, handler_data, str, len, handle));
+ return len;
+}
+
+static bool repeated_endstr(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ print_data(p, "\"", 1);
+ return true;
+}
+
+static void *mapkeyval_startstr(void *closure, const void *handler_data,
+ size_t size_hint) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ UPB_UNUSED(size_hint);
+ print_data(p, "\"", 1);
+ return p;
+}
+
+static size_t mapkey_str(void *closure, const void *handler_data,
+ const char *str, size_t len,
+ const upb_bufhandle *handle) {
+ CHK(putstr(closure, handler_data, str, len, handle));
+ return len;
+}
+
+static bool mapkey_endstr(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ print_data(p, "\":", 2);
+ return true;
+}
+
+static bool mapvalue_endstr(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ print_data(p, "\"", 1);
+ return true;
+}
+
+static size_t scalar_bytes(void *closure, const void *handler_data,
+ const char *str, size_t len,
+ const upb_bufhandle *handle) {
+ CHK(putkey(closure, handler_data));
+ CHK(putbytes(closure, handler_data, str, len, handle));
+ return len;
+}
+
+static size_t repeated_bytes(void *closure, const void *handler_data,
+ const char *str, size_t len,
+ const upb_bufhandle *handle) {
+ upb_json_printer *p = closure;
+ print_comma(p);
+ CHK(putbytes(closure, handler_data, str, len, handle));
+ return len;
+}
+
+static size_t mapkey_bytes(void *closure, const void *handler_data,
+ const char *str, size_t len,
+ const upb_bufhandle *handle) {
+ upb_json_printer *p = closure;
+ CHK(putbytes(closure, handler_data, str, len, handle));
+ print_data(p, ":", 1);
+ return len;
+}
+
+static void set_enum_hd(upb_handlers *h,
+ const upb_fielddef *f,
+ bool preserve_fieldnames,
+ upb_handlerattr *attr) {
+ EnumHandlerData *hd = upb_gmalloc(sizeof(EnumHandlerData));
+ hd->enumdef = (const upb_enumdef *)upb_fielddef_subdef(f);
+ hd->keyname = newstrpc(h, f, preserve_fieldnames);
+ upb_handlers_addcleanup(h, hd, upb_gfree);
+ upb_handlerattr_sethandlerdata(attr, hd);
+}
+
+/* Set up handlers for a mapentry submessage (i.e., an individual key/value pair
+ * in a map).
+ *
+ * TODO: Handle missing key, missing value, out-of-order key/value, or repeated
+ * key or value cases properly. The right way to do this is to allocate a
+ * temporary structure at the start of a mapentry submessage, store key and
+ * value data in it as key and value handlers are called, and then print the
+ * key/value pair once at the end of the submessage. If we don't do this, we
+ * should at least detect the case and throw an error. However, so far all of
+ * our sources that emit mapentry messages do so canonically (with one key
+ * field, and then one value field), so this is not a pressing concern at the
+ * moment. */
+void printer_sethandlers_mapentry(const void *closure, bool preserve_fieldnames,
+ upb_handlers *h) {
+ const upb_msgdef *md = upb_handlers_msgdef(h);
+
+ /* A mapentry message is printed simply as '"key": value'. Rather than
+ * special-case key and value for every type below, we just handle both
+ * fields explicitly here. */
+ const upb_fielddef* key_field = upb_msgdef_itof(md, UPB_MAPENTRY_KEY);
+ const upb_fielddef* value_field = upb_msgdef_itof(md, UPB_MAPENTRY_VALUE);
+
+ upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER;
+
+ UPB_UNUSED(closure);
+
+ switch (upb_fielddef_type(key_field)) {
+ case UPB_TYPE_INT32:
+ upb_handlers_setint32(h, key_field, putmapkey_int32_t, &empty_attr);
+ break;
+ case UPB_TYPE_INT64:
+ upb_handlers_setint64(h, key_field, putmapkey_int64_t, &empty_attr);
+ break;
+ case UPB_TYPE_UINT32:
+ upb_handlers_setuint32(h, key_field, putmapkey_uint32_t, &empty_attr);
+ break;
+ case UPB_TYPE_UINT64:
+ upb_handlers_setuint64(h, key_field, putmapkey_uint64_t, &empty_attr);
+ break;
+ case UPB_TYPE_BOOL:
+ upb_handlers_setbool(h, key_field, putmapkey_bool, &empty_attr);
+ break;
+ case UPB_TYPE_STRING:
+ upb_handlers_setstartstr(h, key_field, mapkeyval_startstr, &empty_attr);
+ upb_handlers_setstring(h, key_field, mapkey_str, &empty_attr);
+ upb_handlers_setendstr(h, key_field, mapkey_endstr, &empty_attr);
+ break;
+ case UPB_TYPE_BYTES:
+ upb_handlers_setstring(h, key_field, mapkey_bytes, &empty_attr);
+ break;
+ default:
+ UPB_ASSERT(false);
+ break;
+ }
+
+ switch (upb_fielddef_type(value_field)) {
+ case UPB_TYPE_INT32:
+ upb_handlers_setint32(h, value_field, putint32_t, &empty_attr);
+ break;
+ case UPB_TYPE_INT64:
+ upb_handlers_setint64(h, value_field, putint64_t, &empty_attr);
+ break;
+ case UPB_TYPE_UINT32:
+ upb_handlers_setuint32(h, value_field, putuint32_t, &empty_attr);
+ break;
+ case UPB_TYPE_UINT64:
+ upb_handlers_setuint64(h, value_field, putuint64_t, &empty_attr);
+ break;
+ case UPB_TYPE_BOOL:
+ upb_handlers_setbool(h, value_field, putbool, &empty_attr);
+ break;
+ case UPB_TYPE_FLOAT:
+ upb_handlers_setfloat(h, value_field, putfloat, &empty_attr);
+ break;
+ case UPB_TYPE_DOUBLE:
+ upb_handlers_setdouble(h, value_field, putdouble, &empty_attr);
+ break;
+ case UPB_TYPE_STRING:
+ upb_handlers_setstartstr(h, value_field, mapkeyval_startstr, &empty_attr);
+ upb_handlers_setstring(h, value_field, putstr, &empty_attr);
+ upb_handlers_setendstr(h, value_field, mapvalue_endstr, &empty_attr);
+ break;
+ case UPB_TYPE_BYTES:
+ upb_handlers_setstring(h, value_field, putbytes, &empty_attr);
+ break;
+ case UPB_TYPE_ENUM: {
+ upb_handlerattr enum_attr = UPB_HANDLERATTR_INITIALIZER;
+ set_enum_hd(h, value_field, preserve_fieldnames, &enum_attr);
+ upb_handlers_setint32(h, value_field, mapvalue_enum, &enum_attr);
+ upb_handlerattr_uninit(&enum_attr);
+ break;
+ }
+ case UPB_TYPE_MESSAGE:
+ /* No handler necessary -- the submsg handlers will print the message
+ * as appropriate. */
+ break;
+ }
+
+ upb_handlerattr_uninit(&empty_attr);
+}
+
+void printer_sethandlers(const void *closure, upb_handlers *h) {
+ const upb_msgdef *md = upb_handlers_msgdef(h);
+ bool is_mapentry = upb_msgdef_mapentry(md);
+ upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_msg_field_iter i;
+ const bool *preserve_fieldnames_ptr = closure;
+ const bool preserve_fieldnames = *preserve_fieldnames_ptr;
+
+ if (is_mapentry) {
+ /* mapentry messages are sufficiently different that we handle them
+ * separately. */
+ printer_sethandlers_mapentry(closure, preserve_fieldnames, h);
+ return;
+ }
+
+ upb_handlers_setstartmsg(h, printer_startmsg, &empty_attr);
+ upb_handlers_setendmsg(h, printer_endmsg, &empty_attr);
+
+#define TYPE(type, name, ctype) \
+ case type: \
+ if (upb_fielddef_isseq(f)) { \
+ upb_handlers_set##name(h, f, repeated_##ctype, &empty_attr); \
+ } else { \
+ upb_handlers_set##name(h, f, scalar_##ctype, &name_attr); \
+ } \
+ break;
+
+ upb_msg_field_begin(&i, md);
+ for(; !upb_msg_field_done(&i); upb_msg_field_next(&i)) {
+ const upb_fielddef *f = upb_msg_iter_field(&i);
+
+ upb_handlerattr name_attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_handlerattr_sethandlerdata(&name_attr,
+ newstrpc(h, f, preserve_fieldnames));
+
+ if (upb_fielddef_ismap(f)) {
+ upb_handlers_setstartseq(h, f, startmap, &name_attr);
+ upb_handlers_setendseq(h, f, endmap, &name_attr);
+ } else if (upb_fielddef_isseq(f)) {
+ upb_handlers_setstartseq(h, f, startseq, &name_attr);
+ upb_handlers_setendseq(h, f, endseq, &empty_attr);
+ }
+
+ switch (upb_fielddef_type(f)) {
+ TYPE(UPB_TYPE_FLOAT, float, float);
+ TYPE(UPB_TYPE_DOUBLE, double, double);
+ TYPE(UPB_TYPE_BOOL, bool, bool);
+ TYPE(UPB_TYPE_INT32, int32, int32_t);
+ TYPE(UPB_TYPE_UINT32, uint32, uint32_t);
+ TYPE(UPB_TYPE_INT64, int64, int64_t);
+ TYPE(UPB_TYPE_UINT64, uint64, uint64_t);
+ case UPB_TYPE_ENUM: {
+ /* For now, we always emit symbolic names for enums. We may want an
+ * option later to control this behavior, but we will wait for a real
+ * need first. */
+ upb_handlerattr enum_attr = UPB_HANDLERATTR_INITIALIZER;
+ set_enum_hd(h, f, preserve_fieldnames, &enum_attr);
+
+ if (upb_fielddef_isseq(f)) {
+ upb_handlers_setint32(h, f, repeated_enum, &enum_attr);
+ } else {
+ upb_handlers_setint32(h, f, scalar_enum, &enum_attr);
+ }
+
+ upb_handlerattr_uninit(&enum_attr);
+ break;
+ }
+ case UPB_TYPE_STRING:
+ if (upb_fielddef_isseq(f)) {
+ upb_handlers_setstartstr(h, f, repeated_startstr, &empty_attr);
+ upb_handlers_setstring(h, f, repeated_str, &empty_attr);
+ upb_handlers_setendstr(h, f, repeated_endstr, &empty_attr);
+ } else {
+ upb_handlers_setstartstr(h, f, scalar_startstr, &name_attr);
+ upb_handlers_setstring(h, f, scalar_str, &empty_attr);
+ upb_handlers_setendstr(h, f, scalar_endstr, &empty_attr);
+ }
+ break;
+ case UPB_TYPE_BYTES:
+ /* XXX: this doesn't support strings that span buffers yet. The base64
+ * encoder will need to be made resumable for this to work properly. */
+ if (upb_fielddef_isseq(f)) {
+ upb_handlers_setstring(h, f, repeated_bytes, &empty_attr);
+ } else {
+ upb_handlers_setstring(h, f, scalar_bytes, &name_attr);
+ }
+ break;
+ case UPB_TYPE_MESSAGE:
+ if (upb_fielddef_isseq(f)) {
+ upb_handlers_setstartsubmsg(h, f, repeated_startsubmsg, &name_attr);
+ } else {
+ upb_handlers_setstartsubmsg(h, f, scalar_startsubmsg, &name_attr);
+ }
+ break;
+ }
+
+ upb_handlerattr_uninit(&name_attr);
+ }
+
+ upb_handlerattr_uninit(&empty_attr);
+#undef TYPE
+}
+
+static void json_printer_reset(upb_json_printer *p) {
+ p->depth_ = 0;
+}
+
+
+/* Public API *****************************************************************/
+
+upb_json_printer *upb_json_printer_create(upb_env *e, const upb_handlers *h,
+ upb_bytessink *output) {
+#ifndef NDEBUG
+ size_t size_before = upb_env_bytesallocated(e);
+#endif
+
+ upb_json_printer *p = upb_env_malloc(e, sizeof(upb_json_printer));
+ if (!p) return NULL;
+
+ p->output_ = output;
+ json_printer_reset(p);
+ upb_sink_reset(&p->input_, h, p);
+
+ /* If this fails, increase the value in printer.h. */
+ UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(e) - size_before <=
+ UPB_JSON_PRINTER_SIZE);
+ return p;
+}
+
+upb_sink *upb_json_printer_input(upb_json_printer *p) {
+ return &p->input_;
+}
+
+const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md,
+ bool preserve_fieldnames,
+ const void *owner) {
+ return upb_handlers_newfrozen(
+ md, owner, printer_sethandlers, &preserve_fieldnames);
+}
diff --git a/third_party/protobuf/php/ext/google/protobuf/upb.h b/third_party/protobuf/php/ext/google/protobuf/upb.h
new file mode 100644
index 0000000000..78f255f947
--- /dev/null
+++ b/third_party/protobuf/php/ext/google/protobuf/upb.h
@@ -0,0 +1,8875 @@
+// Amalgamated source file
+/*
+** Defs are upb's internal representation of the constructs that can appear
+** in a .proto file:
+**
+** - upb::MessageDef (upb_msgdef): describes a "message" construct.
+** - upb::FieldDef (upb_fielddef): describes a message field.
+** - upb::FileDef (upb_filedef): describes a .proto file and its defs.
+** - upb::EnumDef (upb_enumdef): describes an enum.
+** - upb::OneofDef (upb_oneofdef): describes a oneof.
+** - upb::Def (upb_def): base class of all the others.
+**
+** TODO: definitions of services.
+**
+** Like upb_refcounted objects, defs are mutable only until frozen, and are
+** only thread-safe once frozen.
+**
+** This is a mixed C/C++ interface that offers a full API to both languages.
+** See the top-level README for more information.
+*/
+
+#ifndef UPB_DEF_H_
+#define UPB_DEF_H_
+
+/*
+** upb::RefCounted (upb_refcounted)
+**
+** A refcounting scheme that supports circular refs. It accomplishes this by
+** partitioning the set of objects into groups such that no cycle spans groups;
+** we can then reference-count the group as a whole and ignore refs within the
+** group. When objects are mutable, these groups are computed very
+** conservatively; we group any objects that have ever had a link between them.
+** When objects are frozen, we compute strongly-connected components which
+** allows us to be precise and only group objects that are actually cyclic.
+**
+** This is a mixed C/C++ interface that offers a full API to both languages.
+** See the top-level README for more information.
+*/
+
+#ifndef UPB_REFCOUNTED_H_
+#define UPB_REFCOUNTED_H_
+
+/*
+** upb_table
+**
+** This header is INTERNAL-ONLY! Its interfaces are not public or stable!
+** This file defines very fast int->upb_value (inttable) and string->upb_value
+** (strtable) hash tables.
+**
+** The table uses chained scatter with Brent's variation (inspired by the Lua
+** implementation of hash tables). The hash function for strings is Austin
+** Appleby's "MurmurHash."
+**
+** The inttable uses uintptr_t as its key, which guarantees it can be used to
+** store pointers or integers of at least 32 bits (upb isn't really useful on
+** systems where sizeof(void*) < 4).
+**
+** The table must be homogenous (all values of the same type). In debug
+** mode, we check this on insert and lookup.
+*/
+
+#ifndef UPB_TABLE_H_
+#define UPB_TABLE_H_
+
+// php.h intentionally defined NDEBUG. We have to define this macro in order to
+// be used together with php.h
+#ifndef NDEBUG
+#define NDEBUG
+#endif
+
+#include <stdint.h>
+#include <string.h>
+/*
+** This file contains shared definitions that are widely used across upb.
+**
+** This is a mixed C/C++ interface that offers a full API to both languages.
+** See the top-level README for more information.
+*/
+
+#ifndef UPB_H_
+#define UPB_H_
+
+#include <assert.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stddef.h>
+
+#ifdef __cplusplus
+namespace upb {
+class Allocator;
+class Arena;
+class Environment;
+class ErrorSpace;
+class Status;
+template <int N> class InlinedArena;
+template <int N> class InlinedEnvironment;
+}
+#endif
+
+/* UPB_INLINE: inline if possible, emit standalone code if required. */
+#ifdef __cplusplus
+#define UPB_INLINE inline
+#elif defined (__GNUC__)
+#define UPB_INLINE static __inline__
+#else
+#define UPB_INLINE static
+#endif
+
+/* Define UPB_BIG_ENDIAN manually if you're on big endian and your compiler
+ * doesn't provide these preprocessor symbols. */
+#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#define UPB_BIG_ENDIAN
+#endif
+
+/* Macros for function attributes on compilers that support them. */
+#ifdef __GNUC__
+#define UPB_FORCEINLINE __inline__ __attribute__((always_inline))
+#define UPB_NOINLINE __attribute__((noinline))
+#define UPB_NORETURN __attribute__((__noreturn__))
+#else /* !defined(__GNUC__) */
+#define UPB_FORCEINLINE
+#define UPB_NOINLINE
+#define UPB_NORETURN
+#endif
+
+#if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L
+/* C99/C++11 versions. */
+#include <stdio.h>
+#define _upb_snprintf snprintf
+#define _upb_vsnprintf vsnprintf
+#define _upb_va_copy(a, b) va_copy(a, b)
+#elif defined __GNUC__
+/* A few hacky workarounds for functions not in C89.
+ * For internal use only!
+ * TODO(haberman): fix these by including our own implementations, or finding
+ * another workaround.
+ */
+#define _upb_snprintf __builtin_snprintf
+#define _upb_vsnprintf __builtin_vsnprintf
+#define _upb_va_copy(a, b) __va_copy(a, b)
+#else
+#error Need implementations of [v]snprintf and va_copy
+#endif
+
+
+#if ((defined(__cplusplus) && __cplusplus >= 201103L) || \
+ defined(__GXX_EXPERIMENTAL_CXX0X__)) && !defined(UPB_NO_CXX11)
+#define UPB_CXX11
+#endif
+
+/* UPB_DISALLOW_COPY_AND_ASSIGN()
+ * UPB_DISALLOW_POD_OPS()
+ *
+ * Declare these in the "private" section of a C++ class to forbid copy/assign
+ * or all POD ops (construct, destruct, copy, assign) on that class. */
+#ifdef UPB_CXX11
+#include <type_traits>
+#define UPB_DISALLOW_COPY_AND_ASSIGN(class_name) \
+ class_name(const class_name&) = delete; \
+ void operator=(const class_name&) = delete;
+#define UPB_DISALLOW_POD_OPS(class_name, full_class_name) \
+ class_name() = delete; \
+ ~class_name() = delete; \
+ UPB_DISALLOW_COPY_AND_ASSIGN(class_name)
+#define UPB_ASSERT_STDLAYOUT(type) \
+ static_assert(std::is_standard_layout<type>::value, \
+ #type " must be standard layout");
+#define UPB_FINAL final
+#else /* !defined(UPB_CXX11) */
+#define UPB_DISALLOW_COPY_AND_ASSIGN(class_name) \
+ class_name(const class_name&); \
+ void operator=(const class_name&);
+#define UPB_DISALLOW_POD_OPS(class_name, full_class_name) \
+ class_name(); \
+ ~class_name(); \
+ UPB_DISALLOW_COPY_AND_ASSIGN(class_name)
+#define UPB_ASSERT_STDLAYOUT(type)
+#define UPB_FINAL
+#endif
+
+/* UPB_DECLARE_TYPE()
+ * UPB_DECLARE_DERIVED_TYPE()
+ * UPB_DECLARE_DERIVED_TYPE2()
+ *
+ * Macros for declaring C and C++ types both, including inheritance.
+ * The inheritance doesn't use real C++ inheritance, to stay compatible with C.
+ *
+ * These macros also provide upcasts:
+ * - in C: types-specific functions (ie. upb_foo_upcast(foo))
+ * - in C++: upb::upcast(foo) along with implicit conversions
+ *
+ * Downcasts are not provided, but upb/def.h defines downcasts for upb::Def. */
+
+#define UPB_C_UPCASTS(ty, base) \
+ UPB_INLINE base *ty ## _upcast_mutable(ty *p) { return (base*)p; } \
+ UPB_INLINE const base *ty ## _upcast(const ty *p) { return (const base*)p; }
+
+#define UPB_C_UPCASTS2(ty, base, base2) \
+ UPB_C_UPCASTS(ty, base) \
+ UPB_INLINE base2 *ty ## _upcast2_mutable(ty *p) { return (base2*)p; } \
+ UPB_INLINE const base2 *ty ## _upcast2(const ty *p) { return (const base2*)p; }
+
+#ifdef __cplusplus
+
+#define UPB_BEGIN_EXTERN_C extern "C" {
+#define UPB_END_EXTERN_C }
+#define UPB_PRIVATE_FOR_CPP private:
+#define UPB_DECLARE_TYPE(cppname, cname) typedef cppname cname;
+
+#define UPB_DECLARE_DERIVED_TYPE(cppname, cppbase, cname, cbase) \
+ UPB_DECLARE_TYPE(cppname, cname) \
+ UPB_C_UPCASTS(cname, cbase) \
+ namespace upb { \
+ template <> \
+ class Pointer<cppname> : public PointerBase<cppname, cppbase> { \
+ public: \
+ explicit Pointer(cppname* ptr) \
+ : PointerBase<cppname, cppbase>(ptr) {} \
+ }; \
+ template <> \
+ class Pointer<const cppname> \
+ : public PointerBase<const cppname, const cppbase> { \
+ public: \
+ explicit Pointer(const cppname* ptr) \
+ : PointerBase<const cppname, const cppbase>(ptr) {} \
+ }; \
+ }
+
+#define UPB_DECLARE_DERIVED_TYPE2(cppname, cppbase, cppbase2, cname, cbase, \
+ cbase2) \
+ UPB_DECLARE_TYPE(cppname, cname) \
+ UPB_C_UPCASTS2(cname, cbase, cbase2) \
+ namespace upb { \
+ template <> \
+ class Pointer<cppname> : public PointerBase2<cppname, cppbase, cppbase2> { \
+ public: \
+ explicit Pointer(cppname* ptr) \
+ : PointerBase2<cppname, cppbase, cppbase2>(ptr) {} \
+ }; \
+ template <> \
+ class Pointer<const cppname> \
+ : public PointerBase2<const cppname, const cppbase, const cppbase2> { \
+ public: \
+ explicit Pointer(const cppname* ptr) \
+ : PointerBase2<const cppname, const cppbase, const cppbase2>(ptr) {} \
+ }; \
+ }
+
+#else /* !defined(__cplusplus) */
+
+#define UPB_BEGIN_EXTERN_C
+#define UPB_END_EXTERN_C
+#define UPB_PRIVATE_FOR_CPP
+#define UPB_DECLARE_TYPE(cppname, cname) \
+ struct cname; \
+ typedef struct cname cname;
+#define UPB_DECLARE_DERIVED_TYPE(cppname, cppbase, cname, cbase) \
+ UPB_DECLARE_TYPE(cppname, cname) \
+ UPB_C_UPCASTS(cname, cbase)
+#define UPB_DECLARE_DERIVED_TYPE2(cppname, cppbase, cppbase2, \
+ cname, cbase, cbase2) \
+ UPB_DECLARE_TYPE(cppname, cname) \
+ UPB_C_UPCASTS2(cname, cbase, cbase2)
+
+#endif /* defined(__cplusplus) */
+
+#define UPB_MAX(x, y) ((x) > (y) ? (x) : (y))
+#define UPB_MIN(x, y) ((x) < (y) ? (x) : (y))
+
+#define UPB_UNUSED(var) (void)var
+
+/* UPB_ASSERT(): in release mode, we use the expression without letting it be
+ * evaluated. This prevents "unused variable" warnings. */
+#ifdef NDEBUG
+#define UPB_ASSERT(expr) do {} while (false && (expr))
+#else
+#define UPB_ASSERT(expr) assert(expr)
+#endif
+
+/* UPB_ASSERT_DEBUGVAR(): assert that uses functions or variables that only
+ * exist in debug mode. This turns into regular assert. */
+#define UPB_ASSERT_DEBUGVAR(expr) assert(expr)
+
+#ifdef __GNUC__
+#define UPB_UNREACHABLE() do { assert(0); __builtin_unreachable(); } while(0)
+#else
+#define UPB_UNREACHABLE() do { assert(0); } while(0)
+#endif
+
+/* Generic function type. */
+typedef void upb_func();
+
+
+/* C++ Casts ******************************************************************/
+
+#ifdef __cplusplus
+
+namespace upb {
+
+template <class T> class Pointer;
+
+/* Casts to a subclass. The caller must know that cast is correct; an
+ * incorrect cast will throw an assertion failure in debug mode.
+ *
+ * Example:
+ * upb::Def* def = GetDef();
+ * // Assert-fails if this was not actually a MessageDef.
+ * upb::MessgeDef* md = upb::down_cast<upb::MessageDef>(def);
+ *
+ * Note that downcasts are only defined for some types (at the moment you can
+ * only downcast from a upb::Def to a specific Def type). */
+template<class To, class From> To down_cast(From* f);
+
+/* Casts to a subclass. If the class does not actually match the given To type,
+ * returns NULL.
+ *
+ * Example:
+ * upb::Def* def = GetDef();
+ * // md will be NULL if this was not actually a MessageDef.
+ * upb::MessgeDef* md = upb::down_cast<upb::MessageDef>(def);
+ *
+ * Note that dynamic casts are only defined for some types (at the moment you
+ * can only downcast from a upb::Def to a specific Def type).. */
+template<class To, class From> To dyn_cast(From* f);
+
+/* Casts to any base class, or the type itself (ie. can be a no-op).
+ *
+ * Example:
+ * upb::MessageDef* md = GetDef();
+ * // This will fail to compile if this wasn't actually a base class.
+ * upb::Def* def = upb::upcast(md);
+ */
+template <class T> inline Pointer<T> upcast(T *f) { return Pointer<T>(f); }
+
+/* Attempt upcast to specific base class.
+ *
+ * Example:
+ * upb::MessageDef* md = GetDef();
+ * upb::upcast_to<upb::Def>(md)->MethodOnDef();
+ */
+template <class T, class F> inline T* upcast_to(F *f) {
+ return static_cast<T*>(upcast(f));
+}
+
+/* PointerBase<T>: implementation detail of upb::upcast().
+ * It is implicitly convertable to pointers to the Base class(es).
+ */
+template <class T, class Base>
+class PointerBase {
+ public:
+ explicit PointerBase(T* ptr) : ptr_(ptr) {}
+ operator T*() { return ptr_; }
+ operator Base*() { return (Base*)ptr_; }
+
+ private:
+ T* ptr_;
+};
+
+template <class T, class Base, class Base2>
+class PointerBase2 : public PointerBase<T, Base> {
+ public:
+ explicit PointerBase2(T* ptr) : PointerBase<T, Base>(ptr) {}
+ operator Base2*() { return Pointer<Base>(*this); }
+};
+
+}
+
+#endif
+
+
+/* upb::ErrorSpace ************************************************************/
+
+/* A upb::ErrorSpace represents some domain of possible error values. This lets
+ * upb::Status attach specific error codes to operations, like POSIX/C errno,
+ * Win32 error codes, etc. Clients who want to know the very specific error
+ * code can check the error space and then know the type of the integer code.
+ *
+ * NOTE: upb::ErrorSpace is currently not used and should be considered
+ * experimental. It is important primarily in cases where upb is performing
+ * I/O, but upb doesn't currently have any components that do this. */
+
+UPB_DECLARE_TYPE(upb::ErrorSpace, upb_errorspace)
+
+#ifdef __cplusplus
+class upb::ErrorSpace {
+#else
+struct upb_errorspace {
+#endif
+ const char *name;
+};
+
+
+/* upb::Status ****************************************************************/
+
+/* upb::Status represents a success or failure status and error message.
+ * It owns no resources and allocates no memory, so it should work
+ * even in OOM situations. */
+UPB_DECLARE_TYPE(upb::Status, upb_status)
+
+/* The maximum length of an error message before it will get truncated. */
+#define UPB_STATUS_MAX_MESSAGE 128
+
+UPB_BEGIN_EXTERN_C
+
+const char *upb_status_errmsg(const upb_status *status);
+bool upb_ok(const upb_status *status);
+upb_errorspace *upb_status_errspace(const upb_status *status);
+int upb_status_errcode(const upb_status *status);
+
+/* Any of the functions that write to a status object allow status to be NULL,
+ * to support use cases where the function's caller does not care about the
+ * status message. */
+void upb_status_clear(upb_status *status);
+void upb_status_seterrmsg(upb_status *status, const char *msg);
+void upb_status_seterrf(upb_status *status, const char *fmt, ...);
+void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args);
+void upb_status_copy(upb_status *to, const upb_status *from);
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+class upb::Status {
+ public:
+ Status() { upb_status_clear(this); }
+
+ /* Returns true if there is no error. */
+ bool ok() const { return upb_ok(this); }
+
+ /* Optional error space and code, useful if the caller wants to
+ * programmatically check the specific kind of error. */
+ ErrorSpace* error_space() { return upb_status_errspace(this); }
+ int error_code() const { return upb_status_errcode(this); }
+
+ /* The returned string is invalidated by any other call into the status. */
+ const char *error_message() const { return upb_status_errmsg(this); }
+
+ /* The error message will be truncated if it is longer than
+ * UPB_STATUS_MAX_MESSAGE-4. */
+ void SetErrorMessage(const char* msg) { upb_status_seterrmsg(this, msg); }
+ void SetFormattedErrorMessage(const char* fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ upb_status_vseterrf(this, fmt, args);
+ va_end(args);
+ }
+
+ /* Resets the status to a successful state with no message. */
+ void Clear() { upb_status_clear(this); }
+
+ void CopyFrom(const Status& other) { upb_status_copy(this, &other); }
+
+ private:
+ UPB_DISALLOW_COPY_AND_ASSIGN(Status)
+#else
+struct upb_status {
+#endif
+ bool ok_;
+
+ /* Specific status code defined by some error space (optional). */
+ int code_;
+ upb_errorspace *error_space_;
+
+ /* TODO(haberman): add file/line of error? */
+
+ /* Error message; NULL-terminated. */
+ char msg[UPB_STATUS_MAX_MESSAGE];
+};
+
+#define UPB_STATUS_INIT {true, 0, NULL, {0}}
+
+
+/** Built-in error spaces. ****************************************************/
+
+/* Errors raised by upb that we want to be able to detect programmatically. */
+typedef enum {
+ UPB_NOMEM /* Can't reuse ENOMEM because it is POSIX, not ISO C. */
+} upb_errcode_t;
+
+extern upb_errorspace upb_upberr;
+
+void upb_upberr_setoom(upb_status *s);
+
+/* Since errno is defined by standard C, we define an error space for it in
+ * core upb. Other error spaces should be defined in other, platform-specific
+ * modules. */
+
+extern upb_errorspace upb_errnoerr;
+
+
+/** upb::Allocator ************************************************************/
+
+/* A upb::Allocator is a possibly-stateful allocator object.
+ *
+ * It could either be an arena allocator (which doesn't require individual
+ * free() calls) or a regular malloc() (which does). The client must therefore
+ * free memory unless it knows that the allocator is an arena allocator. */
+UPB_DECLARE_TYPE(upb::Allocator, upb_alloc)
+
+/* A malloc()/free() function.
+ * If "size" is 0 then the function acts like free(), otherwise it acts like
+ * realloc(). Only "oldsize" bytes from a previous allocation are preserved. */
+typedef void *upb_alloc_func(upb_alloc *alloc, void *ptr, size_t oldsize,
+ size_t size);
+
+#ifdef __cplusplus
+
+class upb::Allocator UPB_FINAL {
+ public:
+ Allocator() {}
+
+ private:
+ UPB_DISALLOW_COPY_AND_ASSIGN(Allocator)
+
+ public:
+#else
+struct upb_alloc {
+#endif /* __cplusplus */
+ upb_alloc_func *func;
+};
+
+UPB_INLINE void *upb_malloc(upb_alloc *alloc, size_t size) {
+ UPB_ASSERT(alloc);
+ return alloc->func(alloc, NULL, 0, size);
+}
+
+UPB_INLINE void *upb_realloc(upb_alloc *alloc, void *ptr, size_t oldsize,
+ size_t size) {
+ UPB_ASSERT(alloc);
+ return alloc->func(alloc, ptr, oldsize, size);
+}
+
+UPB_INLINE void upb_free(upb_alloc *alloc, void *ptr) {
+ assert(alloc);
+ alloc->func(alloc, ptr, 0, 0);
+}
+
+/* The global allocator used by upb. Uses the standard malloc()/free(). */
+
+extern upb_alloc upb_alloc_global;
+
+/* Functions that hard-code the global malloc.
+ *
+ * We still get benefit because we can put custom logic into our global
+ * allocator, like injecting out-of-memory faults in debug/testing builds. */
+
+UPB_INLINE void *upb_gmalloc(size_t size) {
+ return upb_malloc(&upb_alloc_global, size);
+}
+
+UPB_INLINE void *upb_grealloc(void *ptr, size_t oldsize, size_t size) {
+ return upb_realloc(&upb_alloc_global, ptr, oldsize, size);
+}
+
+UPB_INLINE void upb_gfree(void *ptr) {
+ upb_free(&upb_alloc_global, ptr);
+}
+
+/* upb::Arena *****************************************************************/
+
+/* upb::Arena is a specific allocator implementation that uses arena allocation.
+ * The user provides an allocator that will be used to allocate the underlying
+ * arena blocks. Arenas by nature do not require the individual allocations
+ * to be freed. However the Arena does allow users to register cleanup
+ * functions that will run when the arena is destroyed.
+ *
+ * A upb::Arena is *not* thread-safe.
+ *
+ * You could write a thread-safe arena allocator that satisfies the
+ * upb::Allocator interface, but it would not be as efficient for the
+ * single-threaded case. */
+UPB_DECLARE_TYPE(upb::Arena, upb_arena)
+
+typedef void upb_cleanup_func(void *ud);
+
+#define UPB_ARENA_BLOCK_OVERHEAD (sizeof(size_t)*4)
+
+UPB_BEGIN_EXTERN_C
+
+void upb_arena_init(upb_arena *a);
+void upb_arena_init2(upb_arena *a, void *mem, size_t n, upb_alloc *alloc);
+void upb_arena_uninit(upb_arena *a);
+bool upb_arena_addcleanup(upb_arena *a, upb_cleanup_func *func, void *ud);
+size_t upb_arena_bytesallocated(const upb_arena *a);
+void upb_arena_setnextblocksize(upb_arena *a, size_t size);
+void upb_arena_setmaxblocksize(upb_arena *a, size_t size);
+UPB_INLINE upb_alloc *upb_arena_alloc(upb_arena *a) { return (upb_alloc*)a; }
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+class upb::Arena {
+ public:
+ /* A simple arena with no initial memory block and the default allocator. */
+ Arena() { upb_arena_init(this); }
+
+ /* Constructs an arena with the given initial block which allocates blocks
+ * with the given allocator. The given allocator must outlive the Arena.
+ *
+ * If you pass NULL for the allocator it will default to the global allocator
+ * upb_alloc_global, and NULL/0 for the initial block will cause there to be
+ * no initial block. */
+ Arena(void *mem, size_t len, Allocator* a) {
+ upb_arena_init2(this, mem, len, a);
+ }
+
+ ~Arena() { upb_arena_uninit(this); }
+
+ /* Sets the size of the next block the Arena will request (unless the
+ * requested allocation is larger). Each block will double in size until the
+ * max limit is reached. */
+ void SetNextBlockSize(size_t size) { upb_arena_setnextblocksize(this, size); }
+
+ /* Sets the maximum block size. No blocks larger than this will be requested
+ * from the underlying allocator unless individual arena allocations are
+ * larger. */
+ void SetMaxBlockSize(size_t size) { upb_arena_setmaxblocksize(this, size); }
+
+ /* Allows this arena to be used as a generic allocator.
+ *
+ * The arena does not need free() calls so when using Arena as an allocator
+ * it is safe to skip them. However they are no-ops so there is no harm in
+ * calling free() either. */
+ Allocator* allocator() { return upb_arena_alloc(this); }
+
+ /* Add a cleanup function to run when the arena is destroyed.
+ * Returns false on out-of-memory. */
+ bool AddCleanup(upb_cleanup_func* func, void* ud) {
+ return upb_arena_addcleanup(this, func, ud);
+ }
+
+ /* Total number of bytes that have been allocated. It is undefined what
+ * Realloc() does to this counter. */
+ size_t BytesAllocated() const {
+ return upb_arena_bytesallocated(this);
+ }
+
+ private:
+ UPB_DISALLOW_COPY_AND_ASSIGN(Arena)
+
+#else
+struct upb_arena {
+#endif /* __cplusplus */
+ /* We implement the allocator interface.
+ * This must be the first member of upb_arena! */
+ upb_alloc alloc;
+
+ /* Allocator to allocate arena blocks. We are responsible for freeing these
+ * when we are destroyed. */
+ upb_alloc *block_alloc;
+
+ size_t bytes_allocated;
+ size_t next_block_size;
+ size_t max_block_size;
+
+ /* Linked list of blocks. Points to an arena_block, defined in env.c */
+ void *block_head;
+
+ /* Cleanup entries. Pointer to a cleanup_ent, defined in env.c */
+ void *cleanup_head;
+
+ /* For future expansion, since the size of this struct is exposed to users. */
+ void *future1;
+ void *future2;
+};
+
+
+/* upb::Environment ***********************************************************/
+
+/* A upb::Environment provides a means for injecting malloc and an
+ * error-reporting callback into encoders/decoders. This allows them to be
+ * independent of nearly all assumptions about their actual environment.
+ *
+ * It is also a container for allocating the encoders/decoders themselves that
+ * insulates clients from knowing their actual size. This provides ABI
+ * compatibility even if the size of the objects change. And this allows the
+ * structure definitions to be in the .c files instead of the .h files, making
+ * the .h files smaller and more readable.
+ *
+ * We might want to consider renaming this to "Pipeline" if/when the concept of
+ * a pipeline element becomes more formalized. */
+UPB_DECLARE_TYPE(upb::Environment, upb_env)
+
+/* A function that receives an error report from an encoder or decoder. The
+ * callback can return true to request that the error should be recovered, but
+ * if the error is not recoverable this has no effect. */
+typedef bool upb_error_func(void *ud, const upb_status *status);
+
+UPB_BEGIN_EXTERN_C
+
+void upb_env_init(upb_env *e);
+void upb_env_init2(upb_env *e, void *mem, size_t n, upb_alloc *alloc);
+void upb_env_uninit(upb_env *e);
+
+void upb_env_initonly(upb_env *e);
+
+upb_arena *upb_env_arena(upb_env *e);
+bool upb_env_ok(const upb_env *e);
+void upb_env_seterrorfunc(upb_env *e, upb_error_func *func, void *ud);
+
+/* Convenience wrappers around the methods of the contained arena. */
+void upb_env_reporterrorsto(upb_env *e, upb_status *s);
+bool upb_env_reporterror(upb_env *e, const upb_status *s);
+void *upb_env_malloc(upb_env *e, size_t size);
+void *upb_env_realloc(upb_env *e, void *ptr, size_t oldsize, size_t size);
+void upb_env_free(upb_env *e, void *ptr);
+bool upb_env_addcleanup(upb_env *e, upb_cleanup_func *func, void *ud);
+size_t upb_env_bytesallocated(const upb_env *e);
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+class upb::Environment {
+ public:
+ /* The given Arena must outlive this environment. */
+ Environment() { upb_env_initonly(this); }
+
+ Environment(void *mem, size_t len, Allocator *a) : arena_(mem, len, a) {
+ upb_env_initonly(this);
+ }
+
+ Arena* arena() { return upb_env_arena(this); }
+
+ /* Set a custom error reporting function. */
+ void SetErrorFunction(upb_error_func* func, void* ud) {
+ upb_env_seterrorfunc(this, func, ud);
+ }
+
+ /* Set the error reporting function to simply copy the status to the given
+ * status and abort. */
+ void ReportErrorsTo(Status* status) { upb_env_reporterrorsto(this, status); }
+
+ /* Returns true if all allocations and AddCleanup() calls have succeeded,
+ * and no errors were reported with ReportError() (except ones that recovered
+ * successfully). */
+ bool ok() const { return upb_env_ok(this); }
+
+ /* Reports an error to this environment's callback, returning true if
+ * the caller should try to recover. */
+ bool ReportError(const Status* status) {
+ return upb_env_reporterror(this, status);
+ }
+
+ private:
+ UPB_DISALLOW_COPY_AND_ASSIGN(Environment)
+
+#else
+struct upb_env {
+#endif /* __cplusplus */
+ upb_arena arena_;
+ upb_error_func *error_func_;
+ void *error_ud_;
+ bool ok_;
+};
+
+
+/* upb::InlinedArena **********************************************************/
+/* upb::InlinedEnvironment ****************************************************/
+
+/* upb::InlinedArena and upb::InlinedEnvironment seed their arenas with a
+ * predefined amount of memory. No heap memory will be allocated until the
+ * initial block is exceeded.
+ *
+ * These types only exist in C++ */
+
+#ifdef __cplusplus
+
+template <int N> class upb::InlinedArena : public upb::Arena {
+ public:
+ InlinedArena() : Arena(initial_block_, N, NULL) {}
+ explicit InlinedArena(Allocator* a) : Arena(initial_block_, N, a) {}
+
+ private:
+ UPB_DISALLOW_COPY_AND_ASSIGN(InlinedArena)
+
+ char initial_block_[N + UPB_ARENA_BLOCK_OVERHEAD];
+};
+
+template <int N> class upb::InlinedEnvironment : public upb::Environment {
+ public:
+ InlinedEnvironment() : Environment(initial_block_, N, NULL) {}
+ explicit InlinedEnvironment(Allocator *a)
+ : Environment(initial_block_, N, a) {}
+
+ private:
+ UPB_DISALLOW_COPY_AND_ASSIGN(InlinedEnvironment)
+
+ char initial_block_[N + UPB_ARENA_BLOCK_OVERHEAD];
+};
+
+#endif /* __cplusplus */
+
+
+
+#endif /* UPB_H_ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* upb_value ******************************************************************/
+
+/* A tagged union (stored untagged inside the table) so that we can check that
+ * clients calling table accessors are correctly typed without having to have
+ * an explosion of accessors. */
+typedef enum {
+ UPB_CTYPE_INT32 = 1,
+ UPB_CTYPE_INT64 = 2,
+ UPB_CTYPE_UINT32 = 3,
+ UPB_CTYPE_UINT64 = 4,
+ UPB_CTYPE_BOOL = 5,
+ UPB_CTYPE_CSTR = 6,
+ UPB_CTYPE_PTR = 7,
+ UPB_CTYPE_CONSTPTR = 8,
+ UPB_CTYPE_FPTR = 9,
+ UPB_CTYPE_FLOAT = 10,
+ UPB_CTYPE_DOUBLE = 11
+} upb_ctype_t;
+
+typedef struct {
+ uint64_t val;
+#ifndef NDEBUG
+ /* In debug mode we carry the value type around also so we can check accesses
+ * to be sure the right member is being read. */
+ upb_ctype_t ctype;
+#endif
+} upb_value;
+
+#ifdef NDEBUG
+#define SET_TYPE(dest, val) UPB_UNUSED(val)
+#else
+#define SET_TYPE(dest, val) dest = val
+#endif
+
+/* Like strdup(), which isn't always available since it's not ANSI C. */
+char *upb_strdup(const char *s, upb_alloc *a);
+/* Variant that works with a length-delimited rather than NULL-delimited string,
+ * as supported by strtable. */
+char *upb_strdup2(const char *s, size_t len, upb_alloc *a);
+
+UPB_INLINE char *upb_gstrdup(const char *s) {
+ return upb_strdup(s, &upb_alloc_global);
+}
+
+UPB_INLINE void _upb_value_setval(upb_value *v, uint64_t val,
+ upb_ctype_t ctype) {
+ v->val = val;
+ SET_TYPE(v->ctype, ctype);
+}
+
+UPB_INLINE upb_value _upb_value_val(uint64_t val, upb_ctype_t ctype) {
+ upb_value ret;
+ _upb_value_setval(&ret, val, ctype);
+ return ret;
+}
+
+/* For each value ctype, define the following set of functions:
+ *
+ * // Get/set an int32 from a upb_value.
+ * int32_t upb_value_getint32(upb_value val);
+ * void upb_value_setint32(upb_value *val, int32_t cval);
+ *
+ * // Construct a new upb_value from an int32.
+ * upb_value upb_value_int32(int32_t val); */
+#define FUNCS(name, membername, type_t, converter, proto_type) \
+ UPB_INLINE void upb_value_set ## name(upb_value *val, type_t cval) { \
+ val->val = (converter)cval; \
+ SET_TYPE(val->ctype, proto_type); \
+ } \
+ UPB_INLINE upb_value upb_value_ ## name(type_t val) { \
+ upb_value ret; \
+ upb_value_set ## name(&ret, val); \
+ return ret; \
+ } \
+ UPB_INLINE type_t upb_value_get ## name(upb_value val) { \
+ UPB_ASSERT_DEBUGVAR(val.ctype == proto_type); \
+ return (type_t)(converter)val.val; \
+ }
+
+FUNCS(int32, int32, int32_t, int32_t, UPB_CTYPE_INT32)
+FUNCS(int64, int64, int64_t, int64_t, UPB_CTYPE_INT64)
+FUNCS(uint32, uint32, uint32_t, uint32_t, UPB_CTYPE_UINT32)
+FUNCS(uint64, uint64, uint64_t, uint64_t, UPB_CTYPE_UINT64)
+FUNCS(bool, _bool, bool, bool, UPB_CTYPE_BOOL)
+FUNCS(cstr, cstr, char*, uintptr_t, UPB_CTYPE_CSTR)
+FUNCS(ptr, ptr, void*, uintptr_t, UPB_CTYPE_PTR)
+FUNCS(constptr, constptr, const void*, uintptr_t, UPB_CTYPE_CONSTPTR)
+FUNCS(fptr, fptr, upb_func*, uintptr_t, UPB_CTYPE_FPTR)
+
+#undef FUNCS
+
+UPB_INLINE void upb_value_setfloat(upb_value *val, float cval) {
+ memcpy(&val->val, &cval, sizeof(cval));
+ SET_TYPE(val->ctype, UPB_CTYPE_FLOAT);
+}
+
+UPB_INLINE void upb_value_setdouble(upb_value *val, double cval) {
+ memcpy(&val->val, &cval, sizeof(cval));
+ SET_TYPE(val->ctype, UPB_CTYPE_DOUBLE);
+}
+
+UPB_INLINE upb_value upb_value_float(float cval) {
+ upb_value ret;
+ upb_value_setfloat(&ret, cval);
+ return ret;
+}
+
+UPB_INLINE upb_value upb_value_double(double cval) {
+ upb_value ret;
+ upb_value_setdouble(&ret, cval);
+ return ret;
+}
+
+#undef SET_TYPE
+
+
+/* upb_tabkey *****************************************************************/
+
+/* Either:
+ * 1. an actual integer key, or
+ * 2. a pointer to a string prefixed by its uint32_t length, owned by us.
+ *
+ * ...depending on whether this is a string table or an int table. We would
+ * make this a union of those two types, but C89 doesn't support statically
+ * initializing a non-first union member. */
+typedef uintptr_t upb_tabkey;
+
+#define UPB_TABKEY_NUM(n) n
+#define UPB_TABKEY_NONE 0
+/* The preprocessor isn't quite powerful enough to turn the compile-time string
+ * length into a byte-wise string representation, so code generation needs to
+ * help it along.
+ *
+ * "len1" is the low byte and len4 is the high byte. */
+#ifdef UPB_BIG_ENDIAN
+#define UPB_TABKEY_STR(len1, len2, len3, len4, strval) \
+ (uintptr_t)(len4 len3 len2 len1 strval)
+#else
+#define UPB_TABKEY_STR(len1, len2, len3, len4, strval) \
+ (uintptr_t)(len1 len2 len3 len4 strval)
+#endif
+
+UPB_INLINE char *upb_tabstr(upb_tabkey key, uint32_t *len) {
+ char* mem = (char*)key;
+ if (len) memcpy(len, mem, sizeof(*len));
+ return mem + sizeof(*len);
+}
+
+
+/* upb_tabval *****************************************************************/
+
+#ifdef __cplusplus
+
+/* Status initialization not supported.
+ *
+ * This separate definition is necessary because in C++, UINTPTR_MAX isn't
+ * reliably available. */
+typedef struct {
+ uint64_t val;
+} upb_tabval;
+
+#else
+
+/* C -- supports static initialization, but to support static initialization of
+ * both integers and points for both 32 and 64 bit targets, it takes a little
+ * bit of doing. */
+
+#if UINTPTR_MAX == 0xffffffffffffffffULL
+#define UPB_PTR_IS_64BITS
+#elif UINTPTR_MAX != 0xffffffff
+#error Could not determine how many bits pointers are.
+#endif
+
+typedef union {
+ /* For static initialization.
+ *
+ * Unfortunately this ugliness is necessary -- it is the only way that we can,
+ * with -std=c89 -pedantic, statically initialize this to either a pointer or
+ * an integer on 32-bit platforms. */
+ struct {
+#ifdef UPB_PTR_IS_64BITS
+ uintptr_t val;
+#else
+ uintptr_t val1;
+ uintptr_t val2;
+#endif
+ } staticinit;
+
+ /* The normal accessor that we use for everything at runtime. */
+ uint64_t val;
+} upb_tabval;
+
+#ifdef UPB_PTR_IS_64BITS
+#define UPB_TABVALUE_INT_INIT(v) {{v}}
+#define UPB_TABVALUE_EMPTY_INIT {{-1}}
+#else
+
+/* 32-bit pointers */
+
+#ifdef UPB_BIG_ENDIAN
+#define UPB_TABVALUE_INT_INIT(v) {{0, v}}
+#define UPB_TABVALUE_EMPTY_INIT {{-1, -1}}
+#else
+#define UPB_TABVALUE_INT_INIT(v) {{v, 0}}
+#define UPB_TABVALUE_EMPTY_INIT {{-1, -1}}
+#endif
+
+#endif
+
+#define UPB_TABVALUE_PTR_INIT(v) UPB_TABVALUE_INT_INIT((uintptr_t)v)
+
+#undef UPB_PTR_IS_64BITS
+
+#endif /* __cplusplus */
+
+
+/* upb_table ******************************************************************/
+
+typedef struct _upb_tabent {
+ upb_tabkey key;
+ upb_tabval val;
+
+ /* Internal chaining. This is const so we can create static initializers for
+ * tables. We cast away const sometimes, but *only* when the containing
+ * upb_table is known to be non-const. This requires a bit of care, but
+ * the subtlety is confined to table.c. */
+ const struct _upb_tabent *next;
+} upb_tabent;
+
+typedef struct {
+ size_t count; /* Number of entries in the hash part. */
+ size_t mask; /* Mask to turn hash value -> bucket. */
+ upb_ctype_t ctype; /* Type of all values. */
+ uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */
+
+ /* Hash table entries.
+ * Making this const isn't entirely accurate; what we really want is for it to
+ * have the same const-ness as the table it's inside. But there's no way to
+ * declare that in C. So we have to make it const so that we can statically
+ * initialize const hash tables. Then we cast away const when we have to.
+ */
+ const upb_tabent *entries;
+
+#ifndef NDEBUG
+ /* This table's allocator. We make the user pass it in to every relevant
+ * function and only use this to check it in debug mode. We do this solely
+ * to keep upb_table as small as possible. This might seem slightly paranoid
+ * but the plan is to use upb_table for all map fields and extension sets in
+ * a forthcoming message representation, so there could be a lot of these.
+ * If this turns out to be too annoying later, we can change it (since this
+ * is an internal-only header file). */
+ upb_alloc *alloc;
+#endif
+} upb_table;
+
+#ifdef NDEBUG
+# define UPB_TABLE_INIT(count, mask, ctype, size_lg2, entries) \
+ {count, mask, ctype, size_lg2, entries}
+#else
+# ifdef UPB_DEBUG_REFS
+/* At the moment the only mutable tables we statically initialize are debug
+ * ref tables. */
+# define UPB_TABLE_INIT(count, mask, ctype, size_lg2, entries) \
+ {count, mask, ctype, size_lg2, entries, &upb_alloc_debugrefs}
+# else
+# define UPB_TABLE_INIT(count, mask, ctype, size_lg2, entries) \
+ {count, mask, ctype, size_lg2, entries, NULL}
+# endif
+#endif
+
+typedef struct {
+ upb_table t;
+} upb_strtable;
+
+#define UPB_STRTABLE_INIT(count, mask, ctype, size_lg2, entries) \
+ {UPB_TABLE_INIT(count, mask, ctype, size_lg2, entries)}
+
+#define UPB_EMPTY_STRTABLE_INIT(ctype) \
+ UPB_STRTABLE_INIT(0, 0, ctype, 0, NULL)
+
+typedef struct {
+ upb_table t; /* For entries that don't fit in the array part. */
+ const upb_tabval *array; /* Array part of the table. See const note above. */
+ size_t array_size; /* Array part size. */
+ size_t array_count; /* Array part number of elements. */
+} upb_inttable;
+
+#define UPB_INTTABLE_INIT(count, mask, ctype, size_lg2, ent, a, asize, acount) \
+ {UPB_TABLE_INIT(count, mask, ctype, size_lg2, ent), a, asize, acount}
+
+#define UPB_EMPTY_INTTABLE_INIT(ctype) \
+ UPB_INTTABLE_INIT(0, 0, ctype, 0, NULL, NULL, 0, 0)
+
+#define UPB_ARRAY_EMPTYENT -1
+
+UPB_INLINE size_t upb_table_size(const upb_table *t) {
+ if (t->size_lg2 == 0)
+ return 0;
+ else
+ return 1 << t->size_lg2;
+}
+
+/* Internal-only functions, in .h file only out of necessity. */
+UPB_INLINE bool upb_tabent_isempty(const upb_tabent *e) {
+ return e->key == 0;
+}
+
+/* Used by some of the unit tests for generic hashing functionality. */
+uint32_t MurmurHash2(const void * key, size_t len, uint32_t seed);
+
+UPB_INLINE uintptr_t upb_intkey(uintptr_t key) {
+ return key;
+}
+
+UPB_INLINE uint32_t upb_inthash(uintptr_t key) {
+ return (uint32_t)key;
+}
+
+static const upb_tabent *upb_getentry(const upb_table *t, uint32_t hash) {
+ return t->entries + (hash & t->mask);
+}
+
+UPB_INLINE bool upb_arrhas(upb_tabval key) {
+ return key.val != (uint64_t)-1;
+}
+
+/* Initialize and uninitialize a table, respectively. If memory allocation
+ * failed, false is returned that the table is uninitialized. */
+bool upb_inttable_init2(upb_inttable *table, upb_ctype_t ctype, upb_alloc *a);
+bool upb_strtable_init2(upb_strtable *table, upb_ctype_t ctype, upb_alloc *a);
+void upb_inttable_uninit2(upb_inttable *table, upb_alloc *a);
+void upb_strtable_uninit2(upb_strtable *table, upb_alloc *a);
+
+UPB_INLINE bool upb_inttable_init(upb_inttable *table, upb_ctype_t ctype) {
+ return upb_inttable_init2(table, ctype, &upb_alloc_global);
+}
+
+UPB_INLINE bool upb_strtable_init(upb_strtable *table, upb_ctype_t ctype) {
+ return upb_strtable_init2(table, ctype, &upb_alloc_global);
+}
+
+UPB_INLINE void upb_inttable_uninit(upb_inttable *table) {
+ upb_inttable_uninit2(table, &upb_alloc_global);
+}
+
+UPB_INLINE void upb_strtable_uninit(upb_strtable *table) {
+ upb_strtable_uninit2(table, &upb_alloc_global);
+}
+
+/* Returns the number of values in the table. */
+size_t upb_inttable_count(const upb_inttable *t);
+UPB_INLINE size_t upb_strtable_count(const upb_strtable *t) {
+ return t->t.count;
+}
+
+void upb_inttable_packedsize(const upb_inttable *t, size_t *size);
+void upb_strtable_packedsize(const upb_strtable *t, size_t *size);
+upb_inttable *upb_inttable_pack(const upb_inttable *t, void *p, size_t *ofs,
+ size_t size);
+upb_strtable *upb_strtable_pack(const upb_strtable *t, void *p, size_t *ofs,
+ size_t size);
+
+/* Inserts the given key into the hashtable with the given value. The key must
+ * not already exist in the hash table. For string tables, the key must be
+ * NULL-terminated, and the table will make an internal copy of the key.
+ * Inttables must not insert a value of UINTPTR_MAX.
+ *
+ * If a table resize was required but memory allocation failed, false is
+ * returned and the table is unchanged. */
+bool upb_inttable_insert2(upb_inttable *t, uintptr_t key, upb_value val,
+ upb_alloc *a);
+bool upb_strtable_insert3(upb_strtable *t, const char *key, size_t len,
+ upb_value val, upb_alloc *a);
+
+UPB_INLINE bool upb_inttable_insert(upb_inttable *t, uintptr_t key,
+ upb_value val) {
+ return upb_inttable_insert2(t, key, val, &upb_alloc_global);
+}
+
+UPB_INLINE bool upb_strtable_insert2(upb_strtable *t, const char *key,
+ size_t len, upb_value val) {
+ return upb_strtable_insert3(t, key, len, val, &upb_alloc_global);
+}
+
+/* For NULL-terminated strings. */
+UPB_INLINE bool upb_strtable_insert(upb_strtable *t, const char *key,
+ upb_value val) {
+ return upb_strtable_insert2(t, key, strlen(key), val);
+}
+
+/* Looks up key in this table, returning "true" if the key was found.
+ * If v is non-NULL, copies the value for this key into *v. */
+bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v);
+bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len,
+ upb_value *v);
+
+/* For NULL-terminated strings. */
+UPB_INLINE bool upb_strtable_lookup(const upb_strtable *t, const char *key,
+ upb_value *v) {
+ return upb_strtable_lookup2(t, key, strlen(key), v);
+}
+
+/* Removes an item from the table. Returns true if the remove was successful,
+ * and stores the removed item in *val if non-NULL. */
+bool upb_inttable_remove(upb_inttable *t, uintptr_t key, upb_value *val);
+bool upb_strtable_remove3(upb_strtable *t, const char *key, size_t len,
+ upb_value *val, upb_alloc *alloc);
+
+UPB_INLINE bool upb_strtable_remove2(upb_strtable *t, const char *key,
+ size_t len, upb_value *val) {
+ return upb_strtable_remove3(t, key, len, val, &upb_alloc_global);
+}
+
+/* For NULL-terminated strings. */
+UPB_INLINE bool upb_strtable_remove(upb_strtable *t, const char *key,
+ upb_value *v) {
+ return upb_strtable_remove2(t, key, strlen(key), v);
+}
+
+/* Updates an existing entry in an inttable. If the entry does not exist,
+ * returns false and does nothing. Unlike insert/remove, this does not
+ * invalidate iterators. */
+bool upb_inttable_replace(upb_inttable *t, uintptr_t key, upb_value val);
+
+/* Handy routines for treating an inttable like a stack. May not be mixed with
+ * other insert/remove calls. */
+bool upb_inttable_push2(upb_inttable *t, upb_value val, upb_alloc *a);
+upb_value upb_inttable_pop(upb_inttable *t);
+
+UPB_INLINE bool upb_inttable_push(upb_inttable *t, upb_value val) {
+ return upb_inttable_push2(t, val, &upb_alloc_global);
+}
+
+/* Convenience routines for inttables with pointer keys. */
+bool upb_inttable_insertptr2(upb_inttable *t, const void *key, upb_value val,
+ upb_alloc *a);
+bool upb_inttable_removeptr(upb_inttable *t, const void *key, upb_value *val);
+bool upb_inttable_lookupptr(
+ const upb_inttable *t, const void *key, upb_value *val);
+
+UPB_INLINE bool upb_inttable_insertptr(upb_inttable *t, const void *key,
+ upb_value val) {
+ return upb_inttable_insertptr2(t, key, val, &upb_alloc_global);
+}
+
+/* Optimizes the table for the current set of entries, for both memory use and
+ * lookup time. Client should call this after all entries have been inserted;
+ * inserting more entries is legal, but will likely require a table resize. */
+void upb_inttable_compact2(upb_inttable *t, upb_alloc *a);
+
+UPB_INLINE void upb_inttable_compact(upb_inttable *t) {
+ upb_inttable_compact2(t, &upb_alloc_global);
+}
+
+/* A special-case inlinable version of the lookup routine for 32-bit
+ * integers. */
+UPB_INLINE bool upb_inttable_lookup32(const upb_inttable *t, uint32_t key,
+ upb_value *v) {
+ *v = upb_value_int32(0); /* Silence compiler warnings. */
+ if (key < t->array_size) {
+ upb_tabval arrval = t->array[key];
+ if (upb_arrhas(arrval)) {
+ _upb_value_setval(v, arrval.val, t->t.ctype);
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ const upb_tabent *e;
+ if (t->t.entries == NULL) return false;
+ for (e = upb_getentry(&t->t, upb_inthash(key)); true; e = e->next) {
+ if ((uint32_t)e->key == key) {
+ _upb_value_setval(v, e->val.val, t->t.ctype);
+ return true;
+ }
+ if (e->next == NULL) return false;
+ }
+ }
+}
+
+/* Exposed for testing only. */
+bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_alloc *a);
+
+/* Iterators ******************************************************************/
+
+/* Iterators for int and string tables. We are subject to some kind of unusual
+ * design constraints:
+ *
+ * For high-level languages:
+ * - we must be able to guarantee that we don't crash or corrupt memory even if
+ * the program accesses an invalidated iterator.
+ *
+ * For C++11 range-based for:
+ * - iterators must be copyable
+ * - iterators must be comparable
+ * - it must be possible to construct an "end" value.
+ *
+ * Iteration order is undefined.
+ *
+ * Modifying the table invalidates iterators. upb_{str,int}table_done() is
+ * guaranteed to work even on an invalidated iterator, as long as the table it
+ * is iterating over has not been freed. Calling next() or accessing data from
+ * an invalidated iterator yields unspecified elements from the table, but it is
+ * guaranteed not to crash and to return real table elements (except when done()
+ * is true). */
+
+
+/* upb_strtable_iter **********************************************************/
+
+/* upb_strtable_iter i;
+ * upb_strtable_begin(&i, t);
+ * for(; !upb_strtable_done(&i); upb_strtable_next(&i)) {
+ * const char *key = upb_strtable_iter_key(&i);
+ * const upb_value val = upb_strtable_iter_value(&i);
+ * // ...
+ * }
+ */
+
+typedef struct {
+ const upb_strtable *t;
+ size_t index;
+} upb_strtable_iter;
+
+void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t);
+void upb_strtable_next(upb_strtable_iter *i);
+bool upb_strtable_done(const upb_strtable_iter *i);
+const char *upb_strtable_iter_key(const upb_strtable_iter *i);
+size_t upb_strtable_iter_keylength(const upb_strtable_iter *i);
+upb_value upb_strtable_iter_value(const upb_strtable_iter *i);
+void upb_strtable_iter_setdone(upb_strtable_iter *i);
+bool upb_strtable_iter_isequal(const upb_strtable_iter *i1,
+ const upb_strtable_iter *i2);
+
+
+/* upb_inttable_iter **********************************************************/
+
+/* upb_inttable_iter i;
+ * upb_inttable_begin(&i, t);
+ * for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ * uintptr_t key = upb_inttable_iter_key(&i);
+ * upb_value val = upb_inttable_iter_value(&i);
+ * // ...
+ * }
+ */
+
+typedef struct {
+ const upb_inttable *t;
+ size_t index;
+ bool array_part;
+} upb_inttable_iter;
+
+void upb_inttable_begin(upb_inttable_iter *i, const upb_inttable *t);
+void upb_inttable_next(upb_inttable_iter *i);
+bool upb_inttable_done(const upb_inttable_iter *i);
+uintptr_t upb_inttable_iter_key(const upb_inttable_iter *i);
+upb_value upb_inttable_iter_value(const upb_inttable_iter *i);
+void upb_inttable_iter_setdone(upb_inttable_iter *i);
+bool upb_inttable_iter_isequal(const upb_inttable_iter *i1,
+ const upb_inttable_iter *i2);
+
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* UPB_TABLE_H_ */
+
+/* Reference tracking will check ref()/unref() operations to make sure the
+ * ref ownership is correct. Where possible it will also make tools like
+ * Valgrind attribute ref leaks to the code that took the leaked ref, not
+ * the code that originally created the object.
+ *
+ * Enabling this requires the application to define upb_lock()/upb_unlock()
+ * functions that acquire/release a global mutex (or #define UPB_THREAD_UNSAFE).
+ * For this reason we don't enable it by default, even in debug builds.
+ */
+
+/* #define UPB_DEBUG_REFS */
+
+#ifdef __cplusplus
+namespace upb {
+class RefCounted;
+template <class T> class reffed_ptr;
+}
+#endif
+
+UPB_DECLARE_TYPE(upb::RefCounted, upb_refcounted)
+
+struct upb_refcounted_vtbl;
+
+#ifdef __cplusplus
+
+class upb::RefCounted {
+ public:
+ /* Returns true if the given object is frozen. */
+ bool IsFrozen() const;
+
+ /* Increases the ref count, the new ref is owned by "owner" which must not
+ * already own a ref (and should not itself be a refcounted object if the ref
+ * could possibly be circular; see below).
+ * Thread-safe iff "this" is frozen. */
+ void Ref(const void *owner) const;
+
+ /* Release a ref that was acquired from upb_refcounted_ref() and collects any
+ * objects it can. */
+ void Unref(const void *owner) const;
+
+ /* Moves an existing ref from "from" to "to", without changing the overall
+ * ref count. DonateRef(foo, NULL, owner) is the same as Ref(foo, owner),
+ * but "to" may not be NULL. */
+ void DonateRef(const void *from, const void *to) const;
+
+ /* Verifies that a ref to the given object is currently held by the given
+ * owner. Only effective in UPB_DEBUG_REFS builds. */
+ void CheckRef(const void *owner) const;
+
+ private:
+ UPB_DISALLOW_POD_OPS(RefCounted, upb::RefCounted)
+#else
+struct upb_refcounted {
+#endif
+ /* TODO(haberman): move the actual structure definition to structdefs.int.h.
+ * The only reason they are here is because inline functions need to see the
+ * definition of upb_handlers, which needs to see this definition. But we
+ * can change the upb_handlers inline functions to deal in raw offsets
+ * instead.
+ */
+
+ /* A single reference count shared by all objects in the group. */
+ uint32_t *group;
+
+ /* A singly-linked list of all objects in the group. */
+ upb_refcounted *next;
+
+ /* Table of function pointers for this type. */
+ const struct upb_refcounted_vtbl *vtbl;
+
+ /* Maintained only when mutable, this tracks the number of refs (but not
+ * ref2's) to this object. *group should be the sum of all individual_count
+ * in the group. */
+ uint32_t individual_count;
+
+ bool is_frozen;
+
+#ifdef UPB_DEBUG_REFS
+ upb_inttable *refs; /* Maps owner -> trackedref for incoming refs. */
+ upb_inttable *ref2s; /* Set of targets for outgoing ref2s. */
+#endif
+};
+
+#ifdef UPB_DEBUG_REFS
+extern upb_alloc upb_alloc_debugrefs;
+#define UPB_REFCOUNT_INIT(vtbl, refs, ref2s) \
+ {&static_refcount, NULL, vtbl, 0, true, refs, ref2s}
+#else
+#define UPB_REFCOUNT_INIT(vtbl, refs, ref2s) \
+ {&static_refcount, NULL, vtbl, 0, true}
+#endif
+
+UPB_BEGIN_EXTERN_C
+
+/* It is better to use tracked refs when possible, for the extra debugging
+ * capability. But if this is not possible (because you don't have easy access
+ * to a stable pointer value that is associated with the ref), you can pass
+ * UPB_UNTRACKED_REF instead. */
+extern const void *UPB_UNTRACKED_REF;
+
+/* Native C API. */
+bool upb_refcounted_isfrozen(const upb_refcounted *r);
+void upb_refcounted_ref(const upb_refcounted *r, const void *owner);
+void upb_refcounted_unref(const upb_refcounted *r, const void *owner);
+void upb_refcounted_donateref(
+ const upb_refcounted *r, const void *from, const void *to);
+void upb_refcounted_checkref(const upb_refcounted *r, const void *owner);
+
+#define UPB_REFCOUNTED_CMETHODS(type, upcastfunc) \
+ UPB_INLINE bool type ## _isfrozen(const type *v) { \
+ return upb_refcounted_isfrozen(upcastfunc(v)); \
+ } \
+ UPB_INLINE void type ## _ref(const type *v, const void *owner) { \
+ upb_refcounted_ref(upcastfunc(v), owner); \
+ } \
+ UPB_INLINE void type ## _unref(const type *v, const void *owner) { \
+ upb_refcounted_unref(upcastfunc(v), owner); \
+ } \
+ UPB_INLINE void type ## _donateref(const type *v, const void *from, const void *to) { \
+ upb_refcounted_donateref(upcastfunc(v), from, to); \
+ } \
+ UPB_INLINE void type ## _checkref(const type *v, const void *owner) { \
+ upb_refcounted_checkref(upcastfunc(v), owner); \
+ }
+
+#define UPB_REFCOUNTED_CPPMETHODS \
+ bool IsFrozen() const { \
+ return upb::upcast_to<const upb::RefCounted>(this)->IsFrozen(); \
+ } \
+ void Ref(const void *owner) const { \
+ return upb::upcast_to<const upb::RefCounted>(this)->Ref(owner); \
+ } \
+ void Unref(const void *owner) const { \
+ return upb::upcast_to<const upb::RefCounted>(this)->Unref(owner); \
+ } \
+ void DonateRef(const void *from, const void *to) const { \
+ return upb::upcast_to<const upb::RefCounted>(this)->DonateRef(from, to); \
+ } \
+ void CheckRef(const void *owner) const { \
+ return upb::upcast_to<const upb::RefCounted>(this)->CheckRef(owner); \
+ }
+
+/* Internal-to-upb Interface **************************************************/
+
+typedef void upb_refcounted_visit(const upb_refcounted *r,
+ const upb_refcounted *subobj,
+ void *closure);
+
+struct upb_refcounted_vtbl {
+ /* Must visit all subobjects that are currently ref'd via upb_refcounted_ref2.
+ * Must be longjmp()-safe. */
+ void (*visit)(const upb_refcounted *r, upb_refcounted_visit *visit, void *c);
+
+ /* Must free the object and release all references to other objects. */
+ void (*free)(upb_refcounted *r);
+};
+
+/* Initializes the refcounted with a single ref for the given owner. Returns
+ * false if memory could not be allocated. */
+bool upb_refcounted_init(upb_refcounted *r,
+ const struct upb_refcounted_vtbl *vtbl,
+ const void *owner);
+
+/* Adds a ref from one refcounted object to another ("from" must not already
+ * own a ref). These refs may be circular; cycles will be collected correctly
+ * (if conservatively). These refs do not need to be freed in from's free()
+ * function. */
+void upb_refcounted_ref2(const upb_refcounted *r, upb_refcounted *from);
+
+/* Removes a ref that was acquired from upb_refcounted_ref2(), and collects any
+ * object it can. This is only necessary when "from" no longer points to "r",
+ * and not from from's "free" function. */
+void upb_refcounted_unref2(const upb_refcounted *r, upb_refcounted *from);
+
+#define upb_ref2(r, from) \
+ upb_refcounted_ref2((const upb_refcounted*)r, (upb_refcounted*)from)
+#define upb_unref2(r, from) \
+ upb_refcounted_unref2((const upb_refcounted*)r, (upb_refcounted*)from)
+
+/* Freezes all mutable object reachable by ref2() refs from the given roots.
+ * This will split refcounting groups into precise SCC groups, so that
+ * refcounting of frozen objects can be more aggressive. If memory allocation
+ * fails, or if more than 2**31 mutable objects are reachable from "roots", or
+ * if the maximum depth of the graph exceeds "maxdepth", false is returned and
+ * the objects are unchanged.
+ *
+ * After this operation succeeds, the objects are frozen/const, and may not be
+ * used through non-const pointers. In particular, they may not be passed as
+ * the second parameter of upb_refcounted_{ref,unref}2(). On the upside, all
+ * operations on frozen refcounteds are threadsafe, and objects will be freed
+ * at the precise moment that they become unreachable.
+ *
+ * Caller must own refs on each object in the "roots" list. */
+bool upb_refcounted_freeze(upb_refcounted *const*roots, int n, upb_status *s,
+ int maxdepth);
+
+/* Shared by all compiled-in refcounted objects. */
+extern uint32_t static_refcount;
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+/* C++ Wrappers. */
+namespace upb {
+inline bool RefCounted::IsFrozen() const {
+ return upb_refcounted_isfrozen(this);
+}
+inline void RefCounted::Ref(const void *owner) const {
+ upb_refcounted_ref(this, owner);
+}
+inline void RefCounted::Unref(const void *owner) const {
+ upb_refcounted_unref(this, owner);
+}
+inline void RefCounted::DonateRef(const void *from, const void *to) const {
+ upb_refcounted_donateref(this, from, to);
+}
+inline void RefCounted::CheckRef(const void *owner) const {
+ upb_refcounted_checkref(this, owner);
+}
+} /* namespace upb */
+#endif
+
+
+/* upb::reffed_ptr ************************************************************/
+
+#ifdef __cplusplus
+
+#include <algorithm> /* For std::swap(). */
+
+/* Provides RAII semantics for upb refcounted objects. Each reffed_ptr owns a
+ * ref on whatever object it points to (if any). */
+template <class T> class upb::reffed_ptr {
+ public:
+ reffed_ptr() : ptr_(NULL) {}
+
+ /* If ref_donor is NULL, takes a new ref, otherwise adopts from ref_donor. */
+ template <class U>
+ reffed_ptr(U* val, const void* ref_donor = NULL)
+ : ptr_(upb::upcast(val)) {
+ if (ref_donor) {
+ UPB_ASSERT(ptr_);
+ ptr_->DonateRef(ref_donor, this);
+ } else if (ptr_) {
+ ptr_->Ref(this);
+ }
+ }
+
+ template <class U>
+ reffed_ptr(const reffed_ptr<U>& other)
+ : ptr_(upb::upcast(other.get())) {
+ if (ptr_) ptr_->Ref(this);
+ }
+
+ reffed_ptr(const reffed_ptr& other)
+ : ptr_(upb::upcast(other.get())) {
+ if (ptr_) ptr_->Ref(this);
+ }
+
+ ~reffed_ptr() { if (ptr_) ptr_->Unref(this); }
+
+ template <class U>
+ reffed_ptr& operator=(const reffed_ptr<U>& other) {
+ reset(other.get());
+ return *this;
+ }
+
+ reffed_ptr& operator=(const reffed_ptr& other) {
+ reset(other.get());
+ return *this;
+ }
+
+ /* TODO(haberman): add C++11 move construction/assignment for greater
+ * efficiency. */
+
+ void swap(reffed_ptr& other) {
+ if (ptr_ == other.ptr_) {
+ return;
+ }
+
+ if (ptr_) ptr_->DonateRef(this, &other);
+ if (other.ptr_) other.ptr_->DonateRef(&other, this);
+ std::swap(ptr_, other.ptr_);
+ }
+
+ T& operator*() const {
+ UPB_ASSERT(ptr_);
+ return *ptr_;
+ }
+
+ T* operator->() const {
+ UPB_ASSERT(ptr_);
+ return ptr_;
+ }
+
+ T* get() const { return ptr_; }
+
+ /* If ref_donor is NULL, takes a new ref, otherwise adopts from ref_donor. */
+ template <class U>
+ void reset(U* ptr = NULL, const void* ref_donor = NULL) {
+ reffed_ptr(ptr, ref_donor).swap(*this);
+ }
+
+ template <class U>
+ reffed_ptr<U> down_cast() {
+ return reffed_ptr<U>(upb::down_cast<U*>(get()));
+ }
+
+ template <class U>
+ reffed_ptr<U> dyn_cast() {
+ return reffed_ptr<U>(upb::dyn_cast<U*>(get()));
+ }
+
+ /* Plain release() is unsafe; if we were the only owner, it would leak the
+ * object. Instead we provide this: */
+ T* ReleaseTo(const void* new_owner) {
+ T* ret = NULL;
+ ptr_->DonateRef(this, new_owner);
+ std::swap(ret, ptr_);
+ return ret;
+ }
+
+ private:
+ T* ptr_;
+};
+
+#endif /* __cplusplus */
+
+#endif /* UPB_REFCOUNT_H_ */
+
+#ifdef __cplusplus
+#include <cstring>
+#include <string>
+#include <vector>
+
+namespace upb {
+class Def;
+class EnumDef;
+class FieldDef;
+class FileDef;
+class MessageDef;
+class OneofDef;
+class SymbolTable;
+}
+#endif
+
+UPB_DECLARE_DERIVED_TYPE(upb::Def, upb::RefCounted, upb_def, upb_refcounted)
+UPB_DECLARE_DERIVED_TYPE(upb::OneofDef, upb::RefCounted, upb_oneofdef,
+ upb_refcounted)
+UPB_DECLARE_DERIVED_TYPE(upb::FileDef, upb::RefCounted, upb_filedef,
+ upb_refcounted)
+UPB_DECLARE_TYPE(upb::SymbolTable, upb_symtab)
+
+
+/* The maximum message depth that the type graph can have. This is a resource
+ * limit for the C stack since we sometimes need to recursively traverse the
+ * graph. Cycles are ok; the traversal will stop when it detects a cycle, but
+ * we must hit the cycle before the maximum depth is reached.
+ *
+ * If having a single static limit is too inflexible, we can add another variant
+ * of Def::Freeze that allows specifying this as a parameter. */
+#define UPB_MAX_MESSAGE_DEPTH 64
+
+
+/* upb::Def: base class for top-level defs ***********************************/
+
+/* All the different kind of defs that can be defined at the top-level and put
+ * in a SymbolTable or appear in a FileDef::defs() list. This excludes some
+ * defs (like oneofs and files). It only includes fields because they can be
+ * defined as extensions. */
+typedef enum {
+ UPB_DEF_MSG,
+ UPB_DEF_FIELD,
+ UPB_DEF_ENUM,
+ UPB_DEF_SERVICE, /* Not yet implemented. */
+ UPB_DEF_ANY = -1 /* Wildcard for upb_symtab_get*() */
+} upb_deftype_t;
+
+#ifdef __cplusplus
+
+/* The base class of all defs. Its base is upb::RefCounted (use upb::upcast()
+ * to convert). */
+class upb::Def {
+ public:
+ typedef upb_deftype_t Type;
+
+ /* upb::RefCounted methods like Ref()/Unref(). */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ Type def_type() const;
+
+ /* "fullname" is the def's fully-qualified name (eg. foo.bar.Message). */
+ const char *full_name() const;
+
+ /* The final part of a def's name (eg. Message). */
+ const char *name() const;
+
+ /* The def must be mutable. Caller retains ownership of fullname. Defs are
+ * not required to have a name; if a def has no name when it is frozen, it
+ * will remain an anonymous def. On failure, returns false and details in "s"
+ * if non-NULL. */
+ bool set_full_name(const char* fullname, upb::Status* s);
+ bool set_full_name(const std::string &fullname, upb::Status* s);
+
+ /* The file in which this def appears. It is not necessary to add a def to a
+ * file (and consequently the accessor may return NULL). Set this by calling
+ * file->Add(def). */
+ FileDef* file() const;
+
+ /* Freezes the given defs; this validates all constraints and marks the defs
+ * as frozen (read-only). "defs" may not contain any fielddefs, but fields
+ * of any msgdefs will be frozen.
+ *
+ * Symbolic references to sub-types and enum defaults must have already been
+ * resolved. Any mutable defs reachable from any of "defs" must also be in
+ * the list; more formally, "defs" must be a transitive closure of mutable
+ * defs.
+ *
+ * After this operation succeeds, the finalized defs must only be accessed
+ * through a const pointer! */
+ static bool Freeze(Def* const* defs, size_t n, Status* status);
+ static bool Freeze(const std::vector<Def*>& defs, Status* status);
+
+ private:
+ UPB_DISALLOW_POD_OPS(Def, upb::Def)
+};
+
+#endif /* __cplusplus */
+
+UPB_BEGIN_EXTERN_C
+
+/* Include upb_refcounted methods like upb_def_ref()/upb_def_unref(). */
+UPB_REFCOUNTED_CMETHODS(upb_def, upb_def_upcast)
+
+upb_deftype_t upb_def_type(const upb_def *d);
+const char *upb_def_fullname(const upb_def *d);
+const char *upb_def_name(const upb_def *d);
+const upb_filedef *upb_def_file(const upb_def *d);
+bool upb_def_setfullname(upb_def *def, const char *fullname, upb_status *s);
+bool upb_def_freeze(upb_def *const *defs, size_t n, upb_status *s);
+
+/* Temporary API: for internal use only. */
+bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s);
+
+UPB_END_EXTERN_C
+
+
+/* upb::Def casts *************************************************************/
+
+#ifdef __cplusplus
+#define UPB_CPP_CASTS(cname, cpptype) \
+ namespace upb { \
+ template <> \
+ inline cpptype *down_cast<cpptype *, Def>(Def * def) { \
+ return upb_downcast_##cname##_mutable(def); \
+ } \
+ template <> \
+ inline cpptype *dyn_cast<cpptype *, Def>(Def * def) { \
+ return upb_dyncast_##cname##_mutable(def); \
+ } \
+ template <> \
+ inline const cpptype *down_cast<const cpptype *, const Def>( \
+ const Def *def) { \
+ return upb_downcast_##cname(def); \
+ } \
+ template <> \
+ inline const cpptype *dyn_cast<const cpptype *, const Def>(const Def *def) { \
+ return upb_dyncast_##cname(def); \
+ } \
+ template <> \
+ inline const cpptype *down_cast<const cpptype *, Def>(Def * def) { \
+ return upb_downcast_##cname(def); \
+ } \
+ template <> \
+ inline const cpptype *dyn_cast<const cpptype *, Def>(Def * def) { \
+ return upb_dyncast_##cname(def); \
+ } \
+ } /* namespace upb */
+#else
+#define UPB_CPP_CASTS(cname, cpptype)
+#endif /* __cplusplus */
+
+/* Dynamic casts, for determining if a def is of a particular type at runtime.
+ * Downcasts, for when some wants to assert that a def is of a particular type.
+ * These are only checked if we are building debug. */
+#define UPB_DEF_CASTS(lower, upper, cpptype) \
+ UPB_INLINE const upb_##lower *upb_dyncast_##lower(const upb_def *def) { \
+ if (upb_def_type(def) != UPB_DEF_##upper) return NULL; \
+ return (upb_##lower *)def; \
+ } \
+ UPB_INLINE const upb_##lower *upb_downcast_##lower(const upb_def *def) { \
+ UPB_ASSERT(upb_def_type(def) == UPB_DEF_##upper); \
+ return (const upb_##lower *)def; \
+ } \
+ UPB_INLINE upb_##lower *upb_dyncast_##lower##_mutable(upb_def *def) { \
+ return (upb_##lower *)upb_dyncast_##lower(def); \
+ } \
+ UPB_INLINE upb_##lower *upb_downcast_##lower##_mutable(upb_def *def) { \
+ return (upb_##lower *)upb_downcast_##lower(def); \
+ } \
+ UPB_CPP_CASTS(lower, cpptype)
+
+#define UPB_DEFINE_DEF(cppname, lower, upper, cppmethods, members) \
+ UPB_DEFINE_CLASS2(cppname, upb::Def, upb::RefCounted, cppmethods, \
+ members) \
+ UPB_DEF_CASTS(lower, upper, cppname)
+
+#define UPB_DECLARE_DEF_TYPE(cppname, lower, upper) \
+ UPB_DECLARE_DERIVED_TYPE2(cppname, upb::Def, upb::RefCounted, \
+ upb_ ## lower, upb_def, upb_refcounted) \
+ UPB_DEF_CASTS(lower, upper, cppname)
+
+UPB_DECLARE_DEF_TYPE(upb::FieldDef, fielddef, FIELD)
+UPB_DECLARE_DEF_TYPE(upb::MessageDef, msgdef, MSG)
+UPB_DECLARE_DEF_TYPE(upb::EnumDef, enumdef, ENUM)
+
+#undef UPB_DECLARE_DEF_TYPE
+#undef UPB_DEF_CASTS
+#undef UPB_CPP_CASTS
+
+
+/* upb::FieldDef **************************************************************/
+
+/* The types a field can have. Note that this list is not identical to the
+ * types defined in descriptor.proto, which gives INT32 and SINT32 separate
+ * types (we distinguish the two with the "integer encoding" enum below). */
+typedef enum {
+ /* Types stored in 1 byte. */
+ UPB_TYPE_BOOL = 1,
+ /* Types stored in 4 bytes. */
+ UPB_TYPE_FLOAT = 2,
+ UPB_TYPE_INT32 = 3,
+ UPB_TYPE_UINT32 = 4,
+ UPB_TYPE_ENUM = 5, /* Enum values are int32. */
+ /* Types stored as pointers (probably 4 or 8 bytes). */
+ UPB_TYPE_STRING = 6,
+ UPB_TYPE_BYTES = 7,
+ UPB_TYPE_MESSAGE = 8,
+ /* Types stored as 8 bytes. */
+ UPB_TYPE_DOUBLE = 9,
+ UPB_TYPE_INT64 = 10,
+ UPB_TYPE_UINT64 = 11
+} upb_fieldtype_t;
+
+/* The repeated-ness of each field; this matches descriptor.proto. */
+typedef enum {
+ UPB_LABEL_OPTIONAL = 1,
+ UPB_LABEL_REQUIRED = 2,
+ UPB_LABEL_REPEATED = 3
+} upb_label_t;
+
+/* How integers should be encoded in serializations that offer multiple
+ * integer encoding methods. */
+typedef enum {
+ UPB_INTFMT_VARIABLE = 1,
+ UPB_INTFMT_FIXED = 2,
+ UPB_INTFMT_ZIGZAG = 3 /* Only for signed types (INT32/INT64). */
+} upb_intfmt_t;
+
+/* Descriptor types, as defined in descriptor.proto. */
+typedef enum {
+ UPB_DESCRIPTOR_TYPE_DOUBLE = 1,
+ UPB_DESCRIPTOR_TYPE_FLOAT = 2,
+ UPB_DESCRIPTOR_TYPE_INT64 = 3,
+ UPB_DESCRIPTOR_TYPE_UINT64 = 4,
+ UPB_DESCRIPTOR_TYPE_INT32 = 5,
+ UPB_DESCRIPTOR_TYPE_FIXED64 = 6,
+ UPB_DESCRIPTOR_TYPE_FIXED32 = 7,
+ UPB_DESCRIPTOR_TYPE_BOOL = 8,
+ UPB_DESCRIPTOR_TYPE_STRING = 9,
+ UPB_DESCRIPTOR_TYPE_GROUP = 10,
+ UPB_DESCRIPTOR_TYPE_MESSAGE = 11,
+ UPB_DESCRIPTOR_TYPE_BYTES = 12,
+ UPB_DESCRIPTOR_TYPE_UINT32 = 13,
+ UPB_DESCRIPTOR_TYPE_ENUM = 14,
+ UPB_DESCRIPTOR_TYPE_SFIXED32 = 15,
+ UPB_DESCRIPTOR_TYPE_SFIXED64 = 16,
+ UPB_DESCRIPTOR_TYPE_SINT32 = 17,
+ UPB_DESCRIPTOR_TYPE_SINT64 = 18
+} upb_descriptortype_t;
+
+typedef enum {
+ UPB_SYNTAX_PROTO2 = 2,
+ UPB_SYNTAX_PROTO3 = 3
+} upb_syntax_t;
+
+/* Maximum field number allowed for FieldDefs. This is an inherent limit of the
+ * protobuf wire format. */
+#define UPB_MAX_FIELDNUMBER ((1 << 29) - 1)
+
+#ifdef __cplusplus
+
+/* A upb_fielddef describes a single field in a message. It is most often
+ * found as a part of a upb_msgdef, but can also stand alone to represent
+ * an extension.
+ *
+ * Its base class is upb::Def (use upb::upcast() to convert). */
+class upb::FieldDef {
+ public:
+ typedef upb_fieldtype_t Type;
+ typedef upb_label_t Label;
+ typedef upb_intfmt_t IntegerFormat;
+ typedef upb_descriptortype_t DescriptorType;
+
+ /* These return true if the given value is a valid member of the enumeration. */
+ static bool CheckType(int32_t val);
+ static bool CheckLabel(int32_t val);
+ static bool CheckDescriptorType(int32_t val);
+ static bool CheckIntegerFormat(int32_t val);
+
+ /* These convert to the given enumeration; they require that the value is
+ * valid. */
+ static Type ConvertType(int32_t val);
+ static Label ConvertLabel(int32_t val);
+ static DescriptorType ConvertDescriptorType(int32_t val);
+ static IntegerFormat ConvertIntegerFormat(int32_t val);
+
+ /* Returns NULL if memory allocation failed. */
+ static reffed_ptr<FieldDef> New();
+
+ /* upb::RefCounted methods like Ref()/Unref(). */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ /* Functionality from upb::Def. */
+ const char* full_name() const;
+
+ bool type_is_set() const; /* set_[descriptor_]type() has been called? */
+ Type type() const; /* Requires that type_is_set() == true. */
+ Label label() const; /* Defaults to UPB_LABEL_OPTIONAL. */
+ const char* name() const; /* NULL if uninitialized. */
+ uint32_t number() const; /* Returns 0 if uninitialized. */
+ bool is_extension() const;
+
+ /* Copies the JSON name for this field into the given buffer. Returns the
+ * actual size of the JSON name, including the NULL terminator. If the
+ * return value is 0, the JSON name is unset. If the return value is
+ * greater than len, the JSON name was truncated. The buffer is always
+ * NULL-terminated if len > 0.
+ *
+ * The JSON name always defaults to a camelCased version of the regular
+ * name. However if the regular name is unset, the JSON name will be unset
+ * also.
+ */
+ size_t GetJsonName(char* buf, size_t len) const;
+
+ /* Convenience version of the above function which copies the JSON name
+ * into the given string, returning false if the name is not set. */
+ template <class T>
+ bool GetJsonName(T* str) {
+ str->resize(GetJsonName(NULL, 0));
+ GetJsonName(&(*str)[0], str->size());
+ return str->size() > 0;
+ }
+
+ /* For UPB_TYPE_MESSAGE fields only where is_tag_delimited() == false,
+ * indicates whether this field should have lazy parsing handlers that yield
+ * the unparsed string for the submessage.
+ *
+ * TODO(haberman): I think we want to move this into a FieldOptions container
+ * when we add support for custom options (the FieldOptions struct will
+ * contain both regular FieldOptions like "lazy" *and* custom options). */
+ bool lazy() const;
+
+ /* For non-string, non-submessage fields, this indicates whether binary
+ * protobufs are encoded in packed or non-packed format.
+ *
+ * TODO(haberman): see note above about putting options like this into a
+ * FieldOptions container. */
+ bool packed() const;
+
+ /* An integer that can be used as an index into an array of fields for
+ * whatever message this field belongs to. Guaranteed to be less than
+ * f->containing_type()->field_count(). May only be accessed once the def has
+ * been finalized. */
+ uint32_t index() const;
+
+ /* The MessageDef to which this field belongs.
+ *
+ * If this field has been added to a MessageDef, that message can be retrieved
+ * directly (this is always the case for frozen FieldDefs).
+ *
+ * If the field has not yet been added to a MessageDef, you can set the name
+ * of the containing type symbolically instead. This is mostly useful for
+ * extensions, where the extension is declared separately from the message. */
+ const MessageDef* containing_type() const;
+ const char* containing_type_name();
+
+ /* The OneofDef to which this field belongs, or NULL if this field is not part
+ * of a oneof. */
+ const OneofDef* containing_oneof() const;
+
+ /* The field's type according to the enum in descriptor.proto. This is not
+ * the same as UPB_TYPE_*, because it distinguishes between (for example)
+ * INT32 and SINT32, whereas our "type" enum does not. This return of
+ * descriptor_type() is a function of type(), integer_format(), and
+ * is_tag_delimited(). Likewise set_descriptor_type() sets all three
+ * appropriately. */
+ DescriptorType descriptor_type() const;
+
+ /* Convenient field type tests. */
+ bool IsSubMessage() const;
+ bool IsString() const;
+ bool IsSequence() const;
+ bool IsPrimitive() const;
+ bool IsMap() const;
+
+ /* Returns whether this field explicitly represents presence.
+ *
+ * For proto2 messages: Returns true for any scalar (non-repeated) field.
+ * For proto3 messages: Returns true for scalar submessage or oneof fields. */
+ bool HasPresence() const;
+
+ /* How integers are encoded. Only meaningful for integer types.
+ * Defaults to UPB_INTFMT_VARIABLE, and is reset when "type" changes. */
+ IntegerFormat integer_format() const;
+
+ /* Whether a submessage field is tag-delimited or not (if false, then
+ * length-delimited). May only be set when type() == UPB_TYPE_MESSAGE. */
+ bool is_tag_delimited() const;
+
+ /* Returns the non-string default value for this fielddef, which may either
+ * be something the client set explicitly or the "default default" (0 for
+ * numbers, empty for strings). The field's type indicates the type of the
+ * returned value, except for enum fields that are still mutable.
+ *
+ * Requires that the given function matches the field's current type. */
+ int64_t default_int64() const;
+ int32_t default_int32() const;
+ uint64_t default_uint64() const;
+ uint32_t default_uint32() const;
+ bool default_bool() const;
+ float default_float() const;
+ double default_double() const;
+
+ /* The resulting string is always NULL-terminated. If non-NULL, the length
+ * will be stored in *len. */
+ const char *default_string(size_t* len) const;
+
+ /* For frozen UPB_TYPE_ENUM fields, enum defaults can always be read as either
+ * string or int32, and both of these methods will always return true.
+ *
+ * For mutable UPB_TYPE_ENUM fields, the story is a bit more complicated.
+ * Enum defaults are unusual. They can be specified either as string or int32,
+ * but to be valid the enum must have that value as a member. And if no
+ * default is specified, the "default default" comes from the EnumDef.
+ *
+ * We allow reading the default as either an int32 or a string, but only if
+ * we have a meaningful value to report. We have a meaningful value if it was
+ * set explicitly, or if we could get the "default default" from the EnumDef.
+ * Also if you explicitly set the name and we find the number in the EnumDef */
+ bool EnumHasStringDefault() const;
+ bool EnumHasInt32Default() const;
+
+ /* Submessage and enum fields must reference a "subdef", which is the
+ * upb::MessageDef or upb::EnumDef that defines their type. Note that when
+ * the FieldDef is mutable it may not have a subdef *yet*, but this function
+ * still returns true to indicate that the field's type requires a subdef. */
+ bool HasSubDef() const;
+
+ /* Returns the enum or submessage def for this field, if any. The field's
+ * type must match (ie. you may only call enum_subdef() for fields where
+ * type() == UPB_TYPE_ENUM). Returns NULL if the subdef has not been set or
+ * is currently set symbolically. */
+ const EnumDef* enum_subdef() const;
+ const MessageDef* message_subdef() const;
+
+ /* Returns the generic subdef for this field. Requires that HasSubDef() (ie.
+ * only works for UPB_TYPE_ENUM and UPB_TYPE_MESSAGE fields). */
+ const Def* subdef() const;
+
+ /* Returns the symbolic name of the subdef. If the subdef is currently set
+ * unresolved (ie. set symbolically) returns the symbolic name. If it has
+ * been resolved to a specific subdef, returns the name from that subdef. */
+ const char* subdef_name() const;
+
+ /* Setters (non-const methods), only valid for mutable FieldDefs! ***********/
+
+ bool set_full_name(const char* fullname, upb::Status* s);
+ bool set_full_name(const std::string& fullname, upb::Status* s);
+
+ /* This may only be called if containing_type() == NULL (ie. the field has not
+ * been added to a message yet). */
+ bool set_containing_type_name(const char *name, Status* status);
+ bool set_containing_type_name(const std::string& name, Status* status);
+
+ /* Defaults to false. When we freeze, we ensure that this can only be true
+ * for length-delimited message fields. Prior to freezing this can be true or
+ * false with no restrictions. */
+ void set_lazy(bool lazy);
+
+ /* Defaults to true. Sets whether this field is encoded in packed format. */
+ void set_packed(bool packed);
+
+ /* "type" or "descriptor_type" MUST be set explicitly before the fielddef is
+ * finalized. These setters require that the enum value is valid; if the
+ * value did not come directly from an enum constant, the caller should
+ * validate it first with the functions above (CheckFieldType(), etc). */
+ void set_type(Type type);
+ void set_label(Label label);
+ void set_descriptor_type(DescriptorType type);
+ void set_is_extension(bool is_extension);
+
+ /* "number" and "name" must be set before the FieldDef is added to a
+ * MessageDef, and may not be set after that.
+ *
+ * "name" is the same as full_name()/set_full_name(), but since fielddefs
+ * most often use simple, non-qualified names, we provide this accessor
+ * also. Generally only extensions will want to think of this name as
+ * fully-qualified. */
+ bool set_number(uint32_t number, upb::Status* s);
+ bool set_name(const char* name, upb::Status* s);
+ bool set_name(const std::string& name, upb::Status* s);
+
+ /* Sets the JSON name to the given string. */
+ /* TODO(haberman): implement. Right now only default json_name (camelCase)
+ * is supported. */
+ bool set_json_name(const char* json_name, upb::Status* s);
+ bool set_json_name(const std::string& name, upb::Status* s);
+
+ /* Clears the JSON name. This will make it revert to its default, which is
+ * a camelCased version of the regular field name. */
+ void clear_json_name();
+
+ void set_integer_format(IntegerFormat format);
+ bool set_tag_delimited(bool tag_delimited, upb::Status* s);
+
+ /* Sets default value for the field. The call must exactly match the type
+ * of the field. Enum fields may use either setint32 or setstring to set
+ * the default numerically or symbolically, respectively, but symbolic
+ * defaults must be resolved before finalizing (see ResolveEnumDefault()).
+ *
+ * Changing the type of a field will reset its default. */
+ void set_default_int64(int64_t val);
+ void set_default_int32(int32_t val);
+ void set_default_uint64(uint64_t val);
+ void set_default_uint32(uint32_t val);
+ void set_default_bool(bool val);
+ void set_default_float(float val);
+ void set_default_double(double val);
+ bool set_default_string(const void *str, size_t len, Status *s);
+ bool set_default_string(const std::string &str, Status *s);
+ void set_default_cstr(const char *str, Status *s);
+
+ /* Before a fielddef is frozen, its subdef may be set either directly (with a
+ * upb::Def*) or symbolically. Symbolic refs must be resolved before the
+ * containing msgdef can be frozen (see upb_resolve() above). upb always
+ * guarantees that any def reachable from a live def will also be kept alive.
+ *
+ * Both methods require that upb_hassubdef(f) (so the type must be set prior
+ * to calling these methods). Returns false if this is not the case, or if
+ * the given subdef is not of the correct type. The subdef is reset if the
+ * field's type is changed. The subdef can be set to NULL to clear it. */
+ bool set_subdef(const Def* subdef, Status* s);
+ bool set_enum_subdef(const EnumDef* subdef, Status* s);
+ bool set_message_subdef(const MessageDef* subdef, Status* s);
+ bool set_subdef_name(const char* name, Status* s);
+ bool set_subdef_name(const std::string &name, Status* s);
+
+ private:
+ UPB_DISALLOW_POD_OPS(FieldDef, upb::FieldDef)
+};
+
+# endif /* defined(__cplusplus) */
+
+UPB_BEGIN_EXTERN_C
+
+/* Native C API. */
+upb_fielddef *upb_fielddef_new(const void *owner);
+
+/* Include upb_refcounted methods like upb_fielddef_ref(). */
+UPB_REFCOUNTED_CMETHODS(upb_fielddef, upb_fielddef_upcast2)
+
+/* Methods from upb_def. */
+const char *upb_fielddef_fullname(const upb_fielddef *f);
+bool upb_fielddef_setfullname(upb_fielddef *f, const char *fullname,
+ upb_status *s);
+
+bool upb_fielddef_typeisset(const upb_fielddef *f);
+upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f);
+upb_descriptortype_t upb_fielddef_descriptortype(const upb_fielddef *f);
+upb_label_t upb_fielddef_label(const upb_fielddef *f);
+uint32_t upb_fielddef_number(const upb_fielddef *f);
+const char *upb_fielddef_name(const upb_fielddef *f);
+bool upb_fielddef_isextension(const upb_fielddef *f);
+bool upb_fielddef_lazy(const upb_fielddef *f);
+bool upb_fielddef_packed(const upb_fielddef *f);
+size_t upb_fielddef_getjsonname(const upb_fielddef *f, char *buf, size_t len);
+const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f);
+const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f);
+upb_msgdef *upb_fielddef_containingtype_mutable(upb_fielddef *f);
+const char *upb_fielddef_containingtypename(upb_fielddef *f);
+upb_intfmt_t upb_fielddef_intfmt(const upb_fielddef *f);
+uint32_t upb_fielddef_index(const upb_fielddef *f);
+bool upb_fielddef_istagdelim(const upb_fielddef *f);
+bool upb_fielddef_issubmsg(const upb_fielddef *f);
+bool upb_fielddef_isstring(const upb_fielddef *f);
+bool upb_fielddef_isseq(const upb_fielddef *f);
+bool upb_fielddef_isprimitive(const upb_fielddef *f);
+bool upb_fielddef_ismap(const upb_fielddef *f);
+bool upb_fielddef_haspresence(const upb_fielddef *f);
+int64_t upb_fielddef_defaultint64(const upb_fielddef *f);
+int32_t upb_fielddef_defaultint32(const upb_fielddef *f);
+uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f);
+uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f);
+bool upb_fielddef_defaultbool(const upb_fielddef *f);
+float upb_fielddef_defaultfloat(const upb_fielddef *f);
+double upb_fielddef_defaultdouble(const upb_fielddef *f);
+const char *upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len);
+bool upb_fielddef_enumhasdefaultint32(const upb_fielddef *f);
+bool upb_fielddef_enumhasdefaultstr(const upb_fielddef *f);
+bool upb_fielddef_hassubdef(const upb_fielddef *f);
+const upb_def *upb_fielddef_subdef(const upb_fielddef *f);
+const upb_msgdef *upb_fielddef_msgsubdef(const upb_fielddef *f);
+const upb_enumdef *upb_fielddef_enumsubdef(const upb_fielddef *f);
+const char *upb_fielddef_subdefname(const upb_fielddef *f);
+
+void upb_fielddef_settype(upb_fielddef *f, upb_fieldtype_t type);
+void upb_fielddef_setdescriptortype(upb_fielddef *f, int type);
+void upb_fielddef_setlabel(upb_fielddef *f, upb_label_t label);
+bool upb_fielddef_setnumber(upb_fielddef *f, uint32_t number, upb_status *s);
+bool upb_fielddef_setname(upb_fielddef *f, const char *name, upb_status *s);
+bool upb_fielddef_setjsonname(upb_fielddef *f, const char *name, upb_status *s);
+bool upb_fielddef_clearjsonname(upb_fielddef *f);
+bool upb_fielddef_setcontainingtypename(upb_fielddef *f, const char *name,
+ upb_status *s);
+void upb_fielddef_setisextension(upb_fielddef *f, bool is_extension);
+void upb_fielddef_setlazy(upb_fielddef *f, bool lazy);
+void upb_fielddef_setpacked(upb_fielddef *f, bool packed);
+void upb_fielddef_setintfmt(upb_fielddef *f, upb_intfmt_t fmt);
+void upb_fielddef_settagdelim(upb_fielddef *f, bool tag_delim);
+void upb_fielddef_setdefaultint64(upb_fielddef *f, int64_t val);
+void upb_fielddef_setdefaultint32(upb_fielddef *f, int32_t val);
+void upb_fielddef_setdefaultuint64(upb_fielddef *f, uint64_t val);
+void upb_fielddef_setdefaultuint32(upb_fielddef *f, uint32_t val);
+void upb_fielddef_setdefaultbool(upb_fielddef *f, bool val);
+void upb_fielddef_setdefaultfloat(upb_fielddef *f, float val);
+void upb_fielddef_setdefaultdouble(upb_fielddef *f, double val);
+bool upb_fielddef_setdefaultstr(upb_fielddef *f, const void *str, size_t len,
+ upb_status *s);
+void upb_fielddef_setdefaultcstr(upb_fielddef *f, const char *str,
+ upb_status *s);
+bool upb_fielddef_setsubdef(upb_fielddef *f, const upb_def *subdef,
+ upb_status *s);
+bool upb_fielddef_setmsgsubdef(upb_fielddef *f, const upb_msgdef *subdef,
+ upb_status *s);
+bool upb_fielddef_setenumsubdef(upb_fielddef *f, const upb_enumdef *subdef,
+ upb_status *s);
+bool upb_fielddef_setsubdefname(upb_fielddef *f, const char *name,
+ upb_status *s);
+
+bool upb_fielddef_checklabel(int32_t label);
+bool upb_fielddef_checktype(int32_t type);
+bool upb_fielddef_checkdescriptortype(int32_t type);
+bool upb_fielddef_checkintfmt(int32_t fmt);
+
+UPB_END_EXTERN_C
+
+
+/* upb::MessageDef ************************************************************/
+
+typedef upb_inttable_iter upb_msg_field_iter;
+typedef upb_strtable_iter upb_msg_oneof_iter;
+
+/* Well-known field tag numbers for map-entry messages. */
+#define UPB_MAPENTRY_KEY 1
+#define UPB_MAPENTRY_VALUE 2
+
+#ifdef __cplusplus
+
+/* Structure that describes a single .proto message type.
+ *
+ * Its base class is upb::Def (use upb::upcast() to convert). */
+class upb::MessageDef {
+ public:
+ /* Returns NULL if memory allocation failed. */
+ static reffed_ptr<MessageDef> New();
+
+ /* upb::RefCounted methods like Ref()/Unref(). */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ /* Functionality from upb::Def. */
+ const char* full_name() const;
+ const char* name() const;
+ bool set_full_name(const char* fullname, Status* s);
+ bool set_full_name(const std::string& fullname, Status* s);
+
+ /* Call to freeze this MessageDef.
+ * WARNING: this will fail if this message has any unfrozen submessages!
+ * Messages with cycles must be frozen as a batch using upb::Def::Freeze(). */
+ bool Freeze(Status* s);
+
+ /* The number of fields that belong to the MessageDef. */
+ int field_count() const;
+
+ /* The number of oneofs that belong to the MessageDef. */
+ int oneof_count() const;
+
+ /* Adds a field (upb_fielddef object) to a msgdef. Requires that the msgdef
+ * and the fielddefs are mutable. The fielddef's name and number must be
+ * set, and the message may not already contain any field with this name or
+ * number, and this fielddef may not be part of another message. In error
+ * cases false is returned and the msgdef is unchanged.
+ *
+ * If the given field is part of a oneof, this call succeeds if and only if
+ * that oneof is already part of this msgdef. (Note that adding a oneof to a
+ * msgdef automatically adds all of its fields to the msgdef at the time that
+ * the oneof is added, so it is usually more idiomatic to add the oneof's
+ * fields first then add the oneof to the msgdef. This case is supported for
+ * convenience.)
+ *
+ * If |f| is already part of this MessageDef, this method performs no action
+ * and returns true (success). Thus, this method is idempotent. */
+ bool AddField(FieldDef* f, Status* s);
+ bool AddField(const reffed_ptr<FieldDef>& f, Status* s);
+
+ /* Adds a oneof (upb_oneofdef object) to a msgdef. Requires that the msgdef,
+ * oneof, and any fielddefs are mutable, that the fielddefs contained in the
+ * oneof do not have any name or number conflicts with existing fields in the
+ * msgdef, and that the oneof's name is unique among all oneofs in the msgdef.
+ * If the oneof is added successfully, all of its fields will be added
+ * directly to the msgdef as well. In error cases, false is returned and the
+ * msgdef is unchanged. */
+ bool AddOneof(OneofDef* o, Status* s);
+ bool AddOneof(const reffed_ptr<OneofDef>& o, Status* s);
+
+ upb_syntax_t syntax() const;
+
+ /* Returns false if we don't support this syntax value. */
+ bool set_syntax(upb_syntax_t syntax);
+
+ /* Set this to false to indicate that primitive fields should not have
+ * explicit presence information associated with them. This will affect all
+ * fields added to this message. Defaults to true. */
+ void SetPrimitivesHavePresence(bool have_presence);
+
+ /* These return NULL if the field is not found. */
+ FieldDef* FindFieldByNumber(uint32_t number);
+ FieldDef* FindFieldByName(const char *name, size_t len);
+ const FieldDef* FindFieldByNumber(uint32_t number) const;
+ const FieldDef* FindFieldByName(const char* name, size_t len) const;
+
+
+ FieldDef* FindFieldByName(const char *name) {
+ return FindFieldByName(name, strlen(name));
+ }
+ const FieldDef* FindFieldByName(const char *name) const {
+ return FindFieldByName(name, strlen(name));
+ }
+
+ template <class T>
+ FieldDef* FindFieldByName(const T& str) {
+ return FindFieldByName(str.c_str(), str.size());
+ }
+ template <class T>
+ const FieldDef* FindFieldByName(const T& str) const {
+ return FindFieldByName(str.c_str(), str.size());
+ }
+
+ OneofDef* FindOneofByName(const char* name, size_t len);
+ const OneofDef* FindOneofByName(const char* name, size_t len) const;
+
+ OneofDef* FindOneofByName(const char* name) {
+ return FindOneofByName(name, strlen(name));
+ }
+ const OneofDef* FindOneofByName(const char* name) const {
+ return FindOneofByName(name, strlen(name));
+ }
+
+ template<class T>
+ OneofDef* FindOneofByName(const T& str) {
+ return FindOneofByName(str.c_str(), str.size());
+ }
+ template<class T>
+ const OneofDef* FindOneofByName(const T& str) const {
+ return FindOneofByName(str.c_str(), str.size());
+ }
+
+ /* Is this message a map entry? */
+ void setmapentry(bool map_entry);
+ bool mapentry() const;
+
+ /* Iteration over fields. The order is undefined. */
+ class field_iterator
+ : public std::iterator<std::forward_iterator_tag, FieldDef*> {
+ public:
+ explicit field_iterator(MessageDef* md);
+ static field_iterator end(MessageDef* md);
+
+ void operator++();
+ FieldDef* operator*() const;
+ bool operator!=(const field_iterator& other) const;
+ bool operator==(const field_iterator& other) const;
+
+ private:
+ upb_msg_field_iter iter_;
+ };
+
+ class const_field_iterator
+ : public std::iterator<std::forward_iterator_tag, const FieldDef*> {
+ public:
+ explicit const_field_iterator(const MessageDef* md);
+ static const_field_iterator end(const MessageDef* md);
+
+ void operator++();
+ const FieldDef* operator*() const;
+ bool operator!=(const const_field_iterator& other) const;
+ bool operator==(const const_field_iterator& other) const;
+
+ private:
+ upb_msg_field_iter iter_;
+ };
+
+ /* Iteration over oneofs. The order is undefined. */
+ class oneof_iterator
+ : public std::iterator<std::forward_iterator_tag, FieldDef*> {
+ public:
+ explicit oneof_iterator(MessageDef* md);
+ static oneof_iterator end(MessageDef* md);
+
+ void operator++();
+ OneofDef* operator*() const;
+ bool operator!=(const oneof_iterator& other) const;
+ bool operator==(const oneof_iterator& other) const;
+
+ private:
+ upb_msg_oneof_iter iter_;
+ };
+
+ class const_oneof_iterator
+ : public std::iterator<std::forward_iterator_tag, const FieldDef*> {
+ public:
+ explicit const_oneof_iterator(const MessageDef* md);
+ static const_oneof_iterator end(const MessageDef* md);
+
+ void operator++();
+ const OneofDef* operator*() const;
+ bool operator!=(const const_oneof_iterator& other) const;
+ bool operator==(const const_oneof_iterator& other) const;
+
+ private:
+ upb_msg_oneof_iter iter_;
+ };
+
+ class FieldAccessor {
+ public:
+ explicit FieldAccessor(MessageDef* msg) : msg_(msg) {}
+ field_iterator begin() { return msg_->field_begin(); }
+ field_iterator end() { return msg_->field_end(); }
+ private:
+ MessageDef* msg_;
+ };
+
+ class ConstFieldAccessor {
+ public:
+ explicit ConstFieldAccessor(const MessageDef* msg) : msg_(msg) {}
+ const_field_iterator begin() { return msg_->field_begin(); }
+ const_field_iterator end() { return msg_->field_end(); }
+ private:
+ const MessageDef* msg_;
+ };
+
+ class OneofAccessor {
+ public:
+ explicit OneofAccessor(MessageDef* msg) : msg_(msg) {}
+ oneof_iterator begin() { return msg_->oneof_begin(); }
+ oneof_iterator end() { return msg_->oneof_end(); }
+ private:
+ MessageDef* msg_;
+ };
+
+ class ConstOneofAccessor {
+ public:
+ explicit ConstOneofAccessor(const MessageDef* msg) : msg_(msg) {}
+ const_oneof_iterator begin() { return msg_->oneof_begin(); }
+ const_oneof_iterator end() { return msg_->oneof_end(); }
+ private:
+ const MessageDef* msg_;
+ };
+
+ field_iterator field_begin();
+ field_iterator field_end();
+ const_field_iterator field_begin() const;
+ const_field_iterator field_end() const;
+
+ oneof_iterator oneof_begin();
+ oneof_iterator oneof_end();
+ const_oneof_iterator oneof_begin() const;
+ const_oneof_iterator oneof_end() const;
+
+ FieldAccessor fields() { return FieldAccessor(this); }
+ ConstFieldAccessor fields() const { return ConstFieldAccessor(this); }
+ OneofAccessor oneofs() { return OneofAccessor(this); }
+ ConstOneofAccessor oneofs() const { return ConstOneofAccessor(this); }
+
+ private:
+ UPB_DISALLOW_POD_OPS(MessageDef, upb::MessageDef)
+};
+
+#endif /* __cplusplus */
+
+UPB_BEGIN_EXTERN_C
+
+/* Returns NULL if memory allocation failed. */
+upb_msgdef *upb_msgdef_new(const void *owner);
+
+/* Include upb_refcounted methods like upb_msgdef_ref(). */
+UPB_REFCOUNTED_CMETHODS(upb_msgdef, upb_msgdef_upcast2)
+
+bool upb_msgdef_freeze(upb_msgdef *m, upb_status *status);
+
+const char *upb_msgdef_fullname(const upb_msgdef *m);
+const char *upb_msgdef_name(const upb_msgdef *m);
+int upb_msgdef_numoneofs(const upb_msgdef *m);
+upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m);
+
+bool upb_msgdef_addfield(upb_msgdef *m, upb_fielddef *f, const void *ref_donor,
+ upb_status *s);
+bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor,
+ upb_status *s);
+bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname, upb_status *s);
+void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry);
+bool upb_msgdef_mapentry(const upb_msgdef *m);
+bool upb_msgdef_setsyntax(upb_msgdef *m, upb_syntax_t syntax);
+
+/* Field lookup in a couple of different variations:
+ * - itof = int to field
+ * - ntof = name to field
+ * - ntofz = name to field, null-terminated string. */
+const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i);
+const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name,
+ size_t len);
+int upb_msgdef_numfields(const upb_msgdef *m);
+
+UPB_INLINE const upb_fielddef *upb_msgdef_ntofz(const upb_msgdef *m,
+ const char *name) {
+ return upb_msgdef_ntof(m, name, strlen(name));
+}
+
+UPB_INLINE upb_fielddef *upb_msgdef_itof_mutable(upb_msgdef *m, uint32_t i) {
+ return (upb_fielddef*)upb_msgdef_itof(m, i);
+}
+
+UPB_INLINE upb_fielddef *upb_msgdef_ntof_mutable(upb_msgdef *m,
+ const char *name, size_t len) {
+ return (upb_fielddef *)upb_msgdef_ntof(m, name, len);
+}
+
+/* Oneof lookup:
+ * - ntoo = name to oneof
+ * - ntooz = name to oneof, null-terminated string. */
+const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name,
+ size_t len);
+int upb_msgdef_numoneofs(const upb_msgdef *m);
+
+UPB_INLINE const upb_oneofdef *upb_msgdef_ntooz(const upb_msgdef *m,
+ const char *name) {
+ return upb_msgdef_ntoo(m, name, strlen(name));
+}
+
+UPB_INLINE upb_oneofdef *upb_msgdef_ntoo_mutable(upb_msgdef *m,
+ const char *name, size_t len) {
+ return (upb_oneofdef *)upb_msgdef_ntoo(m, name, len);
+}
+
+/* Lookup of either field or oneof by name. Returns whether either was found.
+ * If the return is true, then the found def will be set, and the non-found
+ * one set to NULL. */
+bool upb_msgdef_lookupname(const upb_msgdef *m, const char *name, size_t len,
+ const upb_fielddef **f, const upb_oneofdef **o);
+
+UPB_INLINE bool upb_msgdef_lookupnamez(const upb_msgdef *m, const char *name,
+ const upb_fielddef **f,
+ const upb_oneofdef **o) {
+ return upb_msgdef_lookupname(m, name, strlen(name), f, o);
+}
+
+/* Iteration over fields and oneofs. For example:
+ *
+ * upb_msg_field_iter i;
+ * for(upb_msg_field_begin(&i, m);
+ * !upb_msg_field_done(&i);
+ * upb_msg_field_next(&i)) {
+ * upb_fielddef *f = upb_msg_iter_field(&i);
+ * // ...
+ * }
+ *
+ * For C we don't have separate iterators for const and non-const.
+ * It is the caller's responsibility to cast the upb_fielddef* to
+ * const if the upb_msgdef* is const. */
+void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m);
+void upb_msg_field_next(upb_msg_field_iter *iter);
+bool upb_msg_field_done(const upb_msg_field_iter *iter);
+upb_fielddef *upb_msg_iter_field(const upb_msg_field_iter *iter);
+void upb_msg_field_iter_setdone(upb_msg_field_iter *iter);
+
+/* Similar to above, we also support iterating through the oneofs in a
+ * msgdef. */
+void upb_msg_oneof_begin(upb_msg_oneof_iter *iter, const upb_msgdef *m);
+void upb_msg_oneof_next(upb_msg_oneof_iter *iter);
+bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter);
+upb_oneofdef *upb_msg_iter_oneof(const upb_msg_oneof_iter *iter);
+void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter *iter);
+
+UPB_END_EXTERN_C
+
+
+/* upb::EnumDef ***************************************************************/
+
+typedef upb_strtable_iter upb_enum_iter;
+
+#ifdef __cplusplus
+
+/* Class that represents an enum. Its base class is upb::Def (convert with
+ * upb::upcast()). */
+class upb::EnumDef {
+ public:
+ /* Returns NULL if memory allocation failed. */
+ static reffed_ptr<EnumDef> New();
+
+ /* upb::RefCounted methods like Ref()/Unref(). */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ /* Functionality from upb::Def. */
+ const char* full_name() const;
+ const char* name() const;
+ bool set_full_name(const char* fullname, Status* s);
+ bool set_full_name(const std::string& fullname, Status* s);
+
+ /* Call to freeze this EnumDef. */
+ bool Freeze(Status* s);
+
+ /* The value that is used as the default when no field default is specified.
+ * If not set explicitly, the first value that was added will be used.
+ * The default value must be a member of the enum.
+ * Requires that value_count() > 0. */
+ int32_t default_value() const;
+
+ /* Sets the default value. If this value is not valid, returns false and an
+ * error message in status. */
+ bool set_default_value(int32_t val, Status* status);
+
+ /* Returns the number of values currently defined in the enum. Note that
+ * multiple names can refer to the same number, so this may be greater than
+ * the total number of unique numbers. */
+ int value_count() const;
+
+ /* Adds a single name/number pair to the enum. Fails if this name has
+ * already been used by another value. */
+ bool AddValue(const char* name, int32_t num, Status* status);
+ bool AddValue(const std::string& name, int32_t num, Status* status);
+
+ /* Lookups from name to integer, returning true if found. */
+ bool FindValueByName(const char* name, int32_t* num) const;
+
+ /* Finds the name corresponding to the given number, or NULL if none was
+ * found. If more than one name corresponds to this number, returns the
+ * first one that was added. */
+ const char* FindValueByNumber(int32_t num) const;
+
+ /* Iteration over name/value pairs. The order is undefined.
+ * Adding an enum val invalidates any iterators.
+ *
+ * TODO: make compatible with range-for, with elements as pairs? */
+ class Iterator {
+ public:
+ explicit Iterator(const EnumDef*);
+
+ int32_t number();
+ const char *name();
+ bool Done();
+ void Next();
+
+ private:
+ upb_enum_iter iter_;
+ };
+
+ private:
+ UPB_DISALLOW_POD_OPS(EnumDef, upb::EnumDef)
+};
+
+#endif /* __cplusplus */
+
+UPB_BEGIN_EXTERN_C
+
+/* Native C API. */
+upb_enumdef *upb_enumdef_new(const void *owner);
+
+/* Include upb_refcounted methods like upb_enumdef_ref(). */
+UPB_REFCOUNTED_CMETHODS(upb_enumdef, upb_enumdef_upcast2)
+
+bool upb_enumdef_freeze(upb_enumdef *e, upb_status *status);
+
+/* From upb_def. */
+const char *upb_enumdef_fullname(const upb_enumdef *e);
+const char *upb_enumdef_name(const upb_enumdef *e);
+bool upb_enumdef_setfullname(upb_enumdef *e, const char *fullname,
+ upb_status *s);
+
+int32_t upb_enumdef_default(const upb_enumdef *e);
+bool upb_enumdef_setdefault(upb_enumdef *e, int32_t val, upb_status *s);
+int upb_enumdef_numvals(const upb_enumdef *e);
+bool upb_enumdef_addval(upb_enumdef *e, const char *name, int32_t num,
+ upb_status *status);
+
+/* Enum lookups:
+ * - ntoi: look up a name with specified length.
+ * - ntoiz: look up a name provided as a null-terminated string.
+ * - iton: look up an integer, returning the name as a null-terminated
+ * string. */
+bool upb_enumdef_ntoi(const upb_enumdef *e, const char *name, size_t len,
+ int32_t *num);
+UPB_INLINE bool upb_enumdef_ntoiz(const upb_enumdef *e,
+ const char *name, int32_t *num) {
+ return upb_enumdef_ntoi(e, name, strlen(name), num);
+}
+const char *upb_enumdef_iton(const upb_enumdef *e, int32_t num);
+
+/* upb_enum_iter i;
+ * for(upb_enum_begin(&i, e); !upb_enum_done(&i); upb_enum_next(&i)) {
+ * // ...
+ * }
+ */
+void upb_enum_begin(upb_enum_iter *iter, const upb_enumdef *e);
+void upb_enum_next(upb_enum_iter *iter);
+bool upb_enum_done(upb_enum_iter *iter);
+const char *upb_enum_iter_name(upb_enum_iter *iter);
+int32_t upb_enum_iter_number(upb_enum_iter *iter);
+
+UPB_END_EXTERN_C
+
+
+/* upb::OneofDef **************************************************************/
+
+typedef upb_inttable_iter upb_oneof_iter;
+
+#ifdef __cplusplus
+
+/* Class that represents a oneof. */
+class upb::OneofDef {
+ public:
+ /* Returns NULL if memory allocation failed. */
+ static reffed_ptr<OneofDef> New();
+
+ /* upb::RefCounted methods like Ref()/Unref(). */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ /* Returns the MessageDef that owns this OneofDef. */
+ const MessageDef* containing_type() const;
+
+ /* Returns the name of this oneof. This is the name used to look up the oneof
+ * by name once added to a message def. */
+ const char* name() const;
+ bool set_name(const char* name, Status* s);
+ bool set_name(const std::string& name, Status* s);
+
+ /* Returns the number of fields currently defined in the oneof. */
+ int field_count() const;
+
+ /* Adds a field to the oneof. The field must not have been added to any other
+ * oneof or msgdef. If the oneof is not yet part of a msgdef, then when the
+ * oneof is eventually added to a msgdef, all fields added to the oneof will
+ * also be added to the msgdef at that time. If the oneof is already part of a
+ * msgdef, the field must either be a part of that msgdef already, or must not
+ * be a part of any msgdef; in the latter case, the field is added to the
+ * msgdef as a part of this operation.
+ *
+ * The field may only have an OPTIONAL label, never REQUIRED or REPEATED.
+ *
+ * If |f| is already part of this MessageDef, this method performs no action
+ * and returns true (success). Thus, this method is idempotent. */
+ bool AddField(FieldDef* field, Status* s);
+ bool AddField(const reffed_ptr<FieldDef>& field, Status* s);
+
+ /* Looks up by name. */
+ const FieldDef* FindFieldByName(const char* name, size_t len) const;
+ FieldDef* FindFieldByName(const char* name, size_t len);
+ const FieldDef* FindFieldByName(const char* name) const {
+ return FindFieldByName(name, strlen(name));
+ }
+ FieldDef* FindFieldByName(const char* name) {
+ return FindFieldByName(name, strlen(name));
+ }
+
+ template <class T>
+ FieldDef* FindFieldByName(const T& str) {
+ return FindFieldByName(str.c_str(), str.size());
+ }
+ template <class T>
+ const FieldDef* FindFieldByName(const T& str) const {
+ return FindFieldByName(str.c_str(), str.size());
+ }
+
+ /* Looks up by tag number. */
+ const FieldDef* FindFieldByNumber(uint32_t num) const;
+
+ /* Iteration over fields. The order is undefined. */
+ class iterator : public std::iterator<std::forward_iterator_tag, FieldDef*> {
+ public:
+ explicit iterator(OneofDef* md);
+ static iterator end(OneofDef* md);
+
+ void operator++();
+ FieldDef* operator*() const;
+ bool operator!=(const iterator& other) const;
+ bool operator==(const iterator& other) const;
+
+ private:
+ upb_oneof_iter iter_;
+ };
+
+ class const_iterator
+ : public std::iterator<std::forward_iterator_tag, const FieldDef*> {
+ public:
+ explicit const_iterator(const OneofDef* md);
+ static const_iterator end(const OneofDef* md);
+
+ void operator++();
+ const FieldDef* operator*() const;
+ bool operator!=(const const_iterator& other) const;
+ bool operator==(const const_iterator& other) const;
+
+ private:
+ upb_oneof_iter iter_;
+ };
+
+ iterator begin();
+ iterator end();
+ const_iterator begin() const;
+ const_iterator end() const;
+
+ private:
+ UPB_DISALLOW_POD_OPS(OneofDef, upb::OneofDef)
+};
+
+#endif /* __cplusplus */
+
+UPB_BEGIN_EXTERN_C
+
+/* Native C API. */
+upb_oneofdef *upb_oneofdef_new(const void *owner);
+
+/* Include upb_refcounted methods like upb_oneofdef_ref(). */
+UPB_REFCOUNTED_CMETHODS(upb_oneofdef, upb_oneofdef_upcast)
+
+const char *upb_oneofdef_name(const upb_oneofdef *o);
+const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o);
+int upb_oneofdef_numfields(const upb_oneofdef *o);
+uint32_t upb_oneofdef_index(const upb_oneofdef *o);
+
+bool upb_oneofdef_setname(upb_oneofdef *o, const char *name, upb_status *s);
+bool upb_oneofdef_addfield(upb_oneofdef *o, upb_fielddef *f,
+ const void *ref_donor,
+ upb_status *s);
+
+/* Oneof lookups:
+ * - ntof: look up a field by name.
+ * - ntofz: look up a field by name (as a null-terminated string).
+ * - itof: look up a field by number. */
+const upb_fielddef *upb_oneofdef_ntof(const upb_oneofdef *o,
+ const char *name, size_t length);
+UPB_INLINE const upb_fielddef *upb_oneofdef_ntofz(const upb_oneofdef *o,
+ const char *name) {
+ return upb_oneofdef_ntof(o, name, strlen(name));
+}
+const upb_fielddef *upb_oneofdef_itof(const upb_oneofdef *o, uint32_t num);
+
+/* upb_oneof_iter i;
+ * for(upb_oneof_begin(&i, e); !upb_oneof_done(&i); upb_oneof_next(&i)) {
+ * // ...
+ * }
+ */
+void upb_oneof_begin(upb_oneof_iter *iter, const upb_oneofdef *o);
+void upb_oneof_next(upb_oneof_iter *iter);
+bool upb_oneof_done(upb_oneof_iter *iter);
+upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter);
+void upb_oneof_iter_setdone(upb_oneof_iter *iter);
+
+UPB_END_EXTERN_C
+
+
+/* upb::FileDef ***************************************************************/
+
+#ifdef __cplusplus
+
+/* Class that represents a .proto file with some things defined in it.
+ *
+ * Many users won't care about FileDefs, but they are necessary if you want to
+ * read the values of file-level options. */
+class upb::FileDef {
+ public:
+ /* Returns NULL if memory allocation failed. */
+ static reffed_ptr<FileDef> New();
+
+ /* upb::RefCounted methods like Ref()/Unref(). */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ /* Get/set name of the file (eg. "foo/bar.proto"). */
+ const char* name() const;
+ bool set_name(const char* name, Status* s);
+ bool set_name(const std::string& name, Status* s);
+
+ /* Package name for definitions inside the file (eg. "foo.bar"). */
+ const char* package() const;
+ bool set_package(const char* package, Status* s);
+
+ /* Sets the php class prefix which is prepended to all php generated classes
+ / from this .proto. Default is empty. */
+ const char* phpprefix() const;
+ bool set_phpprefix(const char* phpprefix, Status* s);
+
+ /* Syntax for the file. Defaults to proto2. */
+ upb_syntax_t syntax() const;
+ void set_syntax(upb_syntax_t syntax);
+
+ /* Get the list of defs from the file. These are returned in the order that
+ * they were added to the FileDef. */
+ int def_count() const;
+ const Def* def(int index) const;
+ Def* def(int index);
+
+ /* Get the list of dependencies from the file. These are returned in the
+ * order that they were added to the FileDef. */
+ int dependency_count() const;
+ const FileDef* dependency(int index) const;
+
+ /* Adds defs to this file. The def must not already belong to another
+ * file.
+ *
+ * Note: this does *not* ensure that this def's name is unique in this file!
+ * Use a SymbolTable if you want to check this property. Especially since
+ * properly checking uniqueness would require a check across *all* files
+ * (including dependencies). */
+ bool AddDef(Def* def, Status* s);
+ bool AddMessage(MessageDef* m, Status* s);
+ bool AddEnum(EnumDef* e, Status* s);
+ bool AddExtension(FieldDef* f, Status* s);
+
+ /* Adds a dependency of this file. */
+ bool AddDependency(const FileDef* file);
+
+ /* Freezes this FileDef and all messages/enums under it. All subdefs must be
+ * resolved and all messages/enums must validate. Returns true if this
+ * succeeded.
+ *
+ * TODO(haberman): should we care whether the file's dependencies are frozen
+ * already? */
+ bool Freeze(Status* s);
+
+ private:
+ UPB_DISALLOW_POD_OPS(FileDef, upb::FileDef)
+};
+
+#endif
+
+UPB_BEGIN_EXTERN_C
+
+upb_filedef *upb_filedef_new(const void *owner);
+
+/* Include upb_refcounted methods like upb_msgdef_ref(). */
+UPB_REFCOUNTED_CMETHODS(upb_filedef, upb_filedef_upcast)
+
+const char *upb_filedef_name(const upb_filedef *f);
+const char *upb_filedef_package(const upb_filedef *f);
+const char *upb_filedef_phpprefix(const upb_filedef *f);
+upb_syntax_t upb_filedef_syntax(const upb_filedef *f);
+size_t upb_filedef_defcount(const upb_filedef *f);
+size_t upb_filedef_depcount(const upb_filedef *f);
+const upb_def *upb_filedef_def(const upb_filedef *f, size_t i);
+const upb_filedef *upb_filedef_dep(const upb_filedef *f, size_t i);
+
+bool upb_filedef_freeze(upb_filedef *f, upb_status *s);
+bool upb_filedef_setname(upb_filedef *f, const char *name, upb_status *s);
+bool upb_filedef_setpackage(upb_filedef *f, const char *package, upb_status *s);
+bool upb_filedef_setphpprefix(upb_filedef *f, const char *phpprefix,
+ upb_status *s);
+bool upb_filedef_setsyntax(upb_filedef *f, upb_syntax_t syntax, upb_status *s);
+
+bool upb_filedef_adddef(upb_filedef *f, upb_def *def, const void *ref_donor,
+ upb_status *s);
+bool upb_filedef_adddep(upb_filedef *f, const upb_filedef *dep);
+
+UPB_INLINE bool upb_filedef_addmsg(upb_filedef *f, upb_msgdef *m,
+ const void *ref_donor, upb_status *s) {
+ return upb_filedef_adddef(f, upb_msgdef_upcast_mutable(m), ref_donor, s);
+}
+
+UPB_INLINE bool upb_filedef_addenum(upb_filedef *f, upb_enumdef *e,
+ const void *ref_donor, upb_status *s) {
+ return upb_filedef_adddef(f, upb_enumdef_upcast_mutable(e), ref_donor, s);
+}
+
+UPB_INLINE bool upb_filedef_addext(upb_filedef *file, upb_fielddef *f,
+ const void *ref_donor, upb_status *s) {
+ return upb_filedef_adddef(file, upb_fielddef_upcast_mutable(f), ref_donor, s);
+}
+UPB_INLINE upb_def *upb_filedef_mutabledef(upb_filedef *f, int i) {
+ return (upb_def*)upb_filedef_def(f, i);
+}
+
+UPB_END_EXTERN_C
+
+typedef struct {
+ UPB_PRIVATE_FOR_CPP
+ upb_strtable_iter iter;
+ upb_deftype_t type;
+} upb_symtab_iter;
+
+#ifdef __cplusplus
+
+/* Non-const methods in upb::SymbolTable are NOT thread-safe. */
+class upb::SymbolTable {
+ public:
+ /* Returns a new symbol table with a single ref owned by "owner."
+ * Returns NULL if memory allocation failed. */
+ static SymbolTable* New();
+ static void Free(upb::SymbolTable* table);
+
+ /* For all lookup functions, the returned pointer is not owned by the
+ * caller; it may be invalidated by any non-const call or unref of the
+ * SymbolTable! To protect against this, take a ref if desired. */
+
+ /* Freezes the symbol table: prevents further modification of it.
+ * After the Freeze() operation is successful, the SymbolTable must only be
+ * accessed via a const pointer.
+ *
+ * Unlike with upb::MessageDef/upb::EnumDef/etc, freezing a SymbolTable is not
+ * a necessary step in using a SymbolTable. If you have no need for it to be
+ * immutable, there is no need to freeze it ever. However sometimes it is
+ * useful, and SymbolTables that are statically compiled into the binary are
+ * always frozen by nature. */
+ void Freeze();
+
+ /* Resolves the given symbol using the rules described in descriptor.proto,
+ * namely:
+ *
+ * If the name starts with a '.', it is fully-qualified. Otherwise,
+ * C++-like scoping rules are used to find the type (i.e. first the nested
+ * types within this message are searched, then within the parent, on up
+ * to the root namespace).
+ *
+ * If not found, returns NULL. */
+ const Def* Resolve(const char* base, const char* sym) const;
+
+ /* Finds an entry in the symbol table with this exact name. If not found,
+ * returns NULL. */
+ const Def* Lookup(const char *sym) const;
+ const MessageDef* LookupMessage(const char *sym) const;
+ const EnumDef* LookupEnum(const char *sym) const;
+
+ /* TODO: introduce a C++ iterator, but make it nice and templated so that if
+ * you ask for an iterator of MessageDef the iterated elements are strongly
+ * typed as MessageDef*. */
+
+ /* Adds the given mutable defs to the symtab, resolving all symbols (including
+ * enum default values) and finalizing the defs. Only one def per name may be
+ * in the list, and the defs may not duplicate any name already in the symtab.
+ * All defs must have a name -- anonymous defs are not allowed. Anonymous
+ * defs can still be frozen by calling upb_def_freeze() directly.
+ *
+ * The entire operation either succeeds or fails. If the operation fails,
+ * the symtab is unchanged, false is returned, and status indicates the
+ * error. The caller passes a ref on all defs to the symtab (even if the
+ * operation fails).
+ *
+ * TODO(haberman): currently failure will leave the symtab unchanged, but may
+ * leave the defs themselves partially resolved. Does this matter? If so we
+ * could do a prepass that ensures that all symbols are resolvable and bail
+ * if not, so we don't mutate anything until we know the operation will
+ * succeed. */
+ bool Add(Def*const* defs, size_t n, void* ref_donor, Status* status);
+
+ bool Add(const std::vector<Def*>& defs, void *owner, Status* status) {
+ return Add((Def*const*)&defs[0], defs.size(), owner, status);
+ }
+
+ /* Resolves all subdefs for messages in this file and attempts to freeze the
+ * file. If this succeeds, adds all the symbols to this SymbolTable
+ * (replacing any existing ones with the same names). */
+ bool AddFile(FileDef* file, Status* s);
+
+ private:
+ UPB_DISALLOW_POD_OPS(SymbolTable, upb::SymbolTable)
+};
+
+#endif /* __cplusplus */
+
+UPB_BEGIN_EXTERN_C
+
+/* Native C API. */
+
+upb_symtab *upb_symtab_new();
+void upb_symtab_free(upb_symtab* s);
+const upb_def *upb_symtab_resolve(const upb_symtab *s, const char *base,
+ const char *sym);
+const upb_def *upb_symtab_lookup(const upb_symtab *s, const char *sym);
+const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym);
+const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym);
+bool upb_symtab_add(upb_symtab *s, upb_def *const*defs, size_t n,
+ void *ref_donor, upb_status *status);
+bool upb_symtab_addfile(upb_symtab *s, upb_filedef *file, upb_status* status);
+
+/* upb_symtab_iter i;
+ * for(upb_symtab_begin(&i, s, type); !upb_symtab_done(&i);
+ * upb_symtab_next(&i)) {
+ * const upb_def *def = upb_symtab_iter_def(&i);
+ * // ...
+ * }
+ *
+ * For C we don't have separate iterators for const and non-const.
+ * It is the caller's responsibility to cast the upb_fielddef* to
+ * const if the upb_msgdef* is const. */
+void upb_symtab_begin(upb_symtab_iter *iter, const upb_symtab *s,
+ upb_deftype_t type);
+void upb_symtab_next(upb_symtab_iter *iter);
+bool upb_symtab_done(const upb_symtab_iter *iter);
+const upb_def *upb_symtab_iter_def(const upb_symtab_iter *iter);
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+/* C++ inline wrappers. */
+namespace upb {
+inline SymbolTable* SymbolTable::New() {
+ return upb_symtab_new();
+}
+inline void SymbolTable::Free(SymbolTable* s) {
+ upb_symtab_free(s);
+}
+inline const Def *SymbolTable::Resolve(const char *base,
+ const char *sym) const {
+ return upb_symtab_resolve(this, base, sym);
+}
+inline const Def* SymbolTable::Lookup(const char *sym) const {
+ return upb_symtab_lookup(this, sym);
+}
+inline const MessageDef *SymbolTable::LookupMessage(const char *sym) const {
+ return upb_symtab_lookupmsg(this, sym);
+}
+inline bool SymbolTable::Add(
+ Def*const* defs, size_t n, void* ref_donor, Status* status) {
+ return upb_symtab_add(this, (upb_def*const*)defs, n, ref_donor, status);
+}
+inline bool SymbolTable::AddFile(FileDef* file, Status* s) {
+ return upb_symtab_addfile(this, file, s);
+}
+} /* namespace upb */
+#endif
+
+#ifdef __cplusplus
+
+UPB_INLINE const char* upb_safecstr(const std::string& str) {
+ UPB_ASSERT(str.size() == std::strlen(str.c_str()));
+ return str.c_str();
+}
+
+/* Inline C++ wrappers. */
+namespace upb {
+
+inline Def::Type Def::def_type() const { return upb_def_type(this); }
+inline const char* Def::full_name() const { return upb_def_fullname(this); }
+inline const char* Def::name() const { return upb_def_name(this); }
+inline bool Def::set_full_name(const char* fullname, Status* s) {
+ return upb_def_setfullname(this, fullname, s);
+}
+inline bool Def::set_full_name(const std::string& fullname, Status* s) {
+ return upb_def_setfullname(this, upb_safecstr(fullname), s);
+}
+inline bool Def::Freeze(Def* const* defs, size_t n, Status* status) {
+ return upb_def_freeze(defs, n, status);
+}
+inline bool Def::Freeze(const std::vector<Def*>& defs, Status* status) {
+ return upb_def_freeze((Def* const*)&defs[0], defs.size(), status);
+}
+
+inline bool FieldDef::CheckType(int32_t val) {
+ return upb_fielddef_checktype(val);
+}
+inline bool FieldDef::CheckLabel(int32_t val) {
+ return upb_fielddef_checklabel(val);
+}
+inline bool FieldDef::CheckDescriptorType(int32_t val) {
+ return upb_fielddef_checkdescriptortype(val);
+}
+inline bool FieldDef::CheckIntegerFormat(int32_t val) {
+ return upb_fielddef_checkintfmt(val);
+}
+inline FieldDef::Type FieldDef::ConvertType(int32_t val) {
+ UPB_ASSERT(CheckType(val));
+ return static_cast<FieldDef::Type>(val);
+}
+inline FieldDef::Label FieldDef::ConvertLabel(int32_t val) {
+ UPB_ASSERT(CheckLabel(val));
+ return static_cast<FieldDef::Label>(val);
+}
+inline FieldDef::DescriptorType FieldDef::ConvertDescriptorType(int32_t val) {
+ UPB_ASSERT(CheckDescriptorType(val));
+ return static_cast<FieldDef::DescriptorType>(val);
+}
+inline FieldDef::IntegerFormat FieldDef::ConvertIntegerFormat(int32_t val) {
+ UPB_ASSERT(CheckIntegerFormat(val));
+ return static_cast<FieldDef::IntegerFormat>(val);
+}
+
+inline reffed_ptr<FieldDef> FieldDef::New() {
+ upb_fielddef *f = upb_fielddef_new(&f);
+ return reffed_ptr<FieldDef>(f, &f);
+}
+inline const char* FieldDef::full_name() const {
+ return upb_fielddef_fullname(this);
+}
+inline bool FieldDef::set_full_name(const char* fullname, Status* s) {
+ return upb_fielddef_setfullname(this, fullname, s);
+}
+inline bool FieldDef::set_full_name(const std::string& fullname, Status* s) {
+ return upb_fielddef_setfullname(this, upb_safecstr(fullname), s);
+}
+inline bool FieldDef::type_is_set() const {
+ return upb_fielddef_typeisset(this);
+}
+inline FieldDef::Type FieldDef::type() const { return upb_fielddef_type(this); }
+inline FieldDef::DescriptorType FieldDef::descriptor_type() const {
+ return upb_fielddef_descriptortype(this);
+}
+inline FieldDef::Label FieldDef::label() const {
+ return upb_fielddef_label(this);
+}
+inline uint32_t FieldDef::number() const { return upb_fielddef_number(this); }
+inline const char* FieldDef::name() const { return upb_fielddef_name(this); }
+inline bool FieldDef::is_extension() const {
+ return upb_fielddef_isextension(this);
+}
+inline size_t FieldDef::GetJsonName(char* buf, size_t len) const {
+ return upb_fielddef_getjsonname(this, buf, len);
+}
+inline bool FieldDef::lazy() const {
+ return upb_fielddef_lazy(this);
+}
+inline void FieldDef::set_lazy(bool lazy) {
+ upb_fielddef_setlazy(this, lazy);
+}
+inline bool FieldDef::packed() const {
+ return upb_fielddef_packed(this);
+}
+inline uint32_t FieldDef::index() const {
+ return upb_fielddef_index(this);
+}
+inline void FieldDef::set_packed(bool packed) {
+ upb_fielddef_setpacked(this, packed);
+}
+inline const MessageDef* FieldDef::containing_type() const {
+ return upb_fielddef_containingtype(this);
+}
+inline const OneofDef* FieldDef::containing_oneof() const {
+ return upb_fielddef_containingoneof(this);
+}
+inline const char* FieldDef::containing_type_name() {
+ return upb_fielddef_containingtypename(this);
+}
+inline bool FieldDef::set_number(uint32_t number, Status* s) {
+ return upb_fielddef_setnumber(this, number, s);
+}
+inline bool FieldDef::set_name(const char *name, Status* s) {
+ return upb_fielddef_setname(this, name, s);
+}
+inline bool FieldDef::set_name(const std::string& name, Status* s) {
+ return upb_fielddef_setname(this, upb_safecstr(name), s);
+}
+inline bool FieldDef::set_json_name(const char *name, Status* s) {
+ return upb_fielddef_setjsonname(this, name, s);
+}
+inline bool FieldDef::set_json_name(const std::string& name, Status* s) {
+ return upb_fielddef_setjsonname(this, upb_safecstr(name), s);
+}
+inline void FieldDef::clear_json_name() {
+ upb_fielddef_clearjsonname(this);
+}
+inline bool FieldDef::set_containing_type_name(const char *name, Status* s) {
+ return upb_fielddef_setcontainingtypename(this, name, s);
+}
+inline bool FieldDef::set_containing_type_name(const std::string &name,
+ Status *s) {
+ return upb_fielddef_setcontainingtypename(this, upb_safecstr(name), s);
+}
+inline void FieldDef::set_type(upb_fieldtype_t type) {
+ upb_fielddef_settype(this, type);
+}
+inline void FieldDef::set_is_extension(bool is_extension) {
+ upb_fielddef_setisextension(this, is_extension);
+}
+inline void FieldDef::set_descriptor_type(FieldDef::DescriptorType type) {
+ upb_fielddef_setdescriptortype(this, type);
+}
+inline void FieldDef::set_label(upb_label_t label) {
+ upb_fielddef_setlabel(this, label);
+}
+inline bool FieldDef::IsSubMessage() const {
+ return upb_fielddef_issubmsg(this);
+}
+inline bool FieldDef::IsString() const { return upb_fielddef_isstring(this); }
+inline bool FieldDef::IsSequence() const { return upb_fielddef_isseq(this); }
+inline bool FieldDef::IsMap() const { return upb_fielddef_ismap(this); }
+inline int64_t FieldDef::default_int64() const {
+ return upb_fielddef_defaultint64(this);
+}
+inline int32_t FieldDef::default_int32() const {
+ return upb_fielddef_defaultint32(this);
+}
+inline uint64_t FieldDef::default_uint64() const {
+ return upb_fielddef_defaultuint64(this);
+}
+inline uint32_t FieldDef::default_uint32() const {
+ return upb_fielddef_defaultuint32(this);
+}
+inline bool FieldDef::default_bool() const {
+ return upb_fielddef_defaultbool(this);
+}
+inline float FieldDef::default_float() const {
+ return upb_fielddef_defaultfloat(this);
+}
+inline double FieldDef::default_double() const {
+ return upb_fielddef_defaultdouble(this);
+}
+inline const char* FieldDef::default_string(size_t* len) const {
+ return upb_fielddef_defaultstr(this, len);
+}
+inline void FieldDef::set_default_int64(int64_t value) {
+ upb_fielddef_setdefaultint64(this, value);
+}
+inline void FieldDef::set_default_int32(int32_t value) {
+ upb_fielddef_setdefaultint32(this, value);
+}
+inline void FieldDef::set_default_uint64(uint64_t value) {
+ upb_fielddef_setdefaultuint64(this, value);
+}
+inline void FieldDef::set_default_uint32(uint32_t value) {
+ upb_fielddef_setdefaultuint32(this, value);
+}
+inline void FieldDef::set_default_bool(bool value) {
+ upb_fielddef_setdefaultbool(this, value);
+}
+inline void FieldDef::set_default_float(float value) {
+ upb_fielddef_setdefaultfloat(this, value);
+}
+inline void FieldDef::set_default_double(double value) {
+ upb_fielddef_setdefaultdouble(this, value);
+}
+inline bool FieldDef::set_default_string(const void *str, size_t len,
+ Status *s) {
+ return upb_fielddef_setdefaultstr(this, str, len, s);
+}
+inline bool FieldDef::set_default_string(const std::string& str, Status* s) {
+ return upb_fielddef_setdefaultstr(this, str.c_str(), str.size(), s);
+}
+inline void FieldDef::set_default_cstr(const char* str, Status* s) {
+ return upb_fielddef_setdefaultcstr(this, str, s);
+}
+inline bool FieldDef::HasSubDef() const { return upb_fielddef_hassubdef(this); }
+inline const Def* FieldDef::subdef() const { return upb_fielddef_subdef(this); }
+inline const MessageDef *FieldDef::message_subdef() const {
+ return upb_fielddef_msgsubdef(this);
+}
+inline const EnumDef *FieldDef::enum_subdef() const {
+ return upb_fielddef_enumsubdef(this);
+}
+inline const char* FieldDef::subdef_name() const {
+ return upb_fielddef_subdefname(this);
+}
+inline bool FieldDef::set_subdef(const Def* subdef, Status* s) {
+ return upb_fielddef_setsubdef(this, subdef, s);
+}
+inline bool FieldDef::set_enum_subdef(const EnumDef* subdef, Status* s) {
+ return upb_fielddef_setenumsubdef(this, subdef, s);
+}
+inline bool FieldDef::set_message_subdef(const MessageDef* subdef, Status* s) {
+ return upb_fielddef_setmsgsubdef(this, subdef, s);
+}
+inline bool FieldDef::set_subdef_name(const char* name, Status* s) {
+ return upb_fielddef_setsubdefname(this, name, s);
+}
+inline bool FieldDef::set_subdef_name(const std::string& name, Status* s) {
+ return upb_fielddef_setsubdefname(this, upb_safecstr(name), s);
+}
+
+inline reffed_ptr<MessageDef> MessageDef::New() {
+ upb_msgdef *m = upb_msgdef_new(&m);
+ return reffed_ptr<MessageDef>(m, &m);
+}
+inline const char *MessageDef::full_name() const {
+ return upb_msgdef_fullname(this);
+}
+inline const char *MessageDef::name() const {
+ return upb_msgdef_name(this);
+}
+inline upb_syntax_t MessageDef::syntax() const {
+ return upb_msgdef_syntax(this);
+}
+inline bool MessageDef::set_full_name(const char* fullname, Status* s) {
+ return upb_msgdef_setfullname(this, fullname, s);
+}
+inline bool MessageDef::set_full_name(const std::string& fullname, Status* s) {
+ return upb_msgdef_setfullname(this, upb_safecstr(fullname), s);
+}
+inline bool MessageDef::set_syntax(upb_syntax_t syntax) {
+ return upb_msgdef_setsyntax(this, syntax);
+}
+inline bool MessageDef::Freeze(Status* status) {
+ return upb_msgdef_freeze(this, status);
+}
+inline int MessageDef::field_count() const {
+ return upb_msgdef_numfields(this);
+}
+inline int MessageDef::oneof_count() const {
+ return upb_msgdef_numoneofs(this);
+}
+inline bool MessageDef::AddField(upb_fielddef* f, Status* s) {
+ return upb_msgdef_addfield(this, f, NULL, s);
+}
+inline bool MessageDef::AddField(const reffed_ptr<FieldDef>& f, Status* s) {
+ return upb_msgdef_addfield(this, f.get(), NULL, s);
+}
+inline bool MessageDef::AddOneof(upb_oneofdef* o, Status* s) {
+ return upb_msgdef_addoneof(this, o, NULL, s);
+}
+inline bool MessageDef::AddOneof(const reffed_ptr<OneofDef>& o, Status* s) {
+ return upb_msgdef_addoneof(this, o.get(), NULL, s);
+}
+inline FieldDef* MessageDef::FindFieldByNumber(uint32_t number) {
+ return upb_msgdef_itof_mutable(this, number);
+}
+inline FieldDef* MessageDef::FindFieldByName(const char* name, size_t len) {
+ return upb_msgdef_ntof_mutable(this, name, len);
+}
+inline const FieldDef* MessageDef::FindFieldByNumber(uint32_t number) const {
+ return upb_msgdef_itof(this, number);
+}
+inline const FieldDef *MessageDef::FindFieldByName(const char *name,
+ size_t len) const {
+ return upb_msgdef_ntof(this, name, len);
+}
+inline OneofDef* MessageDef::FindOneofByName(const char* name, size_t len) {
+ return upb_msgdef_ntoo_mutable(this, name, len);
+}
+inline const OneofDef* MessageDef::FindOneofByName(const char* name,
+ size_t len) const {
+ return upb_msgdef_ntoo(this, name, len);
+}
+inline void MessageDef::setmapentry(bool map_entry) {
+ upb_msgdef_setmapentry(this, map_entry);
+}
+inline bool MessageDef::mapentry() const {
+ return upb_msgdef_mapentry(this);
+}
+inline MessageDef::field_iterator MessageDef::field_begin() {
+ return field_iterator(this);
+}
+inline MessageDef::field_iterator MessageDef::field_end() {
+ return field_iterator::end(this);
+}
+inline MessageDef::const_field_iterator MessageDef::field_begin() const {
+ return const_field_iterator(this);
+}
+inline MessageDef::const_field_iterator MessageDef::field_end() const {
+ return const_field_iterator::end(this);
+}
+
+inline MessageDef::oneof_iterator MessageDef::oneof_begin() {
+ return oneof_iterator(this);
+}
+inline MessageDef::oneof_iterator MessageDef::oneof_end() {
+ return oneof_iterator::end(this);
+}
+inline MessageDef::const_oneof_iterator MessageDef::oneof_begin() const {
+ return const_oneof_iterator(this);
+}
+inline MessageDef::const_oneof_iterator MessageDef::oneof_end() const {
+ return const_oneof_iterator::end(this);
+}
+
+inline MessageDef::field_iterator::field_iterator(MessageDef* md) {
+ upb_msg_field_begin(&iter_, md);
+}
+inline MessageDef::field_iterator MessageDef::field_iterator::end(
+ MessageDef* md) {
+ MessageDef::field_iterator iter(md);
+ upb_msg_field_iter_setdone(&iter.iter_);
+ return iter;
+}
+inline FieldDef* MessageDef::field_iterator::operator*() const {
+ return upb_msg_iter_field(&iter_);
+}
+inline void MessageDef::field_iterator::operator++() {
+ return upb_msg_field_next(&iter_);
+}
+inline bool MessageDef::field_iterator::operator==(
+ const field_iterator &other) const {
+ return upb_inttable_iter_isequal(&iter_, &other.iter_);
+}
+inline bool MessageDef::field_iterator::operator!=(
+ const field_iterator &other) const {
+ return !(*this == other);
+}
+
+inline MessageDef::const_field_iterator::const_field_iterator(
+ const MessageDef* md) {
+ upb_msg_field_begin(&iter_, md);
+}
+inline MessageDef::const_field_iterator MessageDef::const_field_iterator::end(
+ const MessageDef *md) {
+ MessageDef::const_field_iterator iter(md);
+ upb_msg_field_iter_setdone(&iter.iter_);
+ return iter;
+}
+inline const FieldDef* MessageDef::const_field_iterator::operator*() const {
+ return upb_msg_iter_field(&iter_);
+}
+inline void MessageDef::const_field_iterator::operator++() {
+ return upb_msg_field_next(&iter_);
+}
+inline bool MessageDef::const_field_iterator::operator==(
+ const const_field_iterator &other) const {
+ return upb_inttable_iter_isequal(&iter_, &other.iter_);
+}
+inline bool MessageDef::const_field_iterator::operator!=(
+ const const_field_iterator &other) const {
+ return !(*this == other);
+}
+
+inline MessageDef::oneof_iterator::oneof_iterator(MessageDef* md) {
+ upb_msg_oneof_begin(&iter_, md);
+}
+inline MessageDef::oneof_iterator MessageDef::oneof_iterator::end(
+ MessageDef* md) {
+ MessageDef::oneof_iterator iter(md);
+ upb_msg_oneof_iter_setdone(&iter.iter_);
+ return iter;
+}
+inline OneofDef* MessageDef::oneof_iterator::operator*() const {
+ return upb_msg_iter_oneof(&iter_);
+}
+inline void MessageDef::oneof_iterator::operator++() {
+ return upb_msg_oneof_next(&iter_);
+}
+inline bool MessageDef::oneof_iterator::operator==(
+ const oneof_iterator &other) const {
+ return upb_strtable_iter_isequal(&iter_, &other.iter_);
+}
+inline bool MessageDef::oneof_iterator::operator!=(
+ const oneof_iterator &other) const {
+ return !(*this == other);
+}
+
+inline MessageDef::const_oneof_iterator::const_oneof_iterator(
+ const MessageDef* md) {
+ upb_msg_oneof_begin(&iter_, md);
+}
+inline MessageDef::const_oneof_iterator MessageDef::const_oneof_iterator::end(
+ const MessageDef *md) {
+ MessageDef::const_oneof_iterator iter(md);
+ upb_msg_oneof_iter_setdone(&iter.iter_);
+ return iter;
+}
+inline const OneofDef* MessageDef::const_oneof_iterator::operator*() const {
+ return upb_msg_iter_oneof(&iter_);
+}
+inline void MessageDef::const_oneof_iterator::operator++() {
+ return upb_msg_oneof_next(&iter_);
+}
+inline bool MessageDef::const_oneof_iterator::operator==(
+ const const_oneof_iterator &other) const {
+ return upb_strtable_iter_isequal(&iter_, &other.iter_);
+}
+inline bool MessageDef::const_oneof_iterator::operator!=(
+ const const_oneof_iterator &other) const {
+ return !(*this == other);
+}
+
+inline reffed_ptr<EnumDef> EnumDef::New() {
+ upb_enumdef *e = upb_enumdef_new(&e);
+ return reffed_ptr<EnumDef>(e, &e);
+}
+inline const char* EnumDef::full_name() const {
+ return upb_enumdef_fullname(this);
+}
+inline const char* EnumDef::name() const {
+ return upb_enumdef_name(this);
+}
+inline bool EnumDef::set_full_name(const char* fullname, Status* s) {
+ return upb_enumdef_setfullname(this, fullname, s);
+}
+inline bool EnumDef::set_full_name(const std::string& fullname, Status* s) {
+ return upb_enumdef_setfullname(this, upb_safecstr(fullname), s);
+}
+inline bool EnumDef::Freeze(Status* status) {
+ return upb_enumdef_freeze(this, status);
+}
+inline int32_t EnumDef::default_value() const {
+ return upb_enumdef_default(this);
+}
+inline bool EnumDef::set_default_value(int32_t val, Status* status) {
+ return upb_enumdef_setdefault(this, val, status);
+}
+inline int EnumDef::value_count() const { return upb_enumdef_numvals(this); }
+inline bool EnumDef::AddValue(const char* name, int32_t num, Status* status) {
+ return upb_enumdef_addval(this, name, num, status);
+}
+inline bool EnumDef::AddValue(const std::string& name, int32_t num,
+ Status* status) {
+ return upb_enumdef_addval(this, upb_safecstr(name), num, status);
+}
+inline bool EnumDef::FindValueByName(const char* name, int32_t *num) const {
+ return upb_enumdef_ntoiz(this, name, num);
+}
+inline const char* EnumDef::FindValueByNumber(int32_t num) const {
+ return upb_enumdef_iton(this, num);
+}
+
+inline EnumDef::Iterator::Iterator(const EnumDef* e) {
+ upb_enum_begin(&iter_, e);
+}
+inline int32_t EnumDef::Iterator::number() {
+ return upb_enum_iter_number(&iter_);
+}
+inline const char* EnumDef::Iterator::name() {
+ return upb_enum_iter_name(&iter_);
+}
+inline bool EnumDef::Iterator::Done() { return upb_enum_done(&iter_); }
+inline void EnumDef::Iterator::Next() { return upb_enum_next(&iter_); }
+
+inline reffed_ptr<OneofDef> OneofDef::New() {
+ upb_oneofdef *o = upb_oneofdef_new(&o);
+ return reffed_ptr<OneofDef>(o, &o);
+}
+
+inline const MessageDef* OneofDef::containing_type() const {
+ return upb_oneofdef_containingtype(this);
+}
+inline const char* OneofDef::name() const {
+ return upb_oneofdef_name(this);
+}
+inline bool OneofDef::set_name(const char* name, Status* s) {
+ return upb_oneofdef_setname(this, name, s);
+}
+inline bool OneofDef::set_name(const std::string& name, Status* s) {
+ return upb_oneofdef_setname(this, upb_safecstr(name), s);
+}
+inline int OneofDef::field_count() const {
+ return upb_oneofdef_numfields(this);
+}
+inline bool OneofDef::AddField(FieldDef* field, Status* s) {
+ return upb_oneofdef_addfield(this, field, NULL, s);
+}
+inline bool OneofDef::AddField(const reffed_ptr<FieldDef>& field, Status* s) {
+ return upb_oneofdef_addfield(this, field.get(), NULL, s);
+}
+inline const FieldDef* OneofDef::FindFieldByName(const char* name,
+ size_t len) const {
+ return upb_oneofdef_ntof(this, name, len);
+}
+inline const FieldDef* OneofDef::FindFieldByNumber(uint32_t num) const {
+ return upb_oneofdef_itof(this, num);
+}
+inline OneofDef::iterator OneofDef::begin() { return iterator(this); }
+inline OneofDef::iterator OneofDef::end() { return iterator::end(this); }
+inline OneofDef::const_iterator OneofDef::begin() const {
+ return const_iterator(this);
+}
+inline OneofDef::const_iterator OneofDef::end() const {
+ return const_iterator::end(this);
+}
+
+inline OneofDef::iterator::iterator(OneofDef* o) {
+ upb_oneof_begin(&iter_, o);
+}
+inline OneofDef::iterator OneofDef::iterator::end(OneofDef* o) {
+ OneofDef::iterator iter(o);
+ upb_oneof_iter_setdone(&iter.iter_);
+ return iter;
+}
+inline FieldDef* OneofDef::iterator::operator*() const {
+ return upb_oneof_iter_field(&iter_);
+}
+inline void OneofDef::iterator::operator++() { return upb_oneof_next(&iter_); }
+inline bool OneofDef::iterator::operator==(const iterator &other) const {
+ return upb_inttable_iter_isequal(&iter_, &other.iter_);
+}
+inline bool OneofDef::iterator::operator!=(const iterator &other) const {
+ return !(*this == other);
+}
+
+inline OneofDef::const_iterator::const_iterator(const OneofDef* md) {
+ upb_oneof_begin(&iter_, md);
+}
+inline OneofDef::const_iterator OneofDef::const_iterator::end(
+ const OneofDef *md) {
+ OneofDef::const_iterator iter(md);
+ upb_oneof_iter_setdone(&iter.iter_);
+ return iter;
+}
+inline const FieldDef* OneofDef::const_iterator::operator*() const {
+ return upb_msg_iter_field(&iter_);
+}
+inline void OneofDef::const_iterator::operator++() {
+ return upb_oneof_next(&iter_);
+}
+inline bool OneofDef::const_iterator::operator==(
+ const const_iterator &other) const {
+ return upb_inttable_iter_isequal(&iter_, &other.iter_);
+}
+inline bool OneofDef::const_iterator::operator!=(
+ const const_iterator &other) const {
+ return !(*this == other);
+}
+
+inline reffed_ptr<FileDef> FileDef::New() {
+ upb_filedef *f = upb_filedef_new(&f);
+ return reffed_ptr<FileDef>(f, &f);
+}
+
+inline const char* FileDef::name() const {
+ return upb_filedef_name(this);
+}
+inline bool FileDef::set_name(const char* name, Status* s) {
+ return upb_filedef_setname(this, name, s);
+}
+inline bool FileDef::set_name(const std::string& name, Status* s) {
+ return upb_filedef_setname(this, upb_safecstr(name), s);
+}
+inline const char* FileDef::package() const {
+ return upb_filedef_package(this);
+}
+inline bool FileDef::set_package(const char* package, Status* s) {
+ return upb_filedef_setpackage(this, package, s);
+}
+inline const char* FileDef::phpprefix() const {
+ return upb_filedef_phpprefix(this);
+}
+inline bool FileDef::set_phpprefix(const char* phpprefix, Status* s) {
+ return upb_filedef_setphpprefix(this, phpprefix, s);
+}
+inline int FileDef::def_count() const {
+ return upb_filedef_defcount(this);
+}
+inline const Def* FileDef::def(int index) const {
+ return upb_filedef_def(this, index);
+}
+inline Def* FileDef::def(int index) {
+ return const_cast<Def*>(upb_filedef_def(this, index));
+}
+inline int FileDef::dependency_count() const {
+ return upb_filedef_depcount(this);
+}
+inline const FileDef* FileDef::dependency(int index) const {
+ return upb_filedef_dep(this, index);
+}
+inline bool FileDef::AddDef(Def* def, Status* s) {
+ return upb_filedef_adddef(this, def, NULL, s);
+}
+inline bool FileDef::AddMessage(MessageDef* m, Status* s) {
+ return upb_filedef_addmsg(this, m, NULL, s);
+}
+inline bool FileDef::AddEnum(EnumDef* e, Status* s) {
+ return upb_filedef_addenum(this, e, NULL, s);
+}
+inline bool FileDef::AddExtension(FieldDef* f, Status* s) {
+ return upb_filedef_addext(this, f, NULL, s);
+}
+inline bool FileDef::AddDependency(const FileDef* file) {
+ return upb_filedef_adddep(this, file);
+}
+
+} /* namespace upb */
+#endif
+
+#endif /* UPB_DEF_H_ */
+/*
+** This file contains definitions of structs that should be considered private
+** and NOT stable across versions of upb.
+**
+** The only reason they are declared here and not in .c files is to allow upb
+** and the application (if desired) to embed statically-initialized instances
+** of structures like defs.
+**
+** If you include this file, all guarantees of ABI compatibility go out the
+** window! Any code that includes this file needs to recompile against the
+** exact same version of upb that they are linking against.
+**
+** You also need to recompile if you change the value of the UPB_DEBUG_REFS
+** flag.
+*/
+
+
+#ifndef UPB_STATICINIT_H_
+#define UPB_STATICINIT_H_
+
+#ifdef __cplusplus
+/* Because of how we do our typedefs, this header can't be included from C++. */
+#error This file cannot be included from C++
+#endif
+
+/* upb_refcounted *************************************************************/
+
+
+/* upb_def ********************************************************************/
+
+struct upb_def {
+ upb_refcounted base;
+
+ const char *fullname;
+ const upb_filedef* file;
+ char type; /* A upb_deftype_t (char to save space) */
+
+ /* Used as a flag during the def's mutable stage. Must be false unless
+ * it is currently being used by a function on the stack. This allows
+ * us to easily determine which defs were passed into the function's
+ * current invocation. */
+ bool came_from_user;
+};
+
+#define UPB_DEF_INIT(name, type, vtbl, refs, ref2s) \
+ { UPB_REFCOUNT_INIT(vtbl, refs, ref2s), name, NULL, type, false }
+
+
+/* upb_fielddef ***************************************************************/
+
+struct upb_fielddef {
+ upb_def base;
+
+ union {
+ int64_t sint;
+ uint64_t uint;
+ double dbl;
+ float flt;
+ void *bytes;
+ } defaultval;
+ union {
+ const upb_msgdef *def; /* If !msg_is_symbolic. */
+ char *name; /* If msg_is_symbolic. */
+ } msg;
+ union {
+ const upb_def *def; /* If !subdef_is_symbolic. */
+ char *name; /* If subdef_is_symbolic. */
+ } sub; /* The msgdef or enumdef for this field, if upb_hassubdef(f). */
+ bool subdef_is_symbolic;
+ bool msg_is_symbolic;
+ const upb_oneofdef *oneof;
+ bool default_is_string;
+ bool type_is_set_; /* False until type is explicitly set. */
+ bool is_extension_;
+ bool lazy_;
+ bool packed_;
+ upb_intfmt_t intfmt;
+ bool tagdelim;
+ upb_fieldtype_t type_;
+ upb_label_t label_;
+ uint32_t number_;
+ uint32_t selector_base; /* Used to index into a upb::Handlers table. */
+ uint32_t index_;
+};
+
+extern const struct upb_refcounted_vtbl upb_fielddef_vtbl;
+
+#define UPB_FIELDDEF_INIT(label, type, intfmt, tagdelim, is_extension, lazy, \
+ packed, name, num, msgdef, subdef, selector_base, \
+ index, defaultval, refs, ref2s) \
+ { \
+ UPB_DEF_INIT(name, UPB_DEF_FIELD, &upb_fielddef_vtbl, refs, ref2s), \
+ defaultval, {msgdef}, {subdef}, NULL, false, false, \
+ type == UPB_TYPE_STRING || type == UPB_TYPE_BYTES, true, is_extension, \
+ lazy, packed, intfmt, tagdelim, type, label, num, selector_base, index \
+ }
+
+
+/* upb_msgdef *****************************************************************/
+
+struct upb_msgdef {
+ upb_def base;
+
+ size_t selector_count;
+ uint32_t submsg_field_count;
+
+ /* Tables for looking up fields by number and name. */
+ upb_inttable itof; /* int to field */
+ upb_strtable ntof; /* name to field/oneof */
+
+ /* Is this a map-entry message? */
+ bool map_entry;
+
+ /* Whether this message has proto2 or proto3 semantics. */
+ upb_syntax_t syntax;
+
+ /* TODO(haberman): proper extension ranges (there can be multiple). */
+};
+
+extern const struct upb_refcounted_vtbl upb_msgdef_vtbl;
+
+/* TODO: also support static initialization of the oneofs table. This will be
+ * needed if we compile in descriptors that contain oneofs. */
+#define UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, \
+ map_entry, syntax, refs, ref2s) \
+ { \
+ UPB_DEF_INIT(name, UPB_DEF_MSG, &upb_fielddef_vtbl, refs, ref2s), \
+ selector_count, submsg_field_count, itof, ntof, map_entry, syntax \
+ }
+
+
+/* upb_enumdef ****************************************************************/
+
+struct upb_enumdef {
+ upb_def base;
+
+ upb_strtable ntoi;
+ upb_inttable iton;
+ int32_t defaultval;
+};
+
+extern const struct upb_refcounted_vtbl upb_enumdef_vtbl;
+
+#define UPB_ENUMDEF_INIT(name, ntoi, iton, defaultval, refs, ref2s) \
+ { UPB_DEF_INIT(name, UPB_DEF_ENUM, &upb_enumdef_vtbl, refs, ref2s), ntoi, \
+ iton, defaultval }
+
+
+/* upb_oneofdef ***************************************************************/
+
+struct upb_oneofdef {
+ upb_refcounted base;
+
+ uint32_t index; /* Index within oneofs. */
+ const char *name;
+ upb_strtable ntof;
+ upb_inttable itof;
+ const upb_msgdef *parent;
+};
+
+extern const struct upb_refcounted_vtbl upb_oneofdef_vtbl;
+
+#define UPB_ONEOFDEF_INIT(name, ntof, itof, refs, ref2s) \
+ { UPB_REFCOUNT_INIT(&upb_oneofdef_vtbl, refs, ref2s), 0, name, ntof, itof }
+
+
+/* upb_symtab *****************************************************************/
+
+struct upb_symtab {
+ upb_refcounted base;
+
+ upb_strtable symtab;
+};
+
+struct upb_filedef {
+ upb_refcounted base;
+
+ const char *name;
+ const char *package;
+ const char *phpprefix;
+ upb_syntax_t syntax;
+
+ upb_inttable defs;
+ upb_inttable deps;
+};
+
+extern const struct upb_refcounted_vtbl upb_filedef_vtbl;
+
+#endif /* UPB_STATICINIT_H_ */
+/*
+** upb::Handlers (upb_handlers)
+**
+** A upb_handlers is like a virtual table for a upb_msgdef. Each field of the
+** message can have associated functions that will be called when we are
+** parsing or visiting a stream of data. This is similar to how handlers work
+** in SAX (the Simple API for XML).
+**
+** The handlers have no idea where the data is coming from, so a single set of
+** handlers could be used with two completely different data sources (for
+** example, a parser and a visitor over in-memory objects). This decoupling is
+** the most important feature of upb, because it allows parsers and serializers
+** to be highly reusable.
+**
+** This is a mixed C/C++ interface that offers a full API to both languages.
+** See the top-level README for more information.
+*/
+
+#ifndef UPB_HANDLERS_H
+#define UPB_HANDLERS_H
+
+
+#ifdef __cplusplus
+namespace upb {
+class BufferHandle;
+class BytesHandler;
+class HandlerAttributes;
+class Handlers;
+template <class T> class Handler;
+template <class T> struct CanonicalType;
+} /* namespace upb */
+#endif
+
+UPB_DECLARE_TYPE(upb::BufferHandle, upb_bufhandle)
+UPB_DECLARE_TYPE(upb::BytesHandler, upb_byteshandler)
+UPB_DECLARE_TYPE(upb::HandlerAttributes, upb_handlerattr)
+UPB_DECLARE_DERIVED_TYPE(upb::Handlers, upb::RefCounted,
+ upb_handlers, upb_refcounted)
+
+/* The maximum depth that the handler graph can have. This is a resource limit
+ * for the C stack since we sometimes need to recursively traverse the graph.
+ * Cycles are ok; the traversal will stop when it detects a cycle, but we must
+ * hit the cycle before the maximum depth is reached.
+ *
+ * If having a single static limit is too inflexible, we can add another variant
+ * of Handlers::Freeze that allows specifying this as a parameter. */
+#define UPB_MAX_HANDLER_DEPTH 64
+
+/* All the different types of handlers that can be registered.
+ * Only needed for the advanced functions in upb::Handlers. */
+typedef enum {
+ UPB_HANDLER_INT32,
+ UPB_HANDLER_INT64,
+ UPB_HANDLER_UINT32,
+ UPB_HANDLER_UINT64,
+ UPB_HANDLER_FLOAT,
+ UPB_HANDLER_DOUBLE,
+ UPB_HANDLER_BOOL,
+ UPB_HANDLER_STARTSTR,
+ UPB_HANDLER_STRING,
+ UPB_HANDLER_ENDSTR,
+ UPB_HANDLER_STARTSUBMSG,
+ UPB_HANDLER_ENDSUBMSG,
+ UPB_HANDLER_STARTSEQ,
+ UPB_HANDLER_ENDSEQ
+} upb_handlertype_t;
+
+#define UPB_HANDLER_MAX (UPB_HANDLER_ENDSEQ+1)
+
+#define UPB_BREAK NULL
+
+/* A convenient definition for when no closure is needed. */
+extern char _upb_noclosure;
+#define UPB_NO_CLOSURE &_upb_noclosure
+
+/* A selector refers to a specific field handler in the Handlers object
+ * (for example: the STARTSUBMSG handler for field "field15"). */
+typedef int32_t upb_selector_t;
+
+UPB_BEGIN_EXTERN_C
+
+/* Forward-declares for C inline accessors. We need to declare these here
+ * so we can "friend" them in the class declarations in C++. */
+UPB_INLINE upb_func *upb_handlers_gethandler(const upb_handlers *h,
+ upb_selector_t s);
+UPB_INLINE const void *upb_handlerattr_handlerdata(const upb_handlerattr *attr);
+UPB_INLINE const void *upb_handlers_gethandlerdata(const upb_handlers *h,
+ upb_selector_t s);
+
+UPB_INLINE void upb_bufhandle_init(upb_bufhandle *h);
+UPB_INLINE void upb_bufhandle_setobj(upb_bufhandle *h, const void *obj,
+ const void *type);
+UPB_INLINE void upb_bufhandle_setbuf(upb_bufhandle *h, const char *buf,
+ size_t ofs);
+UPB_INLINE const void *upb_bufhandle_obj(const upb_bufhandle *h);
+UPB_INLINE const void *upb_bufhandle_objtype(const upb_bufhandle *h);
+UPB_INLINE const char *upb_bufhandle_buf(const upb_bufhandle *h);
+
+UPB_END_EXTERN_C
+
+
+/* Static selectors for upb::Handlers. */
+#define UPB_STARTMSG_SELECTOR 0
+#define UPB_ENDMSG_SELECTOR 1
+#define UPB_STATIC_SELECTOR_COUNT 2
+
+/* Static selectors for upb::BytesHandler. */
+#define UPB_STARTSTR_SELECTOR 0
+#define UPB_STRING_SELECTOR 1
+#define UPB_ENDSTR_SELECTOR 2
+
+typedef void upb_handlerfree(void *d);
+
+#ifdef __cplusplus
+
+/* A set of attributes that accompanies a handler's function pointer. */
+class upb::HandlerAttributes {
+ public:
+ HandlerAttributes();
+ ~HandlerAttributes();
+
+ /* Sets the handler data that will be passed as the second parameter of the
+ * handler. To free this pointer when the handlers are freed, call
+ * Handlers::AddCleanup(). */
+ bool SetHandlerData(const void *handler_data);
+ const void* handler_data() const;
+
+ /* Use this to specify the type of the closure. This will be checked against
+ * all other closure types for handler that use the same closure.
+ * Registration will fail if this does not match all other non-NULL closure
+ * types. */
+ bool SetClosureType(const void *closure_type);
+ const void* closure_type() const;
+
+ /* Use this to specify the type of the returned closure. Only used for
+ * Start*{String,SubMessage,Sequence} handlers. This must match the closure
+ * type of any handlers that use it (for example, the StringBuf handler must
+ * match the closure returned from StartString). */
+ bool SetReturnClosureType(const void *return_closure_type);
+ const void* return_closure_type() const;
+
+ /* Set to indicate that the handler always returns "ok" (either "true" or a
+ * non-NULL closure). This is a hint that can allow code generators to
+ * generate more efficient code. */
+ bool SetAlwaysOk(bool always_ok);
+ bool always_ok() const;
+
+ private:
+ friend UPB_INLINE const void * ::upb_handlerattr_handlerdata(
+ const upb_handlerattr *attr);
+#else
+struct upb_handlerattr {
+#endif
+ const void *handler_data_;
+ const void *closure_type_;
+ const void *return_closure_type_;
+ bool alwaysok_;
+};
+
+#define UPB_HANDLERATTR_INITIALIZER {NULL, NULL, NULL, false}
+
+typedef struct {
+ upb_func *func;
+
+ /* It is wasteful to include the entire attributes here:
+ *
+ * * Some of the information is redundant (like storing the closure type
+ * separately for each handler that must match).
+ * * Some of the info is only needed prior to freeze() (like closure types).
+ * * alignment padding wastes a lot of space for alwaysok_.
+ *
+ * If/when the size and locality of handlers is an issue, we can optimize this
+ * not to store the entire attr like this. We do not expose the table's
+ * layout to allow this optimization in the future. */
+ upb_handlerattr attr;
+} upb_handlers_tabent;
+
+#ifdef __cplusplus
+
+/* Extra information about a buffer that is passed to a StringBuf handler.
+ * TODO(haberman): allow the handle to be pinned so that it will outlive
+ * the handler invocation. */
+class upb::BufferHandle {
+ public:
+ BufferHandle();
+ ~BufferHandle();
+
+ /* The beginning of the buffer. This may be different than the pointer
+ * passed to a StringBuf handler because the handler may receive data
+ * that is from the middle or end of a larger buffer. */
+ const char* buffer() const;
+
+ /* The offset within the attached object where this buffer begins. Only
+ * meaningful if there is an attached object. */
+ size_t object_offset() const;
+
+ /* Note that object_offset is the offset of "buf" within the attached
+ * object. */
+ void SetBuffer(const char* buf, size_t object_offset);
+
+ /* The BufferHandle can have an "attached object", which can be used to
+ * tunnel through a pointer to the buffer's underlying representation. */
+ template <class T>
+ void SetAttachedObject(const T* obj);
+
+ /* Returns NULL if the attached object is not of this type. */
+ template <class T>
+ const T* GetAttachedObject() const;
+
+ private:
+ friend UPB_INLINE void ::upb_bufhandle_init(upb_bufhandle *h);
+ friend UPB_INLINE void ::upb_bufhandle_setobj(upb_bufhandle *h,
+ const void *obj,
+ const void *type);
+ friend UPB_INLINE void ::upb_bufhandle_setbuf(upb_bufhandle *h,
+ const char *buf, size_t ofs);
+ friend UPB_INLINE const void* ::upb_bufhandle_obj(const upb_bufhandle *h);
+ friend UPB_INLINE const void* ::upb_bufhandle_objtype(
+ const upb_bufhandle *h);
+ friend UPB_INLINE const char* ::upb_bufhandle_buf(const upb_bufhandle *h);
+#else
+struct upb_bufhandle {
+#endif
+ const char *buf_;
+ const void *obj_;
+ const void *objtype_;
+ size_t objofs_;
+};
+
+#ifdef __cplusplus
+
+/* A upb::Handlers object represents the set of handlers associated with a
+ * message in the graph of messages. You can think of it as a big virtual
+ * table with functions corresponding to all the events that can fire while
+ * parsing or visiting a message of a specific type.
+ *
+ * Any handlers that are not set behave as if they had successfully consumed
+ * the value. Any unset Start* handlers will propagate their closure to the
+ * inner frame.
+ *
+ * The easiest way to create the *Handler objects needed by the Set* methods is
+ * with the UpbBind() and UpbMakeHandler() macros; see below. */
+class upb::Handlers {
+ public:
+ typedef upb_selector_t Selector;
+ typedef upb_handlertype_t Type;
+
+ typedef Handler<void *(*)(void *, const void *)> StartFieldHandler;
+ typedef Handler<bool (*)(void *, const void *)> EndFieldHandler;
+ typedef Handler<bool (*)(void *, const void *)> StartMessageHandler;
+ typedef Handler<bool (*)(void *, const void *, Status*)> EndMessageHandler;
+ typedef Handler<void *(*)(void *, const void *, size_t)> StartStringHandler;
+ typedef Handler<size_t (*)(void *, const void *, const char *, size_t,
+ const BufferHandle *)> StringHandler;
+
+ template <class T> struct ValueHandler {
+ typedef Handler<bool(*)(void *, const void *, T)> H;
+ };
+
+ typedef ValueHandler<int32_t>::H Int32Handler;
+ typedef ValueHandler<int64_t>::H Int64Handler;
+ typedef ValueHandler<uint32_t>::H UInt32Handler;
+ typedef ValueHandler<uint64_t>::H UInt64Handler;
+ typedef ValueHandler<float>::H FloatHandler;
+ typedef ValueHandler<double>::H DoubleHandler;
+ typedef ValueHandler<bool>::H BoolHandler;
+
+ /* Any function pointer can be converted to this and converted back to its
+ * correct type. */
+ typedef void GenericFunction();
+
+ typedef void HandlersCallback(const void *closure, upb_handlers *h);
+
+ /* Returns a new handlers object for the given frozen msgdef.
+ * Returns NULL if memory allocation failed. */
+ static reffed_ptr<Handlers> New(const MessageDef *m);
+
+ /* Convenience function for registering a graph of handlers that mirrors the
+ * graph of msgdefs for some message. For "m" and all its children a new set
+ * of handlers will be created and the given callback will be invoked,
+ * allowing the client to register handlers for this message. Note that any
+ * subhandlers set by the callback will be overwritten. */
+ static reffed_ptr<const Handlers> NewFrozen(const MessageDef *m,
+ HandlersCallback *callback,
+ const void *closure);
+
+ /* Functionality from upb::RefCounted. */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ /* All handler registration functions return bool to indicate success or
+ * failure; details about failures are stored in this status object. If a
+ * failure does occur, it must be cleared before the Handlers are frozen,
+ * otherwise the freeze() operation will fail. The functions may *only* be
+ * used while the Handlers are mutable. */
+ const Status* status();
+ void ClearError();
+
+ /* Call to freeze these Handlers. Requires that any SubHandlers are already
+ * frozen. For cycles, you must use the static version below and freeze the
+ * whole graph at once. */
+ bool Freeze(Status* s);
+
+ /* Freezes the given set of handlers. You may not freeze a handler without
+ * also freezing any handlers they point to. */
+ static bool Freeze(Handlers*const* handlers, int n, Status* s);
+ static bool Freeze(const std::vector<Handlers*>& handlers, Status* s);
+
+ /* Returns the msgdef associated with this handlers object. */
+ const MessageDef* message_def() const;
+
+ /* Adds the given pointer and function to the list of cleanup functions that
+ * will be run when these handlers are freed. If this pointer has previously
+ * been registered, the function returns false and does nothing. */
+ bool AddCleanup(void *ptr, upb_handlerfree *cleanup);
+
+ /* Sets the startmsg handler for the message, which is defined as follows:
+ *
+ * bool startmsg(MyType* closure) {
+ * // Called when the message begins. Returns true if processing should
+ * // continue.
+ * return true;
+ * }
+ */
+ bool SetStartMessageHandler(const StartMessageHandler& handler);
+
+ /* Sets the endmsg handler for the message, which is defined as follows:
+ *
+ * bool endmsg(MyType* closure, upb_status *status) {
+ * // Called when processing of this message ends, whether in success or
+ * // failure. "status" indicates the final status of processing, and
+ * // can also be modified in-place to update the final status.
+ * }
+ */
+ bool SetEndMessageHandler(const EndMessageHandler& handler);
+
+ /* Sets the value handler for the given field, which is defined as follows
+ * (this is for an int32 field; other field types will pass their native
+ * C/C++ type for "val"):
+ *
+ * bool OnValue(MyClosure* c, const MyHandlerData* d, int32_t val) {
+ * // Called when the field's value is encountered. "d" contains
+ * // whatever data was bound to this field when it was registered.
+ * // Returns true if processing should continue.
+ * return true;
+ * }
+ *
+ * handers->SetInt32Handler(f, UpbBind(OnValue, new MyHandlerData(...)));
+ *
+ * The value type must exactly match f->type().
+ * For example, a handler that takes an int32_t parameter may only be used for
+ * fields of type UPB_TYPE_INT32 and UPB_TYPE_ENUM.
+ *
+ * Returns false if the handler failed to register; in this case the cleanup
+ * handler (if any) will be called immediately.
+ */
+ bool SetInt32Handler (const FieldDef* f, const Int32Handler& h);
+ bool SetInt64Handler (const FieldDef* f, const Int64Handler& h);
+ bool SetUInt32Handler(const FieldDef* f, const UInt32Handler& h);
+ bool SetUInt64Handler(const FieldDef* f, const UInt64Handler& h);
+ bool SetFloatHandler (const FieldDef* f, const FloatHandler& h);
+ bool SetDoubleHandler(const FieldDef* f, const DoubleHandler& h);
+ bool SetBoolHandler (const FieldDef* f, const BoolHandler& h);
+
+ /* Like the previous, but templated on the type on the value (ie. int32).
+ * This is mostly useful to call from other templates. To call this you must
+ * specify the template parameter explicitly, ie:
+ * h->SetValueHandler<T>(f, UpbBind(MyHandler<T>, MyData)); */
+ template <class T>
+ bool SetValueHandler(
+ const FieldDef *f,
+ const typename ValueHandler<typename CanonicalType<T>::Type>::H& handler);
+
+ /* Sets handlers for a string field, which are defined as follows:
+ *
+ * MySubClosure* startstr(MyClosure* c, const MyHandlerData* d,
+ * size_t size_hint) {
+ * // Called when a string value begins. The return value indicates the
+ * // closure for the string. "size_hint" indicates the size of the
+ * // string if it is known, however if the string is length-delimited
+ * // and the end-of-string is not available size_hint will be zero.
+ * // This case is indistinguishable from the case where the size is
+ * // known to be zero.
+ * //
+ * // TODO(haberman): is it important to distinguish these cases?
+ * // If we had ssize_t as a type we could make -1 "unknown", but
+ * // ssize_t is POSIX (not ANSI) and therefore less portable.
+ * // In practice I suspect it won't be important to distinguish.
+ * return closure;
+ * }
+ *
+ * size_t str(MyClosure* closure, const MyHandlerData* d,
+ * const char *str, size_t len) {
+ * // Called for each buffer of string data; the multiple physical buffers
+ * // are all part of the same logical string. The return value indicates
+ * // how many bytes were consumed. If this number is less than "len",
+ * // this will also indicate that processing should be halted for now,
+ * // like returning false or UPB_BREAK from any other callback. If
+ * // number is greater than "len", the excess bytes will be skipped over
+ * // and not passed to the callback.
+ * return len;
+ * }
+ *
+ * bool endstr(MyClosure* c, const MyHandlerData* d) {
+ * // Called when a string value ends. Return value indicates whether
+ * // processing should continue.
+ * return true;
+ * }
+ */
+ bool SetStartStringHandler(const FieldDef* f, const StartStringHandler& h);
+ bool SetStringHandler(const FieldDef* f, const StringHandler& h);
+ bool SetEndStringHandler(const FieldDef* f, const EndFieldHandler& h);
+
+ /* Sets the startseq handler, which is defined as follows:
+ *
+ * MySubClosure *startseq(MyClosure* c, const MyHandlerData* d) {
+ * // Called when a sequence (repeated field) begins. The returned
+ * // pointer indicates the closure for the sequence (or UPB_BREAK
+ * // to interrupt processing).
+ * return closure;
+ * }
+ *
+ * h->SetStartSequenceHandler(f, UpbBind(startseq, new MyHandlerData(...)));
+ *
+ * Returns "false" if "f" does not belong to this message or is not a
+ * repeated field.
+ */
+ bool SetStartSequenceHandler(const FieldDef* f, const StartFieldHandler& h);
+
+ /* Sets the startsubmsg handler for the given field, which is defined as
+ * follows:
+ *
+ * MySubClosure* startsubmsg(MyClosure* c, const MyHandlerData* d) {
+ * // Called when a submessage begins. The returned pointer indicates the
+ * // closure for the sequence (or UPB_BREAK to interrupt processing).
+ * return closure;
+ * }
+ *
+ * h->SetStartSubMessageHandler(f, UpbBind(startsubmsg,
+ * new MyHandlerData(...)));
+ *
+ * Returns "false" if "f" does not belong to this message or is not a
+ * submessage/group field.
+ */
+ bool SetStartSubMessageHandler(const FieldDef* f, const StartFieldHandler& h);
+
+ /* Sets the endsubmsg handler for the given field, which is defined as
+ * follows:
+ *
+ * bool endsubmsg(MyClosure* c, const MyHandlerData* d) {
+ * // Called when a submessage ends. Returns true to continue processing.
+ * return true;
+ * }
+ *
+ * Returns "false" if "f" does not belong to this message or is not a
+ * submessage/group field.
+ */
+ bool SetEndSubMessageHandler(const FieldDef *f, const EndFieldHandler &h);
+
+ /* Starts the endsubseq handler for the given field, which is defined as
+ * follows:
+ *
+ * bool endseq(MyClosure* c, const MyHandlerData* d) {
+ * // Called when a sequence ends. Returns true continue processing.
+ * return true;
+ * }
+ *
+ * Returns "false" if "f" does not belong to this message or is not a
+ * repeated field.
+ */
+ bool SetEndSequenceHandler(const FieldDef* f, const EndFieldHandler& h);
+
+ /* Sets or gets the object that specifies handlers for the given field, which
+ * must be a submessage or group. Returns NULL if no handlers are set. */
+ bool SetSubHandlers(const FieldDef* f, const Handlers* sub);
+ const Handlers* GetSubHandlers(const FieldDef* f) const;
+
+ /* Equivalent to GetSubHandlers, but takes the STARTSUBMSG selector for the
+ * field. */
+ const Handlers* GetSubHandlers(Selector startsubmsg) const;
+
+ /* A selector refers to a specific field handler in the Handlers object
+ * (for example: the STARTSUBMSG handler for field "field15").
+ * On success, returns true and stores the selector in "s".
+ * If the FieldDef or Type are invalid, returns false.
+ * The returned selector is ONLY valid for Handlers whose MessageDef
+ * contains this FieldDef. */
+ static bool GetSelector(const FieldDef* f, Type type, Selector* s);
+
+ /* Given a START selector of any kind, returns the corresponding END selector. */
+ static Selector GetEndSelector(Selector start_selector);
+
+ /* Returns the function pointer for this handler. It is the client's
+ * responsibility to cast to the correct function type before calling it. */
+ GenericFunction* GetHandler(Selector selector);
+
+ /* Sets the given attributes to the attributes for this selector. */
+ bool GetAttributes(Selector selector, HandlerAttributes* attr);
+
+ /* Returns the handler data that was registered with this handler. */
+ const void* GetHandlerData(Selector selector);
+
+ /* Could add any of the following functions as-needed, with some minor
+ * implementation changes:
+ *
+ * const FieldDef* GetFieldDef(Selector selector);
+ * static bool IsSequence(Selector selector); */
+
+ private:
+ UPB_DISALLOW_POD_OPS(Handlers, upb::Handlers)
+
+ friend UPB_INLINE GenericFunction *::upb_handlers_gethandler(
+ const upb_handlers *h, upb_selector_t s);
+ friend UPB_INLINE const void *::upb_handlers_gethandlerdata(
+ const upb_handlers *h, upb_selector_t s);
+#else
+struct upb_handlers {
+#endif
+ upb_refcounted base;
+
+ const upb_msgdef *msg;
+ const upb_handlers **sub;
+ const void *top_closure_type;
+ upb_inttable cleanup_;
+ upb_status status_; /* Used only when mutable. */
+ upb_handlers_tabent table[1]; /* Dynamically-sized field handler array. */
+};
+
+#ifdef __cplusplus
+
+namespace upb {
+
+/* Convenience macros for creating a Handler object that is wrapped with a
+ * type-safe wrapper function that converts the "void*" parameters/returns
+ * of the underlying C API into nice C++ function.
+ *
+ * Sample usage:
+ * void OnValue1(MyClosure* c, const MyHandlerData* d, int32_t val) {
+ * // do stuff ...
+ * }
+ *
+ * // Handler that doesn't need any data bound to it.
+ * void OnValue2(MyClosure* c, int32_t val) {
+ * // do stuff ...
+ * }
+ *
+ * // Handler that returns bool so it can return failure if necessary.
+ * bool OnValue3(MyClosure* c, int32_t val) {
+ * // do stuff ...
+ * return ok;
+ * }
+ *
+ * // Member function handler.
+ * class MyClosure {
+ * public:
+ * void OnValue(int32_t val) {
+ * // do stuff ...
+ * }
+ * };
+ *
+ * // Takes ownership of the MyHandlerData.
+ * handlers->SetInt32Handler(f1, UpbBind(OnValue1, new MyHandlerData(...)));
+ * handlers->SetInt32Handler(f2, UpbMakeHandler(OnValue2));
+ * handlers->SetInt32Handler(f1, UpbMakeHandler(OnValue3));
+ * handlers->SetInt32Handler(f2, UpbMakeHandler(&MyClosure::OnValue));
+ */
+
+#ifdef UPB_CXX11
+
+/* In C++11, the "template" disambiguator can appear even outside templates,
+ * so all calls can safely use this pair of macros. */
+
+#define UpbMakeHandler(f) upb::MatchFunc(f).template GetFunc<f>()
+
+/* We have to be careful to only evaluate "d" once. */
+#define UpbBind(f, d) upb::MatchFunc(f).template GetFunc<f>((d))
+
+#else
+
+/* Prior to C++11, the "template" disambiguator may only appear inside a
+ * template, so the regular macro must not use "template" */
+
+#define UpbMakeHandler(f) upb::MatchFunc(f).GetFunc<f>()
+
+#define UpbBind(f, d) upb::MatchFunc(f).GetFunc<f>((d))
+
+#endif /* UPB_CXX11 */
+
+/* This macro must be used in C++98 for calls from inside a template. But we
+ * define this variant in all cases; code that wants to be compatible with both
+ * C++98 and C++11 should always use this macro when calling from a template. */
+#define UpbMakeHandlerT(f) upb::MatchFunc(f).template GetFunc<f>()
+
+/* We have to be careful to only evaluate "d" once. */
+#define UpbBindT(f, d) upb::MatchFunc(f).template GetFunc<f>((d))
+
+/* Handler: a struct that contains the (handler, data, deleter) tuple that is
+ * used to register all handlers. Users can Make() these directly but it's
+ * more convenient to use the UpbMakeHandler/UpbBind macros above. */
+template <class T> class Handler {
+ public:
+ /* The underlying, handler function signature that upb uses internally. */
+ typedef T FuncPtr;
+
+ /* Intentionally implicit. */
+ template <class F> Handler(F func);
+ ~Handler();
+
+ private:
+ void AddCleanup(Handlers* h) const {
+ if (cleanup_func_) {
+ bool ok = h->AddCleanup(cleanup_data_, cleanup_func_);
+ UPB_ASSERT(ok);
+ }
+ }
+
+ UPB_DISALLOW_COPY_AND_ASSIGN(Handler)
+ friend class Handlers;
+ FuncPtr handler_;
+ mutable HandlerAttributes attr_;
+ mutable bool registered_;
+ void *cleanup_data_;
+ upb_handlerfree *cleanup_func_;
+};
+
+} /* namespace upb */
+
+#endif /* __cplusplus */
+
+UPB_BEGIN_EXTERN_C
+
+/* Native C API. */
+
+/* Handler function typedefs. */
+typedef bool upb_startmsg_handlerfunc(void *c, const void*);
+typedef bool upb_endmsg_handlerfunc(void *c, const void *, upb_status *status);
+typedef void* upb_startfield_handlerfunc(void *c, const void *hd);
+typedef bool upb_endfield_handlerfunc(void *c, const void *hd);
+typedef bool upb_int32_handlerfunc(void *c, const void *hd, int32_t val);
+typedef bool upb_int64_handlerfunc(void *c, const void *hd, int64_t val);
+typedef bool upb_uint32_handlerfunc(void *c, const void *hd, uint32_t val);
+typedef bool upb_uint64_handlerfunc(void *c, const void *hd, uint64_t val);
+typedef bool upb_float_handlerfunc(void *c, const void *hd, float val);
+typedef bool upb_double_handlerfunc(void *c, const void *hd, double val);
+typedef bool upb_bool_handlerfunc(void *c, const void *hd, bool val);
+typedef void *upb_startstr_handlerfunc(void *c, const void *hd,
+ size_t size_hint);
+typedef size_t upb_string_handlerfunc(void *c, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle* handle);
+
+/* upb_bufhandle */
+size_t upb_bufhandle_objofs(const upb_bufhandle *h);
+
+/* upb_handlerattr */
+void upb_handlerattr_init(upb_handlerattr *attr);
+void upb_handlerattr_uninit(upb_handlerattr *attr);
+
+bool upb_handlerattr_sethandlerdata(upb_handlerattr *attr, const void *hd);
+bool upb_handlerattr_setclosuretype(upb_handlerattr *attr, const void *type);
+const void *upb_handlerattr_closuretype(const upb_handlerattr *attr);
+bool upb_handlerattr_setreturnclosuretype(upb_handlerattr *attr,
+ const void *type);
+const void *upb_handlerattr_returnclosuretype(const upb_handlerattr *attr);
+bool upb_handlerattr_setalwaysok(upb_handlerattr *attr, bool alwaysok);
+bool upb_handlerattr_alwaysok(const upb_handlerattr *attr);
+
+UPB_INLINE const void *upb_handlerattr_handlerdata(
+ const upb_handlerattr *attr) {
+ return attr->handler_data_;
+}
+
+/* upb_handlers */
+typedef void upb_handlers_callback(const void *closure, upb_handlers *h);
+upb_handlers *upb_handlers_new(const upb_msgdef *m,
+ const void *owner);
+const upb_handlers *upb_handlers_newfrozen(const upb_msgdef *m,
+ const void *owner,
+ upb_handlers_callback *callback,
+ const void *closure);
+
+/* Include refcounted methods like upb_handlers_ref(). */
+UPB_REFCOUNTED_CMETHODS(upb_handlers, upb_handlers_upcast)
+
+const upb_status *upb_handlers_status(upb_handlers *h);
+void upb_handlers_clearerr(upb_handlers *h);
+const upb_msgdef *upb_handlers_msgdef(const upb_handlers *h);
+bool upb_handlers_addcleanup(upb_handlers *h, void *p, upb_handlerfree *hfree);
+
+bool upb_handlers_setstartmsg(upb_handlers *h, upb_startmsg_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setendmsg(upb_handlers *h, upb_endmsg_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setint32(upb_handlers *h, const upb_fielddef *f,
+ upb_int32_handlerfunc *func, upb_handlerattr *attr);
+bool upb_handlers_setint64(upb_handlers *h, const upb_fielddef *f,
+ upb_int64_handlerfunc *func, upb_handlerattr *attr);
+bool upb_handlers_setuint32(upb_handlers *h, const upb_fielddef *f,
+ upb_uint32_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setuint64(upb_handlers *h, const upb_fielddef *f,
+ upb_uint64_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setfloat(upb_handlers *h, const upb_fielddef *f,
+ upb_float_handlerfunc *func, upb_handlerattr *attr);
+bool upb_handlers_setdouble(upb_handlers *h, const upb_fielddef *f,
+ upb_double_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setbool(upb_handlers *h, const upb_fielddef *f,
+ upb_bool_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setstartstr(upb_handlers *h, const upb_fielddef *f,
+ upb_startstr_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setstring(upb_handlers *h, const upb_fielddef *f,
+ upb_string_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setendstr(upb_handlers *h, const upb_fielddef *f,
+ upb_endfield_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setstartseq(upb_handlers *h, const upb_fielddef *f,
+ upb_startfield_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setstartsubmsg(upb_handlers *h, const upb_fielddef *f,
+ upb_startfield_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setendsubmsg(upb_handlers *h, const upb_fielddef *f,
+ upb_endfield_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setendseq(upb_handlers *h, const upb_fielddef *f,
+ upb_endfield_handlerfunc *func,
+ upb_handlerattr *attr);
+
+bool upb_handlers_setsubhandlers(upb_handlers *h, const upb_fielddef *f,
+ const upb_handlers *sub);
+const upb_handlers *upb_handlers_getsubhandlers(const upb_handlers *h,
+ const upb_fielddef *f);
+const upb_handlers *upb_handlers_getsubhandlers_sel(const upb_handlers *h,
+ upb_selector_t sel);
+
+UPB_INLINE upb_func *upb_handlers_gethandler(const upb_handlers *h,
+ upb_selector_t s) {
+ return (upb_func *)h->table[s].func;
+}
+
+bool upb_handlers_getattr(const upb_handlers *h, upb_selector_t s,
+ upb_handlerattr *attr);
+
+UPB_INLINE const void *upb_handlers_gethandlerdata(const upb_handlers *h,
+ upb_selector_t s) {
+ return upb_handlerattr_handlerdata(&h->table[s].attr);
+}
+
+#ifdef __cplusplus
+
+/* Handler types for single fields.
+ * Right now we only have one for TYPE_BYTES but ones for other types
+ * should follow.
+ *
+ * These follow the same handlers protocol for fields of a message. */
+class upb::BytesHandler {
+ public:
+ BytesHandler();
+ ~BytesHandler();
+#else
+struct upb_byteshandler {
+#endif
+ upb_handlers_tabent table[3];
+};
+
+void upb_byteshandler_init(upb_byteshandler *h);
+
+/* Caller must ensure that "d" outlives the handlers.
+ * TODO(haberman): should this have a "freeze" operation? It's not necessary
+ * for memory management, but could be useful to force immutability and provide
+ * a convenient moment to verify that all registration succeeded. */
+bool upb_byteshandler_setstartstr(upb_byteshandler *h,
+ upb_startstr_handlerfunc *func, void *d);
+bool upb_byteshandler_setstring(upb_byteshandler *h,
+ upb_string_handlerfunc *func, void *d);
+bool upb_byteshandler_setendstr(upb_byteshandler *h,
+ upb_endfield_handlerfunc *func, void *d);
+
+/* "Static" methods */
+bool upb_handlers_freeze(upb_handlers *const *handlers, int n, upb_status *s);
+upb_handlertype_t upb_handlers_getprimitivehandlertype(const upb_fielddef *f);
+bool upb_handlers_getselector(const upb_fielddef *f, upb_handlertype_t type,
+ upb_selector_t *s);
+UPB_INLINE upb_selector_t upb_handlers_getendselector(upb_selector_t start) {
+ return start + 1;
+}
+
+/* Internal-only. */
+uint32_t upb_handlers_selectorbaseoffset(const upb_fielddef *f);
+uint32_t upb_handlers_selectorcount(const upb_fielddef *f);
+
+UPB_END_EXTERN_C
+
+/*
+** Inline definitions for handlers.h, which are particularly long and a bit
+** tricky.
+*/
+
+#ifndef UPB_HANDLERS_INL_H_
+#define UPB_HANDLERS_INL_H_
+
+#include <limits.h>
+
+/* C inline methods. */
+
+/* upb_bufhandle */
+UPB_INLINE void upb_bufhandle_init(upb_bufhandle *h) {
+ h->obj_ = NULL;
+ h->objtype_ = NULL;
+ h->buf_ = NULL;
+ h->objofs_ = 0;
+}
+UPB_INLINE void upb_bufhandle_uninit(upb_bufhandle *h) {
+ UPB_UNUSED(h);
+}
+UPB_INLINE void upb_bufhandle_setobj(upb_bufhandle *h, const void *obj,
+ const void *type) {
+ h->obj_ = obj;
+ h->objtype_ = type;
+}
+UPB_INLINE void upb_bufhandle_setbuf(upb_bufhandle *h, const char *buf,
+ size_t ofs) {
+ h->buf_ = buf;
+ h->objofs_ = ofs;
+}
+UPB_INLINE const void *upb_bufhandle_obj(const upb_bufhandle *h) {
+ return h->obj_;
+}
+UPB_INLINE const void *upb_bufhandle_objtype(const upb_bufhandle *h) {
+ return h->objtype_;
+}
+UPB_INLINE const char *upb_bufhandle_buf(const upb_bufhandle *h) {
+ return h->buf_;
+}
+
+
+#ifdef __cplusplus
+
+/* Type detection and typedefs for integer types.
+ * For platforms where there are multiple 32-bit or 64-bit types, we need to be
+ * able to enumerate them so we can properly create overloads for all variants.
+ *
+ * If any platform existed where there were three integer types with the same
+ * size, this would have to become more complicated. For example, short, int,
+ * and long could all be 32-bits. Even more diabolically, short, int, long,
+ * and long long could all be 64 bits and still be standard-compliant.
+ * However, few platforms are this strange, and it's unlikely that upb will be
+ * used on the strangest ones. */
+
+/* Can't count on stdint.h limits like INT32_MAX, because in C++ these are
+ * only defined when __STDC_LIMIT_MACROS are defined before the *first* include
+ * of stdint.h. We can't guarantee that someone else didn't include these first
+ * without defining __STDC_LIMIT_MACROS. */
+#define UPB_INT32_MAX 0x7fffffffLL
+#define UPB_INT32_MIN (-UPB_INT32_MAX - 1)
+#define UPB_INT64_MAX 0x7fffffffffffffffLL
+#define UPB_INT64_MIN (-UPB_INT64_MAX - 1)
+
+#if INT_MAX == UPB_INT32_MAX && INT_MIN == UPB_INT32_MIN
+#define UPB_INT_IS_32BITS 1
+#endif
+
+#if LONG_MAX == UPB_INT32_MAX && LONG_MIN == UPB_INT32_MIN
+#define UPB_LONG_IS_32BITS 1
+#endif
+
+#if LONG_MAX == UPB_INT64_MAX && LONG_MIN == UPB_INT64_MIN
+#define UPB_LONG_IS_64BITS 1
+#endif
+
+#if LLONG_MAX == UPB_INT64_MAX && LLONG_MIN == UPB_INT64_MIN
+#define UPB_LLONG_IS_64BITS 1
+#endif
+
+/* We use macros instead of typedefs so we can undefine them later and avoid
+ * leaking them outside this header file. */
+#if UPB_INT_IS_32BITS
+#define UPB_INT32_T int
+#define UPB_UINT32_T unsigned int
+
+#if UPB_LONG_IS_32BITS
+#define UPB_TWO_32BIT_TYPES 1
+#define UPB_INT32ALT_T long
+#define UPB_UINT32ALT_T unsigned long
+#endif /* UPB_LONG_IS_32BITS */
+
+#elif UPB_LONG_IS_32BITS /* && !UPB_INT_IS_32BITS */
+#define UPB_INT32_T long
+#define UPB_UINT32_T unsigned long
+#endif /* UPB_INT_IS_32BITS */
+
+
+#if UPB_LONG_IS_64BITS
+#define UPB_INT64_T long
+#define UPB_UINT64_T unsigned long
+
+#if UPB_LLONG_IS_64BITS
+#define UPB_TWO_64BIT_TYPES 1
+#define UPB_INT64ALT_T long long
+#define UPB_UINT64ALT_T unsigned long long
+#endif /* UPB_LLONG_IS_64BITS */
+
+#elif UPB_LLONG_IS_64BITS /* && !UPB_LONG_IS_64BITS */
+#define UPB_INT64_T long long
+#define UPB_UINT64_T unsigned long long
+#endif /* UPB_LONG_IS_64BITS */
+
+#undef UPB_INT32_MAX
+#undef UPB_INT32_MIN
+#undef UPB_INT64_MAX
+#undef UPB_INT64_MIN
+#undef UPB_INT_IS_32BITS
+#undef UPB_LONG_IS_32BITS
+#undef UPB_LONG_IS_64BITS
+#undef UPB_LLONG_IS_64BITS
+
+
+namespace upb {
+
+typedef void CleanupFunc(void *ptr);
+
+/* Template to remove "const" from "const T*" and just return "T*".
+ *
+ * We define a nonsense default because otherwise it will fail to instantiate as
+ * a function parameter type even in cases where we don't expect any caller to
+ * actually match the overload. */
+class CouldntRemoveConst {};
+template <class T> struct remove_constptr { typedef CouldntRemoveConst type; };
+template <class T> struct remove_constptr<const T *> { typedef T *type; };
+
+/* Template that we use below to remove a template specialization from
+ * consideration if it matches a specific type. */
+template <class T, class U> struct disable_if_same { typedef void Type; };
+template <class T> struct disable_if_same<T, T> {};
+
+template <class T> void DeletePointer(void *p) { delete static_cast<T>(p); }
+
+template <class T1, class T2>
+struct FirstUnlessVoidOrBool {
+ typedef T1 value;
+};
+
+template <class T2>
+struct FirstUnlessVoidOrBool<void, T2> {
+ typedef T2 value;
+};
+
+template <class T2>
+struct FirstUnlessVoidOrBool<bool, T2> {
+ typedef T2 value;
+};
+
+template<class T, class U>
+struct is_same {
+ static bool value;
+};
+
+template<class T>
+struct is_same<T, T> {
+ static bool value;
+};
+
+template<class T, class U>
+bool is_same<T, U>::value = false;
+
+template<class T>
+bool is_same<T, T>::value = true;
+
+/* FuncInfo *******************************************************************/
+
+/* Info about the user's original, pre-wrapped function. */
+template <class C, class R = void>
+struct FuncInfo {
+ /* The type of the closure that the function takes (its first param). */
+ typedef C Closure;
+
+ /* The return type. */
+ typedef R Return;
+};
+
+/* Func ***********************************************************************/
+
+/* Func1, Func2, Func3: Template classes representing a function and its
+ * signature.
+ *
+ * Since the function is a template parameter, calling the function can be
+ * inlined at compile-time and does not require a function pointer at runtime.
+ * These functions are not bound to a handler data so have no data or cleanup
+ * handler. */
+struct UnboundFunc {
+ CleanupFunc *GetCleanup() { return NULL; }
+ void *GetData() { return NULL; }
+};
+
+template <class R, class P1, R F(P1), class I>
+struct Func1 : public UnboundFunc {
+ typedef R Return;
+ typedef I FuncInfo;
+ static R Call(P1 p1) { return F(p1); }
+};
+
+template <class R, class P1, class P2, R F(P1, P2), class I>
+struct Func2 : public UnboundFunc {
+ typedef R Return;
+ typedef I FuncInfo;
+ static R Call(P1 p1, P2 p2) { return F(p1, p2); }
+};
+
+template <class R, class P1, class P2, class P3, R F(P1, P2, P3), class I>
+struct Func3 : public UnboundFunc {
+ typedef R Return;
+ typedef I FuncInfo;
+ static R Call(P1 p1, P2 p2, P3 p3) { return F(p1, p2, p3); }
+};
+
+template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4),
+ class I>
+struct Func4 : public UnboundFunc {
+ typedef R Return;
+ typedef I FuncInfo;
+ static R Call(P1 p1, P2 p2, P3 p3, P4 p4) { return F(p1, p2, p3, p4); }
+};
+
+template <class R, class P1, class P2, class P3, class P4, class P5,
+ R F(P1, P2, P3, P4, P5), class I>
+struct Func5 : public UnboundFunc {
+ typedef R Return;
+ typedef I FuncInfo;
+ static R Call(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) {
+ return F(p1, p2, p3, p4, p5);
+ }
+};
+
+/* BoundFunc ******************************************************************/
+
+/* BoundFunc2, BoundFunc3: Like Func2/Func3 except also contains a value that
+ * shall be bound to the function's second parameter.
+ *
+ * Note that the second parameter is a const pointer, but our stored bound value
+ * is non-const so we can free it when the handlers are destroyed. */
+template <class T>
+struct BoundFunc {
+ typedef typename remove_constptr<T>::type MutableP2;
+ explicit BoundFunc(MutableP2 data_) : data(data_) {}
+ CleanupFunc *GetCleanup() { return &DeletePointer<MutableP2>; }
+ MutableP2 GetData() { return data; }
+ MutableP2 data;
+};
+
+template <class R, class P1, class P2, R F(P1, P2), class I>
+struct BoundFunc2 : public BoundFunc<P2> {
+ typedef BoundFunc<P2> Base;
+ typedef I FuncInfo;
+ explicit BoundFunc2(typename Base::MutableP2 arg) : Base(arg) {}
+};
+
+template <class R, class P1, class P2, class P3, R F(P1, P2, P3), class I>
+struct BoundFunc3 : public BoundFunc<P2> {
+ typedef BoundFunc<P2> Base;
+ typedef I FuncInfo;
+ explicit BoundFunc3(typename Base::MutableP2 arg) : Base(arg) {}
+};
+
+template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4),
+ class I>
+struct BoundFunc4 : public BoundFunc<P2> {
+ typedef BoundFunc<P2> Base;
+ typedef I FuncInfo;
+ explicit BoundFunc4(typename Base::MutableP2 arg) : Base(arg) {}
+};
+
+template <class R, class P1, class P2, class P3, class P4, class P5,
+ R F(P1, P2, P3, P4, P5), class I>
+struct BoundFunc5 : public BoundFunc<P2> {
+ typedef BoundFunc<P2> Base;
+ typedef I FuncInfo;
+ explicit BoundFunc5(typename Base::MutableP2 arg) : Base(arg) {}
+};
+
+/* FuncSig ********************************************************************/
+
+/* FuncSig1, FuncSig2, FuncSig3: template classes reflecting a function
+ * *signature*, but without a specific function attached.
+ *
+ * These classes contain member functions that can be invoked with a
+ * specific function to return a Func/BoundFunc class. */
+template <class R, class P1>
+struct FuncSig1 {
+ template <R F(P1)>
+ Func1<R, P1, F, FuncInfo<P1, R> > GetFunc() {
+ return Func1<R, P1, F, FuncInfo<P1, R> >();
+ }
+};
+
+template <class R, class P1, class P2>
+struct FuncSig2 {
+ template <R F(P1, P2)>
+ Func2<R, P1, P2, F, FuncInfo<P1, R> > GetFunc() {
+ return Func2<R, P1, P2, F, FuncInfo<P1, R> >();
+ }
+
+ template <R F(P1, P2)>
+ BoundFunc2<R, P1, P2, F, FuncInfo<P1, R> > GetFunc(
+ typename remove_constptr<P2>::type param2) {
+ return BoundFunc2<R, P1, P2, F, FuncInfo<P1, R> >(param2);
+ }
+};
+
+template <class R, class P1, class P2, class P3>
+struct FuncSig3 {
+ template <R F(P1, P2, P3)>
+ Func3<R, P1, P2, P3, F, FuncInfo<P1, R> > GetFunc() {
+ return Func3<R, P1, P2, P3, F, FuncInfo<P1, R> >();
+ }
+
+ template <R F(P1, P2, P3)>
+ BoundFunc3<R, P1, P2, P3, F, FuncInfo<P1, R> > GetFunc(
+ typename remove_constptr<P2>::type param2) {
+ return BoundFunc3<R, P1, P2, P3, F, FuncInfo<P1, R> >(param2);
+ }
+};
+
+template <class R, class P1, class P2, class P3, class P4>
+struct FuncSig4 {
+ template <R F(P1, P2, P3, P4)>
+ Func4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> > GetFunc() {
+ return Func4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> >();
+ }
+
+ template <R F(P1, P2, P3, P4)>
+ BoundFunc4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> > GetFunc(
+ typename remove_constptr<P2>::type param2) {
+ return BoundFunc4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> >(param2);
+ }
+};
+
+template <class R, class P1, class P2, class P3, class P4, class P5>
+struct FuncSig5 {
+ template <R F(P1, P2, P3, P4, P5)>
+ Func5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> > GetFunc() {
+ return Func5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> >();
+ }
+
+ template <R F(P1, P2, P3, P4, P5)>
+ BoundFunc5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> > GetFunc(
+ typename remove_constptr<P2>::type param2) {
+ return BoundFunc5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> >(param2);
+ }
+};
+
+/* Overloaded template function that can construct the appropriate FuncSig*
+ * class given a function pointer by deducing the template parameters. */
+template <class R, class P1>
+inline FuncSig1<R, P1> MatchFunc(R (*f)(P1)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return FuncSig1<R, P1>();
+}
+
+template <class R, class P1, class P2>
+inline FuncSig2<R, P1, P2> MatchFunc(R (*f)(P1, P2)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return FuncSig2<R, P1, P2>();
+}
+
+template <class R, class P1, class P2, class P3>
+inline FuncSig3<R, P1, P2, P3> MatchFunc(R (*f)(P1, P2, P3)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return FuncSig3<R, P1, P2, P3>();
+}
+
+template <class R, class P1, class P2, class P3, class P4>
+inline FuncSig4<R, P1, P2, P3, P4> MatchFunc(R (*f)(P1, P2, P3, P4)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return FuncSig4<R, P1, P2, P3, P4>();
+}
+
+template <class R, class P1, class P2, class P3, class P4, class P5>
+inline FuncSig5<R, P1, P2, P3, P4, P5> MatchFunc(R (*f)(P1, P2, P3, P4, P5)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return FuncSig5<R, P1, P2, P3, P4, P5>();
+}
+
+/* MethodSig ******************************************************************/
+
+/* CallMethod*: a function template that calls a given method. */
+template <class R, class C, R (C::*F)()>
+R CallMethod0(C *obj) {
+ return ((*obj).*F)();
+}
+
+template <class R, class C, class P1, R (C::*F)(P1)>
+R CallMethod1(C *obj, P1 arg1) {
+ return ((*obj).*F)(arg1);
+}
+
+template <class R, class C, class P1, class P2, R (C::*F)(P1, P2)>
+R CallMethod2(C *obj, P1 arg1, P2 arg2) {
+ return ((*obj).*F)(arg1, arg2);
+}
+
+template <class R, class C, class P1, class P2, class P3, R (C::*F)(P1, P2, P3)>
+R CallMethod3(C *obj, P1 arg1, P2 arg2, P3 arg3) {
+ return ((*obj).*F)(arg1, arg2, arg3);
+}
+
+template <class R, class C, class P1, class P2, class P3, class P4,
+ R (C::*F)(P1, P2, P3, P4)>
+R CallMethod4(C *obj, P1 arg1, P2 arg2, P3 arg3, P4 arg4) {
+ return ((*obj).*F)(arg1, arg2, arg3, arg4);
+}
+
+/* MethodSig: like FuncSig, but for member functions.
+ *
+ * GetFunc() returns a normal FuncN object, so after calling GetFunc() no
+ * more logic is required to special-case methods. */
+template <class R, class C>
+struct MethodSig0 {
+ template <R (C::*F)()>
+ Func1<R, C *, CallMethod0<R, C, F>, FuncInfo<C *, R> > GetFunc() {
+ return Func1<R, C *, CallMethod0<R, C, F>, FuncInfo<C *, R> >();
+ }
+};
+
+template <class R, class C, class P1>
+struct MethodSig1 {
+ template <R (C::*F)(P1)>
+ Func2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> > GetFunc() {
+ return Func2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> >();
+ }
+
+ template <R (C::*F)(P1)>
+ BoundFunc2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> > GetFunc(
+ typename remove_constptr<P1>::type param1) {
+ return BoundFunc2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> >(
+ param1);
+ }
+};
+
+template <class R, class C, class P1, class P2>
+struct MethodSig2 {
+ template <R (C::*F)(P1, P2)>
+ Func3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>, FuncInfo<C *, R> >
+ GetFunc() {
+ return Func3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>,
+ FuncInfo<C *, R> >();
+ }
+
+ template <R (C::*F)(P1, P2)>
+ BoundFunc3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>, FuncInfo<C *, R> >
+ GetFunc(typename remove_constptr<P1>::type param1) {
+ return BoundFunc3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>,
+ FuncInfo<C *, R> >(param1);
+ }
+};
+
+template <class R, class C, class P1, class P2, class P3>
+struct MethodSig3 {
+ template <R (C::*F)(P1, P2, P3)>
+ Func4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>, FuncInfo<C *, R> >
+ GetFunc() {
+ return Func4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>,
+ FuncInfo<C *, R> >();
+ }
+
+ template <R (C::*F)(P1, P2, P3)>
+ BoundFunc4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>,
+ FuncInfo<C *, R> >
+ GetFunc(typename remove_constptr<P1>::type param1) {
+ return BoundFunc4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>,
+ FuncInfo<C *, R> >(param1);
+ }
+};
+
+template <class R, class C, class P1, class P2, class P3, class P4>
+struct MethodSig4 {
+ template <R (C::*F)(P1, P2, P3, P4)>
+ Func5<R, C *, P1, P2, P3, P4, CallMethod4<R, C, P1, P2, P3, P4, F>,
+ FuncInfo<C *, R> >
+ GetFunc() {
+ return Func5<R, C *, P1, P2, P3, P4, CallMethod4<R, C, P1, P2, P3, P4, F>,
+ FuncInfo<C *, R> >();
+ }
+
+ template <R (C::*F)(P1, P2, P3, P4)>
+ BoundFunc5<R, C *, P1, P2, P3, P4, CallMethod4<R, C, P1, P2, P3, P4, F>,
+ FuncInfo<C *, R> >
+ GetFunc(typename remove_constptr<P1>::type param1) {
+ return BoundFunc5<R, C *, P1, P2, P3, P4,
+ CallMethod4<R, C, P1, P2, P3, P4, F>, FuncInfo<C *, R> >(
+ param1);
+ }
+};
+
+template <class R, class C>
+inline MethodSig0<R, C> MatchFunc(R (C::*f)()) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return MethodSig0<R, C>();
+}
+
+template <class R, class C, class P1>
+inline MethodSig1<R, C, P1> MatchFunc(R (C::*f)(P1)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return MethodSig1<R, C, P1>();
+}
+
+template <class R, class C, class P1, class P2>
+inline MethodSig2<R, C, P1, P2> MatchFunc(R (C::*f)(P1, P2)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return MethodSig2<R, C, P1, P2>();
+}
+
+template <class R, class C, class P1, class P2, class P3>
+inline MethodSig3<R, C, P1, P2, P3> MatchFunc(R (C::*f)(P1, P2, P3)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return MethodSig3<R, C, P1, P2, P3>();
+}
+
+template <class R, class C, class P1, class P2, class P3, class P4>
+inline MethodSig4<R, C, P1, P2, P3, P4> MatchFunc(R (C::*f)(P1, P2, P3, P4)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return MethodSig4<R, C, P1, P2, P3, P4>();
+}
+
+/* MaybeWrapReturn ************************************************************/
+
+/* Template class that attempts to wrap the return value of the function so it
+ * matches the expected type. There are two main adjustments it may make:
+ *
+ * 1. If the function returns void, make it return the expected type and with
+ * a value that always indicates success.
+ * 2. If the function returns bool, make it return the expected type with a
+ * value that indicates success or failure.
+ *
+ * The "expected type" for return is:
+ * 1. void* for start handlers. If the closure parameter has a different type
+ * we will cast it to void* for the return in the success case.
+ * 2. size_t for string buffer handlers.
+ * 3. bool for everything else. */
+
+/* Template parameters are FuncN type and desired return type. */
+template <class F, class R, class Enable = void>
+struct MaybeWrapReturn;
+
+/* If the return type matches, return the given function unwrapped. */
+template <class F>
+struct MaybeWrapReturn<F, typename F::Return> {
+ typedef F Func;
+};
+
+/* Function wrapper that munges the return value from void to (bool)true. */
+template <class P1, class P2, void F(P1, P2)>
+bool ReturnTrue2(P1 p1, P2 p2) {
+ F(p1, p2);
+ return true;
+}
+
+template <class P1, class P2, class P3, void F(P1, P2, P3)>
+bool ReturnTrue3(P1 p1, P2 p2, P3 p3) {
+ F(p1, p2, p3);
+ return true;
+}
+
+/* Function wrapper that munges the return value from void to (void*)arg1 */
+template <class P1, class P2, void F(P1, P2)>
+void *ReturnClosure2(P1 p1, P2 p2) {
+ F(p1, p2);
+ return p1;
+}
+
+template <class P1, class P2, class P3, void F(P1, P2, P3)>
+void *ReturnClosure3(P1 p1, P2 p2, P3 p3) {
+ F(p1, p2, p3);
+ return p1;
+}
+
+/* Function wrapper that munges the return value from R to void*. */
+template <class R, class P1, class P2, R F(P1, P2)>
+void *CastReturnToVoidPtr2(P1 p1, P2 p2) {
+ return F(p1, p2);
+}
+
+template <class R, class P1, class P2, class P3, R F(P1, P2, P3)>
+void *CastReturnToVoidPtr3(P1 p1, P2 p2, P3 p3) {
+ return F(p1, p2, p3);
+}
+
+/* Function wrapper that munges the return value from bool to void*. */
+template <class P1, class P2, bool F(P1, P2)>
+void *ReturnClosureOrBreak2(P1 p1, P2 p2) {
+ return F(p1, p2) ? p1 : UPB_BREAK;
+}
+
+template <class P1, class P2, class P3, bool F(P1, P2, P3)>
+void *ReturnClosureOrBreak3(P1 p1, P2 p2, P3 p3) {
+ return F(p1, p2, p3) ? p1 : UPB_BREAK;
+}
+
+/* For the string callback, which takes five params, returns the size param. */
+template <class P1, class P2,
+ void F(P1, P2, const char *, size_t, const BufferHandle *)>
+size_t ReturnStringLen(P1 p1, P2 p2, const char *p3, size_t p4,
+ const BufferHandle *p5) {
+ F(p1, p2, p3, p4, p5);
+ return p4;
+}
+
+/* For the string callback, which takes five params, returns the size param or
+ * zero. */
+template <class P1, class P2,
+ bool F(P1, P2, const char *, size_t, const BufferHandle *)>
+size_t ReturnNOr0(P1 p1, P2 p2, const char *p3, size_t p4,
+ const BufferHandle *p5) {
+ return F(p1, p2, p3, p4, p5) ? p4 : 0;
+}
+
+/* If we have a function returning void but want a function returning bool, wrap
+ * it in a function that returns true. */
+template <class P1, class P2, void F(P1, P2), class I>
+struct MaybeWrapReturn<Func2<void, P1, P2, F, I>, bool> {
+ typedef Func2<bool, P1, P2, ReturnTrue2<P1, P2, F>, I> Func;
+};
+
+template <class P1, class P2, class P3, void F(P1, P2, P3), class I>
+struct MaybeWrapReturn<Func3<void, P1, P2, P3, F, I>, bool> {
+ typedef Func3<bool, P1, P2, P3, ReturnTrue3<P1, P2, P3, F>, I> Func;
+};
+
+/* If our function returns void but we want one returning void*, wrap it in a
+ * function that returns the first argument. */
+template <class P1, class P2, void F(P1, P2), class I>
+struct MaybeWrapReturn<Func2<void, P1, P2, F, I>, void *> {
+ typedef Func2<void *, P1, P2, ReturnClosure2<P1, P2, F>, I> Func;
+};
+
+template <class P1, class P2, class P3, void F(P1, P2, P3), class I>
+struct MaybeWrapReturn<Func3<void, P1, P2, P3, F, I>, void *> {
+ typedef Func3<void *, P1, P2, P3, ReturnClosure3<P1, P2, P3, F>, I> Func;
+};
+
+/* If our function returns R* but we want one returning void*, wrap it in a
+ * function that casts to void*. */
+template <class R, class P1, class P2, R *F(P1, P2), class I>
+struct MaybeWrapReturn<Func2<R *, P1, P2, F, I>, void *,
+ typename disable_if_same<R *, void *>::Type> {
+ typedef Func2<void *, P1, P2, CastReturnToVoidPtr2<R *, P1, P2, F>, I> Func;
+};
+
+template <class R, class P1, class P2, class P3, R *F(P1, P2, P3), class I>
+struct MaybeWrapReturn<Func3<R *, P1, P2, P3, F, I>, void *,
+ typename disable_if_same<R *, void *>::Type> {
+ typedef Func3<void *, P1, P2, P3, CastReturnToVoidPtr3<R *, P1, P2, P3, F>, I>
+ Func;
+};
+
+/* If our function returns bool but we want one returning void*, wrap it in a
+ * function that returns either the first param or UPB_BREAK. */
+template <class P1, class P2, bool F(P1, P2), class I>
+struct MaybeWrapReturn<Func2<bool, P1, P2, F, I>, void *> {
+ typedef Func2<void *, P1, P2, ReturnClosureOrBreak2<P1, P2, F>, I> Func;
+};
+
+template <class P1, class P2, class P3, bool F(P1, P2, P3), class I>
+struct MaybeWrapReturn<Func3<bool, P1, P2, P3, F, I>, void *> {
+ typedef Func3<void *, P1, P2, P3, ReturnClosureOrBreak3<P1, P2, P3, F>, I>
+ Func;
+};
+
+/* If our function returns void but we want one returning size_t, wrap it in a
+ * function that returns the size argument. */
+template <class P1, class P2,
+ void F(P1, P2, const char *, size_t, const BufferHandle *), class I>
+struct MaybeWrapReturn<
+ Func5<void, P1, P2, const char *, size_t, const BufferHandle *, F, I>,
+ size_t> {
+ typedef Func5<size_t, P1, P2, const char *, size_t, const BufferHandle *,
+ ReturnStringLen<P1, P2, F>, I> Func;
+};
+
+/* If our function returns bool but we want one returning size_t, wrap it in a
+ * function that returns either 0 or the buf size. */
+template <class P1, class P2,
+ bool F(P1, P2, const char *, size_t, const BufferHandle *), class I>
+struct MaybeWrapReturn<
+ Func5<bool, P1, P2, const char *, size_t, const BufferHandle *, F, I>,
+ size_t> {
+ typedef Func5<size_t, P1, P2, const char *, size_t, const BufferHandle *,
+ ReturnNOr0<P1, P2, F>, I> Func;
+};
+
+/* ConvertParams **************************************************************/
+
+/* Template class that converts the function parameters if necessary, and
+ * ignores the HandlerData parameter if appropriate.
+ *
+ * Template parameter is the are FuncN function type. */
+template <class F, class T>
+struct ConvertParams;
+
+/* Function that discards the handler data parameter. */
+template <class R, class P1, R F(P1)>
+R IgnoreHandlerData2(void *p1, const void *hd) {
+ UPB_UNUSED(hd);
+ return F(static_cast<P1>(p1));
+}
+
+template <class R, class P1, class P2Wrapper, class P2Wrapped,
+ R F(P1, P2Wrapped)>
+R IgnoreHandlerData3(void *p1, const void *hd, P2Wrapper p2) {
+ UPB_UNUSED(hd);
+ return F(static_cast<P1>(p1), p2);
+}
+
+template <class R, class P1, class P2, class P3, R F(P1, P2, P3)>
+R IgnoreHandlerData4(void *p1, const void *hd, P2 p2, P3 p3) {
+ UPB_UNUSED(hd);
+ return F(static_cast<P1>(p1), p2, p3);
+}
+
+template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4)>
+R IgnoreHandlerData5(void *p1, const void *hd, P2 p2, P3 p3, P4 p4) {
+ UPB_UNUSED(hd);
+ return F(static_cast<P1>(p1), p2, p3, p4);
+}
+
+template <class R, class P1, R F(P1, const char*, size_t)>
+R IgnoreHandlerDataIgnoreHandle(void *p1, const void *hd, const char *p2,
+ size_t p3, const BufferHandle *handle) {
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+ return F(static_cast<P1>(p1), p2, p3);
+}
+
+/* Function that casts the handler data parameter. */
+template <class R, class P1, class P2, R F(P1, P2)>
+R CastHandlerData2(void *c, const void *hd) {
+ return F(static_cast<P1>(c), static_cast<P2>(hd));
+}
+
+template <class R, class P1, class P2, class P3Wrapper, class P3Wrapped,
+ R F(P1, P2, P3Wrapped)>
+R CastHandlerData3(void *c, const void *hd, P3Wrapper p3) {
+ return F(static_cast<P1>(c), static_cast<P2>(hd), p3);
+}
+
+template <class R, class P1, class P2, class P3, class P4, class P5,
+ R F(P1, P2, P3, P4, P5)>
+R CastHandlerData5(void *c, const void *hd, P3 p3, P4 p4, P5 p5) {
+ return F(static_cast<P1>(c), static_cast<P2>(hd), p3, p4, p5);
+}
+
+template <class R, class P1, class P2, R F(P1, P2, const char *, size_t)>
+R CastHandlerDataIgnoreHandle(void *c, const void *hd, const char *p3,
+ size_t p4, const BufferHandle *handle) {
+ UPB_UNUSED(handle);
+ return F(static_cast<P1>(c), static_cast<P2>(hd), p3, p4);
+}
+
+/* For unbound functions, ignore the handler data. */
+template <class R, class P1, R F(P1), class I, class T>
+struct ConvertParams<Func1<R, P1, F, I>, T> {
+ typedef Func2<R, void *, const void *, IgnoreHandlerData2<R, P1, F>, I> Func;
+};
+
+template <class R, class P1, class P2, R F(P1, P2), class I,
+ class R2, class P1_2, class P2_2, class P3_2>
+struct ConvertParams<Func2<R, P1, P2, F, I>,
+ R2 (*)(P1_2, P2_2, P3_2)> {
+ typedef Func3<R, void *, const void *, P3_2,
+ IgnoreHandlerData3<R, P1, P3_2, P2, F>, I> Func;
+};
+
+/* For StringBuffer only; this ignores both the handler data and the
+ * BufferHandle. */
+template <class R, class P1, R F(P1, const char *, size_t), class I, class T>
+struct ConvertParams<Func3<R, P1, const char *, size_t, F, I>, T> {
+ typedef Func5<R, void *, const void *, const char *, size_t,
+ const BufferHandle *, IgnoreHandlerDataIgnoreHandle<R, P1, F>,
+ I> Func;
+};
+
+template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4),
+ class I, class T>
+struct ConvertParams<Func4<R, P1, P2, P3, P4, F, I>, T> {
+ typedef Func5<R, void *, const void *, P2, P3, P4,
+ IgnoreHandlerData5<R, P1, P2, P3, P4, F>, I> Func;
+};
+
+/* For bound functions, cast the handler data. */
+template <class R, class P1, class P2, R F(P1, P2), class I, class T>
+struct ConvertParams<BoundFunc2<R, P1, P2, F, I>, T> {
+ typedef Func2<R, void *, const void *, CastHandlerData2<R, P1, P2, F>, I>
+ Func;
+};
+
+template <class R, class P1, class P2, class P3, R F(P1, P2, P3), class I,
+ class R2, class P1_2, class P2_2, class P3_2>
+struct ConvertParams<BoundFunc3<R, P1, P2, P3, F, I>,
+ R2 (*)(P1_2, P2_2, P3_2)> {
+ typedef Func3<R, void *, const void *, P3_2,
+ CastHandlerData3<R, P1, P2, P3_2, P3, F>, I> Func;
+};
+
+/* For StringBuffer only; this ignores the BufferHandle. */
+template <class R, class P1, class P2, R F(P1, P2, const char *, size_t),
+ class I, class T>
+struct ConvertParams<BoundFunc4<R, P1, P2, const char *, size_t, F, I>, T> {
+ typedef Func5<R, void *, const void *, const char *, size_t,
+ const BufferHandle *, CastHandlerDataIgnoreHandle<R, P1, P2, F>,
+ I> Func;
+};
+
+template <class R, class P1, class P2, class P3, class P4, class P5,
+ R F(P1, P2, P3, P4, P5), class I, class T>
+struct ConvertParams<BoundFunc5<R, P1, P2, P3, P4, P5, F, I>, T> {
+ typedef Func5<R, void *, const void *, P3, P4, P5,
+ CastHandlerData5<R, P1, P2, P3, P4, P5, F>, I> Func;
+};
+
+/* utype/ltype are upper/lower-case, ctype is canonical C type, vtype is
+ * variant C type. */
+#define TYPE_METHODS(utype, ltype, ctype, vtype) \
+ template <> struct CanonicalType<vtype> { \
+ typedef ctype Type; \
+ }; \
+ template <> \
+ inline bool Handlers::SetValueHandler<vtype>( \
+ const FieldDef *f, \
+ const Handlers::utype ## Handler& handler) { \
+ UPB_ASSERT(!handler.registered_); \
+ handler.AddCleanup(this); \
+ handler.registered_ = true; \
+ return upb_handlers_set##ltype(this, f, handler.handler_, &handler.attr_); \
+ } \
+
+TYPE_METHODS(Double, double, double, double)
+TYPE_METHODS(Float, float, float, float)
+TYPE_METHODS(UInt64, uint64, uint64_t, UPB_UINT64_T)
+TYPE_METHODS(UInt32, uint32, uint32_t, UPB_UINT32_T)
+TYPE_METHODS(Int64, int64, int64_t, UPB_INT64_T)
+TYPE_METHODS(Int32, int32, int32_t, UPB_INT32_T)
+TYPE_METHODS(Bool, bool, bool, bool)
+
+#ifdef UPB_TWO_32BIT_TYPES
+TYPE_METHODS(Int32, int32, int32_t, UPB_INT32ALT_T)
+TYPE_METHODS(UInt32, uint32, uint32_t, UPB_UINT32ALT_T)
+#endif
+
+#ifdef UPB_TWO_64BIT_TYPES
+TYPE_METHODS(Int64, int64, int64_t, UPB_INT64ALT_T)
+TYPE_METHODS(UInt64, uint64, uint64_t, UPB_UINT64ALT_T)
+#endif
+#undef TYPE_METHODS
+
+template <> struct CanonicalType<Status*> {
+ typedef Status* Type;
+};
+
+/* Type methods that are only one-per-canonical-type and not
+ * one-per-cvariant. */
+
+#define TYPE_METHODS(utype, ctype) \
+ inline bool Handlers::Set##utype##Handler(const FieldDef *f, \
+ const utype##Handler &h) { \
+ return SetValueHandler<ctype>(f, h); \
+ } \
+
+TYPE_METHODS(Double, double)
+TYPE_METHODS(Float, float)
+TYPE_METHODS(UInt64, uint64_t)
+TYPE_METHODS(UInt32, uint32_t)
+TYPE_METHODS(Int64, int64_t)
+TYPE_METHODS(Int32, int32_t)
+TYPE_METHODS(Bool, bool)
+#undef TYPE_METHODS
+
+template <class F> struct ReturnOf;
+
+template <class R, class P1, class P2>
+struct ReturnOf<R (*)(P1, P2)> {
+ typedef R Return;
+};
+
+template <class R, class P1, class P2, class P3>
+struct ReturnOf<R (*)(P1, P2, P3)> {
+ typedef R Return;
+};
+
+template <class R, class P1, class P2, class P3, class P4>
+struct ReturnOf<R (*)(P1, P2, P3, P4)> {
+ typedef R Return;
+};
+
+template <class R, class P1, class P2, class P3, class P4, class P5>
+struct ReturnOf<R (*)(P1, P2, P3, P4, P5)> {
+ typedef R Return;
+};
+
+template<class T> const void *UniquePtrForType() {
+ static const char ch = 0;
+ return &ch;
+}
+
+template <class T>
+template <class F>
+inline Handler<T>::Handler(F func)
+ : registered_(false),
+ cleanup_data_(func.GetData()),
+ cleanup_func_(func.GetCleanup()) {
+ upb_handlerattr_sethandlerdata(&attr_, func.GetData());
+ typedef typename ReturnOf<T>::Return Return;
+ typedef typename ConvertParams<F, T>::Func ConvertedParamsFunc;
+ typedef typename MaybeWrapReturn<ConvertedParamsFunc, Return>::Func
+ ReturnWrappedFunc;
+ handler_ = ReturnWrappedFunc().Call;
+
+ /* Set attributes based on what templates can statically tell us about the
+ * user's function. */
+
+ /* If the original function returns void, then we know that we wrapped it to
+ * always return ok. */
+ bool always_ok = is_same<typename F::FuncInfo::Return, void>::value;
+ attr_.SetAlwaysOk(always_ok);
+
+ /* Closure parameter and return type. */
+ attr_.SetClosureType(UniquePtrForType<typename F::FuncInfo::Closure>());
+
+ /* We use the closure type (from the first parameter) if the return type is
+ * void or bool, since these are the two cases we wrap to return the closure's
+ * type anyway.
+ *
+ * This is all nonsense for non START* handlers, but it doesn't matter because
+ * in that case the value will be ignored. */
+ typedef typename FirstUnlessVoidOrBool<typename F::FuncInfo::Return,
+ typename F::FuncInfo::Closure>::value
+ EffectiveReturn;
+ attr_.SetReturnClosureType(UniquePtrForType<EffectiveReturn>());
+}
+
+template <class T>
+inline Handler<T>::~Handler() {
+ UPB_ASSERT(registered_);
+}
+
+inline HandlerAttributes::HandlerAttributes() { upb_handlerattr_init(this); }
+inline HandlerAttributes::~HandlerAttributes() { upb_handlerattr_uninit(this); }
+inline bool HandlerAttributes::SetHandlerData(const void *hd) {
+ return upb_handlerattr_sethandlerdata(this, hd);
+}
+inline const void* HandlerAttributes::handler_data() const {
+ return upb_handlerattr_handlerdata(this);
+}
+inline bool HandlerAttributes::SetClosureType(const void *type) {
+ return upb_handlerattr_setclosuretype(this, type);
+}
+inline const void* HandlerAttributes::closure_type() const {
+ return upb_handlerattr_closuretype(this);
+}
+inline bool HandlerAttributes::SetReturnClosureType(const void *type) {
+ return upb_handlerattr_setreturnclosuretype(this, type);
+}
+inline const void* HandlerAttributes::return_closure_type() const {
+ return upb_handlerattr_returnclosuretype(this);
+}
+inline bool HandlerAttributes::SetAlwaysOk(bool always_ok) {
+ return upb_handlerattr_setalwaysok(this, always_ok);
+}
+inline bool HandlerAttributes::always_ok() const {
+ return upb_handlerattr_alwaysok(this);
+}
+
+inline BufferHandle::BufferHandle() { upb_bufhandle_init(this); }
+inline BufferHandle::~BufferHandle() { upb_bufhandle_uninit(this); }
+inline const char* BufferHandle::buffer() const {
+ return upb_bufhandle_buf(this);
+}
+inline size_t BufferHandle::object_offset() const {
+ return upb_bufhandle_objofs(this);
+}
+inline void BufferHandle::SetBuffer(const char* buf, size_t ofs) {
+ upb_bufhandle_setbuf(this, buf, ofs);
+}
+template <class T>
+void BufferHandle::SetAttachedObject(const T* obj) {
+ upb_bufhandle_setobj(this, obj, UniquePtrForType<T>());
+}
+template <class T>
+const T* BufferHandle::GetAttachedObject() const {
+ return upb_bufhandle_objtype(this) == UniquePtrForType<T>()
+ ? static_cast<const T *>(upb_bufhandle_obj(this))
+ : NULL;
+}
+
+inline reffed_ptr<Handlers> Handlers::New(const MessageDef *m) {
+ upb_handlers *h = upb_handlers_new(m, &h);
+ return reffed_ptr<Handlers>(h, &h);
+}
+inline reffed_ptr<const Handlers> Handlers::NewFrozen(
+ const MessageDef *m, upb_handlers_callback *callback,
+ const void *closure) {
+ const upb_handlers *h = upb_handlers_newfrozen(m, &h, callback, closure);
+ return reffed_ptr<const Handlers>(h, &h);
+}
+inline const Status* Handlers::status() {
+ return upb_handlers_status(this);
+}
+inline void Handlers::ClearError() {
+ return upb_handlers_clearerr(this);
+}
+inline bool Handlers::Freeze(Status *s) {
+ upb::Handlers* h = this;
+ return upb_handlers_freeze(&h, 1, s);
+}
+inline bool Handlers::Freeze(Handlers *const *handlers, int n, Status *s) {
+ return upb_handlers_freeze(handlers, n, s);
+}
+inline bool Handlers::Freeze(const std::vector<Handlers*>& h, Status* status) {
+ return upb_handlers_freeze((Handlers* const*)&h[0], h.size(), status);
+}
+inline const MessageDef *Handlers::message_def() const {
+ return upb_handlers_msgdef(this);
+}
+inline bool Handlers::AddCleanup(void *p, upb_handlerfree *func) {
+ return upb_handlers_addcleanup(this, p, func);
+}
+inline bool Handlers::SetStartMessageHandler(
+ const Handlers::StartMessageHandler &handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setstartmsg(this, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetEndMessageHandler(
+ const Handlers::EndMessageHandler &handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setendmsg(this, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetStartStringHandler(const FieldDef *f,
+ const StartStringHandler &handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setstartstr(this, f, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetEndStringHandler(const FieldDef *f,
+ const EndFieldHandler &handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setendstr(this, f, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetStringHandler(const FieldDef *f,
+ const StringHandler& handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setstring(this, f, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetStartSequenceHandler(
+ const FieldDef *f, const StartFieldHandler &handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setstartseq(this, f, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetStartSubMessageHandler(
+ const FieldDef *f, const StartFieldHandler &handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setstartsubmsg(this, f, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetEndSubMessageHandler(const FieldDef *f,
+ const EndFieldHandler &handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setendsubmsg(this, f, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetEndSequenceHandler(const FieldDef *f,
+ const EndFieldHandler &handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setendseq(this, f, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetSubHandlers(const FieldDef *f, const Handlers *sub) {
+ return upb_handlers_setsubhandlers(this, f, sub);
+}
+inline const Handlers *Handlers::GetSubHandlers(const FieldDef *f) const {
+ return upb_handlers_getsubhandlers(this, f);
+}
+inline const Handlers *Handlers::GetSubHandlers(Handlers::Selector sel) const {
+ return upb_handlers_getsubhandlers_sel(this, sel);
+}
+inline bool Handlers::GetSelector(const FieldDef *f, Handlers::Type type,
+ Handlers::Selector *s) {
+ return upb_handlers_getselector(f, type, s);
+}
+inline Handlers::Selector Handlers::GetEndSelector(Handlers::Selector start) {
+ return upb_handlers_getendselector(start);
+}
+inline Handlers::GenericFunction *Handlers::GetHandler(
+ Handlers::Selector selector) {
+ return upb_handlers_gethandler(this, selector);
+}
+inline const void *Handlers::GetHandlerData(Handlers::Selector selector) {
+ return upb_handlers_gethandlerdata(this, selector);
+}
+
+inline BytesHandler::BytesHandler() {
+ upb_byteshandler_init(this);
+}
+
+inline BytesHandler::~BytesHandler() {}
+
+} /* namespace upb */
+
+#endif /* __cplusplus */
+
+
+#undef UPB_TWO_32BIT_TYPES
+#undef UPB_TWO_64BIT_TYPES
+#undef UPB_INT32_T
+#undef UPB_UINT32_T
+#undef UPB_INT32ALT_T
+#undef UPB_UINT32ALT_T
+#undef UPB_INT64_T
+#undef UPB_UINT64_T
+#undef UPB_INT64ALT_T
+#undef UPB_UINT64ALT_T
+
+#endif /* UPB_HANDLERS_INL_H_ */
+
+#endif /* UPB_HANDLERS_H */
+/*
+** upb::Sink (upb_sink)
+** upb::BytesSink (upb_bytessink)
+**
+** A upb_sink is an object that binds a upb_handlers object to some runtime
+** state. It is the object that can actually receive data via the upb_handlers
+** interface.
+**
+** Unlike upb_def and upb_handlers, upb_sink is never frozen, immutable, or
+** thread-safe. You can create as many of them as you want, but each one may
+** only be used in a single thread at a time.
+**
+** If we compare with class-based OOP, a you can think of a upb_def as an
+** abstract base class, a upb_handlers as a concrete derived class, and a
+** upb_sink as an object (class instance).
+*/
+
+#ifndef UPB_SINK_H
+#define UPB_SINK_H
+
+
+#ifdef __cplusplus
+namespace upb {
+class BufferSink;
+class BufferSource;
+class BytesSink;
+class Sink;
+}
+#endif
+
+UPB_DECLARE_TYPE(upb::BufferSink, upb_bufsink)
+UPB_DECLARE_TYPE(upb::BufferSource, upb_bufsrc)
+UPB_DECLARE_TYPE(upb::BytesSink, upb_bytessink)
+UPB_DECLARE_TYPE(upb::Sink, upb_sink)
+
+#ifdef __cplusplus
+
+/* A upb::Sink is an object that binds a upb::Handlers object to some runtime
+ * state. It represents an endpoint to which data can be sent.
+ *
+ * TODO(haberman): right now all of these functions take selectors. Should they
+ * take selectorbase instead?
+ *
+ * ie. instead of calling:
+ * sink->StartString(FOO_FIELD_START_STRING, ...)
+ * a selector base would let you say:
+ * sink->StartString(FOO_FIELD, ...)
+ *
+ * This would make call sites a little nicer and require emitting fewer selector
+ * definitions in .h files.
+ *
+ * But the current scheme has the benefit that you can retrieve a function
+ * pointer for any handler with handlers->GetHandler(selector), without having
+ * to have a separate GetHandler() function for each handler type. The JIT
+ * compiler uses this. To accommodate we'd have to expose a separate
+ * GetHandler() for every handler type.
+ *
+ * Also to ponder: selectors right now are independent of a specific Handlers
+ * instance. In other words, they allocate a number to every possible handler
+ * that *could* be registered, without knowing anything about what handlers
+ * *are* registered. That means that using selectors as table offsets prohibits
+ * us from compacting the handler table at Freeze() time. If the table is very
+ * sparse, this could be wasteful.
+ *
+ * Having another selector-like thing that is specific to a Handlers instance
+ * would allow this compacting, but then it would be impossible to write code
+ * ahead-of-time that can be bound to any Handlers instance at runtime. For
+ * example, a .proto file parser written as straight C will not know what
+ * Handlers it will be bound to, so when it calls sink->StartString() what
+ * selector will it pass? It needs a selector like we have today, that is
+ * independent of any particular upb::Handlers.
+ *
+ * Is there a way then to allow Handlers table compaction? */
+class upb::Sink {
+ public:
+ /* Constructor with no initialization; must be Reset() before use. */
+ Sink() {}
+
+ /* Constructs a new sink for the given frozen handlers and closure.
+ *
+ * TODO: once the Handlers know the expected closure type, verify that T
+ * matches it. */
+ template <class T> Sink(const Handlers* handlers, T* closure);
+
+ /* Resets the value of the sink. */
+ template <class T> void Reset(const Handlers* handlers, T* closure);
+
+ /* Returns the top-level object that is bound to this sink.
+ *
+ * TODO: once the Handlers know the expected closure type, verify that T
+ * matches it. */
+ template <class T> T* GetObject() const;
+
+ /* Functions for pushing data into the sink.
+ *
+ * These return false if processing should stop (either due to error or just
+ * to suspend).
+ *
+ * These may not be called from within one of the same sink's handlers (in
+ * other words, handlers are not re-entrant). */
+
+ /* Should be called at the start and end of every message; both the top-level
+ * message and submessages. This means that submessages should use the
+ * following sequence:
+ * sink->StartSubMessage(startsubmsg_selector);
+ * sink->StartMessage();
+ * // ...
+ * sink->EndMessage(&status);
+ * sink->EndSubMessage(endsubmsg_selector); */
+ bool StartMessage();
+ bool EndMessage(Status* status);
+
+ /* Putting of individual values. These work for both repeated and
+ * non-repeated fields, but for repeated fields you must wrap them in
+ * calls to StartSequence()/EndSequence(). */
+ bool PutInt32(Handlers::Selector s, int32_t val);
+ bool PutInt64(Handlers::Selector s, int64_t val);
+ bool PutUInt32(Handlers::Selector s, uint32_t val);
+ bool PutUInt64(Handlers::Selector s, uint64_t val);
+ bool PutFloat(Handlers::Selector s, float val);
+ bool PutDouble(Handlers::Selector s, double val);
+ bool PutBool(Handlers::Selector s, bool val);
+
+ /* Putting of string/bytes values. Each string can consist of zero or more
+ * non-contiguous buffers of data.
+ *
+ * For StartString(), the function will write a sink for the string to "sub."
+ * The sub-sink must be used for any/all PutStringBuffer() calls. */
+ bool StartString(Handlers::Selector s, size_t size_hint, Sink* sub);
+ size_t PutStringBuffer(Handlers::Selector s, const char *buf, size_t len,
+ const BufferHandle *handle);
+ bool EndString(Handlers::Selector s);
+
+ /* For submessage fields.
+ *
+ * For StartSubMessage(), the function will write a sink for the string to
+ * "sub." The sub-sink must be used for any/all handlers called within the
+ * submessage. */
+ bool StartSubMessage(Handlers::Selector s, Sink* sub);
+ bool EndSubMessage(Handlers::Selector s);
+
+ /* For repeated fields of any type, the sequence of values must be wrapped in
+ * these calls.
+ *
+ * For StartSequence(), the function will write a sink for the string to
+ * "sub." The sub-sink must be used for any/all handlers called within the
+ * sequence. */
+ bool StartSequence(Handlers::Selector s, Sink* sub);
+ bool EndSequence(Handlers::Selector s);
+
+ /* Copy and assign specifically allowed.
+ * We don't even bother making these members private because so many
+ * functions need them and this is mainly just a dumb data container anyway.
+ */
+#else
+struct upb_sink {
+#endif
+ const upb_handlers *handlers;
+ void *closure;
+};
+
+#ifdef __cplusplus
+class upb::BytesSink {
+ public:
+ BytesSink() {}
+
+ /* Constructs a new sink for the given frozen handlers and closure.
+ *
+ * TODO(haberman): once the Handlers know the expected closure type, verify
+ * that T matches it. */
+ template <class T> BytesSink(const BytesHandler* handler, T* closure);
+
+ /* Resets the value of the sink. */
+ template <class T> void Reset(const BytesHandler* handler, T* closure);
+
+ bool Start(size_t size_hint, void **subc);
+ size_t PutBuffer(void *subc, const char *buf, size_t len,
+ const BufferHandle *handle);
+ bool End();
+#else
+struct upb_bytessink {
+#endif
+ const upb_byteshandler *handler;
+ void *closure;
+};
+
+#ifdef __cplusplus
+
+/* A class for pushing a flat buffer of data to a BytesSink.
+ * You can construct an instance of this to get a resumable source,
+ * or just call the static PutBuffer() to do a non-resumable push all in one
+ * go. */
+class upb::BufferSource {
+ public:
+ BufferSource();
+ BufferSource(const char* buf, size_t len, BytesSink* sink);
+
+ /* Returns true if the entire buffer was pushed successfully. Otherwise the
+ * next call to PutNext() will resume where the previous one left off.
+ * TODO(haberman): implement this. */
+ bool PutNext();
+
+ /* A static version; with this version is it not possible to resume in the
+ * case of failure or a partially-consumed buffer. */
+ static bool PutBuffer(const char* buf, size_t len, BytesSink* sink);
+
+ template <class T> static bool PutBuffer(const T& str, BytesSink* sink) {
+ return PutBuffer(str.c_str(), str.size(), sink);
+ }
+#else
+struct upb_bufsrc {
+ char dummy;
+#endif
+};
+
+UPB_BEGIN_EXTERN_C
+
+/* A class for accumulating output string data in a flat buffer. */
+
+upb_bufsink *upb_bufsink_new(upb_env *env);
+void upb_bufsink_free(upb_bufsink *sink);
+upb_bytessink *upb_bufsink_sink(upb_bufsink *sink);
+const char *upb_bufsink_getdata(const upb_bufsink *sink, size_t *len);
+
+/* Inline definitions. */
+
+UPB_INLINE void upb_bytessink_reset(upb_bytessink *s, const upb_byteshandler *h,
+ void *closure) {
+ s->handler = h;
+ s->closure = closure;
+}
+
+UPB_INLINE bool upb_bytessink_start(upb_bytessink *s, size_t size_hint,
+ void **subc) {
+ typedef upb_startstr_handlerfunc func;
+ func *start;
+ *subc = s->closure;
+ if (!s->handler) return true;
+ start = (func *)s->handler->table[UPB_STARTSTR_SELECTOR].func;
+
+ if (!start) return true;
+ *subc = start(s->closure, upb_handlerattr_handlerdata(
+ &s->handler->table[UPB_STARTSTR_SELECTOR].attr),
+ size_hint);
+ return *subc != NULL;
+}
+
+UPB_INLINE size_t upb_bytessink_putbuf(upb_bytessink *s, void *subc,
+ const char *buf, size_t size,
+ const upb_bufhandle* handle) {
+ typedef upb_string_handlerfunc func;
+ func *putbuf;
+ if (!s->handler) return true;
+ putbuf = (func *)s->handler->table[UPB_STRING_SELECTOR].func;
+
+ if (!putbuf) return true;
+ return putbuf(subc, upb_handlerattr_handlerdata(
+ &s->handler->table[UPB_STRING_SELECTOR].attr),
+ buf, size, handle);
+}
+
+UPB_INLINE bool upb_bytessink_end(upb_bytessink *s) {
+ typedef upb_endfield_handlerfunc func;
+ func *end;
+ if (!s->handler) return true;
+ end = (func *)s->handler->table[UPB_ENDSTR_SELECTOR].func;
+
+ if (!end) return true;
+ return end(s->closure,
+ upb_handlerattr_handlerdata(
+ &s->handler->table[UPB_ENDSTR_SELECTOR].attr));
+}
+
+bool upb_bufsrc_putbuf(const char *buf, size_t len, upb_bytessink *sink);
+
+#define PUTVAL(type, ctype) \
+ UPB_INLINE bool upb_sink_put##type(upb_sink *s, upb_selector_t sel, \
+ ctype val) { \
+ typedef upb_##type##_handlerfunc functype; \
+ functype *func; \
+ const void *hd; \
+ if (!s->handlers) return true; \
+ func = (functype *)upb_handlers_gethandler(s->handlers, sel); \
+ if (!func) return true; \
+ hd = upb_handlers_gethandlerdata(s->handlers, sel); \
+ return func(s->closure, hd, val); \
+ }
+
+PUTVAL(int32, int32_t)
+PUTVAL(int64, int64_t)
+PUTVAL(uint32, uint32_t)
+PUTVAL(uint64, uint64_t)
+PUTVAL(float, float)
+PUTVAL(double, double)
+PUTVAL(bool, bool)
+#undef PUTVAL
+
+UPB_INLINE void upb_sink_reset(upb_sink *s, const upb_handlers *h, void *c) {
+ s->handlers = h;
+ s->closure = c;
+}
+
+UPB_INLINE size_t upb_sink_putstring(upb_sink *s, upb_selector_t sel,
+ const char *buf, size_t n,
+ const upb_bufhandle *handle) {
+ typedef upb_string_handlerfunc func;
+ func *handler;
+ const void *hd;
+ if (!s->handlers) return n;
+ handler = (func *)upb_handlers_gethandler(s->handlers, sel);
+
+ if (!handler) return n;
+ hd = upb_handlers_gethandlerdata(s->handlers, sel);
+ return handler(s->closure, hd, buf, n, handle);
+}
+
+UPB_INLINE bool upb_sink_startmsg(upb_sink *s) {
+ typedef upb_startmsg_handlerfunc func;
+ func *startmsg;
+ const void *hd;
+ if (!s->handlers) return true;
+ startmsg = (func*)upb_handlers_gethandler(s->handlers, UPB_STARTMSG_SELECTOR);
+
+ if (!startmsg) return true;
+ hd = upb_handlers_gethandlerdata(s->handlers, UPB_STARTMSG_SELECTOR);
+ return startmsg(s->closure, hd);
+}
+
+UPB_INLINE bool upb_sink_endmsg(upb_sink *s, upb_status *status) {
+ typedef upb_endmsg_handlerfunc func;
+ func *endmsg;
+ const void *hd;
+ if (!s->handlers) return true;
+ endmsg = (func *)upb_handlers_gethandler(s->handlers, UPB_ENDMSG_SELECTOR);
+
+ if (!endmsg) return true;
+ hd = upb_handlers_gethandlerdata(s->handlers, UPB_ENDMSG_SELECTOR);
+ return endmsg(s->closure, hd, status);
+}
+
+UPB_INLINE bool upb_sink_startseq(upb_sink *s, upb_selector_t sel,
+ upb_sink *sub) {
+ typedef upb_startfield_handlerfunc func;
+ func *startseq;
+ const void *hd;
+ sub->closure = s->closure;
+ sub->handlers = s->handlers;
+ if (!s->handlers) return true;
+ startseq = (func*)upb_handlers_gethandler(s->handlers, sel);
+
+ if (!startseq) return true;
+ hd = upb_handlers_gethandlerdata(s->handlers, sel);
+ sub->closure = startseq(s->closure, hd);
+ return sub->closure ? true : false;
+}
+
+UPB_INLINE bool upb_sink_endseq(upb_sink *s, upb_selector_t sel) {
+ typedef upb_endfield_handlerfunc func;
+ func *endseq;
+ const void *hd;
+ if (!s->handlers) return true;
+ endseq = (func*)upb_handlers_gethandler(s->handlers, sel);
+
+ if (!endseq) return true;
+ hd = upb_handlers_gethandlerdata(s->handlers, sel);
+ return endseq(s->closure, hd);
+}
+
+UPB_INLINE bool upb_sink_startstr(upb_sink *s, upb_selector_t sel,
+ size_t size_hint, upb_sink *sub) {
+ typedef upb_startstr_handlerfunc func;
+ func *startstr;
+ const void *hd;
+ sub->closure = s->closure;
+ sub->handlers = s->handlers;
+ if (!s->handlers) return true;
+ startstr = (func*)upb_handlers_gethandler(s->handlers, sel);
+
+ if (!startstr) return true;
+ hd = upb_handlers_gethandlerdata(s->handlers, sel);
+ sub->closure = startstr(s->closure, hd, size_hint);
+ return sub->closure ? true : false;
+}
+
+UPB_INLINE bool upb_sink_endstr(upb_sink *s, upb_selector_t sel) {
+ typedef upb_endfield_handlerfunc func;
+ func *endstr;
+ const void *hd;
+ if (!s->handlers) return true;
+ endstr = (func*)upb_handlers_gethandler(s->handlers, sel);
+
+ if (!endstr) return true;
+ hd = upb_handlers_gethandlerdata(s->handlers, sel);
+ return endstr(s->closure, hd);
+}
+
+UPB_INLINE bool upb_sink_startsubmsg(upb_sink *s, upb_selector_t sel,
+ upb_sink *sub) {
+ typedef upb_startfield_handlerfunc func;
+ func *startsubmsg;
+ const void *hd;
+ sub->closure = s->closure;
+ if (!s->handlers) {
+ sub->handlers = NULL;
+ return true;
+ }
+ sub->handlers = upb_handlers_getsubhandlers_sel(s->handlers, sel);
+ startsubmsg = (func*)upb_handlers_gethandler(s->handlers, sel);
+
+ if (!startsubmsg) return true;
+ hd = upb_handlers_gethandlerdata(s->handlers, sel);
+ sub->closure = startsubmsg(s->closure, hd);
+ return sub->closure ? true : false;
+}
+
+UPB_INLINE bool upb_sink_endsubmsg(upb_sink *s, upb_selector_t sel) {
+ typedef upb_endfield_handlerfunc func;
+ func *endsubmsg;
+ const void *hd;
+ if (!s->handlers) return true;
+ endsubmsg = (func*)upb_handlers_gethandler(s->handlers, sel);
+
+ if (!endsubmsg) return s->closure;
+ hd = upb_handlers_gethandlerdata(s->handlers, sel);
+ return endsubmsg(s->closure, hd);
+}
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+namespace upb {
+
+template <class T> Sink::Sink(const Handlers* handlers, T* closure) {
+ upb_sink_reset(this, handlers, closure);
+}
+template <class T>
+inline void Sink::Reset(const Handlers* handlers, T* closure) {
+ upb_sink_reset(this, handlers, closure);
+}
+inline bool Sink::StartMessage() {
+ return upb_sink_startmsg(this);
+}
+inline bool Sink::EndMessage(Status* status) {
+ return upb_sink_endmsg(this, status);
+}
+inline bool Sink::PutInt32(Handlers::Selector sel, int32_t val) {
+ return upb_sink_putint32(this, sel, val);
+}
+inline bool Sink::PutInt64(Handlers::Selector sel, int64_t val) {
+ return upb_sink_putint64(this, sel, val);
+}
+inline bool Sink::PutUInt32(Handlers::Selector sel, uint32_t val) {
+ return upb_sink_putuint32(this, sel, val);
+}
+inline bool Sink::PutUInt64(Handlers::Selector sel, uint64_t val) {
+ return upb_sink_putuint64(this, sel, val);
+}
+inline bool Sink::PutFloat(Handlers::Selector sel, float val) {
+ return upb_sink_putfloat(this, sel, val);
+}
+inline bool Sink::PutDouble(Handlers::Selector sel, double val) {
+ return upb_sink_putdouble(this, sel, val);
+}
+inline bool Sink::PutBool(Handlers::Selector sel, bool val) {
+ return upb_sink_putbool(this, sel, val);
+}
+inline bool Sink::StartString(Handlers::Selector sel, size_t size_hint,
+ Sink *sub) {
+ return upb_sink_startstr(this, sel, size_hint, sub);
+}
+inline size_t Sink::PutStringBuffer(Handlers::Selector sel, const char *buf,
+ size_t len, const BufferHandle* handle) {
+ return upb_sink_putstring(this, sel, buf, len, handle);
+}
+inline bool Sink::EndString(Handlers::Selector sel) {
+ return upb_sink_endstr(this, sel);
+}
+inline bool Sink::StartSubMessage(Handlers::Selector sel, Sink* sub) {
+ return upb_sink_startsubmsg(this, sel, sub);
+}
+inline bool Sink::EndSubMessage(Handlers::Selector sel) {
+ return upb_sink_endsubmsg(this, sel);
+}
+inline bool Sink::StartSequence(Handlers::Selector sel, Sink* sub) {
+ return upb_sink_startseq(this, sel, sub);
+}
+inline bool Sink::EndSequence(Handlers::Selector sel) {
+ return upb_sink_endseq(this, sel);
+}
+
+template <class T>
+BytesSink::BytesSink(const BytesHandler* handler, T* closure) {
+ Reset(handler, closure);
+}
+
+template <class T>
+void BytesSink::Reset(const BytesHandler *handler, T *closure) {
+ upb_bytessink_reset(this, handler, closure);
+}
+inline bool BytesSink::Start(size_t size_hint, void **subc) {
+ return upb_bytessink_start(this, size_hint, subc);
+}
+inline size_t BytesSink::PutBuffer(void *subc, const char *buf, size_t len,
+ const BufferHandle *handle) {
+ return upb_bytessink_putbuf(this, subc, buf, len, handle);
+}
+inline bool BytesSink::End() {
+ return upb_bytessink_end(this);
+}
+
+inline bool BufferSource::PutBuffer(const char *buf, size_t len,
+ BytesSink *sink) {
+ return upb_bufsrc_putbuf(buf, len, sink);
+}
+
+} /* namespace upb */
+#endif
+
+#endif
+/*
+** upb::Message is a representation for protobuf messages.
+**
+** However it differs from other common representations like
+** google::protobuf::Message in one key way: it does not prescribe any
+** ownership between messages and submessages, and it relies on the
+** client to delete each message/submessage/array/map at the appropriate
+** time.
+**
+** A client can access a upb::Message without knowing anything about
+** ownership semantics, but to create or mutate a message a user needs
+** to implement the memory management themselves.
+**
+** Currently all messages, arrays, and maps store a upb_alloc* internally.
+** Mutating operations use this when they require dynamically-allocated
+** memory. We could potentially eliminate this size overhead later by
+** letting the user flip a bit on the factory that prevents this from
+** being stored. The user would then need to use separate functions where
+** the upb_alloc* is passed explicitly. However for handlers to populate
+** such structures, they would need a place to store this upb_alloc* during
+** parsing; upb_handlers don't currently have a good way to accommodate this.
+**
+** TODO: UTF-8 checking?
+**/
+
+#ifndef UPB_MSG_H_
+#define UPB_MSG_H_
+
+
+#ifdef __cplusplus
+
+namespace upb {
+class Array;
+class Map;
+class MapIterator;
+class MessageFactory;
+class MessageLayout;
+class Visitor;
+class VisitorPlan;
+}
+
+#endif
+
+UPB_DECLARE_TYPE(upb::MessageFactory, upb_msgfactory)
+UPB_DECLARE_TYPE(upb::MessageLayout, upb_msglayout)
+UPB_DECLARE_TYPE(upb::Array, upb_array)
+UPB_DECLARE_TYPE(upb::Map, upb_map)
+UPB_DECLARE_TYPE(upb::MapIterator, upb_mapiter)
+UPB_DECLARE_TYPE(upb::Visitor, upb_visitor)
+UPB_DECLARE_TYPE(upb::VisitorPlan, upb_visitorplan)
+
+/* TODO(haberman): C++ accessors */
+
+UPB_BEGIN_EXTERN_C
+
+typedef void upb_msg;
+
+
+/** upb_msglayout *************************************************************/
+
+/* upb_msglayout represents the memory layout of a given upb_msgdef. You get
+ * instances of this from a upb_msgfactory, and the factory always owns the
+ * msglayout. */
+
+/* Gets the factory for this layout */
+upb_msgfactory *upb_msglayout_factory(const upb_msglayout *l);
+
+/* Get the msglayout for a submessage. This requires that this field is a
+ * submessage, ie. upb_fielddef_issubmsg(upb_msglayout_msgdef(l)) == true.
+ *
+ * Since map entry messages don't have layouts, if upb_fielddef_ismap(f) == true
+ * then this function will return the layout for the map's value. It requires
+ * that the value type of the map field is a submessage. */
+const upb_msglayout *upb_msglayout_sublayout(const upb_msglayout *l,
+ const upb_fielddef *f);
+
+/* Returns the msgdef for this msglayout. */
+const upb_msgdef *upb_msglayout_msgdef(const upb_msglayout *l);
+
+
+/** upb_visitor ***************************************************************/
+
+/* upb_visitor will visit all the fields of a message and its submessages. It
+ * uses a upb_visitorplan which you can obtain from a upb_msgfactory. */
+
+upb_visitor *upb_visitor_create(upb_env *e, const upb_visitorplan *vp,
+ upb_sink *output);
+bool upb_visitor_visitmsg(upb_visitor *v, const upb_msg *msg);
+
+
+/** upb_msgfactory ************************************************************/
+
+/* A upb_msgfactory contains a cache of upb_msglayout, upb_handlers, and
+ * upb_visitorplan objects. These are the objects necessary to represent,
+ * populate, and and visit upb_msg objects.
+ *
+ * These caches are all populated by upb_msgdef, and lazily created on demand.
+ */
+
+/* Creates and destroys a msgfactory, respectively. The messages for this
+ * msgfactory must come from |symtab| (which should outlive the msgfactory). */
+upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab);
+void upb_msgfactory_free(upb_msgfactory *f);
+
+const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f);
+
+/* The functions to get cached objects, lazily creating them on demand. These
+ * all require:
+ *
+ * - m is in upb_msgfactory_symtab(f)
+ * - upb_msgdef_mapentry(m) == false (since map messages can't have layouts).
+ *
+ * The returned objects will live for as long as the msgfactory does.
+ *
+ * TODO(haberman): consider making this thread-safe and take a const
+ * upb_msgfactory. */
+const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f,
+ const upb_msgdef *m);
+const upb_handlers *upb_msgfactory_getmergehandlers(upb_msgfactory *f,
+ const upb_msgdef *m);
+const upb_visitorplan *upb_msgfactory_getvisitorplan(upb_msgfactory *f,
+ const upb_handlers *h);
+
+
+/** upb_msgval ****************************************************************/
+
+/* A union representing all possible protobuf values. Used for generic get/set
+ * operations. */
+
+typedef union {
+ bool b;
+ float flt;
+ double dbl;
+ int32_t i32;
+ int64_t i64;
+ uint32_t u32;
+ uint64_t u64;
+ const upb_map* map;
+ const upb_msg* msg;
+ const upb_array* arr;
+ const void* ptr;
+ struct {
+ const char *ptr;
+ size_t len;
+ } str;
+} upb_msgval;
+
+#define ACCESSORS(name, membername, ctype) \
+ UPB_INLINE ctype upb_msgval_get ## name(upb_msgval v) { \
+ return v.membername; \
+ } \
+ UPB_INLINE void upb_msgval_set ## name(upb_msgval *v, ctype cval) { \
+ v->membername = cval; \
+ } \
+ UPB_INLINE upb_msgval upb_msgval_ ## name(ctype v) { \
+ upb_msgval ret; \
+ ret.membername = v; \
+ return ret; \
+ }
+
+ACCESSORS(bool, b, bool)
+ACCESSORS(float, flt, float)
+ACCESSORS(double, dbl, double)
+ACCESSORS(int32, i32, int32_t)
+ACCESSORS(int64, i64, int64_t)
+ACCESSORS(uint32, u32, uint32_t)
+ACCESSORS(uint64, u64, uint64_t)
+ACCESSORS(map, map, const upb_map*)
+ACCESSORS(msg, msg, const upb_msg*)
+ACCESSORS(ptr, ptr, const void*)
+ACCESSORS(arr, arr, const upb_array*)
+
+#undef ACCESSORS
+
+UPB_INLINE upb_msgval upb_msgval_str(const char *ptr, size_t len) {
+ upb_msgval ret;
+ ret.str.ptr = ptr;
+ ret.str.len = len;
+ return ret;
+}
+
+UPB_INLINE const char* upb_msgval_getstr(upb_msgval val) {
+ return val.str.ptr;
+}
+
+UPB_INLINE size_t upb_msgval_getstrlen(upb_msgval val) {
+ return val.str.len;
+}
+
+
+/** upb_msg *******************************************************************/
+
+/* A upb_msg represents a protobuf message. It always corresponds to a specific
+ * upb_msglayout, which describes how it is laid out in memory.
+ *
+ * The message will have a fixed size, as returned by upb_msg_sizeof(), which
+ * will be used to store fixed-length fields. The upb_msg may also allocate
+ * dynamic memory internally to store data such as:
+ *
+ * - extensions
+ * - unknown fields
+ */
+
+/* Returns the size of a message given this layout. */
+size_t upb_msg_sizeof(const upb_msglayout *l);
+
+/* upb_msg_init() / upb_msg_uninit() allow the user to use a pre-allocated
+ * block of memory as a message. The block's size should be upb_msg_sizeof().
+ * upb_msg_uninit() must be called to release internally-allocated memory
+ * unless the allocator is an arena that does not require freeing.
+ *
+ * Please note that upb_msg_uninit() does *not* free any submessages, maps,
+ * or arrays referred to by this message's fields. You must free them manually
+ * yourself. */
+void upb_msg_init(upb_msg *msg, const upb_msglayout *l, upb_alloc *a);
+void upb_msg_uninit(upb_msg *msg, const upb_msglayout *l);
+
+/* Like upb_msg_init() / upb_msg_uninit(), except the message's memory is
+ * allocated / freed from the given upb_alloc. */
+upb_msg *upb_msg_new(const upb_msglayout *l, upb_alloc *a);
+void upb_msg_free(upb_msg *msg, const upb_msglayout *l);
+
+/* Returns the upb_alloc for the given message. */
+upb_alloc *upb_msg_alloc(const upb_msg *msg, const upb_msglayout *l);
+
+/* Packs the tree of messages rooted at "msg" into a single hunk of memory,
+ * allocated from the given allocator. */
+void *upb_msg_pack(const upb_msg *msg, const upb_msglayout *l,
+ void *p, size_t *ofs, size_t size);
+
+/* Read-only message API. Can be safely called by anyone. */
+
+/* Returns the value associated with this field:
+ * - for scalar fields (including strings), the value directly.
+ * - return upb_msg*, or upb_map* for msg/map.
+ * If the field is unset for these field types, returns NULL.
+ *
+ * TODO(haberman): should we let users store cached array/map/msg
+ * pointers here for fields that are unset? Could be useful for the
+ * strongly-owned submessage model (ie. generated C API that doesn't use
+ * arenas).
+ */
+upb_msgval upb_msg_get(const upb_msg *msg,
+ const upb_fielddef *f,
+ const upb_msglayout *l);
+
+/* May only be called for fields where upb_fielddef_haspresence(f) == true. */
+bool upb_msg_has(const upb_msg *msg,
+ const upb_fielddef *f,
+ const upb_msglayout *l);
+
+/* Returns NULL if no field in the oneof is set. */
+const upb_fielddef *upb_msg_getoneofcase(const upb_msg *msg,
+ const upb_oneofdef *o,
+ const upb_msglayout *l);
+
+/* Returns true if any field in the oneof is set. */
+bool upb_msg_hasoneof(const upb_msg *msg,
+ const upb_oneofdef *o,
+ const upb_msglayout *l);
+
+
+/* Mutable message API. May only be called by the owner of the message who
+ * knows its ownership scheme and how to keep it consistent. */
+
+/* Sets the given field to the given value. Does not perform any memory
+ * management: if you overwrite a pointer to a msg/array/map/string without
+ * cleaning it up (or using an arena) it will leak.
+ */
+bool upb_msg_set(upb_msg *msg,
+ const upb_fielddef *f,
+ upb_msgval val,
+ const upb_msglayout *l);
+
+/* For a primitive field, set it back to its default. For repeated, string, and
+ * submessage fields set it back to NULL. This could involve releasing some
+ * internal memory (for example, from an extension dictionary), but it is not
+ * recursive in any way and will not recover any memory that may be used by
+ * arrays/maps/strings/msgs that this field may have pointed to.
+ */
+bool upb_msg_clearfield(upb_msg *msg,
+ const upb_fielddef *f,
+ const upb_msglayout *l);
+
+/* Clears all fields in the oneof such that none of them are set. */
+bool upb_msg_clearoneof(upb_msg *msg,
+ const upb_oneofdef *o,
+ const upb_msglayout *l);
+
+/* TODO(haberman): copyfrom()/mergefrom()? */
+
+
+/** upb_array *****************************************************************/
+
+/* A upb_array stores data for a repeated field. The memory management
+ * semantics are the same as upb_msg. A upb_array allocates dynamic
+ * memory internally for the array elements. */
+
+size_t upb_array_sizeof(upb_fieldtype_t type);
+void upb_array_init(upb_array *arr, upb_fieldtype_t type, upb_alloc *a);
+void upb_array_uninit(upb_array *arr);
+upb_array *upb_array_new(upb_fieldtype_t type, upb_alloc *a);
+void upb_array_free(upb_array *arr);
+
+/* Read-only interface. Safe for anyone to call. */
+
+size_t upb_array_size(const upb_array *arr);
+upb_fieldtype_t upb_array_type(const upb_array *arr);
+upb_msgval upb_array_get(const upb_array *arr, size_t i);
+
+/* Write interface. May only be called by the message's owner who can enforce
+ * its memory management invariants. */
+
+bool upb_array_set(upb_array *arr, size_t i, upb_msgval val);
+
+
+/** upb_map *******************************************************************/
+
+/* A upb_map stores data for a map field. The memory management semantics are
+ * the same as upb_msg, with one notable exception. upb_map will internally
+ * store a copy of all string keys, but *not* any string values or submessages.
+ * So you must ensure that any string or message values outlive the map, and you
+ * must delete them manually when they are no longer required. */
+
+size_t upb_map_sizeof(upb_fieldtype_t ktype, upb_fieldtype_t vtype);
+bool upb_map_init(upb_map *map, upb_fieldtype_t ktype, upb_fieldtype_t vtype,
+ upb_alloc *a);
+void upb_map_uninit(upb_map *map);
+upb_map *upb_map_new(upb_fieldtype_t ktype, upb_fieldtype_t vtype, upb_alloc *a);
+void upb_map_free(upb_map *map);
+
+/* Read-only interface. Safe for anyone to call. */
+
+size_t upb_map_size(const upb_map *map);
+upb_fieldtype_t upb_map_keytype(const upb_map *map);
+upb_fieldtype_t upb_map_valuetype(const upb_map *map);
+bool upb_map_get(const upb_map *map, upb_msgval key, upb_msgval *val);
+
+/* Write interface. May only be called by the message's owner who can enforce
+ * its memory management invariants. */
+
+/* Sets or overwrites an entry in the map. Return value indicates whether
+ * the operation succeeded or failed with OOM, and also whether an existing
+ * key was replaced or not. */
+bool upb_map_set(upb_map *map,
+ upb_msgval key, upb_msgval val,
+ upb_msgval *valremoved);
+
+/* Deletes an entry in the map. Returns true if the key was present. */
+bool upb_map_del(upb_map *map, upb_msgval key);
+
+
+/** upb_mapiter ***************************************************************/
+
+/* For iterating over a map. Map iterators are invalidated by mutations to the
+ * map, but an invalidated iterator will never return junk or crash the process.
+ * An invalidated iterator may return entries that were already returned though,
+ * and if you keep invalidating the iterator during iteration, the program may
+ * enter an infinite loop. */
+
+size_t upb_mapiter_sizeof();
+
+void upb_mapiter_begin(upb_mapiter *i, const upb_map *t);
+upb_mapiter *upb_mapiter_new(const upb_map *t, upb_alloc *a);
+void upb_mapiter_free(upb_mapiter *i, upb_alloc *a);
+void upb_mapiter_next(upb_mapiter *i);
+bool upb_mapiter_done(const upb_mapiter *i);
+
+upb_msgval upb_mapiter_key(const upb_mapiter *i);
+upb_msgval upb_mapiter_value(const upb_mapiter *i);
+void upb_mapiter_setdone(upb_mapiter *i);
+bool upb_mapiter_isequal(const upb_mapiter *i1, const upb_mapiter *i2);
+
+
+/** Handlers ******************************************************************/
+
+/* These are the handlers used internally by upb_msgfactory_getmergehandlers().
+ * They write scalar data to a known offset from the message pointer.
+ *
+ * These would be trivial for anyone to implement themselves, but it's better
+ * to use these because some JITs will recognize and specialize these instead
+ * of actually calling the function. */
+
+/* Sets a handler for the given primitive field that will write the data at the
+ * given offset. If hasbit > 0, also sets a hasbit at the given bit offset
+ * (addressing each byte low to high). */
+bool upb_msg_setscalarhandler(upb_handlers *h,
+ const upb_fielddef *f,
+ size_t offset,
+ int32_t hasbit);
+
+/* If the given handler is a msghandlers_primitive field, returns true and sets
+ * *type, *offset and *hasbit. Otherwise returns false. */
+bool upb_msg_getscalarhandlerdata(const upb_handlers *h,
+ upb_selector_t s,
+ upb_fieldtype_t *type,
+ size_t *offset,
+ int32_t *hasbit);
+
+UPB_END_EXTERN_C
+
+#endif /* UPB_MSG_H_ */
+/*
+** upb::descriptor::Reader (upb_descreader)
+**
+** Provides a way of building upb::Defs from data in descriptor.proto format.
+*/
+
+#ifndef UPB_DESCRIPTOR_H
+#define UPB_DESCRIPTOR_H
+
+
+#ifdef __cplusplus
+namespace upb {
+namespace descriptor {
+class Reader;
+} /* namespace descriptor */
+} /* namespace upb */
+#endif
+
+UPB_DECLARE_TYPE(upb::descriptor::Reader, upb_descreader)
+
+#ifdef __cplusplus
+
+/* Class that receives descriptor data according to the descriptor.proto schema
+ * and use it to build upb::Defs corresponding to that schema. */
+class upb::descriptor::Reader {
+ public:
+ /* These handlers must have come from NewHandlers() and must outlive the
+ * Reader.
+ *
+ * TODO: generate the handlers statically (like we do with the
+ * descriptor.proto defs) so that there is no need to pass this parameter (or
+ * to build/memory-manage the handlers at runtime at all). Unfortunately this
+ * is a bit tricky to implement for Handlers, but necessary to simplify this
+ * interface. */
+ static Reader* Create(Environment* env, const Handlers* handlers);
+
+ /* The reader's input; this is where descriptor.proto data should be sent. */
+ Sink* input();
+
+ /* Use to get the FileDefs that have been parsed. */
+ size_t file_count() const;
+ FileDef* file(size_t i) const;
+
+ /* Builds and returns handlers for the reader, owned by "owner." */
+ static Handlers* NewHandlers(const void* owner);
+
+ private:
+ UPB_DISALLOW_POD_OPS(Reader, upb::descriptor::Reader)
+};
+
+#endif
+
+UPB_BEGIN_EXTERN_C
+
+/* C API. */
+upb_descreader *upb_descreader_create(upb_env *e, const upb_handlers *h);
+upb_sink *upb_descreader_input(upb_descreader *r);
+size_t upb_descreader_filecount(const upb_descreader *r);
+upb_filedef *upb_descreader_file(const upb_descreader *r, size_t i);
+const upb_handlers *upb_descreader_newhandlers(const void *owner);
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+/* C++ implementation details. ************************************************/
+namespace upb {
+namespace descriptor {
+inline Reader* Reader::Create(Environment* e, const Handlers *h) {
+ return upb_descreader_create(e, h);
+}
+inline Sink* Reader::input() { return upb_descreader_input(this); }
+inline size_t Reader::file_count() const {
+ return upb_descreader_filecount(this);
+}
+inline FileDef* Reader::file(size_t i) const {
+ return upb_descreader_file(this, i);
+}
+} /* namespace descriptor */
+} /* namespace upb */
+#endif
+
+#endif /* UPB_DESCRIPTOR_H */
+/* This file contains accessors for a set of compiled-in defs.
+ * Note that unlike Google's protobuf, it does *not* define
+ * generated classes or any other kind of data structure for
+ * actually storing protobufs. It only contains *defs* which
+ * let you reflect over a protobuf *schema*.
+ */
+/* This file was generated by upbc (the upb compiler) from the input
+ * file:
+ *
+ * upb/descriptor/descriptor.proto
+ *
+ * Do not edit -- your changes will be discarded when the file is
+ * regenerated. */
+
+#ifndef UPB_DESCRIPTOR_DESCRIPTOR_PROTO_UPB_H_
+#define UPB_DESCRIPTOR_DESCRIPTOR_PROTO_UPB_H_
+
+
+UPB_BEGIN_EXTERN_C
+
+/* Enums */
+
+typedef enum {
+ google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1,
+ google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2,
+ google_protobuf_FieldDescriptorProto_LABEL_REPEATED = 3
+} google_protobuf_FieldDescriptorProto_Label;
+
+typedef enum {
+ google_protobuf_FieldDescriptorProto_TYPE_DOUBLE = 1,
+ google_protobuf_FieldDescriptorProto_TYPE_FLOAT = 2,
+ google_protobuf_FieldDescriptorProto_TYPE_INT64 = 3,
+ google_protobuf_FieldDescriptorProto_TYPE_UINT64 = 4,
+ google_protobuf_FieldDescriptorProto_TYPE_INT32 = 5,
+ google_protobuf_FieldDescriptorProto_TYPE_FIXED64 = 6,
+ google_protobuf_FieldDescriptorProto_TYPE_FIXED32 = 7,
+ google_protobuf_FieldDescriptorProto_TYPE_BOOL = 8,
+ google_protobuf_FieldDescriptorProto_TYPE_STRING = 9,
+ google_protobuf_FieldDescriptorProto_TYPE_GROUP = 10,
+ google_protobuf_FieldDescriptorProto_TYPE_MESSAGE = 11,
+ google_protobuf_FieldDescriptorProto_TYPE_BYTES = 12,
+ google_protobuf_FieldDescriptorProto_TYPE_UINT32 = 13,
+ google_protobuf_FieldDescriptorProto_TYPE_ENUM = 14,
+ google_protobuf_FieldDescriptorProto_TYPE_SFIXED32 = 15,
+ google_protobuf_FieldDescriptorProto_TYPE_SFIXED64 = 16,
+ google_protobuf_FieldDescriptorProto_TYPE_SINT32 = 17,
+ google_protobuf_FieldDescriptorProto_TYPE_SINT64 = 18
+} google_protobuf_FieldDescriptorProto_Type;
+
+typedef enum {
+ google_protobuf_FieldOptions_STRING = 0,
+ google_protobuf_FieldOptions_CORD = 1,
+ google_protobuf_FieldOptions_STRING_PIECE = 2
+} google_protobuf_FieldOptions_CType;
+
+typedef enum {
+ google_protobuf_FieldOptions_JS_NORMAL = 0,
+ google_protobuf_FieldOptions_JS_STRING = 1,
+ google_protobuf_FieldOptions_JS_NUMBER = 2
+} google_protobuf_FieldOptions_JSType;
+
+typedef enum {
+ google_protobuf_FileOptions_SPEED = 1,
+ google_protobuf_FileOptions_CODE_SIZE = 2,
+ google_protobuf_FileOptions_LITE_RUNTIME = 3
+} google_protobuf_FileOptions_OptimizeMode;
+
+/* MessageDefs: call these functions to get a ref to a msgdef. */
+const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ReservedRange_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_EnumDescriptorProto_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_EnumOptions_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_EnumValueDescriptorProto_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_EnumValueOptions_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_FieldDescriptorProto_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_FieldOptions_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_FileDescriptorProto_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_FileDescriptorSet_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_FileOptions_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_MessageOptions_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_MethodDescriptorProto_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_MethodOptions_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_OneofDescriptorProto_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_ServiceDescriptorProto_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_ServiceOptions_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo_Location_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption_NamePart_get(const void *owner);
+
+/* EnumDefs: call these functions to get a ref to an enumdef. */
+const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Label_get(const void *owner);
+const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Type_get(const void *owner);
+const upb_enumdef *upbdefs_google_protobuf_FieldOptions_CType_get(const void *owner);
+const upb_enumdef *upbdefs_google_protobuf_FieldOptions_JSType_get(const void *owner);
+const upb_enumdef *upbdefs_google_protobuf_FileOptions_OptimizeMode_get(const void *owner);
+
+/* Functions to test whether this message is of a certain type. */
+UPB_INLINE bool upbdefs_google_protobuf_DescriptorProto_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.DescriptorProto") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_DescriptorProto_ExtensionRange_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.DescriptorProto.ExtensionRange") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_DescriptorProto_ReservedRange_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.DescriptorProto.ReservedRange") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_EnumDescriptorProto_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.EnumDescriptorProto") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_EnumOptions_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.EnumOptions") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_EnumValueDescriptorProto_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.EnumValueDescriptorProto") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_EnumValueOptions_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.EnumValueOptions") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FieldDescriptorProto_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.FieldDescriptorProto") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FieldOptions_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.FieldOptions") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FileDescriptorProto_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.FileDescriptorProto") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FileDescriptorSet_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.FileDescriptorSet") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FileOptions_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.FileOptions") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_MessageOptions_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.MessageOptions") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_MethodDescriptorProto_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.MethodDescriptorProto") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_MethodOptions_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.MethodOptions") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_OneofDescriptorProto_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.OneofDescriptorProto") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_ServiceDescriptorProto_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.ServiceDescriptorProto") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_ServiceOptions_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.ServiceOptions") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_SourceCodeInfo_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.SourceCodeInfo") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_SourceCodeInfo_Location_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.SourceCodeInfo.Location") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_UninterpretedOption_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.UninterpretedOption") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_UninterpretedOption_NamePart_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.UninterpretedOption.NamePart") == 0;
+}
+
+/* Functions to test whether this enum is of a certain type. */
+UPB_INLINE bool upbdefs_google_protobuf_FieldDescriptorProto_Label_is(const upb_enumdef *e) {
+ return strcmp(upb_enumdef_fullname(e), "google.protobuf.FieldDescriptorProto.Label") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FieldDescriptorProto_Type_is(const upb_enumdef *e) {
+ return strcmp(upb_enumdef_fullname(e), "google.protobuf.FieldDescriptorProto.Type") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FieldOptions_CType_is(const upb_enumdef *e) {
+ return strcmp(upb_enumdef_fullname(e), "google.protobuf.FieldOptions.CType") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FieldOptions_JSType_is(const upb_enumdef *e) {
+ return strcmp(upb_enumdef_fullname(e), "google.protobuf.FieldOptions.JSType") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FileOptions_OptimizeMode_is(const upb_enumdef *e) {
+ return strcmp(upb_enumdef_fullname(e), "google.protobuf.FileOptions.OptimizeMode") == 0;
+}
+
+
+/* Functions to get a fielddef from a msgdef reference. */
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_f_end(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ExtensionRange_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_f_start(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ExtensionRange_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ReservedRange_f_end(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ReservedRange_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ReservedRange_f_start(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ReservedRange_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_enum_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 4); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_extension(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 6); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_extension_range(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 5); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_field(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_nested_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_oneof_decl(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 8); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 7); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_reserved_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 10); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_reserved_range(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 9); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_f_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumOptions_f_allow_alias(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumOptions_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumOptions_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumOptions_is(m)); return upb_msgdef_itof(m, 999); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_f_number(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueOptions_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueOptions_is(m)); return upb_msgdef_itof(m, 999); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_default_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 7); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_extendee(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_json_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 10); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_label(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 4); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_number(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_oneof_index(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 9); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 8); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 5); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_type_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 6); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_ctype(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_jstype(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 6); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_lazy(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 5); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_packed(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 999); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_weak(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 10); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_dependency(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_enum_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 5); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_extension(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 7); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_message_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 4); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 8); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_package(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_public_dependency(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 10); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_service(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 6); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_source_code_info(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 9); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_syntax(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 12); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_weak_dependency(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 11); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorSet_f_file(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorSet_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_cc_enable_arenas(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 31); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_cc_generic_services(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 16); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_csharp_namespace(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 37); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 23); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_go_package(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 11); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_generate_equals_and_hash(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 20); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_generic_services(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 17); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_multiple_files(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 10); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_outer_classname(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 8); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_package(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_string_check_utf8(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 27); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_javanano_use_deprecated_package(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 38); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_objc_class_prefix(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 36); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_optimize_for(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 9); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_php_class_prefix(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 40); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_py_generic_services(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 18); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 999); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_map_entry(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m)); return upb_msgdef_itof(m, 7); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_message_set_wire_format(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_no_standard_descriptor_accessor(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m)); return upb_msgdef_itof(m, 999); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_client_streaming(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 5); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_input_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 4); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_output_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_server_streaming(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 6); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodOptions_is(m)); return upb_msgdef_itof(m, 33); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodOptions_is(m)); return upb_msgdef_itof(m, 999); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_OneofDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_OneofDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_f_method(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceOptions_is(m)); return upb_msgdef_itof(m, 33); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceOptions_is(m)); return upb_msgdef_itof(m, 999); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f_leading_comments(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f_leading_detached_comments(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 6); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f_path(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f_span(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f_trailing_comments(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 4); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_f_location(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_NamePart_f_is_extension(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_NamePart_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_NamePart_f_name_part(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_NamePart_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_aggregate_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 8); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_double_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 6); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_identifier_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_negative_int_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 5); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_positive_int_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 4); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_string_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 7); }
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+namespace upbdefs {
+namespace google {
+namespace protobuf {
+
+class DescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ DescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m));
+ }
+
+ static DescriptorProto get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_get(&m);
+ return DescriptorProto(m, &m);
+ }
+
+ class ExtensionRange : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ ExtensionRange(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ExtensionRange_is(m));
+ }
+
+ static ExtensionRange get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_ExtensionRange_get(&m);
+ return ExtensionRange(m, &m);
+ }
+ };
+
+ class ReservedRange : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ ReservedRange(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ReservedRange_is(m));
+ }
+
+ static ReservedRange get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_ReservedRange_get(&m);
+ return ReservedRange(m, &m);
+ }
+ };
+};
+
+class EnumDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ EnumDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_EnumDescriptorProto_is(m));
+ }
+
+ static EnumDescriptorProto get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumDescriptorProto_get(&m);
+ return EnumDescriptorProto(m, &m);
+ }
+};
+
+class EnumOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ EnumOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_EnumOptions_is(m));
+ }
+
+ static EnumOptions get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumOptions_get(&m);
+ return EnumOptions(m, &m);
+ }
+};
+
+class EnumValueDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ EnumValueDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_EnumValueDescriptorProto_is(m));
+ }
+
+ static EnumValueDescriptorProto get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumValueDescriptorProto_get(&m);
+ return EnumValueDescriptorProto(m, &m);
+ }
+};
+
+class EnumValueOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ EnumValueOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_EnumValueOptions_is(m));
+ }
+
+ static EnumValueOptions get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumValueOptions_get(&m);
+ return EnumValueOptions(m, &m);
+ }
+};
+
+class FieldDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ FieldDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m));
+ }
+
+ static FieldDescriptorProto get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_FieldDescriptorProto_get(&m);
+ return FieldDescriptorProto(m, &m);
+ }
+
+ class Label : public ::upb::reffed_ptr<const ::upb::EnumDef> {
+ public:
+ Label(const ::upb::EnumDef* e, const void *ref_donor = NULL)
+ : reffed_ptr(e, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_Label_is(e));
+ }
+ static Label get() {
+ const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldDescriptorProto_Label_get(&e);
+ return Label(e, &e);
+ }
+ };
+
+ class Type : public ::upb::reffed_ptr<const ::upb::EnumDef> {
+ public:
+ Type(const ::upb::EnumDef* e, const void *ref_donor = NULL)
+ : reffed_ptr(e, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_Type_is(e));
+ }
+ static Type get() {
+ const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldDescriptorProto_Type_get(&e);
+ return Type(e, &e);
+ }
+ };
+};
+
+class FieldOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ FieldOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m));
+ }
+
+ static FieldOptions get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_FieldOptions_get(&m);
+ return FieldOptions(m, &m);
+ }
+
+ class CType : public ::upb::reffed_ptr<const ::upb::EnumDef> {
+ public:
+ CType(const ::upb::EnumDef* e, const void *ref_donor = NULL)
+ : reffed_ptr(e, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_CType_is(e));
+ }
+ static CType get() {
+ const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldOptions_CType_get(&e);
+ return CType(e, &e);
+ }
+ };
+
+ class JSType : public ::upb::reffed_ptr<const ::upb::EnumDef> {
+ public:
+ JSType(const ::upb::EnumDef* e, const void *ref_donor = NULL)
+ : reffed_ptr(e, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_JSType_is(e));
+ }
+ static JSType get() {
+ const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldOptions_JSType_get(&e);
+ return JSType(e, &e);
+ }
+ };
+};
+
+class FileDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ FileDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m));
+ }
+
+ static FileDescriptorProto get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_FileDescriptorProto_get(&m);
+ return FileDescriptorProto(m, &m);
+ }
+};
+
+class FileDescriptorSet : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ FileDescriptorSet(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorSet_is(m));
+ }
+
+ static FileDescriptorSet get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_FileDescriptorSet_get(&m);
+ return FileDescriptorSet(m, &m);
+ }
+};
+
+class FileOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ FileOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m));
+ }
+
+ static FileOptions get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_FileOptions_get(&m);
+ return FileOptions(m, &m);
+ }
+
+ class OptimizeMode : public ::upb::reffed_ptr<const ::upb::EnumDef> {
+ public:
+ OptimizeMode(const ::upb::EnumDef* e, const void *ref_donor = NULL)
+ : reffed_ptr(e, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FileOptions_OptimizeMode_is(e));
+ }
+ static OptimizeMode get() {
+ const ::upb::EnumDef* e = upbdefs_google_protobuf_FileOptions_OptimizeMode_get(&e);
+ return OptimizeMode(e, &e);
+ }
+ };
+};
+
+class MessageOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ MessageOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m));
+ }
+
+ static MessageOptions get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_MessageOptions_get(&m);
+ return MessageOptions(m, &m);
+ }
+};
+
+class MethodDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ MethodDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m));
+ }
+
+ static MethodDescriptorProto get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_MethodDescriptorProto_get(&m);
+ return MethodDescriptorProto(m, &m);
+ }
+};
+
+class MethodOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ MethodOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_MethodOptions_is(m));
+ }
+
+ static MethodOptions get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_MethodOptions_get(&m);
+ return MethodOptions(m, &m);
+ }
+};
+
+class OneofDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ OneofDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_OneofDescriptorProto_is(m));
+ }
+
+ static OneofDescriptorProto get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_OneofDescriptorProto_get(&m);
+ return OneofDescriptorProto(m, &m);
+ }
+};
+
+class ServiceDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ ServiceDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_ServiceDescriptorProto_is(m));
+ }
+
+ static ServiceDescriptorProto get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_ServiceDescriptorProto_get(&m);
+ return ServiceDescriptorProto(m, &m);
+ }
+};
+
+class ServiceOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ ServiceOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_ServiceOptions_is(m));
+ }
+
+ static ServiceOptions get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_ServiceOptions_get(&m);
+ return ServiceOptions(m, &m);
+ }
+};
+
+class SourceCodeInfo : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ SourceCodeInfo(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_is(m));
+ }
+
+ static SourceCodeInfo get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_SourceCodeInfo_get(&m);
+ return SourceCodeInfo(m, &m);
+ }
+
+ class Location : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ Location(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m));
+ }
+
+ static Location get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_SourceCodeInfo_Location_get(&m);
+ return Location(m, &m);
+ }
+ };
+};
+
+class UninterpretedOption : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ UninterpretedOption(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m));
+ }
+
+ static UninterpretedOption get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_UninterpretedOption_get(&m);
+ return UninterpretedOption(m, &m);
+ }
+
+ class NamePart : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ NamePart(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_NamePart_is(m));
+ }
+
+ static NamePart get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_UninterpretedOption_NamePart_get(&m);
+ return NamePart(m, &m);
+ }
+ };
+};
+
+} /* namespace protobuf */
+} /* namespace google */
+} /* namespace upbdefs */
+
+#endif /* __cplusplus */
+
+#endif /* UPB_DESCRIPTOR_DESCRIPTOR_PROTO_UPB_H_ */
+/*
+** Internal-only definitions for the decoder.
+*/
+
+#ifndef UPB_DECODER_INT_H_
+#define UPB_DECODER_INT_H_
+
+/*
+** upb::pb::Decoder
+**
+** A high performance, streaming, resumable decoder for the binary protobuf
+** format.
+**
+** This interface works the same regardless of what decoder backend is being
+** used. A client of this class does not need to know whether decoding is using
+** a JITted decoder (DynASM, LLVM, etc) or an interpreted decoder. By default,
+** it will always use the fastest available decoder. However, you can call
+** set_allow_jit(false) to disable any JIT decoder that might be available.
+** This is primarily useful for testing purposes.
+*/
+
+#ifndef UPB_DECODER_H_
+#define UPB_DECODER_H_
+
+
+#ifdef __cplusplus
+namespace upb {
+namespace pb {
+class CodeCache;
+class Decoder;
+class DecoderMethod;
+class DecoderMethodOptions;
+} /* namespace pb */
+} /* namespace upb */
+#endif
+
+UPB_DECLARE_TYPE(upb::pb::CodeCache, upb_pbcodecache)
+UPB_DECLARE_TYPE(upb::pb::Decoder, upb_pbdecoder)
+UPB_DECLARE_TYPE(upb::pb::DecoderMethodOptions, upb_pbdecodermethodopts)
+
+UPB_DECLARE_DERIVED_TYPE(upb::pb::DecoderMethod, upb::RefCounted,
+ upb_pbdecodermethod, upb_refcounted)
+
+/* The maximum number of bytes we are required to buffer internally between
+ * calls to the decoder. The value is 14: a 5 byte unknown tag plus ten-byte
+ * varint, less one because we are buffering an incomplete value.
+ *
+ * Should only be used by unit tests. */
+#define UPB_DECODER_MAX_RESIDUAL_BYTES 14
+
+#ifdef __cplusplus
+
+/* The parameters one uses to construct a DecoderMethod.
+ * TODO(haberman): move allowjit here? Seems more convenient for users.
+ * TODO(haberman): move this to be heap allocated for ABI stability. */
+class upb::pb::DecoderMethodOptions {
+ public:
+ /* Parameter represents the destination handlers that this method will push
+ * to. */
+ explicit DecoderMethodOptions(const Handlers* dest_handlers);
+
+ /* Should the decoder push submessages to lazy handlers for fields that have
+ * them? The caller should set this iff the lazy handlers expect data that is
+ * in protobuf binary format and the caller wishes to lazy parse it. */
+ void set_lazy(bool lazy);
+#else
+struct upb_pbdecodermethodopts {
+#endif
+ const upb_handlers *handlers;
+ bool lazy;
+};
+
+#ifdef __cplusplus
+
+/* Represents the code to parse a protobuf according to a destination
+ * Handlers. */
+class upb::pb::DecoderMethod {
+ public:
+ /* Include base methods from upb::ReferenceCounted. */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ /* The destination handlers that are statically bound to this method.
+ * This method is only capable of outputting to a sink that uses these
+ * handlers. */
+ const Handlers* dest_handlers() const;
+
+ /* The input handlers for this decoder method. */
+ const BytesHandler* input_handler() const;
+
+ /* Whether this method is native. */
+ bool is_native() const;
+
+ /* Convenience method for generating a DecoderMethod without explicitly
+ * creating a CodeCache. */
+ static reffed_ptr<const DecoderMethod> New(const DecoderMethodOptions& opts);
+
+ private:
+ UPB_DISALLOW_POD_OPS(DecoderMethod, upb::pb::DecoderMethod)
+};
+
+#endif
+
+/* Preallocation hint: decoder won't allocate more bytes than this when first
+ * constructed. This hint may be an overestimate for some build configurations.
+ * But if the decoder library is upgraded without recompiling the application,
+ * it may be an underestimate. */
+#define UPB_PB_DECODER_SIZE 4416
+
+#ifdef __cplusplus
+
+/* A Decoder receives binary protobuf data on its input sink and pushes the
+ * decoded data to its output sink. */
+class upb::pb::Decoder {
+ public:
+ /* Constructs a decoder instance for the given method, which must outlive this
+ * decoder. Any errors during parsing will be set on the given status, which
+ * must also outlive this decoder.
+ *
+ * The sink must match the given method. */
+ static Decoder* Create(Environment* env, const DecoderMethod* method,
+ Sink* output);
+
+ /* Returns the DecoderMethod this decoder is parsing from. */
+ const DecoderMethod* method() const;
+
+ /* The sink on which this decoder receives input. */
+ BytesSink* input();
+
+ /* Returns number of bytes successfully parsed.
+ *
+ * This can be useful for determining the stream position where an error
+ * occurred.
+ *
+ * This value may not be up-to-date when called from inside a parsing
+ * callback. */
+ uint64_t BytesParsed() const;
+
+ /* Gets/sets the parsing nexting limit. If the total number of nested
+ * submessages and repeated fields hits this limit, parsing will fail. This
+ * is a resource limit that controls the amount of memory used by the parsing
+ * stack.
+ *
+ * Setting the limit will fail if the parser is currently suspended at a depth
+ * greater than this, or if memory allocation of the stack fails. */
+ size_t max_nesting() const;
+ bool set_max_nesting(size_t max);
+
+ void Reset();
+
+ static const size_t kSize = UPB_PB_DECODER_SIZE;
+
+ private:
+ UPB_DISALLOW_POD_OPS(Decoder, upb::pb::Decoder)
+};
+
+#endif /* __cplusplus */
+
+#ifdef __cplusplus
+
+/* A class for caching protobuf processing code, whether bytecode for the
+ * interpreted decoder or machine code for the JIT.
+ *
+ * This class is not thread-safe.
+ *
+ * TODO(haberman): move this to be heap allocated for ABI stability. */
+class upb::pb::CodeCache {
+ public:
+ CodeCache();
+ ~CodeCache();
+
+ /* Whether the cache is allowed to generate machine code. Defaults to true.
+ * There is no real reason to turn it off except for testing or if you are
+ * having a specific problem with the JIT.
+ *
+ * Note that allow_jit = true does not *guarantee* that the code will be JIT
+ * compiled. If this platform is not supported or the JIT was not compiled
+ * in, the code may still be interpreted. */
+ bool allow_jit() const;
+
+ /* This may only be called when the object is first constructed, and prior to
+ * any code generation, otherwise returns false and does nothing. */
+ bool set_allow_jit(bool allow);
+
+ /* Returns a DecoderMethod that can push data to the given handlers.
+ * If a suitable method already exists, it will be returned from the cache.
+ *
+ * Specifying the destination handlers here allows the DecoderMethod to be
+ * statically bound to the destination handlers if possible, which can allow
+ * more efficient decoding. However the returned method may or may not
+ * actually be statically bound. But in all cases, the returned method can
+ * push data to the given handlers. */
+ const DecoderMethod *GetDecoderMethod(const DecoderMethodOptions& opts);
+
+ /* If/when someone needs to explicitly create a dynamically-bound
+ * DecoderMethod*, we can add a method to get it here. */
+
+ private:
+ UPB_DISALLOW_COPY_AND_ASSIGN(CodeCache)
+#else
+struct upb_pbcodecache {
+#endif
+ bool allow_jit_;
+
+ /* Array of mgroups. */
+ upb_inttable groups;
+};
+
+UPB_BEGIN_EXTERN_C
+
+upb_pbdecoder *upb_pbdecoder_create(upb_env *e,
+ const upb_pbdecodermethod *method,
+ upb_sink *output);
+const upb_pbdecodermethod *upb_pbdecoder_method(const upb_pbdecoder *d);
+upb_bytessink *upb_pbdecoder_input(upb_pbdecoder *d);
+uint64_t upb_pbdecoder_bytesparsed(const upb_pbdecoder *d);
+size_t upb_pbdecoder_maxnesting(const upb_pbdecoder *d);
+bool upb_pbdecoder_setmaxnesting(upb_pbdecoder *d, size_t max);
+void upb_pbdecoder_reset(upb_pbdecoder *d);
+
+void upb_pbdecodermethodopts_init(upb_pbdecodermethodopts *opts,
+ const upb_handlers *h);
+void upb_pbdecodermethodopts_setlazy(upb_pbdecodermethodopts *opts, bool lazy);
+
+
+/* Include refcounted methods like upb_pbdecodermethod_ref(). */
+UPB_REFCOUNTED_CMETHODS(upb_pbdecodermethod, upb_pbdecodermethod_upcast)
+
+const upb_handlers *upb_pbdecodermethod_desthandlers(
+ const upb_pbdecodermethod *m);
+const upb_byteshandler *upb_pbdecodermethod_inputhandler(
+ const upb_pbdecodermethod *m);
+bool upb_pbdecodermethod_isnative(const upb_pbdecodermethod *m);
+const upb_pbdecodermethod *upb_pbdecodermethod_new(
+ const upb_pbdecodermethodopts *opts, const void *owner);
+
+void upb_pbcodecache_init(upb_pbcodecache *c);
+void upb_pbcodecache_uninit(upb_pbcodecache *c);
+bool upb_pbcodecache_allowjit(const upb_pbcodecache *c);
+bool upb_pbcodecache_setallowjit(upb_pbcodecache *c, bool allow);
+const upb_pbdecodermethod *upb_pbcodecache_getdecodermethod(
+ upb_pbcodecache *c, const upb_pbdecodermethodopts *opts);
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+namespace upb {
+
+namespace pb {
+
+/* static */
+inline Decoder* Decoder::Create(Environment* env, const DecoderMethod* m,
+ Sink* sink) {
+ return upb_pbdecoder_create(env, m, sink);
+}
+inline const DecoderMethod* Decoder::method() const {
+ return upb_pbdecoder_method(this);
+}
+inline BytesSink* Decoder::input() {
+ return upb_pbdecoder_input(this);
+}
+inline uint64_t Decoder::BytesParsed() const {
+ return upb_pbdecoder_bytesparsed(this);
+}
+inline size_t Decoder::max_nesting() const {
+ return upb_pbdecoder_maxnesting(this);
+}
+inline bool Decoder::set_max_nesting(size_t max) {
+ return upb_pbdecoder_setmaxnesting(this, max);
+}
+inline void Decoder::Reset() { upb_pbdecoder_reset(this); }
+
+inline DecoderMethodOptions::DecoderMethodOptions(const Handlers* h) {
+ upb_pbdecodermethodopts_init(this, h);
+}
+inline void DecoderMethodOptions::set_lazy(bool lazy) {
+ upb_pbdecodermethodopts_setlazy(this, lazy);
+}
+
+inline const Handlers* DecoderMethod::dest_handlers() const {
+ return upb_pbdecodermethod_desthandlers(this);
+}
+inline const BytesHandler* DecoderMethod::input_handler() const {
+ return upb_pbdecodermethod_inputhandler(this);
+}
+inline bool DecoderMethod::is_native() const {
+ return upb_pbdecodermethod_isnative(this);
+}
+/* static */
+inline reffed_ptr<const DecoderMethod> DecoderMethod::New(
+ const DecoderMethodOptions &opts) {
+ const upb_pbdecodermethod *m = upb_pbdecodermethod_new(&opts, &m);
+ return reffed_ptr<const DecoderMethod>(m, &m);
+}
+
+inline CodeCache::CodeCache() {
+ upb_pbcodecache_init(this);
+}
+inline CodeCache::~CodeCache() {
+ upb_pbcodecache_uninit(this);
+}
+inline bool CodeCache::allow_jit() const {
+ return upb_pbcodecache_allowjit(this);
+}
+inline bool CodeCache::set_allow_jit(bool allow) {
+ return upb_pbcodecache_setallowjit(this, allow);
+}
+inline const DecoderMethod *CodeCache::GetDecoderMethod(
+ const DecoderMethodOptions& opts) {
+ return upb_pbcodecache_getdecodermethod(this, &opts);
+}
+
+} /* namespace pb */
+} /* namespace upb */
+
+#endif /* __cplusplus */
+
+#endif /* UPB_DECODER_H_ */
+
+/* C++ names are not actually used since this type isn't exposed to users. */
+#ifdef __cplusplus
+namespace upb {
+namespace pb {
+class MessageGroup;
+} /* namespace pb */
+} /* namespace upb */
+#endif
+UPB_DECLARE_DERIVED_TYPE(upb::pb::MessageGroup, upb::RefCounted,
+ mgroup, upb_refcounted)
+
+/* Opcode definitions. The canonical meaning of each opcode is its
+ * implementation in the interpreter (the JIT is written to match this).
+ *
+ * All instructions have the opcode in the low byte.
+ * Instruction format for most instructions is:
+ *
+ * +-------------------+--------+
+ * | arg (24) | op (8) |
+ * +-------------------+--------+
+ *
+ * Exceptions are indicated below. A few opcodes are multi-word. */
+typedef enum {
+ /* Opcodes 1-8, 13, 15-18 parse their respective descriptor types.
+ * Arg for all of these is the upb selector for this field. */
+#define T(type) OP_PARSE_ ## type = UPB_DESCRIPTOR_TYPE_ ## type
+ T(DOUBLE), T(FLOAT), T(INT64), T(UINT64), T(INT32), T(FIXED64), T(FIXED32),
+ T(BOOL), T(UINT32), T(SFIXED32), T(SFIXED64), T(SINT32), T(SINT64),
+#undef T
+ OP_STARTMSG = 9, /* No arg. */
+ OP_ENDMSG = 10, /* No arg. */
+ OP_STARTSEQ = 11,
+ OP_ENDSEQ = 12,
+ OP_STARTSUBMSG = 14,
+ OP_ENDSUBMSG = 19,
+ OP_STARTSTR = 20,
+ OP_STRING = 21,
+ OP_ENDSTR = 22,
+
+ OP_PUSHTAGDELIM = 23, /* No arg. */
+ OP_PUSHLENDELIM = 24, /* No arg. */
+ OP_POP = 25, /* No arg. */
+ OP_SETDELIM = 26, /* No arg. */
+ OP_SETBIGGROUPNUM = 27, /* two words:
+ * | unused (24) | opc (8) |
+ * | groupnum (32) | */
+ OP_CHECKDELIM = 28,
+ OP_CALL = 29,
+ OP_RET = 30,
+ OP_BRANCH = 31,
+
+ /* Different opcodes depending on how many bytes expected. */
+ OP_TAG1 = 32, /* | match tag (16) | jump target (8) | opc (8) | */
+ OP_TAG2 = 33, /* | match tag (16) | jump target (8) | opc (8) | */
+ OP_TAGN = 34, /* three words: */
+ /* | unused (16) | jump target(8) | opc (8) | */
+ /* | match tag 1 (32) | */
+ /* | match tag 2 (32) | */
+
+ OP_SETDISPATCH = 35, /* N words: */
+ /* | unused (24) | opc | */
+ /* | upb_inttable* (32 or 64) | */
+
+ OP_DISPATCH = 36, /* No arg. */
+
+ OP_HALT = 37 /* No arg. */
+} opcode;
+
+#define OP_MAX OP_HALT
+
+UPB_INLINE opcode getop(uint32_t instr) { return instr & 0xff; }
+
+/* Method group; represents a set of decoder methods that had their code
+ * emitted together, and must therefore be freed together. Immutable once
+ * created. It is possible we may want to expose this to users at some point.
+ *
+ * Overall ownership of Decoder objects looks like this:
+ *
+ * +----------+
+ * | | <---> DecoderMethod
+ * | method |
+ * CodeCache ---> | group | <---> DecoderMethod
+ * | |
+ * | (mgroup) | <---> DecoderMethod
+ * +----------+
+ */
+struct mgroup {
+ upb_refcounted base;
+
+ /* Maps upb_msgdef/upb_handlers -> upb_pbdecodermethod. We own refs on the
+ * methods. */
+ upb_inttable methods;
+
+ /* When we add the ability to link to previously existing mgroups, we'll
+ * need an array of mgroups we reference here, and own refs on them. */
+
+ /* The bytecode for our methods, if any exists. Owned by us. */
+ uint32_t *bytecode;
+ uint32_t *bytecode_end;
+
+#ifdef UPB_USE_JIT_X64
+ /* JIT-generated machine code, if any. */
+ upb_string_handlerfunc *jit_code;
+ /* The size of the jit_code (required to munmap()). */
+ size_t jit_size;
+ char *debug_info;
+ void *dl;
+#endif
+};
+
+/* The maximum that any submessages can be nested. Matches proto2's limit.
+ * This specifies the size of the decoder's statically-sized array and therefore
+ * setting it high will cause the upb::pb::Decoder object to be larger.
+ *
+ * If necessary we can add a runtime-settable property to Decoder that allow
+ * this to be larger than the compile-time setting, but this would add
+ * complexity, particularly since we would have to decide how/if to give users
+ * the ability to set a custom memory allocation function. */
+#define UPB_DECODER_MAX_NESTING 64
+
+/* Internal-only struct used by the decoder. */
+typedef struct {
+ /* Space optimization note: we store two pointers here that the JIT
+ * doesn't need at all; the upb_handlers* inside the sink and
+ * the dispatch table pointer. We can optimze so that the JIT uses
+ * smaller stack frames than the interpreter. The only thing we need
+ * to guarantee is that the fallback routines can find end_ofs. */
+ upb_sink sink;
+
+ /* The absolute stream offset of the end-of-frame delimiter.
+ * Non-delimited frames (groups and non-packed repeated fields) reuse the
+ * delimiter of their parent, even though the frame may not end there.
+ *
+ * NOTE: the JIT stores a slightly different value here for non-top frames.
+ * It stores the value relative to the end of the enclosed message. But the
+ * top frame is still stored the same way, which is important for ensuring
+ * that calls from the JIT into C work correctly. */
+ uint64_t end_ofs;
+ const uint32_t *base;
+
+ /* 0 indicates a length-delimited field.
+ * A positive number indicates a known group.
+ * A negative number indicates an unknown group. */
+ int32_t groupnum;
+ upb_inttable *dispatch; /* Not used by the JIT. */
+} upb_pbdecoder_frame;
+
+struct upb_pbdecodermethod {
+ upb_refcounted base;
+
+ /* While compiling, the base is relative in "ofs", after compiling it is
+ * absolute in "ptr". */
+ union {
+ uint32_t ofs; /* PC offset of method. */
+ void *ptr; /* Pointer to bytecode or machine code for this method. */
+ } code_base;
+
+ /* The decoder method group to which this method belongs. We own a ref.
+ * Owning a ref on the entire group is more coarse-grained than is strictly
+ * necessary; all we truly require is that methods we directly reference
+ * outlive us, while the group could contain many other messages we don't
+ * require. But the group represents the messages that were
+ * allocated+compiled together, so it makes the most sense to free them
+ * together also. */
+ const upb_refcounted *group;
+
+ /* Whether this method is native code or bytecode. */
+ bool is_native_;
+
+ /* The handler one calls to invoke this method. */
+ upb_byteshandler input_handler_;
+
+ /* The destination handlers this method is bound to. We own a ref. */
+ const upb_handlers *dest_handlers_;
+
+ /* Dispatch table -- used by both bytecode decoder and JIT when encountering a
+ * field number that wasn't the one we were expecting to see. See
+ * decoder.int.h for the layout of this table. */
+ upb_inttable dispatch;
+};
+
+struct upb_pbdecoder {
+ upb_env *env;
+
+ /* Our input sink. */
+ upb_bytessink input_;
+
+ /* The decoder method we are parsing with (owned). */
+ const upb_pbdecodermethod *method_;
+
+ size_t call_len;
+ const uint32_t *pc, *last;
+
+ /* Current input buffer and its stream offset. */
+ const char *buf, *ptr, *end, *checkpoint;
+
+ /* End of the delimited region, relative to ptr, NULL if not in this buf. */
+ const char *delim_end;
+
+ /* End of the delimited region, relative to ptr, end if not in this buf. */
+ const char *data_end;
+
+ /* Overall stream offset of "buf." */
+ uint64_t bufstart_ofs;
+
+ /* Buffer for residual bytes not parsed from the previous buffer. */
+ char residual[UPB_DECODER_MAX_RESIDUAL_BYTES];
+ char *residual_end;
+
+ /* Bytes of data that should be discarded from the input beore we start
+ * parsing again. We set this when we internally determine that we can
+ * safely skip the next N bytes, but this region extends past the current
+ * user buffer. */
+ size_t skip;
+
+ /* Stores the user buffer passed to our decode function. */
+ const char *buf_param;
+ size_t size_param;
+ const upb_bufhandle *handle;
+
+ /* Our internal stack. */
+ upb_pbdecoder_frame *stack, *top, *limit;
+ const uint32_t **callstack;
+ size_t stack_size;
+
+ upb_status *status;
+
+#ifdef UPB_USE_JIT_X64
+ /* Used momentarily by the generated code to store a value while a user
+ * function is called. */
+ uint32_t tmp_len;
+
+ const void *saved_rsp;
+#endif
+};
+
+/* Decoder entry points; used as handlers. */
+void *upb_pbdecoder_startbc(void *closure, const void *pc, size_t size_hint);
+void *upb_pbdecoder_startjit(void *closure, const void *hd, size_t size_hint);
+size_t upb_pbdecoder_decode(void *closure, const void *hd, const char *buf,
+ size_t size, const upb_bufhandle *handle);
+bool upb_pbdecoder_end(void *closure, const void *handler_data);
+
+/* Decoder-internal functions that the JIT calls to handle fallback paths. */
+int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf,
+ size_t size, const upb_bufhandle *handle);
+size_t upb_pbdecoder_suspend(upb_pbdecoder *d);
+int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum,
+ uint8_t wire_type);
+int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d, uint64_t expected);
+int32_t upb_pbdecoder_decode_varint_slow(upb_pbdecoder *d, uint64_t *u64);
+int32_t upb_pbdecoder_decode_f32(upb_pbdecoder *d, uint32_t *u32);
+int32_t upb_pbdecoder_decode_f64(upb_pbdecoder *d, uint64_t *u64);
+void upb_pbdecoder_seterr(upb_pbdecoder *d, const char *msg);
+
+/* Error messages that are shared between the bytecode and JIT decoders. */
+extern const char *kPbDecoderStackOverflow;
+extern const char *kPbDecoderSubmessageTooLong;
+
+/* Access to decoderplan members needed by the decoder. */
+const char *upb_pbdecoder_getopname(unsigned int op);
+
+/* JIT codegen entry point. */
+void upb_pbdecoder_jit(mgroup *group);
+void upb_pbdecoder_freejit(mgroup *group);
+UPB_REFCOUNTED_CMETHODS(mgroup, mgroup_upcast)
+
+/* A special label that means "do field dispatch for this message and branch to
+ * wherever that takes you." */
+#define LABEL_DISPATCH 0
+
+/* A special slot in the dispatch table that stores the epilogue (ENDMSG and/or
+ * RET) for branching to when we find an appropriate ENDGROUP tag. */
+#define DISPATCH_ENDMSG 0
+
+/* It's important to use this invalid wire type instead of 0 (which is a valid
+ * wire type). */
+#define NO_WIRE_TYPE 0xff
+
+/* The dispatch table layout is:
+ * [field number] -> [ 48-bit offset ][ 8-bit wt2 ][ 8-bit wt1 ]
+ *
+ * If wt1 matches, jump to the 48-bit offset. If wt2 matches, lookup
+ * (UPB_MAX_FIELDNUMBER + fieldnum) and jump there.
+ *
+ * We need two wire types because of packed/non-packed compatibility. A
+ * primitive repeated field can use either wire type and be valid. While we
+ * could key the table on fieldnum+wiretype, the table would be 8x sparser.
+ *
+ * Storing two wire types in the primary value allows us to quickly rule out
+ * the second wire type without needing to do a separate lookup (this case is
+ * less common than an unknown field). */
+UPB_INLINE uint64_t upb_pbdecoder_packdispatch(uint64_t ofs, uint8_t wt1,
+ uint8_t wt2) {
+ return (ofs << 16) | (wt2 << 8) | wt1;
+}
+
+UPB_INLINE void upb_pbdecoder_unpackdispatch(uint64_t dispatch, uint64_t *ofs,
+ uint8_t *wt1, uint8_t *wt2) {
+ *wt1 = (uint8_t)dispatch;
+ *wt2 = (uint8_t)(dispatch >> 8);
+ *ofs = dispatch >> 16;
+}
+
+/* All of the functions in decoder.c that return int32_t return values according
+ * to the following scheme:
+ * 1. negative values indicate a return code from the following list.
+ * 2. positive values indicate that error or end of buffer was hit, and
+ * that the decode function should immediately return the given value
+ * (the decoder state has already been suspended and is ready to be
+ * resumed). */
+#define DECODE_OK -1
+#define DECODE_MISMATCH -2 /* Used only from checktag_slow(). */
+#define DECODE_ENDGROUP -3 /* Used only from checkunknown(). */
+
+#define CHECK_RETURN(x) { int32_t ret = x; if (ret >= 0) return ret; }
+
+#endif /* UPB_DECODER_INT_H_ */
+/*
+** A number of routines for varint manipulation (we keep them all around to
+** have multiple approaches available for benchmarking).
+*/
+
+#ifndef UPB_VARINT_DECODER_H_
+#define UPB_VARINT_DECODER_H_
+
+#include <assert.h>
+#include <stdint.h>
+#include <string.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* A list of types as they are encoded on-the-wire. */
+typedef enum {
+ UPB_WIRE_TYPE_VARINT = 0,
+ UPB_WIRE_TYPE_64BIT = 1,
+ UPB_WIRE_TYPE_DELIMITED = 2,
+ UPB_WIRE_TYPE_START_GROUP = 3,
+ UPB_WIRE_TYPE_END_GROUP = 4,
+ UPB_WIRE_TYPE_32BIT = 5
+} upb_wiretype_t;
+
+#define UPB_MAX_WIRE_TYPE 5
+
+/* The maximum number of bytes that it takes to encode a 64-bit varint.
+ * Note that with a better encoding this could be 9 (TODO: write up a
+ * wiki document about this). */
+#define UPB_PB_VARINT_MAX_LEN 10
+
+/* Array of the "native" (ie. non-packed-repeated) wire type for the given a
+ * descriptor type (upb_descriptortype_t). */
+extern const uint8_t upb_pb_native_wire_types[];
+
+/* Zig-zag encoding/decoding **************************************************/
+
+UPB_INLINE int32_t upb_zzdec_32(uint32_t n) {
+ return (n >> 1) ^ -(int32_t)(n & 1);
+}
+UPB_INLINE int64_t upb_zzdec_64(uint64_t n) {
+ return (n >> 1) ^ -(int64_t)(n & 1);
+}
+UPB_INLINE uint32_t upb_zzenc_32(int32_t n) { return (n << 1) ^ (n >> 31); }
+UPB_INLINE uint64_t upb_zzenc_64(int64_t n) { return (n << 1) ^ (n >> 63); }
+
+/* Decoding *******************************************************************/
+
+/* All decoding functions return this struct by value. */
+typedef struct {
+ const char *p; /* NULL if the varint was unterminated. */
+ uint64_t val;
+} upb_decoderet;
+
+UPB_INLINE upb_decoderet upb_decoderet_make(const char *p, uint64_t val) {
+ upb_decoderet ret;
+ ret.p = p;
+ ret.val = val;
+ return ret;
+}
+
+/* Four functions for decoding a varint of at most eight bytes. They are all
+ * functionally identical, but are implemented in different ways and likely have
+ * different performance profiles. We keep them around for performance testing.
+ *
+ * Note that these functions may not read byte-by-byte, so they must not be used
+ * unless there are at least eight bytes left in the buffer! */
+upb_decoderet upb_vdecode_max8_branch32(upb_decoderet r);
+upb_decoderet upb_vdecode_max8_branch64(upb_decoderet r);
+upb_decoderet upb_vdecode_max8_wright(upb_decoderet r);
+upb_decoderet upb_vdecode_max8_massimino(upb_decoderet r);
+
+/* Template for a function that checks the first two bytes with branching
+ * and dispatches 2-10 bytes with a separate function. Note that this may read
+ * up to 10 bytes, so it must not be used unless there are at least ten bytes
+ * left in the buffer! */
+#define UPB_VARINT_DECODER_CHECK2(name, decode_max8_function) \
+UPB_INLINE upb_decoderet upb_vdecode_check2_ ## name(const char *_p) { \
+ uint8_t *p = (uint8_t*)_p; \
+ upb_decoderet r; \
+ if ((*p & 0x80) == 0) { \
+ /* Common case: one-byte varint. */ \
+ return upb_decoderet_make(_p + 1, *p & 0x7fU); \
+ } \
+ r = upb_decoderet_make(_p + 2, (*p & 0x7fU) | ((*(p + 1) & 0x7fU) << 7)); \
+ if ((*(p + 1) & 0x80) == 0) { \
+ /* Two-byte varint. */ \
+ return r; \
+ } \
+ /* Longer varint, fallback to out-of-line function. */ \
+ return decode_max8_function(r); \
+}
+
+UPB_VARINT_DECODER_CHECK2(branch32, upb_vdecode_max8_branch32)
+UPB_VARINT_DECODER_CHECK2(branch64, upb_vdecode_max8_branch64)
+UPB_VARINT_DECODER_CHECK2(wright, upb_vdecode_max8_wright)
+UPB_VARINT_DECODER_CHECK2(massimino, upb_vdecode_max8_massimino)
+#undef UPB_VARINT_DECODER_CHECK2
+
+/* Our canonical functions for decoding varints, based on the currently
+ * favored best-performing implementations. */
+UPB_INLINE upb_decoderet upb_vdecode_fast(const char *p) {
+ if (sizeof(long) == 8)
+ return upb_vdecode_check2_branch64(p);
+ else
+ return upb_vdecode_check2_branch32(p);
+}
+
+UPB_INLINE upb_decoderet upb_vdecode_max8_fast(upb_decoderet r) {
+ return upb_vdecode_max8_massimino(r);
+}
+
+
+/* Encoding *******************************************************************/
+
+UPB_INLINE int upb_value_size(uint64_t val) {
+#ifdef __GNUC__
+ int high_bit = 63 - __builtin_clzll(val); /* 0-based, undef if val == 0. */
+#else
+ int high_bit = 0;
+ uint64_t tmp = val;
+ while(tmp >>= 1) high_bit++;
+#endif
+ return val == 0 ? 1 : high_bit / 8 + 1;
+}
+
+/* Encodes a 64-bit varint into buf (which must be >=UPB_PB_VARINT_MAX_LEN
+ * bytes long), returning how many bytes were used.
+ *
+ * TODO: benchmark and optimize if necessary. */
+UPB_INLINE size_t upb_vencode64(uint64_t val, char *buf) {
+ size_t i;
+ if (val == 0) { buf[0] = 0; return 1; }
+ i = 0;
+ while (val) {
+ uint8_t byte = val & 0x7fU;
+ val >>= 7;
+ if (val) byte |= 0x80U;
+ buf[i++] = byte;
+ }
+ return i;
+}
+
+UPB_INLINE size_t upb_varint_size(uint64_t val) {
+ char buf[UPB_PB_VARINT_MAX_LEN];
+ return upb_vencode64(val, buf);
+}
+
+/* Encodes a 32-bit varint, *not* sign-extended. */
+UPB_INLINE uint64_t upb_vencode32(uint32_t val) {
+ char buf[UPB_PB_VARINT_MAX_LEN];
+ size_t bytes = upb_vencode64(val, buf);
+ uint64_t ret = 0;
+ UPB_ASSERT(bytes <= 5);
+ memcpy(&ret, buf, bytes);
+ UPB_ASSERT(ret <= 0xffffffffffU);
+ return ret;
+}
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* UPB_VARINT_DECODER_H_ */
+/*
+** upb::pb::Encoder (upb_pb_encoder)
+**
+** Implements a set of upb_handlers that write protobuf data to the binary wire
+** format.
+**
+** This encoder implementation does not have any access to any out-of-band or
+** precomputed lengths for submessages, so it must buffer submessages internally
+** before it can emit the first byte.
+*/
+
+#ifndef UPB_ENCODER_H_
+#define UPB_ENCODER_H_
+
+
+#ifdef __cplusplus
+namespace upb {
+namespace pb {
+class Encoder;
+} /* namespace pb */
+} /* namespace upb */
+#endif
+
+UPB_DECLARE_TYPE(upb::pb::Encoder, upb_pb_encoder)
+
+#define UPB_PBENCODER_MAX_NESTING 100
+
+/* upb::pb::Encoder ***********************************************************/
+
+/* Preallocation hint: decoder won't allocate more bytes than this when first
+ * constructed. This hint may be an overestimate for some build configurations.
+ * But if the decoder library is upgraded without recompiling the application,
+ * it may be an underestimate. */
+#define UPB_PB_ENCODER_SIZE 768
+
+#ifdef __cplusplus
+
+class upb::pb::Encoder {
+ public:
+ /* Creates a new encoder in the given environment. The Handlers must have
+ * come from NewHandlers() below. */
+ static Encoder* Create(Environment* env, const Handlers* handlers,
+ BytesSink* output);
+
+ /* The input to the encoder. */
+ Sink* input();
+
+ /* Creates a new set of handlers for this MessageDef. */
+ static reffed_ptr<const Handlers> NewHandlers(const MessageDef* msg);
+
+ static const size_t kSize = UPB_PB_ENCODER_SIZE;
+
+ private:
+ UPB_DISALLOW_POD_OPS(Encoder, upb::pb::Encoder)
+};
+
+#endif
+
+UPB_BEGIN_EXTERN_C
+
+const upb_handlers *upb_pb_encoder_newhandlers(const upb_msgdef *m,
+ const void *owner);
+upb_sink *upb_pb_encoder_input(upb_pb_encoder *p);
+upb_pb_encoder* upb_pb_encoder_create(upb_env* e, const upb_handlers* h,
+ upb_bytessink* output);
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+namespace upb {
+namespace pb {
+inline Encoder* Encoder::Create(Environment* env, const Handlers* handlers,
+ BytesSink* output) {
+ return upb_pb_encoder_create(env, handlers, output);
+}
+inline Sink* Encoder::input() {
+ return upb_pb_encoder_input(this);
+}
+inline reffed_ptr<const Handlers> Encoder::NewHandlers(
+ const upb::MessageDef *md) {
+ const Handlers* h = upb_pb_encoder_newhandlers(md, &h);
+ return reffed_ptr<const Handlers>(h, &h);
+}
+} /* namespace pb */
+} /* namespace upb */
+
+#endif
+
+#endif /* UPB_ENCODER_H_ */
+/*
+** upb's core components like upb_decoder and upb_msg are carefully designed to
+** avoid depending on each other for maximum orthogonality. In other words,
+** you can use a upb_decoder to decode into *any* kind of structure; upb_msg is
+** just one such structure. A upb_msg can be serialized/deserialized into any
+** format, protobuf binary format is just one such format.
+**
+** However, for convenience we provide functions here for doing common
+** operations like deserializing protobuf binary format into a upb_msg. The
+** compromise is that this file drags in almost all of upb as a dependency,
+** which could be undesirable if you're trying to use a trimmed-down build of
+** upb.
+**
+** While these routines are convenient, they do not reuse any encoding/decoding
+** state. For example, if a decoder is JIT-based, it will be re-JITted every
+** time these functions are called. For this reason, if you are parsing lots
+** of data and efficiency is an issue, these may not be the best functions to
+** use (though they are useful for prototyping, before optimizing).
+*/
+
+#ifndef UPB_GLUE_H
+#define UPB_GLUE_H
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+#include <vector>
+
+extern "C" {
+#endif
+
+/* Loads a binary descriptor and returns a NULL-terminated array of unfrozen
+ * filedefs. The caller owns the returned array, which must be freed with
+ * upb_gfree(). */
+upb_filedef **upb_loaddescriptor(const char *buf, size_t n, const void *owner,
+ upb_status *status);
+
+#ifdef __cplusplus
+} /* extern "C" */
+
+namespace upb {
+
+inline bool LoadDescriptor(const char* buf, size_t n, Status* status,
+ std::vector<reffed_ptr<FileDef> >* files) {
+ FileDef** parsed_files = upb_loaddescriptor(buf, n, &parsed_files, status);
+
+ if (parsed_files) {
+ FileDef** p = parsed_files;
+ while (*p) {
+ files->push_back(reffed_ptr<FileDef>(*p, &parsed_files));
+ ++p;
+ }
+ free(parsed_files);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/* Templated so it can accept both string and std::string. */
+template <typename T>
+bool LoadDescriptor(const T& desc, Status* status,
+ std::vector<reffed_ptr<FileDef> >* files) {
+ return LoadDescriptor(desc.c_str(), desc.size(), status, files);
+}
+
+} /* namespace upb */
+
+#endif
+
+#endif /* UPB_GLUE_H */
+/*
+** upb::pb::TextPrinter (upb_textprinter)
+**
+** Handlers for writing to protobuf text format.
+*/
+
+#ifndef UPB_TEXT_H_
+#define UPB_TEXT_H_
+
+
+#ifdef __cplusplus
+namespace upb {
+namespace pb {
+class TextPrinter;
+} /* namespace pb */
+} /* namespace upb */
+#endif
+
+UPB_DECLARE_TYPE(upb::pb::TextPrinter, upb_textprinter)
+
+#ifdef __cplusplus
+
+class upb::pb::TextPrinter {
+ public:
+ /* The given handlers must have come from NewHandlers(). It must outlive the
+ * TextPrinter. */
+ static TextPrinter *Create(Environment *env, const upb::Handlers *handlers,
+ BytesSink *output);
+
+ void SetSingleLineMode(bool single_line);
+
+ Sink* input();
+
+ /* If handler caching becomes a requirement we can add a code cache as in
+ * decoder.h */
+ static reffed_ptr<const Handlers> NewHandlers(const MessageDef* md);
+};
+
+#endif
+
+UPB_BEGIN_EXTERN_C
+
+/* C API. */
+upb_textprinter *upb_textprinter_create(upb_env *env, const upb_handlers *h,
+ upb_bytessink *output);
+void upb_textprinter_setsingleline(upb_textprinter *p, bool single_line);
+upb_sink *upb_textprinter_input(upb_textprinter *p);
+
+const upb_handlers *upb_textprinter_newhandlers(const upb_msgdef *m,
+ const void *owner);
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+namespace upb {
+namespace pb {
+inline TextPrinter *TextPrinter::Create(Environment *env,
+ const upb::Handlers *handlers,
+ BytesSink *output) {
+ return upb_textprinter_create(env, handlers, output);
+}
+inline void TextPrinter::SetSingleLineMode(bool single_line) {
+ upb_textprinter_setsingleline(this, single_line);
+}
+inline Sink* TextPrinter::input() {
+ return upb_textprinter_input(this);
+}
+inline reffed_ptr<const Handlers> TextPrinter::NewHandlers(
+ const MessageDef *md) {
+ const Handlers* h = upb_textprinter_newhandlers(md, &h);
+ return reffed_ptr<const Handlers>(h, &h);
+}
+} /* namespace pb */
+} /* namespace upb */
+
+#endif
+
+#endif /* UPB_TEXT_H_ */
+/*
+** upb::json::Parser (upb_json_parser)
+**
+** Parses JSON according to a specific schema.
+** Support for parsing arbitrary JSON (schema-less) will be added later.
+*/
+
+#ifndef UPB_JSON_PARSER_H_
+#define UPB_JSON_PARSER_H_
+
+
+#ifdef __cplusplus
+namespace upb {
+namespace json {
+class Parser;
+class ParserMethod;
+} /* namespace json */
+} /* namespace upb */
+#endif
+
+UPB_DECLARE_TYPE(upb::json::Parser, upb_json_parser)
+UPB_DECLARE_DERIVED_TYPE(upb::json::ParserMethod, upb::RefCounted,
+ upb_json_parsermethod, upb_refcounted)
+
+/* upb::json::Parser **********************************************************/
+
+/* Preallocation hint: parser won't allocate more bytes than this when first
+ * constructed. This hint may be an overestimate for some build configurations.
+ * But if the parser library is upgraded without recompiling the application,
+ * it may be an underestimate. */
+#define UPB_JSON_PARSER_SIZE 4112
+
+#ifdef __cplusplus
+
+/* Parses an incoming BytesStream, pushing the results to the destination
+ * sink. */
+class upb::json::Parser {
+ public:
+ static Parser* Create(Environment* env, const ParserMethod* method,
+ Sink* output);
+
+ BytesSink* input();
+
+ private:
+ UPB_DISALLOW_POD_OPS(Parser, upb::json::Parser)
+};
+
+class upb::json::ParserMethod {
+ public:
+ /* Include base methods from upb::ReferenceCounted. */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ /* Returns handlers for parsing according to the specified schema. */
+ static reffed_ptr<const ParserMethod> New(const upb::MessageDef* md);
+
+ /* The destination handlers that are statically bound to this method.
+ * This method is only capable of outputting to a sink that uses these
+ * handlers. */
+ const Handlers* dest_handlers() const;
+
+ /* The input handlers for this decoder method. */
+ const BytesHandler* input_handler() const;
+
+ private:
+ UPB_DISALLOW_POD_OPS(ParserMethod, upb::json::ParserMethod)
+};
+
+#endif
+
+UPB_BEGIN_EXTERN_C
+
+upb_json_parser* upb_json_parser_create(upb_env* e,
+ const upb_json_parsermethod* m,
+ upb_sink* output);
+upb_bytessink *upb_json_parser_input(upb_json_parser *p);
+
+upb_json_parsermethod* upb_json_parsermethod_new(const upb_msgdef* md,
+ const void* owner);
+const upb_handlers *upb_json_parsermethod_desthandlers(
+ const upb_json_parsermethod *m);
+const upb_byteshandler *upb_json_parsermethod_inputhandler(
+ const upb_json_parsermethod *m);
+
+/* Include refcounted methods like upb_json_parsermethod_ref(). */
+UPB_REFCOUNTED_CMETHODS(upb_json_parsermethod, upb_json_parsermethod_upcast)
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+namespace upb {
+namespace json {
+inline Parser* Parser::Create(Environment* env, const ParserMethod* method,
+ Sink* output) {
+ return upb_json_parser_create(env, method, output);
+}
+inline BytesSink* Parser::input() {
+ return upb_json_parser_input(this);
+}
+
+inline const Handlers* ParserMethod::dest_handlers() const {
+ return upb_json_parsermethod_desthandlers(this);
+}
+inline const BytesHandler* ParserMethod::input_handler() const {
+ return upb_json_parsermethod_inputhandler(this);
+}
+/* static */
+inline reffed_ptr<const ParserMethod> ParserMethod::New(
+ const MessageDef* md) {
+ const upb_json_parsermethod *m = upb_json_parsermethod_new(md, &m);
+ return reffed_ptr<const ParserMethod>(m, &m);
+}
+
+} /* namespace json */
+} /* namespace upb */
+
+#endif
+
+
+#endif /* UPB_JSON_PARSER_H_ */
+/*
+** upb::json::Printer
+**
+** Handlers that emit JSON according to a specific protobuf schema.
+*/
+
+#ifndef UPB_JSON_TYPED_PRINTER_H_
+#define UPB_JSON_TYPED_PRINTER_H_
+
+
+#ifdef __cplusplus
+namespace upb {
+namespace json {
+class Printer;
+} /* namespace json */
+} /* namespace upb */
+#endif
+
+UPB_DECLARE_TYPE(upb::json::Printer, upb_json_printer)
+
+
+/* upb::json::Printer *********************************************************/
+
+#define UPB_JSON_PRINTER_SIZE 176
+
+#ifdef __cplusplus
+
+/* Prints an incoming stream of data to a BytesSink in JSON format. */
+class upb::json::Printer {
+ public:
+ static Printer* Create(Environment* env, const upb::Handlers* handlers,
+ BytesSink* output);
+
+ /* The input to the printer. */
+ Sink* input();
+
+ /* Returns handlers for printing according to the specified schema.
+ * If preserve_proto_fieldnames is true, the output JSON will use the
+ * original .proto field names (ie. {"my_field":3}) instead of using
+ * camelCased names, which is the default: (eg. {"myField":3}). */
+ static reffed_ptr<const Handlers> NewHandlers(const upb::MessageDef* md,
+ bool preserve_proto_fieldnames);
+
+ static const size_t kSize = UPB_JSON_PRINTER_SIZE;
+
+ private:
+ UPB_DISALLOW_POD_OPS(Printer, upb::json::Printer)
+};
+
+#endif
+
+UPB_BEGIN_EXTERN_C
+
+/* Native C API. */
+upb_json_printer *upb_json_printer_create(upb_env *e, const upb_handlers *h,
+ upb_bytessink *output);
+upb_sink *upb_json_printer_input(upb_json_printer *p);
+const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md,
+ bool preserve_fieldnames,
+ const void *owner);
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+namespace upb {
+namespace json {
+inline Printer* Printer::Create(Environment* env, const upb::Handlers* handlers,
+ BytesSink* output) {
+ return upb_json_printer_create(env, handlers, output);
+}
+inline Sink* Printer::input() { return upb_json_printer_input(this); }
+inline reffed_ptr<const Handlers> Printer::NewHandlers(
+ const upb::MessageDef *md, bool preserve_proto_fieldnames) {
+ const Handlers* h = upb_json_printer_newhandlers(
+ md, preserve_proto_fieldnames, &h);
+ return reffed_ptr<const Handlers>(h, &h);
+}
+} /* namespace json */
+} /* namespace upb */
+
+#endif
+
+#endif /* UPB_JSON_TYPED_PRINTER_H_ */
diff --git a/third_party/protobuf/php/ext/google/protobuf/utf8.c b/third_party/protobuf/php/ext/google/protobuf/utf8.c
new file mode 100644
index 0000000000..2752a08b05
--- /dev/null
+++ b/third_party/protobuf/php/ext/google/protobuf/utf8.c
@@ -0,0 +1,68 @@
+// 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 <stdbool.h>
+#include <stdint.h>
+
+#include "utf8.h"
+
+static const uint8_t utf8_offset[] = {
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0,
+};
+
+bool is_structurally_valid_utf8(const char* buf, int len) {
+ int i, j;
+ uint8_t offset;
+
+ i = 0;
+ while (i < len) {
+ offset = utf8_offset[(uint8_t)buf[i]];
+ if (offset == 0 || i + offset > len) {
+ return false;
+ }
+ for (j = i + 1; j < i + offset; j++) {
+ if ((buf[j] & 0xc0) != 0x80) {
+ return false;
+ }
+ }
+ i += offset;
+ }
+ return i == len;
+}
diff --git a/third_party/protobuf/php/ext/google/protobuf/utf8.h b/third_party/protobuf/php/ext/google/protobuf/utf8.h
new file mode 100644
index 0000000000..28b8d874a8
--- /dev/null
+++ b/third_party/protobuf/php/ext/google/protobuf/utf8.h
@@ -0,0 +1,36 @@
+// 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_UTF8_H_
+#define GOOGLE_PROTOBUF_UTF8_H_
+
+bool is_structurally_valid_utf8(const char* buf, int len);
+
+#endif // GOOGLE_PROTOBUF_UTF8_H_
diff --git a/third_party/protobuf/php/generate_descriptor_protos.sh b/third_party/protobuf/php/generate_descriptor_protos.sh
new file mode 100755
index 0000000000..372ad69c6c
--- /dev/null
+++ b/third_party/protobuf/php/generate_descriptor_protos.sh
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+
+# Run this script to regenerate desriptor protos after the protocol compiler
+# changes.
+
+if test ! -e src/google/protobuf/stubs/common.h; then
+ cat >&2 << __EOF__
+Could not find source code. Make sure you are running this script from the
+root of the distribution tree.
+__EOF__
+ exit 1
+fi
+
+pushd src
+./protoc --php_out=internal:../php/src google/protobuf/descriptor.proto
+popd
diff --git a/third_party/protobuf/php/phpunit.xml b/third_party/protobuf/php/phpunit.xml
new file mode 100644
index 0000000000..0191a601dd
--- /dev/null
+++ b/third_party/protobuf/php/phpunit.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit bootstrap="./vendor/autoload.php"
+ colors="true">
+ <testsuites>
+ <testsuite name="protobuf-tests">
+ <file>tests/php_implementation_test.php</file>
+ <file>tests/array_test.php</file>
+ <file>tests/encode_decode_test.php</file>
+ <file>tests/generated_class_test.php</file>
+ <file>tests/map_field_test.php</file>
+ <file>tests/well_known_test.php</file>
+ </testsuite>
+ </testsuites>
+</phpunit>
diff --git a/third_party/protobuf/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php b/third_party/protobuf/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php
new file mode 100644
index 0000000000..1b6b3d609b
--- /dev/null
+++ b/third_party/protobuf/php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php
@@ -0,0 +1,261 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace GPBMetadata\Google\Protobuf\Internal;
+
+class Descriptor
+{
+ public static $is_initialized = false;
+
+ public static function initOnce() {
+ $pool = \Google\Protobuf\Internal\DescriptorPool::getGeneratedPool();
+
+ if (static::$is_initialized == true) {
+ return;
+ }
+ $pool->addMessage('google.protobuf.internal.FileDescriptorSet', \Google\Protobuf\Internal\FileDescriptorSet::class)
+ ->repeated('file', \Google\Protobuf\Internal\GPBType::MESSAGE, 1, 'google.protobuf.internal.FileDescriptorProto')
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.FileDescriptorProto', \Google\Protobuf\Internal\FileDescriptorProto::class)
+ ->optional('name', \Google\Protobuf\Internal\GPBType::STRING, 1)
+ ->optional('package', \Google\Protobuf\Internal\GPBType::STRING, 2)
+ ->repeated('dependency', \Google\Protobuf\Internal\GPBType::STRING, 3)
+ ->repeated('public_dependency', \Google\Protobuf\Internal\GPBType::INT32, 10)
+ ->repeated('weak_dependency', \Google\Protobuf\Internal\GPBType::INT32, 11)
+ ->repeated('message_type', \Google\Protobuf\Internal\GPBType::MESSAGE, 4, 'google.protobuf.internal.DescriptorProto')
+ ->repeated('enum_type', \Google\Protobuf\Internal\GPBType::MESSAGE, 5, 'google.protobuf.internal.EnumDescriptorProto')
+ ->repeated('service', \Google\Protobuf\Internal\GPBType::MESSAGE, 6, 'google.protobuf.internal.ServiceDescriptorProto')
+ ->repeated('extension', \Google\Protobuf\Internal\GPBType::MESSAGE, 7, 'google.protobuf.internal.FieldDescriptorProto')
+ ->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 8, 'google.protobuf.internal.FileOptions')
+ ->optional('source_code_info', \Google\Protobuf\Internal\GPBType::MESSAGE, 9, 'google.protobuf.internal.SourceCodeInfo')
+ ->optional('syntax', \Google\Protobuf\Internal\GPBType::STRING, 12)
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.DescriptorProto', \Google\Protobuf\Internal\DescriptorProto::class)
+ ->optional('name', \Google\Protobuf\Internal\GPBType::STRING, 1)
+ ->repeated('field', \Google\Protobuf\Internal\GPBType::MESSAGE, 2, 'google.protobuf.internal.FieldDescriptorProto')
+ ->repeated('extension', \Google\Protobuf\Internal\GPBType::MESSAGE, 6, 'google.protobuf.internal.FieldDescriptorProto')
+ ->repeated('nested_type', \Google\Protobuf\Internal\GPBType::MESSAGE, 3, 'google.protobuf.internal.DescriptorProto')
+ ->repeated('enum_type', \Google\Protobuf\Internal\GPBType::MESSAGE, 4, 'google.protobuf.internal.EnumDescriptorProto')
+ ->repeated('extension_range', \Google\Protobuf\Internal\GPBType::MESSAGE, 5, 'google.protobuf.internal.DescriptorProto.ExtensionRange')
+ ->repeated('oneof_decl', \Google\Protobuf\Internal\GPBType::MESSAGE, 8, 'google.protobuf.internal.OneofDescriptorProto')
+ ->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 7, 'google.protobuf.internal.MessageOptions')
+ ->repeated('reserved_range', \Google\Protobuf\Internal\GPBType::MESSAGE, 9, 'google.protobuf.internal.DescriptorProto.ReservedRange')
+ ->repeated('reserved_name', \Google\Protobuf\Internal\GPBType::STRING, 10)
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.DescriptorProto.ExtensionRange', \Google\Protobuf\Internal\DescriptorProto_ExtensionRange::class)
+ ->optional('start', \Google\Protobuf\Internal\GPBType::INT32, 1)
+ ->optional('end', \Google\Protobuf\Internal\GPBType::INT32, 2)
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.DescriptorProto.ReservedRange', \Google\Protobuf\Internal\DescriptorProto_ReservedRange::class)
+ ->optional('start', \Google\Protobuf\Internal\GPBType::INT32, 1)
+ ->optional('end', \Google\Protobuf\Internal\GPBType::INT32, 2)
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.FieldDescriptorProto', \Google\Protobuf\Internal\FieldDescriptorProto::class)
+ ->optional('name', \Google\Protobuf\Internal\GPBType::STRING, 1)
+ ->optional('number', \Google\Protobuf\Internal\GPBType::INT32, 3)
+ ->optional('label', \Google\Protobuf\Internal\GPBType::ENUM, 4, 'google.protobuf.internal.FieldDescriptorProto.Label')
+ ->optional('type', \Google\Protobuf\Internal\GPBType::ENUM, 5, 'google.protobuf.internal.FieldDescriptorProto.Type')
+ ->optional('type_name', \Google\Protobuf\Internal\GPBType::STRING, 6)
+ ->optional('extendee', \Google\Protobuf\Internal\GPBType::STRING, 2)
+ ->optional('default_value', \Google\Protobuf\Internal\GPBType::STRING, 7)
+ ->optional('oneof_index', \Google\Protobuf\Internal\GPBType::INT32, 9)
+ ->optional('json_name', \Google\Protobuf\Internal\GPBType::STRING, 10)
+ ->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 8, 'google.protobuf.internal.FieldOptions')
+ ->finalizeToPool();
+
+ $pool->addEnum('google.protobuf.internal.FieldDescriptorProto.Type', \Google\Protobuf\Internal\Type::class)
+ ->value("TYPE_DOUBLE", 1)
+ ->value("TYPE_FLOAT", 2)
+ ->value("TYPE_INT64", 3)
+ ->value("TYPE_UINT64", 4)
+ ->value("TYPE_INT32", 5)
+ ->value("TYPE_FIXED64", 6)
+ ->value("TYPE_FIXED32", 7)
+ ->value("TYPE_BOOL", 8)
+ ->value("TYPE_STRING", 9)
+ ->value("TYPE_GROUP", 10)
+ ->value("TYPE_MESSAGE", 11)
+ ->value("TYPE_BYTES", 12)
+ ->value("TYPE_UINT32", 13)
+ ->value("TYPE_ENUM", 14)
+ ->value("TYPE_SFIXED32", 15)
+ ->value("TYPE_SFIXED64", 16)
+ ->value("TYPE_SINT32", 17)
+ ->value("TYPE_SINT64", 18)
+ ->finalizeToPool();
+
+ $pool->addEnum('google.protobuf.internal.FieldDescriptorProto.Label', \Google\Protobuf\Internal\Label::class)
+ ->value("LABEL_OPTIONAL", 1)
+ ->value("LABEL_REQUIRED", 2)
+ ->value("LABEL_REPEATED", 3)
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.OneofDescriptorProto', \Google\Protobuf\Internal\OneofDescriptorProto::class)
+ ->optional('name', \Google\Protobuf\Internal\GPBType::STRING, 1)
+ ->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 2, 'google.protobuf.internal.OneofOptions')
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.EnumDescriptorProto', \Google\Protobuf\Internal\EnumDescriptorProto::class)
+ ->optional('name', \Google\Protobuf\Internal\GPBType::STRING, 1)
+ ->repeated('value', \Google\Protobuf\Internal\GPBType::MESSAGE, 2, 'google.protobuf.internal.EnumValueDescriptorProto')
+ ->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 3, 'google.protobuf.internal.EnumOptions')
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.EnumValueDescriptorProto', \Google\Protobuf\Internal\EnumValueDescriptorProto::class)
+ ->optional('name', \Google\Protobuf\Internal\GPBType::STRING, 1)
+ ->optional('number', \Google\Protobuf\Internal\GPBType::INT32, 2)
+ ->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 3, 'google.protobuf.internal.EnumValueOptions')
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.ServiceDescriptorProto', \Google\Protobuf\Internal\ServiceDescriptorProto::class)
+ ->optional('name', \Google\Protobuf\Internal\GPBType::STRING, 1)
+ ->repeated('method', \Google\Protobuf\Internal\GPBType::MESSAGE, 2, 'google.protobuf.internal.MethodDescriptorProto')
+ ->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 3, 'google.protobuf.internal.ServiceOptions')
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.MethodDescriptorProto', \Google\Protobuf\Internal\MethodDescriptorProto::class)
+ ->optional('name', \Google\Protobuf\Internal\GPBType::STRING, 1)
+ ->optional('input_type', \Google\Protobuf\Internal\GPBType::STRING, 2)
+ ->optional('output_type', \Google\Protobuf\Internal\GPBType::STRING, 3)
+ ->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 4, 'google.protobuf.internal.MethodOptions')
+ ->optional('client_streaming', \Google\Protobuf\Internal\GPBType::BOOL, 5)
+ ->optional('server_streaming', \Google\Protobuf\Internal\GPBType::BOOL, 6)
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.FileOptions', \Google\Protobuf\Internal\FileOptions::class)
+ ->optional('java_package', \Google\Protobuf\Internal\GPBType::STRING, 1)
+ ->optional('java_outer_classname', \Google\Protobuf\Internal\GPBType::STRING, 8)
+ ->optional('java_multiple_files', \Google\Protobuf\Internal\GPBType::BOOL, 10)
+ ->optional('java_generate_equals_and_hash', \Google\Protobuf\Internal\GPBType::BOOL, 20)
+ ->optional('java_string_check_utf8', \Google\Protobuf\Internal\GPBType::BOOL, 27)
+ ->optional('optimize_for', \Google\Protobuf\Internal\GPBType::ENUM, 9, 'google.protobuf.internal.FileOptions.OptimizeMode')
+ ->optional('go_package', \Google\Protobuf\Internal\GPBType::STRING, 11)
+ ->optional('cc_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 16)
+ ->optional('java_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 17)
+ ->optional('py_generic_services', \Google\Protobuf\Internal\GPBType::BOOL, 18)
+ ->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 23)
+ ->optional('cc_enable_arenas', \Google\Protobuf\Internal\GPBType::BOOL, 31)
+ ->optional('objc_class_prefix', \Google\Protobuf\Internal\GPBType::STRING, 36)
+ ->optional('csharp_namespace', \Google\Protobuf\Internal\GPBType::STRING, 37)
+ ->optional('swift_prefix', \Google\Protobuf\Internal\GPBType::STRING, 39)
+ ->optional('php_class_prefix', \Google\Protobuf\Internal\GPBType::STRING, 40)
+ ->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
+ ->finalizeToPool();
+
+ $pool->addEnum('google.protobuf.internal.FileOptions.OptimizeMode', \Google\Protobuf\Internal\OptimizeMode::class)
+ ->value("SPEED", 1)
+ ->value("CODE_SIZE", 2)
+ ->value("LITE_RUNTIME", 3)
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.MessageOptions', \Google\Protobuf\Internal\MessageOptions::class)
+ ->optional('message_set_wire_format', \Google\Protobuf\Internal\GPBType::BOOL, 1)
+ ->optional('no_standard_descriptor_accessor', \Google\Protobuf\Internal\GPBType::BOOL, 2)
+ ->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 3)
+ ->optional('map_entry', \Google\Protobuf\Internal\GPBType::BOOL, 7)
+ ->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.FieldOptions', \Google\Protobuf\Internal\FieldOptions::class)
+ ->optional('ctype', \Google\Protobuf\Internal\GPBType::ENUM, 1, 'google.protobuf.internal.FieldOptions.CType')
+ ->optional('packed', \Google\Protobuf\Internal\GPBType::BOOL, 2)
+ ->optional('jstype', \Google\Protobuf\Internal\GPBType::ENUM, 6, 'google.protobuf.internal.FieldOptions.JSType')
+ ->optional('lazy', \Google\Protobuf\Internal\GPBType::BOOL, 5)
+ ->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 3)
+ ->optional('weak', \Google\Protobuf\Internal\GPBType::BOOL, 10)
+ ->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
+ ->finalizeToPool();
+
+ $pool->addEnum('google.protobuf.internal.FieldOptions.CType', \Google\Protobuf\Internal\CType::class)
+ ->value("STRING", 0)
+ ->value("CORD", 1)
+ ->value("STRING_PIECE", 2)
+ ->finalizeToPool();
+
+ $pool->addEnum('google.protobuf.internal.FieldOptions.JSType', \Google\Protobuf\Internal\JSType::class)
+ ->value("JS_NORMAL", 0)
+ ->value("JS_STRING", 1)
+ ->value("JS_NUMBER", 2)
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.OneofOptions', \Google\Protobuf\Internal\OneofOptions::class)
+ ->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.EnumOptions', \Google\Protobuf\Internal\EnumOptions::class)
+ ->optional('allow_alias', \Google\Protobuf\Internal\GPBType::BOOL, 2)
+ ->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 3)
+ ->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.EnumValueOptions', \Google\Protobuf\Internal\EnumValueOptions::class)
+ ->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 1)
+ ->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.ServiceOptions', \Google\Protobuf\Internal\ServiceOptions::class)
+ ->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 33)
+ ->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.MethodOptions', \Google\Protobuf\Internal\MethodOptions::class)
+ ->optional('deprecated', \Google\Protobuf\Internal\GPBType::BOOL, 33)
+ ->optional('idempotency_level', \Google\Protobuf\Internal\GPBType::ENUM, 34, 'google.protobuf.internal.MethodOptions.IdempotencyLevel')
+ ->repeated('uninterpreted_option', \Google\Protobuf\Internal\GPBType::MESSAGE, 999, 'google.protobuf.internal.UninterpretedOption')
+ ->finalizeToPool();
+
+ $pool->addEnum('google.protobuf.internal.MethodOptions.IdempotencyLevel', \Google\Protobuf\Internal\IdempotencyLevel::class)
+ ->value("IDEMPOTENCY_UNKNOWN", 0)
+ ->value("NO_SIDE_EFFECTS", 1)
+ ->value("IDEMPOTENT", 2)
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.UninterpretedOption', \Google\Protobuf\Internal\UninterpretedOption::class)
+ ->repeated('name', \Google\Protobuf\Internal\GPBType::MESSAGE, 2, 'google.protobuf.internal.UninterpretedOption.NamePart')
+ ->optional('identifier_value', \Google\Protobuf\Internal\GPBType::STRING, 3)
+ ->optional('positive_int_value', \Google\Protobuf\Internal\GPBType::UINT64, 4)
+ ->optional('negative_int_value', \Google\Protobuf\Internal\GPBType::INT64, 5)
+ ->optional('double_value', \Google\Protobuf\Internal\GPBType::DOUBLE, 6)
+ ->optional('string_value', \Google\Protobuf\Internal\GPBType::BYTES, 7)
+ ->optional('aggregate_value', \Google\Protobuf\Internal\GPBType::STRING, 8)
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.UninterpretedOption.NamePart', \Google\Protobuf\Internal\UninterpretedOption_NamePart::class)
+ ->required('name_part', \Google\Protobuf\Internal\GPBType::STRING, 1)
+ ->required('is_extension', \Google\Protobuf\Internal\GPBType::BOOL, 2)
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.SourceCodeInfo', \Google\Protobuf\Internal\SourceCodeInfo::class)
+ ->repeated('location', \Google\Protobuf\Internal\GPBType::MESSAGE, 1, 'google.protobuf.internal.SourceCodeInfo.Location')
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.SourceCodeInfo.Location', \Google\Protobuf\Internal\SourceCodeInfo_Location::class)
+ ->repeated('path', \Google\Protobuf\Internal\GPBType::INT32, 1)
+ ->repeated('span', \Google\Protobuf\Internal\GPBType::INT32, 2)
+ ->optional('leading_comments', \Google\Protobuf\Internal\GPBType::STRING, 3)
+ ->optional('trailing_comments', \Google\Protobuf\Internal\GPBType::STRING, 4)
+ ->repeated('leading_detached_comments', \Google\Protobuf\Internal\GPBType::STRING, 6)
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.GeneratedCodeInfo', \Google\Protobuf\Internal\GeneratedCodeInfo::class)
+ ->repeated('annotation', \Google\Protobuf\Internal\GPBType::MESSAGE, 1, 'google.protobuf.internal.GeneratedCodeInfo.Annotation')
+ ->finalizeToPool();
+
+ $pool->addMessage('google.protobuf.internal.GeneratedCodeInfo.Annotation', \Google\Protobuf\Internal\GeneratedCodeInfo_Annotation::class)
+ ->repeated('path', \Google\Protobuf\Internal\GPBType::INT32, 1)
+ ->optional('source_file', \Google\Protobuf\Internal\GPBType::STRING, 2)
+ ->optional('begin', \Google\Protobuf\Internal\GPBType::INT32, 3)
+ ->optional('end', \Google\Protobuf\Internal\GPBType::INT32, 4)
+ ->finalizeToPool();
+
+ $pool->finish();
+ static::$is_initialized = true;
+ }
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/DescriptorPool.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/DescriptorPool.php
new file mode 100644
index 0000000000..1ef403cfb7
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/DescriptorPool.php
@@ -0,0 +1,162 @@
+<?php
+
+// 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.
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\Descriptor;
+use Google\Protobuf\Internal\FileDescriptor;
+use Google\Protobuf\Internal\FileDescriptorSet;
+use Google\Protobuf\Internal\MessageBuilderContext;
+use Google\Protobuf\Internal\EnumBuilderContext;
+
+class DescriptorPool
+{
+ private static $pool;
+ // Map from message names to sub-maps, which are maps from field numbers to
+ // field descriptors.
+ private $class_to_desc = [];
+ private $class_to_enum_desc = [];
+ private $proto_to_class = [];
+
+ public static function getGeneratedPool()
+ {
+ if (!isset(self::$pool)) {
+ self::$pool = new DescriptorPool();
+ }
+ return self::$pool;
+ }
+
+ public function internalAddGeneratedFile($data)
+ {
+ $files = new FileDescriptorSet();
+ $files->mergeFromString($data);
+ $file = FileDescriptor::buildFromProto($files->getFile()[0]);
+
+ foreach ($file->getMessageType() as &$desc) {
+ $this->addDescriptor($desc);
+ }
+ unset($desc);
+
+ foreach ($file->getEnumType() as &$desc) {
+ $this->addEnumDescriptor($desc);
+ }
+ unset($desc);
+
+ foreach ($file->getMessageType() as &$desc) {
+ $this->crossLink($desc);
+ }
+ unset($desc);
+ }
+
+ public function addMessage($name, $klass)
+ {
+ return new MessageBuilderContext($name, $klass, $this);
+ }
+
+ public function addEnum($name, $klass)
+ {
+ return new EnumBuilderContext($name, $klass, $this);
+ }
+
+ public function addDescriptor($descriptor)
+ {
+ $this->proto_to_class[$descriptor->getFullName()] =
+ $descriptor->getClass();
+ $this->class_to_desc[$descriptor->getClass()] = $descriptor;
+ foreach ($descriptor->getNestedType() as $nested_type) {
+ $this->addDescriptor($nested_type);
+ }
+ }
+
+ public function addEnumDescriptor($descriptor)
+ {
+ $this->proto_to_class[$descriptor->getFullName()] =
+ $descriptor->getClass();
+ $this->class_to_enum_desc[$descriptor->getClass()] = $descriptor;
+ }
+
+ public function getDescriptorByClassName($klass)
+ {
+ return $this->class_to_desc[$klass];
+ }
+
+ public function getEnumDescriptorByClassName($klass)
+ {
+ return $this->class_to_enum_desc[$klass];
+ }
+
+ public function getDescriptorByProtoName($proto)
+ {
+ $klass = $this->proto_to_class[$proto];
+ return $this->class_to_desc[$klass];
+ }
+
+ public function getEnumDescriptorByProtoName($proto)
+ {
+ $klass = $this->proto_to_class[$proto];
+ return $this->class_to_enum_desc[$klass];
+ }
+
+ private function crossLink(&$desc)
+ {
+ foreach ($desc->getField() as &$field) {
+ switch ($field->getType()) {
+ case GPBType::MESSAGE:
+ $proto = $field->getMessageType();
+ $field->setMessageType(
+ $this->getDescriptorByProtoName($proto));
+ break;
+ case GPBType::ENUM:
+ $proto = $field->getEnumType();
+ $field->setEnumType(
+ $this->getEnumDescriptorByProtoName($proto));
+ break;
+ default:
+ break;
+ }
+ }
+ unset($field);
+
+ foreach ($desc->getNestedType() as &$nested_type) {
+ $this->crossLink($nested_type);
+ }
+ unset($nested_type);
+ }
+
+ public function finish()
+ {
+ foreach ($this->class_to_desc as $klass => &$desc) {
+ $this->crossLink($desc);
+ }
+ unset($desc);
+ }
+}
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/DescriptorProto.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/DescriptorProto.php
new file mode 100644
index 0000000000..948c5876bb
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/DescriptorProto.php
@@ -0,0 +1,325 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * <pre>
+ * Describes a message type.
+ * </pre>
+ *
+ * Protobuf type <code>google.protobuf.DescriptorProto</code>
+ */
+class DescriptorProto extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ private $name = '';
+ private $has_name = false;
+ /**
+ * <code>repeated .google.protobuf.FieldDescriptorProto field = 2;</code>
+ */
+ private $field;
+ private $has_field = false;
+ /**
+ * <code>repeated .google.protobuf.FieldDescriptorProto extension = 6;</code>
+ */
+ private $extension;
+ private $has_extension = false;
+ /**
+ * <code>repeated .google.protobuf.DescriptorProto nested_type = 3;</code>
+ */
+ private $nested_type;
+ private $has_nested_type = false;
+ /**
+ * <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 4;</code>
+ */
+ private $enum_type;
+ private $has_enum_type = false;
+ /**
+ * <code>repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5;</code>
+ */
+ private $extension_range;
+ private $has_extension_range = false;
+ /**
+ * <code>repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8;</code>
+ */
+ private $oneof_decl;
+ private $has_oneof_decl = false;
+ /**
+ * <code>optional .google.protobuf.MessageOptions options = 7;</code>
+ */
+ private $options = null;
+ private $has_options = false;
+ /**
+ * <code>repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9;</code>
+ */
+ private $reserved_range;
+ private $has_reserved_range = false;
+ /**
+ * <pre>
+ * Reserved field names, which may not be used by fields in the same message.
+ * A given name may only be reserved once.
+ * </pre>
+ *
+ * <code>repeated string reserved_name = 10;</code>
+ */
+ private $reserved_name;
+ private $has_reserved_name = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ public function setName($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->name = $var;
+ $this->has_name = true;
+ }
+
+ public function hasName()
+ {
+ return $this->has_name;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.FieldDescriptorProto field = 2;</code>
+ */
+ public function getField()
+ {
+ return $this->field;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.FieldDescriptorProto field = 2;</code>
+ */
+ public function setField(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class);
+ $this->field = $arr;
+ $this->has_field = true;
+ }
+
+ public function hasField()
+ {
+ return $this->has_field;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.FieldDescriptorProto extension = 6;</code>
+ */
+ public function getExtension()
+ {
+ return $this->extension;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.FieldDescriptorProto extension = 6;</code>
+ */
+ public function setExtension(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class);
+ $this->extension = $arr;
+ $this->has_extension = true;
+ }
+
+ public function hasExtension()
+ {
+ return $this->has_extension;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.DescriptorProto nested_type = 3;</code>
+ */
+ public function getNestedType()
+ {
+ return $this->nested_type;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.DescriptorProto nested_type = 3;</code>
+ */
+ public function setNestedType(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto::class);
+ $this->nested_type = $arr;
+ $this->has_nested_type = true;
+ }
+
+ public function hasNestedType()
+ {
+ return $this->has_nested_type;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 4;</code>
+ */
+ public function getEnumType()
+ {
+ return $this->enum_type;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 4;</code>
+ */
+ public function setEnumType(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto::class);
+ $this->enum_type = $arr;
+ $this->has_enum_type = true;
+ }
+
+ public function hasEnumType()
+ {
+ return $this->has_enum_type;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5;</code>
+ */
+ public function getExtensionRange()
+ {
+ return $this->extension_range;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5;</code>
+ */
+ public function setExtensionRange(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto_ExtensionRange::class);
+ $this->extension_range = $arr;
+ $this->has_extension_range = true;
+ }
+
+ public function hasExtensionRange()
+ {
+ return $this->has_extension_range;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8;</code>
+ */
+ public function getOneofDecl()
+ {
+ return $this->oneof_decl;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8;</code>
+ */
+ public function setOneofDecl(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\OneofDescriptorProto::class);
+ $this->oneof_decl = $arr;
+ $this->has_oneof_decl = true;
+ }
+
+ public function hasOneofDecl()
+ {
+ return $this->has_oneof_decl;
+ }
+
+ /**
+ * <code>optional .google.protobuf.MessageOptions options = 7;</code>
+ */
+ public function getOptions()
+ {
+ return $this->options;
+ }
+
+ /**
+ * <code>optional .google.protobuf.MessageOptions options = 7;</code>
+ */
+ public function setOptions(&$var)
+ {
+ GPBUtil::checkMessage($var, \Google\Protobuf\Internal\MessageOptions::class);
+ $this->options = $var;
+ $this->has_options = true;
+ }
+
+ public function hasOptions()
+ {
+ return $this->has_options;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9;</code>
+ */
+ public function getReservedRange()
+ {
+ return $this->reserved_range;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9;</code>
+ */
+ public function setReservedRange(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto_ReservedRange::class);
+ $this->reserved_range = $arr;
+ $this->has_reserved_range = true;
+ }
+
+ public function hasReservedRange()
+ {
+ return $this->has_reserved_range;
+ }
+
+ /**
+ * <pre>
+ * Reserved field names, which may not be used by fields in the same message.
+ * A given name may only be reserved once.
+ * </pre>
+ *
+ * <code>repeated string reserved_name = 10;</code>
+ */
+ public function getReservedName()
+ {
+ return $this->reserved_name;
+ }
+
+ /**
+ * <pre>
+ * Reserved field names, which may not be used by fields in the same message.
+ * A given name may only be reserved once.
+ * </pre>
+ *
+ * <code>repeated string reserved_name = 10;</code>
+ */
+ public function setReservedName(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
+ $this->reserved_name = $arr;
+ $this->has_reserved_name = true;
+ }
+
+ public function hasReservedName()
+ {
+ return $this->has_reserved_name;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php
new file mode 100644
index 0000000000..738a17389e
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php
@@ -0,0 +1,82 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * Protobuf type <code>google.protobuf.DescriptorProto.ExtensionRange</code>
+ */
+class DescriptorProto_ExtensionRange extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <code>optional int32 start = 1;</code>
+ */
+ private $start = 0;
+ private $has_start = false;
+ /**
+ * <code>optional int32 end = 2;</code>
+ */
+ private $end = 0;
+ private $has_end = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <code>optional int32 start = 1;</code>
+ */
+ public function getStart()
+ {
+ return $this->start;
+ }
+
+ /**
+ * <code>optional int32 start = 1;</code>
+ */
+ public function setStart($var)
+ {
+ GPBUtil::checkInt32($var);
+ $this->start = $var;
+ $this->has_start = true;
+ }
+
+ public function hasStart()
+ {
+ return $this->has_start;
+ }
+
+ /**
+ * <code>optional int32 end = 2;</code>
+ */
+ public function getEnd()
+ {
+ return $this->end;
+ }
+
+ /**
+ * <code>optional int32 end = 2;</code>
+ */
+ public function setEnd($var)
+ {
+ GPBUtil::checkInt32($var);
+ $this->end = $var;
+ $this->has_end = true;
+ }
+
+ public function hasEnd()
+ {
+ return $this->has_end;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php
new file mode 100644
index 0000000000..be36b8aa38
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php
@@ -0,0 +1,112 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * <pre>
+ * Range of reserved tag numbers. Reserved tag numbers may not be used by
+ * fields or extension ranges in the same message. Reserved ranges may
+ * not overlap.
+ * </pre>
+ *
+ * Protobuf type <code>google.protobuf.DescriptorProto.ReservedRange</code>
+ */
+class DescriptorProto_ReservedRange extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <pre>
+ * Inclusive.
+ * </pre>
+ *
+ * <code>optional int32 start = 1;</code>
+ */
+ private $start = 0;
+ private $has_start = false;
+ /**
+ * <pre>
+ * Exclusive.
+ * </pre>
+ *
+ * <code>optional int32 end = 2;</code>
+ */
+ private $end = 0;
+ private $has_end = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <pre>
+ * Inclusive.
+ * </pre>
+ *
+ * <code>optional int32 start = 1;</code>
+ */
+ public function getStart()
+ {
+ return $this->start;
+ }
+
+ /**
+ * <pre>
+ * Inclusive.
+ * </pre>
+ *
+ * <code>optional int32 start = 1;</code>
+ */
+ public function setStart($var)
+ {
+ GPBUtil::checkInt32($var);
+ $this->start = $var;
+ $this->has_start = true;
+ }
+
+ public function hasStart()
+ {
+ return $this->has_start;
+ }
+
+ /**
+ * <pre>
+ * Exclusive.
+ * </pre>
+ *
+ * <code>optional int32 end = 2;</code>
+ */
+ public function getEnd()
+ {
+ return $this->end;
+ }
+
+ /**
+ * <pre>
+ * Exclusive.
+ * </pre>
+ *
+ * <code>optional int32 end = 2;</code>
+ */
+ public function setEnd($var)
+ {
+ GPBUtil::checkInt32($var);
+ $this->end = $var;
+ $this->has_end = true;
+ }
+
+ public function hasEnd()
+ {
+ return $this->has_end;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/EnumBuilderContext.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/EnumBuilderContext.php
new file mode 100644
index 0000000000..c1dac24dd8
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/EnumBuilderContext.php
@@ -0,0 +1,63 @@
+<?php
+
+// 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.
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\EnumDescriptor;
+use Google\Protobuf\Internal\EnumValueDescriptor;
+
+class EnumBuilderContext
+{
+
+ private $descriptor;
+ private $pool;
+
+ public function __construct($full_name, $klass, $pool)
+ {
+ $this->descriptor = new EnumDescriptor();
+ $this->descriptor->setFullName($full_name);
+ $this->descriptor->setClass($klass);
+ $this->pool = $pool;
+ }
+
+ public function value($name, $number)
+ {
+ $value = new EnumValueDescriptor();
+ $this->descriptor->addValue($number, $value);
+ return $this;
+ }
+
+ public function finalizeToPool()
+ {
+ $this->pool->addEnumDescriptor($this->descriptor);
+ }
+}
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php
new file mode 100644
index 0000000000..73f6edbd9d
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/EnumDescriptorProto.php
@@ -0,0 +1,114 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * <pre>
+ * Describes an enum type.
+ * </pre>
+ *
+ * Protobuf type <code>google.protobuf.EnumDescriptorProto</code>
+ */
+class EnumDescriptorProto extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ private $name = '';
+ private $has_name = false;
+ /**
+ * <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code>
+ */
+ private $value;
+ private $has_value = false;
+ /**
+ * <code>optional .google.protobuf.EnumOptions options = 3;</code>
+ */
+ private $options = null;
+ private $has_options = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ public function setName($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->name = $var;
+ $this->has_name = true;
+ }
+
+ public function hasName()
+ {
+ return $this->has_name;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code>
+ */
+ public function getValue()
+ {
+ return $this->value;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code>
+ */
+ public function setValue(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumValueDescriptorProto::class);
+ $this->value = $arr;
+ $this->has_value = true;
+ }
+
+ public function hasValue()
+ {
+ return $this->has_value;
+ }
+
+ /**
+ * <code>optional .google.protobuf.EnumOptions options = 3;</code>
+ */
+ public function getOptions()
+ {
+ return $this->options;
+ }
+
+ /**
+ * <code>optional .google.protobuf.EnumOptions options = 3;</code>
+ */
+ public function setOptions(&$var)
+ {
+ GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumOptions::class);
+ $this->options = $var;
+ $this->has_options = true;
+ }
+
+ public function hasOptions()
+ {
+ return $this->has_options;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/EnumOptions.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/EnumOptions.php
new file mode 100644
index 0000000000..4fa0bce79d
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/EnumOptions.php
@@ -0,0 +1,158 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * Protobuf type <code>google.protobuf.EnumOptions</code>
+ */
+class EnumOptions extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <pre>
+ * Set this option to true to allow mapping different tag names to the same
+ * value.
+ * </pre>
+ *
+ * <code>optional bool allow_alias = 2;</code>
+ */
+ private $allow_alias = false;
+ private $has_allow_alias = false;
+ /**
+ * <pre>
+ * Is this enum deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for the enum, or it will be completely ignored; in the very least, this
+ * is a formalization for deprecating enums.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 3 [default = false];</code>
+ */
+ private $deprecated = false;
+ private $has_deprecated = false;
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ private $uninterpreted_option;
+ private $has_uninterpreted_option = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <pre>
+ * Set this option to true to allow mapping different tag names to the same
+ * value.
+ * </pre>
+ *
+ * <code>optional bool allow_alias = 2;</code>
+ */
+ public function getAllowAlias()
+ {
+ return $this->allow_alias;
+ }
+
+ /**
+ * <pre>
+ * Set this option to true to allow mapping different tag names to the same
+ * value.
+ * </pre>
+ *
+ * <code>optional bool allow_alias = 2;</code>
+ */
+ public function setAllowAlias($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->allow_alias = $var;
+ $this->has_allow_alias = true;
+ }
+
+ public function hasAllowAlias()
+ {
+ return $this->has_allow_alias;
+ }
+
+ /**
+ * <pre>
+ * Is this enum deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for the enum, or it will be completely ignored; in the very least, this
+ * is a formalization for deprecating enums.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 3 [default = false];</code>
+ */
+ public function getDeprecated()
+ {
+ return $this->deprecated;
+ }
+
+ /**
+ * <pre>
+ * Is this enum deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for the enum, or it will be completely ignored; in the very least, this
+ * is a formalization for deprecating enums.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 3 [default = false];</code>
+ */
+ public function setDeprecated($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->deprecated = $var;
+ $this->has_deprecated = true;
+ }
+
+ public function hasDeprecated()
+ {
+ return $this->has_deprecated;
+ }
+
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ public function getUninterpretedOption()
+ {
+ return $this->uninterpreted_option;
+ }
+
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ public function setUninterpretedOption(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
+ $this->uninterpreted_option = $arr;
+ $this->has_uninterpreted_option = true;
+ }
+
+ public function hasUninterpretedOption()
+ {
+ return $this->has_uninterpreted_option;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php
new file mode 100644
index 0000000000..94dc36ec4e
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php
@@ -0,0 +1,114 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * <pre>
+ * Describes a value within an enum.
+ * </pre>
+ *
+ * Protobuf type <code>google.protobuf.EnumValueDescriptorProto</code>
+ */
+class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ private $name = '';
+ private $has_name = false;
+ /**
+ * <code>optional int32 number = 2;</code>
+ */
+ private $number = 0;
+ private $has_number = false;
+ /**
+ * <code>optional .google.protobuf.EnumValueOptions options = 3;</code>
+ */
+ private $options = null;
+ private $has_options = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ public function setName($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->name = $var;
+ $this->has_name = true;
+ }
+
+ public function hasName()
+ {
+ return $this->has_name;
+ }
+
+ /**
+ * <code>optional int32 number = 2;</code>
+ */
+ public function getNumber()
+ {
+ return $this->number;
+ }
+
+ /**
+ * <code>optional int32 number = 2;</code>
+ */
+ public function setNumber($var)
+ {
+ GPBUtil::checkInt32($var);
+ $this->number = $var;
+ $this->has_number = true;
+ }
+
+ public function hasNumber()
+ {
+ return $this->has_number;
+ }
+
+ /**
+ * <code>optional .google.protobuf.EnumValueOptions options = 3;</code>
+ */
+ public function getOptions()
+ {
+ return $this->options;
+ }
+
+ /**
+ * <code>optional .google.protobuf.EnumValueOptions options = 3;</code>
+ */
+ public function setOptions(&$var)
+ {
+ GPBUtil::checkMessage($var, \Google\Protobuf\Internal\EnumValueOptions::class);
+ $this->options = $var;
+ $this->has_options = true;
+ }
+
+ public function hasOptions()
+ {
+ return $this->has_options;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/EnumValueOptions.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/EnumValueOptions.php
new file mode 100644
index 0000000000..232a6738a6
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/EnumValueOptions.php
@@ -0,0 +1,115 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * Protobuf type <code>google.protobuf.EnumValueOptions</code>
+ */
+class EnumValueOptions extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <pre>
+ * Is this enum value deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for the enum value, or it will be completely ignored; in the very least,
+ * this is a formalization for deprecating enum values.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 1 [default = false];</code>
+ */
+ private $deprecated = false;
+ private $has_deprecated = false;
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ private $uninterpreted_option;
+ private $has_uninterpreted_option = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <pre>
+ * Is this enum value deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for the enum value, or it will be completely ignored; in the very least,
+ * this is a formalization for deprecating enum values.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 1 [default = false];</code>
+ */
+ public function getDeprecated()
+ {
+ return $this->deprecated;
+ }
+
+ /**
+ * <pre>
+ * Is this enum value deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for the enum value, or it will be completely ignored; in the very least,
+ * this is a formalization for deprecating enum values.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 1 [default = false];</code>
+ */
+ public function setDeprecated($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->deprecated = $var;
+ $this->has_deprecated = true;
+ }
+
+ public function hasDeprecated()
+ {
+ return $this->has_deprecated;
+ }
+
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ public function getUninterpretedOption()
+ {
+ return $this->uninterpreted_option;
+ }
+
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ public function setUninterpretedOption(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
+ $this->uninterpreted_option = $arr;
+ $this->has_uninterpreted_option = true;
+ }
+
+ public function hasUninterpretedOption()
+ {
+ return $this->has_uninterpreted_option;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php
new file mode 100644
index 0000000000..6ae2cd418a
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php
@@ -0,0 +1,424 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * <pre>
+ * Describes a field within a message.
+ * </pre>
+ *
+ * Protobuf type <code>google.protobuf.FieldDescriptorProto</code>
+ */
+class FieldDescriptorProto extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ private $name = '';
+ private $has_name = false;
+ /**
+ * <code>optional int32 number = 3;</code>
+ */
+ private $number = 0;
+ private $has_number = false;
+ /**
+ * <code>optional .google.protobuf.FieldDescriptorProto.Label label = 4;</code>
+ */
+ private $label = 0;
+ private $has_label = false;
+ /**
+ * <pre>
+ * If type_name is set, this need not be set. If both this and type_name
+ * are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
+ * </pre>
+ *
+ * <code>optional .google.protobuf.FieldDescriptorProto.Type type = 5;</code>
+ */
+ private $type = 0;
+ private $has_type = false;
+ /**
+ * <pre>
+ * For message and enum types, this is the name of the type. If the name
+ * starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
+ * rules are used to find the type (i.e. first the nested types within this
+ * message are searched, then within the parent, on up to the root
+ * namespace).
+ * </pre>
+ *
+ * <code>optional string type_name = 6;</code>
+ */
+ private $type_name = '';
+ private $has_type_name = false;
+ /**
+ * <pre>
+ * For extensions, this is the name of the type being extended. It is
+ * resolved in the same manner as type_name.
+ * </pre>
+ *
+ * <code>optional string extendee = 2;</code>
+ */
+ private $extendee = '';
+ private $has_extendee = false;
+ /**
+ * <pre>
+ * For numeric types, contains the original text representation of the value.
+ * For booleans, "true" or "false".
+ * For strings, contains the default text contents (not escaped in any way).
+ * For bytes, contains the C escaped value. All bytes &gt;= 128 are escaped.
+ * TODO(kenton): Base-64 encode?
+ * </pre>
+ *
+ * <code>optional string default_value = 7;</code>
+ */
+ private $default_value = '';
+ private $has_default_value = false;
+ /**
+ * <pre>
+ * If set, gives the index of a oneof in the containing type's oneof_decl
+ * list. This field is a member of that oneof.
+ * </pre>
+ *
+ * <code>optional int32 oneof_index = 9;</code>
+ */
+ private $oneof_index = 0;
+ private $has_oneof_index = false;
+ /**
+ * <pre>
+ * JSON name of this field. The value is set by protocol compiler. If the
+ * user has set a "json_name" option on this field, that option's value
+ * will be used. Otherwise, it's deduced from the field's name by converting
+ * it to camelCase.
+ * </pre>
+ *
+ * <code>optional string json_name = 10;</code>
+ */
+ private $json_name = '';
+ private $has_json_name = false;
+ /**
+ * <code>optional .google.protobuf.FieldOptions options = 8;</code>
+ */
+ private $options = null;
+ private $has_options = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ public function setName($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->name = $var;
+ $this->has_name = true;
+ }
+
+ public function hasName()
+ {
+ return $this->has_name;
+ }
+
+ /**
+ * <code>optional int32 number = 3;</code>
+ */
+ public function getNumber()
+ {
+ return $this->number;
+ }
+
+ /**
+ * <code>optional int32 number = 3;</code>
+ */
+ public function setNumber($var)
+ {
+ GPBUtil::checkInt32($var);
+ $this->number = $var;
+ $this->has_number = true;
+ }
+
+ public function hasNumber()
+ {
+ return $this->has_number;
+ }
+
+ /**
+ * <code>optional .google.protobuf.FieldDescriptorProto.Label label = 4;</code>
+ */
+ public function getLabel()
+ {
+ return $this->label;
+ }
+
+ /**
+ * <code>optional .google.protobuf.FieldDescriptorProto.Label label = 4;</code>
+ */
+ public function setLabel($var)
+ {
+ GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto_Label::class);
+ $this->label = $var;
+ $this->has_label = true;
+ }
+
+ public function hasLabel()
+ {
+ return $this->has_label;
+ }
+
+ /**
+ * <pre>
+ * If type_name is set, this need not be set. If both this and type_name
+ * are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
+ * </pre>
+ *
+ * <code>optional .google.protobuf.FieldDescriptorProto.Type type = 5;</code>
+ */
+ public function getType()
+ {
+ return $this->type;
+ }
+
+ /**
+ * <pre>
+ * If type_name is set, this need not be set. If both this and type_name
+ * are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
+ * </pre>
+ *
+ * <code>optional .google.protobuf.FieldDescriptorProto.Type type = 5;</code>
+ */
+ public function setType($var)
+ {
+ GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldDescriptorProto_Type::class);
+ $this->type = $var;
+ $this->has_type = true;
+ }
+
+ public function hasType()
+ {
+ return $this->has_type;
+ }
+
+ /**
+ * <pre>
+ * For message and enum types, this is the name of the type. If the name
+ * starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
+ * rules are used to find the type (i.e. first the nested types within this
+ * message are searched, then within the parent, on up to the root
+ * namespace).
+ * </pre>
+ *
+ * <code>optional string type_name = 6;</code>
+ */
+ public function getTypeName()
+ {
+ return $this->type_name;
+ }
+
+ /**
+ * <pre>
+ * For message and enum types, this is the name of the type. If the name
+ * starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
+ * rules are used to find the type (i.e. first the nested types within this
+ * message are searched, then within the parent, on up to the root
+ * namespace).
+ * </pre>
+ *
+ * <code>optional string type_name = 6;</code>
+ */
+ public function setTypeName($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->type_name = $var;
+ $this->has_type_name = true;
+ }
+
+ public function hasTypeName()
+ {
+ return $this->has_type_name;
+ }
+
+ /**
+ * <pre>
+ * For extensions, this is the name of the type being extended. It is
+ * resolved in the same manner as type_name.
+ * </pre>
+ *
+ * <code>optional string extendee = 2;</code>
+ */
+ public function getExtendee()
+ {
+ return $this->extendee;
+ }
+
+ /**
+ * <pre>
+ * For extensions, this is the name of the type being extended. It is
+ * resolved in the same manner as type_name.
+ * </pre>
+ *
+ * <code>optional string extendee = 2;</code>
+ */
+ public function setExtendee($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->extendee = $var;
+ $this->has_extendee = true;
+ }
+
+ public function hasExtendee()
+ {
+ return $this->has_extendee;
+ }
+
+ /**
+ * <pre>
+ * For numeric types, contains the original text representation of the value.
+ * For booleans, "true" or "false".
+ * For strings, contains the default text contents (not escaped in any way).
+ * For bytes, contains the C escaped value. All bytes &gt;= 128 are escaped.
+ * TODO(kenton): Base-64 encode?
+ * </pre>
+ *
+ * <code>optional string default_value = 7;</code>
+ */
+ public function getDefaultValue()
+ {
+ return $this->default_value;
+ }
+
+ /**
+ * <pre>
+ * For numeric types, contains the original text representation of the value.
+ * For booleans, "true" or "false".
+ * For strings, contains the default text contents (not escaped in any way).
+ * For bytes, contains the C escaped value. All bytes &gt;= 128 are escaped.
+ * TODO(kenton): Base-64 encode?
+ * </pre>
+ *
+ * <code>optional string default_value = 7;</code>
+ */
+ public function setDefaultValue($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->default_value = $var;
+ $this->has_default_value = true;
+ }
+
+ public function hasDefaultValue()
+ {
+ return $this->has_default_value;
+ }
+
+ /**
+ * <pre>
+ * If set, gives the index of a oneof in the containing type's oneof_decl
+ * list. This field is a member of that oneof.
+ * </pre>
+ *
+ * <code>optional int32 oneof_index = 9;</code>
+ */
+ public function getOneofIndex()
+ {
+ return $this->oneof_index;
+ }
+
+ /**
+ * <pre>
+ * If set, gives the index of a oneof in the containing type's oneof_decl
+ * list. This field is a member of that oneof.
+ * </pre>
+ *
+ * <code>optional int32 oneof_index = 9;</code>
+ */
+ public function setOneofIndex($var)
+ {
+ GPBUtil::checkInt32($var);
+ $this->oneof_index = $var;
+ $this->has_oneof_index = true;
+ }
+
+ public function hasOneofIndex()
+ {
+ return $this->has_oneof_index;
+ }
+
+ /**
+ * <pre>
+ * JSON name of this field. The value is set by protocol compiler. If the
+ * user has set a "json_name" option on this field, that option's value
+ * will be used. Otherwise, it's deduced from the field's name by converting
+ * it to camelCase.
+ * </pre>
+ *
+ * <code>optional string json_name = 10;</code>
+ */
+ public function getJsonName()
+ {
+ return $this->json_name;
+ }
+
+ /**
+ * <pre>
+ * JSON name of this field. The value is set by protocol compiler. If the
+ * user has set a "json_name" option on this field, that option's value
+ * will be used. Otherwise, it's deduced from the field's name by converting
+ * it to camelCase.
+ * </pre>
+ *
+ * <code>optional string json_name = 10;</code>
+ */
+ public function setJsonName($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->json_name = $var;
+ $this->has_json_name = true;
+ }
+
+ public function hasJsonName()
+ {
+ return $this->has_json_name;
+ }
+
+ /**
+ * <code>optional .google.protobuf.FieldOptions options = 8;</code>
+ */
+ public function getOptions()
+ {
+ return $this->options;
+ }
+
+ /**
+ * <code>optional .google.protobuf.FieldOptions options = 8;</code>
+ */
+ public function setOptions(&$var)
+ {
+ GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FieldOptions::class);
+ $this->options = $var;
+ $this->has_options = true;
+ }
+
+ public function hasOptions()
+ {
+ return $this->has_options;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldDescriptorProto_Label.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldDescriptorProto_Label.php
new file mode 100644
index 0000000000..a3cd8ef915
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldDescriptorProto_Label.php
@@ -0,0 +1,29 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+/**
+ * Protobuf enum <code>google.protobuf.FieldDescriptorProto.Label</code>
+ */
+class FieldDescriptorProto_Label
+{
+ /**
+ * <pre>
+ * 0 is reserved for errors
+ * </pre>
+ *
+ * <code>LABEL_OPTIONAL = 1;</code>
+ */
+ const LABEL_OPTIONAL = 1;
+ /**
+ * <code>LABEL_REQUIRED = 2;</code>
+ */
+ const LABEL_REQUIRED = 2;
+ /**
+ * <code>LABEL_REPEATED = 3;</code>
+ */
+ const LABEL_REPEATED = 3;
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldDescriptorProto_Type.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldDescriptorProto_Type.php
new file mode 100644
index 0000000000..8335f9b145
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldDescriptorProto_Type.php
@@ -0,0 +1,123 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+/**
+ * Protobuf enum <code>google.protobuf.FieldDescriptorProto.Type</code>
+ */
+class FieldDescriptorProto_Type
+{
+ /**
+ * <pre>
+ * 0 is reserved for errors.
+ * Order is weird for historical reasons.
+ * </pre>
+ *
+ * <code>TYPE_DOUBLE = 1;</code>
+ */
+ const TYPE_DOUBLE = 1;
+ /**
+ * <code>TYPE_FLOAT = 2;</code>
+ */
+ const TYPE_FLOAT = 2;
+ /**
+ * <pre>
+ * Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
+ * negative values are likely.
+ * </pre>
+ *
+ * <code>TYPE_INT64 = 3;</code>
+ */
+ const TYPE_INT64 = 3;
+ /**
+ * <code>TYPE_UINT64 = 4;</code>
+ */
+ const TYPE_UINT64 = 4;
+ /**
+ * <pre>
+ * Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
+ * negative values are likely.
+ * </pre>
+ *
+ * <code>TYPE_INT32 = 5;</code>
+ */
+ const TYPE_INT32 = 5;
+ /**
+ * <code>TYPE_FIXED64 = 6;</code>
+ */
+ const TYPE_FIXED64 = 6;
+ /**
+ * <code>TYPE_FIXED32 = 7;</code>
+ */
+ const TYPE_FIXED32 = 7;
+ /**
+ * <code>TYPE_BOOL = 8;</code>
+ */
+ const TYPE_BOOL = 8;
+ /**
+ * <code>TYPE_STRING = 9;</code>
+ */
+ const TYPE_STRING = 9;
+ /**
+ * <pre>
+ * Tag-delimited aggregate.
+ * Group type is deprecated and not supported in proto3. However, Proto3
+ * implementations should still be able to parse the group wire format and
+ * treat group fields as unknown fields.
+ * </pre>
+ *
+ * <code>TYPE_GROUP = 10;</code>
+ */
+ const TYPE_GROUP = 10;
+ /**
+ * <pre>
+ * Length-delimited aggregate.
+ * </pre>
+ *
+ * <code>TYPE_MESSAGE = 11;</code>
+ */
+ const TYPE_MESSAGE = 11;
+ /**
+ * <pre>
+ * New in version 2.
+ * </pre>
+ *
+ * <code>TYPE_BYTES = 12;</code>
+ */
+ const TYPE_BYTES = 12;
+ /**
+ * <code>TYPE_UINT32 = 13;</code>
+ */
+ const TYPE_UINT32 = 13;
+ /**
+ * <code>TYPE_ENUM = 14;</code>
+ */
+ const TYPE_ENUM = 14;
+ /**
+ * <code>TYPE_SFIXED32 = 15;</code>
+ */
+ const TYPE_SFIXED32 = 15;
+ /**
+ * <code>TYPE_SFIXED64 = 16;</code>
+ */
+ const TYPE_SFIXED64 = 16;
+ /**
+ * <pre>
+ * Uses ZigZag encoding.
+ * </pre>
+ *
+ * <code>TYPE_SINT32 = 17;</code>
+ */
+ const TYPE_SINT32 = 17;
+ /**
+ * <pre>
+ * Uses ZigZag encoding.
+ * </pre>
+ *
+ * <code>TYPE_SINT64 = 18;</code>
+ */
+ const TYPE_SINT64 = 18;
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldOptions.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldOptions.php
new file mode 100644
index 0000000000..8db7ed67aa
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldOptions.php
@@ -0,0 +1,429 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * Protobuf type <code>google.protobuf.FieldOptions</code>
+ */
+class FieldOptions extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <pre>
+ * The ctype option instructs the C++ code generator to use a different
+ * representation of the field than it normally would. See the specific
+ * options below. This option is not yet implemented in the open source
+ * release -- sorry, we'll try to include it in a future version!
+ * </pre>
+ *
+ * <code>optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];</code>
+ */
+ private $ctype = 0;
+ private $has_ctype = false;
+ /**
+ * <pre>
+ * The packed option can be enabled for repeated primitive fields to enable
+ * a more efficient representation on the wire. Rather than repeatedly
+ * writing the tag and type for each element, the entire array is encoded as
+ * a single length-delimited blob. In proto3, only explicit setting it to
+ * false will avoid using packed encoding.
+ * </pre>
+ *
+ * <code>optional bool packed = 2;</code>
+ */
+ private $packed = false;
+ private $has_packed = false;
+ /**
+ * <pre>
+ * 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
+ * represented as JavaScript strings. This avoids loss of precision that can
+ * happen when a large value is converted to a floating point JavaScript
+ * numbers. Specifying JS_NUMBER for the jstype causes the generated
+ * JavaScript code to use the JavaScript "number" type instead of strings.
+ * This option is an enum to permit additional types to be added,
+ * e.g. goog.math.Integer.
+ * </pre>
+ *
+ * <code>optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];</code>
+ */
+ private $jstype = 0;
+ private $has_jstype = false;
+ /**
+ * <pre>
+ * Should this field be parsed lazily? Lazy applies only to message-type
+ * fields. It means that when the outer message is initially parsed, the
+ * inner message's contents will not be parsed but instead stored in encoded
+ * form. The inner message will actually be parsed when it is first accessed.
+ * This is only a hint. Implementations are free to choose whether to use
+ * eager or lazy parsing regardless of the value of this option. However,
+ * setting this option true suggests that the protocol author believes that
+ * using lazy parsing on this field is worth the additional bookkeeping
+ * overhead typically needed to implement it.
+ * This option does not affect the public interface of any generated code;
+ * all method signatures remain the same. Furthermore, thread-safety of the
+ * interface is not affected by this option; const methods remain safe to
+ * call from multiple threads concurrently, while non-const methods continue
+ * to require exclusive access.
+ * Note that implementations may choose not to check required fields within
+ * 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
+ * parsing. An implementation which chooses not to check required fields
+ * must be consistent about it. That is, for any particular sub-message, the
+ * implementation must either *always* check its required fields, or *never*
+ * check its required fields, regardless of whether or not the message has
+ * been parsed.
+ * </pre>
+ *
+ * <code>optional bool lazy = 5 [default = false];</code>
+ */
+ private $lazy = false;
+ private $has_lazy = false;
+ /**
+ * <pre>
+ * Is this field deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for accessors, or it will be completely ignored; in the very least, this
+ * is a formalization for deprecating fields.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 3 [default = false];</code>
+ */
+ private $deprecated = false;
+ private $has_deprecated = false;
+ /**
+ * <pre>
+ * For Google-internal migration only. Do not use.
+ * </pre>
+ *
+ * <code>optional bool weak = 10 [default = false];</code>
+ */
+ private $weak = false;
+ private $has_weak = false;
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ private $uninterpreted_option;
+ private $has_uninterpreted_option = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <pre>
+ * The ctype option instructs the C++ code generator to use a different
+ * representation of the field than it normally would. See the specific
+ * options below. This option is not yet implemented in the open source
+ * release -- sorry, we'll try to include it in a future version!
+ * </pre>
+ *
+ * <code>optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];</code>
+ */
+ public function getCtype()
+ {
+ return $this->ctype;
+ }
+
+ /**
+ * <pre>
+ * The ctype option instructs the C++ code generator to use a different
+ * representation of the field than it normally would. See the specific
+ * options below. This option is not yet implemented in the open source
+ * release -- sorry, we'll try to include it in a future version!
+ * </pre>
+ *
+ * <code>optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];</code>
+ */
+ public function setCtype($var)
+ {
+ GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions_CType::class);
+ $this->ctype = $var;
+ $this->has_ctype = true;
+ }
+
+ public function hasCtype()
+ {
+ return $this->has_ctype;
+ }
+
+ /**
+ * <pre>
+ * The packed option can be enabled for repeated primitive fields to enable
+ * a more efficient representation on the wire. Rather than repeatedly
+ * writing the tag and type for each element, the entire array is encoded as
+ * a single length-delimited blob. In proto3, only explicit setting it to
+ * false will avoid using packed encoding.
+ * </pre>
+ *
+ * <code>optional bool packed = 2;</code>
+ */
+ public function getPacked()
+ {
+ return $this->packed;
+ }
+
+ /**
+ * <pre>
+ * The packed option can be enabled for repeated primitive fields to enable
+ * a more efficient representation on the wire. Rather than repeatedly
+ * writing the tag and type for each element, the entire array is encoded as
+ * a single length-delimited blob. In proto3, only explicit setting it to
+ * false will avoid using packed encoding.
+ * </pre>
+ *
+ * <code>optional bool packed = 2;</code>
+ */
+ public function setPacked($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->packed = $var;
+ $this->has_packed = true;
+ }
+
+ public function hasPacked()
+ {
+ return $this->has_packed;
+ }
+
+ /**
+ * <pre>
+ * 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
+ * represented as JavaScript strings. This avoids loss of precision that can
+ * happen when a large value is converted to a floating point JavaScript
+ * numbers. Specifying JS_NUMBER for the jstype causes the generated
+ * JavaScript code to use the JavaScript "number" type instead of strings.
+ * This option is an enum to permit additional types to be added,
+ * e.g. goog.math.Integer.
+ * </pre>
+ *
+ * <code>optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];</code>
+ */
+ public function getJstype()
+ {
+ return $this->jstype;
+ }
+
+ /**
+ * <pre>
+ * 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
+ * represented as JavaScript strings. This avoids loss of precision that can
+ * happen when a large value is converted to a floating point JavaScript
+ * numbers. Specifying JS_NUMBER for the jstype causes the generated
+ * JavaScript code to use the JavaScript "number" type instead of strings.
+ * This option is an enum to permit additional types to be added,
+ * e.g. goog.math.Integer.
+ * </pre>
+ *
+ * <code>optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];</code>
+ */
+ public function setJstype($var)
+ {
+ GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FieldOptions_JSType::class);
+ $this->jstype = $var;
+ $this->has_jstype = true;
+ }
+
+ public function hasJstype()
+ {
+ return $this->has_jstype;
+ }
+
+ /**
+ * <pre>
+ * Should this field be parsed lazily? Lazy applies only to message-type
+ * fields. It means that when the outer message is initially parsed, the
+ * inner message's contents will not be parsed but instead stored in encoded
+ * form. The inner message will actually be parsed when it is first accessed.
+ * This is only a hint. Implementations are free to choose whether to use
+ * eager or lazy parsing regardless of the value of this option. However,
+ * setting this option true suggests that the protocol author believes that
+ * using lazy parsing on this field is worth the additional bookkeeping
+ * overhead typically needed to implement it.
+ * This option does not affect the public interface of any generated code;
+ * all method signatures remain the same. Furthermore, thread-safety of the
+ * interface is not affected by this option; const methods remain safe to
+ * call from multiple threads concurrently, while non-const methods continue
+ * to require exclusive access.
+ * Note that implementations may choose not to check required fields within
+ * 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
+ * parsing. An implementation which chooses not to check required fields
+ * must be consistent about it. That is, for any particular sub-message, the
+ * implementation must either *always* check its required fields, or *never*
+ * check its required fields, regardless of whether or not the message has
+ * been parsed.
+ * </pre>
+ *
+ * <code>optional bool lazy = 5 [default = false];</code>
+ */
+ public function getLazy()
+ {
+ return $this->lazy;
+ }
+
+ /**
+ * <pre>
+ * Should this field be parsed lazily? Lazy applies only to message-type
+ * fields. It means that when the outer message is initially parsed, the
+ * inner message's contents will not be parsed but instead stored in encoded
+ * form. The inner message will actually be parsed when it is first accessed.
+ * This is only a hint. Implementations are free to choose whether to use
+ * eager or lazy parsing regardless of the value of this option. However,
+ * setting this option true suggests that the protocol author believes that
+ * using lazy parsing on this field is worth the additional bookkeeping
+ * overhead typically needed to implement it.
+ * This option does not affect the public interface of any generated code;
+ * all method signatures remain the same. Furthermore, thread-safety of the
+ * interface is not affected by this option; const methods remain safe to
+ * call from multiple threads concurrently, while non-const methods continue
+ * to require exclusive access.
+ * Note that implementations may choose not to check required fields within
+ * 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
+ * parsing. An implementation which chooses not to check required fields
+ * must be consistent about it. That is, for any particular sub-message, the
+ * implementation must either *always* check its required fields, or *never*
+ * check its required fields, regardless of whether or not the message has
+ * been parsed.
+ * </pre>
+ *
+ * <code>optional bool lazy = 5 [default = false];</code>
+ */
+ public function setLazy($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->lazy = $var;
+ $this->has_lazy = true;
+ }
+
+ public function hasLazy()
+ {
+ return $this->has_lazy;
+ }
+
+ /**
+ * <pre>
+ * Is this field deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for accessors, or it will be completely ignored; in the very least, this
+ * is a formalization for deprecating fields.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 3 [default = false];</code>
+ */
+ public function getDeprecated()
+ {
+ return $this->deprecated;
+ }
+
+ /**
+ * <pre>
+ * Is this field deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for accessors, or it will be completely ignored; in the very least, this
+ * is a formalization for deprecating fields.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 3 [default = false];</code>
+ */
+ public function setDeprecated($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->deprecated = $var;
+ $this->has_deprecated = true;
+ }
+
+ public function hasDeprecated()
+ {
+ return $this->has_deprecated;
+ }
+
+ /**
+ * <pre>
+ * For Google-internal migration only. Do not use.
+ * </pre>
+ *
+ * <code>optional bool weak = 10 [default = false];</code>
+ */
+ public function getWeak()
+ {
+ return $this->weak;
+ }
+
+ /**
+ * <pre>
+ * For Google-internal migration only. Do not use.
+ * </pre>
+ *
+ * <code>optional bool weak = 10 [default = false];</code>
+ */
+ public function setWeak($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->weak = $var;
+ $this->has_weak = true;
+ }
+
+ public function hasWeak()
+ {
+ return $this->has_weak;
+ }
+
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ public function getUninterpretedOption()
+ {
+ return $this->uninterpreted_option;
+ }
+
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ public function setUninterpretedOption(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
+ $this->uninterpreted_option = $arr;
+ $this->has_uninterpreted_option = true;
+ }
+
+ public function hasUninterpretedOption()
+ {
+ return $this->has_uninterpreted_option;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldOptions_CType.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldOptions_CType.php
new file mode 100644
index 0000000000..f59f20be11
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldOptions_CType.php
@@ -0,0 +1,29 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+/**
+ * Protobuf enum <code>google.protobuf.FieldOptions.CType</code>
+ */
+class FieldOptions_CType
+{
+ /**
+ * <pre>
+ * Default mode.
+ * </pre>
+ *
+ * <code>STRING = 0;</code>
+ */
+ const STRING = 0;
+ /**
+ * <code>CORD = 1;</code>
+ */
+ const CORD = 1;
+ /**
+ * <code>STRING_PIECE = 2;</code>
+ */
+ const STRING_PIECE = 2;
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldOptions_JSType.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldOptions_JSType.php
new file mode 100644
index 0000000000..0c6995b7c3
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/FieldOptions_JSType.php
@@ -0,0 +1,37 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+/**
+ * Protobuf enum <code>google.protobuf.FieldOptions.JSType</code>
+ */
+class FieldOptions_JSType
+{
+ /**
+ * <pre>
+ * Use the default type.
+ * </pre>
+ *
+ * <code>JS_NORMAL = 0;</code>
+ */
+ const JS_NORMAL = 0;
+ /**
+ * <pre>
+ * Use JavaScript strings.
+ * </pre>
+ *
+ * <code>JS_STRING = 1;</code>
+ */
+ const JS_STRING = 1;
+ /**
+ * <pre>
+ * Use JavaScript numbers.
+ * </pre>
+ *
+ * <code>JS_NUMBER = 2;</code>
+ */
+ const JS_NUMBER = 2;
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/FileDescriptorProto.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/FileDescriptorProto.php
new file mode 100644
index 0000000000..0363d9e98c
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/FileDescriptorProto.php
@@ -0,0 +1,477 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * <pre>
+ * Describes a complete .proto file.
+ * </pre>
+ *
+ * Protobuf type <code>google.protobuf.FileDescriptorProto</code>
+ */
+class FileDescriptorProto extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <pre>
+ * file name, relative to root of source tree
+ * </pre>
+ *
+ * <code>optional string name = 1;</code>
+ */
+ private $name = '';
+ private $has_name = false;
+ /**
+ * <pre>
+ * e.g. "foo", "foo.bar", etc.
+ * </pre>
+ *
+ * <code>optional string package = 2;</code>
+ */
+ private $package = '';
+ private $has_package = false;
+ /**
+ * <pre>
+ * Names of files imported by this file.
+ * </pre>
+ *
+ * <code>repeated string dependency = 3;</code>
+ */
+ private $dependency;
+ private $has_dependency = false;
+ /**
+ * <pre>
+ * Indexes of the public imported files in the dependency list above.
+ * </pre>
+ *
+ * <code>repeated int32 public_dependency = 10;</code>
+ */
+ private $public_dependency;
+ private $has_public_dependency = false;
+ /**
+ * <pre>
+ * Indexes of the weak imported files in the dependency list.
+ * For Google-internal migration only. Do not use.
+ * </pre>
+ *
+ * <code>repeated int32 weak_dependency = 11;</code>
+ */
+ private $weak_dependency;
+ private $has_weak_dependency = false;
+ /**
+ * <pre>
+ * All top-level definitions in this file.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.DescriptorProto message_type = 4;</code>
+ */
+ private $message_type;
+ private $has_message_type = false;
+ /**
+ * <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 5;</code>
+ */
+ private $enum_type;
+ private $has_enum_type = false;
+ /**
+ * <code>repeated .google.protobuf.ServiceDescriptorProto service = 6;</code>
+ */
+ private $service;
+ private $has_service = false;
+ /**
+ * <code>repeated .google.protobuf.FieldDescriptorProto extension = 7;</code>
+ */
+ private $extension;
+ private $has_extension = false;
+ /**
+ * <code>optional .google.protobuf.FileOptions options = 8;</code>
+ */
+ private $options = null;
+ private $has_options = false;
+ /**
+ * <pre>
+ * This field contains optional information about the original source code.
+ * You may safely remove this entire field without harming runtime
+ * functionality of the descriptors -- the information is needed only by
+ * development tools.
+ * </pre>
+ *
+ * <code>optional .google.protobuf.SourceCodeInfo source_code_info = 9;</code>
+ */
+ private $source_code_info = null;
+ private $has_source_code_info = false;
+ /**
+ * <pre>
+ * The syntax of the proto file.
+ * The supported values are "proto2" and "proto3".
+ * </pre>
+ *
+ * <code>optional string syntax = 12;</code>
+ */
+ private $syntax = '';
+ private $has_syntax = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <pre>
+ * file name, relative to root of source tree
+ * </pre>
+ *
+ * <code>optional string name = 1;</code>
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * <pre>
+ * file name, relative to root of source tree
+ * </pre>
+ *
+ * <code>optional string name = 1;</code>
+ */
+ public function setName($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->name = $var;
+ $this->has_name = true;
+ }
+
+ public function hasName()
+ {
+ return $this->has_name;
+ }
+
+ /**
+ * <pre>
+ * e.g. "foo", "foo.bar", etc.
+ * </pre>
+ *
+ * <code>optional string package = 2;</code>
+ */
+ public function getPackage()
+ {
+ return $this->package;
+ }
+
+ /**
+ * <pre>
+ * e.g. "foo", "foo.bar", etc.
+ * </pre>
+ *
+ * <code>optional string package = 2;</code>
+ */
+ public function setPackage($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->package = $var;
+ $this->has_package = true;
+ }
+
+ public function hasPackage()
+ {
+ return $this->has_package;
+ }
+
+ /**
+ * <pre>
+ * Names of files imported by this file.
+ * </pre>
+ *
+ * <code>repeated string dependency = 3;</code>
+ */
+ public function getDependency()
+ {
+ return $this->dependency;
+ }
+
+ /**
+ * <pre>
+ * Names of files imported by this file.
+ * </pre>
+ *
+ * <code>repeated string dependency = 3;</code>
+ */
+ public function setDependency(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
+ $this->dependency = $arr;
+ $this->has_dependency = true;
+ }
+
+ public function hasDependency()
+ {
+ return $this->has_dependency;
+ }
+
+ /**
+ * <pre>
+ * Indexes of the public imported files in the dependency list above.
+ * </pre>
+ *
+ * <code>repeated int32 public_dependency = 10;</code>
+ */
+ public function getPublicDependency()
+ {
+ return $this->public_dependency;
+ }
+
+ /**
+ * <pre>
+ * Indexes of the public imported files in the dependency list above.
+ * </pre>
+ *
+ * <code>repeated int32 public_dependency = 10;</code>
+ */
+ public function setPublicDependency(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
+ $this->public_dependency = $arr;
+ $this->has_public_dependency = true;
+ }
+
+ public function hasPublicDependency()
+ {
+ return $this->has_public_dependency;
+ }
+
+ /**
+ * <pre>
+ * Indexes of the weak imported files in the dependency list.
+ * For Google-internal migration only. Do not use.
+ * </pre>
+ *
+ * <code>repeated int32 weak_dependency = 11;</code>
+ */
+ public function getWeakDependency()
+ {
+ return $this->weak_dependency;
+ }
+
+ /**
+ * <pre>
+ * Indexes of the weak imported files in the dependency list.
+ * For Google-internal migration only. Do not use.
+ * </pre>
+ *
+ * <code>repeated int32 weak_dependency = 11;</code>
+ */
+ public function setWeakDependency(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
+ $this->weak_dependency = $arr;
+ $this->has_weak_dependency = true;
+ }
+
+ public function hasWeakDependency()
+ {
+ return $this->has_weak_dependency;
+ }
+
+ /**
+ * <pre>
+ * All top-level definitions in this file.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.DescriptorProto message_type = 4;</code>
+ */
+ public function getMessageType()
+ {
+ return $this->message_type;
+ }
+
+ /**
+ * <pre>
+ * All top-level definitions in this file.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.DescriptorProto message_type = 4;</code>
+ */
+ public function setMessageType(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\DescriptorProto::class);
+ $this->message_type = $arr;
+ $this->has_message_type = true;
+ }
+
+ public function hasMessageType()
+ {
+ return $this->has_message_type;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 5;</code>
+ */
+ public function getEnumType()
+ {
+ return $this->enum_type;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.EnumDescriptorProto enum_type = 5;</code>
+ */
+ public function setEnumType(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\EnumDescriptorProto::class);
+ $this->enum_type = $arr;
+ $this->has_enum_type = true;
+ }
+
+ public function hasEnumType()
+ {
+ return $this->has_enum_type;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.ServiceDescriptorProto service = 6;</code>
+ */
+ public function getService()
+ {
+ return $this->service;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.ServiceDescriptorProto service = 6;</code>
+ */
+ public function setService(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\ServiceDescriptorProto::class);
+ $this->service = $arr;
+ $this->has_service = true;
+ }
+
+ public function hasService()
+ {
+ return $this->has_service;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.FieldDescriptorProto extension = 7;</code>
+ */
+ public function getExtension()
+ {
+ return $this->extension;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.FieldDescriptorProto extension = 7;</code>
+ */
+ public function setExtension(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FieldDescriptorProto::class);
+ $this->extension = $arr;
+ $this->has_extension = true;
+ }
+
+ public function hasExtension()
+ {
+ return $this->has_extension;
+ }
+
+ /**
+ * <code>optional .google.protobuf.FileOptions options = 8;</code>
+ */
+ public function getOptions()
+ {
+ return $this->options;
+ }
+
+ /**
+ * <code>optional .google.protobuf.FileOptions options = 8;</code>
+ */
+ public function setOptions(&$var)
+ {
+ GPBUtil::checkMessage($var, \Google\Protobuf\Internal\FileOptions::class);
+ $this->options = $var;
+ $this->has_options = true;
+ }
+
+ public function hasOptions()
+ {
+ return $this->has_options;
+ }
+
+ /**
+ * <pre>
+ * This field contains optional information about the original source code.
+ * You may safely remove this entire field without harming runtime
+ * functionality of the descriptors -- the information is needed only by
+ * development tools.
+ * </pre>
+ *
+ * <code>optional .google.protobuf.SourceCodeInfo source_code_info = 9;</code>
+ */
+ public function getSourceCodeInfo()
+ {
+ return $this->source_code_info;
+ }
+
+ /**
+ * <pre>
+ * This field contains optional information about the original source code.
+ * You may safely remove this entire field without harming runtime
+ * functionality of the descriptors -- the information is needed only by
+ * development tools.
+ * </pre>
+ *
+ * <code>optional .google.protobuf.SourceCodeInfo source_code_info = 9;</code>
+ */
+ public function setSourceCodeInfo(&$var)
+ {
+ GPBUtil::checkMessage($var, \Google\Protobuf\Internal\SourceCodeInfo::class);
+ $this->source_code_info = $var;
+ $this->has_source_code_info = true;
+ }
+
+ public function hasSourceCodeInfo()
+ {
+ return $this->has_source_code_info;
+ }
+
+ /**
+ * <pre>
+ * The syntax of the proto file.
+ * The supported values are "proto2" and "proto3".
+ * </pre>
+ *
+ * <code>optional string syntax = 12;</code>
+ */
+ public function getSyntax()
+ {
+ return $this->syntax;
+ }
+
+ /**
+ * <pre>
+ * The syntax of the proto file.
+ * The supported values are "proto2" and "proto3".
+ * </pre>
+ *
+ * <code>optional string syntax = 12;</code>
+ */
+ public function setSyntax($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->syntax = $var;
+ $this->has_syntax = true;
+ }
+
+ public function hasSyntax()
+ {
+ return $this->has_syntax;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/FileDescriptorSet.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/FileDescriptorSet.php
new file mode 100644
index 0000000000..0bcc80511e
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/FileDescriptorSet.php
@@ -0,0 +1,59 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * <pre>
+ * The protocol compiler can output a FileDescriptorSet containing the .proto
+ * files it parses.
+ * </pre>
+ *
+ * Protobuf type <code>google.protobuf.FileDescriptorSet</code>
+ */
+class FileDescriptorSet extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code>
+ */
+ private $file;
+ private $has_file = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code>
+ */
+ public function getFile()
+ {
+ return $this->file;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code>
+ */
+ public function setFile(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\FileDescriptorProto::class);
+ $this->file = $arr;
+ $this->has_file = true;
+ }
+
+ public function hasFile()
+ {
+ return $this->has_file;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/FileOptions.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/FileOptions.php
new file mode 100644
index 0000000000..22653a4f7e
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/FileOptions.php
@@ -0,0 +1,784 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * Protobuf type <code>google.protobuf.FileOptions</code>
+ */
+class FileOptions extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <pre>
+ * Sets the Java package where classes generated from this .proto will be
+ * placed. By default, the proto package is used, but this is often
+ * inappropriate because proto packages do not normally start with backwards
+ * domain names.
+ * </pre>
+ *
+ * <code>optional string java_package = 1;</code>
+ */
+ private $java_package = '';
+ private $has_java_package = false;
+ /**
+ * <pre>
+ * If set, all the classes from the .proto file are wrapped in a single
+ * outer class with the given name. This applies to both Proto1
+ * (equivalent to the old "--one_java_file" option) and Proto2 (where
+ * a .proto always translates to a single class, but you may want to
+ * explicitly choose the class name).
+ * </pre>
+ *
+ * <code>optional string java_outer_classname = 8;</code>
+ */
+ private $java_outer_classname = '';
+ private $has_java_outer_classname = false;
+ /**
+ * <pre>
+ * If set true, then the Java code generator will generate a separate .java
+ * file for each top-level message, enum, and service defined in the .proto
+ * file. Thus, these types will *not* be nested inside the outer class
+ * named by java_outer_classname. However, the outer class will still be
+ * generated to contain the file's getDescriptor() method as well as any
+ * top-level extensions defined in the file.
+ * </pre>
+ *
+ * <code>optional bool java_multiple_files = 10 [default = false];</code>
+ */
+ private $java_multiple_files = false;
+ private $has_java_multiple_files = false;
+ /**
+ * <pre>
+ * This option does nothing.
+ * </pre>
+ *
+ * <code>optional bool java_generate_equals_and_hash = 20 [deprecated = true];</code>
+ */
+ private $java_generate_equals_and_hash = false;
+ private $has_java_generate_equals_and_hash = false;
+ /**
+ * <pre>
+ * 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
+ * byte sequence to a string field.
+ * Message reflection will do the same.
+ * However, an extension field still accepts non-UTF-8 byte sequences.
+ * This option has no effect on when used with the lite runtime.
+ * </pre>
+ *
+ * <code>optional bool java_string_check_utf8 = 27 [default = false];</code>
+ */
+ private $java_string_check_utf8 = false;
+ private $has_java_string_check_utf8 = false;
+ /**
+ * <code>optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED];</code>
+ */
+ private $optimize_for = 0;
+ private $has_optimize_for = false;
+ /**
+ * <pre>
+ * Sets the Go package where structs generated from this .proto will be
+ * placed. If omitted, the Go package will be derived from the following:
+ * - The basename of the package import path, if provided.
+ * - Otherwise, the package statement in the .proto file, if present.
+ * - Otherwise, the basename of the .proto file, without extension.
+ * </pre>
+ *
+ * <code>optional string go_package = 11;</code>
+ */
+ private $go_package = '';
+ private $has_go_package = false;
+ /**
+ * <pre>
+ * Should generic services be generated in each language? "Generic" services
+ * are not specific to any particular RPC system. They are generated by the
+ * main code generators in each language (without additional plugins).
+ * Generic services were the only kind of service generation supported by
+ * early versions of google.protobuf.
+ * Generic services are now considered deprecated in favor of using plugins
+ * that generate code specific to your particular RPC system. Therefore,
+ * these default to false. Old code which depends on generic services should
+ * explicitly set them to true.
+ * </pre>
+ *
+ * <code>optional bool cc_generic_services = 16 [default = false];</code>
+ */
+ private $cc_generic_services = false;
+ private $has_cc_generic_services = false;
+ /**
+ * <code>optional bool java_generic_services = 17 [default = false];</code>
+ */
+ private $java_generic_services = false;
+ private $has_java_generic_services = false;
+ /**
+ * <code>optional bool py_generic_services = 18 [default = false];</code>
+ */
+ private $py_generic_services = false;
+ private $has_py_generic_services = false;
+ /**
+ * <pre>
+ * Is this file deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for everything in the file, or it will be completely ignored; in the very
+ * least, this is a formalization for deprecating files.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 23 [default = false];</code>
+ */
+ private $deprecated = false;
+ private $has_deprecated = false;
+ /**
+ * <pre>
+ * Enables the use of arenas for the proto messages in this file. This applies
+ * only to generated classes for C++.
+ * </pre>
+ *
+ * <code>optional bool cc_enable_arenas = 31 [default = false];</code>
+ */
+ private $cc_enable_arenas = false;
+ private $has_cc_enable_arenas = false;
+ /**
+ * <pre>
+ * Sets the objective c class prefix which is prepended to all objective c
+ * generated classes from this .proto. There is no default.
+ * </pre>
+ *
+ * <code>optional string objc_class_prefix = 36;</code>
+ */
+ private $objc_class_prefix = '';
+ private $has_objc_class_prefix = false;
+ /**
+ * <pre>
+ * Namespace for generated classes; defaults to the package.
+ * </pre>
+ *
+ * <code>optional string csharp_namespace = 37;</code>
+ */
+ private $csharp_namespace = '';
+ private $has_csharp_namespace = false;
+ /**
+ * <pre>
+ * By default Swift generators will take the proto package and CamelCase it
+ * replacing '.' with underscore and use that to prefix the types/symbols
+ * defined. When this options is provided, they will use this value instead
+ * to prefix the types/symbols defined.
+ * </pre>
+ *
+ * <code>optional string swift_prefix = 39;</code>
+ */
+ private $swift_prefix = '';
+ private $has_swift_prefix = false;
+ /**
+ * <pre>
+ * Sets the php class prefix which is prepended to all php generated classes
+ * from this .proto. Default is empty.
+ * </pre>
+ *
+ * <code>optional string php_class_prefix = 40;</code>
+ */
+ private $php_class_prefix = '';
+ private $has_php_class_prefix = false;
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ private $uninterpreted_option;
+ private $has_uninterpreted_option = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <pre>
+ * Sets the Java package where classes generated from this .proto will be
+ * placed. By default, the proto package is used, but this is often
+ * inappropriate because proto packages do not normally start with backwards
+ * domain names.
+ * </pre>
+ *
+ * <code>optional string java_package = 1;</code>
+ */
+ public function getJavaPackage()
+ {
+ return $this->java_package;
+ }
+
+ /**
+ * <pre>
+ * Sets the Java package where classes generated from this .proto will be
+ * placed. By default, the proto package is used, but this is often
+ * inappropriate because proto packages do not normally start with backwards
+ * domain names.
+ * </pre>
+ *
+ * <code>optional string java_package = 1;</code>
+ */
+ public function setJavaPackage($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->java_package = $var;
+ $this->has_java_package = true;
+ }
+
+ public function hasJavaPackage()
+ {
+ return $this->has_java_package;
+ }
+
+ /**
+ * <pre>
+ * If set, all the classes from the .proto file are wrapped in a single
+ * outer class with the given name. This applies to both Proto1
+ * (equivalent to the old "--one_java_file" option) and Proto2 (where
+ * a .proto always translates to a single class, but you may want to
+ * explicitly choose the class name).
+ * </pre>
+ *
+ * <code>optional string java_outer_classname = 8;</code>
+ */
+ public function getJavaOuterClassname()
+ {
+ return $this->java_outer_classname;
+ }
+
+ /**
+ * <pre>
+ * If set, all the classes from the .proto file are wrapped in a single
+ * outer class with the given name. This applies to both Proto1
+ * (equivalent to the old "--one_java_file" option) and Proto2 (where
+ * a .proto always translates to a single class, but you may want to
+ * explicitly choose the class name).
+ * </pre>
+ *
+ * <code>optional string java_outer_classname = 8;</code>
+ */
+ public function setJavaOuterClassname($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->java_outer_classname = $var;
+ $this->has_java_outer_classname = true;
+ }
+
+ public function hasJavaOuterClassname()
+ {
+ return $this->has_java_outer_classname;
+ }
+
+ /**
+ * <pre>
+ * If set true, then the Java code generator will generate a separate .java
+ * file for each top-level message, enum, and service defined in the .proto
+ * file. Thus, these types will *not* be nested inside the outer class
+ * named by java_outer_classname. However, the outer class will still be
+ * generated to contain the file's getDescriptor() method as well as any
+ * top-level extensions defined in the file.
+ * </pre>
+ *
+ * <code>optional bool java_multiple_files = 10 [default = false];</code>
+ */
+ public function getJavaMultipleFiles()
+ {
+ return $this->java_multiple_files;
+ }
+
+ /**
+ * <pre>
+ * If set true, then the Java code generator will generate a separate .java
+ * file for each top-level message, enum, and service defined in the .proto
+ * file. Thus, these types will *not* be nested inside the outer class
+ * named by java_outer_classname. However, the outer class will still be
+ * generated to contain the file's getDescriptor() method as well as any
+ * top-level extensions defined in the file.
+ * </pre>
+ *
+ * <code>optional bool java_multiple_files = 10 [default = false];</code>
+ */
+ public function setJavaMultipleFiles($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->java_multiple_files = $var;
+ $this->has_java_multiple_files = true;
+ }
+
+ public function hasJavaMultipleFiles()
+ {
+ return $this->has_java_multiple_files;
+ }
+
+ /**
+ * <pre>
+ * This option does nothing.
+ * </pre>
+ *
+ * <code>optional bool java_generate_equals_and_hash = 20 [deprecated = true];</code>
+ */
+ public function getJavaGenerateEqualsAndHash()
+ {
+ return $this->java_generate_equals_and_hash;
+ }
+
+ /**
+ * <pre>
+ * This option does nothing.
+ * </pre>
+ *
+ * <code>optional bool java_generate_equals_and_hash = 20 [deprecated = true];</code>
+ */
+ public function setJavaGenerateEqualsAndHash($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->java_generate_equals_and_hash = $var;
+ $this->has_java_generate_equals_and_hash = true;
+ }
+
+ public function hasJavaGenerateEqualsAndHash()
+ {
+ return $this->has_java_generate_equals_and_hash;
+ }
+
+ /**
+ * <pre>
+ * 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
+ * byte sequence to a string field.
+ * Message reflection will do the same.
+ * However, an extension field still accepts non-UTF-8 byte sequences.
+ * This option has no effect on when used with the lite runtime.
+ * </pre>
+ *
+ * <code>optional bool java_string_check_utf8 = 27 [default = false];</code>
+ */
+ public function getJavaStringCheckUtf8()
+ {
+ return $this->java_string_check_utf8;
+ }
+
+ /**
+ * <pre>
+ * 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
+ * byte sequence to a string field.
+ * Message reflection will do the same.
+ * However, an extension field still accepts non-UTF-8 byte sequences.
+ * This option has no effect on when used with the lite runtime.
+ * </pre>
+ *
+ * <code>optional bool java_string_check_utf8 = 27 [default = false];</code>
+ */
+ public function setJavaStringCheckUtf8($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->java_string_check_utf8 = $var;
+ $this->has_java_string_check_utf8 = true;
+ }
+
+ public function hasJavaStringCheckUtf8()
+ {
+ return $this->has_java_string_check_utf8;
+ }
+
+ /**
+ * <code>optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED];</code>
+ */
+ public function getOptimizeFor()
+ {
+ return $this->optimize_for;
+ }
+
+ /**
+ * <code>optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED];</code>
+ */
+ public function setOptimizeFor($var)
+ {
+ GPBUtil::checkEnum($var, \Google\Protobuf\Internal\FileOptions_OptimizeMode::class);
+ $this->optimize_for = $var;
+ $this->has_optimize_for = true;
+ }
+
+ public function hasOptimizeFor()
+ {
+ return $this->has_optimize_for;
+ }
+
+ /**
+ * <pre>
+ * Sets the Go package where structs generated from this .proto will be
+ * placed. If omitted, the Go package will be derived from the following:
+ * - The basename of the package import path, if provided.
+ * - Otherwise, the package statement in the .proto file, if present.
+ * - Otherwise, the basename of the .proto file, without extension.
+ * </pre>
+ *
+ * <code>optional string go_package = 11;</code>
+ */
+ public function getGoPackage()
+ {
+ return $this->go_package;
+ }
+
+ /**
+ * <pre>
+ * Sets the Go package where structs generated from this .proto will be
+ * placed. If omitted, the Go package will be derived from the following:
+ * - The basename of the package import path, if provided.
+ * - Otherwise, the package statement in the .proto file, if present.
+ * - Otherwise, the basename of the .proto file, without extension.
+ * </pre>
+ *
+ * <code>optional string go_package = 11;</code>
+ */
+ public function setGoPackage($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->go_package = $var;
+ $this->has_go_package = true;
+ }
+
+ public function hasGoPackage()
+ {
+ return $this->has_go_package;
+ }
+
+ /**
+ * <pre>
+ * Should generic services be generated in each language? "Generic" services
+ * are not specific to any particular RPC system. They are generated by the
+ * main code generators in each language (without additional plugins).
+ * Generic services were the only kind of service generation supported by
+ * early versions of google.protobuf.
+ * Generic services are now considered deprecated in favor of using plugins
+ * that generate code specific to your particular RPC system. Therefore,
+ * these default to false. Old code which depends on generic services should
+ * explicitly set them to true.
+ * </pre>
+ *
+ * <code>optional bool cc_generic_services = 16 [default = false];</code>
+ */
+ public function getCcGenericServices()
+ {
+ return $this->cc_generic_services;
+ }
+
+ /**
+ * <pre>
+ * Should generic services be generated in each language? "Generic" services
+ * are not specific to any particular RPC system. They are generated by the
+ * main code generators in each language (without additional plugins).
+ * Generic services were the only kind of service generation supported by
+ * early versions of google.protobuf.
+ * Generic services are now considered deprecated in favor of using plugins
+ * that generate code specific to your particular RPC system. Therefore,
+ * these default to false. Old code which depends on generic services should
+ * explicitly set them to true.
+ * </pre>
+ *
+ * <code>optional bool cc_generic_services = 16 [default = false];</code>
+ */
+ public function setCcGenericServices($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->cc_generic_services = $var;
+ $this->has_cc_generic_services = true;
+ }
+
+ public function hasCcGenericServices()
+ {
+ return $this->has_cc_generic_services;
+ }
+
+ /**
+ * <code>optional bool java_generic_services = 17 [default = false];</code>
+ */
+ public function getJavaGenericServices()
+ {
+ return $this->java_generic_services;
+ }
+
+ /**
+ * <code>optional bool java_generic_services = 17 [default = false];</code>
+ */
+ public function setJavaGenericServices($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->java_generic_services = $var;
+ $this->has_java_generic_services = true;
+ }
+
+ public function hasJavaGenericServices()
+ {
+ return $this->has_java_generic_services;
+ }
+
+ /**
+ * <code>optional bool py_generic_services = 18 [default = false];</code>
+ */
+ public function getPyGenericServices()
+ {
+ return $this->py_generic_services;
+ }
+
+ /**
+ * <code>optional bool py_generic_services = 18 [default = false];</code>
+ */
+ public function setPyGenericServices($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->py_generic_services = $var;
+ $this->has_py_generic_services = true;
+ }
+
+ public function hasPyGenericServices()
+ {
+ return $this->has_py_generic_services;
+ }
+
+ /**
+ * <pre>
+ * Is this file deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for everything in the file, or it will be completely ignored; in the very
+ * least, this is a formalization for deprecating files.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 23 [default = false];</code>
+ */
+ public function getDeprecated()
+ {
+ return $this->deprecated;
+ }
+
+ /**
+ * <pre>
+ * Is this file deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for everything in the file, or it will be completely ignored; in the very
+ * least, this is a formalization for deprecating files.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 23 [default = false];</code>
+ */
+ public function setDeprecated($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->deprecated = $var;
+ $this->has_deprecated = true;
+ }
+
+ public function hasDeprecated()
+ {
+ return $this->has_deprecated;
+ }
+
+ /**
+ * <pre>
+ * Enables the use of arenas for the proto messages in this file. This applies
+ * only to generated classes for C++.
+ * </pre>
+ *
+ * <code>optional bool cc_enable_arenas = 31 [default = false];</code>
+ */
+ public function getCcEnableArenas()
+ {
+ return $this->cc_enable_arenas;
+ }
+
+ /**
+ * <pre>
+ * Enables the use of arenas for the proto messages in this file. This applies
+ * only to generated classes for C++.
+ * </pre>
+ *
+ * <code>optional bool cc_enable_arenas = 31 [default = false];</code>
+ */
+ public function setCcEnableArenas($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->cc_enable_arenas = $var;
+ $this->has_cc_enable_arenas = true;
+ }
+
+ public function hasCcEnableArenas()
+ {
+ return $this->has_cc_enable_arenas;
+ }
+
+ /**
+ * <pre>
+ * Sets the objective c class prefix which is prepended to all objective c
+ * generated classes from this .proto. There is no default.
+ * </pre>
+ *
+ * <code>optional string objc_class_prefix = 36;</code>
+ */
+ public function getObjcClassPrefix()
+ {
+ return $this->objc_class_prefix;
+ }
+
+ /**
+ * <pre>
+ * Sets the objective c class prefix which is prepended to all objective c
+ * generated classes from this .proto. There is no default.
+ * </pre>
+ *
+ * <code>optional string objc_class_prefix = 36;</code>
+ */
+ public function setObjcClassPrefix($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->objc_class_prefix = $var;
+ $this->has_objc_class_prefix = true;
+ }
+
+ public function hasObjcClassPrefix()
+ {
+ return $this->has_objc_class_prefix;
+ }
+
+ /**
+ * <pre>
+ * Namespace for generated classes; defaults to the package.
+ * </pre>
+ *
+ * <code>optional string csharp_namespace = 37;</code>
+ */
+ public function getCsharpNamespace()
+ {
+ return $this->csharp_namespace;
+ }
+
+ /**
+ * <pre>
+ * Namespace for generated classes; defaults to the package.
+ * </pre>
+ *
+ * <code>optional string csharp_namespace = 37;</code>
+ */
+ public function setCsharpNamespace($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->csharp_namespace = $var;
+ $this->has_csharp_namespace = true;
+ }
+
+ public function hasCsharpNamespace()
+ {
+ return $this->has_csharp_namespace;
+ }
+
+ /**
+ * <pre>
+ * By default Swift generators will take the proto package and CamelCase it
+ * replacing '.' with underscore and use that to prefix the types/symbols
+ * defined. When this options is provided, they will use this value instead
+ * to prefix the types/symbols defined.
+ * </pre>
+ *
+ * <code>optional string swift_prefix = 39;</code>
+ */
+ public function getSwiftPrefix()
+ {
+ return $this->swift_prefix;
+ }
+
+ /**
+ * <pre>
+ * By default Swift generators will take the proto package and CamelCase it
+ * replacing '.' with underscore and use that to prefix the types/symbols
+ * defined. When this options is provided, they will use this value instead
+ * to prefix the types/symbols defined.
+ * </pre>
+ *
+ * <code>optional string swift_prefix = 39;</code>
+ */
+ public function setSwiftPrefix($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->swift_prefix = $var;
+ $this->has_swift_prefix = true;
+ }
+
+ public function hasSwiftPrefix()
+ {
+ return $this->has_swift_prefix;
+ }
+
+ /**
+ * <pre>
+ * Sets the php class prefix which is prepended to all php generated classes
+ * from this .proto. Default is empty.
+ * </pre>
+ *
+ * <code>optional string php_class_prefix = 40;</code>
+ */
+ public function getPhpClassPrefix()
+ {
+ return $this->php_class_prefix;
+ }
+
+ /**
+ * <pre>
+ * Sets the php class prefix which is prepended to all php generated classes
+ * from this .proto. Default is empty.
+ * </pre>
+ *
+ * <code>optional string php_class_prefix = 40;</code>
+ */
+ public function setPhpClassPrefix($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->php_class_prefix = $var;
+ $this->has_php_class_prefix = true;
+ }
+
+ public function hasPhpClassPrefix()
+ {
+ return $this->has_php_class_prefix;
+ }
+
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ public function getUninterpretedOption()
+ {
+ return $this->uninterpreted_option;
+ }
+
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ public function setUninterpretedOption(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
+ $this->uninterpreted_option = $arr;
+ $this->has_uninterpreted_option = true;
+ }
+
+ public function hasUninterpretedOption()
+ {
+ return $this->has_uninterpreted_option;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/FileOptions_OptimizeMode.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/FileOptions_OptimizeMode.php
new file mode 100644
index 0000000000..b550e7f17e
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/FileOptions_OptimizeMode.php
@@ -0,0 +1,41 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+/**
+ * <pre>
+ * Generated classes can be optimized for speed or code size.
+ * </pre>
+ *
+ * Protobuf enum <code>google.protobuf.FileOptions.OptimizeMode</code>
+ */
+class FileOptions_OptimizeMode
+{
+ /**
+ * <pre>
+ * Generate complete code for parsing, serialization,
+ * </pre>
+ *
+ * <code>SPEED = 1;</code>
+ */
+ const SPEED = 1;
+ /**
+ * <pre>
+ * etc.
+ * </pre>
+ *
+ * <code>CODE_SIZE = 2;</code>
+ */
+ const CODE_SIZE = 2;
+ /**
+ * <pre>
+ * Generate code using MessageLite and the lite runtime.
+ * </pre>
+ *
+ * <code>LITE_RUNTIME = 3;</code>
+ */
+ const LITE_RUNTIME = 3;
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/GPBLabel.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/GPBLabel.php
new file mode 100644
index 0000000000..0fb238415b
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/GPBLabel.php
@@ -0,0 +1,40 @@
+<?php
+
+// 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.
+
+namespace Google\Protobuf\Internal;
+
+class GPBLabel
+{
+ const OPTIONAL = 1;
+ const REQUIRED = 2;
+ const REPEATED = 3;
+}
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/GPBType.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/GPBType.php
new file mode 100644
index 0000000000..fa849ceb06
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/GPBType.php
@@ -0,0 +1,55 @@
+<?php
+
+// 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.
+
+namespace Google\Protobuf\Internal;
+
+class GPBType
+{
+ const DOUBLE = 1;
+ const FLOAT = 2;
+ const INT64 = 3;
+ const UINT64 = 4;
+ const INT32 = 5;
+ const FIXED64 = 6;
+ const FIXED32 = 7;
+ const BOOL = 8;
+ const STRING = 9;
+ const GROUP = 10;
+ const MESSAGE = 11;
+ const BYTES = 12;
+ const UINT32 = 13;
+ const ENUM = 14;
+ const SFIXED32 = 15;
+ const SFIXED64 = 16;
+ const SINT32 = 17;
+ const SINT64 = 18;
+}
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/GPBUtil.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/GPBUtil.php
new file mode 100644
index 0000000000..0e66ae6f67
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/GPBUtil.php
@@ -0,0 +1,245 @@
+<?php
+
+// 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.
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\MapField;
+
+class GPBUtil
+{
+ public function divideInt64ToInt32($value, &$high, &$low, $trim = false)
+ {
+ $isNeg = (bccomp($value, 0) < 0);
+ if ($isNeg) {
+ $value = bcsub(0, $value);
+ }
+
+ $high = (int) bcdiv(bcadd($value, 1), 4294967296);
+ $low = bcmod($value, 4294967296);
+ if (bccomp($low, 2147483647) > 0) {
+ $low = (int) bcsub($low, 4294967296);
+ } else {
+ $low = (int) $low;
+ }
+
+ if ($isNeg) {
+ $high = ~$high;
+ $low = ~$low;
+ $low++;
+ if (!$low) {
+ $high++;
+ }
+ }
+
+ if ($trim) {
+ $high = 0;
+ }
+ }
+
+
+ public static function checkString(&$var, $check_utf8)
+ {
+ if (is_array($var) || is_object($var)) {
+ trigger_error("Expect string.", E_USER_ERROR);
+ return;
+ }
+ if (!is_string($var)) {
+ $var = strval($var);
+ }
+ if ($check_utf8 && !preg_match('//u', $var)) {
+ trigger_error("Expect utf-8 encoding.", E_USER_ERROR);
+ return;
+ }
+ }
+
+ public static function checkEnum(&$var)
+ {
+ static::checkInt32($var);
+ }
+
+ public static function checkInt32(&$var)
+ {
+ if (is_numeric($var)) {
+ $var = intval($var);
+ } else {
+ trigger_error("Expect integer.", E_USER_ERROR);
+ }
+ }
+
+ public static function checkUint32(&$var)
+ {
+ if (is_numeric($var)) {
+ if (PHP_INT_SIZE === 8) {
+ $var = intval($var);
+ $var |= ((-(($var >> 31) & 0x1)) & ~0xFFFFFFFF);
+ } else {
+ if (bccomp($var, 0x7FFFFFFF) > 0) {
+ $var = bcsub($var, "4294967296");
+ }
+ $var = (int) $var;
+ }
+ } else {
+ trigger_error("Expect integer.", E_USER_ERROR);
+ }
+ }
+
+ public static function checkInt64(&$var)
+ {
+ if (is_numeric($var)) {
+ if (PHP_INT_SIZE == 8) {
+ $var = intval($var);
+ } else {
+ $var = bcdiv($var, 1, 0);
+ }
+ } else {
+ trigger_error("Expect integer.", E_USER_ERROR);
+ }
+ }
+
+ public static function checkUint64(&$var)
+ {
+ if (is_numeric($var)) {
+ if (PHP_INT_SIZE == 8) {
+ $var = intval($var);
+ } else {
+ $var = bcdiv($var, 1, 0);
+ }
+ } else {
+ trigger_error("Expect integer.", E_USER_ERROR);
+ }
+ }
+
+ public static function checkFloat(&$var)
+ {
+ if (is_float($var) || is_numeric($var)) {
+ $var = floatval($var);
+ } else {
+ trigger_error("Expect float.", E_USER_ERROR);
+ }
+ }
+
+ public static function checkDouble(&$var)
+ {
+ if (is_float($var) || is_numeric($var)) {
+ $var = floatval($var);
+ } else {
+ trigger_error("Expect float.", E_USER_ERROR);
+ }
+ }
+
+ public static function checkBool(&$var)
+ {
+ if (is_array($var) || is_object($var)) {
+ trigger_error("Expect boolean.", E_USER_ERROR);
+ return;
+ }
+ $var = boolval($var);
+ }
+
+ public static function checkMessage(&$var, $klass)
+ {
+ if (!$var instanceof $klass && !is_null($var)) {
+ trigger_error("Expect message.", E_USER_ERROR);
+ }
+ }
+
+ public static function checkRepeatedField(&$var, $type, $klass = null)
+ {
+ if (!$var instanceof RepeatedField && !is_array($var)) {
+ trigger_error("Expect array.", E_USER_ERROR);
+ }
+ if (is_array($var)) {
+ $tmp = new RepeatedField($type, $klass);
+ foreach ($var as $value) {
+ $tmp[] = $value;
+ }
+ return $tmp;
+ } else {
+ if ($var->getType() != $type) {
+ trigger_error(
+ "Expect repeated field of different type.",
+ E_USER_ERROR);
+ }
+ if ($var->getType() === GPBType::MESSAGE &&
+ $var->getClass() !== $klass) {
+ trigger_error(
+ "Expect repeated field of different message.",
+ E_USER_ERROR);
+ }
+ return $var;
+ }
+ }
+
+ public static function checkMapField(&$var, $key_type, $value_type, $klass = null)
+ {
+ if (!$var instanceof MapField && !is_array($var)) {
+ trigger_error("Expect dict.", E_USER_ERROR);
+ }
+ if (is_array($var)) {
+ $tmp = new MapField($key_type, $value_type, $klass);
+ foreach ($var as $key => $value) {
+ $tmp[$key] = $value;
+ }
+ return $tmp;
+ } else {
+ if ($var->getKeyType() != $key_type) {
+ trigger_error(
+ "Expect map field of key type.",
+ E_USER_ERROR);
+ }
+ if ($var->getValueType() != $value_type) {
+ trigger_error(
+ "Expect map field of value type.",
+ E_USER_ERROR);
+ }
+ if ($var->getValueType() === GPBType::MESSAGE &&
+ $var->getValueClass() !== $klass) {
+ trigger_error(
+ "Expect map field of different value message.",
+ E_USER_ERROR);
+ }
+ return $var;
+ }
+ }
+
+ public static function Int64($value)
+ {
+ return new Int64($value);
+ }
+
+ public static function Uint64($value)
+ {
+ return new Uint64($value);
+ }
+}
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/GPBWire.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/GPBWire.php
new file mode 100644
index 0000000000..67eb1bee65
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/GPBWire.php
@@ -0,0 +1,617 @@
+<?php
+
+// 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.
+
+namespace Google\Protobuf\Internal;
+
+class GPBWire
+{
+
+ const TAG_TYPE_BITS = 3;
+
+ const WIRETYPE_VARINT = 0;
+ const WIRETYPE_FIXED64 = 1;
+ const WIRETYPE_LENGTH_DELIMITED = 2;
+ const WIRETYPE_START_GROUP = 3;
+ const WIRETYPE_END_GROUP = 4;
+ const WIRETYPE_FIXED32 = 5;
+
+ const UNKNOWN = 0;
+ const NORMAL_FORMAT = 1;
+ const PACKED_FORMAT = 2;
+
+ public static function getTagFieldNumber($tag)
+ {
+ return ($tag >> self::TAG_TYPE_BITS) &
+ (1 << ((PHP_INT_SIZE * 8) - self::TAG_TYPE_BITS)) - 1;
+ }
+
+ public static function getTagWireType($tag)
+ {
+ return $tag & 0x7;
+ }
+
+ public static function getWireType($type)
+ {
+ switch ($type) {
+ case GPBType::FLOAT:
+ case GPBType::FIXED32:
+ case GPBType::SFIXED32:
+ return self::WIRETYPE_FIXED32;
+ case GPBType::DOUBLE:
+ case GPBType::FIXED64:
+ case GPBType::SFIXED64:
+ return self::WIRETYPE_FIXED64;
+ case GPBType::UINT32:
+ case GPBType::UINT64:
+ case GPBType::INT32:
+ case GPBType::INT64:
+ case GPBType::SINT32:
+ case GPBType::SINT64:
+ case GPBType::ENUM:
+ case GPBType::BOOL:
+ return self::WIRETYPE_VARINT;
+ case GPBType::STRING:
+ case GPBType::BYTES:
+ case GPBType::MESSAGE:
+ return self::WIRETYPE_LENGTH_DELIMITED;
+ case GPBType::GROUP:
+ user_error("Unsupported type.");
+ return 0;
+ default:
+ user_error("Unsupported type.");
+ return 0;
+ }
+ }
+
+ // ZigZag Transform: Encodes signed integers so that they can be effectively
+ // used with varint encoding.
+ //
+ // varint operates on unsigned integers, encoding smaller numbers into fewer
+ // bytes. If you try to use it on a signed integer, it will treat this
+ // number as a very large unsigned integer, which means that even small
+ // signed numbers like -1 will take the maximum number of bytes (10) to
+ // encode. zigZagEncode() maps signed integers to unsigned in such a way
+ // that those with a small absolute value will have smaller encoded values,
+ // making them appropriate for encoding using varint.
+ //
+ // int32 -> uint32
+ // -------------------------
+ // 0 -> 0
+ // -1 -> 1
+ // 1 -> 2
+ // -2 -> 3
+ // ... -> ...
+ // 2147483647 -> 4294967294
+ // -2147483648 -> 4294967295
+ //
+ // >> encode >>
+ // << decode <<
+ public static function zigZagEncode32($int32)
+ {
+ // Fill high 32 bits.
+ if (PHP_INT_SIZE === 8) {
+ $int32 |= ((($int32 << 32) >> 31) & (0xFFFFFFFF << 32));
+ }
+
+ $uint32 = ($int32 << 1) ^ ($int32 >> 31);
+
+ // Fill high 32 bits.
+ if (PHP_INT_SIZE === 8) {
+ $uint32 |= ((($uint32 << 32) >> 31) & (0xFFFFFFFF << 32));
+ }
+
+ return $uint32;
+ }
+
+ public static function zigZagDecode32($uint32)
+ {
+ // Fill high 32 bits.
+ if (PHP_INT_SIZE === 8) {
+ $uint32 |= ($uint32 & 0xFFFFFFFF);
+ }
+
+ $int32 = (($uint32 >> 1) & 0x7FFFFFFF) ^ (-($uint32 & 1));
+
+ return $int32;
+ }
+
+ public static function zigZagEncode64($int64)
+ {
+ if (PHP_INT_SIZE == 4) {
+ if (bccomp($int64, 0) >= 0) {
+ return bcmul($int64, 2);
+ } else {
+ return bcsub(bcmul(bcsub(0, $int64), 2), 1);
+ }
+ } else {
+ return ($int64 << 1) ^ ($int64 >> 63);
+ }
+ }
+
+ public static function zigZagDecode64($uint64)
+ {
+ if (PHP_INT_SIZE == 4) {
+ if (bcmod($uint64, 2) == 0) {
+ return bcdiv($uint64, 2, 0);
+ } else {
+ return bcsub(0, bcdiv(bcadd($uint64, 1), 2, 0));
+ }
+ } else {
+ return (($uint64 >> 1) & 0x7FFFFFFFFFFFFFFF) ^ (-($uint64 & 1));
+ }
+ }
+
+ public static function readInt32(&$input, &$value)
+ {
+ return $input->readVarint32($value);
+ }
+
+ public static function readInt64(&$input, &$value)
+ {
+ return $input->readVarint64($value);
+ }
+
+ public static function readUint32(&$input, &$value)
+ {
+ return self::readInt32($input, $value);
+ }
+
+ public static function readUint64(&$input, &$value)
+ {
+ return self::readInt64($input, $value);
+ }
+
+ public static function readSint32(&$input, &$value)
+ {
+ if (!$input->readVarint32($value)) {
+ return false;
+ }
+ $value = GPBWire::zigZagDecode32($value);
+ return true;
+ }
+
+ public static function readSint64(&$input, &$value)
+ {
+ if (!$input->readVarint64($value)) {
+ return false;
+ }
+ $value = GPBWire::zigZagDecode64($value);
+ return true;
+ }
+
+ public static function readFixed32(&$input, &$value)
+ {
+ return $input->readLittleEndian32($value);
+ }
+
+ public static function readFixed64(&$input, &$value)
+ {
+ return $input->readLittleEndian64($value);
+ }
+
+ public static function readSfixed32(&$input, &$value)
+ {
+ if (!self::readFixed32($input, $value)) {
+ return false;
+ }
+ if (PHP_INT_SIZE === 8) {
+ $value |= (-($value >> 31) << 32);
+ }
+ return true;
+ }
+
+ public static function readSfixed64(&$input, &$value)
+ {
+ return $input->readLittleEndian64($value);
+ }
+
+ public static function readFloat(&$input, &$value)
+ {
+ $data = null;
+ if (!$input->readRaw(4, $data)) {
+ return false;
+ }
+ $value = unpack('f', $data)[1];
+ return true;
+ }
+
+ public static function readDouble(&$input, &$value)
+ {
+ $data = null;
+ if (!$input->readRaw(8, $data)) {
+ return false;
+ }
+ $value = unpack('d', $data)[1];
+ return true;
+ }
+
+ public static function readBool(&$input, &$value)
+ {
+ if (!$input->readVarint64($value)) {
+ return false;
+ }
+ if ($value == 0) {
+ $value = false;
+ } else {
+ $value = true;
+ }
+ return true;
+ }
+
+ public static function readString(&$input, &$value)
+ {
+ $length = 0;
+ return $input->readVarintSizeAsInt($length) && $input->readRaw($length, $value);
+ }
+
+ public static function readMessage(&$input, &$message)
+ {
+ $length = 0;
+ if (!$input->readVarintSizeAsInt($length)) {
+ return false;
+ }
+ $old_limit = 0;
+ $recursion_limit = 0;
+ $input->incrementRecursionDepthAndPushLimit(
+ $length,
+ $old_limit,
+ $recursion_limit);
+ if ($recursion_limit < 0 || !$message->parseFromStream($input)) {
+ return false;
+ }
+ return $input->decrementRecursionDepthAndPopLimit($old_limit);
+ }
+
+ public static function writeTag(&$output, $tag)
+ {
+ return $output->writeTag($tag);
+ }
+
+ public static function writeInt32(&$output, $value)
+ {
+ return $output->writeVarint32($value);
+ }
+
+ public static function writeInt64(&$output, $value)
+ {
+ return $output->writeVarint64($value);
+ }
+
+ public static function writeUint32(&$output, $value)
+ {
+ return $output->writeVarint32($value);
+ }
+
+ public static function writeUint64(&$output, $value)
+ {
+ return $output->writeVarint64($value);
+ }
+
+ public static function writeSint32(&$output, $value)
+ {
+ $value = GPBWire::zigZagEncode32($value);
+ return $output->writeVarint64($value);
+ }
+
+ public static function writeSint64(&$output, $value)
+ {
+ $value = GPBWire::zigZagEncode64($value);
+ return $output->writeVarint64($value);
+ }
+
+ public static function writeFixed32(&$output, $value)
+ {
+ return $output->writeLittleEndian32($value);
+ }
+
+ public static function writeFixed64(&$output, $value)
+ {
+ return $output->writeLittleEndian64($value);
+ }
+
+ public static function writeSfixed32(&$output, $value)
+ {
+ return $output->writeLittleEndian32($value);
+ }
+
+ public static function writeSfixed64(&$output, $value)
+ {
+ return $output->writeLittleEndian64($value);
+ }
+
+ public static function writeBool(&$output, $value)
+ {
+ if ($value) {
+ return $output->writeVarint32(1);
+ } else {
+ return $output->writeVarint32(0);
+ }
+ }
+
+ public static function writeFloat(&$output, $value)
+ {
+ $data = pack("f", $value);
+ return $output->writeRaw($data, 4);
+ }
+
+ public static function writeDouble(&$output, $value)
+ {
+ $data = pack("d", $value);
+ return $output->writeRaw($data, 8);
+ }
+
+ public static function writeString(&$output, $value)
+ {
+ return self::writeBytes($output, $value);
+ }
+
+ public static function writeBytes(&$output, $value)
+ {
+ $size = strlen($value);
+ if (!$output->writeVarint32($size)) {
+ return false;
+ }
+ return $output->writeRaw($value, $size);
+ }
+
+ public static function writeMessage(&$output, $value)
+ {
+ $size = $value->byteSize();
+ if (!$output->writeVarint32($size)) {
+ return false;
+ }
+ return $value->serializeToStream($output);
+ }
+
+ public static function makeTag($number, $type)
+ {
+ return ($number << 3) | self::getWireType($type);
+ }
+
+ public static function tagSize($field)
+ {
+ $tag = self::makeTag($field->getNumber(), $field->getType());
+ return self::varint32Size($tag);
+ }
+
+ public static function varint32Size($value, $sign_extended = false)
+ {
+ if ($value < 0) {
+ if ($sign_extended) {
+ return 10;
+ } else {
+ return 5;
+ }
+ }
+ if ($value < (1 << 7)) {
+ return 1;
+ }
+ if ($value < (1 << 14)) {
+ return 2;
+ }
+ if ($value < (1 << 21)) {
+ return 3;
+ }
+ if ($value < (1 << 28)) {
+ return 4;
+ }
+ return 5;
+ }
+
+ public static function sint32Size($value)
+ {
+ $value = self::zigZagEncode32($value);
+ return self::varint32Size($value);
+ }
+
+ public static function sint64Size($value)
+ {
+ $value = self::zigZagEncode64($value);
+ return self::varint64Size($value);
+ }
+
+ public static function varint64Size($value)
+ {
+ if (PHP_INT_SIZE == 4) {
+ if (bccomp($value, 0) < 0) {
+ return 10;
+ }
+ if (bccomp($value, 1 << 7) < 0) {
+ return 1;
+ }
+ if (bccomp($value, 1 << 14) < 0) {
+ return 2;
+ }
+ if (bccomp($value, 1 << 21) < 0) {
+ return 3;
+ }
+ if (bccomp($value, 1 << 28) < 0) {
+ return 4;
+ }
+ if (bccomp($value, '34359738368') < 0) {
+ return 5;
+ }
+ if (bccomp($value, '4398046511104') < 0) {
+ return 6;
+ }
+ if (bccomp($value, '562949953421312') < 0) {
+ return 7;
+ }
+ if (bccomp($value, '72057594037927936') < 0) {
+ return 8;
+ }
+ return 9;
+ } else {
+ if ($value < 0) {
+ return 10;
+ }
+ if ($value < (1 << 7)) {
+ return 1;
+ }
+ if ($value < (1 << 14)) {
+ return 2;
+ }
+ if ($value < (1 << 21)) {
+ return 3;
+ }
+ if ($value < (1 << 28)) {
+ return 4;
+ }
+ if ($value < (1 << 35)) {
+ return 5;
+ }
+ if ($value < (1 << 42)) {
+ return 6;
+ }
+ if ($value < (1 << 49)) {
+ return 7;
+ }
+ if ($value < (1 << 56)) {
+ return 8;
+ }
+ return 9;
+ }
+ }
+
+ public static function serializeFieldToStream(
+ $value,
+ $field,
+ $need_tag,
+ &$output)
+ {
+ if ($need_tag) {
+ if (!GPBWire::writeTag(
+ $output,
+ self::makeTag(
+ $field->getNumber(),
+ $field->getType()))) {
+ return false;
+ }
+ }
+ switch ($field->getType()) {
+ case GPBType::DOUBLE:
+ if (!GPBWire::writeDouble($output, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::FLOAT:
+ if (!GPBWire::writeFloat($output, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::INT64:
+ if (!GPBWire::writeInt64($output, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::UINT64:
+ if (!GPBWire::writeUint64($output, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::INT32:
+ if (!GPBWire::writeInt32($output, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::FIXED32:
+ if (!GPBWire::writeFixed32($output, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::FIXED64:
+ if (!GPBWire::writeFixed64($output, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::BOOL:
+ if (!GPBWire::writeBool($output, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::STRING:
+ if (!GPBWire::writeString($output, $value)) {
+ return false;
+ }
+ break;
+ // case GPBType::GROUP:
+ // echo "GROUP\xA";
+ // trigger_error("Not implemented.", E_ERROR);
+ // break;
+ case GPBType::MESSAGE:
+ if (!GPBWire::writeMessage($output, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::BYTES:
+ if (!GPBWire::writeBytes($output, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::UINT32:
+ if (!GPBWire::writeUint32($output, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::ENUM:
+ if (!GPBWire::writeInt32($output, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::SFIXED32:
+ if (!GPBWire::writeSfixed32($output, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::SFIXED64:
+ if (!GPBWire::writeSfixed64($output, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::SINT32:
+ if (!GPBWire::writeSint32($output, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::SINT64:
+ if (!GPBWire::writeSint64($output, $value)) {
+ return false;
+ }
+ break;
+ default:
+ user_error("Unsupported type.");
+ return false;
+ }
+
+ return true;
+ }
+}
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php
new file mode 100644
index 0000000000..450854f172
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php
@@ -0,0 +1,75 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * <pre>
+ * Describes the relationship between generated code and its original source
+ * file. A GeneratedCodeInfo message is associated with only one generated
+ * source file, but may contain references to different source .proto files.
+ * </pre>
+ *
+ * Protobuf type <code>google.protobuf.GeneratedCodeInfo</code>
+ */
+class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <pre>
+ * An Annotation connects some span of text in generated code to an element
+ * of its generating .proto file.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;</code>
+ */
+ private $annotation;
+ private $has_annotation = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <pre>
+ * An Annotation connects some span of text in generated code to an element
+ * of its generating .proto file.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;</code>
+ */
+ public function getAnnotation()
+ {
+ return $this->annotation;
+ }
+
+ /**
+ * <pre>
+ * An Annotation connects some span of text in generated code to an element
+ * of its generating .proto file.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;</code>
+ */
+ public function setAnnotation(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\GeneratedCodeInfo_Annotation::class);
+ $this->annotation = $arr;
+ $this->has_annotation = true;
+ }
+
+ public function hasAnnotation()
+ {
+ return $this->has_annotation;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php
new file mode 100644
index 0000000000..ed22cc387d
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php
@@ -0,0 +1,198 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * Protobuf type <code>google.protobuf.GeneratedCodeInfo.Annotation</code>
+ */
+class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <pre>
+ * Identifies the element in the original source .proto file. This field
+ * is formatted the same as SourceCodeInfo.Location.path.
+ * </pre>
+ *
+ * <code>repeated int32 path = 1 [packed = true];</code>
+ */
+ private $path;
+ private $has_path = false;
+ /**
+ * <pre>
+ * Identifies the filesystem path to the original source .proto.
+ * </pre>
+ *
+ * <code>optional string source_file = 2;</code>
+ */
+ private $source_file = '';
+ private $has_source_file = false;
+ /**
+ * <pre>
+ * Identifies the starting offset in bytes in the generated code
+ * that relates to the identified object.
+ * </pre>
+ *
+ * <code>optional int32 begin = 3;</code>
+ */
+ private $begin = 0;
+ private $has_begin = false;
+ /**
+ * <pre>
+ * Identifies the ending offset in bytes in the generated code that
+ * relates to the identified offset. The end offset should be one past
+ * the last relevant byte (so the length of the text = end - begin).
+ * </pre>
+ *
+ * <code>optional int32 end = 4;</code>
+ */
+ private $end = 0;
+ private $has_end = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <pre>
+ * Identifies the element in the original source .proto file. This field
+ * is formatted the same as SourceCodeInfo.Location.path.
+ * </pre>
+ *
+ * <code>repeated int32 path = 1 [packed = true];</code>
+ */
+ public function getPath()
+ {
+ return $this->path;
+ }
+
+ /**
+ * <pre>
+ * Identifies the element in the original source .proto file. This field
+ * is formatted the same as SourceCodeInfo.Location.path.
+ * </pre>
+ *
+ * <code>repeated int32 path = 1 [packed = true];</code>
+ */
+ public function setPath(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
+ $this->path = $arr;
+ $this->has_path = true;
+ }
+
+ public function hasPath()
+ {
+ return $this->has_path;
+ }
+
+ /**
+ * <pre>
+ * Identifies the filesystem path to the original source .proto.
+ * </pre>
+ *
+ * <code>optional string source_file = 2;</code>
+ */
+ public function getSourceFile()
+ {
+ return $this->source_file;
+ }
+
+ /**
+ * <pre>
+ * Identifies the filesystem path to the original source .proto.
+ * </pre>
+ *
+ * <code>optional string source_file = 2;</code>
+ */
+ public function setSourceFile($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->source_file = $var;
+ $this->has_source_file = true;
+ }
+
+ public function hasSourceFile()
+ {
+ return $this->has_source_file;
+ }
+
+ /**
+ * <pre>
+ * Identifies the starting offset in bytes in the generated code
+ * that relates to the identified object.
+ * </pre>
+ *
+ * <code>optional int32 begin = 3;</code>
+ */
+ public function getBegin()
+ {
+ return $this->begin;
+ }
+
+ /**
+ * <pre>
+ * Identifies the starting offset in bytes in the generated code
+ * that relates to the identified object.
+ * </pre>
+ *
+ * <code>optional int32 begin = 3;</code>
+ */
+ public function setBegin($var)
+ {
+ GPBUtil::checkInt32($var);
+ $this->begin = $var;
+ $this->has_begin = true;
+ }
+
+ public function hasBegin()
+ {
+ return $this->has_begin;
+ }
+
+ /**
+ * <pre>
+ * Identifies the ending offset in bytes in the generated code that
+ * relates to the identified offset. The end offset should be one past
+ * the last relevant byte (so the length of the text = end - begin).
+ * </pre>
+ *
+ * <code>optional int32 end = 4;</code>
+ */
+ public function getEnd()
+ {
+ return $this->end;
+ }
+
+ /**
+ * <pre>
+ * Identifies the ending offset in bytes in the generated code that
+ * relates to the identified offset. The end offset should be one past
+ * the last relevant byte (so the length of the text = end - begin).
+ * </pre>
+ *
+ * <code>optional int32 end = 4;</code>
+ */
+ public function setEnd($var)
+ {
+ GPBUtil::checkInt32($var);
+ $this->end = $var;
+ $this->has_end = true;
+ }
+
+ public function hasEnd()
+ {
+ return $this->has_end;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/InputStream.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/InputStream.php
new file mode 100644
index 0000000000..de5ca97815
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/InputStream.php
@@ -0,0 +1,394 @@
+<?php
+
+// 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.
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\Uint64;
+
+function combineInt32ToInt64($high, $low)
+{
+ $isNeg = $high < 0;
+ if ($isNeg) {
+ $high = ~$high;
+ $low = ~$low;
+ $low++;
+ if (!$low) {
+ $high++;
+ }
+ }
+ $result = bcadd(bcmul($high, 4294967296), $low);
+ if ($low < 0) {
+ $result = bcadd($result, 4294967296);
+ }
+ if ($isNeg) {
+ $result = bcsub(0, $result);
+ }
+ return $result;
+}
+
+class InputStream
+{
+
+ private $buffer;
+ private $buffer_size_after_limit;
+ private $buffer_end;
+ private $current;
+ private $current_limit;
+ private $legitimate_message_end;
+ private $recursion_budget;
+ private $recursion_limit;
+ private $total_bytes_limit;
+ private $total_bytes_read;
+
+ const MAX_VARINT_BYTES = 10;
+ const DEFAULT_RECURSION_LIMIT = 100;
+ const DEFAULT_TOTAL_BYTES_LIMIT = 33554432; // 32 << 20, 32MB
+
+ public function __construct($buffer)
+ {
+ $start = 0;
+ $end = strlen($buffer);
+ $this->buffer = $buffer;
+ $this->buffer_size_after_limit = 0;
+ $this->buffer_end = $end;
+ $this->current = $start;
+ $this->current_limit = $end;
+ $this->legitimate_message_end = false;
+ $this->recursion_budget = self::DEFAULT_RECURSION_LIMIT;
+ $this->recursion_limit = self::DEFAULT_RECURSION_LIMIT;
+ $this->total_bytes_limit = self::DEFAULT_TOTAL_BYTES_LIMIT;
+ $this->total_bytes_read = $end - $start;
+ }
+
+ private function advance($amount)
+ {
+ $this->current += $amount;
+ }
+
+ private function bufferSize()
+ {
+ return $this->buffer_end - $this->current;
+ }
+
+ private function current()
+ {
+ return $this->total_bytes_read -
+ ($this->buffer_end - $this->current +
+ $this->buffer_size_after_limit);
+ }
+
+ private function recomputeBufferLimits()
+ {
+ $this->buffer_end += $this->buffer_size_after_limit;
+ $closest_limit = min($this->current_limit, $this->total_bytes_limit);
+ if ($closest_limit < $this->total_bytes_read) {
+ // The limit position is in the current buffer. We must adjust the
+ // buffer size accordingly.
+ $this->buffer_size_after_limit = $this->total_bytes_read -
+ $closest_limit;
+ $this->buffer_end -= $this->buffer_size_after_limit;
+ } else {
+ $this->buffer_size_after_limit = 0;
+ }
+ }
+
+ private function consumedEntireMessage()
+ {
+ return $this->legitimate_message_end;
+ }
+
+ /**
+ * Read uint32 into $var. Advance buffer with consumed bytes. If the
+ * contained varint is larger than 32 bits, discard the high order bits.
+ * @param $var.
+ */
+ public function readVarint32(&$var)
+ {
+ if (!$this->readVarint64($var)) {
+ return false;
+ }
+
+ if (PHP_INT_SIZE == 4) {
+ $var = bcmod($var, 4294967296);
+ } else {
+ $var &= 0xFFFFFFFF;
+ }
+
+ // Convert large uint32 to int32.
+ if ($var > 0x7FFFFFFF) {
+ if (PHP_INT_SIZE === 8) {
+ $var = $var | (0xFFFFFFFF << 32);
+ } else {
+ $var = bcsub($var, 4294967296);
+ }
+ }
+
+ $var = intval($var);
+ return true;
+ }
+
+ /**
+ * Read Uint64 into $var. Advance buffer with consumed bytes.
+ * @param $var.
+ */
+ public function readVarint64(&$var)
+ {
+ $count = 0;
+
+ if (PHP_INT_SIZE == 4) {
+ $high = 0;
+ $low = 0;
+ $b = 0;
+
+ do {
+ if ($this->current === $this->buffer_end) {
+ return false;
+ }
+ if ($count === self::MAX_VARINT_BYTES) {
+ return false;
+ }
+ $b = ord($this->buffer[$this->current]);
+ $bits = 7 * $count;
+ if ($bits >= 32) {
+ $high |= (($b & 0x7F) << ($bits - 32));
+ } else if ($bits > 25){
+ // $bits is 28 in this case.
+ $low |= (($b & 0x7F) << 28);
+ $high = ($b & 0x7F) >> 4;
+ } else {
+ $low |= (($b & 0x7F) << $bits);
+ }
+
+ $this->advance(1);
+ $count += 1;
+ } while ($b & 0x80);
+
+ $var = combineInt32ToInt64($high, $low);
+ } else {
+ $result = 0;
+ $shift = 0;
+
+ do {
+ if ($this->current === $this->buffer_end) {
+ return false;
+ }
+ if ($count === self::MAX_VARINT_BYTES) {
+ return false;
+ }
+
+ $byte = ord($this->buffer[$this->current]);
+ $result |= ($byte & 0x7f) << $shift;
+ $shift += 7;
+ $this->advance(1);
+ $count += 1;
+ } while ($byte > 0x7f);
+
+ $var = $result;
+ }
+
+ return true;
+ }
+
+ /**
+ * Read int into $var. If the result is larger than the largest integer, $var
+ * will be -1. Advance buffer with consumed bytes.
+ * @param $var.
+ */
+ public function readVarintSizeAsInt(&$var)
+ {
+ if (!$this->readVarint64($var)) {
+ return false;
+ }
+ $var = (int)$var;
+ return true;
+ }
+
+ /**
+ * Read 32-bit unsiged integer to $var. If the buffer has less than 4 bytes,
+ * return false. Advance buffer with consumed bytes.
+ * @param $var.
+ */
+ public function readLittleEndian32(&$var)
+ {
+ $data = null;
+ if (!$this->readRaw(4, $data)) {
+ return false;
+ }
+ $var = unpack('V', $data);
+ $var = $var[1];
+ return true;
+ }
+
+ /**
+ * Read 64-bit unsiged integer to $var. If the buffer has less than 8 bytes,
+ * return false. Advance buffer with consumed bytes.
+ * @param $var.
+ */
+ public function readLittleEndian64(&$var)
+ {
+ $data = null;
+ if (!$this->readRaw(4, $data)) {
+ return false;
+ }
+ $low = unpack('V', $data)[1];
+ if (!$this->readRaw(4, $data)) {
+ return false;
+ }
+ $high = unpack('V', $data)[1];
+ if (PHP_INT_SIZE == 4) {
+ $var = combineInt32ToInt64($high, $low);
+ } else {
+ $var = ($high << 32) | $low;
+ }
+ return true;
+ }
+
+ /**
+ * Read tag into $var. Advance buffer with consumed bytes.
+ * @param $var.
+ */
+ public function readTag()
+ {
+ if ($this->current === $this->buffer_end) {
+ // Make sure that it failed due to EOF, not because we hit
+ // total_bytes_limit, which, unlike normal limits, is not a valid
+ // place to end a message.
+ $current_position = $this->total_bytes_read -
+ $this->buffer_size_after_limit;
+ if ($current_position >= $this->total_bytes_limit) {
+ // Hit total_bytes_limit_. But if we also hit the normal limit,
+ // we're still OK.
+ $this->legitimate_message_end =
+ ($this->current_limit === $this->total_bytes_limit);
+ } else {
+ $this->legitimate_message_end = true;
+ }
+ return 0;
+ }
+
+ $result = 0;
+ // The larget tag is 2^29 - 1, which can be represented by int32.
+ $success = $this->readVarint32($result);
+ if ($success) {
+ return $result;
+ } else {
+ return 0;
+ }
+ }
+
+ public function readRaw($size, &$buffer)
+ {
+ $current_buffer_size = 0;
+ if ($this->bufferSize() < $size) {
+ return false;
+ }
+
+ $buffer = substr($this->buffer, $this->current, $size);
+ $this->advance($size);
+
+ return true;
+ }
+
+ /* Places a limit on the number of bytes that the stream may read, starting
+ * from the current position. Once the stream hits this limit, it will act
+ * like the end of the input has been reached until popLimit() is called.
+ *
+ * As the names imply, the stream conceptually has a stack of limits. The
+ * shortest limit on the stack is always enforced, even if it is not the top
+ * limit.
+ *
+ * The value returned by pushLimit() is opaque to the caller, and must be
+ * passed unchanged to the corresponding call to popLimit().
+ *
+ * @param integer $byte_limit
+ */
+ public function pushLimit($byte_limit)
+ {
+ // Current position relative to the beginning of the stream.
+ $current_position = $this->current();
+ $old_limit = $this->current_limit;
+
+ // security: byte_limit is possibly evil, so check for negative values
+ // and overflow.
+ if ($byte_limit >= 0 && $byte_limit <= PHP_INT_MAX - $current_position) {
+ $this->current_limit = $current_position + $byte_limit;
+ } else {
+ // Negative or overflow.
+ $this->current_limit = PHP_INT_MAX;
+ }
+
+ // We need to enforce all limits, not just the new one, so if the previous
+ // limit was before the new requested limit, we continue to enforce the
+ // previous limit.
+ $this->current_limit = min($this->current_limit, $old_limit);
+
+ $this->recomputeBufferLimits();
+ return $old_limit;
+ }
+
+ /* The limit passed in is actually the *old* limit, which we returned from
+ * PushLimit().
+ *
+ * @param integer $byte_limit
+ */
+ public function popLimit($byte_limit)
+ {
+ $this->current_limit = $byte_limit;
+ $this->recomputeBufferLimits();
+ // We may no longer be at a legitimate message end. ReadTag() needs to
+ // be called again to find out.
+ $this->legitimate_message_end = false;
+ }
+
+ public function incrementRecursionDepthAndPushLimit(
+ $byte_limit, &$old_limit, &$recursion_budget)
+ {
+ $old_limit = $this->pushLimit($byte_limit);
+ $recursion_limit = --$this->recursion_limit;
+ }
+
+ public function decrementRecursionDepthAndPopLimit($byte_limit)
+ {
+ $result = $this->consumedEntireMessage();
+ $this->popLimit($byte_limit);
+ ++$this->recursion_budget;
+ return $result;
+ }
+
+ public function bytesUntilLimit()
+ {
+ if ($this->current_limit === PHP_INT_MAX) {
+ return -1;
+ }
+ return $this->current_limit - $this->current;
+ }
+}
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/MapEntry.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/MapEntry.php
new file mode 100644
index 0000000000..926645e1db
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/MapEntry.php
@@ -0,0 +1,57 @@
+<?php
+
+// 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.
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\Message;
+
+class MapEntry extends Message
+{
+ public $key;
+ public $value;
+
+ public function setKey(&$key) {
+ $this->key = $key;
+ }
+
+ public function getKey() {
+ return $this->key;
+ }
+
+ public function setValue(&$value) {
+ $this->value = $value;
+ }
+
+ public function getValue() {
+ return $this->value;
+ }
+}
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/MapField.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/MapField.php
new file mode 100644
index 0000000000..68c10c0824
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/MapField.php
@@ -0,0 +1,345 @@
+<?php
+
+// 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.
+
+/**
+ * MapField and MapFieldIter are used by generated protocol message classes to
+ * manipulate map fields.
+ */
+
+namespace Google\Protobuf\Internal;
+
+/**
+ * MapFieldIter is used to iterate MapField. It is also need for the foreach
+ * syntax.
+ */
+class MapFieldIter implements \Iterator
+{
+
+ /**
+ * @ignore
+ */
+ private $container;
+
+ /**
+ * Create iterator instance for MapField.
+ *
+ * @param MapField The MapField instance for which this iterator is
+ * created.
+ * @ignore
+ */
+ public function __construct($container)
+ {
+ $this->container = $container;
+ }
+
+ /**
+ * Reset the status of the iterator
+ *
+ * @return void
+ */
+ public function rewind()
+ {
+ return reset($this->container);
+ }
+
+ /**
+ * Return the element at the current position.
+ *
+ * @return object The element at the current position.
+ */
+ public function current()
+ {
+ return current($this->container);
+ }
+
+ /**
+ * Return the current key.
+ *
+ * @return object The current key.
+ */
+ public function key()
+ {
+ return key($this->container);
+ }
+
+ /**
+ * Move to the next position.
+ *
+ * @return void
+ */
+ public function next()
+ {
+ return next($this->container);
+ }
+
+ /**
+ * Check whether there are more elements to iterate.
+ *
+ * @return bool True if there are more elements to iterate.
+ */
+ public function valid()
+ {
+ return key($this->container) !== null;
+ }
+}
+
+/**
+ * @ignore
+ */
+function checkKey($key_type, &$key)
+{
+ switch ($key_type) {
+ case GPBType::INT32:
+ GPBUtil::checkInt32($key);
+ break;
+ case GPBType::UINT32:
+ GPBUtil::checkUint32($key);
+ break;
+ case GPBType::INT64:
+ GPBUtil::checkInt64($key);
+ break;
+ case GPBType::UINT64:
+ GPBUtil::checkUint64($key);
+ break;
+ case GPBType::FIXED64:
+ GPBUtil::checkUint64($key);
+ break;
+ case GPBType::FIXED32:
+ GPBUtil::checkUint32($key);
+ break;
+ case GPBType::SFIXED64:
+ GPBUtil::checkInt64($key);
+ break;
+ case GPBType::SFIXED32:
+ GPBUtil::checkInt32($key);
+ break;
+ case GPBType::SINT64:
+ GPBUtil::checkInt64($key);
+ break;
+ case GPBType::SINT32:
+ GPBUtil::checkInt32($key);
+ break;
+ case GPBType::BOOL:
+ GPBUtil::checkBool($key);
+ break;
+ case GPBType::STRING:
+ GPBUtil::checkString($key, true);
+ break;
+ default:
+ var_dump($key_type);
+ trigger_error(
+ "Given type cannot be map key.",
+ E_USER_ERROR);
+ break;
+ }
+}
+
+/**
+ * MapField is used by generated protocol message classes to manipulate map
+ * fields. It can be used like native PHP array.
+ */
+class MapField implements \ArrayAccess, \IteratorAggregate, \Countable
+{
+ /**
+ * @ignore
+ */
+ private $container;
+ /**
+ * @ignore
+ */
+ private $key_type;
+ /**
+ * @ignore
+ */
+ private $value_type;
+ /**
+ * @ignore
+ */
+ private $value_klass;
+
+ /**
+ * Constructs an instance of MapField.
+ *
+ * @param long $key_type Type of the stored key element.
+ * @param long $value_type Type of the stored value element.
+ * @param string $klass Message/Enum class name of value instance
+ * (message/enum fields only).
+ * @ignore
+ */
+ public function __construct($key_type, $value_type, $klass = null)
+ {
+ $this->container = [];
+ $this->key_type = $key_type;
+ $this->value_type = $value_type;
+ $this->klass = $klass;
+ }
+
+ /**
+ * @ignore
+ */
+ public function getKeyType()
+ {
+ return $this->key_type;
+ }
+
+ /**
+ * @ignore
+ */
+ public function getValueType()
+ {
+ return $this->value_type;
+ }
+
+ /**
+ * @ignore
+ */
+ public function getValueClass()
+ {
+ return $this->klass;
+ }
+
+ /**
+ * Return the element at the given key.
+ *
+ * This will also be called for: $ele = $arr[$key]
+ *
+ * @param object $key The key of the element to be fetched.
+ * @return object The stored element at given key.
+ * @throws ErrorException Invalid type for index.
+ * @throws ErrorException Non-existing index.
+ */
+ public function offsetGet($key)
+ {
+ return $this->container[$key];
+ }
+
+ /**
+ * Assign the element at the given key.
+ *
+ * This will also be called for: $arr[$key] = $value
+ *
+ * @param object $key The key of the element to be fetched.
+ * @param object $value The element to be assigned.
+ * @return void
+ * @throws ErrorException Invalid type for key.
+ * @throws ErrorException Invalid type for value.
+ * @throws ErrorException Non-existing key.
+ */
+ public function offsetSet($key, $value)
+ {
+ checkKey($this->key_type, $key);
+
+ switch ($this->value_type) {
+ case GPBType::INT32:
+ GPBUtil::checkInt32($value);
+ break;
+ case GPBType::UINT32:
+ GPBUtil::checkUint32($value);
+ break;
+ case GPBType::INT64:
+ GPBUtil::checkInt64($value);
+ break;
+ case GPBType::UINT64:
+ GPBUtil::checkUint64($value);
+ break;
+ case GPBType::FLOAT:
+ GPBUtil::checkFloat($value);
+ break;
+ case GPBType::DOUBLE:
+ GPBUtil::checkDouble($value);
+ break;
+ case GPBType::BOOL:
+ GPBUtil::checkBool($value);
+ break;
+ case GPBType::STRING:
+ GPBUtil::checkString($value, true);
+ break;
+ case GPBType::MESSAGE:
+ GPBUtil::checkMessage($value, $this->klass);
+ break;
+ default:
+ break;
+ }
+
+ $this->container[$key] = $value;
+ }
+
+ /**
+ * Remove the element at the given key.
+ *
+ * This will also be called for: unset($arr)
+ *
+ * @param object $key The key of the element to be removed.
+ * @return void
+ * @throws ErrorException Invalid type for key.
+ */
+ public function offsetUnset($key)
+ {
+ checkKey($this->key_type, $key);
+ unset($this->container[$key]);
+ }
+
+ /**
+ * Check the existence of the element at the given key.
+ *
+ * This will also be called for: isset($arr)
+ *
+ * @param object $key The key of the element to be removed.
+ * @return bool True if the element at the given key exists.
+ * @throws ErrorException Invalid type for key.
+ */
+ public function offsetExists($key)
+ {
+ checkKey($this->key_type, $key);
+ return isset($this->container[$key]);
+ }
+
+ /**
+ * @ignore
+ */
+ public function getIterator()
+ {
+ return new MapFieldIter($this->container);
+ }
+
+ /**
+ * Return the number of stored elements.
+ *
+ * This will also be called for: count($arr)
+ *
+ * @return integer The number of stored elements.
+ */
+ public function count()
+ {
+ return count($this->container);
+ }
+}
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/Message.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/Message.php
new file mode 100644
index 0000000000..887c86ca6e
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/Message.php
@@ -0,0 +1,881 @@
+<?php
+
+// 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.
+
+/**
+ * Defines Message, the parent class extended by all protocol message classes.
+ */
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\InputStream;
+use Google\Protobuf\Internal\OutputStream;
+use Google\Protobuf\Internal\DescriptorPool;
+use Google\Protobuf\Internal\GPBLabel;
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\MapEntry;
+use Google\Protobuf\Internal\RepeatedField;
+
+/**
+ * Parent class of all proto messages. Users should not instantiate this class
+ * or extend this class or its child classes by their own. See the comment of
+ * specific functions for more details.
+ */
+class Message
+{
+
+ /**
+ * @ignore
+ */
+ private $desc;
+
+ /**
+ * @ignore
+ */
+ public function __construct($desc = NULL)
+ {
+ // MapEntry message is shared by all types of map fields, whose
+ // descriptors are different from each other. Thus, we cannot find a
+ // specific descriptor from the descriptor pool.
+ if (get_class($this) === 'Google\Protobuf\Internal\MapEntry') {
+ $this->desc = $desc;
+ return;
+ }
+ $pool = DescriptorPool::getGeneratedPool();
+ $this->desc = $pool->getDescriptorByClassName(get_class($this));
+ foreach ($this->desc->getField() as $field) {
+ $setter = $field->getSetter();
+ if ($field->isMap()) {
+ $message_type = $field->getMessageType();
+ $key_field = $message_type->getFieldByNumber(1);
+ $value_field = $message_type->getFieldByNumber(2);
+ switch ($value_field->getType()) {
+ case GPBType::MESSAGE:
+ case GPBType::GROUP:
+ $map_field = new MapField(
+ $key_field->getType(),
+ $value_field->getType(),
+ $value_field->getMessageType()->getClass());
+ $this->$setter($map_field);
+ break;
+ case GPBType::ENUM:
+ $map_field = new MapField(
+ $key_field->getType(),
+ $value_field->getType(),
+ $value_field->getEnumType()->getClass());
+ $this->$setter($map_field);
+ break;
+ default:
+ $map_field = new MapField(
+ $key_field->getType(),
+ $value_field->getType());
+ $this->$setter($map_field);
+ break;
+ }
+ } else if ($field->getLabel() === GPBLabel::REPEATED) {
+ switch ($field->getType()) {
+ case GPBType::MESSAGE:
+ case GPBType::GROUP:
+ $repeated_field = new RepeatedField(
+ $field->getType(),
+ $field->getMessageType()->getClass());
+ $this->$setter($repeated_field);
+ break;
+ case GPBType::ENUM:
+ $repeated_field = new RepeatedField(
+ $field->getType(),
+ $field->getEnumType()->getClass());
+ $this->$setter($repeated_field);
+ break;
+ default:
+ $repeated_field = new RepeatedField($field->getType());
+ $this->$setter($repeated_field);
+ break;
+ }
+ } else if ($field->getOneofIndex() !== -1) {
+ $oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()];
+ $oneof_name = $oneof->getName();
+ $this->$oneof_name = new OneofField($oneof);
+ } else if ($field->getLabel() === GPBLabel::OPTIONAL &&
+ PHP_INT_SIZE == 4) {
+ switch ($field->getType()) {
+ case GPBType::INT64:
+ case GPBType::UINT64:
+ case GPBType::FIXED64:
+ case GPBType::SFIXED64:
+ case GPBType::SINT64:
+ $this->$setter("0");
+ }
+ }
+ }
+ }
+
+ protected function readOneof($number)
+ {
+ $field = $this->desc->getFieldByNumber($number);
+ $oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()];
+ $oneof_name = $oneof->getName();
+ $oneof_field = $this->$oneof_name;
+ if ($number === $oneof_field->getNumber()) {
+ return $oneof_field->getValue();
+ } else {
+ return $this->defaultValue($field);
+ }
+ }
+
+ protected function writeOneof($number, $value)
+ {
+ $field = $this->desc->getFieldByNumber($number);
+ $oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()];
+ $oneof_name = $oneof->getName();
+ $oneof_field = $this->$oneof_name;
+ $oneof_field->setValue($value);
+ $oneof_field->setFieldName($field->getName());
+ $oneof_field->setNumber($number);
+ }
+
+ protected function whichOneof($oneof_name)
+ {
+ $oneof_field = $this->$oneof_name;
+ $number = $oneof_field->getNumber();
+ if ($number == 0) {
+ return "";
+ }
+ $field = $this->desc->getFieldByNumber($number);
+ return $field->getName();
+ }
+
+ /**
+ * @ignore
+ */
+ private function defaultValue($field)
+ {
+ $value = null;
+
+ switch ($field->getType()) {
+ case GPBType::DOUBLE:
+ case GPBType::FLOAT:
+ return 0.0;
+ case GPBType::UINT32:
+ case GPBType::INT32:
+ case GPBType::FIXED32:
+ case GPBType::SFIXED32:
+ case GPBType::SINT32:
+ case GPBType::ENUM:
+ return 0;
+ case GPBType::INT64:
+ case GPBType::UINT64:
+ case GPBType::FIXED64:
+ case GPBType::SFIXED64:
+ case GPBType::SINT64:
+ if (PHP_INT_SIZE === 4) {
+ return '0';
+ } else {
+ return 0;
+ }
+ case GPBType::BOOL:
+ return false;
+ case GPBType::STRING:
+ case GPBType::BYTES:
+ return "";
+ case GPBType::GROUP:
+ case GPBType::MESSAGE:
+ return null;
+ default:
+ user_error("Unsupported type.");
+ return false;
+ }
+ }
+
+ /**
+ * @ignore
+ */
+ private static function parseFieldFromStreamNoTag($input, $field, &$value)
+ {
+ switch ($field->getType()) {
+ case GPBType::DOUBLE:
+ if (!GPBWire::readDouble($input, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::FLOAT:
+ if (!GPBWire::readFloat($input, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::INT64:
+ if (!GPBWire::readInt64($input, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::UINT64:
+ if (!GPBWire::readUint64($input, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::INT32:
+ if (!GPBWire::readInt32($input, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::FIXED64:
+ if (!GPBWire::readFixed64($input, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::FIXED32:
+ if (!GPBWire::readFixed32($input, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::BOOL:
+ if (!GPBWire::readBool($input, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::STRING:
+ // TODO(teboring): Add utf-8 check.
+ if (!GPBWire::readString($input, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::GROUP:
+ echo "GROUP\xA";
+ trigger_error("Not implemented.", E_ERROR);
+ break;
+ case GPBType::MESSAGE:
+ if ($field->isMap()) {
+ $value = new MapEntry($field->getMessageType());
+ } else {
+ $klass = $field->getMessageType()->getClass();
+ $value = new $klass;
+ }
+ if (!GPBWire::readMessage($input, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::BYTES:
+ if (!GPBWire::readString($input, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::UINT32:
+ if (!GPBWire::readUint32($input, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::ENUM:
+ // TODO(teboring): Check unknown enum value.
+ if (!GPBWire::readInt32($input, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::SFIXED32:
+ if (!GPBWire::readSfixed32($input, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::SFIXED64:
+ if (!GPBWire::readSfixed64($input, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::SINT32:
+ if (!GPBWire::readSint32($input, $value)) {
+ return false;
+ }
+ break;
+ case GPBType::SINT64:
+ if (!GPBWire::readSint64($input, $value)) {
+ return false;
+ }
+ break;
+ default:
+ user_error("Unsupported type.");
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * @ignore
+ */
+ private function parseFieldFromStream($tag, $input, $field)
+ {
+ $value = null;
+ $field_type = $field->getType();
+
+ $value_format = GPBWire::UNKNOWN;
+ if (GPBWire::getTagWireType($tag) ===
+ GPBWire::getWireType($field_type)) {
+ $value_format = GPBWire::NORMAL_FORMAT;
+ } elseif ($field->isPackable() &&
+ GPBWire::getTagWireType($tag) ===
+ GPBWire::WIRETYPE_LENGTH_DELIMITED) {
+ $value_format = GPBWire::PACKED_FORMAT;
+ }
+
+ if ($value_format === GPBWire::NORMAL_FORMAT) {
+ if (!self::parseFieldFromStreamNoTag($input, $field, $value)) {
+ return false;
+ }
+ } elseif ($value_format === GPBWire::PACKED_FORMAT) {
+ $length = 0;
+ if (!GPBWire::readInt32($input, $length)) {
+ return false;
+ }
+ $limit = $input->pushLimit($length);
+ $getter = $field->getGetter();
+ while ($input->bytesUntilLimit() > 0) {
+ if (!self::parseFieldFromStreamNoTag($input, $field, $value)) {
+ return false;
+ }
+ $this->$getter()[] = $value;
+ }
+ $input->popLimit($limit);
+ return true;
+ } else {
+ return false;
+ }
+
+ if ($field->isMap()) {
+ $getter = $field->getGetter();
+ $this->$getter()[$value->getKey()] = $value->getValue();
+ } else if ($field->isRepeated()) {
+ $getter = $field->getGetter();
+ $this->$getter()[] = $value;
+ } else {
+ $setter = $field->getSetter();
+ $this->$setter($value);
+ }
+
+ return true;
+ }
+
+ /**
+ * Clear all containing fields.
+ * @return null.
+ */
+ public function clear()
+ {
+ foreach ($this->desc->getField() as $field) {
+ $setter = $field->getSetter();
+ if ($field->isMap()) {
+ $message_type = $field->getMessageType();
+ $key_field = $message_type->getFieldByNumber(1);
+ $value_field = $message_type->getFieldByNumber(2);
+ switch ($value_field->getType()) {
+ case GPBType::MESSAGE:
+ case GPBType::GROUP:
+ $map_field = new MapField(
+ $key_field->getType(),
+ $value_field->getType(),
+ $value_field->getMessageType()->getClass());
+ $this->$setter($map_field);
+ break;
+ case GPBType::ENUM:
+ $map_field = new MapField(
+ $key_field->getType(),
+ $value_field->getType(),
+ $value_field->getEnumType()->getClass());
+ $this->$setter($map_field);
+ break;
+ default:
+ $map_field = new MapField(
+ $key_field->getType(),
+ $value_field->getType());
+ $this->$setter($map_field);
+ break;
+ }
+ } else if ($field->getLabel() === GPBLabel::REPEATED) {
+ switch ($field->getType()) {
+ case GPBType::MESSAGE:
+ case GPBType::GROUP:
+ $repeated_field = new RepeatedField(
+ $field->getType(),
+ $field->getMessageType()->getClass());
+ $this->$setter($repeated_field);
+ break;
+ case GPBType::ENUM:
+ $repeated_field = new RepeatedField(
+ $field->getType(),
+ $field->getEnumType()->getClass());
+ $this->$setter($repeated_field);
+ break;
+ default:
+ $repeated_field = new RepeatedField($field->getType());
+ $this->$setter($repeated_field);
+ break;
+ }
+ } else if ($field->getOneofIndex() !== -1) {
+ $oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()];
+ $oneof_name = $oneof->getName();
+ $this->$oneof_name = new OneofField($oneof);
+ } else if ($field->getLabel() === GPBLabel::OPTIONAL) {
+ switch ($field->getType()) {
+ case GPBType::DOUBLE :
+ case GPBType::FLOAT :
+ $this->$setter(0.0);
+ break;
+ case GPBType::INT32 :
+ case GPBType::FIXED32 :
+ case GPBType::UINT32 :
+ case GPBType::SFIXED32 :
+ case GPBType::SINT32 :
+ case GPBType::ENUM :
+ $this->$setter(0);
+ break;
+ case GPBType::BOOL :
+ $this->$setter(false);
+ break;
+ case GPBType::STRING :
+ case GPBType::BYTES :
+ $this->$setter("");
+ break;
+ case GPBType::GROUP :
+ case GPBType::MESSAGE :
+ $null = null;
+ $this->$setter($null);
+ break;
+ }
+ if (PHP_INT_SIZE == 4) {
+ switch ($field->getType()) {
+ case GPBType::INT64:
+ case GPBType::UINT64:
+ case GPBType::FIXED64:
+ case GPBType::SFIXED64:
+ case GPBType::SINT64:
+ $this->$setter("0");
+ }
+ } else {
+ switch ($field->getType()) {
+ case GPBType::INT64:
+ case GPBType::UINT64:
+ case GPBType::FIXED64:
+ case GPBType::SFIXED64:
+ case GPBType::SINT64:
+ $this->$setter(0);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Merges the contents of the specified message into current message.
+ *
+ * This method merges the contents of the specified message into the
+ * current message. Singular fields that are set in the specified message
+ * overwrite the corresponding fields in the current message. Repeated
+ * fields are appended. Map fields key-value pairs are overritten.
+ * Singular/Oneof sub-messages are recursively merged. All overritten
+ * sub-messages are deep-copied.
+ *
+ * @param object $msg Protobuf message to be merged from.
+ * @return null.
+ */
+ public function mergeFrom($msg)
+ {
+ if (get_class($this) !== get_class($msg)) {
+ user_error("Cannot merge messages with different class.");
+ return;
+ }
+
+ foreach ($this->desc->getField() as $field) {
+ $setter = $field->getSetter();
+ $getter = $field->getGetter();
+ if ($field->isMap()) {
+ if (count($msg->$getter()) != 0) {
+ $value_field = $field->getMessageType()->getFieldByNumber(2);
+ foreach ($msg->$getter() as $key => $value) {
+ if ($value_field->getType() == GPBType::MESSAGE) {
+ $klass = $value_field->getMessageType()->getClass();
+ $copy = new $klass;
+ $copy->mergeFrom($value);
+ $this->$getter()[$key] = $copy;
+ } else {
+ $this->$getter()[$key] = $value;
+ }
+ }
+ }
+ } else if ($field->getLabel() === GPBLabel::REPEATED) {
+ if (count($msg->$getter()) != 0) {
+ foreach ($msg->$getter() as $tmp) {
+ if ($field->getType() == GPBType::MESSAGE) {
+ $klass = $field->getMessageType()->getClass();
+ $copy = new $klass;
+ $copy->mergeFrom($tmp);
+ $this->$getter()[] = $copy;
+ } else {
+ $this->$getter()[] = $tmp;
+ }
+ }
+ }
+ } else if ($field->getLabel() === GPBLabel::OPTIONAL) {
+ if($msg->$getter() !== $this->defaultValue($field)) {
+ $tmp = $msg->$getter();
+ if ($field->getType() == GPBType::MESSAGE) {
+ if (is_null($this->$getter())) {
+ $klass = $field->getMessageType()->getClass();
+ $new_msg = new $klass;
+ $this->$setter($new_msg);
+ }
+ $this->$getter()->mergeFrom($tmp);
+ } else {
+ $this->$setter($tmp);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Parses a protocol buffer contained in a string.
+ *
+ * This function takes a string in the (non-human-readable) binary wire
+ * format, matching the encoding output by serializeToString().
+ * See mergeFrom() for merging behavior, if the field is already set in the
+ * specified message.
+ *
+ * @param string $data Binary protobuf data.
+ * @return bool Return true on success.
+ */
+ public function mergeFromString($data)
+ {
+ $input = new InputStream($data);
+ $this->parseFromStream($input);
+ }
+
+ /**
+ * @ignore
+ */
+ public function parseFromStream($input)
+ {
+ while (true) {
+ $tag = $input->readTag();
+ // End of input. This is a valid place to end, so return true.
+ if ($tag === 0) {
+ return true;
+ }
+
+ $number = GPBWire::getTagFieldNumber($tag);
+ $field = $this->desc->getFieldByNumber($number);
+
+ // Check whether we retrieved a known field
+ if ($field === NULL) {
+ continue;
+ }
+
+ if (!$this->parseFieldFromStream($tag, $input, $field)) {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * @ignore
+ */
+ private function serializeSingularFieldToStream($field, &$output)
+ {
+ if (!$this->existField($field)) {
+ return true;
+ }
+ $getter = $field->getGetter();
+ $value = $this->$getter();
+ if (!GPBWire::serializeFieldToStream($value, $field, true, $output)) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * @ignore
+ */
+ private function serializeRepeatedFieldToStream($field, &$output)
+ {
+ $getter = $field->getGetter();
+ $values = $this->$getter();
+ $count = count($values);
+ if ($count === 0) {
+ return true;
+ }
+
+ $packed = $field->getPacked();
+ if ($packed) {
+ if (!GPBWire::writeTag(
+ $output,
+ GPBWire::makeTag($field->getNumber(), GPBType::STRING))) {
+ return false;
+ }
+ $size = 0;
+ foreach ($values as $value) {
+ $size += $this->fieldDataOnlyByteSize($field, $value);
+ }
+ if (!$output->writeVarint32($size)) {
+ return false;
+ }
+ }
+
+ foreach ($values as $value) {
+ if (!GPBWire::serializeFieldToStream(
+ $value,
+ $field,
+ !$packed,
+ $output)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * @ignore
+ */
+ private function serializeMapFieldToStream($field, $output)
+ {
+ $getter = $field->getGetter();
+ $values = $this->$getter();
+ $count = count($values);
+ if ($count === 0) {
+ return true;
+ }
+
+ foreach ($values as $key => $value) {
+ $map_entry = new MapEntry($field->getMessageType());
+ $map_entry->setKey($key);
+ $map_entry->setValue($value);
+ if (!GPBWire::serializeFieldToStream(
+ $map_entry,
+ $field,
+ true,
+ $output)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * @ignore
+ */
+ private function serializeFieldToStream(&$output, $field)
+ {
+ if ($field->isMap()) {
+ return $this->serializeMapFieldToStream($field, $output);
+ } elseif ($field->isRepeated()) {
+ return $this->serializeRepeatedFieldToStream($field, $output);
+ } else {
+ return $this->serializeSingularFieldToStream($field, $output);
+ }
+ }
+
+ /**
+ * @ignore
+ */
+ public function serializeToStream(&$output)
+ {
+ $fields = $this->desc->getField();
+ foreach ($fields as $field) {
+ if (!$this->serializeFieldToStream($output, $field)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Serialize the message to string.
+ * @return string Serialized binary protobuf data.
+ */
+ public function serializeToString()
+ {
+ $output = new OutputStream($this->byteSize());
+ $this->serializeToStream($output);
+ return $output->getData();
+ }
+
+ /**
+ * @ignore
+ */
+ private function existField($field)
+ {
+ $getter = $field->getGetter();
+ $value = $this->$getter();
+ return $value !== $this->defaultValue($field);
+ }
+
+ /**
+ * @ignore
+ */
+ private function repeatedFieldDataOnlyByteSize($field)
+ {
+ $size = 0;
+
+ $getter = $field->getGetter();
+ $values = $this->$getter();
+ $count = count($values);
+ if ($count !== 0) {
+ $size += $count * GPBWire::tagSize($field);
+ foreach ($values as $value) {
+ $size += $this->singularFieldDataOnlyByteSize($field);
+ }
+ }
+ }
+
+ /**
+ * @ignore
+ */
+ private function fieldDataOnlyByteSize($field, $value)
+ {
+ $size = 0;
+
+ switch ($field->getType()) {
+ case GPBType::BOOL:
+ $size += 1;
+ break;
+ case GPBType::FLOAT:
+ case GPBType::FIXED32:
+ case GPBType::SFIXED32:
+ $size += 4;
+ break;
+ case GPBType::DOUBLE:
+ case GPBType::FIXED64:
+ case GPBType::SFIXED64:
+ $size += 8;
+ break;
+ case GPBType::INT32:
+ case GPBType::ENUM:
+ $size += GPBWire::varint32Size($value, true);
+ break;
+ case GPBType::UINT32:
+ $size += GPBWire::varint32Size($value);
+ break;
+ case GPBType::UINT64:
+ case GPBType::INT64:
+ $size += GPBWire::varint64Size($value);
+ break;
+ case GPBType::SINT32:
+ $size += GPBWire::sint32Size($value);
+ break;
+ case GPBType::SINT64:
+ $size += GPBWire::sint64Size($value);
+ break;
+ case GPBType::STRING:
+ case GPBType::BYTES:
+ $size += strlen($value);
+ $size += GPBWire::varint32Size($size);
+ break;
+ case GPBType::MESSAGE:
+ $size += $value->byteSize();
+ $size += GPBWire::varint32Size($size);
+ break;
+ case GPBType::GROUP:
+ // TODO(teboring): Add support.
+ user_error("Unsupported type.");
+ break;
+ default:
+ user_error("Unsupported type.");
+ return 0;
+ }
+
+ return $size;
+ }
+
+ /**
+ * @ignore
+ */
+ private function fieldByteSize($field)
+ {
+ $size = 0;
+ if ($field->isMap()) {
+ $getter = $field->getGetter();
+ $values = $this->$getter();
+ $count = count($values);
+ if ($count !== 0) {
+ $size += $count * GPBWire::tagSize($field);
+ $message_type = $field->getMessageType();
+ $key_field = $message_type->getFieldByNumber(1);
+ $value_field = $message_type->getFieldByNumber(2);
+ foreach ($values as $key => $value) {
+ $data_size = 0;
+ $data_size += $this->fieldDataOnlyByteSize($key_field, $key);
+ $data_size += $this->fieldDataOnlyByteSize(
+ $value_field,
+ $value);
+ $data_size += GPBWire::tagSize($key_field);
+ $data_size += GPBWire::tagSize($value_field);
+ $size += GPBWire::varint32Size($data_size) + $data_size;
+ }
+ }
+ } elseif ($field->isRepeated()) {
+ $getter = $field->getGetter();
+ $values = $this->$getter();
+ $count = count($values);
+ if ($count !== 0) {
+ if ($field->getPacked()) {
+ $data_size = 0;
+ foreach ($values as $value) {
+ $data_size += $this->fieldDataOnlyByteSize($field, $value);
+ }
+ $size += GPBWire::tagSize($field);
+ $size += GPBWire::varint32Size($data_size);
+ $size += $data_size;
+ } else {
+ $size += $count * GPBWire::tagSize($field);
+ foreach ($values as $value) {
+ $size += $this->fieldDataOnlyByteSize($field, $value);
+ }
+ }
+ }
+ } elseif ($this->existField($field)) {
+ $size += GPBWire::tagSize($field);
+ $getter = $field->getGetter();
+ $value = $this->$getter();
+ $size += $this->fieldDataOnlyByteSize($field, $value);
+ }
+ return $size;
+ }
+
+ /**
+ * @ignore
+ */
+ public function byteSize()
+ {
+ $size = 0;
+
+ $fields = $this->desc->getField();
+ foreach ($fields as $field) {
+ $size += $this->fieldByteSize($field);
+ }
+ return $size;
+ }
+}
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/MessageBuilderContext.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/MessageBuilderContext.php
new file mode 100644
index 0000000000..2724d2673d
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/MessageBuilderContext.php
@@ -0,0 +1,120 @@
+<?php
+
+// 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.
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBLabel;
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\Descriptor;
+use Google\Protobuf\Internal\FieldDescriptor;
+
+class MessageBuilderContext
+{
+
+ private $descriptor;
+ private $pool;
+
+ public function __construct($full_name, $klass, $pool)
+ {
+ $this->descriptor = new Descriptor();
+ $this->descriptor->setFullName($full_name);
+ $this->descriptor->setClass($klass);
+ $this->pool = $pool;
+ }
+
+ private function getFieldDescriptor($name, $label, $type,
+ $number, $type_name = null)
+ {
+ $field = new FieldDescriptor();
+ $field->setName($name);
+ $camel_name = implode('', array_map('ucwords', explode('_', $name)));
+ $field->setGetter('get' . $camel_name);
+ $field->setSetter('set' . $camel_name);
+ $field->setType($type);
+ $field->setNumber($number);
+ $field->setLabel($label);
+
+ // At this time, the message/enum type may have not been added to pool.
+ // So we use the type name as place holder and will replace it with the
+ // actual descriptor in cross building.
+ switch ($type) {
+ case GPBType::MESSAGE:
+ $field->setMessageType($type_name);
+ break;
+ case GPBType::ENUM:
+ $field->setEnumType($type_name);
+ break;
+ default:
+ break;
+ }
+
+ return $field;
+ }
+
+ public function optional($name, $type, $number, $type_name = null)
+ {
+ $this->descriptor->addField($this->getFieldDescriptor(
+ $name,
+ GPBLabel::OPTIONAL,
+ $type,
+ $number,
+ $type_name));
+ return $this;
+ }
+
+ public function repeated($name, $type, $number, $type_name = null)
+ {
+ $this->descriptor->addField($this->getFieldDescriptor(
+ $name,
+ GPBLabel::REPEATED,
+ $type,
+ $number,
+ $type_name));
+ return $this;
+ }
+
+ public function required($name, $type, $number, $type_name = null)
+ {
+ $this->descriptor->addField($this->getFieldDescriptor(
+ $name,
+ GPBLabel::REQUIRED,
+ $type,
+ $number,
+ $type_name));
+ return $this;
+ }
+
+ public function finalizeToPool()
+ {
+ $this->pool->addDescriptor($this->descriptor);
+ }
+}
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/MessageOptions.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/MessageOptions.php
new file mode 100644
index 0000000000..747f32947b
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/MessageOptions.php
@@ -0,0 +1,334 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * Protobuf type <code>google.protobuf.MessageOptions</code>
+ */
+class MessageOptions extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <pre>
+ * Set true to use the old proto1 MessageSet wire format for extensions.
+ * This is provided for backwards-compatibility with the MessageSet wire
+ * format. You should not use this for any other reason: It's less
+ * efficient, has fewer features, and is more complicated.
+ * The message must be defined exactly as follows:
+ * message Foo {
+ * option message_set_wire_format = true;
+ * extensions 4 to max;
+ * }
+ * Note that the message cannot have any defined fields; MessageSets only
+ * have extensions.
+ * All extensions of your type must be singular messages; e.g. they cannot
+ * be int32s, enums, or repeated messages.
+ * Because this is an option, the above two restrictions are not enforced by
+ * the protocol compiler.
+ * </pre>
+ *
+ * <code>optional bool message_set_wire_format = 1 [default = false];</code>
+ */
+ private $message_set_wire_format = false;
+ private $has_message_set_wire_format = false;
+ /**
+ * <pre>
+ * Disables the generation of the standard "descriptor()" accessor, which can
+ * conflict with a field of the same name. This is meant to make migration
+ * from proto1 easier; new code should avoid fields named "descriptor".
+ * </pre>
+ *
+ * <code>optional bool no_standard_descriptor_accessor = 2 [default = false];</code>
+ */
+ private $no_standard_descriptor_accessor = false;
+ private $has_no_standard_descriptor_accessor = false;
+ /**
+ * <pre>
+ * Is this message deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for the message, or it will be completely ignored; in the very least,
+ * this is a formalization for deprecating messages.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 3 [default = false];</code>
+ */
+ private $deprecated = false;
+ private $has_deprecated = false;
+ /**
+ * <pre>
+ * Whether the message is an automatically generated map entry type for the
+ * maps field.
+ * For maps fields:
+ * map&lt;KeyType, ValueType&gt; map_field = 1;
+ * The parsed descriptor looks like:
+ * message MapFieldEntry {
+ * option map_entry = true;
+ * optional KeyType key = 1;
+ * optional ValueType value = 2;
+ * }
+ * repeated MapFieldEntry map_field = 1;
+ * Implementations may choose not to generate the map_entry=true message, but
+ * use a native map in the target language to hold the keys and values.
+ * The reflection APIs in such implementions still need to work as
+ * if the field is a repeated message field.
+ * NOTE: Do not set the option in .proto files. Always use the maps syntax
+ * instead. The option should only be implicitly set by the proto compiler
+ * parser.
+ * </pre>
+ *
+ * <code>optional bool map_entry = 7;</code>
+ */
+ private $map_entry = false;
+ private $has_map_entry = false;
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ private $uninterpreted_option;
+ private $has_uninterpreted_option = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <pre>
+ * Set true to use the old proto1 MessageSet wire format for extensions.
+ * This is provided for backwards-compatibility with the MessageSet wire
+ * format. You should not use this for any other reason: It's less
+ * efficient, has fewer features, and is more complicated.
+ * The message must be defined exactly as follows:
+ * message Foo {
+ * option message_set_wire_format = true;
+ * extensions 4 to max;
+ * }
+ * Note that the message cannot have any defined fields; MessageSets only
+ * have extensions.
+ * All extensions of your type must be singular messages; e.g. they cannot
+ * be int32s, enums, or repeated messages.
+ * Because this is an option, the above two restrictions are not enforced by
+ * the protocol compiler.
+ * </pre>
+ *
+ * <code>optional bool message_set_wire_format = 1 [default = false];</code>
+ */
+ public function getMessageSetWireFormat()
+ {
+ return $this->message_set_wire_format;
+ }
+
+ /**
+ * <pre>
+ * Set true to use the old proto1 MessageSet wire format for extensions.
+ * This is provided for backwards-compatibility with the MessageSet wire
+ * format. You should not use this for any other reason: It's less
+ * efficient, has fewer features, and is more complicated.
+ * The message must be defined exactly as follows:
+ * message Foo {
+ * option message_set_wire_format = true;
+ * extensions 4 to max;
+ * }
+ * Note that the message cannot have any defined fields; MessageSets only
+ * have extensions.
+ * All extensions of your type must be singular messages; e.g. they cannot
+ * be int32s, enums, or repeated messages.
+ * Because this is an option, the above two restrictions are not enforced by
+ * the protocol compiler.
+ * </pre>
+ *
+ * <code>optional bool message_set_wire_format = 1 [default = false];</code>
+ */
+ public function setMessageSetWireFormat($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->message_set_wire_format = $var;
+ $this->has_message_set_wire_format = true;
+ }
+
+ public function hasMessageSetWireFormat()
+ {
+ return $this->has_message_set_wire_format;
+ }
+
+ /**
+ * <pre>
+ * Disables the generation of the standard "descriptor()" accessor, which can
+ * conflict with a field of the same name. This is meant to make migration
+ * from proto1 easier; new code should avoid fields named "descriptor".
+ * </pre>
+ *
+ * <code>optional bool no_standard_descriptor_accessor = 2 [default = false];</code>
+ */
+ public function getNoStandardDescriptorAccessor()
+ {
+ return $this->no_standard_descriptor_accessor;
+ }
+
+ /**
+ * <pre>
+ * Disables the generation of the standard "descriptor()" accessor, which can
+ * conflict with a field of the same name. This is meant to make migration
+ * from proto1 easier; new code should avoid fields named "descriptor".
+ * </pre>
+ *
+ * <code>optional bool no_standard_descriptor_accessor = 2 [default = false];</code>
+ */
+ public function setNoStandardDescriptorAccessor($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->no_standard_descriptor_accessor = $var;
+ $this->has_no_standard_descriptor_accessor = true;
+ }
+
+ public function hasNoStandardDescriptorAccessor()
+ {
+ return $this->has_no_standard_descriptor_accessor;
+ }
+
+ /**
+ * <pre>
+ * Is this message deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for the message, or it will be completely ignored; in the very least,
+ * this is a formalization for deprecating messages.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 3 [default = false];</code>
+ */
+ public function getDeprecated()
+ {
+ return $this->deprecated;
+ }
+
+ /**
+ * <pre>
+ * Is this message deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for the message, or it will be completely ignored; in the very least,
+ * this is a formalization for deprecating messages.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 3 [default = false];</code>
+ */
+ public function setDeprecated($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->deprecated = $var;
+ $this->has_deprecated = true;
+ }
+
+ public function hasDeprecated()
+ {
+ return $this->has_deprecated;
+ }
+
+ /**
+ * <pre>
+ * Whether the message is an automatically generated map entry type for the
+ * maps field.
+ * For maps fields:
+ * map&lt;KeyType, ValueType&gt; map_field = 1;
+ * The parsed descriptor looks like:
+ * message MapFieldEntry {
+ * option map_entry = true;
+ * optional KeyType key = 1;
+ * optional ValueType value = 2;
+ * }
+ * repeated MapFieldEntry map_field = 1;
+ * Implementations may choose not to generate the map_entry=true message, but
+ * use a native map in the target language to hold the keys and values.
+ * The reflection APIs in such implementions still need to work as
+ * if the field is a repeated message field.
+ * NOTE: Do not set the option in .proto files. Always use the maps syntax
+ * instead. The option should only be implicitly set by the proto compiler
+ * parser.
+ * </pre>
+ *
+ * <code>optional bool map_entry = 7;</code>
+ */
+ public function getMapEntry()
+ {
+ return $this->map_entry;
+ }
+
+ /**
+ * <pre>
+ * Whether the message is an automatically generated map entry type for the
+ * maps field.
+ * For maps fields:
+ * map&lt;KeyType, ValueType&gt; map_field = 1;
+ * The parsed descriptor looks like:
+ * message MapFieldEntry {
+ * option map_entry = true;
+ * optional KeyType key = 1;
+ * optional ValueType value = 2;
+ * }
+ * repeated MapFieldEntry map_field = 1;
+ * Implementations may choose not to generate the map_entry=true message, but
+ * use a native map in the target language to hold the keys and values.
+ * The reflection APIs in such implementions still need to work as
+ * if the field is a repeated message field.
+ * NOTE: Do not set the option in .proto files. Always use the maps syntax
+ * instead. The option should only be implicitly set by the proto compiler
+ * parser.
+ * </pre>
+ *
+ * <code>optional bool map_entry = 7;</code>
+ */
+ public function setMapEntry($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->map_entry = $var;
+ $this->has_map_entry = true;
+ }
+
+ public function hasMapEntry()
+ {
+ return $this->has_map_entry;
+ }
+
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ public function getUninterpretedOption()
+ {
+ return $this->uninterpreted_option;
+ }
+
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ public function setUninterpretedOption(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
+ $this->uninterpreted_option = $arr;
+ $this->has_uninterpreted_option = true;
+ }
+
+ public function hasUninterpretedOption()
+ {
+ return $this->has_uninterpreted_option;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php
new file mode 100644
index 0000000000..3d8df7af73
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/MethodDescriptorProto.php
@@ -0,0 +1,237 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * <pre>
+ * Describes a method of a service.
+ * </pre>
+ *
+ * Protobuf type <code>google.protobuf.MethodDescriptorProto</code>
+ */
+class MethodDescriptorProto extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ private $name = '';
+ private $has_name = false;
+ /**
+ * <pre>
+ * Input and output type names. These are resolved in the same way as
+ * FieldDescriptorProto.type_name, but must refer to a message type.
+ * </pre>
+ *
+ * <code>optional string input_type = 2;</code>
+ */
+ private $input_type = '';
+ private $has_input_type = false;
+ /**
+ * <code>optional string output_type = 3;</code>
+ */
+ private $output_type = '';
+ private $has_output_type = false;
+ /**
+ * <code>optional .google.protobuf.MethodOptions options = 4;</code>
+ */
+ private $options = null;
+ private $has_options = false;
+ /**
+ * <pre>
+ * Identifies if client streams multiple client messages
+ * </pre>
+ *
+ * <code>optional bool client_streaming = 5 [default = false];</code>
+ */
+ private $client_streaming = false;
+ private $has_client_streaming = false;
+ /**
+ * <pre>
+ * Identifies if server streams multiple server messages
+ * </pre>
+ *
+ * <code>optional bool server_streaming = 6 [default = false];</code>
+ */
+ private $server_streaming = false;
+ private $has_server_streaming = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ public function setName($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->name = $var;
+ $this->has_name = true;
+ }
+
+ public function hasName()
+ {
+ return $this->has_name;
+ }
+
+ /**
+ * <pre>
+ * Input and output type names. These are resolved in the same way as
+ * FieldDescriptorProto.type_name, but must refer to a message type.
+ * </pre>
+ *
+ * <code>optional string input_type = 2;</code>
+ */
+ public function getInputType()
+ {
+ return $this->input_type;
+ }
+
+ /**
+ * <pre>
+ * Input and output type names. These are resolved in the same way as
+ * FieldDescriptorProto.type_name, but must refer to a message type.
+ * </pre>
+ *
+ * <code>optional string input_type = 2;</code>
+ */
+ public function setInputType($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->input_type = $var;
+ $this->has_input_type = true;
+ }
+
+ public function hasInputType()
+ {
+ return $this->has_input_type;
+ }
+
+ /**
+ * <code>optional string output_type = 3;</code>
+ */
+ public function getOutputType()
+ {
+ return $this->output_type;
+ }
+
+ /**
+ * <code>optional string output_type = 3;</code>
+ */
+ public function setOutputType($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->output_type = $var;
+ $this->has_output_type = true;
+ }
+
+ public function hasOutputType()
+ {
+ return $this->has_output_type;
+ }
+
+ /**
+ * <code>optional .google.protobuf.MethodOptions options = 4;</code>
+ */
+ public function getOptions()
+ {
+ return $this->options;
+ }
+
+ /**
+ * <code>optional .google.protobuf.MethodOptions options = 4;</code>
+ */
+ public function setOptions(&$var)
+ {
+ GPBUtil::checkMessage($var, \Google\Protobuf\Internal\MethodOptions::class);
+ $this->options = $var;
+ $this->has_options = true;
+ }
+
+ public function hasOptions()
+ {
+ return $this->has_options;
+ }
+
+ /**
+ * <pre>
+ * Identifies if client streams multiple client messages
+ * </pre>
+ *
+ * <code>optional bool client_streaming = 5 [default = false];</code>
+ */
+ public function getClientStreaming()
+ {
+ return $this->client_streaming;
+ }
+
+ /**
+ * <pre>
+ * Identifies if client streams multiple client messages
+ * </pre>
+ *
+ * <code>optional bool client_streaming = 5 [default = false];</code>
+ */
+ public function setClientStreaming($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->client_streaming = $var;
+ $this->has_client_streaming = true;
+ }
+
+ public function hasClientStreaming()
+ {
+ return $this->has_client_streaming;
+ }
+
+ /**
+ * <pre>
+ * Identifies if server streams multiple server messages
+ * </pre>
+ *
+ * <code>optional bool server_streaming = 6 [default = false];</code>
+ */
+ public function getServerStreaming()
+ {
+ return $this->server_streaming;
+ }
+
+ /**
+ * <pre>
+ * Identifies if server streams multiple server messages
+ * </pre>
+ *
+ * <code>optional bool server_streaming = 6 [default = false];</code>
+ */
+ public function setServerStreaming($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->server_streaming = $var;
+ $this->has_server_streaming = true;
+ }
+
+ public function hasServerStreaming()
+ {
+ return $this->has_server_streaming;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/MethodOptions.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/MethodOptions.php
new file mode 100644
index 0000000000..6dca58540b
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/MethodOptions.php
@@ -0,0 +1,143 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * Protobuf type <code>google.protobuf.MethodOptions</code>
+ */
+class MethodOptions extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <pre>
+ * Is this method deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for the method, or it will be completely ignored; in the very least,
+ * this is a formalization for deprecating methods.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 33 [default = false];</code>
+ */
+ private $deprecated = false;
+ private $has_deprecated = false;
+ /**
+ * <code>optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN];</code>
+ */
+ private $idempotency_level = 0;
+ private $has_idempotency_level = false;
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ private $uninterpreted_option;
+ private $has_uninterpreted_option = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <pre>
+ * Is this method deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for the method, or it will be completely ignored; in the very least,
+ * this is a formalization for deprecating methods.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 33 [default = false];</code>
+ */
+ public function getDeprecated()
+ {
+ return $this->deprecated;
+ }
+
+ /**
+ * <pre>
+ * Is this method deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for the method, or it will be completely ignored; in the very least,
+ * this is a formalization for deprecating methods.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 33 [default = false];</code>
+ */
+ public function setDeprecated($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->deprecated = $var;
+ $this->has_deprecated = true;
+ }
+
+ public function hasDeprecated()
+ {
+ return $this->has_deprecated;
+ }
+
+ /**
+ * <code>optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN];</code>
+ */
+ public function getIdempotencyLevel()
+ {
+ return $this->idempotency_level;
+ }
+
+ /**
+ * <code>optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN];</code>
+ */
+ public function setIdempotencyLevel($var)
+ {
+ GPBUtil::checkEnum($var, \Google\Protobuf\Internal\MethodOptions_IdempotencyLevel::class);
+ $this->idempotency_level = $var;
+ $this->has_idempotency_level = true;
+ }
+
+ public function hasIdempotencyLevel()
+ {
+ return $this->has_idempotency_level;
+ }
+
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ public function getUninterpretedOption()
+ {
+ return $this->uninterpreted_option;
+ }
+
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ public function setUninterpretedOption(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
+ $this->uninterpreted_option = $arr;
+ $this->has_uninterpreted_option = true;
+ }
+
+ public function hasUninterpretedOption()
+ {
+ return $this->has_uninterpreted_option;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php
new file mode 100644
index 0000000000..ce4adfe7c4
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php
@@ -0,0 +1,39 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+/**
+ * <pre>
+ * Is this method side-effect-free (or safe in HTTP parlance), or idempotent,
+ * or neither? HTTP based RPC implementation may choose GET verb for safe
+ * methods, and PUT verb for idempotent methods instead of the default POST.
+ * </pre>
+ *
+ * Protobuf enum <code>google.protobuf.MethodOptions.IdempotencyLevel</code>
+ */
+class MethodOptions_IdempotencyLevel
+{
+ /**
+ * <code>IDEMPOTENCY_UNKNOWN = 0;</code>
+ */
+ const IDEMPOTENCY_UNKNOWN = 0;
+ /**
+ * <pre>
+ * implies idempotent
+ * </pre>
+ *
+ * <code>NO_SIDE_EFFECTS = 1;</code>
+ */
+ const NO_SIDE_EFFECTS = 1;
+ /**
+ * <pre>
+ * idempotent, but may have side effects
+ * </pre>
+ *
+ * <code>IDEMPOTENT = 2;</code>
+ */
+ const IDEMPOTENT = 2;
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php
new file mode 100644
index 0000000000..e5fbe37065
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/OneofDescriptorProto.php
@@ -0,0 +1,86 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * <pre>
+ * Describes a oneof.
+ * </pre>
+ *
+ * Protobuf type <code>google.protobuf.OneofDescriptorProto</code>
+ */
+class OneofDescriptorProto extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ private $name = '';
+ private $has_name = false;
+ /**
+ * <code>optional .google.protobuf.OneofOptions options = 2;</code>
+ */
+ private $options = null;
+ private $has_options = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ public function setName($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->name = $var;
+ $this->has_name = true;
+ }
+
+ public function hasName()
+ {
+ return $this->has_name;
+ }
+
+ /**
+ * <code>optional .google.protobuf.OneofOptions options = 2;</code>
+ */
+ public function getOptions()
+ {
+ return $this->options;
+ }
+
+ /**
+ * <code>optional .google.protobuf.OneofOptions options = 2;</code>
+ */
+ public function setOptions(&$var)
+ {
+ GPBUtil::checkMessage($var, \Google\Protobuf\Internal\OneofOptions::class);
+ $this->options = $var;
+ $this->has_options = true;
+ }
+
+ public function hasOptions()
+ {
+ return $this->has_options;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/OneofField.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/OneofField.php
new file mode 100644
index 0000000000..2c689e836c
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/OneofField.php
@@ -0,0 +1,77 @@
+<?php
+
+// 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.
+
+namespace Google\Protobuf\Internal;
+
+class OneofField
+{
+
+ private $desc;
+ private $field_name;
+ private $number = 0;
+ private $value;
+
+ public function __construct($desc)
+ {
+ $this->desc = $desc;
+ }
+
+ public function setValue($value)
+ {
+ $this->value = $value;
+ }
+
+ public function getValue()
+ {
+ return $this->value;
+ }
+
+ public function setFieldName($field_name)
+ {
+ $this->field_name = $field_name;
+ }
+
+ public function getFieldName()
+ {
+ return $this->field_name;
+ }
+
+ public function setNumber($number)
+ {
+ $this->number = $number;
+ }
+
+ public function getNumber()
+ {
+ return $this->number;
+ }
+}
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/OneofOptions.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/OneofOptions.php
new file mode 100644
index 0000000000..b61325d29e
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/OneofOptions.php
@@ -0,0 +1,66 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * Protobuf type <code>google.protobuf.OneofOptions</code>
+ */
+class OneofOptions extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ private $uninterpreted_option;
+ private $has_uninterpreted_option = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ public function getUninterpretedOption()
+ {
+ return $this->uninterpreted_option;
+ }
+
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ public function setUninterpretedOption(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
+ $this->uninterpreted_option = $arr;
+ $this->has_uninterpreted_option = true;
+ }
+
+ public function hasUninterpretedOption()
+ {
+ return $this->has_uninterpreted_option;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/OutputStream.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/OutputStream.php
new file mode 100644
index 0000000000..8c6d9b6807
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/OutputStream.php
@@ -0,0 +1,159 @@
+<?php
+
+// 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.
+
+namespace Google\Protobuf\Internal;
+
+class OutputStream
+{
+
+ private $buffer;
+ private $buffer_size;
+ private $current;
+
+ const MAX_VARINT64_BYTES = 10;
+
+ public function __construct($size)
+ {
+ $this->current = 0;
+ $this->buffer_size = $size;
+ $this->buffer = str_repeat(chr(0), $this->buffer_size);
+ }
+
+ public function getData()
+ {
+ return $this->buffer;
+ }
+
+ public function writeVarint32($value)
+ {
+ $bytes = str_repeat(chr(0), self::MAX_VARINT64_BYTES);
+ $size = self::writeVarintToArray($value, $bytes);
+ return $this->writeRaw($bytes, $size);
+ }
+
+ public function writeVarint64($value)
+ {
+ $bytes = str_repeat(chr(0), self::MAX_VARINT64_BYTES);
+ $size = self::writeVarintToArray($value, $bytes);
+ return $this->writeRaw($bytes, $size);
+ }
+
+ public function writeLittleEndian32($value)
+ {
+ $bytes = str_repeat(chr(0), 4);
+ $size = self::writeLittleEndian32ToArray($value, $bytes);
+ return $this->writeRaw($bytes, $size);
+ }
+
+ public function writeLittleEndian64($value)
+ {
+ $bytes = str_repeat(chr(0), 8);
+ $size = self::writeLittleEndian64ToArray($value, $bytes);
+ return $this->writeRaw($bytes, $size);
+ }
+
+ public function writeTag($tag)
+ {
+ return $this->writeVarint32($tag);
+ }
+
+ public function writeRaw($data, $size)
+ {
+ if ($this->buffer_size < $size) {
+ trigger_error("Output stream doesn't have enough buffer.");
+ return false;
+ }
+
+ for ($i = 0; $i < $size; $i++) {
+ $this->buffer[$this->current] = $data[$i];
+ $this->current++;
+ $this->buffer_size--;
+ }
+ return true;
+ }
+
+ private static function writeVarintToArray($value, &$buffer)
+ {
+ $current = 0;
+
+ $high = 0;
+ $low = 0;
+ if (PHP_INT_SIZE == 4) {
+ GPBUtil::divideInt64ToInt32($value, $high, $low);
+ } else {
+ $low = $value;
+ }
+
+ while ($low >= 0x80 || $low < 0) {
+ $buffer[$current] = chr($low | 0x80);
+ $value = ($value >> 7) & ~(0x7F << ((PHP_INT_SIZE << 3) - 7));
+ $carry = ($high & 0x7F) << ((PHP_INT_SIZE << 3) - 7);
+ $high = ($high >> 7) & ~(0x7F << ((PHP_INT_SIZE << 3) - 7));
+ $low = (($low >> 7) & ~(0x7F << ((PHP_INT_SIZE << 3) - 7)) | $carry);
+ $current++;
+ }
+ $buffer[$current] = chr($low);
+ return $current + 1;
+ }
+
+ private static function writeLittleEndian32ToArray($value, &$buffer)
+ {
+ $buffer[0] = chr($value & 0x000000FF);
+ $buffer[1] = chr(($value >> 8) & 0x000000FF);
+ $buffer[2] = chr(($value >> 16) & 0x000000FF);
+ $buffer[3] = chr(($value >> 24) & 0x000000FF);
+ return 4;
+ }
+
+ private static function writeLittleEndian64ToArray($value, &$buffer)
+ {
+ $high = 0;
+ $low = 0;
+ if (PHP_INT_SIZE == 4) {
+ GPBUtil::divideInt64ToInt32($value, $high, $low);
+ } else {
+ $low = $value & 0xFFFFFFFF;
+ $high = ($value >> 32) & 0xFFFFFFFF;
+ }
+
+ $buffer[0] = chr($low & 0x000000FF);
+ $buffer[1] = chr(($low >> 8) & 0x000000FF);
+ $buffer[2] = chr(($low >> 16) & 0x000000FF);
+ $buffer[3] = chr(($low >> 24) & 0x000000FF);
+ $buffer[4] = chr($high & 0x000000FF);
+ $buffer[5] = chr(($high >> 8) & 0x000000FF);
+ $buffer[6] = chr(($high >> 16) & 0x000000FF);
+ $buffer[7] = chr(($high >> 24) & 0x000000FF);
+ return 8;
+ }
+
+}
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/RepeatedField.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/RepeatedField.php
new file mode 100644
index 0000000000..0dc5d9d206
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/RepeatedField.php
@@ -0,0 +1,303 @@
+<?php
+
+// 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.
+
+/**
+ * RepeatedField and RepeatedFieldIter are used by generated protocol message
+ * classes to manipulate repeated fields.
+ */
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * RepeatedFieldIter is used to iterate RepeatedField. It is also need for the
+ * foreach syntax.
+ */
+class RepeatedFieldIter implements \Iterator
+{
+
+ /**
+ * @ignore
+ */
+ private $position;
+ /**
+ * @ignore
+ */
+ private $container;
+
+ /**
+ * Create iterator instance for RepeatedField.
+ *
+ * @param RepeatedField The RepeatedField instance for which this iterator
+ * is created.
+ * @ignore
+ */
+ public function __construct($container)
+ {
+ $this->position = 0;
+ $this->container = $container;
+ }
+
+ /**
+ * Reset the status of the iterator
+ *
+ * @return void
+ */
+ public function rewind()
+ {
+ $this->position = 0;
+ }
+
+ /**
+ * Return the element at the current position.
+ *
+ * @return object The element at the current position.
+ */
+ public function current()
+ {
+ return $this->container[$this->position];
+ }
+
+ /**
+ * Return the current position.
+ *
+ * @return integer The current position.
+ */
+ public function key()
+ {
+ return $this->position;
+ }
+
+ /**
+ * Move to the next position.
+ *
+ * @return void
+ */
+ public function next()
+ {
+ ++$this->position;
+ }
+
+ /**
+ * Check whether there are more elements to iterate.
+ *
+ * @return bool True if there are more elements to iterate.
+ */
+ public function valid()
+ {
+ return isset($this->container[$this->position]);
+ }
+}
+
+/**
+ * RepeatedField is used by generated protocol message classes to manipulate
+ * repeated fields. It can be used like native PHP array.
+ */
+class RepeatedField implements \ArrayAccess, \IteratorAggregate, \Countable
+{
+
+ /**
+ * @ignore
+ */
+ private $container;
+ /**
+ * @ignore
+ */
+ private $type;
+ /**
+ * @ignore
+ */
+ private $klass;
+
+ /**
+ * Constructs an instance of RepeatedField.
+ *
+ * @param long $type Type of the stored element.
+ * @param string $klass Message/Enum class name (message/enum fields only).
+ * @ignore
+ */
+ public function __construct($type, $klass = null)
+ {
+ $this->container = [];
+ $this->type = $type;
+ $this->klass = $klass;
+ }
+
+ /**
+ * @ignore
+ */
+ public function getType()
+ {
+ return $this->type;
+ }
+
+ /**
+ * @ignore
+ */
+ public function getClass()
+ {
+ return $this->klass;
+ }
+
+ /**
+ * Return the element at the given index.
+ *
+ * This will also be called for: $ele = $arr[0]
+ *
+ * @param long $offset The index of the element to be fetched.
+ * @return object The stored element at given index.
+ * @throws ErrorException Invalid type for index.
+ * @throws ErrorException Non-existing index.
+ */
+ public function offsetGet($offset)
+ {
+ return $this->container[$offset];
+ }
+
+ /**
+ * Assign the element at the given index.
+ *
+ * This will also be called for: $arr []= $ele and $arr[0] = ele
+ *
+ * @param long $offset The index of the element to be assigned.
+ * @param object $value The element to be assigned.
+ * @return void
+ * @throws ErrorException Invalid type for index.
+ * @throws ErrorException Non-existing index.
+ * @throws ErrorException Incorrect type of the element.
+ */
+ public function offsetSet($offset, $value)
+ {
+ switch ($this->type) {
+ case GPBType::INT32:
+ GPBUtil::checkInt32($value);
+ break;
+ case GPBType::UINT32:
+ GPBUtil::checkUint32($value);
+ break;
+ case GPBType::INT64:
+ GPBUtil::checkInt64($value);
+ break;
+ case GPBType::UINT64:
+ GPBUtil::checkUint64($value);
+ break;
+ case GPBType::FLOAT:
+ GPBUtil::checkFloat($value);
+ break;
+ case GPBType::DOUBLE:
+ GPBUtil::checkDouble($value);
+ break;
+ case GPBType::BOOL:
+ GPBUtil::checkBool($value);
+ break;
+ case GPBType::STRING:
+ GPBUtil::checkString($value, true);
+ break;
+ case GPBType::MESSAGE:
+ GPBUtil::checkMessage($value, $this->klass);
+ break;
+ default:
+ break;
+ }
+ if (is_null($offset)) {
+ $this->container[] = $value;
+ } else {
+ $count = count($this->container);
+ if (!is_numeric($offset) || $offset < 0 || $offset >= $count) {
+ trigger_error(
+ "Cannot modify element at the given index",
+ E_USER_ERROR);
+ return;
+ }
+ $this->container[$offset] = $value;
+ }
+ }
+
+ /**
+ * Remove the element at the given index.
+ *
+ * This will also be called for: unset($arr)
+ *
+ * @param long $offset The index of the element to be removed.
+ * @return void
+ * @throws ErrorException Invalid type for index.
+ * @throws ErrorException The element to be removed is not at the end of the
+ * RepeatedField.
+ */
+ public function offsetUnset($offset)
+ {
+ $count = count($this->container);
+ if (!is_numeric($offset) || $count === 0 || $offset !== $count - 1) {
+ trigger_error(
+ "Cannot remove element at the given index",
+ E_USER_ERROR);
+ return;
+ }
+ array_pop($this->container);
+ }
+
+ /**
+ * Check the existence of the element at the given index.
+ *
+ * This will also be called for: isset($arr)
+ *
+ * @param long $offset The index of the element to be removed.
+ * @return bool True if the element at the given offset exists.
+ * @throws ErrorException Invalid type for index.
+ */
+ public function offsetExists($offset)
+ {
+ return isset($this->container[$offset]);
+ }
+
+ /**
+ * @ignore
+ */
+ public function getIterator()
+ {
+ return new RepeatedFieldIter($this->container);
+ }
+
+ /**
+ * Return the number of stored elements.
+ *
+ * This will also be called for: count($arr)
+ *
+ * @return integer The number of stored elements.
+ */
+ public function count()
+ {
+ return count($this->container);
+ }
+}
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php
new file mode 100644
index 0000000000..4777620262
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php
@@ -0,0 +1,114 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * <pre>
+ * Describes a service.
+ * </pre>
+ *
+ * Protobuf type <code>google.protobuf.ServiceDescriptorProto</code>
+ */
+class ServiceDescriptorProto extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ private $name = '';
+ private $has_name = false;
+ /**
+ * <code>repeated .google.protobuf.MethodDescriptorProto method = 2;</code>
+ */
+ private $method;
+ private $has_method = false;
+ /**
+ * <code>optional .google.protobuf.ServiceOptions options = 3;</code>
+ */
+ private $options = null;
+ private $has_options = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * <code>optional string name = 1;</code>
+ */
+ public function setName($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->name = $var;
+ $this->has_name = true;
+ }
+
+ public function hasName()
+ {
+ return $this->has_name;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.MethodDescriptorProto method = 2;</code>
+ */
+ public function getMethod()
+ {
+ return $this->method;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.MethodDescriptorProto method = 2;</code>
+ */
+ public function setMethod(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\MethodDescriptorProto::class);
+ $this->method = $arr;
+ $this->has_method = true;
+ }
+
+ public function hasMethod()
+ {
+ return $this->has_method;
+ }
+
+ /**
+ * <code>optional .google.protobuf.ServiceOptions options = 3;</code>
+ */
+ public function getOptions()
+ {
+ return $this->options;
+ }
+
+ /**
+ * <code>optional .google.protobuf.ServiceOptions options = 3;</code>
+ */
+ public function setOptions(&$var)
+ {
+ GPBUtil::checkMessage($var, \Google\Protobuf\Internal\ServiceOptions::class);
+ $this->options = $var;
+ $this->has_options = true;
+ }
+
+ public function hasOptions()
+ {
+ return $this->has_options;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/ServiceOptions.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/ServiceOptions.php
new file mode 100644
index 0000000000..62323dbad1
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/ServiceOptions.php
@@ -0,0 +1,115 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * Protobuf type <code>google.protobuf.ServiceOptions</code>
+ */
+class ServiceOptions extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <pre>
+ * Is this service deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for the service, or it will be completely ignored; in the very least,
+ * this is a formalization for deprecating services.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 33 [default = false];</code>
+ */
+ private $deprecated = false;
+ private $has_deprecated = false;
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ private $uninterpreted_option;
+ private $has_uninterpreted_option = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <pre>
+ * Is this service deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for the service, or it will be completely ignored; in the very least,
+ * this is a formalization for deprecating services.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 33 [default = false];</code>
+ */
+ public function getDeprecated()
+ {
+ return $this->deprecated;
+ }
+
+ /**
+ * <pre>
+ * Is this service deprecated?
+ * Depending on the target platform, this can emit Deprecated annotations
+ * for the service, or it will be completely ignored; in the very least,
+ * this is a formalization for deprecating services.
+ * </pre>
+ *
+ * <code>optional bool deprecated = 33 [default = false];</code>
+ */
+ public function setDeprecated($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->deprecated = $var;
+ $this->has_deprecated = true;
+ }
+
+ public function hasDeprecated()
+ {
+ return $this->has_deprecated;
+ }
+
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ public function getUninterpretedOption()
+ {
+ return $this->uninterpreted_option;
+ }
+
+ /**
+ * <pre>
+ * The parser stores options it doesn't recognize here. See above.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
+ */
+ public function setUninterpretedOption(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption::class);
+ $this->uninterpreted_option = $arr;
+ $this->has_uninterpreted_option = true;
+ }
+
+ public function hasUninterpretedOption()
+ {
+ return $this->has_uninterpreted_option;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/SourceCodeInfo.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/SourceCodeInfo.php
new file mode 100644
index 0000000000..eab6088033
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/SourceCodeInfo.php
@@ -0,0 +1,191 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * <pre>
+ * Encapsulates information about the original source file from which a
+ * FileDescriptorProto was generated.
+ * </pre>
+ *
+ * Protobuf type <code>google.protobuf.SourceCodeInfo</code>
+ */
+class SourceCodeInfo extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <pre>
+ * A Location identifies a piece of source code in a .proto file which
+ * corresponds to a particular definition. This information is intended
+ * to be useful to IDEs, code indexers, documentation generators, and similar
+ * tools.
+ * For example, say we have a file like:
+ * message Foo {
+ * optional string foo = 1;
+ * }
+ * Let's look at just the field definition:
+ * optional string foo = 1;
+ * ^ ^^ ^^ ^ ^^^
+ * a bc de f ghi
+ * We have the following locations:
+ * span path represents
+ * [a,i) [ 4, 0, 2, 0 ] The whole field definition.
+ * [a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
+ * [c,d) [ 4, 0, 2, 0, 5 ] The type (string).
+ * [e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
+ * [g,h) [ 4, 0, 2, 0, 3 ] The number (1).
+ * Notes:
+ * - A location may refer to a repeated field itself (i.e. not to any
+ * particular index within it). This is used whenever a set of elements are
+ * logically enclosed in a single code segment. For example, an entire
+ * extend block (possibly containing multiple extension definitions) will
+ * have an outer location whose path refers to the "extensions" repeated
+ * field without an index.
+ * - Multiple locations may have the same path. This happens when a single
+ * logical declaration is spread out across multiple places. The most
+ * obvious example is the "extend" block again -- there may be multiple
+ * extend blocks in the same scope, each of which will have the same path.
+ * - A location's span is not always a subset of its parent's span. For
+ * example, the "extendee" of an extension declaration appears at the
+ * beginning of the "extend" block and is shared by all extensions within
+ * the block.
+ * - Just because a location's span is a subset of some other location's span
+ * does not mean that it is a descendent. For example, a "group" defines
+ * both a type and a field in a single declaration. Thus, the locations
+ * corresponding to the type and field and their components will overlap.
+ * - Code which tries to interpret locations should probably be designed to
+ * ignore those that it doesn't understand, as more types of locations could
+ * be recorded in the future.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.SourceCodeInfo.Location location = 1;</code>
+ */
+ private $location;
+ private $has_location = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <pre>
+ * A Location identifies a piece of source code in a .proto file which
+ * corresponds to a particular definition. This information is intended
+ * to be useful to IDEs, code indexers, documentation generators, and similar
+ * tools.
+ * For example, say we have a file like:
+ * message Foo {
+ * optional string foo = 1;
+ * }
+ * Let's look at just the field definition:
+ * optional string foo = 1;
+ * ^ ^^ ^^ ^ ^^^
+ * a bc de f ghi
+ * We have the following locations:
+ * span path represents
+ * [a,i) [ 4, 0, 2, 0 ] The whole field definition.
+ * [a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
+ * [c,d) [ 4, 0, 2, 0, 5 ] The type (string).
+ * [e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
+ * [g,h) [ 4, 0, 2, 0, 3 ] The number (1).
+ * Notes:
+ * - A location may refer to a repeated field itself (i.e. not to any
+ * particular index within it). This is used whenever a set of elements are
+ * logically enclosed in a single code segment. For example, an entire
+ * extend block (possibly containing multiple extension definitions) will
+ * have an outer location whose path refers to the "extensions" repeated
+ * field without an index.
+ * - Multiple locations may have the same path. This happens when a single
+ * logical declaration is spread out across multiple places. The most
+ * obvious example is the "extend" block again -- there may be multiple
+ * extend blocks in the same scope, each of which will have the same path.
+ * - A location's span is not always a subset of its parent's span. For
+ * example, the "extendee" of an extension declaration appears at the
+ * beginning of the "extend" block and is shared by all extensions within
+ * the block.
+ * - Just because a location's span is a subset of some other location's span
+ * does not mean that it is a descendent. For example, a "group" defines
+ * both a type and a field in a single declaration. Thus, the locations
+ * corresponding to the type and field and their components will overlap.
+ * - Code which tries to interpret locations should probably be designed to
+ * ignore those that it doesn't understand, as more types of locations could
+ * be recorded in the future.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.SourceCodeInfo.Location location = 1;</code>
+ */
+ public function getLocation()
+ {
+ return $this->location;
+ }
+
+ /**
+ * <pre>
+ * A Location identifies a piece of source code in a .proto file which
+ * corresponds to a particular definition. This information is intended
+ * to be useful to IDEs, code indexers, documentation generators, and similar
+ * tools.
+ * For example, say we have a file like:
+ * message Foo {
+ * optional string foo = 1;
+ * }
+ * Let's look at just the field definition:
+ * optional string foo = 1;
+ * ^ ^^ ^^ ^ ^^^
+ * a bc de f ghi
+ * We have the following locations:
+ * span path represents
+ * [a,i) [ 4, 0, 2, 0 ] The whole field definition.
+ * [a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
+ * [c,d) [ 4, 0, 2, 0, 5 ] The type (string).
+ * [e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
+ * [g,h) [ 4, 0, 2, 0, 3 ] The number (1).
+ * Notes:
+ * - A location may refer to a repeated field itself (i.e. not to any
+ * particular index within it). This is used whenever a set of elements are
+ * logically enclosed in a single code segment. For example, an entire
+ * extend block (possibly containing multiple extension definitions) will
+ * have an outer location whose path refers to the "extensions" repeated
+ * field without an index.
+ * - Multiple locations may have the same path. This happens when a single
+ * logical declaration is spread out across multiple places. The most
+ * obvious example is the "extend" block again -- there may be multiple
+ * extend blocks in the same scope, each of which will have the same path.
+ * - A location's span is not always a subset of its parent's span. For
+ * example, the "extendee" of an extension declaration appears at the
+ * beginning of the "extend" block and is shared by all extensions within
+ * the block.
+ * - Just because a location's span is a subset of some other location's span
+ * does not mean that it is a descendent. For example, a "group" defines
+ * both a type and a field in a single declaration. Thus, the locations
+ * corresponding to the type and field and their components will overlap.
+ * - Code which tries to interpret locations should probably be designed to
+ * ignore those that it doesn't understand, as more types of locations could
+ * be recorded in the future.
+ * </pre>
+ *
+ * <code>repeated .google.protobuf.SourceCodeInfo.Location location = 1;</code>
+ */
+ public function setLocation(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\SourceCodeInfo_Location::class);
+ $this->location = $arr;
+ $this->has_location = true;
+ }
+
+ public function hasLocation()
+ {
+ return $this->has_location;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php
new file mode 100644
index 0000000000..5a02b26c41
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php
@@ -0,0 +1,379 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * Protobuf type <code>google.protobuf.SourceCodeInfo.Location</code>
+ */
+class SourceCodeInfo_Location extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <pre>
+ * Identifies which part of the FileDescriptorProto was defined at this
+ * location.
+ * Each element is a field number or an index. They form a path from
+ * the root FileDescriptorProto to the place where the definition. For
+ * example, this path:
+ * [ 4, 3, 2, 7, 1 ]
+ * refers to:
+ * file.message_type(3) // 4, 3
+ * .field(7) // 2, 7
+ * .name() // 1
+ * This is because FileDescriptorProto.message_type has field number 4:
+ * repeated DescriptorProto message_type = 4;
+ * and DescriptorProto.field has field number 2:
+ * repeated FieldDescriptorProto field = 2;
+ * and FieldDescriptorProto.name has field number 1:
+ * optional string name = 1;
+ * Thus, the above path gives the location of a field name. If we removed
+ * the last element:
+ * [ 4, 3, 2, 7 ]
+ * this path refers to the whole field declaration (from the beginning
+ * of the label to the terminating semicolon).
+ * </pre>
+ *
+ * <code>repeated int32 path = 1 [packed = true];</code>
+ */
+ private $path;
+ private $has_path = false;
+ /**
+ * <pre>
+ * Always has exactly three or four elements: start line, start column,
+ * end line (optional, otherwise assumed same as start line), end column.
+ * These are packed into a single field for efficiency. Note that line
+ * and column numbers are zero-based -- typically you will want to add
+ * 1 to each before displaying to a user.
+ * </pre>
+ *
+ * <code>repeated int32 span = 2 [packed = true];</code>
+ */
+ private $span;
+ private $has_span = false;
+ /**
+ * <pre>
+ * If this SourceCodeInfo represents a complete declaration, these are any
+ * comments appearing before and after the declaration which appear to be
+ * attached to the declaration.
+ * A series of line comments appearing on consecutive lines, with no other
+ * tokens appearing on those lines, will be treated as a single comment.
+ * leading_detached_comments will keep paragraphs of comments that appear
+ * before (but not connected to) the current element. Each paragraph,
+ * separated by empty lines, will be one comment element in the repeated
+ * field.
+ * Only the comment content is provided; comment markers (e.g. //) are
+ * stripped out. For block comments, leading whitespace and an asterisk
+ * will be stripped from the beginning of each line other than the first.
+ * Newlines are included in the output.
+ * Examples:
+ * optional int32 foo = 1; // Comment attached to foo.
+ * // Comment attached to bar.
+ * optional int32 bar = 2;
+ * optional string baz = 3;
+ * // Comment attached to baz.
+ * // Another line attached to baz.
+ * // Comment attached to qux.
+ * //
+ * // Another line attached to qux.
+ * optional double qux = 4;
+ * // Detached comment for corge. This is not leading or trailing comments
+ * // to qux or corge because there are blank lines separating it from
+ * // both.
+ * // Detached comment for corge paragraph 2.
+ * optional string corge = 5;
+ * /&#42; Block comment attached
+ * * to corge. Leading asterisks
+ * * will be removed. *&#47;
+ * /&#42; Block comment attached to
+ * * grault. *&#47;
+ * optional int32 grault = 6;
+ * // ignored detached comments.
+ * </pre>
+ *
+ * <code>optional string leading_comments = 3;</code>
+ */
+ private $leading_comments = '';
+ private $has_leading_comments = false;
+ /**
+ * <code>optional string trailing_comments = 4;</code>
+ */
+ private $trailing_comments = '';
+ private $has_trailing_comments = false;
+ /**
+ * <code>repeated string leading_detached_comments = 6;</code>
+ */
+ private $leading_detached_comments;
+ private $has_leading_detached_comments = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <pre>
+ * Identifies which part of the FileDescriptorProto was defined at this
+ * location.
+ * Each element is a field number or an index. They form a path from
+ * the root FileDescriptorProto to the place where the definition. For
+ * example, this path:
+ * [ 4, 3, 2, 7, 1 ]
+ * refers to:
+ * file.message_type(3) // 4, 3
+ * .field(7) // 2, 7
+ * .name() // 1
+ * This is because FileDescriptorProto.message_type has field number 4:
+ * repeated DescriptorProto message_type = 4;
+ * and DescriptorProto.field has field number 2:
+ * repeated FieldDescriptorProto field = 2;
+ * and FieldDescriptorProto.name has field number 1:
+ * optional string name = 1;
+ * Thus, the above path gives the location of a field name. If we removed
+ * the last element:
+ * [ 4, 3, 2, 7 ]
+ * this path refers to the whole field declaration (from the beginning
+ * of the label to the terminating semicolon).
+ * </pre>
+ *
+ * <code>repeated int32 path = 1 [packed = true];</code>
+ */
+ public function getPath()
+ {
+ return $this->path;
+ }
+
+ /**
+ * <pre>
+ * Identifies which part of the FileDescriptorProto was defined at this
+ * location.
+ * Each element is a field number or an index. They form a path from
+ * the root FileDescriptorProto to the place where the definition. For
+ * example, this path:
+ * [ 4, 3, 2, 7, 1 ]
+ * refers to:
+ * file.message_type(3) // 4, 3
+ * .field(7) // 2, 7
+ * .name() // 1
+ * This is because FileDescriptorProto.message_type has field number 4:
+ * repeated DescriptorProto message_type = 4;
+ * and DescriptorProto.field has field number 2:
+ * repeated FieldDescriptorProto field = 2;
+ * and FieldDescriptorProto.name has field number 1:
+ * optional string name = 1;
+ * Thus, the above path gives the location of a field name. If we removed
+ * the last element:
+ * [ 4, 3, 2, 7 ]
+ * this path refers to the whole field declaration (from the beginning
+ * of the label to the terminating semicolon).
+ * </pre>
+ *
+ * <code>repeated int32 path = 1 [packed = true];</code>
+ */
+ public function setPath(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
+ $this->path = $arr;
+ $this->has_path = true;
+ }
+
+ public function hasPath()
+ {
+ return $this->has_path;
+ }
+
+ /**
+ * <pre>
+ * Always has exactly three or four elements: start line, start column,
+ * end line (optional, otherwise assumed same as start line), end column.
+ * These are packed into a single field for efficiency. Note that line
+ * and column numbers are zero-based -- typically you will want to add
+ * 1 to each before displaying to a user.
+ * </pre>
+ *
+ * <code>repeated int32 span = 2 [packed = true];</code>
+ */
+ public function getSpan()
+ {
+ return $this->span;
+ }
+
+ /**
+ * <pre>
+ * Always has exactly three or four elements: start line, start column,
+ * end line (optional, otherwise assumed same as start line), end column.
+ * These are packed into a single field for efficiency. Note that line
+ * and column numbers are zero-based -- typically you will want to add
+ * 1 to each before displaying to a user.
+ * </pre>
+ *
+ * <code>repeated int32 span = 2 [packed = true];</code>
+ */
+ public function setSpan(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::INT32);
+ $this->span = $arr;
+ $this->has_span = true;
+ }
+
+ public function hasSpan()
+ {
+ return $this->has_span;
+ }
+
+ /**
+ * <pre>
+ * If this SourceCodeInfo represents a complete declaration, these are any
+ * comments appearing before and after the declaration which appear to be
+ * attached to the declaration.
+ * A series of line comments appearing on consecutive lines, with no other
+ * tokens appearing on those lines, will be treated as a single comment.
+ * leading_detached_comments will keep paragraphs of comments that appear
+ * before (but not connected to) the current element. Each paragraph,
+ * separated by empty lines, will be one comment element in the repeated
+ * field.
+ * Only the comment content is provided; comment markers (e.g. //) are
+ * stripped out. For block comments, leading whitespace and an asterisk
+ * will be stripped from the beginning of each line other than the first.
+ * Newlines are included in the output.
+ * Examples:
+ * optional int32 foo = 1; // Comment attached to foo.
+ * // Comment attached to bar.
+ * optional int32 bar = 2;
+ * optional string baz = 3;
+ * // Comment attached to baz.
+ * // Another line attached to baz.
+ * // Comment attached to qux.
+ * //
+ * // Another line attached to qux.
+ * optional double qux = 4;
+ * // Detached comment for corge. This is not leading or trailing comments
+ * // to qux or corge because there are blank lines separating it from
+ * // both.
+ * // Detached comment for corge paragraph 2.
+ * optional string corge = 5;
+ * /&#42; Block comment attached
+ * * to corge. Leading asterisks
+ * * will be removed. *&#47;
+ * /&#42; Block comment attached to
+ * * grault. *&#47;
+ * optional int32 grault = 6;
+ * // ignored detached comments.
+ * </pre>
+ *
+ * <code>optional string leading_comments = 3;</code>
+ */
+ public function getLeadingComments()
+ {
+ return $this->leading_comments;
+ }
+
+ /**
+ * <pre>
+ * If this SourceCodeInfo represents a complete declaration, these are any
+ * comments appearing before and after the declaration which appear to be
+ * attached to the declaration.
+ * A series of line comments appearing on consecutive lines, with no other
+ * tokens appearing on those lines, will be treated as a single comment.
+ * leading_detached_comments will keep paragraphs of comments that appear
+ * before (but not connected to) the current element. Each paragraph,
+ * separated by empty lines, will be one comment element in the repeated
+ * field.
+ * Only the comment content is provided; comment markers (e.g. //) are
+ * stripped out. For block comments, leading whitespace and an asterisk
+ * will be stripped from the beginning of each line other than the first.
+ * Newlines are included in the output.
+ * Examples:
+ * optional int32 foo = 1; // Comment attached to foo.
+ * // Comment attached to bar.
+ * optional int32 bar = 2;
+ * optional string baz = 3;
+ * // Comment attached to baz.
+ * // Another line attached to baz.
+ * // Comment attached to qux.
+ * //
+ * // Another line attached to qux.
+ * optional double qux = 4;
+ * // Detached comment for corge. This is not leading or trailing comments
+ * // to qux or corge because there are blank lines separating it from
+ * // both.
+ * // Detached comment for corge paragraph 2.
+ * optional string corge = 5;
+ * /&#42; Block comment attached
+ * * to corge. Leading asterisks
+ * * will be removed. *&#47;
+ * /&#42; Block comment attached to
+ * * grault. *&#47;
+ * optional int32 grault = 6;
+ * // ignored detached comments.
+ * </pre>
+ *
+ * <code>optional string leading_comments = 3;</code>
+ */
+ public function setLeadingComments($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->leading_comments = $var;
+ $this->has_leading_comments = true;
+ }
+
+ public function hasLeadingComments()
+ {
+ return $this->has_leading_comments;
+ }
+
+ /**
+ * <code>optional string trailing_comments = 4;</code>
+ */
+ public function getTrailingComments()
+ {
+ return $this->trailing_comments;
+ }
+
+ /**
+ * <code>optional string trailing_comments = 4;</code>
+ */
+ public function setTrailingComments($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->trailing_comments = $var;
+ $this->has_trailing_comments = true;
+ }
+
+ public function hasTrailingComments()
+ {
+ return $this->has_trailing_comments;
+ }
+
+ /**
+ * <code>repeated string leading_detached_comments = 6;</code>
+ */
+ public function getLeadingDetachedComments()
+ {
+ return $this->leading_detached_comments;
+ }
+
+ /**
+ * <code>repeated string leading_detached_comments = 6;</code>
+ */
+ public function setLeadingDetachedComments(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING);
+ $this->leading_detached_comments = $arr;
+ $this->has_leading_detached_comments = true;
+ }
+
+ public function hasLeadingDetachedComments()
+ {
+ return $this->has_leading_detached_comments;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/UninterpretedOption.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/UninterpretedOption.php
new file mode 100644
index 0000000000..286550198e
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/UninterpretedOption.php
@@ -0,0 +1,246 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * <pre>
+ * A message representing a option the parser does not recognize. This only
+ * appears in options protos created by the compiler::Parser class.
+ * DescriptorPool resolves these when building Descriptor objects. Therefore,
+ * options protos in descriptor objects (e.g. returned by Descriptor::options(),
+ * or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
+ * in them.
+ * </pre>
+ *
+ * Protobuf type <code>google.protobuf.UninterpretedOption</code>
+ */
+class UninterpretedOption extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <code>repeated .google.protobuf.UninterpretedOption.NamePart name = 2;</code>
+ */
+ private $name;
+ private $has_name = false;
+ /**
+ * <pre>
+ * The value of the uninterpreted option, in whatever type the tokenizer
+ * identified it as during parsing. Exactly one of these should be set.
+ * </pre>
+ *
+ * <code>optional string identifier_value = 3;</code>
+ */
+ private $identifier_value = '';
+ private $has_identifier_value = false;
+ /**
+ * <code>optional uint64 positive_int_value = 4;</code>
+ */
+ private $positive_int_value = 0;
+ private $has_positive_int_value = false;
+ /**
+ * <code>optional int64 negative_int_value = 5;</code>
+ */
+ private $negative_int_value = 0;
+ private $has_negative_int_value = false;
+ /**
+ * <code>optional double double_value = 6;</code>
+ */
+ private $double_value = 0.0;
+ private $has_double_value = false;
+ /**
+ * <code>optional bytes string_value = 7;</code>
+ */
+ private $string_value = '';
+ private $has_string_value = false;
+ /**
+ * <code>optional string aggregate_value = 8;</code>
+ */
+ private $aggregate_value = '';
+ private $has_aggregate_value = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <code>repeated .google.protobuf.UninterpretedOption.NamePart name = 2;</code>
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * <code>repeated .google.protobuf.UninterpretedOption.NamePart name = 2;</code>
+ */
+ public function setName(&$var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Internal\UninterpretedOption_NamePart::class);
+ $this->name = $arr;
+ $this->has_name = true;
+ }
+
+ public function hasName()
+ {
+ return $this->has_name;
+ }
+
+ /**
+ * <pre>
+ * The value of the uninterpreted option, in whatever type the tokenizer
+ * identified it as during parsing. Exactly one of these should be set.
+ * </pre>
+ *
+ * <code>optional string identifier_value = 3;</code>
+ */
+ public function getIdentifierValue()
+ {
+ return $this->identifier_value;
+ }
+
+ /**
+ * <pre>
+ * The value of the uninterpreted option, in whatever type the tokenizer
+ * identified it as during parsing. Exactly one of these should be set.
+ * </pre>
+ *
+ * <code>optional string identifier_value = 3;</code>
+ */
+ public function setIdentifierValue($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->identifier_value = $var;
+ $this->has_identifier_value = true;
+ }
+
+ public function hasIdentifierValue()
+ {
+ return $this->has_identifier_value;
+ }
+
+ /**
+ * <code>optional uint64 positive_int_value = 4;</code>
+ */
+ public function getPositiveIntValue()
+ {
+ return $this->positive_int_value;
+ }
+
+ /**
+ * <code>optional uint64 positive_int_value = 4;</code>
+ */
+ public function setPositiveIntValue($var)
+ {
+ GPBUtil::checkUint64($var);
+ $this->positive_int_value = $var;
+ $this->has_positive_int_value = true;
+ }
+
+ public function hasPositiveIntValue()
+ {
+ return $this->has_positive_int_value;
+ }
+
+ /**
+ * <code>optional int64 negative_int_value = 5;</code>
+ */
+ public function getNegativeIntValue()
+ {
+ return $this->negative_int_value;
+ }
+
+ /**
+ * <code>optional int64 negative_int_value = 5;</code>
+ */
+ public function setNegativeIntValue($var)
+ {
+ GPBUtil::checkInt64($var);
+ $this->negative_int_value = $var;
+ $this->has_negative_int_value = true;
+ }
+
+ public function hasNegativeIntValue()
+ {
+ return $this->has_negative_int_value;
+ }
+
+ /**
+ * <code>optional double double_value = 6;</code>
+ */
+ public function getDoubleValue()
+ {
+ return $this->double_value;
+ }
+
+ /**
+ * <code>optional double double_value = 6;</code>
+ */
+ public function setDoubleValue($var)
+ {
+ GPBUtil::checkDouble($var);
+ $this->double_value = $var;
+ $this->has_double_value = true;
+ }
+
+ public function hasDoubleValue()
+ {
+ return $this->has_double_value;
+ }
+
+ /**
+ * <code>optional bytes string_value = 7;</code>
+ */
+ public function getStringValue()
+ {
+ return $this->string_value;
+ }
+
+ /**
+ * <code>optional bytes string_value = 7;</code>
+ */
+ public function setStringValue($var)
+ {
+ GPBUtil::checkString($var, False);
+ $this->string_value = $var;
+ $this->has_string_value = true;
+ }
+
+ public function hasStringValue()
+ {
+ return $this->has_string_value;
+ }
+
+ /**
+ * <code>optional string aggregate_value = 8;</code>
+ */
+ public function getAggregateValue()
+ {
+ return $this->aggregate_value;
+ }
+
+ /**
+ * <code>optional string aggregate_value = 8;</code>
+ */
+ public function setAggregateValue($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->aggregate_value = $var;
+ $this->has_aggregate_value = true;
+ }
+
+ public function hasAggregateValue()
+ {
+ return $this->has_aggregate_value;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php b/third_party/protobuf/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php
new file mode 100644
index 0000000000..86484d23c1
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php
@@ -0,0 +1,90 @@
+<?php
+# Generated by the protocol buffer compiler. DO NOT EDIT!
+# source: google/protobuf/descriptor.proto
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\InputStream;
+
+use Google\Protobuf\Internal\GPBUtil;
+
+/**
+ * <pre>
+ * The name of the uninterpreted option. Each string represents a segment in
+ * a dot-separated name. is_extension is true iff a segment represents an
+ * extension (denoted with parentheses in options specs in .proto files).
+ * E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
+ * "foo.(bar.baz).qux".
+ * </pre>
+ *
+ * Protobuf type <code>google.protobuf.UninterpretedOption.NamePart</code>
+ */
+class UninterpretedOption_NamePart extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * <code>required string name_part = 1;</code>
+ */
+ private $name_part = '';
+ private $has_name_part = false;
+ /**
+ * <code>required bool is_extension = 2;</code>
+ */
+ private $is_extension = false;
+ private $has_is_extension = false;
+
+ public function __construct() {
+ \GPBMetadata\Google\Protobuf\Internal\Descriptor::initOnce();
+ parent::__construct();
+ }
+
+ /**
+ * <code>required string name_part = 1;</code>
+ */
+ public function getNamePart()
+ {
+ return $this->name_part;
+ }
+
+ /**
+ * <code>required string name_part = 1;</code>
+ */
+ public function setNamePart($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->name_part = $var;
+ $this->has_name_part = true;
+ }
+
+ public function hasNamePart()
+ {
+ return $this->has_name_part;
+ }
+
+ /**
+ * <code>required bool is_extension = 2;</code>
+ */
+ public function getIsExtension()
+ {
+ return $this->is_extension;
+ }
+
+ /**
+ * <code>required bool is_extension = 2;</code>
+ */
+ public function setIsExtension($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->is_extension = $var;
+ $this->has_is_extension = true;
+ }
+
+ public function hasIsExtension()
+ {
+ return $this->has_is_extension;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/src/Google/Protobuf/descriptor.php b/third_party/protobuf/php/src/Google/Protobuf/descriptor.php
new file mode 100644
index 0000000000..2263af6ed1
--- /dev/null
+++ b/third_party/protobuf/php/src/Google/Protobuf/descriptor.php
@@ -0,0 +1,565 @@
+<?php
+
+// 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.
+
+namespace Google\Protobuf\Internal;
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\MessageOptions;
+
+class FileDescriptor
+{
+
+ private $package;
+ private $message_type = [];
+ private $enum_type = [];
+
+ public function setPackage($package)
+ {
+ $this->package = $package;
+ }
+
+ public function getPackage()
+ {
+ return $this->package;
+ }
+
+ public function getMessageType()
+ {
+ return $this->message_type;
+ }
+
+ public function addMessageType($desc)
+ {
+ $this->message_type[] = $desc;
+ }
+
+ public function getEnumType()
+ {
+ return $this->enum_type;
+ }
+
+ public function addEnumType($desc)
+ {
+ $this->enum_type[]= $desc;
+ }
+
+ public static function buildFromProto($proto)
+ {
+ $file = new FileDescriptor();
+ $file->setPackage($proto->getPackage());
+ foreach ($proto->getMessageType() as $message_proto) {
+ $file->addMessageType(Descriptor::buildFromProto(
+ $message_proto, $proto, ""));
+ }
+ foreach ($proto->getEnumType() as $enum_proto) {
+ $file->getEnumType()[] =
+ $file->addEnumType(
+ EnumDescriptor::buildFromProto(
+ $enum_proto,
+ $proto,
+ ""));
+ }
+ return $file;
+ }
+}
+
+class Descriptor
+{
+
+ private $full_name;
+ private $field = [];
+ private $nested_type = [];
+ private $enum_type = [];
+ private $klass;
+ private $options;
+ private $oneof_decl = [];
+
+ public function addOneofDecl($oneof)
+ {
+ $this->oneof_decl[] = $oneof;
+ }
+
+ public function getOneofDecl()
+ {
+ return $this->oneof_decl;
+ }
+
+ public function setFullName($full_name)
+ {
+ $this->full_name = $full_name;
+ }
+
+ public function getFullName()
+ {
+ return $this->full_name;
+ }
+
+ public function addField($field)
+ {
+ $this->field[$field->getNumber()] = $field;
+ }
+
+ public function getField()
+ {
+ return $this->field;
+ }
+
+ public function addNestedType($desc)
+ {
+ $this->nested_type[] = $desc;
+ }
+
+ public function getNestedType()
+ {
+ return $this->nested_type;
+ }
+
+ public function addEnumType($desc)
+ {
+ $this->enum_type[] = $desc;
+ }
+
+ public function getEnumType()
+ {
+ return $this->enum_type;
+ }
+
+ public function getFieldByNumber($number)
+ {
+ if (!isset($this->field[$number])) {
+ return NULL;
+ } else {
+ return $this->field[$number];
+ }
+ }
+
+ public function setClass($klass)
+ {
+ $this->klass = $klass;
+ }
+
+ public function getClass()
+ {
+ return $this->klass;
+ }
+
+ public function setOptions($options)
+ {
+ $this->options = $options;
+ }
+
+ public function getOptions()
+ {
+ return $this->options;
+ }
+
+ public static function buildFromProto($proto, $file_proto, $containing)
+ {
+ $desc = new Descriptor();
+
+ $message_name_without_package = "";
+ $classname = "";
+ $fullname = "";
+ getFullClassName(
+ $proto,
+ $containing,
+ $file_proto,
+ $message_name_without_package,
+ $classname,
+ $fullname);
+ $desc->setFullName($fullname);
+ $desc->setClass($classname);
+ $desc->setOptions($proto->getOptions());
+
+ foreach ($proto->getField() as $field_proto) {
+ $desc->addField(FieldDescriptor::buildFromProto($field_proto));
+ }
+
+ // Handle nested types.
+ foreach ($proto->getNestedType() as $nested_proto) {
+ $desc->addNestedType(Descriptor::buildFromProto(
+ $nested_proto, $file_proto, $message_name_without_package));
+ }
+
+ // Handle oneof fields.
+ foreach ($proto->getOneofDecl() as $oneof_proto) {
+ $desc->addOneofDecl(
+ OneofDescriptor::buildFromProto($oneof_proto, $desc));
+ }
+
+ return $desc;
+ }
+}
+
+function getClassNameWithoutPackage(
+ $name,
+ $file_proto)
+{
+ if ($name === "Empty" && $file_proto->getPackage() === "google.protobuf") {
+ return "GPBEmpty";
+ } else {
+ $option = $file_proto->getOptions();
+ $prefix = is_null($option) ? "" : $option->getPhpClassPrefix();
+ // Nested message class names are seperated by '_', and package names
+ // are seperated by '\'.
+ return $prefix . implode('_', array_map('ucwords',
+ explode('.', $name)));
+ }
+}
+
+function getFullClassName(
+ $proto,
+ $containing,
+ $file_proto,
+ &$message_name_without_package,
+ &$classname,
+ &$fullname)
+{
+ // Full name needs to start with '.'.
+ $message_name_without_package = $proto->getName();
+ if ($containing !== "") {
+ $message_name_without_package =
+ $containing . "." . $message_name_without_package;
+ }
+
+ $package = $file_proto->getPackage();
+ if ($package === "") {
+ $fullname = "." . $message_name_without_package;
+ } else {
+ $fullname = "." . $package . "." . $message_name_without_package;
+ }
+
+ $class_name_without_package =
+ getClassNameWithoutPackage($message_name_without_package, $file_proto);
+ if ($package === "") {
+ $classname = $class_name_without_package;
+ } else {
+ $classname =
+ implode('\\', array_map('ucwords', explode('.', $package))).
+ "\\".$class_name_without_package;
+ }
+}
+
+class OneofDescriptor
+{
+
+ private $name;
+ private $fields;
+
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ public function addField(&$field)
+ {
+ $this->fields[] = $field;
+ }
+
+ public function getFields()
+ {
+ return $this->fields;
+ }
+
+ public static function buildFromProto($oneof_proto)
+ {
+ $oneof = new OneofDescriptor();
+ $oneof->setName($oneof_proto->getName());
+ return $oneof;
+ }
+}
+
+
+class EnumDescriptor
+{
+
+ private $klass;
+ private $full_name;
+ private $value;
+
+ public function setFullName($full_name)
+ {
+ $this->full_name = $full_name;
+ }
+
+ public function getFullName()
+ {
+ return $this->full_name;
+ }
+
+ public function addValue($number, $value)
+ {
+ $this->value[$number] = $value;
+ }
+
+ public function setClass($klass)
+ {
+ $this->klass = $klass;
+ }
+
+ public function getClass()
+ {
+ return $this->klass;
+ }
+
+ public static function buildFromProto($proto, $file_proto, $containing)
+ {
+ $desc = new EnumDescriptor();
+
+ $enum_name_without_package = "";
+ $classname = "";
+ $fullname = "";
+ getFullClassName(
+ $proto,
+ $containing,
+ $file_proto,
+ $enum_name_without_package,
+ $classname,
+ $fullname);
+ $desc->setFullName($fullname);
+ $desc->setClass($classname);
+
+ return $desc;
+ }
+}
+
+class EnumValueDescriptor
+{
+}
+
+class FieldDescriptor
+{
+
+ private $name;
+ private $setter;
+ private $getter;
+ private $number;
+ private $label;
+ private $type;
+ private $message_type;
+ private $enum_type;
+ private $packed;
+ private $is_map;
+ private $oneof_index = -1;
+
+ public function setOneofIndex($index)
+ {
+ $this->oneof_index = $index;
+ }
+
+ public function getOneofIndex()
+ {
+ return $this->oneof_index;
+ }
+
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ public function setSetter($setter)
+ {
+ $this->setter = $setter;
+ }
+
+ public function getSetter()
+ {
+ return $this->setter;
+ }
+
+ public function setGetter($getter)
+ {
+ $this->getter = $getter;
+ }
+
+ public function getGetter()
+ {
+ return $this->getter;
+ }
+
+ public function setNumber($number)
+ {
+ $this->number = $number;
+ }
+
+ public function getNumber()
+ {
+ return $this->number;
+ }
+
+ public function setLabel($label)
+ {
+ $this->label = $label;
+ }
+
+ public function getLabel()
+ {
+ return $this->label;
+ }
+
+ public function isRepeated()
+ {
+ return $this->label === GPBLabel::REPEATED;
+ }
+
+ public function setType($type)
+ {
+ $this->type = $type;
+ }
+
+ public function getType()
+ {
+ return $this->type;
+ }
+
+ public function setMessageType($message_type)
+ {
+ $this->message_type = $message_type;
+ }
+
+ public function getMessageType()
+ {
+ return $this->message_type;
+ }
+
+ public function setEnumType($enum_type)
+ {
+ $this->enum_type = $enum_type;
+ }
+
+ public function getEnumType()
+ {
+ return $this->enum_type;
+ }
+
+ public function setPacked($packed)
+ {
+ $this->packed = $packed;
+ }
+
+ public function getPacked()
+ {
+ return $this->packed;
+ }
+
+ public function isPackable()
+ {
+ return $this->isRepeated() && self::isTypePackable($this->type);
+ }
+
+ public function isMap()
+ {
+ return $this->getType() == GPBType::MESSAGE &&
+ !is_null($this->getMessageType()->getOptions()) &&
+ $this->getMessageType()->getOptions()->getMapEntry();
+ }
+
+ private static function isTypePackable($field_type)
+ {
+ return ($field_type !== GPBType::STRING &&
+ $field_type !== GPBType::GROUP &&
+ $field_type !== GPBType::MESSAGE &&
+ $field_type !== GPBType::BYTES);
+ }
+
+ public static function getFieldDescriptor(
+ $name,
+ $label,
+ $type,
+ $number,
+ $oneof_index,
+ $packed,
+ $type_name = null)
+ {
+ $field = new FieldDescriptor();
+ $field->setName($name);
+ $camel_name = implode('', array_map('ucwords', explode('_', $name)));
+ $field->setGetter('get' . $camel_name);
+ $field->setSetter('set' . $camel_name);
+ $field->setType($type);
+ $field->setNumber($number);
+ $field->setLabel($label);
+ $field->setPacked($packed);
+ $field->setOneofIndex($oneof_index);
+
+ // At this time, the message/enum type may have not been added to pool.
+ // So we use the type name as place holder and will replace it with the
+ // actual descriptor in cross building.
+ switch ($type) {
+ case GPBType::MESSAGE:
+ $field->setMessageType($type_name);
+ break;
+ case GPBType::ENUM:
+ $field->setEnumType($type_name);
+ break;
+ default:
+ break;
+ }
+
+ return $field;
+ }
+
+ public static function buildFromProto($proto)
+ {
+ $type_name = null;
+ switch ($proto->getType()) {
+ case GPBType::MESSAGE:
+ case GPBType::GROUP:
+ case GPBType::ENUM:
+ $type_name = $proto->getTypeName();
+ break;
+ default:
+ break;
+ }
+
+ $oneof_index = $proto->hasOneofIndex() ? $proto->getOneofIndex() : -1;
+ $packed = false;
+ $options = $proto->getOptions();
+ if ($options !== null) {
+ $packed = $options->getPacked();
+ }
+
+ return FieldDescriptor::getFieldDescriptor(
+ $proto->getName(), $proto->getLabel(), $proto->getType(),
+ $proto->getNumber(), $oneof_index, $packed, $type_name);
+ }
+}
diff --git a/third_party/protobuf/php/src/phpdoc.dist.xml b/third_party/protobuf/php/src/phpdoc.dist.xml
new file mode 100644
index 0000000000..dd3130253f
--- /dev/null
+++ b/third_party/protobuf/php/src/phpdoc.dist.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!-- Install phpDocumentor to generate docs. -->
+<phpdoc>
+ <parser>
+ <target>doc</target>
+ </parser>
+ <transformer>
+ <target>doc</target>
+ </transformer>
+ <files>
+ <file>Google/Protobuf/Internal/MapField.php</file>
+ <file>Google/Protobuf/Internal/Message.php</file>
+ <file>Google/Protobuf/Internal/RepeatedField.php</file>
+ </files>
+</phpdoc>
diff --git a/third_party/protobuf/php/tests/array_test.php b/third_party/protobuf/php/tests/array_test.php
new file mode 100644
index 0000000000..a4cad7196c
--- /dev/null
+++ b/third_party/protobuf/php/tests/array_test.php
@@ -0,0 +1,939 @@
+<?php
+
+require_once('test_util.php');
+
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\GPBType;
+use Foo\TestMessage;
+use Foo\TestMessage_Sub;
+
+class RepeatedFieldTest extends PHPUnit_Framework_TestCase
+{
+
+ #########################################################
+ # Test int32 field.
+ #########################################################
+
+ public function testInt32()
+ {
+ $arr = new RepeatedField(GPBType::INT32);
+
+ // Test append.
+ $arr []= MAX_INT32;
+ $this->assertSame(MAX_INT32, $arr[0]);
+ $arr []= MIN_INT32;
+ $this->assertSame(MIN_INT32, $arr[1]);
+
+ $arr []= 1.1;
+ $this->assertSame(1, $arr[2]);
+ $arr []= MAX_INT32_FLOAT;
+ $this->assertSame(MAX_INT32, $arr[3]);
+ $arr []= MAX_INT32_FLOAT;
+ $this->assertSame(MAX_INT32, $arr[4]);
+
+ $arr []= '2';
+ $this->assertSame(2, $arr[5]);
+ $arr []= '3.1';
+ $this->assertSame(3, $arr[6]);
+ $arr []= MAX_INT32_STRING;
+ $this->assertSame(MAX_INT32, $arr[7]);
+
+ $this->assertEquals(8, count($arr));
+
+ for ($i = 0; $i < count($arr); $i++) {
+ $arr[$i] = 0;
+ $this->assertSame(0, $arr[$i]);
+ }
+
+ // Test set.
+ $arr [0]= MAX_INT32;
+ $this->assertSame(MAX_INT32, $arr[0]);
+ $arr [1]= MIN_INT32;
+ $this->assertSame(MIN_INT32, $arr[1]);
+
+ $arr [2]= 1.1;
+ $this->assertSame(1, $arr[2]);
+ $arr [3]= MAX_INT32_FLOAT;
+ $this->assertSame(MAX_INT32, $arr[3]);
+ $arr [4]= MAX_INT32_FLOAT;
+ $this->assertSame(MAX_INT32, $arr[4]);
+
+ $arr [5]= '2';
+ $this->assertSame(2, $arr[5]);
+ $arr [6]= '3.1';
+ $this->assertSame(3, $arr[6]);
+ $arr [7]= MAX_INT32_STRING;
+ $this->assertSame(MAX_INT32, $arr[7]);
+
+ // Test foreach.
+ $arr = new RepeatedField(GPBType::INT32);
+ for ($i = 0; $i < 3; $i++) {
+ $arr []= $i;
+ }
+ $i = 0;
+ foreach ($arr as $val) {
+ $this->assertSame($i++, $val);
+ }
+ $this->assertSame(3, $i);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt32AppendStringFail()
+ {
+ $arr = new RepeatedField(GPBType::INT32);
+ $arr []= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt32SetStringFail()
+ {
+ $arr = new RepeatedField(GPBType::INT32);
+ $arr []= 0;
+ $arr [0]= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt32AppendMessageFail()
+ {
+ $arr = new RepeatedField(GPBType::INT32);
+ $arr []= new TestMessage_Sub();
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt32SetMessageFail()
+ {
+ $arr = new RepeatedField(GPBType::INT32);
+ $arr []= 0;
+ $arr [0]= new TestMessage_Sub();
+ }
+
+ #########################################################
+ # Test uint32 field.
+ #########################################################
+
+ public function testUint32()
+ {
+ $arr = new RepeatedField(GPBType::UINT32);
+
+ // Test append.
+ $arr []= MAX_UINT32;
+ $this->assertSame(-1, $arr[0]);
+ $arr []= -1;
+ $this->assertSame(-1, $arr[1]);
+ $arr []= MIN_UINT32;
+ $this->assertSame(MIN_UINT32, $arr[2]);
+
+ $arr []= 1.1;
+ $this->assertSame(1, $arr[3]);
+ $arr []= MAX_UINT32_FLOAT;
+ $this->assertSame(-1, $arr[4]);
+ $arr []= -1.0;
+ $this->assertSame(-1, $arr[5]);
+ $arr []= MIN_UINT32_FLOAT;
+ $this->assertSame(MIN_UINT32, $arr[6]);
+
+ $arr []= '2';
+ $this->assertSame(2, $arr[7]);
+ $arr []= '3.1';
+ $this->assertSame(3, $arr[8]);
+ $arr []= MAX_UINT32_STRING;
+ $this->assertSame(-1, $arr[9]);
+ $arr []= '-1.0';
+ $this->assertSame(-1, $arr[10]);
+ $arr []= MIN_UINT32_STRING;
+ $this->assertSame(MIN_UINT32, $arr[11]);
+
+ $this->assertEquals(12, count($arr));
+
+ for ($i = 0; $i < count($arr); $i++) {
+ $arr[$i] = 0;
+ $this->assertSame(0, $arr[$i]);
+ }
+
+ // Test set.
+ $arr [0]= MAX_UINT32;
+ $this->assertSame(-1, $arr[0]);
+ $arr [1]= -1;
+ $this->assertSame(-1, $arr[1]);
+ $arr [2]= MIN_UINT32;
+ $this->assertSame(MIN_UINT32, $arr[2]);
+
+ $arr [3]= 1.1;
+ $this->assertSame(1, $arr[3]);
+ $arr [4]= MAX_UINT32_FLOAT;
+ $this->assertSame(-1, $arr[4]);
+ $arr [5]= -1.0;
+ $this->assertSame(-1, $arr[5]);
+ $arr [6]= MIN_UINT32_FLOAT;
+ $this->assertSame(MIN_UINT32, $arr[6]);
+
+ $arr [7]= '2';
+ $this->assertSame(2, $arr[7]);
+ $arr [8]= '3.1';
+ $this->assertSame(3, $arr[8]);
+ $arr [9]= MAX_UINT32_STRING;
+ $this->assertSame(-1, $arr[9]);
+ $arr [10]= '-1.0';
+ $this->assertSame(-1, $arr[10]);
+ $arr [11]= MIN_UINT32_STRING;
+ $this->assertSame(MIN_UINT32, $arr[11]);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint32AppendStringFail()
+ {
+ $arr = new RepeatedField(GPBType::UINT32);
+ $arr []= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint32SetStringFail()
+ {
+ $arr = new RepeatedField(GPBType::UINT32);
+ $arr []= 0;
+ $arr [0]= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint32AppendMessageFail()
+ {
+ $arr = new RepeatedField(GPBType::UINT32);
+ $arr []= new TestMessage_Sub();
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint32SetMessageFail()
+ {
+ $arr = new RepeatedField(GPBType::UINT32);
+ $arr []= 0;
+ $arr [0]= new TestMessage_Sub();
+ }
+
+ #########################################################
+ # Test int64 field.
+ #########################################################
+
+ public function testInt64()
+ {
+ $arr = new RepeatedField(GPBType::INT64);
+
+ // Test append.
+ $arr []= MAX_INT64;
+ $arr []= MIN_INT64;
+ $arr []= 1.1;
+ $arr []= '2';
+ $arr []= '3.1';
+ $arr []= MAX_INT64_STRING;
+ $arr []= MIN_INT64_STRING;
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame(MAX_INT64, $arr[0]);
+ $this->assertSame(MIN_INT64, $arr[1]);
+ $this->assertSame('1', $arr[2]);
+ $this->assertSame('2', $arr[3]);
+ $this->assertSame('3', $arr[4]);
+ $this->assertSame(MAX_INT64_STRING, $arr[5]);
+ $this->assertSame(MIN_INT64_STRING, $arr[6]);
+ } else {
+ $this->assertSame(MAX_INT64, $arr[0]);
+ $this->assertSame(MIN_INT64, $arr[1]);
+ $this->assertSame(1, $arr[2]);
+ $this->assertSame(2, $arr[3]);
+ $this->assertSame(3, $arr[4]);
+ $this->assertSame(MAX_INT64, $arr[5]);
+ $this->assertSame(MIN_INT64, $arr[6]);
+ }
+
+
+ $this->assertEquals(7, count($arr));
+
+ for ($i = 0; $i < count($arr); $i++) {
+ $arr[$i] = 0;
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('0', $arr[$i]);
+ } else {
+ $this->assertSame(0, $arr[$i]);
+ }
+ }
+
+ // Test set.
+ $arr [0]= MAX_INT64;
+ $arr [1]= MIN_INT64;
+ $arr [2]= 1.1;
+ $arr [3]= '2';
+ $arr [4]= '3.1';
+ $arr [5]= MAX_INT64_STRING;
+ $arr [6]= MIN_INT64_STRING;
+
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame(MAX_INT64_STRING, $arr[0]);
+ $this->assertSame(MIN_INT64_STRING, $arr[1]);
+ $this->assertSame('1', $arr[2]);
+ $this->assertSame('2', $arr[3]);
+ $this->assertSame('3', $arr[4]);
+ $this->assertSame(MAX_INT64_STRING, $arr[5]);
+ $this->assertEquals(MIN_INT64_STRING, $arr[6]);
+ } else {
+ $this->assertSame(MAX_INT64, $arr[0]);
+ $this->assertSame(MIN_INT64, $arr[1]);
+ $this->assertSame(1, $arr[2]);
+ $this->assertSame(2, $arr[3]);
+ $this->assertSame(3, $arr[4]);
+ $this->assertSame(MAX_INT64, $arr[5]);
+ $this->assertEquals(MIN_INT64, $arr[6]);
+ }
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt64AppendStringFail()
+ {
+ $arr = new RepeatedField(GPBType::INT64);
+ $arr []= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt64SetStringFail()
+ {
+ $arr = new RepeatedField(GPBType::INT64);
+ $arr []= 0;
+ $arr [0]= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt64AppendMessageFail()
+ {
+ $arr = new RepeatedField(GPBType::INT64);
+ $arr []= new TestMessage_Sub();
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt64SetMessageFail()
+ {
+ $arr = new RepeatedField(GPBType::INT64);
+ $arr []= 0;
+ $arr [0]= new TestMessage_Sub();
+ }
+
+ #########################################################
+ # Test uint64 field.
+ #########################################################
+
+ public function testUint64()
+ {
+ $arr = new RepeatedField(GPBType::UINT64);
+
+ // Test append.
+ $arr []= MAX_UINT64;
+ $arr []= 1.1;
+ $arr []= '2';
+ $arr []= '3.1';
+ $arr []= MAX_UINT64_STRING;
+
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame(MAX_UINT64_STRING, $arr[0]);
+ $this->assertSame('1', $arr[1]);
+ $this->assertSame('2', $arr[2]);
+ $this->assertSame('3', $arr[3]);
+ $this->assertSame(MAX_UINT64_STRING, $arr[4]);
+ } else {
+ $this->assertSame(MAX_UINT64, $arr[0]);
+ $this->assertSame(1, $arr[1]);
+ $this->assertSame(2, $arr[2]);
+ $this->assertSame(3, $arr[3]);
+ $this->assertSame(MAX_UINT64, $arr[4]);
+ $this->assertSame(5, count($arr));
+ }
+
+ $this->assertSame(5, count($arr));
+
+ for ($i = 0; $i < count($arr); $i++) {
+ $arr[$i] = 0;
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('0', $arr[$i]);
+ } else {
+ $this->assertSame(0, $arr[$i]);
+ }
+ }
+
+ // Test set.
+ $arr [0]= MAX_UINT64;
+ $arr [1]= 1.1;
+ $arr [2]= '2';
+ $arr [3]= '3.1';
+ $arr [4]= MAX_UINT64_STRING;
+
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame(MAX_UINT64_STRING, $arr[0]);
+ $this->assertSame('1', $arr[1]);
+ $this->assertSame('2', $arr[2]);
+ $this->assertSame('3', $arr[3]);
+ $this->assertSame(MAX_UINT64_STRING, $arr[4]);
+ } else {
+ $this->assertSame(MAX_UINT64, $arr[0]);
+ $this->assertSame(1, $arr[1]);
+ $this->assertSame(2, $arr[2]);
+ $this->assertSame(3, $arr[3]);
+ $this->assertSame(MAX_UINT64, $arr[4]);
+ }
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint64AppendStringFail()
+ {
+ $arr = new RepeatedField(GPBType::UINT64);
+ $arr []= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint64SetStringFail()
+ {
+ $arr = new RepeatedField(GPBType::UINT64);
+ $arr []= 0;
+ $arr [0]= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint64AppendMessageFail()
+ {
+ $arr = new RepeatedField(GPBType::UINT64);
+ $arr []= new TestMessage_Sub();
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint64SetMessageFail()
+ {
+ $arr = new RepeatedField(GPBType::UINT64);
+ $arr []= 0;
+ $arr [0]= new TestMessage_Sub();
+ }
+
+ #########################################################
+ # Test float field.
+ #########################################################
+
+ public function testFloat()
+ {
+ $arr = new RepeatedField(GPBType::FLOAT);
+
+ // Test append.
+ $arr []= 1;
+ $this->assertEquals(1.0, $arr[0], '', MAX_FLOAT_DIFF);
+
+ $arr []= 1.1;
+ $this->assertEquals(1.1, $arr[1], '', MAX_FLOAT_DIFF);
+
+ $arr []= '2';
+ $this->assertEquals(2.0, $arr[2], '', MAX_FLOAT_DIFF);
+ $arr []= '3.1';
+ $this->assertEquals(3.1, $arr[3], '', MAX_FLOAT_DIFF);
+
+ $this->assertEquals(4, count($arr));
+
+ for ($i = 0; $i < count($arr); $i++) {
+ $arr[$i] = 0;
+ $this->assertSame(0.0, $arr[$i]);
+ }
+
+ // Test set.
+ $arr [0]= 1;
+ $this->assertEquals(1.0, $arr[0], '', MAX_FLOAT_DIFF);
+
+ $arr [1]= 1.1;
+ $this->assertEquals(1.1, $arr[1], '', MAX_FLOAT_DIFF);
+
+ $arr [2]= '2';
+ $this->assertEquals(2.0, $arr[2], '', MAX_FLOAT_DIFF);
+ $arr [3]= '3.1';
+ $this->assertEquals(3.1, $arr[3], '', MAX_FLOAT_DIFF);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testFloatAppendStringFail()
+ {
+ $arr = new RepeatedField(GPBType::FLOAT);
+ $arr []= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testFloatSetStringFail()
+ {
+ $arr = new RepeatedField(GPBType::FLOAT);
+ $arr []= 0.0;
+ $arr [0]= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testFloatAppendMessageFail()
+ {
+ $arr = new RepeatedField(GPBType::FLOAT);
+ $arr []= new TestMessage_Sub();
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testFloatSetMessageFail()
+ {
+ $arr = new RepeatedField(GPBType::FLOAT);
+ $arr []= 0.0;
+ $arr [0]= new TestMessage_Sub();
+ }
+
+ #########################################################
+ # Test double field.
+ #########################################################
+
+ public function testDouble()
+ {
+ $arr = new RepeatedField(GPBType::DOUBLE);
+
+ // Test append.
+ $arr []= 1;
+ $this->assertEquals(1.0, $arr[0], '', MAX_FLOAT_DIFF);
+
+ $arr []= 1.1;
+ $this->assertEquals(1.1, $arr[1], '', MAX_FLOAT_DIFF);
+
+ $arr []= '2';
+ $this->assertEquals(2.0, $arr[2], '', MAX_FLOAT_DIFF);
+ $arr []= '3.1';
+ $this->assertEquals(3.1, $arr[3], '', MAX_FLOAT_DIFF);
+
+ $this->assertEquals(4, count($arr));
+
+ for ($i = 0; $i < count($arr); $i++) {
+ $arr[$i] = 0;
+ $this->assertSame(0.0, $arr[$i]);
+ }
+
+ // Test set.
+ $arr [0]= 1;
+ $this->assertEquals(1.0, $arr[0], '', MAX_FLOAT_DIFF);
+
+ $arr [1]= 1.1;
+ $this->assertEquals(1.1, $arr[1], '', MAX_FLOAT_DIFF);
+
+ $arr [2]= '2';
+ $this->assertEquals(2.0, $arr[2], '', MAX_FLOAT_DIFF);
+ $arr [3]= '3.1';
+ $this->assertEquals(3.1, $arr[3], '', MAX_FLOAT_DIFF);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testDoubleAppendStringFail()
+ {
+ $arr = new RepeatedField(GPBType::DOUBLE);
+ $arr []= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testDoubleSetStringFail()
+ {
+ $arr = new RepeatedField(GPBType::DOUBLE);
+ $arr []= 0.0;
+ $arr [0]= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testDoubleAppendMessageFail()
+ {
+ $arr = new RepeatedField(GPBType::DOUBLE);
+ $arr []= new TestMessage_Sub();
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testDoubleSetMessageFail()
+ {
+ $arr = new RepeatedField(GPBType::DOUBLE);
+ $arr []= 0.0;
+ $arr [0]= new TestMessage_Sub();
+ }
+
+ #########################################################
+ # Test bool field.
+ #########################################################
+
+ public function testBool()
+ {
+ $arr = new RepeatedField(GPBType::BOOL);
+
+ // Test append.
+ $arr []= true;
+ $this->assertSame(true, $arr[0]);
+
+ $arr []= -1;
+ $this->assertSame(true, $arr[1]);
+
+ $arr []= 1.1;
+ $this->assertSame(true, $arr[2]);
+
+ $arr []= '';
+ $this->assertSame(false, $arr[3]);
+
+ $this->assertEquals(4, count($arr));
+
+ for ($i = 0; $i < count($arr); $i++) {
+ $arr[$i] = 0;
+ $this->assertSame(false, $arr[$i]);
+ }
+
+ // Test set.
+ $arr [0]= true;
+ $this->assertSame(true, $arr[0]);
+
+ $arr [1]= -1;
+ $this->assertSame(true, $arr[1]);
+
+ $arr [2]= 1.1;
+ $this->assertSame(true, $arr[2]);
+
+ $arr [3]= '';
+ $this->assertSame(false, $arr[3]);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testBoolAppendMessageFail()
+ {
+ $arr = new RepeatedField(GPBType::BOOL);
+ $arr []= new TestMessage_Sub();
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testBoolSetMessageFail()
+ {
+ $arr = new RepeatedField(GPBType::BOOL);
+ $arr []= true;
+ $arr [0]= new TestMessage_Sub();
+ }
+
+ #########################################################
+ # Test string field.
+ #########################################################
+
+ public function testString()
+ {
+ $arr = new RepeatedField(GPBType::STRING);
+
+ // Test append.
+ $arr []= 'abc';
+ $this->assertSame('abc', $arr[0]);
+
+ $arr []= 1;
+ $this->assertSame('1', $arr[1]);
+
+ $arr []= 1.1;
+ $this->assertSame('1.1', $arr[2]);
+
+ $arr []= true;
+ $this->assertSame('1', $arr[3]);
+
+ $this->assertEquals(4, count($arr));
+
+ for ($i = 0; $i < count($arr); $i++) {
+ $arr[$i] = '';
+ $this->assertSame('', $arr[$i]);
+ }
+
+ // Test set.
+ $arr [0]= 'abc';
+ $this->assertSame('abc', $arr[0]);
+
+ $arr [1]= 1;
+ $this->assertSame('1', $arr[1]);
+
+ $arr [2]= 1.1;
+ $this->assertSame('1.1', $arr[2]);
+
+ $arr [3]= true;
+ $this->assertSame('1', $arr[3]);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testStringAppendMessageFail()
+ {
+ $arr = new RepeatedField(GPBType::STRING);
+ $arr []= new TestMessage_Sub();
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testStringSetMessageFail()
+ {
+ $arr = new RepeatedField(GPBType::STRING);
+ $arr []= 'abc';
+ $arr [0]= new TestMessage_Sub();
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testStringAppendInvalidUTF8Fail()
+ {
+ $arr = new RepeatedField(GPBType::STRING);
+ $hex = hex2bin("ff");
+ $arr []= $hex;
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testStringSetInvalidUTF8Fail()
+ {
+ $arr = new RepeatedField(GPBType::STRING);
+ $arr []= 'abc';
+ $hex = hex2bin("ff");
+ $arr [0]= $hex;
+ }
+
+ #########################################################
+ # Test message field.
+ #########################################################
+
+ public function testMessage()
+ {
+ $arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class);
+
+ // Test append.
+ $sub_m = new TestMessage_Sub();
+ $sub_m->setA(1);
+ $arr []= $sub_m;
+ $this->assertSame(1, $arr[0]->getA());
+
+ $null = null;
+ $arr []= $null;
+ $this->assertNull($arr[1]);
+
+ $this->assertEquals(2, count($arr));
+
+ for ($i = 0; $i < count($arr); $i++) {
+ $arr[$i] = $null;
+ $this->assertNull($arr[$i]);
+ }
+
+ // Test set.
+ $arr [0]= $sub_m;
+ $this->assertSame(1, $arr[0]->getA());
+
+ $arr [1]= $null;
+ $this->assertNull($arr[1]);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testMessageAppendIntFail()
+ {
+ $arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class);
+ $arr []= 1;
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testMessageSetIntFail()
+ {
+ $arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class);
+ $arr []= new TestMessage_Sub;
+ $arr [0]= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testMessageAppendStringFail()
+ {
+ $arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class);
+ $arr []= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testMessageSetStringFail()
+ {
+ $arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class);
+ $arr []= new TestMessage_Sub;
+ $arr [0]= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testMessageAppendOtherMessageFail()
+ {
+ $arr = new RepeatedField(GPBType::MESSAGE, TestMessage_Sub::class);
+ $arr []= new TestMessage;
+ }
+
+ #########################################################
+ # Test offset type
+ #########################################################
+
+ public function testOffset()
+ {
+ $arr = new RepeatedField(GPBType::INT32);
+ $arr []= 0;
+
+ $arr [0]= 1;
+ $this->assertSame(1, $arr[0]);
+ $this->assertSame(1, count($arr));
+
+ $arr ['0']= 2;
+ $this->assertSame(2, $arr['0']);
+ $this->assertSame(2, $arr[0]);
+ $this->assertSame(1, count($arr));
+
+ $arr [0.0]= 3;
+ $this->assertSame(3, $arr[0.0]);
+ $this->assertSame(1, count($arr));
+ }
+
+ public function testInsertRemoval()
+ {
+ $arr = new RepeatedField(GPBType::INT32);
+
+ $arr []= 0;
+ $arr []= 1;
+ $arr []= 2;
+ $this->assertSame(3, count($arr));
+
+ unset($arr[2]);
+ $this->assertSame(2, count($arr));
+ $this->assertSame(0, $arr[0]);
+ $this->assertSame(1, $arr[1]);
+
+ $arr [] = 3;
+ $this->assertSame(3, count($arr));
+ $this->assertSame(0, $arr[0]);
+ $this->assertSame(1, $arr[1]);
+ $this->assertSame(3, $arr[2]);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testRemoveMiddleFail()
+ {
+ $arr = new RepeatedField(GPBType::INT32);
+
+ $arr []= 0;
+ $arr []= 1;
+ $arr []= 2;
+ $this->assertSame(3, count($arr));
+
+ unset($arr[1]);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testRemoveEmptyFail()
+ {
+ $arr = new RepeatedField(GPBType::INT32);
+
+ unset($arr[0]);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testMessageOffsetFail()
+ {
+ $arr = new RepeatedField(GPBType::INT32);
+ $arr []= 0;
+ $arr [new TestMessage_Sub()]= 0;
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testStringOffsetFail()
+ {
+ $arr = new RepeatedField(GPBType::INT32);
+ $arr []= 0;
+ $arr ['abc']= 0;
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testSetNonExistedOffsetFail()
+ {
+ $arr = new RepeatedField(GPBType::INT32);
+ $arr [0]= 0;
+ }
+
+ #########################################################
+ # Test memory leak
+ #########################################################
+
+ public function testCycleLeak()
+ {
+ $arr = new RepeatedField(GPBType::MESSAGE, TestMessage::class);
+ $arr []= new TestMessage;
+ $arr[0]->SetRepeatedRecursive($arr);
+
+ // Clean up memory before test.
+ gc_collect_cycles();
+ $start = memory_get_usage();
+ unset($arr);
+
+ // Explicitly trigger garbage collection.
+ gc_collect_cycles();
+
+ $end = memory_get_usage();
+ $this->assertLessThan($start, $end);
+ }
+}
diff --git a/third_party/protobuf/php/tests/autoload.php b/third_party/protobuf/php/tests/autoload.php
new file mode 100755
index 0000000000..0a917fc51a
--- /dev/null
+++ b/third_party/protobuf/php/tests/autoload.php
@@ -0,0 +1,25 @@
+<?php
+
+function getGeneratedFiles($dir, &$results = array())
+{
+ $files = scandir($dir);
+
+ foreach ($files as $key => $value) {
+ $path = realpath($dir.DIRECTORY_SEPARATOR.$value);
+ if (!is_dir($path)) {
+ $results[] = $path;
+ } else if ($value != "." && $value != "..") {
+ getGeneratedFiles($path, $results);
+ }
+ }
+ return $results;
+}
+
+foreach (getGeneratedFiles("generated") as $filename)
+{
+ if (!is_dir($filename)) {
+ include_once $filename;
+ }
+
+}
+
diff --git a/third_party/protobuf/php/tests/encode_decode_test.php b/third_party/protobuf/php/tests/encode_decode_test.php
new file mode 100644
index 0000000000..94adf7931c
--- /dev/null
+++ b/third_party/protobuf/php/tests/encode_decode_test.php
@@ -0,0 +1,225 @@
+<?php
+
+require_once('test_base.php');
+require_once('test_util.php');
+
+use Google\Protobuf\RepeatedField;
+use Google\Protobuf\GPBType;
+use Foo\TestEnum;
+use Foo\TestMessage;
+use Foo\TestMessage_Sub;
+use Foo\TestPackedMessage;
+use Foo\TestUnpackedMessage;
+
+class EncodeDecodeTest extends TestBase
+{
+
+ public function testEncode()
+ {
+ $from = new TestMessage();
+ $this->expectEmptyFields($from);
+ $this->setFields($from);
+ $this->expectFields($from);
+
+ $data = $from->serializeToString();
+ $this->assertSame(bin2hex(TestUtil::getGoldenTestMessage()),
+ bin2hex($data));
+ }
+
+ public function testDecode()
+ {
+ $to = new TestMessage();
+ $to->mergeFromString(TestUtil::getGoldenTestMessage());
+ $this->expectFields($to);
+ }
+
+ public function testEncodeDecode()
+ {
+ $from = new TestMessage();
+ $this->expectEmptyFields($from);
+ $this->setFields($from);
+ $this->expectFields($from);
+
+ $data = $from->serializeToString();
+
+ $to = new TestMessage();
+ $to->mergeFromString($data);
+ $this->expectFields($to);
+ }
+
+ public function testEncodeDecodeEmpty()
+ {
+ $from = new TestMessage();
+ $this->expectEmptyFields($from);
+
+ $data = $from->serializeToString();
+
+ $to = new TestMessage();
+ $to->mergeFromString($data);
+ $this->expectEmptyFields($to);
+ }
+
+ public function testEncodeDecodeOneof()
+ {
+ $m = new TestMessage();
+
+ $m->setOneofInt32(1);
+ $data = $m->serializeToString();
+ $n = new TestMessage();
+ $n->mergeFromString($data);
+ $this->assertSame(1, $n->getOneofInt32());
+
+ $m->setOneofFloat(2.0);
+ $data = $m->serializeToString();
+ $n = new TestMessage();
+ $n->mergeFromString($data);
+ $this->assertSame(2.0, $n->getOneofFloat());
+
+ $m->setOneofString('abc');
+ $data = $m->serializeToString();
+ $n = new TestMessage();
+ $n->mergeFromString($data);
+ $this->assertSame('abc', $n->getOneofString());
+
+ $sub_m = new TestMessage_Sub();
+ $sub_m->setA(1);
+ $m->setOneofMessage($sub_m);
+ $data = $m->serializeToString();
+ $n = new TestMessage();
+ $n->mergeFromString($data);
+ $this->assertSame(1, $n->getOneofMessage()->getA());
+ }
+
+ public function testPackedEncode()
+ {
+ $from = new TestPackedMessage();
+ TestUtil::setTestPackedMessage($from);
+ $this->assertSame(TestUtil::getGoldenTestPackedMessage(),
+ $from->serializeToString());
+ }
+
+ public function testPackedDecodePacked()
+ {
+ $to = new TestPackedMessage();
+ $to->mergeFromString(TestUtil::getGoldenTestPackedMessage());
+ TestUtil::assertTestPackedMessage($to);
+ }
+
+ public function testPackedDecodeUnpacked()
+ {
+ $to = new TestPackedMessage();
+ $to->mergeFromString(TestUtil::getGoldenTestUnpackedMessage());
+ TestUtil::assertTestPackedMessage($to);
+ }
+
+ public function testUnpackedEncode()
+ {
+ $from = new TestUnpackedMessage();
+ TestUtil::setTestPackedMessage($from);
+ $this->assertSame(TestUtil::getGoldenTestUnpackedMessage(),
+ $from->serializeToString());
+ }
+
+ public function testUnpackedDecodePacked()
+ {
+ $to = new TestUnpackedMessage();
+ $to->mergeFromString(TestUtil::getGoldenTestPackedMessage());
+ TestUtil::assertTestPackedMessage($to);
+ }
+
+ public function testUnpackedDecodeUnpacked()
+ {
+ $to = new TestUnpackedMessage();
+ $to->mergeFromString(TestUtil::getGoldenTestUnpackedMessage());
+ TestUtil::assertTestPackedMessage($to);
+ }
+
+ public function testDecodeInt64()
+ {
+ // Read 64 testing
+ $testVals = array(
+ '10' => '100a',
+ '100' => '1064',
+ '800' => '10a006',
+ '6400' => '108032',
+ '70400' => '1080a604',
+ '774400' => '1080a22f',
+ '9292800' => '108098b704',
+ '74342400' => '1080c0b923',
+ '743424000' => '108080bfe202',
+ '8177664000' => '108080b5bb1e',
+ '65421312000' => '108080a8dbf301',
+ '785055744000' => '108080e0c7ec16',
+ '9420668928000' => '10808080dd969202',
+ '103627358208000' => '10808080fff9c717',
+ '1139900940288000' => '10808080f5bd978302',
+ '13678811283456000' => '10808080fce699a618',
+ '109430490267648000' => '10808080e0b7ceb1c201',
+ '984874412408832000' => '10808080e0f5c1bed50d',
+ );
+
+ $msg = new TestMessage();
+ foreach ($testVals as $original => $encoded) {
+ $msg->setOptionalInt64($original);
+ $data = $msg->serializeToString();
+ $this->assertSame($encoded, bin2hex($data));
+ $msg->setOptionalInt64(0);
+ $msg->mergeFromString($data);
+ $this->assertEquals($original, $msg->getOptionalInt64());
+ }
+ }
+
+ public function testDecodeToExistingMessage()
+ {
+ $m1 = new TestMessage();
+ $this->setFields($m1);
+ $this->expectFields($m1);
+
+ $m2 = new TestMessage();
+ $this->setFields2($m2);
+ $data = $m2->serializeToString();
+
+ $m1->mergeFromString($data);
+ $this->expectFieldsMerged($m1);
+ }
+
+ public function testDecodeFieldNonExist()
+ {
+ $data = hex2bin('c80501');
+ $m = new TestMessage();
+ $m->mergeFromString($data);
+ }
+
+ public function testEncodeNegativeInt32()
+ {
+ $m = new TestMessage();
+ $m->setOptionalInt32(-1);
+ $data = $m->serializeToString();
+ $this->assertSame("08ffffffffffffffffff01", bin2hex($data));
+ }
+
+ public function testDecodeNegativeInt32()
+ {
+ $m = new TestMessage();
+ $this->assertEquals(0, $m->getOptionalInt32());
+ $m->mergeFromString(hex2bin("08ffffffffffffffffff01"));
+ $this->assertEquals(-1, $m->getOptionalInt32());
+
+ $m = new TestMessage();
+ $this->assertEquals(0, $m->getOptionalInt32());
+ $m->mergeFromString(hex2bin("08ffffffff0f"));
+ $this->assertEquals(-1, $m->getOptionalInt32());
+ }
+
+ # TODO(teboring): Add test back when php implementation is ready for json
+ # encode/decode.
+ # public function testJsonEncode()
+ # {
+ # $from = new TestMessage();
+ # $this->setFields($from);
+ # $data = $from->jsonEncode();
+ # $to = new TestMessage();
+ # $to->jsonDecode($data);
+ # $this->expectFields($to);
+ # }
+}
diff --git a/third_party/protobuf/php/tests/gdb_test.sh b/third_party/protobuf/php/tests/gdb_test.sh
new file mode 100755
index 0000000000..45a2841fd6
--- /dev/null
+++ b/third_party/protobuf/php/tests/gdb_test.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+# gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which
+# phpunit` --bootstrap autoload.php tmp_test.php
+#
+gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php array_test.php
+#
+# # gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so
+# memory_leak_test.php
+#
+# # USE_ZEND_ALLOC=0 valgrind --leak-check=yes php
+# -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php
diff --git a/third_party/protobuf/php/tests/generated_class_test.php b/third_party/protobuf/php/tests/generated_class_test.php
new file mode 100644
index 0000000000..39e6c6c41c
--- /dev/null
+++ b/third_party/protobuf/php/tests/generated_class_test.php
@@ -0,0 +1,855 @@
+<?php
+
+require_once('generated/NoNameSpaceEnum.php');
+require_once('generated/NoNameSpaceMessage.php');
+require_once('test_base.php');
+require_once('test_util.php');
+
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\MapField;
+use Google\Protobuf\Internal\GPBType;
+use Foo\TestEnum;
+use Foo\TestIncludePrefixMessage;
+use Foo\TestMessage;
+use Foo\TestMessage_Sub;
+
+class GeneratedClassTest extends TestBase
+{
+
+ #########################################################
+ # Test field accessors.
+ #########################################################
+
+ public function testSetterGetter()
+ {
+ $m = new TestMessage();
+ $m->setOptionalInt32(1);
+ $this->assertSame(1, $m->getOptionalInt32());
+ }
+
+ #########################################################
+ # Test int32 field.
+ #########################################################
+
+ public function testInt32Field()
+ {
+ $m = new TestMessage();
+
+ // Set integer.
+ $m->setOptionalInt32(MAX_INT32);
+ $this->assertSame(MAX_INT32, $m->getOptionalInt32());
+ $m->setOptionalInt32(MIN_INT32);
+ $this->assertSame(MIN_INT32, $m->getOptionalInt32());
+
+ // Set float.
+ $m->setOptionalInt32(1.1);
+ $this->assertSame(1, $m->getOptionalInt32());
+ $m->setOptionalInt32(MAX_INT32_FLOAT);
+ $this->assertSame(MAX_INT32, $m->getOptionalInt32());
+ $m->setOptionalInt32(MIN_INT32_FLOAT);
+ $this->assertSame(MIN_INT32, $m->getOptionalInt32());
+
+ // Set string.
+ $m->setOptionalInt32('2');
+ $this->assertSame(2, $m->getOptionalInt32());
+ $m->setOptionalInt32('3.1');
+ $this->assertSame(3, $m->getOptionalInt32());
+ $m->setOptionalInt32(MAX_INT32_STRING);
+ $this->assertSame(MAX_INT32, $m->getOptionalInt32());
+ $m->setOptionalInt32(MIN_INT32_STRING);
+ $this->assertSame(MIN_INT32, $m->getOptionalInt32());
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt32FieldInvalidTypeFail()
+ {
+ $m = new TestMessage();
+ $m->setOptionalInt32(new TestMessage());
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt32FieldInvalidStringFail()
+ {
+ $m = new TestMessage();
+ $m->setOptionalInt32('abc');
+ }
+
+ #########################################################
+ # Test uint32 field.
+ #########################################################
+
+ public function testUint32Field()
+ {
+ $m = new TestMessage();
+
+ // Set integer.
+ $m->setOptionalUint32(MAX_UINT32);
+ $this->assertSame(-1, $m->getOptionalUint32());
+ $m->setOptionalUint32(-1);
+ $this->assertSame(-1, $m->getOptionalUint32());
+ $m->setOptionalUint32(MIN_UINT32);
+ $this->assertSame(MIN_INT32, $m->getOptionalUint32());
+
+ // Set float.
+ $m->setOptionalUint32(1.1);
+ $this->assertSame(1, $m->getOptionalUint32());
+ $m->setOptionalUint32(MAX_UINT32_FLOAT);
+ $this->assertSame(-1, $m->getOptionalUint32());
+ $m->setOptionalUint32(-1.0);
+ $this->assertSame(-1, $m->getOptionalUint32());
+ $m->setOptionalUint32(MIN_UINT32_FLOAT);
+ $this->assertSame(MIN_INT32, $m->getOptionalUint32());
+
+ // Set string.
+ $m->setOptionalUint32('2');
+ $this->assertSame(2, $m->getOptionalUint32());
+ $m->setOptionalUint32('3.1');
+ $this->assertSame(3, $m->getOptionalUint32());
+ $m->setOptionalUint32(MAX_UINT32_STRING);
+ $this->assertSame(-1, $m->getOptionalUint32());
+ $m->setOptionalUint32('-1.0');
+ $this->assertSame(-1, $m->getOptionalUint32());
+ $m->setOptionalUint32(MIN_UINT32_STRING);
+ $this->assertSame(MIN_INT32, $m->getOptionalUint32());
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint32FieldInvalidTypeFail()
+ {
+ $m = new TestMessage();
+ $m->setOptionalUint32(new TestMessage());
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint32FieldInvalidStringFail()
+ {
+ $m = new TestMessage();
+ $m->setOptionalUint32('abc');
+ }
+
+ #########################################################
+ # Test int64 field.
+ #########################################################
+
+ public function testInt64Field()
+ {
+ $m = new TestMessage();
+
+ // Set integer.
+ $m->setOptionalInt64(MAX_INT64);
+ $this->assertSame(MAX_INT64, $m->getOptionalInt64());
+ $m->setOptionalInt64(MIN_INT64);
+ $this->assertEquals(MIN_INT64, $m->getOptionalInt64());
+
+ // Set float.
+ $m->setOptionalInt64(1.1);
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('1', $m->getOptionalInt64());
+ } else {
+ $this->assertSame(1, $m->getOptionalInt64());
+ }
+
+ // Set string.
+ $m->setOptionalInt64('2');
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('2', $m->getOptionalInt64());
+ } else {
+ $this->assertSame(2, $m->getOptionalInt64());
+ }
+
+ $m->setOptionalInt64('3.1');
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('3', $m->getOptionalInt64());
+ } else {
+ $this->assertSame(3, $m->getOptionalInt64());
+ }
+
+ $m->setOptionalInt64(MAX_INT64_STRING);
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame(MAX_INT64_STRING, $m->getOptionalInt64());
+ } else {
+ $this->assertSame(MAX_INT64, $m->getOptionalInt64());
+ }
+
+ $m->setOptionalInt64(MIN_INT64_STRING);
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame(MIN_INT64_STRING, $m->getOptionalInt64());
+ } else {
+ $this->assertSame(MIN_INT64, $m->getOptionalInt64());
+ }
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt64FieldInvalidTypeFail()
+ {
+ $m = new TestMessage();
+ $m->setOptionalInt64(new TestMessage());
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt64FieldInvalidStringFail()
+ {
+ $m = new TestMessage();
+ $m->setOptionalInt64('abc');
+ }
+
+ #########################################################
+ # Test uint64 field.
+ #########################################################
+
+ public function testUint64Field()
+ {
+ $m = new TestMessage();
+
+ // Set integer.
+ $m->setOptionalUint64(MAX_UINT64);
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame(MAX_UINT64_STRING, $m->getOptionalUint64());
+ } else {
+ $this->assertSame(MAX_UINT64, $m->getOptionalUint64());
+ }
+
+ // Set float.
+ $m->setOptionalUint64(1.1);
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('1', $m->getOptionalUint64());
+ } else {
+ $this->assertSame(1, $m->getOptionalUint64());
+ }
+
+ // Set string.
+ $m->setOptionalUint64('2');
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('2', $m->getOptionalUint64());
+ } else {
+ $this->assertSame(2, $m->getOptionalUint64());
+ }
+
+ $m->setOptionalUint64('3.1');
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('3', $m->getOptionalUint64());
+ } else {
+ $this->assertSame(3, $m->getOptionalUint64());
+ }
+
+ $m->setOptionalUint64(MAX_UINT64_STRING);
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame(MAX_UINT64_STRING, $m->getOptionalUint64());
+ } else {
+ $this->assertSame(MAX_UINT64, $m->getOptionalUint64());
+ }
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint64FieldInvalidTypeFail()
+ {
+ $m = new TestMessage();
+ $m->setOptionalUint64(new TestMessage());
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint64FieldInvalidStringFail()
+ {
+ $m = new TestMessage();
+ $m->setOptionalUint64('abc');
+ }
+
+ #########################################################
+ # Test enum field.
+ #########################################################
+
+ public function testEnumField()
+ {
+ $m = new TestMessage();
+
+ // Set enum.
+ $m->setOptionalEnum(TestEnum::ONE);
+ $this->assertEquals(TestEnum::ONE, $m->getOptionalEnum());
+
+ // Set integer.
+ $m->setOptionalEnum(1);
+ $this->assertEquals(TestEnum::ONE, $m->getOptionalEnum());
+
+ // Set float.
+ $m->setOptionalEnum(1.1);
+ $this->assertEquals(TestEnum::ONE, $m->getOptionalEnum());
+
+ // Set string.
+ $m->setOptionalEnum("1");
+ $this->assertEquals(TestEnum::ONE, $m->getOptionalEnum());
+ }
+
+ #########################################################
+ # Test float field.
+ #########################################################
+
+ public function testFloatField()
+ {
+ $m = new TestMessage();
+
+ // Set integer.
+ $m->setOptionalFloat(1);
+ $this->assertEquals(1.0, $m->getOptionalFloat(), '', MAX_FLOAT_DIFF);
+
+ // Set float.
+ $m->setOptionalFloat(1.1);
+ $this->assertEquals(1.1, $m->getOptionalFloat(), '', MAX_FLOAT_DIFF);
+
+ // Set string.
+ $m->setOptionalFloat('2');
+ $this->assertEquals(2.0, $m->getOptionalFloat(), '', MAX_FLOAT_DIFF);
+ $m->setOptionalFloat('3.1');
+ $this->assertEquals(3.1, $m->getOptionalFloat(), '', MAX_FLOAT_DIFF);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testFloatFieldInvalidTypeFail()
+ {
+ $m = new TestMessage();
+ $m->setOptionalFloat(new TestMessage());
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testFloatFieldInvalidStringFail()
+ {
+ $m = new TestMessage();
+ $m->setOptionalFloat('abc');
+ }
+
+ #########################################################
+ # Test double field.
+ #########################################################
+
+ public function testDoubleField()
+ {
+ $m = new TestMessage();
+
+ // Set integer.
+ $m->setOptionalDouble(1);
+ $this->assertEquals(1.0, $m->getOptionalDouble(), '', MAX_FLOAT_DIFF);
+
+ // Set float.
+ $m->setOptionalDouble(1.1);
+ $this->assertEquals(1.1, $m->getOptionalDouble(), '', MAX_FLOAT_DIFF);
+
+ // Set string.
+ $m->setOptionalDouble('2');
+ $this->assertEquals(2.0, $m->getOptionalDouble(), '', MAX_FLOAT_DIFF);
+ $m->setOptionalDouble('3.1');
+ $this->assertEquals(3.1, $m->getOptionalDouble(), '', MAX_FLOAT_DIFF);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testDoubleFieldInvalidTypeFail()
+ {
+ $m = new TestMessage();
+ $m->setOptionalDouble(new TestMessage());
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testDoubleFieldInvalidStringFail()
+ {
+ $m = new TestMessage();
+ $m->setOptionalDouble('abc');
+ }
+
+ #########################################################
+ # Test bool field.
+ #########################################################
+
+ public function testBoolField()
+ {
+ $m = new TestMessage();
+
+ // Set bool.
+ $m->setOptionalBool(true);
+ $this->assertSame(true, $m->getOptionalBool());
+
+ // Set integer.
+ $m->setOptionalBool(-1);
+ $this->assertSame(true, $m->getOptionalBool());
+
+ // Set float.
+ $m->setOptionalBool(1.1);
+ $this->assertSame(true, $m->getOptionalBool());
+
+ // Set string.
+ $m->setOptionalBool('');
+ $this->assertSame(false, $m->getOptionalBool());
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testBoolFieldInvalidStringFail()
+ {
+ $m = new TestMessage();
+ $m->setOptionalBool(new TestMessage());
+ }
+
+ #########################################################
+ # Test string field.
+ #########################################################
+
+ public function testStringField()
+ {
+ $m = new TestMessage();
+
+ // Set string.
+ $m->setOptionalString('abc');
+ $this->assertSame('abc', $m->getOptionalString());
+
+ // Set integer.
+ $m->setOptionalString(1);
+ $this->assertSame('1', $m->getOptionalString());
+
+ // Set double.
+ $m->setOptionalString(1.1);
+ $this->assertSame('1.1', $m->getOptionalString());
+
+ // Set bool.
+ $m->setOptionalString(true);
+ $this->assertSame('1', $m->getOptionalString());
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testStringFieldInvalidUTF8Fail()
+ {
+ $m = new TestMessage();
+ $hex = hex2bin("ff");
+ $m->setOptionalString($hex);
+ }
+
+ #########################################################
+ # Test bytes field.
+ #########################################################
+
+ public function testBytesField()
+ {
+ $m = new TestMessage();
+
+ // Set string.
+ $m->setOptionalBytes('abc');
+ $this->assertSame('abc', $m->getOptionalBytes());
+
+ // Set integer.
+ $m->setOptionalBytes(1);
+ $this->assertSame('1', $m->getOptionalBytes());
+
+ // Set double.
+ $m->setOptionalBytes(1.1);
+ $this->assertSame('1.1', $m->getOptionalBytes());
+
+ // Set bool.
+ $m->setOptionalBytes(true);
+ $this->assertSame('1', $m->getOptionalBytes());
+ }
+
+ public function testBytesFieldInvalidUTF8Success()
+ {
+ $m = new TestMessage();
+ $hex = hex2bin("ff");
+ $m->setOptionalBytes($hex);
+ }
+
+ #########################################################
+ # Test message field.
+ #########################################################
+
+ public function testMessageField()
+ {
+ $m = new TestMessage();
+
+ $sub_m = new TestMessage_Sub();
+ $sub_m->setA(1);
+ $m->setOptionalMessage($sub_m);
+ $this->assertSame(1, $m->getOptionalMessage()->getA());
+
+ $null = null;
+ $m->setOptionalMessage($null);
+ $this->assertNull($m->getOptionalMessage());
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testMessageFieldWrongTypeFail()
+ {
+ $m = new TestMessage();
+ $a = 1;
+ $m->setOptionalMessage($a);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testMessageFieldWrongClassFail()
+ {
+ $m = new TestMessage();
+ $m->setOptionalMessage(new TestMessage());
+ }
+
+ #########################################################
+ # Test repeated field.
+ #########################################################
+
+ public function testRepeatedField()
+ {
+ $m = new TestMessage();
+
+ $repeated_int32 = new RepeatedField(GPBType::INT32);
+ $m->setRepeatedInt32($repeated_int32);
+ $this->assertSame($repeated_int32, $m->getRepeatedInt32());
+ }
+
+ public function testRepeatedFieldViaArray()
+ {
+ $m = new TestMessage();
+
+ $arr = array();
+ $m->setRepeatedInt32($arr);
+ $this->assertSame(0, count($m->getRepeatedInt32()));
+
+ $arr = array(1, 2.1, "3");
+ $m->setRepeatedInt32($arr);
+ $this->assertTrue($m->getRepeatedInt32() instanceof RepeatedField);
+ $this->assertSame("Google\Protobuf\Internal\RepeatedField",
+ get_class($m->getRepeatedInt32()));
+ $this->assertSame(3, count($m->getRepeatedInt32()));
+ $this->assertSame(1, $m->getRepeatedInt32()[0]);
+ $this->assertSame(2, $m->getRepeatedInt32()[1]);
+ $this->assertSame(3, $m->getRepeatedInt32()[2]);
+ $this->assertFalse($arr instanceof RepeatedField);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testRepeatedFieldWrongTypeFail()
+ {
+ $m = new TestMessage();
+ $a = 1;
+ $m->setRepeatedInt32($a);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testRepeatedFieldWrongObjectFail()
+ {
+ $m = new TestMessage();
+ $m->setRepeatedInt32($m);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testRepeatedFieldWrongRepeatedTypeFail()
+ {
+ $m = new TestMessage();
+
+ $repeated_int32 = new RepeatedField(GPBType::UINT32);
+ $m->setRepeatedInt32($repeated_int32);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testRepeatedFieldWrongRepeatedMessageClassFail()
+ {
+ $m = new TestMessage();
+
+ $repeated_message = new RepeatedField(GPBType::MESSAGE,
+ TestMessage::class);
+ $m->setRepeatedMessage($repeated_message);
+ }
+
+ #########################################################
+ # Test map field.
+ #########################################################
+
+ public function testMapField()
+ {
+ $m = new TestMessage();
+
+ $map_int32_int32 = new MapField(GPBType::INT32, GPBType::INT32);
+ $m->setMapInt32Int32($map_int32_int32);
+ $this->assertSame($map_int32_int32, $m->getMapInt32Int32());
+ }
+
+ public function testMapFieldViaArray()
+ {
+ $m = new TestMessage();
+
+ $dict = array();
+ $m->setMapInt32Int32($dict);
+ $this->assertSame(0, count($m->getMapInt32Int32()));
+
+ $dict = array(5 => 5, 6.1 => 6.1, "7" => "7");
+ $m->setMapInt32Int32($dict);
+ $this->assertTrue($m->getMapInt32Int32() instanceof MapField);
+ $this->assertSame(3, count($m->getMapInt32Int32()));
+ $this->assertSame(5, $m->getMapInt32Int32()[5]);
+ $this->assertSame(6, $m->getMapInt32Int32()[6]);
+ $this->assertSame(7, $m->getMapInt32Int32()[7]);
+ $this->assertFalse($dict instanceof MapField);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testMapFieldWrongTypeFail()
+ {
+ $m = new TestMessage();
+ $a = 1;
+ $m->setMapInt32Int32($a);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testMapFieldWrongObjectFail()
+ {
+ $m = new TestMessage();
+ $m->setMapInt32Int32($m);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testMapFieldWrongRepeatedTypeFail()
+ {
+ $m = new TestMessage();
+
+ $map_uint32_uint32 = new MapField(GPBType::UINT32, GPBType::UINT32);
+ $m->setMapInt32Int32($map_uint32_uint32);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testMapFieldWrongRepeatedMessageClassFail()
+ {
+ $m = new TestMessage();
+
+ $map_int32_message = new MapField(GPBType::INT32,
+ GPBType::MESSAGE,
+ TestMessage::class);
+ $m->setMapInt32Message($map_int32_message);
+ }
+
+ #########################################################
+ # Test oneof field.
+ #########################################################
+
+ public function testOneofField() {
+ $m = new TestMessage();
+
+ $this->assertSame("", $m->getMyOneof());
+
+ $m->setOneofInt32(1);
+ $this->assertSame(1, $m->getOneofInt32());
+ $this->assertSame(0.0, $m->getOneofFloat());
+ $this->assertSame('', $m->getOneofString());
+ $this->assertSame(NULL, $m->getOneofMessage());
+ $this->assertSame("oneof_int32", $m->getMyOneof());
+
+ $m->setOneofFloat(2.0);
+ $this->assertSame(0, $m->getOneofInt32());
+ $this->assertSame(2.0, $m->getOneofFloat());
+ $this->assertSame('', $m->getOneofString());
+ $this->assertSame(NULL, $m->getOneofMessage());
+ $this->assertSame("oneof_float", $m->getMyOneof());
+
+ $m->setOneofString('abc');
+ $this->assertSame(0, $m->getOneofInt32());
+ $this->assertSame(0.0, $m->getOneofFloat());
+ $this->assertSame('abc', $m->getOneofString());
+ $this->assertSame(NULL, $m->getOneofMessage());
+ $this->assertSame("oneof_string", $m->getMyOneof());
+
+ $sub_m = new TestMessage_Sub();
+ $sub_m->setA(1);
+ $m->setOneofMessage($sub_m);
+ $this->assertSame(0, $m->getOneofInt32());
+ $this->assertSame(0.0, $m->getOneofFloat());
+ $this->assertSame('', $m->getOneofString());
+ $this->assertSame(1, $m->getOneofMessage()->getA());
+ $this->assertSame("oneof_message", $m->getMyOneof());
+ }
+
+ #########################################################
+ # Test clear method.
+ #########################################################
+
+ public function testMessageClear()
+ {
+ $m = new TestMessage();
+ $this->setFields($m);
+ $this->expectFields($m);
+ $m->clear();
+ $this->expectEmptyFields($m);
+ }
+
+ #########################################################
+ # Test mergeFrom method.
+ #########################################################
+
+ public function testMessageMergeFrom()
+ {
+ $m = new TestMessage();
+ $this->setFields($m);
+ $this->expectFields($m);
+ $arr = $m->getOptionalMessage()->getB();
+ $arr[] = 1;
+
+ $n = new TestMessage();
+
+ // Singular
+ $n->setOptionalInt32(100);
+ $sub1 = new TestMessage_Sub();
+ $sub1->setA(101);
+ $sub1->getB()[] = 102;
+ $n->setOptionalMessage($sub1);
+
+ // Repeated
+ $n->getRepeatedInt32()[] = 200;
+ $n->getRepeatedString()[] = 'abc';
+ $sub2 = new TestMessage_Sub();
+ $sub2->setA(201);
+ $n->getRepeatedMessage()[] = $sub2;
+
+ // Map
+ $n->getMapInt32Int32()[1] = 300;
+ $n->getMapInt32Int32()[-62] = 301;
+ $n->getMapStringString()['def'] = 'def';
+ $n->getMapInt32Message()[1] = new TestMessage_Sub();
+ $n->getMapInt32Message()[1]->setA(302);
+ $n->getMapInt32Message()[2] = new TestMessage_Sub();
+ $n->getMapInt32Message()[2]->setA(303);
+
+ $m->mergeFrom($n);
+
+ $this->assertSame(100, $m->getOptionalInt32());
+ $this->assertSame(42, $m->getOptionalUint32());
+ $this->assertSame(101, $m->getOptionalMessage()->getA());
+ $this->assertSame(2, count($m->getOptionalMessage()->getB()));
+ $this->assertSame(1, $m->getOptionalMessage()->getB()[0]);
+ $this->assertSame(102, $m->getOptionalMessage()->getB()[1]);
+
+ $this->assertSame(3, count($m->getRepeatedInt32()));
+ $this->assertSame(200, $m->getRepeatedInt32()[2]);
+ $this->assertSame(2, count($m->getRepeatedUint32()));
+ $this->assertSame(3, count($m->getRepeatedString()));
+ $this->assertSame('abc', $m->getRepeatedString()[2]);
+ $this->assertSame(3, count($m->getRepeatedMessage()));
+ $this->assertSame(201, $m->getRepeatedMessage()[2]->getA());
+
+ $this->assertSame(2, count($m->getMapInt32Int32()));
+ $this->assertSame(300, $m->getMapInt32Int32()[1]);
+ $this->assertSame(301, $m->getMapInt32Int32()[-62]);
+ $this->assertSame(1, count($m->getMapUint32Uint32()));
+ $this->assertSame(2, count($m->getMapStringString()));
+ $this->assertSame('def', $m->getMapStringString()['def']);
+
+ $this->assertSame(2, count($m->getMapInt32Message()));
+ $this->assertSame(302, $m->getMapInt32Message()[1]->getA());
+ $this->assertSame(303, $m->getMapInt32Message()[2]->getA());
+
+ $this->assertSame("", $m->getMyOneof());
+
+ // Check sub-messages are copied by value.
+ $n->getOptionalMessage()->setA(-101);
+ $this->assertSame(101, $m->getOptionalMessage()->getA());
+ $n->getRepeatedMessage()[0]->setA(-201);
+ $this->assertSame(201, $m->getRepeatedMessage()[2]->getA());
+ $n->getMapInt32Message()[1]->setA(-302);
+ $this->assertSame(302, $m->getMapInt32Message()[1]->getA());
+
+ // Test merge oneof.
+ $m = new TestMessage();
+
+ $n = new TestMessage();
+ $n->setOneofInt32(1);
+ $m->mergeFrom($n);
+ $this->assertSame(1, $m->getOneofInt32());
+
+ $sub = new TestMessage_Sub();
+ $n->setOneofMessage($sub);
+ $n->getOneofMessage()->setA(400);
+ $m->mergeFrom($n);
+ $this->assertSame(400, $m->getOneofMessage()->getA());
+ $n->getOneofMessage()->setA(-400);
+ $this->assertSame(400, $m->getOneofMessage()->getA());
+
+ // Test all fields
+ $m = new TestMessage();
+ $n = new TestMessage();
+ $this->setFields($m);
+ $n->mergeFrom($m);
+ $this->expectFields($n);
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testMessageMergeFromInvalidTypeFail()
+ {
+ $m = new TestMessage();
+ $n = new TestMessage_Sub();
+ $m->mergeFrom($n);
+ }
+
+ #########################################################
+ # Test message/enum without namespace.
+ #########################################################
+
+ public function testMessageWithoutNamespace()
+ {
+ $m = new NoNameSpaceMessage();
+ }
+
+ public function testEnumWithoutNamespace()
+ {
+ $m = new NoNameSpaceEnum();
+ }
+
+ #########################################################
+ # Test message with given prefix.
+ #########################################################
+
+ public function testPrefixMessage()
+ {
+ $m = new TestIncludePrefixMessage();
+ $n = new PrefixTestPrefix();
+ $n->setA(1);
+ $m->setPrefixMessage($n);
+ $this->assertSame(1, $m->getPrefixMessage()->getA());
+ }
+}
diff --git a/third_party/protobuf/php/tests/map_field_test.php b/third_party/protobuf/php/tests/map_field_test.php
new file mode 100644
index 0000000000..d4ec44fc9a
--- /dev/null
+++ b/third_party/protobuf/php/tests/map_field_test.php
@@ -0,0 +1,679 @@
+<?php
+
+require_once('test_util.php');
+
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\MapField;
+use Foo\TestMessage;
+use Foo\TestMessage_Sub;
+
+class MapFieldTest extends PHPUnit_Framework_TestCase {
+
+ #########################################################
+ # Test int32 field.
+ #########################################################
+
+ public function testInt32() {
+ $arr = new MapField(GPBType::INT32, GPBType::INT32);
+
+ // Test integer argument.
+ $arr[MAX_INT32] = MAX_INT32;
+ $this->assertSame(MAX_INT32, $arr[MAX_INT32]);
+ $arr[MIN_INT32] = MIN_INT32;
+ $this->assertSame(MIN_INT32, $arr[MIN_INT32]);
+ $this->assertEquals(2, count($arr));
+ $this->assertTrue(isset($arr[MAX_INT32]));
+ $this->assertTrue(isset($arr[MIN_INT32]));
+ unset($arr[MAX_INT32]);
+ unset($arr[MIN_INT32]);
+ $this->assertEquals(0, count($arr));
+
+ // Test float argument.
+ $arr[1.9] = 1.9;
+ $arr[2.1] = 2.1;
+ $this->assertSame(1, $arr[1]);
+ $this->assertSame(2, $arr[2]);
+ $arr[MAX_INT32_FLOAT] = MAX_INT32_FLOAT;
+ $this->assertSame(MAX_INT32, $arr[MAX_INT32]);
+ $arr[MIN_INT32_FLOAT] = MIN_INT32_FLOAT;
+ $this->assertSame(MIN_INT32, $arr[MIN_INT32]);
+ $this->assertEquals(4, count($arr));
+ unset($arr[1.9]);
+ unset($arr[2.9]);
+ unset($arr[MAX_INT32_FLOAT]);
+ unset($arr[MIN_INT32_FLOAT]);
+ $this->assertEquals(0, count($arr));
+
+ // Test string argument.
+ $arr['2'] = '2';
+ $this->assertSame(2, $arr[2]);
+ $arr['3.1'] = '3.1';
+ $this->assertSame(3, $arr[3]);
+ $arr[MAX_INT32_STRING] = MAX_INT32_STRING;
+ $this->assertSame(MAX_INT32, $arr[MAX_INT32]);
+ $this->assertEquals(3, count($arr));
+ unset($arr['2']);
+ unset($arr['3.1']);
+ unset($arr[MAX_INT32_STRING]);
+ $this->assertEquals(0, count($arr));
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt32SetStringKeyFail()
+ {
+ $arr = new MapField(GPBType::INT32, GPBType::INT32);
+ $arr ['abc']= 0;
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt32SetStringValueFail()
+ {
+ $arr = new MapField(GPBType::INT32, GPBType::INT32);
+ $arr [0]= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt32SetMessageKeyFail()
+ {
+ $arr = new MapField(GPBType::INT32, GPBType::INT32);
+ $arr [new TestMessage_Sub()]= 0;
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt32SetMessageValueFail()
+ {
+ $arr = new MapField(GPBType::INT32, GPBType::INT32);
+ $arr [0]= new TestMessage_Sub();
+ }
+
+ #########################################################
+ # Test uint32 field.
+ #########################################################
+
+ public function testUint32() {
+ $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
+
+ // Test integer argument.
+ $arr[MAX_UINT32] = MAX_UINT32;
+ $this->assertSame(-1, $arr[-1]);
+ $this->assertEquals(1, count($arr));
+ unset($arr[MAX_UINT32]);
+ $this->assertEquals(0, count($arr));
+
+ $arr[-1] = -1;
+ $this->assertSame(-1, $arr[-1]);
+ $arr[MIN_UINT32] = MIN_UINT32;
+ $this->assertSame(MIN_UINT32, $arr[MIN_UINT32]);
+ $this->assertEquals(2, count($arr));
+ unset($arr[-1]);
+ unset($arr[MIN_UINT32]);
+ $this->assertEquals(0, count($arr));
+
+ // Test float argument.
+ $arr[MAX_UINT32_FLOAT] = MAX_UINT32_FLOAT;
+ $this->assertSame(-1, $arr[-1]);
+ $this->assertEquals(1, count($arr));
+ unset($arr[MAX_UINT32_FLOAT]);
+ $this->assertEquals(0, count($arr));
+
+ $arr[3.1] = 3.1;
+ $this->assertSame(3, $arr[3]);
+ $arr[-1.0] = -1.0;
+ $this->assertSame(-1, $arr[-1]);
+ $arr[MIN_UINT32_FLOAT] = MIN_UINT32_FLOAT;
+ $this->assertSame(MIN_UINT32, $arr[MIN_UINT32]);
+ $this->assertEquals(3, count($arr));
+ unset($arr[3.1]);
+ unset($arr[-1.0]);
+ unset($arr[MIN_UINT32_FLOAT]);
+ $this->assertEquals(0, count($arr));
+
+ // Test string argument.
+ $arr[MAX_UINT32_STRING] = MAX_UINT32_STRING;
+ $this->assertSame(-1, $arr[-1]);
+ $this->assertEquals(1, count($arr));
+ unset($arr[MAX_UINT32_STRING]);
+ $this->assertEquals(0, count($arr));
+
+ $arr['7'] = '7';
+ $this->assertSame(7, $arr[7]);
+ $arr['3.1'] = '3.1';
+ $this->assertSame(3, $arr[3]);
+ $arr['-1.0'] = '-1.0';
+ $this->assertSame(-1, $arr[-1]);
+ $arr[MIN_UINT32_STRING] = MIN_UINT32_STRING;
+ $this->assertSame(MIN_UINT32, $arr[MIN_UINT32]);
+ $this->assertEquals(4, count($arr));
+ unset($arr['7']);
+ unset($arr['3.1']);
+ unset($arr['-1.0']);
+ unset($arr[MIN_UINT32_STRING]);
+ $this->assertEquals(0, count($arr));
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint32SetStringKeyFail()
+ {
+ $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
+ $arr ['abc']= 0;
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint32SetStringValueFail()
+ {
+ $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
+ $arr [0]= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint32SetMessageKeyFail()
+ {
+ $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
+ $arr [new TestMessage_Sub()]= 0;
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint32SetMessageValueFail()
+ {
+ $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
+ $arr [0]= new TestMessage_Sub();
+ }
+
+ #########################################################
+ # Test int64 field.
+ #########################################################
+
+ public function testInt64() {
+ $arr = new MapField(GPBType::INT64, GPBType::INT64);
+
+ // Test integer argument.
+ $arr[MAX_INT64] = MAX_INT64;
+ $arr[MIN_INT64] = MIN_INT64;
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame(MAX_INT64_STRING, $arr[MAX_INT64_STRING]);
+ $this->assertSame(MIN_INT64_STRING, $arr[MIN_INT64_STRING]);
+ } else {
+ $this->assertSame(MAX_INT64, $arr[MAX_INT64]);
+ $this->assertSame(MIN_INT64, $arr[MIN_INT64]);
+ }
+ $this->assertEquals(2, count($arr));
+ unset($arr[MAX_INT64]);
+ unset($arr[MIN_INT64]);
+ $this->assertEquals(0, count($arr));
+
+ // Test float argument.
+ $arr[1.1] = 1.1;
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('1', $arr['1']);
+ } else {
+ $this->assertSame(1, $arr[1]);
+ }
+ $this->assertEquals(1, count($arr));
+ unset($arr[1.1]);
+ $this->assertEquals(0, count($arr));
+
+ // Test string argument.
+ $arr['2'] = '2';
+ $arr['3.1'] = '3.1';
+ $arr[MAX_INT64_STRING] = MAX_INT64_STRING;
+ $arr[MIN_INT64_STRING] = MIN_INT64_STRING;
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('2', $arr['2']);
+ $this->assertSame('3', $arr['3']);
+ $this->assertSame(MAX_INT64_STRING, $arr[MAX_INT64_STRING]);
+ $this->assertSame(MIN_INT64_STRING, $arr[MIN_INT64_STRING]);
+ } else {
+ $this->assertSame(2, $arr[2]);
+ $this->assertSame(3, $arr[3]);
+ $this->assertSame(MAX_INT64, $arr[MAX_INT64]);
+ $this->assertSame(MIN_INT64, $arr[MIN_INT64]);
+ }
+ $this->assertEquals(4, count($arr));
+ unset($arr['2']);
+ unset($arr['3.1']);
+ unset($arr[MAX_INT64_STRING]);
+ unset($arr[MIN_INT64_STRING]);
+ $this->assertEquals(0, count($arr));
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt64SetStringKeyFail()
+ {
+ $arr = new MapField(GPBType::INT64, GPBType::INT64);
+ $arr ['abc']= 0;
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt64SetStringValueFail()
+ {
+ $arr = new MapField(GPBType::INT64, GPBType::INT64);
+ $arr [0]= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt64SetMessageKeyFail()
+ {
+ $arr = new MapField(GPBType::INT64, GPBType::INT64);
+ $arr [new TestMessage_Sub()]= 0;
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testInt64SetMessageValueFail()
+ {
+ $arr = new MapField(GPBType::INT64, GPBType::INT64);
+ $arr [0]= new TestMessage_Sub();
+ }
+
+ #########################################################
+ # Test uint64 field.
+ #########################################################
+
+ public function testUint64() {
+ $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
+
+ // Test integer argument.
+ $arr[MAX_UINT64] = MAX_UINT64;
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame(MAX_UINT64_STRING, $arr[MAX_UINT64_STRING]);
+ } else {
+ $this->assertSame(MAX_UINT64, $arr[MAX_UINT64]);
+ }
+ $this->assertEquals(1, count($arr));
+ unset($arr[MAX_UINT64]);
+ $this->assertEquals(0, count($arr));
+
+ // Test float argument.
+ $arr[1.1] = 1.1;
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('1', $arr['1']);
+ } else {
+ $this->assertSame(1, $arr[1]);
+ }
+ $this->assertEquals(1, count($arr));
+ unset($arr[1.1]);
+ $this->assertEquals(0, count($arr));
+
+ // Test string argument.
+ $arr['2'] = '2';
+ $arr['3.1'] = '3.1';
+ $arr[MAX_UINT64_STRING] = MAX_UINT64_STRING;
+
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('2', $arr['2']);
+ $this->assertSame('3', $arr['3']);
+ $this->assertSame(MAX_UINT64_STRING, $arr[MAX_UINT64_STRING]);
+ } else {
+ $this->assertSame(2, $arr[2]);
+ $this->assertSame(3, $arr[3]);
+ $this->assertSame(MAX_UINT64, $arr[MAX_UINT64]);
+ }
+
+ $this->assertEquals(3, count($arr));
+ unset($arr['2']);
+ unset($arr['3.1']);
+ unset($arr[MAX_UINT64_STRING]);
+ $this->assertEquals(0, count($arr));
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint64SetStringKeyFail()
+ {
+ $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
+ $arr ['abc']= 0;
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint64SetStringValueFail()
+ {
+ $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
+ $arr [0]= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint64SetMessageKeyFail()
+ {
+ $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
+ $arr [new TestMessage_Sub()]= 0;
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testUint64SetMessageValueFail()
+ {
+ $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
+ $arr [0]= new TestMessage_Sub();
+ }
+
+ #########################################################
+ # Test float field.
+ #########################################################
+
+ public function testFloat() {
+ $arr = new MapField(GPBType::INT32, GPBType::FLOAT);
+
+ // Test set.
+ $arr[0] = 1;
+ $this->assertEquals(1.0, $arr[0], '', MAX_FLOAT_DIFF);
+
+ $arr[1] = 1.1;
+ $this->assertEquals(1.1, $arr[1], '', MAX_FLOAT_DIFF);
+
+ $arr[2] = '2';
+ $this->assertEquals(2.0, $arr[2], '', MAX_FLOAT_DIFF);
+ $arr[3] = '3.1';
+ $this->assertEquals(3.1, $arr[3], '', MAX_FLOAT_DIFF);
+
+ $this->assertEquals(4, count($arr));
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testFloatSetStringValueFail()
+ {
+ $arr = new MapField(GPBType::INT64, GPBType::FLOAT);
+ $arr [0]= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testFloatSetMessageValueFail()
+ {
+ $arr = new MapField(GPBType::INT64, GPBType::FLOAT);
+ $arr [0]= new TestMessage_Sub();
+ }
+
+ #########################################################
+ # Test double field.
+ #########################################################
+
+ public function testDouble() {
+ $arr = new MapField(GPBType::INT32, GPBType::DOUBLE);
+
+ // Test set.
+ $arr[0] = 1;
+ $this->assertEquals(1.0, $arr[0], '', MAX_FLOAT_DIFF);
+
+ $arr[1] = 1.1;
+ $this->assertEquals(1.1, $arr[1], '', MAX_FLOAT_DIFF);
+
+ $arr[2] = '2';
+ $this->assertEquals(2.0, $arr[2], '', MAX_FLOAT_DIFF);
+ $arr[3] = '3.1';
+ $this->assertEquals(3.1, $arr[3], '', MAX_FLOAT_DIFF);
+
+ $this->assertEquals(4, count($arr));
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testDoubleSetStringValueFail()
+ {
+ $arr = new MapField(GPBType::INT64, GPBType::DOUBLE);
+ $arr [0]= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testDoubleSetMessageValueFail()
+ {
+ $arr = new MapField(GPBType::INT64, GPBType::DOUBLE);
+ $arr [0]= new TestMessage_Sub();
+ }
+
+ #########################################################
+ # Test bool field.
+ #########################################################
+
+ public function testBool() {
+ $arr = new MapField(GPBType::BOOL, GPBType::BOOL);
+
+ // Test boolean.
+ $arr[True] = True;
+ $this->assertSame(True, $arr[True]);
+ $this->assertEquals(1, count($arr));
+ unset($arr[True]);
+ $this->assertEquals(0, count($arr));
+
+ $arr[False] = False;
+ $this->assertSame(False, $arr[False]);
+ $this->assertEquals(1, count($arr));
+ unset($arr[False]);
+ $this->assertEquals(0, count($arr));
+
+ // Test integer.
+ $arr[-1] = -1;
+ $this->assertSame(True, $arr[True]);
+ $this->assertEquals(1, count($arr));
+ unset($arr[-1]);
+ $this->assertEquals(0, count($arr));
+
+ $arr[0] = 0;
+ $this->assertSame(False, $arr[False]);
+ $this->assertEquals(1, count($arr));
+ unset($arr[0]);
+ $this->assertEquals(0, count($arr));
+
+ // Test float.
+ $arr[1.1] = 1.1;
+ $this->assertSame(True, $arr[True]);
+ $this->assertEquals(1, count($arr));
+ unset($arr[1.1]);
+ $this->assertEquals(0, count($arr));
+
+ $arr[0.0] = 0.0;
+ $this->assertSame(False, $arr[False]);
+ $this->assertEquals(1, count($arr));
+ unset($arr[0.0]);
+ $this->assertEquals(0, count($arr));
+
+ // Test string.
+ $arr['a'] = 'a';
+ $this->assertSame(True, $arr[True]);
+ $this->assertEquals(1, count($arr));
+ unset($arr['a']);
+ $this->assertEquals(0, count($arr));
+
+ $arr[''] = '';
+ $this->assertSame(False, $arr[False]);
+ $this->assertEquals(1, count($arr));
+ unset($arr['']);
+ $this->assertEquals(0, count($arr));
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testBoolSetMessageKeyFail()
+ {
+ $arr = new MapField(GPBType::BOOL, GPBType::BOOL);
+ $arr [new TestMessage_Sub()]= true;
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testBoolSetMessageValueFail()
+ {
+ $arr = new MapField(GPBType::BOOL, GPBType::BOOL);
+ $arr [true]= new TestMessage_Sub();
+ }
+
+ #########################################################
+ # Test string field.
+ #########################################################
+
+ public function testString() {
+ $arr = new MapField(GPBType::STRING, GPBType::STRING);
+
+ // Test set.
+ $arr['abc'] = 'abc';
+ $this->assertSame('abc', $arr['abc']);
+ $this->assertEquals(1, count($arr));
+ unset($arr['abc']);
+ $this->assertEquals(0, count($arr));
+
+ $arr[1] = 1;
+ $this->assertSame('1', $arr['1']);
+ $this->assertEquals(1, count($arr));
+ unset($arr[1]);
+ $this->assertEquals(0, count($arr));
+
+ $arr[1.1] = 1.1;
+ $this->assertSame('1.1', $arr['1.1']);
+ $this->assertEquals(1, count($arr));
+ unset($arr[1.1]);
+ $this->assertEquals(0, count($arr));
+
+ $arr[True] = True;
+ $this->assertSame('1', $arr['1']);
+ $this->assertEquals(1, count($arr));
+ unset($arr[True]);
+ $this->assertEquals(0, count($arr));
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testStringSetInvalidUTF8KeyFail()
+ {
+ $arr = new MapField(GPBType::STRING, GPBType::STRING);
+ $arr[hex2bin("ff")]= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testStringSetInvalidUTF8ValueFail()
+ {
+ $arr = new MapField(GPBType::STRING, GPBType::STRING);
+ $arr ['abc']= hex2bin("ff");
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testStringSetMessageKeyFail()
+ {
+ $arr = new MapField(GPBType::STRING, GPBType::STRING);
+ $arr [new TestMessage_Sub()]= 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testStringSetMessageValueFail()
+ {
+ $arr = new MapField(GPBType::STRING, GPBType::STRING);
+ $arr ['abc']= new TestMessage_Sub();
+ }
+
+ #########################################################
+ # Test message field.
+ #########################################################
+
+ public function testMessage() {
+ $arr = new MapField(GPBType::INT32,
+ GPBType::MESSAGE, TestMessage_Sub::class);
+
+ // Test append.
+ $sub_m = new TestMessage_Sub();
+ $sub_m->setA(1);
+ $arr[0] = $sub_m;
+ $this->assertSame(1, $arr[0]->getA());
+
+ $null = NULL;
+ $arr[1] = $null;
+ $this->assertNull($arr[1]);
+
+ $this->assertEquals(2, count($arr));
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testMessageSetIntValueFail()
+ {
+ $arr =
+ new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
+ $arr[0] = 0;
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testMessageSetStringValueFail()
+ {
+ $arr =
+ new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
+ $arr[0] = 'abc';
+ }
+
+ /**
+ * @expectedException PHPUnit_Framework_Error
+ */
+ public function testMessageSetOtherMessageValueFail()
+ {
+ $arr =
+ new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
+ $arr[0] = new TestMessage_Sub();
+ }
+
+ #########################################################
+ # Test memory leak
+ #########################################################
+
+ // TODO(teboring): Add it back.
+ // public function testCycleLeak()
+ // {
+ // $arr = new MapField(GPBType::INT32,
+ // GPBType::MESSAGE, TestMessage::class);
+ // $arr [0]= new TestMessage;
+ // $arr[0]->SetMapRecursive($arr);
+
+ // // Clean up memory before test.
+ // gc_collect_cycles();
+ // $start = memory_get_usage();
+ // unset($arr);
+
+ // // Explicitly trigger garbage collection.
+ // gc_collect_cycles();
+
+ // $end = memory_get_usage();
+ // $this->assertLessThan($start, $end);
+ // }
+}
diff --git a/third_party/protobuf/php/tests/memory_leak_test.php b/third_party/protobuf/php/tests/memory_leak_test.php
new file mode 100644
index 0000000000..5dd79519ae
--- /dev/null
+++ b/third_party/protobuf/php/tests/memory_leak_test.php
@@ -0,0 +1,89 @@
+<?php
+
+# phpunit has memory leak by itself. Thus, it cannot be used to test memory leak.
+
+require_once('generated/PrefixTestPrefix.php');
+require_once('generated/Bar/TestInclude.php');
+require_once('generated/Foo/TestEnum.php');
+require_once('generated/Foo/TestIncludePrefixMessage.php');
+require_once('generated/Foo/TestMessage.php');
+require_once('generated/Foo/TestMessage_Sub.php');
+require_once('generated/Foo/TestPackedMessage.php');
+require_once('generated/Foo/TestPhpDoc.php');
+require_once('generated/Foo/TestUnpackedMessage.php');
+require_once('generated/GPBMetadata/Proto/Test.php');
+require_once('generated/GPBMetadata/Proto/TestInclude.php');
+require_once('generated/GPBMetadata/Proto/TestPrefix.php');
+require_once('test_util.php');
+
+use Google\Protobuf\Internal\RepeatedField;
+use Google\Protobuf\Internal\GPBType;
+use Foo\TestMessage;
+use Foo\TestMessage_Sub;
+
+$from = new TestMessage();
+TestUtil::setTestMessage($from);
+TestUtil::assertTestMessage($from);
+
+$data = $from->serializeToString();
+
+$to = new TestMessage();
+$to->mergeFromString($data);
+
+TestUtil::assertTestMessage($to);
+
+$from->setRecursive($from);
+
+$arr = new RepeatedField(GPBType::MESSAGE, TestMessage::class);
+$arr []= new TestMessage;
+$arr[0]->SetRepeatedRecursive($arr);
+
+// Test oneof fields.
+$m = new TestMessage();
+
+$m->setOneofInt32(1);
+assert(1 === $m->getOneofInt32());
+assert(0.0 === $m->getOneofFloat());
+assert('' === $m->getOneofString());
+assert(NULL === $m->getOneofMessage());
+$data = $m->serializeToString();
+$n = new TestMessage();
+$n->mergeFromString($data);
+assert(1 === $n->getOneofInt32());
+
+$m->setOneofFloat(2.0);
+assert(0 === $m->getOneofInt32());
+assert(2.0 === $m->getOneofFloat());
+assert('' === $m->getOneofString());
+assert(NULL === $m->getOneofMessage());
+$data = $m->serializeToString();
+$n = new TestMessage();
+$n->mergeFromString($data);
+assert(2.0 === $n->getOneofFloat());
+
+$m->setOneofString('abc');
+assert(0 === $m->getOneofInt32());
+assert(0.0 === $m->getOneofFloat());
+assert('abc' === $m->getOneofString());
+assert(NULL === $m->getOneofMessage());
+$data = $m->serializeToString();
+$n = new TestMessage();
+$n->mergeFromString($data);
+assert('abc' === $n->getOneofString());
+
+$sub_m = new TestMessage_Sub();
+$sub_m->setA(1);
+$m->setOneofMessage($sub_m);
+assert(0 === $m->getOneofInt32());
+assert(0.0 === $m->getOneofFloat());
+assert('' === $m->getOneofString());
+assert(1 === $m->getOneofMessage()->getA());
+$data = $m->serializeToString();
+$n = new TestMessage();
+$n->mergeFromString($data);
+assert(1 === $n->getOneofMessage()->getA());
+
+$from = new TestMessage();
+$to = new TestMessage();
+TestUtil::setTestMessage($from);
+$to->mergeFrom($from);
diff --git a/third_party/protobuf/php/tests/php_implementation_test.php b/third_party/protobuf/php/tests/php_implementation_test.php
new file mode 100644
index 0000000000..e124980820
--- /dev/null
+++ b/third_party/protobuf/php/tests/php_implementation_test.php
@@ -0,0 +1,513 @@
+<?php
+
+require_once('test_base.php');
+require_once('test_util.php');
+
+use Foo\TestMessage;
+use Foo\TestMessage_Sub;
+use Foo\TestPackedMessage;
+use Google\Protobuf\Internal\InputStream;
+use Google\Protobuf\Internal\FileDescriptorSet;
+use Google\Protobuf\Internal\GPBLabel;
+use Google\Protobuf\Internal\GPBType;
+use Google\Protobuf\Internal\GPBWire;
+use Google\Protobuf\Internal\OutputStream;
+
+class ImplementationTest extends TestBase
+{
+
+ public function testReadInt32()
+ {
+ $value = null;
+
+ // Positive number.
+ $input = new InputStream(hex2bin("01"));
+ GPBWire::readInt32($input, $value);
+ $this->assertSame(1, $value);
+
+ // Negative number.
+ $input = new InputStream(hex2bin("ffffffff0f"));
+ GPBWire::readInt32($input, $value);
+ $this->assertSame(-1, $value);
+
+ // Discard overflow bits.
+ $input = new InputStream(hex2bin("ffffffff7f"));
+ GPBWire::readInt32($input, $value);
+ $this->assertSame(-1, $value);
+ }
+
+ public function testReadUint32()
+ {
+ $value = null;
+
+ // Positive number.
+ $input = new InputStream(hex2bin("01"));
+ GPBWire::readUint32($input, $value);
+ $this->assertSame(1, $value);
+
+ // Max uint32.
+ $input = new InputStream(hex2bin("ffffffff0f"));
+ GPBWire::readUint32($input, $value);
+ $this->assertSame(-1, $value);
+
+ // Discard overflow bits.
+ $input = new InputStream(hex2bin("ffffffff7f"));
+ GPBWire::readUint32($input, $value);
+ $this->assertSame(-1, $value);
+ }
+
+ public function testReadInt64()
+ {
+ $value = null;
+
+ // Positive number.
+ $input = new InputStream(hex2bin("01"));
+ GPBWire::readInt64($input, $value);
+ $this->assertEquals(1, $value);
+
+ // Negative number.
+ $input = new InputStream(hex2bin("ffffffffffffffffff01"));
+ GPBWire::readInt64($input, $value);
+ $this->assertEquals(-1, $value);
+
+ // Discard overflow bits.
+ $input = new InputStream(hex2bin("ffffffffffffffffff0f"));
+ GPBWire::readInt64($input, $value);
+ $this->assertEquals(-1, $value);
+ }
+
+ public function testReadUint64()
+ {
+ $value = null;
+
+ // Positive number.
+ $input = new InputStream(hex2bin("01"));
+ GPBWire::readUint64($input, $value);
+ $this->assertEquals(1, $value);
+
+ // Negative number.
+ $input = new InputStream(hex2bin("FFFFFFFFFFFFFFFFFF01"));
+ GPBWire::readUint64($input, $value);
+ $this->assertEquals(-1, $value);
+
+ // Discard overflow bits.
+ $input = new InputStream(hex2bin("FFFFFFFFFFFFFFFFFF0F"));
+ GPBWire::readUint64($input, $value);
+ $this->assertEquals(-1, $value);
+ }
+
+ public function testReadSint32()
+ {
+ $value = null;
+
+ $input = new InputStream(hex2bin("00"));
+ GPBWire::readSint32($input, $value);
+ $this->assertSame(0, $value);
+
+ $input = new InputStream(hex2bin("01"));
+ GPBWire::readSint32($input, $value);
+ $this->assertSame(-1, $value);
+
+ $input = new InputStream(hex2bin("02"));
+ GPBWire::readSint32($input, $value);
+ $this->assertSame(1, $value);
+ }
+
+ public function testReadSint64()
+ {
+ $value = null;
+
+ $input = new InputStream(hex2bin("00"));
+ GPBWire::readSint64($input, $value);
+ $this->assertEquals(0, $value);
+
+ $input = new InputStream(hex2bin("01"));
+ GPBWire::readSint64($input, $value);
+ $this->assertEquals(-1, $value);
+
+ $input = new InputStream(hex2bin("02"));
+ GPBWire::readSint64($input, $value);
+ $this->assertEquals(1, $value);
+ }
+
+ public function testReadFixed32()
+ {
+ $value = null;
+ $input = new InputStream(hex2bin("12345678"));
+ GPBWire::readFixed32($input, $value);
+ $this->assertSame(0x78563412, $value);
+ }
+
+ public function testReadFixed64()
+ {
+ $value = null;
+ $input = new InputStream(hex2bin("1234567812345678"));
+ GPBWire::readFixed64($input, $value);
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame("8671175386481439762", $value);
+ } else {
+ $this->assertSame(0x7856341278563412, $value);
+ }
+ }
+
+ public function testReadSfixed32()
+ {
+ $value = null;
+ $input = new InputStream(hex2bin("12345678"));
+ GPBWire::readSfixed32($input, $value);
+ $this->assertSame(0x78563412, $value);
+ }
+
+ public function testReadFloat()
+ {
+ $value = null;
+ $input = new InputStream(hex2bin("0000803F"));
+ GPBWire::readFloat($input, $value);
+ $this->assertSame(1.0, $value);
+ }
+
+ public function testReadBool()
+ {
+ $value = null;
+
+ $input = new InputStream(hex2bin("00"));
+ GPBWire::readBool($input, $value);
+ $this->assertSame(false, $value);
+
+ $input = new InputStream(hex2bin("01"));
+ GPBWire::readBool($input, $value);
+ $this->assertSame(true, $value);
+ }
+
+ public function testReadDouble()
+ {
+ $value = null;
+ $input = new InputStream(hex2bin("000000000000F03F"));
+ GPBWire::readDouble($input, $value);
+ $this->assertSame(1.0, $value);
+ }
+
+ public function testReadSfixed64()
+ {
+ $value = null;
+ $input = new InputStream(hex2bin("1234567812345678"));
+ GPBWire::readSfixed64($input, $value);
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame("8671175386481439762", $value);
+ } else {
+ $this->assertSame(0x7856341278563412, $value);
+ }
+ }
+
+ public function testZigZagEncodeDecode()
+ {
+ $this->assertSame(0, GPBWire::zigZagEncode32(0));
+ $this->assertSame(1, GPBWire::zigZagEncode32(-1));
+ $this->assertSame(2, GPBWire::zigZagEncode32(1));
+ $this->assertSame(3, GPBWire::zigZagEncode32(-2));
+ $this->assertSame(0x7FFFFFFE, GPBWire::zigZagEncode32(0x3FFFFFFF));
+ $this->assertSame(0x7FFFFFFF, GPBWire::zigZagEncode32(0xC0000000));
+ $this->assertSame(-2, GPBWire::zigZagEncode32(0x7FFFFFFF));
+ $this->assertSame(-1, GPBWire::zigZagEncode32(0x80000000));
+
+ $this->assertSame(0, GPBWire::zigZagDecode32(0));
+ $this->assertSame(-1, GPBWire::zigZagDecode32(1));
+ $this->assertSame(1, GPBWire::zigZagDecode32(2));
+ $this->assertSame(-2, GPBWire::zigZagDecode32(3));
+ $this->assertSame(0x3FFFFFFF, GPBWire::zigZagDecode32(0x7FFFFFFE));
+ $this->assertSame(-1073741824, GPBWire::zigZagDecode32(0x7FFFFFFF));
+ $this->assertSame(0x7FFFFFFF, GPBWire::zigZagDecode32(0xFFFFFFFE));
+ $this->assertSame((int)-2147483648,GPBWire::zigZagDecode32(0xFFFFFFFF));
+
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('0', GPBWire::zigZagEncode64(0));
+ $this->assertSame('1', GPBWire::zigZagEncode64(-1));
+ $this->assertSame('2', GPBWire::zigZagEncode64(1));
+ $this->assertSame('3', GPBWire::zigZagEncode64(-2));
+ $this->assertSame(
+ '2147483646', // 0x7FFFFFE
+ GPBWire::zigZagEncode64(0x3FFFFFFF));
+ $this->assertSame(
+ '2147483647', // 0x7FFFFFF
+ GPBWire::zigZagEncode64(-1073741824)); // 0xFFFFFFFFC0000000
+ $this->assertSame(
+ '4294967294', // 0xFFFFFFFE
+ GPBWire::zigZagEncode64(2147483647)); // 0x7FFFFFFF
+ $this->assertSame(
+ '4294967295', // 0xFFFFFFFF
+ GPBWire::zigZagEncode64(-2147483648)); // 0xFFFFFFFF80000000
+ $this->assertSame(
+ '18446744073709551614', // 0xFFFFFFFFFFFFFFFE
+ // 0x7FFFFFFFFFFFFFFF
+ GPBWire::zigZagEncode64("9223372036854775807"));
+ $this->assertSame(
+ '18446744073709551615', // 0xFFFFFFFFFFFFFFFF
+ // 0x8000000000000000
+ GPBWire::zigZagEncode64("-9223372036854775808"));
+
+ $this->assertSame('0', GPBWire::zigZagDecode64(0));
+ $this->assertSame('-1', GPBWire::zigZagDecode64(1));
+ $this->assertSame('1', GPBWire::zigZagDecode64(2));
+ $this->assertSame('-2', GPBWire::zigZagDecode64(3));
+ } else {
+ $this->assertSame(0, GPBWire::zigZagEncode64(0));
+ $this->assertSame(1, GPBWire::zigZagEncode64(-1));
+ $this->assertSame(2, GPBWire::zigZagEncode64(1));
+ $this->assertSame(3, GPBWire::zigZagEncode64(-2));
+ $this->assertSame(0x7FFFFFFE, GPBWire::zigZagEncode64(0x3FFFFFFF));
+ $this->assertSame(
+ 0x7FFFFFFF,
+ GPBWire::zigZagEncode64(0xFFFFFFFFC0000000));
+ $this->assertSame(
+ 0xFFFFFFFE,
+ GPBWire::zigZagEncode64(0x7FFFFFFF));
+ $this->assertSame(
+ 0xFFFFFFFF,
+ GPBWire::zigZagEncode64(0xFFFFFFFF80000000));
+ $this->assertSame(
+ -2, // 0xFFFFFFFFFFFFFFFE
+ GPBWire::zigZagEncode64(0x7FFFFFFFFFFFFFFF));
+ $this->assertSame(
+ -1, // 0xFFFFFFFFFFFFFFFF
+ GPBWire::zigZagEncode64(0x8000000000000000));
+
+ $this->assertSame(0, GPBWire::zigZagDecode64(0));
+ $this->assertSame(-1, GPBWire::zigZagDecode64(1));
+ $this->assertSame(1, GPBWire::zigZagDecode64(2));
+ $this->assertSame(-2, GPBWire::zigZagDecode64(3));
+ }
+
+ // Round trip
+ $this->assertSame(0, GPBWire::zigZagDecode32(GPBWire::zigZagEncode32(0)));
+ $this->assertSame(1, GPBWire::zigZagDecode32(GPBWire::zigZagEncode32(1)));
+ $this->assertSame(-1, GPBWire::zigZagDecode32(GPBWire::zigZagEncode32(-1)));
+ $this->assertSame(14927,
+ GPBWire::zigZagDecode32(GPBWire::zigZagEncode32(14927)));
+ $this->assertSame(-3612,
+ GPBWire::zigZagDecode32(GPBWire::zigZagEncode32(-3612)));
+ }
+
+ public function testDecode()
+ {
+ $m = new TestMessage();
+ $m->mergeFromString(TestUtil::getGoldenTestMessage());
+ TestUtil::assertTestMessage($m);
+ }
+
+ public function testDescriptorDecode()
+ {
+ $file_desc_set = new FileDescriptorSet();
+ $file_desc_set->mergeFromString(hex2bin(
+ "0a3b0a12746573745f696e636c7564652e70726f746f120362617222180a" .
+ "0b54657374496e636c75646512090a0161180120012805620670726f746f33"));
+
+ $this->assertSame(1, sizeof($file_desc_set->getFile()));
+
+ $file_desc = $file_desc_set->getFile()[0];
+ $this->assertSame("test_include.proto", $file_desc->getName());
+ $this->assertSame("bar", $file_desc->getPackage());
+ $this->assertSame(0, sizeof($file_desc->getDependency()));
+ $this->assertSame(1, sizeof($file_desc->getMessageType()));
+ $this->assertSame(0, sizeof($file_desc->getEnumType()));
+ $this->assertSame("proto3", $file_desc->getSyntax());
+
+ $desc = $file_desc->getMessageType()[0];
+ $this->assertSame("TestInclude", $desc->getName());
+ $this->assertSame(1, sizeof($desc->getField()));
+ $this->assertSame(0, sizeof($desc->getNestedType()));
+ $this->assertSame(0, sizeof($desc->getEnumType()));
+ $this->assertSame(0, sizeof($desc->getOneofDecl()));
+
+ $field = $desc->getField()[0];
+ $this->assertSame("a", $field->getName());
+ $this->assertSame(1, $field->getNumber());
+ $this->assertSame(GPBLabel::OPTIONAL, $field->getLabel());
+ $this->assertSame(GPBType::INT32, $field->getType());
+ }
+
+ public function testReadVarint64()
+ {
+ $var = 0;
+
+ // Empty buffer.
+ $input = new InputStream(hex2bin(''));
+ $this->assertFalse($input->readVarint64($var));
+
+ // The largest varint is 10 bytes long.
+ $input = new InputStream(hex2bin('8080808080808080808001'));
+ $this->assertFalse($input->readVarint64($var));
+
+ // Corrupted varint.
+ $input = new InputStream(hex2bin('808080'));
+ $this->assertFalse($input->readVarint64($var));
+
+ // Normal case.
+ $input = new InputStream(hex2bin('808001'));
+ $this->assertTrue($input->readVarint64($var));
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('16384', $var);
+ } else {
+ $this->assertSame(16384, $var);
+ }
+ $this->assertFalse($input->readVarint64($var));
+
+ // Read two varint.
+ $input = new InputStream(hex2bin('808001808002'));
+ $this->assertTrue($input->readVarint64($var));
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('16384', $var);
+ } else {
+ $this->assertSame(16384, $var);
+ }
+ $this->assertTrue($input->readVarint64($var));
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('32768', $var);
+ } else {
+ $this->assertSame(32768, $var);
+ }
+ $this->assertFalse($input->readVarint64($var));
+
+ // Read 64 testing
+ $testVals = array(
+ '10' => '0a000000000000000000',
+ '100' => '64000000000000000000',
+ '800' => 'a0060000000000000000',
+ '6400' => '80320000000000000000',
+ '70400' => '80a60400000000000000',
+ '774400' => '80a22f00000000000000',
+ '9292800' => '8098b704000000000000',
+ '74342400' => '80c0b923000000000000',
+ '743424000' => '8080bfe2020000000000',
+ '8177664000' => '8080b5bb1e0000000000',
+ '65421312000' => '8080a8dbf30100000000',
+ '785055744000' => '8080e0c7ec1600000000',
+ '9420668928000' => '808080dd969202000000',
+ '103627358208000' => '808080fff9c717000000',
+ '1139900940288000' => '808080f5bd9783020000',
+ '13678811283456000' => '808080fce699a6180000',
+ '109430490267648000' => '808080e0b7ceb1c20100',
+ '984874412408832000' => '808080e0f5c1bed50d00',
+ );
+
+ foreach ($testVals as $original => $encoded) {
+ $input = new InputStream(hex2bin($encoded));
+ $this->assertTrue($input->readVarint64($var));
+ $this->assertEquals($original, $var);
+ }
+ }
+
+ public function testReadVarint32()
+ {
+ $var = 0;
+
+ // Empty buffer.
+ $input = new InputStream(hex2bin(''));
+ $this->assertFalse($input->readVarint32($var));
+
+ // The largest varint is 10 bytes long.
+ $input = new InputStream(hex2bin('8080808080808080808001'));
+ $this->assertFalse($input->readVarint32($var));
+
+ // Corrupted varint.
+ $input = new InputStream(hex2bin('808080'));
+ $this->assertFalse($input->readVarint32($var));
+
+ // Normal case.
+ $input = new InputStream(hex2bin('808001'));
+ $this->assertTrue($input->readVarint32($var));
+ $this->assertSame(16384, $var);
+ $this->assertFalse($input->readVarint32($var));
+
+ // Read two varint.
+ $input = new InputStream(hex2bin('808001808002'));
+ $this->assertTrue($input->readVarint32($var));
+ $this->assertSame(16384, $var);
+ $this->assertTrue($input->readVarint32($var));
+ $this->assertSame(32768, $var);
+ $this->assertFalse($input->readVarint32($var));
+
+ // Read a 64-bit integer. High-order bits should be discarded.
+ $input = new InputStream(hex2bin('808081808001'));
+ $this->assertTrue($input->readVarint32($var));
+ $this->assertSame(16384, $var);
+ $this->assertFalse($input->readVarint32($var));
+ }
+
+ public function testReadTag()
+ {
+ $input = new InputStream(hex2bin('808001'));
+ $tag = $input->readTag();
+ $this->assertSame(16384, $tag);
+ $tag = $input->readTag();
+ $this->assertSame(0, $tag);
+ }
+
+ public function testPushPopLimit()
+ {
+ $input = new InputStream(hex2bin('808001'));
+ $old_limit = $input->pushLimit(0);
+ $tag = $input->readTag();
+ $this->assertSame(0, $tag);
+ $input->popLimit($old_limit);
+ $tag = $input->readTag();
+ $this->assertSame(16384, $tag);
+ }
+
+ public function testReadRaw()
+ {
+ $input = new InputStream(hex2bin('808001'));
+ $buffer = null;
+
+ $this->assertTrue($input->readRaw(3, $buffer));
+ $this->assertSame(hex2bin('808001'), $buffer);
+
+ $this->assertFalse($input->readRaw(1, $buffer));
+ }
+
+ public function testWriteVarint32()
+ {
+ $output = new OutputStream(3);
+ $output->writeVarint32(16384);
+ $this->assertSame(hex2bin('808001'), $output->getData());
+
+ // Negative numbers are padded to be compatible with int64.
+ $output = new OutputStream(10);
+ $output->writeVarint32(-43);
+ $this->assertSame(hex2bin('D5FFFFFFFFFFFFFFFF01'), $output->getData());
+ }
+
+ public function testWriteVarint64()
+ {
+ $output = new OutputStream(10);
+ $output->writeVarint64(-43);
+ $this->assertSame(hex2bin('D5FFFFFFFFFFFFFFFF01'), $output->getData());
+ }
+
+ public function testWriteLittleEndian32()
+ {
+ $output = new OutputStream(4);
+ $output->writeLittleEndian32(46);
+ $this->assertSame(hex2bin('2E000000'), $output->getData());
+ }
+
+ public function testWriteLittleEndian64()
+ {
+ $output = new OutputStream(8);
+ $output->writeLittleEndian64(47);
+ $this->assertSame(hex2bin('2F00000000000000'), $output->getData());
+ }
+
+ public function testByteSize()
+ {
+ $m = new TestMessage();
+ TestUtil::setTestMessage($m);
+ $this->assertSame(506, $m->byteSize());
+ }
+
+ public function testPackedByteSize()
+ {
+ $m = new TestPackedMessage();
+ TestUtil::setTestPackedMessage($m);
+ $this->assertSame(166, $m->byteSize());
+ }
+}
diff --git a/third_party/protobuf/php/tests/proto/test.proto b/third_party/protobuf/php/tests/proto/test.proto
new file mode 100644
index 0000000000..1a47a3f291
--- /dev/null
+++ b/third_party/protobuf/php/tests/proto/test.proto
@@ -0,0 +1,149 @@
+syntax = "proto3";
+
+import 'proto/test_include.proto';
+import 'proto/test_prefix.proto';
+
+package foo;
+
+message TestMessage {
+ // Singular
+ int32 optional_int32 = 1;
+ int64 optional_int64 = 2;
+ uint32 optional_uint32 = 3;
+ uint64 optional_uint64 = 4;
+ sint32 optional_sint32 = 5;
+ sint64 optional_sint64 = 6;
+ fixed32 optional_fixed32 = 7;
+ fixed64 optional_fixed64 = 8;
+ sfixed32 optional_sfixed32 = 9;
+ sfixed64 optional_sfixed64 = 10;
+ float optional_float = 11;
+ double optional_double = 12;
+ bool optional_bool = 13;
+ string optional_string = 14;
+ bytes optional_bytes = 15;
+
+ TestEnum optional_enum = 16;
+ Sub optional_message = 17;
+ bar.TestInclude optional_included_message = 18;
+ TestMessage recursive = 19;
+
+ // Repeated
+ repeated int32 repeated_int32 = 31;
+ repeated int64 repeated_int64 = 32;
+ repeated uint32 repeated_uint32 = 33;
+ repeated uint64 repeated_uint64 = 34;
+ repeated sint32 repeated_sint32 = 35;
+ repeated sint64 repeated_sint64 = 36;
+ repeated fixed32 repeated_fixed32 = 37;
+ repeated fixed64 repeated_fixed64 = 38;
+ repeated sfixed32 repeated_sfixed32 = 39;
+ repeated sfixed64 repeated_sfixed64 = 40;
+ repeated float repeated_float = 41;
+ repeated double repeated_double = 42;
+ repeated bool repeated_bool = 43;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+
+ repeated TestEnum repeated_enum = 46;
+ repeated Sub repeated_message = 47;
+ repeated TestMessage repeated_recursive = 48;
+
+ oneof my_oneof {
+ int32 oneof_int32 = 51;
+ int64 oneof_int64 = 52;
+ uint32 oneof_uint32 = 53;
+ uint64 oneof_uint64 = 54;
+ uint32 oneof_sint32 = 55;
+ uint64 oneof_sint64 = 56;
+ uint32 oneof_fixed32 = 57;
+ uint64 oneof_fixed64 = 58;
+ uint32 oneof_sfixed32 = 59;
+ uint64 oneof_sfixed64 = 60;
+ double oneof_double = 61;
+ float oneof_float = 62;
+ bool oneof_bool = 63;
+ string oneof_string = 64;
+ bytes oneof_bytes = 65;
+ TestEnum oneof_enum = 66;
+ Sub oneof_message = 67;
+ }
+
+ map<int32, int32> map_int32_int32 = 71;
+ map<int64, int64> map_int64_int64 = 72;
+ map<uint32, uint32> map_uint32_uint32 = 73;
+ map<uint64, uint64> map_uint64_uint64 = 74;
+ map<sint32, sint32> map_sint32_sint32 = 75;
+ map<sint64, sint64> map_sint64_sint64 = 76;
+ map<fixed32, fixed32> map_fixed32_fixed32 = 77;
+ map<fixed64, fixed64> map_fixed64_fixed64 = 78;
+ map<sfixed32, sfixed32> map_sfixed32_sfixed32 = 79;
+ map<sfixed64, sfixed64> map_sfixed64_sfixed64 = 80;
+ map<int32, float> map_int32_float = 81;
+ map<int32, double> map_int32_double = 82;
+ map<bool, bool> map_bool_bool = 83;
+ map<string, string> map_string_string = 84;
+ map<int32, bytes> map_int32_bytes = 85;
+ map<int32, TestEnum> map_int32_enum = 86;
+ map<int32, Sub> map_int32_message = 87;
+
+ map<int32, TestMessage> map_recursive = 88;
+
+ message Sub {
+ int32 a = 1;
+ repeated int32 b = 2;
+ }
+
+ // Reserved for non-existing field test.
+ // int32 non_exist = 89;
+}
+
+enum TestEnum {
+ ZERO = 0;
+ ONE = 1;
+ TWO = 2;
+}
+
+message TestPackedMessage {
+ repeated int32 repeated_int32 = 90 [packed = true];
+ repeated int64 repeated_int64 = 91 [packed = true];
+ repeated uint32 repeated_uint32 = 92 [packed = true];
+ repeated uint64 repeated_uint64 = 93 [packed = true];
+ repeated sint32 repeated_sint32 = 94 [packed = true];
+ repeated sint64 repeated_sint64 = 95 [packed = true];
+ repeated fixed32 repeated_fixed32 = 96 [packed = true];
+ repeated fixed64 repeated_fixed64 = 97 [packed = true];
+ repeated sfixed32 repeated_sfixed32 = 98 [packed = true];
+ repeated sfixed64 repeated_sfixed64 = 99 [packed = true];
+ repeated float repeated_float = 100 [packed = true];
+ repeated double repeated_double = 101 [packed = true];
+ repeated bool repeated_bool = 102 [packed = true];
+ repeated TestEnum repeated_enum = 103 [packed = true];
+}
+
+// Need to be in sync with TestPackedMessage.
+message TestUnpackedMessage {
+ repeated int32 repeated_int32 = 90 [packed = false];
+ repeated int64 repeated_int64 = 91 [packed = false];
+ repeated uint32 repeated_uint32 = 92 [packed = false];
+ repeated uint64 repeated_uint64 = 93 [packed = false];
+ repeated sint32 repeated_sint32 = 94 [packed = false];
+ repeated sint64 repeated_sint64 = 95 [packed = false];
+ repeated fixed32 repeated_fixed32 = 96 [packed = false];
+ repeated fixed64 repeated_fixed64 = 97 [packed = false];
+ repeated sfixed32 repeated_sfixed32 = 98 [packed = false];
+ repeated sfixed64 repeated_sfixed64 = 99 [packed = false];
+ repeated float repeated_float = 100 [packed = false];
+ repeated double repeated_double = 101 [packed = false];
+ repeated bool repeated_bool = 102 [packed = false];
+ repeated TestEnum repeated_enum = 103 [packed = false];
+}
+
+// /**/@<>&\{
+message TestPhpDoc {
+ int32 a = 1;
+}
+
+message TestIncludePrefixMessage {
+ TestPrefix prefix_message = 1;
+}
diff --git a/third_party/protobuf/php/tests/proto/test_include.proto b/third_party/protobuf/php/tests/proto/test_include.proto
new file mode 100644
index 0000000000..9844617fa8
--- /dev/null
+++ b/third_party/protobuf/php/tests/proto/test_include.proto
@@ -0,0 +1,7 @@
+syntax = "proto3";
+
+package bar;
+
+message TestInclude {
+ int32 a = 1;
+}
diff --git a/third_party/protobuf/php/tests/proto/test_no_namespace.proto b/third_party/protobuf/php/tests/proto/test_no_namespace.proto
new file mode 100644
index 0000000000..b8c4fdf2fc
--- /dev/null
+++ b/third_party/protobuf/php/tests/proto/test_no_namespace.proto
@@ -0,0 +1,10 @@
+syntax = "proto3";
+
+message NoNameSpaceMessage {
+ int32 a = 1;
+}
+
+enum NoNameSpaceEnum {
+ VALUE_A = 0;
+ VALUE_B = 1;
+}
diff --git a/third_party/protobuf/php/tests/proto/test_prefix.proto b/third_party/protobuf/php/tests/proto/test_prefix.proto
new file mode 100644
index 0000000000..045821217c
--- /dev/null
+++ b/third_party/protobuf/php/tests/proto/test_prefix.proto
@@ -0,0 +1,7 @@
+syntax = "proto3";
+
+option php_class_prefix = "Prefix";
+
+message TestPrefix {
+ int32 a = 1;
+}
diff --git a/third_party/protobuf/php/tests/test.sh b/third_party/protobuf/php/tests/test.sh
new file mode 100755
index 0000000000..fc3f018650
--- /dev/null
+++ b/third_party/protobuf/php/tests/test.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# Compile c extension
+pushd ../ext/google/protobuf/
+make clean
+set -e
+# Add following in configure for debug: --enable-debug CFLAGS='-g -O0'
+phpize && ./configure --enable-debug CFLAGS='-g -O0' && make
+popd
+
+tests=( array_test.php encode_decode_test.php generated_class_test.php map_field_test.php well_known_test.php )
+
+for t in "${tests[@]}"
+do
+ echo "****************************"
+ echo "* $t"
+ echo "****************************"
+ php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php $t
+ echo ""
+done
+
+# # Make sure to run the memory test in debug mode.
+# php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php
+
+export ZEND_DONT_UNLOAD_MODULES=1
+export USE_ZEND_ALLOC=0
+valgrind --leak-check=yes php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php
diff --git a/third_party/protobuf/php/tests/test_base.php b/third_party/protobuf/php/tests/test_base.php
new file mode 100644
index 0000000000..67048f4cae
--- /dev/null
+++ b/third_party/protobuf/php/tests/test_base.php
@@ -0,0 +1,339 @@
+<?php
+
+use Foo\TestMessage;
+use Foo\TestEnum;
+use Foo\TestMessage_Sub;
+
+class TestBase extends PHPUnit_Framework_TestCase
+{
+
+ public function setFields(TestMessage $m)
+ {
+ TestUtil::setTestMessage($m);
+ }
+
+ public function setFields2(TestMessage $m)
+ {
+ TestUtil::setTestMessage2($m);
+ }
+
+ public function expectFields(TestMessage $m)
+ {
+ $this->assertSame(-44, $m->getOptionalSint32());
+ $this->assertSame(46, $m->getOptionalFixed32());
+ $this->assertSame(-46, $m->getOptionalSfixed32());
+ $this->assertSame(1.5, $m->getOptionalFloat());
+ $this->assertSame(1.6, $m->getOptionalDouble());
+ $this->assertSame(true, $m->getOptionalBool());
+ $this->assertSame('a', $m->getOptionalString());
+ $this->assertSame('b', $m->getOptionalBytes());
+ $this->assertSame(33, $m->getOptionalMessage()->getA());
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('-43', $m->getOptionalInt64());
+ $this->assertSame('43', $m->getOptionalUint64());
+ $this->assertSame('-45', $m->getOptionalSint64());
+ $this->assertSame('47', $m->getOptionalFixed64());
+ $this->assertSame('-47', $m->getOptionalSfixed64());
+ } else {
+ $this->assertSame(-43, $m->getOptionalInt64());
+ $this->assertSame(43, $m->getOptionalUint64());
+ $this->assertSame(-45, $m->getOptionalSint64());
+ $this->assertSame(47, $m->getOptionalFixed64());
+ $this->assertSame(-47, $m->getOptionalSfixed64());
+ }
+
+ $this->assertEquals(-42, $m->getRepeatedInt32()[0]);
+ $this->assertEquals(42, $m->getRepeatedUint32()[0]);
+ $this->assertEquals(-43, $m->getRepeatedInt64()[0]);
+ $this->assertEquals(43, $m->getRepeatedUint64()[0]);
+ $this->assertEquals(-44, $m->getRepeatedSint32()[0]);
+ $this->assertEquals(-45, $m->getRepeatedSint64()[0]);
+ $this->assertEquals(46, $m->getRepeatedFixed32()[0]);
+ $this->assertEquals(47, $m->getRepeatedFixed64()[0]);
+ $this->assertEquals(-46, $m->getRepeatedSfixed32()[0]);
+ $this->assertEquals(-47, $m->getRepeatedSfixed64()[0]);
+ $this->assertEquals(1.5, $m->getRepeatedFloat()[0]);
+ $this->assertEquals(1.6, $m->getRepeatedDouble()[0]);
+ $this->assertEquals(true, $m->getRepeatedBool()[0]);
+ $this->assertEquals('a', $m->getRepeatedString()[0]);
+ $this->assertEquals('b', $m->getRepeatedBytes()[0]);
+ $this->assertEquals(34, $m->getRepeatedMessage()[0]->GetA());
+
+ $this->assertEquals(-52, $m->getRepeatedInt32()[1]);
+ $this->assertEquals(52, $m->getRepeatedUint32()[1]);
+ $this->assertEquals(-53, $m->getRepeatedInt64()[1]);
+ $this->assertEquals(53, $m->getRepeatedUint64()[1]);
+ $this->assertEquals(-54, $m->getRepeatedSint32()[1]);
+ $this->assertEquals(-55, $m->getRepeatedSint64()[1]);
+ $this->assertEquals(56, $m->getRepeatedFixed32()[1]);
+ $this->assertEquals(57, $m->getRepeatedFixed64()[1]);
+ $this->assertEquals(-56, $m->getRepeatedSfixed32()[1]);
+ $this->assertEquals(-57, $m->getRepeatedSfixed64()[1]);
+ $this->assertEquals(2.5, $m->getRepeatedFloat()[1]);
+ $this->assertEquals(2.6, $m->getRepeatedDouble()[1]);
+ $this->assertEquals(false, $m->getRepeatedBool()[1]);
+ $this->assertEquals('c', $m->getRepeatedString()[1]);
+ $this->assertEquals('d', $m->getRepeatedBytes()[1]);
+ $this->assertEquals(35, $m->getRepeatedMessage()[1]->GetA());
+
+ if (PHP_INT_SIZE == 4) {
+ $this->assertEquals('-63', $m->getMapInt64Int64()['-63']);
+ $this->assertEquals('63', $m->getMapUint64Uint64()['63']);
+ $this->assertEquals('-65', $m->getMapSint64Sint64()['-65']);
+ $this->assertEquals('67', $m->getMapFixed64Fixed64()['67']);
+ $this->assertEquals('-69', $m->getMapSfixed64Sfixed64()['-69']);
+ } else {
+ $this->assertEquals(-63, $m->getMapInt64Int64()[-63]);
+ $this->assertEquals(63, $m->getMapUint64Uint64()[63]);
+ $this->assertEquals(-65, $m->getMapSint64Sint64()[-65]);
+ $this->assertEquals(67, $m->getMapFixed64Fixed64()[67]);
+ $this->assertEquals(-69, $m->getMapSfixed64Sfixed64()[-69]);
+ }
+ $this->assertEquals(-62, $m->getMapInt32Int32()[-62]);
+ $this->assertEquals(62, $m->getMapUint32Uint32()[62]);
+ $this->assertEquals(-64, $m->getMapSint32Sint32()[-64]);
+ $this->assertEquals(66, $m->getMapFixed32Fixed32()[66]);
+ $this->assertEquals(-68, $m->getMapSfixed32Sfixed32()[-68]);
+ $this->assertEquals(3.5, $m->getMapInt32Float()[1]);
+ $this->assertEquals(3.6, $m->getMapInt32Double()[1]);
+ $this->assertEquals(true , $m->getMapBoolBool()[true]);
+ $this->assertEquals('e', $m->getMapStringString()['e']);
+ $this->assertEquals('f', $m->getMapInt32Bytes()[1]);
+ $this->assertEquals(TestEnum::ONE, $m->getMapInt32Enum()[1]);
+ $this->assertEquals(36, $m->getMapInt32Message()[1]->GetA());
+ }
+
+ // Test message merged from setFields and setFields2.
+ public function expectFieldsMerged(TestMessage $m)
+ {
+ $this->assertSame(-144, $m->getOptionalSint32());
+ $this->assertSame(146, $m->getOptionalFixed32());
+ $this->assertSame(-146, $m->getOptionalSfixed32());
+ $this->assertSame(11.5, $m->getOptionalFloat());
+ $this->assertSame(11.6, $m->getOptionalDouble());
+ $this->assertSame(true, $m->getOptionalBool());
+ $this->assertSame('aa', $m->getOptionalString());
+ $this->assertSame('bb', $m->getOptionalBytes());
+ $this->assertSame(133, $m->getOptionalMessage()->getA());
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame('-143', $m->getOptionalInt64());
+ $this->assertSame('143', $m->getOptionalUint64());
+ $this->assertSame('-145', $m->getOptionalSint64());
+ $this->assertSame('147', $m->getOptionalFixed64());
+ $this->assertSame('-147', $m->getOptionalSfixed64());
+ } else {
+ $this->assertSame(-143, $m->getOptionalInt64());
+ $this->assertSame(143, $m->getOptionalUint64());
+ $this->assertSame(-145, $m->getOptionalSint64());
+ $this->assertSame(147, $m->getOptionalFixed64());
+ $this->assertSame(-147, $m->getOptionalSfixed64());
+ }
+
+ $this->assertEquals(-42, $m->getRepeatedInt32()[0]);
+ $this->assertEquals(42, $m->getRepeatedUint32()[0]);
+ $this->assertEquals(-43, $m->getRepeatedInt64()[0]);
+ $this->assertEquals(43, $m->getRepeatedUint64()[0]);
+ $this->assertEquals(-44, $m->getRepeatedSint32()[0]);
+ $this->assertEquals(-45, $m->getRepeatedSint64()[0]);
+ $this->assertEquals(46, $m->getRepeatedFixed32()[0]);
+ $this->assertEquals(47, $m->getRepeatedFixed64()[0]);
+ $this->assertEquals(-46, $m->getRepeatedSfixed32()[0]);
+ $this->assertEquals(-47, $m->getRepeatedSfixed64()[0]);
+ $this->assertEquals(1.5, $m->getRepeatedFloat()[0]);
+ $this->assertEquals(1.6, $m->getRepeatedDouble()[0]);
+ $this->assertEquals(true, $m->getRepeatedBool()[0]);
+ $this->assertEquals('a', $m->getRepeatedString()[0]);
+ $this->assertEquals('b', $m->getRepeatedBytes()[0]);
+ $this->assertEquals(TestEnum::ZERO, $m->getRepeatedEnum()[0]);
+ $this->assertEquals(34, $m->getRepeatedMessage()[0]->GetA());
+
+ $this->assertEquals(-52, $m->getRepeatedInt32()[1]);
+ $this->assertEquals(52, $m->getRepeatedUint32()[1]);
+ $this->assertEquals(-53, $m->getRepeatedInt64()[1]);
+ $this->assertEquals(53, $m->getRepeatedUint64()[1]);
+ $this->assertEquals(-54, $m->getRepeatedSint32()[1]);
+ $this->assertEquals(-55, $m->getRepeatedSint64()[1]);
+ $this->assertEquals(56, $m->getRepeatedFixed32()[1]);
+ $this->assertEquals(57, $m->getRepeatedFixed64()[1]);
+ $this->assertEquals(-56, $m->getRepeatedSfixed32()[1]);
+ $this->assertEquals(-57, $m->getRepeatedSfixed64()[1]);
+ $this->assertEquals(2.5, $m->getRepeatedFloat()[1]);
+ $this->assertEquals(2.6, $m->getRepeatedDouble()[1]);
+ $this->assertEquals(false, $m->getRepeatedBool()[1]);
+ $this->assertEquals('c', $m->getRepeatedString()[1]);
+ $this->assertEquals('d', $m->getRepeatedBytes()[1]);
+ $this->assertEquals(TestEnum::ONE, $m->getRepeatedEnum()[1]);
+ $this->assertEquals(35, $m->getRepeatedMessage()[1]->GetA());
+
+ $this->assertEquals(-142, $m->getRepeatedInt32()[2]);
+ $this->assertEquals(142, $m->getRepeatedUint32()[2]);
+ $this->assertEquals(-143, $m->getRepeatedInt64()[2]);
+ $this->assertEquals(143, $m->getRepeatedUint64()[2]);
+ $this->assertEquals(-144, $m->getRepeatedSint32()[2]);
+ $this->assertEquals(-145, $m->getRepeatedSint64()[2]);
+ $this->assertEquals(146, $m->getRepeatedFixed32()[2]);
+ $this->assertEquals(147, $m->getRepeatedFixed64()[2]);
+ $this->assertEquals(-146, $m->getRepeatedSfixed32()[2]);
+ $this->assertEquals(-147, $m->getRepeatedSfixed64()[2]);
+ $this->assertEquals(11.5, $m->getRepeatedFloat()[2]);
+ $this->assertEquals(11.6, $m->getRepeatedDouble()[2]);
+ $this->assertEquals(false, $m->getRepeatedBool()[2]);
+ $this->assertEquals('aa', $m->getRepeatedString()[2]);
+ $this->assertEquals('bb', $m->getRepeatedBytes()[2]);
+ $this->assertEquals(TestEnum::TWO, $m->getRepeatedEnum()[2]);
+ $this->assertEquals(134, $m->getRepeatedMessage()[2]->GetA());
+
+ if (PHP_INT_SIZE == 4) {
+ $this->assertEquals('-163', $m->getMapInt64Int64()['-63']);
+ $this->assertEquals('163', $m->getMapUint64Uint64()['63']);
+ $this->assertEquals('-165', $m->getMapSint64Sint64()['-65']);
+ $this->assertEquals('167', $m->getMapFixed64Fixed64()['67']);
+ $this->assertEquals('-169', $m->getMapSfixed64Sfixed64()['-69']);
+ } else {
+ $this->assertEquals(-163, $m->getMapInt64Int64()[-63]);
+ $this->assertEquals(163, $m->getMapUint64Uint64()[63]);
+ $this->assertEquals(-165, $m->getMapSint64Sint64()[-65]);
+ $this->assertEquals(167, $m->getMapFixed64Fixed64()[67]);
+ $this->assertEquals(-169, $m->getMapSfixed64Sfixed64()[-69]);
+ }
+ $this->assertEquals(-162, $m->getMapInt32Int32()[-62]);
+ $this->assertEquals(162, $m->getMapUint32Uint32()[62]);
+ $this->assertEquals(-164, $m->getMapSint32Sint32()[-64]);
+ $this->assertEquals(166, $m->getMapFixed32Fixed32()[66]);
+ $this->assertEquals(-168, $m->getMapSfixed32Sfixed32()[-68]);
+ $this->assertEquals(13.5, $m->getMapInt32Float()[1]);
+ $this->assertEquals(13.6, $m->getMapInt32Double()[1]);
+ $this->assertEquals(false , $m->getMapBoolBool()[true]);
+ $this->assertEquals('ee', $m->getMapStringString()['e']);
+ $this->assertEquals('ff', $m->getMapInt32Bytes()[1]);
+ $this->assertEquals(TestEnum::TWO, $m->getMapInt32Enum()[1]);
+ $this->assertEquals(136, $m->getMapInt32Message()[1]->GetA());
+
+ if (PHP_INT_SIZE == 4) {
+ $this->assertEquals('-163', $m->getMapInt64Int64()['-163']);
+ $this->assertEquals('163', $m->getMapUint64Uint64()['163']);
+ $this->assertEquals('-165', $m->getMapSint64Sint64()['-165']);
+ $this->assertEquals('167', $m->getMapFixed64Fixed64()['167']);
+ $this->assertEquals('-169', $m->getMapSfixed64Sfixed64()['-169']);
+ } else {
+ $this->assertEquals(-163, $m->getMapInt64Int64()[-163]);
+ $this->assertEquals(163, $m->getMapUint64Uint64()[163]);
+ $this->assertEquals(-165, $m->getMapSint64Sint64()[-165]);
+ $this->assertEquals(167, $m->getMapFixed64Fixed64()[167]);
+ $this->assertEquals(-169, $m->getMapSfixed64Sfixed64()[-169]);
+ }
+ $this->assertEquals(-162, $m->getMapInt32Int32()[-162]);
+ $this->assertEquals(162, $m->getMapUint32Uint32()[162]);
+ $this->assertEquals(-164, $m->getMapSint32Sint32()[-164]);
+ $this->assertEquals(166, $m->getMapFixed32Fixed32()[166]);
+ $this->assertEquals(-168, $m->getMapSfixed32Sfixed32()[-168]);
+ $this->assertEquals(13.5, $m->getMapInt32Float()[2]);
+ $this->assertEquals(13.6, $m->getMapInt32Double()[2]);
+ $this->assertEquals(false , $m->getMapBoolBool()[false]);
+ $this->assertEquals('ee', $m->getMapStringString()['ee']);
+ $this->assertEquals('ff', $m->getMapInt32Bytes()[2]);
+ $this->assertEquals(TestEnum::TWO, $m->getMapInt32Enum()[2]);
+ $this->assertEquals(136, $m->getMapInt32Message()[2]->GetA());
+ }
+
+ public function expectEmptyFields(TestMessage $m)
+ {
+ $this->assertSame(0, $m->getOptionalInt32());
+ $this->assertSame(0, $m->getOptionalUint32());
+ $this->assertSame(0, $m->getOptionalSint32());
+ $this->assertSame(0, $m->getOptionalFixed32());
+ $this->assertSame(0, $m->getOptionalSfixed32());
+ $this->assertSame(0.0, $m->getOptionalFloat());
+ $this->assertSame(0.0, $m->getOptionalDouble());
+ $this->assertSame(false, $m->getOptionalBool());
+ $this->assertSame('', $m->getOptionalString());
+ $this->assertSame('', $m->getOptionalBytes());
+ $this->assertSame(0, $m->getOptionalEnum());
+ $this->assertNull($m->getOptionalMessage());
+ $this->assertNull($m->getOptionalIncludedMessage());
+ $this->assertNull($m->getRecursive());
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame("0", $m->getOptionalInt64());
+ $this->assertSame("0", $m->getOptionalUint64());
+ $this->assertSame("0", $m->getOptionalSint64());
+ $this->assertSame("0", $m->getOptionalFixed64());
+ $this->assertSame("0", $m->getOptionalSfixed64());
+ } else {
+ $this->assertSame(0, $m->getOptionalInt64());
+ $this->assertSame(0, $m->getOptionalUint64());
+ $this->assertSame(0, $m->getOptionalSint64());
+ $this->assertSame(0, $m->getOptionalFixed64());
+ $this->assertSame(0, $m->getOptionalSfixed64());
+ }
+
+ $this->assertEquals(0, count($m->getRepeatedInt32()));
+ $this->assertEquals(0, count($m->getRepeatedUint32()));
+ $this->assertEquals(0, count($m->getRepeatedInt64()));
+ $this->assertEquals(0, count($m->getRepeatedUint64()));
+ $this->assertEquals(0, count($m->getRepeatedSint32()));
+ $this->assertEquals(0, count($m->getRepeatedSint64()));
+ $this->assertEquals(0, count($m->getRepeatedFixed32()));
+ $this->assertEquals(0, count($m->getRepeatedFixed64()));
+ $this->assertEquals(0, count($m->getRepeatedSfixed32()));
+ $this->assertEquals(0, count($m->getRepeatedSfixed64()));
+ $this->assertEquals(0, count($m->getRepeatedFloat()));
+ $this->assertEquals(0, count($m->getRepeatedDouble()));
+ $this->assertEquals(0, count($m->getRepeatedBool()));
+ $this->assertEquals(0, count($m->getRepeatedString()));
+ $this->assertEquals(0, count($m->getRepeatedBytes()));
+ $this->assertEquals(0, count($m->getRepeatedEnum()));
+ $this->assertEquals(0, count($m->getRepeatedMessage()));
+ $this->assertEquals(0, count($m->getRepeatedRecursive()));
+
+ $this->assertSame("", $m->getMyOneof());
+ $this->assertSame(0, $m->getOneofInt32());
+ $this->assertSame(0, $m->getOneofUint32());
+ $this->assertSame(0, $m->getOneofSint32());
+ $this->assertSame(0, $m->getOneofFixed32());
+ $this->assertSame(0, $m->getOneofSfixed32());
+ $this->assertSame(0.0, $m->getOneofFloat());
+ $this->assertSame(0.0, $m->getOneofDouble());
+ $this->assertSame(false, $m->getOneofBool());
+ $this->assertSame('', $m->getOneofString());
+ $this->assertSame('', $m->getOneofBytes());
+ $this->assertSame(0, $m->getOneofEnum());
+ $this->assertNull($m->getOptionalMessage());
+ if (PHP_INT_SIZE == 4) {
+ $this->assertSame("0", $m->getOneofInt64());
+ $this->assertSame("0", $m->getOneofUint64());
+ $this->assertSame("0", $m->getOneofSint64());
+ $this->assertSame("0", $m->getOneofFixed64());
+ $this->assertSame("0", $m->getOneofSfixed64());
+ } else {
+ $this->assertSame(0, $m->getOneofInt64());
+ $this->assertSame(0, $m->getOneofUint64());
+ $this->assertSame(0, $m->getOneofSint64());
+ $this->assertSame(0, $m->getOneofFixed64());
+ $this->assertSame(0, $m->getOneofSfixed64());
+ }
+
+ $this->assertEquals(0, count($m->getMapInt64Int64()));
+ $this->assertEquals(0, count($m->getMapUint64Uint64()));
+ $this->assertEquals(0, count($m->getMapSint64Sint64()));
+ $this->assertEquals(0, count($m->getMapFixed64Fixed64()));
+ $this->assertEquals(0, count($m->getMapInt32Int32()));
+ $this->assertEquals(0, count($m->getMapUint32Uint32()));
+ $this->assertEquals(0, count($m->getMapSint32Sint32()));
+ $this->assertEquals(0, count($m->getMapFixed32Fixed32()));
+ $this->assertEquals(0, count($m->getMapSfixed32Sfixed32()));
+ $this->assertEquals(0, count($m->getMapSfixed64Sfixed64()));
+ $this->assertEquals(0, count($m->getMapInt32Float()));
+ $this->assertEquals(0, count($m->getMapInt32Double()));
+ $this->assertEquals(0, count($m->getMapBoolBool()));
+ $this->assertEquals(0, count($m->getMapStringString()));
+ $this->assertEquals(0, count($m->getMapInt32Bytes()));
+ $this->assertEquals(0, count($m->getMapInt32Enum()));
+ $this->assertEquals(0, count($m->getMapInt32Message()));
+ $this->assertEquals(0, count($m->getMapRecursive()));
+ }
+
+ // This test is to avoid the warning of no test by php unit.
+ public function testNone()
+ {
+ }
+}
diff --git a/third_party/protobuf/php/tests/test_util.php b/third_party/protobuf/php/tests/test_util.php
new file mode 100644
index 0000000000..61f94aa108
--- /dev/null
+++ b/third_party/protobuf/php/tests/test_util.php
@@ -0,0 +1,528 @@
+<?php
+
+use Foo\TestEnum;
+use Foo\TestMessage;
+use Foo\TestMessage_Sub;
+use Foo\TestPackedMessage;
+use Foo\TestUnpackedMessage;
+
+define('MAX_FLOAT_DIFF', 0.000001);
+
+if (PHP_INT_SIZE == 8) {
+ define('MAX_INT_STRING', '9223372036854775807');
+ define('MAX_INT_UPPER_STRING', '9223372036854775808');
+} else {
+ define('MAX_INT_STRING', '2147483647');
+ define('MAX_INT_UPPER_STRING', '2147483648');
+}
+
+define('MAX_INT32', 2147483647);
+define('MAX_INT32_FLOAT', 2147483647.0);
+define('MAX_INT32_STRING', '2147483647');
+
+define('MIN_INT32', (int)-2147483648);
+define('MIN_INT32_FLOAT', -2147483648.0);
+define('MIN_INT32_STRING', '-2147483648');
+
+define('MAX_UINT32', 4294967295);
+define('MAX_UINT32_FLOAT', 4294967295.0);
+define('MAX_UINT32_STRING', '4294967295');
+
+define('MIN_UINT32', (int)-2147483648);
+define('MIN_UINT32_FLOAT', -2147483648.0);
+define('MIN_UINT32_STRING', '-2147483648');
+
+define('MAX_INT64_STRING', '9223372036854775807');
+define('MIN_INT64_STRING', '-9223372036854775808');
+define('MAX_UINT64_STRING', '-9223372036854775808');
+
+if (PHP_INT_SIZE === 8) {
+ define('MAX_INT64', (int)9223372036854775807);
+ define('MIN_INT64', (int)-9223372036854775808);
+ define('MAX_UINT64', (int)-9223372036854775808);
+} else {
+ define('MAX_INT64', MAX_INT64_STRING);
+ define('MIN_INT64', MIN_INT64_STRING);
+ define('MAX_UINT64', MAX_UINT64_STRING);
+}
+
+class TestUtil
+{
+
+ public static function setTestMessage(TestMessage $m)
+ {
+ $sub = new TestMessage_Sub();
+
+ $m->setOptionalInt32(-42);
+ $m->setOptionalInt64(-43);
+ $m->setOptionalUint32(42);
+ $m->setOptionalUint64(43);
+ $m->setOptionalSint32(-44);
+ $m->setOptionalSint64(-45);
+ $m->setOptionalFixed32(46);
+ $m->setOptionalFixed64(47);
+ $m->setOptionalSfixed32(-46);
+ $m->setOptionalSfixed64(-47);
+ $m->setOptionalFloat(1.5);
+ $m->setOptionalDouble(1.6);
+ $m->setOptionalBool(true);
+ $m->setOptionalString('a');
+ $m->setOptionalBytes('b');
+ $m->setOptionalEnum(TestEnum::ONE);
+ $m->setOptionalMessage($sub);
+ $m->getOptionalMessage()->SetA(33);
+
+ $m->getRepeatedInt32() []= -42;
+ $m->getRepeatedInt64() []= -43;
+ $m->getRepeatedUint32() []= 42;
+ $m->getRepeatedUint64() []= 43;
+ $m->getRepeatedSint32() []= -44;
+ $m->getRepeatedSint64() []= -45;
+ $m->getRepeatedFixed32() []= 46;
+ $m->getRepeatedFixed64() []= 47;
+ $m->getRepeatedSfixed32() []= -46;
+ $m->getRepeatedSfixed64() []= -47;
+ $m->getRepeatedFloat() []= 1.5;
+ $m->getRepeatedDouble() []= 1.6;
+ $m->getRepeatedBool() []= true;
+ $m->getRepeatedString() []= 'a';
+ $m->getRepeatedBytes() []= 'b';
+ $m->getRepeatedEnum() []= TestEnum::ZERO;
+ $m->getRepeatedMessage() []= new TestMessage_Sub();
+ $m->getRepeatedMessage()[0]->setA(34);
+
+ $m->getRepeatedInt32() []= -52;
+ $m->getRepeatedInt64() []= -53;
+ $m->getRepeatedUint32() []= 52;
+ $m->getRepeatedUint64() []= 53;
+ $m->getRepeatedSint32() []= -54;
+ $m->getRepeatedSint64() []= -55;
+ $m->getRepeatedFixed32() []= 56;
+ $m->getRepeatedFixed64() []= 57;
+ $m->getRepeatedSfixed32() []= -56;
+ $m->getRepeatedSfixed64() []= -57;
+ $m->getRepeatedFloat() []= 2.5;
+ $m->getRepeatedDouble() []= 2.6;
+ $m->getRepeatedBool() []= false;
+ $m->getRepeatedString() []= 'c';
+ $m->getRepeatedBytes() []= 'd';
+ $m->getRepeatedEnum() []= TestEnum::ONE;
+ $m->getRepeatedMessage() []= new TestMessage_Sub();
+ $m->getRepeatedMessage()[1]->SetA(35);
+
+ $m->getMapInt32Int32()[-62] = -62;
+ $m->getMapInt64Int64()[-63] = -63;
+ $m->getMapUint32Uint32()[62] = 62;
+ $m->getMapUint64Uint64()[63] = 63;
+ $m->getMapSint32Sint32()[-64] = -64;
+ $m->getMapSint64Sint64()[-65] = -65;
+ $m->getMapFixed32Fixed32()[66] = 66;
+ $m->getMapFixed64Fixed64()[67] = 67;
+ $m->getMapSfixed32Sfixed32()[-68] = -68;
+ $m->getMapSfixed64Sfixed64()[-69] = -69;
+ $m->getMapInt32Float()[1] = 3.5;
+ $m->getMapInt32Double()[1] = 3.6;
+ $m->getMapBoolBool()[true] = true;
+ $m->getMapStringString()['e'] = 'e';
+ $m->getMapInt32Bytes()[1] = 'f';
+ $m->getMapInt32Enum()[1] = TestEnum::ONE;
+ $m->getMapInt32Message()[1] = new TestMessage_Sub();
+ $m->getMapInt32Message()[1]->SetA(36);
+ }
+
+ public static function setTestMessage2(TestMessage $m)
+ {
+ $sub = new TestMessage_Sub();
+
+ $m->setOptionalInt32(-142);
+ $m->setOptionalInt64(-143);
+ $m->setOptionalUint32(142);
+ $m->setOptionalUint64(143);
+ $m->setOptionalSint32(-144);
+ $m->setOptionalSint64(-145);
+ $m->setOptionalFixed32(146);
+ $m->setOptionalFixed64(147);
+ $m->setOptionalSfixed32(-146);
+ $m->setOptionalSfixed64(-147);
+ $m->setOptionalFloat(11.5);
+ $m->setOptionalDouble(11.6);
+ $m->setOptionalBool(true);
+ $m->setOptionalString('aa');
+ $m->setOptionalBytes('bb');
+ $m->setOptionalEnum(TestEnum::TWO);
+ $m->setOptionalMessage($sub);
+ $m->getOptionalMessage()->SetA(133);
+
+ $m->getRepeatedInt32() []= -142;
+ $m->getRepeatedInt64() []= -143;
+ $m->getRepeatedUint32() []= 142;
+ $m->getRepeatedUint64() []= 143;
+ $m->getRepeatedSint32() []= -144;
+ $m->getRepeatedSint64() []= -145;
+ $m->getRepeatedFixed32() []= 146;
+ $m->getRepeatedFixed64() []= 147;
+ $m->getRepeatedSfixed32() []= -146;
+ $m->getRepeatedSfixed64() []= -147;
+ $m->getRepeatedFloat() []= 11.5;
+ $m->getRepeatedDouble() []= 11.6;
+ $m->getRepeatedBool() []= false;
+ $m->getRepeatedString() []= 'aa';
+ $m->getRepeatedBytes() []= 'bb';
+ $m->getRepeatedEnum() []= TestEnum::TWO;
+ $m->getRepeatedMessage() []= new TestMessage_Sub();
+ $m->getRepeatedMessage()[0]->setA(134);
+
+ $m->getMapInt32Int32()[-62] = -162;
+ $m->getMapInt64Int64()[-63] = -163;
+ $m->getMapUint32Uint32()[62] = 162;
+ $m->getMapUint64Uint64()[63] = 163;
+ $m->getMapSint32Sint32()[-64] = -164;
+ $m->getMapSint64Sint64()[-65] = -165;
+ $m->getMapFixed32Fixed32()[66] = 166;
+ $m->getMapFixed64Fixed64()[67] = 167;
+ $m->getMapSfixed32Sfixed32()[-68] = -168;
+ $m->getMapSfixed64Sfixed64()[-69] = -169;
+ $m->getMapInt32Float()[1] = 13.5;
+ $m->getMapInt32Double()[1] = 13.6;
+ $m->getMapBoolBool()[true] = false;
+ $m->getMapStringString()['e'] = 'ee';
+ $m->getMapInt32Bytes()[1] = 'ff';
+ $m->getMapInt32Enum()[1] = TestEnum::TWO;
+ $m->getMapInt32Message()[1] = new TestMessage_Sub();
+ $m->getMapInt32Message()[1]->SetA(136);
+
+ $m->getMapInt32Int32()[-162] = -162;
+ $m->getMapInt64Int64()[-163] = -163;
+ $m->getMapUint32Uint32()[162] = 162;
+ $m->getMapUint64Uint64()[163] = 163;
+ $m->getMapSint32Sint32()[-164] = -164;
+ $m->getMapSint64Sint64()[-165] = -165;
+ $m->getMapFixed32Fixed32()[166] = 166;
+ $m->getMapFixed64Fixed64()[167] = 167;
+ $m->getMapSfixed32Sfixed32()[-168] = -168;
+ $m->getMapSfixed64Sfixed64()[-169] = -169;
+ $m->getMapInt32Float()[2] = 13.5;
+ $m->getMapInt32Double()[2] = 13.6;
+ $m->getMapBoolBool()[false] = false;
+ $m->getMapStringString()['ee'] = 'ee';
+ $m->getMapInt32Bytes()[2] = 'ff';
+ $m->getMapInt32Enum()[2] = TestEnum::TWO;
+ $m->getMapInt32Message()[2] = new TestMessage_Sub();
+ $m->getMapInt32Message()[2]->SetA(136);
+ }
+
+ public static function assertTestMessage(TestMessage $m)
+ {
+ if (PHP_INT_SIZE == 4) {
+ assert('-43' === $m->getOptionalInt64());
+ assert('43' === $m->getOptionalUint64());
+ assert('-45' === $m->getOptionalSint64());
+ assert('47' === $m->getOptionalFixed64());
+ assert('-47' === $m->getOptionalSfixed64());
+ } else {
+ assert(-43 === $m->getOptionalInt64());
+ assert(43 === $m->getOptionalUint64());
+ assert(-45 === $m->getOptionalSint64());
+ assert(47 === $m->getOptionalFixed64());
+ assert(-47 === $m->getOptionalSfixed64());
+ }
+ assert(-42 === $m->getOptionalInt32());
+ assert(42 === $m->getOptionalUint32());
+ assert(-44 === $m->getOptionalSint32());
+ assert(46 === $m->getOptionalFixed32());
+ assert(-46 === $m->getOptionalSfixed32());
+ assert(1.5 === $m->getOptionalFloat());
+ assert(1.6 === $m->getOptionalDouble());
+ assert(true=== $m->getOptionalBool());
+ assert('a' === $m->getOptionalString());
+ assert('b' === $m->getOptionalBytes());
+ assert(TestEnum::ONE === $m->getOptionalEnum());
+ assert(33 === $m->getOptionalMessage()->getA());
+
+ if (PHP_INT_SIZE == 4) {
+ assert('-43' === $m->getRepeatedInt64()[0]);
+ assert('43' === $m->getRepeatedUint64()[0]);
+ assert('-45' === $m->getRepeatedSint64()[0]);
+ assert('47' === $m->getRepeatedFixed64()[0]);
+ assert('-47' === $m->getRepeatedSfixed64()[0]);
+ } else {
+ assert(-43 === $m->getRepeatedInt64()[0]);
+ assert(43 === $m->getRepeatedUint64()[0]);
+ assert(-45 === $m->getRepeatedSint64()[0]);
+ assert(47 === $m->getRepeatedFixed64()[0]);
+ assert(-47 === $m->getRepeatedSfixed64()[0]);
+ }
+ assert(-42 === $m->getRepeatedInt32()[0]);
+ assert(42 === $m->getRepeatedUint32()[0]);
+ assert(-44 === $m->getRepeatedSint32()[0]);
+ assert(46 === $m->getRepeatedFixed32()[0]);
+ assert(-46 === $m->getRepeatedSfixed32()[0]);
+ assert(1.5 === $m->getRepeatedFloat()[0]);
+ assert(1.6 === $m->getRepeatedDouble()[0]);
+ assert(true=== $m->getRepeatedBool()[0]);
+ assert('a' === $m->getRepeatedString()[0]);
+ assert('b' === $m->getRepeatedBytes()[0]);
+ assert(TestEnum::ZERO === $m->getRepeatedEnum()[0]);
+ assert(34 === $m->getRepeatedMessage()[0]->getA());
+
+ if (PHP_INT_SIZE == 4) {
+ assert('-53' === $m->getRepeatedInt64()[1]);
+ assert('53' === $m->getRepeatedUint64()[1]);
+ assert('-55' === $m->getRepeatedSint64()[1]);
+ assert('57' === $m->getRepeatedFixed64()[1]);
+ assert('-57' === $m->getRepeatedSfixed64()[1]);
+ } else {
+ assert(-53 === $m->getRepeatedInt64()[1]);
+ assert(53 === $m->getRepeatedUint64()[1]);
+ assert(-55 === $m->getRepeatedSint64()[1]);
+ assert(57 === $m->getRepeatedFixed64()[1]);
+ assert(-57 === $m->getRepeatedSfixed64()[1]);
+ }
+ assert(-52 === $m->getRepeatedInt32()[1]);
+ assert(52 === $m->getRepeatedUint32()[1]);
+ assert(-54 === $m->getRepeatedSint32()[1]);
+ assert(56 === $m->getRepeatedFixed32()[1]);
+ assert(-56 === $m->getRepeatedSfixed32()[1]);
+ assert(2.5 === $m->getRepeatedFloat()[1]);
+ assert(2.6 === $m->getRepeatedDouble()[1]);
+ assert(false === $m->getRepeatedBool()[1]);
+ assert('c' === $m->getRepeatedString()[1]);
+ assert('d' === $m->getRepeatedBytes()[1]);
+ assert(TestEnum::ONE === $m->getRepeatedEnum()[1]);
+ assert(35 === $m->getRepeatedMessage()[1]->getA());
+
+ if (PHP_INT_SIZE == 4) {
+ assert('-63' === $m->getMapInt64Int64()['-63']);
+ assert('63' === $m->getMapUint64Uint64()['63']);
+ assert('-65' === $m->getMapSint64Sint64()['-65']);
+ assert('67' === $m->getMapFixed64Fixed64()['67']);
+ assert('-69' === $m->getMapSfixed64Sfixed64()['-69']);
+ } else {
+ assert(-63 === $m->getMapInt64Int64()[-63]);
+ assert(63 === $m->getMapUint64Uint64()[63]);
+ assert(-65 === $m->getMapSint64Sint64()[-65]);
+ assert(67 === $m->getMapFixed64Fixed64()[67]);
+ assert(-69 === $m->getMapSfixed64Sfixed64()[-69]);
+ }
+ assert(-62 === $m->getMapInt32Int32()[-62]);
+ assert(62 === $m->getMapUint32Uint32()[62]);
+ assert(-64 === $m->getMapSint32Sint32()[-64]);
+ assert(66 === $m->getMapFixed32Fixed32()[66]);
+ assert(-68 === $m->getMapSfixed32Sfixed32()[-68]);
+ assert(3.5 === $m->getMapInt32Float()[1]);
+ assert(3.6 === $m->getMapInt32Double()[1]);
+ assert(true === $m->getMapBoolBool()[true]);
+ assert('e' === $m->getMapStringString()['e']);
+ assert('f' === $m->getMapInt32Bytes()[1]);
+ assert(TestEnum::ONE === $m->getMapInt32Enum()[1]);
+ assert(36 === $m->getMapInt32Message()[1]->GetA());
+ }
+
+ public static function getGoldenTestMessage()
+ {
+ return hex2bin(
+ "08D6FFFFFFFFFFFFFFFF01" .
+ "10D5FFFFFFFFFFFFFFFF01" .
+ "182A" .
+ "202B" .
+ "2857" .
+ "3059" .
+ "3D2E000000" .
+ "412F00000000000000" .
+ "4DD2FFFFFF" .
+ "51D1FFFFFFFFFFFFFF" .
+ "5D0000C03F" .
+ "619A9999999999F93F" .
+ "6801" .
+ "720161" .
+ "7A0162" .
+ "800101" .
+ "8A01020821" .
+
+ "F801D6FFFFFFFFFFFFFFFF01" .
+ "F801CCFFFFFFFFFFFFFFFF01" .
+ "8002D5FFFFFFFFFFFFFFFF01" .
+ "8002CBFFFFFFFFFFFFFFFF01" .
+ "88022A" .
+ "880234" .
+ "90022B" .
+ "900235" .
+ "980257" .
+ "98026B" .
+ "A00259" .
+ "A0026D" .
+ "AD022E000000" .
+ "AD0238000000" .
+ "B1022F00000000000000" .
+ "B1023900000000000000" .
+ "BD02D2FFFFFF" .
+ "BD02C8FFFFFF" .
+ "C102D1FFFFFFFFFFFFFF" .
+ "C102C7FFFFFFFFFFFFFF" .
+ "CD020000C03F" .
+ "CD0200002040" .
+ "D1029A9999999999F93F" .
+ "D102CDCCCCCCCCCC0440" .
+ "D80201" .
+ "D80200" .
+ "E2020161" .
+ "E2020163" .
+ "EA020162" .
+ "EA020164" .
+ "F00200" .
+ "F00201" .
+ "FA02020822" .
+ "FA02020823" .
+
+ "BA041608C2FFFFFFFFFFFFFFFF0110C2FFFFFFFFFFFFFFFF01" .
+ "C2041608C1FFFFFFFFFFFFFFFF0110C1FFFFFFFFFFFFFFFF01" .
+ "CA0404083E103E" .
+ "D20404083F103F" .
+ "DA0404087f107F" .
+ "E20406088101108101" .
+ "EA040A0D420000001542000000" .
+ "F20412094300000000000000114300000000000000" .
+ "FA040A0DBCFFFFFF15BCFFFFFF" .
+ "82051209BBFFFFFFFFFFFFFF11BBFFFFFFFFFFFFFF" .
+ "8A050708011500006040" .
+ "92050B080111CDCCCCCCCCCC0C40" .
+ "9A050408011001" .
+ "A205060a0165120165" .
+ "AA05050801120166" .
+ "B2050408011001" .
+ "Ba0506080112020824"
+ );
+ }
+
+ public static function setTestPackedMessage($m)
+ {
+ $m->getRepeatedInt32()[] = -42;
+ $m->getRepeatedInt32()[] = -52;
+ $m->getRepeatedInt64()[] = -43;
+ $m->getRepeatedInt64()[] = -53;
+ $m->getRepeatedUint32()[] = 42;
+ $m->getRepeatedUint32()[] = 52;
+ $m->getRepeatedUint64()[] = 43;
+ $m->getRepeatedUint64()[] = 53;
+ $m->getRepeatedSint32()[] = -44;
+ $m->getRepeatedSint32()[] = -54;
+ $m->getRepeatedSint64()[] = -45;
+ $m->getRepeatedSint64()[] = -55;
+ $m->getRepeatedFixed32()[] = 46;
+ $m->getRepeatedFixed32()[] = 56;
+ $m->getRepeatedFixed64()[] = 47;
+ $m->getRepeatedFixed64()[] = 57;
+ $m->getRepeatedSfixed32()[] = -46;
+ $m->getRepeatedSfixed32()[] = -56;
+ $m->getRepeatedSfixed64()[] = -47;
+ $m->getRepeatedSfixed64()[] = -57;
+ $m->getRepeatedFloat()[] = 1.5;
+ $m->getRepeatedFloat()[] = 2.5;
+ $m->getRepeatedDouble()[] = 1.6;
+ $m->getRepeatedDouble()[] = 2.6;
+ $m->getRepeatedBool()[] = true;
+ $m->getRepeatedBool()[] = false;
+ $m->getRepeatedEnum()[] = TestEnum::ONE;
+ $m->getRepeatedEnum()[] = TestEnum::ZERO;
+ }
+
+ public static function assertTestPackedMessage($m)
+ {
+ assert(2 === count($m->getRepeatedInt32()));
+ assert(2 === count($m->getRepeatedInt64()));
+ assert(2 === count($m->getRepeatedUint32()));
+ assert(2 === count($m->getRepeatedUint64()));
+ assert(2 === count($m->getRepeatedSint32()));
+ assert(2 === count($m->getRepeatedSint64()));
+ assert(2 === count($m->getRepeatedFixed32()));
+ assert(2 === count($m->getRepeatedFixed64()));
+ assert(2 === count($m->getRepeatedSfixed32()));
+ assert(2 === count($m->getRepeatedSfixed64()));
+ assert(2 === count($m->getRepeatedFloat()));
+ assert(2 === count($m->getRepeatedDouble()));
+ assert(2 === count($m->getRepeatedBool()));
+ assert(2 === count($m->getRepeatedEnum()));
+
+ assert(-42 === $m->getRepeatedInt32()[0]);
+ assert(-52 === $m->getRepeatedInt32()[1]);
+ assert(42 === $m->getRepeatedUint32()[0]);
+ assert(52 === $m->getRepeatedUint32()[1]);
+ assert(-44 === $m->getRepeatedSint32()[0]);
+ assert(-54 === $m->getRepeatedSint32()[1]);
+ assert(46 === $m->getRepeatedFixed32()[0]);
+ assert(56 === $m->getRepeatedFixed32()[1]);
+ assert(-46 === $m->getRepeatedSfixed32()[0]);
+ assert(-56 === $m->getRepeatedSfixed32()[1]);
+ assert(1.5 === $m->getRepeatedFloat()[0]);
+ assert(2.5 === $m->getRepeatedFloat()[1]);
+ assert(1.6 === $m->getRepeatedDouble()[0]);
+ assert(2.6 === $m->getRepeatedDouble()[1]);
+ assert(true === $m->getRepeatedBool()[0]);
+ assert(false === $m->getRepeatedBool()[1]);
+ assert(TestEnum::ONE === $m->getRepeatedEnum()[0]);
+ assert(TestEnum::ZERO === $m->getRepeatedEnum()[1]);
+ if (PHP_INT_SIZE == 4) {
+ assert('-43' === $m->getRepeatedInt64()[0]);
+ assert('-53' === $m->getRepeatedInt64()[1]);
+ assert('43' === $m->getRepeatedUint64()[0]);
+ assert('53' === $m->getRepeatedUint64()[1]);
+ assert('-45' === $m->getRepeatedSint64()[0]);
+ assert('-55' === $m->getRepeatedSint64()[1]);
+ assert('47' === $m->getRepeatedFixed64()[0]);
+ assert('57' === $m->getRepeatedFixed64()[1]);
+ assert('-47' === $m->getRepeatedSfixed64()[0]);
+ assert('-57' === $m->getRepeatedSfixed64()[1]);
+ } else {
+ assert(-43 === $m->getRepeatedInt64()[0]);
+ assert(-53 === $m->getRepeatedInt64()[1]);
+ assert(43 === $m->getRepeatedUint64()[0]);
+ assert(53 === $m->getRepeatedUint64()[1]);
+ assert(-45 === $m->getRepeatedSint64()[0]);
+ assert(-55 === $m->getRepeatedSint64()[1]);
+ assert(47 === $m->getRepeatedFixed64()[0]);
+ assert(57 === $m->getRepeatedFixed64()[1]);
+ assert(-47 === $m->getRepeatedSfixed64()[0]);
+ assert(-57 === $m->getRepeatedSfixed64()[1]);
+ }
+ }
+
+ public static function getGoldenTestPackedMessage()
+ {
+ return hex2bin(
+ "D20514D6FFFFFFFFFFFFFFFF01CCFFFFFFFFFFFFFFFF01" .
+ "DA0514D5FFFFFFFFFFFFFFFF01CBFFFFFFFFFFFFFFFF01" .
+ "E205022A34" .
+ "EA05022B35" .
+ "F20502576B" .
+ "FA0502596D" .
+ "8206082E00000038000000" .
+ "8A06102F000000000000003900000000000000" .
+ "920608D2FFFFFFC8FFFFFF" .
+ "9A0610D1FFFFFFFFFFFFFFC7FFFFFFFFFFFFFF" .
+ "A206080000C03F00002040" .
+ "AA06109A9999999999F93FCDCCCCCCCCCC0440" .
+ "B206020100" .
+ "BA06020100"
+ );
+ }
+
+ public static function getGoldenTestUnpackedMessage()
+ {
+ return hex2bin(
+ "D005D6FFFFFFFFFFFFFFFF01D005CCFFFFFFFFFFFFFFFF01" .
+ "D805D5FFFFFFFFFFFFFFFF01D805CBFFFFFFFFFFFFFFFF01" .
+ "E0052AE00534" .
+ "E8052BE80535" .
+ "F00557F0056B" .
+ "F80559F8056D" .
+ "85062E000000850638000000" .
+ "89062F0000000000000089063900000000000000" .
+ "9506D2FFFFFF9506C8FFFFFF" .
+ "9906D1FFFFFFFFFFFFFF9906C7FFFFFFFFFFFFFF" .
+ "A5060000C03FA50600002040" .
+ "A9069A9999999999F93FA906CDCCCCCCCCCC0440" .
+ "B00601B00600" .
+ "B80601B80600"
+ );
+ }
+}
diff --git a/third_party/protobuf/php/tests/well_known_test.php b/third_party/protobuf/php/tests/well_known_test.php
new file mode 100644
index 0000000000..40ff1c8f03
--- /dev/null
+++ b/third_party/protobuf/php/tests/well_known_test.php
@@ -0,0 +1,11 @@
+<?php
+
+use Google\Protobuf\GPBEmpty;
+
+class WellKnownTest extends PHPUnit_Framework_TestCase {
+
+ public function testNone() {
+ $msg = new GPBEmpty();
+ }
+
+}
diff --git a/third_party/protobuf/post_process_dist.sh b/third_party/protobuf/post_process_dist.sh
new file mode 100755
index 0000000000..a5f95800b8
--- /dev/null
+++ b/third_party/protobuf/post_process_dist.sh
@@ -0,0 +1,64 @@
+#! /bin/sh
+
+# This script takes the result of "make dist" and:
+# 1) Unpacks it.
+# 2) Ensures all contents are user-writable. Some version control systems
+# keep code read-only until you explicitly ask to edit it, and the normal
+# "make dist" process does not correct for this, so the result is that
+# the entire dist is still marked read-only when unpacked, which is
+# annoying. So, we fix it.
+# 3) Convert MSVC project files to MSVC 2005, so that anyone who has version
+# 2005 *or* 2008 can open them. (In version control, we keep things in
+# MSVC 2008 format since that's what we use in development.)
+# 4) Uses the result to create .tar.gz, .tar.bz2, and .zip versions and
+# deposites them in the "dist" directory. In the .zip version, all
+# non-testdata .txt files are converted to Windows-style line endings.
+# 5) Cleans up after itself.
+
+if [ "$1" == "" ]; then
+ echo "USAGE: $0 DISTFILE" >&2
+ exit 1
+fi
+
+if [ ! -e $1 ]; then
+ echo $1": File not found." >&2
+ exit 1
+fi
+
+set -ex
+
+LANGUAGES="cpp csharp java javanano js objectivec python ruby php"
+BASENAME=`basename $1 .tar.gz`
+VERSION=${BASENAME:9}
+
+# Create a directory called "dist", copy the tarball there and unpack it.
+mkdir dist
+cp $1 dist
+cd dist
+tar zxvf $BASENAME.tar.gz
+rm $BASENAME.tar.gz
+
+# Set the entire contents to be user-writable.
+chmod -R u+w $BASENAME
+cd $BASENAME
+
+for LANG in $LANGUAGES; do
+ # Build the dist again in .tar.gz
+ ./configure DIST_LANG=$LANG
+ make dist-gzip
+ mv $BASENAME.tar.gz ../protobuf-$LANG-$VERSION.tar.gz
+done
+
+# Convert all text files to use DOS-style line endings, then build a .zip
+# distribution.
+todos *.txt */*.txt
+
+for LANG in $LANGUAGES; do
+ # Build the dist again in .zip
+ ./configure DIST_LANG=$LANG
+ make dist-zip
+ mv $BASENAME.zip ../protobuf-$LANG-$VERSION.zip
+done
+
+cd ..
+rm -rf $BASENAME
diff --git a/third_party/protobuf/proto_alias.bzl b/third_party/protobuf/proto_alias.bzl
deleted file mode 100644
index e47728f96d..0000000000
--- a/third_party/protobuf/proto_alias.bzl
+++ /dev/null
@@ -1,18 +0,0 @@
-# Copyright 2016 The Bazel Authors. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-def proto_alias(name, version):
- native.alias(
- name = name,
- actual = "//third_party/protobuf/" + version + ":" + name)
diff --git a/third_party/protobuf/protobuf-java-3.2.0.jar b/third_party/protobuf/protobuf-java-3.2.0.jar
new file mode 100644
index 0000000000..b1f970176d
--- /dev/null
+++ b/third_party/protobuf/protobuf-java-3.2.0.jar
Binary files differ
diff --git a/third_party/protobuf/protobuf-java-util-3.2.0.jar b/third_party/protobuf/protobuf-java-util-3.2.0.jar
new file mode 100644
index 0000000000..2fb0a207ee
--- /dev/null
+++ b/third_party/protobuf/protobuf-java-util-3.2.0.jar
Binary files differ
diff --git a/third_party/protobuf/protobuf-lite.pc.in b/third_party/protobuf/protobuf-lite.pc.in
new file mode 100644
index 0000000000..80f1f46195
--- /dev/null
+++ b/third_party/protobuf/protobuf-lite.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: Protocol Buffers
+Description: Google's Data Interchange Format
+Version: @VERSION@
+Libs: -L${libdir} -lprotobuf-lite @PTHREAD_CFLAGS@ @PTHREAD_LIBS@
+Cflags: -I${includedir} @PTHREAD_CFLAGS@
+Conflicts: protobuf
diff --git a/third_party/protobuf/3.0.0/protobuf.bzl b/third_party/protobuf/protobuf.bzl
index 0e8c2e234c..73c396d556 100644
--- a/third_party/protobuf/3.0.0/protobuf.bzl
+++ b/third_party/protobuf/protobuf.bzl
@@ -1,12 +1,27 @@
-# -*- mode: python; -*- PYTHON-PREPROCESSING-REQUIRED
-
def _GetPath(ctx, path):
if ctx.label.workspace_root:
return ctx.label.workspace_root + '/' + path
else:
return path
+def _IsNewExternal(ctx):
+ # Bazel 0.4.4 and older have genfiles paths that look like:
+ # bazel-out/local-fastbuild/genfiles/external/repo/foo
+ # After the exec root rearrangement, they look like:
+ # ../repo/bazel-out/local-fastbuild/genfiles/foo
+ return ctx.label.workspace_root.startswith("../")
+
def _GenDir(ctx):
+ if _IsNewExternal(ctx):
+ # We are using the fact that Bazel 0.4.4+ provides repository-relative paths
+ # for ctx.genfiles_dir.
+ return ctx.genfiles_dir.path + (
+ "/" + ctx.attr.includes[0] if ctx.attr.includes and ctx.attr.includes[0] else "")
+ # This means that we're either in the old version OR the new version in the local repo.
+ # Either way, appending the source path to the genfiles dir works.
+ return ctx.var["GENDIR"] + "/" + _SourceDir(ctx)
+
+def _SourceDir(ctx):
if not ctx.attr.includes:
return ctx.label.workspace_root
if not ctx.attr.includes[0]:
@@ -15,14 +30,21 @@ def _GenDir(ctx):
return _GetPath(ctx, ctx.attr.includes[0])
return _GetPath(ctx, ctx.label.package + '/' + ctx.attr.includes[0])
-def _CcOuts(srcs, use_grpc_plugin=False):
- ret = [s[:-len(".proto")] + ".pb.h" for s in srcs] + \
- [s[:-len(".proto")] + ".pb.cc" for s in srcs]
+def _CcHdrs(srcs, use_grpc_plugin=False):
+ ret = [s[:-len(".proto")] + ".pb.h" for s in srcs]
if use_grpc_plugin:
- ret += [s[:-len(".proto")] + ".grpc.pb.h" for s in srcs] + \
- [s[:-len(".proto")] + ".grpc.pb.cc" for s in srcs]
+ ret += [s[:-len(".proto")] + ".grpc.pb.h" for s in srcs]
return ret
+def _CcSrcs(srcs, use_grpc_plugin=False):
+ ret = [s[:-len(".proto")] + ".pb.cc" for s in srcs]
+ if use_grpc_plugin:
+ ret += [s[:-len(".proto")] + ".grpc.pb.cc" for s in srcs]
+ return ret
+
+def _CcOuts(srcs, use_grpc_plugin=False):
+ return _CcHdrs(srcs, use_grpc_plugin) + _CcSrcs(srcs, use_grpc_plugin)
+
def _PyOuts(srcs):
return [s[:-len(".proto")] + "_pb2.py" for s in srcs]
@@ -46,9 +68,10 @@ def _proto_gen_impl(ctx):
srcs = ctx.files.srcs
deps = []
deps += ctx.files.srcs
+ source_dir = _SourceDir(ctx)
gen_dir = _GenDir(ctx)
- if gen_dir:
- import_flags = ["-I" + gen_dir, "-I" + ctx.var["GENDIR"] + "/" + gen_dir]
+ if source_dir:
+ import_flags = ["-I" + source_dir, "-I" + gen_dir]
else:
import_flags = ["-I."]
@@ -58,20 +81,33 @@ def _proto_gen_impl(ctx):
args = []
if ctx.attr.gen_cc:
- args += ["--cpp_out=" + ctx.var["GENDIR"] + "/" + gen_dir]
+ args += ["--cpp_out=" + gen_dir]
if ctx.attr.gen_py:
- args += ["--python_out=" + ctx.var["GENDIR"] + "/" + gen_dir]
-
- if ctx.executable.grpc_cpp_plugin:
- args += ["--plugin=protoc-gen-grpc=" + ctx.executable.grpc_cpp_plugin.path]
- args += ["--grpc_out=" + ctx.var["GENDIR"] + "/" + gen_dir]
+ args += ["--python_out=" + gen_dir]
+
+ inputs = srcs + deps
+ if ctx.executable.plugin:
+ plugin = ctx.executable.plugin
+ lang = ctx.attr.plugin_language
+ if not lang and plugin.basename.startswith('protoc-gen-'):
+ lang = plugin.basename[len('protoc-gen-'):]
+ if not lang:
+ fail("cannot infer the target language of plugin", "plugin_language")
+
+ outdir = gen_dir
+ if ctx.attr.plugin_options:
+ outdir = ",".join(ctx.attr.plugin_options) + ":" + outdir
+ args += ["--plugin=protoc-gen-%s=%s" % (lang, plugin.path)]
+ args += ["--%s_out=%s" % (lang, outdir)]
+ inputs += [plugin]
if args:
ctx.action(
- inputs=srcs + deps,
+ inputs=inputs,
outputs=ctx.outputs.outs,
arguments=args + import_flags + [s.path for s in srcs],
executable=ctx.executable.protoc,
+ mnemonic="ProtoCompile",
)
return struct(
@@ -82,7 +118,7 @@ def _proto_gen_impl(ctx):
),
)
-_proto_gen = rule(
+proto_gen = rule(
attrs = {
"srcs": attr.label_list(allow_files = True),
"deps": attr.label_list(providers = ["proto"]),
@@ -93,11 +129,13 @@ _proto_gen = rule(
single_file = True,
mandatory = True,
),
- "grpc_cpp_plugin": attr.label(
+ "plugin": attr.label(
cfg = "host",
+ allow_files = True,
executable = True,
- single_file = True,
),
+ "plugin_language": attr.string(),
+ "plugin_options": attr.string_list(),
"gen_cc": attr.bool(),
"gen_py": attr.bool(),
"outs": attr.output_list(),
@@ -105,6 +143,26 @@ _proto_gen = rule(
output_to_genfiles = True,
implementation = _proto_gen_impl,
)
+"""Generates codes from Protocol Buffers definitions.
+
+This rule helps you to implement Skylark macros specific to the target
+language. You should prefer more specific `cc_proto_library `,
+`py_proto_library` and others unless you are adding such wrapper macros.
+
+Args:
+ srcs: Protocol Buffers definition files (.proto) to run the protocol compiler
+ against.
+ deps: a list of dependency labels; must be other proto libraries.
+ includes: a list of include paths to .proto files.
+ protoc: the label of the protocol compiler to generate the sources.
+ plugin: the label of the protocol compiler plugin to be passed to the protocol
+ compiler.
+ plugin_language: the language of the generated sources
+ plugin_options: a list of options to be passed to the plugin
+ gen_cc: generates C++ sources in addition to the ones from the plugin.
+ gen_py: generates Python sources in addition to the ones from the plugin.
+ outs: a list of labels of the expected outputs from the protocol compiler.
+"""
def cc_proto_library(
name,
@@ -150,7 +208,7 @@ def cc_proto_library(
if internal_bootstrap_hack:
# For pre-checked-in generated files, we add the internal_bootstrap_hack
# which will skip the codegen action.
- _proto_gen(
+ proto_gen(
name=name + "_genproto",
srcs=srcs,
deps=[s + "_genproto" for s in deps],
@@ -168,15 +226,18 @@ def cc_proto_library(
if use_grpc_plugin:
grpc_cpp_plugin = "//external:grpc_cpp_plugin"
- outs = _CcOuts(srcs, use_grpc_plugin)
+ gen_srcs = _CcSrcs(srcs, use_grpc_plugin)
+ gen_hdrs = _CcHdrs(srcs, use_grpc_plugin)
+ outs = gen_srcs + gen_hdrs
- _proto_gen(
+ proto_gen(
name=name + "_genproto",
srcs=srcs,
deps=[s + "_genproto" for s in deps],
includes=includes,
protoc=protoc,
- grpc_cpp_plugin=grpc_cpp_plugin,
+ plugin=grpc_cpp_plugin,
+ plugin_language="grpc",
gen_cc=1,
outs=outs,
visibility=["//visibility:public"],
@@ -189,12 +250,12 @@ def cc_proto_library(
native.cc_library(
name=name,
- srcs=outs,
+ srcs=gen_srcs,
+ hdrs=gen_hdrs,
deps=cc_libs + deps,
includes=includes,
**kargs)
-
def internal_gen_well_known_protos_java(srcs):
"""Bazel rule to generate the gen_well_known_protos_java genrule
@@ -202,10 +263,11 @@ def internal_gen_well_known_protos_java(srcs):
srcs: the well known protos
"""
root = Label("%s//protobuf_java" % (REPOSITORY_NAME)).workspace_root
+ pkg = PACKAGE_NAME + "/" if PACKAGE_NAME else ""
if root == "":
- include = " -Isrc "
+ include = " -I%ssrc " % pkg
else:
- include = " -I%s/src " % root
+ include = " -I%s/%ssrc " % (root, pkg)
native.genrule(
name = "gen_well_known_protos_java",
srcs = srcs,
@@ -218,7 +280,6 @@ def internal_gen_well_known_protos_java(srcs):
tools = [":protoc"],
)
-
def internal_copied_filegroup(name, srcs, strip_prefix, dest, **kwargs):
"""Macro to copy files to a different directory and then create a filegroup.
@@ -248,7 +309,6 @@ def internal_copied_filegroup(name, srcs, strip_prefix, dest, **kwargs):
srcs = outs,
**kwargs)
-
def py_proto_library(
name,
srcs=[],
@@ -258,6 +318,7 @@ def py_proto_library(
include=None,
default_runtime="//:protobuf_python",
protoc="//:protoc",
+ use_grpc_plugin=False,
**kargs):
"""Bazel rule to create a Python protobuf library from proto source files
@@ -277,6 +338,8 @@ def py_proto_library(
default_runtime: the implicitly default runtime which will be depended on by
the generated py_library target.
protoc: the label of the protocol compiler to generate the sources.
+ use_grpc_plugin: a flag to indicate whether to call the Python C++ plugin
+ when processing the proto files.
**kargs: other keyword arguments that are passed to cc_library.
"""
@@ -286,7 +349,14 @@ def py_proto_library(
if include != None:
includes = [include]
- _proto_gen(
+ grpc_python_plugin = None
+ if use_grpc_plugin:
+ grpc_python_plugin = "//external:grpc_python_plugin"
+ # Note: Generated grpc code depends on Python grpc module. This dependency
+ # is not explicitly listed in py_libs. Instead, host system is assumed to
+ # have grpc installed.
+
+ proto_gen(
name=name + "_genproto",
srcs=srcs,
deps=[s + "_genproto" for s in deps],
@@ -295,6 +365,8 @@ def py_proto_library(
gen_py=1,
outs=outs,
visibility=["//visibility:public"],
+ plugin=grpc_python_plugin,
+ plugin_language="grpc"
)
if default_runtime and not default_runtime in py_libs + deps:
diff --git a/third_party/protobuf/protobuf.pc.in b/third_party/protobuf/protobuf.pc.in
new file mode 100644
index 0000000000..490149034d
--- /dev/null
+++ b/third_party/protobuf/protobuf.pc.in
@@ -0,0 +1,12 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: Protocol Buffers
+Description: Google's Data Interchange Format
+Version: @VERSION@
+Libs: -L${libdir} -lprotobuf @PTHREAD_CFLAGS@ @PTHREAD_LIBS@
+Libs.private: @LIBS@
+Cflags: -I${includedir} @PTHREAD_CFLAGS@
+Conflicts: protobuf-lite
diff --git a/third_party/protobuf/protoc-artifacts/Dockerfile b/third_party/protobuf/protoc-artifacts/Dockerfile
new file mode 100644
index 0000000000..5143b0281d
--- /dev/null
+++ b/third_party/protobuf/protoc-artifacts/Dockerfile
@@ -0,0 +1,40 @@
+FROM centos:6.6
+
+RUN yum install -y git \
+ tar \
+ wget \
+ make \
+ autoconf \
+ curl-devel \
+ unzip \
+ automake \
+ libtool \
+ glibc-static.i686 \
+ glibc-devel \
+ glibc-devel.i686
+
+# Install Java 8
+RUN wget -q --no-cookies --no-check-certificate \
+ --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u45-linux-x64.tar.gz" \
+ -O - | tar xz -C /var/local
+ENV JAVA_HOME /var/local/jdk1.8.0_45
+ENV PATH $JAVA_HOME/bin:$PATH
+
+# Install Maven
+RUN wget -q http://apache.cs.utah.edu/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz -O - | \
+ tar xz -C /var/local
+ENV PATH /var/local/apache-maven-3.3.9/bin:$PATH
+
+# Install GCC 4.7 to support -static-libstdc++
+RUN wget http://people.centos.org/tru/devtools-1.1/devtools-1.1.repo -P /etc/yum.repos.d
+RUN bash -c 'echo "enabled=1" >> /etc/yum.repos.d/devtools-1.1.repo'
+RUN bash -c "sed -e 's/\$basearch/i386/g' /etc/yum.repos.d/devtools-1.1.repo > /etc/yum.repos.d/devtools-i386-1.1.repo"
+RUN sed -e 's/testing-/testing-i386-/g' -i /etc/yum.repos.d/devtools-i386-1.1.repo
+RUN yum install -y devtoolset-1.1 \
+ devtoolset-1.1-libstdc++-devel \
+ devtoolset-1.1-libstdc++-devel.i686
+
+RUN git clone --depth 1 https://github.com/google/protobuf.git
+
+# Start in devtoolset environment that uses GCC 4.7
+CMD ["scl", "enable", "devtoolset-1.1", "bash"]
diff --git a/third_party/protobuf/protoc-artifacts/README.md b/third_party/protobuf/protoc-artifacts/README.md
new file mode 100644
index 0000000000..5062920932
--- /dev/null
+++ b/third_party/protobuf/protoc-artifacts/README.md
@@ -0,0 +1,177 @@
+# Build scripts that publish pre-compiled protoc artifacts
+``protoc`` is the compiler for ``.proto`` files. It generates language bindings
+for the messages and/or RPC services from ``.proto`` files.
+
+Because ``protoc`` is a native executable, the scripts under this directory
+build and publish a ``protoc`` executable (a.k.a. artifact) to Maven
+repositories. The artifact can be used by build automation tools so that users
+would not need to compile and install ``protoc`` for their systems.
+
+## Versioning
+The version of the ``protoc`` artifact must be the same as the version of the
+Protobuf project.
+
+## Artifact name
+The name of a published ``protoc`` artifact is in the following format:
+``protoc-<version>-<os>-<arch>.exe``, e.g., ``protoc-3.0.0-alpha-3-windows-x86_64.exe``.
+
+## System requirement
+Install [Apache Maven](http://maven.apache.org/) if you don't have it.
+
+The scripts only work under Unix-like environments, e.g., Linux, MacOSX, and
+Cygwin or MinGW for Windows. Please see ``README.md`` of the Protobuf project
+for how to set up the build environment.
+
+## Building from a freshly checked-out source
+
+If you just checked out the Protobuf source from github, you need to
+generate the configure script.
+
+Under the protobuf project directory:
+
+```
+$ ./autogen.sh && ./configure && make
+```
+
+## To install artifacts locally
+The following command will install the ``protoc`` artifact to your local Maven repository.
+```
+$ mvn install
+```
+
+## Cross-compilation
+The Maven script will try to detect the OS and the architecture from Java
+system properties. It's possible to build a protoc binary for an architecture
+that is different from what Java has detected, as long as you have the proper
+compilers installed.
+
+You can override the Maven properties ``os.detected.name`` and
+``os.detected.arch`` to force the script to generate binaries for a specific OS
+and/or architecture. Valid values are defined as the return values of
+``normalizeOs()`` and ``normalizeArch()`` of ``Detector`` from
+[os-maven-plugin](https://github.com/trustin/os-maven-plugin/blob/master/src/main/java/kr/motd/maven/os/Detector.java).
+Frequently used values are:
+- ``os.detected.name``: ``linux``, ``osx``, ``windows``.
+- ``os.detected.arch``: ``x86_32``, ``x86_64``
+
+For example, MinGW32 only ships with 32-bit compilers, but you can still build
+32-bit protoc under 64-bit Windows, with the following command:
+```
+$ mvn install -Dos.detected.arch=x86_32
+```
+
+## To push artifacts to Maven Central
+Before you can upload artifacts to Maven Central repository, make sure you have
+read [this page](http://central.sonatype.org/pages/apache-maven.html) on how to
+configure GPG and Sonatype account.
+
+You need to perform the deployment for every platform that you want to
+support. DO NOT close the staging repository until you have done the
+deployment for all platforms. Currently the following platforms are supported:
+- Linux (x86_32 and x86_64)
+- Windows (x86_32 and x86_64) with
+ - Cygwin64 with MinGW compilers (x86_64)
+ - MSYS with MinGW32 (x86_32)
+- MacOSX (x86_32 and x86_64)
+
+As for MSYS2/MinGW64 for Windows: protoc will build, but it insists on
+adding a dependency of `libwinpthread-1.dll`, which isn't shipped with
+Windows.
+
+Use the following command to deploy artifacts for the host platform to a
+staging repository.
+```
+$ mvn clean deploy -P release
+```
+It creates a new staging repository. Go to
+https://oss.sonatype.org/#stagingRepositories and find the repository, usually
+in the name like ``comgoogle-123``.
+
+You will want to run this command on a different platform. Remember, in
+subsequent deployments you will need to provide the repository name that you
+have found in the first deployment so that all artifacts go to the same
+repository:
+```
+$ mvn clean deploy -P release -Dstaging.repository=comgoogle-123
+```
+
+A 32-bit artifact can be deployed from a 64-bit host with
+``-Dos.detected.arch=x86_32``
+
+When you have done deployment for all platforms, go to
+https://oss.sonatype.org/#stagingRepositories, verify that the staging
+repository has all the binaries, close and release this repository.
+
+## Upload zip packages to github release page.
+After uploading protoc artifacts to Maven Central repository, run the
+build-zip.sh script to bulid zip packages for these protoc binaries
+and upload these zip packages to the download section of the github
+release. For example:
+```
+$ ./build-zip.sh 3.0.0-beta-4
+```
+The above command will create 5 zip files:
+```
+dist/protoc-3.0.0-beta-4-win32.zip
+dist/protoc-3.0.0-beta-4-osx-x86_32.zip
+dist/protoc-3.0.0-beta-4-osx-x86_64.zip
+dist/protoc-3.0.0-beta-4-linux-x86_32.zip
+dist/protoc-3.0.0-beta-4-linux-x86_64.zip
+```
+Before running the script, make sure the artifacts are accessible from:
+http://repo1.maven.org/maven2/com/google/protobuf/protoc/
+
+### Tips for deploying on Linux
+We build on Centos 6.6 to provide a good compatibility for not very new
+systems. We have provided a ``Dockerfile`` under this directory to build the
+environment. It has been tested with Docker 1.6.1.
+
+To build a image:
+```
+$ docker build -t protoc-artifacts .
+```
+
+To run the image:
+```
+$ docker run -it --rm=true protoc-artifacts
+```
+
+The Protobuf repository has been cloned into ``/protobuf``.
+
+### Tips for deploying on Windows
+Under Windows the following error may occur: ``gpg: cannot open tty `no tty':
+No such file or directory``. This can be fixed by configuring gpg through an
+active profile in ``.m2\settings.xml`` where also the Sonatype password is
+stored:
+```xml
+<settings>
+ <servers>
+ <server>
+ <id>sonatype-nexus-staging</id>
+ <username>[username]</username>
+ <password>[password]</password>
+ </server>
+ </servers>
+ <profiles>
+ <profile>
+ <id>gpg</id>
+ <properties>
+ <gpg.executable>gpg</gpg.executable>
+ <gpg.passphrase>[password]</gpg.passphrase>
+ </properties>
+ </profile>
+ </profiles>
+ <activeProfiles>
+ <activeProfile>gpg</activeProfile>
+ </activeProfiles>
+</settings>
+```
+
+### Tested build environments
+We have successfully built artifacts on the following environments:
+- Linux x86_32 and x86_64:
+ - Centos 6.6 (within Docker 1.6.1)
+ - Ubuntu 14.04.2 64-bit
+- Windows x86_32: MSYS with ``mingw32-gcc-g++ 4.8.1-4`` on Windows 7 64-bit
+- Windows x86_64: Cygwin64 with ``mingw64-x86_64-gcc-g++ 4.8.3-1`` on Windows 7 64-bit
+- Mac OS X x86_32 and x86_64: Mac OS X 10.9.5
diff --git a/third_party/protobuf/protoc-artifacts/build-protoc.sh b/third_party/protobuf/protoc-artifacts/build-protoc.sh
new file mode 100755
index 0000000000..e31948e987
--- /dev/null
+++ b/third_party/protobuf/protoc-artifacts/build-protoc.sh
@@ -0,0 +1,236 @@
+#!/bin/bash
+
+# Builds protoc executable into target/protoc.exe; optionally build protoc
+# plugins into target/protoc-gen-*.exe
+# To be run from Maven.
+# Usage: build-protoc.sh <OS> <ARCH> <TARGET>
+# <OS> and <ARCH> are ${os.detected.name} and ${os.detected.arch} from os-maven-plugin
+# <TARGET> can be "protoc" or "protoc-gen-javalite"
+OS=$1
+ARCH=$2
+MAKE_TARGET=$3
+
+if [[ $# < 3 ]]; then
+ echo "No arguments provided. This script is intended to be run from Maven."
+ exit 1
+fi
+
+case $MAKE_TARGET in
+ protoc-gen-javalite)
+ ;;
+ protoc)
+ ;;
+ *)
+ echo "Target ""$TARGET"" invalid."
+ exit 1
+esac
+
+# Under Cygwin, bash doesn't have these in PATH when called from Maven which
+# runs in Windows version of Java.
+export PATH="/bin:/usr/bin:$PATH"
+
+############################################################################
+# Helper functions
+############################################################################
+E_PARAM_ERR=98
+E_ASSERT_FAILED=99
+
+# Usage:
+fail()
+{
+ echo "ERROR: $1"
+ echo
+ exit $E_ASSERT_FAILED
+}
+
+# Usage: assertEq VAL1 VAL2 $LINENO
+assertEq ()
+{
+ lineno=$3
+ if [ -z "$lineno" ]; then
+ echo "lineno not given"
+ exit $E_PARAM_ERR
+ fi
+
+ if [[ "$1" != "$2" ]]; then
+ echo "Assertion failed: \"$1\" == \"$2\""
+ echo "File \"$0\", line $lineno" # Give name of file and line number.
+ exit $E_ASSERT_FAILED
+ fi
+}
+
+# Checks the artifact is for the expected architecture
+# Usage: checkArch <path-to-protoc>
+checkArch ()
+{
+ echo
+ echo "Checking file format ..."
+ if [[ "$OS" == windows || "$OS" == linux ]]; then
+ format="$(objdump -f "$1" | grep -o "file format .*$" | grep -o "[^ ]*$")"
+ echo Format=$format
+ if [[ "$OS" == linux ]]; then
+ if [[ "$ARCH" == x86_32 ]]; then
+ assertEq $format "elf32-i386" $LINENO
+ elif [[ "$ARCH" == x86_64 ]]; then
+ assertEq $format "elf64-x86-64" $LINENO
+ else
+ fail "Unsupported arch: $ARCH"
+ fi
+ else
+ # $OS == windows
+ if [[ "$ARCH" == x86_32 ]]; then
+ assertEq $format "pei-i386" $LINENO
+ elif [[ "$ARCH" == x86_64 ]]; then
+ assertEq $format "pei-x86-64" $LINENO
+ else
+ fail "Unsupported arch: $ARCH"
+ fi
+ fi
+ elif [[ "$OS" == osx ]]; then
+ format="$(file -b "$1" | grep -o "[^ ]*$")"
+ echo Format=$format
+ if [[ "$ARCH" == x86_32 ]]; then
+ assertEq $format "i386" $LINENO
+ elif [[ "$ARCH" == x86_64 ]]; then
+ assertEq $format "x86_64" $LINENO
+ else
+ fail "Unsupported arch: $ARCH"
+ fi
+ else
+ fail "Unsupported system: $OS"
+ fi
+ echo
+}
+
+# Checks the dependencies of the artifact. Artifacts should only depend on
+# system libraries.
+# Usage: checkDependencies <path-to-protoc>
+checkDependencies ()
+{
+ if [[ "$OS" == windows ]]; then
+ dump_cmd='objdump -x '"$1"' | fgrep "DLL Name"'
+ white_list="KERNEL32\.dll\|msvcrt\.dll"
+ elif [[ "$OS" == linux ]]; then
+ dump_cmd='ldd '"$1"
+ if [[ "$ARCH" == x86_32 ]]; then
+ white_list="linux-gate\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux\.so\.2"
+ elif [[ "$ARCH" == x86_64 ]]; then
+ white_list="linux-vdso\.so\.1\|libpthread\.so\.0\|libm\.so\.6\|libc\.so\.6\|ld-linux-x86-64\.so\.2"
+ fi
+ elif [[ "$OS" == osx ]]; then
+ dump_cmd='otool -L '"$1"' | fgrep dylib'
+ white_list="libz\.1\.dylib\|libstdc++\.6\.dylib\|libSystem\.B\.dylib"
+ fi
+ if [[ -z "$white_list" || -z "$dump_cmd" ]]; then
+ fail "Unsupported platform $OS-$ARCH."
+ fi
+ echo "Checking for expected dependencies ..."
+ eval $dump_cmd | grep -i "$white_list" || fail "doesn't show any expected dependencies"
+ echo "Checking for unexpected dependencies ..."
+ eval $dump_cmd | grep -i -v "$white_list"
+ ret=$?
+ if [[ $ret == 0 ]]; then
+ fail "found unexpected dependencies (listed above)."
+ elif [[ $ret != 1 ]]; then
+ fail "Error when checking dependencies."
+ fi # grep returns 1 when "not found", which is what we expect
+ echo "Dependencies look good."
+ echo
+}
+############################################################################
+
+echo "Building protoc, OS=$OS ARCH=$ARCH TARGET=$TARGET"
+
+# Nested double quotes are unintuitive, but it works.
+cd "$(dirname "$0")"
+
+WORKING_DIR=$(pwd)
+CONFIGURE_ARGS="--disable-shared"
+
+TARGET_FILE=target/$MAKE_TARGET.exe
+if [[ "$OS" == windows ]]; then
+ MAKE_TARGET="${MAKE_TARGET}.exe"
+fi
+
+# Override the default value set in configure.ac that has '-g' which produces
+# huge binary.
+CXXFLAGS="-DNDEBUG"
+LDFLAGS=""
+
+if [[ "$(uname)" == CYGWIN* ]]; then
+ assertEq "$OS" windows $LINENO
+ # Use mingw32 compilers because executables produced by Cygwin compiler
+ # always have dependency on Cygwin DLL.
+ if [[ "$ARCH" == x86_64 ]]; then
+ CONFIGURE_ARGS="$CONFIGURE_ARGS --host=x86_64-w64-mingw32"
+ elif [[ "$ARCH" == x86_32 ]]; then
+ CONFIGURE_ARGS="$CONFIGURE_ARGS --host=i686-pc-mingw32"
+ else
+ fail "Unsupported arch by CYGWIN: $ARCH"
+ fi
+elif [[ "$(uname)" == MINGW32* ]]; then
+ assertEq "$OS" windows $LINENO
+ assertEq "$ARCH" x86_32 $LINENO
+elif [[ "$(uname)" == MINGW64* ]]; then
+ assertEq "$OS" windows $LINENO
+ assertEq "$ARCH" x86_64 $LINENO
+elif [[ "$(uname)" == Linux* ]]; then
+ if [[ "$OS" == linux ]]; then
+ if [[ "$ARCH" == x86_64 ]]; then
+ CXXFLAGS="$CXXFLAGS -m64"
+ elif [[ "$ARCH" == x86_32 ]]; then
+ CXXFLAGS="$CXXFLAGS -m32"
+ else
+ fail "Unsupported arch: $ARCH"
+ fi
+ elif [[ "$OS" == windows ]]; then
+ # Cross-compilation for Windows
+ # TODO(zhangkun83) MinGW 64 always adds dependency on libwinpthread-1.dll,
+ # which is undesirable for repository deployment.
+ CONFIGURE_ARGS="$CONFIGURE_ARGS"
+ if [[ "$ARCH" == x86_64 ]]; then
+ CONFIGURE_ARGS="$CONFIGURE_ARGS --host=x86_64-w64-mingw32"
+ elif [[ "$ARCH" == x86_32 ]]; then
+ CONFIGURE_ARGS="$CONFIGURE_ARGS --host=i686-w64-mingw32"
+ else
+ fail "Unsupported arch: $ARCH"
+ fi
+ else
+ fail "Cannot build $OS on $(uname)"
+ fi
+elif [[ "$(uname)" == Darwin* ]]; then
+ assertEq "$OS" osx $LINENO
+ # Make the binary compatible with OSX 10.7 and later
+ CXXFLAGS="$CXXFLAGS -mmacosx-version-min=10.7"
+ if [[ "$ARCH" == x86_64 ]]; then
+ CXXFLAGS="$CXXFLAGS -m64"
+ elif [[ "$ARCH" == x86_32 ]]; then
+ CXXFLAGS="$CXXFLAGS -m32"
+ else
+ fail "Unsupported arch: $ARCH"
+ fi
+else
+ fail "Unsupported system: $(uname)"
+fi
+
+# Statically link libgcc and libstdc++.
+# -s to produce stripped binary.
+# And they don't work under Mac.
+if [[ "$OS" != osx ]]; then
+ LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++ -s"
+fi
+
+export CXXFLAGS LDFLAGS
+
+cd "$WORKING_DIR"/.. && ./configure $CONFIGURE_ARGS &&
+ cd src && make clean && make $MAKE_TARGET &&
+ cd "$WORKING_DIR" && mkdir -p target &&
+ cp ../src/$MAKE_TARGET $TARGET_FILE ||
+ exit 1
+
+if [[ "$OS" == osx ]]; then
+ # Since Mac linker doesn't accept "-s", we need to run strip
+ strip $TARGET_FILE || exit 1
+fi
+
+checkArch $TARGET_FILE && checkDependencies $TARGET_FILE
diff --git a/third_party/protobuf/protoc-artifacts/build-zip.sh b/third_party/protobuf/protoc-artifacts/build-zip.sh
new file mode 100755
index 0000000000..3c5e887b29
--- /dev/null
+++ b/third_party/protobuf/protoc-artifacts/build-zip.sh
@@ -0,0 +1,108 @@
+#!/bin/bash
+
+if [ $# -ne 2 ]; then
+ cat <<EOF
+Usage: $0 <TARGET> <VERSION_NUMBER>
+
+TARGET: protoc | protoc-gen-javalite
+
+Example:
+ $ $0 protoc 3.0.0
+ $ $0 protoc-gen-javalite 3.0.0
+
+This script will download pre-built protoc or protoc plugin binaries from maven
+repository and create .zip packages suitable to be included in the github
+release page. If the target is protoc, well-known type .proto files will also be
+included. Each invocation will create 5 zip packages:
+ dist/<TARGET>-<VERSION_NUMBER>-win32.zip
+ dist/<TARGET>-<VERSION_NUMBER>-osx-x86_32.zip
+ dist/<TARGET>-<VERSION_NUMBER>-osx-x86_64.zip
+ dist/<TARGET>-<VERSION_NUMBER>-linux-x86_32.zip
+ dist/<TARGET>-<VERSION_NUMBER>-linux-x86_64.zip
+EOF
+ exit 1
+fi
+
+TARGET=$1
+VERSION_NUMBER=$2
+
+# <zip file name> <binary file name> pairs.
+declare -a FILE_NAMES=( \
+ win32.zip windows-x86_32.exe \
+ osx-x86_32.zip osx-x86_32.exe \
+ osx-x86_64.zip osx-x86_64.exe \
+ linux-x86_32.zip linux-x86_32.exe \
+ linux-x86_64.zip linux-x86_64.exe \
+)
+
+# List of all well-known types to be included.
+declare -a WELL_KNOWN_TYPES=( \
+ google/protobuf/descriptor.proto \
+ google/protobuf/any.proto \
+ google/protobuf/api.proto \
+ google/protobuf/duration.proto \
+ google/protobuf/empty.proto \
+ google/protobuf/field_mask.proto \
+ google/protobuf/source_context.proto \
+ google/protobuf/struct.proto \
+ google/protobuf/timestamp.proto \
+ google/protobuf/type.proto \
+ google/protobuf/wrappers.proto \
+ google/protobuf/compiler/plugin.proto \
+)
+
+set -e
+
+# A temporary working directory to put all files.
+DIR=$(mktemp -d)
+
+# Copy over well-known types.
+mkdir -p ${DIR}/include/google/protobuf/compiler
+for PROTO in ${WELL_KNOWN_TYPES[@]}; do
+ cp -f ../src/${PROTO} ${DIR}/include/${PROTO}
+done
+
+# Create a readme file.
+cat <<EOF > ${DIR}/readme.txt
+Protocol Buffers - Google's data interchange format
+Copyright 2008 Google Inc.
+https://developers.google.com/protocol-buffers/
+
+This package contains a precompiled binary version of the protocol buffer
+compiler (protoc). This binary is intended for users who want to use Protocol
+Buffers in languages other than C++ but do not want to compile protoc
+themselves. To install, simply place this binary somewhere in your PATH.
+
+Please refer to our official github site for more installation instructions:
+ https://github.com/google/protobuf
+EOF
+
+mkdir -p dist
+mkdir -p ${DIR}/bin
+# Create a zip file for each binary.
+for((i=0;i<${#FILE_NAMES[@]};i+=2));do
+ ZIP_NAME=${FILE_NAMES[$i]}
+ if [ ${ZIP_NAME:0:3} = "win" ]; then
+ BINARY="$TARGET.exe"
+ else
+ BINARY="$TARGET"
+ fi
+ BINARY_NAME=${FILE_NAMES[$(($i+1))]}
+ BINARY_URL=http://repo1.maven.org/maven2/com/google/protobuf/$TARGET/${VERSION_NUMBER}/$TARGET-${VERSION_NUMBER}-${BINARY_NAME}
+ if ! wget ${BINARY_URL} -O ${DIR}/bin/$BINARY &> /dev/null; then
+ echo "[ERROR] Failed to download ${BINARY_URL}" >&2
+ echo "[ERROR] Skipped $TARGET-${VERSION_NAME}-${ZIP_NAME}" >&2
+ continue
+ fi
+ TARGET_ZIP_FILE=`pwd`/dist/$TARGET-${VERSION_NUMBER}-${ZIP_NAME}
+ pushd $DIR &> /dev/null
+ chmod +x bin/$BINARY
+ if [ "$TARGET" = "protoc" ]; then
+ zip -r ${TARGET_ZIP_FILE} include bin readme.txt &> /dev/null
+ else
+ zip -r ${TARGET_ZIP_FILE} bin &> /dev/null
+ fi
+ rm bin/$BINARY
+ popd &> /dev/null
+ echo "[INFO] Successfully created ${TARGET_ZIP_FILE}"
+done
diff --git a/third_party/protobuf/protoc-artifacts/pom.xml b/third_party/protobuf/protoc-artifacts/pom.xml
new file mode 100644
index 0000000000..28a2511926
--- /dev/null
+++ b/third_party/protobuf/protoc-artifacts/pom.xml
@@ -0,0 +1,135 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>com.google</groupId>
+ <artifactId>google</artifactId>
+ <version>1</version>
+ </parent>
+ <groupId>com.google.protobuf</groupId>
+ <artifactId>protoc</artifactId>
+ <version>3.2.0</version>
+ <packaging>pom</packaging>
+ <name>Protobuf Compiler</name>
+ <description>
+ Protobuf Compiler (protoc) is a compiler for .proto files. It generates
+ language-specific code for Protobuf messages and RPC interfaces.
+ </description>
+ <inceptionYear>2008</inceptionYear>
+ <url>https://developers.google.com/protocol-buffers/</url>
+ <licenses>
+ <license>
+ <name>3-Clause BSD License</name>
+ <url>https://opensource.org/licenses/BSD-3-Clause</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+ <scm>
+ <url>https://github.com/google/protobuf</url>
+ <connection>
+ scm:git:https://github.com/google/protobuf.git
+ </connection>
+ </scm>
+ <build>
+ <extensions>
+ <extension>
+ <groupId>kr.motd.maven</groupId>
+ <artifactId>os-maven-plugin</artifactId>
+ <version>1.2.3.Final</version>
+ </extension>
+ </extensions>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.1.1</version>
+ <executions>
+ <execution>
+ <phase>compile</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <executable>bash</executable>
+ <arguments>
+ <argument>build-protoc.sh</argument>
+ <argument>${os.detected.name}</argument>
+ <argument>${os.detected.arch}</argument>
+ <argument>protoc</argument>
+ </arguments>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.8</version>
+ <executions>
+ <execution>
+ <id>attach-artifacts</id>
+ <phase>package</phase>
+ <goals>
+ <goal>attach-artifact</goal>
+ </goals>
+ <configuration>
+ <artifacts>
+ <artifact>
+ <file>${basedir}/target/protoc.exe</file>
+ <classifier>${os.detected.name}-${os.detected.arch}</classifier>
+ <type>exe</type>
+ </artifact>
+ </artifacts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <profiles>
+ <profile>
+ <id>release</id>
+ <properties>
+ <!-- Specify the staging repository to deploy to. This can be left
+ empty for the first deployment, and Sonatype will create one. For
+ subsequent deployments it should be set to what Sonatype has
+ created, so that all deployments will go to the same repository.
+ -->
+ <staging.repository></staging.repository>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-gpg-plugin</artifactId>
+ <version>1.5</version>
+ <executions>
+ <execution>
+ <id>sign-artifacts</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>sign</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.sonatype.plugins</groupId>
+ <artifactId>nexus-staging-maven-plugin</artifactId>
+ <version>1.6.3</version>
+ <extensions>true</extensions>
+ <configuration>
+ <serverId>sonatype-nexus-staging</serverId>
+ <nexusUrl>https://oss.sonatype.org/</nexusUrl>
+ <skipStagingRepositoryClose>true</skipStagingRepositoryClose>
+ <autoReleaseAfterClose>false</autoReleaseAfterClose>
+ <stagingRepositoryId>${staging.repository}</stagingRepositoryId>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
diff --git a/third_party/protobuf/python/MANIFEST.in b/third_party/protobuf/python/MANIFEST.in
new file mode 100644
index 0000000000..260888263b
--- /dev/null
+++ b/third_party/protobuf/python/MANIFEST.in
@@ -0,0 +1,14 @@
+prune google/protobuf/internal/import_test_package
+exclude google/protobuf/internal/*_pb2.py
+exclude google/protobuf/internal/*_test.py
+exclude google/protobuf/internal/*.proto
+exclude google/protobuf/internal/test_util.py
+
+recursive-exclude google *_test.py
+recursive-exclude google *_test.proto
+recursive-exclude google unittest*_pb2.py
+
+global-exclude *.dll
+global-exclude *.pyc
+global-exclude *.pyo
+global-exclude *.so
diff --git a/third_party/protobuf/python/README.md b/third_party/protobuf/python/README.md
new file mode 100644
index 0000000000..8f3db7851c
--- /dev/null
+++ b/third_party/protobuf/python/README.md
@@ -0,0 +1,127 @@
+Protocol Buffers - Google's data interchange format
+===================================================
+
+[![Build Status](https://travis-ci.org/google/protobuf.svg?branch=master)](https://travis-ci.org/google/protobuf)
+
+Copyright 2008 Google Inc.
+
+This directory contains the Python Protocol Buffers runtime library.
+
+Normally, this directory comes as part of the protobuf package, available
+from:
+
+ https://developers.google.com/protocol-buffers/
+
+The complete package includes the C++ source code, which includes the
+Protocol Compiler (protoc). If you downloaded this package from PyPI
+or some other Python-specific source, you may have received only the
+Python part of the code. In this case, you will need to obtain the
+Protocol Compiler from some other source before you can use this
+package.
+
+Development Warning
+===================
+
+The Python implementation of Protocol Buffers is not as mature as the C++
+and Java implementations. It may be more buggy, and it is known to be
+pretty slow at this time. If you would like to help fix these issues,
+join the Protocol Buffers discussion list and let us know!
+
+Installation
+============
+
+1) Make sure you have Python 2.6 or newer. If in doubt, run:
+
+ $ python -V
+
+2) If you do not have setuptools installed, note that it will be
+ downloaded and installed automatically as soon as you run setup.py.
+ If you would rather install it manually, you may do so by following
+ the instructions on this page:
+
+ https://packaging.python.org/en/latest/installing.html#setup-for-installing-packages
+
+3) Build the C++ code, or install a binary distribution of protoc. If
+ you install a binary distribution, make sure that it is the same
+ version as this package. If in doubt, run:
+
+ $ protoc --version
+
+4) Build and run the tests:
+
+ $ python setup.py build
+ $ python setup.py test
+
+ To build, test, and use the C++ implementation, you must first compile
+ libprotobuf.so:
+
+ $ (cd .. && make)
+
+ On OS X:
+
+ If you are running a homebrew-provided python, you must make sure another
+ version of protobuf is not already installed, as homebrew's python will
+ search /usr/local/lib for libprotobuf.so before it searches ../src/.libs
+ You can either unlink homebrew's protobuf or install the libprotobuf you
+ built earlier:
+
+ $ brew unlink protobuf
+ or
+ $ (cd .. && make install)
+
+ On other *nix:
+
+ You must make libprotobuf.so dynamically available. You can either
+ install libprotobuf you built earlier, or set LD_LIBRARY_PATH:
+
+ $ export LD_LIBRARY_PATH=../src/.libs
+ or
+ $ (cd .. && make install)
+
+ To build the C++ implementation run:
+ $ python setup.py build --cpp_implementation
+
+ Then run the tests like so:
+ $ python setup.py test --cpp_implementation
+
+ If some tests fail, this library may not work correctly on your
+ system. Continue at your own risk.
+
+ Please note that there is a known problem with some versions of
+ Python on Cygwin which causes the tests to fail after printing the
+ error: "sem_init: Resource temporarily unavailable". This appears
+ to be a bug either in Cygwin or in Python:
+ http://www.cygwin.com/ml/cygwin/2005-07/msg01378.html
+ We do not know if or when it might be fixed. We also do not know
+ how likely it is that this bug will affect users in practice.
+
+5) Install:
+
+ $ python setup.py install
+
+ or:
+
+ $ (cd .. && make install)
+ $ python setup.py install --cpp_implementation
+
+ This step may require superuser privileges.
+ NOTE: To use C++ implementation, you need to export an environment
+ variable before running your program. See the "C++ Implementation"
+ section below for more details.
+
+Usage
+=====
+
+The complete documentation for Protocol Buffers is available via the
+web at:
+
+ https://developers.google.com/protocol-buffers/
+
+C++ Implementation
+==================
+
+The C++ implementation for Python messages is built as a Python extension to
+improve the overall protobuf Python performance.
+
+To use the C++ implementation, you need to install the C++ protobuf runtime
+library, please see instructions in the parent directory.
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/factory_test1.proto b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/factory_test1.proto
new file mode 100644
index 0000000000..9f55e037f6
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/factory_test1.proto
@@ -0,0 +1,55 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: matthewtoia@google.com (Matt Toia)
+
+
+package google.protobuf.python.internal;
+
+
+enum Factory1Enum {
+ FACTORY_1_VALUE_0 = 0;
+ FACTORY_1_VALUE_1 = 1;
+}
+
+message Factory1Message {
+ optional Factory1Enum factory_1_enum = 1;
+ enum NestedFactory1Enum {
+ NESTED_FACTORY_1_VALUE_0 = 0;
+ NESTED_FACTORY_1_VALUE_1 = 1;
+ }
+ optional NestedFactory1Enum nested_factory_1_enum = 2;
+ message NestedFactory1Message {
+ optional string value = 1;
+ }
+ optional NestedFactory1Message nested_factory_1_message = 3;
+ optional int32 scalar_value = 4;
+ repeated string list_value = 5;
+}
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/factory_test2.proto b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/factory_test2.proto
new file mode 100644
index 0000000000..d3ce4d7f95
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/factory_test2.proto
@@ -0,0 +1,77 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: matthewtoia@google.com (Matt Toia)
+
+
+package google.protobuf.python.internal;
+
+import "google/protobuf/internal/factory_test1.proto";
+
+
+enum Factory2Enum {
+ FACTORY_2_VALUE_0 = 0;
+ FACTORY_2_VALUE_1 = 1;
+}
+
+message Factory2Message {
+ required int32 mandatory = 1;
+ optional Factory2Enum factory_2_enum = 2;
+ enum NestedFactory2Enum {
+ NESTED_FACTORY_2_VALUE_0 = 0;
+ NESTED_FACTORY_2_VALUE_1 = 1;
+ }
+ optional NestedFactory2Enum nested_factory_2_enum = 3;
+ message NestedFactory2Message {
+ optional string value = 1;
+ }
+ optional NestedFactory2Message nested_factory_2_message = 4;
+ optional Factory1Message factory_1_message = 5;
+ optional Factory1Enum factory_1_enum = 6;
+ optional Factory1Message.NestedFactory1Enum nested_factory_1_enum = 7;
+ optional Factory1Message.NestedFactory1Message nested_factory_1_message = 8;
+ optional Factory2Message circular_message = 9;
+ optional string scalar_value = 10;
+ repeated string list_value = 11;
+ repeated group Grouped = 12 {
+ optional string part_1 = 13;
+ optional string part_2 = 14;
+ }
+ optional LoopMessage loop = 15;
+ optional int32 int_with_default = 16 [default = 1776];
+ optional double double_with_default = 17 [default = 9.99];
+ optional string string_with_default = 18 [default = "hello world"];
+ optional bool bool_with_default = 19 [default = false];
+ optional Factory2Enum enum_with_default = 20 [default = FACTORY_2_VALUE_1];
+}
+
+message LoopMessage {
+ optional Factory2Message loop = 1;
+}
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/more_extensions.proto b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/more_extensions.proto
new file mode 100644
index 0000000000..e2d9701045
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/more_extensions.proto
@@ -0,0 +1,58 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: robinson@google.com (Will Robinson)
+
+
+package google.protobuf.internal;
+
+
+message TopLevelMessage {
+ optional ExtendedMessage submessage = 1;
+}
+
+
+message ExtendedMessage {
+ extensions 1 to max;
+}
+
+
+message ForeignMessage {
+ optional int32 foreign_message_int = 1;
+}
+
+
+extend ExtendedMessage {
+ optional int32 optional_int_extension = 1;
+ optional ForeignMessage optional_message_extension = 2;
+
+ repeated int32 repeated_int_extension = 3;
+ repeated ForeignMessage repeated_message_extension = 4;
+}
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/more_extensions_dynamic.proto b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/more_extensions_dynamic.proto
new file mode 100644
index 0000000000..df98ac4bd1
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/more_extensions_dynamic.proto
@@ -0,0 +1,49 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: jasonh@google.com (Jason Hsueh)
+//
+// This file is used to test a corner case in the CPP implementation where the
+// generated C++ type is available for the extendee, but the extension is
+// defined in a file whose C++ type is not in the binary.
+
+
+import "google/protobuf/internal/more_extensions.proto";
+
+package google.protobuf.internal;
+
+message DynamicMessageType {
+ optional int32 a = 1;
+}
+
+extend ExtendedMessage {
+ optional int32 dynamic_int32_extension = 100;
+ optional DynamicMessageType dynamic_message_extension = 101;
+}
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/more_messages.proto b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/more_messages.proto
new file mode 100644
index 0000000000..c701b4460b
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/more_messages.proto
@@ -0,0 +1,51 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: robinson@google.com (Will Robinson)
+
+
+package google.protobuf.internal;
+
+// A message where tag numbers are listed out of order, to allow us to test our
+// canonicalization of serialized output, which should always be in tag order.
+// We also mix in some extensions for extra fun.
+message OutOfOrderFields {
+ optional sint32 optional_sint32 = 5;
+ extensions 4 to 4;
+ optional uint32 optional_uint32 = 3;
+ extensions 2 to 2;
+ optional int32 optional_int32 = 1;
+};
+
+
+extend OutOfOrderFields {
+ optional uint64 optional_uint64 = 4;
+ optional int64 optional_int64 = 2;
+}
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/test_bad_identifiers.proto b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/test_bad_identifiers.proto
new file mode 100644
index 0000000000..6a82299a52
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/python/google/protobuf/internal/test_bad_identifiers.proto
@@ -0,0 +1,52 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+
+
+package protobuf_unittest;
+
+option py_generic_services = true;
+
+message TestBadIdentifiers {
+ extensions 100 to max;
+}
+
+// Make sure these reasonable extension names don't conflict with internal
+// variables.
+extend TestBadIdentifiers {
+ optional string message = 100 [default="foo"];
+ optional string descriptor = 101 [default="bar"];
+ optional string reflection = 102 [default="baz"];
+ optional string service = 103 [default="qux"];
+}
+
+message AnotherMessage {}
+service AnotherService {}
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/descriptor.proto b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/descriptor.proto
new file mode 100644
index 0000000000..a785f79faf
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/descriptor.proto
@@ -0,0 +1,620 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// The messages in this file describe the definitions found in .proto files.
+// A valid .proto file can be translated directly to a FileDescriptorProto
+// without any other information (e.g. without reading its imports).
+
+
+
+package google.protobuf;
+option java_package = "com.google.protobuf";
+option java_outer_classname = "DescriptorProtos";
+
+// descriptor.proto must be optimized for speed because reflection-based
+// algorithms don't work during bootstrapping.
+option optimize_for = SPEED;
+
+// The protocol compiler can output a FileDescriptorSet containing the .proto
+// files it parses.
+message FileDescriptorSet {
+ repeated FileDescriptorProto file = 1;
+}
+
+// Describes a complete .proto file.
+message FileDescriptorProto {
+ optional string name = 1; // file name, relative to root of source tree
+ optional string package = 2; // e.g. "foo", "foo.bar", etc.
+
+ // Names of files imported by this file.
+ repeated string dependency = 3;
+ // Indexes of the public imported files in the dependency list above.
+ repeated int32 public_dependency = 10;
+ // Indexes of the weak imported files in the dependency list.
+ // For Google-internal migration only. Do not use.
+ repeated int32 weak_dependency = 11;
+
+ // All top-level definitions in this file.
+ repeated DescriptorProto message_type = 4;
+ repeated EnumDescriptorProto enum_type = 5;
+ repeated ServiceDescriptorProto service = 6;
+ repeated FieldDescriptorProto extension = 7;
+
+ optional FileOptions options = 8;
+
+ // This field contains optional information about the original source code.
+ // You may safely remove this entire field whithout harming runtime
+ // functionality of the descriptors -- the information is needed only by
+ // development tools.
+ optional SourceCodeInfo source_code_info = 9;
+}
+
+// Describes a message type.
+message DescriptorProto {
+ optional string name = 1;
+
+ repeated FieldDescriptorProto field = 2;
+ repeated FieldDescriptorProto extension = 6;
+
+ repeated DescriptorProto nested_type = 3;
+ repeated EnumDescriptorProto enum_type = 4;
+
+ message ExtensionRange {
+ optional int32 start = 1;
+ optional int32 end = 2;
+ }
+ repeated ExtensionRange extension_range = 5;
+
+ optional MessageOptions options = 7;
+}
+
+// Describes a field within a message.
+message FieldDescriptorProto {
+ enum Type {
+ // 0 is reserved for errors.
+ // Order is weird for historical reasons.
+ TYPE_DOUBLE = 1;
+ TYPE_FLOAT = 2;
+ // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
+ // negative values are likely.
+ TYPE_INT64 = 3;
+ TYPE_UINT64 = 4;
+ // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
+ // negative values are likely.
+ TYPE_INT32 = 5;
+ TYPE_FIXED64 = 6;
+ TYPE_FIXED32 = 7;
+ TYPE_BOOL = 8;
+ TYPE_STRING = 9;
+ TYPE_GROUP = 10; // Tag-delimited aggregate.
+ TYPE_MESSAGE = 11; // Length-delimited aggregate.
+
+ // New in version 2.
+ TYPE_BYTES = 12;
+ TYPE_UINT32 = 13;
+ TYPE_ENUM = 14;
+ TYPE_SFIXED32 = 15;
+ TYPE_SFIXED64 = 16;
+ TYPE_SINT32 = 17; // Uses ZigZag encoding.
+ TYPE_SINT64 = 18; // Uses ZigZag encoding.
+ };
+
+ enum Label {
+ // 0 is reserved for errors
+ LABEL_OPTIONAL = 1;
+ LABEL_REQUIRED = 2;
+ LABEL_REPEATED = 3;
+ // TODO(sanjay): Should we add LABEL_MAP?
+ };
+
+ optional string name = 1;
+ optional int32 number = 3;
+ optional Label label = 4;
+
+ // If type_name is set, this need not be set. If both this and type_name
+ // are set, this must be either TYPE_ENUM or TYPE_MESSAGE.
+ optional Type type = 5;
+
+ // For message and enum types, this is the name of the type. If the name
+ // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
+ // rules are used to find the type (i.e. first the nested types within this
+ // message are searched, then within the parent, on up to the root
+ // namespace).
+ optional string type_name = 6;
+
+ // For extensions, this is the name of the type being extended. It is
+ // resolved in the same manner as type_name.
+ optional string extendee = 2;
+
+ // For numeric types, contains the original text representation of the value.
+ // For booleans, "true" or "false".
+ // For strings, contains the default text contents (not escaped in any way).
+ // For bytes, contains the C escaped value. All bytes >= 128 are escaped.
+ // TODO(kenton): Base-64 encode?
+ optional string default_value = 7;
+
+ optional FieldOptions options = 8;
+}
+
+// Describes an enum type.
+message EnumDescriptorProto {
+ optional string name = 1;
+
+ repeated EnumValueDescriptorProto value = 2;
+
+ optional EnumOptions options = 3;
+}
+
+// Describes a value within an enum.
+message EnumValueDescriptorProto {
+ optional string name = 1;
+ optional int32 number = 2;
+
+ optional EnumValueOptions options = 3;
+}
+
+// Describes a service.
+message ServiceDescriptorProto {
+ optional string name = 1;
+ repeated MethodDescriptorProto method = 2;
+
+ optional ServiceOptions options = 3;
+}
+
+// Describes a method of a service.
+message MethodDescriptorProto {
+ optional string name = 1;
+
+ // Input and output type names. These are resolved in the same way as
+ // FieldDescriptorProto.type_name, but must refer to a message type.
+ optional string input_type = 2;
+ optional string output_type = 3;
+
+ optional MethodOptions options = 4;
+}
+
+
+// ===================================================================
+// Options
+
+// Each of the definitions above may have "options" attached. These are
+// just annotations which may cause code to be generated slightly differently
+// or may contain hints for code that manipulates protocol messages.
+//
+// Clients may define custom options as extensions of the *Options messages.
+// These extensions may not yet be known at parsing time, so the parser cannot
+// store the values in them. Instead it stores them in a field in the *Options
+// message called uninterpreted_option. This field must have the same name
+// across all *Options messages. We then use this field to populate the
+// extensions when we build a descriptor, at which point all protos have been
+// parsed and so all extensions are known.
+//
+// Extension numbers for custom options may be chosen as follows:
+// * For options which will only be used within a single application or
+// organization, or for experimental options, use field numbers 50000
+// through 99999. It is up to you to ensure that you do not use the
+// same number for multiple options.
+// * For options which will be published and used publicly by multiple
+// independent entities, e-mail protobuf-global-extension-registry@google.com
+// to reserve extension numbers. Simply provide your project name (e.g.
+// Object-C plugin) and your porject website (if available) -- there's no need
+// to explain how you intend to use them. Usually you only need one extension
+// number. You can declare multiple options with only one extension number by
+// putting them in a sub-message. See the Custom Options section of the docs
+// for examples:
+// http://code.google.com/apis/protocolbuffers/docs/proto.html#options
+// If this turns out to be popular, a web service will be set up
+// to automatically assign option numbers.
+
+
+message FileOptions {
+
+ // Sets the Java package where classes generated from this .proto will be
+ // placed. By default, the proto package is used, but this is often
+ // inappropriate because proto packages do not normally start with backwards
+ // domain names.
+ optional string java_package = 1;
+
+
+ // If set, all the classes from the .proto file are wrapped in a single
+ // outer class with the given name. This applies to both Proto1
+ // (equivalent to the old "--one_java_file" option) and Proto2 (where
+ // a .proto always translates to a single class, but you may want to
+ // explicitly choose the class name).
+ optional string java_outer_classname = 8;
+
+ // If set true, then the Java code generator will generate a separate .java
+ // file for each top-level message, enum, and service defined in the .proto
+ // file. Thus, these types will *not* be nested inside the outer class
+ // named by java_outer_classname. However, the outer class will still be
+ // generated to contain the file's getDescriptor() method as well as any
+ // 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 is
+ // purely a speed optimization, as the AbstractMessage base class includes
+ // reflection-based implementations of these methods.
+ optional bool java_generate_equals_and_hash = 20 [default=false];
+
+ // Generated classes can be optimized for speed or code size.
+ enum OptimizeMode {
+ SPEED = 1; // Generate complete code for parsing, serialization,
+ // etc.
+ CODE_SIZE = 2; // Use ReflectionOps to implement these methods.
+ LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime.
+ }
+ optional OptimizeMode optimize_for = 9 [default=SPEED];
+
+ // Sets the Go package where structs generated from this .proto will be
+ // placed. There is no default.
+ optional string go_package = 11;
+
+
+
+ // Should generic services be generated in each language? "Generic" services
+ // are not specific to any particular RPC system. They are generated by the
+ // main code generators in each language (without additional plugins).
+ // Generic services were the only kind of service generation supported by
+ // early versions of proto2.
+ //
+ // Generic services are now considered deprecated in favor of using plugins
+ // that generate code specific to your particular RPC system. Therefore,
+ // these default to false. Old code which depends on generic services should
+ // explicitly set them to true.
+ optional bool cc_generic_services = 16 [default=false];
+ optional bool java_generic_services = 17 [default=false];
+ optional bool py_generic_services = 18 [default=false];
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message MessageOptions {
+ // Set true to use the old proto1 MessageSet wire format for extensions.
+ // This is provided for backwards-compatibility with the MessageSet wire
+ // format. You should not use this for any other reason: It's less
+ // efficient, has fewer features, and is more complicated.
+ //
+ // The message must be defined exactly as follows:
+ // message Foo {
+ // option message_set_wire_format = true;
+ // extensions 4 to max;
+ // }
+ // Note that the message cannot have any defined fields; MessageSets only
+ // have extensions.
+ //
+ // All extensions of your type must be singular messages; e.g. they cannot
+ // be int32s, enums, or repeated messages.
+ //
+ // Because this is an option, the above two restrictions are not enforced by
+ // the protocol compiler.
+ optional bool message_set_wire_format = 1 [default=false];
+
+ // Disables the generation of the standard "descriptor()" accessor, which can
+ // conflict with a field of the same name. This is meant to make migration
+ // from proto1 easier; new code should avoid fields named "descriptor".
+ optional bool no_standard_descriptor_accessor = 2 [default=false];
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message FieldOptions {
+ // The ctype option instructs the C++ code generator to use a different
+ // representation of the field than it normally would. See the specific
+ // options below. This option is not yet implemented in the open source
+ // release -- sorry, we'll try to include it in a future version!
+ optional CType ctype = 1 [default = STRING];
+ enum CType {
+ // Default mode.
+ STRING = 0;
+
+ CORD = 1;
+
+ STRING_PIECE = 2;
+ }
+ // The packed option can be enabled for repeated primitive fields to enable
+ // a more efficient representation on the wire. Rather than repeatedly
+ // writing the tag and type for each element, the entire array is encoded as
+ // a single length-delimited blob.
+ optional bool packed = 2;
+
+
+
+ // Should this field be parsed lazily? Lazy applies only to message-type
+ // fields. It means that when the outer message is initially parsed, the
+ // inner message's contents will not be parsed but instead stored in encoded
+ // form. The inner message will actually be parsed when it is first accessed.
+ //
+ // This is only a hint. Implementations are free to choose whether to use
+ // eager or lazy parsing regardless of the value of this option. However,
+ // setting this option true suggests that the protocol author believes that
+ // using lazy parsing on this field is worth the additional bookkeeping
+ // overhead typically needed to implement it.
+ //
+ // This option does not affect the public interface of any generated code;
+ // all method signatures remain the same. Furthermore, thread-safety of the
+ // interface is not affected by this option; const methods remain safe to
+ // call from multiple threads concurrently, while non-const methods continue
+ // to require exclusive access.
+ //
+ //
+ // Note that implementations may choose not to check required fields within
+ // a lazy sub-message. That is, calling IsInitialized() on the outher 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
+ // parsing. An implementation which chooses not to check required fields
+ // must be consistent about it. That is, for any particular sub-message, the
+ // implementation must either *always* check its required fields, or *never*
+ // check its required fields, regardless of whether or not the message has
+ // been parsed.
+ optional bool lazy = 5 [default=false];
+
+ // Is this field deprecated?
+ // Depending on the target platform, this can emit Deprecated annotations
+ // for accessors, or it will be completely ignored; in the very least, this
+ // is a formalization for deprecating fields.
+ optional bool deprecated = 3 [default=false];
+
+ // EXPERIMENTAL. DO NOT USE.
+ // For "map" fields, the name of the field in the enclosed type that
+ // is the key for this map. For example, suppose we have:
+ // message Item {
+ // required string name = 1;
+ // required string value = 2;
+ // }
+ // message Config {
+ // repeated Item items = 1 [experimental_map_key="name"];
+ // }
+ // In this situation, the map key for Item will be set to "name".
+ // TODO: Fully-implement this, then remove the "experimental_" prefix.
+ optional string experimental_map_key = 9;
+
+ // For Google-internal migration only. Do not use.
+ optional bool weak = 10 [default=false];
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message EnumOptions {
+
+ // Set this option to false to disallow mapping different tag names to a same
+ // value.
+ optional bool allow_alias = 2 [default=true];
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message EnumValueOptions {
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message ServiceOptions {
+
+ // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
+ // framework. We apologize for hoarding these numbers to ourselves, but
+ // we were already using them long before we decided to release Protocol
+ // Buffers.
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+message MethodOptions {
+
+ // Note: Field numbers 1 through 32 are reserved for Google's internal RPC
+ // framework. We apologize for hoarding these numbers to ourselves, but
+ // we were already using them long before we decided to release Protocol
+ // Buffers.
+
+ // The parser stores options it doesn't recognize here. See above.
+ repeated UninterpretedOption uninterpreted_option = 999;
+
+ // Clients can define custom options in extensions of this message. See above.
+ extensions 1000 to max;
+}
+
+
+// A message representing a option the parser does not recognize. This only
+// appears in options protos created by the compiler::Parser class.
+// DescriptorPool resolves these when building Descriptor objects. Therefore,
+// options protos in descriptor objects (e.g. returned by Descriptor::options(),
+// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
+// in them.
+message UninterpretedOption {
+ // The name of the uninterpreted option. Each string represents a segment in
+ // a dot-separated name. is_extension is true iff a segment represents an
+ // extension (denoted with parentheses in options specs in .proto files).
+ // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
+ // "foo.(bar.baz).qux".
+ message NamePart {
+ required string name_part = 1;
+ required bool is_extension = 2;
+ }
+ repeated NamePart name = 2;
+
+ // The value of the uninterpreted option, in whatever type the tokenizer
+ // identified it as during parsing. Exactly one of these should be set.
+ optional string identifier_value = 3;
+ optional uint64 positive_int_value = 4;
+ optional int64 negative_int_value = 5;
+ optional double double_value = 6;
+ optional bytes string_value = 7;
+ optional string aggregate_value = 8;
+}
+
+// ===================================================================
+// Optional source code info
+
+// Encapsulates information about the original source file from which a
+// FileDescriptorProto was generated.
+message SourceCodeInfo {
+ // A Location identifies a piece of source code in a .proto file which
+ // corresponds to a particular definition. This information is intended
+ // to be useful to IDEs, code indexers, documentation generators, and similar
+ // tools.
+ //
+ // For example, say we have a file like:
+ // message Foo {
+ // optional string foo = 1;
+ // }
+ // Let's look at just the field definition:
+ // optional string foo = 1;
+ // ^ ^^ ^^ ^ ^^^
+ // a bc de f ghi
+ // We have the following locations:
+ // span path represents
+ // [a,i) [ 4, 0, 2, 0 ] The whole field definition.
+ // [a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
+ // [c,d) [ 4, 0, 2, 0, 5 ] The type (string).
+ // [e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
+ // [g,h) [ 4, 0, 2, 0, 3 ] The number (1).
+ //
+ // Notes:
+ // - A location may refer to a repeated field itself (i.e. not to any
+ // particular index within it). This is used whenever a set of elements are
+ // logically enclosed in a single code segment. For example, an entire
+ // extend block (possibly containing multiple extension definitions) will
+ // have an outer location whose path refers to the "extensions" repeated
+ // field without an index.
+ // - Multiple locations may have the same path. This happens when a single
+ // logical declaration is spread out across multiple places. The most
+ // obvious example is the "extend" block again -- there may be multiple
+ // extend blocks in the same scope, each of which will have the same path.
+ // - A location's span is not always a subset of its parent's span. For
+ // example, the "extendee" of an extension declaration appears at the
+ // beginning of the "extend" block and is shared by all extensions within
+ // the block.
+ // - Just because a location's span is a subset of some other location's span
+ // does not mean that it is a descendent. For example, a "group" defines
+ // both a type and a field in a single declaration. Thus, the locations
+ // corresponding to the type and field and their components will overlap.
+ // - Code which tries to interpret locations should probably be designed to
+ // ignore those that it doesn't understand, as more types of locations could
+ // be recorded in the future.
+ repeated Location location = 1;
+ message Location {
+ // Identifies which part of the FileDescriptorProto was defined at this
+ // location.
+ //
+ // Each element is a field number or an index. They form a path from
+ // the root FileDescriptorProto to the place where the definition. For
+ // example, this path:
+ // [ 4, 3, 2, 7, 1 ]
+ // refers to:
+ // file.message_type(3) // 4, 3
+ // .field(7) // 2, 7
+ // .name() // 1
+ // This is because FileDescriptorProto.message_type has field number 4:
+ // repeated DescriptorProto message_type = 4;
+ // and DescriptorProto.field has field number 2:
+ // repeated FieldDescriptorProto field = 2;
+ // and FieldDescriptorProto.name has field number 1:
+ // optional string name = 1;
+ //
+ // Thus, the above path gives the location of a field name. If we removed
+ // the last element:
+ // [ 4, 3, 2, 7 ]
+ // this path refers to the whole field declaration (from the beginning
+ // of the label to the terminating semicolon).
+ repeated int32 path = 1 [packed=true];
+
+ // Always has exactly three or four elements: start line, start column,
+ // end line (optional, otherwise assumed same as start line), end column.
+ // These are packed into a single field for efficiency. Note that line
+ // and column numbers are zero-based -- typically you will want to add
+ // 1 to each before displaying to a user.
+ repeated int32 span = 2 [packed=true];
+
+ // If this SourceCodeInfo represents a complete declaration, these are any
+ // comments appearing before and after the declaration which appear to be
+ // attached to the declaration.
+ //
+ // A series of line comments appearing on consecutive lines, with no other
+ // tokens appearing on those lines, will be treated as a single comment.
+ //
+ // Only the comment content is provided; comment markers (e.g. //) are
+ // stripped out. For block comments, leading whitespace and an asterisk
+ // will be stripped from the beginning of each line other than the first.
+ // Newlines are included in the output.
+ //
+ // Examples:
+ //
+ // optional int32 foo = 1; // Comment attached to foo.
+ // // Comment attached to bar.
+ // optional int32 bar = 2;
+ //
+ // optional string baz = 3;
+ // // Comment attached to baz.
+ // // Another line attached to baz.
+ //
+ // // Comment attached to qux.
+ // //
+ // // Another line attached to qux.
+ // optional double qux = 4;
+ //
+ // optional string corge = 5;
+ // /* Block comment attached
+ // * to corge. Leading asterisks
+ // * will be removed. */
+ // /* Block comment attached to
+ // * grault. */
+ // optional int32 grault = 6;
+ optional string leading_comments = 3;
+ optional string trailing_comments = 4;
+ }
+}
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest.proto b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest.proto
new file mode 100644
index 0000000000..6eb2d86f51
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest.proto
@@ -0,0 +1,719 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file we will use for unit testing.
+
+
+// Some generic_services option(s) added automatically.
+// See: http://go/proto2-generic-services-default
+option cc_generic_services = true; // auto-added
+option java_generic_services = true; // auto-added
+option py_generic_services = true; // auto-added
+
+import "google/protobuf/unittest_import.proto";
+
+// We don't put this in a package within proto2 because we need to make sure
+// that the generated code doesn't depend on being in the proto2 namespace.
+// In test_util.h we do "using namespace unittest = protobuf_unittest".
+package protobuf_unittest;
+
+// Protos optimized for SPEED use a strict superset of the generated code
+// of equivalent ones optimized for CODE_SIZE, so we should optimize all our
+// tests for speed unless explicitly testing code size optimization.
+option optimize_for = SPEED;
+
+option java_outer_classname = "UnittestProto";
+
+// This proto includes every type of field in both singular and repeated
+// forms.
+message TestAllTypes {
+ message NestedMessage {
+ // The field name "b" fails to compile in proto1 because it conflicts with
+ // a local variable named "b" in one of the generated methods. Doh.
+ // This file needs to compile in proto1 to test backwards-compatibility.
+ optional int32 bb = 1;
+ }
+
+ enum NestedEnum {
+ FOO = 1;
+ BAR = 2;
+ BAZ = 3;
+ }
+
+ // Singular
+ optional int32 optional_int32 = 1;
+ optional int64 optional_int64 = 2;
+ optional uint32 optional_uint32 = 3;
+ optional uint64 optional_uint64 = 4;
+ optional sint32 optional_sint32 = 5;
+ optional sint64 optional_sint64 = 6;
+ optional fixed32 optional_fixed32 = 7;
+ optional fixed64 optional_fixed64 = 8;
+ optional sfixed32 optional_sfixed32 = 9;
+ optional sfixed64 optional_sfixed64 = 10;
+ optional float optional_float = 11;
+ optional double optional_double = 12;
+ optional bool optional_bool = 13;
+ optional string optional_string = 14;
+ optional bytes optional_bytes = 15;
+
+ optional group OptionalGroup = 16 {
+ optional int32 a = 17;
+ }
+
+ optional NestedMessage optional_nested_message = 18;
+ optional ForeignMessage optional_foreign_message = 19;
+ optional protobuf_unittest_import.ImportMessage optional_import_message = 20;
+
+ optional NestedEnum optional_nested_enum = 21;
+ optional ForeignEnum optional_foreign_enum = 22;
+ optional protobuf_unittest_import.ImportEnum optional_import_enum = 23;
+
+ optional string optional_string_piece = 24 [ctype=STRING_PIECE];
+ optional string optional_cord = 25 [ctype=CORD];
+
+ // Defined in unittest_import_public.proto
+ optional protobuf_unittest_import.PublicImportMessage
+ optional_public_import_message = 26;
+
+ optional NestedMessage optional_lazy_message = 27 [lazy=true];
+
+ // Repeated
+ repeated int32 repeated_int32 = 31;
+ repeated int64 repeated_int64 = 32;
+ repeated uint32 repeated_uint32 = 33;
+ repeated uint64 repeated_uint64 = 34;
+ repeated sint32 repeated_sint32 = 35;
+ repeated sint64 repeated_sint64 = 36;
+ repeated fixed32 repeated_fixed32 = 37;
+ repeated fixed64 repeated_fixed64 = 38;
+ repeated sfixed32 repeated_sfixed32 = 39;
+ repeated sfixed64 repeated_sfixed64 = 40;
+ repeated float repeated_float = 41;
+ repeated double repeated_double = 42;
+ repeated bool repeated_bool = 43;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+
+ repeated group RepeatedGroup = 46 {
+ optional int32 a = 47;
+ }
+
+ repeated NestedMessage repeated_nested_message = 48;
+ repeated ForeignMessage repeated_foreign_message = 49;
+ repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50;
+
+ repeated NestedEnum repeated_nested_enum = 51;
+ repeated ForeignEnum repeated_foreign_enum = 52;
+ repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53;
+
+ repeated string repeated_string_piece = 54 [ctype=STRING_PIECE];
+ repeated string repeated_cord = 55 [ctype=CORD];
+
+ repeated NestedMessage repeated_lazy_message = 57 [lazy=true];
+
+ // Singular with defaults
+ optional int32 default_int32 = 61 [default = 41 ];
+ optional int64 default_int64 = 62 [default = 42 ];
+ optional uint32 default_uint32 = 63 [default = 43 ];
+ optional uint64 default_uint64 = 64 [default = 44 ];
+ optional sint32 default_sint32 = 65 [default = -45 ];
+ optional sint64 default_sint64 = 66 [default = 46 ];
+ optional fixed32 default_fixed32 = 67 [default = 47 ];
+ optional fixed64 default_fixed64 = 68 [default = 48 ];
+ optional sfixed32 default_sfixed32 = 69 [default = 49 ];
+ optional sfixed64 default_sfixed64 = 70 [default = -50 ];
+ optional float default_float = 71 [default = 51.5 ];
+ optional double default_double = 72 [default = 52e3 ];
+ optional bool default_bool = 73 [default = true ];
+ optional string default_string = 74 [default = "hello"];
+ optional bytes default_bytes = 75 [default = "world"];
+
+ optional NestedEnum default_nested_enum = 81 [default = BAR ];
+ optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR];
+ optional protobuf_unittest_import.ImportEnum
+ default_import_enum = 83 [default = IMPORT_BAR];
+
+ optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"];
+ optional string default_cord = 85 [ctype=CORD,default="123"];
+}
+
+message TestDeprecatedFields {
+ optional int32 deprecated_int32 = 1 [deprecated=true];
+}
+
+// Define these after TestAllTypes to make sure the compiler can handle
+// that.
+message ForeignMessage {
+ optional int32 c = 1;
+}
+
+enum ForeignEnum {
+ FOREIGN_FOO = 4;
+ FOREIGN_BAR = 5;
+ FOREIGN_BAZ = 6;
+}
+
+message TestAllExtensions {
+ extensions 1 to max;
+}
+
+extend TestAllExtensions {
+ // Singular
+ optional int32 optional_int32_extension = 1;
+ optional int64 optional_int64_extension = 2;
+ optional uint32 optional_uint32_extension = 3;
+ optional uint64 optional_uint64_extension = 4;
+ optional sint32 optional_sint32_extension = 5;
+ optional sint64 optional_sint64_extension = 6;
+ optional fixed32 optional_fixed32_extension = 7;
+ optional fixed64 optional_fixed64_extension = 8;
+ optional sfixed32 optional_sfixed32_extension = 9;
+ optional sfixed64 optional_sfixed64_extension = 10;
+ optional float optional_float_extension = 11;
+ optional double optional_double_extension = 12;
+ optional bool optional_bool_extension = 13;
+ optional string optional_string_extension = 14;
+ optional bytes optional_bytes_extension = 15;
+
+ optional group OptionalGroup_extension = 16 {
+ optional int32 a = 17;
+ }
+
+ optional TestAllTypes.NestedMessage optional_nested_message_extension = 18;
+ optional ForeignMessage optional_foreign_message_extension = 19;
+ optional protobuf_unittest_import.ImportMessage
+ optional_import_message_extension = 20;
+
+ optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21;
+ optional ForeignEnum optional_foreign_enum_extension = 22;
+ optional protobuf_unittest_import.ImportEnum
+ optional_import_enum_extension = 23;
+
+ optional string optional_string_piece_extension = 24 [ctype=STRING_PIECE];
+ optional string optional_cord_extension = 25 [ctype=CORD];
+
+ optional protobuf_unittest_import.PublicImportMessage
+ optional_public_import_message_extension = 26;
+
+ optional TestAllTypes.NestedMessage
+ optional_lazy_message_extension = 27 [lazy=true];
+
+ // Repeated
+ repeated int32 repeated_int32_extension = 31;
+ repeated int64 repeated_int64_extension = 32;
+ repeated uint32 repeated_uint32_extension = 33;
+ repeated uint64 repeated_uint64_extension = 34;
+ repeated sint32 repeated_sint32_extension = 35;
+ repeated sint64 repeated_sint64_extension = 36;
+ repeated fixed32 repeated_fixed32_extension = 37;
+ repeated fixed64 repeated_fixed64_extension = 38;
+ repeated sfixed32 repeated_sfixed32_extension = 39;
+ repeated sfixed64 repeated_sfixed64_extension = 40;
+ repeated float repeated_float_extension = 41;
+ repeated double repeated_double_extension = 42;
+ repeated bool repeated_bool_extension = 43;
+ repeated string repeated_string_extension = 44;
+ repeated bytes repeated_bytes_extension = 45;
+
+ repeated group RepeatedGroup_extension = 46 {
+ optional int32 a = 47;
+ }
+
+ repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48;
+ repeated ForeignMessage repeated_foreign_message_extension = 49;
+ repeated protobuf_unittest_import.ImportMessage
+ repeated_import_message_extension = 50;
+
+ repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51;
+ repeated ForeignEnum repeated_foreign_enum_extension = 52;
+ repeated protobuf_unittest_import.ImportEnum
+ repeated_import_enum_extension = 53;
+
+ repeated string repeated_string_piece_extension = 54 [ctype=STRING_PIECE];
+ repeated string repeated_cord_extension = 55 [ctype=CORD];
+
+ repeated TestAllTypes.NestedMessage
+ repeated_lazy_message_extension = 57 [lazy=true];
+
+ // Singular with defaults
+ optional int32 default_int32_extension = 61 [default = 41 ];
+ optional int64 default_int64_extension = 62 [default = 42 ];
+ optional uint32 default_uint32_extension = 63 [default = 43 ];
+ optional uint64 default_uint64_extension = 64 [default = 44 ];
+ optional sint32 default_sint32_extension = 65 [default = -45 ];
+ optional sint64 default_sint64_extension = 66 [default = 46 ];
+ optional fixed32 default_fixed32_extension = 67 [default = 47 ];
+ optional fixed64 default_fixed64_extension = 68 [default = 48 ];
+ optional sfixed32 default_sfixed32_extension = 69 [default = 49 ];
+ optional sfixed64 default_sfixed64_extension = 70 [default = -50 ];
+ optional float default_float_extension = 71 [default = 51.5 ];
+ optional double default_double_extension = 72 [default = 52e3 ];
+ optional bool default_bool_extension = 73 [default = true ];
+ optional string default_string_extension = 74 [default = "hello"];
+ optional bytes default_bytes_extension = 75 [default = "world"];
+
+ optional TestAllTypes.NestedEnum
+ default_nested_enum_extension = 81 [default = BAR];
+ optional ForeignEnum
+ default_foreign_enum_extension = 82 [default = FOREIGN_BAR];
+ optional protobuf_unittest_import.ImportEnum
+ default_import_enum_extension = 83 [default = IMPORT_BAR];
+
+ optional string default_string_piece_extension = 84 [ctype=STRING_PIECE,
+ default="abc"];
+ optional string default_cord_extension = 85 [ctype=CORD, default="123"];
+}
+
+message TestNestedExtension {
+ extend TestAllExtensions {
+ // Check for bug where string extensions declared in tested scope did not
+ // compile.
+ optional string test = 1002 [default="test"];
+ }
+}
+
+// We have separate messages for testing required fields because it's
+// annoying to have to fill in required fields in TestProto in order to
+// do anything with it. Note that we don't need to test every type of
+// required filed because the code output is basically identical to
+// optional fields for all types.
+message TestRequired {
+ required int32 a = 1;
+ optional int32 dummy2 = 2;
+ required int32 b = 3;
+
+ extend TestAllExtensions {
+ optional TestRequired single = 1000;
+ repeated TestRequired multi = 1001;
+ }
+
+ // Pad the field count to 32 so that we can test that IsInitialized()
+ // properly checks multiple elements of has_bits_.
+ optional int32 dummy4 = 4;
+ optional int32 dummy5 = 5;
+ optional int32 dummy6 = 6;
+ optional int32 dummy7 = 7;
+ optional int32 dummy8 = 8;
+ optional int32 dummy9 = 9;
+ optional int32 dummy10 = 10;
+ optional int32 dummy11 = 11;
+ optional int32 dummy12 = 12;
+ optional int32 dummy13 = 13;
+ optional int32 dummy14 = 14;
+ optional int32 dummy15 = 15;
+ optional int32 dummy16 = 16;
+ optional int32 dummy17 = 17;
+ optional int32 dummy18 = 18;
+ optional int32 dummy19 = 19;
+ optional int32 dummy20 = 20;
+ optional int32 dummy21 = 21;
+ optional int32 dummy22 = 22;
+ optional int32 dummy23 = 23;
+ optional int32 dummy24 = 24;
+ optional int32 dummy25 = 25;
+ optional int32 dummy26 = 26;
+ optional int32 dummy27 = 27;
+ optional int32 dummy28 = 28;
+ optional int32 dummy29 = 29;
+ optional int32 dummy30 = 30;
+ optional int32 dummy31 = 31;
+ optional int32 dummy32 = 32;
+
+ required int32 c = 33;
+}
+
+message TestRequiredForeign {
+ optional TestRequired optional_message = 1;
+ repeated TestRequired repeated_message = 2;
+ optional int32 dummy = 3;
+}
+
+// Test that we can use NestedMessage from outside TestAllTypes.
+message TestForeignNested {
+ optional TestAllTypes.NestedMessage foreign_nested = 1;
+}
+
+// TestEmptyMessage is used to test unknown field support.
+message TestEmptyMessage {
+}
+
+// Like above, but declare all field numbers as potential extensions. No
+// actual extensions should ever be defined for this type.
+message TestEmptyMessageWithExtensions {
+ extensions 1 to max;
+}
+
+message TestMultipleExtensionRanges {
+ extensions 42;
+ extensions 4143 to 4243;
+ extensions 65536 to max;
+}
+
+// Test that really large tag numbers don't break anything.
+message TestReallyLargeTagNumber {
+ // The largest possible tag number is 2^28 - 1, since the wire format uses
+ // three bits to communicate wire type.
+ optional int32 a = 1;
+ optional int32 bb = 268435455;
+}
+
+message TestRecursiveMessage {
+ optional TestRecursiveMessage a = 1;
+ optional int32 i = 2;
+}
+
+// Test that mutual recursion works.
+message TestMutualRecursionA {
+ optional TestMutualRecursionB bb = 1;
+}
+
+message TestMutualRecursionB {
+ optional TestMutualRecursionA a = 1;
+ optional int32 optional_int32 = 2;
+}
+
+// Test that groups have disjoint field numbers from their siblings and
+// parents. This is NOT possible in proto1; only proto2. When attempting
+// to compile with proto1, this will emit an error; so we only include it
+// in protobuf_unittest_proto.
+message TestDupFieldNumber { // NO_PROTO1
+ optional int32 a = 1; // NO_PROTO1
+ optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1
+ optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1
+} // NO_PROTO1
+
+// Additional messages for testing lazy fields.
+message TestEagerMessage {
+ optional TestAllTypes sub_message = 1 [lazy=false];
+}
+message TestLazyMessage {
+ optional TestAllTypes sub_message = 1 [lazy=true];
+}
+
+// Needed for a Python test.
+message TestNestedMessageHasBits {
+ message NestedMessage {
+ repeated int32 nestedmessage_repeated_int32 = 1;
+ repeated ForeignMessage nestedmessage_repeated_foreignmessage = 2;
+ }
+ optional NestedMessage optional_nested_message = 1;
+}
+
+
+// Test an enum that has multiple values with the same number.
+enum TestEnumWithDupValue {
+ option allow_alias = true;
+ FOO1 = 1;
+ BAR1 = 2;
+ BAZ = 3;
+ FOO2 = 1;
+ BAR2 = 2;
+}
+
+// Test an enum with large, unordered values.
+enum TestSparseEnum {
+ SPARSE_A = 123;
+ SPARSE_B = 62374;
+ SPARSE_C = 12589234;
+ SPARSE_D = -15;
+ SPARSE_E = -53452;
+ SPARSE_F = 0;
+ SPARSE_G = 2;
+}
+
+// Test message with CamelCase field names. This violates Protocol Buffer
+// standard style.
+message TestCamelCaseFieldNames {
+ optional int32 PrimitiveField = 1;
+ optional string StringField = 2;
+ optional ForeignEnum EnumField = 3;
+ optional ForeignMessage MessageField = 4;
+ optional string StringPieceField = 5 [ctype=STRING_PIECE];
+ optional string CordField = 6 [ctype=CORD];
+
+ repeated int32 RepeatedPrimitiveField = 7;
+ repeated string RepeatedStringField = 8;
+ repeated ForeignEnum RepeatedEnumField = 9;
+ repeated ForeignMessage RepeatedMessageField = 10;
+ repeated string RepeatedStringPieceField = 11 [ctype=STRING_PIECE];
+ repeated string RepeatedCordField = 12 [ctype=CORD];
+}
+
+
+// We list fields out of order, to ensure that we're using field number and not
+// field index to determine serialization order.
+message TestFieldOrderings {
+ optional string my_string = 11;
+ extensions 2 to 10;
+ optional int64 my_int = 1;
+ extensions 12 to 100;
+ optional float my_float = 101;
+}
+
+
+extend TestFieldOrderings {
+ optional string my_extension_string = 50;
+ optional int32 my_extension_int = 5;
+}
+
+
+message TestExtremeDefaultValues {
+ optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"];
+ optional uint32 large_uint32 = 2 [default = 0xFFFFFFFF];
+ optional uint64 large_uint64 = 3 [default = 0xFFFFFFFFFFFFFFFF];
+ optional int32 small_int32 = 4 [default = -0x7FFFFFFF];
+ optional int64 small_int64 = 5 [default = -0x7FFFFFFFFFFFFFFF];
+ optional int32 really_small_int32 = 21 [default = -0x80000000];
+ optional int64 really_small_int64 = 22 [default = -0x8000000000000000];
+
+ // The default value here is UTF-8 for "\u1234". (We could also just type
+ // the UTF-8 text directly into this text file rather than escape it, but
+ // lots of people use editors that would be confused by this.)
+ optional string utf8_string = 6 [default = "\341\210\264"];
+
+ // Tests for single-precision floating-point values.
+ optional float zero_float = 7 [default = 0];
+ optional float one_float = 8 [default = 1];
+ optional float small_float = 9 [default = 1.5];
+ optional float negative_one_float = 10 [default = -1];
+ optional float negative_float = 11 [default = -1.5];
+ // Using exponents
+ optional float large_float = 12 [default = 2E8];
+ optional float small_negative_float = 13 [default = -8e-28];
+
+ // Text for nonfinite floating-point values.
+ optional double inf_double = 14 [default = inf];
+ optional double neg_inf_double = 15 [default = -inf];
+ optional double nan_double = 16 [default = nan];
+ optional float inf_float = 17 [default = inf];
+ optional float neg_inf_float = 18 [default = -inf];
+ optional float nan_float = 19 [default = nan];
+
+ // Tests for C++ trigraphs.
+ // Trigraphs should be escaped in C++ generated files, but they should not be
+ // escaped for other languages.
+ // Note that in .proto file, "\?" is a valid way to escape ? in string
+ // literals.
+ optional string cpp_trigraph = 20 [default = "? \? ?? \?? \??? ??/ ?\?-"];
+
+ // String defaults containing the character '\000'
+ optional string string_with_zero = 23 [default = "hel\000lo"];
+ optional bytes bytes_with_zero = 24 [default = "wor\000ld"];
+ optional string string_piece_with_zero = 25 [ctype=STRING_PIECE,
+ default="ab\000c"];
+ optional string cord_with_zero = 26 [ctype=CORD,
+ default="12\0003"];
+}
+
+message SparseEnumMessage {
+ optional TestSparseEnum sparse_enum = 1;
+}
+
+// Test String and Bytes: string is for valid UTF-8 strings
+message OneString {
+ optional string data = 1;
+}
+
+message MoreString {
+ repeated string data = 1;
+}
+
+message OneBytes {
+ optional bytes data = 1;
+}
+
+message MoreBytes {
+ repeated bytes data = 1;
+}
+
+
+// Test messages for packed fields
+
+message TestPackedTypes {
+ repeated int32 packed_int32 = 90 [packed = true];
+ repeated int64 packed_int64 = 91 [packed = true];
+ repeated uint32 packed_uint32 = 92 [packed = true];
+ repeated uint64 packed_uint64 = 93 [packed = true];
+ repeated sint32 packed_sint32 = 94 [packed = true];
+ repeated sint64 packed_sint64 = 95 [packed = true];
+ repeated fixed32 packed_fixed32 = 96 [packed = true];
+ repeated fixed64 packed_fixed64 = 97 [packed = true];
+ repeated sfixed32 packed_sfixed32 = 98 [packed = true];
+ repeated sfixed64 packed_sfixed64 = 99 [packed = true];
+ repeated float packed_float = 100 [packed = true];
+ repeated double packed_double = 101 [packed = true];
+ repeated bool packed_bool = 102 [packed = true];
+ repeated ForeignEnum packed_enum = 103 [packed = true];
+}
+
+// A message with the same fields as TestPackedTypes, but without packing. Used
+// to test packed <-> unpacked wire compatibility.
+message TestUnpackedTypes {
+ repeated int32 unpacked_int32 = 90 [packed = false];
+ repeated int64 unpacked_int64 = 91 [packed = false];
+ repeated uint32 unpacked_uint32 = 92 [packed = false];
+ repeated uint64 unpacked_uint64 = 93 [packed = false];
+ repeated sint32 unpacked_sint32 = 94 [packed = false];
+ repeated sint64 unpacked_sint64 = 95 [packed = false];
+ repeated fixed32 unpacked_fixed32 = 96 [packed = false];
+ repeated fixed64 unpacked_fixed64 = 97 [packed = false];
+ repeated sfixed32 unpacked_sfixed32 = 98 [packed = false];
+ repeated sfixed64 unpacked_sfixed64 = 99 [packed = false];
+ repeated float unpacked_float = 100 [packed = false];
+ repeated double unpacked_double = 101 [packed = false];
+ repeated bool unpacked_bool = 102 [packed = false];
+ repeated ForeignEnum unpacked_enum = 103 [packed = false];
+}
+
+message TestPackedExtensions {
+ extensions 1 to max;
+}
+
+extend TestPackedExtensions {
+ repeated int32 packed_int32_extension = 90 [packed = true];
+ repeated int64 packed_int64_extension = 91 [packed = true];
+ repeated uint32 packed_uint32_extension = 92 [packed = true];
+ repeated uint64 packed_uint64_extension = 93 [packed = true];
+ repeated sint32 packed_sint32_extension = 94 [packed = true];
+ repeated sint64 packed_sint64_extension = 95 [packed = true];
+ repeated fixed32 packed_fixed32_extension = 96 [packed = true];
+ repeated fixed64 packed_fixed64_extension = 97 [packed = true];
+ repeated sfixed32 packed_sfixed32_extension = 98 [packed = true];
+ repeated sfixed64 packed_sfixed64_extension = 99 [packed = true];
+ repeated float packed_float_extension = 100 [packed = true];
+ repeated double packed_double_extension = 101 [packed = true];
+ repeated bool packed_bool_extension = 102 [packed = true];
+ repeated ForeignEnum packed_enum_extension = 103 [packed = true];
+}
+
+// Used by ExtensionSetTest/DynamicExtensions. The test actually builds
+// a set of extensions to TestAllExtensions dynamically, based on the fields
+// of this message type.
+message TestDynamicExtensions {
+ enum DynamicEnumType {
+ DYNAMIC_FOO = 2200;
+ DYNAMIC_BAR = 2201;
+ DYNAMIC_BAZ = 2202;
+ }
+ message DynamicMessageType {
+ optional int32 dynamic_field = 2100;
+ }
+
+ optional fixed32 scalar_extension = 2000;
+ optional ForeignEnum enum_extension = 2001;
+ optional DynamicEnumType dynamic_enum_extension = 2002;
+
+ optional ForeignMessage message_extension = 2003;
+ optional DynamicMessageType dynamic_message_extension = 2004;
+
+ repeated string repeated_extension = 2005;
+ repeated sint32 packed_extension = 2006 [packed = true];
+}
+
+message TestRepeatedScalarDifferentTagSizes {
+ // Parsing repeated fixed size values used to fail. This message needs to be
+ // used in order to get a tag of the right size; all of the repeated fields
+ // in TestAllTypes didn't trigger the check.
+ repeated fixed32 repeated_fixed32 = 12;
+ // Check for a varint type, just for good measure.
+ repeated int32 repeated_int32 = 13;
+
+ // These have two-byte tags.
+ repeated fixed64 repeated_fixed64 = 2046;
+ repeated int64 repeated_int64 = 2047;
+
+ // Three byte tags.
+ repeated float repeated_float = 262142;
+ repeated uint64 repeated_uint64 = 262143;
+}
+
+// Test that if an optional or required message/group field appears multiple
+// times in the input, they need to be merged.
+message TestParsingMerge {
+ // RepeatedFieldsGenerator defines matching field types as TestParsingMerge,
+ // except that all fields are repeated. In the tests, we will serialize the
+ // RepeatedFieldsGenerator to bytes, and parse the bytes to TestParsingMerge.
+ // Repeated fields in RepeatedFieldsGenerator are expected to be merged into
+ // the corresponding required/optional fields in TestParsingMerge.
+ message RepeatedFieldsGenerator {
+ repeated TestAllTypes field1 = 1;
+ repeated TestAllTypes field2 = 2;
+ repeated TestAllTypes field3 = 3;
+ repeated group Group1 = 10 {
+ optional TestAllTypes field1 = 11;
+ }
+ repeated group Group2 = 20 {
+ optional TestAllTypes field1 = 21;
+ }
+ repeated TestAllTypes ext1 = 1000;
+ repeated TestAllTypes ext2 = 1001;
+ }
+ required TestAllTypes required_all_types = 1;
+ optional TestAllTypes optional_all_types = 2;
+ repeated TestAllTypes repeated_all_types = 3;
+ optional group OptionalGroup = 10 {
+ optional TestAllTypes optional_group_all_types = 11;
+ }
+ repeated group RepeatedGroup = 20 {
+ optional TestAllTypes repeated_group_all_types = 21;
+ }
+ extensions 1000 to max;
+ extend TestParsingMerge {
+ optional TestAllTypes optional_ext = 1000;
+ repeated TestAllTypes repeated_ext = 1001;
+ }
+}
+
+message TestCommentInjectionMessage {
+ // */ <- This should not close the generated doc comment
+ optional string a = 1 [default="*/ <- Neither should this."];
+}
+
+
+// Test that RPC services work.
+message FooRequest {}
+message FooResponse {}
+
+message FooClientMessage {}
+message FooServerMessage{}
+
+service TestService {
+ rpc Foo(FooRequest) returns (FooResponse);
+ rpc Bar(BarRequest) returns (BarResponse);
+}
+
+
+message BarRequest {}
+message BarResponse {}
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_custom_options.proto b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_custom_options.proto
new file mode 100644
index 0000000000..e591d29447
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_custom_options.proto
@@ -0,0 +1,387 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: benjy@google.com (Benjy Weinberger)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file used to test the "custom options" feature of proto2.
+
+
+// Some generic_services option(s) added automatically.
+// See: http://go/proto2-generic-services-default
+option cc_generic_services = true; // auto-added
+option java_generic_services = true; // auto-added
+option py_generic_services = true;
+
+// A custom file option (defined below).
+option (file_opt1) = 9876543210;
+
+import "google/protobuf/descriptor.proto";
+
+// We don't put this in a package within proto2 because we need to make sure
+// that the generated code doesn't depend on being in the proto2 namespace.
+package protobuf_unittest;
+
+
+// Some simple test custom options of various types.
+
+extend google.protobuf.FileOptions {
+ optional uint64 file_opt1 = 7736974;
+}
+
+extend google.protobuf.MessageOptions {
+ optional int32 message_opt1 = 7739036;
+}
+
+extend google.protobuf.FieldOptions {
+ optional fixed64 field_opt1 = 7740936;
+ // This is useful for testing that we correctly register default values for
+ // extension options.
+ optional int32 field_opt2 = 7753913 [default=42];
+}
+
+extend google.protobuf.EnumOptions {
+ optional sfixed32 enum_opt1 = 7753576;
+}
+
+extend google.protobuf.EnumValueOptions {
+ optional int32 enum_value_opt1 = 1560678;
+}
+
+extend google.protobuf.ServiceOptions {
+ optional sint64 service_opt1 = 7887650;
+}
+
+enum MethodOpt1 {
+ METHODOPT1_VAL1 = 1;
+ METHODOPT1_VAL2 = 2;
+}
+
+extend google.protobuf.MethodOptions {
+ optional MethodOpt1 method_opt1 = 7890860;
+}
+
+// A test message with custom options at all possible locations (and also some
+// regular options, to make sure they interact nicely).
+message TestMessageWithCustomOptions {
+ option message_set_wire_format = false;
+
+ option (message_opt1) = -56;
+
+ optional string field1 = 1 [ctype=CORD,
+ (field_opt1)=8765432109];
+
+ enum AnEnum {
+ option (enum_opt1) = -789;
+
+ ANENUM_VAL1 = 1;
+ ANENUM_VAL2 = 2 [(enum_value_opt1) = 123];
+ }
+}
+
+
+// A test RPC service with custom options at all possible locations (and also
+// some regular options, to make sure they interact nicely).
+message CustomOptionFooRequest {
+}
+
+message CustomOptionFooResponse {
+}
+
+message CustomOptionFooClientMessage {
+}
+
+message CustomOptionFooServerMessage {
+}
+
+service TestServiceWithCustomOptions {
+ option (service_opt1) = -9876543210;
+
+ rpc Foo(CustomOptionFooRequest) returns (CustomOptionFooResponse) {
+ option (method_opt1) = METHODOPT1_VAL2;
+ }
+}
+
+
+
+// Options of every possible field type, so we can test them all exhaustively.
+
+message DummyMessageContainingEnum {
+ enum TestEnumType {
+ TEST_OPTION_ENUM_TYPE1 = 22;
+ TEST_OPTION_ENUM_TYPE2 = -23;
+ }
+}
+
+message DummyMessageInvalidAsOptionType {
+}
+
+extend google.protobuf.MessageOptions {
+ optional bool bool_opt = 7706090;
+ optional int32 int32_opt = 7705709;
+ optional int64 int64_opt = 7705542;
+ optional uint32 uint32_opt = 7704880;
+ optional uint64 uint64_opt = 7702367;
+ optional sint32 sint32_opt = 7701568;
+ optional sint64 sint64_opt = 7700863;
+ optional fixed32 fixed32_opt = 7700307;
+ optional fixed64 fixed64_opt = 7700194;
+ optional sfixed32 sfixed32_opt = 7698645;
+ optional sfixed64 sfixed64_opt = 7685475;
+ optional float float_opt = 7675390;
+ optional double double_opt = 7673293;
+ optional string string_opt = 7673285;
+ optional bytes bytes_opt = 7673238;
+ optional DummyMessageContainingEnum.TestEnumType enum_opt = 7673233;
+ optional DummyMessageInvalidAsOptionType message_type_opt = 7665967;
+}
+
+message CustomOptionMinIntegerValues {
+ option (bool_opt) = false;
+ option (int32_opt) = -0x80000000;
+ option (int64_opt) = -0x8000000000000000;
+ option (uint32_opt) = 0;
+ option (uint64_opt) = 0;
+ option (sint32_opt) = -0x80000000;
+ option (sint64_opt) = -0x8000000000000000;
+ option (fixed32_opt) = 0;
+ option (fixed64_opt) = 0;
+ option (sfixed32_opt) = -0x80000000;
+ option (sfixed64_opt) = -0x8000000000000000;
+}
+
+message CustomOptionMaxIntegerValues {
+ option (bool_opt) = true;
+ option (int32_opt) = 0x7FFFFFFF;
+ option (int64_opt) = 0x7FFFFFFFFFFFFFFF;
+ option (uint32_opt) = 0xFFFFFFFF;
+ option (uint64_opt) = 0xFFFFFFFFFFFFFFFF;
+ option (sint32_opt) = 0x7FFFFFFF;
+ option (sint64_opt) = 0x7FFFFFFFFFFFFFFF;
+ option (fixed32_opt) = 0xFFFFFFFF;
+ option (fixed64_opt) = 0xFFFFFFFFFFFFFFFF;
+ option (sfixed32_opt) = 0x7FFFFFFF;
+ option (sfixed64_opt) = 0x7FFFFFFFFFFFFFFF;
+}
+
+message CustomOptionOtherValues {
+ option (int32_opt) = -100; // To test sign-extension.
+ option (float_opt) = 12.3456789;
+ option (double_opt) = 1.234567890123456789;
+ option (string_opt) = "Hello, \"World\"";
+ option (bytes_opt) = "Hello\0World";
+ option (enum_opt) = TEST_OPTION_ENUM_TYPE2;
+}
+
+message SettingRealsFromPositiveInts {
+ option (float_opt) = 12;
+ option (double_opt) = 154;
+}
+
+message SettingRealsFromNegativeInts {
+ option (float_opt) = -12;
+ option (double_opt) = -154;
+}
+
+// Options of complex message types, themselves combined and extended in
+// various ways.
+
+message ComplexOptionType1 {
+ optional int32 foo = 1;
+ optional int32 foo2 = 2;
+ optional int32 foo3 = 3;
+
+ extensions 100 to max;
+}
+
+message ComplexOptionType2 {
+ optional ComplexOptionType1 bar = 1;
+ optional int32 baz = 2;
+
+ message ComplexOptionType4 {
+ optional int32 waldo = 1;
+
+ extend google.protobuf.MessageOptions {
+ optional ComplexOptionType4 complex_opt4 = 7633546;
+ }
+ }
+
+ optional ComplexOptionType4 fred = 3;
+
+ extensions 100 to max;
+}
+
+message ComplexOptionType3 {
+ optional int32 qux = 1;
+
+ optional group ComplexOptionType5 = 2 {
+ optional int32 plugh = 3;
+ }
+}
+
+extend ComplexOptionType1 {
+ optional int32 quux = 7663707;
+ optional ComplexOptionType3 corge = 7663442;
+}
+
+extend ComplexOptionType2 {
+ optional int32 grault = 7650927;
+ optional ComplexOptionType1 garply = 7649992;
+}
+
+extend google.protobuf.MessageOptions {
+ optional protobuf_unittest.ComplexOptionType1 complex_opt1 = 7646756;
+ optional ComplexOptionType2 complex_opt2 = 7636949;
+ optional ComplexOptionType3 complex_opt3 = 7636463;
+ optional group ComplexOpt6 = 7595468 {
+ optional int32 xyzzy = 7593951;
+ }
+}
+
+// Note that we try various different ways of naming the same extension.
+message VariousComplexOptions {
+ option (.protobuf_unittest.complex_opt1).foo = 42;
+ option (protobuf_unittest.complex_opt1).(.protobuf_unittest.quux) = 324;
+ option (.protobuf_unittest.complex_opt1).(protobuf_unittest.corge).qux = 876;
+ option (complex_opt2).baz = 987;
+ option (complex_opt2).(grault) = 654;
+ option (complex_opt2).bar.foo = 743;
+ option (complex_opt2).bar.(quux) = 1999;
+ option (complex_opt2).bar.(protobuf_unittest.corge).qux = 2008;
+ option (complex_opt2).(garply).foo = 741;
+ option (complex_opt2).(garply).(.protobuf_unittest.quux) = 1998;
+ option (complex_opt2).(protobuf_unittest.garply).(corge).qux = 2121;
+ option (ComplexOptionType2.ComplexOptionType4.complex_opt4).waldo = 1971;
+ option (complex_opt2).fred.waldo = 321;
+ option (protobuf_unittest.complex_opt3).qux = 9;
+ option (complex_opt3).complexoptiontype5.plugh = 22;
+ option (complexopt6).xyzzy = 24;
+}
+
+// ------------------------------------------------------
+// Definitions for testing aggregate option parsing.
+// See descriptor_unittest.cc.
+
+message AggregateMessageSet {
+ option message_set_wire_format = true;
+ extensions 4 to max;
+}
+
+message AggregateMessageSetElement {
+ extend AggregateMessageSet {
+ optional AggregateMessageSetElement message_set_extension = 15447542;
+ }
+ optional string s = 1;
+}
+
+// A helper type used to test aggregate option parsing
+message Aggregate {
+ optional int32 i = 1;
+ optional string s = 2;
+
+ // A nested object
+ optional Aggregate sub = 3;
+
+ // To test the parsing of extensions inside aggregate values
+ optional google.protobuf.FileOptions file = 4;
+ extend google.protobuf.FileOptions {
+ optional Aggregate nested = 15476903;
+ }
+
+ // An embedded message set
+ optional AggregateMessageSet mset = 5;
+}
+
+// Allow Aggregate to be used as an option at all possible locations
+// in the .proto grammer.
+extend google.protobuf.FileOptions { optional Aggregate fileopt = 15478479; }
+extend google.protobuf.MessageOptions { optional Aggregate msgopt = 15480088; }
+extend google.protobuf.FieldOptions { optional Aggregate fieldopt = 15481374; }
+extend google.protobuf.EnumOptions { optional Aggregate enumopt = 15483218; }
+extend google.protobuf.EnumValueOptions { optional Aggregate enumvalopt = 15486921; }
+extend google.protobuf.ServiceOptions { optional Aggregate serviceopt = 15497145; }
+extend google.protobuf.MethodOptions { optional Aggregate methodopt = 15512713; }
+
+// Try using AggregateOption at different points in the proto grammar
+option (fileopt) = {
+ s: 'FileAnnotation'
+ // Also test the handling of comments
+ /* of both types */ i: 100
+
+ sub { s: 'NestedFileAnnotation' }
+
+ // Include a google.protobuf.FileOptions and recursively extend it with
+ // another fileopt.
+ file {
+ [protobuf_unittest.fileopt] {
+ s:'FileExtensionAnnotation'
+ }
+ }
+
+ // A message set inside an option value
+ mset {
+ [protobuf_unittest.AggregateMessageSetElement.message_set_extension] {
+ s: 'EmbeddedMessageSetElement'
+ }
+ }
+};
+
+message AggregateMessage {
+ option (msgopt) = { i:101 s:'MessageAnnotation' };
+ optional int32 fieldname = 1 [(fieldopt) = { s:'FieldAnnotation' }];
+}
+
+service AggregateService {
+ option (serviceopt) = { s:'ServiceAnnotation' };
+ rpc Method (AggregateMessage) returns (AggregateMessage) {
+ option (methodopt) = { s:'MethodAnnotation' };
+ }
+}
+
+enum AggregateEnum {
+ option (enumopt) = { s:'EnumAnnotation' };
+ VALUE = 1 [(enumvalopt) = { s:'EnumValueAnnotation' }];
+}
+
+// Test custom options for nested type.
+message NestedOptionType {
+ message NestedMessage {
+ option (message_opt1) = 1001;
+ optional int32 nested_field = 1 [(field_opt1) = 1002];
+ }
+ enum NestedEnum {
+ option (enum_opt1) = 1003;
+ NESTED_ENUM_VALUE = 1 [(enum_value_opt1) = 1004];
+ }
+ extend google.protobuf.FileOptions {
+ optional int32 nested_extension = 7912573 [(field_opt2) = 1005];
+ }
+}
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import.proto b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import.proto
new file mode 100644
index 0000000000..c115b11171
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import.proto
@@ -0,0 +1,64 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file which is imported by unittest.proto to test importing.
+
+
+// We don't put this in a package within proto2 because we need to make sure
+// that the generated code doesn't depend on being in the proto2 namespace.
+// In test_util.h we do
+// "using namespace unittest_import = protobuf_unittest_import".
+package protobuf_unittest_import;
+
+option optimize_for = SPEED;
+
+// Excercise the java_package option.
+option java_package = "com.google.protobuf.test";
+
+// Do not set a java_outer_classname here to verify that Proto2 works without
+// one.
+
+// Test public import
+import public "google/protobuf/unittest_import_public.proto";
+
+message ImportMessage {
+ optional int32 d = 1;
+}
+
+enum ImportEnum {
+ IMPORT_FOO = 7;
+ IMPORT_BAR = 8;
+ IMPORT_BAZ = 9;
+}
+
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import_public.proto b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import_public.proto
new file mode 100644
index 0000000000..ea5d1b13fe
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_import_public.proto
@@ -0,0 +1,40 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: liujisi@google.com (Pherl Liu)
+
+
+package protobuf_unittest_import;
+
+option java_package = "com.google.protobuf.test";
+
+message PublicImportMessage {
+ optional int32 e = 1;
+}
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_mset.proto b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_mset.proto
new file mode 100644
index 0000000000..3497f09fa6
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_mset.proto
@@ -0,0 +1,72 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// This file contains messages for testing message_set_wire_format.
+
+package protobuf_unittest;
+
+option optimize_for = SPEED;
+
+// A message with message_set_wire_format.
+message TestMessageSet {
+ option message_set_wire_format = true;
+ extensions 4 to max;
+}
+
+message TestMessageSetContainer {
+ optional TestMessageSet message_set = 1;
+}
+
+message TestMessageSetExtension1 {
+ extend TestMessageSet {
+ optional TestMessageSetExtension1 message_set_extension = 1545008;
+ }
+ optional int32 i = 15;
+}
+
+message TestMessageSetExtension2 {
+ extend TestMessageSet {
+ optional TestMessageSetExtension2 message_set_extension = 1547769;
+ }
+ optional string str = 25;
+}
+
+// MessageSet wire format is equivalent to this.
+message RawMessageSet {
+ repeated group Item = 1 {
+ required int32 type_id = 2;
+ required bytes message = 3;
+ }
+}
+
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_no_generic_services.proto b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_no_generic_services.proto
new file mode 100644
index 0000000000..cffb4122c5
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/protos/src/proto/google/protobuf/unittest_no_generic_services.proto
@@ -0,0 +1,52 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+
+package google.protobuf.no_generic_services_test;
+
+// *_generic_services are false by default.
+
+message TestMessage {
+ optional int32 a = 1;
+ extensions 1000 to max;
+}
+
+enum TestEnum {
+ FOO = 1;
+}
+
+extend TestMessage {
+ optional int32 test_extension = 1000;
+}
+
+service TestService {
+ rpc Foo(TestMessage) returns(TestMessage);
+}
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/setup.py b/third_party/protobuf/python/compatibility_tests/v2.5.0/setup.py
new file mode 100755
index 0000000000..b41d54d4fe
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/setup.py
@@ -0,0 +1,87 @@
+#! /usr/bin/env python
+#
+import glob
+import os
+import subprocess
+import sys
+
+from setuptools import setup, Extension, find_packages
+
+if sys.version_info[0] == 3:
+ # Python 3
+ from distutils.command.build_py import build_py_2to3 as _build_py
+else:
+ # Python 2
+ from distutils.command.build_py import build_py as _build_py
+from distutils.spawn import find_executable
+
+def generate_proto(source, code_gen):
+ """Invokes the Protocol Compiler to generate a _pb2.py from the given
+ .proto file."""
+ output = source.replace(".proto", "_pb2.py").replace("protos/src/proto/", "").replace("protos/python/", "")
+
+ if not os.path.exists(source):
+ sys.stderr.write("Can't find required file: %s\n" % source)
+ sys.exit(-1)
+
+ protoc_command = [ code_gen, "-Iprotos/src/proto", "-Iprotos/python", "--python_out=.", source ]
+ if subprocess.call(protoc_command) != 0:
+ sys.exit(-1)
+
+class build_py(_build_py):
+ def run(self):
+ # generate .proto file
+ protoc_1 = "./protoc_1"
+ protoc_2 = "./protoc_2"
+ generate_proto("protos/src/proto/google/protobuf/unittest.proto", protoc_2)
+ generate_proto("protos/src/proto/google/protobuf/unittest_custom_options.proto", protoc_1)
+ generate_proto("protos/src/proto/google/protobuf/unittest_import.proto", protoc_1)
+ generate_proto("protos/src/proto/google/protobuf/unittest_import_public.proto", protoc_1)
+ generate_proto("protos/src/proto/google/protobuf/unittest_mset.proto", protoc_1)
+ generate_proto("protos/src/proto/google/protobuf/unittest_no_generic_services.proto", protoc_1)
+ generate_proto("protos/python/google/protobuf/internal/factory_test1.proto", protoc_1)
+ generate_proto("protos/python/google/protobuf/internal/factory_test2.proto", protoc_1)
+ generate_proto("protos/python/google/protobuf/internal/more_extensions.proto", protoc_1)
+ generate_proto("protos/python/google/protobuf/internal/more_extensions_dynamic.proto", protoc_1)
+ generate_proto("protos/python/google/protobuf/internal/more_messages.proto", protoc_1)
+ generate_proto("protos/python/google/protobuf/internal/test_bad_identifiers.proto", protoc_1)
+
+ # _build_py is an old-style class, so super() doesn't work.
+ _build_py.run(self)
+
+if __name__ == '__main__':
+ # Keep this list of dependencies in sync with tox.ini.
+ install_requires = ['six>=1.9', 'setuptools']
+ if sys.version_info <= (2,7):
+ install_requires.append('ordereddict')
+ install_requires.append('unittest2')
+
+ setup(
+ name='protobuf',
+ description='Protocol Buffers',
+ download_url='https://github.com/google/protobuf/releases',
+ long_description="Protocol Buffers are Google's data interchange format",
+ url='https://developers.google.com/protocol-buffers/',
+ maintainer='protobuf@googlegroups.com',
+ maintainer_email='protobuf@googlegroups.com',
+ license='3-Clause BSD License',
+ classifiers=[
+ "Programming Language :: Python",
+ "Programming Language :: Python :: 2",
+ "Programming Language :: Python :: 2.6",
+ "Programming Language :: Python :: 2.7",
+ "Programming Language :: Python :: 3",
+ "Programming Language :: Python :: 3.3",
+ "Programming Language :: Python :: 3.4",
+ ],
+ packages=find_packages(
+ exclude=[
+ 'import_test_package',
+ ],
+ ),
+ test_suite='tests.google.protobuf.internal',
+ cmdclass={
+ 'build_py': build_py,
+ },
+ install_requires=install_requires,
+ )
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/test.sh b/third_party/protobuf/python/compatibility_tests/v2.5.0/test.sh
new file mode 100755
index 0000000000..78c16ad1ca
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/test.sh
@@ -0,0 +1,104 @@
+#!/bin/bash
+
+set -ex
+
+# Change to the script's directory.
+cd $(dirname $0)
+
+# Version of the tests (i.e., the version of protobuf from where we extracted
+# these tests).
+TEST_VERSION=2.5.0
+
+# The old version of protobuf that we are testing compatibility against. This
+# is usually the same as TEST_VERSION (i.e., we use the tests extracted from
+# that version to test compatibility of the newest runtime against it), but it
+# is also possible to use this same test set to test the compatibiilty of the
+# latest version against other versions.
+case "$1" in
+ ""|2.5.0)
+ OLD_VERSION=2.5.0
+ OLD_VERSION_PROTOC=https://github.com/xfxyjwf/protobuf-compiler-release/raw/master/v2.5.0/linux/protoc
+ ;;
+ 2.6.1)
+ OLD_VERSION=2.6.1
+ OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/2.6.1-build2/protoc-2.6.1-build2-linux-x86_64.exe
+ ;;
+ 3.0.0-beta-1)
+ OLD_VERSION=3.0.0-beta-1
+ OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-1/protoc-3.0.0-beta-1-linux-x86_64.exe
+ ;;
+ 3.0.0-beta-2)
+ OLD_VERSION=3.0.0-beta-2
+ OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-2/protoc-3.0.0-beta-2-linux-x86_64.exe
+ ;;
+ 3.0.0-beta-3)
+ OLD_VERSION=3.0.0-beta-3
+ OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-3/protoc-3.0.0-beta-3-linux-x86_64.exe
+ ;;
+ 3.0.0-beta-4)
+ OLD_VERSION=3.0.0-beta-4
+ OLD_VERSION_PROTOC=http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0-beta-4/protoc-3.0.0-beta-4-linux-x86_64.exe
+ ;;
+ *)
+ echo "[ERROR]: Unknown version number: $1"
+ exit 1
+ ;;
+esac
+
+# Extract the latest protobuf version number.
+VERSION_NUMBER=`grep "^__version__ = '.*'" ../../google/protobuf/__init__.py | sed "s|__version__ = '\(.*\)'|\1|"`
+
+echo "Running compatibility tests between $VERSION_NUMBER and $OLD_VERSION"
+
+# Check protoc
+[ -f ../../../src/protoc ] || {
+ echo "[ERROR]: Please build protoc first."
+ exit 1
+}
+
+# Test source compatibility. In these tests we recompile everything against
+# the new runtime (including old version generated code).
+rm google -f -r
+mkdir -p google/protobuf/internal
+# Build and copy the new runtime
+cd ../../
+python setup.py build
+cp google/protobuf/*.py compatibility_tests/v2.5.0/google/protobuf/
+cp google/protobuf/internal/*.py compatibility_tests/v2.5.0/google/protobuf/internal/
+cd compatibility_tests/v2.5.0
+cp tests/google/protobuf/internal/test_util.py google/protobuf/internal/
+cp google/protobuf/__init__.py google/
+
+# Download old version protoc compiler (for linux)
+wget $OLD_VERSION_PROTOC -O old_protoc
+chmod +x old_protoc
+
+# Test A.1:
+# proto set 1: use old version
+# proto set 2 which may import protos in set 1: use old version
+cp old_protoc protoc_1
+cp old_protoc protoc_2
+python setup.py build
+python setup.py test
+
+# Test A.2:
+# proto set 1: use new version
+# proto set 2 which may import protos in set 1: use old version
+cp ../../../src/protoc protoc_1
+cp old_protoc protoc_2
+python setup.py build
+python setup.py test
+
+# Test A.3:
+# proto set 1: use old version
+# proto set 2 which may import protos in set 1: use new version
+cp old_protoc protoc_1
+cp ../../../src/protoc protoc_2
+python setup.py build
+python setup.py test
+
+rm google -r -f
+rm build -r -f
+rm protoc_1
+rm protoc_2
+rm old_protoc
diff --git a/third_party/protobuf/3.0.0/python/google/__init__.py b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/__init__.py
index 5585614122..5585614122 100755..100644
--- a/third_party/protobuf/3.0.0/python/google/__init__.py
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/__init__.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/__init__.py b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/__init__.py
index 5585614122..5585614122 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/__init__.py
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/__init__.py
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/__init__.py b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/__init__.py
new file mode 100644
index 0000000000..5585614122
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/__init__.py
@@ -0,0 +1,4 @@
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ __path__ = __import__('pkgutil').extend_path(__path__, __name__)
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/__init__.py b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/__init__.py
new file mode 100644
index 0000000000..64c6956f8f
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/__init__.py
@@ -0,0 +1,37 @@
+# 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.
+
+# Copyright 2007 Google Inc. All Rights Reserved.
+
+if __name__ != '__main__':
+ try:
+ __import__('pkg_resources').declare_namespace(__name__)
+ except ImportError:
+ __path__ = __import__('pkgutil').extend_path(__path__, __name__)
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/descriptor_test.py b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/descriptor_test.py
new file mode 100755
index 0000000000..c74f882e78
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/descriptor_test.py
@@ -0,0 +1,613 @@
+#! /usr/bin/python
+#
+# Protocol Buffers - Google's data interchange format
+# Copyright 2008 Google Inc. All rights reserved.
+# http://code.google.com/p/protobuf/
+#
+# 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.
+
+"""Unittest for google.protobuf.internal.descriptor."""
+
+__author__ = 'robinson@google.com (Will Robinson)'
+
+import unittest
+from google.protobuf import unittest_custom_options_pb2
+from google.protobuf import unittest_import_pb2
+from google.protobuf import unittest_pb2
+from google.protobuf import descriptor_pb2
+from google.protobuf import descriptor
+from google.protobuf import text_format
+
+
+TEST_EMPTY_MESSAGE_DESCRIPTOR_ASCII = """
+name: 'TestEmptyMessage'
+"""
+
+
+class DescriptorTest(unittest.TestCase):
+
+ def setUp(self):
+ self.my_file = descriptor.FileDescriptor(
+ name='some/filename/some.proto',
+ package='protobuf_unittest'
+ )
+ self.my_enum = descriptor.EnumDescriptor(
+ name='ForeignEnum',
+ full_name='protobuf_unittest.ForeignEnum',
+ filename=None,
+ file=self.my_file,
+ values=[
+ descriptor.EnumValueDescriptor(name='FOREIGN_FOO', index=0, number=4),
+ descriptor.EnumValueDescriptor(name='FOREIGN_BAR', index=1, number=5),
+ descriptor.EnumValueDescriptor(name='FOREIGN_BAZ', index=2, number=6),
+ ])
+ self.my_message = descriptor.Descriptor(
+ name='NestedMessage',
+ full_name='protobuf_unittest.TestAllTypes.NestedMessage',
+ filename=None,
+ file=self.my_file,
+ containing_type=None,
+ fields=[
+ descriptor.FieldDescriptor(
+ name='bb',
+ full_name='protobuf_unittest.TestAllTypes.NestedMessage.bb',
+ index=0, number=1,
+ type=5, cpp_type=1, label=1,
+ has_default_value=False, default_value=0,
+ message_type=None, enum_type=None, containing_type=None,
+ is_extension=False, extension_scope=None),
+ ],
+ nested_types=[],
+ enum_types=[
+ self.my_enum,
+ ],
+ extensions=[])
+ self.my_method = descriptor.MethodDescriptor(
+ name='Bar',
+ full_name='protobuf_unittest.TestService.Bar',
+ index=0,
+ containing_service=None,
+ input_type=None,
+ output_type=None)
+ self.my_service = descriptor.ServiceDescriptor(
+ name='TestServiceWithOptions',
+ full_name='protobuf_unittest.TestServiceWithOptions',
+ file=self.my_file,
+ index=0,
+ methods=[
+ self.my_method
+ ])
+
+ def testEnumValueName(self):
+ self.assertEqual(self.my_message.EnumValueName('ForeignEnum', 4),
+ 'FOREIGN_FOO')
+
+ self.assertEqual(
+ self.my_message.enum_types_by_name[
+ 'ForeignEnum'].values_by_number[4].name,
+ self.my_message.EnumValueName('ForeignEnum', 4))
+
+ def testEnumFixups(self):
+ self.assertEqual(self.my_enum, self.my_enum.values[0].type)
+
+ def testContainingTypeFixups(self):
+ self.assertEqual(self.my_message, self.my_message.fields[0].containing_type)
+ self.assertEqual(self.my_message, self.my_enum.containing_type)
+
+ def testContainingServiceFixups(self):
+ self.assertEqual(self.my_service, self.my_method.containing_service)
+
+ def testGetOptions(self):
+ self.assertEqual(self.my_enum.GetOptions(),
+ descriptor_pb2.EnumOptions())
+ self.assertEqual(self.my_enum.values[0].GetOptions(),
+ descriptor_pb2.EnumValueOptions())
+ self.assertEqual(self.my_message.GetOptions(),
+ descriptor_pb2.MessageOptions())
+ self.assertEqual(self.my_message.fields[0].GetOptions(),
+ descriptor_pb2.FieldOptions())
+ self.assertEqual(self.my_method.GetOptions(),
+ descriptor_pb2.MethodOptions())
+ self.assertEqual(self.my_service.GetOptions(),
+ descriptor_pb2.ServiceOptions())
+
+ def testSimpleCustomOptions(self):
+ file_descriptor = unittest_custom_options_pb2.DESCRIPTOR
+ message_descriptor =\
+ unittest_custom_options_pb2.TestMessageWithCustomOptions.DESCRIPTOR
+ field_descriptor = message_descriptor.fields_by_name["field1"]
+ enum_descriptor = message_descriptor.enum_types_by_name["AnEnum"]
+ enum_value_descriptor =\
+ message_descriptor.enum_values_by_name["ANENUM_VAL2"]
+ service_descriptor =\
+ unittest_custom_options_pb2.TestServiceWithCustomOptions.DESCRIPTOR
+ method_descriptor = service_descriptor.FindMethodByName("Foo")
+
+ file_options = file_descriptor.GetOptions()
+ file_opt1 = unittest_custom_options_pb2.file_opt1
+ self.assertEqual(9876543210, file_options.Extensions[file_opt1])
+ message_options = message_descriptor.GetOptions()
+ message_opt1 = unittest_custom_options_pb2.message_opt1
+ self.assertEqual(-56, message_options.Extensions[message_opt1])
+ field_options = field_descriptor.GetOptions()
+ field_opt1 = unittest_custom_options_pb2.field_opt1
+ self.assertEqual(8765432109, field_options.Extensions[field_opt1])
+ field_opt2 = unittest_custom_options_pb2.field_opt2
+ self.assertEqual(42, field_options.Extensions[field_opt2])
+ enum_options = enum_descriptor.GetOptions()
+ enum_opt1 = unittest_custom_options_pb2.enum_opt1
+ self.assertEqual(-789, enum_options.Extensions[enum_opt1])
+ enum_value_options = enum_value_descriptor.GetOptions()
+ enum_value_opt1 = unittest_custom_options_pb2.enum_value_opt1
+ self.assertEqual(123, enum_value_options.Extensions[enum_value_opt1])
+
+ service_options = service_descriptor.GetOptions()
+ service_opt1 = unittest_custom_options_pb2.service_opt1
+ self.assertEqual(-9876543210, service_options.Extensions[service_opt1])
+ method_options = method_descriptor.GetOptions()
+ method_opt1 = unittest_custom_options_pb2.method_opt1
+ self.assertEqual(unittest_custom_options_pb2.METHODOPT1_VAL2,
+ method_options.Extensions[method_opt1])
+
+ def testDifferentCustomOptionTypes(self):
+ kint32min = -2**31
+ kint64min = -2**63
+ kint32max = 2**31 - 1
+ kint64max = 2**63 - 1
+ kuint32max = 2**32 - 1
+ kuint64max = 2**64 - 1
+
+ message_descriptor =\
+ unittest_custom_options_pb2.CustomOptionMinIntegerValues.DESCRIPTOR
+ message_options = message_descriptor.GetOptions()
+ self.assertEqual(False, message_options.Extensions[
+ unittest_custom_options_pb2.bool_opt])
+ self.assertEqual(kint32min, message_options.Extensions[
+ unittest_custom_options_pb2.int32_opt])
+ self.assertEqual(kint64min, message_options.Extensions[
+ unittest_custom_options_pb2.int64_opt])
+ self.assertEqual(0, message_options.Extensions[
+ unittest_custom_options_pb2.uint32_opt])
+ self.assertEqual(0, message_options.Extensions[
+ unittest_custom_options_pb2.uint64_opt])
+ self.assertEqual(kint32min, message_options.Extensions[
+ unittest_custom_options_pb2.sint32_opt])
+ self.assertEqual(kint64min, message_options.Extensions[
+ unittest_custom_options_pb2.sint64_opt])
+ self.assertEqual(0, message_options.Extensions[
+ unittest_custom_options_pb2.fixed32_opt])
+ self.assertEqual(0, message_options.Extensions[
+ unittest_custom_options_pb2.fixed64_opt])
+ self.assertEqual(kint32min, message_options.Extensions[
+ unittest_custom_options_pb2.sfixed32_opt])
+ self.assertEqual(kint64min, message_options.Extensions[
+ unittest_custom_options_pb2.sfixed64_opt])
+
+ message_descriptor =\
+ unittest_custom_options_pb2.CustomOptionMaxIntegerValues.DESCRIPTOR
+ message_options = message_descriptor.GetOptions()
+ self.assertEqual(True, message_options.Extensions[
+ unittest_custom_options_pb2.bool_opt])
+ self.assertEqual(kint32max, message_options.Extensions[
+ unittest_custom_options_pb2.int32_opt])
+ self.assertEqual(kint64max, message_options.Extensions[
+ unittest_custom_options_pb2.int64_opt])
+ self.assertEqual(kuint32max, message_options.Extensions[
+ unittest_custom_options_pb2.uint32_opt])
+ self.assertEqual(kuint64max, message_options.Extensions[
+ unittest_custom_options_pb2.uint64_opt])
+ self.assertEqual(kint32max, message_options.Extensions[
+ unittest_custom_options_pb2.sint32_opt])
+ self.assertEqual(kint64max, message_options.Extensions[
+ unittest_custom_options_pb2.sint64_opt])
+ self.assertEqual(kuint32max, message_options.Extensions[
+ unittest_custom_options_pb2.fixed32_opt])
+ self.assertEqual(kuint64max, message_options.Extensions[
+ unittest_custom_options_pb2.fixed64_opt])
+ self.assertEqual(kint32max, message_options.Extensions[
+ unittest_custom_options_pb2.sfixed32_opt])
+ self.assertEqual(kint64max, message_options.Extensions[
+ unittest_custom_options_pb2.sfixed64_opt])
+
+ message_descriptor =\
+ unittest_custom_options_pb2.CustomOptionOtherValues.DESCRIPTOR
+ message_options = message_descriptor.GetOptions()
+ self.assertEqual(-100, message_options.Extensions[
+ unittest_custom_options_pb2.int32_opt])
+ self.assertAlmostEqual(12.3456789, message_options.Extensions[
+ unittest_custom_options_pb2.float_opt], 6)
+ self.assertAlmostEqual(1.234567890123456789, message_options.Extensions[
+ unittest_custom_options_pb2.double_opt])
+ self.assertEqual("Hello, \"World\"", message_options.Extensions[
+ unittest_custom_options_pb2.string_opt])
+ self.assertEqual("Hello\0World", message_options.Extensions[
+ unittest_custom_options_pb2.bytes_opt])
+ dummy_enum = unittest_custom_options_pb2.DummyMessageContainingEnum
+ self.assertEqual(
+ dummy_enum.TEST_OPTION_ENUM_TYPE2,
+ message_options.Extensions[unittest_custom_options_pb2.enum_opt])
+
+ message_descriptor =\
+ unittest_custom_options_pb2.SettingRealsFromPositiveInts.DESCRIPTOR
+ message_options = message_descriptor.GetOptions()
+ self.assertAlmostEqual(12, message_options.Extensions[
+ unittest_custom_options_pb2.float_opt], 6)
+ self.assertAlmostEqual(154, message_options.Extensions[
+ unittest_custom_options_pb2.double_opt])
+
+ message_descriptor =\
+ unittest_custom_options_pb2.SettingRealsFromNegativeInts.DESCRIPTOR
+ message_options = message_descriptor.GetOptions()
+ self.assertAlmostEqual(-12, message_options.Extensions[
+ unittest_custom_options_pb2.float_opt], 6)
+ self.assertAlmostEqual(-154, message_options.Extensions[
+ unittest_custom_options_pb2.double_opt])
+
+ def testComplexExtensionOptions(self):
+ descriptor =\
+ unittest_custom_options_pb2.VariousComplexOptions.DESCRIPTOR
+ options = descriptor.GetOptions()
+ self.assertEqual(42, options.Extensions[
+ unittest_custom_options_pb2.complex_opt1].foo)
+ self.assertEqual(324, options.Extensions[
+ unittest_custom_options_pb2.complex_opt1].Extensions[
+ unittest_custom_options_pb2.quux])
+ self.assertEqual(876, options.Extensions[
+ unittest_custom_options_pb2.complex_opt1].Extensions[
+ unittest_custom_options_pb2.corge].qux)
+ self.assertEqual(987, options.Extensions[
+ unittest_custom_options_pb2.complex_opt2].baz)
+ self.assertEqual(654, options.Extensions[
+ unittest_custom_options_pb2.complex_opt2].Extensions[
+ unittest_custom_options_pb2.grault])
+ self.assertEqual(743, options.Extensions[
+ unittest_custom_options_pb2.complex_opt2].bar.foo)
+ self.assertEqual(1999, options.Extensions[
+ unittest_custom_options_pb2.complex_opt2].bar.Extensions[
+ unittest_custom_options_pb2.quux])
+ self.assertEqual(2008, options.Extensions[
+ unittest_custom_options_pb2.complex_opt2].bar.Extensions[
+ unittest_custom_options_pb2.corge].qux)
+ self.assertEqual(741, options.Extensions[
+ unittest_custom_options_pb2.complex_opt2].Extensions[
+ unittest_custom_options_pb2.garply].foo)
+ self.assertEqual(1998, options.Extensions[
+ unittest_custom_options_pb2.complex_opt2].Extensions[
+ unittest_custom_options_pb2.garply].Extensions[
+ unittest_custom_options_pb2.quux])
+ self.assertEqual(2121, options.Extensions[
+ unittest_custom_options_pb2.complex_opt2].Extensions[
+ unittest_custom_options_pb2.garply].Extensions[
+ unittest_custom_options_pb2.corge].qux)
+ self.assertEqual(1971, options.Extensions[
+ unittest_custom_options_pb2.ComplexOptionType2
+ .ComplexOptionType4.complex_opt4].waldo)
+ self.assertEqual(321, options.Extensions[
+ unittest_custom_options_pb2.complex_opt2].fred.waldo)
+ self.assertEqual(9, options.Extensions[
+ unittest_custom_options_pb2.complex_opt3].qux)
+ self.assertEqual(22, options.Extensions[
+ unittest_custom_options_pb2.complex_opt3].complexoptiontype5.plugh)
+ self.assertEqual(24, options.Extensions[
+ unittest_custom_options_pb2.complexopt6].xyzzy)
+
+ # Check that aggregate options were parsed and saved correctly in
+ # the appropriate descriptors.
+ def testAggregateOptions(self):
+ file_descriptor = unittest_custom_options_pb2.DESCRIPTOR
+ message_descriptor =\
+ unittest_custom_options_pb2.AggregateMessage.DESCRIPTOR
+ field_descriptor = message_descriptor.fields_by_name["fieldname"]
+ enum_descriptor = unittest_custom_options_pb2.AggregateEnum.DESCRIPTOR
+ enum_value_descriptor = enum_descriptor.values_by_name["VALUE"]
+ service_descriptor =\
+ unittest_custom_options_pb2.AggregateService.DESCRIPTOR
+ method_descriptor = service_descriptor.FindMethodByName("Method")
+
+ # Tests for the different types of data embedded in fileopt
+ file_options = file_descriptor.GetOptions().Extensions[
+ unittest_custom_options_pb2.fileopt]
+ self.assertEqual(100, file_options.i)
+ self.assertEqual("FileAnnotation", file_options.s)
+ self.assertEqual("NestedFileAnnotation", file_options.sub.s)
+ self.assertEqual("FileExtensionAnnotation", file_options.file.Extensions[
+ unittest_custom_options_pb2.fileopt].s)
+ self.assertEqual("EmbeddedMessageSetElement", file_options.mset.Extensions[
+ unittest_custom_options_pb2.AggregateMessageSetElement
+ .message_set_extension].s)
+
+ # Simple tests for all the other types of annotations
+ self.assertEqual(
+ "MessageAnnotation",
+ message_descriptor.GetOptions().Extensions[
+ unittest_custom_options_pb2.msgopt].s)
+ self.assertEqual(
+ "FieldAnnotation",
+ field_descriptor.GetOptions().Extensions[
+ unittest_custom_options_pb2.fieldopt].s)
+ self.assertEqual(
+ "EnumAnnotation",
+ enum_descriptor.GetOptions().Extensions[
+ unittest_custom_options_pb2.enumopt].s)
+ self.assertEqual(
+ "EnumValueAnnotation",
+ enum_value_descriptor.GetOptions().Extensions[
+ unittest_custom_options_pb2.enumvalopt].s)
+ self.assertEqual(
+ "ServiceAnnotation",
+ service_descriptor.GetOptions().Extensions[
+ unittest_custom_options_pb2.serviceopt].s)
+ self.assertEqual(
+ "MethodAnnotation",
+ method_descriptor.GetOptions().Extensions[
+ unittest_custom_options_pb2.methodopt].s)
+
+ def testNestedOptions(self):
+ nested_message =\
+ unittest_custom_options_pb2.NestedOptionType.NestedMessage.DESCRIPTOR
+ self.assertEqual(1001, nested_message.GetOptions().Extensions[
+ unittest_custom_options_pb2.message_opt1])
+ nested_field = nested_message.fields_by_name["nested_field"]
+ self.assertEqual(1002, nested_field.GetOptions().Extensions[
+ unittest_custom_options_pb2.field_opt1])
+ outer_message =\
+ unittest_custom_options_pb2.NestedOptionType.DESCRIPTOR
+ nested_enum = outer_message.enum_types_by_name["NestedEnum"]
+ self.assertEqual(1003, nested_enum.GetOptions().Extensions[
+ unittest_custom_options_pb2.enum_opt1])
+ nested_enum_value = outer_message.enum_values_by_name["NESTED_ENUM_VALUE"]
+ self.assertEqual(1004, nested_enum_value.GetOptions().Extensions[
+ unittest_custom_options_pb2.enum_value_opt1])
+ nested_extension = outer_message.extensions_by_name["nested_extension"]
+ self.assertEqual(1005, nested_extension.GetOptions().Extensions[
+ unittest_custom_options_pb2.field_opt2])
+
+ def testFileDescriptorReferences(self):
+ self.assertEqual(self.my_enum.file, self.my_file)
+ self.assertEqual(self.my_message.file, self.my_file)
+
+ def testFileDescriptor(self):
+ self.assertEqual(self.my_file.name, 'some/filename/some.proto')
+ self.assertEqual(self.my_file.package, 'protobuf_unittest')
+
+
+class DescriptorCopyToProtoTest(unittest.TestCase):
+ """Tests for CopyTo functions of Descriptor."""
+
+ def _AssertProtoEqual(self, actual_proto, expected_class, expected_ascii):
+ expected_proto = expected_class()
+ text_format.Merge(expected_ascii, expected_proto)
+
+ self.assertEqual(
+ actual_proto, expected_proto,
+ 'Not equal,\nActual:\n%s\nExpected:\n%s\n'
+ % (str(actual_proto), str(expected_proto)))
+
+ def _InternalTestCopyToProto(self, desc, expected_proto_class,
+ expected_proto_ascii):
+ actual = expected_proto_class()
+ desc.CopyToProto(actual)
+ self._AssertProtoEqual(
+ actual, expected_proto_class, expected_proto_ascii)
+
+ def testCopyToProto_EmptyMessage(self):
+ self._InternalTestCopyToProto(
+ unittest_pb2.TestEmptyMessage.DESCRIPTOR,
+ descriptor_pb2.DescriptorProto,
+ TEST_EMPTY_MESSAGE_DESCRIPTOR_ASCII)
+
+ def testCopyToProto_NestedMessage(self):
+ TEST_NESTED_MESSAGE_ASCII = """
+ name: 'NestedMessage'
+ field: <
+ name: 'bb'
+ number: 1
+ label: 1 # Optional
+ type: 5 # TYPE_INT32
+ >
+ """
+
+ self._InternalTestCopyToProto(
+ unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR,
+ descriptor_pb2.DescriptorProto,
+ TEST_NESTED_MESSAGE_ASCII)
+
+ def testCopyToProto_ForeignNestedMessage(self):
+ TEST_FOREIGN_NESTED_ASCII = """
+ name: 'TestForeignNested'
+ field: <
+ name: 'foreign_nested'
+ number: 1
+ label: 1 # Optional
+ type: 11 # TYPE_MESSAGE
+ type_name: '.protobuf_unittest.TestAllTypes.NestedMessage'
+ >
+ """
+
+ self._InternalTestCopyToProto(
+ unittest_pb2.TestForeignNested.DESCRIPTOR,
+ descriptor_pb2.DescriptorProto,
+ TEST_FOREIGN_NESTED_ASCII)
+
+ def testCopyToProto_ForeignEnum(self):
+ TEST_FOREIGN_ENUM_ASCII = """
+ name: 'ForeignEnum'
+ value: <
+ name: 'FOREIGN_FOO'
+ number: 4
+ >
+ value: <
+ name: 'FOREIGN_BAR'
+ number: 5
+ >
+ value: <
+ name: 'FOREIGN_BAZ'
+ number: 6
+ >
+ """
+
+ self._InternalTestCopyToProto(
+ unittest_pb2._FOREIGNENUM,
+ descriptor_pb2.EnumDescriptorProto,
+ TEST_FOREIGN_ENUM_ASCII)
+
+ def testCopyToProto_Options(self):
+ TEST_DEPRECATED_FIELDS_ASCII = """
+ name: 'TestDeprecatedFields'
+ field: <
+ name: 'deprecated_int32'
+ number: 1
+ label: 1 # Optional
+ type: 5 # TYPE_INT32
+ options: <
+ deprecated: true
+ >
+ >
+ """
+
+ self._InternalTestCopyToProto(
+ unittest_pb2.TestDeprecatedFields.DESCRIPTOR,
+ descriptor_pb2.DescriptorProto,
+ TEST_DEPRECATED_FIELDS_ASCII)
+
+ def testCopyToProto_AllExtensions(self):
+ TEST_EMPTY_MESSAGE_WITH_EXTENSIONS_ASCII = """
+ name: 'TestEmptyMessageWithExtensions'
+ extension_range: <
+ start: 1
+ end: 536870912
+ >
+ """
+
+ self._InternalTestCopyToProto(
+ unittest_pb2.TestEmptyMessageWithExtensions.DESCRIPTOR,
+ descriptor_pb2.DescriptorProto,
+ TEST_EMPTY_MESSAGE_WITH_EXTENSIONS_ASCII)
+
+ def testCopyToProto_SeveralExtensions(self):
+ TEST_MESSAGE_WITH_SEVERAL_EXTENSIONS_ASCII = """
+ name: 'TestMultipleExtensionRanges'
+ extension_range: <
+ start: 42
+ end: 43
+ >
+ extension_range: <
+ start: 4143
+ end: 4244
+ >
+ extension_range: <
+ start: 65536
+ end: 536870912
+ >
+ """
+
+ self._InternalTestCopyToProto(
+ unittest_pb2.TestMultipleExtensionRanges.DESCRIPTOR,
+ descriptor_pb2.DescriptorProto,
+ TEST_MESSAGE_WITH_SEVERAL_EXTENSIONS_ASCII)
+
+ def testCopyToProto_FileDescriptor(self):
+ UNITTEST_IMPORT_FILE_DESCRIPTOR_ASCII = ("""
+ name: 'google/protobuf/unittest_import.proto'
+ package: 'protobuf_unittest_import'
+ dependency: 'google/protobuf/unittest_import_public.proto'
+ message_type: <
+ name: 'ImportMessage'
+ field: <
+ name: 'd'
+ number: 1
+ label: 1 # Optional
+ type: 5 # TYPE_INT32
+ >
+ >
+ """ +
+ """enum_type: <
+ name: 'ImportEnum'
+ value: <
+ name: 'IMPORT_FOO'
+ number: 7
+ >
+ value: <
+ name: 'IMPORT_BAR'
+ number: 8
+ >
+ value: <
+ name: 'IMPORT_BAZ'
+ number: 9
+ >
+ >
+ options: <
+ java_package: 'com.google.protobuf.test'
+ optimize_for: 1 # SPEED
+ >
+ public_dependency: 0
+ """)
+
+ self._InternalTestCopyToProto(
+ unittest_import_pb2.DESCRIPTOR,
+ descriptor_pb2.FileDescriptorProto,
+ UNITTEST_IMPORT_FILE_DESCRIPTOR_ASCII)
+
+ def testCopyToProto_ServiceDescriptor(self):
+ TEST_SERVICE_ASCII = """
+ name: 'TestService'
+ method: <
+ name: 'Foo'
+ input_type: '.protobuf_unittest.FooRequest'
+ output_type: '.protobuf_unittest.FooResponse'
+ >
+ method: <
+ name: 'Bar'
+ input_type: '.protobuf_unittest.BarRequest'
+ output_type: '.protobuf_unittest.BarResponse'
+ >
+ """
+
+ self._InternalTestCopyToProto(
+ unittest_pb2.TestService.DESCRIPTOR,
+ descriptor_pb2.ServiceDescriptorProto,
+ TEST_SERVICE_ASCII)
+
+
+class MakeDescriptorTest(unittest.TestCase):
+ def testMakeDescriptorWithUnsignedIntField(self):
+ file_descriptor_proto = descriptor_pb2.FileDescriptorProto()
+ file_descriptor_proto.name = 'Foo'
+ message_type = file_descriptor_proto.message_type.add()
+ message_type.name = file_descriptor_proto.name
+ field = message_type.field.add()
+ field.number = 1
+ field.name = 'uint64_field'
+ field.label = descriptor.FieldDescriptor.LABEL_REQUIRED
+ field.type = descriptor.FieldDescriptor.TYPE_UINT64
+ result = descriptor.MakeDescriptor(message_type)
+ self.assertEqual(result.fields[0].cpp_type,
+ descriptor.FieldDescriptor.CPPTYPE_UINT64)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/generator_test.py b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/generator_test.py
new file mode 100755
index 0000000000..8343aba1e1
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/generator_test.py
@@ -0,0 +1,269 @@
+#! /usr/bin/python
+#
+# Protocol Buffers - Google's data interchange format
+# Copyright 2008 Google Inc. All rights reserved.
+# http://code.google.com/p/protobuf/
+#
+# 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.
+
+# TODO(robinson): Flesh this out considerably. We focused on reflection_test.py
+# first, since it's testing the subtler code, and since it provides decent
+# indirect testing of the protocol compiler output.
+
+"""Unittest that directly tests the output of the pure-Python protocol
+compiler. See //google/protobuf/reflection_test.py for a test which
+further ensures that we can use Python protocol message objects as we expect.
+"""
+
+__author__ = 'robinson@google.com (Will Robinson)'
+
+import unittest
+from google.protobuf.internal import test_bad_identifiers_pb2
+from google.protobuf import unittest_custom_options_pb2
+from google.protobuf import unittest_import_pb2
+from google.protobuf import unittest_import_public_pb2
+from google.protobuf import unittest_mset_pb2
+from google.protobuf import unittest_pb2
+from google.protobuf import unittest_no_generic_services_pb2
+from google.protobuf import service
+
+MAX_EXTENSION = 536870912
+
+
+class GeneratorTest(unittest.TestCase):
+
+ def testNestedMessageDescriptor(self):
+ field_name = 'optional_nested_message'
+ proto_type = unittest_pb2.TestAllTypes
+ self.assertEqual(
+ proto_type.NestedMessage.DESCRIPTOR,
+ proto_type.DESCRIPTOR.fields_by_name[field_name].message_type)
+
+ def testEnums(self):
+ # We test only module-level enums here.
+ # TODO(robinson): Examine descriptors directly to check
+ # enum descriptor output.
+ self.assertEqual(4, unittest_pb2.FOREIGN_FOO)
+ self.assertEqual(5, unittest_pb2.FOREIGN_BAR)
+ self.assertEqual(6, unittest_pb2.FOREIGN_BAZ)
+
+ proto = unittest_pb2.TestAllTypes()
+ self.assertEqual(1, proto.FOO)
+ self.assertEqual(1, unittest_pb2.TestAllTypes.FOO)
+ self.assertEqual(2, proto.BAR)
+ self.assertEqual(2, unittest_pb2.TestAllTypes.BAR)
+ self.assertEqual(3, proto.BAZ)
+ self.assertEqual(3, unittest_pb2.TestAllTypes.BAZ)
+
+ def testExtremeDefaultValues(self):
+ message = unittest_pb2.TestExtremeDefaultValues()
+
+ # Python pre-2.6 does not have isinf() or isnan() functions, so we have
+ # to provide our own.
+ def isnan(val):
+ # NaN is never equal to itself.
+ return val != val
+ def isinf(val):
+ # Infinity times zero equals NaN.
+ return not isnan(val) and isnan(val * 0)
+
+ self.assertTrue(isinf(message.inf_double))
+ self.assertTrue(message.inf_double > 0)
+ self.assertTrue(isinf(message.neg_inf_double))
+ self.assertTrue(message.neg_inf_double < 0)
+ self.assertTrue(isnan(message.nan_double))
+
+ self.assertTrue(isinf(message.inf_float))
+ self.assertTrue(message.inf_float > 0)
+ self.assertTrue(isinf(message.neg_inf_float))
+ self.assertTrue(message.neg_inf_float < 0)
+ self.assertTrue(isnan(message.nan_float))
+ self.assertEqual("? ? ?? ?? ??? ??/ ??-", message.cpp_trigraph)
+
+ def testHasDefaultValues(self):
+ desc = unittest_pb2.TestAllTypes.DESCRIPTOR
+
+ expected_has_default_by_name = {
+ 'optional_int32': False,
+ 'repeated_int32': False,
+ 'optional_nested_message': False,
+ 'default_int32': True,
+ }
+
+ has_default_by_name = dict(
+ [(f.name, f.has_default_value)
+ for f in desc.fields
+ if f.name in expected_has_default_by_name])
+ self.assertEqual(expected_has_default_by_name, has_default_by_name)
+
+ def testContainingTypeBehaviorForExtensions(self):
+ self.assertEqual(unittest_pb2.optional_int32_extension.containing_type,
+ unittest_pb2.TestAllExtensions.DESCRIPTOR)
+ self.assertEqual(unittest_pb2.TestRequired.single.containing_type,
+ unittest_pb2.TestAllExtensions.DESCRIPTOR)
+
+ def testExtensionScope(self):
+ self.assertEqual(unittest_pb2.optional_int32_extension.extension_scope,
+ None)
+ self.assertEqual(unittest_pb2.TestRequired.single.extension_scope,
+ unittest_pb2.TestRequired.DESCRIPTOR)
+
+ def testIsExtension(self):
+ self.assertTrue(unittest_pb2.optional_int32_extension.is_extension)
+ self.assertTrue(unittest_pb2.TestRequired.single.is_extension)
+
+ message_descriptor = unittest_pb2.TestRequired.DESCRIPTOR
+ non_extension_descriptor = message_descriptor.fields_by_name['a']
+ self.assertTrue(not non_extension_descriptor.is_extension)
+
+ def testOptions(self):
+ proto = unittest_mset_pb2.TestMessageSet()
+ self.assertTrue(proto.DESCRIPTOR.GetOptions().message_set_wire_format)
+
+ def testMessageWithCustomOptions(self):
+ proto = unittest_custom_options_pb2.TestMessageWithCustomOptions()
+ enum_options = proto.DESCRIPTOR.enum_types_by_name['AnEnum'].GetOptions()
+ self.assertTrue(enum_options is not None)
+ # TODO(gps): We really should test for the presense of the enum_opt1
+ # extension and for its value to be set to -789.
+
+ def testNestedTypes(self):
+ self.assertEquals(
+ set(unittest_pb2.TestAllTypes.DESCRIPTOR.nested_types),
+ set([
+ unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR,
+ unittest_pb2.TestAllTypes.OptionalGroup.DESCRIPTOR,
+ unittest_pb2.TestAllTypes.RepeatedGroup.DESCRIPTOR,
+ ]))
+ self.assertEqual(unittest_pb2.TestEmptyMessage.DESCRIPTOR.nested_types, [])
+ self.assertEqual(
+ unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR.nested_types, [])
+
+ def testContainingType(self):
+ self.assertTrue(
+ unittest_pb2.TestEmptyMessage.DESCRIPTOR.containing_type is None)
+ self.assertTrue(
+ unittest_pb2.TestAllTypes.DESCRIPTOR.containing_type is None)
+ self.assertEqual(
+ unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR.containing_type,
+ unittest_pb2.TestAllTypes.DESCRIPTOR)
+ self.assertEqual(
+ unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR.containing_type,
+ unittest_pb2.TestAllTypes.DESCRIPTOR)
+ self.assertEqual(
+ unittest_pb2.TestAllTypes.RepeatedGroup.DESCRIPTOR.containing_type,
+ unittest_pb2.TestAllTypes.DESCRIPTOR)
+
+ def testContainingTypeInEnumDescriptor(self):
+ self.assertTrue(unittest_pb2._FOREIGNENUM.containing_type is None)
+ self.assertEqual(unittest_pb2._TESTALLTYPES_NESTEDENUM.containing_type,
+ unittest_pb2.TestAllTypes.DESCRIPTOR)
+
+ def testPackage(self):
+ self.assertEqual(
+ unittest_pb2.TestAllTypes.DESCRIPTOR.file.package,
+ 'protobuf_unittest')
+ desc = unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR
+ self.assertEqual(desc.file.package, 'protobuf_unittest')
+ self.assertEqual(
+ unittest_import_pb2.ImportMessage.DESCRIPTOR.file.package,
+ 'protobuf_unittest_import')
+
+ self.assertEqual(
+ unittest_pb2._FOREIGNENUM.file.package, 'protobuf_unittest')
+ self.assertEqual(
+ unittest_pb2._TESTALLTYPES_NESTEDENUM.file.package,
+ 'protobuf_unittest')
+ self.assertEqual(
+ unittest_import_pb2._IMPORTENUM.file.package,
+ 'protobuf_unittest_import')
+
+ def testExtensionRange(self):
+ self.assertEqual(
+ unittest_pb2.TestAllTypes.DESCRIPTOR.extension_ranges, [])
+ self.assertEqual(
+ unittest_pb2.TestAllExtensions.DESCRIPTOR.extension_ranges,
+ [(1, MAX_EXTENSION)])
+ self.assertEqual(
+ unittest_pb2.TestMultipleExtensionRanges.DESCRIPTOR.extension_ranges,
+ [(42, 43), (4143, 4244), (65536, MAX_EXTENSION)])
+
+ def testFileDescriptor(self):
+ self.assertEqual(unittest_pb2.DESCRIPTOR.name,
+ 'google/protobuf/unittest.proto')
+ self.assertEqual(unittest_pb2.DESCRIPTOR.package, 'protobuf_unittest')
+ self.assertFalse(unittest_pb2.DESCRIPTOR.serialized_pb is None)
+
+ def testNoGenericServices(self):
+ self.assertTrue(hasattr(unittest_no_generic_services_pb2, "TestMessage"))
+ self.assertTrue(hasattr(unittest_no_generic_services_pb2, "FOO"))
+ self.assertTrue(hasattr(unittest_no_generic_services_pb2, "test_extension"))
+
+ # Make sure unittest_no_generic_services_pb2 has no services subclassing
+ # Proto2 Service class.
+ if hasattr(unittest_no_generic_services_pb2, "TestService"):
+ self.assertFalse(issubclass(unittest_no_generic_services_pb2.TestService,
+ service.Service))
+
+ def testMessageTypesByName(self):
+ file_type = unittest_pb2.DESCRIPTOR
+ self.assertEqual(
+ unittest_pb2._TESTALLTYPES,
+ file_type.message_types_by_name[unittest_pb2._TESTALLTYPES.name])
+
+ # Nested messages shouldn't be included in the message_types_by_name
+ # dictionary (like in the C++ API).
+ self.assertFalse(
+ unittest_pb2._TESTALLTYPES_NESTEDMESSAGE.name in
+ file_type.message_types_by_name)
+
+ def testPublicImports(self):
+ # Test public imports as embedded message.
+ all_type_proto = unittest_pb2.TestAllTypes()
+ self.assertEqual(0, all_type_proto.optional_public_import_message.e)
+
+ # PublicImportMessage is actually defined in unittest_import_public_pb2
+ # module, and is public imported by unittest_import_pb2 module.
+ public_import_proto = unittest_import_pb2.PublicImportMessage()
+ self.assertEqual(0, public_import_proto.e)
+ self.assertTrue(unittest_import_public_pb2.PublicImportMessage is
+ unittest_import_pb2.PublicImportMessage)
+
+ def testBadIdentifiers(self):
+ # We're just testing that the code was imported without problems.
+ message = test_bad_identifiers_pb2.TestBadIdentifiers()
+ self.assertEqual(message.Extensions[test_bad_identifiers_pb2.message],
+ "foo")
+ self.assertEqual(message.Extensions[test_bad_identifiers_pb2.descriptor],
+ "bar")
+ self.assertEqual(message.Extensions[test_bad_identifiers_pb2.reflection],
+ "baz")
+ self.assertEqual(message.Extensions[test_bad_identifiers_pb2.service],
+ "qux")
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/golden_message b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/golden_message
new file mode 100644
index 0000000000..4dd62cd3bb
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/golden_message
Binary files differ
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/golden_packed_fields_message b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/golden_packed_fields_message
index ee28d38830..ee28d38830 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/golden_packed_fields_message
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/golden_packed_fields_message
Binary files differ
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/message_test.py b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/message_test.py
new file mode 100755
index 0000000000..53e9d50780
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/message_test.py
@@ -0,0 +1,494 @@
+#! /usr/bin/python
+#
+# Protocol Buffers - Google's data interchange format
+# Copyright 2008 Google Inc. All rights reserved.
+# http://code.google.com/p/protobuf/
+#
+# 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.
+
+"""Tests python protocol buffers against the golden message.
+
+Note that the golden messages exercise every known field type, thus this
+test ends up exercising and verifying nearly all of the parsing and
+serialization code in the whole library.
+
+TODO(kenton): Merge with wire_format_test? It doesn't make a whole lot of
+sense to call this a test of the "message" module, which only declares an
+abstract interface.
+"""
+
+__author__ = 'gps@google.com (Gregory P. Smith)'
+
+import copy
+import math
+import operator
+import pickle
+
+import unittest
+from google.protobuf import unittest_import_pb2
+from google.protobuf import unittest_pb2
+from google.protobuf.internal import api_implementation
+from google.protobuf.internal import test_util
+from google.protobuf import message
+
+# Python pre-2.6 does not have isinf() or isnan() functions, so we have
+# to provide our own.
+def isnan(val):
+ # NaN is never equal to itself.
+ return val != val
+def isinf(val):
+ # Infinity times zero equals NaN.
+ return not isnan(val) and isnan(val * 0)
+def IsPosInf(val):
+ return isinf(val) and (val > 0)
+def IsNegInf(val):
+ return isinf(val) and (val < 0)
+
+class MessageTest(unittest.TestCase):
+
+ def testGoldenMessage(self):
+ golden_data = test_util.GoldenFile('golden_message').read()
+ golden_message = unittest_pb2.TestAllTypes()
+ golden_message.ParseFromString(golden_data)
+ test_util.ExpectAllFieldsSet(self, golden_message)
+ self.assertEqual(golden_data, golden_message.SerializeToString())
+ golden_copy = copy.deepcopy(golden_message)
+ self.assertEqual(golden_data, golden_copy.SerializeToString())
+
+ def testGoldenExtensions(self):
+ golden_data = test_util.GoldenFile('golden_message').read()
+ golden_message = unittest_pb2.TestAllExtensions()
+ golden_message.ParseFromString(golden_data)
+ all_set = unittest_pb2.TestAllExtensions()
+ test_util.SetAllExtensions(all_set)
+ self.assertEquals(all_set, golden_message)
+ self.assertEqual(golden_data, golden_message.SerializeToString())
+ golden_copy = copy.deepcopy(golden_message)
+ self.assertEqual(golden_data, golden_copy.SerializeToString())
+
+ def testGoldenPackedMessage(self):
+ golden_data = test_util.GoldenFile('golden_packed_fields_message').read()
+ golden_message = unittest_pb2.TestPackedTypes()
+ golden_message.ParseFromString(golden_data)
+ all_set = unittest_pb2.TestPackedTypes()
+ test_util.SetAllPackedFields(all_set)
+ self.assertEquals(all_set, golden_message)
+ self.assertEqual(golden_data, all_set.SerializeToString())
+ golden_copy = copy.deepcopy(golden_message)
+ self.assertEqual(golden_data, golden_copy.SerializeToString())
+
+ def testGoldenPackedExtensions(self):
+ golden_data = test_util.GoldenFile('golden_packed_fields_message').read()
+ golden_message = unittest_pb2.TestPackedExtensions()
+ golden_message.ParseFromString(golden_data)
+ all_set = unittest_pb2.TestPackedExtensions()
+ test_util.SetAllPackedExtensions(all_set)
+ self.assertEquals(all_set, golden_message)
+ self.assertEqual(golden_data, all_set.SerializeToString())
+ golden_copy = copy.deepcopy(golden_message)
+ self.assertEqual(golden_data, golden_copy.SerializeToString())
+
+ def testPickleSupport(self):
+ golden_data = test_util.GoldenFile('golden_message').read()
+ golden_message = unittest_pb2.TestAllTypes()
+ golden_message.ParseFromString(golden_data)
+ pickled_message = pickle.dumps(golden_message)
+
+ unpickled_message = pickle.loads(pickled_message)
+ self.assertEquals(unpickled_message, golden_message)
+
+ def testPickleIncompleteProto(self):
+ golden_message = unittest_pb2.TestRequired(a=1)
+ pickled_message = pickle.dumps(golden_message)
+
+ unpickled_message = pickle.loads(pickled_message)
+ self.assertEquals(unpickled_message, golden_message)
+ self.assertEquals(unpickled_message.a, 1)
+ # This is still an incomplete proto - so serializing should fail
+ self.assertRaises(message.EncodeError, unpickled_message.SerializeToString)
+
+ def testPositiveInfinity(self):
+ golden_data = ('\x5D\x00\x00\x80\x7F'
+ '\x61\x00\x00\x00\x00\x00\x00\xF0\x7F'
+ '\xCD\x02\x00\x00\x80\x7F'
+ '\xD1\x02\x00\x00\x00\x00\x00\x00\xF0\x7F')
+ golden_message = unittest_pb2.TestAllTypes()
+ golden_message.ParseFromString(golden_data)
+ self.assertTrue(IsPosInf(golden_message.optional_float))
+ self.assertTrue(IsPosInf(golden_message.optional_double))
+ self.assertTrue(IsPosInf(golden_message.repeated_float[0]))
+ self.assertTrue(IsPosInf(golden_message.repeated_double[0]))
+ self.assertEqual(golden_data, golden_message.SerializeToString())
+
+ def testNegativeInfinity(self):
+ golden_data = ('\x5D\x00\x00\x80\xFF'
+ '\x61\x00\x00\x00\x00\x00\x00\xF0\xFF'
+ '\xCD\x02\x00\x00\x80\xFF'
+ '\xD1\x02\x00\x00\x00\x00\x00\x00\xF0\xFF')
+ golden_message = unittest_pb2.TestAllTypes()
+ golden_message.ParseFromString(golden_data)
+ self.assertTrue(IsNegInf(golden_message.optional_float))
+ self.assertTrue(IsNegInf(golden_message.optional_double))
+ self.assertTrue(IsNegInf(golden_message.repeated_float[0]))
+ self.assertTrue(IsNegInf(golden_message.repeated_double[0]))
+ self.assertEqual(golden_data, golden_message.SerializeToString())
+
+ def testNotANumber(self):
+ golden_data = ('\x5D\x00\x00\xC0\x7F'
+ '\x61\x00\x00\x00\x00\x00\x00\xF8\x7F'
+ '\xCD\x02\x00\x00\xC0\x7F'
+ '\xD1\x02\x00\x00\x00\x00\x00\x00\xF8\x7F')
+ golden_message = unittest_pb2.TestAllTypes()
+ golden_message.ParseFromString(golden_data)
+ self.assertTrue(isnan(golden_message.optional_float))
+ self.assertTrue(isnan(golden_message.optional_double))
+ self.assertTrue(isnan(golden_message.repeated_float[0]))
+ self.assertTrue(isnan(golden_message.repeated_double[0]))
+
+ # The protocol buffer may serialize to any one of multiple different
+ # representations of a NaN. Rather than verify a specific representation,
+ # verify the serialized string can be converted into a correctly
+ # behaving protocol buffer.
+ serialized = golden_message.SerializeToString()
+ message = unittest_pb2.TestAllTypes()
+ message.ParseFromString(serialized)
+ self.assertTrue(isnan(message.optional_float))
+ self.assertTrue(isnan(message.optional_double))
+ self.assertTrue(isnan(message.repeated_float[0]))
+ self.assertTrue(isnan(message.repeated_double[0]))
+
+ def testPositiveInfinityPacked(self):
+ golden_data = ('\xA2\x06\x04\x00\x00\x80\x7F'
+ '\xAA\x06\x08\x00\x00\x00\x00\x00\x00\xF0\x7F')
+ golden_message = unittest_pb2.TestPackedTypes()
+ golden_message.ParseFromString(golden_data)
+ self.assertTrue(IsPosInf(golden_message.packed_float[0]))
+ self.assertTrue(IsPosInf(golden_message.packed_double[0]))
+ self.assertEqual(golden_data, golden_message.SerializeToString())
+
+ def testNegativeInfinityPacked(self):
+ golden_data = ('\xA2\x06\x04\x00\x00\x80\xFF'
+ '\xAA\x06\x08\x00\x00\x00\x00\x00\x00\xF0\xFF')
+ golden_message = unittest_pb2.TestPackedTypes()
+ golden_message.ParseFromString(golden_data)
+ self.assertTrue(IsNegInf(golden_message.packed_float[0]))
+ self.assertTrue(IsNegInf(golden_message.packed_double[0]))
+ self.assertEqual(golden_data, golden_message.SerializeToString())
+
+ def testNotANumberPacked(self):
+ golden_data = ('\xA2\x06\x04\x00\x00\xC0\x7F'
+ '\xAA\x06\x08\x00\x00\x00\x00\x00\x00\xF8\x7F')
+ golden_message = unittest_pb2.TestPackedTypes()
+ golden_message.ParseFromString(golden_data)
+ self.assertTrue(isnan(golden_message.packed_float[0]))
+ self.assertTrue(isnan(golden_message.packed_double[0]))
+
+ serialized = golden_message.SerializeToString()
+ message = unittest_pb2.TestPackedTypes()
+ message.ParseFromString(serialized)
+ self.assertTrue(isnan(message.packed_float[0]))
+ self.assertTrue(isnan(message.packed_double[0]))
+
+ def testExtremeFloatValues(self):
+ message = unittest_pb2.TestAllTypes()
+
+ # Most positive exponent, no significand bits set.
+ kMostPosExponentNoSigBits = math.pow(2, 127)
+ message.optional_float = kMostPosExponentNoSigBits
+ message.ParseFromString(message.SerializeToString())
+ self.assertTrue(message.optional_float == kMostPosExponentNoSigBits)
+
+ # Most positive exponent, one significand bit set.
+ kMostPosExponentOneSigBit = 1.5 * math.pow(2, 127)
+ message.optional_float = kMostPosExponentOneSigBit
+ message.ParseFromString(message.SerializeToString())
+ self.assertTrue(message.optional_float == kMostPosExponentOneSigBit)
+
+ # Repeat last two cases with values of same magnitude, but negative.
+ message.optional_float = -kMostPosExponentNoSigBits
+ message.ParseFromString(message.SerializeToString())
+ self.assertTrue(message.optional_float == -kMostPosExponentNoSigBits)
+
+ message.optional_float = -kMostPosExponentOneSigBit
+ message.ParseFromString(message.SerializeToString())
+ self.assertTrue(message.optional_float == -kMostPosExponentOneSigBit)
+
+ # Most negative exponent, no significand bits set.
+ kMostNegExponentNoSigBits = math.pow(2, -127)
+ message.optional_float = kMostNegExponentNoSigBits
+ message.ParseFromString(message.SerializeToString())
+ self.assertTrue(message.optional_float == kMostNegExponentNoSigBits)
+
+ # Most negative exponent, one significand bit set.
+ kMostNegExponentOneSigBit = 1.5 * math.pow(2, -127)
+ message.optional_float = kMostNegExponentOneSigBit
+ message.ParseFromString(message.SerializeToString())
+ self.assertTrue(message.optional_float == kMostNegExponentOneSigBit)
+
+ # Repeat last two cases with values of the same magnitude, but negative.
+ message.optional_float = -kMostNegExponentNoSigBits
+ message.ParseFromString(message.SerializeToString())
+ self.assertTrue(message.optional_float == -kMostNegExponentNoSigBits)
+
+ message.optional_float = -kMostNegExponentOneSigBit
+ message.ParseFromString(message.SerializeToString())
+ self.assertTrue(message.optional_float == -kMostNegExponentOneSigBit)
+
+ def testExtremeDoubleValues(self):
+ message = unittest_pb2.TestAllTypes()
+
+ # Most positive exponent, no significand bits set.
+ kMostPosExponentNoSigBits = math.pow(2, 1023)
+ message.optional_double = kMostPosExponentNoSigBits
+ message.ParseFromString(message.SerializeToString())
+ self.assertTrue(message.optional_double == kMostPosExponentNoSigBits)
+
+ # Most positive exponent, one significand bit set.
+ kMostPosExponentOneSigBit = 1.5 * math.pow(2, 1023)
+ message.optional_double = kMostPosExponentOneSigBit
+ message.ParseFromString(message.SerializeToString())
+ self.assertTrue(message.optional_double == kMostPosExponentOneSigBit)
+
+ # Repeat last two cases with values of same magnitude, but negative.
+ message.optional_double = -kMostPosExponentNoSigBits
+ message.ParseFromString(message.SerializeToString())
+ self.assertTrue(message.optional_double == -kMostPosExponentNoSigBits)
+
+ message.optional_double = -kMostPosExponentOneSigBit
+ message.ParseFromString(message.SerializeToString())
+ self.assertTrue(message.optional_double == -kMostPosExponentOneSigBit)
+
+ # Most negative exponent, no significand bits set.
+ kMostNegExponentNoSigBits = math.pow(2, -1023)
+ message.optional_double = kMostNegExponentNoSigBits
+ message.ParseFromString(message.SerializeToString())
+ self.assertTrue(message.optional_double == kMostNegExponentNoSigBits)
+
+ # Most negative exponent, one significand bit set.
+ kMostNegExponentOneSigBit = 1.5 * math.pow(2, -1023)
+ message.optional_double = kMostNegExponentOneSigBit
+ message.ParseFromString(message.SerializeToString())
+ self.assertTrue(message.optional_double == kMostNegExponentOneSigBit)
+
+ # Repeat last two cases with values of the same magnitude, but negative.
+ message.optional_double = -kMostNegExponentNoSigBits
+ message.ParseFromString(message.SerializeToString())
+ self.assertTrue(message.optional_double == -kMostNegExponentNoSigBits)
+
+ message.optional_double = -kMostNegExponentOneSigBit
+ message.ParseFromString(message.SerializeToString())
+ self.assertTrue(message.optional_double == -kMostNegExponentOneSigBit)
+
+ def testSortingRepeatedScalarFieldsDefaultComparator(self):
+ """Check some different types with the default comparator."""
+ message = unittest_pb2.TestAllTypes()
+
+ # TODO(mattp): would testing more scalar types strengthen test?
+ message.repeated_int32.append(1)
+ message.repeated_int32.append(3)
+ message.repeated_int32.append(2)
+ message.repeated_int32.sort()
+ self.assertEqual(message.repeated_int32[0], 1)
+ self.assertEqual(message.repeated_int32[1], 2)
+ self.assertEqual(message.repeated_int32[2], 3)
+
+ message.repeated_float.append(1.1)
+ message.repeated_float.append(1.3)
+ message.repeated_float.append(1.2)
+ message.repeated_float.sort()
+ self.assertAlmostEqual(message.repeated_float[0], 1.1)
+ self.assertAlmostEqual(message.repeated_float[1], 1.2)
+ self.assertAlmostEqual(message.repeated_float[2], 1.3)
+
+ message.repeated_string.append('a')
+ message.repeated_string.append('c')
+ message.repeated_string.append('b')
+ message.repeated_string.sort()
+ self.assertEqual(message.repeated_string[0], 'a')
+ self.assertEqual(message.repeated_string[1], 'b')
+ self.assertEqual(message.repeated_string[2], 'c')
+
+ message.repeated_bytes.append('a')
+ message.repeated_bytes.append('c')
+ message.repeated_bytes.append('b')
+ message.repeated_bytes.sort()
+ self.assertEqual(message.repeated_bytes[0], 'a')
+ self.assertEqual(message.repeated_bytes[1], 'b')
+ self.assertEqual(message.repeated_bytes[2], 'c')
+
+ def testSortingRepeatedScalarFieldsCustomComparator(self):
+ """Check some different types with custom comparator."""
+ message = unittest_pb2.TestAllTypes()
+
+ message.repeated_int32.append(-3)
+ message.repeated_int32.append(-2)
+ message.repeated_int32.append(-1)
+ message.repeated_int32.sort(lambda x,y: cmp(abs(x), abs(y)))
+ self.assertEqual(message.repeated_int32[0], -1)
+ self.assertEqual(message.repeated_int32[1], -2)
+ self.assertEqual(message.repeated_int32[2], -3)
+
+ message.repeated_string.append('aaa')
+ message.repeated_string.append('bb')
+ message.repeated_string.append('c')
+ message.repeated_string.sort(lambda x,y: cmp(len(x), len(y)))
+ self.assertEqual(message.repeated_string[0], 'c')
+ self.assertEqual(message.repeated_string[1], 'bb')
+ self.assertEqual(message.repeated_string[2], 'aaa')
+
+ def testSortingRepeatedCompositeFieldsCustomComparator(self):
+ """Check passing a custom comparator to sort a repeated composite field."""
+ message = unittest_pb2.TestAllTypes()
+
+ message.repeated_nested_message.add().bb = 1
+ message.repeated_nested_message.add().bb = 3
+ message.repeated_nested_message.add().bb = 2
+ message.repeated_nested_message.add().bb = 6
+ message.repeated_nested_message.add().bb = 5
+ message.repeated_nested_message.add().bb = 4
+ message.repeated_nested_message.sort(lambda x,y: cmp(x.bb, y.bb))
+ self.assertEqual(message.repeated_nested_message[0].bb, 1)
+ self.assertEqual(message.repeated_nested_message[1].bb, 2)
+ self.assertEqual(message.repeated_nested_message[2].bb, 3)
+ self.assertEqual(message.repeated_nested_message[3].bb, 4)
+ self.assertEqual(message.repeated_nested_message[4].bb, 5)
+ self.assertEqual(message.repeated_nested_message[5].bb, 6)
+
+ def testRepeatedCompositeFieldSortArguments(self):
+ """Check sorting a repeated composite field using list.sort() arguments."""
+ message = unittest_pb2.TestAllTypes()
+
+ get_bb = operator.attrgetter('bb')
+ cmp_bb = lambda a, b: cmp(a.bb, b.bb)
+ message.repeated_nested_message.add().bb = 1
+ message.repeated_nested_message.add().bb = 3
+ message.repeated_nested_message.add().bb = 2
+ message.repeated_nested_message.add().bb = 6
+ message.repeated_nested_message.add().bb = 5
+ message.repeated_nested_message.add().bb = 4
+ message.repeated_nested_message.sort(key=get_bb)
+ self.assertEqual([k.bb for k in message.repeated_nested_message],
+ [1, 2, 3, 4, 5, 6])
+ message.repeated_nested_message.sort(key=get_bb, reverse=True)
+ self.assertEqual([k.bb for k in message.repeated_nested_message],
+ [6, 5, 4, 3, 2, 1])
+ message.repeated_nested_message.sort(sort_function=cmp_bb)
+ self.assertEqual([k.bb for k in message.repeated_nested_message],
+ [1, 2, 3, 4, 5, 6])
+ message.repeated_nested_message.sort(cmp=cmp_bb, reverse=True)
+ self.assertEqual([k.bb for k in message.repeated_nested_message],
+ [6, 5, 4, 3, 2, 1])
+
+ def testRepeatedScalarFieldSortArguments(self):
+ """Check sorting a scalar field using list.sort() arguments."""
+ message = unittest_pb2.TestAllTypes()
+
+ abs_cmp = lambda a, b: cmp(abs(a), abs(b))
+ message.repeated_int32.append(-3)
+ message.repeated_int32.append(-2)
+ message.repeated_int32.append(-1)
+ message.repeated_int32.sort(key=abs)
+ self.assertEqual(list(message.repeated_int32), [-1, -2, -3])
+ message.repeated_int32.sort(key=abs, reverse=True)
+ self.assertEqual(list(message.repeated_int32), [-3, -2, -1])
+ message.repeated_int32.sort(sort_function=abs_cmp)
+ self.assertEqual(list(message.repeated_int32), [-1, -2, -3])
+ message.repeated_int32.sort(cmp=abs_cmp, reverse=True)
+ self.assertEqual(list(message.repeated_int32), [-3, -2, -1])
+
+ len_cmp = lambda a, b: cmp(len(a), len(b))
+ message.repeated_string.append('aaa')
+ message.repeated_string.append('bb')
+ message.repeated_string.append('c')
+ message.repeated_string.sort(key=len)
+ self.assertEqual(list(message.repeated_string), ['c', 'bb', 'aaa'])
+ message.repeated_string.sort(key=len, reverse=True)
+ self.assertEqual(list(message.repeated_string), ['aaa', 'bb', 'c'])
+ message.repeated_string.sort(sort_function=len_cmp)
+ self.assertEqual(list(message.repeated_string), ['c', 'bb', 'aaa'])
+ message.repeated_string.sort(cmp=len_cmp, reverse=True)
+ self.assertEqual(list(message.repeated_string), ['aaa', 'bb', 'c'])
+
+ def testParsingMerge(self):
+ """Check the merge behavior when a required or optional field appears
+ multiple times in the input."""
+ messages = [
+ unittest_pb2.TestAllTypes(),
+ unittest_pb2.TestAllTypes(),
+ unittest_pb2.TestAllTypes() ]
+ messages[0].optional_int32 = 1
+ messages[1].optional_int64 = 2
+ messages[2].optional_int32 = 3
+ messages[2].optional_string = 'hello'
+
+ merged_message = unittest_pb2.TestAllTypes()
+ merged_message.optional_int32 = 3
+ merged_message.optional_int64 = 2
+ merged_message.optional_string = 'hello'
+
+ generator = unittest_pb2.TestParsingMerge.RepeatedFieldsGenerator()
+ generator.field1.extend(messages)
+ generator.field2.extend(messages)
+ generator.field3.extend(messages)
+ generator.ext1.extend(messages)
+ generator.ext2.extend(messages)
+ generator.group1.add().field1.MergeFrom(messages[0])
+ generator.group1.add().field1.MergeFrom(messages[1])
+ generator.group1.add().field1.MergeFrom(messages[2])
+ generator.group2.add().field1.MergeFrom(messages[0])
+ generator.group2.add().field1.MergeFrom(messages[1])
+ generator.group2.add().field1.MergeFrom(messages[2])
+
+ data = generator.SerializeToString()
+ parsing_merge = unittest_pb2.TestParsingMerge()
+ parsing_merge.ParseFromString(data)
+
+ # Required and optional fields should be merged.
+ self.assertEqual(parsing_merge.required_all_types, merged_message)
+ self.assertEqual(parsing_merge.optional_all_types, merged_message)
+ self.assertEqual(parsing_merge.optionalgroup.optional_group_all_types,
+ merged_message)
+ self.assertEqual(parsing_merge.Extensions[
+ unittest_pb2.TestParsingMerge.optional_ext],
+ merged_message)
+
+ # Repeated fields should not be merged.
+ self.assertEqual(len(parsing_merge.repeated_all_types), 3)
+ self.assertEqual(len(parsing_merge.repeatedgroup), 3)
+ self.assertEqual(len(parsing_merge.Extensions[
+ unittest_pb2.TestParsingMerge.repeated_ext]), 3)
+
+
+ def testSortEmptyRepeatedCompositeContainer(self):
+ """Exercise a scenario that has led to segfaults in the past.
+ """
+ m = unittest_pb2.TestAllTypes()
+ m.repeated_nested_message.sort()
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/service_reflection_test.py b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/service_reflection_test.py
new file mode 100755
index 0000000000..e04f8252c0
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/service_reflection_test.py
@@ -0,0 +1,136 @@
+#! /usr/bin/python
+#
+# Protocol Buffers - Google's data interchange format
+# Copyright 2008 Google Inc. All rights reserved.
+# http://code.google.com/p/protobuf/
+#
+# 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.
+
+"""Tests for google.protobuf.internal.service_reflection."""
+
+__author__ = 'petar@google.com (Petar Petrov)'
+
+import unittest
+from google.protobuf import unittest_pb2
+from google.protobuf import service_reflection
+from google.protobuf import service
+
+
+class FooUnitTest(unittest.TestCase):
+
+ def testService(self):
+ class MockRpcChannel(service.RpcChannel):
+ def CallMethod(self, method, controller, request, response, callback):
+ self.method = method
+ self.controller = controller
+ self.request = request
+ callback(response)
+
+ class MockRpcController(service.RpcController):
+ def SetFailed(self, msg):
+ self.failure_message = msg
+
+ self.callback_response = None
+
+ class MyService(unittest_pb2.TestService):
+ pass
+
+ self.callback_response = None
+
+ def MyCallback(response):
+ self.callback_response = response
+
+ rpc_controller = MockRpcController()
+ channel = MockRpcChannel()
+ srvc = MyService()
+ srvc.Foo(rpc_controller, unittest_pb2.FooRequest(), MyCallback)
+ self.assertEqual('Method Foo not implemented.',
+ rpc_controller.failure_message)
+ self.assertEqual(None, self.callback_response)
+
+ rpc_controller.failure_message = None
+
+ service_descriptor = unittest_pb2.TestService.GetDescriptor()
+ srvc.CallMethod(service_descriptor.methods[1], rpc_controller,
+ unittest_pb2.BarRequest(), MyCallback)
+ self.assertEqual('Method Bar not implemented.',
+ rpc_controller.failure_message)
+ self.assertEqual(None, self.callback_response)
+
+ class MyServiceImpl(unittest_pb2.TestService):
+ def Foo(self, rpc_controller, request, done):
+ self.foo_called = True
+ def Bar(self, rpc_controller, request, done):
+ self.bar_called = True
+
+ srvc = MyServiceImpl()
+ rpc_controller.failure_message = None
+ srvc.Foo(rpc_controller, unittest_pb2.FooRequest(), MyCallback)
+ self.assertEqual(None, rpc_controller.failure_message)
+ self.assertEqual(True, srvc.foo_called)
+
+ rpc_controller.failure_message = None
+ srvc.CallMethod(service_descriptor.methods[1], rpc_controller,
+ unittest_pb2.BarRequest(), MyCallback)
+ self.assertEqual(None, rpc_controller.failure_message)
+ self.assertEqual(True, srvc.bar_called)
+
+ def testServiceStub(self):
+ class MockRpcChannel(service.RpcChannel):
+ def CallMethod(self, method, controller, request,
+ response_class, callback):
+ self.method = method
+ self.controller = controller
+ self.request = request
+ callback(response_class())
+
+ self.callback_response = None
+
+ def MyCallback(response):
+ self.callback_response = response
+
+ channel = MockRpcChannel()
+ stub = unittest_pb2.TestService_Stub(channel)
+ rpc_controller = 'controller'
+ request = 'request'
+
+ # GetDescriptor now static, still works as instance method for compatability
+ self.assertEqual(unittest_pb2.TestService_Stub.GetDescriptor(),
+ stub.GetDescriptor())
+
+ # Invoke method.
+ stub.Foo(rpc_controller, request, MyCallback)
+
+ self.assertTrue(isinstance(self.callback_response,
+ unittest_pb2.FooResponse))
+ self.assertEqual(request, channel.request)
+ self.assertEqual(rpc_controller, channel.controller)
+ self.assertEqual(stub.GetDescriptor().methods[0], channel.method)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/test_util.py b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/test_util.py
new file mode 100755
index 0000000000..e2c9db0377
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/test_util.py
@@ -0,0 +1,651 @@
+# Protocol Buffers - Google's data interchange format
+# Copyright 2008 Google Inc. All rights reserved.
+# http://code.google.com/p/protobuf/
+#
+# 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.
+
+"""Utilities for Python proto2 tests.
+
+This is intentionally modeled on C++ code in
+//google/protobuf/test_util.*.
+"""
+
+__author__ = 'robinson@google.com (Will Robinson)'
+
+import os.path
+
+from google.protobuf import unittest_import_pb2
+from google.protobuf import unittest_pb2
+
+
+def SetAllNonLazyFields(message):
+ """Sets every non-lazy field in the message to a unique value.
+
+ Args:
+ message: A unittest_pb2.TestAllTypes instance.
+ """
+
+ #
+ # Optional fields.
+ #
+
+ message.optional_int32 = 101
+ message.optional_int64 = 102
+ message.optional_uint32 = 103
+ message.optional_uint64 = 104
+ message.optional_sint32 = 105
+ message.optional_sint64 = 106
+ message.optional_fixed32 = 107
+ message.optional_fixed64 = 108
+ message.optional_sfixed32 = 109
+ message.optional_sfixed64 = 110
+ message.optional_float = 111
+ message.optional_double = 112
+ message.optional_bool = True
+ # TODO(robinson): Firmly spec out and test how
+ # protos interact with unicode. One specific example:
+ # what happens if we change the literal below to
+ # u'115'? What *should* happen? Still some discussion
+ # to finish with Kenton about bytes vs. strings
+ # and forcing everything to be utf8. :-/
+ message.optional_string = '115'
+ message.optional_bytes = '116'
+
+ message.optionalgroup.a = 117
+ message.optional_nested_message.bb = 118
+ message.optional_foreign_message.c = 119
+ message.optional_import_message.d = 120
+ message.optional_public_import_message.e = 126
+
+ message.optional_nested_enum = unittest_pb2.TestAllTypes.BAZ
+ message.optional_foreign_enum = unittest_pb2.FOREIGN_BAZ
+ message.optional_import_enum = unittest_import_pb2.IMPORT_BAZ
+
+ message.optional_string_piece = '124'
+ message.optional_cord = '125'
+
+ #
+ # Repeated fields.
+ #
+
+ message.repeated_int32.append(201)
+ message.repeated_int64.append(202)
+ message.repeated_uint32.append(203)
+ message.repeated_uint64.append(204)
+ message.repeated_sint32.append(205)
+ message.repeated_sint64.append(206)
+ message.repeated_fixed32.append(207)
+ message.repeated_fixed64.append(208)
+ message.repeated_sfixed32.append(209)
+ message.repeated_sfixed64.append(210)
+ message.repeated_float.append(211)
+ message.repeated_double.append(212)
+ message.repeated_bool.append(True)
+ message.repeated_string.append('215')
+ message.repeated_bytes.append('216')
+
+ message.repeatedgroup.add().a = 217
+ message.repeated_nested_message.add().bb = 218
+ message.repeated_foreign_message.add().c = 219
+ message.repeated_import_message.add().d = 220
+ message.repeated_lazy_message.add().bb = 227
+
+ message.repeated_nested_enum.append(unittest_pb2.TestAllTypes.BAR)
+ message.repeated_foreign_enum.append(unittest_pb2.FOREIGN_BAR)
+ message.repeated_import_enum.append(unittest_import_pb2.IMPORT_BAR)
+
+ message.repeated_string_piece.append('224')
+ message.repeated_cord.append('225')
+
+ # Add a second one of each field.
+ message.repeated_int32.append(301)
+ message.repeated_int64.append(302)
+ message.repeated_uint32.append(303)
+ message.repeated_uint64.append(304)
+ message.repeated_sint32.append(305)
+ message.repeated_sint64.append(306)
+ message.repeated_fixed32.append(307)
+ message.repeated_fixed64.append(308)
+ message.repeated_sfixed32.append(309)
+ message.repeated_sfixed64.append(310)
+ message.repeated_float.append(311)
+ message.repeated_double.append(312)
+ message.repeated_bool.append(False)
+ message.repeated_string.append('315')
+ message.repeated_bytes.append('316')
+
+ message.repeatedgroup.add().a = 317
+ message.repeated_nested_message.add().bb = 318
+ message.repeated_foreign_message.add().c = 319
+ message.repeated_import_message.add().d = 320
+ message.repeated_lazy_message.add().bb = 327
+
+ message.repeated_nested_enum.append(unittest_pb2.TestAllTypes.BAZ)
+ message.repeated_foreign_enum.append(unittest_pb2.FOREIGN_BAZ)
+ message.repeated_import_enum.append(unittest_import_pb2.IMPORT_BAZ)
+
+ message.repeated_string_piece.append('324')
+ message.repeated_cord.append('325')
+
+ #
+ # Fields that have defaults.
+ #
+
+ message.default_int32 = 401
+ message.default_int64 = 402
+ message.default_uint32 = 403
+ message.default_uint64 = 404
+ message.default_sint32 = 405
+ message.default_sint64 = 406
+ message.default_fixed32 = 407
+ message.default_fixed64 = 408
+ message.default_sfixed32 = 409
+ message.default_sfixed64 = 410
+ message.default_float = 411
+ message.default_double = 412
+ message.default_bool = False
+ message.default_string = '415'
+ message.default_bytes = '416'
+
+ message.default_nested_enum = unittest_pb2.TestAllTypes.FOO
+ message.default_foreign_enum = unittest_pb2.FOREIGN_FOO
+ message.default_import_enum = unittest_import_pb2.IMPORT_FOO
+
+ message.default_string_piece = '424'
+ message.default_cord = '425'
+
+
+def SetAllFields(message):
+ SetAllNonLazyFields(message)
+ message.optional_lazy_message.bb = 127
+
+
+def SetAllExtensions(message):
+ """Sets every extension in the message to a unique value.
+
+ Args:
+ message: A unittest_pb2.TestAllExtensions instance.
+ """
+
+ extensions = message.Extensions
+ pb2 = unittest_pb2
+ import_pb2 = unittest_import_pb2
+
+ #
+ # Optional fields.
+ #
+
+ extensions[pb2.optional_int32_extension] = 101
+ extensions[pb2.optional_int64_extension] = 102
+ extensions[pb2.optional_uint32_extension] = 103
+ extensions[pb2.optional_uint64_extension] = 104
+ extensions[pb2.optional_sint32_extension] = 105
+ extensions[pb2.optional_sint64_extension] = 106
+ extensions[pb2.optional_fixed32_extension] = 107
+ extensions[pb2.optional_fixed64_extension] = 108
+ extensions[pb2.optional_sfixed32_extension] = 109
+ extensions[pb2.optional_sfixed64_extension] = 110
+ extensions[pb2.optional_float_extension] = 111
+ extensions[pb2.optional_double_extension] = 112
+ extensions[pb2.optional_bool_extension] = True
+ extensions[pb2.optional_string_extension] = '115'
+ extensions[pb2.optional_bytes_extension] = '116'
+
+ extensions[pb2.optionalgroup_extension].a = 117
+ extensions[pb2.optional_nested_message_extension].bb = 118
+ extensions[pb2.optional_foreign_message_extension].c = 119
+ extensions[pb2.optional_import_message_extension].d = 120
+ extensions[pb2.optional_public_import_message_extension].e = 126
+ extensions[pb2.optional_lazy_message_extension].bb = 127
+
+ extensions[pb2.optional_nested_enum_extension] = pb2.TestAllTypes.BAZ
+ extensions[pb2.optional_nested_enum_extension] = pb2.TestAllTypes.BAZ
+ extensions[pb2.optional_foreign_enum_extension] = pb2.FOREIGN_BAZ
+ extensions[pb2.optional_import_enum_extension] = import_pb2.IMPORT_BAZ
+
+ extensions[pb2.optional_string_piece_extension] = '124'
+ extensions[pb2.optional_cord_extension] = '125'
+
+ #
+ # Repeated fields.
+ #
+
+ extensions[pb2.repeated_int32_extension].append(201)
+ extensions[pb2.repeated_int64_extension].append(202)
+ extensions[pb2.repeated_uint32_extension].append(203)
+ extensions[pb2.repeated_uint64_extension].append(204)
+ extensions[pb2.repeated_sint32_extension].append(205)
+ extensions[pb2.repeated_sint64_extension].append(206)
+ extensions[pb2.repeated_fixed32_extension].append(207)
+ extensions[pb2.repeated_fixed64_extension].append(208)
+ extensions[pb2.repeated_sfixed32_extension].append(209)
+ extensions[pb2.repeated_sfixed64_extension].append(210)
+ extensions[pb2.repeated_float_extension].append(211)
+ extensions[pb2.repeated_double_extension].append(212)
+ extensions[pb2.repeated_bool_extension].append(True)
+ extensions[pb2.repeated_string_extension].append('215')
+ extensions[pb2.repeated_bytes_extension].append('216')
+
+ extensions[pb2.repeatedgroup_extension].add().a = 217
+ extensions[pb2.repeated_nested_message_extension].add().bb = 218
+ extensions[pb2.repeated_foreign_message_extension].add().c = 219
+ extensions[pb2.repeated_import_message_extension].add().d = 220
+ extensions[pb2.repeated_lazy_message_extension].add().bb = 227
+
+ extensions[pb2.repeated_nested_enum_extension].append(pb2.TestAllTypes.BAR)
+ extensions[pb2.repeated_foreign_enum_extension].append(pb2.FOREIGN_BAR)
+ extensions[pb2.repeated_import_enum_extension].append(import_pb2.IMPORT_BAR)
+
+ extensions[pb2.repeated_string_piece_extension].append('224')
+ extensions[pb2.repeated_cord_extension].append('225')
+
+ # Append a second one of each field.
+ extensions[pb2.repeated_int32_extension].append(301)
+ extensions[pb2.repeated_int64_extension].append(302)
+ extensions[pb2.repeated_uint32_extension].append(303)
+ extensions[pb2.repeated_uint64_extension].append(304)
+ extensions[pb2.repeated_sint32_extension].append(305)
+ extensions[pb2.repeated_sint64_extension].append(306)
+ extensions[pb2.repeated_fixed32_extension].append(307)
+ extensions[pb2.repeated_fixed64_extension].append(308)
+ extensions[pb2.repeated_sfixed32_extension].append(309)
+ extensions[pb2.repeated_sfixed64_extension].append(310)
+ extensions[pb2.repeated_float_extension].append(311)
+ extensions[pb2.repeated_double_extension].append(312)
+ extensions[pb2.repeated_bool_extension].append(False)
+ extensions[pb2.repeated_string_extension].append('315')
+ extensions[pb2.repeated_bytes_extension].append('316')
+
+ extensions[pb2.repeatedgroup_extension].add().a = 317
+ extensions[pb2.repeated_nested_message_extension].add().bb = 318
+ extensions[pb2.repeated_foreign_message_extension].add().c = 319
+ extensions[pb2.repeated_import_message_extension].add().d = 320
+ extensions[pb2.repeated_lazy_message_extension].add().bb = 327
+
+ extensions[pb2.repeated_nested_enum_extension].append(pb2.TestAllTypes.BAZ)
+ extensions[pb2.repeated_foreign_enum_extension].append(pb2.FOREIGN_BAZ)
+ extensions[pb2.repeated_import_enum_extension].append(import_pb2.IMPORT_BAZ)
+
+ extensions[pb2.repeated_string_piece_extension].append('324')
+ extensions[pb2.repeated_cord_extension].append('325')
+
+ #
+ # Fields with defaults.
+ #
+
+ extensions[pb2.default_int32_extension] = 401
+ extensions[pb2.default_int64_extension] = 402
+ extensions[pb2.default_uint32_extension] = 403
+ extensions[pb2.default_uint64_extension] = 404
+ extensions[pb2.default_sint32_extension] = 405
+ extensions[pb2.default_sint64_extension] = 406
+ extensions[pb2.default_fixed32_extension] = 407
+ extensions[pb2.default_fixed64_extension] = 408
+ extensions[pb2.default_sfixed32_extension] = 409
+ extensions[pb2.default_sfixed64_extension] = 410
+ extensions[pb2.default_float_extension] = 411
+ extensions[pb2.default_double_extension] = 412
+ extensions[pb2.default_bool_extension] = False
+ extensions[pb2.default_string_extension] = '415'
+ extensions[pb2.default_bytes_extension] = '416'
+
+ extensions[pb2.default_nested_enum_extension] = pb2.TestAllTypes.FOO
+ extensions[pb2.default_foreign_enum_extension] = pb2.FOREIGN_FOO
+ extensions[pb2.default_import_enum_extension] = import_pb2.IMPORT_FOO
+
+ extensions[pb2.default_string_piece_extension] = '424'
+ extensions[pb2.default_cord_extension] = '425'
+
+
+def SetAllFieldsAndExtensions(message):
+ """Sets every field and extension in the message to a unique value.
+
+ Args:
+ message: A unittest_pb2.TestAllExtensions message.
+ """
+ message.my_int = 1
+ message.my_string = 'foo'
+ message.my_float = 1.0
+ message.Extensions[unittest_pb2.my_extension_int] = 23
+ message.Extensions[unittest_pb2.my_extension_string] = 'bar'
+
+
+def ExpectAllFieldsAndExtensionsInOrder(serialized):
+ """Ensures that serialized is the serialization we expect for a message
+ filled with SetAllFieldsAndExtensions(). (Specifically, ensures that the
+ serialization is in canonical, tag-number order).
+ """
+ my_extension_int = unittest_pb2.my_extension_int
+ my_extension_string = unittest_pb2.my_extension_string
+ expected_strings = []
+ message = unittest_pb2.TestFieldOrderings()
+ message.my_int = 1 # Field 1.
+ expected_strings.append(message.SerializeToString())
+ message.Clear()
+ message.Extensions[my_extension_int] = 23 # Field 5.
+ expected_strings.append(message.SerializeToString())
+ message.Clear()
+ message.my_string = 'foo' # Field 11.
+ expected_strings.append(message.SerializeToString())
+ message.Clear()
+ message.Extensions[my_extension_string] = 'bar' # Field 50.
+ expected_strings.append(message.SerializeToString())
+ message.Clear()
+ message.my_float = 1.0
+ expected_strings.append(message.SerializeToString())
+ message.Clear()
+ expected = ''.join(expected_strings)
+
+ if expected != serialized:
+ raise ValueError('Expected %r, found %r' % (expected, serialized))
+
+
+def ExpectAllFieldsSet(test_case, message):
+ """Check all fields for correct values have after Set*Fields() is called."""
+ test_case.assertTrue(message.HasField('optional_int32'))
+ test_case.assertTrue(message.HasField('optional_int64'))
+ test_case.assertTrue(message.HasField('optional_uint32'))
+ test_case.assertTrue(message.HasField('optional_uint64'))
+ test_case.assertTrue(message.HasField('optional_sint32'))
+ test_case.assertTrue(message.HasField('optional_sint64'))
+ test_case.assertTrue(message.HasField('optional_fixed32'))
+ test_case.assertTrue(message.HasField('optional_fixed64'))
+ test_case.assertTrue(message.HasField('optional_sfixed32'))
+ test_case.assertTrue(message.HasField('optional_sfixed64'))
+ test_case.assertTrue(message.HasField('optional_float'))
+ test_case.assertTrue(message.HasField('optional_double'))
+ test_case.assertTrue(message.HasField('optional_bool'))
+ test_case.assertTrue(message.HasField('optional_string'))
+ test_case.assertTrue(message.HasField('optional_bytes'))
+
+ test_case.assertTrue(message.HasField('optionalgroup'))
+ test_case.assertTrue(message.HasField('optional_nested_message'))
+ test_case.assertTrue(message.HasField('optional_foreign_message'))
+ test_case.assertTrue(message.HasField('optional_import_message'))
+
+ test_case.assertTrue(message.optionalgroup.HasField('a'))
+ test_case.assertTrue(message.optional_nested_message.HasField('bb'))
+ test_case.assertTrue(message.optional_foreign_message.HasField('c'))
+ test_case.assertTrue(message.optional_import_message.HasField('d'))
+
+ test_case.assertTrue(message.HasField('optional_nested_enum'))
+ test_case.assertTrue(message.HasField('optional_foreign_enum'))
+ test_case.assertTrue(message.HasField('optional_import_enum'))
+
+ test_case.assertTrue(message.HasField('optional_string_piece'))
+ test_case.assertTrue(message.HasField('optional_cord'))
+
+ test_case.assertEqual(101, message.optional_int32)
+ test_case.assertEqual(102, message.optional_int64)
+ test_case.assertEqual(103, message.optional_uint32)
+ test_case.assertEqual(104, message.optional_uint64)
+ test_case.assertEqual(105, message.optional_sint32)
+ test_case.assertEqual(106, message.optional_sint64)
+ test_case.assertEqual(107, message.optional_fixed32)
+ test_case.assertEqual(108, message.optional_fixed64)
+ test_case.assertEqual(109, message.optional_sfixed32)
+ test_case.assertEqual(110, message.optional_sfixed64)
+ test_case.assertEqual(111, message.optional_float)
+ test_case.assertEqual(112, message.optional_double)
+ test_case.assertEqual(True, message.optional_bool)
+ test_case.assertEqual('115', message.optional_string)
+ test_case.assertEqual('116', message.optional_bytes)
+
+ test_case.assertEqual(117, message.optionalgroup.a)
+ test_case.assertEqual(118, message.optional_nested_message.bb)
+ test_case.assertEqual(119, message.optional_foreign_message.c)
+ test_case.assertEqual(120, message.optional_import_message.d)
+ test_case.assertEqual(126, message.optional_public_import_message.e)
+ test_case.assertEqual(127, message.optional_lazy_message.bb)
+
+ test_case.assertEqual(unittest_pb2.TestAllTypes.BAZ,
+ message.optional_nested_enum)
+ test_case.assertEqual(unittest_pb2.FOREIGN_BAZ,
+ message.optional_foreign_enum)
+ test_case.assertEqual(unittest_import_pb2.IMPORT_BAZ,
+ message.optional_import_enum)
+
+ # -----------------------------------------------------------------
+
+ test_case.assertEqual(2, len(message.repeated_int32))
+ test_case.assertEqual(2, len(message.repeated_int64))
+ test_case.assertEqual(2, len(message.repeated_uint32))
+ test_case.assertEqual(2, len(message.repeated_uint64))
+ test_case.assertEqual(2, len(message.repeated_sint32))
+ test_case.assertEqual(2, len(message.repeated_sint64))
+ test_case.assertEqual(2, len(message.repeated_fixed32))
+ test_case.assertEqual(2, len(message.repeated_fixed64))
+ test_case.assertEqual(2, len(message.repeated_sfixed32))
+ test_case.assertEqual(2, len(message.repeated_sfixed64))
+ test_case.assertEqual(2, len(message.repeated_float))
+ test_case.assertEqual(2, len(message.repeated_double))
+ test_case.assertEqual(2, len(message.repeated_bool))
+ test_case.assertEqual(2, len(message.repeated_string))
+ test_case.assertEqual(2, len(message.repeated_bytes))
+
+ test_case.assertEqual(2, len(message.repeatedgroup))
+ test_case.assertEqual(2, len(message.repeated_nested_message))
+ test_case.assertEqual(2, len(message.repeated_foreign_message))
+ test_case.assertEqual(2, len(message.repeated_import_message))
+ test_case.assertEqual(2, len(message.repeated_nested_enum))
+ test_case.assertEqual(2, len(message.repeated_foreign_enum))
+ test_case.assertEqual(2, len(message.repeated_import_enum))
+
+ test_case.assertEqual(2, len(message.repeated_string_piece))
+ test_case.assertEqual(2, len(message.repeated_cord))
+
+ test_case.assertEqual(201, message.repeated_int32[0])
+ test_case.assertEqual(202, message.repeated_int64[0])
+ test_case.assertEqual(203, message.repeated_uint32[0])
+ test_case.assertEqual(204, message.repeated_uint64[0])
+ test_case.assertEqual(205, message.repeated_sint32[0])
+ test_case.assertEqual(206, message.repeated_sint64[0])
+ test_case.assertEqual(207, message.repeated_fixed32[0])
+ test_case.assertEqual(208, message.repeated_fixed64[0])
+ test_case.assertEqual(209, message.repeated_sfixed32[0])
+ test_case.assertEqual(210, message.repeated_sfixed64[0])
+ test_case.assertEqual(211, message.repeated_float[0])
+ test_case.assertEqual(212, message.repeated_double[0])
+ test_case.assertEqual(True, message.repeated_bool[0])
+ test_case.assertEqual('215', message.repeated_string[0])
+ test_case.assertEqual('216', message.repeated_bytes[0])
+
+ test_case.assertEqual(217, message.repeatedgroup[0].a)
+ test_case.assertEqual(218, message.repeated_nested_message[0].bb)
+ test_case.assertEqual(219, message.repeated_foreign_message[0].c)
+ test_case.assertEqual(220, message.repeated_import_message[0].d)
+ test_case.assertEqual(227, message.repeated_lazy_message[0].bb)
+
+ test_case.assertEqual(unittest_pb2.TestAllTypes.BAR,
+ message.repeated_nested_enum[0])
+ test_case.assertEqual(unittest_pb2.FOREIGN_BAR,
+ message.repeated_foreign_enum[0])
+ test_case.assertEqual(unittest_import_pb2.IMPORT_BAR,
+ message.repeated_import_enum[0])
+
+ test_case.assertEqual(301, message.repeated_int32[1])
+ test_case.assertEqual(302, message.repeated_int64[1])
+ test_case.assertEqual(303, message.repeated_uint32[1])
+ test_case.assertEqual(304, message.repeated_uint64[1])
+ test_case.assertEqual(305, message.repeated_sint32[1])
+ test_case.assertEqual(306, message.repeated_sint64[1])
+ test_case.assertEqual(307, message.repeated_fixed32[1])
+ test_case.assertEqual(308, message.repeated_fixed64[1])
+ test_case.assertEqual(309, message.repeated_sfixed32[1])
+ test_case.assertEqual(310, message.repeated_sfixed64[1])
+ test_case.assertEqual(311, message.repeated_float[1])
+ test_case.assertEqual(312, message.repeated_double[1])
+ test_case.assertEqual(False, message.repeated_bool[1])
+ test_case.assertEqual('315', message.repeated_string[1])
+ test_case.assertEqual('316', message.repeated_bytes[1])
+
+ test_case.assertEqual(317, message.repeatedgroup[1].a)
+ test_case.assertEqual(318, message.repeated_nested_message[1].bb)
+ test_case.assertEqual(319, message.repeated_foreign_message[1].c)
+ test_case.assertEqual(320, message.repeated_import_message[1].d)
+ test_case.assertEqual(327, message.repeated_lazy_message[1].bb)
+
+ test_case.assertEqual(unittest_pb2.TestAllTypes.BAZ,
+ message.repeated_nested_enum[1])
+ test_case.assertEqual(unittest_pb2.FOREIGN_BAZ,
+ message.repeated_foreign_enum[1])
+ test_case.assertEqual(unittest_import_pb2.IMPORT_BAZ,
+ message.repeated_import_enum[1])
+
+ # -----------------------------------------------------------------
+
+ test_case.assertTrue(message.HasField('default_int32'))
+ test_case.assertTrue(message.HasField('default_int64'))
+ test_case.assertTrue(message.HasField('default_uint32'))
+ test_case.assertTrue(message.HasField('default_uint64'))
+ test_case.assertTrue(message.HasField('default_sint32'))
+ test_case.assertTrue(message.HasField('default_sint64'))
+ test_case.assertTrue(message.HasField('default_fixed32'))
+ test_case.assertTrue(message.HasField('default_fixed64'))
+ test_case.assertTrue(message.HasField('default_sfixed32'))
+ test_case.assertTrue(message.HasField('default_sfixed64'))
+ test_case.assertTrue(message.HasField('default_float'))
+ test_case.assertTrue(message.HasField('default_double'))
+ test_case.assertTrue(message.HasField('default_bool'))
+ test_case.assertTrue(message.HasField('default_string'))
+ test_case.assertTrue(message.HasField('default_bytes'))
+
+ test_case.assertTrue(message.HasField('default_nested_enum'))
+ test_case.assertTrue(message.HasField('default_foreign_enum'))
+ test_case.assertTrue(message.HasField('default_import_enum'))
+
+ test_case.assertEqual(401, message.default_int32)
+ test_case.assertEqual(402, message.default_int64)
+ test_case.assertEqual(403, message.default_uint32)
+ test_case.assertEqual(404, message.default_uint64)
+ test_case.assertEqual(405, message.default_sint32)
+ test_case.assertEqual(406, message.default_sint64)
+ test_case.assertEqual(407, message.default_fixed32)
+ test_case.assertEqual(408, message.default_fixed64)
+ test_case.assertEqual(409, message.default_sfixed32)
+ test_case.assertEqual(410, message.default_sfixed64)
+ test_case.assertEqual(411, message.default_float)
+ test_case.assertEqual(412, message.default_double)
+ test_case.assertEqual(False, message.default_bool)
+ test_case.assertEqual('415', message.default_string)
+ test_case.assertEqual('416', message.default_bytes)
+
+ test_case.assertEqual(unittest_pb2.TestAllTypes.FOO,
+ message.default_nested_enum)
+ test_case.assertEqual(unittest_pb2.FOREIGN_FOO,
+ message.default_foreign_enum)
+ test_case.assertEqual(unittest_import_pb2.IMPORT_FOO,
+ message.default_import_enum)
+
+def GoldenFile(filename):
+ """Finds the given golden file and returns a file object representing it."""
+
+ # Search up the directory tree looking for the C++ protobuf source code.
+ path = '.'
+ while os.path.exists(path):
+ if os.path.exists(os.path.join(path, 'tests/google/protobuf/internal')):
+ # Found it. Load the golden file from the testdata directory.
+ full_path = os.path.join(path, 'tests/google/protobuf/internal', filename)
+ return open(full_path, 'rb')
+ path = os.path.join(path, '..')
+
+ raise RuntimeError(
+ 'Could not find golden files. This test must be run from within the '
+ 'protobuf source package so that it can read test data files from the '
+ 'C++ source tree.')
+
+
+def SetAllPackedFields(message):
+ """Sets every field in the message to a unique value.
+
+ Args:
+ message: A unittest_pb2.TestPackedTypes instance.
+ """
+ message.packed_int32.extend([601, 701])
+ message.packed_int64.extend([602, 702])
+ message.packed_uint32.extend([603, 703])
+ message.packed_uint64.extend([604, 704])
+ message.packed_sint32.extend([605, 705])
+ message.packed_sint64.extend([606, 706])
+ message.packed_fixed32.extend([607, 707])
+ message.packed_fixed64.extend([608, 708])
+ message.packed_sfixed32.extend([609, 709])
+ message.packed_sfixed64.extend([610, 710])
+ message.packed_float.extend([611.0, 711.0])
+ message.packed_double.extend([612.0, 712.0])
+ message.packed_bool.extend([True, False])
+ message.packed_enum.extend([unittest_pb2.FOREIGN_BAR,
+ unittest_pb2.FOREIGN_BAZ])
+
+
+def SetAllPackedExtensions(message):
+ """Sets every extension in the message to a unique value.
+
+ Args:
+ message: A unittest_pb2.TestPackedExtensions instance.
+ """
+ extensions = message.Extensions
+ pb2 = unittest_pb2
+
+ extensions[pb2.packed_int32_extension].extend([601, 701])
+ extensions[pb2.packed_int64_extension].extend([602, 702])
+ extensions[pb2.packed_uint32_extension].extend([603, 703])
+ extensions[pb2.packed_uint64_extension].extend([604, 704])
+ extensions[pb2.packed_sint32_extension].extend([605, 705])
+ extensions[pb2.packed_sint64_extension].extend([606, 706])
+ extensions[pb2.packed_fixed32_extension].extend([607, 707])
+ extensions[pb2.packed_fixed64_extension].extend([608, 708])
+ extensions[pb2.packed_sfixed32_extension].extend([609, 709])
+ extensions[pb2.packed_sfixed64_extension].extend([610, 710])
+ extensions[pb2.packed_float_extension].extend([611.0, 711.0])
+ extensions[pb2.packed_double_extension].extend([612.0, 712.0])
+ extensions[pb2.packed_bool_extension].extend([True, False])
+ extensions[pb2.packed_enum_extension].extend([unittest_pb2.FOREIGN_BAR,
+ unittest_pb2.FOREIGN_BAZ])
+
+
+def SetAllUnpackedFields(message):
+ """Sets every field in the message to a unique value.
+
+ Args:
+ message: A unittest_pb2.TestUnpackedTypes instance.
+ """
+ message.unpacked_int32.extend([601, 701])
+ message.unpacked_int64.extend([602, 702])
+ message.unpacked_uint32.extend([603, 703])
+ message.unpacked_uint64.extend([604, 704])
+ message.unpacked_sint32.extend([605, 705])
+ message.unpacked_sint64.extend([606, 706])
+ message.unpacked_fixed32.extend([607, 707])
+ message.unpacked_fixed64.extend([608, 708])
+ message.unpacked_sfixed32.extend([609, 709])
+ message.unpacked_sfixed64.extend([610, 710])
+ message.unpacked_float.extend([611.0, 711.0])
+ message.unpacked_double.extend([612.0, 712.0])
+ message.unpacked_bool.extend([True, False])
+ message.unpacked_enum.extend([unittest_pb2.FOREIGN_BAR,
+ unittest_pb2.FOREIGN_BAZ])
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/text_format_test.py b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/text_format_test.py
new file mode 100755
index 0000000000..6bf7befb11
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/text_format_test.py
@@ -0,0 +1,620 @@
+#! /usr/bin/python
+#
+# Protocol Buffers - Google's data interchange format
+# Copyright 2008 Google Inc. All rights reserved.
+# http://code.google.com/p/protobuf/
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""Test for google.protobuf.text_format."""
+
+__author__ = 'kenton@google.com (Kenton Varda)'
+
+import difflib
+import re
+
+import unittest
+from google.protobuf import text_format
+from google.protobuf.internal import test_util
+from google.protobuf import unittest_pb2
+from google.protobuf import unittest_mset_pb2
+
+
+class TextFormatTest(unittest.TestCase):
+ def ReadGolden(self, golden_filename):
+ f = test_util.GoldenFile(golden_filename)
+ golden_lines = f.readlines()
+ f.close()
+ return golden_lines
+
+ def CompareToGoldenFile(self, text, golden_filename):
+ golden_lines = self.ReadGolden(golden_filename)
+ self.CompareToGoldenLines(text, golden_lines)
+
+ def CompareToGoldenText(self, text, golden_text):
+ self.CompareToGoldenLines(text, golden_text.splitlines(1))
+
+ def CompareToGoldenLines(self, text, golden_lines):
+ actual_lines = text.splitlines(1)
+ self.assertEqual(golden_lines, actual_lines,
+ "Text doesn't match golden. Diff:\n" +
+ ''.join(difflib.ndiff(golden_lines, actual_lines)))
+
+ def testPrintAllFields(self):
+ message = unittest_pb2.TestAllTypes()
+ test_util.SetAllFields(message)
+ self.CompareToGoldenFile(
+ self.RemoveRedundantZeros(text_format.MessageToString(message)),
+ 'text_format_unittest_data.txt')
+
+ def testPrintAllExtensions(self):
+ message = unittest_pb2.TestAllExtensions()
+ test_util.SetAllExtensions(message)
+ self.CompareToGoldenFile(
+ self.RemoveRedundantZeros(text_format.MessageToString(message)),
+ 'text_format_unittest_extensions_data.txt')
+
+ def testPrintMessageSet(self):
+ message = unittest_mset_pb2.TestMessageSetContainer()
+ ext1 = unittest_mset_pb2.TestMessageSetExtension1.message_set_extension
+ ext2 = unittest_mset_pb2.TestMessageSetExtension2.message_set_extension
+ message.message_set.Extensions[ext1].i = 23
+ message.message_set.Extensions[ext2].str = 'foo'
+ self.CompareToGoldenText(text_format.MessageToString(message),
+ 'message_set {\n'
+ ' [protobuf_unittest.TestMessageSetExtension1] {\n'
+ ' i: 23\n'
+ ' }\n'
+ ' [protobuf_unittest.TestMessageSetExtension2] {\n'
+ ' str: \"foo\"\n'
+ ' }\n'
+ '}\n')
+
+ """
+ def testPrintBadEnumValue(self):
+ message = unittest_pb2.TestAllTypes()
+ message.optional_nested_enum = 100
+ message.optional_foreign_enum = 101
+ message.optional_import_enum = 102
+ self.CompareToGoldenText(
+ text_format.MessageToString(message),
+ 'optional_nested_enum: 100\n'
+ 'optional_foreign_enum: 101\n'
+ 'optional_import_enum: 102\n')
+
+ def testPrintBadEnumValueExtensions(self):
+ message = unittest_pb2.TestAllExtensions()
+ message.Extensions[unittest_pb2.optional_nested_enum_extension] = 100
+ message.Extensions[unittest_pb2.optional_foreign_enum_extension] = 101
+ message.Extensions[unittest_pb2.optional_import_enum_extension] = 102
+ self.CompareToGoldenText(
+ text_format.MessageToString(message),
+ '[protobuf_unittest.optional_nested_enum_extension]: 100\n'
+ '[protobuf_unittest.optional_foreign_enum_extension]: 101\n'
+ '[protobuf_unittest.optional_import_enum_extension]: 102\n')
+ """
+
+ def testPrintExotic(self):
+ message = unittest_pb2.TestAllTypes()
+ message.repeated_int64.append(-9223372036854775808)
+ message.repeated_uint64.append(18446744073709551615)
+ message.repeated_double.append(123.456)
+ message.repeated_double.append(1.23e22)
+ message.repeated_double.append(1.23e-18)
+ message.repeated_string.append('\000\001\a\b\f\n\r\t\v\\\'"')
+ message.repeated_string.append(u'\u00fc\ua71f')
+ self.CompareToGoldenText(
+ self.RemoveRedundantZeros(text_format.MessageToString(message)),
+ 'repeated_int64: -9223372036854775808\n'
+ 'repeated_uint64: 18446744073709551615\n'
+ 'repeated_double: 123.456\n'
+ 'repeated_double: 1.23e+22\n'
+ 'repeated_double: 1.23e-18\n'
+ 'repeated_string: '
+ '"\\000\\001\\007\\010\\014\\n\\r\\t\\013\\\\\\\'\\""\n'
+ 'repeated_string: "\\303\\274\\352\\234\\237"\n')
+
+ def testPrintNestedMessageAsOneLine(self):
+ message = unittest_pb2.TestAllTypes()
+ msg = message.repeated_nested_message.add()
+ msg.bb = 42;
+ self.CompareToGoldenText(
+ text_format.MessageToString(message, as_one_line=True),
+ 'repeated_nested_message { bb: 42 }')
+
+ def testPrintRepeatedFieldsAsOneLine(self):
+ message = unittest_pb2.TestAllTypes()
+ message.repeated_int32.append(1)
+ message.repeated_int32.append(1)
+ message.repeated_int32.append(3)
+ message.repeated_string.append("Google")
+ message.repeated_string.append("Zurich")
+ self.CompareToGoldenText(
+ text_format.MessageToString(message, as_one_line=True),
+ 'repeated_int32: 1 repeated_int32: 1 repeated_int32: 3 '
+ 'repeated_string: "Google" repeated_string: "Zurich"')
+
+ def testPrintNestedNewLineInStringAsOneLine(self):
+ message = unittest_pb2.TestAllTypes()
+ message.optional_string = "a\nnew\nline"
+ self.CompareToGoldenText(
+ text_format.MessageToString(message, as_one_line=True),
+ 'optional_string: "a\\nnew\\nline"')
+
+ def testPrintMessageSetAsOneLine(self):
+ message = unittest_mset_pb2.TestMessageSetContainer()
+ ext1 = unittest_mset_pb2.TestMessageSetExtension1.message_set_extension
+ ext2 = unittest_mset_pb2.TestMessageSetExtension2.message_set_extension
+ message.message_set.Extensions[ext1].i = 23
+ message.message_set.Extensions[ext2].str = 'foo'
+ self.CompareToGoldenText(
+ text_format.MessageToString(message, as_one_line=True),
+ 'message_set {'
+ ' [protobuf_unittest.TestMessageSetExtension1] {'
+ ' i: 23'
+ ' }'
+ ' [protobuf_unittest.TestMessageSetExtension2] {'
+ ' str: \"foo\"'
+ ' }'
+ ' }')
+
+ def testPrintExoticAsOneLine(self):
+ message = unittest_pb2.TestAllTypes()
+ message.repeated_int64.append(-9223372036854775808)
+ message.repeated_uint64.append(18446744073709551615)
+ message.repeated_double.append(123.456)
+ message.repeated_double.append(1.23e22)
+ message.repeated_double.append(1.23e-18)
+ message.repeated_string.append('\000\001\a\b\f\n\r\t\v\\\'"')
+ message.repeated_string.append(u'\u00fc\ua71f')
+ self.CompareToGoldenText(
+ self.RemoveRedundantZeros(
+ text_format.MessageToString(message, as_one_line=True)),
+ 'repeated_int64: -9223372036854775808'
+ ' repeated_uint64: 18446744073709551615'
+ ' repeated_double: 123.456'
+ ' repeated_double: 1.23e+22'
+ ' repeated_double: 1.23e-18'
+ ' repeated_string: '
+ '"\\000\\001\\007\\010\\014\\n\\r\\t\\013\\\\\\\'\\""'
+ ' repeated_string: "\\303\\274\\352\\234\\237"')
+
+ def testRoundTripExoticAsOneLine(self):
+ message = unittest_pb2.TestAllTypes()
+ message.repeated_int64.append(-9223372036854775808)
+ message.repeated_uint64.append(18446744073709551615)
+ message.repeated_double.append(123.456)
+ message.repeated_double.append(1.23e22)
+ message.repeated_double.append(1.23e-18)
+ message.repeated_string.append('\000\001\a\b\f\n\r\t\v\\\'"')
+ message.repeated_string.append(u'\u00fc\ua71f')
+
+ # Test as_utf8 = False.
+ wire_text = text_format.MessageToString(
+ message, as_one_line=True, as_utf8=False)
+ parsed_message = unittest_pb2.TestAllTypes()
+ text_format.Merge(wire_text, parsed_message)
+ self.assertEquals(message, parsed_message)
+
+ # Test as_utf8 = True.
+ wire_text = text_format.MessageToString(
+ message, as_one_line=True, as_utf8=True)
+ parsed_message = unittest_pb2.TestAllTypes()
+ text_format.Merge(wire_text, parsed_message)
+ self.assertEquals(message, parsed_message)
+
+ def testPrintRawUtf8String(self):
+ message = unittest_pb2.TestAllTypes()
+ message.repeated_string.append(u'\u00fc\ua71f')
+ text = text_format.MessageToString(message, as_utf8 = True)
+ self.CompareToGoldenText(text, 'repeated_string: "\303\274\352\234\237"\n')
+ parsed_message = unittest_pb2.TestAllTypes()
+ text_format.Merge(text, parsed_message)
+ self.assertEquals(message, parsed_message)
+
+ def testMessageToString(self):
+ message = unittest_pb2.ForeignMessage()
+ message.c = 123
+ self.assertEqual('c: 123\n', str(message))
+
+ def RemoveRedundantZeros(self, text):
+ # Some platforms print 1e+5 as 1e+005. This is fine, but we need to remove
+ # these zeros in order to match the golden file.
+ text = text.replace('e+0','e+').replace('e+0','e+') \
+ .replace('e-0','e-').replace('e-0','e-')
+ # Floating point fields are printed with .0 suffix even if they are
+ # actualy integer numbers.
+ text = re.compile('\.0$', re.MULTILINE).sub('', text)
+ return text
+
+ def testMergeGolden(self):
+ golden_text = '\n'.join(self.ReadGolden('text_format_unittest_data.txt'))
+ parsed_message = unittest_pb2.TestAllTypes()
+ text_format.Merge(golden_text, parsed_message)
+
+ message = unittest_pb2.TestAllTypes()
+ test_util.SetAllFields(message)
+ self.assertEquals(message, parsed_message)
+
+ def testMergeGoldenExtensions(self):
+ golden_text = '\n'.join(self.ReadGolden(
+ 'text_format_unittest_extensions_data.txt'))
+ parsed_message = unittest_pb2.TestAllExtensions()
+ text_format.Merge(golden_text, parsed_message)
+
+ message = unittest_pb2.TestAllExtensions()
+ test_util.SetAllExtensions(message)
+ self.assertEquals(message, parsed_message)
+
+ def testMergeAllFields(self):
+ message = unittest_pb2.TestAllTypes()
+ test_util.SetAllFields(message)
+ ascii_text = text_format.MessageToString(message)
+
+ parsed_message = unittest_pb2.TestAllTypes()
+ text_format.Merge(ascii_text, parsed_message)
+ self.assertEqual(message, parsed_message)
+ test_util.ExpectAllFieldsSet(self, message)
+
+ def testMergeAllExtensions(self):
+ message = unittest_pb2.TestAllExtensions()
+ test_util.SetAllExtensions(message)
+ ascii_text = text_format.MessageToString(message)
+
+ parsed_message = unittest_pb2.TestAllExtensions()
+ text_format.Merge(ascii_text, parsed_message)
+ self.assertEqual(message, parsed_message)
+
+ def testMergeMessageSet(self):
+ message = unittest_pb2.TestAllTypes()
+ text = ('repeated_uint64: 1\n'
+ 'repeated_uint64: 2\n')
+ text_format.Merge(text, message)
+ self.assertEqual(1, message.repeated_uint64[0])
+ self.assertEqual(2, message.repeated_uint64[1])
+
+ message = unittest_mset_pb2.TestMessageSetContainer()
+ text = ('message_set {\n'
+ ' [protobuf_unittest.TestMessageSetExtension1] {\n'
+ ' i: 23\n'
+ ' }\n'
+ ' [protobuf_unittest.TestMessageSetExtension2] {\n'
+ ' str: \"foo\"\n'
+ ' }\n'
+ '}\n')
+ text_format.Merge(text, message)
+ ext1 = unittest_mset_pb2.TestMessageSetExtension1.message_set_extension
+ ext2 = unittest_mset_pb2.TestMessageSetExtension2.message_set_extension
+ self.assertEquals(23, message.message_set.Extensions[ext1].i)
+ self.assertEquals('foo', message.message_set.Extensions[ext2].str)
+
+ def testMergeExotic(self):
+ message = unittest_pb2.TestAllTypes()
+ text = ('repeated_int64: -9223372036854775808\n'
+ 'repeated_uint64: 18446744073709551615\n'
+ 'repeated_double: 123.456\n'
+ 'repeated_double: 1.23e+22\n'
+ 'repeated_double: 1.23e-18\n'
+ 'repeated_string: \n'
+ '"\\000\\001\\007\\010\\014\\n\\r\\t\\013\\\\\\\'\\""\n'
+ 'repeated_string: "foo" \'corge\' "grault"\n'
+ 'repeated_string: "\\303\\274\\352\\234\\237"\n'
+ 'repeated_string: "\\xc3\\xbc"\n'
+ 'repeated_string: "\xc3\xbc"\n')
+ text_format.Merge(text, message)
+
+ self.assertEqual(-9223372036854775808, message.repeated_int64[0])
+ self.assertEqual(18446744073709551615, message.repeated_uint64[0])
+ self.assertEqual(123.456, message.repeated_double[0])
+ self.assertEqual(1.23e22, message.repeated_double[1])
+ self.assertEqual(1.23e-18, message.repeated_double[2])
+ self.assertEqual(
+ '\000\001\a\b\f\n\r\t\v\\\'"', message.repeated_string[0])
+ self.assertEqual('foocorgegrault', message.repeated_string[1])
+ self.assertEqual(u'\u00fc\ua71f', message.repeated_string[2])
+ self.assertEqual(u'\u00fc', message.repeated_string[3])
+
+ def testMergeEmptyText(self):
+ message = unittest_pb2.TestAllTypes()
+ text = ''
+ text_format.Merge(text, message)
+ self.assertEquals(unittest_pb2.TestAllTypes(), message)
+
+ def testMergeInvalidUtf8(self):
+ message = unittest_pb2.TestAllTypes()
+ text = 'repeated_string: "\\xc3\\xc3"'
+ self.assertRaises(text_format.ParseError, text_format.Merge, text, message)
+
+ def testMergeSingleWord(self):
+ message = unittest_pb2.TestAllTypes()
+ text = 'foo'
+ self.assertRaisesWithMessage(
+ text_format.ParseError,
+ ('1:1 : Message type "protobuf_unittest.TestAllTypes" has no field named '
+ '"foo".'),
+ text_format.Merge, text, message)
+
+ def testMergeUnknownField(self):
+ message = unittest_pb2.TestAllTypes()
+ text = 'unknown_field: 8\n'
+ self.assertRaisesWithMessage(
+ text_format.ParseError,
+ ('1:1 : Message type "protobuf_unittest.TestAllTypes" has no field named '
+ '"unknown_field".'),
+ text_format.Merge, text, message)
+
+ def testMergeBadExtension(self):
+ message = unittest_pb2.TestAllExtensions()
+ text = '[unknown_extension]: 8\n'
+ self.assertRaisesWithMessage(
+ text_format.ParseError,
+ '1:2 : Extension "unknown_extension" not registered.',
+ text_format.Merge, text, message)
+ message = unittest_pb2.TestAllTypes()
+ self.assertRaisesWithMessage(
+ text_format.ParseError,
+ ('1:2 : Message type "protobuf_unittest.TestAllTypes" does not have '
+ 'extensions.'),
+ text_format.Merge, text, message)
+
+ def testMergeGroupNotClosed(self):
+ message = unittest_pb2.TestAllTypes()
+ text = 'RepeatedGroup: <'
+ self.assertRaisesWithMessage(
+ text_format.ParseError, '1:16 : Expected ">".',
+ text_format.Merge, text, message)
+
+ text = 'RepeatedGroup: {'
+ self.assertRaisesWithMessage(
+ text_format.ParseError, '1:16 : Expected "}".',
+ text_format.Merge, text, message)
+
+ def testMergeEmptyGroup(self):
+ message = unittest_pb2.TestAllTypes()
+ text = 'OptionalGroup: {}'
+ text_format.Merge(text, message)
+ self.assertTrue(message.HasField('optionalgroup'))
+
+ message.Clear()
+
+ message = unittest_pb2.TestAllTypes()
+ text = 'OptionalGroup: <>'
+ text_format.Merge(text, message)
+ self.assertTrue(message.HasField('optionalgroup'))
+
+ def testMergeBadEnumValue(self):
+ message = unittest_pb2.TestAllTypes()
+ text = 'optional_nested_enum: BARR'
+ self.assertRaisesWithMessage(
+ text_format.ParseError,
+ ('1:23 : Enum type "protobuf_unittest.TestAllTypes.NestedEnum" '
+ 'has no value named BARR.'),
+ text_format.Merge, text, message)
+
+ message = unittest_pb2.TestAllTypes()
+ text = 'optional_nested_enum: 100'
+ self.assertRaisesWithMessage(
+ text_format.ParseError,
+ ('1:23 : Enum type "protobuf_unittest.TestAllTypes.NestedEnum" '
+ 'has no value with number 100.'),
+ text_format.Merge, text, message)
+
+ def testMergeBadIntValue(self):
+ message = unittest_pb2.TestAllTypes()
+ text = 'optional_int32: bork'
+ self.assertRaisesWithMessage(
+ text_format.ParseError,
+ ('1:17 : Couldn\'t parse integer: bork'),
+ text_format.Merge, text, message)
+
+ def testMergeStringFieldUnescape(self):
+ message = unittest_pb2.TestAllTypes()
+ text = r'''repeated_string: "\xf\x62"
+ repeated_string: "\\xf\\x62"
+ repeated_string: "\\\xf\\\x62"
+ repeated_string: "\\\\xf\\\\x62"
+ repeated_string: "\\\\\xf\\\\\x62"
+ repeated_string: "\x5cx20"'''
+ text_format.Merge(text, message)
+
+ SLASH = '\\'
+ self.assertEqual('\x0fb', message.repeated_string[0])
+ self.assertEqual(SLASH + 'xf' + SLASH + 'x62', message.repeated_string[1])
+ self.assertEqual(SLASH + '\x0f' + SLASH + 'b', message.repeated_string[2])
+ self.assertEqual(SLASH + SLASH + 'xf' + SLASH + SLASH + 'x62',
+ message.repeated_string[3])
+ self.assertEqual(SLASH + SLASH + '\x0f' + SLASH + SLASH + 'b',
+ message.repeated_string[4])
+ self.assertEqual(SLASH + 'x20', message.repeated_string[5])
+
+ def assertRaisesWithMessage(self, e_class, e, func, *args, **kwargs):
+ """Same as assertRaises, but also compares the exception message."""
+ if hasattr(e_class, '__name__'):
+ exc_name = e_class.__name__
+ else:
+ exc_name = str(e_class)
+
+ try:
+ func(*args, **kwargs)
+ except e_class as expr:
+ if str(expr) != e:
+ msg = '%s raised, but with wrong message: "%s" instead of "%s"'
+ raise self.failureException(msg % (exc_name,
+ str(expr).encode('string_escape'),
+ e.encode('string_escape')))
+ return
+ else:
+ raise self.failureException('%s not raised' % exc_name)
+
+
+class TokenizerTest(unittest.TestCase):
+ """
+ def testSimpleTokenCases(self):
+ text = ('identifier1:"string1"\n \n\n'
+ 'identifier2 : \n \n123 \n identifier3 :\'string\'\n'
+ 'identifiER_4 : 1.1e+2 ID5:-0.23 ID6:\'aaaa\\\'bbbb\'\n'
+ '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 ' )
+ tokenizer = text_format._Tokenizer(text)
+ methods = [(tokenizer.ConsumeIdentifier, 'identifier1'),
+ ':',
+ (tokenizer.ConsumeString, 'string1'),
+ (tokenizer.ConsumeIdentifier, 'identifier2'),
+ ':',
+ (tokenizer.ConsumeInt32, 123),
+ (tokenizer.ConsumeIdentifier, 'identifier3'),
+ ':',
+ (tokenizer.ConsumeString, 'string'),
+ (tokenizer.ConsumeIdentifier, 'identifiER_4'),
+ ':',
+ (tokenizer.ConsumeFloat, 1.1e+2),
+ (tokenizer.ConsumeIdentifier, 'ID5'),
+ ':',
+ (tokenizer.ConsumeFloat, -0.23),
+ (tokenizer.ConsumeIdentifier, 'ID6'),
+ ':',
+ (tokenizer.ConsumeString, 'aaaa\'bbbb'),
+ (tokenizer.ConsumeIdentifier, 'ID7'),
+ ':',
+ (tokenizer.ConsumeString, 'aa\"bb'),
+ (tokenizer.ConsumeIdentifier, 'ID8'),
+ ':',
+ '{',
+ (tokenizer.ConsumeIdentifier, 'A'),
+ ':',
+ (tokenizer.ConsumeFloat, float('inf')),
+ (tokenizer.ConsumeIdentifier, 'B'),
+ ':',
+ (tokenizer.ConsumeFloat, -float('inf')),
+ (tokenizer.ConsumeIdentifier, 'C'),
+ ':',
+ (tokenizer.ConsumeBool, True),
+ (tokenizer.ConsumeIdentifier, 'D'),
+ ':',
+ (tokenizer.ConsumeBool, False),
+ '}',
+ (tokenizer.ConsumeIdentifier, 'ID9'),
+ ':',
+ (tokenizer.ConsumeUint32, 22),
+ (tokenizer.ConsumeIdentifier, 'ID10'),
+ ':',
+ (tokenizer.ConsumeInt64, -111111111111111111),
+ (tokenizer.ConsumeIdentifier, 'ID11'),
+ ':',
+ (tokenizer.ConsumeInt32, -22),
+ (tokenizer.ConsumeIdentifier, 'ID12'),
+ ':',
+ (tokenizer.ConsumeUint64, 2222222222222222222),
+ (tokenizer.ConsumeIdentifier, 'ID13'),
+ ':',
+ (tokenizer.ConsumeFloat, 1.23456),
+ (tokenizer.ConsumeIdentifier, 'ID14'),
+ ':',
+ (tokenizer.ConsumeFloat, 1.2e+2),
+ (tokenizer.ConsumeIdentifier, 'false_bool'),
+ ':',
+ (tokenizer.ConsumeBool, False),
+ (tokenizer.ConsumeIdentifier, 'true_BOOL'),
+ ':',
+ (tokenizer.ConsumeBool, True),
+ (tokenizer.ConsumeIdentifier, 'true_bool1'),
+ ':',
+ (tokenizer.ConsumeBool, True),
+ (tokenizer.ConsumeIdentifier, 'false_BOOL1'),
+ ':',
+ (tokenizer.ConsumeBool, False)]
+
+ i = 0
+ while not tokenizer.AtEnd():
+ m = methods[i]
+ if type(m) == str:
+ token = tokenizer.token
+ self.assertEqual(token, m)
+ tokenizer.NextToken()
+ else:
+ self.assertEqual(m[1], m[0]())
+ i += 1
+
+ def testConsumeIntegers(self):
+ # This test only tests the failures in the integer parsing methods as well
+ # as the '0' special cases.
+ int64_max = (1 << 63) - 1
+ uint32_max = (1 << 32) - 1
+ text = '-1 %d %d' % (uint32_max + 1, int64_max + 1)
+ tokenizer = text_format._Tokenizer(text)
+ self.assertRaises(text_format.ParseError, tokenizer.ConsumeUint32)
+ self.assertRaises(text_format.ParseError, tokenizer.ConsumeUint64)
+ self.assertEqual(-1, tokenizer.ConsumeInt32())
+
+ self.assertRaises(text_format.ParseError, tokenizer.ConsumeUint32)
+ self.assertRaises(text_format.ParseError, tokenizer.ConsumeInt32)
+ self.assertEqual(uint32_max + 1, tokenizer.ConsumeInt64())
+
+ self.assertRaises(text_format.ParseError, tokenizer.ConsumeInt64)
+ self.assertEqual(int64_max + 1, tokenizer.ConsumeUint64())
+ self.assertTrue(tokenizer.AtEnd())
+
+ text = '-0 -0 0 0'
+ tokenizer = text_format._Tokenizer(text)
+ self.assertEqual(0, tokenizer.ConsumeUint32())
+ self.assertEqual(0, tokenizer.ConsumeUint64())
+ self.assertEqual(0, tokenizer.ConsumeUint32())
+ self.assertEqual(0, tokenizer.ConsumeUint64())
+ self.assertTrue(tokenizer.AtEnd())
+ """
+
+ def testConsumeByteString(self):
+ text = '"string1\''
+ tokenizer = text_format._Tokenizer(text)
+ self.assertRaises(text_format.ParseError, tokenizer.ConsumeByteString)
+
+ text = 'string1"'
+ tokenizer = text_format._Tokenizer(text)
+ self.assertRaises(text_format.ParseError, tokenizer.ConsumeByteString)
+
+ text = '\n"\\xt"'
+ tokenizer = text_format._Tokenizer(text)
+ self.assertRaises(text_format.ParseError, tokenizer.ConsumeByteString)
+
+ text = '\n"\\"'
+ tokenizer = text_format._Tokenizer(text)
+ self.assertRaises(text_format.ParseError, tokenizer.ConsumeByteString)
+
+ text = '\n"\\x"'
+ tokenizer = text_format._Tokenizer(text)
+ self.assertRaises(text_format.ParseError, tokenizer.ConsumeByteString)
+
+ def testConsumeBool(self):
+ text = 'not-a-bool'
+ tokenizer = text_format._Tokenizer(text)
+ self.assertRaises(text_format.ParseError, tokenizer.ConsumeBool)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/text_format_unittest_data.txt b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/text_format_unittest_data.txt
new file mode 100644
index 0000000000..bbe5882634
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/text_format_unittest_data.txt
@@ -0,0 +1,128 @@
+optional_int32: 101
+optional_int64: 102
+optional_uint32: 103
+optional_uint64: 104
+optional_sint32: 105
+optional_sint64: 106
+optional_fixed32: 107
+optional_fixed64: 108
+optional_sfixed32: 109
+optional_sfixed64: 110
+optional_float: 111
+optional_double: 112
+optional_bool: true
+optional_string: "115"
+optional_bytes: "116"
+OptionalGroup {
+ a: 117
+}
+optional_nested_message {
+ bb: 118
+}
+optional_foreign_message {
+ c: 119
+}
+optional_import_message {
+ d: 120
+}
+optional_nested_enum: BAZ
+optional_foreign_enum: FOREIGN_BAZ
+optional_import_enum: IMPORT_BAZ
+optional_string_piece: "124"
+optional_cord: "125"
+optional_public_import_message {
+ e: 126
+}
+optional_lazy_message {
+ bb: 127
+}
+repeated_int32: 201
+repeated_int32: 301
+repeated_int64: 202
+repeated_int64: 302
+repeated_uint32: 203
+repeated_uint32: 303
+repeated_uint64: 204
+repeated_uint64: 304
+repeated_sint32: 205
+repeated_sint32: 305
+repeated_sint64: 206
+repeated_sint64: 306
+repeated_fixed32: 207
+repeated_fixed32: 307
+repeated_fixed64: 208
+repeated_fixed64: 308
+repeated_sfixed32: 209
+repeated_sfixed32: 309
+repeated_sfixed64: 210
+repeated_sfixed64: 310
+repeated_float: 211
+repeated_float: 311
+repeated_double: 212
+repeated_double: 312
+repeated_bool: true
+repeated_bool: false
+repeated_string: "215"
+repeated_string: "315"
+repeated_bytes: "216"
+repeated_bytes: "316"
+RepeatedGroup {
+ a: 217
+}
+RepeatedGroup {
+ a: 317
+}
+repeated_nested_message {
+ bb: 218
+}
+repeated_nested_message {
+ bb: 318
+}
+repeated_foreign_message {
+ c: 219
+}
+repeated_foreign_message {
+ c: 319
+}
+repeated_import_message {
+ d: 220
+}
+repeated_import_message {
+ d: 320
+}
+repeated_nested_enum: BAR
+repeated_nested_enum: BAZ
+repeated_foreign_enum: FOREIGN_BAR
+repeated_foreign_enum: FOREIGN_BAZ
+repeated_import_enum: IMPORT_BAR
+repeated_import_enum: IMPORT_BAZ
+repeated_string_piece: "224"
+repeated_string_piece: "324"
+repeated_cord: "225"
+repeated_cord: "325"
+repeated_lazy_message {
+ bb: 227
+}
+repeated_lazy_message {
+ bb: 327
+}
+default_int32: 401
+default_int64: 402
+default_uint32: 403
+default_uint64: 404
+default_sint32: 405
+default_sint64: 406
+default_fixed32: 407
+default_fixed64: 408
+default_sfixed32: 409
+default_sfixed64: 410
+default_float: 411
+default_double: 412
+default_bool: false
+default_string: "415"
+default_bytes: "416"
+default_nested_enum: FOO
+default_foreign_enum: FOREIGN_FOO
+default_import_enum: IMPORT_FOO
+default_string_piece: "424"
+default_cord: "425"
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/text_format_unittest_extensions_data.txt b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/text_format_unittest_extensions_data.txt
new file mode 100644
index 0000000000..0a217f025d
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/text_format_unittest_extensions_data.txt
@@ -0,0 +1,128 @@
+[protobuf_unittest.optional_int32_extension]: 101
+[protobuf_unittest.optional_int64_extension]: 102
+[protobuf_unittest.optional_uint32_extension]: 103
+[protobuf_unittest.optional_uint64_extension]: 104
+[protobuf_unittest.optional_sint32_extension]: 105
+[protobuf_unittest.optional_sint64_extension]: 106
+[protobuf_unittest.optional_fixed32_extension]: 107
+[protobuf_unittest.optional_fixed64_extension]: 108
+[protobuf_unittest.optional_sfixed32_extension]: 109
+[protobuf_unittest.optional_sfixed64_extension]: 110
+[protobuf_unittest.optional_float_extension]: 111
+[protobuf_unittest.optional_double_extension]: 112
+[protobuf_unittest.optional_bool_extension]: true
+[protobuf_unittest.optional_string_extension]: "115"
+[protobuf_unittest.optional_bytes_extension]: "116"
+[protobuf_unittest.optionalgroup_extension] {
+ a: 117
+}
+[protobuf_unittest.optional_nested_message_extension] {
+ bb: 118
+}
+[protobuf_unittest.optional_foreign_message_extension] {
+ c: 119
+}
+[protobuf_unittest.optional_import_message_extension] {
+ d: 120
+}
+[protobuf_unittest.optional_nested_enum_extension]: BAZ
+[protobuf_unittest.optional_foreign_enum_extension]: FOREIGN_BAZ
+[protobuf_unittest.optional_import_enum_extension]: IMPORT_BAZ
+[protobuf_unittest.optional_string_piece_extension]: "124"
+[protobuf_unittest.optional_cord_extension]: "125"
+[protobuf_unittest.optional_public_import_message_extension] {
+ e: 126
+}
+[protobuf_unittest.optional_lazy_message_extension] {
+ bb: 127
+}
+[protobuf_unittest.repeated_int32_extension]: 201
+[protobuf_unittest.repeated_int32_extension]: 301
+[protobuf_unittest.repeated_int64_extension]: 202
+[protobuf_unittest.repeated_int64_extension]: 302
+[protobuf_unittest.repeated_uint32_extension]: 203
+[protobuf_unittest.repeated_uint32_extension]: 303
+[protobuf_unittest.repeated_uint64_extension]: 204
+[protobuf_unittest.repeated_uint64_extension]: 304
+[protobuf_unittest.repeated_sint32_extension]: 205
+[protobuf_unittest.repeated_sint32_extension]: 305
+[protobuf_unittest.repeated_sint64_extension]: 206
+[protobuf_unittest.repeated_sint64_extension]: 306
+[protobuf_unittest.repeated_fixed32_extension]: 207
+[protobuf_unittest.repeated_fixed32_extension]: 307
+[protobuf_unittest.repeated_fixed64_extension]: 208
+[protobuf_unittest.repeated_fixed64_extension]: 308
+[protobuf_unittest.repeated_sfixed32_extension]: 209
+[protobuf_unittest.repeated_sfixed32_extension]: 309
+[protobuf_unittest.repeated_sfixed64_extension]: 210
+[protobuf_unittest.repeated_sfixed64_extension]: 310
+[protobuf_unittest.repeated_float_extension]: 211
+[protobuf_unittest.repeated_float_extension]: 311
+[protobuf_unittest.repeated_double_extension]: 212
+[protobuf_unittest.repeated_double_extension]: 312
+[protobuf_unittest.repeated_bool_extension]: true
+[protobuf_unittest.repeated_bool_extension]: false
+[protobuf_unittest.repeated_string_extension]: "215"
+[protobuf_unittest.repeated_string_extension]: "315"
+[protobuf_unittest.repeated_bytes_extension]: "216"
+[protobuf_unittest.repeated_bytes_extension]: "316"
+[protobuf_unittest.repeatedgroup_extension] {
+ a: 217
+}
+[protobuf_unittest.repeatedgroup_extension] {
+ a: 317
+}
+[protobuf_unittest.repeated_nested_message_extension] {
+ bb: 218
+}
+[protobuf_unittest.repeated_nested_message_extension] {
+ bb: 318
+}
+[protobuf_unittest.repeated_foreign_message_extension] {
+ c: 219
+}
+[protobuf_unittest.repeated_foreign_message_extension] {
+ c: 319
+}
+[protobuf_unittest.repeated_import_message_extension] {
+ d: 220
+}
+[protobuf_unittest.repeated_import_message_extension] {
+ d: 320
+}
+[protobuf_unittest.repeated_nested_enum_extension]: BAR
+[protobuf_unittest.repeated_nested_enum_extension]: BAZ
+[protobuf_unittest.repeated_foreign_enum_extension]: FOREIGN_BAR
+[protobuf_unittest.repeated_foreign_enum_extension]: FOREIGN_BAZ
+[protobuf_unittest.repeated_import_enum_extension]: IMPORT_BAR
+[protobuf_unittest.repeated_import_enum_extension]: IMPORT_BAZ
+[protobuf_unittest.repeated_string_piece_extension]: "224"
+[protobuf_unittest.repeated_string_piece_extension]: "324"
+[protobuf_unittest.repeated_cord_extension]: "225"
+[protobuf_unittest.repeated_cord_extension]: "325"
+[protobuf_unittest.repeated_lazy_message_extension] {
+ bb: 227
+}
+[protobuf_unittest.repeated_lazy_message_extension] {
+ bb: 327
+}
+[protobuf_unittest.default_int32_extension]: 401
+[protobuf_unittest.default_int64_extension]: 402
+[protobuf_unittest.default_uint32_extension]: 403
+[protobuf_unittest.default_uint64_extension]: 404
+[protobuf_unittest.default_sint32_extension]: 405
+[protobuf_unittest.default_sint64_extension]: 406
+[protobuf_unittest.default_fixed32_extension]: 407
+[protobuf_unittest.default_fixed64_extension]: 408
+[protobuf_unittest.default_sfixed32_extension]: 409
+[protobuf_unittest.default_sfixed64_extension]: 410
+[protobuf_unittest.default_float_extension]: 411
+[protobuf_unittest.default_double_extension]: 412
+[protobuf_unittest.default_bool_extension]: false
+[protobuf_unittest.default_string_extension]: "415"
+[protobuf_unittest.default_bytes_extension]: "416"
+[protobuf_unittest.default_nested_enum_extension]: FOO
+[protobuf_unittest.default_foreign_enum_extension]: FOREIGN_FOO
+[protobuf_unittest.default_import_enum_extension]: IMPORT_FOO
+[protobuf_unittest.default_string_piece_extension]: "424"
+[protobuf_unittest.default_cord_extension]: "425"
diff --git a/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/wire_format_test.py b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/wire_format_test.py
new file mode 100755
index 0000000000..7600778603
--- /dev/null
+++ b/third_party/protobuf/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/wire_format_test.py
@@ -0,0 +1,253 @@
+#! /usr/bin/python
+#
+# Protocol Buffers - Google's data interchange format
+# Copyright 2008 Google Inc. All rights reserved.
+# http://code.google.com/p/protobuf/
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""Test for google.protobuf.internal.wire_format."""
+
+__author__ = 'robinson@google.com (Will Robinson)'
+
+import unittest
+from google.protobuf import message
+from google.protobuf.internal import wire_format
+
+
+class WireFormatTest(unittest.TestCase):
+
+ def testPackTag(self):
+ field_number = 0xabc
+ tag_type = 2
+ self.assertEqual((field_number << 3) | tag_type,
+ wire_format.PackTag(field_number, tag_type))
+ PackTag = wire_format.PackTag
+ # Number too high.
+ self.assertRaises(message.EncodeError, PackTag, field_number, 6)
+ # Number too low.
+ self.assertRaises(message.EncodeError, PackTag, field_number, -1)
+
+ def testUnpackTag(self):
+ # Test field numbers that will require various varint sizes.
+ for expected_field_number in (1, 15, 16, 2047, 2048):
+ for expected_wire_type in range(6): # Highest-numbered wiretype is 5.
+ field_number, wire_type = wire_format.UnpackTag(
+ wire_format.PackTag(expected_field_number, expected_wire_type))
+ self.assertEqual(expected_field_number, field_number)
+ self.assertEqual(expected_wire_type, wire_type)
+
+ self.assertRaises(TypeError, wire_format.UnpackTag, None)
+ self.assertRaises(TypeError, wire_format.UnpackTag, 'abc')
+ self.assertRaises(TypeError, wire_format.UnpackTag, 0.0)
+ self.assertRaises(TypeError, wire_format.UnpackTag, object())
+
+ def testZigZagEncode(self):
+ Z = wire_format.ZigZagEncode
+ self.assertEqual(0, Z(0))
+ self.assertEqual(1, Z(-1))
+ self.assertEqual(2, Z(1))
+ self.assertEqual(3, Z(-2))
+ self.assertEqual(4, Z(2))
+ self.assertEqual(0xfffffffe, Z(0x7fffffff))
+ self.assertEqual(0xffffffff, Z(-0x80000000))
+ self.assertEqual(0xfffffffffffffffe, Z(0x7fffffffffffffff))
+ self.assertEqual(0xffffffffffffffff, Z(-0x8000000000000000))
+
+ self.assertRaises(TypeError, Z, None)
+ self.assertRaises(TypeError, Z, 'abcd')
+ self.assertRaises(TypeError, Z, 0.0)
+ self.assertRaises(TypeError, Z, object())
+
+ def testZigZagDecode(self):
+ Z = wire_format.ZigZagDecode
+ self.assertEqual(0, Z(0))
+ self.assertEqual(-1, Z(1))
+ self.assertEqual(1, Z(2))
+ self.assertEqual(-2, Z(3))
+ self.assertEqual(2, Z(4))
+ self.assertEqual(0x7fffffff, Z(0xfffffffe))
+ self.assertEqual(-0x80000000, Z(0xffffffff))
+ self.assertEqual(0x7fffffffffffffff, Z(0xfffffffffffffffe))
+ self.assertEqual(-0x8000000000000000, Z(0xffffffffffffffff))
+
+ self.assertRaises(TypeError, Z, None)
+ self.assertRaises(TypeError, Z, 'abcd')
+ self.assertRaises(TypeError, Z, 0.0)
+ self.assertRaises(TypeError, Z, object())
+
+ def NumericByteSizeTestHelper(self, byte_size_fn, value, expected_value_size):
+ # Use field numbers that cause various byte sizes for the tag information.
+ for field_number, tag_bytes in ((15, 1), (16, 2), (2047, 2), (2048, 3)):
+ expected_size = expected_value_size + tag_bytes
+ actual_size = byte_size_fn(field_number, value)
+ self.assertEqual(expected_size, actual_size,
+ 'byte_size_fn: %s, field_number: %d, value: %r\n'
+ 'Expected: %d, Actual: %d'% (
+ byte_size_fn, field_number, value, expected_size, actual_size))
+
+ def testByteSizeFunctions(self):
+ # Test all numeric *ByteSize() functions.
+ NUMERIC_ARGS = [
+ # Int32ByteSize().
+ [wire_format.Int32ByteSize, 0, 1],
+ [wire_format.Int32ByteSize, 127, 1],
+ [wire_format.Int32ByteSize, 128, 2],
+ [wire_format.Int32ByteSize, -1, 10],
+ # Int64ByteSize().
+ [wire_format.Int64ByteSize, 0, 1],
+ [wire_format.Int64ByteSize, 127, 1],
+ [wire_format.Int64ByteSize, 128, 2],
+ [wire_format.Int64ByteSize, -1, 10],
+ # UInt32ByteSize().
+ [wire_format.UInt32ByteSize, 0, 1],
+ [wire_format.UInt32ByteSize, 127, 1],
+ [wire_format.UInt32ByteSize, 128, 2],
+ [wire_format.UInt32ByteSize, wire_format.UINT32_MAX, 5],
+ # UInt64ByteSize().
+ [wire_format.UInt64ByteSize, 0, 1],
+ [wire_format.UInt64ByteSize, 127, 1],
+ [wire_format.UInt64ByteSize, 128, 2],
+ [wire_format.UInt64ByteSize, wire_format.UINT64_MAX, 10],
+ # SInt32ByteSize().
+ [wire_format.SInt32ByteSize, 0, 1],
+ [wire_format.SInt32ByteSize, -1, 1],
+ [wire_format.SInt32ByteSize, 1, 1],
+ [wire_format.SInt32ByteSize, -63, 1],
+ [wire_format.SInt32ByteSize, 63, 1],
+ [wire_format.SInt32ByteSize, -64, 1],
+ [wire_format.SInt32ByteSize, 64, 2],
+ # SInt64ByteSize().
+ [wire_format.SInt64ByteSize, 0, 1],
+ [wire_format.SInt64ByteSize, -1, 1],
+ [wire_format.SInt64ByteSize, 1, 1],
+ [wire_format.SInt64ByteSize, -63, 1],
+ [wire_format.SInt64ByteSize, 63, 1],
+ [wire_format.SInt64ByteSize, -64, 1],
+ [wire_format.SInt64ByteSize, 64, 2],
+ # Fixed32ByteSize().
+ [wire_format.Fixed32ByteSize, 0, 4],
+ [wire_format.Fixed32ByteSize, wire_format.UINT32_MAX, 4],
+ # Fixed64ByteSize().
+ [wire_format.Fixed64ByteSize, 0, 8],
+ [wire_format.Fixed64ByteSize, wire_format.UINT64_MAX, 8],
+ # SFixed32ByteSize().
+ [wire_format.SFixed32ByteSize, 0, 4],
+ [wire_format.SFixed32ByteSize, wire_format.INT32_MIN, 4],
+ [wire_format.SFixed32ByteSize, wire_format.INT32_MAX, 4],
+ # SFixed64ByteSize().
+ [wire_format.SFixed64ByteSize, 0, 8],
+ [wire_format.SFixed64ByteSize, wire_format.INT64_MIN, 8],
+ [wire_format.SFixed64ByteSize, wire_format.INT64_MAX, 8],
+ # FloatByteSize().
+ [wire_format.FloatByteSize, 0.0, 4],
+ [wire_format.FloatByteSize, 1000000000.0, 4],
+ [wire_format.FloatByteSize, -1000000000.0, 4],
+ # DoubleByteSize().
+ [wire_format.DoubleByteSize, 0.0, 8],
+ [wire_format.DoubleByteSize, 1000000000.0, 8],
+ [wire_format.DoubleByteSize, -1000000000.0, 8],
+ # BoolByteSize().
+ [wire_format.BoolByteSize, False, 1],
+ [wire_format.BoolByteSize, True, 1],
+ # EnumByteSize().
+ [wire_format.EnumByteSize, 0, 1],
+ [wire_format.EnumByteSize, 127, 1],
+ [wire_format.EnumByteSize, 128, 2],
+ [wire_format.EnumByteSize, wire_format.UINT32_MAX, 5],
+ ]
+ for args in NUMERIC_ARGS:
+ self.NumericByteSizeTestHelper(*args)
+
+ # Test strings and bytes.
+ for byte_size_fn in (wire_format.StringByteSize, wire_format.BytesByteSize):
+ # 1 byte for tag, 1 byte for length, 3 bytes for contents.
+ self.assertEqual(5, byte_size_fn(10, 'abc'))
+ # 2 bytes for tag, 1 byte for length, 3 bytes for contents.
+ self.assertEqual(6, byte_size_fn(16, 'abc'))
+ # 2 bytes for tag, 2 bytes for length, 128 bytes for contents.
+ self.assertEqual(132, byte_size_fn(16, 'a' * 128))
+
+ # Test UTF-8 string byte size calculation.
+ # 1 byte for tag, 1 byte for length, 8 bytes for content.
+ self.assertEqual(10, wire_format.StringByteSize(
+ 5, unicode('\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82', 'utf-8')))
+
+ class MockMessage(object):
+ def __init__(self, byte_size):
+ self.byte_size = byte_size
+ def ByteSize(self):
+ return self.byte_size
+
+ message_byte_size = 10
+ mock_message = MockMessage(byte_size=message_byte_size)
+ # Test groups.
+ # (2 * 1) bytes for begin and end tags, plus message_byte_size.
+ self.assertEqual(2 + message_byte_size,
+ wire_format.GroupByteSize(1, mock_message))
+ # (2 * 2) bytes for begin and end tags, plus message_byte_size.
+ self.assertEqual(4 + message_byte_size,
+ wire_format.GroupByteSize(16, mock_message))
+
+ # Test messages.
+ # 1 byte for tag, plus 1 byte for length, plus contents.
+ self.assertEqual(2 + mock_message.byte_size,
+ wire_format.MessageByteSize(1, mock_message))
+ # 2 bytes for tag, plus 1 byte for length, plus contents.
+ self.assertEqual(3 + mock_message.byte_size,
+ wire_format.MessageByteSize(16, mock_message))
+ # 2 bytes for tag, plus 2 bytes for length, plus contents.
+ mock_message.byte_size = 128
+ self.assertEqual(4 + mock_message.byte_size,
+ wire_format.MessageByteSize(16, mock_message))
+
+
+ # Test message set item byte size.
+ # 4 bytes for tags, plus 1 byte for length, plus 1 byte for type_id,
+ # plus contents.
+ mock_message.byte_size = 10
+ self.assertEqual(mock_message.byte_size + 6,
+ wire_format.MessageSetItemByteSize(1, mock_message))
+
+ # 4 bytes for tags, plus 2 bytes for length, plus 1 byte for type_id,
+ # plus contents.
+ mock_message.byte_size = 128
+ self.assertEqual(mock_message.byte_size + 7,
+ wire_format.MessageSetItemByteSize(1, mock_message))
+
+ # 4 bytes for tags, plus 2 bytes for length, plus 2 byte for type_id,
+ # plus contents.
+ self.assertEqual(mock_message.byte_size + 8,
+ wire_format.MessageSetItemByteSize(128, mock_message))
+
+ # Too-long varint.
+ self.assertRaises(message.EncodeError,
+ wire_format.UInt64ByteSize, 1, 1 << 128)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/third_party/protobuf/python/google/__init__.py b/third_party/protobuf/python/google/__init__.py
new file mode 100755
index 0000000000..5585614122
--- /dev/null
+++ b/third_party/protobuf/python/google/__init__.py
@@ -0,0 +1,4 @@
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ __path__ = __import__('pkgutil').extend_path(__path__, __name__)
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/__init__.py b/third_party/protobuf/python/google/protobuf/__init__.py
index 6210a404b5..7fd9e5a458 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/__init__.py
+++ b/third_party/protobuf/python/google/protobuf/__init__.py
@@ -30,7 +30,7 @@
# Copyright 2007 Google Inc. All Rights Reserved.
-__version__ = '3.0.0'
+__version__ = '3.2.0'
if __name__ != '__main__':
try:
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/descriptor.py b/third_party/protobuf/python/google/protobuf/descriptor.py
index 873af30646..e1f2e3b7c9 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/descriptor.py
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/python/google/protobuf/descriptor_database.py b/third_party/protobuf/python/google/protobuf/descriptor_database.py
index 1333f9966e..1333f9966e 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/descriptor_database.py
+++ b/third_party/protobuf/python/google/protobuf/descriptor_database.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/descriptor_pool.py b/third_party/protobuf/python/google/protobuf/descriptor_pool.py
index 5c055ab9b7..fc3a7f4404 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/descriptor_pool.py
+++ b/third_party/protobuf/python/google/protobuf/descriptor_pool.py
@@ -57,12 +57,14 @@ directly instead of this class.
__author__ = 'matthewtoia@google.com (Matt Toia)'
+import collections
+
from google.protobuf import descriptor
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 +82,22 @@ 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
+
+
+def _IsMessageSetExtension(field):
+ return (field.is_extension and
+ field.containing_type.has_options and
+ field.containing_type.GetOptions().message_set_wire_format and
+ field.type == descriptor.FieldDescriptor.TYPE_MESSAGE and
+ field.label == descriptor.FieldDescriptor.LABEL_OPTIONAL)
+
+
class DescriptorPool(object):
"""A collection of protobufs dynamically constructed by descriptor protos."""
@@ -107,6 +125,12 @@ class DescriptorPool(object):
self._descriptors = {}
self._enum_descriptors = {}
self._file_descriptors = {}
+ self._toplevel_extensions = {}
+ # We store extensions in two two-level mappings: The first key is the
+ # descriptor of the message being extended, the second key is the extension
+ # full name or its tag number.
+ self._extensions_by_name = collections.defaultdict(dict)
+ self._extensions_by_number = collections.defaultdict(dict)
def Add(self, file_desc_proto):
"""Adds the FileDescriptorProto and its types to this pool.
@@ -162,6 +186,48 @@ class DescriptorPool(object):
self._enum_descriptors[enum_desc.full_name] = enum_desc
self.AddFileDescriptor(enum_desc.file)
+ def AddExtensionDescriptor(self, extension):
+ """Adds a FieldDescriptor describing an extension to the pool.
+
+ Args:
+ extension: A FieldDescriptor.
+
+ Raises:
+ AssertionError: when another extension with the same number extends the
+ same message.
+ TypeError: when the specified extension is not a
+ descriptor.FieldDescriptor.
+ """
+ if not (isinstance(extension, descriptor.FieldDescriptor) and
+ extension.is_extension):
+ raise TypeError('Expected an extension descriptor.')
+
+ if extension.extension_scope is None:
+ self._toplevel_extensions[extension.full_name] = extension
+
+ try:
+ existing_desc = self._extensions_by_number[
+ extension.containing_type][extension.number]
+ except KeyError:
+ pass
+ else:
+ if extension is not existing_desc:
+ raise AssertionError(
+ 'Extensions "%s" and "%s" both try to extend message type "%s" '
+ 'with field number %d.' %
+ (extension.full_name, existing_desc.full_name,
+ extension.containing_type.full_name, extension.number))
+
+ self._extensions_by_number[extension.containing_type][
+ extension.number] = extension
+ self._extensions_by_name[extension.containing_type][
+ extension.full_name] = extension
+
+ # Also register MessageSet extensions with the type name.
+ if _IsMessageSetExtension(extension):
+ self._extensions_by_name[extension.containing_type][
+ extension.message_type.full_name] = extension
+
def AddFileDescriptor(self, file_desc):
"""Adds a FileDescriptor to the pool, non-recursively.
@@ -294,6 +360,14 @@ class DescriptorPool(object):
A FieldDescriptor, describing the named extension.
"""
full_name = _NormalizeFullyQualifiedName(full_name)
+ try:
+ # The proto compiler does not give any link between the FileDescriptor
+ # and top-level extensions unless the FileDescriptorProto is added to
+ # the DescriptorDatabase, but this can impact memory usage.
+ # So we registered these extensions by name explicitly.
+ return self._toplevel_extensions[full_name]
+ except KeyError:
+ pass
message_name, _, extension_name = full_name.rpartition('.')
try:
# Most extensions are nested inside a message.
@@ -303,6 +377,39 @@ class DescriptorPool(object):
scope = self.FindFileContainingSymbol(full_name)
return scope.extensions_by_name[extension_name]
+ def FindExtensionByNumber(self, message_descriptor, number):
+ """Gets the extension of the specified message with the specified number.
+
+ Extensions have to be registered to this pool by calling
+ AddExtensionDescriptor.
+
+ Args:
+ message_descriptor: descriptor of the extended message.
+ number: integer, number of the extension field.
+
+ Returns:
+ A FieldDescriptor describing the extension.
+
+ Raise:
+ KeyError: when no extension with the given number is known for the
+ specified message.
+ """
+ return self._extensions_by_number[message_descriptor][number]
+
+ def FindAllExtensions(self, message_descriptor):
+ """Gets all the known extension of a given message.
+
+ Extensions have to be registered to this pool by calling
+ AddExtensionDescriptor.
+
+ Args:
+ message_descriptor: descriptor of the extended message.
+
+ Returns:
+ A list of FieldDescriptor describing the extensions.
+ """
+ return list(self._extensions_by_number[message_descriptor].values())
+
def _ConvertFileProtoToFileDescriptor(self, file_proto):
"""Creates a FileDescriptor from a proto or returns a cached copy.
@@ -326,78 +433,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 +503,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 +554,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 +608,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 +653,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 +772,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 +802,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 +831,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/third_party/protobuf/python/google/protobuf/internal/__init__.py b/third_party/protobuf/python/google/protobuf/internal/__init__.py
new file mode 100755
index 0000000000..e69de29bb2
--- /dev/null
+++ b/third_party/protobuf/python/google/protobuf/internal/__init__.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/_parameterized.py b/third_party/protobuf/python/google/protobuf/internal/_parameterized.py
index 23a78f037e..23a78f037e 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/_parameterized.py
+++ b/third_party/protobuf/python/google/protobuf/internal/_parameterized.py
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/anys.proto b/third_party/protobuf/python/google/protobuf/internal/any_test.proto
index 18c59cbb96..76a7ebd68d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/anys.proto
+++ b/third_party/protobuf/python/google/protobuf/internal/any_test.proto
@@ -28,26 +28,23 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Proto to test Proto3 Any serialization.
-syntax = "proto3";
+// Author: jieluo@google.com (Jie Luo)
-package google.protobuf.testing.anys;
-option java_package = "com.google.protobuf.testing.anys";
+syntax = "proto2";
-import "google/protobuf/any.proto";
-
-message AnyIn {
- string something = 1;
-}
+package google.protobuf.internal;
-message AnyOut {
- google.protobuf.Any any = 1;
-}
+import "google/protobuf/any.proto";
-message AnyM {
- string foo = 1;
+message TestAny {
+ optional google.protobuf.Any value = 1;
+ optional int32 int_value = 2;
+ extensions 10 to max;
}
-service TestService {
- rpc Call(AnyIn) returns (AnyOut);
+message TestAnyExtension1 {
+ extend TestAny {
+ optional TestAnyExtension1 extension1 = 98418603;
+ }
+ optional int32 i = 15;
}
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/api_implementation.cc b/third_party/protobuf/python/google/protobuf/internal/api_implementation.cc
index 6db12e8dc6..6db12e8dc6 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/api_implementation.cc
+++ b/third_party/protobuf/python/google/protobuf/internal/api_implementation.cc
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/api_implementation.py b/third_party/protobuf/python/google/protobuf/internal/api_implementation.py
index 460a4a6c2c..460a4a6c2c 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/api_implementation.py
+++ b/third_party/protobuf/python/google/protobuf/internal/api_implementation.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/containers.py b/third_party/protobuf/python/google/protobuf/internal/containers.py
index ce46d08c9e..de13018eef 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/containers.py
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/python/google/protobuf/internal/decoder.py b/third_party/protobuf/python/google/protobuf/internal/decoder.py
index 31869e4575..ff3e6d306c 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/decoder.py
+++ b/third_party/protobuf/python/google/protobuf/internal/decoder.py
@@ -131,9 +131,12 @@ def _VarintDecoder(mask, result_type):
return DecodeVarint
-def _SignedVarintDecoder(mask, result_type):
+def _SignedVarintDecoder(bits, result_type):
"""Like _VarintDecoder() but decodes signed values."""
+ signbit = 1 << (bits - 1)
+ mask = (1 << bits) - 1
+
def DecodeVarint(buffer, pos):
result = 0
shift = 0
@@ -142,11 +145,8 @@ def _SignedVarintDecoder(mask, result_type):
result |= ((b & 0x7f) << shift)
pos += 1
if not (b & 0x80):
- if result > 0x7fffffffffffffff:
- result -= (1 << 64)
- result |= ~mask
- else:
- result &= mask
+ result &= mask
+ result = (result ^ signbit) - signbit
result = result_type(result)
return (result, pos)
shift += 7
@@ -159,11 +159,11 @@ def _SignedVarintDecoder(mask, result_type):
# (e.g. the C++ implementation) simpler.
_DecodeVarint = _VarintDecoder((1 << 64) - 1, long)
-_DecodeSignedVarint = _SignedVarintDecoder((1 << 64) - 1, long)
+_DecodeSignedVarint = _SignedVarintDecoder(64, long)
# Use these versions for values which must be limited to 32 bits.
_DecodeVarint32 = _VarintDecoder((1 << 32) - 1, int)
-_DecodeSignedVarint32 = _SignedVarintDecoder((1 << 32) - 1, int)
+_DecodeSignedVarint32 = _SignedVarintDecoder(32, int)
def ReadTag(buffer, pos):
@@ -642,10 +642,10 @@ def MessageDecoder(field_number, is_repeated, is_packed, key, new_default):
MESSAGE_SET_ITEM_TAG = encoder.TagBytes(1, wire_format.WIRETYPE_START_GROUP)
-def MessageSetItemDecoder(extensions_by_number):
+def MessageSetItemDecoder(descriptor):
"""Returns a decoder for a MessageSet item.
- The parameter is the _extensions_by_number map for the message class.
+ The parameter is the message Descriptor.
The message set message looks like this:
message MessageSet {
@@ -694,7 +694,7 @@ def MessageSetItemDecoder(extensions_by_number):
if message_start == -1:
raise _DecodeError('MessageSet item missing message.')
- extension = extensions_by_number.get(type_id)
+ extension = message.Extensions._FindExtensionByNumber(type_id)
if extension is not None:
value = field_dict.get(extension)
if value is None:
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/descriptor_database_test.py b/third_party/protobuf/python/google/protobuf/internal/descriptor_database_test.py
index 5225a45821..5225a45821 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/descriptor_database_test.py
+++ b/third_party/protobuf/python/google/protobuf/internal/descriptor_database_test.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/descriptor_pool_test.py b/third_party/protobuf/python/google/protobuf/internal/descriptor_pool_test.py
index 3c8c793537..1e710dcf82 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/descriptor_pool_test.py
+++ b/third_party/protobuf/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')
@@ -250,6 +254,53 @@ class DescriptorPoolTest(unittest.TestCase):
with self.assertRaises(KeyError):
self.pool.FindFieldByName('Does not exist')
+ def testFindAllExtensions(self):
+ factory1_message = self.pool.FindMessageTypeByName(
+ 'google.protobuf.python.internal.Factory1Message')
+ factory2_message = self.pool.FindMessageTypeByName(
+ 'google.protobuf.python.internal.Factory2Message')
+ # An extension defined in a message.
+ one_more_field = factory2_message.extensions_by_name['one_more_field']
+ self.pool.AddExtensionDescriptor(one_more_field)
+ # An extension defined at file scope.
+ factory_test2 = self.pool.FindFileByName(
+ 'google/protobuf/internal/factory_test2.proto')
+ another_field = factory_test2.extensions_by_name['another_field']
+ self.pool.AddExtensionDescriptor(another_field)
+
+ extensions = self.pool.FindAllExtensions(factory1_message)
+ expected_extension_numbers = set([one_more_field, another_field])
+ self.assertEqual(expected_extension_numbers, set(extensions))
+ # Verify that mutating the returned list does not affect the pool.
+ extensions.append('unexpected_element')
+ # Get the extensions again, the returned value does not contain the
+ # 'unexpected_element'.
+ extensions = self.pool.FindAllExtensions(factory1_message)
+ self.assertEqual(expected_extension_numbers, set(extensions))
+
+ def testFindExtensionByNumber(self):
+ factory1_message = self.pool.FindMessageTypeByName(
+ 'google.protobuf.python.internal.Factory1Message')
+ factory2_message = self.pool.FindMessageTypeByName(
+ 'google.protobuf.python.internal.Factory2Message')
+ # An extension defined in a message.
+ one_more_field = factory2_message.extensions_by_name['one_more_field']
+ self.pool.AddExtensionDescriptor(one_more_field)
+ # An extension defined at file scope.
+ factory_test2 = self.pool.FindFileByName(
+ 'google/protobuf/internal/factory_test2.proto')
+ another_field = factory_test2.extensions_by_name['another_field']
+ self.pool.AddExtensionDescriptor(another_field)
+
+ # An extension defined in a message.
+ extension = self.pool.FindExtensionByNumber(factory1_message, 1001)
+ self.assertEqual(extension.name, 'one_more_field')
+ # An extension defined at file scope.
+ extension = self.pool.FindExtensionByNumber(factory1_message, 1002)
+ self.assertEqual(extension.name, 'another_field')
+ with self.assertRaises(KeyError):
+ extension = self.pool.FindExtensionByNumber(factory1_message, 1234567)
+
def testExtensionsAreNotFields(self):
with self.assertRaises(KeyError):
self.pool.FindFieldByName('google.protobuf.python.internal.another_field')
@@ -448,6 +499,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/third_party/protobuf/3.0.0/python/google/protobuf/internal/descriptor_pool_test1.proto b/third_party/protobuf/python/google/protobuf/internal/descriptor_pool_test1.proto
index 00816b78ec..00816b78ec 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/descriptor_pool_test1.proto
+++ b/third_party/protobuf/python/google/protobuf/internal/descriptor_pool_test1.proto
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/descriptor_pool_test2.proto b/third_party/protobuf/python/google/protobuf/internal/descriptor_pool_test2.proto
index a218eccb9f..a218eccb9f 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/descriptor_pool_test2.proto
+++ b/third_party/protobuf/python/google/protobuf/internal/descriptor_pool_test2.proto
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/descriptor_test.py b/third_party/protobuf/python/google/protobuf/internal/descriptor_test.py
index 623198c8d0..1f148ab90b 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/descriptor_test.py
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/python/google/protobuf/internal/encoder.py b/third_party/protobuf/python/google/protobuf/internal/encoder.py
index 48ef2df31c..48ef2df31c 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/encoder.py
+++ b/third_party/protobuf/python/google/protobuf/internal/encoder.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/enum_type_wrapper.py b/third_party/protobuf/python/google/protobuf/internal/enum_type_wrapper.py
index 1cffe35295..1cffe35295 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/enum_type_wrapper.py
+++ b/third_party/protobuf/python/google/protobuf/internal/enum_type_wrapper.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/factory_test1.proto b/third_party/protobuf/python/google/protobuf/internal/factory_test1.proto
index d2fbbeecf1..d2fbbeecf1 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/factory_test1.proto
+++ b/third_party/protobuf/python/google/protobuf/internal/factory_test1.proto
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/factory_test2.proto b/third_party/protobuf/python/google/protobuf/internal/factory_test2.proto
index bb1b54ada2..bb1b54ada2 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/factory_test2.proto
+++ b/third_party/protobuf/python/google/protobuf/internal/factory_test2.proto
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/file_options_test.proto b/third_party/protobuf/python/google/protobuf/internal/file_options_test.proto
index 4eceeb07f4..4eceeb07f4 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/file_options_test.proto
+++ b/third_party/protobuf/python/google/protobuf/internal/file_options_test.proto
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/generator_test.py b/third_party/protobuf/python/google/protobuf/internal/generator_test.py
index 83ea5f5094..7f13f9da3d 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/generator_test.py
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/python/google/protobuf/internal/import_test_package/__init__.py b/third_party/protobuf/python/google/protobuf/internal/import_test_package/__init__.py
index 5121dd0ec5..5121dd0ec5 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/import_test_package/__init__.py
+++ b/third_party/protobuf/python/google/protobuf/internal/import_test_package/__init__.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/import_test_package/inner.proto b/third_party/protobuf/python/google/protobuf/internal/import_test_package/inner.proto
index 2887c1230e..2887c1230e 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/import_test_package/inner.proto
+++ b/third_party/protobuf/python/google/protobuf/internal/import_test_package/inner.proto
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/import_test_package/outer.proto b/third_party/protobuf/python/google/protobuf/internal/import_test_package/outer.proto
index a27fb5c8f4..a27fb5c8f4 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/import_test_package/outer.proto
+++ b/third_party/protobuf/python/google/protobuf/internal/import_test_package/outer.proto
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/json_format_test.py b/third_party/protobuf/python/google/protobuf/internal/json_format_test.py
index a5ee8ace0e..5ed656221b 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/json_format_test.py
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/python/google/protobuf/internal/message_factory_test.py b/third_party/protobuf/python/google/protobuf/internal/message_factory_test.py
index 7bb7d1acec..4caa244344 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/message_factory_test.py
+++ b/third_party/protobuf/python/google/protobuf/internal/message_factory_test.py
@@ -114,18 +114,18 @@ class MessageFactoryTest(unittest.TestCase):
).issubset(set(messages.keys())))
self._ExerciseDynamicClass(
messages['google.protobuf.python.internal.Factory2Message'])
- self.assertTrue(
- set(['google.protobuf.python.internal.Factory2Message.one_more_field',
- 'google.protobuf.python.internal.another_field'],
- ).issubset(
- set(messages['google.protobuf.python.internal.Factory1Message']
- ._extensions_by_name.keys())))
factory_msg1 = messages['google.protobuf.python.internal.Factory1Message']
+ self.assertTrue(set(
+ ['google.protobuf.python.internal.Factory2Message.one_more_field',
+ 'google.protobuf.python.internal.another_field'],).issubset(set(
+ ext.full_name
+ for ext in factory_msg1.DESCRIPTOR.file.pool.FindAllExtensions(
+ factory_msg1.DESCRIPTOR))))
msg1 = messages['google.protobuf.python.internal.Factory1Message']()
- ext1 = factory_msg1._extensions_by_name[
- 'google.protobuf.python.internal.Factory2Message.one_more_field']
- ext2 = factory_msg1._extensions_by_name[
- 'google.protobuf.python.internal.another_field']
+ ext1 = msg1.Extensions._FindExtensionByName(
+ 'google.protobuf.python.internal.Factory2Message.one_more_field')
+ ext2 = msg1.Extensions._FindExtensionByName(
+ 'google.protobuf.python.internal.another_field')
msg1.Extensions[ext1] = 'test1'
msg1.Extensions[ext2] = 'test2'
self.assertEqual('test1', msg1.Extensions[ext1])
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/message_listener.py b/third_party/protobuf/python/google/protobuf/internal/message_listener.py
index 0fc255a774..0fc255a774 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/message_listener.py
+++ b/third_party/protobuf/python/google/protobuf/internal/message_listener.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/message_set_extensions.proto b/third_party/protobuf/python/google/protobuf/internal/message_set_extensions.proto
index 14e5f19375..14e5f19375 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/message_set_extensions.proto
+++ b/third_party/protobuf/python/google/protobuf/internal/message_set_extensions.proto
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/message_test.py b/third_party/protobuf/python/google/protobuf/internal/message_test.py
index 1e95adf9cd..9986c0d99b 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/message_test.py
+++ b/third_party/protobuf/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 <type 'module.class_name'> 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/third_party/protobuf/3.0.0/python/google/protobuf/internal/missing_enum_values.proto b/third_party/protobuf/python/google/protobuf/internal/missing_enum_values.proto
index 1850be5bb7..1850be5bb7 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/missing_enum_values.proto
+++ b/third_party/protobuf/python/google/protobuf/internal/missing_enum_values.proto
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/more_extensions.proto b/third_party/protobuf/python/google/protobuf/internal/more_extensions.proto
index 78f1467361..78f1467361 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/more_extensions.proto
+++ b/third_party/protobuf/python/google/protobuf/internal/more_extensions.proto
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/more_extensions_dynamic.proto b/third_party/protobuf/python/google/protobuf/internal/more_extensions_dynamic.proto
index 11f85ef60c..11f85ef60c 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/more_extensions_dynamic.proto
+++ b/third_party/protobuf/python/google/protobuf/internal/more_extensions_dynamic.proto
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/more_messages.proto b/third_party/protobuf/python/google/protobuf/internal/more_messages.proto
index 2c6ab9efdf..2c6ab9efdf 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/more_messages.proto
+++ b/third_party/protobuf/python/google/protobuf/internal/more_messages.proto
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/packed_field_test.proto b/third_party/protobuf/python/google/protobuf/internal/packed_field_test.proto
index 0dfdc10a87..0dfdc10a87 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/packed_field_test.proto
+++ b/third_party/protobuf/python/google/protobuf/internal/packed_field_test.proto
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/proto_builder_test.py b/third_party/protobuf/python/google/protobuf/internal/proto_builder_test.py
index 36dfbfded8..36dfbfded8 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/proto_builder_test.py
+++ b/third_party/protobuf/python/google/protobuf/internal/proto_builder_test.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/python_message.py b/third_party/protobuf/python/google/protobuf/internal/python_message.py
index c0d0ad451f..4b7010390a 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/python_message.py
+++ b/third_party/protobuf/python/google/protobuf/internal/python_message.py
@@ -51,19 +51,11 @@ this file*.
__author__ = 'robinson@google.com (Will Robinson)'
from io import BytesIO
-import sys
import struct
+import sys
import weakref
import six
-try:
- import six.moves.copyreg as copyreg
-except ImportError:
- # On some platforms, for example gMac, we run native Python because there is
- # nothing like hermetic Python. This means lesser control on the system and
- # the six.moves package may be missing (is missing on 20150321 on gMac). Be
- # extra conservative and try to load the old replacement if it fails.
- import copy_reg as copyreg
# We use "as" to avoid name collisions with variables.
from google.protobuf.internal import containers
@@ -159,12 +151,10 @@ class GeneratedProtocolMessageType(type):
"""
descriptor = dictionary[GeneratedProtocolMessageType._DESCRIPTOR_KEY]
cls._decoders_by_tag = {}
- cls._extensions_by_name = {}
- cls._extensions_by_number = {}
if (descriptor.has_options and
descriptor.GetOptions().message_set_wire_format):
cls._decoders_by_tag[decoder.MESSAGE_SET_ITEM_TAG] = (
- decoder.MessageSetItemDecoder(cls._extensions_by_number), None)
+ decoder.MessageSetItemDecoder(descriptor), None)
# Attach stuff to each FieldDescriptor for quick lookup later on.
for field in descriptor.fields:
@@ -178,7 +168,6 @@ class GeneratedProtocolMessageType(type):
_AddStaticMethods(cls)
_AddMessageMethods(descriptor, cls)
_AddPrivateHelperMethods(descriptor, cls)
- copyreg.pickle(cls, lambda obj: (cls, (), obj.__getstate__()))
superclass = super(GeneratedProtocolMessageType, cls)
superclass.__init__(name, bases, dictionary)
@@ -380,13 +369,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):
@@ -742,32 +733,21 @@ def _AddPropertiesForExtensions(descriptor, cls):
constant_name = extension_name.upper() + "_FIELD_NUMBER"
setattr(cls, constant_name, extension_field.number)
+ # TODO(amauryfa): Migrate all users of these attributes to functions like
+ # pool.FindExtensionByNumber(descriptor).
+ if descriptor.file is not None:
+ # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
+ pool = descriptor.file.pool
+ cls._extensions_by_number = pool._extensions_by_number[descriptor]
+ cls._extensions_by_name = pool._extensions_by_name[descriptor]
def _AddStaticMethods(cls):
# TODO(robinson): This probably needs to be thread-safe(?)
def RegisterExtension(extension_handle):
extension_handle.containing_type = cls.DESCRIPTOR
+ # TODO(amauryfa): Use cls.MESSAGE_FACTORY.pool when available.
+ cls.DESCRIPTOR.file.pool.AddExtensionDescriptor(extension_handle)
_AttachFieldHelpers(cls, extension_handle)
-
- # Try to insert our extension, failing if an extension with the same number
- # already exists.
- actual_handle = cls._extensions_by_number.setdefault(
- extension_handle.number, extension_handle)
- if actual_handle is not extension_handle:
- raise AssertionError(
- 'Extensions "%s" and "%s" both try to extend message type "%s" with '
- 'field number %d.' %
- (extension_handle.full_name, actual_handle.full_name,
- cls.DESCRIPTOR.full_name, extension_handle.number))
-
- cls._extensions_by_name[extension_handle.full_name] = extension_handle
-
- handle = extension_handle # avoid line wrapping
- if _IsMessageSetExtension(handle):
- # MessageSet extension. Also register under type name.
- cls._extensions_by_name[
- extension_handle.message_type.full_name] = extension_handle
-
cls.RegisterExtension = staticmethod(RegisterExtension)
def FromString(s):
@@ -1225,7 +1205,7 @@ def _AddMergeFromMethod(cls):
if not isinstance(msg, cls):
raise TypeError(
"Parameter to MergeFrom() must be instance of same class: "
- "expected %s got %s." % (cls.__name__, type(msg).__name__))
+ 'expected %s got %s.' % (cls.__name__, msg.__class__.__name__))
assert msg is not self
self._Modified()
@@ -1279,6 +1259,12 @@ def _AddWhichOneofMethod(message_descriptor, cls):
cls.WhichOneof = WhichOneof
+def _AddReduceMethod(cls):
+ def __reduce__(self): # pylint: disable=invalid-name
+ return (type(self), (), self.__getstate__())
+ cls.__reduce__ = __reduce__
+
+
def _Clear(self):
# Clear fields.
self._fields = {}
@@ -1324,6 +1310,7 @@ def _AddMessageMethods(message_descriptor, cls):
_AddIsInitializedMethod(message_descriptor, cls)
_AddMergeFromMethod(cls)
_AddWhichOneofMethod(message_descriptor, cls)
+ _AddReduceMethod(cls)
# Adds methods which do not depend on cls.
cls.Clear = _Clear
cls.DiscardUnknownFields = _DiscardUnknownFields
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/reflection_test.py b/third_party/protobuf/python/google/protobuf/internal/reflection_test.py
index 20e5d245d3..0e88101578 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/reflection_test.py
+++ b/third_party/protobuf/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.
@@ -95,12 +99,12 @@ class _MiniDecoder(object):
return wire_format.UnpackTag(self.ReadVarint())
def ReadFloat(self):
- result = struct.unpack("<f", self._bytes[self._pos:self._pos+4])[0]
+ result = struct.unpack('<f', self._bytes[self._pos:self._pos+4])[0]
self._pos += 4
return result
def ReadDouble(self):
- result = struct.unpack("<d", self._bytes[self._pos:self._pos+8])[0]
+ result = struct.unpack('<d', self._bytes[self._pos:self._pos+8])[0]
self._pos += 8
return result
@@ -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))
@@ -617,9 +621,15 @@ class ReflectionTest(unittest.TestCase):
self.assertRaises(TypeError, setattr, proto, 'optional_string', 10)
self.assertRaises(TypeError, setattr, proto, 'optional_bytes', 10)
- def testIntegerTypes(self):
+ def assertIntegerTypes(self, integer_fn):
+ """Verifies setting of scalar integers.
+
+ Args:
+ integer_fn: A function to wrap the integers that will be assigned.
+ """
def TestGetAndDeserialize(field_name, value, expected_type):
proto = unittest_pb2.TestAllTypes()
+ value = integer_fn(value)
setattr(proto, field_name, value)
self.assertIsInstance(getattr(proto, field_name), expected_type)
proto2 = unittest_pb2.TestAllTypes()
@@ -631,12 +641,12 @@ class ReflectionTest(unittest.TestCase):
TestGetAndDeserialize('optional_uint32', 1 << 30, int)
try:
integer_64 = long
- except NameError: # Python3
+ except NameError: # Python3
integer_64 = int
if struct.calcsize('L') == 4:
# Python only has signed ints, so 32-bit python can't fit an uint32
# in an int.
- TestGetAndDeserialize('optional_uint32', 1 << 31, long)
+ TestGetAndDeserialize('optional_uint32', 1 << 31, integer_64)
else:
# 64-bit python can fit uint32 inside an int
TestGetAndDeserialize('optional_uint32', 1 << 31, int)
@@ -645,9 +655,33 @@ class ReflectionTest(unittest.TestCase):
TestGetAndDeserialize('optional_uint64', 1 << 30, integer_64)
TestGetAndDeserialize('optional_uint64', 1 << 60, integer_64)
- def testSingleScalarBoundsChecking(self):
+ def testIntegerTypes(self):
+ self.assertIntegerTypes(lambda x: x)
+
+ def testNonStandardIntegerTypes(self):
+ self.assertIntegerTypes(test_util.NonStandardInteger)
+
+ def testIllegalValuesForIntegers(self):
+ pb = unittest_pb2.TestAllTypes()
+
+ # Strings are illegal, even when the represent an integer.
+ with self.assertRaises(TypeError):
+ pb.optional_uint64 = '2'
+
+ # The exact error should propagate with a poorly written custom integer.
+ with self.assertRaisesRegexp(RuntimeError, 'my_error'):
+ pb.optional_uint64 = test_util.NonStandardInteger(5, 'my_error')
+
+ def assetIntegerBoundsChecking(self, integer_fn):
+ """Verifies bounds checking for scalar integer fields.
+
+ Args:
+ integer_fn: A function to wrap the integers that will be assigned.
+ """
def TestMinAndMaxIntegers(field_name, expected_min, expected_max):
pb = unittest_pb2.TestAllTypes()
+ expected_min = integer_fn(expected_min)
+ expected_max = integer_fn(expected_max)
setattr(pb, field_name, expected_min)
self.assertEqual(expected_min, getattr(pb, field_name))
setattr(pb, field_name, expected_max)
@@ -659,11 +693,22 @@ class ReflectionTest(unittest.TestCase):
TestMinAndMaxIntegers('optional_uint32', 0, 0xffffffff)
TestMinAndMaxIntegers('optional_int64', -(1 << 63), (1 << 63) - 1)
TestMinAndMaxIntegers('optional_uint64', 0, 0xffffffffffffffff)
+ # A bit of white-box testing since -1 is an int and not a long in C++ and
+ # so goes down a different path.
+ pb = unittest_pb2.TestAllTypes()
+ with self.assertRaises(ValueError):
+ pb.optional_uint64 = integer_fn(-(1 << 63))
pb = unittest_pb2.TestAllTypes()
- pb.optional_nested_enum = 1
+ pb.optional_nested_enum = integer_fn(1)
self.assertEqual(1, pb.optional_nested_enum)
+ def testSingleScalarBoundsChecking(self):
+ self.assetIntegerBoundsChecking(lambda x: x)
+
+ def testNonStandardSingleScalarBoundsChecking(self):
+ self.assetIntegerBoundsChecking(test_util.NonStandardInteger)
+
def testRepeatedScalarTypeSafety(self):
proto = unittest_pb2.TestAllTypes()
self.assertRaises(TypeError, proto.repeated_int32.append, 1.1)
@@ -1183,12 +1228,18 @@ class ReflectionTest(unittest.TestCase):
self.assertTrue(not extendee_proto.HasExtension(extension))
def testRegisteredExtensions(self):
- self.assertTrue('protobuf_unittest.optional_int32_extension' in
- unittest_pb2.TestAllExtensions._extensions_by_name)
- self.assertTrue(1 in unittest_pb2.TestAllExtensions._extensions_by_number)
+ pool = unittest_pb2.DESCRIPTOR.pool
+ self.assertTrue(
+ pool.FindExtensionByNumber(
+ unittest_pb2.TestAllExtensions.DESCRIPTOR, 1))
+ self.assertIs(
+ pool.FindExtensionByName(
+ 'protobuf_unittest.optional_int32_extension').containing_type,
+ unittest_pb2.TestAllExtensions.DESCRIPTOR)
# Make sure extensions haven't been registered into types that shouldn't
# have any.
- self.assertEqual(0, len(unittest_pb2.TestAllTypes._extensions_by_name))
+ self.assertEqual(0, len(
+ pool.FindAllExtensions(unittest_pb2.TestAllTypes.DESCRIPTOR)))
# If message A directly contains message B, and
# a.HasField('b') is currently False, then mutating any
@@ -1552,6 +1603,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 +1875,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 +1891,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 +1977,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 +2010,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 +2022,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 +2318,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 +2879,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 +2906,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 +2989,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 +3016,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 +3032,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/third_party/protobuf/3.0.0/python/google/protobuf/internal/service_reflection_test.py b/third_party/protobuf/python/google/protobuf/internal/service_reflection_test.py
index 62900b1d15..62900b1d15 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/service_reflection_test.py
+++ b/third_party/protobuf/python/google/protobuf/internal/service_reflection_test.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/symbol_database_test.py b/third_party/protobuf/python/google/protobuf/internal/symbol_database_test.py
index 4f5173b2a2..4f5173b2a2 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/symbol_database_test.py
+++ b/third_party/protobuf/python/google/protobuf/internal/symbol_database_test.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/test_bad_identifiers.proto b/third_party/protobuf/python/google/protobuf/internal/test_bad_identifiers.proto
index c4860ea88a..c4860ea88a 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/test_bad_identifiers.proto
+++ b/third_party/protobuf/python/google/protobuf/internal/test_bad_identifiers.proto
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/test_util.py b/third_party/protobuf/python/google/protobuf/internal/test_util.py
index 2c805599b6..269d0e2d4f 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/test_util.py
+++ b/third_party/protobuf/python/google/protobuf/internal/test_util.py
@@ -36,8 +36,9 @@ This is intentionally modeled on C++ code in
__author__ = 'robinson@google.com (Will Robinson)'
+import numbers
+import operator
import os.path
-
import sys
from google.protobuf import unittest_import_pb2
@@ -694,3 +695,154 @@ def SetAllUnpackedFields(message):
message.unpacked_bool.extend([True, False])
message.unpacked_enum.extend([unittest_pb2.FOREIGN_BAR,
unittest_pb2.FOREIGN_BAZ])
+
+
+class NonStandardInteger(numbers.Integral):
+ """An integer object that does not subclass int.
+
+ This is used to verify that both C++ and regular proto systems can handle
+ integer others than int and long and that they handle them in predictable
+ ways.
+
+ NonStandardInteger is the minimal legal specification for a custom Integral.
+ As such, it does not support 0 < x < 5 and it is not hashable.
+
+ Note: This is added here instead of relying on numpy or a similar library with
+ custom integers to limit dependencies.
+ """
+
+ def __init__(self, val, error_string_on_conversion=None):
+ assert isinstance(val, numbers.Integral)
+ if isinstance(val, NonStandardInteger):
+ val = val.val
+ self.val = val
+ self.error_string_on_conversion = error_string_on_conversion
+
+ def __long__(self):
+ if self.error_string_on_conversion:
+ raise RuntimeError(self.error_string_on_conversion)
+ return long(self.val)
+
+ def __abs__(self):
+ return NonStandardInteger(operator.abs(self.val))
+
+ def __add__(self, y):
+ return NonStandardInteger(operator.add(self.val, y))
+
+ def __div__(self, y):
+ return NonStandardInteger(operator.div(self.val, y))
+
+ def __eq__(self, y):
+ return operator.eq(self.val, y)
+
+ def __floordiv__(self, y):
+ return NonStandardInteger(operator.floordiv(self.val, y))
+
+ def __truediv__(self, y):
+ return NonStandardInteger(operator.truediv(self.val, y))
+
+ def __invert__(self):
+ return NonStandardInteger(operator.invert(self.val))
+
+ def __mod__(self, y):
+ return NonStandardInteger(operator.mod(self.val, y))
+
+ def __mul__(self, y):
+ return NonStandardInteger(operator.mul(self.val, y))
+
+ def __neg__(self):
+ return NonStandardInteger(operator.neg(self.val))
+
+ def __pos__(self):
+ return NonStandardInteger(operator.pos(self.val))
+
+ def __pow__(self, y):
+ return NonStandardInteger(operator.pow(self.val, y))
+
+ def __trunc__(self):
+ return int(self.val)
+
+ def __radd__(self, y):
+ return NonStandardInteger(operator.add(y, self.val))
+
+ def __rdiv__(self, y):
+ return NonStandardInteger(operator.div(y, self.val))
+
+ def __rmod__(self, y):
+ return NonStandardInteger(operator.mod(y, self.val))
+
+ def __rmul__(self, y):
+ return NonStandardInteger(operator.mul(y, self.val))
+
+ def __rpow__(self, y):
+ return NonStandardInteger(operator.pow(y, self.val))
+
+ def __rfloordiv__(self, y):
+ return NonStandardInteger(operator.floordiv(y, self.val))
+
+ def __rtruediv__(self, y):
+ return NonStandardInteger(operator.truediv(y, self.val))
+
+ def __lshift__(self, y):
+ return NonStandardInteger(operator.lshift(self.val, y))
+
+ def __rshift__(self, y):
+ return NonStandardInteger(operator.rshift(self.val, y))
+
+ def __rlshift__(self, y):
+ return NonStandardInteger(operator.lshift(y, self.val))
+
+ def __rrshift__(self, y):
+ return NonStandardInteger(operator.rshift(y, self.val))
+
+ def __le__(self, y):
+ if isinstance(y, NonStandardInteger):
+ y = y.val
+ return operator.le(self.val, y)
+
+ def __lt__(self, y):
+ if isinstance(y, NonStandardInteger):
+ y = y.val
+ return operator.lt(self.val, y)
+
+ def __and__(self, y):
+ return NonStandardInteger(operator.and_(self.val, y))
+
+ def __or__(self, y):
+ return NonStandardInteger(operator.or_(self.val, y))
+
+ def __xor__(self, y):
+ return NonStandardInteger(operator.xor(self.val, y))
+
+ def __rand__(self, y):
+ return NonStandardInteger(operator.and_(y, self.val))
+
+ def __ror__(self, y):
+ return NonStandardInteger(operator.or_(y, self.val))
+
+ def __rxor__(self, y):
+ return NonStandardInteger(operator.xor(y, self.val))
+
+ def __bool__(self):
+ return self.val
+
+ def __nonzero__(self):
+ return self.val
+
+ def __ceil__(self):
+ return self
+
+ def __floor__(self):
+ return self
+
+ def __int__(self):
+ if self.error_string_on_conversion:
+ raise RuntimeError(self.error_string_on_conversion)
+ return int(self.val)
+
+ def __round__(self):
+ return self
+
+ def __repr__(self):
+ return 'NonStandardInteger(%s)' % self.val
+
diff --git a/third_party/protobuf/python/google/protobuf/internal/testing_refleaks.py b/third_party/protobuf/python/google/protobuf/internal/testing_refleaks.py
new file mode 100644
index 0000000000..8ce06519bc
--- /dev/null
+++ b/third_party/protobuf/python/google/protobuf/internal/testing_refleaks.py
@@ -0,0 +1,126 @@
+# 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 gc
+import sys
+
+try:
+ import copy_reg as copyreg #PY26
+except ImportError:
+ import copyreg
+
+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 = copyreg.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):
+ copyreg.dispatch_table.clear()
+ copyreg.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/third_party/protobuf/3.0.0/python/google/protobuf/internal/text_encoding_test.py b/third_party/protobuf/python/google/protobuf/internal/text_encoding_test.py
index c7d182c444..c7d182c444 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/text_encoding_test.py
+++ b/third_party/protobuf/python/google/protobuf/internal/text_encoding_test.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/text_format_test.py b/third_party/protobuf/python/google/protobuf/internal/text_format_test.py
index 0e38e0e9e9..176cbd151a 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/text_format_test.py
+++ b/third_party/protobuf/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
@@ -581,22 +582,20 @@ class OnlyWorksWithProto2RightNowTests(TextFormatBase):
% (letter,) for letter in string.ascii_uppercase))
self.CompareToGoldenText(text_format.MessageToString(message), golden)
- def testMapOrderSemantics(self):
- golden_lines = self.ReadGolden('map_test_data.txt')
- # The C++ implementation emits defaulted-value fields, while the Python
- # implementation does not. Adjusting for this is awkward, but it is
- # valuable to test against a common golden file.
- line_blacklist = (' key: 0\n', ' value: 0\n', ' key: false\n',
- ' value: false\n')
- golden_lines = [line for line in golden_lines if line not in line_blacklist]
+ # TODO(teboring): In c/137553523, not serializing default value for map entry
+ # message has been fixed. This test needs to be disabled in order to submit
+ # that cl. Add this back when c/137553523 has been submitted.
+ # def testMapOrderSemantics(self):
+ # golden_lines = self.ReadGolden('map_test_data.txt')
- message = map_unittest_pb2.TestMap()
- text_format.ParseLines(golden_lines, message)
- candidate = text_format.MessageToString(message)
- # The Python implementation emits "1.0" for the double value that the C++
- # implementation emits as "1".
- candidate = candidate.replace('1.0', '1', 2)
- self.assertMultiLineEqual(candidate, ''.join(golden_lines))
+ # message = map_unittest_pb2.TestMap()
+ # text_format.ParseLines(golden_lines, message)
+ # candidate = text_format.MessageToString(message)
+ # # The Python implementation emits "1.0" for the double value that the C++
+ # # implementation emits as "1".
+ # candidate = candidate.replace('1.0', '1', 2)
+ # candidate = candidate.replace('0.0', '0', 2)
+ # self.assertMultiLineEqual(candidate, ''.join(golden_lines))
# Tests of proto2-only features (MessageSet, extensions, etc.).
@@ -684,6 +683,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 +1198,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 +1243,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/third_party/protobuf/3.0.0/python/google/protobuf/internal/type_checkers.py b/third_party/protobuf/python/google/protobuf/internal/type_checkers.py
index 1be3ad9a3c..4a76cd4ef6 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/type_checkers.py
+++ b/third_party/protobuf/python/google/protobuf/internal/type_checkers.py
@@ -45,6 +45,7 @@ TYPE_TO_DESERIALIZE_METHOD: A dictionary with field types and deserialization
__author__ = 'robinson@google.com (Will Robinson)'
+import numbers
import six
if six.PY3:
@@ -126,11 +127,11 @@ class IntValueChecker(object):
"""Checker used for integer fields. Performs type-check and range check."""
def CheckValue(self, proposed_value):
- if not isinstance(proposed_value, six.integer_types):
+ if not isinstance(proposed_value, numbers.Integral):
message = ('%.1024r has type %s, but expected one of: %s' %
(proposed_value, type(proposed_value), six.integer_types))
raise TypeError(message)
- if not self._MIN <= proposed_value <= self._MAX:
+ if not self._MIN <= int(proposed_value) <= self._MAX:
raise ValueError('Value out of range: %d' % proposed_value)
# We force 32-bit values to int and 64-bit values to long to make
# alternate implementations where the distinction is more significant
@@ -150,11 +151,11 @@ class EnumValueChecker(object):
self._enum_type = enum_type
def CheckValue(self, proposed_value):
- if not isinstance(proposed_value, six.integer_types):
+ if not isinstance(proposed_value, numbers.Integral):
message = ('%.1024r has type %s, but expected one of: %s' %
(proposed_value, type(proposed_value), six.integer_types))
raise TypeError(message)
- if proposed_value not in self._enum_type.values_by_number:
+ if int(proposed_value) not in self._enum_type.values_by_number:
raise ValueError('Unknown enum value: %d' % proposed_value)
return proposed_value
@@ -223,11 +224,11 @@ _VALUE_CHECKERS = {
_FieldDescriptor.CPPTYPE_UINT32: Uint32ValueChecker(),
_FieldDescriptor.CPPTYPE_UINT64: Uint64ValueChecker(),
_FieldDescriptor.CPPTYPE_DOUBLE: TypeCheckerWithDefault(
- 0.0, float, int, long),
+ 0.0, numbers.Real),
_FieldDescriptor.CPPTYPE_FLOAT: TypeCheckerWithDefault(
- 0.0, float, int, long),
+ 0.0, numbers.Real),
_FieldDescriptor.CPPTYPE_BOOL: TypeCheckerWithDefault(
- False, bool, int),
+ False, bool, numbers.Integral),
_FieldDescriptor.CPPTYPE_STRING: TypeCheckerWithDefault(b'', bytes),
}
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/unknown_fields_test.py b/third_party/protobuf/python/google/protobuf/internal/unknown_fields_test.py
index 84073f1c53..d614eaa874 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/unknown_fields_test.py
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/python/google/protobuf/internal/well_known_types.py b/third_party/protobuf/python/google/protobuf/internal/well_known_types.py
index 7c5dffd0fc..d631abeeaa 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/well_known_types.py
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/python/google/protobuf/internal/well_known_types_test.py b/third_party/protobuf/python/google/protobuf/internal/well_known_types_test.py
index 2f32ac9941..077f630f71 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/well_known_types_test.py
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/python/google/protobuf/internal/wire_format.py b/third_party/protobuf/python/google/protobuf/internal/wire_format.py
index 883f525585..883f525585 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/wire_format.py
+++ b/third_party/protobuf/python/google/protobuf/internal/wire_format.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/internal/wire_format_test.py b/third_party/protobuf/python/google/protobuf/internal/wire_format_test.py
index da120f3361..da120f3361 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/internal/wire_format_test.py
+++ b/third_party/protobuf/python/google/protobuf/internal/wire_format_test.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/json_format.py b/third_party/protobuf/python/google/protobuf/json_format.py
index bb6a19986e..d02cb09156 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/json_format.py
+++ b/third_party/protobuf/python/google/protobuf/json_format.py
@@ -43,9 +43,9 @@ Simple usage example:
__author__ = 'jieluo@google.com (Jie Luo)'
try:
- from collections import OrderedDict
+ from collections import OrderedDict
except ImportError:
- from ordereddict import OrderedDict #PY26
+ from ordereddict import OrderedDict #PY26
import base64
import json
import math
@@ -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
@@ -310,7 +348,7 @@ def Parse(text, message, ignore_unknown_fields=False):
Args:
text: Message JSON representation.
- message: A protocol beffer message to merge into.
+ message: A protocol buffer message to merge into.
ignore_unknown_fields: If True, do not raise errors for unknown fields.
Returns:
@@ -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/third_party/protobuf/3.0.0/python/google/protobuf/message.py b/third_party/protobuf/python/google/protobuf/message.py
index 606f735f3e..aab250e422 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/message.py
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/python/google/protobuf/message_factory.py b/third_party/protobuf/python/google/protobuf/message_factory.py
index 1b059d130b..8ab1c513d1 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/message_factory.py
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/python/google/protobuf/proto_builder.py b/third_party/protobuf/python/google/protobuf/proto_builder.py
index 736caed385..736caed385 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/proto_builder.py
+++ b/third_party/protobuf/python/google/protobuf/proto_builder.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/README b/third_party/protobuf/python/google/protobuf/pyext/README
index 6d61cb45bf..6d61cb45bf 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/README
+++ b/third_party/protobuf/python/google/protobuf/pyext/README
diff --git a/third_party/protobuf/python/google/protobuf/pyext/__init__.py b/third_party/protobuf/python/google/protobuf/pyext/__init__.py
new file mode 100644
index 0000000000..5585614122
--- /dev/null
+++ b/third_party/protobuf/python/google/protobuf/pyext/__init__.py
@@ -0,0 +1,4 @@
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ __path__ = __import__('pkgutil').extend_path(__path__, __name__)
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/cpp_message.py b/third_party/protobuf/python/google/protobuf/pyext/cpp_message.py
index fc8eb32d79..fc8eb32d79 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/cpp_message.py
+++ b/third_party/protobuf/python/google/protobuf/pyext/cpp_message.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor.cc b/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc
index e6ef5ef50a..924ae0b9cd 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor.cc
+++ b/third_party/protobuf/python/google/protobuf/pyext/descriptor.cc
@@ -41,6 +41,7 @@
#include <google/protobuf/pyext/descriptor_containers.h>
#include <google/protobuf/pyext/descriptor_pool.h>
#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
#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<const uint8*>(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/third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor.h b/third_party/protobuf/python/google/protobuf/pyext/descriptor.h
index 1ae0e672ed..1ae0e672ed 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor.h
+++ b/third_party/protobuf/python/google/protobuf/pyext/descriptor.h
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_containers.cc b/third_party/protobuf/python/google/protobuf/pyext/descriptor_containers.cc
index d0aae9c9b3..d0aae9c9b3 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_containers.cc
+++ b/third_party/protobuf/python/google/protobuf/pyext/descriptor_containers.cc
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_containers.h b/third_party/protobuf/python/google/protobuf/pyext/descriptor_containers.h
index 83de07b68c..83de07b68c 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_containers.h
+++ b/third_party/protobuf/python/google/protobuf/pyext/descriptor_containers.h
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_database.cc b/third_party/protobuf/python/google/protobuf/pyext/descriptor_database.cc
index daa40cc720..daa40cc720 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_database.cc
+++ b/third_party/protobuf/python/google/protobuf/pyext/descriptor_database.cc
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_database.h b/third_party/protobuf/python/google/protobuf/pyext/descriptor_database.h
index fc71c4bcb0..fc71c4bcb0 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_database.h
+++ b/third_party/protobuf/python/google/protobuf/pyext/descriptor_database.h
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_pool.cc b/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc
index cfd9869030..fa66bf9ace 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_pool.cc
+++ b/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc
@@ -33,11 +33,11 @@
#include <Python.h>
#include <google/protobuf/descriptor.pb.h>
-#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/pyext/descriptor.h>
#include <google/protobuf/pyext/descriptor_database.h>
#include <google/protobuf/pyext/descriptor_pool.h>
#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
#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<const void*, PyObject *>();
+ 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<const void*, PyObject*>::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<PyObject*>(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<iterator, bool> 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);
}
@@ -356,6 +319,51 @@ PyObject* FindFileContainingSymbol(PyDescriptorPool* self, PyObject* arg) {
return PyFileDescriptor_FromDescriptor(file_descriptor);
}
+PyObject* FindExtensionByNumber(PyDescriptorPool* self, PyObject* args) {
+ PyObject* message_descriptor;
+ int number;
+ if (!PyArg_ParseTuple(args, "Oi", &message_descriptor, &number)) {
+ return NULL;
+ }
+ const Descriptor* descriptor = PyMessageDescriptor_AsDescriptor(
+ message_descriptor);
+ if (descriptor == NULL) {
+ return NULL;
+ }
+
+ const FieldDescriptor* extension_descriptor =
+ self->pool->FindExtensionByNumber(descriptor, number);
+ if (extension_descriptor == NULL) {
+ PyErr_Format(PyExc_KeyError, "Couldn't find extension %d", number);
+ return NULL;
+ }
+
+ return PyFieldDescriptor_FromDescriptor(extension_descriptor);
+}
+
+PyObject* FindAllExtensions(PyDescriptorPool* self, PyObject* arg) {
+ const Descriptor* descriptor = PyMessageDescriptor_AsDescriptor(arg);
+ if (descriptor == NULL) {
+ return NULL;
+ }
+
+ std::vector<const FieldDescriptor*> extensions;
+ self->pool->FindAllExtensions(descriptor, &extensions);
+
+ ScopedPyObjectPtr result(PyList_New(extensions.size()));
+ if (result == NULL) {
+ return NULL;
+ }
+ for (int i = 0; i < extensions.size(); i++) {
+ PyObject* extension = PyFieldDescriptor_FromDescriptor(extensions[i]);
+ if (extension == NULL) {
+ return NULL;
+ }
+ PyList_SET_ITEM(result.get(), i, extension); // Steals the reference.
+ }
+ return result.release();
+}
+
// These functions should not exist -- the only valid way to create
// descriptors is to call Add() or AddSerializedFile().
// But these AddDescriptor() functions were created in Python and some people
@@ -413,6 +421,22 @@ PyObject* AddEnumDescriptor(PyDescriptorPool* self, PyObject* descriptor) {
Py_RETURN_NONE;
}
+PyObject* AddExtensionDescriptor(PyDescriptorPool* self, PyObject* descriptor) {
+ const FieldDescriptor* extension_descriptor =
+ PyFieldDescriptor_AsDescriptor(descriptor);
+ if (!extension_descriptor) {
+ return NULL;
+ }
+ if (extension_descriptor !=
+ self->pool->FindExtensionByName(extension_descriptor->full_name())) {
+ PyErr_Format(PyExc_ValueError,
+ "The extension descriptor %s does not belong to this pool",
+ extension_descriptor->full_name().c_str());
+ return NULL;
+ }
+ Py_RETURN_NONE;
+}
+
// The code below loads new Descriptors from a serialized FileDescriptorProto.
@@ -512,6 +536,8 @@ static PyMethodDef Methods[] = {
"No-op. Add() must have been called before." },
{ "AddEnumDescriptor", (PyCFunction)AddEnumDescriptor, METH_O,
"No-op. Add() must have been called before." },
+ { "AddExtensionDescriptor", (PyCFunction)AddExtensionDescriptor, METH_O,
+ "No-op. Add() must have been called before." },
{ "FindFileByName", (PyCFunction)FindFileByName, METH_O,
"Searches for a file descriptor by its .proto name." },
@@ -532,6 +558,10 @@ static PyMethodDef Methods[] = {
{ "FindFileContainingSymbol", (PyCFunction)FindFileContainingSymbol, METH_O,
"Gets the FileDescriptor containing the specified symbol." },
+ { "FindExtensionByNumber", (PyCFunction)FindExtensionByNumber, METH_VARARGS,
+ "Gets the extension descriptor for the given number." },
+ { "FindAllExtensions", (PyCFunction)FindAllExtensions, METH_O,
+ "Gets all known extensions of the given message descriptor." },
{NULL}
};
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_pool.h b/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.h
index 2a42c11262..c4d7d40343 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/descriptor_pool.h
+++ b/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.h
@@ -38,10 +38,10 @@
namespace google {
namespace protobuf {
-class MessageFactory;
-
namespace python {
+struct 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<const Descriptor*, CMessageClass*> 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/third_party/protobuf/3.0.0/python/google/protobuf/pyext/extension_dict.cc b/third_party/protobuf/python/google/protobuf/pyext/extension_dict.cc
index 21bbb8c2b1..43ee5d15f4 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/extension_dict.cc
+++ b/third_party/protobuf/python/google/protobuf/pyext/extension_dict.cc
@@ -38,14 +38,25 @@
#include <google/protobuf/descriptor.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/message.h>
+#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/pyext/descriptor.h>
-#include <google/protobuf/pyext/descriptor_pool.h>
#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
#include <google/protobuf/pyext/repeated_composite_container.h>
#include <google/protobuf/pyext/repeated_scalar_container.h>
#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
#include <google/protobuf/stubs/shared_ptr.h>
+#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 {
@@ -60,35 +71,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<RepeatedCompositeContainer*>(
- extension)) < 0) {
- return -1;
- }
- } else {
- if (repeated_scalar_container::Release(
- reinterpret_cast<RepeatedScalarContainer*>(
- extension)) < 0) {
- return -1;
- }
- }
- } else if (descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
- if (cmessage::ReleaseSubMessage(
- self->parent, descriptor,
- reinterpret_cast<CMessage*>(extension)) < 0) {
- return -1;
- }
- }
-
- return 0;
-}
-
PyObject* subscript(ExtensionDict* self, PyObject* key) {
const FieldDescriptor* descriptor = cmessage::GetExtensionDescriptor(key);
if (descriptor == NULL) {
@@ -119,6 +101,7 @@ PyObject* subscript(ExtensionDict* self, PyObject* key) {
if (descriptor->label() != FieldDescriptor::LABEL_REPEATED &&
descriptor->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
+ // TODO(plabatut): consider building the class on the fly!
PyObject* sub_message = cmessage::InternalGetSubMessage(
self->parent, descriptor);
if (sub_message == NULL) {
@@ -130,9 +113,21 @@ 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),
+ // On the fly message class creation is needed to support the following
+ // situation:
+ // 1- add FileDescriptor to the pool that contains extensions of a message
+ // defined by another proto file. Do not create any message classes.
+ // 2- instantiate an extended message, and access the extension using
+ // the field descriptor.
+ // 3- the extension submessage fails to be returned, because no class has
+ // been created.
+ // It happens when deserializing text proto format, or when enumerating
+ // fields of a deserialized message.
+ CMessageClass* message_class = message_factory::GetOrCreateMessageClass(
+ cmessage::GetFactoryForMessage(self->parent),
descriptor->message_type());
+ ScopedPyObjectPtr message_class_handler(
+ reinterpret_cast<PyObject*>(message_class));
if (message_class == NULL) {
return NULL;
}
@@ -183,75 +178,51 @@ 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) {
+PyObject* _FindExtensionByName(ExtensionDict* self, PyObject* arg) {
+ char* name;
+ Py_ssize_t name_size;
+ if (PyString_AsStringAndSize(arg, &name, &name_size) < 0) {
return NULL;
}
- PyObject* value = PyDict_GetItem(self->values, extension);
- if (self->parent) {
- if (value != NULL) {
- if (ReleaseExtension(self, value, descriptor) < 0) {
- return NULL;
+
+ PyDescriptorPool* pool = cmessage::GetFactoryForMessage(self->parent)->pool;
+ const FieldDescriptor* message_extension =
+ pool->pool->FindExtensionByName(string(name, name_size));
+ if (message_extension == NULL) {
+ // Is is the name of a message set extension?
+ const Descriptor* message_descriptor = pool->pool->FindMessageTypeByName(
+ string(name, name_size));
+ if (message_descriptor && message_descriptor->extension_count() > 0) {
+ const FieldDescriptor* extension = message_descriptor->extension(0);
+ if (extension->is_extension() &&
+ extension->containing_type()->options().message_set_wire_format() &&
+ extension->type() == FieldDescriptor::TYPE_MESSAGE &&
+ extension->label() == FieldDescriptor::LABEL_OPTIONAL) {
+ message_extension = extension;
}
}
- if (ScopedPyObjectPtr(cmessage::ClearFieldByDescriptor(
- self->parent, descriptor)) == NULL) {
- return NULL;
- }
}
- if (PyDict_DelItem(self->values, extension) < 0) {
- PyErr_Clear();
+ if (message_extension == NULL) {
+ Py_RETURN_NONE;
}
- 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);
- }
+ return PyFieldDescriptor_FromDescriptor(message_extension);
}
-PyObject* _FindExtensionByName(ExtensionDict* self, PyObject* name) {
- ScopedPyObjectPtr extensions_by_name(PyObject_GetAttrString(
- reinterpret_cast<PyObject*>(self->parent), "_extensions_by_name"));
- if (extensions_by_name == NULL) {
+PyObject* _FindExtensionByNumber(ExtensionDict* self, PyObject* arg) {
+ int64 number = PyLong_AsLong(arg);
+ if (number == -1 && PyErr_Occurred()) {
return NULL;
}
- PyObject* result = PyDict_GetItem(extensions_by_name.get(), name);
- if (result == NULL) {
- Py_RETURN_NONE;
- } else {
- Py_INCREF(result);
- return result;
- }
-}
-PyObject* _FindExtensionByNumber(ExtensionDict* self, PyObject* number) {
- ScopedPyObjectPtr extensions_by_number(PyObject_GetAttrString(
- reinterpret_cast<PyObject*>(self->parent), "_extensions_by_number"));
- if (extensions_by_number == NULL) {
- return NULL;
- }
- PyObject* result = PyDict_GetItem(extensions_by_number.get(), number);
- if (result == NULL) {
+ PyDescriptorPool* pool = cmessage::GetFactoryForMessage(self->parent)->pool;
+ const FieldDescriptor* message_extension = pool->pool->FindExtensionByNumber(
+ self->parent->message->GetDescriptor(), number);
+ if (message_extension == NULL) {
Py_RETURN_NONE;
- } else {
- Py_INCREF(result);
- return result;
}
+
+ return PyFieldDescriptor_FromDescriptor(message_extension);
}
ExtensionDict* NewExtensionDict(CMessage *parent) {
@@ -282,8 +253,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/third_party/protobuf/3.0.0/python/google/protobuf/pyext/extension_dict.h b/third_party/protobuf/python/google/protobuf/pyext/extension_dict.h
index 2456eda1e6..65b878625a 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/extension_dict.h
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/python/google/protobuf/pyext/map_container.cc b/third_party/protobuf/python/google/protobuf/pyext/map_container.cc
index 0987b89832..088ddf9353 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/map_container.cc
+++ b/third_party/protobuf/python/google/protobuf/pyext/map_container.cc
@@ -42,7 +42,9 @@
#include <google/protobuf/map_field.h>
#include <google/protobuf/map.h>
#include <google/protobuf/message.h>
+#include <google/protobuf/pyext/message_factory.h>
#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/repeated_composite_container.h>
#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
#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<PyObject*>(message_class);
+}
+
PyObject* MapReflectionFriend::Contains(PyObject* _self, PyObject* key) {
MapContainer* self = GetMap(_self);
@@ -363,7 +374,7 @@ static int InitializeAndCopyToParentContainer(MapContainer* from,
// A somewhat roundabout way of copying just one field from old_message to
// new_message. This is the best we can do with what Reflection gives us.
Message* mutable_old = from->GetMutableMessage();
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
fields.push_back(from->parent_field_descriptor);
// Move the map field into the new message.
@@ -400,12 +411,7 @@ PyObject *NewScalarMapContainer(
return NULL;
}
-#if PY_MAJOR_VERSION >= 3
- ScopedPyObjectPtr obj(PyType_GenericAlloc(
- reinterpret_cast<PyTypeObject *>(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<PyTypeObject *>(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<PyTypeObject*>(
+ PyType_FromSpecWithBases(&ScalarMapContainer_Type_spec, bases));
+#else
+ _ScalarMapContainer_Type.tp_base =
+ reinterpret_cast<PyTypeObject*>(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<PyTypeObject*>(
+ PyType_FromSpecWithBases(&MessageMapContainer_Type_spec, bases));
+#else
+ Py_INCREF(mutable_mapping.get());
+ _MessageMapContainer_Type.tp_base =
+ reinterpret_cast<PyTypeObject*>(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/third_party/protobuf/3.0.0/python/google/protobuf/pyext/map_container.h b/third_party/protobuf/python/google/protobuf/pyext/map_container.h
index fbd6713f73..615657b03b 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/map_container.h
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/python/google/protobuf/pyext/message.cc b/third_party/protobuf/python/google/protobuf/pyext/message.cc
index 5535338d44..c810b7885f 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/message.cc
+++ b/third_party/protobuf/python/google/protobuf/pyext/message.cc
@@ -63,11 +63,12 @@
#include <google/protobuf/pyext/repeated_composite_container.h>
#include <google/protobuf/pyext/repeated_scalar_container.h>
#include <google/protobuf/pyext/map_container.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/pyext/safe_numerics.h>
#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
#include <google/protobuf/stubs/strutil.h>
#if PY_MAJOR_VERSION >= 3
- #define PyInt_Check PyLong_Check
#define PyInt_AsLong PyLong_AsLong
#define PyInt_FromLong PyLong_FromLong
#define PyInt_FromSize_t PyLong_FromSize_t
@@ -91,8 +92,6 @@ namespace protobuf {
namespace python {
static PyObject* kDESCRIPTOR;
-static PyObject* k_extensions_by_name;
-static PyObject* k_extensions_by_number;
PyObject* EnumTypeWrapper_class;
static PyObject* PythonMessage_class;
static PyObject* kEmptyWeakref;
@@ -127,19 +126,6 @@ static bool AddFieldNumberToClass(
// Finalize the creation of the Message class.
static int AddDescriptors(PyObject* cls, const Descriptor* descriptor) {
- // If there are extension_ranges, the message is "extendable", and extension
- // classes will register themselves in this class.
- if (descriptor->extension_range_count() > 0) {
- ScopedPyObjectPtr by_name(PyDict_New());
- if (PyObject_SetAttr(cls, k_extensions_by_name, by_name.get()) < 0) {
- return -1;
- }
- ScopedPyObjectPtr by_number(PyDict_New());
- if (PyObject_SetAttr(cls, k_extensions_by_number, by_number.get()) < 0) {
- return -1;
- }
- }
-
// For each field set: cls.<field>_FIELD_NUMBER = <number>
for (int i = 0; i < descriptor->field_count(); ++i) {
if (!AddFieldNumberToClass(cls, descriptor->field(i))) {
@@ -244,6 +230,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 +292,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 +316,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<PyObject*>(self));
}
@@ -347,6 +342,61 @@ static int InsertEmptyWeakref(PyTypeObject *base_type) {
#endif // PY_MAJOR_VERSION >= 3
}
+// The _extensions_by_name dictionary is built on every access.
+// TODO(amauryfa): Migrate all users to pool.FindAllExtensions()
+static PyObject* GetExtensionsByName(CMessageClass *self, void *closure) {
+ const PyDescriptorPool* pool = self->py_message_factory->pool;
+
+ std::vector<const FieldDescriptor*> extensions;
+ pool->pool->FindAllExtensions(self->message_descriptor, &extensions);
+
+ ScopedPyObjectPtr result(PyDict_New());
+ for (int i = 0; i < extensions.size(); i++) {
+ ScopedPyObjectPtr extension(
+ PyFieldDescriptor_FromDescriptor(extensions[i]));
+ if (extension == NULL) {
+ return NULL;
+ }
+ if (PyDict_SetItemString(result.get(), extensions[i]->full_name().c_str(),
+ extension.get()) < 0) {
+ return NULL;
+ }
+ }
+ return result.release();
+}
+
+// The _extensions_by_number dictionary is built on every access.
+// TODO(amauryfa): Migrate all users to pool.FindExtensionByNumber()
+static PyObject* GetExtensionsByNumber(CMessageClass *self, void *closure) {
+ const PyDescriptorPool* pool = self->py_message_factory->pool;
+
+ std::vector<const FieldDescriptor*> extensions;
+ pool->pool->FindAllExtensions(self->message_descriptor, &extensions);
+
+ ScopedPyObjectPtr result(PyDict_New());
+ for (int i = 0; i < extensions.size(); i++) {
+ ScopedPyObjectPtr extension(
+ PyFieldDescriptor_FromDescriptor(extensions[i]));
+ if (extension == NULL) {
+ return NULL;
+ }
+ ScopedPyObjectPtr number(PyInt_FromLong(extensions[i]->number()));
+ if (number == NULL) {
+ return NULL;
+ }
+ if (PyDict_SetItem(result.get(), number.get(), extension.get()) < 0) {
+ return NULL;
+ }
+ }
+ return result.release();
+}
+
+static PyGetSetDef Getters[] = {
+ {"_extensions_by_name", (getter)GetExtensionsByName, NULL},
+ {"_extensions_by_number", (getter)GetExtensionsByNumber, NULL},
+ {NULL}
+};
+
} // namespace message_meta
PyTypeObject CMessageClass_Type = {
@@ -379,7 +429,7 @@ PyTypeObject CMessageClass_Type = {
0, // tp_iternext
0, // tp_methods
0, // tp_members
- 0, // tp_getset
+ message_meta::Getters, // tp_getset
0, // tp_base
0, // tp_dict
0, // tp_descr_get
@@ -515,23 +565,10 @@ int ForEachCompositeField(CMessage* self, Visitor visitor) {
// ---------------------------------------------------------------------
-// Constants used for integer type range checking.
-PyObject* kPythonZero;
-PyObject* kint32min_py;
-PyObject* kint32max_py;
-PyObject* kuint32max_py;
-PyObject* kint64min_py;
-PyObject* kint64max_py;
-PyObject* kuint64max_py;
-
PyObject* EncodeError_class;
PyObject* DecodeError_class;
PyObject* PickleError_class;
-// Constant PyString values used for GetAttr/GetItem.
-static PyObject* k_cdescriptor;
-static PyObject* kfull_name;
-
/* Is 64bit */
void FormatTypeError(PyObject* arg, char* expected_types) {
PyObject* repr = PyObject_Repr(arg);
@@ -545,68 +582,126 @@ void FormatTypeError(PyObject* arg, char* expected_types) {
}
}
-template<class T>
-bool CheckAndGetInteger(
- PyObject* arg, T* value, PyObject* min, PyObject* max) {
- bool is_long = PyLong_Check(arg);
-#if PY_MAJOR_VERSION < 3
- if (!PyInt_Check(arg) && !is_long) {
- FormatTypeError(arg, "int, long");
- return false;
+void OutOfRangeError(PyObject* arg) {
+ PyObject *s = PyObject_Str(arg);
+ if (s) {
+ PyErr_Format(PyExc_ValueError,
+ "Value out of range: %s",
+ PyString_AsString(s));
+ Py_DECREF(s);
}
- if (PyObject_Compare(min, arg) > 0 || PyObject_Compare(max, arg) < 0) {
-#else
- if (!is_long) {
- FormatTypeError(arg, "int");
+}
+
+template<class RangeType, class ValueType>
+bool VerifyIntegerCastAndRange(PyObject* arg, ValueType value) {
+ if GOOGLE_PREDICT_FALSE(value == -1 && PyErr_Occurred()) {
+ if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
+ // Replace it with the same ValueError as pure python protos instead of
+ // the default one.
+ PyErr_Clear();
+ OutOfRangeError(arg);
+ } // Otherwise propagate existing error.
return false;
}
- if (PyObject_RichCompareBool(min, arg, Py_LE) != 1 ||
- PyObject_RichCompareBool(max, arg, Py_GE) != 1) {
-#endif
- if (!PyErr_Occurred()) {
- PyObject *s = PyObject_Str(arg);
- if (s) {
- PyErr_Format(PyExc_ValueError,
- "Value out of range: %s",
- PyString_AsString(s));
- Py_DECREF(s);
- }
- }
+ if GOOGLE_PREDICT_FALSE(!IsValidNumericCast<RangeType>(value)) {
+ OutOfRangeError(arg);
return false;
}
+ return true;
+}
+
+template<class T>
+bool CheckAndGetInteger(PyObject* arg, T* value) {
+ // The fast path.
#if PY_MAJOR_VERSION < 3
- if (!is_long) {
- *value = static_cast<T>(PyInt_AsLong(arg));
- } else // NOLINT
+ // For the typical case, offer a fast path.
+ if GOOGLE_PREDICT_TRUE(PyInt_Check(arg)) {
+ long int_result = PyInt_AsLong(arg);
+ if GOOGLE_PREDICT_TRUE(IsValidNumericCast<T>(int_result)) {
+ *value = static_cast<T>(int_result);
+ return true;
+ } else {
+ OutOfRangeError(arg);
+ return false;
+ }
+ }
#endif
- {
- if (min == kPythonZero) {
- *value = static_cast<T>(PyLong_AsUnsignedLongLong(arg));
+ // This effectively defines an integer as "an object that can be cast as
+ // an integer and can be used as an ordinal number".
+ // This definition includes everything that implements numbers.Integral
+ // and shouldn't cast the net too wide.
+ if GOOGLE_PREDICT_FALSE(!PyIndex_Check(arg)) {
+ FormatTypeError(arg, "int, long");
+ return false;
+ }
+
+ // Now we have an integral number so we can safely use PyLong_ functions.
+ // We need to treat the signed and unsigned cases differently in case arg is
+ // holding a value above the maximum for signed longs.
+ if (std::numeric_limits<T>::min() == 0) {
+ // Unsigned case.
+ unsigned PY_LONG_LONG ulong_result;
+ if (PyLong_Check(arg)) {
+ ulong_result = PyLong_AsUnsignedLongLong(arg);
+ } else {
+ // Unlike PyLong_AsLongLong, PyLong_AsUnsignedLongLong is very
+ // picky about the exact type.
+ PyObject* casted = PyNumber_Long(arg);
+ if GOOGLE_PREDICT_FALSE(casted == NULL) {
+ // Propagate existing error.
+ return false;
+ }
+ ulong_result = PyLong_AsUnsignedLongLong(casted);
+ Py_DECREF(casted);
+ }
+ if (VerifyIntegerCastAndRange<T, unsigned PY_LONG_LONG>(arg,
+ ulong_result)) {
+ *value = static_cast<T>(ulong_result);
+ } else {
+ return false;
+ }
+ } else {
+ // Signed case.
+ PY_LONG_LONG long_result;
+ PyNumberMethods *nb;
+ if ((nb = arg->ob_type->tp_as_number) != NULL && nb->nb_int != NULL) {
+ // PyLong_AsLongLong requires it to be a long or to have an __int__()
+ // method.
+ long_result = PyLong_AsLongLong(arg);
+ } else {
+ // Valid subclasses of numbers.Integral should have a __long__() method
+ // so fall back to that.
+ PyObject* casted = PyNumber_Long(arg);
+ if GOOGLE_PREDICT_FALSE(casted == NULL) {
+ // Propagate existing error.
+ return false;
+ }
+ long_result = PyLong_AsLongLong(casted);
+ Py_DECREF(casted);
+ }
+ if (VerifyIntegerCastAndRange<T, PY_LONG_LONG>(arg, long_result)) {
+ *value = static_cast<T>(long_result);
} else {
- *value = static_cast<T>(PyLong_AsLongLong(arg));
+ return false;
}
}
+
return true;
}
// These are referenced by repeated_scalar_container, and must
// be explicitly instantiated.
-template bool CheckAndGetInteger<int32>(
- PyObject*, int32*, PyObject*, PyObject*);
-template bool CheckAndGetInteger<int64>(
- PyObject*, int64*, PyObject*, PyObject*);
-template bool CheckAndGetInteger<uint32>(
- PyObject*, uint32*, PyObject*, PyObject*);
-template bool CheckAndGetInteger<uint64>(
- PyObject*, uint64*, PyObject*, PyObject*);
+template bool CheckAndGetInteger<int32>(PyObject*, int32*);
+template bool CheckAndGetInteger<int64>(PyObject*, int64*);
+template bool CheckAndGetInteger<uint32>(PyObject*, uint32*);
+template bool CheckAndGetInteger<uint64>(PyObject*, uint64*);
bool CheckAndGetDouble(PyObject* arg, double* value) {
- if (!PyInt_Check(arg) && !PyLong_Check(arg) &&
- !PyFloat_Check(arg)) {
+ *value = PyFloat_AsDouble(arg);
+ if GOOGLE_PREDICT_FALSE(*value == -1 && PyErr_Occurred()) {
FormatTypeError(arg, "int, long, float");
return false;
}
- *value = PyFloat_AsDouble(arg);
return true;
}
@@ -620,11 +715,13 @@ bool CheckAndGetFloat(PyObject* arg, float* value) {
}
bool CheckAndGetBool(PyObject* arg, bool* value) {
- if (!PyInt_Check(arg) && !PyBool_Check(arg) && !PyLong_Check(arg)) {
+ long long_value = PyInt_AsLong(arg);
+ if (long_value == -1 && PyErr_Occurred()) {
FormatTypeError(arg, "int, long, bool");
return false;
}
- *value = static_cast<bool>(PyInt_AsLong(arg));
+ *value = static_cast<bool>(long_value);
+
return true;
}
@@ -752,15 +849,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<CMessageClass*>(Py_TYPE(message))->py_descriptor_pool;
-}
-
-MessageFactory* GetFactoryForMessage(CMessage* message) {
- return GetDescriptorPoolForMessage(message)->message_factory;
+ return reinterpret_cast<CMessageClass*>(Py_TYPE(message))->py_message_factory;
}
static int MaybeReleaseOverlappingOneofField(
@@ -813,7 +904,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 {
@@ -961,20 +1053,7 @@ int InternalDeleteRepeatedField(
int min, max;
length = reflection->FieldSize(*message, field_descriptor);
- if (PyInt_Check(slice) || PyLong_Check(slice)) {
- from = to = PyLong_AsLong(slice);
- if (from < 0) {
- from = to = length + from;
- }
- step = 1;
- min = max = from;
-
- // Range check.
- if (from < 0 || from >= length) {
- PyErr_Format(PyExc_IndexError, "list assignment index out of range");
- return -1;
- }
- } else if (PySlice_Check(slice)) {
+ if (PySlice_Check(slice)) {
from = to = step = slice_length = 0;
PySlice_GetIndicesEx(
#if PY_MAJOR_VERSION < 3
@@ -991,8 +1070,23 @@ int InternalDeleteRepeatedField(
max = from;
}
} else {
- PyErr_SetString(PyExc_TypeError, "list indices must be integers");
- return -1;
+ from = to = PyLong_AsLong(slice);
+ if (from == -1 && PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError, "list indices must be integers");
+ return -1;
+ }
+
+ if (from < 0) {
+ from = to = length + from;
+ }
+ step = 1;
+ min = max = from;
+
+ // Range check.
+ if (from < 0 || from >= length) {
+ PyErr_Format(PyExc_IndexError, "list assignment index out of range");
+ return -1;
+ }
}
Py_ssize_t i = from;
@@ -1172,6 +1266,8 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs) {
}
CMessage* cmessage = reinterpret_cast<CMessage*>(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 +1327,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 +1388,9 @@ struct ClearWeakReferences : public ChildVisitor {
};
static void Dealloc(CMessage* self) {
+ if (self->weakreflist) {
+ PyObject_ClearWeakRefs(reinterpret_cast<PyObject*>(self));
+ }
// Null out all weak references from children to this message.
GOOGLE_CHECK_EQ(0, ForEachCompositeField(self, ClearWeakReferences()));
if (self->extensions) {
@@ -1459,18 +1558,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 +1657,7 @@ int SetOwner(CMessage* self, const shared_ptr<Message>& 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 +1725,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 +1773,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) {
@@ -1896,7 +1994,11 @@ static PyObject* CopyFrom(CMessage* self, PyObject* arg) {
// get OOM errors. The protobuf APIs do not provide any tools for processing
// protobufs in chunks. If you have protos this big you should break them up if
// it is at all convenient to do so.
+#ifdef PROTOBUF_PYTHON_ALLOW_OVERSIZE_PROTOS
+static bool allow_oversize_protos = true;
+#else
static bool allow_oversize_protos = false;
+#endif
// Provide a method in the module to set allow_oversize_protos to a boolean
// value. This method returns the newly value of allow_oversize_protos.
@@ -1927,8 +2029,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());
@@ -1949,99 +2051,29 @@ static PyObject* ByteSize(CMessage* self, PyObject* args) {
return PyLong_FromLong(self->message->ByteSize());
}
-static PyObject* RegisterExtension(PyObject* cls,
- PyObject* extension_handle) {
+PyObject* RegisterExtension(PyObject* cls, PyObject* extension_handle) {
const FieldDescriptor* descriptor =
GetExtensionDescriptor(extension_handle);
if (descriptor == NULL) {
return NULL;
}
-
- ScopedPyObjectPtr extensions_by_name(
- PyObject_GetAttr(cls, k_extensions_by_name));
- if (extensions_by_name == NULL) {
- PyErr_SetString(PyExc_TypeError, "no extensions_by_name on class");
+ if (!PyObject_TypeCheck(cls, &CMessageClass_Type)) {
+ PyErr_Format(PyExc_TypeError, "Expected a message class, got %s",
+ cls->ob_type->tp_name);
return NULL;
}
- ScopedPyObjectPtr full_name(PyObject_GetAttr(extension_handle, kfull_name));
- if (full_name == NULL) {
+ CMessageClass *message_class = reinterpret_cast<CMessageClass*>(cls);
+ if (message_class == NULL) {
return NULL;
}
-
// If the extension was already registered, check that it is the same.
- PyObject* existing_extension =
- PyDict_GetItem(extensions_by_name.get(), full_name.get());
- if (existing_extension != NULL) {
- const FieldDescriptor* existing_extension_descriptor =
- GetExtensionDescriptor(existing_extension);
- if (existing_extension_descriptor != descriptor) {
- PyErr_SetString(PyExc_ValueError, "Double registration of Extensions");
- return NULL;
- }
- // Nothing else to do.
- Py_RETURN_NONE;
- }
-
- if (PyDict_SetItem(extensions_by_name.get(), full_name.get(),
- extension_handle) < 0) {
- return NULL;
- }
-
- // Also store a mapping from extension number to implementing class.
- ScopedPyObjectPtr extensions_by_number(
- PyObject_GetAttr(cls, k_extensions_by_number));
- if (extensions_by_number == NULL) {
- PyErr_SetString(PyExc_TypeError, "no extensions_by_number on class");
+ const FieldDescriptor* existing_extension =
+ message_class->py_message_factory->pool->pool->FindExtensionByNumber(
+ descriptor->containing_type(), descriptor->number());
+ if (existing_extension != NULL && existing_extension != descriptor) {
+ PyErr_SetString(PyExc_ValueError, "Double registration of Extensions");
return NULL;
}
-
- ScopedPyObjectPtr number(PyObject_GetAttrString(extension_handle, "number"));
- if (number == NULL) {
- return NULL;
- }
-
- // If the extension was already registered by number, check that it is the
- // same.
- existing_extension = PyDict_GetItem(extensions_by_number.get(), number.get());
- if (existing_extension != NULL) {
- const FieldDescriptor* existing_extension_descriptor =
- GetExtensionDescriptor(existing_extension);
- if (existing_extension_descriptor != descriptor) {
- const Descriptor* msg_desc = GetMessageDescriptor(
- reinterpret_cast<PyTypeObject*>(cls));
- PyErr_Format(
- PyExc_ValueError,
- "Extensions \"%s\" and \"%s\" both try to extend message type "
- "\"%s\" with field number %ld.",
- existing_extension_descriptor->full_name().c_str(),
- descriptor->full_name().c_str(),
- msg_desc->full_name().c_str(),
- PyInt_AsLong(number.get()));
- return NULL;
- }
- // Nothing else to do.
- Py_RETURN_NONE;
- }
- if (PyDict_SetItem(extensions_by_number.get(), number.get(),
- extension_handle) < 0) {
- return NULL;
- }
-
- // Check if it's a message set
- if (descriptor->is_extension() &&
- descriptor->containing_type()->options().message_set_wire_format() &&
- descriptor->type() == FieldDescriptor::TYPE_MESSAGE &&
- descriptor->label() == FieldDescriptor::LABEL_OPTIONAL) {
- ScopedPyObjectPtr message_name(PyString_FromStringAndSize(
- descriptor->message_type()->full_name().c_str(),
- descriptor->message_type()->full_name().size()));
- if (message_name == NULL) {
- return NULL;
- }
- PyDict_SetItem(extensions_by_name.get(), message_name.get(),
- extension_handle);
- }
-
Py_RETURN_NONE;
}
@@ -2078,7 +2110,7 @@ static PyObject* WhichOneof(CMessage* self, PyObject* arg) {
static PyObject* GetExtensionDict(CMessage* self, void *closure);
static PyObject* ListFields(CMessage* self) {
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
self->message->GetReflection()->ListFields(*self->message, &fields);
// Normally, the list will be exactly the size of the fields.
@@ -2108,8 +2140,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;
@@ -2169,7 +2201,7 @@ static PyObject* DiscardUnknownFields(CMessage* self) {
PyObject* FindInitializationErrors(CMessage* self) {
Message* message = self->message;
- vector<string> errors;
+ std::vector<string> errors;
message->FindInitializationErrors(&errors);
PyObject* error_list = PyList_New(errors.size());
@@ -2306,12 +2338,14 @@ 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::GetOrCreateMessageClass(
+ factory, field_descriptor->message_type());
+ ScopedPyObjectPtr message_class_handler(
+ reinterpret_cast<PyObject*>(message_class));
if (message_class == NULL) {
return NULL;
}
@@ -2561,11 +2595,24 @@ static PyObject* GetExtensionDict(CMessage* self, void *closure) {
return NULL;
}
+static PyObject* GetExtensionsByName(CMessage *self, void *closure) {
+ return message_meta::GetExtensionsByName(
+ reinterpret_cast<CMessageClass*>(Py_TYPE(self)), closure);
+}
+
+static PyObject* GetExtensionsByNumber(CMessage *self, void *closure) {
+ return message_meta::GetExtensionsByNumber(
+ reinterpret_cast<CMessageClass*>(Py_TYPE(self)), closure);
+}
+
static PyGetSetDef Getters[] = {
{"Extensions", (getter)GetExtensionDict, NULL, "Extension dict"},
+ {"_extensions_by_name", (getter)GetExtensionsByName, NULL},
+ {"_extensions_by_number", (getter)GetExtensionsByNumber, NULL},
{NULL}
};
+
static PyMethodDef Methods[] = {
{ "__deepcopy__", (PyCFunction)DeepCopy, METH_VARARGS,
"Makes a deep copy of the class." },
@@ -2656,8 +2703,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 +2726,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 +2822,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
@@ -2822,30 +2869,11 @@ static Message* MutableCProtoInsidePyProtoImpl(PyObject* msg) {
return cmsg->message;
}
-static const char module_docstring[] =
-"python-proto2 is a module that can be used to enhance proto2 Python API\n"
-"performance.\n"
-"\n"
-"It provides access to the protocol buffers C++ reflection API that\n"
-"implements the basic protocol buffer functions.";
-
void InitGlobals() {
// TODO(gps): Check all return values in this function for NULL and propagate
// the error (MemoryError) on up to result in an import failure. These should
// also be freed and reset to NULL during finalization.
- kPythonZero = PyInt_FromLong(0);
- kint32min_py = PyInt_FromLong(kint32min);
- kint32max_py = PyInt_FromLong(kint32max);
- kuint32max_py = PyLong_FromLongLong(kuint32max);
- kint64min_py = PyLong_FromLongLong(kint64min);
- kint64max_py = PyLong_FromLongLong(kint64max);
- kuint64max_py = PyLong_FromUnsignedLongLong(kuint64max);
-
kDESCRIPTOR = PyString_FromString("DESCRIPTOR");
- k_cdescriptor = PyString_FromString("_cdescriptor");
- kfull_name = PyString_FromString("full_name");
- k_extensions_by_name = PyString_FromString("_extensions_by_name");
- k_extensions_by_number = PyString_FromString("_extensions_by_number");
PyObject *dummy_obj = PySet_New(NULL);
kEmptyWeakref = PyWeakref_NewRef(dummy_obj, NULL);
@@ -2863,6 +2891,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();
@@ -2880,25 +2913,6 @@ bool InitProto2MessageModule(PyObject *m) {
// DESCRIPTOR is set on each protocol buffer message class elsewhere, but set
// it here as well to document that subclasses need to set it.
PyDict_SetItem(CMessage_Type.tp_dict, kDESCRIPTOR, Py_None);
- // Subclasses with message extensions will override _extensions_by_name and
- // _extensions_by_number with fresh mutable dictionaries in AddDescriptors.
- // All other classes can share this same immutable mapping.
- ScopedPyObjectPtr empty_dict(PyDict_New());
- if (empty_dict == NULL) {
- return false;
- }
- ScopedPyObjectPtr immutable_dict(PyDictProxy_New(empty_dict.get()));
- if (immutable_dict == NULL) {
- return false;
- }
- if (PyDict_SetItem(CMessage_Type.tp_dict,
- k_extensions_by_name, immutable_dict.get()) < 0) {
- return false;
- }
- if (PyDict_SetItem(CMessage_Type.tp_dict,
- k_extensions_by_number, immutable_dict.get()) < 0) {
- return false;
- }
PyModule_AddObject(m, "Message", reinterpret_cast<PyObject*>(&CMessage_Type));
@@ -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<PyTypeObject*>(mutable_mapping.get());
-
- if (PyType_Ready(&ScalarMapContainer_Type) < 0) {
- return false;
- }
-
- PyModule_AddObject(m, "ScalarMapContainer",
- reinterpret_cast<PyObject*>(&ScalarMapContainer_Type));
-#endif
-
- if (PyType_Ready(&MapIterator_Type) < 0) {
- return false;
- }
-
- PyModule_AddObject(m, "MapIterator",
- reinterpret_cast<PyObject*>(&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<PyTypeObject*>(mutable_mapping.get());
-
- if (PyType_Ready(&MessageMapContainer_Type) < 0) {
- return false;
- }
-
- PyModule_AddObject(m, "MessageMapContainer",
- reinterpret_cast<PyObject*>(&MessageMapContainer_Type));
-#endif
+ if (!InitMapContainers()) {
+ return false;
}
+ PyModule_AddObject(m, "ScalarMapContainer",
+ reinterpret_cast<PyObject*>(ScalarMapContainer_Type));
+ PyModule_AddObject(m, "MessageMapContainer",
+ reinterpret_cast<PyObject*>(MessageMapContainer_Type));
+ PyModule_AddObject(m, "MapIterator",
+ reinterpret_cast<PyObject*>(&MapIterator_Type));
if (PyType_Ready(&ExtensionDict_Type) < 0) {
return false;
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/message.h b/third_party/protobuf/python/google/protobuf/pyext/message.h
index c44a2ae2b7..ce80497e6b 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/message.h
+++ b/third_party/protobuf/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,8 +112,12 @@ 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 CMessageClass_Type;
extern PyTypeObject CMessage_Type;
@@ -132,14 +136,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<PyObject*>(this);
@@ -154,14 +155,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);
@@ -243,6 +236,10 @@ int InitAttributes(CMessage* self, PyObject* args, PyObject* kwargs);
PyObject* MergeFrom(CMessage* self, PyObject* arg);
+// This method does not do anything beyond checking that no other extension
+// has been registered with the same field number on this class.
+PyObject* RegisterExtension(PyObject* cls, PyObject* extension_handle);
+
// Retrieves an attribute named 'name' from CMessage 'self'. Returns
// the attribute value on success, or NULL on failure.
//
@@ -262,14 +259,13 @@ int SetOwner(CMessage* self, const shared_ptr<Message>& 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);
@@ -284,25 +280,25 @@ PyObject* SetAllowOversizeProtos(PyObject* m, PyObject* arg);
#define GOOGLE_CHECK_GET_INT32(arg, value, err) \
int32 value; \
- if (!CheckAndGetInteger(arg, &value, kint32min_py, kint32max_py)) { \
+ if (!CheckAndGetInteger(arg, &value)) { \
return err; \
}
#define GOOGLE_CHECK_GET_INT64(arg, value, err) \
int64 value; \
- if (!CheckAndGetInteger(arg, &value, kint64min_py, kint64max_py)) { \
+ if (!CheckAndGetInteger(arg, &value)) { \
return err; \
}
#define GOOGLE_CHECK_GET_UINT32(arg, value, err) \
uint32 value; \
- if (!CheckAndGetInteger(arg, &value, kPythonZero, kuint32max_py)) { \
+ if (!CheckAndGetInteger(arg, &value)) { \
return err; \
}
#define GOOGLE_CHECK_GET_UINT64(arg, value, err) \
uint64 value; \
- if (!CheckAndGetInteger(arg, &value, kPythonZero, kuint64max_py)) { \
+ if (!CheckAndGetInteger(arg, &value)) { \
return err; \
}
@@ -325,20 +321,11 @@ PyObject* SetAllowOversizeProtos(PyObject* m, PyObject* arg);
}
-extern PyObject* kPythonZero;
-extern PyObject* kint32min_py;
-extern PyObject* kint32max_py;
-extern PyObject* kuint32max_py;
-extern PyObject* kint64min_py;
-extern PyObject* kint64max_py;
-extern PyObject* kuint64max_py;
-
#define FULL_MODULE_NAME "google.protobuf.pyext._message"
void FormatTypeError(PyObject* arg, char* expected_types);
template<class T>
-bool CheckAndGetInteger(
- PyObject* arg, T* value, PyObject* min, PyObject* max);
+bool CheckAndGetInteger(PyObject* arg, T* value);
bool CheckAndGetDouble(PyObject* arg, double* value);
bool CheckAndGetFloat(PyObject* arg, float* value);
bool CheckAndGetBool(PyObject* arg, bool* value);
diff --git a/third_party/protobuf/python/google/protobuf/pyext/message_factory.cc b/third_party/protobuf/python/google/protobuf/pyext/message_factory.cc
new file mode 100644
index 0000000000..e0b45bf2d9
--- /dev/null
+++ b/third_party/protobuf/python/google/protobuf/pyext/message_factory.cc
@@ -0,0 +1,280 @@
+// 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 <Python.h>
+
+#include <google/protobuf/dynamic_message.h>
+#include <google/protobuf/pyext/descriptor.h>
+#include <google/protobuf/pyext/message.h>
+#include <google/protobuf/pyext/message_factory.h>
+#include <google/protobuf/pyext/scoped_pyobject_ptr.h>
+
+#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<PyMessageFactory*>(
+ 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<PyObject*>(&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<PyObject*>(
+ NewMessageFactory(type, reinterpret_cast<PyDescriptorPool*>(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<PyObject*>(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<iterator, bool> 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;
+}
+
+CMessageClass* GetOrCreateMessageClass(PyMessageFactory* self,
+ const Descriptor* descriptor) {
+ // This is the same implementation as MessageFactory.GetPrototype().
+ ScopedPyObjectPtr py_descriptor(
+ PyMessageDescriptor_FromDescriptor(descriptor));
+ if (py_descriptor == NULL) {
+ return NULL;
+ }
+ // Do not create a MessageClass that already exists.
+ hash_map<const Descriptor*, CMessageClass*>::iterator it =
+ self->classes_by_descriptor->find(descriptor);
+ if (it != self->classes_by_descriptor->end()) {
+ Py_INCREF(it->second);
+ return it->second;
+ }
+ // Create a new message class.
+ ScopedPyObjectPtr args(Py_BuildValue(
+ "s(){sOsOsO}", descriptor->name().c_str(),
+ "DESCRIPTOR", py_descriptor.get(),
+ "__module__", Py_None,
+ "message_factory", self));
+ if (args == NULL) {
+ return NULL;
+ }
+ ScopedPyObjectPtr message_class(PyObject_CallObject(
+ reinterpret_cast<PyObject*>(&CMessageClass_Type), args.get()));
+ if (message_class == NULL) {
+ return NULL;
+ }
+ // Create messages class for the messages used by the fields, and registers
+ // all extensions for these messages during the recursion.
+ for (int field_idx = 0; field_idx < descriptor->field_count(); field_idx++) {
+ const Descriptor* sub_descriptor =
+ descriptor->field(field_idx)->message_type();
+ // It is NULL if the field type is not a message.
+ if (sub_descriptor != NULL) {
+ CMessageClass* result = GetOrCreateMessageClass(self, sub_descriptor);
+ if (result == NULL) {
+ return NULL;
+ }
+ Py_DECREF(result);
+ }
+ }
+
+ // Register extensions defined in this message.
+ for (int ext_idx = 0 ; ext_idx < descriptor->extension_count() ; ext_idx++) {
+ const FieldDescriptor* extension = descriptor->extension(ext_idx);
+ ScopedPyObjectPtr py_extended_class(
+ GetOrCreateMessageClass(self, extension->containing_type())
+ ->AsPyObject());
+ if (py_extended_class == NULL) {
+ return NULL;
+ }
+ ScopedPyObjectPtr py_extension(PyFieldDescriptor_FromDescriptor(extension));
+ if (py_extension == NULL) {
+ return NULL;
+ }
+ ScopedPyObjectPtr result(cmessage::RegisterExtension(
+ py_extended_class.get(), py_extension.get()));
+ if (result == NULL) {
+ return NULL;
+ }
+ }
+ return reinterpret_cast<CMessageClass*>(message_class.release());
+}
+
+// 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<PyObject*>(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/third_party/protobuf/python/google/protobuf/pyext/message_factory.h b/third_party/protobuf/python/google/protobuf/pyext/message_factory.h
new file mode 100644
index 0000000000..36092f7e40
--- /dev/null
+++ b/third_party/protobuf/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 <Python.h>
+
+#include <google/protobuf/stubs/hash.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/pyext/descriptor_pool.h>
+
+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<const Descriptor*, CMessageClass*> 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, or
+// fail with a TypeError. Returns a *borrowed* reference.
+CMessageClass* GetMessageClass(PyMessageFactory* self,
+ const Descriptor* message_descriptor);
+// Retrieves the Python class registered with the given message descriptor.
+// The class is created if not done yet. Returns a *new* reference.
+CMessageClass* GetOrCreateMessageClass(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/third_party/protobuf/3.0.0/python/google/protobuf/pyext/message_module.cc b/third_party/protobuf/python/google/protobuf/pyext/message_module.cc
index d90d9de35a..d90d9de35a 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/message_module.cc
+++ b/third_party/protobuf/python/google/protobuf/pyext/message_module.cc
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/proto2_api_test.proto b/third_party/protobuf/python/google/protobuf/pyext/proto2_api_test.proto
index 18aecfb7d6..18aecfb7d6 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/proto2_api_test.proto
+++ b/third_party/protobuf/python/google/protobuf/pyext/proto2_api_test.proto
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/python.proto b/third_party/protobuf/python/google/protobuf/pyext/python.proto
index cce645d71a..cce645d71a 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/python.proto
+++ b/third_party/protobuf/python/google/protobuf/pyext/python.proto
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/python_protobuf.h b/third_party/protobuf/python/google/protobuf/pyext/python_protobuf.h
index beb6e4604a..beb6e4604a 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/python_protobuf.h
+++ b/third_party/protobuf/python/google/protobuf/pyext/python_protobuf.h
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/repeated_composite_container.cc b/third_party/protobuf/python/google/protobuf/pyext/repeated_composite_container.cc
index bb2f6db287..43a2bc12d9 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/repeated_composite_container.cc
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/python/google/protobuf/pyext/repeated_composite_container.h b/third_party/protobuf/python/google/protobuf/pyext/repeated_composite_container.h
index a7b56b61b3..a7b56b61b3 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/repeated_composite_container.h
+++ b/third_party/protobuf/python/google/protobuf/pyext/repeated_composite_container.h
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/repeated_scalar_container.cc b/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc
index 95da85f87b..95da85f87b 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/repeated_scalar_container.cc
+++ b/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/repeated_scalar_container.h b/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.h
index 555e621c9b..555e621c9b 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/repeated_scalar_container.h
+++ b/third_party/protobuf/python/google/protobuf/pyext/repeated_scalar_container.h
diff --git a/third_party/protobuf/python/google/protobuf/pyext/safe_numerics.h b/third_party/protobuf/python/google/protobuf/pyext/safe_numerics.h
new file mode 100644
index 0000000000..639ba2c8e3
--- /dev/null
+++ b/third_party/protobuf/python/google/protobuf/pyext/safe_numerics.h
@@ -0,0 +1,164 @@
+// 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_SAFE_NUMERICS_H__
+#define GOOGLE_PROTOBUF_PYTHON_CPP_SAFE_NUMERICS_H__
+// Copied from chromium with only changes to the namespace.
+
+#include <limits>
+
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/stubs/common.h>
+
+namespace google {
+namespace protobuf {
+namespace python {
+
+template <bool SameSize, bool DestLarger,
+ bool DestIsSigned, bool SourceIsSigned>
+struct IsValidNumericCastImpl;
+
+#define BASE_NUMERIC_CAST_CASE_SPECIALIZATION(A, B, C, D, Code) \
+template <> struct IsValidNumericCastImpl<A, B, C, D> { \
+ template <class Source, class DestBounds> static inline bool Test( \
+ Source source, DestBounds min, DestBounds max) { \
+ return Code; \
+ } \
+}
+
+#define BASE_NUMERIC_CAST_CASE_SAME_SIZE(DestSigned, SourceSigned, Code) \
+ BASE_NUMERIC_CAST_CASE_SPECIALIZATION( \
+ true, true, DestSigned, SourceSigned, Code); \
+ BASE_NUMERIC_CAST_CASE_SPECIALIZATION( \
+ true, false, DestSigned, SourceSigned, Code)
+
+#define BASE_NUMERIC_CAST_CASE_SOURCE_LARGER(DestSigned, SourceSigned, Code) \
+ BASE_NUMERIC_CAST_CASE_SPECIALIZATION( \
+ false, false, DestSigned, SourceSigned, Code); \
+
+#define BASE_NUMERIC_CAST_CASE_DEST_LARGER(DestSigned, SourceSigned, Code) \
+ BASE_NUMERIC_CAST_CASE_SPECIALIZATION( \
+ false, true, DestSigned, SourceSigned, Code); \
+
+// The three top level cases are:
+// - Same size
+// - Source larger
+// - Dest larger
+// And for each of those three cases, we handle the 4 different possibilities
+// of signed and unsigned. This gives 12 cases to handle, which we enumerate
+// below.
+//
+// The last argument in each of the macros is the actual comparison code. It
+// has three arguments available, source (the value), and min/max which are
+// the ranges of the destination.
+
+
+// These are the cases where both types have the same size.
+
+// Both signed.
+BASE_NUMERIC_CAST_CASE_SAME_SIZE(true, true, true);
+// Both unsigned.
+BASE_NUMERIC_CAST_CASE_SAME_SIZE(false, false, true);
+// Dest unsigned, Source signed.
+BASE_NUMERIC_CAST_CASE_SAME_SIZE(false, true, source >= 0);
+// Dest signed, Source unsigned.
+// This cast is OK because Dest's max must be less than Source's.
+BASE_NUMERIC_CAST_CASE_SAME_SIZE(true, false,
+ source <= static_cast<Source>(max));
+
+
+// These are the cases where Source is larger.
+
+// Both unsigned.
+BASE_NUMERIC_CAST_CASE_SOURCE_LARGER(false, false, source <= max);
+// Both signed.
+BASE_NUMERIC_CAST_CASE_SOURCE_LARGER(true, true,
+ source >= min && source <= max);
+// Dest is unsigned, Source is signed.
+BASE_NUMERIC_CAST_CASE_SOURCE_LARGER(false, true,
+ source >= 0 && source <= max);
+// Dest is signed, Source is unsigned.
+// This cast is OK because Dest's max must be less than Source's.
+BASE_NUMERIC_CAST_CASE_SOURCE_LARGER(true, false,
+ source <= static_cast<Source>(max));
+
+
+// These are the cases where Dest is larger.
+
+// Both unsigned.
+BASE_NUMERIC_CAST_CASE_DEST_LARGER(false, false, true);
+// Both signed.
+BASE_NUMERIC_CAST_CASE_DEST_LARGER(true, true, true);
+// Dest is unsigned, Source is signed.
+BASE_NUMERIC_CAST_CASE_DEST_LARGER(false, true, source >= 0);
+// Dest is signed, Source is unsigned.
+BASE_NUMERIC_CAST_CASE_DEST_LARGER(true, false, true);
+
+#undef BASE_NUMERIC_CAST_CASE_SPECIALIZATION
+#undef BASE_NUMERIC_CAST_CASE_SAME_SIZE
+#undef BASE_NUMERIC_CAST_CASE_SOURCE_LARGER
+#undef BASE_NUMERIC_CAST_CASE_DEST_LARGER
+
+
+// The main test for whether the conversion will under or overflow.
+template <class Dest, class Source>
+inline bool IsValidNumericCast(Source source) {
+ typedef std::numeric_limits<Source> SourceLimits;
+ typedef std::numeric_limits<Dest> DestLimits;
+ GOOGLE_COMPILE_ASSERT(SourceLimits::is_specialized, argument_must_be_numeric);
+ GOOGLE_COMPILE_ASSERT(SourceLimits::is_integer, argument_must_be_integral);
+ GOOGLE_COMPILE_ASSERT(DestLimits::is_specialized, result_must_be_numeric);
+ GOOGLE_COMPILE_ASSERT(DestLimits::is_integer, result_must_be_integral);
+
+ return IsValidNumericCastImpl<
+ sizeof(Dest) == sizeof(Source),
+ (sizeof(Dest) > sizeof(Source)),
+ DestLimits::is_signed,
+ SourceLimits::is_signed>::Test(
+ source,
+ DestLimits::min(),
+ DestLimits::max());
+}
+
+// checked_numeric_cast<> is analogous to static_cast<> for numeric types,
+// except that it CHECKs that the specified numeric conversion will not
+// overflow or underflow. Floating point arguments are not currently allowed
+// (this is COMPILE_ASSERTd), though this could be supported if necessary.
+template <class Dest, class Source>
+inline Dest checked_numeric_cast(Source source) {
+ GOOGLE_CHECK(IsValidNumericCast<Dest>(source));
+ return static_cast<Dest>(source);
+}
+
+} // namespace python
+} // namespace protobuf
+
+} // namespace google
+#endif // GOOGLE_PROTOBUF_PYTHON_CPP_SAFE_NUMERICS_H__
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/scoped_pyobject_ptr.h b/third_party/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h
index a128cd4c61..a128cd4c61 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/pyext/scoped_pyobject_ptr.h
+++ b/third_party/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/reflection.py b/third_party/protobuf/python/google/protobuf/reflection.py
index 51c8332120..05bafd692f 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/reflection.py
+++ b/third_party/protobuf/python/google/protobuf/reflection.py
@@ -61,6 +61,8 @@ else:
# Part of the public interface, but normally only used by message factories.
GeneratedProtocolMessageType = message_impl.GeneratedProtocolMessageType
+MESSAGE_CLASS_CACHE = {}
+
def ParseMessage(descriptor, byte_str):
"""Generate a new Message instance from this Descriptor and a byte string.
@@ -104,11 +106,16 @@ def MakeClass(descriptor):
Returns:
The Message class object described by the descriptor.
"""
+ if descriptor in MESSAGE_CLASS_CACHE:
+ return MESSAGE_CLASS_CACHE[descriptor]
+
attributes = {}
for name, nested_type in descriptor.nested_types_by_name.items():
attributes[name] = MakeClass(nested_type)
attributes[GeneratedProtocolMessageType._DESCRIPTOR_KEY] = descriptor
- return GeneratedProtocolMessageType(str(descriptor.name), (message.Message,),
+ result = GeneratedProtocolMessageType(str(descriptor.name), (message.Message,),
attributes)
+ MESSAGE_CLASS_CACHE[descriptor] = result
+ return result
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/service.py b/third_party/protobuf/python/google/protobuf/service.py
index 9e00de7042..9e00de7042 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/service.py
+++ b/third_party/protobuf/python/google/protobuf/service.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/service_reflection.py b/third_party/protobuf/python/google/protobuf/service_reflection.py
index 1c3636afe0..1c3636afe0 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/service_reflection.py
+++ b/third_party/protobuf/python/google/protobuf/service_reflection.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/symbol_database.py b/third_party/protobuf/python/google/protobuf/symbol_database.py
index aa466abd26..ecbef21114 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/symbol_database.py
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/python/google/protobuf/text_encoding.py b/third_party/protobuf/python/google/protobuf/text_encoding.py
index 9899563825..9899563825 100644
--- a/third_party/protobuf/3.0.0/python/google/protobuf/text_encoding.py
+++ b/third_party/protobuf/python/google/protobuf/text_encoding.py
diff --git a/third_party/protobuf/3.0.0/python/google/protobuf/text_format.py b/third_party/protobuf/python/google/protobuf/text_format.py
index 06b79d77d1..90f6ce42a4 100755
--- a/third_party/protobuf/3.0.0/python/google/protobuf/text_format.py
+++ b/third_party/protobuf/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/third_party/protobuf/python/mox.py b/third_party/protobuf/python/mox.py
new file mode 100755
index 0000000000..257468e52d
--- /dev/null
+++ b/third_party/protobuf/python/mox.py
@@ -0,0 +1,1401 @@
+#!/usr/bin/python2.4
+#
+# Copyright 2008 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This file is used for testing. The original is at:
+# http://code.google.com/p/pymox/
+
+"""Mox, an object-mocking framework for Python.
+
+Mox works in the record-replay-verify paradigm. When you first create
+a mock object, it is in record mode. You then programmatically set
+the expected behavior of the mock object (what methods are to be
+called on it, with what parameters, what they should return, and in
+what order).
+
+Once you have set up the expected mock behavior, you put it in replay
+mode. Now the mock responds to method calls just as you told it to.
+If an unexpected method (or an expected method with unexpected
+parameters) is called, then an exception will be raised.
+
+Once you are done interacting with the mock, you need to verify that
+all the expected interactions occurred. (Maybe your code exited
+prematurely without calling some cleanup method!) The verify phase
+ensures that every expected method was called; otherwise, an exception
+will be raised.
+
+Suggested usage / workflow:
+
+ # Create Mox factory
+ my_mox = Mox()
+
+ # Create a mock data access object
+ mock_dao = my_mox.CreateMock(DAOClass)
+
+ # Set up expected behavior
+ mock_dao.RetrievePersonWithIdentifier('1').AndReturn(person)
+ mock_dao.DeletePerson(person)
+
+ # Put mocks in replay mode
+ my_mox.ReplayAll()
+
+ # Inject mock object and run test
+ controller.SetDao(mock_dao)
+ controller.DeletePersonById('1')
+
+ # Verify all methods were called as expected
+ my_mox.VerifyAll()
+"""
+
+from collections import deque
+import re
+import types
+import unittest
+
+import stubout
+
+class Error(AssertionError):
+ """Base exception for this module."""
+
+ pass
+
+
+class ExpectedMethodCallsError(Error):
+ """Raised when Verify() is called before all expected methods have been called
+ """
+
+ def __init__(self, expected_methods):
+ """Init exception.
+
+ Args:
+ # expected_methods: A sequence of MockMethod objects that should have been
+ # called.
+ expected_methods: [MockMethod]
+
+ Raises:
+ ValueError: if expected_methods contains no methods.
+ """
+
+ if not expected_methods:
+ raise ValueError("There must be at least one expected method")
+ Error.__init__(self)
+ self._expected_methods = expected_methods
+
+ def __str__(self):
+ calls = "\n".join(["%3d. %s" % (i, m)
+ for i, m in enumerate(self._expected_methods)])
+ return "Verify: Expected methods never called:\n%s" % (calls,)
+
+
+class UnexpectedMethodCallError(Error):
+ """Raised when an unexpected method is called.
+
+ This can occur if a method is called with incorrect parameters, or out of the
+ specified order.
+ """
+
+ def __init__(self, unexpected_method, expected):
+ """Init exception.
+
+ Args:
+ # unexpected_method: MockMethod that was called but was not at the head of
+ # the expected_method queue.
+ # expected: MockMethod or UnorderedGroup the method should have
+ # been in.
+ unexpected_method: MockMethod
+ expected: MockMethod or UnorderedGroup
+ """
+
+ Error.__init__(self)
+ self._unexpected_method = unexpected_method
+ self._expected = expected
+
+ def __str__(self):
+ return "Unexpected method call: %s. Expecting: %s" % \
+ (self._unexpected_method, self._expected)
+
+
+class UnknownMethodCallError(Error):
+ """Raised if an unknown method is requested of the mock object."""
+
+ def __init__(self, unknown_method_name):
+ """Init exception.
+
+ Args:
+ # unknown_method_name: Method call that is not part of the mocked class's
+ # public interface.
+ unknown_method_name: str
+ """
+
+ Error.__init__(self)
+ self._unknown_method_name = unknown_method_name
+
+ def __str__(self):
+ return "Method called is not a member of the object: %s" % \
+ self._unknown_method_name
+
+
+class Mox(object):
+ """Mox: a factory for creating mock objects."""
+
+ # A list of types that should be stubbed out with MockObjects (as
+ # opposed to MockAnythings).
+ _USE_MOCK_OBJECT = [types.ClassType, types.InstanceType, types.ModuleType,
+ types.ObjectType, types.TypeType]
+
+ def __init__(self):
+ """Initialize a new Mox."""
+
+ self._mock_objects = []
+ self.stubs = stubout.StubOutForTesting()
+
+ def CreateMock(self, class_to_mock):
+ """Create a new mock object.
+
+ Args:
+ # class_to_mock: the class to be mocked
+ class_to_mock: class
+
+ Returns:
+ MockObject that can be used as the class_to_mock would be.
+ """
+
+ new_mock = MockObject(class_to_mock)
+ self._mock_objects.append(new_mock)
+ return new_mock
+
+ def CreateMockAnything(self):
+ """Create a mock that will accept any method calls.
+
+ This does not enforce an interface.
+ """
+
+ new_mock = MockAnything()
+ self._mock_objects.append(new_mock)
+ return new_mock
+
+ def ReplayAll(self):
+ """Set all mock objects to replay mode."""
+
+ for mock_obj in self._mock_objects:
+ mock_obj._Replay()
+
+
+ def VerifyAll(self):
+ """Call verify on all mock objects created."""
+
+ for mock_obj in self._mock_objects:
+ mock_obj._Verify()
+
+ def ResetAll(self):
+ """Call reset on all mock objects. This does not unset stubs."""
+
+ for mock_obj in self._mock_objects:
+ mock_obj._Reset()
+
+ def StubOutWithMock(self, obj, attr_name, use_mock_anything=False):
+ """Replace a method, attribute, etc. with a Mock.
+
+ This will replace a class or module with a MockObject, and everything else
+ (method, function, etc) with a MockAnything. This can be overridden to
+ always use a MockAnything by setting use_mock_anything to True.
+
+ Args:
+ obj: A Python object (class, module, instance, callable).
+ attr_name: str. The name of the attribute to replace with a mock.
+ use_mock_anything: bool. True if a MockAnything should be used regardless
+ of the type of attribute.
+ """
+
+ attr_to_replace = getattr(obj, attr_name)
+ if type(attr_to_replace) in self._USE_MOCK_OBJECT and not use_mock_anything:
+ stub = self.CreateMock(attr_to_replace)
+ else:
+ stub = self.CreateMockAnything()
+
+ self.stubs.Set(obj, attr_name, stub)
+
+ def UnsetStubs(self):
+ """Restore stubs to their original state."""
+
+ self.stubs.UnsetAll()
+
+def Replay(*args):
+ """Put mocks into Replay mode.
+
+ Args:
+ # args is any number of mocks to put into replay mode.
+ """
+
+ for mock in args:
+ mock._Replay()
+
+
+def Verify(*args):
+ """Verify mocks.
+
+ Args:
+ # args is any number of mocks to be verified.
+ """
+
+ for mock in args:
+ mock._Verify()
+
+
+def Reset(*args):
+ """Reset mocks.
+
+ Args:
+ # args is any number of mocks to be reset.
+ """
+
+ for mock in args:
+ mock._Reset()
+
+
+class MockAnything:
+ """A mock that can be used to mock anything.
+
+ This is helpful for mocking classes that do not provide a public interface.
+ """
+
+ def __init__(self):
+ """ """
+ self._Reset()
+
+ def __getattr__(self, method_name):
+ """Intercept method calls on this object.
+
+ A new MockMethod is returned that is aware of the MockAnything's
+ state (record or replay). The call will be recorded or replayed
+ by the MockMethod's __call__.
+
+ Args:
+ # method name: the name of the method being called.
+ method_name: str
+
+ Returns:
+ A new MockMethod aware of MockAnything's state (record or replay).
+ """
+
+ return self._CreateMockMethod(method_name)
+
+ def _CreateMockMethod(self, method_name):
+ """Create a new mock method call and return it.
+
+ Args:
+ # method name: the name of the method being called.
+ method_name: str
+
+ Returns:
+ A new MockMethod aware of MockAnything's state (record or replay).
+ """
+
+ return MockMethod(method_name, self._expected_calls_queue,
+ self._replay_mode)
+
+ def __nonzero__(self):
+ """Return 1 for nonzero so the mock can be used as a conditional."""
+
+ return 1
+
+ def __eq__(self, rhs):
+ """Provide custom logic to compare objects."""
+
+ return (isinstance(rhs, MockAnything) and
+ self._replay_mode == rhs._replay_mode and
+ self._expected_calls_queue == rhs._expected_calls_queue)
+
+ def __ne__(self, rhs):
+ """Provide custom logic to compare objects."""
+
+ return not self == rhs
+
+ def _Replay(self):
+ """Start replaying expected method calls."""
+
+ self._replay_mode = True
+
+ def _Verify(self):
+ """Verify that all of the expected calls have been made.
+
+ Raises:
+ ExpectedMethodCallsError: if there are still more method calls in the
+ expected queue.
+ """
+
+ # If the list of expected calls is not empty, raise an exception
+ if self._expected_calls_queue:
+ # The last MultipleTimesGroup is not popped from the queue.
+ if (len(self._expected_calls_queue) == 1 and
+ isinstance(self._expected_calls_queue[0], MultipleTimesGroup) and
+ self._expected_calls_queue[0].IsSatisfied()):
+ pass
+ else:
+ raise ExpectedMethodCallsError(self._expected_calls_queue)
+
+ def _Reset(self):
+ """Reset the state of this mock to record mode with an empty queue."""
+
+ # Maintain a list of method calls we are expecting
+ self._expected_calls_queue = deque()
+
+ # Make sure we are in setup mode, not replay mode
+ self._replay_mode = False
+
+
+class MockObject(MockAnything, object):
+ """A mock object that simulates the public/protected interface of a class."""
+
+ def __init__(self, class_to_mock):
+ """Initialize a mock object.
+
+ This determines the methods and properties of the class and stores them.
+
+ Args:
+ # class_to_mock: class to be mocked
+ class_to_mock: class
+ """
+
+ # This is used to hack around the mixin/inheritance of MockAnything, which
+ # is not a proper object (it can be anything. :-)
+ MockAnything.__dict__['__init__'](self)
+
+ # Get a list of all the public and special methods we should mock.
+ self._known_methods = set()
+ self._known_vars = set()
+ self._class_to_mock = class_to_mock
+ for method in dir(class_to_mock):
+ if callable(getattr(class_to_mock, method)):
+ self._known_methods.add(method)
+ else:
+ self._known_vars.add(method)
+
+ def __getattr__(self, name):
+ """Intercept attribute request on this object.
+
+ If the attribute is a public class variable, it will be returned and not
+ recorded as a call.
+
+ If the attribute is not a variable, it is handled like a method
+ call. The method name is checked against the set of mockable
+ methods, and a new MockMethod is returned that is aware of the
+ MockObject's state (record or replay). The call will be recorded
+ or replayed by the MockMethod's __call__.
+
+ Args:
+ # name: the name of the attribute being requested.
+ name: str
+
+ Returns:
+ Either a class variable or a new MockMethod that is aware of the state
+ of the mock (record or replay).
+
+ Raises:
+ UnknownMethodCallError if the MockObject does not mock the requested
+ method.
+ """
+
+ if name in self._known_vars:
+ return getattr(self._class_to_mock, name)
+
+ if name in self._known_methods:
+ return self._CreateMockMethod(name)
+
+ raise UnknownMethodCallError(name)
+
+ def __eq__(self, rhs):
+ """Provide custom logic to compare objects."""
+
+ return (isinstance(rhs, MockObject) and
+ self._class_to_mock == rhs._class_to_mock and
+ self._replay_mode == rhs._replay_mode and
+ self._expected_calls_queue == rhs._expected_calls_queue)
+
+ def __setitem__(self, key, value):
+ """Provide custom logic for mocking classes that support item assignment.
+
+ Args:
+ key: Key to set the value for.
+ value: Value to set.
+
+ Returns:
+ Expected return value in replay mode. A MockMethod object for the
+ __setitem__ method that has already been called if not in replay mode.
+
+ Raises:
+ TypeError if the underlying class does not support item assignment.
+ UnexpectedMethodCallError if the object does not expect the call to
+ __setitem__.
+
+ """
+ setitem = self._class_to_mock.__dict__.get('__setitem__', None)
+
+ # Verify the class supports item assignment.
+ if setitem is None:
+ raise TypeError('object does not support item assignment')
+
+ # If we are in replay mode then simply call the mock __setitem__ method.
+ if self._replay_mode:
+ return MockMethod('__setitem__', self._expected_calls_queue,
+ self._replay_mode)(key, value)
+
+
+ # Otherwise, create a mock method __setitem__.
+ return self._CreateMockMethod('__setitem__')(key, value)
+
+ def __getitem__(self, key):
+ """Provide custom logic for mocking classes that are subscriptable.
+
+ Args:
+ key: Key to return the value for.
+
+ Returns:
+ Expected return value in replay mode. A MockMethod object for the
+ __getitem__ method that has already been called if not in replay mode.
+
+ Raises:
+ TypeError if the underlying class is not subscriptable.
+ UnexpectedMethodCallError if the object does not expect the call to
+ __setitem__.
+
+ """
+ getitem = self._class_to_mock.__dict__.get('__getitem__', None)
+
+ # Verify the class supports item assignment.
+ if getitem is None:
+ raise TypeError('unsubscriptable object')
+
+ # If we are in replay mode then simply call the mock __getitem__ method.
+ if self._replay_mode:
+ return MockMethod('__getitem__', self._expected_calls_queue,
+ self._replay_mode)(key)
+
+
+ # Otherwise, create a mock method __getitem__.
+ return self._CreateMockMethod('__getitem__')(key)
+
+ def __call__(self, *params, **named_params):
+ """Provide custom logic for mocking classes that are callable."""
+
+ # Verify the class we are mocking is callable
+ callable = self._class_to_mock.__dict__.get('__call__', None)
+ if callable is None:
+ raise TypeError('Not callable')
+
+ # Because the call is happening directly on this object instead of a method,
+ # the call on the mock method is made right here
+ mock_method = self._CreateMockMethod('__call__')
+ return mock_method(*params, **named_params)
+
+ @property
+ def __class__(self):
+ """Return the class that is being mocked."""
+
+ return self._class_to_mock
+
+
+class MockMethod(object):
+ """Callable mock method.
+
+ A MockMethod should act exactly like the method it mocks, accepting parameters
+ and returning a value, or throwing an exception (as specified). When this
+ method is called, it can optionally verify whether the called method (name and
+ signature) matches the expected method.
+ """
+
+ def __init__(self, method_name, call_queue, replay_mode):
+ """Construct a new mock method.
+
+ Args:
+ # method_name: the name of the method
+ # call_queue: deque of calls, verify this call against the head, or add
+ # this call to the queue.
+ # replay_mode: False if we are recording, True if we are verifying calls
+ # against the call queue.
+ method_name: str
+ call_queue: list or deque
+ replay_mode: bool
+ """
+
+ self._name = method_name
+ self._call_queue = call_queue
+ if not isinstance(call_queue, deque):
+ self._call_queue = deque(self._call_queue)
+ self._replay_mode = replay_mode
+
+ self._params = None
+ self._named_params = None
+ self._return_value = None
+ self._exception = None
+ self._side_effects = None
+
+ def __call__(self, *params, **named_params):
+ """Log parameters and return the specified return value.
+
+ If the Mock(Anything/Object) associated with this call is in record mode,
+ this MockMethod will be pushed onto the expected call queue. If the mock
+ is in replay mode, this will pop a MockMethod off the top of the queue and
+ verify this call is equal to the expected call.
+
+ Raises:
+ UnexpectedMethodCall if this call is supposed to match an expected method
+ call and it does not.
+ """
+
+ self._params = params
+ self._named_params = named_params
+
+ if not self._replay_mode:
+ self._call_queue.append(self)
+ return self
+
+ expected_method = self._VerifyMethodCall()
+
+ if expected_method._side_effects:
+ expected_method._side_effects(*params, **named_params)
+
+ if expected_method._exception:
+ raise expected_method._exception
+
+ return expected_method._return_value
+
+ def __getattr__(self, name):
+ """Raise an AttributeError with a helpful message."""
+
+ raise AttributeError('MockMethod has no attribute "%s". '
+ 'Did you remember to put your mocks in replay mode?' % name)
+
+ def _PopNextMethod(self):
+ """Pop the next method from our call queue."""
+ try:
+ return self._call_queue.popleft()
+ except IndexError:
+ raise UnexpectedMethodCallError(self, None)
+
+ def _VerifyMethodCall(self):
+ """Verify the called method is expected.
+
+ This can be an ordered method, or part of an unordered set.
+
+ Returns:
+ The expected mock method.
+
+ Raises:
+ UnexpectedMethodCall if the method called was not expected.
+ """
+
+ expected = self._PopNextMethod()
+
+ # Loop here, because we might have a MethodGroup followed by another
+ # group.
+ while isinstance(expected, MethodGroup):
+ expected, method = expected.MethodCalled(self)
+ if method is not None:
+ return method
+
+ # This is a mock method, so just check equality.
+ if expected != self:
+ raise UnexpectedMethodCallError(self, expected)
+
+ return expected
+
+ def __str__(self):
+ params = ', '.join(
+ [repr(p) for p in self._params or []] +
+ ['%s=%r' % x for x in sorted((self._named_params or {}).items())])
+ desc = "%s(%s) -> %r" % (self._name, params, self._return_value)
+ return desc
+
+ def __eq__(self, rhs):
+ """Test whether this MockMethod is equivalent to another MockMethod.
+
+ Args:
+ # rhs: the right hand side of the test
+ rhs: MockMethod
+ """
+
+ return (isinstance(rhs, MockMethod) and
+ self._name == rhs._name and
+ self._params == rhs._params and
+ self._named_params == rhs._named_params)
+
+ def __ne__(self, rhs):
+ """Test whether this MockMethod is not equivalent to another MockMethod.
+
+ Args:
+ # rhs: the right hand side of the test
+ rhs: MockMethod
+ """
+
+ return not self == rhs
+
+ def GetPossibleGroup(self):
+ """Returns a possible group from the end of the call queue or None if no
+ other methods are on the stack.
+ """
+
+ # Remove this method from the tail of the queue so we can add it to a group.
+ this_method = self._call_queue.pop()
+ assert this_method == self
+
+ # Determine if the tail of the queue is a group, or just a regular ordered
+ # mock method.
+ group = None
+ try:
+ group = self._call_queue[-1]
+ except IndexError:
+ pass
+
+ return group
+
+ def _CheckAndCreateNewGroup(self, group_name, group_class):
+ """Checks if the last method (a possible group) is an instance of our
+ group_class. Adds the current method to this group or creates a new one.
+
+ Args:
+
+ group_name: the name of the group.
+ group_class: the class used to create instance of this new group
+ """
+ group = self.GetPossibleGroup()
+
+ # If this is a group, and it is the correct group, add the method.
+ if isinstance(group, group_class) and group.group_name() == group_name:
+ group.AddMethod(self)
+ return self
+
+ # Create a new group and add the method.
+ new_group = group_class(group_name)
+ new_group.AddMethod(self)
+ self._call_queue.append(new_group)
+ return self
+
+ def InAnyOrder(self, group_name="default"):
+ """Move this method into a group of unordered calls.
+
+ A group of unordered calls must be defined together, and must be executed
+ in full before the next expected method can be called. There can be
+ multiple groups that are expected serially, if they are given
+ different group names. The same group name can be reused if there is a
+ standard method call, or a group with a different name, spliced between
+ usages.
+
+ Args:
+ group_name: the name of the unordered group.
+
+ Returns:
+ self
+ """
+ return self._CheckAndCreateNewGroup(group_name, UnorderedGroup)
+
+ def MultipleTimes(self, group_name="default"):
+ """Move this method into group of calls which may be called multiple times.
+
+ A group of repeating calls must be defined together, and must be executed in
+ full before the next expected mehtod can be called.
+
+ Args:
+ group_name: the name of the unordered group.
+
+ Returns:
+ self
+ """
+ return self._CheckAndCreateNewGroup(group_name, MultipleTimesGroup)
+
+ def AndReturn(self, return_value):
+ """Set the value to return when this method is called.
+
+ Args:
+ # return_value can be anything.
+ """
+
+ self._return_value = return_value
+ return return_value
+
+ def AndRaise(self, exception):
+ """Set the exception to raise when this method is called.
+
+ Args:
+ # exception: the exception to raise when this method is called.
+ exception: Exception
+ """
+
+ self._exception = exception
+
+ def WithSideEffects(self, side_effects):
+ """Set the side effects that are simulated when this method is called.
+
+ Args:
+ side_effects: A callable which modifies the parameters or other relevant
+ state which a given test case depends on.
+
+ Returns:
+ Self for chaining with AndReturn and AndRaise.
+ """
+ self._side_effects = side_effects
+ return self
+
+class Comparator:
+ """Base class for all Mox comparators.
+
+ A Comparator can be used as a parameter to a mocked method when the exact
+ value is not known. For example, the code you are testing might build up a
+ long SQL string that is passed to your mock DAO. You're only interested that
+ the IN clause contains the proper primary keys, so you can set your mock
+ up as follows:
+
+ mock_dao.RunQuery(StrContains('IN (1, 2, 4, 5)')).AndReturn(mock_result)
+
+ Now whatever query is passed in must contain the string 'IN (1, 2, 4, 5)'.
+
+ A Comparator may replace one or more parameters, for example:
+ # return at most 10 rows
+ mock_dao.RunQuery(StrContains('SELECT'), 10)
+
+ or
+
+ # Return some non-deterministic number of rows
+ mock_dao.RunQuery(StrContains('SELECT'), IsA(int))
+ """
+
+ def equals(self, rhs):
+ """Special equals method that all comparators must implement.
+
+ Args:
+ rhs: any python object
+ """
+
+ raise NotImplementedError, 'method must be implemented by a subclass.'
+
+ def __eq__(self, rhs):
+ return self.equals(rhs)
+
+ def __ne__(self, rhs):
+ return not self.equals(rhs)
+
+
+class IsA(Comparator):
+ """This class wraps a basic Python type or class. It is used to verify
+ that a parameter is of the given type or class.
+
+ Example:
+ mock_dao.Connect(IsA(DbConnectInfo))
+ """
+
+ def __init__(self, class_name):
+ """Initialize IsA
+
+ Args:
+ class_name: basic python type or a class
+ """
+
+ self._class_name = class_name
+
+ def equals(self, rhs):
+ """Check to see if the RHS is an instance of class_name.
+
+ Args:
+ # rhs: the right hand side of the test
+ rhs: object
+
+ Returns:
+ bool
+ """
+
+ try:
+ return isinstance(rhs, self._class_name)
+ except TypeError:
+ # Check raw types if there was a type error. This is helpful for
+ # things like cStringIO.StringIO.
+ return type(rhs) == type(self._class_name)
+
+ def __repr__(self):
+ return str(self._class_name)
+
+class IsAlmost(Comparator):
+ """Comparison class used to check whether a parameter is nearly equal
+ to a given value. Generally useful for floating point numbers.
+
+ Example mock_dao.SetTimeout((IsAlmost(3.9)))
+ """
+
+ def __init__(self, float_value, places=7):
+ """Initialize IsAlmost.
+
+ Args:
+ float_value: The value for making the comparison.
+ places: The number of decimal places to round to.
+ """
+
+ self._float_value = float_value
+ self._places = places
+
+ def equals(self, rhs):
+ """Check to see if RHS is almost equal to float_value
+
+ Args:
+ rhs: the value to compare to float_value
+
+ Returns:
+ bool
+ """
+
+ try:
+ return round(rhs-self._float_value, self._places) == 0
+ except TypeError:
+ # This is probably because either float_value or rhs is not a number.
+ return False
+
+ def __repr__(self):
+ return str(self._float_value)
+
+class StrContains(Comparator):
+ """Comparison class used to check whether a substring exists in a
+ string parameter. This can be useful in mocking a database with SQL
+ passed in as a string parameter, for example.
+
+ Example:
+ mock_dao.RunQuery(StrContains('IN (1, 2, 4, 5)')).AndReturn(mock_result)
+ """
+
+ def __init__(self, search_string):
+ """Initialize.
+
+ Args:
+ # search_string: the string you are searching for
+ search_string: str
+ """
+
+ self._search_string = search_string
+
+ def equals(self, rhs):
+ """Check to see if the search_string is contained in the rhs string.
+
+ Args:
+ # rhs: the right hand side of the test
+ rhs: object
+
+ Returns:
+ bool
+ """
+
+ try:
+ return rhs.find(self._search_string) > -1
+ except Exception:
+ return False
+
+ def __repr__(self):
+ return '<str containing \'%s\'>' % self._search_string
+
+
+class Regex(Comparator):
+ """Checks if a string matches a regular expression.
+
+ This uses a given regular expression to determine equality.
+ """
+
+ def __init__(self, pattern, flags=0):
+ """Initialize.
+
+ Args:
+ # pattern is the regular expression to search for
+ pattern: str
+ # flags passed to re.compile function as the second argument
+ flags: int
+ """
+
+ self.regex = re.compile(pattern, flags=flags)
+
+ def equals(self, rhs):
+ """Check to see if rhs matches regular expression pattern.
+
+ Returns:
+ bool
+ """
+
+ return self.regex.search(rhs) is not None
+
+ def __repr__(self):
+ s = '<regular expression \'%s\'' % self.regex.pattern
+ if self.regex.flags:
+ s += ', flags=%d' % self.regex.flags
+ s += '>'
+ return s
+
+
+class In(Comparator):
+ """Checks whether an item (or key) is in a list (or dict) parameter.
+
+ Example:
+ mock_dao.GetUsersInfo(In('expectedUserName')).AndReturn(mock_result)
+ """
+
+ def __init__(self, key):
+ """Initialize.
+
+ Args:
+ # key is any thing that could be in a list or a key in a dict
+ """
+
+ self._key = key
+
+ def equals(self, rhs):
+ """Check to see whether key is in rhs.
+
+ Args:
+ rhs: dict
+
+ Returns:
+ bool
+ """
+
+ return self._key in rhs
+
+ def __repr__(self):
+ return '<sequence or map containing \'%s\'>' % self._key
+
+
+class ContainsKeyValue(Comparator):
+ """Checks whether a key/value pair is in a dict parameter.
+
+ Example:
+ mock_dao.UpdateUsers(ContainsKeyValue('stevepm', stevepm_user_info))
+ """
+
+ def __init__(self, key, value):
+ """Initialize.
+
+ Args:
+ # key: a key in a dict
+ # value: the corresponding value
+ """
+
+ self._key = key
+ self._value = value
+
+ def equals(self, rhs):
+ """Check whether the given key/value pair is in the rhs dict.
+
+ Returns:
+ bool
+ """
+
+ try:
+ return rhs[self._key] == self._value
+ except Exception:
+ return False
+
+ def __repr__(self):
+ return '<map containing the entry \'%s: %s\'>' % (self._key, self._value)
+
+
+class SameElementsAs(Comparator):
+ """Checks whether iterables contain the same elements (ignoring order).
+
+ Example:
+ mock_dao.ProcessUsers(SameElementsAs('stevepm', 'salomaki'))
+ """
+
+ def __init__(self, expected_seq):
+ """Initialize.
+
+ Args:
+ expected_seq: a sequence
+ """
+
+ self._expected_seq = expected_seq
+
+ def equals(self, actual_seq):
+ """Check to see whether actual_seq has same elements as expected_seq.
+
+ Args:
+ actual_seq: sequence
+
+ Returns:
+ bool
+ """
+
+ try:
+ expected = dict([(element, None) for element in self._expected_seq])
+ actual = dict([(element, None) for element in actual_seq])
+ except TypeError:
+ # Fall back to slower list-compare if any of the objects are unhashable.
+ expected = list(self._expected_seq)
+ actual = list(actual_seq)
+ expected.sort()
+ actual.sort()
+ return expected == actual
+
+ def __repr__(self):
+ return '<sequence with same elements as \'%s\'>' % self._expected_seq
+
+
+class And(Comparator):
+ """Evaluates one or more Comparators on RHS and returns an AND of the results.
+ """
+
+ def __init__(self, *args):
+ """Initialize.
+
+ Args:
+ *args: One or more Comparator
+ """
+
+ self._comparators = args
+
+ def equals(self, rhs):
+ """Checks whether all Comparators are equal to rhs.
+
+ Args:
+ # rhs: can be anything
+
+ Returns:
+ bool
+ """
+
+ for comparator in self._comparators:
+ if not comparator.equals(rhs):
+ return False
+
+ return True
+
+ def __repr__(self):
+ return '<AND %s>' % str(self._comparators)
+
+
+class Or(Comparator):
+ """Evaluates one or more Comparators on RHS and returns an OR of the results.
+ """
+
+ def __init__(self, *args):
+ """Initialize.
+
+ Args:
+ *args: One or more Mox comparators
+ """
+
+ self._comparators = args
+
+ def equals(self, rhs):
+ """Checks whether any Comparator is equal to rhs.
+
+ Args:
+ # rhs: can be anything
+
+ Returns:
+ bool
+ """
+
+ for comparator in self._comparators:
+ if comparator.equals(rhs):
+ return True
+
+ return False
+
+ def __repr__(self):
+ return '<OR %s>' % str(self._comparators)
+
+
+class Func(Comparator):
+ """Call a function that should verify the parameter passed in is correct.
+
+ You may need the ability to perform more advanced operations on the parameter
+ in order to validate it. You can use this to have a callable validate any
+ parameter. The callable should return either True or False.
+
+
+ Example:
+
+ def myParamValidator(param):
+ # Advanced logic here
+ return True
+
+ mock_dao.DoSomething(Func(myParamValidator), true)
+ """
+
+ def __init__(self, func):
+ """Initialize.
+
+ Args:
+ func: callable that takes one parameter and returns a bool
+ """
+
+ self._func = func
+
+ def equals(self, rhs):
+ """Test whether rhs passes the function test.
+
+ rhs is passed into func.
+
+ Args:
+ rhs: any python object
+
+ Returns:
+ the result of func(rhs)
+ """
+
+ return self._func(rhs)
+
+ def __repr__(self):
+ return str(self._func)
+
+
+class IgnoreArg(Comparator):
+ """Ignore an argument.
+
+ This can be used when we don't care about an argument of a method call.
+
+ Example:
+ # Check if CastMagic is called with 3 as first arg and 'disappear' as third.
+ mymock.CastMagic(3, IgnoreArg(), 'disappear')
+ """
+
+ def equals(self, unused_rhs):
+ """Ignores arguments and returns True.
+
+ Args:
+ unused_rhs: any python object
+
+ Returns:
+ always returns True
+ """
+
+ return True
+
+ def __repr__(self):
+ return '<IgnoreArg>'
+
+
+class MethodGroup(object):
+ """Base class containing common behaviour for MethodGroups."""
+
+ def __init__(self, group_name):
+ self._group_name = group_name
+
+ def group_name(self):
+ return self._group_name
+
+ def __str__(self):
+ return '<%s "%s">' % (self.__class__.__name__, self._group_name)
+
+ def AddMethod(self, mock_method):
+ raise NotImplementedError
+
+ def MethodCalled(self, mock_method):
+ raise NotImplementedError
+
+ def IsSatisfied(self):
+ raise NotImplementedError
+
+class UnorderedGroup(MethodGroup):
+ """UnorderedGroup holds a set of method calls that may occur in any order.
+
+ This construct is helpful for non-deterministic events, such as iterating
+ over the keys of a dict.
+ """
+
+ def __init__(self, group_name):
+ super(UnorderedGroup, self).__init__(group_name)
+ self._methods = []
+
+ def AddMethod(self, mock_method):
+ """Add a method to this group.
+
+ Args:
+ mock_method: A mock method to be added to this group.
+ """
+
+ self._methods.append(mock_method)
+
+ def MethodCalled(self, mock_method):
+ """Remove a method call from the group.
+
+ If the method is not in the set, an UnexpectedMethodCallError will be
+ raised.
+
+ Args:
+ mock_method: a mock method that should be equal to a method in the group.
+
+ Returns:
+ The mock method from the group
+
+ Raises:
+ UnexpectedMethodCallError if the mock_method was not in the group.
+ """
+
+ # Check to see if this method exists, and if so, remove it from the set
+ # and return it.
+ for method in self._methods:
+ if method == mock_method:
+ # Remove the called mock_method instead of the method in the group.
+ # The called method will match any comparators when equality is checked
+ # during removal. The method in the group could pass a comparator to
+ # another comparator during the equality check.
+ self._methods.remove(mock_method)
+
+ # If this group is not empty, put it back at the head of the queue.
+ if not self.IsSatisfied():
+ mock_method._call_queue.appendleft(self)
+
+ return self, method
+
+ raise UnexpectedMethodCallError(mock_method, self)
+
+ def IsSatisfied(self):
+ """Return True if there are not any methods in this group."""
+
+ return len(self._methods) == 0
+
+
+class MultipleTimesGroup(MethodGroup):
+ """MultipleTimesGroup holds methods that may be called any number of times.
+
+ Note: Each method must be called at least once.
+
+ This is helpful, if you don't know or care how many times a method is called.
+ """
+
+ def __init__(self, group_name):
+ super(MultipleTimesGroup, self).__init__(group_name)
+ self._methods = set()
+ self._methods_called = set()
+
+ def AddMethod(self, mock_method):
+ """Add a method to this group.
+
+ Args:
+ mock_method: A mock method to be added to this group.
+ """
+
+ self._methods.add(mock_method)
+
+ def MethodCalled(self, mock_method):
+ """Remove a method call from the group.
+
+ If the method is not in the set, an UnexpectedMethodCallError will be
+ raised.
+
+ Args:
+ mock_method: a mock method that should be equal to a method in the group.
+
+ Returns:
+ The mock method from the group
+
+ Raises:
+ UnexpectedMethodCallError if the mock_method was not in the group.
+ """
+
+ # Check to see if this method exists, and if so add it to the set of
+ # called methods.
+
+ for method in self._methods:
+ if method == mock_method:
+ self._methods_called.add(mock_method)
+ # Always put this group back on top of the queue, because we don't know
+ # when we are done.
+ mock_method._call_queue.appendleft(self)
+ return self, method
+
+ if self.IsSatisfied():
+ next_method = mock_method._PopNextMethod();
+ return next_method, None
+ else:
+ raise UnexpectedMethodCallError(mock_method, self)
+
+ def IsSatisfied(self):
+ """Return True if all methods in this group are called at least once."""
+ # NOTE(psycho): We can't use the simple set difference here because we want
+ # to match different parameters which are considered the same e.g. IsA(str)
+ # and some string. This solution is O(n^2) but n should be small.
+ tmp = self._methods.copy()
+ for called in self._methods_called:
+ for expected in tmp:
+ if called == expected:
+ tmp.remove(expected)
+ if not tmp:
+ return True
+ break
+ return False
+
+
+class MoxMetaTestBase(type):
+ """Metaclass to add mox cleanup and verification to every test.
+
+ As the mox unit testing class is being constructed (MoxTestBase or a
+ subclass), this metaclass will modify all test functions to call the
+ CleanUpMox method of the test class after they finish. This means that
+ unstubbing and verifying will happen for every test with no additional code,
+ and any failures will result in test failures as opposed to errors.
+ """
+
+ def __init__(cls, name, bases, d):
+ type.__init__(cls, name, bases, d)
+
+ # also get all the attributes from the base classes to account
+ # for a case when test class is not the immediate child of MoxTestBase
+ for base in bases:
+ for attr_name in dir(base):
+ d[attr_name] = getattr(base, attr_name)
+
+ for func_name, func in d.items():
+ if func_name.startswith('test') and callable(func):
+ setattr(cls, func_name, MoxMetaTestBase.CleanUpTest(cls, func))
+
+ @staticmethod
+ def CleanUpTest(cls, func):
+ """Adds Mox cleanup code to any MoxTestBase method.
+
+ Always unsets stubs after a test. Will verify all mocks for tests that
+ otherwise pass.
+
+ Args:
+ cls: MoxTestBase or subclass; the class whose test method we are altering.
+ func: method; the method of the MoxTestBase test class we wish to alter.
+
+ Returns:
+ The modified method.
+ """
+ def new_method(self, *args, **kwargs):
+ mox_obj = getattr(self, 'mox', None)
+ cleanup_mox = False
+ if mox_obj and isinstance(mox_obj, Mox):
+ cleanup_mox = True
+ try:
+ func(self, *args, **kwargs)
+ finally:
+ if cleanup_mox:
+ mox_obj.UnsetStubs()
+ if cleanup_mox:
+ mox_obj.VerifyAll()
+ new_method.__name__ = func.__name__
+ new_method.__doc__ = func.__doc__
+ new_method.__module__ = func.__module__
+ return new_method
+
+
+class MoxTestBase(unittest.TestCase):
+ """Convenience test class to make stubbing easier.
+
+ Sets up a "mox" attribute which is an instance of Mox - any mox tests will
+ want this. Also automatically unsets any stubs and verifies that all mock
+ methods have been called at the end of each test, eliminating boilerplate
+ code.
+ """
+
+ __metaclass__ = MoxMetaTestBase
+
+ def setUp(self):
+ self.mox = Mox()
diff --git a/third_party/protobuf/python/setup.cfg b/third_party/protobuf/python/setup.cfg
new file mode 100644
index 0000000000..2a9acf13da
--- /dev/null
+++ b/third_party/protobuf/python/setup.cfg
@@ -0,0 +1,2 @@
+[bdist_wheel]
+universal = 1
diff --git a/third_party/protobuf/python/setup.py b/third_party/protobuf/python/setup.py
new file mode 100755
index 0000000000..a2026706e4
--- /dev/null
+++ b/third_party/protobuf/python/setup.py
@@ -0,0 +1,261 @@
+#! /usr/bin/env python
+#
+# See README for usage instructions.
+import glob
+import os
+import subprocess
+import sys
+import platform
+
+# We must use setuptools, not distutils, because we need to use the
+# namespace_packages option for the "google" package.
+from setuptools import setup, Extension, find_packages
+
+from distutils.command.clean import clean as _clean
+
+if sys.version_info[0] == 3:
+ # Python 3
+ from distutils.command.build_py import build_py_2to3 as _build_py
+else:
+ # Python 2
+ from distutils.command.build_py import build_py as _build_py
+from distutils.spawn import find_executable
+
+# Find the Protocol Compiler.
+if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']):
+ protoc = os.environ['PROTOC']
+elif os.path.exists("../src/protoc"):
+ protoc = "../src/protoc"
+elif os.path.exists("../src/protoc.exe"):
+ protoc = "../src/protoc.exe"
+elif os.path.exists("../vsprojects/Debug/protoc.exe"):
+ protoc = "../vsprojects/Debug/protoc.exe"
+elif os.path.exists("../vsprojects/Release/protoc.exe"):
+ protoc = "../vsprojects/Release/protoc.exe"
+else:
+ protoc = find_executable("protoc")
+
+
+def GetVersion():
+ """Gets the version from google/protobuf/__init__.py
+
+ Do not import google.protobuf.__init__ directly, because an installed
+ protobuf library may be loaded instead."""
+
+ with open(os.path.join('google', 'protobuf', '__init__.py')) as version_file:
+ exec(version_file.read(), globals())
+ return __version__
+
+
+def generate_proto(source, require = True):
+ """Invokes the Protocol Compiler to generate a _pb2.py from the given
+ .proto file. Does nothing if the output already exists and is newer than
+ the input."""
+
+ if not require and not os.path.exists(source):
+ return
+
+ output = source.replace(".proto", "_pb2.py").replace("../src/", "")
+
+ if (not os.path.exists(output) or
+ (os.path.exists(source) and
+ os.path.getmtime(source) > os.path.getmtime(output))):
+ print("Generating %s..." % output)
+
+ if not os.path.exists(source):
+ sys.stderr.write("Can't find required file: %s\n" % source)
+ sys.exit(-1)
+
+ if protoc is None:
+ sys.stderr.write(
+ "protoc is not installed nor found in ../src. Please compile it "
+ "or install the binary package.\n")
+ sys.exit(-1)
+
+ protoc_command = [ protoc, "-I../src", "-I.", "--python_out=.", source ]
+ if subprocess.call(protoc_command) != 0:
+ sys.exit(-1)
+
+def GenerateUnittestProtos():
+ generate_proto("../src/google/protobuf/any_test.proto", False)
+ generate_proto("../src/google/protobuf/map_unittest.proto", False)
+ generate_proto("../src/google/protobuf/test_messages_proto3.proto", False)
+ generate_proto("../src/google/protobuf/unittest_arena.proto", False)
+ generate_proto("../src/google/protobuf/unittest_no_arena.proto", False)
+ generate_proto("../src/google/protobuf/unittest_no_arena_import.proto", False)
+ generate_proto("../src/google/protobuf/unittest.proto", False)
+ generate_proto("../src/google/protobuf/unittest_custom_options.proto", False)
+ generate_proto("../src/google/protobuf/unittest_import.proto", False)
+ generate_proto("../src/google/protobuf/unittest_import_public.proto", False)
+ generate_proto("../src/google/protobuf/unittest_mset.proto", False)
+ generate_proto("../src/google/protobuf/unittest_mset_wire_format.proto", False)
+ generate_proto("../src/google/protobuf/unittest_no_generic_services.proto", False)
+ generate_proto("../src/google/protobuf/unittest_proto3_arena.proto", False)
+ generate_proto("../src/google/protobuf/util/json_format_proto3.proto", False)
+ generate_proto("google/protobuf/internal/any_test.proto", False)
+ generate_proto("google/protobuf/internal/descriptor_pool_test1.proto", False)
+ generate_proto("google/protobuf/internal/descriptor_pool_test2.proto", False)
+ generate_proto("google/protobuf/internal/factory_test1.proto", False)
+ generate_proto("google/protobuf/internal/factory_test2.proto", False)
+ generate_proto("google/protobuf/internal/file_options_test.proto", False)
+ generate_proto("google/protobuf/internal/import_test_package/inner.proto", False)
+ generate_proto("google/protobuf/internal/import_test_package/outer.proto", False)
+ generate_proto("google/protobuf/internal/missing_enum_values.proto", False)
+ generate_proto("google/protobuf/internal/message_set_extensions.proto", False)
+ generate_proto("google/protobuf/internal/more_extensions.proto", False)
+ generate_proto("google/protobuf/internal/more_extensions_dynamic.proto", False)
+ generate_proto("google/protobuf/internal/more_messages.proto", False)
+ generate_proto("google/protobuf/internal/packed_field_test.proto", False)
+ generate_proto("google/protobuf/internal/test_bad_identifiers.proto", False)
+ generate_proto("google/protobuf/pyext/python.proto", False)
+
+
+class clean(_clean):
+ def run(self):
+ # Delete generated files in the code tree.
+ for (dirpath, dirnames, filenames) in os.walk("."):
+ for filename in filenames:
+ filepath = os.path.join(dirpath, filename)
+ if filepath.endswith("_pb2.py") or filepath.endswith(".pyc") or \
+ filepath.endswith(".so") or filepath.endswith(".o") or \
+ filepath.endswith('google/protobuf/compiler/__init__.py') or \
+ filepath.endswith('google/protobuf/util/__init__.py'):
+ os.remove(filepath)
+ # _clean is an old-style class, so super() doesn't work.
+ _clean.run(self)
+
+class build_py(_build_py):
+ def run(self):
+ # Generate necessary .proto file if it doesn't exist.
+ generate_proto("../src/google/protobuf/descriptor.proto")
+ generate_proto("../src/google/protobuf/compiler/plugin.proto")
+ generate_proto("../src/google/protobuf/any.proto")
+ generate_proto("../src/google/protobuf/api.proto")
+ generate_proto("../src/google/protobuf/duration.proto")
+ generate_proto("../src/google/protobuf/empty.proto")
+ generate_proto("../src/google/protobuf/field_mask.proto")
+ generate_proto("../src/google/protobuf/source_context.proto")
+ generate_proto("../src/google/protobuf/struct.proto")
+ generate_proto("../src/google/protobuf/timestamp.proto")
+ generate_proto("../src/google/protobuf/type.proto")
+ generate_proto("../src/google/protobuf/wrappers.proto")
+ GenerateUnittestProtos()
+
+ # Make sure google.protobuf/** are valid packages.
+ for path in ['', 'internal/', 'compiler/', 'pyext/', 'util/']:
+ try:
+ open('google/protobuf/%s__init__.py' % path, 'a').close()
+ except EnvironmentError:
+ pass
+ # _build_py is an old-style class, so super() doesn't work.
+ _build_py.run(self)
+
+class test_conformance(_build_py):
+ target = 'test_python'
+ def run(self):
+ if sys.version_info >= (2, 7):
+ # Python 2.6 dodges these extra failures.
+ os.environ["CONFORMANCE_PYTHON_EXTRA_FAILURES"] = (
+ "--failure_list failure_list_python-post26.txt")
+ cmd = 'cd ../conformance && make %s' % (test_conformance.target)
+ status = subprocess.check_call(cmd, shell=True)
+
+
+def get_option_from_sys_argv(option_str):
+ if option_str in sys.argv:
+ sys.argv.remove(option_str)
+ return True
+ return False
+
+
+if __name__ == '__main__':
+ ext_module_list = []
+ warnings_as_errors = '--warnings_as_errors'
+ if get_option_from_sys_argv('--cpp_implementation'):
+ # Link libprotobuf.a and libprotobuf-lite.a statically with the
+ # extension. Note that those libraries have to be compiled with
+ # -fPIC for this to work.
+ compile_static_ext = get_option_from_sys_argv('--compile_static_extension')
+ extra_compile_args = ['-Wno-write-strings',
+ '-Wno-invalid-offsetof',
+ '-Wno-sign-compare']
+ libraries = ['protobuf']
+ extra_objects = None
+ if compile_static_ext:
+ libraries = None
+ extra_objects = ['../src/.libs/libprotobuf.a',
+ '../src/.libs/libprotobuf-lite.a']
+ test_conformance.target = 'test_python_cpp'
+
+ if "clang" in os.popen('$CC --version 2> /dev/null').read():
+ extra_compile_args.append('-Wno-shorten-64-to-32')
+
+ v, _, _ = platform.mac_ver()
+ if v:
+ v = float('.'.join(v.split('.')[:2]))
+ if v >= 10.12:
+ extra_compile_args.append('-std=c++11')
+
+ if warnings_as_errors in sys.argv:
+ extra_compile_args.append('-Werror')
+ sys.argv.remove(warnings_as_errors)
+
+ # C++ implementation extension
+ ext_module_list.extend([
+ Extension(
+ "google.protobuf.pyext._message",
+ glob.glob('google/protobuf/pyext/*.cc'),
+ include_dirs=[".", "../src"],
+ libraries=libraries,
+ extra_objects=extra_objects,
+ library_dirs=['../src/.libs'],
+ extra_compile_args=extra_compile_args,
+ ),
+ Extension(
+ "google.protobuf.internal._api_implementation",
+ glob.glob('google/protobuf/internal/api_implementation.cc'),
+ extra_compile_args=['-DPYTHON_PROTO2_CPP_IMPL_V2'],
+ ),
+ ])
+ os.environ['PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'] = 'cpp'
+
+ # Keep this list of dependencies in sync with tox.ini.
+ install_requires = ['six>=1.9', 'setuptools']
+ if sys.version_info <= (2,7):
+ install_requires.append('ordereddict')
+ install_requires.append('unittest2')
+
+ setup(
+ name='protobuf',
+ version=GetVersion(),
+ description='Protocol Buffers',
+ download_url='https://github.com/google/protobuf/releases',
+ long_description="Protocol Buffers are Google's data interchange format",
+ url='https://developers.google.com/protocol-buffers/',
+ maintainer='protobuf@googlegroups.com',
+ maintainer_email='protobuf@googlegroups.com',
+ license='3-Clause BSD License',
+ classifiers=[
+ "Programming Language :: Python",
+ "Programming Language :: Python :: 2",
+ "Programming Language :: Python :: 2.6",
+ "Programming Language :: Python :: 2.7",
+ "Programming Language :: Python :: 3",
+ "Programming Language :: Python :: 3.3",
+ "Programming Language :: Python :: 3.4",
+ ],
+ namespace_packages=['google'],
+ packages=find_packages(
+ exclude=[
+ 'import_test_package',
+ ],
+ ),
+ test_suite='google.protobuf.internal',
+ cmdclass={
+ 'clean': clean,
+ 'build_py': build_py,
+ 'test_conformance': test_conformance,
+ },
+ install_requires=install_requires,
+ ext_modules=ext_module_list,
+ )
diff --git a/third_party/protobuf/python/stubout.py b/third_party/protobuf/python/stubout.py
new file mode 100755
index 0000000000..aee4f2da20
--- /dev/null
+++ b/third_party/protobuf/python/stubout.py
@@ -0,0 +1,140 @@
+#!/usr/bin/python2.4
+#
+# Copyright 2008 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This file is used for testing. The original is at:
+# http://code.google.com/p/pymox/
+
+class StubOutForTesting:
+ """Sample Usage:
+ You want os.path.exists() to always return true during testing.
+
+ stubs = StubOutForTesting()
+ stubs.Set(os.path, 'exists', lambda x: 1)
+ ...
+ stubs.UnsetAll()
+
+ The above changes os.path.exists into a lambda that returns 1. Once
+ the ... part of the code finishes, the UnsetAll() looks up the old value
+ of os.path.exists and restores it.
+
+ """
+ def __init__(self):
+ self.cache = []
+ self.stubs = []
+
+ def __del__(self):
+ self.SmartUnsetAll()
+ self.UnsetAll()
+
+ def SmartSet(self, obj, attr_name, new_attr):
+ """Replace obj.attr_name with new_attr. This method is smart and works
+ at the module, class, and instance level while preserving proper
+ inheritance. It will not stub out C types however unless that has been
+ explicitly allowed by the type.
+
+ This method supports the case where attr_name is a staticmethod or a
+ classmethod of obj.
+
+ Notes:
+ - If obj is an instance, then it is its class that will actually be
+ stubbed. Note that the method Set() does not do that: if obj is
+ an instance, it (and not its class) will be stubbed.
+ - The stubbing is using the builtin getattr and setattr. So, the __get__
+ and __set__ will be called when stubbing (TODO: A better idea would
+ probably be to manipulate obj.__dict__ instead of getattr() and
+ setattr()).
+
+ Raises AttributeError if the attribute cannot be found.
+ """
+ if (inspect.ismodule(obj) or
+ (not inspect.isclass(obj) and obj.__dict__.has_key(attr_name))):
+ orig_obj = obj
+ orig_attr = getattr(obj, attr_name)
+
+ else:
+ if not inspect.isclass(obj):
+ mro = list(inspect.getmro(obj.__class__))
+ else:
+ mro = list(inspect.getmro(obj))
+
+ mro.reverse()
+
+ orig_attr = None
+
+ for cls in mro:
+ try:
+ orig_obj = cls
+ orig_attr = getattr(obj, attr_name)
+ except AttributeError:
+ continue
+
+ if orig_attr is None:
+ raise AttributeError("Attribute not found.")
+
+ # Calling getattr() on a staticmethod transforms it to a 'normal' function.
+ # We need to ensure that we put it back as a staticmethod.
+ old_attribute = obj.__dict__.get(attr_name)
+ if old_attribute is not None and isinstance(old_attribute, staticmethod):
+ orig_attr = staticmethod(orig_attr)
+
+ self.stubs.append((orig_obj, attr_name, orig_attr))
+ setattr(orig_obj, attr_name, new_attr)
+
+ def SmartUnsetAll(self):
+ """Reverses all the SmartSet() calls, restoring things to their original
+ definition. Its okay to call SmartUnsetAll() repeatedly, as later calls
+ have no effect if no SmartSet() calls have been made.
+
+ """
+ self.stubs.reverse()
+
+ for args in self.stubs:
+ setattr(*args)
+
+ self.stubs = []
+
+ def Set(self, parent, child_name, new_child):
+ """Replace child_name's old definition with new_child, in the context
+ of the given parent. The parent could be a module when the child is a
+ function at module scope. Or the parent could be a class when a class'
+ method is being replaced. The named child is set to new_child, while
+ the prior definition is saved away for later, when UnsetAll() is called.
+
+ This method supports the case where child_name is a staticmethod or a
+ classmethod of parent.
+ """
+ old_child = getattr(parent, child_name)
+
+ old_attribute = parent.__dict__.get(child_name)
+ if old_attribute is not None and isinstance(old_attribute, staticmethod):
+ old_child = staticmethod(old_child)
+
+ self.cache.append((parent, old_child, child_name))
+ setattr(parent, child_name, new_child)
+
+ def UnsetAll(self):
+ """Reverses all the Set() calls, restoring things to their original
+ definition. Its okay to call UnsetAll() repeatedly, as later calls have
+ no effect if no Set() calls have been made.
+
+ """
+ # Undo calls to Set() in reverse order, in case Set() was called on the
+ # same arguments repeatedly (want the original call to be last one undone)
+ self.cache.reverse()
+
+ for (parent, old_child, child_name) in self.cache:
+ setattr(parent, child_name, old_child)
+ self.cache = []
diff --git a/third_party/protobuf/python/tox.ini b/third_party/protobuf/python/tox.ini
new file mode 100644
index 0000000000..1600db21fc
--- /dev/null
+++ b/third_party/protobuf/python/tox.ini
@@ -0,0 +1,24 @@
+[tox]
+envlist =
+ py{26,27,33,34}-{cpp,python}
+
+[testenv]
+usedevelop=true
+passenv = CC
+setenv =
+ cpp: LD_LIBRARY_PATH={toxinidir}/../src/.libs
+ cpp: DYLD_LIBRARY_PATH={toxinidir}/../src/.libs
+ cpp: PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
+commands =
+ python setup.py -q build_py
+ python: python setup.py -q build
+ cpp: python setup.py -q build --cpp_implementation --warnings_as_errors --compile_static_extension
+ python: python setup.py -q test -q
+ cpp: python setup.py -q test -q --cpp_implementation
+ python: python setup.py -q test_conformance
+ cpp: python setup.py -q test_conformance --cpp_implementation
+deps =
+ # Keep this list of dependencies in sync with setup.py.
+ six>=1.9
+ py26: ordereddict
+ py26: unittest2
diff --git a/third_party/protobuf/ruby/.gitignore b/third_party/protobuf/ruby/.gitignore
new file mode 100644
index 0000000000..bd8745dd85
--- /dev/null
+++ b/third_party/protobuf/ruby/.gitignore
@@ -0,0 +1,8 @@
+*.bundle
+tags
+.idea/
+lib/google/protobuf_java.jar
+protobuf-jruby.iml
+target/
+pkg/
+tmp/
diff --git a/third_party/protobuf/ruby/Gemfile b/third_party/protobuf/ruby/Gemfile
new file mode 100644
index 0000000000..fa75df1563
--- /dev/null
+++ b/third_party/protobuf/ruby/Gemfile
@@ -0,0 +1,3 @@
+source 'https://rubygems.org'
+
+gemspec
diff --git a/third_party/protobuf/ruby/README.md b/third_party/protobuf/ruby/README.md
new file mode 100644
index 0000000000..f28e05a72b
--- /dev/null
+++ b/third_party/protobuf/ruby/README.md
@@ -0,0 +1,114 @@
+This directory contains the Ruby extension that implements Protocol Buffers
+functionality in Ruby.
+
+The Ruby extension makes use of generated Ruby code that defines message and
+enum types in a Ruby DSL. You may write definitions in this DSL directly, but
+we recommend using protoc's Ruby generation support with .proto files. The
+build process in this directory only installs the extension; you need to
+install protoc as well to have Ruby code generation functionality.
+
+Installation from Gem
+---------------------
+
+When we release a version of Protocol Buffers, we will upload a Gem to
+[RubyGems](https://www.rubygems.org/). To use this pre-packaged gem, simply
+install it as you would any other gem:
+
+ $ gem install [--prerelease] google-protobuf
+
+The `--pre` flag is necessary if we have not yet made a non-alpha/beta release
+of the Ruby extension; it allows `gem` to consider these "pre-release"
+alpha/beta versions.
+
+Once the gem is installed, you may or may not need `protoc`. If you write your
+message type descriptions directly in the Ruby DSL, you do not need it.
+However, if you wish to generate the Ruby DSL from a `.proto` file, you will
+also want to install Protocol Buffers itself, as described in this repository's
+main `README` file. The version of `protoc` included in the latest release
+supports the `--ruby_out` option to generate Ruby code.
+
+A simple example of using the Ruby extension follows. More extensive
+documentation may be found in the RubyDoc comments (`call-seq` tags) in the
+source, and we plan to release separate, more detailed, documentation at a
+later date.
+
+```ruby
+require 'google/protobuf'
+
+# generated from my_proto_types.proto with protoc:
+# $ protoc --ruby_out=. my_proto_types.proto
+require 'my_proto_types'
+
+mymessage = MyTestMessage.new(:field1 => 42, :field2 => ["a", "b", "c"])
+mymessage.field1 = 43
+mymessage.field2.push("d")
+mymessage.field3 = SubMessage.new(:foo => 100)
+
+encoded_data = MyTestMessage.encode(mymessage)
+decoded = MyTestMessage.decode(encoded_data)
+assert decoded == mymessage
+
+puts "JSON:"
+puts MyTestMessage.encode_json(mymessage)
+```
+
+Installation from Source (Building Gem)
+---------------------------------------
+
+To build this Ruby extension, you will need:
+
+* Rake
+* Bundler
+* Ruby development headers
+* a C compiler
+
+To Build the JRuby extension, you will need:
+
+* Maven
+* The latest version of the protobuf java library (see ../java/README.md)
+* Install JRuby via rbenv or RVM
+
+First switch to the desired platform with rbenv or RVM.
+
+Then install the required Ruby gems:
+
+ $ gem install bundler
+ $ bundle
+
+Then build the Gem:
+
+ $ rake
+ $ rake clobber_package gem
+ $ gem install `ls pkg/google-protobuf-*.gem`
+
+To run the specs:
+
+ $ rake test
+
+This gem includes the upb parsing and serialization library as a single-file
+amalgamation. It is up-to-date with upb git commit
+`535bc2fe2f2b467f59347ffc9449e11e47791257`.
+
+Version Number Scheme
+---------------------
+
+We are using a version number scheme that is a hybrid of Protocol Buffers'
+overall version number and some Ruby-specific rules. Gem does not allow
+re-uploads of a gem with the same version number, so we add a sequence number
+("upload version") to the version. We also format alphabetical tags (alpha,
+pre, ...) slightly differently, and we avoid hyphens. In more detail:
+
+* First, we determine the prefix: a Protocol Buffers version "3.0.0-alpha-2"
+ becomes "3.0.0.alpha.2". When we release 3.0.0, this prefix will be simply
+ "3.0.0".
+* We then append the upload version: "3.0.0.alpha.2.0" or "3.0.0.0". If we need
+ to upload a new version of the gem to fix an issue, the version becomes
+ "3.0.0.alpha.2.1" or "3.0.0.1".
+* If we are working on a prerelease version, we append a prerelease tag:
+ "3.0.0.alpha.3.0.pre". The prerelease tag comes at the end so that when
+ version numbers are sorted, any prerelease builds are ordered between the
+ prior version and current version.
+
+These rules are designed to work with the sorting rules for
+[Gem::Version](http://ruby-doc.org/stdlib-2.0/libdoc/rubygems/rdoc/Gem/Version.html):
+release numbers should sort in actual release order.
diff --git a/third_party/protobuf/ruby/Rakefile b/third_party/protobuf/ruby/Rakefile
new file mode 100644
index 0000000000..a329a777b4
--- /dev/null
+++ b/third_party/protobuf/ruby/Rakefile
@@ -0,0 +1,108 @@
+require "rubygems"
+require "rubygems/package_task"
+require "rake/extensiontask" unless RUBY_PLATFORM == "java"
+require "rake/testtask"
+
+spec = Gem::Specification.load("google-protobuf.gemspec")
+
+well_known_protos = %w[
+ google/protobuf/any.proto
+ google/protobuf/api.proto
+ google/protobuf/duration.proto
+ google/protobuf/empty.proto
+ google/protobuf/field_mask.proto
+ google/protobuf/source_context.proto
+ google/protobuf/struct.proto
+ google/protobuf/timestamp.proto
+ google/protobuf/type.proto
+ google/protobuf/wrappers.proto
+]
+
+# These are omitted for now because we don't support proto2.
+proto2_protos = %w[
+ google/protobuf/descriptor.proto
+ google/protobuf/compiler/plugin.proto
+]
+
+genproto_output = []
+
+# We won't have access to .. from within docker, but the proto files
+# will be there, thanks to the :genproto rule dependency for gem:native.
+unless ENV['IN_DOCKER'] == 'true'
+ well_known_protos.each do |proto_file|
+ input_file = "../src/" + proto_file
+ output_file = "lib/" + proto_file.sub(/\.proto$/, "_pb.rb")
+ genproto_output << output_file
+ file output_file => input_file do |file_task|
+ sh "../src/protoc -I../src --ruby_out=lib #{input_file}"
+ end
+ end
+end
+
+if RUBY_PLATFORM == "java"
+ if `which mvn` == ''
+ raise ArgumentError, "maven needs to be installed"
+ end
+ task :clean do
+ system("mvn --batch-mode clean")
+ end
+
+ task :compile do
+ system("mvn --batch-mode package")
+ end
+else
+ Rake::ExtensionTask.new("protobuf_c", spec) do |ext|
+ ext.ext_dir = "ext/google/protobuf_c"
+ ext.lib_dir = "lib/google"
+ ext.cross_compile = true
+ ext.cross_platform = [
+ 'x86-mingw32', 'x64-mingw32',
+ 'x86_64-linux', 'x86-linux',
+ 'universal-darwin'
+ ]
+ end
+
+ task 'gem:windows' do
+ require 'rake_compiler_dock'
+ RakeCompilerDock.sh "bundle && IN_DOCKER=true rake cross native gem RUBY_CC_VERSION=2.4.0:2.3.0:2.2.2:2.1.5:2.0.0"
+ end
+
+ if RUBY_PLATFORM =~ /darwin/
+ task 'gem:native' do
+ system "rake genproto"
+ system "rake cross native gem RUBY_CC_VERSION=2.4.0:2.3.0:2.2.2:2.1.5:2.0.0"
+ end
+ else
+ task 'gem:native' => [:genproto, 'gem:windows']
+ end
+end
+
+
+# Proto for tests.
+genproto_output << "tests/generated_code.rb"
+genproto_output << "tests/test_import.rb"
+file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task|
+ sh "../src/protoc --ruby_out=. tests/generated_code.proto"
+end
+
+file "tests/test_import.rb" => "tests/test_import.proto" do |file_task|
+ sh "../src/protoc --ruby_out=. tests/test_import.proto"
+end
+
+task :genproto => genproto_output
+
+task :clean do
+ sh "rm -f #{genproto_output.join(' ')}"
+end
+
+Gem::PackageTask.new(spec) do |pkg|
+end
+
+Rake::TestTask.new(:test => :build) do |t|
+ t.test_files = FileList["tests/*.rb"]
+end
+
+task :build => [:clean, :compile, :genproto]
+task :default => [:build]
+
+# vim:sw=2:et
diff --git a/third_party/protobuf/ruby/compatibility_tests/v3.0.0/README.md b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/README.md
new file mode 100644
index 0000000000..eb341228cf
--- /dev/null
+++ b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/README.md
@@ -0,0 +1,5 @@
+# Protobuf Ruby Compatibility Tests
+
+This drectory contains a snapshot of protobuf ruby 3.0.0 unittest code and
+test scripts used to verifies whether the latest version of protobuf is
+still compatible with 3.0.0 generated code.
diff --git a/third_party/protobuf/ruby/compatibility_tests/v3.0.0/Rakefile b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/Rakefile
new file mode 100644
index 0000000000..19a4ba1280
--- /dev/null
+++ b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/Rakefile
@@ -0,0 +1,25 @@
+require "rake/testtask"
+
+# Proto for tests.
+genproto_output = []
+genproto_output << "tests/generated_code.rb"
+genproto_output << "tests/test_import.rb"
+file "tests/generated_code.rb" => "tests/generated_code.proto" do |file_task|
+ sh "./protoc --ruby_out=. tests/generated_code.proto"
+end
+
+file "tests/test_import.rb" => "tests/test_import.proto" do |file_task|
+ sh "./protoc --ruby_out=. tests/test_import.proto"
+end
+
+task :genproto => genproto_output
+
+task :clean do
+ sh "rm -f #{genproto_output.join(' ')}"
+end
+
+Rake::TestTask.new(:test => :genproto) do |t|
+ t.test_files = FileList["tests/*.rb"]
+end
+
+task :default => [:test]
diff --git a/third_party/protobuf/ruby/compatibility_tests/v3.0.0/test.sh b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/test.sh
new file mode 100755
index 0000000000..996dc020c2
--- /dev/null
+++ b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/test.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+set -ex
+
+# Change to the script's directory
+cd $(dirname $0)
+
+# Download 3.0.0 version of protoc
+PROTOC_BINARY_NAME="protoc-3.0.0-linux-x86_64.exe"
+if [ `uname` = "Darwin" ]; then
+ PROTOC_BINARY_NAME="protoc-3.0.0-osx-x86_64.exe"
+fi
+wget http://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0/${PROTOC_BINARY_NAME} -O protoc
+chmod +x protoc
+
+# Run tests
+rake test
diff --git a/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/basic.rb b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/basic.rb
new file mode 100644
index 0000000000..f81e456c3f
--- /dev/null
+++ b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/basic.rb
@@ -0,0 +1,1182 @@
+#!/usr/bin/ruby
+
+require 'google/protobuf'
+require 'test/unit'
+
+# ------------- generated code --------------
+
+module BasicTest
+ pool = Google::Protobuf::DescriptorPool.new
+ pool.build do
+ add_message "Foo" do
+ optional :bar, :message, 1, "Bar"
+ repeated :baz, :message, 2, "Baz"
+ end
+
+ add_message "Bar" do
+ optional :msg, :string, 1
+ end
+
+ add_message "Baz" do
+ optional :msg, :string, 1
+ end
+
+ add_message "TestMessage" do
+ optional :optional_int32, :int32, 1
+ optional :optional_int64, :int64, 2
+ optional :optional_uint32, :uint32, 3
+ optional :optional_uint64, :uint64, 4
+ optional :optional_bool, :bool, 5
+ optional :optional_float, :float, 6
+ optional :optional_double, :double, 7
+ optional :optional_string, :string, 8
+ optional :optional_bytes, :bytes, 9
+ optional :optional_msg, :message, 10, "TestMessage2"
+ optional :optional_enum, :enum, 11, "TestEnum"
+
+ repeated :repeated_int32, :int32, 12
+ repeated :repeated_int64, :int64, 13
+ repeated :repeated_uint32, :uint32, 14
+ repeated :repeated_uint64, :uint64, 15
+ repeated :repeated_bool, :bool, 16
+ repeated :repeated_float, :float, 17
+ repeated :repeated_double, :double, 18
+ repeated :repeated_string, :string, 19
+ repeated :repeated_bytes, :bytes, 20
+ repeated :repeated_msg, :message, 21, "TestMessage2"
+ repeated :repeated_enum, :enum, 22, "TestEnum"
+ end
+ add_message "TestMessage2" do
+ optional :foo, :int32, 1
+ end
+
+ add_message "Recursive1" do
+ optional :foo, :message, 1, "Recursive2"
+ end
+ add_message "Recursive2" do
+ optional :foo, :message, 1, "Recursive1"
+ end
+
+ add_enum "TestEnum" do
+ value :Default, 0
+ value :A, 1
+ value :B, 2
+ value :C, 3
+ end
+
+ add_message "BadFieldNames" do
+ optional :dup, :int32, 1
+ optional :class, :int32, 2
+ optional :"a.b", :int32, 3
+ end
+
+ add_message "MapMessage" do
+ map :map_string_int32, :string, :int32, 1
+ map :map_string_msg, :string, :message, 2, "TestMessage2"
+ end
+ add_message "MapMessageWireEquiv" do
+ repeated :map_string_int32, :message, 1, "MapMessageWireEquiv_entry1"
+ repeated :map_string_msg, :message, 2, "MapMessageWireEquiv_entry2"
+ end
+ add_message "MapMessageWireEquiv_entry1" do
+ optional :key, :string, 1
+ optional :value, :int32, 2
+ end
+ add_message "MapMessageWireEquiv_entry2" do
+ optional :key, :string, 1
+ optional :value, :message, 2, "TestMessage2"
+ end
+
+ add_message "OneofMessage" do
+ oneof :my_oneof do
+ optional :a, :string, 1
+ optional :b, :int32, 2
+ optional :c, :message, 3, "TestMessage2"
+ optional :d, :enum, 4, "TestEnum"
+ end
+ end
+ end
+
+ Foo = pool.lookup("Foo").msgclass
+ Bar = pool.lookup("Bar").msgclass
+ Baz = pool.lookup("Baz").msgclass
+ TestMessage = pool.lookup("TestMessage").msgclass
+ TestMessage2 = pool.lookup("TestMessage2").msgclass
+ Recursive1 = pool.lookup("Recursive1").msgclass
+ Recursive2 = pool.lookup("Recursive2").msgclass
+ TestEnum = pool.lookup("TestEnum").enummodule
+ BadFieldNames = pool.lookup("BadFieldNames").msgclass
+ MapMessage = pool.lookup("MapMessage").msgclass
+ MapMessageWireEquiv = pool.lookup("MapMessageWireEquiv").msgclass
+ MapMessageWireEquiv_entry1 =
+ pool.lookup("MapMessageWireEquiv_entry1").msgclass
+ MapMessageWireEquiv_entry2 =
+ pool.lookup("MapMessageWireEquiv_entry2").msgclass
+ OneofMessage = pool.lookup("OneofMessage").msgclass
+
+# ------------ test cases ---------------
+
+ class MessageContainerTest < Test::Unit::TestCase
+
+ def test_defaults
+ m = TestMessage.new
+ assert m.optional_int32 == 0
+ assert m.optional_int64 == 0
+ assert m.optional_uint32 == 0
+ assert m.optional_uint64 == 0
+ assert m.optional_bool == false
+ assert m.optional_float == 0.0
+ assert m.optional_double == 0.0
+ assert m.optional_string == ""
+ assert m.optional_bytes == ""
+ assert m.optional_msg == nil
+ assert m.optional_enum == :Default
+ end
+
+ def test_setters
+ m = TestMessage.new
+ m.optional_int32 = -42
+ assert m.optional_int32 == -42
+ m.optional_int64 = -0x1_0000_0000
+ assert m.optional_int64 == -0x1_0000_0000
+ m.optional_uint32 = 0x9000_0000
+ assert m.optional_uint32 == 0x9000_0000
+ m.optional_uint64 = 0x9000_0000_0000_0000
+ assert m.optional_uint64 == 0x9000_0000_0000_0000
+ m.optional_bool = true
+ assert m.optional_bool == true
+ m.optional_float = 0.5
+ assert m.optional_float == 0.5
+ m.optional_double = 0.5
+ m.optional_string = "hello"
+ assert m.optional_string == "hello"
+ m.optional_bytes = "world".encode!('ASCII-8BIT')
+ assert m.optional_bytes == "world"
+ m.optional_msg = TestMessage2.new(:foo => 42)
+ assert m.optional_msg == TestMessage2.new(:foo => 42)
+ m.optional_msg = nil
+ assert m.optional_msg == nil
+ end
+
+ def test_ctor_args
+ m = TestMessage.new(:optional_int32 => -42,
+ :optional_msg => TestMessage2.new,
+ :optional_enum => :C,
+ :repeated_string => ["hello", "there", "world"])
+ assert m.optional_int32 == -42
+ assert m.optional_msg.class == TestMessage2
+ assert m.repeated_string.length == 3
+ assert m.optional_enum == :C
+ assert m.repeated_string[0] == "hello"
+ assert m.repeated_string[1] == "there"
+ assert m.repeated_string[2] == "world"
+ end
+
+ def test_inspect
+ m = TestMessage.new(:optional_int32 => -42,
+ :optional_enum => :A,
+ :optional_msg => TestMessage2.new,
+ :repeated_string => ["hello", "there", "world"])
+ expected = '<BasicTest::TestMessage: optional_int32: -42, optional_int64: 0, optional_uint32: 0, optional_uint64: 0, optional_bool: false, optional_float: 0.0, optional_double: 0.0, optional_string: "", optional_bytes: "", optional_msg: <BasicTest::TestMessage2: foo: 0>, optional_enum: :A, repeated_int32: [], repeated_int64: [], repeated_uint32: [], repeated_uint64: [], repeated_bool: [], repeated_float: [], repeated_double: [], repeated_string: ["hello", "there", "world"], repeated_bytes: [], repeated_msg: [], repeated_enum: []>'
+ assert_equal expected, m.inspect
+ end
+
+ def test_hash
+ m1 = TestMessage.new(:optional_int32 => 42)
+ m2 = TestMessage.new(:optional_int32 => 102)
+ assert m1.hash != 0
+ assert m2.hash != 0
+ # relying on the randomness here -- if hash function changes and we are
+ # unlucky enough to get a collision, then change the values above.
+ assert m1.hash != m2.hash
+ end
+
+ def test_unknown_field_errors
+ e = assert_raise NoMethodError do
+ TestMessage.new.hello
+ end
+ assert_match(/hello/, e.message)
+
+ e = assert_raise NoMethodError do
+ TestMessage.new.hello = "world"
+ end
+ assert_match(/hello/, e.message)
+ end
+
+ def test_initialization_map_errors
+ e = assert_raise ArgumentError do
+ TestMessage.new(:hello => "world")
+ end
+ assert_match(/hello/, e.message)
+
+ e = assert_raise ArgumentError do
+ MapMessage.new(:map_string_int32 => "hello")
+ end
+ assert_equal e.message, "Expected Hash object as initializer value for map field 'map_string_int32'."
+
+ e = assert_raise ArgumentError do
+ TestMessage.new(:repeated_uint32 => "hello")
+ end
+ assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32'."
+ end
+
+ def test_type_errors
+ m = TestMessage.new
+ assert_raise TypeError do
+ m.optional_int32 = "hello"
+ end
+ assert_raise TypeError do
+ m.optional_string = 42
+ end
+ assert_raise TypeError do
+ m.optional_string = nil
+ end
+ assert_raise TypeError do
+ m.optional_bool = 42
+ end
+ assert_raise TypeError do
+ m.optional_msg = TestMessage.new # expects TestMessage2
+ end
+
+ assert_raise TypeError do
+ m.repeated_int32 = [] # needs RepeatedField
+ end
+
+ assert_raise TypeError do
+ m.repeated_int32.push "hello"
+ end
+
+ assert_raise TypeError do
+ m.repeated_msg.push TestMessage.new
+ end
+ end
+
+ def test_string_encoding
+ m = TestMessage.new
+
+ # Assigning a normal (ASCII or UTF8) string to a bytes field, or
+ # ASCII-8BIT to a string field will convert to the proper encoding.
+ m.optional_bytes = "Test string ASCII".encode!('ASCII')
+ assert m.optional_bytes.frozen?
+ assert_equal Encoding::ASCII_8BIT, m.optional_bytes.encoding
+ assert_equal "Test string ASCII", m.optional_bytes
+
+ assert_raise Encoding::UndefinedConversionError do
+ m.optional_bytes = "Test string UTF-8 \u0100".encode!('UTF-8')
+ end
+
+ assert_raise Encoding::UndefinedConversionError do
+ m.optional_string = ["FFFF"].pack('H*')
+ end
+
+ # "Ordinary" use case.
+ m.optional_bytes = ["FFFF"].pack('H*')
+ m.optional_string = "\u0100"
+
+ # strings are immutable so we can't do this, but serialize should catch it.
+ m.optional_string = "asdf".encode!('UTF-8')
+ assert_raise RuntimeError do
+ m.optional_string.encode!('ASCII-8BIT')
+ end
+ end
+
+ def test_rptfield_int32
+ l = Google::Protobuf::RepeatedField.new(:int32)
+ assert l.count == 0
+ l = Google::Protobuf::RepeatedField.new(:int32, [1, 2, 3])
+ assert l.count == 3
+ assert_equal [1, 2, 3], l
+ assert_equal l, [1, 2, 3]
+ l.push 4
+ assert l == [1, 2, 3, 4]
+ dst_list = []
+ l.each { |val| dst_list.push val }
+ assert dst_list == [1, 2, 3, 4]
+ assert l.to_a == [1, 2, 3, 4]
+ assert l[0] == 1
+ assert l[3] == 4
+ l[0] = 5
+ assert l == [5, 2, 3, 4]
+
+ l2 = l.dup
+ assert l == l2
+ assert l.object_id != l2.object_id
+ l2.push 6
+ assert l.count == 4
+ assert l2.count == 5
+
+ assert l.inspect == '[5, 2, 3, 4]'
+
+ l.concat([7, 8, 9])
+ assert l == [5, 2, 3, 4, 7, 8, 9]
+ assert l.pop == 9
+ assert l == [5, 2, 3, 4, 7, 8]
+
+ assert_raise TypeError do
+ m = TestMessage.new
+ l.push m
+ end
+
+ m = TestMessage.new
+ m.repeated_int32 = l
+ assert m.repeated_int32 == [5, 2, 3, 4, 7, 8]
+ assert m.repeated_int32.object_id == l.object_id
+ l.push 42
+ assert m.repeated_int32.pop == 42
+
+ l3 = l + l.dup
+ assert l3.count == l.count * 2
+ l.count.times do |i|
+ assert l3[i] == l[i]
+ assert l3[l.count + i] == l[i]
+ end
+
+ l.clear
+ assert l.count == 0
+ l += [1, 2, 3, 4]
+ l.replace([5, 6, 7, 8])
+ assert l == [5, 6, 7, 8]
+
+ l4 = Google::Protobuf::RepeatedField.new(:int32)
+ l4[5] = 42
+ assert l4 == [0, 0, 0, 0, 0, 42]
+
+ l4 << 100
+ assert l4 == [0, 0, 0, 0, 0, 42, 100]
+ l4 << 101 << 102
+ assert l4 == [0, 0, 0, 0, 0, 42, 100, 101, 102]
+ end
+
+ def test_parent_rptfield
+ #make sure we set the RepeatedField and can add to it
+ m = TestMessage.new
+ assert m.repeated_string == []
+ m.repeated_string << 'ok'
+ m.repeated_string.push('ok2')
+ assert m.repeated_string == ['ok', 'ok2']
+ m.repeated_string += ['ok3']
+ assert m.repeated_string == ['ok', 'ok2', 'ok3']
+ end
+
+ def test_rptfield_msg
+ l = Google::Protobuf::RepeatedField.new(:message, TestMessage)
+ l.push TestMessage.new
+ assert l.count == 1
+ assert_raise TypeError do
+ l.push TestMessage2.new
+ end
+ assert_raise TypeError do
+ l.push 42
+ end
+
+ l2 = l.dup
+ assert l2[0] == l[0]
+ assert l2[0].object_id == l[0].object_id
+
+ l2 = Google::Protobuf.deep_copy(l)
+ assert l2[0] == l[0]
+ assert l2[0].object_id != l[0].object_id
+
+ l3 = l + l2
+ assert l3.count == 2
+ assert l3[0] == l[0]
+ assert l3[1] == l2[0]
+ l3[0].optional_int32 = 1000
+ assert l[0].optional_int32 == 1000
+
+ new_msg = TestMessage.new(:optional_int32 => 200)
+ l4 = l + [new_msg]
+ assert l4.count == 2
+ new_msg.optional_int32 = 1000
+ assert l4[1].optional_int32 == 1000
+ end
+
+ def test_rptfield_enum
+ l = Google::Protobuf::RepeatedField.new(:enum, TestEnum)
+ l.push :A
+ l.push :B
+ l.push :C
+ assert l.count == 3
+ assert_raise RangeError do
+ l.push :D
+ end
+ assert l[0] == :A
+
+ l.push 4
+ assert l[3] == 4
+ end
+
+ def test_rptfield_initialize
+ assert_raise ArgumentError do
+ l = Google::Protobuf::RepeatedField.new
+ end
+ assert_raise ArgumentError do
+ l = Google::Protobuf::RepeatedField.new(:message)
+ end
+ assert_raise ArgumentError do
+ l = Google::Protobuf::RepeatedField.new([1, 2, 3])
+ end
+ assert_raise ArgumentError do
+ l = Google::Protobuf::RepeatedField.new(:message, [TestMessage2.new])
+ end
+ end
+
+ def test_rptfield_array_ducktyping
+ l = Google::Protobuf::RepeatedField.new(:int32)
+ length_methods = %w(count length size)
+ length_methods.each do |lm|
+ assert l.send(lm) == 0
+ end
+ # out of bounds returns a nil
+ assert l[0] == nil
+ assert l[1] == nil
+ assert l[-1] == nil
+ l.push 4
+ length_methods.each do |lm|
+ assert l.send(lm) == 1
+ end
+ assert l[0] == 4
+ assert l[1] == nil
+ assert l[-1] == 4
+ assert l[-2] == nil
+
+ l.push 2
+ length_methods.each do |lm|
+ assert l.send(lm) == 2
+ end
+ assert l[0] == 4
+ assert l[1] == 2
+ assert l[2] == nil
+ assert l[-1] == 2
+ assert l[-2] == 4
+ assert l[-3] == nil
+
+ #adding out of scope will backfill with empty objects
+ end
+
+ def test_map_basic
+ # allowed key types:
+ # :int32, :int64, :uint32, :uint64, :bool, :string, :bytes.
+
+ m = Google::Protobuf::Map.new(:string, :int32)
+ m["asdf"] = 1
+ assert m["asdf"] == 1
+ m["jkl;"] = 42
+ assert m == { "jkl;" => 42, "asdf" => 1 }
+ assert m.has_key?("asdf")
+ assert !m.has_key?("qwerty")
+ assert m.length == 2
+
+ m2 = m.dup
+ assert m == m2
+ assert m.hash != 0
+ assert m.hash == m2.hash
+
+ collected = {}
+ m.each { |k,v| collected[v] = k }
+ assert collected == { 42 => "jkl;", 1 => "asdf" }
+
+ assert m.delete("asdf") == 1
+ assert !m.has_key?("asdf")
+ assert m["asdf"] == nil
+ assert !m.has_key?("asdf")
+
+ # We only assert on inspect value when there is one map entry because the
+ # order in which elements appear is unspecified (depends on the internal
+ # hash function). We don't want a brittle test.
+ assert m.inspect == "{\"jkl;\"=>42}"
+
+ assert m.keys == ["jkl;"]
+ assert m.values == [42]
+
+ m.clear
+ assert m.length == 0
+ assert m == {}
+
+ assert_raise TypeError do
+ m[1] = 1
+ end
+ assert_raise RangeError do
+ m["asdf"] = 0x1_0000_0000
+ end
+ end
+
+ def test_map_ctor
+ m = Google::Protobuf::Map.new(:string, :int32,
+ {"a" => 1, "b" => 2, "c" => 3})
+ assert m == {"a" => 1, "c" => 3, "b" => 2}
+ end
+
+ def test_map_keytypes
+ m = Google::Protobuf::Map.new(:int32, :int32)
+ m[1] = 42
+ m[-1] = 42
+ assert_raise RangeError do
+ m[0x8000_0000] = 1
+ end
+ assert_raise TypeError do
+ m["asdf"] = 1
+ end
+
+ m = Google::Protobuf::Map.new(:int64, :int32)
+ m[0x1000_0000_0000_0000] = 1
+ assert_raise RangeError do
+ m[0x1_0000_0000_0000_0000] = 1
+ end
+ assert_raise TypeError do
+ m["asdf"] = 1
+ end
+
+ m = Google::Protobuf::Map.new(:uint32, :int32)
+ m[0x8000_0000] = 1
+ assert_raise RangeError do
+ m[0x1_0000_0000] = 1
+ end
+ assert_raise RangeError do
+ m[-1] = 1
+ end
+
+ m = Google::Protobuf::Map.new(:uint64, :int32)
+ m[0x8000_0000_0000_0000] = 1
+ assert_raise RangeError do
+ m[0x1_0000_0000_0000_0000] = 1
+ end
+ assert_raise RangeError do
+ m[-1] = 1
+ end
+
+ m = Google::Protobuf::Map.new(:bool, :int32)
+ m[true] = 1
+ m[false] = 2
+ assert_raise TypeError do
+ m[1] = 1
+ end
+ assert_raise TypeError do
+ m["asdf"] = 1
+ end
+
+ m = Google::Protobuf::Map.new(:string, :int32)
+ m["asdf"] = 1
+ assert_raise TypeError do
+ m[1] = 1
+ end
+ assert_raise Encoding::UndefinedConversionError do
+ bytestring = ["FFFF"].pack("H*")
+ m[bytestring] = 1
+ end
+
+ m = Google::Protobuf::Map.new(:bytes, :int32)
+ bytestring = ["FFFF"].pack("H*")
+ m[bytestring] = 1
+ # Allowed -- we will automatically convert to ASCII-8BIT.
+ m["asdf"] = 1
+ assert_raise TypeError do
+ m[1] = 1
+ end
+ end
+
+ def test_map_msg_enum_valuetypes
+ m = Google::Protobuf::Map.new(:string, :message, TestMessage)
+ m["asdf"] = TestMessage.new
+ assert_raise TypeError do
+ m["jkl;"] = TestMessage2.new
+ end
+
+ m = Google::Protobuf::Map.new(
+ :string, :message, TestMessage,
+ { "a" => TestMessage.new(:optional_int32 => 42),
+ "b" => TestMessage.new(:optional_int32 => 84) })
+ assert m.length == 2
+ assert m.values.map{|msg| msg.optional_int32}.sort == [42, 84]
+
+ m = Google::Protobuf::Map.new(:string, :enum, TestEnum,
+ { "x" => :A, "y" => :B, "z" => :C })
+ assert m.length == 3
+ assert m["z"] == :C
+ m["z"] = 2
+ assert m["z"] == :B
+ m["z"] = 4
+ assert m["z"] == 4
+ assert_raise RangeError do
+ m["z"] = :Z
+ end
+ assert_raise TypeError do
+ m["z"] = "z"
+ end
+ end
+
+ def test_map_dup_deep_copy
+ m = Google::Protobuf::Map.new(
+ :string, :message, TestMessage,
+ { "a" => TestMessage.new(:optional_int32 => 42),
+ "b" => TestMessage.new(:optional_int32 => 84) })
+
+ m2 = m.dup
+ assert m == m2
+ assert m.object_id != m2.object_id
+ assert m["a"].object_id == m2["a"].object_id
+ assert m["b"].object_id == m2["b"].object_id
+
+ m2 = Google::Protobuf.deep_copy(m)
+ assert m == m2
+ assert m.object_id != m2.object_id
+ assert m["a"].object_id != m2["a"].object_id
+ assert m["b"].object_id != m2["b"].object_id
+ end
+
+ def test_map_field
+ m = MapMessage.new
+ assert m.map_string_int32 == {}
+ assert m.map_string_msg == {}
+
+ m = MapMessage.new(
+ :map_string_int32 => {"a" => 1, "b" => 2},
+ :map_string_msg => {"a" => TestMessage2.new(:foo => 1),
+ "b" => TestMessage2.new(:foo => 2)})
+ assert m.map_string_int32.keys.sort == ["a", "b"]
+ assert m.map_string_int32["a"] == 1
+ assert m.map_string_msg["b"].foo == 2
+
+ m.map_string_int32["c"] = 3
+ assert m.map_string_int32["c"] == 3
+ m.map_string_msg["c"] = TestMessage2.new(:foo => 3)
+ assert m.map_string_msg["c"] == TestMessage2.new(:foo => 3)
+ m.map_string_msg.delete("b")
+ m.map_string_msg.delete("c")
+ assert m.map_string_msg == { "a" => TestMessage2.new(:foo => 1) }
+
+ assert_raise TypeError do
+ m.map_string_msg["e"] = TestMessage.new # wrong value type
+ end
+ # ensure nothing was added by the above
+ assert m.map_string_msg == { "a" => TestMessage2.new(:foo => 1) }
+
+ m.map_string_int32 = Google::Protobuf::Map.new(:string, :int32)
+ assert_raise TypeError do
+ m.map_string_int32 = Google::Protobuf::Map.new(:string, :int64)
+ end
+ assert_raise TypeError do
+ m.map_string_int32 = {}
+ end
+
+ assert_raise TypeError do
+ m = MapMessage.new(:map_string_int32 => { 1 => "I am not a number" })
+ end
+ end
+
+ def test_map_encode_decode
+ m = MapMessage.new(
+ :map_string_int32 => {"a" => 1, "b" => 2},
+ :map_string_msg => {"a" => TestMessage2.new(:foo => 1),
+ "b" => TestMessage2.new(:foo => 2)})
+ m2 = MapMessage.decode(MapMessage.encode(m))
+ assert m == m2
+
+ m3 = MapMessageWireEquiv.decode(MapMessage.encode(m))
+ assert m3.map_string_int32.length == 2
+
+ kv = {}
+ m3.map_string_int32.map { |msg| kv[msg.key] = msg.value }
+ assert kv == {"a" => 1, "b" => 2}
+
+ kv = {}
+ m3.map_string_msg.map { |msg| kv[msg.key] = msg.value }
+ assert kv == {"a" => TestMessage2.new(:foo => 1),
+ "b" => TestMessage2.new(:foo => 2)}
+ end
+
+ def test_oneof_descriptors
+ d = OneofMessage.descriptor
+ o = d.lookup_oneof("my_oneof")
+ assert o != nil
+ assert o.class == Google::Protobuf::OneofDescriptor
+ assert o.name == "my_oneof"
+ oneof_count = 0
+ d.each_oneof{ |oneof|
+ oneof_count += 1
+ assert oneof == o
+ }
+ assert oneof_count == 1
+ assert o.count == 4
+ field_names = o.map{|f| f.name}.sort
+ assert field_names == ["a", "b", "c", "d"]
+ end
+
+ def test_oneof
+ d = OneofMessage.new
+ assert d.a == ""
+ assert d.b == 0
+ assert d.c == nil
+ assert d.d == :Default
+ assert d.my_oneof == nil
+
+ d.a = "hi"
+ assert d.a == "hi"
+ assert d.b == 0
+ assert d.c == nil
+ assert d.d == :Default
+ assert d.my_oneof == :a
+
+ d.b = 42
+ assert d.a == ""
+ assert d.b == 42
+ assert d.c == nil
+ assert d.d == :Default
+ assert d.my_oneof == :b
+
+ d.c = TestMessage2.new(:foo => 100)
+ assert d.a == ""
+ assert d.b == 0
+ assert d.c.foo == 100
+ assert d.d == :Default
+ assert d.my_oneof == :c
+
+ d.d = :C
+ assert d.a == ""
+ assert d.b == 0
+ assert d.c == nil
+ assert d.d == :C
+ assert d.my_oneof == :d
+
+ d2 = OneofMessage.decode(OneofMessage.encode(d))
+ assert d2 == d
+
+ encoded_field_a = OneofMessage.encode(OneofMessage.new(:a => "string"))
+ encoded_field_b = OneofMessage.encode(OneofMessage.new(:b => 1000))
+ encoded_field_c = OneofMessage.encode(
+ OneofMessage.new(:c => TestMessage2.new(:foo => 1)))
+ encoded_field_d = OneofMessage.encode(OneofMessage.new(:d => :B))
+
+ d3 = OneofMessage.decode(
+ encoded_field_c + encoded_field_a + encoded_field_d)
+ assert d3.a == ""
+ assert d3.b == 0
+ assert d3.c == nil
+ assert d3.d == :B
+
+ d4 = OneofMessage.decode(
+ encoded_field_c + encoded_field_a + encoded_field_d +
+ encoded_field_c)
+ assert d4.a == ""
+ assert d4.b == 0
+ assert d4.c.foo == 1
+ assert d4.d == :Default
+
+ d5 = OneofMessage.new(:a => "hello")
+ assert d5.a == "hello"
+ d5.a = nil
+ assert d5.a == ""
+ assert OneofMessage.encode(d5) == ''
+ assert d5.my_oneof == nil
+ end
+
+ def test_enum_field
+ m = TestMessage.new
+ assert m.optional_enum == :Default
+ m.optional_enum = :A
+ assert m.optional_enum == :A
+ assert_raise RangeError do
+ m.optional_enum = :ASDF
+ end
+ m.optional_enum = 1
+ assert m.optional_enum == :A
+ m.optional_enum = 100
+ assert m.optional_enum == 100
+ end
+
+ def test_dup
+ m = TestMessage.new
+ m.optional_string = "hello"
+ m.optional_int32 = 42
+ tm1 = TestMessage2.new(:foo => 100)
+ tm2 = TestMessage2.new(:foo => 200)
+ m.repeated_msg.push tm1
+ assert m.repeated_msg[-1] == tm1
+ m.repeated_msg.push tm2
+ assert m.repeated_msg[-1] == tm2
+ m2 = m.dup
+ assert m == m2
+ m.optional_int32 += 1
+ assert m != m2
+ assert m.repeated_msg[0] == m2.repeated_msg[0]
+ assert m.repeated_msg[0].object_id == m2.repeated_msg[0].object_id
+ end
+
+ def test_deep_copy
+ m = TestMessage.new(:optional_int32 => 42,
+ :repeated_msg => [TestMessage2.new(:foo => 100)])
+ m2 = Google::Protobuf.deep_copy(m)
+ assert m == m2
+ assert m.repeated_msg == m2.repeated_msg
+ assert m.repeated_msg.object_id != m2.repeated_msg.object_id
+ assert m.repeated_msg[0].object_id != m2.repeated_msg[0].object_id
+ end
+
+ def test_eq
+ m = TestMessage.new(:optional_int32 => 42,
+ :repeated_int32 => [1, 2, 3])
+ m2 = TestMessage.new(:optional_int32 => 43,
+ :repeated_int32 => [1, 2, 3])
+ assert m != m2
+ end
+
+ def test_enum_lookup
+ assert TestEnum::A == 1
+ assert TestEnum::B == 2
+ assert TestEnum::C == 3
+
+ assert TestEnum::lookup(1) == :A
+ assert TestEnum::lookup(2) == :B
+ assert TestEnum::lookup(3) == :C
+
+ assert TestEnum::resolve(:A) == 1
+ assert TestEnum::resolve(:B) == 2
+ assert TestEnum::resolve(:C) == 3
+ end
+
+ def test_parse_serialize
+ m = TestMessage.new(:optional_int32 => 42,
+ :optional_string => "hello world",
+ :optional_enum => :B,
+ :repeated_string => ["a", "b", "c"],
+ :repeated_int32 => [42, 43, 44],
+ :repeated_enum => [:A, :B, :C, 100],
+ :repeated_msg => [TestMessage2.new(:foo => 1),
+ TestMessage2.new(:foo => 2)])
+ data = TestMessage.encode m
+ m2 = TestMessage.decode data
+ assert m == m2
+
+ data = Google::Protobuf.encode m
+ m2 = Google::Protobuf.decode(TestMessage, data)
+ assert m == m2
+ end
+
+ def test_encode_decode_helpers
+ m = TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2'])
+ assert_equal 'foo', m.optional_string
+ assert_equal ['bar1', 'bar2'], m.repeated_string
+
+ json = m.to_json
+ m2 = TestMessage.decode_json(json)
+ assert_equal 'foo', m2.optional_string
+ assert_equal ['bar1', 'bar2'], m2.repeated_string
+ if RUBY_PLATFORM != "java"
+ assert m2.optional_string.frozen?
+ assert m2.repeated_string[0].frozen?
+ end
+
+ proto = m.to_proto
+ m2 = TestMessage.decode(proto)
+ assert_equal 'foo', m2.optional_string
+ assert_equal ['bar1', 'bar2'], m2.repeated_string
+ end
+
+ def test_protobuf_encode_decode_helpers
+ m = TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2'])
+ encoded_msg = Google::Protobuf.encode(m)
+ assert_equal m.to_proto, encoded_msg
+
+ decoded_msg = Google::Protobuf.decode(TestMessage, encoded_msg)
+ assert_equal TestMessage.decode(m.to_proto), decoded_msg
+ end
+
+ def test_protobuf_encode_decode_json_helpers
+ m = TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2'])
+ encoded_msg = Google::Protobuf.encode_json(m)
+ assert_equal m.to_json, encoded_msg
+
+ decoded_msg = Google::Protobuf.decode_json(TestMessage, encoded_msg)
+ assert_equal TestMessage.decode_json(m.to_json), decoded_msg
+ end
+
+ def test_to_h
+ m = TestMessage.new(:optional_bool => true, :optional_double => -10.100001, :optional_string => 'foo', :repeated_string => ['bar1', 'bar2'])
+ expected_result = {
+ :optional_bool=>true,
+ :optional_bytes=>"",
+ :optional_double=>-10.100001,
+ :optional_enum=>:Default,
+ :optional_float=>0.0,
+ :optional_int32=>0,
+ :optional_int64=>0,
+ :optional_msg=>nil,
+ :optional_string=>"foo",
+ :optional_uint32=>0,
+ :optional_uint64=>0,
+ :repeated_bool=>[],
+ :repeated_bytes=>[],
+ :repeated_double=>[],
+ :repeated_enum=>[],
+ :repeated_float=>[],
+ :repeated_int32=>[],
+ :repeated_int64=>[],
+ :repeated_msg=>[],
+ :repeated_string=>["bar1", "bar2"],
+ :repeated_uint32=>[],
+ :repeated_uint64=>[]
+ }
+ assert_equal expected_result, m.to_h
+ end
+
+
+ def test_def_errors
+ s = Google::Protobuf::DescriptorPool.new
+ assert_raise TypeError do
+ s.build do
+ # enum with no default (integer value 0)
+ add_enum "MyEnum" do
+ value :A, 1
+ end
+ end
+ end
+ assert_raise TypeError do
+ s.build do
+ # message with required field (unsupported in proto3)
+ add_message "MyMessage" do
+ required :foo, :int32, 1
+ end
+ end
+ end
+ end
+
+ def test_corecursive
+ # just be sure that we can instantiate types with corecursive field-type
+ # references.
+ m = Recursive1.new(:foo => Recursive2.new(:foo => Recursive1.new))
+ assert Recursive1.descriptor.lookup("foo").subtype ==
+ Recursive2.descriptor
+ assert Recursive2.descriptor.lookup("foo").subtype ==
+ Recursive1.descriptor
+
+ serialized = Recursive1.encode(m)
+ m2 = Recursive1.decode(serialized)
+ assert m == m2
+ end
+
+ def test_serialize_cycle
+ m = Recursive1.new(:foo => Recursive2.new)
+ m.foo.foo = m
+ assert_raise RuntimeError do
+ serialized = Recursive1.encode(m)
+ end
+ end
+
+ def test_bad_field_names
+ m = BadFieldNames.new(:dup => 1, :class => 2)
+ m2 = m.dup
+ assert m == m2
+ assert m['dup'] == 1
+ assert m['class'] == 2
+ m['dup'] = 3
+ assert m['dup'] == 3
+ m['a.b'] = 4
+ assert m['a.b'] == 4
+ end
+
+ def test_int_ranges
+ m = TestMessage.new
+
+ m.optional_int32 = 0
+ m.optional_int32 = -0x8000_0000
+ m.optional_int32 = +0x7fff_ffff
+ m.optional_int32 = 1.0
+ m.optional_int32 = -1.0
+ m.optional_int32 = 2e9
+ assert_raise RangeError do
+ m.optional_int32 = -0x8000_0001
+ end
+ assert_raise RangeError do
+ m.optional_int32 = +0x8000_0000
+ end
+ assert_raise RangeError do
+ m.optional_int32 = +0x1000_0000_0000_0000_0000_0000 # force Bignum
+ end
+ assert_raise RangeError do
+ m.optional_int32 = 1e12
+ end
+ assert_raise RangeError do
+ m.optional_int32 = 1.5
+ end
+
+ m.optional_uint32 = 0
+ m.optional_uint32 = +0xffff_ffff
+ m.optional_uint32 = 1.0
+ m.optional_uint32 = 4e9
+ assert_raise RangeError do
+ m.optional_uint32 = -1
+ end
+ assert_raise RangeError do
+ m.optional_uint32 = -1.5
+ end
+ assert_raise RangeError do
+ m.optional_uint32 = -1.5e12
+ end
+ assert_raise RangeError do
+ m.optional_uint32 = -0x1000_0000_0000_0000
+ end
+ assert_raise RangeError do
+ m.optional_uint32 = +0x1_0000_0000
+ end
+ assert_raise RangeError do
+ m.optional_uint32 = +0x1000_0000_0000_0000_0000_0000 # force Bignum
+ end
+ assert_raise RangeError do
+ m.optional_uint32 = 1e12
+ end
+ assert_raise RangeError do
+ m.optional_uint32 = 1.5
+ end
+
+ m.optional_int64 = 0
+ m.optional_int64 = -0x8000_0000_0000_0000
+ m.optional_int64 = +0x7fff_ffff_ffff_ffff
+ m.optional_int64 = 1.0
+ m.optional_int64 = -1.0
+ m.optional_int64 = 8e18
+ m.optional_int64 = -8e18
+ assert_raise RangeError do
+ m.optional_int64 = -0x8000_0000_0000_0001
+ end
+ assert_raise RangeError do
+ m.optional_int64 = +0x8000_0000_0000_0000
+ end
+ assert_raise RangeError do
+ m.optional_int64 = +0x1000_0000_0000_0000_0000_0000 # force Bignum
+ end
+ assert_raise RangeError do
+ m.optional_int64 = 1e50
+ end
+ assert_raise RangeError do
+ m.optional_int64 = 1.5
+ end
+
+ m.optional_uint64 = 0
+ m.optional_uint64 = +0xffff_ffff_ffff_ffff
+ m.optional_uint64 = 1.0
+ m.optional_uint64 = 16e18
+ assert_raise RangeError do
+ m.optional_uint64 = -1
+ end
+ assert_raise RangeError do
+ m.optional_uint64 = -1.5
+ end
+ assert_raise RangeError do
+ m.optional_uint64 = -1.5e12
+ end
+ assert_raise RangeError do
+ m.optional_uint64 = -0x1_0000_0000_0000_0000
+ end
+ assert_raise RangeError do
+ m.optional_uint64 = +0x1_0000_0000_0000_0000
+ end
+ assert_raise RangeError do
+ m.optional_uint64 = +0x1000_0000_0000_0000_0000_0000 # force Bignum
+ end
+ assert_raise RangeError do
+ m.optional_uint64 = 1e50
+ end
+ assert_raise RangeError do
+ m.optional_uint64 = 1.5
+ end
+ end
+
+ def test_stress_test
+ m = TestMessage.new
+ m.optional_int32 = 42
+ m.optional_int64 = 0x100000000
+ m.optional_string = "hello world"
+ 10.times do m.repeated_msg.push TestMessage2.new(:foo => 42) end
+ 10.times do m.repeated_string.push "hello world" end
+
+ data = TestMessage.encode(m)
+
+ l = 0
+ 10_000.times do
+ m = TestMessage.decode(data)
+ data_new = TestMessage.encode(m)
+ assert data_new == data
+ data = data_new
+ end
+ end
+
+ def test_reflection
+ m = TestMessage.new(:optional_int32 => 1234)
+ msgdef = m.class.descriptor
+ assert msgdef.class == Google::Protobuf::Descriptor
+ assert msgdef.any? {|field| field.name == "optional_int32"}
+ optional_int32 = msgdef.lookup "optional_int32"
+ assert optional_int32.class == Google::Protobuf::FieldDescriptor
+ assert optional_int32 != nil
+ assert optional_int32.name == "optional_int32"
+ assert optional_int32.type == :int32
+ optional_int32.set(m, 5678)
+ assert m.optional_int32 == 5678
+ m.optional_int32 = 1000
+ assert optional_int32.get(m) == 1000
+
+ optional_msg = msgdef.lookup "optional_msg"
+ assert optional_msg.subtype == TestMessage2.descriptor
+
+ optional_msg.set(m, optional_msg.subtype.msgclass.new)
+
+ assert msgdef.msgclass == TestMessage
+
+ optional_enum = msgdef.lookup "optional_enum"
+ assert optional_enum.subtype == TestEnum.descriptor
+ assert optional_enum.subtype.class == Google::Protobuf::EnumDescriptor
+ optional_enum.subtype.each do |k, v|
+ # set with integer, check resolution to symbolic name
+ optional_enum.set(m, v)
+ assert optional_enum.get(m) == k
+ end
+ end
+
+ def test_json
+ # TODO: Fix JSON in JRuby version.
+ return if RUBY_PLATFORM == "java"
+ m = TestMessage.new(:optional_int32 => 1234,
+ :optional_int64 => -0x1_0000_0000,
+ :optional_uint32 => 0x8000_0000,
+ :optional_uint64 => 0xffff_ffff_ffff_ffff,
+ :optional_bool => true,
+ :optional_float => 1.0,
+ :optional_double => -1e100,
+ :optional_string => "Test string",
+ :optional_bytes => ["FFFFFFFF"].pack('H*'),
+ :optional_msg => TestMessage2.new(:foo => 42),
+ :repeated_int32 => [1, 2, 3, 4],
+ :repeated_string => ["a", "b", "c"],
+ :repeated_bool => [true, false, true, false],
+ :repeated_msg => [TestMessage2.new(:foo => 1),
+ TestMessage2.new(:foo => 2)])
+
+ json_text = TestMessage.encode_json(m)
+ m2 = TestMessage.decode_json(json_text)
+ assert m == m2
+
+ # Crash case from GitHub issue 283.
+ bar = Bar.new(msg: "bar")
+ baz1 = Baz.new(msg: "baz")
+ baz2 = Baz.new(msg: "quux")
+ Foo.encode_json(Foo.new)
+ Foo.encode_json(Foo.new(bar: bar))
+ Foo.encode_json(Foo.new(bar: bar, baz: [baz1, baz2]))
+ end
+
+ def test_json_maps
+ # TODO: Fix JSON in JRuby version.
+ return if RUBY_PLATFORM == "java"
+ m = MapMessage.new(:map_string_int32 => {"a" => 1})
+ expected = '{"mapStringInt32":{"a":1},"mapStringMsg":{}}'
+ expected_preserve = '{"map_string_int32":{"a":1},"map_string_msg":{}}'
+ assert MapMessage.encode_json(m) == expected
+
+ json = MapMessage.encode_json(m, :preserve_proto_fieldnames => true)
+ assert json == expected_preserve
+
+ m2 = MapMessage.decode_json(MapMessage.encode_json(m))
+ assert m == m2
+ end
+ end
+end
diff --git a/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/generated_code.proto b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/generated_code.proto
new file mode 100644
index 0000000000..62fd83ed89
--- /dev/null
+++ b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/generated_code.proto
@@ -0,0 +1,67 @@
+syntax = "proto3";
+
+package a.b.c;
+
+message TestMessage {
+ int32 optional_int32 = 1;
+ int64 optional_int64 = 2;
+ uint32 optional_uint32 = 3;
+ uint64 optional_uint64 = 4;
+ bool optional_bool = 5;
+ double optional_double = 6;
+ float optional_float = 7;
+ string optional_string = 8;
+ bytes optional_bytes = 9;
+ TestEnum optional_enum = 10;
+ TestMessage optional_msg = 11;
+
+ repeated int32 repeated_int32 = 21;
+ repeated int64 repeated_int64 = 22;
+ repeated uint32 repeated_uint32 = 23;
+ repeated uint64 repeated_uint64 = 24;
+ repeated bool repeated_bool = 25;
+ repeated double repeated_double = 26;
+ repeated float repeated_float = 27;
+ repeated string repeated_string = 28;
+ repeated bytes repeated_bytes = 29;
+ repeated TestEnum repeated_enum = 30;
+ repeated TestMessage repeated_msg = 31;
+
+ oneof my_oneof {
+ int32 oneof_int32 = 41;
+ int64 oneof_int64 = 42;
+ uint32 oneof_uint32 = 43;
+ uint64 oneof_uint64 = 44;
+ bool oneof_bool = 45;
+ double oneof_double = 46;
+ float oneof_float = 47;
+ string oneof_string = 48;
+ bytes oneof_bytes = 49;
+ TestEnum oneof_enum = 50;
+ TestMessage oneof_msg = 51;
+ }
+
+ map<int32, string> map_int32_string = 61;
+ map<int64, string> map_int64_string = 62;
+ map<uint32, string> map_uint32_string = 63;
+ map<uint64, string> map_uint64_string = 64;
+ map<bool, string> map_bool_string = 65;
+ map<string, string> map_string_string = 66;
+ map<string, TestMessage> map_string_msg = 67;
+ map<string, TestEnum> map_string_enum = 68;
+ map<string, int32> map_string_int32 = 69;
+ map<string, bool> map_string_bool = 70;
+
+ message NestedMessage {
+ int32 foo = 1;
+ }
+
+ NestedMessage nested_message = 80;
+}
+
+enum TestEnum {
+ Default = 0;
+ A = 1;
+ B = 2;
+ C = 3;
+}
diff --git a/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/generated_code_test.rb b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/generated_code_test.rb
new file mode 100644
index 0000000000..b92b0462d1
--- /dev/null
+++ b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/generated_code_test.rb
@@ -0,0 +1,19 @@
+#!/usr/bin/ruby
+
+# generated_code.rb is in the same directory as this test.
+$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
+
+require 'generated_code_pb'
+require 'test_import_pb'
+require 'test/unit'
+
+class GeneratedCodeTest < Test::Unit::TestCase
+ def test_generated_msg
+ # just test that we can instantiate the message. The purpose of this test
+ # is to ensure that the output of the code generator is valid Ruby and
+ # successfully creates message definitions and classes, not to test every
+ # aspect of the extension (basic.rb is for that).
+ m = A::B::C::TestMessage.new()
+ m2 = FooBar::TestImportedMessage.new()
+ end
+end
diff --git a/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb
new file mode 100644
index 0000000000..25727b7b28
--- /dev/null
+++ b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/repeated_field_test.rb
@@ -0,0 +1,640 @@
+#!/usr/bin/ruby
+
+require 'google/protobuf'
+require 'test/unit'
+
+class RepeatedFieldTest < Test::Unit::TestCase
+
+ def test_acts_like_enumerator
+ m = TestMessage.new
+ (Enumerable.instance_methods - TestMessage.new.repeated_string.methods).each do |method_name|
+ assert m.repeated_string.respond_to?(method_name) == true, "does not respond to #{method_name}"
+ end
+ end
+
+ def test_acts_like_an_array
+ m = TestMessage.new
+ arr_methods = ([].methods - TestMessage.new.repeated_string.methods)
+ # jRuby additions to the Array class that we can ignore
+ arr_methods -= [ :indices, :iter_for_each, :iter_for_each_index,
+ :iter_for_each_with_index, :dimensions, :copy_data, :copy_data_simple,
+ :nitems, :iter_for_reverse_each, :indexes]
+ arr_methods.each do |method_name|
+ assert m.repeated_string.respond_to?(method_name) == true, "does not respond to #{method_name}"
+ end
+ end
+
+ def test_first
+ m = TestMessage.new
+ repeated_field_names(TestMessage).each do |field_name|
+ assert_nil m.send(field_name).first
+ end
+ fill_test_msg(m)
+ assert_equal -10, m.repeated_int32.first
+ assert_equal -1_000_000, m.repeated_int64.first
+ assert_equal 10, m.repeated_uint32.first
+ assert_equal 1_000_000, m.repeated_uint64.first
+ assert_equal true, m.repeated_bool.first
+ assert_equal -1.01, m.repeated_float.first.round(2)
+ assert_equal -1.0000000000001, m.repeated_double.first
+ assert_equal 'foo', m.repeated_string.first
+ assert_equal "bar".encode!('ASCII-8BIT'), m.repeated_bytes.first
+ assert_equal TestMessage2.new(:foo => 1), m.repeated_msg.first
+ assert_equal :A, m.repeated_enum.first
+ end
+
+
+ def test_last
+ m = TestMessage.new
+ repeated_field_names(TestMessage).each do |field_name|
+ assert_nil m.send(field_name).first
+ end
+ fill_test_msg(m)
+ assert_equal -11, m.repeated_int32.last
+ assert_equal -1_000_001, m.repeated_int64.last
+ assert_equal 11, m.repeated_uint32.last
+ assert_equal 1_000_001, m.repeated_uint64.last
+ assert_equal false, m.repeated_bool.last
+ assert_equal -1.02, m.repeated_float.last.round(2)
+ assert_equal -1.0000000000002, m.repeated_double.last
+ assert_equal 'bar', m.repeated_string.last
+ assert_equal "foo".encode!('ASCII-8BIT'), m.repeated_bytes.last
+ assert_equal TestMessage2.new(:foo => 2), m.repeated_msg.last
+ assert_equal :B, m.repeated_enum.last
+ end
+
+
+ def test_pop
+ m = TestMessage.new
+ repeated_field_names(TestMessage).each do |field_name|
+ assert_nil m.send(field_name).pop
+ end
+ fill_test_msg(m)
+
+ assert_equal -11, m.repeated_int32.pop
+ assert_equal -10, m.repeated_int32.pop
+ assert_equal -1_000_001, m.repeated_int64.pop
+ assert_equal -1_000_000, m.repeated_int64.pop
+ assert_equal 11, m.repeated_uint32.pop
+ assert_equal 10, m.repeated_uint32.pop
+ assert_equal 1_000_001, m.repeated_uint64.pop
+ assert_equal 1_000_000, m.repeated_uint64.pop
+ assert_equal false, m.repeated_bool.pop
+ assert_equal true, m.repeated_bool.pop
+ assert_equal -1.02, m.repeated_float.pop.round(2)
+ assert_equal -1.01, m.repeated_float.pop.round(2)
+ assert_equal -1.0000000000002, m.repeated_double.pop
+ assert_equal -1.0000000000001, m.repeated_double.pop
+ assert_equal 'bar', m.repeated_string.pop
+ assert_equal 'foo', m.repeated_string.pop
+ assert_equal "foo".encode!('ASCII-8BIT'), m.repeated_bytes.pop
+ assert_equal "bar".encode!('ASCII-8BIT'), m.repeated_bytes.pop
+ assert_equal TestMessage2.new(:foo => 2), m.repeated_msg.pop
+ assert_equal TestMessage2.new(:foo => 1), m.repeated_msg.pop
+ assert_equal :B, m.repeated_enum.pop
+ assert_equal :A, m.repeated_enum.pop
+ repeated_field_names(TestMessage).each do |field_name|
+ assert_nil m.send(field_name).pop
+ end
+
+ fill_test_msg(m)
+ assert_equal ['bar', 'foo'], m.repeated_string.pop(2)
+ assert_nil m.repeated_string.pop
+ end
+
+
+ def test_each
+ m = TestMessage.new
+ 5.times{|i| m.repeated_string << 'string' }
+ count = 0
+ m.repeated_string.each do |val|
+ assert_equal 'string', val
+ count += 1
+ end
+ assert_equal 5, count
+ result = m.repeated_string.each{|val| val + '_junk'}
+ assert_equal ['string'] * 5, result
+ end
+
+
+ def test_empty?
+ m = TestMessage.new
+ assert_equal true, m.repeated_string.empty?
+ m.repeated_string << 'foo'
+ assert_equal false, m.repeated_string.empty?
+ m.repeated_string << 'bar'
+ assert_equal false, m.repeated_string.empty?
+ end
+
+ def test_array_accessor
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[1]
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[-2]
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[20]
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[1, 2]
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[0..2]
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[-1, 1]
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[10, 12]
+ end
+ end
+
+ def test_array_settor
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[1] = 'junk'
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[-2] = 'snappy'
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[3] = ''
+ end
+ # slight deviation; we are strongly typed, and nil is not allowed
+ # for string types;
+ m.repeated_string[5] = 'spacious'
+ assert_equal ["foo", "snappy", "baz", "", "", "spacious"], m.repeated_string
+
+ #make sure it sests the default types for other fields besides strings
+ %w(repeated_int32 repeated_int64 repeated_uint32 repeated_uint64).each do |field_name|
+ m.send(field_name)[3] = 10
+ assert_equal [0,0,0,10], m.send(field_name)
+ end
+ m.repeated_float[3] = 10.1
+ #wonky mri float handling
+ assert_equal [0,0,0], m.repeated_float.to_a[0..2]
+ assert_equal 10.1, m.repeated_float[3].round(1)
+ m.repeated_double[3] = 10.1
+ assert_equal [0,0,0,10.1], m.repeated_double
+ m.repeated_bool[3] = true
+ assert_equal [false, false, false, true], m.repeated_bool
+ m.repeated_bytes[3] = "bar".encode!('ASCII-8BIT')
+ assert_equal ['', '', '', "bar".encode!('ASCII-8BIT')], m.repeated_bytes
+ m.repeated_msg[3] = TestMessage2.new(:foo => 1)
+ assert_equal [nil, nil, nil, TestMessage2.new(:foo => 1)], m.repeated_msg
+ m.repeated_enum[3] = :A
+ assert_equal [:Default, :Default, :Default, :A], m.repeated_enum
+
+ # check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ # arr[20] = 'spacious'
+ # end
+ # TODO: accessor doesn't allow other ruby-like methods
+ # check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ # arr[1, 2] = 'fizz'
+ # end
+ # check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ # arr[0..2] = 'buzz'
+ # end
+ end
+
+ def test_push
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.push('fizz')
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr << 'fizz'
+ end
+ #TODO: push should support multiple
+ # check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ # arr.push('fizz', 'buzz')
+ # end
+ end
+
+ def test_clear
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.clear
+ end
+ end
+
+ def test_concat
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+ m.repeated_string.concat(['fizz', 'buzz'])
+ assert_equal %w(foo bar baz fizz buzz), m.repeated_string
+ #TODO: concat should return the orig array
+ # check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ # arr.concat(['fizz', 'buzz'])
+ # end
+ end
+
+ def test_equal
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+ assert_equal reference_arr, m.repeated_string
+ reference_arr << 'fizz'
+ assert_not_equal reference_arr, m.repeated_string
+ m.repeated_string << 'fizz'
+ assert_equal reference_arr, m.repeated_string
+ end
+
+ def test_hash
+ # just a sanity check
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+ assert m.repeated_string.hash.is_a?(Integer)
+ hash = m.repeated_string.hash
+ assert_equal hash, m.repeated_string.hash
+ m.repeated_string << 'j'
+ assert_not_equal hash, m.repeated_string.hash
+ end
+
+ def test_plus
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr + ['fizz', 'buzz']
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr += ['fizz', 'buzz']
+ end
+ end
+
+ def test_replace
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.replace(['fizz', 'buzz'])
+ end
+ end
+
+ def test_to_a
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.to_a
+ end
+ end
+
+ def test_to_ary
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.to_ary
+ end
+ end
+
+ # emulate Array behavior
+ ##########################
+
+ def test_collect!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.collect!{|x| x + "!" }
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.collect!.with_index{|x, i| x[0...i] }
+ end
+ end
+
+ def test_compact!
+ m = TestMessage.new
+ m.repeated_msg << TestMessage2.new(:foo => 1)
+ m.repeated_msg << nil
+ m.repeated_msg << TestMessage2.new(:foo => 2)
+ reference_arr = m.repeated_string.to_a
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.compact!
+ end
+ end
+
+ def test_delete
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.delete('bar')
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.delete('nope')
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.delete('nope'){'within'}
+ end
+ end
+
+ def test_delete_at
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.delete_at(2)
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.delete_at(10)
+ end
+ end
+
+ def test_fill
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.fill("x")
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.fill("z", 2, 2)
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.fill("y", 0..1)
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.fill { |i| (i*i).to_s }
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.fill(-2) { |i| (i*i*i).to_s }
+ end
+ end
+
+ def test_flatten!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.flatten!
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.flatten!(1)
+ end
+ end
+
+ def test_insert
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.insert(2, 'fizz')
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.insert(3, 'fizz', 'buzz', 'bazz')
+ end
+ end
+
+ def test_inspect
+ m = TestMessage.new
+ assert_equal '[]', m.repeated_string.inspect
+ m.repeated_string << 'foo'
+ assert_equal m.repeated_string.to_a.inspect, m.repeated_string.inspect
+ m.repeated_string << 'bar'
+ assert_equal m.repeated_string.to_a.inspect, m.repeated_string.inspect
+ end
+
+ def test_reverse!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.reverse!
+ end
+ end
+
+ def test_rotate!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.rotate!
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.rotate!(2)
+ end
+ end
+
+ def test_select!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.select! { |v| v =~ /[aeiou]/ }
+ end
+ end
+
+ def test_shift
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ # should return an element
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.shift
+ end
+ # should return an array
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.shift(2)
+ end
+ # should return nil
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.shift
+ end
+ end
+
+ def test_shuffle!
+ m = TestMessage.new
+ m.repeated_string += %w(foo bar baz)
+ orig_repeated_string = m.repeated_string.clone
+ result = m.repeated_string.shuffle!
+ assert_equal m.repeated_string, result
+ # NOTE: sometimes it doesn't change the order...
+ # assert_not_equal m.repeated_string.to_a, orig_repeated_string.to_a
+ end
+
+ def test_slice!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz bar fizz buzz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.slice!(2)
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.slice!(1,2)
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.slice!(0..1)
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.slice!(10)
+ end
+ end
+
+ def test_sort!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.sort!
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.sort! { |x,y| y <=> x }
+ end
+ end
+
+ def test_sort_by!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.sort_by!
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.sort_by!(&:hash)
+ end
+ end
+
+ def test_uniq!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.uniq!
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.uniq!{|s| s[0] }
+ end
+ end
+
+ def test_unshift
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.unshift('1')
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.unshift('a', 'b')
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.unshift('')
+ end
+ end
+
+
+ ##### HELPER METHODS
+
+ def check_self_modifying_method(repeated_field, ref_array)
+ expected_result = yield(ref_array)
+ actual_result = yield(repeated_field)
+ if expected_result.is_a?(Enumerator)
+ assert_equal expected_result.to_a, actual_result.to_a
+ else
+ assert_equal expected_result, actual_result
+ end
+ assert_equal ref_array, repeated_field
+ end
+
+
+ def repeated_field_names(klass)
+ klass.descriptor.find_all{|f| f.label == :repeated}.map(&:name)
+ end
+
+
+ def fill_test_msg(test_msg)
+ test_msg.repeated_int32 += [-10, -11]
+ test_msg.repeated_int64 += [-1_000_000, -1_000_001]
+ test_msg.repeated_uint32 += [10, 11]
+ test_msg.repeated_uint64 += [1_000_000, 1_000_001]
+ test_msg.repeated_bool += [true, false]
+ test_msg.repeated_float += [-1.01, -1.02]
+ test_msg.repeated_double += [-1.0000000000001, -1.0000000000002]
+ test_msg.repeated_string += %w(foo bar)
+ test_msg.repeated_bytes += ["bar".encode!('ASCII-8BIT'), "foo".encode!('ASCII-8BIT')]
+ test_msg.repeated_msg << TestMessage2.new(:foo => 1)
+ test_msg.repeated_msg << TestMessage2.new(:foo => 2)
+ test_msg.repeated_enum << :A
+ test_msg.repeated_enum << :B
+ end
+
+
+ pool = Google::Protobuf::DescriptorPool.new
+ pool.build do
+
+ add_message "TestMessage" do
+ optional :optional_int32, :int32, 1
+ optional :optional_int64, :int64, 2
+ optional :optional_uint32, :uint32, 3
+ optional :optional_uint64, :uint64, 4
+ optional :optional_bool, :bool, 5
+ optional :optional_float, :float, 6
+ optional :optional_double, :double, 7
+ optional :optional_string, :string, 8
+ optional :optional_bytes, :bytes, 9
+ optional :optional_msg, :message, 10, "TestMessage2"
+ optional :optional_enum, :enum, 11, "TestEnum"
+
+ repeated :repeated_int32, :int32, 12
+ repeated :repeated_int64, :int64, 13
+ repeated :repeated_uint32, :uint32, 14
+ repeated :repeated_uint64, :uint64, 15
+ repeated :repeated_bool, :bool, 16
+ repeated :repeated_float, :float, 17
+ repeated :repeated_double, :double, 18
+ repeated :repeated_string, :string, 19
+ repeated :repeated_bytes, :bytes, 20
+ repeated :repeated_msg, :message, 21, "TestMessage2"
+ repeated :repeated_enum, :enum, 22, "TestEnum"
+ end
+ add_message "TestMessage2" do
+ optional :foo, :int32, 1
+ end
+
+ add_enum "TestEnum" do
+ value :Default, 0
+ value :A, 1
+ value :B, 2
+ value :C, 3
+ end
+ end
+
+ TestMessage = pool.lookup("TestMessage").msgclass
+ TestMessage2 = pool.lookup("TestMessage2").msgclass
+ TestEnum = pool.lookup("TestEnum").enummodule
+
+
+end
diff --git a/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/stress.rb b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/stress.rb
new file mode 100644
index 0000000000..082d5e22df
--- /dev/null
+++ b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/stress.rb
@@ -0,0 +1,38 @@
+#!/usr/bin/ruby
+
+require 'google/protobuf'
+require 'test/unit'
+
+module StressTest
+ pool = Google::Protobuf::DescriptorPool.new
+ pool.build do
+ add_message "TestMessage" do
+ optional :a, :int32, 1
+ repeated :b, :message, 2, "M"
+ end
+ add_message "M" do
+ optional :foo, :string, 1
+ end
+ end
+
+ TestMessage = pool.lookup("TestMessage").msgclass
+ M = pool.lookup("M").msgclass
+
+ class StressTest < Test::Unit::TestCase
+ def get_msg
+ TestMessage.new(:a => 1000,
+ :b => [M.new(:foo => "hello"),
+ M.new(:foo => "world")])
+ end
+ def test_stress
+ m = get_msg
+ data = TestMessage.encode(m)
+ 100_000.times do
+ mnew = TestMessage.decode(data)
+ mnew = mnew.dup
+ assert_equal mnew.inspect, m.inspect
+ assert TestMessage.encode(mnew) == data
+ end
+ end
+ end
+end
diff --git a/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/test_import.proto b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/test_import.proto
new file mode 100644
index 0000000000..230484ee57
--- /dev/null
+++ b/third_party/protobuf/ruby/compatibility_tests/v3.0.0/tests/test_import.proto
@@ -0,0 +1,5 @@
+syntax = "proto3";
+
+package foo_bar;
+
+message TestImportedMessage {}
diff --git a/third_party/protobuf/ruby/ext/google/protobuf_c/defs.c b/third_party/protobuf/ruby/ext/google/protobuf_c/defs.c
new file mode 100644
index 0000000000..845c02257f
--- /dev/null
+++ b/third_party/protobuf/ruby/ext/google/protobuf_c/defs.c
@@ -0,0 +1,1763 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 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 "protobuf.h"
+
+// -----------------------------------------------------------------------------
+// Common utilities.
+// -----------------------------------------------------------------------------
+
+static const char* get_str(VALUE str) {
+ Check_Type(str, T_STRING);
+ return RSTRING_PTR(str);
+}
+
+static VALUE rb_str_maybe_null(const char* s) {
+ if (s == NULL) {
+ s = "";
+ }
+ return rb_str_new2(s);
+}
+
+static upb_def* check_notfrozen(const upb_def* def) {
+ if (upb_def_isfrozen(def)) {
+ rb_raise(rb_eRuntimeError,
+ "Attempt to modify a frozen descriptor. Once descriptors are "
+ "added to the descriptor pool, they may not be modified.");
+ }
+ return (upb_def*)def;
+}
+
+static upb_msgdef* check_msg_notfrozen(const upb_msgdef* def) {
+ return upb_downcast_msgdef_mutable(check_notfrozen((const upb_def*)def));
+}
+
+static upb_fielddef* check_field_notfrozen(const upb_fielddef* def) {
+ return upb_downcast_fielddef_mutable(check_notfrozen((const upb_def*)def));
+}
+
+static upb_oneofdef* check_oneof_notfrozen(const upb_oneofdef* def) {
+ return (upb_oneofdef*)check_notfrozen((const upb_def*)def);
+}
+
+static upb_enumdef* check_enum_notfrozen(const upb_enumdef* def) {
+ return (upb_enumdef*)check_notfrozen((const upb_def*)def);
+}
+
+// -----------------------------------------------------------------------------
+// DescriptorPool.
+// -----------------------------------------------------------------------------
+
+#define DEFINE_CLASS(name, string_name) \
+ VALUE c ## name; \
+ const rb_data_type_t _ ## name ## _type = { \
+ string_name, \
+ { name ## _mark, name ## _free, NULL }, \
+ }; \
+ name* ruby_to_ ## name(VALUE val) { \
+ name* ret; \
+ TypedData_Get_Struct(val, name, &_ ## name ## _type, ret); \
+ return ret; \
+ } \
+
+#define DEFINE_SELF(type, var, rb_var) \
+ type* var = ruby_to_ ## type(rb_var)
+
+// Global singleton DescriptorPool. The user is free to create others, but this
+// is used by generated code.
+VALUE generated_pool;
+
+DEFINE_CLASS(DescriptorPool, "Google::Protobuf::DescriptorPool");
+
+void DescriptorPool_mark(void* _self) {
+}
+
+void DescriptorPool_free(void* _self) {
+ DescriptorPool* self = _self;
+ upb_symtab_free(self->symtab);
+ xfree(self);
+}
+
+/*
+ * call-seq:
+ * DescriptorPool.new => pool
+ *
+ * Creates a new, empty, descriptor pool.
+ */
+VALUE DescriptorPool_alloc(VALUE klass) {
+ DescriptorPool* self = ALLOC(DescriptorPool);
+ self->symtab = upb_symtab_new();
+ return TypedData_Wrap_Struct(klass, &_DescriptorPool_type, self);
+}
+
+void DescriptorPool_register(VALUE module) {
+ VALUE klass = rb_define_class_under(
+ module, "DescriptorPool", rb_cObject);
+ rb_define_alloc_func(klass, DescriptorPool_alloc);
+ rb_define_method(klass, "add", DescriptorPool_add, 1);
+ rb_define_method(klass, "build", DescriptorPool_build, 0);
+ rb_define_method(klass, "lookup", DescriptorPool_lookup, 1);
+ rb_define_singleton_method(klass, "generated_pool",
+ DescriptorPool_generated_pool, 0);
+ cDescriptorPool = klass;
+ rb_gc_register_address(&cDescriptorPool);
+
+ generated_pool = rb_class_new_instance(0, NULL, klass);
+ rb_gc_register_address(&generated_pool);
+}
+
+static void add_descriptor_to_pool(DescriptorPool* self,
+ Descriptor* descriptor) {
+ CHECK_UPB(
+ upb_symtab_add(self->symtab, (upb_def**)&descriptor->msgdef, 1,
+ NULL, &status),
+ "Adding Descriptor to DescriptorPool failed");
+}
+
+static void add_enumdesc_to_pool(DescriptorPool* self,
+ EnumDescriptor* enumdesc) {
+ CHECK_UPB(
+ upb_symtab_add(self->symtab, (upb_def**)&enumdesc->enumdef, 1,
+ NULL, &status),
+ "Adding EnumDescriptor to DescriptorPool failed");
+}
+
+/*
+ * call-seq:
+ * DescriptorPool.add(descriptor)
+ *
+ * Adds the given Descriptor or EnumDescriptor to this pool. All references to
+ * other types in a Descriptor's fields must be resolvable within this pool or
+ * an exception will be raised.
+ */
+VALUE DescriptorPool_add(VALUE _self, VALUE def) {
+ DEFINE_SELF(DescriptorPool, self, _self);
+ VALUE def_klass = rb_obj_class(def);
+ if (def_klass == cDescriptor) {
+ add_descriptor_to_pool(self, ruby_to_Descriptor(def));
+ } else if (def_klass == cEnumDescriptor) {
+ add_enumdesc_to_pool(self, ruby_to_EnumDescriptor(def));
+ } else {
+ rb_raise(rb_eArgError,
+ "Second argument must be a Descriptor or EnumDescriptor.");
+ }
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * DescriptorPool.build(&block)
+ *
+ * Invokes the block with a Builder instance as self. All message and enum types
+ * added within the block are committed to the pool atomically, and may refer
+ * (co)recursively to each other. The user should call Builder#add_message and
+ * Builder#add_enum within the block as appropriate. This is the recommended,
+ * idiomatic way to define new message and enum types.
+ */
+VALUE DescriptorPool_build(VALUE _self) {
+ VALUE ctx = rb_class_new_instance(0, NULL, cBuilder);
+ VALUE block = rb_block_proc();
+ rb_funcall_with_block(ctx, rb_intern("instance_eval"), 0, NULL, block);
+ rb_funcall(ctx, rb_intern("finalize_to_pool"), 1, _self);
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * DescriptorPool.lookup(name) => descriptor
+ *
+ * Finds a Descriptor or EnumDescriptor by name and returns it, or nil if none
+ * exists with the given name.
+ */
+VALUE DescriptorPool_lookup(VALUE _self, VALUE name) {
+ DEFINE_SELF(DescriptorPool, self, _self);
+ const char* name_str = get_str(name);
+ const upb_def* def = upb_symtab_lookup(self->symtab, name_str);
+ if (!def) {
+ return Qnil;
+ }
+ return get_def_obj(def);
+}
+
+/*
+ * call-seq:
+ * DescriptorPool.generated_pool => descriptor_pool
+ *
+ * Class method that returns the global DescriptorPool. This is a singleton into
+ * which generated-code message and enum types are registered. The user may also
+ * register types in this pool for convenience so that they do not have to hold
+ * a reference to a private pool instance.
+ */
+VALUE DescriptorPool_generated_pool(VALUE _self) {
+ return generated_pool;
+}
+
+// -----------------------------------------------------------------------------
+// Descriptor.
+// -----------------------------------------------------------------------------
+
+DEFINE_CLASS(Descriptor, "Google::Protobuf::Descriptor");
+
+void Descriptor_mark(void* _self) {
+ Descriptor* self = _self;
+ rb_gc_mark(self->klass);
+ rb_gc_mark(self->typeclass_references);
+}
+
+void Descriptor_free(void* _self) {
+ Descriptor* self = _self;
+ upb_msgdef_unref(self->msgdef, &self->msgdef);
+ if (self->layout) {
+ free_layout(self->layout);
+ }
+ if (self->fill_handlers) {
+ upb_handlers_unref(self->fill_handlers, &self->fill_handlers);
+ }
+ if (self->fill_method) {
+ upb_pbdecodermethod_unref(self->fill_method, &self->fill_method);
+ }
+ if (self->json_fill_method) {
+ upb_json_parsermethod_unref(self->json_fill_method,
+ &self->json_fill_method);
+ }
+ if (self->pb_serialize_handlers) {
+ upb_handlers_unref(self->pb_serialize_handlers,
+ &self->pb_serialize_handlers);
+ }
+ if (self->json_serialize_handlers) {
+ upb_handlers_unref(self->json_serialize_handlers,
+ &self->json_serialize_handlers);
+ }
+ if (self->json_serialize_handlers_preserve) {
+ upb_handlers_unref(self->json_serialize_handlers_preserve,
+ &self->json_serialize_handlers_preserve);
+ }
+ xfree(self);
+}
+
+/*
+ * call-seq:
+ * Descriptor.new => descriptor
+ *
+ * Creates a new, empty, message type descriptor. At a minimum, its name must be
+ * set before it is added to a pool. It cannot be used to create messages until
+ * it is added to a pool, after which it becomes immutable (as part of a
+ * finalization process).
+ */
+VALUE Descriptor_alloc(VALUE klass) {
+ Descriptor* self = ALLOC(Descriptor);
+ VALUE ret = TypedData_Wrap_Struct(klass, &_Descriptor_type, self);
+ self->msgdef = upb_msgdef_new(&self->msgdef);
+ self->klass = Qnil;
+ self->layout = NULL;
+ self->fill_handlers = NULL;
+ self->fill_method = NULL;
+ self->json_fill_method = NULL;
+ self->pb_serialize_handlers = NULL;
+ self->json_serialize_handlers = NULL;
+ self->json_serialize_handlers_preserve = NULL;
+ self->typeclass_references = rb_ary_new();
+ return ret;
+}
+
+void Descriptor_register(VALUE module) {
+ VALUE klass = rb_define_class_under(
+ module, "Descriptor", rb_cObject);
+ rb_define_alloc_func(klass, Descriptor_alloc);
+ rb_define_method(klass, "each", Descriptor_each, 0);
+ rb_define_method(klass, "lookup", Descriptor_lookup, 1);
+ rb_define_method(klass, "add_field", Descriptor_add_field, 1);
+ rb_define_method(klass, "add_oneof", Descriptor_add_oneof, 1);
+ rb_define_method(klass, "each_oneof", Descriptor_each_oneof, 0);
+ rb_define_method(klass, "lookup_oneof", Descriptor_lookup_oneof, 1);
+ rb_define_method(klass, "msgclass", Descriptor_msgclass, 0);
+ rb_define_method(klass, "name", Descriptor_name, 0);
+ rb_define_method(klass, "name=", Descriptor_name_set, 1);
+ rb_include_module(klass, rb_mEnumerable);
+ cDescriptor = klass;
+ rb_gc_register_address(&cDescriptor);
+}
+
+/*
+ * call-seq:
+ * Descriptor.name => name
+ *
+ * Returns the name of this message type as a fully-qualfied string (e.g.,
+ * My.Package.MessageType).
+ */
+VALUE Descriptor_name(VALUE _self) {
+ DEFINE_SELF(Descriptor, self, _self);
+ return rb_str_maybe_null(upb_msgdef_fullname(self->msgdef));
+}
+
+/*
+ * call-seq:
+ * Descriptor.name = name
+ *
+ * Assigns a name to this message type. The descriptor must not have been added
+ * to a pool yet.
+ */
+VALUE Descriptor_name_set(VALUE _self, VALUE str) {
+ DEFINE_SELF(Descriptor, self, _self);
+ upb_msgdef* mut_def = check_msg_notfrozen(self->msgdef);
+ const char* name = get_str(str);
+ CHECK_UPB(
+ upb_msgdef_setfullname(mut_def, name, &status),
+ "Error setting Descriptor name");
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * Descriptor.each(&block)
+ *
+ * Iterates over fields in this message type, yielding to the block on each one.
+ */
+VALUE Descriptor_each(VALUE _self) {
+ DEFINE_SELF(Descriptor, self, _self);
+
+ upb_msg_field_iter it;
+ for (upb_msg_field_begin(&it, self->msgdef);
+ !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* field = upb_msg_iter_field(&it);
+ VALUE obj = get_def_obj(field);
+ rb_yield(obj);
+ }
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * Descriptor.lookup(name) => FieldDescriptor
+ *
+ * Returns the field descriptor for the field with the given name, if present,
+ * or nil if none.
+ */
+VALUE Descriptor_lookup(VALUE _self, VALUE name) {
+ DEFINE_SELF(Descriptor, self, _self);
+ const char* s = get_str(name);
+ const upb_fielddef* field = upb_msgdef_ntofz(self->msgdef, s);
+ if (field == NULL) {
+ return Qnil;
+ }
+ return get_def_obj(field);
+}
+
+/*
+ * call-seq:
+ * Descriptor.add_field(field) => nil
+ *
+ * Adds the given FieldDescriptor to this message type. This descriptor must not
+ * have been added to a pool yet. Raises an exception if a field with the same
+ * name or number already exists. Sub-type references (e.g. for fields of type
+ * message) are not resolved at this point.
+ */
+VALUE Descriptor_add_field(VALUE _self, VALUE obj) {
+ DEFINE_SELF(Descriptor, self, _self);
+ upb_msgdef* mut_def = check_msg_notfrozen(self->msgdef);
+ FieldDescriptor* def = ruby_to_FieldDescriptor(obj);
+ upb_fielddef* mut_field_def = check_field_notfrozen(def->fielddef);
+ CHECK_UPB(
+ upb_msgdef_addfield(mut_def, mut_field_def, NULL, &status),
+ "Adding field to Descriptor failed");
+ add_def_obj(def->fielddef, obj);
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * Descriptor.add_oneof(oneof) => nil
+ *
+ * Adds the given OneofDescriptor to this message type. This descriptor must not
+ * have been added to a pool yet. Raises an exception if a oneof with the same
+ * name already exists, or if any of the oneof's fields' names or numbers
+ * conflict with an existing field in this message type. All fields in the oneof
+ * are added to the message descriptor. Sub-type references (e.g. for fields of
+ * type message) are not resolved at this point.
+ */
+VALUE Descriptor_add_oneof(VALUE _self, VALUE obj) {
+ DEFINE_SELF(Descriptor, self, _self);
+ upb_msgdef* mut_def = check_msg_notfrozen(self->msgdef);
+ OneofDescriptor* def = ruby_to_OneofDescriptor(obj);
+ upb_oneofdef* mut_oneof_def = check_oneof_notfrozen(def->oneofdef);
+ CHECK_UPB(
+ upb_msgdef_addoneof(mut_def, mut_oneof_def, NULL, &status),
+ "Adding oneof to Descriptor failed");
+ add_def_obj(def->oneofdef, obj);
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * Descriptor.each_oneof(&block) => nil
+ *
+ * Invokes the given block for each oneof in this message type, passing the
+ * corresponding OneofDescriptor.
+ */
+VALUE Descriptor_each_oneof(VALUE _self) {
+ DEFINE_SELF(Descriptor, self, _self);
+
+ upb_msg_oneof_iter it;
+ for (upb_msg_oneof_begin(&it, self->msgdef);
+ !upb_msg_oneof_done(&it);
+ upb_msg_oneof_next(&it)) {
+ const upb_oneofdef* oneof = upb_msg_iter_oneof(&it);
+ VALUE obj = get_def_obj(oneof);
+ rb_yield(obj);
+ }
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * Descriptor.lookup_oneof(name) => OneofDescriptor
+ *
+ * Returns the oneof descriptor for the oneof with the given name, if present,
+ * or nil if none.
+ */
+VALUE Descriptor_lookup_oneof(VALUE _self, VALUE name) {
+ DEFINE_SELF(Descriptor, self, _self);
+ const char* s = get_str(name);
+ const upb_oneofdef* oneof = upb_msgdef_ntooz(self->msgdef, s);
+ if (oneof == NULL) {
+ return Qnil;
+ }
+ return get_def_obj(oneof);
+}
+
+/*
+ * call-seq:
+ * Descriptor.msgclass => message_klass
+ *
+ * Returns the Ruby class created for this message type. Valid only once the
+ * message type has been added to a pool.
+ */
+VALUE Descriptor_msgclass(VALUE _self) {
+ DEFINE_SELF(Descriptor, self, _self);
+ if (!upb_def_isfrozen((const upb_def*)self->msgdef)) {
+ rb_raise(rb_eRuntimeError,
+ "Cannot fetch message class from a Descriptor not yet in a pool.");
+ }
+ if (self->klass == Qnil) {
+ self->klass = build_class_from_descriptor(self);
+ }
+ return self->klass;
+}
+
+// -----------------------------------------------------------------------------
+// FieldDescriptor.
+// -----------------------------------------------------------------------------
+
+DEFINE_CLASS(FieldDescriptor, "Google::Protobuf::FieldDescriptor");
+
+void FieldDescriptor_mark(void* _self) {
+}
+
+void FieldDescriptor_free(void* _self) {
+ FieldDescriptor* self = _self;
+ upb_fielddef_unref(self->fielddef, &self->fielddef);
+ xfree(self);
+}
+
+/*
+ * call-seq:
+ * FieldDescriptor.new => field
+ *
+ * Returns a new field descriptor. Its name, type, etc. must be set before it is
+ * added to a message type.
+ */
+VALUE FieldDescriptor_alloc(VALUE klass) {
+ FieldDescriptor* self = ALLOC(FieldDescriptor);
+ VALUE ret = TypedData_Wrap_Struct(klass, &_FieldDescriptor_type, self);
+ upb_fielddef* fielddef = upb_fielddef_new(&self->fielddef);
+ upb_fielddef_setpacked(fielddef, false);
+ self->fielddef = fielddef;
+ return ret;
+}
+
+void FieldDescriptor_register(VALUE module) {
+ VALUE klass = rb_define_class_under(
+ module, "FieldDescriptor", rb_cObject);
+ rb_define_alloc_func(klass, FieldDescriptor_alloc);
+ rb_define_method(klass, "name", FieldDescriptor_name, 0);
+ rb_define_method(klass, "name=", FieldDescriptor_name_set, 1);
+ rb_define_method(klass, "type", FieldDescriptor_type, 0);
+ rb_define_method(klass, "type=", FieldDescriptor_type_set, 1);
+ rb_define_method(klass, "label", FieldDescriptor_label, 0);
+ rb_define_method(klass, "label=", FieldDescriptor_label_set, 1);
+ rb_define_method(klass, "number", FieldDescriptor_number, 0);
+ rb_define_method(klass, "number=", FieldDescriptor_number_set, 1);
+ rb_define_method(klass, "submsg_name", FieldDescriptor_submsg_name, 0);
+ rb_define_method(klass, "submsg_name=", FieldDescriptor_submsg_name_set, 1);
+ rb_define_method(klass, "subtype", FieldDescriptor_subtype, 0);
+ rb_define_method(klass, "get", FieldDescriptor_get, 1);
+ rb_define_method(klass, "set", FieldDescriptor_set, 2);
+ cFieldDescriptor = klass;
+ rb_gc_register_address(&cFieldDescriptor);
+}
+
+/*
+ * call-seq:
+ * FieldDescriptor.name => name
+ *
+ * Returns the name of this field.
+ */
+VALUE FieldDescriptor_name(VALUE _self) {
+ DEFINE_SELF(FieldDescriptor, self, _self);
+ return rb_str_maybe_null(upb_fielddef_name(self->fielddef));
+}
+
+/*
+ * call-seq:
+ * FieldDescriptor.name = name
+ *
+ * Sets the name of this field. Cannot be called once the containing message
+ * type, if any, is added to a pool.
+ */
+VALUE FieldDescriptor_name_set(VALUE _self, VALUE str) {
+ DEFINE_SELF(FieldDescriptor, self, _self);
+ upb_fielddef* mut_def = check_field_notfrozen(self->fielddef);
+ const char* name = get_str(str);
+ CHECK_UPB(upb_fielddef_setname(mut_def, name, &status),
+ "Error setting FieldDescriptor name");
+ return Qnil;
+}
+
+upb_fieldtype_t ruby_to_fieldtype(VALUE type) {
+ if (TYPE(type) != T_SYMBOL) {
+ rb_raise(rb_eArgError, "Expected symbol for field type.");
+ }
+
+#define CONVERT(upb, ruby) \
+ if (SYM2ID(type) == rb_intern( # ruby )) { \
+ return UPB_TYPE_ ## upb; \
+ }
+
+ CONVERT(FLOAT, float);
+ CONVERT(DOUBLE, double);
+ CONVERT(BOOL, bool);
+ CONVERT(STRING, string);
+ CONVERT(BYTES, bytes);
+ CONVERT(MESSAGE, message);
+ CONVERT(ENUM, enum);
+ CONVERT(INT32, int32);
+ CONVERT(INT64, int64);
+ CONVERT(UINT32, uint32);
+ CONVERT(UINT64, uint64);
+
+#undef CONVERT
+
+ rb_raise(rb_eArgError, "Unknown field type.");
+ return 0;
+}
+
+VALUE fieldtype_to_ruby(upb_fieldtype_t type) {
+ switch (type) {
+#define CONVERT(upb, ruby) \
+ case UPB_TYPE_ ## upb : return ID2SYM(rb_intern( # ruby ));
+ CONVERT(FLOAT, float);
+ CONVERT(DOUBLE, double);
+ CONVERT(BOOL, bool);
+ CONVERT(STRING, string);
+ CONVERT(BYTES, bytes);
+ CONVERT(MESSAGE, message);
+ CONVERT(ENUM, enum);
+ CONVERT(INT32, int32);
+ CONVERT(INT64, int64);
+ CONVERT(UINT32, uint32);
+ CONVERT(UINT64, uint64);
+#undef CONVERT
+ }
+ return Qnil;
+}
+
+upb_descriptortype_t ruby_to_descriptortype(VALUE type) {
+ if (TYPE(type) != T_SYMBOL) {
+ rb_raise(rb_eArgError, "Expected symbol for field type.");
+ }
+
+#define CONVERT(upb, ruby) \
+ if (SYM2ID(type) == rb_intern( # ruby )) { \
+ return UPB_DESCRIPTOR_TYPE_ ## upb; \
+ }
+
+ CONVERT(FLOAT, float);
+ CONVERT(DOUBLE, double);
+ CONVERT(BOOL, bool);
+ CONVERT(STRING, string);
+ CONVERT(BYTES, bytes);
+ CONVERT(MESSAGE, message);
+ CONVERT(GROUP, group);
+ CONVERT(ENUM, enum);
+ CONVERT(INT32, int32);
+ CONVERT(INT64, int64);
+ CONVERT(UINT32, uint32);
+ CONVERT(UINT64, uint64);
+ CONVERT(SINT32, sint32);
+ CONVERT(SINT64, sint64);
+ CONVERT(FIXED32, fixed32);
+ CONVERT(FIXED64, fixed64);
+ CONVERT(SFIXED32, sfixed32);
+ CONVERT(SFIXED64, sfixed64);
+
+#undef CONVERT
+
+ rb_raise(rb_eArgError, "Unknown field type.");
+ return 0;
+}
+
+VALUE descriptortype_to_ruby(upb_descriptortype_t type) {
+ switch (type) {
+#define CONVERT(upb, ruby) \
+ case UPB_DESCRIPTOR_TYPE_ ## upb : return ID2SYM(rb_intern( # ruby ));
+ CONVERT(FLOAT, float);
+ CONVERT(DOUBLE, double);
+ CONVERT(BOOL, bool);
+ CONVERT(STRING, string);
+ CONVERT(BYTES, bytes);
+ CONVERT(MESSAGE, message);
+ CONVERT(GROUP, group);
+ CONVERT(ENUM, enum);
+ CONVERT(INT32, int32);
+ CONVERT(INT64, int64);
+ CONVERT(UINT32, uint32);
+ CONVERT(UINT64, uint64);
+ CONVERT(SINT32, sint32);
+ CONVERT(SINT64, sint64);
+ CONVERT(FIXED32, fixed32);
+ CONVERT(FIXED64, fixed64);
+ CONVERT(SFIXED32, sfixed32);
+ CONVERT(SFIXED64, sfixed64);
+#undef CONVERT
+ }
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * FieldDescriptor.type => type
+ *
+ * Returns this field's type, as a Ruby symbol, or nil if not yet set.
+ *
+ * Valid field types are:
+ * :int32, :int64, :uint32, :uint64, :float, :double, :bool, :string,
+ * :bytes, :message.
+ */
+VALUE FieldDescriptor_type(VALUE _self) {
+ DEFINE_SELF(FieldDescriptor, self, _self);
+ if (!upb_fielddef_typeisset(self->fielddef)) {
+ return Qnil;
+ }
+ return descriptortype_to_ruby(upb_fielddef_descriptortype(self->fielddef));
+}
+
+/*
+ * call-seq:
+ * FieldDescriptor.type = type
+ *
+ * Sets this field's type. Cannot be called if field is part of a message type
+ * already in a pool.
+ */
+VALUE FieldDescriptor_type_set(VALUE _self, VALUE type) {
+ DEFINE_SELF(FieldDescriptor, self, _self);
+ upb_fielddef* mut_def = check_field_notfrozen(self->fielddef);
+ upb_fielddef_setdescriptortype(mut_def, ruby_to_descriptortype(type));
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * FieldDescriptor.label => label
+ *
+ * Returns this field's label (i.e., plurality), as a Ruby symbol.
+ *
+ * Valid field labels are:
+ * :optional, :repeated
+ */
+VALUE FieldDescriptor_label(VALUE _self) {
+ DEFINE_SELF(FieldDescriptor, self, _self);
+ switch (upb_fielddef_label(self->fielddef)) {
+#define CONVERT(upb, ruby) \
+ case UPB_LABEL_ ## upb : return ID2SYM(rb_intern( # ruby ));
+
+ CONVERT(OPTIONAL, optional);
+ CONVERT(REQUIRED, required);
+ CONVERT(REPEATED, repeated);
+
+#undef CONVERT
+ }
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * FieldDescriptor.label = label
+ *
+ * Sets the label on this field. Cannot be called if field is part of a message
+ * type already in a pool.
+ */
+VALUE FieldDescriptor_label_set(VALUE _self, VALUE label) {
+ DEFINE_SELF(FieldDescriptor, self, _self);
+ upb_fielddef* mut_def = check_field_notfrozen(self->fielddef);
+ upb_label_t upb_label = -1;
+ bool converted = false;
+
+ if (TYPE(label) != T_SYMBOL) {
+ rb_raise(rb_eArgError, "Expected symbol for field label.");
+ }
+
+#define CONVERT(upb, ruby) \
+ if (SYM2ID(label) == rb_intern( # ruby )) { \
+ upb_label = UPB_LABEL_ ## upb; \
+ converted = true; \
+ }
+
+ CONVERT(OPTIONAL, optional);
+ CONVERT(REQUIRED, required);
+ CONVERT(REPEATED, repeated);
+
+#undef CONVERT
+
+ if (!converted) {
+ rb_raise(rb_eArgError, "Unknown field label.");
+ }
+
+ upb_fielddef_setlabel(mut_def, upb_label);
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * FieldDescriptor.number => number
+ *
+ * Returns the tag number for this field.
+ */
+VALUE FieldDescriptor_number(VALUE _self) {
+ DEFINE_SELF(FieldDescriptor, self, _self);
+ return INT2NUM(upb_fielddef_number(self->fielddef));
+}
+
+/*
+ * call-seq:
+ * FieldDescriptor.number = number
+ *
+ * Sets the tag number for this field. Cannot be called if field is part of a
+ * message type already in a pool.
+ */
+VALUE FieldDescriptor_number_set(VALUE _self, VALUE number) {
+ DEFINE_SELF(FieldDescriptor, self, _self);
+ upb_fielddef* mut_def = check_field_notfrozen(self->fielddef);
+ CHECK_UPB(upb_fielddef_setnumber(mut_def, NUM2INT(number), &status),
+ "Error setting field number");
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * FieldDescriptor.submsg_name => submsg_name
+ *
+ * Returns the name of the message or enum type corresponding to this field, if
+ * it is a message or enum field (respectively), or nil otherwise. This type
+ * name will be resolved within the context of the pool to which the containing
+ * message type is added.
+ */
+VALUE FieldDescriptor_submsg_name(VALUE _self) {
+ DEFINE_SELF(FieldDescriptor, self, _self);
+ if (!upb_fielddef_hassubdef(self->fielddef)) {
+ return Qnil;
+ }
+ return rb_str_maybe_null(upb_fielddef_subdefname(self->fielddef));
+}
+
+/*
+ * call-seq:
+ * FieldDescriptor.submsg_name = submsg_name
+ *
+ * Sets the name of the message or enum type corresponding to this field, if it
+ * is a message or enum field (respectively). This type name will be resolved
+ * within the context of the pool to which the containing message type is added.
+ * Cannot be called on field that are not of message or enum type, or on fields
+ * that are part of a message type already added to a pool.
+ */
+VALUE FieldDescriptor_submsg_name_set(VALUE _self, VALUE value) {
+ DEFINE_SELF(FieldDescriptor, self, _self);
+ upb_fielddef* mut_def = check_field_notfrozen(self->fielddef);
+ const char* str = get_str(value);
+ if (!upb_fielddef_hassubdef(self->fielddef)) {
+ rb_raise(rb_eTypeError, "FieldDescriptor does not have subdef.");
+ }
+ CHECK_UPB(upb_fielddef_setsubdefname(mut_def, str, &status),
+ "Error setting submessage name");
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * FieldDescriptor.subtype => message_or_enum_descriptor
+ *
+ * Returns the message or enum descriptor corresponding to this field's type if
+ * it is a message or enum field, respectively, or nil otherwise. Cannot be
+ * called *until* the containing message type is added to a pool (and thus
+ * resolved).
+ */
+VALUE FieldDescriptor_subtype(VALUE _self) {
+ DEFINE_SELF(FieldDescriptor, self, _self);
+ const upb_def* def;
+
+ if (!upb_fielddef_hassubdef(self->fielddef)) {
+ return Qnil;
+ }
+ def = upb_fielddef_subdef(self->fielddef);
+ if (def == NULL) {
+ return Qnil;
+ }
+ return get_def_obj(def);
+}
+
+/*
+ * call-seq:
+ * FieldDescriptor.get(message) => value
+ *
+ * Returns the value set for this field on the given message. Raises an
+ * exception if message is of the wrong type.
+ */
+VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) {
+ DEFINE_SELF(FieldDescriptor, self, _self);
+ MessageHeader* msg;
+ TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg);
+ if (msg->descriptor->msgdef != upb_fielddef_containingtype(self->fielddef)) {
+ rb_raise(rb_eTypeError, "get method called on wrong message type");
+ }
+ return layout_get(msg->descriptor->layout, Message_data(msg), self->fielddef);
+}
+
+/*
+ * call-seq:
+ * FieldDescriptor.set(message, value)
+ *
+ * Sets the value corresponding to this field to the given value on the given
+ * message. Raises an exception if message is of the wrong type. Performs the
+ * ordinary type-checks for field setting.
+ */
+VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) {
+ DEFINE_SELF(FieldDescriptor, self, _self);
+ MessageHeader* msg;
+ TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg);
+ if (msg->descriptor->msgdef != upb_fielddef_containingtype(self->fielddef)) {
+ rb_raise(rb_eTypeError, "set method called on wrong message type");
+ }
+ layout_set(msg->descriptor->layout, Message_data(msg), self->fielddef, value);
+ return Qnil;
+}
+
+// -----------------------------------------------------------------------------
+// OneofDescriptor.
+// -----------------------------------------------------------------------------
+
+DEFINE_CLASS(OneofDescriptor, "Google::Protobuf::OneofDescriptor");
+
+void OneofDescriptor_mark(void* _self) {
+}
+
+void OneofDescriptor_free(void* _self) {
+ OneofDescriptor* self = _self;
+ upb_oneofdef_unref(self->oneofdef, &self->oneofdef);
+ xfree(self);
+}
+
+/*
+ * call-seq:
+ * OneofDescriptor.new => oneof_descriptor
+ *
+ * Creates a new, empty, oneof descriptor. The oneof may only be modified prior
+ * to being added to a message descriptor which is subsequently added to a pool.
+ */
+VALUE OneofDescriptor_alloc(VALUE klass) {
+ OneofDescriptor* self = ALLOC(OneofDescriptor);
+ VALUE ret = TypedData_Wrap_Struct(klass, &_OneofDescriptor_type, self);
+ self->oneofdef = upb_oneofdef_new(&self->oneofdef);
+ return ret;
+}
+
+void OneofDescriptor_register(VALUE module) {
+ VALUE klass = rb_define_class_under(
+ module, "OneofDescriptor", rb_cObject);
+ rb_define_alloc_func(klass, OneofDescriptor_alloc);
+ rb_define_method(klass, "name", OneofDescriptor_name, 0);
+ rb_define_method(klass, "name=", OneofDescriptor_name_set, 1);
+ rb_define_method(klass, "add_field", OneofDescriptor_add_field, 1);
+ rb_define_method(klass, "each", OneofDescriptor_each, 0);
+ rb_include_module(klass, rb_mEnumerable);
+ cOneofDescriptor = klass;
+ rb_gc_register_address(&cOneofDescriptor);
+}
+
+/*
+ * call-seq:
+ * OneofDescriptor.name => name
+ *
+ * Returns the name of this oneof.
+ */
+VALUE OneofDescriptor_name(VALUE _self) {
+ DEFINE_SELF(OneofDescriptor, self, _self);
+ return rb_str_maybe_null(upb_oneofdef_name(self->oneofdef));
+}
+
+/*
+ * call-seq:
+ * OneofDescriptor.name = name
+ *
+ * Sets a new name for this oneof. The oneof must not have been added to a
+ * message descriptor yet.
+ */
+VALUE OneofDescriptor_name_set(VALUE _self, VALUE value) {
+ DEFINE_SELF(OneofDescriptor, self, _self);
+ upb_oneofdef* mut_def = check_oneof_notfrozen(self->oneofdef);
+ const char* str = get_str(value);
+ CHECK_UPB(upb_oneofdef_setname(mut_def, str, &status),
+ "Error setting oneof name");
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * OneofDescriptor.add_field(field) => nil
+ *
+ * Adds a field to this oneof. The field may have been added to this oneof in
+ * the past, or the message to which this oneof belongs (if any), but may not
+ * have already been added to any other oneof or message. Otherwise, an
+ * exception is raised.
+ *
+ * All fields added to the oneof via this method will be automatically added to
+ * the message to which this oneof belongs, if it belongs to one currently, or
+ * else will be added to any message to which the oneof is later added at the
+ * time that it is added.
+ */
+VALUE OneofDescriptor_add_field(VALUE _self, VALUE obj) {
+ DEFINE_SELF(OneofDescriptor, self, _self);
+ upb_oneofdef* mut_def = check_oneof_notfrozen(self->oneofdef);
+ FieldDescriptor* def = ruby_to_FieldDescriptor(obj);
+ upb_fielddef* mut_field_def = check_field_notfrozen(def->fielddef);
+ CHECK_UPB(
+ upb_oneofdef_addfield(mut_def, mut_field_def, NULL, &status),
+ "Adding field to OneofDescriptor failed");
+ add_def_obj(def->fielddef, obj);
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * OneofDescriptor.each(&block) => nil
+ *
+ * Iterates through fields in this oneof, yielding to the block on each one.
+ */
+VALUE OneofDescriptor_each(VALUE _self, VALUE field) {
+ DEFINE_SELF(OneofDescriptor, self, _self);
+ upb_oneof_iter it;
+ for (upb_oneof_begin(&it, self->oneofdef);
+ !upb_oneof_done(&it);
+ upb_oneof_next(&it)) {
+ const upb_fielddef* f = upb_oneof_iter_field(&it);
+ VALUE obj = get_def_obj(f);
+ rb_yield(obj);
+ }
+ return Qnil;
+}
+
+// -----------------------------------------------------------------------------
+// EnumDescriptor.
+// -----------------------------------------------------------------------------
+
+DEFINE_CLASS(EnumDescriptor, "Google::Protobuf::EnumDescriptor");
+
+void EnumDescriptor_mark(void* _self) {
+ EnumDescriptor* self = _self;
+ rb_gc_mark(self->module);
+}
+
+void EnumDescriptor_free(void* _self) {
+ EnumDescriptor* self = _self;
+ upb_enumdef_unref(self->enumdef, &self->enumdef);
+ xfree(self);
+}
+
+/*
+ * call-seq:
+ * EnumDescriptor.new => enum_descriptor
+ *
+ * Creates a new, empty, enum descriptor. Must be added to a pool before the
+ * enum type can be used. The enum type may only be modified prior to adding to
+ * a pool.
+ */
+VALUE EnumDescriptor_alloc(VALUE klass) {
+ EnumDescriptor* self = ALLOC(EnumDescriptor);
+ VALUE ret = TypedData_Wrap_Struct(klass, &_EnumDescriptor_type, self);
+ self->enumdef = upb_enumdef_new(&self->enumdef);
+ self->module = Qnil;
+ return ret;
+}
+
+void EnumDescriptor_register(VALUE module) {
+ VALUE klass = rb_define_class_under(
+ module, "EnumDescriptor", rb_cObject);
+ rb_define_alloc_func(klass, EnumDescriptor_alloc);
+ rb_define_method(klass, "name", EnumDescriptor_name, 0);
+ rb_define_method(klass, "name=", EnumDescriptor_name_set, 1);
+ rb_define_method(klass, "add_value", EnumDescriptor_add_value, 2);
+ rb_define_method(klass, "lookup_name", EnumDescriptor_lookup_name, 1);
+ rb_define_method(klass, "lookup_value", EnumDescriptor_lookup_value, 1);
+ rb_define_method(klass, "each", EnumDescriptor_each, 0);
+ rb_define_method(klass, "enummodule", EnumDescriptor_enummodule, 0);
+ rb_include_module(klass, rb_mEnumerable);
+ cEnumDescriptor = klass;
+ rb_gc_register_address(&cEnumDescriptor);
+}
+
+/*
+ * call-seq:
+ * EnumDescriptor.name => name
+ *
+ * Returns the name of this enum type.
+ */
+VALUE EnumDescriptor_name(VALUE _self) {
+ DEFINE_SELF(EnumDescriptor, self, _self);
+ return rb_str_maybe_null(upb_enumdef_fullname(self->enumdef));
+}
+
+/*
+ * call-seq:
+ * EnumDescriptor.name = name
+ *
+ * Sets the name of this enum type. Cannot be called if the enum type has
+ * already been added to a pool.
+ */
+VALUE EnumDescriptor_name_set(VALUE _self, VALUE str) {
+ DEFINE_SELF(EnumDescriptor, self, _self);
+ upb_enumdef* mut_def = check_enum_notfrozen(self->enumdef);
+ const char* name = get_str(str);
+ CHECK_UPB(upb_enumdef_setfullname(mut_def, name, &status),
+ "Error setting EnumDescriptor name");
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * EnumDescriptor.add_value(key, value)
+ *
+ * Adds a new key => value mapping to this enum type. Key must be given as a
+ * Ruby symbol. Cannot be called if the enum type has already been added to a
+ * pool. Will raise an exception if the key or value is already in use.
+ */
+VALUE EnumDescriptor_add_value(VALUE _self, VALUE name, VALUE number) {
+ DEFINE_SELF(EnumDescriptor, self, _self);
+ upb_enumdef* mut_def = check_enum_notfrozen(self->enumdef);
+ const char* name_str = rb_id2name(SYM2ID(name));
+ int32_t val = NUM2INT(number);
+ CHECK_UPB(upb_enumdef_addval(mut_def, name_str, val, &status),
+ "Error adding value to enum");
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * EnumDescriptor.lookup_name(name) => value
+ *
+ * Returns the numeric value corresponding to the given key name (as a Ruby
+ * symbol), or nil if none.
+ */
+VALUE EnumDescriptor_lookup_name(VALUE _self, VALUE name) {
+ DEFINE_SELF(EnumDescriptor, self, _self);
+ const char* name_str= rb_id2name(SYM2ID(name));
+ int32_t val = 0;
+ if (upb_enumdef_ntoiz(self->enumdef, name_str, &val)) {
+ return INT2NUM(val);
+ } else {
+ return Qnil;
+ }
+}
+
+/*
+ * call-seq:
+ * EnumDescriptor.lookup_value(name) => value
+ *
+ * Returns the key name (as a Ruby symbol) corresponding to the integer value,
+ * or nil if none.
+ */
+VALUE EnumDescriptor_lookup_value(VALUE _self, VALUE number) {
+ DEFINE_SELF(EnumDescriptor, self, _self);
+ int32_t val = NUM2INT(number);
+ const char* name = upb_enumdef_iton(self->enumdef, val);
+ if (name != NULL) {
+ return ID2SYM(rb_intern(name));
+ } else {
+ return Qnil;
+ }
+}
+
+/*
+ * call-seq:
+ * EnumDescriptor.each(&block)
+ *
+ * Iterates over key => value mappings in this enum's definition, yielding to
+ * the block with (key, value) arguments for each one.
+ */
+VALUE EnumDescriptor_each(VALUE _self) {
+ DEFINE_SELF(EnumDescriptor, self, _self);
+
+ upb_enum_iter it;
+ for (upb_enum_begin(&it, self->enumdef);
+ !upb_enum_done(&it);
+ upb_enum_next(&it)) {
+ VALUE key = ID2SYM(rb_intern(upb_enum_iter_name(&it)));
+ VALUE number = INT2NUM(upb_enum_iter_number(&it));
+ rb_yield_values(2, key, number);
+ }
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * EnumDescriptor.enummodule => module
+ *
+ * Returns the Ruby module corresponding to this enum type. Cannot be called
+ * until the enum descriptor has been added to a pool.
+ */
+VALUE EnumDescriptor_enummodule(VALUE _self) {
+ DEFINE_SELF(EnumDescriptor, self, _self);
+ if (!upb_def_isfrozen((const upb_def*)self->enumdef)) {
+ rb_raise(rb_eRuntimeError,
+ "Cannot fetch enum module from an EnumDescriptor not yet "
+ "in a pool.");
+ }
+ if (self->module == Qnil) {
+ self->module = build_module_from_enumdesc(self);
+ }
+ return self->module;
+}
+
+// -----------------------------------------------------------------------------
+// MessageBuilderContext.
+// -----------------------------------------------------------------------------
+
+DEFINE_CLASS(MessageBuilderContext,
+ "Google::Protobuf::Internal::MessageBuilderContext");
+
+void MessageBuilderContext_mark(void* _self) {
+ MessageBuilderContext* self = _self;
+ rb_gc_mark(self->descriptor);
+ rb_gc_mark(self->builder);
+}
+
+void MessageBuilderContext_free(void* _self) {
+ MessageBuilderContext* self = _self;
+ xfree(self);
+}
+
+VALUE MessageBuilderContext_alloc(VALUE klass) {
+ MessageBuilderContext* self = ALLOC(MessageBuilderContext);
+ VALUE ret = TypedData_Wrap_Struct(
+ klass, &_MessageBuilderContext_type, self);
+ self->descriptor = Qnil;
+ self->builder = Qnil;
+ return ret;
+}
+
+void MessageBuilderContext_register(VALUE module) {
+ VALUE klass = rb_define_class_under(
+ module, "MessageBuilderContext", rb_cObject);
+ rb_define_alloc_func(klass, MessageBuilderContext_alloc);
+ rb_define_method(klass, "initialize",
+ MessageBuilderContext_initialize, 2);
+ rb_define_method(klass, "optional", MessageBuilderContext_optional, -1);
+ rb_define_method(klass, "required", MessageBuilderContext_required, -1);
+ rb_define_method(klass, "repeated", MessageBuilderContext_repeated, -1);
+ rb_define_method(klass, "map", MessageBuilderContext_map, -1);
+ rb_define_method(klass, "oneof", MessageBuilderContext_oneof, 1);
+ cMessageBuilderContext = klass;
+ rb_gc_register_address(&cMessageBuilderContext);
+}
+
+/*
+ * call-seq:
+ * MessageBuilderContext.new(desc, builder) => context
+ *
+ * Create a new message builder context around the given message descriptor and
+ * builder context. This class is intended to serve as a DSL context to be used
+ * with #instance_eval.
+ */
+VALUE MessageBuilderContext_initialize(VALUE _self,
+ VALUE msgdef,
+ VALUE builder) {
+ DEFINE_SELF(MessageBuilderContext, self, _self);
+ self->descriptor = msgdef;
+ self->builder = builder;
+ return Qnil;
+}
+
+static VALUE msgdef_add_field(VALUE msgdef,
+ const char* label, VALUE name,
+ VALUE type, VALUE number,
+ VALUE type_class) {
+ VALUE fielddef = rb_class_new_instance(0, NULL, cFieldDescriptor);
+ VALUE name_str = rb_str_new2(rb_id2name(SYM2ID(name)));
+
+ rb_funcall(fielddef, rb_intern("label="), 1, ID2SYM(rb_intern(label)));
+ rb_funcall(fielddef, rb_intern("name="), 1, name_str);
+ rb_funcall(fielddef, rb_intern("type="), 1, type);
+ rb_funcall(fielddef, rb_intern("number="), 1, number);
+
+ if (type_class != Qnil) {
+ if (TYPE(type_class) != T_STRING) {
+ rb_raise(rb_eArgError, "Expected string for type class");
+ }
+ // Make it an absolute type name by prepending a dot.
+ type_class = rb_str_append(rb_str_new2("."), type_class);
+ rb_funcall(fielddef, rb_intern("submsg_name="), 1, type_class);
+ }
+
+ rb_funcall(msgdef, rb_intern("add_field"), 1, fielddef);
+ return fielddef;
+}
+
+/*
+ * call-seq:
+ * MessageBuilderContext.optional(name, type, number, type_class = nil)
+ *
+ * Defines a new optional field on this message type with the given type, tag
+ * number, and type class (for message and enum fields). The type must be a Ruby
+ * symbol (as accepted by FieldDescriptor#type=) and the type_class must be a
+ * string, if present (as accepted by FieldDescriptor#submsg_name=).
+ */
+VALUE MessageBuilderContext_optional(int argc, VALUE* argv, VALUE _self) {
+ DEFINE_SELF(MessageBuilderContext, self, _self);
+ VALUE name, type, number, type_class;
+
+ if (argc < 3) {
+ rb_raise(rb_eArgError, "Expected at least 3 arguments.");
+ }
+ name = argv[0];
+ type = argv[1];
+ number = argv[2];
+ type_class = (argc > 3) ? argv[3] : Qnil;
+
+ return msgdef_add_field(self->descriptor, "optional",
+ name, type, number, type_class);
+}
+
+/*
+ * call-seq:
+ * MessageBuilderContext.required(name, type, number, type_class = nil)
+ *
+ * Defines a new required field on this message type with the given type, tag
+ * number, and type class (for message and enum fields). The type must be a Ruby
+ * symbol (as accepted by FieldDescriptor#type=) and the type_class must be a
+ * string, if present (as accepted by FieldDescriptor#submsg_name=).
+ *
+ * Proto3 does not have required fields, but this method exists for
+ * completeness. Any attempt to add a message type with required fields to a
+ * pool will currently result in an error.
+ */
+VALUE MessageBuilderContext_required(int argc, VALUE* argv, VALUE _self) {
+ DEFINE_SELF(MessageBuilderContext, self, _self);
+ VALUE name, type, number, type_class;
+
+ if (argc < 3) {
+ rb_raise(rb_eArgError, "Expected at least 3 arguments.");
+ }
+ name = argv[0];
+ type = argv[1];
+ number = argv[2];
+ type_class = (argc > 3) ? argv[3] : Qnil;
+
+ return msgdef_add_field(self->descriptor, "required",
+ name, type, number, type_class);
+}
+
+/*
+ * call-seq:
+ * MessageBuilderContext.repeated(name, type, number, type_class = nil)
+ *
+ * Defines a new repeated field on this message type with the given type, tag
+ * number, and type class (for message and enum fields). The type must be a Ruby
+ * symbol (as accepted by FieldDescriptor#type=) and the type_class must be a
+ * string, if present (as accepted by FieldDescriptor#submsg_name=).
+ */
+VALUE MessageBuilderContext_repeated(int argc, VALUE* argv, VALUE _self) {
+ DEFINE_SELF(MessageBuilderContext, self, _self);
+ VALUE name, type, number, type_class;
+
+ if (argc < 3) {
+ rb_raise(rb_eArgError, "Expected at least 3 arguments.");
+ }
+ name = argv[0];
+ type = argv[1];
+ number = argv[2];
+ type_class = (argc > 3) ? argv[3] : Qnil;
+
+ return msgdef_add_field(self->descriptor, "repeated",
+ name, type, number, type_class);
+}
+
+/*
+ * call-seq:
+ * MessageBuilderContext.map(name, key_type, value_type, number,
+ * value_type_class = nil)
+ *
+ * Defines a new map field on this message type with the given key and value
+ * types, tag number, and type class (for message and enum value types). The key
+ * type must be :int32/:uint32/:int64/:uint64, :bool, or :string. The value type
+ * type must be a Ruby symbol (as accepted by FieldDescriptor#type=) and the
+ * type_class must be a string, if present (as accepted by
+ * FieldDescriptor#submsg_name=).
+ */
+VALUE MessageBuilderContext_map(int argc, VALUE* argv, VALUE _self) {
+ DEFINE_SELF(MessageBuilderContext, self, _self);
+ VALUE name, key_type, value_type, number, type_class;
+ VALUE mapentry_desc, mapentry_desc_name;
+
+ if (argc < 4) {
+ rb_raise(rb_eArgError, "Expected at least 4 arguments.");
+ }
+ name = argv[0];
+ key_type = argv[1];
+ value_type = argv[2];
+ number = argv[3];
+ type_class = (argc > 4) ? argv[4] : Qnil;
+
+ // Validate the key type. We can't accept enums, messages, or floats/doubles
+ // as map keys. (We exclude these explicitly, and the field-descriptor setter
+ // below then ensures that the type is one of the remaining valid options.)
+ if (SYM2ID(key_type) == rb_intern("float") ||
+ SYM2ID(key_type) == rb_intern("double") ||
+ SYM2ID(key_type) == rb_intern("enum") ||
+ SYM2ID(key_type) == rb_intern("message")) {
+ rb_raise(rb_eArgError,
+ "Cannot add a map field with a float, double, enum, or message "
+ "type.");
+ }
+
+ // Create a new message descriptor for the map entry message, and create a
+ // repeated submessage field here with that type.
+ mapentry_desc = rb_class_new_instance(0, NULL, cDescriptor);
+ mapentry_desc_name = rb_funcall(self->descriptor, rb_intern("name"), 0);
+ mapentry_desc_name = rb_str_cat2(mapentry_desc_name, "_MapEntry_");
+ mapentry_desc_name = rb_str_cat2(mapentry_desc_name,
+ rb_id2name(SYM2ID(name)));
+ Descriptor_name_set(mapentry_desc, mapentry_desc_name);
+
+ {
+ // The 'mapentry' attribute has no Ruby setter because we do not want the
+ // user attempting to DIY the setup below; we want to ensure that the fields
+ // are correct. So we reach into the msgdef here to set the bit manually.
+ Descriptor* mapentry_desc_self = ruby_to_Descriptor(mapentry_desc);
+ upb_msgdef_setmapentry((upb_msgdef*)mapentry_desc_self->msgdef, true);
+ }
+
+ {
+ // optional <type> key = 1;
+ VALUE key_field = rb_class_new_instance(0, NULL, cFieldDescriptor);
+ FieldDescriptor_name_set(key_field, rb_str_new2("key"));
+ FieldDescriptor_label_set(key_field, ID2SYM(rb_intern("optional")));
+ FieldDescriptor_number_set(key_field, INT2NUM(1));
+ FieldDescriptor_type_set(key_field, key_type);
+ Descriptor_add_field(mapentry_desc, key_field);
+ }
+
+ {
+ // optional <type> value = 2;
+ VALUE value_field = rb_class_new_instance(0, NULL, cFieldDescriptor);
+ FieldDescriptor_name_set(value_field, rb_str_new2("value"));
+ FieldDescriptor_label_set(value_field, ID2SYM(rb_intern("optional")));
+ FieldDescriptor_number_set(value_field, INT2NUM(2));
+ FieldDescriptor_type_set(value_field, value_type);
+ if (type_class != Qnil) {
+ VALUE submsg_name = rb_str_new2("."); // prepend '.' to make absolute.
+ submsg_name = rb_str_append(submsg_name, type_class);
+ FieldDescriptor_submsg_name_set(value_field, submsg_name);
+ }
+ Descriptor_add_field(mapentry_desc, value_field);
+ }
+
+ {
+ // Add the map-entry message type to the current builder, and use the type
+ // to create the map field itself.
+ Builder* builder_self = ruby_to_Builder(self->builder);
+ rb_ary_push(builder_self->pending_list, mapentry_desc);
+ }
+
+ {
+ VALUE map_field = rb_class_new_instance(0, NULL, cFieldDescriptor);
+ VALUE name_str = rb_str_new2(rb_id2name(SYM2ID(name)));
+ VALUE submsg_name;
+
+ FieldDescriptor_name_set(map_field, name_str);
+ FieldDescriptor_number_set(map_field, number);
+ FieldDescriptor_label_set(map_field, ID2SYM(rb_intern("repeated")));
+ FieldDescriptor_type_set(map_field, ID2SYM(rb_intern("message")));
+ submsg_name = rb_str_new2("."); // prepend '.' to make name absolute.
+ submsg_name = rb_str_append(submsg_name, mapentry_desc_name);
+ FieldDescriptor_submsg_name_set(map_field, submsg_name);
+ Descriptor_add_field(self->descriptor, map_field);
+ }
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * MessageBuilderContext.oneof(name, &block) => nil
+ *
+ * Creates a new OneofDescriptor with the given name, creates a
+ * OneofBuilderContext attached to that OneofDescriptor, evaluates the given
+ * block in the context of that OneofBuilderContext with #instance_eval, and
+ * then adds the oneof to the message.
+ *
+ * This is the recommended, idiomatic way to build oneof definitions.
+ */
+VALUE MessageBuilderContext_oneof(VALUE _self, VALUE name) {
+ DEFINE_SELF(MessageBuilderContext, self, _self);
+ VALUE oneofdef = rb_class_new_instance(0, NULL, cOneofDescriptor);
+ VALUE args[2] = { oneofdef, self->builder };
+ VALUE ctx = rb_class_new_instance(2, args, cOneofBuilderContext);
+ VALUE block = rb_block_proc();
+ VALUE name_str = rb_str_new2(rb_id2name(SYM2ID(name)));
+ rb_funcall(oneofdef, rb_intern("name="), 1, name_str);
+ rb_funcall_with_block(ctx, rb_intern("instance_eval"), 0, NULL, block);
+ Descriptor_add_oneof(self->descriptor, oneofdef);
+
+ return Qnil;
+}
+
+// -----------------------------------------------------------------------------
+// OneofBuilderContext.
+// -----------------------------------------------------------------------------
+
+DEFINE_CLASS(OneofBuilderContext,
+ "Google::Protobuf::Internal::OneofBuilderContext");
+
+void OneofBuilderContext_mark(void* _self) {
+ OneofBuilderContext* self = _self;
+ rb_gc_mark(self->descriptor);
+ rb_gc_mark(self->builder);
+}
+
+void OneofBuilderContext_free(void* _self) {
+ OneofBuilderContext* self = _self;
+ xfree(self);
+}
+
+VALUE OneofBuilderContext_alloc(VALUE klass) {
+ OneofBuilderContext* self = ALLOC(OneofBuilderContext);
+ VALUE ret = TypedData_Wrap_Struct(
+ klass, &_OneofBuilderContext_type, self);
+ self->descriptor = Qnil;
+ self->builder = Qnil;
+ return ret;
+}
+
+void OneofBuilderContext_register(VALUE module) {
+ VALUE klass = rb_define_class_under(
+ module, "OneofBuilderContext", rb_cObject);
+ rb_define_alloc_func(klass, OneofBuilderContext_alloc);
+ rb_define_method(klass, "initialize",
+ OneofBuilderContext_initialize, 2);
+ rb_define_method(klass, "optional", OneofBuilderContext_optional, -1);
+ cOneofBuilderContext = klass;
+ rb_gc_register_address(&cOneofBuilderContext);
+}
+
+/*
+ * call-seq:
+ * OneofBuilderContext.new(desc, builder) => context
+ *
+ * Create a new oneof builder context around the given oneof descriptor and
+ * builder context. This class is intended to serve as a DSL context to be used
+ * with #instance_eval.
+ */
+VALUE OneofBuilderContext_initialize(VALUE _self,
+ VALUE oneofdef,
+ VALUE builder) {
+ DEFINE_SELF(OneofBuilderContext, self, _self);
+ self->descriptor = oneofdef;
+ self->builder = builder;
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * OneofBuilderContext.optional(name, type, number, type_class = nil)
+ *
+ * Defines a new optional field in this oneof with the given type, tag number,
+ * and type class (for message and enum fields). The type must be a Ruby symbol
+ * (as accepted by FieldDescriptor#type=) and the type_class must be a string,
+ * if present (as accepted by FieldDescriptor#submsg_name=).
+ */
+VALUE OneofBuilderContext_optional(int argc, VALUE* argv, VALUE _self) {
+ DEFINE_SELF(OneofBuilderContext, self, _self);
+ VALUE name, type, number, type_class;
+
+ if (argc < 3) {
+ rb_raise(rb_eArgError, "Expected at least 3 arguments.");
+ }
+ name = argv[0];
+ type = argv[1];
+ number = argv[2];
+ type_class = (argc > 3) ? argv[3] : Qnil;
+
+ return msgdef_add_field(self->descriptor, "optional",
+ name, type, number, type_class);
+}
+
+// -----------------------------------------------------------------------------
+// EnumBuilderContext.
+// -----------------------------------------------------------------------------
+
+DEFINE_CLASS(EnumBuilderContext,
+ "Google::Protobuf::Internal::EnumBuilderContext");
+
+void EnumBuilderContext_mark(void* _self) {
+ EnumBuilderContext* self = _self;
+ rb_gc_mark(self->enumdesc);
+}
+
+void EnumBuilderContext_free(void* _self) {
+ EnumBuilderContext* self = _self;
+ xfree(self);
+}
+
+VALUE EnumBuilderContext_alloc(VALUE klass) {
+ EnumBuilderContext* self = ALLOC(EnumBuilderContext);
+ VALUE ret = TypedData_Wrap_Struct(
+ klass, &_EnumBuilderContext_type, self);
+ self->enumdesc = Qnil;
+ return ret;
+}
+
+void EnumBuilderContext_register(VALUE module) {
+ VALUE klass = rb_define_class_under(
+ module, "EnumBuilderContext", rb_cObject);
+ rb_define_alloc_func(klass, EnumBuilderContext_alloc);
+ rb_define_method(klass, "initialize",
+ EnumBuilderContext_initialize, 1);
+ rb_define_method(klass, "value", EnumBuilderContext_value, 2);
+ cEnumBuilderContext = klass;
+ rb_gc_register_address(&cEnumBuilderContext);
+}
+
+/*
+ * call-seq:
+ * EnumBuilderContext.new(enumdesc) => context
+ *
+ * Create a new builder context around the given enum descriptor. This class is
+ * intended to serve as a DSL context to be used with #instance_eval.
+ */
+VALUE EnumBuilderContext_initialize(VALUE _self, VALUE enumdef) {
+ DEFINE_SELF(EnumBuilderContext, self, _self);
+ self->enumdesc = enumdef;
+ return Qnil;
+}
+
+static VALUE enumdef_add_value(VALUE enumdef,
+ VALUE name, VALUE number) {
+ rb_funcall(enumdef, rb_intern("add_value"), 2, name, number);
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * EnumBuilder.add_value(name, number)
+ *
+ * Adds the given name => number mapping to the enum type. Name must be a Ruby
+ * symbol.
+ */
+VALUE EnumBuilderContext_value(VALUE _self, VALUE name, VALUE number) {
+ DEFINE_SELF(EnumBuilderContext, self, _self);
+ return enumdef_add_value(self->enumdesc, name, number);
+}
+
+// -----------------------------------------------------------------------------
+// Builder.
+// -----------------------------------------------------------------------------
+
+DEFINE_CLASS(Builder, "Google::Protobuf::Internal::Builder");
+
+void Builder_mark(void* _self) {
+ Builder* self = _self;
+ rb_gc_mark(self->pending_list);
+}
+
+void Builder_free(void* _self) {
+ Builder* self = _self;
+ xfree(self->defs);
+ xfree(self);
+}
+
+/*
+ * call-seq:
+ * Builder.new => builder
+ *
+ * Creates a new Builder. A Builder can accumulate a set of new message and enum
+ * descriptors and atomically register them into a pool in a way that allows for
+ * (co)recursive type references.
+ */
+VALUE Builder_alloc(VALUE klass) {
+ Builder* self = ALLOC(Builder);
+ VALUE ret = TypedData_Wrap_Struct(
+ klass, &_Builder_type, self);
+ self->pending_list = rb_ary_new();
+ self->defs = NULL;
+ return ret;
+}
+
+void Builder_register(VALUE module) {
+ VALUE klass = rb_define_class_under(module, "Builder", rb_cObject);
+ rb_define_alloc_func(klass, Builder_alloc);
+ rb_define_method(klass, "add_message", Builder_add_message, 1);
+ rb_define_method(klass, "add_enum", Builder_add_enum, 1);
+ rb_define_method(klass, "finalize_to_pool", Builder_finalize_to_pool, 1);
+ cBuilder = klass;
+ rb_gc_register_address(&cBuilder);
+}
+
+/*
+ * call-seq:
+ * Builder.add_message(name, &block)
+ *
+ * Creates a new, empty descriptor with the given name, and invokes the block in
+ * the context of a MessageBuilderContext on that descriptor. The block can then
+ * call, e.g., MessageBuilderContext#optional and MessageBuilderContext#repeated
+ * methods to define the message fields.
+ *
+ * This is the recommended, idiomatic way to build message definitions.
+ */
+VALUE Builder_add_message(VALUE _self, VALUE name) {
+ DEFINE_SELF(Builder, self, _self);
+ VALUE msgdef = rb_class_new_instance(0, NULL, cDescriptor);
+ VALUE args[2] = { msgdef, _self };
+ VALUE ctx = rb_class_new_instance(2, args, cMessageBuilderContext);
+ VALUE block = rb_block_proc();
+ rb_funcall(msgdef, rb_intern("name="), 1, name);
+ rb_funcall_with_block(ctx, rb_intern("instance_eval"), 0, NULL, block);
+ rb_ary_push(self->pending_list, msgdef);
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * Builder.add_enum(name, &block)
+ *
+ * Creates a new, empty enum descriptor with the given name, and invokes the
+ * block in the context of an EnumBuilderContext on that descriptor. The block
+ * can then call EnumBuilderContext#add_value to define the enum values.
+ *
+ * This is the recommended, idiomatic way to build enum definitions.
+ */
+VALUE Builder_add_enum(VALUE _self, VALUE name) {
+ DEFINE_SELF(Builder, self, _self);
+ VALUE enumdef = rb_class_new_instance(0, NULL, cEnumDescriptor);
+ VALUE ctx = rb_class_new_instance(1, &enumdef, cEnumBuilderContext);
+ VALUE block = rb_block_proc();
+ rb_funcall(enumdef, rb_intern("name="), 1, name);
+ rb_funcall_with_block(ctx, rb_intern("instance_eval"), 0, NULL, block);
+ rb_ary_push(self->pending_list, enumdef);
+ return Qnil;
+}
+
+static void validate_msgdef(const upb_msgdef* msgdef) {
+ // Verify that no required fields exist. proto3 does not support these.
+ upb_msg_field_iter it;
+ for (upb_msg_field_begin(&it, msgdef);
+ !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* field = upb_msg_iter_field(&it);
+ if (upb_fielddef_label(field) == UPB_LABEL_REQUIRED) {
+ rb_raise(rb_eTypeError, "Required fields are unsupported in proto3.");
+ }
+ }
+}
+
+static void validate_enumdef(const upb_enumdef* enumdef) {
+ // Verify that an entry exists with integer value 0. (This is the default
+ // value.)
+ const char* lookup = upb_enumdef_iton(enumdef, 0);
+ if (lookup == NULL) {
+ rb_raise(rb_eTypeError,
+ "Enum definition does not contain a value for '0'.");
+ }
+}
+
+/*
+ * call-seq:
+ * Builder.finalize_to_pool(pool)
+ *
+ * Adds all accumulated message and enum descriptors created in this builder
+ * context to the given pool. The operation occurs atomically, and all
+ * descriptors can refer to each other (including in cycles). This is the only
+ * way to build (co)recursive message definitions.
+ *
+ * This method is usually called automatically by DescriptorPool#build after it
+ * invokes the given user block in the context of the builder. The user should
+ * not normally need to call this manually because a Builder is not normally
+ * created manually.
+ */
+VALUE Builder_finalize_to_pool(VALUE _self, VALUE pool_rb) {
+ DEFINE_SELF(Builder, self, _self);
+
+ DescriptorPool* pool = ruby_to_DescriptorPool(pool_rb);
+
+ REALLOC_N(self->defs, upb_def*, RARRAY_LEN(self->pending_list));
+
+ for (int i = 0; i < RARRAY_LEN(self->pending_list); i++) {
+ VALUE def_rb = rb_ary_entry(self->pending_list, i);
+ if (CLASS_OF(def_rb) == cDescriptor) {
+ self->defs[i] = (upb_def*)ruby_to_Descriptor(def_rb)->msgdef;
+ validate_msgdef((const upb_msgdef*)self->defs[i]);
+ } else if (CLASS_OF(def_rb) == cEnumDescriptor) {
+ self->defs[i] = (upb_def*)ruby_to_EnumDescriptor(def_rb)->enumdef;
+ validate_enumdef((const upb_enumdef*)self->defs[i]);
+ }
+ }
+
+ CHECK_UPB(upb_symtab_add(pool->symtab, (upb_def**)self->defs,
+ RARRAY_LEN(self->pending_list), NULL, &status),
+ "Unable to add defs to DescriptorPool");
+
+ for (int i = 0; i < RARRAY_LEN(self->pending_list); i++) {
+ VALUE def_rb = rb_ary_entry(self->pending_list, i);
+ add_def_obj(self->defs[i], def_rb);
+ }
+
+ self->pending_list = rb_ary_new();
+ return Qnil;
+}
diff --git a/third_party/protobuf/ruby/ext/google/protobuf_c/encode_decode.c b/third_party/protobuf/ruby/ext/google/protobuf_c/encode_decode.c
new file mode 100644
index 0000000000..d86a1145d0
--- /dev/null
+++ b/third_party/protobuf/ruby/ext/google/protobuf_c/encode_decode.c
@@ -0,0 +1,1310 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 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 "protobuf.h"
+
+// This function is equivalent to rb_str_cat(), but unlike the real
+// rb_str_cat(), it doesn't leak memory in some versions of Ruby.
+// For more information, see:
+// https://bugs.ruby-lang.org/issues/11328
+VALUE noleak_rb_str_cat(VALUE rb_str, const char *str, long len) {
+ char *p;
+ size_t oldlen = RSTRING_LEN(rb_str);
+ rb_str_modify_expand(rb_str, len);
+ p = RSTRING_PTR(rb_str);
+ memcpy(p + oldlen, str, len);
+ rb_str_set_len(rb_str, oldlen + len);
+ return rb_str;
+}
+
+// -----------------------------------------------------------------------------
+// Parsing.
+// -----------------------------------------------------------------------------
+
+#define DEREF(msg, ofs, type) *(type*)(((uint8_t *)msg) + ofs)
+
+// Creates a handlerdata that simply contains the offset for this field.
+static const void* newhandlerdata(upb_handlers* h, uint32_t ofs) {
+ size_t* hd_ofs = ALLOC(size_t);
+ *hd_ofs = ofs;
+ upb_handlers_addcleanup(h, hd_ofs, xfree);
+ return hd_ofs;
+}
+
+typedef struct {
+ size_t ofs;
+ const upb_msgdef *md;
+} submsg_handlerdata_t;
+
+// Creates a handlerdata that contains offset and submessage type information.
+static const void *newsubmsghandlerdata(upb_handlers* h, uint32_t ofs,
+ const upb_fielddef* f) {
+ submsg_handlerdata_t *hd = ALLOC(submsg_handlerdata_t);
+ hd->ofs = ofs;
+ hd->md = upb_fielddef_msgsubdef(f);
+ upb_handlers_addcleanup(h, hd, xfree);
+ return hd;
+}
+
+typedef struct {
+ size_t ofs; // union data slot
+ size_t case_ofs; // oneof_case field
+ uint32_t oneof_case_num; // oneof-case number to place in oneof_case field
+ const upb_msgdef *md; // msgdef, for oneof submessage handler
+} oneof_handlerdata_t;
+
+static const void *newoneofhandlerdata(upb_handlers *h,
+ uint32_t ofs,
+ uint32_t case_ofs,
+ const upb_fielddef *f) {
+ oneof_handlerdata_t *hd = ALLOC(oneof_handlerdata_t);
+ hd->ofs = ofs;
+ hd->case_ofs = case_ofs;
+ // We reuse the field tag number as a oneof union discriminant tag. Note that
+ // we don't expose these numbers to the user, so the only requirement is that
+ // we have some unique ID for each union case/possibility. The field tag
+ // numbers are already present and are easy to use so there's no reason to
+ // create a separate ID space. In addition, using the field tag number here
+ // lets us easily look up the field in the oneof accessor.
+ hd->oneof_case_num = upb_fielddef_number(f);
+ if (upb_fielddef_type(f) == UPB_TYPE_MESSAGE) {
+ hd->md = upb_fielddef_msgsubdef(f);
+ } else {
+ hd->md = NULL;
+ }
+ upb_handlers_addcleanup(h, hd, xfree);
+ return hd;
+}
+
+// A handler that starts a repeated field. Gets the Repeated*Field instance for
+// this field (such an instance always exists even in an empty message).
+static void *startseq_handler(void* closure, const void* hd) {
+ MessageHeader* msg = closure;
+ const size_t *ofs = hd;
+ return (void*)DEREF(msg, *ofs, VALUE);
+}
+
+// Handlers that append primitive values to a repeated field.
+#define DEFINE_APPEND_HANDLER(type, ctype) \
+ static bool append##type##_handler(void *closure, const void *hd, \
+ ctype val) { \
+ VALUE ary = (VALUE)closure; \
+ RepeatedField_push_native(ary, &val); \
+ return true; \
+ }
+
+DEFINE_APPEND_HANDLER(bool, bool)
+DEFINE_APPEND_HANDLER(int32, int32_t)
+DEFINE_APPEND_HANDLER(uint32, uint32_t)
+DEFINE_APPEND_HANDLER(float, float)
+DEFINE_APPEND_HANDLER(int64, int64_t)
+DEFINE_APPEND_HANDLER(uint64, uint64_t)
+DEFINE_APPEND_HANDLER(double, double)
+
+// Appends a string to a repeated field.
+static void* appendstr_handler(void *closure,
+ const void *hd,
+ size_t size_hint) {
+ VALUE ary = (VALUE)closure;
+ VALUE str = rb_str_new2("");
+ rb_enc_associate(str, kRubyStringUtf8Encoding);
+ RepeatedField_push_native(ary, &str);
+ return (void*)str;
+}
+
+// Appends a 'bytes' string to a repeated field.
+static void* appendbytes_handler(void *closure,
+ const void *hd,
+ size_t size_hint) {
+ VALUE ary = (VALUE)closure;
+ VALUE str = rb_str_new2("");
+ rb_enc_associate(str, kRubyString8bitEncoding);
+ RepeatedField_push_native(ary, &str);
+ return (void*)str;
+}
+
+// Sets a non-repeated string field in a message.
+static void* str_handler(void *closure,
+ const void *hd,
+ size_t size_hint) {
+ MessageHeader* msg = closure;
+ const size_t *ofs = hd;
+ VALUE str = rb_str_new2("");
+ rb_enc_associate(str, kRubyStringUtf8Encoding);
+ DEREF(msg, *ofs, VALUE) = str;
+ return (void*)str;
+}
+
+// Sets a non-repeated 'bytes' field in a message.
+static void* bytes_handler(void *closure,
+ const void *hd,
+ size_t size_hint) {
+ MessageHeader* msg = closure;
+ const size_t *ofs = hd;
+ VALUE str = rb_str_new2("");
+ rb_enc_associate(str, kRubyString8bitEncoding);
+ DEREF(msg, *ofs, VALUE) = str;
+ return (void*)str;
+}
+
+static size_t stringdata_handler(void* closure, const void* hd,
+ const char* str, size_t len,
+ const upb_bufhandle* handle) {
+ VALUE rb_str = (VALUE)closure;
+ noleak_rb_str_cat(rb_str, str, len);
+ return len;
+}
+
+static bool stringdata_end_handler(void* closure, const void* hd) {
+ MessageHeader* msg = closure;
+ const size_t *ofs = hd;
+ VALUE rb_str = DEREF(msg, *ofs, VALUE);
+ rb_obj_freeze(rb_str);
+ return true;
+}
+
+static bool appendstring_end_handler(void* closure, const void* hd) {
+ VALUE ary = (VALUE)closure;
+ int size = RepeatedField_size(ary);
+ VALUE* last = RepeatedField_index_native(ary, size - 1);
+ VALUE rb_str = *last;
+ rb_obj_freeze(rb_str);
+ return true;
+}
+
+// Appends a submessage to a repeated field (a regular Ruby array for now).
+static void *appendsubmsg_handler(void *closure, const void *hd) {
+ VALUE ary = (VALUE)closure;
+ const submsg_handlerdata_t *submsgdata = hd;
+ VALUE subdesc =
+ get_def_obj((void*)submsgdata->md);
+ VALUE subklass = Descriptor_msgclass(subdesc);
+ MessageHeader* submsg;
+
+ VALUE submsg_rb = rb_class_new_instance(0, NULL, subklass);
+ RepeatedField_push(ary, submsg_rb);
+
+ TypedData_Get_Struct(submsg_rb, MessageHeader, &Message_type, submsg);
+ return submsg;
+}
+
+// Sets a non-repeated submessage field in a message.
+static void *submsg_handler(void *closure, const void *hd) {
+ MessageHeader* msg = closure;
+ const submsg_handlerdata_t* submsgdata = hd;
+ VALUE subdesc =
+ get_def_obj((void*)submsgdata->md);
+ VALUE subklass = Descriptor_msgclass(subdesc);
+ VALUE submsg_rb;
+ MessageHeader* submsg;
+
+ if (DEREF(msg, submsgdata->ofs, VALUE) == Qnil) {
+ DEREF(msg, submsgdata->ofs, VALUE) =
+ rb_class_new_instance(0, NULL, subklass);
+ }
+
+ submsg_rb = DEREF(msg, submsgdata->ofs, VALUE);
+ TypedData_Get_Struct(submsg_rb, MessageHeader, &Message_type, submsg);
+ return submsg;
+}
+
+// Handler data for startmap/endmap handlers.
+typedef struct {
+ size_t ofs;
+ upb_fieldtype_t key_field_type;
+ upb_fieldtype_t value_field_type;
+
+ // We know that we can hold this reference because the handlerdata has the
+ // same lifetime as the upb_handlers struct, and the upb_handlers struct holds
+ // a reference to the upb_msgdef, which in turn has references to its subdefs.
+ const upb_def* value_field_subdef;
+} map_handlerdata_t;
+
+// Temporary frame for map parsing: at the beginning of a map entry message, a
+// submsg handler allocates a frame to hold (i) a reference to the Map object
+// into which this message will be inserted and (ii) storage slots to
+// temporarily hold the key and value for this map entry until the end of the
+// submessage. When the submessage ends, another handler is called to insert the
+// value into the map.
+typedef struct {
+ VALUE map;
+ const map_handlerdata_t* handlerdata;
+ char key_storage[NATIVE_SLOT_MAX_SIZE];
+ char value_storage[NATIVE_SLOT_MAX_SIZE];
+} map_parse_frame_t;
+
+static void MapParseFrame_mark(void* _self) {
+ map_parse_frame_t* frame = _self;
+
+ // This shouldn't strictly be necessary since this should be rooted by the
+ // message itself, but it can't hurt.
+ rb_gc_mark(frame->map);
+
+ native_slot_mark(frame->handlerdata->key_field_type, &frame->key_storage);
+ native_slot_mark(frame->handlerdata->value_field_type, &frame->value_storage);
+}
+
+void MapParseFrame_free(void* self) {
+ xfree(self);
+}
+
+rb_data_type_t MapParseFrame_type = {
+ "MapParseFrame",
+ { MapParseFrame_mark, MapParseFrame_free, NULL },
+};
+
+// Array of Ruby objects wrapping map_parse_frame_t.
+// We don't allow multiple concurrent decodes, so we assume that this global
+// variable is specific to the "current" decode.
+VALUE map_parse_frames;
+
+static map_parse_frame_t* map_push_frame(VALUE map,
+ const map_handlerdata_t* handlerdata) {
+ map_parse_frame_t* frame = ALLOC(map_parse_frame_t);
+ frame->handlerdata = handlerdata;
+ frame->map = map;
+ native_slot_init(handlerdata->key_field_type, &frame->key_storage);
+ native_slot_init(handlerdata->value_field_type, &frame->value_storage);
+
+ rb_ary_push(map_parse_frames,
+ TypedData_Wrap_Struct(rb_cObject, &MapParseFrame_type, frame));
+
+ return frame;
+}
+
+static void map_pop_frame() {
+ rb_ary_pop(map_parse_frames);
+}
+
+// Handler to begin a map entry: allocates a temporary frame. This is the
+// 'startsubmsg' handler on the msgdef that contains the map field.
+static void *startmapentry_handler(void *closure, const void *hd) {
+ MessageHeader* msg = closure;
+ const map_handlerdata_t* mapdata = hd;
+ VALUE map_rb = DEREF(msg, mapdata->ofs, VALUE);
+
+ return map_push_frame(map_rb, mapdata);
+}
+
+// Handler to end a map entry: inserts the value defined during the message into
+// the map. This is the 'endmsg' handler on the map entry msgdef.
+static bool endmap_handler(void *closure, const void *hd, upb_status* s) {
+ map_parse_frame_t* frame = closure;
+ const map_handlerdata_t* mapdata = hd;
+
+ VALUE key = native_slot_get(
+ mapdata->key_field_type, Qnil,
+ &frame->key_storage);
+
+ VALUE value_field_typeclass = Qnil;
+ VALUE value;
+
+ if (mapdata->value_field_type == UPB_TYPE_MESSAGE ||
+ mapdata->value_field_type == UPB_TYPE_ENUM) {
+ value_field_typeclass = get_def_obj(mapdata->value_field_subdef);
+ }
+
+ value = native_slot_get(
+ mapdata->value_field_type, value_field_typeclass,
+ &frame->value_storage);
+
+ Map_index_set(frame->map, key, value);
+ map_pop_frame();
+
+ return true;
+}
+
+// Allocates a new map_handlerdata_t given the map entry message definition. If
+// the offset of the field within the parent message is also given, that is
+// added to the handler data as well. Note that this is called *twice* per map
+// field: once in the parent message handler setup when setting the startsubmsg
+// handler and once in the map entry message handler setup when setting the
+// key/value and endmsg handlers. The reason is that there is no easy way to
+// pass the handlerdata down to the sub-message handler setup.
+static map_handlerdata_t* new_map_handlerdata(
+ size_t ofs,
+ const upb_msgdef* mapentry_def,
+ Descriptor* desc) {
+ const upb_fielddef* key_field;
+ const upb_fielddef* value_field;
+ map_handlerdata_t* hd = ALLOC(map_handlerdata_t);
+ hd->ofs = ofs;
+ key_field = upb_msgdef_itof(mapentry_def, MAP_KEY_FIELD);
+ assert(key_field != NULL);
+ hd->key_field_type = upb_fielddef_type(key_field);
+ value_field = upb_msgdef_itof(mapentry_def, MAP_VALUE_FIELD);
+ assert(value_field != NULL);
+ hd->value_field_type = upb_fielddef_type(value_field);
+ hd->value_field_subdef = upb_fielddef_subdef(value_field);
+
+ return hd;
+}
+
+// Handlers that set primitive values in oneofs.
+#define DEFINE_ONEOF_HANDLER(type, ctype) \
+ static bool oneof##type##_handler(void *closure, const void *hd, \
+ ctype val) { \
+ const oneof_handlerdata_t *oneofdata = hd; \
+ DEREF(closure, oneofdata->case_ofs, uint32_t) = \
+ oneofdata->oneof_case_num; \
+ DEREF(closure, oneofdata->ofs, ctype) = val; \
+ return true; \
+ }
+
+DEFINE_ONEOF_HANDLER(bool, bool)
+DEFINE_ONEOF_HANDLER(int32, int32_t)
+DEFINE_ONEOF_HANDLER(uint32, uint32_t)
+DEFINE_ONEOF_HANDLER(float, float)
+DEFINE_ONEOF_HANDLER(int64, int64_t)
+DEFINE_ONEOF_HANDLER(uint64, uint64_t)
+DEFINE_ONEOF_HANDLER(double, double)
+
+#undef DEFINE_ONEOF_HANDLER
+
+// Handlers for strings in a oneof.
+static void *oneofstr_handler(void *closure,
+ const void *hd,
+ size_t size_hint) {
+ MessageHeader* msg = closure;
+ const oneof_handlerdata_t *oneofdata = hd;
+ VALUE str = rb_str_new2("");
+ rb_enc_associate(str, kRubyStringUtf8Encoding);
+ DEREF(msg, oneofdata->case_ofs, uint32_t) =
+ oneofdata->oneof_case_num;
+ DEREF(msg, oneofdata->ofs, VALUE) = str;
+ return (void*)str;
+}
+
+static void *oneofbytes_handler(void *closure,
+ const void *hd,
+ size_t size_hint) {
+ MessageHeader* msg = closure;
+ const oneof_handlerdata_t *oneofdata = hd;
+ VALUE str = rb_str_new2("");
+ rb_enc_associate(str, kRubyString8bitEncoding);
+ DEREF(msg, oneofdata->case_ofs, uint32_t) =
+ oneofdata->oneof_case_num;
+ DEREF(msg, oneofdata->ofs, VALUE) = str;
+ return (void*)str;
+}
+
+static bool oneofstring_end_handler(void* closure, const void* hd) {
+ MessageHeader* msg = closure;
+ const oneof_handlerdata_t *oneofdata = hd;
+ rb_obj_freeze(DEREF(msg, oneofdata->ofs, VALUE));
+ return true;
+}
+
+// Handler for a submessage field in a oneof.
+static void *oneofsubmsg_handler(void *closure,
+ const void *hd) {
+ MessageHeader* msg = closure;
+ const oneof_handlerdata_t *oneofdata = hd;
+ uint32_t oldcase = DEREF(msg, oneofdata->case_ofs, uint32_t);
+
+ VALUE subdesc =
+ get_def_obj((void*)oneofdata->md);
+ VALUE subklass = Descriptor_msgclass(subdesc);
+ VALUE submsg_rb;
+ MessageHeader* submsg;
+
+ if (oldcase != oneofdata->oneof_case_num ||
+ DEREF(msg, oneofdata->ofs, VALUE) == Qnil) {
+ DEREF(msg, oneofdata->ofs, VALUE) =
+ rb_class_new_instance(0, NULL, subklass);
+ }
+ // Set the oneof case *after* allocating the new class instance -- otherwise,
+ // if the Ruby GC is invoked as part of a call into the VM, it might invoke
+ // our mark routines, and our mark routines might see the case value
+ // indicating a VALUE is present and expect a valid VALUE. See comment in
+ // layout_set() for more detail: basically, the change to the value and the
+ // case must be atomic w.r.t. the Ruby VM.
+ DEREF(msg, oneofdata->case_ofs, uint32_t) =
+ oneofdata->oneof_case_num;
+
+ submsg_rb = DEREF(msg, oneofdata->ofs, VALUE);
+ TypedData_Get_Struct(submsg_rb, MessageHeader, &Message_type, submsg);
+ return submsg;
+}
+
+// Set up handlers for a repeated field.
+static void add_handlers_for_repeated_field(upb_handlers *h,
+ const upb_fielddef *f,
+ size_t offset) {
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_handlerattr_sethandlerdata(&attr, newhandlerdata(h, offset));
+ upb_handlers_setstartseq(h, f, startseq_handler, &attr);
+ upb_handlerattr_uninit(&attr);
+
+ switch (upb_fielddef_type(f)) {
+
+#define SET_HANDLER(utype, ltype) \
+ case utype: \
+ upb_handlers_set##ltype(h, f, append##ltype##_handler, NULL); \
+ break;
+
+ SET_HANDLER(UPB_TYPE_BOOL, bool);
+ SET_HANDLER(UPB_TYPE_INT32, int32);
+ SET_HANDLER(UPB_TYPE_UINT32, uint32);
+ SET_HANDLER(UPB_TYPE_ENUM, int32);
+ SET_HANDLER(UPB_TYPE_FLOAT, float);
+ SET_HANDLER(UPB_TYPE_INT64, int64);
+ SET_HANDLER(UPB_TYPE_UINT64, uint64);
+ SET_HANDLER(UPB_TYPE_DOUBLE, double);
+
+#undef SET_HANDLER
+
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ bool is_bytes = upb_fielddef_type(f) == UPB_TYPE_BYTES;
+ upb_handlers_setstartstr(h, f, is_bytes ?
+ appendbytes_handler : appendstr_handler,
+ NULL);
+ upb_handlers_setstring(h, f, stringdata_handler, NULL);
+ upb_handlers_setendstr(h, f, appendstring_end_handler, NULL);
+ break;
+ }
+ case UPB_TYPE_MESSAGE: {
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_handlerattr_sethandlerdata(&attr, newsubmsghandlerdata(h, 0, f));
+ upb_handlers_setstartsubmsg(h, f, appendsubmsg_handler, &attr);
+ upb_handlerattr_uninit(&attr);
+ break;
+ }
+ }
+}
+
+// Set up handlers for a singular field.
+static void add_handlers_for_singular_field(upb_handlers *h,
+ const upb_fielddef *f,
+ size_t offset) {
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_BOOL:
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_FLOAT:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT64:
+ case UPB_TYPE_DOUBLE:
+ upb_msg_setscalarhandler(h, f, offset, -1);
+ break;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ bool is_bytes = upb_fielddef_type(f) == UPB_TYPE_BYTES;
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_handlerattr_sethandlerdata(&attr, newhandlerdata(h, offset));
+ upb_handlers_setstartstr(h, f,
+ is_bytes ? bytes_handler : str_handler,
+ &attr);
+ upb_handlers_setstring(h, f, stringdata_handler, &attr);
+ upb_handlers_setendstr(h, f, stringdata_end_handler, &attr);
+ upb_handlerattr_uninit(&attr);
+ break;
+ }
+ case UPB_TYPE_MESSAGE: {
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_handlerattr_sethandlerdata(&attr, newsubmsghandlerdata(h, offset, f));
+ upb_handlers_setstartsubmsg(h, f, submsg_handler, &attr);
+ upb_handlerattr_uninit(&attr);
+ break;
+ }
+ }
+}
+
+// Adds handlers to a map field.
+static void add_handlers_for_mapfield(upb_handlers* h,
+ const upb_fielddef* fielddef,
+ size_t offset,
+ Descriptor* desc) {
+ const upb_msgdef* map_msgdef = upb_fielddef_msgsubdef(fielddef);
+ map_handlerdata_t* hd = new_map_handlerdata(offset, map_msgdef, desc);
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+
+ upb_handlers_addcleanup(h, hd, xfree);
+ upb_handlerattr_sethandlerdata(&attr, hd);
+ upb_handlers_setstartsubmsg(h, fielddef, startmapentry_handler, &attr);
+ upb_handlerattr_uninit(&attr);
+}
+
+// Adds handlers to a map-entry msgdef.
+static void add_handlers_for_mapentry(const upb_msgdef* msgdef,
+ upb_handlers* h,
+ Descriptor* desc) {
+ const upb_fielddef* key_field = map_entry_key(msgdef);
+ const upb_fielddef* value_field = map_entry_value(msgdef);
+ map_handlerdata_t* hd = new_map_handlerdata(0, msgdef, desc);
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+
+ upb_handlers_addcleanup(h, hd, xfree);
+ upb_handlerattr_sethandlerdata(&attr, hd);
+ upb_handlers_setendmsg(h, endmap_handler, &attr);
+
+ add_handlers_for_singular_field(
+ h, key_field,
+ offsetof(map_parse_frame_t, key_storage));
+ add_handlers_for_singular_field(
+ h, value_field,
+ offsetof(map_parse_frame_t, value_storage));
+}
+
+// Set up handlers for a oneof field.
+static void add_handlers_for_oneof_field(upb_handlers *h,
+ const upb_fielddef *f,
+ size_t offset,
+ size_t oneof_case_offset) {
+
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_handlerattr_sethandlerdata(
+ &attr, newoneofhandlerdata(h, offset, oneof_case_offset, f));
+
+ switch (upb_fielddef_type(f)) {
+
+#define SET_HANDLER(utype, ltype) \
+ case utype: \
+ upb_handlers_set##ltype(h, f, oneof##ltype##_handler, &attr); \
+ break;
+
+ SET_HANDLER(UPB_TYPE_BOOL, bool);
+ SET_HANDLER(UPB_TYPE_INT32, int32);
+ SET_HANDLER(UPB_TYPE_UINT32, uint32);
+ SET_HANDLER(UPB_TYPE_ENUM, int32);
+ SET_HANDLER(UPB_TYPE_FLOAT, float);
+ SET_HANDLER(UPB_TYPE_INT64, int64);
+ SET_HANDLER(UPB_TYPE_UINT64, uint64);
+ SET_HANDLER(UPB_TYPE_DOUBLE, double);
+
+#undef SET_HANDLER
+
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ bool is_bytes = upb_fielddef_type(f) == UPB_TYPE_BYTES;
+ upb_handlers_setstartstr(h, f, is_bytes ?
+ oneofbytes_handler : oneofstr_handler,
+ &attr);
+ upb_handlers_setstring(h, f, stringdata_handler, NULL);
+ upb_handlers_setendstr(h, f, oneofstring_end_handler, &attr);
+ break;
+ }
+ case UPB_TYPE_MESSAGE: {
+ upb_handlers_setstartsubmsg(h, f, oneofsubmsg_handler, &attr);
+ break;
+ }
+ }
+
+ upb_handlerattr_uninit(&attr);
+}
+
+
+static void add_handlers_for_message(const void *closure, upb_handlers *h) {
+ const upb_msgdef* msgdef = upb_handlers_msgdef(h);
+ Descriptor* desc = ruby_to_Descriptor(get_def_obj((void*)msgdef));
+ upb_msg_field_iter i;
+
+ // If this is a mapentry message type, set up a special set of handlers and
+ // bail out of the normal (user-defined) message type handling.
+ if (upb_msgdef_mapentry(msgdef)) {
+ add_handlers_for_mapentry(msgdef, h, desc);
+ return;
+ }
+
+ // Ensure layout exists. We may be invoked to create handlers for a given
+ // message if we are included as a submsg of another message type before our
+ // class is actually built, so to work around this, we just create the layout
+ // (and handlers, in the class-building function) on-demand.
+ if (desc->layout == NULL) {
+ desc->layout = create_layout(desc->msgdef);
+ }
+
+ for (upb_msg_field_begin(&i, desc->msgdef);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ const upb_fielddef *f = upb_msg_iter_field(&i);
+ size_t offset = desc->layout->fields[upb_fielddef_index(f)].offset +
+ sizeof(MessageHeader);
+
+ if (upb_fielddef_containingoneof(f)) {
+ size_t oneof_case_offset =
+ desc->layout->fields[upb_fielddef_index(f)].case_offset +
+ sizeof(MessageHeader);
+ add_handlers_for_oneof_field(h, f, offset, oneof_case_offset);
+ } else if (is_map_field(f)) {
+ add_handlers_for_mapfield(h, f, offset, desc);
+ } else if (upb_fielddef_isseq(f)) {
+ add_handlers_for_repeated_field(h, f, offset);
+ } else {
+ add_handlers_for_singular_field(h, f, offset);
+ }
+ }
+}
+
+// Creates upb handlers for populating a message.
+static const upb_handlers *new_fill_handlers(Descriptor* desc,
+ const void* owner) {
+ // TODO(cfallin, haberman): once upb gets a caching/memoization layer for
+ // handlers, reuse subdef handlers so that e.g. if we already parse
+ // B-with-field-of-type-C, we don't have to rebuild the whole hierarchy to
+ // parse A-with-field-of-type-B-with-field-of-type-C.
+ return upb_handlers_newfrozen(desc->msgdef, owner,
+ add_handlers_for_message, NULL);
+}
+
+// Constructs the handlers for filling a message's data into an in-memory
+// object.
+const upb_handlers* get_fill_handlers(Descriptor* desc) {
+ if (!desc->fill_handlers) {
+ desc->fill_handlers =
+ new_fill_handlers(desc, &desc->fill_handlers);
+ }
+ return desc->fill_handlers;
+}
+
+// Constructs the upb decoder method for parsing messages of this type.
+// This is called from the message class creation code.
+const upb_pbdecodermethod *new_fillmsg_decodermethod(Descriptor* desc,
+ const void* owner) {
+ const upb_handlers* handlers = get_fill_handlers(desc);
+ upb_pbdecodermethodopts opts;
+ upb_pbdecodermethodopts_init(&opts, handlers);
+
+ return upb_pbdecodermethod_new(&opts, owner);
+}
+
+static const upb_pbdecodermethod *msgdef_decodermethod(Descriptor* desc) {
+ if (desc->fill_method == NULL) {
+ desc->fill_method = new_fillmsg_decodermethod(
+ desc, &desc->fill_method);
+ }
+ return desc->fill_method;
+}
+
+static const upb_json_parsermethod *msgdef_jsonparsermethod(Descriptor* desc) {
+ if (desc->json_fill_method == NULL) {
+ desc->json_fill_method =
+ upb_json_parsermethod_new(desc->msgdef, &desc->json_fill_method);
+ }
+ return desc->json_fill_method;
+}
+
+
+// Stack-allocated context during an encode/decode operation. Contains the upb
+// environment and its stack-based allocator, an initial buffer for allocations
+// to avoid malloc() when possible, and a template for Ruby exception messages
+// if any error occurs.
+#define STACK_ENV_STACKBYTES 4096
+typedef struct {
+ upb_env env;
+ const char* ruby_error_template;
+ char allocbuf[STACK_ENV_STACKBYTES];
+} stackenv;
+
+static void stackenv_init(stackenv* se, const char* errmsg);
+static void stackenv_uninit(stackenv* se);
+
+// Callback invoked by upb if any error occurs during parsing or serialization.
+static bool env_error_func(void* ud, const upb_status* status) {
+ stackenv* se = ud;
+ // Free the env -- rb_raise will longjmp up the stack past the encode/decode
+ // function so it would not otherwise have been freed.
+ stackenv_uninit(se);
+
+ // TODO(haberman): have a way to verify that this is actually a parse error,
+ // instead of just throwing "parse error" unconditionally.
+ rb_raise(cParseError, se->ruby_error_template, upb_status_errmsg(status));
+ // Never reached: rb_raise() always longjmp()s up the stack, past all of our
+ // code, back to Ruby.
+ return false;
+}
+
+static void stackenv_init(stackenv* se, const char* errmsg) {
+ se->ruby_error_template = errmsg;
+ upb_env_init2(&se->env, se->allocbuf, sizeof(se->allocbuf), NULL);
+ upb_env_seterrorfunc(&se->env, env_error_func, se);
+}
+
+static void stackenv_uninit(stackenv* se) {
+ upb_env_uninit(&se->env);
+}
+
+/*
+ * call-seq:
+ * MessageClass.decode(data) => message
+ *
+ * Decodes the given data (as a string containing bytes in protocol buffers wire
+ * format) under the interpretration given by this message class's definition
+ * and returns a message object with the corresponding field values.
+ */
+VALUE Message_decode(VALUE klass, VALUE data) {
+ VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned);
+ Descriptor* desc = ruby_to_Descriptor(descriptor);
+ VALUE msgklass = Descriptor_msgclass(descriptor);
+ VALUE msg_rb;
+ MessageHeader* msg;
+
+ if (TYPE(data) != T_STRING) {
+ rb_raise(rb_eArgError, "Expected string for binary protobuf data.");
+ }
+
+ msg_rb = rb_class_new_instance(0, NULL, msgklass);
+ TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg);
+
+ // We generally expect this to be clear already, but clear it in case parsing
+ // previously got interrupted somehow.
+ rb_ary_clear(map_parse_frames);
+
+ {
+ const upb_pbdecodermethod* method = msgdef_decodermethod(desc);
+ const upb_handlers* h = upb_pbdecodermethod_desthandlers(method);
+ stackenv se;
+ upb_sink sink;
+ upb_pbdecoder* decoder;
+ stackenv_init(&se, "Error occurred during parsing: %s");
+
+ upb_sink_reset(&sink, h, msg);
+ decoder = upb_pbdecoder_create(&se.env, method, &sink);
+ upb_bufsrc_putbuf(RSTRING_PTR(data), RSTRING_LEN(data),
+ upb_pbdecoder_input(decoder));
+
+ stackenv_uninit(&se);
+ }
+
+ return msg_rb;
+}
+
+/*
+ * call-seq:
+ * MessageClass.decode_json(data) => message
+ *
+ * Decodes the given data (as a string containing bytes in protocol buffers wire
+ * format) under the interpretration given by this message class's definition
+ * and returns a message object with the corresponding field values.
+ */
+VALUE Message_decode_json(VALUE klass, VALUE data) {
+ VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned);
+ Descriptor* desc = ruby_to_Descriptor(descriptor);
+ VALUE msgklass = Descriptor_msgclass(descriptor);
+ VALUE msg_rb;
+ MessageHeader* msg;
+
+ if (TYPE(data) != T_STRING) {
+ rb_raise(rb_eArgError, "Expected string for JSON data.");
+ }
+ // TODO(cfallin): Check and respect string encoding. If not UTF-8, we need to
+ // convert, because string handlers pass data directly to message string
+ // fields.
+
+ msg_rb = rb_class_new_instance(0, NULL, msgklass);
+ TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg);
+
+ // We generally expect this to be clear already, but clear it in case parsing
+ // previously got interrupted somehow.
+ rb_ary_clear(map_parse_frames);
+
+ {
+ const upb_json_parsermethod* method = msgdef_jsonparsermethod(desc);
+ stackenv se;
+ upb_sink sink;
+ upb_json_parser* parser;
+ stackenv_init(&se, "Error occurred during parsing: %s");
+
+ upb_sink_reset(&sink, get_fill_handlers(desc), msg);
+ parser = upb_json_parser_create(&se.env, method, &sink);
+ upb_bufsrc_putbuf(RSTRING_PTR(data), RSTRING_LEN(data),
+ upb_json_parser_input(parser));
+
+ stackenv_uninit(&se);
+ }
+
+ return msg_rb;
+}
+
+// -----------------------------------------------------------------------------
+// Serializing.
+// -----------------------------------------------------------------------------
+//
+// The code below also comes from upb's prototype Ruby binding, developed by
+// haberman@.
+
+/* stringsink *****************************************************************/
+
+// This should probably be factored into a common upb component.
+
+typedef struct {
+ upb_byteshandler handler;
+ upb_bytessink sink;
+ char *ptr;
+ size_t len, size;
+} stringsink;
+
+static void *stringsink_start(void *_sink, const void *hd, size_t size_hint) {
+ stringsink *sink = _sink;
+ sink->len = 0;
+ return sink;
+}
+
+static size_t stringsink_string(void *_sink, const void *hd, const char *ptr,
+ size_t len, const upb_bufhandle *handle) {
+ stringsink *sink = _sink;
+ size_t new_size = sink->size;
+
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ while (sink->len + len > new_size) {
+ new_size *= 2;
+ }
+
+ if (new_size != sink->size) {
+ sink->ptr = realloc(sink->ptr, new_size);
+ sink->size = new_size;
+ }
+
+ memcpy(sink->ptr + sink->len, ptr, len);
+ sink->len += len;
+
+ return len;
+}
+
+void stringsink_init(stringsink *sink) {
+ upb_byteshandler_init(&sink->handler);
+ upb_byteshandler_setstartstr(&sink->handler, stringsink_start, NULL);
+ upb_byteshandler_setstring(&sink->handler, stringsink_string, NULL);
+
+ upb_bytessink_reset(&sink->sink, &sink->handler, sink);
+
+ sink->size = 32;
+ sink->ptr = malloc(sink->size);
+ sink->len = 0;
+}
+
+void stringsink_uninit(stringsink *sink) {
+ free(sink->ptr);
+}
+
+/* msgvisitor *****************************************************************/
+
+// TODO: If/when we support proto2 semantics in addition to the current proto3
+// semantics, which means that we have true field presence, we will want to
+// modify msgvisitor so that it emits all present fields rather than all
+// non-default-value fields.
+//
+// Likewise, when implementing JSON serialization, we may need to have a
+// 'verbose' mode that outputs all fields and a 'concise' mode that outputs only
+// those with non-default values.
+
+static void putmsg(VALUE msg, const Descriptor* desc,
+ upb_sink *sink, int depth);
+
+static upb_selector_t getsel(const upb_fielddef *f, upb_handlertype_t type) {
+ upb_selector_t ret;
+ bool ok = upb_handlers_getselector(f, type, &ret);
+ UPB_ASSERT(ok);
+ return ret;
+}
+
+static void putstr(VALUE str, const upb_fielddef *f, upb_sink *sink) {
+ upb_sink subsink;
+
+ if (str == Qnil) return;
+
+ assert(BUILTIN_TYPE(str) == RUBY_T_STRING);
+
+ // We should be guaranteed that the string has the correct encoding because
+ // we ensured this at assignment time and then froze the string.
+ if (upb_fielddef_type(f) == UPB_TYPE_STRING) {
+ assert(rb_enc_from_index(ENCODING_GET(str)) == kRubyStringUtf8Encoding);
+ } else {
+ assert(rb_enc_from_index(ENCODING_GET(str)) == kRubyString8bitEncoding);
+ }
+
+ upb_sink_startstr(sink, getsel(f, UPB_HANDLER_STARTSTR), RSTRING_LEN(str),
+ &subsink);
+ upb_sink_putstring(&subsink, getsel(f, UPB_HANDLER_STRING), RSTRING_PTR(str),
+ RSTRING_LEN(str), NULL);
+ upb_sink_endstr(sink, getsel(f, UPB_HANDLER_ENDSTR));
+}
+
+static void putsubmsg(VALUE submsg, const upb_fielddef *f, upb_sink *sink,
+ int depth) {
+ upb_sink subsink;
+ VALUE descriptor;
+ Descriptor* subdesc;
+
+ if (submsg == Qnil) return;
+
+ descriptor = rb_ivar_get(submsg, descriptor_instancevar_interned);
+ subdesc = ruby_to_Descriptor(descriptor);
+
+ upb_sink_startsubmsg(sink, getsel(f, UPB_HANDLER_STARTSUBMSG), &subsink);
+ putmsg(submsg, subdesc, &subsink, depth + 1);
+ upb_sink_endsubmsg(sink, getsel(f, UPB_HANDLER_ENDSUBMSG));
+}
+
+static void putary(VALUE ary, const upb_fielddef *f, upb_sink *sink,
+ int depth) {
+ upb_sink subsink;
+ upb_fieldtype_t type = upb_fielddef_type(f);
+ upb_selector_t sel = 0;
+ int size;
+
+ if (ary == Qnil) return;
+
+ upb_sink_startseq(sink, getsel(f, UPB_HANDLER_STARTSEQ), &subsink);
+
+ if (upb_fielddef_isprimitive(f)) {
+ sel = getsel(f, upb_handlers_getprimitivehandlertype(f));
+ }
+
+ size = NUM2INT(RepeatedField_length(ary));
+ for (int i = 0; i < size; i++) {
+ void* memory = RepeatedField_index_native(ary, i);
+ switch (type) {
+#define T(upbtypeconst, upbtype, ctype) \
+ case upbtypeconst: \
+ upb_sink_put##upbtype(&subsink, sel, *((ctype *)memory)); \
+ break;
+
+ T(UPB_TYPE_FLOAT, float, float)
+ T(UPB_TYPE_DOUBLE, double, double)
+ T(UPB_TYPE_BOOL, bool, int8_t)
+ case UPB_TYPE_ENUM:
+ T(UPB_TYPE_INT32, int32, int32_t)
+ T(UPB_TYPE_UINT32, uint32, uint32_t)
+ T(UPB_TYPE_INT64, int64, int64_t)
+ T(UPB_TYPE_UINT64, uint64, uint64_t)
+
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ putstr(*((VALUE *)memory), f, &subsink);
+ break;
+ case UPB_TYPE_MESSAGE:
+ putsubmsg(*((VALUE *)memory), f, &subsink, depth);
+ break;
+
+#undef T
+
+ }
+ }
+ upb_sink_endseq(sink, getsel(f, UPB_HANDLER_ENDSEQ));
+}
+
+static void put_ruby_value(VALUE value,
+ const upb_fielddef *f,
+ VALUE type_class,
+ int depth,
+ upb_sink *sink) {
+ upb_selector_t sel = 0;
+ if (upb_fielddef_isprimitive(f)) {
+ sel = getsel(f, upb_handlers_getprimitivehandlertype(f));
+ }
+
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_INT32:
+ upb_sink_putint32(sink, sel, NUM2INT(value));
+ break;
+ case UPB_TYPE_INT64:
+ upb_sink_putint64(sink, sel, NUM2LL(value));
+ break;
+ case UPB_TYPE_UINT32:
+ upb_sink_putuint32(sink, sel, NUM2UINT(value));
+ break;
+ case UPB_TYPE_UINT64:
+ upb_sink_putuint64(sink, sel, NUM2ULL(value));
+ break;
+ case UPB_TYPE_FLOAT:
+ upb_sink_putfloat(sink, sel, NUM2DBL(value));
+ break;
+ case UPB_TYPE_DOUBLE:
+ upb_sink_putdouble(sink, sel, NUM2DBL(value));
+ break;
+ case UPB_TYPE_ENUM: {
+ if (TYPE(value) == T_SYMBOL) {
+ value = rb_funcall(type_class, rb_intern("resolve"), 1, value);
+ }
+ upb_sink_putint32(sink, sel, NUM2INT(value));
+ break;
+ }
+ case UPB_TYPE_BOOL:
+ upb_sink_putbool(sink, sel, value == Qtrue);
+ break;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ putstr(value, f, sink);
+ break;
+ case UPB_TYPE_MESSAGE:
+ putsubmsg(value, f, sink, depth);
+ }
+}
+
+static void putmap(VALUE map, const upb_fielddef *f, upb_sink *sink,
+ int depth) {
+ Map* self;
+ upb_sink subsink;
+ const upb_fielddef* key_field;
+ const upb_fielddef* value_field;
+ Map_iter it;
+
+ if (map == Qnil) return;
+ self = ruby_to_Map(map);
+
+ upb_sink_startseq(sink, getsel(f, UPB_HANDLER_STARTSEQ), &subsink);
+
+ assert(upb_fielddef_type(f) == UPB_TYPE_MESSAGE);
+ key_field = map_field_key(f);
+ value_field = map_field_value(f);
+
+ for (Map_begin(map, &it); !Map_done(&it); Map_next(&it)) {
+ VALUE key = Map_iter_key(&it);
+ VALUE value = Map_iter_value(&it);
+ upb_status status;
+
+ upb_sink entry_sink;
+ upb_sink_startsubmsg(&subsink, getsel(f, UPB_HANDLER_STARTSUBMSG),
+ &entry_sink);
+ upb_sink_startmsg(&entry_sink);
+
+ put_ruby_value(key, key_field, Qnil, depth + 1, &entry_sink);
+ put_ruby_value(value, value_field, self->value_type_class, depth + 1,
+ &entry_sink);
+
+ upb_sink_endmsg(&entry_sink, &status);
+ upb_sink_endsubmsg(&subsink, getsel(f, UPB_HANDLER_ENDSUBMSG));
+ }
+
+ upb_sink_endseq(sink, getsel(f, UPB_HANDLER_ENDSEQ));
+}
+
+static void putmsg(VALUE msg_rb, const Descriptor* desc,
+ upb_sink *sink, int depth) {
+ MessageHeader* msg;
+ upb_msg_field_iter i;
+ upb_status status;
+
+ upb_sink_startmsg(sink);
+
+ // Protect against cycles (possible because users may freely reassign message
+ // and repeated fields) by imposing a maximum recursion depth.
+ if (depth > ENCODE_MAX_NESTING) {
+ rb_raise(rb_eRuntimeError,
+ "Maximum recursion depth exceeded during encoding.");
+ }
+
+ TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg);
+
+ for (upb_msg_field_begin(&i, desc->msgdef);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ upb_fielddef *f = upb_msg_iter_field(&i);
+ bool is_matching_oneof = false;
+ uint32_t offset =
+ desc->layout->fields[upb_fielddef_index(f)].offset +
+ sizeof(MessageHeader);
+
+ if (upb_fielddef_containingoneof(f)) {
+ uint32_t oneof_case_offset =
+ desc->layout->fields[upb_fielddef_index(f)].case_offset +
+ sizeof(MessageHeader);
+ // For a oneof, check that this field is actually present -- skip all the
+ // below if not.
+ if (DEREF(msg, oneof_case_offset, uint32_t) !=
+ upb_fielddef_number(f)) {
+ continue;
+ }
+ // Otherwise, fall through to the appropriate singular-field handler
+ // below.
+ is_matching_oneof = true;
+ }
+
+ if (is_map_field(f)) {
+ VALUE map = DEREF(msg, offset, VALUE);
+ if (map != Qnil) {
+ putmap(map, f, sink, depth);
+ }
+ } else if (upb_fielddef_isseq(f)) {
+ VALUE ary = DEREF(msg, offset, VALUE);
+ if (ary != Qnil) {
+ putary(ary, f, sink, depth);
+ }
+ } else if (upb_fielddef_isstring(f)) {
+ VALUE str = DEREF(msg, offset, VALUE);
+ if (is_matching_oneof || RSTRING_LEN(str) > 0) {
+ putstr(str, f, sink);
+ }
+ } else if (upb_fielddef_issubmsg(f)) {
+ putsubmsg(DEREF(msg, offset, VALUE), f, sink, depth);
+ } else {
+ upb_selector_t sel = getsel(f, upb_handlers_getprimitivehandlertype(f));
+
+#define T(upbtypeconst, upbtype, ctype, default_value) \
+ case upbtypeconst: { \
+ ctype value = DEREF(msg, offset, ctype); \
+ if (is_matching_oneof || value != default_value) { \
+ upb_sink_put##upbtype(sink, sel, value); \
+ } \
+ } \
+ break;
+
+ switch (upb_fielddef_type(f)) {
+ T(UPB_TYPE_FLOAT, float, float, 0.0)
+ T(UPB_TYPE_DOUBLE, double, double, 0.0)
+ T(UPB_TYPE_BOOL, bool, uint8_t, 0)
+ case UPB_TYPE_ENUM:
+ T(UPB_TYPE_INT32, int32, int32_t, 0)
+ T(UPB_TYPE_UINT32, uint32, uint32_t, 0)
+ T(UPB_TYPE_INT64, int64, int64_t, 0)
+ T(UPB_TYPE_UINT64, uint64, uint64_t, 0)
+
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_MESSAGE: rb_raise(rb_eRuntimeError, "Internal error.");
+ }
+
+#undef T
+
+ }
+ }
+
+ upb_sink_endmsg(sink, &status);
+}
+
+static const upb_handlers* msgdef_pb_serialize_handlers(Descriptor* desc) {
+ if (desc->pb_serialize_handlers == NULL) {
+ desc->pb_serialize_handlers =
+ upb_pb_encoder_newhandlers(desc->msgdef, &desc->pb_serialize_handlers);
+ }
+ return desc->pb_serialize_handlers;
+}
+
+static const upb_handlers* msgdef_json_serialize_handlers(
+ Descriptor* desc, bool preserve_proto_fieldnames) {
+ if (preserve_proto_fieldnames) {
+ if (desc->json_serialize_handlers == NULL) {
+ desc->json_serialize_handlers =
+ upb_json_printer_newhandlers(
+ desc->msgdef, true, &desc->json_serialize_handlers);
+ }
+ return desc->json_serialize_handlers;
+ } else {
+ if (desc->json_serialize_handlers_preserve == NULL) {
+ desc->json_serialize_handlers_preserve =
+ upb_json_printer_newhandlers(
+ desc->msgdef, false, &desc->json_serialize_handlers_preserve);
+ }
+ return desc->json_serialize_handlers_preserve;
+ }
+}
+
+/*
+ * call-seq:
+ * MessageClass.encode(msg) => bytes
+ *
+ * Encodes the given message object to its serialized form in protocol buffers
+ * wire format.
+ */
+VALUE Message_encode(VALUE klass, VALUE msg_rb) {
+ VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned);
+ Descriptor* desc = ruby_to_Descriptor(descriptor);
+
+ stringsink sink;
+ stringsink_init(&sink);
+
+ {
+ const upb_handlers* serialize_handlers =
+ msgdef_pb_serialize_handlers(desc);
+
+ stackenv se;
+ upb_pb_encoder* encoder;
+ VALUE ret;
+
+ stackenv_init(&se, "Error occurred during encoding: %s");
+ encoder = upb_pb_encoder_create(&se.env, serialize_handlers, &sink.sink);
+
+ putmsg(msg_rb, desc, upb_pb_encoder_input(encoder), 0);
+
+ ret = rb_str_new(sink.ptr, sink.len);
+
+ stackenv_uninit(&se);
+ stringsink_uninit(&sink);
+
+ return ret;
+ }
+}
+
+/*
+ * call-seq:
+ * MessageClass.encode_json(msg) => json_string
+ *
+ * Encodes the given message object into its serialized JSON representation.
+ */
+VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass) {
+ VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned);
+ Descriptor* desc = ruby_to_Descriptor(descriptor);
+ VALUE msg_rb;
+ VALUE preserve_proto_fieldnames = Qfalse;
+ stringsink sink;
+
+ if (argc < 1 || argc > 2) {
+ rb_raise(rb_eArgError, "Expected 1 or 2 arguments.");
+ }
+
+ msg_rb = argv[0];
+
+ if (argc == 2) {
+ VALUE hash_args = argv[1];
+ if (TYPE(hash_args) != T_HASH) {
+ rb_raise(rb_eArgError, "Expected hash arguments.");
+ }
+ preserve_proto_fieldnames = rb_hash_lookup2(
+ hash_args, ID2SYM(rb_intern("preserve_proto_fieldnames")), Qfalse);
+ }
+
+ stringsink_init(&sink);
+
+ {
+ const upb_handlers* serialize_handlers =
+ msgdef_json_serialize_handlers(desc, RTEST(preserve_proto_fieldnames));
+ upb_json_printer* printer;
+ stackenv se;
+ VALUE ret;
+
+ stackenv_init(&se, "Error occurred during encoding: %s");
+ printer = upb_json_printer_create(&se.env, serialize_handlers, &sink.sink);
+
+ putmsg(msg_rb, desc, upb_json_printer_input(printer), 0);
+
+ ret = rb_enc_str_new(sink.ptr, sink.len, rb_utf8_encoding());
+
+ stackenv_uninit(&se);
+ stringsink_uninit(&sink);
+
+ return ret;
+ }
+}
+
diff --git a/third_party/protobuf/ruby/ext/google/protobuf_c/extconf.rb b/third_party/protobuf/ruby/ext/google/protobuf_c/extconf.rb
new file mode 100644
index 0000000000..0886e60708
--- /dev/null
+++ b/third_party/protobuf/ruby/ext/google/protobuf_c/extconf.rb
@@ -0,0 +1,17 @@
+#!/usr/bin/ruby
+
+require 'mkmf'
+
+$CFLAGS += " -std=c99 -O3 -DNDEBUG"
+
+
+if RUBY_PLATFORM =~ /linux/
+ # Instruct the linker to point memcpy calls at our __wrap_memcpy wrapper.
+ $LDFLAGS += " -Wl,-wrap,memcpy"
+end
+
+$objs = ["protobuf.o", "defs.o", "storage.o", "message.o",
+ "repeated_field.o", "map.o", "encode_decode.o", "upb.o",
+ "wrap_memcpy.o"]
+
+create_makefile("google/protobuf_c")
diff --git a/third_party/protobuf/ruby/ext/google/protobuf_c/map.c b/third_party/protobuf/ruby/ext/google/protobuf_c/map.c
new file mode 100644
index 0000000000..4be54c39d1
--- /dev/null
+++ b/third_party/protobuf/ruby/ext/google/protobuf_c/map.c
@@ -0,0 +1,841 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 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 "protobuf.h"
+
+// -----------------------------------------------------------------------------
+// Basic map operations on top of upb's strtable.
+//
+// Note that we roll our own `Map` container here because, as for
+// `RepeatedField`, we want a strongly-typed container. This is so that any user
+// errors due to incorrect map key or value types are raised as close as
+// possible to the error site, rather than at some deferred point (e.g.,
+// serialization).
+//
+// We build our `Map` on top of upb_strtable so that we're able to take
+// advantage of the native_slot storage abstraction, as RepeatedField does.
+// (This is not quite a perfect mapping -- see the key conversions below -- but
+// gives us full support and error-checking for all value types for free.)
+// -----------------------------------------------------------------------------
+
+// Map values are stored using the native_slot abstraction (as with repeated
+// field values), but keys are a bit special. Since we use a strtable, we need
+// to store keys as sequences of bytes such that equality of those bytes maps
+// one-to-one to equality of keys. We store strings directly (i.e., they map to
+// their own bytes) and integers as native integers (using the native_slot
+// abstraction).
+
+// Note that there is another tradeoff here in keeping string keys as native
+// strings rather than Ruby strings: traversing the Map requires conversion to
+// Ruby string values on every traversal, potentially creating more garbage. We
+// should consider ways to cache a Ruby version of the key if this becomes an
+// issue later.
+
+// Forms a key to use with the underlying strtable from a Ruby key value. |buf|
+// must point to TABLE_KEY_BUF_LENGTH bytes of temporary space, used to
+// construct a key byte sequence if needed. |out_key| and |out_length| provide
+// the resulting key data/length.
+#define TABLE_KEY_BUF_LENGTH 8 // sizeof(uint64_t)
+static VALUE table_key(Map* self, VALUE key,
+ char* buf,
+ const char** out_key,
+ size_t* out_length) {
+ switch (self->key_type) {
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_STRING:
+ // Strings: use string content directly.
+ Check_Type(key, T_STRING);
+ key = native_slot_encode_and_freeze_string(self->key_type, key);
+ *out_key = RSTRING_PTR(key);
+ *out_length = RSTRING_LEN(key);
+ break;
+
+ case UPB_TYPE_BOOL:
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_UINT64:
+ native_slot_set(self->key_type, Qnil, buf, key);
+ *out_key = buf;
+ *out_length = native_slot_size(self->key_type);
+ break;
+
+ default:
+ // Map constructor should not allow a Map with another key type to be
+ // constructed.
+ assert(false);
+ break;
+ }
+
+ return key;
+}
+
+static VALUE table_key_to_ruby(Map* self, const char* buf, size_t length) {
+ switch (self->key_type) {
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_STRING: {
+ VALUE ret = rb_str_new(buf, length);
+ rb_enc_associate(ret,
+ (self->key_type == UPB_TYPE_BYTES) ?
+ kRubyString8bitEncoding : kRubyStringUtf8Encoding);
+ return ret;
+ }
+
+ case UPB_TYPE_BOOL:
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_UINT64:
+ return native_slot_get(self->key_type, Qnil, buf);
+
+ default:
+ assert(false);
+ return Qnil;
+ }
+}
+
+static void* value_memory(upb_value* v) {
+ return (void*)(&v->val);
+}
+
+// -----------------------------------------------------------------------------
+// Map container type.
+// -----------------------------------------------------------------------------
+
+const rb_data_type_t Map_type = {
+ "Google::Protobuf::Map",
+ { Map_mark, Map_free, NULL },
+};
+
+VALUE cMap;
+
+Map* ruby_to_Map(VALUE _self) {
+ Map* self;
+ TypedData_Get_Struct(_self, Map, &Map_type, self);
+ return self;
+}
+
+void Map_mark(void* _self) {
+ Map* self = _self;
+
+ rb_gc_mark(self->value_type_class);
+
+ if (self->value_type == UPB_TYPE_STRING ||
+ self->value_type == UPB_TYPE_BYTES ||
+ self->value_type == UPB_TYPE_MESSAGE) {
+ upb_strtable_iter it;
+ for (upb_strtable_begin(&it, &self->table);
+ !upb_strtable_done(&it);
+ upb_strtable_next(&it)) {
+ upb_value v = upb_strtable_iter_value(&it);
+ void* mem = value_memory(&v);
+ native_slot_mark(self->value_type, mem);
+ }
+ }
+}
+
+void Map_free(void* _self) {
+ Map* self = _self;
+ upb_strtable_uninit(&self->table);
+ xfree(self);
+}
+
+VALUE Map_alloc(VALUE klass) {
+ Map* self = ALLOC(Map);
+ memset(self, 0, sizeof(Map));
+ self->value_type_class = Qnil;
+ return TypedData_Wrap_Struct(klass, &Map_type, self);
+}
+
+static bool needs_typeclass(upb_fieldtype_t type) {
+ switch (type) {
+ case UPB_TYPE_MESSAGE:
+ case UPB_TYPE_ENUM:
+ return true;
+ default:
+ return false;
+ }
+}
+
+/*
+ * call-seq:
+ * Map.new(key_type, value_type, value_typeclass = nil, init_hashmap = {})
+ * => new map
+ *
+ * Allocates a new Map container. This constructor may be called with 2, 3, or 4
+ * arguments. The first two arguments are always present and are symbols (taking
+ * on the same values as field-type symbols in message descriptors) that
+ * indicate the type of the map key and value fields.
+ *
+ * The supported key types are: :int32, :int64, :uint32, :uint64, :bool,
+ * :string, :bytes.
+ *
+ * The supported value types are: :int32, :int64, :uint32, :uint64, :bool,
+ * :string, :bytes, :enum, :message.
+ *
+ * The third argument, value_typeclass, must be present if value_type is :enum
+ * or :message. As in RepeatedField#new, this argument must be a message class
+ * (for :message) or enum module (for :enum).
+ *
+ * The last argument, if present, provides initial content for map. Note that
+ * this may be an ordinary Ruby hashmap or another Map instance with identical
+ * key and value types. Also note that this argument may be present whether or
+ * not value_typeclass is present (and it is unambiguously separate from
+ * value_typeclass because value_typeclass's presence is strictly determined by
+ * value_type). The contents of this initial hashmap or Map instance are
+ * shallow-copied into the new Map: the original map is unmodified, but
+ * references to underlying objects will be shared if the value type is a
+ * message type.
+ */
+VALUE Map_init(int argc, VALUE* argv, VALUE _self) {
+ Map* self = ruby_to_Map(_self);
+ int init_value_arg;
+
+ // We take either two args (:key_type, :value_type), three args (:key_type,
+ // :value_type, "ValueMessageType"), or four args (the above plus an initial
+ // hashmap).
+ if (argc < 2 || argc > 4) {
+ rb_raise(rb_eArgError, "Map constructor expects 2, 3 or 4 arguments.");
+ }
+
+ self->key_type = ruby_to_fieldtype(argv[0]);
+ self->value_type = ruby_to_fieldtype(argv[1]);
+
+ // Check that the key type is an allowed type.
+ switch (self->key_type) {
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_UINT64:
+ case UPB_TYPE_BOOL:
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ // These are OK.
+ break;
+ default:
+ rb_raise(rb_eArgError, "Invalid key type for map.");
+ }
+
+ init_value_arg = 2;
+ if (needs_typeclass(self->value_type) && argc > 2) {
+ self->value_type_class = argv[2];
+ validate_type_class(self->value_type, self->value_type_class);
+ init_value_arg = 3;
+ }
+
+ // Table value type is always UINT64: this ensures enough space to store the
+ // native_slot value.
+ if (!upb_strtable_init(&self->table, UPB_CTYPE_UINT64)) {
+ rb_raise(rb_eRuntimeError, "Could not allocate table.");
+ }
+
+ if (argc > init_value_arg) {
+ Map_merge_into_self(_self, argv[init_value_arg]);
+ }
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * Map.each(&block)
+ *
+ * Invokes &block on each |key, value| pair in the map, in unspecified order.
+ * Note that Map also includes Enumerable; map thus acts like a normal Ruby
+ * sequence.
+ */
+VALUE Map_each(VALUE _self) {
+ Map* self = ruby_to_Map(_self);
+
+ upb_strtable_iter it;
+ for (upb_strtable_begin(&it, &self->table);
+ !upb_strtable_done(&it);
+ upb_strtable_next(&it)) {
+
+ VALUE key = table_key_to_ruby(
+ self, upb_strtable_iter_key(&it), upb_strtable_iter_keylength(&it));
+
+ upb_value v = upb_strtable_iter_value(&it);
+ void* mem = value_memory(&v);
+ VALUE value = native_slot_get(self->value_type,
+ self->value_type_class,
+ mem);
+
+ rb_yield_values(2, key, value);
+ }
+
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * Map.keys => [list_of_keys]
+ *
+ * Returns the list of keys contained in the map, in unspecified order.
+ */
+VALUE Map_keys(VALUE _self) {
+ Map* self = ruby_to_Map(_self);
+
+ VALUE ret = rb_ary_new();
+ upb_strtable_iter it;
+ for (upb_strtable_begin(&it, &self->table);
+ !upb_strtable_done(&it);
+ upb_strtable_next(&it)) {
+
+ VALUE key = table_key_to_ruby(
+ self, upb_strtable_iter_key(&it), upb_strtable_iter_keylength(&it));
+
+ rb_ary_push(ret, key);
+ }
+
+ return ret;
+}
+
+/*
+ * call-seq:
+ * Map.values => [list_of_values]
+ *
+ * Returns the list of values contained in the map, in unspecified order.
+ */
+VALUE Map_values(VALUE _self) {
+ Map* self = ruby_to_Map(_self);
+
+ VALUE ret = rb_ary_new();
+ upb_strtable_iter it;
+ for (upb_strtable_begin(&it, &self->table);
+ !upb_strtable_done(&it);
+ upb_strtable_next(&it)) {
+
+ upb_value v = upb_strtable_iter_value(&it);
+ void* mem = value_memory(&v);
+ VALUE value = native_slot_get(self->value_type,
+ self->value_type_class,
+ mem);
+
+ rb_ary_push(ret, value);
+ }
+
+ return ret;
+}
+
+/*
+ * call-seq:
+ * Map.[](key) => value
+ *
+ * Accesses the element at the given key. Throws an exception if the key type is
+ * incorrect. Returns nil when the key is not present in the map.
+ */
+VALUE Map_index(VALUE _self, VALUE key) {
+ Map* self = ruby_to_Map(_self);
+
+ char keybuf[TABLE_KEY_BUF_LENGTH];
+ const char* keyval = NULL;
+ size_t length = 0;
+ upb_value v;
+ key = table_key(self, key, keybuf, &keyval, &length);
+
+ if (upb_strtable_lookup2(&self->table, keyval, length, &v)) {
+ void* mem = value_memory(&v);
+ return native_slot_get(self->value_type, self->value_type_class, mem);
+ } else {
+ return Qnil;
+ }
+}
+
+/*
+ * call-seq:
+ * Map.[]=(key, value) => value
+ *
+ * Inserts or overwrites the value at the given key with the given new value.
+ * Throws an exception if the key type is incorrect. Returns the new value that
+ * was just inserted.
+ */
+VALUE Map_index_set(VALUE _self, VALUE key, VALUE value) {
+ Map* self = ruby_to_Map(_self);
+
+ char keybuf[TABLE_KEY_BUF_LENGTH];
+ const char* keyval = NULL;
+ size_t length = 0;
+ upb_value v;
+ void* mem;
+ key = table_key(self, key, keybuf, &keyval, &length);
+
+ mem = value_memory(&v);
+ native_slot_set(self->value_type, self->value_type_class, mem, value);
+
+ // Replace any existing value by issuing a 'remove' operation first.
+ upb_strtable_remove2(&self->table, keyval, length, NULL);
+ if (!upb_strtable_insert2(&self->table, keyval, length, v)) {
+ rb_raise(rb_eRuntimeError, "Could not insert into table");
+ }
+
+ // Ruby hashmap's :[]= method also returns the inserted value.
+ return value;
+}
+
+/*
+ * call-seq:
+ * Map.has_key?(key) => bool
+ *
+ * Returns true if the given key is present in the map. Throws an exception if
+ * the key has the wrong type.
+ */
+VALUE Map_has_key(VALUE _self, VALUE key) {
+ Map* self = ruby_to_Map(_self);
+
+ char keybuf[TABLE_KEY_BUF_LENGTH];
+ const char* keyval = NULL;
+ size_t length = 0;
+ key = table_key(self, key, keybuf, &keyval, &length);
+
+ if (upb_strtable_lookup2(&self->table, keyval, length, NULL)) {
+ return Qtrue;
+ } else {
+ return Qfalse;
+ }
+}
+
+/*
+ * call-seq:
+ * Map.delete(key) => old_value
+ *
+ * Deletes the value at the given key, if any, returning either the old value or
+ * nil if none was present. Throws an exception if the key is of the wrong type.
+ */
+VALUE Map_delete(VALUE _self, VALUE key) {
+ Map* self = ruby_to_Map(_self);
+
+ char keybuf[TABLE_KEY_BUF_LENGTH];
+ const char* keyval = NULL;
+ size_t length = 0;
+ upb_value v;
+ key = table_key(self, key, keybuf, &keyval, &length);
+
+ if (upb_strtable_remove2(&self->table, keyval, length, &v)) {
+ void* mem = value_memory(&v);
+ return native_slot_get(self->value_type, self->value_type_class, mem);
+ } else {
+ return Qnil;
+ }
+}
+
+/*
+ * call-seq:
+ * Map.clear
+ *
+ * Removes all entries from the map.
+ */
+VALUE Map_clear(VALUE _self) {
+ Map* self = ruby_to_Map(_self);
+
+ // Uninit and reinit the table -- this is faster than iterating and doing a
+ // delete-lookup on each key.
+ upb_strtable_uninit(&self->table);
+ if (!upb_strtable_init(&self->table, UPB_CTYPE_INT64)) {
+ rb_raise(rb_eRuntimeError, "Unable to re-initialize table");
+ }
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * Map.length
+ *
+ * Returns the number of entries (key-value pairs) in the map.
+ */
+VALUE Map_length(VALUE _self) {
+ Map* self = ruby_to_Map(_self);
+ return ULL2NUM(upb_strtable_count(&self->table));
+}
+
+static VALUE Map_new_this_type(VALUE _self) {
+ Map* self = ruby_to_Map(_self);
+ VALUE new_map = Qnil;
+ VALUE key_type = fieldtype_to_ruby(self->key_type);
+ VALUE value_type = fieldtype_to_ruby(self->value_type);
+ if (self->value_type_class != Qnil) {
+ new_map = rb_funcall(CLASS_OF(_self), rb_intern("new"), 3,
+ key_type, value_type, self->value_type_class);
+ } else {
+ new_map = rb_funcall(CLASS_OF(_self), rb_intern("new"), 2,
+ key_type, value_type);
+ }
+ return new_map;
+}
+
+/*
+ * call-seq:
+ * Map.dup => new_map
+ *
+ * Duplicates this map with a shallow copy. References to all non-primitive
+ * element objects (e.g., submessages) are shared.
+ */
+VALUE Map_dup(VALUE _self) {
+ Map* self = ruby_to_Map(_self);
+ VALUE new_map = Map_new_this_type(_self);
+ Map* new_self = ruby_to_Map(new_map);
+
+ upb_strtable_iter it;
+ for (upb_strtable_begin(&it, &self->table);
+ !upb_strtable_done(&it);
+ upb_strtable_next(&it)) {
+
+ upb_value v = upb_strtable_iter_value(&it);
+ void* mem = value_memory(&v);
+ upb_value dup;
+ void* dup_mem = value_memory(&dup);
+ native_slot_dup(self->value_type, dup_mem, mem);
+
+ if (!upb_strtable_insert2(&new_self->table,
+ upb_strtable_iter_key(&it),
+ upb_strtable_iter_keylength(&it),
+ dup)) {
+ rb_raise(rb_eRuntimeError, "Error inserting value into new table");
+ }
+ }
+
+ return new_map;
+}
+
+// Used by Google::Protobuf.deep_copy but not exposed directly.
+VALUE Map_deep_copy(VALUE _self) {
+ Map* self = ruby_to_Map(_self);
+ VALUE new_map = Map_new_this_type(_self);
+ Map* new_self = ruby_to_Map(new_map);
+
+ upb_strtable_iter it;
+ for (upb_strtable_begin(&it, &self->table);
+ !upb_strtable_done(&it);
+ upb_strtable_next(&it)) {
+
+ upb_value v = upb_strtable_iter_value(&it);
+ void* mem = value_memory(&v);
+ upb_value dup;
+ void* dup_mem = value_memory(&dup);
+ native_slot_deep_copy(self->value_type, dup_mem, mem);
+
+ if (!upb_strtable_insert2(&new_self->table,
+ upb_strtable_iter_key(&it),
+ upb_strtable_iter_keylength(&it),
+ dup)) {
+ rb_raise(rb_eRuntimeError, "Error inserting value into new table");
+ }
+ }
+
+ return new_map;
+}
+
+/*
+ * call-seq:
+ * Map.==(other) => boolean
+ *
+ * Compares this map to another. Maps are equal if they have identical key sets,
+ * and for each key, the values in both maps compare equal. Elements are
+ * compared as per normal Ruby semantics, by calling their :== methods (or
+ * performing a more efficient comparison for primitive types).
+ *
+ * Maps with dissimilar key types or value types/typeclasses are never equal,
+ * even if value comparison (for example, between integers and floats) would
+ * have otherwise indicated that every element has equal value.
+ */
+VALUE Map_eq(VALUE _self, VALUE _other) {
+ Map* self = ruby_to_Map(_self);
+ Map* other;
+ upb_strtable_iter it;
+
+ // Allow comparisons to Ruby hashmaps by converting to a temporary Map
+ // instance. Slow, but workable.
+ if (TYPE(_other) == T_HASH) {
+ VALUE other_map = Map_new_this_type(_self);
+ Map_merge_into_self(other_map, _other);
+ _other = other_map;
+ }
+
+ other = ruby_to_Map(_other);
+
+ if (self == other) {
+ return Qtrue;
+ }
+ if (self->key_type != other->key_type ||
+ self->value_type != other->value_type ||
+ self->value_type_class != other->value_type_class) {
+ return Qfalse;
+ }
+ if (upb_strtable_count(&self->table) != upb_strtable_count(&other->table)) {
+ return Qfalse;
+ }
+
+ // For each member of self, check that an equal member exists at the same key
+ // in other.
+ for (upb_strtable_begin(&it, &self->table);
+ !upb_strtable_done(&it);
+ upb_strtable_next(&it)) {
+
+ upb_value v = upb_strtable_iter_value(&it);
+ void* mem = value_memory(&v);
+ upb_value other_v;
+ void* other_mem = value_memory(&other_v);
+
+ if (!upb_strtable_lookup2(&other->table,
+ upb_strtable_iter_key(&it),
+ upb_strtable_iter_keylength(&it),
+ &other_v)) {
+ // Not present in other map.
+ return Qfalse;
+ }
+
+ if (!native_slot_eq(self->value_type, mem, other_mem)) {
+ // Present, but value not equal.
+ return Qfalse;
+ }
+ }
+
+ return Qtrue;
+}
+
+/*
+ * call-seq:
+ * Map.hash => hash_value
+ *
+ * Returns a hash value based on this map's contents.
+ */
+VALUE Map_hash(VALUE _self) {
+ Map* self = ruby_to_Map(_self);
+
+ st_index_t h = rb_hash_start(0);
+ VALUE hash_sym = rb_intern("hash");
+
+ upb_strtable_iter it;
+ for (upb_strtable_begin(&it, &self->table);
+ !upb_strtable_done(&it);
+ upb_strtable_next(&it)) {
+ VALUE key = table_key_to_ruby(
+ self, upb_strtable_iter_key(&it), upb_strtable_iter_keylength(&it));
+
+ upb_value v = upb_strtable_iter_value(&it);
+ void* mem = value_memory(&v);
+ VALUE value = native_slot_get(self->value_type,
+ self->value_type_class,
+ mem);
+
+ h = rb_hash_uint(h, NUM2LONG(rb_funcall(key, hash_sym, 0)));
+ h = rb_hash_uint(h, NUM2LONG(rb_funcall(value, hash_sym, 0)));
+ }
+
+ return INT2FIX(h);
+}
+
+/*
+ * call-seq:
+ * Map.to_h => {}
+ *
+ * Returns a Ruby Hash object containing all the values within the map
+ */
+VALUE Map_to_h(VALUE _self) {
+ Map* self = ruby_to_Map(_self);
+ VALUE hash = rb_hash_new();
+ upb_strtable_iter it;
+ for (upb_strtable_begin(&it, &self->table);
+ !upb_strtable_done(&it);
+ upb_strtable_next(&it)) {
+ VALUE key = table_key_to_ruby(
+ self, upb_strtable_iter_key(&it), upb_strtable_iter_keylength(&it));
+ upb_value v = upb_strtable_iter_value(&it);
+ void* mem = value_memory(&v);
+ VALUE value = native_slot_get(self->value_type,
+ self->value_type_class,
+ mem);
+
+ if (self->value_type == UPB_TYPE_MESSAGE) {
+ value = Message_to_h(value);
+ }
+ rb_hash_aset(hash, key, value);
+ }
+ return hash;
+}
+
+/*
+ * call-seq:
+ * Map.inspect => string
+ *
+ * Returns a string representing this map's elements. It will be formatted as
+ * "{key => value, key => value, ...}", with each key and value string
+ * representation computed by its own #inspect method.
+ */
+VALUE Map_inspect(VALUE _self) {
+ Map* self = ruby_to_Map(_self);
+
+ VALUE str = rb_str_new2("{");
+
+ bool first = true;
+ VALUE inspect_sym = rb_intern("inspect");
+
+ upb_strtable_iter it;
+ for (upb_strtable_begin(&it, &self->table);
+ !upb_strtable_done(&it);
+ upb_strtable_next(&it)) {
+ VALUE key = table_key_to_ruby(
+ self, upb_strtable_iter_key(&it), upb_strtable_iter_keylength(&it));
+
+ upb_value v = upb_strtable_iter_value(&it);
+ void* mem = value_memory(&v);
+ VALUE value = native_slot_get(self->value_type,
+ self->value_type_class,
+ mem);
+
+ if (!first) {
+ str = rb_str_cat2(str, ", ");
+ } else {
+ first = false;
+ }
+ str = rb_str_append(str, rb_funcall(key, inspect_sym, 0));
+ str = rb_str_cat2(str, "=>");
+ str = rb_str_append(str, rb_funcall(value, inspect_sym, 0));
+ }
+
+ str = rb_str_cat2(str, "}");
+ return str;
+}
+
+/*
+ * call-seq:
+ * Map.merge(other_map) => map
+ *
+ * Copies key/value pairs from other_map into a copy of this map. If a key is
+ * set in other_map and this map, the value from other_map overwrites the value
+ * in the new copy of this map. Returns the new copy of this map with merged
+ * contents.
+ */
+VALUE Map_merge(VALUE _self, VALUE hashmap) {
+ VALUE dupped = Map_dup(_self);
+ return Map_merge_into_self(dupped, hashmap);
+}
+
+static int merge_into_self_callback(VALUE key, VALUE value, VALUE self) {
+ Map_index_set(self, key, value);
+ return ST_CONTINUE;
+}
+
+// Used only internally -- shared by #merge and #initialize.
+VALUE Map_merge_into_self(VALUE _self, VALUE hashmap) {
+ if (TYPE(hashmap) == T_HASH) {
+ rb_hash_foreach(hashmap, merge_into_self_callback, _self);
+ } else if (RB_TYPE_P(hashmap, T_DATA) && RTYPEDDATA_P(hashmap) &&
+ RTYPEDDATA_TYPE(hashmap) == &Map_type) {
+
+ Map* self = ruby_to_Map(_self);
+ Map* other = ruby_to_Map(hashmap);
+ upb_strtable_iter it;
+
+ if (self->key_type != other->key_type ||
+ self->value_type != other->value_type ||
+ self->value_type_class != other->value_type_class) {
+ rb_raise(rb_eArgError, "Attempt to merge Map with mismatching types");
+ }
+
+ for (upb_strtable_begin(&it, &other->table);
+ !upb_strtable_done(&it);
+ upb_strtable_next(&it)) {
+
+ // Replace any existing value by issuing a 'remove' operation first.
+ upb_value v;
+ upb_value oldv;
+ upb_strtable_remove2(&self->table,
+ upb_strtable_iter_key(&it),
+ upb_strtable_iter_keylength(&it),
+ &oldv);
+
+ v = upb_strtable_iter_value(&it);
+ upb_strtable_insert2(&self->table,
+ upb_strtable_iter_key(&it),
+ upb_strtable_iter_keylength(&it),
+ v);
+ }
+ } else {
+ rb_raise(rb_eArgError, "Unknown type merging into Map");
+ }
+ return _self;
+}
+
+// Internal method: map iterator initialization (used for serialization).
+void Map_begin(VALUE _self, Map_iter* iter) {
+ Map* self = ruby_to_Map(_self);
+ iter->self = self;
+ upb_strtable_begin(&iter->it, &self->table);
+}
+
+void Map_next(Map_iter* iter) {
+ upb_strtable_next(&iter->it);
+}
+
+bool Map_done(Map_iter* iter) {
+ return upb_strtable_done(&iter->it);
+}
+
+VALUE Map_iter_key(Map_iter* iter) {
+ return table_key_to_ruby(
+ iter->self,
+ upb_strtable_iter_key(&iter->it),
+ upb_strtable_iter_keylength(&iter->it));
+}
+
+VALUE Map_iter_value(Map_iter* iter) {
+ upb_value v = upb_strtable_iter_value(&iter->it);
+ void* mem = value_memory(&v);
+ return native_slot_get(iter->self->value_type,
+ iter->self->value_type_class,
+ mem);
+}
+
+void Map_register(VALUE module) {
+ VALUE klass = rb_define_class_under(module, "Map", rb_cObject);
+ rb_define_alloc_func(klass, Map_alloc);
+ cMap = klass;
+ rb_gc_register_address(&cMap);
+
+ rb_define_method(klass, "initialize", Map_init, -1);
+ rb_define_method(klass, "each", Map_each, 0);
+ rb_define_method(klass, "keys", Map_keys, 0);
+ rb_define_method(klass, "values", Map_values, 0);
+ rb_define_method(klass, "[]", Map_index, 1);
+ rb_define_method(klass, "[]=", Map_index_set, 2);
+ rb_define_method(klass, "has_key?", Map_has_key, 1);
+ rb_define_method(klass, "delete", Map_delete, 1);
+ rb_define_method(klass, "clear", Map_clear, 0);
+ rb_define_method(klass, "length", Map_length, 0);
+ rb_define_method(klass, "dup", Map_dup, 0);
+ rb_define_method(klass, "==", Map_eq, 1);
+ rb_define_method(klass, "hash", Map_hash, 0);
+ rb_define_method(klass, "to_hash", Map_to_h, 0);
+ rb_define_method(klass, "to_h", Map_to_h, 0);
+ rb_define_method(klass, "inspect", Map_inspect, 0);
+ rb_define_method(klass, "merge", Map_merge, 1);
+ rb_include_module(klass, rb_mEnumerable);
+}
diff --git a/third_party/protobuf/ruby/ext/google/protobuf_c/message.c b/third_party/protobuf/ruby/ext/google/protobuf_c/message.c
new file mode 100644
index 0000000000..299111404d
--- /dev/null
+++ b/third_party/protobuf/ruby/ext/google/protobuf_c/message.c
@@ -0,0 +1,632 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 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 "protobuf.h"
+
+// -----------------------------------------------------------------------------
+// Class/module creation from msgdefs and enumdefs, respectively.
+// -----------------------------------------------------------------------------
+
+void* Message_data(void* msg) {
+ return ((uint8_t *)msg) + sizeof(MessageHeader);
+}
+
+void Message_mark(void* _self) {
+ MessageHeader* self = (MessageHeader *)_self;
+ layout_mark(self->descriptor->layout, Message_data(self));
+}
+
+void Message_free(void* self) {
+ xfree(self);
+}
+
+rb_data_type_t Message_type = {
+ "Message",
+ { Message_mark, Message_free, NULL },
+};
+
+VALUE Message_alloc(VALUE klass) {
+ VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned);
+ Descriptor* desc = ruby_to_Descriptor(descriptor);
+ MessageHeader* msg = (MessageHeader*)ALLOC_N(
+ uint8_t, sizeof(MessageHeader) + desc->layout->size);
+ VALUE ret;
+
+ memset(Message_data(msg), 0, desc->layout->size);
+
+ // We wrap first so that everything in the message object is GC-rooted in case
+ // a collection happens during object creation in layout_init().
+ ret = TypedData_Wrap_Struct(klass, &Message_type, msg);
+ msg->descriptor = desc;
+ rb_ivar_set(ret, descriptor_instancevar_interned, descriptor);
+
+ layout_init(desc->layout, Message_data(msg));
+
+ return ret;
+}
+
+static VALUE which_oneof_field(MessageHeader* self, const upb_oneofdef* o) {
+ upb_oneof_iter it;
+ size_t case_ofs;
+ uint32_t oneof_case;
+ const upb_fielddef* first_field;
+ const upb_fielddef* f;
+
+ // If no fields in the oneof, always nil.
+ if (upb_oneofdef_numfields(o) == 0) {
+ return Qnil;
+ }
+ // Grab the first field in the oneof so we can get its layout info to find the
+ // oneof_case field.
+ upb_oneof_begin(&it, o);
+ assert(!upb_oneof_done(&it));
+ first_field = upb_oneof_iter_field(&it);
+ assert(upb_fielddef_containingoneof(first_field) != NULL);
+
+ case_ofs =
+ self->descriptor->layout->
+ fields[upb_fielddef_index(first_field)].case_offset;
+ oneof_case = *((uint32_t*)((char*)Message_data(self) + case_ofs));
+
+ if (oneof_case == ONEOF_CASE_NONE) {
+ return Qnil;
+ }
+
+ // oneof_case is a field index, so find that field.
+ f = upb_oneofdef_itof(o, oneof_case);
+ assert(f != NULL);
+
+ return ID2SYM(rb_intern(upb_fielddef_name(f)));
+}
+
+/*
+ * call-seq:
+ * Message.method_missing(*args)
+ *
+ * Provides accessors and setters for message fields according to their field
+ * names. For any field whose name does not conflict with a built-in method, an
+ * accessor is provided with the same name as the field, and a setter is
+ * provided with the name of the field plus the '=' suffix. Thus, given a
+ * message instance 'msg' with field 'foo', the following code is valid:
+ *
+ * msg.foo = 42
+ * puts msg.foo
+ *
+ * This method also provides read-only accessors for oneofs. If a oneof exists
+ * with name 'my_oneof', then msg.my_oneof will return a Ruby symbol equal to
+ * the name of the field in that oneof that is currently set, or nil if none.
+ */
+VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self) {
+ MessageHeader* self;
+ VALUE method_name, method_str;
+ char* name;
+ size_t name_len;
+ bool setter;
+ const upb_oneofdef* o;
+ const upb_fielddef* f;
+
+ TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
+ if (argc < 1) {
+ rb_raise(rb_eArgError, "Expected method name as first argument.");
+ }
+ method_name = argv[0];
+ if (!SYMBOL_P(method_name)) {
+ rb_raise(rb_eArgError, "Expected symbol as method name.");
+ }
+ method_str = rb_id2str(SYM2ID(method_name));
+ name = RSTRING_PTR(method_str);
+ name_len = RSTRING_LEN(method_str);
+ setter = false;
+
+ // Setters have names that end in '='.
+ if (name[name_len - 1] == '=') {
+ setter = true;
+ name_len--;
+ }
+
+ // See if this name corresponds to either a oneof or field in this message.
+ if (!upb_msgdef_lookupname(self->descriptor->msgdef, name, name_len, &f,
+ &o)) {
+ return rb_call_super(argc, argv);
+ }
+
+ if (o != NULL) {
+ // This is a oneof -- return which field inside the oneof is set.
+ if (setter) {
+ rb_raise(rb_eRuntimeError, "Oneof accessors are read-only.");
+ }
+ return which_oneof_field(self, o);
+ } else {
+ // This is a field -- get or set the field's value.
+ assert(f);
+ if (setter) {
+ if (argc < 2) {
+ rb_raise(rb_eArgError, "No value provided to setter.");
+ }
+ layout_set(self->descriptor->layout, Message_data(self), f, argv[1]);
+ return Qnil;
+ } else {
+ return layout_get(self->descriptor->layout, Message_data(self), f);
+ }
+ }
+}
+
+VALUE Message_respond_to_missing(int argc, VALUE* argv, VALUE _self) {
+ MessageHeader* self;
+ VALUE method_name, method_str;
+ char* name;
+ size_t name_len;
+ bool setter;
+ const upb_oneofdef* o;
+ const upb_fielddef* f;
+
+ TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
+ if (argc < 1) {
+ rb_raise(rb_eArgError, "Expected method name as first argument.");
+ }
+ method_name = argv[0];
+ if (!SYMBOL_P(method_name)) {
+ rb_raise(rb_eArgError, "Expected symbol as method name.");
+ }
+ method_str = rb_id2str(SYM2ID(method_name));
+ name = RSTRING_PTR(method_str);
+ name_len = RSTRING_LEN(method_str);
+ setter = false;
+
+ // Setters have names that end in '='.
+ if (name[name_len - 1] == '=') {
+ setter = true;
+ name_len--;
+ }
+
+ // See if this name corresponds to either a oneof or field in this message.
+ if (!upb_msgdef_lookupname(self->descriptor->msgdef, name, name_len, &f,
+ &o)) {
+ return rb_call_super(argc, argv);
+ }
+ if (o != NULL) {
+ return setter ? Qfalse : Qtrue;
+ }
+ return Qtrue;
+}
+
+int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
+ MessageHeader* self;
+ VALUE method_str;
+ char* name;
+ const upb_fielddef* f;
+ TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
+
+ if (!SYMBOL_P(key)) {
+ rb_raise(rb_eArgError,
+ "Expected symbols as hash keys in initialization map.");
+ }
+
+ method_str = rb_id2str(SYM2ID(key));
+ name = RSTRING_PTR(method_str);
+ f = upb_msgdef_ntofz(self->descriptor->msgdef, name);
+ if (f == NULL) {
+ rb_raise(rb_eArgError,
+ "Unknown field name '%s' in initialization map entry.", name);
+ }
+
+ if (is_map_field(f)) {
+ VALUE map;
+
+ if (TYPE(val) != T_HASH) {
+ rb_raise(rb_eArgError,
+ "Expected Hash object as initializer value for map field '%s'.", name);
+ }
+ map = layout_get(self->descriptor->layout, Message_data(self), f);
+ Map_merge_into_self(map, val);
+ } else if (upb_fielddef_label(f) == UPB_LABEL_REPEATED) {
+ VALUE ary;
+
+ if (TYPE(val) != T_ARRAY) {
+ rb_raise(rb_eArgError,
+ "Expected array as initializer value for repeated field '%s'.", name);
+ }
+ ary = layout_get(self->descriptor->layout, Message_data(self), f);
+ for (int i = 0; i < RARRAY_LEN(val); i++) {
+ RepeatedField_push(ary, rb_ary_entry(val, i));
+ }
+ } else {
+ layout_set(self->descriptor->layout, Message_data(self), f, val);
+ }
+ return 0;
+}
+
+/*
+ * call-seq:
+ * Message.new(kwargs) => new_message
+ *
+ * Creates a new instance of the given message class. Keyword arguments may be
+ * provided with keywords corresponding to field names.
+ *
+ * Note that no literal Message class exists. Only concrete classes per message
+ * type exist, as provided by the #msgclass method on Descriptors after they
+ * have been added to a pool. The method definitions described here on the
+ * Message class are provided on each concrete message class.
+ */
+VALUE Message_initialize(int argc, VALUE* argv, VALUE _self) {
+ VALUE hash_args;
+
+ if (argc == 0) {
+ return Qnil;
+ }
+ if (argc != 1) {
+ rb_raise(rb_eArgError, "Expected 0 or 1 arguments.");
+ }
+ hash_args = argv[0];
+ if (TYPE(hash_args) != T_HASH) {
+ rb_raise(rb_eArgError, "Expected hash arguments.");
+ }
+
+ rb_hash_foreach(hash_args, Message_initialize_kwarg, _self);
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * Message.dup => new_message
+ *
+ * Performs a shallow copy of this message and returns the new copy.
+ */
+VALUE Message_dup(VALUE _self) {
+ MessageHeader* self;
+ VALUE new_msg;
+ MessageHeader* new_msg_self;
+ TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
+
+ new_msg = rb_class_new_instance(0, NULL, CLASS_OF(_self));
+ TypedData_Get_Struct(new_msg, MessageHeader, &Message_type, new_msg_self);
+
+ layout_dup(self->descriptor->layout,
+ Message_data(new_msg_self),
+ Message_data(self));
+
+ return new_msg;
+}
+
+// Internal only; used by Google::Protobuf.deep_copy.
+VALUE Message_deep_copy(VALUE _self) {
+ MessageHeader* self;
+ MessageHeader* new_msg_self;
+ VALUE new_msg;
+ TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
+
+ new_msg = rb_class_new_instance(0, NULL, CLASS_OF(_self));
+ TypedData_Get_Struct(new_msg, MessageHeader, &Message_type, new_msg_self);
+
+ layout_deep_copy(self->descriptor->layout,
+ Message_data(new_msg_self),
+ Message_data(self));
+
+ return new_msg;
+}
+
+/*
+ * call-seq:
+ * Message.==(other) => boolean
+ *
+ * Performs a deep comparison of this message with another. Messages are equal
+ * if they have the same type and if each field is equal according to the :==
+ * method's semantics (a more efficient comparison may actually be done if the
+ * field is of a primitive type).
+ */
+VALUE Message_eq(VALUE _self, VALUE _other) {
+ MessageHeader* self;
+ MessageHeader* other;
+ if (TYPE(_self) != TYPE(_other)) {
+ return Qfalse;
+ }
+ TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
+ TypedData_Get_Struct(_other, MessageHeader, &Message_type, other);
+
+ if (self->descriptor != other->descriptor) {
+ return Qfalse;
+ }
+
+ return layout_eq(self->descriptor->layout,
+ Message_data(self),
+ Message_data(other));
+}
+
+/*
+ * call-seq:
+ * Message.hash => hash_value
+ *
+ * Returns a hash value that represents this message's field values.
+ */
+VALUE Message_hash(VALUE _self) {
+ MessageHeader* self;
+ TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
+
+ return layout_hash(self->descriptor->layout, Message_data(self));
+}
+
+/*
+ * call-seq:
+ * Message.inspect => string
+ *
+ * Returns a human-readable string representing this message. It will be
+ * formatted as "<MessageType: field1: value1, field2: value2, ...>". Each
+ * field's value is represented according to its own #inspect method.
+ */
+VALUE Message_inspect(VALUE _self) {
+ MessageHeader* self;
+ VALUE str;
+ TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
+
+ str = rb_str_new2("<");
+ str = rb_str_append(str, rb_str_new2(rb_class2name(CLASS_OF(_self))));
+ str = rb_str_cat2(str, ": ");
+ str = rb_str_append(str, layout_inspect(
+ self->descriptor->layout, Message_data(self)));
+ str = rb_str_cat2(str, ">");
+ return str;
+}
+
+/*
+ * call-seq:
+ * Message.to_h => {}
+ *
+ * Returns the message as a Ruby Hash object, with keys as symbols.
+ */
+VALUE Message_to_h(VALUE _self) {
+ MessageHeader* self;
+ VALUE hash;
+ upb_msg_field_iter it;
+ TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
+
+ hash = rb_hash_new();
+
+ for (upb_msg_field_begin(&it, self->descriptor->msgdef);
+ !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* field = upb_msg_iter_field(&it);
+ VALUE msg_value = layout_get(self->descriptor->layout, Message_data(self),
+ field);
+ VALUE msg_key = ID2SYM(rb_intern(upb_fielddef_name(field)));
+ if (upb_fielddef_ismap(field)) {
+ msg_value = Map_to_h(msg_value);
+ } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
+ msg_value = RepeatedField_to_ary(msg_value);
+ } else if (msg_value != Qnil &&
+ upb_fielddef_type(field) == UPB_TYPE_MESSAGE) {
+ msg_value = Message_to_h(msg_value);
+ }
+ rb_hash_aset(hash, msg_key, msg_value);
+ }
+ return hash;
+}
+
+
+
+/*
+ * call-seq:
+ * Message.[](index) => value
+ *
+ * Accesses a field's value by field name. The provided field name should be a
+ * string.
+ */
+VALUE Message_index(VALUE _self, VALUE field_name) {
+ MessageHeader* self;
+ const upb_fielddef* field;
+ TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
+ Check_Type(field_name, T_STRING);
+ field = upb_msgdef_ntofz(self->descriptor->msgdef, RSTRING_PTR(field_name));
+ if (field == NULL) {
+ return Qnil;
+ }
+ return layout_get(self->descriptor->layout, Message_data(self), field);
+}
+
+/*
+ * call-seq:
+ * Message.[]=(index, value)
+ *
+ * Sets a field's value by field name. The provided field name should be a
+ * string.
+ */
+VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value) {
+ MessageHeader* self;
+ const upb_fielddef* field;
+ TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
+ Check_Type(field_name, T_STRING);
+ field = upb_msgdef_ntofz(self->descriptor->msgdef, RSTRING_PTR(field_name));
+ if (field == NULL) {
+ rb_raise(rb_eArgError, "Unknown field: %s", RSTRING_PTR(field_name));
+ }
+ layout_set(self->descriptor->layout, Message_data(self), field, value);
+ return Qnil;
+}
+
+/*
+ * call-seq:
+ * Message.descriptor => descriptor
+ *
+ * Class method that returns the Descriptor instance corresponding to this
+ * message class's type.
+ */
+VALUE Message_descriptor(VALUE klass) {
+ return rb_ivar_get(klass, descriptor_instancevar_interned);
+}
+
+VALUE build_class_from_descriptor(Descriptor* desc) {
+ const char *name;
+ VALUE klass;
+
+ if (desc->layout == NULL) {
+ desc->layout = create_layout(desc->msgdef);
+ }
+ if (desc->fill_method == NULL) {
+ desc->fill_method = new_fillmsg_decodermethod(desc, &desc->fill_method);
+ }
+
+ name = upb_msgdef_fullname(desc->msgdef);
+ if (name == NULL) {
+ rb_raise(rb_eRuntimeError, "Descriptor does not have assigned name.");
+ }
+
+ klass = rb_define_class_id(
+ // Docs say this parameter is ignored. User will assign return value to
+ // their own toplevel constant class name.
+ rb_intern("Message"),
+ rb_cObject);
+ rb_ivar_set(klass, descriptor_instancevar_interned,
+ get_def_obj(desc->msgdef));
+ rb_define_alloc_func(klass, Message_alloc);
+ rb_require("google/protobuf/message_exts");
+ rb_include_module(klass, rb_eval_string("Google::Protobuf::MessageExts"));
+ rb_extend_object(
+ klass, rb_eval_string("Google::Protobuf::MessageExts::ClassMethods"));
+
+ rb_define_method(klass, "method_missing",
+ Message_method_missing, -1);
+ rb_define_method(klass, "respond_to_missing?",
+ Message_respond_to_missing, -1);
+ rb_define_method(klass, "initialize", Message_initialize, -1);
+ rb_define_method(klass, "dup", Message_dup, 0);
+ // Also define #clone so that we don't inherit Object#clone.
+ rb_define_method(klass, "clone", Message_dup, 0);
+ rb_define_method(klass, "==", Message_eq, 1);
+ rb_define_method(klass, "hash", Message_hash, 0);
+ rb_define_method(klass, "to_h", Message_to_h, 0);
+ rb_define_method(klass, "to_hash", Message_to_h, 0);
+ rb_define_method(klass, "inspect", Message_inspect, 0);
+ rb_define_method(klass, "[]", Message_index, 1);
+ rb_define_method(klass, "[]=", Message_index_set, 2);
+ rb_define_singleton_method(klass, "decode", Message_decode, 1);
+ rb_define_singleton_method(klass, "encode", Message_encode, 1);
+ rb_define_singleton_method(klass, "decode_json", Message_decode_json, 1);
+ rb_define_singleton_method(klass, "encode_json", Message_encode_json, -1);
+ rb_define_singleton_method(klass, "descriptor", Message_descriptor, 0);
+
+ return klass;
+}
+
+/*
+ * call-seq:
+ * Enum.lookup(number) => name
+ *
+ * This module method, provided on each generated enum module, looks up an enum
+ * value by number and returns its name as a Ruby symbol, or nil if not found.
+ */
+VALUE enum_lookup(VALUE self, VALUE number) {
+ int32_t num = NUM2INT(number);
+ VALUE desc = rb_ivar_get(self, descriptor_instancevar_interned);
+ EnumDescriptor* enumdesc = ruby_to_EnumDescriptor(desc);
+
+ const char* name = upb_enumdef_iton(enumdesc->enumdef, num);
+ if (name == NULL) {
+ return Qnil;
+ } else {
+ return ID2SYM(rb_intern(name));
+ }
+}
+
+/*
+ * call-seq:
+ * Enum.resolve(name) => number
+ *
+ * This module method, provided on each generated enum module, looks up an enum
+ * value by name (as a Ruby symbol) and returns its name, or nil if not found.
+ */
+VALUE enum_resolve(VALUE self, VALUE sym) {
+ const char* name = rb_id2name(SYM2ID(sym));
+ VALUE desc = rb_ivar_get(self, descriptor_instancevar_interned);
+ EnumDescriptor* enumdesc = ruby_to_EnumDescriptor(desc);
+
+ int32_t num = 0;
+ bool found = upb_enumdef_ntoiz(enumdesc->enumdef, name, &num);
+ if (!found) {
+ return Qnil;
+ } else {
+ return INT2NUM(num);
+ }
+}
+
+/*
+ * call-seq:
+ * Enum.descriptor
+ *
+ * This module method, provided on each generated enum module, returns the
+ * EnumDescriptor corresponding to this enum type.
+ */
+VALUE enum_descriptor(VALUE self) {
+ return rb_ivar_get(self, descriptor_instancevar_interned);
+}
+
+VALUE build_module_from_enumdesc(EnumDescriptor* enumdesc) {
+ VALUE mod = rb_define_module_id(
+ rb_intern(upb_enumdef_fullname(enumdesc->enumdef)));
+
+ upb_enum_iter it;
+ for (upb_enum_begin(&it, enumdesc->enumdef);
+ !upb_enum_done(&it);
+ upb_enum_next(&it)) {
+ const char* name = upb_enum_iter_name(&it);
+ int32_t value = upb_enum_iter_number(&it);
+ if (name[0] < 'A' || name[0] > 'Z') {
+ rb_raise(rb_eTypeError,
+ "Enum value '%s' does not start with an uppercase letter "
+ "as is required for Ruby constants.",
+ name);
+ }
+ rb_define_const(mod, name, INT2NUM(value));
+ }
+
+ rb_define_singleton_method(mod, "lookup", enum_lookup, 1);
+ rb_define_singleton_method(mod, "resolve", enum_resolve, 1);
+ rb_define_singleton_method(mod, "descriptor", enum_descriptor, 0);
+ rb_ivar_set(mod, descriptor_instancevar_interned,
+ get_def_obj(enumdesc->enumdef));
+
+ return mod;
+}
+
+/*
+ * call-seq:
+ * Google::Protobuf.deep_copy(obj) => copy_of_obj
+ *
+ * Performs a deep copy of a RepeatedField instance, a Map instance, or a
+ * message object, recursively copying its members.
+ */
+VALUE Google_Protobuf_deep_copy(VALUE self, VALUE obj) {
+ VALUE klass = CLASS_OF(obj);
+ if (klass == cRepeatedField) {
+ return RepeatedField_deep_copy(obj);
+ } else if (klass == cMap) {
+ return Map_deep_copy(obj);
+ } else {
+ return Message_deep_copy(obj);
+ }
+}
diff --git a/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.c b/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.c
new file mode 100644
index 0000000000..9896366760
--- /dev/null
+++ b/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.c
@@ -0,0 +1,117 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 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 "protobuf.h"
+
+// -----------------------------------------------------------------------------
+// Global map from upb {msg,enum}defs to wrapper Descriptor/EnumDescriptor
+// instances.
+// -----------------------------------------------------------------------------
+
+// This is a hash table from def objects (encoded by converting pointers to
+// Ruby integers) to MessageDef/EnumDef instances (as Ruby values).
+VALUE upb_def_to_ruby_obj_map;
+
+VALUE cError;
+VALUE cParseError;
+
+void add_def_obj(const void* def, VALUE value) {
+ rb_hash_aset(upb_def_to_ruby_obj_map, ULL2NUM((intptr_t)def), value);
+}
+
+VALUE get_def_obj(const void* def) {
+ return rb_hash_aref(upb_def_to_ruby_obj_map, ULL2NUM((intptr_t)def));
+}
+
+// -----------------------------------------------------------------------------
+// Utilities.
+// -----------------------------------------------------------------------------
+
+// Raises a Ruby error if |status| is not OK, using its error message.
+void check_upb_status(const upb_status* status, const char* msg) {
+ if (!upb_ok(status)) {
+ rb_raise(rb_eRuntimeError, "%s: %s\n", msg, upb_status_errmsg(status));
+ }
+}
+
+// String encodings: we look these up once, at load time, and then cache them
+// here.
+rb_encoding* kRubyStringUtf8Encoding;
+rb_encoding* kRubyStringASCIIEncoding;
+rb_encoding* kRubyString8bitEncoding;
+
+// Ruby-interned string: "descriptor". We use this identifier to store an
+// instance variable on message classes we create in order to link them back to
+// their descriptors.
+//
+// We intern this once at module load time then use the interned identifier at
+// runtime in order to avoid the cost of repeatedly interning in hot paths.
+const char* kDescriptorInstanceVar = "descriptor";
+ID descriptor_instancevar_interned;
+
+// -----------------------------------------------------------------------------
+// Initialization/entry point.
+// -----------------------------------------------------------------------------
+
+// This must be named "Init_protobuf_c" because the Ruby module is named
+// "protobuf_c" -- the VM looks for this symbol in our .so.
+void Init_protobuf_c() {
+ VALUE google = rb_define_module("Google");
+ VALUE protobuf = rb_define_module_under(google, "Protobuf");
+ VALUE internal = rb_define_module_under(protobuf, "Internal");
+
+ descriptor_instancevar_interned = rb_intern(kDescriptorInstanceVar);
+ DescriptorPool_register(protobuf);
+ Descriptor_register(protobuf);
+ FieldDescriptor_register(protobuf);
+ OneofDescriptor_register(protobuf);
+ EnumDescriptor_register(protobuf);
+ MessageBuilderContext_register(internal);
+ OneofBuilderContext_register(internal);
+ EnumBuilderContext_register(internal);
+ Builder_register(internal);
+ RepeatedField_register(protobuf);
+ Map_register(protobuf);
+
+ cError = rb_const_get(protobuf, rb_intern("Error"));
+ cParseError = rb_const_get(protobuf, rb_intern("ParseError"));
+
+ rb_define_singleton_method(protobuf, "deep_copy",
+ Google_Protobuf_deep_copy, 1);
+
+ kRubyStringUtf8Encoding = rb_utf8_encoding();
+ kRubyStringASCIIEncoding = rb_usascii_encoding();
+ kRubyString8bitEncoding = rb_ascii8bit_encoding();
+
+ upb_def_to_ruby_obj_map = rb_hash_new();
+ rb_gc_register_address(&upb_def_to_ruby_obj_map);
+ map_parse_frames = rb_ary_new();
+ rb_gc_register_address(&map_parse_frames);
+}
diff --git a/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h b/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h
new file mode 100644
index 0000000000..520e9d9b84
--- /dev/null
+++ b/third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h
@@ -0,0 +1,543 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 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_RUBY_PROTOBUF_H__
+#define __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__
+
+#include <ruby/ruby.h>
+#include <ruby/vm.h>
+#include <ruby/encoding.h>
+
+#include "upb.h"
+
+// Forward decls.
+struct DescriptorPool;
+struct Descriptor;
+struct FieldDescriptor;
+struct EnumDescriptor;
+struct MessageLayout;
+struct MessageField;
+struct MessageHeader;
+struct MessageBuilderContext;
+struct EnumBuilderContext;
+struct Builder;
+
+typedef struct DescriptorPool DescriptorPool;
+typedef struct Descriptor Descriptor;
+typedef struct FieldDescriptor FieldDescriptor;
+typedef struct OneofDescriptor OneofDescriptor;
+typedef struct EnumDescriptor EnumDescriptor;
+typedef struct MessageLayout MessageLayout;
+typedef struct MessageField MessageField;
+typedef struct MessageHeader MessageHeader;
+typedef struct MessageBuilderContext MessageBuilderContext;
+typedef struct OneofBuilderContext OneofBuilderContext;
+typedef struct EnumBuilderContext EnumBuilderContext;
+typedef struct Builder Builder;
+
+/*
+ It can be a bit confusing how the C structs defined below and the Ruby
+ objects interact and hold references to each other. First, a few principles:
+
+ - Ruby's "TypedData" abstraction lets a Ruby VALUE hold a pointer to a C
+ struct (or arbitrary memory chunk), own it, and free it when collected.
+ Thus, each struct below will have a corresponding Ruby object
+ wrapping/owning it.
+
+ - To get back from an underlying upb {msg,enum}def to the Ruby object, we
+ keep a global hashmap, accessed by get_def_obj/add_def_obj below.
+
+ The in-memory structure is then something like:
+
+ Ruby | upb
+ |
+ DescriptorPool ------------|-----------> upb_symtab____________________
+ | | (message types) \
+ | v \
+ Descriptor ---------------|-----------> upb_msgdef (enum types)|
+ |--> msgclass | | ^ |
+ | (dynamically built) | | | (submsg fields) |
+ |--> MessageLayout | | | /
+ |--------------------------|> decoder method| | /
+ \--------------------------|> serialize | | /
+ | handlers v | /
+ FieldDescriptor -----------|-----------> upb_fielddef /
+ | | /
+ | v (enum fields) /
+ EnumDescriptor ------------|-----------> upb_enumdef <----------'
+ |
+ |
+ ^ | \___/
+ `---------------|-----------------' (get_def_obj map)
+ */
+
+// -----------------------------------------------------------------------------
+// Ruby class structure definitions.
+// -----------------------------------------------------------------------------
+
+struct DescriptorPool {
+ upb_symtab* symtab;
+};
+
+struct Descriptor {
+ const upb_msgdef* msgdef;
+ MessageLayout* layout;
+ VALUE klass; // begins as nil
+ const upb_handlers* fill_handlers;
+ const upb_pbdecodermethod* fill_method;
+ const upb_json_parsermethod* json_fill_method;
+ const upb_handlers* pb_serialize_handlers;
+ const upb_handlers* json_serialize_handlers;
+ const upb_handlers* json_serialize_handlers_preserve;
+ // Handlers hold type class references for sub-message fields directly in some
+ // cases. We need to keep these rooted because they might otherwise be
+ // collected.
+ VALUE typeclass_references;
+};
+
+struct FieldDescriptor {
+ const upb_fielddef* fielddef;
+};
+
+struct OneofDescriptor {
+ const upb_oneofdef* oneofdef;
+};
+
+struct EnumDescriptor {
+ const upb_enumdef* enumdef;
+ VALUE module; // begins as nil
+};
+
+struct MessageBuilderContext {
+ VALUE descriptor;
+ VALUE builder;
+};
+
+struct OneofBuilderContext {
+ VALUE descriptor;
+ VALUE builder;
+};
+
+struct EnumBuilderContext {
+ VALUE enumdesc;
+};
+
+struct Builder {
+ VALUE pending_list;
+ upb_def** defs; // used only while finalizing
+};
+
+extern VALUE cDescriptorPool;
+extern VALUE cDescriptor;
+extern VALUE cFieldDescriptor;
+extern VALUE cEnumDescriptor;
+extern VALUE cMessageBuilderContext;
+extern VALUE cOneofBuilderContext;
+extern VALUE cEnumBuilderContext;
+extern VALUE cBuilder;
+
+extern VALUE cError;
+extern VALUE cParseError;
+
+extern VALUE map_parse_frames;
+
+// We forward-declare all of the Ruby method implementations here because we
+// sometimes call the methods directly across .c files, rather than going
+// through Ruby's method dispatching (e.g. during message parse). It's cleaner
+// to keep the list of object methods together than to split them between
+// static-in-file definitions and header declarations.
+
+void DescriptorPool_mark(void* _self);
+void DescriptorPool_free(void* _self);
+VALUE DescriptorPool_alloc(VALUE klass);
+void DescriptorPool_register(VALUE module);
+DescriptorPool* ruby_to_DescriptorPool(VALUE value);
+VALUE DescriptorPool_add(VALUE _self, VALUE def);
+VALUE DescriptorPool_build(VALUE _self);
+VALUE DescriptorPool_lookup(VALUE _self, VALUE name);
+VALUE DescriptorPool_generated_pool(VALUE _self);
+
+void Descriptor_mark(void* _self);
+void Descriptor_free(void* _self);
+VALUE Descriptor_alloc(VALUE klass);
+void Descriptor_register(VALUE module);
+Descriptor* ruby_to_Descriptor(VALUE value);
+VALUE Descriptor_name(VALUE _self);
+VALUE Descriptor_name_set(VALUE _self, VALUE str);
+VALUE Descriptor_each(VALUE _self);
+VALUE Descriptor_lookup(VALUE _self, VALUE name);
+VALUE Descriptor_add_field(VALUE _self, VALUE obj);
+VALUE Descriptor_add_oneof(VALUE _self, VALUE obj);
+VALUE Descriptor_each_oneof(VALUE _self);
+VALUE Descriptor_lookup_oneof(VALUE _self, VALUE name);
+VALUE Descriptor_msgclass(VALUE _self);
+extern const rb_data_type_t _Descriptor_type;
+
+void FieldDescriptor_mark(void* _self);
+void FieldDescriptor_free(void* _self);
+VALUE FieldDescriptor_alloc(VALUE klass);
+void FieldDescriptor_register(VALUE module);
+FieldDescriptor* ruby_to_FieldDescriptor(VALUE value);
+VALUE FieldDescriptor_name(VALUE _self);
+VALUE FieldDescriptor_name_set(VALUE _self, VALUE str);
+VALUE FieldDescriptor_type(VALUE _self);
+VALUE FieldDescriptor_type_set(VALUE _self, VALUE type);
+VALUE FieldDescriptor_label(VALUE _self);
+VALUE FieldDescriptor_label_set(VALUE _self, VALUE label);
+VALUE FieldDescriptor_number(VALUE _self);
+VALUE FieldDescriptor_number_set(VALUE _self, VALUE number);
+VALUE FieldDescriptor_submsg_name(VALUE _self);
+VALUE FieldDescriptor_submsg_name_set(VALUE _self, VALUE value);
+VALUE FieldDescriptor_subtype(VALUE _self);
+VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb);
+VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value);
+upb_fieldtype_t ruby_to_fieldtype(VALUE type);
+VALUE fieldtype_to_ruby(upb_fieldtype_t type);
+
+void OneofDescriptor_mark(void* _self);
+void OneofDescriptor_free(void* _self);
+VALUE OneofDescriptor_alloc(VALUE klass);
+void OneofDescriptor_register(VALUE module);
+OneofDescriptor* ruby_to_OneofDescriptor(VALUE value);
+VALUE OneofDescriptor_name(VALUE _self);
+VALUE OneofDescriptor_name_set(VALUE _self, VALUE value);
+VALUE OneofDescriptor_add_field(VALUE _self, VALUE field);
+VALUE OneofDescriptor_each(VALUE _self, VALUE field);
+
+void EnumDescriptor_mark(void* _self);
+void EnumDescriptor_free(void* _self);
+VALUE EnumDescriptor_alloc(VALUE klass);
+void EnumDescriptor_register(VALUE module);
+EnumDescriptor* ruby_to_EnumDescriptor(VALUE value);
+VALUE EnumDescriptor_name(VALUE _self);
+VALUE EnumDescriptor_name_set(VALUE _self, VALUE str);
+VALUE EnumDescriptor_add_value(VALUE _self, VALUE name, VALUE number);
+VALUE EnumDescriptor_lookup_name(VALUE _self, VALUE name);
+VALUE EnumDescriptor_lookup_value(VALUE _self, VALUE number);
+VALUE EnumDescriptor_each(VALUE _self);
+VALUE EnumDescriptor_enummodule(VALUE _self);
+extern const rb_data_type_t _EnumDescriptor_type;
+
+void MessageBuilderContext_mark(void* _self);
+void MessageBuilderContext_free(void* _self);
+VALUE MessageBuilderContext_alloc(VALUE klass);
+void MessageBuilderContext_register(VALUE module);
+MessageBuilderContext* ruby_to_MessageBuilderContext(VALUE value);
+VALUE MessageBuilderContext_initialize(VALUE _self,
+ VALUE descriptor,
+ VALUE builder);
+VALUE MessageBuilderContext_optional(int argc, VALUE* argv, VALUE _self);
+VALUE MessageBuilderContext_required(int argc, VALUE* argv, VALUE _self);
+VALUE MessageBuilderContext_repeated(int argc, VALUE* argv, VALUE _self);
+VALUE MessageBuilderContext_map(int argc, VALUE* argv, VALUE _self);
+VALUE MessageBuilderContext_oneof(VALUE _self, VALUE name);
+
+void OneofBuilderContext_mark(void* _self);
+void OneofBuilderContext_free(void* _self);
+VALUE OneofBuilderContext_alloc(VALUE klass);
+void OneofBuilderContext_register(VALUE module);
+OneofBuilderContext* ruby_to_OneofBuilderContext(VALUE value);
+VALUE OneofBuilderContext_initialize(VALUE _self,
+ VALUE descriptor,
+ VALUE builder);
+VALUE OneofBuilderContext_optional(int argc, VALUE* argv, VALUE _self);
+
+void EnumBuilderContext_mark(void* _self);
+void EnumBuilderContext_free(void* _self);
+VALUE EnumBuilderContext_alloc(VALUE klass);
+void EnumBuilderContext_register(VALUE module);
+EnumBuilderContext* ruby_to_EnumBuilderContext(VALUE value);
+VALUE EnumBuilderContext_initialize(VALUE _self, VALUE enumdesc);
+VALUE EnumBuilderContext_value(VALUE _self, VALUE name, VALUE number);
+
+void Builder_mark(void* _self);
+void Builder_free(void* _self);
+VALUE Builder_alloc(VALUE klass);
+void Builder_register(VALUE module);
+Builder* ruby_to_Builder(VALUE value);
+VALUE Builder_add_message(VALUE _self, VALUE name);
+VALUE Builder_add_enum(VALUE _self, VALUE name);
+VALUE Builder_finalize_to_pool(VALUE _self, VALUE pool_rb);
+
+// -----------------------------------------------------------------------------
+// Native slot storage abstraction.
+// -----------------------------------------------------------------------------
+
+#define NATIVE_SLOT_MAX_SIZE sizeof(uint64_t)
+
+size_t native_slot_size(upb_fieldtype_t type);
+void native_slot_set(upb_fieldtype_t type,
+ VALUE type_class,
+ void* memory,
+ VALUE value);
+// Atomically (with respect to Ruby VM calls) either update the value and set a
+// oneof case, or do neither. If |case_memory| is null, then no case value is
+// set.
+void native_slot_set_value_and_case(upb_fieldtype_t type,
+ VALUE type_class,
+ void* memory,
+ VALUE value,
+ uint32_t* case_memory,
+ uint32_t case_number);
+VALUE native_slot_get(upb_fieldtype_t type,
+ VALUE type_class,
+ const void* memory);
+void native_slot_init(upb_fieldtype_t type, void* memory);
+void native_slot_mark(upb_fieldtype_t type, void* memory);
+void native_slot_dup(upb_fieldtype_t type, void* to, void* from);
+void native_slot_deep_copy(upb_fieldtype_t type, void* to, void* from);
+bool native_slot_eq(upb_fieldtype_t type, void* mem1, void* mem2);
+
+VALUE native_slot_encode_and_freeze_string(upb_fieldtype_t type, VALUE value);
+void native_slot_check_int_range_precision(upb_fieldtype_t type, VALUE value);
+
+extern rb_encoding* kRubyStringUtf8Encoding;
+extern rb_encoding* kRubyStringASCIIEncoding;
+extern rb_encoding* kRubyString8bitEncoding;
+
+VALUE field_type_class(const upb_fielddef* field);
+
+#define MAP_KEY_FIELD 1
+#define MAP_VALUE_FIELD 2
+
+// Oneof case slot value to indicate that no oneof case is set. The value `0` is
+// safe because field numbers are used as case identifiers, and no field can
+// have a number of 0.
+#define ONEOF_CASE_NONE 0
+
+// These operate on a map field (i.e., a repeated field of submessages whose
+// submessage type is a map-entry msgdef).
+bool is_map_field(const upb_fielddef* field);
+const upb_fielddef* map_field_key(const upb_fielddef* field);
+const upb_fielddef* map_field_value(const upb_fielddef* field);
+
+// These operate on a map-entry msgdef.
+const upb_fielddef* map_entry_key(const upb_msgdef* msgdef);
+const upb_fielddef* map_entry_value(const upb_msgdef* msgdef);
+
+// -----------------------------------------------------------------------------
+// Repeated field container type.
+// -----------------------------------------------------------------------------
+
+typedef struct {
+ upb_fieldtype_t field_type;
+ VALUE field_type_class;
+ void* elements;
+ int size;
+ int capacity;
+} RepeatedField;
+
+void RepeatedField_mark(void* self);
+void RepeatedField_free(void* self);
+VALUE RepeatedField_alloc(VALUE klass);
+VALUE RepeatedField_init(int argc, VALUE* argv, VALUE self);
+void RepeatedField_register(VALUE module);
+
+extern const rb_data_type_t RepeatedField_type;
+extern VALUE cRepeatedField;
+
+RepeatedField* ruby_to_RepeatedField(VALUE value);
+
+VALUE RepeatedField_each(VALUE _self);
+VALUE RepeatedField_index(int argc, VALUE* argv, VALUE _self);
+void* RepeatedField_index_native(VALUE _self, int index);
+int RepeatedField_size(VALUE _self);
+VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val);
+void RepeatedField_reserve(RepeatedField* self, int new_size);
+VALUE RepeatedField_push(VALUE _self, VALUE val);
+void RepeatedField_push_native(VALUE _self, void* data);
+VALUE RepeatedField_pop_one(VALUE _self);
+VALUE RepeatedField_insert(int argc, VALUE* argv, VALUE _self);
+VALUE RepeatedField_replace(VALUE _self, VALUE list);
+VALUE RepeatedField_clear(VALUE _self);
+VALUE RepeatedField_length(VALUE _self);
+VALUE RepeatedField_dup(VALUE _self);
+VALUE RepeatedField_deep_copy(VALUE _self);
+VALUE RepeatedField_to_ary(VALUE _self);
+VALUE RepeatedField_eq(VALUE _self, VALUE _other);
+VALUE RepeatedField_hash(VALUE _self);
+VALUE RepeatedField_inspect(VALUE _self);
+VALUE RepeatedField_plus(VALUE _self, VALUE list);
+
+// Defined in repeated_field.c; also used by Map.
+void validate_type_class(upb_fieldtype_t type, VALUE klass);
+
+// -----------------------------------------------------------------------------
+// Map container type.
+// -----------------------------------------------------------------------------
+
+typedef struct {
+ upb_fieldtype_t key_type;
+ upb_fieldtype_t value_type;
+ VALUE value_type_class;
+ upb_strtable table;
+} Map;
+
+void Map_mark(void* self);
+void Map_free(void* self);
+VALUE Map_alloc(VALUE klass);
+VALUE Map_init(int argc, VALUE* argv, VALUE self);
+void Map_register(VALUE module);
+
+extern const rb_data_type_t Map_type;
+extern VALUE cMap;
+
+Map* ruby_to_Map(VALUE value);
+
+VALUE Map_each(VALUE _self);
+VALUE Map_keys(VALUE _self);
+VALUE Map_values(VALUE _self);
+VALUE Map_index(VALUE _self, VALUE key);
+VALUE Map_index_set(VALUE _self, VALUE key, VALUE value);
+VALUE Map_has_key(VALUE _self, VALUE key);
+VALUE Map_delete(VALUE _self, VALUE key);
+VALUE Map_clear(VALUE _self);
+VALUE Map_length(VALUE _self);
+VALUE Map_dup(VALUE _self);
+VALUE Map_deep_copy(VALUE _self);
+VALUE Map_eq(VALUE _self, VALUE _other);
+VALUE Map_hash(VALUE _self);
+VALUE Map_to_h(VALUE _self);
+VALUE Map_inspect(VALUE _self);
+VALUE Map_merge(VALUE _self, VALUE hashmap);
+VALUE Map_merge_into_self(VALUE _self, VALUE hashmap);
+
+typedef struct {
+ Map* self;
+ upb_strtable_iter it;
+} Map_iter;
+
+void Map_begin(VALUE _self, Map_iter* iter);
+void Map_next(Map_iter* iter);
+bool Map_done(Map_iter* iter);
+VALUE Map_iter_key(Map_iter* iter);
+VALUE Map_iter_value(Map_iter* iter);
+
+// -----------------------------------------------------------------------------
+// Message layout / storage.
+// -----------------------------------------------------------------------------
+
+#define MESSAGE_FIELD_NO_CASE ((size_t)-1)
+
+struct MessageField {
+ size_t offset;
+ size_t case_offset; // for oneofs, a uint32. Else, MESSAGE_FIELD_NO_CASE.
+};
+
+struct MessageLayout {
+ const upb_msgdef* msgdef;
+ MessageField* fields;
+ size_t size;
+};
+
+MessageLayout* create_layout(const upb_msgdef* msgdef);
+void free_layout(MessageLayout* layout);
+VALUE layout_get(MessageLayout* layout,
+ const void* storage,
+ const upb_fielddef* field);
+void layout_set(MessageLayout* layout,
+ void* storage,
+ const upb_fielddef* field,
+ VALUE val);
+void layout_init(MessageLayout* layout, void* storage);
+void layout_mark(MessageLayout* layout, void* storage);
+void layout_dup(MessageLayout* layout, void* to, void* from);
+void layout_deep_copy(MessageLayout* layout, void* to, void* from);
+VALUE layout_eq(MessageLayout* layout, void* msg1, void* msg2);
+VALUE layout_hash(MessageLayout* layout, void* storage);
+VALUE layout_inspect(MessageLayout* layout, void* storage);
+
+// -----------------------------------------------------------------------------
+// Message class creation.
+// -----------------------------------------------------------------------------
+
+struct MessageHeader {
+ Descriptor* descriptor; // kept alive by self.class.descriptor reference.
+ // Data comes after this.
+};
+
+extern rb_data_type_t Message_type;
+
+VALUE build_class_from_descriptor(Descriptor* descriptor);
+void* Message_data(void* msg);
+void Message_mark(void* self);
+void Message_free(void* self);
+VALUE Message_alloc(VALUE klass);
+VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self);
+VALUE Message_initialize(int argc, VALUE* argv, VALUE _self);
+VALUE Message_dup(VALUE _self);
+VALUE Message_deep_copy(VALUE _self);
+VALUE Message_eq(VALUE _self, VALUE _other);
+VALUE Message_hash(VALUE _self);
+VALUE Message_inspect(VALUE _self);
+VALUE Message_to_h(VALUE _self);
+VALUE Message_index(VALUE _self, VALUE field_name);
+VALUE Message_index_set(VALUE _self, VALUE field_name, VALUE value);
+VALUE Message_descriptor(VALUE klass);
+VALUE Message_decode(VALUE klass, VALUE data);
+VALUE Message_encode(VALUE klass, VALUE msg_rb);
+VALUE Message_decode_json(VALUE klass, VALUE data);
+VALUE Message_encode_json(int argc, VALUE* argv, VALUE klass);
+
+VALUE Google_Protobuf_deep_copy(VALUE self, VALUE obj);
+
+VALUE build_module_from_enumdesc(EnumDescriptor* enumdef);
+VALUE enum_lookup(VALUE self, VALUE number);
+VALUE enum_resolve(VALUE self, VALUE sym);
+
+const upb_pbdecodermethod *new_fillmsg_decodermethod(
+ Descriptor* descriptor, const void *owner);
+
+// Maximum depth allowed during encoding, to avoid stack overflows due to
+// cycles.
+#define ENCODE_MAX_NESTING 63
+
+// -----------------------------------------------------------------------------
+// Global map from upb {msg,enum}defs to wrapper Descriptor/EnumDescriptor
+// instances.
+// -----------------------------------------------------------------------------
+void add_def_obj(const void* def, VALUE value);
+VALUE get_def_obj(const void* def);
+
+// -----------------------------------------------------------------------------
+// Utilities.
+// -----------------------------------------------------------------------------
+
+void check_upb_status(const upb_status* status, const char* msg);
+
+#define CHECK_UPB(code, msg) do { \
+ upb_status status = UPB_STATUS_INIT; \
+ code; \
+ check_upb_status(&status, msg); \
+} while (0)
+
+extern ID descriptor_instancevar_interned;
+
+#endif // __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__
diff --git a/third_party/protobuf/ruby/ext/google/protobuf_c/repeated_field.c b/third_party/protobuf/ruby/ext/google/protobuf_c/repeated_field.c
new file mode 100644
index 0000000000..1c651c192d
--- /dev/null
+++ b/third_party/protobuf/ruby/ext/google/protobuf_c/repeated_field.c
@@ -0,0 +1,654 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 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 "protobuf.h"
+
+// -----------------------------------------------------------------------------
+// Repeated field container type.
+// -----------------------------------------------------------------------------
+
+const rb_data_type_t RepeatedField_type = {
+ "Google::Protobuf::RepeatedField",
+ { RepeatedField_mark, RepeatedField_free, NULL },
+};
+
+VALUE cRepeatedField;
+
+RepeatedField* ruby_to_RepeatedField(VALUE _self) {
+ RepeatedField* self;
+ TypedData_Get_Struct(_self, RepeatedField, &RepeatedField_type, self);
+ return self;
+}
+
+void* RepeatedField_memoryat(RepeatedField* self, int index, int element_size) {
+ return ((uint8_t *)self->elements) + index * element_size;
+}
+
+static int index_position(VALUE _index, RepeatedField* repeated_field) {
+ int index = NUM2INT(_index);
+ if (index < 0 && repeated_field->size > 0) {
+ index = repeated_field->size + index;
+ }
+ return index;
+}
+
+VALUE RepeatedField_subarray(VALUE _self, long beg, long len) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ int element_size = native_slot_size(self->field_type);
+ upb_fieldtype_t field_type = self->field_type;
+ VALUE field_type_class = self->field_type_class;
+
+ size_t off = beg * element_size;
+ VALUE ary = rb_ary_new2(len);
+ for (int i = beg; i < beg + len; i++, off += element_size) {
+ void* mem = ((uint8_t *)self->elements) + off;
+ VALUE elem = native_slot_get(field_type, field_type_class, mem);
+ rb_ary_push(ary, elem);
+ }
+ return ary;
+}
+
+/*
+ * call-seq:
+ * RepeatedField.each(&block)
+ *
+ * Invokes the block once for each element of the repeated field. RepeatedField
+ * also includes Enumerable; combined with this method, the repeated field thus
+ * acts like an ordinary Ruby sequence.
+ */
+VALUE RepeatedField_each(VALUE _self) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ upb_fieldtype_t field_type = self->field_type;
+ VALUE field_type_class = self->field_type_class;
+ int element_size = native_slot_size(field_type);
+
+ size_t off = 0;
+ for (int i = 0; i < self->size; i++, off += element_size) {
+ void* memory = (void *) (((uint8_t *)self->elements) + off);
+ VALUE val = native_slot_get(field_type, field_type_class, memory);
+ rb_yield(val);
+ }
+ return _self;
+}
+
+
+/*
+ * call-seq:
+ * RepeatedField.[](index) => value
+ *
+ * Accesses the element at the given index. Returns nil on out-of-bounds
+ */
+VALUE RepeatedField_index(int argc, VALUE* argv, VALUE _self) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ int element_size = native_slot_size(self->field_type);
+ upb_fieldtype_t field_type = self->field_type;
+ VALUE field_type_class = self->field_type_class;
+
+ VALUE arg = argv[0];
+ long beg, len;
+
+ if (argc == 1){
+ if (FIXNUM_P(arg)) {
+ /* standard case */
+ void* memory;
+ int index = index_position(argv[0], self);
+ if (index < 0 || index >= self->size) {
+ return Qnil;
+ }
+ memory = RepeatedField_memoryat(self, index, element_size);
+ return native_slot_get(field_type, field_type_class, memory);
+ }else{
+ /* check if idx is Range */
+ switch (rb_range_beg_len(arg, &beg, &len, self->size, 0)) {
+ case Qfalse:
+ break;
+ case Qnil:
+ return Qnil;
+ default:
+ return RepeatedField_subarray(_self, beg, len);
+ }
+ }
+ }
+ /* assume 2 arguments */
+ beg = NUM2LONG(argv[0]);
+ len = NUM2LONG(argv[1]);
+ if (beg < 0) {
+ beg += self->size;
+ }
+ if (beg >= self->size) {
+ return Qnil;
+ }
+ return RepeatedField_subarray(_self, beg, len);
+}
+
+/*
+ * call-seq:
+ * RepeatedField.[]=(index, value)
+ *
+ * Sets the element at the given index. On out-of-bounds assignments, extends
+ * the array and fills the hole (if any) with default values.
+ */
+VALUE RepeatedField_index_set(VALUE _self, VALUE _index, VALUE val) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ upb_fieldtype_t field_type = self->field_type;
+ VALUE field_type_class = self->field_type_class;
+ int element_size = native_slot_size(field_type);
+ void* memory;
+
+ int index = index_position(_index, self);
+ if (index < 0 || index >= (INT_MAX - 1)) {
+ return Qnil;
+ }
+ if (index >= self->size) {
+ upb_fieldtype_t field_type = self->field_type;
+ int element_size = native_slot_size(field_type);
+ RepeatedField_reserve(self, index + 1);
+ for (int i = self->size; i <= index; i++) {
+ void* elem = RepeatedField_memoryat(self, i, element_size);
+ native_slot_init(field_type, elem);
+ }
+ self->size = index + 1;
+ }
+
+ memory = RepeatedField_memoryat(self, index, element_size);
+ native_slot_set(field_type, field_type_class, memory, val);
+ return Qnil;
+}
+
+static int kInitialSize = 8;
+
+void RepeatedField_reserve(RepeatedField* self, int new_size) {
+ void* old_elems = self->elements;
+ int elem_size = native_slot_size(self->field_type);
+ if (new_size <= self->capacity) {
+ return;
+ }
+ if (self->capacity == 0) {
+ self->capacity = kInitialSize;
+ }
+ while (self->capacity < new_size) {
+ self->capacity *= 2;
+ }
+ self->elements = ALLOC_N(uint8_t, elem_size * self->capacity);
+ if (old_elems != NULL) {
+ memcpy(self->elements, old_elems, self->size * elem_size);
+ xfree(old_elems);
+ }
+}
+
+/*
+ * call-seq:
+ * RepeatedField.push(value)
+ *
+ * Adds a new element to the repeated field.
+ */
+VALUE RepeatedField_push(VALUE _self, VALUE val) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ upb_fieldtype_t field_type = self->field_type;
+ int element_size = native_slot_size(field_type);
+ void* memory;
+
+ RepeatedField_reserve(self, self->size + 1);
+ memory = (void *) (((uint8_t *)self->elements) + self->size * element_size);
+ native_slot_set(field_type, self->field_type_class, memory, val);
+ // native_slot_set may raise an error; bump size only after set.
+ self->size++;
+ return _self;
+}
+
+
+// Used by parsing handlers.
+void RepeatedField_push_native(VALUE _self, void* data) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ upb_fieldtype_t field_type = self->field_type;
+ int element_size = native_slot_size(field_type);
+ void* memory;
+
+ RepeatedField_reserve(self, self->size + 1);
+ memory = (void *) (((uint8_t *)self->elements) + self->size * element_size);
+ memcpy(memory, data, element_size);
+ self->size++;
+}
+
+void* RepeatedField_index_native(VALUE _self, int index) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ upb_fieldtype_t field_type = self->field_type;
+ int element_size = native_slot_size(field_type);
+ return RepeatedField_memoryat(self, index, element_size);
+}
+
+int RepeatedField_size(VALUE _self) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ return self->size;
+}
+
+/*
+ * Private ruby method, used by RepeatedField.pop
+ */
+VALUE RepeatedField_pop_one(VALUE _self) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ upb_fieldtype_t field_type = self->field_type;
+ VALUE field_type_class = self->field_type_class;
+ int element_size = native_slot_size(field_type);
+ int index;
+ void* memory;
+ VALUE ret;
+
+ if (self->size == 0) {
+ return Qnil;
+ }
+ index = self->size - 1;
+ memory = RepeatedField_memoryat(self, index, element_size);
+ ret = native_slot_get(field_type, field_type_class, memory);
+ self->size--;
+ return ret;
+}
+
+/*
+ * call-seq:
+ * RepeatedField.replace(list)
+ *
+ * Replaces the contents of the repeated field with the given list of elements.
+ */
+VALUE RepeatedField_replace(VALUE _self, VALUE list) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ Check_Type(list, T_ARRAY);
+ self->size = 0;
+ for (int i = 0; i < RARRAY_LEN(list); i++) {
+ RepeatedField_push(_self, rb_ary_entry(list, i));
+ }
+ return list;
+}
+
+/*
+ * call-seq:
+ * RepeatedField.clear
+ *
+ * Clears (removes all elements from) this repeated field.
+ */
+VALUE RepeatedField_clear(VALUE _self) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ self->size = 0;
+ return _self;
+}
+
+/*
+ * call-seq:
+ * RepeatedField.length
+ *
+ * Returns the length of this repeated field.
+ */
+VALUE RepeatedField_length(VALUE _self) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ return INT2NUM(self->size);
+}
+
+static VALUE RepeatedField_new_this_type(VALUE _self) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ VALUE new_rptfield = Qnil;
+ VALUE element_type = fieldtype_to_ruby(self->field_type);
+ if (self->field_type_class != Qnil) {
+ new_rptfield = rb_funcall(CLASS_OF(_self), rb_intern("new"), 2,
+ element_type, self->field_type_class);
+ } else {
+ new_rptfield = rb_funcall(CLASS_OF(_self), rb_intern("new"), 1,
+ element_type);
+ }
+ return new_rptfield;
+}
+
+/*
+ * call-seq:
+ * RepeatedField.dup => repeated_field
+ *
+ * Duplicates this repeated field with a shallow copy. References to all
+ * non-primitive element objects (e.g., submessages) are shared.
+ */
+VALUE RepeatedField_dup(VALUE _self) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ VALUE new_rptfield = RepeatedField_new_this_type(_self);
+ RepeatedField* new_rptfield_self = ruby_to_RepeatedField(new_rptfield);
+ upb_fieldtype_t field_type = self->field_type;
+ size_t elem_size = native_slot_size(field_type);
+ size_t off = 0;
+ RepeatedField_reserve(new_rptfield_self, self->size);
+ for (int i = 0; i < self->size; i++, off += elem_size) {
+ void* to_mem = (uint8_t *)new_rptfield_self->elements + off;
+ void* from_mem = (uint8_t *)self->elements + off;
+ native_slot_dup(field_type, to_mem, from_mem);
+ new_rptfield_self->size++;
+ }
+
+ return new_rptfield;
+}
+
+// Internal only: used by Google::Protobuf.deep_copy.
+VALUE RepeatedField_deep_copy(VALUE _self) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ VALUE new_rptfield = RepeatedField_new_this_type(_self);
+ RepeatedField* new_rptfield_self = ruby_to_RepeatedField(new_rptfield);
+ upb_fieldtype_t field_type = self->field_type;
+ size_t elem_size = native_slot_size(field_type);
+ size_t off = 0;
+ RepeatedField_reserve(new_rptfield_self, self->size);
+ for (int i = 0; i < self->size; i++, off += elem_size) {
+ void* to_mem = (uint8_t *)new_rptfield_self->elements + off;
+ void* from_mem = (uint8_t *)self->elements + off;
+ native_slot_deep_copy(field_type, to_mem, from_mem);
+ new_rptfield_self->size++;
+ }
+
+ return new_rptfield;
+}
+
+/*
+ * call-seq:
+ * RepeatedField.to_ary => array
+ *
+ * Used when converted implicitly into array, e.g. compared to an Array.
+ * Also called as a fallback of Object#to_a
+ */
+VALUE RepeatedField_to_ary(VALUE _self) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ upb_fieldtype_t field_type = self->field_type;
+
+ size_t elem_size = native_slot_size(field_type);
+ size_t off = 0;
+ VALUE ary = rb_ary_new2(self->size);
+ for (int i = 0; i < self->size; i++, off += elem_size) {
+ void* mem = ((uint8_t *)self->elements) + off;
+ VALUE elem = native_slot_get(field_type, self->field_type_class, mem);
+ rb_ary_push(ary, elem);
+ }
+ return ary;
+}
+
+/*
+ * call-seq:
+ * RepeatedField.==(other) => boolean
+ *
+ * Compares this repeated field to another. Repeated fields are equal if their
+ * element types are equal, their lengths are equal, and each element is equal.
+ * Elements are compared as per normal Ruby semantics, by calling their :==
+ * methods (or performing a more efficient comparison for primitive types).
+ *
+ * Repeated fields with dissimilar element types are never equal, even if value
+ * comparison (for example, between integers and floats) would have otherwise
+ * indicated that every element has equal value.
+ */
+VALUE RepeatedField_eq(VALUE _self, VALUE _other) {
+ RepeatedField* self;
+ RepeatedField* other;
+
+ if (_self == _other) {
+ return Qtrue;
+ }
+
+ if (TYPE(_other) == T_ARRAY) {
+ VALUE self_ary = RepeatedField_to_ary(_self);
+ return rb_equal(self_ary, _other);
+ }
+
+ self = ruby_to_RepeatedField(_self);
+ other = ruby_to_RepeatedField(_other);
+ if (self->field_type != other->field_type ||
+ self->field_type_class != other->field_type_class ||
+ self->size != other->size) {
+ return Qfalse;
+ }
+
+ {
+ upb_fieldtype_t field_type = self->field_type;
+ size_t elem_size = native_slot_size(field_type);
+ size_t off = 0;
+ for (int i = 0; i < self->size; i++, off += elem_size) {
+ void* self_mem = ((uint8_t *)self->elements) + off;
+ void* other_mem = ((uint8_t *)other->elements) + off;
+ if (!native_slot_eq(field_type, self_mem, other_mem)) {
+ return Qfalse;
+ }
+ }
+ return Qtrue;
+ }
+}
+
+/*
+ * call-seq:
+ * RepeatedField.hash => hash_value
+ *
+ * Returns a hash value computed from this repeated field's elements.
+ */
+VALUE RepeatedField_hash(VALUE _self) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ st_index_t h = rb_hash_start(0);
+ VALUE hash_sym = rb_intern("hash");
+ upb_fieldtype_t field_type = self->field_type;
+ VALUE field_type_class = self->field_type_class;
+ size_t elem_size = native_slot_size(field_type);
+ size_t off = 0;
+ for (int i = 0; i < self->size; i++, off += elem_size) {
+ void* mem = ((uint8_t *)self->elements) + off;
+ VALUE elem = native_slot_get(field_type, field_type_class, mem);
+ h = rb_hash_uint(h, NUM2LONG(rb_funcall(elem, hash_sym, 0)));
+ }
+ h = rb_hash_end(h);
+
+ return INT2FIX(h);
+}
+
+/*
+ * call-seq:
+ * RepeatedField.+(other) => repeated field
+ *
+ * Returns a new repeated field that contains the concatenated list of this
+ * repeated field's elements and other's elements. The other (second) list may
+ * be either another repeated field or a Ruby array.
+ */
+VALUE RepeatedField_plus(VALUE _self, VALUE list) {
+ VALUE dupped = RepeatedField_dup(_self);
+
+ if (TYPE(list) == T_ARRAY) {
+ for (int i = 0; i < RARRAY_LEN(list); i++) {
+ VALUE elem = rb_ary_entry(list, i);
+ RepeatedField_push(dupped, elem);
+ }
+ } else if (RB_TYPE_P(list, T_DATA) && RTYPEDDATA_P(list) &&
+ RTYPEDDATA_TYPE(list) == &RepeatedField_type) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ RepeatedField* list_rptfield = ruby_to_RepeatedField(list);
+ if (self->field_type != list_rptfield->field_type ||
+ self->field_type_class != list_rptfield->field_type_class) {
+ rb_raise(rb_eArgError,
+ "Attempt to append RepeatedField with different element type.");
+ }
+ for (int i = 0; i < list_rptfield->size; i++) {
+ void* mem = RepeatedField_index_native(list, i);
+ RepeatedField_push_native(dupped, mem);
+ }
+ } else {
+ rb_raise(rb_eArgError, "Unknown type appending to RepeatedField");
+ }
+
+ return dupped;
+}
+
+/*
+ * call-seq:
+ * RepeatedField.concat(other) => self
+ *
+ * concats the passed in array to self. Returns a Ruby array.
+ */
+VALUE RepeatedField_concat(VALUE _self, VALUE list) {
+ Check_Type(list, T_ARRAY);
+ for (int i = 0; i < RARRAY_LEN(list); i++) {
+ RepeatedField_push(_self, rb_ary_entry(list, i));
+ }
+ return _self;
+}
+
+
+void validate_type_class(upb_fieldtype_t type, VALUE klass) {
+ if (rb_ivar_get(klass, descriptor_instancevar_interned) == Qnil) {
+ rb_raise(rb_eArgError,
+ "Type class has no descriptor. Please pass a "
+ "class or enum as returned by the DescriptorPool.");
+ }
+ if (type == UPB_TYPE_MESSAGE) {
+ VALUE desc = rb_ivar_get(klass, descriptor_instancevar_interned);
+ if (!RB_TYPE_P(desc, T_DATA) || !RTYPEDDATA_P(desc) ||
+ RTYPEDDATA_TYPE(desc) != &_Descriptor_type) {
+ rb_raise(rb_eArgError, "Descriptor has an incorrect type.");
+ }
+ if (rb_get_alloc_func(klass) != &Message_alloc) {
+ rb_raise(rb_eArgError,
+ "Message class was not returned by the DescriptorPool.");
+ }
+ } else if (type == UPB_TYPE_ENUM) {
+ VALUE enumdesc = rb_ivar_get(klass, descriptor_instancevar_interned);
+ if (!RB_TYPE_P(enumdesc, T_DATA) || !RTYPEDDATA_P(enumdesc) ||
+ RTYPEDDATA_TYPE(enumdesc) != &_EnumDescriptor_type) {
+ rb_raise(rb_eArgError, "Descriptor has an incorrect type.");
+ }
+ }
+}
+
+void RepeatedField_init_args(int argc, VALUE* argv,
+ VALUE _self) {
+ RepeatedField* self = ruby_to_RepeatedField(_self);
+ VALUE ary = Qnil;
+ if (argc < 1) {
+ rb_raise(rb_eArgError, "Expected at least 1 argument.");
+ }
+ self->field_type = ruby_to_fieldtype(argv[0]);
+
+ if (self->field_type == UPB_TYPE_MESSAGE ||
+ self->field_type == UPB_TYPE_ENUM) {
+ if (argc < 2) {
+ rb_raise(rb_eArgError, "Expected at least 2 arguments for message/enum.");
+ }
+ self->field_type_class = argv[1];
+ if (argc > 2) {
+ ary = argv[2];
+ }
+ validate_type_class(self->field_type, self->field_type_class);
+ } else {
+ if (argc > 2) {
+ rb_raise(rb_eArgError, "Too many arguments: expected 1 or 2.");
+ }
+ if (argc > 1) {
+ ary = argv[1];
+ }
+ }
+
+ if (ary != Qnil) {
+ if (!RB_TYPE_P(ary, T_ARRAY)) {
+ rb_raise(rb_eArgError, "Expected array as initialize argument");
+ }
+ for (int i = 0; i < RARRAY_LEN(ary); i++) {
+ RepeatedField_push(_self, rb_ary_entry(ary, i));
+ }
+ }
+}
+
+// Mark, free, alloc, init and class setup functions.
+
+void RepeatedField_mark(void* _self) {
+ RepeatedField* self = (RepeatedField*)_self;
+ upb_fieldtype_t field_type = self->field_type;
+ int element_size = native_slot_size(field_type);
+ rb_gc_mark(self->field_type_class);
+ for (int i = 0; i < self->size; i++) {
+ void* memory = (((uint8_t *)self->elements) + i * element_size);
+ native_slot_mark(self->field_type, memory);
+ }
+}
+
+void RepeatedField_free(void* _self) {
+ RepeatedField* self = (RepeatedField*)_self;
+ xfree(self->elements);
+ xfree(self);
+}
+
+/*
+ * call-seq:
+ * RepeatedField.new(type, type_class = nil, initial_elems = [])
+ *
+ * Creates a new repeated field. The provided type must be a Ruby symbol, and
+ * can take on the same values as those accepted by FieldDescriptor#type=. If
+ * the type is :message or :enum, type_class must be non-nil, and must be the
+ * Ruby class or module returned by Descriptor#msgclass or
+ * EnumDescriptor#enummodule, respectively. An initial list of elements may also
+ * be provided.
+ */
+VALUE RepeatedField_alloc(VALUE klass) {
+ RepeatedField* self = ALLOC(RepeatedField);
+ self->elements = NULL;
+ self->size = 0;
+ self->capacity = 0;
+ self->field_type = -1;
+ self->field_type_class = Qnil;
+ return TypedData_Wrap_Struct(klass, &RepeatedField_type, self);
+}
+
+VALUE RepeatedField_init(int argc, VALUE* argv, VALUE self) {
+ RepeatedField_init_args(argc, argv, self);
+ return Qnil;
+}
+
+void RepeatedField_register(VALUE module) {
+ VALUE klass = rb_define_class_under(
+ module, "RepeatedField", rb_cObject);
+ rb_define_alloc_func(klass, RepeatedField_alloc);
+ cRepeatedField = klass;
+ rb_gc_register_address(&cRepeatedField);
+
+ rb_define_method(klass, "initialize",
+ RepeatedField_init, -1);
+ rb_define_method(klass, "each", RepeatedField_each, 0);
+ rb_define_method(klass, "[]", RepeatedField_index, -1);
+ rb_define_method(klass, "at", RepeatedField_index, -1);
+ rb_define_method(klass, "[]=", RepeatedField_index_set, 2);
+ rb_define_method(klass, "push", RepeatedField_push, 1);
+ rb_define_method(klass, "<<", RepeatedField_push, 1);
+ rb_define_private_method(klass, "pop_one", RepeatedField_pop_one, 0);
+ rb_define_method(klass, "replace", RepeatedField_replace, 1);
+ rb_define_method(klass, "clear", RepeatedField_clear, 0);
+ rb_define_method(klass, "length", RepeatedField_length, 0);
+ rb_define_method(klass, "size", RepeatedField_length, 0);
+ rb_define_method(klass, "dup", RepeatedField_dup, 0);
+ // Also define #clone so that we don't inherit Object#clone.
+ rb_define_method(klass, "clone", RepeatedField_dup, 0);
+ rb_define_method(klass, "==", RepeatedField_eq, 1);
+ rb_define_method(klass, "to_ary", RepeatedField_to_ary, 0);
+ rb_define_method(klass, "hash", RepeatedField_hash, 0);
+ rb_define_method(klass, "+", RepeatedField_plus, 1);
+ rb_define_method(klass, "concat", RepeatedField_concat, 1);
+ rb_include_module(klass, rb_mEnumerable);
+}
diff --git a/third_party/protobuf/ruby/ext/google/protobuf_c/storage.c b/third_party/protobuf/ruby/ext/google/protobuf_c/storage.c
new file mode 100644
index 0000000000..3ff2bda6bb
--- /dev/null
+++ b/third_party/protobuf/ruby/ext/google/protobuf_c/storage.c
@@ -0,0 +1,893 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 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 "protobuf.h"
+
+#include <math.h>
+
+#include <ruby/encoding.h>
+
+// -----------------------------------------------------------------------------
+// Ruby <-> native slot management.
+// -----------------------------------------------------------------------------
+
+#define DEREF(memory, type) *(type*)(memory)
+
+size_t native_slot_size(upb_fieldtype_t type) {
+ switch (type) {
+ case UPB_TYPE_FLOAT: return 4;
+ case UPB_TYPE_DOUBLE: return 8;
+ case UPB_TYPE_BOOL: return 1;
+ case UPB_TYPE_STRING: return sizeof(VALUE);
+ case UPB_TYPE_BYTES: return sizeof(VALUE);
+ case UPB_TYPE_MESSAGE: return sizeof(VALUE);
+ case UPB_TYPE_ENUM: return 4;
+ case UPB_TYPE_INT32: return 4;
+ case UPB_TYPE_INT64: return 8;
+ case UPB_TYPE_UINT32: return 4;
+ case UPB_TYPE_UINT64: return 8;
+ default: return 0;
+ }
+}
+
+static VALUE value_from_default(const upb_fielddef *field) {
+ switch (upb_fielddef_type(field)) {
+ case UPB_TYPE_FLOAT: return DBL2NUM(upb_fielddef_defaultfloat(field));
+ case UPB_TYPE_DOUBLE: return DBL2NUM(upb_fielddef_defaultdouble(field));
+ case UPB_TYPE_BOOL:
+ return upb_fielddef_defaultbool(field) ? Qtrue : Qfalse;
+ case UPB_TYPE_MESSAGE: return Qnil;
+ case UPB_TYPE_ENUM: {
+ const upb_enumdef *enumdef = upb_fielddef_enumsubdef(field);
+ int32_t num = upb_fielddef_defaultint32(field);
+ const char *label = upb_enumdef_iton(enumdef, num);
+ if (label) {
+ return ID2SYM(rb_intern(label));
+ } else {
+ return INT2NUM(num);
+ }
+ }
+ case UPB_TYPE_INT32: return INT2NUM(upb_fielddef_defaultint32(field));
+ case UPB_TYPE_INT64: return LL2NUM(upb_fielddef_defaultint64(field));;
+ case UPB_TYPE_UINT32: return UINT2NUM(upb_fielddef_defaultuint32(field));
+ case UPB_TYPE_UINT64: return ULL2NUM(upb_fielddef_defaultuint64(field));
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ size_t size;
+ const char *str = upb_fielddef_defaultstr(field, &size);
+ return rb_str_new(str, size);
+ }
+ default: return Qnil;
+ }
+}
+
+static bool is_ruby_num(VALUE value) {
+ return (TYPE(value) == T_FLOAT ||
+ TYPE(value) == T_FIXNUM ||
+ TYPE(value) == T_BIGNUM);
+}
+
+void native_slot_check_int_range_precision(upb_fieldtype_t type, VALUE val) {
+ if (!is_ruby_num(val)) {
+ rb_raise(rb_eTypeError, "Expected number type for integral field.");
+ }
+
+ // NUM2{INT,UINT,LL,ULL} macros do the appropriate range checks on upper
+ // bound; we just need to do precision checks (i.e., disallow rounding) and
+ // check for < 0 on unsigned types.
+ if (TYPE(val) == T_FLOAT) {
+ double dbl_val = NUM2DBL(val);
+ if (floor(dbl_val) != dbl_val) {
+ rb_raise(rb_eRangeError,
+ "Non-integral floating point value assigned to integer field.");
+ }
+ }
+ if (type == UPB_TYPE_UINT32 || type == UPB_TYPE_UINT64) {
+ if (NUM2DBL(val) < 0) {
+ rb_raise(rb_eRangeError,
+ "Assigning negative value to unsigned integer field.");
+ }
+ }
+}
+
+VALUE native_slot_encode_and_freeze_string(upb_fieldtype_t type, VALUE value) {
+ rb_encoding* desired_encoding = (type == UPB_TYPE_STRING) ?
+ kRubyStringUtf8Encoding : kRubyString8bitEncoding;
+ VALUE desired_encoding_value = rb_enc_from_encoding(desired_encoding);
+
+ // Note: this will not duplicate underlying string data unless necessary.
+ value = rb_str_encode(value, desired_encoding_value, 0, Qnil);
+
+ if (type == UPB_TYPE_STRING &&
+ rb_enc_str_coderange(value) == ENC_CODERANGE_BROKEN) {
+ rb_raise(rb_eEncodingError, "String is invalid UTF-8");
+ }
+
+ // Ensure the data remains valid. Since we called #encode a moment ago,
+ // this does not freeze the string the user assigned.
+ rb_obj_freeze(value);
+
+ return value;
+}
+
+void native_slot_set(upb_fieldtype_t type, VALUE type_class,
+ void* memory, VALUE value) {
+ native_slot_set_value_and_case(type, type_class, memory, value, NULL, 0);
+}
+
+void native_slot_set_value_and_case(upb_fieldtype_t type, VALUE type_class,
+ void* memory, VALUE value,
+ uint32_t* case_memory,
+ uint32_t case_number) {
+ // Note that in order to atomically change the value in memory and the case
+ // value (w.r.t. Ruby VM calls), we must set the value at |memory| only after
+ // all Ruby VM calls are complete. The case is then set at the bottom of this
+ // function.
+ switch (type) {
+ case UPB_TYPE_FLOAT:
+ if (!is_ruby_num(value)) {
+ rb_raise(rb_eTypeError, "Expected number type for float field.");
+ }
+ DEREF(memory, float) = NUM2DBL(value);
+ break;
+ case UPB_TYPE_DOUBLE:
+ if (!is_ruby_num(value)) {
+ rb_raise(rb_eTypeError, "Expected number type for double field.");
+ }
+ DEREF(memory, double) = NUM2DBL(value);
+ break;
+ case UPB_TYPE_BOOL: {
+ int8_t val = -1;
+ if (value == Qtrue) {
+ val = 1;
+ } else if (value == Qfalse) {
+ val = 0;
+ } else {
+ rb_raise(rb_eTypeError, "Invalid argument for boolean field.");
+ }
+ DEREF(memory, int8_t) = val;
+ break;
+ }
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ if (CLASS_OF(value) != rb_cString) {
+ rb_raise(rb_eTypeError, "Invalid argument for string field.");
+ }
+
+ DEREF(memory, VALUE) = native_slot_encode_and_freeze_string(type, value);
+ break;
+ }
+ case UPB_TYPE_MESSAGE: {
+ if (CLASS_OF(value) == CLASS_OF(Qnil)) {
+ value = Qnil;
+ } else if (CLASS_OF(value) != type_class) {
+ rb_raise(rb_eTypeError,
+ "Invalid type %s to assign to submessage field.",
+ rb_class2name(CLASS_OF(value)));
+ }
+ DEREF(memory, VALUE) = value;
+ break;
+ }
+ case UPB_TYPE_ENUM: {
+ int32_t int_val = 0;
+ if (!is_ruby_num(value) && TYPE(value) != T_SYMBOL) {
+ rb_raise(rb_eTypeError,
+ "Expected number or symbol type for enum field.");
+ }
+ if (TYPE(value) == T_SYMBOL) {
+ // Ensure that the given symbol exists in the enum module.
+ VALUE lookup = rb_funcall(type_class, rb_intern("resolve"), 1, value);
+ if (lookup == Qnil) {
+ rb_raise(rb_eRangeError, "Unknown symbol value for enum field.");
+ } else {
+ int_val = NUM2INT(lookup);
+ }
+ } else {
+ native_slot_check_int_range_precision(UPB_TYPE_INT32, value);
+ int_val = NUM2INT(value);
+ }
+ DEREF(memory, int32_t) = int_val;
+ break;
+ }
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_UINT64:
+ native_slot_check_int_range_precision(type, value);
+ switch (type) {
+ case UPB_TYPE_INT32:
+ DEREF(memory, int32_t) = NUM2INT(value);
+ break;
+ case UPB_TYPE_INT64:
+ DEREF(memory, int64_t) = NUM2LL(value);
+ break;
+ case UPB_TYPE_UINT32:
+ DEREF(memory, uint32_t) = NUM2UINT(value);
+ break;
+ case UPB_TYPE_UINT64:
+ DEREF(memory, uint64_t) = NUM2ULL(value);
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (case_memory != NULL) {
+ *case_memory = case_number;
+ }
+}
+
+VALUE native_slot_get(upb_fieldtype_t type,
+ VALUE type_class,
+ const void* memory) {
+ switch (type) {
+ case UPB_TYPE_FLOAT:
+ return DBL2NUM(DEREF(memory, float));
+ case UPB_TYPE_DOUBLE:
+ return DBL2NUM(DEREF(memory, double));
+ case UPB_TYPE_BOOL:
+ return DEREF(memory, int8_t) ? Qtrue : Qfalse;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_MESSAGE:
+ return DEREF(memory, VALUE);
+ case UPB_TYPE_ENUM: {
+ int32_t val = DEREF(memory, int32_t);
+ VALUE symbol = enum_lookup(type_class, INT2NUM(val));
+ if (symbol == Qnil) {
+ return INT2NUM(val);
+ } else {
+ return symbol;
+ }
+ }
+ case UPB_TYPE_INT32:
+ return INT2NUM(DEREF(memory, int32_t));
+ case UPB_TYPE_INT64:
+ return LL2NUM(DEREF(memory, int64_t));
+ case UPB_TYPE_UINT32:
+ return UINT2NUM(DEREF(memory, uint32_t));
+ case UPB_TYPE_UINT64:
+ return ULL2NUM(DEREF(memory, uint64_t));
+ default:
+ return Qnil;
+ }
+}
+
+void native_slot_init(upb_fieldtype_t type, void* memory) {
+ switch (type) {
+ case UPB_TYPE_FLOAT:
+ DEREF(memory, float) = 0.0;
+ break;
+ case UPB_TYPE_DOUBLE:
+ DEREF(memory, double) = 0.0;
+ break;
+ case UPB_TYPE_BOOL:
+ DEREF(memory, int8_t) = 0;
+ break;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ DEREF(memory, VALUE) = rb_str_new2("");
+ rb_enc_associate(DEREF(memory, VALUE), (type == UPB_TYPE_BYTES) ?
+ kRubyString8bitEncoding : kRubyStringUtf8Encoding);
+ break;
+ case UPB_TYPE_MESSAGE:
+ DEREF(memory, VALUE) = Qnil;
+ break;
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32:
+ DEREF(memory, int32_t) = 0;
+ break;
+ case UPB_TYPE_INT64:
+ DEREF(memory, int64_t) = 0;
+ break;
+ case UPB_TYPE_UINT32:
+ DEREF(memory, uint32_t) = 0;
+ break;
+ case UPB_TYPE_UINT64:
+ DEREF(memory, uint64_t) = 0;
+ break;
+ default:
+ break;
+ }
+}
+
+void native_slot_mark(upb_fieldtype_t type, void* memory) {
+ switch (type) {
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_MESSAGE:
+ rb_gc_mark(DEREF(memory, VALUE));
+ break;
+ default:
+ break;
+ }
+}
+
+void native_slot_dup(upb_fieldtype_t type, void* to, void* from) {
+ memcpy(to, from, native_slot_size(type));
+}
+
+void native_slot_deep_copy(upb_fieldtype_t type, void* to, void* from) {
+ switch (type) {
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ VALUE from_val = DEREF(from, VALUE);
+ DEREF(to, VALUE) = (from_val != Qnil) ?
+ rb_funcall(from_val, rb_intern("dup"), 0) : Qnil;
+ break;
+ }
+ case UPB_TYPE_MESSAGE: {
+ VALUE from_val = DEREF(from, VALUE);
+ DEREF(to, VALUE) = (from_val != Qnil) ?
+ Message_deep_copy(from_val) : Qnil;
+ break;
+ }
+ default:
+ memcpy(to, from, native_slot_size(type));
+ }
+}
+
+bool native_slot_eq(upb_fieldtype_t type, void* mem1, void* mem2) {
+ switch (type) {
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_MESSAGE: {
+ VALUE val1 = DEREF(mem1, VALUE);
+ VALUE val2 = DEREF(mem2, VALUE);
+ VALUE ret = rb_funcall(val1, rb_intern("=="), 1, val2);
+ return ret == Qtrue;
+ }
+ default:
+ return !memcmp(mem1, mem2, native_slot_size(type));
+ }
+}
+
+// -----------------------------------------------------------------------------
+// Map field utilities.
+// -----------------------------------------------------------------------------
+
+const upb_msgdef* tryget_map_entry_msgdef(const upb_fielddef* field) {
+ const upb_msgdef* subdef;
+ if (upb_fielddef_label(field) != UPB_LABEL_REPEATED ||
+ upb_fielddef_type(field) != UPB_TYPE_MESSAGE) {
+ return NULL;
+ }
+ subdef = upb_fielddef_msgsubdef(field);
+ return upb_msgdef_mapentry(subdef) ? subdef : NULL;
+}
+
+const upb_msgdef *map_entry_msgdef(const upb_fielddef* field) {
+ const upb_msgdef* subdef = tryget_map_entry_msgdef(field);
+ assert(subdef);
+ return subdef;
+}
+
+bool is_map_field(const upb_fielddef *field) {
+ return tryget_map_entry_msgdef(field) != NULL;
+}
+
+const upb_fielddef* map_field_key(const upb_fielddef* field) {
+ const upb_msgdef* subdef = map_entry_msgdef(field);
+ return map_entry_key(subdef);
+}
+
+const upb_fielddef* map_field_value(const upb_fielddef* field) {
+ const upb_msgdef* subdef = map_entry_msgdef(field);
+ return map_entry_value(subdef);
+}
+
+const upb_fielddef* map_entry_key(const upb_msgdef* msgdef) {
+ const upb_fielddef* key_field = upb_msgdef_itof(msgdef, MAP_KEY_FIELD);
+ assert(key_field != NULL);
+ return key_field;
+}
+
+const upb_fielddef* map_entry_value(const upb_msgdef* msgdef) {
+ const upb_fielddef* value_field = upb_msgdef_itof(msgdef, MAP_VALUE_FIELD);
+ assert(value_field != NULL);
+ return value_field;
+}
+
+// -----------------------------------------------------------------------------
+// Memory layout management.
+// -----------------------------------------------------------------------------
+
+static size_t align_up_to(size_t offset, size_t granularity) {
+ // Granularity must be a power of two.
+ return (offset + granularity - 1) & ~(granularity - 1);
+}
+
+MessageLayout* create_layout(const upb_msgdef* msgdef) {
+ MessageLayout* layout = ALLOC(MessageLayout);
+ int nfields = upb_msgdef_numfields(msgdef);
+ upb_msg_field_iter it;
+ upb_msg_oneof_iter oit;
+ size_t off = 0;
+
+ layout->fields = ALLOC_N(MessageField, nfields);
+
+ for (upb_msg_field_begin(&it, msgdef);
+ !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* field = upb_msg_iter_field(&it);
+ size_t field_size;
+
+ if (upb_fielddef_containingoneof(field)) {
+ // Oneofs are handled separately below.
+ continue;
+ }
+
+ // Allocate |field_size| bytes for this field in the layout.
+ field_size = 0;
+ if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
+ field_size = sizeof(VALUE);
+ } else {
+ field_size = native_slot_size(upb_fielddef_type(field));
+ }
+ // Align current offset up to |size| granularity.
+ off = align_up_to(off, field_size);
+ layout->fields[upb_fielddef_index(field)].offset = off;
+ layout->fields[upb_fielddef_index(field)].case_offset =
+ MESSAGE_FIELD_NO_CASE;
+ off += field_size;
+ }
+
+ // Handle oneofs now -- we iterate over oneofs specifically and allocate only
+ // one slot per oneof.
+ //
+ // We assign all value slots first, then pack the 'case' fields at the end,
+ // since in the common case (modern 64-bit platform) these are 8 bytes and 4
+ // bytes respectively and we want to avoid alignment overhead.
+ //
+ // Note that we reserve 4 bytes (a uint32) per 'case' slot because the value
+ // space for oneof cases is conceptually as wide as field tag numbers. In
+ // practice, it's unlikely that a oneof would have more than e.g. 256 or 64K
+ // members (8 or 16 bits respectively), so conceivably we could assign
+ // consecutive case numbers and then pick a smaller oneof case slot size, but
+ // the complexity to implement this indirection is probably not worthwhile.
+ for (upb_msg_oneof_begin(&oit, msgdef);
+ !upb_msg_oneof_done(&oit);
+ upb_msg_oneof_next(&oit)) {
+ const upb_oneofdef* oneof = upb_msg_iter_oneof(&oit);
+ upb_oneof_iter fit;
+
+ // Always allocate NATIVE_SLOT_MAX_SIZE bytes, but share the slot between
+ // all fields.
+ size_t field_size = NATIVE_SLOT_MAX_SIZE;
+ // Align the offset.
+ off = align_up_to(off, field_size);
+ // Assign all fields in the oneof this same offset.
+ for (upb_oneof_begin(&fit, oneof);
+ !upb_oneof_done(&fit);
+ upb_oneof_next(&fit)) {
+ const upb_fielddef* field = upb_oneof_iter_field(&fit);
+ layout->fields[upb_fielddef_index(field)].offset = off;
+ }
+ off += field_size;
+ }
+
+ // Now the case fields.
+ for (upb_msg_oneof_begin(&oit, msgdef);
+ !upb_msg_oneof_done(&oit);
+ upb_msg_oneof_next(&oit)) {
+ const upb_oneofdef* oneof = upb_msg_iter_oneof(&oit);
+ upb_oneof_iter fit;
+
+ size_t field_size = sizeof(uint32_t);
+ // Align the offset.
+ off = (off + field_size - 1) & ~(field_size - 1);
+ // Assign all fields in the oneof this same offset.
+ for (upb_oneof_begin(&fit, oneof);
+ !upb_oneof_done(&fit);
+ upb_oneof_next(&fit)) {
+ const upb_fielddef* field = upb_oneof_iter_field(&fit);
+ layout->fields[upb_fielddef_index(field)].case_offset = off;
+ }
+ off += field_size;
+ }
+
+ layout->size = off;
+
+ layout->msgdef = msgdef;
+ upb_msgdef_ref(layout->msgdef, &layout->msgdef);
+
+ return layout;
+}
+
+void free_layout(MessageLayout* layout) {
+ xfree(layout->fields);
+ upb_msgdef_unref(layout->msgdef, &layout->msgdef);
+ xfree(layout);
+}
+
+VALUE field_type_class(const upb_fielddef* field) {
+ VALUE type_class = Qnil;
+ if (upb_fielddef_type(field) == UPB_TYPE_MESSAGE) {
+ VALUE submsgdesc =
+ get_def_obj(upb_fielddef_subdef(field));
+ type_class = Descriptor_msgclass(submsgdesc);
+ } else if (upb_fielddef_type(field) == UPB_TYPE_ENUM) {
+ VALUE subenumdesc =
+ get_def_obj(upb_fielddef_subdef(field));
+ type_class = EnumDescriptor_enummodule(subenumdesc);
+ }
+ return type_class;
+}
+
+static void* slot_memory(MessageLayout* layout,
+ const void* storage,
+ const upb_fielddef* field) {
+ return ((uint8_t *)storage) +
+ layout->fields[upb_fielddef_index(field)].offset;
+}
+
+static uint32_t* slot_oneof_case(MessageLayout* layout,
+ const void* storage,
+ const upb_fielddef* field) {
+ return (uint32_t *)(((uint8_t *)storage) +
+ layout->fields[upb_fielddef_index(field)].case_offset);
+}
+
+
+VALUE layout_get(MessageLayout* layout,
+ const void* storage,
+ const upb_fielddef* field) {
+ void* memory = slot_memory(layout, storage, field);
+ uint32_t* oneof_case = slot_oneof_case(layout, storage, field);
+
+ if (upb_fielddef_containingoneof(field)) {
+ if (*oneof_case != upb_fielddef_number(field)) {
+ return value_from_default(field);
+ }
+ return native_slot_get(upb_fielddef_type(field),
+ field_type_class(field),
+ memory);
+ } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
+ return *((VALUE *)memory);
+ } else {
+ return native_slot_get(upb_fielddef_type(field),
+ field_type_class(field),
+ memory);
+ }
+}
+
+static void check_repeated_field_type(VALUE val, const upb_fielddef* field) {
+ RepeatedField* self;
+ assert(upb_fielddef_label(field) == UPB_LABEL_REPEATED);
+
+ if (!RB_TYPE_P(val, T_DATA) || !RTYPEDDATA_P(val) ||
+ RTYPEDDATA_TYPE(val) != &RepeatedField_type) {
+ rb_raise(rb_eTypeError, "Expected repeated field array");
+ }
+
+ self = ruby_to_RepeatedField(val);
+ if (self->field_type != upb_fielddef_type(field)) {
+ rb_raise(rb_eTypeError, "Repeated field array has wrong element type");
+ }
+
+ if (self->field_type == UPB_TYPE_MESSAGE ||
+ self->field_type == UPB_TYPE_ENUM) {
+ if (self->field_type_class !=
+ get_def_obj(upb_fielddef_subdef(field))) {
+ rb_raise(rb_eTypeError,
+ "Repeated field array has wrong message/enum class");
+ }
+ }
+}
+
+static void check_map_field_type(VALUE val, const upb_fielddef* field) {
+ const upb_fielddef* key_field = map_field_key(field);
+ const upb_fielddef* value_field = map_field_value(field);
+ Map* self;
+
+ if (!RB_TYPE_P(val, T_DATA) || !RTYPEDDATA_P(val) ||
+ RTYPEDDATA_TYPE(val) != &Map_type) {
+ rb_raise(rb_eTypeError, "Expected Map instance");
+ }
+
+ self = ruby_to_Map(val);
+ if (self->key_type != upb_fielddef_type(key_field)) {
+ rb_raise(rb_eTypeError, "Map key type does not match field's key type");
+ }
+ if (self->value_type != upb_fielddef_type(value_field)) {
+ rb_raise(rb_eTypeError, "Map value type does not match field's value type");
+ }
+ if (upb_fielddef_type(value_field) == UPB_TYPE_MESSAGE ||
+ upb_fielddef_type(value_field) == UPB_TYPE_ENUM) {
+ if (self->value_type_class !=
+ get_def_obj(upb_fielddef_subdef(value_field))) {
+ rb_raise(rb_eTypeError,
+ "Map value type has wrong message/enum class");
+ }
+ }
+}
+
+
+void layout_set(MessageLayout* layout,
+ void* storage,
+ const upb_fielddef* field,
+ VALUE val) {
+ void* memory = slot_memory(layout, storage, field);
+ uint32_t* oneof_case = slot_oneof_case(layout, storage, field);
+
+ if (upb_fielddef_containingoneof(field)) {
+ if (val == Qnil) {
+ // Assigning nil to a oneof field clears the oneof completely.
+ *oneof_case = ONEOF_CASE_NONE;
+ memset(memory, 0, NATIVE_SLOT_MAX_SIZE);
+ } else {
+ // The transition between field types for a single oneof (union) slot is
+ // somewhat complex because we need to ensure that a GC triggered at any
+ // point by a call into the Ruby VM sees a valid state for this field and
+ // does not either go off into the weeds (following what it thinks is a
+ // VALUE but is actually a different field type) or miss an object (seeing
+ // what it thinks is a primitive field but is actually a VALUE for the new
+ // field type).
+ //
+ // In order for the transition to be safe, the oneof case slot must be in
+ // sync with the value slot whenever the Ruby VM has been called. Thus, we
+ // use native_slot_set_value_and_case(), which ensures that both the value
+ // and case number are altered atomically (w.r.t. the Ruby VM).
+ native_slot_set_value_and_case(
+ upb_fielddef_type(field), field_type_class(field),
+ memory, val,
+ oneof_case, upb_fielddef_number(field));
+ }
+ } else if (is_map_field(field)) {
+ check_map_field_type(val, field);
+ DEREF(memory, VALUE) = val;
+ } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
+ check_repeated_field_type(val, field);
+ DEREF(memory, VALUE) = val;
+ } else {
+ native_slot_set(upb_fielddef_type(field), field_type_class(field),
+ memory, val);
+ }
+}
+
+void layout_init(MessageLayout* layout,
+ void* storage) {
+ upb_msg_field_iter it;
+ for (upb_msg_field_begin(&it, layout->msgdef);
+ !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* field = upb_msg_iter_field(&it);
+ void* memory = slot_memory(layout, storage, field);
+ uint32_t* oneof_case = slot_oneof_case(layout, storage, field);
+
+ if (upb_fielddef_containingoneof(field)) {
+ memset(memory, 0, NATIVE_SLOT_MAX_SIZE);
+ *oneof_case = ONEOF_CASE_NONE;
+ } else if (is_map_field(field)) {
+ VALUE map = Qnil;
+
+ const upb_fielddef* key_field = map_field_key(field);
+ const upb_fielddef* value_field = map_field_value(field);
+ VALUE type_class = field_type_class(value_field);
+
+ if (type_class != Qnil) {
+ VALUE args[3] = {
+ fieldtype_to_ruby(upb_fielddef_type(key_field)),
+ fieldtype_to_ruby(upb_fielddef_type(value_field)),
+ type_class,
+ };
+ map = rb_class_new_instance(3, args, cMap);
+ } else {
+ VALUE args[2] = {
+ fieldtype_to_ruby(upb_fielddef_type(key_field)),
+ fieldtype_to_ruby(upb_fielddef_type(value_field)),
+ };
+ map = rb_class_new_instance(2, args, cMap);
+ }
+
+ DEREF(memory, VALUE) = map;
+ } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
+ VALUE ary = Qnil;
+
+ VALUE type_class = field_type_class(field);
+
+ if (type_class != Qnil) {
+ VALUE args[2] = {
+ fieldtype_to_ruby(upb_fielddef_type(field)),
+ type_class,
+ };
+ ary = rb_class_new_instance(2, args, cRepeatedField);
+ } else {
+ VALUE args[1] = { fieldtype_to_ruby(upb_fielddef_type(field)) };
+ ary = rb_class_new_instance(1, args, cRepeatedField);
+ }
+
+ DEREF(memory, VALUE) = ary;
+ } else {
+ native_slot_init(upb_fielddef_type(field), memory);
+ }
+ }
+}
+
+void layout_mark(MessageLayout* layout, void* storage) {
+ upb_msg_field_iter it;
+ for (upb_msg_field_begin(&it, layout->msgdef);
+ !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* field = upb_msg_iter_field(&it);
+ void* memory = slot_memory(layout, storage, field);
+ uint32_t* oneof_case = slot_oneof_case(layout, storage, field);
+
+ if (upb_fielddef_containingoneof(field)) {
+ if (*oneof_case == upb_fielddef_number(field)) {
+ native_slot_mark(upb_fielddef_type(field), memory);
+ }
+ } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
+ rb_gc_mark(DEREF(memory, VALUE));
+ } else {
+ native_slot_mark(upb_fielddef_type(field), memory);
+ }
+ }
+}
+
+void layout_dup(MessageLayout* layout, void* to, void* from) {
+ upb_msg_field_iter it;
+ for (upb_msg_field_begin(&it, layout->msgdef);
+ !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* field = upb_msg_iter_field(&it);
+
+ void* to_memory = slot_memory(layout, to, field);
+ uint32_t* to_oneof_case = slot_oneof_case(layout, to, field);
+ void* from_memory = slot_memory(layout, from, field);
+ uint32_t* from_oneof_case = slot_oneof_case(layout, from, field);
+
+ if (upb_fielddef_containingoneof(field)) {
+ if (*from_oneof_case == upb_fielddef_number(field)) {
+ *to_oneof_case = *from_oneof_case;
+ native_slot_dup(upb_fielddef_type(field), to_memory, from_memory);
+ }
+ } else if (is_map_field(field)) {
+ DEREF(to_memory, VALUE) = Map_dup(DEREF(from_memory, VALUE));
+ } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
+ DEREF(to_memory, VALUE) = RepeatedField_dup(DEREF(from_memory, VALUE));
+ } else {
+ native_slot_dup(upb_fielddef_type(field), to_memory, from_memory);
+ }
+ }
+}
+
+void layout_deep_copy(MessageLayout* layout, void* to, void* from) {
+ upb_msg_field_iter it;
+ for (upb_msg_field_begin(&it, layout->msgdef);
+ !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* field = upb_msg_iter_field(&it);
+
+ void* to_memory = slot_memory(layout, to, field);
+ uint32_t* to_oneof_case = slot_oneof_case(layout, to, field);
+ void* from_memory = slot_memory(layout, from, field);
+ uint32_t* from_oneof_case = slot_oneof_case(layout, from, field);
+
+ if (upb_fielddef_containingoneof(field)) {
+ if (*from_oneof_case == upb_fielddef_number(field)) {
+ *to_oneof_case = *from_oneof_case;
+ native_slot_deep_copy(upb_fielddef_type(field), to_memory, from_memory);
+ }
+ } else if (is_map_field(field)) {
+ DEREF(to_memory, VALUE) =
+ Map_deep_copy(DEREF(from_memory, VALUE));
+ } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
+ DEREF(to_memory, VALUE) =
+ RepeatedField_deep_copy(DEREF(from_memory, VALUE));
+ } else {
+ native_slot_deep_copy(upb_fielddef_type(field), to_memory, from_memory);
+ }
+ }
+}
+
+VALUE layout_eq(MessageLayout* layout, void* msg1, void* msg2) {
+ upb_msg_field_iter it;
+ for (upb_msg_field_begin(&it, layout->msgdef);
+ !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* field = upb_msg_iter_field(&it);
+
+ void* msg1_memory = slot_memory(layout, msg1, field);
+ uint32_t* msg1_oneof_case = slot_oneof_case(layout, msg1, field);
+ void* msg2_memory = slot_memory(layout, msg2, field);
+ uint32_t* msg2_oneof_case = slot_oneof_case(layout, msg2, field);
+
+ if (upb_fielddef_containingoneof(field)) {
+ if (*msg1_oneof_case != *msg2_oneof_case ||
+ (*msg1_oneof_case == upb_fielddef_number(field) &&
+ !native_slot_eq(upb_fielddef_type(field),
+ msg1_memory,
+ msg2_memory))) {
+ return Qfalse;
+ }
+ } else if (is_map_field(field)) {
+ if (!Map_eq(DEREF(msg1_memory, VALUE),
+ DEREF(msg2_memory, VALUE))) {
+ return Qfalse;
+ }
+ } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) {
+ if (!RepeatedField_eq(DEREF(msg1_memory, VALUE),
+ DEREF(msg2_memory, VALUE))) {
+ return Qfalse;
+ }
+ } else {
+ if (!native_slot_eq(upb_fielddef_type(field),
+ msg1_memory, msg2_memory)) {
+ return Qfalse;
+ }
+ }
+ }
+ return Qtrue;
+}
+
+VALUE layout_hash(MessageLayout* layout, void* storage) {
+ upb_msg_field_iter it;
+ st_index_t h = rb_hash_start(0);
+ VALUE hash_sym = rb_intern("hash");
+ for (upb_msg_field_begin(&it, layout->msgdef);
+ !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* field = upb_msg_iter_field(&it);
+ VALUE field_val = layout_get(layout, storage, field);
+ h = rb_hash_uint(h, NUM2LONG(rb_funcall(field_val, hash_sym, 0)));
+ }
+ h = rb_hash_end(h);
+
+ return INT2FIX(h);
+}
+
+VALUE layout_inspect(MessageLayout* layout, void* storage) {
+ VALUE str = rb_str_new2("");
+
+ upb_msg_field_iter it;
+ bool first = true;
+ for (upb_msg_field_begin(&it, layout->msgdef);
+ !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* field = upb_msg_iter_field(&it);
+ VALUE field_val = layout_get(layout, storage, field);
+
+ if (!first) {
+ str = rb_str_cat2(str, ", ");
+ } else {
+ first = false;
+ }
+ str = rb_str_cat2(str, upb_fielddef_name(field));
+ str = rb_str_cat2(str, ": ");
+
+ str = rb_str_append(str, rb_funcall(field_val, rb_intern("inspect"), 0));
+ }
+
+ return str;
+}
diff --git a/third_party/protobuf/ruby/ext/google/protobuf_c/upb.c b/third_party/protobuf/ruby/ext/google/protobuf_c/upb.c
new file mode 100644
index 0000000000..e0c56f8ed5
--- /dev/null
+++ b/third_party/protobuf/ruby/ext/google/protobuf_c/upb.c
@@ -0,0 +1,13950 @@
+// Amalgamated source file
+#include "upb.h"
+
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+typedef struct {
+ size_t len;
+ char str[1]; /* Null-terminated string data follows. */
+} str_t;
+
+static str_t *newstr(const char *data, size_t len) {
+ str_t *ret = upb_gmalloc(sizeof(*ret) + len);
+ if (!ret) return NULL;
+ ret->len = len;
+ memcpy(ret->str, data, len);
+ ret->str[len] = '\0';
+ return ret;
+}
+
+static void freestr(str_t *s) { upb_gfree(s); }
+
+/* isalpha() etc. from <ctype.h> are locale-dependent, which we don't want. */
+static bool upb_isbetween(char c, char low, char high) {
+ return c >= low && c <= high;
+}
+
+static bool upb_isletter(char c) {
+ return upb_isbetween(c, 'A', 'Z') || upb_isbetween(c, 'a', 'z') || c == '_';
+}
+
+static bool upb_isalphanum(char c) {
+ return upb_isletter(c) || upb_isbetween(c, '0', '9');
+}
+
+static bool upb_isident(const char *str, size_t len, bool full, upb_status *s) {
+ bool start = true;
+ size_t i;
+ for (i = 0; i < len; i++) {
+ char c = str[i];
+ if (c == '.') {
+ if (start || !full) {
+ upb_status_seterrf(s, "invalid name: unexpected '.' (%s)", str);
+ return false;
+ }
+ start = true;
+ } else if (start) {
+ if (!upb_isletter(c)) {
+ upb_status_seterrf(
+ s, "invalid name: path components must start with a letter (%s)",
+ str);
+ return false;
+ }
+ start = false;
+ } else {
+ if (!upb_isalphanum(c)) {
+ upb_status_seterrf(s, "invalid name: non-alphanumeric character (%s)",
+ str);
+ return false;
+ }
+ }
+ }
+ return !start;
+}
+
+static bool upb_isoneof(const upb_refcounted *def) {
+ return def->vtbl == &upb_oneofdef_vtbl;
+}
+
+static bool upb_isfield(const upb_refcounted *def) {
+ return def->vtbl == &upb_fielddef_vtbl;
+}
+
+static const upb_oneofdef *upb_trygetoneof(const upb_refcounted *def) {
+ return upb_isoneof(def) ? (const upb_oneofdef*)def : NULL;
+}
+
+static const upb_fielddef *upb_trygetfield(const upb_refcounted *def) {
+ return upb_isfield(def) ? (const upb_fielddef*)def : NULL;
+}
+
+
+/* upb_def ********************************************************************/
+
+upb_deftype_t upb_def_type(const upb_def *d) { return d->type; }
+
+const char *upb_def_fullname(const upb_def *d) { return d->fullname; }
+
+const char *upb_def_name(const upb_def *d) {
+ const char *p;
+
+ if (d->fullname == NULL) {
+ return NULL;
+ } else if ((p = strrchr(d->fullname, '.')) == NULL) {
+ /* No '.' in the name, return the full string. */
+ return d->fullname;
+ } else {
+ /* Return one past the last '.'. */
+ return p + 1;
+ }
+}
+
+bool upb_def_setfullname(upb_def *def, const char *fullname, upb_status *s) {
+ UPB_ASSERT(!upb_def_isfrozen(def));
+ if (!upb_isident(fullname, strlen(fullname), true, s)) {
+ return false;
+ }
+
+ fullname = upb_gstrdup(fullname);
+ if (!fullname) {
+ upb_upberr_setoom(s);
+ return false;
+ }
+
+ upb_gfree((void*)def->fullname);
+ def->fullname = fullname;
+ return true;
+}
+
+const upb_filedef *upb_def_file(const upb_def *d) { return d->file; }
+
+static bool upb_def_init(upb_def *def, upb_deftype_t type,
+ const struct upb_refcounted_vtbl *vtbl,
+ const void *owner) {
+ if (!upb_refcounted_init(upb_def_upcast_mutable(def), vtbl, owner)) return false;
+ def->type = type;
+ def->fullname = NULL;
+ def->came_from_user = false;
+ def->file = NULL;
+ return true;
+}
+
+static void upb_def_uninit(upb_def *def) {
+ upb_gfree((void*)def->fullname);
+}
+
+static const char *msgdef_name(const upb_msgdef *m) {
+ const char *name = upb_def_fullname(upb_msgdef_upcast(m));
+ return name ? name : "(anonymous)";
+}
+
+static bool upb_validate_field(upb_fielddef *f, upb_status *s) {
+ if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) {
+ upb_status_seterrmsg(s, "fielddef must have name and number set");
+ return false;
+ }
+
+ if (!f->type_is_set_) {
+ upb_status_seterrmsg(s, "fielddef type was not initialized");
+ return false;
+ }
+
+ if (upb_fielddef_lazy(f) &&
+ upb_fielddef_descriptortype(f) != UPB_DESCRIPTOR_TYPE_MESSAGE) {
+ upb_status_seterrmsg(s,
+ "only length-delimited submessage fields may be lazy");
+ return false;
+ }
+
+ if (upb_fielddef_hassubdef(f)) {
+ const upb_def *subdef;
+
+ if (f->subdef_is_symbolic) {
+ upb_status_seterrf(s, "field '%s.%s' has not been resolved",
+ msgdef_name(f->msg.def), upb_fielddef_name(f));
+ return false;
+ }
+
+ subdef = upb_fielddef_subdef(f);
+ if (subdef == NULL) {
+ upb_status_seterrf(s, "field %s.%s is missing required subdef",
+ msgdef_name(f->msg.def), upb_fielddef_name(f));
+ return false;
+ }
+
+ if (!upb_def_isfrozen(subdef) && !subdef->came_from_user) {
+ upb_status_seterrf(s,
+ "subdef of field %s.%s is not frozen or being frozen",
+ msgdef_name(f->msg.def), upb_fielddef_name(f));
+ return false;
+ }
+ }
+
+ if (upb_fielddef_type(f) == UPB_TYPE_ENUM) {
+ bool has_default_name = upb_fielddef_enumhasdefaultstr(f);
+ bool has_default_number = upb_fielddef_enumhasdefaultint32(f);
+
+ /* Previously verified by upb_validate_enumdef(). */
+ UPB_ASSERT(upb_enumdef_numvals(upb_fielddef_enumsubdef(f)) > 0);
+
+ /* We've already validated that we have an associated enumdef and that it
+ * has at least one member, so at least one of these should be true.
+ * Because if the user didn't set anything, we'll pick up the enum's
+ * default, but if the user *did* set something we should at least pick up
+ * the one they set (int32 or string). */
+ UPB_ASSERT(has_default_name || has_default_number);
+
+ if (!has_default_name) {
+ upb_status_seterrf(s,
+ "enum default for field %s.%s (%d) is not in the enum",
+ msgdef_name(f->msg.def), upb_fielddef_name(f),
+ upb_fielddef_defaultint32(f));
+ return false;
+ }
+
+ if (!has_default_number) {
+ upb_status_seterrf(s,
+ "enum default for field %s.%s (%s) is not in the enum",
+ msgdef_name(f->msg.def), upb_fielddef_name(f),
+ upb_fielddef_defaultstr(f, NULL));
+ return false;
+ }
+
+ /* Lift the effective numeric default into the field's default slot, in case
+ * we were only getting it "by reference" from the enumdef. */
+ upb_fielddef_setdefaultint32(f, upb_fielddef_defaultint32(f));
+ }
+
+ /* Ensure that MapEntry submessages only appear as repeated fields, not
+ * optional/required (singular) fields. */
+ if (upb_fielddef_type(f) == UPB_TYPE_MESSAGE &&
+ upb_fielddef_msgsubdef(f) != NULL) {
+ const upb_msgdef *subdef = upb_fielddef_msgsubdef(f);
+ if (upb_msgdef_mapentry(subdef) && !upb_fielddef_isseq(f)) {
+ upb_status_seterrf(s,
+ "Field %s refers to mapentry message but is not "
+ "a repeated field",
+ upb_fielddef_name(f) ? upb_fielddef_name(f) :
+ "(unnamed)");
+ return false;
+ }
+ }
+
+ return true;
+}
+
+static bool upb_validate_enumdef(const upb_enumdef *e, upb_status *s) {
+ if (upb_enumdef_numvals(e) == 0) {
+ upb_status_seterrf(s, "enum %s has no members (must have at least one)",
+ upb_enumdef_fullname(e));
+ return false;
+ }
+
+ return true;
+}
+
+/* All submessage fields are lower than all other fields.
+ * Secondly, fields are increasing in order. */
+uint32_t field_rank(const upb_fielddef *f) {
+ uint32_t ret = upb_fielddef_number(f);
+ const uint32_t high_bit = 1 << 30;
+ UPB_ASSERT(ret < high_bit);
+ if (!upb_fielddef_issubmsg(f))
+ ret |= high_bit;
+ return ret;
+}
+
+int cmp_fields(const void *p1, const void *p2) {
+ const upb_fielddef *f1 = *(upb_fielddef*const*)p1;
+ const upb_fielddef *f2 = *(upb_fielddef*const*)p2;
+ return field_rank(f1) - field_rank(f2);
+}
+
+static bool assign_msg_indices(upb_msgdef *m, upb_status *s) {
+ /* Sort fields. upb internally relies on UPB_TYPE_MESSAGE fields having the
+ * lowest indexes, but we do not publicly guarantee this. */
+ upb_msg_field_iter j;
+ upb_msg_oneof_iter k;
+ int i;
+ uint32_t selector;
+ int n = upb_msgdef_numfields(m);
+ upb_fielddef **fields;
+
+ if (n == 0) {
+ m->selector_count = UPB_STATIC_SELECTOR_COUNT;
+ m->submsg_field_count = 0;
+ return true;
+ }
+
+ fields = upb_gmalloc(n * sizeof(*fields));
+ if (!fields) {
+ upb_upberr_setoom(s);
+ return false;
+ }
+
+ m->submsg_field_count = 0;
+ for(i = 0, upb_msg_field_begin(&j, m);
+ !upb_msg_field_done(&j);
+ upb_msg_field_next(&j), i++) {
+ upb_fielddef *f = upb_msg_iter_field(&j);
+ UPB_ASSERT(f->msg.def == m);
+ if (!upb_validate_field(f, s)) {
+ upb_gfree(fields);
+ return false;
+ }
+ if (upb_fielddef_issubmsg(f)) {
+ m->submsg_field_count++;
+ }
+ fields[i] = f;
+ }
+
+ qsort(fields, n, sizeof(*fields), cmp_fields);
+
+ selector = UPB_STATIC_SELECTOR_COUNT + m->submsg_field_count;
+ for (i = 0; i < n; i++) {
+ upb_fielddef *f = fields[i];
+ f->index_ = i;
+ f->selector_base = selector + upb_handlers_selectorbaseoffset(f);
+ selector += upb_handlers_selectorcount(f);
+ }
+ m->selector_count = selector;
+
+#ifndef NDEBUG
+ {
+ /* Verify that all selectors for the message are distinct. */
+#define TRY(type) \
+ if (upb_handlers_getselector(f, type, &sel)) upb_inttable_insert(&t, sel, v);
+
+ upb_inttable t;
+ upb_value v;
+ upb_selector_t sel;
+
+ upb_inttable_init(&t, UPB_CTYPE_BOOL);
+ v = upb_value_bool(true);
+ upb_inttable_insert(&t, UPB_STARTMSG_SELECTOR, v);
+ upb_inttable_insert(&t, UPB_ENDMSG_SELECTOR, v);
+ for(upb_msg_field_begin(&j, m);
+ !upb_msg_field_done(&j);
+ upb_msg_field_next(&j)) {
+ upb_fielddef *f = upb_msg_iter_field(&j);
+ /* These calls will assert-fail in upb_table if the value already
+ * exists. */
+ TRY(UPB_HANDLER_INT32);
+ TRY(UPB_HANDLER_INT64)
+ TRY(UPB_HANDLER_UINT32)
+ TRY(UPB_HANDLER_UINT64)
+ TRY(UPB_HANDLER_FLOAT)
+ TRY(UPB_HANDLER_DOUBLE)
+ TRY(UPB_HANDLER_BOOL)
+ TRY(UPB_HANDLER_STARTSTR)
+ TRY(UPB_HANDLER_STRING)
+ TRY(UPB_HANDLER_ENDSTR)
+ TRY(UPB_HANDLER_STARTSUBMSG)
+ TRY(UPB_HANDLER_ENDSUBMSG)
+ TRY(UPB_HANDLER_STARTSEQ)
+ TRY(UPB_HANDLER_ENDSEQ)
+ }
+ upb_inttable_uninit(&t);
+ }
+#undef TRY
+#endif
+
+ for(upb_msg_oneof_begin(&k, m), i = 0;
+ !upb_msg_oneof_done(&k);
+ upb_msg_oneof_next(&k), i++) {
+ upb_oneofdef *o = upb_msg_iter_oneof(&k);
+ o->index = i;
+ }
+
+ upb_gfree(fields);
+ return true;
+}
+
+bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s) {
+ size_t i;
+
+ /* First perform validation, in two passes so we can check that we have a
+ * transitive closure without needing to search. */
+ for (i = 0; i < n; i++) {
+ upb_def *def = defs[i];
+ if (upb_def_isfrozen(def)) {
+ /* Could relax this requirement if it's annoying. */
+ upb_status_seterrmsg(s, "def is already frozen");
+ goto err;
+ } else if (def->type == UPB_DEF_FIELD) {
+ upb_status_seterrmsg(s, "standalone fielddefs can not be frozen");
+ goto err;
+ } else if (def->type == UPB_DEF_ENUM) {
+ if (!upb_validate_enumdef(upb_dyncast_enumdef(def), s)) {
+ goto err;
+ }
+ } else {
+ /* Set now to detect transitive closure in the second pass. */
+ def->came_from_user = true;
+ }
+ }
+
+ /* Second pass of validation. Also assign selector bases and indexes, and
+ * compact tables. */
+ for (i = 0; i < n; i++) {
+ upb_def *def = defs[i];
+ upb_msgdef *m = upb_dyncast_msgdef_mutable(def);
+ upb_enumdef *e = upb_dyncast_enumdef_mutable(def);
+ if (m) {
+ upb_inttable_compact(&m->itof);
+ if (!assign_msg_indices(m, s)) {
+ goto err;
+ }
+ } else if (e) {
+ upb_inttable_compact(&e->iton);
+ }
+ }
+
+ return true;
+
+err:
+ for (i = 0; i < n; i++) {
+ upb_def *def = defs[i];
+ def->came_from_user = false;
+ }
+ UPB_ASSERT(!(s && upb_ok(s)));
+ return false;
+}
+
+bool upb_def_freeze(upb_def *const* defs, size_t n, upb_status *s) {
+ /* Def graph contains FieldDefs between each MessageDef, so double the
+ * limit. */
+ const size_t maxdepth = UPB_MAX_MESSAGE_DEPTH * 2;
+
+ if (!_upb_def_validate(defs, n, s)) {
+ return false;
+ }
+
+
+ /* Validation all passed; freeze the objects. */
+ return upb_refcounted_freeze((upb_refcounted *const*)defs, n, s, maxdepth);
+}
+
+
+/* upb_enumdef ****************************************************************/
+
+static void visitenum(const upb_refcounted *r, upb_refcounted_visit *visit,
+ void *closure) {
+ const upb_enumdef *e = (const upb_enumdef*)r;
+ const upb_def *def = upb_enumdef_upcast(e);
+ if (upb_def_file(def)) {
+ visit(r, upb_filedef_upcast(upb_def_file(def)), closure);
+ }
+}
+
+static void freeenum(upb_refcounted *r) {
+ upb_enumdef *e = (upb_enumdef*)r;
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, &e->iton);
+ for( ; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ /* To clean up the upb_gstrdup() from upb_enumdef_addval(). */
+ upb_gfree(upb_value_getcstr(upb_inttable_iter_value(&i)));
+ }
+ upb_strtable_uninit(&e->ntoi);
+ upb_inttable_uninit(&e->iton);
+ upb_def_uninit(upb_enumdef_upcast_mutable(e));
+ upb_gfree(e);
+}
+
+const struct upb_refcounted_vtbl upb_enumdef_vtbl = {&visitenum, &freeenum};
+
+upb_enumdef *upb_enumdef_new(const void *owner) {
+ upb_enumdef *e = upb_gmalloc(sizeof(*e));
+ if (!e) return NULL;
+
+ if (!upb_def_init(upb_enumdef_upcast_mutable(e), UPB_DEF_ENUM,
+ &upb_enumdef_vtbl, owner)) {
+ goto err2;
+ }
+
+ if (!upb_strtable_init(&e->ntoi, UPB_CTYPE_INT32)) goto err2;
+ if (!upb_inttable_init(&e->iton, UPB_CTYPE_CSTR)) goto err1;
+ return e;
+
+err1:
+ upb_strtable_uninit(&e->ntoi);
+err2:
+ upb_gfree(e);
+ return NULL;
+}
+
+bool upb_enumdef_freeze(upb_enumdef *e, upb_status *status) {
+ upb_def *d = upb_enumdef_upcast_mutable(e);
+ return upb_def_freeze(&d, 1, status);
+}
+
+const char *upb_enumdef_fullname(const upb_enumdef *e) {
+ return upb_def_fullname(upb_enumdef_upcast(e));
+}
+
+const char *upb_enumdef_name(const upb_enumdef *e) {
+ return upb_def_name(upb_enumdef_upcast(e));
+}
+
+bool upb_enumdef_setfullname(upb_enumdef *e, const char *fullname,
+ upb_status *s) {
+ return upb_def_setfullname(upb_enumdef_upcast_mutable(e), fullname, s);
+}
+
+bool upb_enumdef_addval(upb_enumdef *e, const char *name, int32_t num,
+ upb_status *status) {
+ char *name2;
+
+ if (!upb_isident(name, strlen(name), false, status)) {
+ return false;
+ }
+
+ if (upb_enumdef_ntoiz(e, name, NULL)) {
+ upb_status_seterrf(status, "name '%s' is already defined", name);
+ return false;
+ }
+
+ if (!upb_strtable_insert(&e->ntoi, name, upb_value_int32(num))) {
+ upb_status_seterrmsg(status, "out of memory");
+ return false;
+ }
+
+ if (!upb_inttable_lookup(&e->iton, num, NULL)) {
+ name2 = upb_gstrdup(name);
+ if (!name2 || !upb_inttable_insert(&e->iton, num, upb_value_cstr(name2))) {
+ upb_status_seterrmsg(status, "out of memory");
+ upb_strtable_remove(&e->ntoi, name, NULL);
+ return false;
+ }
+ }
+
+ if (upb_enumdef_numvals(e) == 1) {
+ bool ok = upb_enumdef_setdefault(e, num, NULL);
+ UPB_ASSERT(ok);
+ }
+
+ return true;
+}
+
+int32_t upb_enumdef_default(const upb_enumdef *e) {
+ UPB_ASSERT(upb_enumdef_iton(e, e->defaultval));
+ return e->defaultval;
+}
+
+bool upb_enumdef_setdefault(upb_enumdef *e, int32_t val, upb_status *s) {
+ UPB_ASSERT(!upb_enumdef_isfrozen(e));
+ if (!upb_enumdef_iton(e, val)) {
+ upb_status_seterrf(s, "number '%d' is not in the enum.", val);
+ return false;
+ }
+ e->defaultval = val;
+ return true;
+}
+
+int upb_enumdef_numvals(const upb_enumdef *e) {
+ return upb_strtable_count(&e->ntoi);
+}
+
+void upb_enum_begin(upb_enum_iter *i, const upb_enumdef *e) {
+ /* We iterate over the ntoi table, to account for duplicate numbers. */
+ upb_strtable_begin(i, &e->ntoi);
+}
+
+void upb_enum_next(upb_enum_iter *iter) { upb_strtable_next(iter); }
+bool upb_enum_done(upb_enum_iter *iter) { return upb_strtable_done(iter); }
+
+bool upb_enumdef_ntoi(const upb_enumdef *def, const char *name,
+ size_t len, int32_t *num) {
+ upb_value v;
+ if (!upb_strtable_lookup2(&def->ntoi, name, len, &v)) {
+ return false;
+ }
+ if (num) *num = upb_value_getint32(v);
+ return true;
+}
+
+const char *upb_enumdef_iton(const upb_enumdef *def, int32_t num) {
+ upb_value v;
+ return upb_inttable_lookup32(&def->iton, num, &v) ?
+ upb_value_getcstr(v) : NULL;
+}
+
+const char *upb_enum_iter_name(upb_enum_iter *iter) {
+ return upb_strtable_iter_key(iter);
+}
+
+int32_t upb_enum_iter_number(upb_enum_iter *iter) {
+ return upb_value_getint32(upb_strtable_iter_value(iter));
+}
+
+
+/* upb_fielddef ***************************************************************/
+
+static void upb_fielddef_init_default(upb_fielddef *f);
+
+static void upb_fielddef_uninit_default(upb_fielddef *f) {
+ if (f->type_is_set_ && f->default_is_string && f->defaultval.bytes)
+ freestr(f->defaultval.bytes);
+}
+
+const char *upb_fielddef_fullname(const upb_fielddef *e) {
+ return upb_def_fullname(upb_fielddef_upcast(e));
+}
+
+static void visitfield(const upb_refcounted *r, upb_refcounted_visit *visit,
+ void *closure) {
+ const upb_fielddef *f = (const upb_fielddef*)r;
+ const upb_def *def = upb_fielddef_upcast(f);
+ if (upb_fielddef_containingtype(f)) {
+ visit(r, upb_msgdef_upcast2(upb_fielddef_containingtype(f)), closure);
+ }
+ if (upb_fielddef_containingoneof(f)) {
+ visit(r, upb_oneofdef_upcast(upb_fielddef_containingoneof(f)), closure);
+ }
+ if (upb_fielddef_subdef(f)) {
+ visit(r, upb_def_upcast(upb_fielddef_subdef(f)), closure);
+ }
+ if (upb_def_file(def)) {
+ visit(r, upb_filedef_upcast(upb_def_file(def)), closure);
+ }
+}
+
+static void freefield(upb_refcounted *r) {
+ upb_fielddef *f = (upb_fielddef*)r;
+ upb_fielddef_uninit_default(f);
+ if (f->subdef_is_symbolic)
+ upb_gfree(f->sub.name);
+ upb_def_uninit(upb_fielddef_upcast_mutable(f));
+ upb_gfree(f);
+}
+
+static const char *enumdefaultstr(const upb_fielddef *f) {
+ const upb_enumdef *e;
+ UPB_ASSERT(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM);
+ e = upb_fielddef_enumsubdef(f);
+ if (f->default_is_string && f->defaultval.bytes) {
+ /* Default was explicitly set as a string. */
+ str_t *s = f->defaultval.bytes;
+ return s->str;
+ } else if (e) {
+ if (!f->default_is_string) {
+ /* Default was explicitly set as an integer; look it up in enumdef. */
+ const char *name = upb_enumdef_iton(e, f->defaultval.sint);
+ if (name) {
+ return name;
+ }
+ } else {
+ /* Default is completely unset; pull enumdef default. */
+ if (upb_enumdef_numvals(e) > 0) {
+ const char *name = upb_enumdef_iton(e, upb_enumdef_default(e));
+ UPB_ASSERT(name);
+ return name;
+ }
+ }
+ }
+ return NULL;
+}
+
+static bool enumdefaultint32(const upb_fielddef *f, int32_t *val) {
+ const upb_enumdef *e;
+ UPB_ASSERT(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM);
+ e = upb_fielddef_enumsubdef(f);
+ if (!f->default_is_string) {
+ /* Default was explicitly set as an integer. */
+ *val = f->defaultval.sint;
+ return true;
+ } else if (e) {
+ if (f->defaultval.bytes) {
+ /* Default was explicitly set as a str; try to lookup corresponding int. */
+ str_t *s = f->defaultval.bytes;
+ if (upb_enumdef_ntoiz(e, s->str, val)) {
+ return true;
+ }
+ } else {
+ /* Default is unset; try to pull in enumdef default. */
+ if (upb_enumdef_numvals(e) > 0) {
+ *val = upb_enumdef_default(e);
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+const struct upb_refcounted_vtbl upb_fielddef_vtbl = {visitfield, freefield};
+
+upb_fielddef *upb_fielddef_new(const void *o) {
+ upb_fielddef *f = upb_gmalloc(sizeof(*f));
+ if (!f) return NULL;
+ if (!upb_def_init(upb_fielddef_upcast_mutable(f), UPB_DEF_FIELD,
+ &upb_fielddef_vtbl, o)) {
+ upb_gfree(f);
+ return NULL;
+ }
+ f->msg.def = NULL;
+ f->sub.def = NULL;
+ f->oneof = NULL;
+ f->subdef_is_symbolic = false;
+ f->msg_is_symbolic = false;
+ f->label_ = UPB_LABEL_OPTIONAL;
+ f->type_ = UPB_TYPE_INT32;
+ f->number_ = 0;
+ f->type_is_set_ = false;
+ f->tagdelim = false;
+ f->is_extension_ = false;
+ f->lazy_ = false;
+ f->packed_ = true;
+
+ /* For the moment we default this to UPB_INTFMT_VARIABLE, since it will work
+ * with all integer types and is in some since more "default" since the most
+ * normal-looking proto2 types int32/int64/uint32/uint64 use variable.
+ *
+ * Other options to consider:
+ * - there is no default; users must set this manually (like type).
+ * - default signed integers to UPB_INTFMT_ZIGZAG, since it's more likely to
+ * be an optimal default for signed integers. */
+ f->intfmt = UPB_INTFMT_VARIABLE;
+ return f;
+}
+
+static upb_fielddef *upb_fielddef_dup(const upb_fielddef *f,
+ const void *owner) {
+ const char *srcname;
+ upb_fielddef *newf = upb_fielddef_new(owner);
+ if (!newf) return NULL;
+ upb_fielddef_settype(newf, upb_fielddef_type(f));
+ upb_fielddef_setlabel(newf, upb_fielddef_label(f));
+ upb_fielddef_setnumber(newf, upb_fielddef_number(f), NULL);
+ upb_fielddef_setname(newf, upb_fielddef_name(f), NULL);
+ if (f->default_is_string && f->defaultval.bytes) {
+ str_t *s = f->defaultval.bytes;
+ upb_fielddef_setdefaultstr(newf, s->str, s->len, NULL);
+ } else {
+ newf->default_is_string = f->default_is_string;
+ newf->defaultval = f->defaultval;
+ }
+
+ if (f->subdef_is_symbolic) {
+ srcname = f->sub.name; /* Might be NULL. */
+ } else {
+ srcname = f->sub.def ? upb_def_fullname(f->sub.def) : NULL;
+ }
+ if (srcname) {
+ char *newname = upb_gmalloc(strlen(f->sub.def->fullname) + 2);
+ if (!newname) {
+ upb_fielddef_unref(newf, owner);
+ return NULL;
+ }
+ strcpy(newname, ".");
+ strcat(newname, f->sub.def->fullname);
+ upb_fielddef_setsubdefname(newf, newname, NULL);
+ upb_gfree(newname);
+ }
+
+ return newf;
+}
+
+bool upb_fielddef_typeisset(const upb_fielddef *f) {
+ return f->type_is_set_;
+}
+
+upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f) {
+ UPB_ASSERT(f->type_is_set_);
+ return f->type_;
+}
+
+uint32_t upb_fielddef_index(const upb_fielddef *f) {
+ return f->index_;
+}
+
+upb_label_t upb_fielddef_label(const upb_fielddef *f) {
+ return f->label_;
+}
+
+upb_intfmt_t upb_fielddef_intfmt(const upb_fielddef *f) {
+ return f->intfmt;
+}
+
+bool upb_fielddef_istagdelim(const upb_fielddef *f) {
+ return f->tagdelim;
+}
+
+uint32_t upb_fielddef_number(const upb_fielddef *f) {
+ return f->number_;
+}
+
+bool upb_fielddef_isextension(const upb_fielddef *f) {
+ return f->is_extension_;
+}
+
+bool upb_fielddef_lazy(const upb_fielddef *f) {
+ return f->lazy_;
+}
+
+bool upb_fielddef_packed(const upb_fielddef *f) {
+ return f->packed_;
+}
+
+const char *upb_fielddef_name(const upb_fielddef *f) {
+ return upb_def_fullname(upb_fielddef_upcast(f));
+}
+
+size_t upb_fielddef_getjsonname(const upb_fielddef *f, char *buf, size_t len) {
+ const char *name = upb_fielddef_name(f);
+ size_t src, dst = 0;
+ bool ucase_next = false;
+
+#define WRITE(byte) \
+ ++dst; \
+ if (dst < len) buf[dst - 1] = byte; \
+ else if (dst == len) buf[dst - 1] = '\0'
+
+ if (!name) {
+ WRITE('\0');
+ return 0;
+ }
+
+ /* Implement the transformation as described in the spec:
+ * 1. upper case all letters after an underscore.
+ * 2. remove all underscores.
+ */
+ for (src = 0; name[src]; src++) {
+ if (name[src] == '_') {
+ ucase_next = true;
+ continue;
+ }
+
+ if (ucase_next) {
+ WRITE(toupper(name[src]));
+ ucase_next = false;
+ } else {
+ WRITE(name[src]);
+ }
+ }
+
+ WRITE('\0');
+ return dst;
+
+#undef WRITE
+}
+
+const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f) {
+ return f->msg_is_symbolic ? NULL : f->msg.def;
+}
+
+const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f) {
+ return f->oneof;
+}
+
+upb_msgdef *upb_fielddef_containingtype_mutable(upb_fielddef *f) {
+ return (upb_msgdef*)upb_fielddef_containingtype(f);
+}
+
+const char *upb_fielddef_containingtypename(upb_fielddef *f) {
+ return f->msg_is_symbolic ? f->msg.name : NULL;
+}
+
+static void release_containingtype(upb_fielddef *f) {
+ if (f->msg_is_symbolic) upb_gfree(f->msg.name);
+}
+
+bool upb_fielddef_setcontainingtypename(upb_fielddef *f, const char *name,
+ upb_status *s) {
+ char *name_copy;
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ if (upb_fielddef_containingtype(f)) {
+ upb_status_seterrmsg(s, "field has already been added to a message.");
+ return false;
+ }
+ /* TODO: validate name (upb_isident() doesn't quite work atm because this name
+ * may have a leading "."). */
+
+ name_copy = upb_gstrdup(name);
+ if (!name_copy) {
+ upb_upberr_setoom(s);
+ return false;
+ }
+
+ release_containingtype(f);
+ f->msg.name = name_copy;
+ f->msg_is_symbolic = true;
+ return true;
+}
+
+bool upb_fielddef_setname(upb_fielddef *f, const char *name, upb_status *s) {
+ if (upb_fielddef_containingtype(f) || upb_fielddef_containingoneof(f)) {
+ upb_status_seterrmsg(s, "Already added to message or oneof");
+ return false;
+ }
+ return upb_def_setfullname(upb_fielddef_upcast_mutable(f), name, s);
+}
+
+static void chkdefaulttype(const upb_fielddef *f, upb_fieldtype_t type) {
+ UPB_UNUSED(f);
+ UPB_UNUSED(type);
+ UPB_ASSERT(f->type_is_set_ && upb_fielddef_type(f) == type);
+}
+
+int64_t upb_fielddef_defaultint64(const upb_fielddef *f) {
+ chkdefaulttype(f, UPB_TYPE_INT64);
+ return f->defaultval.sint;
+}
+
+int32_t upb_fielddef_defaultint32(const upb_fielddef *f) {
+ if (f->type_is_set_ && upb_fielddef_type(f) == UPB_TYPE_ENUM) {
+ int32_t val;
+ bool ok = enumdefaultint32(f, &val);
+ UPB_ASSERT(ok);
+ return val;
+ } else {
+ chkdefaulttype(f, UPB_TYPE_INT32);
+ return f->defaultval.sint;
+ }
+}
+
+uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f) {
+ chkdefaulttype(f, UPB_TYPE_UINT64);
+ return f->defaultval.uint;
+}
+
+uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f) {
+ chkdefaulttype(f, UPB_TYPE_UINT32);
+ return f->defaultval.uint;
+}
+
+bool upb_fielddef_defaultbool(const upb_fielddef *f) {
+ chkdefaulttype(f, UPB_TYPE_BOOL);
+ return f->defaultval.uint;
+}
+
+float upb_fielddef_defaultfloat(const upb_fielddef *f) {
+ chkdefaulttype(f, UPB_TYPE_FLOAT);
+ return f->defaultval.flt;
+}
+
+double upb_fielddef_defaultdouble(const upb_fielddef *f) {
+ chkdefaulttype(f, UPB_TYPE_DOUBLE);
+ return f->defaultval.dbl;
+}
+
+const char *upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len) {
+ UPB_ASSERT(f->type_is_set_);
+ UPB_ASSERT(upb_fielddef_type(f) == UPB_TYPE_STRING ||
+ upb_fielddef_type(f) == UPB_TYPE_BYTES ||
+ upb_fielddef_type(f) == UPB_TYPE_ENUM);
+
+ if (upb_fielddef_type(f) == UPB_TYPE_ENUM) {
+ const char *ret = enumdefaultstr(f);
+ UPB_ASSERT(ret);
+ /* Enum defaults can't have embedded NULLs. */
+ if (len) *len = strlen(ret);
+ return ret;
+ }
+
+ if (f->default_is_string) {
+ str_t *str = f->defaultval.bytes;
+ if (len) *len = str->len;
+ return str->str;
+ }
+
+ return NULL;
+}
+
+static void upb_fielddef_init_default(upb_fielddef *f) {
+ f->default_is_string = false;
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_DOUBLE: f->defaultval.dbl = 0; break;
+ case UPB_TYPE_FLOAT: f->defaultval.flt = 0; break;
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_INT64: f->defaultval.sint = 0; break;
+ case UPB_TYPE_UINT64:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_BOOL: f->defaultval.uint = 0; break;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ f->defaultval.bytes = newstr("", 0);
+ f->default_is_string = true;
+ break;
+ case UPB_TYPE_MESSAGE: break;
+ case UPB_TYPE_ENUM:
+ /* This is our special sentinel that indicates "not set" for an enum. */
+ f->default_is_string = true;
+ f->defaultval.bytes = NULL;
+ break;
+ }
+}
+
+const upb_def *upb_fielddef_subdef(const upb_fielddef *f) {
+ return f->subdef_is_symbolic ? NULL : f->sub.def;
+}
+
+const upb_msgdef *upb_fielddef_msgsubdef(const upb_fielddef *f) {
+ const upb_def *def = upb_fielddef_subdef(f);
+ return def ? upb_dyncast_msgdef(def) : NULL;
+}
+
+const upb_enumdef *upb_fielddef_enumsubdef(const upb_fielddef *f) {
+ const upb_def *def = upb_fielddef_subdef(f);
+ return def ? upb_dyncast_enumdef(def) : NULL;
+}
+
+upb_def *upb_fielddef_subdef_mutable(upb_fielddef *f) {
+ return (upb_def*)upb_fielddef_subdef(f);
+}
+
+const char *upb_fielddef_subdefname(const upb_fielddef *f) {
+ if (f->subdef_is_symbolic) {
+ return f->sub.name;
+ } else if (f->sub.def) {
+ return upb_def_fullname(f->sub.def);
+ } else {
+ return NULL;
+ }
+}
+
+bool upb_fielddef_setnumber(upb_fielddef *f, uint32_t number, upb_status *s) {
+ if (upb_fielddef_containingtype(f)) {
+ upb_status_seterrmsg(
+ s, "cannot change field number after adding to a message");
+ return false;
+ }
+ if (number == 0 || number > UPB_MAX_FIELDNUMBER) {
+ upb_status_seterrf(s, "invalid field number (%u)", number);
+ return false;
+ }
+ f->number_ = number;
+ return true;
+}
+
+void upb_fielddef_settype(upb_fielddef *f, upb_fieldtype_t type) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ UPB_ASSERT(upb_fielddef_checktype(type));
+ upb_fielddef_uninit_default(f);
+ f->type_ = type;
+ f->type_is_set_ = true;
+ upb_fielddef_init_default(f);
+}
+
+void upb_fielddef_setdescriptortype(upb_fielddef *f, int type) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ switch (type) {
+ case UPB_DESCRIPTOR_TYPE_DOUBLE:
+ upb_fielddef_settype(f, UPB_TYPE_DOUBLE);
+ break;
+ case UPB_DESCRIPTOR_TYPE_FLOAT:
+ upb_fielddef_settype(f, UPB_TYPE_FLOAT);
+ break;
+ case UPB_DESCRIPTOR_TYPE_INT64:
+ case UPB_DESCRIPTOR_TYPE_SFIXED64:
+ case UPB_DESCRIPTOR_TYPE_SINT64:
+ upb_fielddef_settype(f, UPB_TYPE_INT64);
+ break;
+ case UPB_DESCRIPTOR_TYPE_UINT64:
+ case UPB_DESCRIPTOR_TYPE_FIXED64:
+ upb_fielddef_settype(f, UPB_TYPE_UINT64);
+ break;
+ case UPB_DESCRIPTOR_TYPE_INT32:
+ case UPB_DESCRIPTOR_TYPE_SFIXED32:
+ case UPB_DESCRIPTOR_TYPE_SINT32:
+ upb_fielddef_settype(f, UPB_TYPE_INT32);
+ break;
+ case UPB_DESCRIPTOR_TYPE_UINT32:
+ case UPB_DESCRIPTOR_TYPE_FIXED32:
+ upb_fielddef_settype(f, UPB_TYPE_UINT32);
+ break;
+ case UPB_DESCRIPTOR_TYPE_BOOL:
+ upb_fielddef_settype(f, UPB_TYPE_BOOL);
+ break;
+ case UPB_DESCRIPTOR_TYPE_STRING:
+ upb_fielddef_settype(f, UPB_TYPE_STRING);
+ break;
+ case UPB_DESCRIPTOR_TYPE_BYTES:
+ upb_fielddef_settype(f, UPB_TYPE_BYTES);
+ break;
+ case UPB_DESCRIPTOR_TYPE_GROUP:
+ case UPB_DESCRIPTOR_TYPE_MESSAGE:
+ upb_fielddef_settype(f, UPB_TYPE_MESSAGE);
+ break;
+ case UPB_DESCRIPTOR_TYPE_ENUM:
+ upb_fielddef_settype(f, UPB_TYPE_ENUM);
+ break;
+ default: UPB_ASSERT(false);
+ }
+
+ if (type == UPB_DESCRIPTOR_TYPE_FIXED64 ||
+ type == UPB_DESCRIPTOR_TYPE_FIXED32 ||
+ type == UPB_DESCRIPTOR_TYPE_SFIXED64 ||
+ type == UPB_DESCRIPTOR_TYPE_SFIXED32) {
+ upb_fielddef_setintfmt(f, UPB_INTFMT_FIXED);
+ } else if (type == UPB_DESCRIPTOR_TYPE_SINT64 ||
+ type == UPB_DESCRIPTOR_TYPE_SINT32) {
+ upb_fielddef_setintfmt(f, UPB_INTFMT_ZIGZAG);
+ } else {
+ upb_fielddef_setintfmt(f, UPB_INTFMT_VARIABLE);
+ }
+
+ upb_fielddef_settagdelim(f, type == UPB_DESCRIPTOR_TYPE_GROUP);
+}
+
+upb_descriptortype_t upb_fielddef_descriptortype(const upb_fielddef *f) {
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_FLOAT: return UPB_DESCRIPTOR_TYPE_FLOAT;
+ case UPB_TYPE_DOUBLE: return UPB_DESCRIPTOR_TYPE_DOUBLE;
+ case UPB_TYPE_BOOL: return UPB_DESCRIPTOR_TYPE_BOOL;
+ case UPB_TYPE_STRING: return UPB_DESCRIPTOR_TYPE_STRING;
+ case UPB_TYPE_BYTES: return UPB_DESCRIPTOR_TYPE_BYTES;
+ case UPB_TYPE_ENUM: return UPB_DESCRIPTOR_TYPE_ENUM;
+ case UPB_TYPE_INT32:
+ switch (upb_fielddef_intfmt(f)) {
+ case UPB_INTFMT_VARIABLE: return UPB_DESCRIPTOR_TYPE_INT32;
+ case UPB_INTFMT_FIXED: return UPB_DESCRIPTOR_TYPE_SFIXED32;
+ case UPB_INTFMT_ZIGZAG: return UPB_DESCRIPTOR_TYPE_SINT32;
+ }
+ case UPB_TYPE_INT64:
+ switch (upb_fielddef_intfmt(f)) {
+ case UPB_INTFMT_VARIABLE: return UPB_DESCRIPTOR_TYPE_INT64;
+ case UPB_INTFMT_FIXED: return UPB_DESCRIPTOR_TYPE_SFIXED64;
+ case UPB_INTFMT_ZIGZAG: return UPB_DESCRIPTOR_TYPE_SINT64;
+ }
+ case UPB_TYPE_UINT32:
+ switch (upb_fielddef_intfmt(f)) {
+ case UPB_INTFMT_VARIABLE: return UPB_DESCRIPTOR_TYPE_UINT32;
+ case UPB_INTFMT_FIXED: return UPB_DESCRIPTOR_TYPE_FIXED32;
+ case UPB_INTFMT_ZIGZAG: return -1;
+ }
+ case UPB_TYPE_UINT64:
+ switch (upb_fielddef_intfmt(f)) {
+ case UPB_INTFMT_VARIABLE: return UPB_DESCRIPTOR_TYPE_UINT64;
+ case UPB_INTFMT_FIXED: return UPB_DESCRIPTOR_TYPE_FIXED64;
+ case UPB_INTFMT_ZIGZAG: return -1;
+ }
+ case UPB_TYPE_MESSAGE:
+ return upb_fielddef_istagdelim(f) ?
+ UPB_DESCRIPTOR_TYPE_GROUP : UPB_DESCRIPTOR_TYPE_MESSAGE;
+ }
+ return 0;
+}
+
+void upb_fielddef_setisextension(upb_fielddef *f, bool is_extension) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ f->is_extension_ = is_extension;
+}
+
+void upb_fielddef_setlazy(upb_fielddef *f, bool lazy) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ f->lazy_ = lazy;
+}
+
+void upb_fielddef_setpacked(upb_fielddef *f, bool packed) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ f->packed_ = packed;
+}
+
+void upb_fielddef_setlabel(upb_fielddef *f, upb_label_t label) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ UPB_ASSERT(upb_fielddef_checklabel(label));
+ f->label_ = label;
+}
+
+void upb_fielddef_setintfmt(upb_fielddef *f, upb_intfmt_t fmt) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ UPB_ASSERT(upb_fielddef_checkintfmt(fmt));
+ f->intfmt = fmt;
+}
+
+void upb_fielddef_settagdelim(upb_fielddef *f, bool tag_delim) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ f->tagdelim = tag_delim;
+ f->tagdelim = tag_delim;
+}
+
+static bool checksetdefault(upb_fielddef *f, upb_fieldtype_t type) {
+ if (!f->type_is_set_ || upb_fielddef_isfrozen(f) ||
+ upb_fielddef_type(f) != type) {
+ UPB_ASSERT(false);
+ return false;
+ }
+ if (f->default_is_string) {
+ str_t *s = f->defaultval.bytes;
+ UPB_ASSERT(s || type == UPB_TYPE_ENUM);
+ if (s) freestr(s);
+ }
+ f->default_is_string = false;
+ return true;
+}
+
+void upb_fielddef_setdefaultint64(upb_fielddef *f, int64_t value) {
+ if (checksetdefault(f, UPB_TYPE_INT64))
+ f->defaultval.sint = value;
+}
+
+void upb_fielddef_setdefaultint32(upb_fielddef *f, int32_t value) {
+ if ((upb_fielddef_type(f) == UPB_TYPE_ENUM &&
+ checksetdefault(f, UPB_TYPE_ENUM)) ||
+ checksetdefault(f, UPB_TYPE_INT32)) {
+ f->defaultval.sint = value;
+ }
+}
+
+void upb_fielddef_setdefaultuint64(upb_fielddef *f, uint64_t value) {
+ if (checksetdefault(f, UPB_TYPE_UINT64))
+ f->defaultval.uint = value;
+}
+
+void upb_fielddef_setdefaultuint32(upb_fielddef *f, uint32_t value) {
+ if (checksetdefault(f, UPB_TYPE_UINT32))
+ f->defaultval.uint = value;
+}
+
+void upb_fielddef_setdefaultbool(upb_fielddef *f, bool value) {
+ if (checksetdefault(f, UPB_TYPE_BOOL))
+ f->defaultval.uint = value;
+}
+
+void upb_fielddef_setdefaultfloat(upb_fielddef *f, float value) {
+ if (checksetdefault(f, UPB_TYPE_FLOAT))
+ f->defaultval.flt = value;
+}
+
+void upb_fielddef_setdefaultdouble(upb_fielddef *f, double value) {
+ if (checksetdefault(f, UPB_TYPE_DOUBLE))
+ f->defaultval.dbl = value;
+}
+
+bool upb_fielddef_setdefaultstr(upb_fielddef *f, const void *str, size_t len,
+ upb_status *s) {
+ str_t *str2;
+ UPB_ASSERT(upb_fielddef_isstring(f) || f->type_ == UPB_TYPE_ENUM);
+ if (f->type_ == UPB_TYPE_ENUM && !upb_isident(str, len, false, s))
+ return false;
+
+ if (f->default_is_string) {
+ str_t *s = f->defaultval.bytes;
+ UPB_ASSERT(s || f->type_ == UPB_TYPE_ENUM);
+ if (s) freestr(s);
+ } else {
+ UPB_ASSERT(f->type_ == UPB_TYPE_ENUM);
+ }
+
+ str2 = newstr(str, len);
+ f->defaultval.bytes = str2;
+ f->default_is_string = true;
+ return true;
+}
+
+void upb_fielddef_setdefaultcstr(upb_fielddef *f, const char *str,
+ upb_status *s) {
+ UPB_ASSERT(f->type_is_set_);
+ upb_fielddef_setdefaultstr(f, str, str ? strlen(str) : 0, s);
+}
+
+bool upb_fielddef_enumhasdefaultint32(const upb_fielddef *f) {
+ int32_t val;
+ UPB_ASSERT(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM);
+ return enumdefaultint32(f, &val);
+}
+
+bool upb_fielddef_enumhasdefaultstr(const upb_fielddef *f) {
+ UPB_ASSERT(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM);
+ return enumdefaultstr(f) != NULL;
+}
+
+static bool upb_subdef_typecheck(upb_fielddef *f, const upb_def *subdef,
+ upb_status *s) {
+ if (f->type_ == UPB_TYPE_MESSAGE) {
+ if (upb_dyncast_msgdef(subdef)) return true;
+ upb_status_seterrmsg(s, "invalid subdef type for this submessage field");
+ return false;
+ } else if (f->type_ == UPB_TYPE_ENUM) {
+ if (upb_dyncast_enumdef(subdef)) return true;
+ upb_status_seterrmsg(s, "invalid subdef type for this enum field");
+ return false;
+ } else {
+ upb_status_seterrmsg(s, "only message and enum fields can have a subdef");
+ return false;
+ }
+}
+
+static void release_subdef(upb_fielddef *f) {
+ if (f->subdef_is_symbolic) {
+ upb_gfree(f->sub.name);
+ } else if (f->sub.def) {
+ upb_unref2(f->sub.def, f);
+ }
+}
+
+bool upb_fielddef_setsubdef(upb_fielddef *f, const upb_def *subdef,
+ upb_status *s) {
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ UPB_ASSERT(upb_fielddef_hassubdef(f));
+ if (subdef && !upb_subdef_typecheck(f, subdef, s)) return false;
+ release_subdef(f);
+ f->sub.def = subdef;
+ f->subdef_is_symbolic = false;
+ if (f->sub.def) upb_ref2(f->sub.def, f);
+ return true;
+}
+
+bool upb_fielddef_setmsgsubdef(upb_fielddef *f, const upb_msgdef *subdef,
+ upb_status *s) {
+ return upb_fielddef_setsubdef(f, upb_msgdef_upcast(subdef), s);
+}
+
+bool upb_fielddef_setenumsubdef(upb_fielddef *f, const upb_enumdef *subdef,
+ upb_status *s) {
+ return upb_fielddef_setsubdef(f, upb_enumdef_upcast(subdef), s);
+}
+
+bool upb_fielddef_setsubdefname(upb_fielddef *f, const char *name,
+ upb_status *s) {
+ char *name_copy;
+ UPB_ASSERT(!upb_fielddef_isfrozen(f));
+ if (!upb_fielddef_hassubdef(f)) {
+ upb_status_seterrmsg(s, "field type does not accept a subdef");
+ return false;
+ }
+
+ name_copy = upb_gstrdup(name);
+ if (!name_copy) {
+ upb_upberr_setoom(s);
+ return false;
+ }
+
+ /* TODO: validate name (upb_isident() doesn't quite work atm because this name
+ * may have a leading "."). */
+ release_subdef(f);
+ f->sub.name = name_copy;
+ f->subdef_is_symbolic = true;
+ return true;
+}
+
+bool upb_fielddef_issubmsg(const upb_fielddef *f) {
+ return upb_fielddef_type(f) == UPB_TYPE_MESSAGE;
+}
+
+bool upb_fielddef_isstring(const upb_fielddef *f) {
+ return upb_fielddef_type(f) == UPB_TYPE_STRING ||
+ upb_fielddef_type(f) == UPB_TYPE_BYTES;
+}
+
+bool upb_fielddef_isseq(const upb_fielddef *f) {
+ return upb_fielddef_label(f) == UPB_LABEL_REPEATED;
+}
+
+bool upb_fielddef_isprimitive(const upb_fielddef *f) {
+ return !upb_fielddef_isstring(f) && !upb_fielddef_issubmsg(f);
+}
+
+bool upb_fielddef_ismap(const upb_fielddef *f) {
+ return upb_fielddef_isseq(f) && upb_fielddef_issubmsg(f) &&
+ upb_msgdef_mapentry(upb_fielddef_msgsubdef(f));
+}
+
+bool upb_fielddef_haspresence(const upb_fielddef *f) {
+ if (upb_fielddef_isseq(f)) return false;
+ if (upb_fielddef_issubmsg(f)) return true;
+
+ /* Primitive field: return true unless there is a message that specifies
+ * presence should not exist. */
+ if (f->msg_is_symbolic || !f->msg.def) return true;
+ return f->msg.def->syntax == UPB_SYNTAX_PROTO2;
+}
+
+bool upb_fielddef_hassubdef(const upb_fielddef *f) {
+ return upb_fielddef_issubmsg(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM;
+}
+
+static bool between(int32_t x, int32_t low, int32_t high) {
+ return x >= low && x <= high;
+}
+
+bool upb_fielddef_checklabel(int32_t label) { return between(label, 1, 3); }
+bool upb_fielddef_checktype(int32_t type) { return between(type, 1, 11); }
+bool upb_fielddef_checkintfmt(int32_t fmt) { return between(fmt, 1, 3); }
+
+bool upb_fielddef_checkdescriptortype(int32_t type) {
+ return between(type, 1, 18);
+}
+
+/* upb_msgdef *****************************************************************/
+
+static void visitmsg(const upb_refcounted *r, upb_refcounted_visit *visit,
+ void *closure) {
+ upb_msg_oneof_iter o;
+ const upb_msgdef *m = (const upb_msgdef*)r;
+ const upb_def *def = upb_msgdef_upcast(m);
+ upb_msg_field_iter i;
+ for(upb_msg_field_begin(&i, m);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ upb_fielddef *f = upb_msg_iter_field(&i);
+ visit(r, upb_fielddef_upcast2(f), closure);
+ }
+ for(upb_msg_oneof_begin(&o, m);
+ !upb_msg_oneof_done(&o);
+ upb_msg_oneof_next(&o)) {
+ upb_oneofdef *f = upb_msg_iter_oneof(&o);
+ visit(r, upb_oneofdef_upcast(f), closure);
+ }
+ if (upb_def_file(def)) {
+ visit(r, upb_filedef_upcast(upb_def_file(def)), closure);
+ }
+}
+
+static void freemsg(upb_refcounted *r) {
+ upb_msgdef *m = (upb_msgdef*)r;
+ upb_strtable_uninit(&m->ntof);
+ upb_inttable_uninit(&m->itof);
+ upb_def_uninit(upb_msgdef_upcast_mutable(m));
+ upb_gfree(m);
+}
+
+const struct upb_refcounted_vtbl upb_msgdef_vtbl = {visitmsg, freemsg};
+
+upb_msgdef *upb_msgdef_new(const void *owner) {
+ upb_msgdef *m = upb_gmalloc(sizeof(*m));
+ if (!m) return NULL;
+
+ if (!upb_def_init(upb_msgdef_upcast_mutable(m), UPB_DEF_MSG, &upb_msgdef_vtbl,
+ owner)) {
+ goto err2;
+ }
+
+ if (!upb_inttable_init(&m->itof, UPB_CTYPE_PTR)) goto err2;
+ if (!upb_strtable_init(&m->ntof, UPB_CTYPE_PTR)) goto err1;
+ m->map_entry = false;
+ m->syntax = UPB_SYNTAX_PROTO2;
+ return m;
+
+err1:
+ upb_inttable_uninit(&m->itof);
+err2:
+ upb_gfree(m);
+ return NULL;
+}
+
+static upb_oneofdef *upb_oneofdef_dup(const upb_oneofdef *o, const void *owner);
+
+static upb_msgdef *upb_msgdef_dup(const upb_msgdef *m, const void *owner) {
+ bool ok;
+ upb_msg_field_iter i;
+ upb_msg_oneof_iter o;
+
+ upb_msgdef *newm = upb_msgdef_new(owner);
+ if (!newm) return NULL;
+ ok = upb_def_setfullname(upb_msgdef_upcast_mutable(newm),
+ upb_def_fullname(upb_msgdef_upcast(m)),
+ NULL);
+ newm->map_entry = m->map_entry;
+ newm->syntax = m->syntax;
+ UPB_ASSERT(ok);
+ for(upb_msg_field_begin(&i, m);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ upb_fielddef *f = upb_fielddef_dup(upb_msg_iter_field(&i), &f);
+ /* Fields in oneofs are dup'd below. */
+ if (upb_fielddef_containingoneof(f)) continue;
+ if (!f || !upb_msgdef_addfield(newm, f, &f, NULL)) {
+ upb_msgdef_unref(newm, owner);
+ return NULL;
+ }
+ }
+ for(upb_msg_oneof_begin(&o, m);
+ !upb_msg_oneof_done(&o);
+ upb_msg_oneof_next(&o)) {
+ upb_oneofdef *f = upb_oneofdef_dup(upb_msg_iter_oneof(&o), &f);
+ if (!f || !upb_msgdef_addoneof(newm, f, &f, NULL)) {
+ upb_msgdef_unref(newm, owner);
+ return NULL;
+ }
+ }
+ return newm;
+}
+
+bool upb_msgdef_freeze(upb_msgdef *m, upb_status *status) {
+ upb_def *d = upb_msgdef_upcast_mutable(m);
+ return upb_def_freeze(&d, 1, status);
+}
+
+const char *upb_msgdef_fullname(const upb_msgdef *m) {
+ return upb_def_fullname(upb_msgdef_upcast(m));
+}
+
+const char *upb_msgdef_name(const upb_msgdef *m) {
+ return upb_def_name(upb_msgdef_upcast(m));
+}
+
+bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname,
+ upb_status *s) {
+ return upb_def_setfullname(upb_msgdef_upcast_mutable(m), fullname, s);
+}
+
+bool upb_msgdef_setsyntax(upb_msgdef *m, upb_syntax_t syntax) {
+ if (syntax != UPB_SYNTAX_PROTO2 && syntax != UPB_SYNTAX_PROTO3) {
+ return false;
+ }
+
+ m->syntax = syntax;
+ return true;
+}
+
+upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m) {
+ return m->syntax;
+}
+
+/* Helper: check that the field |f| is safe to add to msgdef |m|. Set an error
+ * on status |s| and return false if not. */
+static bool check_field_add(const upb_msgdef *m, const upb_fielddef *f,
+ upb_status *s) {
+ if (upb_fielddef_containingtype(f) != NULL) {
+ upb_status_seterrmsg(s, "fielddef already belongs to a message");
+ return false;
+ } else if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) {
+ upb_status_seterrmsg(s, "field name or number were not set");
+ return false;
+ } else if (upb_msgdef_itof(m, upb_fielddef_number(f))) {
+ upb_status_seterrmsg(s, "duplicate field number");
+ return false;
+ } else if (upb_strtable_lookup(&m->ntof, upb_fielddef_name(f), NULL)) {
+ upb_status_seterrmsg(s, "name conflicts with existing field or oneof");
+ return false;
+ }
+ return true;
+}
+
+static void add_field(upb_msgdef *m, upb_fielddef *f, const void *ref_donor) {
+ release_containingtype(f);
+ f->msg.def = m;
+ f->msg_is_symbolic = false;
+ upb_inttable_insert(&m->itof, upb_fielddef_number(f), upb_value_ptr(f));
+ upb_strtable_insert(&m->ntof, upb_fielddef_name(f), upb_value_ptr(f));
+ upb_ref2(f, m);
+ upb_ref2(m, f);
+ if (ref_donor) upb_fielddef_unref(f, ref_donor);
+}
+
+bool upb_msgdef_addfield(upb_msgdef *m, upb_fielddef *f, const void *ref_donor,
+ upb_status *s) {
+ /* TODO: extensions need to have a separate namespace, because proto2 allows a
+ * top-level extension (ie. one not in any package) to have the same name as a
+ * field from the message.
+ *
+ * This also implies that there needs to be a separate lookup-by-name method
+ * for extensions. It seems desirable for iteration to return both extensions
+ * and non-extensions though.
+ *
+ * We also need to validate that the field number is in an extension range iff
+ * it is an extension.
+ *
+ * This method is idempotent. Check if |f| is already part of this msgdef and
+ * return immediately if so. */
+ if (upb_fielddef_containingtype(f) == m) {
+ if (ref_donor) upb_fielddef_unref(f, ref_donor);
+ return true;
+ }
+
+ /* Check constraints for all fields before performing any action. */
+ if (!check_field_add(m, f, s)) {
+ return false;
+ } else if (upb_fielddef_containingoneof(f) != NULL) {
+ /* Fields in a oneof can only be added by adding the oneof to the msgdef. */
+ upb_status_seterrmsg(s, "fielddef is part of a oneof");
+ return false;
+ }
+
+ /* Constraint checks ok, perform the action. */
+ add_field(m, f, ref_donor);
+ return true;
+}
+
+bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor,
+ upb_status *s) {
+ upb_oneof_iter it;
+
+ /* Check various conditions that would prevent this oneof from being added. */
+ if (upb_oneofdef_containingtype(o)) {
+ upb_status_seterrmsg(s, "oneofdef already belongs to a message");
+ return false;
+ } else if (upb_oneofdef_name(o) == NULL) {
+ upb_status_seterrmsg(s, "oneofdef name was not set");
+ return false;
+ } else if (upb_strtable_lookup(&m->ntof, upb_oneofdef_name(o), NULL)) {
+ upb_status_seterrmsg(s, "name conflicts with existing field or oneof");
+ return false;
+ }
+
+ /* Check that all of the oneof's fields do not conflict with names or numbers
+ * of fields already in the message. */
+ for (upb_oneof_begin(&it, o); !upb_oneof_done(&it); upb_oneof_next(&it)) {
+ const upb_fielddef *f = upb_oneof_iter_field(&it);
+ if (!check_field_add(m, f, s)) {
+ return false;
+ }
+ }
+
+ /* Everything checks out -- commit now. */
+
+ /* Add oneof itself first. */
+ o->parent = m;
+ upb_strtable_insert(&m->ntof, upb_oneofdef_name(o), upb_value_ptr(o));
+ upb_ref2(o, m);
+ upb_ref2(m, o);
+
+ /* Add each field of the oneof directly to the msgdef. */
+ for (upb_oneof_begin(&it, o); !upb_oneof_done(&it); upb_oneof_next(&it)) {
+ upb_fielddef *f = upb_oneof_iter_field(&it);
+ add_field(m, f, NULL);
+ }
+
+ if (ref_donor) upb_oneofdef_unref(o, ref_donor);
+
+ return true;
+}
+
+const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i) {
+ upb_value val;
+ return upb_inttable_lookup32(&m->itof, i, &val) ?
+ upb_value_getptr(val) : NULL;
+}
+
+const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name,
+ size_t len) {
+ upb_value val;
+
+ if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) {
+ return NULL;
+ }
+
+ return upb_trygetfield(upb_value_getptr(val));
+}
+
+const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name,
+ size_t len) {
+ upb_value val;
+
+ if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) {
+ return NULL;
+ }
+
+ return upb_trygetoneof(upb_value_getptr(val));
+}
+
+bool upb_msgdef_lookupname(const upb_msgdef *m, const char *name, size_t len,
+ const upb_fielddef **f, const upb_oneofdef **o) {
+ upb_value val;
+
+ if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) {
+ return false;
+ }
+
+ *o = upb_trygetoneof(upb_value_getptr(val));
+ *f = upb_trygetfield(upb_value_getptr(val));
+ UPB_ASSERT((*o != NULL) ^ (*f != NULL)); /* Exactly one of the two should be set. */
+ return true;
+}
+
+int upb_msgdef_numfields(const upb_msgdef *m) {
+ /* The number table contains only fields. */
+ return upb_inttable_count(&m->itof);
+}
+
+int upb_msgdef_numoneofs(const upb_msgdef *m) {
+ /* The name table includes oneofs, and the number table does not. */
+ return upb_strtable_count(&m->ntof) - upb_inttable_count(&m->itof);
+}
+
+void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry) {
+ UPB_ASSERT(!upb_msgdef_isfrozen(m));
+ m->map_entry = map_entry;
+}
+
+bool upb_msgdef_mapentry(const upb_msgdef *m) {
+ return m->map_entry;
+}
+
+void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m) {
+ upb_inttable_begin(iter, &m->itof);
+}
+
+void upb_msg_field_next(upb_msg_field_iter *iter) { upb_inttable_next(iter); }
+
+bool upb_msg_field_done(const upb_msg_field_iter *iter) {
+ return upb_inttable_done(iter);
+}
+
+upb_fielddef *upb_msg_iter_field(const upb_msg_field_iter *iter) {
+ return (upb_fielddef*)upb_value_getptr(upb_inttable_iter_value(iter));
+}
+
+void upb_msg_field_iter_setdone(upb_msg_field_iter *iter) {
+ upb_inttable_iter_setdone(iter);
+}
+
+void upb_msg_oneof_begin(upb_msg_oneof_iter *iter, const upb_msgdef *m) {
+ upb_strtable_begin(iter, &m->ntof);
+ /* We need to skip past any initial fields. */
+ while (!upb_strtable_done(iter) &&
+ !upb_isoneof(upb_value_getptr(upb_strtable_iter_value(iter)))) {
+ upb_strtable_next(iter);
+ }
+}
+
+void upb_msg_oneof_next(upb_msg_oneof_iter *iter) {
+ /* We need to skip past fields to return only oneofs. */
+ do {
+ upb_strtable_next(iter);
+ } while (!upb_strtable_done(iter) &&
+ !upb_isoneof(upb_value_getptr(upb_strtable_iter_value(iter))));
+}
+
+bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter) {
+ return upb_strtable_done(iter);
+}
+
+upb_oneofdef *upb_msg_iter_oneof(const upb_msg_oneof_iter *iter) {
+ return (upb_oneofdef*)upb_value_getptr(upb_strtable_iter_value(iter));
+}
+
+void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter *iter) {
+ upb_strtable_iter_setdone(iter);
+}
+
+/* upb_oneofdef ***************************************************************/
+
+static void visitoneof(const upb_refcounted *r, upb_refcounted_visit *visit,
+ void *closure) {
+ const upb_oneofdef *o = (const upb_oneofdef*)r;
+ upb_oneof_iter i;
+ for (upb_oneof_begin(&i, o); !upb_oneof_done(&i); upb_oneof_next(&i)) {
+ const upb_fielddef *f = upb_oneof_iter_field(&i);
+ visit(r, upb_fielddef_upcast2(f), closure);
+ }
+ if (o->parent) {
+ visit(r, upb_msgdef_upcast2(o->parent), closure);
+ }
+}
+
+static void freeoneof(upb_refcounted *r) {
+ upb_oneofdef *o = (upb_oneofdef*)r;
+ upb_strtable_uninit(&o->ntof);
+ upb_inttable_uninit(&o->itof);
+ upb_gfree((void*)o->name);
+ upb_gfree(o);
+}
+
+const struct upb_refcounted_vtbl upb_oneofdef_vtbl = {visitoneof, freeoneof};
+
+upb_oneofdef *upb_oneofdef_new(const void *owner) {
+ upb_oneofdef *o = upb_gmalloc(sizeof(*o));
+
+ if (!o) {
+ return NULL;
+ }
+
+ o->parent = NULL;
+ o->name = NULL;
+
+ if (!upb_refcounted_init(upb_oneofdef_upcast_mutable(o), &upb_oneofdef_vtbl,
+ owner)) {
+ goto err2;
+ }
+
+ if (!upb_inttable_init(&o->itof, UPB_CTYPE_PTR)) goto err2;
+ if (!upb_strtable_init(&o->ntof, UPB_CTYPE_PTR)) goto err1;
+
+ return o;
+
+err1:
+ upb_inttable_uninit(&o->itof);
+err2:
+ upb_gfree(o);
+ return NULL;
+}
+
+static upb_oneofdef *upb_oneofdef_dup(const upb_oneofdef *o,
+ const void *owner) {
+ bool ok;
+ upb_oneof_iter i;
+ upb_oneofdef *newo = upb_oneofdef_new(owner);
+ if (!newo) return NULL;
+ ok = upb_oneofdef_setname(newo, upb_oneofdef_name(o), NULL);
+ UPB_ASSERT(ok);
+ for (upb_oneof_begin(&i, o); !upb_oneof_done(&i); upb_oneof_next(&i)) {
+ upb_fielddef *f = upb_fielddef_dup(upb_oneof_iter_field(&i), &f);
+ if (!f || !upb_oneofdef_addfield(newo, f, &f, NULL)) {
+ upb_oneofdef_unref(newo, owner);
+ return NULL;
+ }
+ }
+ return newo;
+}
+
+const char *upb_oneofdef_name(const upb_oneofdef *o) { return o->name; }
+
+bool upb_oneofdef_setname(upb_oneofdef *o, const char *name, upb_status *s) {
+ UPB_ASSERT(!upb_oneofdef_isfrozen(o));
+ if (upb_oneofdef_containingtype(o)) {
+ upb_status_seterrmsg(s, "oneof already added to a message");
+ return false;
+ }
+
+ if (!upb_isident(name, strlen(name), true, s)) {
+ return false;
+ }
+
+ name = upb_gstrdup(name);
+ if (!name) {
+ upb_status_seterrmsg(s, "One of memory");
+ return false;
+ }
+
+ upb_gfree((void*)o->name);
+ o->name = name;
+ return true;
+}
+
+const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o) {
+ return o->parent;
+}
+
+int upb_oneofdef_numfields(const upb_oneofdef *o) {
+ return upb_strtable_count(&o->ntof);
+}
+
+uint32_t upb_oneofdef_index(const upb_oneofdef *o) {
+ return o->index;
+}
+
+bool upb_oneofdef_addfield(upb_oneofdef *o, upb_fielddef *f,
+ const void *ref_donor,
+ upb_status *s) {
+ UPB_ASSERT(!upb_oneofdef_isfrozen(o));
+ UPB_ASSERT(!o->parent || !upb_msgdef_isfrozen(o->parent));
+
+ /* This method is idempotent. Check if |f| is already part of this oneofdef
+ * and return immediately if so. */
+ if (upb_fielddef_containingoneof(f) == o) {
+ return true;
+ }
+
+ /* The field must have an OPTIONAL label. */
+ if (upb_fielddef_label(f) != UPB_LABEL_OPTIONAL) {
+ upb_status_seterrmsg(s, "fields in oneof must have OPTIONAL label");
+ return false;
+ }
+
+ /* Check that no field with this name or number exists already in the oneof.
+ * Also check that the field is not already part of a oneof. */
+ if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) {
+ upb_status_seterrmsg(s, "field name or number were not set");
+ return false;
+ } else if (upb_oneofdef_itof(o, upb_fielddef_number(f)) ||
+ upb_oneofdef_ntofz(o, upb_fielddef_name(f))) {
+ upb_status_seterrmsg(s, "duplicate field name or number");
+ return false;
+ } else if (upb_fielddef_containingoneof(f) != NULL) {
+ upb_status_seterrmsg(s, "fielddef already belongs to a oneof");
+ return false;
+ }
+
+ /* We allow adding a field to the oneof either if the field is not part of a
+ * msgdef, or if it is and we are also part of the same msgdef. */
+ if (o->parent == NULL) {
+ /* If we're not in a msgdef, the field cannot be either. Otherwise we would
+ * need to magically add this oneof to a msgdef to remain consistent, which
+ * is surprising behavior. */
+ if (upb_fielddef_containingtype(f) != NULL) {
+ upb_status_seterrmsg(s, "fielddef already belongs to a message, but "
+ "oneof does not");
+ return false;
+ }
+ } else {
+ /* If we're in a msgdef, the user can add fields that either aren't in any
+ * msgdef (in which case they're added to our msgdef) or already a part of
+ * our msgdef. */
+ if (upb_fielddef_containingtype(f) != NULL &&
+ upb_fielddef_containingtype(f) != o->parent) {
+ upb_status_seterrmsg(s, "fielddef belongs to a different message "
+ "than oneof");
+ return false;
+ }
+ }
+
+ /* Commit phase. First add the field to our parent msgdef, if any, because
+ * that may fail; then add the field to our own tables. */
+
+ if (o->parent != NULL && upb_fielddef_containingtype(f) == NULL) {
+ if (!upb_msgdef_addfield((upb_msgdef*)o->parent, f, NULL, s)) {
+ return false;
+ }
+ }
+
+ release_containingtype(f);
+ f->oneof = o;
+ upb_inttable_insert(&o->itof, upb_fielddef_number(f), upb_value_ptr(f));
+ upb_strtable_insert(&o->ntof, upb_fielddef_name(f), upb_value_ptr(f));
+ upb_ref2(f, o);
+ upb_ref2(o, f);
+ if (ref_donor) upb_fielddef_unref(f, ref_donor);
+
+ return true;
+}
+
+const upb_fielddef *upb_oneofdef_ntof(const upb_oneofdef *o,
+ const char *name, size_t length) {
+ upb_value val;
+ return upb_strtable_lookup2(&o->ntof, name, length, &val) ?
+ upb_value_getptr(val) : NULL;
+}
+
+const upb_fielddef *upb_oneofdef_itof(const upb_oneofdef *o, uint32_t num) {
+ upb_value val;
+ return upb_inttable_lookup32(&o->itof, num, &val) ?
+ upb_value_getptr(val) : NULL;
+}
+
+void upb_oneof_begin(upb_oneof_iter *iter, const upb_oneofdef *o) {
+ upb_inttable_begin(iter, &o->itof);
+}
+
+void upb_oneof_next(upb_oneof_iter *iter) {
+ upb_inttable_next(iter);
+}
+
+bool upb_oneof_done(upb_oneof_iter *iter) {
+ return upb_inttable_done(iter);
+}
+
+upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter) {
+ return (upb_fielddef*)upb_value_getptr(upb_inttable_iter_value(iter));
+}
+
+void upb_oneof_iter_setdone(upb_oneof_iter *iter) {
+ upb_inttable_iter_setdone(iter);
+}
+
+/* upb_filedef ****************************************************************/
+
+static void visitfiledef(const upb_refcounted *r, upb_refcounted_visit *visit,
+ void *closure) {
+ const upb_filedef *f = (const upb_filedef*)r;
+ size_t i;
+
+ for(i = 0; i < upb_filedef_defcount(f); i++) {
+ visit(r, upb_def_upcast(upb_filedef_def(f, i)), closure);
+ }
+}
+
+static void freefiledef(upb_refcounted *r) {
+ upb_filedef *f = (upb_filedef*)r;
+ size_t i;
+
+ for(i = 0; i < upb_filedef_depcount(f); i++) {
+ upb_filedef_unref(upb_filedef_dep(f, i), f);
+ }
+
+ upb_inttable_uninit(&f->defs);
+ upb_inttable_uninit(&f->deps);
+ upb_gfree((void*)f->name);
+ upb_gfree((void*)f->package);
+ upb_gfree(f);
+}
+
+const struct upb_refcounted_vtbl upb_filedef_vtbl = {visitfiledef, freefiledef};
+
+upb_filedef *upb_filedef_new(const void *owner) {
+ upb_filedef *f = upb_gmalloc(sizeof(*f));
+
+ if (!f) {
+ return NULL;
+ }
+
+ f->package = NULL;
+ f->name = NULL;
+ f->syntax = UPB_SYNTAX_PROTO2;
+
+ if (!upb_refcounted_init(upb_filedef_upcast_mutable(f), &upb_filedef_vtbl,
+ owner)) {
+ goto err;
+ }
+
+ if (!upb_inttable_init(&f->defs, UPB_CTYPE_CONSTPTR)) {
+ goto err;
+ }
+
+ if (!upb_inttable_init(&f->deps, UPB_CTYPE_CONSTPTR)) {
+ goto err2;
+ }
+
+ return f;
+
+
+err2:
+ upb_inttable_uninit(&f->defs);
+
+err:
+ upb_gfree(f);
+ return NULL;
+}
+
+const char *upb_filedef_name(const upb_filedef *f) {
+ return f->name;
+}
+
+const char *upb_filedef_package(const upb_filedef *f) {
+ return f->package;
+}
+
+upb_syntax_t upb_filedef_syntax(const upb_filedef *f) {
+ return f->syntax;
+}
+
+size_t upb_filedef_defcount(const upb_filedef *f) {
+ return upb_inttable_count(&f->defs);
+}
+
+size_t upb_filedef_depcount(const upb_filedef *f) {
+ return upb_inttable_count(&f->deps);
+}
+
+const upb_def *upb_filedef_def(const upb_filedef *f, size_t i) {
+ upb_value v;
+
+ if (upb_inttable_lookup32(&f->defs, i, &v)) {
+ return upb_value_getconstptr(v);
+ } else {
+ return NULL;
+ }
+}
+
+const upb_filedef *upb_filedef_dep(const upb_filedef *f, size_t i) {
+ upb_value v;
+
+ if (upb_inttable_lookup32(&f->deps, i, &v)) {
+ return upb_value_getconstptr(v);
+ } else {
+ return NULL;
+ }
+}
+
+bool upb_filedef_setname(upb_filedef *f, const char *name, upb_status *s) {
+ name = upb_gstrdup(name);
+ if (!name) {
+ upb_upberr_setoom(s);
+ return false;
+ }
+ upb_gfree((void*)f->name);
+ f->name = name;
+ return true;
+}
+
+bool upb_filedef_setpackage(upb_filedef *f, const char *package,
+ upb_status *s) {
+ if (!upb_isident(package, strlen(package), true, s)) return false;
+ package = upb_gstrdup(package);
+ if (!package) {
+ upb_upberr_setoom(s);
+ return false;
+ }
+ upb_gfree((void*)f->package);
+ f->package = package;
+ return true;
+}
+
+bool upb_filedef_setsyntax(upb_filedef *f, upb_syntax_t syntax,
+ upb_status *s) {
+ UPB_UNUSED(s);
+ if (syntax != UPB_SYNTAX_PROTO2 &&
+ syntax != UPB_SYNTAX_PROTO3) {
+ upb_status_seterrmsg(s, "Unknown syntax value.");
+ return false;
+ }
+ f->syntax = syntax;
+
+ {
+ /* Set all messages in this file to match. */
+ size_t i;
+ for (i = 0; i < upb_filedef_defcount(f); i++) {
+ /* Casting const away is safe since all defs in mutable filedef must
+ * also be mutable. */
+ upb_def *def = (upb_def*)upb_filedef_def(f, i);
+
+ upb_msgdef *m = upb_dyncast_msgdef_mutable(def);
+ if (m) {
+ m->syntax = syntax;
+ }
+ }
+ }
+
+ return true;
+}
+
+bool upb_filedef_adddef(upb_filedef *f, upb_def *def, const void *ref_donor,
+ upb_status *s) {
+ if (def->file) {
+ upb_status_seterrmsg(s, "Def is already part of another filedef.");
+ return false;
+ }
+
+ if (upb_inttable_push(&f->defs, upb_value_constptr(def))) {
+ def->file = f;
+ upb_ref2(def, f);
+ upb_ref2(f, def);
+ if (ref_donor) upb_def_unref(def, ref_donor);
+ if (def->type == UPB_DEF_MSG) {
+ upb_downcast_msgdef_mutable(def)->syntax = f->syntax;
+ }
+ return true;
+ } else {
+ upb_upberr_setoom(s);
+ return false;
+ }
+}
+
+bool upb_filedef_adddep(upb_filedef *f, const upb_filedef *dep) {
+ if (upb_inttable_push(&f->deps, upb_value_constptr(dep))) {
+ /* Regular ref instead of ref2 because files can't form cycles. */
+ upb_filedef_ref(dep, f);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+void upb_symtab_free(upb_symtab *s) {
+ upb_strtable_iter i;
+ upb_strtable_begin(&i, &s->symtab);
+ for (; !upb_strtable_done(&i); upb_strtable_next(&i)) {
+ const upb_def *def = upb_value_getptr(upb_strtable_iter_value(&i));
+ upb_def_unref(def, s);
+ }
+ upb_strtable_uninit(&s->symtab);
+ upb_gfree(s);
+}
+
+upb_symtab *upb_symtab_new() {
+ upb_symtab *s = upb_gmalloc(sizeof(*s));
+ if (!s) {
+ return NULL;
+ }
+
+ upb_strtable_init(&s->symtab, UPB_CTYPE_PTR);
+ return s;
+}
+
+const upb_def *upb_symtab_lookup(const upb_symtab *s, const char *sym) {
+ upb_value v;
+ upb_def *ret = upb_strtable_lookup(&s->symtab, sym, &v) ?
+ upb_value_getptr(v) : NULL;
+ return ret;
+}
+
+const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym) {
+ upb_value v;
+ upb_def *def = upb_strtable_lookup(&s->symtab, sym, &v) ?
+ upb_value_getptr(v) : NULL;
+ return def ? upb_dyncast_msgdef(def) : NULL;
+}
+
+const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym) {
+ upb_value v;
+ upb_def *def = upb_strtable_lookup(&s->symtab, sym, &v) ?
+ upb_value_getptr(v) : NULL;
+ return def ? upb_dyncast_enumdef(def) : NULL;
+}
+
+/* Given a symbol and the base symbol inside which it is defined, find the
+ * symbol's definition in t. */
+static upb_def *upb_resolvename(const upb_strtable *t,
+ const char *base, const char *sym) {
+ if(strlen(sym) == 0) return NULL;
+ if(sym[0] == '.') {
+ /* Symbols starting with '.' are absolute, so we do a single lookup.
+ * Slice to omit the leading '.' */
+ upb_value v;
+ return upb_strtable_lookup(t, sym + 1, &v) ? upb_value_getptr(v) : NULL;
+ } else {
+ /* Remove components from base until we find an entry or run out.
+ * TODO: This branch is totally broken, but currently not used. */
+ (void)base;
+ UPB_ASSERT(false);
+ return NULL;
+ }
+}
+
+const upb_def *upb_symtab_resolve(const upb_symtab *s, const char *base,
+ const char *sym) {
+ upb_def *ret = upb_resolvename(&s->symtab, base, sym);
+ return ret;
+}
+
+/* TODO(haberman): we need a lot more testing of error conditions. */
+static bool symtab_add(upb_symtab *s, upb_def *const*defs, size_t n,
+ void *ref_donor, upb_refcounted *freeze_also,
+ upb_status *status) {
+ size_t i;
+ size_t add_n;
+ size_t freeze_n;
+ upb_strtable_iter iter;
+ upb_refcounted **add_objs = NULL;
+ upb_def **add_defs = NULL;
+ size_t add_objs_size;
+ upb_strtable addtab;
+
+ if (n == 0 && !freeze_also) {
+ return true;
+ }
+
+ if (!upb_strtable_init(&addtab, UPB_CTYPE_PTR)) {
+ upb_status_seterrmsg(status, "out of memory");
+ return false;
+ }
+
+ /* Add new defs to our "add" set. */
+ for (i = 0; i < n; i++) {
+ upb_def *def = defs[i];
+ const char *fullname;
+ upb_fielddef *f;
+
+ if (upb_def_isfrozen(def)) {
+ upb_status_seterrmsg(status, "added defs must be mutable");
+ goto err;
+ }
+ UPB_ASSERT(!upb_def_isfrozen(def));
+ fullname = upb_def_fullname(def);
+ if (!fullname) {
+ upb_status_seterrmsg(
+ status, "Anonymous defs cannot be added to a symtab");
+ goto err;
+ }
+
+ f = upb_dyncast_fielddef_mutable(def);
+
+ if (f) {
+ if (!upb_fielddef_containingtypename(f)) {
+ upb_status_seterrmsg(status,
+ "Standalone fielddefs must have a containing type "
+ "(extendee) name set");
+ goto err;
+ }
+ } else {
+ if (upb_strtable_lookup(&addtab, fullname, NULL)) {
+ upb_status_seterrf(status, "Conflicting defs named '%s'", fullname);
+ goto err;
+ }
+ if (upb_strtable_lookup(&s->symtab, fullname, NULL)) {
+ upb_status_seterrf(status, "Symtab already has a def named '%s'",
+ fullname);
+ goto err;
+ }
+ upb_def_donateref(def, ref_donor, s);
+ if (!upb_strtable_insert(&addtab, fullname, upb_value_ptr(def)))
+ goto oom_err;
+ def->came_from_user = true;
+ }
+ }
+
+ /* Add standalone fielddefs (ie. extensions) to the appropriate messages.
+ * If the appropriate message only exists in the existing symtab, duplicate
+ * it so we have a mutable copy we can add the fields to. */
+ for (i = 0; i < n; i++) {
+ upb_def *def = defs[i];
+ upb_fielddef *f = upb_dyncast_fielddef_mutable(def);
+ const char *msgname;
+ upb_value v;
+ upb_msgdef *m;
+
+ if (!f) continue;
+ msgname = upb_fielddef_containingtypename(f);
+ /* We validated this earlier in this function. */
+ UPB_ASSERT(msgname);
+
+ /* If the extendee name is absolutely qualified, move past the initial ".".
+ * TODO(haberman): it is not obvious what it would mean if this was not
+ * absolutely qualified. */
+ if (msgname[0] == '.') {
+ msgname++;
+ }
+
+ if (upb_strtable_lookup(&addtab, msgname, &v)) {
+ /* Extendee is in the set of defs the user asked us to add. */
+ m = upb_value_getptr(v);
+ } else {
+ /* Need to find and dup the extendee from the existing symtab. */
+ const upb_msgdef *frozen_m = upb_symtab_lookupmsg(s, msgname);
+ if (!frozen_m) {
+ upb_status_seterrf(status,
+ "Tried to extend message %s that does not exist "
+ "in this SymbolTable.",
+ msgname);
+ goto err;
+ }
+ m = upb_msgdef_dup(frozen_m, s);
+ if (!m) goto oom_err;
+ if (!upb_strtable_insert(&addtab, msgname, upb_value_ptr(m))) {
+ upb_msgdef_unref(m, s);
+ goto oom_err;
+ }
+ }
+
+ if (!upb_msgdef_addfield(m, f, ref_donor, status)) {
+ goto err;
+ }
+ }
+
+ /* Now using the table, resolve symbolic references for subdefs. */
+ upb_strtable_begin(&iter, &addtab);
+ for (; !upb_strtable_done(&iter); upb_strtable_next(&iter)) {
+ const char *base;
+ upb_def *def = upb_value_getptr(upb_strtable_iter_value(&iter));
+ upb_msgdef *m = upb_dyncast_msgdef_mutable(def);
+ upb_msg_field_iter j;
+
+ if (!m) continue;
+ /* Type names are resolved relative to the message in which they appear. */
+ base = upb_msgdef_fullname(m);
+
+ for(upb_msg_field_begin(&j, m);
+ !upb_msg_field_done(&j);
+ upb_msg_field_next(&j)) {
+ upb_fielddef *f = upb_msg_iter_field(&j);
+ const char *name = upb_fielddef_subdefname(f);
+ if (name && !upb_fielddef_subdef(f)) {
+ /* Try the lookup in the current set of to-be-added defs first. If not
+ * there, try existing defs. */
+ upb_def *subdef = upb_resolvename(&addtab, base, name);
+ if (subdef == NULL) {
+ subdef = upb_resolvename(&s->symtab, base, name);
+ }
+ if (subdef == NULL) {
+ upb_status_seterrf(
+ status, "couldn't resolve name '%s' in message '%s'", name, base);
+ goto err;
+ } else if (!upb_fielddef_setsubdef(f, subdef, status)) {
+ goto err;
+ }
+ }
+ }
+ }
+
+ /* We need an array of the defs in addtab, for passing to
+ * upb_refcounted_freeze(). */
+ add_objs_size = upb_strtable_count(&addtab);
+ if (freeze_also) {
+ add_objs_size++;
+ }
+
+ add_defs = upb_gmalloc(sizeof(void*) * add_objs_size);
+ if (add_defs == NULL) goto oom_err;
+ upb_strtable_begin(&iter, &addtab);
+ for (add_n = 0; !upb_strtable_done(&iter); upb_strtable_next(&iter)) {
+ add_defs[add_n++] = upb_value_getptr(upb_strtable_iter_value(&iter));
+ }
+
+ /* Validate defs. */
+ if (!_upb_def_validate(add_defs, add_n, status)) {
+ goto err;
+ }
+
+ /* Cheat a little and give the array a new type.
+ * This is probably undefined behavior, but this code will be deleted soon. */
+ add_objs = (upb_refcounted**)add_defs;
+
+ freeze_n = add_n;
+ if (freeze_also) {
+ add_objs[freeze_n++] = freeze_also;
+ }
+
+ if (!upb_refcounted_freeze(add_objs, freeze_n, status,
+ UPB_MAX_MESSAGE_DEPTH * 2)) {
+ goto err;
+ }
+
+ /* This must be delayed until all errors have been detected, since error
+ * recovery code uses this table to cleanup defs. */
+ upb_strtable_uninit(&addtab);
+
+ /* TODO(haberman) we don't properly handle errors after this point (like
+ * OOM in upb_strtable_insert() below). */
+ for (i = 0; i < add_n; i++) {
+ upb_def *def = (upb_def*)add_objs[i];
+ const char *name = upb_def_fullname(def);
+ upb_value v;
+ bool success;
+
+ if (upb_strtable_remove(&s->symtab, name, &v)) {
+ const upb_def *def = upb_value_getptr(v);
+ upb_def_unref(def, s);
+ }
+ success = upb_strtable_insert(&s->symtab, name, upb_value_ptr(def));
+ UPB_ASSERT(success == true);
+ }
+ upb_gfree(add_defs);
+ return true;
+
+oom_err:
+ upb_status_seterrmsg(status, "out of memory");
+err: {
+ /* We need to donate the refs back. */
+ upb_strtable_begin(&iter, &addtab);
+ for (; !upb_strtable_done(&iter); upb_strtable_next(&iter)) {
+ upb_def *def = upb_value_getptr(upb_strtable_iter_value(&iter));
+ upb_def_donateref(def, s, ref_donor);
+ }
+ }
+ upb_strtable_uninit(&addtab);
+ upb_gfree(add_defs);
+ UPB_ASSERT(!upb_ok(status));
+ return false;
+}
+
+bool upb_symtab_add(upb_symtab *s, upb_def *const*defs, size_t n,
+ void *ref_donor, upb_status *status) {
+ return symtab_add(s, defs, n, ref_donor, NULL, status);
+}
+
+bool upb_symtab_addfile(upb_symtab *s, upb_filedef *file, upb_status *status) {
+ size_t n;
+ size_t i;
+ upb_def **defs;
+ bool ret;
+
+ n = upb_filedef_defcount(file);
+ defs = upb_gmalloc(sizeof(*defs) * n);
+
+ if (defs == NULL) {
+ upb_status_seterrmsg(status, "Out of memory");
+ return false;
+ }
+
+ for (i = 0; i < n; i++) {
+ defs[i] = upb_filedef_mutabledef(file, i);
+ }
+
+ ret = symtab_add(s, defs, n, NULL, upb_filedef_upcast_mutable(file), status);
+
+ upb_gfree(defs);
+ return ret;
+}
+
+/* Iteration. */
+
+static void advance_to_matching(upb_symtab_iter *iter) {
+ if (iter->type == UPB_DEF_ANY)
+ return;
+
+ while (!upb_strtable_done(&iter->iter) &&
+ iter->type != upb_symtab_iter_def(iter)->type) {
+ upb_strtable_next(&iter->iter);
+ }
+}
+
+void upb_symtab_begin(upb_symtab_iter *iter, const upb_symtab *s,
+ upb_deftype_t type) {
+ upb_strtable_begin(&iter->iter, &s->symtab);
+ iter->type = type;
+ advance_to_matching(iter);
+}
+
+void upb_symtab_next(upb_symtab_iter *iter) {
+ upb_strtable_next(&iter->iter);
+ advance_to_matching(iter);
+}
+
+bool upb_symtab_done(const upb_symtab_iter *iter) {
+ return upb_strtable_done(&iter->iter);
+}
+
+const upb_def *upb_symtab_iter_def(const upb_symtab_iter *iter) {
+ return upb_value_getptr(upb_strtable_iter_value(&iter->iter));
+}
+/*
+** TODO(haberman): it's unclear whether a lot of the consistency checks should
+** UPB_ASSERT() or return false.
+*/
+
+
+#include <string.h>
+
+
+static void *upb_calloc(size_t size) {
+ void *mem = upb_gmalloc(size);
+ if (mem) {
+ memset(mem, 0, size);
+ }
+ return mem;
+}
+
+/* Defined for the sole purpose of having a unique pointer value for
+ * UPB_NO_CLOSURE. */
+char _upb_noclosure;
+
+static void freehandlers(upb_refcounted *r) {
+ upb_handlers *h = (upb_handlers*)r;
+
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, &h->cleanup_);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ void *val = (void*)upb_inttable_iter_key(&i);
+ upb_value func_val = upb_inttable_iter_value(&i);
+ upb_handlerfree *func = upb_value_getfptr(func_val);
+ func(val);
+ }
+
+ upb_inttable_uninit(&h->cleanup_);
+ upb_msgdef_unref(h->msg, h);
+ upb_gfree(h->sub);
+ upb_gfree(h);
+}
+
+static void visithandlers(const upb_refcounted *r, upb_refcounted_visit *visit,
+ void *closure) {
+ const upb_handlers *h = (const upb_handlers*)r;
+ upb_msg_field_iter i;
+ for(upb_msg_field_begin(&i, h->msg);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ upb_fielddef *f = upb_msg_iter_field(&i);
+ const upb_handlers *sub;
+ if (!upb_fielddef_issubmsg(f)) continue;
+ sub = upb_handlers_getsubhandlers(h, f);
+ if (sub) visit(r, upb_handlers_upcast(sub), closure);
+ }
+}
+
+static const struct upb_refcounted_vtbl vtbl = {visithandlers, freehandlers};
+
+typedef struct {
+ upb_inttable tab; /* maps upb_msgdef* -> upb_handlers*. */
+ upb_handlers_callback *callback;
+ const void *closure;
+} dfs_state;
+
+/* TODO(haberman): discard upb_handlers* objects that do not actually have any
+ * handlers set and cannot reach any upb_handlers* object that does. This is
+ * slightly tricky to do correctly. */
+static upb_handlers *newformsg(const upb_msgdef *m, const void *owner,
+ dfs_state *s) {
+ upb_msg_field_iter i;
+ upb_handlers *h = upb_handlers_new(m, owner);
+ if (!h) return NULL;
+ if (!upb_inttable_insertptr(&s->tab, m, upb_value_ptr(h))) goto oom;
+
+ s->callback(s->closure, h);
+
+ /* For each submessage field, get or create a handlers object and set it as
+ * the subhandlers. */
+ for(upb_msg_field_begin(&i, m);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ upb_fielddef *f = upb_msg_iter_field(&i);
+ const upb_msgdef *subdef;
+ upb_value subm_ent;
+
+ if (!upb_fielddef_issubmsg(f)) continue;
+
+ subdef = upb_downcast_msgdef(upb_fielddef_subdef(f));
+ if (upb_inttable_lookupptr(&s->tab, subdef, &subm_ent)) {
+ upb_handlers_setsubhandlers(h, f, upb_value_getptr(subm_ent));
+ } else {
+ upb_handlers *sub_mh = newformsg(subdef, &sub_mh, s);
+ if (!sub_mh) goto oom;
+ upb_handlers_setsubhandlers(h, f, sub_mh);
+ upb_handlers_unref(sub_mh, &sub_mh);
+ }
+ }
+ return h;
+
+oom:
+ upb_handlers_unref(h, owner);
+ return NULL;
+}
+
+/* Given a selector for a STARTSUBMSG handler, resolves to a pointer to the
+ * subhandlers for this submessage field. */
+#define SUBH(h, selector) (h->sub[selector])
+
+/* The selector for a submessage field is the field index. */
+#define SUBH_F(h, f) SUBH(h, f->index_)
+
+static int32_t trygetsel(upb_handlers *h, const upb_fielddef *f,
+ upb_handlertype_t type) {
+ upb_selector_t sel;
+ UPB_ASSERT(!upb_handlers_isfrozen(h));
+ if (upb_handlers_msgdef(h) != upb_fielddef_containingtype(f)) {
+ upb_status_seterrf(
+ &h->status_, "type mismatch: field %s does not belong to message %s",
+ upb_fielddef_name(f), upb_msgdef_fullname(upb_handlers_msgdef(h)));
+ return -1;
+ }
+ if (!upb_handlers_getselector(f, type, &sel)) {
+ upb_status_seterrf(
+ &h->status_,
+ "type mismatch: cannot register handler type %d for field %s",
+ type, upb_fielddef_name(f));
+ return -1;
+ }
+ return sel;
+}
+
+static upb_selector_t handlers_getsel(upb_handlers *h, const upb_fielddef *f,
+ upb_handlertype_t type) {
+ int32_t sel = trygetsel(h, f, type);
+ UPB_ASSERT(sel >= 0);
+ return sel;
+}
+
+static const void **returntype(upb_handlers *h, const upb_fielddef *f,
+ upb_handlertype_t type) {
+ return &h->table[handlers_getsel(h, f, type)].attr.return_closure_type_;
+}
+
+static bool doset(upb_handlers *h, int32_t sel, const upb_fielddef *f,
+ upb_handlertype_t type, upb_func *func,
+ upb_handlerattr *attr) {
+ upb_handlerattr set_attr = UPB_HANDLERATTR_INITIALIZER;
+ const void *closure_type;
+ const void **context_closure_type;
+
+ UPB_ASSERT(!upb_handlers_isfrozen(h));
+
+ if (sel < 0) {
+ upb_status_seterrmsg(&h->status_,
+ "incorrect handler type for this field.");
+ return false;
+ }
+
+ if (h->table[sel].func) {
+ upb_status_seterrmsg(&h->status_,
+ "cannot change handler once it has been set.");
+ return false;
+ }
+
+ if (attr) {
+ set_attr = *attr;
+ }
+
+ /* Check that the given closure type matches the closure type that has been
+ * established for this context (if any). */
+ closure_type = upb_handlerattr_closuretype(&set_attr);
+
+ if (type == UPB_HANDLER_STRING) {
+ context_closure_type = returntype(h, f, UPB_HANDLER_STARTSTR);
+ } else if (f && upb_fielddef_isseq(f) &&
+ type != UPB_HANDLER_STARTSEQ &&
+ type != UPB_HANDLER_ENDSEQ) {
+ context_closure_type = returntype(h, f, UPB_HANDLER_STARTSEQ);
+ } else {
+ context_closure_type = &h->top_closure_type;
+ }
+
+ if (closure_type && *context_closure_type &&
+ closure_type != *context_closure_type) {
+ /* TODO(haberman): better message for debugging. */
+ if (f) {
+ upb_status_seterrf(&h->status_,
+ "closure type does not match for field %s",
+ upb_fielddef_name(f));
+ } else {
+ upb_status_seterrmsg(
+ &h->status_, "closure type does not match for message-level handler");
+ }
+ return false;
+ }
+
+ if (closure_type)
+ *context_closure_type = closure_type;
+
+ /* If this is a STARTSEQ or STARTSTR handler, check that the returned pointer
+ * matches any pre-existing expectations about what type is expected. */
+ if (type == UPB_HANDLER_STARTSEQ || type == UPB_HANDLER_STARTSTR) {
+ const void *return_type = upb_handlerattr_returnclosuretype(&set_attr);
+ const void *table_return_type =
+ upb_handlerattr_returnclosuretype(&h->table[sel].attr);
+ if (return_type && table_return_type && return_type != table_return_type) {
+ upb_status_seterrmsg(&h->status_, "closure return type does not match");
+ return false;
+ }
+
+ if (table_return_type && !return_type)
+ upb_handlerattr_setreturnclosuretype(&set_attr, table_return_type);
+ }
+
+ h->table[sel].func = (upb_func*)func;
+ h->table[sel].attr = set_attr;
+ return true;
+}
+
+/* Returns the effective closure type for this handler (which will propagate
+ * from outer frames if this frame has no START* handler). Not implemented for
+ * UPB_HANDLER_STRING at the moment since this is not needed. Returns NULL is
+ * the effective closure type is unspecified (either no handler was registered
+ * to specify it or the handler that was registered did not specify the closure
+ * type). */
+const void *effective_closure_type(upb_handlers *h, const upb_fielddef *f,
+ upb_handlertype_t type) {
+ const void *ret;
+ upb_selector_t sel;
+
+ UPB_ASSERT(type != UPB_HANDLER_STRING);
+ ret = h->top_closure_type;
+
+ if (upb_fielddef_isseq(f) &&
+ type != UPB_HANDLER_STARTSEQ &&
+ type != UPB_HANDLER_ENDSEQ &&
+ h->table[sel = handlers_getsel(h, f, UPB_HANDLER_STARTSEQ)].func) {
+ ret = upb_handlerattr_returnclosuretype(&h->table[sel].attr);
+ }
+
+ if (type == UPB_HANDLER_STRING &&
+ h->table[sel = handlers_getsel(h, f, UPB_HANDLER_STARTSTR)].func) {
+ ret = upb_handlerattr_returnclosuretype(&h->table[sel].attr);
+ }
+
+ /* The effective type of the submessage; not used yet.
+ * if (type == SUBMESSAGE &&
+ * h->table[sel = handlers_getsel(h, f, UPB_HANDLER_STARTSUBMSG)].func) {
+ * ret = upb_handlerattr_returnclosuretype(&h->table[sel].attr);
+ * } */
+
+ return ret;
+}
+
+/* Checks whether the START* handler specified by f & type is missing even
+ * though it is required to convert the established type of an outer frame
+ * ("closure_type") into the established type of an inner frame (represented in
+ * the return closure type of this handler's attr. */
+bool checkstart(upb_handlers *h, const upb_fielddef *f, upb_handlertype_t type,
+ upb_status *status) {
+ const void *closure_type;
+ const upb_handlerattr *attr;
+ const void *return_closure_type;
+
+ upb_selector_t sel = handlers_getsel(h, f, type);
+ if (h->table[sel].func) return true;
+ closure_type = effective_closure_type(h, f, type);
+ attr = &h->table[sel].attr;
+ return_closure_type = upb_handlerattr_returnclosuretype(attr);
+ if (closure_type && return_closure_type &&
+ closure_type != return_closure_type) {
+ upb_status_seterrf(status,
+ "expected start handler to return sub type for field %f",
+ upb_fielddef_name(f));
+ return false;
+ }
+ return true;
+}
+
+/* Public interface ***********************************************************/
+
+upb_handlers *upb_handlers_new(const upb_msgdef *md, const void *owner) {
+ int extra;
+ upb_handlers *h;
+
+ UPB_ASSERT(upb_msgdef_isfrozen(md));
+
+ extra = sizeof(upb_handlers_tabent) * (md->selector_count - 1);
+ h = upb_calloc(sizeof(*h) + extra);
+ if (!h) return NULL;
+
+ h->msg = md;
+ upb_msgdef_ref(h->msg, h);
+ upb_status_clear(&h->status_);
+
+ if (md->submsg_field_count > 0) {
+ h->sub = upb_calloc(md->submsg_field_count * sizeof(*h->sub));
+ if (!h->sub) goto oom;
+ } else {
+ h->sub = 0;
+ }
+
+ if (!upb_refcounted_init(upb_handlers_upcast_mutable(h), &vtbl, owner))
+ goto oom;
+ if (!upb_inttable_init(&h->cleanup_, UPB_CTYPE_FPTR)) goto oom;
+
+ /* calloc() above initialized all handlers to NULL. */
+ return h;
+
+oom:
+ freehandlers(upb_handlers_upcast_mutable(h));
+ return NULL;
+}
+
+const upb_handlers *upb_handlers_newfrozen(const upb_msgdef *m,
+ const void *owner,
+ upb_handlers_callback *callback,
+ const void *closure) {
+ dfs_state state;
+ upb_handlers *ret;
+ bool ok;
+ upb_refcounted *r;
+
+ state.callback = callback;
+ state.closure = closure;
+ if (!upb_inttable_init(&state.tab, UPB_CTYPE_PTR)) return NULL;
+
+ ret = newformsg(m, owner, &state);
+
+ upb_inttable_uninit(&state.tab);
+ if (!ret) return NULL;
+
+ r = upb_handlers_upcast_mutable(ret);
+ ok = upb_refcounted_freeze(&r, 1, NULL, UPB_MAX_HANDLER_DEPTH);
+ UPB_ASSERT(ok);
+
+ return ret;
+}
+
+const upb_status *upb_handlers_status(upb_handlers *h) {
+ UPB_ASSERT(!upb_handlers_isfrozen(h));
+ return &h->status_;
+}
+
+void upb_handlers_clearerr(upb_handlers *h) {
+ UPB_ASSERT(!upb_handlers_isfrozen(h));
+ upb_status_clear(&h->status_);
+}
+
+#define SETTER(name, handlerctype, handlertype) \
+ bool upb_handlers_set ## name(upb_handlers *h, const upb_fielddef *f, \
+ handlerctype func, upb_handlerattr *attr) { \
+ int32_t sel = trygetsel(h, f, handlertype); \
+ return doset(h, sel, f, handlertype, (upb_func*)func, attr); \
+ }
+
+SETTER(int32, upb_int32_handlerfunc*, UPB_HANDLER_INT32)
+SETTER(int64, upb_int64_handlerfunc*, UPB_HANDLER_INT64)
+SETTER(uint32, upb_uint32_handlerfunc*, UPB_HANDLER_UINT32)
+SETTER(uint64, upb_uint64_handlerfunc*, UPB_HANDLER_UINT64)
+SETTER(float, upb_float_handlerfunc*, UPB_HANDLER_FLOAT)
+SETTER(double, upb_double_handlerfunc*, UPB_HANDLER_DOUBLE)
+SETTER(bool, upb_bool_handlerfunc*, UPB_HANDLER_BOOL)
+SETTER(startstr, upb_startstr_handlerfunc*, UPB_HANDLER_STARTSTR)
+SETTER(string, upb_string_handlerfunc*, UPB_HANDLER_STRING)
+SETTER(endstr, upb_endfield_handlerfunc*, UPB_HANDLER_ENDSTR)
+SETTER(startseq, upb_startfield_handlerfunc*, UPB_HANDLER_STARTSEQ)
+SETTER(startsubmsg, upb_startfield_handlerfunc*, UPB_HANDLER_STARTSUBMSG)
+SETTER(endsubmsg, upb_endfield_handlerfunc*, UPB_HANDLER_ENDSUBMSG)
+SETTER(endseq, upb_endfield_handlerfunc*, UPB_HANDLER_ENDSEQ)
+
+#undef SETTER
+
+bool upb_handlers_setstartmsg(upb_handlers *h, upb_startmsg_handlerfunc *func,
+ upb_handlerattr *attr) {
+ return doset(h, UPB_STARTMSG_SELECTOR, NULL, UPB_HANDLER_INT32,
+ (upb_func *)func, attr);
+}
+
+bool upb_handlers_setendmsg(upb_handlers *h, upb_endmsg_handlerfunc *func,
+ upb_handlerattr *attr) {
+ UPB_ASSERT(!upb_handlers_isfrozen(h));
+ return doset(h, UPB_ENDMSG_SELECTOR, NULL, UPB_HANDLER_INT32,
+ (upb_func *)func, attr);
+}
+
+bool upb_handlers_setsubhandlers(upb_handlers *h, const upb_fielddef *f,
+ const upb_handlers *sub) {
+ UPB_ASSERT(sub);
+ UPB_ASSERT(!upb_handlers_isfrozen(h));
+ UPB_ASSERT(upb_fielddef_issubmsg(f));
+ if (SUBH_F(h, f)) return false; /* Can't reset. */
+ if (upb_msgdef_upcast(upb_handlers_msgdef(sub)) != upb_fielddef_subdef(f)) {
+ return false;
+ }
+ SUBH_F(h, f) = sub;
+ upb_ref2(sub, h);
+ return true;
+}
+
+const upb_handlers *upb_handlers_getsubhandlers(const upb_handlers *h,
+ const upb_fielddef *f) {
+ UPB_ASSERT(upb_fielddef_issubmsg(f));
+ return SUBH_F(h, f);
+}
+
+bool upb_handlers_getattr(const upb_handlers *h, upb_selector_t sel,
+ upb_handlerattr *attr) {
+ if (!upb_handlers_gethandler(h, sel))
+ return false;
+ *attr = h->table[sel].attr;
+ return true;
+}
+
+const upb_handlers *upb_handlers_getsubhandlers_sel(const upb_handlers *h,
+ upb_selector_t sel) {
+ /* STARTSUBMSG selector in sel is the field's selector base. */
+ return SUBH(h, sel - UPB_STATIC_SELECTOR_COUNT);
+}
+
+const upb_msgdef *upb_handlers_msgdef(const upb_handlers *h) { return h->msg; }
+
+bool upb_handlers_addcleanup(upb_handlers *h, void *p, upb_handlerfree *func) {
+ bool ok;
+ if (upb_inttable_lookupptr(&h->cleanup_, p, NULL)) {
+ return false;
+ }
+ ok = upb_inttable_insertptr(&h->cleanup_, p, upb_value_fptr(func));
+ UPB_ASSERT(ok);
+ return true;
+}
+
+
+/* "Static" methods ***********************************************************/
+
+bool upb_handlers_freeze(upb_handlers *const*handlers, int n, upb_status *s) {
+ /* TODO: verify we have a transitive closure. */
+ int i;
+ for (i = 0; i < n; i++) {
+ upb_msg_field_iter j;
+ upb_handlers *h = handlers[i];
+
+ if (!upb_ok(&h->status_)) {
+ upb_status_seterrf(s, "handlers for message %s had error status: %s",
+ upb_msgdef_fullname(upb_handlers_msgdef(h)),
+ upb_status_errmsg(&h->status_));
+ return false;
+ }
+
+ /* Check that there are no closure mismatches due to missing Start* handlers
+ * or subhandlers with different type-level types. */
+ for(upb_msg_field_begin(&j, h->msg);
+ !upb_msg_field_done(&j);
+ upb_msg_field_next(&j)) {
+
+ const upb_fielddef *f = upb_msg_iter_field(&j);
+ if (upb_fielddef_isseq(f)) {
+ if (!checkstart(h, f, UPB_HANDLER_STARTSEQ, s))
+ return false;
+ }
+
+ if (upb_fielddef_isstring(f)) {
+ if (!checkstart(h, f, UPB_HANDLER_STARTSTR, s))
+ return false;
+ }
+
+ if (upb_fielddef_issubmsg(f)) {
+ bool hashandler = false;
+ if (upb_handlers_gethandler(
+ h, handlers_getsel(h, f, UPB_HANDLER_STARTSUBMSG)) ||
+ upb_handlers_gethandler(
+ h, handlers_getsel(h, f, UPB_HANDLER_ENDSUBMSG))) {
+ hashandler = true;
+ }
+
+ if (upb_fielddef_isseq(f) &&
+ (upb_handlers_gethandler(
+ h, handlers_getsel(h, f, UPB_HANDLER_STARTSEQ)) ||
+ upb_handlers_gethandler(
+ h, handlers_getsel(h, f, UPB_HANDLER_ENDSEQ)))) {
+ hashandler = true;
+ }
+
+ if (hashandler && !upb_handlers_getsubhandlers(h, f)) {
+ /* For now we add an empty subhandlers in this case. It makes the
+ * decoder code generator simpler, because it only has to handle two
+ * cases (submessage has handlers or not) as opposed to three
+ * (submessage has handlers in enclosing message but no subhandlers).
+ *
+ * This makes parsing less efficient in the case that we want to
+ * notice a submessage but skip its contents (like if we're testing
+ * for submessage presence or counting the number of repeated
+ * submessages). In this case we will end up parsing the submessage
+ * field by field and throwing away the results for each, instead of
+ * skipping the whole delimited thing at once. If this is an issue we
+ * can revisit it, but do remember that this only arises when you have
+ * handlers (startseq/startsubmsg/endsubmsg/endseq) set for the
+ * submessage but no subhandlers. The uses cases for this are
+ * limited. */
+ upb_handlers *sub = upb_handlers_new(upb_fielddef_msgsubdef(f), &sub);
+ upb_handlers_setsubhandlers(h, f, sub);
+ upb_handlers_unref(sub, &sub);
+ }
+
+ /* TODO(haberman): check type of submessage.
+ * This is slightly tricky; also consider whether we should check that
+ * they match at setsubhandlers time. */
+ }
+ }
+ }
+
+ if (!upb_refcounted_freeze((upb_refcounted*const*)handlers, n, s,
+ UPB_MAX_HANDLER_DEPTH)) {
+ return false;
+ }
+
+ return true;
+}
+
+upb_handlertype_t upb_handlers_getprimitivehandlertype(const upb_fielddef *f) {
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_ENUM: return UPB_HANDLER_INT32;
+ case UPB_TYPE_INT64: return UPB_HANDLER_INT64;
+ case UPB_TYPE_UINT32: return UPB_HANDLER_UINT32;
+ case UPB_TYPE_UINT64: return UPB_HANDLER_UINT64;
+ case UPB_TYPE_FLOAT: return UPB_HANDLER_FLOAT;
+ case UPB_TYPE_DOUBLE: return UPB_HANDLER_DOUBLE;
+ case UPB_TYPE_BOOL: return UPB_HANDLER_BOOL;
+ default: UPB_ASSERT(false); return -1; /* Invalid input. */
+ }
+}
+
+bool upb_handlers_getselector(const upb_fielddef *f, upb_handlertype_t type,
+ upb_selector_t *s) {
+ switch (type) {
+ case UPB_HANDLER_INT32:
+ case UPB_HANDLER_INT64:
+ case UPB_HANDLER_UINT32:
+ case UPB_HANDLER_UINT64:
+ case UPB_HANDLER_FLOAT:
+ case UPB_HANDLER_DOUBLE:
+ case UPB_HANDLER_BOOL:
+ if (!upb_fielddef_isprimitive(f) ||
+ upb_handlers_getprimitivehandlertype(f) != type)
+ return false;
+ *s = f->selector_base;
+ break;
+ case UPB_HANDLER_STRING:
+ if (upb_fielddef_isstring(f)) {
+ *s = f->selector_base;
+ } else if (upb_fielddef_lazy(f)) {
+ *s = f->selector_base + 3;
+ } else {
+ return false;
+ }
+ break;
+ case UPB_HANDLER_STARTSTR:
+ if (upb_fielddef_isstring(f) || upb_fielddef_lazy(f)) {
+ *s = f->selector_base + 1;
+ } else {
+ return false;
+ }
+ break;
+ case UPB_HANDLER_ENDSTR:
+ if (upb_fielddef_isstring(f) || upb_fielddef_lazy(f)) {
+ *s = f->selector_base + 2;
+ } else {
+ return false;
+ }
+ break;
+ case UPB_HANDLER_STARTSEQ:
+ if (!upb_fielddef_isseq(f)) return false;
+ *s = f->selector_base - 2;
+ break;
+ case UPB_HANDLER_ENDSEQ:
+ if (!upb_fielddef_isseq(f)) return false;
+ *s = f->selector_base - 1;
+ break;
+ case UPB_HANDLER_STARTSUBMSG:
+ if (!upb_fielddef_issubmsg(f)) return false;
+ /* Selectors for STARTSUBMSG are at the beginning of the table so that the
+ * selector can also be used as an index into the "sub" array of
+ * subhandlers. The indexes for the two into these two tables are the
+ * same, except that in the handler table the static selectors come first. */
+ *s = f->index_ + UPB_STATIC_SELECTOR_COUNT;
+ break;
+ case UPB_HANDLER_ENDSUBMSG:
+ if (!upb_fielddef_issubmsg(f)) return false;
+ *s = f->selector_base;
+ break;
+ }
+ UPB_ASSERT((size_t)*s < upb_fielddef_containingtype(f)->selector_count);
+ return true;
+}
+
+uint32_t upb_handlers_selectorbaseoffset(const upb_fielddef *f) {
+ return upb_fielddef_isseq(f) ? 2 : 0;
+}
+
+uint32_t upb_handlers_selectorcount(const upb_fielddef *f) {
+ uint32_t ret = 1;
+ if (upb_fielddef_isseq(f)) ret += 2; /* STARTSEQ/ENDSEQ */
+ if (upb_fielddef_isstring(f)) ret += 2; /* [STRING]/STARTSTR/ENDSTR */
+ if (upb_fielddef_issubmsg(f)) {
+ /* ENDSUBMSG (STARTSUBMSG is at table beginning) */
+ ret += 0;
+ if (upb_fielddef_lazy(f)) {
+ /* STARTSTR/ENDSTR/STRING (for lazy) */
+ ret += 3;
+ }
+ }
+ return ret;
+}
+
+
+/* upb_handlerattr ************************************************************/
+
+void upb_handlerattr_init(upb_handlerattr *attr) {
+ upb_handlerattr from = UPB_HANDLERATTR_INITIALIZER;
+ memcpy(attr, &from, sizeof(*attr));
+}
+
+void upb_handlerattr_uninit(upb_handlerattr *attr) {
+ UPB_UNUSED(attr);
+}
+
+bool upb_handlerattr_sethandlerdata(upb_handlerattr *attr, const void *hd) {
+ attr->handler_data_ = hd;
+ return true;
+}
+
+bool upb_handlerattr_setclosuretype(upb_handlerattr *attr, const void *type) {
+ attr->closure_type_ = type;
+ return true;
+}
+
+const void *upb_handlerattr_closuretype(const upb_handlerattr *attr) {
+ return attr->closure_type_;
+}
+
+bool upb_handlerattr_setreturnclosuretype(upb_handlerattr *attr,
+ const void *type) {
+ attr->return_closure_type_ = type;
+ return true;
+}
+
+const void *upb_handlerattr_returnclosuretype(const upb_handlerattr *attr) {
+ return attr->return_closure_type_;
+}
+
+bool upb_handlerattr_setalwaysok(upb_handlerattr *attr, bool alwaysok) {
+ attr->alwaysok_ = alwaysok;
+ return true;
+}
+
+bool upb_handlerattr_alwaysok(const upb_handlerattr *attr) {
+ return attr->alwaysok_;
+}
+
+/* upb_bufhandle **************************************************************/
+
+size_t upb_bufhandle_objofs(const upb_bufhandle *h) {
+ return h->objofs_;
+}
+
+/* upb_byteshandler ***********************************************************/
+
+void upb_byteshandler_init(upb_byteshandler* h) {
+ memset(h, 0, sizeof(*h));
+}
+
+/* For when we support handlerfree callbacks. */
+void upb_byteshandler_uninit(upb_byteshandler* h) {
+ UPB_UNUSED(h);
+}
+
+bool upb_byteshandler_setstartstr(upb_byteshandler *h,
+ upb_startstr_handlerfunc *func, void *d) {
+ h->table[UPB_STARTSTR_SELECTOR].func = (upb_func*)func;
+ h->table[UPB_STARTSTR_SELECTOR].attr.handler_data_ = d;
+ return true;
+}
+
+bool upb_byteshandler_setstring(upb_byteshandler *h,
+ upb_string_handlerfunc *func, void *d) {
+ h->table[UPB_STRING_SELECTOR].func = (upb_func*)func;
+ h->table[UPB_STRING_SELECTOR].attr.handler_data_ = d;
+ return true;
+}
+
+bool upb_byteshandler_setendstr(upb_byteshandler *h,
+ upb_endfield_handlerfunc *func, void *d) {
+ h->table[UPB_ENDSTR_SELECTOR].func = (upb_func*)func;
+ h->table[UPB_ENDSTR_SELECTOR].attr.handler_data_ = d;
+ return true;
+}
+
+
+static bool is_power_of_two(size_t val) {
+ return (val & (val - 1)) == 0;
+}
+
+/* Align up to the given power of 2. */
+static size_t align_up(size_t val, size_t align) {
+ UPB_ASSERT(is_power_of_two(align));
+ return (val + align - 1) & ~(align - 1);
+}
+
+static size_t div_round_up(size_t n, size_t d) {
+ return (n + d - 1) / d;
+}
+
+bool upb_fieldtype_mapkeyok(upb_fieldtype_t type) {
+ return type == UPB_TYPE_BOOL || type == UPB_TYPE_INT32 ||
+ type == UPB_TYPE_UINT32 || type == UPB_TYPE_INT64 ||
+ type == UPB_TYPE_UINT64 || type == UPB_TYPE_STRING;
+}
+
+void *upb_array_pack(const upb_array *arr, void *p, size_t *ofs, size_t size);
+void *upb_map_pack(const upb_map *map, void *p, size_t *ofs, size_t size);
+
+#define CHARPTR_AT(msg, ofs) ((char*)msg + ofs)
+#define ENCODE_MAX_NESTING 64
+#define CHECK_TRUE(x) if (!(x)) { return false; }
+
+/** upb_msgval ****************************************************************/
+
+#define upb_alignof(t) offsetof(struct { char c; t x; }, x)
+
+/* These functions will generate real memcpy() calls on ARM sadly, because
+ * the compiler assumes they might not be aligned. */
+
+static upb_msgval upb_msgval_read(const void *p, size_t ofs,
+ uint8_t size) {
+ upb_msgval val;
+ p = (char*)p + ofs;
+ memcpy(&val, p, size);
+ return val;
+}
+
+static void upb_msgval_write(void *p, size_t ofs, upb_msgval val,
+ uint8_t size) {
+ p = (char*)p + ofs;
+ memcpy(p, &val, size);
+}
+
+static size_t upb_msgval_sizeof(upb_fieldtype_t type) {
+ switch (type) {
+ case UPB_TYPE_DOUBLE:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT64:
+ return 8;
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_FLOAT:
+ return 4;
+ case UPB_TYPE_BOOL:
+ return 1;
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_MESSAGE:
+ return sizeof(void*);
+ case UPB_TYPE_STRING:
+ return sizeof(char*) + sizeof(size_t);
+ }
+ UPB_UNREACHABLE();
+}
+
+static uint8_t upb_msg_fieldsize(const upb_fielddef *f) {
+ if (upb_fielddef_isseq(f)) {
+ return sizeof(void*);
+ } else {
+ return upb_msgval_sizeof(upb_fielddef_type(f));
+ }
+}
+
+/* TODO(haberman): this is broken right now because upb_msgval can contain
+ * a char* / size_t pair, which is too big for a upb_value. To fix this
+ * we'll probably need to dynamically allocate a upb_msgval and store a
+ * pointer to that in the tables for extensions/maps. */
+static upb_value upb_toval(upb_msgval val) {
+ upb_value ret;
+ UPB_UNUSED(val);
+ memset(&ret, 0, sizeof(upb_value)); /* XXX */
+ return ret;
+}
+
+static upb_msgval upb_msgval_fromval(upb_value val) {
+ upb_msgval ret;
+ UPB_UNUSED(val);
+ memset(&ret, 0, sizeof(upb_msgval)); /* XXX */
+ return ret;
+}
+
+static upb_ctype_t upb_fieldtotabtype(upb_fieldtype_t type) {
+ switch (type) {
+ case UPB_TYPE_FLOAT: return UPB_CTYPE_FLOAT;
+ case UPB_TYPE_DOUBLE: return UPB_CTYPE_DOUBLE;
+ case UPB_TYPE_BOOL: return UPB_CTYPE_BOOL;
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_MESSAGE:
+ case UPB_TYPE_STRING: return UPB_CTYPE_CONSTPTR;
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32: return UPB_CTYPE_INT32;
+ case UPB_TYPE_UINT32: return UPB_CTYPE_UINT32;
+ case UPB_TYPE_INT64: return UPB_CTYPE_INT64;
+ case UPB_TYPE_UINT64: return UPB_CTYPE_UINT64;
+ default: UPB_ASSERT(false); return 0;
+ }
+}
+
+static upb_msgval upb_msgval_fromdefault(const upb_fielddef *f) {
+ /* TODO(haberman): improve/optimize this (maybe use upb_msgval in fielddef) */
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_FLOAT:
+ return upb_msgval_float(upb_fielddef_defaultfloat(f));
+ case UPB_TYPE_DOUBLE:
+ return upb_msgval_double(upb_fielddef_defaultdouble(f));
+ case UPB_TYPE_BOOL:
+ return upb_msgval_bool(upb_fielddef_defaultbool(f));
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ size_t len;
+ const char *ptr = upb_fielddef_defaultstr(f, &len);
+ return upb_msgval_str(ptr, len);
+ }
+ case UPB_TYPE_MESSAGE:
+ return upb_msgval_msg(NULL);
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32:
+ return upb_msgval_int32(upb_fielddef_defaultint32(f));
+ case UPB_TYPE_UINT32:
+ return upb_msgval_uint32(upb_fielddef_defaultuint32(f));
+ case UPB_TYPE_INT64:
+ return upb_msgval_int64(upb_fielddef_defaultint64(f));
+ case UPB_TYPE_UINT64:
+ return upb_msgval_uint64(upb_fielddef_defaultuint64(f));
+ default:
+ UPB_ASSERT(false);
+ return upb_msgval_msg(NULL);
+ }
+}
+
+
+/** upb_msglayout *************************************************************/
+
+struct upb_msglayout {
+ upb_msgfactory *factory;
+ const upb_msgdef *msgdef;
+ size_t size;
+ size_t extdict_offset;
+ void *default_msg;
+ uint32_t *field_offsets;
+ uint32_t *case_offsets;
+ uint32_t *hasbits;
+ bool has_extdict;
+ uint8_t align;
+};
+
+static void upb_msg_checkfield(const upb_msglayout *l, const upb_fielddef *f) {
+ UPB_ASSERT(l->msgdef == upb_fielddef_containingtype(f));
+}
+
+static void upb_msglayout_free(upb_msglayout *l) {
+ upb_gfree(l->default_msg);
+ upb_gfree(l);
+}
+
+const upb_msgdef *upb_msglayout_msgdef(const upb_msglayout *l) {
+ return l->msgdef;
+}
+
+static size_t upb_msglayout_place(upb_msglayout *l, size_t size) {
+ size_t ret;
+
+ l->size = align_up(l->size, size);
+ l->align = align_up(l->align, size);
+ ret = l->size;
+ l->size += size;
+ return ret;
+}
+
+static uint32_t upb_msglayout_offset(const upb_msglayout *l,
+ const upb_fielddef *f) {
+ return l->field_offsets[upb_fielddef_index(f)];
+}
+
+static uint32_t upb_msglayout_hasbit(const upb_msglayout *l,
+ const upb_fielddef *f) {
+ return l->hasbits[upb_fielddef_index(f)];
+}
+
+static bool upb_msglayout_initdefault(upb_msglayout *l) {
+ const upb_msgdef *m = l->msgdef;
+ upb_msg_field_iter it;
+
+ if (upb_msgdef_syntax(m) == UPB_SYNTAX_PROTO2 && l->size) {
+ /* Allocate default message and set default values in it. */
+ l->default_msg = upb_gmalloc(l->size);
+ if (!l->default_msg) {
+ return false;
+ }
+
+ memset(l->default_msg, 0, l->size);
+
+ for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* f = upb_msg_iter_field(&it);
+
+ if (upb_fielddef_containingoneof(f)) {
+ continue;
+ }
+
+ if (!upb_fielddef_isstring(f) &&
+ !upb_fielddef_issubmsg(f) &&
+ !upb_fielddef_isseq(f)) {
+ upb_msg_set(l->default_msg, f, upb_msgval_fromdefault(f), l);
+ }
+ }
+ }
+
+ return true;
+}
+
+static upb_msglayout *upb_msglayout_new(const upb_msgdef *m) {
+ upb_msg_field_iter it;
+ upb_msg_oneof_iter oit;
+ upb_msglayout *l;
+ size_t hasbit;
+ size_t array_size = upb_msgdef_numfields(m) + upb_msgdef_numoneofs(m);
+
+ if (upb_msgdef_syntax(m) == UPB_SYNTAX_PROTO2) {
+ array_size += upb_msgdef_numfields(m); /* hasbits. */
+ }
+
+ l = upb_gmalloc(sizeof(*l) + (sizeof(uint32_t) * array_size));
+ if (!l) return NULL;
+
+ memset(l, 0, sizeof(*l));
+
+ l->msgdef = m;
+ l->align = 1;
+ l->field_offsets = (uint32_t*)CHARPTR_AT(l, sizeof(*l));
+ l->case_offsets = l->field_offsets + upb_msgdef_numfields(m);
+ l->hasbits = l->case_offsets + upb_msgdef_numoneofs(m);
+
+ /* Allocate data offsets in three stages:
+ *
+ * 1. hasbits.
+ * 2. regular fields.
+ * 3. oneof fields.
+ *
+ * OPT: There is a lot of room for optimization here to minimize the size.
+ */
+
+ /* Allocate hasbits. Start at sizeof(void*) for upb_alloc*. */
+ for (upb_msg_field_begin(&it, m), hasbit = sizeof(void*) * 8;
+ !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* f = upb_msg_iter_field(&it);
+
+ if (upb_fielddef_haspresence(f) && !upb_fielddef_containingoneof(f)) {
+ l->hasbits[upb_fielddef_index(f)] = hasbit++;
+ }
+ }
+
+ /* Account for space used by hasbits. */
+ l->size = div_round_up(hasbit, 8);
+
+ /* Allocate non-oneof fields. */
+ for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* f = upb_msg_iter_field(&it);
+ size_t field_size = upb_msg_fieldsize(f);
+ size_t index = upb_fielddef_index(f);
+
+
+ if (upb_fielddef_containingoneof(f)) {
+ /* Oneofs are handled separately below. */
+ continue;
+ }
+
+ l->field_offsets[index] = upb_msglayout_place(l, field_size);
+ }
+
+ /* Allocate oneof fields. Each oneof field consists of a uint32 for the case
+ * and space for the actual data. */
+ for (upb_msg_oneof_begin(&oit, m); !upb_msg_oneof_done(&oit);
+ upb_msg_oneof_next(&oit)) {
+ const upb_oneofdef* oneof = upb_msg_iter_oneof(&oit);
+ upb_oneof_iter fit;
+ size_t case_size = sizeof(uint32_t); /* Could potentially optimize this. */
+ size_t field_size = 0;
+ size_t case_offset;
+ size_t val_offset;
+
+ /* Calculate field size: the max of all field sizes. */
+ for (upb_oneof_begin(&fit, oneof);
+ !upb_oneof_done(&fit);
+ upb_oneof_next(&fit)) {
+ const upb_fielddef* f = upb_oneof_iter_field(&fit);
+ field_size = UPB_MAX(field_size, upb_msg_fieldsize(f));
+ }
+
+ /* Align and allocate case offset. */
+ case_offset = upb_msglayout_place(l, case_size);
+ val_offset = upb_msglayout_place(l, field_size);
+
+ l->case_offsets[upb_oneofdef_index(oneof)] = case_offset;
+
+ /* Assign all fields in the oneof this same offset. */
+ for (upb_oneof_begin(&fit, oneof); !upb_oneof_done(&fit);
+ upb_oneof_next(&fit)) {
+ const upb_fielddef* f = upb_oneof_iter_field(&fit);
+ l->field_offsets[upb_fielddef_index(f)] = val_offset;
+ }
+ }
+
+ /* Size of the entire structure should be a multiple of its greatest
+ * alignment. */
+ l->size = align_up(l->size, l->align);
+
+ if (upb_msglayout_initdefault(l)) {
+ return l;
+ } else {
+ upb_msglayout_free(l);
+ return NULL;
+ }
+}
+
+upb_msgfactory *upb_msglayout_factory(const upb_msglayout *layout) {
+ return layout->factory;
+}
+
+
+/** upb_msgfactory ************************************************************/
+
+struct upb_msgfactory {
+ const upb_symtab *symtab; /* We own a ref. */
+ upb_inttable layouts;
+ upb_inttable mergehandlers;
+};
+
+upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab) {
+ upb_msgfactory *ret = upb_gmalloc(sizeof(*ret));
+
+ ret->symtab = symtab;
+ upb_inttable_init(&ret->layouts, UPB_CTYPE_PTR);
+ upb_inttable_init(&ret->mergehandlers, UPB_CTYPE_CONSTPTR);
+
+ return ret;
+}
+
+void upb_msgfactory_free(upb_msgfactory *f) {
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, &f->layouts);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ upb_msglayout *l = upb_value_getptr(upb_inttable_iter_value(&i));
+ upb_msglayout_free(l);
+ }
+
+ upb_inttable_begin(&i, &f->mergehandlers);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ const upb_handlers *h = upb_value_getconstptr(upb_inttable_iter_value(&i));
+ upb_handlers_unref(h, f);
+ }
+
+ upb_inttable_uninit(&f->layouts);
+ upb_inttable_uninit(&f->mergehandlers);
+ upb_gfree(f);
+}
+
+const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f) {
+ return f->symtab;
+}
+
+const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f,
+ const upb_msgdef *m) {
+ upb_value v;
+ UPB_ASSERT(upb_symtab_lookupmsg(f->symtab, upb_msgdef_fullname(m)) == m);
+ UPB_ASSERT(!upb_msgdef_mapentry(m));
+
+ if (upb_inttable_lookupptr(&f->layouts, m, &v)) {
+ UPB_ASSERT(upb_value_getptr(v));
+ return upb_value_getptr(v);
+ } else {
+ upb_msgfactory *mutable_f = (void*)f;
+ upb_msglayout *l = upb_msglayout_new(m);
+ upb_inttable_insertptr(&mutable_f->layouts, m, upb_value_ptr(l));
+ UPB_ASSERT(l);
+ l->factory = f;
+ return l;
+ }
+}
+
+/* Our handlers that we don't expose externally. */
+
+void *upb_msg_startstr(void *msg, const void *hd, size_t size_hint) {
+ uint32_t ofs = (uintptr_t)hd;
+ /* We pass NULL here because we know we can get away with it. */
+ upb_alloc *alloc = upb_msg_alloc(msg, NULL);
+ upb_msgval val;
+ UPB_UNUSED(size_hint);
+
+ val = upb_msgval_read(msg, ofs, upb_msgval_sizeof(UPB_TYPE_STRING));
+
+ upb_free(alloc, (void*)val.str.ptr);
+ val.str.ptr = NULL;
+ val.str.len = 0;
+
+ upb_msgval_write(msg, ofs, val, upb_msgval_sizeof(UPB_TYPE_STRING));
+ return msg;
+}
+
+size_t upb_msg_str(void *msg, const void *hd, const char *ptr, size_t size,
+ const upb_bufhandle *handle) {
+ uint32_t ofs = (uintptr_t)hd;
+ /* We pass NULL here because we know we can get away with it. */
+ upb_alloc *alloc = upb_msg_alloc(msg, NULL);
+ upb_msgval val;
+ size_t newsize;
+ UPB_UNUSED(handle);
+
+ val = upb_msgval_read(msg, ofs, upb_msgval_sizeof(UPB_TYPE_STRING));
+
+ newsize = val.str.len + size;
+ val.str.ptr = upb_realloc(alloc, (void*)val.str.ptr, val.str.len, newsize);
+
+ if (!val.str.ptr) {
+ return false;
+ }
+
+ memcpy((char*)val.str.ptr + val.str.len, ptr, size);
+ val.str.len = newsize;
+ upb_msgval_write(msg, ofs, val, upb_msgval_sizeof(UPB_TYPE_STRING));
+ return size;
+}
+
+static void callback(const void *closure, upb_handlers *h) {
+ upb_msgfactory *factory = (upb_msgfactory*)closure;
+ const upb_msgdef *md = upb_handlers_msgdef(h);
+ const upb_msglayout* layout = upb_msgfactory_getlayout(factory, md);
+ upb_msg_field_iter i;
+ UPB_UNUSED(factory);
+
+ for(upb_msg_field_begin(&i, md);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ const upb_fielddef *f = upb_msg_iter_field(&i);
+ size_t offset = upb_msglayout_offset(layout, f);
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_handlerattr_sethandlerdata(&attr, (void*)offset);
+
+ if (upb_fielddef_isseq(f)) {
+ } else if (upb_fielddef_isstring(f)) {
+ upb_handlers_setstartstr(h, f, upb_msg_startstr, &attr);
+ upb_handlers_setstring(h, f, upb_msg_str, &attr);
+ } else {
+ upb_msg_setscalarhandler(
+ h, f, offset, upb_msglayout_hasbit(layout, f));
+ }
+ }
+}
+
+const upb_handlers *upb_msgfactory_getmergehandlers(upb_msgfactory *f,
+ const upb_msgdef *m) {
+ upb_msgfactory *mutable_f = (void*)f;
+
+ /* TODO(haberman): properly cache these. */
+ const upb_handlers *ret = upb_handlers_newfrozen(m, f, callback, f);
+ upb_inttable_push(&mutable_f->mergehandlers, upb_value_constptr(ret));
+
+ return ret;
+}
+
+const upb_visitorplan *upb_msgfactory_getvisitorplan(upb_msgfactory *f,
+ const upb_handlers *h) {
+ const upb_msgdef *md = upb_handlers_msgdef(h);
+ return (const upb_visitorplan*)upb_msgfactory_getlayout(f, md);
+}
+
+
+/** upb_visitor ***************************************************************/
+
+struct upb_visitor {
+ const upb_msglayout *layout;
+ upb_sink *sink;
+};
+
+static upb_selector_t getsel2(const upb_fielddef *f, upb_handlertype_t type) {
+ upb_selector_t ret;
+ bool ok = upb_handlers_getselector(f, type, &ret);
+ UPB_ASSERT(ok);
+ return ret;
+}
+
+static bool upb_visitor_hasfield(const upb_msg *msg, const upb_fielddef *f,
+ const upb_msglayout *layout) {
+ if (upb_fielddef_isseq(f)) {
+ return upb_msgval_getarr(upb_msg_get(msg, f, layout)) != NULL;
+ } else if (upb_msgdef_syntax(upb_fielddef_containingtype(f)) ==
+ UPB_SYNTAX_PROTO2) {
+ return upb_msg_has(msg, f, layout);
+ } else {
+ upb_msgval val = upb_msg_get(msg, f, layout);
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_FLOAT:
+ return upb_msgval_getfloat(val) != 0;
+ case UPB_TYPE_DOUBLE:
+ return upb_msgval_getdouble(val) != 0;
+ case UPB_TYPE_BOOL:
+ return upb_msgval_getbool(val);
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32:
+ return upb_msgval_getint32(val) != 0;
+ case UPB_TYPE_UINT32:
+ return upb_msgval_getuint32(val) != 0;
+ case UPB_TYPE_INT64:
+ return upb_msgval_getint64(val) != 0;
+ case UPB_TYPE_UINT64:
+ return upb_msgval_getuint64(val) != 0;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ return upb_msgval_getstr(val) && upb_msgval_getstrlen(val) > 0;
+ case UPB_TYPE_MESSAGE:
+ return upb_msgval_getmsg(val) != NULL;
+ }
+ UPB_UNREACHABLE();
+ }
+}
+
+static bool upb_visitor_visitmsg2(const upb_msg *msg,
+ const upb_msglayout *layout, upb_sink *sink,
+ int depth) {
+ const upb_msgdef *md = upb_msglayout_msgdef(layout);
+ upb_msg_field_iter i;
+ upb_status status;
+
+ upb_sink_startmsg(sink);
+
+ /* Protect against cycles (possible because users may freely reassign message
+ * and repeated fields) by imposing a maximum recursion depth. */
+ if (depth > ENCODE_MAX_NESTING) {
+ return false;
+ }
+
+ for (upb_msg_field_begin(&i, md);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ upb_fielddef *f = upb_msg_iter_field(&i);
+ upb_msgval val;
+
+ if (!upb_visitor_hasfield(msg, f, layout)) {
+ continue;
+ }
+
+ val = upb_msg_get(msg, f, layout);
+
+ if (upb_fielddef_isseq(f)) {
+ const upb_array *arr = upb_msgval_getarr(val);
+ UPB_ASSERT(arr);
+ /* TODO: putary(ary, f, sink, depth);*/
+ } else if (upb_fielddef_issubmsg(f)) {
+ const upb_map *map = upb_msgval_getmap(val);
+ UPB_ASSERT(map);
+ /* TODO: putmap(map, f, sink, depth);*/
+ } else if (upb_fielddef_isstring(f)) {
+ /* TODO putstr(); */
+ } else {
+ upb_selector_t sel = getsel2(f, upb_handlers_getprimitivehandlertype(f));
+ UPB_ASSERT(upb_fielddef_isprimitive(f));
+
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_FLOAT:
+ CHECK_TRUE(upb_sink_putfloat(sink, sel, upb_msgval_getfloat(val)));
+ break;
+ case UPB_TYPE_DOUBLE:
+ CHECK_TRUE(
+ upb_sink_putdouble(sink, sel, upb_msgval_getdouble(val)));
+ break;
+ case UPB_TYPE_BOOL:
+ CHECK_TRUE(upb_sink_putbool(sink, sel, upb_msgval_getbool(val)));
+ break;
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32:
+ CHECK_TRUE(upb_sink_putint32(sink, sel, upb_msgval_getint32(val)));
+ break;
+ case UPB_TYPE_UINT32:
+ CHECK_TRUE(
+ upb_sink_putuint32(sink, sel, upb_msgval_getuint32(val)));
+ break;
+ case UPB_TYPE_INT64:
+ CHECK_TRUE(upb_sink_putint64(sink, sel, upb_msgval_getint64(val)));
+ break;
+ case UPB_TYPE_UINT64:
+ CHECK_TRUE(
+ upb_sink_putuint64(sink, sel, upb_msgval_getuint64(val)));
+ break;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_MESSAGE:
+ UPB_UNREACHABLE();
+ }
+ }
+ }
+
+ upb_sink_endmsg(sink, &status);
+ return true;
+}
+
+upb_visitor *upb_visitor_create(upb_env *e, const upb_visitorplan *vp,
+ upb_sink *output) {
+ upb_visitor *visitor = upb_env_malloc(e, sizeof(*visitor));
+ visitor->layout = (const upb_msglayout*)vp;
+ visitor->sink = output;
+ return visitor;
+}
+
+bool upb_visitor_visitmsg(upb_visitor *visitor, const upb_msg *msg) {
+ return upb_visitor_visitmsg2(msg, visitor->layout, visitor->sink, 0);
+}
+
+
+/** upb_msg *******************************************************************/
+
+/* If we always read/write as a consistent type to each address, this shouldn't
+ * violate aliasing.
+ */
+#define DEREF(msg, ofs, type) *(type*)CHARPTR_AT(msg, ofs)
+
+static upb_inttable *upb_msg_trygetextdict(const upb_msg *msg,
+ const upb_msglayout *l) {
+ return l->has_extdict ? DEREF(msg, l->extdict_offset, upb_inttable*) : NULL;
+}
+
+static upb_inttable *upb_msg_getextdict(upb_msg *msg,
+ const upb_msglayout *l,
+ upb_alloc *a) {
+ upb_inttable *ext_dict;
+ UPB_ASSERT(l->has_extdict);
+
+ ext_dict = upb_msg_trygetextdict(msg, l);
+
+ if (!ext_dict) {
+ ext_dict = upb_malloc(a, sizeof(upb_inttable));
+
+ if (!ext_dict) {
+ return NULL;
+ }
+
+ /* Use an 8-byte type to ensure all bytes are copied. */
+ if (!upb_inttable_init2(ext_dict, UPB_CTYPE_INT64, a)) {
+ upb_free(a, ext_dict);
+ return NULL;
+ }
+
+ DEREF(msg, l->extdict_offset, upb_inttable*) = ext_dict;
+ }
+
+ return ext_dict;
+}
+
+static uint32_t upb_msg_getoneofint(const upb_msg *msg,
+ const upb_oneofdef *o,
+ const upb_msglayout *l) {
+ size_t oneof_ofs = l->case_offsets[upb_oneofdef_index(o)];
+ return DEREF(msg, oneof_ofs, uint8_t);
+}
+
+static void upb_msg_setoneofcase(const upb_msg *msg,
+ const upb_oneofdef *o,
+ const upb_msglayout *l,
+ uint32_t val) {
+ size_t oneof_ofs = l->case_offsets[upb_oneofdef_index(o)];
+ DEREF(msg, oneof_ofs, uint8_t) = val;
+}
+
+
+static bool upb_msg_oneofis(const upb_msg *msg, const upb_msglayout *l,
+ const upb_oneofdef *o, const upb_fielddef *f) {
+ return upb_msg_getoneofint(msg, o, l) == upb_fielddef_number(f);
+}
+
+size_t upb_msg_sizeof(const upb_msglayout *l) { return l->size; }
+
+void upb_msg_init(upb_msg *msg, const upb_msglayout *l, upb_alloc *a) {
+ if (l->default_msg) {
+ memcpy(msg, l->default_msg, l->size);
+ } else {
+ memset(msg, 0, l->size);
+ }
+
+ /* Set arena pointer. */
+ memcpy(msg, &a, sizeof(a));
+}
+
+void upb_msg_uninit(upb_msg *msg, const upb_msglayout *l) {
+ upb_inttable *ext_dict = upb_msg_trygetextdict(msg, l);
+ if (ext_dict) {
+ upb_inttable_uninit2(ext_dict, upb_msg_alloc(msg, l));
+ }
+}
+
+upb_msg *upb_msg_new(const upb_msglayout *l, upb_alloc *a) {
+ upb_msg *msg = upb_malloc(a, upb_msg_sizeof(l));
+
+ if (msg) {
+ upb_msg_init(msg, l, a);
+ }
+
+ return msg;
+}
+
+void upb_msg_free(upb_msg *msg, const upb_msglayout *l) {
+ upb_msg_uninit(msg, l);
+ upb_free(upb_msg_alloc(msg, l), msg);
+}
+
+upb_alloc *upb_msg_alloc(const upb_msg *msg, const upb_msglayout *l) {
+ upb_alloc *alloc;
+ UPB_UNUSED(l);
+ memcpy(&alloc, msg, sizeof(alloc));
+ return alloc;
+}
+
+bool upb_msg_has(const upb_msg *msg,
+ const upb_fielddef *f,
+ const upb_msglayout *l) {
+ const upb_oneofdef *o;
+ upb_msg_checkfield(l, f);
+ UPB_ASSERT(upb_fielddef_haspresence(f));
+
+ if (upb_fielddef_isextension(f)) {
+ /* Extensions are set when they are present in the extension dict. */
+ upb_inttable *ext_dict = upb_msg_trygetextdict(msg, l);
+ upb_value v;
+ return ext_dict != NULL &&
+ upb_inttable_lookup32(ext_dict, upb_fielddef_number(f), &v);
+ } else if ((o = upb_fielddef_containingoneof(f)) != NULL) {
+ /* Oneofs are set when the oneof number is set to this field. */
+ return upb_msg_getoneofint(msg, o, l) == upb_fielddef_number(f);
+ } else {
+ /* Other fields are set when their hasbit is set. */
+ uint32_t hasbit = l->hasbits[upb_fielddef_index(f)];
+ return DEREF(msg, hasbit / 8, char) | (1 << (hasbit % 8));
+ }
+}
+
+upb_msgval upb_msg_get(const upb_msg *msg, const upb_fielddef *f,
+ const upb_msglayout *l) {
+ upb_msg_checkfield(l, f);
+
+ if (upb_fielddef_isextension(f)) {
+ upb_inttable *ext_dict = upb_msg_trygetextdict(msg, l);
+ upb_value val;
+ if (upb_inttable_lookup32(ext_dict, upb_fielddef_number(f), &val)) {
+ return upb_msgval_fromval(val);
+ } else {
+ return upb_msgval_fromdefault(f);
+ }
+ } else {
+ size_t ofs = l->field_offsets[upb_fielddef_index(f)];
+ const upb_oneofdef *o = upb_fielddef_containingoneof(f);
+ upb_msgval ret;
+
+ if (o && !upb_msg_oneofis(msg, l, o, f)) {
+ /* Oneof defaults can't come from the message because the memory is reused
+ * by all types in the oneof. */
+ return upb_msgval_fromdefault(f);
+ }
+
+ ret = upb_msgval_read(msg, ofs, upb_msg_fieldsize(f));
+ return ret;
+ }
+}
+
+bool upb_msg_set(upb_msg *msg,
+ const upb_fielddef *f,
+ upb_msgval val,
+ const upb_msglayout *l) {
+ upb_alloc *a = upb_msg_alloc(msg, l);
+ upb_msg_checkfield(l, f);
+
+ if (upb_fielddef_isextension(f)) {
+ /* TODO(haberman): introduce table API that can do this in one call. */
+ upb_inttable *ext = upb_msg_getextdict(msg, l, a);
+ upb_value val2 = upb_toval(val);
+ if (!upb_inttable_replace(ext, upb_fielddef_number(f), val2) &&
+ !upb_inttable_insert2(ext, upb_fielddef_number(f), val2, a)) {
+ return false;
+ }
+ } else {
+ size_t ofs = l->field_offsets[upb_fielddef_index(f)];
+ const upb_oneofdef *o = upb_fielddef_containingoneof(f);
+
+ if (o) {
+ upb_msg_setoneofcase(msg, o, l, upb_fielddef_number(f));
+ }
+
+ upb_msgval_write(msg, ofs, val, upb_msg_fieldsize(f));
+ }
+ return true;
+}
+
+
+/** upb_array *****************************************************************/
+
+struct upb_array {
+ upb_fieldtype_t type;
+ uint8_t element_size;
+ void *data; /* Each element is element_size. */
+ size_t len; /* Measured in elements. */
+ size_t size; /* Measured in elements. */
+ upb_alloc *alloc;
+};
+
+#define DEREF_ARR(arr, i, type) ((type*)arr->data)[i]
+
+size_t upb_array_sizeof(upb_fieldtype_t type) {
+ UPB_UNUSED(type);
+ return sizeof(upb_array);
+}
+
+void upb_array_init(upb_array *arr, upb_fieldtype_t type, upb_alloc *alloc) {
+ arr->type = type;
+ arr->data = NULL;
+ arr->len = 0;
+ arr->size = 0;
+ arr->element_size = upb_msgval_sizeof(type);
+ arr->alloc = alloc;
+}
+
+void upb_array_uninit(upb_array *arr) {
+ upb_free(arr->alloc, arr->data);
+}
+
+upb_array *upb_array_new(upb_fieldtype_t type, upb_alloc *a) {
+ upb_array *ret = upb_malloc(a, upb_array_sizeof(type));
+
+ if (ret) {
+ upb_array_init(ret, type, a);
+ }
+
+ return ret;
+}
+
+void upb_array_free(upb_array *arr) {
+ upb_array_uninit(arr);
+ upb_free(arr->alloc, arr);
+}
+
+size_t upb_array_size(const upb_array *arr) {
+ return arr->len;
+}
+
+upb_fieldtype_t upb_array_type(const upb_array *arr) {
+ return arr->type;
+}
+
+upb_msgval upb_array_get(const upb_array *arr, size_t i) {
+ UPB_ASSERT(i < arr->len);
+ return upb_msgval_read(arr->data, i * arr->element_size, arr->element_size);
+}
+
+bool upb_array_set(upb_array *arr, size_t i, upb_msgval val) {
+ UPB_ASSERT(i <= arr->len);
+
+ if (i == arr->len) {
+ /* Extending the array. */
+
+ if (i == arr->size) {
+ /* Need to reallocate. */
+ size_t new_size = UPB_MAX(arr->size * 2, 8);
+ size_t new_bytes = new_size * arr->element_size;
+ size_t old_bytes = arr->size * arr->element_size;
+ upb_msgval *new_data =
+ upb_realloc(arr->alloc, arr->data, old_bytes, new_bytes);
+
+ if (!new_data) {
+ return false;
+ }
+
+ arr->data = new_data;
+ arr->size = new_size;
+ }
+
+ arr->len = i + 1;
+ }
+
+ upb_msgval_write(arr->data, i * arr->element_size, val, arr->element_size);
+ return true;
+}
+
+
+/** upb_map *******************************************************************/
+
+struct upb_map {
+ upb_fieldtype_t key_type;
+ upb_fieldtype_t val_type;
+ /* We may want to optimize this to use inttable where possible, for greater
+ * efficiency and lower memory footprint. */
+ upb_strtable strtab;
+ upb_alloc *alloc;
+};
+
+static void upb_map_tokey(upb_fieldtype_t type, upb_msgval *key,
+ const char **out_key, size_t *out_len) {
+ switch (type) {
+ case UPB_TYPE_STRING:
+ /* Point to string data of the input key. */
+ *out_key = key->str.ptr;
+ *out_len = key->str.len;
+ return;
+ case UPB_TYPE_BOOL:
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT64:
+ /* Point to the key itself. XXX: big-endian. */
+ *out_key = (const char*)key;
+ *out_len = upb_msgval_sizeof(type);
+ return;
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_DOUBLE:
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_FLOAT:
+ case UPB_TYPE_MESSAGE:
+ break; /* Cannot be a map key. */
+ }
+ UPB_UNREACHABLE();
+}
+
+static upb_msgval upb_map_fromkey(upb_fieldtype_t type, const char *key,
+ size_t len) {
+ switch (type) {
+ case UPB_TYPE_STRING:
+ return upb_msgval_str(key, len);
+ case UPB_TYPE_BOOL:
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT64:
+ return upb_msgval_read(key, 0, upb_msgval_sizeof(type));
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_DOUBLE:
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_FLOAT:
+ case UPB_TYPE_MESSAGE:
+ break; /* Cannot be a map key. */
+ }
+ UPB_UNREACHABLE();
+}
+
+size_t upb_map_sizeof(upb_fieldtype_t ktype, upb_fieldtype_t vtype) {
+ /* Size does not currently depend on key/value type. */
+ UPB_UNUSED(ktype);
+ UPB_UNUSED(vtype);
+ return sizeof(upb_map);
+}
+
+bool upb_map_init(upb_map *map, upb_fieldtype_t ktype, upb_fieldtype_t vtype,
+ upb_alloc *a) {
+ upb_ctype_t vtabtype = upb_fieldtotabtype(vtype);
+ UPB_ASSERT(upb_fieldtype_mapkeyok(ktype));
+ map->key_type = ktype;
+ map->val_type = vtype;
+ map->alloc = a;
+
+ if (!upb_strtable_init2(&map->strtab, vtabtype, a)) {
+ return false;
+ }
+
+ return true;
+}
+
+void upb_map_uninit(upb_map *map) {
+ upb_strtable_uninit2(&map->strtab, map->alloc);
+}
+
+upb_map *upb_map_new(upb_fieldtype_t ktype, upb_fieldtype_t vtype,
+ upb_alloc *a) {
+ upb_map *map = upb_malloc(a, upb_map_sizeof(ktype, vtype));
+
+ if (!map) {
+ return NULL;
+ }
+
+ if (!upb_map_init(map, ktype, vtype, a)) {
+ return NULL;
+ }
+
+ return map;
+}
+
+void upb_map_free(upb_map *map) {
+ upb_map_uninit(map);
+ upb_free(map->alloc, map);
+}
+
+size_t upb_map_size(const upb_map *map) {
+ return upb_strtable_count(&map->strtab);
+}
+
+upb_fieldtype_t upb_map_keytype(const upb_map *map) {
+ return map->key_type;
+}
+
+upb_fieldtype_t upb_map_valuetype(const upb_map *map) {
+ return map->val_type;
+}
+
+bool upb_map_get(const upb_map *map, upb_msgval key, upb_msgval *val) {
+ upb_value tabval;
+ const char *key_str;
+ size_t key_len;
+ bool ret;
+
+ upb_map_tokey(map->key_type, &key, &key_str, &key_len);
+ ret = upb_strtable_lookup2(&map->strtab, key_str, key_len, &tabval);
+ if (ret) {
+ memcpy(val, &tabval, sizeof(tabval));
+ }
+
+ return ret;
+}
+
+bool upb_map_set(upb_map *map, upb_msgval key, upb_msgval val,
+ upb_msgval *removed) {
+ const char *key_str;
+ size_t key_len;
+ upb_value tabval = upb_toval(val);
+ upb_value removedtabval;
+ upb_alloc *a = map->alloc;
+
+ upb_map_tokey(map->key_type, &key, &key_str, &key_len);
+
+ /* TODO(haberman): add overwrite operation to minimize number of lookups. */
+ if (upb_strtable_lookup2(&map->strtab, key_str, key_len, NULL)) {
+ upb_strtable_remove3(&map->strtab, key_str, key_len, &removedtabval, a);
+ memcpy(&removed, &removedtabval, sizeof(removed));
+ }
+
+ return upb_strtable_insert3(&map->strtab, key_str, key_len, tabval, a);
+}
+
+bool upb_map_del(upb_map *map, upb_msgval key) {
+ const char *key_str;
+ size_t key_len;
+ upb_alloc *a = map->alloc;
+
+ upb_map_tokey(map->key_type, &key, &key_str, &key_len);
+ return upb_strtable_remove3(&map->strtab, key_str, key_len, NULL, a);
+}
+
+
+/** upb_mapiter ***************************************************************/
+
+struct upb_mapiter {
+ upb_strtable_iter iter;
+ upb_fieldtype_t key_type;
+};
+
+size_t upb_mapiter_sizeof() {
+ return sizeof(upb_mapiter);
+}
+
+void upb_mapiter_begin(upb_mapiter *i, const upb_map *map) {
+ upb_strtable_begin(&i->iter, &map->strtab);
+ i->key_type = map->key_type;
+}
+
+upb_mapiter *upb_mapiter_new(const upb_map *t, upb_alloc *a) {
+ upb_mapiter *ret = upb_malloc(a, upb_mapiter_sizeof());
+
+ if (!ret) {
+ return NULL;
+ }
+
+ upb_mapiter_begin(ret, t);
+ return ret;
+}
+
+void upb_mapiter_free(upb_mapiter *i, upb_alloc *a) {
+ upb_free(a, i);
+}
+
+void upb_mapiter_next(upb_mapiter *i) {
+ upb_strtable_next(&i->iter);
+}
+
+bool upb_mapiter_done(const upb_mapiter *i) {
+ return upb_strtable_done(&i->iter);
+}
+
+upb_msgval upb_mapiter_key(const upb_mapiter *i) {
+ return upb_map_fromkey(i->key_type, upb_strtable_iter_key(&i->iter),
+ upb_strtable_iter_keylength(&i->iter));
+}
+
+upb_msgval upb_mapiter_value(const upb_mapiter *i) {
+ return upb_msgval_fromval(upb_strtable_iter_value(&i->iter));
+}
+
+void upb_mapiter_setdone(upb_mapiter *i) {
+ upb_strtable_iter_setdone(&i->iter);
+}
+
+bool upb_mapiter_isequal(const upb_mapiter *i1, const upb_mapiter *i2) {
+ return upb_strtable_iter_isequal(&i1->iter, &i2->iter);
+}
+
+
+/** Handlers for upb_msg ******************************************************/
+
+typedef struct {
+ size_t offset;
+ int32_t hasbit;
+} upb_msg_handlerdata;
+
+/* Fallback implementation if the handler is not specialized by the producer. */
+#define MSG_WRITER(type, ctype) \
+ bool upb_msg_set ## type (void *c, const void *hd, ctype val) { \
+ uint8_t *m = c; \
+ const upb_msg_handlerdata *d = hd; \
+ if (d->hasbit > 0) \
+ *(uint8_t*)&m[d->hasbit / 8] |= 1 << (d->hasbit % 8); \
+ *(ctype*)&m[d->offset] = val; \
+ return true; \
+ } \
+
+MSG_WRITER(double, double)
+MSG_WRITER(float, float)
+MSG_WRITER(int32, int32_t)
+MSG_WRITER(int64, int64_t)
+MSG_WRITER(uint32, uint32_t)
+MSG_WRITER(uint64, uint64_t)
+MSG_WRITER(bool, bool)
+
+bool upb_msg_setscalarhandler(upb_handlers *h, const upb_fielddef *f,
+ size_t offset, int32_t hasbit) {
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ bool ok;
+
+ upb_msg_handlerdata *d = upb_gmalloc(sizeof(*d));
+ if (!d) return false;
+ d->offset = offset;
+ d->hasbit = hasbit;
+
+ upb_handlerattr_sethandlerdata(&attr, d);
+ upb_handlerattr_setalwaysok(&attr, true);
+ upb_handlers_addcleanup(h, d, upb_gfree);
+
+#define TYPE(u, l) \
+ case UPB_TYPE_##u: \
+ ok = upb_handlers_set##l(h, f, upb_msg_set##l, &attr); break;
+
+ ok = false;
+
+ switch (upb_fielddef_type(f)) {
+ TYPE(INT64, int64);
+ TYPE(INT32, int32);
+ TYPE(ENUM, int32);
+ TYPE(UINT64, uint64);
+ TYPE(UINT32, uint32);
+ TYPE(DOUBLE, double);
+ TYPE(FLOAT, float);
+ TYPE(BOOL, bool);
+ default: UPB_ASSERT(false); break;
+ }
+#undef TYPE
+
+ upb_handlerattr_uninit(&attr);
+ return ok;
+}
+
+bool upb_msg_getscalarhandlerdata(const upb_handlers *h,
+ upb_selector_t s,
+ upb_fieldtype_t *type,
+ size_t *offset,
+ int32_t *hasbit) {
+ const upb_msg_handlerdata *d;
+ upb_func *f = upb_handlers_gethandler(h, s);
+
+ if ((upb_int64_handlerfunc*)f == upb_msg_setint64) {
+ *type = UPB_TYPE_INT64;
+ } else if ((upb_int32_handlerfunc*)f == upb_msg_setint32) {
+ *type = UPB_TYPE_INT32;
+ } else if ((upb_uint64_handlerfunc*)f == upb_msg_setuint64) {
+ *type = UPB_TYPE_UINT64;
+ } else if ((upb_uint32_handlerfunc*)f == upb_msg_setuint32) {
+ *type = UPB_TYPE_UINT32;
+ } else if ((upb_double_handlerfunc*)f == upb_msg_setdouble) {
+ *type = UPB_TYPE_DOUBLE;
+ } else if ((upb_float_handlerfunc*)f == upb_msg_setfloat) {
+ *type = UPB_TYPE_FLOAT;
+ } else if ((upb_bool_handlerfunc*)f == upb_msg_setbool) {
+ *type = UPB_TYPE_BOOL;
+ } else {
+ return false;
+ }
+
+ d = upb_handlers_gethandlerdata(h, s);
+ *offset = d->offset;
+ *hasbit = d->hasbit;
+ return true;
+}
+/*
+** upb::RefCounted Implementation
+**
+** Our key invariants are:
+** 1. reference cycles never span groups
+** 2. for ref2(to, from), we increment to's count iff group(from) != group(to)
+**
+** The previous two are how we avoid leaking cycles. Other important
+** invariants are:
+** 3. for mutable objects "from" and "to", if there exists a ref2(to, from)
+** this implies group(from) == group(to). (In practice, what we implement
+** is even stronger; "from" and "to" will share a group if there has *ever*
+** been a ref2(to, from), but all that is necessary for correctness is the
+** weaker one).
+** 4. mutable and immutable objects are never in the same group.
+*/
+
+
+#include <setjmp.h>
+
+static void freeobj(upb_refcounted *o);
+
+const char untracked_val;
+const void *UPB_UNTRACKED_REF = &untracked_val;
+
+/* arch-specific atomic primitives *******************************************/
+
+#ifdef UPB_THREAD_UNSAFE /*---------------------------------------------------*/
+
+static void atomic_inc(uint32_t *a) { (*a)++; }
+static bool atomic_dec(uint32_t *a) { return --(*a) == 0; }
+
+#elif defined(__GNUC__) || defined(__clang__) /*------------------------------*/
+
+static void atomic_inc(uint32_t *a) { __sync_fetch_and_add(a, 1); }
+static bool atomic_dec(uint32_t *a) { return __sync_sub_and_fetch(a, 1) == 0; }
+
+#elif defined(WIN32) /*-------------------------------------------------------*/
+
+#include <Windows.h>
+
+static void atomic_inc(upb_atomic_t *a) { InterlockedIncrement(&a->val); }
+static bool atomic_dec(upb_atomic_t *a) {
+ return InterlockedDecrement(&a->val) == 0;
+}
+
+#else
+#error Atomic primitives not defined for your platform/CPU. \
+ Implement them or compile with UPB_THREAD_UNSAFE.
+#endif
+
+/* All static objects point to this refcount.
+ * It is special-cased in ref/unref below. */
+uint32_t static_refcount = -1;
+
+/* We can avoid atomic ops for statically-declared objects.
+ * This is a minor optimization but nice since we can avoid degrading under
+ * contention in this case. */
+
+static void refgroup(uint32_t *group) {
+ if (group != &static_refcount)
+ atomic_inc(group);
+}
+
+static bool unrefgroup(uint32_t *group) {
+ if (group == &static_refcount) {
+ return false;
+ } else {
+ return atomic_dec(group);
+ }
+}
+
+
+/* Reference tracking (debug only) ********************************************/
+
+#ifdef UPB_DEBUG_REFS
+
+#ifdef UPB_THREAD_UNSAFE
+
+static void upb_lock() {}
+static void upb_unlock() {}
+
+#else
+
+/* User must define functions that lock/unlock a global mutex and link this
+ * file against them. */
+void upb_lock();
+void upb_unlock();
+
+#endif
+
+/* UPB_DEBUG_REFS mode counts on being able to malloc() memory in some
+ * code-paths that can normally never fail, like upb_refcounted_ref(). Since
+ * we have no way to propagage out-of-memory errors back to the user, and since
+ * these errors can only occur in UPB_DEBUG_REFS mode, we use an allocator that
+ * immediately aborts on failure (avoiding the global allocator, which might
+ * inject failures). */
+
+#include <stdlib.h>
+
+static void *upb_debugrefs_allocfunc(upb_alloc *alloc, void *ptr,
+ size_t oldsize, size_t size) {
+ UPB_UNUSED(alloc);
+ UPB_UNUSED(oldsize);
+ if (size == 0) {
+ free(ptr);
+ return NULL;
+ } else {
+ void *ret = realloc(ptr, size);
+
+ if (!ret) {
+ abort();
+ }
+
+ return ret;
+ }
+}
+
+upb_alloc upb_alloc_debugrefs = {&upb_debugrefs_allocfunc};
+
+typedef struct {
+ int count; /* How many refs there are (duplicates only allowed for ref2). */
+ bool is_ref2;
+} trackedref;
+
+static trackedref *trackedref_new(bool is_ref2) {
+ trackedref *ret = upb_malloc(&upb_alloc_debugrefs, sizeof(*ret));
+ ret->count = 1;
+ ret->is_ref2 = is_ref2;
+ return ret;
+}
+
+static void track(const upb_refcounted *r, const void *owner, bool ref2) {
+ upb_value v;
+
+ UPB_ASSERT(owner);
+ if (owner == UPB_UNTRACKED_REF) return;
+
+ upb_lock();
+ if (upb_inttable_lookupptr(r->refs, owner, &v)) {
+ trackedref *ref = upb_value_getptr(v);
+ /* Since we allow multiple ref2's for the same to/from pair without
+ * allocating separate memory for each one, we lose the fine-grained
+ * tracking behavior we get with regular refs. Since ref2s only happen
+ * inside upb, we'll accept this limitation until/unless there is a really
+ * difficult upb-internal bug that can't be figured out without it. */
+ UPB_ASSERT(ref2);
+ UPB_ASSERT(ref->is_ref2);
+ ref->count++;
+ } else {
+ trackedref *ref = trackedref_new(ref2);
+ upb_inttable_insertptr2(r->refs, owner, upb_value_ptr(ref),
+ &upb_alloc_debugrefs);
+ if (ref2) {
+ /* We know this cast is safe when it is a ref2, because it's coming from
+ * another refcounted object. */
+ const upb_refcounted *from = owner;
+ UPB_ASSERT(!upb_inttable_lookupptr(from->ref2s, r, NULL));
+ upb_inttable_insertptr2(from->ref2s, r, upb_value_ptr(NULL),
+ &upb_alloc_debugrefs);
+ }
+ }
+ upb_unlock();
+}
+
+static void untrack(const upb_refcounted *r, const void *owner, bool ref2) {
+ upb_value v;
+ bool found;
+ trackedref *ref;
+
+ UPB_ASSERT(owner);
+ if (owner == UPB_UNTRACKED_REF) return;
+
+ upb_lock();
+ found = upb_inttable_lookupptr(r->refs, owner, &v);
+ /* This assert will fail if an owner attempts to release a ref it didn't have. */
+ UPB_ASSERT(found);
+ ref = upb_value_getptr(v);
+ UPB_ASSERT(ref->is_ref2 == ref2);
+ if (--ref->count == 0) {
+ free(ref);
+ upb_inttable_removeptr(r->refs, owner, NULL);
+ if (ref2) {
+ /* We know this cast is safe when it is a ref2, because it's coming from
+ * another refcounted object. */
+ const upb_refcounted *from = owner;
+ bool removed = upb_inttable_removeptr(from->ref2s, r, NULL);
+ UPB_ASSERT(removed);
+ }
+ }
+ upb_unlock();
+}
+
+static void checkref(const upb_refcounted *r, const void *owner, bool ref2) {
+ upb_value v;
+ bool found;
+ trackedref *ref;
+
+ upb_lock();
+ found = upb_inttable_lookupptr(r->refs, owner, &v);
+ UPB_ASSERT(found);
+ ref = upb_value_getptr(v);
+ UPB_ASSERT(ref->is_ref2 == ref2);
+ upb_unlock();
+}
+
+/* Populates the given UPB_CTYPE_INT32 inttable with counts of ref2's that
+ * originate from the given owner. */
+static void getref2s(const upb_refcounted *owner, upb_inttable *tab) {
+ upb_inttable_iter i;
+
+ upb_lock();
+ upb_inttable_begin(&i, owner->ref2s);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ upb_value v;
+ upb_value count;
+ trackedref *ref;
+ bool found;
+
+ upb_refcounted *to = (upb_refcounted*)upb_inttable_iter_key(&i);
+
+ /* To get the count we need to look in the target's table. */
+ found = upb_inttable_lookupptr(to->refs, owner, &v);
+ UPB_ASSERT(found);
+ ref = upb_value_getptr(v);
+ count = upb_value_int32(ref->count);
+
+ upb_inttable_insertptr2(tab, to, count, &upb_alloc_debugrefs);
+ }
+ upb_unlock();
+}
+
+typedef struct {
+ upb_inttable ref2;
+ const upb_refcounted *obj;
+} check_state;
+
+static void visit_check(const upb_refcounted *obj, const upb_refcounted *subobj,
+ void *closure) {
+ check_state *s = closure;
+ upb_inttable *ref2 = &s->ref2;
+ upb_value v;
+ bool removed;
+ int32_t newcount;
+
+ UPB_ASSERT(obj == s->obj);
+ UPB_ASSERT(subobj);
+ removed = upb_inttable_removeptr(ref2, subobj, &v);
+ /* The following assertion will fail if the visit() function visits a subobj
+ * that it did not have a ref2 on, or visits the same subobj too many times. */
+ UPB_ASSERT(removed);
+ newcount = upb_value_getint32(v) - 1;
+ if (newcount > 0) {
+ upb_inttable_insert2(ref2, (uintptr_t)subobj, upb_value_int32(newcount),
+ &upb_alloc_debugrefs);
+ }
+}
+
+static void visit(const upb_refcounted *r, upb_refcounted_visit *v,
+ void *closure) {
+ /* In DEBUG_REFS mode we know what existing ref2 refs there are, so we know
+ * exactly the set of nodes that visit() should visit. So we verify visit()'s
+ * correctness here. */
+ check_state state;
+ state.obj = r;
+ upb_inttable_init2(&state.ref2, UPB_CTYPE_INT32, &upb_alloc_debugrefs);
+ getref2s(r, &state.ref2);
+
+ /* This should visit any children in the ref2 table. */
+ if (r->vtbl->visit) r->vtbl->visit(r, visit_check, &state);
+
+ /* This assertion will fail if the visit() function missed any children. */
+ UPB_ASSERT(upb_inttable_count(&state.ref2) == 0);
+ upb_inttable_uninit2(&state.ref2, &upb_alloc_debugrefs);
+ if (r->vtbl->visit) r->vtbl->visit(r, v, closure);
+}
+
+static void trackinit(upb_refcounted *r) {
+ r->refs = upb_malloc(&upb_alloc_debugrefs, sizeof(*r->refs));
+ r->ref2s = upb_malloc(&upb_alloc_debugrefs, sizeof(*r->ref2s));
+ upb_inttable_init2(r->refs, UPB_CTYPE_PTR, &upb_alloc_debugrefs);
+ upb_inttable_init2(r->ref2s, UPB_CTYPE_PTR, &upb_alloc_debugrefs);
+}
+
+static void trackfree(const upb_refcounted *r) {
+ upb_inttable_uninit2(r->refs, &upb_alloc_debugrefs);
+ upb_inttable_uninit2(r->ref2s, &upb_alloc_debugrefs);
+ upb_free(&upb_alloc_debugrefs, r->refs);
+ upb_free(&upb_alloc_debugrefs, r->ref2s);
+}
+
+#else
+
+static void track(const upb_refcounted *r, const void *owner, bool ref2) {
+ UPB_UNUSED(r);
+ UPB_UNUSED(owner);
+ UPB_UNUSED(ref2);
+}
+
+static void untrack(const upb_refcounted *r, const void *owner, bool ref2) {
+ UPB_UNUSED(r);
+ UPB_UNUSED(owner);
+ UPB_UNUSED(ref2);
+}
+
+static void checkref(const upb_refcounted *r, const void *owner, bool ref2) {
+ UPB_UNUSED(r);
+ UPB_UNUSED(owner);
+ UPB_UNUSED(ref2);
+}
+
+static void trackinit(upb_refcounted *r) {
+ UPB_UNUSED(r);
+}
+
+static void trackfree(const upb_refcounted *r) {
+ UPB_UNUSED(r);
+}
+
+static void visit(const upb_refcounted *r, upb_refcounted_visit *v,
+ void *closure) {
+ if (r->vtbl->visit) r->vtbl->visit(r, v, closure);
+}
+
+#endif /* UPB_DEBUG_REFS */
+
+
+/* freeze() *******************************************************************/
+
+/* The freeze() operation is by far the most complicated part of this scheme.
+ * We compute strongly-connected components and then mutate the graph such that
+ * we preserve the invariants documented at the top of this file. And we must
+ * handle out-of-memory errors gracefully (without leaving the graph
+ * inconsistent), which adds to the fun. */
+
+/* The state used by the freeze operation (shared across many functions). */
+typedef struct {
+ int depth;
+ int maxdepth;
+ uint64_t index;
+ /* Maps upb_refcounted* -> attributes (color, etc). attr layout varies by
+ * color. */
+ upb_inttable objattr;
+ upb_inttable stack; /* stack of upb_refcounted* for Tarjan's algorithm. */
+ upb_inttable groups; /* array of uint32_t*, malloc'd refcounts for new groups */
+ upb_status *status;
+ jmp_buf err;
+} tarjan;
+
+static void release_ref2(const upb_refcounted *obj,
+ const upb_refcounted *subobj,
+ void *closure);
+
+/* Node attributes -----------------------------------------------------------*/
+
+/* After our analysis phase all nodes will be either GRAY or WHITE. */
+
+typedef enum {
+ BLACK = 0, /* Object has not been seen. */
+ GRAY, /* Object has been found via a refgroup but may not be reachable. */
+ GREEN, /* Object is reachable and is currently on the Tarjan stack. */
+ WHITE /* Object is reachable and has been assigned a group (SCC). */
+} color_t;
+
+UPB_NORETURN static void err(tarjan *t) { longjmp(t->err, 1); }
+UPB_NORETURN static void oom(tarjan *t) {
+ upb_status_seterrmsg(t->status, "out of memory");
+ err(t);
+}
+
+static uint64_t trygetattr(const tarjan *t, const upb_refcounted *r) {
+ upb_value v;
+ return upb_inttable_lookupptr(&t->objattr, r, &v) ?
+ upb_value_getuint64(v) : 0;
+}
+
+static uint64_t getattr(const tarjan *t, const upb_refcounted *r) {
+ upb_value v;
+ bool found = upb_inttable_lookupptr(&t->objattr, r, &v);
+ UPB_ASSERT(found);
+ return upb_value_getuint64(v);
+}
+
+static void setattr(tarjan *t, const upb_refcounted *r, uint64_t attr) {
+ upb_inttable_removeptr(&t->objattr, r, NULL);
+ upb_inttable_insertptr(&t->objattr, r, upb_value_uint64(attr));
+}
+
+static color_t color(tarjan *t, const upb_refcounted *r) {
+ return trygetattr(t, r) & 0x3; /* Color is always stored in the low 2 bits. */
+}
+
+static void set_gray(tarjan *t, const upb_refcounted *r) {
+ UPB_ASSERT(color(t, r) == BLACK);
+ setattr(t, r, GRAY);
+}
+
+/* Pushes an obj onto the Tarjan stack and sets it to GREEN. */
+static void push(tarjan *t, const upb_refcounted *r) {
+ UPB_ASSERT(color(t, r) == BLACK || color(t, r) == GRAY);
+ /* This defines the attr layout for the GREEN state. "index" and "lowlink"
+ * get 31 bits, which is plenty (limit of 2B objects frozen at a time). */
+ setattr(t, r, GREEN | (t->index << 2) | (t->index << 33));
+ if (++t->index == 0x80000000) {
+ upb_status_seterrmsg(t->status, "too many objects to freeze");
+ err(t);
+ }
+ upb_inttable_push(&t->stack, upb_value_ptr((void*)r));
+}
+
+/* Pops an obj from the Tarjan stack and sets it to WHITE, with a ptr to its
+ * SCC group. */
+static upb_refcounted *pop(tarjan *t) {
+ upb_refcounted *r = upb_value_getptr(upb_inttable_pop(&t->stack));
+ UPB_ASSERT(color(t, r) == GREEN);
+ /* This defines the attr layout for nodes in the WHITE state.
+ * Top of group stack is [group, NULL]; we point at group. */
+ setattr(t, r, WHITE | (upb_inttable_count(&t->groups) - 2) << 8);
+ return r;
+}
+
+static void tarjan_newgroup(tarjan *t) {
+ uint32_t *group = upb_gmalloc(sizeof(*group));
+ if (!group) oom(t);
+ /* Push group and empty group leader (we'll fill in leader later). */
+ if (!upb_inttable_push(&t->groups, upb_value_ptr(group)) ||
+ !upb_inttable_push(&t->groups, upb_value_ptr(NULL))) {
+ upb_gfree(group);
+ oom(t);
+ }
+ *group = 0;
+}
+
+static uint32_t idx(tarjan *t, const upb_refcounted *r) {
+ UPB_ASSERT(color(t, r) == GREEN);
+ return (getattr(t, r) >> 2) & 0x7FFFFFFF;
+}
+
+static uint32_t lowlink(tarjan *t, const upb_refcounted *r) {
+ if (color(t, r) == GREEN) {
+ return getattr(t, r) >> 33;
+ } else {
+ return UINT32_MAX;
+ }
+}
+
+static void set_lowlink(tarjan *t, const upb_refcounted *r, uint32_t lowlink) {
+ UPB_ASSERT(color(t, r) == GREEN);
+ setattr(t, r, ((uint64_t)lowlink << 33) | (getattr(t, r) & 0x1FFFFFFFF));
+}
+
+static uint32_t *group(tarjan *t, upb_refcounted *r) {
+ uint64_t groupnum;
+ upb_value v;
+ bool found;
+
+ UPB_ASSERT(color(t, r) == WHITE);
+ groupnum = getattr(t, r) >> 8;
+ found = upb_inttable_lookup(&t->groups, groupnum, &v);
+ UPB_ASSERT(found);
+ return upb_value_getptr(v);
+}
+
+/* If the group leader for this object's group has not previously been set,
+ * the given object is assigned to be its leader. */
+static upb_refcounted *groupleader(tarjan *t, upb_refcounted *r) {
+ uint64_t leader_slot;
+ upb_value v;
+ bool found;
+
+ UPB_ASSERT(color(t, r) == WHITE);
+ leader_slot = (getattr(t, r) >> 8) + 1;
+ found = upb_inttable_lookup(&t->groups, leader_slot, &v);
+ UPB_ASSERT(found);
+ if (upb_value_getptr(v)) {
+ return upb_value_getptr(v);
+ } else {
+ upb_inttable_remove(&t->groups, leader_slot, NULL);
+ upb_inttable_insert(&t->groups, leader_slot, upb_value_ptr(r));
+ return r;
+ }
+}
+
+
+/* Tarjan's algorithm --------------------------------------------------------*/
+
+/* See:
+ * http://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm */
+static void do_tarjan(const upb_refcounted *obj, tarjan *t);
+
+static void tarjan_visit(const upb_refcounted *obj,
+ const upb_refcounted *subobj,
+ void *closure) {
+ tarjan *t = closure;
+ if (++t->depth > t->maxdepth) {
+ upb_status_seterrf(t->status, "graph too deep to freeze (%d)", t->maxdepth);
+ err(t);
+ } else if (subobj->is_frozen || color(t, subobj) == WHITE) {
+ /* Do nothing: we don't want to visit or color already-frozen nodes,
+ * and WHITE nodes have already been assigned a SCC. */
+ } else if (color(t, subobj) < GREEN) {
+ /* Subdef has not yet been visited; recurse on it. */
+ do_tarjan(subobj, t);
+ set_lowlink(t, obj, UPB_MIN(lowlink(t, obj), lowlink(t, subobj)));
+ } else if (color(t, subobj) == GREEN) {
+ /* Subdef is in the stack and hence in the current SCC. */
+ set_lowlink(t, obj, UPB_MIN(lowlink(t, obj), idx(t, subobj)));
+ }
+ --t->depth;
+}
+
+static void do_tarjan(const upb_refcounted *obj, tarjan *t) {
+ if (color(t, obj) == BLACK) {
+ /* We haven't seen this object's group; mark the whole group GRAY. */
+ const upb_refcounted *o = obj;
+ do { set_gray(t, o); } while ((o = o->next) != obj);
+ }
+
+ push(t, obj);
+ visit(obj, tarjan_visit, t);
+ if (lowlink(t, obj) == idx(t, obj)) {
+ tarjan_newgroup(t);
+ while (pop(t) != obj)
+ ;
+ }
+}
+
+
+/* freeze() ------------------------------------------------------------------*/
+
+static void crossref(const upb_refcounted *r, const upb_refcounted *subobj,
+ void *_t) {
+ tarjan *t = _t;
+ UPB_ASSERT(color(t, r) > BLACK);
+ if (color(t, subobj) > BLACK && r->group != subobj->group) {
+ /* Previously this ref was not reflected in subobj->group because they
+ * were in the same group; now that they are split a ref must be taken. */
+ refgroup(subobj->group);
+ }
+}
+
+static bool freeze(upb_refcounted *const*roots, int n, upb_status *s,
+ int maxdepth) {
+ volatile bool ret = false;
+ int i;
+ upb_inttable_iter iter;
+
+ /* We run in two passes so that we can allocate all memory before performing
+ * any mutation of the input -- this allows us to leave the input unchanged
+ * in the case of memory allocation failure. */
+ tarjan t;
+ t.index = 0;
+ t.depth = 0;
+ t.maxdepth = maxdepth;
+ t.status = s;
+ if (!upb_inttable_init(&t.objattr, UPB_CTYPE_UINT64)) goto err1;
+ if (!upb_inttable_init(&t.stack, UPB_CTYPE_PTR)) goto err2;
+ if (!upb_inttable_init(&t.groups, UPB_CTYPE_PTR)) goto err3;
+ if (setjmp(t.err) != 0) goto err4;
+
+
+ for (i = 0; i < n; i++) {
+ if (color(&t, roots[i]) < GREEN) {
+ do_tarjan(roots[i], &t);
+ }
+ }
+
+ /* If we've made it this far, no further errors are possible so it's safe to
+ * mutate the objects without risk of leaving them in an inconsistent state. */
+ ret = true;
+
+ /* The transformation that follows requires care. The preconditions are:
+ * - all objects in attr map are WHITE or GRAY, and are in mutable groups
+ * (groups of all mutable objs)
+ * - no ref2(to, from) refs have incremented count(to) if both "to" and
+ * "from" are in our attr map (this follows from invariants (2) and (3)) */
+
+ /* Pass 1: we remove WHITE objects from their mutable groups, and add them to
+ * new groups according to the SCC's we computed. These new groups will
+ * consist of only frozen objects. None will be immediately collectible,
+ * because WHITE objects are by definition reachable from one of "roots",
+ * which the caller must own refs on. */
+ upb_inttable_begin(&iter, &t.objattr);
+ for(; !upb_inttable_done(&iter); upb_inttable_next(&iter)) {
+ upb_refcounted *obj = (upb_refcounted*)upb_inttable_iter_key(&iter);
+ /* Since removal from a singly-linked list requires access to the object's
+ * predecessor, we consider obj->next instead of obj for moving. With the
+ * while() loop we guarantee that we will visit every node's predecessor.
+ * Proof:
+ * 1. every node's predecessor is in our attr map.
+ * 2. though the loop body may change a node's predecessor, it will only
+ * change it to be the node we are currently operating on, so with a
+ * while() loop we guarantee ourselves the chance to remove each node. */
+ while (color(&t, obj->next) == WHITE &&
+ group(&t, obj->next) != obj->next->group) {
+ upb_refcounted *leader;
+
+ /* Remove from old group. */
+ upb_refcounted *move = obj->next;
+ if (obj == move) {
+ /* Removing the last object from a group. */
+ UPB_ASSERT(*obj->group == obj->individual_count);
+ upb_gfree(obj->group);
+ } else {
+ obj->next = move->next;
+ /* This may decrease to zero; we'll collect GRAY objects (if any) that
+ * remain in the group in the third pass. */
+ UPB_ASSERT(*move->group >= move->individual_count);
+ *move->group -= move->individual_count;
+ }
+
+ /* Add to new group. */
+ leader = groupleader(&t, move);
+ if (move == leader) {
+ /* First object added to new group is its leader. */
+ move->group = group(&t, move);
+ move->next = move;
+ *move->group = move->individual_count;
+ } else {
+ /* Group already has at least one object in it. */
+ UPB_ASSERT(leader->group == group(&t, move));
+ move->group = group(&t, move);
+ move->next = leader->next;
+ leader->next = move;
+ *move->group += move->individual_count;
+ }
+
+ move->is_frozen = true;
+ }
+ }
+
+ /* Pass 2: GRAY and WHITE objects "obj" with ref2(to, obj) references must
+ * increment count(to) if group(obj) != group(to) (which could now be the
+ * case if "to" was just frozen). */
+ upb_inttable_begin(&iter, &t.objattr);
+ for(; !upb_inttable_done(&iter); upb_inttable_next(&iter)) {
+ upb_refcounted *obj = (upb_refcounted*)upb_inttable_iter_key(&iter);
+ visit(obj, crossref, &t);
+ }
+
+ /* Pass 3: GRAY objects are collected if their group's refcount dropped to
+ * zero when we removed its white nodes. This can happen if they had only
+ * been kept alive by virtue of sharing a group with an object that was just
+ * frozen.
+ *
+ * It is important that we do this last, since the GRAY object's free()
+ * function could call unref2() on just-frozen objects, which will decrement
+ * refs that were added in pass 2. */
+ upb_inttable_begin(&iter, &t.objattr);
+ for(; !upb_inttable_done(&iter); upb_inttable_next(&iter)) {
+ upb_refcounted *obj = (upb_refcounted*)upb_inttable_iter_key(&iter);
+ if (obj->group == NULL || *obj->group == 0) {
+ if (obj->group) {
+ upb_refcounted *o;
+
+ /* We eagerly free() the group's count (since we can't easily determine
+ * the group's remaining size it's the easiest way to ensure it gets
+ * done). */
+ upb_gfree(obj->group);
+
+ /* Visit to release ref2's (done in a separate pass since release_ref2
+ * depends on o->group being unmodified so it can test merged()). */
+ o = obj;
+ do { visit(o, release_ref2, NULL); } while ((o = o->next) != obj);
+
+ /* Mark "group" fields as NULL so we know to free the objects later in
+ * this loop, but also don't try to delete the group twice. */
+ o = obj;
+ do { o->group = NULL; } while ((o = o->next) != obj);
+ }
+ freeobj(obj);
+ }
+ }
+
+err4:
+ if (!ret) {
+ upb_inttable_begin(&iter, &t.groups);
+ for(; !upb_inttable_done(&iter); upb_inttable_next(&iter))
+ upb_gfree(upb_value_getptr(upb_inttable_iter_value(&iter)));
+ }
+ upb_inttable_uninit(&t.groups);
+err3:
+ upb_inttable_uninit(&t.stack);
+err2:
+ upb_inttable_uninit(&t.objattr);
+err1:
+ return ret;
+}
+
+
+/* Misc internal functions ***************************************************/
+
+static bool merged(const upb_refcounted *r, const upb_refcounted *r2) {
+ return r->group == r2->group;
+}
+
+static void merge(upb_refcounted *r, upb_refcounted *from) {
+ upb_refcounted *base;
+ upb_refcounted *tmp;
+
+ if (merged(r, from)) return;
+ *r->group += *from->group;
+ upb_gfree(from->group);
+ base = from;
+
+ /* Set all refcount pointers in the "from" chain to the merged refcount.
+ *
+ * TODO(haberman): this linear algorithm can result in an overall O(n^2) bound
+ * if the user continuously extends a group by one object. Prevent this by
+ * using one of the techniques in this paper:
+ * http://bioinfo.ict.ac.cn/~dbu/AlgorithmCourses/Lectures/Union-Find-Tarjan.pdf */
+ do { from->group = r->group; } while ((from = from->next) != base);
+
+ /* Merge the two circularly linked lists by swapping their next pointers. */
+ tmp = r->next;
+ r->next = base->next;
+ base->next = tmp;
+}
+
+static void unref(const upb_refcounted *r);
+
+static void release_ref2(const upb_refcounted *obj,
+ const upb_refcounted *subobj,
+ void *closure) {
+ UPB_UNUSED(closure);
+ untrack(subobj, obj, true);
+ if (!merged(obj, subobj)) {
+ UPB_ASSERT(subobj->is_frozen);
+ unref(subobj);
+ }
+}
+
+static void unref(const upb_refcounted *r) {
+ if (unrefgroup(r->group)) {
+ const upb_refcounted *o;
+
+ upb_gfree(r->group);
+
+ /* In two passes, since release_ref2 needs a guarantee that any subobjs
+ * are alive. */
+ o = r;
+ do { visit(o, release_ref2, NULL); } while((o = o->next) != r);
+
+ o = r;
+ do {
+ const upb_refcounted *next = o->next;
+ UPB_ASSERT(o->is_frozen || o->individual_count == 0);
+ freeobj((upb_refcounted*)o);
+ o = next;
+ } while(o != r);
+ }
+}
+
+static void freeobj(upb_refcounted *o) {
+ trackfree(o);
+ o->vtbl->free((upb_refcounted*)o);
+}
+
+
+/* Public interface ***********************************************************/
+
+bool upb_refcounted_init(upb_refcounted *r,
+ const struct upb_refcounted_vtbl *vtbl,
+ const void *owner) {
+#ifndef NDEBUG
+ /* Endianness check. This is unrelated to upb_refcounted, it's just a
+ * convenient place to put the check that we can be assured will run for
+ * basically every program using upb. */
+ const int x = 1;
+#ifdef UPB_BIG_ENDIAN
+ UPB_ASSERT(*(char*)&x != 1);
+#else
+ UPB_ASSERT(*(char*)&x == 1);
+#endif
+#endif
+
+ r->next = r;
+ r->vtbl = vtbl;
+ r->individual_count = 0;
+ r->is_frozen = false;
+ r->group = upb_gmalloc(sizeof(*r->group));
+ if (!r->group) return false;
+ *r->group = 0;
+ trackinit(r);
+ upb_refcounted_ref(r, owner);
+ return true;
+}
+
+bool upb_refcounted_isfrozen(const upb_refcounted *r) {
+ return r->is_frozen;
+}
+
+void upb_refcounted_ref(const upb_refcounted *r, const void *owner) {
+ track(r, owner, false);
+ if (!r->is_frozen)
+ ((upb_refcounted*)r)->individual_count++;
+ refgroup(r->group);
+}
+
+void upb_refcounted_unref(const upb_refcounted *r, const void *owner) {
+ untrack(r, owner, false);
+ if (!r->is_frozen)
+ ((upb_refcounted*)r)->individual_count--;
+ unref(r);
+}
+
+void upb_refcounted_ref2(const upb_refcounted *r, upb_refcounted *from) {
+ UPB_ASSERT(!from->is_frozen); /* Non-const pointer implies this. */
+ track(r, from, true);
+ if (r->is_frozen) {
+ refgroup(r->group);
+ } else {
+ merge((upb_refcounted*)r, from);
+ }
+}
+
+void upb_refcounted_unref2(const upb_refcounted *r, upb_refcounted *from) {
+ UPB_ASSERT(!from->is_frozen); /* Non-const pointer implies this. */
+ untrack(r, from, true);
+ if (r->is_frozen) {
+ unref(r);
+ } else {
+ UPB_ASSERT(merged(r, from));
+ }
+}
+
+void upb_refcounted_donateref(
+ const upb_refcounted *r, const void *from, const void *to) {
+ UPB_ASSERT(from != to);
+ if (to != NULL)
+ upb_refcounted_ref(r, to);
+ if (from != NULL)
+ upb_refcounted_unref(r, from);
+}
+
+void upb_refcounted_checkref(const upb_refcounted *r, const void *owner) {
+ checkref(r, owner, false);
+}
+
+bool upb_refcounted_freeze(upb_refcounted *const*roots, int n, upb_status *s,
+ int maxdepth) {
+ int i;
+ bool ret;
+ for (i = 0; i < n; i++) {
+ UPB_ASSERT(!roots[i]->is_frozen);
+ }
+ ret = freeze(roots, n, s, maxdepth);
+ UPB_ASSERT(!s || ret == upb_ok(s));
+ return ret;
+}
+
+
+bool upb_bufsrc_putbuf(const char *buf, size_t len, upb_bytessink *sink) {
+ void *subc;
+ bool ret;
+ upb_bufhandle handle;
+ upb_bufhandle_init(&handle);
+ upb_bufhandle_setbuf(&handle, buf, 0);
+ ret = upb_bytessink_start(sink, len, &subc);
+ if (ret && len != 0) {
+ ret = (upb_bytessink_putbuf(sink, subc, buf, len, &handle) >= len);
+ }
+ if (ret) {
+ ret = upb_bytessink_end(sink);
+ }
+ upb_bufhandle_uninit(&handle);
+ return ret;
+}
+
+struct upb_bufsink {
+ upb_byteshandler handler;
+ upb_bytessink sink;
+ upb_env *env;
+ char *ptr;
+ size_t len, size;
+};
+
+static void *upb_bufsink_start(void *_sink, const void *hd, size_t size_hint) {
+ upb_bufsink *sink = _sink;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(size_hint);
+ sink->len = 0;
+ return sink;
+}
+
+static size_t upb_bufsink_string(void *_sink, const void *hd, const char *ptr,
+ size_t len, const upb_bufhandle *handle) {
+ upb_bufsink *sink = _sink;
+ size_t new_size = sink->size;
+
+ UPB_ASSERT(new_size > 0);
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ while (sink->len + len > new_size) {
+ new_size *= 2;
+ }
+
+ if (new_size != sink->size) {
+ sink->ptr = upb_env_realloc(sink->env, sink->ptr, sink->size, new_size);
+ sink->size = new_size;
+ }
+
+ memcpy(sink->ptr + sink->len, ptr, len);
+ sink->len += len;
+
+ return len;
+}
+
+upb_bufsink *upb_bufsink_new(upb_env *env) {
+ upb_bufsink *sink = upb_env_malloc(env, sizeof(upb_bufsink));
+ upb_byteshandler_init(&sink->handler);
+ upb_byteshandler_setstartstr(&sink->handler, upb_bufsink_start, NULL);
+ upb_byteshandler_setstring(&sink->handler, upb_bufsink_string, NULL);
+
+ upb_bytessink_reset(&sink->sink, &sink->handler, sink);
+
+ sink->env = env;
+ sink->size = 32;
+ sink->ptr = upb_env_malloc(env, sink->size);
+ sink->len = 0;
+
+ return sink;
+}
+
+void upb_bufsink_free(upb_bufsink *sink) {
+ upb_env_free(sink->env, sink->ptr);
+ upb_env_free(sink->env, sink);
+}
+
+upb_bytessink *upb_bufsink_sink(upb_bufsink *sink) {
+ return &sink->sink;
+}
+
+const char *upb_bufsink_getdata(const upb_bufsink *sink, size_t *len) {
+ *len = sink->len;
+ return sink->ptr;
+}
+/*
+** upb_table Implementation
+**
+** Implementation is heavily inspired by Lua's ltable.c.
+*/
+
+
+#include <string.h>
+
+#define UPB_MAXARRSIZE 16 /* 64k. */
+
+/* From Chromium. */
+#define ARRAY_SIZE(x) \
+ ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
+
+static void upb_check_alloc(upb_table *t, upb_alloc *a) {
+ UPB_UNUSED(t);
+ UPB_UNUSED(a);
+ UPB_ASSERT_DEBUGVAR(t->alloc == a);
+}
+
+static const double MAX_LOAD = 0.85;
+
+/* The minimum utilization of the array part of a mixed hash/array table. This
+ * is a speed/memory-usage tradeoff (though it's not straightforward because of
+ * cache effects). The lower this is, the more memory we'll use. */
+static const double MIN_DENSITY = 0.1;
+
+bool is_pow2(uint64_t v) { return v == 0 || (v & (v - 1)) == 0; }
+
+int log2ceil(uint64_t v) {
+ int ret = 0;
+ bool pow2 = is_pow2(v);
+ while (v >>= 1) ret++;
+ ret = pow2 ? ret : ret + 1; /* Ceiling. */
+ return UPB_MIN(UPB_MAXARRSIZE, ret);
+}
+
+char *upb_strdup(const char *s, upb_alloc *a) {
+ return upb_strdup2(s, strlen(s), a);
+}
+
+char *upb_strdup2(const char *s, size_t len, upb_alloc *a) {
+ size_t n;
+ char *p;
+
+ /* Prevent overflow errors. */
+ if (len == SIZE_MAX) return NULL;
+ /* Always null-terminate, even if binary data; but don't rely on the input to
+ * have a null-terminating byte since it may be a raw binary buffer. */
+ n = len + 1;
+ p = upb_malloc(a, n);
+ if (p) {
+ memcpy(p, s, len);
+ p[len] = 0;
+ }
+ return p;
+}
+
+/* A type to represent the lookup key of either a strtable or an inttable. */
+typedef union {
+ uintptr_t num;
+ struct {
+ const char *str;
+ size_t len;
+ } str;
+} lookupkey_t;
+
+static lookupkey_t strkey2(const char *str, size_t len) {
+ lookupkey_t k;
+ k.str.str = str;
+ k.str.len = len;
+ return k;
+}
+
+static lookupkey_t intkey(uintptr_t key) {
+ lookupkey_t k;
+ k.num = key;
+ return k;
+}
+
+typedef uint32_t hashfunc_t(upb_tabkey key);
+typedef bool eqlfunc_t(upb_tabkey k1, lookupkey_t k2);
+
+/* Base table (shared code) ***************************************************/
+
+/* For when we need to cast away const. */
+static upb_tabent *mutable_entries(upb_table *t) {
+ return (upb_tabent*)t->entries;
+}
+
+static bool isfull(upb_table *t) {
+ if (upb_table_size(t) == 0) {
+ return true;
+ } else {
+ return ((double)(t->count + 1) / upb_table_size(t)) > MAX_LOAD;
+ }
+}
+
+static bool init(upb_table *t, upb_ctype_t ctype, uint8_t size_lg2,
+ upb_alloc *a) {
+ size_t bytes;
+
+ t->count = 0;
+ t->ctype = ctype;
+ t->size_lg2 = size_lg2;
+ t->mask = upb_table_size(t) ? upb_table_size(t) - 1 : 0;
+#ifndef NDEBUG
+ t->alloc = a;
+#endif
+ bytes = upb_table_size(t) * sizeof(upb_tabent);
+ if (bytes > 0) {
+ t->entries = upb_malloc(a, bytes);
+ if (!t->entries) return false;
+ memset(mutable_entries(t), 0, bytes);
+ } else {
+ t->entries = NULL;
+ }
+ return true;
+}
+
+static void uninit(upb_table *t, upb_alloc *a) {
+ upb_check_alloc(t, a);
+ upb_free(a, mutable_entries(t));
+}
+
+static upb_tabent *emptyent(upb_table *t) {
+ upb_tabent *e = mutable_entries(t) + upb_table_size(t);
+ while (1) { if (upb_tabent_isempty(--e)) return e; UPB_ASSERT(e > t->entries); }
+}
+
+static upb_tabent *getentry_mutable(upb_table *t, uint32_t hash) {
+ return (upb_tabent*)upb_getentry(t, hash);
+}
+
+static const upb_tabent *findentry(const upb_table *t, lookupkey_t key,
+ uint32_t hash, eqlfunc_t *eql) {
+ const upb_tabent *e;
+
+ if (t->size_lg2 == 0) return NULL;
+ e = upb_getentry(t, hash);
+ if (upb_tabent_isempty(e)) return NULL;
+ while (1) {
+ if (eql(e->key, key)) return e;
+ if ((e = e->next) == NULL) return NULL;
+ }
+}
+
+static upb_tabent *findentry_mutable(upb_table *t, lookupkey_t key,
+ uint32_t hash, eqlfunc_t *eql) {
+ return (upb_tabent*)findentry(t, key, hash, eql);
+}
+
+static bool lookup(const upb_table *t, lookupkey_t key, upb_value *v,
+ uint32_t hash, eqlfunc_t *eql) {
+ const upb_tabent *e = findentry(t, key, hash, eql);
+ if (e) {
+ if (v) {
+ _upb_value_setval(v, e->val.val, t->ctype);
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/* The given key must not already exist in the table. */
+static void insert(upb_table *t, lookupkey_t key, upb_tabkey tabkey,
+ upb_value val, uint32_t hash,
+ hashfunc_t *hashfunc, eqlfunc_t *eql) {
+ upb_tabent *mainpos_e;
+ upb_tabent *our_e;
+
+ UPB_ASSERT(findentry(t, key, hash, eql) == NULL);
+ UPB_ASSERT_DEBUGVAR(val.ctype == t->ctype);
+
+ t->count++;
+ mainpos_e = getentry_mutable(t, hash);
+ our_e = mainpos_e;
+
+ if (upb_tabent_isempty(mainpos_e)) {
+ /* Our main position is empty; use it. */
+ our_e->next = NULL;
+ } else {
+ /* Collision. */
+ upb_tabent *new_e = emptyent(t);
+ /* Head of collider's chain. */
+ upb_tabent *chain = getentry_mutable(t, hashfunc(mainpos_e->key));
+ if (chain == mainpos_e) {
+ /* Existing ent is in its main posisiton (it has the same hash as us, and
+ * is the head of our chain). Insert to new ent and append to this chain. */
+ new_e->next = mainpos_e->next;
+ mainpos_e->next = new_e;
+ our_e = new_e;
+ } else {
+ /* Existing ent is not in its main position (it is a node in some other
+ * chain). This implies that no existing ent in the table has our hash.
+ * Evict it (updating its chain) and use its ent for head of our chain. */
+ *new_e = *mainpos_e; /* copies next. */
+ while (chain->next != mainpos_e) {
+ chain = (upb_tabent*)chain->next;
+ UPB_ASSERT(chain);
+ }
+ chain->next = new_e;
+ our_e = mainpos_e;
+ our_e->next = NULL;
+ }
+ }
+ our_e->key = tabkey;
+ our_e->val.val = val.val;
+ UPB_ASSERT(findentry(t, key, hash, eql) == our_e);
+}
+
+static bool rm(upb_table *t, lookupkey_t key, upb_value *val,
+ upb_tabkey *removed, uint32_t hash, eqlfunc_t *eql) {
+ upb_tabent *chain = getentry_mutable(t, hash);
+ if (upb_tabent_isempty(chain)) return false;
+ if (eql(chain->key, key)) {
+ /* Element to remove is at the head of its chain. */
+ t->count--;
+ if (val) _upb_value_setval(val, chain->val.val, t->ctype);
+ if (removed) *removed = chain->key;
+ if (chain->next) {
+ upb_tabent *move = (upb_tabent*)chain->next;
+ *chain = *move;
+ move->key = 0; /* Make the slot empty. */
+ } else {
+ chain->key = 0; /* Make the slot empty. */
+ }
+ return true;
+ } else {
+ /* Element to remove is either in a non-head position or not in the
+ * table. */
+ while (chain->next && !eql(chain->next->key, key)) {
+ chain = (upb_tabent*)chain->next;
+ }
+ if (chain->next) {
+ /* Found element to remove. */
+ upb_tabent *rm = (upb_tabent*)chain->next;
+ t->count--;
+ if (val) _upb_value_setval(val, chain->next->val.val, t->ctype);
+ if (removed) *removed = rm->key;
+ rm->key = 0; /* Make the slot empty. */
+ chain->next = rm->next;
+ return true;
+ } else {
+ /* Element to remove is not in the table. */
+ return false;
+ }
+ }
+}
+
+static size_t next(const upb_table *t, size_t i) {
+ do {
+ if (++i >= upb_table_size(t))
+ return SIZE_MAX;
+ } while(upb_tabent_isempty(&t->entries[i]));
+
+ return i;
+}
+
+static size_t begin(const upb_table *t) {
+ return next(t, -1);
+}
+
+
+/* upb_strtable ***************************************************************/
+
+/* A simple "subclass" of upb_table that only adds a hash function for strings. */
+
+static upb_tabkey strcopy(lookupkey_t k2, upb_alloc *a) {
+ char *str = upb_malloc(a, k2.str.len + sizeof(uint32_t) + 1);
+ if (str == NULL) return 0;
+ memcpy(str, &k2.str.len, sizeof(uint32_t));
+ memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len + 1);
+ return (uintptr_t)str;
+}
+
+static uint32_t strhash(upb_tabkey key) {
+ uint32_t len;
+ char *str = upb_tabstr(key, &len);
+ return MurmurHash2(str, len, 0);
+}
+
+static bool streql(upb_tabkey k1, lookupkey_t k2) {
+ uint32_t len;
+ char *str = upb_tabstr(k1, &len);
+ return len == k2.str.len && memcmp(str, k2.str.str, len) == 0;
+}
+
+bool upb_strtable_init2(upb_strtable *t, upb_ctype_t ctype, upb_alloc *a) {
+ return init(&t->t, ctype, 2, a);
+}
+
+void upb_strtable_uninit2(upb_strtable *t, upb_alloc *a) {
+ size_t i;
+ for (i = 0; i < upb_table_size(&t->t); i++)
+ upb_free(a, (void*)t->t.entries[i].key);
+ uninit(&t->t, a);
+}
+
+bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_alloc *a) {
+ upb_strtable new_table;
+ upb_strtable_iter i;
+
+ upb_check_alloc(&t->t, a);
+
+ if (!init(&new_table.t, t->t.ctype, size_lg2, a))
+ return false;
+ upb_strtable_begin(&i, t);
+ for ( ; !upb_strtable_done(&i); upb_strtable_next(&i)) {
+ upb_strtable_insert3(
+ &new_table,
+ upb_strtable_iter_key(&i),
+ upb_strtable_iter_keylength(&i),
+ upb_strtable_iter_value(&i),
+ a);
+ }
+ upb_strtable_uninit2(t, a);
+ *t = new_table;
+ return true;
+}
+
+bool upb_strtable_insert3(upb_strtable *t, const char *k, size_t len,
+ upb_value v, upb_alloc *a) {
+ lookupkey_t key;
+ upb_tabkey tabkey;
+ uint32_t hash;
+
+ upb_check_alloc(&t->t, a);
+
+ if (isfull(&t->t)) {
+ /* Need to resize. New table of double the size, add old elements to it. */
+ if (!upb_strtable_resize(t, t->t.size_lg2 + 1, a)) {
+ return false;
+ }
+ }
+
+ key = strkey2(k, len);
+ tabkey = strcopy(key, a);
+ if (tabkey == 0) return false;
+
+ hash = MurmurHash2(key.str.str, key.str.len, 0);
+ insert(&t->t, key, tabkey, v, hash, &strhash, &streql);
+ return true;
+}
+
+bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len,
+ upb_value *v) {
+ uint32_t hash = MurmurHash2(key, len, 0);
+ return lookup(&t->t, strkey2(key, len), v, hash, &streql);
+}
+
+bool upb_strtable_remove3(upb_strtable *t, const char *key, size_t len,
+ upb_value *val, upb_alloc *alloc) {
+ uint32_t hash = MurmurHash2(key, len, 0);
+ upb_tabkey tabkey;
+ if (rm(&t->t, strkey2(key, len), val, &tabkey, hash, &streql)) {
+ upb_free(alloc, (void*)tabkey);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/* Iteration */
+
+static const upb_tabent *str_tabent(const upb_strtable_iter *i) {
+ return &i->t->t.entries[i->index];
+}
+
+void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t) {
+ i->t = t;
+ i->index = begin(&t->t);
+}
+
+void upb_strtable_next(upb_strtable_iter *i) {
+ i->index = next(&i->t->t, i->index);
+}
+
+bool upb_strtable_done(const upb_strtable_iter *i) {
+ return i->index >= upb_table_size(&i->t->t) ||
+ upb_tabent_isempty(str_tabent(i));
+}
+
+const char *upb_strtable_iter_key(const upb_strtable_iter *i) {
+ UPB_ASSERT(!upb_strtable_done(i));
+ return upb_tabstr(str_tabent(i)->key, NULL);
+}
+
+size_t upb_strtable_iter_keylength(const upb_strtable_iter *i) {
+ uint32_t len;
+ UPB_ASSERT(!upb_strtable_done(i));
+ upb_tabstr(str_tabent(i)->key, &len);
+ return len;
+}
+
+upb_value upb_strtable_iter_value(const upb_strtable_iter *i) {
+ UPB_ASSERT(!upb_strtable_done(i));
+ return _upb_value_val(str_tabent(i)->val.val, i->t->t.ctype);
+}
+
+void upb_strtable_iter_setdone(upb_strtable_iter *i) {
+ i->index = SIZE_MAX;
+}
+
+bool upb_strtable_iter_isequal(const upb_strtable_iter *i1,
+ const upb_strtable_iter *i2) {
+ if (upb_strtable_done(i1) && upb_strtable_done(i2))
+ return true;
+ return i1->t == i2->t && i1->index == i2->index;
+}
+
+
+/* upb_inttable ***************************************************************/
+
+/* For inttables we use a hybrid structure where small keys are kept in an
+ * array and large keys are put in the hash table. */
+
+static uint32_t inthash(upb_tabkey key) { return upb_inthash(key); }
+
+static bool inteql(upb_tabkey k1, lookupkey_t k2) {
+ return k1 == k2.num;
+}
+
+static upb_tabval *mutable_array(upb_inttable *t) {
+ return (upb_tabval*)t->array;
+}
+
+static upb_tabval *inttable_val(upb_inttable *t, uintptr_t key) {
+ if (key < t->array_size) {
+ return upb_arrhas(t->array[key]) ? &(mutable_array(t)[key]) : NULL;
+ } else {
+ upb_tabent *e =
+ findentry_mutable(&t->t, intkey(key), upb_inthash(key), &inteql);
+ return e ? &e->val : NULL;
+ }
+}
+
+static const upb_tabval *inttable_val_const(const upb_inttable *t,
+ uintptr_t key) {
+ return inttable_val((upb_inttable*)t, key);
+}
+
+size_t upb_inttable_count(const upb_inttable *t) {
+ return t->t.count + t->array_count;
+}
+
+static void check(upb_inttable *t) {
+ UPB_UNUSED(t);
+#if defined(UPB_DEBUG_TABLE) && !defined(NDEBUG)
+ {
+ /* This check is very expensive (makes inserts/deletes O(N)). */
+ size_t count = 0;
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, t);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i), count++) {
+ UPB_ASSERT(upb_inttable_lookup(t, upb_inttable_iter_key(&i), NULL));
+ }
+ UPB_ASSERT(count == upb_inttable_count(t));
+ }
+#endif
+}
+
+bool upb_inttable_sizedinit(upb_inttable *t, upb_ctype_t ctype,
+ size_t asize, int hsize_lg2, upb_alloc *a) {
+ size_t array_bytes;
+
+ if (!init(&t->t, ctype, hsize_lg2, a)) return false;
+ /* Always make the array part at least 1 long, so that we know key 0
+ * won't be in the hash part, which simplifies things. */
+ t->array_size = UPB_MAX(1, asize);
+ t->array_count = 0;
+ array_bytes = t->array_size * sizeof(upb_value);
+ t->array = upb_malloc(a, array_bytes);
+ if (!t->array) {
+ uninit(&t->t, a);
+ return false;
+ }
+ memset(mutable_array(t), 0xff, array_bytes);
+ check(t);
+ return true;
+}
+
+bool upb_inttable_init2(upb_inttable *t, upb_ctype_t ctype, upb_alloc *a) {
+ return upb_inttable_sizedinit(t, ctype, 0, 4, a);
+}
+
+void upb_inttable_uninit2(upb_inttable *t, upb_alloc *a) {
+ uninit(&t->t, a);
+ upb_free(a, mutable_array(t));
+}
+
+bool upb_inttable_insert2(upb_inttable *t, uintptr_t key, upb_value val,
+ upb_alloc *a) {
+ upb_tabval tabval;
+ tabval.val = val.val;
+ UPB_ASSERT(upb_arrhas(tabval)); /* This will reject (uint64_t)-1. Fix this. */
+
+ upb_check_alloc(&t->t, a);
+
+ if (key < t->array_size) {
+ UPB_ASSERT(!upb_arrhas(t->array[key]));
+ t->array_count++;
+ mutable_array(t)[key].val = val.val;
+ } else {
+ if (isfull(&t->t)) {
+ /* Need to resize the hash part, but we re-use the array part. */
+ size_t i;
+ upb_table new_table;
+
+ if (!init(&new_table, t->t.ctype, t->t.size_lg2 + 1, a)) {
+ return false;
+ }
+
+ for (i = begin(&t->t); i < upb_table_size(&t->t); i = next(&t->t, i)) {
+ const upb_tabent *e = &t->t.entries[i];
+ uint32_t hash;
+ upb_value v;
+
+ _upb_value_setval(&v, e->val.val, t->t.ctype);
+ hash = upb_inthash(e->key);
+ insert(&new_table, intkey(e->key), e->key, v, hash, &inthash, &inteql);
+ }
+
+ UPB_ASSERT(t->t.count == new_table.count);
+
+ uninit(&t->t, a);
+ t->t = new_table;
+ }
+ insert(&t->t, intkey(key), key, val, upb_inthash(key), &inthash, &inteql);
+ }
+ check(t);
+ return true;
+}
+
+bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v) {
+ const upb_tabval *table_v = inttable_val_const(t, key);
+ if (!table_v) return false;
+ if (v) _upb_value_setval(v, table_v->val, t->t.ctype);
+ return true;
+}
+
+bool upb_inttable_replace(upb_inttable *t, uintptr_t key, upb_value val) {
+ upb_tabval *table_v = inttable_val(t, key);
+ if (!table_v) return false;
+ table_v->val = val.val;
+ return true;
+}
+
+bool upb_inttable_remove(upb_inttable *t, uintptr_t key, upb_value *val) {
+ bool success;
+ if (key < t->array_size) {
+ if (upb_arrhas(t->array[key])) {
+ upb_tabval empty = UPB_TABVALUE_EMPTY_INIT;
+ t->array_count--;
+ if (val) {
+ _upb_value_setval(val, t->array[key].val, t->t.ctype);
+ }
+ mutable_array(t)[key] = empty;
+ success = true;
+ } else {
+ success = false;
+ }
+ } else {
+ success = rm(&t->t, intkey(key), val, NULL, upb_inthash(key), &inteql);
+ }
+ check(t);
+ return success;
+}
+
+bool upb_inttable_push2(upb_inttable *t, upb_value val, upb_alloc *a) {
+ upb_check_alloc(&t->t, a);
+ return upb_inttable_insert2(t, upb_inttable_count(t), val, a);
+}
+
+upb_value upb_inttable_pop(upb_inttable *t) {
+ upb_value val;
+ bool ok = upb_inttable_remove(t, upb_inttable_count(t) - 1, &val);
+ UPB_ASSERT(ok);
+ return val;
+}
+
+bool upb_inttable_insertptr2(upb_inttable *t, const void *key, upb_value val,
+ upb_alloc *a) {
+ upb_check_alloc(&t->t, a);
+ return upb_inttable_insert2(t, (uintptr_t)key, val, a);
+}
+
+bool upb_inttable_lookupptr(const upb_inttable *t, const void *key,
+ upb_value *v) {
+ return upb_inttable_lookup(t, (uintptr_t)key, v);
+}
+
+bool upb_inttable_removeptr(upb_inttable *t, const void *key, upb_value *val) {
+ return upb_inttable_remove(t, (uintptr_t)key, val);
+}
+
+void upb_inttable_compact2(upb_inttable *t, upb_alloc *a) {
+ /* A power-of-two histogram of the table keys. */
+ size_t counts[UPB_MAXARRSIZE + 1] = {0};
+
+ /* The max key in each bucket. */
+ uintptr_t max[UPB_MAXARRSIZE + 1] = {0};
+
+ upb_inttable_iter i;
+ size_t arr_count;
+ int size_lg2;
+ upb_inttable new_t;
+
+ upb_check_alloc(&t->t, a);
+
+ upb_inttable_begin(&i, t);
+ for (; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ uintptr_t key = upb_inttable_iter_key(&i);
+ int bucket = log2ceil(key);
+ max[bucket] = UPB_MAX(max[bucket], key);
+ counts[bucket]++;
+ }
+
+ /* Find the largest power of two that satisfies the MIN_DENSITY
+ * definition (while actually having some keys). */
+ arr_count = upb_inttable_count(t);
+
+ for (size_lg2 = ARRAY_SIZE(counts) - 1; size_lg2 > 0; size_lg2--) {
+ if (counts[size_lg2] == 0) {
+ /* We can halve again without losing any entries. */
+ continue;
+ } else if (arr_count >= (1 << size_lg2) * MIN_DENSITY) {
+ break;
+ }
+
+ arr_count -= counts[size_lg2];
+ }
+
+ UPB_ASSERT(arr_count <= upb_inttable_count(t));
+
+ {
+ /* Insert all elements into new, perfectly-sized table. */
+ size_t arr_size = max[size_lg2] + 1; /* +1 so arr[max] will fit. */
+ size_t hash_count = upb_inttable_count(t) - arr_count;
+ size_t hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0;
+ size_t hashsize_lg2 = log2ceil(hash_size);
+
+ upb_inttable_sizedinit(&new_t, t->t.ctype, arr_size, hashsize_lg2, a);
+ upb_inttable_begin(&i, t);
+ for (; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ uintptr_t k = upb_inttable_iter_key(&i);
+ upb_inttable_insert2(&new_t, k, upb_inttable_iter_value(&i), a);
+ }
+ UPB_ASSERT(new_t.array_size == arr_size);
+ UPB_ASSERT(new_t.t.size_lg2 == hashsize_lg2);
+ }
+ upb_inttable_uninit2(t, a);
+ *t = new_t;
+}
+
+/* Iteration. */
+
+static const upb_tabent *int_tabent(const upb_inttable_iter *i) {
+ UPB_ASSERT(!i->array_part);
+ return &i->t->t.entries[i->index];
+}
+
+static upb_tabval int_arrent(const upb_inttable_iter *i) {
+ UPB_ASSERT(i->array_part);
+ return i->t->array[i->index];
+}
+
+void upb_inttable_begin(upb_inttable_iter *i, const upb_inttable *t) {
+ i->t = t;
+ i->index = -1;
+ i->array_part = true;
+ upb_inttable_next(i);
+}
+
+void upb_inttable_next(upb_inttable_iter *iter) {
+ const upb_inttable *t = iter->t;
+ if (iter->array_part) {
+ while (++iter->index < t->array_size) {
+ if (upb_arrhas(int_arrent(iter))) {
+ return;
+ }
+ }
+ iter->array_part = false;
+ iter->index = begin(&t->t);
+ } else {
+ iter->index = next(&t->t, iter->index);
+ }
+}
+
+bool upb_inttable_done(const upb_inttable_iter *i) {
+ if (i->array_part) {
+ return i->index >= i->t->array_size ||
+ !upb_arrhas(int_arrent(i));
+ } else {
+ return i->index >= upb_table_size(&i->t->t) ||
+ upb_tabent_isempty(int_tabent(i));
+ }
+}
+
+uintptr_t upb_inttable_iter_key(const upb_inttable_iter *i) {
+ UPB_ASSERT(!upb_inttable_done(i));
+ return i->array_part ? i->index : int_tabent(i)->key;
+}
+
+upb_value upb_inttable_iter_value(const upb_inttable_iter *i) {
+ UPB_ASSERT(!upb_inttable_done(i));
+ return _upb_value_val(
+ i->array_part ? i->t->array[i->index].val : int_tabent(i)->val.val,
+ i->t->t.ctype);
+}
+
+void upb_inttable_iter_setdone(upb_inttable_iter *i) {
+ i->index = SIZE_MAX;
+ i->array_part = false;
+}
+
+bool upb_inttable_iter_isequal(const upb_inttable_iter *i1,
+ const upb_inttable_iter *i2) {
+ if (upb_inttable_done(i1) && upb_inttable_done(i2))
+ return true;
+ return i1->t == i2->t && i1->index == i2->index &&
+ i1->array_part == i2->array_part;
+}
+
+#ifdef UPB_UNALIGNED_READS_OK
+/* -----------------------------------------------------------------------------
+ * MurmurHash2, by Austin Appleby (released as public domain).
+ * Reformatted and C99-ified by Joshua Haberman.
+ * Note - This code makes a few assumptions about how your machine behaves -
+ * 1. We can read a 4-byte value from any address without crashing
+ * 2. sizeof(int) == 4 (in upb this limitation is removed by using uint32_t
+ * And it has a few limitations -
+ * 1. It will not work incrementally.
+ * 2. It will not produce the same results on little-endian and big-endian
+ * machines. */
+uint32_t MurmurHash2(const void *key, size_t len, uint32_t seed) {
+ /* 'm' and 'r' are mixing constants generated offline.
+ * They're not really 'magic', they just happen to work well. */
+ const uint32_t m = 0x5bd1e995;
+ const int32_t r = 24;
+
+ /* Initialize the hash to a 'random' value */
+ uint32_t h = seed ^ len;
+
+ /* Mix 4 bytes at a time into the hash */
+ const uint8_t * data = (const uint8_t *)key;
+ while(len >= 4) {
+ uint32_t k = *(uint32_t *)data;
+
+ k *= m;
+ k ^= k >> r;
+ k *= m;
+
+ h *= m;
+ h ^= k;
+
+ data += 4;
+ len -= 4;
+ }
+
+ /* Handle the last few bytes of the input array */
+ switch(len) {
+ case 3: h ^= data[2] << 16;
+ case 2: h ^= data[1] << 8;
+ case 1: h ^= data[0]; h *= m;
+ };
+
+ /* Do a few final mixes of the hash to ensure the last few
+ * bytes are well-incorporated. */
+ h ^= h >> 13;
+ h *= m;
+ h ^= h >> 15;
+
+ return h;
+}
+
+#else /* !UPB_UNALIGNED_READS_OK */
+
+/* -----------------------------------------------------------------------------
+ * MurmurHashAligned2, by Austin Appleby
+ * Same algorithm as MurmurHash2, but only does aligned reads - should be safer
+ * on certain platforms.
+ * Performance will be lower than MurmurHash2 */
+
+#define MIX(h,k,m) { k *= m; k ^= k >> r; k *= m; h *= m; h ^= k; }
+
+uint32_t MurmurHash2(const void * key, size_t len, uint32_t seed) {
+ const uint32_t m = 0x5bd1e995;
+ const int32_t r = 24;
+ const uint8_t * data = (const uint8_t *)key;
+ uint32_t h = seed ^ len;
+ uint8_t align = (uintptr_t)data & 3;
+
+ if(align && (len >= 4)) {
+ /* Pre-load the temp registers */
+ uint32_t t = 0, d = 0;
+ int32_t sl;
+ int32_t sr;
+
+ switch(align) {
+ case 1: t |= data[2] << 16;
+ case 2: t |= data[1] << 8;
+ case 3: t |= data[0];
+ }
+
+ t <<= (8 * align);
+
+ data += 4-align;
+ len -= 4-align;
+
+ sl = 8 * (4-align);
+ sr = 8 * align;
+
+ /* Mix */
+
+ while(len >= 4) {
+ uint32_t k;
+
+ d = *(uint32_t *)data;
+ t = (t >> sr) | (d << sl);
+
+ k = t;
+
+ MIX(h,k,m);
+
+ t = d;
+
+ data += 4;
+ len -= 4;
+ }
+
+ /* Handle leftover data in temp registers */
+
+ d = 0;
+
+ if(len >= align) {
+ uint32_t k;
+
+ switch(align) {
+ case 3: d |= data[2] << 16;
+ case 2: d |= data[1] << 8;
+ case 1: d |= data[0];
+ }
+
+ k = (t >> sr) | (d << sl);
+ MIX(h,k,m);
+
+ data += align;
+ len -= align;
+
+ /* ----------
+ * Handle tail bytes */
+
+ switch(len) {
+ case 3: h ^= data[2] << 16;
+ case 2: h ^= data[1] << 8;
+ case 1: h ^= data[0]; h *= m;
+ };
+ } else {
+ switch(len) {
+ case 3: d |= data[2] << 16;
+ case 2: d |= data[1] << 8;
+ case 1: d |= data[0];
+ case 0: h ^= (t >> sr) | (d << sl); h *= m;
+ }
+ }
+
+ h ^= h >> 13;
+ h *= m;
+ h ^= h >> 15;
+
+ return h;
+ } else {
+ while(len >= 4) {
+ uint32_t k = *(uint32_t *)data;
+
+ MIX(h,k,m);
+
+ data += 4;
+ len -= 4;
+ }
+
+ /* ----------
+ * Handle tail bytes */
+
+ switch(len) {
+ case 3: h ^= data[2] << 16;
+ case 2: h ^= data[1] << 8;
+ case 1: h ^= data[0]; h *= m;
+ };
+
+ h ^= h >> 13;
+ h *= m;
+ h ^= h >> 15;
+
+ return h;
+ }
+}
+#undef MIX
+
+#endif /* UPB_UNALIGNED_READS_OK */
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+bool upb_dumptostderr(void *closure, const upb_status* status) {
+ UPB_UNUSED(closure);
+ fprintf(stderr, "%s\n", upb_status_errmsg(status));
+ return false;
+}
+
+/* Guarantee null-termination and provide ellipsis truncation.
+ * It may be tempting to "optimize" this by initializing these final
+ * four bytes up-front and then being careful never to overwrite them,
+ * this is safer and simpler. */
+static void nullz(upb_status *status) {
+ const char *ellipsis = "...";
+ size_t len = strlen(ellipsis);
+ UPB_ASSERT(sizeof(status->msg) > len);
+ memcpy(status->msg + sizeof(status->msg) - len, ellipsis, len);
+}
+
+
+/* upb_upberr *****************************************************************/
+
+upb_errorspace upb_upberr = {"upb error"};
+
+void upb_upberr_setoom(upb_status *status) {
+ status->error_space_ = &upb_upberr;
+ upb_status_seterrmsg(status, "Out of memory");
+}
+
+
+/* upb_status *****************************************************************/
+
+void upb_status_clear(upb_status *status) {
+ if (!status) return;
+ status->ok_ = true;
+ status->code_ = 0;
+ status->msg[0] = '\0';
+}
+
+bool upb_ok(const upb_status *status) { return status->ok_; }
+
+upb_errorspace *upb_status_errspace(const upb_status *status) {
+ return status->error_space_;
+}
+
+int upb_status_errcode(const upb_status *status) { return status->code_; }
+
+const char *upb_status_errmsg(const upb_status *status) { return status->msg; }
+
+void upb_status_seterrmsg(upb_status *status, const char *msg) {
+ if (!status) return;
+ status->ok_ = false;
+ strncpy(status->msg, msg, sizeof(status->msg));
+ nullz(status);
+}
+
+void upb_status_seterrf(upb_status *status, const char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ upb_status_vseterrf(status, fmt, args);
+ va_end(args);
+}
+
+void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args) {
+ if (!status) return;
+ status->ok_ = false;
+ _upb_vsnprintf(status->msg, sizeof(status->msg), fmt, args);
+ nullz(status);
+}
+
+void upb_status_copy(upb_status *to, const upb_status *from) {
+ if (!to) return;
+ *to = *from;
+}
+
+
+/* upb_alloc ******************************************************************/
+
+static void *upb_global_allocfunc(upb_alloc *alloc, void *ptr, size_t oldsize,
+ size_t size) {
+ UPB_UNUSED(alloc);
+ UPB_UNUSED(oldsize);
+ if (size == 0) {
+ free(ptr);
+ return NULL;
+ } else {
+ return realloc(ptr, size);
+ }
+}
+
+upb_alloc upb_alloc_global = {&upb_global_allocfunc};
+
+
+/* upb_arena ******************************************************************/
+
+/* Be conservative and choose 16 in case anyone is using SSE. */
+static const size_t maxalign = 16;
+
+static size_t align_up_max(size_t size) {
+ return ((size + maxalign - 1) / maxalign) * maxalign;
+}
+
+typedef struct mem_block {
+ struct mem_block *next;
+ size_t size;
+ size_t used;
+ bool owned;
+ /* Data follows. */
+} mem_block;
+
+typedef struct cleanup_ent {
+ struct cleanup_ent *next;
+ upb_cleanup_func *cleanup;
+ void *ud;
+} cleanup_ent;
+
+static void upb_arena_addblock(upb_arena *a, void *ptr, size_t size,
+ bool owned) {
+ mem_block *block = ptr;
+
+ block->next = a->block_head;
+ block->size = size;
+ block->used = align_up_max(sizeof(mem_block));
+ block->owned = owned;
+
+ a->block_head = block;
+
+ /* TODO(haberman): ASAN poison. */
+}
+
+
+static mem_block *upb_arena_allocblock(upb_arena *a, size_t size) {
+ size_t block_size = UPB_MAX(size, a->next_block_size) + sizeof(mem_block);
+ mem_block *block = upb_malloc(a->block_alloc, block_size);
+
+ if (!block) {
+ return NULL;
+ }
+
+ upb_arena_addblock(a, block, block_size, true);
+ a->next_block_size = UPB_MIN(block_size * 2, a->max_block_size);
+
+ return block;
+}
+
+static void *upb_arena_doalloc(upb_alloc *alloc, void *ptr, size_t oldsize,
+ size_t size) {
+ upb_arena *a = (upb_arena*)alloc; /* upb_alloc is initial member. */
+ mem_block *block = a->block_head;
+ void *ret;
+
+ if (size == 0) {
+ return NULL; /* We are an arena, don't need individual frees. */
+ }
+
+ size = align_up_max(size);
+
+ /* TODO(haberman): special-case if this is a realloc of the last alloc? */
+
+ if (!block || block->size - block->used < size) {
+ /* Slow path: have to allocate a new block. */
+ block = upb_arena_allocblock(a, size);
+
+ if (!block) {
+ return NULL; /* Out of memory. */
+ }
+ }
+
+ ret = (char*)block + block->used;
+ block->used += size;
+
+ if (oldsize > 0) {
+ memcpy(ret, ptr, oldsize); /* Preserve existing data. */
+ }
+
+ /* TODO(haberman): ASAN unpoison. */
+
+ a->bytes_allocated += size;
+ return ret;
+}
+
+/* Public Arena API ***********************************************************/
+
+void upb_arena_init(upb_arena *a) {
+ a->alloc.func = &upb_arena_doalloc;
+ a->block_alloc = &upb_alloc_global;
+ a->bytes_allocated = 0;
+ a->next_block_size = 256;
+ a->max_block_size = 16384;
+ a->cleanup_head = NULL;
+ a->block_head = NULL;
+}
+
+void upb_arena_init2(upb_arena *a, void *mem, size_t size, upb_alloc *alloc) {
+ upb_arena_init(a);
+
+ if (size > sizeof(mem_block)) {
+ upb_arena_addblock(a, mem, size, false);
+ }
+
+ if (alloc) {
+ a->block_alloc = alloc;
+ }
+}
+
+void upb_arena_uninit(upb_arena *a) {
+ cleanup_ent *ent = a->cleanup_head;
+ mem_block *block = a->block_head;
+
+ while (ent) {
+ ent->cleanup(ent->ud);
+ ent = ent->next;
+ }
+
+ /* Must do this after running cleanup functions, because this will delete
+ * the memory we store our cleanup entries in! */
+ while (block) {
+ mem_block *next = block->next;
+
+ if (block->owned) {
+ upb_free(a->block_alloc, block);
+ }
+
+ block = next;
+ }
+
+ /* Protect against multiple-uninit. */
+ a->cleanup_head = NULL;
+ a->block_head = NULL;
+}
+
+bool upb_arena_addcleanup(upb_arena *a, upb_cleanup_func *func, void *ud) {
+ cleanup_ent *ent = upb_malloc(&a->alloc, sizeof(cleanup_ent));
+ if (!ent) {
+ return false; /* Out of memory. */
+ }
+
+ ent->cleanup = func;
+ ent->ud = ud;
+ ent->next = a->cleanup_head;
+ a->cleanup_head = ent;
+
+ return true;
+}
+
+size_t upb_arena_bytesallocated(const upb_arena *a) {
+ return a->bytes_allocated;
+}
+
+
+/* Standard error functions ***************************************************/
+
+static bool default_err(void *ud, const upb_status *status) {
+ UPB_UNUSED(ud);
+ UPB_UNUSED(status);
+ return false;
+}
+
+static bool write_err_to(void *ud, const upb_status *status) {
+ upb_status *copy_to = ud;
+ upb_status_copy(copy_to, status);
+ return false;
+}
+
+
+/* upb_env ********************************************************************/
+
+void upb_env_initonly(upb_env *e) {
+ e->ok_ = true;
+ e->error_func_ = &default_err;
+ e->error_ud_ = NULL;
+}
+
+void upb_env_init(upb_env *e) {
+ upb_arena_init(&e->arena_);
+ upb_env_initonly(e);
+}
+
+void upb_env_init2(upb_env *e, void *mem, size_t n, upb_alloc *alloc) {
+ upb_arena_init2(&e->arena_, mem, n, alloc);
+ upb_env_initonly(e);
+}
+
+void upb_env_uninit(upb_env *e) {
+ upb_arena_uninit(&e->arena_);
+}
+
+void upb_env_seterrorfunc(upb_env *e, upb_error_func *func, void *ud) {
+ e->error_func_ = func;
+ e->error_ud_ = ud;
+}
+
+void upb_env_reporterrorsto(upb_env *e, upb_status *s) {
+ e->error_func_ = &write_err_to;
+ e->error_ud_ = s;
+}
+
+bool upb_env_reporterror(upb_env *e, const upb_status *status) {
+ e->ok_ = false;
+ return e->error_func_(e->error_ud_, status);
+}
+
+void *upb_env_malloc(upb_env *e, size_t size) {
+ return upb_malloc(&e->arena_.alloc, size);
+}
+
+void *upb_env_realloc(upb_env *e, void *ptr, size_t oldsize, size_t size) {
+ return upb_realloc(&e->arena_.alloc, ptr, oldsize, size);
+}
+
+void upb_env_free(upb_env *e, void *ptr) {
+ upb_free(&e->arena_.alloc, ptr);
+}
+
+bool upb_env_addcleanup(upb_env *e, upb_cleanup_func *func, void *ud) {
+ return upb_arena_addcleanup(&e->arena_, func, ud);
+}
+
+size_t upb_env_bytesallocated(const upb_env *e) {
+ return upb_arena_bytesallocated(&e->arena_);
+}
+/* This file was generated by upbc (the upb compiler) from the input
+ * file:
+ *
+ * upb/descriptor/descriptor.proto
+ *
+ * Do not edit -- your changes will be discarded when the file is
+ * regenerated. */
+
+
+static const upb_msgdef msgs[22];
+static const upb_fielddef fields[105];
+static const upb_enumdef enums[5];
+static const upb_tabent strentries[236];
+static const upb_tabent intentries[18];
+static const upb_tabval arrays[184];
+
+#ifdef UPB_DEBUG_REFS
+static upb_inttable reftables[264];
+#endif
+
+static const upb_msgdef msgs[22] = {
+ UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 40, 8, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[0], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[0]), false, UPB_SYNTAX_PROTO2, &reftables[0], &reftables[1]),
+ UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 4, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[11], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[16]), false, UPB_SYNTAX_PROTO2, &reftables[2], &reftables[3]),
+ UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ReservedRange", 4, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[14], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[20]), false, UPB_SYNTAX_PROTO2, &reftables[4], &reftables[5]),
+ UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 11, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[17], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[24]), false, UPB_SYNTAX_PROTO2, &reftables[6], &reftables[7]),
+ UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 8, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[0], &arrays[21], 4, 2), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[28]), false, UPB_SYNTAX_PROTO2, &reftables[8], &reftables[9]),
+ UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 8, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[25], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[32]), false, UPB_SYNTAX_PROTO2, &reftables[10], &reftables[11]),
+ UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 7, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[2], &arrays[29], 2, 1), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[36]), false, UPB_SYNTAX_PROTO2, &reftables[12], &reftables[13]),
+ UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 23, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[31], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[40]), false, UPB_SYNTAX_PROTO2, &reftables[14], &reftables[15]),
+ UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 12, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[4], &arrays[42], 11, 6), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[56]), false, UPB_SYNTAX_PROTO2, &reftables[16], &reftables[17]),
+ UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 42, 6, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[53], 13, 12), UPB_STRTABLE_INIT(12, 15, UPB_CTYPE_PTR, 4, &strentries[72]), false, UPB_SYNTAX_PROTO2, &reftables[18], &reftables[19]),
+ UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 6, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[66], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[88]), false, UPB_SYNTAX_PROTO2, &reftables[20], &reftables[21]),
+ UPB_MSGDEF_INIT("google.protobuf.FileOptions", 31, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[68], 39, 15), UPB_STRTABLE_INIT(16, 31, UPB_CTYPE_PTR, 5, &strentries[92]), false, UPB_SYNTAX_PROTO2, &reftables[22], &reftables[23]),
+ UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 10, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[8], &arrays[107], 8, 4), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[124]), false, UPB_SYNTAX_PROTO2, &reftables[24], &reftables[25]),
+ UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 15, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[115], 7, 6), UPB_STRTABLE_INIT(6, 7, UPB_CTYPE_PTR, 3, &strentries[132]), false, UPB_SYNTAX_PROTO2, &reftables[26], &reftables[27]),
+ UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 7, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[10], &arrays[122], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[140]), false, UPB_SYNTAX_PROTO2, &reftables[28], &reftables[29]),
+ UPB_MSGDEF_INIT("google.protobuf.OneofDescriptorProto", 5, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[123], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[144]), false, UPB_SYNTAX_PROTO2, &reftables[30], &reftables[31]),
+ UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 11, 2, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[125], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[148]), false, UPB_SYNTAX_PROTO2, &reftables[32], &reftables[33]),
+ UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 7, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[14], &arrays[129], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[152]), false, UPB_SYNTAX_PROTO2, &reftables[34], &reftables[35]),
+ UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 6, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[130], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[156]), false, UPB_SYNTAX_PROTO2, &reftables[36], &reftables[37]),
+ UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 19, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[132], 7, 5), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[160]), false, UPB_SYNTAX_PROTO2, &reftables[38], &reftables[39]),
+ UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 18, 1, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[139], 9, 7), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[168]), false, UPB_SYNTAX_PROTO2, &reftables[40], &reftables[41]),
+ UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 6, 0, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[148], 3, 2), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[184]), false, UPB_SYNTAX_PROTO2, &reftables[42], &reftables[43]),
+};
+
+static const upb_fielddef fields[105] = {
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "aggregate_value", 8, &msgs[20], NULL, 15, 6, {0},&reftables[44], &reftables[45]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "allow_alias", 2, &msgs[4], NULL, 6, 1, {0},&reftables[46], &reftables[47]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "cc_enable_arenas", 31, &msgs[11], NULL, 23, 12, {0},&reftables[48], &reftables[49]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "cc_generic_services", 16, &msgs[11], NULL, 17, 6, {0},&reftables[50], &reftables[51]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "client_streaming", 5, &msgs[13], NULL, 13, 4, {0},&reftables[52], &reftables[53]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "csharp_namespace", 37, &msgs[11], NULL, 27, 14, {0},&reftables[54], &reftables[55]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "ctype", 1, &msgs[8], (const upb_def*)(&enums[2]), 6, 1, {0},&reftables[56], &reftables[57]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "default_value", 7, &msgs[7], NULL, 16, 7, {0},&reftables[58], &reftables[59]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "dependency", 3, &msgs[9], NULL, 30, 8, {0},&reftables[60], &reftables[61]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 3, &msgs[12], NULL, 8, 3, {0},&reftables[62], &reftables[63]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 3, &msgs[8], NULL, 8, 3, {0},&reftables[64], &reftables[65]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 33, &msgs[14], NULL, 6, 1, {0},&reftables[66], &reftables[67]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 23, &msgs[11], NULL, 21, 10, {0},&reftables[68], &reftables[69]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 3, &msgs[4], NULL, 7, 2, {0},&reftables[70], &reftables[71]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 33, &msgs[17], NULL, 6, 1, {0},&reftables[72], &reftables[73]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "deprecated", 1, &msgs[6], NULL, 6, 1, {0},&reftables[74], &reftables[75]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_DOUBLE, 0, false, false, false, false, "double_value", 6, &msgs[20], NULL, 11, 4, {0},&reftables[76], &reftables[77]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "end", 2, &msgs[2], NULL, 3, 1, {0},&reftables[78], &reftables[79]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "end", 2, &msgs[1], NULL, 3, 1, {0},&reftables[80], &reftables[81]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "enum_type", 4, &msgs[0], (const upb_def*)(&msgs[3]), 18, 2, {0},&reftables[82], &reftables[83]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "enum_type", 5, &msgs[9], (const upb_def*)(&msgs[3]), 13, 1, {0},&reftables[84], &reftables[85]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "extendee", 2, &msgs[7], NULL, 7, 2, {0},&reftables[86], &reftables[87]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension", 6, &msgs[0], (const upb_def*)(&msgs[7]), 24, 4, {0},&reftables[88], &reftables[89]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension", 7, &msgs[9], (const upb_def*)(&msgs[7]), 19, 3, {0},&reftables[90], &reftables[91]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "extension_range", 5, &msgs[0], (const upb_def*)(&msgs[1]), 21, 3, {0},&reftables[92], &reftables[93]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "field", 2, &msgs[0], (const upb_def*)(&msgs[7]), 12, 0, {0},&reftables[94], &reftables[95]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "file", 1, &msgs[10], (const upb_def*)(&msgs[9]), 5, 0, {0},&reftables[96], &reftables[97]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "go_package", 11, &msgs[11], NULL, 14, 5, {0},&reftables[98], &reftables[99]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "identifier_value", 3, &msgs[20], NULL, 6, 1, {0},&reftables[100], &reftables[101]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "input_type", 2, &msgs[13], NULL, 7, 2, {0},&reftables[102], &reftables[103]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REQUIRED, UPB_TYPE_BOOL, 0, false, false, false, false, "is_extension", 2, &msgs[21], NULL, 5, 1, {0},&reftables[104], &reftables[105]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_generate_equals_and_hash", 20, &msgs[11], NULL, 20, 9, {0},&reftables[106], &reftables[107]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_generic_services", 17, &msgs[11], NULL, 18, 7, {0},&reftables[108], &reftables[109]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_multiple_files", 10, &msgs[11], NULL, 13, 4, {0},&reftables[110], &reftables[111]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "java_outer_classname", 8, &msgs[11], NULL, 9, 2, {0},&reftables[112], &reftables[113]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "java_package", 1, &msgs[11], NULL, 6, 1, {0},&reftables[114], &reftables[115]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "java_string_check_utf8", 27, &msgs[11], NULL, 22, 11, {0},&reftables[116], &reftables[117]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "javanano_use_deprecated_package", 38, &msgs[11], NULL, 30, 15, {0},&reftables[118], &reftables[119]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "json_name", 10, &msgs[7], NULL, 20, 9, {0},&reftables[120], &reftables[121]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "jstype", 6, &msgs[8], (const upb_def*)(&enums[3]), 10, 5, {0},&reftables[122], &reftables[123]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "label", 4, &msgs[7], (const upb_def*)(&enums[0]), 11, 4, {0},&reftables[124], &reftables[125]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "lazy", 5, &msgs[8], NULL, 9, 4, {0},&reftables[126], &reftables[127]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "leading_comments", 3, &msgs[19], NULL, 8, 2, {0},&reftables[128], &reftables[129]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "leading_detached_comments", 6, &msgs[19], NULL, 16, 4, {0},&reftables[130], &reftables[131]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "location", 1, &msgs[18], (const upb_def*)(&msgs[19]), 5, 0, {0},&reftables[132], &reftables[133]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "map_entry", 7, &msgs[12], NULL, 9, 4, {0},&reftables[134], &reftables[135]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "message_set_wire_format", 1, &msgs[12], NULL, 6, 1, {0},&reftables[136], &reftables[137]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "message_type", 4, &msgs[9], (const upb_def*)(&msgs[0]), 10, 0, {0},&reftables[138], &reftables[139]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "method", 2, &msgs[16], (const upb_def*)(&msgs[13]), 6, 0, {0},&reftables[140], &reftables[141]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[3], NULL, 8, 2, {0},&reftables[142], &reftables[143]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[15], NULL, 2, 0, {0},&reftables[144], &reftables[145]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "name", 2, &msgs[20], (const upb_def*)(&msgs[21]), 5, 0, {0},&reftables[146], &reftables[147]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[0], NULL, 32, 8, {0},&reftables[148], &reftables[149]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[5], NULL, 4, 1, {0},&reftables[150], &reftables[151]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[9], NULL, 22, 6, {0},&reftables[152], &reftables[153]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[7], NULL, 4, 1, {0},&reftables[154], &reftables[155]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[13], NULL, 4, 1, {0},&reftables[156], &reftables[157]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[16], NULL, 8, 2, {0},&reftables[158], &reftables[159]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REQUIRED, UPB_TYPE_STRING, 0, false, false, false, false, "name_part", 1, &msgs[21], NULL, 2, 0, {0},&reftables[160], &reftables[161]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT64, UPB_INTFMT_VARIABLE, false, false, false, false, "negative_int_value", 5, &msgs[20], NULL, 10, 3, {0},&reftables[162], &reftables[163]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "nested_type", 3, &msgs[0], (const upb_def*)(&msgs[0]), 15, 1, {0},&reftables[164], &reftables[165]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "no_standard_descriptor_accessor", 2, &msgs[12], NULL, 7, 2, {0},&reftables[166], &reftables[167]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "number", 2, &msgs[5], NULL, 7, 2, {0},&reftables[168], &reftables[169]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "number", 3, &msgs[7], NULL, 10, 3, {0},&reftables[170], &reftables[171]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "objc_class_prefix", 36, &msgs[11], NULL, 24, 13, {0},&reftables[172], &reftables[173]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "oneof_decl", 8, &msgs[0], (const upb_def*)(&msgs[15]), 28, 6, {0},&reftables[174], &reftables[175]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "oneof_index", 9, &msgs[7], NULL, 19, 8, {0},&reftables[176], &reftables[177]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "optimize_for", 9, &msgs[11], (const upb_def*)(&enums[4]), 12, 3, {0},&reftables[178], &reftables[179]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 7, &msgs[0], (const upb_def*)(&msgs[12]), 25, 5, {0},&reftables[180], &reftables[181]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 8, &msgs[9], (const upb_def*)(&msgs[11]), 20, 4, {0},&reftables[182], &reftables[183]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 4, &msgs[13], (const upb_def*)(&msgs[14]), 3, 0, {0},&reftables[184], &reftables[185]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 8, &msgs[7], (const upb_def*)(&msgs[8]), 3, 0, {0},&reftables[186], &reftables[187]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[16], (const upb_def*)(&msgs[17]), 7, 1, {0},&reftables[188], &reftables[189]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[5], (const upb_def*)(&msgs[6]), 3, 0, {0},&reftables[190], &reftables[191]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "options", 3, &msgs[3], (const upb_def*)(&msgs[4]), 7, 1, {0},&reftables[192], &reftables[193]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "output_type", 3, &msgs[13], NULL, 10, 3, {0},&reftables[194], &reftables[195]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "package", 2, &msgs[9], NULL, 25, 7, {0},&reftables[196], &reftables[197]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "packed", 2, &msgs[8], NULL, 7, 2, {0},&reftables[198], &reftables[199]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, true, "path", 1, &msgs[19], NULL, 4, 0, {0},&reftables[200], &reftables[201]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_UINT64, UPB_INTFMT_VARIABLE, false, false, false, false, "positive_int_value", 4, &msgs[20], NULL, 9, 2, {0},&reftables[202], &reftables[203]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "public_dependency", 10, &msgs[9], NULL, 35, 9, {0},&reftables[204], &reftables[205]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "py_generic_services", 18, &msgs[11], NULL, 19, 8, {0},&reftables[206], &reftables[207]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "reserved_name", 10, &msgs[0], NULL, 37, 9, {0},&reftables[208], &reftables[209]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "reserved_range", 9, &msgs[0], (const upb_def*)(&msgs[2]), 31, 7, {0},&reftables[210], &reftables[211]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "server_streaming", 6, &msgs[13], NULL, 14, 5, {0},&reftables[212], &reftables[213]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "service", 6, &msgs[9], (const upb_def*)(&msgs[16]), 16, 2, {0},&reftables[214], &reftables[215]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false, false, "source_code_info", 9, &msgs[9], (const upb_def*)(&msgs[18]), 21, 5, {0},&reftables[216], &reftables[217]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, true, "span", 2, &msgs[19], NULL, 7, 1, {0},&reftables[218], &reftables[219]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "start", 1, &msgs[2], NULL, 2, 0, {0},&reftables[220], &reftables[221]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "start", 1, &msgs[1], NULL, 2, 0, {0},&reftables[222], &reftables[223]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BYTES, 0, false, false, false, false, "string_value", 7, &msgs[20], NULL, 12, 5, {0},&reftables[224], &reftables[225]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "syntax", 12, &msgs[9], NULL, 39, 11, {0},&reftables[226], &reftables[227]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "trailing_comments", 4, &msgs[19], NULL, 11, 3, {0},&reftables[228], &reftables[229]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, false, "type", 5, &msgs[7], (const upb_def*)(&enums[1]), 12, 5, {0},&reftables[230], &reftables[231]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "type_name", 6, &msgs[7], NULL, 13, 6, {0},&reftables[232], &reftables[233]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[11], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[234], &reftables[235]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[12], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[236], &reftables[237]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[6], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[238], &reftables[239]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[4], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[240], &reftables[241]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[8], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[242], &reftables[243]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[14], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[244], &reftables[245]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "uninterpreted_option", 999, &msgs[17], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[246], &reftables[247]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false, false, "value", 2, &msgs[3], (const upb_def*)(&msgs[5]), 6, 0, {0},&reftables[248], &reftables[249]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, false, "weak", 10, &msgs[8], NULL, 11, 6, {0},&reftables[250], &reftables[251]),
+ UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, false, false, false, false, "weak_dependency", 11, &msgs[9], NULL, 38, 10, {0},&reftables[252], &reftables[253]),
+};
+
+static const upb_enumdef enums[5] = {
+ UPB_ENUMDEF_INIT("google.protobuf.FieldDescriptorProto.Label", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[188]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[151], 4, 3), 0, &reftables[254], &reftables[255]),
+ UPB_ENUMDEF_INIT("google.protobuf.FieldDescriptorProto.Type", UPB_STRTABLE_INIT(18, 31, UPB_CTYPE_INT32, 5, &strentries[192]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[155], 19, 18), 0, &reftables[256], &reftables[257]),
+ UPB_ENUMDEF_INIT("google.protobuf.FieldOptions.CType", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[224]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[174], 3, 3), 0, &reftables[258], &reftables[259]),
+ UPB_ENUMDEF_INIT("google.protobuf.FieldOptions.JSType", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[228]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[177], 3, 3), 0, &reftables[260], &reftables[261]),
+ UPB_ENUMDEF_INIT("google.protobuf.FileOptions.OptimizeMode", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[232]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[180], 4, 3), 0, &reftables[262], &reftables[263]),
+};
+
+static const upb_tabent strentries[236] = {
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR_INIT(&fields[22]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "reserved_name"), UPB_TABVALUE_PTR_INIT(&fields[82]), NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[52]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "field"), UPB_TABVALUE_PTR_INIT(&fields[25]), &strentries[12]},
+ {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "extension_range"), UPB_TABVALUE_PTR_INIT(&fields[24]), &strentries[14]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "nested_type"), UPB_TABVALUE_PTR_INIT(&fields[60]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "reserved_range"), UPB_TABVALUE_PTR_INIT(&fields[83]), NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[68]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "oneof_decl"), UPB_TABVALUE_PTR_INIT(&fields[65]), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "enum_type"), UPB_TABVALUE_PTR_INIT(&fields[19]), &strentries[13]},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "start"), UPB_TABVALUE_PTR_INIT(&fields[89]), NULL},
+ {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "end"), UPB_TABVALUE_PTR_INIT(&fields[18]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "start"), UPB_TABVALUE_PTR_INIT(&fields[88]), NULL},
+ {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "end"), UPB_TABVALUE_PTR_INIT(&fields[17]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "value"), UPB_TABVALUE_PTR_INIT(&fields[102]), NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[74]), NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[49]), &strentries[26]},
+ {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[98]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[13]), NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "allow_alias"), UPB_TABVALUE_PTR_INIT(&fields[1]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "number"), UPB_TABVALUE_PTR_INIT(&fields[62]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[73]), NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[53]), &strentries[34]},
+ {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[97]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[15]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "oneof_index"), UPB_TABVALUE_PTR_INIT(&fields[66]), NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "label"), UPB_TABVALUE_PTR_INIT(&fields[40]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[55]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "number"), UPB_TABVALUE_PTR_INIT(&fields[63]), &strentries[53]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\010", "\000", "\000", "\000", "extendee"), UPB_TABVALUE_PTR_INIT(&fields[21]), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "type_name"), UPB_TABVALUE_PTR_INIT(&fields[94]), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "json_name"), UPB_TABVALUE_PTR_INIT(&fields[38]), NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "type"), UPB_TABVALUE_PTR_INIT(&fields[93]), &strentries[50]},
+ {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "default_value"), UPB_TABVALUE_PTR_INIT(&fields[7]), NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[71]), NULL},
+ {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[99]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "weak"), UPB_TABVALUE_PTR_INIT(&fields[103]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "packed"), UPB_TABVALUE_PTR_INIT(&fields[77]), NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "lazy"), UPB_TABVALUE_PTR_INIT(&fields[41]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "ctype"), UPB_TABVALUE_PTR_INIT(&fields[6]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "jstype"), UPB_TABVALUE_PTR_INIT(&fields[39]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[10]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR_INIT(&fields[23]), NULL},
+ {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "weak_dependency"), UPB_TABVALUE_PTR_INIT(&fields[104]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[54]), NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "service"), UPB_TABVALUE_PTR_INIT(&fields[85]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "source_code_info"), UPB_TABVALUE_PTR_INIT(&fields[86]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "syntax"), UPB_TABVALUE_PTR_INIT(&fields[91]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "dependency"), UPB_TABVALUE_PTR_INIT(&fields[8]), NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "message_type"), UPB_TABVALUE_PTR_INIT(&fields[47]), NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "package"), UPB_TABVALUE_PTR_INIT(&fields[76]), NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[69]), &strentries[86]},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "enum_type"), UPB_TABVALUE_PTR_INIT(&fields[20]), NULL},
+ {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "public_dependency"), UPB_TABVALUE_PTR_INIT(&fields[80]), &strentries[85]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "file"), UPB_TABVALUE_PTR_INIT(&fields[26]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "cc_generic_services"), UPB_TABVALUE_PTR_INIT(&fields[3]), NULL},
+ {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "csharp_namespace"), UPB_TABVALUE_PTR_INIT(&fields[5]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "go_package"), UPB_TABVALUE_PTR_INIT(&fields[27]), NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "java_package"), UPB_TABVALUE_PTR_INIT(&fields[35]), &strentries[120]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "java_outer_classname"), UPB_TABVALUE_PTR_INIT(&fields[34]), NULL},
+ {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[95]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "java_multiple_files"), UPB_TABVALUE_PTR_INIT(&fields[33]), &strentries[117]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\025", "\000", "\000", "\000", "java_generic_services"), UPB_TABVALUE_PTR_INIT(&fields[32]), &strentries[118]},
+ {UPB_TABKEY_STR("\035", "\000", "\000", "\000", "java_generate_equals_and_hash"), UPB_TABVALUE_PTR_INIT(&fields[31]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\037", "\000", "\000", "\000", "javanano_use_deprecated_package"), UPB_TABVALUE_PTR_INIT(&fields[37]), &strentries[123]},
+ {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "py_generic_services"), UPB_TABVALUE_PTR_INIT(&fields[81]), NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "optimize_for"), UPB_TABVALUE_PTR_INIT(&fields[67]), NULL},
+ {UPB_TABKEY_STR("\026", "\000", "\000", "\000", "java_string_check_utf8"), UPB_TABVALUE_PTR_INIT(&fields[36]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[12]), &strentries[119]},
+ {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "objc_class_prefix"), UPB_TABVALUE_PTR_INIT(&fields[64]), NULL},
+ {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "cc_enable_arenas"), UPB_TABVALUE_PTR_INIT(&fields[2]), NULL},
+ {UPB_TABKEY_STR("\027", "\000", "\000", "\000", "message_set_wire_format"), UPB_TABVALUE_PTR_INIT(&fields[46]), &strentries[128]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[96]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[9]), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "map_entry"), UPB_TABVALUE_PTR_INIT(&fields[45]), NULL},
+ {UPB_TABKEY_STR("\037", "\000", "\000", "\000", "no_standard_descriptor_accessor"), UPB_TABVALUE_PTR_INIT(&fields[61]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "client_streaming"), UPB_TABVALUE_PTR_INIT(&fields[4]), NULL},
+ {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "server_streaming"), UPB_TABVALUE_PTR_INIT(&fields[84]), NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[56]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "input_type"), UPB_TABVALUE_PTR_INIT(&fields[29]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "output_type"), UPB_TABVALUE_PTR_INIT(&fields[75]), NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[70]), NULL},
+ {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[100]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[11]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[50]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_INIT(&fields[72]), &strentries[150]},
+ {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "method"), UPB_TABVALUE_PTR_INIT(&fields[48]), NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[57]), &strentries[149]},
+ {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_TABVALUE_PTR_INIT(&fields[101]), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PTR_INIT(&fields[14]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\010", "\000", "\000", "\000", "location"), UPB_TABVALUE_PTR_INIT(&fields[44]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "span"), UPB_TABVALUE_PTR_INIT(&fields[87]), &strentries[167]},
+ {UPB_TABKEY_STR("\031", "\000", "\000", "\000", "leading_detached_comments"), UPB_TABVALUE_PTR_INIT(&fields[43]), &strentries[165]},
+ {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "trailing_comments"), UPB_TABVALUE_PTR_INIT(&fields[92]), NULL},
+ {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "leading_comments"), UPB_TABVALUE_PTR_INIT(&fields[42]), &strentries[164]},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "path"), UPB_TABVALUE_PTR_INIT(&fields[78]), NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "double_value"), UPB_TABVALUE_PTR_INIT(&fields[16]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT(&fields[51]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\022", "\000", "\000", "\000", "negative_int_value"), UPB_TABVALUE_PTR_INIT(&fields[59]), NULL},
+ {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "aggregate_value"), UPB_TABVALUE_PTR_INIT(&fields[0]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\022", "\000", "\000", "\000", "positive_int_value"), UPB_TABVALUE_PTR_INIT(&fields[79]), NULL},
+ {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "identifier_value"), UPB_TABVALUE_PTR_INIT(&fields[28]), NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "string_value"), UPB_TABVALUE_PTR_INIT(&fields[90]), &strentries[182]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "is_extension"), UPB_TABVALUE_PTR_INIT(&fields[30]), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "name_part"), UPB_TABVALUE_PTR_INIT(&fields[58]), NULL},
+ {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_REQUIRED"), UPB_TABVALUE_INT_INIT(2), &strentries[190]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_REPEATED"), UPB_TABVALUE_INT_INIT(3), NULL},
+ {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_OPTIONAL"), UPB_TABVALUE_INT_INIT(1), NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_FIXED64"), UPB_TABVALUE_INT_INIT(6), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_STRING"), UPB_TABVALUE_INT_INIT(9), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_FLOAT"), UPB_TABVALUE_INT_INIT(2), &strentries[221]},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_DOUBLE"), UPB_TABVALUE_INT_INIT(1), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_INT32"), UPB_TABVALUE_INT_INIT(5), NULL},
+ {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "TYPE_SFIXED32"), UPB_TABVALUE_INT_INIT(15), NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_FIXED32"), UPB_TABVALUE_INT_INIT(7), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_MESSAGE"), UPB_TABVALUE_INT_INIT(11), &strentries[222]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_INT64"), UPB_TABVALUE_INT_INIT(3), &strentries[219]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "TYPE_ENUM"), UPB_TABVALUE_INT_INIT(14), NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_UINT32"), UPB_TABVALUE_INT_INIT(13), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_UINT64"), UPB_TABVALUE_INT_INIT(4), &strentries[218]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "TYPE_SFIXED64"), UPB_TABVALUE_INT_INIT(16), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_BYTES"), UPB_TABVALUE_INT_INIT(12), NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_SINT64"), UPB_TABVALUE_INT_INIT(18), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "TYPE_BOOL"), UPB_TABVALUE_INT_INIT(8), NULL},
+ {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_GROUP"), UPB_TABVALUE_INT_INIT(10), NULL},
+ {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_SINT32"), UPB_TABVALUE_INT_INIT(17), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "CORD"), UPB_TABVALUE_INT_INIT(1), NULL},
+ {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "STRING"), UPB_TABVALUE_INT_INIT(0), &strentries[225]},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "STRING_PIECE"), UPB_TABVALUE_INT_INIT(2), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "JS_NORMAL"), UPB_TABVALUE_INT_INIT(0), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "JS_NUMBER"), UPB_TABVALUE_INT_INIT(2), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "JS_STRING"), UPB_TABVALUE_INT_INIT(1), NULL},
+ {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "CODE_SIZE"), UPB_TABVALUE_INT_INIT(2), NULL},
+ {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "SPEED"), UPB_TABVALUE_INT_INIT(1), &strentries[235]},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "LITE_RUNTIME"), UPB_TABVALUE_INT_INIT(3), NULL},
+};
+
+static const upb_tabent intentries[18] = {
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[98]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[97]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[99]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[95]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[96]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(33), UPB_TABVALUE_PTR_INIT(&fields[11]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[100]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(33), UPB_TABVALUE_PTR_INIT(&fields[14]), NULL},
+ {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
+ {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[101]), NULL},
+};
+
+static const upb_tabval arrays[184] = {
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[52]),
+ UPB_TABVALUE_PTR_INIT(&fields[25]),
+ UPB_TABVALUE_PTR_INIT(&fields[60]),
+ UPB_TABVALUE_PTR_INIT(&fields[19]),
+ UPB_TABVALUE_PTR_INIT(&fields[24]),
+ UPB_TABVALUE_PTR_INIT(&fields[22]),
+ UPB_TABVALUE_PTR_INIT(&fields[68]),
+ UPB_TABVALUE_PTR_INIT(&fields[65]),
+ UPB_TABVALUE_PTR_INIT(&fields[83]),
+ UPB_TABVALUE_PTR_INIT(&fields[82]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[89]),
+ UPB_TABVALUE_PTR_INIT(&fields[18]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[88]),
+ UPB_TABVALUE_PTR_INIT(&fields[17]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[49]),
+ UPB_TABVALUE_PTR_INIT(&fields[102]),
+ UPB_TABVALUE_PTR_INIT(&fields[74]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[1]),
+ UPB_TABVALUE_PTR_INIT(&fields[13]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[53]),
+ UPB_TABVALUE_PTR_INIT(&fields[62]),
+ UPB_TABVALUE_PTR_INIT(&fields[73]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[15]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[55]),
+ UPB_TABVALUE_PTR_INIT(&fields[21]),
+ UPB_TABVALUE_PTR_INIT(&fields[63]),
+ UPB_TABVALUE_PTR_INIT(&fields[40]),
+ UPB_TABVALUE_PTR_INIT(&fields[93]),
+ UPB_TABVALUE_PTR_INIT(&fields[94]),
+ UPB_TABVALUE_PTR_INIT(&fields[7]),
+ UPB_TABVALUE_PTR_INIT(&fields[71]),
+ UPB_TABVALUE_PTR_INIT(&fields[66]),
+ UPB_TABVALUE_PTR_INIT(&fields[38]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[6]),
+ UPB_TABVALUE_PTR_INIT(&fields[77]),
+ UPB_TABVALUE_PTR_INIT(&fields[10]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[41]),
+ UPB_TABVALUE_PTR_INIT(&fields[39]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[103]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[54]),
+ UPB_TABVALUE_PTR_INIT(&fields[76]),
+ UPB_TABVALUE_PTR_INIT(&fields[8]),
+ UPB_TABVALUE_PTR_INIT(&fields[47]),
+ UPB_TABVALUE_PTR_INIT(&fields[20]),
+ UPB_TABVALUE_PTR_INIT(&fields[85]),
+ UPB_TABVALUE_PTR_INIT(&fields[23]),
+ UPB_TABVALUE_PTR_INIT(&fields[69]),
+ UPB_TABVALUE_PTR_INIT(&fields[86]),
+ UPB_TABVALUE_PTR_INIT(&fields[80]),
+ UPB_TABVALUE_PTR_INIT(&fields[104]),
+ UPB_TABVALUE_PTR_INIT(&fields[91]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[26]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[35]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[34]),
+ UPB_TABVALUE_PTR_INIT(&fields[67]),
+ UPB_TABVALUE_PTR_INIT(&fields[33]),
+ UPB_TABVALUE_PTR_INIT(&fields[27]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[3]),
+ UPB_TABVALUE_PTR_INIT(&fields[32]),
+ UPB_TABVALUE_PTR_INIT(&fields[81]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[31]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[12]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[36]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[2]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[64]),
+ UPB_TABVALUE_PTR_INIT(&fields[5]),
+ UPB_TABVALUE_PTR_INIT(&fields[37]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[46]),
+ UPB_TABVALUE_PTR_INIT(&fields[61]),
+ UPB_TABVALUE_PTR_INIT(&fields[9]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[45]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[56]),
+ UPB_TABVALUE_PTR_INIT(&fields[29]),
+ UPB_TABVALUE_PTR_INIT(&fields[75]),
+ UPB_TABVALUE_PTR_INIT(&fields[70]),
+ UPB_TABVALUE_PTR_INIT(&fields[4]),
+ UPB_TABVALUE_PTR_INIT(&fields[84]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[50]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[57]),
+ UPB_TABVALUE_PTR_INIT(&fields[48]),
+ UPB_TABVALUE_PTR_INIT(&fields[72]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[44]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[78]),
+ UPB_TABVALUE_PTR_INIT(&fields[87]),
+ UPB_TABVALUE_PTR_INIT(&fields[42]),
+ UPB_TABVALUE_PTR_INIT(&fields[92]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[43]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[51]),
+ UPB_TABVALUE_PTR_INIT(&fields[28]),
+ UPB_TABVALUE_PTR_INIT(&fields[79]),
+ UPB_TABVALUE_PTR_INIT(&fields[59]),
+ UPB_TABVALUE_PTR_INIT(&fields[16]),
+ UPB_TABVALUE_PTR_INIT(&fields[90]),
+ UPB_TABVALUE_PTR_INIT(&fields[0]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT(&fields[58]),
+ UPB_TABVALUE_PTR_INIT(&fields[30]),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT("LABEL_OPTIONAL"),
+ UPB_TABVALUE_PTR_INIT("LABEL_REQUIRED"),
+ UPB_TABVALUE_PTR_INIT("LABEL_REPEATED"),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT("TYPE_DOUBLE"),
+ UPB_TABVALUE_PTR_INIT("TYPE_FLOAT"),
+ UPB_TABVALUE_PTR_INIT("TYPE_INT64"),
+ UPB_TABVALUE_PTR_INIT("TYPE_UINT64"),
+ UPB_TABVALUE_PTR_INIT("TYPE_INT32"),
+ UPB_TABVALUE_PTR_INIT("TYPE_FIXED64"),
+ UPB_TABVALUE_PTR_INIT("TYPE_FIXED32"),
+ UPB_TABVALUE_PTR_INIT("TYPE_BOOL"),
+ UPB_TABVALUE_PTR_INIT("TYPE_STRING"),
+ UPB_TABVALUE_PTR_INIT("TYPE_GROUP"),
+ UPB_TABVALUE_PTR_INIT("TYPE_MESSAGE"),
+ UPB_TABVALUE_PTR_INIT("TYPE_BYTES"),
+ UPB_TABVALUE_PTR_INIT("TYPE_UINT32"),
+ UPB_TABVALUE_PTR_INIT("TYPE_ENUM"),
+ UPB_TABVALUE_PTR_INIT("TYPE_SFIXED32"),
+ UPB_TABVALUE_PTR_INIT("TYPE_SFIXED64"),
+ UPB_TABVALUE_PTR_INIT("TYPE_SINT32"),
+ UPB_TABVALUE_PTR_INIT("TYPE_SINT64"),
+ UPB_TABVALUE_PTR_INIT("STRING"),
+ UPB_TABVALUE_PTR_INIT("CORD"),
+ UPB_TABVALUE_PTR_INIT("STRING_PIECE"),
+ UPB_TABVALUE_PTR_INIT("JS_NORMAL"),
+ UPB_TABVALUE_PTR_INIT("JS_STRING"),
+ UPB_TABVALUE_PTR_INIT("JS_NUMBER"),
+ UPB_TABVALUE_EMPTY_INIT,
+ UPB_TABVALUE_PTR_INIT("SPEED"),
+ UPB_TABVALUE_PTR_INIT("CODE_SIZE"),
+ UPB_TABVALUE_PTR_INIT("LITE_RUNTIME"),
+};
+
+#ifdef UPB_DEBUG_REFS
+static upb_inttable reftables[264] = {
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+ UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
+};
+#endif
+
+static const upb_msgdef *refm(const upb_msgdef *m, const void *owner) {
+ upb_msgdef_ref(m, owner);
+ return m;
+}
+
+static const upb_enumdef *refe(const upb_enumdef *e, const void *owner) {
+ upb_enumdef_ref(e, owner);
+ return e;
+}
+
+/* Public API. */
+const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_get(const void *owner) { return refm(&msgs[0], owner); }
+const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_get(const void *owner) { return refm(&msgs[1], owner); }
+const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ReservedRange_get(const void *owner) { return refm(&msgs[2], owner); }
+const upb_msgdef *upbdefs_google_protobuf_EnumDescriptorProto_get(const void *owner) { return refm(&msgs[3], owner); }
+const upb_msgdef *upbdefs_google_protobuf_EnumOptions_get(const void *owner) { return refm(&msgs[4], owner); }
+const upb_msgdef *upbdefs_google_protobuf_EnumValueDescriptorProto_get(const void *owner) { return refm(&msgs[5], owner); }
+const upb_msgdef *upbdefs_google_protobuf_EnumValueOptions_get(const void *owner) { return refm(&msgs[6], owner); }
+const upb_msgdef *upbdefs_google_protobuf_FieldDescriptorProto_get(const void *owner) { return refm(&msgs[7], owner); }
+const upb_msgdef *upbdefs_google_protobuf_FieldOptions_get(const void *owner) { return refm(&msgs[8], owner); }
+const upb_msgdef *upbdefs_google_protobuf_FileDescriptorProto_get(const void *owner) { return refm(&msgs[9], owner); }
+const upb_msgdef *upbdefs_google_protobuf_FileDescriptorSet_get(const void *owner) { return refm(&msgs[10], owner); }
+const upb_msgdef *upbdefs_google_protobuf_FileOptions_get(const void *owner) { return refm(&msgs[11], owner); }
+const upb_msgdef *upbdefs_google_protobuf_MessageOptions_get(const void *owner) { return refm(&msgs[12], owner); }
+const upb_msgdef *upbdefs_google_protobuf_MethodDescriptorProto_get(const void *owner) { return refm(&msgs[13], owner); }
+const upb_msgdef *upbdefs_google_protobuf_MethodOptions_get(const void *owner) { return refm(&msgs[14], owner); }
+const upb_msgdef *upbdefs_google_protobuf_OneofDescriptorProto_get(const void *owner) { return refm(&msgs[15], owner); }
+const upb_msgdef *upbdefs_google_protobuf_ServiceDescriptorProto_get(const void *owner) { return refm(&msgs[16], owner); }
+const upb_msgdef *upbdefs_google_protobuf_ServiceOptions_get(const void *owner) { return refm(&msgs[17], owner); }
+const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo_get(const void *owner) { return refm(&msgs[18], owner); }
+const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo_Location_get(const void *owner) { return refm(&msgs[19], owner); }
+const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption_get(const void *owner) { return refm(&msgs[20], owner); }
+const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption_NamePart_get(const void *owner) { return refm(&msgs[21], owner); }
+
+const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Label_get(const void *owner) { return refe(&enums[0], owner); }
+const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Type_get(const void *owner) { return refe(&enums[1], owner); }
+const upb_enumdef *upbdefs_google_protobuf_FieldOptions_CType_get(const void *owner) { return refe(&enums[2], owner); }
+const upb_enumdef *upbdefs_google_protobuf_FieldOptions_JSType_get(const void *owner) { return refe(&enums[3], owner); }
+const upb_enumdef *upbdefs_google_protobuf_FileOptions_OptimizeMode_get(const void *owner) { return refe(&enums[4], owner); }
+/*
+** XXX: The routines in this file that consume a string do not currently
+** support having the string span buffers. In the future, as upb_sink and
+** its buffering/sharing functionality evolve there should be an easy and
+** idiomatic way of correctly handling this case. For now, we accept this
+** limitation since we currently only parse descriptors from single strings.
+*/
+
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* Compares a NULL-terminated string with a non-NULL-terminated string. */
+static bool upb_streq(const char *str, const char *buf, size_t n) {
+ return strlen(str) == n && memcmp(str, buf, n) == 0;
+}
+
+/* We keep a stack of all the messages scopes we are currently in, as well as
+ * the top-level file scope. This is necessary to correctly qualify the
+ * definitions that are contained inside. "name" tracks the name of the
+ * message or package (a bare name -- not qualified by any enclosing scopes). */
+typedef struct {
+ char *name;
+ /* Index of the first def that is under this scope. For msgdefs, the
+ * msgdef itself is at start-1. */
+ int start;
+ uint32_t oneof_start;
+ uint32_t oneof_index;
+} upb_descreader_frame;
+
+/* The maximum number of nested declarations that are allowed, ie.
+ * message Foo {
+ * message Bar {
+ * message Baz {
+ * }
+ * }
+ * }
+ *
+ * This is a resource limit that affects how big our runtime stack can grow.
+ * TODO: make this a runtime-settable property of the Reader instance. */
+#define UPB_MAX_MESSAGE_NESTING 64
+
+struct upb_descreader {
+ upb_sink sink;
+ upb_inttable files;
+ upb_filedef *file; /* The last file in files. */
+ upb_descreader_frame stack[UPB_MAX_MESSAGE_NESTING];
+ int stack_len;
+ upb_inttable oneofs;
+
+ uint32_t number;
+ char *name;
+ bool saw_number;
+ bool saw_name;
+
+ char *default_string;
+
+ upb_fielddef *f;
+};
+
+static char *upb_gstrndup(const char *buf, size_t n) {
+ char *ret = upb_gmalloc(n + 1);
+ if (!ret) return NULL;
+ memcpy(ret, buf, n);
+ ret[n] = '\0';
+ return ret;
+}
+
+/* Returns a newly allocated string that joins input strings together, for
+ * example:
+ * join("Foo.Bar", "Baz") -> "Foo.Bar.Baz"
+ * join("", "Baz") -> "Baz"
+ * Caller owns a ref on the returned string. */
+static char *upb_join(const char *base, const char *name) {
+ if (!base || strlen(base) == 0) {
+ return upb_gstrdup(name);
+ } else {
+ char *ret = upb_gmalloc(strlen(base) + strlen(name) + 2);
+ if (!ret) {
+ return NULL;
+ }
+ ret[0] = '\0';
+ strcat(ret, base);
+ strcat(ret, ".");
+ strcat(ret, name);
+ return ret;
+ }
+}
+
+/* Qualify the defname for all defs starting with offset "start" with "str". */
+static bool upb_descreader_qualify(upb_filedef *f, char *str, int32_t start) {
+ size_t i;
+ for (i = start; i < upb_filedef_defcount(f); i++) {
+ upb_def *def = upb_filedef_mutabledef(f, i);
+ char *name = upb_join(str, upb_def_fullname(def));
+ if (!name) {
+ /* Need better logic here; at this point we've qualified some names but
+ * not others. */
+ return false;
+ }
+ upb_def_setfullname(def, name, NULL);
+ upb_gfree(name);
+ }
+ return true;
+}
+
+
+/* upb_descreader ************************************************************/
+
+static upb_msgdef *upb_descreader_top(upb_descreader *r) {
+ int index;
+ UPB_ASSERT(r->stack_len > 1);
+ index = r->stack[r->stack_len-1].start - 1;
+ UPB_ASSERT(index >= 0);
+ return upb_downcast_msgdef_mutable(upb_filedef_mutabledef(r->file, index));
+}
+
+static upb_def *upb_descreader_last(upb_descreader *r) {
+ return upb_filedef_mutabledef(r->file, upb_filedef_defcount(r->file) - 1);
+}
+
+/* Start/end handlers for FileDescriptorProto and DescriptorProto (the two
+ * entities that have names and can contain sub-definitions. */
+void upb_descreader_startcontainer(upb_descreader *r) {
+ upb_descreader_frame *f = &r->stack[r->stack_len++];
+ f->start = upb_filedef_defcount(r->file);
+ f->oneof_start = upb_inttable_count(&r->oneofs);
+ f->oneof_index = 0;
+ f->name = NULL;
+}
+
+bool upb_descreader_endcontainer(upb_descreader *r) {
+ upb_descreader_frame *f = &r->stack[r->stack_len - 1];
+
+ while (upb_inttable_count(&r->oneofs) > f->oneof_start) {
+ upb_oneofdef *o = upb_value_getptr(upb_inttable_pop(&r->oneofs));
+ bool ok = upb_msgdef_addoneof(upb_descreader_top(r), o, &r->oneofs, NULL);
+ UPB_ASSERT(ok);
+ }
+
+ if (!upb_descreader_qualify(r->file, f->name, f->start)) {
+ return false;
+ }
+ upb_gfree(f->name);
+ f->name = NULL;
+
+ r->stack_len--;
+ return true;
+}
+
+void upb_descreader_setscopename(upb_descreader *r, char *str) {
+ upb_descreader_frame *f = &r->stack[r->stack_len-1];
+ upb_gfree(f->name);
+ f->name = str;
+}
+
+static upb_oneofdef *upb_descreader_getoneof(upb_descreader *r,
+ uint32_t index) {
+ bool found;
+ upb_value val;
+ upb_descreader_frame *f = &r->stack[r->stack_len-1];
+
+ /* DescriptorProto messages can be nested, so we will see the nested messages
+ * between when we see the FieldDescriptorProto and the OneofDescriptorProto.
+ * We need to preserve the oneofs in between these two things. */
+ index += f->oneof_start;
+
+ while (upb_inttable_count(&r->oneofs) <= index) {
+ upb_inttable_push(&r->oneofs, upb_value_ptr(upb_oneofdef_new(&r->oneofs)));
+ }
+
+ found = upb_inttable_lookup(&r->oneofs, index, &val);
+ UPB_ASSERT(found);
+ return upb_value_getptr(val);
+}
+
+/** Handlers for google.protobuf.FileDescriptorSet. ***************************/
+
+static void *fileset_startfile(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+ r->file = upb_filedef_new(&r->files);
+ upb_inttable_push(&r->files, upb_value_ptr(r->file));
+ return r;
+}
+
+/** Handlers for google.protobuf.FileDescriptorProto. *************************/
+
+static bool file_start(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+ upb_descreader_startcontainer(r);
+ return true;
+}
+
+static bool file_end(void *closure, const void *hd, upb_status *status) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(status);
+ return upb_descreader_endcontainer(r);
+}
+
+static size_t file_onname(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ char *name;
+ bool ok;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ name = upb_gstrndup(buf, n);
+ /* XXX: see comment at the top of the file. */
+ ok = upb_filedef_setname(r->file, name, NULL);
+ upb_gfree(name);
+ UPB_ASSERT(ok);
+ return n;
+}
+
+static size_t file_onpackage(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ char *package;
+ bool ok;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ package = upb_gstrndup(buf, n);
+ /* XXX: see comment at the top of the file. */
+ upb_descreader_setscopename(r, package);
+ ok = upb_filedef_setpackage(r->file, package, NULL);
+ UPB_ASSERT(ok);
+ return n;
+}
+
+static size_t file_onsyntax(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ bool ok;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+ /* XXX: see comment at the top of the file. */
+ if (upb_streq("proto2", buf, n)) {
+ ok = upb_filedef_setsyntax(r->file, UPB_SYNTAX_PROTO2, NULL);
+ } else if (upb_streq("proto3", buf, n)) {
+ ok = upb_filedef_setsyntax(r->file, UPB_SYNTAX_PROTO3, NULL);
+ } else {
+ ok = false;
+ }
+
+ UPB_ASSERT(ok);
+ return n;
+}
+
+static void *file_startmsg(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ upb_msgdef *m = upb_msgdef_new(&m);
+ bool ok = upb_filedef_addmsg(r->file, m, &m, NULL);
+ UPB_UNUSED(hd);
+ UPB_ASSERT(ok);
+ return r;
+}
+
+static void *file_startenum(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ upb_enumdef *e = upb_enumdef_new(&e);
+ bool ok = upb_filedef_addenum(r->file, e, &e, NULL);
+ UPB_UNUSED(hd);
+ UPB_ASSERT(ok);
+ return r;
+}
+
+static void *file_startext(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ bool ok;
+ r->f = upb_fielddef_new(r);
+ ok = upb_filedef_addext(r->file, r->f, r, NULL);
+ UPB_UNUSED(hd);
+ UPB_ASSERT(ok);
+ return r;
+}
+
+/** Handlers for google.protobuf.EnumValueDescriptorProto. *********************/
+
+static bool enumval_startmsg(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+ r->saw_number = false;
+ r->saw_name = false;
+ return true;
+}
+
+static size_t enumval_onname(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+ /* XXX: see comment at the top of the file. */
+ upb_gfree(r->name);
+ r->name = upb_gstrndup(buf, n);
+ r->saw_name = true;
+ return n;
+}
+
+static bool enumval_onnumber(void *closure, const void *hd, int32_t val) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+ r->number = val;
+ r->saw_number = true;
+ return true;
+}
+
+static bool enumval_endmsg(void *closure, const void *hd, upb_status *status) {
+ upb_descreader *r = closure;
+ upb_enumdef *e;
+ UPB_UNUSED(hd);
+
+ if(!r->saw_number || !r->saw_name) {
+ upb_status_seterrmsg(status, "Enum value missing name or number.");
+ return false;
+ }
+ e = upb_downcast_enumdef_mutable(upb_descreader_last(r));
+ upb_enumdef_addval(e, r->name, r->number, status);
+ upb_gfree(r->name);
+ r->name = NULL;
+ return true;
+}
+
+/** Handlers for google.protobuf.EnumDescriptorProto. *************************/
+
+static bool enum_endmsg(void *closure, const void *hd, upb_status *status) {
+ upb_descreader *r = closure;
+ upb_enumdef *e;
+ UPB_UNUSED(hd);
+
+ e = upb_downcast_enumdef_mutable(upb_descreader_last(r));
+ if (upb_def_fullname(upb_descreader_last(r)) == NULL) {
+ upb_status_seterrmsg(status, "Enum had no name.");
+ return false;
+ }
+ if (upb_enumdef_numvals(e) == 0) {
+ upb_status_seterrmsg(status, "Enum had no values.");
+ return false;
+ }
+ return true;
+}
+
+static size_t enum_onname(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ char *fullname = upb_gstrndup(buf, n);
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+ /* XXX: see comment at the top of the file. */
+ upb_def_setfullname(upb_descreader_last(r), fullname, NULL);
+ upb_gfree(fullname);
+ return n;
+}
+
+/** Handlers for google.protobuf.FieldDescriptorProto *************************/
+
+static bool field_startmsg(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+ UPB_ASSERT(r->f);
+ upb_gfree(r->default_string);
+ r->default_string = NULL;
+
+ /* fielddefs default to packed, but descriptors default to non-packed. */
+ upb_fielddef_setpacked(r->f, false);
+ return true;
+}
+
+/* Converts the default value in string "str" into "d". Passes a ref on str.
+ * Returns true on success. */
+static bool parse_default(char *str, upb_fielddef *f) {
+ bool success = true;
+ char *end;
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_INT32: {
+ long val = strtol(str, &end, 0);
+ if (val > INT32_MAX || val < INT32_MIN || errno == ERANGE || *end)
+ success = false;
+ else
+ upb_fielddef_setdefaultint32(f, val);
+ break;
+ }
+ case UPB_TYPE_INT64: {
+ /* XXX: Need to write our own strtoll, since it's not available in c89. */
+ long long val = strtol(str, &end, 0);
+ if (val > INT64_MAX || val < INT64_MIN || errno == ERANGE || *end)
+ success = false;
+ else
+ upb_fielddef_setdefaultint64(f, val);
+ break;
+ }
+ case UPB_TYPE_UINT32: {
+ unsigned long val = strtoul(str, &end, 0);
+ if (val > UINT32_MAX || errno == ERANGE || *end)
+ success = false;
+ else
+ upb_fielddef_setdefaultuint32(f, val);
+ break;
+ }
+ case UPB_TYPE_UINT64: {
+ /* XXX: Need to write our own strtoull, since it's not available in c89. */
+ unsigned long long val = strtoul(str, &end, 0);
+ if (val > UINT64_MAX || errno == ERANGE || *end)
+ success = false;
+ else
+ upb_fielddef_setdefaultuint64(f, val);
+ break;
+ }
+ case UPB_TYPE_DOUBLE: {
+ double val = strtod(str, &end);
+ if (errno == ERANGE || *end)
+ success = false;
+ else
+ upb_fielddef_setdefaultdouble(f, val);
+ break;
+ }
+ case UPB_TYPE_FLOAT: {
+ /* XXX: Need to write our own strtof, since it's not available in c89. */
+ float val = strtod(str, &end);
+ if (errno == ERANGE || *end)
+ success = false;
+ else
+ upb_fielddef_setdefaultfloat(f, val);
+ break;
+ }
+ case UPB_TYPE_BOOL: {
+ if (strcmp(str, "false") == 0)
+ upb_fielddef_setdefaultbool(f, false);
+ else if (strcmp(str, "true") == 0)
+ upb_fielddef_setdefaultbool(f, true);
+ else
+ success = false;
+ break;
+ }
+ default: abort();
+ }
+ return success;
+}
+
+static bool field_endmsg(void *closure, const void *hd, upb_status *status) {
+ upb_descreader *r = closure;
+ upb_fielddef *f = r->f;
+ UPB_UNUSED(hd);
+
+ /* TODO: verify that all required fields were present. */
+ UPB_ASSERT(upb_fielddef_number(f) != 0);
+ UPB_ASSERT(upb_fielddef_name(f) != NULL);
+ UPB_ASSERT((upb_fielddef_subdefname(f) != NULL) == upb_fielddef_hassubdef(f));
+
+ if (r->default_string) {
+ if (upb_fielddef_issubmsg(f)) {
+ upb_status_seterrmsg(status, "Submessages cannot have defaults.");
+ return false;
+ }
+ if (upb_fielddef_isstring(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM) {
+ upb_fielddef_setdefaultcstr(f, r->default_string, NULL);
+ } else {
+ if (r->default_string && !parse_default(r->default_string, f)) {
+ /* We don't worry too much about giving a great error message since the
+ * compiler should have ensured this was correct. */
+ upb_status_seterrmsg(status, "Error converting default value.");
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+static bool field_onlazy(void *closure, const void *hd, bool val) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+
+ upb_fielddef_setlazy(r->f, val);
+ return true;
+}
+
+static bool field_onpacked(void *closure, const void *hd, bool val) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+
+ upb_fielddef_setpacked(r->f, val);
+ return true;
+}
+
+static bool field_ontype(void *closure, const void *hd, int32_t val) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+
+ upb_fielddef_setdescriptortype(r->f, val);
+ return true;
+}
+
+static bool field_onlabel(void *closure, const void *hd, int32_t val) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+
+ upb_fielddef_setlabel(r->f, val);
+ return true;
+}
+
+static bool field_onnumber(void *closure, const void *hd, int32_t val) {
+ upb_descreader *r = closure;
+ bool ok;
+ UPB_UNUSED(hd);
+
+ ok = upb_fielddef_setnumber(r->f, val, NULL);
+ UPB_ASSERT(ok);
+ return true;
+}
+
+static size_t field_onname(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ char *name = upb_gstrndup(buf, n);
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ /* XXX: see comment at the top of the file. */
+ upb_fielddef_setname(r->f, name, NULL);
+ upb_gfree(name);
+ return n;
+}
+
+static size_t field_ontypename(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ char *name = upb_gstrndup(buf, n);
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ /* XXX: see comment at the top of the file. */
+ upb_fielddef_setsubdefname(r->f, name, NULL);
+ upb_gfree(name);
+ return n;
+}
+
+static size_t field_onextendee(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ char *name = upb_gstrndup(buf, n);
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ /* XXX: see comment at the top of the file. */
+ upb_fielddef_setcontainingtypename(r->f, name, NULL);
+ upb_gfree(name);
+ return n;
+}
+
+static size_t field_ondefaultval(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ /* Have to convert from string to the correct type, but we might not know the
+ * type yet, so we save it as a string until the end of the field.
+ * XXX: see comment at the top of the file. */
+ upb_gfree(r->default_string);
+ r->default_string = upb_gstrndup(buf, n);
+ return n;
+}
+
+static bool field_ononeofindex(void *closure, const void *hd, int32_t index) {
+ upb_descreader *r = closure;
+ upb_oneofdef *o = upb_descreader_getoneof(r, index);
+ bool ok = upb_oneofdef_addfield(o, r->f, &r->f, NULL);
+ UPB_UNUSED(hd);
+
+ UPB_ASSERT(ok);
+ return true;
+}
+
+/** Handlers for google.protobuf.OneofDescriptorProto. ************************/
+
+static size_t oneof_name(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ upb_descreader_frame *f = &r->stack[r->stack_len-1];
+ upb_oneofdef *o = upb_descreader_getoneof(r, f->oneof_index++);
+ char *name_null_terminated = upb_gstrndup(buf, n);
+ bool ok = upb_oneofdef_setname(o, name_null_terminated, NULL);
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ UPB_ASSERT(ok);
+ free(name_null_terminated);
+ return n;
+}
+
+/** Handlers for google.protobuf.DescriptorProto ******************************/
+
+static bool msg_start(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ UPB_UNUSED(hd);
+
+ upb_descreader_startcontainer(r);
+ return true;
+}
+
+static bool msg_end(void *closure, const void *hd, upb_status *status) {
+ upb_descreader *r = closure;
+ upb_msgdef *m = upb_descreader_top(r);
+ UPB_UNUSED(hd);
+
+ if(!upb_def_fullname(upb_msgdef_upcast_mutable(m))) {
+ upb_status_seterrmsg(status, "Encountered message with no name.");
+ return false;
+ }
+ return upb_descreader_endcontainer(r);
+}
+
+static size_t msg_name(void *closure, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle *handle) {
+ upb_descreader *r = closure;
+ upb_msgdef *m = upb_descreader_top(r);
+ /* XXX: see comment at the top of the file. */
+ char *name = upb_gstrndup(buf, n);
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ upb_def_setfullname(upb_msgdef_upcast_mutable(m), name, NULL);
+ upb_descreader_setscopename(r, name); /* Passes ownership of name. */
+ return n;
+}
+
+static void *msg_startmsg(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ upb_msgdef *m = upb_msgdef_new(&m);
+ bool ok = upb_filedef_addmsg(r->file, m, &m, NULL);
+ UPB_UNUSED(hd);
+ UPB_ASSERT(ok);
+ return r;
+}
+
+static void *msg_startext(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ upb_fielddef *f = upb_fielddef_new(&f);
+ bool ok = upb_filedef_addext(r->file, f, &f, NULL);
+ UPB_UNUSED(hd);
+ UPB_ASSERT(ok);
+ return r;
+}
+
+static void *msg_startfield(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ r->f = upb_fielddef_new(&r->f);
+ /* We can't add the new field to the message until its name/number are
+ * filled in. */
+ UPB_UNUSED(hd);
+ return r;
+}
+
+static bool msg_endfield(void *closure, const void *hd) {
+ upb_descreader *r = closure;
+ upb_msgdef *m = upb_descreader_top(r);
+ bool ok;
+ UPB_UNUSED(hd);
+
+ /* Oneof fields are added to the msgdef through their oneof, so don't need to
+ * be added here. */
+ if (upb_fielddef_containingoneof(r->f) == NULL) {
+ ok = upb_msgdef_addfield(m, r->f, &r->f, NULL);
+ UPB_ASSERT(ok);
+ }
+ r->f = NULL;
+ return true;
+}
+
+static bool msg_onmapentry(void *closure, const void *hd, bool mapentry) {
+ upb_descreader *r = closure;
+ upb_msgdef *m = upb_descreader_top(r);
+ UPB_UNUSED(hd);
+
+ upb_msgdef_setmapentry(m, mapentry);
+ r->f = NULL;
+ return true;
+}
+
+
+
+/** Code to register handlers *************************************************/
+
+#define F(msg, field) upbdefs_google_protobuf_ ## msg ## _f_ ## field(m)
+
+static void reghandlers(const void *closure, upb_handlers *h) {
+ const upb_msgdef *m = upb_handlers_msgdef(h);
+ UPB_UNUSED(closure);
+
+ if (upbdefs_google_protobuf_FileDescriptorSet_is(m)) {
+ upb_handlers_setstartsubmsg(h, F(FileDescriptorSet, file),
+ &fileset_startfile, NULL);
+ } else if (upbdefs_google_protobuf_DescriptorProto_is(m)) {
+ upb_handlers_setstartmsg(h, &msg_start, NULL);
+ upb_handlers_setendmsg(h, &msg_end, NULL);
+ upb_handlers_setstring(h, F(DescriptorProto, name), &msg_name, NULL);
+ upb_handlers_setstartsubmsg(h, F(DescriptorProto, extension), &msg_startext,
+ NULL);
+ upb_handlers_setstartsubmsg(h, F(DescriptorProto, nested_type),
+ &msg_startmsg, NULL);
+ upb_handlers_setstartsubmsg(h, F(DescriptorProto, field),
+ &msg_startfield, NULL);
+ upb_handlers_setendsubmsg(h, F(DescriptorProto, field),
+ &msg_endfield, NULL);
+ upb_handlers_setstartsubmsg(h, F(DescriptorProto, enum_type),
+ &file_startenum, NULL);
+ } else if (upbdefs_google_protobuf_FileDescriptorProto_is(m)) {
+ upb_handlers_setstartmsg(h, &file_start, NULL);
+ upb_handlers_setendmsg(h, &file_end, NULL);
+ upb_handlers_setstring(h, F(FileDescriptorProto, name), &file_onname,
+ NULL);
+ upb_handlers_setstring(h, F(FileDescriptorProto, package), &file_onpackage,
+ NULL);
+ upb_handlers_setstring(h, F(FileDescriptorProto, syntax), &file_onsyntax,
+ NULL);
+ upb_handlers_setstartsubmsg(h, F(FileDescriptorProto, message_type),
+ &file_startmsg, NULL);
+ upb_handlers_setstartsubmsg(h, F(FileDescriptorProto, enum_type),
+ &file_startenum, NULL);
+ upb_handlers_setstartsubmsg(h, F(FileDescriptorProto, extension),
+ &file_startext, NULL);
+ } else if (upbdefs_google_protobuf_EnumValueDescriptorProto_is(m)) {
+ upb_handlers_setstartmsg(h, &enumval_startmsg, NULL);
+ upb_handlers_setendmsg(h, &enumval_endmsg, NULL);
+ upb_handlers_setstring(h, F(EnumValueDescriptorProto, name), &enumval_onname, NULL);
+ upb_handlers_setint32(h, F(EnumValueDescriptorProto, number), &enumval_onnumber,
+ NULL);
+ } else if (upbdefs_google_protobuf_EnumDescriptorProto_is(m)) {
+ upb_handlers_setendmsg(h, &enum_endmsg, NULL);
+ upb_handlers_setstring(h, F(EnumDescriptorProto, name), &enum_onname, NULL);
+ } else if (upbdefs_google_protobuf_FieldDescriptorProto_is(m)) {
+ upb_handlers_setstartmsg(h, &field_startmsg, NULL);
+ upb_handlers_setendmsg(h, &field_endmsg, NULL);
+ upb_handlers_setint32(h, F(FieldDescriptorProto, type), &field_ontype,
+ NULL);
+ upb_handlers_setint32(h, F(FieldDescriptorProto, label), &field_onlabel,
+ NULL);
+ upb_handlers_setint32(h, F(FieldDescriptorProto, number), &field_onnumber,
+ NULL);
+ upb_handlers_setstring(h, F(FieldDescriptorProto, name), &field_onname,
+ NULL);
+ upb_handlers_setstring(h, F(FieldDescriptorProto, type_name),
+ &field_ontypename, NULL);
+ upb_handlers_setstring(h, F(FieldDescriptorProto, extendee),
+ &field_onextendee, NULL);
+ upb_handlers_setstring(h, F(FieldDescriptorProto, default_value),
+ &field_ondefaultval, NULL);
+ upb_handlers_setint32(h, F(FieldDescriptorProto, oneof_index),
+ &field_ononeofindex, NULL);
+ } else if (upbdefs_google_protobuf_OneofDescriptorProto_is(m)) {
+ upb_handlers_setstring(h, F(OneofDescriptorProto, name), &oneof_name, NULL);
+ } else if (upbdefs_google_protobuf_FieldOptions_is(m)) {
+ upb_handlers_setbool(h, F(FieldOptions, lazy), &field_onlazy, NULL);
+ upb_handlers_setbool(h, F(FieldOptions, packed), &field_onpacked, NULL);
+ } else if (upbdefs_google_protobuf_MessageOptions_is(m)) {
+ upb_handlers_setbool(h, F(MessageOptions, map_entry), &msg_onmapentry, NULL);
+ }
+
+ UPB_ASSERT(upb_ok(upb_handlers_status(h)));
+}
+
+#undef F
+
+void descreader_cleanup(void *_r) {
+ upb_descreader *r = _r;
+ size_t i;
+
+ for (i = 0; i < upb_descreader_filecount(r); i++) {
+ upb_filedef_unref(upb_descreader_file(r, i), &r->files);
+ }
+
+ upb_gfree(r->name);
+ upb_inttable_uninit(&r->files);
+ upb_inttable_uninit(&r->oneofs);
+ upb_gfree(r->default_string);
+ while (r->stack_len > 0) {
+ upb_descreader_frame *f = &r->stack[--r->stack_len];
+ upb_gfree(f->name);
+ }
+}
+
+
+/* Public API ****************************************************************/
+
+upb_descreader *upb_descreader_create(upb_env *e, const upb_handlers *h) {
+ upb_descreader *r = upb_env_malloc(e, sizeof(upb_descreader));
+ if (!r || !upb_env_addcleanup(e, descreader_cleanup, r)) {
+ return NULL;
+ }
+
+ upb_inttable_init(&r->files, UPB_CTYPE_PTR);
+ upb_inttable_init(&r->oneofs, UPB_CTYPE_PTR);
+ upb_sink_reset(upb_descreader_input(r), h, r);
+ r->stack_len = 0;
+ r->name = NULL;
+ r->default_string = NULL;
+
+ return r;
+}
+
+size_t upb_descreader_filecount(const upb_descreader *r) {
+ return upb_inttable_count(&r->files);
+}
+
+upb_filedef *upb_descreader_file(const upb_descreader *r, size_t i) {
+ upb_value v;
+ if (upb_inttable_lookup(&r->files, i, &v)) {
+ return upb_value_getptr(v);
+ } else {
+ return NULL;
+ }
+}
+
+upb_sink *upb_descreader_input(upb_descreader *r) {
+ return &r->sink;
+}
+
+const upb_handlers *upb_descreader_newhandlers(const void *owner) {
+ const upb_msgdef *m = upbdefs_google_protobuf_FileDescriptorSet_get(&m);
+ const upb_handlers *h = upb_handlers_newfrozen(m, owner, reghandlers, NULL);
+ upb_msgdef_unref(m, &m);
+ return h;
+}
+/*
+** protobuf decoder bytecode compiler
+**
+** Code to compile a upb::Handlers into bytecode for decoding a protobuf
+** according to that specific schema and destination handlers.
+**
+** Compiling to bytecode is always the first step. If we are using the
+** interpreted decoder we leave it as bytecode and interpret that. If we are
+** using a JIT decoder we use a code generator to turn the bytecode into native
+** code, LLVM IR, etc.
+**
+** Bytecode definition is in decoder.int.h.
+*/
+
+#include <stdarg.h>
+
+#ifdef UPB_DUMP_BYTECODE
+#include <stdio.h>
+#endif
+
+#define MAXLABEL 5
+#define EMPTYLABEL -1
+
+/* mgroup *********************************************************************/
+
+static void freegroup(upb_refcounted *r) {
+ mgroup *g = (mgroup*)r;
+ upb_inttable_uninit(&g->methods);
+#ifdef UPB_USE_JIT_X64
+ upb_pbdecoder_freejit(g);
+#endif
+ upb_gfree(g->bytecode);
+ upb_gfree(g);
+}
+
+static void visitgroup(const upb_refcounted *r, upb_refcounted_visit *visit,
+ void *closure) {
+ const mgroup *g = (const mgroup*)r;
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, &g->methods);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ upb_pbdecodermethod *method = upb_value_getptr(upb_inttable_iter_value(&i));
+ visit(r, upb_pbdecodermethod_upcast(method), closure);
+ }
+}
+
+mgroup *newgroup(const void *owner) {
+ mgroup *g = upb_gmalloc(sizeof(*g));
+ static const struct upb_refcounted_vtbl vtbl = {visitgroup, freegroup};
+ upb_refcounted_init(mgroup_upcast_mutable(g), &vtbl, owner);
+ upb_inttable_init(&g->methods, UPB_CTYPE_PTR);
+ g->bytecode = NULL;
+ g->bytecode_end = NULL;
+ return g;
+}
+
+
+/* upb_pbdecodermethod ********************************************************/
+
+static void freemethod(upb_refcounted *r) {
+ upb_pbdecodermethod *method = (upb_pbdecodermethod*)r;
+
+ if (method->dest_handlers_) {
+ upb_handlers_unref(method->dest_handlers_, method);
+ }
+
+ upb_inttable_uninit(&method->dispatch);
+ upb_gfree(method);
+}
+
+static void visitmethod(const upb_refcounted *r, upb_refcounted_visit *visit,
+ void *closure) {
+ const upb_pbdecodermethod *m = (const upb_pbdecodermethod*)r;
+ visit(r, m->group, closure);
+}
+
+static upb_pbdecodermethod *newmethod(const upb_handlers *dest_handlers,
+ mgroup *group) {
+ static const struct upb_refcounted_vtbl vtbl = {visitmethod, freemethod};
+ upb_pbdecodermethod *ret = upb_gmalloc(sizeof(*ret));
+ upb_refcounted_init(upb_pbdecodermethod_upcast_mutable(ret), &vtbl, &ret);
+ upb_byteshandler_init(&ret->input_handler_);
+
+ /* The method references the group and vice-versa, in a circular reference. */
+ upb_ref2(ret, group);
+ upb_ref2(group, ret);
+ upb_inttable_insertptr(&group->methods, dest_handlers, upb_value_ptr(ret));
+ upb_pbdecodermethod_unref(ret, &ret);
+
+ ret->group = mgroup_upcast_mutable(group);
+ ret->dest_handlers_ = dest_handlers;
+ ret->is_native_ = false; /* If we JIT, it will update this later. */
+ upb_inttable_init(&ret->dispatch, UPB_CTYPE_UINT64);
+
+ if (ret->dest_handlers_) {
+ upb_handlers_ref(ret->dest_handlers_, ret);
+ }
+ return ret;
+}
+
+const upb_handlers *upb_pbdecodermethod_desthandlers(
+ const upb_pbdecodermethod *m) {
+ return m->dest_handlers_;
+}
+
+const upb_byteshandler *upb_pbdecodermethod_inputhandler(
+ const upb_pbdecodermethod *m) {
+ return &m->input_handler_;
+}
+
+bool upb_pbdecodermethod_isnative(const upb_pbdecodermethod *m) {
+ return m->is_native_;
+}
+
+const upb_pbdecodermethod *upb_pbdecodermethod_new(
+ const upb_pbdecodermethodopts *opts, const void *owner) {
+ const upb_pbdecodermethod *ret;
+ upb_pbcodecache cache;
+
+ upb_pbcodecache_init(&cache);
+ ret = upb_pbcodecache_getdecodermethod(&cache, opts);
+ upb_pbdecodermethod_ref(ret, owner);
+ upb_pbcodecache_uninit(&cache);
+ return ret;
+}
+
+
+/* bytecode compiler **********************************************************/
+
+/* Data used only at compilation time. */
+typedef struct {
+ mgroup *group;
+
+ uint32_t *pc;
+ int fwd_labels[MAXLABEL];
+ int back_labels[MAXLABEL];
+
+ /* For fields marked "lazy", parse them lazily or eagerly? */
+ bool lazy;
+} compiler;
+
+static compiler *newcompiler(mgroup *group, bool lazy) {
+ compiler *ret = upb_gmalloc(sizeof(*ret));
+ int i;
+
+ ret->group = group;
+ ret->lazy = lazy;
+ for (i = 0; i < MAXLABEL; i++) {
+ ret->fwd_labels[i] = EMPTYLABEL;
+ ret->back_labels[i] = EMPTYLABEL;
+ }
+ return ret;
+}
+
+static void freecompiler(compiler *c) {
+ upb_gfree(c);
+}
+
+const size_t ptr_words = sizeof(void*) / sizeof(uint32_t);
+
+/* How many words an instruction is. */
+static int instruction_len(uint32_t instr) {
+ switch (getop(instr)) {
+ case OP_SETDISPATCH: return 1 + ptr_words;
+ case OP_TAGN: return 3;
+ case OP_SETBIGGROUPNUM: return 2;
+ default: return 1;
+ }
+}
+
+bool op_has_longofs(int32_t instruction) {
+ switch (getop(instruction)) {
+ case OP_CALL:
+ case OP_BRANCH:
+ case OP_CHECKDELIM:
+ return true;
+ /* The "tag" instructions only have 8 bytes available for the jump target,
+ * but that is ok because these opcodes only require short jumps. */
+ case OP_TAG1:
+ case OP_TAG2:
+ case OP_TAGN:
+ return false;
+ default:
+ UPB_ASSERT(false);
+ return false;
+ }
+}
+
+static int32_t getofs(uint32_t instruction) {
+ if (op_has_longofs(instruction)) {
+ return (int32_t)instruction >> 8;
+ } else {
+ return (int8_t)(instruction >> 8);
+ }
+}
+
+static void setofs(uint32_t *instruction, int32_t ofs) {
+ if (op_has_longofs(*instruction)) {
+ *instruction = getop(*instruction) | ofs << 8;
+ } else {
+ *instruction = (*instruction & ~0xff00) | ((ofs & 0xff) << 8);
+ }
+ UPB_ASSERT(getofs(*instruction) == ofs); /* Would fail in cases of overflow. */
+}
+
+static uint32_t pcofs(compiler *c) { return c->pc - c->group->bytecode; }
+
+/* Defines a local label at the current PC location. All previous forward
+ * references are updated to point to this location. The location is noted
+ * for any future backward references. */
+static void label(compiler *c, unsigned int label) {
+ int val;
+ uint32_t *codep;
+
+ UPB_ASSERT(label < MAXLABEL);
+ val = c->fwd_labels[label];
+ codep = (val == EMPTYLABEL) ? NULL : c->group->bytecode + val;
+ while (codep) {
+ int ofs = getofs(*codep);
+ setofs(codep, c->pc - codep - instruction_len(*codep));
+ codep = ofs ? codep + ofs : NULL;
+ }
+ c->fwd_labels[label] = EMPTYLABEL;
+ c->back_labels[label] = pcofs(c);
+}
+
+/* Creates a reference to a numbered label; either a forward reference
+ * (positive arg) or backward reference (negative arg). For forward references
+ * the value returned now is actually a "next" pointer into a linked list of all
+ * instructions that use this label and will be patched later when the label is
+ * defined with label().
+ *
+ * The returned value is the offset that should be written into the instruction.
+ */
+static int32_t labelref(compiler *c, int label) {
+ UPB_ASSERT(label < MAXLABEL);
+ if (label == LABEL_DISPATCH) {
+ /* No resolving required. */
+ return 0;
+ } else if (label < 0) {
+ /* Backward local label. Relative to the next instruction. */
+ uint32_t from = (c->pc + 1) - c->group->bytecode;
+ return c->back_labels[-label] - from;
+ } else {
+ /* Forward local label: prepend to (possibly-empty) linked list. */
+ int *lptr = &c->fwd_labels[label];
+ int32_t ret = (*lptr == EMPTYLABEL) ? 0 : *lptr - pcofs(c);
+ *lptr = pcofs(c);
+ return ret;
+ }
+}
+
+static void put32(compiler *c, uint32_t v) {
+ mgroup *g = c->group;
+ if (c->pc == g->bytecode_end) {
+ int ofs = pcofs(c);
+ size_t oldsize = g->bytecode_end - g->bytecode;
+ size_t newsize = UPB_MAX(oldsize * 2, 64);
+ /* TODO(haberman): handle OOM. */
+ g->bytecode = upb_grealloc(g->bytecode, oldsize * sizeof(uint32_t),
+ newsize * sizeof(uint32_t));
+ g->bytecode_end = g->bytecode + newsize;
+ c->pc = g->bytecode + ofs;
+ }
+ *c->pc++ = v;
+}
+
+static void putop(compiler *c, opcode op, ...) {
+ va_list ap;
+ va_start(ap, op);
+
+ switch (op) {
+ case OP_SETDISPATCH: {
+ uintptr_t ptr = (uintptr_t)va_arg(ap, void*);
+ put32(c, OP_SETDISPATCH);
+ put32(c, ptr);
+ if (sizeof(uintptr_t) > sizeof(uint32_t))
+ put32(c, (uint64_t)ptr >> 32);
+ break;
+ }
+ case OP_STARTMSG:
+ case OP_ENDMSG:
+ case OP_PUSHLENDELIM:
+ case OP_POP:
+ case OP_SETDELIM:
+ case OP_HALT:
+ case OP_RET:
+ case OP_DISPATCH:
+ put32(c, op);
+ break;
+ case OP_PARSE_DOUBLE:
+ case OP_PARSE_FLOAT:
+ case OP_PARSE_INT64:
+ case OP_PARSE_UINT64:
+ case OP_PARSE_INT32:
+ case OP_PARSE_FIXED64:
+ case OP_PARSE_FIXED32:
+ case OP_PARSE_BOOL:
+ case OP_PARSE_UINT32:
+ case OP_PARSE_SFIXED32:
+ case OP_PARSE_SFIXED64:
+ case OP_PARSE_SINT32:
+ case OP_PARSE_SINT64:
+ case OP_STARTSEQ:
+ case OP_ENDSEQ:
+ case OP_STARTSUBMSG:
+ case OP_ENDSUBMSG:
+ case OP_STARTSTR:
+ case OP_STRING:
+ case OP_ENDSTR:
+ case OP_PUSHTAGDELIM:
+ put32(c, op | va_arg(ap, upb_selector_t) << 8);
+ break;
+ case OP_SETBIGGROUPNUM:
+ put32(c, op);
+ put32(c, va_arg(ap, int));
+ break;
+ case OP_CALL: {
+ const upb_pbdecodermethod *method = va_arg(ap, upb_pbdecodermethod *);
+ put32(c, op | (method->code_base.ofs - (pcofs(c) + 1)) << 8);
+ break;
+ }
+ case OP_CHECKDELIM:
+ case OP_BRANCH: {
+ uint32_t instruction = op;
+ int label = va_arg(ap, int);
+ setofs(&instruction, labelref(c, label));
+ put32(c, instruction);
+ break;
+ }
+ case OP_TAG1:
+ case OP_TAG2: {
+ int label = va_arg(ap, int);
+ uint64_t tag = va_arg(ap, uint64_t);
+ uint32_t instruction = op | (tag << 16);
+ UPB_ASSERT(tag <= 0xffff);
+ setofs(&instruction, labelref(c, label));
+ put32(c, instruction);
+ break;
+ }
+ case OP_TAGN: {
+ int label = va_arg(ap, int);
+ uint64_t tag = va_arg(ap, uint64_t);
+ uint32_t instruction = op | (upb_value_size(tag) << 16);
+ setofs(&instruction, labelref(c, label));
+ put32(c, instruction);
+ put32(c, tag);
+ put32(c, tag >> 32);
+ break;
+ }
+ }
+
+ va_end(ap);
+}
+
+#if defined(UPB_USE_JIT_X64) || defined(UPB_DUMP_BYTECODE)
+
+const char *upb_pbdecoder_getopname(unsigned int op) {
+#define QUOTE(x) #x
+#define EXPAND_AND_QUOTE(x) QUOTE(x)
+#define OPNAME(x) OP_##x
+#define OP(x) case OPNAME(x): return EXPAND_AND_QUOTE(OPNAME(x));
+#define T(x) OP(PARSE_##x)
+ /* Keep in sync with list in decoder.int.h. */
+ switch ((opcode)op) {
+ T(DOUBLE) T(FLOAT) T(INT64) T(UINT64) T(INT32) T(FIXED64) T(FIXED32)
+ T(BOOL) T(UINT32) T(SFIXED32) T(SFIXED64) T(SINT32) T(SINT64)
+ OP(STARTMSG) OP(ENDMSG) OP(STARTSEQ) OP(ENDSEQ) OP(STARTSUBMSG)
+ OP(ENDSUBMSG) OP(STARTSTR) OP(STRING) OP(ENDSTR) OP(CALL) OP(RET)
+ OP(PUSHLENDELIM) OP(PUSHTAGDELIM) OP(SETDELIM) OP(CHECKDELIM)
+ OP(BRANCH) OP(TAG1) OP(TAG2) OP(TAGN) OP(SETDISPATCH) OP(POP)
+ OP(SETBIGGROUPNUM) OP(DISPATCH) OP(HALT)
+ }
+ return "<unknown op>";
+#undef OP
+#undef T
+}
+
+#endif
+
+#ifdef UPB_DUMP_BYTECODE
+
+static void dumpbc(uint32_t *p, uint32_t *end, FILE *f) {
+
+ uint32_t *begin = p;
+
+ while (p < end) {
+ fprintf(f, "%p %8tx", p, p - begin);
+ uint32_t instr = *p++;
+ uint8_t op = getop(instr);
+ fprintf(f, " %s", upb_pbdecoder_getopname(op));
+ switch ((opcode)op) {
+ case OP_SETDISPATCH: {
+ const upb_inttable *dispatch;
+ memcpy(&dispatch, p, sizeof(void*));
+ p += ptr_words;
+ const upb_pbdecodermethod *method =
+ (void *)((char *)dispatch -
+ offsetof(upb_pbdecodermethod, dispatch));
+ fprintf(f, " %s", upb_msgdef_fullname(
+ upb_handlers_msgdef(method->dest_handlers_)));
+ break;
+ }
+ case OP_DISPATCH:
+ case OP_STARTMSG:
+ case OP_ENDMSG:
+ case OP_PUSHLENDELIM:
+ case OP_POP:
+ case OP_SETDELIM:
+ case OP_HALT:
+ case OP_RET:
+ break;
+ case OP_PARSE_DOUBLE:
+ case OP_PARSE_FLOAT:
+ case OP_PARSE_INT64:
+ case OP_PARSE_UINT64:
+ case OP_PARSE_INT32:
+ case OP_PARSE_FIXED64:
+ case OP_PARSE_FIXED32:
+ case OP_PARSE_BOOL:
+ case OP_PARSE_UINT32:
+ case OP_PARSE_SFIXED32:
+ case OP_PARSE_SFIXED64:
+ case OP_PARSE_SINT32:
+ case OP_PARSE_SINT64:
+ case OP_STARTSEQ:
+ case OP_ENDSEQ:
+ case OP_STARTSUBMSG:
+ case OP_ENDSUBMSG:
+ case OP_STARTSTR:
+ case OP_STRING:
+ case OP_ENDSTR:
+ case OP_PUSHTAGDELIM:
+ fprintf(f, " %d", instr >> 8);
+ break;
+ case OP_SETBIGGROUPNUM:
+ fprintf(f, " %d", *p++);
+ break;
+ case OP_CHECKDELIM:
+ case OP_CALL:
+ case OP_BRANCH:
+ fprintf(f, " =>0x%tx", p + getofs(instr) - begin);
+ break;
+ case OP_TAG1:
+ case OP_TAG2: {
+ fprintf(f, " tag:0x%x", instr >> 16);
+ if (getofs(instr)) {
+ fprintf(f, " =>0x%tx", p + getofs(instr) - begin);
+ }
+ break;
+ }
+ case OP_TAGN: {
+ uint64_t tag = *p++;
+ tag |= (uint64_t)*p++ << 32;
+ fprintf(f, " tag:0x%llx", (long long)tag);
+ fprintf(f, " n:%d", instr >> 16);
+ if (getofs(instr)) {
+ fprintf(f, " =>0x%tx", p + getofs(instr) - begin);
+ }
+ break;
+ }
+ }
+ fputs("\n", f);
+ }
+}
+
+#endif
+
+static uint64_t get_encoded_tag(const upb_fielddef *f, int wire_type) {
+ uint32_t tag = (upb_fielddef_number(f) << 3) | wire_type;
+ uint64_t encoded_tag = upb_vencode32(tag);
+ /* No tag should be greater than 5 bytes. */
+ UPB_ASSERT(encoded_tag <= 0xffffffffff);
+ return encoded_tag;
+}
+
+static void putchecktag(compiler *c, const upb_fielddef *f,
+ int wire_type, int dest) {
+ uint64_t tag = get_encoded_tag(f, wire_type);
+ switch (upb_value_size(tag)) {
+ case 1:
+ putop(c, OP_TAG1, dest, tag);
+ break;
+ case 2:
+ putop(c, OP_TAG2, dest, tag);
+ break;
+ default:
+ putop(c, OP_TAGN, dest, tag);
+ break;
+ }
+}
+
+static upb_selector_t getsel(const upb_fielddef *f, upb_handlertype_t type) {
+ upb_selector_t selector;
+ bool ok = upb_handlers_getselector(f, type, &selector);
+ UPB_ASSERT(ok);
+ return selector;
+}
+
+/* Takes an existing, primary dispatch table entry and repacks it with a
+ * different alternate wire type. Called when we are inserting a secondary
+ * dispatch table entry for an alternate wire type. */
+static uint64_t repack(uint64_t dispatch, int new_wt2) {
+ uint64_t ofs;
+ uint8_t wt1;
+ uint8_t old_wt2;
+ upb_pbdecoder_unpackdispatch(dispatch, &ofs, &wt1, &old_wt2);
+ UPB_ASSERT(old_wt2 == NO_WIRE_TYPE); /* wt2 should not be set yet. */
+ return upb_pbdecoder_packdispatch(ofs, wt1, new_wt2);
+}
+
+/* Marks the current bytecode position as the dispatch target for this message,
+ * field, and wire type. */
+static void dispatchtarget(compiler *c, upb_pbdecodermethod *method,
+ const upb_fielddef *f, int wire_type) {
+ /* Offset is relative to msg base. */
+ uint64_t ofs = pcofs(c) - method->code_base.ofs;
+ uint32_t fn = upb_fielddef_number(f);
+ upb_inttable *d = &method->dispatch;
+ upb_value v;
+ if (upb_inttable_remove(d, fn, &v)) {
+ /* TODO: prioritize based on packed setting in .proto file. */
+ uint64_t repacked = repack(upb_value_getuint64(v), wire_type);
+ upb_inttable_insert(d, fn, upb_value_uint64(repacked));
+ upb_inttable_insert(d, fn + UPB_MAX_FIELDNUMBER, upb_value_uint64(ofs));
+ } else {
+ uint64_t val = upb_pbdecoder_packdispatch(ofs, wire_type, NO_WIRE_TYPE);
+ upb_inttable_insert(d, fn, upb_value_uint64(val));
+ }
+}
+
+static void putpush(compiler *c, const upb_fielddef *f) {
+ if (upb_fielddef_descriptortype(f) == UPB_DESCRIPTOR_TYPE_MESSAGE) {
+ putop(c, OP_PUSHLENDELIM);
+ } else {
+ uint32_t fn = upb_fielddef_number(f);
+ if (fn >= 1 << 24) {
+ putop(c, OP_PUSHTAGDELIM, 0);
+ putop(c, OP_SETBIGGROUPNUM, fn);
+ } else {
+ putop(c, OP_PUSHTAGDELIM, fn);
+ }
+ }
+}
+
+static upb_pbdecodermethod *find_submethod(const compiler *c,
+ const upb_pbdecodermethod *method,
+ const upb_fielddef *f) {
+ const upb_handlers *sub =
+ upb_handlers_getsubhandlers(method->dest_handlers_, f);
+ upb_value v;
+ return upb_inttable_lookupptr(&c->group->methods, sub, &v)
+ ? upb_value_getptr(v)
+ : NULL;
+}
+
+static void putsel(compiler *c, opcode op, upb_selector_t sel,
+ const upb_handlers *h) {
+ if (upb_handlers_gethandler(h, sel)) {
+ putop(c, op, sel);
+ }
+}
+
+/* Puts an opcode to call a callback, but only if a callback actually exists for
+ * this field and handler type. */
+static void maybeput(compiler *c, opcode op, const upb_handlers *h,
+ const upb_fielddef *f, upb_handlertype_t type) {
+ putsel(c, op, getsel(f, type), h);
+}
+
+static bool haslazyhandlers(const upb_handlers *h, const upb_fielddef *f) {
+ if (!upb_fielddef_lazy(f))
+ return false;
+
+ return upb_handlers_gethandler(h, getsel(f, UPB_HANDLER_STARTSTR)) ||
+ upb_handlers_gethandler(h, getsel(f, UPB_HANDLER_STRING)) ||
+ upb_handlers_gethandler(h, getsel(f, UPB_HANDLER_ENDSTR));
+}
+
+
+/* bytecode compiler code generation ******************************************/
+
+/* Symbolic names for our local labels. */
+#define LABEL_LOOPSTART 1 /* Top of a repeated field loop. */
+#define LABEL_LOOPBREAK 2 /* To jump out of a repeated loop */
+#define LABEL_FIELD 3 /* Jump backward to find the most recent field. */
+#define LABEL_ENDMSG 4 /* To reach the OP_ENDMSG instr for this msg. */
+
+/* Generates bytecode to parse a single non-lazy message field. */
+static void generate_msgfield(compiler *c, const upb_fielddef *f,
+ upb_pbdecodermethod *method) {
+ const upb_handlers *h = upb_pbdecodermethod_desthandlers(method);
+ const upb_pbdecodermethod *sub_m = find_submethod(c, method, f);
+ int wire_type;
+
+ if (!sub_m) {
+ /* Don't emit any code for this field at all; it will be parsed as an
+ * unknown field.
+ *
+ * TODO(haberman): we should change this to parse it as a string field
+ * instead. It will probably be faster, but more importantly, once we
+ * start vending unknown fields, a field shouldn't be treated as unknown
+ * just because it doesn't have subhandlers registered. */
+ return;
+ }
+
+ label(c, LABEL_FIELD);
+
+ wire_type =
+ (upb_fielddef_descriptortype(f) == UPB_DESCRIPTOR_TYPE_MESSAGE)
+ ? UPB_WIRE_TYPE_DELIMITED
+ : UPB_WIRE_TYPE_START_GROUP;
+
+ if (upb_fielddef_isseq(f)) {
+ putop(c, OP_CHECKDELIM, LABEL_ENDMSG);
+ putchecktag(c, f, wire_type, LABEL_DISPATCH);
+ dispatchtarget(c, method, f, wire_type);
+ putop(c, OP_PUSHTAGDELIM, 0);
+ putop(c, OP_STARTSEQ, getsel(f, UPB_HANDLER_STARTSEQ));
+ label(c, LABEL_LOOPSTART);
+ putpush(c, f);
+ putop(c, OP_STARTSUBMSG, getsel(f, UPB_HANDLER_STARTSUBMSG));
+ putop(c, OP_CALL, sub_m);
+ putop(c, OP_POP);
+ maybeput(c, OP_ENDSUBMSG, h, f, UPB_HANDLER_ENDSUBMSG);
+ if (wire_type == UPB_WIRE_TYPE_DELIMITED) {
+ putop(c, OP_SETDELIM);
+ }
+ putop(c, OP_CHECKDELIM, LABEL_LOOPBREAK);
+ putchecktag(c, f, wire_type, LABEL_LOOPBREAK);
+ putop(c, OP_BRANCH, -LABEL_LOOPSTART);
+ label(c, LABEL_LOOPBREAK);
+ putop(c, OP_POP);
+ maybeput(c, OP_ENDSEQ, h, f, UPB_HANDLER_ENDSEQ);
+ } else {
+ putop(c, OP_CHECKDELIM, LABEL_ENDMSG);
+ putchecktag(c, f, wire_type, LABEL_DISPATCH);
+ dispatchtarget(c, method, f, wire_type);
+ putpush(c, f);
+ putop(c, OP_STARTSUBMSG, getsel(f, UPB_HANDLER_STARTSUBMSG));
+ putop(c, OP_CALL, sub_m);
+ putop(c, OP_POP);
+ maybeput(c, OP_ENDSUBMSG, h, f, UPB_HANDLER_ENDSUBMSG);
+ if (wire_type == UPB_WIRE_TYPE_DELIMITED) {
+ putop(c, OP_SETDELIM);
+ }
+ }
+}
+
+/* Generates bytecode to parse a single string or lazy submessage field. */
+static void generate_delimfield(compiler *c, const upb_fielddef *f,
+ upb_pbdecodermethod *method) {
+ const upb_handlers *h = upb_pbdecodermethod_desthandlers(method);
+
+ label(c, LABEL_FIELD);
+ if (upb_fielddef_isseq(f)) {
+ putop(c, OP_CHECKDELIM, LABEL_ENDMSG);
+ putchecktag(c, f, UPB_WIRE_TYPE_DELIMITED, LABEL_DISPATCH);
+ dispatchtarget(c, method, f, UPB_WIRE_TYPE_DELIMITED);
+ putop(c, OP_PUSHTAGDELIM, 0);
+ putop(c, OP_STARTSEQ, getsel(f, UPB_HANDLER_STARTSEQ));
+ label(c, LABEL_LOOPSTART);
+ putop(c, OP_PUSHLENDELIM);
+ putop(c, OP_STARTSTR, getsel(f, UPB_HANDLER_STARTSTR));
+ /* Need to emit even if no handler to skip past the string. */
+ putop(c, OP_STRING, getsel(f, UPB_HANDLER_STRING));
+ putop(c, OP_POP);
+ maybeput(c, OP_ENDSTR, h, f, UPB_HANDLER_ENDSTR);
+ putop(c, OP_SETDELIM);
+ putop(c, OP_CHECKDELIM, LABEL_LOOPBREAK);
+ putchecktag(c, f, UPB_WIRE_TYPE_DELIMITED, LABEL_LOOPBREAK);
+ putop(c, OP_BRANCH, -LABEL_LOOPSTART);
+ label(c, LABEL_LOOPBREAK);
+ putop(c, OP_POP);
+ maybeput(c, OP_ENDSEQ, h, f, UPB_HANDLER_ENDSEQ);
+ } else {
+ putop(c, OP_CHECKDELIM, LABEL_ENDMSG);
+ putchecktag(c, f, UPB_WIRE_TYPE_DELIMITED, LABEL_DISPATCH);
+ dispatchtarget(c, method, f, UPB_WIRE_TYPE_DELIMITED);
+ putop(c, OP_PUSHLENDELIM);
+ putop(c, OP_STARTSTR, getsel(f, UPB_HANDLER_STARTSTR));
+ putop(c, OP_STRING, getsel(f, UPB_HANDLER_STRING));
+ putop(c, OP_POP);
+ maybeput(c, OP_ENDSTR, h, f, UPB_HANDLER_ENDSTR);
+ putop(c, OP_SETDELIM);
+ }
+}
+
+/* Generates bytecode to parse a single primitive field. */
+static void generate_primitivefield(compiler *c, const upb_fielddef *f,
+ upb_pbdecodermethod *method) {
+ const upb_handlers *h = upb_pbdecodermethod_desthandlers(method);
+ upb_descriptortype_t descriptor_type = upb_fielddef_descriptortype(f);
+ opcode parse_type;
+ upb_selector_t sel;
+ int wire_type;
+
+ label(c, LABEL_FIELD);
+
+ /* From a decoding perspective, ENUM is the same as INT32. */
+ if (descriptor_type == UPB_DESCRIPTOR_TYPE_ENUM)
+ descriptor_type = UPB_DESCRIPTOR_TYPE_INT32;
+
+ parse_type = (opcode)descriptor_type;
+
+ /* TODO(haberman): generate packed or non-packed first depending on "packed"
+ * setting in the fielddef. This will favor (in speed) whichever was
+ * specified. */
+
+ UPB_ASSERT((int)parse_type >= 0 && parse_type <= OP_MAX);
+ sel = getsel(f, upb_handlers_getprimitivehandlertype(f));
+ wire_type = upb_pb_native_wire_types[upb_fielddef_descriptortype(f)];
+ if (upb_fielddef_isseq(f)) {
+ putop(c, OP_CHECKDELIM, LABEL_ENDMSG);
+ putchecktag(c, f, UPB_WIRE_TYPE_DELIMITED, LABEL_DISPATCH);
+ dispatchtarget(c, method, f, UPB_WIRE_TYPE_DELIMITED);
+ putop(c, OP_PUSHLENDELIM);
+ putop(c, OP_STARTSEQ, getsel(f, UPB_HANDLER_STARTSEQ)); /* Packed */
+ label(c, LABEL_LOOPSTART);
+ putop(c, parse_type, sel);
+ putop(c, OP_CHECKDELIM, LABEL_LOOPBREAK);
+ putop(c, OP_BRANCH, -LABEL_LOOPSTART);
+ dispatchtarget(c, method, f, wire_type);
+ putop(c, OP_PUSHTAGDELIM, 0);
+ putop(c, OP_STARTSEQ, getsel(f, UPB_HANDLER_STARTSEQ)); /* Non-packed */
+ label(c, LABEL_LOOPSTART);
+ putop(c, parse_type, sel);
+ putop(c, OP_CHECKDELIM, LABEL_LOOPBREAK);
+ putchecktag(c, f, wire_type, LABEL_LOOPBREAK);
+ putop(c, OP_BRANCH, -LABEL_LOOPSTART);
+ label(c, LABEL_LOOPBREAK);
+ putop(c, OP_POP); /* Packed and non-packed join. */
+ maybeput(c, OP_ENDSEQ, h, f, UPB_HANDLER_ENDSEQ);
+ putop(c, OP_SETDELIM); /* Could remove for non-packed by dup ENDSEQ. */
+ } else {
+ putop(c, OP_CHECKDELIM, LABEL_ENDMSG);
+ putchecktag(c, f, wire_type, LABEL_DISPATCH);
+ dispatchtarget(c, method, f, wire_type);
+ putop(c, parse_type, sel);
+ }
+}
+
+/* Adds bytecode for parsing the given message to the given decoderplan,
+ * while adding all dispatch targets to this message's dispatch table. */
+static void compile_method(compiler *c, upb_pbdecodermethod *method) {
+ const upb_handlers *h;
+ const upb_msgdef *md;
+ uint32_t* start_pc;
+ upb_msg_field_iter i;
+ upb_value val;
+
+ UPB_ASSERT(method);
+
+ /* Clear all entries in the dispatch table. */
+ upb_inttable_uninit(&method->dispatch);
+ upb_inttable_init(&method->dispatch, UPB_CTYPE_UINT64);
+
+ h = upb_pbdecodermethod_desthandlers(method);
+ md = upb_handlers_msgdef(h);
+
+ method->code_base.ofs = pcofs(c);
+ putop(c, OP_SETDISPATCH, &method->dispatch);
+ putsel(c, OP_STARTMSG, UPB_STARTMSG_SELECTOR, h);
+ label(c, LABEL_FIELD);
+ start_pc = c->pc;
+ for(upb_msg_field_begin(&i, md);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ const upb_fielddef *f = upb_msg_iter_field(&i);
+ upb_fieldtype_t type = upb_fielddef_type(f);
+
+ if (type == UPB_TYPE_MESSAGE && !(haslazyhandlers(h, f) && c->lazy)) {
+ generate_msgfield(c, f, method);
+ } else if (type == UPB_TYPE_STRING || type == UPB_TYPE_BYTES ||
+ type == UPB_TYPE_MESSAGE) {
+ generate_delimfield(c, f, method);
+ } else {
+ generate_primitivefield(c, f, method);
+ }
+ }
+
+ /* If there were no fields, or if no handlers were defined, we need to
+ * generate a non-empty loop body so that we can at least dispatch for unknown
+ * fields and check for the end of the message. */
+ if (c->pc == start_pc) {
+ /* Check for end-of-message. */
+ putop(c, OP_CHECKDELIM, LABEL_ENDMSG);
+ /* Unconditionally dispatch. */
+ putop(c, OP_DISPATCH, 0);
+ }
+
+ /* For now we just loop back to the last field of the message (or if none,
+ * the DISPATCH opcode for the message). */
+ putop(c, OP_BRANCH, -LABEL_FIELD);
+
+ /* Insert both a label and a dispatch table entry for this end-of-msg. */
+ label(c, LABEL_ENDMSG);
+ val = upb_value_uint64(pcofs(c) - method->code_base.ofs);
+ upb_inttable_insert(&method->dispatch, DISPATCH_ENDMSG, val);
+
+ putsel(c, OP_ENDMSG, UPB_ENDMSG_SELECTOR, h);
+ putop(c, OP_RET);
+
+ upb_inttable_compact(&method->dispatch);
+}
+
+/* Populate "methods" with new upb_pbdecodermethod objects reachable from "h".
+ * Returns the method for these handlers.
+ *
+ * Generates a new method for every destination handlers reachable from "h". */
+static void find_methods(compiler *c, const upb_handlers *h) {
+ upb_value v;
+ upb_msg_field_iter i;
+ const upb_msgdef *md;
+
+ if (upb_inttable_lookupptr(&c->group->methods, h, &v))
+ return;
+ newmethod(h, c->group);
+
+ /* Find submethods. */
+ md = upb_handlers_msgdef(h);
+ for(upb_msg_field_begin(&i, md);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ const upb_fielddef *f = upb_msg_iter_field(&i);
+ const upb_handlers *sub_h;
+ if (upb_fielddef_type(f) == UPB_TYPE_MESSAGE &&
+ (sub_h = upb_handlers_getsubhandlers(h, f)) != NULL) {
+ /* We only generate a decoder method for submessages with handlers.
+ * Others will be parsed as unknown fields. */
+ find_methods(c, sub_h);
+ }
+ }
+}
+
+/* (Re-)compile bytecode for all messages in "msgs."
+ * Overwrites any existing bytecode in "c". */
+static void compile_methods(compiler *c) {
+ upb_inttable_iter i;
+
+ /* Start over at the beginning of the bytecode. */
+ c->pc = c->group->bytecode;
+
+ upb_inttable_begin(&i, &c->group->methods);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ upb_pbdecodermethod *method = upb_value_getptr(upb_inttable_iter_value(&i));
+ compile_method(c, method);
+ }
+}
+
+static void set_bytecode_handlers(mgroup *g) {
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, &g->methods);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ upb_pbdecodermethod *m = upb_value_getptr(upb_inttable_iter_value(&i));
+ upb_byteshandler *h = &m->input_handler_;
+
+ m->code_base.ptr = g->bytecode + m->code_base.ofs;
+
+ upb_byteshandler_setstartstr(h, upb_pbdecoder_startbc, m->code_base.ptr);
+ upb_byteshandler_setstring(h, upb_pbdecoder_decode, g);
+ upb_byteshandler_setendstr(h, upb_pbdecoder_end, m);
+ }
+}
+
+
+/* JIT setup. *****************************************************************/
+
+#ifdef UPB_USE_JIT_X64
+
+static void sethandlers(mgroup *g, bool allowjit) {
+ g->jit_code = NULL;
+ if (allowjit) {
+ /* Compile byte-code into machine code, create handlers. */
+ upb_pbdecoder_jit(g);
+ } else {
+ set_bytecode_handlers(g);
+ }
+}
+
+#else /* UPB_USE_JIT_X64 */
+
+static void sethandlers(mgroup *g, bool allowjit) {
+ /* No JIT compiled in; use bytecode handlers unconditionally. */
+ UPB_UNUSED(allowjit);
+ set_bytecode_handlers(g);
+}
+
+#endif /* UPB_USE_JIT_X64 */
+
+
+/* TODO(haberman): allow this to be constructed for an arbitrary set of dest
+ * handlers and other mgroups (but verify we have a transitive closure). */
+const mgroup *mgroup_new(const upb_handlers *dest, bool allowjit, bool lazy,
+ const void *owner) {
+ mgroup *g;
+ compiler *c;
+
+ UPB_UNUSED(allowjit);
+ UPB_ASSERT(upb_handlers_isfrozen(dest));
+
+ g = newgroup(owner);
+ c = newcompiler(g, lazy);
+ find_methods(c, dest);
+
+ /* We compile in two passes:
+ * 1. all messages are assigned relative offsets from the beginning of the
+ * bytecode (saved in method->code_base).
+ * 2. forwards OP_CALL instructions can be correctly linked since message
+ * offsets have been previously assigned.
+ *
+ * Could avoid the second pass by linking OP_CALL instructions somehow. */
+ compile_methods(c);
+ compile_methods(c);
+ g->bytecode_end = c->pc;
+ freecompiler(c);
+
+#ifdef UPB_DUMP_BYTECODE
+ {
+ FILE *f = fopen("/tmp/upb-bytecode", "w");
+ UPB_ASSERT(f);
+ dumpbc(g->bytecode, g->bytecode_end, stderr);
+ dumpbc(g->bytecode, g->bytecode_end, f);
+ fclose(f);
+
+ f = fopen("/tmp/upb-bytecode.bin", "wb");
+ UPB_ASSERT(f);
+ fwrite(g->bytecode, 1, g->bytecode_end - g->bytecode, f);
+ fclose(f);
+ }
+#endif
+
+ sethandlers(g, allowjit);
+ return g;
+}
+
+
+/* upb_pbcodecache ************************************************************/
+
+void upb_pbcodecache_init(upb_pbcodecache *c) {
+ upb_inttable_init(&c->groups, UPB_CTYPE_CONSTPTR);
+ c->allow_jit_ = true;
+}
+
+void upb_pbcodecache_uninit(upb_pbcodecache *c) {
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, &c->groups);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ const mgroup *group = upb_value_getconstptr(upb_inttable_iter_value(&i));
+ mgroup_unref(group, c);
+ }
+ upb_inttable_uninit(&c->groups);
+}
+
+bool upb_pbcodecache_allowjit(const upb_pbcodecache *c) {
+ return c->allow_jit_;
+}
+
+bool upb_pbcodecache_setallowjit(upb_pbcodecache *c, bool allow) {
+ if (upb_inttable_count(&c->groups) > 0)
+ return false;
+ c->allow_jit_ = allow;
+ return true;
+}
+
+const upb_pbdecodermethod *upb_pbcodecache_getdecodermethod(
+ upb_pbcodecache *c, const upb_pbdecodermethodopts *opts) {
+ upb_value v;
+ bool ok;
+
+ /* Right now we build a new DecoderMethod every time.
+ * TODO(haberman): properly cache methods by their true key. */
+ const mgroup *g = mgroup_new(opts->handlers, c->allow_jit_, opts->lazy, c);
+ upb_inttable_push(&c->groups, upb_value_constptr(g));
+
+ ok = upb_inttable_lookupptr(&g->methods, opts->handlers, &v);
+ UPB_ASSERT(ok);
+ return upb_value_getptr(v);
+}
+
+
+/* upb_pbdecodermethodopts ****************************************************/
+
+void upb_pbdecodermethodopts_init(upb_pbdecodermethodopts *opts,
+ const upb_handlers *h) {
+ opts->handlers = h;
+ opts->lazy = false;
+}
+
+void upb_pbdecodermethodopts_setlazy(upb_pbdecodermethodopts *opts, bool lazy) {
+ opts->lazy = lazy;
+}
+/*
+** upb::Decoder (Bytecode Decoder VM)
+**
+** Bytecode must previously have been generated using the bytecode compiler in
+** compile_decoder.c. This decoder then walks through the bytecode op-by-op to
+** parse the input.
+**
+** Decoding is fully resumable; we just keep a pointer to the current bytecode
+** instruction and resume from there. A fair amount of the logic here is to
+** handle the fact that values can span buffer seams and we have to be able to
+** be capable of suspending/resuming from any byte in the stream. This
+** sometimes requires keeping a few trailing bytes from the last buffer around
+** in the "residual" buffer.
+*/
+
+#include <inttypes.h>
+#include <stddef.h>
+
+#ifdef UPB_DUMP_BYTECODE
+#include <stdio.h>
+#endif
+
+#define CHECK_SUSPEND(x) if (!(x)) return upb_pbdecoder_suspend(d);
+
+/* Error messages that are shared between the bytecode and JIT decoders. */
+const char *kPbDecoderStackOverflow = "Nesting too deep.";
+const char *kPbDecoderSubmessageTooLong =
+ "Submessage end extends past enclosing submessage.";
+
+/* Error messages shared within this file. */
+static const char *kUnterminatedVarint = "Unterminated varint.";
+
+/* upb_pbdecoder **************************************************************/
+
+static opcode halt = OP_HALT;
+
+/* A dummy character we can point to when the user passes us a NULL buffer.
+ * We need this because in C (NULL + 0) and (NULL - NULL) are undefined
+ * behavior, which would invalidate functions like curbufleft(). */
+static const char dummy_char;
+
+/* Whether an op consumes any of the input buffer. */
+static bool consumes_input(opcode op) {
+ switch (op) {
+ case OP_SETDISPATCH:
+ case OP_STARTMSG:
+ case OP_ENDMSG:
+ case OP_STARTSEQ:
+ case OP_ENDSEQ:
+ case OP_STARTSUBMSG:
+ case OP_ENDSUBMSG:
+ case OP_STARTSTR:
+ case OP_ENDSTR:
+ case OP_PUSHTAGDELIM:
+ case OP_POP:
+ case OP_SETDELIM:
+ case OP_SETBIGGROUPNUM:
+ case OP_CHECKDELIM:
+ case OP_CALL:
+ case OP_RET:
+ case OP_BRANCH:
+ return false;
+ default:
+ return true;
+ }
+}
+
+static size_t stacksize(upb_pbdecoder *d, size_t entries) {
+ UPB_UNUSED(d);
+ return entries * sizeof(upb_pbdecoder_frame);
+}
+
+static size_t callstacksize(upb_pbdecoder *d, size_t entries) {
+ UPB_UNUSED(d);
+
+#ifdef UPB_USE_JIT_X64
+ if (d->method_->is_native_) {
+ /* Each native stack frame needs two pointers, plus we need a few frames for
+ * the enter/exit trampolines. */
+ size_t ret = entries * sizeof(void*) * 2;
+ ret += sizeof(void*) * 10;
+ return ret;
+ }
+#endif
+
+ return entries * sizeof(uint32_t*);
+}
+
+
+static bool in_residual_buf(const upb_pbdecoder *d, const char *p);
+
+/* It's unfortunate that we have to micro-manage the compiler with
+ * UPB_FORCEINLINE and UPB_NOINLINE, especially since this tuning is necessarily
+ * specific to one hardware configuration. But empirically on a Core i7,
+ * performance increases 30-50% with these annotations. Every instance where
+ * these appear, gcc 4.2.1 made the wrong decision and degraded performance in
+ * benchmarks. */
+
+static void seterr(upb_pbdecoder *d, const char *msg) {
+ upb_status status = UPB_STATUS_INIT;
+ upb_status_seterrmsg(&status, msg);
+ upb_env_reporterror(d->env, &status);
+}
+
+void upb_pbdecoder_seterr(upb_pbdecoder *d, const char *msg) {
+ seterr(d, msg);
+}
+
+
+/* Buffering ******************************************************************/
+
+/* We operate on one buffer at a time, which is either the user's buffer passed
+ * to our "decode" callback or some residual bytes from the previous buffer. */
+
+/* How many bytes can be safely read from d->ptr without reading past end-of-buf
+ * or past the current delimited end. */
+static size_t curbufleft(const upb_pbdecoder *d) {
+ UPB_ASSERT(d->data_end >= d->ptr);
+ return d->data_end - d->ptr;
+}
+
+/* How many bytes are available before end-of-buffer. */
+static size_t bufleft(const upb_pbdecoder *d) {
+ return d->end - d->ptr;
+}
+
+/* Overall stream offset of d->ptr. */
+uint64_t offset(const upb_pbdecoder *d) {
+ return d->bufstart_ofs + (d->ptr - d->buf);
+}
+
+/* How many bytes are available before the end of this delimited region. */
+size_t delim_remaining(const upb_pbdecoder *d) {
+ return d->top->end_ofs - offset(d);
+}
+
+/* Advances d->ptr. */
+static void advance(upb_pbdecoder *d, size_t len) {
+ UPB_ASSERT(curbufleft(d) >= len);
+ d->ptr += len;
+}
+
+static bool in_buf(const char *p, const char *buf, const char *end) {
+ return p >= buf && p <= end;
+}
+
+static bool in_residual_buf(const upb_pbdecoder *d, const char *p) {
+ return in_buf(p, d->residual, d->residual_end);
+}
+
+/* Calculates the delim_end value, which is affected by both the current buffer
+ * and the parsing stack, so must be called whenever either is updated. */
+static void set_delim_end(upb_pbdecoder *d) {
+ size_t delim_ofs = d->top->end_ofs - d->bufstart_ofs;
+ if (delim_ofs <= (size_t)(d->end - d->buf)) {
+ d->delim_end = d->buf + delim_ofs;
+ d->data_end = d->delim_end;
+ } else {
+ d->data_end = d->end;
+ d->delim_end = NULL;
+ }
+}
+
+static void switchtobuf(upb_pbdecoder *d, const char *buf, const char *end) {
+ d->ptr = buf;
+ d->buf = buf;
+ d->end = end;
+ set_delim_end(d);
+}
+
+static void advancetobuf(upb_pbdecoder *d, const char *buf, size_t len) {
+ UPB_ASSERT(curbufleft(d) == 0);
+ d->bufstart_ofs += (d->end - d->buf);
+ switchtobuf(d, buf, buf + len);
+}
+
+static void checkpoint(upb_pbdecoder *d) {
+ /* The assertion here is in the interests of efficiency, not correctness.
+ * We are trying to ensure that we don't checkpoint() more often than
+ * necessary. */
+ UPB_ASSERT(d->checkpoint != d->ptr);
+ d->checkpoint = d->ptr;
+}
+
+/* Skips "bytes" bytes in the stream, which may be more than available. If we
+ * skip more bytes than are available, we return a long read count to the caller
+ * indicating how many bytes can be skipped over before passing actual data
+ * again. Skipped bytes can pass a NULL buffer and the decoder guarantees they
+ * won't actually be read.
+ */
+static int32_t skip(upb_pbdecoder *d, size_t bytes) {
+ UPB_ASSERT(!in_residual_buf(d, d->ptr) || d->size_param == 0);
+ UPB_ASSERT(d->skip == 0);
+ if (bytes > delim_remaining(d)) {
+ seterr(d, "Skipped value extended beyond enclosing submessage.");
+ return upb_pbdecoder_suspend(d);
+ } else if (bufleft(d) >= bytes) {
+ /* Skipped data is all in current buffer, and more is still available. */
+ advance(d, bytes);
+ d->skip = 0;
+ return DECODE_OK;
+ } else {
+ /* Skipped data extends beyond currently available buffers. */
+ d->pc = d->last;
+ d->skip = bytes - curbufleft(d);
+ d->bufstart_ofs += (d->end - d->buf);
+ d->residual_end = d->residual;
+ switchtobuf(d, d->residual, d->residual_end);
+ return d->size_param + d->skip;
+ }
+}
+
+
+/* Resumes the decoder from an initial state or from a previous suspend. */
+int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf,
+ size_t size, const upb_bufhandle *handle) {
+ UPB_UNUSED(p); /* Useless; just for the benefit of the JIT. */
+
+ /* d->skip and d->residual_end could probably elegantly be represented
+ * as a single variable, to more easily represent this invariant. */
+ UPB_ASSERT(!(d->skip && d->residual_end > d->residual));
+
+ /* We need to remember the original size_param, so that the value we return
+ * is relative to it, even if we do some skipping first. */
+ d->size_param = size;
+ d->handle = handle;
+
+ /* Have to handle this case specially (ie. not with skip()) because the user
+ * is allowed to pass a NULL buffer here, which won't allow us to safely
+ * calculate a d->end or use our normal functions like curbufleft(). */
+ if (d->skip && d->skip >= size) {
+ d->skip -= size;
+ d->bufstart_ofs += size;
+ buf = &dummy_char;
+ size = 0;
+
+ /* We can't just return now, because we might need to execute some ops
+ * like CHECKDELIM, which could call some callbacks and pop the stack. */
+ }
+
+ /* We need to pretend that this was the actual buffer param, since some of the
+ * calculations assume that d->ptr/d->buf is relative to this. */
+ d->buf_param = buf;
+
+ if (!buf) {
+ /* NULL buf is ok if its entire span is covered by the "skip" above, but
+ * by this point we know that "skip" doesn't cover the buffer. */
+ seterr(d, "Passed NULL buffer over non-skippable region.");
+ return upb_pbdecoder_suspend(d);
+ }
+
+ if (d->residual_end > d->residual) {
+ /* We have residual bytes from the last buffer. */
+ UPB_ASSERT(d->ptr == d->residual);
+ } else {
+ switchtobuf(d, buf, buf + size);
+ }
+
+ d->checkpoint = d->ptr;
+
+ /* Handle skips that don't cover the whole buffer (as above). */
+ if (d->skip) {
+ size_t skip_bytes = d->skip;
+ d->skip = 0;
+ CHECK_RETURN(skip(d, skip_bytes));
+ checkpoint(d);
+ }
+
+ /* If we're inside an unknown group, continue to parse unknown values. */
+ if (d->top->groupnum < 0) {
+ CHECK_RETURN(upb_pbdecoder_skipunknown(d, -1, 0));
+ checkpoint(d);
+ }
+
+ return DECODE_OK;
+}
+
+/* Suspends the decoder at the last checkpoint, without saving any residual
+ * bytes. If there are any unconsumed bytes, returns a short byte count. */
+size_t upb_pbdecoder_suspend(upb_pbdecoder *d) {
+ d->pc = d->last;
+ if (d->checkpoint == d->residual) {
+ /* Checkpoint was in residual buf; no user bytes were consumed. */
+ d->ptr = d->residual;
+ return 0;
+ } else {
+ size_t ret = d->size_param - (d->end - d->checkpoint);
+ UPB_ASSERT(!in_residual_buf(d, d->checkpoint));
+ UPB_ASSERT(d->buf == d->buf_param || d->buf == &dummy_char);
+
+ d->bufstart_ofs += (d->checkpoint - d->buf);
+ d->residual_end = d->residual;
+ switchtobuf(d, d->residual, d->residual_end);
+ return ret;
+ }
+}
+
+/* Suspends the decoder at the last checkpoint, and saves any unconsumed
+ * bytes in our residual buffer. This is necessary if we need more user
+ * bytes to form a complete value, which might not be contiguous in the
+ * user's buffers. Always consumes all user bytes. */
+static size_t suspend_save(upb_pbdecoder *d) {
+ /* We hit end-of-buffer before we could parse a full value.
+ * Save any unconsumed bytes (if any) to the residual buffer. */
+ d->pc = d->last;
+
+ if (d->checkpoint == d->residual) {
+ /* Checkpoint was in residual buf; append user byte(s) to residual buf. */
+ UPB_ASSERT((d->residual_end - d->residual) + d->size_param <=
+ sizeof(d->residual));
+ if (!in_residual_buf(d, d->ptr)) {
+ d->bufstart_ofs -= (d->residual_end - d->residual);
+ }
+ memcpy(d->residual_end, d->buf_param, d->size_param);
+ d->residual_end += d->size_param;
+ } else {
+ /* Checkpoint was in user buf; old residual bytes not needed. */
+ size_t save;
+ UPB_ASSERT(!in_residual_buf(d, d->checkpoint));
+
+ d->ptr = d->checkpoint;
+ save = curbufleft(d);
+ UPB_ASSERT(save <= sizeof(d->residual));
+ memcpy(d->residual, d->ptr, save);
+ d->residual_end = d->residual + save;
+ d->bufstart_ofs = offset(d);
+ }
+
+ switchtobuf(d, d->residual, d->residual_end);
+ return d->size_param;
+}
+
+/* Copies the next "bytes" bytes into "buf" and advances the stream.
+ * Requires that this many bytes are available in the current buffer. */
+UPB_FORCEINLINE static void consumebytes(upb_pbdecoder *d, void *buf,
+ size_t bytes) {
+ UPB_ASSERT(bytes <= curbufleft(d));
+ memcpy(buf, d->ptr, bytes);
+ advance(d, bytes);
+}
+
+/* Slow path for getting the next "bytes" bytes, regardless of whether they are
+ * available in the current buffer or not. Returns a status code as described
+ * in decoder.int.h. */
+UPB_NOINLINE static int32_t getbytes_slow(upb_pbdecoder *d, void *buf,
+ size_t bytes) {
+ const size_t avail = curbufleft(d);
+ consumebytes(d, buf, avail);
+ bytes -= avail;
+ UPB_ASSERT(bytes > 0);
+ if (in_residual_buf(d, d->ptr)) {
+ advancetobuf(d, d->buf_param, d->size_param);
+ }
+ if (curbufleft(d) >= bytes) {
+ consumebytes(d, (char *)buf + avail, bytes);
+ return DECODE_OK;
+ } else if (d->data_end == d->delim_end) {
+ seterr(d, "Submessage ended in the middle of a value or group");
+ return upb_pbdecoder_suspend(d);
+ } else {
+ return suspend_save(d);
+ }
+}
+
+/* Gets the next "bytes" bytes, regardless of whether they are available in the
+ * current buffer or not. Returns a status code as described in decoder.int.h.
+ */
+UPB_FORCEINLINE static int32_t getbytes(upb_pbdecoder *d, void *buf,
+ size_t bytes) {
+ if (curbufleft(d) >= bytes) {
+ /* Buffer has enough data to satisfy. */
+ consumebytes(d, buf, bytes);
+ return DECODE_OK;
+ } else {
+ return getbytes_slow(d, buf, bytes);
+ }
+}
+
+UPB_NOINLINE static size_t peekbytes_slow(upb_pbdecoder *d, void *buf,
+ size_t bytes) {
+ size_t ret = curbufleft(d);
+ memcpy(buf, d->ptr, ret);
+ if (in_residual_buf(d, d->ptr)) {
+ size_t copy = UPB_MIN(bytes - ret, d->size_param);
+ memcpy((char *)buf + ret, d->buf_param, copy);
+ ret += copy;
+ }
+ return ret;
+}
+
+UPB_FORCEINLINE static size_t peekbytes(upb_pbdecoder *d, void *buf,
+ size_t bytes) {
+ if (curbufleft(d) >= bytes) {
+ memcpy(buf, d->ptr, bytes);
+ return bytes;
+ } else {
+ return peekbytes_slow(d, buf, bytes);
+ }
+}
+
+
+/* Decoding of wire types *****************************************************/
+
+/* Slow path for decoding a varint from the current buffer position.
+ * Returns a status code as described in decoder.int.h. */
+UPB_NOINLINE int32_t upb_pbdecoder_decode_varint_slow(upb_pbdecoder *d,
+ uint64_t *u64) {
+ uint8_t byte = 0x80;
+ int bitpos;
+ *u64 = 0;
+ for(bitpos = 0; bitpos < 70 && (byte & 0x80); bitpos += 7) {
+ CHECK_RETURN(getbytes(d, &byte, 1));
+ *u64 |= (uint64_t)(byte & 0x7F) << bitpos;
+ }
+ if(bitpos == 70 && (byte & 0x80)) {
+ seterr(d, kUnterminatedVarint);
+ return upb_pbdecoder_suspend(d);
+ }
+ return DECODE_OK;
+}
+
+/* Decodes a varint from the current buffer position.
+ * Returns a status code as described in decoder.int.h. */
+UPB_FORCEINLINE static int32_t decode_varint(upb_pbdecoder *d, uint64_t *u64) {
+ if (curbufleft(d) > 0 && !(*d->ptr & 0x80)) {
+ *u64 = *d->ptr;
+ advance(d, 1);
+ return DECODE_OK;
+ } else if (curbufleft(d) >= 10) {
+ /* Fast case. */
+ upb_decoderet r = upb_vdecode_fast(d->ptr);
+ if (r.p == NULL) {
+ seterr(d, kUnterminatedVarint);
+ return upb_pbdecoder_suspend(d);
+ }
+ advance(d, r.p - d->ptr);
+ *u64 = r.val;
+ return DECODE_OK;
+ } else {
+ /* Slow case -- varint spans buffer seam. */
+ return upb_pbdecoder_decode_varint_slow(d, u64);
+ }
+}
+
+/* Decodes a 32-bit varint from the current buffer position.
+ * Returns a status code as described in decoder.int.h. */
+UPB_FORCEINLINE static int32_t decode_v32(upb_pbdecoder *d, uint32_t *u32) {
+ uint64_t u64;
+ int32_t ret = decode_varint(d, &u64);
+ if (ret >= 0) return ret;
+ if (u64 > UINT32_MAX) {
+ seterr(d, "Unterminated 32-bit varint");
+ /* TODO(haberman) guarantee that this function return is >= 0 somehow,
+ * so we know this path will always be treated as error by our caller.
+ * Right now the size_t -> int32_t can overflow and produce negative values.
+ */
+ *u32 = 0;
+ return upb_pbdecoder_suspend(d);
+ }
+ *u32 = u64;
+ return DECODE_OK;
+}
+
+/* Decodes a fixed32 from the current buffer position.
+ * Returns a status code as described in decoder.int.h.
+ * TODO: proper byte swapping for big-endian machines. */
+UPB_FORCEINLINE static int32_t decode_fixed32(upb_pbdecoder *d, uint32_t *u32) {
+ return getbytes(d, u32, 4);
+}
+
+/* Decodes a fixed64 from the current buffer position.
+ * Returns a status code as described in decoder.int.h.
+ * TODO: proper byte swapping for big-endian machines. */
+UPB_FORCEINLINE static int32_t decode_fixed64(upb_pbdecoder *d, uint64_t *u64) {
+ return getbytes(d, u64, 8);
+}
+
+/* Non-static versions of the above functions.
+ * These are called by the JIT for fallback paths. */
+int32_t upb_pbdecoder_decode_f32(upb_pbdecoder *d, uint32_t *u32) {
+ return decode_fixed32(d, u32);
+}
+
+int32_t upb_pbdecoder_decode_f64(upb_pbdecoder *d, uint64_t *u64) {
+ return decode_fixed64(d, u64);
+}
+
+static double as_double(uint64_t n) { double d; memcpy(&d, &n, 8); return d; }
+static float as_float(uint32_t n) { float f; memcpy(&f, &n, 4); return f; }
+
+/* Pushes a frame onto the decoder stack. */
+static bool decoder_push(upb_pbdecoder *d, uint64_t end) {
+ upb_pbdecoder_frame *fr = d->top;
+
+ if (end > fr->end_ofs) {
+ seterr(d, kPbDecoderSubmessageTooLong);
+ return false;
+ } else if (fr == d->limit) {
+ seterr(d, kPbDecoderStackOverflow);
+ return false;
+ }
+
+ fr++;
+ fr->end_ofs = end;
+ fr->dispatch = NULL;
+ fr->groupnum = 0;
+ d->top = fr;
+ return true;
+}
+
+static bool pushtagdelim(upb_pbdecoder *d, uint32_t arg) {
+ /* While we expect to see an "end" tag (either ENDGROUP or a non-sequence
+ * field number) prior to hitting any enclosing submessage end, pushing our
+ * existing delim end prevents us from continuing to parse values from a
+ * corrupt proto that doesn't give us an END tag in time. */
+ if (!decoder_push(d, d->top->end_ofs))
+ return false;
+ d->top->groupnum = arg;
+ return true;
+}
+
+/* Pops a frame from the decoder stack. */
+static void decoder_pop(upb_pbdecoder *d) { d->top--; }
+
+UPB_NOINLINE int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d,
+ uint64_t expected) {
+ uint64_t data = 0;
+ size_t bytes = upb_value_size(expected);
+ size_t read = peekbytes(d, &data, bytes);
+ if (read == bytes && data == expected) {
+ /* Advance past matched bytes. */
+ int32_t ok = getbytes(d, &data, read);
+ UPB_ASSERT(ok < 0);
+ return DECODE_OK;
+ } else if (read < bytes && memcmp(&data, &expected, read) == 0) {
+ return suspend_save(d);
+ } else {
+ return DECODE_MISMATCH;
+ }
+}
+
+int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum,
+ uint8_t wire_type) {
+ if (fieldnum >= 0)
+ goto have_tag;
+
+ while (true) {
+ uint32_t tag;
+ CHECK_RETURN(decode_v32(d, &tag));
+ wire_type = tag & 0x7;
+ fieldnum = tag >> 3;
+
+have_tag:
+ if (fieldnum == 0) {
+ seterr(d, "Saw invalid field number (0)");
+ return upb_pbdecoder_suspend(d);
+ }
+
+ /* TODO: deliver to unknown field callback. */
+ switch (wire_type) {
+ case UPB_WIRE_TYPE_32BIT:
+ CHECK_RETURN(skip(d, 4));
+ break;
+ case UPB_WIRE_TYPE_64BIT:
+ CHECK_RETURN(skip(d, 8));
+ break;
+ case UPB_WIRE_TYPE_VARINT: {
+ uint64_t u64;
+ CHECK_RETURN(decode_varint(d, &u64));
+ break;
+ }
+ case UPB_WIRE_TYPE_DELIMITED: {
+ uint32_t len;
+ CHECK_RETURN(decode_v32(d, &len));
+ CHECK_RETURN(skip(d, len));
+ break;
+ }
+ case UPB_WIRE_TYPE_START_GROUP:
+ CHECK_SUSPEND(pushtagdelim(d, -fieldnum));
+ break;
+ case UPB_WIRE_TYPE_END_GROUP:
+ if (fieldnum == -d->top->groupnum) {
+ decoder_pop(d);
+ } else if (fieldnum == d->top->groupnum) {
+ return DECODE_ENDGROUP;
+ } else {
+ seterr(d, "Unmatched ENDGROUP tag.");
+ return upb_pbdecoder_suspend(d);
+ }
+ break;
+ default:
+ seterr(d, "Invalid wire type");
+ return upb_pbdecoder_suspend(d);
+ }
+
+ if (d->top->groupnum >= 0) {
+ return DECODE_OK;
+ }
+
+ /* Unknown group -- continue looping over unknown fields. */
+ checkpoint(d);
+ }
+}
+
+static void goto_endmsg(upb_pbdecoder *d) {
+ upb_value v;
+ bool found = upb_inttable_lookup32(d->top->dispatch, DISPATCH_ENDMSG, &v);
+ UPB_ASSERT(found);
+ d->pc = d->top->base + upb_value_getuint64(v);
+}
+
+/* Parses a tag and jumps to the corresponding bytecode instruction for this
+ * field.
+ *
+ * If the tag is unknown (or the wire type doesn't match), parses the field as
+ * unknown. If the tag is a valid ENDGROUP tag, jumps to the bytecode
+ * instruction for the end of message. */
+static int32_t dispatch(upb_pbdecoder *d) {
+ upb_inttable *dispatch = d->top->dispatch;
+ uint32_t tag;
+ uint8_t wire_type;
+ uint32_t fieldnum;
+ upb_value val;
+ int32_t retval;
+
+ /* Decode tag. */
+ CHECK_RETURN(decode_v32(d, &tag));
+ wire_type = tag & 0x7;
+ fieldnum = tag >> 3;
+
+ /* Lookup tag. Because of packed/non-packed compatibility, we have to
+ * check the wire type against two possibilities. */
+ if (fieldnum != DISPATCH_ENDMSG &&
+ upb_inttable_lookup32(dispatch, fieldnum, &val)) {
+ uint64_t v = upb_value_getuint64(val);
+ if (wire_type == (v & 0xff)) {
+ d->pc = d->top->base + (v >> 16);
+ return DECODE_OK;
+ } else if (wire_type == ((v >> 8) & 0xff)) {
+ bool found =
+ upb_inttable_lookup(dispatch, fieldnum + UPB_MAX_FIELDNUMBER, &val);
+ UPB_ASSERT(found);
+ d->pc = d->top->base + upb_value_getuint64(val);
+ return DECODE_OK;
+ }
+ }
+
+ /* We have some unknown fields (or ENDGROUP) to parse. The DISPATCH or TAG
+ * bytecode that triggered this is preceded by a CHECKDELIM bytecode which
+ * we need to back up to, so that when we're done skipping unknown data we
+ * can re-check the delimited end. */
+ d->last--; /* Necessary if we get suspended */
+ d->pc = d->last;
+ UPB_ASSERT(getop(*d->last) == OP_CHECKDELIM);
+
+ /* Unknown field or ENDGROUP. */
+ retval = upb_pbdecoder_skipunknown(d, fieldnum, wire_type);
+
+ CHECK_RETURN(retval);
+
+ if (retval == DECODE_ENDGROUP) {
+ goto_endmsg(d);
+ return DECODE_OK;
+ }
+
+ return DECODE_OK;
+}
+
+/* Callers know that the stack is more than one deep because the opcodes that
+ * call this only occur after PUSH operations. */
+upb_pbdecoder_frame *outer_frame(upb_pbdecoder *d) {
+ UPB_ASSERT(d->top != d->stack);
+ return d->top - 1;
+}
+
+
+/* The main decoding loop *****************************************************/
+
+/* The main decoder VM function. Uses traditional bytecode dispatch loop with a
+ * switch() statement. */
+size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group,
+ const upb_bufhandle* handle) {
+
+#define VMCASE(op, code) \
+ case op: { code; if (consumes_input(op)) checkpoint(d); break; }
+#define PRIMITIVE_OP(type, wt, name, convfunc, ctype) \
+ VMCASE(OP_PARSE_ ## type, { \
+ ctype val; \
+ CHECK_RETURN(decode_ ## wt(d, &val)); \
+ upb_sink_put ## name(&d->top->sink, arg, (convfunc)(val)); \
+ })
+
+ while(1) {
+ int32_t instruction;
+ opcode op;
+ uint32_t arg;
+ int32_t longofs;
+
+ d->last = d->pc;
+ instruction = *d->pc++;
+ op = getop(instruction);
+ arg = instruction >> 8;
+ longofs = arg;
+ UPB_ASSERT(d->ptr != d->residual_end);
+ UPB_UNUSED(group);
+#ifdef UPB_DUMP_BYTECODE
+ fprintf(stderr, "s_ofs=%d buf_ofs=%d data_rem=%d buf_rem=%d delim_rem=%d "
+ "%x %s (%d)\n",
+ (int)offset(d),
+ (int)(d->ptr - d->buf),
+ (int)(d->data_end - d->ptr),
+ (int)(d->end - d->ptr),
+ (int)((d->top->end_ofs - d->bufstart_ofs) - (d->ptr - d->buf)),
+ (int)(d->pc - 1 - group->bytecode),
+ upb_pbdecoder_getopname(op),
+ arg);
+#endif
+ switch (op) {
+ /* Technically, we are losing data if we see a 32-bit varint that is not
+ * properly sign-extended. We could detect this and error about the data
+ * loss, but proto2 does not do this, so we pass. */
+ PRIMITIVE_OP(INT32, varint, int32, int32_t, uint64_t)
+ PRIMITIVE_OP(INT64, varint, int64, int64_t, uint64_t)
+ PRIMITIVE_OP(UINT32, varint, uint32, uint32_t, uint64_t)
+ PRIMITIVE_OP(UINT64, varint, uint64, uint64_t, uint64_t)
+ PRIMITIVE_OP(FIXED32, fixed32, uint32, uint32_t, uint32_t)
+ PRIMITIVE_OP(FIXED64, fixed64, uint64, uint64_t, uint64_t)
+ PRIMITIVE_OP(SFIXED32, fixed32, int32, int32_t, uint32_t)
+ PRIMITIVE_OP(SFIXED64, fixed64, int64, int64_t, uint64_t)
+ PRIMITIVE_OP(BOOL, varint, bool, bool, uint64_t)
+ PRIMITIVE_OP(DOUBLE, fixed64, double, as_double, uint64_t)
+ PRIMITIVE_OP(FLOAT, fixed32, float, as_float, uint32_t)
+ PRIMITIVE_OP(SINT32, varint, int32, upb_zzdec_32, uint64_t)
+ PRIMITIVE_OP(SINT64, varint, int64, upb_zzdec_64, uint64_t)
+
+ VMCASE(OP_SETDISPATCH,
+ d->top->base = d->pc - 1;
+ memcpy(&d->top->dispatch, d->pc, sizeof(void*));
+ d->pc += sizeof(void*) / sizeof(uint32_t);
+ )
+ VMCASE(OP_STARTMSG,
+ CHECK_SUSPEND(upb_sink_startmsg(&d->top->sink));
+ )
+ VMCASE(OP_ENDMSG,
+ CHECK_SUSPEND(upb_sink_endmsg(&d->top->sink, d->status));
+ )
+ VMCASE(OP_STARTSEQ,
+ upb_pbdecoder_frame *outer = outer_frame(d);
+ CHECK_SUSPEND(upb_sink_startseq(&outer->sink, arg, &d->top->sink));
+ )
+ VMCASE(OP_ENDSEQ,
+ CHECK_SUSPEND(upb_sink_endseq(&d->top->sink, arg));
+ )
+ VMCASE(OP_STARTSUBMSG,
+ upb_pbdecoder_frame *outer = outer_frame(d);
+ CHECK_SUSPEND(upb_sink_startsubmsg(&outer->sink, arg, &d->top->sink));
+ )
+ VMCASE(OP_ENDSUBMSG,
+ CHECK_SUSPEND(upb_sink_endsubmsg(&d->top->sink, arg));
+ )
+ VMCASE(OP_STARTSTR,
+ uint32_t len = delim_remaining(d);
+ upb_pbdecoder_frame *outer = outer_frame(d);
+ CHECK_SUSPEND(upb_sink_startstr(&outer->sink, arg, len, &d->top->sink));
+ if (len == 0) {
+ d->pc++; /* Skip OP_STRING. */
+ }
+ )
+ VMCASE(OP_STRING,
+ uint32_t len = curbufleft(d);
+ size_t n = upb_sink_putstring(&d->top->sink, arg, d->ptr, len, handle);
+ if (n > len) {
+ if (n > delim_remaining(d)) {
+ seterr(d, "Tried to skip past end of string.");
+ return upb_pbdecoder_suspend(d);
+ } else {
+ int32_t ret = skip(d, n);
+ /* This shouldn't return DECODE_OK, because n > len. */
+ UPB_ASSERT(ret >= 0);
+ return ret;
+ }
+ }
+ advance(d, n);
+ if (n < len || d->delim_end == NULL) {
+ /* We aren't finished with this string yet. */
+ d->pc--; /* Repeat OP_STRING. */
+ if (n > 0) checkpoint(d);
+ return upb_pbdecoder_suspend(d);
+ }
+ )
+ VMCASE(OP_ENDSTR,
+ CHECK_SUSPEND(upb_sink_endstr(&d->top->sink, arg));
+ )
+ VMCASE(OP_PUSHTAGDELIM,
+ CHECK_SUSPEND(pushtagdelim(d, arg));
+ )
+ VMCASE(OP_SETBIGGROUPNUM,
+ d->top->groupnum = *d->pc++;
+ )
+ VMCASE(OP_POP,
+ UPB_ASSERT(d->top > d->stack);
+ decoder_pop(d);
+ )
+ VMCASE(OP_PUSHLENDELIM,
+ uint32_t len;
+ CHECK_RETURN(decode_v32(d, &len));
+ CHECK_SUSPEND(decoder_push(d, offset(d) + len));
+ set_delim_end(d);
+ )
+ VMCASE(OP_SETDELIM,
+ set_delim_end(d);
+ )
+ VMCASE(OP_CHECKDELIM,
+ /* We are guaranteed of this assert because we never allow ourselves to
+ * consume bytes beyond data_end, which covers delim_end when non-NULL.
+ */
+ UPB_ASSERT(!(d->delim_end && d->ptr > d->delim_end));
+ if (d->ptr == d->delim_end)
+ d->pc += longofs;
+ )
+ VMCASE(OP_CALL,
+ d->callstack[d->call_len++] = d->pc;
+ d->pc += longofs;
+ )
+ VMCASE(OP_RET,
+ UPB_ASSERT(d->call_len > 0);
+ d->pc = d->callstack[--d->call_len];
+ )
+ VMCASE(OP_BRANCH,
+ d->pc += longofs;
+ )
+ VMCASE(OP_TAG1,
+ uint8_t expected;
+ CHECK_SUSPEND(curbufleft(d) > 0);
+ expected = (arg >> 8) & 0xff;
+ if (*d->ptr == expected) {
+ advance(d, 1);
+ } else {
+ int8_t shortofs;
+ badtag:
+ shortofs = arg;
+ if (shortofs == LABEL_DISPATCH) {
+ CHECK_RETURN(dispatch(d));
+ } else {
+ d->pc += shortofs;
+ break; /* Avoid checkpoint(). */
+ }
+ }
+ )
+ VMCASE(OP_TAG2,
+ uint16_t expected;
+ CHECK_SUSPEND(curbufleft(d) > 0);
+ expected = (arg >> 8) & 0xffff;
+ if (curbufleft(d) >= 2) {
+ uint16_t actual;
+ memcpy(&actual, d->ptr, 2);
+ if (expected == actual) {
+ advance(d, 2);
+ } else {
+ goto badtag;
+ }
+ } else {
+ int32_t result = upb_pbdecoder_checktag_slow(d, expected);
+ if (result == DECODE_MISMATCH) goto badtag;
+ if (result >= 0) return result;
+ }
+ )
+ VMCASE(OP_TAGN, {
+ uint64_t expected;
+ int32_t result;
+ memcpy(&expected, d->pc, 8);
+ d->pc += 2;
+ result = upb_pbdecoder_checktag_slow(d, expected);
+ if (result == DECODE_MISMATCH) goto badtag;
+ if (result >= 0) return result;
+ })
+ VMCASE(OP_DISPATCH, {
+ CHECK_RETURN(dispatch(d));
+ })
+ VMCASE(OP_HALT, {
+ return d->size_param;
+ })
+ }
+ }
+}
+
+
+/* BytesHandler handlers ******************************************************/
+
+void *upb_pbdecoder_startbc(void *closure, const void *pc, size_t size_hint) {
+ upb_pbdecoder *d = closure;
+ UPB_UNUSED(size_hint);
+ d->top->end_ofs = UINT64_MAX;
+ d->bufstart_ofs = 0;
+ d->call_len = 1;
+ d->callstack[0] = &halt;
+ d->pc = pc;
+ d->skip = 0;
+ return d;
+}
+
+void *upb_pbdecoder_startjit(void *closure, const void *hd, size_t size_hint) {
+ upb_pbdecoder *d = closure;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(size_hint);
+ d->top->end_ofs = UINT64_MAX;
+ d->bufstart_ofs = 0;
+ d->call_len = 0;
+ d->skip = 0;
+ return d;
+}
+
+bool upb_pbdecoder_end(void *closure, const void *handler_data) {
+ upb_pbdecoder *d = closure;
+ const upb_pbdecodermethod *method = handler_data;
+ uint64_t end;
+ char dummy;
+
+ if (d->residual_end > d->residual) {
+ seterr(d, "Unexpected EOF: decoder still has buffered unparsed data");
+ return false;
+ }
+
+ if (d->skip) {
+ seterr(d, "Unexpected EOF inside skipped data");
+ return false;
+ }
+
+ if (d->top->end_ofs != UINT64_MAX) {
+ seterr(d, "Unexpected EOF inside delimited string");
+ return false;
+ }
+
+ /* The user's end() call indicates that the message ends here. */
+ end = offset(d);
+ d->top->end_ofs = end;
+
+#ifdef UPB_USE_JIT_X64
+ if (method->is_native_) {
+ const mgroup *group = (const mgroup*)method->group;
+ if (d->top != d->stack)
+ d->stack->end_ofs = 0;
+ group->jit_code(closure, method->code_base.ptr, &dummy, 0, NULL);
+ } else
+#endif
+ {
+ const uint32_t *p = d->pc;
+ d->stack->end_ofs = end;
+ /* Check the previous bytecode, but guard against beginning. */
+ if (p != method->code_base.ptr) p--;
+ if (getop(*p) == OP_CHECKDELIM) {
+ /* Rewind from OP_TAG* to OP_CHECKDELIM. */
+ UPB_ASSERT(getop(*d->pc) == OP_TAG1 ||
+ getop(*d->pc) == OP_TAG2 ||
+ getop(*d->pc) == OP_TAGN ||
+ getop(*d->pc) == OP_DISPATCH);
+ d->pc = p;
+ }
+ upb_pbdecoder_decode(closure, handler_data, &dummy, 0, NULL);
+ }
+
+ if (d->call_len != 0) {
+ seterr(d, "Unexpected EOF inside submessage or group");
+ return false;
+ }
+
+ return true;
+}
+
+size_t upb_pbdecoder_decode(void *decoder, const void *group, const char *buf,
+ size_t size, const upb_bufhandle *handle) {
+ int32_t result = upb_pbdecoder_resume(decoder, NULL, buf, size, handle);
+
+ if (result == DECODE_ENDGROUP) goto_endmsg(decoder);
+ CHECK_RETURN(result);
+
+ return run_decoder_vm(decoder, group, handle);
+}
+
+
+/* Public API *****************************************************************/
+
+void upb_pbdecoder_reset(upb_pbdecoder *d) {
+ d->top = d->stack;
+ d->top->groupnum = 0;
+ d->ptr = d->residual;
+ d->buf = d->residual;
+ d->end = d->residual;
+ d->residual_end = d->residual;
+}
+
+upb_pbdecoder *upb_pbdecoder_create(upb_env *e, const upb_pbdecodermethod *m,
+ upb_sink *sink) {
+ const size_t default_max_nesting = 64;
+#ifndef NDEBUG
+ size_t size_before = upb_env_bytesallocated(e);
+#endif
+
+ upb_pbdecoder *d = upb_env_malloc(e, sizeof(upb_pbdecoder));
+ if (!d) return NULL;
+
+ d->method_ = m;
+ d->callstack = upb_env_malloc(e, callstacksize(d, default_max_nesting));
+ d->stack = upb_env_malloc(e, stacksize(d, default_max_nesting));
+ if (!d->stack || !d->callstack) {
+ return NULL;
+ }
+
+ d->env = e;
+ d->limit = d->stack + default_max_nesting - 1;
+ d->stack_size = default_max_nesting;
+ d->status = NULL;
+
+ upb_pbdecoder_reset(d);
+ upb_bytessink_reset(&d->input_, &m->input_handler_, d);
+
+ UPB_ASSERT(sink);
+ if (d->method_->dest_handlers_) {
+ if (sink->handlers != d->method_->dest_handlers_)
+ return NULL;
+ }
+ upb_sink_reset(&d->top->sink, sink->handlers, sink->closure);
+
+ /* If this fails, increase the value in decoder.h. */
+ UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(e) - size_before <=
+ UPB_PB_DECODER_SIZE);
+ return d;
+}
+
+uint64_t upb_pbdecoder_bytesparsed(const upb_pbdecoder *d) {
+ return offset(d);
+}
+
+const upb_pbdecodermethod *upb_pbdecoder_method(const upb_pbdecoder *d) {
+ return d->method_;
+}
+
+upb_bytessink *upb_pbdecoder_input(upb_pbdecoder *d) {
+ return &d->input_;
+}
+
+size_t upb_pbdecoder_maxnesting(const upb_pbdecoder *d) {
+ return d->stack_size;
+}
+
+bool upb_pbdecoder_setmaxnesting(upb_pbdecoder *d, size_t max) {
+ UPB_ASSERT(d->top >= d->stack);
+
+ if (max < (size_t)(d->top - d->stack)) {
+ /* Can't set a limit smaller than what we are currently at. */
+ return false;
+ }
+
+ if (max > d->stack_size) {
+ /* Need to reallocate stack and callstack to accommodate. */
+ size_t old_size = stacksize(d, d->stack_size);
+ size_t new_size = stacksize(d, max);
+ void *p = upb_env_realloc(d->env, d->stack, old_size, new_size);
+ if (!p) {
+ return false;
+ }
+ d->stack = p;
+
+ old_size = callstacksize(d, d->stack_size);
+ new_size = callstacksize(d, max);
+ p = upb_env_realloc(d->env, d->callstack, old_size, new_size);
+ if (!p) {
+ return false;
+ }
+ d->callstack = p;
+
+ d->stack_size = max;
+ }
+
+ d->limit = d->stack + max - 1;
+ return true;
+}
+/*
+** upb::Encoder
+**
+** Since we are implementing pure handlers (ie. without any out-of-band access
+** to pre-computed lengths), we have to buffer all submessages before we can
+** emit even their first byte.
+**
+** Not knowing the size of submessages also means we can't write a perfect
+** zero-copy implementation, even with buffering. Lengths are stored as
+** varints, which means that we don't know how many bytes to reserve for the
+** length until we know what the length is.
+**
+** This leaves us with three main choices:
+**
+** 1. buffer all submessage data in a temporary buffer, then copy it exactly
+** once into the output buffer.
+**
+** 2. attempt to buffer data directly into the output buffer, estimating how
+** many bytes each length will take. When our guesses are wrong, use
+** memmove() to grow or shrink the allotted space.
+**
+** 3. buffer directly into the output buffer, allocating a max length
+** ahead-of-time for each submessage length. If we overallocated, we waste
+** space, but no memcpy() or memmove() is required. This approach requires
+** defining a maximum size for submessages and rejecting submessages that
+** exceed that size.
+**
+** (2) and (3) have the potential to have better performance, but they are more
+** complicated and subtle to implement:
+**
+** (3) requires making an arbitrary choice of the maximum message size; it
+** wastes space when submessages are shorter than this and fails
+** completely when they are longer. This makes it more finicky and
+** requires configuration based on the input. It also makes it impossible
+** to perfectly match the output of reference encoders that always use the
+** optimal amount of space for each length.
+**
+** (2) requires guessing the the size upfront, and if multiple lengths are
+** guessed wrong the minimum required number of memmove() operations may
+** be complicated to compute correctly. Implemented properly, it may have
+** a useful amortized or average cost, but more investigation is required
+** to determine this and what the optimal algorithm is to achieve it.
+**
+** (1) makes you always pay for exactly one copy, but its implementation is
+** the simplest and its performance is predictable.
+**
+** So for now, we implement (1) only. If we wish to optimize later, we should
+** be able to do it without affecting users.
+**
+** The strategy is to buffer the segments of data that do *not* depend on
+** unknown lengths in one buffer, and keep a separate buffer of segment pointers
+** and lengths. When the top-level submessage ends, we can go beginning to end,
+** alternating the writing of lengths with memcpy() of the rest of the data.
+** At the top level though, no buffering is required.
+*/
+
+
+
+/* The output buffer is divided into segments; a segment is a string of data
+ * that is "ready to go" -- it does not need any varint lengths inserted into
+ * the middle. The seams between segments are where varints will be inserted
+ * once they are known.
+ *
+ * We also use the concept of a "run", which is a range of encoded bytes that
+ * occur at a single submessage level. Every segment contains one or more runs.
+ *
+ * A segment can span messages. Consider:
+ *
+ * .--Submessage lengths---------.
+ * | | |
+ * | V V
+ * V | |--------------- | |-----------------
+ * Submessages: | |-----------------------------------------------
+ * Top-level msg: ------------------------------------------------------------
+ *
+ * Segments: ----- ------------------- -----------------
+ * Runs: *---- *--------------*--- *----------------
+ * (* marks the start)
+ *
+ * Note that the top-level menssage is not in any segment because it does not
+ * have any length preceding it.
+ *
+ * A segment is only interrupted when another length needs to be inserted. So
+ * observe how the second segment spans both the inner submessage and part of
+ * the next enclosing message. */
+typedef struct {
+ uint32_t msglen; /* The length to varint-encode before this segment. */
+ uint32_t seglen; /* Length of the segment. */
+} upb_pb_encoder_segment;
+
+struct upb_pb_encoder {
+ upb_env *env;
+
+ /* Our input and output. */
+ upb_sink input_;
+ upb_bytessink *output_;
+
+ /* The "subclosure" -- used as the inner closure as part of the bytessink
+ * protocol. */
+ void *subc;
+
+ /* The output buffer and limit, and our current write position. "buf"
+ * initially points to "initbuf", but is dynamically allocated if we need to
+ * grow beyond the initial size. */
+ char *buf, *ptr, *limit;
+
+ /* The beginning of the current run, or undefined if we are at the top
+ * level. */
+ char *runbegin;
+
+ /* The list of segments we are accumulating. */
+ upb_pb_encoder_segment *segbuf, *segptr, *seglimit;
+
+ /* The stack of enclosing submessages. Each entry in the stack points to the
+ * segment where this submessage's length is being accumulated. */
+ int *stack, *top, *stacklimit;
+
+ /* Depth of startmsg/endmsg calls. */
+ int depth;
+};
+
+/* low-level buffering ********************************************************/
+
+/* Low-level functions for interacting with the output buffer. */
+
+/* TODO(haberman): handle pushback */
+static void putbuf(upb_pb_encoder *e, const char *buf, size_t len) {
+ size_t n = upb_bytessink_putbuf(e->output_, e->subc, buf, len, NULL);
+ UPB_ASSERT(n == len);
+}
+
+static upb_pb_encoder_segment *top(upb_pb_encoder *e) {
+ return &e->segbuf[*e->top];
+}
+
+/* Call to ensure that at least "bytes" bytes are available for writing at
+ * e->ptr. Returns false if the bytes could not be allocated. */
+static bool reserve(upb_pb_encoder *e, size_t bytes) {
+ if ((size_t)(e->limit - e->ptr) < bytes) {
+ /* Grow buffer. */
+ char *new_buf;
+ size_t needed = bytes + (e->ptr - e->buf);
+ size_t old_size = e->limit - e->buf;
+
+ size_t new_size = old_size;
+
+ while (new_size < needed) {
+ new_size *= 2;
+ }
+
+ new_buf = upb_env_realloc(e->env, e->buf, old_size, new_size);
+
+ if (new_buf == NULL) {
+ return false;
+ }
+
+ e->ptr = new_buf + (e->ptr - e->buf);
+ e->runbegin = new_buf + (e->runbegin - e->buf);
+ e->limit = new_buf + new_size;
+ e->buf = new_buf;
+ }
+
+ return true;
+}
+
+/* Call when "bytes" bytes have been writte at e->ptr. The caller *must* have
+ * previously called reserve() with at least this many bytes. */
+static void encoder_advance(upb_pb_encoder *e, size_t bytes) {
+ UPB_ASSERT((size_t)(e->limit - e->ptr) >= bytes);
+ e->ptr += bytes;
+}
+
+/* Call when all of the bytes for a handler have been written. Flushes the
+ * bytes if possible and necessary, returning false if this failed. */
+static bool commit(upb_pb_encoder *e) {
+ if (!e->top) {
+ /* We aren't inside a delimited region. Flush our accumulated bytes to
+ * the output.
+ *
+ * TODO(haberman): in the future we may want to delay flushing for
+ * efficiency reasons. */
+ putbuf(e, e->buf, e->ptr - e->buf);
+ e->ptr = e->buf;
+ }
+
+ return true;
+}
+
+/* Writes the given bytes to the buffer, handling reserve/advance. */
+static bool encode_bytes(upb_pb_encoder *e, const void *data, size_t len) {
+ if (!reserve(e, len)) {
+ return false;
+ }
+
+ memcpy(e->ptr, data, len);
+ encoder_advance(e, len);
+ return true;
+}
+
+/* Finish the current run by adding the run totals to the segment and message
+ * length. */
+static void accumulate(upb_pb_encoder *e) {
+ size_t run_len;
+ UPB_ASSERT(e->ptr >= e->runbegin);
+ run_len = e->ptr - e->runbegin;
+ e->segptr->seglen += run_len;
+ top(e)->msglen += run_len;
+ e->runbegin = e->ptr;
+}
+
+/* Call to indicate the start of delimited region for which the full length is
+ * not yet known. All data will be buffered until the length is known.
+ * Delimited regions may be nested; their lengths will all be tracked properly. */
+static bool start_delim(upb_pb_encoder *e) {
+ if (e->top) {
+ /* We are already buffering, advance to the next segment and push it on the
+ * stack. */
+ accumulate(e);
+
+ if (++e->top == e->stacklimit) {
+ /* TODO(haberman): grow stack? */
+ return false;
+ }
+
+ if (++e->segptr == e->seglimit) {
+ /* Grow segment buffer. */
+ size_t old_size =
+ (e->seglimit - e->segbuf) * sizeof(upb_pb_encoder_segment);
+ size_t new_size = old_size * 2;
+ upb_pb_encoder_segment *new_buf =
+ upb_env_realloc(e->env, e->segbuf, old_size, new_size);
+
+ if (new_buf == NULL) {
+ return false;
+ }
+
+ e->segptr = new_buf + (e->segptr - e->segbuf);
+ e->seglimit = new_buf + (new_size / sizeof(upb_pb_encoder_segment));
+ e->segbuf = new_buf;
+ }
+ } else {
+ /* We were previously at the top level, start buffering. */
+ e->segptr = e->segbuf;
+ e->top = e->stack;
+ e->runbegin = e->ptr;
+ }
+
+ *e->top = e->segptr - e->segbuf;
+ e->segptr->seglen = 0;
+ e->segptr->msglen = 0;
+
+ return true;
+}
+
+/* Call to indicate the end of a delimited region. We now know the length of
+ * the delimited region. If we are not nested inside any other delimited
+ * regions, we can now emit all of the buffered data we accumulated. */
+static bool end_delim(upb_pb_encoder *e) {
+ size_t msglen;
+ accumulate(e);
+ msglen = top(e)->msglen;
+
+ if (e->top == e->stack) {
+ /* All lengths are now available, emit all buffered data. */
+ char buf[UPB_PB_VARINT_MAX_LEN];
+ upb_pb_encoder_segment *s;
+ const char *ptr = e->buf;
+ for (s = e->segbuf; s <= e->segptr; s++) {
+ size_t lenbytes = upb_vencode64(s->msglen, buf);
+ putbuf(e, buf, lenbytes);
+ putbuf(e, ptr, s->seglen);
+ ptr += s->seglen;
+ }
+
+ e->ptr = e->buf;
+ e->top = NULL;
+ } else {
+ /* Need to keep buffering; propagate length info into enclosing
+ * submessages. */
+ --e->top;
+ top(e)->msglen += msglen + upb_varint_size(msglen);
+ }
+
+ return true;
+}
+
+
+/* tag_t **********************************************************************/
+
+/* A precomputed (pre-encoded) tag and length. */
+
+typedef struct {
+ uint8_t bytes;
+ char tag[7];
+} tag_t;
+
+/* Allocates a new tag for this field, and sets it in these handlerattr. */
+static void new_tag(upb_handlers *h, const upb_fielddef *f, upb_wiretype_t wt,
+ upb_handlerattr *attr) {
+ uint32_t n = upb_fielddef_number(f);
+
+ tag_t *tag = upb_gmalloc(sizeof(tag_t));
+ tag->bytes = upb_vencode64((n << 3) | wt, tag->tag);
+
+ upb_handlerattr_init(attr);
+ upb_handlerattr_sethandlerdata(attr, tag);
+ upb_handlers_addcleanup(h, tag, upb_gfree);
+}
+
+static bool encode_tag(upb_pb_encoder *e, const tag_t *tag) {
+ return encode_bytes(e, tag->tag, tag->bytes);
+}
+
+
+/* encoding of wire types *****************************************************/
+
+static bool encode_fixed64(upb_pb_encoder *e, uint64_t val) {
+ /* TODO(haberman): byte-swap for big endian. */
+ return encode_bytes(e, &val, sizeof(uint64_t));
+}
+
+static bool encode_fixed32(upb_pb_encoder *e, uint32_t val) {
+ /* TODO(haberman): byte-swap for big endian. */
+ return encode_bytes(e, &val, sizeof(uint32_t));
+}
+
+static bool encode_varint(upb_pb_encoder *e, uint64_t val) {
+ if (!reserve(e, UPB_PB_VARINT_MAX_LEN)) {
+ return false;
+ }
+
+ encoder_advance(e, upb_vencode64(val, e->ptr));
+ return true;
+}
+
+static uint64_t dbl2uint64(double d) {
+ uint64_t ret;
+ memcpy(&ret, &d, sizeof(uint64_t));
+ return ret;
+}
+
+static uint32_t flt2uint32(float d) {
+ uint32_t ret;
+ memcpy(&ret, &d, sizeof(uint32_t));
+ return ret;
+}
+
+
+/* encoding of proto types ****************************************************/
+
+static bool startmsg(void *c, const void *hd) {
+ upb_pb_encoder *e = c;
+ UPB_UNUSED(hd);
+ if (e->depth++ == 0) {
+ upb_bytessink_start(e->output_, 0, &e->subc);
+ }
+ return true;
+}
+
+static bool endmsg(void *c, const void *hd, upb_status *status) {
+ upb_pb_encoder *e = c;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(status);
+ if (--e->depth == 0) {
+ upb_bytessink_end(e->output_);
+ }
+ return true;
+}
+
+static void *encode_startdelimfield(void *c, const void *hd) {
+ bool ok = encode_tag(c, hd) && commit(c) && start_delim(c);
+ return ok ? c : UPB_BREAK;
+}
+
+static bool encode_enddelimfield(void *c, const void *hd) {
+ UPB_UNUSED(hd);
+ return end_delim(c);
+}
+
+static void *encode_startgroup(void *c, const void *hd) {
+ return (encode_tag(c, hd) && commit(c)) ? c : UPB_BREAK;
+}
+
+static bool encode_endgroup(void *c, const void *hd) {
+ return encode_tag(c, hd) && commit(c);
+}
+
+static void *encode_startstr(void *c, const void *hd, size_t size_hint) {
+ UPB_UNUSED(size_hint);
+ return encode_startdelimfield(c, hd);
+}
+
+static size_t encode_strbuf(void *c, const void *hd, const char *buf,
+ size_t len, const upb_bufhandle *h) {
+ UPB_UNUSED(hd);
+ UPB_UNUSED(h);
+ return encode_bytes(c, buf, len) ? len : 0;
+}
+
+#define T(type, ctype, convert, encode) \
+ static bool encode_scalar_##type(void *e, const void *hd, ctype val) { \
+ return encode_tag(e, hd) && encode(e, (convert)(val)) && commit(e); \
+ } \
+ static bool encode_packed_##type(void *e, const void *hd, ctype val) { \
+ UPB_UNUSED(hd); \
+ return encode(e, (convert)(val)); \
+ }
+
+T(double, double, dbl2uint64, encode_fixed64)
+T(float, float, flt2uint32, encode_fixed32)
+T(int64, int64_t, uint64_t, encode_varint)
+T(int32, int32_t, uint32_t, encode_varint)
+T(fixed64, uint64_t, uint64_t, encode_fixed64)
+T(fixed32, uint32_t, uint32_t, encode_fixed32)
+T(bool, bool, bool, encode_varint)
+T(uint32, uint32_t, uint32_t, encode_varint)
+T(uint64, uint64_t, uint64_t, encode_varint)
+T(enum, int32_t, uint32_t, encode_varint)
+T(sfixed32, int32_t, uint32_t, encode_fixed32)
+T(sfixed64, int64_t, uint64_t, encode_fixed64)
+T(sint32, int32_t, upb_zzenc_32, encode_varint)
+T(sint64, int64_t, upb_zzenc_64, encode_varint)
+
+#undef T
+
+
+/* code to build the handlers *************************************************/
+
+static void newhandlers_callback(const void *closure, upb_handlers *h) {
+ const upb_msgdef *m;
+ upb_msg_field_iter i;
+
+ UPB_UNUSED(closure);
+
+ upb_handlers_setstartmsg(h, startmsg, NULL);
+ upb_handlers_setendmsg(h, endmsg, NULL);
+
+ m = upb_handlers_msgdef(h);
+ for(upb_msg_field_begin(&i, m);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ const upb_fielddef *f = upb_msg_iter_field(&i);
+ bool packed = upb_fielddef_isseq(f) && upb_fielddef_isprimitive(f) &&
+ upb_fielddef_packed(f);
+ upb_handlerattr attr;
+ upb_wiretype_t wt =
+ packed ? UPB_WIRE_TYPE_DELIMITED
+ : upb_pb_native_wire_types[upb_fielddef_descriptortype(f)];
+
+ /* Pre-encode the tag for this field. */
+ new_tag(h, f, wt, &attr);
+
+ if (packed) {
+ upb_handlers_setstartseq(h, f, encode_startdelimfield, &attr);
+ upb_handlers_setendseq(h, f, encode_enddelimfield, &attr);
+ }
+
+#define T(upper, lower, upbtype) \
+ case UPB_DESCRIPTOR_TYPE_##upper: \
+ if (packed) { \
+ upb_handlers_set##upbtype(h, f, encode_packed_##lower, &attr); \
+ } else { \
+ upb_handlers_set##upbtype(h, f, encode_scalar_##lower, &attr); \
+ } \
+ break;
+
+ switch (upb_fielddef_descriptortype(f)) {
+ T(DOUBLE, double, double);
+ T(FLOAT, float, float);
+ T(INT64, int64, int64);
+ T(INT32, int32, int32);
+ T(FIXED64, fixed64, uint64);
+ T(FIXED32, fixed32, uint32);
+ T(BOOL, bool, bool);
+ T(UINT32, uint32, uint32);
+ T(UINT64, uint64, uint64);
+ T(ENUM, enum, int32);
+ T(SFIXED32, sfixed32, int32);
+ T(SFIXED64, sfixed64, int64);
+ T(SINT32, sint32, int32);
+ T(SINT64, sint64, int64);
+ case UPB_DESCRIPTOR_TYPE_STRING:
+ case UPB_DESCRIPTOR_TYPE_BYTES:
+ upb_handlers_setstartstr(h, f, encode_startstr, &attr);
+ upb_handlers_setendstr(h, f, encode_enddelimfield, &attr);
+ upb_handlers_setstring(h, f, encode_strbuf, &attr);
+ break;
+ case UPB_DESCRIPTOR_TYPE_MESSAGE:
+ upb_handlers_setstartsubmsg(h, f, encode_startdelimfield, &attr);
+ upb_handlers_setendsubmsg(h, f, encode_enddelimfield, &attr);
+ break;
+ case UPB_DESCRIPTOR_TYPE_GROUP: {
+ /* Endgroup takes a different tag (wire_type = END_GROUP). */
+ upb_handlerattr attr2;
+ new_tag(h, f, UPB_WIRE_TYPE_END_GROUP, &attr2);
+
+ upb_handlers_setstartsubmsg(h, f, encode_startgroup, &attr);
+ upb_handlers_setendsubmsg(h, f, encode_endgroup, &attr2);
+
+ upb_handlerattr_uninit(&attr2);
+ break;
+ }
+ }
+
+#undef T
+
+ upb_handlerattr_uninit(&attr);
+ }
+}
+
+void upb_pb_encoder_reset(upb_pb_encoder *e) {
+ e->segptr = NULL;
+ e->top = NULL;
+ e->depth = 0;
+}
+
+
+/* public API *****************************************************************/
+
+const upb_handlers *upb_pb_encoder_newhandlers(const upb_msgdef *m,
+ const void *owner) {
+ return upb_handlers_newfrozen(m, owner, newhandlers_callback, NULL);
+}
+
+upb_pb_encoder *upb_pb_encoder_create(upb_env *env, const upb_handlers *h,
+ upb_bytessink *output) {
+ const size_t initial_bufsize = 256;
+ const size_t initial_segbufsize = 16;
+ /* TODO(haberman): make this configurable. */
+ const size_t stack_size = 64;
+#ifndef NDEBUG
+ const size_t size_before = upb_env_bytesallocated(env);
+#endif
+
+ upb_pb_encoder *e = upb_env_malloc(env, sizeof(upb_pb_encoder));
+ if (!e) return NULL;
+
+ e->buf = upb_env_malloc(env, initial_bufsize);
+ e->segbuf = upb_env_malloc(env, initial_segbufsize * sizeof(*e->segbuf));
+ e->stack = upb_env_malloc(env, stack_size * sizeof(*e->stack));
+
+ if (!e->buf || !e->segbuf || !e->stack) {
+ return NULL;
+ }
+
+ e->limit = e->buf + initial_bufsize;
+ e->seglimit = e->segbuf + initial_segbufsize;
+ e->stacklimit = e->stack + stack_size;
+
+ upb_pb_encoder_reset(e);
+ upb_sink_reset(&e->input_, h, e);
+
+ e->env = env;
+ e->output_ = output;
+ e->subc = output->closure;
+ e->ptr = e->buf;
+
+ /* If this fails, increase the value in encoder.h. */
+ UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(env) - size_before <=
+ UPB_PB_ENCODER_SIZE);
+ return e;
+}
+
+upb_sink *upb_pb_encoder_input(upb_pb_encoder *e) { return &e->input_; }
+
+
+
+upb_filedef **upb_loaddescriptor(const char *buf, size_t n, const void *owner,
+ upb_status *status) {
+ /* Create handlers. */
+ const upb_pbdecodermethod *decoder_m;
+ const upb_handlers *reader_h = upb_descreader_newhandlers(&reader_h);
+ upb_env env;
+ upb_pbdecodermethodopts opts;
+ upb_pbdecoder *decoder;
+ upb_descreader *reader;
+ bool ok;
+ size_t i;
+ upb_filedef **ret = NULL;
+
+ upb_pbdecodermethodopts_init(&opts, reader_h);
+ decoder_m = upb_pbdecodermethod_new(&opts, &decoder_m);
+
+ upb_env_init(&env);
+ upb_env_reporterrorsto(&env, status);
+
+ reader = upb_descreader_create(&env, reader_h);
+ decoder = upb_pbdecoder_create(&env, decoder_m, upb_descreader_input(reader));
+
+ /* Push input data. */
+ ok = upb_bufsrc_putbuf(buf, n, upb_pbdecoder_input(decoder));
+
+ if (!ok) {
+ goto cleanup;
+ }
+
+ ret = upb_gmalloc(sizeof (*ret) * (upb_descreader_filecount(reader) + 1));
+
+ if (!ret) {
+ goto cleanup;
+ }
+
+ for (i = 0; i < upb_descreader_filecount(reader); i++) {
+ ret[i] = upb_descreader_file(reader, i);
+ upb_filedef_ref(ret[i], owner);
+ }
+
+ ret[i] = NULL;
+
+cleanup:
+ upb_env_uninit(&env);
+ upb_handlers_unref(reader_h, &reader_h);
+ upb_pbdecodermethod_unref(decoder_m, &decoder_m);
+ return ret;
+}
+/*
+ * upb::pb::TextPrinter
+ *
+ * OPT: This is not optimized at all. It uses printf() which parses the format
+ * string every time, and it allocates memory for every put.
+ */
+
+
+#include <ctype.h>
+#include <float.h>
+#include <inttypes.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+
+
+struct upb_textprinter {
+ upb_sink input_;
+ upb_bytessink *output_;
+ int indent_depth_;
+ bool single_line_;
+ void *subc;
+};
+
+#define CHECK(x) if ((x) < 0) goto err;
+
+static const char *shortname(const char *longname) {
+ const char *last = strrchr(longname, '.');
+ return last ? last + 1 : longname;
+}
+
+static int indent(upb_textprinter *p) {
+ int i;
+ if (!p->single_line_)
+ for (i = 0; i < p->indent_depth_; i++)
+ upb_bytessink_putbuf(p->output_, p->subc, " ", 2, NULL);
+ return 0;
+}
+
+static int endfield(upb_textprinter *p) {
+ const char ch = (p->single_line_ ? ' ' : '\n');
+ upb_bytessink_putbuf(p->output_, p->subc, &ch, 1, NULL);
+ return 0;
+}
+
+static int putescaped(upb_textprinter *p, const char *buf, size_t len,
+ bool preserve_utf8) {
+ /* Based on CEscapeInternal() from Google's protobuf release. */
+ char dstbuf[4096], *dst = dstbuf, *dstend = dstbuf + sizeof(dstbuf);
+ const char *end = buf + len;
+
+ /* I think hex is prettier and more useful, but proto2 uses octal; should
+ * investigate whether it can parse hex also. */
+ const bool use_hex = false;
+ bool last_hex_escape = false; /* true if last output char was \xNN */
+
+ for (; buf < end; buf++) {
+ bool is_hex_escape;
+
+ if (dstend - dst < 4) {
+ upb_bytessink_putbuf(p->output_, p->subc, dstbuf, dst - dstbuf, NULL);
+ dst = dstbuf;
+ }
+
+ is_hex_escape = false;
+ switch (*buf) {
+ case '\n': *(dst++) = '\\'; *(dst++) = 'n'; break;
+ case '\r': *(dst++) = '\\'; *(dst++) = 'r'; break;
+ case '\t': *(dst++) = '\\'; *(dst++) = 't'; break;
+ case '\"': *(dst++) = '\\'; *(dst++) = '\"'; break;
+ case '\'': *(dst++) = '\\'; *(dst++) = '\''; break;
+ case '\\': *(dst++) = '\\'; *(dst++) = '\\'; break;
+ default:
+ /* Note that if we emit \xNN and the buf character after that is a hex
+ * digit then that digit must be escaped too to prevent it being
+ * interpreted as part of the character code by C. */
+ if ((!preserve_utf8 || (uint8_t)*buf < 0x80) &&
+ (!isprint(*buf) || (last_hex_escape && isxdigit(*buf)))) {
+ sprintf(dst, (use_hex ? "\\x%02x" : "\\%03o"), (uint8_t)*buf);
+ is_hex_escape = use_hex;
+ dst += 4;
+ } else {
+ *(dst++) = *buf; break;
+ }
+ }
+ last_hex_escape = is_hex_escape;
+ }
+ /* Flush remaining data. */
+ upb_bytessink_putbuf(p->output_, p->subc, dstbuf, dst - dstbuf, NULL);
+ return 0;
+}
+
+bool putf(upb_textprinter *p, const char *fmt, ...) {
+ va_list args;
+ va_list args_copy;
+ char *str;
+ int written;
+ int len;
+ bool ok;
+
+ va_start(args, fmt);
+
+ /* Run once to get the length of the string. */
+ _upb_va_copy(args_copy, args);
+ len = _upb_vsnprintf(NULL, 0, fmt, args_copy);
+ va_end(args_copy);
+
+ /* + 1 for NULL terminator (vsprintf() requires it even if we don't). */
+ str = upb_gmalloc(len + 1);
+ if (!str) return false;
+ written = vsprintf(str, fmt, args);
+ va_end(args);
+ UPB_ASSERT(written == len);
+
+ ok = upb_bytessink_putbuf(p->output_, p->subc, str, len, NULL);
+ upb_gfree(str);
+ return ok;
+}
+
+
+/* handlers *******************************************************************/
+
+static bool textprinter_startmsg(void *c, const void *hd) {
+ upb_textprinter *p = c;
+ UPB_UNUSED(hd);
+ if (p->indent_depth_ == 0) {
+ upb_bytessink_start(p->output_, 0, &p->subc);
+ }
+ return true;
+}
+
+static bool textprinter_endmsg(void *c, const void *hd, upb_status *s) {
+ upb_textprinter *p = c;
+ UPB_UNUSED(hd);
+ UPB_UNUSED(s);
+ if (p->indent_depth_ == 0) {
+ upb_bytessink_end(p->output_);
+ }
+ return true;
+}
+
+#define TYPE(name, ctype, fmt) \
+ static bool textprinter_put ## name(void *closure, const void *handler_data, \
+ ctype val) { \
+ upb_textprinter *p = closure; \
+ const upb_fielddef *f = handler_data; \
+ CHECK(indent(p)); \
+ putf(p, "%s: " fmt, upb_fielddef_name(f), val); \
+ CHECK(endfield(p)); \
+ return true; \
+ err: \
+ return false; \
+}
+
+static bool textprinter_putbool(void *closure, const void *handler_data,
+ bool val) {
+ upb_textprinter *p = closure;
+ const upb_fielddef *f = handler_data;
+ CHECK(indent(p));
+ putf(p, "%s: %s", upb_fielddef_name(f), val ? "true" : "false");
+ CHECK(endfield(p));
+ return true;
+err:
+ return false;
+}
+
+#define STRINGIFY_HELPER(x) #x
+#define STRINGIFY_MACROVAL(x) STRINGIFY_HELPER(x)
+
+TYPE(int32, int32_t, "%" PRId32)
+TYPE(int64, int64_t, "%" PRId64)
+TYPE(uint32, uint32_t, "%" PRIu32)
+TYPE(uint64, uint64_t, "%" PRIu64)
+TYPE(float, float, "%." STRINGIFY_MACROVAL(FLT_DIG) "g")
+TYPE(double, double, "%." STRINGIFY_MACROVAL(DBL_DIG) "g")
+
+#undef TYPE
+
+/* Output a symbolic value from the enum if found, else just print as int32. */
+static bool textprinter_putenum(void *closure, const void *handler_data,
+ int32_t val) {
+ upb_textprinter *p = closure;
+ const upb_fielddef *f = handler_data;
+ const upb_enumdef *enum_def = upb_downcast_enumdef(upb_fielddef_subdef(f));
+ const char *label = upb_enumdef_iton(enum_def, val);
+ if (label) {
+ indent(p);
+ putf(p, "%s: %s", upb_fielddef_name(f), label);
+ endfield(p);
+ } else {
+ if (!textprinter_putint32(closure, handler_data, val))
+ return false;
+ }
+ return true;
+}
+
+static void *textprinter_startstr(void *closure, const void *handler_data,
+ size_t size_hint) {
+ upb_textprinter *p = closure;
+ const upb_fielddef *f = handler_data;
+ UPB_UNUSED(size_hint);
+ indent(p);
+ putf(p, "%s: \"", upb_fielddef_name(f));
+ return p;
+}
+
+static bool textprinter_endstr(void *closure, const void *handler_data) {
+ upb_textprinter *p = closure;
+ UPB_UNUSED(handler_data);
+ putf(p, "\"");
+ endfield(p);
+ return true;
+}
+
+static size_t textprinter_putstr(void *closure, const void *hd, const char *buf,
+ size_t len, const upb_bufhandle *handle) {
+ upb_textprinter *p = closure;
+ const upb_fielddef *f = hd;
+ UPB_UNUSED(handle);
+ CHECK(putescaped(p, buf, len, upb_fielddef_type(f) == UPB_TYPE_STRING));
+ return len;
+err:
+ return 0;
+}
+
+static void *textprinter_startsubmsg(void *closure, const void *handler_data) {
+ upb_textprinter *p = closure;
+ const char *name = handler_data;
+ CHECK(indent(p));
+ putf(p, "%s {%c", name, p->single_line_ ? ' ' : '\n');
+ p->indent_depth_++;
+ return p;
+err:
+ return UPB_BREAK;
+}
+
+static bool textprinter_endsubmsg(void *closure, const void *handler_data) {
+ upb_textprinter *p = closure;
+ UPB_UNUSED(handler_data);
+ p->indent_depth_--;
+ CHECK(indent(p));
+ upb_bytessink_putbuf(p->output_, p->subc, "}", 1, NULL);
+ CHECK(endfield(p));
+ return true;
+err:
+ return false;
+}
+
+static void onmreg(const void *c, upb_handlers *h) {
+ const upb_msgdef *m = upb_handlers_msgdef(h);
+ upb_msg_field_iter i;
+ UPB_UNUSED(c);
+
+ upb_handlers_setstartmsg(h, textprinter_startmsg, NULL);
+ upb_handlers_setendmsg(h, textprinter_endmsg, NULL);
+
+ for(upb_msg_field_begin(&i, m);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ upb_fielddef *f = upb_msg_iter_field(&i);
+ upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_handlerattr_sethandlerdata(&attr, f);
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_INT32:
+ upb_handlers_setint32(h, f, textprinter_putint32, &attr);
+ break;
+ case UPB_TYPE_INT64:
+ upb_handlers_setint64(h, f, textprinter_putint64, &attr);
+ break;
+ case UPB_TYPE_UINT32:
+ upb_handlers_setuint32(h, f, textprinter_putuint32, &attr);
+ break;
+ case UPB_TYPE_UINT64:
+ upb_handlers_setuint64(h, f, textprinter_putuint64, &attr);
+ break;
+ case UPB_TYPE_FLOAT:
+ upb_handlers_setfloat(h, f, textprinter_putfloat, &attr);
+ break;
+ case UPB_TYPE_DOUBLE:
+ upb_handlers_setdouble(h, f, textprinter_putdouble, &attr);
+ break;
+ case UPB_TYPE_BOOL:
+ upb_handlers_setbool(h, f, textprinter_putbool, &attr);
+ break;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ upb_handlers_setstartstr(h, f, textprinter_startstr, &attr);
+ upb_handlers_setstring(h, f, textprinter_putstr, &attr);
+ upb_handlers_setendstr(h, f, textprinter_endstr, &attr);
+ break;
+ case UPB_TYPE_MESSAGE: {
+ const char *name =
+ upb_fielddef_istagdelim(f)
+ ? shortname(upb_msgdef_fullname(upb_fielddef_msgsubdef(f)))
+ : upb_fielddef_name(f);
+ upb_handlerattr_sethandlerdata(&attr, name);
+ upb_handlers_setstartsubmsg(h, f, textprinter_startsubmsg, &attr);
+ upb_handlers_setendsubmsg(h, f, textprinter_endsubmsg, &attr);
+ break;
+ }
+ case UPB_TYPE_ENUM:
+ upb_handlers_setint32(h, f, textprinter_putenum, &attr);
+ break;
+ }
+ }
+}
+
+static void textprinter_reset(upb_textprinter *p, bool single_line) {
+ p->single_line_ = single_line;
+ p->indent_depth_ = 0;
+}
+
+
+/* Public API *****************************************************************/
+
+upb_textprinter *upb_textprinter_create(upb_env *env, const upb_handlers *h,
+ upb_bytessink *output) {
+ upb_textprinter *p = upb_env_malloc(env, sizeof(upb_textprinter));
+ if (!p) return NULL;
+
+ p->output_ = output;
+ upb_sink_reset(&p->input_, h, p);
+ textprinter_reset(p, false);
+
+ return p;
+}
+
+const upb_handlers *upb_textprinter_newhandlers(const upb_msgdef *m,
+ const void *owner) {
+ return upb_handlers_newfrozen(m, owner, &onmreg, NULL);
+}
+
+upb_sink *upb_textprinter_input(upb_textprinter *p) { return &p->input_; }
+
+void upb_textprinter_setsingleline(upb_textprinter *p, bool single_line) {
+ p->single_line_ = single_line;
+}
+
+
+/* Index is descriptor type. */
+const uint8_t upb_pb_native_wire_types[] = {
+ UPB_WIRE_TYPE_END_GROUP, /* ENDGROUP */
+ UPB_WIRE_TYPE_64BIT, /* DOUBLE */
+ UPB_WIRE_TYPE_32BIT, /* FLOAT */
+ UPB_WIRE_TYPE_VARINT, /* INT64 */
+ UPB_WIRE_TYPE_VARINT, /* UINT64 */
+ UPB_WIRE_TYPE_VARINT, /* INT32 */
+ UPB_WIRE_TYPE_64BIT, /* FIXED64 */
+ UPB_WIRE_TYPE_32BIT, /* FIXED32 */
+ UPB_WIRE_TYPE_VARINT, /* BOOL */
+ UPB_WIRE_TYPE_DELIMITED, /* STRING */
+ UPB_WIRE_TYPE_START_GROUP, /* GROUP */
+ UPB_WIRE_TYPE_DELIMITED, /* MESSAGE */
+ UPB_WIRE_TYPE_DELIMITED, /* BYTES */
+ UPB_WIRE_TYPE_VARINT, /* UINT32 */
+ UPB_WIRE_TYPE_VARINT, /* ENUM */
+ UPB_WIRE_TYPE_32BIT, /* SFIXED32 */
+ UPB_WIRE_TYPE_64BIT, /* SFIXED64 */
+ UPB_WIRE_TYPE_VARINT, /* SINT32 */
+ UPB_WIRE_TYPE_VARINT, /* SINT64 */
+};
+
+/* A basic branch-based decoder, uses 32-bit values to get good performance
+ * on 32-bit architectures (but performs well on 64-bits also).
+ * This scheme comes from the original Google Protobuf implementation
+ * (proto2). */
+upb_decoderet upb_vdecode_max8_branch32(upb_decoderet r) {
+ upb_decoderet err = {NULL, 0};
+ const char *p = r.p;
+ uint32_t low = (uint32_t)r.val;
+ uint32_t high = 0;
+ uint32_t b;
+ b = *(p++); low |= (b & 0x7fU) << 14; if (!(b & 0x80)) goto done;
+ b = *(p++); low |= (b & 0x7fU) << 21; if (!(b & 0x80)) goto done;
+ b = *(p++); low |= (b & 0x7fU) << 28;
+ high = (b & 0x7fU) >> 4; if (!(b & 0x80)) goto done;
+ b = *(p++); high |= (b & 0x7fU) << 3; if (!(b & 0x80)) goto done;
+ b = *(p++); high |= (b & 0x7fU) << 10; if (!(b & 0x80)) goto done;
+ b = *(p++); high |= (b & 0x7fU) << 17; if (!(b & 0x80)) goto done;
+ b = *(p++); high |= (b & 0x7fU) << 24; if (!(b & 0x80)) goto done;
+ b = *(p++); high |= (b & 0x7fU) << 31; if (!(b & 0x80)) goto done;
+ return err;
+
+done:
+ r.val = ((uint64_t)high << 32) | low;
+ r.p = p;
+ return r;
+}
+
+/* Like the previous, but uses 64-bit values. */
+upb_decoderet upb_vdecode_max8_branch64(upb_decoderet r) {
+ const char *p = r.p;
+ uint64_t val = r.val;
+ uint64_t b;
+ upb_decoderet err = {NULL, 0};
+ b = *(p++); val |= (b & 0x7fU) << 14; if (!(b & 0x80)) goto done;
+ b = *(p++); val |= (b & 0x7fU) << 21; if (!(b & 0x80)) goto done;
+ b = *(p++); val |= (b & 0x7fU) << 28; if (!(b & 0x80)) goto done;
+ b = *(p++); val |= (b & 0x7fU) << 35; if (!(b & 0x80)) goto done;
+ b = *(p++); val |= (b & 0x7fU) << 42; if (!(b & 0x80)) goto done;
+ b = *(p++); val |= (b & 0x7fU) << 49; if (!(b & 0x80)) goto done;
+ b = *(p++); val |= (b & 0x7fU) << 56; if (!(b & 0x80)) goto done;
+ b = *(p++); val |= (b & 0x7fU) << 63; if (!(b & 0x80)) goto done;
+ return err;
+
+done:
+ r.val = val;
+ r.p = p;
+ return r;
+}
+
+/* Given an encoded varint v, returns an integer with a single bit set that
+ * indicates the end of the varint. Subtracting one from this value will
+ * yield a mask that leaves only bits that are part of the varint. Returns
+ * 0 if the varint is unterminated. */
+static uint64_t upb_get_vstopbit(uint64_t v) {
+ uint64_t cbits = v | 0x7f7f7f7f7f7f7f7fULL;
+ return ~cbits & (cbits+1);
+}
+
+/* A branchless decoder. Credit to Pascal Massimino for the bit-twiddling. */
+upb_decoderet upb_vdecode_max8_massimino(upb_decoderet r) {
+ uint64_t b;
+ uint64_t stop_bit;
+ upb_decoderet my_r;
+ memcpy(&b, r.p, sizeof(b));
+ stop_bit = upb_get_vstopbit(b);
+ b = (b & 0x7f7f7f7f7f7f7f7fULL) & (stop_bit - 1);
+ b += b & 0x007f007f007f007fULL;
+ b += 3 * (b & 0x0000ffff0000ffffULL);
+ b += 15 * (b & 0x00000000ffffffffULL);
+ if (stop_bit == 0) {
+ /* Error: unterminated varint. */
+ upb_decoderet err_r = {(void*)0, 0};
+ return err_r;
+ }
+ my_r = upb_decoderet_make(r.p + ((__builtin_ctzll(stop_bit) + 1) / 8),
+ r.val | (b << 7));
+ return my_r;
+}
+
+/* A branchless decoder. Credit to Daniel Wright for the bit-twiddling. */
+upb_decoderet upb_vdecode_max8_wright(upb_decoderet r) {
+ uint64_t b;
+ uint64_t stop_bit;
+ upb_decoderet my_r;
+ memcpy(&b, r.p, sizeof(b));
+ stop_bit = upb_get_vstopbit(b);
+ b &= (stop_bit - 1);
+ b = ((b & 0x7f007f007f007f00ULL) >> 1) | (b & 0x007f007f007f007fULL);
+ b = ((b & 0xffff0000ffff0000ULL) >> 2) | (b & 0x0000ffff0000ffffULL);
+ b = ((b & 0xffffffff00000000ULL) >> 4) | (b & 0x00000000ffffffffULL);
+ if (stop_bit == 0) {
+ /* Error: unterminated varint. */
+ upb_decoderet err_r = {(void*)0, 0};
+ return err_r;
+ }
+ my_r = upb_decoderet_make(r.p + ((__builtin_ctzll(stop_bit) + 1) / 8),
+ r.val | (b << 14));
+ return my_r;
+}
+
+#line 1 "upb/json/parser.rl"
+/*
+** upb::json::Parser (upb_json_parser)
+**
+** A parser that uses the Ragel State Machine Compiler to generate
+** the finite automata.
+**
+** Ragel only natively handles regular languages, but we can manually
+** program it a bit to handle context-free languages like JSON, by using
+** the "fcall" and "fret" constructs.
+**
+** This parser can handle the basics, but needs several things to be fleshed
+** out:
+**
+** - handling of unicode escape sequences (including high surrogate pairs).
+** - properly check and report errors for unknown fields, stack overflow,
+** improper array nesting (or lack of nesting).
+** - handling of base64 sequences with padding characters.
+** - handling of push-back (non-success returns from sink functions).
+** - handling of keys/escape-sequences/etc that span input buffers.
+*/
+
+#include <assert.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+#define UPB_JSON_MAX_DEPTH 64
+
+typedef struct {
+ upb_sink sink;
+
+ /* The current message in which we're parsing, and the field whose value we're
+ * expecting next. */
+ const upb_msgdef *m;
+ const upb_fielddef *f;
+
+ /* The table mapping json name to fielddef for this message. */
+ upb_strtable *name_table;
+
+ /* We are in a repeated-field context, ready to emit mapentries as
+ * submessages. This flag alters the start-of-object (open-brace) behavior to
+ * begin a sequence of mapentry messages rather than a single submessage. */
+ bool is_map;
+
+ /* We are in a map-entry message context. This flag is set when parsing the
+ * value field of a single map entry and indicates to all value-field parsers
+ * (subobjects, strings, numbers, and bools) that the map-entry submessage
+ * should end as soon as the value is parsed. */
+ bool is_mapentry;
+
+ /* If |is_map| or |is_mapentry| is true, |mapfield| refers to the parent
+ * message's map field that we're currently parsing. This differs from |f|
+ * because |f| is the field in the *current* message (i.e., the map-entry
+ * message itself), not the parent's field that leads to this map. */
+ const upb_fielddef *mapfield;
+} upb_jsonparser_frame;
+
+struct upb_json_parser {
+ upb_env *env;
+ const upb_json_parsermethod *method;
+ upb_bytessink input_;
+
+ /* Stack to track the JSON scopes we are in. */
+ upb_jsonparser_frame stack[UPB_JSON_MAX_DEPTH];
+ upb_jsonparser_frame *top;
+ upb_jsonparser_frame *limit;
+
+ upb_status status;
+
+ /* Ragel's internal parsing stack for the parsing state machine. */
+ int current_state;
+ int parser_stack[UPB_JSON_MAX_DEPTH];
+ int parser_top;
+
+ /* The handle for the current buffer. */
+ const upb_bufhandle *handle;
+
+ /* Accumulate buffer. See details in parser.rl. */
+ const char *accumulated;
+ size_t accumulated_len;
+ char *accumulate_buf;
+ size_t accumulate_buf_size;
+
+ /* Multi-part text data. See details in parser.rl. */
+ int multipart_state;
+ upb_selector_t string_selector;
+
+ /* Input capture. See details in parser.rl. */
+ const char *capture;
+
+ /* Intermediate result of parsing a unicode escape sequence. */
+ uint32_t digit;
+};
+
+struct upb_json_parsermethod {
+ upb_refcounted base;
+
+ upb_byteshandler input_handler_;
+
+ /* Mainly for the purposes of refcounting, so all the fielddefs we point
+ * to stay alive. */
+ const upb_msgdef *msg;
+
+ /* Keys are upb_msgdef*, values are upb_strtable (json_name -> fielddef) */
+ upb_inttable name_tables;
+};
+
+#define PARSER_CHECK_RETURN(x) if (!(x)) return false
+
+/* Used to signal that a capture has been suspended. */
+static char suspend_capture;
+
+static upb_selector_t getsel_for_handlertype(upb_json_parser *p,
+ upb_handlertype_t type) {
+ upb_selector_t sel;
+ bool ok = upb_handlers_getselector(p->top->f, type, &sel);
+ UPB_ASSERT(ok);
+ return sel;
+}
+
+static upb_selector_t parser_getsel(upb_json_parser *p) {
+ return getsel_for_handlertype(
+ p, upb_handlers_getprimitivehandlertype(p->top->f));
+}
+
+static bool check_stack(upb_json_parser *p) {
+ if ((p->top + 1) == p->limit) {
+ upb_status_seterrmsg(&p->status, "Nesting too deep");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ return true;
+}
+
+static void set_name_table(upb_json_parser *p, upb_jsonparser_frame *frame) {
+ upb_value v;
+ bool ok = upb_inttable_lookupptr(&p->method->name_tables, frame->m, &v);
+ UPB_ASSERT(ok);
+ frame->name_table = upb_value_getptr(v);
+}
+
+/* There are GCC/Clang built-ins for overflow checking which we could start
+ * using if there was any performance benefit to it. */
+
+static bool checked_add(size_t a, size_t b, size_t *c) {
+ if (SIZE_MAX - a < b) return false;
+ *c = a + b;
+ return true;
+}
+
+static size_t saturating_multiply(size_t a, size_t b) {
+ /* size_t is unsigned, so this is defined behavior even on overflow. */
+ size_t ret = a * b;
+ if (b != 0 && ret / b != a) {
+ ret = SIZE_MAX;
+ }
+ return ret;
+}
+
+
+/* Base64 decoding ************************************************************/
+
+/* TODO(haberman): make this streaming. */
+
+static const signed char b64table[] = {
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 62/*+*/, -1, -1, -1, 63/*/ */,
+ 52/*0*/, 53/*1*/, 54/*2*/, 55/*3*/, 56/*4*/, 57/*5*/, 58/*6*/, 59/*7*/,
+ 60/*8*/, 61/*9*/, -1, -1, -1, -1, -1, -1,
+ -1, 0/*A*/, 1/*B*/, 2/*C*/, 3/*D*/, 4/*E*/, 5/*F*/, 6/*G*/,
+ 07/*H*/, 8/*I*/, 9/*J*/, 10/*K*/, 11/*L*/, 12/*M*/, 13/*N*/, 14/*O*/,
+ 15/*P*/, 16/*Q*/, 17/*R*/, 18/*S*/, 19/*T*/, 20/*U*/, 21/*V*/, 22/*W*/,
+ 23/*X*/, 24/*Y*/, 25/*Z*/, -1, -1, -1, -1, -1,
+ -1, 26/*a*/, 27/*b*/, 28/*c*/, 29/*d*/, 30/*e*/, 31/*f*/, 32/*g*/,
+ 33/*h*/, 34/*i*/, 35/*j*/, 36/*k*/, 37/*l*/, 38/*m*/, 39/*n*/, 40/*o*/,
+ 41/*p*/, 42/*q*/, 43/*r*/, 44/*s*/, 45/*t*/, 46/*u*/, 47/*v*/, 48/*w*/,
+ 49/*x*/, 50/*y*/, 51/*z*/, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1
+};
+
+/* Returns the table value sign-extended to 32 bits. Knowing that the upper
+ * bits will be 1 for unrecognized characters makes it easier to check for
+ * this error condition later (see below). */
+int32_t b64lookup(unsigned char ch) { return b64table[ch]; }
+
+/* Returns true if the given character is not a valid base64 character or
+ * padding. */
+bool nonbase64(unsigned char ch) { return b64lookup(ch) == -1 && ch != '='; }
+
+static bool base64_push(upb_json_parser *p, upb_selector_t sel, const char *ptr,
+ size_t len) {
+ const char *limit = ptr + len;
+ for (; ptr < limit; ptr += 4) {
+ uint32_t val;
+ char output[3];
+
+ if (limit - ptr < 4) {
+ upb_status_seterrf(&p->status,
+ "Base64 input for bytes field not a multiple of 4: %s",
+ upb_fielddef_name(p->top->f));
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ val = b64lookup(ptr[0]) << 18 |
+ b64lookup(ptr[1]) << 12 |
+ b64lookup(ptr[2]) << 6 |
+ b64lookup(ptr[3]);
+
+ /* Test the upper bit; returns true if any of the characters returned -1. */
+ if (val & 0x80000000) {
+ goto otherchar;
+ }
+
+ output[0] = val >> 16;
+ output[1] = (val >> 8) & 0xff;
+ output[2] = val & 0xff;
+ upb_sink_putstring(&p->top->sink, sel, output, 3, NULL);
+ }
+ return true;
+
+otherchar:
+ if (nonbase64(ptr[0]) || nonbase64(ptr[1]) || nonbase64(ptr[2]) ||
+ nonbase64(ptr[3]) ) {
+ upb_status_seterrf(&p->status,
+ "Non-base64 characters in bytes field: %s",
+ upb_fielddef_name(p->top->f));
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ } if (ptr[2] == '=') {
+ uint32_t val;
+ char output;
+
+ /* Last group contains only two input bytes, one output byte. */
+ if (ptr[0] == '=' || ptr[1] == '=' || ptr[3] != '=') {
+ goto badpadding;
+ }
+
+ val = b64lookup(ptr[0]) << 18 |
+ b64lookup(ptr[1]) << 12;
+
+ UPB_ASSERT(!(val & 0x80000000));
+ output = val >> 16;
+ upb_sink_putstring(&p->top->sink, sel, &output, 1, NULL);
+ return true;
+ } else {
+ uint32_t val;
+ char output[2];
+
+ /* Last group contains only three input bytes, two output bytes. */
+ if (ptr[0] == '=' || ptr[1] == '=' || ptr[2] == '=') {
+ goto badpadding;
+ }
+
+ val = b64lookup(ptr[0]) << 18 |
+ b64lookup(ptr[1]) << 12 |
+ b64lookup(ptr[2]) << 6;
+
+ output[0] = val >> 16;
+ output[1] = (val >> 8) & 0xff;
+ upb_sink_putstring(&p->top->sink, sel, output, 2, NULL);
+ return true;
+ }
+
+badpadding:
+ upb_status_seterrf(&p->status,
+ "Incorrect base64 padding for field: %s (%.*s)",
+ upb_fielddef_name(p->top->f),
+ 4, ptr);
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+}
+
+
+/* Accumulate buffer **********************************************************/
+
+/* Functionality for accumulating a buffer.
+ *
+ * Some parts of the parser need an entire value as a contiguous string. For
+ * example, to look up a member name in a hash table, or to turn a string into
+ * a number, the relevant library routines need the input string to be in
+ * contiguous memory, even if the value spanned two or more buffers in the
+ * input. These routines handle that.
+ *
+ * In the common case we can just point to the input buffer to get this
+ * contiguous string and avoid any actual copy. So we optimistically begin
+ * this way. But there are a few cases where we must instead copy into a
+ * separate buffer:
+ *
+ * 1. The string was not contiguous in the input (it spanned buffers).
+ *
+ * 2. The string included escape sequences that need to be interpreted to get
+ * the true value in a contiguous buffer. */
+
+static void assert_accumulate_empty(upb_json_parser *p) {
+ UPB_ASSERT(p->accumulated == NULL);
+ UPB_ASSERT(p->accumulated_len == 0);
+}
+
+static void accumulate_clear(upb_json_parser *p) {
+ p->accumulated = NULL;
+ p->accumulated_len = 0;
+}
+
+/* Used internally by accumulate_append(). */
+static bool accumulate_realloc(upb_json_parser *p, size_t need) {
+ void *mem;
+ size_t old_size = p->accumulate_buf_size;
+ size_t new_size = UPB_MAX(old_size, 128);
+ while (new_size < need) {
+ new_size = saturating_multiply(new_size, 2);
+ }
+
+ mem = upb_env_realloc(p->env, p->accumulate_buf, old_size, new_size);
+ if (!mem) {
+ upb_status_seterrmsg(&p->status, "Out of memory allocating buffer.");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ p->accumulate_buf = mem;
+ p->accumulate_buf_size = new_size;
+ return true;
+}
+
+/* Logically appends the given data to the append buffer.
+ * If "can_alias" is true, we will try to avoid actually copying, but the buffer
+ * must be valid until the next accumulate_append() call (if any). */
+static bool accumulate_append(upb_json_parser *p, const char *buf, size_t len,
+ bool can_alias) {
+ size_t need;
+
+ if (!p->accumulated && can_alias) {
+ p->accumulated = buf;
+ p->accumulated_len = len;
+ return true;
+ }
+
+ if (!checked_add(p->accumulated_len, len, &need)) {
+ upb_status_seterrmsg(&p->status, "Integer overflow.");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ if (need > p->accumulate_buf_size && !accumulate_realloc(p, need)) {
+ return false;
+ }
+
+ if (p->accumulated != p->accumulate_buf) {
+ memcpy(p->accumulate_buf, p->accumulated, p->accumulated_len);
+ p->accumulated = p->accumulate_buf;
+ }
+
+ memcpy(p->accumulate_buf + p->accumulated_len, buf, len);
+ p->accumulated_len += len;
+ return true;
+}
+
+/* Returns a pointer to the data accumulated since the last accumulate_clear()
+ * call, and writes the length to *len. This with point either to the input
+ * buffer or a temporary accumulate buffer. */
+static const char *accumulate_getptr(upb_json_parser *p, size_t *len) {
+ UPB_ASSERT(p->accumulated);
+ *len = p->accumulated_len;
+ return p->accumulated;
+}
+
+
+/* Mult-part text data ********************************************************/
+
+/* When we have text data in the input, it can often come in multiple segments.
+ * For example, there may be some raw string data followed by an escape
+ * sequence. The two segments are processed with different logic. Also buffer
+ * seams in the input can cause multiple segments.
+ *
+ * As we see segments, there are two main cases for how we want to process them:
+ *
+ * 1. we want to push the captured input directly to string handlers.
+ *
+ * 2. we need to accumulate all the parts into a contiguous buffer for further
+ * processing (field name lookup, string->number conversion, etc). */
+
+/* This is the set of states for p->multipart_state. */
+enum {
+ /* We are not currently processing multipart data. */
+ MULTIPART_INACTIVE = 0,
+
+ /* We are processing multipart data by accumulating it into a contiguous
+ * buffer. */
+ MULTIPART_ACCUMULATE = 1,
+
+ /* We are processing multipart data by pushing each part directly to the
+ * current string handlers. */
+ MULTIPART_PUSHEAGERLY = 2
+};
+
+/* Start a multi-part text value where we accumulate the data for processing at
+ * the end. */
+static void multipart_startaccum(upb_json_parser *p) {
+ assert_accumulate_empty(p);
+ UPB_ASSERT(p->multipart_state == MULTIPART_INACTIVE);
+ p->multipart_state = MULTIPART_ACCUMULATE;
+}
+
+/* Start a multi-part text value where we immediately push text data to a string
+ * value with the given selector. */
+static void multipart_start(upb_json_parser *p, upb_selector_t sel) {
+ assert_accumulate_empty(p);
+ UPB_ASSERT(p->multipart_state == MULTIPART_INACTIVE);
+ p->multipart_state = MULTIPART_PUSHEAGERLY;
+ p->string_selector = sel;
+}
+
+static bool multipart_text(upb_json_parser *p, const char *buf, size_t len,
+ bool can_alias) {
+ switch (p->multipart_state) {
+ case MULTIPART_INACTIVE:
+ upb_status_seterrmsg(
+ &p->status, "Internal error: unexpected state MULTIPART_INACTIVE");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+
+ case MULTIPART_ACCUMULATE:
+ if (!accumulate_append(p, buf, len, can_alias)) {
+ return false;
+ }
+ break;
+
+ case MULTIPART_PUSHEAGERLY: {
+ const upb_bufhandle *handle = can_alias ? p->handle : NULL;
+ upb_sink_putstring(&p->top->sink, p->string_selector, buf, len, handle);
+ break;
+ }
+ }
+
+ return true;
+}
+
+/* Note: this invalidates the accumulate buffer! Call only after reading its
+ * contents. */
+static void multipart_end(upb_json_parser *p) {
+ UPB_ASSERT(p->multipart_state != MULTIPART_INACTIVE);
+ p->multipart_state = MULTIPART_INACTIVE;
+ accumulate_clear(p);
+}
+
+
+/* Input capture **************************************************************/
+
+/* Functionality for capturing a region of the input as text. Gracefully
+ * handles the case where a buffer seam occurs in the middle of the captured
+ * region. */
+
+static void capture_begin(upb_json_parser *p, const char *ptr) {
+ UPB_ASSERT(p->multipart_state != MULTIPART_INACTIVE);
+ UPB_ASSERT(p->capture == NULL);
+ p->capture = ptr;
+}
+
+static bool capture_end(upb_json_parser *p, const char *ptr) {
+ UPB_ASSERT(p->capture);
+ if (multipart_text(p, p->capture, ptr - p->capture, true)) {
+ p->capture = NULL;
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/* This is called at the end of each input buffer (ie. when we have hit a
+ * buffer seam). If we are in the middle of capturing the input, this
+ * processes the unprocessed capture region. */
+static void capture_suspend(upb_json_parser *p, const char **ptr) {
+ if (!p->capture) return;
+
+ if (multipart_text(p, p->capture, *ptr - p->capture, false)) {
+ /* We use this as a signal that we were in the middle of capturing, and
+ * that capturing should resume at the beginning of the next buffer.
+ *
+ * We can't use *ptr here, because we have no guarantee that this pointer
+ * will be valid when we resume (if the underlying memory is freed, then
+ * using the pointer at all, even to compare to NULL, is likely undefined
+ * behavior). */
+ p->capture = &suspend_capture;
+ } else {
+ /* Need to back up the pointer to the beginning of the capture, since
+ * we were not able to actually preserve it. */
+ *ptr = p->capture;
+ }
+}
+
+static void capture_resume(upb_json_parser *p, const char *ptr) {
+ if (p->capture) {
+ UPB_ASSERT(p->capture == &suspend_capture);
+ p->capture = ptr;
+ }
+}
+
+
+/* Callbacks from the parser **************************************************/
+
+/* These are the functions called directly from the parser itself.
+ * We define these in the same order as their declarations in the parser. */
+
+static char escape_char(char in) {
+ switch (in) {
+ case 'r': return '\r';
+ case 't': return '\t';
+ case 'n': return '\n';
+ case 'f': return '\f';
+ case 'b': return '\b';
+ case '/': return '/';
+ case '"': return '"';
+ case '\\': return '\\';
+ default:
+ UPB_ASSERT(0);
+ return 'x';
+ }
+}
+
+static bool escape(upb_json_parser *p, const char *ptr) {
+ char ch = escape_char(*ptr);
+ return multipart_text(p, &ch, 1, false);
+}
+
+static void start_hex(upb_json_parser *p) {
+ p->digit = 0;
+}
+
+static void hexdigit(upb_json_parser *p, const char *ptr) {
+ char ch = *ptr;
+
+ p->digit <<= 4;
+
+ if (ch >= '0' && ch <= '9') {
+ p->digit += (ch - '0');
+ } else if (ch >= 'a' && ch <= 'f') {
+ p->digit += ((ch - 'a') + 10);
+ } else {
+ UPB_ASSERT(ch >= 'A' && ch <= 'F');
+ p->digit += ((ch - 'A') + 10);
+ }
+}
+
+static bool end_hex(upb_json_parser *p) {
+ uint32_t codepoint = p->digit;
+
+ /* emit the codepoint as UTF-8. */
+ char utf8[3]; /* support \u0000 -- \uFFFF -- need only three bytes. */
+ int length = 0;
+ if (codepoint <= 0x7F) {
+ utf8[0] = codepoint;
+ length = 1;
+ } else if (codepoint <= 0x07FF) {
+ utf8[1] = (codepoint & 0x3F) | 0x80;
+ codepoint >>= 6;
+ utf8[0] = (codepoint & 0x1F) | 0xC0;
+ length = 2;
+ } else /* codepoint <= 0xFFFF */ {
+ utf8[2] = (codepoint & 0x3F) | 0x80;
+ codepoint >>= 6;
+ utf8[1] = (codepoint & 0x3F) | 0x80;
+ codepoint >>= 6;
+ utf8[0] = (codepoint & 0x0F) | 0xE0;
+ length = 3;
+ }
+ /* TODO(haberman): Handle high surrogates: if codepoint is a high surrogate
+ * we have to wait for the next escape to get the full code point). */
+
+ return multipart_text(p, utf8, length, false);
+}
+
+static void start_text(upb_json_parser *p, const char *ptr) {
+ capture_begin(p, ptr);
+}
+
+static bool end_text(upb_json_parser *p, const char *ptr) {
+ return capture_end(p, ptr);
+}
+
+static void start_number(upb_json_parser *p, const char *ptr) {
+ multipart_startaccum(p);
+ capture_begin(p, ptr);
+}
+
+static bool parse_number(upb_json_parser *p);
+
+static bool end_number(upb_json_parser *p, const char *ptr) {
+ if (!capture_end(p, ptr)) {
+ return false;
+ }
+
+ return parse_number(p);
+}
+
+static bool parse_number(upb_json_parser *p) {
+ size_t len;
+ const char *buf;
+ const char *myend;
+ char *end;
+
+ /* strtol() and friends unfortunately do not support specifying the length of
+ * the input string, so we need to force a copy into a NULL-terminated buffer. */
+ if (!multipart_text(p, "\0", 1, false)) {
+ return false;
+ }
+
+ buf = accumulate_getptr(p, &len);
+ myend = buf + len - 1; /* One for NULL. */
+
+ /* XXX: We are using strtol to parse integers, but this is wrong as even
+ * integers can be represented as 1e6 (for example), which strtol can't
+ * handle correctly.
+ *
+ * XXX: Also, we can't handle large integers properly because strto[u]ll
+ * isn't in C89.
+ *
+ * XXX: Also, we don't properly check floats for overflow, since strtof
+ * isn't in C89. */
+ switch (upb_fielddef_type(p->top->f)) {
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32: {
+ long val = strtol(p->accumulated, &end, 0);
+ if (val > INT32_MAX || val < INT32_MIN || errno == ERANGE || end != myend)
+ goto err;
+ else
+ upb_sink_putint32(&p->top->sink, parser_getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_INT64: {
+ long long val = strtol(p->accumulated, &end, 0);
+ if (val > INT64_MAX || val < INT64_MIN || errno == ERANGE || end != myend)
+ goto err;
+ else
+ upb_sink_putint64(&p->top->sink, parser_getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_UINT32: {
+ unsigned long val = strtoul(p->accumulated, &end, 0);
+ if (val > UINT32_MAX || errno == ERANGE || end != myend)
+ goto err;
+ else
+ upb_sink_putuint32(&p->top->sink, parser_getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_UINT64: {
+ unsigned long long val = strtoul(p->accumulated, &end, 0);
+ if (val > UINT64_MAX || errno == ERANGE || end != myend)
+ goto err;
+ else
+ upb_sink_putuint64(&p->top->sink, parser_getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_DOUBLE: {
+ double val = strtod(p->accumulated, &end);
+ if (errno == ERANGE || end != myend)
+ goto err;
+ else
+ upb_sink_putdouble(&p->top->sink, parser_getsel(p), val);
+ break;
+ }
+ case UPB_TYPE_FLOAT: {
+ float val = strtod(p->accumulated, &end);
+ if (errno == ERANGE || end != myend)
+ goto err;
+ else
+ upb_sink_putfloat(&p->top->sink, parser_getsel(p), val);
+ break;
+ }
+ default:
+ UPB_ASSERT(false);
+ }
+
+ multipart_end(p);
+
+ return true;
+
+err:
+ upb_status_seterrf(&p->status, "error parsing number: %s", buf);
+ upb_env_reporterror(p->env, &p->status);
+ multipart_end(p);
+ return false;
+}
+
+static bool parser_putbool(upb_json_parser *p, bool val) {
+ bool ok;
+
+ if (upb_fielddef_type(p->top->f) != UPB_TYPE_BOOL) {
+ upb_status_seterrf(&p->status,
+ "Boolean value specified for non-bool field: %s",
+ upb_fielddef_name(p->top->f));
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ ok = upb_sink_putbool(&p->top->sink, parser_getsel(p), val);
+ UPB_ASSERT(ok);
+
+ return true;
+}
+
+static bool start_stringval(upb_json_parser *p) {
+ UPB_ASSERT(p->top->f);
+
+ if (upb_fielddef_isstring(p->top->f)) {
+ upb_jsonparser_frame *inner;
+ upb_selector_t sel;
+
+ if (!check_stack(p)) return false;
+
+ /* Start a new parser frame: parser frames correspond one-to-one with
+ * handler frames, and string events occur in a sub-frame. */
+ inner = p->top + 1;
+ sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR);
+ upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink);
+ inner->m = p->top->m;
+ inner->f = p->top->f;
+ inner->name_table = NULL;
+ inner->is_map = false;
+ inner->is_mapentry = false;
+ p->top = inner;
+
+ if (upb_fielddef_type(p->top->f) == UPB_TYPE_STRING) {
+ /* For STRING fields we push data directly to the handlers as it is
+ * parsed. We don't do this yet for BYTES fields, because our base64
+ * decoder is not streaming.
+ *
+ * TODO(haberman): make base64 decoding streaming also. */
+ multipart_start(p, getsel_for_handlertype(p, UPB_HANDLER_STRING));
+ return true;
+ } else {
+ multipart_startaccum(p);
+ return true;
+ }
+ } else if (upb_fielddef_type(p->top->f) == UPB_TYPE_ENUM) {
+ /* No need to push a frame -- symbolic enum names in quotes remain in the
+ * current parser frame.
+ *
+ * Enum string values must accumulate so we can look up the value in a table
+ * once it is complete. */
+ multipart_startaccum(p);
+ return true;
+ } else {
+ upb_status_seterrf(&p->status,
+ "String specified for non-string/non-enum field: %s",
+ upb_fielddef_name(p->top->f));
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+}
+
+static bool end_stringval(upb_json_parser *p) {
+ bool ok = true;
+
+ switch (upb_fielddef_type(p->top->f)) {
+ case UPB_TYPE_BYTES:
+ if (!base64_push(p, getsel_for_handlertype(p, UPB_HANDLER_STRING),
+ p->accumulated, p->accumulated_len)) {
+ return false;
+ }
+ /* Fall through. */
+
+ case UPB_TYPE_STRING: {
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR);
+ p->top--;
+ upb_sink_endstr(&p->top->sink, sel);
+ break;
+ }
+
+ case UPB_TYPE_ENUM: {
+ /* Resolve enum symbolic name to integer value. */
+ const upb_enumdef *enumdef =
+ (const upb_enumdef*)upb_fielddef_subdef(p->top->f);
+
+ size_t len;
+ const char *buf = accumulate_getptr(p, &len);
+
+ int32_t int_val = 0;
+ ok = upb_enumdef_ntoi(enumdef, buf, len, &int_val);
+
+ if (ok) {
+ upb_selector_t sel = parser_getsel(p);
+ upb_sink_putint32(&p->top->sink, sel, int_val);
+ } else {
+ upb_status_seterrf(&p->status, "Enum value unknown: '%.*s'", len, buf);
+ upb_env_reporterror(p->env, &p->status);
+ }
+
+ break;
+ }
+
+ default:
+ UPB_ASSERT(false);
+ upb_status_seterrmsg(&p->status, "Internal error in JSON decoder");
+ upb_env_reporterror(p->env, &p->status);
+ ok = false;
+ break;
+ }
+
+ multipart_end(p);
+
+ return ok;
+}
+
+static void start_member(upb_json_parser *p) {
+ UPB_ASSERT(!p->top->f);
+ multipart_startaccum(p);
+}
+
+/* Helper: invoked during parse_mapentry() to emit the mapentry message's key
+ * field based on the current contents of the accumulate buffer. */
+static bool parse_mapentry_key(upb_json_parser *p) {
+
+ size_t len;
+ const char *buf = accumulate_getptr(p, &len);
+
+ /* Emit the key field. We do a bit of ad-hoc parsing here because the
+ * parser state machine has already decided that this is a string field
+ * name, and we are reinterpreting it as some arbitrary key type. In
+ * particular, integer and bool keys are quoted, so we need to parse the
+ * quoted string contents here. */
+
+ p->top->f = upb_msgdef_itof(p->top->m, UPB_MAPENTRY_KEY);
+ if (p->top->f == NULL) {
+ upb_status_seterrmsg(&p->status, "mapentry message has no key");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+ switch (upb_fielddef_type(p->top->f)) {
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_UINT64:
+ /* Invoke end_number. The accum buffer has the number's text already. */
+ if (!parse_number(p)) {
+ return false;
+ }
+ break;
+ case UPB_TYPE_BOOL:
+ if (len == 4 && !strncmp(buf, "true", 4)) {
+ if (!parser_putbool(p, true)) {
+ return false;
+ }
+ } else if (len == 5 && !strncmp(buf, "false", 5)) {
+ if (!parser_putbool(p, false)) {
+ return false;
+ }
+ } else {
+ upb_status_seterrmsg(&p->status,
+ "Map bool key not 'true' or 'false'");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+ multipart_end(p);
+ break;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ upb_sink subsink;
+ upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR);
+ upb_sink_startstr(&p->top->sink, sel, len, &subsink);
+ sel = getsel_for_handlertype(p, UPB_HANDLER_STRING);
+ upb_sink_putstring(&subsink, sel, buf, len, NULL);
+ sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR);
+ upb_sink_endstr(&p->top->sink, sel);
+ multipart_end(p);
+ break;
+ }
+ default:
+ upb_status_seterrmsg(&p->status, "Invalid field type for map key");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ return true;
+}
+
+/* Helper: emit one map entry (as a submessage in the map field sequence). This
+ * is invoked from end_membername(), at the end of the map entry's key string,
+ * with the map key in the accumulate buffer. It parses the key from that
+ * buffer, emits the handler calls to start the mapentry submessage (setting up
+ * its subframe in the process), and sets up state in the subframe so that the
+ * value parser (invoked next) will emit the mapentry's value field and then
+ * end the mapentry message. */
+
+static bool handle_mapentry(upb_json_parser *p) {
+ const upb_fielddef *mapfield;
+ const upb_msgdef *mapentrymsg;
+ upb_jsonparser_frame *inner;
+ upb_selector_t sel;
+
+ /* Map entry: p->top->sink is the seq frame, so we need to start a frame
+ * for the mapentry itself, and then set |f| in that frame so that the map
+ * value field is parsed, and also set a flag to end the frame after the
+ * map-entry value is parsed. */
+ if (!check_stack(p)) return false;
+
+ mapfield = p->top->mapfield;
+ mapentrymsg = upb_fielddef_msgsubdef(mapfield);
+
+ inner = p->top + 1;
+ p->top->f = mapfield;
+ sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG);
+ upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink);
+ inner->m = mapentrymsg;
+ inner->name_table = NULL;
+ inner->mapfield = mapfield;
+ inner->is_map = false;
+
+ /* Don't set this to true *yet* -- we reuse parsing handlers below to push
+ * the key field value to the sink, and these handlers will pop the frame
+ * if they see is_mapentry (when invoked by the parser state machine, they
+ * would have just seen the map-entry value, not key). */
+ inner->is_mapentry = false;
+ p->top = inner;
+
+ /* send STARTMSG in submsg frame. */
+ upb_sink_startmsg(&p->top->sink);
+
+ parse_mapentry_key(p);
+
+ /* Set up the value field to receive the map-entry value. */
+ p->top->f = upb_msgdef_itof(p->top->m, UPB_MAPENTRY_VALUE);
+ p->top->is_mapentry = true; /* set up to pop frame after value is parsed. */
+ p->top->mapfield = mapfield;
+ if (p->top->f == NULL) {
+ upb_status_seterrmsg(&p->status, "mapentry message has no value");
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ return true;
+}
+
+static bool end_membername(upb_json_parser *p) {
+ UPB_ASSERT(!p->top->f);
+
+ if (p->top->is_map) {
+ return handle_mapentry(p);
+ } else {
+ size_t len;
+ const char *buf = accumulate_getptr(p, &len);
+ upb_value v;
+
+ if (upb_strtable_lookup2(p->top->name_table, buf, len, &v)) {
+ p->top->f = upb_value_getconstptr(v);
+ multipart_end(p);
+
+ return true;
+ } else {
+ /* TODO(haberman): Ignore unknown fields if requested/configured to do
+ * so. */
+ upb_status_seterrf(&p->status, "No such field: %.*s\n", (int)len, buf);
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+ }
+}
+
+static void end_member(upb_json_parser *p) {
+ /* If we just parsed a map-entry value, end that frame too. */
+ if (p->top->is_mapentry) {
+ upb_status s = UPB_STATUS_INIT;
+ upb_selector_t sel;
+ bool ok;
+ const upb_fielddef *mapfield;
+
+ UPB_ASSERT(p->top > p->stack);
+ /* send ENDMSG on submsg. */
+ upb_sink_endmsg(&p->top->sink, &s);
+ mapfield = p->top->mapfield;
+
+ /* send ENDSUBMSG in repeated-field-of-mapentries frame. */
+ p->top--;
+ ok = upb_handlers_getselector(mapfield, UPB_HANDLER_ENDSUBMSG, &sel);
+ UPB_ASSERT(ok);
+ upb_sink_endsubmsg(&p->top->sink, sel);
+ }
+
+ p->top->f = NULL;
+}
+
+static bool start_subobject(upb_json_parser *p) {
+ UPB_ASSERT(p->top->f);
+
+ if (upb_fielddef_ismap(p->top->f)) {
+ upb_jsonparser_frame *inner;
+ upb_selector_t sel;
+
+ /* Beginning of a map. Start a new parser frame in a repeated-field
+ * context. */
+ if (!check_stack(p)) return false;
+
+ inner = p->top + 1;
+ sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ);
+ upb_sink_startseq(&p->top->sink, sel, &inner->sink);
+ inner->m = upb_fielddef_msgsubdef(p->top->f);
+ inner->name_table = NULL;
+ inner->mapfield = p->top->f;
+ inner->f = NULL;
+ inner->is_map = true;
+ inner->is_mapentry = false;
+ p->top = inner;
+
+ return true;
+ } else if (upb_fielddef_issubmsg(p->top->f)) {
+ upb_jsonparser_frame *inner;
+ upb_selector_t sel;
+
+ /* Beginning of a subobject. Start a new parser frame in the submsg
+ * context. */
+ if (!check_stack(p)) return false;
+
+ inner = p->top + 1;
+
+ sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG);
+ upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink);
+ inner->m = upb_fielddef_msgsubdef(p->top->f);
+ set_name_table(p, inner);
+ inner->f = NULL;
+ inner->is_map = false;
+ inner->is_mapentry = false;
+ p->top = inner;
+
+ return true;
+ } else {
+ upb_status_seterrf(&p->status,
+ "Object specified for non-message/group field: %s",
+ upb_fielddef_name(p->top->f));
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+}
+
+static void end_subobject(upb_json_parser *p) {
+ if (p->top->is_map) {
+ upb_selector_t sel;
+ p->top--;
+ sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ);
+ upb_sink_endseq(&p->top->sink, sel);
+ } else {
+ upb_selector_t sel;
+ p->top--;
+ sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSUBMSG);
+ upb_sink_endsubmsg(&p->top->sink, sel);
+ }
+}
+
+static bool start_array(upb_json_parser *p) {
+ upb_jsonparser_frame *inner;
+ upb_selector_t sel;
+
+ UPB_ASSERT(p->top->f);
+
+ if (!upb_fielddef_isseq(p->top->f)) {
+ upb_status_seterrf(&p->status,
+ "Array specified for non-repeated field: %s",
+ upb_fielddef_name(p->top->f));
+ upb_env_reporterror(p->env, &p->status);
+ return false;
+ }
+
+ if (!check_stack(p)) return false;
+
+ inner = p->top + 1;
+ sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ);
+ upb_sink_startseq(&p->top->sink, sel, &inner->sink);
+ inner->m = p->top->m;
+ inner->name_table = NULL;
+ inner->f = p->top->f;
+ inner->is_map = false;
+ inner->is_mapentry = false;
+ p->top = inner;
+
+ return true;
+}
+
+static void end_array(upb_json_parser *p) {
+ upb_selector_t sel;
+
+ UPB_ASSERT(p->top > p->stack);
+
+ p->top--;
+ sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ);
+ upb_sink_endseq(&p->top->sink, sel);
+}
+
+static void start_object(upb_json_parser *p) {
+ if (!p->top->is_map) {
+ upb_sink_startmsg(&p->top->sink);
+ }
+}
+
+static void end_object(upb_json_parser *p) {
+ if (!p->top->is_map) {
+ upb_status status;
+ upb_status_clear(&status);
+ upb_sink_endmsg(&p->top->sink, &status);
+ if (!upb_ok(&status)) {
+ upb_env_reporterror(p->env, &status);
+ }
+ }
+}
+
+
+#define CHECK_RETURN_TOP(x) if (!(x)) goto error
+
+
+/* The actual parser **********************************************************/
+
+/* What follows is the Ragel parser itself. The language is specified in Ragel
+ * and the actions call our C functions above.
+ *
+ * Ragel has an extensive set of functionality, and we use only a small part of
+ * it. There are many action types but we only use a few:
+ *
+ * ">" -- transition into a machine
+ * "%" -- transition out of a machine
+ * "@" -- transition into a final state of a machine.
+ *
+ * "@" transitions are tricky because a machine can transition into a final
+ * state repeatedly. But in some cases we know this can't happen, for example
+ * a string which is delimited by a final '"' can only transition into its
+ * final state once, when the closing '"' is seen. */
+
+
+#line 1244 "upb/json/parser.rl"
+
+
+
+#line 1156 "upb/json/parser.c"
+static const char _json_actions[] = {
+ 0, 1, 0, 1, 2, 1, 3, 1,
+ 5, 1, 6, 1, 7, 1, 8, 1,
+ 10, 1, 12, 1, 13, 1, 14, 1,
+ 15, 1, 16, 1, 17, 1, 21, 1,
+ 25, 1, 27, 2, 3, 8, 2, 4,
+ 5, 2, 6, 2, 2, 6, 8, 2,
+ 11, 9, 2, 13, 15, 2, 14, 15,
+ 2, 18, 1, 2, 19, 27, 2, 20,
+ 9, 2, 22, 27, 2, 23, 27, 2,
+ 24, 27, 2, 26, 27, 3, 14, 11,
+ 9
+};
+
+static const unsigned char _json_key_offsets[] = {
+ 0, 0, 4, 9, 14, 15, 19, 24,
+ 29, 34, 38, 42, 45, 48, 50, 54,
+ 58, 60, 62, 67, 69, 71, 80, 86,
+ 92, 98, 104, 106, 115, 116, 116, 116,
+ 121, 126, 131, 132, 133, 134, 135, 135,
+ 136, 137, 138, 138, 139, 140, 141, 141,
+ 146, 151, 152, 156, 161, 166, 171, 175,
+ 175, 178, 178, 178
+};
+
+static const char _json_trans_keys[] = {
+ 32, 123, 9, 13, 32, 34, 125, 9,
+ 13, 32, 34, 125, 9, 13, 34, 32,
+ 58, 9, 13, 32, 93, 125, 9, 13,
+ 32, 44, 125, 9, 13, 32, 44, 125,
+ 9, 13, 32, 34, 9, 13, 45, 48,
+ 49, 57, 48, 49, 57, 46, 69, 101,
+ 48, 57, 69, 101, 48, 57, 43, 45,
+ 48, 57, 48, 57, 48, 57, 46, 69,
+ 101, 48, 57, 34, 92, 34, 92, 34,
+ 47, 92, 98, 102, 110, 114, 116, 117,
+ 48, 57, 65, 70, 97, 102, 48, 57,
+ 65, 70, 97, 102, 48, 57, 65, 70,
+ 97, 102, 48, 57, 65, 70, 97, 102,
+ 34, 92, 34, 45, 91, 102, 110, 116,
+ 123, 48, 57, 34, 32, 93, 125, 9,
+ 13, 32, 44, 93, 9, 13, 32, 93,
+ 125, 9, 13, 97, 108, 115, 101, 117,
+ 108, 108, 114, 117, 101, 32, 34, 125,
+ 9, 13, 32, 34, 125, 9, 13, 34,
+ 32, 58, 9, 13, 32, 93, 125, 9,
+ 13, 32, 44, 125, 9, 13, 32, 44,
+ 125, 9, 13, 32, 34, 9, 13, 32,
+ 9, 13, 0
+};
+
+static const char _json_single_lengths[] = {
+ 0, 2, 3, 3, 1, 2, 3, 3,
+ 3, 2, 2, 1, 3, 0, 2, 2,
+ 0, 0, 3, 2, 2, 9, 0, 0,
+ 0, 0, 2, 7, 1, 0, 0, 3,
+ 3, 3, 1, 1, 1, 1, 0, 1,
+ 1, 1, 0, 1, 1, 1, 0, 3,
+ 3, 1, 2, 3, 3, 3, 2, 0,
+ 1, 0, 0, 0
+};
+
+static const char _json_range_lengths[] = {
+ 0, 1, 1, 1, 0, 1, 1, 1,
+ 1, 1, 1, 1, 0, 1, 1, 1,
+ 1, 1, 1, 0, 0, 0, 3, 3,
+ 3, 3, 0, 1, 0, 0, 0, 1,
+ 1, 1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 1,
+ 1, 0, 1, 1, 1, 1, 1, 0,
+ 1, 0, 0, 0
+};
+
+static const short _json_index_offsets[] = {
+ 0, 0, 4, 9, 14, 16, 20, 25,
+ 30, 35, 39, 43, 46, 50, 52, 56,
+ 60, 62, 64, 69, 72, 75, 85, 89,
+ 93, 97, 101, 104, 113, 115, 116, 117,
+ 122, 127, 132, 134, 136, 138, 140, 141,
+ 143, 145, 147, 148, 150, 152, 154, 155,
+ 160, 165, 167, 171, 176, 181, 186, 190,
+ 191, 194, 195, 196
+};
+
+static const char _json_indicies[] = {
+ 0, 2, 0, 1, 3, 4, 5, 3,
+ 1, 6, 7, 8, 6, 1, 9, 1,
+ 10, 11, 10, 1, 11, 1, 1, 11,
+ 12, 13, 14, 15, 13, 1, 16, 17,
+ 8, 16, 1, 17, 7, 17, 1, 18,
+ 19, 20, 1, 19, 20, 1, 22, 23,
+ 23, 21, 24, 1, 23, 23, 24, 21,
+ 25, 25, 26, 1, 26, 1, 26, 21,
+ 22, 23, 23, 20, 21, 28, 29, 27,
+ 31, 32, 30, 33, 33, 33, 33, 33,
+ 33, 33, 33, 34, 1, 35, 35, 35,
+ 1, 36, 36, 36, 1, 37, 37, 37,
+ 1, 38, 38, 38, 1, 40, 41, 39,
+ 42, 43, 44, 45, 46, 47, 48, 43,
+ 1, 49, 1, 50, 51, 53, 54, 1,
+ 53, 52, 55, 56, 54, 55, 1, 56,
+ 1, 1, 56, 52, 57, 1, 58, 1,
+ 59, 1, 60, 1, 61, 62, 1, 63,
+ 1, 64, 1, 65, 66, 1, 67, 1,
+ 68, 1, 69, 70, 71, 72, 70, 1,
+ 73, 74, 75, 73, 1, 76, 1, 77,
+ 78, 77, 1, 78, 1, 1, 78, 79,
+ 80, 81, 82, 80, 1, 83, 84, 75,
+ 83, 1, 84, 74, 84, 1, 85, 86,
+ 86, 1, 1, 1, 1, 0
+};
+
+static const char _json_trans_targs[] = {
+ 1, 0, 2, 3, 4, 56, 3, 4,
+ 56, 5, 5, 6, 7, 8, 9, 56,
+ 8, 9, 11, 12, 18, 57, 13, 15,
+ 14, 16, 17, 20, 58, 21, 20, 58,
+ 21, 19, 22, 23, 24, 25, 26, 20,
+ 58, 21, 28, 30, 31, 34, 39, 43,
+ 47, 29, 59, 59, 32, 31, 29, 32,
+ 33, 35, 36, 37, 38, 59, 40, 41,
+ 42, 59, 44, 45, 46, 59, 48, 49,
+ 55, 48, 49, 55, 50, 50, 51, 52,
+ 53, 54, 55, 53, 54, 59, 56
+};
+
+static const char _json_trans_actions[] = {
+ 0, 0, 0, 21, 77, 53, 0, 47,
+ 23, 17, 0, 0, 15, 19, 19, 50,
+ 0, 0, 0, 0, 0, 1, 0, 0,
+ 0, 0, 0, 3, 13, 0, 0, 35,
+ 5, 11, 0, 38, 7, 7, 7, 41,
+ 44, 9, 62, 56, 25, 0, 0, 0,
+ 31, 29, 33, 59, 15, 0, 27, 0,
+ 0, 0, 0, 0, 0, 68, 0, 0,
+ 0, 71, 0, 0, 0, 65, 21, 77,
+ 53, 0, 47, 23, 17, 0, 0, 15,
+ 19, 19, 50, 0, 0, 74, 0
+};
+
+static const int json_start = 1;
+
+static const int json_en_number_machine = 10;
+static const int json_en_string_machine = 19;
+static const int json_en_value_machine = 27;
+static const int json_en_main = 1;
+
+
+#line 1247 "upb/json/parser.rl"
+
+size_t parse(void *closure, const void *hd, const char *buf, size_t size,
+ const upb_bufhandle *handle) {
+ upb_json_parser *parser = closure;
+
+ /* Variables used by Ragel's generated code. */
+ int cs = parser->current_state;
+ int *stack = parser->parser_stack;
+ int top = parser->parser_top;
+
+ const char *p = buf;
+ const char *pe = buf + size;
+
+ parser->handle = handle;
+
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+
+ capture_resume(parser, buf);
+
+
+#line 1327 "upb/json/parser.c"
+ {
+ int _klen;
+ unsigned int _trans;
+ const char *_acts;
+ unsigned int _nacts;
+ const char *_keys;
+
+ if ( p == pe )
+ goto _test_eof;
+ if ( cs == 0 )
+ goto _out;
+_resume:
+ _keys = _json_trans_keys + _json_key_offsets[cs];
+ _trans = _json_index_offsets[cs];
+
+ _klen = _json_single_lengths[cs];
+ if ( _klen > 0 ) {
+ const char *_lower = _keys;
+ const char *_mid;
+ const char *_upper = _keys + _klen - 1;
+ while (1) {
+ if ( _upper < _lower )
+ break;
+
+ _mid = _lower + ((_upper-_lower) >> 1);
+ if ( (*p) < *_mid )
+ _upper = _mid - 1;
+ else if ( (*p) > *_mid )
+ _lower = _mid + 1;
+ else {
+ _trans += (unsigned int)(_mid - _keys);
+ goto _match;
+ }
+ }
+ _keys += _klen;
+ _trans += _klen;
+ }
+
+ _klen = _json_range_lengths[cs];
+ if ( _klen > 0 ) {
+ const char *_lower = _keys;
+ const char *_mid;
+ const char *_upper = _keys + (_klen<<1) - 2;
+ while (1) {
+ if ( _upper < _lower )
+ break;
+
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1);
+ if ( (*p) < _mid[0] )
+ _upper = _mid - 2;
+ else if ( (*p) > _mid[1] )
+ _lower = _mid + 2;
+ else {
+ _trans += (unsigned int)((_mid - _keys)>>1);
+ goto _match;
+ }
+ }
+ _trans += _klen;
+ }
+
+_match:
+ _trans = _json_indicies[_trans];
+ cs = _json_trans_targs[_trans];
+
+ if ( _json_trans_actions[_trans] == 0 )
+ goto _again;
+
+ _acts = _json_actions + _json_trans_actions[_trans];
+ _nacts = (unsigned int) *_acts++;
+ while ( _nacts-- > 0 )
+ {
+ switch ( *_acts++ )
+ {
+ case 0:
+#line 1159 "upb/json/parser.rl"
+ { p--; {cs = stack[--top]; goto _again;} }
+ break;
+ case 1:
+#line 1160 "upb/json/parser.rl"
+ { p--; {stack[top++] = cs; cs = 10; goto _again;} }
+ break;
+ case 2:
+#line 1164 "upb/json/parser.rl"
+ { start_text(parser, p); }
+ break;
+ case 3:
+#line 1165 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_text(parser, p)); }
+ break;
+ case 4:
+#line 1171 "upb/json/parser.rl"
+ { start_hex(parser); }
+ break;
+ case 5:
+#line 1172 "upb/json/parser.rl"
+ { hexdigit(parser, p); }
+ break;
+ case 6:
+#line 1173 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_hex(parser)); }
+ break;
+ case 7:
+#line 1179 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(escape(parser, p)); }
+ break;
+ case 8:
+#line 1185 "upb/json/parser.rl"
+ { p--; {cs = stack[--top]; goto _again;} }
+ break;
+ case 9:
+#line 1188 "upb/json/parser.rl"
+ { {stack[top++] = cs; cs = 19; goto _again;} }
+ break;
+ case 10:
+#line 1190 "upb/json/parser.rl"
+ { p--; {stack[top++] = cs; cs = 27; goto _again;} }
+ break;
+ case 11:
+#line 1195 "upb/json/parser.rl"
+ { start_member(parser); }
+ break;
+ case 12:
+#line 1196 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_membername(parser)); }
+ break;
+ case 13:
+#line 1199 "upb/json/parser.rl"
+ { end_member(parser); }
+ break;
+ case 14:
+#line 1205 "upb/json/parser.rl"
+ { start_object(parser); }
+ break;
+ case 15:
+#line 1208 "upb/json/parser.rl"
+ { end_object(parser); }
+ break;
+ case 16:
+#line 1214 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(start_array(parser)); }
+ break;
+ case 17:
+#line 1218 "upb/json/parser.rl"
+ { end_array(parser); }
+ break;
+ case 18:
+#line 1223 "upb/json/parser.rl"
+ { start_number(parser, p); }
+ break;
+ case 19:
+#line 1224 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_number(parser, p)); }
+ break;
+ case 20:
+#line 1226 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(start_stringval(parser)); }
+ break;
+ case 21:
+#line 1227 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(end_stringval(parser)); }
+ break;
+ case 22:
+#line 1229 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(parser_putbool(parser, true)); }
+ break;
+ case 23:
+#line 1231 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(parser_putbool(parser, false)); }
+ break;
+ case 24:
+#line 1233 "upb/json/parser.rl"
+ { /* null value */ }
+ break;
+ case 25:
+#line 1235 "upb/json/parser.rl"
+ { CHECK_RETURN_TOP(start_subobject(parser)); }
+ break;
+ case 26:
+#line 1236 "upb/json/parser.rl"
+ { end_subobject(parser); }
+ break;
+ case 27:
+#line 1241 "upb/json/parser.rl"
+ { p--; {cs = stack[--top]; goto _again;} }
+ break;
+#line 1513 "upb/json/parser.c"
+ }
+ }
+
+_again:
+ if ( cs == 0 )
+ goto _out;
+ if ( ++p != pe )
+ goto _resume;
+ _test_eof: {}
+ _out: {}
+ }
+
+#line 1268 "upb/json/parser.rl"
+
+ if (p != pe) {
+ upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p);
+ upb_env_reporterror(parser->env, &parser->status);
+ } else {
+ capture_suspend(parser, &p);
+ }
+
+error:
+ /* Save parsing state back to parser. */
+ parser->current_state = cs;
+ parser->parser_top = top;
+
+ return p - buf;
+}
+
+bool end(void *closure, const void *hd) {
+ UPB_UNUSED(closure);
+ UPB_UNUSED(hd);
+
+ /* Prevent compile warning on unused static constants. */
+ UPB_UNUSED(json_start);
+ UPB_UNUSED(json_en_number_machine);
+ UPB_UNUSED(json_en_string_machine);
+ UPB_UNUSED(json_en_value_machine);
+ UPB_UNUSED(json_en_main);
+ return true;
+}
+
+static void json_parser_reset(upb_json_parser *p) {
+ int cs;
+ int top;
+
+ p->top = p->stack;
+ p->top->f = NULL;
+ p->top->is_map = false;
+ p->top->is_mapentry = false;
+
+ /* Emit Ragel initialization of the parser. */
+
+#line 1567 "upb/json/parser.c"
+ {
+ cs = json_start;
+ top = 0;
+ }
+
+#line 1308 "upb/json/parser.rl"
+ p->current_state = cs;
+ p->parser_top = top;
+ accumulate_clear(p);
+ p->multipart_state = MULTIPART_INACTIVE;
+ p->capture = NULL;
+ p->accumulated = NULL;
+ upb_status_clear(&p->status);
+}
+
+static void visit_json_parsermethod(const upb_refcounted *r,
+ upb_refcounted_visit *visit,
+ void *closure) {
+ const upb_json_parsermethod *method = (upb_json_parsermethod*)r;
+ visit(r, upb_msgdef_upcast2(method->msg), closure);
+}
+
+static void free_json_parsermethod(upb_refcounted *r) {
+ upb_json_parsermethod *method = (upb_json_parsermethod*)r;
+
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, &method->name_tables);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ upb_value val = upb_inttable_iter_value(&i);
+ upb_strtable *t = upb_value_getptr(val);
+ upb_strtable_uninit(t);
+ upb_gfree(t);
+ }
+
+ upb_inttable_uninit(&method->name_tables);
+
+ upb_gfree(r);
+}
+
+static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) {
+ upb_msg_field_iter i;
+ upb_strtable *t;
+
+ /* It would be nice to stack-allocate this, but protobufs do not limit the
+ * length of fields to any reasonable limit. */
+ char *buf = NULL;
+ size_t len = 0;
+
+ if (upb_inttable_lookupptr(&m->name_tables, md, NULL)) {
+ return;
+ }
+
+ /* TODO(haberman): handle malloc failure. */
+ t = upb_gmalloc(sizeof(*t));
+ upb_strtable_init(t, UPB_CTYPE_CONSTPTR);
+ upb_inttable_insertptr(&m->name_tables, md, upb_value_ptr(t));
+
+ for(upb_msg_field_begin(&i, md);
+ !upb_msg_field_done(&i);
+ upb_msg_field_next(&i)) {
+ const upb_fielddef *f = upb_msg_iter_field(&i);
+
+ /* Add an entry for the JSON name. */
+ size_t field_len = upb_fielddef_getjsonname(f, buf, len);
+ if (field_len > len) {
+ size_t len2;
+ buf = upb_grealloc(buf, 0, field_len);
+ len = field_len;
+ len2 = upb_fielddef_getjsonname(f, buf, len);
+ UPB_ASSERT(len == len2);
+ }
+ upb_strtable_insert(t, buf, upb_value_constptr(f));
+
+ if (strcmp(buf, upb_fielddef_name(f)) != 0) {
+ /* Since the JSON name is different from the regular field name, add an
+ * entry for the raw name (compliant proto3 JSON parsers must accept
+ * both). */
+ upb_strtable_insert(t, upb_fielddef_name(f), upb_value_constptr(f));
+ }
+
+ if (upb_fielddef_issubmsg(f)) {
+ add_jsonname_table(m, upb_fielddef_msgsubdef(f));
+ }
+ }
+
+ upb_gfree(buf);
+}
+
+/* Public API *****************************************************************/
+
+upb_json_parser *upb_json_parser_create(upb_env *env,
+ const upb_json_parsermethod *method,
+ upb_sink *output) {
+#ifndef NDEBUG
+ const size_t size_before = upb_env_bytesallocated(env);
+#endif
+ upb_json_parser *p = upb_env_malloc(env, sizeof(upb_json_parser));
+ if (!p) return false;
+
+ p->env = env;
+ p->method = method;
+ p->limit = p->stack + UPB_JSON_MAX_DEPTH;
+ p->accumulate_buf = NULL;
+ p->accumulate_buf_size = 0;
+ upb_bytessink_reset(&p->input_, &method->input_handler_, p);
+
+ json_parser_reset(p);
+ upb_sink_reset(&p->top->sink, output->handlers, output->closure);
+ p->top->m = upb_handlers_msgdef(output->handlers);
+ set_name_table(p, p->top);
+
+ /* If this fails, uncomment and increase the value in parser.h. */
+ /* fprintf(stderr, "%zd\n", upb_env_bytesallocated(env) - size_before); */
+ UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(env) - size_before <=
+ UPB_JSON_PARSER_SIZE);
+ return p;
+}
+
+upb_bytessink *upb_json_parser_input(upb_json_parser *p) {
+ return &p->input_;
+}
+
+upb_json_parsermethod *upb_json_parsermethod_new(const upb_msgdef* md,
+ const void* owner) {
+ static const struct upb_refcounted_vtbl vtbl = {visit_json_parsermethod,
+ free_json_parsermethod};
+ upb_json_parsermethod *ret = upb_gmalloc(sizeof(*ret));
+ upb_refcounted_init(upb_json_parsermethod_upcast_mutable(ret), &vtbl, owner);
+
+ ret->msg = md;
+ upb_ref2(md, ret);
+
+ upb_byteshandler_init(&ret->input_handler_);
+ upb_byteshandler_setstring(&ret->input_handler_, parse, ret);
+ upb_byteshandler_setendstr(&ret->input_handler_, end, ret);
+
+ upb_inttable_init(&ret->name_tables, UPB_CTYPE_PTR);
+
+ add_jsonname_table(ret, md);
+
+ return ret;
+}
+
+const upb_byteshandler *upb_json_parsermethod_inputhandler(
+ const upb_json_parsermethod *m) {
+ return &m->input_handler_;
+}
+/*
+** This currently uses snprintf() to format primitives, and could be optimized
+** further.
+*/
+
+
+#include <string.h>
+#include <stdint.h>
+
+struct upb_json_printer {
+ upb_sink input_;
+ /* BytesSink closure. */
+ void *subc_;
+ upb_bytessink *output_;
+
+ /* We track the depth so that we know when to emit startstr/endstr on the
+ * output. */
+ int depth_;
+
+ /* Have we emitted the first element? This state is necessary to emit commas
+ * without leaving a trailing comma in arrays/maps. We keep this state per
+ * frame depth.
+ *
+ * Why max_depth * 2? UPB_MAX_HANDLER_DEPTH counts depth as nested messages.
+ * We count frames (contexts in which we separate elements by commas) as both
+ * repeated fields and messages (maps), and the worst case is a
+ * message->repeated field->submessage->repeated field->... nesting. */
+ bool first_elem_[UPB_MAX_HANDLER_DEPTH * 2];
+};
+
+/* StringPiece; a pointer plus a length. */
+typedef struct {
+ char *ptr;
+ size_t len;
+} strpc;
+
+void freestrpc(void *ptr) {
+ strpc *pc = ptr;
+ upb_gfree(pc->ptr);
+ upb_gfree(pc);
+}
+
+/* Convert fielddef name to JSON name and return as a string piece. */
+strpc *newstrpc(upb_handlers *h, const upb_fielddef *f,
+ bool preserve_fieldnames) {
+ /* TODO(haberman): handle malloc failure. */
+ strpc *ret = upb_gmalloc(sizeof(*ret));
+ if (preserve_fieldnames) {
+ ret->ptr = upb_gstrdup(upb_fielddef_name(f));
+ ret->len = strlen(ret->ptr);
+ } else {
+ size_t len;
+ ret->len = upb_fielddef_getjsonname(f, NULL, 0);
+ ret->ptr = upb_gmalloc(ret->len);
+ len = upb_fielddef_getjsonname(f, ret->ptr, ret->len);
+ UPB_ASSERT(len == ret->len);
+ ret->len--; /* NULL */
+ }
+
+ upb_handlers_addcleanup(h, ret, freestrpc);
+ return ret;
+}
+
+/* ------------ JSON string printing: values, maps, arrays ------------------ */
+
+static void print_data(
+ upb_json_printer *p, const char *buf, unsigned int len) {
+ /* TODO: Will need to change if we support pushback from the sink. */
+ size_t n = upb_bytessink_putbuf(p->output_, p->subc_, buf, len, NULL);
+ UPB_ASSERT(n == len);
+}
+
+static void print_comma(upb_json_printer *p) {
+ if (!p->first_elem_[p->depth_]) {
+ print_data(p, ",", 1);
+ }
+ p->first_elem_[p->depth_] = false;
+}
+
+/* Helpers that print properly formatted elements to the JSON output stream. */
+
+/* Used for escaping control chars in strings. */
+static const char kControlCharLimit = 0x20;
+
+UPB_INLINE bool is_json_escaped(char c) {
+ /* See RFC 4627. */
+ unsigned char uc = (unsigned char)c;
+ return uc < kControlCharLimit || uc == '"' || uc == '\\';
+}
+
+UPB_INLINE const char* json_nice_escape(char c) {
+ switch (c) {
+ case '"': return "\\\"";
+ case '\\': return "\\\\";
+ case '\b': return "\\b";
+ case '\f': return "\\f";
+ case '\n': return "\\n";
+ case '\r': return "\\r";
+ case '\t': return "\\t";
+ default: return NULL;
+ }
+}
+
+/* Write a properly escaped string chunk. The surrounding quotes are *not*
+ * printed; this is so that the caller has the option of emitting the string
+ * content in chunks. */
+static void putstring(upb_json_printer *p, const char *buf, unsigned int len) {
+ const char* unescaped_run = NULL;
+ unsigned int i;
+ for (i = 0; i < len; i++) {
+ char c = buf[i];
+ /* Handle escaping. */
+ if (is_json_escaped(c)) {
+ /* Use a "nice" escape, like \n, if one exists for this character. */
+ const char* escape = json_nice_escape(c);
+ /* If we don't have a specific 'nice' escape code, use a \uXXXX-style
+ * escape. */
+ char escape_buf[8];
+ if (!escape) {
+ unsigned char byte = (unsigned char)c;
+ _upb_snprintf(escape_buf, sizeof(escape_buf), "\\u%04x", (int)byte);
+ escape = escape_buf;
+ }
+
+ /* N.B. that we assume that the input encoding is equal to the output
+ * encoding (both UTF-8 for now), so for chars >= 0x20 and != \, ", we
+ * can simply pass the bytes through. */
+
+ /* If there's a current run of unescaped chars, print that run first. */
+ if (unescaped_run) {
+ print_data(p, unescaped_run, &buf[i] - unescaped_run);
+ unescaped_run = NULL;
+ }
+ /* Then print the escape code. */
+ print_data(p, escape, strlen(escape));
+ } else {
+ /* Add to the current unescaped run of characters. */
+ if (unescaped_run == NULL) {
+ unescaped_run = &buf[i];
+ }
+ }
+ }
+
+ /* If the string ended in a run of unescaped characters, print that last run. */
+ if (unescaped_run) {
+ print_data(p, unescaped_run, &buf[len] - unescaped_run);
+ }
+}
+
+#define CHKLENGTH(x) if (!(x)) return -1;
+
+/* Helpers that format floating point values according to our custom formats.
+ * Right now we use %.8g and %.17g for float/double, respectively, to match
+ * proto2::util::JsonFormat's defaults. May want to change this later. */
+
+static size_t fmt_double(double val, char* buf, size_t length) {
+ size_t n = _upb_snprintf(buf, length, "%.17g", val);
+ CHKLENGTH(n > 0 && n < length);
+ return n;
+}
+
+static size_t fmt_float(float val, char* buf, size_t length) {
+ size_t n = _upb_snprintf(buf, length, "%.8g", val);
+ CHKLENGTH(n > 0 && n < length);
+ return n;
+}
+
+static size_t fmt_bool(bool val, char* buf, size_t length) {
+ size_t n = _upb_snprintf(buf, length, "%s", (val ? "true" : "false"));
+ CHKLENGTH(n > 0 && n < length);
+ return n;
+}
+
+static size_t fmt_int64(long val, char* buf, size_t length) {
+ size_t n = _upb_snprintf(buf, length, "%ld", val);
+ CHKLENGTH(n > 0 && n < length);
+ return n;
+}
+
+static size_t fmt_uint64(unsigned long long val, char* buf, size_t length) {
+ size_t n = _upb_snprintf(buf, length, "%llu", val);
+ CHKLENGTH(n > 0 && n < length);
+ return n;
+}
+
+/* Print a map key given a field name. Called by scalar field handlers and by
+ * startseq for repeated fields. */
+static bool putkey(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ const strpc *key = handler_data;
+ print_comma(p);
+ print_data(p, "\"", 1);
+ putstring(p, key->ptr, key->len);
+ print_data(p, "\":", 2);
+ return true;
+}
+
+#define CHKFMT(val) if ((val) == (size_t)-1) return false;
+#define CHK(val) if (!(val)) return false;
+
+#define TYPE_HANDLERS(type, fmt_func) \
+ static bool put##type(void *closure, const void *handler_data, type val) { \
+ upb_json_printer *p = closure; \
+ char data[64]; \
+ size_t length = fmt_func(val, data, sizeof(data)); \
+ UPB_UNUSED(handler_data); \
+ CHKFMT(length); \
+ print_data(p, data, length); \
+ return true; \
+ } \
+ static bool scalar_##type(void *closure, const void *handler_data, \
+ type val) { \
+ CHK(putkey(closure, handler_data)); \
+ CHK(put##type(closure, handler_data, val)); \
+ return true; \
+ } \
+ static bool repeated_##type(void *closure, const void *handler_data, \
+ type val) { \
+ upb_json_printer *p = closure; \
+ print_comma(p); \
+ CHK(put##type(closure, handler_data, val)); \
+ return true; \
+ }
+
+#define TYPE_HANDLERS_MAPKEY(type, fmt_func) \
+ static bool putmapkey_##type(void *closure, const void *handler_data, \
+ type val) { \
+ upb_json_printer *p = closure; \
+ print_data(p, "\"", 1); \
+ CHK(put##type(closure, handler_data, val)); \
+ print_data(p, "\":", 2); \
+ return true; \
+ }
+
+TYPE_HANDLERS(double, fmt_double)
+TYPE_HANDLERS(float, fmt_float)
+TYPE_HANDLERS(bool, fmt_bool)
+TYPE_HANDLERS(int32_t, fmt_int64)
+TYPE_HANDLERS(uint32_t, fmt_int64)
+TYPE_HANDLERS(int64_t, fmt_int64)
+TYPE_HANDLERS(uint64_t, fmt_uint64)
+
+/* double and float are not allowed to be map keys. */
+TYPE_HANDLERS_MAPKEY(bool, fmt_bool)
+TYPE_HANDLERS_MAPKEY(int32_t, fmt_int64)
+TYPE_HANDLERS_MAPKEY(uint32_t, fmt_int64)
+TYPE_HANDLERS_MAPKEY(int64_t, fmt_int64)
+TYPE_HANDLERS_MAPKEY(uint64_t, fmt_uint64)
+
+#undef TYPE_HANDLERS
+#undef TYPE_HANDLERS_MAPKEY
+
+typedef struct {
+ void *keyname;
+ const upb_enumdef *enumdef;
+} EnumHandlerData;
+
+static bool scalar_enum(void *closure, const void *handler_data,
+ int32_t val) {
+ const EnumHandlerData *hd = handler_data;
+ upb_json_printer *p = closure;
+ const char *symbolic_name;
+
+ CHK(putkey(closure, hd->keyname));
+
+ symbolic_name = upb_enumdef_iton(hd->enumdef, val);
+ if (symbolic_name) {
+ print_data(p, "\"", 1);
+ putstring(p, symbolic_name, strlen(symbolic_name));
+ print_data(p, "\"", 1);
+ } else {
+ putint32_t(closure, NULL, val);
+ }
+
+ return true;
+}
+
+static void print_enum_symbolic_name(upb_json_printer *p,
+ const upb_enumdef *def,
+ int32_t val) {
+ const char *symbolic_name = upb_enumdef_iton(def, val);
+ if (symbolic_name) {
+ print_data(p, "\"", 1);
+ putstring(p, symbolic_name, strlen(symbolic_name));
+ print_data(p, "\"", 1);
+ } else {
+ putint32_t(p, NULL, val);
+ }
+}
+
+static bool repeated_enum(void *closure, const void *handler_data,
+ int32_t val) {
+ const EnumHandlerData *hd = handler_data;
+ upb_json_printer *p = closure;
+ print_comma(p);
+
+ print_enum_symbolic_name(p, hd->enumdef, val);
+
+ return true;
+}
+
+static bool mapvalue_enum(void *closure, const void *handler_data,
+ int32_t val) {
+ const EnumHandlerData *hd = handler_data;
+ upb_json_printer *p = closure;
+
+ print_enum_symbolic_name(p, hd->enumdef, val);
+
+ return true;
+}
+
+static void *scalar_startsubmsg(void *closure, const void *handler_data) {
+ return putkey(closure, handler_data) ? closure : UPB_BREAK;
+}
+
+static void *repeated_startsubmsg(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ print_comma(p);
+ return closure;
+}
+
+static void start_frame(upb_json_printer *p) {
+ p->depth_++;
+ p->first_elem_[p->depth_] = true;
+ print_data(p, "{", 1);
+}
+
+static void end_frame(upb_json_printer *p) {
+ print_data(p, "}", 1);
+ p->depth_--;
+}
+
+static bool printer_startmsg(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ if (p->depth_ == 0) {
+ upb_bytessink_start(p->output_, 0, &p->subc_);
+ }
+ start_frame(p);
+ return true;
+}
+
+static bool printer_endmsg(void *closure, const void *handler_data, upb_status *s) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ UPB_UNUSED(s);
+ end_frame(p);
+ if (p->depth_ == 0) {
+ upb_bytessink_end(p->output_);
+ }
+ return true;
+}
+
+static void *startseq(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ CHK(putkey(closure, handler_data));
+ p->depth_++;
+ p->first_elem_[p->depth_] = true;
+ print_data(p, "[", 1);
+ return closure;
+}
+
+static bool endseq(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ print_data(p, "]", 1);
+ p->depth_--;
+ return true;
+}
+
+static void *startmap(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ CHK(putkey(closure, handler_data));
+ p->depth_++;
+ p->first_elem_[p->depth_] = true;
+ print_data(p, "{", 1);
+ return closure;
+}
+
+static bool endmap(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ print_data(p, "}", 1);
+ p->depth_--;
+ return true;
+}
+
+static size_t putstr(void *closure, const void *handler_data, const char *str,
+ size_t len, const upb_bufhandle *handle) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ UPB_UNUSED(handle);
+ putstring(p, str, len);
+ return len;
+}
+
+/* This has to Base64 encode the bytes, because JSON has no "bytes" type. */
+static size_t putbytes(void *closure, const void *handler_data, const char *str,
+ size_t len, const upb_bufhandle *handle) {
+ upb_json_printer *p = closure;
+
+ /* This is the regular base64, not the "web-safe" version. */
+ static const char base64[] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+ /* Base64-encode. */
+ char data[16000];
+ const char *limit = data + sizeof(data);
+ const unsigned char *from = (const unsigned char*)str;
+ char *to = data;
+ size_t remaining = len;
+ size_t bytes;
+
+ UPB_UNUSED(handler_data);
+ UPB_UNUSED(handle);
+
+ while (remaining > 2) {
+ /* TODO(haberman): handle encoded lengths > sizeof(data) */
+ UPB_ASSERT((limit - to) >= 4);
+
+ to[0] = base64[from[0] >> 2];
+ to[1] = base64[((from[0] & 0x3) << 4) | (from[1] >> 4)];
+ to[2] = base64[((from[1] & 0xf) << 2) | (from[2] >> 6)];
+ to[3] = base64[from[2] & 0x3f];
+
+ remaining -= 3;
+ to += 4;
+ from += 3;
+ }
+
+ switch (remaining) {
+ case 2:
+ to[0] = base64[from[0] >> 2];
+ to[1] = base64[((from[0] & 0x3) << 4) | (from[1] >> 4)];
+ to[2] = base64[(from[1] & 0xf) << 2];
+ to[3] = '=';
+ to += 4;
+ from += 2;
+ break;
+ case 1:
+ to[0] = base64[from[0] >> 2];
+ to[1] = base64[((from[0] & 0x3) << 4)];
+ to[2] = '=';
+ to[3] = '=';
+ to += 4;
+ from += 1;
+ break;
+ }
+
+ bytes = to - data;
+ print_data(p, "\"", 1);
+ putstring(p, data, bytes);
+ print_data(p, "\"", 1);
+ return len;
+}
+
+static void *scalar_startstr(void *closure, const void *handler_data,
+ size_t size_hint) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ UPB_UNUSED(size_hint);
+ CHK(putkey(closure, handler_data));
+ print_data(p, "\"", 1);
+ return p;
+}
+
+static size_t scalar_str(void *closure, const void *handler_data,
+ const char *str, size_t len,
+ const upb_bufhandle *handle) {
+ CHK(putstr(closure, handler_data, str, len, handle));
+ return len;
+}
+
+static bool scalar_endstr(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ print_data(p, "\"", 1);
+ return true;
+}
+
+static void *repeated_startstr(void *closure, const void *handler_data,
+ size_t size_hint) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ UPB_UNUSED(size_hint);
+ print_comma(p);
+ print_data(p, "\"", 1);
+ return p;
+}
+
+static size_t repeated_str(void *closure, const void *handler_data,
+ const char *str, size_t len,
+ const upb_bufhandle *handle) {
+ CHK(putstr(closure, handler_data, str, len, handle));
+ return len;
+}
+
+static bool repeated_endstr(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ print_data(p, "\"", 1);
+ return true;
+}
+
+static void *mapkeyval_startstr(void *closure, const void *handler_data,
+ size_t size_hint) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ UPB_UNUSED(size_hint);
+ print_data(p, "\"", 1);
+ return p;
+}
+
+static size_t mapkey_str(void *closure, const void *handler_data,
+ const char *str, size_t len,
+ const upb_bufhandle *handle) {
+ CHK(putstr(closure, handler_data, str, len, handle));
+ return len;
+}
+
+static bool mapkey_endstr(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ print_data(p, "\":", 2);
+ return true;
+}
+
+static bool mapvalue_endstr(void *closure, const void *handler_data) {
+ upb_json_printer *p = closure;
+ UPB_UNUSED(handler_data);
+ print_data(p, "\"", 1);
+ return true;
+}
+
+static size_t scalar_bytes(void *closure, const void *handler_data,
+ const char *str, size_t len,
+ const upb_bufhandle *handle) {
+ CHK(putkey(closure, handler_data));
+ CHK(putbytes(closure, handler_data, str, len, handle));
+ return len;
+}
+
+static size_t repeated_bytes(void *closure, const void *handler_data,
+ const char *str, size_t len,
+ const upb_bufhandle *handle) {
+ upb_json_printer *p = closure;
+ print_comma(p);
+ CHK(putbytes(closure, handler_data, str, len, handle));
+ return len;
+}
+
+static size_t mapkey_bytes(void *closure, const void *handler_data,
+ const char *str, size_t len,
+ const upb_bufhandle *handle) {
+ upb_json_printer *p = closure;
+ CHK(putbytes(closure, handler_data, str, len, handle));
+ print_data(p, ":", 1);
+ return len;
+}
+
+static void set_enum_hd(upb_handlers *h,
+ const upb_fielddef *f,
+ bool preserve_fieldnames,
+ upb_handlerattr *attr) {
+ EnumHandlerData *hd = upb_gmalloc(sizeof(EnumHandlerData));
+ hd->enumdef = (const upb_enumdef *)upb_fielddef_subdef(f);
+ hd->keyname = newstrpc(h, f, preserve_fieldnames);
+ upb_handlers_addcleanup(h, hd, upb_gfree);
+ upb_handlerattr_sethandlerdata(attr, hd);
+}
+
+/* Set up handlers for a mapentry submessage (i.e., an individual key/value pair
+ * in a map).
+ *
+ * TODO: Handle missing key, missing value, out-of-order key/value, or repeated
+ * key or value cases properly. The right way to do this is to allocate a
+ * temporary structure at the start of a mapentry submessage, store key and
+ * value data in it as key and value handlers are called, and then print the
+ * key/value pair once at the end of the submessage. If we don't do this, we
+ * should at least detect the case and throw an error. However, so far all of
+ * our sources that emit mapentry messages do so canonically (with one key
+ * field, and then one value field), so this is not a pressing concern at the
+ * moment. */
+void printer_sethandlers_mapentry(const void *closure, bool preserve_fieldnames,
+ upb_handlers *h) {
+ const upb_msgdef *md = upb_handlers_msgdef(h);
+
+ /* A mapentry message is printed simply as '"key": value'. Rather than
+ * special-case key and value for every type below, we just handle both
+ * fields explicitly here. */
+ const upb_fielddef* key_field = upb_msgdef_itof(md, UPB_MAPENTRY_KEY);
+ const upb_fielddef* value_field = upb_msgdef_itof(md, UPB_MAPENTRY_VALUE);
+
+ upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER;
+
+ UPB_UNUSED(closure);
+
+ switch (upb_fielddef_type(key_field)) {
+ case UPB_TYPE_INT32:
+ upb_handlers_setint32(h, key_field, putmapkey_int32_t, &empty_attr);
+ break;
+ case UPB_TYPE_INT64:
+ upb_handlers_setint64(h, key_field, putmapkey_int64_t, &empty_attr);
+ break;
+ case UPB_TYPE_UINT32:
+ upb_handlers_setuint32(h, key_field, putmapkey_uint32_t, &empty_attr);
+ break;
+ case UPB_TYPE_UINT64:
+ upb_handlers_setuint64(h, key_field, putmapkey_uint64_t, &empty_attr);
+ break;
+ case UPB_TYPE_BOOL:
+ upb_handlers_setbool(h, key_field, putmapkey_bool, &empty_attr);
+ break;
+ case UPB_TYPE_STRING:
+ upb_handlers_setstartstr(h, key_field, mapkeyval_startstr, &empty_attr);
+ upb_handlers_setstring(h, key_field, mapkey_str, &empty_attr);
+ upb_handlers_setendstr(h, key_field, mapkey_endstr, &empty_attr);
+ break;
+ case UPB_TYPE_BYTES:
+ upb_handlers_setstring(h, key_field, mapkey_bytes, &empty_attr);
+ break;
+ default:
+ UPB_ASSERT(false);
+ break;
+ }
+
+ switch (upb_fielddef_type(value_field)) {
+ case UPB_TYPE_INT32:
+ upb_handlers_setint32(h, value_field, putint32_t, &empty_attr);
+ break;
+ case UPB_TYPE_INT64:
+ upb_handlers_setint64(h, value_field, putint64_t, &empty_attr);
+ break;
+ case UPB_TYPE_UINT32:
+ upb_handlers_setuint32(h, value_field, putuint32_t, &empty_attr);
+ break;
+ case UPB_TYPE_UINT64:
+ upb_handlers_setuint64(h, value_field, putuint64_t, &empty_attr);
+ break;
+ case UPB_TYPE_BOOL:
+ upb_handlers_setbool(h, value_field, putbool, &empty_attr);
+ break;
+ case UPB_TYPE_FLOAT:
+ upb_handlers_setfloat(h, value_field, putfloat, &empty_attr);
+ break;
+ case UPB_TYPE_DOUBLE:
+ upb_handlers_setdouble(h, value_field, putdouble, &empty_attr);
+ break;
+ case UPB_TYPE_STRING:
+ upb_handlers_setstartstr(h, value_field, mapkeyval_startstr, &empty_attr);
+ upb_handlers_setstring(h, value_field, putstr, &empty_attr);
+ upb_handlers_setendstr(h, value_field, mapvalue_endstr, &empty_attr);
+ break;
+ case UPB_TYPE_BYTES:
+ upb_handlers_setstring(h, value_field, putbytes, &empty_attr);
+ break;
+ case UPB_TYPE_ENUM: {
+ upb_handlerattr enum_attr = UPB_HANDLERATTR_INITIALIZER;
+ set_enum_hd(h, value_field, preserve_fieldnames, &enum_attr);
+ upb_handlers_setint32(h, value_field, mapvalue_enum, &enum_attr);
+ upb_handlerattr_uninit(&enum_attr);
+ break;
+ }
+ case UPB_TYPE_MESSAGE:
+ /* No handler necessary -- the submsg handlers will print the message
+ * as appropriate. */
+ break;
+ }
+
+ upb_handlerattr_uninit(&empty_attr);
+}
+
+void printer_sethandlers(const void *closure, upb_handlers *h) {
+ const upb_msgdef *md = upb_handlers_msgdef(h);
+ bool is_mapentry = upb_msgdef_mapentry(md);
+ upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_msg_field_iter i;
+ const bool *preserve_fieldnames_ptr = closure;
+ const bool preserve_fieldnames = *preserve_fieldnames_ptr;
+
+ if (is_mapentry) {
+ /* mapentry messages are sufficiently different that we handle them
+ * separately. */
+ printer_sethandlers_mapentry(closure, preserve_fieldnames, h);
+ return;
+ }
+
+ upb_handlers_setstartmsg(h, printer_startmsg, &empty_attr);
+ upb_handlers_setendmsg(h, printer_endmsg, &empty_attr);
+
+#define TYPE(type, name, ctype) \
+ case type: \
+ if (upb_fielddef_isseq(f)) { \
+ upb_handlers_set##name(h, f, repeated_##ctype, &empty_attr); \
+ } else { \
+ upb_handlers_set##name(h, f, scalar_##ctype, &name_attr); \
+ } \
+ break;
+
+ upb_msg_field_begin(&i, md);
+ for(; !upb_msg_field_done(&i); upb_msg_field_next(&i)) {
+ const upb_fielddef *f = upb_msg_iter_field(&i);
+
+ upb_handlerattr name_attr = UPB_HANDLERATTR_INITIALIZER;
+ upb_handlerattr_sethandlerdata(&name_attr,
+ newstrpc(h, f, preserve_fieldnames));
+
+ if (upb_fielddef_ismap(f)) {
+ upb_handlers_setstartseq(h, f, startmap, &name_attr);
+ upb_handlers_setendseq(h, f, endmap, &name_attr);
+ } else if (upb_fielddef_isseq(f)) {
+ upb_handlers_setstartseq(h, f, startseq, &name_attr);
+ upb_handlers_setendseq(h, f, endseq, &empty_attr);
+ }
+
+ switch (upb_fielddef_type(f)) {
+ TYPE(UPB_TYPE_FLOAT, float, float);
+ TYPE(UPB_TYPE_DOUBLE, double, double);
+ TYPE(UPB_TYPE_BOOL, bool, bool);
+ TYPE(UPB_TYPE_INT32, int32, int32_t);
+ TYPE(UPB_TYPE_UINT32, uint32, uint32_t);
+ TYPE(UPB_TYPE_INT64, int64, int64_t);
+ TYPE(UPB_TYPE_UINT64, uint64, uint64_t);
+ case UPB_TYPE_ENUM: {
+ /* For now, we always emit symbolic names for enums. We may want an
+ * option later to control this behavior, but we will wait for a real
+ * need first. */
+ upb_handlerattr enum_attr = UPB_HANDLERATTR_INITIALIZER;
+ set_enum_hd(h, f, preserve_fieldnames, &enum_attr);
+
+ if (upb_fielddef_isseq(f)) {
+ upb_handlers_setint32(h, f, repeated_enum, &enum_attr);
+ } else {
+ upb_handlers_setint32(h, f, scalar_enum, &enum_attr);
+ }
+
+ upb_handlerattr_uninit(&enum_attr);
+ break;
+ }
+ case UPB_TYPE_STRING:
+ if (upb_fielddef_isseq(f)) {
+ upb_handlers_setstartstr(h, f, repeated_startstr, &empty_attr);
+ upb_handlers_setstring(h, f, repeated_str, &empty_attr);
+ upb_handlers_setendstr(h, f, repeated_endstr, &empty_attr);
+ } else {
+ upb_handlers_setstartstr(h, f, scalar_startstr, &name_attr);
+ upb_handlers_setstring(h, f, scalar_str, &empty_attr);
+ upb_handlers_setendstr(h, f, scalar_endstr, &empty_attr);
+ }
+ break;
+ case UPB_TYPE_BYTES:
+ /* XXX: this doesn't support strings that span buffers yet. The base64
+ * encoder will need to be made resumable for this to work properly. */
+ if (upb_fielddef_isseq(f)) {
+ upb_handlers_setstring(h, f, repeated_bytes, &empty_attr);
+ } else {
+ upb_handlers_setstring(h, f, scalar_bytes, &name_attr);
+ }
+ break;
+ case UPB_TYPE_MESSAGE:
+ if (upb_fielddef_isseq(f)) {
+ upb_handlers_setstartsubmsg(h, f, repeated_startsubmsg, &name_attr);
+ } else {
+ upb_handlers_setstartsubmsg(h, f, scalar_startsubmsg, &name_attr);
+ }
+ break;
+ }
+
+ upb_handlerattr_uninit(&name_attr);
+ }
+
+ upb_handlerattr_uninit(&empty_attr);
+#undef TYPE
+}
+
+static void json_printer_reset(upb_json_printer *p) {
+ p->depth_ = 0;
+}
+
+
+/* Public API *****************************************************************/
+
+upb_json_printer *upb_json_printer_create(upb_env *e, const upb_handlers *h,
+ upb_bytessink *output) {
+#ifndef NDEBUG
+ size_t size_before = upb_env_bytesallocated(e);
+#endif
+
+ upb_json_printer *p = upb_env_malloc(e, sizeof(upb_json_printer));
+ if (!p) return NULL;
+
+ p->output_ = output;
+ json_printer_reset(p);
+ upb_sink_reset(&p->input_, h, p);
+
+ /* If this fails, increase the value in printer.h. */
+ UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(e) - size_before <=
+ UPB_JSON_PRINTER_SIZE);
+ return p;
+}
+
+upb_sink *upb_json_printer_input(upb_json_printer *p) {
+ return &p->input_;
+}
+
+const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md,
+ bool preserve_fieldnames,
+ const void *owner) {
+ return upb_handlers_newfrozen(
+ md, owner, printer_sethandlers, &preserve_fieldnames);
+}
diff --git a/third_party/protobuf/ruby/ext/google/protobuf_c/upb.h b/third_party/protobuf/ruby/ext/google/protobuf_c/upb.h
new file mode 100644
index 0000000000..6e1e6c6fff
--- /dev/null
+++ b/third_party/protobuf/ruby/ext/google/protobuf_c/upb.h
@@ -0,0 +1,8853 @@
+// Amalgamated source file
+/*
+** Defs are upb's internal representation of the constructs that can appear
+** in a .proto file:
+**
+** - upb::MessageDef (upb_msgdef): describes a "message" construct.
+** - upb::FieldDef (upb_fielddef): describes a message field.
+** - upb::FileDef (upb_filedef): describes a .proto file and its defs.
+** - upb::EnumDef (upb_enumdef): describes an enum.
+** - upb::OneofDef (upb_oneofdef): describes a oneof.
+** - upb::Def (upb_def): base class of all the others.
+**
+** TODO: definitions of services.
+**
+** Like upb_refcounted objects, defs are mutable only until frozen, and are
+** only thread-safe once frozen.
+**
+** This is a mixed C/C++ interface that offers a full API to both languages.
+** See the top-level README for more information.
+*/
+
+#ifndef UPB_DEF_H_
+#define UPB_DEF_H_
+
+/*
+** upb::RefCounted (upb_refcounted)
+**
+** A refcounting scheme that supports circular refs. It accomplishes this by
+** partitioning the set of objects into groups such that no cycle spans groups;
+** we can then reference-count the group as a whole and ignore refs within the
+** group. When objects are mutable, these groups are computed very
+** conservatively; we group any objects that have ever had a link between them.
+** When objects are frozen, we compute strongly-connected components which
+** allows us to be precise and only group objects that are actually cyclic.
+**
+** This is a mixed C/C++ interface that offers a full API to both languages.
+** See the top-level README for more information.
+*/
+
+#ifndef UPB_REFCOUNTED_H_
+#define UPB_REFCOUNTED_H_
+
+/*
+** upb_table
+**
+** This header is INTERNAL-ONLY! Its interfaces are not public or stable!
+** This file defines very fast int->upb_value (inttable) and string->upb_value
+** (strtable) hash tables.
+**
+** The table uses chained scatter with Brent's variation (inspired by the Lua
+** implementation of hash tables). The hash function for strings is Austin
+** Appleby's "MurmurHash."
+**
+** The inttable uses uintptr_t as its key, which guarantees it can be used to
+** store pointers or integers of at least 32 bits (upb isn't really useful on
+** systems where sizeof(void*) < 4).
+**
+** The table must be homogenous (all values of the same type). In debug
+** mode, we check this on insert and lookup.
+*/
+
+#ifndef UPB_TABLE_H_
+#define UPB_TABLE_H_
+
+#include <stdint.h>
+#include <string.h>
+/*
+** This file contains shared definitions that are widely used across upb.
+**
+** This is a mixed C/C++ interface that offers a full API to both languages.
+** See the top-level README for more information.
+*/
+
+#ifndef UPB_H_
+#define UPB_H_
+
+#include <assert.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stddef.h>
+
+#ifdef __cplusplus
+namespace upb {
+class Allocator;
+class Arena;
+class Environment;
+class ErrorSpace;
+class Status;
+template <int N> class InlinedArena;
+template <int N> class InlinedEnvironment;
+}
+#endif
+
+/* UPB_INLINE: inline if possible, emit standalone code if required. */
+#ifdef __cplusplus
+#define UPB_INLINE inline
+#elif defined (__GNUC__)
+#define UPB_INLINE static __inline__
+#else
+#define UPB_INLINE static
+#endif
+
+/* Define UPB_BIG_ENDIAN manually if you're on big endian and your compiler
+ * doesn't provide these preprocessor symbols. */
+#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#define UPB_BIG_ENDIAN
+#endif
+
+/* Macros for function attributes on compilers that support them. */
+#ifdef __GNUC__
+#define UPB_FORCEINLINE __inline__ __attribute__((always_inline))
+#define UPB_NOINLINE __attribute__((noinline))
+#define UPB_NORETURN __attribute__((__noreturn__))
+#else /* !defined(__GNUC__) */
+#define UPB_FORCEINLINE
+#define UPB_NOINLINE
+#define UPB_NORETURN
+#endif
+
+#if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L
+/* C99/C++11 versions. */
+#include <stdio.h>
+#define _upb_snprintf snprintf
+#define _upb_vsnprintf vsnprintf
+#define _upb_va_copy(a, b) va_copy(a, b)
+#elif defined __GNUC__
+/* A few hacky workarounds for functions not in C89.
+ * For internal use only!
+ * TODO(haberman): fix these by including our own implementations, or finding
+ * another workaround.
+ */
+#define _upb_snprintf __builtin_snprintf
+#define _upb_vsnprintf __builtin_vsnprintf
+#define _upb_va_copy(a, b) __va_copy(a, b)
+#else
+#error Need implementations of [v]snprintf and va_copy
+#endif
+
+
+#if ((defined(__cplusplus) && __cplusplus >= 201103L) || \
+ defined(__GXX_EXPERIMENTAL_CXX0X__)) && !defined(UPB_NO_CXX11)
+#define UPB_CXX11
+#endif
+
+/* UPB_DISALLOW_COPY_AND_ASSIGN()
+ * UPB_DISALLOW_POD_OPS()
+ *
+ * Declare these in the "private" section of a C++ class to forbid copy/assign
+ * or all POD ops (construct, destruct, copy, assign) on that class. */
+#ifdef UPB_CXX11
+#include <type_traits>
+#define UPB_DISALLOW_COPY_AND_ASSIGN(class_name) \
+ class_name(const class_name&) = delete; \
+ void operator=(const class_name&) = delete;
+#define UPB_DISALLOW_POD_OPS(class_name, full_class_name) \
+ class_name() = delete; \
+ ~class_name() = delete; \
+ UPB_DISALLOW_COPY_AND_ASSIGN(class_name)
+#define UPB_ASSERT_STDLAYOUT(type) \
+ static_assert(std::is_standard_layout<type>::value, \
+ #type " must be standard layout");
+#define UPB_FINAL final
+#else /* !defined(UPB_CXX11) */
+#define UPB_DISALLOW_COPY_AND_ASSIGN(class_name) \
+ class_name(const class_name&); \
+ void operator=(const class_name&);
+#define UPB_DISALLOW_POD_OPS(class_name, full_class_name) \
+ class_name(); \
+ ~class_name(); \
+ UPB_DISALLOW_COPY_AND_ASSIGN(class_name)
+#define UPB_ASSERT_STDLAYOUT(type)
+#define UPB_FINAL
+#endif
+
+/* UPB_DECLARE_TYPE()
+ * UPB_DECLARE_DERIVED_TYPE()
+ * UPB_DECLARE_DERIVED_TYPE2()
+ *
+ * Macros for declaring C and C++ types both, including inheritance.
+ * The inheritance doesn't use real C++ inheritance, to stay compatible with C.
+ *
+ * These macros also provide upcasts:
+ * - in C: types-specific functions (ie. upb_foo_upcast(foo))
+ * - in C++: upb::upcast(foo) along with implicit conversions
+ *
+ * Downcasts are not provided, but upb/def.h defines downcasts for upb::Def. */
+
+#define UPB_C_UPCASTS(ty, base) \
+ UPB_INLINE base *ty ## _upcast_mutable(ty *p) { return (base*)p; } \
+ UPB_INLINE const base *ty ## _upcast(const ty *p) { return (const base*)p; }
+
+#define UPB_C_UPCASTS2(ty, base, base2) \
+ UPB_C_UPCASTS(ty, base) \
+ UPB_INLINE base2 *ty ## _upcast2_mutable(ty *p) { return (base2*)p; } \
+ UPB_INLINE const base2 *ty ## _upcast2(const ty *p) { return (const base2*)p; }
+
+#ifdef __cplusplus
+
+#define UPB_BEGIN_EXTERN_C extern "C" {
+#define UPB_END_EXTERN_C }
+#define UPB_PRIVATE_FOR_CPP private:
+#define UPB_DECLARE_TYPE(cppname, cname) typedef cppname cname;
+
+#define UPB_DECLARE_DERIVED_TYPE(cppname, cppbase, cname, cbase) \
+ UPB_DECLARE_TYPE(cppname, cname) \
+ UPB_C_UPCASTS(cname, cbase) \
+ namespace upb { \
+ template <> \
+ class Pointer<cppname> : public PointerBase<cppname, cppbase> { \
+ public: \
+ explicit Pointer(cppname* ptr) \
+ : PointerBase<cppname, cppbase>(ptr) {} \
+ }; \
+ template <> \
+ class Pointer<const cppname> \
+ : public PointerBase<const cppname, const cppbase> { \
+ public: \
+ explicit Pointer(const cppname* ptr) \
+ : PointerBase<const cppname, const cppbase>(ptr) {} \
+ }; \
+ }
+
+#define UPB_DECLARE_DERIVED_TYPE2(cppname, cppbase, cppbase2, cname, cbase, \
+ cbase2) \
+ UPB_DECLARE_TYPE(cppname, cname) \
+ UPB_C_UPCASTS2(cname, cbase, cbase2) \
+ namespace upb { \
+ template <> \
+ class Pointer<cppname> : public PointerBase2<cppname, cppbase, cppbase2> { \
+ public: \
+ explicit Pointer(cppname* ptr) \
+ : PointerBase2<cppname, cppbase, cppbase2>(ptr) {} \
+ }; \
+ template <> \
+ class Pointer<const cppname> \
+ : public PointerBase2<const cppname, const cppbase, const cppbase2> { \
+ public: \
+ explicit Pointer(const cppname* ptr) \
+ : PointerBase2<const cppname, const cppbase, const cppbase2>(ptr) {} \
+ }; \
+ }
+
+#else /* !defined(__cplusplus) */
+
+#define UPB_BEGIN_EXTERN_C
+#define UPB_END_EXTERN_C
+#define UPB_PRIVATE_FOR_CPP
+#define UPB_DECLARE_TYPE(cppname, cname) \
+ struct cname; \
+ typedef struct cname cname;
+#define UPB_DECLARE_DERIVED_TYPE(cppname, cppbase, cname, cbase) \
+ UPB_DECLARE_TYPE(cppname, cname) \
+ UPB_C_UPCASTS(cname, cbase)
+#define UPB_DECLARE_DERIVED_TYPE2(cppname, cppbase, cppbase2, \
+ cname, cbase, cbase2) \
+ UPB_DECLARE_TYPE(cppname, cname) \
+ UPB_C_UPCASTS2(cname, cbase, cbase2)
+
+#endif /* defined(__cplusplus) */
+
+#define UPB_MAX(x, y) ((x) > (y) ? (x) : (y))
+#define UPB_MIN(x, y) ((x) < (y) ? (x) : (y))
+
+#define UPB_UNUSED(var) (void)var
+
+/* UPB_ASSERT(): in release mode, we use the expression without letting it be
+ * evaluated. This prevents "unused variable" warnings. */
+#ifdef NDEBUG
+#define UPB_ASSERT(expr) do {} while (false && (expr))
+#else
+#define UPB_ASSERT(expr) assert(expr)
+#endif
+
+/* UPB_ASSERT_DEBUGVAR(): assert that uses functions or variables that only
+ * exist in debug mode. This turns into regular assert. */
+#define UPB_ASSERT_DEBUGVAR(expr) assert(expr)
+
+#ifdef __GNUC__
+#define UPB_UNREACHABLE() do { assert(0); __builtin_unreachable(); } while(0)
+#else
+#define UPB_UNREACHABLE() do { assert(0); } while(0)
+#endif
+
+/* Generic function type. */
+typedef void upb_func();
+
+
+/* C++ Casts ******************************************************************/
+
+#ifdef __cplusplus
+
+namespace upb {
+
+template <class T> class Pointer;
+
+/* Casts to a subclass. The caller must know that cast is correct; an
+ * incorrect cast will throw an assertion failure in debug mode.
+ *
+ * Example:
+ * upb::Def* def = GetDef();
+ * // Assert-fails if this was not actually a MessageDef.
+ * upb::MessgeDef* md = upb::down_cast<upb::MessageDef>(def);
+ *
+ * Note that downcasts are only defined for some types (at the moment you can
+ * only downcast from a upb::Def to a specific Def type). */
+template<class To, class From> To down_cast(From* f);
+
+/* Casts to a subclass. If the class does not actually match the given To type,
+ * returns NULL.
+ *
+ * Example:
+ * upb::Def* def = GetDef();
+ * // md will be NULL if this was not actually a MessageDef.
+ * upb::MessgeDef* md = upb::down_cast<upb::MessageDef>(def);
+ *
+ * Note that dynamic casts are only defined for some types (at the moment you
+ * can only downcast from a upb::Def to a specific Def type).. */
+template<class To, class From> To dyn_cast(From* f);
+
+/* Casts to any base class, or the type itself (ie. can be a no-op).
+ *
+ * Example:
+ * upb::MessageDef* md = GetDef();
+ * // This will fail to compile if this wasn't actually a base class.
+ * upb::Def* def = upb::upcast(md);
+ */
+template <class T> inline Pointer<T> upcast(T *f) { return Pointer<T>(f); }
+
+/* Attempt upcast to specific base class.
+ *
+ * Example:
+ * upb::MessageDef* md = GetDef();
+ * upb::upcast_to<upb::Def>(md)->MethodOnDef();
+ */
+template <class T, class F> inline T* upcast_to(F *f) {
+ return static_cast<T*>(upcast(f));
+}
+
+/* PointerBase<T>: implementation detail of upb::upcast().
+ * It is implicitly convertable to pointers to the Base class(es).
+ */
+template <class T, class Base>
+class PointerBase {
+ public:
+ explicit PointerBase(T* ptr) : ptr_(ptr) {}
+ operator T*() { return ptr_; }
+ operator Base*() { return (Base*)ptr_; }
+
+ private:
+ T* ptr_;
+};
+
+template <class T, class Base, class Base2>
+class PointerBase2 : public PointerBase<T, Base> {
+ public:
+ explicit PointerBase2(T* ptr) : PointerBase<T, Base>(ptr) {}
+ operator Base2*() { return Pointer<Base>(*this); }
+};
+
+}
+
+#endif
+
+
+/* upb::ErrorSpace ************************************************************/
+
+/* A upb::ErrorSpace represents some domain of possible error values. This lets
+ * upb::Status attach specific error codes to operations, like POSIX/C errno,
+ * Win32 error codes, etc. Clients who want to know the very specific error
+ * code can check the error space and then know the type of the integer code.
+ *
+ * NOTE: upb::ErrorSpace is currently not used and should be considered
+ * experimental. It is important primarily in cases where upb is performing
+ * I/O, but upb doesn't currently have any components that do this. */
+
+UPB_DECLARE_TYPE(upb::ErrorSpace, upb_errorspace)
+
+#ifdef __cplusplus
+class upb::ErrorSpace {
+#else
+struct upb_errorspace {
+#endif
+ const char *name;
+};
+
+
+/* upb::Status ****************************************************************/
+
+/* upb::Status represents a success or failure status and error message.
+ * It owns no resources and allocates no memory, so it should work
+ * even in OOM situations. */
+UPB_DECLARE_TYPE(upb::Status, upb_status)
+
+/* The maximum length of an error message before it will get truncated. */
+#define UPB_STATUS_MAX_MESSAGE 128
+
+UPB_BEGIN_EXTERN_C
+
+const char *upb_status_errmsg(const upb_status *status);
+bool upb_ok(const upb_status *status);
+upb_errorspace *upb_status_errspace(const upb_status *status);
+int upb_status_errcode(const upb_status *status);
+
+/* Any of the functions that write to a status object allow status to be NULL,
+ * to support use cases where the function's caller does not care about the
+ * status message. */
+void upb_status_clear(upb_status *status);
+void upb_status_seterrmsg(upb_status *status, const char *msg);
+void upb_status_seterrf(upb_status *status, const char *fmt, ...);
+void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args);
+void upb_status_copy(upb_status *to, const upb_status *from);
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+class upb::Status {
+ public:
+ Status() { upb_status_clear(this); }
+
+ /* Returns true if there is no error. */
+ bool ok() const { return upb_ok(this); }
+
+ /* Optional error space and code, useful if the caller wants to
+ * programmatically check the specific kind of error. */
+ ErrorSpace* error_space() { return upb_status_errspace(this); }
+ int error_code() const { return upb_status_errcode(this); }
+
+ /* The returned string is invalidated by any other call into the status. */
+ const char *error_message() const { return upb_status_errmsg(this); }
+
+ /* The error message will be truncated if it is longer than
+ * UPB_STATUS_MAX_MESSAGE-4. */
+ void SetErrorMessage(const char* msg) { upb_status_seterrmsg(this, msg); }
+ void SetFormattedErrorMessage(const char* fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ upb_status_vseterrf(this, fmt, args);
+ va_end(args);
+ }
+
+ /* Resets the status to a successful state with no message. */
+ void Clear() { upb_status_clear(this); }
+
+ void CopyFrom(const Status& other) { upb_status_copy(this, &other); }
+
+ private:
+ UPB_DISALLOW_COPY_AND_ASSIGN(Status)
+#else
+struct upb_status {
+#endif
+ bool ok_;
+
+ /* Specific status code defined by some error space (optional). */
+ int code_;
+ upb_errorspace *error_space_;
+
+ /* TODO(haberman): add file/line of error? */
+
+ /* Error message; NULL-terminated. */
+ char msg[UPB_STATUS_MAX_MESSAGE];
+};
+
+#define UPB_STATUS_INIT {true, 0, NULL, {0}}
+
+
+/** Built-in error spaces. ****************************************************/
+
+/* Errors raised by upb that we want to be able to detect programmatically. */
+typedef enum {
+ UPB_NOMEM /* Can't reuse ENOMEM because it is POSIX, not ISO C. */
+} upb_errcode_t;
+
+extern upb_errorspace upb_upberr;
+
+void upb_upberr_setoom(upb_status *s);
+
+/* Since errno is defined by standard C, we define an error space for it in
+ * core upb. Other error spaces should be defined in other, platform-specific
+ * modules. */
+
+extern upb_errorspace upb_errnoerr;
+
+
+/** upb::Allocator ************************************************************/
+
+/* A upb::Allocator is a possibly-stateful allocator object.
+ *
+ * It could either be an arena allocator (which doesn't require individual
+ * free() calls) or a regular malloc() (which does). The client must therefore
+ * free memory unless it knows that the allocator is an arena allocator. */
+UPB_DECLARE_TYPE(upb::Allocator, upb_alloc)
+
+/* A malloc()/free() function.
+ * If "size" is 0 then the function acts like free(), otherwise it acts like
+ * realloc(). Only "oldsize" bytes from a previous allocation are preserved. */
+typedef void *upb_alloc_func(upb_alloc *alloc, void *ptr, size_t oldsize,
+ size_t size);
+
+#ifdef __cplusplus
+
+class upb::Allocator UPB_FINAL {
+ public:
+ Allocator() {}
+
+ private:
+ UPB_DISALLOW_COPY_AND_ASSIGN(Allocator)
+
+ public:
+#else
+struct upb_alloc {
+#endif /* __cplusplus */
+ upb_alloc_func *func;
+};
+
+UPB_INLINE void *upb_malloc(upb_alloc *alloc, size_t size) {
+ UPB_ASSERT(alloc);
+ return alloc->func(alloc, NULL, 0, size);
+}
+
+UPB_INLINE void *upb_realloc(upb_alloc *alloc, void *ptr, size_t oldsize,
+ size_t size) {
+ UPB_ASSERT(alloc);
+ return alloc->func(alloc, ptr, oldsize, size);
+}
+
+UPB_INLINE void upb_free(upb_alloc *alloc, void *ptr) {
+ assert(alloc);
+ alloc->func(alloc, ptr, 0, 0);
+}
+
+/* The global allocator used by upb. Uses the standard malloc()/free(). */
+
+extern upb_alloc upb_alloc_global;
+
+/* Functions that hard-code the global malloc.
+ *
+ * We still get benefit because we can put custom logic into our global
+ * allocator, like injecting out-of-memory faults in debug/testing builds. */
+
+UPB_INLINE void *upb_gmalloc(size_t size) {
+ return upb_malloc(&upb_alloc_global, size);
+}
+
+UPB_INLINE void *upb_grealloc(void *ptr, size_t oldsize, size_t size) {
+ return upb_realloc(&upb_alloc_global, ptr, oldsize, size);
+}
+
+UPB_INLINE void upb_gfree(void *ptr) {
+ upb_free(&upb_alloc_global, ptr);
+}
+
+/* upb::Arena *****************************************************************/
+
+/* upb::Arena is a specific allocator implementation that uses arena allocation.
+ * The user provides an allocator that will be used to allocate the underlying
+ * arena blocks. Arenas by nature do not require the individual allocations
+ * to be freed. However the Arena does allow users to register cleanup
+ * functions that will run when the arena is destroyed.
+ *
+ * A upb::Arena is *not* thread-safe.
+ *
+ * You could write a thread-safe arena allocator that satisfies the
+ * upb::Allocator interface, but it would not be as efficient for the
+ * single-threaded case. */
+UPB_DECLARE_TYPE(upb::Arena, upb_arena)
+
+typedef void upb_cleanup_func(void *ud);
+
+#define UPB_ARENA_BLOCK_OVERHEAD (sizeof(size_t)*4)
+
+UPB_BEGIN_EXTERN_C
+
+void upb_arena_init(upb_arena *a);
+void upb_arena_init2(upb_arena *a, void *mem, size_t n, upb_alloc *alloc);
+void upb_arena_uninit(upb_arena *a);
+bool upb_arena_addcleanup(upb_arena *a, upb_cleanup_func *func, void *ud);
+size_t upb_arena_bytesallocated(const upb_arena *a);
+void upb_arena_setnextblocksize(upb_arena *a, size_t size);
+void upb_arena_setmaxblocksize(upb_arena *a, size_t size);
+UPB_INLINE upb_alloc *upb_arena_alloc(upb_arena *a) { return (upb_alloc*)a; }
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+class upb::Arena {
+ public:
+ /* A simple arena with no initial memory block and the default allocator. */
+ Arena() { upb_arena_init(this); }
+
+ /* Constructs an arena with the given initial block which allocates blocks
+ * with the given allocator. The given allocator must outlive the Arena.
+ *
+ * If you pass NULL for the allocator it will default to the global allocator
+ * upb_alloc_global, and NULL/0 for the initial block will cause there to be
+ * no initial block. */
+ Arena(void *mem, size_t len, Allocator* a) {
+ upb_arena_init2(this, mem, len, a);
+ }
+
+ ~Arena() { upb_arena_uninit(this); }
+
+ /* Sets the size of the next block the Arena will request (unless the
+ * requested allocation is larger). Each block will double in size until the
+ * max limit is reached. */
+ void SetNextBlockSize(size_t size) { upb_arena_setnextblocksize(this, size); }
+
+ /* Sets the maximum block size. No blocks larger than this will be requested
+ * from the underlying allocator unless individual arena allocations are
+ * larger. */
+ void SetMaxBlockSize(size_t size) { upb_arena_setmaxblocksize(this, size); }
+
+ /* Allows this arena to be used as a generic allocator.
+ *
+ * The arena does not need free() calls so when using Arena as an allocator
+ * it is safe to skip them. However they are no-ops so there is no harm in
+ * calling free() either. */
+ Allocator* allocator() { return upb_arena_alloc(this); }
+
+ /* Add a cleanup function to run when the arena is destroyed.
+ * Returns false on out-of-memory. */
+ bool AddCleanup(upb_cleanup_func* func, void* ud) {
+ return upb_arena_addcleanup(this, func, ud);
+ }
+
+ /* Total number of bytes that have been allocated. It is undefined what
+ * Realloc() does to this counter. */
+ size_t BytesAllocated() const {
+ return upb_arena_bytesallocated(this);
+ }
+
+ private:
+ UPB_DISALLOW_COPY_AND_ASSIGN(Arena)
+
+#else
+struct upb_arena {
+#endif /* __cplusplus */
+ /* We implement the allocator interface.
+ * This must be the first member of upb_arena! */
+ upb_alloc alloc;
+
+ /* Allocator to allocate arena blocks. We are responsible for freeing these
+ * when we are destroyed. */
+ upb_alloc *block_alloc;
+
+ size_t bytes_allocated;
+ size_t next_block_size;
+ size_t max_block_size;
+
+ /* Linked list of blocks. Points to an arena_block, defined in env.c */
+ void *block_head;
+
+ /* Cleanup entries. Pointer to a cleanup_ent, defined in env.c */
+ void *cleanup_head;
+
+ /* For future expansion, since the size of this struct is exposed to users. */
+ void *future1;
+ void *future2;
+};
+
+
+/* upb::Environment ***********************************************************/
+
+/* A upb::Environment provides a means for injecting malloc and an
+ * error-reporting callback into encoders/decoders. This allows them to be
+ * independent of nearly all assumptions about their actual environment.
+ *
+ * It is also a container for allocating the encoders/decoders themselves that
+ * insulates clients from knowing their actual size. This provides ABI
+ * compatibility even if the size of the objects change. And this allows the
+ * structure definitions to be in the .c files instead of the .h files, making
+ * the .h files smaller and more readable.
+ *
+ * We might want to consider renaming this to "Pipeline" if/when the concept of
+ * a pipeline element becomes more formalized. */
+UPB_DECLARE_TYPE(upb::Environment, upb_env)
+
+/* A function that receives an error report from an encoder or decoder. The
+ * callback can return true to request that the error should be recovered, but
+ * if the error is not recoverable this has no effect. */
+typedef bool upb_error_func(void *ud, const upb_status *status);
+
+UPB_BEGIN_EXTERN_C
+
+void upb_env_init(upb_env *e);
+void upb_env_init2(upb_env *e, void *mem, size_t n, upb_alloc *alloc);
+void upb_env_uninit(upb_env *e);
+
+void upb_env_initonly(upb_env *e);
+
+upb_arena *upb_env_arena(upb_env *e);
+bool upb_env_ok(const upb_env *e);
+void upb_env_seterrorfunc(upb_env *e, upb_error_func *func, void *ud);
+
+/* Convenience wrappers around the methods of the contained arena. */
+void upb_env_reporterrorsto(upb_env *e, upb_status *s);
+bool upb_env_reporterror(upb_env *e, const upb_status *s);
+void *upb_env_malloc(upb_env *e, size_t size);
+void *upb_env_realloc(upb_env *e, void *ptr, size_t oldsize, size_t size);
+void upb_env_free(upb_env *e, void *ptr);
+bool upb_env_addcleanup(upb_env *e, upb_cleanup_func *func, void *ud);
+size_t upb_env_bytesallocated(const upb_env *e);
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+class upb::Environment {
+ public:
+ /* The given Arena must outlive this environment. */
+ Environment() { upb_env_initonly(this); }
+
+ Environment(void *mem, size_t len, Allocator *a) : arena_(mem, len, a) {
+ upb_env_initonly(this);
+ }
+
+ Arena* arena() { return upb_env_arena(this); }
+
+ /* Set a custom error reporting function. */
+ void SetErrorFunction(upb_error_func* func, void* ud) {
+ upb_env_seterrorfunc(this, func, ud);
+ }
+
+ /* Set the error reporting function to simply copy the status to the given
+ * status and abort. */
+ void ReportErrorsTo(Status* status) { upb_env_reporterrorsto(this, status); }
+
+ /* Returns true if all allocations and AddCleanup() calls have succeeded,
+ * and no errors were reported with ReportError() (except ones that recovered
+ * successfully). */
+ bool ok() const { return upb_env_ok(this); }
+
+ /* Reports an error to this environment's callback, returning true if
+ * the caller should try to recover. */
+ bool ReportError(const Status* status) {
+ return upb_env_reporterror(this, status);
+ }
+
+ private:
+ UPB_DISALLOW_COPY_AND_ASSIGN(Environment)
+
+#else
+struct upb_env {
+#endif /* __cplusplus */
+ upb_arena arena_;
+ upb_error_func *error_func_;
+ void *error_ud_;
+ bool ok_;
+};
+
+
+/* upb::InlinedArena **********************************************************/
+/* upb::InlinedEnvironment ****************************************************/
+
+/* upb::InlinedArena and upb::InlinedEnvironment seed their arenas with a
+ * predefined amount of memory. No heap memory will be allocated until the
+ * initial block is exceeded.
+ *
+ * These types only exist in C++ */
+
+#ifdef __cplusplus
+
+template <int N> class upb::InlinedArena : public upb::Arena {
+ public:
+ InlinedArena() : Arena(initial_block_, N, NULL) {}
+ explicit InlinedArena(Allocator* a) : Arena(initial_block_, N, a) {}
+
+ private:
+ UPB_DISALLOW_COPY_AND_ASSIGN(InlinedArena)
+
+ char initial_block_[N + UPB_ARENA_BLOCK_OVERHEAD];
+};
+
+template <int N> class upb::InlinedEnvironment : public upb::Environment {
+ public:
+ InlinedEnvironment() : Environment(initial_block_, N, NULL) {}
+ explicit InlinedEnvironment(Allocator *a)
+ : Environment(initial_block_, N, a) {}
+
+ private:
+ UPB_DISALLOW_COPY_AND_ASSIGN(InlinedEnvironment)
+
+ char initial_block_[N + UPB_ARENA_BLOCK_OVERHEAD];
+};
+
+#endif /* __cplusplus */
+
+
+
+#endif /* UPB_H_ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* upb_value ******************************************************************/
+
+/* A tagged union (stored untagged inside the table) so that we can check that
+ * clients calling table accessors are correctly typed without having to have
+ * an explosion of accessors. */
+typedef enum {
+ UPB_CTYPE_INT32 = 1,
+ UPB_CTYPE_INT64 = 2,
+ UPB_CTYPE_UINT32 = 3,
+ UPB_CTYPE_UINT64 = 4,
+ UPB_CTYPE_BOOL = 5,
+ UPB_CTYPE_CSTR = 6,
+ UPB_CTYPE_PTR = 7,
+ UPB_CTYPE_CONSTPTR = 8,
+ UPB_CTYPE_FPTR = 9,
+ UPB_CTYPE_FLOAT = 10,
+ UPB_CTYPE_DOUBLE = 11
+} upb_ctype_t;
+
+typedef struct {
+ uint64_t val;
+#ifndef NDEBUG
+ /* In debug mode we carry the value type around also so we can check accesses
+ * to be sure the right member is being read. */
+ upb_ctype_t ctype;
+#endif
+} upb_value;
+
+#ifdef NDEBUG
+#define SET_TYPE(dest, val) UPB_UNUSED(val)
+#else
+#define SET_TYPE(dest, val) dest = val
+#endif
+
+/* Like strdup(), which isn't always available since it's not ANSI C. */
+char *upb_strdup(const char *s, upb_alloc *a);
+/* Variant that works with a length-delimited rather than NULL-delimited string,
+ * as supported by strtable. */
+char *upb_strdup2(const char *s, size_t len, upb_alloc *a);
+
+UPB_INLINE char *upb_gstrdup(const char *s) {
+ return upb_strdup(s, &upb_alloc_global);
+}
+
+UPB_INLINE void _upb_value_setval(upb_value *v, uint64_t val,
+ upb_ctype_t ctype) {
+ v->val = val;
+ SET_TYPE(v->ctype, ctype);
+}
+
+UPB_INLINE upb_value _upb_value_val(uint64_t val, upb_ctype_t ctype) {
+ upb_value ret;
+ _upb_value_setval(&ret, val, ctype);
+ return ret;
+}
+
+/* For each value ctype, define the following set of functions:
+ *
+ * // Get/set an int32 from a upb_value.
+ * int32_t upb_value_getint32(upb_value val);
+ * void upb_value_setint32(upb_value *val, int32_t cval);
+ *
+ * // Construct a new upb_value from an int32.
+ * upb_value upb_value_int32(int32_t val); */
+#define FUNCS(name, membername, type_t, converter, proto_type) \
+ UPB_INLINE void upb_value_set ## name(upb_value *val, type_t cval) { \
+ val->val = (converter)cval; \
+ SET_TYPE(val->ctype, proto_type); \
+ } \
+ UPB_INLINE upb_value upb_value_ ## name(type_t val) { \
+ upb_value ret; \
+ upb_value_set ## name(&ret, val); \
+ return ret; \
+ } \
+ UPB_INLINE type_t upb_value_get ## name(upb_value val) { \
+ UPB_ASSERT_DEBUGVAR(val.ctype == proto_type); \
+ return (type_t)(converter)val.val; \
+ }
+
+FUNCS(int32, int32, int32_t, int32_t, UPB_CTYPE_INT32)
+FUNCS(int64, int64, int64_t, int64_t, UPB_CTYPE_INT64)
+FUNCS(uint32, uint32, uint32_t, uint32_t, UPB_CTYPE_UINT32)
+FUNCS(uint64, uint64, uint64_t, uint64_t, UPB_CTYPE_UINT64)
+FUNCS(bool, _bool, bool, bool, UPB_CTYPE_BOOL)
+FUNCS(cstr, cstr, char*, uintptr_t, UPB_CTYPE_CSTR)
+FUNCS(ptr, ptr, void*, uintptr_t, UPB_CTYPE_PTR)
+FUNCS(constptr, constptr, const void*, uintptr_t, UPB_CTYPE_CONSTPTR)
+FUNCS(fptr, fptr, upb_func*, uintptr_t, UPB_CTYPE_FPTR)
+
+#undef FUNCS
+
+UPB_INLINE void upb_value_setfloat(upb_value *val, float cval) {
+ memcpy(&val->val, &cval, sizeof(cval));
+ SET_TYPE(val->ctype, UPB_CTYPE_FLOAT);
+}
+
+UPB_INLINE void upb_value_setdouble(upb_value *val, double cval) {
+ memcpy(&val->val, &cval, sizeof(cval));
+ SET_TYPE(val->ctype, UPB_CTYPE_DOUBLE);
+}
+
+UPB_INLINE upb_value upb_value_float(float cval) {
+ upb_value ret;
+ upb_value_setfloat(&ret, cval);
+ return ret;
+}
+
+UPB_INLINE upb_value upb_value_double(double cval) {
+ upb_value ret;
+ upb_value_setdouble(&ret, cval);
+ return ret;
+}
+
+#undef SET_TYPE
+
+
+/* upb_tabkey *****************************************************************/
+
+/* Either:
+ * 1. an actual integer key, or
+ * 2. a pointer to a string prefixed by its uint32_t length, owned by us.
+ *
+ * ...depending on whether this is a string table or an int table. We would
+ * make this a union of those two types, but C89 doesn't support statically
+ * initializing a non-first union member. */
+typedef uintptr_t upb_tabkey;
+
+#define UPB_TABKEY_NUM(n) n
+#define UPB_TABKEY_NONE 0
+/* The preprocessor isn't quite powerful enough to turn the compile-time string
+ * length into a byte-wise string representation, so code generation needs to
+ * help it along.
+ *
+ * "len1" is the low byte and len4 is the high byte. */
+#ifdef UPB_BIG_ENDIAN
+#define UPB_TABKEY_STR(len1, len2, len3, len4, strval) \
+ (uintptr_t)(len4 len3 len2 len1 strval)
+#else
+#define UPB_TABKEY_STR(len1, len2, len3, len4, strval) \
+ (uintptr_t)(len1 len2 len3 len4 strval)
+#endif
+
+UPB_INLINE char *upb_tabstr(upb_tabkey key, uint32_t *len) {
+ char* mem = (char*)key;
+ if (len) memcpy(len, mem, sizeof(*len));
+ return mem + sizeof(*len);
+}
+
+
+/* upb_tabval *****************************************************************/
+
+#ifdef __cplusplus
+
+/* Status initialization not supported.
+ *
+ * This separate definition is necessary because in C++, UINTPTR_MAX isn't
+ * reliably available. */
+typedef struct {
+ uint64_t val;
+} upb_tabval;
+
+#else
+
+/* C -- supports static initialization, but to support static initialization of
+ * both integers and points for both 32 and 64 bit targets, it takes a little
+ * bit of doing. */
+
+#if UINTPTR_MAX == 0xffffffffffffffffULL
+#define UPB_PTR_IS_64BITS
+#elif UINTPTR_MAX != 0xffffffff
+#error Could not determine how many bits pointers are.
+#endif
+
+typedef union {
+ /* For static initialization.
+ *
+ * Unfortunately this ugliness is necessary -- it is the only way that we can,
+ * with -std=c89 -pedantic, statically initialize this to either a pointer or
+ * an integer on 32-bit platforms. */
+ struct {
+#ifdef UPB_PTR_IS_64BITS
+ uintptr_t val;
+#else
+ uintptr_t val1;
+ uintptr_t val2;
+#endif
+ } staticinit;
+
+ /* The normal accessor that we use for everything at runtime. */
+ uint64_t val;
+} upb_tabval;
+
+#ifdef UPB_PTR_IS_64BITS
+#define UPB_TABVALUE_INT_INIT(v) {{v}}
+#define UPB_TABVALUE_EMPTY_INIT {{-1}}
+#else
+
+/* 32-bit pointers */
+
+#ifdef UPB_BIG_ENDIAN
+#define UPB_TABVALUE_INT_INIT(v) {{0, v}}
+#define UPB_TABVALUE_EMPTY_INIT {{-1, -1}}
+#else
+#define UPB_TABVALUE_INT_INIT(v) {{v, 0}}
+#define UPB_TABVALUE_EMPTY_INIT {{-1, -1}}
+#endif
+
+#endif
+
+#define UPB_TABVALUE_PTR_INIT(v) UPB_TABVALUE_INT_INIT((uintptr_t)v)
+
+#undef UPB_PTR_IS_64BITS
+
+#endif /* __cplusplus */
+
+
+/* upb_table ******************************************************************/
+
+typedef struct _upb_tabent {
+ upb_tabkey key;
+ upb_tabval val;
+
+ /* Internal chaining. This is const so we can create static initializers for
+ * tables. We cast away const sometimes, but *only* when the containing
+ * upb_table is known to be non-const. This requires a bit of care, but
+ * the subtlety is confined to table.c. */
+ const struct _upb_tabent *next;
+} upb_tabent;
+
+typedef struct {
+ size_t count; /* Number of entries in the hash part. */
+ size_t mask; /* Mask to turn hash value -> bucket. */
+ upb_ctype_t ctype; /* Type of all values. */
+ uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */
+
+ /* Hash table entries.
+ * Making this const isn't entirely accurate; what we really want is for it to
+ * have the same const-ness as the table it's inside. But there's no way to
+ * declare that in C. So we have to make it const so that we can statically
+ * initialize const hash tables. Then we cast away const when we have to.
+ */
+ const upb_tabent *entries;
+
+#ifndef NDEBUG
+ /* This table's allocator. We make the user pass it in to every relevant
+ * function and only use this to check it in debug mode. We do this solely
+ * to keep upb_table as small as possible. This might seem slightly paranoid
+ * but the plan is to use upb_table for all map fields and extension sets in
+ * a forthcoming message representation, so there could be a lot of these.
+ * If this turns out to be too annoying later, we can change it (since this
+ * is an internal-only header file). */
+ upb_alloc *alloc;
+#endif
+} upb_table;
+
+#ifdef NDEBUG
+# define UPB_TABLE_INIT(count, mask, ctype, size_lg2, entries) \
+ {count, mask, ctype, size_lg2, entries}
+#else
+# ifdef UPB_DEBUG_REFS
+/* At the moment the only mutable tables we statically initialize are debug
+ * ref tables. */
+# define UPB_TABLE_INIT(count, mask, ctype, size_lg2, entries) \
+ {count, mask, ctype, size_lg2, entries, &upb_alloc_debugrefs}
+# else
+# define UPB_TABLE_INIT(count, mask, ctype, size_lg2, entries) \
+ {count, mask, ctype, size_lg2, entries, NULL}
+# endif
+#endif
+
+typedef struct {
+ upb_table t;
+} upb_strtable;
+
+#define UPB_STRTABLE_INIT(count, mask, ctype, size_lg2, entries) \
+ {UPB_TABLE_INIT(count, mask, ctype, size_lg2, entries)}
+
+#define UPB_EMPTY_STRTABLE_INIT(ctype) \
+ UPB_STRTABLE_INIT(0, 0, ctype, 0, NULL)
+
+typedef struct {
+ upb_table t; /* For entries that don't fit in the array part. */
+ const upb_tabval *array; /* Array part of the table. See const note above. */
+ size_t array_size; /* Array part size. */
+ size_t array_count; /* Array part number of elements. */
+} upb_inttable;
+
+#define UPB_INTTABLE_INIT(count, mask, ctype, size_lg2, ent, a, asize, acount) \
+ {UPB_TABLE_INIT(count, mask, ctype, size_lg2, ent), a, asize, acount}
+
+#define UPB_EMPTY_INTTABLE_INIT(ctype) \
+ UPB_INTTABLE_INIT(0, 0, ctype, 0, NULL, NULL, 0, 0)
+
+#define UPB_ARRAY_EMPTYENT -1
+
+UPB_INLINE size_t upb_table_size(const upb_table *t) {
+ if (t->size_lg2 == 0)
+ return 0;
+ else
+ return 1 << t->size_lg2;
+}
+
+/* Internal-only functions, in .h file only out of necessity. */
+UPB_INLINE bool upb_tabent_isempty(const upb_tabent *e) {
+ return e->key == 0;
+}
+
+/* Used by some of the unit tests for generic hashing functionality. */
+uint32_t MurmurHash2(const void * key, size_t len, uint32_t seed);
+
+UPB_INLINE uintptr_t upb_intkey(uintptr_t key) {
+ return key;
+}
+
+UPB_INLINE uint32_t upb_inthash(uintptr_t key) {
+ return (uint32_t)key;
+}
+
+static const upb_tabent *upb_getentry(const upb_table *t, uint32_t hash) {
+ return t->entries + (hash & t->mask);
+}
+
+UPB_INLINE bool upb_arrhas(upb_tabval key) {
+ return key.val != (uint64_t)-1;
+}
+
+/* Initialize and uninitialize a table, respectively. If memory allocation
+ * failed, false is returned that the table is uninitialized. */
+bool upb_inttable_init2(upb_inttable *table, upb_ctype_t ctype, upb_alloc *a);
+bool upb_strtable_init2(upb_strtable *table, upb_ctype_t ctype, upb_alloc *a);
+void upb_inttable_uninit2(upb_inttable *table, upb_alloc *a);
+void upb_strtable_uninit2(upb_strtable *table, upb_alloc *a);
+
+UPB_INLINE bool upb_inttable_init(upb_inttable *table, upb_ctype_t ctype) {
+ return upb_inttable_init2(table, ctype, &upb_alloc_global);
+}
+
+UPB_INLINE bool upb_strtable_init(upb_strtable *table, upb_ctype_t ctype) {
+ return upb_strtable_init2(table, ctype, &upb_alloc_global);
+}
+
+UPB_INLINE void upb_inttable_uninit(upb_inttable *table) {
+ upb_inttable_uninit2(table, &upb_alloc_global);
+}
+
+UPB_INLINE void upb_strtable_uninit(upb_strtable *table) {
+ upb_strtable_uninit2(table, &upb_alloc_global);
+}
+
+/* Returns the number of values in the table. */
+size_t upb_inttable_count(const upb_inttable *t);
+UPB_INLINE size_t upb_strtable_count(const upb_strtable *t) {
+ return t->t.count;
+}
+
+void upb_inttable_packedsize(const upb_inttable *t, size_t *size);
+void upb_strtable_packedsize(const upb_strtable *t, size_t *size);
+upb_inttable *upb_inttable_pack(const upb_inttable *t, void *p, size_t *ofs,
+ size_t size);
+upb_strtable *upb_strtable_pack(const upb_strtable *t, void *p, size_t *ofs,
+ size_t size);
+
+/* Inserts the given key into the hashtable with the given value. The key must
+ * not already exist in the hash table. For string tables, the key must be
+ * NULL-terminated, and the table will make an internal copy of the key.
+ * Inttables must not insert a value of UINTPTR_MAX.
+ *
+ * If a table resize was required but memory allocation failed, false is
+ * returned and the table is unchanged. */
+bool upb_inttable_insert2(upb_inttable *t, uintptr_t key, upb_value val,
+ upb_alloc *a);
+bool upb_strtable_insert3(upb_strtable *t, const char *key, size_t len,
+ upb_value val, upb_alloc *a);
+
+UPB_INLINE bool upb_inttable_insert(upb_inttable *t, uintptr_t key,
+ upb_value val) {
+ return upb_inttable_insert2(t, key, val, &upb_alloc_global);
+}
+
+UPB_INLINE bool upb_strtable_insert2(upb_strtable *t, const char *key,
+ size_t len, upb_value val) {
+ return upb_strtable_insert3(t, key, len, val, &upb_alloc_global);
+}
+
+/* For NULL-terminated strings. */
+UPB_INLINE bool upb_strtable_insert(upb_strtable *t, const char *key,
+ upb_value val) {
+ return upb_strtable_insert2(t, key, strlen(key), val);
+}
+
+/* Looks up key in this table, returning "true" if the key was found.
+ * If v is non-NULL, copies the value for this key into *v. */
+bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v);
+bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len,
+ upb_value *v);
+
+/* For NULL-terminated strings. */
+UPB_INLINE bool upb_strtable_lookup(const upb_strtable *t, const char *key,
+ upb_value *v) {
+ return upb_strtable_lookup2(t, key, strlen(key), v);
+}
+
+/* Removes an item from the table. Returns true if the remove was successful,
+ * and stores the removed item in *val if non-NULL. */
+bool upb_inttable_remove(upb_inttable *t, uintptr_t key, upb_value *val);
+bool upb_strtable_remove3(upb_strtable *t, const char *key, size_t len,
+ upb_value *val, upb_alloc *alloc);
+
+UPB_INLINE bool upb_strtable_remove2(upb_strtable *t, const char *key,
+ size_t len, upb_value *val) {
+ return upb_strtable_remove3(t, key, len, val, &upb_alloc_global);
+}
+
+/* For NULL-terminated strings. */
+UPB_INLINE bool upb_strtable_remove(upb_strtable *t, const char *key,
+ upb_value *v) {
+ return upb_strtable_remove2(t, key, strlen(key), v);
+}
+
+/* Updates an existing entry in an inttable. If the entry does not exist,
+ * returns false and does nothing. Unlike insert/remove, this does not
+ * invalidate iterators. */
+bool upb_inttable_replace(upb_inttable *t, uintptr_t key, upb_value val);
+
+/* Handy routines for treating an inttable like a stack. May not be mixed with
+ * other insert/remove calls. */
+bool upb_inttable_push2(upb_inttable *t, upb_value val, upb_alloc *a);
+upb_value upb_inttable_pop(upb_inttable *t);
+
+UPB_INLINE bool upb_inttable_push(upb_inttable *t, upb_value val) {
+ return upb_inttable_push2(t, val, &upb_alloc_global);
+}
+
+/* Convenience routines for inttables with pointer keys. */
+bool upb_inttable_insertptr2(upb_inttable *t, const void *key, upb_value val,
+ upb_alloc *a);
+bool upb_inttable_removeptr(upb_inttable *t, const void *key, upb_value *val);
+bool upb_inttable_lookupptr(
+ const upb_inttable *t, const void *key, upb_value *val);
+
+UPB_INLINE bool upb_inttable_insertptr(upb_inttable *t, const void *key,
+ upb_value val) {
+ return upb_inttable_insertptr2(t, key, val, &upb_alloc_global);
+}
+
+/* Optimizes the table for the current set of entries, for both memory use and
+ * lookup time. Client should call this after all entries have been inserted;
+ * inserting more entries is legal, but will likely require a table resize. */
+void upb_inttable_compact2(upb_inttable *t, upb_alloc *a);
+
+UPB_INLINE void upb_inttable_compact(upb_inttable *t) {
+ upb_inttable_compact2(t, &upb_alloc_global);
+}
+
+/* A special-case inlinable version of the lookup routine for 32-bit
+ * integers. */
+UPB_INLINE bool upb_inttable_lookup32(const upb_inttable *t, uint32_t key,
+ upb_value *v) {
+ *v = upb_value_int32(0); /* Silence compiler warnings. */
+ if (key < t->array_size) {
+ upb_tabval arrval = t->array[key];
+ if (upb_arrhas(arrval)) {
+ _upb_value_setval(v, arrval.val, t->t.ctype);
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ const upb_tabent *e;
+ if (t->t.entries == NULL) return false;
+ for (e = upb_getentry(&t->t, upb_inthash(key)); true; e = e->next) {
+ if ((uint32_t)e->key == key) {
+ _upb_value_setval(v, e->val.val, t->t.ctype);
+ return true;
+ }
+ if (e->next == NULL) return false;
+ }
+ }
+}
+
+/* Exposed for testing only. */
+bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_alloc *a);
+
+/* Iterators ******************************************************************/
+
+/* Iterators for int and string tables. We are subject to some kind of unusual
+ * design constraints:
+ *
+ * For high-level languages:
+ * - we must be able to guarantee that we don't crash or corrupt memory even if
+ * the program accesses an invalidated iterator.
+ *
+ * For C++11 range-based for:
+ * - iterators must be copyable
+ * - iterators must be comparable
+ * - it must be possible to construct an "end" value.
+ *
+ * Iteration order is undefined.
+ *
+ * Modifying the table invalidates iterators. upb_{str,int}table_done() is
+ * guaranteed to work even on an invalidated iterator, as long as the table it
+ * is iterating over has not been freed. Calling next() or accessing data from
+ * an invalidated iterator yields unspecified elements from the table, but it is
+ * guaranteed not to crash and to return real table elements (except when done()
+ * is true). */
+
+
+/* upb_strtable_iter **********************************************************/
+
+/* upb_strtable_iter i;
+ * upb_strtable_begin(&i, t);
+ * for(; !upb_strtable_done(&i); upb_strtable_next(&i)) {
+ * const char *key = upb_strtable_iter_key(&i);
+ * const upb_value val = upb_strtable_iter_value(&i);
+ * // ...
+ * }
+ */
+
+typedef struct {
+ const upb_strtable *t;
+ size_t index;
+} upb_strtable_iter;
+
+void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t);
+void upb_strtable_next(upb_strtable_iter *i);
+bool upb_strtable_done(const upb_strtable_iter *i);
+const char *upb_strtable_iter_key(const upb_strtable_iter *i);
+size_t upb_strtable_iter_keylength(const upb_strtable_iter *i);
+upb_value upb_strtable_iter_value(const upb_strtable_iter *i);
+void upb_strtable_iter_setdone(upb_strtable_iter *i);
+bool upb_strtable_iter_isequal(const upb_strtable_iter *i1,
+ const upb_strtable_iter *i2);
+
+
+/* upb_inttable_iter **********************************************************/
+
+/* upb_inttable_iter i;
+ * upb_inttable_begin(&i, t);
+ * for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ * uintptr_t key = upb_inttable_iter_key(&i);
+ * upb_value val = upb_inttable_iter_value(&i);
+ * // ...
+ * }
+ */
+
+typedef struct {
+ const upb_inttable *t;
+ size_t index;
+ bool array_part;
+} upb_inttable_iter;
+
+void upb_inttable_begin(upb_inttable_iter *i, const upb_inttable *t);
+void upb_inttable_next(upb_inttable_iter *i);
+bool upb_inttable_done(const upb_inttable_iter *i);
+uintptr_t upb_inttable_iter_key(const upb_inttable_iter *i);
+upb_value upb_inttable_iter_value(const upb_inttable_iter *i);
+void upb_inttable_iter_setdone(upb_inttable_iter *i);
+bool upb_inttable_iter_isequal(const upb_inttable_iter *i1,
+ const upb_inttable_iter *i2);
+
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* UPB_TABLE_H_ */
+
+/* Reference tracking will check ref()/unref() operations to make sure the
+ * ref ownership is correct. Where possible it will also make tools like
+ * Valgrind attribute ref leaks to the code that took the leaked ref, not
+ * the code that originally created the object.
+ *
+ * Enabling this requires the application to define upb_lock()/upb_unlock()
+ * functions that acquire/release a global mutex (or #define UPB_THREAD_UNSAFE).
+ * For this reason we don't enable it by default, even in debug builds.
+ */
+
+/* #define UPB_DEBUG_REFS */
+
+#ifdef __cplusplus
+namespace upb {
+class RefCounted;
+template <class T> class reffed_ptr;
+}
+#endif
+
+UPB_DECLARE_TYPE(upb::RefCounted, upb_refcounted)
+
+struct upb_refcounted_vtbl;
+
+#ifdef __cplusplus
+
+class upb::RefCounted {
+ public:
+ /* Returns true if the given object is frozen. */
+ bool IsFrozen() const;
+
+ /* Increases the ref count, the new ref is owned by "owner" which must not
+ * already own a ref (and should not itself be a refcounted object if the ref
+ * could possibly be circular; see below).
+ * Thread-safe iff "this" is frozen. */
+ void Ref(const void *owner) const;
+
+ /* Release a ref that was acquired from upb_refcounted_ref() and collects any
+ * objects it can. */
+ void Unref(const void *owner) const;
+
+ /* Moves an existing ref from "from" to "to", without changing the overall
+ * ref count. DonateRef(foo, NULL, owner) is the same as Ref(foo, owner),
+ * but "to" may not be NULL. */
+ void DonateRef(const void *from, const void *to) const;
+
+ /* Verifies that a ref to the given object is currently held by the given
+ * owner. Only effective in UPB_DEBUG_REFS builds. */
+ void CheckRef(const void *owner) const;
+
+ private:
+ UPB_DISALLOW_POD_OPS(RefCounted, upb::RefCounted)
+#else
+struct upb_refcounted {
+#endif
+ /* TODO(haberman): move the actual structure definition to structdefs.int.h.
+ * The only reason they are here is because inline functions need to see the
+ * definition of upb_handlers, which needs to see this definition. But we
+ * can change the upb_handlers inline functions to deal in raw offsets
+ * instead.
+ */
+
+ /* A single reference count shared by all objects in the group. */
+ uint32_t *group;
+
+ /* A singly-linked list of all objects in the group. */
+ upb_refcounted *next;
+
+ /* Table of function pointers for this type. */
+ const struct upb_refcounted_vtbl *vtbl;
+
+ /* Maintained only when mutable, this tracks the number of refs (but not
+ * ref2's) to this object. *group should be the sum of all individual_count
+ * in the group. */
+ uint32_t individual_count;
+
+ bool is_frozen;
+
+#ifdef UPB_DEBUG_REFS
+ upb_inttable *refs; /* Maps owner -> trackedref for incoming refs. */
+ upb_inttable *ref2s; /* Set of targets for outgoing ref2s. */
+#endif
+};
+
+#ifdef UPB_DEBUG_REFS
+extern upb_alloc upb_alloc_debugrefs;
+#define UPB_REFCOUNT_INIT(vtbl, refs, ref2s) \
+ {&static_refcount, NULL, vtbl, 0, true, refs, ref2s}
+#else
+#define UPB_REFCOUNT_INIT(vtbl, refs, ref2s) \
+ {&static_refcount, NULL, vtbl, 0, true}
+#endif
+
+UPB_BEGIN_EXTERN_C
+
+/* It is better to use tracked refs when possible, for the extra debugging
+ * capability. But if this is not possible (because you don't have easy access
+ * to a stable pointer value that is associated with the ref), you can pass
+ * UPB_UNTRACKED_REF instead. */
+extern const void *UPB_UNTRACKED_REF;
+
+/* Native C API. */
+bool upb_refcounted_isfrozen(const upb_refcounted *r);
+void upb_refcounted_ref(const upb_refcounted *r, const void *owner);
+void upb_refcounted_unref(const upb_refcounted *r, const void *owner);
+void upb_refcounted_donateref(
+ const upb_refcounted *r, const void *from, const void *to);
+void upb_refcounted_checkref(const upb_refcounted *r, const void *owner);
+
+#define UPB_REFCOUNTED_CMETHODS(type, upcastfunc) \
+ UPB_INLINE bool type ## _isfrozen(const type *v) { \
+ return upb_refcounted_isfrozen(upcastfunc(v)); \
+ } \
+ UPB_INLINE void type ## _ref(const type *v, const void *owner) { \
+ upb_refcounted_ref(upcastfunc(v), owner); \
+ } \
+ UPB_INLINE void type ## _unref(const type *v, const void *owner) { \
+ upb_refcounted_unref(upcastfunc(v), owner); \
+ } \
+ UPB_INLINE void type ## _donateref(const type *v, const void *from, const void *to) { \
+ upb_refcounted_donateref(upcastfunc(v), from, to); \
+ } \
+ UPB_INLINE void type ## _checkref(const type *v, const void *owner) { \
+ upb_refcounted_checkref(upcastfunc(v), owner); \
+ }
+
+#define UPB_REFCOUNTED_CPPMETHODS \
+ bool IsFrozen() const { \
+ return upb::upcast_to<const upb::RefCounted>(this)->IsFrozen(); \
+ } \
+ void Ref(const void *owner) const { \
+ return upb::upcast_to<const upb::RefCounted>(this)->Ref(owner); \
+ } \
+ void Unref(const void *owner) const { \
+ return upb::upcast_to<const upb::RefCounted>(this)->Unref(owner); \
+ } \
+ void DonateRef(const void *from, const void *to) const { \
+ return upb::upcast_to<const upb::RefCounted>(this)->DonateRef(from, to); \
+ } \
+ void CheckRef(const void *owner) const { \
+ return upb::upcast_to<const upb::RefCounted>(this)->CheckRef(owner); \
+ }
+
+/* Internal-to-upb Interface **************************************************/
+
+typedef void upb_refcounted_visit(const upb_refcounted *r,
+ const upb_refcounted *subobj,
+ void *closure);
+
+struct upb_refcounted_vtbl {
+ /* Must visit all subobjects that are currently ref'd via upb_refcounted_ref2.
+ * Must be longjmp()-safe. */
+ void (*visit)(const upb_refcounted *r, upb_refcounted_visit *visit, void *c);
+
+ /* Must free the object and release all references to other objects. */
+ void (*free)(upb_refcounted *r);
+};
+
+/* Initializes the refcounted with a single ref for the given owner. Returns
+ * false if memory could not be allocated. */
+bool upb_refcounted_init(upb_refcounted *r,
+ const struct upb_refcounted_vtbl *vtbl,
+ const void *owner);
+
+/* Adds a ref from one refcounted object to another ("from" must not already
+ * own a ref). These refs may be circular; cycles will be collected correctly
+ * (if conservatively). These refs do not need to be freed in from's free()
+ * function. */
+void upb_refcounted_ref2(const upb_refcounted *r, upb_refcounted *from);
+
+/* Removes a ref that was acquired from upb_refcounted_ref2(), and collects any
+ * object it can. This is only necessary when "from" no longer points to "r",
+ * and not from from's "free" function. */
+void upb_refcounted_unref2(const upb_refcounted *r, upb_refcounted *from);
+
+#define upb_ref2(r, from) \
+ upb_refcounted_ref2((const upb_refcounted*)r, (upb_refcounted*)from)
+#define upb_unref2(r, from) \
+ upb_refcounted_unref2((const upb_refcounted*)r, (upb_refcounted*)from)
+
+/* Freezes all mutable object reachable by ref2() refs from the given roots.
+ * This will split refcounting groups into precise SCC groups, so that
+ * refcounting of frozen objects can be more aggressive. If memory allocation
+ * fails, or if more than 2**31 mutable objects are reachable from "roots", or
+ * if the maximum depth of the graph exceeds "maxdepth", false is returned and
+ * the objects are unchanged.
+ *
+ * After this operation succeeds, the objects are frozen/const, and may not be
+ * used through non-const pointers. In particular, they may not be passed as
+ * the second parameter of upb_refcounted_{ref,unref}2(). On the upside, all
+ * operations on frozen refcounteds are threadsafe, and objects will be freed
+ * at the precise moment that they become unreachable.
+ *
+ * Caller must own refs on each object in the "roots" list. */
+bool upb_refcounted_freeze(upb_refcounted *const*roots, int n, upb_status *s,
+ int maxdepth);
+
+/* Shared by all compiled-in refcounted objects. */
+extern uint32_t static_refcount;
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+/* C++ Wrappers. */
+namespace upb {
+inline bool RefCounted::IsFrozen() const {
+ return upb_refcounted_isfrozen(this);
+}
+inline void RefCounted::Ref(const void *owner) const {
+ upb_refcounted_ref(this, owner);
+}
+inline void RefCounted::Unref(const void *owner) const {
+ upb_refcounted_unref(this, owner);
+}
+inline void RefCounted::DonateRef(const void *from, const void *to) const {
+ upb_refcounted_donateref(this, from, to);
+}
+inline void RefCounted::CheckRef(const void *owner) const {
+ upb_refcounted_checkref(this, owner);
+}
+} /* namespace upb */
+#endif
+
+
+/* upb::reffed_ptr ************************************************************/
+
+#ifdef __cplusplus
+
+#include <algorithm> /* For std::swap(). */
+
+/* Provides RAII semantics for upb refcounted objects. Each reffed_ptr owns a
+ * ref on whatever object it points to (if any). */
+template <class T> class upb::reffed_ptr {
+ public:
+ reffed_ptr() : ptr_(NULL) {}
+
+ /* If ref_donor is NULL, takes a new ref, otherwise adopts from ref_donor. */
+ template <class U>
+ reffed_ptr(U* val, const void* ref_donor = NULL)
+ : ptr_(upb::upcast(val)) {
+ if (ref_donor) {
+ UPB_ASSERT(ptr_);
+ ptr_->DonateRef(ref_donor, this);
+ } else if (ptr_) {
+ ptr_->Ref(this);
+ }
+ }
+
+ template <class U>
+ reffed_ptr(const reffed_ptr<U>& other)
+ : ptr_(upb::upcast(other.get())) {
+ if (ptr_) ptr_->Ref(this);
+ }
+
+ reffed_ptr(const reffed_ptr& other)
+ : ptr_(upb::upcast(other.get())) {
+ if (ptr_) ptr_->Ref(this);
+ }
+
+ ~reffed_ptr() { if (ptr_) ptr_->Unref(this); }
+
+ template <class U>
+ reffed_ptr& operator=(const reffed_ptr<U>& other) {
+ reset(other.get());
+ return *this;
+ }
+
+ reffed_ptr& operator=(const reffed_ptr& other) {
+ reset(other.get());
+ return *this;
+ }
+
+ /* TODO(haberman): add C++11 move construction/assignment for greater
+ * efficiency. */
+
+ void swap(reffed_ptr& other) {
+ if (ptr_ == other.ptr_) {
+ return;
+ }
+
+ if (ptr_) ptr_->DonateRef(this, &other);
+ if (other.ptr_) other.ptr_->DonateRef(&other, this);
+ std::swap(ptr_, other.ptr_);
+ }
+
+ T& operator*() const {
+ UPB_ASSERT(ptr_);
+ return *ptr_;
+ }
+
+ T* operator->() const {
+ UPB_ASSERT(ptr_);
+ return ptr_;
+ }
+
+ T* get() const { return ptr_; }
+
+ /* If ref_donor is NULL, takes a new ref, otherwise adopts from ref_donor. */
+ template <class U>
+ void reset(U* ptr = NULL, const void* ref_donor = NULL) {
+ reffed_ptr(ptr, ref_donor).swap(*this);
+ }
+
+ template <class U>
+ reffed_ptr<U> down_cast() {
+ return reffed_ptr<U>(upb::down_cast<U*>(get()));
+ }
+
+ template <class U>
+ reffed_ptr<U> dyn_cast() {
+ return reffed_ptr<U>(upb::dyn_cast<U*>(get()));
+ }
+
+ /* Plain release() is unsafe; if we were the only owner, it would leak the
+ * object. Instead we provide this: */
+ T* ReleaseTo(const void* new_owner) {
+ T* ret = NULL;
+ ptr_->DonateRef(this, new_owner);
+ std::swap(ret, ptr_);
+ return ret;
+ }
+
+ private:
+ T* ptr_;
+};
+
+#endif /* __cplusplus */
+
+#endif /* UPB_REFCOUNT_H_ */
+
+#ifdef __cplusplus
+#include <cstring>
+#include <string>
+#include <vector>
+
+namespace upb {
+class Def;
+class EnumDef;
+class FieldDef;
+class FileDef;
+class MessageDef;
+class OneofDef;
+class SymbolTable;
+}
+#endif
+
+UPB_DECLARE_DERIVED_TYPE(upb::Def, upb::RefCounted, upb_def, upb_refcounted)
+UPB_DECLARE_DERIVED_TYPE(upb::OneofDef, upb::RefCounted, upb_oneofdef,
+ upb_refcounted)
+UPB_DECLARE_DERIVED_TYPE(upb::FileDef, upb::RefCounted, upb_filedef,
+ upb_refcounted)
+UPB_DECLARE_TYPE(upb::SymbolTable, upb_symtab)
+
+
+/* The maximum message depth that the type graph can have. This is a resource
+ * limit for the C stack since we sometimes need to recursively traverse the
+ * graph. Cycles are ok; the traversal will stop when it detects a cycle, but
+ * we must hit the cycle before the maximum depth is reached.
+ *
+ * If having a single static limit is too inflexible, we can add another variant
+ * of Def::Freeze that allows specifying this as a parameter. */
+#define UPB_MAX_MESSAGE_DEPTH 64
+
+
+/* upb::Def: base class for top-level defs ***********************************/
+
+/* All the different kind of defs that can be defined at the top-level and put
+ * in a SymbolTable or appear in a FileDef::defs() list. This excludes some
+ * defs (like oneofs and files). It only includes fields because they can be
+ * defined as extensions. */
+typedef enum {
+ UPB_DEF_MSG,
+ UPB_DEF_FIELD,
+ UPB_DEF_ENUM,
+ UPB_DEF_SERVICE, /* Not yet implemented. */
+ UPB_DEF_ANY = -1 /* Wildcard for upb_symtab_get*() */
+} upb_deftype_t;
+
+#ifdef __cplusplus
+
+/* The base class of all defs. Its base is upb::RefCounted (use upb::upcast()
+ * to convert). */
+class upb::Def {
+ public:
+ typedef upb_deftype_t Type;
+
+ /* upb::RefCounted methods like Ref()/Unref(). */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ Type def_type() const;
+
+ /* "fullname" is the def's fully-qualified name (eg. foo.bar.Message). */
+ const char *full_name() const;
+
+ /* The final part of a def's name (eg. Message). */
+ const char *name() const;
+
+ /* The def must be mutable. Caller retains ownership of fullname. Defs are
+ * not required to have a name; if a def has no name when it is frozen, it
+ * will remain an anonymous def. On failure, returns false and details in "s"
+ * if non-NULL. */
+ bool set_full_name(const char* fullname, upb::Status* s);
+ bool set_full_name(const std::string &fullname, upb::Status* s);
+
+ /* The file in which this def appears. It is not necessary to add a def to a
+ * file (and consequently the accessor may return NULL). Set this by calling
+ * file->Add(def). */
+ FileDef* file() const;
+
+ /* Freezes the given defs; this validates all constraints and marks the defs
+ * as frozen (read-only). "defs" may not contain any fielddefs, but fields
+ * of any msgdefs will be frozen.
+ *
+ * Symbolic references to sub-types and enum defaults must have already been
+ * resolved. Any mutable defs reachable from any of "defs" must also be in
+ * the list; more formally, "defs" must be a transitive closure of mutable
+ * defs.
+ *
+ * After this operation succeeds, the finalized defs must only be accessed
+ * through a const pointer! */
+ static bool Freeze(Def* const* defs, size_t n, Status* status);
+ static bool Freeze(const std::vector<Def*>& defs, Status* status);
+
+ private:
+ UPB_DISALLOW_POD_OPS(Def, upb::Def)
+};
+
+#endif /* __cplusplus */
+
+UPB_BEGIN_EXTERN_C
+
+/* Include upb_refcounted methods like upb_def_ref()/upb_def_unref(). */
+UPB_REFCOUNTED_CMETHODS(upb_def, upb_def_upcast)
+
+upb_deftype_t upb_def_type(const upb_def *d);
+const char *upb_def_fullname(const upb_def *d);
+const char *upb_def_name(const upb_def *d);
+const upb_filedef *upb_def_file(const upb_def *d);
+bool upb_def_setfullname(upb_def *def, const char *fullname, upb_status *s);
+bool upb_def_freeze(upb_def *const *defs, size_t n, upb_status *s);
+
+/* Temporary API: for internal use only. */
+bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s);
+
+UPB_END_EXTERN_C
+
+
+/* upb::Def casts *************************************************************/
+
+#ifdef __cplusplus
+#define UPB_CPP_CASTS(cname, cpptype) \
+ namespace upb { \
+ template <> \
+ inline cpptype *down_cast<cpptype *, Def>(Def * def) { \
+ return upb_downcast_##cname##_mutable(def); \
+ } \
+ template <> \
+ inline cpptype *dyn_cast<cpptype *, Def>(Def * def) { \
+ return upb_dyncast_##cname##_mutable(def); \
+ } \
+ template <> \
+ inline const cpptype *down_cast<const cpptype *, const Def>( \
+ const Def *def) { \
+ return upb_downcast_##cname(def); \
+ } \
+ template <> \
+ inline const cpptype *dyn_cast<const cpptype *, const Def>(const Def *def) { \
+ return upb_dyncast_##cname(def); \
+ } \
+ template <> \
+ inline const cpptype *down_cast<const cpptype *, Def>(Def * def) { \
+ return upb_downcast_##cname(def); \
+ } \
+ template <> \
+ inline const cpptype *dyn_cast<const cpptype *, Def>(Def * def) { \
+ return upb_dyncast_##cname(def); \
+ } \
+ } /* namespace upb */
+#else
+#define UPB_CPP_CASTS(cname, cpptype)
+#endif /* __cplusplus */
+
+/* Dynamic casts, for determining if a def is of a particular type at runtime.
+ * Downcasts, for when some wants to assert that a def is of a particular type.
+ * These are only checked if we are building debug. */
+#define UPB_DEF_CASTS(lower, upper, cpptype) \
+ UPB_INLINE const upb_##lower *upb_dyncast_##lower(const upb_def *def) { \
+ if (upb_def_type(def) != UPB_DEF_##upper) return NULL; \
+ return (upb_##lower *)def; \
+ } \
+ UPB_INLINE const upb_##lower *upb_downcast_##lower(const upb_def *def) { \
+ UPB_ASSERT(upb_def_type(def) == UPB_DEF_##upper); \
+ return (const upb_##lower *)def; \
+ } \
+ UPB_INLINE upb_##lower *upb_dyncast_##lower##_mutable(upb_def *def) { \
+ return (upb_##lower *)upb_dyncast_##lower(def); \
+ } \
+ UPB_INLINE upb_##lower *upb_downcast_##lower##_mutable(upb_def *def) { \
+ return (upb_##lower *)upb_downcast_##lower(def); \
+ } \
+ UPB_CPP_CASTS(lower, cpptype)
+
+#define UPB_DEFINE_DEF(cppname, lower, upper, cppmethods, members) \
+ UPB_DEFINE_CLASS2(cppname, upb::Def, upb::RefCounted, cppmethods, \
+ members) \
+ UPB_DEF_CASTS(lower, upper, cppname)
+
+#define UPB_DECLARE_DEF_TYPE(cppname, lower, upper) \
+ UPB_DECLARE_DERIVED_TYPE2(cppname, upb::Def, upb::RefCounted, \
+ upb_ ## lower, upb_def, upb_refcounted) \
+ UPB_DEF_CASTS(lower, upper, cppname)
+
+UPB_DECLARE_DEF_TYPE(upb::FieldDef, fielddef, FIELD)
+UPB_DECLARE_DEF_TYPE(upb::MessageDef, msgdef, MSG)
+UPB_DECLARE_DEF_TYPE(upb::EnumDef, enumdef, ENUM)
+
+#undef UPB_DECLARE_DEF_TYPE
+#undef UPB_DEF_CASTS
+#undef UPB_CPP_CASTS
+
+
+/* upb::FieldDef **************************************************************/
+
+/* The types a field can have. Note that this list is not identical to the
+ * types defined in descriptor.proto, which gives INT32 and SINT32 separate
+ * types (we distinguish the two with the "integer encoding" enum below). */
+typedef enum {
+ /* Types stored in 1 byte. */
+ UPB_TYPE_BOOL = 1,
+ /* Types stored in 4 bytes. */
+ UPB_TYPE_FLOAT = 2,
+ UPB_TYPE_INT32 = 3,
+ UPB_TYPE_UINT32 = 4,
+ UPB_TYPE_ENUM = 5, /* Enum values are int32. */
+ /* Types stored as pointers (probably 4 or 8 bytes). */
+ UPB_TYPE_STRING = 6,
+ UPB_TYPE_BYTES = 7,
+ UPB_TYPE_MESSAGE = 8,
+ /* Types stored as 8 bytes. */
+ UPB_TYPE_DOUBLE = 9,
+ UPB_TYPE_INT64 = 10,
+ UPB_TYPE_UINT64 = 11
+} upb_fieldtype_t;
+
+/* The repeated-ness of each field; this matches descriptor.proto. */
+typedef enum {
+ UPB_LABEL_OPTIONAL = 1,
+ UPB_LABEL_REQUIRED = 2,
+ UPB_LABEL_REPEATED = 3
+} upb_label_t;
+
+/* How integers should be encoded in serializations that offer multiple
+ * integer encoding methods. */
+typedef enum {
+ UPB_INTFMT_VARIABLE = 1,
+ UPB_INTFMT_FIXED = 2,
+ UPB_INTFMT_ZIGZAG = 3 /* Only for signed types (INT32/INT64). */
+} upb_intfmt_t;
+
+/* Descriptor types, as defined in descriptor.proto. */
+typedef enum {
+ UPB_DESCRIPTOR_TYPE_DOUBLE = 1,
+ UPB_DESCRIPTOR_TYPE_FLOAT = 2,
+ UPB_DESCRIPTOR_TYPE_INT64 = 3,
+ UPB_DESCRIPTOR_TYPE_UINT64 = 4,
+ UPB_DESCRIPTOR_TYPE_INT32 = 5,
+ UPB_DESCRIPTOR_TYPE_FIXED64 = 6,
+ UPB_DESCRIPTOR_TYPE_FIXED32 = 7,
+ UPB_DESCRIPTOR_TYPE_BOOL = 8,
+ UPB_DESCRIPTOR_TYPE_STRING = 9,
+ UPB_DESCRIPTOR_TYPE_GROUP = 10,
+ UPB_DESCRIPTOR_TYPE_MESSAGE = 11,
+ UPB_DESCRIPTOR_TYPE_BYTES = 12,
+ UPB_DESCRIPTOR_TYPE_UINT32 = 13,
+ UPB_DESCRIPTOR_TYPE_ENUM = 14,
+ UPB_DESCRIPTOR_TYPE_SFIXED32 = 15,
+ UPB_DESCRIPTOR_TYPE_SFIXED64 = 16,
+ UPB_DESCRIPTOR_TYPE_SINT32 = 17,
+ UPB_DESCRIPTOR_TYPE_SINT64 = 18
+} upb_descriptortype_t;
+
+typedef enum {
+ UPB_SYNTAX_PROTO2 = 2,
+ UPB_SYNTAX_PROTO3 = 3
+} upb_syntax_t;
+
+/* Maximum field number allowed for FieldDefs. This is an inherent limit of the
+ * protobuf wire format. */
+#define UPB_MAX_FIELDNUMBER ((1 << 29) - 1)
+
+#ifdef __cplusplus
+
+/* A upb_fielddef describes a single field in a message. It is most often
+ * found as a part of a upb_msgdef, but can also stand alone to represent
+ * an extension.
+ *
+ * Its base class is upb::Def (use upb::upcast() to convert). */
+class upb::FieldDef {
+ public:
+ typedef upb_fieldtype_t Type;
+ typedef upb_label_t Label;
+ typedef upb_intfmt_t IntegerFormat;
+ typedef upb_descriptortype_t DescriptorType;
+
+ /* These return true if the given value is a valid member of the enumeration. */
+ static bool CheckType(int32_t val);
+ static bool CheckLabel(int32_t val);
+ static bool CheckDescriptorType(int32_t val);
+ static bool CheckIntegerFormat(int32_t val);
+
+ /* These convert to the given enumeration; they require that the value is
+ * valid. */
+ static Type ConvertType(int32_t val);
+ static Label ConvertLabel(int32_t val);
+ static DescriptorType ConvertDescriptorType(int32_t val);
+ static IntegerFormat ConvertIntegerFormat(int32_t val);
+
+ /* Returns NULL if memory allocation failed. */
+ static reffed_ptr<FieldDef> New();
+
+ /* upb::RefCounted methods like Ref()/Unref(). */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ /* Functionality from upb::Def. */
+ const char* full_name() const;
+
+ bool type_is_set() const; /* set_[descriptor_]type() has been called? */
+ Type type() const; /* Requires that type_is_set() == true. */
+ Label label() const; /* Defaults to UPB_LABEL_OPTIONAL. */
+ const char* name() const; /* NULL if uninitialized. */
+ uint32_t number() const; /* Returns 0 if uninitialized. */
+ bool is_extension() const;
+
+ /* Copies the JSON name for this field into the given buffer. Returns the
+ * actual size of the JSON name, including the NULL terminator. If the
+ * return value is 0, the JSON name is unset. If the return value is
+ * greater than len, the JSON name was truncated. The buffer is always
+ * NULL-terminated if len > 0.
+ *
+ * The JSON name always defaults to a camelCased version of the regular
+ * name. However if the regular name is unset, the JSON name will be unset
+ * also.
+ */
+ size_t GetJsonName(char* buf, size_t len) const;
+
+ /* Convenience version of the above function which copies the JSON name
+ * into the given string, returning false if the name is not set. */
+ template <class T>
+ bool GetJsonName(T* str) {
+ str->resize(GetJsonName(NULL, 0));
+ GetJsonName(&(*str)[0], str->size());
+ return str->size() > 0;
+ }
+
+ /* For UPB_TYPE_MESSAGE fields only where is_tag_delimited() == false,
+ * indicates whether this field should have lazy parsing handlers that yield
+ * the unparsed string for the submessage.
+ *
+ * TODO(haberman): I think we want to move this into a FieldOptions container
+ * when we add support for custom options (the FieldOptions struct will
+ * contain both regular FieldOptions like "lazy" *and* custom options). */
+ bool lazy() const;
+
+ /* For non-string, non-submessage fields, this indicates whether binary
+ * protobufs are encoded in packed or non-packed format.
+ *
+ * TODO(haberman): see note above about putting options like this into a
+ * FieldOptions container. */
+ bool packed() const;
+
+ /* An integer that can be used as an index into an array of fields for
+ * whatever message this field belongs to. Guaranteed to be less than
+ * f->containing_type()->field_count(). May only be accessed once the def has
+ * been finalized. */
+ uint32_t index() const;
+
+ /* The MessageDef to which this field belongs.
+ *
+ * If this field has been added to a MessageDef, that message can be retrieved
+ * directly (this is always the case for frozen FieldDefs).
+ *
+ * If the field has not yet been added to a MessageDef, you can set the name
+ * of the containing type symbolically instead. This is mostly useful for
+ * extensions, where the extension is declared separately from the message. */
+ const MessageDef* containing_type() const;
+ const char* containing_type_name();
+
+ /* The OneofDef to which this field belongs, or NULL if this field is not part
+ * of a oneof. */
+ const OneofDef* containing_oneof() const;
+
+ /* The field's type according to the enum in descriptor.proto. This is not
+ * the same as UPB_TYPE_*, because it distinguishes between (for example)
+ * INT32 and SINT32, whereas our "type" enum does not. This return of
+ * descriptor_type() is a function of type(), integer_format(), and
+ * is_tag_delimited(). Likewise set_descriptor_type() sets all three
+ * appropriately. */
+ DescriptorType descriptor_type() const;
+
+ /* Convenient field type tests. */
+ bool IsSubMessage() const;
+ bool IsString() const;
+ bool IsSequence() const;
+ bool IsPrimitive() const;
+ bool IsMap() const;
+
+ /* Returns whether this field explicitly represents presence.
+ *
+ * For proto2 messages: Returns true for any scalar (non-repeated) field.
+ * For proto3 messages: Returns true for scalar submessage or oneof fields. */
+ bool HasPresence() const;
+
+ /* How integers are encoded. Only meaningful for integer types.
+ * Defaults to UPB_INTFMT_VARIABLE, and is reset when "type" changes. */
+ IntegerFormat integer_format() const;
+
+ /* Whether a submessage field is tag-delimited or not (if false, then
+ * length-delimited). May only be set when type() == UPB_TYPE_MESSAGE. */
+ bool is_tag_delimited() const;
+
+ /* Returns the non-string default value for this fielddef, which may either
+ * be something the client set explicitly or the "default default" (0 for
+ * numbers, empty for strings). The field's type indicates the type of the
+ * returned value, except for enum fields that are still mutable.
+ *
+ * Requires that the given function matches the field's current type. */
+ int64_t default_int64() const;
+ int32_t default_int32() const;
+ uint64_t default_uint64() const;
+ uint32_t default_uint32() const;
+ bool default_bool() const;
+ float default_float() const;
+ double default_double() const;
+
+ /* The resulting string is always NULL-terminated. If non-NULL, the length
+ * will be stored in *len. */
+ const char *default_string(size_t* len) const;
+
+ /* For frozen UPB_TYPE_ENUM fields, enum defaults can always be read as either
+ * string or int32, and both of these methods will always return true.
+ *
+ * For mutable UPB_TYPE_ENUM fields, the story is a bit more complicated.
+ * Enum defaults are unusual. They can be specified either as string or int32,
+ * but to be valid the enum must have that value as a member. And if no
+ * default is specified, the "default default" comes from the EnumDef.
+ *
+ * We allow reading the default as either an int32 or a string, but only if
+ * we have a meaningful value to report. We have a meaningful value if it was
+ * set explicitly, or if we could get the "default default" from the EnumDef.
+ * Also if you explicitly set the name and we find the number in the EnumDef */
+ bool EnumHasStringDefault() const;
+ bool EnumHasInt32Default() const;
+
+ /* Submessage and enum fields must reference a "subdef", which is the
+ * upb::MessageDef or upb::EnumDef that defines their type. Note that when
+ * the FieldDef is mutable it may not have a subdef *yet*, but this function
+ * still returns true to indicate that the field's type requires a subdef. */
+ bool HasSubDef() const;
+
+ /* Returns the enum or submessage def for this field, if any. The field's
+ * type must match (ie. you may only call enum_subdef() for fields where
+ * type() == UPB_TYPE_ENUM). Returns NULL if the subdef has not been set or
+ * is currently set symbolically. */
+ const EnumDef* enum_subdef() const;
+ const MessageDef* message_subdef() const;
+
+ /* Returns the generic subdef for this field. Requires that HasSubDef() (ie.
+ * only works for UPB_TYPE_ENUM and UPB_TYPE_MESSAGE fields). */
+ const Def* subdef() const;
+
+ /* Returns the symbolic name of the subdef. If the subdef is currently set
+ * unresolved (ie. set symbolically) returns the symbolic name. If it has
+ * been resolved to a specific subdef, returns the name from that subdef. */
+ const char* subdef_name() const;
+
+ /* Setters (non-const methods), only valid for mutable FieldDefs! ***********/
+
+ bool set_full_name(const char* fullname, upb::Status* s);
+ bool set_full_name(const std::string& fullname, upb::Status* s);
+
+ /* This may only be called if containing_type() == NULL (ie. the field has not
+ * been added to a message yet). */
+ bool set_containing_type_name(const char *name, Status* status);
+ bool set_containing_type_name(const std::string& name, Status* status);
+
+ /* Defaults to false. When we freeze, we ensure that this can only be true
+ * for length-delimited message fields. Prior to freezing this can be true or
+ * false with no restrictions. */
+ void set_lazy(bool lazy);
+
+ /* Defaults to true. Sets whether this field is encoded in packed format. */
+ void set_packed(bool packed);
+
+ /* "type" or "descriptor_type" MUST be set explicitly before the fielddef is
+ * finalized. These setters require that the enum value is valid; if the
+ * value did not come directly from an enum constant, the caller should
+ * validate it first with the functions above (CheckFieldType(), etc). */
+ void set_type(Type type);
+ void set_label(Label label);
+ void set_descriptor_type(DescriptorType type);
+ void set_is_extension(bool is_extension);
+
+ /* "number" and "name" must be set before the FieldDef is added to a
+ * MessageDef, and may not be set after that.
+ *
+ * "name" is the same as full_name()/set_full_name(), but since fielddefs
+ * most often use simple, non-qualified names, we provide this accessor
+ * also. Generally only extensions will want to think of this name as
+ * fully-qualified. */
+ bool set_number(uint32_t number, upb::Status* s);
+ bool set_name(const char* name, upb::Status* s);
+ bool set_name(const std::string& name, upb::Status* s);
+
+ /* Sets the JSON name to the given string. */
+ /* TODO(haberman): implement. Right now only default json_name (camelCase)
+ * is supported. */
+ bool set_json_name(const char* json_name, upb::Status* s);
+ bool set_json_name(const std::string& name, upb::Status* s);
+
+ /* Clears the JSON name. This will make it revert to its default, which is
+ * a camelCased version of the regular field name. */
+ void clear_json_name();
+
+ void set_integer_format(IntegerFormat format);
+ bool set_tag_delimited(bool tag_delimited, upb::Status* s);
+
+ /* Sets default value for the field. The call must exactly match the type
+ * of the field. Enum fields may use either setint32 or setstring to set
+ * the default numerically or symbolically, respectively, but symbolic
+ * defaults must be resolved before finalizing (see ResolveEnumDefault()).
+ *
+ * Changing the type of a field will reset its default. */
+ void set_default_int64(int64_t val);
+ void set_default_int32(int32_t val);
+ void set_default_uint64(uint64_t val);
+ void set_default_uint32(uint32_t val);
+ void set_default_bool(bool val);
+ void set_default_float(float val);
+ void set_default_double(double val);
+ bool set_default_string(const void *str, size_t len, Status *s);
+ bool set_default_string(const std::string &str, Status *s);
+ void set_default_cstr(const char *str, Status *s);
+
+ /* Before a fielddef is frozen, its subdef may be set either directly (with a
+ * upb::Def*) or symbolically. Symbolic refs must be resolved before the
+ * containing msgdef can be frozen (see upb_resolve() above). upb always
+ * guarantees that any def reachable from a live def will also be kept alive.
+ *
+ * Both methods require that upb_hassubdef(f) (so the type must be set prior
+ * to calling these methods). Returns false if this is not the case, or if
+ * the given subdef is not of the correct type. The subdef is reset if the
+ * field's type is changed. The subdef can be set to NULL to clear it. */
+ bool set_subdef(const Def* subdef, Status* s);
+ bool set_enum_subdef(const EnumDef* subdef, Status* s);
+ bool set_message_subdef(const MessageDef* subdef, Status* s);
+ bool set_subdef_name(const char* name, Status* s);
+ bool set_subdef_name(const std::string &name, Status* s);
+
+ private:
+ UPB_DISALLOW_POD_OPS(FieldDef, upb::FieldDef)
+};
+
+# endif /* defined(__cplusplus) */
+
+UPB_BEGIN_EXTERN_C
+
+/* Native C API. */
+upb_fielddef *upb_fielddef_new(const void *owner);
+
+/* Include upb_refcounted methods like upb_fielddef_ref(). */
+UPB_REFCOUNTED_CMETHODS(upb_fielddef, upb_fielddef_upcast2)
+
+/* Methods from upb_def. */
+const char *upb_fielddef_fullname(const upb_fielddef *f);
+bool upb_fielddef_setfullname(upb_fielddef *f, const char *fullname,
+ upb_status *s);
+
+bool upb_fielddef_typeisset(const upb_fielddef *f);
+upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f);
+upb_descriptortype_t upb_fielddef_descriptortype(const upb_fielddef *f);
+upb_label_t upb_fielddef_label(const upb_fielddef *f);
+uint32_t upb_fielddef_number(const upb_fielddef *f);
+const char *upb_fielddef_name(const upb_fielddef *f);
+bool upb_fielddef_isextension(const upb_fielddef *f);
+bool upb_fielddef_lazy(const upb_fielddef *f);
+bool upb_fielddef_packed(const upb_fielddef *f);
+size_t upb_fielddef_getjsonname(const upb_fielddef *f, char *buf, size_t len);
+const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f);
+const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f);
+upb_msgdef *upb_fielddef_containingtype_mutable(upb_fielddef *f);
+const char *upb_fielddef_containingtypename(upb_fielddef *f);
+upb_intfmt_t upb_fielddef_intfmt(const upb_fielddef *f);
+uint32_t upb_fielddef_index(const upb_fielddef *f);
+bool upb_fielddef_istagdelim(const upb_fielddef *f);
+bool upb_fielddef_issubmsg(const upb_fielddef *f);
+bool upb_fielddef_isstring(const upb_fielddef *f);
+bool upb_fielddef_isseq(const upb_fielddef *f);
+bool upb_fielddef_isprimitive(const upb_fielddef *f);
+bool upb_fielddef_ismap(const upb_fielddef *f);
+bool upb_fielddef_haspresence(const upb_fielddef *f);
+int64_t upb_fielddef_defaultint64(const upb_fielddef *f);
+int32_t upb_fielddef_defaultint32(const upb_fielddef *f);
+uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f);
+uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f);
+bool upb_fielddef_defaultbool(const upb_fielddef *f);
+float upb_fielddef_defaultfloat(const upb_fielddef *f);
+double upb_fielddef_defaultdouble(const upb_fielddef *f);
+const char *upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len);
+bool upb_fielddef_enumhasdefaultint32(const upb_fielddef *f);
+bool upb_fielddef_enumhasdefaultstr(const upb_fielddef *f);
+bool upb_fielddef_hassubdef(const upb_fielddef *f);
+const upb_def *upb_fielddef_subdef(const upb_fielddef *f);
+const upb_msgdef *upb_fielddef_msgsubdef(const upb_fielddef *f);
+const upb_enumdef *upb_fielddef_enumsubdef(const upb_fielddef *f);
+const char *upb_fielddef_subdefname(const upb_fielddef *f);
+
+void upb_fielddef_settype(upb_fielddef *f, upb_fieldtype_t type);
+void upb_fielddef_setdescriptortype(upb_fielddef *f, int type);
+void upb_fielddef_setlabel(upb_fielddef *f, upb_label_t label);
+bool upb_fielddef_setnumber(upb_fielddef *f, uint32_t number, upb_status *s);
+bool upb_fielddef_setname(upb_fielddef *f, const char *name, upb_status *s);
+bool upb_fielddef_setjsonname(upb_fielddef *f, const char *name, upb_status *s);
+bool upb_fielddef_clearjsonname(upb_fielddef *f);
+bool upb_fielddef_setcontainingtypename(upb_fielddef *f, const char *name,
+ upb_status *s);
+void upb_fielddef_setisextension(upb_fielddef *f, bool is_extension);
+void upb_fielddef_setlazy(upb_fielddef *f, bool lazy);
+void upb_fielddef_setpacked(upb_fielddef *f, bool packed);
+void upb_fielddef_setintfmt(upb_fielddef *f, upb_intfmt_t fmt);
+void upb_fielddef_settagdelim(upb_fielddef *f, bool tag_delim);
+void upb_fielddef_setdefaultint64(upb_fielddef *f, int64_t val);
+void upb_fielddef_setdefaultint32(upb_fielddef *f, int32_t val);
+void upb_fielddef_setdefaultuint64(upb_fielddef *f, uint64_t val);
+void upb_fielddef_setdefaultuint32(upb_fielddef *f, uint32_t val);
+void upb_fielddef_setdefaultbool(upb_fielddef *f, bool val);
+void upb_fielddef_setdefaultfloat(upb_fielddef *f, float val);
+void upb_fielddef_setdefaultdouble(upb_fielddef *f, double val);
+bool upb_fielddef_setdefaultstr(upb_fielddef *f, const void *str, size_t len,
+ upb_status *s);
+void upb_fielddef_setdefaultcstr(upb_fielddef *f, const char *str,
+ upb_status *s);
+bool upb_fielddef_setsubdef(upb_fielddef *f, const upb_def *subdef,
+ upb_status *s);
+bool upb_fielddef_setmsgsubdef(upb_fielddef *f, const upb_msgdef *subdef,
+ upb_status *s);
+bool upb_fielddef_setenumsubdef(upb_fielddef *f, const upb_enumdef *subdef,
+ upb_status *s);
+bool upb_fielddef_setsubdefname(upb_fielddef *f, const char *name,
+ upb_status *s);
+
+bool upb_fielddef_checklabel(int32_t label);
+bool upb_fielddef_checktype(int32_t type);
+bool upb_fielddef_checkdescriptortype(int32_t type);
+bool upb_fielddef_checkintfmt(int32_t fmt);
+
+UPB_END_EXTERN_C
+
+
+/* upb::MessageDef ************************************************************/
+
+typedef upb_inttable_iter upb_msg_field_iter;
+typedef upb_strtable_iter upb_msg_oneof_iter;
+
+/* Well-known field tag numbers for map-entry messages. */
+#define UPB_MAPENTRY_KEY 1
+#define UPB_MAPENTRY_VALUE 2
+
+#ifdef __cplusplus
+
+/* Structure that describes a single .proto message type.
+ *
+ * Its base class is upb::Def (use upb::upcast() to convert). */
+class upb::MessageDef {
+ public:
+ /* Returns NULL if memory allocation failed. */
+ static reffed_ptr<MessageDef> New();
+
+ /* upb::RefCounted methods like Ref()/Unref(). */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ /* Functionality from upb::Def. */
+ const char* full_name() const;
+ const char* name() const;
+ bool set_full_name(const char* fullname, Status* s);
+ bool set_full_name(const std::string& fullname, Status* s);
+
+ /* Call to freeze this MessageDef.
+ * WARNING: this will fail if this message has any unfrozen submessages!
+ * Messages with cycles must be frozen as a batch using upb::Def::Freeze(). */
+ bool Freeze(Status* s);
+
+ /* The number of fields that belong to the MessageDef. */
+ int field_count() const;
+
+ /* The number of oneofs that belong to the MessageDef. */
+ int oneof_count() const;
+
+ /* Adds a field (upb_fielddef object) to a msgdef. Requires that the msgdef
+ * and the fielddefs are mutable. The fielddef's name and number must be
+ * set, and the message may not already contain any field with this name or
+ * number, and this fielddef may not be part of another message. In error
+ * cases false is returned and the msgdef is unchanged.
+ *
+ * If the given field is part of a oneof, this call succeeds if and only if
+ * that oneof is already part of this msgdef. (Note that adding a oneof to a
+ * msgdef automatically adds all of its fields to the msgdef at the time that
+ * the oneof is added, so it is usually more idiomatic to add the oneof's
+ * fields first then add the oneof to the msgdef. This case is supported for
+ * convenience.)
+ *
+ * If |f| is already part of this MessageDef, this method performs no action
+ * and returns true (success). Thus, this method is idempotent. */
+ bool AddField(FieldDef* f, Status* s);
+ bool AddField(const reffed_ptr<FieldDef>& f, Status* s);
+
+ /* Adds a oneof (upb_oneofdef object) to a msgdef. Requires that the msgdef,
+ * oneof, and any fielddefs are mutable, that the fielddefs contained in the
+ * oneof do not have any name or number conflicts with existing fields in the
+ * msgdef, and that the oneof's name is unique among all oneofs in the msgdef.
+ * If the oneof is added successfully, all of its fields will be added
+ * directly to the msgdef as well. In error cases, false is returned and the
+ * msgdef is unchanged. */
+ bool AddOneof(OneofDef* o, Status* s);
+ bool AddOneof(const reffed_ptr<OneofDef>& o, Status* s);
+
+ upb_syntax_t syntax() const;
+
+ /* Returns false if we don't support this syntax value. */
+ bool set_syntax(upb_syntax_t syntax);
+
+ /* Set this to false to indicate that primitive fields should not have
+ * explicit presence information associated with them. This will affect all
+ * fields added to this message. Defaults to true. */
+ void SetPrimitivesHavePresence(bool have_presence);
+
+ /* These return NULL if the field is not found. */
+ FieldDef* FindFieldByNumber(uint32_t number);
+ FieldDef* FindFieldByName(const char *name, size_t len);
+ const FieldDef* FindFieldByNumber(uint32_t number) const;
+ const FieldDef* FindFieldByName(const char* name, size_t len) const;
+
+
+ FieldDef* FindFieldByName(const char *name) {
+ return FindFieldByName(name, strlen(name));
+ }
+ const FieldDef* FindFieldByName(const char *name) const {
+ return FindFieldByName(name, strlen(name));
+ }
+
+ template <class T>
+ FieldDef* FindFieldByName(const T& str) {
+ return FindFieldByName(str.c_str(), str.size());
+ }
+ template <class T>
+ const FieldDef* FindFieldByName(const T& str) const {
+ return FindFieldByName(str.c_str(), str.size());
+ }
+
+ OneofDef* FindOneofByName(const char* name, size_t len);
+ const OneofDef* FindOneofByName(const char* name, size_t len) const;
+
+ OneofDef* FindOneofByName(const char* name) {
+ return FindOneofByName(name, strlen(name));
+ }
+ const OneofDef* FindOneofByName(const char* name) const {
+ return FindOneofByName(name, strlen(name));
+ }
+
+ template<class T>
+ OneofDef* FindOneofByName(const T& str) {
+ return FindOneofByName(str.c_str(), str.size());
+ }
+ template<class T>
+ const OneofDef* FindOneofByName(const T& str) const {
+ return FindOneofByName(str.c_str(), str.size());
+ }
+
+ /* Is this message a map entry? */
+ void setmapentry(bool map_entry);
+ bool mapentry() const;
+
+ /* Iteration over fields. The order is undefined. */
+ class field_iterator
+ : public std::iterator<std::forward_iterator_tag, FieldDef*> {
+ public:
+ explicit field_iterator(MessageDef* md);
+ static field_iterator end(MessageDef* md);
+
+ void operator++();
+ FieldDef* operator*() const;
+ bool operator!=(const field_iterator& other) const;
+ bool operator==(const field_iterator& other) const;
+
+ private:
+ upb_msg_field_iter iter_;
+ };
+
+ class const_field_iterator
+ : public std::iterator<std::forward_iterator_tag, const FieldDef*> {
+ public:
+ explicit const_field_iterator(const MessageDef* md);
+ static const_field_iterator end(const MessageDef* md);
+
+ void operator++();
+ const FieldDef* operator*() const;
+ bool operator!=(const const_field_iterator& other) const;
+ bool operator==(const const_field_iterator& other) const;
+
+ private:
+ upb_msg_field_iter iter_;
+ };
+
+ /* Iteration over oneofs. The order is undefined. */
+ class oneof_iterator
+ : public std::iterator<std::forward_iterator_tag, FieldDef*> {
+ public:
+ explicit oneof_iterator(MessageDef* md);
+ static oneof_iterator end(MessageDef* md);
+
+ void operator++();
+ OneofDef* operator*() const;
+ bool operator!=(const oneof_iterator& other) const;
+ bool operator==(const oneof_iterator& other) const;
+
+ private:
+ upb_msg_oneof_iter iter_;
+ };
+
+ class const_oneof_iterator
+ : public std::iterator<std::forward_iterator_tag, const FieldDef*> {
+ public:
+ explicit const_oneof_iterator(const MessageDef* md);
+ static const_oneof_iterator end(const MessageDef* md);
+
+ void operator++();
+ const OneofDef* operator*() const;
+ bool operator!=(const const_oneof_iterator& other) const;
+ bool operator==(const const_oneof_iterator& other) const;
+
+ private:
+ upb_msg_oneof_iter iter_;
+ };
+
+ class FieldAccessor {
+ public:
+ explicit FieldAccessor(MessageDef* msg) : msg_(msg) {}
+ field_iterator begin() { return msg_->field_begin(); }
+ field_iterator end() { return msg_->field_end(); }
+ private:
+ MessageDef* msg_;
+ };
+
+ class ConstFieldAccessor {
+ public:
+ explicit ConstFieldAccessor(const MessageDef* msg) : msg_(msg) {}
+ const_field_iterator begin() { return msg_->field_begin(); }
+ const_field_iterator end() { return msg_->field_end(); }
+ private:
+ const MessageDef* msg_;
+ };
+
+ class OneofAccessor {
+ public:
+ explicit OneofAccessor(MessageDef* msg) : msg_(msg) {}
+ oneof_iterator begin() { return msg_->oneof_begin(); }
+ oneof_iterator end() { return msg_->oneof_end(); }
+ private:
+ MessageDef* msg_;
+ };
+
+ class ConstOneofAccessor {
+ public:
+ explicit ConstOneofAccessor(const MessageDef* msg) : msg_(msg) {}
+ const_oneof_iterator begin() { return msg_->oneof_begin(); }
+ const_oneof_iterator end() { return msg_->oneof_end(); }
+ private:
+ const MessageDef* msg_;
+ };
+
+ field_iterator field_begin();
+ field_iterator field_end();
+ const_field_iterator field_begin() const;
+ const_field_iterator field_end() const;
+
+ oneof_iterator oneof_begin();
+ oneof_iterator oneof_end();
+ const_oneof_iterator oneof_begin() const;
+ const_oneof_iterator oneof_end() const;
+
+ FieldAccessor fields() { return FieldAccessor(this); }
+ ConstFieldAccessor fields() const { return ConstFieldAccessor(this); }
+ OneofAccessor oneofs() { return OneofAccessor(this); }
+ ConstOneofAccessor oneofs() const { return ConstOneofAccessor(this); }
+
+ private:
+ UPB_DISALLOW_POD_OPS(MessageDef, upb::MessageDef)
+};
+
+#endif /* __cplusplus */
+
+UPB_BEGIN_EXTERN_C
+
+/* Returns NULL if memory allocation failed. */
+upb_msgdef *upb_msgdef_new(const void *owner);
+
+/* Include upb_refcounted methods like upb_msgdef_ref(). */
+UPB_REFCOUNTED_CMETHODS(upb_msgdef, upb_msgdef_upcast2)
+
+bool upb_msgdef_freeze(upb_msgdef *m, upb_status *status);
+
+const char *upb_msgdef_fullname(const upb_msgdef *m);
+const char *upb_msgdef_name(const upb_msgdef *m);
+int upb_msgdef_numoneofs(const upb_msgdef *m);
+upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m);
+
+bool upb_msgdef_addfield(upb_msgdef *m, upb_fielddef *f, const void *ref_donor,
+ upb_status *s);
+bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor,
+ upb_status *s);
+bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname, upb_status *s);
+void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry);
+bool upb_msgdef_mapentry(const upb_msgdef *m);
+bool upb_msgdef_setsyntax(upb_msgdef *m, upb_syntax_t syntax);
+
+/* Field lookup in a couple of different variations:
+ * - itof = int to field
+ * - ntof = name to field
+ * - ntofz = name to field, null-terminated string. */
+const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i);
+const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name,
+ size_t len);
+int upb_msgdef_numfields(const upb_msgdef *m);
+
+UPB_INLINE const upb_fielddef *upb_msgdef_ntofz(const upb_msgdef *m,
+ const char *name) {
+ return upb_msgdef_ntof(m, name, strlen(name));
+}
+
+UPB_INLINE upb_fielddef *upb_msgdef_itof_mutable(upb_msgdef *m, uint32_t i) {
+ return (upb_fielddef*)upb_msgdef_itof(m, i);
+}
+
+UPB_INLINE upb_fielddef *upb_msgdef_ntof_mutable(upb_msgdef *m,
+ const char *name, size_t len) {
+ return (upb_fielddef *)upb_msgdef_ntof(m, name, len);
+}
+
+/* Oneof lookup:
+ * - ntoo = name to oneof
+ * - ntooz = name to oneof, null-terminated string. */
+const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name,
+ size_t len);
+int upb_msgdef_numoneofs(const upb_msgdef *m);
+
+UPB_INLINE const upb_oneofdef *upb_msgdef_ntooz(const upb_msgdef *m,
+ const char *name) {
+ return upb_msgdef_ntoo(m, name, strlen(name));
+}
+
+UPB_INLINE upb_oneofdef *upb_msgdef_ntoo_mutable(upb_msgdef *m,
+ const char *name, size_t len) {
+ return (upb_oneofdef *)upb_msgdef_ntoo(m, name, len);
+}
+
+/* Lookup of either field or oneof by name. Returns whether either was found.
+ * If the return is true, then the found def will be set, and the non-found
+ * one set to NULL. */
+bool upb_msgdef_lookupname(const upb_msgdef *m, const char *name, size_t len,
+ const upb_fielddef **f, const upb_oneofdef **o);
+
+UPB_INLINE bool upb_msgdef_lookupnamez(const upb_msgdef *m, const char *name,
+ const upb_fielddef **f,
+ const upb_oneofdef **o) {
+ return upb_msgdef_lookupname(m, name, strlen(name), f, o);
+}
+
+/* Iteration over fields and oneofs. For example:
+ *
+ * upb_msg_field_iter i;
+ * for(upb_msg_field_begin(&i, m);
+ * !upb_msg_field_done(&i);
+ * upb_msg_field_next(&i)) {
+ * upb_fielddef *f = upb_msg_iter_field(&i);
+ * // ...
+ * }
+ *
+ * For C we don't have separate iterators for const and non-const.
+ * It is the caller's responsibility to cast the upb_fielddef* to
+ * const if the upb_msgdef* is const. */
+void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m);
+void upb_msg_field_next(upb_msg_field_iter *iter);
+bool upb_msg_field_done(const upb_msg_field_iter *iter);
+upb_fielddef *upb_msg_iter_field(const upb_msg_field_iter *iter);
+void upb_msg_field_iter_setdone(upb_msg_field_iter *iter);
+
+/* Similar to above, we also support iterating through the oneofs in a
+ * msgdef. */
+void upb_msg_oneof_begin(upb_msg_oneof_iter *iter, const upb_msgdef *m);
+void upb_msg_oneof_next(upb_msg_oneof_iter *iter);
+bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter);
+upb_oneofdef *upb_msg_iter_oneof(const upb_msg_oneof_iter *iter);
+void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter *iter);
+
+UPB_END_EXTERN_C
+
+
+/* upb::EnumDef ***************************************************************/
+
+typedef upb_strtable_iter upb_enum_iter;
+
+#ifdef __cplusplus
+
+/* Class that represents an enum. Its base class is upb::Def (convert with
+ * upb::upcast()). */
+class upb::EnumDef {
+ public:
+ /* Returns NULL if memory allocation failed. */
+ static reffed_ptr<EnumDef> New();
+
+ /* upb::RefCounted methods like Ref()/Unref(). */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ /* Functionality from upb::Def. */
+ const char* full_name() const;
+ const char* name() const;
+ bool set_full_name(const char* fullname, Status* s);
+ bool set_full_name(const std::string& fullname, Status* s);
+
+ /* Call to freeze this EnumDef. */
+ bool Freeze(Status* s);
+
+ /* The value that is used as the default when no field default is specified.
+ * If not set explicitly, the first value that was added will be used.
+ * The default value must be a member of the enum.
+ * Requires that value_count() > 0. */
+ int32_t default_value() const;
+
+ /* Sets the default value. If this value is not valid, returns false and an
+ * error message in status. */
+ bool set_default_value(int32_t val, Status* status);
+
+ /* Returns the number of values currently defined in the enum. Note that
+ * multiple names can refer to the same number, so this may be greater than
+ * the total number of unique numbers. */
+ int value_count() const;
+
+ /* Adds a single name/number pair to the enum. Fails if this name has
+ * already been used by another value. */
+ bool AddValue(const char* name, int32_t num, Status* status);
+ bool AddValue(const std::string& name, int32_t num, Status* status);
+
+ /* Lookups from name to integer, returning true if found. */
+ bool FindValueByName(const char* name, int32_t* num) const;
+
+ /* Finds the name corresponding to the given number, or NULL if none was
+ * found. If more than one name corresponds to this number, returns the
+ * first one that was added. */
+ const char* FindValueByNumber(int32_t num) const;
+
+ /* Iteration over name/value pairs. The order is undefined.
+ * Adding an enum val invalidates any iterators.
+ *
+ * TODO: make compatible with range-for, with elements as pairs? */
+ class Iterator {
+ public:
+ explicit Iterator(const EnumDef*);
+
+ int32_t number();
+ const char *name();
+ bool Done();
+ void Next();
+
+ private:
+ upb_enum_iter iter_;
+ };
+
+ private:
+ UPB_DISALLOW_POD_OPS(EnumDef, upb::EnumDef)
+};
+
+#endif /* __cplusplus */
+
+UPB_BEGIN_EXTERN_C
+
+/* Native C API. */
+upb_enumdef *upb_enumdef_new(const void *owner);
+
+/* Include upb_refcounted methods like upb_enumdef_ref(). */
+UPB_REFCOUNTED_CMETHODS(upb_enumdef, upb_enumdef_upcast2)
+
+bool upb_enumdef_freeze(upb_enumdef *e, upb_status *status);
+
+/* From upb_def. */
+const char *upb_enumdef_fullname(const upb_enumdef *e);
+const char *upb_enumdef_name(const upb_enumdef *e);
+bool upb_enumdef_setfullname(upb_enumdef *e, const char *fullname,
+ upb_status *s);
+
+int32_t upb_enumdef_default(const upb_enumdef *e);
+bool upb_enumdef_setdefault(upb_enumdef *e, int32_t val, upb_status *s);
+int upb_enumdef_numvals(const upb_enumdef *e);
+bool upb_enumdef_addval(upb_enumdef *e, const char *name, int32_t num,
+ upb_status *status);
+
+/* Enum lookups:
+ * - ntoi: look up a name with specified length.
+ * - ntoiz: look up a name provided as a null-terminated string.
+ * - iton: look up an integer, returning the name as a null-terminated
+ * string. */
+bool upb_enumdef_ntoi(const upb_enumdef *e, const char *name, size_t len,
+ int32_t *num);
+UPB_INLINE bool upb_enumdef_ntoiz(const upb_enumdef *e,
+ const char *name, int32_t *num) {
+ return upb_enumdef_ntoi(e, name, strlen(name), num);
+}
+const char *upb_enumdef_iton(const upb_enumdef *e, int32_t num);
+
+/* upb_enum_iter i;
+ * for(upb_enum_begin(&i, e); !upb_enum_done(&i); upb_enum_next(&i)) {
+ * // ...
+ * }
+ */
+void upb_enum_begin(upb_enum_iter *iter, const upb_enumdef *e);
+void upb_enum_next(upb_enum_iter *iter);
+bool upb_enum_done(upb_enum_iter *iter);
+const char *upb_enum_iter_name(upb_enum_iter *iter);
+int32_t upb_enum_iter_number(upb_enum_iter *iter);
+
+UPB_END_EXTERN_C
+
+
+/* upb::OneofDef **************************************************************/
+
+typedef upb_inttable_iter upb_oneof_iter;
+
+#ifdef __cplusplus
+
+/* Class that represents a oneof. */
+class upb::OneofDef {
+ public:
+ /* Returns NULL if memory allocation failed. */
+ static reffed_ptr<OneofDef> New();
+
+ /* upb::RefCounted methods like Ref()/Unref(). */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ /* Returns the MessageDef that owns this OneofDef. */
+ const MessageDef* containing_type() const;
+
+ /* Returns the name of this oneof. This is the name used to look up the oneof
+ * by name once added to a message def. */
+ const char* name() const;
+ bool set_name(const char* name, Status* s);
+ bool set_name(const std::string& name, Status* s);
+
+ /* Returns the number of fields currently defined in the oneof. */
+ int field_count() const;
+
+ /* Adds a field to the oneof. The field must not have been added to any other
+ * oneof or msgdef. If the oneof is not yet part of a msgdef, then when the
+ * oneof is eventually added to a msgdef, all fields added to the oneof will
+ * also be added to the msgdef at that time. If the oneof is already part of a
+ * msgdef, the field must either be a part of that msgdef already, or must not
+ * be a part of any msgdef; in the latter case, the field is added to the
+ * msgdef as a part of this operation.
+ *
+ * The field may only have an OPTIONAL label, never REQUIRED or REPEATED.
+ *
+ * If |f| is already part of this MessageDef, this method performs no action
+ * and returns true (success). Thus, this method is idempotent. */
+ bool AddField(FieldDef* field, Status* s);
+ bool AddField(const reffed_ptr<FieldDef>& field, Status* s);
+
+ /* Looks up by name. */
+ const FieldDef* FindFieldByName(const char* name, size_t len) const;
+ FieldDef* FindFieldByName(const char* name, size_t len);
+ const FieldDef* FindFieldByName(const char* name) const {
+ return FindFieldByName(name, strlen(name));
+ }
+ FieldDef* FindFieldByName(const char* name) {
+ return FindFieldByName(name, strlen(name));
+ }
+
+ template <class T>
+ FieldDef* FindFieldByName(const T& str) {
+ return FindFieldByName(str.c_str(), str.size());
+ }
+ template <class T>
+ const FieldDef* FindFieldByName(const T& str) const {
+ return FindFieldByName(str.c_str(), str.size());
+ }
+
+ /* Looks up by tag number. */
+ const FieldDef* FindFieldByNumber(uint32_t num) const;
+
+ /* Iteration over fields. The order is undefined. */
+ class iterator : public std::iterator<std::forward_iterator_tag, FieldDef*> {
+ public:
+ explicit iterator(OneofDef* md);
+ static iterator end(OneofDef* md);
+
+ void operator++();
+ FieldDef* operator*() const;
+ bool operator!=(const iterator& other) const;
+ bool operator==(const iterator& other) const;
+
+ private:
+ upb_oneof_iter iter_;
+ };
+
+ class const_iterator
+ : public std::iterator<std::forward_iterator_tag, const FieldDef*> {
+ public:
+ explicit const_iterator(const OneofDef* md);
+ static const_iterator end(const OneofDef* md);
+
+ void operator++();
+ const FieldDef* operator*() const;
+ bool operator!=(const const_iterator& other) const;
+ bool operator==(const const_iterator& other) const;
+
+ private:
+ upb_oneof_iter iter_;
+ };
+
+ iterator begin();
+ iterator end();
+ const_iterator begin() const;
+ const_iterator end() const;
+
+ private:
+ UPB_DISALLOW_POD_OPS(OneofDef, upb::OneofDef)
+};
+
+#endif /* __cplusplus */
+
+UPB_BEGIN_EXTERN_C
+
+/* Native C API. */
+upb_oneofdef *upb_oneofdef_new(const void *owner);
+
+/* Include upb_refcounted methods like upb_oneofdef_ref(). */
+UPB_REFCOUNTED_CMETHODS(upb_oneofdef, upb_oneofdef_upcast)
+
+const char *upb_oneofdef_name(const upb_oneofdef *o);
+const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o);
+int upb_oneofdef_numfields(const upb_oneofdef *o);
+uint32_t upb_oneofdef_index(const upb_oneofdef *o);
+
+bool upb_oneofdef_setname(upb_oneofdef *o, const char *name, upb_status *s);
+bool upb_oneofdef_addfield(upb_oneofdef *o, upb_fielddef *f,
+ const void *ref_donor,
+ upb_status *s);
+
+/* Oneof lookups:
+ * - ntof: look up a field by name.
+ * - ntofz: look up a field by name (as a null-terminated string).
+ * - itof: look up a field by number. */
+const upb_fielddef *upb_oneofdef_ntof(const upb_oneofdef *o,
+ const char *name, size_t length);
+UPB_INLINE const upb_fielddef *upb_oneofdef_ntofz(const upb_oneofdef *o,
+ const char *name) {
+ return upb_oneofdef_ntof(o, name, strlen(name));
+}
+const upb_fielddef *upb_oneofdef_itof(const upb_oneofdef *o, uint32_t num);
+
+/* upb_oneof_iter i;
+ * for(upb_oneof_begin(&i, e); !upb_oneof_done(&i); upb_oneof_next(&i)) {
+ * // ...
+ * }
+ */
+void upb_oneof_begin(upb_oneof_iter *iter, const upb_oneofdef *o);
+void upb_oneof_next(upb_oneof_iter *iter);
+bool upb_oneof_done(upb_oneof_iter *iter);
+upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter);
+void upb_oneof_iter_setdone(upb_oneof_iter *iter);
+
+UPB_END_EXTERN_C
+
+
+/* upb::FileDef ***************************************************************/
+
+#ifdef __cplusplus
+
+/* Class that represents a .proto file with some things defined in it.
+ *
+ * Many users won't care about FileDefs, but they are necessary if you want to
+ * read the values of file-level options. */
+class upb::FileDef {
+ public:
+ /* Returns NULL if memory allocation failed. */
+ static reffed_ptr<FileDef> New();
+
+ /* upb::RefCounted methods like Ref()/Unref(). */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ /* Get/set name of the file (eg. "foo/bar.proto"). */
+ const char* name() const;
+ bool set_name(const char* name, Status* s);
+ bool set_name(const std::string& name, Status* s);
+
+ /* Package name for definitions inside the file (eg. "foo.bar"). */
+ const char* package() const;
+ bool set_package(const char* package, Status* s);
+
+ /* Syntax for the file. Defaults to proto2. */
+ upb_syntax_t syntax() const;
+ void set_syntax(upb_syntax_t syntax);
+
+ /* Get the list of defs from the file. These are returned in the order that
+ * they were added to the FileDef. */
+ int def_count() const;
+ const Def* def(int index) const;
+ Def* def(int index);
+
+ /* Get the list of dependencies from the file. These are returned in the
+ * order that they were added to the FileDef. */
+ int dependency_count() const;
+ const FileDef* dependency(int index) const;
+
+ /* Adds defs to this file. The def must not already belong to another
+ * file.
+ *
+ * Note: this does *not* ensure that this def's name is unique in this file!
+ * Use a SymbolTable if you want to check this property. Especially since
+ * properly checking uniqueness would require a check across *all* files
+ * (including dependencies). */
+ bool AddDef(Def* def, Status* s);
+ bool AddMessage(MessageDef* m, Status* s);
+ bool AddEnum(EnumDef* e, Status* s);
+ bool AddExtension(FieldDef* f, Status* s);
+
+ /* Adds a dependency of this file. */
+ bool AddDependency(const FileDef* file);
+
+ /* Freezes this FileDef and all messages/enums under it. All subdefs must be
+ * resolved and all messages/enums must validate. Returns true if this
+ * succeeded.
+ *
+ * TODO(haberman): should we care whether the file's dependencies are frozen
+ * already? */
+ bool Freeze(Status* s);
+
+ private:
+ UPB_DISALLOW_POD_OPS(FileDef, upb::FileDef)
+};
+
+#endif
+
+UPB_BEGIN_EXTERN_C
+
+upb_filedef *upb_filedef_new(const void *owner);
+
+/* Include upb_refcounted methods like upb_msgdef_ref(). */
+UPB_REFCOUNTED_CMETHODS(upb_filedef, upb_filedef_upcast)
+
+const char *upb_filedef_name(const upb_filedef *f);
+const char *upb_filedef_package(const upb_filedef *f);
+upb_syntax_t upb_filedef_syntax(const upb_filedef *f);
+size_t upb_filedef_defcount(const upb_filedef *f);
+size_t upb_filedef_depcount(const upb_filedef *f);
+const upb_def *upb_filedef_def(const upb_filedef *f, size_t i);
+const upb_filedef *upb_filedef_dep(const upb_filedef *f, size_t i);
+
+bool upb_filedef_freeze(upb_filedef *f, upb_status *s);
+bool upb_filedef_setname(upb_filedef *f, const char *name, upb_status *s);
+bool upb_filedef_setpackage(upb_filedef *f, const char *package, upb_status *s);
+bool upb_filedef_setsyntax(upb_filedef *f, upb_syntax_t syntax, upb_status *s);
+
+bool upb_filedef_adddef(upb_filedef *f, upb_def *def, const void *ref_donor,
+ upb_status *s);
+bool upb_filedef_adddep(upb_filedef *f, const upb_filedef *dep);
+
+UPB_INLINE bool upb_filedef_addmsg(upb_filedef *f, upb_msgdef *m,
+ const void *ref_donor, upb_status *s) {
+ return upb_filedef_adddef(f, upb_msgdef_upcast_mutable(m), ref_donor, s);
+}
+
+UPB_INLINE bool upb_filedef_addenum(upb_filedef *f, upb_enumdef *e,
+ const void *ref_donor, upb_status *s) {
+ return upb_filedef_adddef(f, upb_enumdef_upcast_mutable(e), ref_donor, s);
+}
+
+UPB_INLINE bool upb_filedef_addext(upb_filedef *file, upb_fielddef *f,
+ const void *ref_donor, upb_status *s) {
+ return upb_filedef_adddef(file, upb_fielddef_upcast_mutable(f), ref_donor, s);
+}
+UPB_INLINE upb_def *upb_filedef_mutabledef(upb_filedef *f, int i) {
+ return (upb_def*)upb_filedef_def(f, i);
+}
+
+UPB_END_EXTERN_C
+
+typedef struct {
+ UPB_PRIVATE_FOR_CPP
+ upb_strtable_iter iter;
+ upb_deftype_t type;
+} upb_symtab_iter;
+
+#ifdef __cplusplus
+
+/* Non-const methods in upb::SymbolTable are NOT thread-safe. */
+class upb::SymbolTable {
+ public:
+ /* Returns a new symbol table with a single ref owned by "owner."
+ * Returns NULL if memory allocation failed. */
+ static SymbolTable* New();
+ static void Free(upb::SymbolTable* table);
+
+ /* For all lookup functions, the returned pointer is not owned by the
+ * caller; it may be invalidated by any non-const call or unref of the
+ * SymbolTable! To protect against this, take a ref if desired. */
+
+ /* Freezes the symbol table: prevents further modification of it.
+ * After the Freeze() operation is successful, the SymbolTable must only be
+ * accessed via a const pointer.
+ *
+ * Unlike with upb::MessageDef/upb::EnumDef/etc, freezing a SymbolTable is not
+ * a necessary step in using a SymbolTable. If you have no need for it to be
+ * immutable, there is no need to freeze it ever. However sometimes it is
+ * useful, and SymbolTables that are statically compiled into the binary are
+ * always frozen by nature. */
+ void Freeze();
+
+ /* Resolves the given symbol using the rules described in descriptor.proto,
+ * namely:
+ *
+ * If the name starts with a '.', it is fully-qualified. Otherwise,
+ * C++-like scoping rules are used to find the type (i.e. first the nested
+ * types within this message are searched, then within the parent, on up
+ * to the root namespace).
+ *
+ * If not found, returns NULL. */
+ const Def* Resolve(const char* base, const char* sym) const;
+
+ /* Finds an entry in the symbol table with this exact name. If not found,
+ * returns NULL. */
+ const Def* Lookup(const char *sym) const;
+ const MessageDef* LookupMessage(const char *sym) const;
+ const EnumDef* LookupEnum(const char *sym) const;
+
+ /* TODO: introduce a C++ iterator, but make it nice and templated so that if
+ * you ask for an iterator of MessageDef the iterated elements are strongly
+ * typed as MessageDef*. */
+
+ /* Adds the given mutable defs to the symtab, resolving all symbols (including
+ * enum default values) and finalizing the defs. Only one def per name may be
+ * in the list, and the defs may not duplicate any name already in the symtab.
+ * All defs must have a name -- anonymous defs are not allowed. Anonymous
+ * defs can still be frozen by calling upb_def_freeze() directly.
+ *
+ * The entire operation either succeeds or fails. If the operation fails,
+ * the symtab is unchanged, false is returned, and status indicates the
+ * error. The caller passes a ref on all defs to the symtab (even if the
+ * operation fails).
+ *
+ * TODO(haberman): currently failure will leave the symtab unchanged, but may
+ * leave the defs themselves partially resolved. Does this matter? If so we
+ * could do a prepass that ensures that all symbols are resolvable and bail
+ * if not, so we don't mutate anything until we know the operation will
+ * succeed. */
+ bool Add(Def*const* defs, size_t n, void* ref_donor, Status* status);
+
+ bool Add(const std::vector<Def*>& defs, void *owner, Status* status) {
+ return Add((Def*const*)&defs[0], defs.size(), owner, status);
+ }
+
+ /* Resolves all subdefs for messages in this file and attempts to freeze the
+ * file. If this succeeds, adds all the symbols to this SymbolTable
+ * (replacing any existing ones with the same names). */
+ bool AddFile(FileDef* file, Status* s);
+
+ private:
+ UPB_DISALLOW_POD_OPS(SymbolTable, upb::SymbolTable)
+};
+
+#endif /* __cplusplus */
+
+UPB_BEGIN_EXTERN_C
+
+/* Native C API. */
+
+upb_symtab *upb_symtab_new();
+void upb_symtab_free(upb_symtab* s);
+const upb_def *upb_symtab_resolve(const upb_symtab *s, const char *base,
+ const char *sym);
+const upb_def *upb_symtab_lookup(const upb_symtab *s, const char *sym);
+const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym);
+const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym);
+bool upb_symtab_add(upb_symtab *s, upb_def *const*defs, size_t n,
+ void *ref_donor, upb_status *status);
+bool upb_symtab_addfile(upb_symtab *s, upb_filedef *file, upb_status* status);
+
+/* upb_symtab_iter i;
+ * for(upb_symtab_begin(&i, s, type); !upb_symtab_done(&i);
+ * upb_symtab_next(&i)) {
+ * const upb_def *def = upb_symtab_iter_def(&i);
+ * // ...
+ * }
+ *
+ * For C we don't have separate iterators for const and non-const.
+ * It is the caller's responsibility to cast the upb_fielddef* to
+ * const if the upb_msgdef* is const. */
+void upb_symtab_begin(upb_symtab_iter *iter, const upb_symtab *s,
+ upb_deftype_t type);
+void upb_symtab_next(upb_symtab_iter *iter);
+bool upb_symtab_done(const upb_symtab_iter *iter);
+const upb_def *upb_symtab_iter_def(const upb_symtab_iter *iter);
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+/* C++ inline wrappers. */
+namespace upb {
+inline SymbolTable* SymbolTable::New() {
+ return upb_symtab_new();
+}
+inline void SymbolTable::Free(SymbolTable* s) {
+ upb_symtab_free(s);
+}
+inline const Def *SymbolTable::Resolve(const char *base,
+ const char *sym) const {
+ return upb_symtab_resolve(this, base, sym);
+}
+inline const Def* SymbolTable::Lookup(const char *sym) const {
+ return upb_symtab_lookup(this, sym);
+}
+inline const MessageDef *SymbolTable::LookupMessage(const char *sym) const {
+ return upb_symtab_lookupmsg(this, sym);
+}
+inline bool SymbolTable::Add(
+ Def*const* defs, size_t n, void* ref_donor, Status* status) {
+ return upb_symtab_add(this, (upb_def*const*)defs, n, ref_donor, status);
+}
+inline bool SymbolTable::AddFile(FileDef* file, Status* s) {
+ return upb_symtab_addfile(this, file, s);
+}
+} /* namespace upb */
+#endif
+
+#ifdef __cplusplus
+
+UPB_INLINE const char* upb_safecstr(const std::string& str) {
+ UPB_ASSERT(str.size() == std::strlen(str.c_str()));
+ return str.c_str();
+}
+
+/* Inline C++ wrappers. */
+namespace upb {
+
+inline Def::Type Def::def_type() const { return upb_def_type(this); }
+inline const char* Def::full_name() const { return upb_def_fullname(this); }
+inline const char* Def::name() const { return upb_def_name(this); }
+inline bool Def::set_full_name(const char* fullname, Status* s) {
+ return upb_def_setfullname(this, fullname, s);
+}
+inline bool Def::set_full_name(const std::string& fullname, Status* s) {
+ return upb_def_setfullname(this, upb_safecstr(fullname), s);
+}
+inline bool Def::Freeze(Def* const* defs, size_t n, Status* status) {
+ return upb_def_freeze(defs, n, status);
+}
+inline bool Def::Freeze(const std::vector<Def*>& defs, Status* status) {
+ return upb_def_freeze((Def* const*)&defs[0], defs.size(), status);
+}
+
+inline bool FieldDef::CheckType(int32_t val) {
+ return upb_fielddef_checktype(val);
+}
+inline bool FieldDef::CheckLabel(int32_t val) {
+ return upb_fielddef_checklabel(val);
+}
+inline bool FieldDef::CheckDescriptorType(int32_t val) {
+ return upb_fielddef_checkdescriptortype(val);
+}
+inline bool FieldDef::CheckIntegerFormat(int32_t val) {
+ return upb_fielddef_checkintfmt(val);
+}
+inline FieldDef::Type FieldDef::ConvertType(int32_t val) {
+ UPB_ASSERT(CheckType(val));
+ return static_cast<FieldDef::Type>(val);
+}
+inline FieldDef::Label FieldDef::ConvertLabel(int32_t val) {
+ UPB_ASSERT(CheckLabel(val));
+ return static_cast<FieldDef::Label>(val);
+}
+inline FieldDef::DescriptorType FieldDef::ConvertDescriptorType(int32_t val) {
+ UPB_ASSERT(CheckDescriptorType(val));
+ return static_cast<FieldDef::DescriptorType>(val);
+}
+inline FieldDef::IntegerFormat FieldDef::ConvertIntegerFormat(int32_t val) {
+ UPB_ASSERT(CheckIntegerFormat(val));
+ return static_cast<FieldDef::IntegerFormat>(val);
+}
+
+inline reffed_ptr<FieldDef> FieldDef::New() {
+ upb_fielddef *f = upb_fielddef_new(&f);
+ return reffed_ptr<FieldDef>(f, &f);
+}
+inline const char* FieldDef::full_name() const {
+ return upb_fielddef_fullname(this);
+}
+inline bool FieldDef::set_full_name(const char* fullname, Status* s) {
+ return upb_fielddef_setfullname(this, fullname, s);
+}
+inline bool FieldDef::set_full_name(const std::string& fullname, Status* s) {
+ return upb_fielddef_setfullname(this, upb_safecstr(fullname), s);
+}
+inline bool FieldDef::type_is_set() const {
+ return upb_fielddef_typeisset(this);
+}
+inline FieldDef::Type FieldDef::type() const { return upb_fielddef_type(this); }
+inline FieldDef::DescriptorType FieldDef::descriptor_type() const {
+ return upb_fielddef_descriptortype(this);
+}
+inline FieldDef::Label FieldDef::label() const {
+ return upb_fielddef_label(this);
+}
+inline uint32_t FieldDef::number() const { return upb_fielddef_number(this); }
+inline const char* FieldDef::name() const { return upb_fielddef_name(this); }
+inline bool FieldDef::is_extension() const {
+ return upb_fielddef_isextension(this);
+}
+inline size_t FieldDef::GetJsonName(char* buf, size_t len) const {
+ return upb_fielddef_getjsonname(this, buf, len);
+}
+inline bool FieldDef::lazy() const {
+ return upb_fielddef_lazy(this);
+}
+inline void FieldDef::set_lazy(bool lazy) {
+ upb_fielddef_setlazy(this, lazy);
+}
+inline bool FieldDef::packed() const {
+ return upb_fielddef_packed(this);
+}
+inline uint32_t FieldDef::index() const {
+ return upb_fielddef_index(this);
+}
+inline void FieldDef::set_packed(bool packed) {
+ upb_fielddef_setpacked(this, packed);
+}
+inline const MessageDef* FieldDef::containing_type() const {
+ return upb_fielddef_containingtype(this);
+}
+inline const OneofDef* FieldDef::containing_oneof() const {
+ return upb_fielddef_containingoneof(this);
+}
+inline const char* FieldDef::containing_type_name() {
+ return upb_fielddef_containingtypename(this);
+}
+inline bool FieldDef::set_number(uint32_t number, Status* s) {
+ return upb_fielddef_setnumber(this, number, s);
+}
+inline bool FieldDef::set_name(const char *name, Status* s) {
+ return upb_fielddef_setname(this, name, s);
+}
+inline bool FieldDef::set_name(const std::string& name, Status* s) {
+ return upb_fielddef_setname(this, upb_safecstr(name), s);
+}
+inline bool FieldDef::set_json_name(const char *name, Status* s) {
+ return upb_fielddef_setjsonname(this, name, s);
+}
+inline bool FieldDef::set_json_name(const std::string& name, Status* s) {
+ return upb_fielddef_setjsonname(this, upb_safecstr(name), s);
+}
+inline void FieldDef::clear_json_name() {
+ upb_fielddef_clearjsonname(this);
+}
+inline bool FieldDef::set_containing_type_name(const char *name, Status* s) {
+ return upb_fielddef_setcontainingtypename(this, name, s);
+}
+inline bool FieldDef::set_containing_type_name(const std::string &name,
+ Status *s) {
+ return upb_fielddef_setcontainingtypename(this, upb_safecstr(name), s);
+}
+inline void FieldDef::set_type(upb_fieldtype_t type) {
+ upb_fielddef_settype(this, type);
+}
+inline void FieldDef::set_is_extension(bool is_extension) {
+ upb_fielddef_setisextension(this, is_extension);
+}
+inline void FieldDef::set_descriptor_type(FieldDef::DescriptorType type) {
+ upb_fielddef_setdescriptortype(this, type);
+}
+inline void FieldDef::set_label(upb_label_t label) {
+ upb_fielddef_setlabel(this, label);
+}
+inline bool FieldDef::IsSubMessage() const {
+ return upb_fielddef_issubmsg(this);
+}
+inline bool FieldDef::IsString() const { return upb_fielddef_isstring(this); }
+inline bool FieldDef::IsSequence() const { return upb_fielddef_isseq(this); }
+inline bool FieldDef::IsMap() const { return upb_fielddef_ismap(this); }
+inline int64_t FieldDef::default_int64() const {
+ return upb_fielddef_defaultint64(this);
+}
+inline int32_t FieldDef::default_int32() const {
+ return upb_fielddef_defaultint32(this);
+}
+inline uint64_t FieldDef::default_uint64() const {
+ return upb_fielddef_defaultuint64(this);
+}
+inline uint32_t FieldDef::default_uint32() const {
+ return upb_fielddef_defaultuint32(this);
+}
+inline bool FieldDef::default_bool() const {
+ return upb_fielddef_defaultbool(this);
+}
+inline float FieldDef::default_float() const {
+ return upb_fielddef_defaultfloat(this);
+}
+inline double FieldDef::default_double() const {
+ return upb_fielddef_defaultdouble(this);
+}
+inline const char* FieldDef::default_string(size_t* len) const {
+ return upb_fielddef_defaultstr(this, len);
+}
+inline void FieldDef::set_default_int64(int64_t value) {
+ upb_fielddef_setdefaultint64(this, value);
+}
+inline void FieldDef::set_default_int32(int32_t value) {
+ upb_fielddef_setdefaultint32(this, value);
+}
+inline void FieldDef::set_default_uint64(uint64_t value) {
+ upb_fielddef_setdefaultuint64(this, value);
+}
+inline void FieldDef::set_default_uint32(uint32_t value) {
+ upb_fielddef_setdefaultuint32(this, value);
+}
+inline void FieldDef::set_default_bool(bool value) {
+ upb_fielddef_setdefaultbool(this, value);
+}
+inline void FieldDef::set_default_float(float value) {
+ upb_fielddef_setdefaultfloat(this, value);
+}
+inline void FieldDef::set_default_double(double value) {
+ upb_fielddef_setdefaultdouble(this, value);
+}
+inline bool FieldDef::set_default_string(const void *str, size_t len,
+ Status *s) {
+ return upb_fielddef_setdefaultstr(this, str, len, s);
+}
+inline bool FieldDef::set_default_string(const std::string& str, Status* s) {
+ return upb_fielddef_setdefaultstr(this, str.c_str(), str.size(), s);
+}
+inline void FieldDef::set_default_cstr(const char* str, Status* s) {
+ return upb_fielddef_setdefaultcstr(this, str, s);
+}
+inline bool FieldDef::HasSubDef() const { return upb_fielddef_hassubdef(this); }
+inline const Def* FieldDef::subdef() const { return upb_fielddef_subdef(this); }
+inline const MessageDef *FieldDef::message_subdef() const {
+ return upb_fielddef_msgsubdef(this);
+}
+inline const EnumDef *FieldDef::enum_subdef() const {
+ return upb_fielddef_enumsubdef(this);
+}
+inline const char* FieldDef::subdef_name() const {
+ return upb_fielddef_subdefname(this);
+}
+inline bool FieldDef::set_subdef(const Def* subdef, Status* s) {
+ return upb_fielddef_setsubdef(this, subdef, s);
+}
+inline bool FieldDef::set_enum_subdef(const EnumDef* subdef, Status* s) {
+ return upb_fielddef_setenumsubdef(this, subdef, s);
+}
+inline bool FieldDef::set_message_subdef(const MessageDef* subdef, Status* s) {
+ return upb_fielddef_setmsgsubdef(this, subdef, s);
+}
+inline bool FieldDef::set_subdef_name(const char* name, Status* s) {
+ return upb_fielddef_setsubdefname(this, name, s);
+}
+inline bool FieldDef::set_subdef_name(const std::string& name, Status* s) {
+ return upb_fielddef_setsubdefname(this, upb_safecstr(name), s);
+}
+
+inline reffed_ptr<MessageDef> MessageDef::New() {
+ upb_msgdef *m = upb_msgdef_new(&m);
+ return reffed_ptr<MessageDef>(m, &m);
+}
+inline const char *MessageDef::full_name() const {
+ return upb_msgdef_fullname(this);
+}
+inline const char *MessageDef::name() const {
+ return upb_msgdef_name(this);
+}
+inline upb_syntax_t MessageDef::syntax() const {
+ return upb_msgdef_syntax(this);
+}
+inline bool MessageDef::set_full_name(const char* fullname, Status* s) {
+ return upb_msgdef_setfullname(this, fullname, s);
+}
+inline bool MessageDef::set_full_name(const std::string& fullname, Status* s) {
+ return upb_msgdef_setfullname(this, upb_safecstr(fullname), s);
+}
+inline bool MessageDef::set_syntax(upb_syntax_t syntax) {
+ return upb_msgdef_setsyntax(this, syntax);
+}
+inline bool MessageDef::Freeze(Status* status) {
+ return upb_msgdef_freeze(this, status);
+}
+inline int MessageDef::field_count() const {
+ return upb_msgdef_numfields(this);
+}
+inline int MessageDef::oneof_count() const {
+ return upb_msgdef_numoneofs(this);
+}
+inline bool MessageDef::AddField(upb_fielddef* f, Status* s) {
+ return upb_msgdef_addfield(this, f, NULL, s);
+}
+inline bool MessageDef::AddField(const reffed_ptr<FieldDef>& f, Status* s) {
+ return upb_msgdef_addfield(this, f.get(), NULL, s);
+}
+inline bool MessageDef::AddOneof(upb_oneofdef* o, Status* s) {
+ return upb_msgdef_addoneof(this, o, NULL, s);
+}
+inline bool MessageDef::AddOneof(const reffed_ptr<OneofDef>& o, Status* s) {
+ return upb_msgdef_addoneof(this, o.get(), NULL, s);
+}
+inline FieldDef* MessageDef::FindFieldByNumber(uint32_t number) {
+ return upb_msgdef_itof_mutable(this, number);
+}
+inline FieldDef* MessageDef::FindFieldByName(const char* name, size_t len) {
+ return upb_msgdef_ntof_mutable(this, name, len);
+}
+inline const FieldDef* MessageDef::FindFieldByNumber(uint32_t number) const {
+ return upb_msgdef_itof(this, number);
+}
+inline const FieldDef *MessageDef::FindFieldByName(const char *name,
+ size_t len) const {
+ return upb_msgdef_ntof(this, name, len);
+}
+inline OneofDef* MessageDef::FindOneofByName(const char* name, size_t len) {
+ return upb_msgdef_ntoo_mutable(this, name, len);
+}
+inline const OneofDef* MessageDef::FindOneofByName(const char* name,
+ size_t len) const {
+ return upb_msgdef_ntoo(this, name, len);
+}
+inline void MessageDef::setmapentry(bool map_entry) {
+ upb_msgdef_setmapentry(this, map_entry);
+}
+inline bool MessageDef::mapentry() const {
+ return upb_msgdef_mapentry(this);
+}
+inline MessageDef::field_iterator MessageDef::field_begin() {
+ return field_iterator(this);
+}
+inline MessageDef::field_iterator MessageDef::field_end() {
+ return field_iterator::end(this);
+}
+inline MessageDef::const_field_iterator MessageDef::field_begin() const {
+ return const_field_iterator(this);
+}
+inline MessageDef::const_field_iterator MessageDef::field_end() const {
+ return const_field_iterator::end(this);
+}
+
+inline MessageDef::oneof_iterator MessageDef::oneof_begin() {
+ return oneof_iterator(this);
+}
+inline MessageDef::oneof_iterator MessageDef::oneof_end() {
+ return oneof_iterator::end(this);
+}
+inline MessageDef::const_oneof_iterator MessageDef::oneof_begin() const {
+ return const_oneof_iterator(this);
+}
+inline MessageDef::const_oneof_iterator MessageDef::oneof_end() const {
+ return const_oneof_iterator::end(this);
+}
+
+inline MessageDef::field_iterator::field_iterator(MessageDef* md) {
+ upb_msg_field_begin(&iter_, md);
+}
+inline MessageDef::field_iterator MessageDef::field_iterator::end(
+ MessageDef* md) {
+ MessageDef::field_iterator iter(md);
+ upb_msg_field_iter_setdone(&iter.iter_);
+ return iter;
+}
+inline FieldDef* MessageDef::field_iterator::operator*() const {
+ return upb_msg_iter_field(&iter_);
+}
+inline void MessageDef::field_iterator::operator++() {
+ return upb_msg_field_next(&iter_);
+}
+inline bool MessageDef::field_iterator::operator==(
+ const field_iterator &other) const {
+ return upb_inttable_iter_isequal(&iter_, &other.iter_);
+}
+inline bool MessageDef::field_iterator::operator!=(
+ const field_iterator &other) const {
+ return !(*this == other);
+}
+
+inline MessageDef::const_field_iterator::const_field_iterator(
+ const MessageDef* md) {
+ upb_msg_field_begin(&iter_, md);
+}
+inline MessageDef::const_field_iterator MessageDef::const_field_iterator::end(
+ const MessageDef *md) {
+ MessageDef::const_field_iterator iter(md);
+ upb_msg_field_iter_setdone(&iter.iter_);
+ return iter;
+}
+inline const FieldDef* MessageDef::const_field_iterator::operator*() const {
+ return upb_msg_iter_field(&iter_);
+}
+inline void MessageDef::const_field_iterator::operator++() {
+ return upb_msg_field_next(&iter_);
+}
+inline bool MessageDef::const_field_iterator::operator==(
+ const const_field_iterator &other) const {
+ return upb_inttable_iter_isequal(&iter_, &other.iter_);
+}
+inline bool MessageDef::const_field_iterator::operator!=(
+ const const_field_iterator &other) const {
+ return !(*this == other);
+}
+
+inline MessageDef::oneof_iterator::oneof_iterator(MessageDef* md) {
+ upb_msg_oneof_begin(&iter_, md);
+}
+inline MessageDef::oneof_iterator MessageDef::oneof_iterator::end(
+ MessageDef* md) {
+ MessageDef::oneof_iterator iter(md);
+ upb_msg_oneof_iter_setdone(&iter.iter_);
+ return iter;
+}
+inline OneofDef* MessageDef::oneof_iterator::operator*() const {
+ return upb_msg_iter_oneof(&iter_);
+}
+inline void MessageDef::oneof_iterator::operator++() {
+ return upb_msg_oneof_next(&iter_);
+}
+inline bool MessageDef::oneof_iterator::operator==(
+ const oneof_iterator &other) const {
+ return upb_strtable_iter_isequal(&iter_, &other.iter_);
+}
+inline bool MessageDef::oneof_iterator::operator!=(
+ const oneof_iterator &other) const {
+ return !(*this == other);
+}
+
+inline MessageDef::const_oneof_iterator::const_oneof_iterator(
+ const MessageDef* md) {
+ upb_msg_oneof_begin(&iter_, md);
+}
+inline MessageDef::const_oneof_iterator MessageDef::const_oneof_iterator::end(
+ const MessageDef *md) {
+ MessageDef::const_oneof_iterator iter(md);
+ upb_msg_oneof_iter_setdone(&iter.iter_);
+ return iter;
+}
+inline const OneofDef* MessageDef::const_oneof_iterator::operator*() const {
+ return upb_msg_iter_oneof(&iter_);
+}
+inline void MessageDef::const_oneof_iterator::operator++() {
+ return upb_msg_oneof_next(&iter_);
+}
+inline bool MessageDef::const_oneof_iterator::operator==(
+ const const_oneof_iterator &other) const {
+ return upb_strtable_iter_isequal(&iter_, &other.iter_);
+}
+inline bool MessageDef::const_oneof_iterator::operator!=(
+ const const_oneof_iterator &other) const {
+ return !(*this == other);
+}
+
+inline reffed_ptr<EnumDef> EnumDef::New() {
+ upb_enumdef *e = upb_enumdef_new(&e);
+ return reffed_ptr<EnumDef>(e, &e);
+}
+inline const char* EnumDef::full_name() const {
+ return upb_enumdef_fullname(this);
+}
+inline const char* EnumDef::name() const {
+ return upb_enumdef_name(this);
+}
+inline bool EnumDef::set_full_name(const char* fullname, Status* s) {
+ return upb_enumdef_setfullname(this, fullname, s);
+}
+inline bool EnumDef::set_full_name(const std::string& fullname, Status* s) {
+ return upb_enumdef_setfullname(this, upb_safecstr(fullname), s);
+}
+inline bool EnumDef::Freeze(Status* status) {
+ return upb_enumdef_freeze(this, status);
+}
+inline int32_t EnumDef::default_value() const {
+ return upb_enumdef_default(this);
+}
+inline bool EnumDef::set_default_value(int32_t val, Status* status) {
+ return upb_enumdef_setdefault(this, val, status);
+}
+inline int EnumDef::value_count() const { return upb_enumdef_numvals(this); }
+inline bool EnumDef::AddValue(const char* name, int32_t num, Status* status) {
+ return upb_enumdef_addval(this, name, num, status);
+}
+inline bool EnumDef::AddValue(const std::string& name, int32_t num,
+ Status* status) {
+ return upb_enumdef_addval(this, upb_safecstr(name), num, status);
+}
+inline bool EnumDef::FindValueByName(const char* name, int32_t *num) const {
+ return upb_enumdef_ntoiz(this, name, num);
+}
+inline const char* EnumDef::FindValueByNumber(int32_t num) const {
+ return upb_enumdef_iton(this, num);
+}
+
+inline EnumDef::Iterator::Iterator(const EnumDef* e) {
+ upb_enum_begin(&iter_, e);
+}
+inline int32_t EnumDef::Iterator::number() {
+ return upb_enum_iter_number(&iter_);
+}
+inline const char* EnumDef::Iterator::name() {
+ return upb_enum_iter_name(&iter_);
+}
+inline bool EnumDef::Iterator::Done() { return upb_enum_done(&iter_); }
+inline void EnumDef::Iterator::Next() { return upb_enum_next(&iter_); }
+
+inline reffed_ptr<OneofDef> OneofDef::New() {
+ upb_oneofdef *o = upb_oneofdef_new(&o);
+ return reffed_ptr<OneofDef>(o, &o);
+}
+
+inline const MessageDef* OneofDef::containing_type() const {
+ return upb_oneofdef_containingtype(this);
+}
+inline const char* OneofDef::name() const {
+ return upb_oneofdef_name(this);
+}
+inline bool OneofDef::set_name(const char* name, Status* s) {
+ return upb_oneofdef_setname(this, name, s);
+}
+inline bool OneofDef::set_name(const std::string& name, Status* s) {
+ return upb_oneofdef_setname(this, upb_safecstr(name), s);
+}
+inline int OneofDef::field_count() const {
+ return upb_oneofdef_numfields(this);
+}
+inline bool OneofDef::AddField(FieldDef* field, Status* s) {
+ return upb_oneofdef_addfield(this, field, NULL, s);
+}
+inline bool OneofDef::AddField(const reffed_ptr<FieldDef>& field, Status* s) {
+ return upb_oneofdef_addfield(this, field.get(), NULL, s);
+}
+inline const FieldDef* OneofDef::FindFieldByName(const char* name,
+ size_t len) const {
+ return upb_oneofdef_ntof(this, name, len);
+}
+inline const FieldDef* OneofDef::FindFieldByNumber(uint32_t num) const {
+ return upb_oneofdef_itof(this, num);
+}
+inline OneofDef::iterator OneofDef::begin() { return iterator(this); }
+inline OneofDef::iterator OneofDef::end() { return iterator::end(this); }
+inline OneofDef::const_iterator OneofDef::begin() const {
+ return const_iterator(this);
+}
+inline OneofDef::const_iterator OneofDef::end() const {
+ return const_iterator::end(this);
+}
+
+inline OneofDef::iterator::iterator(OneofDef* o) {
+ upb_oneof_begin(&iter_, o);
+}
+inline OneofDef::iterator OneofDef::iterator::end(OneofDef* o) {
+ OneofDef::iterator iter(o);
+ upb_oneof_iter_setdone(&iter.iter_);
+ return iter;
+}
+inline FieldDef* OneofDef::iterator::operator*() const {
+ return upb_oneof_iter_field(&iter_);
+}
+inline void OneofDef::iterator::operator++() { return upb_oneof_next(&iter_); }
+inline bool OneofDef::iterator::operator==(const iterator &other) const {
+ return upb_inttable_iter_isequal(&iter_, &other.iter_);
+}
+inline bool OneofDef::iterator::operator!=(const iterator &other) const {
+ return !(*this == other);
+}
+
+inline OneofDef::const_iterator::const_iterator(const OneofDef* md) {
+ upb_oneof_begin(&iter_, md);
+}
+inline OneofDef::const_iterator OneofDef::const_iterator::end(
+ const OneofDef *md) {
+ OneofDef::const_iterator iter(md);
+ upb_oneof_iter_setdone(&iter.iter_);
+ return iter;
+}
+inline const FieldDef* OneofDef::const_iterator::operator*() const {
+ return upb_msg_iter_field(&iter_);
+}
+inline void OneofDef::const_iterator::operator++() {
+ return upb_oneof_next(&iter_);
+}
+inline bool OneofDef::const_iterator::operator==(
+ const const_iterator &other) const {
+ return upb_inttable_iter_isequal(&iter_, &other.iter_);
+}
+inline bool OneofDef::const_iterator::operator!=(
+ const const_iterator &other) const {
+ return !(*this == other);
+}
+
+inline reffed_ptr<FileDef> FileDef::New() {
+ upb_filedef *f = upb_filedef_new(&f);
+ return reffed_ptr<FileDef>(f, &f);
+}
+
+inline const char* FileDef::name() const {
+ return upb_filedef_name(this);
+}
+inline bool FileDef::set_name(const char* name, Status* s) {
+ return upb_filedef_setname(this, name, s);
+}
+inline bool FileDef::set_name(const std::string& name, Status* s) {
+ return upb_filedef_setname(this, upb_safecstr(name), s);
+}
+inline const char* FileDef::package() const {
+ return upb_filedef_package(this);
+}
+inline bool FileDef::set_package(const char* package, Status* s) {
+ return upb_filedef_setpackage(this, package, s);
+}
+inline int FileDef::def_count() const {
+ return upb_filedef_defcount(this);
+}
+inline const Def* FileDef::def(int index) const {
+ return upb_filedef_def(this, index);
+}
+inline Def* FileDef::def(int index) {
+ return const_cast<Def*>(upb_filedef_def(this, index));
+}
+inline int FileDef::dependency_count() const {
+ return upb_filedef_depcount(this);
+}
+inline const FileDef* FileDef::dependency(int index) const {
+ return upb_filedef_dep(this, index);
+}
+inline bool FileDef::AddDef(Def* def, Status* s) {
+ return upb_filedef_adddef(this, def, NULL, s);
+}
+inline bool FileDef::AddMessage(MessageDef* m, Status* s) {
+ return upb_filedef_addmsg(this, m, NULL, s);
+}
+inline bool FileDef::AddEnum(EnumDef* e, Status* s) {
+ return upb_filedef_addenum(this, e, NULL, s);
+}
+inline bool FileDef::AddExtension(FieldDef* f, Status* s) {
+ return upb_filedef_addext(this, f, NULL, s);
+}
+inline bool FileDef::AddDependency(const FileDef* file) {
+ return upb_filedef_adddep(this, file);
+}
+
+} /* namespace upb */
+#endif
+
+#endif /* UPB_DEF_H_ */
+/*
+** This file contains definitions of structs that should be considered private
+** and NOT stable across versions of upb.
+**
+** The only reason they are declared here and not in .c files is to allow upb
+** and the application (if desired) to embed statically-initialized instances
+** of structures like defs.
+**
+** If you include this file, all guarantees of ABI compatibility go out the
+** window! Any code that includes this file needs to recompile against the
+** exact same version of upb that they are linking against.
+**
+** You also need to recompile if you change the value of the UPB_DEBUG_REFS
+** flag.
+*/
+
+
+#ifndef UPB_STATICINIT_H_
+#define UPB_STATICINIT_H_
+
+#ifdef __cplusplus
+/* Because of how we do our typedefs, this header can't be included from C++. */
+#error This file cannot be included from C++
+#endif
+
+/* upb_refcounted *************************************************************/
+
+
+/* upb_def ********************************************************************/
+
+struct upb_def {
+ upb_refcounted base;
+
+ const char *fullname;
+ const upb_filedef* file;
+ char type; /* A upb_deftype_t (char to save space) */
+
+ /* Used as a flag during the def's mutable stage. Must be false unless
+ * it is currently being used by a function on the stack. This allows
+ * us to easily determine which defs were passed into the function's
+ * current invocation. */
+ bool came_from_user;
+};
+
+#define UPB_DEF_INIT(name, type, vtbl, refs, ref2s) \
+ { UPB_REFCOUNT_INIT(vtbl, refs, ref2s), name, NULL, type, false }
+
+
+/* upb_fielddef ***************************************************************/
+
+struct upb_fielddef {
+ upb_def base;
+
+ union {
+ int64_t sint;
+ uint64_t uint;
+ double dbl;
+ float flt;
+ void *bytes;
+ } defaultval;
+ union {
+ const upb_msgdef *def; /* If !msg_is_symbolic. */
+ char *name; /* If msg_is_symbolic. */
+ } msg;
+ union {
+ const upb_def *def; /* If !subdef_is_symbolic. */
+ char *name; /* If subdef_is_symbolic. */
+ } sub; /* The msgdef or enumdef for this field, if upb_hassubdef(f). */
+ bool subdef_is_symbolic;
+ bool msg_is_symbolic;
+ const upb_oneofdef *oneof;
+ bool default_is_string;
+ bool type_is_set_; /* False until type is explicitly set. */
+ bool is_extension_;
+ bool lazy_;
+ bool packed_;
+ upb_intfmt_t intfmt;
+ bool tagdelim;
+ upb_fieldtype_t type_;
+ upb_label_t label_;
+ uint32_t number_;
+ uint32_t selector_base; /* Used to index into a upb::Handlers table. */
+ uint32_t index_;
+};
+
+extern const struct upb_refcounted_vtbl upb_fielddef_vtbl;
+
+#define UPB_FIELDDEF_INIT(label, type, intfmt, tagdelim, is_extension, lazy, \
+ packed, name, num, msgdef, subdef, selector_base, \
+ index, defaultval, refs, ref2s) \
+ { \
+ UPB_DEF_INIT(name, UPB_DEF_FIELD, &upb_fielddef_vtbl, refs, ref2s), \
+ defaultval, {msgdef}, {subdef}, NULL, false, false, \
+ type == UPB_TYPE_STRING || type == UPB_TYPE_BYTES, true, is_extension, \
+ lazy, packed, intfmt, tagdelim, type, label, num, selector_base, index \
+ }
+
+
+/* upb_msgdef *****************************************************************/
+
+struct upb_msgdef {
+ upb_def base;
+
+ size_t selector_count;
+ uint32_t submsg_field_count;
+
+ /* Tables for looking up fields by number and name. */
+ upb_inttable itof; /* int to field */
+ upb_strtable ntof; /* name to field/oneof */
+
+ /* Is this a map-entry message? */
+ bool map_entry;
+
+ /* Whether this message has proto2 or proto3 semantics. */
+ upb_syntax_t syntax;
+
+ /* TODO(haberman): proper extension ranges (there can be multiple). */
+};
+
+extern const struct upb_refcounted_vtbl upb_msgdef_vtbl;
+
+/* TODO: also support static initialization of the oneofs table. This will be
+ * needed if we compile in descriptors that contain oneofs. */
+#define UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, \
+ map_entry, syntax, refs, ref2s) \
+ { \
+ UPB_DEF_INIT(name, UPB_DEF_MSG, &upb_fielddef_vtbl, refs, ref2s), \
+ selector_count, submsg_field_count, itof, ntof, map_entry, syntax \
+ }
+
+
+/* upb_enumdef ****************************************************************/
+
+struct upb_enumdef {
+ upb_def base;
+
+ upb_strtable ntoi;
+ upb_inttable iton;
+ int32_t defaultval;
+};
+
+extern const struct upb_refcounted_vtbl upb_enumdef_vtbl;
+
+#define UPB_ENUMDEF_INIT(name, ntoi, iton, defaultval, refs, ref2s) \
+ { UPB_DEF_INIT(name, UPB_DEF_ENUM, &upb_enumdef_vtbl, refs, ref2s), ntoi, \
+ iton, defaultval }
+
+
+/* upb_oneofdef ***************************************************************/
+
+struct upb_oneofdef {
+ upb_refcounted base;
+
+ uint32_t index; /* Index within oneofs. */
+ const char *name;
+ upb_strtable ntof;
+ upb_inttable itof;
+ const upb_msgdef *parent;
+};
+
+extern const struct upb_refcounted_vtbl upb_oneofdef_vtbl;
+
+#define UPB_ONEOFDEF_INIT(name, ntof, itof, refs, ref2s) \
+ { UPB_REFCOUNT_INIT(&upb_oneofdef_vtbl, refs, ref2s), 0, name, ntof, itof }
+
+
+/* upb_symtab *****************************************************************/
+
+struct upb_symtab {
+ upb_refcounted base;
+
+ upb_strtable symtab;
+};
+
+struct upb_filedef {
+ upb_refcounted base;
+
+ const char *name;
+ const char *package;
+ upb_syntax_t syntax;
+
+ upb_inttable defs;
+ upb_inttable deps;
+};
+
+extern const struct upb_refcounted_vtbl upb_filedef_vtbl;
+
+#endif /* UPB_STATICINIT_H_ */
+/*
+** upb::Handlers (upb_handlers)
+**
+** A upb_handlers is like a virtual table for a upb_msgdef. Each field of the
+** message can have associated functions that will be called when we are
+** parsing or visiting a stream of data. This is similar to how handlers work
+** in SAX (the Simple API for XML).
+**
+** The handlers have no idea where the data is coming from, so a single set of
+** handlers could be used with two completely different data sources (for
+** example, a parser and a visitor over in-memory objects). This decoupling is
+** the most important feature of upb, because it allows parsers and serializers
+** to be highly reusable.
+**
+** This is a mixed C/C++ interface that offers a full API to both languages.
+** See the top-level README for more information.
+*/
+
+#ifndef UPB_HANDLERS_H
+#define UPB_HANDLERS_H
+
+
+#ifdef __cplusplus
+namespace upb {
+class BufferHandle;
+class BytesHandler;
+class HandlerAttributes;
+class Handlers;
+template <class T> class Handler;
+template <class T> struct CanonicalType;
+} /* namespace upb */
+#endif
+
+UPB_DECLARE_TYPE(upb::BufferHandle, upb_bufhandle)
+UPB_DECLARE_TYPE(upb::BytesHandler, upb_byteshandler)
+UPB_DECLARE_TYPE(upb::HandlerAttributes, upb_handlerattr)
+UPB_DECLARE_DERIVED_TYPE(upb::Handlers, upb::RefCounted,
+ upb_handlers, upb_refcounted)
+
+/* The maximum depth that the handler graph can have. This is a resource limit
+ * for the C stack since we sometimes need to recursively traverse the graph.
+ * Cycles are ok; the traversal will stop when it detects a cycle, but we must
+ * hit the cycle before the maximum depth is reached.
+ *
+ * If having a single static limit is too inflexible, we can add another variant
+ * of Handlers::Freeze that allows specifying this as a parameter. */
+#define UPB_MAX_HANDLER_DEPTH 64
+
+/* All the different types of handlers that can be registered.
+ * Only needed for the advanced functions in upb::Handlers. */
+typedef enum {
+ UPB_HANDLER_INT32,
+ UPB_HANDLER_INT64,
+ UPB_HANDLER_UINT32,
+ UPB_HANDLER_UINT64,
+ UPB_HANDLER_FLOAT,
+ UPB_HANDLER_DOUBLE,
+ UPB_HANDLER_BOOL,
+ UPB_HANDLER_STARTSTR,
+ UPB_HANDLER_STRING,
+ UPB_HANDLER_ENDSTR,
+ UPB_HANDLER_STARTSUBMSG,
+ UPB_HANDLER_ENDSUBMSG,
+ UPB_HANDLER_STARTSEQ,
+ UPB_HANDLER_ENDSEQ
+} upb_handlertype_t;
+
+#define UPB_HANDLER_MAX (UPB_HANDLER_ENDSEQ+1)
+
+#define UPB_BREAK NULL
+
+/* A convenient definition for when no closure is needed. */
+extern char _upb_noclosure;
+#define UPB_NO_CLOSURE &_upb_noclosure
+
+/* A selector refers to a specific field handler in the Handlers object
+ * (for example: the STARTSUBMSG handler for field "field15"). */
+typedef int32_t upb_selector_t;
+
+UPB_BEGIN_EXTERN_C
+
+/* Forward-declares for C inline accessors. We need to declare these here
+ * so we can "friend" them in the class declarations in C++. */
+UPB_INLINE upb_func *upb_handlers_gethandler(const upb_handlers *h,
+ upb_selector_t s);
+UPB_INLINE const void *upb_handlerattr_handlerdata(const upb_handlerattr *attr);
+UPB_INLINE const void *upb_handlers_gethandlerdata(const upb_handlers *h,
+ upb_selector_t s);
+
+UPB_INLINE void upb_bufhandle_init(upb_bufhandle *h);
+UPB_INLINE void upb_bufhandle_setobj(upb_bufhandle *h, const void *obj,
+ const void *type);
+UPB_INLINE void upb_bufhandle_setbuf(upb_bufhandle *h, const char *buf,
+ size_t ofs);
+UPB_INLINE const void *upb_bufhandle_obj(const upb_bufhandle *h);
+UPB_INLINE const void *upb_bufhandle_objtype(const upb_bufhandle *h);
+UPB_INLINE const char *upb_bufhandle_buf(const upb_bufhandle *h);
+
+UPB_END_EXTERN_C
+
+
+/* Static selectors for upb::Handlers. */
+#define UPB_STARTMSG_SELECTOR 0
+#define UPB_ENDMSG_SELECTOR 1
+#define UPB_STATIC_SELECTOR_COUNT 2
+
+/* Static selectors for upb::BytesHandler. */
+#define UPB_STARTSTR_SELECTOR 0
+#define UPB_STRING_SELECTOR 1
+#define UPB_ENDSTR_SELECTOR 2
+
+typedef void upb_handlerfree(void *d);
+
+#ifdef __cplusplus
+
+/* A set of attributes that accompanies a handler's function pointer. */
+class upb::HandlerAttributes {
+ public:
+ HandlerAttributes();
+ ~HandlerAttributes();
+
+ /* Sets the handler data that will be passed as the second parameter of the
+ * handler. To free this pointer when the handlers are freed, call
+ * Handlers::AddCleanup(). */
+ bool SetHandlerData(const void *handler_data);
+ const void* handler_data() const;
+
+ /* Use this to specify the type of the closure. This will be checked against
+ * all other closure types for handler that use the same closure.
+ * Registration will fail if this does not match all other non-NULL closure
+ * types. */
+ bool SetClosureType(const void *closure_type);
+ const void* closure_type() const;
+
+ /* Use this to specify the type of the returned closure. Only used for
+ * Start*{String,SubMessage,Sequence} handlers. This must match the closure
+ * type of any handlers that use it (for example, the StringBuf handler must
+ * match the closure returned from StartString). */
+ bool SetReturnClosureType(const void *return_closure_type);
+ const void* return_closure_type() const;
+
+ /* Set to indicate that the handler always returns "ok" (either "true" or a
+ * non-NULL closure). This is a hint that can allow code generators to
+ * generate more efficient code. */
+ bool SetAlwaysOk(bool always_ok);
+ bool always_ok() const;
+
+ private:
+ friend UPB_INLINE const void * ::upb_handlerattr_handlerdata(
+ const upb_handlerattr *attr);
+#else
+struct upb_handlerattr {
+#endif
+ const void *handler_data_;
+ const void *closure_type_;
+ const void *return_closure_type_;
+ bool alwaysok_;
+};
+
+#define UPB_HANDLERATTR_INITIALIZER {NULL, NULL, NULL, false}
+
+typedef struct {
+ upb_func *func;
+
+ /* It is wasteful to include the entire attributes here:
+ *
+ * * Some of the information is redundant (like storing the closure type
+ * separately for each handler that must match).
+ * * Some of the info is only needed prior to freeze() (like closure types).
+ * * alignment padding wastes a lot of space for alwaysok_.
+ *
+ * If/when the size and locality of handlers is an issue, we can optimize this
+ * not to store the entire attr like this. We do not expose the table's
+ * layout to allow this optimization in the future. */
+ upb_handlerattr attr;
+} upb_handlers_tabent;
+
+#ifdef __cplusplus
+
+/* Extra information about a buffer that is passed to a StringBuf handler.
+ * TODO(haberman): allow the handle to be pinned so that it will outlive
+ * the handler invocation. */
+class upb::BufferHandle {
+ public:
+ BufferHandle();
+ ~BufferHandle();
+
+ /* The beginning of the buffer. This may be different than the pointer
+ * passed to a StringBuf handler because the handler may receive data
+ * that is from the middle or end of a larger buffer. */
+ const char* buffer() const;
+
+ /* The offset within the attached object where this buffer begins. Only
+ * meaningful if there is an attached object. */
+ size_t object_offset() const;
+
+ /* Note that object_offset is the offset of "buf" within the attached
+ * object. */
+ void SetBuffer(const char* buf, size_t object_offset);
+
+ /* The BufferHandle can have an "attached object", which can be used to
+ * tunnel through a pointer to the buffer's underlying representation. */
+ template <class T>
+ void SetAttachedObject(const T* obj);
+
+ /* Returns NULL if the attached object is not of this type. */
+ template <class T>
+ const T* GetAttachedObject() const;
+
+ private:
+ friend UPB_INLINE void ::upb_bufhandle_init(upb_bufhandle *h);
+ friend UPB_INLINE void ::upb_bufhandle_setobj(upb_bufhandle *h,
+ const void *obj,
+ const void *type);
+ friend UPB_INLINE void ::upb_bufhandle_setbuf(upb_bufhandle *h,
+ const char *buf, size_t ofs);
+ friend UPB_INLINE const void* ::upb_bufhandle_obj(const upb_bufhandle *h);
+ friend UPB_INLINE const void* ::upb_bufhandle_objtype(
+ const upb_bufhandle *h);
+ friend UPB_INLINE const char* ::upb_bufhandle_buf(const upb_bufhandle *h);
+#else
+struct upb_bufhandle {
+#endif
+ const char *buf_;
+ const void *obj_;
+ const void *objtype_;
+ size_t objofs_;
+};
+
+#ifdef __cplusplus
+
+/* A upb::Handlers object represents the set of handlers associated with a
+ * message in the graph of messages. You can think of it as a big virtual
+ * table with functions corresponding to all the events that can fire while
+ * parsing or visiting a message of a specific type.
+ *
+ * Any handlers that are not set behave as if they had successfully consumed
+ * the value. Any unset Start* handlers will propagate their closure to the
+ * inner frame.
+ *
+ * The easiest way to create the *Handler objects needed by the Set* methods is
+ * with the UpbBind() and UpbMakeHandler() macros; see below. */
+class upb::Handlers {
+ public:
+ typedef upb_selector_t Selector;
+ typedef upb_handlertype_t Type;
+
+ typedef Handler<void *(*)(void *, const void *)> StartFieldHandler;
+ typedef Handler<bool (*)(void *, const void *)> EndFieldHandler;
+ typedef Handler<bool (*)(void *, const void *)> StartMessageHandler;
+ typedef Handler<bool (*)(void *, const void *, Status*)> EndMessageHandler;
+ typedef Handler<void *(*)(void *, const void *, size_t)> StartStringHandler;
+ typedef Handler<size_t (*)(void *, const void *, const char *, size_t,
+ const BufferHandle *)> StringHandler;
+
+ template <class T> struct ValueHandler {
+ typedef Handler<bool(*)(void *, const void *, T)> H;
+ };
+
+ typedef ValueHandler<int32_t>::H Int32Handler;
+ typedef ValueHandler<int64_t>::H Int64Handler;
+ typedef ValueHandler<uint32_t>::H UInt32Handler;
+ typedef ValueHandler<uint64_t>::H UInt64Handler;
+ typedef ValueHandler<float>::H FloatHandler;
+ typedef ValueHandler<double>::H DoubleHandler;
+ typedef ValueHandler<bool>::H BoolHandler;
+
+ /* Any function pointer can be converted to this and converted back to its
+ * correct type. */
+ typedef void GenericFunction();
+
+ typedef void HandlersCallback(const void *closure, upb_handlers *h);
+
+ /* Returns a new handlers object for the given frozen msgdef.
+ * Returns NULL if memory allocation failed. */
+ static reffed_ptr<Handlers> New(const MessageDef *m);
+
+ /* Convenience function for registering a graph of handlers that mirrors the
+ * graph of msgdefs for some message. For "m" and all its children a new set
+ * of handlers will be created and the given callback will be invoked,
+ * allowing the client to register handlers for this message. Note that any
+ * subhandlers set by the callback will be overwritten. */
+ static reffed_ptr<const Handlers> NewFrozen(const MessageDef *m,
+ HandlersCallback *callback,
+ const void *closure);
+
+ /* Functionality from upb::RefCounted. */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ /* All handler registration functions return bool to indicate success or
+ * failure; details about failures are stored in this status object. If a
+ * failure does occur, it must be cleared before the Handlers are frozen,
+ * otherwise the freeze() operation will fail. The functions may *only* be
+ * used while the Handlers are mutable. */
+ const Status* status();
+ void ClearError();
+
+ /* Call to freeze these Handlers. Requires that any SubHandlers are already
+ * frozen. For cycles, you must use the static version below and freeze the
+ * whole graph at once. */
+ bool Freeze(Status* s);
+
+ /* Freezes the given set of handlers. You may not freeze a handler without
+ * also freezing any handlers they point to. */
+ static bool Freeze(Handlers*const* handlers, int n, Status* s);
+ static bool Freeze(const std::vector<Handlers*>& handlers, Status* s);
+
+ /* Returns the msgdef associated with this handlers object. */
+ const MessageDef* message_def() const;
+
+ /* Adds the given pointer and function to the list of cleanup functions that
+ * will be run when these handlers are freed. If this pointer has previously
+ * been registered, the function returns false and does nothing. */
+ bool AddCleanup(void *ptr, upb_handlerfree *cleanup);
+
+ /* Sets the startmsg handler for the message, which is defined as follows:
+ *
+ * bool startmsg(MyType* closure) {
+ * // Called when the message begins. Returns true if processing should
+ * // continue.
+ * return true;
+ * }
+ */
+ bool SetStartMessageHandler(const StartMessageHandler& handler);
+
+ /* Sets the endmsg handler for the message, which is defined as follows:
+ *
+ * bool endmsg(MyType* closure, upb_status *status) {
+ * // Called when processing of this message ends, whether in success or
+ * // failure. "status" indicates the final status of processing, and
+ * // can also be modified in-place to update the final status.
+ * }
+ */
+ bool SetEndMessageHandler(const EndMessageHandler& handler);
+
+ /* Sets the value handler for the given field, which is defined as follows
+ * (this is for an int32 field; other field types will pass their native
+ * C/C++ type for "val"):
+ *
+ * bool OnValue(MyClosure* c, const MyHandlerData* d, int32_t val) {
+ * // Called when the field's value is encountered. "d" contains
+ * // whatever data was bound to this field when it was registered.
+ * // Returns true if processing should continue.
+ * return true;
+ * }
+ *
+ * handers->SetInt32Handler(f, UpbBind(OnValue, new MyHandlerData(...)));
+ *
+ * The value type must exactly match f->type().
+ * For example, a handler that takes an int32_t parameter may only be used for
+ * fields of type UPB_TYPE_INT32 and UPB_TYPE_ENUM.
+ *
+ * Returns false if the handler failed to register; in this case the cleanup
+ * handler (if any) will be called immediately.
+ */
+ bool SetInt32Handler (const FieldDef* f, const Int32Handler& h);
+ bool SetInt64Handler (const FieldDef* f, const Int64Handler& h);
+ bool SetUInt32Handler(const FieldDef* f, const UInt32Handler& h);
+ bool SetUInt64Handler(const FieldDef* f, const UInt64Handler& h);
+ bool SetFloatHandler (const FieldDef* f, const FloatHandler& h);
+ bool SetDoubleHandler(const FieldDef* f, const DoubleHandler& h);
+ bool SetBoolHandler (const FieldDef* f, const BoolHandler& h);
+
+ /* Like the previous, but templated on the type on the value (ie. int32).
+ * This is mostly useful to call from other templates. To call this you must
+ * specify the template parameter explicitly, ie:
+ * h->SetValueHandler<T>(f, UpbBind(MyHandler<T>, MyData)); */
+ template <class T>
+ bool SetValueHandler(
+ const FieldDef *f,
+ const typename ValueHandler<typename CanonicalType<T>::Type>::H& handler);
+
+ /* Sets handlers for a string field, which are defined as follows:
+ *
+ * MySubClosure* startstr(MyClosure* c, const MyHandlerData* d,
+ * size_t size_hint) {
+ * // Called when a string value begins. The return value indicates the
+ * // closure for the string. "size_hint" indicates the size of the
+ * // string if it is known, however if the string is length-delimited
+ * // and the end-of-string is not available size_hint will be zero.
+ * // This case is indistinguishable from the case where the size is
+ * // known to be zero.
+ * //
+ * // TODO(haberman): is it important to distinguish these cases?
+ * // If we had ssize_t as a type we could make -1 "unknown", but
+ * // ssize_t is POSIX (not ANSI) and therefore less portable.
+ * // In practice I suspect it won't be important to distinguish.
+ * return closure;
+ * }
+ *
+ * size_t str(MyClosure* closure, const MyHandlerData* d,
+ * const char *str, size_t len) {
+ * // Called for each buffer of string data; the multiple physical buffers
+ * // are all part of the same logical string. The return value indicates
+ * // how many bytes were consumed. If this number is less than "len",
+ * // this will also indicate that processing should be halted for now,
+ * // like returning false or UPB_BREAK from any other callback. If
+ * // number is greater than "len", the excess bytes will be skipped over
+ * // and not passed to the callback.
+ * return len;
+ * }
+ *
+ * bool endstr(MyClosure* c, const MyHandlerData* d) {
+ * // Called when a string value ends. Return value indicates whether
+ * // processing should continue.
+ * return true;
+ * }
+ */
+ bool SetStartStringHandler(const FieldDef* f, const StartStringHandler& h);
+ bool SetStringHandler(const FieldDef* f, const StringHandler& h);
+ bool SetEndStringHandler(const FieldDef* f, const EndFieldHandler& h);
+
+ /* Sets the startseq handler, which is defined as follows:
+ *
+ * MySubClosure *startseq(MyClosure* c, const MyHandlerData* d) {
+ * // Called when a sequence (repeated field) begins. The returned
+ * // pointer indicates the closure for the sequence (or UPB_BREAK
+ * // to interrupt processing).
+ * return closure;
+ * }
+ *
+ * h->SetStartSequenceHandler(f, UpbBind(startseq, new MyHandlerData(...)));
+ *
+ * Returns "false" if "f" does not belong to this message or is not a
+ * repeated field.
+ */
+ bool SetStartSequenceHandler(const FieldDef* f, const StartFieldHandler& h);
+
+ /* Sets the startsubmsg handler for the given field, which is defined as
+ * follows:
+ *
+ * MySubClosure* startsubmsg(MyClosure* c, const MyHandlerData* d) {
+ * // Called when a submessage begins. The returned pointer indicates the
+ * // closure for the sequence (or UPB_BREAK to interrupt processing).
+ * return closure;
+ * }
+ *
+ * h->SetStartSubMessageHandler(f, UpbBind(startsubmsg,
+ * new MyHandlerData(...)));
+ *
+ * Returns "false" if "f" does not belong to this message or is not a
+ * submessage/group field.
+ */
+ bool SetStartSubMessageHandler(const FieldDef* f, const StartFieldHandler& h);
+
+ /* Sets the endsubmsg handler for the given field, which is defined as
+ * follows:
+ *
+ * bool endsubmsg(MyClosure* c, const MyHandlerData* d) {
+ * // Called when a submessage ends. Returns true to continue processing.
+ * return true;
+ * }
+ *
+ * Returns "false" if "f" does not belong to this message or is not a
+ * submessage/group field.
+ */
+ bool SetEndSubMessageHandler(const FieldDef *f, const EndFieldHandler &h);
+
+ /* Starts the endsubseq handler for the given field, which is defined as
+ * follows:
+ *
+ * bool endseq(MyClosure* c, const MyHandlerData* d) {
+ * // Called when a sequence ends. Returns true continue processing.
+ * return true;
+ * }
+ *
+ * Returns "false" if "f" does not belong to this message or is not a
+ * repeated field.
+ */
+ bool SetEndSequenceHandler(const FieldDef* f, const EndFieldHandler& h);
+
+ /* Sets or gets the object that specifies handlers for the given field, which
+ * must be a submessage or group. Returns NULL if no handlers are set. */
+ bool SetSubHandlers(const FieldDef* f, const Handlers* sub);
+ const Handlers* GetSubHandlers(const FieldDef* f) const;
+
+ /* Equivalent to GetSubHandlers, but takes the STARTSUBMSG selector for the
+ * field. */
+ const Handlers* GetSubHandlers(Selector startsubmsg) const;
+
+ /* A selector refers to a specific field handler in the Handlers object
+ * (for example: the STARTSUBMSG handler for field "field15").
+ * On success, returns true and stores the selector in "s".
+ * If the FieldDef or Type are invalid, returns false.
+ * The returned selector is ONLY valid for Handlers whose MessageDef
+ * contains this FieldDef. */
+ static bool GetSelector(const FieldDef* f, Type type, Selector* s);
+
+ /* Given a START selector of any kind, returns the corresponding END selector. */
+ static Selector GetEndSelector(Selector start_selector);
+
+ /* Returns the function pointer for this handler. It is the client's
+ * responsibility to cast to the correct function type before calling it. */
+ GenericFunction* GetHandler(Selector selector);
+
+ /* Sets the given attributes to the attributes for this selector. */
+ bool GetAttributes(Selector selector, HandlerAttributes* attr);
+
+ /* Returns the handler data that was registered with this handler. */
+ const void* GetHandlerData(Selector selector);
+
+ /* Could add any of the following functions as-needed, with some minor
+ * implementation changes:
+ *
+ * const FieldDef* GetFieldDef(Selector selector);
+ * static bool IsSequence(Selector selector); */
+
+ private:
+ UPB_DISALLOW_POD_OPS(Handlers, upb::Handlers)
+
+ friend UPB_INLINE GenericFunction *::upb_handlers_gethandler(
+ const upb_handlers *h, upb_selector_t s);
+ friend UPB_INLINE const void *::upb_handlers_gethandlerdata(
+ const upb_handlers *h, upb_selector_t s);
+#else
+struct upb_handlers {
+#endif
+ upb_refcounted base;
+
+ const upb_msgdef *msg;
+ const upb_handlers **sub;
+ const void *top_closure_type;
+ upb_inttable cleanup_;
+ upb_status status_; /* Used only when mutable. */
+ upb_handlers_tabent table[1]; /* Dynamically-sized field handler array. */
+};
+
+#ifdef __cplusplus
+
+namespace upb {
+
+/* Convenience macros for creating a Handler object that is wrapped with a
+ * type-safe wrapper function that converts the "void*" parameters/returns
+ * of the underlying C API into nice C++ function.
+ *
+ * Sample usage:
+ * void OnValue1(MyClosure* c, const MyHandlerData* d, int32_t val) {
+ * // do stuff ...
+ * }
+ *
+ * // Handler that doesn't need any data bound to it.
+ * void OnValue2(MyClosure* c, int32_t val) {
+ * // do stuff ...
+ * }
+ *
+ * // Handler that returns bool so it can return failure if necessary.
+ * bool OnValue3(MyClosure* c, int32_t val) {
+ * // do stuff ...
+ * return ok;
+ * }
+ *
+ * // Member function handler.
+ * class MyClosure {
+ * public:
+ * void OnValue(int32_t val) {
+ * // do stuff ...
+ * }
+ * };
+ *
+ * // Takes ownership of the MyHandlerData.
+ * handlers->SetInt32Handler(f1, UpbBind(OnValue1, new MyHandlerData(...)));
+ * handlers->SetInt32Handler(f2, UpbMakeHandler(OnValue2));
+ * handlers->SetInt32Handler(f1, UpbMakeHandler(OnValue3));
+ * handlers->SetInt32Handler(f2, UpbMakeHandler(&MyClosure::OnValue));
+ */
+
+#ifdef UPB_CXX11
+
+/* In C++11, the "template" disambiguator can appear even outside templates,
+ * so all calls can safely use this pair of macros. */
+
+#define UpbMakeHandler(f) upb::MatchFunc(f).template GetFunc<f>()
+
+/* We have to be careful to only evaluate "d" once. */
+#define UpbBind(f, d) upb::MatchFunc(f).template GetFunc<f>((d))
+
+#else
+
+/* Prior to C++11, the "template" disambiguator may only appear inside a
+ * template, so the regular macro must not use "template" */
+
+#define UpbMakeHandler(f) upb::MatchFunc(f).GetFunc<f>()
+
+#define UpbBind(f, d) upb::MatchFunc(f).GetFunc<f>((d))
+
+#endif /* UPB_CXX11 */
+
+/* This macro must be used in C++98 for calls from inside a template. But we
+ * define this variant in all cases; code that wants to be compatible with both
+ * C++98 and C++11 should always use this macro when calling from a template. */
+#define UpbMakeHandlerT(f) upb::MatchFunc(f).template GetFunc<f>()
+
+/* We have to be careful to only evaluate "d" once. */
+#define UpbBindT(f, d) upb::MatchFunc(f).template GetFunc<f>((d))
+
+/* Handler: a struct that contains the (handler, data, deleter) tuple that is
+ * used to register all handlers. Users can Make() these directly but it's
+ * more convenient to use the UpbMakeHandler/UpbBind macros above. */
+template <class T> class Handler {
+ public:
+ /* The underlying, handler function signature that upb uses internally. */
+ typedef T FuncPtr;
+
+ /* Intentionally implicit. */
+ template <class F> Handler(F func);
+ ~Handler();
+
+ private:
+ void AddCleanup(Handlers* h) const {
+ if (cleanup_func_) {
+ bool ok = h->AddCleanup(cleanup_data_, cleanup_func_);
+ UPB_ASSERT(ok);
+ }
+ }
+
+ UPB_DISALLOW_COPY_AND_ASSIGN(Handler)
+ friend class Handlers;
+ FuncPtr handler_;
+ mutable HandlerAttributes attr_;
+ mutable bool registered_;
+ void *cleanup_data_;
+ upb_handlerfree *cleanup_func_;
+};
+
+} /* namespace upb */
+
+#endif /* __cplusplus */
+
+UPB_BEGIN_EXTERN_C
+
+/* Native C API. */
+
+/* Handler function typedefs. */
+typedef bool upb_startmsg_handlerfunc(void *c, const void*);
+typedef bool upb_endmsg_handlerfunc(void *c, const void *, upb_status *status);
+typedef void* upb_startfield_handlerfunc(void *c, const void *hd);
+typedef bool upb_endfield_handlerfunc(void *c, const void *hd);
+typedef bool upb_int32_handlerfunc(void *c, const void *hd, int32_t val);
+typedef bool upb_int64_handlerfunc(void *c, const void *hd, int64_t val);
+typedef bool upb_uint32_handlerfunc(void *c, const void *hd, uint32_t val);
+typedef bool upb_uint64_handlerfunc(void *c, const void *hd, uint64_t val);
+typedef bool upb_float_handlerfunc(void *c, const void *hd, float val);
+typedef bool upb_double_handlerfunc(void *c, const void *hd, double val);
+typedef bool upb_bool_handlerfunc(void *c, const void *hd, bool val);
+typedef void *upb_startstr_handlerfunc(void *c, const void *hd,
+ size_t size_hint);
+typedef size_t upb_string_handlerfunc(void *c, const void *hd, const char *buf,
+ size_t n, const upb_bufhandle* handle);
+
+/* upb_bufhandle */
+size_t upb_bufhandle_objofs(const upb_bufhandle *h);
+
+/* upb_handlerattr */
+void upb_handlerattr_init(upb_handlerattr *attr);
+void upb_handlerattr_uninit(upb_handlerattr *attr);
+
+bool upb_handlerattr_sethandlerdata(upb_handlerattr *attr, const void *hd);
+bool upb_handlerattr_setclosuretype(upb_handlerattr *attr, const void *type);
+const void *upb_handlerattr_closuretype(const upb_handlerattr *attr);
+bool upb_handlerattr_setreturnclosuretype(upb_handlerattr *attr,
+ const void *type);
+const void *upb_handlerattr_returnclosuretype(const upb_handlerattr *attr);
+bool upb_handlerattr_setalwaysok(upb_handlerattr *attr, bool alwaysok);
+bool upb_handlerattr_alwaysok(const upb_handlerattr *attr);
+
+UPB_INLINE const void *upb_handlerattr_handlerdata(
+ const upb_handlerattr *attr) {
+ return attr->handler_data_;
+}
+
+/* upb_handlers */
+typedef void upb_handlers_callback(const void *closure, upb_handlers *h);
+upb_handlers *upb_handlers_new(const upb_msgdef *m,
+ const void *owner);
+const upb_handlers *upb_handlers_newfrozen(const upb_msgdef *m,
+ const void *owner,
+ upb_handlers_callback *callback,
+ const void *closure);
+
+/* Include refcounted methods like upb_handlers_ref(). */
+UPB_REFCOUNTED_CMETHODS(upb_handlers, upb_handlers_upcast)
+
+const upb_status *upb_handlers_status(upb_handlers *h);
+void upb_handlers_clearerr(upb_handlers *h);
+const upb_msgdef *upb_handlers_msgdef(const upb_handlers *h);
+bool upb_handlers_addcleanup(upb_handlers *h, void *p, upb_handlerfree *hfree);
+
+bool upb_handlers_setstartmsg(upb_handlers *h, upb_startmsg_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setendmsg(upb_handlers *h, upb_endmsg_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setint32(upb_handlers *h, const upb_fielddef *f,
+ upb_int32_handlerfunc *func, upb_handlerattr *attr);
+bool upb_handlers_setint64(upb_handlers *h, const upb_fielddef *f,
+ upb_int64_handlerfunc *func, upb_handlerattr *attr);
+bool upb_handlers_setuint32(upb_handlers *h, const upb_fielddef *f,
+ upb_uint32_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setuint64(upb_handlers *h, const upb_fielddef *f,
+ upb_uint64_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setfloat(upb_handlers *h, const upb_fielddef *f,
+ upb_float_handlerfunc *func, upb_handlerattr *attr);
+bool upb_handlers_setdouble(upb_handlers *h, const upb_fielddef *f,
+ upb_double_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setbool(upb_handlers *h, const upb_fielddef *f,
+ upb_bool_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setstartstr(upb_handlers *h, const upb_fielddef *f,
+ upb_startstr_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setstring(upb_handlers *h, const upb_fielddef *f,
+ upb_string_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setendstr(upb_handlers *h, const upb_fielddef *f,
+ upb_endfield_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setstartseq(upb_handlers *h, const upb_fielddef *f,
+ upb_startfield_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setstartsubmsg(upb_handlers *h, const upb_fielddef *f,
+ upb_startfield_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setendsubmsg(upb_handlers *h, const upb_fielddef *f,
+ upb_endfield_handlerfunc *func,
+ upb_handlerattr *attr);
+bool upb_handlers_setendseq(upb_handlers *h, const upb_fielddef *f,
+ upb_endfield_handlerfunc *func,
+ upb_handlerattr *attr);
+
+bool upb_handlers_setsubhandlers(upb_handlers *h, const upb_fielddef *f,
+ const upb_handlers *sub);
+const upb_handlers *upb_handlers_getsubhandlers(const upb_handlers *h,
+ const upb_fielddef *f);
+const upb_handlers *upb_handlers_getsubhandlers_sel(const upb_handlers *h,
+ upb_selector_t sel);
+
+UPB_INLINE upb_func *upb_handlers_gethandler(const upb_handlers *h,
+ upb_selector_t s) {
+ return (upb_func *)h->table[s].func;
+}
+
+bool upb_handlers_getattr(const upb_handlers *h, upb_selector_t s,
+ upb_handlerattr *attr);
+
+UPB_INLINE const void *upb_handlers_gethandlerdata(const upb_handlers *h,
+ upb_selector_t s) {
+ return upb_handlerattr_handlerdata(&h->table[s].attr);
+}
+
+#ifdef __cplusplus
+
+/* Handler types for single fields.
+ * Right now we only have one for TYPE_BYTES but ones for other types
+ * should follow.
+ *
+ * These follow the same handlers protocol for fields of a message. */
+class upb::BytesHandler {
+ public:
+ BytesHandler();
+ ~BytesHandler();
+#else
+struct upb_byteshandler {
+#endif
+ upb_handlers_tabent table[3];
+};
+
+void upb_byteshandler_init(upb_byteshandler *h);
+
+/* Caller must ensure that "d" outlives the handlers.
+ * TODO(haberman): should this have a "freeze" operation? It's not necessary
+ * for memory management, but could be useful to force immutability and provide
+ * a convenient moment to verify that all registration succeeded. */
+bool upb_byteshandler_setstartstr(upb_byteshandler *h,
+ upb_startstr_handlerfunc *func, void *d);
+bool upb_byteshandler_setstring(upb_byteshandler *h,
+ upb_string_handlerfunc *func, void *d);
+bool upb_byteshandler_setendstr(upb_byteshandler *h,
+ upb_endfield_handlerfunc *func, void *d);
+
+/* "Static" methods */
+bool upb_handlers_freeze(upb_handlers *const *handlers, int n, upb_status *s);
+upb_handlertype_t upb_handlers_getprimitivehandlertype(const upb_fielddef *f);
+bool upb_handlers_getselector(const upb_fielddef *f, upb_handlertype_t type,
+ upb_selector_t *s);
+UPB_INLINE upb_selector_t upb_handlers_getendselector(upb_selector_t start) {
+ return start + 1;
+}
+
+/* Internal-only. */
+uint32_t upb_handlers_selectorbaseoffset(const upb_fielddef *f);
+uint32_t upb_handlers_selectorcount(const upb_fielddef *f);
+
+UPB_END_EXTERN_C
+
+/*
+** Inline definitions for handlers.h, which are particularly long and a bit
+** tricky.
+*/
+
+#ifndef UPB_HANDLERS_INL_H_
+#define UPB_HANDLERS_INL_H_
+
+#include <limits.h>
+
+/* C inline methods. */
+
+/* upb_bufhandle */
+UPB_INLINE void upb_bufhandle_init(upb_bufhandle *h) {
+ h->obj_ = NULL;
+ h->objtype_ = NULL;
+ h->buf_ = NULL;
+ h->objofs_ = 0;
+}
+UPB_INLINE void upb_bufhandle_uninit(upb_bufhandle *h) {
+ UPB_UNUSED(h);
+}
+UPB_INLINE void upb_bufhandle_setobj(upb_bufhandle *h, const void *obj,
+ const void *type) {
+ h->obj_ = obj;
+ h->objtype_ = type;
+}
+UPB_INLINE void upb_bufhandle_setbuf(upb_bufhandle *h, const char *buf,
+ size_t ofs) {
+ h->buf_ = buf;
+ h->objofs_ = ofs;
+}
+UPB_INLINE const void *upb_bufhandle_obj(const upb_bufhandle *h) {
+ return h->obj_;
+}
+UPB_INLINE const void *upb_bufhandle_objtype(const upb_bufhandle *h) {
+ return h->objtype_;
+}
+UPB_INLINE const char *upb_bufhandle_buf(const upb_bufhandle *h) {
+ return h->buf_;
+}
+
+
+#ifdef __cplusplus
+
+/* Type detection and typedefs for integer types.
+ * For platforms where there are multiple 32-bit or 64-bit types, we need to be
+ * able to enumerate them so we can properly create overloads for all variants.
+ *
+ * If any platform existed where there were three integer types with the same
+ * size, this would have to become more complicated. For example, short, int,
+ * and long could all be 32-bits. Even more diabolically, short, int, long,
+ * and long long could all be 64 bits and still be standard-compliant.
+ * However, few platforms are this strange, and it's unlikely that upb will be
+ * used on the strangest ones. */
+
+/* Can't count on stdint.h limits like INT32_MAX, because in C++ these are
+ * only defined when __STDC_LIMIT_MACROS are defined before the *first* include
+ * of stdint.h. We can't guarantee that someone else didn't include these first
+ * without defining __STDC_LIMIT_MACROS. */
+#define UPB_INT32_MAX 0x7fffffffLL
+#define UPB_INT32_MIN (-UPB_INT32_MAX - 1)
+#define UPB_INT64_MAX 0x7fffffffffffffffLL
+#define UPB_INT64_MIN (-UPB_INT64_MAX - 1)
+
+#if INT_MAX == UPB_INT32_MAX && INT_MIN == UPB_INT32_MIN
+#define UPB_INT_IS_32BITS 1
+#endif
+
+#if LONG_MAX == UPB_INT32_MAX && LONG_MIN == UPB_INT32_MIN
+#define UPB_LONG_IS_32BITS 1
+#endif
+
+#if LONG_MAX == UPB_INT64_MAX && LONG_MIN == UPB_INT64_MIN
+#define UPB_LONG_IS_64BITS 1
+#endif
+
+#if LLONG_MAX == UPB_INT64_MAX && LLONG_MIN == UPB_INT64_MIN
+#define UPB_LLONG_IS_64BITS 1
+#endif
+
+/* We use macros instead of typedefs so we can undefine them later and avoid
+ * leaking them outside this header file. */
+#if UPB_INT_IS_32BITS
+#define UPB_INT32_T int
+#define UPB_UINT32_T unsigned int
+
+#if UPB_LONG_IS_32BITS
+#define UPB_TWO_32BIT_TYPES 1
+#define UPB_INT32ALT_T long
+#define UPB_UINT32ALT_T unsigned long
+#endif /* UPB_LONG_IS_32BITS */
+
+#elif UPB_LONG_IS_32BITS /* && !UPB_INT_IS_32BITS */
+#define UPB_INT32_T long
+#define UPB_UINT32_T unsigned long
+#endif /* UPB_INT_IS_32BITS */
+
+
+#if UPB_LONG_IS_64BITS
+#define UPB_INT64_T long
+#define UPB_UINT64_T unsigned long
+
+#if UPB_LLONG_IS_64BITS
+#define UPB_TWO_64BIT_TYPES 1
+#define UPB_INT64ALT_T long long
+#define UPB_UINT64ALT_T unsigned long long
+#endif /* UPB_LLONG_IS_64BITS */
+
+#elif UPB_LLONG_IS_64BITS /* && !UPB_LONG_IS_64BITS */
+#define UPB_INT64_T long long
+#define UPB_UINT64_T unsigned long long
+#endif /* UPB_LONG_IS_64BITS */
+
+#undef UPB_INT32_MAX
+#undef UPB_INT32_MIN
+#undef UPB_INT64_MAX
+#undef UPB_INT64_MIN
+#undef UPB_INT_IS_32BITS
+#undef UPB_LONG_IS_32BITS
+#undef UPB_LONG_IS_64BITS
+#undef UPB_LLONG_IS_64BITS
+
+
+namespace upb {
+
+typedef void CleanupFunc(void *ptr);
+
+/* Template to remove "const" from "const T*" and just return "T*".
+ *
+ * We define a nonsense default because otherwise it will fail to instantiate as
+ * a function parameter type even in cases where we don't expect any caller to
+ * actually match the overload. */
+class CouldntRemoveConst {};
+template <class T> struct remove_constptr { typedef CouldntRemoveConst type; };
+template <class T> struct remove_constptr<const T *> { typedef T *type; };
+
+/* Template that we use below to remove a template specialization from
+ * consideration if it matches a specific type. */
+template <class T, class U> struct disable_if_same { typedef void Type; };
+template <class T> struct disable_if_same<T, T> {};
+
+template <class T> void DeletePointer(void *p) { delete static_cast<T>(p); }
+
+template <class T1, class T2>
+struct FirstUnlessVoidOrBool {
+ typedef T1 value;
+};
+
+template <class T2>
+struct FirstUnlessVoidOrBool<void, T2> {
+ typedef T2 value;
+};
+
+template <class T2>
+struct FirstUnlessVoidOrBool<bool, T2> {
+ typedef T2 value;
+};
+
+template<class T, class U>
+struct is_same {
+ static bool value;
+};
+
+template<class T>
+struct is_same<T, T> {
+ static bool value;
+};
+
+template<class T, class U>
+bool is_same<T, U>::value = false;
+
+template<class T>
+bool is_same<T, T>::value = true;
+
+/* FuncInfo *******************************************************************/
+
+/* Info about the user's original, pre-wrapped function. */
+template <class C, class R = void>
+struct FuncInfo {
+ /* The type of the closure that the function takes (its first param). */
+ typedef C Closure;
+
+ /* The return type. */
+ typedef R Return;
+};
+
+/* Func ***********************************************************************/
+
+/* Func1, Func2, Func3: Template classes representing a function and its
+ * signature.
+ *
+ * Since the function is a template parameter, calling the function can be
+ * inlined at compile-time and does not require a function pointer at runtime.
+ * These functions are not bound to a handler data so have no data or cleanup
+ * handler. */
+struct UnboundFunc {
+ CleanupFunc *GetCleanup() { return NULL; }
+ void *GetData() { return NULL; }
+};
+
+template <class R, class P1, R F(P1), class I>
+struct Func1 : public UnboundFunc {
+ typedef R Return;
+ typedef I FuncInfo;
+ static R Call(P1 p1) { return F(p1); }
+};
+
+template <class R, class P1, class P2, R F(P1, P2), class I>
+struct Func2 : public UnboundFunc {
+ typedef R Return;
+ typedef I FuncInfo;
+ static R Call(P1 p1, P2 p2) { return F(p1, p2); }
+};
+
+template <class R, class P1, class P2, class P3, R F(P1, P2, P3), class I>
+struct Func3 : public UnboundFunc {
+ typedef R Return;
+ typedef I FuncInfo;
+ static R Call(P1 p1, P2 p2, P3 p3) { return F(p1, p2, p3); }
+};
+
+template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4),
+ class I>
+struct Func4 : public UnboundFunc {
+ typedef R Return;
+ typedef I FuncInfo;
+ static R Call(P1 p1, P2 p2, P3 p3, P4 p4) { return F(p1, p2, p3, p4); }
+};
+
+template <class R, class P1, class P2, class P3, class P4, class P5,
+ R F(P1, P2, P3, P4, P5), class I>
+struct Func5 : public UnboundFunc {
+ typedef R Return;
+ typedef I FuncInfo;
+ static R Call(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) {
+ return F(p1, p2, p3, p4, p5);
+ }
+};
+
+/* BoundFunc ******************************************************************/
+
+/* BoundFunc2, BoundFunc3: Like Func2/Func3 except also contains a value that
+ * shall be bound to the function's second parameter.
+ *
+ * Note that the second parameter is a const pointer, but our stored bound value
+ * is non-const so we can free it when the handlers are destroyed. */
+template <class T>
+struct BoundFunc {
+ typedef typename remove_constptr<T>::type MutableP2;
+ explicit BoundFunc(MutableP2 data_) : data(data_) {}
+ CleanupFunc *GetCleanup() { return &DeletePointer<MutableP2>; }
+ MutableP2 GetData() { return data; }
+ MutableP2 data;
+};
+
+template <class R, class P1, class P2, R F(P1, P2), class I>
+struct BoundFunc2 : public BoundFunc<P2> {
+ typedef BoundFunc<P2> Base;
+ typedef I FuncInfo;
+ explicit BoundFunc2(typename Base::MutableP2 arg) : Base(arg) {}
+};
+
+template <class R, class P1, class P2, class P3, R F(P1, P2, P3), class I>
+struct BoundFunc3 : public BoundFunc<P2> {
+ typedef BoundFunc<P2> Base;
+ typedef I FuncInfo;
+ explicit BoundFunc3(typename Base::MutableP2 arg) : Base(arg) {}
+};
+
+template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4),
+ class I>
+struct BoundFunc4 : public BoundFunc<P2> {
+ typedef BoundFunc<P2> Base;
+ typedef I FuncInfo;
+ explicit BoundFunc4(typename Base::MutableP2 arg) : Base(arg) {}
+};
+
+template <class R, class P1, class P2, class P3, class P4, class P5,
+ R F(P1, P2, P3, P4, P5), class I>
+struct BoundFunc5 : public BoundFunc<P2> {
+ typedef BoundFunc<P2> Base;
+ typedef I FuncInfo;
+ explicit BoundFunc5(typename Base::MutableP2 arg) : Base(arg) {}
+};
+
+/* FuncSig ********************************************************************/
+
+/* FuncSig1, FuncSig2, FuncSig3: template classes reflecting a function
+ * *signature*, but without a specific function attached.
+ *
+ * These classes contain member functions that can be invoked with a
+ * specific function to return a Func/BoundFunc class. */
+template <class R, class P1>
+struct FuncSig1 {
+ template <R F(P1)>
+ Func1<R, P1, F, FuncInfo<P1, R> > GetFunc() {
+ return Func1<R, P1, F, FuncInfo<P1, R> >();
+ }
+};
+
+template <class R, class P1, class P2>
+struct FuncSig2 {
+ template <R F(P1, P2)>
+ Func2<R, P1, P2, F, FuncInfo<P1, R> > GetFunc() {
+ return Func2<R, P1, P2, F, FuncInfo<P1, R> >();
+ }
+
+ template <R F(P1, P2)>
+ BoundFunc2<R, P1, P2, F, FuncInfo<P1, R> > GetFunc(
+ typename remove_constptr<P2>::type param2) {
+ return BoundFunc2<R, P1, P2, F, FuncInfo<P1, R> >(param2);
+ }
+};
+
+template <class R, class P1, class P2, class P3>
+struct FuncSig3 {
+ template <R F(P1, P2, P3)>
+ Func3<R, P1, P2, P3, F, FuncInfo<P1, R> > GetFunc() {
+ return Func3<R, P1, P2, P3, F, FuncInfo<P1, R> >();
+ }
+
+ template <R F(P1, P2, P3)>
+ BoundFunc3<R, P1, P2, P3, F, FuncInfo<P1, R> > GetFunc(
+ typename remove_constptr<P2>::type param2) {
+ return BoundFunc3<R, P1, P2, P3, F, FuncInfo<P1, R> >(param2);
+ }
+};
+
+template <class R, class P1, class P2, class P3, class P4>
+struct FuncSig4 {
+ template <R F(P1, P2, P3, P4)>
+ Func4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> > GetFunc() {
+ return Func4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> >();
+ }
+
+ template <R F(P1, P2, P3, P4)>
+ BoundFunc4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> > GetFunc(
+ typename remove_constptr<P2>::type param2) {
+ return BoundFunc4<R, P1, P2, P3, P4, F, FuncInfo<P1, R> >(param2);
+ }
+};
+
+template <class R, class P1, class P2, class P3, class P4, class P5>
+struct FuncSig5 {
+ template <R F(P1, P2, P3, P4, P5)>
+ Func5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> > GetFunc() {
+ return Func5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> >();
+ }
+
+ template <R F(P1, P2, P3, P4, P5)>
+ BoundFunc5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> > GetFunc(
+ typename remove_constptr<P2>::type param2) {
+ return BoundFunc5<R, P1, P2, P3, P4, P5, F, FuncInfo<P1, R> >(param2);
+ }
+};
+
+/* Overloaded template function that can construct the appropriate FuncSig*
+ * class given a function pointer by deducing the template parameters. */
+template <class R, class P1>
+inline FuncSig1<R, P1> MatchFunc(R (*f)(P1)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return FuncSig1<R, P1>();
+}
+
+template <class R, class P1, class P2>
+inline FuncSig2<R, P1, P2> MatchFunc(R (*f)(P1, P2)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return FuncSig2<R, P1, P2>();
+}
+
+template <class R, class P1, class P2, class P3>
+inline FuncSig3<R, P1, P2, P3> MatchFunc(R (*f)(P1, P2, P3)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return FuncSig3<R, P1, P2, P3>();
+}
+
+template <class R, class P1, class P2, class P3, class P4>
+inline FuncSig4<R, P1, P2, P3, P4> MatchFunc(R (*f)(P1, P2, P3, P4)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return FuncSig4<R, P1, P2, P3, P4>();
+}
+
+template <class R, class P1, class P2, class P3, class P4, class P5>
+inline FuncSig5<R, P1, P2, P3, P4, P5> MatchFunc(R (*f)(P1, P2, P3, P4, P5)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return FuncSig5<R, P1, P2, P3, P4, P5>();
+}
+
+/* MethodSig ******************************************************************/
+
+/* CallMethod*: a function template that calls a given method. */
+template <class R, class C, R (C::*F)()>
+R CallMethod0(C *obj) {
+ return ((*obj).*F)();
+}
+
+template <class R, class C, class P1, R (C::*F)(P1)>
+R CallMethod1(C *obj, P1 arg1) {
+ return ((*obj).*F)(arg1);
+}
+
+template <class R, class C, class P1, class P2, R (C::*F)(P1, P2)>
+R CallMethod2(C *obj, P1 arg1, P2 arg2) {
+ return ((*obj).*F)(arg1, arg2);
+}
+
+template <class R, class C, class P1, class P2, class P3, R (C::*F)(P1, P2, P3)>
+R CallMethod3(C *obj, P1 arg1, P2 arg2, P3 arg3) {
+ return ((*obj).*F)(arg1, arg2, arg3);
+}
+
+template <class R, class C, class P1, class P2, class P3, class P4,
+ R (C::*F)(P1, P2, P3, P4)>
+R CallMethod4(C *obj, P1 arg1, P2 arg2, P3 arg3, P4 arg4) {
+ return ((*obj).*F)(arg1, arg2, arg3, arg4);
+}
+
+/* MethodSig: like FuncSig, but for member functions.
+ *
+ * GetFunc() returns a normal FuncN object, so after calling GetFunc() no
+ * more logic is required to special-case methods. */
+template <class R, class C>
+struct MethodSig0 {
+ template <R (C::*F)()>
+ Func1<R, C *, CallMethod0<R, C, F>, FuncInfo<C *, R> > GetFunc() {
+ return Func1<R, C *, CallMethod0<R, C, F>, FuncInfo<C *, R> >();
+ }
+};
+
+template <class R, class C, class P1>
+struct MethodSig1 {
+ template <R (C::*F)(P1)>
+ Func2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> > GetFunc() {
+ return Func2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> >();
+ }
+
+ template <R (C::*F)(P1)>
+ BoundFunc2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> > GetFunc(
+ typename remove_constptr<P1>::type param1) {
+ return BoundFunc2<R, C *, P1, CallMethod1<R, C, P1, F>, FuncInfo<C *, R> >(
+ param1);
+ }
+};
+
+template <class R, class C, class P1, class P2>
+struct MethodSig2 {
+ template <R (C::*F)(P1, P2)>
+ Func3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>, FuncInfo<C *, R> >
+ GetFunc() {
+ return Func3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>,
+ FuncInfo<C *, R> >();
+ }
+
+ template <R (C::*F)(P1, P2)>
+ BoundFunc3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>, FuncInfo<C *, R> >
+ GetFunc(typename remove_constptr<P1>::type param1) {
+ return BoundFunc3<R, C *, P1, P2, CallMethod2<R, C, P1, P2, F>,
+ FuncInfo<C *, R> >(param1);
+ }
+};
+
+template <class R, class C, class P1, class P2, class P3>
+struct MethodSig3 {
+ template <R (C::*F)(P1, P2, P3)>
+ Func4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>, FuncInfo<C *, R> >
+ GetFunc() {
+ return Func4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>,
+ FuncInfo<C *, R> >();
+ }
+
+ template <R (C::*F)(P1, P2, P3)>
+ BoundFunc4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>,
+ FuncInfo<C *, R> >
+ GetFunc(typename remove_constptr<P1>::type param1) {
+ return BoundFunc4<R, C *, P1, P2, P3, CallMethod3<R, C, P1, P2, P3, F>,
+ FuncInfo<C *, R> >(param1);
+ }
+};
+
+template <class R, class C, class P1, class P2, class P3, class P4>
+struct MethodSig4 {
+ template <R (C::*F)(P1, P2, P3, P4)>
+ Func5<R, C *, P1, P2, P3, P4, CallMethod4<R, C, P1, P2, P3, P4, F>,
+ FuncInfo<C *, R> >
+ GetFunc() {
+ return Func5<R, C *, P1, P2, P3, P4, CallMethod4<R, C, P1, P2, P3, P4, F>,
+ FuncInfo<C *, R> >();
+ }
+
+ template <R (C::*F)(P1, P2, P3, P4)>
+ BoundFunc5<R, C *, P1, P2, P3, P4, CallMethod4<R, C, P1, P2, P3, P4, F>,
+ FuncInfo<C *, R> >
+ GetFunc(typename remove_constptr<P1>::type param1) {
+ return BoundFunc5<R, C *, P1, P2, P3, P4,
+ CallMethod4<R, C, P1, P2, P3, P4, F>, FuncInfo<C *, R> >(
+ param1);
+ }
+};
+
+template <class R, class C>
+inline MethodSig0<R, C> MatchFunc(R (C::*f)()) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return MethodSig0<R, C>();
+}
+
+template <class R, class C, class P1>
+inline MethodSig1<R, C, P1> MatchFunc(R (C::*f)(P1)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return MethodSig1<R, C, P1>();
+}
+
+template <class R, class C, class P1, class P2>
+inline MethodSig2<R, C, P1, P2> MatchFunc(R (C::*f)(P1, P2)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return MethodSig2<R, C, P1, P2>();
+}
+
+template <class R, class C, class P1, class P2, class P3>
+inline MethodSig3<R, C, P1, P2, P3> MatchFunc(R (C::*f)(P1, P2, P3)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return MethodSig3<R, C, P1, P2, P3>();
+}
+
+template <class R, class C, class P1, class P2, class P3, class P4>
+inline MethodSig4<R, C, P1, P2, P3, P4> MatchFunc(R (C::*f)(P1, P2, P3, P4)) {
+ UPB_UNUSED(f); /* Only used for template parameter deduction. */
+ return MethodSig4<R, C, P1, P2, P3, P4>();
+}
+
+/* MaybeWrapReturn ************************************************************/
+
+/* Template class that attempts to wrap the return value of the function so it
+ * matches the expected type. There are two main adjustments it may make:
+ *
+ * 1. If the function returns void, make it return the expected type and with
+ * a value that always indicates success.
+ * 2. If the function returns bool, make it return the expected type with a
+ * value that indicates success or failure.
+ *
+ * The "expected type" for return is:
+ * 1. void* for start handlers. If the closure parameter has a different type
+ * we will cast it to void* for the return in the success case.
+ * 2. size_t for string buffer handlers.
+ * 3. bool for everything else. */
+
+/* Template parameters are FuncN type and desired return type. */
+template <class F, class R, class Enable = void>
+struct MaybeWrapReturn;
+
+/* If the return type matches, return the given function unwrapped. */
+template <class F>
+struct MaybeWrapReturn<F, typename F::Return> {
+ typedef F Func;
+};
+
+/* Function wrapper that munges the return value from void to (bool)true. */
+template <class P1, class P2, void F(P1, P2)>
+bool ReturnTrue2(P1 p1, P2 p2) {
+ F(p1, p2);
+ return true;
+}
+
+template <class P1, class P2, class P3, void F(P1, P2, P3)>
+bool ReturnTrue3(P1 p1, P2 p2, P3 p3) {
+ F(p1, p2, p3);
+ return true;
+}
+
+/* Function wrapper that munges the return value from void to (void*)arg1 */
+template <class P1, class P2, void F(P1, P2)>
+void *ReturnClosure2(P1 p1, P2 p2) {
+ F(p1, p2);
+ return p1;
+}
+
+template <class P1, class P2, class P3, void F(P1, P2, P3)>
+void *ReturnClosure3(P1 p1, P2 p2, P3 p3) {
+ F(p1, p2, p3);
+ return p1;
+}
+
+/* Function wrapper that munges the return value from R to void*. */
+template <class R, class P1, class P2, R F(P1, P2)>
+void *CastReturnToVoidPtr2(P1 p1, P2 p2) {
+ return F(p1, p2);
+}
+
+template <class R, class P1, class P2, class P3, R F(P1, P2, P3)>
+void *CastReturnToVoidPtr3(P1 p1, P2 p2, P3 p3) {
+ return F(p1, p2, p3);
+}
+
+/* Function wrapper that munges the return value from bool to void*. */
+template <class P1, class P2, bool F(P1, P2)>
+void *ReturnClosureOrBreak2(P1 p1, P2 p2) {
+ return F(p1, p2) ? p1 : UPB_BREAK;
+}
+
+template <class P1, class P2, class P3, bool F(P1, P2, P3)>
+void *ReturnClosureOrBreak3(P1 p1, P2 p2, P3 p3) {
+ return F(p1, p2, p3) ? p1 : UPB_BREAK;
+}
+
+/* For the string callback, which takes five params, returns the size param. */
+template <class P1, class P2,
+ void F(P1, P2, const char *, size_t, const BufferHandle *)>
+size_t ReturnStringLen(P1 p1, P2 p2, const char *p3, size_t p4,
+ const BufferHandle *p5) {
+ F(p1, p2, p3, p4, p5);
+ return p4;
+}
+
+/* For the string callback, which takes five params, returns the size param or
+ * zero. */
+template <class P1, class P2,
+ bool F(P1, P2, const char *, size_t, const BufferHandle *)>
+size_t ReturnNOr0(P1 p1, P2 p2, const char *p3, size_t p4,
+ const BufferHandle *p5) {
+ return F(p1, p2, p3, p4, p5) ? p4 : 0;
+}
+
+/* If we have a function returning void but want a function returning bool, wrap
+ * it in a function that returns true. */
+template <class P1, class P2, void F(P1, P2), class I>
+struct MaybeWrapReturn<Func2<void, P1, P2, F, I>, bool> {
+ typedef Func2<bool, P1, P2, ReturnTrue2<P1, P2, F>, I> Func;
+};
+
+template <class P1, class P2, class P3, void F(P1, P2, P3), class I>
+struct MaybeWrapReturn<Func3<void, P1, P2, P3, F, I>, bool> {
+ typedef Func3<bool, P1, P2, P3, ReturnTrue3<P1, P2, P3, F>, I> Func;
+};
+
+/* If our function returns void but we want one returning void*, wrap it in a
+ * function that returns the first argument. */
+template <class P1, class P2, void F(P1, P2), class I>
+struct MaybeWrapReturn<Func2<void, P1, P2, F, I>, void *> {
+ typedef Func2<void *, P1, P2, ReturnClosure2<P1, P2, F>, I> Func;
+};
+
+template <class P1, class P2, class P3, void F(P1, P2, P3), class I>
+struct MaybeWrapReturn<Func3<void, P1, P2, P3, F, I>, void *> {
+ typedef Func3<void *, P1, P2, P3, ReturnClosure3<P1, P2, P3, F>, I> Func;
+};
+
+/* If our function returns R* but we want one returning void*, wrap it in a
+ * function that casts to void*. */
+template <class R, class P1, class P2, R *F(P1, P2), class I>
+struct MaybeWrapReturn<Func2<R *, P1, P2, F, I>, void *,
+ typename disable_if_same<R *, void *>::Type> {
+ typedef Func2<void *, P1, P2, CastReturnToVoidPtr2<R *, P1, P2, F>, I> Func;
+};
+
+template <class R, class P1, class P2, class P3, R *F(P1, P2, P3), class I>
+struct MaybeWrapReturn<Func3<R *, P1, P2, P3, F, I>, void *,
+ typename disable_if_same<R *, void *>::Type> {
+ typedef Func3<void *, P1, P2, P3, CastReturnToVoidPtr3<R *, P1, P2, P3, F>, I>
+ Func;
+};
+
+/* If our function returns bool but we want one returning void*, wrap it in a
+ * function that returns either the first param or UPB_BREAK. */
+template <class P1, class P2, bool F(P1, P2), class I>
+struct MaybeWrapReturn<Func2<bool, P1, P2, F, I>, void *> {
+ typedef Func2<void *, P1, P2, ReturnClosureOrBreak2<P1, P2, F>, I> Func;
+};
+
+template <class P1, class P2, class P3, bool F(P1, P2, P3), class I>
+struct MaybeWrapReturn<Func3<bool, P1, P2, P3, F, I>, void *> {
+ typedef Func3<void *, P1, P2, P3, ReturnClosureOrBreak3<P1, P2, P3, F>, I>
+ Func;
+};
+
+/* If our function returns void but we want one returning size_t, wrap it in a
+ * function that returns the size argument. */
+template <class P1, class P2,
+ void F(P1, P2, const char *, size_t, const BufferHandle *), class I>
+struct MaybeWrapReturn<
+ Func5<void, P1, P2, const char *, size_t, const BufferHandle *, F, I>,
+ size_t> {
+ typedef Func5<size_t, P1, P2, const char *, size_t, const BufferHandle *,
+ ReturnStringLen<P1, P2, F>, I> Func;
+};
+
+/* If our function returns bool but we want one returning size_t, wrap it in a
+ * function that returns either 0 or the buf size. */
+template <class P1, class P2,
+ bool F(P1, P2, const char *, size_t, const BufferHandle *), class I>
+struct MaybeWrapReturn<
+ Func5<bool, P1, P2, const char *, size_t, const BufferHandle *, F, I>,
+ size_t> {
+ typedef Func5<size_t, P1, P2, const char *, size_t, const BufferHandle *,
+ ReturnNOr0<P1, P2, F>, I> Func;
+};
+
+/* ConvertParams **************************************************************/
+
+/* Template class that converts the function parameters if necessary, and
+ * ignores the HandlerData parameter if appropriate.
+ *
+ * Template parameter is the are FuncN function type. */
+template <class F, class T>
+struct ConvertParams;
+
+/* Function that discards the handler data parameter. */
+template <class R, class P1, R F(P1)>
+R IgnoreHandlerData2(void *p1, const void *hd) {
+ UPB_UNUSED(hd);
+ return F(static_cast<P1>(p1));
+}
+
+template <class R, class P1, class P2Wrapper, class P2Wrapped,
+ R F(P1, P2Wrapped)>
+R IgnoreHandlerData3(void *p1, const void *hd, P2Wrapper p2) {
+ UPB_UNUSED(hd);
+ return F(static_cast<P1>(p1), p2);
+}
+
+template <class R, class P1, class P2, class P3, R F(P1, P2, P3)>
+R IgnoreHandlerData4(void *p1, const void *hd, P2 p2, P3 p3) {
+ UPB_UNUSED(hd);
+ return F(static_cast<P1>(p1), p2, p3);
+}
+
+template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4)>
+R IgnoreHandlerData5(void *p1, const void *hd, P2 p2, P3 p3, P4 p4) {
+ UPB_UNUSED(hd);
+ return F(static_cast<P1>(p1), p2, p3, p4);
+}
+
+template <class R, class P1, R F(P1, const char*, size_t)>
+R IgnoreHandlerDataIgnoreHandle(void *p1, const void *hd, const char *p2,
+ size_t p3, const BufferHandle *handle) {
+ UPB_UNUSED(hd);
+ UPB_UNUSED(handle);
+ return F(static_cast<P1>(p1), p2, p3);
+}
+
+/* Function that casts the handler data parameter. */
+template <class R, class P1, class P2, R F(P1, P2)>
+R CastHandlerData2(void *c, const void *hd) {
+ return F(static_cast<P1>(c), static_cast<P2>(hd));
+}
+
+template <class R, class P1, class P2, class P3Wrapper, class P3Wrapped,
+ R F(P1, P2, P3Wrapped)>
+R CastHandlerData3(void *c, const void *hd, P3Wrapper p3) {
+ return F(static_cast<P1>(c), static_cast<P2>(hd), p3);
+}
+
+template <class R, class P1, class P2, class P3, class P4, class P5,
+ R F(P1, P2, P3, P4, P5)>
+R CastHandlerData5(void *c, const void *hd, P3 p3, P4 p4, P5 p5) {
+ return F(static_cast<P1>(c), static_cast<P2>(hd), p3, p4, p5);
+}
+
+template <class R, class P1, class P2, R F(P1, P2, const char *, size_t)>
+R CastHandlerDataIgnoreHandle(void *c, const void *hd, const char *p3,
+ size_t p4, const BufferHandle *handle) {
+ UPB_UNUSED(handle);
+ return F(static_cast<P1>(c), static_cast<P2>(hd), p3, p4);
+}
+
+/* For unbound functions, ignore the handler data. */
+template <class R, class P1, R F(P1), class I, class T>
+struct ConvertParams<Func1<R, P1, F, I>, T> {
+ typedef Func2<R, void *, const void *, IgnoreHandlerData2<R, P1, F>, I> Func;
+};
+
+template <class R, class P1, class P2, R F(P1, P2), class I,
+ class R2, class P1_2, class P2_2, class P3_2>
+struct ConvertParams<Func2<R, P1, P2, F, I>,
+ R2 (*)(P1_2, P2_2, P3_2)> {
+ typedef Func3<R, void *, const void *, P3_2,
+ IgnoreHandlerData3<R, P1, P3_2, P2, F>, I> Func;
+};
+
+/* For StringBuffer only; this ignores both the handler data and the
+ * BufferHandle. */
+template <class R, class P1, R F(P1, const char *, size_t), class I, class T>
+struct ConvertParams<Func3<R, P1, const char *, size_t, F, I>, T> {
+ typedef Func5<R, void *, const void *, const char *, size_t,
+ const BufferHandle *, IgnoreHandlerDataIgnoreHandle<R, P1, F>,
+ I> Func;
+};
+
+template <class R, class P1, class P2, class P3, class P4, R F(P1, P2, P3, P4),
+ class I, class T>
+struct ConvertParams<Func4<R, P1, P2, P3, P4, F, I>, T> {
+ typedef Func5<R, void *, const void *, P2, P3, P4,
+ IgnoreHandlerData5<R, P1, P2, P3, P4, F>, I> Func;
+};
+
+/* For bound functions, cast the handler data. */
+template <class R, class P1, class P2, R F(P1, P2), class I, class T>
+struct ConvertParams<BoundFunc2<R, P1, P2, F, I>, T> {
+ typedef Func2<R, void *, const void *, CastHandlerData2<R, P1, P2, F>, I>
+ Func;
+};
+
+template <class R, class P1, class P2, class P3, R F(P1, P2, P3), class I,
+ class R2, class P1_2, class P2_2, class P3_2>
+struct ConvertParams<BoundFunc3<R, P1, P2, P3, F, I>,
+ R2 (*)(P1_2, P2_2, P3_2)> {
+ typedef Func3<R, void *, const void *, P3_2,
+ CastHandlerData3<R, P1, P2, P3_2, P3, F>, I> Func;
+};
+
+/* For StringBuffer only; this ignores the BufferHandle. */
+template <class R, class P1, class P2, R F(P1, P2, const char *, size_t),
+ class I, class T>
+struct ConvertParams<BoundFunc4<R, P1, P2, const char *, size_t, F, I>, T> {
+ typedef Func5<R, void *, const void *, const char *, size_t,
+ const BufferHandle *, CastHandlerDataIgnoreHandle<R, P1, P2, F>,
+ I> Func;
+};
+
+template <class R, class P1, class P2, class P3, class P4, class P5,
+ R F(P1, P2, P3, P4, P5), class I, class T>
+struct ConvertParams<BoundFunc5<R, P1, P2, P3, P4, P5, F, I>, T> {
+ typedef Func5<R, void *, const void *, P3, P4, P5,
+ CastHandlerData5<R, P1, P2, P3, P4, P5, F>, I> Func;
+};
+
+/* utype/ltype are upper/lower-case, ctype is canonical C type, vtype is
+ * variant C type. */
+#define TYPE_METHODS(utype, ltype, ctype, vtype) \
+ template <> struct CanonicalType<vtype> { \
+ typedef ctype Type; \
+ }; \
+ template <> \
+ inline bool Handlers::SetValueHandler<vtype>( \
+ const FieldDef *f, \
+ const Handlers::utype ## Handler& handler) { \
+ UPB_ASSERT(!handler.registered_); \
+ handler.AddCleanup(this); \
+ handler.registered_ = true; \
+ return upb_handlers_set##ltype(this, f, handler.handler_, &handler.attr_); \
+ } \
+
+TYPE_METHODS(Double, double, double, double)
+TYPE_METHODS(Float, float, float, float)
+TYPE_METHODS(UInt64, uint64, uint64_t, UPB_UINT64_T)
+TYPE_METHODS(UInt32, uint32, uint32_t, UPB_UINT32_T)
+TYPE_METHODS(Int64, int64, int64_t, UPB_INT64_T)
+TYPE_METHODS(Int32, int32, int32_t, UPB_INT32_T)
+TYPE_METHODS(Bool, bool, bool, bool)
+
+#ifdef UPB_TWO_32BIT_TYPES
+TYPE_METHODS(Int32, int32, int32_t, UPB_INT32ALT_T)
+TYPE_METHODS(UInt32, uint32, uint32_t, UPB_UINT32ALT_T)
+#endif
+
+#ifdef UPB_TWO_64BIT_TYPES
+TYPE_METHODS(Int64, int64, int64_t, UPB_INT64ALT_T)
+TYPE_METHODS(UInt64, uint64, uint64_t, UPB_UINT64ALT_T)
+#endif
+#undef TYPE_METHODS
+
+template <> struct CanonicalType<Status*> {
+ typedef Status* Type;
+};
+
+/* Type methods that are only one-per-canonical-type and not
+ * one-per-cvariant. */
+
+#define TYPE_METHODS(utype, ctype) \
+ inline bool Handlers::Set##utype##Handler(const FieldDef *f, \
+ const utype##Handler &h) { \
+ return SetValueHandler<ctype>(f, h); \
+ } \
+
+TYPE_METHODS(Double, double)
+TYPE_METHODS(Float, float)
+TYPE_METHODS(UInt64, uint64_t)
+TYPE_METHODS(UInt32, uint32_t)
+TYPE_METHODS(Int64, int64_t)
+TYPE_METHODS(Int32, int32_t)
+TYPE_METHODS(Bool, bool)
+#undef TYPE_METHODS
+
+template <class F> struct ReturnOf;
+
+template <class R, class P1, class P2>
+struct ReturnOf<R (*)(P1, P2)> {
+ typedef R Return;
+};
+
+template <class R, class P1, class P2, class P3>
+struct ReturnOf<R (*)(P1, P2, P3)> {
+ typedef R Return;
+};
+
+template <class R, class P1, class P2, class P3, class P4>
+struct ReturnOf<R (*)(P1, P2, P3, P4)> {
+ typedef R Return;
+};
+
+template <class R, class P1, class P2, class P3, class P4, class P5>
+struct ReturnOf<R (*)(P1, P2, P3, P4, P5)> {
+ typedef R Return;
+};
+
+template<class T> const void *UniquePtrForType() {
+ static const char ch = 0;
+ return &ch;
+}
+
+template <class T>
+template <class F>
+inline Handler<T>::Handler(F func)
+ : registered_(false),
+ cleanup_data_(func.GetData()),
+ cleanup_func_(func.GetCleanup()) {
+ upb_handlerattr_sethandlerdata(&attr_, func.GetData());
+ typedef typename ReturnOf<T>::Return Return;
+ typedef typename ConvertParams<F, T>::Func ConvertedParamsFunc;
+ typedef typename MaybeWrapReturn<ConvertedParamsFunc, Return>::Func
+ ReturnWrappedFunc;
+ handler_ = ReturnWrappedFunc().Call;
+
+ /* Set attributes based on what templates can statically tell us about the
+ * user's function. */
+
+ /* If the original function returns void, then we know that we wrapped it to
+ * always return ok. */
+ bool always_ok = is_same<typename F::FuncInfo::Return, void>::value;
+ attr_.SetAlwaysOk(always_ok);
+
+ /* Closure parameter and return type. */
+ attr_.SetClosureType(UniquePtrForType<typename F::FuncInfo::Closure>());
+
+ /* We use the closure type (from the first parameter) if the return type is
+ * void or bool, since these are the two cases we wrap to return the closure's
+ * type anyway.
+ *
+ * This is all nonsense for non START* handlers, but it doesn't matter because
+ * in that case the value will be ignored. */
+ typedef typename FirstUnlessVoidOrBool<typename F::FuncInfo::Return,
+ typename F::FuncInfo::Closure>::value
+ EffectiveReturn;
+ attr_.SetReturnClosureType(UniquePtrForType<EffectiveReturn>());
+}
+
+template <class T>
+inline Handler<T>::~Handler() {
+ UPB_ASSERT(registered_);
+}
+
+inline HandlerAttributes::HandlerAttributes() { upb_handlerattr_init(this); }
+inline HandlerAttributes::~HandlerAttributes() { upb_handlerattr_uninit(this); }
+inline bool HandlerAttributes::SetHandlerData(const void *hd) {
+ return upb_handlerattr_sethandlerdata(this, hd);
+}
+inline const void* HandlerAttributes::handler_data() const {
+ return upb_handlerattr_handlerdata(this);
+}
+inline bool HandlerAttributes::SetClosureType(const void *type) {
+ return upb_handlerattr_setclosuretype(this, type);
+}
+inline const void* HandlerAttributes::closure_type() const {
+ return upb_handlerattr_closuretype(this);
+}
+inline bool HandlerAttributes::SetReturnClosureType(const void *type) {
+ return upb_handlerattr_setreturnclosuretype(this, type);
+}
+inline const void* HandlerAttributes::return_closure_type() const {
+ return upb_handlerattr_returnclosuretype(this);
+}
+inline bool HandlerAttributes::SetAlwaysOk(bool always_ok) {
+ return upb_handlerattr_setalwaysok(this, always_ok);
+}
+inline bool HandlerAttributes::always_ok() const {
+ return upb_handlerattr_alwaysok(this);
+}
+
+inline BufferHandle::BufferHandle() { upb_bufhandle_init(this); }
+inline BufferHandle::~BufferHandle() { upb_bufhandle_uninit(this); }
+inline const char* BufferHandle::buffer() const {
+ return upb_bufhandle_buf(this);
+}
+inline size_t BufferHandle::object_offset() const {
+ return upb_bufhandle_objofs(this);
+}
+inline void BufferHandle::SetBuffer(const char* buf, size_t ofs) {
+ upb_bufhandle_setbuf(this, buf, ofs);
+}
+template <class T>
+void BufferHandle::SetAttachedObject(const T* obj) {
+ upb_bufhandle_setobj(this, obj, UniquePtrForType<T>());
+}
+template <class T>
+const T* BufferHandle::GetAttachedObject() const {
+ return upb_bufhandle_objtype(this) == UniquePtrForType<T>()
+ ? static_cast<const T *>(upb_bufhandle_obj(this))
+ : NULL;
+}
+
+inline reffed_ptr<Handlers> Handlers::New(const MessageDef *m) {
+ upb_handlers *h = upb_handlers_new(m, &h);
+ return reffed_ptr<Handlers>(h, &h);
+}
+inline reffed_ptr<const Handlers> Handlers::NewFrozen(
+ const MessageDef *m, upb_handlers_callback *callback,
+ const void *closure) {
+ const upb_handlers *h = upb_handlers_newfrozen(m, &h, callback, closure);
+ return reffed_ptr<const Handlers>(h, &h);
+}
+inline const Status* Handlers::status() {
+ return upb_handlers_status(this);
+}
+inline void Handlers::ClearError() {
+ return upb_handlers_clearerr(this);
+}
+inline bool Handlers::Freeze(Status *s) {
+ upb::Handlers* h = this;
+ return upb_handlers_freeze(&h, 1, s);
+}
+inline bool Handlers::Freeze(Handlers *const *handlers, int n, Status *s) {
+ return upb_handlers_freeze(handlers, n, s);
+}
+inline bool Handlers::Freeze(const std::vector<Handlers*>& h, Status* status) {
+ return upb_handlers_freeze((Handlers* const*)&h[0], h.size(), status);
+}
+inline const MessageDef *Handlers::message_def() const {
+ return upb_handlers_msgdef(this);
+}
+inline bool Handlers::AddCleanup(void *p, upb_handlerfree *func) {
+ return upb_handlers_addcleanup(this, p, func);
+}
+inline bool Handlers::SetStartMessageHandler(
+ const Handlers::StartMessageHandler &handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setstartmsg(this, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetEndMessageHandler(
+ const Handlers::EndMessageHandler &handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setendmsg(this, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetStartStringHandler(const FieldDef *f,
+ const StartStringHandler &handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setstartstr(this, f, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetEndStringHandler(const FieldDef *f,
+ const EndFieldHandler &handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setendstr(this, f, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetStringHandler(const FieldDef *f,
+ const StringHandler& handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setstring(this, f, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetStartSequenceHandler(
+ const FieldDef *f, const StartFieldHandler &handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setstartseq(this, f, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetStartSubMessageHandler(
+ const FieldDef *f, const StartFieldHandler &handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setstartsubmsg(this, f, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetEndSubMessageHandler(const FieldDef *f,
+ const EndFieldHandler &handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setendsubmsg(this, f, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetEndSequenceHandler(const FieldDef *f,
+ const EndFieldHandler &handler) {
+ UPB_ASSERT(!handler.registered_);
+ handler.registered_ = true;
+ handler.AddCleanup(this);
+ return upb_handlers_setendseq(this, f, handler.handler_, &handler.attr_);
+}
+inline bool Handlers::SetSubHandlers(const FieldDef *f, const Handlers *sub) {
+ return upb_handlers_setsubhandlers(this, f, sub);
+}
+inline const Handlers *Handlers::GetSubHandlers(const FieldDef *f) const {
+ return upb_handlers_getsubhandlers(this, f);
+}
+inline const Handlers *Handlers::GetSubHandlers(Handlers::Selector sel) const {
+ return upb_handlers_getsubhandlers_sel(this, sel);
+}
+inline bool Handlers::GetSelector(const FieldDef *f, Handlers::Type type,
+ Handlers::Selector *s) {
+ return upb_handlers_getselector(f, type, s);
+}
+inline Handlers::Selector Handlers::GetEndSelector(Handlers::Selector start) {
+ return upb_handlers_getendselector(start);
+}
+inline Handlers::GenericFunction *Handlers::GetHandler(
+ Handlers::Selector selector) {
+ return upb_handlers_gethandler(this, selector);
+}
+inline const void *Handlers::GetHandlerData(Handlers::Selector selector) {
+ return upb_handlers_gethandlerdata(this, selector);
+}
+
+inline BytesHandler::BytesHandler() {
+ upb_byteshandler_init(this);
+}
+
+inline BytesHandler::~BytesHandler() {}
+
+} /* namespace upb */
+
+#endif /* __cplusplus */
+
+
+#undef UPB_TWO_32BIT_TYPES
+#undef UPB_TWO_64BIT_TYPES
+#undef UPB_INT32_T
+#undef UPB_UINT32_T
+#undef UPB_INT32ALT_T
+#undef UPB_UINT32ALT_T
+#undef UPB_INT64_T
+#undef UPB_UINT64_T
+#undef UPB_INT64ALT_T
+#undef UPB_UINT64ALT_T
+
+#endif /* UPB_HANDLERS_INL_H_ */
+
+#endif /* UPB_HANDLERS_H */
+/*
+** upb::Sink (upb_sink)
+** upb::BytesSink (upb_bytessink)
+**
+** A upb_sink is an object that binds a upb_handlers object to some runtime
+** state. It is the object that can actually receive data via the upb_handlers
+** interface.
+**
+** Unlike upb_def and upb_handlers, upb_sink is never frozen, immutable, or
+** thread-safe. You can create as many of them as you want, but each one may
+** only be used in a single thread at a time.
+**
+** If we compare with class-based OOP, a you can think of a upb_def as an
+** abstract base class, a upb_handlers as a concrete derived class, and a
+** upb_sink as an object (class instance).
+*/
+
+#ifndef UPB_SINK_H
+#define UPB_SINK_H
+
+
+#ifdef __cplusplus
+namespace upb {
+class BufferSink;
+class BufferSource;
+class BytesSink;
+class Sink;
+}
+#endif
+
+UPB_DECLARE_TYPE(upb::BufferSink, upb_bufsink)
+UPB_DECLARE_TYPE(upb::BufferSource, upb_bufsrc)
+UPB_DECLARE_TYPE(upb::BytesSink, upb_bytessink)
+UPB_DECLARE_TYPE(upb::Sink, upb_sink)
+
+#ifdef __cplusplus
+
+/* A upb::Sink is an object that binds a upb::Handlers object to some runtime
+ * state. It represents an endpoint to which data can be sent.
+ *
+ * TODO(haberman): right now all of these functions take selectors. Should they
+ * take selectorbase instead?
+ *
+ * ie. instead of calling:
+ * sink->StartString(FOO_FIELD_START_STRING, ...)
+ * a selector base would let you say:
+ * sink->StartString(FOO_FIELD, ...)
+ *
+ * This would make call sites a little nicer and require emitting fewer selector
+ * definitions in .h files.
+ *
+ * But the current scheme has the benefit that you can retrieve a function
+ * pointer for any handler with handlers->GetHandler(selector), without having
+ * to have a separate GetHandler() function for each handler type. The JIT
+ * compiler uses this. To accommodate we'd have to expose a separate
+ * GetHandler() for every handler type.
+ *
+ * Also to ponder: selectors right now are independent of a specific Handlers
+ * instance. In other words, they allocate a number to every possible handler
+ * that *could* be registered, without knowing anything about what handlers
+ * *are* registered. That means that using selectors as table offsets prohibits
+ * us from compacting the handler table at Freeze() time. If the table is very
+ * sparse, this could be wasteful.
+ *
+ * Having another selector-like thing that is specific to a Handlers instance
+ * would allow this compacting, but then it would be impossible to write code
+ * ahead-of-time that can be bound to any Handlers instance at runtime. For
+ * example, a .proto file parser written as straight C will not know what
+ * Handlers it will be bound to, so when it calls sink->StartString() what
+ * selector will it pass? It needs a selector like we have today, that is
+ * independent of any particular upb::Handlers.
+ *
+ * Is there a way then to allow Handlers table compaction? */
+class upb::Sink {
+ public:
+ /* Constructor with no initialization; must be Reset() before use. */
+ Sink() {}
+
+ /* Constructs a new sink for the given frozen handlers and closure.
+ *
+ * TODO: once the Handlers know the expected closure type, verify that T
+ * matches it. */
+ template <class T> Sink(const Handlers* handlers, T* closure);
+
+ /* Resets the value of the sink. */
+ template <class T> void Reset(const Handlers* handlers, T* closure);
+
+ /* Returns the top-level object that is bound to this sink.
+ *
+ * TODO: once the Handlers know the expected closure type, verify that T
+ * matches it. */
+ template <class T> T* GetObject() const;
+
+ /* Functions for pushing data into the sink.
+ *
+ * These return false if processing should stop (either due to error or just
+ * to suspend).
+ *
+ * These may not be called from within one of the same sink's handlers (in
+ * other words, handlers are not re-entrant). */
+
+ /* Should be called at the start and end of every message; both the top-level
+ * message and submessages. This means that submessages should use the
+ * following sequence:
+ * sink->StartSubMessage(startsubmsg_selector);
+ * sink->StartMessage();
+ * // ...
+ * sink->EndMessage(&status);
+ * sink->EndSubMessage(endsubmsg_selector); */
+ bool StartMessage();
+ bool EndMessage(Status* status);
+
+ /* Putting of individual values. These work for both repeated and
+ * non-repeated fields, but for repeated fields you must wrap them in
+ * calls to StartSequence()/EndSequence(). */
+ bool PutInt32(Handlers::Selector s, int32_t val);
+ bool PutInt64(Handlers::Selector s, int64_t val);
+ bool PutUInt32(Handlers::Selector s, uint32_t val);
+ bool PutUInt64(Handlers::Selector s, uint64_t val);
+ bool PutFloat(Handlers::Selector s, float val);
+ bool PutDouble(Handlers::Selector s, double val);
+ bool PutBool(Handlers::Selector s, bool val);
+
+ /* Putting of string/bytes values. Each string can consist of zero or more
+ * non-contiguous buffers of data.
+ *
+ * For StartString(), the function will write a sink for the string to "sub."
+ * The sub-sink must be used for any/all PutStringBuffer() calls. */
+ bool StartString(Handlers::Selector s, size_t size_hint, Sink* sub);
+ size_t PutStringBuffer(Handlers::Selector s, const char *buf, size_t len,
+ const BufferHandle *handle);
+ bool EndString(Handlers::Selector s);
+
+ /* For submessage fields.
+ *
+ * For StartSubMessage(), the function will write a sink for the string to
+ * "sub." The sub-sink must be used for any/all handlers called within the
+ * submessage. */
+ bool StartSubMessage(Handlers::Selector s, Sink* sub);
+ bool EndSubMessage(Handlers::Selector s);
+
+ /* For repeated fields of any type, the sequence of values must be wrapped in
+ * these calls.
+ *
+ * For StartSequence(), the function will write a sink for the string to
+ * "sub." The sub-sink must be used for any/all handlers called within the
+ * sequence. */
+ bool StartSequence(Handlers::Selector s, Sink* sub);
+ bool EndSequence(Handlers::Selector s);
+
+ /* Copy and assign specifically allowed.
+ * We don't even bother making these members private because so many
+ * functions need them and this is mainly just a dumb data container anyway.
+ */
+#else
+struct upb_sink {
+#endif
+ const upb_handlers *handlers;
+ void *closure;
+};
+
+#ifdef __cplusplus
+class upb::BytesSink {
+ public:
+ BytesSink() {}
+
+ /* Constructs a new sink for the given frozen handlers and closure.
+ *
+ * TODO(haberman): once the Handlers know the expected closure type, verify
+ * that T matches it. */
+ template <class T> BytesSink(const BytesHandler* handler, T* closure);
+
+ /* Resets the value of the sink. */
+ template <class T> void Reset(const BytesHandler* handler, T* closure);
+
+ bool Start(size_t size_hint, void **subc);
+ size_t PutBuffer(void *subc, const char *buf, size_t len,
+ const BufferHandle *handle);
+ bool End();
+#else
+struct upb_bytessink {
+#endif
+ const upb_byteshandler *handler;
+ void *closure;
+};
+
+#ifdef __cplusplus
+
+/* A class for pushing a flat buffer of data to a BytesSink.
+ * You can construct an instance of this to get a resumable source,
+ * or just call the static PutBuffer() to do a non-resumable push all in one
+ * go. */
+class upb::BufferSource {
+ public:
+ BufferSource();
+ BufferSource(const char* buf, size_t len, BytesSink* sink);
+
+ /* Returns true if the entire buffer was pushed successfully. Otherwise the
+ * next call to PutNext() will resume where the previous one left off.
+ * TODO(haberman): implement this. */
+ bool PutNext();
+
+ /* A static version; with this version is it not possible to resume in the
+ * case of failure or a partially-consumed buffer. */
+ static bool PutBuffer(const char* buf, size_t len, BytesSink* sink);
+
+ template <class T> static bool PutBuffer(const T& str, BytesSink* sink) {
+ return PutBuffer(str.c_str(), str.size(), sink);
+ }
+#else
+struct upb_bufsrc {
+ char dummy;
+#endif
+};
+
+UPB_BEGIN_EXTERN_C
+
+/* A class for accumulating output string data in a flat buffer. */
+
+upb_bufsink *upb_bufsink_new(upb_env *env);
+void upb_bufsink_free(upb_bufsink *sink);
+upb_bytessink *upb_bufsink_sink(upb_bufsink *sink);
+const char *upb_bufsink_getdata(const upb_bufsink *sink, size_t *len);
+
+/* Inline definitions. */
+
+UPB_INLINE void upb_bytessink_reset(upb_bytessink *s, const upb_byteshandler *h,
+ void *closure) {
+ s->handler = h;
+ s->closure = closure;
+}
+
+UPB_INLINE bool upb_bytessink_start(upb_bytessink *s, size_t size_hint,
+ void **subc) {
+ typedef upb_startstr_handlerfunc func;
+ func *start;
+ *subc = s->closure;
+ if (!s->handler) return true;
+ start = (func *)s->handler->table[UPB_STARTSTR_SELECTOR].func;
+
+ if (!start) return true;
+ *subc = start(s->closure, upb_handlerattr_handlerdata(
+ &s->handler->table[UPB_STARTSTR_SELECTOR].attr),
+ size_hint);
+ return *subc != NULL;
+}
+
+UPB_INLINE size_t upb_bytessink_putbuf(upb_bytessink *s, void *subc,
+ const char *buf, size_t size,
+ const upb_bufhandle* handle) {
+ typedef upb_string_handlerfunc func;
+ func *putbuf;
+ if (!s->handler) return true;
+ putbuf = (func *)s->handler->table[UPB_STRING_SELECTOR].func;
+
+ if (!putbuf) return true;
+ return putbuf(subc, upb_handlerattr_handlerdata(
+ &s->handler->table[UPB_STRING_SELECTOR].attr),
+ buf, size, handle);
+}
+
+UPB_INLINE bool upb_bytessink_end(upb_bytessink *s) {
+ typedef upb_endfield_handlerfunc func;
+ func *end;
+ if (!s->handler) return true;
+ end = (func *)s->handler->table[UPB_ENDSTR_SELECTOR].func;
+
+ if (!end) return true;
+ return end(s->closure,
+ upb_handlerattr_handlerdata(
+ &s->handler->table[UPB_ENDSTR_SELECTOR].attr));
+}
+
+bool upb_bufsrc_putbuf(const char *buf, size_t len, upb_bytessink *sink);
+
+#define PUTVAL(type, ctype) \
+ UPB_INLINE bool upb_sink_put##type(upb_sink *s, upb_selector_t sel, \
+ ctype val) { \
+ typedef upb_##type##_handlerfunc functype; \
+ functype *func; \
+ const void *hd; \
+ if (!s->handlers) return true; \
+ func = (functype *)upb_handlers_gethandler(s->handlers, sel); \
+ if (!func) return true; \
+ hd = upb_handlers_gethandlerdata(s->handlers, sel); \
+ return func(s->closure, hd, val); \
+ }
+
+PUTVAL(int32, int32_t)
+PUTVAL(int64, int64_t)
+PUTVAL(uint32, uint32_t)
+PUTVAL(uint64, uint64_t)
+PUTVAL(float, float)
+PUTVAL(double, double)
+PUTVAL(bool, bool)
+#undef PUTVAL
+
+UPB_INLINE void upb_sink_reset(upb_sink *s, const upb_handlers *h, void *c) {
+ s->handlers = h;
+ s->closure = c;
+}
+
+UPB_INLINE size_t upb_sink_putstring(upb_sink *s, upb_selector_t sel,
+ const char *buf, size_t n,
+ const upb_bufhandle *handle) {
+ typedef upb_string_handlerfunc func;
+ func *handler;
+ const void *hd;
+ if (!s->handlers) return n;
+ handler = (func *)upb_handlers_gethandler(s->handlers, sel);
+
+ if (!handler) return n;
+ hd = upb_handlers_gethandlerdata(s->handlers, sel);
+ return handler(s->closure, hd, buf, n, handle);
+}
+
+UPB_INLINE bool upb_sink_startmsg(upb_sink *s) {
+ typedef upb_startmsg_handlerfunc func;
+ func *startmsg;
+ const void *hd;
+ if (!s->handlers) return true;
+ startmsg = (func*)upb_handlers_gethandler(s->handlers, UPB_STARTMSG_SELECTOR);
+
+ if (!startmsg) return true;
+ hd = upb_handlers_gethandlerdata(s->handlers, UPB_STARTMSG_SELECTOR);
+ return startmsg(s->closure, hd);
+}
+
+UPB_INLINE bool upb_sink_endmsg(upb_sink *s, upb_status *status) {
+ typedef upb_endmsg_handlerfunc func;
+ func *endmsg;
+ const void *hd;
+ if (!s->handlers) return true;
+ endmsg = (func *)upb_handlers_gethandler(s->handlers, UPB_ENDMSG_SELECTOR);
+
+ if (!endmsg) return true;
+ hd = upb_handlers_gethandlerdata(s->handlers, UPB_ENDMSG_SELECTOR);
+ return endmsg(s->closure, hd, status);
+}
+
+UPB_INLINE bool upb_sink_startseq(upb_sink *s, upb_selector_t sel,
+ upb_sink *sub) {
+ typedef upb_startfield_handlerfunc func;
+ func *startseq;
+ const void *hd;
+ sub->closure = s->closure;
+ sub->handlers = s->handlers;
+ if (!s->handlers) return true;
+ startseq = (func*)upb_handlers_gethandler(s->handlers, sel);
+
+ if (!startseq) return true;
+ hd = upb_handlers_gethandlerdata(s->handlers, sel);
+ sub->closure = startseq(s->closure, hd);
+ return sub->closure ? true : false;
+}
+
+UPB_INLINE bool upb_sink_endseq(upb_sink *s, upb_selector_t sel) {
+ typedef upb_endfield_handlerfunc func;
+ func *endseq;
+ const void *hd;
+ if (!s->handlers) return true;
+ endseq = (func*)upb_handlers_gethandler(s->handlers, sel);
+
+ if (!endseq) return true;
+ hd = upb_handlers_gethandlerdata(s->handlers, sel);
+ return endseq(s->closure, hd);
+}
+
+UPB_INLINE bool upb_sink_startstr(upb_sink *s, upb_selector_t sel,
+ size_t size_hint, upb_sink *sub) {
+ typedef upb_startstr_handlerfunc func;
+ func *startstr;
+ const void *hd;
+ sub->closure = s->closure;
+ sub->handlers = s->handlers;
+ if (!s->handlers) return true;
+ startstr = (func*)upb_handlers_gethandler(s->handlers, sel);
+
+ if (!startstr) return true;
+ hd = upb_handlers_gethandlerdata(s->handlers, sel);
+ sub->closure = startstr(s->closure, hd, size_hint);
+ return sub->closure ? true : false;
+}
+
+UPB_INLINE bool upb_sink_endstr(upb_sink *s, upb_selector_t sel) {
+ typedef upb_endfield_handlerfunc func;
+ func *endstr;
+ const void *hd;
+ if (!s->handlers) return true;
+ endstr = (func*)upb_handlers_gethandler(s->handlers, sel);
+
+ if (!endstr) return true;
+ hd = upb_handlers_gethandlerdata(s->handlers, sel);
+ return endstr(s->closure, hd);
+}
+
+UPB_INLINE bool upb_sink_startsubmsg(upb_sink *s, upb_selector_t sel,
+ upb_sink *sub) {
+ typedef upb_startfield_handlerfunc func;
+ func *startsubmsg;
+ const void *hd;
+ sub->closure = s->closure;
+ if (!s->handlers) {
+ sub->handlers = NULL;
+ return true;
+ }
+ sub->handlers = upb_handlers_getsubhandlers_sel(s->handlers, sel);
+ startsubmsg = (func*)upb_handlers_gethandler(s->handlers, sel);
+
+ if (!startsubmsg) return true;
+ hd = upb_handlers_gethandlerdata(s->handlers, sel);
+ sub->closure = startsubmsg(s->closure, hd);
+ return sub->closure ? true : false;
+}
+
+UPB_INLINE bool upb_sink_endsubmsg(upb_sink *s, upb_selector_t sel) {
+ typedef upb_endfield_handlerfunc func;
+ func *endsubmsg;
+ const void *hd;
+ if (!s->handlers) return true;
+ endsubmsg = (func*)upb_handlers_gethandler(s->handlers, sel);
+
+ if (!endsubmsg) return s->closure;
+ hd = upb_handlers_gethandlerdata(s->handlers, sel);
+ return endsubmsg(s->closure, hd);
+}
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+namespace upb {
+
+template <class T> Sink::Sink(const Handlers* handlers, T* closure) {
+ upb_sink_reset(this, handlers, closure);
+}
+template <class T>
+inline void Sink::Reset(const Handlers* handlers, T* closure) {
+ upb_sink_reset(this, handlers, closure);
+}
+inline bool Sink::StartMessage() {
+ return upb_sink_startmsg(this);
+}
+inline bool Sink::EndMessage(Status* status) {
+ return upb_sink_endmsg(this, status);
+}
+inline bool Sink::PutInt32(Handlers::Selector sel, int32_t val) {
+ return upb_sink_putint32(this, sel, val);
+}
+inline bool Sink::PutInt64(Handlers::Selector sel, int64_t val) {
+ return upb_sink_putint64(this, sel, val);
+}
+inline bool Sink::PutUInt32(Handlers::Selector sel, uint32_t val) {
+ return upb_sink_putuint32(this, sel, val);
+}
+inline bool Sink::PutUInt64(Handlers::Selector sel, uint64_t val) {
+ return upb_sink_putuint64(this, sel, val);
+}
+inline bool Sink::PutFloat(Handlers::Selector sel, float val) {
+ return upb_sink_putfloat(this, sel, val);
+}
+inline bool Sink::PutDouble(Handlers::Selector sel, double val) {
+ return upb_sink_putdouble(this, sel, val);
+}
+inline bool Sink::PutBool(Handlers::Selector sel, bool val) {
+ return upb_sink_putbool(this, sel, val);
+}
+inline bool Sink::StartString(Handlers::Selector sel, size_t size_hint,
+ Sink *sub) {
+ return upb_sink_startstr(this, sel, size_hint, sub);
+}
+inline size_t Sink::PutStringBuffer(Handlers::Selector sel, const char *buf,
+ size_t len, const BufferHandle* handle) {
+ return upb_sink_putstring(this, sel, buf, len, handle);
+}
+inline bool Sink::EndString(Handlers::Selector sel) {
+ return upb_sink_endstr(this, sel);
+}
+inline bool Sink::StartSubMessage(Handlers::Selector sel, Sink* sub) {
+ return upb_sink_startsubmsg(this, sel, sub);
+}
+inline bool Sink::EndSubMessage(Handlers::Selector sel) {
+ return upb_sink_endsubmsg(this, sel);
+}
+inline bool Sink::StartSequence(Handlers::Selector sel, Sink* sub) {
+ return upb_sink_startseq(this, sel, sub);
+}
+inline bool Sink::EndSequence(Handlers::Selector sel) {
+ return upb_sink_endseq(this, sel);
+}
+
+template <class T>
+BytesSink::BytesSink(const BytesHandler* handler, T* closure) {
+ Reset(handler, closure);
+}
+
+template <class T>
+void BytesSink::Reset(const BytesHandler *handler, T *closure) {
+ upb_bytessink_reset(this, handler, closure);
+}
+inline bool BytesSink::Start(size_t size_hint, void **subc) {
+ return upb_bytessink_start(this, size_hint, subc);
+}
+inline size_t BytesSink::PutBuffer(void *subc, const char *buf, size_t len,
+ const BufferHandle *handle) {
+ return upb_bytessink_putbuf(this, subc, buf, len, handle);
+}
+inline bool BytesSink::End() {
+ return upb_bytessink_end(this);
+}
+
+inline bool BufferSource::PutBuffer(const char *buf, size_t len,
+ BytesSink *sink) {
+ return upb_bufsrc_putbuf(buf, len, sink);
+}
+
+} /* namespace upb */
+#endif
+
+#endif
+/*
+** upb::Message is a representation for protobuf messages.
+**
+** However it differs from other common representations like
+** google::protobuf::Message in one key way: it does not prescribe any
+** ownership between messages and submessages, and it relies on the
+** client to delete each message/submessage/array/map at the appropriate
+** time.
+**
+** A client can access a upb::Message without knowing anything about
+** ownership semantics, but to create or mutate a message a user needs
+** to implement the memory management themselves.
+**
+** Currently all messages, arrays, and maps store a upb_alloc* internally.
+** Mutating operations use this when they require dynamically-allocated
+** memory. We could potentially eliminate this size overhead later by
+** letting the user flip a bit on the factory that prevents this from
+** being stored. The user would then need to use separate functions where
+** the upb_alloc* is passed explicitly. However for handlers to populate
+** such structures, they would need a place to store this upb_alloc* during
+** parsing; upb_handlers don't currently have a good way to accommodate this.
+**
+** TODO: UTF-8 checking?
+**/
+
+#ifndef UPB_MSG_H_
+#define UPB_MSG_H_
+
+
+#ifdef __cplusplus
+
+namespace upb {
+class Array;
+class Map;
+class MapIterator;
+class MessageFactory;
+class MessageLayout;
+class Visitor;
+class VisitorPlan;
+}
+
+#endif
+
+UPB_DECLARE_TYPE(upb::MessageFactory, upb_msgfactory)
+UPB_DECLARE_TYPE(upb::MessageLayout, upb_msglayout)
+UPB_DECLARE_TYPE(upb::Array, upb_array)
+UPB_DECLARE_TYPE(upb::Map, upb_map)
+UPB_DECLARE_TYPE(upb::MapIterator, upb_mapiter)
+UPB_DECLARE_TYPE(upb::Visitor, upb_visitor)
+UPB_DECLARE_TYPE(upb::VisitorPlan, upb_visitorplan)
+
+/* TODO(haberman): C++ accessors */
+
+UPB_BEGIN_EXTERN_C
+
+typedef void upb_msg;
+
+
+/** upb_msglayout *************************************************************/
+
+/* upb_msglayout represents the memory layout of a given upb_msgdef. You get
+ * instances of this from a upb_msgfactory, and the factory always owns the
+ * msglayout. */
+
+/* Gets the factory for this layout */
+upb_msgfactory *upb_msglayout_factory(const upb_msglayout *l);
+
+/* Get the msglayout for a submessage. This requires that this field is a
+ * submessage, ie. upb_fielddef_issubmsg(upb_msglayout_msgdef(l)) == true.
+ *
+ * Since map entry messages don't have layouts, if upb_fielddef_ismap(f) == true
+ * then this function will return the layout for the map's value. It requires
+ * that the value type of the map field is a submessage. */
+const upb_msglayout *upb_msglayout_sublayout(const upb_msglayout *l,
+ const upb_fielddef *f);
+
+/* Returns the msgdef for this msglayout. */
+const upb_msgdef *upb_msglayout_msgdef(const upb_msglayout *l);
+
+
+/** upb_visitor ***************************************************************/
+
+/* upb_visitor will visit all the fields of a message and its submessages. It
+ * uses a upb_visitorplan which you can obtain from a upb_msgfactory. */
+
+upb_visitor *upb_visitor_create(upb_env *e, const upb_visitorplan *vp,
+ upb_sink *output);
+bool upb_visitor_visitmsg(upb_visitor *v, const upb_msg *msg);
+
+
+/** upb_msgfactory ************************************************************/
+
+/* A upb_msgfactory contains a cache of upb_msglayout, upb_handlers, and
+ * upb_visitorplan objects. These are the objects necessary to represent,
+ * populate, and and visit upb_msg objects.
+ *
+ * These caches are all populated by upb_msgdef, and lazily created on demand.
+ */
+
+/* Creates and destroys a msgfactory, respectively. The messages for this
+ * msgfactory must come from |symtab| (which should outlive the msgfactory). */
+upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab);
+void upb_msgfactory_free(upb_msgfactory *f);
+
+const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f);
+
+/* The functions to get cached objects, lazily creating them on demand. These
+ * all require:
+ *
+ * - m is in upb_msgfactory_symtab(f)
+ * - upb_msgdef_mapentry(m) == false (since map messages can't have layouts).
+ *
+ * The returned objects will live for as long as the msgfactory does.
+ *
+ * TODO(haberman): consider making this thread-safe and take a const
+ * upb_msgfactory. */
+const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f,
+ const upb_msgdef *m);
+const upb_handlers *upb_msgfactory_getmergehandlers(upb_msgfactory *f,
+ const upb_msgdef *m);
+const upb_visitorplan *upb_msgfactory_getvisitorplan(upb_msgfactory *f,
+ const upb_handlers *h);
+
+
+/** upb_msgval ****************************************************************/
+
+/* A union representing all possible protobuf values. Used for generic get/set
+ * operations. */
+
+typedef union {
+ bool b;
+ float flt;
+ double dbl;
+ int32_t i32;
+ int64_t i64;
+ uint32_t u32;
+ uint64_t u64;
+ const upb_map* map;
+ const upb_msg* msg;
+ const upb_array* arr;
+ const void* ptr;
+ struct {
+ const char *ptr;
+ size_t len;
+ } str;
+} upb_msgval;
+
+#define ACCESSORS(name, membername, ctype) \
+ UPB_INLINE ctype upb_msgval_get ## name(upb_msgval v) { \
+ return v.membername; \
+ } \
+ UPB_INLINE void upb_msgval_set ## name(upb_msgval *v, ctype cval) { \
+ v->membername = cval; \
+ } \
+ UPB_INLINE upb_msgval upb_msgval_ ## name(ctype v) { \
+ upb_msgval ret; \
+ ret.membername = v; \
+ return ret; \
+ }
+
+ACCESSORS(bool, b, bool)
+ACCESSORS(float, flt, float)
+ACCESSORS(double, dbl, double)
+ACCESSORS(int32, i32, int32_t)
+ACCESSORS(int64, i64, int64_t)
+ACCESSORS(uint32, u32, uint32_t)
+ACCESSORS(uint64, u64, uint64_t)
+ACCESSORS(map, map, const upb_map*)
+ACCESSORS(msg, msg, const upb_msg*)
+ACCESSORS(ptr, ptr, const void*)
+ACCESSORS(arr, arr, const upb_array*)
+
+#undef ACCESSORS
+
+UPB_INLINE upb_msgval upb_msgval_str(const char *ptr, size_t len) {
+ upb_msgval ret;
+ ret.str.ptr = ptr;
+ ret.str.len = len;
+ return ret;
+}
+
+UPB_INLINE const char* upb_msgval_getstr(upb_msgval val) {
+ return val.str.ptr;
+}
+
+UPB_INLINE size_t upb_msgval_getstrlen(upb_msgval val) {
+ return val.str.len;
+}
+
+
+/** upb_msg *******************************************************************/
+
+/* A upb_msg represents a protobuf message. It always corresponds to a specific
+ * upb_msglayout, which describes how it is laid out in memory.
+ *
+ * The message will have a fixed size, as returned by upb_msg_sizeof(), which
+ * will be used to store fixed-length fields. The upb_msg may also allocate
+ * dynamic memory internally to store data such as:
+ *
+ * - extensions
+ * - unknown fields
+ */
+
+/* Returns the size of a message given this layout. */
+size_t upb_msg_sizeof(const upb_msglayout *l);
+
+/* upb_msg_init() / upb_msg_uninit() allow the user to use a pre-allocated
+ * block of memory as a message. The block's size should be upb_msg_sizeof().
+ * upb_msg_uninit() must be called to release internally-allocated memory
+ * unless the allocator is an arena that does not require freeing.
+ *
+ * Please note that upb_msg_uninit() does *not* free any submessages, maps,
+ * or arrays referred to by this message's fields. You must free them manually
+ * yourself. */
+void upb_msg_init(upb_msg *msg, const upb_msglayout *l, upb_alloc *a);
+void upb_msg_uninit(upb_msg *msg, const upb_msglayout *l);
+
+/* Like upb_msg_init() / upb_msg_uninit(), except the message's memory is
+ * allocated / freed from the given upb_alloc. */
+upb_msg *upb_msg_new(const upb_msglayout *l, upb_alloc *a);
+void upb_msg_free(upb_msg *msg, const upb_msglayout *l);
+
+/* Returns the upb_alloc for the given message. */
+upb_alloc *upb_msg_alloc(const upb_msg *msg, const upb_msglayout *l);
+
+/* Packs the tree of messages rooted at "msg" into a single hunk of memory,
+ * allocated from the given allocator. */
+void *upb_msg_pack(const upb_msg *msg, const upb_msglayout *l,
+ void *p, size_t *ofs, size_t size);
+
+/* Read-only message API. Can be safely called by anyone. */
+
+/* Returns the value associated with this field:
+ * - for scalar fields (including strings), the value directly.
+ * - return upb_msg*, or upb_map* for msg/map.
+ * If the field is unset for these field types, returns NULL.
+ *
+ * TODO(haberman): should we let users store cached array/map/msg
+ * pointers here for fields that are unset? Could be useful for the
+ * strongly-owned submessage model (ie. generated C API that doesn't use
+ * arenas).
+ */
+upb_msgval upb_msg_get(const upb_msg *msg,
+ const upb_fielddef *f,
+ const upb_msglayout *l);
+
+/* May only be called for fields where upb_fielddef_haspresence(f) == true. */
+bool upb_msg_has(const upb_msg *msg,
+ const upb_fielddef *f,
+ const upb_msglayout *l);
+
+/* Returns NULL if no field in the oneof is set. */
+const upb_fielddef *upb_msg_getoneofcase(const upb_msg *msg,
+ const upb_oneofdef *o,
+ const upb_msglayout *l);
+
+/* Returns true if any field in the oneof is set. */
+bool upb_msg_hasoneof(const upb_msg *msg,
+ const upb_oneofdef *o,
+ const upb_msglayout *l);
+
+
+/* Mutable message API. May only be called by the owner of the message who
+ * knows its ownership scheme and how to keep it consistent. */
+
+/* Sets the given field to the given value. Does not perform any memory
+ * management: if you overwrite a pointer to a msg/array/map/string without
+ * cleaning it up (or using an arena) it will leak.
+ */
+bool upb_msg_set(upb_msg *msg,
+ const upb_fielddef *f,
+ upb_msgval val,
+ const upb_msglayout *l);
+
+/* For a primitive field, set it back to its default. For repeated, string, and
+ * submessage fields set it back to NULL. This could involve releasing some
+ * internal memory (for example, from an extension dictionary), but it is not
+ * recursive in any way and will not recover any memory that may be used by
+ * arrays/maps/strings/msgs that this field may have pointed to.
+ */
+bool upb_msg_clearfield(upb_msg *msg,
+ const upb_fielddef *f,
+ const upb_msglayout *l);
+
+/* Clears all fields in the oneof such that none of them are set. */
+bool upb_msg_clearoneof(upb_msg *msg,
+ const upb_oneofdef *o,
+ const upb_msglayout *l);
+
+/* TODO(haberman): copyfrom()/mergefrom()? */
+
+
+/** upb_array *****************************************************************/
+
+/* A upb_array stores data for a repeated field. The memory management
+ * semantics are the same as upb_msg. A upb_array allocates dynamic
+ * memory internally for the array elements. */
+
+size_t upb_array_sizeof(upb_fieldtype_t type);
+void upb_array_init(upb_array *arr, upb_fieldtype_t type, upb_alloc *a);
+void upb_array_uninit(upb_array *arr);
+upb_array *upb_array_new(upb_fieldtype_t type, upb_alloc *a);
+void upb_array_free(upb_array *arr);
+
+/* Read-only interface. Safe for anyone to call. */
+
+size_t upb_array_size(const upb_array *arr);
+upb_fieldtype_t upb_array_type(const upb_array *arr);
+upb_msgval upb_array_get(const upb_array *arr, size_t i);
+
+/* Write interface. May only be called by the message's owner who can enforce
+ * its memory management invariants. */
+
+bool upb_array_set(upb_array *arr, size_t i, upb_msgval val);
+
+
+/** upb_map *******************************************************************/
+
+/* A upb_map stores data for a map field. The memory management semantics are
+ * the same as upb_msg, with one notable exception. upb_map will internally
+ * store a copy of all string keys, but *not* any string values or submessages.
+ * So you must ensure that any string or message values outlive the map, and you
+ * must delete them manually when they are no longer required. */
+
+size_t upb_map_sizeof(upb_fieldtype_t ktype, upb_fieldtype_t vtype);
+bool upb_map_init(upb_map *map, upb_fieldtype_t ktype, upb_fieldtype_t vtype,
+ upb_alloc *a);
+void upb_map_uninit(upb_map *map);
+upb_map *upb_map_new(upb_fieldtype_t ktype, upb_fieldtype_t vtype, upb_alloc *a);
+void upb_map_free(upb_map *map);
+
+/* Read-only interface. Safe for anyone to call. */
+
+size_t upb_map_size(const upb_map *map);
+upb_fieldtype_t upb_map_keytype(const upb_map *map);
+upb_fieldtype_t upb_map_valuetype(const upb_map *map);
+bool upb_map_get(const upb_map *map, upb_msgval key, upb_msgval *val);
+
+/* Write interface. May only be called by the message's owner who can enforce
+ * its memory management invariants. */
+
+/* Sets or overwrites an entry in the map. Return value indicates whether
+ * the operation succeeded or failed with OOM, and also whether an existing
+ * key was replaced or not. */
+bool upb_map_set(upb_map *map,
+ upb_msgval key, upb_msgval val,
+ upb_msgval *valremoved);
+
+/* Deletes an entry in the map. Returns true if the key was present. */
+bool upb_map_del(upb_map *map, upb_msgval key);
+
+
+/** upb_mapiter ***************************************************************/
+
+/* For iterating over a map. Map iterators are invalidated by mutations to the
+ * map, but an invalidated iterator will never return junk or crash the process.
+ * An invalidated iterator may return entries that were already returned though,
+ * and if you keep invalidating the iterator during iteration, the program may
+ * enter an infinite loop. */
+
+size_t upb_mapiter_sizeof();
+
+void upb_mapiter_begin(upb_mapiter *i, const upb_map *t);
+upb_mapiter *upb_mapiter_new(const upb_map *t, upb_alloc *a);
+void upb_mapiter_free(upb_mapiter *i, upb_alloc *a);
+void upb_mapiter_next(upb_mapiter *i);
+bool upb_mapiter_done(const upb_mapiter *i);
+
+upb_msgval upb_mapiter_key(const upb_mapiter *i);
+upb_msgval upb_mapiter_value(const upb_mapiter *i);
+void upb_mapiter_setdone(upb_mapiter *i);
+bool upb_mapiter_isequal(const upb_mapiter *i1, const upb_mapiter *i2);
+
+
+/** Handlers ******************************************************************/
+
+/* These are the handlers used internally by upb_msgfactory_getmergehandlers().
+ * They write scalar data to a known offset from the message pointer.
+ *
+ * These would be trivial for anyone to implement themselves, but it's better
+ * to use these because some JITs will recognize and specialize these instead
+ * of actually calling the function. */
+
+/* Sets a handler for the given primitive field that will write the data at the
+ * given offset. If hasbit > 0, also sets a hasbit at the given bit offset
+ * (addressing each byte low to high). */
+bool upb_msg_setscalarhandler(upb_handlers *h,
+ const upb_fielddef *f,
+ size_t offset,
+ int32_t hasbit);
+
+/* If the given handler is a msghandlers_primitive field, returns true and sets
+ * *type, *offset and *hasbit. Otherwise returns false. */
+bool upb_msg_getscalarhandlerdata(const upb_handlers *h,
+ upb_selector_t s,
+ upb_fieldtype_t *type,
+ size_t *offset,
+ int32_t *hasbit);
+
+UPB_END_EXTERN_C
+
+#endif /* UPB_MSG_H_ */
+/*
+** upb::descriptor::Reader (upb_descreader)
+**
+** Provides a way of building upb::Defs from data in descriptor.proto format.
+*/
+
+#ifndef UPB_DESCRIPTOR_H
+#define UPB_DESCRIPTOR_H
+
+
+#ifdef __cplusplus
+namespace upb {
+namespace descriptor {
+class Reader;
+} /* namespace descriptor */
+} /* namespace upb */
+#endif
+
+UPB_DECLARE_TYPE(upb::descriptor::Reader, upb_descreader)
+
+#ifdef __cplusplus
+
+/* Class that receives descriptor data according to the descriptor.proto schema
+ * and use it to build upb::Defs corresponding to that schema. */
+class upb::descriptor::Reader {
+ public:
+ /* These handlers must have come from NewHandlers() and must outlive the
+ * Reader.
+ *
+ * TODO: generate the handlers statically (like we do with the
+ * descriptor.proto defs) so that there is no need to pass this parameter (or
+ * to build/memory-manage the handlers at runtime at all). Unfortunately this
+ * is a bit tricky to implement for Handlers, but necessary to simplify this
+ * interface. */
+ static Reader* Create(Environment* env, const Handlers* handlers);
+
+ /* The reader's input; this is where descriptor.proto data should be sent. */
+ Sink* input();
+
+ /* Use to get the FileDefs that have been parsed. */
+ size_t file_count() const;
+ FileDef* file(size_t i) const;
+
+ /* Builds and returns handlers for the reader, owned by "owner." */
+ static Handlers* NewHandlers(const void* owner);
+
+ private:
+ UPB_DISALLOW_POD_OPS(Reader, upb::descriptor::Reader)
+};
+
+#endif
+
+UPB_BEGIN_EXTERN_C
+
+/* C API. */
+upb_descreader *upb_descreader_create(upb_env *e, const upb_handlers *h);
+upb_sink *upb_descreader_input(upb_descreader *r);
+size_t upb_descreader_filecount(const upb_descreader *r);
+upb_filedef *upb_descreader_file(const upb_descreader *r, size_t i);
+const upb_handlers *upb_descreader_newhandlers(const void *owner);
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+/* C++ implementation details. ************************************************/
+namespace upb {
+namespace descriptor {
+inline Reader* Reader::Create(Environment* e, const Handlers *h) {
+ return upb_descreader_create(e, h);
+}
+inline Sink* Reader::input() { return upb_descreader_input(this); }
+inline size_t Reader::file_count() const {
+ return upb_descreader_filecount(this);
+}
+inline FileDef* Reader::file(size_t i) const {
+ return upb_descreader_file(this, i);
+}
+} /* namespace descriptor */
+} /* namespace upb */
+#endif
+
+#endif /* UPB_DESCRIPTOR_H */
+/* This file contains accessors for a set of compiled-in defs.
+ * Note that unlike Google's protobuf, it does *not* define
+ * generated classes or any other kind of data structure for
+ * actually storing protobufs. It only contains *defs* which
+ * let you reflect over a protobuf *schema*.
+ */
+/* This file was generated by upbc (the upb compiler) from the input
+ * file:
+ *
+ * upb/descriptor/descriptor.proto
+ *
+ * Do not edit -- your changes will be discarded when the file is
+ * regenerated. */
+
+#ifndef UPB_DESCRIPTOR_DESCRIPTOR_PROTO_UPB_H_
+#define UPB_DESCRIPTOR_DESCRIPTOR_PROTO_UPB_H_
+
+
+UPB_BEGIN_EXTERN_C
+
+/* Enums */
+
+typedef enum {
+ google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1,
+ google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2,
+ google_protobuf_FieldDescriptorProto_LABEL_REPEATED = 3
+} google_protobuf_FieldDescriptorProto_Label;
+
+typedef enum {
+ google_protobuf_FieldDescriptorProto_TYPE_DOUBLE = 1,
+ google_protobuf_FieldDescriptorProto_TYPE_FLOAT = 2,
+ google_protobuf_FieldDescriptorProto_TYPE_INT64 = 3,
+ google_protobuf_FieldDescriptorProto_TYPE_UINT64 = 4,
+ google_protobuf_FieldDescriptorProto_TYPE_INT32 = 5,
+ google_protobuf_FieldDescriptorProto_TYPE_FIXED64 = 6,
+ google_protobuf_FieldDescriptorProto_TYPE_FIXED32 = 7,
+ google_protobuf_FieldDescriptorProto_TYPE_BOOL = 8,
+ google_protobuf_FieldDescriptorProto_TYPE_STRING = 9,
+ google_protobuf_FieldDescriptorProto_TYPE_GROUP = 10,
+ google_protobuf_FieldDescriptorProto_TYPE_MESSAGE = 11,
+ google_protobuf_FieldDescriptorProto_TYPE_BYTES = 12,
+ google_protobuf_FieldDescriptorProto_TYPE_UINT32 = 13,
+ google_protobuf_FieldDescriptorProto_TYPE_ENUM = 14,
+ google_protobuf_FieldDescriptorProto_TYPE_SFIXED32 = 15,
+ google_protobuf_FieldDescriptorProto_TYPE_SFIXED64 = 16,
+ google_protobuf_FieldDescriptorProto_TYPE_SINT32 = 17,
+ google_protobuf_FieldDescriptorProto_TYPE_SINT64 = 18
+} google_protobuf_FieldDescriptorProto_Type;
+
+typedef enum {
+ google_protobuf_FieldOptions_STRING = 0,
+ google_protobuf_FieldOptions_CORD = 1,
+ google_protobuf_FieldOptions_STRING_PIECE = 2
+} google_protobuf_FieldOptions_CType;
+
+typedef enum {
+ google_protobuf_FieldOptions_JS_NORMAL = 0,
+ google_protobuf_FieldOptions_JS_STRING = 1,
+ google_protobuf_FieldOptions_JS_NUMBER = 2
+} google_protobuf_FieldOptions_JSType;
+
+typedef enum {
+ google_protobuf_FileOptions_SPEED = 1,
+ google_protobuf_FileOptions_CODE_SIZE = 2,
+ google_protobuf_FileOptions_LITE_RUNTIME = 3
+} google_protobuf_FileOptions_OptimizeMode;
+
+/* MessageDefs: call these functions to get a ref to a msgdef. */
+const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ReservedRange_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_EnumDescriptorProto_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_EnumOptions_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_EnumValueDescriptorProto_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_EnumValueOptions_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_FieldDescriptorProto_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_FieldOptions_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_FileDescriptorProto_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_FileDescriptorSet_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_FileOptions_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_MessageOptions_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_MethodDescriptorProto_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_MethodOptions_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_OneofDescriptorProto_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_ServiceDescriptorProto_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_ServiceOptions_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo_Location_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption_get(const void *owner);
+const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption_NamePart_get(const void *owner);
+
+/* EnumDefs: call these functions to get a ref to an enumdef. */
+const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Label_get(const void *owner);
+const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Type_get(const void *owner);
+const upb_enumdef *upbdefs_google_protobuf_FieldOptions_CType_get(const void *owner);
+const upb_enumdef *upbdefs_google_protobuf_FieldOptions_JSType_get(const void *owner);
+const upb_enumdef *upbdefs_google_protobuf_FileOptions_OptimizeMode_get(const void *owner);
+
+/* Functions to test whether this message is of a certain type. */
+UPB_INLINE bool upbdefs_google_protobuf_DescriptorProto_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.DescriptorProto") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_DescriptorProto_ExtensionRange_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.DescriptorProto.ExtensionRange") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_DescriptorProto_ReservedRange_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.DescriptorProto.ReservedRange") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_EnumDescriptorProto_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.EnumDescriptorProto") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_EnumOptions_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.EnumOptions") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_EnumValueDescriptorProto_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.EnumValueDescriptorProto") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_EnumValueOptions_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.EnumValueOptions") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FieldDescriptorProto_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.FieldDescriptorProto") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FieldOptions_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.FieldOptions") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FileDescriptorProto_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.FileDescriptorProto") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FileDescriptorSet_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.FileDescriptorSet") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FileOptions_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.FileOptions") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_MessageOptions_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.MessageOptions") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_MethodDescriptorProto_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.MethodDescriptorProto") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_MethodOptions_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.MethodOptions") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_OneofDescriptorProto_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.OneofDescriptorProto") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_ServiceDescriptorProto_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.ServiceDescriptorProto") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_ServiceOptions_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.ServiceOptions") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_SourceCodeInfo_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.SourceCodeInfo") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_SourceCodeInfo_Location_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.SourceCodeInfo.Location") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_UninterpretedOption_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.UninterpretedOption") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_UninterpretedOption_NamePart_is(const upb_msgdef *m) {
+ return strcmp(upb_msgdef_fullname(m), "google.protobuf.UninterpretedOption.NamePart") == 0;
+}
+
+/* Functions to test whether this enum is of a certain type. */
+UPB_INLINE bool upbdefs_google_protobuf_FieldDescriptorProto_Label_is(const upb_enumdef *e) {
+ return strcmp(upb_enumdef_fullname(e), "google.protobuf.FieldDescriptorProto.Label") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FieldDescriptorProto_Type_is(const upb_enumdef *e) {
+ return strcmp(upb_enumdef_fullname(e), "google.protobuf.FieldDescriptorProto.Type") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FieldOptions_CType_is(const upb_enumdef *e) {
+ return strcmp(upb_enumdef_fullname(e), "google.protobuf.FieldOptions.CType") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FieldOptions_JSType_is(const upb_enumdef *e) {
+ return strcmp(upb_enumdef_fullname(e), "google.protobuf.FieldOptions.JSType") == 0;
+}
+UPB_INLINE bool upbdefs_google_protobuf_FileOptions_OptimizeMode_is(const upb_enumdef *e) {
+ return strcmp(upb_enumdef_fullname(e), "google.protobuf.FileOptions.OptimizeMode") == 0;
+}
+
+
+/* Functions to get a fielddef from a msgdef reference. */
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_f_end(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ExtensionRange_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_f_start(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ExtensionRange_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ReservedRange_f_end(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ReservedRange_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_ReservedRange_f_start(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ReservedRange_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_enum_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 4); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_extension(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 6); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_extension_range(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 5); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_field(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_nested_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_oneof_decl(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 8); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 7); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_reserved_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 10); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_DescriptorProto_f_reserved_range(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m)); return upb_msgdef_itof(m, 9); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumDescriptorProto_f_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumOptions_f_allow_alias(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumOptions_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumOptions_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumOptions_is(m)); return upb_msgdef_itof(m, 999); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_f_number(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueOptions_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_EnumValueOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_EnumValueOptions_is(m)); return upb_msgdef_itof(m, 999); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_default_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 7); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_extendee(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_json_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 10); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_label(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 4); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_number(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_oneof_index(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 9); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 8); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 5); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldDescriptorProto_f_type_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m)); return upb_msgdef_itof(m, 6); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_ctype(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_jstype(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 6); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_lazy(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 5); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_packed(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 999); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FieldOptions_f_weak(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m)); return upb_msgdef_itof(m, 10); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_dependency(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_enum_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 5); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_extension(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 7); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_message_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 4); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 8); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_package(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_public_dependency(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 10); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_service(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 6); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_source_code_info(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 9); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_syntax(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 12); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorProto_f_weak_dependency(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m)); return upb_msgdef_itof(m, 11); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileDescriptorSet_f_file(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorSet_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_cc_enable_arenas(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 31); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_cc_generic_services(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 16); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_csharp_namespace(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 37); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 23); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_go_package(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 11); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_generate_equals_and_hash(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 20); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_generic_services(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 17); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_multiple_files(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 10); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_outer_classname(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 8); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_package(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_java_string_check_utf8(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 27); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_javanano_use_deprecated_package(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 38); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_objc_class_prefix(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 36); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_optimize_for(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 9); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_py_generic_services(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 18); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_FileOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m)); return upb_msgdef_itof(m, 999); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_map_entry(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m)); return upb_msgdef_itof(m, 7); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_message_set_wire_format(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_no_standard_descriptor_accessor(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MessageOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m)); return upb_msgdef_itof(m, 999); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_client_streaming(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 5); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_input_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 4); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_output_type(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodDescriptorProto_f_server_streaming(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m)); return upb_msgdef_itof(m, 6); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodOptions_is(m)); return upb_msgdef_itof(m, 33); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_MethodOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_MethodOptions_is(m)); return upb_msgdef_itof(m, 999); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_OneofDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_OneofDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_f_method(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceDescriptorProto_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceDescriptorProto_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceDescriptorProto_f_options(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceDescriptorProto_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceOptions_f_deprecated(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceOptions_is(m)); return upb_msgdef_itof(m, 33); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_ServiceOptions_f_uninterpreted_option(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_ServiceOptions_is(m)); return upb_msgdef_itof(m, 999); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f_leading_comments(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f_leading_detached_comments(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 6); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f_path(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f_span(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_Location_f_trailing_comments(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m)); return upb_msgdef_itof(m, 4); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_SourceCodeInfo_f_location(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_NamePart_f_is_extension(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_NamePart_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_NamePart_f_name_part(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_NamePart_is(m)); return upb_msgdef_itof(m, 1); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_aggregate_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 8); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_double_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 6); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_identifier_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 3); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_name(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 2); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_negative_int_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 5); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_positive_int_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 4); }
+UPB_INLINE const upb_fielddef *upbdefs_google_protobuf_UninterpretedOption_f_string_value(const upb_msgdef *m) { UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m)); return upb_msgdef_itof(m, 7); }
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+namespace upbdefs {
+namespace google {
+namespace protobuf {
+
+class DescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ DescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_is(m));
+ }
+
+ static DescriptorProto get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_get(&m);
+ return DescriptorProto(m, &m);
+ }
+
+ class ExtensionRange : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ ExtensionRange(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ExtensionRange_is(m));
+ }
+
+ static ExtensionRange get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_ExtensionRange_get(&m);
+ return ExtensionRange(m, &m);
+ }
+ };
+
+ class ReservedRange : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ ReservedRange(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_DescriptorProto_ReservedRange_is(m));
+ }
+
+ static ReservedRange get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_DescriptorProto_ReservedRange_get(&m);
+ return ReservedRange(m, &m);
+ }
+ };
+};
+
+class EnumDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ EnumDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_EnumDescriptorProto_is(m));
+ }
+
+ static EnumDescriptorProto get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumDescriptorProto_get(&m);
+ return EnumDescriptorProto(m, &m);
+ }
+};
+
+class EnumOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ EnumOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_EnumOptions_is(m));
+ }
+
+ static EnumOptions get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumOptions_get(&m);
+ return EnumOptions(m, &m);
+ }
+};
+
+class EnumValueDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ EnumValueDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_EnumValueDescriptorProto_is(m));
+ }
+
+ static EnumValueDescriptorProto get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumValueDescriptorProto_get(&m);
+ return EnumValueDescriptorProto(m, &m);
+ }
+};
+
+class EnumValueOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ EnumValueOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_EnumValueOptions_is(m));
+ }
+
+ static EnumValueOptions get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_EnumValueOptions_get(&m);
+ return EnumValueOptions(m, &m);
+ }
+};
+
+class FieldDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ FieldDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_is(m));
+ }
+
+ static FieldDescriptorProto get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_FieldDescriptorProto_get(&m);
+ return FieldDescriptorProto(m, &m);
+ }
+
+ class Label : public ::upb::reffed_ptr<const ::upb::EnumDef> {
+ public:
+ Label(const ::upb::EnumDef* e, const void *ref_donor = NULL)
+ : reffed_ptr(e, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_Label_is(e));
+ }
+ static Label get() {
+ const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldDescriptorProto_Label_get(&e);
+ return Label(e, &e);
+ }
+ };
+
+ class Type : public ::upb::reffed_ptr<const ::upb::EnumDef> {
+ public:
+ Type(const ::upb::EnumDef* e, const void *ref_donor = NULL)
+ : reffed_ptr(e, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FieldDescriptorProto_Type_is(e));
+ }
+ static Type get() {
+ const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldDescriptorProto_Type_get(&e);
+ return Type(e, &e);
+ }
+ };
+};
+
+class FieldOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ FieldOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_is(m));
+ }
+
+ static FieldOptions get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_FieldOptions_get(&m);
+ return FieldOptions(m, &m);
+ }
+
+ class CType : public ::upb::reffed_ptr<const ::upb::EnumDef> {
+ public:
+ CType(const ::upb::EnumDef* e, const void *ref_donor = NULL)
+ : reffed_ptr(e, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_CType_is(e));
+ }
+ static CType get() {
+ const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldOptions_CType_get(&e);
+ return CType(e, &e);
+ }
+ };
+
+ class JSType : public ::upb::reffed_ptr<const ::upb::EnumDef> {
+ public:
+ JSType(const ::upb::EnumDef* e, const void *ref_donor = NULL)
+ : reffed_ptr(e, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FieldOptions_JSType_is(e));
+ }
+ static JSType get() {
+ const ::upb::EnumDef* e = upbdefs_google_protobuf_FieldOptions_JSType_get(&e);
+ return JSType(e, &e);
+ }
+ };
+};
+
+class FileDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ FileDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorProto_is(m));
+ }
+
+ static FileDescriptorProto get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_FileDescriptorProto_get(&m);
+ return FileDescriptorProto(m, &m);
+ }
+};
+
+class FileDescriptorSet : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ FileDescriptorSet(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FileDescriptorSet_is(m));
+ }
+
+ static FileDescriptorSet get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_FileDescriptorSet_get(&m);
+ return FileDescriptorSet(m, &m);
+ }
+};
+
+class FileOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ FileOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FileOptions_is(m));
+ }
+
+ static FileOptions get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_FileOptions_get(&m);
+ return FileOptions(m, &m);
+ }
+
+ class OptimizeMode : public ::upb::reffed_ptr<const ::upb::EnumDef> {
+ public:
+ OptimizeMode(const ::upb::EnumDef* e, const void *ref_donor = NULL)
+ : reffed_ptr(e, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_FileOptions_OptimizeMode_is(e));
+ }
+ static OptimizeMode get() {
+ const ::upb::EnumDef* e = upbdefs_google_protobuf_FileOptions_OptimizeMode_get(&e);
+ return OptimizeMode(e, &e);
+ }
+ };
+};
+
+class MessageOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ MessageOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_MessageOptions_is(m));
+ }
+
+ static MessageOptions get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_MessageOptions_get(&m);
+ return MessageOptions(m, &m);
+ }
+};
+
+class MethodDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ MethodDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_MethodDescriptorProto_is(m));
+ }
+
+ static MethodDescriptorProto get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_MethodDescriptorProto_get(&m);
+ return MethodDescriptorProto(m, &m);
+ }
+};
+
+class MethodOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ MethodOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_MethodOptions_is(m));
+ }
+
+ static MethodOptions get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_MethodOptions_get(&m);
+ return MethodOptions(m, &m);
+ }
+};
+
+class OneofDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ OneofDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_OneofDescriptorProto_is(m));
+ }
+
+ static OneofDescriptorProto get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_OneofDescriptorProto_get(&m);
+ return OneofDescriptorProto(m, &m);
+ }
+};
+
+class ServiceDescriptorProto : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ ServiceDescriptorProto(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_ServiceDescriptorProto_is(m));
+ }
+
+ static ServiceDescriptorProto get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_ServiceDescriptorProto_get(&m);
+ return ServiceDescriptorProto(m, &m);
+ }
+};
+
+class ServiceOptions : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ ServiceOptions(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_ServiceOptions_is(m));
+ }
+
+ static ServiceOptions get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_ServiceOptions_get(&m);
+ return ServiceOptions(m, &m);
+ }
+};
+
+class SourceCodeInfo : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ SourceCodeInfo(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_is(m));
+ }
+
+ static SourceCodeInfo get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_SourceCodeInfo_get(&m);
+ return SourceCodeInfo(m, &m);
+ }
+
+ class Location : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ Location(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_SourceCodeInfo_Location_is(m));
+ }
+
+ static Location get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_SourceCodeInfo_Location_get(&m);
+ return Location(m, &m);
+ }
+ };
+};
+
+class UninterpretedOption : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ UninterpretedOption(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_is(m));
+ }
+
+ static UninterpretedOption get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_UninterpretedOption_get(&m);
+ return UninterpretedOption(m, &m);
+ }
+
+ class NamePart : public ::upb::reffed_ptr<const ::upb::MessageDef> {
+ public:
+ NamePart(const ::upb::MessageDef* m, const void *ref_donor = NULL)
+ : reffed_ptr(m, ref_donor) {
+ UPB_ASSERT(upbdefs_google_protobuf_UninterpretedOption_NamePart_is(m));
+ }
+
+ static NamePart get() {
+ const ::upb::MessageDef* m = upbdefs_google_protobuf_UninterpretedOption_NamePart_get(&m);
+ return NamePart(m, &m);
+ }
+ };
+};
+
+} /* namespace protobuf */
+} /* namespace google */
+} /* namespace upbdefs */
+
+#endif /* __cplusplus */
+
+#endif /* UPB_DESCRIPTOR_DESCRIPTOR_PROTO_UPB_H_ */
+/*
+** Internal-only definitions for the decoder.
+*/
+
+#ifndef UPB_DECODER_INT_H_
+#define UPB_DECODER_INT_H_
+
+/*
+** upb::pb::Decoder
+**
+** A high performance, streaming, resumable decoder for the binary protobuf
+** format.
+**
+** This interface works the same regardless of what decoder backend is being
+** used. A client of this class does not need to know whether decoding is using
+** a JITted decoder (DynASM, LLVM, etc) or an interpreted decoder. By default,
+** it will always use the fastest available decoder. However, you can call
+** set_allow_jit(false) to disable any JIT decoder that might be available.
+** This is primarily useful for testing purposes.
+*/
+
+#ifndef UPB_DECODER_H_
+#define UPB_DECODER_H_
+
+
+#ifdef __cplusplus
+namespace upb {
+namespace pb {
+class CodeCache;
+class Decoder;
+class DecoderMethod;
+class DecoderMethodOptions;
+} /* namespace pb */
+} /* namespace upb */
+#endif
+
+UPB_DECLARE_TYPE(upb::pb::CodeCache, upb_pbcodecache)
+UPB_DECLARE_TYPE(upb::pb::Decoder, upb_pbdecoder)
+UPB_DECLARE_TYPE(upb::pb::DecoderMethodOptions, upb_pbdecodermethodopts)
+
+UPB_DECLARE_DERIVED_TYPE(upb::pb::DecoderMethod, upb::RefCounted,
+ upb_pbdecodermethod, upb_refcounted)
+
+/* The maximum number of bytes we are required to buffer internally between
+ * calls to the decoder. The value is 14: a 5 byte unknown tag plus ten-byte
+ * varint, less one because we are buffering an incomplete value.
+ *
+ * Should only be used by unit tests. */
+#define UPB_DECODER_MAX_RESIDUAL_BYTES 14
+
+#ifdef __cplusplus
+
+/* The parameters one uses to construct a DecoderMethod.
+ * TODO(haberman): move allowjit here? Seems more convenient for users.
+ * TODO(haberman): move this to be heap allocated for ABI stability. */
+class upb::pb::DecoderMethodOptions {
+ public:
+ /* Parameter represents the destination handlers that this method will push
+ * to. */
+ explicit DecoderMethodOptions(const Handlers* dest_handlers);
+
+ /* Should the decoder push submessages to lazy handlers for fields that have
+ * them? The caller should set this iff the lazy handlers expect data that is
+ * in protobuf binary format and the caller wishes to lazy parse it. */
+ void set_lazy(bool lazy);
+#else
+struct upb_pbdecodermethodopts {
+#endif
+ const upb_handlers *handlers;
+ bool lazy;
+};
+
+#ifdef __cplusplus
+
+/* Represents the code to parse a protobuf according to a destination
+ * Handlers. */
+class upb::pb::DecoderMethod {
+ public:
+ /* Include base methods from upb::ReferenceCounted. */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ /* The destination handlers that are statically bound to this method.
+ * This method is only capable of outputting to a sink that uses these
+ * handlers. */
+ const Handlers* dest_handlers() const;
+
+ /* The input handlers for this decoder method. */
+ const BytesHandler* input_handler() const;
+
+ /* Whether this method is native. */
+ bool is_native() const;
+
+ /* Convenience method for generating a DecoderMethod without explicitly
+ * creating a CodeCache. */
+ static reffed_ptr<const DecoderMethod> New(const DecoderMethodOptions& opts);
+
+ private:
+ UPB_DISALLOW_POD_OPS(DecoderMethod, upb::pb::DecoderMethod)
+};
+
+#endif
+
+/* Preallocation hint: decoder won't allocate more bytes than this when first
+ * constructed. This hint may be an overestimate for some build configurations.
+ * But if the decoder library is upgraded without recompiling the application,
+ * it may be an underestimate. */
+#define UPB_PB_DECODER_SIZE 4416
+
+#ifdef __cplusplus
+
+/* A Decoder receives binary protobuf data on its input sink and pushes the
+ * decoded data to its output sink. */
+class upb::pb::Decoder {
+ public:
+ /* Constructs a decoder instance for the given method, which must outlive this
+ * decoder. Any errors during parsing will be set on the given status, which
+ * must also outlive this decoder.
+ *
+ * The sink must match the given method. */
+ static Decoder* Create(Environment* env, const DecoderMethod* method,
+ Sink* output);
+
+ /* Returns the DecoderMethod this decoder is parsing from. */
+ const DecoderMethod* method() const;
+
+ /* The sink on which this decoder receives input. */
+ BytesSink* input();
+
+ /* Returns number of bytes successfully parsed.
+ *
+ * This can be useful for determining the stream position where an error
+ * occurred.
+ *
+ * This value may not be up-to-date when called from inside a parsing
+ * callback. */
+ uint64_t BytesParsed() const;
+
+ /* Gets/sets the parsing nexting limit. If the total number of nested
+ * submessages and repeated fields hits this limit, parsing will fail. This
+ * is a resource limit that controls the amount of memory used by the parsing
+ * stack.
+ *
+ * Setting the limit will fail if the parser is currently suspended at a depth
+ * greater than this, or if memory allocation of the stack fails. */
+ size_t max_nesting() const;
+ bool set_max_nesting(size_t max);
+
+ void Reset();
+
+ static const size_t kSize = UPB_PB_DECODER_SIZE;
+
+ private:
+ UPB_DISALLOW_POD_OPS(Decoder, upb::pb::Decoder)
+};
+
+#endif /* __cplusplus */
+
+#ifdef __cplusplus
+
+/* A class for caching protobuf processing code, whether bytecode for the
+ * interpreted decoder or machine code for the JIT.
+ *
+ * This class is not thread-safe.
+ *
+ * TODO(haberman): move this to be heap allocated for ABI stability. */
+class upb::pb::CodeCache {
+ public:
+ CodeCache();
+ ~CodeCache();
+
+ /* Whether the cache is allowed to generate machine code. Defaults to true.
+ * There is no real reason to turn it off except for testing or if you are
+ * having a specific problem with the JIT.
+ *
+ * Note that allow_jit = true does not *guarantee* that the code will be JIT
+ * compiled. If this platform is not supported or the JIT was not compiled
+ * in, the code may still be interpreted. */
+ bool allow_jit() const;
+
+ /* This may only be called when the object is first constructed, and prior to
+ * any code generation, otherwise returns false and does nothing. */
+ bool set_allow_jit(bool allow);
+
+ /* Returns a DecoderMethod that can push data to the given handlers.
+ * If a suitable method already exists, it will be returned from the cache.
+ *
+ * Specifying the destination handlers here allows the DecoderMethod to be
+ * statically bound to the destination handlers if possible, which can allow
+ * more efficient decoding. However the returned method may or may not
+ * actually be statically bound. But in all cases, the returned method can
+ * push data to the given handlers. */
+ const DecoderMethod *GetDecoderMethod(const DecoderMethodOptions& opts);
+
+ /* If/when someone needs to explicitly create a dynamically-bound
+ * DecoderMethod*, we can add a method to get it here. */
+
+ private:
+ UPB_DISALLOW_COPY_AND_ASSIGN(CodeCache)
+#else
+struct upb_pbcodecache {
+#endif
+ bool allow_jit_;
+
+ /* Array of mgroups. */
+ upb_inttable groups;
+};
+
+UPB_BEGIN_EXTERN_C
+
+upb_pbdecoder *upb_pbdecoder_create(upb_env *e,
+ const upb_pbdecodermethod *method,
+ upb_sink *output);
+const upb_pbdecodermethod *upb_pbdecoder_method(const upb_pbdecoder *d);
+upb_bytessink *upb_pbdecoder_input(upb_pbdecoder *d);
+uint64_t upb_pbdecoder_bytesparsed(const upb_pbdecoder *d);
+size_t upb_pbdecoder_maxnesting(const upb_pbdecoder *d);
+bool upb_pbdecoder_setmaxnesting(upb_pbdecoder *d, size_t max);
+void upb_pbdecoder_reset(upb_pbdecoder *d);
+
+void upb_pbdecodermethodopts_init(upb_pbdecodermethodopts *opts,
+ const upb_handlers *h);
+void upb_pbdecodermethodopts_setlazy(upb_pbdecodermethodopts *opts, bool lazy);
+
+
+/* Include refcounted methods like upb_pbdecodermethod_ref(). */
+UPB_REFCOUNTED_CMETHODS(upb_pbdecodermethod, upb_pbdecodermethod_upcast)
+
+const upb_handlers *upb_pbdecodermethod_desthandlers(
+ const upb_pbdecodermethod *m);
+const upb_byteshandler *upb_pbdecodermethod_inputhandler(
+ const upb_pbdecodermethod *m);
+bool upb_pbdecodermethod_isnative(const upb_pbdecodermethod *m);
+const upb_pbdecodermethod *upb_pbdecodermethod_new(
+ const upb_pbdecodermethodopts *opts, const void *owner);
+
+void upb_pbcodecache_init(upb_pbcodecache *c);
+void upb_pbcodecache_uninit(upb_pbcodecache *c);
+bool upb_pbcodecache_allowjit(const upb_pbcodecache *c);
+bool upb_pbcodecache_setallowjit(upb_pbcodecache *c, bool allow);
+const upb_pbdecodermethod *upb_pbcodecache_getdecodermethod(
+ upb_pbcodecache *c, const upb_pbdecodermethodopts *opts);
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+namespace upb {
+
+namespace pb {
+
+/* static */
+inline Decoder* Decoder::Create(Environment* env, const DecoderMethod* m,
+ Sink* sink) {
+ return upb_pbdecoder_create(env, m, sink);
+}
+inline const DecoderMethod* Decoder::method() const {
+ return upb_pbdecoder_method(this);
+}
+inline BytesSink* Decoder::input() {
+ return upb_pbdecoder_input(this);
+}
+inline uint64_t Decoder::BytesParsed() const {
+ return upb_pbdecoder_bytesparsed(this);
+}
+inline size_t Decoder::max_nesting() const {
+ return upb_pbdecoder_maxnesting(this);
+}
+inline bool Decoder::set_max_nesting(size_t max) {
+ return upb_pbdecoder_setmaxnesting(this, max);
+}
+inline void Decoder::Reset() { upb_pbdecoder_reset(this); }
+
+inline DecoderMethodOptions::DecoderMethodOptions(const Handlers* h) {
+ upb_pbdecodermethodopts_init(this, h);
+}
+inline void DecoderMethodOptions::set_lazy(bool lazy) {
+ upb_pbdecodermethodopts_setlazy(this, lazy);
+}
+
+inline const Handlers* DecoderMethod::dest_handlers() const {
+ return upb_pbdecodermethod_desthandlers(this);
+}
+inline const BytesHandler* DecoderMethod::input_handler() const {
+ return upb_pbdecodermethod_inputhandler(this);
+}
+inline bool DecoderMethod::is_native() const {
+ return upb_pbdecodermethod_isnative(this);
+}
+/* static */
+inline reffed_ptr<const DecoderMethod> DecoderMethod::New(
+ const DecoderMethodOptions &opts) {
+ const upb_pbdecodermethod *m = upb_pbdecodermethod_new(&opts, &m);
+ return reffed_ptr<const DecoderMethod>(m, &m);
+}
+
+inline CodeCache::CodeCache() {
+ upb_pbcodecache_init(this);
+}
+inline CodeCache::~CodeCache() {
+ upb_pbcodecache_uninit(this);
+}
+inline bool CodeCache::allow_jit() const {
+ return upb_pbcodecache_allowjit(this);
+}
+inline bool CodeCache::set_allow_jit(bool allow) {
+ return upb_pbcodecache_setallowjit(this, allow);
+}
+inline const DecoderMethod *CodeCache::GetDecoderMethod(
+ const DecoderMethodOptions& opts) {
+ return upb_pbcodecache_getdecodermethod(this, &opts);
+}
+
+} /* namespace pb */
+} /* namespace upb */
+
+#endif /* __cplusplus */
+
+#endif /* UPB_DECODER_H_ */
+
+/* C++ names are not actually used since this type isn't exposed to users. */
+#ifdef __cplusplus
+namespace upb {
+namespace pb {
+class MessageGroup;
+} /* namespace pb */
+} /* namespace upb */
+#endif
+UPB_DECLARE_DERIVED_TYPE(upb::pb::MessageGroup, upb::RefCounted,
+ mgroup, upb_refcounted)
+
+/* Opcode definitions. The canonical meaning of each opcode is its
+ * implementation in the interpreter (the JIT is written to match this).
+ *
+ * All instructions have the opcode in the low byte.
+ * Instruction format for most instructions is:
+ *
+ * +-------------------+--------+
+ * | arg (24) | op (8) |
+ * +-------------------+--------+
+ *
+ * Exceptions are indicated below. A few opcodes are multi-word. */
+typedef enum {
+ /* Opcodes 1-8, 13, 15-18 parse their respective descriptor types.
+ * Arg for all of these is the upb selector for this field. */
+#define T(type) OP_PARSE_ ## type = UPB_DESCRIPTOR_TYPE_ ## type
+ T(DOUBLE), T(FLOAT), T(INT64), T(UINT64), T(INT32), T(FIXED64), T(FIXED32),
+ T(BOOL), T(UINT32), T(SFIXED32), T(SFIXED64), T(SINT32), T(SINT64),
+#undef T
+ OP_STARTMSG = 9, /* No arg. */
+ OP_ENDMSG = 10, /* No arg. */
+ OP_STARTSEQ = 11,
+ OP_ENDSEQ = 12,
+ OP_STARTSUBMSG = 14,
+ OP_ENDSUBMSG = 19,
+ OP_STARTSTR = 20,
+ OP_STRING = 21,
+ OP_ENDSTR = 22,
+
+ OP_PUSHTAGDELIM = 23, /* No arg. */
+ OP_PUSHLENDELIM = 24, /* No arg. */
+ OP_POP = 25, /* No arg. */
+ OP_SETDELIM = 26, /* No arg. */
+ OP_SETBIGGROUPNUM = 27, /* two words:
+ * | unused (24) | opc (8) |
+ * | groupnum (32) | */
+ OP_CHECKDELIM = 28,
+ OP_CALL = 29,
+ OP_RET = 30,
+ OP_BRANCH = 31,
+
+ /* Different opcodes depending on how many bytes expected. */
+ OP_TAG1 = 32, /* | match tag (16) | jump target (8) | opc (8) | */
+ OP_TAG2 = 33, /* | match tag (16) | jump target (8) | opc (8) | */
+ OP_TAGN = 34, /* three words: */
+ /* | unused (16) | jump target(8) | opc (8) | */
+ /* | match tag 1 (32) | */
+ /* | match tag 2 (32) | */
+
+ OP_SETDISPATCH = 35, /* N words: */
+ /* | unused (24) | opc | */
+ /* | upb_inttable* (32 or 64) | */
+
+ OP_DISPATCH = 36, /* No arg. */
+
+ OP_HALT = 37 /* No arg. */
+} opcode;
+
+#define OP_MAX OP_HALT
+
+UPB_INLINE opcode getop(uint32_t instr) { return instr & 0xff; }
+
+/* Method group; represents a set of decoder methods that had their code
+ * emitted together, and must therefore be freed together. Immutable once
+ * created. It is possible we may want to expose this to users at some point.
+ *
+ * Overall ownership of Decoder objects looks like this:
+ *
+ * +----------+
+ * | | <---> DecoderMethod
+ * | method |
+ * CodeCache ---> | group | <---> DecoderMethod
+ * | |
+ * | (mgroup) | <---> DecoderMethod
+ * +----------+
+ */
+struct mgroup {
+ upb_refcounted base;
+
+ /* Maps upb_msgdef/upb_handlers -> upb_pbdecodermethod. We own refs on the
+ * methods. */
+ upb_inttable methods;
+
+ /* When we add the ability to link to previously existing mgroups, we'll
+ * need an array of mgroups we reference here, and own refs on them. */
+
+ /* The bytecode for our methods, if any exists. Owned by us. */
+ uint32_t *bytecode;
+ uint32_t *bytecode_end;
+
+#ifdef UPB_USE_JIT_X64
+ /* JIT-generated machine code, if any. */
+ upb_string_handlerfunc *jit_code;
+ /* The size of the jit_code (required to munmap()). */
+ size_t jit_size;
+ char *debug_info;
+ void *dl;
+#endif
+};
+
+/* The maximum that any submessages can be nested. Matches proto2's limit.
+ * This specifies the size of the decoder's statically-sized array and therefore
+ * setting it high will cause the upb::pb::Decoder object to be larger.
+ *
+ * If necessary we can add a runtime-settable property to Decoder that allow
+ * this to be larger than the compile-time setting, but this would add
+ * complexity, particularly since we would have to decide how/if to give users
+ * the ability to set a custom memory allocation function. */
+#define UPB_DECODER_MAX_NESTING 64
+
+/* Internal-only struct used by the decoder. */
+typedef struct {
+ /* Space optimization note: we store two pointers here that the JIT
+ * doesn't need at all; the upb_handlers* inside the sink and
+ * the dispatch table pointer. We can optimze so that the JIT uses
+ * smaller stack frames than the interpreter. The only thing we need
+ * to guarantee is that the fallback routines can find end_ofs. */
+ upb_sink sink;
+
+ /* The absolute stream offset of the end-of-frame delimiter.
+ * Non-delimited frames (groups and non-packed repeated fields) reuse the
+ * delimiter of their parent, even though the frame may not end there.
+ *
+ * NOTE: the JIT stores a slightly different value here for non-top frames.
+ * It stores the value relative to the end of the enclosed message. But the
+ * top frame is still stored the same way, which is important for ensuring
+ * that calls from the JIT into C work correctly. */
+ uint64_t end_ofs;
+ const uint32_t *base;
+
+ /* 0 indicates a length-delimited field.
+ * A positive number indicates a known group.
+ * A negative number indicates an unknown group. */
+ int32_t groupnum;
+ upb_inttable *dispatch; /* Not used by the JIT. */
+} upb_pbdecoder_frame;
+
+struct upb_pbdecodermethod {
+ upb_refcounted base;
+
+ /* While compiling, the base is relative in "ofs", after compiling it is
+ * absolute in "ptr". */
+ union {
+ uint32_t ofs; /* PC offset of method. */
+ void *ptr; /* Pointer to bytecode or machine code for this method. */
+ } code_base;
+
+ /* The decoder method group to which this method belongs. We own a ref.
+ * Owning a ref on the entire group is more coarse-grained than is strictly
+ * necessary; all we truly require is that methods we directly reference
+ * outlive us, while the group could contain many other messages we don't
+ * require. But the group represents the messages that were
+ * allocated+compiled together, so it makes the most sense to free them
+ * together also. */
+ const upb_refcounted *group;
+
+ /* Whether this method is native code or bytecode. */
+ bool is_native_;
+
+ /* The handler one calls to invoke this method. */
+ upb_byteshandler input_handler_;
+
+ /* The destination handlers this method is bound to. We own a ref. */
+ const upb_handlers *dest_handlers_;
+
+ /* Dispatch table -- used by both bytecode decoder and JIT when encountering a
+ * field number that wasn't the one we were expecting to see. See
+ * decoder.int.h for the layout of this table. */
+ upb_inttable dispatch;
+};
+
+struct upb_pbdecoder {
+ upb_env *env;
+
+ /* Our input sink. */
+ upb_bytessink input_;
+
+ /* The decoder method we are parsing with (owned). */
+ const upb_pbdecodermethod *method_;
+
+ size_t call_len;
+ const uint32_t *pc, *last;
+
+ /* Current input buffer and its stream offset. */
+ const char *buf, *ptr, *end, *checkpoint;
+
+ /* End of the delimited region, relative to ptr, NULL if not in this buf. */
+ const char *delim_end;
+
+ /* End of the delimited region, relative to ptr, end if not in this buf. */
+ const char *data_end;
+
+ /* Overall stream offset of "buf." */
+ uint64_t bufstart_ofs;
+
+ /* Buffer for residual bytes not parsed from the previous buffer. */
+ char residual[UPB_DECODER_MAX_RESIDUAL_BYTES];
+ char *residual_end;
+
+ /* Bytes of data that should be discarded from the input beore we start
+ * parsing again. We set this when we internally determine that we can
+ * safely skip the next N bytes, but this region extends past the current
+ * user buffer. */
+ size_t skip;
+
+ /* Stores the user buffer passed to our decode function. */
+ const char *buf_param;
+ size_t size_param;
+ const upb_bufhandle *handle;
+
+ /* Our internal stack. */
+ upb_pbdecoder_frame *stack, *top, *limit;
+ const uint32_t **callstack;
+ size_t stack_size;
+
+ upb_status *status;
+
+#ifdef UPB_USE_JIT_X64
+ /* Used momentarily by the generated code to store a value while a user
+ * function is called. */
+ uint32_t tmp_len;
+
+ const void *saved_rsp;
+#endif
+};
+
+/* Decoder entry points; used as handlers. */
+void *upb_pbdecoder_startbc(void *closure, const void *pc, size_t size_hint);
+void *upb_pbdecoder_startjit(void *closure, const void *hd, size_t size_hint);
+size_t upb_pbdecoder_decode(void *closure, const void *hd, const char *buf,
+ size_t size, const upb_bufhandle *handle);
+bool upb_pbdecoder_end(void *closure, const void *handler_data);
+
+/* Decoder-internal functions that the JIT calls to handle fallback paths. */
+int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf,
+ size_t size, const upb_bufhandle *handle);
+size_t upb_pbdecoder_suspend(upb_pbdecoder *d);
+int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum,
+ uint8_t wire_type);
+int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d, uint64_t expected);
+int32_t upb_pbdecoder_decode_varint_slow(upb_pbdecoder *d, uint64_t *u64);
+int32_t upb_pbdecoder_decode_f32(upb_pbdecoder *d, uint32_t *u32);
+int32_t upb_pbdecoder_decode_f64(upb_pbdecoder *d, uint64_t *u64);
+void upb_pbdecoder_seterr(upb_pbdecoder *d, const char *msg);
+
+/* Error messages that are shared between the bytecode and JIT decoders. */
+extern const char *kPbDecoderStackOverflow;
+extern const char *kPbDecoderSubmessageTooLong;
+
+/* Access to decoderplan members needed by the decoder. */
+const char *upb_pbdecoder_getopname(unsigned int op);
+
+/* JIT codegen entry point. */
+void upb_pbdecoder_jit(mgroup *group);
+void upb_pbdecoder_freejit(mgroup *group);
+UPB_REFCOUNTED_CMETHODS(mgroup, mgroup_upcast)
+
+/* A special label that means "do field dispatch for this message and branch to
+ * wherever that takes you." */
+#define LABEL_DISPATCH 0
+
+/* A special slot in the dispatch table that stores the epilogue (ENDMSG and/or
+ * RET) for branching to when we find an appropriate ENDGROUP tag. */
+#define DISPATCH_ENDMSG 0
+
+/* It's important to use this invalid wire type instead of 0 (which is a valid
+ * wire type). */
+#define NO_WIRE_TYPE 0xff
+
+/* The dispatch table layout is:
+ * [field number] -> [ 48-bit offset ][ 8-bit wt2 ][ 8-bit wt1 ]
+ *
+ * If wt1 matches, jump to the 48-bit offset. If wt2 matches, lookup
+ * (UPB_MAX_FIELDNUMBER + fieldnum) and jump there.
+ *
+ * We need two wire types because of packed/non-packed compatibility. A
+ * primitive repeated field can use either wire type and be valid. While we
+ * could key the table on fieldnum+wiretype, the table would be 8x sparser.
+ *
+ * Storing two wire types in the primary value allows us to quickly rule out
+ * the second wire type without needing to do a separate lookup (this case is
+ * less common than an unknown field). */
+UPB_INLINE uint64_t upb_pbdecoder_packdispatch(uint64_t ofs, uint8_t wt1,
+ uint8_t wt2) {
+ return (ofs << 16) | (wt2 << 8) | wt1;
+}
+
+UPB_INLINE void upb_pbdecoder_unpackdispatch(uint64_t dispatch, uint64_t *ofs,
+ uint8_t *wt1, uint8_t *wt2) {
+ *wt1 = (uint8_t)dispatch;
+ *wt2 = (uint8_t)(dispatch >> 8);
+ *ofs = dispatch >> 16;
+}
+
+/* All of the functions in decoder.c that return int32_t return values according
+ * to the following scheme:
+ * 1. negative values indicate a return code from the following list.
+ * 2. positive values indicate that error or end of buffer was hit, and
+ * that the decode function should immediately return the given value
+ * (the decoder state has already been suspended and is ready to be
+ * resumed). */
+#define DECODE_OK -1
+#define DECODE_MISMATCH -2 /* Used only from checktag_slow(). */
+#define DECODE_ENDGROUP -3 /* Used only from checkunknown(). */
+
+#define CHECK_RETURN(x) { int32_t ret = x; if (ret >= 0) return ret; }
+
+#endif /* UPB_DECODER_INT_H_ */
+/*
+** A number of routines for varint manipulation (we keep them all around to
+** have multiple approaches available for benchmarking).
+*/
+
+#ifndef UPB_VARINT_DECODER_H_
+#define UPB_VARINT_DECODER_H_
+
+#include <assert.h>
+#include <stdint.h>
+#include <string.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* A list of types as they are encoded on-the-wire. */
+typedef enum {
+ UPB_WIRE_TYPE_VARINT = 0,
+ UPB_WIRE_TYPE_64BIT = 1,
+ UPB_WIRE_TYPE_DELIMITED = 2,
+ UPB_WIRE_TYPE_START_GROUP = 3,
+ UPB_WIRE_TYPE_END_GROUP = 4,
+ UPB_WIRE_TYPE_32BIT = 5
+} upb_wiretype_t;
+
+#define UPB_MAX_WIRE_TYPE 5
+
+/* The maximum number of bytes that it takes to encode a 64-bit varint.
+ * Note that with a better encoding this could be 9 (TODO: write up a
+ * wiki document about this). */
+#define UPB_PB_VARINT_MAX_LEN 10
+
+/* Array of the "native" (ie. non-packed-repeated) wire type for the given a
+ * descriptor type (upb_descriptortype_t). */
+extern const uint8_t upb_pb_native_wire_types[];
+
+/* Zig-zag encoding/decoding **************************************************/
+
+UPB_INLINE int32_t upb_zzdec_32(uint32_t n) {
+ return (n >> 1) ^ -(int32_t)(n & 1);
+}
+UPB_INLINE int64_t upb_zzdec_64(uint64_t n) {
+ return (n >> 1) ^ -(int64_t)(n & 1);
+}
+UPB_INLINE uint32_t upb_zzenc_32(int32_t n) { return (n << 1) ^ (n >> 31); }
+UPB_INLINE uint64_t upb_zzenc_64(int64_t n) { return (n << 1) ^ (n >> 63); }
+
+/* Decoding *******************************************************************/
+
+/* All decoding functions return this struct by value. */
+typedef struct {
+ const char *p; /* NULL if the varint was unterminated. */
+ uint64_t val;
+} upb_decoderet;
+
+UPB_INLINE upb_decoderet upb_decoderet_make(const char *p, uint64_t val) {
+ upb_decoderet ret;
+ ret.p = p;
+ ret.val = val;
+ return ret;
+}
+
+/* Four functions for decoding a varint of at most eight bytes. They are all
+ * functionally identical, but are implemented in different ways and likely have
+ * different performance profiles. We keep them around for performance testing.
+ *
+ * Note that these functions may not read byte-by-byte, so they must not be used
+ * unless there are at least eight bytes left in the buffer! */
+upb_decoderet upb_vdecode_max8_branch32(upb_decoderet r);
+upb_decoderet upb_vdecode_max8_branch64(upb_decoderet r);
+upb_decoderet upb_vdecode_max8_wright(upb_decoderet r);
+upb_decoderet upb_vdecode_max8_massimino(upb_decoderet r);
+
+/* Template for a function that checks the first two bytes with branching
+ * and dispatches 2-10 bytes with a separate function. Note that this may read
+ * up to 10 bytes, so it must not be used unless there are at least ten bytes
+ * left in the buffer! */
+#define UPB_VARINT_DECODER_CHECK2(name, decode_max8_function) \
+UPB_INLINE upb_decoderet upb_vdecode_check2_ ## name(const char *_p) { \
+ uint8_t *p = (uint8_t*)_p; \
+ upb_decoderet r; \
+ if ((*p & 0x80) == 0) { \
+ /* Common case: one-byte varint. */ \
+ return upb_decoderet_make(_p + 1, *p & 0x7fU); \
+ } \
+ r = upb_decoderet_make(_p + 2, (*p & 0x7fU) | ((*(p + 1) & 0x7fU) << 7)); \
+ if ((*(p + 1) & 0x80) == 0) { \
+ /* Two-byte varint. */ \
+ return r; \
+ } \
+ /* Longer varint, fallback to out-of-line function. */ \
+ return decode_max8_function(r); \
+}
+
+UPB_VARINT_DECODER_CHECK2(branch32, upb_vdecode_max8_branch32)
+UPB_VARINT_DECODER_CHECK2(branch64, upb_vdecode_max8_branch64)
+UPB_VARINT_DECODER_CHECK2(wright, upb_vdecode_max8_wright)
+UPB_VARINT_DECODER_CHECK2(massimino, upb_vdecode_max8_massimino)
+#undef UPB_VARINT_DECODER_CHECK2
+
+/* Our canonical functions for decoding varints, based on the currently
+ * favored best-performing implementations. */
+UPB_INLINE upb_decoderet upb_vdecode_fast(const char *p) {
+ if (sizeof(long) == 8)
+ return upb_vdecode_check2_branch64(p);
+ else
+ return upb_vdecode_check2_branch32(p);
+}
+
+UPB_INLINE upb_decoderet upb_vdecode_max8_fast(upb_decoderet r) {
+ return upb_vdecode_max8_massimino(r);
+}
+
+
+/* Encoding *******************************************************************/
+
+UPB_INLINE int upb_value_size(uint64_t val) {
+#ifdef __GNUC__
+ int high_bit = 63 - __builtin_clzll(val); /* 0-based, undef if val == 0. */
+#else
+ int high_bit = 0;
+ uint64_t tmp = val;
+ while(tmp >>= 1) high_bit++;
+#endif
+ return val == 0 ? 1 : high_bit / 8 + 1;
+}
+
+/* Encodes a 64-bit varint into buf (which must be >=UPB_PB_VARINT_MAX_LEN
+ * bytes long), returning how many bytes were used.
+ *
+ * TODO: benchmark and optimize if necessary. */
+UPB_INLINE size_t upb_vencode64(uint64_t val, char *buf) {
+ size_t i;
+ if (val == 0) { buf[0] = 0; return 1; }
+ i = 0;
+ while (val) {
+ uint8_t byte = val & 0x7fU;
+ val >>= 7;
+ if (val) byte |= 0x80U;
+ buf[i++] = byte;
+ }
+ return i;
+}
+
+UPB_INLINE size_t upb_varint_size(uint64_t val) {
+ char buf[UPB_PB_VARINT_MAX_LEN];
+ return upb_vencode64(val, buf);
+}
+
+/* Encodes a 32-bit varint, *not* sign-extended. */
+UPB_INLINE uint64_t upb_vencode32(uint32_t val) {
+ char buf[UPB_PB_VARINT_MAX_LEN];
+ size_t bytes = upb_vencode64(val, buf);
+ uint64_t ret = 0;
+ UPB_ASSERT(bytes <= 5);
+ memcpy(&ret, buf, bytes);
+ UPB_ASSERT(ret <= 0xffffffffffU);
+ return ret;
+}
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* UPB_VARINT_DECODER_H_ */
+/*
+** upb::pb::Encoder (upb_pb_encoder)
+**
+** Implements a set of upb_handlers that write protobuf data to the binary wire
+** format.
+**
+** This encoder implementation does not have any access to any out-of-band or
+** precomputed lengths for submessages, so it must buffer submessages internally
+** before it can emit the first byte.
+*/
+
+#ifndef UPB_ENCODER_H_
+#define UPB_ENCODER_H_
+
+
+#ifdef __cplusplus
+namespace upb {
+namespace pb {
+class Encoder;
+} /* namespace pb */
+} /* namespace upb */
+#endif
+
+UPB_DECLARE_TYPE(upb::pb::Encoder, upb_pb_encoder)
+
+#define UPB_PBENCODER_MAX_NESTING 100
+
+/* upb::pb::Encoder ***********************************************************/
+
+/* Preallocation hint: decoder won't allocate more bytes than this when first
+ * constructed. This hint may be an overestimate for some build configurations.
+ * But if the decoder library is upgraded without recompiling the application,
+ * it may be an underestimate. */
+#define UPB_PB_ENCODER_SIZE 768
+
+#ifdef __cplusplus
+
+class upb::pb::Encoder {
+ public:
+ /* Creates a new encoder in the given environment. The Handlers must have
+ * come from NewHandlers() below. */
+ static Encoder* Create(Environment* env, const Handlers* handlers,
+ BytesSink* output);
+
+ /* The input to the encoder. */
+ Sink* input();
+
+ /* Creates a new set of handlers for this MessageDef. */
+ static reffed_ptr<const Handlers> NewHandlers(const MessageDef* msg);
+
+ static const size_t kSize = UPB_PB_ENCODER_SIZE;
+
+ private:
+ UPB_DISALLOW_POD_OPS(Encoder, upb::pb::Encoder)
+};
+
+#endif
+
+UPB_BEGIN_EXTERN_C
+
+const upb_handlers *upb_pb_encoder_newhandlers(const upb_msgdef *m,
+ const void *owner);
+upb_sink *upb_pb_encoder_input(upb_pb_encoder *p);
+upb_pb_encoder* upb_pb_encoder_create(upb_env* e, const upb_handlers* h,
+ upb_bytessink* output);
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+namespace upb {
+namespace pb {
+inline Encoder* Encoder::Create(Environment* env, const Handlers* handlers,
+ BytesSink* output) {
+ return upb_pb_encoder_create(env, handlers, output);
+}
+inline Sink* Encoder::input() {
+ return upb_pb_encoder_input(this);
+}
+inline reffed_ptr<const Handlers> Encoder::NewHandlers(
+ const upb::MessageDef *md) {
+ const Handlers* h = upb_pb_encoder_newhandlers(md, &h);
+ return reffed_ptr<const Handlers>(h, &h);
+}
+} /* namespace pb */
+} /* namespace upb */
+
+#endif
+
+#endif /* UPB_ENCODER_H_ */
+/*
+** upb's core components like upb_decoder and upb_msg are carefully designed to
+** avoid depending on each other for maximum orthogonality. In other words,
+** you can use a upb_decoder to decode into *any* kind of structure; upb_msg is
+** just one such structure. A upb_msg can be serialized/deserialized into any
+** format, protobuf binary format is just one such format.
+**
+** However, for convenience we provide functions here for doing common
+** operations like deserializing protobuf binary format into a upb_msg. The
+** compromise is that this file drags in almost all of upb as a dependency,
+** which could be undesirable if you're trying to use a trimmed-down build of
+** upb.
+**
+** While these routines are convenient, they do not reuse any encoding/decoding
+** state. For example, if a decoder is JIT-based, it will be re-JITted every
+** time these functions are called. For this reason, if you are parsing lots
+** of data and efficiency is an issue, these may not be the best functions to
+** use (though they are useful for prototyping, before optimizing).
+*/
+
+#ifndef UPB_GLUE_H
+#define UPB_GLUE_H
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+#include <vector>
+
+extern "C" {
+#endif
+
+/* Loads a binary descriptor and returns a NULL-terminated array of unfrozen
+ * filedefs. The caller owns the returned array, which must be freed with
+ * upb_gfree(). */
+upb_filedef **upb_loaddescriptor(const char *buf, size_t n, const void *owner,
+ upb_status *status);
+
+#ifdef __cplusplus
+} /* extern "C" */
+
+namespace upb {
+
+inline bool LoadDescriptor(const char* buf, size_t n, Status* status,
+ std::vector<reffed_ptr<FileDef> >* files) {
+ FileDef** parsed_files = upb_loaddescriptor(buf, n, &parsed_files, status);
+
+ if (parsed_files) {
+ FileDef** p = parsed_files;
+ while (*p) {
+ files->push_back(reffed_ptr<FileDef>(*p, &parsed_files));
+ ++p;
+ }
+ free(parsed_files);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/* Templated so it can accept both string and std::string. */
+template <typename T>
+bool LoadDescriptor(const T& desc, Status* status,
+ std::vector<reffed_ptr<FileDef> >* files) {
+ return LoadDescriptor(desc.c_str(), desc.size(), status, files);
+}
+
+} /* namespace upb */
+
+#endif
+
+#endif /* UPB_GLUE_H */
+/*
+** upb::pb::TextPrinter (upb_textprinter)
+**
+** Handlers for writing to protobuf text format.
+*/
+
+#ifndef UPB_TEXT_H_
+#define UPB_TEXT_H_
+
+
+#ifdef __cplusplus
+namespace upb {
+namespace pb {
+class TextPrinter;
+} /* namespace pb */
+} /* namespace upb */
+#endif
+
+UPB_DECLARE_TYPE(upb::pb::TextPrinter, upb_textprinter)
+
+#ifdef __cplusplus
+
+class upb::pb::TextPrinter {
+ public:
+ /* The given handlers must have come from NewHandlers(). It must outlive the
+ * TextPrinter. */
+ static TextPrinter *Create(Environment *env, const upb::Handlers *handlers,
+ BytesSink *output);
+
+ void SetSingleLineMode(bool single_line);
+
+ Sink* input();
+
+ /* If handler caching becomes a requirement we can add a code cache as in
+ * decoder.h */
+ static reffed_ptr<const Handlers> NewHandlers(const MessageDef* md);
+};
+
+#endif
+
+UPB_BEGIN_EXTERN_C
+
+/* C API. */
+upb_textprinter *upb_textprinter_create(upb_env *env, const upb_handlers *h,
+ upb_bytessink *output);
+void upb_textprinter_setsingleline(upb_textprinter *p, bool single_line);
+upb_sink *upb_textprinter_input(upb_textprinter *p);
+
+const upb_handlers *upb_textprinter_newhandlers(const upb_msgdef *m,
+ const void *owner);
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+namespace upb {
+namespace pb {
+inline TextPrinter *TextPrinter::Create(Environment *env,
+ const upb::Handlers *handlers,
+ BytesSink *output) {
+ return upb_textprinter_create(env, handlers, output);
+}
+inline void TextPrinter::SetSingleLineMode(bool single_line) {
+ upb_textprinter_setsingleline(this, single_line);
+}
+inline Sink* TextPrinter::input() {
+ return upb_textprinter_input(this);
+}
+inline reffed_ptr<const Handlers> TextPrinter::NewHandlers(
+ const MessageDef *md) {
+ const Handlers* h = upb_textprinter_newhandlers(md, &h);
+ return reffed_ptr<const Handlers>(h, &h);
+}
+} /* namespace pb */
+} /* namespace upb */
+
+#endif
+
+#endif /* UPB_TEXT_H_ */
+/*
+** upb::json::Parser (upb_json_parser)
+**
+** Parses JSON according to a specific schema.
+** Support for parsing arbitrary JSON (schema-less) will be added later.
+*/
+
+#ifndef UPB_JSON_PARSER_H_
+#define UPB_JSON_PARSER_H_
+
+
+#ifdef __cplusplus
+namespace upb {
+namespace json {
+class Parser;
+class ParserMethod;
+} /* namespace json */
+} /* namespace upb */
+#endif
+
+UPB_DECLARE_TYPE(upb::json::Parser, upb_json_parser)
+UPB_DECLARE_DERIVED_TYPE(upb::json::ParserMethod, upb::RefCounted,
+ upb_json_parsermethod, upb_refcounted)
+
+/* upb::json::Parser **********************************************************/
+
+/* Preallocation hint: parser won't allocate more bytes than this when first
+ * constructed. This hint may be an overestimate for some build configurations.
+ * But if the parser library is upgraded without recompiling the application,
+ * it may be an underestimate. */
+#define UPB_JSON_PARSER_SIZE 4112
+
+#ifdef __cplusplus
+
+/* Parses an incoming BytesStream, pushing the results to the destination
+ * sink. */
+class upb::json::Parser {
+ public:
+ static Parser* Create(Environment* env, const ParserMethod* method,
+ Sink* output);
+
+ BytesSink* input();
+
+ private:
+ UPB_DISALLOW_POD_OPS(Parser, upb::json::Parser)
+};
+
+class upb::json::ParserMethod {
+ public:
+ /* Include base methods from upb::ReferenceCounted. */
+ UPB_REFCOUNTED_CPPMETHODS
+
+ /* Returns handlers for parsing according to the specified schema. */
+ static reffed_ptr<const ParserMethod> New(const upb::MessageDef* md);
+
+ /* The destination handlers that are statically bound to this method.
+ * This method is only capable of outputting to a sink that uses these
+ * handlers. */
+ const Handlers* dest_handlers() const;
+
+ /* The input handlers for this decoder method. */
+ const BytesHandler* input_handler() const;
+
+ private:
+ UPB_DISALLOW_POD_OPS(ParserMethod, upb::json::ParserMethod)
+};
+
+#endif
+
+UPB_BEGIN_EXTERN_C
+
+upb_json_parser* upb_json_parser_create(upb_env* e,
+ const upb_json_parsermethod* m,
+ upb_sink* output);
+upb_bytessink *upb_json_parser_input(upb_json_parser *p);
+
+upb_json_parsermethod* upb_json_parsermethod_new(const upb_msgdef* md,
+ const void* owner);
+const upb_handlers *upb_json_parsermethod_desthandlers(
+ const upb_json_parsermethod *m);
+const upb_byteshandler *upb_json_parsermethod_inputhandler(
+ const upb_json_parsermethod *m);
+
+/* Include refcounted methods like upb_json_parsermethod_ref(). */
+UPB_REFCOUNTED_CMETHODS(upb_json_parsermethod, upb_json_parsermethod_upcast)
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+namespace upb {
+namespace json {
+inline Parser* Parser::Create(Environment* env, const ParserMethod* method,
+ Sink* output) {
+ return upb_json_parser_create(env, method, output);
+}
+inline BytesSink* Parser::input() {
+ return upb_json_parser_input(this);
+}
+
+inline const Handlers* ParserMethod::dest_handlers() const {
+ return upb_json_parsermethod_desthandlers(this);
+}
+inline const BytesHandler* ParserMethod::input_handler() const {
+ return upb_json_parsermethod_inputhandler(this);
+}
+/* static */
+inline reffed_ptr<const ParserMethod> ParserMethod::New(
+ const MessageDef* md) {
+ const upb_json_parsermethod *m = upb_json_parsermethod_new(md, &m);
+ return reffed_ptr<const ParserMethod>(m, &m);
+}
+
+} /* namespace json */
+} /* namespace upb */
+
+#endif
+
+
+#endif /* UPB_JSON_PARSER_H_ */
+/*
+** upb::json::Printer
+**
+** Handlers that emit JSON according to a specific protobuf schema.
+*/
+
+#ifndef UPB_JSON_TYPED_PRINTER_H_
+#define UPB_JSON_TYPED_PRINTER_H_
+
+
+#ifdef __cplusplus
+namespace upb {
+namespace json {
+class Printer;
+} /* namespace json */
+} /* namespace upb */
+#endif
+
+UPB_DECLARE_TYPE(upb::json::Printer, upb_json_printer)
+
+
+/* upb::json::Printer *********************************************************/
+
+#define UPB_JSON_PRINTER_SIZE 176
+
+#ifdef __cplusplus
+
+/* Prints an incoming stream of data to a BytesSink in JSON format. */
+class upb::json::Printer {
+ public:
+ static Printer* Create(Environment* env, const upb::Handlers* handlers,
+ BytesSink* output);
+
+ /* The input to the printer. */
+ Sink* input();
+
+ /* Returns handlers for printing according to the specified schema.
+ * If preserve_proto_fieldnames is true, the output JSON will use the
+ * original .proto field names (ie. {"my_field":3}) instead of using
+ * camelCased names, which is the default: (eg. {"myField":3}). */
+ static reffed_ptr<const Handlers> NewHandlers(const upb::MessageDef* md,
+ bool preserve_proto_fieldnames);
+
+ static const size_t kSize = UPB_JSON_PRINTER_SIZE;
+
+ private:
+ UPB_DISALLOW_POD_OPS(Printer, upb::json::Printer)
+};
+
+#endif
+
+UPB_BEGIN_EXTERN_C
+
+/* Native C API. */
+upb_json_printer *upb_json_printer_create(upb_env *e, const upb_handlers *h,
+ upb_bytessink *output);
+upb_sink *upb_json_printer_input(upb_json_printer *p);
+const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md,
+ bool preserve_fieldnames,
+ const void *owner);
+
+UPB_END_EXTERN_C
+
+#ifdef __cplusplus
+
+namespace upb {
+namespace json {
+inline Printer* Printer::Create(Environment* env, const upb::Handlers* handlers,
+ BytesSink* output) {
+ return upb_json_printer_create(env, handlers, output);
+}
+inline Sink* Printer::input() { return upb_json_printer_input(this); }
+inline reffed_ptr<const Handlers> Printer::NewHandlers(
+ const upb::MessageDef *md, bool preserve_proto_fieldnames) {
+ const Handlers* h = upb_json_printer_newhandlers(
+ md, preserve_proto_fieldnames, &h);
+ return reffed_ptr<const Handlers>(h, &h);
+}
+} /* namespace json */
+} /* namespace upb */
+
+#endif
+
+#endif /* UPB_JSON_TYPED_PRINTER_H_ */
diff --git a/third_party/protobuf/ruby/ext/google/protobuf_c/wrap_memcpy.c b/third_party/protobuf/ruby/ext/google/protobuf_c/wrap_memcpy.c
new file mode 100644
index 0000000000..394a52f9f6
--- /dev/null
+++ b/third_party/protobuf/ruby/ext/google/protobuf_c/wrap_memcpy.c
@@ -0,0 +1,51 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2017 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 <string.h>
+
+// On x86-64 Linux with glibc, we link against the 2.2.5 version of memcpy so
+// that we avoid depending on the 2.14 version of the symbol. This way,
+// distributions that are using pre-2.14 versions of glibc can successfully use
+// the gem we distribute (https://github.com/google/protobuf/issues/2783).
+//
+// This wrapper is enabled by passing the linker flags -Wl,-wrap,memcpy in
+// extconf.rb.
+#ifdef __linux__
+#if defined(__x86_64__) && defined(__GNU_LIBRARY__)
+__asm__(".symver memcpy,memcpy@GLIBC_2.2.5");
+void *__wrap_memcpy(void *dest, const void *src, size_t n) {
+ return memcpy(dest, src, n);
+}
+#else
+void *__wrap_memcpy(void *dest, const void *src, size_t n) {
+ return memmove(dest, src, n);
+}
+#endif
+#endif
diff --git a/third_party/protobuf/ruby/google-protobuf.gemspec b/third_party/protobuf/ruby/google-protobuf.gemspec
new file mode 100644
index 0000000000..1e30ae4d7d
--- /dev/null
+++ b/third_party/protobuf/ruby/google-protobuf.gemspec
@@ -0,0 +1,26 @@
+Gem::Specification.new do |s|
+ s.name = "google-protobuf"
+ s.version = "3.2.0.1"
+ s.licenses = ["BSD-3-Clause"]
+ s.summary = "Protocol Buffers"
+ s.description = "Protocol Buffers are Google's data interchange format."
+ s.homepage = "https://developers.google.com/protocol-buffers"
+ s.authors = ["Protobuf Authors"]
+ s.email = "protobuf@googlegroups.com"
+ s.require_paths = ["lib"]
+ s.files = Dir.glob('lib/**/*.rb')
+ if RUBY_PLATFORM == "java"
+ s.platform = "java"
+ s.files += ["lib/google/protobuf_java.jar"]
+ else
+ s.files += Dir.glob('ext/**/*')
+ s.extensions= ["ext/google/protobuf_c/extconf.rb"]
+ s.add_development_dependency "rake-compiler-dock", "~> 0.6.0"
+ end
+ s.test_files = ["tests/basic.rb",
+ "tests/stress.rb",
+ "tests/generated_code_test.rb"]
+ s.add_development_dependency "rake-compiler", "~> 0.9.5"
+ s.add_development_dependency "test-unit", '~> 3.0', '>= 3.0.9'
+ s.add_development_dependency "rubygems-tasks", "~> 0.2.4"
+end
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/arena_nc_test.py b/third_party/protobuf/ruby/lib/google/protobuf.rb
index 56a7dd05aa..9b8d8231e2 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/arena_nc_test.py
+++ b/third_party/protobuf/ruby/lib/google/protobuf.rb
@@ -1,5 +1,3 @@
-#! /usr/bin/env python
-#
# Protocol Buffers - Google's data interchange format
# Copyright 2008 Google Inc. All rights reserved.
# https://developers.google.com/protocol-buffers/
@@ -30,32 +28,49 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-"""Negative compilation unit tests for arena API."""
+# require mixins before we hook them into the java & c code
+require 'google/protobuf/message_exts'
+
+# We define these before requiring the platform-specific modules.
+# That way the module init can grab references to these.
+module Google
+ module Protobuf
+ class Error < StandardError; end
+ class ParseError < Error; end
+ end
+end
-import unittest
+if RUBY_PLATFORM == "java"
+ require 'json'
+ require 'google/protobuf_java'
+else
+ begin
+ require "google/#{RUBY_VERSION.sub(/\.\d+$/, '')}/protobuf_c"
+ rescue LoadError
+ require 'google/protobuf_c'
+ end
+end
-from google3.testing.pybase import fake_target_util
-from google3.testing.pybase import unittest
+require 'google/protobuf/repeated_field'
+module Google
+ module Protobuf
-class ArenaNcTest(unittest.TestCase):
+ def self.encode(msg)
+ msg.to_proto
+ end
- def testCompilerErrors(self):
- """Runs a list of tests to verify compiler error messages."""
+ def self.encode_json(msg)
+ msg.to_json
+ end
- # Defines a list of test specs, where each element is a tuple
- # (test name, list of regexes for matching the compiler errors).
- test_specs = [
- ('ARENA_PRIVATE_CONSTRUCTOR',
- [r'calling a protected constructor']),
- ('SANITY', None)]
+ def self.decode(klass, proto)
+ klass.decode(proto)
+ end
- fake_target_util.AssertCcCompilerErrors(
- self, # The current test case.
- 'google3/google/protobuf/arena_nc', # The fake target file.
- 'arena_nc.o', # The sub-target to build.
- test_specs # List of test specifications.
- )
+ def self.decode_json(klass, json)
+ klass.decode_json(json)
+ end
-if __name__ == '__main__':
- unittest.main()
+ end
+end
diff --git a/third_party/protobuf/ruby/lib/google/protobuf/message_exts.rb b/third_party/protobuf/ruby/lib/google/protobuf/message_exts.rb
new file mode 100644
index 0000000000..e10266ba2f
--- /dev/null
+++ b/third_party/protobuf/ruby/lib/google/protobuf/message_exts.rb
@@ -0,0 +1,53 @@
+# 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.
+
+module Google
+ module Protobuf
+ module MessageExts
+
+ #this is only called in jruby; mri loades the ClassMethods differently
+ def self.included(klass)
+ klass.extend(ClassMethods)
+ end
+
+ module ClassMethods
+ end
+
+ def to_json
+ self.class.encode_json(self)
+ end
+
+ def to_proto
+ self.class.encode(self)
+ end
+
+ end
+ end
+end
diff --git a/third_party/protobuf/ruby/lib/google/protobuf/repeated_field.rb b/third_party/protobuf/ruby/lib/google/protobuf/repeated_field.rb
new file mode 100644
index 0000000000..11d6c2eb8c
--- /dev/null
+++ b/third_party/protobuf/ruby/lib/google/protobuf/repeated_field.rb
@@ -0,0 +1,188 @@
+# 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.
+
+require 'forwardable'
+
+#
+# This class makes RepeatedField act (almost-) like a Ruby Array.
+# It has convenience methods that extend the core C or Java based
+# methods.
+#
+# This is a best-effort to mirror Array behavior. Two comments:
+# 1) patches always welcome :)
+# 2) if performance is an issue, feel free to rewrite the method
+# in jruby and C. The source code has plenty of examples
+#
+# KNOWN ISSUES
+# - #[]= doesn't allow less used approaches such as `arr[1, 2] = 'fizz'`
+# - #concat should return the orig array
+# - #push should accept multiple arguments and push them all at the same time
+#
+module Google
+ module Protobuf
+ class RepeatedField
+ extend Forwardable
+
+ # methods defined in C or Java:
+ # +
+ # [], at
+ # []=
+ # concat
+ # clear
+ # dup, clone
+ # each
+ # push, <<
+ # replace
+ # length, size
+ # ==
+ # to_ary, to_a
+ # also all enumerable
+ #
+ # NOTE: using delegators rather than method_missing to make the
+ # relationship explicit instead of implicit
+ def_delegators :to_ary,
+ :&, :*, :-, :'<=>',
+ :assoc, :bsearch, :bsearch_index, :combination, :compact, :count,
+ :cycle, :dig, :drop, :drop_while, :eql?, :fetch, :find_index, :flatten,
+ :include?, :index, :inspect, :join,
+ :pack, :permutation, :product, :pretty_print, :pretty_print_cycle,
+ :rassoc, :repeated_combination, :repeated_permutation, :reverse,
+ :rindex, :rotate, :sample, :shuffle, :shelljoin,
+ :to_s, :transpose, :uniq, :|
+
+
+ def first(n=nil)
+ n ? self[0..n] : self[0]
+ end
+
+
+ def last(n=nil)
+ n ? self[(self.size-n-1)..-1] : self[-1]
+ end
+
+
+ def pop(n=nil)
+ if n
+ results = []
+ n.times{ results << pop_one }
+ return results
+ else
+ return pop_one
+ end
+ end
+
+
+ def empty?
+ self.size == 0
+ end
+
+ # array aliases into enumerable
+ alias_method :each_index, :each_with_index
+ alias_method :slice, :[]
+ alias_method :values_at, :select
+ alias_method :map, :collect
+
+
+ class << self
+ def define_array_wrapper_method(method_name)
+ define_method(method_name) do |*args, &block|
+ arr = self.to_a
+ result = arr.send(method_name, *args)
+ self.replace(arr)
+ return result if result
+ return block ? block.call : result
+ end
+ end
+ private :define_array_wrapper_method
+
+
+ def define_array_wrapper_with_result_method(method_name)
+ define_method(method_name) do |*args, &block|
+ # result can be an Enumerator, Array, or nil
+ # Enumerator can sometimes be returned if a block is an optional argument and it is not passed in
+ # nil usually specifies that no change was made
+ result = self.to_a.send(method_name, *args, &block)
+ if result
+ new_arr = result.to_a
+ self.replace(new_arr)
+ if result.is_a?(Enumerator)
+ # generate a fresh enum; rewinding the exiting one, in Ruby 2.2, will
+ # reset the enum with the same length, but all the #next calls will
+ # return nil
+ result = new_arr.to_enum
+ # generate a wrapper enum so any changes which occur by a chained
+ # enum can be captured
+ ie = ProxyingEnumerator.new(self, result)
+ result = ie.to_enum
+ end
+ end
+ result
+ end
+ end
+ private :define_array_wrapper_with_result_method
+ end
+
+
+ %w(delete delete_at delete_if shift slice! unshift).each do |method_name|
+ define_array_wrapper_method(method_name)
+ end
+
+
+ %w(collect! compact! fill flatten! insert reverse!
+ rotate! select! shuffle! sort! sort_by! uniq!).each do |method_name|
+ define_array_wrapper_with_result_method(method_name)
+ end
+ alias_method :keep_if, :select!
+ alias_method :map!, :collect!
+ alias_method :reject!, :delete_if
+
+
+ # propagates changes made by user of enumerator back to the original repeated field.
+ # This only applies in cases where the calling function which created the enumerator,
+ # such as #sort!, modifies itself rather than a new array, such as #sort
+ class ProxyingEnumerator < Struct.new(:repeated_field, :external_enumerator)
+ def each(*args, &block)
+ results = []
+ external_enumerator.each_with_index do |val, i|
+ result = yield(val)
+ results << result
+ #nil means no change occurred from yield; usually occurs when #to_a is called
+ if result
+ repeated_field[i] = result if result != val
+ end
+ end
+ results
+ end
+ end
+
+
+ end
+ end
+end
diff --git a/third_party/protobuf/ruby/lib/google/protobuf/well_known_types.rb b/third_party/protobuf/ruby/lib/google/protobuf/well_known_types.rb
new file mode 100644
index 0000000000..547de87493
--- /dev/null
+++ b/third_party/protobuf/ruby/lib/google/protobuf/well_known_types.rb
@@ -0,0 +1,212 @@
+#!/usr/bin/ruby
+# 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.
+
+require 'google/protobuf/any_pb'
+require 'google/protobuf/duration_pb'
+require 'google/protobuf/field_mask_pb'
+require 'google/protobuf/struct_pb'
+require 'google/protobuf/timestamp_pb'
+
+module Google
+ module Protobuf
+
+ Any.class_eval do
+ def pack(msg, type_url_prefix='type.googleapis.com/')
+ if type_url_prefix.empty? or type_url_prefix[-1] != '/' then
+ self.type_url = "#{type_url_prefix}/#{msg.class.descriptor.name}"
+ else
+ self.type_url = "#{type_url_prefix}#{msg.class.descriptor.name}"
+ end
+ self.value = msg.to_proto
+ end
+
+ def unpack(klass)
+ if self.is(klass) then
+ klass.decode(self.value)
+ else
+ nil
+ end
+ end
+
+ def type_name
+ return self.type_url.split("/")[-1]
+ end
+
+ def is(klass)
+ return self.type_name == klass.descriptor.name
+ end
+ end
+
+ Timestamp.class_eval do
+ def to_time
+ Time.at(self.to_f)
+ end
+
+ def from_time(time)
+ self.seconds = time.to_i
+ self.nanos = time.nsec
+ end
+
+ def to_i
+ self.seconds
+ end
+
+ def to_f
+ self.seconds + (self.nanos.to_f / 1_000_000_000)
+ end
+ end
+
+ Duration.class_eval do
+ def to_f
+ self.seconds + (self.nanos.to_f / 1_000_000_000)
+ end
+ end
+
+ class UnexpectedStructType < Google::Protobuf::Error; end
+
+ Value.class_eval do
+ def to_ruby(recursive = false)
+ case self.kind
+ when :struct_value
+ if recursive
+ self.struct_value.to_h
+ else
+ self.struct_value
+ end
+ when :list_value
+ if recursive
+ self.list_value.to_a
+ else
+ self.list_value
+ end
+ when :null_value
+ nil
+ when :number_value
+ self.number_value
+ when :string_value
+ self.string_value
+ when :bool_value
+ self.bool_value
+ else
+ raise UnexpectedStructType
+ end
+ end
+
+ def from_ruby(value)
+ case value
+ when NilClass
+ self.null_value = 0
+ when Numeric
+ self.number_value = value
+ when String
+ self.string_value = value
+ when TrueClass
+ self.bool_value = true
+ when FalseClass
+ self.bool_value = false
+ when Struct
+ self.struct_value = value
+ when Hash
+ self.struct_value = Struct.from_hash(value)
+ when ListValue
+ self.list_value = value
+ when Array
+ self.list_value = ListValue.from_a(value)
+ else
+ raise UnexpectedStructType
+ end
+ end
+ end
+
+ Struct.class_eval do
+ def [](key)
+ self.fields[key].to_ruby
+ end
+
+ def []=(key, value)
+ unless key.is_a?(String)
+ raise UnexpectedStructType, "Struct keys must be strings."
+ end
+ self.fields[key] ||= Google::Protobuf::Value.new
+ self.fields[key].from_ruby(value)
+ end
+
+ def to_h
+ ret = {}
+ self.fields.each { |key, val| ret[key] = val.to_ruby(true) }
+ ret
+ end
+
+ def self.from_hash(hash)
+ ret = Struct.new
+ hash.each { |key, val| ret[key] = val }
+ ret
+ end
+ end
+
+ ListValue.class_eval do
+ include Enumerable
+
+ def length
+ self.values.length
+ end
+
+ def [](index)
+ self.values[index].to_ruby
+ end
+
+ def []=(index, value)
+ self.values[index].from_ruby(value)
+ end
+
+ def <<(value)
+ wrapper = Google::Protobuf::Value.new
+ wrapper.from_ruby(value)
+ self.values << wrapper
+ end
+
+ def each
+ self.values.each { |x| yield(x.to_ruby) }
+ end
+
+ def to_a
+ self.values.map { |x| x.to_ruby(true) }
+ end
+
+ def self.from_a(arr)
+ ret = ListValue.new
+ arr.each { |val| ret << val }
+ ret
+ end
+ end
+
+ end
+end
diff --git a/third_party/protobuf/ruby/pom.xml b/third_party/protobuf/ruby/pom.xml
new file mode 100644
index 0000000000..adf6ff207d
--- /dev/null
+++ b/third_party/protobuf/ruby/pom.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>com.google</groupId>
+ <artifactId>google</artifactId>
+ <version>1</version>
+ </parent>
+
+ <groupId>com.google.protobuf.jruby</groupId>
+ <artifactId>protobuf-jruby</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <name>Protocol Buffer JRuby native extension</name>
+ <description>
+ Protocol Buffers are a way of encoding structured data in an efficient yet
+ extensible format.
+ </description>
+ <inceptionYear>2014</inceptionYear>
+ <url>https://developers.google.com/protocol-buffers/</url>
+ <licenses>
+ <license>
+ <name>3-Clause BSD License</name>
+ <url>https://opensource.org/licenses/BSD-3-Clause</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+ <scm>
+ <url>https://github.com/google/protobuf</url>
+ <connection>
+ scm:git:https://github.com/google/protobuf.git
+ </connection>
+ </scm>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <ruby.sources>lib/google</ruby.sources>
+ <jar.finalName>protobuf_java</jar.finalName>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <finalName>${jar.finalName}</finalName>
+ <outputDirectory>${ruby.sources}</outputDirectory>
+ <appendAssemblyId>false</appendAssemblyId>
+ <descriptorRefs>
+ <descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ </configuration>
+ <executions>
+ <execution>
+ <id>make-assembly</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>2.4.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jruby</groupId>
+ <artifactId>jruby-complete</artifactId>
+ <version>1.7.13</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.protobuf</groupId>
+ <artifactId>protobuf-java</artifactId>
+ <version>3.0.0</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyBuilder.java b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyBuilder.java
new file mode 100644
index 0000000000..5addae58da
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyBuilder.java
@@ -0,0 +1,167 @@
+/*
+ * Protocol Buffers - Google's data interchange format
+ * Copyright 2014 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.jruby;
+
+import org.jruby.*;
+import org.jruby.anno.JRubyClass;
+import org.jruby.anno.JRubyMethod;
+import org.jruby.runtime.*;
+import org.jruby.runtime.builtin.IRubyObject;
+
+@JRubyClass(name = "Builder")
+public class RubyBuilder extends RubyObject {
+ public static void createRubyBuilder(Ruby runtime) {
+ RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
+ RubyClass cBuilder = protobuf.defineClassUnder("Builder", runtime.getObject(), new ObjectAllocator() {
+ @Override
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
+ return new RubyBuilder(runtime, klazz);
+ }
+ });
+ cBuilder.defineAnnotatedMethods(RubyBuilder.class);
+ }
+
+ public RubyBuilder(Ruby runtime, RubyClass metaClass) {
+ super(runtime, metaClass);
+ this.cDescriptor = (RubyClass) runtime.getClassFromPath("Google::Protobuf::Descriptor");
+ this.cEnumDescriptor = (RubyClass) runtime.getClassFromPath("Google::Protobuf::EnumDescriptor");
+ this.cMessageBuilderContext = (RubyClass) runtime.getClassFromPath("Google::Protobuf::MessageBuilderContext");
+ this.cEnumBuilderContext = (RubyClass) runtime.getClassFromPath("Google::Protobuf::EnumBuilderContext");
+ }
+
+ /*
+ * call-seq:
+ * Builder.new => builder
+ *
+ * Creates a new Builder. A Builder can accumulate a set of new message and enum
+ * descriptors and atomically register them into a pool in a way that allows for
+ * (co)recursive type references.
+ */
+ @JRubyMethod
+ public IRubyObject initialize(ThreadContext context) {
+ Ruby runtime = context.runtime;
+ this.pendingList = runtime.newArray();
+ return this;
+ }
+
+ /*
+ * call-seq:
+ * Builder.add_message(name, &block)
+ *
+ * Creates a new, empty descriptor with the given name, and invokes the block in
+ * the context of a MessageBuilderContext on that descriptor. The block can then
+ * call, e.g., MessageBuilderContext#optional and MessageBuilderContext#repeated
+ * methods to define the message fields.
+ *
+ * This is the recommended, idiomatic way to build message definitions.
+ */
+ @JRubyMethod(name = "add_message")
+ public IRubyObject addMessage(ThreadContext context, IRubyObject name, Block block) {
+ RubyDescriptor msgdef = (RubyDescriptor) cDescriptor.newInstance(context, Block.NULL_BLOCK);
+ IRubyObject ctx = cMessageBuilderContext.newInstance(context, msgdef, this, Block.NULL_BLOCK);
+ msgdef.setName(context, name);
+ if (block.isGiven()) {
+ if (block.arity() == Arity.ONE_ARGUMENT) {
+ block.yield(context, ctx);
+ } else {
+ Binding binding = block.getBinding();
+ binding.setSelf(ctx);
+ block.yieldSpecific(context);
+ }
+ }
+ this.pendingList.add(msgdef);
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * Builder.add_enum(name, &block)
+ *
+ * Creates a new, empty enum descriptor with the given name, and invokes the block in
+ * the context of an EnumBuilderContext on that descriptor. The block can then
+ * call EnumBuilderContext#add_value to define the enum values.
+ *
+ * This is the recommended, idiomatic way to build enum definitions.
+ */
+ @JRubyMethod(name = "add_enum")
+ public IRubyObject addEnum(ThreadContext context, IRubyObject name, Block block) {
+ RubyEnumDescriptor enumDef = (RubyEnumDescriptor) cEnumDescriptor.newInstance(context, Block.NULL_BLOCK);
+ IRubyObject ctx = cEnumBuilderContext.newInstance(context, enumDef, Block.NULL_BLOCK);
+ enumDef.setName(context, name);
+
+ if (block.isGiven()) {
+ if (block.arity() == Arity.ONE_ARGUMENT) {
+ block.yield(context, ctx);
+ } else {
+ Binding binding = block.getBinding();
+ binding.setSelf(ctx);
+ block.yieldSpecific(context);
+ }
+ }
+
+ this.pendingList.add(enumDef);
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * Builder.finalize_to_pool(pool)
+ *
+ * Adds all accumulated message and enum descriptors created in this builder
+ * context to the given pool. The operation occurs atomically, and all
+ * descriptors can refer to each other (including in cycles). This is the only
+ * way to build (co)recursive message definitions.
+ *
+ * This method is usually called automatically by DescriptorPool#build after it
+ * invokes the given user block in the context of the builder. The user should
+ * not normally need to call this manually because a Builder is not normally
+ * created manually.
+ */
+ @JRubyMethod(name = "finalize_to_pool")
+ public IRubyObject finalizeToPool(ThreadContext context, IRubyObject rbPool) {
+ RubyDescriptorPool pool = (RubyDescriptorPool) rbPool;
+ for (int i = 0; i < this.pendingList.size(); i++) {
+ IRubyObject defRb = this.pendingList.entry(i);
+ if (defRb instanceof RubyDescriptor) {
+ pool.addToSymtab(context, (RubyDescriptor) defRb);
+ } else {
+ pool.addToSymtab(context, (RubyEnumDescriptor) defRb);
+ }
+ }
+ this.pendingList = context.runtime.newArray();
+ return context.runtime.getNil();
+ }
+
+ protected RubyArray pendingList;
+ private RubyClass cDescriptor, cEnumDescriptor, cMessageBuilderContext, cEnumBuilderContext;
+}
diff --git a/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyDescriptor.java b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyDescriptor.java
new file mode 100644
index 0000000000..dd9179b030
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyDescriptor.java
@@ -0,0 +1,269 @@
+/*
+ * Protocol Buffers - Google's data interchange format
+ * Copyright 2014 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.jruby;
+
+import com.google.protobuf.DescriptorProtos;
+import com.google.protobuf.Descriptors;
+import org.jruby.*;
+import org.jruby.anno.JRubyClass;
+import org.jruby.anno.JRubyMethod;
+import org.jruby.runtime.Block;
+import org.jruby.runtime.ObjectAllocator;
+import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.builtin.IRubyObject;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+@JRubyClass(name = "Descriptor", include = "Enumerable")
+public class RubyDescriptor extends RubyObject {
+ public static void createRubyDescriptor(Ruby runtime) {
+ RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
+ RubyClass cDescriptor = protobuf.defineClassUnder("Descriptor", runtime.getObject(), new ObjectAllocator() {
+ @Override
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
+ return new RubyDescriptor(runtime, klazz);
+ }
+ });
+ cDescriptor.includeModule(runtime.getEnumerable());
+ cDescriptor.defineAnnotatedMethods(RubyDescriptor.class);
+ }
+
+ public RubyDescriptor(Ruby runtime, RubyClass klazz) {
+ super(runtime, klazz);
+ }
+
+ /*
+ * call-seq:
+ * Descriptor.new => descriptor
+ *
+ * Creates a new, empty, message type descriptor. At a minimum, its name must be
+ * set before it is added to a pool. It cannot be used to create messages until
+ * it is added to a pool, after which it becomes immutable (as part of a
+ * finalization process).
+ */
+ @JRubyMethod
+ public IRubyObject initialize(ThreadContext context) {
+ this.builder = DescriptorProtos.DescriptorProto.newBuilder();
+ this.fieldDefMap = new HashMap<String, RubyFieldDescriptor>();
+ this.oneofDefs = new HashMap<IRubyObject, RubyOneofDescriptor>();
+ return this;
+ }
+
+ /*
+ * call-seq:
+ * Descriptor.name => name
+ *
+ * Returns the name of this message type as a fully-qualfied string (e.g.,
+ * My.Package.MessageType).
+ */
+ @JRubyMethod(name = "name")
+ public IRubyObject getName(ThreadContext context) {
+ return this.name;
+ }
+
+ /*
+ * call-seq:
+ * Descriptor.name = name
+ *
+ * Assigns a name to this message type. The descriptor must not have been added
+ * to a pool yet.
+ */
+ @JRubyMethod(name = "name=")
+ public IRubyObject setName(ThreadContext context, IRubyObject name) {
+ this.name = name;
+ this.builder.setName(Utils.escapeIdentifier(this.name.asJavaString()));
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * Descriptor.add_field(field) => nil
+ *
+ * Adds the given FieldDescriptor to this message type. The descriptor must not
+ * have been added to a pool yet. Raises an exception if a field with the same
+ * name or number already exists. Sub-type references (e.g. for fields of type
+ * message) are not resolved at this point.
+ */
+ @JRubyMethod(name = "add_field")
+ public IRubyObject addField(ThreadContext context, IRubyObject obj) {
+ RubyFieldDescriptor fieldDef = (RubyFieldDescriptor) obj;
+ this.fieldDefMap.put(fieldDef.getName(context).asJavaString(), fieldDef);
+ this.builder.addField(fieldDef.build());
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * Descriptor.lookup(name) => FieldDescriptor
+ *
+ * Returns the field descriptor for the field with the given name, if present,
+ * or nil if none.
+ */
+ @JRubyMethod
+ public IRubyObject lookup(ThreadContext context, IRubyObject fieldName) {
+ return this.fieldDefMap.get(fieldName.asJavaString());
+ }
+
+ /*
+ * call-seq:
+ * Descriptor.msgclass => message_klass
+ *
+ * Returns the Ruby class created for this message type. Valid only once the
+ * message type has been added to a pool.
+ */
+ @JRubyMethod
+ public IRubyObject msgclass(ThreadContext context) {
+ if (this.klazz == null) {
+ this.klazz = buildClassFromDescriptor(context);
+ }
+ return this.klazz;
+ }
+
+ /*
+ * call-seq:
+ * Descriptor.each(&block)
+ *
+ * Iterates over fields in this message type, yielding to the block on each one.
+ */
+ @JRubyMethod
+ public IRubyObject each(ThreadContext context, Block block) {
+ for (Map.Entry<String, RubyFieldDescriptor> entry : fieldDefMap.entrySet()) {
+ block.yield(context, entry.getValue());
+ }
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * Descriptor.add_oneof(oneof) => nil
+ *
+ * Adds the given OneofDescriptor to this message type. This descriptor must not
+ * have been added to a pool yet. Raises an exception if a oneof with the same
+ * name already exists, or if any of the oneof's fields' names or numbers
+ * conflict with an existing field in this message type. All fields in the oneof
+ * are added to the message descriptor. Sub-type references (e.g. for fields of
+ * type message) are not resolved at this point.
+ */
+ @JRubyMethod(name = "add_oneof")
+ public IRubyObject addOneof(ThreadContext context, IRubyObject obj) {
+ RubyOneofDescriptor def = (RubyOneofDescriptor) obj;
+ builder.addOneofDecl(def.build(builder.getOneofDeclCount()));
+ for (RubyFieldDescriptor fieldDescriptor : def.getFields()) {
+ addField(context, fieldDescriptor);
+ }
+ oneofDefs.put(def.getName(context), def);
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * Descriptor.each_oneof(&block) => nil
+ *
+ * Invokes the given block for each oneof in this message type, passing the
+ * corresponding OneofDescriptor.
+ */
+ @JRubyMethod(name = "each_oneof")
+ public IRubyObject eachOneof(ThreadContext context, Block block) {
+ for (RubyOneofDescriptor oneofDescriptor : oneofDefs.values()) {
+ block.yieldSpecific(context, oneofDescriptor);
+ }
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * Descriptor.lookup_oneof(name) => OneofDescriptor
+ *
+ * Returns the oneof descriptor for the oneof with the given name, if present,
+ * or nil if none.
+ */
+ @JRubyMethod(name = "lookup_oneof")
+ public IRubyObject lookupOneof(ThreadContext context, IRubyObject name) {
+ if (name instanceof RubySymbol) {
+ name = ((RubySymbol) name).id2name();
+ }
+ return oneofDefs.containsKey(name) ? oneofDefs.get(name) : context.runtime.getNil();
+ }
+
+ public void setDescriptor(Descriptors.Descriptor descriptor) {
+ this.descriptor = descriptor;
+ }
+
+ public Descriptors.Descriptor getDescriptor() {
+ return this.descriptor;
+ }
+
+ public DescriptorProtos.DescriptorProto.Builder getBuilder() {
+ return builder;
+ }
+
+ public void setMapEntry(boolean isMapEntry) {
+ this.builder.setOptions(DescriptorProtos.MessageOptions.newBuilder().setMapEntry(isMapEntry));
+ }
+
+ private RubyModule buildClassFromDescriptor(ThreadContext context) {
+ Ruby runtime = context.runtime;
+
+ ObjectAllocator allocator = new ObjectAllocator() {
+ @Override
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
+ return new RubyMessage(runtime, klazz, descriptor);
+ }
+ };
+
+ // rb_define_class_id
+ RubyClass klass = RubyClass.newClass(runtime, runtime.getObject());
+ klass.setAllocator(allocator);
+ klass.makeMetaClass(runtime.getObject().getMetaClass());
+ klass.inherit(runtime.getObject());
+ RubyModule messageExts = runtime.getClassFromPath("Google::Protobuf::MessageExts");
+ klass.include(new IRubyObject[] {messageExts});
+ klass.instance_variable_set(runtime.newString(Utils.DESCRIPTOR_INSTANCE_VAR), this);
+ klass.defineAnnotatedMethods(RubyMessage.class);
+ return klass;
+ }
+
+ protected RubyFieldDescriptor lookup(String fieldName) {
+ return fieldDefMap.get(Utils.unescapeIdentifier(fieldName));
+ }
+
+ private IRubyObject name;
+ private RubyModule klazz;
+
+ private DescriptorProtos.DescriptorProto.Builder builder;
+ private Descriptors.Descriptor descriptor;
+ private Map<String, RubyFieldDescriptor> fieldDefMap;
+ private Map<IRubyObject, RubyOneofDescriptor> oneofDefs;
+}
diff --git a/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyDescriptorPool.java b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyDescriptorPool.java
new file mode 100644
index 0000000000..0345cb991b
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyDescriptorPool.java
@@ -0,0 +1,169 @@
+/*
+ * Protocol Buffers - Google's data interchange format
+ * Copyright 2014 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.jruby;
+
+import com.google.protobuf.DescriptorProtos;
+import com.google.protobuf.Descriptors;
+import org.jruby.*;
+import org.jruby.anno.JRubyClass;
+import org.jruby.anno.JRubyMethod;
+import org.jruby.runtime.*;
+import org.jruby.runtime.builtin.IRubyObject;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@JRubyClass(name = "DescriptorPool")
+public class RubyDescriptorPool extends RubyObject {
+ public static void createRubyDescriptorPool(Ruby runtime) {
+ RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
+ RubyClass cDescriptorPool = protobuf.defineClassUnder("DescriptorPool", runtime.getObject(), new ObjectAllocator() {
+ @Override
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
+ return new RubyDescriptorPool(runtime, klazz);
+ }
+ });
+
+ cDescriptorPool.defineAnnotatedMethods(RubyDescriptorPool.class);
+ descriptorPool = (RubyDescriptorPool) cDescriptorPool.newInstance(runtime.getCurrentContext(), Block.NULL_BLOCK);
+ }
+
+ public RubyDescriptorPool(Ruby ruby, RubyClass klazz) {
+ super(ruby, klazz);
+ }
+
+ @JRubyMethod
+ public IRubyObject initialize(ThreadContext context) {
+ this.symtab = new HashMap<IRubyObject, IRubyObject>();
+ this.cBuilder = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::Builder");
+ this.builder = DescriptorProtos.FileDescriptorProto.newBuilder();
+ return this;
+ }
+
+ @JRubyMethod
+ public IRubyObject build(ThreadContext context, Block block) {
+ RubyBuilder ctx = (RubyBuilder) cBuilder.newInstance(context, Block.NULL_BLOCK);
+ if (block.arity() == Arity.ONE_ARGUMENT) {
+ block.yield(context, ctx);
+ } else {
+ Binding binding = block.getBinding();
+ binding.setSelf(ctx);
+ block.yieldSpecific(context);
+ }
+ ctx.finalizeToPool(context, this);
+ buildFileDescriptor(context);
+ return context.runtime.getNil();
+ }
+
+ @JRubyMethod
+ public IRubyObject lookup(ThreadContext context, IRubyObject name) {
+ IRubyObject descriptor = this.symtab.get(name);
+ if (descriptor == null) {
+ return context.runtime.getNil();
+ }
+ return descriptor;
+ }
+
+ /*
+ * call-seq:
+ * DescriptorPool.generated_pool => descriptor_pool
+ *
+ * Class method that returns the global DescriptorPool. This is a singleton into
+ * which generated-code message and enum types are registered. The user may also
+ * register types in this pool for convenience so that they do not have to hold
+ * a reference to a private pool instance.
+ */
+ @JRubyMethod(meta = true, name = "generated_pool")
+ public static IRubyObject generatedPool(ThreadContext context, IRubyObject recv) {
+ return descriptorPool;
+ }
+
+ protected void addToSymtab(ThreadContext context, RubyDescriptor def) {
+ symtab.put(def.getName(context), def);
+ this.builder.addMessageType(def.getBuilder());
+ }
+
+ protected void addToSymtab(ThreadContext context, RubyEnumDescriptor def) {
+ symtab.put(def.getName(context), def);
+ this.builder.addEnumType(def.getBuilder());
+ }
+
+ private void buildFileDescriptor(ThreadContext context) {
+ Ruby runtime = context.runtime;
+ try {
+ this.builder.setSyntax("proto3");
+ final Descriptors.FileDescriptor fileDescriptor = Descriptors.FileDescriptor.buildFrom(
+ this.builder.build(), new Descriptors.FileDescriptor[]{});
+
+ for (Descriptors.EnumDescriptor enumDescriptor : fileDescriptor.getEnumTypes()) {
+ String enumName = Utils.unescapeIdentifier(enumDescriptor.getName());
+ if (enumDescriptor.findValueByNumber(0) == null) {
+ throw runtime.newTypeError("Enum definition " + enumName
+ + " does not contain a value for '0'");
+ }
+ ((RubyEnumDescriptor) symtab.get(runtime.newString(enumName)))
+ .setDescriptor(enumDescriptor);
+ }
+ for (Descriptors.Descriptor descriptor : fileDescriptor.getMessageTypes()) {
+ RubyDescriptor rubyDescriptor = ((RubyDescriptor)
+ symtab.get(runtime.newString(Utils.unescapeIdentifier(descriptor.getName()))));
+ for (Descriptors.FieldDescriptor fieldDescriptor : descriptor.getFields()) {
+ if (fieldDescriptor.isRequired()) {
+ throw runtime.newTypeError("Required fields are unsupported in proto3");
+ }
+ RubyFieldDescriptor rubyFieldDescriptor = rubyDescriptor.lookup(fieldDescriptor.getName());
+ rubyFieldDescriptor.setFieldDef(fieldDescriptor);
+ if (fieldDescriptor.getType() == Descriptors.FieldDescriptor.Type.MESSAGE) {
+ RubyDescriptor subType = (RubyDescriptor) lookup(context,
+ runtime.newString(Utils.unescapeIdentifier(fieldDescriptor.getMessageType().getName())));
+ rubyFieldDescriptor.setSubType(subType);
+ }
+ if (fieldDescriptor.getType() == Descriptors.FieldDescriptor.Type.ENUM) {
+ RubyEnumDescriptor subType = (RubyEnumDescriptor) lookup(context,
+ runtime.newString(Utils.unescapeIdentifier(fieldDescriptor.getEnumType().getName())));
+ rubyFieldDescriptor.setSubType(subType);
+ }
+ }
+ rubyDescriptor.setDescriptor(descriptor);
+ }
+ } catch (Descriptors.DescriptorValidationException e) {
+ throw runtime.newRuntimeError(e.getMessage());
+ }
+ }
+
+ private static RubyDescriptorPool descriptorPool;
+
+ private RubyClass cBuilder;
+ private Map<IRubyObject, IRubyObject> symtab;
+ private DescriptorProtos.FileDescriptorProto.Builder builder;
+}
diff --git a/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyEnum.java b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyEnum.java
new file mode 100644
index 0000000000..929d869990
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyEnum.java
@@ -0,0 +1,86 @@
+/*
+ * Protocol Buffers - Google's data interchange format
+ * Copyright 2014 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.jruby;
+
+import com.google.protobuf.Descriptors;
+import org.jruby.RubyModule;
+import org.jruby.RubyNumeric;
+import org.jruby.anno.JRubyMethod;
+import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.builtin.IRubyObject;
+
+public class RubyEnum {
+ /*
+ * call-seq:
+ * Enum.lookup(number) => name
+ *
+ * This module method, provided on each generated enum module, looks up an enum
+ * value by number and returns its name as a Ruby symbol, or nil if not found.
+ */
+ @JRubyMethod(meta = true)
+ public static IRubyObject lookup(ThreadContext context, IRubyObject recv, IRubyObject number) {
+ RubyEnumDescriptor rubyEnumDescriptorescriptor = (RubyEnumDescriptor) getDescriptor(context, recv);
+ Descriptors.EnumDescriptor descriptor = rubyEnumDescriptorescriptor.getDescriptor();
+ Descriptors.EnumValueDescriptor value = descriptor.findValueByNumber(RubyNumeric.num2int(number));
+ if (value == null) return context.runtime.getNil();
+ return context.runtime.newSymbol(value.getName());
+ }
+
+ /*
+ * call-seq:
+ * Enum.resolve(name) => number
+ *
+ * This module method, provided on each generated enum module, looks up an enum
+ * value by name (as a Ruby symbol) and returns its name, or nil if not found.
+ */
+ @JRubyMethod(meta = true)
+ public static IRubyObject resolve(ThreadContext context, IRubyObject recv, IRubyObject name) {
+ RubyEnumDescriptor rubyEnumDescriptorescriptor = (RubyEnumDescriptor) getDescriptor(context, recv);
+ Descriptors.EnumDescriptor descriptor = rubyEnumDescriptorescriptor.getDescriptor();
+ Descriptors.EnumValueDescriptor value = descriptor.findValueByName(name.asJavaString());
+ if (value == null) return context.runtime.getNil();
+ return context.runtime.newFixnum(value.getNumber());
+ }
+
+ /*
+ * call-seq:
+ * Enum.descriptor
+ *
+ * This module method, provided on each generated enum module, returns the
+ * EnumDescriptor corresponding to this enum type.
+ */
+ @JRubyMethod(meta = true, name = "descriptor")
+ public static IRubyObject getDescriptor(ThreadContext context, IRubyObject recv) {
+ return ((RubyModule) recv).getInstanceVariable(Utils.DESCRIPTOR_INSTANCE_VAR);
+ }
+}
diff --git a/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyEnumBuilderContext.java b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyEnumBuilderContext.java
new file mode 100644
index 0000000000..e4cac34581
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyEnumBuilderContext.java
@@ -0,0 +1,82 @@
+/*
+ * Protocol Buffers - Google's data interchange format
+ * Copyright 2014 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.jruby;
+
+import org.jruby.Ruby;
+import org.jruby.RubyClass;
+import org.jruby.RubyModule;
+import org.jruby.RubyObject;
+import org.jruby.anno.JRubyClass;
+import org.jruby.anno.JRubyMethod;
+import org.jruby.runtime.ObjectAllocator;
+import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.builtin.IRubyObject;
+
+@JRubyClass(name = "EnumBuilderContext")
+public class RubyEnumBuilderContext extends RubyObject {
+ public static void createRubyEnumBuilderContext(Ruby runtime) {
+ RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
+ RubyClass cMessageBuilderContext = protobuf.defineClassUnder("EnumBuilderContext", runtime.getObject(), new ObjectAllocator() {
+ @Override
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
+ return new RubyEnumBuilderContext(runtime, klazz);
+ }
+ });
+ cMessageBuilderContext.defineAnnotatedMethods(RubyEnumBuilderContext.class);
+ }
+
+ public RubyEnumBuilderContext(Ruby ruby, RubyClass klazz) {
+ super(ruby, klazz);
+ }
+
+ @JRubyMethod
+ public IRubyObject initialize(ThreadContext context, IRubyObject enumDescriptor) {
+ this.enumDescriptor = (RubyEnumDescriptor) enumDescriptor;
+ return this;
+ }
+
+ /*
+ * call-seq:
+ * EnumBuilder.add_value(name, number)
+ *
+ * Adds the given name => number mapping to the enum type. Name must be a Ruby
+ * symbol.
+ */
+ @JRubyMethod
+ public IRubyObject value(ThreadContext context, IRubyObject name, IRubyObject number) {
+ this.enumDescriptor.addValue(context, name, number);
+ return context.runtime.getNil();
+ }
+
+ private RubyEnumDescriptor enumDescriptor;
+}
diff --git a/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyEnumDescriptor.java b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyEnumDescriptor.java
new file mode 100644
index 0000000000..4df832d0cf
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyEnumDescriptor.java
@@ -0,0 +1,185 @@
+/*
+ * Protocol Buffers - Google's data interchange format
+ * Copyright 2014 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.jruby;
+
+import com.google.protobuf.DescriptorProtos;
+import com.google.protobuf.Descriptors;
+import org.jruby.Ruby;
+import org.jruby.RubyClass;
+import org.jruby.RubyModule;
+import org.jruby.RubyObject;
+import org.jruby.RubyNumeric;
+import org.jruby.anno.JRubyClass;
+import org.jruby.anno.JRubyMethod;
+import org.jruby.runtime.Block;
+import org.jruby.runtime.ObjectAllocator;
+import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.builtin.IRubyObject;
+
+@JRubyClass(name = "EnumDescriptor", include = "Enumerable")
+public class RubyEnumDescriptor extends RubyObject {
+ public static void createRubyEnumDescriptor(Ruby runtime) {
+ RubyModule mProtobuf = runtime.getClassFromPath("Google::Protobuf");
+ RubyClass cEnumDescriptor = mProtobuf.defineClassUnder("EnumDescriptor", runtime.getObject(), new ObjectAllocator() {
+ @Override
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
+ return new RubyEnumDescriptor(runtime, klazz);
+ }
+ });
+ cEnumDescriptor.includeModule(runtime.getEnumerable());
+ cEnumDescriptor.defineAnnotatedMethods(RubyEnumDescriptor.class);
+ }
+
+ public RubyEnumDescriptor(Ruby runtime, RubyClass klazz) {
+ super(runtime, klazz);
+ }
+
+ /*
+ * call-seq:
+ * EnumDescriptor.new => enum_descriptor
+ *
+ * Creates a new, empty, enum descriptor. Must be added to a pool before the
+ * enum type can be used. The enum type may only be modified prior to adding to
+ * a pool.
+ */
+ @JRubyMethod
+ public IRubyObject initialize(ThreadContext context) {
+ this.builder = DescriptorProtos.EnumDescriptorProto.newBuilder();
+ return this;
+ }
+
+ /*
+ * call-seq:
+ * EnumDescriptor.name => name
+ *
+ * Returns the name of this enum type.
+ */
+ @JRubyMethod(name = "name")
+ public IRubyObject getName(ThreadContext context) {
+ return this.name;
+ }
+
+ /*
+ * call-seq:
+ * EnumDescriptor.name = name
+ *
+ * Sets the name of this enum type. Cannot be called if the enum type has
+ * already been added to a pool.
+ */
+ @JRubyMethod(name = "name=")
+ public IRubyObject setName(ThreadContext context, IRubyObject name) {
+ this.name = name;
+ this.builder.setName(Utils.escapeIdentifier(name.asJavaString()));
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * EnumDescriptor.add_value(key, value)
+ *
+ * Adds a new key => value mapping to this enum type. Key must be given as a
+ * Ruby symbol. Cannot be called if the enum type has already been added to a
+ * pool. Will raise an exception if the key or value is already in use.
+ */
+ @JRubyMethod(name = "add_value")
+ public IRubyObject addValue(ThreadContext context, IRubyObject name, IRubyObject number) {
+ DescriptorProtos.EnumValueDescriptorProto.Builder valueBuilder = DescriptorProtos.EnumValueDescriptorProto.newBuilder();
+ valueBuilder.setName(name.asJavaString());
+ valueBuilder.setNumber(RubyNumeric.num2int(number));
+ this.builder.addValue(valueBuilder);
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * EnumDescriptor.each(&block)
+ *
+ * Iterates over key => value mappings in this enum's definition, yielding to
+ * the block with (key, value) arguments for each one.
+ */
+ @JRubyMethod
+ public IRubyObject each(ThreadContext context, Block block) {
+ Ruby runtime = context.runtime;
+ for (Descriptors.EnumValueDescriptor enumValueDescriptor : descriptor.getValues()) {
+ block.yield(context, runtime.newArray(runtime.newSymbol(enumValueDescriptor.getName()),
+ runtime.newFixnum(enumValueDescriptor.getNumber())));
+ }
+ return runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * EnumDescriptor.enummodule => module
+ *
+ * Returns the Ruby module corresponding to this enum type. Cannot be called
+ * until the enum descriptor has been added to a pool.
+ */
+ @JRubyMethod
+ public IRubyObject enummodule(ThreadContext context) {
+ if (this.klazz == null) {
+ this.klazz = buildModuleFromDescriptor(context);
+ }
+ return this.klazz;
+ }
+
+ public void setDescriptor(Descriptors.EnumDescriptor descriptor) {
+ this.descriptor = descriptor;
+ }
+
+ public Descriptors.EnumDescriptor getDescriptor() {
+ return this.descriptor;
+ }
+
+ public DescriptorProtos.EnumDescriptorProto.Builder getBuilder() {
+ return this.builder;
+ }
+
+ private RubyModule buildModuleFromDescriptor(ThreadContext context) {
+ Ruby runtime = context.runtime;
+ Utils.checkNameAvailability(context, name.asJavaString());
+
+ RubyModule enumModule = RubyModule.newModule(runtime);
+ for (Descriptors.EnumValueDescriptor value : descriptor.getValues()) {
+ enumModule.defineConstant(value.getName(), runtime.newFixnum(value.getNumber()));
+ }
+
+ enumModule.instance_variable_set(runtime.newString(Utils.DESCRIPTOR_INSTANCE_VAR), this);
+ enumModule.defineAnnotatedMethods(RubyEnum.class);
+ return enumModule;
+ }
+
+ private IRubyObject name;
+ private RubyModule klazz;
+ private Descriptors.EnumDescriptor descriptor;
+ private DescriptorProtos.EnumDescriptorProto.Builder builder;
+}
diff --git a/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyFieldDescriptor.java b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyFieldDescriptor.java
new file mode 100644
index 0000000000..f3c488bc98
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyFieldDescriptor.java
@@ -0,0 +1,277 @@
+/*
+ * Protocol Buffers - Google's data interchange format
+ * Copyright 2014 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.jruby;
+
+import com.google.protobuf.DescriptorProtos;
+import com.google.protobuf.Descriptors;
+import org.jruby.*;
+import org.jruby.anno.JRubyClass;
+import org.jruby.anno.JRubyMethod;
+import org.jruby.runtime.ObjectAllocator;
+import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.builtin.IRubyObject;
+
+@JRubyClass(name = "FieldDescriptor")
+public class RubyFieldDescriptor extends RubyObject {
+ public static void createRubyFileDescriptor(Ruby runtime) {
+ RubyModule mProtobuf = runtime.getClassFromPath("Google::Protobuf");
+ RubyClass cFieldDescriptor = mProtobuf.defineClassUnder("FieldDescriptor", runtime.getObject(), new ObjectAllocator() {
+ @Override
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
+ return new RubyFieldDescriptor(runtime, klazz);
+ }
+ });
+ cFieldDescriptor.defineAnnotatedMethods(RubyFieldDescriptor.class);
+ }
+
+ public RubyFieldDescriptor(Ruby runtime, RubyClass klazz) {
+ super(runtime, klazz);
+ }
+
+ /*
+ * call-seq:
+ * FieldDescriptor.new => field
+ *
+ * Returns a new field descriptor. Its name, type, etc. must be set before it is
+ * added to a message type.
+ */
+ @JRubyMethod
+ public IRubyObject initialize(ThreadContext context) {
+ builder = DescriptorProtos.FieldDescriptorProto.newBuilder();
+ return this;
+ }
+
+ /*
+ * call-seq:
+ * FieldDescriptor.label
+ *
+ * Return the label of this field.
+ */
+ @JRubyMethod(name = "label")
+ public IRubyObject getLabel(ThreadContext context) {
+ return this.label;
+ }
+
+ /*
+ * call-seq:
+ * FieldDescriptor.label = label
+ *
+ * Sets the label on this field. Cannot be called if field is part of a message
+ * type already in a pool.
+ */
+ @JRubyMethod(name = "label=")
+ public IRubyObject setLabel(ThreadContext context, IRubyObject value) {
+ String labelName = value.asJavaString();
+ this.label = context.runtime.newSymbol(labelName.toLowerCase());
+ this.builder.setLabel(
+ DescriptorProtos.FieldDescriptorProto.Label.valueOf("LABEL_" + labelName.toUpperCase()));
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * FieldDescriptor.name => name
+ *
+ * Returns the name of this field as a Ruby String, or nil if it is not set.
+ */
+ @JRubyMethod(name = "name")
+ public IRubyObject getName(ThreadContext context) {
+ return this.name;
+ }
+
+ /*
+ * call-seq:
+ * FieldDescriptor.name = name
+ *
+ * Sets the name of this field. Cannot be called once the containing message
+ * type, if any, is added to a pool.
+ */
+ @JRubyMethod(name = "name=")
+ public IRubyObject setName(ThreadContext context, IRubyObject value) {
+ String nameStr = value.asJavaString();
+ this.name = context.runtime.newString(nameStr);
+ this.builder.setName(Utils.escapeIdentifier(nameStr));
+ return context.runtime.getNil();
+ }
+
+
+ @JRubyMethod(name = "subtype")
+ public IRubyObject getSubType(ThreadContext context) {
+ return subType;
+ }
+
+ /*
+ * call-seq:
+ * FieldDescriptor.type => type
+ *
+ * Returns this field's type, as a Ruby symbol, or nil if not yet set.
+ *
+ * Valid field types are:
+ * :int32, :int64, :uint32, :uint64, :float, :double, :bool, :string,
+ * :bytes, :message.
+ */
+ @JRubyMethod(name = "type")
+ public IRubyObject getType(ThreadContext context) {
+ return Utils.fieldTypeToRuby(context, this.builder.getType());
+ }
+
+ /*
+ * call-seq:
+ * FieldDescriptor.type = type
+ *
+ * Sets this field's type. Cannot be called if field is part of a message type
+ * already in a pool.
+ */
+ @JRubyMethod(name = "type=")
+ public IRubyObject setType(ThreadContext context, IRubyObject value) {
+ this.builder.setType(DescriptorProtos.FieldDescriptorProto.Type.valueOf("TYPE_" + value.asJavaString().toUpperCase()));
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * FieldDescriptor.number => number
+ *
+ * Returns this field's number, as a Ruby Integer, or nil if not yet set.
+ *
+ */
+ @JRubyMethod(name = "number")
+ public IRubyObject getnumber(ThreadContext context) {
+ return this.number;
+ }
+
+ /*
+ * call-seq:
+ * FieldDescriptor.number = number
+ *
+ * Sets the tag number for this field. Cannot be called if field is part of a
+ * message type already in a pool.
+ */
+ @JRubyMethod(name = "number=")
+ public IRubyObject setNumber(ThreadContext context, IRubyObject value) {
+ this.number = value;
+ this.builder.setNumber(RubyNumeric.num2int(value));
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * FieldDescriptor.submsg_name = submsg_name
+ *
+ * Sets the name of the message or enum type corresponding to this field, if it
+ * is a message or enum field (respectively). This type name will be resolved
+ * within the context of the pool to which the containing message type is added.
+ * Cannot be called on field that are not of message or enum type, or on fields
+ * that are part of a message type already added to a pool.
+ */
+ @JRubyMethod(name = "submsg_name=")
+ public IRubyObject setSubmsgName(ThreadContext context, IRubyObject name) {
+ this.builder.setTypeName("." + Utils.escapeIdentifier(name.asJavaString()));
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * FieldDescriptor.get(message) => value
+ *
+ * Returns the value set for this field on the given message. Raises an
+ * exception if message is of the wrong type.
+ */
+ @JRubyMethod(name = "get")
+ public IRubyObject getValue(ThreadContext context, IRubyObject msgRb) {
+ RubyMessage message = (RubyMessage) msgRb;
+ if (message.getDescriptor() != fieldDef.getContainingType()) {
+ throw context.runtime.newTypeError("set method called on wrong message type");
+ }
+ return message.getField(context, fieldDef);
+ }
+
+ /*
+ * call-seq:
+ * FieldDescriptor.set(message, value)
+ *
+ * Sets the value corresponding to this field to the given value on the given
+ * message. Raises an exception if message is of the wrong type. Performs the
+ * ordinary type-checks for field setting.
+ */
+ @JRubyMethod(name = "set")
+ public IRubyObject setValue(ThreadContext context, IRubyObject msgRb, IRubyObject value) {
+ RubyMessage message = (RubyMessage) msgRb;
+ if (message.getDescriptor() != fieldDef.getContainingType()) {
+ throw context.runtime.newTypeError("set method called on wrong message type");
+ }
+ message.setField(context, fieldDef, value);
+ return context.runtime.getNil();
+ }
+
+ protected void setSubType(IRubyObject rubyDescriptor) {
+ this.subType = rubyDescriptor;
+ }
+
+ protected void setFieldDef(Descriptors.FieldDescriptor fieldDescriptor) {
+ this.fieldDef = fieldDescriptor;
+ }
+
+ protected void setOneofName(IRubyObject name) {
+ oneofName = name;
+ }
+
+ protected void setOneofIndex(int index) {
+ hasOneofIndex = true;
+ oneofIndex = index;
+ }
+
+ protected IRubyObject getOneofName() {
+ return oneofName;
+ }
+
+ protected Descriptors.FieldDescriptor getFieldDef() {
+ return fieldDef;
+ }
+
+ protected DescriptorProtos.FieldDescriptorProto build() {
+ if (hasOneofIndex)
+ builder.setOneofIndex(oneofIndex);
+ return this.builder.build();
+ }
+
+ private DescriptorProtos.FieldDescriptorProto.Builder builder;
+ private IRubyObject name;
+ private IRubyObject label;
+ private IRubyObject number;
+ private IRubyObject subType;
+ private IRubyObject oneofName;
+ private Descriptors.FieldDescriptor fieldDef;
+ private int oneofIndex;
+ private boolean hasOneofIndex = false;
+}
diff --git a/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyMap.java b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyMap.java
new file mode 100644
index 0000000000..3adaa2a8bd
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyMap.java
@@ -0,0 +1,434 @@
+/*
+ * Protocol Buffers - Google's data interchange format
+ * Copyright 2014 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.jruby;
+
+import com.google.protobuf.Descriptors;
+import com.google.protobuf.DynamicMessage;
+import com.google.protobuf.MapEntry;
+import org.jruby.*;
+import org.jruby.anno.JRubyClass;
+import org.jruby.anno.JRubyMethod;
+import org.jruby.internal.runtime.methods.DynamicMethod;
+import org.jruby.runtime.Block;
+import org.jruby.runtime.ObjectAllocator;
+import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.builtin.IRubyObject;
+import org.jruby.util.ByteList;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@JRubyClass(name = "Map", include = "Enumerable")
+public class RubyMap extends RubyObject {
+ public static void createRubyMap(Ruby runtime) {
+ RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
+ RubyClass cMap = protobuf.defineClassUnder("Map", runtime.getObject(), new ObjectAllocator() {
+ @Override
+ public IRubyObject allocate(Ruby ruby, RubyClass rubyClass) {
+ return new RubyMap(ruby, rubyClass);
+ }
+ });
+ cMap.includeModule(runtime.getEnumerable());
+ cMap.defineAnnotatedMethods(RubyMap.class);
+ }
+
+ public RubyMap(Ruby ruby, RubyClass rubyClass) {
+ super(ruby, rubyClass);
+ }
+
+ /*
+ * call-seq:
+ * Map.new(key_type, value_type, value_typeclass = nil, init_hashmap = {})
+ * => new map
+ *
+ * Allocates a new Map container. This constructor may be called with 2, 3, or 4
+ * arguments. The first two arguments are always present and are symbols (taking
+ * on the same values as field-type symbols in message descriptors) that
+ * indicate the type of the map key and value fields.
+ *
+ * The supported key types are: :int32, :int64, :uint32, :uint64, :bool,
+ * :string, :bytes.
+ *
+ * The supported value types are: :int32, :int64, :uint32, :uint64, :bool,
+ * :string, :bytes, :enum, :message.
+ *
+ * The third argument, value_typeclass, must be present if value_type is :enum
+ * or :message. As in RepeatedField#new, this argument must be a message class
+ * (for :message) or enum module (for :enum).
+ *
+ * The last argument, if present, provides initial content for map. Note that
+ * this may be an ordinary Ruby hashmap or another Map instance with identical
+ * key and value types. Also note that this argument may be present whether or
+ * not value_typeclass is present (and it is unambiguously separate from
+ * value_typeclass because value_typeclass's presence is strictly determined by
+ * value_type). The contents of this initial hashmap or Map instance are
+ * shallow-copied into the new Map: the original map is unmodified, but
+ * references to underlying objects will be shared if the value type is a
+ * message type.
+ */
+
+ @JRubyMethod(required = 2, optional = 2)
+ public IRubyObject initialize(ThreadContext context, IRubyObject[] args) {
+ this.table = new HashMap<IRubyObject, IRubyObject>();
+ this.keyType = Utils.rubyToFieldType(args[0]);
+ this.valueType = Utils.rubyToFieldType(args[1]);
+
+ switch(keyType) {
+ case INT32:
+ case INT64:
+ case UINT32:
+ case UINT64:
+ case BOOL:
+ case STRING:
+ case BYTES:
+ // These are OK.
+ break;
+ default:
+ throw context.runtime.newArgumentError("Invalid key type for map.");
+ }
+
+ int initValueArg = 2;
+ if (needTypeclass(this.valueType) && args.length > 2) {
+ this.valueTypeClass = args[2];
+ Utils.validateTypeClass(context, this.valueType, this.valueTypeClass);
+ initValueArg = 3;
+ } else {
+ this.valueTypeClass = context.runtime.getNilClass();
+ }
+
+ // Table value type is always UINT64: this ensures enough space to store the
+ // native_slot value.
+ if (args.length > initValueArg) {
+ mergeIntoSelf(context, args[initValueArg]);
+ }
+ return this;
+ }
+
+ /*
+ * call-seq:
+ * Map.[]=(key, value) => value
+ *
+ * Inserts or overwrites the value at the given key with the given new value.
+ * Throws an exception if the key type is incorrect. Returns the new value that
+ * was just inserted.
+ */
+ @JRubyMethod(name = "[]=")
+ public IRubyObject indexSet(ThreadContext context, IRubyObject key, IRubyObject value) {
+ key = Utils.checkType(context, keyType, key, (RubyModule) valueTypeClass);
+ value = Utils.checkType(context, valueType, value, (RubyModule) valueTypeClass);
+ IRubyObject symbol;
+ if (valueType == Descriptors.FieldDescriptor.Type.ENUM &&
+ Utils.isRubyNum(value) &&
+ ! (symbol = RubyEnum.lookup(context, valueTypeClass, value)).isNil()) {
+ value = symbol;
+ }
+ this.table.put(key, value);
+ return value;
+ }
+
+ /*
+ * call-seq:
+ * Map.[](key) => value
+ *
+ * Accesses the element at the given key. Throws an exception if the key type is
+ * incorrect. Returns nil when the key is not present in the map.
+ */
+ @JRubyMethod(name = "[]")
+ public IRubyObject index(ThreadContext context, IRubyObject key) {
+ if (table.containsKey(key))
+ return this.table.get(key);
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * Map.==(other) => boolean
+ *
+ * Compares this map to another. Maps are equal if they have identical key sets,
+ * and for each key, the values in both maps compare equal. Elements are
+ * compared as per normal Ruby semantics, by calling their :== methods (or
+ * performing a more efficient comparison for primitive types).
+ *
+ * Maps with dissimilar key types or value types/typeclasses are never equal,
+ * even if value comparison (for example, between integers and floats) would
+ * have otherwise indicated that every element has equal value.
+ */
+ @JRubyMethod(name = "==")
+ public IRubyObject eq(ThreadContext context, IRubyObject _other) {
+ if (_other instanceof RubyHash)
+ return toHash(context).op_equal(context, _other);
+ RubyMap other = (RubyMap) _other;
+ if (this == other) return context.runtime.getTrue();
+ if (!typeCompatible(other) || this.table.size() != other.table.size())
+ return context.runtime.getFalse();
+ for (IRubyObject key : table.keySet()) {
+ if (! other.table.containsKey(key))
+ return context.runtime.getFalse();
+ if (! other.table.get(key).equals(table.get(key)))
+ return context.runtime.getFalse();
+ }
+ return context.runtime.getTrue();
+ }
+
+ /*
+ * call-seq:
+ * Map.inspect => string
+ *
+ * Returns a string representing this map's elements. It will be formatted as
+ * "{key => value, key => value, ...}", with each key and value string
+ * representation computed by its own #inspect method.
+ */
+ @JRubyMethod
+ public IRubyObject inspect() {
+ return toHash(getRuntime().getCurrentContext()).inspect();
+ }
+
+ /*
+ * call-seq:
+ * Map.hash => hash_value
+ *
+ * Returns a hash value based on this map's contents.
+ */
+ @JRubyMethod
+ public IRubyObject hash(ThreadContext context) {
+ try {
+ MessageDigest digest = MessageDigest.getInstance("SHA-256");
+ for (IRubyObject key : table.keySet()) {
+ digest.update((byte) key.hashCode());
+ digest.update((byte) table.get(key).hashCode());
+ }
+ return context.runtime.newString(new ByteList(digest.digest()));
+ } catch (NoSuchAlgorithmException ignore) {
+ return context.runtime.newFixnum(System.identityHashCode(table));
+ }
+ }
+
+ /*
+ * call-seq:
+ * Map.keys => [list_of_keys]
+ *
+ * Returns the list of keys contained in the map, in unspecified order.
+ */
+ @JRubyMethod
+ public IRubyObject keys(ThreadContext context) {
+ return RubyArray.newArray(context.runtime, table.keySet());
+ }
+
+ /*
+ * call-seq:
+ * Map.values => [list_of_values]
+ *
+ * Returns the list of values contained in the map, in unspecified order.
+ */
+ @JRubyMethod
+ public IRubyObject values(ThreadContext context) {
+ return RubyArray.newArray(context.runtime, table.values());
+ }
+
+ /*
+ * call-seq:
+ * Map.clear
+ *
+ * Removes all entries from the map.
+ */
+ @JRubyMethod
+ public IRubyObject clear(ThreadContext context) {
+ table.clear();
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * Map.each(&block)
+ *
+ * Invokes &block on each |key, value| pair in the map, in unspecified order.
+ * Note that Map also includes Enumerable; map thus acts like a normal Ruby
+ * sequence.
+ */
+ @JRubyMethod
+ public IRubyObject each(ThreadContext context, Block block) {
+ for (IRubyObject key : table.keySet()) {
+ block.yieldSpecific(context, key, table.get(key));
+ }
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * Map.delete(key) => old_value
+ *
+ * Deletes the value at the given key, if any, returning either the old value or
+ * nil if none was present. Throws an exception if the key is of the wrong type.
+ */
+ @JRubyMethod
+ public IRubyObject delete(ThreadContext context, IRubyObject key) {
+ return table.remove(key);
+ }
+
+ /*
+ * call-seq:
+ * Map.has_key?(key) => bool
+ *
+ * Returns true if the given key is present in the map. Throws an exception if
+ * the key has the wrong type.
+ */
+ @JRubyMethod(name = "has_key?")
+ public IRubyObject hasKey(ThreadContext context, IRubyObject key) {
+ return this.table.containsKey(key) ? context.runtime.getTrue() : context.runtime.getFalse();
+ }
+
+ /*
+ * call-seq:
+ * Map.length
+ *
+ * Returns the number of entries (key-value pairs) in the map.
+ */
+ @JRubyMethod
+ public IRubyObject length(ThreadContext context) {
+ return context.runtime.newFixnum(this.table.size());
+ }
+
+ /*
+ * call-seq:
+ * Map.dup => new_map
+ *
+ * Duplicates this map with a shallow copy. References to all non-primitive
+ * element objects (e.g., submessages) are shared.
+ */
+ @JRubyMethod
+ public IRubyObject dup(ThreadContext context) {
+ RubyMap newMap = newThisType(context);
+ for (Map.Entry<IRubyObject, IRubyObject> entry : table.entrySet()) {
+ newMap.table.put(entry.getKey(), entry.getValue());
+ }
+ return newMap;
+ }
+
+ @JRubyMethod(name = {"to_h", "to_hash"})
+ public RubyHash toHash(ThreadContext context) {
+ return RubyHash.newHash(context.runtime, table, context.runtime.getNil());
+ }
+
+ // Used by Google::Protobuf.deep_copy but not exposed directly.
+ protected IRubyObject deepCopy(ThreadContext context) {
+ RubyMap newMap = newThisType(context);
+ switch (valueType) {
+ case MESSAGE:
+ for (IRubyObject key : table.keySet()) {
+ RubyMessage message = (RubyMessage) table.get(key);
+ newMap.table.put(key.dup(), message.deepCopy(context));
+ }
+ break;
+ default:
+ for (IRubyObject key : table.keySet()) {
+ newMap.table.put(key.dup(), table.get(key).dup());
+ }
+ }
+ return newMap;
+ }
+
+ protected List<DynamicMessage> build(ThreadContext context, RubyDescriptor descriptor) {
+ List<DynamicMessage> list = new ArrayList<DynamicMessage>();
+ RubyClass rubyClass = (RubyClass) descriptor.msgclass(context);
+ Descriptors.FieldDescriptor keyField = descriptor.lookup("key").getFieldDef();
+ Descriptors.FieldDescriptor valueField = descriptor.lookup("value").getFieldDef();
+ for (IRubyObject key : table.keySet()) {
+ RubyMessage mapMessage = (RubyMessage) rubyClass.newInstance(context, Block.NULL_BLOCK);
+ mapMessage.setField(context, keyField, key);
+ mapMessage.setField(context, valueField, table.get(key));
+ list.add(mapMessage.build(context));
+ }
+ return list;
+ }
+
+ protected RubyMap mergeIntoSelf(final ThreadContext context, IRubyObject hashmap) {
+ if (hashmap instanceof RubyHash) {
+ ((RubyHash) hashmap).visitAll(new RubyHash.Visitor() {
+ @Override
+ public void visit(IRubyObject key, IRubyObject val) {
+ indexSet(context, key, val);
+ }
+ });
+ } else if (hashmap instanceof RubyMap) {
+ RubyMap other = (RubyMap) hashmap;
+ if (!typeCompatible(other)) {
+ throw context.runtime.newTypeError("Attempt to merge Map with mismatching types");
+ }
+ } else {
+ throw context.runtime.newTypeError("Unknown type merging into Map");
+ }
+ return this;
+ }
+
+ protected boolean typeCompatible(RubyMap other) {
+ return this.keyType == other.keyType &&
+ this.valueType == other.valueType &&
+ this.valueTypeClass == other.valueTypeClass;
+ }
+
+ private RubyMap newThisType(ThreadContext context) {
+ RubyMap newMap;
+ if (needTypeclass(valueType)) {
+ newMap = (RubyMap) metaClass.newInstance(context,
+ Utils.fieldTypeToRuby(context, keyType),
+ Utils.fieldTypeToRuby(context, valueType),
+ valueTypeClass, Block.NULL_BLOCK);
+ } else {
+ newMap = (RubyMap) metaClass.newInstance(context,
+ Utils.fieldTypeToRuby(context, keyType),
+ Utils.fieldTypeToRuby(context, valueType),
+ Block.NULL_BLOCK);
+ }
+ newMap.table = new HashMap<IRubyObject, IRubyObject>();
+ return newMap;
+ }
+
+ private boolean needTypeclass(Descriptors.FieldDescriptor.Type type) {
+ switch(type) {
+ case MESSAGE:
+ case ENUM:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ private Descriptors.FieldDescriptor.Type keyType;
+ private Descriptors.FieldDescriptor.Type valueType;
+ private IRubyObject valueTypeClass;
+ private Map<IRubyObject, IRubyObject> table;
+}
diff --git a/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java
new file mode 100644
index 0000000000..733ccfbc7d
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java
@@ -0,0 +1,784 @@
+/*
+ * Protocol Buffers - Google's data interchange format
+ * Copyright 2014 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.jruby;
+
+import com.google.protobuf.*;
+import org.jruby.*;
+import org.jruby.anno.JRubyMethod;
+import org.jruby.runtime.Block;
+import org.jruby.runtime.Helpers;
+import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.builtin.IRubyObject;
+import org.jruby.util.ByteList;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.HashMap;
+import java.util.Map;
+
+public class RubyMessage extends RubyObject {
+ public RubyMessage(Ruby ruby, RubyClass klazz, Descriptors.Descriptor descriptor) {
+ super(ruby, klazz);
+ this.descriptor = descriptor;
+ }
+
+ /*
+ * call-seq:
+ * Message.new(kwargs) => new_message
+ *
+ * Creates a new instance of the given message class. Keyword arguments may be
+ * provided with keywords corresponding to field names.
+ *
+ * Note that no literal Message class exists. Only concrete classes per message
+ * type exist, as provided by the #msgclass method on Descriptors after they
+ * have been added to a pool. The method definitions described here on the
+ * Message class are provided on each concrete message class.
+ */
+ @JRubyMethod(optional = 1)
+ public IRubyObject initialize(final ThreadContext context, IRubyObject[] args) {
+ final Ruby runtime = context.runtime;
+ this.cRepeatedField = (RubyClass) runtime.getClassFromPath("Google::Protobuf::RepeatedField");
+ this.cMap = (RubyClass) runtime.getClassFromPath("Google::Protobuf::Map");
+ this.builder = DynamicMessage.newBuilder(this.descriptor);
+ this.repeatedFields = new HashMap<Descriptors.FieldDescriptor, RubyRepeatedField>();
+ this.maps = new HashMap<Descriptors.FieldDescriptor, RubyMap>();
+ this.fields = new HashMap<Descriptors.FieldDescriptor, IRubyObject>();
+ this.oneofCases = new HashMap<Descriptors.OneofDescriptor, Descriptors.FieldDescriptor>();
+ if (args.length == 1) {
+ if (!(args[0] instanceof RubyHash)) {
+ throw runtime.newArgumentError("expected Hash arguments.");
+ }
+ RubyHash hash = args[0].convertToHash();
+ hash.visitAll(new RubyHash.Visitor() {
+ @Override
+ public void visit(IRubyObject key, IRubyObject value) {
+ if (!(key instanceof RubySymbol))
+ throw runtime.newTypeError("Expected symbols as hash keys in initialization map.");
+ final Descriptors.FieldDescriptor fieldDescriptor = findField(context, key);
+
+ if (Utils.isMapEntry(fieldDescriptor)) {
+ if (!(value instanceof RubyHash))
+ throw runtime.newArgumentError("Expected Hash object as initializer value for map field '" + key.asJavaString() + "'.");
+
+ final RubyMap map = newMapForField(context, fieldDescriptor);
+ map.mergeIntoSelf(context, value);
+ maps.put(fieldDescriptor, map);
+ } else if (fieldDescriptor.isRepeated()) {
+ if (!(value instanceof RubyArray))
+ throw runtime.newArgumentError("Expected array as initializer value for repeated field '" + key.asJavaString() + "'.");
+ RubyRepeatedField repeatedField = rubyToRepeatedField(context, fieldDescriptor, value);
+ addRepeatedField(fieldDescriptor, repeatedField);
+ } else {
+ Descriptors.OneofDescriptor oneof = fieldDescriptor.getContainingOneof();
+ if (oneof != null) {
+ oneofCases.put(oneof, fieldDescriptor);
+ }
+ fields.put(fieldDescriptor, value);
+ }
+
+ }
+ });
+ }
+ return this;
+ }
+
+ /*
+ * call-seq:
+ * Message.[]=(index, value)
+ *
+ * Sets a field's value by field name. The provided field name should be a
+ * string.
+ */
+ @JRubyMethod(name = "[]=")
+ public IRubyObject indexSet(ThreadContext context, IRubyObject fieldName, IRubyObject value) {
+ Descriptors.FieldDescriptor fieldDescriptor = findField(context, fieldName);
+ return setField(context, fieldDescriptor, value);
+ }
+
+ /*
+ * call-seq:
+ * Message.[](index) => value
+ *
+ * Accesses a field's value by field name. The provided field name should be a
+ * string.
+ */
+ @JRubyMethod(name = "[]")
+ public IRubyObject index(ThreadContext context, IRubyObject fieldName) {
+ Descriptors.FieldDescriptor fieldDescriptor = findField(context, fieldName);
+ return getField(context, fieldDescriptor);
+ }
+
+ /*
+ * call-seq:
+ * Message.inspect => string
+ *
+ * Returns a human-readable string representing this message. It will be
+ * formatted as "<MessageType: field1: value1, field2: value2, ...>". Each
+ * field's value is represented according to its own #inspect method.
+ */
+ @JRubyMethod
+ public IRubyObject inspect() {
+ String cname = metaClass.getName();
+ StringBuilder sb = new StringBuilder("<");
+ sb.append(cname);
+ sb.append(": ");
+ sb.append(this.layoutInspect());
+ sb.append(">");
+
+ return getRuntime().newString(sb.toString());
+ }
+
+ /*
+ * call-seq:
+ * Message.hash => hash_value
+ *
+ * Returns a hash value that represents this message's field values.
+ */
+ @JRubyMethod
+ public IRubyObject hash(ThreadContext context) {
+ try {
+ MessageDigest digest = MessageDigest.getInstance("SHA-256");
+ for (RubyMap map : maps.values()) {
+ digest.update((byte) map.hashCode());
+ }
+ for (RubyRepeatedField repeatedField : repeatedFields.values()) {
+ digest.update((byte) repeatedFields.hashCode());
+ }
+ for (IRubyObject field : fields.values()) {
+ digest.update((byte) field.hashCode());
+ }
+ return context.runtime.newString(new ByteList(digest.digest()));
+ } catch (NoSuchAlgorithmException ignore) {
+ return context.runtime.newFixnum(System.identityHashCode(this));
+ }
+ }
+
+ /*
+ * call-seq:
+ * Message.==(other) => boolean
+ *
+ * Performs a deep comparison of this message with another. Messages are equal
+ * if they have the same type and if each field is equal according to the :==
+ * method's semantics (a more efficient comparison may actually be done if the
+ * field is of a primitive type).
+ */
+ @JRubyMethod(name = "==")
+ public IRubyObject eq(ThreadContext context, IRubyObject other) {
+ Ruby runtime = context.runtime;
+ if (!(other instanceof RubyMessage))
+ return runtime.getFalse();
+ RubyMessage message = (RubyMessage) other;
+ if (descriptor != message.descriptor) {
+ return runtime.getFalse();
+ }
+
+ for (Descriptors.FieldDescriptor fdef : descriptor.getFields()) {
+ IRubyObject thisVal = getField(context, fdef);
+ IRubyObject thatVal = message.getField(context, fdef);
+ IRubyObject ret = thisVal.callMethod(context, "==", thatVal);
+ if (!ret.isTrue()) {
+ return runtime.getFalse();
+ }
+ }
+ return runtime.getTrue();
+ }
+
+ /*
+ * call-seq:
+ * Message.method_missing(*args)
+ *
+ * Provides accessors and setters for message fields according to their field
+ * names. For any field whose name does not conflict with a built-in method, an
+ * accessor is provided with the same name as the field, and a setter is
+ * provided with the name of the field plus the '=' suffix. Thus, given a
+ * message instance 'msg' with field 'foo', the following code is valid:
+ *
+ * msg.foo = 42
+ * puts msg.foo
+ */
+ @JRubyMethod(name = "method_missing", rest = true)
+ public IRubyObject methodMissing(ThreadContext context, IRubyObject[] args) {
+ if (args.length == 1) {
+ RubyDescriptor rubyDescriptor = (RubyDescriptor) getDescriptor(context, metaClass);
+ IRubyObject oneofDescriptor = rubyDescriptor.lookupOneof(context, args[0]);
+ if (oneofDescriptor.isNil()) {
+ if (!hasField(args[0])) {
+ return Helpers.invokeSuper(context, this, metaClass, "method_missing", args, Block.NULL_BLOCK);
+ }
+ return index(context, args[0]);
+ }
+ RubyOneofDescriptor rubyOneofDescriptor = (RubyOneofDescriptor) oneofDescriptor;
+ Descriptors.FieldDescriptor fieldDescriptor =
+ oneofCases.get(rubyOneofDescriptor.getOneofDescriptor());
+ if (fieldDescriptor == null)
+ return context.runtime.getNil();
+
+ return context.runtime.newSymbol(fieldDescriptor.getName());
+ } else {
+ // fieldName is RubySymbol
+ RubyString field = args[0].asString();
+ RubyString equalSign = context.runtime.newString(Utils.EQUAL_SIGN);
+ if (field.end_with_p(context, equalSign).isTrue()) {
+ field.chomp_bang(context, equalSign);
+ }
+
+ if (!hasField(field)) {
+ return Helpers.invokeSuper(context, this, metaClass, "method_missing", args, Block.NULL_BLOCK);
+ }
+ return indexSet(context, field, args[1]);
+ }
+ }
+
+ /**
+ * call-seq:
+ * Message.dup => new_message
+ * Performs a shallow copy of this message and returns the new copy.
+ */
+ @JRubyMethod
+ public IRubyObject dup(ThreadContext context) {
+ RubyMessage dup = (RubyMessage) metaClass.newInstance(context, Block.NULL_BLOCK);
+ IRubyObject value;
+ for (Descriptors.FieldDescriptor fieldDescriptor : this.descriptor.getFields()) {
+ if (fieldDescriptor.isRepeated()) {
+ dup.addRepeatedField(fieldDescriptor, this.getRepeatedField(context, fieldDescriptor));
+ } else if (fields.containsKey(fieldDescriptor)) {
+ dup.fields.put(fieldDescriptor, fields.get(fieldDescriptor));
+ } else if (this.builder.hasField(fieldDescriptor)) {
+ dup.fields.put(fieldDescriptor, wrapField(context, fieldDescriptor, this.builder.getField(fieldDescriptor)));
+ }
+ }
+ for (Descriptors.FieldDescriptor fieldDescriptor : maps.keySet()) {
+ dup.maps.put(fieldDescriptor, maps.get(fieldDescriptor));
+ }
+ return dup;
+ }
+
+ /*
+ * call-seq:
+ * Message.descriptor => descriptor
+ *
+ * Class method that returns the Descriptor instance corresponding to this
+ * message class's type.
+ */
+ @JRubyMethod(name = "descriptor", meta = true)
+ public static IRubyObject getDescriptor(ThreadContext context, IRubyObject recv) {
+ return ((RubyClass) recv).getInstanceVariable(Utils.DESCRIPTOR_INSTANCE_VAR);
+ }
+
+ /*
+ * call-seq:
+ * MessageClass.encode(msg) => bytes
+ *
+ * Encodes the given message object to its serialized form in protocol buffers
+ * wire format.
+ */
+ @JRubyMethod(meta = true)
+ public static IRubyObject encode(ThreadContext context, IRubyObject recv, IRubyObject value) {
+ RubyMessage message = (RubyMessage) value;
+ return context.runtime.newString(new ByteList(message.build(context).toByteArray()));
+ }
+
+ /*
+ * call-seq:
+ * MessageClass.decode(data) => message
+ *
+ * Decodes the given data (as a string containing bytes in protocol buffers wire
+ * format) under the interpretration given by this message class's definition
+ * and returns a message object with the corresponding field values.
+ */
+ @JRubyMethod(meta = true)
+ public static IRubyObject decode(ThreadContext context, IRubyObject recv, IRubyObject data) {
+ byte[] bin = data.convertToString().getBytes();
+ RubyMessage ret = (RubyMessage) ((RubyClass) recv).newInstance(context, Block.NULL_BLOCK);
+ try {
+ ret.builder.mergeFrom(bin);
+ } catch (InvalidProtocolBufferException e) {
+ throw context.runtime.newRuntimeError(e.getMessage());
+ }
+ return ret;
+ }
+
+ /*
+ * call-seq:
+ * MessageClass.encode_json(msg) => json_string
+ *
+ * Encodes the given message object into its serialized JSON representation.
+ */
+ @JRubyMethod(name = "encode_json", meta = true)
+ public static IRubyObject encodeJson(ThreadContext context, IRubyObject recv, IRubyObject msgRb) {
+ RubyMessage message = (RubyMessage) msgRb;
+ return Helpers.invoke(context, message.toHash(context), "to_json");
+ }
+
+ /*
+ * call-seq:
+ * MessageClass.decode_json(data) => message
+ *
+ * Decodes the given data (as a string containing bytes in protocol buffers wire
+ * format) under the interpretration given by this message class's definition
+ * and returns a message object with the corresponding field values.
+ */
+ @JRubyMethod(name = "decode_json", meta = true)
+ public static IRubyObject decodeJson(ThreadContext context, IRubyObject recv, IRubyObject json) {
+ Ruby runtime = context.runtime;
+ RubyMessage ret = (RubyMessage) ((RubyClass) recv).newInstance(context, Block.NULL_BLOCK);
+ RubyModule jsonModule = runtime.getClassFromPath("JSON");
+ RubyHash opts = RubyHash.newHash(runtime);
+ opts.fastASet(runtime.newSymbol("symbolize_names"), runtime.getTrue());
+ IRubyObject[] args = new IRubyObject[] { Helpers.invoke(context, jsonModule, "parse", json, opts) };
+ ret.initialize(context, args);
+ return ret;
+ }
+
+ @JRubyMethod(name = {"to_h", "to_hash"})
+ public IRubyObject toHash(ThreadContext context) {
+ Ruby runtime = context.runtime;
+ RubyHash ret = RubyHash.newHash(runtime);
+ for (Descriptors.FieldDescriptor fdef : this.descriptor.getFields()) {
+ IRubyObject value = getField(context, fdef);
+ if (!value.isNil()) {
+ if (value.respondsTo("to_h")) {
+ value = Helpers.invoke(context, value, "to_h");
+ } else if (value.respondsTo("to_a")) {
+ value = Helpers.invoke(context, value, "to_a");
+ }
+ }
+ ret.fastASet(runtime.newSymbol(fdef.getName()), value);
+ }
+ return ret;
+ }
+
+ protected DynamicMessage build(ThreadContext context) {
+ return build(context, 0);
+ }
+
+ protected DynamicMessage build(ThreadContext context, int depth) {
+ if (depth > SINK_MAXIMUM_NESTING) {
+ throw context.runtime.newRuntimeError("Maximum recursion depth exceeded during encoding.");
+ }
+ for (Descriptors.FieldDescriptor fieldDescriptor : maps.keySet()) {
+ this.builder.clearField(fieldDescriptor);
+ RubyDescriptor mapDescriptor = (RubyDescriptor) getDescriptorForField(context, fieldDescriptor);
+ for (DynamicMessage kv : maps.get(fieldDescriptor).build(context, mapDescriptor)) {
+ this.builder.addRepeatedField(fieldDescriptor, kv);
+ }
+ }
+ for (Descriptors.FieldDescriptor fieldDescriptor : repeatedFields.keySet()) {
+ RubyRepeatedField repeatedField = repeatedFields.get(fieldDescriptor);
+ this.builder.clearField(fieldDescriptor);
+ for (int i = 0; i < repeatedField.size(); i++) {
+ Object item = convert(context, fieldDescriptor, repeatedField.get(i), depth);
+ this.builder.addRepeatedField(fieldDescriptor, item);
+ }
+ }
+ for (Descriptors.FieldDescriptor fieldDescriptor : fields.keySet()) {
+ IRubyObject value = fields.get(fieldDescriptor);
+ this.builder.setField(fieldDescriptor, convert(context, fieldDescriptor, value, depth));
+ }
+ return this.builder.build();
+ }
+
+ protected Descriptors.Descriptor getDescriptor() {
+ return this.descriptor;
+ }
+
+ // Internal use only, called by Google::Protobuf.deep_copy
+ protected IRubyObject deepCopy(ThreadContext context) {
+ RubyMessage copy = (RubyMessage) metaClass.newInstance(context, Block.NULL_BLOCK);
+ for (Descriptors.FieldDescriptor fdef : this.descriptor.getFields()) {
+ if (fdef.isRepeated()) {
+ copy.addRepeatedField(fdef, this.getRepeatedField(context, fdef).deepCopy(context));
+ } else if (fields.containsKey(fdef)) {
+ copy.fields.put(fdef, fields.get(fdef));
+ } else if (this.builder.hasField(fdef)) {
+ copy.fields.put(fdef, wrapField(context, fdef, this.builder.getField(fdef)));
+ }
+ }
+ return copy;
+ }
+
+ private RubyRepeatedField getRepeatedField(ThreadContext context, Descriptors.FieldDescriptor fieldDescriptor) {
+ if (this.repeatedFields.containsKey(fieldDescriptor)) {
+ return this.repeatedFields.get(fieldDescriptor);
+ }
+ int count = this.builder.getRepeatedFieldCount(fieldDescriptor);
+ RubyRepeatedField ret = repeatedFieldForFieldDescriptor(context, fieldDescriptor);
+ for (int i = 0; i < count; i++) {
+ ret.push(context, wrapField(context, fieldDescriptor, this.builder.getRepeatedField(fieldDescriptor, i)));
+ }
+ addRepeatedField(fieldDescriptor, ret);
+ return ret;
+ }
+
+ private void addRepeatedField(Descriptors.FieldDescriptor fieldDescriptor, RubyRepeatedField repeatedField) {
+ this.repeatedFields.put(fieldDescriptor, repeatedField);
+ }
+
+ private IRubyObject buildFrom(ThreadContext context, DynamicMessage dynamicMessage) {
+ this.builder.mergeFrom(dynamicMessage);
+ return this;
+ }
+
+ private Descriptors.FieldDescriptor findField(ThreadContext context, IRubyObject fieldName) {
+ String nameStr = fieldName.asJavaString();
+ Descriptors.FieldDescriptor ret = this.descriptor.findFieldByName(Utils.escapeIdentifier(nameStr));
+ if (ret == null)
+ throw context.runtime.newArgumentError("field " + fieldName.asJavaString() + " is not found");
+ return ret;
+ }
+
+ private boolean hasField(IRubyObject fieldName) {
+ String nameStr = fieldName.asJavaString();
+ return this.descriptor.findFieldByName(Utils.escapeIdentifier(nameStr)) != null;
+ }
+
+ private void checkRepeatedFieldType(ThreadContext context, IRubyObject value,
+ Descriptors.FieldDescriptor fieldDescriptor) {
+ Ruby runtime = context.runtime;
+ if (!(value instanceof RubyRepeatedField)) {
+ throw runtime.newTypeError("Expected repeated field array");
+ }
+ }
+
+ // convert a ruby object to protobuf type, with type check
+ private Object convert(ThreadContext context,
+ Descriptors.FieldDescriptor fieldDescriptor,
+ IRubyObject value, int depth) {
+ Ruby runtime = context.runtime;
+ Object val = null;
+ switch (fieldDescriptor.getType()) {
+ case INT32:
+ case INT64:
+ case UINT32:
+ case UINT64:
+ if (!Utils.isRubyNum(value)) {
+ throw runtime.newTypeError("Expected number type for integral field.");
+ }
+ Utils.checkIntTypePrecision(context, fieldDescriptor.getType(), value);
+ switch (fieldDescriptor.getType()) {
+ case INT32:
+ val = RubyNumeric.num2int(value);
+ break;
+ case INT64:
+ val = RubyNumeric.num2long(value);
+ break;
+ case UINT32:
+ val = Utils.num2uint(value);
+ break;
+ case UINT64:
+ val = Utils.num2ulong(context.runtime, value);
+ break;
+ default:
+ break;
+ }
+ break;
+ case FLOAT:
+ if (!Utils.isRubyNum(value))
+ throw runtime.newTypeError("Expected number type for float field.");
+ val = (float) RubyNumeric.num2dbl(value);
+ break;
+ case DOUBLE:
+ if (!Utils.isRubyNum(value))
+ throw runtime.newTypeError("Expected number type for double field.");
+ val = RubyNumeric.num2dbl(value);
+ break;
+ case BOOL:
+ if (!(value instanceof RubyBoolean))
+ throw runtime.newTypeError("Invalid argument for boolean field.");
+ val = value.isTrue();
+ break;
+ case BYTES:
+ case STRING:
+ Utils.validateStringEncoding(context, fieldDescriptor.getType(), value);
+ RubyString str = (RubyString) value;
+ switch (fieldDescriptor.getType()) {
+ case BYTES:
+ val = ByteString.copyFrom(str.getBytes());
+ break;
+ case STRING:
+ val = str.asJavaString();
+ break;
+ default:
+ break;
+ }
+ break;
+ case MESSAGE:
+ RubyClass typeClass = (RubyClass) ((RubyDescriptor) getDescriptorForField(context, fieldDescriptor)).msgclass(context);
+ if (!value.getMetaClass().equals(typeClass))
+ throw runtime.newTypeError(value, "Invalid type to assign to submessage field.");
+ val = ((RubyMessage) value).build(context, depth + 1);
+ break;
+ case ENUM:
+ Descriptors.EnumDescriptor enumDescriptor = fieldDescriptor.getEnumType();
+
+ if (Utils.isRubyNum(value)) {
+ val = enumDescriptor.findValueByNumberCreatingIfUnknown(RubyNumeric.num2int(value));
+ } else if (value instanceof RubySymbol) {
+ val = enumDescriptor.findValueByName(value.asJavaString());
+ } else {
+ throw runtime.newTypeError("Expected number or symbol type for enum field.");
+ }
+ if (val == null) {
+ throw runtime.newRangeError("Enum value " + value + " is not found.");
+ }
+ break;
+ default:
+ break;
+ }
+ return val;
+ }
+
+ private IRubyObject wrapField(ThreadContext context, Descriptors.FieldDescriptor fieldDescriptor, Object value) {
+ if (value == null) {
+ return context.runtime.getNil();
+ }
+ Ruby runtime = context.runtime;
+ switch (fieldDescriptor.getType()) {
+ case INT32:
+ case INT64:
+ case UINT32:
+ case UINT64:
+ case FLOAT:
+ case DOUBLE:
+ case BOOL:
+ case BYTES:
+ case STRING:
+ return Utils.wrapPrimaryValue(context, fieldDescriptor.getType(), value);
+ case MESSAGE:
+ RubyClass typeClass = (RubyClass) ((RubyDescriptor) getDescriptorForField(context, fieldDescriptor)).msgclass(context);
+ RubyMessage msg = (RubyMessage) typeClass.newInstance(context, Block.NULL_BLOCK);
+ return msg.buildFrom(context, (DynamicMessage) value);
+ case ENUM:
+ Descriptors.EnumValueDescriptor enumValueDescriptor = (Descriptors.EnumValueDescriptor) value;
+ if (enumValueDescriptor.getIndex() == -1) { // UNKNOWN ENUM VALUE
+ return runtime.newFixnum(enumValueDescriptor.getNumber());
+ }
+ return runtime.newSymbol(enumValueDescriptor.getName());
+ default:
+ return runtime.newString(value.toString());
+ }
+ }
+
+ private RubyRepeatedField repeatedFieldForFieldDescriptor(ThreadContext context,
+ Descriptors.FieldDescriptor fieldDescriptor) {
+ IRubyObject typeClass = context.runtime.getNilClass();
+
+ IRubyObject descriptor = getDescriptorForField(context, fieldDescriptor);
+ Descriptors.FieldDescriptor.Type type = fieldDescriptor.getType();
+ if (type == Descriptors.FieldDescriptor.Type.MESSAGE) {
+ typeClass = ((RubyDescriptor) descriptor).msgclass(context);
+
+ } else if (type == Descriptors.FieldDescriptor.Type.ENUM) {
+ typeClass = ((RubyEnumDescriptor) descriptor).enummodule(context);
+ }
+ return new RubyRepeatedField(context.runtime, cRepeatedField, type, typeClass);
+ }
+
+ protected IRubyObject getField(ThreadContext context, Descriptors.FieldDescriptor fieldDescriptor) {
+ Descriptors.OneofDescriptor oneofDescriptor = fieldDescriptor.getContainingOneof();
+ if (oneofDescriptor != null) {
+ if (oneofCases.get(oneofDescriptor) == fieldDescriptor) {
+ return fields.get(fieldDescriptor);
+ } else {
+ Descriptors.FieldDescriptor oneofCase = builder.getOneofFieldDescriptor(oneofDescriptor);
+ if (oneofCase != fieldDescriptor) {
+ if (fieldDescriptor.getType() == Descriptors.FieldDescriptor.Type.MESSAGE) {
+ return context.runtime.getNil();
+ } else {
+ return wrapField(context, fieldDescriptor, fieldDescriptor.getDefaultValue());
+ }
+ }
+ IRubyObject value = wrapField(context, oneofCase, builder.getField(oneofCase));
+ fields.put(fieldDescriptor, value);
+ return value;
+ }
+ }
+
+ if (Utils.isMapEntry(fieldDescriptor)) {
+ RubyMap map = maps.get(fieldDescriptor);
+ if (map == null) {
+ map = newMapForField(context, fieldDescriptor);
+ int mapSize = this.builder.getRepeatedFieldCount(fieldDescriptor);
+ Descriptors.FieldDescriptor keyField = fieldDescriptor.getMessageType().findFieldByNumber(1);
+ Descriptors.FieldDescriptor valueField = fieldDescriptor.getMessageType().findFieldByNumber(2);
+ RubyDescriptor kvDescriptor = (RubyDescriptor) getDescriptorForField(context, fieldDescriptor);
+ RubyClass kvClass = (RubyClass) kvDescriptor.msgclass(context);
+ for (int i = 0; i < mapSize; i++) {
+ RubyMessage kvMessage = (RubyMessage) kvClass.newInstance(context, Block.NULL_BLOCK);
+ DynamicMessage message = (DynamicMessage) this.builder.getRepeatedField(fieldDescriptor, i);
+ kvMessage.buildFrom(context, message);
+ map.indexSet(context, kvMessage.getField(context, keyField), kvMessage.getField(context, valueField));
+ }
+ maps.put(fieldDescriptor, map);
+ }
+ return map;
+ }
+ if (fieldDescriptor.isRepeated()) {
+ return getRepeatedField(context, fieldDescriptor);
+ }
+ if (fieldDescriptor.getType() != Descriptors.FieldDescriptor.Type.MESSAGE ||
+ this.builder.hasField(fieldDescriptor) || fields.containsKey(fieldDescriptor)) {
+ if (fields.containsKey(fieldDescriptor)) {
+ return fields.get(fieldDescriptor);
+ } else {
+ IRubyObject value = wrapField(context, fieldDescriptor, this.builder.getField(fieldDescriptor));
+ if (this.builder.hasField(fieldDescriptor)) {
+ fields.put(fieldDescriptor, value);
+ }
+ return value;
+ }
+ }
+ return context.runtime.getNil();
+ }
+
+ protected IRubyObject setField(ThreadContext context, Descriptors.FieldDescriptor fieldDescriptor, IRubyObject value) {
+ if (Utils.isMapEntry(fieldDescriptor)) {
+ if (!(value instanceof RubyMap)) {
+ throw context.runtime.newTypeError("Expected Map instance");
+ }
+ RubyMap thisMap = (RubyMap) getField(context, fieldDescriptor);
+ thisMap.mergeIntoSelf(context, value);
+ } else if (fieldDescriptor.isRepeated()) {
+ checkRepeatedFieldType(context, value, fieldDescriptor);
+ if (value instanceof RubyRepeatedField) {
+ addRepeatedField(fieldDescriptor, (RubyRepeatedField) value);
+ } else {
+ RubyArray ary = value.convertToArray();
+ RubyRepeatedField repeatedField = rubyToRepeatedField(context, fieldDescriptor, ary);
+ addRepeatedField(fieldDescriptor, repeatedField);
+ }
+ } else {
+ Descriptors.OneofDescriptor oneofDescriptor = fieldDescriptor.getContainingOneof();
+ if (oneofDescriptor != null) {
+ Descriptors.FieldDescriptor oneofCase = oneofCases.get(oneofDescriptor);
+ if (oneofCase != null && oneofCase != fieldDescriptor) {
+ fields.remove(oneofCase);
+ }
+ if (value.isNil()) {
+ oneofCases.remove(oneofDescriptor);
+ fields.remove(fieldDescriptor);
+ } else {
+ oneofCases.put(oneofDescriptor, fieldDescriptor);
+ fields.put(fieldDescriptor, value);
+ }
+ } else {
+ Descriptors.FieldDescriptor.Type fieldType = fieldDescriptor.getType();
+ IRubyObject typeClass = context.runtime.getObject();
+ boolean addValue = true;
+ if (fieldType == Descriptors.FieldDescriptor.Type.MESSAGE) {
+ typeClass = ((RubyDescriptor) getDescriptorForField(context, fieldDescriptor)).msgclass(context);
+ if (value.isNil()){
+ addValue = false;
+ }
+ } else if (fieldType == Descriptors.FieldDescriptor.Type.ENUM) {
+ typeClass = ((RubyEnumDescriptor) getDescriptorForField(context, fieldDescriptor)).enummodule(context);
+ Descriptors.EnumDescriptor enumDescriptor = fieldDescriptor.getEnumType();
+ if (Utils.isRubyNum(value)) {
+ Descriptors.EnumValueDescriptor val =
+ enumDescriptor.findValueByNumberCreatingIfUnknown(RubyNumeric.num2int(value));
+ if (val.getIndex() != -1) value = context.runtime.newSymbol(val.getName());
+ }
+ }
+ if (addValue) {
+ value = Utils.checkType(context, fieldType, value, (RubyModule) typeClass);
+ this.fields.put(fieldDescriptor, value);
+ } else {
+ this.fields.remove(fieldDescriptor);
+ }
+ }
+ }
+ return context.runtime.getNil();
+ }
+
+ private String layoutInspect() {
+ ThreadContext context = getRuntime().getCurrentContext();
+ StringBuilder sb = new StringBuilder();
+ for (Descriptors.FieldDescriptor fdef : descriptor.getFields()) {
+ sb.append(Utils.unescapeIdentifier(fdef.getName()));
+ sb.append(": ");
+ sb.append(getField(context, fdef).inspect());
+ sb.append(", ");
+ }
+ return sb.substring(0, sb.length() - 2);
+ }
+
+ private IRubyObject getDescriptorForField(ThreadContext context, Descriptors.FieldDescriptor fieldDescriptor) {
+ RubyDescriptor thisRbDescriptor = (RubyDescriptor) getDescriptor(context, metaClass);
+ return thisRbDescriptor.lookup(fieldDescriptor.getName()).getSubType(context);
+ }
+
+ private RubyRepeatedField rubyToRepeatedField(ThreadContext context,
+ Descriptors.FieldDescriptor fieldDescriptor, IRubyObject value) {
+ RubyArray arr = value.convertToArray();
+ RubyRepeatedField repeatedField = repeatedFieldForFieldDescriptor(context, fieldDescriptor);
+ for (int i = 0; i < arr.size(); i++) {
+ repeatedField.push(context, arr.eltInternal(i));
+ }
+ return repeatedField;
+ }
+
+ private RubyMap newMapForField(ThreadContext context, Descriptors.FieldDescriptor fieldDescriptor) {
+ RubyDescriptor mapDescriptor = (RubyDescriptor) getDescriptorForField(context, fieldDescriptor);
+ Descriptors.FieldDescriptor keyField = fieldDescriptor.getMessageType().findFieldByNumber(1);
+ Descriptors.FieldDescriptor valueField = fieldDescriptor.getMessageType().findFieldByNumber(2);
+ IRubyObject keyType = RubySymbol.newSymbol(context.runtime, keyField.getType().name());
+ IRubyObject valueType = RubySymbol.newSymbol(context.runtime, valueField.getType().name());
+ if (valueField.getType() == Descriptors.FieldDescriptor.Type.MESSAGE) {
+ RubyFieldDescriptor rubyFieldDescriptor = (RubyFieldDescriptor) mapDescriptor.lookup(context,
+ context.runtime.newString("value"));
+ RubyDescriptor rubyDescriptor = (RubyDescriptor) rubyFieldDescriptor.getSubType(context);
+ return (RubyMap) cMap.newInstance(context, keyType, valueType,
+ rubyDescriptor.msgclass(context), Block.NULL_BLOCK);
+ } else {
+ return (RubyMap) cMap.newInstance(context, keyType, valueType, Block.NULL_BLOCK);
+ }
+ }
+
+ private Descriptors.FieldDescriptor getOneofCase(Descriptors.OneofDescriptor oneof) {
+ if (oneofCases.containsKey(oneof)) {
+ return oneofCases.get(oneof);
+ }
+ return builder.getOneofFieldDescriptor(oneof);
+ }
+
+ private Descriptors.Descriptor descriptor;
+ private DynamicMessage.Builder builder;
+ private RubyClass cRepeatedField;
+ private RubyClass cMap;
+ private Map<Descriptors.FieldDescriptor, RubyRepeatedField> repeatedFields;
+ private Map<Descriptors.FieldDescriptor, RubyMap> maps;
+ private Map<Descriptors.FieldDescriptor, IRubyObject> fields;
+ private Map<Descriptors.OneofDescriptor, Descriptors.FieldDescriptor> oneofCases;
+
+ private static final int SINK_MAXIMUM_NESTING = 64;
+}
diff --git a/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyMessageBuilderContext.java b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyMessageBuilderContext.java
new file mode 100644
index 0000000000..a619b803cc
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyMessageBuilderContext.java
@@ -0,0 +1,217 @@
+/*
+ * Protocol Buffers - Google's data interchange format
+ * Copyright 2014 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.jruby;
+
+import com.google.protobuf.Descriptors;
+import org.jruby.*;
+import org.jruby.anno.JRubyClass;
+import org.jruby.anno.JRubyMethod;
+import org.jruby.runtime.Binding;
+import org.jruby.runtime.Block;
+import org.jruby.runtime.ObjectAllocator;
+import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.builtin.IRubyObject;
+
+@JRubyClass(name = "MessageBuilderContext")
+public class RubyMessageBuilderContext extends RubyObject {
+ public static void createRubyMessageBuilderContext(Ruby runtime) {
+ RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
+ RubyClass cMessageBuilderContext = protobuf.defineClassUnder("MessageBuilderContext", runtime.getObject(), new ObjectAllocator() {
+ @Override
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
+ return new RubyMessageBuilderContext(runtime, klazz);
+ }
+ });
+ cMessageBuilderContext.defineAnnotatedMethods(RubyMessageBuilderContext.class);
+ }
+
+ public RubyMessageBuilderContext(Ruby ruby, RubyClass klazz) {
+ super(ruby, klazz);
+ }
+
+ @JRubyMethod
+ public IRubyObject initialize(ThreadContext context, IRubyObject descriptor, IRubyObject rubyBuilder) {
+ this.cFieldDescriptor = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::FieldDescriptor");
+ this.cDescriptor = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::Descriptor");
+ this.cOneofDescriptor = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::OneofDescriptor");
+ this.cOneofBuilderContext = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::Internal::OneofBuilderContext");
+ this.descriptor = (RubyDescriptor) descriptor;
+ this.builder = (RubyBuilder) rubyBuilder;
+ return this;
+ }
+
+ /*
+ * call-seq:
+ * MessageBuilderContext.optional(name, type, number, type_class = nil)
+ *
+ * Defines a new optional field on this message type with the given type, tag
+ * number, and type class (for message and enum fields). The type must be a Ruby
+ * symbol (as accepted by FieldDescriptor#type=) and the type_class must be a
+ * string, if present (as accepted by FieldDescriptor#submsg_name=).
+ */
+ @JRubyMethod(required = 3, optional = 1)
+ public IRubyObject optional(ThreadContext context, IRubyObject[] args) {
+ Ruby runtime = context.runtime;
+ IRubyObject typeClass = runtime.getNil();
+ if (args.length > 3) typeClass = args[3];
+ msgdefAddField(context, "optional", args[0], args[1], args[2], typeClass);
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * MessageBuilderContext.required(name, type, number, type_class = nil)
+ *
+ * Defines a new required field on this message type with the given type, tag
+ * number, and type class (for message and enum fields). The type must be a Ruby
+ * symbol (as accepted by FieldDescriptor#type=) and the type_class must be a
+ * string, if present (as accepted by FieldDescriptor#submsg_name=).
+ *
+ * Proto3 does not have required fields, but this method exists for
+ * completeness. Any attempt to add a message type with required fields to a
+ * pool will currently result in an error.
+ */
+ @JRubyMethod(required = 3, optional = 1)
+ public IRubyObject required(ThreadContext context, IRubyObject[] args) {
+ IRubyObject typeClass = context.runtime.getNil();
+ if (args.length > 3) typeClass = args[3];
+ msgdefAddField(context, "required", args[0], args[1], args[2], typeClass);
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * MessageBuilderContext.repeated(name, type, number, type_class = nil)
+ *
+ * Defines a new repeated field on this message type with the given type, tag
+ * number, and type class (for message and enum fields). The type must be a Ruby
+ * symbol (as accepted by FieldDescriptor#type=) and the type_class must be a
+ * string, if present (as accepted by FieldDescriptor#submsg_name=).
+ */
+ @JRubyMethod(required = 3, optional = 1)
+ public IRubyObject repeated(ThreadContext context, IRubyObject[] args) {
+ IRubyObject typeClass = context.runtime.getNil();
+ if (args.length > 3) typeClass = args[3];
+ msgdefAddField(context, "repeated", args[0], args[1], args[2], typeClass);
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * MessageBuilderContext.map(name, key_type, value_type, number,
+ * value_type_class = nil)
+ *
+ * Defines a new map field on this message type with the given key and value
+ * types, tag number, and type class (for message and enum value types). The key
+ * type must be :int32/:uint32/:int64/:uint64, :bool, or :string. The value type
+ * type must be a Ruby symbol (as accepted by FieldDescriptor#type=) and the
+ * type_class must be a string, if present (as accepted by
+ * FieldDescriptor#submsg_name=).
+ */
+ @JRubyMethod(required = 4, optional = 1)
+ public IRubyObject map(ThreadContext context, IRubyObject[] args) {
+ Ruby runtime = context.runtime;
+ IRubyObject name = args[0];
+ IRubyObject keyType = args[1];
+ IRubyObject valueType = args[2];
+ IRubyObject number = args[3];
+ IRubyObject typeClass = args.length > 4 ? args[4] : context.runtime.getNil();
+
+ // Validate the key type. We can't accept enums, messages, or floats/doubles
+ // as map keys. (We exclude these explicitly, and the field-descriptor setter
+ // below then ensures that the type is one of the remaining valid options.)
+ if (keyType.equals(RubySymbol.newSymbol(runtime, "float")) ||
+ keyType.equals(RubySymbol.newSymbol(runtime, "double")) ||
+ keyType.equals(RubySymbol.newSymbol(runtime, "enum")) ||
+ keyType.equals(RubySymbol.newSymbol(runtime, "message")))
+ throw runtime.newArgumentError("Cannot add a map field with a float, double, enum, or message type.");
+
+ // Create a new message descriptor for the map entry message, and create a
+ // repeated submessage field here with that type.
+ RubyDescriptor mapentryDesc = (RubyDescriptor) cDescriptor.newInstance(context, Block.NULL_BLOCK);
+ IRubyObject mapentryDescName = RubySymbol.newSymbol(runtime, name).id2name(context);
+ mapentryDesc.setName(context, mapentryDescName);
+ mapentryDesc.setMapEntry(true);
+
+ //optional <type> key = 1;
+ RubyFieldDescriptor keyField = (RubyFieldDescriptor) cFieldDescriptor.newInstance(context, Block.NULL_BLOCK);
+ keyField.setName(context, runtime.newString("key"));
+ keyField.setLabel(context, RubySymbol.newSymbol(runtime, "optional"));
+ keyField.setNumber(context, runtime.newFixnum(1));
+ keyField.setType(context, keyType);
+ mapentryDesc.addField(context, keyField);
+
+ //optional <type> value = 2;
+ RubyFieldDescriptor valueField = (RubyFieldDescriptor) cFieldDescriptor.newInstance(context, Block.NULL_BLOCK);
+ valueField.setName(context, runtime.newString("value"));
+ valueField.setLabel(context, RubySymbol.newSymbol(runtime, "optional"));
+ valueField.setNumber(context, runtime.newFixnum(2));
+ valueField.setType(context, valueType);
+ if (! typeClass.isNil()) valueField.setSubmsgName(context, typeClass);
+ mapentryDesc.addField(context, valueField);
+
+ // Add the map-entry message type to the current builder, and use the type to
+ // create the map field itself.
+ this.builder.pendingList.add(mapentryDesc);
+
+ msgdefAddField(context, "repeated", name, runtime.newSymbol("message"), number, mapentryDescName);
+ return runtime.getNil();
+ }
+
+ @JRubyMethod
+ public IRubyObject oneof(ThreadContext context, IRubyObject name, Block block) {
+ RubyOneofDescriptor oneofdef = (RubyOneofDescriptor)
+ cOneofDescriptor.newInstance(context, Block.NULL_BLOCK);
+ RubyOneofBuilderContext ctx = (RubyOneofBuilderContext)
+ cOneofBuilderContext.newInstance(context, oneofdef, Block.NULL_BLOCK);
+ oneofdef.setName(context, name);
+ Binding binding = block.getBinding();
+ binding.setSelf(ctx);
+ block.yieldSpecific(context);
+ descriptor.addOneof(context, oneofdef);
+ return context.runtime.getNil();
+ }
+
+ private void msgdefAddField(ThreadContext context, String label, IRubyObject name,
+ IRubyObject type, IRubyObject number, IRubyObject typeClass) {
+ descriptor.addField(context,
+ Utils.msgdefCreateField(context, label, name, type, number, typeClass, cFieldDescriptor));
+ }
+
+ private RubyDescriptor descriptor;
+ private RubyBuilder builder;
+ private RubyClass cFieldDescriptor;
+ private RubyClass cOneofDescriptor;
+ private RubyClass cOneofBuilderContext;
+ private RubyClass cDescriptor;
+}
diff --git a/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyOneofBuilderContext.java b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyOneofBuilderContext.java
new file mode 100644
index 0000000000..c9b99e0489
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyOneofBuilderContext.java
@@ -0,0 +1,84 @@
+/*
+ * Protocol Buffers - Google's data interchange format
+ * Copyright 2014 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.jruby;
+
+import org.jruby.Ruby;
+import org.jruby.RubyClass;
+import org.jruby.RubyModule;
+import org.jruby.RubyObject;
+import org.jruby.anno.JRubyClass;
+import org.jruby.anno.JRubyMethod;
+import org.jruby.runtime.ObjectAllocator;
+import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.builtin.IRubyObject;
+
+@JRubyClass(name = "OneofBuilderContext")
+public class RubyOneofBuilderContext extends RubyObject {
+ public static void createRubyOneofBuilderContext(Ruby runtime) {
+ RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
+ RubyModule internal = protobuf.defineModuleUnder("Internal");
+ RubyClass cRubyOneofBuidlerContext = internal.defineClassUnder("OneofBuilderContext", runtime.getObject(), new ObjectAllocator() {
+ @Override
+ public IRubyObject allocate(Ruby ruby, RubyClass rubyClass) {
+ return new RubyOneofBuilderContext(ruby, rubyClass);
+ }
+ });
+ cRubyOneofBuidlerContext.defineAnnotatedMethods(RubyOneofBuilderContext.class);
+ }
+
+ public RubyOneofBuilderContext(Ruby ruby, RubyClass rubyClass) {
+ super(ruby, rubyClass);
+ }
+
+ @JRubyMethod
+ public IRubyObject initialize(ThreadContext context, IRubyObject oneofdef) {
+ this.descriptor = (RubyOneofDescriptor) oneofdef;
+ this.cFieldDescriptor = (RubyClass) context.runtime.getClassFromPath("Google::Protobuf::FieldDescriptor");
+ return this;
+ }
+
+ @JRubyMethod(required = 3, optional = 1)
+ public IRubyObject optional(ThreadContext context, IRubyObject[] args) {
+ IRubyObject name = args[0];
+ IRubyObject type = args[1];
+ IRubyObject number = args[2];
+ IRubyObject typeClass = args.length > 3 ? args[3] : context.runtime.getNil();
+ RubyFieldDescriptor fieldDescriptor = Utils.msgdefCreateField(context, "optional",
+ name, type, number, typeClass, cFieldDescriptor);
+ descriptor.addField(context, fieldDescriptor);
+ return this;
+ }
+
+ private RubyOneofDescriptor descriptor;
+ private RubyClass cFieldDescriptor;
+}
diff --git a/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyOneofDescriptor.java b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyOneofDescriptor.java
new file mode 100644
index 0000000000..cc4ab66284
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyOneofDescriptor.java
@@ -0,0 +1,124 @@
+package com.google.protobuf.jruby;
+
+import com.google.protobuf.DescriptorProtos;
+import com.google.protobuf.Descriptors;
+import org.jruby.Ruby;
+import org.jruby.RubyClass;
+import org.jruby.RubyModule;
+import org.jruby.RubyObject;
+import org.jruby.anno.JRubyClass;
+import org.jruby.anno.JRubyMethod;
+import org.jruby.runtime.Block;
+import org.jruby.runtime.ObjectAllocator;
+import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.builtin.IRubyObject;
+
+import java.util.*;
+
+@JRubyClass(name = "OneofDescriptor", include = "Enumerable")
+public class RubyOneofDescriptor extends RubyObject {
+
+ public static void createRubyOneofDescriptor(Ruby runtime) {
+ RubyModule protobuf = runtime.getClassFromPath("Google::Protobuf");
+ RubyClass cRubyOneofDescriptor = protobuf.defineClassUnder("OneofDescriptor", runtime.getObject(), new ObjectAllocator() {
+ @Override
+ public IRubyObject allocate(Ruby ruby, RubyClass rubyClass) {
+ return new RubyOneofDescriptor(ruby, rubyClass);
+ }
+ });
+ cRubyOneofDescriptor.defineAnnotatedMethods(RubyOneofDescriptor.class);
+ cRubyOneofDescriptor.includeModule(runtime.getEnumerable());
+ }
+
+ public RubyOneofDescriptor(Ruby ruby, RubyClass rubyClass) {
+ super(ruby, rubyClass);
+ }
+
+ @JRubyMethod
+ public IRubyObject initialize(ThreadContext context) {
+ builder = DescriptorProtos.OneofDescriptorProto.newBuilder();
+ fields = new ArrayList<RubyFieldDescriptor>();
+ return this;
+ }
+
+ /*
+ * call-seq:
+ * OneofDescriptor.name => name
+ *
+ * Returns the name of this oneof.
+ */
+ @JRubyMethod(name = "name")
+ public IRubyObject getName(ThreadContext context) {
+ return name;
+ }
+
+ /*
+ * call-seq:
+ * OneofDescriptor.name = name
+ *
+ * Sets a new name for this oneof. The oneof must not have been added to a
+ * message descriptor yet.
+ */
+ @JRubyMethod(name = "name=")
+ public IRubyObject setName(ThreadContext context, IRubyObject name) {
+ this.name = context.runtime.newString(name.asJavaString());
+ this.builder.setName(name.asJavaString());
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * OneofDescriptor.add_field(field) => nil
+ *
+ * Adds a field to this oneof. The field may have been added to this oneof in
+ * the past, or the message to which this oneof belongs (if any), but may not
+ * have already been added to any other oneof or message. Otherwise, an
+ * exception is raised.
+ *
+ * All fields added to the oneof via this method will be automatically added to
+ * the message to which this oneof belongs, if it belongs to one currently, or
+ * else will be added to any message to which the oneof is later added at the
+ * time that it is added.
+ */
+ @JRubyMethod(name = "add_field")
+ public IRubyObject addField(ThreadContext context, IRubyObject obj) {
+ RubyFieldDescriptor fieldDescriptor = (RubyFieldDescriptor) obj;
+ fieldDescriptor.setOneofName(this.name);
+ fields.add(fieldDescriptor);
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * OneofDescriptor.each(&block) => nil
+ *
+ * Iterates through fields in this oneof, yielding to the block on each one.
+ */
+ @JRubyMethod
+ public IRubyObject each(ThreadContext context, Block block) {
+ for (RubyFieldDescriptor field : fields) {
+ block.yieldSpecific(context, field);
+ }
+ return context.runtime.getNil();
+ }
+
+ public DescriptorProtos.OneofDescriptorProto build(int index) {
+ for (RubyFieldDescriptor field: fields) {
+ field.setOneofIndex(index);
+ }
+ return this.builder.build();
+ }
+
+ protected Collection<RubyFieldDescriptor> getFields() {
+ return fields;
+ }
+
+ protected Descriptors.OneofDescriptor getOneofDescriptor() {
+ RubyFieldDescriptor fieldDescriptor = fields.get(0);
+ return fieldDescriptor.getFieldDef().getContainingOneof();
+ }
+
+ private IRubyObject name;
+ private DescriptorProtos.OneofDescriptorProto.Builder builder;
+ private List<RubyFieldDescriptor> fields;
+}
diff --git a/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyProtobuf.java b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyProtobuf.java
new file mode 100644
index 0000000000..2cf210d26f
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyProtobuf.java
@@ -0,0 +1,68 @@
+/*
+ * Protocol Buffers - Google's data interchange format
+ * Copyright 2014 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.jruby;
+
+import org.jruby.Ruby;
+import org.jruby.RubyModule;
+import org.jruby.anno.JRubyMethod;
+import org.jruby.anno.JRubyModule;
+import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.builtin.IRubyObject;
+
+@JRubyModule(name = "Protobuf")
+public class RubyProtobuf {
+
+ public static void createProtobuf(Ruby runtime) {
+ RubyModule mGoogle = runtime.getModule("Google");
+ RubyModule mProtobuf = mGoogle.defineModuleUnder("Protobuf");
+ mProtobuf.defineAnnotatedMethods(RubyProtobuf.class);
+ }
+
+ /*
+ * call-seq:
+ * Google::Protobuf.deep_copy(obj) => copy_of_obj
+ *
+ * Performs a deep copy of either a RepeatedField instance or a message object,
+ * recursively copying its members.
+ */
+ @JRubyMethod(name = "deep_copy", meta = true)
+ public static IRubyObject deepCopy(ThreadContext context, IRubyObject self, IRubyObject message) {
+ if (message instanceof RubyMessage) {
+ return ((RubyMessage) message).deepCopy(context);
+ } else if (message instanceof RubyRepeatedField) {
+ return ((RubyRepeatedField) message).deepCopy(context);
+ } else {
+ return ((RubyMap) message).deepCopy(context);
+ }
+ }
+}
diff --git a/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyRepeatedField.java b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyRepeatedField.java
new file mode 100644
index 0000000000..ae2907a985
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/RubyRepeatedField.java
@@ -0,0 +1,409 @@
+/*
+ * Protocol Buffers - Google's data interchange format
+ * Copyright 2014 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.jruby;
+
+import com.google.protobuf.Descriptors;
+import org.jruby.*;
+import org.jruby.anno.JRubyClass;
+import org.jruby.anno.JRubyMethod;
+import org.jruby.runtime.Block;
+import org.jruby.runtime.ObjectAllocator;
+import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.builtin.IRubyObject;
+import java.util.Arrays;
+
+@JRubyClass(name = "RepeatedClass", include = "Enumerable")
+public class RubyRepeatedField extends RubyObject {
+ public static void createRubyRepeatedField(Ruby runtime) {
+ RubyModule mProtobuf = runtime.getClassFromPath("Google::Protobuf");
+ RubyClass cRepeatedField = mProtobuf.defineClassUnder("RepeatedField", runtime.getObject(),
+ new ObjectAllocator() {
+ @Override
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
+ return new RubyRepeatedField(runtime, klazz);
+ }
+ });
+ cRepeatedField.defineAnnotatedMethods(RubyRepeatedField.class);
+ cRepeatedField.includeModule(runtime.getEnumerable());
+ }
+
+ public RubyRepeatedField(Ruby runtime, RubyClass klazz) {
+ super(runtime, klazz);
+ }
+
+ public RubyRepeatedField(Ruby runtime, RubyClass klazz, Descriptors.FieldDescriptor.Type fieldType, IRubyObject typeClass) {
+ this(runtime, klazz);
+ this.fieldType = fieldType;
+ this.storage = runtime.newArray();
+ this.typeClass = typeClass;
+ }
+
+ @JRubyMethod(required = 1, optional = 2)
+ public IRubyObject initialize(ThreadContext context, IRubyObject[] args) {
+ Ruby runtime = context.runtime;
+ this.storage = runtime.newArray();
+ IRubyObject ary = null;
+ if (!(args[0] instanceof RubySymbol)) {
+ throw runtime.newArgumentError("Expected Symbol for type name");
+ }
+ this.fieldType = Utils.rubyToFieldType(args[0]);
+ if (fieldType == Descriptors.FieldDescriptor.Type.MESSAGE
+ || fieldType == Descriptors.FieldDescriptor.Type.ENUM) {
+ if (args.length < 2)
+ throw runtime.newArgumentError("Expected at least 2 arguments for message/enum");
+ typeClass = args[1];
+ if (args.length > 2)
+ ary = args[2];
+ Utils.validateTypeClass(context, fieldType, typeClass);
+ } else {
+ if (args.length > 2)
+ throw runtime.newArgumentError("Too many arguments: expected 1 or 2");
+ if (args.length > 1)
+ ary = args[1];
+ }
+ if (ary != null) {
+ RubyArray arr = ary.convertToArray();
+ for (int i = 0; i < arr.size(); i++) {
+ this.storage.add(arr.eltInternal(i));
+ }
+ }
+ return this;
+ }
+
+ /*
+ * call-seq:
+ * RepeatedField.[]=(index, value)
+ *
+ * Sets the element at the given index. On out-of-bounds assignments, extends
+ * the array and fills the hole (if any) with default values.
+ */
+ @JRubyMethod(name = "[]=")
+ public IRubyObject indexSet(ThreadContext context, IRubyObject index, IRubyObject value) {
+ int arrIndex = normalizeArrayIndex(index);
+ value = Utils.checkType(context, fieldType, value, (RubyModule) typeClass);
+ IRubyObject defaultValue = defaultValue(context);
+ for (int i = this.storage.size(); i < arrIndex; i++) {
+ this.storage.set(i, defaultValue);
+ }
+ this.storage.set(arrIndex, value);
+ return context.runtime.getNil();
+ }
+
+ /*
+ * call-seq:
+ * RepeatedField.[](index) => value
+ *
+ * Accesses the element at the given index. Returns nil on out-of-bounds
+ */
+ @JRubyMethod(required=1, optional=1, name = {"at", "[]"})
+ public IRubyObject index(ThreadContext context, IRubyObject[] args) {
+ if (args.length == 1){
+ IRubyObject arg = args[0];
+ if (Utils.isRubyNum(arg)) {
+ /* standard case */
+ int arrIndex = normalizeArrayIndex(arg);
+ if (arrIndex < 0 || arrIndex >= this.storage.size()) {
+ return context.runtime.getNil();
+ }
+ return this.storage.eltInternal(arrIndex);
+ } else if (arg instanceof RubyRange) {
+ RubyRange range = ((RubyRange) arg);
+ int beg = RubyNumeric.num2int(range.first(context));
+ int to = RubyNumeric.num2int(range.last(context));
+ int len = to - beg + 1;
+ return this.storage.subseq(beg, len);
+ }
+ }
+ /* assume 2 arguments */
+ int beg = RubyNumeric.num2int(args[0]);
+ int len = RubyNumeric.num2int(args[1]);
+ if (beg < 0) {
+ beg += this.storage.size();
+ }
+ if (beg >= this.storage.size()) {
+ return context.runtime.getNil();
+ }
+ return this.storage.subseq(beg, len);
+ }
+
+ /*
+ * call-seq:
+ * RepeatedField.push(value)
+ *
+ * Adds a new element to the repeated field.
+ */
+ @JRubyMethod(name = {"push", "<<"})
+ public IRubyObject push(ThreadContext context, IRubyObject value) {
+ if (!(fieldType == Descriptors.FieldDescriptor.Type.MESSAGE &&
+ value == context.runtime.getNil())) {
+ value = Utils.checkType(context, fieldType, value, (RubyModule) typeClass);
+ }
+ this.storage.add(value);
+ return this.storage;
+ }
+
+ /*
+ * private Ruby method used by RepeatedField.pop
+ */
+ @JRubyMethod(visibility = org.jruby.runtime.Visibility.PRIVATE)
+ public IRubyObject pop_one(ThreadContext context) {
+ IRubyObject ret = this.storage.last();
+ this.storage.remove(ret);
+ return ret;
+ }
+
+ /*
+ * call-seq:
+ * RepeatedField.replace(list)
+ *
+ * Replaces the contents of the repeated field with the given list of elements.
+ */
+ @JRubyMethod
+ public IRubyObject replace(ThreadContext context, IRubyObject list) {
+ RubyArray arr = (RubyArray) list;
+ checkArrayElementType(context, arr);
+ this.storage = arr;
+ return this.storage;
+ }
+
+ /*
+ * call-seq:
+ * RepeatedField.clear
+ *
+ * Clears (removes all elements from) this repeated field.
+ */
+ @JRubyMethod
+ public IRubyObject clear(ThreadContext context) {
+ this.storage.clear();
+ return this.storage;
+ }
+
+ /*
+ * call-seq:
+ * RepeatedField.length
+ *
+ * Returns the length of this repeated field.
+ */
+ @JRubyMethod(name = {"length", "size"})
+ public IRubyObject length(ThreadContext context) {
+ return context.runtime.newFixnum(this.storage.size());
+ }
+
+ /*
+ * call-seq:
+ * RepeatedField.+(other) => repeated field
+ *
+ * Returns a new repeated field that contains the concatenated list of this
+ * repeated field's elements and other's elements. The other (second) list may
+ * be either another repeated field or a Ruby array.
+ */
+ @JRubyMethod(name = {"+"})
+ public IRubyObject plus(ThreadContext context, IRubyObject list) {
+ RubyRepeatedField dup = (RubyRepeatedField) dup(context);
+ if (list instanceof RubyArray) {
+ checkArrayElementType(context, (RubyArray) list);
+ dup.storage.addAll((RubyArray) list);
+ } else {
+ RubyRepeatedField repeatedField = (RubyRepeatedField) list;
+ if (! fieldType.equals(repeatedField.fieldType) || (typeClass != null && !
+ typeClass.equals(repeatedField.typeClass)))
+ throw context.runtime.newArgumentError("Attempt to append RepeatedField with different element type.");
+ dup.storage.addAll((RubyArray) repeatedField.toArray(context));
+ }
+ return dup;
+ }
+
+ /*
+ * call-seq:
+ * RepeatedField.concat(other) => self
+ *
+ * concats the passed in array to self. Returns a Ruby array.
+ */
+ @JRubyMethod
+ public IRubyObject concat(ThreadContext context, IRubyObject list) {
+ if (list instanceof RubyArray) {
+ checkArrayElementType(context, (RubyArray) list);
+ this.storage.addAll((RubyArray) list);
+ } else {
+ RubyRepeatedField repeatedField = (RubyRepeatedField) list;
+ if (! fieldType.equals(repeatedField.fieldType) || (typeClass != null && !
+ typeClass.equals(repeatedField.typeClass)))
+ throw context.runtime.newArgumentError("Attempt to append RepeatedField with different element type.");
+ this.storage.addAll((RubyArray) repeatedField.toArray(context));
+ }
+ return this.storage;
+ }
+
+ /*
+ * call-seq:
+ * RepeatedField.hash => hash_value
+ *
+ * Returns a hash value computed from this repeated field's elements.
+ */
+ @JRubyMethod
+ public IRubyObject hash(ThreadContext context) {
+ int hashCode = this.storage.hashCode();
+ return context.runtime.newFixnum(hashCode);
+ }
+
+ /*
+ * call-seq:
+ * RepeatedField.==(other) => boolean
+ *
+ * Compares this repeated field to another. Repeated fields are equal if their
+ * element types are equal, their lengths are equal, and each element is equal.
+ * Elements are compared as per normal Ruby semantics, by calling their :==
+ * methods (or performing a more efficient comparison for primitive types).
+ */
+ @JRubyMethod(name = "==")
+ public IRubyObject eq(ThreadContext context, IRubyObject other) {
+ return this.toArray(context).op_equal(context, other);
+ }
+
+ /*
+ * call-seq:
+ * RepeatedField.each(&block)
+ *
+ * Invokes the block once for each element of the repeated field. RepeatedField
+ * also includes Enumerable; combined with this method, the repeated field thus
+ * acts like an ordinary Ruby sequence.
+ */
+ @JRubyMethod
+ public IRubyObject each(ThreadContext context, Block block) {
+ this.storage.each(context, block);
+ return this.storage;
+ }
+
+
+ @JRubyMethod(name = {"to_ary", "to_a"})
+ public IRubyObject toArray(ThreadContext context) {
+ return this.storage;
+ }
+
+ /*
+ * call-seq:
+ * RepeatedField.dup => repeated_field
+ *
+ * Duplicates this repeated field with a shallow copy. References to all
+ * non-primitive element objects (e.g., submessages) are shared.
+ */
+ @JRubyMethod
+ public IRubyObject dup(ThreadContext context) {
+ RubyRepeatedField dup = new RubyRepeatedField(context.runtime, metaClass, fieldType, typeClass);
+ for (int i = 0; i < this.storage.size(); i++) {
+ dup.push(context, this.storage.eltInternal(i));
+ }
+ return dup;
+ }
+
+ // Java API
+ protected IRubyObject get(int index) {
+ return this.storage.eltInternal(index);
+ }
+
+ protected RubyRepeatedField deepCopy(ThreadContext context) {
+ RubyRepeatedField copy = new RubyRepeatedField(context.runtime, metaClass, fieldType, typeClass);
+ for (int i = 0; i < size(); i++) {
+ IRubyObject value = storage.eltInternal(i);
+ if (fieldType == Descriptors.FieldDescriptor.Type.MESSAGE) {
+ copy.storage.add(((RubyMessage) value).deepCopy(context));
+ } else {
+ copy.storage.add(value);
+ }
+ }
+ return copy;
+ }
+
+ protected int size() {
+ return this.storage.size();
+ }
+
+ private IRubyObject defaultValue(ThreadContext context) {
+ SentinelOuterClass.Sentinel sentinel = SentinelOuterClass.Sentinel.getDefaultInstance();
+ Object value;
+ switch (fieldType) {
+ case INT32:
+ value = sentinel.getDefaultInt32();
+ break;
+ case INT64:
+ value = sentinel.getDefaultInt64();
+ break;
+ case UINT32:
+ value = sentinel.getDefaultUnit32();
+ break;
+ case UINT64:
+ value = sentinel.getDefaultUint64();
+ break;
+ case FLOAT:
+ value = sentinel.getDefaultFloat();
+ break;
+ case DOUBLE:
+ value = sentinel.getDefaultDouble();
+ break;
+ case BOOL:
+ value = sentinel.getDefaultBool();
+ break;
+ case BYTES:
+ value = sentinel.getDefaultBytes();
+ break;
+ case STRING:
+ value = sentinel.getDefaultString();
+ break;
+ case ENUM:
+ IRubyObject defaultEnumLoc = context.runtime.newFixnum(0);
+ return RubyEnum.lookup(context, typeClass, defaultEnumLoc);
+ default:
+ return context.runtime.getNil();
+ }
+ return Utils.wrapPrimaryValue(context, fieldType, value);
+ }
+
+ private void checkArrayElementType(ThreadContext context, RubyArray arr) {
+ for (int i = 0; i < arr.getLength(); i++) {
+ Utils.checkType(context, fieldType, arr.eltInternal(i), (RubyModule) typeClass);
+ }
+ }
+
+ private int normalizeArrayIndex(IRubyObject index) {
+ int arrIndex = RubyNumeric.num2int(index);
+ int arrSize = this.storage.size();
+ if (arrIndex < 0 && arrSize > 0) {
+ arrIndex = arrSize + arrIndex;
+ }
+ return arrIndex;
+ }
+
+ private RubyArray storage;
+ private Descriptors.FieldDescriptor.Type fieldType;
+ private IRubyObject typeClass;
+}
diff --git a/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/SentinelOuterClass.java b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/SentinelOuterClass.java
new file mode 100644
index 0000000000..54f2c729a2
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/SentinelOuterClass.java
@@ -0,0 +1,776 @@
+/*
+ * Protocol Buffers - Google's data interchange format
+ * Copyright 2014 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.
+ */
+
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: sentinel.proto
+
+package com.google.protobuf.jruby;
+
+public final class SentinelOuterClass {
+ private SentinelOuterClass() {}
+ public static void registerAllExtensions(
+ com.google.protobuf.ExtensionRegistry registry) {
+ }
+ public interface SentinelOrBuilder extends
+ // @@protoc_insertion_point(interface_extends:com.google.protobuf.jruby.Sentinel)
+ com.google.protobuf.MessageOrBuilder {
+
+ /**
+ * <code>optional int32 default_int32 = 1;</code>
+ */
+ int getDefaultInt32();
+
+ /**
+ * <code>optional int64 default_int64 = 2;</code>
+ */
+ long getDefaultInt64();
+
+ /**
+ * <code>optional uint32 default_unit32 = 3;</code>
+ */
+ int getDefaultUnit32();
+
+ /**
+ * <code>optional uint64 default_uint64 = 4;</code>
+ */
+ long getDefaultUint64();
+
+ /**
+ * <code>optional string default_string = 5;</code>
+ */
+ java.lang.String getDefaultString();
+ /**
+ * <code>optional string default_string = 5;</code>
+ */
+ com.google.protobuf.ByteString
+ getDefaultStringBytes();
+
+ /**
+ * <code>optional bool default_bool = 6;</code>
+ */
+ boolean getDefaultBool();
+
+ /**
+ * <code>optional float default_float = 7;</code>
+ */
+ float getDefaultFloat();
+
+ /**
+ * <code>optional double default_double = 8;</code>
+ */
+ double getDefaultDouble();
+
+ /**
+ * <code>optional bytes default_bytes = 9;</code>
+ */
+ com.google.protobuf.ByteString getDefaultBytes();
+ }
+ /**
+ * Protobuf type {@code com.google.protobuf.jruby.Sentinel}
+ */
+ public static final class Sentinel extends
+ com.google.protobuf.GeneratedMessage implements
+ // @@protoc_insertion_point(message_implements:com.google.protobuf.jruby.Sentinel)
+ SentinelOrBuilder {
+ // Use Sentinel.newBuilder() to construct.
+ private Sentinel(com.google.protobuf.GeneratedMessage.Builder builder) {
+ super(builder);
+ }
+ private Sentinel() {
+ defaultInt32_ = 0;
+ defaultInt64_ = 0L;
+ defaultUnit32_ = 0;
+ defaultUint64_ = 0L;
+ defaultString_ = "";
+ defaultBool_ = false;
+ defaultFloat_ = 0F;
+ defaultDouble_ = 0D;
+ defaultBytes_ = com.google.protobuf.ByteString.EMPTY;
+ }
+
+ @java.lang.Override
+ public final com.google.protobuf.UnknownFieldSet
+ getUnknownFields() {
+ return com.google.protobuf.UnknownFieldSet.getDefaultInstance();
+ }
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.google.protobuf.jruby.SentinelOuterClass.internal_static_com_google_protobuf_jruby_Sentinel_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.google.protobuf.jruby.SentinelOuterClass.internal_static_com_google_protobuf_jruby_Sentinel_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ com.google.protobuf.jruby.SentinelOuterClass.Sentinel.class, com.google.protobuf.jruby.SentinelOuterClass.Sentinel.Builder.class);
+ }
+
+ public static final com.google.protobuf.Parser<Sentinel> PARSER =
+ new com.google.protobuf.AbstractParser<Sentinel>() {
+ public Sentinel parsePartialFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ Builder builder = newBuilder();
+ try {
+ builder.mergeFrom(input, extensionRegistry);
+ } catch (com.google.protobuf.InvalidProtocolBufferException e) {
+ throw e.setUnfinishedMessage(builder.buildPartial());
+ } catch (java.io.IOException e) {
+ throw new com.google.protobuf.InvalidProtocolBufferException(
+ e.getMessage()).setUnfinishedMessage(builder.buildPartial());
+ }
+ return builder.buildPartial();
+ }
+ };
+
+ @java.lang.Override
+ public com.google.protobuf.Parser<Sentinel> getParserForType() {
+ return PARSER;
+ }
+
+ public static final int DEFAULT_INT32_FIELD_NUMBER = 1;
+ private int defaultInt32_;
+ /**
+ * <code>optional int32 default_int32 = 1;</code>
+ */
+ public int getDefaultInt32() {
+ return defaultInt32_;
+ }
+
+ public static final int DEFAULT_INT64_FIELD_NUMBER = 2;
+ private long defaultInt64_;
+ /**
+ * <code>optional int64 default_int64 = 2;</code>
+ */
+ public long getDefaultInt64() {
+ return defaultInt64_;
+ }
+
+ public static final int DEFAULT_UNIT32_FIELD_NUMBER = 3;
+ private int defaultUnit32_;
+ /**
+ * <code>optional uint32 default_unit32 = 3;</code>
+ */
+ public int getDefaultUnit32() {
+ return defaultUnit32_;
+ }
+
+ public static final int DEFAULT_UINT64_FIELD_NUMBER = 4;
+ private long defaultUint64_;
+ /**
+ * <code>optional uint64 default_uint64 = 4;</code>
+ */
+ public long getDefaultUint64() {
+ return defaultUint64_;
+ }
+
+ public static final int DEFAULT_STRING_FIELD_NUMBER = 5;
+ private java.lang.Object defaultString_;
+ /**
+ * <code>optional string default_string = 5;</code>
+ */
+ public java.lang.String getDefaultString() {
+ java.lang.Object ref = defaultString_;
+ if (ref instanceof java.lang.String) {
+ return (java.lang.String) ref;
+ } else {
+ com.google.protobuf.ByteString bs =
+ (com.google.protobuf.ByteString) ref;
+ java.lang.String s = bs.toStringUtf8();
+ if (bs.isValidUtf8()) {
+ defaultString_ = s;
+ }
+ return s;
+ }
+ }
+ /**
+ * <code>optional string default_string = 5;</code>
+ */
+ public com.google.protobuf.ByteString
+ getDefaultStringBytes() {
+ java.lang.Object ref = defaultString_;
+ if (ref instanceof java.lang.String) {
+ com.google.protobuf.ByteString b =
+ com.google.protobuf.ByteString.copyFromUtf8(
+ (java.lang.String) ref);
+ defaultString_ = b;
+ return b;
+ } else {
+ return (com.google.protobuf.ByteString) ref;
+ }
+ }
+
+ public static final int DEFAULT_BOOL_FIELD_NUMBER = 6;
+ private boolean defaultBool_;
+ /**
+ * <code>optional bool default_bool = 6;</code>
+ */
+ public boolean getDefaultBool() {
+ return defaultBool_;
+ }
+
+ public static final int DEFAULT_FLOAT_FIELD_NUMBER = 7;
+ private float defaultFloat_;
+ /**
+ * <code>optional float default_float = 7;</code>
+ */
+ public float getDefaultFloat() {
+ return defaultFloat_;
+ }
+
+ public static final int DEFAULT_DOUBLE_FIELD_NUMBER = 8;
+ private double defaultDouble_;
+ /**
+ * <code>optional double default_double = 8;</code>
+ */
+ public double getDefaultDouble() {
+ return defaultDouble_;
+ }
+
+ public static final int DEFAULT_BYTES_FIELD_NUMBER = 9;
+ private com.google.protobuf.ByteString defaultBytes_;
+ /**
+ * <code>optional bytes default_bytes = 9;</code>
+ */
+ public com.google.protobuf.ByteString getDefaultBytes() {
+ return defaultBytes_;
+ }
+
+ public static com.google.protobuf.jruby.SentinelOuterClass.Sentinel parseFrom(
+ com.google.protobuf.ByteString data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static com.google.protobuf.jruby.SentinelOuterClass.Sentinel parseFrom(
+ com.google.protobuf.ByteString data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static com.google.protobuf.jruby.SentinelOuterClass.Sentinel parseFrom(byte[] data)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data);
+ }
+ public static com.google.protobuf.jruby.SentinelOuterClass.Sentinel parseFrom(
+ byte[] data,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws com.google.protobuf.InvalidProtocolBufferException {
+ return PARSER.parseFrom(data, extensionRegistry);
+ }
+ public static com.google.protobuf.jruby.SentinelOuterClass.Sentinel parseFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input);
+ }
+ public static com.google.protobuf.jruby.SentinelOuterClass.Sentinel parseFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input, extensionRegistry);
+ }
+ public static com.google.protobuf.jruby.SentinelOuterClass.Sentinel parseDelimitedFrom(java.io.InputStream input)
+ throws java.io.IOException {
+ return PARSER.parseDelimitedFrom(input);
+ }
+ public static com.google.protobuf.jruby.SentinelOuterClass.Sentinel parseDelimitedFrom(
+ java.io.InputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseDelimitedFrom(input, extensionRegistry);
+ }
+ public static com.google.protobuf.jruby.SentinelOuterClass.Sentinel parseFrom(
+ com.google.protobuf.CodedInputStream input)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input);
+ }
+ public static com.google.protobuf.jruby.SentinelOuterClass.Sentinel parseFrom(
+ com.google.protobuf.CodedInputStream input,
+ com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+ throws java.io.IOException {
+ return PARSER.parseFrom(input, extensionRegistry);
+ }
+
+ public static Builder newBuilder() { return new Builder(); }
+ public Builder newBuilderForType() { return newBuilder(); }
+ public static Builder newBuilder(com.google.protobuf.jruby.SentinelOuterClass.Sentinel prototype) {
+ return newBuilder().mergeFrom(prototype);
+ }
+ public Builder toBuilder() { return newBuilder(this); }
+
+ @java.lang.Override
+ protected Builder newBuilderForType(
+ com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+ Builder builder = new Builder(parent);
+ return builder;
+ }
+ /**
+ * Protobuf type {@code com.google.protobuf.jruby.Sentinel}
+ */
+ public static final class Builder extends
+ com.google.protobuf.GeneratedMessage.Builder<Builder> implements
+ // @@protoc_insertion_point(builder_implements:com.google.protobuf.jruby.Sentinel)
+ com.google.protobuf.jruby.SentinelOuterClass.SentinelOrBuilder {
+ public static final com.google.protobuf.Descriptors.Descriptor
+ getDescriptor() {
+ return com.google.protobuf.jruby.SentinelOuterClass.internal_static_com_google_protobuf_jruby_Sentinel_descriptor;
+ }
+
+ protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internalGetFieldAccessorTable() {
+ return com.google.protobuf.jruby.SentinelOuterClass.internal_static_com_google_protobuf_jruby_Sentinel_fieldAccessorTable
+ .ensureFieldAccessorsInitialized(
+ com.google.protobuf.jruby.SentinelOuterClass.Sentinel.class, com.google.protobuf.jruby.SentinelOuterClass.Sentinel.Builder.class);
+ }
+
+ // Construct using com.google.protobuf.jruby.SentinelOuterClass.Sentinel.newBuilder()
+ private Builder() {
+ maybeForceBuilderInitialization();
+ }
+
+ private Builder(
+ com.google.protobuf.GeneratedMessage.BuilderParent parent) {
+ super(parent);
+ maybeForceBuilderInitialization();
+ }
+ private void maybeForceBuilderInitialization() {
+ if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
+ }
+ }
+ public Builder clear() {
+ super.clear();
+ defaultInt32_ = 0;
+
+ defaultInt64_ = 0L;
+
+ defaultUnit32_ = 0;
+
+ defaultUint64_ = 0L;
+
+ defaultString_ = "";
+
+ defaultBool_ = false;
+
+ defaultFloat_ = 0F;
+
+ defaultDouble_ = 0D;
+
+ defaultBytes_ = com.google.protobuf.ByteString.EMPTY;
+
+ return this;
+ }
+
+ public com.google.protobuf.Descriptors.Descriptor
+ getDescriptorForType() {
+ return com.google.protobuf.jruby.SentinelOuterClass.internal_static_com_google_protobuf_jruby_Sentinel_descriptor;
+ }
+
+ public com.google.protobuf.jruby.SentinelOuterClass.Sentinel getDefaultInstanceForType() {
+ return com.google.protobuf.jruby.SentinelOuterClass.Sentinel.getDefaultInstance();
+ }
+
+ public com.google.protobuf.jruby.SentinelOuterClass.Sentinel build() {
+ com.google.protobuf.jruby.SentinelOuterClass.Sentinel result = buildPartial();
+ if (!result.isInitialized()) {
+ throw newUninitializedMessageException(result);
+ }
+ return result;
+ }
+
+ public com.google.protobuf.jruby.SentinelOuterClass.Sentinel buildPartial() {
+ com.google.protobuf.jruby.SentinelOuterClass.Sentinel result = new com.google.protobuf.jruby.SentinelOuterClass.Sentinel(this);
+ result.defaultInt32_ = defaultInt32_;
+ result.defaultInt64_ = defaultInt64_;
+ result.defaultUnit32_ = defaultUnit32_;
+ result.defaultUint64_ = defaultUint64_;
+ result.defaultString_ = defaultString_;
+ result.defaultBool_ = defaultBool_;
+ result.defaultFloat_ = defaultFloat_;
+ result.defaultDouble_ = defaultDouble_;
+ result.defaultBytes_ = defaultBytes_;
+ onBuilt();
+ return result;
+ }
+
+
+ private int defaultInt32_ ;
+ /**
+ * <code>optional int32 default_int32 = 1;</code>
+ */
+ public int getDefaultInt32() {
+ return defaultInt32_;
+ }
+ /**
+ * <code>optional int32 default_int32 = 1;</code>
+ */
+ public Builder setDefaultInt32(int value) {
+
+ defaultInt32_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional int32 default_int32 = 1;</code>
+ */
+ public Builder clearDefaultInt32() {
+
+ defaultInt32_ = 0;
+ onChanged();
+ return this;
+ }
+
+ private long defaultInt64_ ;
+ /**
+ * <code>optional int64 default_int64 = 2;</code>
+ */
+ public long getDefaultInt64() {
+ return defaultInt64_;
+ }
+ /**
+ * <code>optional int64 default_int64 = 2;</code>
+ */
+ public Builder setDefaultInt64(long value) {
+
+ defaultInt64_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional int64 default_int64 = 2;</code>
+ */
+ public Builder clearDefaultInt64() {
+
+ defaultInt64_ = 0L;
+ onChanged();
+ return this;
+ }
+
+ private int defaultUnit32_ ;
+ /**
+ * <code>optional uint32 default_unit32 = 3;</code>
+ */
+ public int getDefaultUnit32() {
+ return defaultUnit32_;
+ }
+ /**
+ * <code>optional uint32 default_unit32 = 3;</code>
+ */
+ public Builder setDefaultUnit32(int value) {
+
+ defaultUnit32_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional uint32 default_unit32 = 3;</code>
+ */
+ public Builder clearDefaultUnit32() {
+
+ defaultUnit32_ = 0;
+ onChanged();
+ return this;
+ }
+
+ private long defaultUint64_ ;
+ /**
+ * <code>optional uint64 default_uint64 = 4;</code>
+ */
+ public long getDefaultUint64() {
+ return defaultUint64_;
+ }
+ /**
+ * <code>optional uint64 default_uint64 = 4;</code>
+ */
+ public Builder setDefaultUint64(long value) {
+
+ defaultUint64_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional uint64 default_uint64 = 4;</code>
+ */
+ public Builder clearDefaultUint64() {
+
+ defaultUint64_ = 0L;
+ onChanged();
+ return this;
+ }
+
+ private java.lang.Object defaultString_ = "";
+ /**
+ * <code>optional string default_string = 5;</code>
+ */
+ public java.lang.String getDefaultString() {
+ java.lang.Object ref = defaultString_;
+ if (!(ref instanceof java.lang.String)) {
+ com.google.protobuf.ByteString bs =
+ (com.google.protobuf.ByteString) ref;
+ java.lang.String s = bs.toStringUtf8();
+ if (bs.isValidUtf8()) {
+ defaultString_ = s;
+ }
+ return s;
+ } else {
+ return (java.lang.String) ref;
+ }
+ }
+ /**
+ * <code>optional string default_string = 5;</code>
+ */
+ public com.google.protobuf.ByteString
+ getDefaultStringBytes() {
+ java.lang.Object ref = defaultString_;
+ if (ref instanceof String) {
+ com.google.protobuf.ByteString b =
+ com.google.protobuf.ByteString.copyFromUtf8(
+ (java.lang.String) ref);
+ defaultString_ = b;
+ return b;
+ } else {
+ return (com.google.protobuf.ByteString) ref;
+ }
+ }
+ /**
+ * <code>optional string default_string = 5;</code>
+ */
+ public Builder setDefaultString(
+ java.lang.String value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+
+ defaultString_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional string default_string = 5;</code>
+ */
+ public Builder clearDefaultString() {
+
+ defaultString_ = getDefaultInstance().getDefaultString();
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional string default_string = 5;</code>
+ */
+ public Builder setDefaultStringBytes(
+ com.google.protobuf.ByteString value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+
+ defaultString_ = value;
+ onChanged();
+ return this;
+ }
+
+ private boolean defaultBool_ ;
+ /**
+ * <code>optional bool default_bool = 6;</code>
+ */
+ public boolean getDefaultBool() {
+ return defaultBool_;
+ }
+ /**
+ * <code>optional bool default_bool = 6;</code>
+ */
+ public Builder setDefaultBool(boolean value) {
+
+ defaultBool_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional bool default_bool = 6;</code>
+ */
+ public Builder clearDefaultBool() {
+
+ defaultBool_ = false;
+ onChanged();
+ return this;
+ }
+
+ private float defaultFloat_ ;
+ /**
+ * <code>optional float default_float = 7;</code>
+ */
+ public float getDefaultFloat() {
+ return defaultFloat_;
+ }
+ /**
+ * <code>optional float default_float = 7;</code>
+ */
+ public Builder setDefaultFloat(float value) {
+
+ defaultFloat_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional float default_float = 7;</code>
+ */
+ public Builder clearDefaultFloat() {
+
+ defaultFloat_ = 0F;
+ onChanged();
+ return this;
+ }
+
+ private double defaultDouble_ ;
+ /**
+ * <code>optional double default_double = 8;</code>
+ */
+ public double getDefaultDouble() {
+ return defaultDouble_;
+ }
+ /**
+ * <code>optional double default_double = 8;</code>
+ */
+ public Builder setDefaultDouble(double value) {
+
+ defaultDouble_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional double default_double = 8;</code>
+ */
+ public Builder clearDefaultDouble() {
+
+ defaultDouble_ = 0D;
+ onChanged();
+ return this;
+ }
+
+ private com.google.protobuf.ByteString defaultBytes_ = com.google.protobuf.ByteString.EMPTY;
+ /**
+ * <code>optional bytes default_bytes = 9;</code>
+ */
+ public com.google.protobuf.ByteString getDefaultBytes() {
+ return defaultBytes_;
+ }
+ /**
+ * <code>optional bytes default_bytes = 9;</code>
+ */
+ public Builder setDefaultBytes(com.google.protobuf.ByteString value) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+
+ defaultBytes_ = value;
+ onChanged();
+ return this;
+ }
+ /**
+ * <code>optional bytes default_bytes = 9;</code>
+ */
+ public Builder clearDefaultBytes() {
+
+ defaultBytes_ = getDefaultInstance().getDefaultBytes();
+ onChanged();
+ return this;
+ }
+ public final Builder setUnknownFields(
+ final com.google.protobuf.UnknownFieldSet unknownFields) {
+ return this;
+ }
+
+ public final Builder mergeUnknownFields(
+ final com.google.protobuf.UnknownFieldSet unknownFields) {
+ return this;
+ }
+
+
+ // @@protoc_insertion_point(builder_scope:com.google.protobuf.jruby.Sentinel)
+ }
+
+ // @@protoc_insertion_point(class_scope:com.google.protobuf.jruby.Sentinel)
+ private static final com.google.protobuf.jruby.SentinelOuterClass.Sentinel defaultInstance;static {
+ defaultInstance = new com.google.protobuf.jruby.SentinelOuterClass.Sentinel();
+ }
+
+ public static com.google.protobuf.jruby.SentinelOuterClass.Sentinel getDefaultInstance() {
+ return defaultInstance;
+ }
+
+ public com.google.protobuf.jruby.SentinelOuterClass.Sentinel getDefaultInstanceForType() {
+ return defaultInstance;
+ }
+
+ }
+
+ private static final com.google.protobuf.Descriptors.Descriptor
+ internal_static_com_google_protobuf_jruby_Sentinel_descriptor;
+ private static
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable
+ internal_static_com_google_protobuf_jruby_Sentinel_fieldAccessorTable;
+
+ public static com.google.protobuf.Descriptors.FileDescriptor
+ getDescriptor() {
+ return descriptor;
+ }
+ private static com.google.protobuf.Descriptors.FileDescriptor
+ descriptor;
+ static {
+ java.lang.String[] descriptorData = {
+ "\n\016sentinel.proto\022\031com.google.protobuf.jr" +
+ "uby\"\334\001\n\010Sentinel\022\025\n\rdefault_int32\030\001 \001(\005\022" +
+ "\025\n\rdefault_int64\030\002 \001(\003\022\026\n\016default_unit32" +
+ "\030\003 \001(\r\022\026\n\016default_uint64\030\004 \001(\004\022\026\n\016defaul" +
+ "t_string\030\005 \001(\t\022\024\n\014default_bool\030\006 \001(\010\022\025\n\r" +
+ "default_float\030\007 \001(\002\022\026\n\016default_double\030\010 " +
+ "\001(\001\022\025\n\rdefault_bytes\030\t \001(\014B\002H\002b\006proto3"
+ };
+ com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
+ new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
+ public com.google.protobuf.ExtensionRegistry assignDescriptors(
+ com.google.protobuf.Descriptors.FileDescriptor root) {
+ descriptor = root;
+ return null;
+ }
+ };
+ com.google.protobuf.Descriptors.FileDescriptor
+ .internalBuildGeneratedFileFrom(descriptorData,
+ new com.google.protobuf.Descriptors.FileDescriptor[] {
+ }, assigner);
+ internal_static_com_google_protobuf_jruby_Sentinel_descriptor =
+ getDescriptor().getMessageTypes().get(0);
+ internal_static_com_google_protobuf_jruby_Sentinel_fieldAccessorTable = new
+ com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+ internal_static_com_google_protobuf_jruby_Sentinel_descriptor,
+ new java.lang.String[] { "DefaultInt32", "DefaultInt64", "DefaultUnit32", "DefaultUint64", "DefaultString", "DefaultBool", "DefaultFloat", "DefaultDouble", "DefaultBytes", });
+ }
+
+ // @@protoc_insertion_point(outer_class_scope)
+}
diff --git a/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/Utils.java b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/Utils.java
new file mode 100644
index 0000000000..f199feb962
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/java/com/google/protobuf/jruby/Utils.java
@@ -0,0 +1,303 @@
+/*
+ * Protocol Buffers - Google's data interchange format
+ * Copyright 2014 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.jruby;
+
+import com.google.protobuf.ByteString;
+import com.google.protobuf.DescriptorProtos;
+import com.google.protobuf.Descriptors;
+import org.jcodings.Encoding;
+import org.jcodings.specific.ASCIIEncoding;
+import org.jcodings.specific.USASCIIEncoding;
+import org.jcodings.specific.UTF8Encoding;
+import org.jruby.*;
+import org.jruby.runtime.Block;
+import org.jruby.runtime.ThreadContext;
+import org.jruby.runtime.builtin.IRubyObject;
+
+import java.math.BigInteger;
+
+public class Utils {
+ public static Descriptors.FieldDescriptor.Type rubyToFieldType(IRubyObject typeClass) {
+ return Descriptors.FieldDescriptor.Type.valueOf(typeClass.asJavaString().toUpperCase());
+ }
+
+ public static IRubyObject fieldTypeToRuby(ThreadContext context, Descriptors.FieldDescriptor.Type type) {
+ return fieldTypeToRuby(context, type.name());
+ }
+
+ public static IRubyObject fieldTypeToRuby(ThreadContext context, DescriptorProtos.FieldDescriptorProto.Type type) {
+ return fieldTypeToRuby(context, type.name());
+ }
+
+ private static IRubyObject fieldTypeToRuby(ThreadContext context, String typeName) {
+
+ return context.runtime.newSymbol(typeName.replace("TYPE_", "").toLowerCase());
+ }
+
+ public static IRubyObject checkType(ThreadContext context, Descriptors.FieldDescriptor.Type fieldType,
+ IRubyObject value, RubyModule typeClass) {
+ Ruby runtime = context.runtime;
+ Object val;
+ switch(fieldType) {
+ case INT32:
+ case INT64:
+ case UINT32:
+ case UINT64:
+ if (!isRubyNum(value)) {
+ throw runtime.newTypeError("Expected number type for integral field.");
+ }
+ switch(fieldType) {
+ case INT32:
+ RubyNumeric.num2int(value);
+ break;
+ case INT64:
+ RubyNumeric.num2long(value);
+ break;
+ case UINT32:
+ num2uint(value);
+ break;
+ default:
+ num2ulong(context.runtime, value);
+ break;
+ }
+ checkIntTypePrecision(context, fieldType, value);
+ break;
+ case FLOAT:
+ if (!isRubyNum(value))
+ throw runtime.newTypeError("Expected number type for float field.");
+ break;
+ case DOUBLE:
+ if (!isRubyNum(value))
+ throw runtime.newTypeError("Expected number type for double field.");
+ break;
+ case BOOL:
+ if (!(value instanceof RubyBoolean))
+ throw runtime.newTypeError("Invalid argument for boolean field.");
+ break;
+ case BYTES:
+ case STRING:
+ value = validateStringEncoding(context, fieldType, value);
+ break;
+ case MESSAGE:
+ if (value.getMetaClass() != typeClass) {
+ throw runtime.newTypeError(value, typeClass);
+ }
+ break;
+ case ENUM:
+ if (value instanceof RubySymbol) {
+ Descriptors.EnumDescriptor enumDescriptor =
+ ((RubyEnumDescriptor) typeClass.getInstanceVariable(DESCRIPTOR_INSTANCE_VAR)).getDescriptor();
+ val = enumDescriptor.findValueByName(value.asJavaString());
+ if (val == null)
+ throw runtime.newRangeError("Enum value " + value + " is not found.");
+ } else if(!isRubyNum(value)) {
+ throw runtime.newTypeError("Expected number or symbol type for enum field.");
+ }
+ break;
+ default:
+ break;
+ }
+ return value;
+ }
+
+ public static IRubyObject wrapPrimaryValue(ThreadContext context, Descriptors.FieldDescriptor.Type fieldType, Object value) {
+ Ruby runtime = context.runtime;
+ switch (fieldType) {
+ case INT32:
+ return runtime.newFixnum((Integer) value);
+ case INT64:
+ return runtime.newFixnum((Long) value);
+ case UINT32:
+ return runtime.newFixnum(((Integer) value) & (-1l >>> 32));
+ case UINT64:
+ long ret = (Long) value;
+ return ret >= 0 ? runtime.newFixnum(ret) :
+ RubyBignum.newBignum(runtime, UINT64_COMPLEMENTARY.add(new BigInteger(ret + "")));
+ case FLOAT:
+ return runtime.newFloat((Float) value);
+ case DOUBLE:
+ return runtime.newFloat((Double) value);
+ case BOOL:
+ return (Boolean) value ? runtime.getTrue() : runtime.getFalse();
+ case BYTES: {
+ IRubyObject wrapped = runtime.newString(((ByteString) value).toStringUtf8());
+ wrapped.setFrozen(true);
+ return wrapped;
+ }
+ case STRING: {
+ IRubyObject wrapped = runtime.newString(value.toString());
+ wrapped.setFrozen(true);
+ return wrapped;
+ }
+ default:
+ return runtime.getNil();
+ }
+ }
+
+ public static int num2uint(IRubyObject value) {
+ long longVal = RubyNumeric.num2long(value);
+ if (longVal > UINT_MAX)
+ throw value.getRuntime().newRangeError("Integer " + longVal + " too big to convert to 'unsigned int'");
+ long num = longVal;
+ if (num > Integer.MAX_VALUE || num < Integer.MIN_VALUE)
+ // encode to UINT32
+ num = (-longVal ^ (-1l >>> 32) ) + 1;
+ RubyNumeric.checkInt(value, num);
+ return (int) num;
+ }
+
+ public static long num2ulong(Ruby runtime, IRubyObject value) {
+ if (value instanceof RubyFloat) {
+ RubyBignum bignum = RubyBignum.newBignum(runtime, ((RubyFloat) value).getDoubleValue());
+ return RubyBignum.big2ulong(bignum);
+ } else if (value instanceof RubyBignum) {
+ return RubyBignum.big2ulong((RubyBignum) value);
+ } else {
+ return RubyNumeric.num2long(value);
+ }
+ }
+
+ public static IRubyObject validateStringEncoding(ThreadContext context, Descriptors.FieldDescriptor.Type type, IRubyObject value) {
+ if (!(value instanceof RubyString))
+ throw context.runtime.newTypeError("Invalid argument for string field.");
+ switch(type) {
+ case BYTES:
+ value = ((RubyString)value).encode(context, context.runtime.evalScriptlet("Encoding::ASCII_8BIT"));
+ break;
+ case STRING:
+ value = ((RubyString)value).encode(context, context.runtime.evalScriptlet("Encoding::UTF_8"));
+ break;
+ default:
+ break;
+ }
+ value.setFrozen(true);
+ return value;
+ }
+
+ public static void checkNameAvailability(ThreadContext context, String name) {
+ if (context.runtime.getObject().getConstantAt(name) != null)
+ throw context.runtime.newNameError(name + " is already defined", name);
+ }
+
+ /**
+ * Replace invalid "." in descriptor with __DOT__
+ * @param name
+ * @return
+ */
+ public static String escapeIdentifier(String name) {
+ return name.replace(".", BADNAME_REPLACEMENT);
+ }
+
+ /**
+ * Replace __DOT__ in descriptor name with "."
+ * @param name
+ * @return
+ */
+ public static String unescapeIdentifier(String name) {
+ return name.replace(BADNAME_REPLACEMENT, ".");
+ }
+
+ public static boolean isMapEntry(Descriptors.FieldDescriptor fieldDescriptor) {
+ return fieldDescriptor.getType() == Descriptors.FieldDescriptor.Type.MESSAGE &&
+ fieldDescriptor.isRepeated() &&
+ fieldDescriptor.getMessageType().getOptions().getMapEntry();
+ }
+
+ public static RubyFieldDescriptor msgdefCreateField(ThreadContext context, String label, IRubyObject name,
+ IRubyObject type, IRubyObject number, IRubyObject typeClass, RubyClass cFieldDescriptor) {
+ Ruby runtime = context.runtime;
+ RubyFieldDescriptor fieldDef = (RubyFieldDescriptor) cFieldDescriptor.newInstance(context, Block.NULL_BLOCK);
+ fieldDef.setLabel(context, runtime.newString(label));
+ fieldDef.setName(context, name);
+ fieldDef.setType(context, type);
+ fieldDef.setNumber(context, number);
+
+ if (!typeClass.isNil()) {
+ if (!(typeClass instanceof RubyString)) {
+ throw runtime.newArgumentError("expected string for type class");
+ }
+ fieldDef.setSubmsgName(context, typeClass);
+ }
+ return fieldDef;
+ }
+
+ protected static void checkIntTypePrecision(ThreadContext context, Descriptors.FieldDescriptor.Type type, IRubyObject value) {
+ if (value instanceof RubyFloat) {
+ double doubleVal = RubyNumeric.num2dbl(value);
+ if (Math.floor(doubleVal) != doubleVal) {
+ throw context.runtime.newRangeError("Non-integral floating point value assigned to integer field.");
+ }
+ }
+ if (type == Descriptors.FieldDescriptor.Type.UINT32 || type == Descriptors.FieldDescriptor.Type.UINT64) {
+ if (RubyNumeric.num2dbl(value) < 0) {
+ throw context.runtime.newRangeError("Assigning negative value to unsigned integer field.");
+ }
+ }
+ }
+
+ protected static boolean isRubyNum(Object value) {
+ return value instanceof RubyFixnum || value instanceof RubyFloat || value instanceof RubyBignum;
+ }
+
+ protected static void validateTypeClass(ThreadContext context, Descriptors.FieldDescriptor.Type type, IRubyObject value) {
+ Ruby runtime = context.runtime;
+ if (!(value instanceof RubyModule)) {
+ throw runtime.newArgumentError("TypeClass has incorrect type");
+ }
+ RubyModule klass = (RubyModule) value;
+ IRubyObject descriptor = klass.getInstanceVariable(DESCRIPTOR_INSTANCE_VAR);
+ if (descriptor.isNil()) {
+ throw runtime.newArgumentError("Type class has no descriptor. Please pass a " +
+ "class or enum as returned by the DescriptorPool.");
+ }
+ if (type == Descriptors.FieldDescriptor.Type.MESSAGE) {
+ if (! (descriptor instanceof RubyDescriptor)) {
+ throw runtime.newArgumentError("Descriptor has an incorrect type");
+ }
+ } else if (type == Descriptors.FieldDescriptor.Type.ENUM) {
+ if (! (descriptor instanceof RubyEnumDescriptor)) {
+ throw runtime.newArgumentError("Descriptor has an incorrect type");
+ }
+ }
+ }
+
+ public static String BADNAME_REPLACEMENT = "__DOT__";
+
+ public static String DESCRIPTOR_INSTANCE_VAR = "@descriptor";
+
+ public static String EQUAL_SIGN = "=";
+
+ private static BigInteger UINT64_COMPLEMENTARY = new BigInteger("18446744073709551616"); //Math.pow(2, 64)
+
+ private static long UINT_MAX = 0xffffffffl;
+}
diff --git a/third_party/protobuf/ruby/src/main/java/google/ProtobufJavaService.java b/third_party/protobuf/ruby/src/main/java/google/ProtobufJavaService.java
new file mode 100644
index 0000000000..bffb492a9e
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/java/google/ProtobufJavaService.java
@@ -0,0 +1,60 @@
+/*
+ * Protocol Buffers - Google's data interchange format
+ * Copyright 2014 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 google;
+
+import com.google.protobuf.jruby.*;
+import org.jruby.Ruby;
+import org.jruby.runtime.load.BasicLibraryService;
+
+import java.io.IOException;
+
+public class ProtobufJavaService implements BasicLibraryService {
+ @Override
+ public boolean basicLoad(Ruby ruby) throws IOException {
+ ruby.defineModule("Google");
+ RubyProtobuf.createProtobuf(ruby);
+ RubyDescriptor.createRubyDescriptor(ruby);
+ RubyBuilder.createRubyBuilder(ruby);
+ RubyFieldDescriptor.createRubyFileDescriptor(ruby);
+ RubyMessageBuilderContext.createRubyMessageBuilderContext(ruby);
+ RubyEnumDescriptor.createRubyEnumDescriptor(ruby);
+ RubyEnumBuilderContext.createRubyEnumBuilderContext(ruby);
+ RubyDescriptorPool.createRubyDescriptorPool(ruby);
+ RubyRepeatedField.createRubyRepeatedField(ruby);
+ RubyFieldDescriptor.createRubyFileDescriptor(ruby);
+ RubyMap.createRubyMap(ruby);
+ RubyOneofDescriptor.createRubyOneofDescriptor(ruby);
+ RubyOneofBuilderContext.createRubyOneofBuilderContext(ruby);
+ return true;
+ }
+}
diff --git a/third_party/protobuf/ruby/src/main/sentinel.proto b/third_party/protobuf/ruby/src/main/sentinel.proto
new file mode 100644
index 0000000000..722041ba07
--- /dev/null
+++ b/third_party/protobuf/ruby/src/main/sentinel.proto
@@ -0,0 +1,15 @@
+syntax = "proto3";
+package com.google.protobuf.jruby;
+option optimize_for = CODE_SIZE;
+
+message Sentinel {
+ int32 default_int32 = 1;
+ int64 default_int64 = 2;
+ uint32 default_unit32 = 3;
+ uint64 default_uint64 = 4;
+ string default_string = 5;
+ bool default_bool = 6;
+ float default_float = 7;
+ double default_double = 8;
+ bytes default_bytes = 9;
+}
diff --git a/third_party/protobuf/ruby/tests/basic.rb b/third_party/protobuf/ruby/tests/basic.rb
new file mode 100644
index 0000000000..34251234a0
--- /dev/null
+++ b/third_party/protobuf/ruby/tests/basic.rb
@@ -0,0 +1,1214 @@
+#!/usr/bin/ruby
+
+require 'google/protobuf'
+require 'test/unit'
+
+# ------------- generated code --------------
+
+module BasicTest
+ pool = Google::Protobuf::DescriptorPool.new
+ pool.build do
+ add_message "Foo" do
+ optional :bar, :message, 1, "Bar"
+ repeated :baz, :message, 2, "Baz"
+ end
+
+ add_message "Bar" do
+ optional :msg, :string, 1
+ end
+
+ add_message "Baz" do
+ optional :msg, :string, 1
+ end
+
+ add_message "TestMessage" do
+ optional :optional_int32, :int32, 1
+ optional :optional_int64, :int64, 2
+ optional :optional_uint32, :uint32, 3
+ optional :optional_uint64, :uint64, 4
+ optional :optional_bool, :bool, 5
+ optional :optional_float, :float, 6
+ optional :optional_double, :double, 7
+ optional :optional_string, :string, 8
+ optional :optional_bytes, :bytes, 9
+ optional :optional_msg, :message, 10, "TestMessage2"
+ optional :optional_enum, :enum, 11, "TestEnum"
+
+ repeated :repeated_int32, :int32, 12
+ repeated :repeated_int64, :int64, 13
+ repeated :repeated_uint32, :uint32, 14
+ repeated :repeated_uint64, :uint64, 15
+ repeated :repeated_bool, :bool, 16
+ repeated :repeated_float, :float, 17
+ repeated :repeated_double, :double, 18
+ repeated :repeated_string, :string, 19
+ repeated :repeated_bytes, :bytes, 20
+ repeated :repeated_msg, :message, 21, "TestMessage2"
+ repeated :repeated_enum, :enum, 22, "TestEnum"
+ end
+ add_message "TestMessage2" do
+ optional :foo, :int32, 1
+ end
+
+ add_message "Recursive1" do
+ optional :foo, :message, 1, "Recursive2"
+ end
+ add_message "Recursive2" do
+ optional :foo, :message, 1, "Recursive1"
+ end
+
+ add_enum "TestEnum" do
+ value :Default, 0
+ value :A, 1
+ value :B, 2
+ value :C, 3
+ end
+
+ add_message "BadFieldNames" do
+ optional :dup, :int32, 1
+ optional :class, :int32, 2
+ optional :"a.b", :int32, 3
+ end
+
+ add_message "MapMessage" do
+ map :map_string_int32, :string, :int32, 1
+ map :map_string_msg, :string, :message, 2, "TestMessage2"
+ end
+ add_message "MapMessageWireEquiv" do
+ repeated :map_string_int32, :message, 1, "MapMessageWireEquiv_entry1"
+ repeated :map_string_msg, :message, 2, "MapMessageWireEquiv_entry2"
+ end
+ add_message "MapMessageWireEquiv_entry1" do
+ optional :key, :string, 1
+ optional :value, :int32, 2
+ end
+ add_message "MapMessageWireEquiv_entry2" do
+ optional :key, :string, 1
+ optional :value, :message, 2, "TestMessage2"
+ end
+
+ add_message "OneofMessage" do
+ oneof :my_oneof do
+ optional :a, :string, 1
+ optional :b, :int32, 2
+ optional :c, :message, 3, "TestMessage2"
+ optional :d, :enum, 4, "TestEnum"
+ end
+ end
+ end
+
+ Foo = pool.lookup("Foo").msgclass
+ Bar = pool.lookup("Bar").msgclass
+ Baz = pool.lookup("Baz").msgclass
+ TestMessage = pool.lookup("TestMessage").msgclass
+ TestMessage2 = pool.lookup("TestMessage2").msgclass
+ Recursive1 = pool.lookup("Recursive1").msgclass
+ Recursive2 = pool.lookup("Recursive2").msgclass
+ TestEnum = pool.lookup("TestEnum").enummodule
+ BadFieldNames = pool.lookup("BadFieldNames").msgclass
+ MapMessage = pool.lookup("MapMessage").msgclass
+ MapMessageWireEquiv = pool.lookup("MapMessageWireEquiv").msgclass
+ MapMessageWireEquiv_entry1 =
+ pool.lookup("MapMessageWireEquiv_entry1").msgclass
+ MapMessageWireEquiv_entry2 =
+ pool.lookup("MapMessageWireEquiv_entry2").msgclass
+ OneofMessage = pool.lookup("OneofMessage").msgclass
+
+# ------------ test cases ---------------
+
+ class MessageContainerTest < Test::Unit::TestCase
+
+ def test_defaults
+ m = TestMessage.new
+ assert m.optional_int32 == 0
+ assert m.optional_int64 == 0
+ assert m.optional_uint32 == 0
+ assert m.optional_uint64 == 0
+ assert m.optional_bool == false
+ assert m.optional_float == 0.0
+ assert m.optional_double == 0.0
+ assert m.optional_string == ""
+ assert m.optional_bytes == ""
+ assert m.optional_msg == nil
+ assert m.optional_enum == :Default
+ end
+
+ def test_setters
+ m = TestMessage.new
+ m.optional_int32 = -42
+ assert m.optional_int32 == -42
+ m.optional_int64 = -0x1_0000_0000
+ assert m.optional_int64 == -0x1_0000_0000
+ m.optional_uint32 = 0x9000_0000
+ assert m.optional_uint32 == 0x9000_0000
+ m.optional_uint64 = 0x9000_0000_0000_0000
+ assert m.optional_uint64 == 0x9000_0000_0000_0000
+ m.optional_bool = true
+ assert m.optional_bool == true
+ m.optional_float = 0.5
+ assert m.optional_float == 0.5
+ m.optional_double = 0.5
+ m.optional_string = "hello"
+ assert m.optional_string == "hello"
+ m.optional_bytes = "world".encode!('ASCII-8BIT')
+ assert m.optional_bytes == "world"
+ m.optional_msg = TestMessage2.new(:foo => 42)
+ assert m.optional_msg == TestMessage2.new(:foo => 42)
+ m.optional_msg = nil
+ assert m.optional_msg == nil
+ end
+
+ def test_ctor_args
+ m = TestMessage.new(:optional_int32 => -42,
+ :optional_msg => TestMessage2.new,
+ :optional_enum => :C,
+ :repeated_string => ["hello", "there", "world"])
+ assert m.optional_int32 == -42
+ assert m.optional_msg.class == TestMessage2
+ assert m.repeated_string.length == 3
+ assert m.optional_enum == :C
+ assert m.repeated_string[0] == "hello"
+ assert m.repeated_string[1] == "there"
+ assert m.repeated_string[2] == "world"
+ end
+
+ def test_inspect
+ m = TestMessage.new(:optional_int32 => -42,
+ :optional_enum => :A,
+ :optional_msg => TestMessage2.new,
+ :repeated_string => ["hello", "there", "world"])
+ expected = '<BasicTest::TestMessage: optional_int32: -42, optional_int64: 0, optional_uint32: 0, optional_uint64: 0, optional_bool: false, optional_float: 0.0, optional_double: 0.0, optional_string: "", optional_bytes: "", optional_msg: <BasicTest::TestMessage2: foo: 0>, optional_enum: :A, repeated_int32: [], repeated_int64: [], repeated_uint32: [], repeated_uint64: [], repeated_bool: [], repeated_float: [], repeated_double: [], repeated_string: ["hello", "there", "world"], repeated_bytes: [], repeated_msg: [], repeated_enum: []>'
+ assert_equal expected, m.inspect
+ end
+
+ def test_hash
+ m1 = TestMessage.new(:optional_int32 => 42)
+ m2 = TestMessage.new(:optional_int32 => 102, repeated_string: ['please', 'work', 'ok?'])
+ m3 = TestMessage.new(:optional_int32 => 102, repeated_string: ['please', 'work', 'ok?'])
+ assert m1.hash != 0
+ assert m2.hash != 0
+ assert m3.hash != 0
+ # relying on the randomness here -- if hash function changes and we are
+ # unlucky enough to get a collision, then change the values above.
+ assert m1.hash != m2.hash
+ assert_equal m2.hash, m3.hash
+ end
+
+ def test_unknown_field_errors
+ e = assert_raise NoMethodError do
+ TestMessage.new.hello
+ end
+ assert_match(/hello/, e.message)
+
+ e = assert_raise NoMethodError do
+ TestMessage.new.hello = "world"
+ end
+ assert_match(/hello/, e.message)
+ end
+
+ def test_initialization_map_errors
+ e = assert_raise ArgumentError do
+ TestMessage.new(:hello => "world")
+ end
+ assert_match(/hello/, e.message)
+
+ e = assert_raise ArgumentError do
+ MapMessage.new(:map_string_int32 => "hello")
+ end
+ assert_equal e.message, "Expected Hash object as initializer value for map field 'map_string_int32'."
+
+ e = assert_raise ArgumentError do
+ TestMessage.new(:repeated_uint32 => "hello")
+ end
+ assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32'."
+ end
+
+ def test_type_errors
+ m = TestMessage.new
+ assert_raise TypeError do
+ m.optional_int32 = "hello"
+ end
+ assert_raise TypeError do
+ m.optional_string = 42
+ end
+ assert_raise TypeError do
+ m.optional_string = nil
+ end
+ assert_raise TypeError do
+ m.optional_bool = 42
+ end
+ assert_raise TypeError do
+ m.optional_msg = TestMessage.new # expects TestMessage2
+ end
+
+ assert_raise TypeError do
+ m.repeated_int32 = [] # needs RepeatedField
+ end
+
+ assert_raise TypeError do
+ m.repeated_int32.push "hello"
+ end
+
+ assert_raise TypeError do
+ m.repeated_msg.push TestMessage.new
+ end
+ end
+
+ def test_string_encoding
+ m = TestMessage.new
+
+ # Assigning a normal (ASCII or UTF8) string to a bytes field, or
+ # ASCII-8BIT to a string field will convert to the proper encoding.
+ m.optional_bytes = "Test string ASCII".encode!('ASCII')
+ assert m.optional_bytes.frozen?
+ assert_equal Encoding::ASCII_8BIT, m.optional_bytes.encoding
+ assert_equal "Test string ASCII", m.optional_bytes
+
+ assert_raise Encoding::UndefinedConversionError do
+ m.optional_bytes = "Test string UTF-8 \u0100".encode!('UTF-8')
+ end
+
+ assert_raise Encoding::UndefinedConversionError do
+ m.optional_string = ["FFFF"].pack('H*')
+ end
+
+ # "Ordinary" use case.
+ m.optional_bytes = ["FFFF"].pack('H*')
+ m.optional_string = "\u0100"
+
+ # strings are immutable so we can't do this, but serialize should catch it.
+ m.optional_string = "asdf".encode!('UTF-8')
+ assert_raise RuntimeError do
+ m.optional_string.encode!('ASCII-8BIT')
+ end
+ end
+
+ def test_rptfield_int32
+ l = Google::Protobuf::RepeatedField.new(:int32)
+ assert l.count == 0
+ l = Google::Protobuf::RepeatedField.new(:int32, [1, 2, 3])
+ assert l.count == 3
+ assert_equal [1, 2, 3], l
+ assert_equal l, [1, 2, 3]
+ l.push 4
+ assert l == [1, 2, 3, 4]
+ dst_list = []
+ l.each { |val| dst_list.push val }
+ assert dst_list == [1, 2, 3, 4]
+ assert l.to_a == [1, 2, 3, 4]
+ assert l[0] == 1
+ assert l[3] == 4
+ l[0] = 5
+ assert l == [5, 2, 3, 4]
+
+ l2 = l.dup
+ assert l == l2
+ assert l.object_id != l2.object_id
+ l2.push 6
+ assert l.count == 4
+ assert l2.count == 5
+
+ assert l.inspect == '[5, 2, 3, 4]'
+
+ l.concat([7, 8, 9])
+ assert l == [5, 2, 3, 4, 7, 8, 9]
+ assert l.pop == 9
+ assert l == [5, 2, 3, 4, 7, 8]
+
+ assert_raise TypeError do
+ m = TestMessage.new
+ l.push m
+ end
+
+ m = TestMessage.new
+ m.repeated_int32 = l
+ assert m.repeated_int32 == [5, 2, 3, 4, 7, 8]
+ assert m.repeated_int32.object_id == l.object_id
+ l.push 42
+ assert m.repeated_int32.pop == 42
+
+ l3 = l + l.dup
+ assert l3.count == l.count * 2
+ l.count.times do |i|
+ assert l3[i] == l[i]
+ assert l3[l.count + i] == l[i]
+ end
+
+ l.clear
+ assert l.count == 0
+ l += [1, 2, 3, 4]
+ l.replace([5, 6, 7, 8])
+ assert l == [5, 6, 7, 8]
+
+ l4 = Google::Protobuf::RepeatedField.new(:int32)
+ l4[5] = 42
+ assert l4 == [0, 0, 0, 0, 0, 42]
+
+ l4 << 100
+ assert l4 == [0, 0, 0, 0, 0, 42, 100]
+ l4 << 101 << 102
+ assert l4 == [0, 0, 0, 0, 0, 42, 100, 101, 102]
+ end
+
+ def test_parent_rptfield
+ #make sure we set the RepeatedField and can add to it
+ m = TestMessage.new
+ assert m.repeated_string == []
+ m.repeated_string << 'ok'
+ m.repeated_string.push('ok2')
+ assert m.repeated_string == ['ok', 'ok2']
+ m.repeated_string += ['ok3']
+ assert m.repeated_string == ['ok', 'ok2', 'ok3']
+ end
+
+ def test_rptfield_msg
+ l = Google::Protobuf::RepeatedField.new(:message, TestMessage)
+ l.push TestMessage.new
+ assert l.count == 1
+ assert_raise TypeError do
+ l.push TestMessage2.new
+ end
+ assert_raise TypeError do
+ l.push 42
+ end
+
+ l2 = l.dup
+ assert l2[0] == l[0]
+ assert l2[0].object_id == l[0].object_id
+
+ l2 = Google::Protobuf.deep_copy(l)
+ assert l2[0] == l[0]
+ assert l2[0].object_id != l[0].object_id
+
+ l3 = l + l2
+ assert l3.count == 2
+ assert l3[0] == l[0]
+ assert l3[1] == l2[0]
+ l3[0].optional_int32 = 1000
+ assert l[0].optional_int32 == 1000
+
+ new_msg = TestMessage.new(:optional_int32 => 200)
+ l4 = l + [new_msg]
+ assert l4.count == 2
+ new_msg.optional_int32 = 1000
+ assert l4[1].optional_int32 == 1000
+ end
+
+ def test_rptfield_enum
+ l = Google::Protobuf::RepeatedField.new(:enum, TestEnum)
+ l.push :A
+ l.push :B
+ l.push :C
+ assert l.count == 3
+ assert_raise RangeError do
+ l.push :D
+ end
+ assert l[0] == :A
+
+ l.push 4
+ assert l[3] == 4
+ end
+
+ def test_rptfield_initialize
+ assert_raise ArgumentError do
+ l = Google::Protobuf::RepeatedField.new
+ end
+ assert_raise ArgumentError do
+ l = Google::Protobuf::RepeatedField.new(:message)
+ end
+ assert_raise ArgumentError do
+ l = Google::Protobuf::RepeatedField.new([1, 2, 3])
+ end
+ assert_raise ArgumentError do
+ l = Google::Protobuf::RepeatedField.new(:message, [TestMessage2.new])
+ end
+ end
+
+ def test_rptfield_array_ducktyping
+ l = Google::Protobuf::RepeatedField.new(:int32)
+ length_methods = %w(count length size)
+ length_methods.each do |lm|
+ assert l.send(lm) == 0
+ end
+ # out of bounds returns a nil
+ assert l[0] == nil
+ assert l[1] == nil
+ assert l[-1] == nil
+ l.push 4
+ length_methods.each do |lm|
+ assert l.send(lm) == 1
+ end
+ assert l[0] == 4
+ assert l[1] == nil
+ assert l[-1] == 4
+ assert l[-2] == nil
+
+ l.push 2
+ length_methods.each do |lm|
+ assert l.send(lm) == 2
+ end
+ assert l[0] == 4
+ assert l[1] == 2
+ assert l[2] == nil
+ assert l[-1] == 2
+ assert l[-2] == 4
+ assert l[-3] == nil
+
+ #adding out of scope will backfill with empty objects
+ end
+
+ def test_map_basic
+ # allowed key types:
+ # :int32, :int64, :uint32, :uint64, :bool, :string, :bytes.
+
+ m = Google::Protobuf::Map.new(:string, :int32)
+ m["asdf"] = 1
+ assert m["asdf"] == 1
+ m["jkl;"] = 42
+ assert m == { "jkl;" => 42, "asdf" => 1 }
+ assert m.has_key?("asdf")
+ assert !m.has_key?("qwerty")
+ assert m.length == 2
+
+ m2 = m.dup
+ assert_equal m, m2
+ assert m.hash != 0
+ assert_equal m.hash, m2.hash
+
+ collected = {}
+ m.each { |k,v| collected[v] = k }
+ assert collected == { 42 => "jkl;", 1 => "asdf" }
+
+ assert m.delete("asdf") == 1
+ assert !m.has_key?("asdf")
+ assert m["asdf"] == nil
+ assert !m.has_key?("asdf")
+
+ # We only assert on inspect value when there is one map entry because the
+ # order in which elements appear is unspecified (depends on the internal
+ # hash function). We don't want a brittle test.
+ assert m.inspect == "{\"jkl;\"=>42}"
+
+ assert m.keys == ["jkl;"]
+ assert m.values == [42]
+
+ m.clear
+ assert m.length == 0
+ assert m == {}
+
+ assert_raise TypeError do
+ m[1] = 1
+ end
+ assert_raise RangeError do
+ m["asdf"] = 0x1_0000_0000
+ end
+ end
+
+ def test_map_ctor
+ m = Google::Protobuf::Map.new(:string, :int32,
+ {"a" => 1, "b" => 2, "c" => 3})
+ assert m == {"a" => 1, "c" => 3, "b" => 2}
+ end
+
+ def test_map_keytypes
+ m = Google::Protobuf::Map.new(:int32, :int32)
+ m[1] = 42
+ m[-1] = 42
+ assert_raise RangeError do
+ m[0x8000_0000] = 1
+ end
+ assert_raise TypeError do
+ m["asdf"] = 1
+ end
+
+ m = Google::Protobuf::Map.new(:int64, :int32)
+ m[0x1000_0000_0000_0000] = 1
+ assert_raise RangeError do
+ m[0x1_0000_0000_0000_0000] = 1
+ end
+ assert_raise TypeError do
+ m["asdf"] = 1
+ end
+
+ m = Google::Protobuf::Map.new(:uint32, :int32)
+ m[0x8000_0000] = 1
+ assert_raise RangeError do
+ m[0x1_0000_0000] = 1
+ end
+ assert_raise RangeError do
+ m[-1] = 1
+ end
+
+ m = Google::Protobuf::Map.new(:uint64, :int32)
+ m[0x8000_0000_0000_0000] = 1
+ assert_raise RangeError do
+ m[0x1_0000_0000_0000_0000] = 1
+ end
+ assert_raise RangeError do
+ m[-1] = 1
+ end
+
+ m = Google::Protobuf::Map.new(:bool, :int32)
+ m[true] = 1
+ m[false] = 2
+ assert_raise TypeError do
+ m[1] = 1
+ end
+ assert_raise TypeError do
+ m["asdf"] = 1
+ end
+
+ m = Google::Protobuf::Map.new(:string, :int32)
+ m["asdf"] = 1
+ assert_raise TypeError do
+ m[1] = 1
+ end
+ assert_raise Encoding::UndefinedConversionError do
+ bytestring = ["FFFF"].pack("H*")
+ m[bytestring] = 1
+ end
+
+ m = Google::Protobuf::Map.new(:bytes, :int32)
+ bytestring = ["FFFF"].pack("H*")
+ m[bytestring] = 1
+ # Allowed -- we will automatically convert to ASCII-8BIT.
+ m["asdf"] = 1
+ assert_raise TypeError do
+ m[1] = 1
+ end
+ end
+
+ def test_map_msg_enum_valuetypes
+ m = Google::Protobuf::Map.new(:string, :message, TestMessage)
+ m["asdf"] = TestMessage.new
+ assert_raise TypeError do
+ m["jkl;"] = TestMessage2.new
+ end
+
+ m = Google::Protobuf::Map.new(
+ :string, :message, TestMessage,
+ { "a" => TestMessage.new(:optional_int32 => 42),
+ "b" => TestMessage.new(:optional_int32 => 84) })
+ assert m.length == 2
+ assert m.values.map{|msg| msg.optional_int32}.sort == [42, 84]
+
+ m = Google::Protobuf::Map.new(:string, :enum, TestEnum,
+ { "x" => :A, "y" => :B, "z" => :C })
+ assert m.length == 3
+ assert m["z"] == :C
+ m["z"] = 2
+ assert m["z"] == :B
+ m["z"] = 4
+ assert m["z"] == 4
+ assert_raise RangeError do
+ m["z"] = :Z
+ end
+ assert_raise TypeError do
+ m["z"] = "z"
+ end
+ end
+
+ def test_map_dup_deep_copy
+ m = Google::Protobuf::Map.new(
+ :string, :message, TestMessage,
+ { "a" => TestMessage.new(:optional_int32 => 42),
+ "b" => TestMessage.new(:optional_int32 => 84) })
+
+ m2 = m.dup
+ assert m == m2
+ assert m.object_id != m2.object_id
+ assert m["a"].object_id == m2["a"].object_id
+ assert m["b"].object_id == m2["b"].object_id
+
+ m2 = Google::Protobuf.deep_copy(m)
+ assert m == m2
+ assert m.object_id != m2.object_id
+ assert m["a"].object_id != m2["a"].object_id
+ assert m["b"].object_id != m2["b"].object_id
+ end
+
+ def test_map_field
+ m = MapMessage.new
+ assert m.map_string_int32 == {}
+ assert m.map_string_msg == {}
+
+ m = MapMessage.new(
+ :map_string_int32 => {"a" => 1, "b" => 2},
+ :map_string_msg => {"a" => TestMessage2.new(:foo => 1),
+ "b" => TestMessage2.new(:foo => 2)})
+ assert m.map_string_int32.keys.sort == ["a", "b"]
+ assert m.map_string_int32["a"] == 1
+ assert m.map_string_msg["b"].foo == 2
+
+ m.map_string_int32["c"] = 3
+ assert m.map_string_int32["c"] == 3
+ m.map_string_msg["c"] = TestMessage2.new(:foo => 3)
+ assert m.map_string_msg["c"] == TestMessage2.new(:foo => 3)
+ m.map_string_msg.delete("b")
+ m.map_string_msg.delete("c")
+ assert m.map_string_msg == { "a" => TestMessage2.new(:foo => 1) }
+
+ assert_raise TypeError do
+ m.map_string_msg["e"] = TestMessage.new # wrong value type
+ end
+ # ensure nothing was added by the above
+ assert m.map_string_msg == { "a" => TestMessage2.new(:foo => 1) }
+
+ m.map_string_int32 = Google::Protobuf::Map.new(:string, :int32)
+ assert_raise TypeError do
+ m.map_string_int32 = Google::Protobuf::Map.new(:string, :int64)
+ end
+ assert_raise TypeError do
+ m.map_string_int32 = {}
+ end
+
+ assert_raise TypeError do
+ m = MapMessage.new(:map_string_int32 => { 1 => "I am not a number" })
+ end
+ end
+
+ def test_map_corruption
+ # This pattern led to a crash in a previous version of upb/protobuf.
+ m = MapMessage.new(map_string_int32: { "aaa" => 1 })
+ m.map_string_int32['podid'] = 2
+ m.map_string_int32['aaa'] = 3
+ end
+
+ def test_map_encode_decode
+ m = MapMessage.new(
+ :map_string_int32 => {"a" => 1, "b" => 2},
+ :map_string_msg => {"a" => TestMessage2.new(:foo => 1),
+ "b" => TestMessage2.new(:foo => 2)})
+ m2 = MapMessage.decode(MapMessage.encode(m))
+ assert m == m2
+
+ m3 = MapMessageWireEquiv.decode(MapMessage.encode(m))
+ assert m3.map_string_int32.length == 2
+
+ kv = {}
+ m3.map_string_int32.map { |msg| kv[msg.key] = msg.value }
+ assert kv == {"a" => 1, "b" => 2}
+
+ kv = {}
+ m3.map_string_msg.map { |msg| kv[msg.key] = msg.value }
+ assert kv == {"a" => TestMessage2.new(:foo => 1),
+ "b" => TestMessage2.new(:foo => 2)}
+ end
+
+ def test_oneof_descriptors
+ d = OneofMessage.descriptor
+ o = d.lookup_oneof("my_oneof")
+ assert o != nil
+ assert o.class == Google::Protobuf::OneofDescriptor
+ assert o.name == "my_oneof"
+ oneof_count = 0
+ d.each_oneof{ |oneof|
+ oneof_count += 1
+ assert oneof == o
+ }
+ assert oneof_count == 1
+ assert o.count == 4
+ field_names = o.map{|f| f.name}.sort
+ assert field_names == ["a", "b", "c", "d"]
+ end
+
+ def test_oneof
+ d = OneofMessage.new
+ assert d.a == ""
+ assert d.b == 0
+ assert d.c == nil
+ assert d.d == :Default
+ assert d.my_oneof == nil
+
+ d.a = "hi"
+ assert d.a == "hi"
+ assert d.b == 0
+ assert d.c == nil
+ assert d.d == :Default
+ assert d.my_oneof == :a
+
+ d.b = 42
+ assert d.a == ""
+ assert d.b == 42
+ assert d.c == nil
+ assert d.d == :Default
+ assert d.my_oneof == :b
+
+ d.c = TestMessage2.new(:foo => 100)
+ assert d.a == ""
+ assert d.b == 0
+ assert d.c.foo == 100
+ assert d.d == :Default
+ assert d.my_oneof == :c
+
+ d.d = :C
+ assert d.a == ""
+ assert d.b == 0
+ assert d.c == nil
+ assert d.d == :C
+ assert d.my_oneof == :d
+
+ d2 = OneofMessage.decode(OneofMessage.encode(d))
+ assert d2 == d
+
+ encoded_field_a = OneofMessage.encode(OneofMessage.new(:a => "string"))
+ encoded_field_b = OneofMessage.encode(OneofMessage.new(:b => 1000))
+ encoded_field_c = OneofMessage.encode(
+ OneofMessage.new(:c => TestMessage2.new(:foo => 1)))
+ encoded_field_d = OneofMessage.encode(OneofMessage.new(:d => :B))
+
+ d3 = OneofMessage.decode(
+ encoded_field_c + encoded_field_a + encoded_field_d)
+ assert d3.a == ""
+ assert d3.b == 0
+ assert d3.c == nil
+ assert d3.d == :B
+
+ d4 = OneofMessage.decode(
+ encoded_field_c + encoded_field_a + encoded_field_d +
+ encoded_field_c)
+ assert d4.a == ""
+ assert d4.b == 0
+ assert d4.c.foo == 1
+ assert d4.d == :Default
+
+ d5 = OneofMessage.new(:a => "hello")
+ assert d5.a == "hello"
+ d5.a = nil
+ assert d5.a == ""
+ assert OneofMessage.encode(d5) == ''
+ assert d5.my_oneof == nil
+ end
+
+ def test_enum_field
+ m = TestMessage.new
+ assert m.optional_enum == :Default
+ m.optional_enum = :A
+ assert m.optional_enum == :A
+ assert_raise RangeError do
+ m.optional_enum = :ASDF
+ end
+ m.optional_enum = 1
+ assert m.optional_enum == :A
+ m.optional_enum = 100
+ assert m.optional_enum == 100
+ end
+
+ def test_dup
+ m = TestMessage.new
+ m.optional_string = "hello"
+ m.optional_int32 = 42
+ tm1 = TestMessage2.new(:foo => 100)
+ tm2 = TestMessage2.new(:foo => 200)
+ m.repeated_msg.push tm1
+ assert m.repeated_msg[-1] == tm1
+ m.repeated_msg.push tm2
+ assert m.repeated_msg[-1] == tm2
+ m2 = m.dup
+ assert m == m2
+ m.optional_int32 += 1
+ assert m != m2
+ assert m.repeated_msg[0] == m2.repeated_msg[0]
+ assert m.repeated_msg[0].object_id == m2.repeated_msg[0].object_id
+ end
+
+ def test_deep_copy
+ m = TestMessage.new(:optional_int32 => 42,
+ :repeated_msg => [TestMessage2.new(:foo => 100)])
+ m2 = Google::Protobuf.deep_copy(m)
+ assert m == m2
+ assert m.repeated_msg == m2.repeated_msg
+ assert m.repeated_msg.object_id != m2.repeated_msg.object_id
+ assert m.repeated_msg[0].object_id != m2.repeated_msg[0].object_id
+ end
+
+ def test_eq
+ m = TestMessage.new(:optional_int32 => 42,
+ :repeated_int32 => [1, 2, 3])
+ m2 = TestMessage.new(:optional_int32 => 43,
+ :repeated_int32 => [1, 2, 3])
+ assert m != m2
+ end
+
+ def test_enum_lookup
+ assert TestEnum::A == 1
+ assert TestEnum::B == 2
+ assert TestEnum::C == 3
+
+ assert TestEnum::lookup(1) == :A
+ assert TestEnum::lookup(2) == :B
+ assert TestEnum::lookup(3) == :C
+
+ assert TestEnum::resolve(:A) == 1
+ assert TestEnum::resolve(:B) == 2
+ assert TestEnum::resolve(:C) == 3
+ end
+
+ def test_parse_serialize
+ m = TestMessage.new(:optional_int32 => 42,
+ :optional_string => "hello world",
+ :optional_enum => :B,
+ :repeated_string => ["a", "b", "c"],
+ :repeated_int32 => [42, 43, 44],
+ :repeated_enum => [:A, :B, :C, 100],
+ :repeated_msg => [TestMessage2.new(:foo => 1),
+ TestMessage2.new(:foo => 2)])
+ data = TestMessage.encode m
+ m2 = TestMessage.decode data
+ assert m == m2
+
+ data = Google::Protobuf.encode m
+ m2 = Google::Protobuf.decode(TestMessage, data)
+ assert m == m2
+ end
+
+ def test_encode_decode_helpers
+ m = TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2'])
+ assert_equal 'foo', m.optional_string
+ assert_equal ['bar1', 'bar2'], m.repeated_string
+
+ json = m.to_json
+ m2 = TestMessage.decode_json(json)
+ assert_equal 'foo', m2.optional_string
+ assert_equal ['bar1', 'bar2'], m2.repeated_string
+ if RUBY_PLATFORM != "java"
+ assert m2.optional_string.frozen?
+ assert m2.repeated_string[0].frozen?
+ end
+
+ proto = m.to_proto
+ m2 = TestMessage.decode(proto)
+ assert_equal 'foo', m2.optional_string
+ assert_equal ['bar1', 'bar2'], m2.repeated_string
+ end
+
+ def test_protobuf_encode_decode_helpers
+ m = TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2'])
+ encoded_msg = Google::Protobuf.encode(m)
+ assert_equal m.to_proto, encoded_msg
+
+ decoded_msg = Google::Protobuf.decode(TestMessage, encoded_msg)
+ assert_equal TestMessage.decode(m.to_proto), decoded_msg
+ end
+
+ def test_protobuf_encode_decode_json_helpers
+ m = TestMessage.new(:optional_string => 'foo', :repeated_string => ['bar1', 'bar2'])
+ encoded_msg = Google::Protobuf.encode_json(m)
+ assert_equal m.to_json, encoded_msg
+
+ decoded_msg = Google::Protobuf.decode_json(TestMessage, encoded_msg)
+ assert_equal TestMessage.decode_json(m.to_json), decoded_msg
+ end
+
+ def test_to_h
+ m = TestMessage.new(:optional_bool => true, :optional_double => -10.100001, :optional_string => 'foo', :repeated_string => ['bar1', 'bar2'])
+ expected_result = {
+ :optional_bool=>true,
+ :optional_bytes=>"",
+ :optional_double=>-10.100001,
+ :optional_enum=>:Default,
+ :optional_float=>0.0,
+ :optional_int32=>0,
+ :optional_int64=>0,
+ :optional_msg=>nil,
+ :optional_string=>"foo",
+ :optional_uint32=>0,
+ :optional_uint64=>0,
+ :repeated_bool=>[],
+ :repeated_bytes=>[],
+ :repeated_double=>[],
+ :repeated_enum=>[],
+ :repeated_float=>[],
+ :repeated_int32=>[],
+ :repeated_int64=>[],
+ :repeated_msg=>[],
+ :repeated_string=>["bar1", "bar2"],
+ :repeated_uint32=>[],
+ :repeated_uint64=>[]
+ }
+ assert_equal expected_result, m.to_h
+
+ m = MapMessage.new(
+ :map_string_int32 => {"a" => 1, "b" => 2},
+ :map_string_msg => {"a" => TestMessage2.new(:foo => 1),
+ "b" => TestMessage2.new(:foo => 2)})
+ expected_result = {
+ :map_string_int32 => {"a" => 1, "b" => 2},
+ :map_string_msg => {"a" => {:foo => 1}, "b" => {:foo => 2}}
+ }
+ assert_equal expected_result, m.to_h
+ end
+
+
+ def test_def_errors
+ s = Google::Protobuf::DescriptorPool.new
+ assert_raise TypeError do
+ s.build do
+ # enum with no default (integer value 0)
+ add_enum "MyEnum" do
+ value :A, 1
+ end
+ end
+ end
+ assert_raise TypeError do
+ s.build do
+ # message with required field (unsupported in proto3)
+ add_message "MyMessage" do
+ required :foo, :int32, 1
+ end
+ end
+ end
+ end
+
+ def test_corecursive
+ # just be sure that we can instantiate types with corecursive field-type
+ # references.
+ m = Recursive1.new(:foo => Recursive2.new(:foo => Recursive1.new))
+ assert Recursive1.descriptor.lookup("foo").subtype ==
+ Recursive2.descriptor
+ assert Recursive2.descriptor.lookup("foo").subtype ==
+ Recursive1.descriptor
+
+ serialized = Recursive1.encode(m)
+ m2 = Recursive1.decode(serialized)
+ assert m == m2
+ end
+
+ def test_serialize_cycle
+ m = Recursive1.new(:foo => Recursive2.new)
+ m.foo.foo = m
+ assert_raise RuntimeError do
+ serialized = Recursive1.encode(m)
+ end
+ end
+
+ def test_bad_field_names
+ m = BadFieldNames.new(:dup => 1, :class => 2)
+ m2 = m.dup
+ assert m == m2
+ assert m['dup'] == 1
+ assert m['class'] == 2
+ m['dup'] = 3
+ assert m['dup'] == 3
+ m['a.b'] = 4
+ assert m['a.b'] == 4
+ end
+
+ def test_int_ranges
+ m = TestMessage.new
+
+ m.optional_int32 = 0
+ m.optional_int32 = -0x8000_0000
+ m.optional_int32 = +0x7fff_ffff
+ m.optional_int32 = 1.0
+ m.optional_int32 = -1.0
+ m.optional_int32 = 2e9
+ assert_raise RangeError do
+ m.optional_int32 = -0x8000_0001
+ end
+ assert_raise RangeError do
+ m.optional_int32 = +0x8000_0000
+ end
+ assert_raise RangeError do
+ m.optional_int32 = +0x1000_0000_0000_0000_0000_0000 # force Bignum
+ end
+ assert_raise RangeError do
+ m.optional_int32 = 1e12
+ end
+ assert_raise RangeError do
+ m.optional_int32 = 1.5
+ end
+
+ m.optional_uint32 = 0
+ m.optional_uint32 = +0xffff_ffff
+ m.optional_uint32 = 1.0
+ m.optional_uint32 = 4e9
+ assert_raise RangeError do
+ m.optional_uint32 = -1
+ end
+ assert_raise RangeError do
+ m.optional_uint32 = -1.5
+ end
+ assert_raise RangeError do
+ m.optional_uint32 = -1.5e12
+ end
+ assert_raise RangeError do
+ m.optional_uint32 = -0x1000_0000_0000_0000
+ end
+ assert_raise RangeError do
+ m.optional_uint32 = +0x1_0000_0000
+ end
+ assert_raise RangeError do
+ m.optional_uint32 = +0x1000_0000_0000_0000_0000_0000 # force Bignum
+ end
+ assert_raise RangeError do
+ m.optional_uint32 = 1e12
+ end
+ assert_raise RangeError do
+ m.optional_uint32 = 1.5
+ end
+
+ m.optional_int64 = 0
+ m.optional_int64 = -0x8000_0000_0000_0000
+ m.optional_int64 = +0x7fff_ffff_ffff_ffff
+ m.optional_int64 = 1.0
+ m.optional_int64 = -1.0
+ m.optional_int64 = 8e18
+ m.optional_int64 = -8e18
+ assert_raise RangeError do
+ m.optional_int64 = -0x8000_0000_0000_0001
+ end
+ assert_raise RangeError do
+ m.optional_int64 = +0x8000_0000_0000_0000
+ end
+ assert_raise RangeError do
+ m.optional_int64 = +0x1000_0000_0000_0000_0000_0000 # force Bignum
+ end
+ assert_raise RangeError do
+ m.optional_int64 = 1e50
+ end
+ assert_raise RangeError do
+ m.optional_int64 = 1.5
+ end
+
+ m.optional_uint64 = 0
+ m.optional_uint64 = +0xffff_ffff_ffff_ffff
+ m.optional_uint64 = 1.0
+ m.optional_uint64 = 16e18
+ assert_raise RangeError do
+ m.optional_uint64 = -1
+ end
+ assert_raise RangeError do
+ m.optional_uint64 = -1.5
+ end
+ assert_raise RangeError do
+ m.optional_uint64 = -1.5e12
+ end
+ assert_raise RangeError do
+ m.optional_uint64 = -0x1_0000_0000_0000_0000
+ end
+ assert_raise RangeError do
+ m.optional_uint64 = +0x1_0000_0000_0000_0000
+ end
+ assert_raise RangeError do
+ m.optional_uint64 = +0x1000_0000_0000_0000_0000_0000 # force Bignum
+ end
+ assert_raise RangeError do
+ m.optional_uint64 = 1e50
+ end
+ assert_raise RangeError do
+ m.optional_uint64 = 1.5
+ end
+ end
+
+ def test_stress_test
+ m = TestMessage.new
+ m.optional_int32 = 42
+ m.optional_int64 = 0x100000000
+ m.optional_string = "hello world"
+ 10.times do m.repeated_msg.push TestMessage2.new(:foo => 42) end
+ 10.times do m.repeated_string.push "hello world" end
+
+ data = TestMessage.encode(m)
+
+ l = 0
+ 10_000.times do
+ m = TestMessage.decode(data)
+ data_new = TestMessage.encode(m)
+ assert data_new == data
+ data = data_new
+ end
+ end
+
+ def test_reflection
+ m = TestMessage.new(:optional_int32 => 1234)
+ msgdef = m.class.descriptor
+ assert msgdef.class == Google::Protobuf::Descriptor
+ assert msgdef.any? {|field| field.name == "optional_int32"}
+ optional_int32 = msgdef.lookup "optional_int32"
+ assert optional_int32.class == Google::Protobuf::FieldDescriptor
+ assert optional_int32 != nil
+ assert optional_int32.name == "optional_int32"
+ assert optional_int32.type == :int32
+ optional_int32.set(m, 5678)
+ assert m.optional_int32 == 5678
+ m.optional_int32 = 1000
+ assert optional_int32.get(m) == 1000
+
+ optional_msg = msgdef.lookup "optional_msg"
+ assert optional_msg.subtype == TestMessage2.descriptor
+
+ optional_msg.set(m, optional_msg.subtype.msgclass.new)
+
+ assert msgdef.msgclass == TestMessage
+
+ optional_enum = msgdef.lookup "optional_enum"
+ assert optional_enum.subtype == TestEnum.descriptor
+ assert optional_enum.subtype.class == Google::Protobuf::EnumDescriptor
+ optional_enum.subtype.each do |k, v|
+ # set with integer, check resolution to symbolic name
+ optional_enum.set(m, v)
+ assert optional_enum.get(m) == k
+ end
+ end
+
+ def test_json
+ # TODO: Fix JSON in JRuby version.
+ return if RUBY_PLATFORM == "java"
+ m = TestMessage.new(:optional_int32 => 1234,
+ :optional_int64 => -0x1_0000_0000,
+ :optional_uint32 => 0x8000_0000,
+ :optional_uint64 => 0xffff_ffff_ffff_ffff,
+ :optional_bool => true,
+ :optional_float => 1.0,
+ :optional_double => -1e100,
+ :optional_string => "Test string",
+ :optional_bytes => ["FFFFFFFF"].pack('H*'),
+ :optional_msg => TestMessage2.new(:foo => 42),
+ :repeated_int32 => [1, 2, 3, 4],
+ :repeated_string => ["a", "b", "c"],
+ :repeated_bool => [true, false, true, false],
+ :repeated_msg => [TestMessage2.new(:foo => 1),
+ TestMessage2.new(:foo => 2)])
+
+ json_text = TestMessage.encode_json(m)
+ m2 = TestMessage.decode_json(json_text)
+ assert m == m2
+
+ # Crash case from GitHub issue 283.
+ bar = Bar.new(msg: "bar")
+ baz1 = Baz.new(msg: "baz")
+ baz2 = Baz.new(msg: "quux")
+ Foo.encode_json(Foo.new)
+ Foo.encode_json(Foo.new(bar: bar))
+ Foo.encode_json(Foo.new(bar: bar, baz: [baz1, baz2]))
+ end
+
+ def test_json_maps
+ # TODO: Fix JSON in JRuby version.
+ return if RUBY_PLATFORM == "java"
+ m = MapMessage.new(:map_string_int32 => {"a" => 1})
+ expected = '{"mapStringInt32":{"a":1},"mapStringMsg":{}}'
+ expected_preserve = '{"map_string_int32":{"a":1},"map_string_msg":{}}'
+ assert MapMessage.encode_json(m) == expected
+
+ json = MapMessage.encode_json(m, :preserve_proto_fieldnames => true)
+ assert json == expected_preserve
+
+ m2 = MapMessage.decode_json(MapMessage.encode_json(m))
+ assert m == m2
+ end
+
+ def test_comparison_with_arbitrary_object
+ assert MapMessage.new != nil
+ end
+
+ def test_respond_to
+ # This test fails with JRuby 1.7.23, likely because of an old JRuby bug.
+ return if RUBY_PLATFORM == "java"
+ msg = MapMessage.new
+ assert msg.respond_to?(:map_string_int32)
+ assert !msg.respond_to?(:bacon)
+ end
+ end
+end
diff --git a/third_party/protobuf/ruby/tests/generated_code.proto b/third_party/protobuf/ruby/tests/generated_code.proto
new file mode 100644
index 0000000000..62fd83ed89
--- /dev/null
+++ b/third_party/protobuf/ruby/tests/generated_code.proto
@@ -0,0 +1,67 @@
+syntax = "proto3";
+
+package a.b.c;
+
+message TestMessage {
+ int32 optional_int32 = 1;
+ int64 optional_int64 = 2;
+ uint32 optional_uint32 = 3;
+ uint64 optional_uint64 = 4;
+ bool optional_bool = 5;
+ double optional_double = 6;
+ float optional_float = 7;
+ string optional_string = 8;
+ bytes optional_bytes = 9;
+ TestEnum optional_enum = 10;
+ TestMessage optional_msg = 11;
+
+ repeated int32 repeated_int32 = 21;
+ repeated int64 repeated_int64 = 22;
+ repeated uint32 repeated_uint32 = 23;
+ repeated uint64 repeated_uint64 = 24;
+ repeated bool repeated_bool = 25;
+ repeated double repeated_double = 26;
+ repeated float repeated_float = 27;
+ repeated string repeated_string = 28;
+ repeated bytes repeated_bytes = 29;
+ repeated TestEnum repeated_enum = 30;
+ repeated TestMessage repeated_msg = 31;
+
+ oneof my_oneof {
+ int32 oneof_int32 = 41;
+ int64 oneof_int64 = 42;
+ uint32 oneof_uint32 = 43;
+ uint64 oneof_uint64 = 44;
+ bool oneof_bool = 45;
+ double oneof_double = 46;
+ float oneof_float = 47;
+ string oneof_string = 48;
+ bytes oneof_bytes = 49;
+ TestEnum oneof_enum = 50;
+ TestMessage oneof_msg = 51;
+ }
+
+ map<int32, string> map_int32_string = 61;
+ map<int64, string> map_int64_string = 62;
+ map<uint32, string> map_uint32_string = 63;
+ map<uint64, string> map_uint64_string = 64;
+ map<bool, string> map_bool_string = 65;
+ map<string, string> map_string_string = 66;
+ map<string, TestMessage> map_string_msg = 67;
+ map<string, TestEnum> map_string_enum = 68;
+ map<string, int32> map_string_int32 = 69;
+ map<string, bool> map_string_bool = 70;
+
+ message NestedMessage {
+ int32 foo = 1;
+ }
+
+ NestedMessage nested_message = 80;
+}
+
+enum TestEnum {
+ Default = 0;
+ A = 1;
+ B = 2;
+ C = 3;
+}
diff --git a/third_party/protobuf/ruby/tests/generated_code_test.rb b/third_party/protobuf/ruby/tests/generated_code_test.rb
new file mode 100644
index 0000000000..b92b0462d1
--- /dev/null
+++ b/third_party/protobuf/ruby/tests/generated_code_test.rb
@@ -0,0 +1,19 @@
+#!/usr/bin/ruby
+
+# generated_code.rb is in the same directory as this test.
+$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
+
+require 'generated_code_pb'
+require 'test_import_pb'
+require 'test/unit'
+
+class GeneratedCodeTest < Test::Unit::TestCase
+ def test_generated_msg
+ # just test that we can instantiate the message. The purpose of this test
+ # is to ensure that the output of the code generator is valid Ruby and
+ # successfully creates message definitions and classes, not to test every
+ # aspect of the extension (basic.rb is for that).
+ m = A::B::C::TestMessage.new()
+ m2 = FooBar::TestImportedMessage.new()
+ end
+end
diff --git a/third_party/protobuf/ruby/tests/repeated_field_test.rb b/third_party/protobuf/ruby/tests/repeated_field_test.rb
new file mode 100644
index 0000000000..25727b7b28
--- /dev/null
+++ b/third_party/protobuf/ruby/tests/repeated_field_test.rb
@@ -0,0 +1,640 @@
+#!/usr/bin/ruby
+
+require 'google/protobuf'
+require 'test/unit'
+
+class RepeatedFieldTest < Test::Unit::TestCase
+
+ def test_acts_like_enumerator
+ m = TestMessage.new
+ (Enumerable.instance_methods - TestMessage.new.repeated_string.methods).each do |method_name|
+ assert m.repeated_string.respond_to?(method_name) == true, "does not respond to #{method_name}"
+ end
+ end
+
+ def test_acts_like_an_array
+ m = TestMessage.new
+ arr_methods = ([].methods - TestMessage.new.repeated_string.methods)
+ # jRuby additions to the Array class that we can ignore
+ arr_methods -= [ :indices, :iter_for_each, :iter_for_each_index,
+ :iter_for_each_with_index, :dimensions, :copy_data, :copy_data_simple,
+ :nitems, :iter_for_reverse_each, :indexes]
+ arr_methods.each do |method_name|
+ assert m.repeated_string.respond_to?(method_name) == true, "does not respond to #{method_name}"
+ end
+ end
+
+ def test_first
+ m = TestMessage.new
+ repeated_field_names(TestMessage).each do |field_name|
+ assert_nil m.send(field_name).first
+ end
+ fill_test_msg(m)
+ assert_equal -10, m.repeated_int32.first
+ assert_equal -1_000_000, m.repeated_int64.first
+ assert_equal 10, m.repeated_uint32.first
+ assert_equal 1_000_000, m.repeated_uint64.first
+ assert_equal true, m.repeated_bool.first
+ assert_equal -1.01, m.repeated_float.first.round(2)
+ assert_equal -1.0000000000001, m.repeated_double.first
+ assert_equal 'foo', m.repeated_string.first
+ assert_equal "bar".encode!('ASCII-8BIT'), m.repeated_bytes.first
+ assert_equal TestMessage2.new(:foo => 1), m.repeated_msg.first
+ assert_equal :A, m.repeated_enum.first
+ end
+
+
+ def test_last
+ m = TestMessage.new
+ repeated_field_names(TestMessage).each do |field_name|
+ assert_nil m.send(field_name).first
+ end
+ fill_test_msg(m)
+ assert_equal -11, m.repeated_int32.last
+ assert_equal -1_000_001, m.repeated_int64.last
+ assert_equal 11, m.repeated_uint32.last
+ assert_equal 1_000_001, m.repeated_uint64.last
+ assert_equal false, m.repeated_bool.last
+ assert_equal -1.02, m.repeated_float.last.round(2)
+ assert_equal -1.0000000000002, m.repeated_double.last
+ assert_equal 'bar', m.repeated_string.last
+ assert_equal "foo".encode!('ASCII-8BIT'), m.repeated_bytes.last
+ assert_equal TestMessage2.new(:foo => 2), m.repeated_msg.last
+ assert_equal :B, m.repeated_enum.last
+ end
+
+
+ def test_pop
+ m = TestMessage.new
+ repeated_field_names(TestMessage).each do |field_name|
+ assert_nil m.send(field_name).pop
+ end
+ fill_test_msg(m)
+
+ assert_equal -11, m.repeated_int32.pop
+ assert_equal -10, m.repeated_int32.pop
+ assert_equal -1_000_001, m.repeated_int64.pop
+ assert_equal -1_000_000, m.repeated_int64.pop
+ assert_equal 11, m.repeated_uint32.pop
+ assert_equal 10, m.repeated_uint32.pop
+ assert_equal 1_000_001, m.repeated_uint64.pop
+ assert_equal 1_000_000, m.repeated_uint64.pop
+ assert_equal false, m.repeated_bool.pop
+ assert_equal true, m.repeated_bool.pop
+ assert_equal -1.02, m.repeated_float.pop.round(2)
+ assert_equal -1.01, m.repeated_float.pop.round(2)
+ assert_equal -1.0000000000002, m.repeated_double.pop
+ assert_equal -1.0000000000001, m.repeated_double.pop
+ assert_equal 'bar', m.repeated_string.pop
+ assert_equal 'foo', m.repeated_string.pop
+ assert_equal "foo".encode!('ASCII-8BIT'), m.repeated_bytes.pop
+ assert_equal "bar".encode!('ASCII-8BIT'), m.repeated_bytes.pop
+ assert_equal TestMessage2.new(:foo => 2), m.repeated_msg.pop
+ assert_equal TestMessage2.new(:foo => 1), m.repeated_msg.pop
+ assert_equal :B, m.repeated_enum.pop
+ assert_equal :A, m.repeated_enum.pop
+ repeated_field_names(TestMessage).each do |field_name|
+ assert_nil m.send(field_name).pop
+ end
+
+ fill_test_msg(m)
+ assert_equal ['bar', 'foo'], m.repeated_string.pop(2)
+ assert_nil m.repeated_string.pop
+ end
+
+
+ def test_each
+ m = TestMessage.new
+ 5.times{|i| m.repeated_string << 'string' }
+ count = 0
+ m.repeated_string.each do |val|
+ assert_equal 'string', val
+ count += 1
+ end
+ assert_equal 5, count
+ result = m.repeated_string.each{|val| val + '_junk'}
+ assert_equal ['string'] * 5, result
+ end
+
+
+ def test_empty?
+ m = TestMessage.new
+ assert_equal true, m.repeated_string.empty?
+ m.repeated_string << 'foo'
+ assert_equal false, m.repeated_string.empty?
+ m.repeated_string << 'bar'
+ assert_equal false, m.repeated_string.empty?
+ end
+
+ def test_array_accessor
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[1]
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[-2]
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[20]
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[1, 2]
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[0..2]
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[-1, 1]
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[10, 12]
+ end
+ end
+
+ def test_array_settor
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[1] = 'junk'
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[-2] = 'snappy'
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr[3] = ''
+ end
+ # slight deviation; we are strongly typed, and nil is not allowed
+ # for string types;
+ m.repeated_string[5] = 'spacious'
+ assert_equal ["foo", "snappy", "baz", "", "", "spacious"], m.repeated_string
+
+ #make sure it sests the default types for other fields besides strings
+ %w(repeated_int32 repeated_int64 repeated_uint32 repeated_uint64).each do |field_name|
+ m.send(field_name)[3] = 10
+ assert_equal [0,0,0,10], m.send(field_name)
+ end
+ m.repeated_float[3] = 10.1
+ #wonky mri float handling
+ assert_equal [0,0,0], m.repeated_float.to_a[0..2]
+ assert_equal 10.1, m.repeated_float[3].round(1)
+ m.repeated_double[3] = 10.1
+ assert_equal [0,0,0,10.1], m.repeated_double
+ m.repeated_bool[3] = true
+ assert_equal [false, false, false, true], m.repeated_bool
+ m.repeated_bytes[3] = "bar".encode!('ASCII-8BIT')
+ assert_equal ['', '', '', "bar".encode!('ASCII-8BIT')], m.repeated_bytes
+ m.repeated_msg[3] = TestMessage2.new(:foo => 1)
+ assert_equal [nil, nil, nil, TestMessage2.new(:foo => 1)], m.repeated_msg
+ m.repeated_enum[3] = :A
+ assert_equal [:Default, :Default, :Default, :A], m.repeated_enum
+
+ # check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ # arr[20] = 'spacious'
+ # end
+ # TODO: accessor doesn't allow other ruby-like methods
+ # check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ # arr[1, 2] = 'fizz'
+ # end
+ # check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ # arr[0..2] = 'buzz'
+ # end
+ end
+
+ def test_push
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.push('fizz')
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr << 'fizz'
+ end
+ #TODO: push should support multiple
+ # check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ # arr.push('fizz', 'buzz')
+ # end
+ end
+
+ def test_clear
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.clear
+ end
+ end
+
+ def test_concat
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+ m.repeated_string.concat(['fizz', 'buzz'])
+ assert_equal %w(foo bar baz fizz buzz), m.repeated_string
+ #TODO: concat should return the orig array
+ # check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ # arr.concat(['fizz', 'buzz'])
+ # end
+ end
+
+ def test_equal
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+ assert_equal reference_arr, m.repeated_string
+ reference_arr << 'fizz'
+ assert_not_equal reference_arr, m.repeated_string
+ m.repeated_string << 'fizz'
+ assert_equal reference_arr, m.repeated_string
+ end
+
+ def test_hash
+ # just a sanity check
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+ assert m.repeated_string.hash.is_a?(Integer)
+ hash = m.repeated_string.hash
+ assert_equal hash, m.repeated_string.hash
+ m.repeated_string << 'j'
+ assert_not_equal hash, m.repeated_string.hash
+ end
+
+ def test_plus
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr + ['fizz', 'buzz']
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr += ['fizz', 'buzz']
+ end
+ end
+
+ def test_replace
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.replace(['fizz', 'buzz'])
+ end
+ end
+
+ def test_to_a
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.to_a
+ end
+ end
+
+ def test_to_ary
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.to_ary
+ end
+ end
+
+ # emulate Array behavior
+ ##########################
+
+ def test_collect!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.collect!{|x| x + "!" }
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.collect!.with_index{|x, i| x[0...i] }
+ end
+ end
+
+ def test_compact!
+ m = TestMessage.new
+ m.repeated_msg << TestMessage2.new(:foo => 1)
+ m.repeated_msg << nil
+ m.repeated_msg << TestMessage2.new(:foo => 2)
+ reference_arr = m.repeated_string.to_a
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.compact!
+ end
+ end
+
+ def test_delete
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.delete('bar')
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.delete('nope')
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.delete('nope'){'within'}
+ end
+ end
+
+ def test_delete_at
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.delete_at(2)
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.delete_at(10)
+ end
+ end
+
+ def test_fill
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.fill("x")
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.fill("z", 2, 2)
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.fill("y", 0..1)
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.fill { |i| (i*i).to_s }
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.fill(-2) { |i| (i*i*i).to_s }
+ end
+ end
+
+ def test_flatten!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.flatten!
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.flatten!(1)
+ end
+ end
+
+ def test_insert
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.insert(2, 'fizz')
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.insert(3, 'fizz', 'buzz', 'bazz')
+ end
+ end
+
+ def test_inspect
+ m = TestMessage.new
+ assert_equal '[]', m.repeated_string.inspect
+ m.repeated_string << 'foo'
+ assert_equal m.repeated_string.to_a.inspect, m.repeated_string.inspect
+ m.repeated_string << 'bar'
+ assert_equal m.repeated_string.to_a.inspect, m.repeated_string.inspect
+ end
+
+ def test_reverse!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.reverse!
+ end
+ end
+
+ def test_rotate!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.rotate!
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.rotate!(2)
+ end
+ end
+
+ def test_select!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.select! { |v| v =~ /[aeiou]/ }
+ end
+ end
+
+ def test_shift
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ # should return an element
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.shift
+ end
+ # should return an array
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.shift(2)
+ end
+ # should return nil
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.shift
+ end
+ end
+
+ def test_shuffle!
+ m = TestMessage.new
+ m.repeated_string += %w(foo bar baz)
+ orig_repeated_string = m.repeated_string.clone
+ result = m.repeated_string.shuffle!
+ assert_equal m.repeated_string, result
+ # NOTE: sometimes it doesn't change the order...
+ # assert_not_equal m.repeated_string.to_a, orig_repeated_string.to_a
+ end
+
+ def test_slice!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz bar fizz buzz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.slice!(2)
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.slice!(1,2)
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.slice!(0..1)
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.slice!(10)
+ end
+ end
+
+ def test_sort!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.sort!
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.sort! { |x,y| y <=> x }
+ end
+ end
+
+ def test_sort_by!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.sort_by!
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.sort_by!(&:hash)
+ end
+ end
+
+ def test_uniq!
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.uniq!
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.uniq!{|s| s[0] }
+ end
+ end
+
+ def test_unshift
+ m = TestMessage.new
+ reference_arr = %w(foo bar baz)
+ m.repeated_string += reference_arr.clone
+
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.unshift('1')
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.unshift('a', 'b')
+ end
+ check_self_modifying_method(m.repeated_string, reference_arr) do |arr|
+ arr.unshift('')
+ end
+ end
+
+
+ ##### HELPER METHODS
+
+ def check_self_modifying_method(repeated_field, ref_array)
+ expected_result = yield(ref_array)
+ actual_result = yield(repeated_field)
+ if expected_result.is_a?(Enumerator)
+ assert_equal expected_result.to_a, actual_result.to_a
+ else
+ assert_equal expected_result, actual_result
+ end
+ assert_equal ref_array, repeated_field
+ end
+
+
+ def repeated_field_names(klass)
+ klass.descriptor.find_all{|f| f.label == :repeated}.map(&:name)
+ end
+
+
+ def fill_test_msg(test_msg)
+ test_msg.repeated_int32 += [-10, -11]
+ test_msg.repeated_int64 += [-1_000_000, -1_000_001]
+ test_msg.repeated_uint32 += [10, 11]
+ test_msg.repeated_uint64 += [1_000_000, 1_000_001]
+ test_msg.repeated_bool += [true, false]
+ test_msg.repeated_float += [-1.01, -1.02]
+ test_msg.repeated_double += [-1.0000000000001, -1.0000000000002]
+ test_msg.repeated_string += %w(foo bar)
+ test_msg.repeated_bytes += ["bar".encode!('ASCII-8BIT'), "foo".encode!('ASCII-8BIT')]
+ test_msg.repeated_msg << TestMessage2.new(:foo => 1)
+ test_msg.repeated_msg << TestMessage2.new(:foo => 2)
+ test_msg.repeated_enum << :A
+ test_msg.repeated_enum << :B
+ end
+
+
+ pool = Google::Protobuf::DescriptorPool.new
+ pool.build do
+
+ add_message "TestMessage" do
+ optional :optional_int32, :int32, 1
+ optional :optional_int64, :int64, 2
+ optional :optional_uint32, :uint32, 3
+ optional :optional_uint64, :uint64, 4
+ optional :optional_bool, :bool, 5
+ optional :optional_float, :float, 6
+ optional :optional_double, :double, 7
+ optional :optional_string, :string, 8
+ optional :optional_bytes, :bytes, 9
+ optional :optional_msg, :message, 10, "TestMessage2"
+ optional :optional_enum, :enum, 11, "TestEnum"
+
+ repeated :repeated_int32, :int32, 12
+ repeated :repeated_int64, :int64, 13
+ repeated :repeated_uint32, :uint32, 14
+ repeated :repeated_uint64, :uint64, 15
+ repeated :repeated_bool, :bool, 16
+ repeated :repeated_float, :float, 17
+ repeated :repeated_double, :double, 18
+ repeated :repeated_string, :string, 19
+ repeated :repeated_bytes, :bytes, 20
+ repeated :repeated_msg, :message, 21, "TestMessage2"
+ repeated :repeated_enum, :enum, 22, "TestEnum"
+ end
+ add_message "TestMessage2" do
+ optional :foo, :int32, 1
+ end
+
+ add_enum "TestEnum" do
+ value :Default, 0
+ value :A, 1
+ value :B, 2
+ value :C, 3
+ end
+ end
+
+ TestMessage = pool.lookup("TestMessage").msgclass
+ TestMessage2 = pool.lookup("TestMessage2").msgclass
+ TestEnum = pool.lookup("TestEnum").enummodule
+
+
+end
diff --git a/third_party/protobuf/ruby/tests/stress.rb b/third_party/protobuf/ruby/tests/stress.rb
new file mode 100644
index 0000000000..082d5e22df
--- /dev/null
+++ b/third_party/protobuf/ruby/tests/stress.rb
@@ -0,0 +1,38 @@
+#!/usr/bin/ruby
+
+require 'google/protobuf'
+require 'test/unit'
+
+module StressTest
+ pool = Google::Protobuf::DescriptorPool.new
+ pool.build do
+ add_message "TestMessage" do
+ optional :a, :int32, 1
+ repeated :b, :message, 2, "M"
+ end
+ add_message "M" do
+ optional :foo, :string, 1
+ end
+ end
+
+ TestMessage = pool.lookup("TestMessage").msgclass
+ M = pool.lookup("M").msgclass
+
+ class StressTest < Test::Unit::TestCase
+ def get_msg
+ TestMessage.new(:a => 1000,
+ :b => [M.new(:foo => "hello"),
+ M.new(:foo => "world")])
+ end
+ def test_stress
+ m = get_msg
+ data = TestMessage.encode(m)
+ 100_000.times do
+ mnew = TestMessage.decode(data)
+ mnew = mnew.dup
+ assert_equal mnew.inspect, m.inspect
+ assert TestMessage.encode(mnew) == data
+ end
+ end
+ end
+end
diff --git a/third_party/protobuf/ruby/tests/test_import.proto b/third_party/protobuf/ruby/tests/test_import.proto
new file mode 100644
index 0000000000..230484ee57
--- /dev/null
+++ b/third_party/protobuf/ruby/tests/test_import.proto
@@ -0,0 +1,5 @@
+syntax = "proto3";
+
+package foo_bar;
+
+message TestImportedMessage {}
diff --git a/third_party/protobuf/ruby/tests/well_known_types_test.rb b/third_party/protobuf/ruby/tests/well_known_types_test.rb
new file mode 100644
index 0000000000..9b46632b72
--- /dev/null
+++ b/third_party/protobuf/ruby/tests/well_known_types_test.rb
@@ -0,0 +1,122 @@
+#!/usr/bin/ruby
+
+require 'test/unit'
+require 'google/protobuf/well_known_types'
+
+class TestWellKnownTypes < Test::Unit::TestCase
+ def test_timestamp
+ ts = Google::Protobuf::Timestamp.new
+
+ assert_equal Time.at(0), ts.to_time
+
+ ts.seconds = 12345
+ assert_equal Time.at(12345), ts.to_time
+ assert_equal 12345, ts.to_i
+
+ ts.from_time(Time.at(123456, 654321))
+ assert_equal 123456, ts.seconds
+ assert_equal 654321000, ts.nanos
+ assert_equal Time.at(123456.654321), ts.to_time
+ end
+
+ def test_duration
+ duration = Google::Protobuf::Duration.new(seconds: 123, nanos: 456)
+ assert_equal 123.000000456, duration.to_f
+ end
+
+ def test_struct
+ struct = Google::Protobuf::Struct.new
+
+ substruct = {
+ "subkey" => 999,
+ "subkey2" => false
+ }
+
+ sublist = ["abc", 123, {"deepkey" => "deepval"}]
+
+ struct["number"] = 12345
+ struct["boolean-true"] = true
+ struct["boolean-false"] = false
+ struct["null"] = nil
+ struct["string"] = "abcdef"
+ struct["substruct"] = substruct
+ struct["sublist"] = sublist
+
+ assert_equal 12345, struct["number"]
+ assert_equal true, struct["boolean-true"]
+ assert_equal false, struct["boolean-false"]
+ assert_equal nil, struct["null"]
+ assert_equal "abcdef", struct["string"]
+ assert_equal(Google::Protobuf::Struct.from_hash(substruct),
+ struct["substruct"])
+ assert_equal(Google::Protobuf::ListValue.from_a(sublist),
+ struct["sublist"])
+
+ should_equal = {
+ "number" => 12345,
+ "boolean-true" => true,
+ "boolean-false" => false,
+ "null" => nil,
+ "string" => "abcdef",
+ "substruct" => {
+ "subkey" => 999,
+ "subkey2" => false
+ },
+ "sublist" => ["abc", 123, {"deepkey" => "deepval"}]
+ }
+
+ list = struct["sublist"]
+ list.is_a?(Google::Protobuf::ListValue)
+ assert_equal "abc", list[0]
+ assert_equal 123, list[1]
+ assert_equal({"deepkey" => "deepval"}, list[2].to_h)
+
+ # to_h returns a fully-flattened Ruby structure (Hash and Array).
+ assert_equal(should_equal, struct.to_h)
+
+ # Test that we can assign Struct and ListValue directly.
+ struct["substruct"] = Google::Protobuf::Struct.from_hash(substruct)
+ struct["sublist"] = Google::Protobuf::ListValue.from_a(sublist)
+
+ assert_equal(should_equal, struct.to_h)
+
+ struct["sublist"] << nil
+ should_equal["sublist"] << nil
+
+ assert_equal(should_equal, struct.to_h)
+ assert_equal(should_equal["sublist"].length, struct["sublist"].length)
+
+ assert_raise Google::Protobuf::UnexpectedStructType do
+ struct[123] = 5
+ end
+
+ assert_raise Google::Protobuf::UnexpectedStructType do
+ struct[5] = Time.new
+ end
+
+ assert_raise Google::Protobuf::UnexpectedStructType do
+ struct[5] = [Time.new]
+ end
+
+ assert_raise Google::Protobuf::UnexpectedStructType do
+ struct[5] = {123 => 456}
+ end
+
+ assert_raise Google::Protobuf::UnexpectedStructType do
+ struct = Google::Protobuf::Struct.new
+ struct.fields["foo"] = Google::Protobuf::Value.new
+ # Tries to return a Ruby value for a Value class whose type
+ # hasn't been filled in.
+ struct["foo"]
+ end
+ end
+
+ def test_any
+ any = Google::Protobuf::Any.new
+ ts = Google::Protobuf::Timestamp.new(seconds: 12345, nanos: 6789)
+ any.pack(ts)
+
+ assert any.is(Google::Protobuf::Timestamp)
+ assert_equal ts, any.unpack(Google::Protobuf::Timestamp)
+ end
+end
diff --git a/third_party/protobuf/ruby/travis-test.sh b/third_party/protobuf/ruby/travis-test.sh
new file mode 100755
index 0000000000..52ea81b616
--- /dev/null
+++ b/third_party/protobuf/ruby/travis-test.sh
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+
+# Exit on any error.
+set -e
+
+test_version() {
+ version=$1
+ if [ "$version" == "jruby-1.7" ] ; then
+ # No conformance tests yet -- JRuby is too broken to run them.
+ bash --login -c \
+ "rvm install $version && rvm use $version && rvm get head && \
+ which ruby && \
+ git clean -f && \
+ gem install bundler && bundle && \
+ rake test"
+ else
+ bash --login -c \
+ "rvm install $version && rvm use $version && \
+ which ruby && \
+ git clean -f && \
+ gem install bundler && bundle && \
+ rake test &&
+ cd ../conformance && make test_ruby &&
+ cd ../ruby/compatibility_tests/v3.0.0 && ./test.sh"
+ fi
+}
+
+test_version $1
diff --git a/third_party/protobuf/six.BUILD b/third_party/protobuf/six.BUILD
new file mode 100644
index 0000000000..fb0b3604cd
--- /dev/null
+++ b/third_party/protobuf/six.BUILD
@@ -0,0 +1,13 @@
+genrule(
+ name = "copy_six",
+ srcs = ["six-1.10.0/six.py"],
+ outs = ["six.py"],
+ cmd = "cp $< $(@)",
+)
+
+py_library(
+ name = "six",
+ srcs = ["six.py"],
+ srcs_version = "PY2AND3",
+ visibility = ["//visibility:public"],
+)
diff --git a/third_party/protobuf/src/Makefile.am b/third_party/protobuf/src/Makefile.am
new file mode 100644
index 0000000000..bcd81576b2
--- /dev/null
+++ b/third_party/protobuf/src/Makefile.am
@@ -0,0 +1,913 @@
+## Process this file with automake to produce Makefile.in
+
+if HAVE_ZLIB
+GZCHECKPROGRAMS = zcgzip zcgunzip
+GZHEADERS = google/protobuf/io/gzip_stream.h
+GZTESTS = google/protobuf/io/gzip_stream_unittest.sh
+ZLIB_DEF = -DHAVE_ZLIB=1
+else
+GZCHECKPROGRAMS =
+GZHEADERS =
+GZTESTS =
+ZLIB_DEF =
+endif
+
+if HAVE_PTHREAD
+PTHREAD_DEF = -DHAVE_PTHREAD=1
+else
+PTHREAD_DEF =
+endif
+
+if GCC
+# Turn on all warnings except for sign comparison (we ignore sign comparison
+# in Google so our code base have tons of such warnings).
+NO_OPT_CXXFLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_DEF) $(ZLIB_DEF) -Wall -Wno-sign-compare
+else
+NO_OPT_CXXFLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_DEF) $(ZLIB_DEF)
+endif
+
+AM_CXXFLAGS = $(NO_OPT_CXXFLAGS) $(PROTOBUF_OPT_FLAG)
+
+AM_LDFLAGS = $(PTHREAD_CFLAGS)
+
+# If I say "dist_include_DATA", automake complains that $(includedir) is not
+# a "legitimate" directory for DATA. Screw you, automake.
+protodir = $(includedir)
+
+# If you are adding new files here, also remember to change the build files for
+# all other languages, //protoc-artifacts/build-zip.sh and run
+# //update_file_list.sh for bazel.
+nobase_dist_proto_DATA = google/protobuf/descriptor.proto \
+ google/protobuf/any.proto \
+ google/protobuf/api.proto \
+ google/protobuf/duration.proto \
+ google/protobuf/empty.proto \
+ google/protobuf/field_mask.proto \
+ google/protobuf/source_context.proto \
+ google/protobuf/struct.proto \
+ google/protobuf/timestamp.proto \
+ google/protobuf/type.proto \
+ google/protobuf/wrappers.proto \
+ google/protobuf/compiler/plugin.proto
+
+# Not sure why these don't get cleaned automatically.
+clean-local:
+ rm -f *.loT
+
+CLEANFILES = $(protoc_outputs) unittest_proto_middleman \
+ testzip.jar testzip.list testzip.proto testzip.zip \
+ no_warning_test.cc \
+ google/protobuf/compiler/js/well_known_types_embed.cc \
+ js_embed$(EXEEXT)
+
+MAINTAINERCLEANFILES = \
+ Makefile.in
+
+nobase_include_HEADERS = \
+ google/protobuf/stubs/atomic_sequence_num.h \
+ google/protobuf/stubs/atomicops.h \
+ google/protobuf/stubs/atomicops_internals_power.h \
+ google/protobuf/stubs/atomicops_internals_ppc_gcc.h \
+ google/protobuf/stubs/atomicops_internals_arm64_gcc.h \
+ google/protobuf/stubs/atomicops_internals_arm_gcc.h \
+ google/protobuf/stubs/atomicops_internals_arm_qnx.h \
+ google/protobuf/stubs/atomicops_internals_atomicword_compat.h \
+ google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h \
+ google/protobuf/stubs/atomicops_internals_generic_gcc.h \
+ google/protobuf/stubs/atomicops_internals_mips_gcc.h \
+ google/protobuf/stubs/atomicops_internals_solaris.h \
+ google/protobuf/stubs/atomicops_internals_tsan.h \
+ google/protobuf/stubs/atomicops_internals_x86_gcc.h \
+ google/protobuf/stubs/atomicops_internals_x86_msvc.h \
+ google/protobuf/stubs/callback.h \
+ google/protobuf/stubs/bytestream.h \
+ google/protobuf/stubs/casts.h \
+ google/protobuf/stubs/common.h \
+ google/protobuf/stubs/fastmem.h \
+ google/protobuf/stubs/hash.h \
+ google/protobuf/stubs/logging.h \
+ google/protobuf/stubs/macros.h \
+ google/protobuf/stubs/mutex.h \
+ google/protobuf/stubs/once.h \
+ google/protobuf/stubs/platform_macros.h \
+ google/protobuf/stubs/port.h \
+ google/protobuf/stubs/scoped_ptr.h \
+ google/protobuf/stubs/shared_ptr.h \
+ google/protobuf/stubs/singleton.h \
+ google/protobuf/stubs/status.h \
+ google/protobuf/stubs/stl_util.h \
+ google/protobuf/stubs/stringpiece.h \
+ google/protobuf/stubs/template_util.h \
+ google/protobuf/stubs/type_traits.h \
+ google/protobuf/any.pb.h \
+ google/protobuf/api.pb.h \
+ google/protobuf/any.h \
+ google/protobuf/arena.h \
+ google/protobuf/arenastring.h \
+ google/protobuf/descriptor_database.h \
+ google/protobuf/descriptor.h \
+ google/protobuf/descriptor.pb.h \
+ google/protobuf/duration.pb.h \
+ google/protobuf/dynamic_message.h \
+ google/protobuf/empty.pb.h \
+ google/protobuf/extension_set.h \
+ google/protobuf/field_mask.pb.h \
+ google/protobuf/generated_enum_reflection.h \
+ google/protobuf/generated_enum_util.h \
+ google/protobuf/generated_message_reflection.h \
+ google/protobuf/generated_message_util.h \
+ google/protobuf/has_bits.h \
+ google/protobuf/map_entry.h \
+ google/protobuf/map_entry_lite.h \
+ google/protobuf/map_field.h \
+ google/protobuf/map_field_inl.h \
+ google/protobuf/map_field_lite.h \
+ google/protobuf/map.h \
+ google/protobuf/map_type_handler.h \
+ google/protobuf/message.h \
+ google/protobuf/message_lite.h \
+ google/protobuf/metadata.h \
+ google/protobuf/reflection.h \
+ google/protobuf/reflection_ops.h \
+ google/protobuf/repeated_field.h \
+ google/protobuf/service.h \
+ google/protobuf/source_context.pb.h \
+ google/protobuf/struct.pb.h \
+ google/protobuf/text_format.h \
+ google/protobuf/timestamp.pb.h \
+ google/protobuf/type.pb.h \
+ google/protobuf/unknown_field_set.h \
+ google/protobuf/wire_format.h \
+ google/protobuf/wire_format_lite.h \
+ google/protobuf/wire_format_lite_inl.h \
+ google/protobuf/wrappers.pb.h \
+ google/protobuf/io/coded_stream.h \
+ $(GZHEADERS) \
+ google/protobuf/io/printer.h \
+ google/protobuf/io/strtod.h \
+ google/protobuf/io/tokenizer.h \
+ google/protobuf/io/zero_copy_stream.h \
+ google/protobuf/io/zero_copy_stream_impl.h \
+ google/protobuf/io/zero_copy_stream_impl_lite.h \
+ google/protobuf/compiler/code_generator.h \
+ google/protobuf/compiler/command_line_interface.h \
+ google/protobuf/compiler/importer.h \
+ google/protobuf/compiler/parser.h \
+ google/protobuf/compiler/plugin.h \
+ google/protobuf/compiler/plugin.pb.h \
+ google/protobuf/compiler/cpp/cpp_generator.h \
+ google/protobuf/compiler/csharp/csharp_generator.h \
+ google/protobuf/compiler/csharp/csharp_names.h \
+ google/protobuf/compiler/java/java_generator.h \
+ google/protobuf/compiler/java/java_names.h \
+ google/protobuf/compiler/javanano/javanano_generator.h \
+ google/protobuf/compiler/js/js_generator.h \
+ google/protobuf/compiler/js/well_known_types_embed.h \
+ google/protobuf/compiler/objectivec/objectivec_generator.h \
+ google/protobuf/compiler/objectivec/objectivec_helpers.h \
+ google/protobuf/compiler/php/php_generator.h \
+ google/protobuf/compiler/python/python_generator.h \
+ google/protobuf/compiler/ruby/ruby_generator.h \
+ google/protobuf/util/type_resolver.h \
+ google/protobuf/util/delimited_message_util.h \
+ google/protobuf/util/field_comparator.h \
+ google/protobuf/util/field_mask_util.h \
+ google/protobuf/util/json_util.h \
+ google/protobuf/util/time_util.h \
+ google/protobuf/util/type_resolver_util.h \
+ google/protobuf/util/message_differencer.h
+
+lib_LTLIBRARIES = libprotobuf-lite.la libprotobuf.la libprotoc.la
+
+libprotobuf_lite_la_LIBADD = $(PTHREAD_LIBS)
+libprotobuf_lite_la_LDFLAGS = -version-info 12:0:0 -export-dynamic -no-undefined
+if HAVE_LD_VERSION_SCRIPT
+libprotobuf_lite_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libprotobuf-lite.map
+EXTRA_libprotobuf_lite_la_DEPENDENCIES = libprotobuf-lite.map
+endif
+libprotobuf_lite_la_SOURCES = \
+ google/protobuf/stubs/atomicops_internals_x86_gcc.cc \
+ google/protobuf/stubs/atomicops_internals_x86_msvc.cc \
+ google/protobuf/stubs/bytestream.cc \
+ google/protobuf/stubs/bytestream.h \
+ google/protobuf/stubs/common.cc \
+ google/protobuf/stubs/hash.h \
+ google/protobuf/stubs/int128.cc \
+ google/protobuf/stubs/int128.h \
+ google/protobuf/stubs/map_util.h \
+ google/protobuf/stubs/mathutil.h \
+ google/protobuf/stubs/once.cc \
+ google/protobuf/stubs/shared_ptr.h \
+ google/protobuf/stubs/status.cc \
+ google/protobuf/stubs/status.h \
+ google/protobuf/stubs/status_macros.h \
+ google/protobuf/stubs/statusor.cc \
+ google/protobuf/stubs/statusor.h \
+ google/protobuf/stubs/stringpiece.cc \
+ google/protobuf/stubs/stringpiece.h \
+ google/protobuf/stubs/stringprintf.cc \
+ google/protobuf/stubs/stringprintf.h \
+ google/protobuf/stubs/structurally_valid.cc \
+ google/protobuf/stubs/strutil.cc \
+ google/protobuf/stubs/strutil.h \
+ google/protobuf/stubs/time.cc \
+ google/protobuf/stubs/time.h \
+ google/protobuf/arena.cc \
+ google/protobuf/arenastring.cc \
+ google/protobuf/extension_set.cc \
+ google/protobuf/generated_message_util.cc \
+ google/protobuf/message_lite.cc \
+ google/protobuf/repeated_field.cc \
+ google/protobuf/wire_format_lite.cc \
+ google/protobuf/io/coded_stream.cc \
+ google/protobuf/io/coded_stream_inl.h \
+ google/protobuf/io/zero_copy_stream.cc \
+ google/protobuf/io/zero_copy_stream_impl_lite.cc
+
+libprotobuf_la_LIBADD = $(PTHREAD_LIBS)
+libprotobuf_la_LDFLAGS = -version-info 12:0:0 -export-dynamic -no-undefined
+if HAVE_LD_VERSION_SCRIPT
+libprotobuf_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libprotobuf.map
+EXTRA_libprotobuf_la_DEPENDENCIES = libprotobuf.map
+endif
+libprotobuf_la_SOURCES = \
+ $(libprotobuf_lite_la_SOURCES) \
+ google/protobuf/any.pb.cc \
+ google/protobuf/api.pb.cc \
+ google/protobuf/stubs/mathlimits.cc \
+ google/protobuf/stubs/mathlimits.h \
+ google/protobuf/any.cc \
+ google/protobuf/descriptor.cc \
+ google/protobuf/descriptor_database.cc \
+ google/protobuf/descriptor.pb.cc \
+ google/protobuf/duration.pb.cc \
+ google/protobuf/dynamic_message.cc \
+ google/protobuf/empty.pb.cc \
+ google/protobuf/extension_set_heavy.cc \
+ google/protobuf/field_mask.pb.cc \
+ google/protobuf/generated_message_reflection.cc \
+ google/protobuf/map_field.cc \
+ google/protobuf/message.cc \
+ google/protobuf/reflection_internal.h \
+ google/protobuf/reflection_ops.cc \
+ google/protobuf/service.cc \
+ google/protobuf/source_context.pb.cc \
+ google/protobuf/struct.pb.cc \
+ google/protobuf/stubs/substitute.cc \
+ google/protobuf/stubs/substitute.h \
+ google/protobuf/text_format.cc \
+ google/protobuf/timestamp.pb.cc \
+ google/protobuf/type.pb.cc \
+ google/protobuf/unknown_field_set.cc \
+ google/protobuf/wire_format.cc \
+ google/protobuf/wrappers.pb.cc \
+ google/protobuf/io/gzip_stream.cc \
+ google/protobuf/io/printer.cc \
+ google/protobuf/io/strtod.cc \
+ google/protobuf/io/tokenizer.cc \
+ google/protobuf/io/zero_copy_stream_impl.cc \
+ google/protobuf/compiler/importer.cc \
+ google/protobuf/compiler/parser.cc \
+ google/protobuf/util/delimited_message_util.cc \
+ google/protobuf/util/field_comparator.cc \
+ google/protobuf/util/field_mask_util.cc \
+ google/protobuf/util/internal/constants.h \
+ google/protobuf/util/internal/datapiece.cc \
+ google/protobuf/util/internal/datapiece.h \
+ google/protobuf/util/internal/default_value_objectwriter.cc \
+ google/protobuf/util/internal/default_value_objectwriter.h \
+ google/protobuf/util/internal/error_listener.cc \
+ google/protobuf/util/internal/error_listener.h \
+ google/protobuf/util/internal/expecting_objectwriter.h \
+ google/protobuf/util/internal/field_mask_utility.cc \
+ google/protobuf/util/internal/field_mask_utility.h \
+ google/protobuf/util/internal/json_escaping.cc \
+ google/protobuf/util/internal/json_escaping.h \
+ google/protobuf/util/internal/json_objectwriter.cc \
+ google/protobuf/util/internal/json_objectwriter.h \
+ google/protobuf/util/internal/json_stream_parser.cc \
+ google/protobuf/util/internal/json_stream_parser.h \
+ google/protobuf/util/internal/location_tracker.h \
+ google/protobuf/util/internal/mock_error_listener.h \
+ google/protobuf/util/internal/object_location_tracker.h \
+ google/protobuf/util/internal/object_source.h \
+ google/protobuf/util/internal/object_writer.cc \
+ google/protobuf/util/internal/object_writer.h \
+ google/protobuf/util/internal/protostream_objectsource.cc \
+ google/protobuf/util/internal/protostream_objectsource.h \
+ google/protobuf/util/internal/protostream_objectwriter.cc \
+ google/protobuf/util/internal/protostream_objectwriter.h \
+ google/protobuf/util/internal/proto_writer.cc \
+ google/protobuf/util/internal/proto_writer.h \
+ google/protobuf/util/internal/structured_objectwriter.h \
+ google/protobuf/util/internal/type_info.cc \
+ google/protobuf/util/internal/type_info.h \
+ google/protobuf/util/internal/type_info_test_helper.cc \
+ google/protobuf/util/internal/type_info_test_helper.h \
+ google/protobuf/util/internal/utility.cc \
+ google/protobuf/util/internal/utility.h \
+ google/protobuf/util/json_util.cc \
+ google/protobuf/util/message_differencer.cc \
+ google/protobuf/util/time_util.cc \
+ google/protobuf/util/type_resolver_util.cc
+
+nodist_libprotobuf_la_SOURCES = $(nodist_libprotobuf_lite_la_SOURCES)
+
+libprotoc_la_LIBADD = $(PTHREAD_LIBS) libprotobuf.la
+libprotoc_la_LDFLAGS = -version-info 12:0:0 -export-dynamic -no-undefined
+if HAVE_LD_VERSION_SCRIPT
+libprotoc_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libprotoc.map
+EXTRA_libprotoc_la_DEPENDENCIES = libprotoc.map
+endif
+libprotoc_la_SOURCES = \
+ google/protobuf/compiler/code_generator.cc \
+ google/protobuf/compiler/command_line_interface.cc \
+ google/protobuf/compiler/plugin.cc \
+ google/protobuf/compiler/plugin.pb.cc \
+ google/protobuf/compiler/subprocess.cc \
+ google/protobuf/compiler/subprocess.h \
+ google/protobuf/compiler/zip_writer.cc \
+ google/protobuf/compiler/zip_writer.h \
+ google/protobuf/compiler/cpp/cpp_enum.cc \
+ google/protobuf/compiler/cpp/cpp_enum.h \
+ google/protobuf/compiler/cpp/cpp_enum_field.cc \
+ google/protobuf/compiler/cpp/cpp_enum_field.h \
+ google/protobuf/compiler/cpp/cpp_extension.cc \
+ google/protobuf/compiler/cpp/cpp_extension.h \
+ google/protobuf/compiler/cpp/cpp_field.cc \
+ google/protobuf/compiler/cpp/cpp_field.h \
+ google/protobuf/compiler/cpp/cpp_file.cc \
+ google/protobuf/compiler/cpp/cpp_file.h \
+ google/protobuf/compiler/cpp/cpp_generator.cc \
+ google/protobuf/compiler/cpp/cpp_helpers.cc \
+ google/protobuf/compiler/cpp/cpp_helpers.h \
+ google/protobuf/compiler/cpp/cpp_map_field.cc \
+ google/protobuf/compiler/cpp/cpp_map_field.h \
+ google/protobuf/compiler/cpp/cpp_message.cc \
+ google/protobuf/compiler/cpp/cpp_message.h \
+ google/protobuf/compiler/cpp/cpp_message_field.cc \
+ google/protobuf/compiler/cpp/cpp_message_field.h \
+ google/protobuf/compiler/cpp/cpp_options.h \
+ google/protobuf/compiler/cpp/cpp_primitive_field.cc \
+ google/protobuf/compiler/cpp/cpp_primitive_field.h \
+ google/protobuf/compiler/cpp/cpp_service.cc \
+ google/protobuf/compiler/cpp/cpp_service.h \
+ google/protobuf/compiler/cpp/cpp_string_field.cc \
+ google/protobuf/compiler/cpp/cpp_string_field.h \
+ google/protobuf/compiler/java/java_context.cc \
+ google/protobuf/compiler/java/java_context.h \
+ google/protobuf/compiler/java/java_enum.cc \
+ google/protobuf/compiler/java/java_enum_lite.cc \
+ google/protobuf/compiler/java/java_enum_field.cc \
+ google/protobuf/compiler/java/java_enum_field.h \
+ google/protobuf/compiler/java/java_enum_field_lite.cc \
+ google/protobuf/compiler/java/java_enum_field_lite.h \
+ google/protobuf/compiler/java/java_enum.h \
+ google/protobuf/compiler/java/java_enum_lite.h \
+ google/protobuf/compiler/java/java_extension.cc \
+ google/protobuf/compiler/java/java_extension.h \
+ google/protobuf/compiler/java/java_extension_lite.cc \
+ google/protobuf/compiler/java/java_extension_lite.h \
+ google/protobuf/compiler/java/java_field.cc \
+ google/protobuf/compiler/java/java_field.h \
+ google/protobuf/compiler/java/java_file.cc \
+ google/protobuf/compiler/java/java_file.h \
+ google/protobuf/compiler/java/java_generator.cc \
+ google/protobuf/compiler/java/java_generator_factory.cc \
+ google/protobuf/compiler/java/java_generator_factory.h \
+ google/protobuf/compiler/java/java_helpers.cc \
+ google/protobuf/compiler/java/java_helpers.h \
+ google/protobuf/compiler/java/java_lazy_message_field.cc \
+ google/protobuf/compiler/java/java_lazy_message_field.h \
+ google/protobuf/compiler/java/java_lazy_message_field_lite.cc\
+ google/protobuf/compiler/java/java_lazy_message_field_lite.h \
+ google/protobuf/compiler/java/java_map_field.cc \
+ google/protobuf/compiler/java/java_map_field.h \
+ google/protobuf/compiler/java/java_map_field_lite.cc \
+ google/protobuf/compiler/java/java_map_field_lite.h \
+ google/protobuf/compiler/java/java_message.cc \
+ google/protobuf/compiler/java/java_message_lite.cc \
+ google/protobuf/compiler/java/java_message_builder.cc \
+ google/protobuf/compiler/java/java_message_builder_lite.cc \
+ google/protobuf/compiler/java/java_message_field.cc \
+ google/protobuf/compiler/java/java_message_field.h \
+ google/protobuf/compiler/java/java_message_field_lite.cc \
+ google/protobuf/compiler/java/java_message_field_lite.h \
+ google/protobuf/compiler/java/java_message.h \
+ google/protobuf/compiler/java/java_message_lite.h \
+ google/protobuf/compiler/java/java_message_builder.h \
+ google/protobuf/compiler/java/java_message_builder_lite.h \
+ google/protobuf/compiler/java/java_name_resolver.cc \
+ google/protobuf/compiler/java/java_name_resolver.h \
+ google/protobuf/compiler/java/java_options.h \
+ google/protobuf/compiler/java/java_primitive_field.cc \
+ google/protobuf/compiler/java/java_primitive_field.h \
+ google/protobuf/compiler/java/java_primitive_field_lite.cc \
+ google/protobuf/compiler/java/java_primitive_field_lite.h \
+ google/protobuf/compiler/java/java_shared_code_generator.cc \
+ google/protobuf/compiler/java/java_shared_code_generator.h \
+ google/protobuf/compiler/java/java_service.cc \
+ google/protobuf/compiler/java/java_service.h \
+ google/protobuf/compiler/java/java_string_field.cc \
+ google/protobuf/compiler/java/java_string_field.h \
+ google/protobuf/compiler/java/java_string_field_lite.cc \
+ google/protobuf/compiler/java/java_string_field_lite.h \
+ google/protobuf/compiler/java/java_doc_comment.cc \
+ google/protobuf/compiler/java/java_doc_comment.h \
+ google/protobuf/compiler/js/js_generator.cc \
+ google/protobuf/compiler/js/well_known_types_embed.cc \
+ google/protobuf/compiler/javanano/javanano_enum.cc \
+ google/protobuf/compiler/javanano/javanano_enum.h \
+ google/protobuf/compiler/javanano/javanano_enum_field.cc \
+ google/protobuf/compiler/javanano/javanano_enum_field.h \
+ google/protobuf/compiler/javanano/javanano_extension.cc \
+ google/protobuf/compiler/javanano/javanano_extension.h \
+ google/protobuf/compiler/javanano/javanano_field.cc \
+ google/protobuf/compiler/javanano/javanano_field.h \
+ google/protobuf/compiler/javanano/javanano_file.cc \
+ google/protobuf/compiler/javanano/javanano_file.h \
+ google/protobuf/compiler/javanano/javanano_generator.cc \
+ google/protobuf/compiler/javanano/javanano_generator.h \
+ google/protobuf/compiler/javanano/javanano_helpers.cc \
+ google/protobuf/compiler/javanano/javanano_helpers.h \
+ google/protobuf/compiler/javanano/javanano_map_field.cc \
+ google/protobuf/compiler/javanano/javanano_map_field.h \
+ google/protobuf/compiler/javanano/javanano_message.cc \
+ google/protobuf/compiler/javanano/javanano_message.h \
+ google/protobuf/compiler/javanano/javanano_message_field.cc \
+ google/protobuf/compiler/javanano/javanano_message_field.h \
+ google/protobuf/compiler/javanano/javanano_params.h \
+ google/protobuf/compiler/javanano/javanano_primitive_field.cc \
+ google/protobuf/compiler/javanano/javanano_primitive_field.h \
+ google/protobuf/compiler/objectivec/objectivec_enum.cc \
+ google/protobuf/compiler/objectivec/objectivec_enum.h \
+ google/protobuf/compiler/objectivec/objectivec_enum_field.cc \
+ google/protobuf/compiler/objectivec/objectivec_enum_field.h \
+ google/protobuf/compiler/objectivec/objectivec_extension.cc \
+ google/protobuf/compiler/objectivec/objectivec_extension.h \
+ google/protobuf/compiler/objectivec/objectivec_field.cc \
+ google/protobuf/compiler/objectivec/objectivec_field.h \
+ google/protobuf/compiler/objectivec/objectivec_file.cc \
+ google/protobuf/compiler/objectivec/objectivec_file.h \
+ google/protobuf/compiler/objectivec/objectivec_generator.cc \
+ google/protobuf/compiler/objectivec/objectivec_helpers.cc \
+ google/protobuf/compiler/objectivec/objectivec_helpers.h \
+ google/protobuf/compiler/objectivec/objectivec_map_field.cc \
+ google/protobuf/compiler/objectivec/objectivec_map_field.h \
+ google/protobuf/compiler/objectivec/objectivec_message.cc \
+ google/protobuf/compiler/objectivec/objectivec_message.h \
+ google/protobuf/compiler/objectivec/objectivec_message_field.cc \
+ google/protobuf/compiler/objectivec/objectivec_message_field.h \
+ google/protobuf/compiler/objectivec/objectivec_oneof.cc \
+ google/protobuf/compiler/objectivec/objectivec_oneof.h \
+ google/protobuf/compiler/objectivec/objectivec_primitive_field.cc \
+ google/protobuf/compiler/objectivec/objectivec_primitive_field.h \
+ google/protobuf/compiler/php/php_generator.cc \
+ google/protobuf/compiler/python/python_generator.cc \
+ google/protobuf/compiler/ruby/ruby_generator.cc \
+ google/protobuf/compiler/csharp/csharp_doc_comment.cc \
+ google/protobuf/compiler/csharp/csharp_doc_comment.h \
+ google/protobuf/compiler/csharp/csharp_enum.cc \
+ google/protobuf/compiler/csharp/csharp_enum.h \
+ google/protobuf/compiler/csharp/csharp_enum_field.cc \
+ google/protobuf/compiler/csharp/csharp_enum_field.h \
+ google/protobuf/compiler/csharp/csharp_field_base.cc \
+ google/protobuf/compiler/csharp/csharp_field_base.h \
+ google/protobuf/compiler/csharp/csharp_generator.cc \
+ google/protobuf/compiler/csharp/csharp_helpers.cc \
+ google/protobuf/compiler/csharp/csharp_helpers.h \
+ google/protobuf/compiler/csharp/csharp_map_field.cc \
+ google/protobuf/compiler/csharp/csharp_map_field.h \
+ google/protobuf/compiler/csharp/csharp_message.cc \
+ google/protobuf/compiler/csharp/csharp_message.h \
+ google/protobuf/compiler/csharp/csharp_message_field.cc \
+ google/protobuf/compiler/csharp/csharp_message_field.h \
+ google/protobuf/compiler/csharp/csharp_options.h \
+ google/protobuf/compiler/csharp/csharp_primitive_field.cc \
+ google/protobuf/compiler/csharp/csharp_primitive_field.h \
+ google/protobuf/compiler/csharp/csharp_reflection_class.cc \
+ google/protobuf/compiler/csharp/csharp_reflection_class.h \
+ google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc \
+ google/protobuf/compiler/csharp/csharp_repeated_enum_field.h \
+ google/protobuf/compiler/csharp/csharp_repeated_message_field.cc \
+ google/protobuf/compiler/csharp/csharp_repeated_message_field.h \
+ google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc \
+ google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h \
+ google/protobuf/compiler/csharp/csharp_source_generator_base.cc \
+ google/protobuf/compiler/csharp/csharp_source_generator_base.h \
+ google/protobuf/compiler/csharp/csharp_wrapper_field.cc \
+ google/protobuf/compiler/csharp/csharp_wrapper_field.h
+
+bin_PROGRAMS = protoc
+protoc_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la
+protoc_SOURCES = google/protobuf/compiler/main.cc
+
+# The special JS code for the well-known types is linked into the compiler via
+# well_known_types_embed.cc, which is generated from .js source files. We have
+# to build the js_embed binary using $(CXX_FOR_BUILD) so that it is executable
+# on the build machine in a cross-compilation setup.
+js_embed$(EXEEXT): $(srcdir)/google/protobuf/compiler/js/embed.cc
+ $(CXX_FOR_BUILD) -o $@ $<
+js_well_known_types_sources = \
+ google/protobuf/compiler/js/well_known_types/any.js \
+ google/protobuf/compiler/js/well_known_types/struct.js \
+ google/protobuf/compiler/js/well_known_types/timestamp.js
+# We have to cd to $(srcdir) so that out-of-tree builds work properly.
+google/protobuf/compiler/js/well_known_types_embed.cc: js_embed$(EXEEXT) $(js_well_known_types_sources)
+ oldpwd=`pwd` && cd $(srcdir) && \
+ $$oldpwd/js_embed$(EXEEXT) $(js_well_known_types_sources) > $$oldpwd/$@
+
+# Tests ==============================================================
+
+protoc_inputs = \
+ google/protobuf/any_test.proto \
+ google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto \
+ google/protobuf/map_lite_unittest.proto \
+ google/protobuf/map_proto2_unittest.proto \
+ google/protobuf/map_unittest.proto \
+ google/protobuf/unittest_arena.proto \
+ google/protobuf/unittest_custom_options.proto \
+ google/protobuf/unittest_drop_unknown_fields.proto \
+ google/protobuf/unittest_embed_optimize_for.proto \
+ google/protobuf/unittest_empty.proto \
+ google/protobuf/unittest_enormous_descriptor.proto \
+ google/protobuf/unittest_import_lite.proto \
+ google/protobuf/unittest_import.proto \
+ google/protobuf/unittest_import_public_lite.proto \
+ google/protobuf/unittest_import_public.proto \
+ google/protobuf/unittest_lite_imports_nonlite.proto \
+ google/protobuf/unittest_lite.proto \
+ google/protobuf/unittest_mset.proto \
+ google/protobuf/unittest_mset_wire_format.proto \
+ google/protobuf/unittest_no_arena_lite.proto \
+ google/protobuf/unittest_no_arena_import.proto \
+ google/protobuf/unittest_no_arena.proto \
+ google/protobuf/unittest_no_field_presence.proto \
+ google/protobuf/unittest_no_generic_services.proto \
+ google/protobuf/unittest_optimize_for.proto \
+ google/protobuf/unittest_preserve_unknown_enum2.proto \
+ google/protobuf/unittest_preserve_unknown_enum.proto \
+ google/protobuf/unittest.proto \
+ google/protobuf/unittest_proto3_arena.proto \
+ google/protobuf/unittest_proto3_arena_lite.proto \
+ google/protobuf/unittest_proto3_lite.proto \
+ google/protobuf/unittest_well_known_types.proto \
+ google/protobuf/util/internal/testdata/anys.proto \
+ google/protobuf/util/internal/testdata/books.proto \
+ google/protobuf/util/internal/testdata/default_value.proto \
+ google/protobuf/util/internal/testdata/default_value_test.proto \
+ 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
+
+EXTRA_DIST = \
+ $(protoc_inputs) \
+ $(js_well_known_types_sources) \
+ solaris/libstdc++.la \
+ google/protobuf/io/gzip_stream.h \
+ google/protobuf/io/gzip_stream_unittest.sh \
+ google/protobuf/testdata/golden_message \
+ google/protobuf/testdata/golden_message_maps \
+ google/protobuf/testdata/golden_message_oneof_implemented \
+ google/protobuf/testdata/golden_message_proto3 \
+ google/protobuf/testdata/golden_packed_fields_message \
+ google/protobuf/testdata/bad_utf8_string \
+ google/protobuf/testdata/map_test_data.txt \
+ google/protobuf/testdata/text_format_unittest_data.txt \
+ google/protobuf/testdata/text_format_unittest_data_oneof_implemented.txt \
+ google/protobuf/testdata/text_format_unittest_data_pointy.txt \
+ google/protobuf/testdata/text_format_unittest_data_pointy_oneof.txt \
+ google/protobuf/testdata/text_format_unittest_extensions_data.txt \
+ google/protobuf/testdata/text_format_unittest_extensions_data_pointy.txt \
+ google/protobuf/package_info.h \
+ google/protobuf/io/package_info.h \
+ google/protobuf/util/package_info.h \
+ google/protobuf/compiler/js/embed.cc \
+ google/protobuf/compiler/ruby/ruby_generated_code.proto \
+ google/protobuf/compiler/ruby/ruby_generated_code_pb.rb \
+ google/protobuf/compiler/package_info.h \
+ google/protobuf/compiler/zip_output_unittest.sh \
+ libprotobuf-lite.map \
+ libprotobuf.map \
+ libprotoc.map \
+ README.md
+
+protoc_lite_outputs = \
+ google/protobuf/map_lite_unittest.pb.cc \
+ google/protobuf/map_lite_unittest.pb.h \
+ google/protobuf/unittest_lite.pb.cc \
+ google/protobuf/unittest_lite.pb.h \
+ google/protobuf/unittest_no_arena_lite.pb.cc \
+ google/protobuf/unittest_no_arena_lite.pb.h \
+ google/protobuf/unittest_import_lite.pb.cc \
+ google/protobuf/unittest_import_lite.pb.h \
+ google/protobuf/unittest_import_public_lite.pb.cc \
+ google/protobuf/unittest_import_public_lite.pb.h
+
+protoc_outputs = \
+ $(protoc_lite_outputs) \
+ google/protobuf/any_test.pb.cc \
+ google/protobuf/any_test.pb.h \
+ google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.cc \
+ google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h \
+ google/protobuf/compiler/cpp/cpp_test_large_enum_value.pb.cc \
+ google/protobuf/compiler/cpp/cpp_test_large_enum_value.pb.h \
+ google/protobuf/map_proto2_unittest.pb.cc \
+ google/protobuf/map_proto2_unittest.pb.h \
+ google/protobuf/map_unittest.pb.cc \
+ google/protobuf/map_unittest.pb.h \
+ google/protobuf/unittest_arena.pb.cc \
+ google/protobuf/unittest_arena.pb.h \
+ google/protobuf/unittest_custom_options.pb.cc \
+ google/protobuf/unittest_custom_options.pb.h \
+ google/protobuf/unittest_drop_unknown_fields.pb.cc \
+ google/protobuf/unittest_drop_unknown_fields.pb.h \
+ google/protobuf/unittest_embed_optimize_for.pb.cc \
+ google/protobuf/unittest_embed_optimize_for.pb.h \
+ google/protobuf/unittest_empty.pb.cc \
+ google/protobuf/unittest_empty.pb.h \
+ google/protobuf/unittest_enormous_descriptor.pb.cc \
+ google/protobuf/unittest_enormous_descriptor.pb.h \
+ google/protobuf/unittest_import.pb.cc \
+ google/protobuf/unittest_import.pb.h \
+ google/protobuf/unittest_import_public.pb.cc \
+ google/protobuf/unittest_import_public.pb.h \
+ google/protobuf/unittest_lite_imports_nonlite.pb.cc \
+ google/protobuf/unittest_lite_imports_nonlite.pb.h \
+ google/protobuf/unittest_mset.pb.cc \
+ google/protobuf/unittest_mset.pb.h \
+ google/protobuf/unittest_mset_wire_format.pb.cc \
+ google/protobuf/unittest_mset_wire_format.pb.h \
+ google/protobuf/unittest_no_arena_import.pb.cc \
+ google/protobuf/unittest_no_arena_import.pb.h \
+ google/protobuf/unittest_no_arena.pb.cc \
+ google/protobuf/unittest_no_arena.pb.h \
+ google/protobuf/unittest_no_field_presence.pb.cc \
+ google/protobuf/unittest_no_field_presence.pb.h \
+ google/protobuf/unittest_no_generic_services.pb.cc \
+ google/protobuf/unittest_no_generic_services.pb.h \
+ google/protobuf/unittest_optimize_for.pb.cc \
+ google/protobuf/unittest_optimize_for.pb.h \
+ google/protobuf/unittest.pb.cc \
+ google/protobuf/unittest.pb.h \
+ google/protobuf/unittest_preserve_unknown_enum2.pb.cc \
+ google/protobuf/unittest_preserve_unknown_enum2.pb.h \
+ google/protobuf/unittest_preserve_unknown_enum.pb.cc \
+ google/protobuf/unittest_preserve_unknown_enum.pb.h \
+ google/protobuf/unittest_proto3_arena.pb.cc \
+ google/protobuf/unittest_proto3_arena.pb.h \
+ google/protobuf/unittest_proto3_arena_lite.pb.cc \
+ google/protobuf/unittest_proto3_arena_lite.pb.h \
+ google/protobuf/unittest_proto3_lite.pb.cc \
+ google/protobuf/unittest_proto3_lite.pb.h \
+ google/protobuf/unittest_well_known_types.pb.cc \
+ google/protobuf/unittest_well_known_types.pb.h \
+ google/protobuf/util/internal/testdata/anys.pb.cc \
+ google/protobuf/util/internal/testdata/anys.pb.h \
+ google/protobuf/util/internal/testdata/books.pb.cc \
+ google/protobuf/util/internal/testdata/books.pb.h \
+ google/protobuf/util/internal/testdata/default_value.pb.cc \
+ google/protobuf/util/internal/testdata/default_value.pb.h \
+ google/protobuf/util/internal/testdata/default_value_test.pb.cc \
+ google/protobuf/util/internal/testdata/default_value_test.pb.h \
+ google/protobuf/util/internal/testdata/field_mask.pb.cc \
+ google/protobuf/util/internal/testdata/field_mask.pb.h \
+ google/protobuf/util/internal/testdata/maps.pb.cc \
+ 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 \
+ google/protobuf/util/message_differencer_unittest.pb.h
+
+BUILT_SOURCES = $(protoc_outputs) google/protobuf/compiler/js/well_known_types_embed.cc
+
+if USE_EXTERNAL_PROTOC
+
+unittest_proto_middleman: $(protoc_inputs)
+ $(PROTOC) -I$(srcdir) --cpp_out=. $^
+ touch unittest_proto_middleman
+
+else
+
+# We have to cd to $(srcdir) before executing protoc because $(protoc_inputs) is
+# relative to srcdir, which may not be the same as the current directory when
+# building out-of-tree.
+unittest_proto_middleman: protoc$(EXEEXT) $(protoc_inputs)
+ oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/protoc$(EXEEXT) -I. --cpp_out=$$oldpwd $(protoc_inputs) )
+ touch unittest_proto_middleman
+
+endif
+
+$(protoc_outputs): unittest_proto_middleman
+
+COMMON_TEST_SOURCES = \
+ google/protobuf/arena_test_util.cc \
+ google/protobuf/arena_test_util.h \
+ google/protobuf/map_test_util.cc \
+ google/protobuf/map_test_util.h \
+ google/protobuf/map_test_util_impl.h \
+ google/protobuf/test_util.cc \
+ google/protobuf/test_util.h \
+ google/protobuf/testing/googletest.cc \
+ google/protobuf/testing/googletest.h \
+ google/protobuf/testing/file.cc \
+ google/protobuf/testing/file.h
+
+check_PROGRAMS = protoc protobuf-test protobuf-lazy-descriptor-test \
+ protobuf-lite-test test_plugin protobuf-lite-arena-test \
+ no-warning-test $(GZCHECKPROGRAMS)
+protobuf_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \
+ ../gmock/gtest/lib/libgtest.la \
+ ../gmock/lib/libgmock.la \
+ ../gmock/lib/libgmock_main.la
+protobuf_test_CPPFLAGS = -I$(srcdir)/../gmock/gtest/include \
+ -I$(srcdir)/../gmock/include
+# Disable optimization for tests unless the user explicitly asked for it,
+# since test_util.cc takes forever to compile with optimization (with GCC).
+# See configure.ac for more info.
+protobuf_test_CXXFLAGS = $(NO_OPT_CXXFLAGS)
+protobuf_test_SOURCES = \
+ google/protobuf/stubs/bytestream_unittest.cc \
+ google/protobuf/stubs/common_unittest.cc \
+ google/protobuf/stubs/int128_unittest.cc \
+ google/protobuf/stubs/once_unittest.cc \
+ google/protobuf/stubs/statusor_test.cc \
+ google/protobuf/stubs/status_test.cc \
+ google/protobuf/stubs/stringpiece_unittest.cc \
+ google/protobuf/stubs/stringprintf_unittest.cc \
+ google/protobuf/stubs/structurally_valid_unittest.cc \
+ google/protobuf/stubs/strutil_unittest.cc \
+ google/protobuf/stubs/template_util_unittest.cc \
+ google/protobuf/stubs/time_test.cc \
+ google/protobuf/stubs/type_traits_unittest.cc \
+ google/protobuf/any_test.cc \
+ google/protobuf/arenastring_unittest.cc \
+ google/protobuf/arena_unittest.cc \
+ google/protobuf/descriptor_database_unittest.cc \
+ google/protobuf/descriptor_unittest.cc \
+ google/protobuf/drop_unknown_fields_test.cc \
+ google/protobuf/dynamic_message_unittest.cc \
+ google/protobuf/extension_set_unittest.cc \
+ google/protobuf/generated_message_reflection_unittest.cc \
+ google/protobuf/map_field_test.cc \
+ google/protobuf/map_test.cc \
+ google/protobuf/message_unittest.cc \
+ google/protobuf/no_field_presence_test.cc \
+ google/protobuf/preserve_unknown_enum_test.cc \
+ google/protobuf/proto3_arena_unittest.cc \
+ google/protobuf/proto3_arena_lite_unittest.cc \
+ google/protobuf/proto3_lite_unittest.cc \
+ google/protobuf/reflection_ops_unittest.cc \
+ google/protobuf/repeated_field_reflection_unittest.cc \
+ google/protobuf/repeated_field_unittest.cc \
+ google/protobuf/text_format_unittest.cc \
+ google/protobuf/unknown_field_set_unittest.cc \
+ google/protobuf/well_known_types_unittest.cc \
+ google/protobuf/wire_format_unittest.cc \
+ google/protobuf/io/coded_stream_unittest.cc \
+ google/protobuf/io/printer_unittest.cc \
+ google/protobuf/io/tokenizer_unittest.cc \
+ google/protobuf/io/zero_copy_stream_unittest.cc \
+ google/protobuf/compiler/command_line_interface_unittest.cc \
+ google/protobuf/compiler/importer_unittest.cc \
+ google/protobuf/compiler/mock_code_generator.cc \
+ google/protobuf/compiler/mock_code_generator.h \
+ google/protobuf/compiler/parser_unittest.cc \
+ google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc \
+ google/protobuf/compiler/cpp/cpp_unittest.h \
+ google/protobuf/compiler/cpp/cpp_unittest.cc \
+ google/protobuf/compiler/cpp/cpp_plugin_unittest.cc \
+ google/protobuf/compiler/cpp/metadata_test.cc \
+ google/protobuf/compiler/java/java_plugin_unittest.cc \
+ google/protobuf/compiler/java/java_doc_comment_unittest.cc \
+ google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc \
+ google/protobuf/compiler/python/python_plugin_unittest.cc \
+ google/protobuf/compiler/ruby/ruby_generator_unittest.cc \
+ google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc \
+ google/protobuf/compiler/csharp/csharp_generator_unittest.cc \
+ google/protobuf/util/delimited_message_util_test.cc \
+ google/protobuf/util/field_comparator_test.cc \
+ google/protobuf/util/field_mask_util_test.cc \
+ google/protobuf/util/internal/default_value_objectwriter_test.cc \
+ google/protobuf/util/internal/json_objectwriter_test.cc \
+ google/protobuf/util/internal/json_stream_parser_test.cc \
+ google/protobuf/util/internal/protostream_objectsource_test.cc \
+ google/protobuf/util/internal/protostream_objectwriter_test.cc \
+ google/protobuf/util/internal/type_info_test_helper.cc \
+ google/protobuf/util/json_util_test.cc \
+ google/protobuf/util/message_differencer_unittest.cc \
+ google/protobuf/util/time_util_test.cc \
+ google/protobuf/util/type_resolver_util_test.cc \
+ $(COMMON_TEST_SOURCES)
+
+
+nodist_protobuf_test_SOURCES = $(protoc_outputs)
+
+# Run cpp_unittest again with PROTOBUF_TEST_NO_DESCRIPTORS defined.
+protobuf_lazy_descriptor_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la \
+ libprotoc.la \
+ ../gmock/gtest/lib/libgtest.la \
+ ../gmock/lib/libgmock.la \
+ ../gmock/lib/libgmock_main.la
+protobuf_lazy_descriptor_test_CPPFLAGS = -I$(srcdir)/../gmock/include \
+ -I$(srcdir)/../gmock/gtest/include \
+ -DPROTOBUF_TEST_NO_DESCRIPTORS
+protobuf_lazy_descriptor_test_CXXFLAGS = $(NO_OPT_CXXFLAGS)
+protobuf_lazy_descriptor_test_SOURCES = \
+ google/protobuf/compiler/cpp/cpp_unittest.cc \
+ $(COMMON_TEST_SOURCES)
+nodist_protobuf_lazy_descriptor_test_SOURCES = $(protoc_outputs)
+
+COMMON_LITE_TEST_SOURCES = \
+ google/protobuf/arena_test_util.cc \
+ google/protobuf/arena_test_util.h \
+ google/protobuf/map_lite_test_util.cc \
+ google/protobuf/map_lite_test_util.h \
+ google/protobuf/test_util_lite.cc \
+ google/protobuf/test_util_lite.h
+
+# Build lite_unittest separately, since it doesn't use gtest. It can't
+# depend on gtest because our internal version of gtest depend on proto
+# full runtime and we want to make sure this test builds without full
+# runtime.
+protobuf_lite_test_LDADD = $(PTHREAD_LIBS) libprotobuf-lite.la
+protobuf_lite_test_CXXFLAGS = $(NO_OPT_CXXFLAGS)
+protobuf_lite_test_SOURCES = \
+ google/protobuf/lite_unittest.cc \
+ $(COMMON_LITE_TEST_SOURCES)
+nodist_protobuf_lite_test_SOURCES = $(protoc_lite_outputs)
+
+# lite_arena_unittest depends on gtest because teboring@ found that without
+# gtest when building the test internally our memory sanitizer doesn't detect
+# memory leaks (don't know why).
+protobuf_lite_arena_test_LDADD = $(PTHREAD_LIBS) libprotobuf-lite.la \
+ ../gmock/gtest/lib/libgtest.la \
+ ../gmock/lib/libgmock.la \
+ ../gmock/lib/libgmock_main.la
+protobuf_lite_arena_test_CPPFLAGS = -I$(srcdir)/../gmock/include \
+ -I$(srcdir)/../gmock/gtest/include
+protobuf_lite_arena_test_CXXFLAGS = $(NO_OPT_CXXFLAGS)
+protobuf_lite_arena_test_SOURCES = \
+ google/protobuf/lite_arena_unittest.cc \
+ $(COMMON_LITE_TEST_SOURCES)
+nodist_protobuf_lite_arena_test_SOURCES = $(protoc_lite_outputs)
+
+# Test plugin binary.
+test_plugin_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \
+ ../gmock/gtest/lib/libgtest.la
+test_plugin_CPPFLAGS = -I$(srcdir)/../gmock/gtest/include
+test_plugin_SOURCES = \
+ google/protobuf/compiler/mock_code_generator.cc \
+ google/protobuf/testing/file.cc \
+ google/protobuf/testing/file.h \
+ google/protobuf/compiler/test_plugin.cc
+
+if HAVE_ZLIB
+zcgzip_LDADD = $(PTHREAD_LIBS) libprotobuf.la
+zcgzip_SOURCES = google/protobuf/testing/zcgzip.cc
+
+zcgunzip_LDADD = $(PTHREAD_LIBS) libprotobuf.la
+zcgunzip_SOURCES = google/protobuf/testing/zcgunzip.cc
+endif
+
+# This test target is to ensure all our public header files and generated
+# code is free from warnings. We have to be more pedantic about these
+# files because they are compiled by users with different compiler flags.
+no_warning_test.cc:
+ echo "// Generated from Makefile.am" > no_warning_test.cc
+ for FILE in $(nobase_include_HEADERS); do \
+ if ! echo $${FILE} | grep "atomicops"; then \
+ echo "#include <$${FILE}>" >> no_warning_test.cc; \
+ fi \
+ done
+ echo "#include <gtest/gtest.h>" >> no_warning_test.cc
+ echo "TEST(NoWarningTest, Empty) {}" >> no_warning_test.cc
+
+no_warning_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la \
+ ../gmock/gtest/lib/libgtest.la \
+ ../gmock/gtest/lib/libgtest_main.la
+no_warning_test_CPPFLAGS = -I$(srcdir)/../gmock/gtest/include
+no_warning_test_CXXFLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_DEF) $(ZLIB_DEF) \
+ -Wall -Werror
+nodist_no_warning_test_SOURCES = no_warning_test.cc $(protoc_outputs)
+
+TESTS = protobuf-test protobuf-lazy-descriptor-test protobuf-lite-test \
+ google/protobuf/compiler/zip_output_unittest.sh $(GZTESTS) \
+ protobuf-lite-arena-test no-warning-test
diff --git a/third_party/protobuf/src/README.md b/third_party/protobuf/src/README.md
new file mode 100644
index 0000000000..c9362ee228
--- /dev/null
+++ b/third_party/protobuf/src/README.md
@@ -0,0 +1,212 @@
+Protocol Buffers - Google's data interchange format
+===================================================
+
+[![Build Status](https://travis-ci.org/google/protobuf.svg?branch=master)](https://travis-ci.org/google/protobuf) [![Build status](https://ci.appveyor.com/api/projects/status/73ctee6ua4w2ruin?svg=true)](https://ci.appveyor.com/project/protobuf/protobuf)
+
+Copyright 2008 Google Inc.
+
+https://developers.google.com/protocol-buffers/
+
+C++ Installation - Unix
+-----------------------
+
+To build protobuf from source, the following tools are needed:
+
+ * autoconf
+ * automake
+ * libtool
+ * curl (used to download gmock)
+ * make
+ * g++
+ * unzip
+
+On Ubuntu, you can install them with:
+
+ $ sudo apt-get install autoconf automake libtool curl make g++ unzip
+
+On other platforms, please use the corresponding package managing tool to
+install them before proceeding.
+
+If you get the source from github, you need to generate the configure script
+first:
+
+ $ ./autogen.sh
+
+This will download gmock source (which is used for C++ Protocol Buffer
+unit-tests) to the current directory and run automake, autoconf, etc.
+to generate the configure script and various template makefiles.
+
+You can skip this step if you are using a release package (which already
+contains gmock and the configure script).
+
+To build and install the C++ Protocol Buffer runtime and the Protocol
+Buffer compiler (protoc) execute the following:
+
+ $ ./configure
+ $ make
+ $ make check
+ $ sudo make install
+ $ sudo ldconfig # refresh shared library cache.
+
+If "make check" fails, you can still install, but it is likely that
+some features of this library will not work correctly on your system.
+Proceed at your own risk.
+
+For advanced usage information on configure and make, please refer to the
+autoconf documentation:
+
+ http://www.gnu.org/software/autoconf/manual/autoconf.html#Running-configure-Scripts
+
+**Hint on install location**
+
+ By default, the package will be installed to /usr/local. However,
+ on many platforms, /usr/local/lib is not part of LD_LIBRARY_PATH.
+ You can add it, but it may be easier to just install to /usr
+ instead. To do this, invoke configure as follows:
+
+ ./configure --prefix=/usr
+
+ If you already built the package with a different prefix, make sure
+ to run "make clean" before building again.
+
+**Compiling dependent packages**
+
+ To compile a package that uses Protocol Buffers, you need to pass
+ various flags to your compiler and linker. As of version 2.2.0,
+ Protocol Buffers integrates with pkg-config to manage this. If you
+ have pkg-config installed, then you can invoke it to get a list of
+ flags like so:
+
+ pkg-config --cflags protobuf # print compiler flags
+ pkg-config --libs protobuf # print linker flags
+ pkg-config --cflags --libs protobuf # print both
+
+ For example:
+
+ c++ my_program.cc my_proto.pb.cc `pkg-config --cflags --libs protobuf`
+
+ Note that packages written prior to the 2.2.0 release of Protocol
+ Buffers may not yet integrate with pkg-config to get flags, and may
+ not pass the correct set of flags to correctly link against
+ libprotobuf. If the package in question uses autoconf, you can
+ often fix the problem by invoking its configure script like:
+
+ configure CXXFLAGS="$(pkg-config --cflags protobuf)" \
+ LIBS="$(pkg-config --libs protobuf)"
+
+ This will force it to use the correct flags.
+
+ If you are writing an autoconf-based package that uses Protocol
+ Buffers, you should probably use the PKG_CHECK_MODULES macro in your
+ configure script like:
+
+ PKG_CHECK_MODULES([protobuf], [protobuf])
+
+ See the pkg-config man page for more info.
+
+ If you only want protobuf-lite, substitute "protobuf-lite" in place
+ of "protobuf" in these examples.
+
+**Note for Mac users**
+
+ For a Mac system, Unix tools are not available by default. You will first need
+ to install Xcode from the Mac AppStore and then run the following command from
+ a terminal:
+
+ $ sudo xcode-select --install
+
+ To install Unix tools, you can install "port" following the instructions at
+ https://www.macports.org . This will reside in /opt/local/bin/port for most
+ Mac installations.
+
+ $ sudo /opt/local/bin/port install autoconf automake libtool
+
+ Then follow the Unix instructions above.
+
+**Note for cross-compiling**
+
+ The makefiles normally invoke the protoc executable that they just
+ built in order to build tests. When cross-compiling, the protoc
+ executable may not be executable on the host machine. In this case,
+ you must build a copy of protoc for the host machine first, then use
+ the --with-protoc option to tell configure to use it instead. For
+ example:
+
+ ./configure --with-protoc=protoc
+
+ This will use the installed protoc (found in your $PATH) instead of
+ trying to execute the one built during the build process. You can
+ also use an executable that hasn't been installed. For example, if
+ you built the protobuf package for your host machine in ../host,
+ you might do:
+
+ ./configure --with-protoc=../host/src/protoc
+
+ Either way, you must make sure that the protoc executable you use
+ has the same version as the protobuf source code you are trying to
+ use it with.
+
+**Note for Solaris users**
+
+ Solaris 10 x86 has a bug that will make linking fail, complaining
+ about libstdc++.la being invalid. We have included a work-around
+ in this package. To use the work-around, run configure as follows:
+
+ ./configure LDFLAGS=-L$PWD/src/solaris
+
+ See src/solaris/libstdc++.la for more info on this bug.
+
+**Note for HP C++ Tru64 users**
+
+ To compile invoke configure as follows:
+
+ ./configure CXXFLAGS="-O -std ansi -ieee -D__USE_STD_IOSTREAM"
+
+ Also, you will need to use gmake instead of make.
+
+**Note for AIX users**
+
+ Compile using the IBM xlC C++ compiler as follows:
+
+ ./configure CXX=xlC
+
+ Also, you will need to use GNU `make` (`gmake`) instead of AIX `make`.
+
+C++ Installation - Windows
+--------------------------
+
+If you only need the protoc binary, you can download it from the release
+page:
+
+ https://github.com/google/protobuf/releases
+
+In the downloads section, download the zip file protoc-$VERSION-win32.zip.
+It contains the protoc binary as well as public proto files of protobuf
+library.
+
+To build from source using Microsoft Visual C++, see [cmake/README.md](../cmake/README.md).
+
+To build from source using Cygwin or MinGW, follow the Unix installation
+instructions, above.
+
+Binary Compatibility Warning
+----------------------------
+
+Due to the nature of C++, it is unlikely that any two versions of the
+Protocol Buffers C++ runtime libraries will have compatible ABIs.
+That is, if you linked an executable against an older version of
+libprotobuf, it is unlikely to work with a newer version without
+re-compiling. This problem, when it occurs, will normally be detected
+immediately on startup of your app. Still, you may want to consider
+using static linkage. You can configure this package to install
+static libraries only using:
+
+ ./configure --disable-shared
+
+Usage
+-----
+
+The complete documentation for Protocol Buffers is available via the
+web at:
+
+ https://developers.google.com/protocol-buffers/
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/any.cc b/third_party/protobuf/src/google/protobuf/any.cc
index f7b1d31061..83edba5788 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/any.cc
+++ b/third_party/protobuf/src/google/protobuf/any.cc
@@ -30,6 +30,8 @@
#include <google/protobuf/any.h>
+#include <google/protobuf/generated_message_util.h>
+
namespace google {
namespace protobuf {
namespace internal {
@@ -70,13 +72,11 @@ bool AnyMetadata::UnpackTo(Message* message) const {
if (!InternalIs(message->GetDescriptor())) {
return false;
}
- return message->ParseFromString(
- value_->GetNoArena(&::google::protobuf::internal::GetEmptyString()));
+ return message->ParseFromString(value_->GetNoArena());
}
bool AnyMetadata::InternalIs(const Descriptor* descriptor) const {
- const string type_url = type_url_->GetNoArena(
- &::google::protobuf::internal::GetEmptyString());
+ const string type_url = type_url_->GetNoArena();
string full_name;
if (!ParseAnyTypeUrl(type_url, &full_name)) {
return false;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/any.h b/third_party/protobuf/src/google/protobuf/any.h
index 04e541667f..04e541667f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/any.h
+++ b/third_party/protobuf/src/google/protobuf/any.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/any.pb.cc b/third_party/protobuf/src/google/protobuf/any.pb.cc
index ccccc9c12b..94c9539f44 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/any.pb.cc
+++ b/third_party/protobuf/src/google/protobuf/any.pb.cc
@@ -19,90 +19,104 @@
namespace google {
namespace protobuf {
+class AnyDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Any> {
+} _Any_default_instance_;
+
+namespace protobuf_google_2fprotobuf_2fany_2eproto {
+
namespace {
-const ::google::protobuf::Descriptor* Any_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- Any_reflection_ = NULL;
+::google::protobuf::Metadata file_level_metadata[1];
} // namespace
+const ::google::protobuf::uint32 TableStruct::offsets[] = {
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Any, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Any, type_url_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Any, value_),
+};
-void protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto() GOOGLE_ATTRIBUTE_COLD;
-void protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fany_2eproto();
- const ::google::protobuf::FileDescriptor* file =
- ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
- "google/protobuf/any.proto");
- GOOGLE_CHECK(file != NULL);
- Any_descriptor_ = file->message_type(0);
- static const int Any_offsets_[2] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Any, type_url_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Any, value_),
- };
- Any_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- Any_descriptor_,
- Any::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_));
-}
+static const ::google::protobuf::internal::MigrationSchema schemas[] = {
+ { 0, -1, sizeof(Any)},
+};
+
+static ::google::protobuf::Message const * const file_default_instances[] = {
+ reinterpret_cast<const ::google::protobuf::Message*>(&_Any_default_instance_),
+};
namespace {
-GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
-inline void protobuf_AssignDescriptorsOnce() {
- ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
- &protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto);
+void protobuf_AssignDescriptors() {
+ AddDescriptors();
+ ::google::protobuf::MessageFactory* factory = NULL;
+ AssignDescriptors(
+ "google/protobuf/any.proto", schemas, file_default_instances, TableStruct::offsets, factory,
+ file_level_metadata, NULL, NULL);
+}
+
+void protobuf_AssignDescriptorsOnce() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
}
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());
+ ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
}
} // namespace
-void protobuf_ShutdownFile_google_2fprotobuf_2fany_2eproto() {
- delete Any::default_instance_;
- delete Any_reflection_;
+void TableStruct::Shutdown() {
+ _Any_default_instance_.Shutdown();
+ delete file_level_metadata[0].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 TableStruct::InitDefaultsImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
+ ::google::protobuf::internal::InitProtobufDefaults();
+ _Any_default_instance_.DefaultConstruct();
+}
+
+void InitDefaults() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &TableStruct::InitDefaultsImpl);
+}
+void AddDescriptorsImpl() {
+ InitDefaults();
+ static const char descriptor[] = {
+ "\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(\014Bo\n\023com.google.protobufB\010AnyProtoP\001Z"
+ "%github.com/golang/protobuf/ptypes/any\242\002"
+ "\003GPB\252\002\036Google.Protobuf.WellKnownTypesb\006p"
+ "roto3"
+ };
::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);
+ descriptor, 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::internal::OnShutdown(&TableStruct::Shutdown);
}
+void AddDescriptors() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
+}
// Force AddDescriptors() to be called at static initialization time.
-struct StaticDescriptorInitializer_google_2fprotobuf_2fany_2eproto {
- StaticDescriptorInitializer_google_2fprotobuf_2fany_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fany_2eproto();
+struct StaticDescriptorInitializer {
+ StaticDescriptorInitializer() {
+ AddDescriptors();
}
-} static_descriptor_initializer_google_2fprotobuf_2fany_2eproto_;
+} static_descriptor_initializer;
+
+} // namespace protobuf_google_2fprotobuf_2fany_2eproto
+
// ===================================================================
@@ -126,29 +140,33 @@ const int Any::kValueFieldNumber;
Any::Any()
: ::google::protobuf::Message(), _internal_metadata_(NULL), _any_metadata_(&type_url_, &value_) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fany_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.Any)
}
-
-void Any::InitAsDefaultInstance() {
- _is_default_instance_ = true;
-}
-
Any::Any(const Any& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL),
- _any_metadata_(&type_url_, &value_) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _cached_size_(0),
+ _any_metadata_(&type_url_, &value_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ type_url_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.type_url().size() > 0) {
+ type_url_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.type_url_);
+ }
+ value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.value().size() > 0) {
+ value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.value_);
+ }
// @@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 +177,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 {
@@ -169,17 +185,15 @@ void Any::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Any::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Any_descriptor_;
+ protobuf_google_2fprotobuf_2fany_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fany_2eproto::file_level_metadata[0].descriptor;
}
const Any& Any::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fany_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fany_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-Any* Any::default_instance_ = NULL;
-
Any* Any::New(::google::protobuf::Arena* arena) const {
Any* n = new Any;
if (arena != NULL) {
@@ -200,13 +214,14 @@ bool Any::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Any)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional string type_url = 1;
+ // string type_url = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_type_url()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -216,20 +231,18 @@ bool Any::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_value;
break;
}
- // optional bytes value = 2;
+ // bytes value = 2;
case 2: {
- if (tag == 18) {
- parse_value:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadBytes(
input, this->mutable_value()));
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -257,7 +270,7 @@ failure:
void Any::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.Any)
- // optional string type_url = 1;
+ // string type_url = 1;
if (this->type_url().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->type_url().data(), this->type_url().length(),
@@ -267,7 +280,7 @@ void Any::SerializeWithCachedSizes(
1, this->type_url(), output);
}
- // optional bytes value = 2;
+ // bytes value = 2;
if (this->value().size() > 0) {
::google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(
2, this->value(), output);
@@ -278,8 +291,9 @@ void Any::SerializeWithCachedSizes(
::google::protobuf::uint8* Any::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Any)
- // optional string type_url = 1;
+ // string type_url = 1;
if (this->type_url().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->type_url().data(), this->type_url().length(),
@@ -290,7 +304,7 @@ void Any::SerializeWithCachedSizes(
1, this->type_url(), target);
}
- // optional bytes value = 2;
+ // bytes value = 2;
if (this->value().size() > 0) {
target =
::google::protobuf::internal::WireFormatLite::WriteBytesToArray(
@@ -301,36 +315,35 @@ 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;
+ // string type_url = 1;
if (this->type_url().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->type_url());
}
- // optional bytes value = 2;
+ // bytes value = 2;
if (this->value().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::BytesSize(
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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const Any* source =
::google::protobuf::internal::DynamicCastToGenerated<const Any>(
&from);
if (source == NULL) {
@@ -344,9 +357,8 @@ void Any::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
if (from.type_url().size() > 0) {
type_url_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.type_url_);
@@ -372,7 +384,6 @@ void Any::CopyFrom(const Any& from) {
}
bool Any::IsInitialized() const {
-
return true;
}
@@ -383,56 +394,60 @@ void Any::Swap(Any* other) {
void Any::InternalSwap(Any* other) {
type_url_.Swap(&other->type_url_);
value_.Swap(&other->value_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Any::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = Any_descriptor_;
- metadata.reflection = Any_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fany_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fany_2eproto::file_level_metadata[0];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// Any
-// optional string type_url = 1;
+// string type_url = 1;
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());
+ return type_url_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void Any::set_type_url(::std::string&& value) {
+
+ type_url_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Any.type_url)
+}
+#endif
+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<const char*>(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 {
@@ -442,41 +457,49 @@ void Any::clear_type_url() {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.type_url)
}
-// optional bytes value = 2;
+// bytes value = 2;
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());
+ return value_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void Any::set_value(::std::string&& value) {
+
+ value_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Any.value)
+}
+#endif
+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<const char*>(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/third_party/protobuf/3.0.0/src/google/protobuf/any.pb.h b/third_party/protobuf/src/google/protobuf/any.pb.h
index d8cbee2d02..1a61d5afa2 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/any.pb.h
+++ b/third_party/protobuf/src/google/protobuf/any.pb.h
@@ -8,37 +8,49 @@
#include <google/protobuf/stubs/common.h>
-#if GOOGLE_PROTOBUF_VERSION < 3000000
+#if GOOGLE_PROTOBUF_VERSION < 3002000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
-#if 3000000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
+#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
+#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/metadata.h>
#include <google/protobuf/message.h>
-#include <google/protobuf/repeated_field.h>
-#include <google/protobuf/extension_set.h>
+#include <google/protobuf/repeated_field.h> // IWYU pragma: export
+#include <google/protobuf/extension_set.h> // IWYU pragma: export
#include <google/protobuf/unknown_field_set.h>
#include <google/protobuf/any.h>
// @@protoc_insertion_point(includes)
+namespace google {
+namespace protobuf {
+class Any;
+class AnyDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern AnyDefaultTypeInternal _Any_default_instance_;
+} // namespace protobuf
+} // namespace google
namespace google {
namespace protobuf {
+namespace protobuf_google_2fprotobuf_2fany_2eproto {
// Internal implementation detail -- do not call these.
-void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fany_2eproto();
-void protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto();
-void protobuf_ShutdownFile_google_2fprotobuf_2fany_2eproto();
-
-class Any;
+struct LIBPROTOBUF_EXPORT TableStruct {
+ static const ::google::protobuf::uint32 offsets[];
+ static void InitDefaultsImpl();
+ static void Shutdown();
+};
+void LIBPROTOBUF_EXPORT AddDescriptors();
+void LIBPROTOBUF_EXPORT InitDefaults();
+} // namespace protobuf_google_2fprotobuf_2fany_2eproto
// ===================================================================
@@ -57,6 +69,11 @@ 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 reinterpret_cast<const Any*>(
+ &_Any_default_instance_);
+ }
+
// implements Any -----------------------------------------------
void PackFrom(const ::google::protobuf::Message& message);
@@ -71,63 +88,71 @@ class LIBPROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_in
// implements Message ----------------------------------------------
- inline Any* New() const { return New(NULL); }
+ inline Any* New() const PROTOBUF_FINAL { return New(NULL); }
- Any* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ Any* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Any& from);
void MergeFrom(const Any& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Any* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional string type_url = 1;
+ // string type_url = 1;
void clear_type_url();
static const int kTypeUrlFieldNumber = 1;
const ::std::string& type_url() const;
void set_type_url(const ::std::string& value);
+ #if LANG_CXX11
+ void set_type_url(::std::string&& value);
+ #endif
void set_type_url(const char* value);
void set_type_url(const char* value, size_t size);
::std::string* mutable_type_url();
::std::string* release_type_url();
void set_allocated_type_url(::std::string* type_url);
- // optional bytes value = 2;
+ // bytes value = 2;
void clear_value();
static const int kValueFieldNumber = 2;
const ::std::string& value() const;
void set_value(const ::std::string& value);
+ #if LANG_CXX11
+ void set_value(::std::string&& value);
+ #endif
void set_value(const char* value);
void set_value(const void* value, size_t size);
::std::string* mutable_value();
@@ -138,17 +163,11 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fany_2eproto();
-
- void InitAsDefaultInstance();
- static Any* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fany_2eproto::TableStruct;
};
// ===================================================================
@@ -158,19 +177,27 @@ class LIBPROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_in
#if !PROTOBUF_INLINE_NOT_IN_HEADERS
// Any
-// optional string type_url = 1;
+// string type_url = 1;
inline void Any::clear_type_url() {
type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline 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());
+ return type_url_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void Any::set_type_url(::std::string&& value) {
+
+ type_url_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Any.type_url)
+}
+#endif
inline void Any::set_type_url(const char* value) {
type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -202,19 +229,27 @@ inline void Any::set_allocated_type_url(::std::string* type_url) {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.type_url)
}
-// optional bytes value = 2;
+// bytes value = 2;
inline void Any::clear_value() {
value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& Any::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.Any.value)
- return value_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return value_.GetNoArena();
}
inline void Any::set_value(const ::std::string& value) {
value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.Any.value)
}
+#if LANG_CXX11
+inline void Any::set_value(::std::string&& value) {
+
+ value_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Any.value)
+}
+#endif
inline void Any::set_value(const char* value) {
value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -250,6 +285,7 @@ inline void Any::set_allocated_value(::std::string* value) {
// @@protoc_insertion_point(namespace_scope)
+
} // namespace protobuf
} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/any.proto b/third_party/protobuf/src/google/protobuf/any.proto
index 81dcf46ccf..9bd3f50a45 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/any.proto
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/src/google/protobuf/any_test.cc b/third_party/protobuf/src/google/protobuf/any_test.cc
index 1bfaa63d87..1bfaa63d87 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/any_test.cc
+++ b/third_party/protobuf/src/google/protobuf/any_test.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/any_test.proto b/third_party/protobuf/src/google/protobuf/any_test.proto
index 0c5b30ba3e..0c5b30ba3e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/any_test.proto
+++ b/third_party/protobuf/src/google/protobuf/any_test.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/api.pb.cc b/third_party/protobuf/src/google/protobuf/api.pb.cc
index cfb3078691..6518e51817 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/api.pb.cc
+++ b/third_party/protobuf/src/google/protobuf/api.pb.cc
@@ -19,164 +19,159 @@
namespace google {
namespace protobuf {
+class ApiDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Api> {
+} _Api_default_instance_;
+class MethodDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Method> {
+} _Method_default_instance_;
+class MixinDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Mixin> {
+} _Mixin_default_instance_;
+
+namespace protobuf_google_2fprotobuf_2fapi_2eproto {
+
namespace {
-const ::google::protobuf::Descriptor* Api_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- Api_reflection_ = NULL;
-const ::google::protobuf::Descriptor* Method_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- Method_reflection_ = NULL;
-const ::google::protobuf::Descriptor* Mixin_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- Mixin_reflection_ = NULL;
+::google::protobuf::Metadata file_level_metadata[3];
} // namespace
-
-void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto() GOOGLE_ATTRIBUTE_COLD;
-void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto();
- const ::google::protobuf::FileDescriptor* file =
- ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
- "google/protobuf/api.proto");
- GOOGLE_CHECK(file != NULL);
- Api_descriptor_ = file->message_type(0);
- static const int Api_offsets_[7] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, methods_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, options_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, version_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, source_context_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, mixins_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, syntax_),
- };
- Api_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- Api_descriptor_,
- Api::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_));
- Method_descriptor_ = file->message_type(1);
- static const int Method_offsets_[7] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, request_type_url_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, request_streaming_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, response_type_url_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, response_streaming_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, options_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, syntax_),
- };
- Method_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- Method_descriptor_,
- Method::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_));
- Mixin_descriptor_ = file->message_type(2);
- static const int Mixin_offsets_[2] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Mixin, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Mixin, root_),
- };
- Mixin_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- Mixin_descriptor_,
- Mixin::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_));
-}
+const ::google::protobuf::uint32 TableStruct::offsets[] = {
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, methods_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, options_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, version_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, source_context_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, mixins_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, syntax_),
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, request_type_url_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, request_streaming_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, response_type_url_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, response_streaming_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, options_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Method, syntax_),
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Mixin, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Mixin, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Mixin, root_),
+};
+
+static const ::google::protobuf::internal::MigrationSchema schemas[] = {
+ { 0, -1, sizeof(Api)},
+ { 11, -1, sizeof(Method)},
+ { 22, -1, sizeof(Mixin)},
+};
+
+static ::google::protobuf::Message const * const file_default_instances[] = {
+ reinterpret_cast<const ::google::protobuf::Message*>(&_Api_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_Method_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_Mixin_default_instance_),
+};
namespace {
-GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
-inline void protobuf_AssignDescriptorsOnce() {
- ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
- &protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto);
+void protobuf_AssignDescriptors() {
+ AddDescriptors();
+ ::google::protobuf::MessageFactory* factory = NULL;
+ AssignDescriptors(
+ "google/protobuf/api.proto", schemas, file_default_instances, TableStruct::offsets, factory,
+ file_level_metadata, NULL, NULL);
+}
+
+void protobuf_AssignDescriptorsOnce() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
}
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());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- Method_descriptor_, &Method::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- Mixin_descriptor_, &Mixin::default_instance());
+ ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 3);
}
} // 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 TableStruct::Shutdown() {
+ _Api_default_instance_.Shutdown();
+ delete file_level_metadata[0].reflection;
+ _Method_default_instance_.Shutdown();
+ delete file_level_metadata[1].reflection;
+ _Mixin_default_instance_.Shutdown();
+ delete file_level_metadata[2].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 TableStruct::InitDefaultsImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
- ::google::protobuf::protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto();
- ::google::protobuf::protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto();
+ ::google::protobuf::internal::InitProtobufDefaults();
+ ::google::protobuf::protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::InitDefaults();
+ ::google::protobuf::protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults();
+ _Api_default_instance_.DefaultConstruct();
+ _Method_default_instance_.DefaultConstruct();
+ _Mixin_default_instance_.DefaultConstruct();
+ _Api_default_instance_.get_mutable()->source_context_ = const_cast< ::google::protobuf::SourceContext*>(
+ ::google::protobuf::SourceContext::internal_default_instance());
+}
+
+void InitDefaults() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &TableStruct::InitDefaultsImpl);
+}
+void AddDescriptorsImpl() {
+ InitDefaults();
+ static const char descriptor[] = {
+ "\n\031google/protobuf/api.proto\022\017google.prot"
+ "obuf\032$google/protobuf/source_context.pro"
+ "to\032\032google/protobuf/type.proto\"\201\002\n\003Api\022\014"
+ "\n\004name\030\001 \001(\t\022(\n\007methods\030\002 \003(\0132\027.google.p"
+ "rotobuf.Method\022(\n\007options\030\003 \003(\0132\027.google"
+ ".protobuf.Option\022\017\n\007version\030\004 \001(\t\0226\n\016sou"
+ "rce_context\030\005 \001(\0132\036.google.protobuf.Sour"
+ "ceContext\022&\n\006mixins\030\006 \003(\0132\026.google.proto"
+ "buf.Mixin\022\'\n\006syntax\030\007 \001(\0162\027.google.proto"
+ "buf.Syntax\"\325\001\n\006Method\022\014\n\004name\030\001 \001(\t\022\030\n\020r"
+ "equest_type_url\030\002 \001(\t\022\031\n\021request_streami"
+ "ng\030\003 \001(\010\022\031\n\021response_type_url\030\004 \001(\t\022\032\n\022r"
+ "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(\tBu\n\023com.google.pr"
+ "otobufB\010ApiProtoP\001Z+google.golang.org/ge"
+ "nproto/protobuf/api;api\242\002\003GPB\252\002\036Google.P"
+ "rotobuf.WellKnownTypesb\006proto3"
+ };
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
- "\n\031google/protobuf/api.proto\022\017google.prot"
- "obuf\032$google/protobuf/source_context.pro"
- "to\032\032google/protobuf/type.proto\"\201\002\n\003Api\022\014"
- "\n\004name\030\001 \001(\t\022(\n\007methods\030\002 \003(\0132\027.google.p"
- "rotobuf.Method\022(\n\007options\030\003 \003(\0132\027.google"
- ".protobuf.Option\022\017\n\007version\030\004 \001(\t\0226\n\016sou"
- "rce_context\030\005 \001(\0132\036.google.protobuf.Sour"
- "ceContext\022&\n\006mixins\030\006 \003(\0132\026.google.proto"
- "buf.Mixin\022\'\n\006syntax\030\007 \001(\0162\027.google.proto"
- "buf.Syntax\"\325\001\n\006Method\022\014\n\004name\030\001 \001(\t\022\030\n\020r"
- "equest_type_url\030\002 \001(\t\022\031\n\021request_streami"
- "ng\030\003 \001(\010\022\031\n\021response_type_url\030\004 \001(\t\022\032\n\022r"
- "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);
+ descriptor, 750);
::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::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto);
+ ::google::protobuf::protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::AddDescriptors();
+ ::google::protobuf::protobuf_google_2fprotobuf_2ftype_2eproto::AddDescriptors();
+ ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown);
}
+void AddDescriptors() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
+}
// Force AddDescriptors() to be called at static initialization time.
-struct StaticDescriptorInitializer_google_2fprotobuf_2fapi_2eproto {
- StaticDescriptorInitializer_google_2fprotobuf_2fapi_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto();
+struct StaticDescriptorInitializer {
+ StaticDescriptorInitializer() {
+ AddDescriptors();
}
-} static_descriptor_initializer_google_2fprotobuf_2fapi_2eproto_;
+} static_descriptor_initializer;
+
+} // namespace protobuf_google_2fprotobuf_2fapi_2eproto
+
// ===================================================================
@@ -192,31 +187,43 @@ const int Api::kSyntaxFieldNumber;
Api::Api()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fapi_2eproto::InitDefaults();
+ }
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());
-}
-
Api::Api(const Api& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ methods_(from.methods_),
+ options_(from.options_),
+ mixins_(from.mixins_),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.name().size() > 0) {
+ name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
+ }
+ version_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.version().size() > 0) {
+ version_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.version_);
+ }
+ if (from.has_source_context()) {
+ source_context_ = new ::google::protobuf::SourceContext(*from.source_context_);
+ } else {
+ source_context_ = NULL;
+ }
+ syntax_ = from.syntax_;
// @@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;
+ ::memset(&source_context_, 0, reinterpret_cast<char*>(&syntax_) -
+ reinterpret_cast<char*>(&source_context_) + sizeof(syntax_));
+ _cached_size_ = 0;
}
Api::~Api() {
@@ -227,7 +234,7 @@ Api::~Api() {
void Api::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
version_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- if (this != default_instance_) {
+ if (this != internal_default_instance()) {
delete source_context_;
}
}
@@ -238,17 +245,15 @@ void Api::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Api::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Api_descriptor_;
+ protobuf_google_2fprotobuf_2fapi_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[0].descriptor;
}
const Api& Api::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fapi_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-Api* Api::default_instance_ = NULL;
-
Api* Api::New(::google::protobuf::Arena* arena) const {
Api* n = new Api;
if (arena != NULL) {
@@ -259,14 +264,16 @@ Api* Api::New(::google::protobuf::Arena* arena) const {
void Api::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.Api)
+ methods_.Clear();
+ options_.Clear();
+ mixins_.Clear();
name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
version_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- if (GetArenaNoVirtual() == NULL && source_context_ != NULL) delete source_context_;
+ if (GetArenaNoVirtual() == NULL && source_context_ != NULL) {
+ delete source_context_;
+ }
source_context_ = NULL;
syntax_ = 0;
- methods_.Clear();
- options_.Clear();
- mixins_.Clear();
}
bool Api::MergePartialFromCodedStream(
@@ -275,13 +282,14 @@ bool Api::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Api)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional string name = 1;
+ // string name = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -291,47 +299,41 @@ bool Api::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_methods;
break;
}
// repeated .google.protobuf.Method methods = 2;
case 2: {
- if (tag == 18) {
- parse_methods:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_methods:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_methods()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_loop_methods;
- if (input->ExpectTag(26)) goto parse_loop_options;
input->UnsafeDecrementRecursionDepth();
break;
}
// repeated .google.protobuf.Option options = 3;
case 3: {
- if (tag == 26) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(26u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_options:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_options()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(26)) goto parse_loop_options;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectTag(34)) goto parse_version;
break;
}
- // optional string version = 4;
+ // string version = 4;
case 4: {
- if (tag == 34) {
- parse_version:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(34u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_version()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -341,44 +343,39 @@ bool Api::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(42)) goto parse_source_context;
break;
}
- // optional .google.protobuf.SourceContext source_context = 5;
+ // .google.protobuf.SourceContext source_context = 5;
case 5: {
- if (tag == 42) {
- parse_source_context:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(42u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, mutable_source_context()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(50)) goto parse_mixins;
break;
}
// repeated .google.protobuf.Mixin mixins = 6;
case 6: {
- if (tag == 50) {
- parse_mixins:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(50u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_mixins:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_mixins()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(50)) goto parse_loop_mixins;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectTag(56)) goto parse_syntax;
break;
}
- // optional .google.protobuf.Syntax syntax = 7;
+ // .google.protobuf.Syntax syntax = 7;
case 7: {
- if (tag == 56) {
- parse_syntax:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(56u)) {
int value;
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(
@@ -387,7 +384,6 @@ bool Api::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -415,7 +411,7 @@ failure:
void Api::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.Api)
- // optional string name = 1;
+ // string name = 1;
if (this->name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->name().data(), this->name().length(),
@@ -437,7 +433,7 @@ void Api::SerializeWithCachedSizes(
3, this->options(i), output);
}
- // optional string version = 4;
+ // string version = 4;
if (this->version().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->version().data(), this->version().length(),
@@ -447,7 +443,7 @@ void Api::SerializeWithCachedSizes(
4, this->version(), output);
}
- // optional .google.protobuf.SourceContext source_context = 5;
+ // .google.protobuf.SourceContext source_context = 5;
if (this->has_source_context()) {
::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
5, *this->source_context_, output);
@@ -459,7 +455,7 @@ void Api::SerializeWithCachedSizes(
6, this->mixins(i), output);
}
- // optional .google.protobuf.Syntax syntax = 7;
+ // .google.protobuf.Syntax syntax = 7;
if (this->syntax() != 0) {
::google::protobuf::internal::WireFormatLite::WriteEnum(
7, this->syntax(), output);
@@ -470,8 +466,9 @@ void Api::SerializeWithCachedSizes(
::google::protobuf::uint8* Api::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Api)
- // optional string name = 1;
+ // string name = 1;
if (this->name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->name().data(), this->name().length(),
@@ -496,7 +493,7 @@ void Api::SerializeWithCachedSizes(
3, this->options(i), false, target);
}
- // optional string version = 4;
+ // string version = 4;
if (this->version().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->version().data(), this->version().length(),
@@ -507,7 +504,7 @@ void Api::SerializeWithCachedSizes(
4, this->version(), target);
}
- // optional .google.protobuf.SourceContext source_context = 5;
+ // .google.protobuf.SourceContext source_context = 5;
if (this->has_source_context()) {
target = ::google::protobuf::internal::WireFormatLite::
InternalWriteMessageNoVirtualToArray(
@@ -521,7 +518,7 @@ void Api::SerializeWithCachedSizes(
6, this->mixins(i), false, target);
}
- // optional .google.protobuf.Syntax syntax = 7;
+ // .google.protobuf.Syntax syntax = 7;
if (this->syntax() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray(
7, this->syntax(), target);
@@ -531,73 +528,81 @@ 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;
+
+ // repeated .google.protobuf.Method methods = 2;
+ {
+ 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;
+ {
+ 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));
+ }
+ }
- // optional string name = 1;
+ // repeated .google.protobuf.Mixin mixins = 6;
+ {
+ 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));
+ }
+ }
+
+ // string name = 1;
if (this->name().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->name());
}
- // optional string version = 4;
+ // string version = 4;
if (this->version().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->version());
}
- // optional .google.protobuf.SourceContext source_context = 5;
+ // .google.protobuf.SourceContext source_context = 5;
if (this->has_source_context()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual(
*this->source_context_);
}
- // optional .google.protobuf.Syntax syntax = 7;
+ // .google.protobuf.Syntax syntax = 7;
if (this->syntax() != 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::EnumSize(this->syntax());
}
- // 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));
- }
-
- // 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));
- }
-
- // 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));
- }
-
+ 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const Api* source =
::google::protobuf::internal::DynamicCastToGenerated<const Api>(
&from);
if (source == NULL) {
@@ -611,9 +616,8 @@ void Api::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
methods_.MergeFrom(from.methods_);
options_.MergeFrom(from.options_);
mixins_.MergeFrom(from.mixins_);
@@ -648,7 +652,6 @@ void Api::CopyFrom(const Api& from) {
}
bool Api::IsInitialized() const {
-
return true;
}
@@ -657,63 +660,67 @@ void Api::Swap(Api* other) {
InternalSwap(other);
}
void Api::InternalSwap(Api* other) {
- name_.Swap(&other->name_);
methods_.UnsafeArenaSwap(&other->methods_);
options_.UnsafeArenaSwap(&other->options_);
+ mixins_.UnsafeArenaSwap(&other->mixins_);
+ name_.Swap(&other->name_);
version_.Swap(&other->version_);
std::swap(source_context_, other->source_context_);
- mixins_.UnsafeArenaSwap(&other->mixins_);
std::swap(syntax_, other->syntax_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Api::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = Api_descriptor_;
- metadata.reflection = Api_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fapi_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[0];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// Api
-// optional string name = 1;
+// string name = 1;
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());
+ return name_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void Api::set_name(::std::string&& value) {
+
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Api.name)
+}
+#endif
+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<const char*>(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 {
@@ -783,41 +790,49 @@ Api::options() const {
return options_;
}
-// optional string version = 4;
+// string version = 4;
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());
+ return version_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void Api::set_version(::std::string&& value) {
+
+ version_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Api.version)
+}
+#endif
+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<const char*>(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 {
@@ -827,9 +842,9 @@ void Api::clear_version() {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.version)
}
-// optional .google.protobuf.SourceContext source_context = 5;
+// .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_;
@@ -837,7 +852,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() {
@@ -895,15 +911,15 @@ Api::mixins() const {
return mixins_;
}
-// optional .google.protobuf.Syntax syntax = 7;
+// .google.protobuf.Syntax syntax = 7;
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)
@@ -925,32 +941,43 @@ const int Method::kSyntaxFieldNumber;
Method::Method()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fapi_2eproto::InitDefaults();
+ }
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);
+ _internal_metadata_(NULL),
+ options_(from.options_),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.name().size() > 0) {
+ name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
+ }
+ request_type_url_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.request_type_url().size() > 0) {
+ request_type_url_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.request_type_url_);
+ }
+ response_type_url_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.response_type_url().size() > 0) {
+ response_type_url_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.response_type_url_);
+ }
+ ::memcpy(&request_streaming_, &from.request_streaming_,
+ reinterpret_cast<char*>(&syntax_) -
+ reinterpret_cast<char*>(&request_streaming_) + sizeof(syntax_));
// @@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<char*>(&syntax_) -
+ reinterpret_cast<char*>(&request_streaming_) + sizeof(syntax_));
+ _cached_size_ = 0;
}
Method::~Method() {
@@ -962,8 +989,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 {
@@ -972,17 +997,15 @@ void Method::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Method::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Method_descriptor_;
+ protobuf_google_2fprotobuf_2fapi_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[1].descriptor;
}
const Method& Method::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fapi_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-Method* Method::default_instance_ = NULL;
-
Method* Method::New(::google::protobuf::Arena* arena) const {
Method* n = new Method;
if (arena != NULL) {
@@ -993,31 +1016,12 @@ Method* Method::New(::google::protobuf::Arena* arena) const {
void Method::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.Method)
-#if defined(__clang__)
-#define ZR_HELPER_(f) \
- _Pragma("clang diagnostic push") \
- _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
- __builtin_offsetof(Method, f) \
- _Pragma("clang diagnostic pop")
-#else
-#define ZR_HELPER_(f) reinterpret_cast<char*>(\
- &reinterpret_cast<Method*>(16)->f)
-#endif
-
-#define ZR_(first, last) do {\
- ::memset(&first, 0,\
- ZR_HELPER_(last) - ZR_HELPER_(first) + sizeof(last));\
-} while (0)
-
- ZR_(request_streaming_, syntax_);
+ options_.Clear();
name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
request_type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
response_type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
-
-#undef ZR_HELPER_
-#undef ZR_
-
- options_.Clear();
+ ::memset(&request_streaming_, 0, reinterpret_cast<char*>(&syntax_) -
+ reinterpret_cast<char*>(&request_streaming_) + sizeof(syntax_));
}
bool Method::MergePartialFromCodedStream(
@@ -1026,13 +1030,14 @@ bool Method::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Method)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional string name = 1;
+ // string name = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -1042,14 +1047,13 @@ bool Method::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_request_type_url;
break;
}
- // optional string request_type_url = 2;
+ // string request_type_url = 2;
case 2: {
- if (tag == 18) {
- parse_request_type_url:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_request_type_url()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -1059,29 +1063,27 @@ bool Method::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(24)) goto parse_request_streaming;
break;
}
- // optional bool request_streaming = 3;
+ // bool request_streaming = 3;
case 3: {
- if (tag == 24) {
- parse_request_streaming:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(24u)) {
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>(
input, &request_streaming_)));
-
} else {
goto handle_unusual;
}
- if (input->ExpectTag(34)) goto parse_response_type_url;
break;
}
- // optional string response_type_url = 4;
+ // string response_type_url = 4;
case 4: {
- if (tag == 34) {
- parse_response_type_url:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(34u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_response_type_url()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -1091,46 +1093,41 @@ bool Method::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(40)) goto parse_response_streaming;
break;
}
- // optional bool response_streaming = 5;
+ // bool response_streaming = 5;
case 5: {
- if (tag == 40) {
- parse_response_streaming:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(40u)) {
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>(
input, &response_streaming_)));
-
} else {
goto handle_unusual;
}
- if (input->ExpectTag(50)) goto parse_options;
break;
}
// repeated .google.protobuf.Option options = 6;
case 6: {
- if (tag == 50) {
- parse_options:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(50u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_options:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_options()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(50)) goto parse_loop_options;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectTag(56)) goto parse_syntax;
break;
}
- // optional .google.protobuf.Syntax syntax = 7;
+ // .google.protobuf.Syntax syntax = 7;
case 7: {
- if (tag == 56) {
- parse_syntax:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(56u)) {
int value;
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(
@@ -1139,7 +1136,6 @@ bool Method::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -1167,7 +1163,7 @@ failure:
void Method::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.Method)
- // optional string name = 1;
+ // string name = 1;
if (this->name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->name().data(), this->name().length(),
@@ -1177,7 +1173,7 @@ void Method::SerializeWithCachedSizes(
1, this->name(), output);
}
- // optional string request_type_url = 2;
+ // string request_type_url = 2;
if (this->request_type_url().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->request_type_url().data(), this->request_type_url().length(),
@@ -1187,12 +1183,12 @@ void Method::SerializeWithCachedSizes(
2, this->request_type_url(), output);
}
- // optional bool request_streaming = 3;
+ // bool request_streaming = 3;
if (this->request_streaming() != 0) {
::google::protobuf::internal::WireFormatLite::WriteBool(3, this->request_streaming(), output);
}
- // optional string response_type_url = 4;
+ // string response_type_url = 4;
if (this->response_type_url().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->response_type_url().data(), this->response_type_url().length(),
@@ -1202,7 +1198,7 @@ void Method::SerializeWithCachedSizes(
4, this->response_type_url(), output);
}
- // optional bool response_streaming = 5;
+ // bool response_streaming = 5;
if (this->response_streaming() != 0) {
::google::protobuf::internal::WireFormatLite::WriteBool(5, this->response_streaming(), output);
}
@@ -1213,7 +1209,7 @@ void Method::SerializeWithCachedSizes(
6, this->options(i), output);
}
- // optional .google.protobuf.Syntax syntax = 7;
+ // .google.protobuf.Syntax syntax = 7;
if (this->syntax() != 0) {
::google::protobuf::internal::WireFormatLite::WriteEnum(
7, this->syntax(), output);
@@ -1224,8 +1220,9 @@ void Method::SerializeWithCachedSizes(
::google::protobuf::uint8* Method::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Method)
- // optional string name = 1;
+ // string name = 1;
if (this->name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->name().data(), this->name().length(),
@@ -1236,7 +1233,7 @@ void Method::SerializeWithCachedSizes(
1, this->name(), target);
}
- // optional string request_type_url = 2;
+ // string request_type_url = 2;
if (this->request_type_url().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->request_type_url().data(), this->request_type_url().length(),
@@ -1247,12 +1244,12 @@ void Method::SerializeWithCachedSizes(
2, this->request_type_url(), target);
}
- // optional bool request_streaming = 3;
+ // bool request_streaming = 3;
if (this->request_streaming() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(3, this->request_streaming(), target);
}
- // optional string response_type_url = 4;
+ // string response_type_url = 4;
if (this->response_type_url().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->response_type_url().data(), this->response_type_url().length(),
@@ -1263,7 +1260,7 @@ void Method::SerializeWithCachedSizes(
4, this->response_type_url(), target);
}
- // optional bool response_streaming = 5;
+ // bool response_streaming = 5;
if (this->response_streaming() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(5, this->response_streaming(), target);
}
@@ -1275,7 +1272,7 @@ void Method::SerializeWithCachedSizes(
6, this->options(i), false, target);
}
- // optional .google.protobuf.Syntax syntax = 7;
+ // .google.protobuf.Syntax syntax = 7;
if (this->syntax() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray(
7, this->syntax(), target);
@@ -1285,67 +1282,69 @@ 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;
+
+ // repeated .google.protobuf.Option options = 6;
+ {
+ 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));
+ }
+ }
- // optional string name = 1;
+ // string name = 1;
if (this->name().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->name());
}
- // optional string request_type_url = 2;
+ // string request_type_url = 2;
if (this->request_type_url().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->request_type_url());
}
- // optional bool request_streaming = 3;
- if (this->request_streaming() != 0) {
- total_size += 1 + 1;
- }
-
- // optional string response_type_url = 4;
+ // string response_type_url = 4;
if (this->response_type_url().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->response_type_url());
}
- // optional bool response_streaming = 5;
+ // bool request_streaming = 3;
+ if (this->request_streaming() != 0) {
+ total_size += 1 + 1;
+ }
+
+ // bool response_streaming = 5;
if (this->response_streaming() != 0) {
total_size += 1 + 1;
}
- // optional .google.protobuf.Syntax syntax = 7;
+ // .google.protobuf.Syntax syntax = 7;
if (this->syntax() != 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::EnumSize(this->syntax());
}
- // 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));
- }
-
+ 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const Method* source =
::google::protobuf::internal::DynamicCastToGenerated<const Method>(
&from);
if (source == NULL) {
@@ -1359,9 +1358,8 @@ void Method::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
options_.MergeFrom(from.options_);
if (from.name().size() > 0) {
@@ -1371,13 +1369,13 @@ void Method::MergeFrom(const Method& from) {
request_type_url_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.request_type_url_);
}
- if (from.request_streaming() != 0) {
- set_request_streaming(from.request_streaming());
- }
if (from.response_type_url().size() > 0) {
response_type_url_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.response_type_url_);
}
+ if (from.request_streaming() != 0) {
+ set_request_streaming(from.request_streaming());
+ }
if (from.response_streaming() != 0) {
set_response_streaming(from.response_streaming());
}
@@ -1401,7 +1399,6 @@ void Method::CopyFrom(const Method& from) {
}
bool Method::IsInitialized() const {
-
return true;
}
@@ -1410,63 +1407,67 @@ void Method::Swap(Method* other) {
InternalSwap(other);
}
void Method::InternalSwap(Method* other) {
+ options_.UnsafeArenaSwap(&other->options_);
name_.Swap(&other->name_);
request_type_url_.Swap(&other->request_type_url_);
- std::swap(request_streaming_, other->request_streaming_);
response_type_url_.Swap(&other->response_type_url_);
+ std::swap(request_streaming_, other->request_streaming_);
std::swap(response_streaming_, other->response_streaming_);
- options_.UnsafeArenaSwap(&other->options_);
std::swap(syntax_, other->syntax_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Method::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = Method_descriptor_;
- metadata.reflection = Method_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fapi_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[1];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// Method
-// optional string name = 1;
+// string name = 1;
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());
+ return name_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void Method::set_name(::std::string&& value) {
+
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.name)
+}
+#endif
+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<const char*>(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 {
@@ -1476,41 +1477,49 @@ void Method::clear_name() {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.name)
}
-// optional string request_type_url = 2;
+// string request_type_url = 2;
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());
+ return request_type_url_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void Method::set_request_type_url(::std::string&& value) {
+
+ request_type_url_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.request_type_url)
+}
+#endif
+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<const char*>(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 {
@@ -1520,55 +1529,63 @@ void Method::clear_request_type_url() {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.request_type_url)
}
-// optional bool request_streaming = 3;
+// bool request_streaming = 3;
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)
}
-// optional string response_type_url = 4;
+// string response_type_url = 4;
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());
+ return response_type_url_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void Method::set_response_type_url(::std::string&& value) {
+
+ response_type_url_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.response_type_url)
+}
+#endif
+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<const char*>(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 {
@@ -1578,15 +1595,15 @@ void Method::clear_response_type_url() {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.response_type_url)
}
-// optional bool response_streaming = 5;
+// bool response_streaming = 5;
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)
@@ -1622,15 +1639,15 @@ Method::options() const {
return options_;
}
-// optional .google.protobuf.Syntax syntax = 7;
+// .google.protobuf.Syntax syntax = 7;
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)
@@ -1647,28 +1664,32 @@ const int Mixin::kRootFieldNumber;
Mixin::Mixin()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fapi_2eproto::InitDefaults();
+ }
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);
+ _internal_metadata_(NULL),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.name().size() > 0) {
+ name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
+ }
+ root_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.root().size() > 0) {
+ root_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.root_);
+ }
// @@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() {
@@ -1679,8 +1700,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 {
@@ -1689,17 +1708,15 @@ void Mixin::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Mixin::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Mixin_descriptor_;
+ protobuf_google_2fprotobuf_2fapi_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[2].descriptor;
}
const Mixin& Mixin::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fapi_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-Mixin* Mixin::default_instance_ = NULL;
-
Mixin* Mixin::New(::google::protobuf::Arena* arena) const {
Mixin* n = new Mixin;
if (arena != NULL) {
@@ -1720,13 +1737,14 @@ bool Mixin::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Mixin)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional string name = 1;
+ // string name = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -1736,14 +1754,13 @@ bool Mixin::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_root;
break;
}
- // optional string root = 2;
+ // string root = 2;
case 2: {
- if (tag == 18) {
- parse_root:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_root()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -1753,7 +1770,6 @@ bool Mixin::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -1781,7 +1797,7 @@ failure:
void Mixin::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.Mixin)
- // optional string name = 1;
+ // string name = 1;
if (this->name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->name().data(), this->name().length(),
@@ -1791,7 +1807,7 @@ void Mixin::SerializeWithCachedSizes(
1, this->name(), output);
}
- // optional string root = 2;
+ // string root = 2;
if (this->root().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->root().data(), this->root().length(),
@@ -1806,8 +1822,9 @@ void Mixin::SerializeWithCachedSizes(
::google::protobuf::uint8* Mixin::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Mixin)
- // optional string name = 1;
+ // string name = 1;
if (this->name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->name().data(), this->name().length(),
@@ -1818,7 +1835,7 @@ void Mixin::SerializeWithCachedSizes(
1, this->name(), target);
}
- // optional string root = 2;
+ // string root = 2;
if (this->root().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->root().data(), this->root().length(),
@@ -1833,36 +1850,35 @@ 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;
+ // string name = 1;
if (this->name().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->name());
}
- // optional string root = 2;
+ // string root = 2;
if (this->root().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const Mixin* source =
::google::protobuf::internal::DynamicCastToGenerated<const Mixin>(
&from);
if (source == NULL) {
@@ -1876,9 +1892,8 @@ void Mixin::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
if (from.name().size() > 0) {
name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
@@ -1904,7 +1919,6 @@ void Mixin::CopyFrom(const Mixin& from) {
}
bool Mixin::IsInitialized() const {
-
return true;
}
@@ -1915,56 +1929,60 @@ void Mixin::Swap(Mixin* other) {
void Mixin::InternalSwap(Mixin* other) {
name_.Swap(&other->name_);
root_.Swap(&other->root_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Mixin::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = Mixin_descriptor_;
- metadata.reflection = Mixin_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fapi_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fapi_2eproto::file_level_metadata[2];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// Mixin
-// optional string name = 1;
+// string name = 1;
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());
+ return name_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void Mixin::set_name(::std::string&& value) {
+
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Mixin.name)
+}
+#endif
+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<const char*>(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 {
@@ -1974,41 +1992,49 @@ void Mixin::clear_name() {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.name)
}
-// optional string root = 2;
+// string root = 2;
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());
+ return root_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void Mixin::set_root(::std::string&& value) {
+
+ root_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Mixin.root)
+}
+#endif
+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<const char*>(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/third_party/protobuf/3.0.0/src/google/protobuf/api.pb.h b/third_party/protobuf/src/google/protobuf/api.pb.h
index c9ec923a83..2eb571e613 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/api.pb.h
+++ b/third_party/protobuf/src/google/protobuf/api.pb.h
@@ -8,40 +8,74 @@
#include <google/protobuf/stubs/common.h>
-#if GOOGLE_PROTOBUF_VERSION < 3000000
+#if GOOGLE_PROTOBUF_VERSION < 3002000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
-#if 3000000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
+#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
+#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/metadata.h>
#include <google/protobuf/message.h>
-#include <google/protobuf/repeated_field.h>
-#include <google/protobuf/extension_set.h>
+#include <google/protobuf/repeated_field.h> // IWYU pragma: export
+#include <google/protobuf/extension_set.h> // IWYU pragma: export
#include <google/protobuf/unknown_field_set.h>
#include <google/protobuf/source_context.pb.h>
#include <google/protobuf/type.pb.h>
// @@protoc_insertion_point(includes)
-
namespace google {
namespace protobuf {
-
-// Internal implementation detail -- do not call these.
-void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto();
-void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto();
-void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto();
-
class Api;
+class ApiDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern ApiDefaultTypeInternal _Api_default_instance_;
+class Enum;
+class EnumDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern EnumDefaultTypeInternal _Enum_default_instance_;
+class EnumValue;
+class EnumValueDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern EnumValueDefaultTypeInternal _EnumValue_default_instance_;
+class Field;
+class FieldDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern FieldDefaultTypeInternal _Field_default_instance_;
class Method;
+class MethodDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern MethodDefaultTypeInternal _Method_default_instance_;
class Mixin;
+class MixinDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern MixinDefaultTypeInternal _Mixin_default_instance_;
+class Option;
+class OptionDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern OptionDefaultTypeInternal _Option_default_instance_;
+class SourceContext;
+class SourceContextDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern SourceContextDefaultTypeInternal _SourceContext_default_instance_;
+class Type;
+class TypeDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern TypeDefaultTypeInternal _Type_default_instance_;
+} // namespace protobuf
+} // namespace google
+
+namespace google {
+namespace protobuf {
+
+namespace protobuf_google_2fprotobuf_2fapi_2eproto {
+// Internal implementation detail -- do not call these.
+struct LIBPROTOBUF_EXPORT TableStruct {
+ static const ::google::protobuf::uint32 offsets[];
+ static void InitDefaultsImpl();
+ static void Shutdown();
+};
+void LIBPROTOBUF_EXPORT AddDescriptors();
+void LIBPROTOBUF_EXPORT InitDefaults();
+} // namespace protobuf_google_2fprotobuf_2fapi_2eproto
// ===================================================================
@@ -60,62 +94,58 @@ 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 reinterpret_cast<const Api*>(
+ &_Api_default_instance_);
+ }
+
void Swap(Api* other);
// implements Message ----------------------------------------------
- inline Api* New() const { return New(NULL); }
+ inline Api* New() const PROTOBUF_FINAL { return New(NULL); }
- Api* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ Api* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Api& from);
void MergeFrom(const Api& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Api* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional string name = 1;
- void clear_name();
- static const int kNameFieldNumber = 1;
- const ::std::string& name() const;
- void set_name(const ::std::string& value);
- void set_name(const char* value);
- void set_name(const char* value, size_t size);
- ::std::string* mutable_name();
- ::std::string* release_name();
- void set_allocated_name(::std::string* name);
-
// repeated .google.protobuf.Method methods = 2;
int methods_size() const;
void clear_methods();
@@ -140,18 +170,47 @@ class LIBPROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_in
const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >&
options() const;
- // optional string version = 4;
+ // repeated .google.protobuf.Mixin mixins = 6;
+ int mixins_size() const;
+ void clear_mixins();
+ static const int kMixinsFieldNumber = 6;
+ const ::google::protobuf::Mixin& mixins(int index) const;
+ ::google::protobuf::Mixin* mutable_mixins(int index);
+ ::google::protobuf::Mixin* add_mixins();
+ ::google::protobuf::RepeatedPtrField< ::google::protobuf::Mixin >*
+ mutable_mixins();
+ const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Mixin >&
+ mixins() const;
+
+ // string name = 1;
+ void clear_name();
+ static const int kNameFieldNumber = 1;
+ const ::std::string& name() const;
+ void set_name(const ::std::string& value);
+ #if LANG_CXX11
+ void set_name(::std::string&& value);
+ #endif
+ void set_name(const char* value);
+ void set_name(const char* value, size_t size);
+ ::std::string* mutable_name();
+ ::std::string* release_name();
+ void set_allocated_name(::std::string* name);
+
+ // string version = 4;
void clear_version();
static const int kVersionFieldNumber = 4;
const ::std::string& version() const;
void set_version(const ::std::string& value);
+ #if LANG_CXX11
+ void set_version(::std::string&& value);
+ #endif
void set_version(const char* value);
void set_version(const char* value, size_t size);
::std::string* mutable_version();
::std::string* release_version();
void set_allocated_version(::std::string* version);
- // optional .google.protobuf.SourceContext source_context = 5;
+ // .google.protobuf.SourceContext source_context = 5;
bool has_source_context() const;
void clear_source_context();
static const int kSourceContextFieldNumber = 5;
@@ -160,19 +219,7 @@ class LIBPROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_in
::google::protobuf::SourceContext* release_source_context();
void set_allocated_source_context(::google::protobuf::SourceContext* source_context);
- // repeated .google.protobuf.Mixin mixins = 6;
- int mixins_size() const;
- void clear_mixins();
- static const int kMixinsFieldNumber = 6;
- const ::google::protobuf::Mixin& mixins(int index) const;
- ::google::protobuf::Mixin* mutable_mixins(int index);
- ::google::protobuf::Mixin* add_mixins();
- ::google::protobuf::RepeatedPtrField< ::google::protobuf::Mixin >*
- mutable_mixins();
- const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Mixin >&
- mixins() const;
-
- // optional .google.protobuf.Syntax syntax = 7;
+ // .google.protobuf.Syntax syntax = 7;
void clear_syntax();
static const int kSyntaxFieldNumber = 7;
::google::protobuf::Syntax syntax() const;
@@ -182,21 +229,15 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto();
-
- void InitAsDefaultInstance();
- static Api* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fapi_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -215,109 +256,125 @@ 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 reinterpret_cast<const Method*>(
+ &_Method_default_instance_);
+ }
+
void Swap(Method* other);
// implements Message ----------------------------------------------
- inline Method* New() const { return New(NULL); }
+ inline Method* New() const PROTOBUF_FINAL { return New(NULL); }
- Method* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ Method* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Method& from);
void MergeFrom(const Method& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Method* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional string name = 1;
+ // repeated .google.protobuf.Option options = 6;
+ int options_size() const;
+ void clear_options();
+ static const int kOptionsFieldNumber = 6;
+ const ::google::protobuf::Option& options(int index) const;
+ ::google::protobuf::Option* mutable_options(int index);
+ ::google::protobuf::Option* add_options();
+ ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >*
+ mutable_options();
+ const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >&
+ options() const;
+
+ // string name = 1;
void clear_name();
static const int kNameFieldNumber = 1;
const ::std::string& name() const;
void set_name(const ::std::string& value);
+ #if LANG_CXX11
+ void set_name(::std::string&& value);
+ #endif
void set_name(const char* value);
void set_name(const char* value, size_t size);
::std::string* mutable_name();
::std::string* release_name();
void set_allocated_name(::std::string* name);
- // optional string request_type_url = 2;
+ // string request_type_url = 2;
void clear_request_type_url();
static const int kRequestTypeUrlFieldNumber = 2;
const ::std::string& request_type_url() const;
void set_request_type_url(const ::std::string& value);
+ #if LANG_CXX11
+ void set_request_type_url(::std::string&& value);
+ #endif
void set_request_type_url(const char* value);
void set_request_type_url(const char* value, size_t size);
::std::string* mutable_request_type_url();
::std::string* release_request_type_url();
void set_allocated_request_type_url(::std::string* request_type_url);
- // optional bool request_streaming = 3;
- void clear_request_streaming();
- static const int kRequestStreamingFieldNumber = 3;
- bool request_streaming() const;
- void set_request_streaming(bool value);
-
- // optional string response_type_url = 4;
+ // string response_type_url = 4;
void clear_response_type_url();
static const int kResponseTypeUrlFieldNumber = 4;
const ::std::string& response_type_url() const;
void set_response_type_url(const ::std::string& value);
+ #if LANG_CXX11
+ void set_response_type_url(::std::string&& value);
+ #endif
void set_response_type_url(const char* value);
void set_response_type_url(const char* value, size_t size);
::std::string* mutable_response_type_url();
::std::string* release_response_type_url();
void set_allocated_response_type_url(::std::string* response_type_url);
- // optional bool response_streaming = 5;
+ // bool request_streaming = 3;
+ void clear_request_streaming();
+ static const int kRequestStreamingFieldNumber = 3;
+ bool request_streaming() const;
+ void set_request_streaming(bool value);
+
+ // bool response_streaming = 5;
void clear_response_streaming();
static const int kResponseStreamingFieldNumber = 5;
bool response_streaming() const;
void set_response_streaming(bool value);
- // repeated .google.protobuf.Option options = 6;
- int options_size() const;
- void clear_options();
- static const int kOptionsFieldNumber = 6;
- const ::google::protobuf::Option& options(int index) const;
- ::google::protobuf::Option* mutable_options(int index);
- ::google::protobuf::Option* add_options();
- ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >*
- mutable_options();
- const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >&
- options() const;
-
- // optional .google.protobuf.Syntax syntax = 7;
+ // .google.protobuf.Syntax syntax = 7;
void clear_syntax();
static const int kSyntaxFieldNumber = 7;
::google::protobuf::Syntax syntax() const;
@@ -327,21 +384,15 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto();
-
- void InitAsDefaultInstance();
- static Method* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fapi_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -360,67 +411,80 @@ 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 reinterpret_cast<const Mixin*>(
+ &_Mixin_default_instance_);
+ }
+
void Swap(Mixin* other);
// implements Message ----------------------------------------------
- inline Mixin* New() const { return New(NULL); }
+ inline Mixin* New() const PROTOBUF_FINAL { return New(NULL); }
- Mixin* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ Mixin* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Mixin& from);
void MergeFrom(const Mixin& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Mixin* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional string name = 1;
+ // string name = 1;
void clear_name();
static const int kNameFieldNumber = 1;
const ::std::string& name() const;
void set_name(const ::std::string& value);
+ #if LANG_CXX11
+ void set_name(::std::string&& value);
+ #endif
void set_name(const char* value);
void set_name(const char* value, size_t size);
::std::string* mutable_name();
::std::string* release_name();
void set_allocated_name(::std::string* name);
- // optional string root = 2;
+ // string root = 2;
void clear_root();
static const int kRootFieldNumber = 2;
const ::std::string& root() const;
void set_root(const ::std::string& value);
+ #if LANG_CXX11
+ void set_root(::std::string&& value);
+ #endif
void set_root(const char* value);
void set_root(const char* value, size_t size);
::std::string* mutable_root();
@@ -431,16 +495,10 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto();
-
- void InitAsDefaultInstance();
- static Mixin* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fapi_2eproto::TableStruct;
};
// ===================================================================
@@ -450,19 +508,27 @@ class LIBPROTOBUF_EXPORT Mixin : public ::google::protobuf::Message /* @@protoc_
#if !PROTOBUF_INLINE_NOT_IN_HEADERS
// Api
-// optional string name = 1;
+// string name = 1;
inline void Api::clear_name() {
name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& Api::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.Api.name)
- return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return name_.GetNoArena();
}
inline void Api::set_name(const ::std::string& value) {
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.Api.name)
}
+#if LANG_CXX11
+inline void Api::set_name(::std::string&& value) {
+
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Api.name)
+}
+#endif
inline void Api::set_name(const char* value) {
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -554,19 +620,27 @@ Api::options() const {
return options_;
}
-// optional string version = 4;
+// string version = 4;
inline void Api::clear_version() {
version_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& Api::version() const {
// @@protoc_insertion_point(field_get:google.protobuf.Api.version)
- return version_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return version_.GetNoArena();
}
inline void Api::set_version(const ::std::string& value) {
version_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.Api.version)
}
+#if LANG_CXX11
+inline void Api::set_version(::std::string&& value) {
+
+ version_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Api.version)
+}
+#endif
inline void Api::set_version(const char* value) {
version_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -598,9 +672,9 @@ inline void Api::set_allocated_version(::std::string* version) {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.version)
}
-// optional .google.protobuf.SourceContext source_context = 5;
+// .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 +682,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() {
@@ -666,7 +741,7 @@ Api::mixins() const {
return mixins_;
}
-// optional .google.protobuf.Syntax syntax = 7;
+// .google.protobuf.Syntax syntax = 7;
inline void Api::clear_syntax() {
syntax_ = 0;
}
@@ -684,19 +759,27 @@ inline void Api::set_syntax(::google::protobuf::Syntax value) {
// Method
-// optional string name = 1;
+// string name = 1;
inline void Method::clear_name() {
name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& Method::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.Method.name)
- return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return name_.GetNoArena();
}
inline void Method::set_name(const ::std::string& value) {
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.Method.name)
}
+#if LANG_CXX11
+inline void Method::set_name(::std::string&& value) {
+
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.name)
+}
+#endif
inline void Method::set_name(const char* value) {
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -728,19 +811,27 @@ inline void Method::set_allocated_name(::std::string* name) {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.name)
}
-// optional string request_type_url = 2;
+// string request_type_url = 2;
inline void Method::clear_request_type_url() {
request_type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline 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());
+ return request_type_url_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void Method::set_request_type_url(::std::string&& value) {
+
+ request_type_url_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.request_type_url)
+}
+#endif
inline void Method::set_request_type_url(const char* value) {
request_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -772,7 +863,7 @@ inline void Method::set_allocated_request_type_url(::std::string* request_type_u
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.request_type_url)
}
-// optional bool request_streaming = 3;
+// bool request_streaming = 3;
inline void Method::clear_request_streaming() {
request_streaming_ = false;
}
@@ -786,19 +877,27 @@ inline void Method::set_request_streaming(bool value) {
// @@protoc_insertion_point(field_set:google.protobuf.Method.request_streaming)
}
-// optional string response_type_url = 4;
+// string response_type_url = 4;
inline void Method::clear_response_type_url() {
response_type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline 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());
+ return response_type_url_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void Method::set_response_type_url(::std::string&& value) {
+
+ response_type_url_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Method.response_type_url)
+}
+#endif
inline void Method::set_response_type_url(const char* value) {
response_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -830,7 +929,7 @@ inline void Method::set_allocated_response_type_url(::std::string* response_type
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.response_type_url)
}
-// optional bool response_streaming = 5;
+// bool response_streaming = 5;
inline void Method::clear_response_streaming() {
response_streaming_ = false;
}
@@ -874,7 +973,7 @@ Method::options() const {
return options_;
}
-// optional .google.protobuf.Syntax syntax = 7;
+// .google.protobuf.Syntax syntax = 7;
inline void Method::clear_syntax() {
syntax_ = 0;
}
@@ -892,19 +991,27 @@ inline void Method::set_syntax(::google::protobuf::Syntax value) {
// Mixin
-// optional string name = 1;
+// string name = 1;
inline void Mixin::clear_name() {
name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& Mixin::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.Mixin.name)
- return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return name_.GetNoArena();
}
inline void Mixin::set_name(const ::std::string& value) {
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.Mixin.name)
}
+#if LANG_CXX11
+inline void Mixin::set_name(::std::string&& value) {
+
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Mixin.name)
+}
+#endif
inline void Mixin::set_name(const char* value) {
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -936,19 +1043,27 @@ inline void Mixin::set_allocated_name(::std::string* name) {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.name)
}
-// optional string root = 2;
+// string root = 2;
inline void Mixin::clear_root() {
root_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline const ::std::string& Mixin::root() const {
// @@protoc_insertion_point(field_get:google.protobuf.Mixin.root)
- return root_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return root_.GetNoArena();
}
inline void Mixin::set_root(const ::std::string& value) {
root_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
// @@protoc_insertion_point(field_set:google.protobuf.Mixin.root)
}
+#if LANG_CXX11
+inline void Mixin::set_root(::std::string&& value) {
+
+ root_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Mixin.root)
+}
+#endif
inline void Mixin::set_root(const char* value) {
root_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -988,6 +1103,7 @@ inline void Mixin::set_allocated_root(::std::string* root) {
// @@protoc_insertion_point(namespace_scope)
+
} // namespace protobuf
} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/api.proto b/third_party/protobuf/src/google/protobuf/api.proto
index dbe87b8f54..7c30e8b7ad 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/api.proto
+++ b/third_party/protobuf/src/google/protobuf/api.proto
@@ -39,8 +39,8 @@ 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";
+option go_package = "google.golang.org/genproto/protobuf/api;api";
// Api is a light-weight descriptor for a protocol buffer service.
message Api {
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/arena.cc b/third_party/protobuf/src/google/protobuf/arena.cc
index 78e20946c3..16cf8951cf 100755
--- a/third_party/protobuf/3.0.0/src/google/protobuf/arena.cc
+++ b/third_party/protobuf/src/google/protobuf/arena.cc
@@ -30,10 +30,13 @@
#include <google/protobuf/arena.h>
+#include <algorithm>
+#include <limits>
+
#ifdef ADDRESS_SANITIZER
#include <sanitizer/asan_interface.h>
-#endif
+#endif // ADDRESS_SANITIZER
namespace google {
namespace protobuf {
@@ -59,6 +62,7 @@ void Arena::Init() {
lifecycle_id_ = lifecycle_id_generator_.GetNext();
blocks_ = 0;
hint_ = 0;
+ space_allocated_ = 0;
owns_first_block_ = true;
cleanup_list_ = 0;
@@ -125,10 +129,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<size_t>::max() - kHeaderSize);
+ size = std::max(size, kHeaderSize + n);
Block* b = reinterpret_cast<Block*>(options_.block_alloc(size));
b->pos = kHeaderSize + n;
@@ -139,7 +142,7 @@ Arena::Block* Arena::NewBlock(void* me, Block* my_last_block, size_t n,
// malloc but it's not yet usable until we return it as part of an allocation.
ASAN_POISON_MEMORY_REGION(
reinterpret_cast<char*>(b) + b->pos, b->size - b->pos);
-#endif
+#endif // ADDRESS_SANITIZER
return b;
}
@@ -155,6 +158,7 @@ void Arena::AddBlockInternal(Block* b) {
// Direct future allocations to this block.
google::protobuf::internal::Release_Store(&hint_, reinterpret_cast<google::protobuf::internal::AtomicWord>(b));
}
+ space_allocated_ += b->size;
}
void Arena::AddListNode(void* elem, void (*cleanup)(void*)) {
@@ -203,7 +207,7 @@ void* Arena::AllocFromBlock(Block* b, size_t n) {
b->pos = p + n;
#ifdef ADDRESS_SANITIZER
ASAN_UNPOISON_MEMORY_REGION(reinterpret_cast<char*>(b) + p, n);
-#endif
+#endif // ADDRESS_SANITIZER
return reinterpret_cast<char*>(b) + p;
}
@@ -223,13 +227,8 @@ void* Arena::SlowAlloc(size_t n) {
}
uint64 Arena::SpaceAllocated() const {
- uint64 space_allocated = 0;
- Block* b = reinterpret_cast<Block*>(google::protobuf::internal::NoBarrier_Load(&blocks_));
- while (b != NULL) {
- space_allocated += (b->size);
- b = b->next;
- }
- return space_allocated;
+ MutexLock l(&blocks_lock_);
+ return space_allocated_;
}
uint64 Arena::SpaceUsed() const {
@@ -242,17 +241,8 @@ uint64 Arena::SpaceUsed() const {
return space_used;
}
-pair<uint64, uint64> Arena::SpaceAllocatedAndUsed() const {
- uint64 allocated = 0;
- uint64 used = 0;
-
- Block* b = reinterpret_cast<Block*>(google::protobuf::internal::NoBarrier_Load(&blocks_));
- while (b != NULL) {
- allocated += b->size;
- used += (b->pos - kHeaderSize);
- b = b->next;
- }
- return std::make_pair(allocated, used);
+std::pair<uint64, uint64> Arena::SpaceAllocatedAndUsed() const {
+ return std::make_pair(SpaceAllocated(), SpaceUsed());
}
uint64 Arena::FreeBlocks() {
@@ -263,9 +253,19 @@ uint64 Arena::FreeBlocks() {
space_allocated += (b->size);
Block* next = b->next;
if (next != NULL) {
+#ifdef ADDRESS_SANITIZER
+ // This memory was provided by the underlying allocator as unpoisoned, so
+ // return it in an unpoisoned state.
+ ASAN_UNPOISON_MEMORY_REGION(reinterpret_cast<char*>(b), b->size);
+#endif // ADDRESS_SANITIZER
options_.block_dealloc(b, b->size);
} else {
if (owns_first_block_) {
+#ifdef ADDRESS_SANITIZER
+ // This memory was provided by the underlying allocator as unpoisoned,
+ // so return it in an unpoisoned state.
+ ASAN_UNPOISON_MEMORY_REGION(reinterpret_cast<char*>(b), b->size);
+#endif // ADDRESS_SANITIZER
options_.block_dealloc(b, b->size);
} else {
// User passed in the first block, skip free'ing the memory.
@@ -276,6 +276,7 @@ uint64 Arena::FreeBlocks() {
}
blocks_ = 0;
hint_ = 0;
+ space_allocated_ = 0;
if (!owns_first_block_) {
// Make the first block that was passed in through ArenaOptions
// available for reuse.
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/arena.h b/third_party/protobuf/src/google/protobuf/arena.h
index 58b1e126d5..05e05ebc19 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/arena.h
+++ b/third_party/protobuf/src/google/protobuf/arena.h
@@ -28,6 +28,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// This file defines an Arena allocator for better allocation performance.
+
#ifndef GOOGLE_PROTOBUF_ARENA_H__
#define GOOGLE_PROTOBUF_ARENA_H__
@@ -77,8 +79,13 @@ template<typename T> void arena_destruct_object(void* object) {
template<typename T> void arena_delete_object(void* object) {
delete reinterpret_cast<T*>(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
+ (void)size;
+ ::operator delete(object);
+#endif
}
} // namespace internal
@@ -142,7 +149,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),
@@ -211,12 +218,10 @@ struct ArenaOptions {
//
// This protocol is implemented by all arena-enabled proto2 message classes as
// well as RepeatedPtrField.
-
-#if __cplusplus >= 201103L
-class LIBPROTOBUF_EXPORT Arena final {
-#else
+//
+// Do NOT subclass Arena. This class will be marked as final when C++11 is
+// enabled.
class LIBPROTOBUF_EXPORT Arena {
-#endif
public:
// Arena constructor taking custom options. See ArenaOptions below for
// descriptions of the options available.
@@ -317,6 +322,17 @@ class LIBPROTOBUF_EXPORT Arena {
arg);
}
}
+#if LANG_CXX11
+ template <typename T, typename Arg> GOOGLE_ATTRIBUTE_ALWAYS_INLINE
+ static T* Create(::google::protobuf::Arena* arena, Arg&& arg) {
+ if (arena == NULL) {
+ return new T(std::move(arg));
+ } else {
+ return arena->CreateInternal<T>(google::protobuf::internal::has_trivial_destructor<T>::value,
+ std::move(arg));
+ }
+ }
+#endif
// Version of the above with two constructor arguments for the created object.
template <typename T, typename Arg1, typename Arg2> GOOGLE_ATTRIBUTE_ALWAYS_INLINE
@@ -444,17 +460,20 @@ class LIBPROTOBUF_EXPORT Arena {
}
}
- // Returns the total space used by the arena, which is the sums of the sizes
- // of the underlying blocks. The total space used may not include the new
- // blocks that are allocated by this arena from other threads concurrently
- // with the call to this method.
- GOOGLE_ATTRIBUTE_NOINLINE uint64 SpaceAllocated() const;
- // As above, but does not include any free space in underlying blocks.
+ // Returns the total space allocated by the arena, which is the sum of the
+ // sizes of the underlying blocks. This method is relatively fast; a counter
+ // is kept as blocks are allocated.
+ uint64 SpaceAllocated() const;
+ // Returns the total space used by the arena. Similar to SpaceAllocated but
+ // does not include free space and block overhead. The total space returned
+ // may not include space used by other threads executing concurrently with
+ // the call to this method.
GOOGLE_ATTRIBUTE_NOINLINE uint64 SpaceUsed() const;
-
+ // DEPRECATED. Please use SpaceAllocated() and SpaceUsed().
+ //
// Combines SpaceAllocated and SpaceUsed. Returns a pair of
// <space_allocated, space_used>.
- GOOGLE_ATTRIBUTE_NOINLINE pair<uint64, uint64> SpaceAllocatedAndUsed() const;
+ GOOGLE_ATTRIBUTE_NOINLINE std::pair<uint64, uint64> SpaceAllocatedAndUsed() const;
// Frees all storage allocated by this arena after calling destructors
// registered with OwnDestructor() and freeing objects registered with Own().
@@ -608,6 +627,7 @@ class LIBPROTOBUF_EXPORT Arena {
const T>(static_cast<const T*>(0))) == sizeof(char) ||
google::protobuf::internal::has_trivial_destructor<T>::value> {};
+ private:
// CreateMessage<T> 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
@@ -653,6 +673,18 @@ class LIBPROTOBUF_EXPORT Arena {
return t;
}
+#if LANG_CXX11
+ template <typename T, typename Arg> GOOGLE_ATTRIBUTE_ALWAYS_INLINE
+ T* CreateInternal(bool skip_explicit_ownership, Arg&& arg) {
+ T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) T(
+ std::move(arg));
+ if (!skip_explicit_ownership) {
+ AddListNode(t, &internal::arena_destruct_object<T>);
+ }
+ return t;
+ }
+#endif
+
template <typename T, typename Arg1, typename Arg2> GOOGLE_ATTRIBUTE_ALWAYS_INLINE
T* CreateInternal(
bool skip_explicit_ownership, const Arg1& arg1, const Arg2& arg2) {
@@ -878,8 +910,9 @@ class LIBPROTOBUF_EXPORT Arena {
int64 lifecycle_id_; // Unique for each arena. Changes on Reset().
- google::protobuf::internal::AtomicWord blocks_; // Head of linked list of all allocated blocks
- google::protobuf::internal::AtomicWord hint_; // Fast thread-local block access
+ google::protobuf::internal::AtomicWord blocks_; // Head of linked list of all allocated blocks
+ google::protobuf::internal::AtomicWord hint_; // Fast thread-local block access
+ uint64 space_allocated_; // Sum of sizes of all allocated blocks.
// Node contains the ptr of the object to be cleaned up and the associated
// cleanup function ptr.
@@ -893,7 +926,7 @@ class LIBPROTOBUF_EXPORT Arena {
// ptrs and cleanup methods.
bool owns_first_block_; // Indicates that arena owns the first block
- Mutex blocks_lock_;
+ mutable Mutex blocks_lock_;
void AddBlock(Block* b);
// Access must be synchronized, either by blocks_lock_ or by being called from
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/arena_test_util.cc b/third_party/protobuf/src/google/protobuf/arena_test_util.cc
index df9c5bd6b4..df9c5bd6b4 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/arena_test_util.cc
+++ b/third_party/protobuf/src/google/protobuf/arena_test_util.cc
diff --git a/third_party/protobuf/src/google/protobuf/arena_test_util.h b/third_party/protobuf/src/google/protobuf/arena_test_util.h
new file mode 100644
index 0000000000..8c9f7698c5
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/arena_test_util.h
@@ -0,0 +1,91 @@
+// 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_ARENA_TEST_UTIL_H__
+#define GOOGLE_PROTOBUF_ARENA_TEST_UTIL_H__
+
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/arena.h>
+
+namespace google {
+namespace protobuf {
+
+template <typename T, bool use_arena>
+void TestParseCorruptedString(const T& message) {
+ int success_count = 0;
+ string s = message.SerializeAsString();
+ const int kMaxIters = 900;
+ const int stride = s.size() <= kMaxIters ? 1 : s.size() / kMaxIters;
+ const int start = stride == 1 || use_arena ? 0 : (stride + 1) / 2;
+ for (int i = start; i < s.size(); i += stride) {
+ for (int c = 1 + (i % 17); c < 256; c += 2 * c + (i & 3)) {
+ s[i] ^= c;
+ google::protobuf::Arena arena;
+ T* message =
+ google::protobuf::Arena::CreateMessage<T>(use_arena ? &arena : NULL);
+ if (message->ParseFromString(s)) {
+ ++success_count;
+ }
+ if (!use_arena) {
+ delete message;
+ }
+ s[i] ^= c; // Restore s to its original state.
+ }
+ }
+ // This next line is a low bar. But getting through the test without crashing
+ // due to use-after-free or other bugs is a big part of what we're checking.
+ GOOGLE_CHECK_GT(success_count, 0);
+}
+
+namespace internal {
+
+class NoHeapChecker {
+ public:
+ NoHeapChecker() {
+ capture_alloc.Hook();
+ }
+ ~NoHeapChecker();
+ private:
+ class NewDeleteCapture {
+ public:
+ // TOOD(xiaofeng): Implement this for opensource protobuf.
+ void Hook() {}
+ void Unhook() {}
+ int alloc_count() { return 0; }
+ int free_count() { return 0; }
+ } capture_alloc;
+};
+
+} // namespace internal
+} // namespace protobuf
+
+} // namespace google
+#endif // GOOGLE_PROTOBUF_ARENA_TEST_UTIL_H__
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/arena_unittest.cc b/third_party/protobuf/src/google/protobuf/arena_unittest.cc
index 5f33e93987..4f9571dbff 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/arena_unittest.cc
+++ b/third_party/protobuf/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<TestAllTypes>::type::value);
EXPECT_TRUE(Arena::is_arena_constructable<const TestAllTypes>::type::value);
@@ -251,7 +249,7 @@ TEST(ArenaTest, Parsing) {
arena_message->ParseFromString(original.SerializeAsString());
TestUtil::ExpectAllFieldsSet(*arena_message);
- // Test that string fields have null terminator bytes (earlier bug).
+ // Test that string fields have nul terminator bytes (earlier bug).
EXPECT_EQ(strlen(original.optional_string().c_str()),
strlen(arena_message->optional_string().c_str()));
}
@@ -893,6 +891,24 @@ TEST(ArenaTest, UnsafeArenaRelease) {
delete s;
}
+TEST(ArenaTest, OneofMerge) {
+ Arena arena;
+ TestAllTypes* message0 = Arena::CreateMessage<TestAllTypes>(&arena);
+ TestAllTypes* message1 = Arena::CreateMessage<TestAllTypes>(&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<TestAllTypes>(&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.
@@ -1144,6 +1154,13 @@ TEST(ArenaTest, NoHeapAllocationsTest) {
arena.Reset();
}
+TEST(ArenaTest, ParseCorruptedString) {
+ TestAllTypes message;
+ TestUtil::SetAllFields(&message);
+ TestParseCorruptedString<TestAllTypes, true>(message);
+ TestParseCorruptedString<TestAllTypes, false>(message);
+}
+
#ifndef GOOGLE_PROTOBUF_NO_RTTI
// Test construction on an arena via generic MessageLite interface. We should be
// able to successfully deserialize on the arena without incurring heap
@@ -1196,9 +1213,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 +1264,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<int64>(&arena) = 42;
+ EXPECT_GE(arena.SpaceAllocated(), 8);
+ EXPECT_EQ(8, arena.SpaceUsed());
+
+ *::google::protobuf::Arena::Create<int64>(&arena) = 42;
+ EXPECT_GE(arena.SpaceAllocated(), 16);
+ EXPECT_EQ(16, arena.SpaceUsed());
+ }
+}
+
TEST(ArenaTest, GetArenaShouldReturnTheArenaForArenaAllocatedMessages) {
::google::protobuf::Arena arena;
ArenaMessage* message = Arena::CreateMessage<ArenaMessage>(&arena);
@@ -1349,5 +1380,7 @@ TEST(ArenaTest, ArenaHooksSanity) {
EXPECT_EQ(1, ArenaHooksTestUtil::num_destruct);
}
+
+} // namespace
} // namespace protobuf
} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/arenastring.cc b/third_party/protobuf/src/google/protobuf/arenastring.cc
index cce61d74de..f10732c0c4 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/arenastring.cc
+++ b/third_party/protobuf/src/google/protobuf/arenastring.cc
@@ -44,7 +44,7 @@ void ArenaStringPtr::AssignWithDefault(const ::std::string* default_value,
const ::std::string* other = *value.UnsafeRawStringPointer();
// If the pointers are the same then do nothing.
if (me != other) {
- SetNoArena(default_value, value.GetNoArena(default_value));
+ SetNoArena(default_value, value.GetNoArena());
}
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/arenastring.h b/third_party/protobuf/src/google/protobuf/arenastring.h
index 590ffce9ac..a7efb7529b 100755
--- a/third_party/protobuf/3.0.0/src/google/protobuf/arenastring.h
+++ b/third_party/protobuf/src/google/protobuf/arenastring.h
@@ -37,7 +37,6 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/fastmem.h>
#include <google/protobuf/arena.h>
-#include <google/protobuf/generated_message_util.h>
@@ -64,9 +63,7 @@ struct LIBPROTOBUF_EXPORT ArenaStringPtr {
}
// Basic accessors.
- inline const ::std::string& Get(const ::std::string* /* default_value */) const {
- return *ptr_;
- }
+ inline const ::std::string& Get() const { return *ptr_; }
inline ::std::string* Mutable(const ::std::string* default_value,
::google::protobuf::Arena* arena) {
@@ -150,13 +147,12 @@ struct LIBPROTOBUF_EXPORT ArenaStringPtr {
std::swap(ptr_, other->ptr_);
}
- // Frees storage (if not on an arena) and sets field to default value.
+ // Frees storage (if not on an arena).
inline void Destroy(const ::std::string* default_value,
::google::protobuf::Arena* arena) {
if (arena == NULL && ptr_ != default_value) {
delete ptr_;
}
- ptr_ = const_cast< ::std::string* >(default_value);
}
// Clears content, but keeps allocated string if arena != NULL, to avoid the
@@ -214,11 +210,19 @@ struct LIBPROTOBUF_EXPORT ArenaStringPtr {
}
}
+#if LANG_CXX11
+ void SetNoArena(const ::std::string* default_value, ::std::string&& value) {
+ if (IsDefault(default_value)) {
+ ptr_ = new ::std::string(std::move(value));
+ } else {
+ *ptr_ = std::move(value);
+ }
+ }
+#endif
+
void AssignWithDefault(const ::std::string* default_value, ArenaStringPtr value);
- inline const ::std::string& GetNoArena(const ::std::string* /* default_value */) const {
- return *ptr_;
- }
+ inline const ::std::string& GetNoArena() const { return *ptr_; }
inline ::std::string* MutableNoArena(const ::std::string* default_value) {
if (ptr_ == default_value) {
@@ -253,7 +257,6 @@ struct LIBPROTOBUF_EXPORT ArenaStringPtr {
if (ptr_ != default_value) {
delete ptr_;
}
- ptr_ = NULL;
}
inline void ClearToEmptyNoArena(const ::std::string* default_value) {
@@ -281,27 +284,24 @@ struct LIBPROTOBUF_EXPORT ArenaStringPtr {
return &ptr_;
}
+ inline bool IsDefault(const ::std::string* default_value) const {
+ return ptr_ == default_value;
+ }
+
private:
::std::string* ptr_;
GOOGLE_ATTRIBUTE_NOINLINE void CreateInstance(::google::protobuf::Arena* arena,
const ::std::string* initial_value) {
- // Assumes ptr_ is not NULL.
- if (initial_value != NULL) {
- ptr_ = new ::std::string(*initial_value);
- } else {
- ptr_ = new ::std::string();
- }
+ GOOGLE_DCHECK(initial_value != NULL);
+ ptr_ = new ::std::string(*initial_value);
if (arena != NULL) {
arena->Own(ptr_);
}
}
GOOGLE_ATTRIBUTE_NOINLINE void CreateInstanceNoArena(const ::std::string* initial_value) {
- if (initial_value != NULL) {
- ptr_ = new ::std::string(*initial_value);
- } else {
- ptr_ = new ::std::string();
- }
+ GOOGLE_DCHECK(initial_value != NULL);
+ ptr_ = new ::std::string(*initial_value);
}
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/arenastring_unittest.cc b/third_party/protobuf/src/google/protobuf/arenastring_unittest.cc
index ea405d7d3e..e5afe42d08 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/arenastring_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/arenastring_unittest.cc
@@ -59,11 +59,11 @@ TEST(ArenaStringPtrTest, ArenaStringPtrOnHeap) {
ArenaStringPtr field;
::std::string default_value = "default";
field.UnsafeSetDefault(&default_value);
- EXPECT_EQ(string("default"), field.Get(&default_value));
+ EXPECT_EQ(string("default"), field.Get());
field.Set(&default_value, WrapString("Test short"), NULL);
- EXPECT_EQ(string("Test short"), field.Get(&default_value));
+ EXPECT_EQ(string("Test short"), field.Get());
field.Set(&default_value, WrapString("Test long long long long value"), NULL);
- EXPECT_EQ(string("Test long long long long value"), field.Get(&default_value));
+ EXPECT_EQ(string("Test long long long long value"), field.Get());
field.Set(&default_value, string(""), NULL);
field.Destroy(&default_value, NULL);
@@ -71,11 +71,11 @@ TEST(ArenaStringPtrTest, ArenaStringPtrOnHeap) {
field2.UnsafeSetDefault(&default_value);
::std::string* mut = field2.Mutable(&default_value, NULL);
EXPECT_EQ(mut, field2.Mutable(&default_value, NULL));
- EXPECT_EQ(mut, &field2.Get(&default_value));
+ EXPECT_EQ(mut, &field2.Get());
EXPECT_NE(&default_value, mut);
EXPECT_EQ(string("default"), *mut);
*mut = "Test long long long long value"; // ensure string allocates storage
- EXPECT_EQ(string("Test long long long long value"), field2.Get(&default_value));
+ EXPECT_EQ(string("Test long long long long value"), field2.Get());
field2.Destroy(&default_value, NULL);
}
@@ -84,12 +84,11 @@ TEST(ArenaStringPtrTest, ArenaStringPtrOnArena) {
ArenaStringPtr field;
::std::string default_value = "default";
field.UnsafeSetDefault(&default_value);
- EXPECT_EQ(string("default"), field.Get(&default_value));
+ EXPECT_EQ(string("default"), field.Get());
field.Set(&default_value, WrapString("Test short"), &arena);
- EXPECT_EQ(string("Test short"), field.Get(&default_value));
+ EXPECT_EQ(string("Test short"), field.Get());
field.Set(&default_value, WrapString("Test long long long long value"), &arena);
- EXPECT_EQ(string("Test long long long long value"),
- field.Get(&default_value));
+ EXPECT_EQ(string("Test long long long long value"), field.Get());
field.Set(&default_value, string(""), &arena);
field.Destroy(&default_value, &arena);
@@ -97,12 +96,11 @@ TEST(ArenaStringPtrTest, ArenaStringPtrOnArena) {
field2.UnsafeSetDefault(&default_value);
::std::string* mut = field2.Mutable(&default_value, &arena);
EXPECT_EQ(mut, field2.Mutable(&default_value, &arena));
- EXPECT_EQ(mut, &field2.Get(&default_value));
+ EXPECT_EQ(mut, &field2.Get());
EXPECT_NE(&default_value, mut);
EXPECT_EQ(string("default"), *mut);
*mut = "Test long long long long value"; // ensure string allocates storage
- EXPECT_EQ(string("Test long long long long value"),
- field2.Get(&default_value));
+ EXPECT_EQ(string("Test long long long long value"), field2.Get());
field2.Destroy(&default_value, &arena);
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/code_generator.cc b/third_party/protobuf/src/google/protobuf/compiler/code_generator.cc
index 473eb4e6fb..11d0f33432 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/code_generator.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/code_generator.cc
@@ -34,8 +34,10 @@
#include <google/protobuf/compiler/code_generator.h>
+#include <google/protobuf/compiler/plugin.pb.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/descriptor.h>
#include <google/protobuf/stubs/strutil.h>
namespace google {
@@ -43,6 +45,33 @@ namespace protobuf {
namespace compiler {
CodeGenerator::~CodeGenerator() {}
+
+bool CodeGenerator::GenerateAll(
+ const std::vector<const FileDescriptor*>& 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*
@@ -57,18 +86,25 @@ io::ZeroCopyOutputStream* GeneratorContext::OpenForInsert(
}
void GeneratorContext::ListParsedFiles(
- vector<const FileDescriptor*>* output) {
+ std::vector<const FileDescriptor*>* output) {
GOOGLE_LOG(FATAL) << "This GeneratorContext does not support ListParsedFiles";
}
+void GeneratorContext::GetCompilerVersion(Version* version) const {
+ version->set_major(GOOGLE_PROTOBUF_VERSION / 1000000);
+ version->set_minor(GOOGLE_PROTOBUF_VERSION / 1000 % 1000);
+ version->set_patch(GOOGLE_PROTOBUF_VERSION % 1000);
+ version->set_suffix(GOOGLE_PROTOBUF_VERSION_SUFFIX);
+}
+
// Parses a set of comma-delimited name/value pairs.
void ParseGeneratorParameter(const string& text,
- vector<pair<string, string> >* output) {
- vector<string> parts = Split(text, ",", true);
+ std::vector<std::pair<string, string> >* output) {
+ std::vector<string> parts = Split(text, ",", true);
for (int i = 0; i < parts.size(); i++) {
string::size_type equals_pos = parts[i].find_first_of('=');
- pair<string, string> value;
+ std::pair<string, string> value;
if (equals_pos == string::npos) {
value.first = parts[i];
value.second = "";
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/code_generator.h b/third_party/protobuf/src/google/protobuf/compiler/code_generator.h
index b989f15132..e2b2a66167 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/code_generator.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/code_generator.h
@@ -50,6 +50,7 @@ namespace io { class ZeroCopyOutputStream; }
class FileDescriptor;
namespace compiler {
+class Version;
// Defined in this file.
class CodeGenerator;
@@ -66,11 +67,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,36 +80,27 @@ 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.
//
// Returns true if successful. Otherwise, sets *error to a description of
// the problem (e.g. "invalid parameter") and returns false.
- virtual bool GenerateAll(const vector<const FileDescriptor*>& files,
+ virtual bool GenerateAll(const std::vector<const FileDescriptor*>& files,
const string& parameter,
GeneratorContext* generator_context,
- string* error) const {
- *error = "Unimplemented GenerateAll() method.";
- return false;
- }
+ string* error) const;
- // 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; }
+ // 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);
@@ -150,7 +142,11 @@ class LIBPROTOC_EXPORT GeneratorContext {
// Returns a vector of FileDescriptors for all the files being compiled
// in this run. Useful for languages, such as Go, that treat files
// differently when compiled as a set rather than individually.
- virtual void ListParsedFiles(vector<const FileDescriptor*>* output);
+ virtual void ListParsedFiles(std::vector<const FileDescriptor*>* output);
+
+ // Retrieves the version number of the protocol compiler associated with
+ // this GeneratorContext.
+ virtual void GetCompilerVersion(Version* version) const;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratorContext);
@@ -166,8 +162,8 @@ typedef GeneratorContext OutputDirectory;
// "foo=bar,baz,qux=corge"
// parses to the pairs:
// ("foo", "bar"), ("baz", ""), ("qux", "corge")
-extern void ParseGeneratorParameter(const string&,
- vector<pair<string, string> >*);
+extern void LIBPROTOC_EXPORT ParseGeneratorParameter(const string&,
+ std::vector<std::pair<string, string> >*);
} // namespace compiler
} // namespace protobuf
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/command_line_interface.cc b/third_party/protobuf/src/google/protobuf/compiler/command_line_interface.cc
index f441cfa6bd..5066989145 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/command_line_interface.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/command_line_interface.cc
@@ -37,6 +37,12 @@
#include <stdio.h>
#include <sys/types.h>
+#ifdef major
+#undef major
+#endif
+#ifdef minor
+#undef minor
+#endif
#include <sys/stat.h>
#include <fcntl.h>
#ifdef _MSC_VER
@@ -74,7 +80,7 @@
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/io/printer.h>
-#include <google/protobuf/io/io_win32.h>
+#include <google/protobuf/stubs/io_win32.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
@@ -101,6 +107,9 @@ static const char* kPathSeparator = ";";
static const char* kPathSeparator = ":";
#endif
+static const char* kDefaultDirectDependenciesViolationMsg =
+ "File is imported but not declared in --direct_dependencies: %s";
+
// Returns true if the text looks like a Windows-style absolute path, starting
// with a drive letter. Example: "C:\foo". TODO(kenton): Share this with
// copy in importer.cc?
@@ -158,7 +167,8 @@ bool VerifyDirectoryExists(const string& path) {
// directories listed in |filename|.
bool TryCreateParentDirectory(const string& prefix, const string& filename) {
// Recursively create parent directories to the output file.
- vector<string> parts = Split(filename, "/", true);
+ std::vector<string> parts =
+ Split(filename, "/", true);
string path_so_far = prefix;
for (int i = 0; i < parts.size() - 1; i++) {
path_so_far += parts[i];
@@ -247,6 +257,12 @@ void AddDefaultProtoPaths(vector<pair<string, string> >* paths) {
return;
}
}
+
+string PluginName(const string& plugin_prefix, const string& directive) {
+ // Assuming the directive starts with "--" and ends with "_out" or "_opt",
+ // strip the "--" and "_out/_opt" and add the plugin prefix.
+ return plugin_prefix + "gen-" + directive.substr(2, directive.size() - 6);
+}
} // namespace
// A MultiFileErrorCollector that prints errors to stderr.
@@ -254,12 +270,13 @@ class CommandLineInterface::ErrorPrinter : public MultiFileErrorCollector,
public io::ErrorCollector {
public:
ErrorPrinter(ErrorFormat format, DiskSourceTree *tree = NULL)
- : format_(format), tree_(tree) {}
+ : format_(format), tree_(tree), found_errors_(false) {}
~ErrorPrinter() {}
// implements MultiFileErrorCollector ------------------------------
void AddError(const string& filename, int line, int column,
const string& message) {
+ found_errors_ = true;
AddErrorOrWarning(filename, line, column, message, "error", std::cerr);
}
@@ -277,10 +294,12 @@ class CommandLineInterface::ErrorPrinter : public MultiFileErrorCollector,
AddErrorOrWarning("input", line, column, message, "warning", std::clog);
}
+ bool FoundErrors() const { return found_errors_; }
+
private:
- void AddErrorOrWarning(
- const string& filename, int line, int column,
- const string& message, const string& type, ostream& out) {
+ void AddErrorOrWarning(const string& filename, int line, int column,
+ const string& message, const string& type,
+ std::ostream& out) {
// Print full path when running under MSVS
string dfile;
if (format_ == CommandLineInterface::ERROR_FORMAT_MSVS &&
@@ -315,6 +334,7 @@ class CommandLineInterface::ErrorPrinter : public MultiFileErrorCollector,
const ErrorFormat format_;
DiskSourceTree *tree_;
+ bool found_errors_;
};
// -------------------------------------------------------------------
@@ -323,7 +343,7 @@ class CommandLineInterface::ErrorPrinter : public MultiFileErrorCollector,
// them all to disk on demand.
class CommandLineInterface::GeneratorContextImpl : public GeneratorContext {
public:
- GeneratorContextImpl(const vector<const FileDescriptor*>& parsed_files);
+ GeneratorContextImpl(const std::vector<const FileDescriptor*>& parsed_files);
~GeneratorContextImpl();
// Write all files in the directory to disk at the given output location,
@@ -339,14 +359,14 @@ class CommandLineInterface::GeneratorContextImpl : public GeneratorContext {
void AddJarManifest();
// Get name of all output files.
- void GetOutputFilenames(vector<string>* output_filenames);
+ void GetOutputFilenames(std::vector<string>* output_filenames);
// implements GeneratorContext --------------------------------------
io::ZeroCopyOutputStream* Open(const string& filename);
io::ZeroCopyOutputStream* OpenForAppend(const string& filename);
io::ZeroCopyOutputStream* OpenForInsert(
const string& filename, const string& insertion_point);
- void ListParsedFiles(vector<const FileDescriptor*>* output) {
+ void ListParsedFiles(std::vector<const FileDescriptor*>* output) {
*output = parsed_files_;
}
@@ -355,8 +375,8 @@ class CommandLineInterface::GeneratorContextImpl : public GeneratorContext {
// map instead of hash_map so that files are written in order (good when
// writing zips).
- map<string, string*> files_;
- const vector<const FileDescriptor*>& parsed_files_;
+ std::map<string, string*> files_;
+ const std::vector<const FileDescriptor*>& parsed_files_;
bool had_error_;
};
@@ -393,7 +413,7 @@ class CommandLineInterface::MemoryOutputStream
// -------------------------------------------------------------------
CommandLineInterface::GeneratorContextImpl::GeneratorContextImpl(
- const vector<const FileDescriptor*>& parsed_files)
+ const std::vector<const FileDescriptor*>& parsed_files)
: parsed_files_(parsed_files),
had_error_(false) {
}
@@ -412,7 +432,7 @@ bool CommandLineInterface::GeneratorContextImpl::WriteAllToDisk(
return false;
}
- for (map<string, string*>::const_iterator iter = files_.begin();
+ for (std::map<string, string*>::const_iterator iter = files_.begin();
iter != files_.end(); ++iter) {
const string& relative_filename = iter->first;
const char* data = iter->second->data();
@@ -500,7 +520,7 @@ bool CommandLineInterface::GeneratorContextImpl::WriteAllToZip(
io::FileOutputStream stream(file_descriptor);
ZipWriter zip_writer(&stream);
- for (map<string, string*>::const_iterator iter = files_.begin();
+ for (std::map<string, string*>::const_iterator iter = files_.begin();
iter != files_.end(); ++iter) {
zip_writer.Write(iter->first, *iter->second);
}
@@ -529,8 +549,8 @@ void CommandLineInterface::GeneratorContextImpl::AddJarManifest() {
}
void CommandLineInterface::GeneratorContextImpl::GetOutputFilenames(
- vector<string>* output_filenames) {
- for (map<string, string*>::iterator iter = files_.begin();
+ std::vector<string>* output_filenames) {
+ for (std::map<string, string*>::iterator iter = files_.begin();
iter != files_.end(); ++iter) {
output_filenames->push_back(iter->first);
}
@@ -686,13 +706,17 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() {
// ===================================================================
CommandLineInterface::CommandLineInterface()
- : mode_(MODE_COMPILE),
- print_mode_(PRINT_NONE),
- error_format_(ERROR_FORMAT_GCC),
- imports_in_descriptor_set_(false),
- source_info_in_descriptor_set_(false),
- disallow_services_(false),
- inputs_are_proto_path_relative_(false) {}
+ : mode_(MODE_COMPILE),
+ print_mode_(PRINT_NONE),
+ error_format_(ERROR_FORMAT_GCC),
+ direct_dependencies_explicitly_set_(false),
+ direct_dependencies_violation_msg_(
+ kDefaultDirectDependenciesViolationMsg),
+ imports_in_descriptor_set_(false),
+ source_info_in_descriptor_set_(false),
+ disallow_services_(false),
+ inputs_are_proto_path_relative_(false) {
+}
CommandLineInterface::~CommandLineInterface() {}
void CommandLineInterface::RegisterGenerator(const string& flag_name,
@@ -752,7 +776,7 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {
ErrorPrinter error_collector(error_format_, &source_tree);
Importer importer(&source_tree, &error_collector);
- vector<const FileDescriptor*> parsed_files;
+ std::vector<const FileDescriptor*> parsed_files;
// Parse each file.
for (int i = 0; i < input_files_.size(); i++) {
@@ -769,6 +793,25 @@ 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() << ": "
+ << StringReplace(direct_dependencies_violation_msg_, "%s",
+ parsed_file->dependency(i)->name(),
+ true /* replace_all */)
+ << std::endl;
+ }
+ }
+ if (indirect_imports) {
+ return 1;
+ }
+ }
}
// We construct a separate GeneratorContext for each output location. Note
@@ -854,6 +897,10 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {
}
}
+ if (error_collector.FoundErrors()) {
+ return 1;
+ }
+
if (mode_ == MODE_PRINT) {
switch (print_mode_) {
case PRINT_FREE_FIELDS:
@@ -882,6 +929,8 @@ void CommandLineInterface::Clear() {
executable_name_.clear();
proto_path_.clear();
input_files_.clear();
+ direct_dependencies_.clear();
+ direct_dependencies_violation_msg_ = kDefaultDirectDependenciesViolationMsg;
output_directives_.clear();
codec_type_.clear();
descriptor_set_name_.clear();
@@ -892,6 +941,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(
@@ -942,7 +992,7 @@ CommandLineInterface::ParseArgumentStatus
CommandLineInterface::ParseArguments(int argc, const char* const argv[]) {
executable_name_ = argv[0];
- vector<string> arguments;
+ std::vector<string> arguments;
for (int i = 1; i < argc; ++i) {
arguments.push_back(argv[i]);
}
@@ -971,12 +1021,42 @@ CommandLineInterface::ParseArguments(int argc, const char* const argv[]) {
return status;
}
+ // Make sure each plugin option has a matching plugin output.
+ bool foundUnknownPluginOption = false;
+ for (map<string, string>::const_iterator i = plugin_parameters_.begin();
+ i != plugin_parameters_.end(); ++i) {
+ if (plugins_.find(i->first) != plugins_.end()) {
+ continue;
+ }
+ bool foundImplicitPlugin = false;
+ for (std::vector<OutputDirective>::const_iterator j = output_directives_.begin();
+ j != output_directives_.end(); ++j) {
+ if (j->generator == NULL) {
+ string plugin_name = PluginName(plugin_prefix_ , j->name);
+ if (plugin_name == i->first) {
+ foundImplicitPlugin = true;
+ break;
+ }
+ }
+ }
+ if (!foundImplicitPlugin) {
+ std::cerr << "Unknown flag: "
+ // strip prefix + "gen-" and add back "_opt"
+ << "--" + i->first.substr(plugin_prefix_.size() + 4) + "_opt"
+ << std::endl;
+ foundUnknownPluginOption = true;
+ }
+ }
+ if (foundUnknownPluginOption) {
+ return PARSE_ARGUMENT_FAIL;
+ }
+
// If no --proto_path was given, use the current working directory.
if (proto_path_.empty()) {
// Don't use make_pair as the old/default standard library on Solaris
// doesn't support it without explicit template parameters, which are
// incompatible with C++0x's make_pair.
- proto_path_.push_back(pair<string, string>("", "."));
+ proto_path_.push_back(std::pair<string, string>("", "."));
}
// Check some errror cases.
@@ -1099,7 +1179,7 @@ CommandLineInterface::InterpretArgument(const string& name,
// Java's -classpath (and some other languages) delimits path components
// with colons. Let's accept that syntax too just to make things more
// intuitive.
- vector<string> parts = Split(
+ std::vector<string> parts = Split(
value, kPathSeparator, true);
for (int i = 0; i < parts.size(); i++) {
@@ -1136,9 +1216,27 @@ CommandLineInterface::InterpretArgument(const string& name,
// Don't use make_pair as the old/default standard library on Solaris
// doesn't support it without explicit template parameters, which are
// incompatible with C++0x's make_pair.
- proto_path_.push_back(pair<string, string>(virtual_path, disk_path));
+ proto_path_.push_back(std::pair<string, string>(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 ':'."
+ << std::endl;
+ return PARSE_ARGUMENT_FAIL;
}
+ direct_dependencies_explicitly_set_ = true;
+ std::vector<string> direct = Split(
+ value, ":", true);
+ GOOGLE_DCHECK(direct_dependencies_.empty());
+ direct_dependencies_.insert(direct.begin(), direct.end());
+
+ } else if (name == "--direct_dependencies_violation_msg") {
+ direct_dependencies_violation_msg_ = value;
+
} else if (name == "-o" || name == "--descriptor_set_out") {
if (!descriptor_set_name_.empty()) {
std::cerr << name << " may only be passed once." << std::endl;
@@ -1286,15 +1384,22 @@ CommandLineInterface::InterpretArgument(const string& name,
(plugin_prefix_.empty() || !HasSuffixString(name, "_out"))) {
// Check if it's a generator option flag.
generator_info = FindOrNull(generators_by_option_name_, name);
- if (generator_info == NULL) {
- std::cerr << "Unknown flag: " << name << std::endl;
- return PARSE_ARGUMENT_FAIL;
- } else {
+ if (generator_info != NULL) {
string* parameters = &generator_parameters_[generator_info->flag_name];
if (!parameters->empty()) {
parameters->append(",");
}
parameters->append(value);
+ } else if (HasPrefixString(name, "--") && HasSuffixString(name, "_opt")) {
+ string* parameters =
+ &plugin_parameters_[PluginName(plugin_prefix_, name)];
+ if (!parameters->empty()) {
+ parameters->append(",");
+ }
+ parameters->append(value);
+ } else {
+ std::cerr << "Unknown flag: " << name << std::endl;
+ return PARSE_ARGUMENT_FAIL;
}
} else {
// It's an output flag. Add it to the output directives.
@@ -1332,7 +1437,7 @@ CommandLineInterface::InterpretArgument(const string& name,
void CommandLineInterface::PrintHelpText() {
// Sorry for indentation here; line wrapping would be uglier.
- std::cerr <<
+ std::cout <<
"Usage: " << executable_name_ << " [OPTION] PROTO_FILES\n"
"Parse PROTO_FILES and generate output based on the options given:\n"
" -IPATH, --proto_path=PATH Specify the directory in which to search for\n"
@@ -1379,7 +1484,7 @@ void CommandLineInterface::PrintHelpText() {
" occupied fields numbers.\n"
<< std::endl;
if (!plugin_prefix_.empty()) {
- std::cerr <<
+ std::cout <<
" --plugin=EXECUTABLE Specifies a plugin executable to use.\n"
" Normally, protoc searches the PATH for\n"
" plugins, but you may specify additional\n"
@@ -1395,14 +1500,14 @@ void CommandLineInterface::PrintHelpText() {
// FIXME(kenton): If the text is long enough it will wrap, which is ugly,
// but fixing this nicely (e.g. splitting on spaces) is probably more
// trouble than it's worth.
- std::cerr << " " << iter->first << "=OUT_DIR "
+ std::cout << " " << iter->first << "=OUT_DIR "
<< string(19 - iter->first.size(), ' ') // Spaces for alignment.
<< iter->second.help_text << std::endl;
}
}
bool CommandLineInterface::GenerateOutput(
- const vector<const FileDescriptor*>& parsed_files,
+ const std::vector<const FileDescriptor*>& parsed_files,
const OutputDirective& output_directive,
GeneratorContext* generator_context) {
// Call the generator.
@@ -1413,12 +1518,16 @@ bool CommandLineInterface::GenerateOutput(
HasSuffixString(output_directive.name, "_out"))
<< "Bad name for plugin generator: " << output_directive.name;
- // Strip the "--" and "_out" and add the plugin prefix.
- string plugin_name = plugin_prefix_ + "gen-" +
- output_directive.name.substr(2, output_directive.name.size() - 6);
-
+ string plugin_name = PluginName(plugin_prefix_ , output_directive.name);
+ string parameters = output_directive.parameter;
+ if (!plugin_parameters_[plugin_name].empty()) {
+ if (!parameters.empty()) {
+ parameters.append(",");
+ }
+ parameters.append(plugin_parameters_[plugin_name]);
+ }
if (!GeneratePluginOutput(parsed_files, plugin_name,
- output_directive.parameter,
+ parameters,
generator_context, &error)) {
std::cerr << output_directive.name << ": " << error << std::endl;
return false;
@@ -1432,24 +1541,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;
}
}
@@ -1457,12 +1553,12 @@ bool CommandLineInterface::GenerateOutput(
}
bool CommandLineInterface::GenerateDependencyManifestFile(
- const vector<const FileDescriptor*>& parsed_files,
+ const std::vector<const FileDescriptor*>& parsed_files,
const GeneratorContextMap& output_directories,
DiskSourceTree* source_tree) {
FileDescriptorSet file_set;
- set<const FileDescriptor*> already_seen;
+ std::set<const FileDescriptor*> already_seen;
for (int i = 0; i < parsed_files.size(); i++) {
GetTransitiveDependencies(parsed_files[i],
false,
@@ -1471,12 +1567,12 @@ bool CommandLineInterface::GenerateDependencyManifestFile(
file_set.mutable_file());
}
- vector<string> output_filenames;
+ std::vector<string> output_filenames;
for (GeneratorContextMap::const_iterator iter = output_directories.begin();
iter != output_directories.end(); ++iter) {
const string& location = iter->first;
GeneratorContextImpl* directory = iter->second;
- vector<string> relative_output_filenames;
+ std::vector<string> relative_output_filenames;
directory->GetOutputFilenames(&relative_output_filenames);
for (int i = 0; i < relative_output_filenames.size(); i++) {
string output_filename = location + relative_output_filenames[i];
@@ -1529,7 +1625,7 @@ bool CommandLineInterface::GenerateDependencyManifestFile(
}
bool CommandLineInterface::GeneratePluginOutput(
- const vector<const FileDescriptor*>& parsed_files,
+ const std::vector<const FileDescriptor*>& parsed_files,
const string& plugin_name,
const string& parameter,
GeneratorContext* generator_context,
@@ -1542,7 +1638,7 @@ bool CommandLineInterface::GeneratePluginOutput(
request.set_parameter(parameter);
}
- set<const FileDescriptor*> already_seen;
+ std::set<const FileDescriptor*> already_seen;
for (int i = 0; i < parsed_files.size(); i++) {
request.add_file_to_generate(parsed_files[i]->name());
GetTransitiveDependencies(parsed_files[i],
@@ -1551,6 +1647,13 @@ bool CommandLineInterface::GeneratePluginOutput(
&already_seen, request.mutable_proto_file());
}
+ google::protobuf::compiler::Version* version =
+ request.mutable_compiler_version();
+ version->set_major(GOOGLE_PROTOBUF_VERSION / 1000000);
+ version->set_minor(GOOGLE_PROTOBUF_VERSION / 1000 % 1000);
+ version->set_patch(GOOGLE_PROTOBUF_VERSION % 1000);
+ version->set_suffix(GOOGLE_PROTOBUF_VERSION_SUFFIX);
+
// Invoke the plugin.
Subprocess subprocess;
@@ -1672,11 +1775,11 @@ bool CommandLineInterface::EncodeOrDecode(const DescriptorPool* pool) {
}
bool CommandLineInterface::WriteDescriptorSet(
- const vector<const FileDescriptor*> parsed_files) {
+ const std::vector<const FileDescriptor*> parsed_files) {
FileDescriptorSet file_set;
if (imports_in_descriptor_set_) {
- set<const FileDescriptor*> already_seen;
+ std::set<const FileDescriptor*> already_seen;
for (int i = 0; i < parsed_files.size(); i++) {
GetTransitiveDependencies(parsed_files[i],
true, // Include json_name
@@ -1684,7 +1787,7 @@ bool CommandLineInterface::WriteDescriptorSet(
&already_seen, file_set.mutable_file());
}
} else {
- set<const FileDescriptor*> already_seen;
+ std::set<const FileDescriptor*> already_seen;
for (int i = 0; i < parsed_files.size(); i++) {
if (!already_seen.insert(parsed_files[i]).second) {
continue;
@@ -1729,7 +1832,7 @@ void CommandLineInterface::GetTransitiveDependencies(
const FileDescriptor* file,
bool include_json_name,
bool include_source_code_info,
- set<const FileDescriptor*>* already_seen,
+ std::set<const FileDescriptor*>* already_seen,
RepeatedPtrField<FileDescriptorProto>* output) {
if (!already_seen->insert(file).second) {
// Already saw this file. Skip.
@@ -1788,11 +1891,11 @@ namespace {
// parameter will contain the direct children (when groups are ignored in the
// tree) of the given descriptor for the caller to traverse. The declaration
// order of the nested messages is also preserved.
-typedef pair<int, int> FieldRange;
-void GatherOccupiedFieldRanges(const Descriptor* descriptor,
- set<FieldRange>* ranges,
- vector<const Descriptor*>* nested_messages) {
- set<const Descriptor*> groups;
+typedef std::pair<int, int> FieldRange;
+void GatherOccupiedFieldRanges(
+ const Descriptor* descriptor, std::set<FieldRange>* ranges,
+ std::vector<const Descriptor*>* nested_messages) {
+ std::set<const Descriptor*> groups;
for (int i = 0; i < descriptor->field_count(); ++i) {
const FieldDescriptor* fd = descriptor->field(i);
ranges->insert(FieldRange(fd->number(), fd->number() + 1));
@@ -1824,11 +1927,11 @@ void GatherOccupiedFieldRanges(const Descriptor* descriptor,
// Actually prints the formatted free field numbers for given message name and
// occupied ranges.
void FormatFreeFieldNumbers(const string& name,
- const set<FieldRange>& ranges) {
+ const std::set<FieldRange>& ranges) {
string output;
StringAppendF(&output, "%-35s free:", name.c_str());
int next_free_number = 1;
- for (set<FieldRange>::const_iterator i = ranges.begin();
+ for (std::set<FieldRange>::const_iterator i = ranges.begin();
i != ranges.end(); ++i) {
// This happens when groups re-use parent field numbers, in which
// case we skip the FieldRange entirely.
@@ -1855,8 +1958,8 @@ void FormatFreeFieldNumbers(const string& name,
void CommandLineInterface::PrintFreeFieldNumbers(
const Descriptor* descriptor) {
- set<FieldRange> ranges;
- vector<const Descriptor*> nested_messages;
+ std::set<FieldRange> ranges;
+ std::vector<const Descriptor*> nested_messages;
GatherOccupiedFieldRanges(descriptor, &ranges, &nested_messages);
for (int i = 0; i < nested_messages.size(); ++i) {
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/command_line_interface.h b/third_party/protobuf/src/google/protobuf/compiler/command_line_interface.h
index d1377666d3..8f8c2682fd 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/command_line_interface.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/command_line_interface.h
@@ -55,6 +55,9 @@ class FileDescriptor; // descriptor.h
class FileDescriptorProto; // descriptor.pb.h
template<typename T> class RepeatedPtrField; // repeated_field.h
+} // namespace protobuf
+
+namespace protobuf {
namespace compiler {
class CodeGenerator; // code_generator.h
@@ -141,14 +144,14 @@ class LIBPROTOC_EXPORT CommandLineInterface {
// plugin [--out=OUTDIR] [--parameter=PARAMETER] PROTO_FILES < DESCRIPTORS
// --out indicates the output directory (as passed to the --foo_out
// parameter); if omitted, the current directory should be used. --parameter
- // gives the generator parameter, if any was provided. The PROTO_FILES list
- // the .proto files which were given on the compiler command-line; these are
- // the files for which the plugin is expected to generate output code.
- // Finally, DESCRIPTORS is an encoded FileDescriptorSet (as defined in
- // descriptor.proto). This is piped to the plugin's stdin. The set will
- // include descriptors for all the files listed in PROTO_FILES as well as
- // all files that they import. The plugin MUST NOT attempt to read the
- // PROTO_FILES directly -- it must use the FileDescriptorSet.
+ // gives the generator parameter, if any was provided (see below). The
+ // PROTO_FILES list the .proto files which were given on the compiler
+ // command-line; these are the files for which the plugin is expected to
+ // generate output code. Finally, DESCRIPTORS is an encoded FileDescriptorSet
+ // (as defined in descriptor.proto). This is piped to the plugin's stdin.
+ // The set will include descriptors for all the files listed in PROTO_FILES as
+ // well as all files that they import. The plugin MUST NOT attempt to read
+ // the PROTO_FILES directly -- it must use the FileDescriptorSet.
//
// The plugin should generate whatever files are necessary, as code generators
// normally do. It should write the names of all files it generates to
@@ -156,6 +159,13 @@ class LIBPROTOC_EXPORT CommandLineInterface {
// names or relative to the current directory. If any errors occur, error
// messages should be written to stderr. If an error is fatal, the plugin
// should exit with a non-zero exit code.
+ //
+ // Plugins can have generator parameters similar to normal built-in
+ // generators. Extra generator parameters can be passed in via a matching
+ // "_opt" parameter. For example:
+ // protoc --plug_out=enable_bar:outdir --plug_opt=enable_baz
+ // This will pass "enable_bar,enable_baz" as the parameter to the plugin.
+ //
void AllowPlugins(const string& exe_name_prefix);
// Run the Protocol Compiler with the given command-line parameters.
@@ -235,24 +245,24 @@ class LIBPROTOC_EXPORT CommandLineInterface {
// Generate the given output file from the given input.
struct OutputDirective; // see below
- bool GenerateOutput(const vector<const FileDescriptor*>& parsed_files,
+ bool GenerateOutput(const std::vector<const FileDescriptor*>& parsed_files,
const OutputDirective& output_directive,
GeneratorContext* generator_context);
- bool GeneratePluginOutput(const vector<const FileDescriptor*>& parsed_files,
- const string& plugin_name,
- const string& parameter,
- GeneratorContext* generator_context,
- string* error);
+ bool GeneratePluginOutput(
+ const std::vector<const FileDescriptor*>& parsed_files,
+ const string& plugin_name, const string& parameter,
+ GeneratorContext* generator_context, string* error);
// Implements --encode and --decode.
bool EncodeOrDecode(const DescriptorPool* pool);
// Implements the --descriptor_set_out option.
- bool WriteDescriptorSet(const vector<const FileDescriptor*> parsed_files);
+ bool WriteDescriptorSet(
+ const std::vector<const FileDescriptor*> parsed_files);
// Implements the --dependency_out option
bool GenerateDependencyManifestFile(
- const vector<const FileDescriptor*>& parsed_files,
+ const std::vector<const FileDescriptor*>& parsed_files,
const GeneratorContextMap& output_directories,
DiskSourceTree* source_tree);
@@ -269,7 +279,7 @@ class LIBPROTOC_EXPORT CommandLineInterface {
const FileDescriptor* file,
bool include_json_name,
bool include_source_code_info,
- set<const FileDescriptor*>* already_seen,
+ std::set<const FileDescriptor*>* already_seen,
RepeatedPtrField<FileDescriptorProto>* output);
// Implements the --print_free_field_numbers. This function prints free field
@@ -303,14 +313,16 @@ class LIBPROTOC_EXPORT CommandLineInterface {
CodeGenerator* generator;
string help_text;
};
- typedef map<string, GeneratorInfo> GeneratorMap;
+ typedef std::map<string, GeneratorInfo> GeneratorMap;
GeneratorMap generators_by_flag_name_;
GeneratorMap generators_by_option_name_;
// A map from generator names to the parameters specified using the option
// flag. For example, if the user invokes the compiler with:
// protoc --foo_out=outputdir --foo_opt=enable_bar ...
// Then there will be an entry ("--foo_out", "enable_bar") in this map.
- map<string, string> generator_parameters_;
+ std::map<string, string> generator_parameters_;
+ // Similar to generator_parameters_, but stores the parameters for plugins.
+ std::map<string, string> plugin_parameters_;
// See AllowPlugins(). If this is empty, plugins aren't allowed.
string plugin_prefix_;
@@ -318,7 +330,7 @@ class LIBPROTOC_EXPORT CommandLineInterface {
// Maps specific plugin names to files. When executing a plugin, this map
// is searched first to find the plugin executable. If not found here, the
// PATH (or other OS-specific search strategy) is searched.
- map<string, string> plugins_;
+ std::map<string, string> plugins_;
// Stuff parsed from command line.
enum Mode {
@@ -344,8 +356,18 @@ class LIBPROTOC_EXPORT CommandLineInterface {
ErrorFormat error_format_;
- vector<pair<string, string> > proto_path_; // Search path for proto files.
- vector<string> input_files_; // Names of the input proto files.
+ std::vector<std::pair<string, string> >
+ proto_path_; // Search path for proto files.
+ std::vector<string> 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.
+ std::set<string> direct_dependencies_;
+ bool direct_dependencies_explicitly_set_;
+
+ // If there's a violation of depend-on-what-you-import, this string will be
+ // presented to the user. "%s" will be replaced with the violating import.
+ string direct_dependencies_violation_msg_;
// output_directives_ lists all the files we are supposed to output and what
// generator to use for each.
@@ -355,7 +377,7 @@ class LIBPROTOC_EXPORT CommandLineInterface {
string parameter;
string output_location;
};
- vector<OutputDirective> output_directives_;
+ std::vector<OutputDirective> output_directives_;
// When using --encode or --decode, this names the type we are encoding or
// decoding. (Empty string indicates --decode_raw.)
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/command_line_interface_unittest.cc b/third_party/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc
index 0ebf9b6a2c..eab14f6001 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/command_line_interface_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc
@@ -57,6 +57,7 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/testing/file.h>
+#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
@@ -100,6 +101,7 @@ class CommandLineInterfaceTest : public testing::Test {
// command is automatically split on spaces, and the string "$tmpdir"
// is replaced with TestTempDir().
void Run(const string& command);
+ void RunWithArgs(vector<string> args);
// -----------------------------------------------------------------
// Methods to set up the test (called before Run()).
@@ -154,6 +156,11 @@ class CommandLineInterfaceTest : public testing::Test {
// Checks that the captured stdout is the same as the expected_text.
void ExpectCapturedStdout(const string& expected_text);
+ // Checks that Run() returned zero and the stdout contains the given
+ // substring.
+ void ExpectCapturedStdoutSubstringWithZeroReturnCode(
+ const string& expected_substring);
+
// Returns true if ExpectErrorSubstring(expected_substring) would pass, but
// does not fail otherwise.
bool HasAlternateErrorSubstring(const string& expected_substring);
@@ -217,7 +224,7 @@ class CommandLineInterfaceTest : public testing::Test {
string captured_stdout_;
// Pointers which need to be deleted later.
- vector<CodeGenerator*> mock_generators_to_delete_;
+ std::vector<CodeGenerator*> mock_generators_to_delete_;
NullCodeGenerator* null_generator_;
};
@@ -291,8 +298,10 @@ void CommandLineInterfaceTest::TearDown() {
}
void CommandLineInterfaceTest::Run(const string& command) {
- vector<string> args = Split(command, " ", true);
+ RunWithArgs(Split(command, " ", true));
+}
+void CommandLineInterfaceTest::RunWithArgs(vector<string> args) {
if (!disallow_plugins_) {
cli_.AllowPlugins("prefix-");
#ifndef GOOGLE_THIRD_PARTY_PROTOBUF
@@ -484,6 +493,11 @@ void CommandLineInterfaceTest::ExpectCapturedStdout(
EXPECT_EQ(expected_text, captured_stdout_);
}
+void CommandLineInterfaceTest::ExpectCapturedStdoutSubstringWithZeroReturnCode(
+ const string& expected_substring) {
+ EXPECT_EQ(0, return_code_);
+ EXPECT_PRED_FORMAT2(testing::IsSubstring, expected_substring, captured_stdout_);
+}
void CommandLineInterfaceTest::ExpectFileContent(
const string& filename, const string& content) {
@@ -653,6 +667,70 @@ TEST_F(CommandLineInterfaceTest, ExtraGeneratorParameters) {
"test_generator", "baz,foo1,foo2,foo3", "foo.proto", "Foo", "b");
}
+TEST_F(CommandLineInterfaceTest, ExtraPluginParameters) {
+ // Test that generator parameters specified with the option flag are
+ // correctly passed to the code generator.
+
+ CreateTempFile("foo.proto",
+ "syntax = \"proto2\";\n"
+ "message Foo {}\n");
+ // Create the "a" and "b" sub-directories.
+ CreateTempDir("a");
+ CreateTempDir("b");
+
+ Run("protocol_compiler "
+ "--plug_opt=foo1 "
+ "--plug_out=bar:$tmpdir/a "
+ "--plug_opt=foo2 "
+ "--plug_out=baz:$tmpdir/b "
+ "--plug_opt=foo3 "
+ "--proto_path=$tmpdir foo.proto");
+
+ ExpectNoErrors();
+ ExpectGenerated(
+ "test_plugin", "bar,foo1,foo2,foo3", "foo.proto", "Foo", "a");
+ ExpectGenerated(
+ "test_plugin", "baz,foo1,foo2,foo3", "foo.proto", "Foo", "b");
+}
+
+TEST_F(CommandLineInterfaceTest, UnrecognizedExtraParameters) {
+ CreateTempFile("foo.proto",
+ "syntax = \"proto2\";\n"
+ "message Foo {}\n");
+
+ Run("protocol_compiler --plug_out=TestParameter:$tmpdir "
+ "--unknown_plug_a_opt=Foo "
+ "--unknown_plug_b_opt=Bar "
+ "--proto_path=$tmpdir foo.proto");
+
+ ExpectErrorSubstring("Unknown flag: --unknown_plug_a_opt");
+ ExpectErrorSubstring("Unknown flag: --unknown_plug_b_opt");
+}
+
+TEST_F(CommandLineInterfaceTest, ExtraPluginParametersForOutParameters) {
+ // This doesn't rely on the plugin having been registred and instead that
+ // the existence of --[name]_out is enough to make the --[name]_opt valid.
+ // However, running out of process plugins found via the search path (i.e. -
+ // not pre registered with --plugin) isn't support in this test suite, so we
+ // list the options pre/post the _out directive, and then include _opt that
+ // will be unknown, and confirm the failure output is about the expected
+ // unknown directive, which means the other were accepted.
+ // NOTE: UnrecognizedExtraParameters confirms that if two unknown _opt
+ // directives appear, they both are reported.
+
+ CreateTempFile("foo.proto",
+ "syntax = \"proto2\";\n"
+ "message Foo {}\n");
+
+ Run("protocol_compiler --plug_out=TestParameter:$tmpdir "
+ "--xyz_opt=foo=bar --xyz_out=$tmpdir "
+ "--abc_out=$tmpdir --abc_opt=foo=bar "
+ "--unknown_plug_opt=Foo "
+ "--proto_path=$tmpdir foo.proto");
+
+ ExpectErrorText("Unknown flag: --unknown_plug_opt\n");
+}
+
TEST_F(CommandLineInterfaceTest, Insert) {
// Test running a generator that inserts code into another's output.
@@ -719,6 +797,11 @@ TEST_F(CommandLineInterfaceTest, TrailingBackslash) {
ExpectGenerated("test_generator", "", "foo.proto", "Foo");
}
+TEST_F(CommandLineInterfaceTest, Win32ErrorMessage) {
+ EXPECT_EQ("The system cannot find the file specified.\r\n",
+ Subprocess::Win32ErrorMessage(ERROR_FILE_NOT_FOUND));
+}
+
#endif // defined(_WIN32) || defined(__CYGWIN__)
TEST_F(CommandLineInterfaceTest, PathLookup) {
@@ -866,6 +949,113 @@ 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, DirectDependencies_CustomErrorMessage) {
+ 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; }");
+
+ vector<string> commands;
+ commands.push_back("protocol_compiler");
+ commands.push_back("--test_out=$tmpdir");
+ commands.push_back("--proto_path=$tmpdir");
+ commands.push_back("--direct_dependencies=");
+ commands.push_back("--direct_dependencies_violation_msg=Bla \"%s\" Bla");
+ commands.push_back("foo.proto");
+ RunWithArgs(commands);
+
+ ExpectErrorText("foo.proto: Bla \"bar.proto\" Bla\n");
+}
+
TEST_F(CommandLineInterfaceTest, CwdRelativeInputs) {
// Test that we can accept working-directory-relative input files.
@@ -1153,6 +1343,19 @@ TEST_F(CommandLineInterfaceTest, ParseErrorsMultipleFiles) {
"foo.proto: Import \"baz.proto\" was not found or had errors.\n");
}
+TEST_F(CommandLineInterfaceTest, RecursiveImportFails) {
+ // Create a proto file that imports itself.
+ CreateTempFile("foo.proto",
+ "syntax = \"proto2\";\n"
+ "import \"foo.proto\";\n");
+
+ Run("protocol_compiler --test_out=$tmpdir "
+ "--proto_path=$tmpdir foo.proto");
+
+ ExpectErrorSubstring(
+ "foo.proto: File recursively imports itself: foo.proto -> foo.proto\n");
+}
+
TEST_F(CommandLineInterfaceTest, InputNotFoundError) {
// Test what happens if the input file is not found.
@@ -1453,6 +1656,21 @@ TEST_F(CommandLineInterfaceTest, PluginReceivesJsonName) {
ExpectErrorSubstring("Saw json_name: 1");
}
+TEST_F(CommandLineInterfaceTest, PluginReceivesCompilerVersion) {
+ CreateTempFile("foo.proto",
+ "syntax = \"proto2\";\n"
+ "message MockCodeGenerator_ShowVersionNumber {\n"
+ " optional int32 value = 1;\n"
+ "}\n");
+
+ Run("protocol_compiler --plug_out=$tmpdir --proto_path=$tmpdir foo.proto");
+
+ ExpectErrorSubstring(
+ StringPrintf("Saw compiler_version: %d %s",
+ GOOGLE_PROTOBUF_VERSION,
+ GOOGLE_PROTOBUF_VERSION_SUFFIX));
+}
+
TEST_F(CommandLineInterfaceTest, GeneratorPluginNotFound) {
// Test what happens if the plugin isn't found.
@@ -1495,11 +1713,11 @@ TEST_F(CommandLineInterfaceTest, GeneratorPluginNotAllowed) {
TEST_F(CommandLineInterfaceTest, HelpText) {
Run("test_exec_name --help");
- ExpectErrorSubstringWithZeroReturnCode("Usage: test_exec_name ");
- ExpectErrorSubstringWithZeroReturnCode("--test_out=OUT_DIR");
- ExpectErrorSubstringWithZeroReturnCode("Test output.");
- ExpectErrorSubstringWithZeroReturnCode("--alt_out=OUT_DIR");
- ExpectErrorSubstringWithZeroReturnCode("Alt output.");
+ ExpectCapturedStdoutSubstringWithZeroReturnCode("Usage: test_exec_name ");
+ ExpectCapturedStdoutSubstringWithZeroReturnCode("--test_out=OUT_DIR");
+ ExpectCapturedStdoutSubstringWithZeroReturnCode("Test output.");
+ ExpectCapturedStdoutSubstringWithZeroReturnCode("--alt_out=OUT_DIR");
+ ExpectCapturedStdoutSubstringWithZeroReturnCode("Alt output.");
}
TEST_F(CommandLineInterfaceTest, GccFormatErrors) {
@@ -1727,7 +1945,7 @@ class EncodeDecodeTest : public testing::Test {
enum ReturnCode { SUCCESS, ERROR };
bool Run(const string& command) {
- vector<string> args;
+ std::vector<string> args;
args.push_back("protoc");
SplitStringUsing(command, " ", &args);
args.push_back("--proto_path=" + TestSourceDir());
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc
index 77451ab1bf..bf4e58319c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc
+++ b/third_party/protobuf/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.";
}
@@ -115,7 +114,7 @@ class MockGeneratorContext : public GeneratorContext {
}
private:
- map<string, string*> files_;
+ std::map<string, string*> files_;
};
TEST(BootstrapTest, GeneratedDescriptorMatches) {
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_enum.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_enum.cc
index 62b7ed4e47..6a8a83d13c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_enum.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_enum.cc
@@ -70,7 +70,7 @@ EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor,
EnumGenerator::~EnumGenerator() {}
void EnumGenerator::FillForwardDeclaration(
- map<string, const EnumDescriptor*>* enum_names) {
+ std::map<string, const EnumDescriptor*>* enum_names) {
if (!options_.proto_h) {
return;
}
@@ -78,7 +78,7 @@ void EnumGenerator::FillForwardDeclaration(
}
void EnumGenerator::GenerateDefinition(io::Printer* printer) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars["classname"] = classname_;
vars["short_name"] = descriptor_->name();
vars["enumbase"] = classname_ + (options_.proto_h ? " : int" : "");
@@ -180,7 +180,7 @@ GenerateGetEnumDescriptorSpecializations(io::Printer* printer) {
}
void EnumGenerator::GenerateSymbolImports(io::Printer* printer) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars["nested_name"] = descriptor_->name();
vars["classname"] = classname_;
vars["constexpr"] = options_.proto_h ? "constexpr " : "";
@@ -229,50 +229,55 @@ void EnumGenerator::GenerateSymbolImports(io::Printer* printer) {
}
}
-void EnumGenerator::GenerateDescriptorInitializer(
- io::Printer* printer, int index) {
- map<string, string> vars;
- vars["classname"] = classname_;
- vars["index"] = SimpleItoa(index);
+void EnumGenerator::GenerateDescriptorInitializer(io::Printer* printer) {
+ std::map<string, string> vars;
+ vars["index"] = SimpleItoa(descriptor_->index());
+ vars["index_in_metadata"] = SimpleItoa(index_in_metadata_);
if (descriptor_->containing_type() == NULL) {
printer->Print(vars,
- "$classname$_descriptor_ = file->enum_type($index$);\n");
+ "file_level_enum_descriptors[$index_in_metadata$] = "
+ "file->enum_type($index$);\n");
} else {
vars["parent"] = ClassName(descriptor_->containing_type(), false);
printer->Print(vars,
- "$classname$_descriptor_ = $parent$_descriptor_->enum_type($index$);\n");
+ "file_level_enum_descriptors[$index_in_metadata$] = "
+ "$parent$_descriptor->enum_type($index$);\n");
}
}
void EnumGenerator::GenerateMethods(io::Printer* printer) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars["classname"] = classname_;
+ vars["index_in_metadata"] = SimpleItoa(index_in_metadata_);
vars["constexpr"] = options_.proto_h ? "constexpr " : "";
+ vars["file_namespace"] = FileLevelNamespace(descriptor_->file()->name());
if (HasDescriptorMethods(descriptor_->file(), options_)) {
- printer->Print(vars,
- "const ::google::protobuf::EnumDescriptor* $classname$_descriptor() {\n"
- " protobuf_AssignDescriptorsOnce();\n"
- " return $classname$_descriptor_;\n"
- "}\n");
+ printer->Print(
+ vars,
+ "const ::google::protobuf::EnumDescriptor* $classname$_descriptor() {\n"
+ " $file_namespace$::protobuf_AssignDescriptorsOnce();\n"
+ " return "
+ "$file_namespace$::file_level_enum_descriptors[$index_in_metadata$];\n"
+ "}\n");
}
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
// numbers, then printing a case statement for each element.
- set<int> numbers;
+ std::set<int> numbers;
for (int j = 0; j < descriptor_->value_count(); j++) {
const EnumValueDescriptor* value = descriptor_->value(j);
numbers.insert(value->number());
}
- for (set<int>::iterator iter = numbers.begin();
+ for (std::set<int>::iterator iter = numbers.begin();
iter != numbers.end(); ++iter) {
printer->Print(
" case $number$:\n",
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_enum.h b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_enum.h
index 90edf0017d..0b568c57b9 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_enum.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_enum.h
@@ -66,7 +66,8 @@ class EnumGenerator {
// enums. A given key in enum_names will map from an enum class name to the
// EnumDescriptor that was responsible for its inclusion in the map. This can
// be used to associate the descriptor with the code generated for it.
- void FillForwardDeclaration(map<string, const EnumDescriptor*>* enum_names);
+ void FillForwardDeclaration(
+ std::map<string, const EnumDescriptor*>* enum_names);
// Generate header code defining the enum. This code should be placed
// within the enum's package namespace, but NOT within any class, even for
@@ -87,7 +88,7 @@ class EnumGenerator {
// Generate code that initializes the global variable storing the enum's
// descriptor.
- void GenerateDescriptorInitializer(io::Printer* printer, int index);
+ void GenerateDescriptorInitializer(io::Printer* printer);
// Generate non-inline methods related to the enum, such as IsValidValue().
// Goes in the .cc file.
@@ -100,6 +101,9 @@ class EnumGenerator {
// whether to generate the *_ARRAYSIZE constant.
const bool generate_array_size_;
+ int index_in_metadata_;
+
+ friend class FileGenerator;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator);
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_enum_field.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
index ffd815293f..e4b17a98e4 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.cc
@@ -46,7 +46,7 @@ namespace cpp {
namespace {
void SetEnumVariables(const FieldDescriptor* descriptor,
- map<string, string>* variables,
+ std::map<string, string>* variables,
const Options& options) {
SetCommonFieldVariables(descriptor, variables, options);
const EnumValueDescriptor* default_value = descriptor->default_value_enum();
@@ -82,14 +82,14 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
void EnumFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer,
bool is_inline) const {
- map<string, string> variables(variables_);
- variables["inline"] = is_inline ? "inline" : "";
+ std::map<string, string> variables(variables_);
+ 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");
@@ -122,6 +122,11 @@ GenerateConstructorCode(io::Printer* printer) const {
}
void EnumFieldGenerator::
+GenerateCopyConstructorCode(io::Printer* printer) const {
+ printer->Print(variables_, "$name$_ = from.$name$_;\n");
+}
+
+void EnumFieldGenerator::
GenerateMergeFromCodedStream(io::Printer* printer) const {
printer->Print(variables_,
"int value;\n"
@@ -142,7 +147,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
} else {
printer->Print(
"} else {\n"
- " unknown_fields_stream.WriteVarint32($tag$);\n"
+ " unknown_fields_stream.WriteVarint32($tag$u);\n"
" unknown_fields_stream.WriteVarint32(value);\n",
"tag", SimpleItoa(internal::WireFormat::MakeTag(descriptor_)));
}
@@ -186,17 +191,17 @@ EnumOneofFieldGenerator::~EnumOneofFieldGenerator() {}
void EnumOneofFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer,
bool is_inline) const {
- map<string, string> variables(variables_);
- variables["inline"] = is_inline ? "inline" : "";
+ std::map<string, string> variables(variables_);
+ 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");
@@ -223,8 +228,9 @@ GenerateSwappingCode(io::Printer* printer) const {
void EnumOneofFieldGenerator::
GenerateConstructorCode(io::Printer* printer) const {
- printer->Print(variables_,
- " $classname$_default_oneof_instance_->$name$_ = $default$;\n");
+ printer->Print(
+ variables_,
+ "_$classname$_default_instance_.$name$_ = $default$;\n");
}
// ===================================================================
@@ -262,14 +268,14 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
void RepeatedEnumFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer,
bool is_inline) const {
- map<string, string> variables(variables_);
- variables["inline"] = is_inline ? "inline" : "";
+ std::map<string, string> variables(variables_);
+ 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 +284,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 +294,12 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" // @@protoc_insertion_point(field_add:$full_name$)\n"
"}\n");
printer->Print(variables,
- "$inline$ const ::google::protobuf::RepeatedField<int>&\n"
+ "$inline$const ::google::protobuf::RepeatedField<int>&\n"
"$classname$::$name$() const {\n"
" // @@protoc_insertion_point(field_list:$full_name$)\n"
" return $name$_;\n"
"}\n"
- "$inline$ ::google::protobuf::RepeatedField<int>*\n"
+ "$inline$::google::protobuf::RepeatedField<int>*\n"
"$classname$::mutable_$name$() {\n"
" // @@protoc_insertion_point(field_mutable_list:$full_name$)\n"
" return &$name$_;\n"
@@ -430,7 +436,7 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) const {
"}\n");
}
printer->Print(variables_,
- "for (int i = 0; i < this->$name$_size(); i++) {\n");
+ "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n");
if (descriptor_->is_packed()) {
printer->Print(variables_,
" ::google::protobuf::internal::WireFormatLite::WriteEnumNoTag(\n"
@@ -458,7 +464,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const {
"}\n");
}
printer->Print(variables_,
- "for (int i = 0; i < this->$name$_size(); i++) {\n");
+ "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n");
if (descriptor_->is_packed()) {
printer->Print(variables_,
" target = ::google::protobuf::internal::WireFormatLite::WriteEnumNoTagToArray(\n"
@@ -475,10 +481,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 +496,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/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_enum_field.h b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.h
index fe21c57574..3ecd7ba871 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_enum_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.h
@@ -58,6 +58,7 @@ class EnumFieldGenerator : public FieldGenerator {
void GenerateMergingCode(io::Printer* printer) const;
void GenerateSwappingCode(io::Printer* printer) const;
void GenerateConstructorCode(io::Printer* printer) const;
+ void GenerateCopyConstructorCode(io::Printer* printer) const;
void GenerateMergeFromCodedStream(io::Printer* printer) const;
void GenerateSerializeWithCachedSizes(io::Printer* printer) const;
void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const;
@@ -65,7 +66,7 @@ class EnumFieldGenerator : public FieldGenerator {
protected:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator);
@@ -103,6 +104,7 @@ class RepeatedEnumFieldGenerator : public FieldGenerator {
void GenerateMergingCode(io::Printer* printer) const;
void GenerateSwappingCode(io::Printer* printer) const;
void GenerateConstructorCode(io::Printer* printer) const;
+ void GenerateCopyConstructorCode(io::Printer* printer) const {}
void GenerateMergeFromCodedStream(io::Printer* printer) const;
void GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const;
void GenerateSerializeWithCachedSizes(io::Printer* printer) const;
@@ -111,7 +113,7 @@ class RepeatedEnumFieldGenerator : public FieldGenerator {
private:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedEnumFieldGenerator);
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_extension.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.cc
index c42f162794..e4fce4617b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_extension.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.cc
@@ -92,7 +92,7 @@ ExtensionGenerator::ExtensionGenerator(const FieldDescriptor* descriptor,
ExtensionGenerator::~ExtensionGenerator() {}
void ExtensionGenerator::GenerateDeclaration(io::Printer* printer) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars["extendee" ] = ExtendeeClassName(descriptor_);
vars["number" ] = SimpleItoa(descriptor_->number());
vars["type_traits" ] = type_traits_;
@@ -128,7 +128,7 @@ void ExtensionGenerator::GenerateDefinition(io::Printer* printer) {
ClassName(descriptor_->extension_scope(), false) + "::";
string name = scope + descriptor_->name();
- map<string, string> vars;
+ std::map<string, string> vars;
vars["extendee" ] = ExtendeeClassName(descriptor_);
vars["type_traits" ] = type_traits_;
vars["name" ] = name;
@@ -167,7 +167,7 @@ void ExtensionGenerator::GenerateDefinition(io::Printer* printer) {
}
void ExtensionGenerator::GenerateRegistration(io::Printer* printer) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars["extendee" ] = ExtendeeClassName(descriptor_);
vars["number" ] = SimpleItoa(descriptor_->number());
vars["field_type" ] = SimpleItoa(static_cast<int>(descriptor_->type()));
@@ -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/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_extension.h b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.h
index 1c1caf1f90..1c1caf1f90 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_extension.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_field.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_field.cc
index e2033c1acd..4480a9d2d0 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_field.cc
@@ -59,7 +59,7 @@ namespace cpp {
using internal::WireFormat;
void SetCommonFieldVariables(const FieldDescriptor* descriptor,
- map<string, string>* variables,
+ std::map<string, string>* variables,
const Options& options) {
(*variables)["name"] = FieldName(descriptor);
(*variables)["index"] = SimpleItoa(descriptor->index());
@@ -98,7 +98,7 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
}
void SetCommonOneofFieldVariables(const FieldDescriptor* descriptor,
- map<string, string>* variables) {
+ std::map<string, string>* variables) {
const string prefix = descriptor->containing_oneof()->name() + "_.";
(*variables)["oneof_prefix"] = prefix;
(*variables)["oneof_name"] = descriptor->containing_oneof()->name();
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_field.h b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_field.h
index 3b01252780..00dc25d4cf 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_field.h
@@ -61,11 +61,11 @@ namespace cpp {
// ['name', 'index', 'number', 'classname', 'declared_type', 'tag_size',
// 'deprecation'].
void SetCommonFieldVariables(const FieldDescriptor* descriptor,
- map<string, string>* variables,
+ std::map<string, string>* variables,
const Options& options);
void SetCommonOneofFieldVariables(const FieldDescriptor* descriptor,
- map<string, string>* variables);
+ std::map<string, string>* variables);
class FieldGenerator {
public:
@@ -124,10 +124,20 @@ class FieldGenerator {
io::Printer* /*printer*/) const {}
// Generate lines of code (statements, not declarations) which clear the
- // field. This is used to define the clear_$name$() method as well as
- // the Clear() method for the whole message.
+ // field. This is used to define the clear_$name$() method
virtual void GenerateClearingCode(io::Printer* printer) const = 0;
+ // Generate lines of code (statements, not declarations) which clear the field
+ // as part of the Clear() method for the whole message. For message types
+ // which have field presence bits, MessageGenerator::GenerateClear will have
+ // already checked the presence bits.
+ //
+ // Since most field types can re-use GenerateClearingCode, this method is not
+ // pure virtual.
+ virtual void GenerateMessageClearingCode(io::Printer* printer) const {
+ GenerateClearingCode(printer);
+ }
+
// Generate lines of code (statements, not declarations) which merges the
// contents of the field from the current message to the target message,
// which is stored in the generated code variable "from".
@@ -136,6 +146,9 @@ class FieldGenerator {
// GenerateMergeFrom method.
virtual void GenerateMergingCode(io::Printer* printer) const = 0;
+ // Generates a copy constructor
+ virtual void GenerateCopyConstructorCode(io::Printer* printer) const = 0;
+
// 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/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_file.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_file.cc
index b3eca660d3..f2e013c05e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_file.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_file.cc
@@ -54,72 +54,105 @@ namespace google {
namespace protobuf {
namespace compiler {
namespace cpp {
+namespace {
+// The list of names that are defined as macros on some platforms. We need to
+// #undef them for the generated code to compile.
+const char* kMacroNames[] = {"major", "minor"};
+
+bool IsMacroName(const string& name) {
+ // Just do a linear search as the number of elements is very small.
+ for (int i = 0; i < GOOGLE_ARRAYSIZE(kMacroNames); ++i) {
+ if (name == kMacroNames[i]) return true;
+ }
+ return false;
+}
+
+void CollectMacroNames(const Descriptor* message, vector<string>* names) {
+ for (int i = 0; i < message->field_count(); ++i) {
+ const FieldDescriptor* field = message->field(i);
+ if (IsMacroName(field->name())) {
+ names->push_back(field->name());
+ }
+ }
+ for (int i = 0; i < message->nested_type_count(); ++i) {
+ CollectMacroNames(message->nested_type(i), names);
+ }
+}
+
+void CollectMacroNames(const FileDescriptor* file, vector<string>* names) {
+ for (int i = 0; i < file->message_type_count(); ++i) {
+ CollectMacroNames(file->message_type(i), names);
+ }
+}
+
+
+} // namespace
// ===================================================================
FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options)
: file_(file),
options_(options),
- message_generators_(
- new google::protobuf::scoped_ptr<MessageGenerator>[file->message_type_count()]),
- enum_generators_(
- new google::protobuf::scoped_ptr<EnumGenerator>[file->enum_type_count()]),
- service_generators_(
- new google::protobuf::scoped_ptr<ServiceGenerator>[file->service_count()]),
- extension_generators_(
- new google::protobuf::scoped_ptr<ExtensionGenerator>[file->extension_count()]) {
+ message_generators_owner_(
+ new google::protobuf::scoped_ptr<MessageGenerator>[ file->message_type_count() ]),
+ enum_generators_owner_(
+ new google::protobuf::scoped_ptr<EnumGenerator>[ file->enum_type_count() ]),
+ service_generators_owner_(
+ new google::protobuf::scoped_ptr<ServiceGenerator>[ file->service_count() ]),
+ extension_generators_owner_(
+ new google::protobuf::scoped_ptr<ExtensionGenerator>[ file->extension_count() ]) {
for (int i = 0; i < file->message_type_count(); i++) {
- message_generators_[i].reset(
- new MessageGenerator(file->message_type(i), options));
+ message_generators_owner_[i].reset(
+ new MessageGenerator(file->message_type(i), options));
+ message_generators_owner_[i]->Flatten(&message_generators_);
+ }
+
+ for (int i = 0; i < message_generators_.size(); i++) {
+ message_generators_[i]->AddGenerators(&enum_generators_,
+ &extension_generators_);
}
for (int i = 0; i < file->enum_type_count(); i++) {
- enum_generators_[i].reset(
- new EnumGenerator(file->enum_type(i), options));
+ enum_generators_owner_[i].reset(
+ new EnumGenerator(file->enum_type(i), options));
+ enum_generators_.push_back(enum_generators_owner_[i].get());
}
for (int i = 0; i < file->service_count(); i++) {
- service_generators_[i].reset(
- new ServiceGenerator(file->service(i), options));
+ service_generators_owner_[i].reset(
+ new ServiceGenerator(file->service(i), options));
+ service_generators_.push_back(service_generators_owner_[i].get());
}
for (int i = 0; i < file->extension_count(); i++) {
- extension_generators_[i].reset(
- new ExtensionGenerator(file->extension(i), options));
+ extension_generators_owner_[i].reset(
+ new ExtensionGenerator(file->extension(i), options));
+ extension_generators_.push_back(extension_generators_owner_[i].get());
}
- SplitStringUsing(file_->package(), ".", &package_parts_);
+ package_parts_ = Split(file_->package(), ".", true);
}
FileGenerator::~FileGenerator() {}
-void FileGenerator::GenerateProtoHeader(io::Printer* printer,
- const string& info_path) {
- if (!options_.proto_h) {
- return;
- }
-
- string filename_identifier = FilenameIdentifier(file_->name());
- GenerateTopHeaderGuard(printer, filename_identifier);
-
-
- GenerateLibraryIncludes(printer);
-
- for (int i = 0; i < file_->public_dependency_count(); i++) {
- const FileDescriptor* dep = file_->public_dependency(i);
- const char* extension = ".proto.h";
- string dependency = StripProto(dep->name()) + extension;
+void FileGenerator::GenerateMacroUndefs(io::Printer* printer) {
+ vector<string> names_to_undef;
+ CollectMacroNames(file_, &names_to_undef);
+ for (int i = 0; i < names_to_undef.size(); ++i) {
printer->Print(
- "#include \"$dependency$\" // IWYU pragma: export\n",
- "dependency", dependency);
+ "#ifdef $name$\n"
+ "#undef $name$\n"
+ "#endif\n",
+ "name", names_to_undef[i]);
}
+}
- GenerateMetadataPragma(printer, info_path);
-
+void FileGenerator::GenerateHeader(io::Printer* printer) {
printer->Print(
"// @@protoc_insertion_point(includes)\n");
+ GenerateMacroUndefs(printer);
GenerateForwardDeclarations(printer);
@@ -166,6 +199,32 @@ void FileGenerator::GenerateProtoHeader(io::Printer* printer,
"\n"
"// @@protoc_insertion_point(global_scope)\n"
"\n");
+}
+
+void FileGenerator::GenerateProtoHeader(io::Printer* printer,
+ const string& info_path) {
+ if (!options_.proto_h) {
+ return;
+ }
+
+ string filename_identifier = FilenameIdentifier(file_->name());
+ GenerateTopHeaderGuard(printer, filename_identifier);
+
+
+ GenerateLibraryIncludes(printer);
+
+ for (int i = 0; i < file_->public_dependency_count(); i++) {
+ const FileDescriptor* dep = file_->public_dependency(i);
+ const char* extension = ".proto.h";
+ string dependency = StripProto(dep->name()) + extension;
+ printer->Print(
+ "#include \"$dependency$\" // IWYU pragma: export\n",
+ "dependency", dependency);
+ }
+
+ GenerateMetadataPragma(printer, info_path);
+
+ GenerateHeader(printer);
GenerateBottomHeaderGuard(printer, filename_identifier);
}
@@ -185,59 +244,29 @@ void FileGenerator::GeneratePBHeader(io::Printer* printer,
GenerateDependencyIncludes(printer);
GenerateMetadataPragma(printer, info_path);
- printer->Print(
- "// @@protoc_insertion_point(includes)\n");
-
-
-
- // Open namespace.
- GenerateNamespaceOpeners(printer);
-
if (!options_.proto_h) {
- GenerateGlobalStateFunctionDeclarations(printer);
- GenerateMessageForwardDeclarations(printer);
-
- printer->Print("\n");
-
- GenerateEnumDefinitions(printer);
-
- printer->Print(kThickSeparator);
- printer->Print("\n");
-
- GenerateMessageDefinitions(printer);
-
- printer->Print("\n");
- printer->Print(kThickSeparator);
- printer->Print("\n");
-
- GenerateServiceDefinitions(printer);
-
- GenerateExtensionIdentifiers(printer);
-
- printer->Print("\n");
- printer->Print(kThickSeparator);
- printer->Print("\n");
-
- GenerateInlineFunctionDefinitions(printer);
- }
-
- printer->Print(
- "\n"
- "// @@protoc_insertion_point(namespace_scope)\n");
+ GenerateHeader(printer);
+ } else {
+ // This is unfortunately necessary for some plugins. I don't see why we
+ // need two of the same insertion points.
+ // TODO(gerbens) remove this.
+ printer->Print(
+ "// @@protoc_insertion_point(includes)\n");
- // Close up namespace.
- GenerateNamespaceClosers(printer);
+ // Open namespace.
+ GenerateNamespaceOpeners(printer);
+ printer->Print(
+ "\n"
+ "// @@protoc_insertion_point(namespace_scope)\n");
+ // Close up namespace.
+ GenerateNamespaceClosers(printer);
- if (!options_.proto_h) {
- // We need to specialize some templates in the ::google::protobuf namespace:
- GenerateProto2NamespaceEnumSpecializations(printer);
+ printer->Print(
+ "\n"
+ "// @@protoc_insertion_point(global_scope)\n"
+ "\n");
}
- printer->Print(
- "\n"
- "// @@protoc_insertion_point(global_scope)\n"
- "\n");
-
GenerateBottomHeaderGuard(printer, filename_identifier);
}
@@ -267,7 +296,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
"right", use_system_include ? ">" : "\"");
// Unknown fields implementation in lite mode uses StringOutputStream
- if (!UseUnknownFieldSet(file_, options_) && file_->message_type_count() > 0) {
+ if (!UseUnknownFieldSet(file_, options_) && !message_generators_.empty()) {
printer->Print(
"#include <google/protobuf/io/zero_copy_stream_impl_lite.h>\n");
}
@@ -297,26 +326,59 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
GenerateNamespaceOpeners(printer);
+ for (int i = 0; i < message_generators_.size(); i++) {
+ if (IsMapEntryMessage(message_generators_[i]->descriptor_)) continue;
+ printer->Print(
+ "class $classname$DefaultTypeInternal : "
+ "public ::google::protobuf::internal::ExplicitlyConstructed<$classname$> {\n",
+ "classname", message_generators_[i]->classname_);
+ printer->Indent();
+ message_generators_[i]->GenerateExtraDefaultFields(printer);
+ printer->Outdent();
+ printer->Print(
+ "} _$classname$_default_instance_;\n",
+ "classname", message_generators_[i]->classname_);
+ }
+
+ for (int i = 0; i < message_generators_.size(); i++) {
+ message_generators_[i]->index_in_metadata_ = i;
+ }
+ for (int i = 0; i < enum_generators_.size(); i++) {
+ enum_generators_[i]->index_in_metadata_ = i;
+ }
+ if (HasGenericServices(file_, options_)) {
+ for (int i = 0; i < service_generators_.size(); i++) {
+ service_generators_[i]->index_in_metadata_ = i;
+ }
+ }
+
+ printer->Print(
+ "\n"
+ "namespace $file_namespace$ {\n"
+ "\n",
+ "file_namespace", FileLevelNamespace(file_->name()));
+
if (HasDescriptorMethods(file_, options_)) {
printer->Print(
"\n"
"namespace {\n"
"\n");
- for (int i = 0; i < file_->message_type_count(); i++) {
- message_generators_[i]->GenerateDescriptorDeclarations(printer);
+
+ if (!message_generators_.empty()) {
+ printer->Print("::google::protobuf::Metadata file_level_metadata[$size$];\n",
+ "size", SimpleItoa(message_generators_.size()));
}
- for (int i = 0; i < file_->enum_type_count(); i++) {
+ if (!enum_generators_.empty()) {
printer->Print(
- "const ::google::protobuf::EnumDescriptor* $name$_descriptor_ = NULL;\n",
- "name", ClassName(file_->enum_type(i), false));
+ "const ::google::protobuf::EnumDescriptor* "
+ "file_level_enum_descriptors[$size$];\n",
+ "size", SimpleItoa(enum_generators_.size()));
}
-
- if (HasGenericServices(file_, options_)) {
- for (int i = 0; i < file_->service_count(); i++) {
- printer->Print(
- "const ::google::protobuf::ServiceDescriptor* $name$_descriptor_ = NULL;\n",
- "name", file_->service(i)->name());
- }
+ if (HasGenericServices(file_, options_) && file_->service_count() > 0) {
+ printer->Print(
+ "const ::google::protobuf::ServiceDescriptor* "
+ "file_level_service_descriptors[$size$];\n",
+ "size", SimpleItoa(file_->service_count()));
}
printer->Print(
@@ -329,13 +391,19 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
// library, all this does is initialize default instances.)
GenerateBuildDescriptors(printer);
+ printer->Print(
+ "\n"
+ "} // namespace $file_namespace$\n"
+ "\n",
+ "file_namespace", FileLevelNamespace(file_->name()));
+
// Generate enums.
- for (int i = 0; i < file_->enum_type_count(); i++) {
+ for (int i = 0; i < enum_generators_.size(); i++) {
enum_generators_[i]->GenerateMethods(printer);
}
// Generate classes.
- for (int i = 0; i < file_->message_type_count(); i++) {
+ for (int i = 0; i < message_generators_.size(); i++) {
printer->Print("\n");
printer->Print(kThickSeparator);
printer->Print("\n");
@@ -350,7 +418,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
if (HasGenericServices(file_, options_)) {
// Generate services.
- for (int i = 0; i < file_->service_count(); i++) {
+ for (int i = 0; i < service_generators_.size(); i++) {
if (i == 0) printer->Print("\n");
printer->Print(kThickSeparator);
printer->Print("\n");
@@ -359,7 +427,7 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
}
// Define extensions.
- for (int i = 0; i < file_->extension_count(); i++) {
+ for (int i = 0; i < extension_generators_.size(); i++) {
extension_generators_[i]->GenerateDefinition(printer);
}
@@ -377,8 +445,9 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
class FileGenerator::ForwardDeclarations {
public:
~ForwardDeclarations() {
- for (map<string, ForwardDeclarations *>::iterator it = namespaces_.begin(),
- end = namespaces_.end();
+ for (std::map<string, ForwardDeclarations*>::iterator
+ it = namespaces_.begin(),
+ end = namespaces_.end();
it != end; ++it) {
delete it->second;
}
@@ -393,11 +462,11 @@ class FileGenerator::ForwardDeclarations {
return ns;
}
- map<string, const Descriptor*>& classes() { return classes_; }
- map<string, const EnumDescriptor*>& enums() { return enums_; }
+ std::map<string, const Descriptor*>& classes() { return classes_; }
+ std::map<string, const EnumDescriptor*>& enums() { return enums_; }
- void Print(io::Printer* printer) const {
- for (map<string, const EnumDescriptor *>::const_iterator
+ void Print(io::Printer* printer, const Options& options) const {
+ for (std::map<string, const EnumDescriptor *>::const_iterator
it = enums_.begin(),
end = enums_.end();
it != end; ++it) {
@@ -406,19 +475,30 @@ class FileGenerator::ForwardDeclarations {
printer->Print("bool $enumname$_IsValid(int value);\n", "enumname",
it->first);
}
- for (map<string, const Descriptor *>::const_iterator it = classes_.begin(),
- end = classes_.end();
+ for (std::map<string, const Descriptor*>::const_iterator
+ it = classes_.begin(),
+ end = classes_.end();
it != end; ++it) {
printer->Print("class $classname$;\n", "classname", it->first);
printer->Annotate("classname", it->second);
+
+ printer->Print(
+ "class $classname$DefaultTypeInternal;\n"
+ "$dllexport_decl$"
+ "extern $classname$DefaultTypeInternal "
+ "_$classname$_default_instance_;\n", // NOLINT
+ "dllexport_decl",
+ options.dllexport_decl.empty() ? "" : options.dllexport_decl + " ",
+ "classname",
+ it->first);
}
- for (map<string, ForwardDeclarations *>::const_iterator
+ for (std::map<string, ForwardDeclarations *>::const_iterator
it = namespaces_.begin(),
end = namespaces_.end();
it != end; ++it) {
printer->Print("namespace $nsname$ {\n",
"nsname", it->first);
- it->second->Print(printer);
+ it->second->Print(printer, options);
printer->Print("} // namespace $nsname$\n",
"nsname", it->first);
}
@@ -426,9 +506,9 @@ class FileGenerator::ForwardDeclarations {
private:
- map<string, ForwardDeclarations*> namespaces_;
- map<string, const Descriptor*> classes_;
- map<string, const EnumDescriptor*> enums_;
+ std::map<string, ForwardDeclarations*> namespaces_;
+ std::map<string, const Descriptor*> classes_;
+ std::map<string, const EnumDescriptor*> enums_;
};
void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
@@ -449,76 +529,114 @@ 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"
- "void $assigndescriptorsname$() GOOGLE_ATTRIBUTE_COLD;\n"
- "void $assigndescriptorsname$() {\n",
- "assigndescriptorsname", GlobalAssignDescriptorsName(file_->name()));
- printer->Indent();
- // Make sure the file has found its way into the pool. If a descriptor
- // is requested *during* static init then AddDescriptors() may not have
- // been called yet, so we call it manually. Note that it's fine if
- // AddDescriptors() is called multiple times.
- printer->Print(
- "$adddescriptorsname$();\n",
- "adddescriptorsname", GlobalAddDescriptorsName(file_->name()));
-
- // Get the file's descriptor from the pool.
- printer->Print(
- "const ::google::protobuf::FileDescriptor* file =\n"
- " ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(\n"
- " \"$filename$\");\n"
- // Note that this GOOGLE_CHECK is necessary to prevent a warning about "file"
- // being unused when compiling an empty .proto file.
- "GOOGLE_CHECK(file != NULL);\n",
- "filename", file_->name());
+ if (HasDescriptorMethods(file_, options_)) {
+ if (!message_generators_.empty()) {
+ printer->Print("const ::google::protobuf::uint32 TableStruct::offsets[] = {\n");
+ printer->Indent();
+ std::vector<std::pair<size_t, size_t> > pairs;
+ for (int i = 0; i < message_generators_.size(); i++) {
+ pairs.push_back(message_generators_[i]->GenerateOffsets(printer));
+ }
+ printer->Outdent();
+ printer->Print(
+ "};\n"
+ "\n"
+ "static const ::google::protobuf::internal::MigrationSchema schemas[] = {\n");
+ printer->Indent();
+ {
+ int offset = 0;
+ for (int i = 0; i < message_generators_.size(); i++) {
+ message_generators_[i]->GenerateSchema(printer, offset,
+ pairs[i].second);
+ offset += pairs[i].first;
+ }
+ }
+ printer->Outdent();
+ printer->Print(
+ "};\n"
+ "\nstatic "
+ "::google::protobuf::Message const * const file_default_instances[] = {\n");
+ printer->Indent();
+ for (int i = 0; i < message_generators_.size(); i++) {
+ const Descriptor* descriptor = message_generators_[i]->descriptor_;
+ if (IsMapEntryMessage(descriptor)) continue;
- // Go through all the stuff defined in this file and generated code to
- // assign the global descriptor pointers based on the file descriptor.
- for (int i = 0; i < file_->message_type_count(); i++) {
- message_generators_[i]->GenerateDescriptorInitializer(printer, i);
- }
- for (int i = 0; i < file_->enum_type_count(); i++) {
- enum_generators_[i]->GenerateDescriptorInitializer(printer, i);
- }
- if (HasGenericServices(file_, options_)) {
- for (int i = 0; i < file_->service_count(); i++) {
- service_generators_[i]->GenerateDescriptorInitializer(printer, i);
+ printer->Print(
+ "reinterpret_cast<const "
+ "::google::protobuf::Message*>(&_$classname$_default_instance_),\n",
+ "classname", ClassName(descriptor, false));
}
+ printer->Outdent();
+ printer->Print(
+ "};\n"
+ "\n");
+ } else {
+ // we still need these symbols to exist
+ printer->Print(
+ // MSVC doesn't like empty arrays, so we add a dummy.
+ "const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u };\n"
+ "static const ::google::protobuf::internal::MigrationSchema* schemas = NULL;\n"
+ "static const ::google::protobuf::Message* const* "
+ "file_default_instances = NULL;\n");
}
- printer->Outdent();
- printer->Print(
- "}\n"
- "\n");
-
// ---------------------------------------------------------------
// protobuf_AssignDescriptorsOnce(): The first time it is called, calls
// AssignDescriptors(). All later times, waits for the first call to
// complete and then returns.
+ string message_factory = "NULL";
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()));
-
- // protobuf_RegisterTypes(): Calls
- // MessageFactory::InternalRegisterGeneratedType() for each message type.
+ "namespace {\n"
+ "\n"
+ "void protobuf_AssignDescriptors() {\n"
+ // Make sure the file has found its way into the pool. If a descriptor
+ // is requested *during* static init then AddDescriptors() may not have
+ // been called yet, so we call it manually. Note that it's fine if
+ // AddDescriptors() is called multiple times.
+ " AddDescriptors();\n"
+ " ::google::protobuf::MessageFactory* factory = $factory$;\n"
+ " AssignDescriptors(\n"
+ " \"$filename$\", schemas, file_default_instances, "
+ "TableStruct::offsets, factory,\n"
+ " $metadata$, $enum_descriptors$, $service_descriptors$);\n"
+ "}\n"
+ "\n"
+ "void protobuf_AssignDescriptorsOnce() {\n"
+ " static GOOGLE_PROTOBUF_DECLARE_ONCE(once);\n"
+ " ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);\n"
+ "}\n"
+ "\n",
+ "filename", file_->name(), "metadata",
+ !message_generators_.empty() ? "file_level_metadata" : "NULL",
+ "enum_descriptors",
+ !enum_generators_.empty() ? "file_level_enum_descriptors" : "NULL",
+ "service_descriptors",
+ HasGenericServices(file_, options_) && file_->service_count() > 0
+ ? "file_level_service_descriptors"
+ : "NULL",
+ "factory", message_factory);
+
+ // Only here because of useless string reference that we don't want in
+ // protobuf_AssignDescriptorsOnce, because that is called from all the
+ // GetMetadata member methods.
printer->Print(
"void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD;\n"
"void protobuf_RegisterTypes(const ::std::string&) {\n"
" protobuf_AssignDescriptorsOnce();\n");
printer->Indent();
- for (int i = 0; i < file_->message_type_count(); i++) {
+ // All normal messages can be done generically
+ if (!message_generators_.empty()) {
+ printer->Print(
+ "::google::protobuf::internal::RegisterAllTypes(file_level_metadata, $size$);\n",
+ "size", SimpleItoa(message_generators_.size()));
+ }
+
+ // Map types are treated special
+ // TODO(gerbens) find a way to treat maps more like normal messages.
+ for (int i = 0; i < message_generators_.size(); i++) {
message_generators_[i]->GenerateTypeRegistrations(printer);
}
@@ -534,11 +652,10 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
// ShutdownFile(): Deletes descriptors, default instances, etc. on shutdown.
printer->Print(
"\n"
- "void $shutdownfilename$() {\n",
- "shutdownfilename", GlobalShutdownFileName(file_->name()));
+ "void TableStruct::Shutdown() {\n");
printer->Indent();
- for (int i = 0; i < file_->message_type_count(); i++) {
+ for (int i = 0; i < message_generators_.size(); i++) {
message_generators_[i]->GenerateShutdownCode(printer);
}
@@ -548,44 +665,59 @@ 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"
- " GOOGLE_PROTOBUF_VERIFY_VERSION;\n"
- "\n",
- // Vars.
- "adddescriptorsname", GlobalAddDescriptorsName(file_->name()));
+ // Now generate the InitDefaultsImpl() function.
+ printer->Print(
+ "void TableStruct::InitDefaultsImpl() {\n"
+ " GOOGLE_PROTOBUF_VERIFY_VERSION;\n\n"
+ // Force initialization of primitive values we depend on.
+ " ::google::protobuf::internal::InitProtobufDefaults();\n");
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()));
+ string file_namespace = QualifiedFileLevelSymbol(
+ dependency->package(), FileLevelNamespace(dependency->name()));
// Call its AddDescriptors function.
- printer->Print(
- "$name$();\n",
- "name", add_desc_name);
+ printer->Print("$file_namespace$::InitDefaults();\n", "file_namespace",
+ file_namespace);
+ }
+
+ // 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 < message_generators_.size(); i++) {
+ message_generators_[i]->GenerateDefaultInstanceAllocator(printer);
+ }
+ for (int i = 0; i < extension_generators_.size(); i++) {
+ extension_generators_[i]->GenerateRegistration(printer);
+ }
+ for (int i = 0; i < message_generators_.size(); i++) {
+ message_generators_[i]->GenerateDefaultInstanceInitializer(printer);
}
+ printer->Outdent();
+ printer->Print(
+ "}\n"
+ "\n"
+ "void InitDefaults() {\n"
+ " static GOOGLE_PROTOBUF_DECLARE_ONCE(once);\n"
+ " ::google::protobuf::GoogleOnceInit(&once, &TableStruct::InitDefaultsImpl);\n"
+ "}\n");
+
+ // -----------------------------------------------------------------
+
+ // Now generate the AddDescriptors() function.
+ printer->Print(
+ "void AddDescriptorsImpl() {\n"
+ " InitDefaults();\n");
+ 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;
@@ -593,60 +725,37 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) {
string file_data;
file_proto.SerializeToString(&file_data);
-#ifdef _MSC_VER
- bool breakdown_large_file = true;
-#else
- bool breakdown_large_file = false;
-#endif
- // Workaround for MSVC: "Error C1091: compiler limit: string exceeds 65535
- // bytes in length". Declare a static array of characters rather than use a
- // string literal.
- if (breakdown_large_file && file_data.size() > 65535) {
- // This has to be explicitly marked as a signed char because the generated
- // code puts negative values in the array, and sometimes plain char is
- // unsigned. That implicit narrowing conversion is not allowed in C++11.
- // <http://stackoverflow.com/questions/4434140/narrowing-conversions-in-c0x-is-it-just-me-or-does-this-sound-like-a-breakin>
- // has details on why.
- printer->Print(
- "static const signed char descriptor[] = {\n");
- printer->Indent();
+ printer->Print("static const char descriptor[] = {\n");
+ printer->Indent();
- // Only write 25 bytes per line.
+ if (file_data.size() > 66535) {
+ // Workaround for MSVC: "Error C1091: compiler limit: string exceeds 65535
+ // bytes in length". Declare a static array of characters rather than use
+ // a string literal. Only write 25 bytes per line.
static const int kBytesPerLine = 25;
for (int i = 0; i < file_data.size();) {
- for (int j = 0; j < kBytesPerLine && i < file_data.size(); ++i, ++j) {
- printer->Print(
- "$char$, ",
- "char", SimpleItoa(file_data[i]));
- }
- printer->Print(
- "\n");
+ for (int j = 0; j < kBytesPerLine && i < file_data.size(); ++i, ++j) {
+ printer->Print("'$char$', ", "char",
+ CEscape(file_data.substr(i, 1)));
+ }
+ printer->Print("\n");
}
-
- printer->Outdent();
- printer->Print(
- "};\n");
-
- printer->Print(
- "::google::protobuf::DescriptorPool::InternalAddGeneratedFile(descriptor, $size$);\n",
- "size", SimpleItoa(file_data.size()));
-
} else {
- printer->Print(
- "::google::protobuf::DescriptorPool::InternalAddGeneratedFile(");
-
// Only write 40 bytes per line.
static const int kBytesPerLine = 40;
for (int i = 0; i < file_data.size(); i += kBytesPerLine) {
- printer->Print("\n \"$data$\"",
- "data",
- EscapeTrigraphs(
- CEscape(file_data.substr(i, kBytesPerLine))));
+ printer->Print(" \"$data$\"\n", "data",
+ EscapeTrigraphs(CEscape(
+ file_data.substr(i, kBytesPerLine))));
+ }
}
+
+ printer->Outdent();
+ printer->Print("};\n");
printer->Print(
- ", $size$);\n",
+ "::google::protobuf::DescriptorPool::InternalAddGeneratedFile(\n"
+ " descriptor, $size$);\n",
"size", SimpleItoa(file_data.size()));
- }
// Call MessageFactory::InternalRegisterGeneratedFile().
printer->Print(
@@ -655,46 +764,44 @@ 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 file_namespace = QualifiedFileLevelSymbol(
+ dependency->package(), FileLevelNamespace(dependency->name()));
+ // Call its AddDescriptors function.
+ printer->Print("$file_namespace$::AddDescriptors();\n", "file_namespace",
+ file_namespace);
}
printer->Print(
- "::google::protobuf::internal::OnShutdown(&$shutdownfilename$);\n",
- "shutdownfilename", GlobalShutdownFileName(file_->name()));
+ "::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown);\n");
printer->Outdent();
printer->Print(
- "}\n"
- "\n");
+ "}\n"
+ "\n"
+ "void AddDescriptors() {\n"
+ " static GOOGLE_PROTOBUF_DECLARE_ONCE(once);\n"
+ " ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);\n"
+ "}\n");
- 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"
- " StaticDescriptorInitializer_$filename$() {\n"
- " $adddescriptorsname$();\n"
+ "struct StaticDescriptorInitializer {\n"
+ " StaticDescriptorInitializer() {\n"
+ " AddDescriptors();\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()));
+ "} static_descriptor_initializer;\n");
+ if (!StaticInitializersForced(file_, options_)) {
+ printer->Print("#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER\n");
+ }
}
void FileGenerator::GenerateNamespaceOpeners(io::Printer* printer) {
@@ -722,7 +829,7 @@ void FileGenerator::GenerateForwardDeclarations(io::Printer* printer) {
dependency.FillForwardDeclarations(&decls);
}
FillForwardDeclarations(&decls);
- decls.Print(printer);
+ decls.Print(printer, options_);
}
void FileGenerator::FillForwardDeclarations(ForwardDeclarations* decls) {
@@ -734,14 +841,11 @@ void FileGenerator::FillForwardDeclarations(ForwardDeclarations* decls) {
decls = decls->AddOrGetNamespace(package_parts_[i]);
}
// Generate enum definitions.
- for (int i = 0; i < file_->message_type_count(); i++) {
- message_generators_[i]->FillEnumForwardDeclarations(&decls->enums());
- }
- for (int i = 0; i < file_->enum_type_count(); i++) {
+ for (int i = 0; i < enum_generators_.size(); i++) {
enum_generators_[i]->FillForwardDeclaration(&decls->enums());
}
// Generate forward declarations of classes.
- for (int i = 0; i < file_->message_type_count(); i++) {
+ for (int i = 0; i < message_generators_.size(); i++) {
message_generators_[i]->FillMessageForwardDeclarations(
&decls->classes());
}
@@ -795,14 +899,13 @@ void FileGenerator::GenerateLibraryIncludes(io::Printer* printer) {
// OK, it's now safe to #include other files.
printer->Print(
- "#include <google/protobuf/arena.h>\n"
- "#include <google/protobuf/arenastring.h>\n"
- "#include <google/protobuf/generated_message_util.h>\n");
- if (UseUnknownFieldSet(file_, options_)) {
- printer->Print(
+ "#include <google/protobuf/io/coded_stream.h>\n"
+ "#include <google/protobuf/arena.h>\n"
+ "#include <google/protobuf/arenastring.h>\n"
+ "#include <google/protobuf/generated_message_util.h>\n"
"#include <google/protobuf/metadata.h>\n");
- }
- if (file_->message_type_count() > 0) {
+
+ if (!message_generators_.empty()) {
if (HasDescriptorMethods(file_, options_)) {
printer->Print(
"#include <google/protobuf/message.h>\n");
@@ -812,8 +915,10 @@ void FileGenerator::GenerateLibraryIncludes(io::Printer* printer) {
}
}
printer->Print(
- "#include <google/protobuf/repeated_field.h>\n"
- "#include <google/protobuf/extension_set.h>\n");
+ "#include <google/protobuf/repeated_field.h>"
+ " // IWYU pragma: export\n"
+ "#include <google/protobuf/extension_set.h>"
+ " // IWYU pragma: export\n");
if (HasMapFields(file_)) {
printer->Print(
"#include <google/protobuf/map.h>\n");
@@ -841,7 +946,7 @@ void FileGenerator::GenerateLibraryIncludes(io::Printer* printer) {
"#include <google/protobuf/service.h>\n");
}
- if (UseUnknownFieldSet(file_, options_) && file_->message_type_count() > 0) {
+ if (UseUnknownFieldSet(file_, options_) && !message_generators_.empty()) {
printer->Print(
"#include <google/protobuf/unknown_field_set.h>\n");
}
@@ -867,7 +972,7 @@ void FileGenerator::GenerateMetadataPragma(io::Printer* printer,
}
void FileGenerator::GenerateDependencyIncludes(io::Printer* printer) {
- set<string> public_import_names;
+ std::set<string> public_import_names;
for (int i = 0; i < file_->public_dependency_count(); i++) {
public_import_names.insert(file_->public_dependency(i)->name());
}
@@ -892,39 +997,28 @@ 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 + " ");
-
- printer->Print(
- // Note that we don't put dllexport_decl on these because they are only
- // called by the .pb.cc file in which they are defined.
- "void $assigndescriptorsname$();\n"
- "void $shutdownfilename$();\n"
- "\n",
- "assigndescriptorsname", GlobalAssignDescriptorsName(file_->name()),
- "shutdownfilename", GlobalShutdownFileName(file_->name()));
-}
-
-void FileGenerator::GenerateMessageForwardDeclarations(io::Printer* printer) {
- map<string, const Descriptor*> classes;
- for (int i = 0; i < file_->message_type_count(); i++) {
- message_generators_[i]->FillMessageForwardDeclarations(&classes);
- }
- for (map<string, const Descriptor *>::const_iterator it = classes.begin(),
- end = classes.end();
- it != end; ++it) {
- printer->Print("class $classname$;\n", "classname", it->first);
- printer->Annotate("classname", it->second);
- }
+ "\n"
+ "namespace $file_namespace$ {\n"
+ "// Internal implementation detail -- do not call these.\n"
+ "struct $dllexport_decl$TableStruct {\n"
+ " static const ::google::protobuf::uint32 offsets[];\n"
+ // The following function(s) need to be able to access private members of
+ // the messages defined in the file. So we make them static members.
+ // This is the internal implementation of InitDefaults. It should only
+ // be called by InitDefaults which makes sure it will be called only once.
+ " static void InitDefaultsImpl();\n"
+ " static void Shutdown();\n"
+ "};\n"
+ "void $dllexport_decl$AddDescriptors();\n"
+ "void $dllexport_decl$InitDefaults();\n"
+ "} // namespace $file_namespace$\n",
+ "file_namespace", FileLevelNamespace(file_->name()), "dllexport_decl",
+ options_.dllexport_decl.empty() ? "" : options_.dllexport_decl + " ");
}
void FileGenerator::GenerateMessageDefinitions(io::Printer* printer) {
// Generate class definitions.
- for (int i = 0; i < file_->message_type_count(); i++) {
+ for (int i = 0; i < message_generators_.size(); i++) {
if (i > 0) {
printer->Print("\n");
printer->Print(kThinSeparator);
@@ -936,10 +1030,7 @@ void FileGenerator::GenerateMessageDefinitions(io::Printer* printer) {
void FileGenerator::GenerateEnumDefinitions(io::Printer* printer) {
// Generate enum definitions.
- for (int i = 0; i < file_->message_type_count(); i++) {
- message_generators_[i]->GenerateEnumDefinitions(printer);
- }
- for (int i = 0; i < file_->enum_type_count(); i++) {
+ for (int i = 0; i < enum_generators_.size(); i++) {
enum_generators_[i]->GenerateDefinition(printer);
}
}
@@ -947,7 +1038,7 @@ void FileGenerator::GenerateEnumDefinitions(io::Printer* printer) {
void FileGenerator::GenerateServiceDefinitions(io::Printer* printer) {
if (HasGenericServices(file_, options_)) {
// Generate service definitions.
- for (int i = 0; i < file_->service_count(); i++) {
+ for (int i = 0; i < service_generators_.size(); i++) {
if (i > 0) {
printer->Print("\n");
printer->Print(kThinSeparator);
@@ -963,9 +1054,10 @@ void FileGenerator::GenerateServiceDefinitions(io::Printer* printer) {
}
void FileGenerator::GenerateExtensionIdentifiers(io::Printer* printer) {
- // Declare extension identifiers.
+ // Declare extension identifiers. These are in global scope and so only
+ // the global scope extensions.
for (int i = 0; i < file_->extension_count(); i++) {
- extension_generators_[i]->GenerateDeclaration(printer);
+ extension_generators_owner_[i]->GenerateDeclaration(printer);
}
}
@@ -1006,7 +1098,7 @@ void FileGenerator::GenerateInlineFunctionDefinitions(io::Printer* printer) {
printer->Print("#if !PROTOBUF_INLINE_NOT_IN_HEADERS\n");
// Generate class inline methods.
- for (int i = 0; i < file_->message_type_count(); i++) {
+ for (int i = 0; i < message_generators_.size(); i++) {
if (i > 0) {
printer->Print(kThinSeparator);
printer->Print("\n");
@@ -1016,7 +1108,7 @@ void FileGenerator::GenerateInlineFunctionDefinitions(io::Printer* printer) {
}
printer->Print("#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS\n");
- for (int i = 0; i < file_->message_type_count(); i++) {
+ for (int i = 0; i < message_generators_.size(); i++) {
if (i > 0) {
printer->Print(kThinSeparator);
printer->Print("\n");
@@ -1039,10 +1131,7 @@ void FileGenerator::GenerateProto2NamespaceEnumSpecializations(
"#ifndef SWIG\n"
"namespace google {\nnamespace protobuf {\n"
"\n");
- for (int i = 0; i < file_->message_type_count(); i++) {
- message_generators_[i]->GenerateGetEnumDescriptorSpecializations(printer);
- }
- for (int i = 0; i < file_->enum_type_count(); i++) {
+ for (int i = 0; i < enum_generators_.size(); i++) {
enum_generators_[i]->GenerateGetEnumDescriptorSpecializations(printer);
}
printer->Print(
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_file.h b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_file.h
index 5dcf692bcd..e3fbb96d23 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_file.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_file.h
@@ -68,6 +68,9 @@ class FileGenerator {
FileGenerator(const FileDescriptor* file, const Options& options);
~FileGenerator();
+ // Shared code between the two header generators below.
+ void GenerateHeader(io::Printer* printer);
+
// info_path, if non-empty, should be the path (relative to printer's output)
// to the metadata file describing this proto header.
void GenerateProtoHeader(io::Printer* printer,
@@ -117,18 +120,6 @@ class FileGenerator {
// Generates types for classes.
void GenerateMessageDefinitions(io::Printer* printer);
- // Generates forward-declarations for just this file's classes. This is
- // used for .pb.h headers, but not in proto_h mode.
- void GenerateMessageForwardDeclarations(io::Printer* printer);
-
- // Fills in types for forward declarations. This is used internally, and
- // also by other FileGenerators to determine imports' declarations.
- void FillMessageForwardDeclarations(ForwardDeclarations* decls);
- void FillMessageDefinitions(ForwardDeclarations* decls);
-
- // Generates enum definitions.
- void GenerateEnumForwardDeclarations(io::Printer* printer);
- void FillEnumForwardDeclarations(ForwardDeclarations* decls);
void GenerateEnumDefinitions(io::Printer* printer);
// Generates generic service definitions.
@@ -142,16 +133,37 @@ class FileGenerator {
void GenerateProto2NamespaceEnumSpecializations(io::Printer* printer);
+ // Sometimes the names we use in a .proto file happen to be defined as macros
+ // on some platforms (e.g., macro/minor used in plugin.proto are defined as
+ // macros in sys/types.h on FreeBSD and a few other platforms). To make the
+ // generated code compile on these platforms, we either have to undef the
+ // macro for these few platforms, or rename the field name for all platforms.
+ // Since these names are part of protobuf public API, renaming is generally
+ // a breaking change so we prefer the #undef approach.
+ void GenerateMacroUndefs(io::Printer* printer);
+
const FileDescriptor* file_;
const Options options_;
- google::protobuf::scoped_array<google::protobuf::scoped_ptr<MessageGenerator> > message_generators_;
- google::protobuf::scoped_array<google::protobuf::scoped_ptr<EnumGenerator> > enum_generators_;
- google::protobuf::scoped_array<google::protobuf::scoped_ptr<ServiceGenerator> > service_generators_;
- google::protobuf::scoped_array<google::protobuf::scoped_ptr<ExtensionGenerator> > extension_generators_;
+ // Contains the post-order walk of all the messages (and child messages) in
+ // this file. If you need a pre-order walk just reverse iterate.
+ std::vector<MessageGenerator*> message_generators_;
+ std::vector<EnumGenerator*> enum_generators_;
+ std::vector<ServiceGenerator*> service_generators_;
+ std::vector<ExtensionGenerator*> extension_generators_;
+
+ // These members are just for owning (and thus proper deleting). Some of the
+ // message_ and enum_generators above are owned by child messages.
+ google::protobuf::scoped_array<google::protobuf::scoped_ptr<MessageGenerator> >
+ message_generators_owner_;
+ google::protobuf::scoped_array<google::protobuf::scoped_ptr<EnumGenerator> > enum_generators_owner_;
+ google::protobuf::scoped_array<google::protobuf::scoped_ptr<ServiceGenerator> >
+ service_generators_owner_;
+ google::protobuf::scoped_array<google::protobuf::scoped_ptr<ExtensionGenerator> >
+ extension_generators_owner_;
// E.g. if the package is foo.bar, package_parts_ is {"foo", "bar"}.
- vector<string> package_parts_;
+ std::vector<string> package_parts_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator);
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_generator.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.cc
index 31d189c255..648ab28a51 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_generator.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.cc
@@ -59,7 +59,7 @@ bool CppGenerator::Generate(const FileDescriptor* file,
const string& parameter,
GeneratorContext* generator_context,
string* error) const {
- vector<pair<string, string> > options;
+ std::vector<std::pair<string, string> > options;
ParseGeneratorParameter(parameter, &options);
// -----------------------------------------------------------------
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_generator.h b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.h
index 3d517cf4a5..3d517cf4a5 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_generator.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.cc
index 2ad4d36a58..3c4dddc590 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_helpers.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.cc
@@ -371,9 +371,9 @@ string DefaultValue(const FieldDescriptor* field) {
return "GOOGLE_ULONGLONG(" + SimpleItoa(field->default_value_uint64())+ ")";
case FieldDescriptor::CPPTYPE_DOUBLE: {
double value = field->default_value_double();
- if (value == numeric_limits<double>::infinity()) {
+ if (value == std::numeric_limits<double>::infinity()) {
return "::google::protobuf::internal::Infinity()";
- } else if (value == -numeric_limits<double>::infinity()) {
+ } else if (value == -std::numeric_limits<double>::infinity()) {
return "-::google::protobuf::internal::Infinity()";
} else if (value != value) {
return "::google::protobuf::internal::NaN()";
@@ -384,9 +384,9 @@ string DefaultValue(const FieldDescriptor* field) {
case FieldDescriptor::CPPTYPE_FLOAT:
{
float value = field->default_value_float();
- if (value == numeric_limits<float>::infinity()) {
+ if (value == std::numeric_limits<float>::infinity()) {
return "static_cast<float>(::google::protobuf::internal::Infinity())";
- } else if (value == -numeric_limits<float>::infinity()) {
+ } else if (value == -std::numeric_limits<float>::infinity()) {
return "static_cast<float>(-::google::protobuf::internal::Infinity())";
} else if (value != value) {
return "static_cast<float>(::google::protobuf::internal::NaN())";
@@ -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
@@ -439,19 +440,8 @@ string FilenameIdentifier(const string& filename) {
return result;
}
-// Return the name of the AddDescriptors() function for a given file.
-string GlobalAddDescriptorsName(const string& filename) {
- return "protobuf_AddDesc_" + FilenameIdentifier(filename);
-}
-
-// Return the name of the AssignDescriptors() function for a given file.
-string GlobalAssignDescriptorsName(const string& filename) {
- return "protobuf_AssignDesc_" + FilenameIdentifier(filename);
-}
-
-// Return the name of the ShutdownFile() function for a given file.
-string GlobalShutdownFileName(const string& filename) {
- return "protobuf_ShutdownFile_" + FilenameIdentifier(filename);
+string FileLevelNamespace(const string& filename) {
+ return "protobuf_" + FilenameIdentifier(filename);
}
// Return the qualified C++ name for a file level symbol.
@@ -500,40 +490,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<string, string> 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<string, string>& 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) {
@@ -631,7 +587,7 @@ static Utf8CheckMode GetUtf8CheckMode(const FieldDescriptor* field,
static void GenerateUtf8CheckCode(const FieldDescriptor* field,
const Options& options, bool for_parse,
- const map<string, string>& variables,
+ const std::map<string, string>& variables,
const char* parameters,
const char* strict_function,
const char* verify_function,
@@ -681,7 +637,7 @@ static void GenerateUtf8CheckCode(const FieldDescriptor* field,
void GenerateUtf8CheckCodeForString(const FieldDescriptor* field,
const Options& options, bool for_parse,
- const map<string, string>& variables,
+ const std::map<string, string>& variables,
const char* parameters,
io::Printer* printer) {
GenerateUtf8CheckCode(field, options, for_parse, variables, parameters,
@@ -691,7 +647,7 @@ void GenerateUtf8CheckCodeForString(const FieldDescriptor* field,
void GenerateUtf8CheckCodeForCord(const FieldDescriptor* field,
const Options& options, bool for_parse,
- const map<string, string>& variables,
+ const std::map<string, string>& variables,
const char* parameters,
io::Printer* printer) {
GenerateUtf8CheckCode(field, options, for_parse, variables, parameters,
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_helpers.h b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.h
index 018acfcad0..0f297ec8b1 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_helpers.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.h
@@ -144,18 +144,13 @@ string DefaultValue(const FieldDescriptor* field);
// Convert a file name into a valid identifier.
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 AssignDescriptors() function for a given file.
-string GlobalAssignDescriptorsName(const string& filename);
+// For each .proto file generates a unique namespace. In this namespace global
+// definitions are put to prevent collisions.
+string FileLevelNamespace(const string& filename);
// Return the qualified C++ name for a file level symbol.
string QualifiedFileLevelSymbol(const string& package, const string& name);
-// Return the name of the ShutdownFile() function for a given file.
-string GlobalShutdownFileName(const string& filename);
-
// Escape C++ trigraphs by escaping question marks to \?
string EscapeTrigraphs(const string& to_escape);
@@ -223,22 +218,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<string, string>& 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();
@@ -282,13 +261,13 @@ bool IsWellKnownMessage(const FileDescriptor* descriptor);
void GenerateUtf8CheckCodeForString(const FieldDescriptor* field,
const Options& options, bool for_parse,
- const map<string, string>& variables,
+ const std::map<string, string>& variables,
const char* parameters,
io::Printer* printer);
void GenerateUtf8CheckCodeForCord(const FieldDescriptor* field,
const Options& options, bool for_parse,
- const map<string, string>& variables,
+ const std::map<string, string>& variables,
const char* parameters, io::Printer* printer);
inline ::google::protobuf::FileOptions_OptimizeMode GetOptimizeFor(
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_map_field.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_map_field.cc
index 0588e34ecd..b4eaf485d0 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_map_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_map_field.cc
@@ -45,10 +45,12 @@ bool IsProto3Field(const FieldDescriptor* field_descriptor) {
}
void SetMessageVariables(const FieldDescriptor* descriptor,
- map<string, string>* variables,
+ std::map<string, string>* variables,
const Options& options) {
SetCommonFieldVariables(descriptor, variables, options);
- (*variables)["type"] = FieldMessageTypeName(descriptor);
+ (*variables)["type"] = ClassName(descriptor->message_type(), false);
+ (*variables)["file_namespace"] =
+ FileLevelNamespace(descriptor->file()->name());
(*variables)["stream_writer"] =
(*variables)["declared_type"] +
(HasFastArraySerialization(descriptor->message_type()->file(), options)
@@ -137,7 +139,7 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
void MapFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer,
bool is_inline) const {
- map<string, string> variables(variables_);
+ std::map<string, string> variables(variables_);
variables["inline"] = is_inline ? "inline" : "";
printer->Print(variables,
"$inline$ const ::google::protobuf::Map< $key_cpp$, $val_cpp$ >&\n"
@@ -154,7 +156,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
void MapFieldGenerator::
GenerateClearingCode(io::Printer* printer) const {
- map<string, string> variables(variables_);
+ std::map<string, string> variables(variables_);
variables["this_message"] = dependent_field_ ? DependentBaseDownCast() : "";
printer->Print(variables, "$this_message$$name$_.Clear();\n");
}
@@ -173,14 +175,20 @@ void MapFieldGenerator::
GenerateConstructorCode(io::Printer* printer) const {
if (HasDescriptorMethods(descriptor_->file(), options_)) {
printer->Print(variables_,
- "$name$_.SetAssignDescriptorCallback(\n"
- " protobuf_AssignDescriptorsOnce);\n"
- "$name$_.SetEntryDescriptor(\n"
- " &$type$_descriptor_);\n");
+ "$name$_.SetAssignDescriptorCallback(\n"
+ " $file_namespace$::protobuf_AssignDescriptorsOnce);\n"
+ "$name$_.SetEntryDescriptor(\n"
+ " &$type$_descriptor);\n");
}
}
void MapFieldGenerator::
+GenerateCopyConstructorCode(io::Printer* printer) const {
+ GenerateConstructorCode(printer);
+ GenerateMergingCode(printer);
+}
+
+void MapFieldGenerator::
GenerateMergeFromCodedStream(io::Printer* printer) const {
const FieldDescriptor* key_field =
descriptor_->message_type()->FindFieldByName("key");
@@ -224,7 +232,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
"->AddLengthDelimited($number$, data);\n");
} else {
printer->Print(variables_,
- " unknown_fields_stream.WriteVarint32($tag$);\n"
+ " unknown_fields_stream.WriteVarint32($tag$u);\n"
" unknown_fields_stream.WriteVarint32(data.size());\n"
" unknown_fields_stream.WriteString(data);\n");
}
@@ -252,7 +260,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
}
static void GenerateSerializationLoop(io::Printer* printer,
- const map<string, string>& variables,
+ const std::map<string, string>& variables,
bool supports_arenas,
const string& utf8_check,
const string& loop_header,
@@ -291,17 +299,17 @@ static void GenerateSerializationLoop(io::Printer* printer,
void MapFieldGenerator::
GenerateSerializeWithCachedSizes(io::Printer* printer) const {
- map<string, string> variables(variables_);
+ std::map<string, string> variables(variables_);
variables["write_entry"] = "::google::protobuf::internal::WireFormatLite::Write" +
variables["stream_writer"] + "(\n " +
variables["number"] + ", *entry, output)";
- variables["deterministic"] = "output->IsSerializationDeterminstic()";
+ variables["deterministic"] = "output->IsSerializationDeterministic()";
GenerateSerializeWithCachedSizes(printer, variables);
}
void MapFieldGenerator::
GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const {
- map<string, string> variables(variables_);
+ std::map<string, string> variables(variables_);
variables["write_entry"] =
"target = ::google::protobuf::internal::WireFormatLite::\n"
" InternalWrite" + variables["declared_type"] +
@@ -312,7 +320,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const {
}
void MapFieldGenerator::GenerateSerializeWithCachedSizes(
- io::Printer* printer, const map<string, string>& variables) const {
+ io::Printer* printer, const std::map<string, string>& variables) const {
printer->Print(variables,
"if (!this->$name$().empty()) {\n");
printer->Indent();
@@ -399,7 +407,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/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_map_field.h b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_map_field.h
index 2930fe59e9..816687b3a9 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_map_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_map_field.h
@@ -55,6 +55,7 @@ class MapFieldGenerator : public FieldGenerator {
void GenerateMergingCode(io::Printer* printer) const;
void GenerateSwappingCode(io::Printer* printer) const;
void GenerateConstructorCode(io::Printer* printer) const;
+ void GenerateCopyConstructorCode(io::Printer* printer) const;
void GenerateMergeFromCodedStream(io::Printer* printer) const;
void GenerateSerializeWithCachedSizes(io::Printer* printer) const;
void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const;
@@ -63,11 +64,11 @@ class MapFieldGenerator : public FieldGenerator {
private:
// A helper for GenerateSerializeWithCachedSizes{,ToArray}.
void GenerateSerializeWithCachedSizes(
- io::Printer* printer, const map<string, string>& variables) const;
+ io::Printer* printer, const std::map<string, string>& variables) const;
const FieldDescriptor* descriptor_;
const bool dependent_field_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapFieldGenerator);
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_message.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_message.cc
index 405a5fed55..1373ffc2c1 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_message.cc
+++ b/third_party/protobuf/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<const FieldDescriptor*> SortFieldsByNumber(
+ const Descriptor* descriptor) {
+ std::vector<const FieldDescriptor*> 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;
}
@@ -208,7 +207,7 @@ class FieldGroup {
}
void SetPreferredLocation(float location) { preferred_location_ = location; }
- const vector<const FieldDescriptor*>& fields() const { return fields_; }
+ const std::vector<const FieldDescriptor*>& fields() const { return fields_; }
// FieldGroup objects sort by their preferred location.
bool operator<(const FieldGroup& other) const {
@@ -222,64 +221,188 @@ class FieldGroup {
// approximate, but should put this group close to where its member fields
// originally went.
float preferred_location_;
- vector<const FieldDescriptor*> fields_;
+ std::vector<const FieldDescriptor*> fields_;
// We rely on the default copy constructor and operator= so this type can be
// 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;
+ }
+}
+
+bool IsPOD(const FieldDescriptor* field) {
+ if (field->is_repeated() || field->is_extension()) return false;
+ switch (field->cpp_type()) {
+ case internal::WireFormatLite::CPPTYPE_ENUM:
+ case internal::WireFormatLite::CPPTYPE_INT32:
+ case internal::WireFormatLite::CPPTYPE_INT64:
+ case internal::WireFormatLite::CPPTYPE_UINT32:
+ case internal::WireFormatLite::CPPTYPE_UINT64:
+ case internal::WireFormatLite::CPPTYPE_FLOAT:
+ case internal::WireFormatLite::CPPTYPE_DOUBLE:
+ case internal::WireFormatLite::CPPTYPE_BOOL:
+ return true;
+ case internal::WireFormatLite::CPPTYPE_STRING:
+ return false;
+ default:
+ return false;
+ }
+}
+
+// Helper for the code that emits the SharedCtor() method.
+bool CanConstructByZeroing(const FieldDescriptor* field,
+ const Options& options) {
+ bool ret = CanInitializeByZeroing(field);
+
+ // Non-repeated, non-lazy message fields are simply raw pointers, so we can
+ // use memset to initialize these in SharedCtor. We cannot use this in
+ // Clear, as we need to potentially delete the existing value.
+ ret = ret ||
+ (!field->is_repeated() &&
+ field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE);
+ return ret;
+}
+
// 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.
-void OptimizePadding(vector<const FieldDescriptor*>* fields) {
+// 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): 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), which allows them to be
+// memset.
+//
+// ZERO_INITIALIZABLE is memset in Clear/SharedCtor
+//
+// OTHER these fields are initialized one-by-one.
+void OptimizePadding(std::vector<const FieldDescriptor*>* fields,
+ const Options& options) {
+ // The sorted numeric order of Family determines the declaration order in the
+ // memory layout.
+ enum Family {
+ REPEATED = 0,
+ STRING = 1,
+ MESSAGE = 2,
+ ZERO_INITIALIZABLE = 4,
+ OTHER = 5,
+ kMaxFamily
+ };
+
// First divide fields into those that align to 1 byte, 4 bytes or 8 bytes.
- vector<FieldGroup> aligned_to_1, aligned_to_4, aligned_to_8;
+ std::vector<FieldGroup> aligned_to_1[kMaxFamily];
+ std::vector<FieldGroup> aligned_to_4[kMaxFamily];
+ std::vector<FieldGroup> 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());
+ }
}
}
@@ -339,7 +462,7 @@ bool HasHasMethod(const FieldDescriptor* field) {
// Collects map entry message type information.
void CollectMapInfo(const Descriptor* descriptor,
- map<string, string>* variables) {
+ std::map<string, string>* variables) {
GOOGLE_CHECK(IsMapEntryMessage(descriptor));
const FieldDescriptor* key = descriptor->FindFieldByName("key");
const FieldDescriptor* val = descriptor->FindFieldByName("value");
@@ -371,6 +494,7 @@ bool HasPrivateHasMethod(const FieldDescriptor* field) {
field->containing_oneof() != NULL);
}
+
} // anonymous namespace
// ===================================================================
@@ -381,6 +505,7 @@ MessageGenerator::MessageGenerator(const Descriptor* descriptor,
classname_(ClassName(descriptor, false)),
options_(options),
field_generators_(descriptor, options),
+ max_has_bit_index_(0),
nested_generators_(new google::protobuf::scoped_ptr<
MessageGenerator>[descriptor->nested_type_count()]),
enum_generators_(
@@ -389,6 +514,29 @@ 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_, options_);
+
+ if (HasFieldPresence(descriptor_->file())) {
+ // We use -1 as a sentinel.
+ has_bit_indices_.resize(descriptor_->field_count(), -1);
+ for (int i = 0; i < optimized_order_.size(); i++) {
+ const FieldDescriptor* field = optimized_order_[i];
+ // Skip fields that do not have has bits.
+ if (field->is_repeated()) {
+ continue;
+ }
+
+ has_bit_indices_[field->index()] = max_has_bit_index_++;
+ }
+ }
+
for (int i = 0; i < descriptor->nested_type_count(); i++) {
nested_generators_[i].reset(
new MessageGenerator(descriptor->nested_type(i), options));
@@ -421,48 +569,41 @@ MessageGenerator::MessageGenerator(const Descriptor* descriptor,
MessageGenerator::~MessageGenerator() {}
-void MessageGenerator::
-FillMessageForwardDeclarations(map<string, const Descriptor*>* class_names) {
- (*class_names)[classname_] = descriptor_;
-
- for (int i = 0; i < descriptor_->nested_type_count(); i++) {
- // map entry message doesn't need forward declaration. Since map entry
- // message cannot be a top level class, we just need to avoid calling
- // GenerateForwardDeclaration here.
- if (IsMapEntryMessage(descriptor_->nested_type(i))) continue;
- nested_generators_[i]->FillMessageForwardDeclarations(class_names);
+size_t MessageGenerator::HasBitsSize() const {
+ size_t sizeof_has_bits = (max_has_bit_index_ + 31) / 32 * 4;
+ if (sizeof_has_bits == 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;
}
-}
-void MessageGenerator::
-FillEnumForwardDeclarations(map<string, const EnumDescriptor*>* enum_names) {
- for (int i = 0; i < descriptor_->nested_type_count(); i++) {
- nested_generators_[i]->FillEnumForwardDeclarations(enum_names);
- }
- for (int i = 0; i < descriptor_->enum_type_count(); i++) {
- enum_generators_[i]->FillForwardDeclaration(enum_names);
- }
+ return sizeof_has_bits;
}
-void MessageGenerator::
-GenerateEnumDefinitions(io::Printer* printer) {
+void MessageGenerator::Flatten(std::vector<MessageGenerator*>* list) {
for (int i = 0; i < descriptor_->nested_type_count(); i++) {
- nested_generators_[i]->GenerateEnumDefinitions(printer);
+ nested_generators_[i]->Flatten(list);
}
+ list->push_back(this);
+}
+void MessageGenerator::AddGenerators(
+ std::vector<EnumGenerator*>* enum_generators,
+ std::vector<ExtensionGenerator*>* extension_generators) {
for (int i = 0; i < descriptor_->enum_type_count(); i++) {
- enum_generators_[i]->GenerateDefinition(printer);
+ enum_generators->push_back(enum_generators_[i].get());
+ }
+ for (int i = 0; i < descriptor_->extension_count(); i++) {
+ extension_generators->push_back(extension_generators_[i].get());
}
}
-void MessageGenerator::
-GenerateGetEnumDescriptorSpecializations(io::Printer* printer) {
- for (int i = 0; i < descriptor_->nested_type_count(); i++) {
- nested_generators_[i]->GenerateGetEnumDescriptorSpecializations(printer);
- }
- for (int i = 0; i < descriptor_->enum_type_count(); i++) {
- enum_generators_[i]->GenerateGetEnumDescriptorSpecializations(printer);
- }
+void MessageGenerator::FillMessageForwardDeclarations(
+ std::map<string, const Descriptor*>* class_names) {
+ if (IsMapEntryMessage(descriptor_)) return;
+ (*class_names)[classname_] = descriptor_;
}
void MessageGenerator::
@@ -472,7 +613,7 @@ GenerateDependentFieldAccessorDeclarations(io::Printer* printer) {
PrintFieldComment(printer, field);
- map<string, string> vars;
+ std::map<string, string> vars;
SetCommonFieldVariables(field, &vars, options_);
if (use_dependent_base_ && IsFieldDependent(field)) {
@@ -489,12 +630,32 @@ GenerateDependentFieldAccessorDeclarations(io::Printer* printer) {
void MessageGenerator::
GenerateFieldAccessorDeclarations(io::Printer* printer) {
+ // optimized_fields_ does not contain fields where
+ // field->containing_oneof() != NULL
+ // so we need to iterate over those as well.
+ //
+ // We place the non-oneof fields in optimized_order_, as that controls the
+ // order of the _has_bits_ entries and we want GDB's pretty printers to be
+ // able to infer these indices from the k[FIELDNAME]FieldNumber order.
+ std::vector<const FieldDescriptor*> ordered_fields;
+ ordered_fields.reserve(descriptor_->field_count());
+
+ ordered_fields.insert(
+ ordered_fields.begin(), optimized_order_.begin(), optimized_order_.end());
for (int i = 0; i < descriptor_->field_count(); i++) {
const FieldDescriptor* field = descriptor_->field(i);
+ if (field->containing_oneof() == NULL) {
+ continue;
+ }
+ ordered_fields.push_back(field);
+ }
+
+ for (int i = 0; i < ordered_fields.size(); i++) {
+ const FieldDescriptor* field = ordered_fields[i];
PrintFieldComment(printer, field);
- map<string, string> vars;
+ std::map<string, string> vars;
SetCommonFieldVariables(field, &vars, options_);
vars["constant_name"] = FieldConstantName(field);
@@ -566,6 +727,8 @@ GenerateDependentFieldAccessorDefinitions(io::Printer* printer) {
for (int i = 0; i < descriptor_->field_count(); i++) {
const FieldDescriptor* field = descriptor_->field(i);
+ if (field->options().weak()) continue;
+
PrintFieldComment(printer, field);
// These functions are not really dependent: they are part of the
@@ -575,7 +738,7 @@ GenerateDependentFieldAccessorDefinitions(io::Printer* printer) {
// See the comment in FileGenerator::GenerateInlineFunctionDefinitions
// for a more complete explanation.
if (use_dependent_base_ && IsFieldDependent(field)) {
- map<string, string> vars;
+ std::map<string, string> vars;
SetCommonFieldVariables(field, &vars, options_);
vars["inline"] = "inline ";
if (field->containing_oneof()) {
@@ -612,13 +775,16 @@ GenerateDependentFieldAccessorDefinitions(io::Printer* printer) {
void MessageGenerator::
GenerateSingularFieldHasBits(const FieldDescriptor* field,
- map<string, string> vars,
+ std::map<string, string> vars,
io::Printer* printer) {
if (HasFieldPresence(descriptor_->file())) {
// N.B.: without field presence, we do not use has-bits or generate
// has_$name$() methods.
- vars["has_array_index"] = SimpleItoa(field->index() / 32);
- vars["has_mask"] = StrCat(strings::Hex(1u << (field->index() % 32),
+ int has_bit_index = has_bit_indices_[field->index()];
+ GOOGLE_CHECK_GE(has_bit_index, 0);
+
+ vars["has_array_index"] = SimpleItoa(has_bit_index / 32);
+ vars["has_mask"] = StrCat(strings::Hex(1u << (has_bit_index % 32),
strings::ZERO_PAD_8));
printer->Print(vars,
"$inline$"
@@ -644,11 +810,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");
}
}
}
@@ -657,7 +824,7 @@ GenerateSingularFieldHasBits(const FieldDescriptor* field,
void MessageGenerator::
GenerateOneofHasBits(io::Printer* printer, bool is_inline) {
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars["oneof_name"] = descriptor_->oneof_decl(i)->name();
vars["oneof_index"] = SimpleItoa(descriptor_->oneof_decl(i)->index());
vars["cap_oneof_name"] =
@@ -679,7 +846,7 @@ GenerateOneofHasBits(io::Printer* printer, bool is_inline) {
void MessageGenerator::
GenerateOneofMemberHasBits(const FieldDescriptor* field,
- const map<string, string>& vars,
+ const std::map<string, string>& vars,
io::Printer* printer) {
// Singular field in a oneof
// N.B.: Without field presence, we do not use has-bits or generate
@@ -701,7 +868,7 @@ GenerateOneofMemberHasBits(const FieldDescriptor* field,
void MessageGenerator::
GenerateFieldClear(const FieldDescriptor* field,
- const map<string, string>& vars,
+ const std::map<string, string>& vars,
io::Printer* printer) {
// Generate clear_$name$() (See GenerateFieldAccessorDeclarations and
// GenerateDependentFieldAccessorDeclarations, $dependent_classname$ is
@@ -749,7 +916,7 @@ GenerateFieldAccessorDefinitions(io::Printer* printer, bool is_inline) {
PrintFieldComment(printer, field);
- map<string, string> vars;
+ std::map<string, string> vars;
SetCommonFieldVariables(field, &vars, options_);
vars["inline"] = is_inline ? "inline " : "";
if (use_dependent_base_ && IsFieldDependent(field)) {
@@ -805,38 +972,13 @@ 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_) {
return;
}
- map<string, string> vars;
+ std::map<string, string> vars;
vars["classname"] = DependentBaseClassTemplateName(descriptor_);
vars["full_name"] = descriptor_->full_name();
vars["superclass"] = SuperClassName(descriptor_, options_);
@@ -862,23 +1004,13 @@ GenerateDependentBaseClassDefinition(io::Printer* printer) {
void MessageGenerator::
GenerateClassDefinition(io::Printer* printer) {
- for (int i = 0; i < descriptor_->nested_type_count(); i++) {
- // map entry message doesn't need class definition. Since map entry message
- // cannot be a top level class, we just need to avoid calling
- // GenerateClassDefinition here.
- if (IsMapEntryMessage(descriptor_->nested_type(i))) continue;
- nested_generators_[i]->GenerateClassDefinition(printer);
- printer->Print("\n");
- printer->Print(kThinSeparator);
- printer->Print("\n");
- }
-
+ if (IsMapEntryMessage(descriptor_)) return;
if (use_dependent_base_) {
GenerateDependentBaseClassDefinition(printer);
printer->Print("\n");
}
- map<string, string> vars;
+ std::map<string, string> vars;
vars["classname"] = classname_;
vars["full_name"] = descriptor_->full_name();
vars["field_count"] = SimpleItoa(descriptor_->field_count());
@@ -918,44 +1050,19 @@ GenerateClassDefinition(io::Printer* printer) {
"\n");
if (PreserveUnknownFields(descriptor_)) {
- if (UseUnknownFieldSet(descriptor_->file(), options_)) {
- printer->Print(
- "inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {\n"
- " return _internal_metadata_.unknown_fields();\n"
- "}\n"
- "\n"
- "inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {\n"
- " return _internal_metadata_.mutable_unknown_fields();\n"
- "}\n"
- "\n");
- } else {
- if (SupportsArenas(descriptor_)) {
- printer->Print(
- "inline const ::std::string& unknown_fields() const {\n"
- " return _unknown_fields_.Get(\n"
- " &::google::protobuf::internal::GetEmptyStringAlreadyInited());\n"
- "}\n"
- "\n"
- "inline ::std::string* mutable_unknown_fields() {\n"
- " return _unknown_fields_.Mutable(\n"
- " &::google::protobuf::internal::GetEmptyStringAlreadyInited(),\n"
- " GetArenaNoVirtual());\n"
- "}\n"
- "\n");
- } else {
- printer->Print(
- "inline const ::std::string& unknown_fields() const {\n"
- " return _unknown_fields_.GetNoArena(\n"
- " &::google::protobuf::internal::GetEmptyStringAlreadyInited());\n"
- "}\n"
- "\n"
- "inline ::std::string* mutable_unknown_fields() {\n"
- " return _unknown_fields_.MutableNoArena(\n"
- " &::google::protobuf::internal::GetEmptyStringAlreadyInited());\n"
- "}\n"
- "\n");
- }
- }
+ string type = UseUnknownFieldSet(descriptor_->file(), options_)
+ ? "::google::protobuf::UnknownFieldSet"
+ : "::std::string";
+ printer->Print(
+ "inline const $type$& unknown_fields() const {\n"
+ " return _internal_metadata_.unknown_fields();\n"
+ "}\n"
+ "\n"
+ "inline $type$* mutable_unknown_fields() {\n"
+ " return _internal_metadata_.mutable_unknown_fields();\n"
+ "}\n"
+ "\n",
+ "type", type );
}
// N.B.: We exclude GetArena() when arena support is disabled, falling back on
@@ -965,8 +1072,10 @@ GenerateClassDefinition(io::Printer* printer) {
// virtual method version of GetArenaNoVirtual(), required for generic dispatch given a
// MessageLite* (e.g., in RepeatedField::AddAllocated()).
printer->Print(
- "inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); }\n"
- "inline void* GetMaybeArenaPointer() const {\n"
+ "inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {\n"
+ " return GetArenaNoVirtual();\n"
+ "}\n"
+ "inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {\n"
" return MaybeArenaPtr();\n"
"}\n");
}
@@ -1009,19 +1118,14 @@ 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 reinterpret_cast<const $classname$*>(\n"
+ " &_$classname$_default_instance_);\n"
"}\n"
- "#endif\n"
"\n");
- }
if (SupportsArenas(descriptor_)) {
@@ -1043,96 +1147,78 @@ GenerateClassDefinition(io::Printer* printer) {
"\n");
}
+ vars["new_final"] = " PROTOBUF_FINAL";
+
printer->Print(vars,
"void Swap($classname$* other);\n"
"\n"
"// implements Message ----------------------------------------------\n"
"\n"
- "inline $classname$* New() const { return New(NULL); }\n"
+ "inline $classname$* New() const$new_final$ { return New(NULL); }\n"
"\n"
- "$classname$* New(::google::protobuf::Arena* arena) const;\n");
+ "$classname$* New(::google::protobuf::Arena* arena) const$new_final$;\n");
+
+ // For instances that derive from Message (rather than MessageLite), some
+ // methods are virtual and should be marked as final.
+ string use_final = HasDescriptorMethods(descriptor_->file(), options_) ?
+ " PROTOBUF_FINAL" : "";
if (HasGeneratedMethods(descriptor_->file(), options_)) {
if (HasDescriptorMethods(descriptor_->file(), options_)) {
printer->Print(vars,
- "void CopyFrom(const ::google::protobuf::Message& from);\n"
- "void MergeFrom(const ::google::protobuf::Message& from);\n");
+ "void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;\n"
+ "void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;\n");
} else {
printer->Print(vars,
- "void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from);\n");
+ "void CheckTypeAndMergeFrom(const ::google::protobuf::MessageLite& from)\n"
+ " PROTOBUF_FINAL;\n");
}
- printer->Print(vars,
- "void CopyFrom(const $classname$& from);\n"
- "void MergeFrom(const $classname$& from);\n"
- "void Clear();\n"
- "bool IsInitialized() const;\n"
- "\n"
- "int ByteSize() const;\n"
- "bool MergePartialFromCodedStream(\n"
- " ::google::protobuf::io::CodedInputStream* input);\n"
- "void SerializeWithCachedSizes(\n"
- " ::google::protobuf::io::CodedOutputStream* output) const;\n");
+ vars["clear_final"] = " PROTOBUF_FINAL";
+ vars["is_initialized_final"] = " PROTOBUF_FINAL";
+ vars["merge_partial_final"] = " PROTOBUF_FINAL";
+
+ printer->Print(
+ vars,
+ "void CopyFrom(const $classname$& from);\n"
+ "void MergeFrom(const $classname$& from);\n"
+ "void Clear()$clear_final$;\n"
+ "bool IsInitialized() const$is_initialized_final$;\n"
+ "\n"
+ "size_t ByteSizeLong() const PROTOBUF_FINAL;\n"
+ "bool MergePartialFromCodedStream(\n"
+ " ::google::protobuf::io::CodedInputStream* input)$merge_partial_final$;\n"
+ "void SerializeWithCachedSizes(\n"
+ " ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;\n");
// DiscardUnknownFields() is implemented in message.cc using reflections. We
// need to implement this function in generated code for messages.
if (!UseUnknownFieldSet(descriptor_->file(), options_)) {
printer->Print(
- "void DiscardUnknownFields();\n");
+ "void DiscardUnknownFields()$final$;\n",
+ "final", use_final);
}
if (HasFastArraySerialization(descriptor_->file(), options_)) {
printer->Print(
- "::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(\n"
- " bool deterministic, ::google::protobuf::uint8* output) const;\n"
- "::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {\n"
- " return InternalSerializeWithCachedSizesToArray(false, output);\n"
- "}\n");
- }
- }
-
- // Check all FieldDescriptors including those in oneofs to estimate
- // whether ::std::string is likely to be used, and depending on that
- // estimate, set uses_string_ to true or false. That contols
- // whether to force initialization of empty_string_ in SharedCtor().
- // It's often advantageous to do so to keep "is empty_string_
- // inited?" code from appearing all over the place.
- vector<const FieldDescriptor*> descriptors;
- for (int i = 0; i < descriptor_->field_count(); i++) {
- descriptors.push_back(descriptor_->field(i));
- }
- for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
- for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
- descriptors.push_back(descriptor_->oneof_decl(i)->field(j));
- }
- }
- for (int i = 0; i < descriptor_->nested_type_count(); i++) {
- const Descriptor* nested_type = descriptor_->nested_type(i);
- if (IsMapEntryMessage(nested_type)) {
- descriptors.push_back(nested_type->FindFieldByName("key"));
- descriptors.push_back(nested_type->FindFieldByName("value"));
- }
- }
- uses_string_ = false;
- if (PreserveUnknownFields(descriptor_) &&
- !UseUnknownFieldSet(descriptor_->file(), options_)) {
- uses_string_ = true;
- }
- for (int i = 0; i < descriptors.size(); i++) {
- const FieldDescriptor* field = descriptors[i];
- if (field->cpp_type() == FieldDescriptor::CPPTYPE_STRING) {
- switch (field->options().ctype()) {
- default: uses_string_ = true; break;
- }
+ "::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(\n"
+ " bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;\n"
+ "::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)\n"
+ " const PROTOBUF_FINAL {\n"
+ " return InternalSerializeWithCachedSizesToArray(\n"
+ " ::google::protobuf::io::CodedOutputStream::"
+ "IsDefaultSerializationDeterministic(), output);\n"
+ "}\n");
}
}
printer->Print(
- "int GetCachedSize() const { return _cached_size_; }\n"
+ "int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }\n"
"private:\n"
"void SharedCtor();\n"
"void SharedDtor();\n"
- "void SetCachedSize(int size) const;\n"
+ "void SetCachedSize(int size) const$final$;\n"
"void InternalSwap($classname$* other);\n",
- "classname", classname_);
+ "classname", classname_,
+ "final", use_final);
if (SupportsArenas(descriptor_)) {
printer->Print(
"protected:\n"
@@ -1143,7 +1229,7 @@ GenerateClassDefinition(io::Printer* printer) {
"classname", classname_);
}
- if (UseUnknownFieldSet(descriptor_->file(), options_)) {
+ if (SupportsArenas(descriptor_)) {
printer->Print(
"private:\n"
"inline ::google::protobuf::Arena* GetArenaNoVirtual() const {\n"
@@ -1151,29 +1237,29 @@ GenerateClassDefinition(io::Printer* printer) {
"}\n"
"inline void* MaybeArenaPtr() const {\n"
" return _internal_metadata_.raw_arena_ptr();\n"
- "}\n"
- "public:\n"
- "\n");
+ "}\n");
} else {
printer->Print(
"private:\n"
"inline ::google::protobuf::Arena* GetArenaNoVirtual() const {\n"
- " return _arena_ptr_;\n"
- "}\n"
- "inline ::google::protobuf::Arena* MaybeArenaPtr() const {\n"
- " return _arena_ptr_;\n"
+ " return NULL;\n"
"}\n"
+ "inline void* MaybeArenaPtr() const {\n"
+ " return NULL;\n"
+ "}\n");
+ }
+
+ printer->Print(
"public:\n"
"\n");
- }
if (HasDescriptorMethods(descriptor_->file(), options_)) {
printer->Print(
- "::google::protobuf::Metadata GetMetadata() const;\n"
+ "::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;\n"
"\n");
} else {
printer->Print(
- "::std::string GetTypeName() const;\n"
+ "::std::string GetTypeName() const PROTOBUF_FINAL;\n"
"\n");
}
@@ -1231,17 +1317,15 @@ GenerateClassDefinition(io::Printer* printer) {
// messages without true field presence.
if (HasFieldPresence(descriptor_->file()) ||
descriptor_->field(i)->containing_oneof()) {
- printer->Print(
- "inline void set_has_$name$();\n",
- "name", FieldName(descriptor_->field(i)));
+ printer->Print("void set_has_$name$();\n", "name",
+ FieldName(descriptor_->field(i)));
}
// clear_has_***() generated only for non-oneof fields
// in proto1/2.
if (!descriptor_->field(i)->containing_oneof() &&
HasFieldPresence(descriptor_->file())) {
- printer->Print(
- "inline void clear_has_$name$();\n",
- "name", FieldName(descriptor_->field(i)));
+ printer->Print("void clear_has_$name$();\n", "name",
+ FieldName(descriptor_->field(i)));
}
}
}
@@ -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<int> 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();
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
@@ -1303,9 +1379,8 @@ GenerateClassDefinition(io::Printer* printer) {
"::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;\n");
} else {
printer->Print(
- "::google::protobuf::internal::ArenaStringPtr _unknown_fields_;\n"
- "::google::protobuf::Arena* _arena_ptr_;\n"
- "\n");
+ "::google::protobuf::internal::InternalMetadataWithArenaLite "
+ "_internal_metadata_;\n");
}
if (SupportsArenas(descriptor_)) {
@@ -1326,55 +1401,16 @@ 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<const FieldDescriptor*> fields;
- hash_map<string, int> 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<string> >(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)) {
- const string& fieldname = FieldName(field);
- if (!runs_of_fields_.back().empty() &&
- (fieldname_to_chunk[runs_of_fields_.back().back()] !=
- fieldname_to_chunk[fieldname])) {
- runs_of_fields_.push_back(vector<string>());
- }
- runs_of_fields_.back().push_back(fieldname);
- } else if (!runs_of_fields_.back().empty()) {
- runs_of_fields_.push_back(vector<string>());
- }
}
// For each oneof generate a union
@@ -1421,69 +1457,41 @@ GenerateClassDefinition(io::Printer* printer) {
"::google::protobuf::internal::AnyMetadata _any_metadata_;\n");
}
- // 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 $assigndescriptorsname$();\n"
- "friend void $shutdownfilename$();\n"
- "\n",
- "assigndescriptorsname",
- GlobalAssignDescriptorsName(descriptor_->file()->name()),
- "shutdownfilename", GlobalShutdownFileName(descriptor_->file()->name()));
-
+ // The TableStruct struct needs access to the private parts, in order to
+ // construct the offsets of all members.
+ // Some InitDefault and Shutdown are defined as static member functions of
+ // TableStruct such that they are also allowed to access private members.
printer->Print(
- "void InitAsDefaultInstance();\n"
- "static $classname$* default_instance_;\n",
- "classname", classname_);
+ "friend struct $file_namespace$::TableStruct;\n",
+ // Vars.
+ "file_namespace",
+ FileLevelNamespace(descriptor_->file()->name()));
printer->Outdent();
- printer->Print(vars, "};");
+ printer->Print("};");
GOOGLE_DCHECK(!need_to_emit_cached_size);
}
void MessageGenerator::
GenerateDependentInlineMethods(io::Printer* printer) {
- for (int i = 0; i < descriptor_->nested_type_count(); i++) {
- // map entry message doesn't need inline methods. Since map entry message
- // cannot be a top level class, we just need to avoid calling
- // GenerateInlineMethods here.
- if (IsMapEntryMessage(descriptor_->nested_type(i))) continue;
- nested_generators_[i]->GenerateDependentInlineMethods(printer);
- printer->Print(kThinSeparator);
- printer->Print("\n");
+ if (IsMapEntryMessage(descriptor_)) return;
+ for (int i = 0; i < descriptor_->field_count(); i++) {
+ if (descriptor_->field(i)->options().weak()) {
+ field_generators_.get(descriptor_->field(i))
+ .GenerateDependentInlineAccessorDefinitions(printer);
+ }
}
-
GenerateDependentFieldAccessorDefinitions(printer);
}
void MessageGenerator::
GenerateInlineMethods(io::Printer* printer, bool is_inline) {
- for (int i = 0; i < descriptor_->nested_type_count(); i++) {
- // map entry message doesn't need inline methods. Since map entry message
- // cannot be a top level class, we just need to avoid calling
- // GenerateInlineMethods here.
- if (IsMapEntryMessage(descriptor_->nested_type(i))) continue;
- nested_generators_[i]->GenerateInlineMethods(printer, is_inline);
- printer->Print(kThinSeparator);
- printer->Print("\n");
- }
-
+ if (IsMapEntryMessage(descriptor_)) return;
GenerateFieldAccessorDefinitions(printer, is_inline);
// Generate oneof_case() functions.
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars["class_name"] = classname_;
vars["camel_oneof_name"] = UnderscoresToCamelCase(
descriptor_->oneof_decl(i)->name(), true);
@@ -1502,27 +1510,13 @@ GenerateInlineMethods(io::Printer* printer, bool is_inline) {
}
void MessageGenerator::
-GenerateDescriptorDeclarations(io::Printer* printer) {
- if (!IsMapEntryMessage(descriptor_)) {
- printer->Print(
- "const ::google::protobuf::Descriptor* $name$_descriptor_ = NULL;\n"
- "const ::google::protobuf::internal::GeneratedMessageReflection*\n"
- " $name$_reflection_ = NULL;\n",
- "name", classname_);
- } else {
- printer->Print(
- "const ::google::protobuf::Descriptor* $name$_descriptor_ = NULL;\n",
- "name", classname_);
- }
-
+GenerateExtraDefaultFields(io::Printer* printer) {
// Generate oneof default instance for reflection usage.
if (descriptor_->oneof_decl_count() > 0) {
- printer->Print("struct $name$OneofInstance {\n",
- "name", classname_);
+ printer->Print("public:\n");
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j);
- printer->Print(" ");
if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE ||
(field->cpp_type() == FieldDescriptor::CPPTYPE_STRING &&
EffectiveStringCType(field) != FieldOptions::STRING)) {
@@ -1531,153 +1525,33 @@ GenerateDescriptorDeclarations(io::Printer* printer) {
field_generators_.get(field).GeneratePrivateMembers(printer);
}
}
-
- printer->Print("}* $name$_default_oneof_instance_ = NULL;\n",
- "name", classname_);
- }
-
- for (int i = 0; i < descriptor_->nested_type_count(); i++) {
- nested_generators_[i]->GenerateDescriptorDeclarations(printer);
- }
-
- for (int i = 0; i < descriptor_->enum_type_count(); i++) {
- printer->Print(
- "const ::google::protobuf::EnumDescriptor* $name$_descriptor_ = NULL;\n",
- "name", ClassName(descriptor_->enum_type(i), false));
}
}
-void MessageGenerator::
-GenerateDescriptorInitializer(io::Printer* printer, int index) {
- // TODO(kenton): Passing the index to this method is redundant; just use
- // descriptor_->index() instead.
- map<string, string> vars;
- vars["classname"] = classname_;
- vars["index"] = SimpleItoa(index);
-
- // Obtain the descriptor from the parent's descriptor.
- if (descriptor_->containing_type() == NULL) {
- printer->Print(vars,
- "$classname$_descriptor_ = file->message_type($index$);\n");
- } else {
- vars["parent"] = ClassName(descriptor_->containing_type(), false);
- printer->Print(vars,
- "$classname$_descriptor_ = "
- "$parent$_descriptor_->nested_type($index$);\n");
- }
-
+void MessageGenerator::GenerateSchema(io::Printer* printer, int offset,
+ int has_offset) {
if (IsMapEntryMessage(descriptor_)) return;
- // Generate the offsets.
- GenerateOffsets(printer);
+ std::map<string, string> vars;
- const bool pass_pool_and_factory = false;
- vars["fn"] = pass_pool_and_factory ?
- "new ::google::protobuf::internal::GeneratedMessageReflection" :
- "::google::protobuf::internal::GeneratedMessageReflection"
- "::NewGeneratedMessageReflection";
- // Construct the reflection object.
- printer->Print(vars,
- "$classname$_reflection_ =\n"
- " $fn$(\n"
- " $classname$_descriptor_,\n"
- " $classname$::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");
- }
-
- // Unknown field offset: either points to the unknown field set if embedded
- // directly, or indicates that the unknown field set is stored as part of the
- // internal metadata if not.
- if (UseUnknownFieldSet(descriptor_->file(), options_)) {
- printer->Print(vars,
- " -1,\n");
- } else {
- printer->Print(vars,
- " GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET("
- "$classname$, _unknown_fields_),\n");
- }
-
- if (descriptor_->extension_range_count() > 0) {
- printer->Print(vars,
- " GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET("
- "$classname$, _extensions_),\n");
- } else {
- // No extensions.
- printer->Print(vars,
- " -1,\n");
- }
-
- if (descriptor_->oneof_decl_count() > 0) {
- printer->Print(vars,
- " $classname$_default_oneof_instance_,\n"
- " GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET("
- "$classname$, _oneof_case_[0]),\n");
- }
-
- if (pass_pool_and_factory) {
- printer->Print(
- " ::google::protobuf::DescriptorPool::generated_pool(),\n");
- printer->Print(vars,
- " ::google::protobuf::MessageFactory::generated_factory(),\n");
- }
+ vars["classname"] = classname_;
+ vars["offset"] = SimpleItoa(offset);
+ vars["has_bits_offsets"] = HasFieldPresence(descriptor_->file())
+ ? SimpleItoa(offset + has_offset)
+ : "-1";
printer->Print(vars,
- " sizeof($classname$),\n");
-
- // Arena offset: either an offset to the metadata struct that contains the
- // arena pointer and unknown field set (in a space-efficient way) if we use
- // that implementation strategy, or an offset directly to the arena pointer if
- // 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");
- } 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");
- }
-
- // Handle nested types.
- for (int i = 0; i < descriptor_->nested_type_count(); i++) {
- nested_generators_[i]->GenerateDescriptorInitializer(printer, i);
- }
-
- for (int i = 0; i < descriptor_->enum_type_count(); i++) {
- enum_generators_[i]->GenerateDescriptorInitializer(printer, i);
- }
+ "{ $offset$, $has_bits_offsets$, sizeof($classname$)},\n");
}
void MessageGenerator::
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 {
- map<string, string> vars;
+ if (IsMapEntryMessage(descriptor_)) {
+ std::map<string, string> vars;
CollectMapInfo(descriptor_, &vars);
vars["classname"] = classname_;
+ vars["file_namespace"] = FileLevelNamespace(descriptor_->file()->name());
const FieldDescriptor* val = descriptor_->FindFieldByName("value");
if (descriptor_->file()->syntax() == FileDescriptor::SYNTAX_PROTO2 &&
@@ -1688,26 +1562,29 @@ GenerateTypeRegistrations(io::Printer* printer) {
vars["default_enum_value"] = "0";
}
- printer->Print(vars,
- "::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(\n"
- " $classname$_descriptor_,\n"
- " ::google::protobuf::internal::MapEntry<\n"
- " $key$,\n"
- " $val$,\n"
- " $key_wire_type$,\n"
- " $val_wire_type$,\n"
- " $default_enum_value$>::CreateDefaultInstance(\n"
- " $classname$_descriptor_));\n");
- }
-
- // Handle nested types.
- for (int i = 0; i < descriptor_->nested_type_count(); i++) {
- nested_generators_[i]->GenerateTypeRegistrations(printer);
+ vars["index_in_metadata"] = SimpleItoa(index_in_metadata_);
+
+ printer->Print(
+ vars,
+ "const ::google::protobuf::Descriptor* $classname$_descriptor = "
+ "$file_namespace$::file_level_metadata[$index_in_metadata$].descriptor;"
+ "\n"
+ "::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(\n"
+ " $classname$_descriptor,\n"
+ " ::google::protobuf::internal::MapEntry<\n"
+ " $key$,\n"
+ " $val$,\n"
+ " $key_wire_type$,\n"
+ " $val_wire_type$,\n"
+ " $default_enum_value$>::CreateDefaultInstance(\n"
+ " $classname$_descriptor));\n");
}
}
void MessageGenerator::
GenerateDefaultInstanceAllocator(io::Printer* printer) {
+ if (IsMapEntryMessage(descriptor_)) return;
+
// 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++) {
@@ -1715,65 +1592,60 @@ GenerateDefaultInstanceAllocator(io::Printer* printer) {
.GenerateDefaultInstanceAllocator(printer);
}
- if (IsMapEntryMessage(descriptor_)) return;
-
// 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_);
-
- if ((descriptor_->oneof_decl_count() > 0) &&
- HasDescriptorMethods(descriptor_->file(), options_)) {
- printer->Print(
- "$classname$_default_oneof_instance_ = new $classname$OneofInstance();\n",
- "classname", classname_);
- }
-
- // Handle nested types.
- for (int i = 0; i < descriptor_->nested_type_count(); i++) {
- nested_generators_[i]->GenerateDefaultInstanceAllocator(printer);
- }
-
+ printer->Print("_$classname$_default_instance_.DefaultConstruct();\n",
+ "classname", classname_);
}
void MessageGenerator::
GenerateDefaultInstanceInitializer(io::Printer* printer) {
- printer->Print(
- "$classname$::default_instance_->InitAsDefaultInstance();\n",
- "classname", classname_);
+ if (IsMapEntryMessage(descriptor_)) return;
- // Register extensions.
- for (int i = 0; i < descriptor_->extension_count(); i++) {
- extension_generators_[i]->GenerateRegistration(printer);
- }
+ // 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
+ // constructed yet at that time.
+ // TODO(kenton): Maybe all message fields (even for non-default messages)
+ // should be initialized to point at default instances rather than NULL?
+ for (int i = 0; i < descriptor_->field_count(); i++) {
+ const FieldDescriptor* field = descriptor_->field(i);
- // Handle nested types.
- for (int i = 0; i < descriptor_->nested_type_count(); i++) {
- // map entry message doesn't need to initialize default instance manually.
- // Since map entry message cannot be a top level class, we just need to
- // avoid calling DefaultInstanceInitializer here.
- if (IsMapEntryMessage(descriptor_->nested_type(i))) continue;
- nested_generators_[i]->GenerateDefaultInstanceInitializer(printer);
+ if (!field->is_repeated() &&
+ field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
+ (field->containing_oneof() == NULL ||
+ HasDescriptorMethods(descriptor_->file(), options_))) {
+ string name;
+ if (field->containing_oneof()) {
+ name = "_" + classname_ + "_default_instance_.";
+ } else {
+ name = "_" + classname_ + "_default_instance_.get_mutable()->";
+ }
+ name += FieldName(field);
+ printer->Print(
+ "$name$_ = const_cast< $type$*>(\n"
+ " $type$::internal_default_instance());\n",
+ // Vars.
+ "name", name, "type", FieldMessageTypeName(field));
+ } else if (field->containing_oneof() &&
+ HasDescriptorMethods(descriptor_->file(), options_)) {
+ field_generators_.get(descriptor_->field(i))
+ .GenerateConstructorCode(printer);
+ }
}
}
void MessageGenerator::
GenerateShutdownCode(io::Printer* printer) {
- printer->Print(
- "delete $classname$::default_instance_;\n",
- "classname", classname_);
+ if (IsMapEntryMessage(descriptor_)) return;
+
+ printer->Print("_$classname$_default_instance_.Shutdown();\n", "classname",
+ classname_);
if (HasDescriptorMethods(descriptor_->file(), options_)) {
- if (descriptor_->oneof_decl_count() > 0) {
- printer->Print(
- "delete $classname$_default_oneof_instance_;\n",
- "classname", classname_);
- }
- printer->Print(
- "delete $classname$_reflection_;\n",
- "classname", classname_);
+ printer->Print("delete file_level_metadata[$index$].reflection;\n", "index",
+ SimpleItoa(index_in_metadata_));
}
// Handle default instances of fields.
@@ -1781,28 +1653,12 @@ GenerateShutdownCode(io::Printer* printer) {
field_generators_.get(descriptor_->field(i))
.GenerateShutdownCode(printer);
}
-
- // Handle nested types.
- for (int i = 0; i < descriptor_->nested_type_count(); i++) {
- if (IsMapEntryMessage(descriptor_->nested_type(i))) continue;
- nested_generators_[i]->GenerateShutdownCode(printer);
- }
}
void MessageGenerator::
GenerateClassMethods(io::Printer* printer) {
- // mutable_unknown_fields wrapper function for LazyStringOutputStream
- // callback.
- if (PreserveUnknownFields(descriptor_) &&
- !UseUnknownFieldSet(descriptor_->file(), options_)) {
- printer->Print(
- "static ::std::string* MutableUnknownFieldsFor$classname$(\n"
- " $classname$* ptr) {\n"
- " return ptr->mutable_unknown_fields();\n"
- "}\n"
- "\n",
- "classname", classname_);
- }
+ if (IsMapEntryMessage(descriptor_)) return;
+
if (IsAnyMessage(descriptor_)) {
printer->Print(
"void $classname$::PackFrom(const ::google::protobuf::Message& message) {\n"
@@ -1821,21 +1677,6 @@ GenerateClassMethods(io::Printer* printer) {
"classname", classname_);
}
- for (int i = 0; i < descriptor_->enum_type_count(); i++) {
- enum_generators_[i]->GenerateMethods(printer);
- }
-
- for (int i = 0; i < descriptor_->nested_type_count(); i++) {
- // map entry message doesn't need class methods. Since map entry message
- // cannot be a top level class, we just need to avoid calling
- // GenerateClassMethods here.
- if (IsMapEntryMessage(descriptor_->nested_type(i))) continue;
- nested_generators_[i]->GenerateClassMethods(printer);
- printer->Print("\n");
- printer->Print(kThinSeparator);
- printer->Print("\n");
- }
-
// Generate non-inline field definitions.
for (int i = 0; i < descriptor_->field_count(); i++) {
field_generators_.get(descriptor_->field(i))
@@ -1855,11 +1696,6 @@ GenerateClassMethods(io::Printer* printer) {
"#endif // !defined(_MSC_VER) || _MSC_VER >= 1900\n"
"\n");
- // Define extension identifiers.
- for (int i = 0; i < descriptor_->extension_count(); i++) {
- extension_generators_[i]->GenerateDefinition(printer);
- }
-
GenerateStructors(printer);
printer->Print("\n");
@@ -1901,15 +1737,13 @@ GenerateClassMethods(io::Printer* printer) {
if (HasDescriptorMethods(descriptor_->file(), options_)) {
printer->Print(
- "::google::protobuf::Metadata $classname$::GetMetadata() const {\n"
- " protobuf_AssignDescriptorsOnce();\n"
- " ::google::protobuf::Metadata metadata;\n"
- " metadata.descriptor = $classname$_descriptor_;\n"
- " metadata.reflection = $classname$_reflection_;\n"
- " return metadata;\n"
- "}\n"
- "\n",
- "classname", classname_);
+ "::google::protobuf::Metadata $classname$::GetMetadata() const {\n"
+ " $file_namespace$::protobuf_AssignDescriptorsOnce();\n"
+ " return $file_namespace$::file_level_metadata[$index$];\n"
+ "}\n"
+ "\n",
+ "classname", classname_, "index", SimpleItoa(index_in_metadata_),
+ "file_namespace", FileLevelNamespace(descriptor_->file()->name()));
} else {
printer->Print(
"::std::string $classname$::GetTypeName() const {\n"
@@ -1922,22 +1756,49 @@ GenerateClassMethods(io::Printer* printer) {
}
-void MessageGenerator::
-GenerateOffsets(io::Printer* printer) {
- printer->Print("static const int $classname$_offsets_[$field_count$] = {\n",
- "classname", classname_, "field_count",
- SimpleItoa(std::max(1, descriptor_->field_count() +
- descriptor_->oneof_decl_count())));
- printer->Indent();
+std::pair<size_t, size_t> MessageGenerator::GenerateOffsets(
+ io::Printer* printer) {
+ if (IsMapEntryMessage(descriptor_)) return std::make_pair(0, 0);
+ std::map<string, string> variables;
+ variables["classname"] = classname_;
+
+ if (HasFieldPresence(descriptor_->file())) {
+ printer->Print(
+ variables,
+ "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, _has_bits_),\n");
+ } else {
+ printer->Print("~0u, // no _has_bits_\n");
+ }
+ printer->Print(variables,
+ "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, "
+ "_internal_metadata_),\n");
+ if (descriptor_->extension_range_count() > 0) {
+ printer->Print(
+ variables,
+ "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, _extensions_),\n");
+ } else {
+ printer->Print("~0u, // no _extensions_\n");
+ }
+ if (descriptor_->oneof_decl_count() > 0) {
+ printer->Print(variables,
+ "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, "
+ "_oneof_case_[0]),\n");
+ } else {
+ printer->Print("~0u, // no _oneof_case_\n");
+ }
+ const int kNumGenericOffsets = 4; // the number of fixed offsets above
+ const size_t offsets = kNumGenericOffsets +
+ descriptor_->field_count() +
+ descriptor_->oneof_decl_count();
+ size_t entries = offsets;
for (int i = 0; i < descriptor_->field_count(); i++) {
const FieldDescriptor* field = descriptor_->field(i);
if (field->containing_oneof()) {
printer->Print(
"PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET("
- "$classname$_default_oneof_instance_, $name$_),\n",
- "classname", classname_,
- "name", FieldName(field));
+ "(&_$classname$_default_instance_), $name$_),\n",
+ "classname", classname_, "name", FieldName(field));
} else {
printer->Print(
"GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, "
@@ -1955,8 +1816,16 @@ GenerateOffsets(io::Printer* printer) {
"name", oneof->name());
}
- printer->Outdent();
- printer->Print("};\n");
+ if (HasFieldPresence(descriptor_->file())) {
+ entries += has_bit_indices_.size();
+ for (int i = 0; i < has_bit_indices_.size(); i++) {
+ const string index = has_bit_indices_[i] >= 0 ?
+ SimpleItoa(has_bit_indices_[i]) : "~0u";
+ printer->Print("$index$,\n", "index", index);
+ }
+ }
+
+ return std::make_pair(entries, offsets);
}
void MessageGenerator::
@@ -1966,33 +1835,30 @@ GenerateSharedConstructorCode(io::Printer* printer) {
"classname", classname_);
printer->Indent();
- if (!HasFieldPresence(descriptor_->file())) {
- printer->Print(
- " _is_default_instance_ = false;\n");
- }
-
- 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(
- "_unknown_fields_.UnsafeSetDefault(\n"
- " &::google::protobuf::internal::GetEmptyStringAlreadyInited());\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() % 8) != 0) {
+ printer->Print("_cached_size_ = 0;\n");
+ need_to_clear_cached_size = false;
}
- for (int i = 0; i < descriptor_->field_count(); i++) {
- if (!descriptor_->field(i)->containing_oneof()) {
- field_generators_.get(descriptor_->field(i))
- .GenerateConstructorCode(printer);
+ // TODO(gerbens) Clean this hack, and why do i need a reference to a pointer??
+ for (int i = 0; i < descriptor_->nested_type_count(); i++) {
+ if (HasDescriptorMethods(descriptor_->file(), options_) &&
+ IsMapEntryMessage(descriptor_->nested_type(i))) {
+ printer->Print(
+ "const ::google::protobuf::Descriptor*& $type$_descriptor = "
+ "$file_namespace$::file_level_metadata[$index$].descriptor;\n",
+ "type", ClassName(descriptor_->nested_type(i), false), "index",
+ SimpleItoa(nested_generators_[i]->index_in_metadata_),
+ "file_namespace", FileLevelNamespace(descriptor_->file()->name()));
}
}
- if (HasFieldPresence(descriptor_->file())) {
- printer->Print(
- "::memset(_has_bits_, 0, sizeof(_has_bits_));\n");
- }
+ std::vector<bool> processed(optimized_order_.size(), false);
+ GenerateConstructorBody(printer, processed, false);
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
printer->Print(
@@ -2000,6 +1866,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,33 +1883,18 @@ 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");
}
- // Write the desctructor for _unknown_fields_ in lite runtime.
- if (PreserveUnknownFields(descriptor_) &&
- !UseUnknownFieldSet(descriptor_->file(), options_)) {
- if (SupportsArenas(descriptor_)) {
- printer->Print(
- "_unknown_fields_.Destroy(\n"
- " &::google::protobuf::internal::GetEmptyStringAlreadyInited(),\n"
- " GetArenaNoVirtual());\n");
- } else {
- printer->Print(
- "_unknown_fields_.DestroyNoArena(\n"
- " &::google::protobuf::internal::GetEmptyStringAlreadyInited());\n");
- }
- }
-
// 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,34 +1906,8 @@ 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
- // MessageFieldGenerator::GenerateDestructorCode().
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const FieldDescriptor* field = descriptor_->field(i);
-
- if (!field->is_repeated() &&
- field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
- // Skip oneof members
- if (!field->containing_oneof()) {
- printer->Print(
- " delete $name$_;\n",
- "name", FieldName(field));
- }
- }
- }
-
printer->Outdent();
printer->Print(
- " }\n"
"}\n"
"\n");
}
@@ -2103,12 +1932,31 @@ GenerateArenaDestructorCode(io::Printer* printer) {
"classname", classname_);
bool need_registration = false;
- for (int i = 0; i < descriptor_->field_count(); i++) {
- if (field_generators_.get(descriptor_->field(i))
+ // Process non-oneof fields first.
+ for (int i = 0; i < optimized_order_.size(); i++) {
+ const FieldDescriptor* field = optimized_order_[i];
+ if (field_generators_.get(field)
.GenerateArenaDestructorCode(printer)) {
need_registration = true;
}
}
+
+ // Process oneof fields.
+ //
+ // Note: As of 10/5/2016, GenerateArenaDestructorCode does not emit anything
+ // and returns false for oneof fields.
+ for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
+ const OneofDescriptor* oneof = descriptor_->oneof_decl(i);
+
+ for (int j = 0; j < oneof->field_count(); j++) {
+ const FieldDescriptor* field = oneof->field(j);
+ if (field_generators_.get(field)
+ .GenerateArenaDestructorCode(printer)) {
+ need_registration = true;
+ }
+ }
+ }
+
printer->Outdent();
printer->Print(
"}\n");
@@ -2129,6 +1977,75 @@ GenerateArenaDestructorCode(io::Printer* printer) {
}
}
+void MessageGenerator::GenerateConstructorBody(io::Printer* printer,
+ std::vector<bool> processed,
+ bool copy_constructor) const {
+ 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<const FieldDescriptor*, size_t> RunMap;
+ RunMap runs;
+
+ for (int i = 0; i < optimized_order_.size(); ++i) {
+ const FieldDescriptor* field = optimized_order_[i];
+ if ((copy_constructor && IsPOD(field)) ||
+ (!copy_constructor && CanConstructByZeroing(field, options_))) {
+ if (last_start == NULL) {
+ last_start = field;
+ }
+
+ runs[last_start]++;
+ } else {
+ last_start = NULL;
+ }
+ }
+
+ string pod_template;
+ if (copy_constructor) {
+ pod_template =
+ "::memcpy(&$first$_, &from.$first$_,\n"
+ " reinterpret_cast<char*>(&$last$_) -\n"
+ " reinterpret_cast<char*>(&$first$_) + sizeof($last$_));\n";
+ } else {
+ pod_template =
+ "::memset(&$first$_, 0, reinterpret_cast<char*>(&$last$_) -\n"
+ " reinterpret_cast<char*>(&$first$_) + sizeof($last$_));\n";
+ }
+
+ for (int i = 0; i < optimized_order_.size(); ++i) {
+ if (processed[i]) {
+ continue;
+ }
+
+ 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(pod_template.c_str(),
+ "first", first_field_name,
+ "last", last_field_name);
+
+ i += run_length - 1;
+ // ++i at the top of the loop.
+ } else {
+ if (copy_constructor) {
+ field_generators_.get(field).GenerateCopyConstructorCode(printer);
+ } else {
+ field_generators_.get(field).GenerateConstructorCode(printer);
+ }
+ }
+ }
+}
+
void MessageGenerator::
GenerateStructors(io::Printer* printer) {
string superclass;
@@ -2144,28 +2061,25 @@ GenerateStructors(io::Printer* printer) {
initializer_with_arena += ",\n _extensions_(arena)";
}
- if (UseUnknownFieldSet(descriptor_->file(), options_)) {
- initializer_with_arena += ",\n _internal_metadata_(arena)";
- } else {
- initializer_with_arena += ",\n _arena_ptr_(arena)";
- }
+ initializer_with_arena += ",\n _internal_metadata_(arena)";
// 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;
- initializer_null = (UseUnknownFieldSet(descriptor_->file(), options_) ?
- ", _internal_metadata_(NULL)" : ", _arena_ptr_(NULL)");
+ initializer_null = ", _internal_metadata_(NULL)";
if (IsAnyMessage(descriptor_)) {
initializer_null += ", _any_metadata_(&type_url_, &value_)";
}
@@ -2173,101 +2087,149 @@ GenerateStructors(io::Printer* printer) {
printer->Print(
"$classname$::$classname$()\n"
" : $superclass$()$initializer$ {\n"
+ " if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {\n"
+ " $file_namespace$::InitDefaults();\n"
+ " }\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,
+ "file_namespace", FileLevelNamespace(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"
+ " $file_namespace$::InitDefaults();\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(),
+ "file_namespace", FileLevelNamespace(descriptor_->file()->name()));
}
+ // Generate the copy constructor.
printer->Print(
- "\n"
- "void $classname$::InitAsDefaultInstance() {\n",
- "classname", classname_);
+ "$classname$::$classname$(const $classname$& from)\n"
+ " : $superclass$()",
+ "classname", classname_,
+ "superclass", superclass,
+ "full_name", descriptor_->full_name());
+ printer->Indent();
+ printer->Indent();
+ printer->Indent();
- if (!HasFieldPresence(descriptor_->file())) {
- printer->Print(
- " _is_default_instance_ = true;\n");
+ printer->Print(
+ ",\n_internal_metadata_(NULL)");
+
+ if (HasFieldPresence(descriptor_->file())) {
+ printer->Print(",\n_has_bits_(from._has_bits_)");
}
- // 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
- // constructed yet at that time.
- // TODO(kenton): Maybe all message fields (even for non-default messages)
- // should be initialized to point at default instances rather than NULL?
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const FieldDescriptor* field = descriptor_->field(i);
+ bool need_to_emit_cached_size = true;
+ const string cached_size_decl = ",\n_cached_size_(0)";
+ // 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() % 8) != 0) {
+ printer->Print(cached_size_decl.c_str());
+ need_to_emit_cached_size = false;
+ }
- if (!field->is_repeated() &&
- field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
- (field->containing_oneof() == NULL ||
- HasDescriptorMethods(descriptor_->file(), options_))) {
- string name;
- if (field->containing_oneof()) {
- 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.
- " $name$_ = const_cast< $type$*>(\n"
- " $type$::internal_default_instance());\n",
- // Vars.
- "name", name, "type", FieldMessageTypeName(field));
- } else if (field->containing_oneof() &&
- HasDescriptorMethods(descriptor_->file(), options_)) {
- field_generators_.get(descriptor_->field(i))
- .GenerateConstructorCode(printer);
+ std::vector<bool> processed(optimized_order_.size(), false);
+ for (int i = 0; i < optimized_order_.size(); ++i) {
+ const FieldDescriptor* field = optimized_order_[i];
+
+ if (!(field->is_repeated() && !(field->is_map()))
+ ) {
+ continue;
}
+
+ processed[i] = true;
+ printer->Print(",\n$name$_(from.$name$_)",
+ "name", FieldName(field));
}
- printer->Print(
- "}\n"
- "\n");
- // Generate the copy constructor.
- printer->Print(
- "$classname$::$classname$(const $classname$& from)\n"
- " : $superclass$()",
- "classname", classname_,
- "superclass", superclass,
- "full_name", descriptor_->full_name());
- if (UseUnknownFieldSet(descriptor_->file(), options_)) {
- printer->Print(
- ",\n _internal_metadata_(NULL)");
- } else if (!UseUnknownFieldSet(descriptor_->file(), options_)) {
- printer->Print(",\n _arena_ptr_(NULL)");
+ if (need_to_emit_cached_size) {
+ printer->Print(cached_size_decl.c_str());
+ need_to_emit_cached_size = false;
}
+
if (IsAnyMessage(descriptor_)) {
- printer->Print(",\n _any_metadata_(&type_url_, &value_)");
+ printer->Print(",\n_any_metadata_(&type_url_, &value_)");
}
+
+ printer->Outdent();
+ printer->Outdent();
printer->Print(" {\n");
+
+ printer->Print(
+ "_internal_metadata_.MergeFrom(from._internal_metadata_);\n");
+
+ if (descriptor_->extension_range_count() > 0) {
+ printer->Print("_extensions_.MergeFrom(from._extensions_);\n");
+ }
+
+ // TODO(gerbens) Clean this hack, and why do i need a reference to a pointer??
+ for (int i = 0; i < descriptor_->nested_type_count(); i++) {
+ if (HasDescriptorMethods(descriptor_->file(), options_) &&
+ IsMapEntryMessage(descriptor_->nested_type(i))) {
+ printer->Print(
+ "const ::google::protobuf::Descriptor*& $type$_descriptor = "
+ "$file_namespace$::file_level_metadata[$index$].descriptor;\n",
+ "type", ClassName(descriptor_->nested_type(i), false), "index",
+ SimpleItoa(nested_generators_[i]->index_in_metadata_),
+ "file_namespace", FileLevelNamespace(descriptor_->file()->name()));
+ }
+ }
+
+ GenerateConstructorBody(printer, processed, true);
+
+ // Copy oneof fields. Oneof field requires oneof case check.
+ for (int i = 0; i < descriptor_->oneof_decl_count(); ++i) {
+ printer->Print(
+ "clear_has_$oneofname$();\n"
+ "switch (from.$oneofname$_case()) {\n",
+ "oneofname", descriptor_->oneof_decl(i)->name());
+ printer->Indent();
+ for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
+ const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j);
+ printer->Print(
+ "case k$field_name$: {\n",
+ "field_name", UnderscoresToCamelCase(field->name(), true));
+ printer->Indent();
+ field_generators_.get(field).GenerateMergingCode(printer);
+ printer->Print(
+ "break;\n");
+ printer->Outdent();
+ printer->Print(
+ "}\n");
+ }
+ printer->Print(
+ "case $cap_oneof_name$_NOT_SET: {\n"
+ " break;\n"
+ "}\n",
+ "oneof_index",
+ SimpleItoa(descriptor_->oneof_decl(i)->index()),
+ "cap_oneof_name",
+ ToUpper(descriptor_->oneof_decl(i)->name()));
+ printer->Outdent();
+ printer->Print(
+ "}\n");
+ }
+
+ printer->Outdent();
printer->Print(
- " SharedCtor();\n"
- " MergeFrom(from);\n"
" // @@protoc_insertion_point(copy_constructor:$full_name$)\n"
"}\n"
"\n",
- "classname", classname_,
- "superclass", superclass,
"full_name", descriptor_->full_name());
// Generate the shared constructor code.
@@ -2304,37 +2266,22 @@ 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"
+ " $file_namespace$::protobuf_AssignDescriptorsOnce();\n"
+ " return $file_namespace$::file_level_metadata[$index$].descriptor;\n"
+ "}\n"
+ "\n",
+ "index", SimpleItoa(index_in_metadata_), "classname", classname_,
+ "file_namespace", FileLevelNamespace(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()));
-
- printer->Print(
- " return *default_instance_;\n"
- "}\n"
- "\n"
- "$classname$* $classname$::default_instance_ = NULL;\n"
- "\n",
- "classname", classname_);
+ "const $classname$& $classname$::default_instance() {\n"
+ " $file_namespace$::InitDefaults();\n"
+ " return *internal_default_instance();\n"
+ "}\n\n",
+ "classname", classname_, "file_namespace",
+ FileLevelNamespace(descriptor_->file()->name()));
if (SupportsArenas(descriptor_)) {
printer->Print(
@@ -2379,154 +2326,173 @@ GenerateClear(io::Printer* printer) {
printer->Print("_extensions_.Clear();\n");
}
- // Step 2: Everything but extensions, repeateds, unions.
- // These are handled in chunks of 8. The first chunk is
- // the non-extensions-non-repeateds-non-unions in
- // descriptor_->field(0), descriptor_->field(1), ... descriptor_->field(7),
- // and the second chunk is the same for
- // descriptor_->field(8), descriptor_->field(9), ... descriptor_->field(15),
- // etc.
- set<int> step2_indices;
- hash_map<string, int> fieldname_to_chunk;
- hash_map<int, string> memsets_for_chunk;
- hash_map<int, int> memset_field_count_for_chunk;
- hash_set<string> handled; // fields that appear anywhere in memsets_for_chunk
- hash_map<int, uint32> fields_mask_for_chunk;
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const FieldDescriptor* field = descriptor_->field(i);
- if (!field->is_repeated() && !field->containing_oneof()) {
- step2_indices.insert(i);
- int chunk = i / 8;
- fieldname_to_chunk[FieldName(field)] = chunk;
- fields_mask_for_chunk[chunk] |= static_cast<uint32>(1) << (i % 32);
- }
- }
-
- // Step 2a: Greedily seek runs of fields that can be cleared by memset-to-0.
- // The generated code uses two macros to help it clear runs of fields:
- // ZR_HELPER_(f1) - ZR_HELPER_(f0) computes the difference, in bytes, of the
- // positions of two fields in the Message.
- // ZR_ zeroes a non-empty range of fields via memset.
- const char* macros =
- "#if defined(__clang__)\n"
- "#define ZR_HELPER_(f) \\\n"
- " _Pragma(\"clang diagnostic push\") \\\n"
- " _Pragma(\"clang diagnostic ignored \\\"-Winvalid-offsetof\\\"\") \\\n"
- " __builtin_offsetof($classname$, f) \\\n"
- " _Pragma(\"clang diagnostic pop\")\n"
- "#else\n"
- "#define ZR_HELPER_(f) reinterpret_cast<char*>(\\\n"
- " &reinterpret_cast<$classname$*>(16)->f)\n"
- "#endif\n\n"
- "#define ZR_(first, last) do {\\\n"
- " ::memset(&first, 0,\\\n"
- " ZR_HELPER_(last) - ZR_HELPER_(first) + sizeof(last));\\\n"
- "} while (0)\n\n";
- for (int i = 0; i < runs_of_fields_.size(); i++) {
- const vector<string>& run = runs_of_fields_[i];
- if (run.size() < 2) continue;
- const string& first_field_name = run[0];
- const string& last_field_name = run.back();
- int chunk = fieldname_to_chunk[run[0]];
- memsets_for_chunk[chunk].append(
- "ZR_(" + first_field_name + "_, " + last_field_name + "_);\n");
- for (int j = 0; j < run.size(); j++) {
- GOOGLE_DCHECK_EQ(chunk, fieldname_to_chunk[run[j]]);
- handled.insert(run[j]);
- }
- memset_field_count_for_chunk[chunk] += run.size();
- }
- const bool macros_are_needed = handled.size() > 0;
- if (macros_are_needed) {
- printer->Outdent();
- printer->Print(macros,
- "classname", classname_);
- printer->Indent();
- }
- // Step 2b: Finish step 2, ignoring fields handled in step 2a.
- int last_index = -1;
- bool chunk_block_in_progress = false;
- for (int i = 0; i < descriptor_->field_count(); i++) {
- if (step2_indices.count(i) == 0) continue;
- const FieldDescriptor* field = descriptor_->field(i);
- const string fieldname = FieldName(field);
- if (i / 8 != last_index / 8 || last_index < 0) {
- // End previous chunk, if there was one.
- if (chunk_block_in_progress) {
- printer->Outdent();
- printer->Print("}\n");
- chunk_block_in_progress = false;
+ int last_i = -1;
+ for (int i = 0; i < optimized_order_.size(); ) {
+ // Detect infinite loops.
+ GOOGLE_CHECK_NE(i, last_i);
+ last_i = i;
+
+ // Step 2: Repeated fields don't use _has_bits_; emit code to clear them
+ // here.
+ for (; i < optimized_order_.size(); i++) {
+ const FieldDescriptor* field = optimized_order_[i];
+ const FieldGenerator& generator = field_generators_.get(field);
+
+ if (!field->is_repeated()) {
+ break;
}
- // Start chunk.
- const string& memsets = memsets_for_chunk[i / 8];
- uint32 mask = fields_mask_for_chunk[i / 8];
- int count = popcnt(mask);
- GOOGLE_DCHECK_GE(count, 1);
- if (count == 1 ||
- (count <= 4 && count == memset_field_count_for_chunk[i / 8])) {
- // No "if" here because the chunk is trivial.
+
+ if (use_dependent_base_ && IsFieldDependent(field)) {
+ printer->Print("clear_$name$();\n", "name", FieldName(field));
} else {
- if (HasFieldPresence(descriptor_->file())) {
- printer->Print(
- "if (_has_bits_[$index$ / 32] & $mask$u) {\n",
- "index", SimpleItoa(i / 8 * 8),
- "mask", SimpleItoa(mask));
- printer->Indent();
- chunk_block_in_progress = true;
- }
+ generator.GenerateMessageClearingCode(printer);
}
- printer->Print(memsets.c_str());
- }
- last_index = i;
- if (handled.count(fieldname) > 0) continue;
-
- // It's faster to just overwrite primitive types, but we should
- // only clear strings and messages if they were set.
- // TODO(kenton): Let the CppFieldGenerator decide this somehow.
- bool should_check_bit =
- field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE ||
- field->cpp_type() == FieldDescriptor::CPPTYPE_STRING;
-
- bool have_enclosing_if = false;
- if (should_check_bit &&
- // If no field presence, then always clear strings/messages as well.
- HasFieldPresence(descriptor_->file())) {
- printer->Print("if (has_$name$()) {\n", "name", fieldname);
- printer->Indent();
- have_enclosing_if = true;
}
- if (use_dependent_base_ && IsFieldDependent(field)) {
- printer->Print("clear_$name$();\n", "name", fieldname);
- } else {
- field_generators_.get(field).GenerateClearingCode(printer);
+ // Step 3: Greedily seek runs of fields that can be cleared by
+ // memset-to-0.
+ int last_chunk = -1;
+ int last_chunk_start = -1;
+ int last_chunk_end = -1;
+ uint32 last_chunk_mask = 0;
+
+ int memset_run_start = -1;
+ int memset_run_end = -1;
+ for (; i < optimized_order_.size(); i++) {
+ const FieldDescriptor* field = optimized_order_[i];
+
+ if (!CanInitializeByZeroing(field)) {
+ break;
+ }
+
+ // "index" defines where in the _has_bits_ the field appears.
+ // "i" is our loop counter within optimized_order_.
+ int index = HasFieldPresence(descriptor_->file()) ?
+ has_bit_indices_[field->index()] : 0;
+ int chunk = index / 8;
+
+ if (last_chunk == -1) {
+ last_chunk = chunk;
+ last_chunk_start = i;
+ } else if (chunk != last_chunk) {
+ // Emit the fields for this chunk so far.
+ break;
+ }
+
+ if (memset_run_start == -1) {
+ memset_run_start = i;
+ }
+
+ memset_run_end = i;
+ last_chunk_end = i;
+ last_chunk_mask |= static_cast<uint32>(1) << (index % 32);
}
- if (have_enclosing_if) {
- printer->Outdent();
- printer->Print("}\n");
+ // Step 4: Non-repeated, non-zero initializable fields.
+ for (; i < optimized_order_.size(); i++) {
+ const FieldDescriptor* field = optimized_order_[i];
+ if (field->is_repeated() || CanInitializeByZeroing(field)) {
+ break;
+ }
+
+ // "index" defines where in the _has_bits_ the field appears.
+ // "i" is our loop counter within optimized_order_.
+ int index = HasFieldPresence(descriptor_->file()) ?
+ has_bit_indices_[field->index()] : 0;
+ int chunk = index / 8;
+
+ if (last_chunk == -1) {
+ last_chunk = chunk;
+ last_chunk_start = i;
+ } else if (chunk != last_chunk) {
+ // Emit the fields for this chunk so far.
+ break;
+ }
+
+ last_chunk_end = i;
+ last_chunk_mask |= static_cast<uint32>(1) << (index % 32);
}
- }
- if (chunk_block_in_progress) {
- printer->Outdent();
- printer->Print("}\n");
- }
- if (macros_are_needed) {
- printer->Outdent();
- printer->Print("\n#undef ZR_HELPER_\n#undef ZR_\n\n");
- printer->Indent();
- }
+ if (last_chunk != -1) {
+ GOOGLE_DCHECK_NE(-1, last_chunk_start);
+ GOOGLE_DCHECK_NE(-1, last_chunk_end);
+ GOOGLE_DCHECK_NE(0, last_chunk_mask);
- // Step 3: Repeated fields don't use _has_bits_; emit code to clear them here.
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const FieldDescriptor* field = descriptor_->field(i);
+ const int count = popcnt(last_chunk_mask);
+ const bool have_outer_if = HasFieldPresence(descriptor_->file()) &&
+ (last_chunk_start != last_chunk_end);
- if (field->is_repeated()) {
- if (use_dependent_base_ && IsFieldDependent(field)) {
- printer->Print("clear_$name$();\n", "name", FieldName(field));
- } else {
- field_generators_.get(field).GenerateClearingCode(printer);
+ if (have_outer_if) {
+ // Check (up to) 8 has_bits at a time if we have more than one field in
+ // this chunk. Due to field layout ordering, we may check
+ // _has_bits_[last_chunk * 8 / 32] multiple times.
+ GOOGLE_DCHECK_LE(2, count);
+ GOOGLE_DCHECK_GE(8, count);
+
+ printer->Print(
+ "if (_has_bits_[$index$ / 32] & $mask$u) {\n",
+ "index", SimpleItoa(last_chunk * 8),
+ "mask", SimpleItoa(last_chunk_mask));
+ printer->Indent();
+ }
+
+ if (memset_run_start != -1) {
+ if (memset_run_start == memset_run_end) {
+ // For clarity, do not memset a single field.
+ const FieldGenerator& generator =
+ field_generators_.get(optimized_order_[memset_run_start]);
+ generator.GenerateMessageClearingCode(printer);
+ } else {
+ const string first_field_name =
+ FieldName(optimized_order_[memset_run_start]);
+ const string last_field_name =
+ FieldName(optimized_order_[memset_run_end]);
+
+ printer->Print(
+ "::memset(&$first$_, 0, reinterpret_cast<char*>(&$last$_) -\n"
+ " reinterpret_cast<char*>(&$first$_) + sizeof($last$_));\n",
+ "first", first_field_name,
+ "last", last_field_name);
+ }
+
+ // Advance last_chunk_start to skip over the fields we zeroed/memset.
+ last_chunk_start = memset_run_end + 1;
+ }
+
+ // Go back and emit clears for each of the fields we processed.
+ for (int j = last_chunk_start; j <= last_chunk_end; j++) {
+ const FieldDescriptor* field = optimized_order_[j];
+ const string fieldname = FieldName(field);
+ const FieldGenerator& generator = field_generators_.get(field);
+
+ // It's faster to just overwrite primitive types, but we should only
+ // clear strings and messages if they were set.
+ //
+ // TODO(kenton): Let the CppFieldGenerator decide this somehow.
+ bool should_check_bit =
+ field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE ||
+ field->cpp_type() == FieldDescriptor::CPPTYPE_STRING;
+
+ bool have_enclosing_if = false;
+ if (should_check_bit &&
+ // If no field presence, then always clear strings/messages as well.
+ HasFieldPresence(descriptor_->file())) {
+ printer->Print("if (has_$name$()) {\n", "name", fieldname);
+ printer->Indent();
+ have_enclosing_if = true;
+ }
+
+ generator.GenerateMessageClearingCode(printer);
+
+ if (have_enclosing_if) {
+ printer->Outdent();
+ printer->Print("}\n");
+ }
+ }
+
+ if (have_outer_if) {
+ printer->Outdent();
+ printer->Print("}\n");
}
}
}
@@ -2540,28 +2506,11 @@ 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_)) {
- if (UseUnknownFieldSet(descriptor_->file(), options_)) {
- printer->Print(
- "if (_internal_metadata_.have_unknown_fields()) {\n"
- " mutable_unknown_fields()->Clear();\n"
- "}\n");
- } else {
- if (SupportsArenas(descriptor_)) {
- printer->Print(
- "_unknown_fields_.ClearToEmpty(\n"
- " &::google::protobuf::internal::GetEmptyStringAlreadyInited(),\n"
- " GetArenaNoVirtual());\n");
- } else {
- printer->Print(
- "_unknown_fields_.ClearToEmptyNoArena(\n"
- " &::google::protobuf::internal::GetEmptyStringAlreadyInited());\n");
- }
- }
+ printer->Print("_internal_metadata_.Clear();\n");
}
printer->Outdent();
@@ -2572,7 +2521,7 @@ void MessageGenerator::
GenerateOneofClear(io::Printer* printer) {
// Generated function clears the active field and union case (e.g. foo_case_).
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
- map<string, string> oneof_vars;
+ std::map<string, string> oneof_vars;
oneof_vars["classname"] = classname_;
oneof_vars["oneofname"] = descriptor_->oneof_decl(i)->name();
oneof_vars["full_name"] = descriptor_->full_name();
@@ -2584,7 +2533,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);
@@ -2638,10 +2587,13 @@ GenerateSwap(io::Printer* printer) {
" if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {\n"
" InternalSwap(other);\n"
" } else {\n"
- " $classname$ temp;\n"
- " temp.MergeFrom(*this);\n"
- " CopyFrom(*other);\n"
- " other->CopyFrom(temp);\n"
+ " $classname$* temp = New(GetArenaNoVirtual());\n"
+ " temp->MergeFrom(*other);\n"
+ " other->CopyFrom(*this);\n"
+ " InternalSwap(temp);\n"
+ " if (GetArenaNoVirtual() == NULL) {\n"
+ " delete temp;\n"
+ " }\n"
" }\n"
"}\n"
"void $classname$::UnsafeArenaSwap($classname$* other) {\n"
@@ -2665,8 +2617,10 @@ GenerateSwap(io::Printer* printer) {
printer->Indent();
if (HasGeneratedMethods(descriptor_->file(), options_)) {
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const FieldDescriptor* field = descriptor_->field(i);
+ for (int i = 0; i < optimized_order_.size(); i++) {
+ // optimized_order_ does not contain oneof fields, but the field
+ // generators for these fields do not emit swapping code on their own.
+ const FieldDescriptor* field = optimized_order_[i];
field_generators_.get(field).GenerateSwappingCode(printer);
}
@@ -2679,19 +2633,14 @@ GenerateSwap(io::Printer* printer) {
}
if (HasFieldPresence(descriptor_->file())) {
- for (int i = 0; i < (descriptor_->field_count() + 31) / 32; ++i) {
+ for (int i = 0; i < HasBitsSize() / 4; ++i) {
printer->Print("std::swap(_has_bits_[$i$], other->_has_bits_[$i$]);\n",
"i", SimpleItoa(i));
}
}
- // Ignore PreserveUnknownFields here - always swap internal_metadata as it
- // may contain more than just unknown fields.
- if (UseUnknownFieldSet(descriptor_->file(), options_)) {
- printer->Print(
- "_internal_metadata_.Swap(&other->_internal_metadata_);\n");
- } else {
- printer->Print("_unknown_fields_.Swap(&other->_unknown_fields_);\n");
+ if (PreserveUnknownFields(descriptor_)) {
+ printer->Print("_internal_metadata_.Swap(&other->_internal_metadata_);\n");
}
printer->Print("std::swap(_cached_size_, other->_cached_size_);\n");
@@ -2715,9 +2664,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",
+ " GOOGLE_DCHECK_NE(&from, this);\n",
"classname", classname_, "full_name", descriptor_->full_name());
printer->Indent();
@@ -2726,7 +2673,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<const $classname$>(\n"
" &from);\n"
"if (source == NULL) {\n"
@@ -2758,19 +2705,118 @@ 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",
+ " GOOGLE_DCHECK_NE(&from, this);\n",
"classname", classname_, "full_name", descriptor_->full_name());
printer->Indent();
- // Merge Repeated fields. These fields do not require a
- // check as we can simply iterate over them.
- for (int i = 0; i < descriptor_->field_count(); ++i) {
- const FieldDescriptor* field = descriptor_->field(i);
+ if (descriptor_->extension_range_count() > 0) {
+ printer->Print("_extensions_.MergeFrom(from._extensions_);\n");
+ }
- if (field->is_repeated()) {
- field_generators_.get(field).GenerateMergingCode(printer);
+ printer->Print(
+ "_internal_metadata_.MergeFrom(from._internal_metadata_);\n");
+
+ int last_i = -1;
+ for (int i = 0; i < optimized_order_.size(); ) {
+ // Detect infinite loops.
+ GOOGLE_CHECK_NE(i, last_i);
+ last_i = i;
+
+ // Merge Repeated fields. These fields do not require a
+ // check as we can simply iterate over them.
+ for (; i < optimized_order_.size(); i++) {
+ const FieldDescriptor* field = optimized_order_[i];
+ if (!field->is_repeated()) {
+ break;
+ }
+
+ const FieldGenerator& generator = field_generators_.get(field);
+ generator.GenerateMergingCode(printer);
+ }
+
+ // Merge Optional and Required fields (after a _has_bit check).
+ int last_chunk = -1;
+ int last_chunk_start = -1;
+ int last_chunk_end = -1;
+ uint32 last_chunk_mask = 0;
+ for (; i < optimized_order_.size(); i++) {
+ const FieldDescriptor* field = optimized_order_[i];
+ if (field->is_repeated()) {
+ break;
+ }
+
+ // "index" defines where in the _has_bits_ the field appears.
+ // "i" is our loop counter within optimized_order_.
+ int index = HasFieldPresence(descriptor_->file()) ?
+ has_bit_indices_[field->index()] : 0;
+ int chunk = index / 8;
+
+ if (last_chunk == -1) {
+ last_chunk = chunk;
+ last_chunk_start = i;
+ } else if (chunk != last_chunk) {
+ // Emit the fields for this chunk so far.
+ break;
+ }
+
+ last_chunk_end = i;
+ last_chunk_mask |= static_cast<uint32>(1) << (index % 32);
+ }
+
+ if (last_chunk != -1) {
+ GOOGLE_DCHECK_NE(-1, last_chunk_start);
+ GOOGLE_DCHECK_NE(-1, last_chunk_end);
+ GOOGLE_DCHECK_NE(0, last_chunk_mask);
+
+ const int count = popcnt(last_chunk_mask);
+ const bool have_outer_if = HasFieldPresence(descriptor_->file()) &&
+ (last_chunk_start != last_chunk_end);
+
+ if (have_outer_if) {
+ // Check (up to) 8 has_bits at a time if we have more than one field in
+ // this chunk. Due to field layout ordering, we may check
+ // _has_bits_[last_chunk * 8 / 32] multiple times.
+ GOOGLE_DCHECK_LE(2, count);
+ GOOGLE_DCHECK_GE(8, count);
+
+ printer->Print(
+ "if (from._has_bits_[$index$ / 32] & $mask$u) {\n",
+ "index", SimpleItoa(last_chunk * 8),
+ "mask", SimpleItoa(last_chunk_mask));
+ printer->Indent();
+ }
+
+ // Go back and emit clears for each of the fields we processed.
+ for (int j = last_chunk_start; j <= last_chunk_end; j++) {
+ const FieldDescriptor* field = optimized_order_[j];
+ const FieldGenerator& generator = field_generators_.get(field);
+
+ bool have_enclosing_if = false;
+ if (HasFieldPresence(descriptor_->file())) {
+ printer->Print(
+ "if (from.has_$name$()) {\n",
+ "name", FieldName(field));
+ printer->Indent();
+ have_enclosing_if = true;
+ } else {
+ // Merge semantics without true field presence: primitive fields are
+ // merged only if non-zero (numeric) or non-empty (string).
+ have_enclosing_if = EmitFieldNonDefaultCondition(
+ printer, "from.", field);
+ }
+
+ generator.GenerateMergingCode(printer);
+
+ if (have_enclosing_if) {
+ printer->Outdent();
+ printer->Print("}\n");
+ }
+ }
+
+ if (have_outer_if) {
+ printer->Outdent();
+ printer->Print("}\n");
+ }
}
}
@@ -2804,77 +2850,6 @@ GenerateMergeFrom(io::Printer* printer) {
"}\n");
}
- // Merge Optional and Required fields (after a _has_bit check).
- int last_index = -1;
-
- for (int i = 0; i < descriptor_->field_count(); ++i) {
- const FieldDescriptor* field = descriptor_->field(i);
-
- if (!field->is_repeated() && !field->containing_oneof()) {
- if (HasFieldPresence(descriptor_->file())) {
- // See above in GenerateClear for an explanation of this.
- if (i / 8 != last_index / 8 || last_index < 0) {
- if (last_index >= 0) {
- printer->Outdent();
- printer->Print("}\n");
- }
- printer->Print(
- "if (from._has_bits_[$index$ / 32] & "
- "(0xffu << ($index$ % 32))) {\n",
- "index", SimpleItoa(field->index()));
- printer->Indent();
- }
- }
-
- last_index = i;
-
- bool have_enclosing_if = false;
- if (HasFieldPresence(descriptor_->file())) {
- printer->Print(
- "if (from.has_$name$()) {\n",
- "name", FieldName(field));
- printer->Indent();
- have_enclosing_if = true;
- } else {
- // Merge semantics without true field presence: primitive fields are
- // merged only if non-zero (numeric) or non-empty (string).
- have_enclosing_if = EmitFieldNonDefaultCondition(
- printer, "from.", field);
- }
-
- field_generators_.get(field).GenerateMergingCode(printer);
-
- if (have_enclosing_if) {
- printer->Outdent();
- printer->Print("}\n");
- }
- }
- }
-
- if (HasFieldPresence(descriptor_->file()) &&
- last_index >= 0) {
- printer->Outdent();
- printer->Print("}\n");
- }
-
- if (descriptor_->extension_range_count() > 0) {
- printer->Print("_extensions_.MergeFrom(from._extensions_);\n");
- }
-
- if (PreserveUnknownFields(descriptor_)) {
- if (UseUnknownFieldSet(descriptor_->file(), options_)) {
- printer->Print(
- "if (from._internal_metadata_.have_unknown_fields()) {\n"
- " mutable_unknown_fields()->MergeFrom(from.unknown_fields());\n"
- "}\n");
- } else {
- printer->Print(
- "if (!from.unknown_fields().empty()) {\n"
- " mutable_unknown_fields()->append(from.unknown_fields());\n"
- "}\n");
- }
- }
-
printer->Outdent();
printer->Print("}\n");
}
@@ -2926,13 +2901,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_);
@@ -2956,8 +2927,8 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
// on the CodedOutputStream.
printer->Print(
" ::google::protobuf::io::LazyStringOutputStream unknown_fields_string(\n"
- " ::google::protobuf::internal::NewPermanentCallback(\n"
- " &MutableUnknownFieldsFor$classname$, this));\n"
+ " ::google::protobuf::NewPermanentCallback(&_internal_metadata_,\n"
+ " &::google::protobuf::internal::InternalMetadataWithArenaLite::mutable_unknown_fields));\n"
" ::google::protobuf::io::CodedOutputStream unknown_fields_stream(\n"
" &unknown_fields_string, false);\n",
"classname", classname_);
@@ -2971,19 +2942,47 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
printer->Print("for (;;) {\n");
printer->Indent();
- google::protobuf::scoped_array<const FieldDescriptor * > ordered_fields(
- SortFieldsByNumber(descriptor_));
+ std::vector<const FieldDescriptor*> 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
const int kCutoff1 = (127 << 7) + 127; // fits in 2-byte varint
+
+ // We need to capture the last tag when parsing if this is a Group type, as
+ // our caller will verify (via CodedInputStream::LastTagWas) that the correct
+ // closing tag was received.
+ bool capture_last_tag = false;
+ const Descriptor* parent = descriptor_->containing_type();
+ if (parent) {
+ for (int i = 0; i < parent->field_count(); i++) {
+ const FieldDescriptor* field = parent->field(i);
+ if (field->type() == FieldDescriptor::TYPE_GROUP &&
+ field->message_type() == descriptor_) {
+ capture_last_tag = true;
+ break;
+ }
+ }
+ }
+
+ for (int i = 0; i < descriptor_->file()->extension_count(); i++) {
+ const FieldDescriptor* field = descriptor_->file()->extension(i);
+ if (field->type() == FieldDescriptor::TYPE_GROUP &&
+ field->message_type() == descriptor_) {
+ capture_last_tag = true;
+ break;
+ }
+ }
+
printer->Print("::std::pair< ::google::protobuf::uint32, bool> p = "
- "input->ReadTagWithCutoff($max$);\n"
+ "input->ReadTagWithCutoff$lasttag$($max$u);\n"
"tag = p.first;\n"
"if (!p.second) goto handle_unusual;\n",
"max", SimpleItoa(maxtag <= kCutoff0 ? kCutoff0 :
(maxtag <= kCutoff1 ? kCutoff1 :
- maxtag)));
+ maxtag)),
+ "lasttag", !capture_last_tag ? "NoLastTag" : "");
+
if (descriptor_->field_count() > 0) {
// We don't even want to print the switch() if we have no fields because
// MSVC dislikes switch() statements that contain only a default value.
@@ -2993,6 +2992,13 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
// of each case. However, this is actually a bit slower in practice as it
// creates a jump table that is 8x larger and sparser, and meanwhile the
// if()s are highly predictable.
+ //
+ // Historically, we inserted checks to peek at the next tag on the wire and
+ // jump directly to the next case statement. While this avoids the jump
+ // table that the switch uses, it greatly increases code size (20-60%) and
+ // inserts branches that may fail (especially for real world protos that
+ // interleave--in field number order--hot and cold fields). Loadtests
+ // confirmed that removing this optimization is performance neutral.
printer->Print("switch (::google::protobuf::internal::WireFormatLite::"
"GetTagFieldNumber(tag)) {\n");
@@ -3000,7 +3006,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
// Find repeated messages and groups now, to simplify what follows.
hash_set<int> 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 ||
@@ -3009,13 +3015,9 @@ 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++) {
+ 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;
PrintFieldComment(printer, field);
@@ -3026,20 +3028,12 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
const FieldGenerator& field_generator = field_generators_.get(field);
// Emit code to parse the common, expected case.
- printer->Print("if (tag == $commontag$) {\n",
+ printer->Print("if (static_cast< ::google::protobuf::uint8>(tag) ==\n"
+ " static_cast< ::google::protobuf::uint8>($commontag$u)) {\n",
"commontag", SimpleItoa(WireFormat::MakeTag(field)));
- if (need_label ||
- (field->is_repeated() && !field->is_packed() && !loops)) {
- printer->Print(
- " parse_$name$:\n",
- "name", field->name());
- }
if (loops) {
- printer->Print(
- " DO_(input->IncrementRecursionDepth());\n"
- " parse_loop_$name$:\n",
- "name", field->name());
+ printer->Print(" DO_(input->IncrementRecursionDepth());\n");
}
printer->Indent();
@@ -3054,7 +3048,8 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
if (field->is_packed()) {
internal::WireFormatLite::WireType wiretype =
WireFormat::WireTypeForFieldType(field->type());
- printer->Print("} else if (tag == $uncommontag$) {\n",
+ printer->Print("} else if (static_cast< ::google::protobuf::uint8>(tag) ==\n"
+ " static_cast< ::google::protobuf::uint8>($uncommontag$u)) {\n",
"uncommontag", SimpleItoa(
internal::WireFormatLite::MakeTag(
field->number(), wiretype)));
@@ -3064,7 +3059,8 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
} else if (field->is_packable() && !field->is_packed()) {
internal::WireFormatLite::WireType wiretype =
internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED;
- printer->Print("} else if (tag == $uncommontag$) {\n",
+ printer->Print("} else if (static_cast< ::google::protobuf::uint8>(tag) ==\n"
+ " static_cast< ::google::protobuf::uint8>($uncommontag$u)) {\n",
"uncommontag", SimpleItoa(
internal::WireFormatLite::MakeTag(
field->number(), wiretype)));
@@ -3078,55 +3074,10 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
" goto handle_unusual;\n"
"}\n");
- // switch() is slow since it can't be predicted well. Insert some if()s
- // here that attempt to predict the next tag.
- // For non-packed repeated fields, expect the same tag again.
- if (loops) {
- printer->Print(
- "if (input->ExpectTag($tag$)) goto parse_loop_$name$;\n",
- "tag", SimpleItoa(WireFormat::MakeTag(field)),
- "name", field->name());
- } else if (field->is_repeated() && !field->is_packed()) {
- printer->Print(
- "if (input->ExpectTag($tag$)) goto parse_$name$;\n",
- "tag", SimpleItoa(WireFormat::MakeTag(field)),
- "name", field->name());
- }
-
- // Have we emitted "if (input->ExpectTag($next_tag$)) ..." yet?
- bool emitted_goto_next_tag = false;
-
- // For repeated messages/groups, we need to decrement recursion depth,
- // unless the next tag is also for a repeated message/group.
+ // For repeated messages/groups, we need to decrement recursion depth.
if (loops) {
- if (next_field_loops) {
- const FieldDescriptor* next_field = ordered_fields[i + 1];
- printer->Print(
- "if (input->ExpectTag($next_tag$)) goto parse_loop_$next_name$;\n",
- "next_tag", SimpleItoa(WireFormat::MakeTag(next_field)),
- "next_name", next_field->name());
- emitted_goto_next_tag = true;
- }
printer->Print(
- "input->UnsafeDecrementRecursionDepth();\n");
- }
-
- // If there are more fields, expect the next one.
- need_label = false;
- if (!emitted_goto_next_tag) {
- if (i + 1 == 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];
- 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;
- }
+ "input->UnsafeDecrementRecursionDepth();\n");
}
printer->Print(
@@ -3179,31 +3130,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 +3189,43 @@ GenerateMergeFromCodedStream(io::Printer* printer) {
"}\n", "full_name", descriptor_->full_name());
}
+void MessageGenerator::GenerateSerializeOneofFields(
+ io::Printer* printer, const std::vector<const FieldDescriptor*>& 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);
@@ -3280,7 +3258,7 @@ void MessageGenerator::GenerateSerializeOneField(
void MessageGenerator::GenerateSerializeOneExtensionRange(
io::Printer* printer, const Descriptor::ExtensionRange* range,
bool to_array) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars["start"] = SimpleItoa(range->start);
vars["end"] = SimpleItoa(range->end);
printer->Print(vars,
@@ -3288,7 +3266,7 @@ void MessageGenerator::GenerateSerializeOneExtensionRange(
if (to_array) {
printer->Print(vars,
"target = _extensions_.InternalSerializeWithCachedSizesToArray(\n"
- " $start$, $end$, false, target);\n\n");
+ " $start$, $end$, deterministic, target);\n\n");
} else {
printer->Print(vars,
"_extensions_.SerializeWithCachedSizes(\n"
@@ -3363,6 +3341,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) {
"classname", classname_);
printer->Indent();
+ printer->Print("(void)deterministic; // Unused\n");
printer->Print(
"// @@protoc_insertion_point(serialize_to_array_start:$full_name$)\n",
"full_name", descriptor_->full_name());
@@ -3381,10 +3360,61 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) {
void MessageGenerator::
GenerateSerializeWithCachedSizesBody(io::Printer* printer, bool to_array) {
- google::protobuf::scoped_array<const FieldDescriptor * > 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);
+ }
+ }
+
+ 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_;
+ std::vector<const FieldDescriptor*> v_;
+ };
- vector<const Descriptor::ExtensionRange*> sorted_extensions;
+ std::vector<const FieldDescriptor*> ordered_fields =
+ SortFieldsByNumber(descriptor_);
+
+ std::vector<const Descriptor::ExtensionRange*> sorted_extensions;
for (int i = 0; i < descriptor_->extension_range_count(); ++i) {
sorted_extensions.push_back(descriptor_->extension_range(i));
}
@@ -3392,22 +3422,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);
+ }
}
}
@@ -3437,30 +3471,29 @@ GenerateSerializeWithCachedSizesBody(io::Printer* printer, bool to_array) {
}
}
-static vector<uint32> RequiredFieldsBitMask(const Descriptor* desc) {
- vector<uint32> result;
- uint32 mask = 0;
- for (int i = 0; i < desc->field_count(); i++) {
- if (i > 0 && i % 32 == 0) {
- result.push_back(mask);
- mask = 0;
- }
- if (desc->field(i)->is_required()) {
- mask |= (1 << (i & 31));
+std::vector<uint32> MessageGenerator::RequiredFieldsBitMask() const {
+ const int array_size = HasBitsSize();
+ std::vector<uint32> masks(array_size, 0);
+
+ for (int i = 0; i < descriptor_->field_count(); i++) {
+ const FieldDescriptor* field = descriptor_->field(i);
+ if (!field->is_required()) {
+ continue;
}
+
+ const int has_bit_index = has_bit_indices_[field->index()];
+ masks[has_bit_index / 32] |=
+ static_cast<uint32>(1) << (has_bit_index % 32);
}
- if (mask != 0) {
- result.push_back(mask);
- }
- return result;
+ return masks;
}
// Create an expression that evaluates to
// "for all i, (_has_bits_[i] & masks[i]) == masks[i]"
// masks is allowed to be shorter than _has_bits_, but at least one element of
// masks must be non-zero.
-static string ConditionalToCheckBitmasks(const vector<uint32>& masks) {
- vector<string> parts;
+static string ConditionalToCheckBitmasks(const std::vector<uint32>& masks) {
+ std::vector<string> parts;
for (int i = 0; i < masks.size(); i++) {
if (masks[i] == 0) continue;
string m = StrCat("0x", strings::Hex(masks[i], strings::ZERO_PAD_8));
@@ -3479,9 +3512,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(
@@ -3490,8 +3523,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");
@@ -3502,14 +3536,14 @@ 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");
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const FieldDescriptor* field = descriptor_->field(i);
+ printer->Print("size_t total_size = 0;\n");
+ for (int i = 0; i < optimized_order_.size(); i++) {
+ const FieldDescriptor* field = optimized_order_[i];
if (field->is_required()) {
printer->Print("\n"
"if (has_$name$()) {\n",
@@ -3528,26 +3562,49 @@ 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");
+ if (descriptor_->extension_range_count() > 0) {
+ printer->Print(
+ "total_size += _extensions_.ByteSize();\n"
+ "\n");
+ }
+
+ if (PreserveUnknownFields(descriptor_)) {
+ if (UseUnknownFieldSet(descriptor_->file(), options_)) {
+ printer->Print(
+ "if (_internal_metadata_.have_unknown_fields()) {\n"
+ " total_size +=\n"
+ " ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(\n"
+ " unknown_fields());\n"
+ "}\n");
+ } else {
+ printer->Print(
+ "total_size += unknown_fields().size();\n"
+ "\n");
+ }
+ }
+
// Handle required fields (if any). We expect all of them to be
// present, so emit one conditional that checks for that. If they are all
// present then the fast path executes; otherwise the slow path executes.
if (num_required_fields_ > 1 && HasFieldPresence(descriptor_->file())) {
// The fast path works if all required fields are present.
- vector<uint32> masks_for_has_bits = RequiredFieldsBitMask(descriptor_);
+ const std::vector<uint32> masks_for_has_bits = RequiredFieldsBitMask();
printer->Print((string("if (") +
ConditionalToCheckBitmasks(masks_for_has_bits) +
") { // All required fields are present.\n").c_str());
printer->Indent();
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const FieldDescriptor* field = descriptor_->field(i);
+ // Oneof fields cannot be required, so optimized_order_ contains all of the
+ // fields that we need to potentially emit.
+ for (int i = 0; i < optimized_order_.size(); i++) {
+ const FieldDescriptor* field = optimized_order_[i];
if (!field->is_required()) continue;
PrintFieldComment(printer, field);
field_generators_.get(field).GenerateByteSize(printer);
@@ -3559,8 +3616,8 @@ GenerateByteSize(io::Printer* printer) {
"}\n");
} else {
// num_required_fields_ <= 1: no need to be tricky
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const FieldDescriptor* field = descriptor_->field(i);
+ for (int i = 0; i < optimized_order_.size(); i++) {
+ const FieldDescriptor* field = optimized_order_[i];
if (!field->is_required()) continue;
PrintFieldComment(printer, field);
printer->Print("if (has_$name$()) {\n",
@@ -3572,98 +3629,125 @@ GenerateByteSize(io::Printer* printer) {
}
}
- // Handle optional fields (worry below about repeateds, oneofs, etc.).
- // These are handled in chunks of 8. The first chunk is
- // the non-requireds-non-repeateds-non-unions-non-extensions in
- // descriptor_->field(0), descriptor_->field(1), ... descriptor_->field(7),
- // and the second chunk is the same for
- // descriptor_->field(8), descriptor_->field(9), ... descriptor_->field(15),
- // etc.
- hash_map<int, uint32> fields_mask_for_chunk;
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const FieldDescriptor* field = descriptor_->field(i);
- if (!field->is_required() && !field->is_repeated() &&
- !field->containing_oneof()) {
- fields_mask_for_chunk[i / 8] |= static_cast<uint32>(1) << (i % 32);
+ int last_i = -1;
+ for (int i = 0; i < optimized_order_.size(); ) {
+ // Detect infinite loops.
+ GOOGLE_CHECK_NE(i, last_i);
+ last_i = i;
+
+ // Skip required fields.
+ for (; i < optimized_order_.size() &&
+ optimized_order_[i]->is_required(); i++) {
}
- }
- int last_index = -1;
- bool chunk_block_in_progress = false;
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const FieldDescriptor* field = descriptor_->field(i);
- if (!field->is_required() && !field->is_repeated() &&
- !field->containing_oneof()) {
- // See above in GenerateClear for an explanation of this.
- // TODO(kenton): Share code? Unclear how to do so without
- // over-engineering.
- if (i / 8 != last_index / 8 || last_index < 0) {
- // End previous chunk, if there was one.
- if (chunk_block_in_progress) {
- printer->Outdent();
- printer->Print("}\n");
- chunk_block_in_progress = false;
- }
- // Start chunk.
- uint32 mask = fields_mask_for_chunk[i / 8];
- int count = popcnt(mask);
- GOOGLE_DCHECK_GE(count, 1);
- if (count == 1) {
- // No "if" here because the chunk is trivial.
- } else {
- if (HasFieldPresence(descriptor_->file())) {
- printer->Print(
- "if (_has_bits_[$index$ / 32] & $mask$u) {\n",
- "index", SimpleItoa(i),
- "mask", SimpleItoa(mask));
- printer->Indent();
- chunk_block_in_progress = true;
- }
- }
+ // Handle repeated fields.
+ for (; i < optimized_order_.size(); i++) {
+ const FieldDescriptor* field = optimized_order_[i];
+ if (!field->is_repeated()) {
+ break;
}
- last_index = i;
PrintFieldComment(printer, field);
+ const FieldGenerator& generator = field_generators_.get(field);
+ generator.GenerateByteSize(printer);
+ printer->Print("\n");
+ }
- bool have_enclosing_if = false;
- if (HasFieldPresence(descriptor_->file())) {
- printer->Print(
- "if (has_$name$()) {\n",
- "name", FieldName(field));
- printer->Indent();
- have_enclosing_if = true;
- } else {
- // Without field presence: field is serialized only if it has a
- // non-default value.
- have_enclosing_if = EmitFieldNonDefaultCondition(
- printer, "this->", field);
+ // Handle optional (non-repeated/oneof) fields.
+ //
+ // These are handled in chunks of 8. The first chunk is
+ // the non-requireds-non-repeateds-non-unions-non-extensions in
+ // descriptor_->field(0), descriptor_->field(1), ... descriptor_->field(7),
+ // and the second chunk is the same for
+ // descriptor_->field(8), descriptor_->field(9), ...
+ // descriptor_->field(15),
+ // etc.
+ int last_chunk = -1;
+ int last_chunk_start = -1;
+ int last_chunk_end = -1;
+ uint32 last_chunk_mask = 0;
+ for (; i < optimized_order_.size(); i++) {
+ const FieldDescriptor* field = optimized_order_[i];
+ if (field->is_repeated() || field->is_required()) {
+ break;
}
- field_generators_.get(field).GenerateByteSize(printer);
+ // "index" defines where in the _has_bits_ the field appears.
+ // "i" is our loop counter within optimized_order_.
+ int index = HasFieldPresence(descriptor_->file()) ?
+ has_bit_indices_[field->index()] : 0;
+ int chunk = index / 8;
+
+ if (last_chunk == -1) {
+ last_chunk = chunk;
+ last_chunk_start = i;
+ } else if (chunk != last_chunk) {
+ // Emit the fields for this chunk so far.
+ break;
+ }
+
+ last_chunk_end = i;
+ last_chunk_mask |= static_cast<uint32>(1) << (index % 32);
+ }
+
+ if (last_chunk != -1) {
+ GOOGLE_DCHECK_NE(-1, last_chunk_start);
+ GOOGLE_DCHECK_NE(-1, last_chunk_end);
+ GOOGLE_DCHECK_NE(0, last_chunk_mask);
+
+ const int count = popcnt(last_chunk_mask);
+ const bool have_outer_if = HasFieldPresence(descriptor_->file()) &&
+ (last_chunk_start != last_chunk_end);
+
+ if (have_outer_if) {
+ // Check (up to) 8 has_bits at a time if we have more than one field in
+ // this chunk. Due to field layout ordering, we may check
+ // _has_bits_[last_chunk * 8 / 32] multiple times.
+ GOOGLE_DCHECK_LE(2, count);
+ GOOGLE_DCHECK_GE(8, count);
- if (have_enclosing_if) {
- printer->Outdent();
printer->Print(
- "}\n"
- "\n");
+ "if (_has_bits_[$index$ / 32] & $mask$u) {\n",
+ "index", SimpleItoa(last_chunk * 8),
+ "mask", SimpleItoa(last_chunk_mask));
+ printer->Indent();
}
- }
- }
- if (chunk_block_in_progress) {
- printer->Outdent();
- printer->Print("}\n");
- }
+ // Go back and emit checks for each of the fields we processed.
+ for (int j = last_chunk_start; j <= last_chunk_end; j++) {
+ const FieldDescriptor* field = optimized_order_[j];
+ const FieldGenerator& generator = field_generators_.get(field);
- // Repeated fields don't use _has_bits_ so we count them in a separate
- // pass.
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const FieldDescriptor* field = descriptor_->field(i);
+ PrintFieldComment(printer, field);
- if (field->is_repeated()) {
- PrintFieldComment(printer, field);
- field_generators_.get(field).GenerateByteSize(printer);
- printer->Print("\n");
+ bool have_enclosing_if = false;
+ if (HasFieldPresence(descriptor_->file())) {
+ printer->Print(
+ "if (has_$name$()) {\n",
+ "name", FieldName(field));
+ printer->Indent();
+ have_enclosing_if = true;
+ } else {
+ // Without field presence: field is serialized only if it has a
+ // non-default value.
+ have_enclosing_if = EmitFieldNonDefaultCondition(
+ printer, "this->", field);
+ }
+
+ generator.GenerateByteSize(printer);
+
+ if (have_enclosing_if) {
+ printer->Outdent();
+ printer->Print(
+ "}\n"
+ "\n");
+ }
+ }
+
+ if (have_outer_if) {
+ printer->Outdent();
+ printer->Print("}\n");
+ }
}
}
@@ -3699,35 +3783,15 @@ GenerateByteSize(io::Printer* printer) {
"}\n");
}
- if (descriptor_->extension_range_count() > 0) {
- printer->Print(
- "total_size += _extensions_.ByteSize();\n"
- "\n");
- }
-
- if (PreserveUnknownFields(descriptor_)) {
- if (UseUnknownFieldSet(descriptor_->file(), options_)) {
- printer->Print(
- "if (_internal_metadata_.have_unknown_fields()) {\n"
- " total_size +=\n"
- " ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(\n"
- " unknown_fields());\n"
- "}\n");
- } else {
- printer->Print(
- "total_size += unknown_fields().size();\n"
- "\n");
- }
- }
-
// We update _cached_size_ even though this is a const method. In theory,
// this is not thread-compatible, because concurrent writes have undefined
// results. In practice, since any concurrent writes will be writing the
// exact same value, it works on all common processors. In a future version
// of C++, _cached_size_ should be made into an atomic<int>.
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");
@@ -3742,35 +3806,38 @@ GenerateIsInitialized(io::Printer* printer) {
"classname", classname_);
printer->Indent();
+ if (descriptor_->extension_range_count() > 0) {
+ printer->Print(
+ "if (!_extensions_.IsInitialized()) {\n"
+ " return false;\n"
+ "}\n\n");
+ }
+
if (HasFieldPresence(descriptor_->file())) {
// Check that all required fields in this message are set. We can do this
// most efficiently by checking 32 "has bits" at a time.
- int has_bits_array_size = (descriptor_->field_count() + 31) / 32;
- for (int i = 0; i < has_bits_array_size; i++) {
- uint32 mask = 0;
- for (int bit = 0; bit < 32; bit++) {
- int index = i * 32 + bit;
- if (index >= descriptor_->field_count()) break;
- const FieldDescriptor* field = descriptor_->field(index);
-
- if (field->is_required()) {
- mask |= 1 << bit;
- }
- }
+ const std::vector<uint32> masks = RequiredFieldsBitMask();
- if (mask != 0) {
- printer->Print(
- "if ((_has_bits_[$i$] & 0x$mask$) != 0x$mask$) return false;\n",
- "i", SimpleItoa(i),
- "mask", StrCat(strings::Hex(mask, strings::ZERO_PAD_8)));
+ for (int i = 0; i < masks.size(); i++) {
+ uint32 mask = masks[i];
+ if (mask == 0) {
+ continue;
}
+
+ // TODO(ckennelly): Consider doing something similar to ByteSizeLong(),
+ // where we check all of the required fields in a single branch (assuming
+ // that we aren't going to benefit from early termination).
+ printer->Print(
+ "if ((_has_bits_[$i$] & 0x$mask$) != 0x$mask$) return false;\n",
+ "i", SimpleItoa(i),
+ "mask", StrCat(strings::Hex(mask, strings::ZERO_PAD_8)));
}
}
- // Now check that all embedded messages are initialized.
- printer->Print("\n");
- for (int i = 0; i < descriptor_->field_count(); i++) {
- const FieldDescriptor* field = descriptor_->field(i);
+ // Now check that all non-oneof embedded messages are initialized.
+ for (int i = 0; i < optimized_order_.size(); i++) {
+ const FieldDescriptor* field = optimized_order_[i];
+ // TODO(ckennelly): Push this down into a generator?
if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
!ShouldIgnoreRequiredFieldCheck(field, options_) &&
HasRequiredFields(field->message_type(), options_)) {
@@ -3780,7 +3847,56 @@ GenerateIsInitialized(io::Printer* printer) {
" return false;\n",
"name", FieldName(field));
} else {
- if (field->options().weak() || !field->containing_oneof()) {
+ GOOGLE_CHECK(field->options().weak() || !field->containing_oneof());
+ // For weak fields, use the data member (::google::protobuf::Message*) instead
+ // of the getter to avoid a link dependency on the weak message type
+ // which is only forward declared.
+ printer->Print(
+ "if (has_$name$()) {\n"
+ " if (!this->$name$_->IsInitialized()) return false;\n"
+ "}\n",
+ "name", FieldName(field));
+ }
+ }
+ }
+
+ // Go through the oneof fields, emitting a switch if any might have required
+ // fields.
+ for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
+ const OneofDescriptor* oneof = descriptor_->oneof_decl(i);
+
+ bool has_required_fields = false;
+ for (int j = 0; j < oneof->field_count(); j++) {
+ const FieldDescriptor* field = oneof->field(j);
+
+ if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
+ !ShouldIgnoreRequiredFieldCheck(field, options_) &&
+ HasRequiredFields(field->message_type(), options_)) {
+ has_required_fields = true;
+ break;
+ }
+ }
+
+ if (!has_required_fields) {
+ continue;
+ }
+
+ printer->Print(
+ "switch ($oneofname$_case()) {\n",
+ "oneofname", oneof->name());
+ printer->Indent();
+ for (int j = 0; j < oneof->field_count(); j++) {
+ const FieldDescriptor* field = oneof->field(j);
+ printer->Print(
+ "case k$field_name$: {\n",
+ "field_name", UnderscoresToCamelCase(field->name(), true));
+ printer->Indent();
+
+ if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
+ !ShouldIgnoreRequiredFieldCheck(field, options_) &&
+ HasRequiredFields(field->message_type(), options_)) {
+ GOOGLE_CHECK(!(field->options().weak() || !field->containing_oneof()));
+ if (field->options().weak()) {
// For weak fields, use the data member (::google::protobuf::Message*) instead
// of the getter to avoid a link dependency on the weak message type
// which is only forward declared.
@@ -3797,13 +3913,22 @@ GenerateIsInitialized(io::Printer* printer) {
"name", FieldName(field));
}
}
- }
- }
- if (descriptor_->extension_range_count() > 0) {
+ printer->Print(
+ "break;\n");
+ printer->Outdent();
+ printer->Print(
+ "}\n");
+ }
printer->Print(
- "\n"
- "if (!_extensions_.IsInitialized()) return false;");
+ "case $cap_oneof_name$_NOT_SET: {\n"
+ " break;\n"
+ "}\n",
+ "cap_oneof_name",
+ ToUpper(oneof->name()));
+ printer->Outdent();
+ printer->Print(
+ "}\n");
}
printer->Outdent();
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_message.h b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_message.h
index b1e3fe21dd..1a804a16b3 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_message.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_message.h
@@ -64,6 +64,12 @@ class MessageGenerator {
MessageGenerator(const Descriptor* descriptor, const Options& options);
~MessageGenerator();
+ // Appends the pre-order walk of the nested generators to list.
+ void Flatten(std::vector<MessageGenerator*>* list);
+ // Append the two types of nested generators to the corresponding vector.
+ void AddGenerators(std::vector<EnumGenerator*>* enum_generators,
+ std::vector<ExtensionGenerator*>* extension_generators);
+
// Header stuff.
// Return names for forward declarations of this class and all its nested
@@ -71,17 +77,7 @@ class MessageGenerator {
// descriptor that was responsible for its inclusion in the map. This can be
// used to associate the descriptor with the code generated for it.
void FillMessageForwardDeclarations(
- map<string, const Descriptor*>* class_names);
- void FillEnumForwardDeclarations(
- map<string, const EnumDescriptor*>* enum_names);
-
- // Generate definitions of all nested enums (must come before class
- // definitions because those classes use the enums definitions).
- void GenerateEnumDefinitions(io::Printer* printer);
-
- // Generate specializations of GetEnumDescriptor<MyEnum>().
- // Precondition: in ::google::protobuf namespace.
- void GenerateGetEnumDescriptorSpecializations(io::Printer* printer);
+ std::map<string, const Descriptor*>* class_names);
// Generate definitions for this class and all its nested types.
void GenerateClassDefinition(io::Printer* printer);
@@ -95,13 +91,8 @@ class MessageGenerator {
// Source file stuff.
- // Generate code which declares all the global descriptor pointers which
- // will be initialized by the methods below.
- void GenerateDescriptorDeclarations(io::Printer* printer);
-
- // Generate code that initializes the global variable storing the message's
- // descriptor.
- void GenerateDescriptorInitializer(io::Printer* printer, int index);
+ // Generate extra fields
+ void GenerateExtraDefaultFields(io::Printer* printer);
// Generate code that calls MessageFactory::InternalRegisterGeneratedMessage()
// for all types.
@@ -130,8 +121,10 @@ class MessageGenerator {
void GenerateDependentFieldAccessorDefinitions(io::Printer* printer);
void GenerateFieldAccessorDefinitions(io::Printer* printer, bool is_inline);
- // Generate the field offsets array.
- void GenerateOffsets(io::Printer* printer);
+ // Generate the field offsets array. Returns the a pair of the total numer
+ // of entries generated and the index of the first has_bit entry.
+ std::pair<size_t, size_t> GenerateOffsets(io::Printer* printer);
+ void GenerateSchema(io::Printer* printer, int offset, int has_offset);
// Generate constructors and destructor.
void GenerateStructors(io::Printer* printer);
@@ -165,6 +158,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 std::vector<const FieldDescriptor*>& fields,
+ bool to_array);
void GenerateSerializeOneExtensionRange(
io::Printer* printer, const Descriptor::ExtensionRange* range,
bool unbounded);
@@ -172,31 +170,46 @@ class MessageGenerator {
// Generates has_foo() functions and variables for singular field has-bits.
void GenerateSingularFieldHasBits(const FieldDescriptor* field,
- map<string, string> vars,
+ std::map<string, string> vars,
io::Printer* printer);
// Generates has_foo() functions and variables for oneof field has-bits.
void GenerateOneofHasBits(io::Printer* printer, bool is_inline);
// Generates has_foo_bar() functions for oneof members.
void GenerateOneofMemberHasBits(const FieldDescriptor* field,
- const map<string, string>& vars,
+ const std::map<string, string>& vars,
io::Printer* printer);
// Generates the clear_foo() method for a field.
void GenerateFieldClear(const FieldDescriptor* field,
- const map<string, string>& vars,
+ const std::map<string, string>& vars,
io::Printer* printer);
+ void GenerateConstructorBody(io::Printer* printer,
+ std::vector<bool> already_processed,
+ bool copy_constructor) const;
+
+ size_t HasBitsSize() const;
+ std::vector<uint32> RequiredFieldsBitMask() const;
+
const Descriptor* descriptor_;
string classname_;
Options options_;
FieldGeneratorMap field_generators_;
- vector< vector<string> > runs_of_fields_; // that might be trivially cleared
+ // 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.
+ std::vector<const FieldDescriptor *> optimized_order_;
+ std::vector<int> has_bit_indices_;
+ int max_has_bit_index_;
google::protobuf::scoped_array<google::protobuf::scoped_ptr<MessageGenerator> > nested_generators_;
google::protobuf::scoped_array<google::protobuf::scoped_ptr<EnumGenerator> > enum_generators_;
google::protobuf::scoped_array<google::protobuf::scoped_ptr<ExtensionGenerator> > extension_generators_;
int num_required_fields_;
- bool uses_string_;
bool use_dependent_base_;
+ int index_in_metadata_;
+
+ friend class FileGenerator;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator);
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_message_field.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_message_field.cc
index d021035d05..c3d1745c7c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_message_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_message_field.cc
@@ -45,7 +45,7 @@ namespace cpp {
namespace {
void SetMessageVariables(const FieldDescriptor* descriptor,
- map<string, string>* variables,
+ std::map<string, string>* variables,
const Options& options) {
SetCommonFieldVariables(descriptor, variables, options);
(*variables)["type"] = FieldMessageTypeName(descriptor);
@@ -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"
@@ -219,7 +218,7 @@ GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const {
return;
}
- map<string, string> variables(variables_);
+ std::map<string, string> variables(variables_);
// For the CRTP base class, all mutation methods are dependent, and so
// they must be in the header.
variables["dependent_classname"] =
@@ -346,24 +345,30 @@ GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const {
void MessageFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer,
bool is_inline) const {
- map<string, string> 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_) {
+ // for dependent fields we cannot access its internal_default_instance,
+ // because the type is incomplete.
+ // TODO(gerbens) deprecate dependent base class.
+ std::map<string, string> 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;
}
+ std::map<string, string> 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"
+ " : *$type$::internal_default_instance();\n"
+ "}\n");
+
if (SupportsArenas(descriptor_)) {
printer->Print(variables,
"$inline$"
@@ -464,7 +469,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
void MessageFieldGenerator::
GenerateClearingCode(io::Printer* printer) const {
- map<string, string> variables(variables_);
+ std::map<string, string> variables(variables_);
variables["this_message"] = dependent_field_ ? DependentBaseDownCast() : "";
if (!HasFieldPresence(descriptor_->file())) {
// If we don't have has-bits, message presence is indicated only by ptr !=
@@ -481,6 +486,23 @@ GenerateClearingCode(io::Printer* printer) const {
}
void MessageFieldGenerator::
+GenerateMessageClearingCode(io::Printer* printer) const {
+ if (!HasFieldPresence(descriptor_->file())) {
+ // If we don't have has-bits, message presence is indicated only by ptr !=
+ // NULL. Thus on clear, we need to delete the object.
+ printer->Print(variables_,
+ "if (GetArenaNoVirtual() == NULL && $name$_ != NULL) {\n"
+ " delete $name$_;\n"
+ "}\n"
+ "$name$_ = NULL;\n");
+ } else {
+ printer->Print(variables_,
+ "GOOGLE_DCHECK($name$_ != NULL);\n"
+ "$name$_->$type$::Clear();\n");
+ }
+}
+
+void MessageFieldGenerator::
GenerateMergingCode(io::Printer* printer) const {
printer->Print(variables_,
"mutable_$name$()->$type$::MergeFrom(from.$name$());\n");
@@ -492,11 +514,51 @@ GenerateSwappingCode(io::Printer* printer) const {
}
void MessageFieldGenerator::
+GenerateDestructorCode(io::Printer* printer) const {
+ // In google3 a default instance will never get deleted so we don't need to
+ // worry about that but in opensource protobuf default instances are deleted
+ // in shutdown process and we need to take special care when handling them.
+ printer->Print(variables_,
+ "if (this != internal_default_instance()) {\n"
+ " delete $name$_;\n"
+ "}\n");
+}
+
+void MessageFieldGenerator::
GenerateConstructorCode(io::Printer* printer) const {
printer->Print(variables_, "$name$_ = NULL;\n");
}
void MessageFieldGenerator::
+GenerateCopyConstructorCode(io::Printer* printer) const {
+ // For non-Arena enabled messages, everything always goes on the heap.
+ //
+ // For Arena enabled messages, the logic is a bit more convoluted.
+ //
+ // In the copy constructor, we call InternalMetadataWithArena::MergeFrom,
+ // which does *not* copy the Arena pointer. In the generated MergeFrom
+ // (see MessageFieldGenerator::GenerateMergingCode), we:
+ // -> copy the has bits (but this is done in bulk by a memcpy in the copy
+ // constructor)
+ // -> check whether the destination field pointer is NULL (it will be, since
+ // we're initializing it and would have called SharedCtor) and if so:
+ // -> call _slow_mutable_$name$(), which calls either
+ // ::google::protobuf::Arena::CreateMessage<>(GetArenaNoVirtual()), or
+ // ::google::protobuf::Arena::Create<>(GetArenaNoVirtual())
+ //
+ // At this point, GetArenaNoVirtual returns NULL since the Arena pointer
+ // wasn't copied, so both of these methods allocate the submessage on the
+ // heap.
+
+ printer->Print(variables_,
+ "if (from.has_$name$()) {\n"
+ " $name$_ = new $type$(*from.$name$_);\n"
+ "} else {\n"
+ " $name$_ = NULL;\n"
+ "}\n");
+}
+
+void MessageFieldGenerator::
GenerateMergeFromCodedStream(io::Printer* printer) const {
if (descriptor_->type() == FieldDescriptor::TYPE_MESSAGE) {
printer->Print(variables_,
@@ -576,7 +638,7 @@ GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const {
if (!dependent_base_) {
return;
}
- map<string, string> variables(variables_);
+ std::map<string, string> variables(variables_);
variables["inline"] = "inline ";
variables["dependent_classname"] =
DependentBaseClassTemplateName(descriptor_->containing_type()) + "<T>";
@@ -596,7 +658,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
if (dependent_base_) {
return;
}
- map<string, string> variables(variables_);
+ std::map<string, string> variables(variables_);
variables["inline"] = is_inline ? "inline " : "";
variables["dependent_classname"] = variables["classname"];
variables["this_message"] = "";
@@ -610,16 +672,15 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
void MessageOneofFieldGenerator::
GenerateNonInlineAccessorDefinitions(io::Printer* printer) const {
- map<string, string> variables(variables_);
+ std::map<string, string> variables(variables_);
variables["field_member"] =
variables["oneof_prefix"] + variables["name"] + "_";
//printer->Print(variables,
}
-void MessageOneofFieldGenerator::
-InternalGenerateInlineAccessorDefinitions(const map<string, string>& variables,
- io::Printer* printer) const {
+void MessageOneofFieldGenerator::InternalGenerateInlineAccessorDefinitions(
+ const std::map<string, string>& variables, io::Printer* printer) const {
printer->Print(variables,
"$tmpl$"
"$inline$ "
@@ -663,8 +724,8 @@ InternalGenerateInlineAccessorDefinitions(const map<string, string>& 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"
@@ -789,7 +850,7 @@ InternalGenerateInlineAccessorDefinitions(const map<string, string>& variables,
void MessageOneofFieldGenerator::
GenerateClearingCode(io::Printer* printer) const {
- map<string, string> variables(variables_);
+ std::map<string, string> variables(variables_);
variables["this_message"] = dependent_field_ ? DependentBaseDownCast() : "";
if (SupportsArenas(descriptor_)) {
printer->Print(variables,
@@ -803,11 +864,22 @@ GenerateClearingCode(io::Printer* printer) const {
}
void MessageOneofFieldGenerator::
+GenerateMessageClearingCode(io::Printer* printer) const {
+ GenerateClearingCode(printer);
+}
+
+void MessageOneofFieldGenerator::
GenerateSwappingCode(io::Printer* printer) const {
// Don't print any swapping code. Swapping the union will swap this field.
}
void MessageOneofFieldGenerator::
+GenerateDestructorCode(io::Printer* printer) const {
+ // We inherit from MessageFieldGenerator, so we need to override the default
+ // behavior.
+}
+
+void MessageOneofFieldGenerator::
GenerateConstructorCode(io::Printer* printer) const {
// Don't print any constructor code. The field is in a union. We allocate
// space only when this field is used.
@@ -879,7 +951,7 @@ GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const {
if (!dependent_field_) {
return;
}
- map<string, string> variables(variables_);
+ std::map<string, string> variables(variables_);
// For the CRTP base class, all mutation methods are dependent, and so
// they must be in the header.
variables["dependent_classname"] =
@@ -910,7 +982,6 @@ GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const {
" return $this_message$$name$_.Add();\n"
"}\n");
-
if (dependent_getter_) {
printer->Print(variables,
"template <class T>\n"
@@ -934,7 +1005,7 @@ GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const {
void RepeatedMessageFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer,
bool is_inline) const {
- map<string, string> variables(variables_);
+ std::map<string, string> variables(variables_);
variables["inline"] = is_inline ? "inline " : "";
if (!dependent_getter_) {
@@ -961,7 +1032,6 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
"}\n");
}
-
if (!dependent_field_) {
printer->Print(variables,
"$inline$"
@@ -984,7 +1054,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
void RepeatedMessageFieldGenerator::
GenerateClearingCode(io::Printer* printer) const {
- map<string, string> variables(variables_);
+ std::map<string, string> variables(variables_);
variables["this_message"] = dependent_field_ ? DependentBaseDownCast() : "";
printer->Print(variables, "$this_message$$name$_.Clear();\n");
}
@@ -1041,12 +1111,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/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_message_field.h b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_message_field.h
index d8d9279c97..9ca9115313 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_message_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_message_field.h
@@ -59,23 +59,26 @@ class MessageFieldGenerator : public FieldGenerator {
bool is_inline) const;
void GenerateNonInlineAccessorDefinitions(io::Printer* printer) const;
void GenerateClearingCode(io::Printer* printer) const;
+ void GenerateMessageClearingCode(io::Printer* printer) const;
void GenerateMergingCode(io::Printer* printer) const;
void GenerateSwappingCode(io::Printer* printer) const;
+ void GenerateDestructorCode(io::Printer* printer) const;
void GenerateConstructorCode(io::Printer* printer) const;
+ void GenerateCopyConstructorCode(io::Printer* printer) const;
void GenerateMergeFromCodedStream(io::Printer* printer) const;
void GenerateSerializeWithCachedSizes(io::Printer* printer) const;
void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const;
void GenerateByteSize(io::Printer* printer) const;
protected:
- void GenerateArenaManipulationCode(const map<string, string>& variables,
+ void GenerateArenaManipulationCode(const std::map<string, string>& variables,
io::Printer* printer) const;
virtual void GenerateGetterDeclaration(io::Printer* printer) const;
const FieldDescriptor* descriptor_;
const bool dependent_field_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator);
@@ -94,7 +97,12 @@ class MessageOneofFieldGenerator : public MessageFieldGenerator {
bool is_inline) const;
void GenerateNonInlineAccessorDefinitions(io::Printer* printer) const;
void GenerateClearingCode(io::Printer* printer) const;
+
+ // MessageFieldGenerator, from which we inherit, overrides this so we need to
+ // override it as well.
+ void GenerateMessageClearingCode(io::Printer* printer) const;
void GenerateSwappingCode(io::Printer* printer) const;
+ void GenerateDestructorCode(io::Printer* printer) const;
void GenerateConstructorCode(io::Printer* printer) const;
protected:
@@ -102,7 +110,7 @@ class MessageOneofFieldGenerator : public MessageFieldGenerator {
private:
void InternalGenerateInlineAccessorDefinitions(
- const map<string, string>& variables, io::Printer* printer) const;
+ const std::map<string, string>& variables, io::Printer* printer) const;
const bool dependent_base_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageOneofFieldGenerator);
@@ -125,6 +133,7 @@ class RepeatedMessageFieldGenerator : public FieldGenerator {
void GenerateMergingCode(io::Printer* printer) const;
void GenerateSwappingCode(io::Printer* printer) const;
void GenerateConstructorCode(io::Printer* printer) const;
+ void GenerateCopyConstructorCode(io::Printer* printer) const {}
void GenerateMergeFromCodedStream(io::Printer* printer) const;
void GenerateSerializeWithCachedSizes(io::Printer* printer) const;
void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const;
@@ -137,7 +146,7 @@ class RepeatedMessageFieldGenerator : public FieldGenerator {
const FieldDescriptor* descriptor_;
const bool dependent_field_;
const bool dependent_getter_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedMessageFieldGenerator);
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_options.h b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_options.h
index ee44fb0abc..ee44fb0abc 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_options.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_options.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc
index 34a41d8232..34a41d8232 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc
index 650f0381e5..4a0a23f60e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc
@@ -80,7 +80,7 @@ int FixedSize(FieldDescriptor::Type type) {
}
void SetPrimitiveVariables(const FieldDescriptor* descriptor,
- map<string, string>* variables,
+ std::map<string, string>* variables,
const Options& options) {
SetCommonFieldVariables(descriptor, variables, options);
(*variables)["type"] = PrimitiveTypeName(descriptor->cpp_type());
@@ -122,14 +122,14 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
void PrimitiveFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const {
- map<string, string> variables(variables_);
- variables["inline"] = is_inline ? "inline" : "";
+ std::map<string, string> variables(variables_);
+ 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"
@@ -157,12 +157,17 @@ GenerateConstructorCode(io::Printer* printer) const {
}
void PrimitiveFieldGenerator::
+GenerateCopyConstructorCode(io::Printer* printer) const {
+ printer->Print(variables_, "$name$_ = from.$name$_;\n");
+}
+
+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::
@@ -206,17 +211,17 @@ PrimitiveOneofFieldGenerator::~PrimitiveOneofFieldGenerator() {}
void PrimitiveOneofFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const {
- map<string, string> variables(variables_);
- variables["inline"] = is_inline ? "inline" : "";
+ std::map<string, string> variables(variables_);
+ 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"
@@ -240,7 +245,7 @@ void PrimitiveOneofFieldGenerator::
GenerateConstructorCode(io::Printer* printer) const {
printer->Print(
variables_,
- " $classname$_default_oneof_instance_->$name$_ = $default$;\n");
+ "_$classname$_default_instance_.$name$_ = $default$;\n");
}
void PrimitiveOneofFieldGenerator::
@@ -297,28 +302,28 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
void RepeatedPrimitiveFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const {
- map<string, string> variables(variables_);
- variables["inline"] = is_inline ? "inline" : "";
+ std::map<string, string> variables(variables_);
+ 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"
@@ -346,11 +351,16 @@ GenerateConstructorCode(io::Printer* printer) const {
}
void RepeatedPrimitiveFieldGenerator::
+GenerateCopyConstructorCode(io::Printer* printer) const {
+ printer->Print(variables_, "$name$_.CopyFrom(from.$name$_);\n");
+}
+
+void RepeatedPrimitiveFieldGenerator::
GenerateMergeFromCodedStream(io::Printer* printer) const {
printer->Print(variables_,
"DO_((::google::protobuf::internal::WireFormatLite::$repeated_reader$<\n"
" $type$, $wire_format_field_type$>(\n"
- " $tag_size$, $tag$, input, this->mutable_$name$())));\n");
+ " $tag_size$, $tag$u, input, this->mutable_$name$())));\n");
}
void RepeatedPrimitiveFieldGenerator::
@@ -363,6 +373,7 @@ GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const {
void RepeatedPrimitiveFieldGenerator::
GenerateSerializeWithCachedSizes(io::Printer* printer) const {
+ bool array_written = false;
if (descriptor_->is_packed()) {
// Write the tag and the size.
printer->Print(variables_,
@@ -371,21 +382,30 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) const {
"$number$, "
"::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, "
"output);\n"
- " output->WriteVarint32(_$name$_cached_byte_size_);\n"
- "}\n");
+ " output->WriteVarint32(_$name$_cached_byte_size_);\n");
+
+ if (FixedSize(descriptor_->type()) > 0) {
+ printer->Print(variables_,
+ " ::google::protobuf::internal::WireFormatLite::Write$declared_type$Array(\n"
+ " this->$name$().data(), this->$name$_size(), output);\n");
+ array_written = true; // Wrote array all at once
+ }
+ printer->Print(variables_, "}\n");
}
- printer->Print(variables_,
- "for (int i = 0; i < this->$name$_size(); i++) {\n");
- if (descriptor_->is_packed()) {
- printer->Print(variables_,
- " ::google::protobuf::internal::WireFormatLite::Write$declared_type$NoTag(\n"
- " this->$name$(i), output);\n");
- } else {
+ if (!array_written) {
printer->Print(variables_,
- " ::google::protobuf::internal::WireFormatLite::Write$declared_type$(\n"
- " $number$, this->$name$(i), output);\n");
+ "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n");
+ if (descriptor_->is_packed()) {
+ printer->Print(variables_,
+ " ::google::protobuf::internal::WireFormatLite::Write$declared_type$NoTag(\n"
+ " this->$name$(i), output);\n");
+ } else {
+ printer->Print(variables_,
+ " ::google::protobuf::internal::WireFormatLite::Write$declared_type$(\n"
+ " $number$, this->$name$(i), output);\n");
+ }
+ printer->Print("}\n");
}
- printer->Print("}\n");
}
void RepeatedPrimitiveFieldGenerator::
@@ -403,7 +423,7 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const {
"}\n");
}
printer->Print(variables_,
- "for (int i = 0; i < this->$name$_size(); i++) {\n");
+ "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n");
if (descriptor_->is_packed()) {
printer->Print(variables_,
" target = ::google::protobuf::internal::WireFormatLite::\n"
@@ -418,20 +438,17 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const {
void RepeatedPrimitiveFieldGenerator::
GenerateByteSize(io::Printer* printer) const {
- printer->Print(variables_,
- "{\n"
- " int data_size = 0;\n");
+ printer->Print(variables_, "{\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"
- " data_size += ::google::protobuf::internal::WireFormatLite::\n"
- " $declared_type$Size(this->$name$(i));\n"
- "}\n");
+ "size_t data_size = ::google::protobuf::internal::WireFormatLite::\n"
+ " $declared_type$Size(this->$name$_);\n");
} else {
printer->Print(variables_,
- "data_size = $fixed_size$ * this->$name$_size();\n");
+ "unsigned int count = this->$name$_size();\n"
+ "size_t data_size = $fixed_size$UL * count;\n");
}
if (descriptor_->is_packed()) {
@@ -440,13 +457,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/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_primitive_field.h b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.h
index 655ebde468..44c9ff3ee5 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_primitive_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.h
@@ -59,6 +59,7 @@ class PrimitiveFieldGenerator : public FieldGenerator {
void GenerateMergingCode(io::Printer* printer) const;
void GenerateSwappingCode(io::Printer* printer) const;
void GenerateConstructorCode(io::Printer* printer) const;
+ void GenerateCopyConstructorCode(io::Printer* printer) const;
void GenerateMergeFromCodedStream(io::Printer* printer) const;
void GenerateSerializeWithCachedSizes(io::Printer* printer) const;
void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const;
@@ -66,7 +67,7 @@ class PrimitiveFieldGenerator : public FieldGenerator {
protected:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(PrimitiveFieldGenerator);
@@ -105,6 +106,7 @@ class RepeatedPrimitiveFieldGenerator : public FieldGenerator {
void GenerateMergingCode(io::Printer* printer) const;
void GenerateSwappingCode(io::Printer* printer) const;
void GenerateConstructorCode(io::Printer* printer) const;
+ void GenerateCopyConstructorCode(io::Printer* printer) const;
void GenerateMergeFromCodedStream(io::Printer* printer) const;
void GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const;
void GenerateSerializeWithCachedSizes(io::Printer* printer) const;
@@ -113,7 +115,7 @@ class RepeatedPrimitiveFieldGenerator : public FieldGenerator {
private:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPrimitiveFieldGenerator);
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_service.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_service.cc
index 6030f7ce1b..95357d9f43 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_service.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_service.cc
@@ -46,6 +46,7 @@ ServiceGenerator::ServiceGenerator(const ServiceDescriptor* descriptor,
const Options& options)
: descriptor_(descriptor) {
vars_["classname"] = descriptor_->name();
+ vars_["file_namespace"] = FileLevelNamespace(descriptor_->file()->name());
vars_["full_name"] = descriptor_->full_name();
if (options.dllexport_decl.empty()) {
vars_["dllexport"] = "";
@@ -143,7 +144,7 @@ void ServiceGenerator::GenerateMethodSignatures(
VirtualOrNon virtual_or_non, io::Printer* printer) {
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
- map<string, string> sub_vars;
+ std::map<string, string> sub_vars;
sub_vars["name"] = method->name();
sub_vars["input_type"] = ClassName(method->input_type(), true);
sub_vars["output_type"] = ClassName(method->output_type(), true);
@@ -161,7 +162,7 @@ void ServiceGenerator::GenerateMethodSignatures(
void ServiceGenerator::GenerateDescriptorInitializer(
io::Printer* printer, int index) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars["classname"] = descriptor_->name();
vars["index"] = SimpleItoa(index);
@@ -172,19 +173,20 @@ void ServiceGenerator::GenerateDescriptorInitializer(
// ===================================================================
void ServiceGenerator::GenerateImplementation(io::Printer* printer) {
- printer->Print(vars_,
- "$classname$::~$classname$() {}\n"
- "\n"
- "const ::google::protobuf::ServiceDescriptor* $classname$::descriptor() {\n"
- " protobuf_AssignDescriptorsOnce();\n"
- " return $classname$_descriptor_;\n"
- "}\n"
- "\n"
- "const ::google::protobuf::ServiceDescriptor* $classname$::GetDescriptor() {\n"
- " protobuf_AssignDescriptorsOnce();\n"
- " return $classname$_descriptor_;\n"
- "}\n"
- "\n");
+ vars_["index"] = SimpleItoa(index_in_metadata_);
+ printer->Print(
+ vars_,
+ "$classname$::~$classname$() {}\n"
+ "\n"
+ "const ::google::protobuf::ServiceDescriptor* $classname$::descriptor() {\n"
+ " $file_namespace$::protobuf_AssignDescriptorsOnce();\n"
+ " return $file_namespace$::file_level_service_descriptors[$index$];\n"
+ "}\n"
+ "\n"
+ "const ::google::protobuf::ServiceDescriptor* $classname$::GetDescriptor() {\n"
+ " return descriptor();\n"
+ "}\n"
+ "\n");
// Generate methods of the interface.
GenerateNotImplementedMethods(printer);
@@ -212,7 +214,7 @@ void ServiceGenerator::GenerateImplementation(io::Printer* printer) {
void ServiceGenerator::GenerateNotImplementedMethods(io::Printer* printer) {
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
- map<string, string> sub_vars;
+ std::map<string, string> sub_vars;
sub_vars["classname"] = descriptor_->name();
sub_vars["name"] = method->name();
sub_vars["index"] = SimpleItoa(i);
@@ -232,18 +234,20 @@ void ServiceGenerator::GenerateNotImplementedMethods(io::Printer* printer) {
}
void ServiceGenerator::GenerateCallMethod(io::Printer* printer) {
- printer->Print(vars_,
- "void $classname$::CallMethod(const ::google::protobuf::MethodDescriptor* method,\n"
- " ::google::protobuf::RpcController* controller,\n"
- " const ::google::protobuf::Message* request,\n"
- " ::google::protobuf::Message* response,\n"
- " ::google::protobuf::Closure* done) {\n"
- " GOOGLE_DCHECK_EQ(method->service(), $classname$_descriptor_);\n"
- " switch(method->index()) {\n");
+ printer->Print(
+ vars_,
+ "void $classname$::CallMethod(const ::google::protobuf::MethodDescriptor* method,\n"
+ " ::google::protobuf::RpcController* controller,\n"
+ " const ::google::protobuf::Message* request,\n"
+ " ::google::protobuf::Message* response,\n"
+ " ::google::protobuf::Closure* done) {\n"
+ " GOOGLE_DCHECK_EQ(method->service(), "
+ "$file_namespace$::file_level_service_descriptors[$index$]);\n"
+ " switch(method->index()) {\n");
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
- map<string, string> sub_vars;
+ std::map<string, string> sub_vars;
sub_vars["name"] = method->name();
sub_vars["index"] = SimpleItoa(i);
sub_vars["input_type"] = ClassName(method->input_type(), true);
@@ -289,7 +293,7 @@ void ServiceGenerator::GenerateGetPrototype(RequestOrResponse which,
const Descriptor* type =
(which == REQUEST) ? method->input_type() : method->output_type();
- map<string, string> sub_vars;
+ std::map<string, string> sub_vars;
sub_vars["index"] = SimpleItoa(i);
sub_vars["type"] = ClassName(type, true);
@@ -312,7 +316,7 @@ void ServiceGenerator::GenerateGetPrototype(RequestOrResponse which,
void ServiceGenerator::GenerateStubMethods(io::Printer* printer) {
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
- map<string, string> sub_vars;
+ std::map<string, string> sub_vars;
sub_vars["classname"] = descriptor_->name();
sub_vars["name"] = method->name();
sub_vars["index"] = SimpleItoa(i);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_service.h b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_service.h
index ede2fd80e6..33c025476a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_service.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_service.h
@@ -105,8 +105,11 @@ class ServiceGenerator {
void GenerateStubMethods(io::Printer* printer);
const ServiceDescriptor* descriptor_;
- map<string, string> vars_;
+ std::map<string, string> vars_;
+ int index_in_metadata_;
+
+ friend class FileGenerator;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceGenerator);
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_string_field.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_string_field.cc
index 1d7434578c..664a277946 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_string_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_string_field.cc
@@ -46,20 +46,19 @@ namespace cpp {
namespace {
void SetStringVariables(const FieldDescriptor* descriptor,
- map<string, string>* variables,
+ std::map<string, string>* variables,
const Options& options) {
SetCommonFieldVariables(descriptor, variables, options);
(*variables)["default"] = DefaultValue(descriptor);
(*variables)["default_length"] =
SimpleItoa(descriptor->default_value_string().length());
- string default_variable_string =
+ string default_variable_string = "_default_" + FieldName(descriptor) + "_";
+ (*variables)["default_variable_name"] = default_variable_string;
+ (*variables)["default_variable"] =
descriptor->default_value_string().empty()
? "&::google::protobuf::internal::GetEmptyStringAlreadyInited()"
- : "_default_" + FieldName(descriptor) + "_";
- (*variables)["default_variable"] = default_variable_string;
- (*variables)["default_value_init"] =
- descriptor->default_value_string().empty()
- ? "" : "*" + default_variable_string;
+ : "&" + (*variables)["classname"] + "::" + default_variable_string +
+ ".get()";
(*variables)["pointer_type"] =
descriptor->type() == FieldDescriptor::TYPE_BYTES ? "void" : "char";
// NOTE: Escaped here to unblock proto1->proto2 migration.
@@ -104,7 +103,9 @@ GeneratePrivateMembers(io::Printer* printer) const {
void StringFieldGenerator::
GenerateStaticMembers(io::Printer* printer) const {
if (!descriptor_->default_value_string().empty()) {
- printer->Print(variables_, "static ::std::string* $default_variable$;\n");
+ printer->Print(variables_,
+ "static ::google::protobuf::internal::ExplicitlyConstructed< ::std::string>"
+ " $default_variable_name$;\n");
}
}
@@ -140,7 +141,16 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
printer->Print(variables_,
"$deprecated_attr$const ::std::string& $name$() const;\n"
- "$deprecated_attr$void set_$name$(const ::std::string& value);\n"
+ "$deprecated_attr$void set_$name$(const ::std::string& value);\n");
+
+ if (!SupportsArenas(descriptor_)) {
+ printer->Print(variables_,
+ "#if LANG_CXX11\n"
+ "$deprecated_attr$void set_$name$(::std::string&& value);\n"
+ "#endif\n");
+ }
+
+ printer->Print(variables_,
"$deprecated_attr$void set_$name$(const char* value);\n"
"$deprecated_attr$void set_$name$(const $pointer_type$* value, size_t size)"
";\n"
@@ -165,117 +175,129 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
void StringFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer,
bool is_inline) const {
- map<string, string> variables(variables_);
- variables["inline"] = is_inline ? "inline" : "";
+ std::map<string, string> variables(variables_);
+ variables["inline"] = is_inline ? "inline " : "";
if (SupportsArenas(descriptor_)) {
- printer->Print(variables,
- "$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"
- " $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"
- " $set_hasbit$\n"
- " $name$_.Set($default_variable$, $string_piece$(value),\n"
- " GetArenaNoVirtual());\n"
- " // @@protoc_insertion_point(field_set_char:$full_name$)\n"
- "}\n"
- "$inline$ "
- "void $classname$::set_$name$(const $pointer_type$* value,\n"
- " size_t size) {\n"
- " $set_hasbit$\n"
- " $name$_.Set($default_variable$, $string_piece$(\n"
- " reinterpret_cast<const char*>(value), size), GetArenaNoVirtual());\n"
- " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
- "}\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"
- " // @@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"
- " // @@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"
- " if ($name$ != NULL) {\n"
- " $set_hasbit$\n"
- " } else {\n"
- " $clear_hasbit$\n"
- " }\n"
- " $name$_.SetAllocated($default_variable$, $name$,\n"
- " GetArenaNoVirtual());\n"
- " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
- "}\n"
- "$inline$ void $classname$::unsafe_arena_set_allocated_$name$(\n"
- " ::std::string* $name$) {\n"
- " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n"
- " if ($name$ != NULL) {\n"
- " $set_hasbit$\n"
- " } else {\n"
- " $clear_hasbit$\n"
- " }\n"
- " $name$_.UnsafeArenaSetAllocated($default_variable$,\n"
- " $name$, GetArenaNoVirtual());\n"
- " // @@protoc_insertion_point(field_unsafe_arena_set_allocated:"
- "$full_name$)\n"
- "}\n");
+ printer->Print(
+ variables,
+ "$inline$const ::std::string& $classname$::$name$() const {\n"
+ " // @@protoc_insertion_point(field_get:$full_name$)\n"
+ " return $name$_.Get();\n"
+ "}\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"
+ " $set_hasbit$\n"
+ " $name$_.Set($default_variable$, $string_piece$(value),\n"
+ " GetArenaNoVirtual());\n"
+ " // @@protoc_insertion_point(field_set_char:$full_name$)\n"
+ "}\n"
+ "$inline$"
+ "void $classname$::set_$name$(const $pointer_type$* value,\n"
+ " size_t size) {\n"
+ " $set_hasbit$\n"
+ " $name$_.Set($default_variable$, $string_piece$(\n"
+ " reinterpret_cast<const char*>(value), size), "
+ "GetArenaNoVirtual());\n"
+ " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
+ "}\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"
+ " // @@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"
+ " // "
+ "@@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"
+ " if ($name$ != NULL) {\n"
+ " $set_hasbit$\n"
+ " } else {\n"
+ " $clear_hasbit$\n"
+ " }\n"
+ " $name$_.SetAllocated($default_variable$, $name$,\n"
+ " GetArenaNoVirtual());\n"
+ " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
+ "}\n"
+ "$inline$void $classname$::unsafe_arena_set_allocated_$name$(\n"
+ " ::std::string* $name$) {\n"
+ " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n"
+ " if ($name$ != NULL) {\n"
+ " $set_hasbit$\n"
+ " } else {\n"
+ " $clear_hasbit$\n"
+ " }\n"
+ " $name$_.UnsafeArenaSetAllocated($default_variable$,\n"
+ " $name$, GetArenaNoVirtual());\n"
+ " // @@protoc_insertion_point(field_unsafe_arena_set_allocated:"
+ "$full_name$)\n"
+ "}\n");
} else {
// No-arena case.
- printer->Print(variables,
- "$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"
- " $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"
- " $set_hasbit$\n"
- " $name$_.SetNoArena($default_variable$, $string_piece$(value));\n"
- " // @@protoc_insertion_point(field_set_char:$full_name$)\n"
- "}\n"
- "$inline$ "
- "void $classname$::set_$name$(const $pointer_type$* value, "
- "size_t size) {\n"
- " $set_hasbit$\n"
- " $name$_.SetNoArena($default_variable$,\n"
- " $string_piece$(reinterpret_cast<const char*>(value), size));\n"
- " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
- "}\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"
- " // @@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"
- " if ($name$ != NULL) {\n"
- " $set_hasbit$\n"
- " } else {\n"
- " $clear_hasbit$\n"
- " }\n"
- " $name$_.SetAllocatedNoArena($default_variable$, $name$);\n"
- " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
- "}\n");
+ printer->Print(
+ variables,
+ "$inline$const ::std::string& $classname$::$name$() const {\n"
+ " // @@protoc_insertion_point(field_get:$full_name$)\n"
+ " return $name$_.GetNoArena();\n"
+ "}\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"
+ "#if LANG_CXX11\n"
+ "$inline$void $classname$::set_$name$(::std::string&& value) {\n"
+ " $set_hasbit$\n"
+ " $name$_.SetNoArena(\n"
+ " $default_variable$, ::std::move(value));\n"
+ " // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n"
+ "}\n"
+ "#endif\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$"
+ "void $classname$::set_$name$(const $pointer_type$* value, "
+ "size_t size) {\n"
+ " $set_hasbit$\n"
+ " $name$_.SetNoArena($default_variable$,\n"
+ " $string_piece$(reinterpret_cast<const char*>(value), size));\n"
+ " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
+ "}\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"
+ " // @@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"
+ " if ($name$ != NULL) {\n"
+ " $set_hasbit$\n"
+ " } else {\n"
+ " $clear_hasbit$\n"
+ " }\n"
+ " $name$_.SetAllocatedNoArena($default_variable$, $name$);\n"
+ " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
+ "}\n");
}
}
@@ -284,7 +306,8 @@ GenerateNonInlineAccessorDefinitions(io::Printer* printer) const {
if (!descriptor_->default_value_string().empty()) {
// Initialized in GenerateDefaultInstanceAllocator.
printer->Print(variables_,
- "::std::string* $classname$::$default_variable$ = NULL;\n");
+ "::google::protobuf::internal::ExplicitlyConstructed< ::std::string> "
+ "$classname$::$default_variable_name$;\n");
}
}
@@ -314,6 +337,52 @@ GenerateClearingCode(io::Printer* printer) const {
}
void StringFieldGenerator::
+GenerateMessageClearingCode(io::Printer* printer) const {
+ // Two-dimension specialization here: supporting arenas, field presence, or
+ // not, and default value is the empty string or not. Complexity here ensures
+ // the minimal number of branches / amount of extraneous code at runtime
+ // (given that the below methods are inlined one-liners)!
+
+ // If we have field presence, then the Clear() method of the protocol buffer
+ // will have checked that this field is set. If so, we can avoid redundant
+ // checks against default_variable.
+ const bool must_be_present = HasFieldPresence(descriptor_->file());
+
+ if (must_be_present) {
+ printer->Print(variables_,
+ "GOOGLE_DCHECK(!$name$_.IsDefault($default_variable$));\n");
+ }
+
+ if (SupportsArenas(descriptor_)) {
+ if (descriptor_->default_value_string().empty()) {
+ printer->Print(variables_,
+ "$name$_.ClearToEmpty($default_variable$, GetArenaNoVirtual());\n");
+ } else {
+ printer->Print(variables_,
+ "$name$_.ClearToDefault($default_variable$, GetArenaNoVirtual());\n");
+ }
+ } else if (must_be_present) {
+ // When Arenas are disabled and field presence has been checked, we can
+ // safely treat the ArenaStringPtr as a string*.
+ if (descriptor_->default_value_string().empty()) {
+ printer->Print(variables_,
+ "(*$name$_.UnsafeRawStringPointer())->clear();\n");
+ } else {
+ printer->Print(variables_,
+ "(*$name$_.UnsafeRawStringPointer())->assign(*$default_variable$);\n");
+ }
+ } else {
+ if (descriptor_->default_value_string().empty()) {
+ printer->Print(variables_,
+ "$name$_.ClearToEmptyNoArena($default_variable$);\n");
+ } else {
+ printer->Print(variables_,
+ "$name$_.ClearToDefaultNoArena($default_variable$);\n");
+ }
+ }
+}
+
+void StringFieldGenerator::
GenerateMergingCode(io::Printer* printer) const {
if (SupportsArenas(descriptor_) || descriptor_->containing_oneof() != NULL) {
// TODO(gpike): improve this
@@ -337,10 +406,40 @@ GenerateConstructorCode(io::Printer* printer) const {
}
void StringFieldGenerator::
+GenerateCopyConstructorCode(io::Printer* printer) const {
+ GenerateConstructorCode(printer);
+
+ if (HasFieldPresence(descriptor_->file())) {
+ printer->Print(variables_,
+ "if (from.has_$name$()) {\n");
+ } else {
+ printer->Print(variables_,
+ "if (from.$name$().size() > 0) {\n");
+ }
+
+ printer->Indent();
+
+ if (SupportsArenas(descriptor_) || descriptor_->containing_oneof() != NULL) {
+ // TODO(gpike): improve this
+ printer->Print(variables_,
+ "$name$_.Set($default_variable$, from.$name$(),\n"
+ " GetArenaNoVirtual());\n");
+ } else {
+ printer->Print(variables_,
+ "$name$_.AssignWithDefault($default_variable$, from.$name$_);\n");
+ }
+
+ printer->Outdent();
+ printer->Print("}\n");
+}
+
+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");
@@ -351,8 +450,9 @@ void StringFieldGenerator::
GenerateDefaultInstanceAllocator(io::Printer* printer) const {
if (!descriptor_->default_value_string().empty()) {
printer->Print(variables_,
- "$classname$::$default_variable$ =\n"
- " new ::std::string($default$, $default_length$);\n");
+ "$classname$::$default_variable_name$.DefaultConstruct();\n"
+ "*$classname$::$default_variable_name$.get_mutable() = "
+ "::std::string($default$, $default_length$);\n");
}
}
@@ -360,7 +460,7 @@ void StringFieldGenerator::
GenerateShutdownCode(io::Printer* printer) const {
if (!descriptor_->default_value_string().empty()) {
printer->Print(variables_,
- "delete $classname$::$default_variable$;\n");
+ "$classname$::$default_variable_name$.Shutdown();\n");
}
}
@@ -425,185 +525,203 @@ StringOneofFieldGenerator::~StringOneofFieldGenerator() {}
void StringOneofFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer,
bool is_inline) const {
- map<string, string> variables(variables_);
- variables["inline"] = is_inline ? "inline" : "";
+ std::map<string, string> variables(variables_);
+ variables["inline"] = is_inline ? "inline " : "";
if (SupportsArenas(descriptor_)) {
- printer->Print(variables,
- "$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"
- " if (!has_$name$()) {\n"
- " clear_$oneof_name$();\n"
- " set_has_$name$();\n"
- " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
- " }\n"
- " $oneof_prefix$$name$_.Set($default_variable$, value,\n"
- " GetArenaNoVirtual());\n"
- " // @@protoc_insertion_point(field_set:$full_name$)\n"
- "}\n"
- "$inline$ void $classname$::set_$name$(const char* value) {\n"
- " if (!has_$name$()) {\n"
- " clear_$oneof_name$();\n"
- " set_has_$name$();\n"
- " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
- " }\n"
- " $oneof_prefix$$name$_.Set($default_variable$,\n"
- " $string_piece$(value), GetArenaNoVirtual());\n"
- " // @@protoc_insertion_point(field_set_char:$full_name$)\n"
- "}\n"
- "$inline$ "
- "void $classname$::set_$name$(const $pointer_type$* value,\n"
- " size_t size) {\n"
- " if (!has_$name$()) {\n"
- " clear_$oneof_name$();\n"
- " set_has_$name$();\n"
- " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
- " }\n"
- " $oneof_prefix$$name$_.Set($default_variable$, $string_piece$(\n"
- " reinterpret_cast<const char*>(value), size),\n"
- " GetArenaNoVirtual());\n"
- " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
- "}\n"
- "$inline$ ::std::string* $classname$::mutable_$name$() {\n"
- " if (!has_$name$()) {\n"
- " clear_$oneof_name$();\n"
- " set_has_$name$();\n"
- " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
- " }\n"
- " return $oneof_prefix$$name$_.Mutable($default_variable$,\n"
- " GetArenaNoVirtual());\n"
- " // @@protoc_insertion_point(field_mutable:$full_name$)\n"
- "}\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"
- " return $oneof_prefix$$name$_.Release($default_variable$,\n"
- " GetArenaNoVirtual());\n"
- " } else {\n"
- " return NULL;\n"
- " }\n"
- "}\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"
- " clear_has_$oneof_name$();\n"
- " return $oneof_prefix$$name$_.UnsafeArenaRelease(\n"
- " $default_variable$, GetArenaNoVirtual());\n"
- " } else {\n"
- " return NULL;\n"
- " }\n"
- "}\n"
- "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\n"
- " if (!has_$name$()) {\n"
- " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
- " }\n"
- " clear_$oneof_name$();\n"
- " if ($name$ != NULL) {\n"
- " set_has_$name$();\n"
- " $oneof_prefix$$name$_.SetAllocated($default_variable$, $name$,\n"
- " GetArenaNoVirtual());\n"
- " }\n"
- " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
- "}\n"
- "$inline$ void $classname$::unsafe_arena_set_allocated_$name$("
- "::std::string* $name$) {\n"
- " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n"
- " if (!has_$name$()) {\n"
- " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
- " }\n"
- " clear_$oneof_name$();\n"
- " if ($name$) {\n"
- " set_has_$name$();\n"
- " $oneof_prefix$$name$_.UnsafeArenaSetAllocated($default_variable$, "
- "$name$, GetArenaNoVirtual());\n"
- " }\n"
- " // @@protoc_insertion_point(field_unsafe_arena_set_allocated:"
- "$full_name$)\n"
- "}\n");
+ printer->Print(
+ variables,
+ "$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();\n"
+ " }\n"
+ " return *$default_variable$;\n"
+ "}\n"
+ "$inline$void $classname$::set_$name$(const ::std::string& value) {\n"
+ " if (!has_$name$()) {\n"
+ " clear_$oneof_name$();\n"
+ " set_has_$name$();\n"
+ " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
+ " }\n"
+ " $oneof_prefix$$name$_.Set($default_variable$, value,\n"
+ " GetArenaNoVirtual());\n"
+ " // @@protoc_insertion_point(field_set:$full_name$)\n"
+ "}\n"
+ "$inline$void $classname$::set_$name$(const char* value) {\n"
+ " if (!has_$name$()) {\n"
+ " clear_$oneof_name$();\n"
+ " set_has_$name$();\n"
+ " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
+ " }\n"
+ " $oneof_prefix$$name$_.Set($default_variable$,\n"
+ " $string_piece$(value), GetArenaNoVirtual());\n"
+ " // @@protoc_insertion_point(field_set_char:$full_name$)\n"
+ "}\n"
+ "$inline$"
+ "void $classname$::set_$name$(const $pointer_type$* value,\n"
+ " size_t size) {\n"
+ " if (!has_$name$()) {\n"
+ " clear_$oneof_name$();\n"
+ " set_has_$name$();\n"
+ " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
+ " }\n"
+ " $oneof_prefix$$name$_.Set($default_variable$, $string_piece$(\n"
+ " reinterpret_cast<const char*>(value), size),\n"
+ " GetArenaNoVirtual());\n"
+ " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
+ "}\n"
+ "$inline$::std::string* $classname$::mutable_$name$() {\n"
+ " if (!has_$name$()) {\n"
+ " clear_$oneof_name$();\n"
+ " set_has_$name$();\n"
+ " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
+ " }\n"
+ " return $oneof_prefix$$name$_.Mutable($default_variable$,\n"
+ " GetArenaNoVirtual());\n"
+ " // @@protoc_insertion_point(field_mutable:$full_name$)\n"
+ "}\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"
+ " return $oneof_prefix$$name$_.Release($default_variable$,\n"
+ " GetArenaNoVirtual());\n"
+ " } else {\n"
+ " return NULL;\n"
+ " }\n"
+ "}\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"
+ " clear_has_$oneof_name$();\n"
+ " return $oneof_prefix$$name$_.UnsafeArenaRelease(\n"
+ " $default_variable$, GetArenaNoVirtual());\n"
+ " } else {\n"
+ " return NULL;\n"
+ " }\n"
+ "}\n"
+ "$inline$void $classname$::set_allocated_$name$(::std::string* $name$) {\n"
+ " if (!has_$name$()) {\n"
+ " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
+ " }\n"
+ " clear_$oneof_name$();\n"
+ " if ($name$ != NULL) {\n"
+ " set_has_$name$();\n"
+ " $oneof_prefix$$name$_.SetAllocated($default_variable$, $name$,\n"
+ " GetArenaNoVirtual());\n"
+ " }\n"
+ " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
+ "}\n"
+ "$inline$void $classname$::unsafe_arena_set_allocated_$name$("
+ "::std::string* $name$) {\n"
+ " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n"
+ " if (!has_$name$()) {\n"
+ " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
+ " }\n"
+ " clear_$oneof_name$();\n"
+ " if ($name$) {\n"
+ " set_has_$name$();\n"
+ " $oneof_prefix$$name$_.UnsafeArenaSetAllocated($default_variable$, "
+ "$name$, GetArenaNoVirtual());\n"
+ " }\n"
+ " // @@protoc_insertion_point(field_unsafe_arena_set_allocated:"
+ "$full_name$)\n"
+ "}\n");
} else {
// No-arena case.
- printer->Print(variables,
- "$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"
- " // @@protoc_insertion_point(field_set:$full_name$)\n"
- " if (!has_$name$()) {\n"
- " clear_$oneof_name$();\n"
- " set_has_$name$();\n"
- " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
- " }\n"
- " $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"
- " if (!has_$name$()) {\n"
- " clear_$oneof_name$();\n"
- " set_has_$name$();\n"
- " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
- " }\n"
- " $oneof_prefix$$name$_.SetNoArena($default_variable$,\n"
- " $string_piece$(value));\n"
- " // @@protoc_insertion_point(field_set_char:$full_name$)\n"
- "}\n"
- "$inline$ "
- "void $classname$::set_$name$(const $pointer_type$* value, size_t size) {\n"
- " if (!has_$name$()) {\n"
- " clear_$oneof_name$();\n"
- " set_has_$name$();\n"
- " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
- " }\n"
- " $oneof_prefix$$name$_.SetNoArena($default_variable$, $string_piece$(\n"
- " reinterpret_cast<const char*>(value), size));\n"
- " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
- "}\n"
- "$inline$ ::std::string* $classname$::mutable_$name$() {\n"
- " if (!has_$name$()) {\n"
- " clear_$oneof_name$();\n"
- " set_has_$name$();\n"
- " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
- " }\n"
- " // @@protoc_insertion_point(field_mutable:$full_name$)\n"
- " return $oneof_prefix$$name$_.MutableNoArena($default_variable$);\n"
- "}\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"
- " return $oneof_prefix$$name$_.ReleaseNoArena($default_variable$);\n"
- " } else {\n"
- " return NULL;\n"
- " }\n"
- "}\n"
- "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\n"
- " if (!has_$name$()) {\n"
- " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
- " }\n"
- " clear_$oneof_name$();\n"
- " if ($name$ != NULL) {\n"
- " set_has_$name$();\n"
- " $oneof_prefix$$name$_.SetAllocatedNoArena($default_variable$,\n"
- " $name$);\n"
- " }\n"
- " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
- "}\n");
+ printer->Print(
+ variables,
+ "$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();\n"
+ " }\n"
+ " return *$default_variable$;\n"
+ "}\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"
+ " set_has_$name$();\n"
+ " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
+ " }\n"
+ " $oneof_prefix$$name$_.SetNoArena($default_variable$, value);\n"
+ " // @@protoc_insertion_point(field_set:$full_name$)\n"
+ "}\n"
+ "#if LANG_CXX11\n"
+ "$inline$void $classname$::set_$name$(::std::string&& value) {\n"
+ " // @@protoc_insertion_point(field_set:$full_name$)\n"
+ " if (!has_$name$()) {\n"
+ " clear_$oneof_name$();\n"
+ " set_has_$name$();\n"
+ " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
+ " }\n"
+ " $oneof_prefix$$name$_.SetNoArena(\n"
+ " $default_variable$, ::std::move(value));\n"
+ " // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n"
+ "}\n"
+ "#endif\n"
+ "$inline$void $classname$::set_$name$(const char* value) {\n"
+ " if (!has_$name$()) {\n"
+ " clear_$oneof_name$();\n"
+ " set_has_$name$();\n"
+ " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
+ " }\n"
+ " $oneof_prefix$$name$_.SetNoArena($default_variable$,\n"
+ " $string_piece$(value));\n"
+ " // @@protoc_insertion_point(field_set_char:$full_name$)\n"
+ "}\n"
+ "$inline$"
+ "void $classname$::set_$name$(const $pointer_type$* value, size_t "
+ "size) {\n"
+ " if (!has_$name$()) {\n"
+ " clear_$oneof_name$();\n"
+ " set_has_$name$();\n"
+ " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
+ " }\n"
+ " $oneof_prefix$$name$_.SetNoArena($default_variable$, "
+ "$string_piece$(\n"
+ " reinterpret_cast<const char*>(value), size));\n"
+ " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n"
+ "}\n"
+ "$inline$::std::string* $classname$::mutable_$name$() {\n"
+ " if (!has_$name$()) {\n"
+ " clear_$oneof_name$();\n"
+ " set_has_$name$();\n"
+ " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
+ " }\n"
+ " // @@protoc_insertion_point(field_mutable:$full_name$)\n"
+ " return $oneof_prefix$$name$_.MutableNoArena($default_variable$);\n"
+ "}\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"
+ " return $oneof_prefix$$name$_.ReleaseNoArena($default_variable$);\n"
+ " } else {\n"
+ " return NULL;\n"
+ " }\n"
+ "}\n"
+ "$inline$void $classname$::set_allocated_$name$(::std::string* $name$) {\n"
+ " if (!has_$name$()) {\n"
+ " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
+ " }\n"
+ " clear_$oneof_name$();\n"
+ " if ($name$ != NULL) {\n"
+ " set_has_$name$();\n"
+ " $oneof_prefix$$name$_.SetAllocatedNoArena($default_variable$,\n"
+ " $name$);\n"
+ " }\n"
+ " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
+ "}\n");
}
}
void StringOneofFieldGenerator::
GenerateClearingCode(io::Printer* printer) const {
- map<string, string> variables(variables_);
+ std::map<string, string> variables(variables_);
if (dependent_field_) {
variables["this_message"] = DependentBaseDownCast();
// This clearing code may be in the dependent base class. If the default
@@ -612,8 +730,9 @@ GenerateClearingCode(io::Printer* printer) const {
// default value's global singleton instance. See SetStringVariables() for
// possible values of default_variable.
if (!descriptor_->default_value_string().empty()) {
- variables["default_variable"] =
- DependentBaseDownCast() + variables["default_variable"];
+ variables["default_variable"] = "&" + DependentBaseDownCast() +
+ variables["default_variable_name"] +
+ ".get()";
}
} else {
variables["this_message"] = "";
@@ -630,15 +749,21 @@ GenerateClearingCode(io::Printer* printer) const {
}
void StringOneofFieldGenerator::
+GenerateMessageClearingCode(io::Printer* printer) const {
+ return GenerateClearingCode(printer);
+}
+
+void StringOneofFieldGenerator::
GenerateSwappingCode(io::Printer* printer) const {
// Don't print any swapping code. Swapping the union will swap this field.
}
void StringOneofFieldGenerator::
GenerateConstructorCode(io::Printer* printer) const {
- printer->Print(variables_,
- " $classname$_default_oneof_instance_->$name$_.UnsafeSetDefault("
- "$default_variable$);\n");
+ printer->Print(
+ variables_,
+ "_$classname$_default_instance_.$name$_.UnsafeSetDefault(\n"
+ " $default_variable$);\n");
}
void StringOneofFieldGenerator::
@@ -705,17 +830,21 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
"$deprecated_attr$const ::std::string& $name$(int index) const;\n"
"$deprecated_attr$::std::string* mutable_$name$(int index);\n"
"$deprecated_attr$void set_$name$(int index, const ::std::string& value);\n"
+ "#if LANG_CXX11\n"
+ "$deprecated_attr$void set_$name$(int index, ::std::string&& value);\n"
+ "#endif\n"
"$deprecated_attr$void set_$name$(int index, const char* value);\n"
""
"$deprecated_attr$void set_$name$("
"int index, const $pointer_type$* value, size_t size);\n"
"$deprecated_attr$::std::string* add_$name$();\n"
"$deprecated_attr$void add_$name$(const ::std::string& value);\n"
+ "#if LANG_CXX11\n"
+ "$deprecated_attr$void add_$name$(::std::string&& value);\n"
+ "#endif\n"
"$deprecated_attr$void add_$name$(const char* value);\n"
"$deprecated_attr$void add_$name$(const $pointer_type$* value, size_t size)"
- ";\n");
-
- printer->Print(variables_,
+ ";\n"
"$deprecated_attr$const ::google::protobuf::RepeatedPtrField< ::std::string>& $name$() "
"const;\n"
"$deprecated_attr$::google::protobuf::RepeatedPtrField< ::std::string>* mutable_$name$()"
@@ -731,56 +860,67 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
void RepeatedStringFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer,
bool is_inline) const {
- map<string, string> variables(variables_);
- variables["inline"] = is_inline ? "inline" : "";
+ std::map<string, string> variables(variables_);
+ 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"
+ "#if LANG_CXX11\n"
+ "$inline$void $classname$::set_$name$(int index, ::std::string&& value) {\n"
+ " // @@protoc_insertion_point(field_set:$full_name$)\n"
+ " $name$_.Mutable(index)->assign(std::move(value));\n"
+ "}\n"
+ "#endif\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<const char*>(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"
+ "#if LANG_CXX11\n"
+ "$inline$void $classname$::add_$name$(::std::string&& value) {\n"
+ " $name$_.Add()->assign(std::move(value));\n"
+ " // @@protoc_insertion_point(field_add:$full_name$)\n"
+ "}\n"
+ "#endif\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<const char*>(value), size);\n"
" // @@protoc_insertion_point(field_add_pointer:$full_name$)\n"
- "}\n");
- printer->Print(variables,
- "$inline$ const ::google::protobuf::RepeatedPtrField< ::std::string>&\n"
+ "}\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"
@@ -808,6 +948,11 @@ GenerateConstructorCode(io::Printer* printer) const {
}
void RepeatedStringFieldGenerator::
+GenerateCopyConstructorCode(io::Printer* printer) const {
+ printer->Print(variables_, "$name$_.CopyFrom(from.$name$_);");
+}
+
+void RepeatedStringFieldGenerator::
GenerateMergeFromCodedStream(io::Printer* printer) const {
printer->Print(variables_,
"DO_(::google::protobuf::internal::WireFormatLite::Read$declared_type$(\n"
@@ -824,7 +969,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) const {
void RepeatedStringFieldGenerator::
GenerateSerializeWithCachedSizes(io::Printer* printer) const {
printer->Print(variables_,
- "for (int i = 0; i < this->$name$_size(); i++) {\n");
+ "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n");
printer->Indent();
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
@@ -841,7 +986,7 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) const {
void RepeatedStringFieldGenerator::
GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const {
printer->Print(variables_,
- "for (int i = 0; i < this->$name$_size(); i++) {\n");
+ "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n");
printer->Indent();
if (descriptor_->type() == FieldDescriptor::TYPE_STRING) {
GenerateUtf8CheckCodeForString(
@@ -858,8 +1003,9 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const {
void RepeatedStringFieldGenerator::
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"
+ "total_size += $tag_size$ *\n"
+ " ::google::protobuf::internal::FromIntSize(this->$name$_size());\n"
+ "for (int i = 0, n = this->$name$_size(); i < n; i++) {\n"
" total_size += ::google::protobuf::internal::WireFormatLite::$declared_type$Size(\n"
" this->$name$(i));\n"
"}\n");
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_string_field.h b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_string_field.h
index cb4e8772d0..af263c1a5b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_string_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_string_field.h
@@ -58,9 +58,11 @@ class StringFieldGenerator : public FieldGenerator {
bool is_inline) const;
void GenerateNonInlineAccessorDefinitions(io::Printer* printer) const;
void GenerateClearingCode(io::Printer* printer) const;
+ void GenerateMessageClearingCode(io::Printer* printer) const;
void GenerateMergingCode(io::Printer* printer) const;
void GenerateSwappingCode(io::Printer* printer) const;
void GenerateConstructorCode(io::Printer* printer) const;
+ void GenerateCopyConstructorCode(io::Printer* printer) const;
void GenerateDestructorCode(io::Printer* printer) const;
void GenerateDefaultInstanceAllocator(io::Printer* printer) const;
void GenerateShutdownCode(io::Printer* printer) const;
@@ -71,7 +73,7 @@ class StringFieldGenerator : public FieldGenerator {
protected:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringFieldGenerator);
@@ -87,6 +89,10 @@ class StringOneofFieldGenerator : public StringFieldGenerator {
void GenerateInlineAccessorDefinitions(io::Printer* printer,
bool is_inline) const;
void GenerateClearingCode(io::Printer* printer) const;
+
+ // StringFieldGenerator, from which we inherit, overrides this so we need to
+ // override it as well.
+ void GenerateMessageClearingCode(io::Printer* printer) const;
void GenerateSwappingCode(io::Printer* printer) const;
void GenerateConstructorCode(io::Printer* printer) const;
void GenerateDestructorCode(io::Printer* printer) const;
@@ -112,6 +118,7 @@ class RepeatedStringFieldGenerator : public FieldGenerator {
void GenerateMergingCode(io::Printer* printer) const;
void GenerateSwappingCode(io::Printer* printer) const;
void GenerateConstructorCode(io::Printer* printer) const;
+ void GenerateCopyConstructorCode(io::Printer* printer) const;
void GenerateMergeFromCodedStream(io::Printer* printer) const;
void GenerateSerializeWithCachedSizes(io::Printer* printer) const;
void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const;
@@ -119,7 +126,7 @@ class RepeatedStringFieldGenerator : public FieldGenerator {
private:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedStringFieldGenerator);
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto
index 4e25b2ea8f..4e25b2ea8f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto
index cb6ca1b151..cb6ca1b151 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_unittest.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_unittest.cc
index 5d82946d61..6d68ec35a9 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_unittest.cc
@@ -53,6 +53,7 @@
#include <vector>
#include <google/protobuf/unittest.pb.h>
+#include <google/protobuf/unittest_no_arena.pb.h>
#include <google/protobuf/unittest_optimize_for.pb.h>
#include <google/protobuf/unittest_embed_optimize_for.pb.h>
#if !defined(GOOGLE_PROTOBUF_CMAKE_BUILD) && !defined(_MSC_VER)
@@ -67,6 +68,7 @@
#include <google/protobuf/compiler/importer.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
+#include <google/protobuf/arena.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/dynamic_message.h>
@@ -129,12 +131,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)
@@ -199,14 +201,14 @@ TEST(GeneratedMessageTest, FloatingPointDefaults) {
EXPECT_EQ(-1.5f, extreme_default.negative_float());
EXPECT_EQ(2.0e8f, extreme_default.large_float());
EXPECT_EQ(-8e-28f, extreme_default.small_negative_float());
- EXPECT_EQ(numeric_limits<double>::infinity(),
+ EXPECT_EQ(std::numeric_limits<double>::infinity(),
extreme_default.inf_double());
- EXPECT_EQ(-numeric_limits<double>::infinity(),
+ EXPECT_EQ(-std::numeric_limits<double>::infinity(),
extreme_default.neg_inf_double());
EXPECT_TRUE(extreme_default.nan_double() != extreme_default.nan_double());
- EXPECT_EQ(numeric_limits<float>::infinity(),
+ EXPECT_EQ(std::numeric_limits<float>::infinity(),
extreme_default.inf_float());
- EXPECT_EQ(-numeric_limits<float>::infinity(),
+ EXPECT_EQ(-std::numeric_limits<float>::infinity(),
extreme_default.neg_inf_float());
EXPECT_TRUE(extreme_default.nan_float() != extreme_default.nan_float());
}
@@ -419,6 +421,71 @@ TEST(GeneratedMessageTest, StringCharStarLength) {
EXPECT_EQ("wx", message.repeated_string(0));
}
+#if LANG_CXX11
+TEST(GeneratedMessageTest, StringMove) {
+ // Verify that we trigger the move behavior on a scalar setter.
+ protobuf_unittest_no_arena::TestAllTypes message;
+ {
+ string tmp(32, 'a');
+
+ const char* old_data = tmp.data();
+ message.set_optional_string(std::move(tmp));
+ const char* new_data = message.optional_string().data();
+
+ EXPECT_EQ(old_data, new_data);
+ EXPECT_EQ(string(32, 'a'), message.optional_string());
+
+ string tmp2(32, 'b');
+ old_data = tmp2.data();
+ message.set_optional_string(std::move(tmp2));
+ new_data = message.optional_string().data();
+
+ EXPECT_EQ(old_data, new_data);
+ EXPECT_EQ(string(32, 'b'), message.optional_string());
+ }
+
+ // Verify that we trigger the move behavior on a oneof setter.
+ {
+ string tmp(32, 'a');
+
+ const char* old_data = tmp.data();
+ message.set_oneof_string(std::move(tmp));
+ const char* new_data = message.oneof_string().data();
+
+ EXPECT_EQ(old_data, new_data);
+ EXPECT_EQ(string(32, 'a'), message.oneof_string());
+
+ string tmp2(32, 'b');
+ old_data = tmp2.data();
+ message.set_oneof_string(std::move(tmp2));
+ new_data = message.oneof_string().data();
+
+ EXPECT_EQ(old_data, new_data);
+ EXPECT_EQ(string(32, 'b'), message.oneof_string());
+ }
+
+ // Verify that we trigger the move behavior on a repeated setter.
+ {
+ string tmp(32, 'a');
+
+ const char* old_data = tmp.data();
+ message.add_repeated_string(std::move(tmp));
+ const char* new_data = message.repeated_string(0).data();
+
+ EXPECT_EQ(old_data, new_data);
+ EXPECT_EQ(string(32, 'a'), message.repeated_string(0));
+
+ string tmp2(32, 'b');
+ old_data = tmp2.data();
+ message.set_repeated_string(0, std::move(tmp2));
+ new_data = message.repeated_string(0).data();
+
+ EXPECT_EQ(old_data, new_data);
+ EXPECT_EQ(string(32, 'b'), message.repeated_string(0));
+ }
+}
+#endif
+
TEST(GeneratedMessageTest, CopyFrom) {
unittest::TestAllTypes message1, message2;
@@ -518,6 +585,26 @@ TEST(GeneratedMessageTest, CopyConstructor) {
TestUtil::ExpectAllFieldsSet(message2);
}
+TEST(GeneratedMessageTest, CopyConstructorWithArenas) {
+ Arena arena;
+ unittest::TestAllTypes* message1 =
+ Arena::CreateMessage<unittest::TestAllTypes>(&arena);
+ TestUtil::SetAllFields(message1);
+
+ unittest::TestAllTypes message2_stack(*message1);
+ TestUtil::ExpectAllFieldsSet(message2_stack);
+
+ google::protobuf::scoped_ptr<unittest::TestAllTypes> message2_heap(
+ new unittest::TestAllTypes(*message1));
+ TestUtil::ExpectAllFieldsSet(*message2_heap);
+
+ arena.Reset();
+
+ // Verify that the copies are still intact.
+ TestUtil::ExpectAllFieldsSet(message2_stack);
+ TestUtil::ExpectAllFieldsSet(*message2_heap);
+}
+
TEST(GeneratedMessageTest, CopyAssignmentOperator) {
unittest::TestAllTypes message1;
TestUtil::SetAllFields(&message1);
@@ -600,14 +687,16 @@ TEST(GeneratedMessageTest, NonEmptyMergeFrom) {
#if !defined(PROTOBUF_TEST_NO_DESCRIPTORS) || \
!defined(GOOGLE_PROTOBUF_NO_RTTI)
#ifdef PROTOBUF_HAS_DEATH_TEST
+#ifndef NDEBUG
TEST(GeneratedMessageTest, MergeFromSelf) {
unittest::TestAllTypes message;
- EXPECT_DEATH(message.MergeFrom(message), "Check failed:.*pb[.]cc");
+ EXPECT_DEATH(message.MergeFrom(message), "pb[.]cc.*Check failed:");
EXPECT_DEATH(message.MergeFrom(implicit_cast<const Message&>(message)),
- "Check failed:.*pb[.]cc");
+ "pb[.]cc.*Check failed:");
}
+#endif // NDEBUG
#endif // PROTOBUF_HAS_DEATH_TEST
#endif // !PROTOBUF_TEST_NO_DESCRIPTORS || !GOOGLE_PROTOBUF_NO_RTTI
@@ -1252,7 +1341,7 @@ class GeneratedServiceTest : public testing::Test {
foo_(descriptor_->FindMethodByName("Foo")),
bar_(descriptor_->FindMethodByName("Bar")),
stub_(&mock_channel_),
- done_(::google::protobuf::internal::NewPermanentCallback(&DoNothing)) {}
+ done_(NewPermanentCallback(&DoNothing)) {}
virtual void SetUp() {
ASSERT_TRUE(foo_ != NULL);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_unittest.h b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_unittest.h
index 69c8f44c1d..69c8f44c1d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/cpp_unittest.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/cpp_unittest.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/metadata_test.cc b/third_party/protobuf/src/google/protobuf/compiler/cpp/metadata_test.cc
index edd30780a9..03f6b12b4a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/cpp/metadata_test.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/cpp/metadata_test.cc
@@ -156,7 +156,7 @@ const char kSmallTestFile[] =
// couldn't).
const GeneratedCodeInfo::Annotation* FindAnnotationOnPath(
const GeneratedCodeInfo& info, const string& source_file,
- const vector<int>& path) {
+ const std::vector<int>& path) {
for (int i = 0; i < info.annotation_size(); ++i) {
const GeneratedCodeInfo::Annotation* annotation = &info.annotation(i);
if (annotation->source_file() != source_file ||
@@ -197,7 +197,7 @@ TEST_F(CppMetadataTest, CapturesEnumNames) {
EXPECT_TRUE(
CaptureMetadata("test.proto", &file, &pb_h, &info, NULL, NULL, NULL));
EXPECT_EQ("Enum", file.enum_type(0).name());
- vector<int> enum_path;
+ std::vector<int> enum_path;
enum_path.push_back(FileDescriptorProto::kEnumTypeFieldNumber);
enum_path.push_back(0);
const GeneratedCodeInfo::Annotation* enum_annotation =
@@ -226,7 +226,7 @@ TEST_F(CppMetadataTest, CapturesMessageNames) {
EXPECT_TRUE(
CaptureMetadata("test.proto", &file, &pb_h, &info, NULL, NULL, NULL));
EXPECT_EQ("Message", file.message_type(0).name());
- vector<int> message_path;
+ std::vector<int> message_path;
message_path.push_back(FileDescriptorProto::kMessageTypeFieldNumber);
message_path.push_back(0);
const GeneratedCodeInfo::Annotation* message_annotation =
diff --git a/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc
new file mode 100644
index 0000000000..4e44b578e8
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc
@@ -0,0 +1,197 @@
+// 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.
+
+// This test insures that
+// csharp/src/Google.Protobuf/Reflection/Descriptor.cs match exactly
+// what would be generated by the protocol compiler. The file is not
+// generated automatically at build time.
+//
+// If this test fails, run the script
+// "generate_descriptor_proto.sh" and add the changed files under
+// csharp/src/ to your changelist.
+
+#include <map>
+
+#include <google/protobuf/compiler/csharp/csharp_generator.h>
+#include <google/protobuf/compiler/importer.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/io/zero_copy_stream_impl.h>
+#include <google/protobuf/stubs/map_util.h>
+#include <google/protobuf/stubs/stl_util.h>
+#include <google/protobuf/stubs/strutil.h>
+#include <google/protobuf/stubs/substitute.h>
+
+#include <google/protobuf/testing/file.h>
+#include <google/protobuf/testing/file.h>
+#include <google/protobuf/testing/googletest.h>
+#include <gtest/gtest.h>
+
+namespace google {
+namespace protobuf {
+namespace compiler {
+namespace csharp {
+
+namespace {
+
+class MockErrorCollector : public MultiFileErrorCollector {
+ public:
+ MockErrorCollector() {}
+ ~MockErrorCollector() {}
+
+ string text_;
+
+ // implements ErrorCollector ---------------------------------------
+ void AddError(const string& filename, int line, int column,
+ const string& message) {
+ strings::SubstituteAndAppend(&text_, "$0:$1:$2: $3\n",
+ filename, line, column, message);
+ }
+};
+
+class MockGeneratorContext : public GeneratorContext {
+ public:
+ MockGeneratorContext() {}
+ ~MockGeneratorContext() {
+ STLDeleteValues(&files_);
+ }
+
+ void ExpectFileMatches(const string& virtual_filename,
+ const string& physical_filename) {
+ string* expected_contents = FindPtrOrNull(files_, virtual_filename);
+ ASSERT_TRUE(expected_contents != NULL)
+ << "Generator failed to generate file: " << virtual_filename;
+
+ string actual_contents;
+ GOOGLE_CHECK_OK(
+ File::GetContents(TestSourceDir() + "/" + physical_filename,
+ &actual_contents, true))
+ << "Unable to get " << physical_filename;
+ EXPECT_TRUE(actual_contents == *expected_contents)
+ << physical_filename << " needs to be regenerated. Please run "
+ "generate_descriptor_proto.sh. Then add this file "
+ "to your CL.";
+ }
+
+ // implements GeneratorContext --------------------------------------
+
+ virtual io::ZeroCopyOutputStream* Open(const string& filename) {
+ string** map_slot = &files_[filename];
+ delete *map_slot;
+ *map_slot = new string;
+
+ return new io::StringOutputStream(*map_slot);
+ }
+
+ private:
+ std::map<string, string*> files_;
+};
+
+class GenerateAndTest {
+ public:
+ GenerateAndTest() {}
+ void Run(const FileDescriptor* proto_file, string file1, string file2) {
+ ASSERT_TRUE(proto_file != NULL) << TestSourceDir();
+ ASSERT_TRUE(generator_.Generate(proto_file, parameter_,
+ &context_, &error_));
+ context_.ExpectFileMatches(file1, file2);
+ }
+ void SetParameter(string parameter) {
+ parameter_ = parameter;
+ }
+
+ private:
+ Generator generator_;
+ MockGeneratorContext context_;
+ string error_;
+ string parameter_;
+};
+
+TEST(CsharpBootstrapTest, GeneratedCsharpDescriptorMatches) {
+ MockErrorCollector error_collector;
+ DiskSourceTree source_tree;
+ Importer importer(&source_tree, &error_collector);
+ GenerateAndTest generate_test;
+
+ generate_test.SetParameter("base_namespace=Google.Protobuf");
+ source_tree.MapPath("", TestSourceDir());
+ generate_test.Run(importer.Import("google/protobuf/descriptor.proto"),
+ "Reflection/Descriptor.cs",
+ "../csharp/src/Google.Protobuf/Reflection/Descriptor.cs");
+ generate_test.Run(importer.Import("google/protobuf/any.proto"),
+ "WellKnownTypes/Any.cs",
+ "../csharp/src/Google.Protobuf/WellKnownTypes/Any.cs");
+ generate_test.Run(importer.Import("google/protobuf/api.proto"),
+ "WellKnownTypes/Api.cs",
+ "../csharp/src/Google.Protobuf/WellKnownTypes/Api.cs");
+ generate_test.Run(importer.Import("google/protobuf/duration.proto"),
+ "WellKnownTypes/Duration.cs",
+ "../csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs");
+ generate_test.Run(importer.Import("google/protobuf/empty.proto"),
+ "WellKnownTypes/Empty.cs",
+ "../csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs");
+ generate_test.Run(importer.Import("google/protobuf/field_mask.proto"),
+ "WellKnownTypes/FieldMask.cs",
+ "../csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs");
+ generate_test.Run(importer.Import("google/protobuf/source_context.proto"),
+ "WellKnownTypes/SourceContext.cs",
+ "../csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs");
+ generate_test.Run(importer.Import("google/protobuf/struct.proto"),
+ "WellKnownTypes/Struct.cs",
+ "../csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs");
+ generate_test.Run(importer.Import("google/protobuf/timestamp.proto"),
+ "WellKnownTypes/Timestamp.cs",
+ "../csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs");
+ generate_test.Run(importer.Import("google/protobuf/type.proto"),
+ "WellKnownTypes/Type.cs",
+ "../csharp/src/Google.Protobuf/WellKnownTypes/Type.cs");
+ generate_test.Run(importer.Import("google/protobuf/wrappers.proto"),
+ "WellKnownTypes/Wrappers.cs",
+ "../csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs");
+
+ generate_test.SetParameter("");
+ source_tree.MapPath("", TestSourceDir() + "/../examples");
+ generate_test.Run(importer.Import("addressbook.proto"),
+ "Addressbook.cs",
+ "../csharp/src/AddressBook/Addressbook.cs");
+
+ source_tree.MapPath("", TestSourceDir() + "/../conformance");
+ generate_test.Run(importer.Import("conformance.proto"),
+ "Conformance.cs",
+ "../csharp/src/Google.Protobuf.Conformance/Conformance.cs");
+
+ EXPECT_EQ("", error_collector.text_);
+}
+
+} // namespace
+
+} // namespace csharp
+} // namespace compiler
+} // namespace protobuf
+} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc
index 587e022286..636a76a0b9 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_doc_comment.cc
@@ -74,7 +74,7 @@ void WriteDocCommentBodyImpl(io::Printer* printer, SourceLocation location) {
printer->Print("///\n");
}
last_was_empty = false;
- printer->Print("/// $line$\n", "line", *it);
+ printer->Print("///$line$\n", "line", *it);
}
}
printer->Print("/// </summary>\n");
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_doc_comment.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_doc_comment.h
index 75eb0ea04d..75eb0ea04d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_doc_comment.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_doc_comment.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_enum.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_enum.cc
index 64381d0faa..9759e3ef26 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_enum.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_enum.cc
@@ -65,12 +65,11 @@ void EnumGenerator::Generate(io::Printer* printer) {
"name", descriptor_->name());
printer->Indent();
std::set<string> used_names;
+ std::set<int> used_number;
for (int i = 0; i < descriptor_->value_count(); i++) {
WriteEnumValueDocComment(printer, descriptor_->value(i));
string original_name = descriptor_->value(i)->name();
- string name = options()->legacy_enum_values
- ? descriptor_->value(i)->name()
- : GetEnumValueName(descriptor_->name(), descriptor_->value(i)->name());
+ string name = GetEnumValueName(descriptor_->name(), descriptor_->value(i)->name());
// Make sure we don't get any duplicate names due to prefix removal.
while (!used_names.insert(name).second) {
// It's possible we'll end up giving this warning multiple times, but that's better than not at all.
@@ -78,10 +77,18 @@ void EnumGenerator::Generate(io::Printer* printer) {
<< ") in " << descriptor_->name() << "; adding underscore to distinguish";
name += "_";
}
- printer->Print("[pbr::OriginalName(\"$original_name$\")] $name$ = $number$,\n",
- "original_name", original_name,
- "name", name,
- "number", SimpleItoa(descriptor_->value(i)->number()));
+ int number = descriptor_->value(i)->number();
+ if (!used_number.insert(number).second) {
+ printer->Print("[pbr::OriginalName(\"$original_name$\", PreferredAlias = false)] $name$ = $number$,\n",
+ "original_name", original_name,
+ "name", name,
+ "number", SimpleItoa(number));
+ } else {
+ printer->Print("[pbr::OriginalName(\"$original_name$\")] $name$ = $number$,\n",
+ "original_name", original_name,
+ "name", name,
+ "number", SimpleItoa(number));
+ }
}
printer->Outdent();
printer->Print("}\n");
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_enum.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_enum.h
index 8925cdf2be..8925cdf2be 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_enum.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_enum.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_enum_field.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_enum_field.cc
index 67c0b5961a..67c0b5961a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_enum_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_enum_field.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_enum_field.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_enum_field.h
index 9b7669ba5d..9b7669ba5d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_enum_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_enum_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_field_base.cc
index e2011b76ca..139cc75366 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_field_base.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_field_base.cc
@@ -122,8 +122,10 @@ void FieldGeneratorBase::GenerateCodecCode(io::Printer* printer) {
}
void FieldGeneratorBase::AddDeprecatedFlag(io::Printer* printer) {
- if (descriptor_->options().deprecated())
- {
+ if (descriptor_->options().deprecated()) {
+ printer->Print("[global::System.ObsoleteAttribute]\n");
+ } else if (descriptor_->type() == FieldDescriptor::TYPE_MESSAGE &&
+ descriptor_->message_type()->options().deprecated()) {
printer->Print("[global::System.ObsoleteAttribute]\n");
}
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_field_base.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_field_base.h
index 4109f3caa0..4109f3caa0 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_field_base.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_field_base.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_generator.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_generator.cc
index d74e8c8847..c13ed65bec 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_generator.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_generator.cc
@@ -83,9 +83,6 @@ bool Generator::Generate(
cli_options.base_namespace_specified = true;
} else if (options[i].first == "internal_access") {
cli_options.internal_access = true;
- } else if (options[i].first == "legacy_enum_values") {
- // TODO: Remove this before final release
- cli_options.legacy_enum_values = true;
} else {
*error = "Unknown generator option: " + options[i].first;
return false;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_generator.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_generator.h
index 9b54e9149e..c8b1952913 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_generator.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_generator.h
@@ -28,6 +28,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// Generates C# code for a given .proto file.
+
#ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_GENERATOR_H__
#define GOOGLE_PROTOBUF_COMPILER_CSHARP_GENERATOR_H__
@@ -40,8 +42,13 @@ namespace protobuf {
namespace compiler {
namespace csharp {
+// CodeGenerator implementation which generates a C# source file and
+// header. If you create your own protocol compiler binary and you want
+// it to support C# output, you can do so by registering an instance of this
+// CodeGenerator with the CommandLineInterface in your main() function.
class LIBPROTOC_EXPORT Generator
: public google::protobuf::compiler::CodeGenerator {
+public:
virtual bool Generate(
const FileDescriptor* file,
const string& parameter,
@@ -55,4 +62,3 @@ class LIBPROTOC_EXPORT Generator
} // namespace google
#endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_GENERATOR_H__
-
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc
index 5755fee00b..5755fee00b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_helpers.cc
index 6c154c5a58..5bca1ffa72 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_helpers.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_helpers.cc
@@ -38,6 +38,7 @@
#include <vector>
#include <google/protobuf/compiler/csharp/csharp_helpers.h>
+#include <google/protobuf/compiler/csharp/csharp_names.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/wire_format.h>
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_helpers.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_helpers.h
index 1563ca7e1d..c317ad0e55 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_helpers.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_helpers.h
@@ -120,6 +120,22 @@ inline bool IsDescriptorProto(const FileDescriptor* descriptor) {
return descriptor->name() == "google/protobuf/descriptor.proto";
}
+// Determines whether the given message is an options message within descriptor.proto.
+inline bool IsDescriptorOptionMessage(const Descriptor* descriptor) {
+ if (!IsDescriptorProto(descriptor->file())) {
+ return false;
+ }
+ const string name = descriptor->full_name();
+ return name == "google.protobuf.FileOptions" ||
+ name == "google.protobuf.MessageOptions" ||
+ name == "google.protobuf.FieldOptions" ||
+ name == "google.protobuf.OneofOptions" ||
+ name == "google.protobuf.EnumOptions" ||
+ name == "google.protobuf.EnumValueOptions" ||
+ name == "google.protobuf.ServiceOptions" ||
+ name == "google.protobuf.MethodOptions";
+}
+
inline bool IsWrapperType(const FieldDescriptor* descriptor) {
return descriptor->type() == FieldDescriptor::TYPE_MESSAGE &&
descriptor->message_type()->file()->name() == "google/protobuf/wrappers.proto";
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_map_field.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_map_field.cc
index e6eac6edb2..e6eac6edb2 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_map_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_map_field.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_map_field.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_map_field.h
index 84a33a0367..84a33a0367 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_map_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_map_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_message.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_message.cc
index ed7448545f..0f00a43858 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_message.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_message.cc
@@ -98,12 +98,20 @@ const std::vector<const FieldDescriptor*>& MessageGenerator::fields_by_number()
return fields_by_number_;
}
+void MessageGenerator::AddDeprecatedFlag(io::Printer* printer) {
+ if (descriptor_->options().deprecated()) {
+ printer->Print("[global::System.ObsoleteAttribute]\n");
+ }
+}
+
void MessageGenerator::Generate(io::Printer* printer) {
map<string, string> vars;
vars["class_name"] = class_name();
vars["access_level"] = class_access_level();
WriteMessageDocComment(printer, descriptor_);
+ AddDeprecatedFlag(printer);
+
printer->Print(
vars,
"$access_level$ sealed partial class $class_name$ : pb::IMessage<$class_name$> {\n");
@@ -115,6 +123,7 @@ void MessageGenerator::Generate(io::Printer* printer) {
"private static readonly pb::MessageParser<$class_name$> _parser = new pb::MessageParser<$class_name$>(() => new $class_name$());\n");
WriteGeneratedCodeAttributes(printer);
+
printer->Print(
vars,
"public static pb::MessageParser<$class_name$> Parser { get { return _parser; } }\n\n");
@@ -142,6 +151,12 @@ void MessageGenerator::Generate(io::Printer* printer) {
" get { return Descriptor; }\n"
"}\n"
"\n");
+ // CustomOptions property, only for options messages
+ if (IsDescriptorOptionMessage(descriptor_)) {
+ printer->Print(
+ "internal CustomOptions CustomOptions{ get; private set; } = CustomOptions.Empty;\n"
+ "\n");
+ }
// Parameterless constructor and partial OnConstruction method.
WriteGeneratedCodeAttributes(printer);
@@ -466,10 +481,18 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) {
" switch(tag) {\n");
printer->Indent();
printer->Indent();
- printer->Print(
- "default:\n"
- " input.SkipLastField();\n" // We're not storing the data, but we still need to consume it.
- " break;\n");
+ // Option messages need to store unknown fields so that options can be parsed later.
+ if (IsDescriptorOptionMessage(descriptor_)) {
+ printer->Print(
+ "default:\n"
+ " CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);\n"
+ " break;\n");
+ } else {
+ printer->Print(
+ "default:\n"
+ " input.SkipLastField();\n" // We're not storing the data, but we still need to consume it.
+ " break;\n");
+ }
for (int i = 0; i < fields_by_number().size(); i++) {
const FieldDescriptor* field = fields_by_number()[i];
internal::WireFormatLite::WireType wt =
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_message.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_message.h
index f794d68dfd..e7f3b4d009 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_message.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_message.h
@@ -69,6 +69,8 @@ class MessageGenerator : public SourceGeneratorBase {
bool HasNestedGeneratedTypes();
+ void AddDeprecatedFlag(io::Printer* printer);
+
std::string class_name();
std::string full_class_name();
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_message_field.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_message_field.cc
index 438f310221..438f310221 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_message_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_message_field.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_message_field.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_message_field.h
index 7d614756fa..7d614756fa 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_message_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_message_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_names.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_names.h
index 308051871c..21758f2882 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_names.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_names.h
@@ -39,6 +39,7 @@
#define GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__
#include <string>
+#include <google/protobuf/stubs/port.h>
namespace google {
namespace protobuf {
@@ -56,14 +57,14 @@ namespace csharp {
//
// Returns:
// The namespace to use for given file descriptor.
-string GetFileNamespace(const FileDescriptor* descriptor);
+string LIBPROTOC_EXPORT GetFileNamespace(const FileDescriptor* descriptor);
// Requires:
// descriptor != NULL
//
// Returns:
// The fully-qualified C# class name.
-string GetClassName(const Descriptor* descriptor);
+string LIBPROTOC_EXPORT GetClassName(const Descriptor* descriptor);
// Requires:
// descriptor != NULL
@@ -72,7 +73,7 @@ string GetClassName(const Descriptor* descriptor);
// The fully-qualified name of the C# class that provides
// access to the file descriptor. Proto compiler generates
// such class for each .proto file processed.
-string GetReflectionClassName(const FileDescriptor* descriptor);
+string LIBPROTOC_EXPORT GetReflectionClassName(const FileDescriptor* descriptor);
// Generates output file name for given file descriptor. If generate_directories
// is true, the output file will be put under directory corresponding to file's
@@ -88,7 +89,7 @@ string GetReflectionClassName(const FileDescriptor* descriptor);
// The file name to use as output file for given file descriptor. In case
// of failure, this function will return empty string and error parameter
// will contain the error message.
-string GetOutputFile(
+string LIBPROTOC_EXPORT GetOutputFile(
const google::protobuf::FileDescriptor* descriptor,
const string file_extension,
const bool generate_directories,
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_options.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_options.h
index 4079bf7f32..426fb3b50f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_options.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_options.h
@@ -45,8 +45,7 @@ struct Options {
file_extension(".cs"),
base_namespace(""),
base_namespace_specified(false),
- internal_access(false),
- legacy_enum_values(false) {
+ internal_access(false) {
}
// Extension of the generated file. Defaults to ".cs"
string file_extension;
@@ -69,12 +68,6 @@ struct Options {
// Whether the generated classes should have accessibility level of "internal".
// Defaults to false that generates "public" classes.
bool internal_access;
- // By default, C# codegen now uses PascalCased enum values names, after
- // removing the enum type name as a prefix (if it *is* a prefix of the value).
- // Setting this option reverts to the previous behavior of just copying the
- // value name specified in the .proto file, allowing gradual migration.
- // This option will be removed before final release.
- bool legacy_enum_values;
};
} // namespace csharp
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
index 169122e6be..169122e6be 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_primitive_field.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_primitive_field.h
index 5f466fc47c..5f466fc47c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_primitive_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_primitive_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc
index bac9aef7b8..bac9aef7b8 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_reflection_class.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_reflection_class.h
index e0c69f31fb..e0c69f31fb 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_reflection_class.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_reflection_class.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
index 683c4b0b7a..683c4b0b7a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h
index 819b583262..819b583262 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
index 8fa0b0504f..8fa0b0504f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h
index 6e33648b6c..6e33648b6c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc
index cd91506ff1..cd91506ff1 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h
index a59348a95f..a59348a95f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc
index 1fda7ddf31..1fda7ddf31 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_source_generator_base.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_source_generator_base.h
index c741080ed8..c741080ed8 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_source_generator_base.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_source_generator_base.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc
index 797d498ed3..797d498ed3 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h
index 250dfd2548..250dfd2548 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/importer.cc b/third_party/protobuf/src/google/protobuf/compiler/importer.cc
index 1182a6ba4c..bb168d5241 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/importer.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/importer.cc
@@ -49,9 +49,9 @@
#include <google/protobuf/compiler/importer.h>
#include <google/protobuf/compiler/parser.h>
-#include <google/protobuf/io/io_win32.h>
#include <google/protobuf/io/tokenizer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
+#include <google/protobuf/stubs/io_win32.h>
#include <google/protobuf/stubs/strutil.h>
namespace google {
@@ -266,8 +266,8 @@ static string CanonicalizePath(string path) {
}
#endif
- vector<string> canonical_parts;
- vector<string> parts = Split(
+ std::vector<string> canonical_parts;
+ std::vector<string> parts = Split(
path, "/", true); // Note: Removes empty parts.
for (int i = 0; i < parts.size(); i++) {
if (parts[i] == ".") {
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/importer.h b/third_party/protobuf/src/google/protobuf/compiler/importer.h
index cc8fcc39b0..759636e164 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/importer.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/importer.h
@@ -305,7 +305,7 @@ class LIBPROTOBUF_EXPORT DiskSourceTree : public SourceTree {
const string& disk_path_param)
: virtual_path(virtual_path_param), disk_path(disk_path_param) {}
};
- vector<Mapping> mappings_;
+ std::vector<Mapping> mappings_;
string last_error_message_;
// Like Open(), but returns the on-disk path in disk_file if disk_file is
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/importer_unittest.cc b/third_party/protobuf/src/google/protobuf/compiler/importer_unittest.cc
index 1b6e970071..00285bcc63 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/importer_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/importer_unittest.cc
@@ -293,7 +293,7 @@ class DiskSourceTreeTest : public testing::Test {
DiskSourceTree source_tree_;
// Paths of two on-disk directories to use during the test.
- vector<string> dirnames_;
+ std::vector<string> dirnames_;
};
TEST_F(DiskSourceTreeTest, MapRoot) {
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_context.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_context.cc
index 6cfa14a012..b82fb3dd42 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_context.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_context.cc
@@ -108,7 +108,7 @@ void Context::InitializeFieldGeneratorInfoForMessage(
for (int i = 0; i < message->nested_type_count(); ++i) {
InitializeFieldGeneratorInfoForMessage(message->nested_type(i));
}
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
for (int i = 0; i < message->field_count(); ++i) {
fields.push_back(message->field(i));
}
@@ -124,11 +124,11 @@ void Context::InitializeFieldGeneratorInfoForMessage(
}
void Context::InitializeFieldGeneratorInfoForFields(
- const vector<const FieldDescriptor*>& fields) {
+ const std::vector<const FieldDescriptor*>& fields) {
// Find out all fields that conflict with some other field in the same
// message.
- vector<bool> is_conflict(fields.size());
- vector<string> conflict_reason(fields.size());
+ std::vector<bool> is_conflict(fields.size());
+ std::vector<string> conflict_reason(fields.size());
for (int i = 0; i < fields.size(); ++i) {
const FieldDescriptor* field = fields[i];
const string& name = UnderscoresToCapitalizedCamelCase(field);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_context.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_context.h
index f92ae87ea7..b22e7e3a24 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_context.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_context.h
@@ -95,11 +95,13 @@ class Context {
void InitializeFieldGeneratorInfo(const FileDescriptor* file);
void InitializeFieldGeneratorInfoForMessage(const Descriptor* message);
void InitializeFieldGeneratorInfoForFields(
- const vector<const FieldDescriptor*>& fields);
+ const std::vector<const FieldDescriptor*>& fields);
google::protobuf::scoped_ptr<ClassNameResolver> name_resolver_;
- map<const FieldDescriptor*, FieldGeneratorInfo> field_generator_info_map_;
- map<const OneofDescriptor*, OneofGeneratorInfo> oneof_generator_info_map_;
+ std::map<const FieldDescriptor*, FieldGeneratorInfo>
+ field_generator_info_map_;
+ std::map<const OneofDescriptor*, OneofGeneratorInfo>
+ oneof_generator_info_map_;
Options options_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Context);
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_doc_comment.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_doc_comment.cc
index 0b5caba434..59c04ad412 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_doc_comment.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_doc_comment.cc
@@ -115,7 +115,7 @@ static void WriteDocCommentBodyForLocation(
// HTML-escape them so that they don't accidentally close the doc comment.
comments = EscapeJavadoc(comments);
- vector<string> lines = Split(comments, "\n");
+ std::vector<string> lines = Split(comments, "\n");
while (!lines.empty() && lines.back().empty()) {
lines.pop_back();
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_doc_comment.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_doc_comment.h
index 7d9535c959..7d9535c959 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_doc_comment.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_doc_comment.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc
index ae582ea649..ae582ea649 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_enum.cc
index b46cfe9cc6..b9ee00ff42 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_enum.cc
@@ -49,17 +49,6 @@ namespace protobuf {
namespace compiler {
namespace java {
-namespace {
-bool EnumHasCustomOptions(const EnumDescriptor* descriptor) {
- if (descriptor->options().unknown_fields().field_count() > 0) return true;
- for (int i = 0; i < descriptor->value_count(); ++i) {
- const EnumValueDescriptor* value = descriptor->value(i);
- if (value->options().unknown_fields().field_count() > 0) return true;
- }
- return false;
-}
-} // namespace
-
EnumGenerator::EnumGenerator(const EnumDescriptor* descriptor,
bool immutable_api,
Context* context)
@@ -105,7 +94,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
}
for (int i = 0; i < canonical_values_.size(); i++) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars["name"] = canonical_values_[i]->name();
vars["index"] = SimpleItoa(canonical_values_[i]->index());
vars["number"] = SimpleItoa(canonical_values_[i]->number());
@@ -137,7 +126,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
// -----------------------------------------------------------------
for (int i = 0; i < aliases_.size(); i++) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars["classname"] = descriptor_->name();
vars["name"] = aliases_[i].value->name();
vars["canonical_name"] = aliases_[i].canonical_value->name();
@@ -147,7 +136,7 @@ void EnumGenerator::Generate(io::Printer* printer) {
}
for (int i = 0; i < descriptor_->value_count(); i++) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars["name"] = descriptor_->value(i)->name();
vars["number"] = SimpleItoa(descriptor_->value(i)->number());
WriteEnumValueDocComment(printer, descriptor_->value(i));
@@ -243,49 +232,14 @@ void EnumGenerator::Generate(io::Printer* printer) {
// at module init time because it wouldn't work with descriptor.proto, but
// we can cache the value the first time getDescriptor() is called.
if (descriptor_->containing_type() == NULL) {
- if (!MultipleJavaFiles(descriptor_->file(), immutable_api_)) {
- printer->Print(
- " return $file$.getDescriptor().getEnumTypes().get($index$);\n",
- "file", name_resolver_->GetClassName(descriptor_->file(),
- immutable_api_),
- "index", SimpleItoa(descriptor_->index()));
- } else {
- printer->Indent();
- if (EnumHasCustomOptions(descriptor_)) {
- // We need to load the immutable classes in order to parse custom
- // options. However, since file level enums (no outer class) are
- // shared by immutable code and mutable code, the immutable classes
- // may not exist. So we try to use Java reflection to retrieve the
- // descriptor from immutable classes.
- printer->Print(
- "try {\n"
- " java.lang.Class immutableFileClass =\n"
- " java.lang.Class.forName(\"$immutable_file_class_name$\");\n"
- " @java.lang.SuppressWarnings(\"unchecked\")\n"
- " java.lang.reflect.Method m =\n"
- " immutableFileClass.getMethod(\"getDescriptor\");\n"
- " com.google.protobuf.Descriptors.FileDescriptor file =\n"
- " (com.google.protobuf.Descriptors.FileDescriptor)\n"
- " m.invoke(immutableFileClass);\n"
- " return file.getEnumTypes().get($index$);\n"
- "} catch (java.lang.Exception e) {\n"
- // Immutable classes cannot be found. Proceed as if custom options
- // don't exist.
- "}\n",
- "immutable_file_class_name",
- name_resolver_->GetImmutableClassName(descriptor_->file()),
- "index", SimpleItoa(descriptor_->index()));
- }
- printer->Print(
- "return $immutable_package$.$descriptor_class$.$descriptor$\n"
- " .getEnumTypes().get($index$);\n",
- "immutable_package", FileJavaPackage(descriptor_->file(), true),
- "descriptor_class",
- name_resolver_->GetDescriptorClassName(descriptor_->file()),
- "descriptor", "getDescriptor()",
- "index", SimpleItoa(descriptor_->index()));
- printer->Outdent();
- }
+ // The class generated for the File fully populates the descriptor with
+ // extensions in both the mutable and immutable cases. (In the mutable api
+ // this is accomplished by attempting to load the immutable outer class).
+ printer->Print(
+ " return $file$.getDescriptor().getEnumTypes().get($index$);\n",
+ "file", name_resolver_->GetClassName(descriptor_->file(),
+ immutable_api_),
+ "index", SimpleItoa(descriptor_->index()));
} else {
printer->Print(
" return $parent$.$descriptor$.getEnumTypes().get($index$);\n",
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_enum.h
index c33e713df1..13dfc32d49 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_enum.h
@@ -72,13 +72,13 @@ class EnumGenerator {
// considered equivalent. We treat the first defined constant for any
// given numeric value as "canonical" and the rest as aliases of that
// canonical value.
- vector<const EnumValueDescriptor*> canonical_values_;
+ std::vector<const EnumValueDescriptor*> canonical_values_;
struct Alias {
const EnumValueDescriptor* value;
const EnumValueDescriptor* canonical_value;
};
- vector<Alias> aliases_;
+ std::vector<Alias> aliases_;
bool immutable_api_;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_field.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_enum_field.cc
index 2e916c5679..279b9da4ef 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_enum_field.cc
@@ -58,7 +58,7 @@ void SetEnumVariables(const FieldDescriptor* descriptor,
int builderBitIndex,
const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
- map<string, string>* variables) {
+ std::map<string, string>* variables) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] =
@@ -68,7 +68,8 @@ void SetEnumVariables(const FieldDescriptor* descriptor,
(*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
(*variables)["default_number"] = SimpleItoa(
descriptor->default_value_enum()->number());
- (*variables)["tag"] = SimpleItoa(internal::WireFormat::MakeTag(descriptor));
+ (*variables)["tag"] =
+ SimpleItoa(static_cast<int32>(internal::WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = SimpleItoa(
internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
// TODO(birdo): Add @deprecated javadoc when generating javadoc is supported
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_field.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_enum_field.h
index b8ff734373..924ff28149 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_enum_field.h
@@ -82,7 +82,7 @@ class ImmutableEnumFieldGenerator : public ImmutableFieldGenerator {
protected:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
@@ -143,7 +143,7 @@ class RepeatedImmutableEnumFieldGenerator : public ImmutableFieldGenerator {
private:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_field_lite.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_enum_field_lite.cc
index aa0eb5e829..50eed5da49 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_field_lite.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_enum_field_lite.cc
@@ -58,7 +58,7 @@ void SetEnumVariables(const FieldDescriptor* descriptor,
int builderBitIndex,
const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
- map<string, string>* variables) {
+ std::map<string, string>* variables) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] =
@@ -68,13 +68,15 @@ void SetEnumVariables(const FieldDescriptor* descriptor,
(*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
(*variables)["default_number"] = SimpleItoa(
descriptor->default_value_enum()->number());
- (*variables)["tag"] = SimpleItoa(internal::WireFormat::MakeTag(descriptor));
+ (*variables)["tag"] =
+ SimpleItoa(static_cast<int32>(internal::WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = SimpleItoa(
internal::WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
// TODO(birdo): Add @deprecated javadoc when generating javadoc is supported
// by the proto compiler
(*variables)["deprecation"] = descriptor->options().deprecated()
? "@java.lang.Deprecated " : "";
+ (*variables)["required"] = descriptor->is_required() ? "true" : "false";
if (SupportFieldPresence(descriptor->file())) {
// For singular messages and builders, one bit is used for the hasField bit.
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_field_lite.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_enum_field_lite.h
index 9201b8d66a..fa004720fd 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_field_lite.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_enum_field_lite.h
@@ -81,7 +81,7 @@ class ImmutableEnumFieldLiteGenerator : public ImmutableFieldLiteGenerator {
protected:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
@@ -142,7 +142,7 @@ class RepeatedImmutableEnumFieldLiteGenerator
private:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_lite.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_enum_lite.cc
index 99f52d4012..96815920a6 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_lite.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_enum_lite.cc
@@ -95,7 +95,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
printer->Indent();
for (int i = 0; i < canonical_values_.size(); i++) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars["name"] = canonical_values_[i]->name();
vars["number"] = SimpleItoa(canonical_values_[i]->number());
WriteEnumValueDocComment(printer, canonical_values_[i]);
@@ -117,7 +117,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
// -----------------------------------------------------------------
for (int i = 0; i < aliases_.size(); i++) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars["classname"] = descriptor_->name();
vars["name"] = aliases_[i].value->name();
vars["canonical_name"] = aliases_[i].canonical_value->name();
@@ -127,7 +127,7 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
}
for (int i = 0; i < descriptor_->value_count(); i++) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars["name"] = descriptor_->value(i)->name();
vars["number"] = SimpleItoa(descriptor_->value(i)->number());
WriteEnumValueDocComment(printer, descriptor_->value(i));
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_lite.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_enum_lite.h
index f27cb76fb1..b7be912cb9 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_enum_lite.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_enum_lite.h
@@ -72,13 +72,13 @@ class EnumLiteGenerator {
// considered equivalent. We treat the first defined constant for any
// given numeric value as "canonical" and the rest as aliases of that
// canonical value.
- vector<const EnumValueDescriptor*> canonical_values_;
+ std::vector<const EnumValueDescriptor*> canonical_values_;
struct Alias {
const EnumValueDescriptor* value;
const EnumValueDescriptor* canonical_value;
};
- vector<Alias> aliases_;
+ std::vector<Alias> aliases_;
bool immutable_api_;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_extension.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_extension.cc
index 46b5faaa50..cb237bf6d5 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_extension.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_extension.cc
@@ -61,12 +61,10 @@ ImmutableExtensionGenerator::ImmutableExtensionGenerator(
ImmutableExtensionGenerator::~ImmutableExtensionGenerator() {}
// Initializes the vars referenced in the generated code templates.
-void ExtensionGenerator::InitTemplateVars(const FieldDescriptor* descriptor,
- const string& scope,
- bool immutable,
- ClassNameResolver* name_resolver,
- map<string, string>* vars_pointer) {
- map<string, string> &vars = *vars_pointer;
+void ExtensionGenerator::InitTemplateVars(
+ const FieldDescriptor* descriptor, const string& scope, bool immutable,
+ ClassNameResolver* name_resolver, std::map<string, string>* vars_pointer) {
+ std::map<string, string> &vars = *vars_pointer;
vars["scope"] = scope;
vars["name"] = UnderscoresToCamelCase(descriptor);
vars["containing_type"] =
@@ -110,7 +108,7 @@ void ExtensionGenerator::InitTemplateVars(const FieldDescriptor* descriptor,
}
void ImmutableExtensionGenerator::Generate(io::Printer* printer) {
- map<string, string> vars;
+ std::map<string, string> vars;
const bool kUseImmutableNames = true;
InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_,
&vars);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_extension.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_extension.h
index bdd4226379..fb8d52015b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_extension.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_extension.h
@@ -79,7 +79,7 @@ class ExtensionGenerator {
const string& scope,
bool immutable,
ClassNameResolver* name_resolver,
- map<string, string>* vars_pointer);
+ std::map<string, string>* vars_pointer);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_extension_lite.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_extension_lite.cc
index 23261bac2f..c48c92e9fc 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_extension_lite.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_extension_lite.cc
@@ -57,7 +57,7 @@ ImmutableExtensionLiteGenerator::ImmutableExtensionLiteGenerator(
ImmutableExtensionLiteGenerator::~ImmutableExtensionLiteGenerator() {}
void ImmutableExtensionLiteGenerator::Generate(io::Printer* printer) {
- map<string, string> vars;
+ std::map<string, string> vars;
const bool kUseImmutableNames = true;
InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_,
&vars);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_extension_lite.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_extension_lite.h
index 4cd49bda20..4cd49bda20 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_extension_lite.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_extension_lite.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_field.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_field.cc
index 3c7bc5c467..04917296dc 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_field.cc
@@ -290,7 +290,7 @@ FieldGeneratorMap<ImmutableFieldLiteGenerator>::~FieldGeneratorMap() {}
void SetCommonFieldVariables(const FieldDescriptor* descriptor,
const FieldGeneratorInfo* info,
- map<string, string>* variables) {
+ std::map<string, string>* variables) {
(*variables)["field_name"] = descriptor->name();
(*variables)["name"] = info->name;
(*variables)["capitalized_name"] = info->capitalized_name;
@@ -301,7 +301,7 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
void SetCommonOneofVariables(const FieldDescriptor* descriptor,
const OneofGeneratorInfo* info,
- map<string, string>* variables) {
+ std::map<string, string>* variables) {
(*variables)["oneof_name"] = info->name;
(*variables)["oneof_capitalized_name"] = info->capitalized_name;
(*variables)["oneof_index"] =
@@ -314,9 +314,9 @@ void SetCommonOneofVariables(const FieldDescriptor* descriptor,
"Case_ == " + SimpleItoa(descriptor->number());
}
-void PrintExtraFieldInfo(const map<string, string>& variables,
+void PrintExtraFieldInfo(const std::map<string, string>& variables,
io::Printer* printer) {
- const map<string, string>::const_iterator it =
+ const std::map<string, string>::const_iterator it =
variables.find("disambiguated_reason");
if (it != variables.end() && !it->second.empty()) {
printer->Print(
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_field.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_field.h
index 4dd4f57f6d..434e610cc1 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_field.h
@@ -169,7 +169,7 @@ struct FieldGeneratorInfo {
string disambiguated_reason;
};
-// Oneof information used in OneofFieldGeneartors.
+// Oneof information used in OneofFieldGenerators.
struct OneofGeneratorInfo {
string name;
string capitalized_name;
@@ -178,15 +178,15 @@ struct OneofGeneratorInfo {
// Set some common variables used in variable FieldGenerators.
void SetCommonFieldVariables(const FieldDescriptor* descriptor,
const FieldGeneratorInfo* info,
- map<string, string>* variables);
+ std::map<string, string>* variables);
// Set some common oneof variables used in OneofFieldGenerators.
void SetCommonOneofVariables(const FieldDescriptor* descriptor,
const OneofGeneratorInfo* info,
- map<string, string>* variables);
+ std::map<string, string>* variables);
// Print useful comments before a field's accessors.
-void PrintExtraFieldInfo(const map<string, string>& variables,
+void PrintExtraFieldInfo(const std::map<string, string>& variables,
io::Printer* printer);
} // namespace java
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_file.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_file.cc
index 5e387285bb..86719f704c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_file.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_file.cc
@@ -65,7 +65,7 @@ namespace java {
namespace {
struct FieldDescriptorCompare {
- bool operator ()(const FieldDescriptor* f1, const FieldDescriptor* f2) {
+ bool operator ()(const FieldDescriptor* f1, const FieldDescriptor* f2) const {
if(f1 == NULL) {
return false;
}
@@ -90,7 +90,7 @@ bool CollectExtensions(const Message& message,
// There are unknown fields that could be extensions, thus this call fails.
if (reflection->GetUnknownFields(message).field_count() > 0) return false;
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
reflection->ListFields(message, &fields);
for (int i = 0; i < fields.size(); i++) {
@@ -189,8 +189,6 @@ void MaybeRestartJavaMethod(io::Printer* printer,
*bytecode_estimate = 0;
}
}
-
-
} // namespace
FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options,
@@ -543,8 +541,8 @@ static void GenerateSibling(const string& package_dir,
const string& java_package,
const DescriptorClass* descriptor,
GeneratorContext* context,
- vector<string>* file_list, bool annotate_code,
- vector<string>* annotation_list,
+ std::vector<string>* file_list, bool annotate_code,
+ std::vector<string>* annotation_list,
const string& name_suffix,
GeneratorClass* generator,
void (GeneratorClass::*pfn)(io::Printer* printer)) {
@@ -583,8 +581,8 @@ static void GenerateSibling(const string& package_dir,
void FileGenerator::GenerateSiblings(const string& package_dir,
GeneratorContext* context,
- vector<string>* file_list,
- vector<string>* annotation_list) {
+ std::vector<string>* file_list,
+ std::vector<string>* annotation_list) {
if (MultipleJavaFiles(file_, immutable_api_)) {
for (int i = 0; i < file_->enum_type_count(); i++) {
if (HasDescriptorMethods(file_, context_->EnforceLite())) {
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_file.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_file.h
index 1e643f79bd..e95aef0912 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_file.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_file.h
@@ -84,8 +84,8 @@ class FileGenerator {
// service type).
void GenerateSiblings(const string& package_dir,
GeneratorContext* generator_context,
- vector<string>* file_list,
- vector<string>* annotation_list);
+ std::vector<string>* file_list,
+ std::vector<string>* annotation_list);
const string& java_package() { return java_package_; }
const string& classname() { return classname_; }
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_generator.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_generator.cc
index b1ab404330..2c02d996fe 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_generator.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_generator.cc
@@ -66,7 +66,7 @@ bool JavaGenerator::Generate(const FileDescriptor* file,
// parse generator options
- vector<pair<string, string> > options;
+ std::vector<std::pair<string, string> > options;
ParseGeneratorParameter(parameter, &options);
Options file_options;
@@ -105,11 +105,11 @@ bool JavaGenerator::Generate(const FileDescriptor* file,
// -----------------------------------------------------------------
- vector<string> all_files;
- vector<string> all_annotations;
+ std::vector<string> all_files;
+ std::vector<string> all_annotations;
- vector<FileGenerator*> file_generators;
+ std::vector<FileGenerator*> file_generators;
if (file_options.generate_immutable_code) {
file_generators.push_back(new FileGenerator(file, file_options,
/* immutable = */ true));
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_generator.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_generator.h
index 47f76be983..47f76be983 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_generator.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_generator.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_generator_factory.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_generator_factory.cc
index 3218b41076..3218b41076 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_generator_factory.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_generator_factory.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_generator_factory.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_generator_factory.h
index 55365a9d4e..55365a9d4e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_generator_factory.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_generator_factory.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_helpers.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.cc
index c31df2651f..efb5fd4565 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_helpers.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.cc
@@ -360,6 +360,7 @@ const char* BoxedPrimitiveTypeName(JavaType type) {
return NULL;
}
+
const char* FieldTypeName(FieldDescriptor::Type field_type) {
switch (field_type) {
case FieldDescriptor::TYPE_INT32 : return "INT32";
@@ -415,9 +416,9 @@ string DefaultValue(const FieldDescriptor* field, bool immutable,
"L";
case FieldDescriptor::CPPTYPE_DOUBLE: {
double value = field->default_value_double();
- if (value == numeric_limits<double>::infinity()) {
+ if (value == std::numeric_limits<double>::infinity()) {
return "Double.POSITIVE_INFINITY";
- } else if (value == -numeric_limits<double>::infinity()) {
+ } else if (value == -std::numeric_limits<double>::infinity()) {
return "Double.NEGATIVE_INFINITY";
} else if (value != value) {
return "Double.NaN";
@@ -427,9 +428,9 @@ string DefaultValue(const FieldDescriptor* field, bool immutable,
}
case FieldDescriptor::CPPTYPE_FLOAT: {
float value = field->default_value_float();
- if (value == numeric_limits<float>::infinity()) {
+ if (value == std::numeric_limits<float>::infinity()) {
return "Float.POSITIVE_INFINITY";
- } else if (value == -numeric_limits<float>::infinity()) {
+ } else if (value == -std::numeric_limits<float>::infinity()) {
return "Float.NEGATIVE_INFINITY";
} else if (value != value) {
return "Float.NaN";
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_helpers.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.h
index 829ec3d763..829ec3d763 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_helpers.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_helpers.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_lazy_message_field.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field.cc
index abf8e55cf7..abf8e55cf7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_lazy_message_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_lazy_message_field.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field.h
index b1b7f2820e..b1b7f2820e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_lazy_message_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc
index dac1b51f73..49070ba0e1 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc
@@ -446,8 +446,7 @@ GenerateMembers(io::Printer* printer) const {
" for (com.google.protobuf.LazyFieldLite lf : $name$_) {\n"
" list.add(($type$) lf.getValue($type$.getDefaultInstance()));\n"
" }\n"
- // TODO(dweis): Make this list immutable?
- " return list;\n"
+ " return java.util.Collections.unmodifiableList(list);\n"
"}\n");
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_lazy_message_field_lite.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field_lite.h
index 47ebeb49a0..47ebeb49a0 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_lazy_message_field_lite.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field_lite.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_map_field.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_map_field.cc
index 16c5bec578..3fe68ae3d5 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_map_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_map_field.cc
@@ -80,7 +80,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor,
int builderBitIndex,
const FieldGeneratorInfo* info,
Context* context,
- map<string, string>* variables) {
+ std::map<string, string>* variables) {
SetCommonFieldVariables(descriptor, info, variables);
ClassNameResolver* name_resolver = context->GetNameResolver();
@@ -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
@@ -303,6 +308,16 @@ GenerateMembers(io::Printer* printer) const {
" com.google.protobuf.Internal.MapAdapter.newEnumConverter(\n"
" $value_enum_type$.internalGetValueMap(),\n"
" $unrecognized_value$);\n");
+ printer->Print(
+ variables_,
+ "private static final java.util.Map<$boxed_key_type$, "
+ "$value_enum_type$>\n"
+ "internalGetAdapted$capitalized_name$Map(\n"
+ " java.util.Map<$boxed_key_type$, $boxed_value_type$> map) {\n"
+ " return new com.google.protobuf.Internal.MapAdapter<\n"
+ " $boxed_key_type$, $value_enum_type$, java.lang.Integer>(\n"
+ " map, $name$ValueConverter);\n"
+ "}\n");
}
GenerateMapGetters(printer);
}
@@ -334,23 +349,23 @@ GenerateBuilderMembers(io::Printer* printer) const {
" return $name$_;\n"
"}\n");
GenerateMapGetters(printer);
- printer->Print(
- variables_,
- "$deprecation$\n"
- "public Builder clear$capitalized_name$() {\n"
- " getMutable$capitalized_name$().clear();\n"
- " return this;\n"
- "}\n");
+ printer->Print(variables_,
+ "$deprecation$\n"
+ "public Builder clear$capitalized_name$() {\n"
+ " internalGetMutable$capitalized_name$().getMutableMap()\n"
+ " .clear();\n"
+ " return this;\n"
+ "}\n");
WriteFieldDocComment(printer, descriptor_);
- printer->Print(
- variables_,
- "$deprecation$\n"
- "public Builder remove$capitalized_name$(\n"
- " $key_type$ key) {\n"
- " $key_null_check$\n"
- " getMutable$capitalized_name$().remove(key);\n"
- " return this;\n"
- "}\n");
+ printer->Print(variables_,
+ "$deprecation$\n"
+ "public Builder remove$capitalized_name$(\n"
+ " $key_type$ key) {\n"
+ " $key_null_check$\n"
+ " internalGetMutable$capitalized_name$().getMutableMap()\n"
+ " .remove(key);\n"
+ " return this;\n"
+ "}\n");
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
printer->Print(
variables_,
@@ -360,30 +375,28 @@ GenerateBuilderMembers(io::Printer* printer) const {
"@java.lang.Deprecated\n"
"public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
"getMutable$capitalized_name$() {\n"
- " return new com.google.protobuf.Internal.MapAdapter<\n"
- " $boxed_key_type$, $value_enum_type$, java.lang.Integer>(\n"
- " internalGetMutable$capitalized_name$().getMutableMap(),\n"
- " $name$ValueConverter);\n"
+ " return internalGetAdapted$capitalized_name$Map(\n"
+ " internalGetMutable$capitalized_name$().getMutableMap());\n"
"}\n");
WriteFieldDocComment(printer, descriptor_);
- printer->Print(
- variables_,
- "$deprecation$public Builder put$capitalized_name$(\n"
- " $key_type$ key,\n"
- " $value_enum_type$ value) {\n"
- " $key_null_check$\n"
- " $value_null_check$\n"
- " getMutable$capitalized_name$().put(key, value);\n"
- " return this;\n"
- "}\n");
+ printer->Print(variables_,
+ "$deprecation$public Builder put$capitalized_name$(\n"
+ " $key_type$ key,\n"
+ " $value_enum_type$ value) {\n"
+ " $key_null_check$\n"
+ " $value_null_check$\n"
+ " internalGetMutable$capitalized_name$().getMutableMap()\n"
+ " .put(key, $name$ValueConverter.doBackward(value));\n"
+ " return this;\n"
+ "}\n");
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
- // TODO(arielb): null check map keys/values here and everywhere else
- // related to putAll
"$deprecation$public Builder putAll$capitalized_name$(\n"
" java.util.Map<$boxed_key_type$, $value_enum_type$> values) {\n"
- " getMutable$capitalized_name$().putAll(values);\n"
+ " internalGetAdapted$capitalized_name$Map(\n"
+ " internalGetMutable$capitalized_name$().getMutableMap())\n"
+ " .putAll(values);\n"
" return this;\n"
"}\n");
if (SupportUnknownEnumValue(descriptor_->file())) {
@@ -407,7 +420,8 @@ GenerateBuilderMembers(io::Printer* printer) const {
" if ($value_enum_type$.forNumber(value) == null) {\n"
" throw new java.lang.IllegalArgumentException();\n"
" }\n"
- " getMutable$capitalized_name$Value().put(key, value);\n"
+ " internalGetMutable$capitalized_name$().getMutableMap()\n"
+ " .put(key, value);\n"
" return this;\n"
"}\n");
WriteFieldDocComment(printer, descriptor_);
@@ -415,7 +429,8 @@ GenerateBuilderMembers(io::Printer* printer) const {
variables_,
"$deprecation$public Builder putAll$capitalized_name$Value(\n"
" java.util.Map<$boxed_key_type$, $boxed_value_type$> values) {\n"
- " getMutable$capitalized_name$Value().putAll(values);\n"
+ " internalGetMutable$capitalized_name$().getMutableMap()\n"
+ " .putAll(values);\n"
" return this;\n"
"}\n");
}
@@ -431,26 +446,26 @@ GenerateBuilderMembers(io::Printer* printer) const {
" return internalGetMutable$capitalized_name$().getMutableMap();\n"
"}\n");
WriteFieldDocComment(printer, descriptor_);
- printer->Print(
- variables_,
- "$deprecation$"
- "public Builder put$capitalized_name$(\n"
- " $key_type$ key,\n"
- " $value_type$ value) {\n"
- " $key_null_check$\n"
- " $value_null_check$\n"
- " getMutable$capitalized_name$().put(key, value);\n"
- " return this;\n"
- "}\n");
+ printer->Print(variables_,
+ "$deprecation$"
+ "public Builder put$capitalized_name$(\n"
+ " $key_type$ key,\n"
+ " $value_type$ value) {\n"
+ " $key_null_check$\n"
+ " $value_null_check$\n"
+ " internalGetMutable$capitalized_name$().getMutableMap()\n"
+ " .put(key, value);\n"
+ " return this;\n"
+ "}\n");
WriteFieldDocComment(printer, descriptor_);
- printer->Print(
- variables_,
- "$deprecation$\n"
- "public Builder putAll$capitalized_name$(\n"
- " java.util.Map<$type_parameters$> values) {\n"
- " getMutable$capitalized_name$().putAll(values);\n"
- " return this;\n"
- "}\n");
+ printer->Print(variables_,
+ "$deprecation$\n"
+ "public Builder putAll$capitalized_name$(\n"
+ " java.util.Map<$type_parameters$> values) {\n"
+ " internalGetMutable$capitalized_name$().getMutableMap()\n"
+ " .putAll(values);\n"
+ " return this;\n"
+ "}\n");
}
}
@@ -483,16 +498,13 @@ GenerateMapGetters(io::Printer* printer) const {
" return get$capitalized_name$Map();\n"
"}\n");
WriteFieldDocComment(printer, descriptor_);
- printer->Print(
- variables_,
- "$deprecation$\n"
- "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
- "get$capitalized_name$Map() {\n"
- " return new com.google.protobuf.Internal.MapAdapter<\n"
- " $boxed_key_type$, $value_enum_type$, java.lang.Integer>(\n"
- " internalGet$capitalized_name$().getMap(),\n"
- " $name$ValueConverter);\n"
- "}\n");
+ printer->Print(variables_,
+ "$deprecation$\n"
+ "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
+ "get$capitalized_name$Map() {\n"
+ " return internalGetAdapted$capitalized_name$Map(\n"
+ " internalGet$capitalized_name$().getMap());"
+ "}\n");
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@@ -661,21 +673,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 +702,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 +717,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/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_map_field.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_map_field.h
index ae7ce7c5b1..4702174063 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_map_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_map_field.h
@@ -67,7 +67,7 @@ class ImmutableMapFieldGenerator : public ImmutableFieldGenerator {
private:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
ClassNameResolver* name_resolver_;
void GenerateMapGetters(io::Printer* printer) const;
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_map_field_lite.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_map_field_lite.cc
index 0d3bea1703..523052cc9e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_map_field_lite.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_map_field_lite.cc
@@ -80,7 +80,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor,
int builderBitIndex,
const FieldGeneratorInfo* info,
Context* context,
- map<string, string>* variables) {
+ std::map<string, string>* variables) {
SetCommonFieldVariables(descriptor, info, variables);
ClassNameResolver* name_resolver = context->GetNameResolver();
@@ -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/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_map_field_lite.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_map_field_lite.h
index 555b5c5bdd..63dedbc2cf 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_map_field_lite.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_map_field_lite.h
@@ -66,7 +66,7 @@ class ImmutableMapFieldLiteGenerator : public ImmutableFieldLiteGenerator {
private:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
ClassNameResolver* name_resolver_;
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc
index 6c80d07064..3b8d7ab8ec 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_message.cc
@@ -110,7 +110,7 @@ void ImmutableMessageGenerator::GenerateStaticVariables(
// the outermost class in the file. This way, they will be initialized in
// a deterministic order.
- map<string, string> vars;
+ std::map<string, string> vars;
vars["identifier"] = UniqueFileScopeIdentifier(descriptor_);
vars["index"] = SimpleItoa(descriptor_->index());
vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_);
@@ -154,7 +154,7 @@ void ImmutableMessageGenerator::GenerateStaticVariables(
int ImmutableMessageGenerator::GenerateStaticVariableInitializers(
io::Printer* printer) {
int bytecode_estimate = 0;
- map<string, string> vars;
+ std::map<string, string> vars;
vars["identifier"] = UniqueFileScopeIdentifier(descriptor_);
vars["index"] = SimpleItoa(descriptor_->index());
vars["classname"] = name_resolver_->GetImmutableClassName(descriptor_);
@@ -191,7 +191,7 @@ int ImmutableMessageGenerator::GenerateStaticVariableInitializers(
void ImmutableMessageGenerator::
GenerateFieldAccessorTable(io::Printer* printer, int* bytecode_estimate) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars["identifier"] = UniqueFileScopeIdentifier(descriptor_);
if (MultipleJavaFiles(descriptor_->file(), /* immutable = */ true)) {
// We can only make these package-private since the classes that use them
@@ -253,18 +253,22 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) {
/* immutable = */ true, "OrBuilder");
if (descriptor_->extension_range_count() > 0) {
printer->Print(
- "public interface $classname$OrBuilder$idend$ extends\n"
+ "$deprecation$public interface $classname$OrBuilder$idend$ extends\n"
" $extra_interfaces$\n"
" com.google.protobuf.GeneratedMessage$ver$.\n"
" ExtendableMessageOrBuilder<$classname$> {\n",
+ "deprecation", descriptor_->options().deprecated() ?
+ "@java.lang.Deprecated " : "",
"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
"classname", descriptor_->name(),
"idend", "", "ver", GeneratedCodeVersionSuffix());
} else {
printer->Print(
- "public interface $classname$OrBuilder$idend$ extends\n"
+ "$deprecation$public interface $classname$OrBuilder$idend$ extends\n"
" $extra_interfaces$\n"
" com.google.protobuf.MessageOrBuilder {\n",
+ "deprecation", descriptor_->options().deprecated() ?
+ "@java.lang.Deprecated " : "",
"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
"classname", descriptor_->name(),
"idend", "");
@@ -299,11 +303,13 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) {
void ImmutableMessageGenerator::Generate(io::Printer* printer) {
bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true);
- map<string, string> variables;
+ std::map<string, string> variables;
variables["static"] = is_own_file ? " " : " static ";
variables["classname"] = descriptor_->name();
variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_);
variables["ver"] = GeneratedCodeVersionSuffix();
+ variables["deprecation"] = descriptor_->options().deprecated()
+ ? "@java.lang.Deprecated " : "";
WriteMessageDocComment(printer, descriptor_);
MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
@@ -312,8 +318,9 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
// The builder_type stores the super type name of the nested Builder class.
string builder_type;
if (descriptor_->extension_range_count() > 0) {
- printer->Print(variables,
- "public $static$final class $classname$ extends\n");
+ printer->Print(
+ variables,
+ "$deprecation$public $static$final class $classname$ extends\n");
printer->Annotate("classname", descriptor_);
printer->Print(
variables,
@@ -326,8 +333,9 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
name_resolver_->GetImmutableClassName(descriptor_),
GeneratedCodeVersionSuffix());
} else {
- printer->Print(variables,
- "public $static$final class $classname$ extends\n");
+ printer->Print(
+ variables,
+ "$deprecation$public $static$final class $classname$ extends\n");
printer->Annotate("classname", descriptor_);
printer->Print(variables,
" com.google.protobuf.GeneratedMessage$ver$ implements\n"
@@ -409,7 +417,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
}
// oneof
- map<string, string> vars;
+ std::map<string, string> vars;
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
vars["oneof_name"] = context_->GetOneofGeneratorInfo(
descriptor_->oneof_decl(i))->name;
@@ -561,13 +569,12 @@ GenerateMessageSerializationMethods(io::Printer* printer) {
google::protobuf::scoped_array<const FieldDescriptor * > sorted_fields(
SortFieldsByNumber(descriptor_));
- vector<const Descriptor::ExtensionRange*> sorted_extensions;
+ std::vector<const Descriptor::ExtensionRange*> sorted_extensions;
for (int i = 0; i < descriptor_->extension_range_count(); ++i) {
sorted_extensions.push_back(descriptor_->extension_range(i));
}
std::sort(sorted_extensions.begin(), sorted_extensions.end(),
ExtensionRangeOrdering());
-
printer->Print(
"public void writeTo(com.google.protobuf.CodedOutputStream output)\n"
" throws java.io.IOException {\n");
@@ -799,7 +806,7 @@ GenerateDescriptorMethods(io::Printer* printer) {
"fileclass", name_resolver_->GetImmutableClassName(descriptor_->file()),
"identifier", UniqueFileScopeIdentifier(descriptor_));
}
- vector<const FieldDescriptor*> map_fields;
+ std::vector<const FieldDescriptor*> map_fields;
for (int i = 0; i < descriptor_->field_count(); i++) {
const FieldDescriptor* field = descriptor_->field(i);
if (GetJavaType(field) == JAVATYPE_MESSAGE &&
@@ -928,7 +935,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"
@@ -1093,7 +1100,12 @@ GenerateEqualsAndHashCode(io::Printer* printer) {
"}\n"
"int hash = 41;\n");
- printer->Print("hash = (19 * hash) + getDescriptorForType().hashCode();\n");
+ // If we output a getDescriptor() method, use that as it is more efficient.
+ if (descriptor_->options().no_standard_descriptor_accessor()) {
+ printer->Print("hash = (19 * hash) + getDescriptorForType().hashCode();\n");
+ } else {
+ printer->Print("hash = (19 * hash) + getDescriptor().hashCode();\n");
+ }
// hashCode non-oneofs.
for (int i = 0; i < descriptor_->field_count(); i++) {
@@ -1254,7 +1266,7 @@ GenerateParsingConstructor(io::Printer* printer) {
printer->Print(
"case $tag$: {\n",
- "tag", SimpleItoa(tag));
+ "tag", SimpleItoa(static_cast<int32>(tag)));
printer->Indent();
field_generators_.get(field).GenerateParsingCode(printer);
@@ -1271,7 +1283,7 @@ GenerateParsingConstructor(io::Printer* printer) {
WireFormatLite::WIRETYPE_LENGTH_DELIMITED);
printer->Print(
"case $tag$: {\n",
- "tag", SimpleItoa(packed_tag));
+ "tag", SimpleItoa(static_cast<int32>(packed_tag)));
printer->Indent();
field_generators_.get(field).GenerateParsingCodeFromPacked(printer);
@@ -1417,7 +1429,7 @@ void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) {
"}\n"
"\n"
"/**\n"
- " * Packs a message uisng the given type URL prefix. The type URL will\n"
+ " * Packs a message using the given type URL prefix. The type URL will\n"
" * be constructed by concatenating the message type's full name to the\n"
" * prefix with an optional \"/\" separator if the prefix doesn't end\n"
" * with \"/\" already.\n"
@@ -1441,6 +1453,7 @@ void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) {
"\n"
"private volatile com.google.protobuf.Message cachedUnpackValue;\n"
"\n"
+ "@java.lang.SuppressWarnings(\"unchecked\")\n"
"public <T extends com.google.protobuf.Message> T unpack(\n"
" java.lang.Class<T> clazz)\n"
" throws com.google.protobuf.InvalidProtocolBufferException {\n"
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_message.h
index da1447c176..da1447c176 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_message.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_builder.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_builder.cc
index 421546943a..f5643abc6a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_builder.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_builder.cc
@@ -122,7 +122,7 @@ Generate(io::Printer* printer) {
}
// oneof
- map<string, string> vars;
+ std::map<string, string> vars;
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
vars["oneof_name"] = context_->GetOneofGeneratorInfo(
descriptor_->oneof_decl(i))->name;
@@ -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"
@@ -220,7 +225,7 @@ GenerateDescriptorMethods(io::Printer* printer) {
"fileclass", name_resolver_->GetImmutableClassName(descriptor_->file()),
"identifier", UniqueFileScopeIdentifier(descriptor_));
}
- vector<const FieldDescriptor*> map_fields;
+ std::vector<const FieldDescriptor*> map_fields;
for (int i = 0; i < descriptor_->field_count(); i++) {
const FieldDescriptor* field = descriptor_->field(i);
if (GetJavaType(field) == JAVATYPE_MESSAGE &&
@@ -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/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_builder.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_builder.h
index 015ea06206..015ea06206 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_builder.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_builder.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_builder_lite.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_builder_lite.cc
index dd429dc93e..7e404ba167 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_builder_lite.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_builder_lite.cc
@@ -106,7 +106,7 @@ Generate(io::Printer* printer) {
GenerateCommonBuilderMethods(printer);
// oneof
- map<string, string> vars;
+ std::map<string, string> vars;
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
vars["oneof_name"] = context_->GetOneofGeneratorInfo(
descriptor_->oneof_decl(i))->name;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_builder_lite.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_builder_lite.h
index 8597b2e66f..8597b2e66f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_builder_lite.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_builder_lite.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_field.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_field.cc
index c9865dda27..ae84db1c17 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_field.cc
@@ -56,7 +56,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor,
int builderBitIndex,
const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
- map<string, string>* variables) {
+ std::map<string, string>* variables) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] =
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_field.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_field.h
index ea8225a5fa..7ee0edb269 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_field.h
@@ -82,7 +82,7 @@ class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator {
protected:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
@@ -148,7 +148,7 @@ class RepeatedImmutableMessageFieldGenerator : public ImmutableFieldGenerator {
protected:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_field_lite.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_field_lite.cc
index 142818169d..0957676cb0 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_field_lite.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_field_lite.cc
@@ -56,7 +56,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor,
int builderBitIndex,
const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
- map<string, string>* variables) {
+ std::map<string, string>* variables) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] =
@@ -70,6 +70,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor,
// by the proto compiler
(*variables)["deprecation"] = descriptor->options().deprecated()
? "@java.lang.Deprecated " : "";
+ (*variables)["required"] = descriptor->is_required() ? "true" : "false";
if (SupportFieldPresence(descriptor->file())) {
// For singular messages and builders, one bit is used for the hasField bit.
@@ -145,6 +146,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/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_field_lite.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_field_lite.h
index 6132154778..dbb263de18 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_field_lite.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_field_lite.h
@@ -81,7 +81,7 @@ class ImmutableMessageFieldLiteGenerator : public ImmutableFieldLiteGenerator {
protected:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
@@ -139,7 +139,7 @@ class RepeatedImmutableMessageFieldLiteGenerator
protected:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_lite.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_lite.cc
index 7c8c4a0314..e84321bb63 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_lite.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_lite.cc
@@ -124,19 +124,23 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) {
/* immutable = */ true, "OrBuilder");
if (descriptor_->extension_range_count() > 0) {
printer->Print(
- "public interface $classname$OrBuilder$idend$ extends \n"
+ "$deprecation$public interface $classname$OrBuilder$idend$ extends \n"
" $extra_interfaces$\n"
" com.google.protobuf.GeneratedMessageLite.\n"
" ExtendableMessageOrBuilder<\n"
" $classname$, $classname$.Builder> {\n",
+ "deprecation", descriptor_->options().deprecated() ?
+ "@java.lang.Deprecated " : "",
"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
"classname", descriptor_->name(),
"idend", "");
} else {
printer->Print(
- "public interface $classname$OrBuilder$idend$ extends\n"
+ "$deprecation$public interface $classname$OrBuilder$idend$ extends\n"
" $extra_interfaces$\n"
" com.google.protobuf.MessageLiteOrBuilder {\n",
+ "deprecation", descriptor_->options().deprecated() ?
+ "@java.lang.Deprecated " : "",
"extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_),
"classname", descriptor_->name(),
"idend", "");
@@ -170,20 +174,23 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) {
void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
bool is_own_file = IsOwnFile(descriptor_, /* immutable = */ true);
- map<string, string> variables;
+ std::map<string, string> variables;
variables["static"] = is_own_file ? " " : " static ";
variables["classname"] = descriptor_->name();
variables["extra_interfaces"] = ExtraMessageInterfaces(descriptor_);
+ variables["deprecation"] = descriptor_->options().deprecated()
+ ? "@java.lang.Deprecated " : "";
WriteMessageDocComment(printer, descriptor_);
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) {
printer->Print(variables,
- "public $static$final class $classname$ extends\n"
+ "$deprecation$public $static$final class $classname$ extends\n"
" com.google.protobuf.GeneratedMessageLite.ExtendableMessage<\n"
" $classname$, $classname$.Builder> implements\n"
" $extra_interfaces$\n"
@@ -193,7 +200,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
name_resolver_->GetImmutableClassName(descriptor_));
} else {
printer->Print(variables,
- "public $static$final class $classname$ extends\n"
+ "$deprecation$public $static$final class $classname$ extends\n"
" com.google.protobuf.GeneratedMessageLite<\n"
" $classname$, $classname$.Builder> implements\n"
" $extra_interfaces$\n"
@@ -203,7 +210,6 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
}
printer->Indent();
-
GenerateConstructor(printer);
// Nested types
@@ -236,13 +242,13 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
}
// oneof
- map<string, string> vars;
+ std::map<string, string> vars;
for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
- vars["oneof_name"] = context_->GetOneofGeneratorInfo(
- descriptor_->oneof_decl(i))->name;
+ const OneofDescriptor* oneof = descriptor_->oneof_decl(i);
+ vars["oneof_name"] = context_->GetOneofGeneratorInfo(oneof)->name;
vars["oneof_capitalized_name"] = context_->GetOneofGeneratorInfo(
- descriptor_->oneof_decl(i))->capitalized_name;
- vars["oneof_index"] = SimpleItoa(descriptor_->oneof_decl(i)->index());
+ oneof)->capitalized_name;
+ vars["oneof_index"] = SimpleItoa(oneof->index());
// oneofCase_ and oneof_
printer->Print(vars,
"private int $oneof_name$Case_ = 0;\n"
@@ -252,8 +258,8 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
"public enum $oneof_capitalized_name$Case\n"
" implements com.google.protobuf.Internal.EnumLite {\n");
printer->Indent();
- for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
- const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j);
+ for (int j = 0; j < oneof->field_count(); j++) {
+ const FieldDescriptor* field = oneof->field(j);
printer->Print(
"$field_name$($field_number$),\n",
"field_name",
@@ -281,8 +287,8 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
"\n"
"public static $oneof_capitalized_name$Case forNumber(int value) {\n"
" switch (value) {\n");
- for (int j = 0; j < descriptor_->oneof_decl(i)->field_count(); j++) {
- const FieldDescriptor* field = descriptor_->oneof_decl(i)->field(j);
+ for (int j = 0; j < oneof->field_count(); j++) {
+ const FieldDescriptor* field = oneof->field(j);
printer->Print(
" case $field_number$: return $field_name$;\n",
"field_number",
@@ -339,6 +345,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
}
printer->Print(
+ "@java.lang.SuppressWarnings({\"unchecked\", \"fallthrough\"})\n"
"protected final Object dynamicMethod(\n"
" com.google.protobuf.GeneratedMessageLite.MethodToInvoke method,\n"
" Object arg0, Object arg1) {\n"
@@ -467,7 +474,7 @@ GenerateMessageSerializationMethods(io::Printer* printer) {
google::protobuf::scoped_array<const FieldDescriptor * > sorted_fields(
SortFieldsByNumber(descriptor_));
- vector<const Descriptor::ExtensionRange*> sorted_extensions;
+ std::vector<const Descriptor::ExtensionRange*> sorted_extensions;
for (int i = 0; i < descriptor_->extension_range_count(); ++i) {
sorted_extensions.push_back(descriptor_->extension_range(i));
}
@@ -523,8 +530,13 @@ GenerateMessageSerializationMethods(io::Printer* printer) {
}
if (PreserveUnknownFields(descriptor_)) {
- printer->Print(
- "unknownFields.writeTo(output);\n");
+ if (descriptor_->options().message_set_wire_format()) {
+ printer->Print(
+ "unknownFields.writeAsMessageSetTo(output);\n");
+ } else {
+ printer->Print(
+ "unknownFields.writeTo(output);\n");
+ }
}
printer->Outdent();
@@ -553,8 +565,13 @@ GenerateMessageSerializationMethods(io::Printer* printer) {
}
if (PreserveUnknownFields(descriptor_)) {
- printer->Print(
- "size += unknownFields.getSerializedSize();\n");
+ if (descriptor_->options().message_set_wire_format()) {
+ printer->Print(
+ "size += unknownFields.getSerializedSizeAsMessageSet();\n");
+ } else {
+ printer->Print(
+ "size += unknownFields.getSerializedSize();\n");
+ }
}
printer->Outdent();
@@ -748,7 +765,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"
@@ -918,10 +935,10 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodMergeFromStream(
"com.google.protobuf.CodedInputStream input =\n"
" (com.google.protobuf.CodedInputStream) arg0;\n"
"com.google.protobuf.ExtensionRegistryLite extensionRegistry =\n"
- " (com.google.protobuf.ExtensionRegistryLite) arg1;\n"
+ " (com.google.protobuf.ExtensionRegistryLite) arg1;\n");
+ printer->Print(
"try {\n");
printer->Indent();
-
printer->Print(
"boolean done = false;\n"
"while (!done) {\n");
@@ -939,14 +956,26 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodMergeFromStream(
if (PreserveUnknownFields(descriptor_)) {
if (descriptor_->extension_range_count() > 0) {
- printer->Print(
- "default: {\n"
- " if (!parseUnknownField(getDefaultInstanceForType(),\n"
- " input, extensionRegistry, tag)) {\n"
- " done = true;\n" // it's an endgroup tag
- " }\n"
- " break;\n"
- "}\n");
+ if (descriptor_->options().message_set_wire_format()) {
+ printer->Print(
+ "default: {\n"
+ " if (!parseUnknownFieldAsMessageSet(\n"
+ " getDefaultInstanceForType(), input, extensionRegistry,\n"
+ " tag)) {\n"
+ " done = true;\n" // it's an endgroup tag
+ " }\n"
+ " break;\n"
+ "}\n");
+ } else {
+ printer->Print(
+ "default: {\n"
+ " if (!parseUnknownField(getDefaultInstanceForType(),\n"
+ " input, extensionRegistry, tag)) {\n"
+ " done = true;\n" // it's an endgroup tag
+ " }\n"
+ " break;\n"
+ "}\n");
+ }
} else {
printer->Print(
"default: {\n"
@@ -975,7 +1004,7 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodMergeFromStream(
printer->Print(
"case $tag$: {\n",
- "tag", SimpleItoa(tag));
+ "tag", SimpleItoa(static_cast<int32>(tag)));
printer->Indent();
field_generators_.get(field).GenerateParsingCode(printer);
@@ -992,7 +1021,7 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodMergeFromStream(
WireFormatLite::WIRETYPE_LENGTH_DELIMITED);
printer->Print(
"case $tag$: {\n",
- "tag", SimpleItoa(packed_tag));
+ "tag", SimpleItoa(static_cast<int32>(packed_tag)));
printer->Indent();
field_generators_.get(field).GenerateParsingCodeFromPacked(printer);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_lite.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_lite.h
index 1e319c6d6e..1e319c6d6e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_message_lite.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_message_lite.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_name_resolver.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_name_resolver.cc
index bffe4f16e7..bffe4f16e7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_name_resolver.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_name_resolver.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_name_resolver.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_name_resolver.h
index 570d8d8f1f..28b049d1e5 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_name_resolver.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_name_resolver.h
@@ -112,7 +112,7 @@ class ClassNameResolver {
const FileDescriptor* file,
bool immutable);
// Caches the result to provide better performance.
- map<const FileDescriptor*, string> file_immutable_outer_class_names_;
+ std::map<const FileDescriptor*, string> file_immutable_outer_class_names_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ClassNameResolver);
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_names.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_names.h
index 0d6143353a..0d6143353a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_names.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_names.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_options.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_options.h
index 7bce14470d..7bce14470d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_options.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_options.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_plugin_unittest.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_plugin_unittest.cc
index 3e4910c88a..3e4910c88a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_plugin_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_plugin_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_primitive_field.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field.cc
index 877baf0a63..840252e7e9 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_primitive_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field.cc
@@ -61,7 +61,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
int builderBitIndex,
const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
- map<string, string>* variables) {
+ std::map<string, string>* variables) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] = PrimitiveTypeName(GetJavaType(descriptor));
@@ -75,7 +75,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
"" : ("= " + ImmutableDefaultValue(descriptor, name_resolver));
(*variables)["capitalized_type"] =
GetCapitalizedType(descriptor, /* immutable = */ true);
- (*variables)["tag"] = SimpleItoa(WireFormat::MakeTag(descriptor));
+ (*variables)["tag"] =
+ SimpleItoa(static_cast<int32>(WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = SimpleItoa(
WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
if (IsReferenceType(GetJavaType(descriptor))) {
@@ -522,8 +523,17 @@ void ImmutablePrimitiveOneofFieldGenerator::
GenerateSerializationCode(io::Printer* printer) const {
printer->Print(variables_,
"if ($has_oneof_case_message$) {\n"
- " output.write$capitalized_type$(\n"
- " $number$, ($type$)(($boxed_type$) $oneof_name$_));\n"
+ " output.write$capitalized_type$(\n");
+ // $type$ and $boxed_type$ is the same for bytes fields so we don't need to
+ // do redundant casts.
+ if (GetJavaType(descriptor_) == JAVATYPE_BYTES) {
+ printer->Print(variables_,
+ " $number$, ($type$) $oneof_name$_);\n");
+ } else {
+ printer->Print(variables_,
+ " $number$, ($type$)(($boxed_type$) $oneof_name$_));\n");
+ }
+ printer->Print(
"}\n");
}
@@ -532,8 +542,17 @@ GenerateSerializedSizeCode(io::Printer* printer) const {
printer->Print(variables_,
"if ($has_oneof_case_message$) {\n"
" size += com.google.protobuf.CodedOutputStream\n"
- " .compute$capitalized_type$Size(\n"
- " $number$, ($type$)(($boxed_type$) $oneof_name$_));\n"
+ " .compute$capitalized_type$Size(\n");
+ // $type$ and $boxed_type$ is the same for bytes fields so we don't need to
+ // do redundant casts.
+ if (GetJavaType(descriptor_) == JAVATYPE_BYTES) {
+ printer->Print(variables_,
+ " $number$, ($type$) $oneof_name$_);\n");
+ } else {
+ printer->Print(variables_,
+ " $number$, ($type$)(($boxed_type$) $oneof_name$_));\n");
+ }
+ printer->Print(
"}\n");
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_primitive_field.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field.h
index d0cd12d976..7ac9bbfb74 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_primitive_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field.h
@@ -82,7 +82,7 @@ class ImmutablePrimitiveFieldGenerator : public ImmutableFieldGenerator {
protected:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
@@ -143,7 +143,7 @@ class RepeatedImmutablePrimitiveFieldGenerator
private:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_primitive_field_lite.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field_lite.cc
index ad2db30c43..b04bf1c22c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_primitive_field_lite.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field_lite.cc
@@ -61,7 +61,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
int builderBitIndex,
const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
- map<string, string>* variables) {
+ std::map<string, string>* variables) {
SetCommonFieldVariables(descriptor, info, variables);
JavaType javaType = GetJavaType(descriptor);
(*variables)["type"] = PrimitiveTypeName(javaType);
@@ -70,9 +70,11 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
(*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
(*variables)["capitalized_type"] =
GetCapitalizedType(descriptor, /* immutable = */ true);
- (*variables)["tag"] = SimpleItoa(WireFormat::MakeTag(descriptor));
+ (*variables)["tag"] =
+ SimpleItoa(static_cast<int32>(WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = SimpleItoa(
WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
+ (*variables)["required"] = descriptor->is_required() ? "true" : "false";
string capitalized_type = UnderscoresToCamelCase(PrimitiveTypeName(javaType),
true /* cap_next_letter */);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_primitive_field_lite.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field_lite.h
index 6cfbbb98cf..dc59f0cf9e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_primitive_field_lite.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_primitive_field_lite.h
@@ -84,7 +84,7 @@ class ImmutablePrimitiveFieldLiteGenerator
protected:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
@@ -146,7 +146,7 @@ class RepeatedImmutablePrimitiveFieldLiteGenerator
private:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_service.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_service.cc
index 9f34f01069..988e1942b7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_service.cc
+++ b/third_party/protobuf/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"
@@ -204,13 +208,12 @@ void ImmutableServiceGenerator::GenerateCallMethod(io::Printer* printer) {
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
- map<string, string> vars;
+ std::map<string, string> vars;
vars["index"] = SimpleItoa(i);
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"
@@ -252,13 +255,12 @@ void ImmutableServiceGenerator::GenerateCallBlockingMethod(
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
- map<string, string> vars;
+ std::map<string, string> vars;
vars["index"] = SimpleItoa(i);
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");
@@ -299,7 +301,7 @@ void ImmutableServiceGenerator::GenerateGetPrototype(RequestOrResponse which,
for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
- map<string, string> vars;
+ std::map<string, string> vars;
vars["index"] = SimpleItoa(i);
vars["type"] = name_resolver_->GetImmutableClassName(
(which == REQUEST) ? method->input_type() : method->output_type());
@@ -351,10 +353,9 @@ void ImmutableServiceGenerator::GenerateStub(io::Printer* printer) {
printer->Print(" {\n");
printer->Indent();
- map<string, string> vars;
+ std::map<string, string> 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"
@@ -416,10 +417,9 @@ void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) {
printer->Print(" {\n");
printer->Indent();
- map<string, string> vars;
+ std::map<string, string> 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"
@@ -440,10 +440,10 @@ void ImmutableServiceGenerator::GenerateBlockingStub(io::Printer* printer) {
void ImmutableServiceGenerator::GenerateMethodSignature(io::Printer* printer,
const MethodDescriptor* method,
IsAbstract is_abstract) {
- map<string, string> vars;
+ std::map<string, string> 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"
@@ -455,10 +455,10 @@ void ImmutableServiceGenerator::GenerateMethodSignature(io::Printer* printer,
void ImmutableServiceGenerator::GenerateBlockingMethodSignature(
io::Printer* printer,
const MethodDescriptor* method) {
- map<string, string> vars;
+ std::map<string, string> 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/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_service.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_service.h
index 5fc9e2f66c..12b3f94266 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_service.h
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_shared_code_generator.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_shared_code_generator.cc
index 5289372117..7bd5ad7aa7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_shared_code_generator.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_shared_code_generator.cc
@@ -59,8 +59,8 @@ SharedCodeGenerator::~SharedCodeGenerator() {
}
void SharedCodeGenerator::Generate(GeneratorContext* context,
- vector<string>* file_list,
- vector<string>* annotation_file_list) {
+ std::vector<string>* file_list,
+ std::vector<string>* annotation_file_list) {
string java_package = FileJavaPackage(file_);
string package_dir = JavaPackageToDir(java_package);
@@ -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);
@@ -181,15 +179,13 @@ void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) {
// -----------------------------------------------------------------
// Find out all dependencies.
- vector<pair<string, string> > dependencies;
+ std::vector<std::pair<string, string> > dependencies;
for (int i = 0; i < file_->dependency_count(); i++) {
- if (ShouldIncludeDependency(file_->dependency(i))) {
- string filename = file_->dependency(i)->name();
- string classname = FileJavaPackage(file_->dependency(i)) + "." +
- name_resolver_->GetDescriptorClassName(
- file_->dependency(i));
- dependencies.push_back(std::make_pair(filename, classname));
- }
+ string filename = file_->dependency(i)->name();
+ string classname = FileJavaPackage(file_->dependency(i)) + "." +
+ name_resolver_->GetDescriptorClassName(
+ file_->dependency(i));
+ dependencies.push_back(std::make_pair(filename, classname));
}
// -----------------------------------------------------------------
@@ -211,11 +207,6 @@ void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) {
" }, assigner);\n");
}
-bool SharedCodeGenerator::ShouldIncludeDependency(
- const FileDescriptor* descriptor) {
- return true;
-}
-
} // namespace java
} // namespace compiler
} // namespace protobuf
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_shared_code_generator.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_shared_code_generator.h
index 7e1e1f17cc..40502270ac 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_shared_code_generator.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_shared_code_generator.h
@@ -70,17 +70,13 @@ class SharedCodeGenerator {
SharedCodeGenerator(const FileDescriptor* file, const Options& options);
~SharedCodeGenerator();
- void Generate(GeneratorContext* generator_context, vector<string>* file_list,
- vector<string>* annotation_file_list);
+ void Generate(GeneratorContext* generator_context,
+ std::vector<string>* file_list,
+ std::vector<string>* annotation_file_list);
void GenerateDescriptors(io::Printer* printer);
private:
- // Returns whether the dependency should be included in the output file.
- // Always returns true for opensource, but used internally at Google to help
- // improve compatibility with version 1 of protocol buffers.
- bool ShouldIncludeDependency(const FileDescriptor* descriptor);
-
google::protobuf::scoped_ptr<ClassNameResolver> name_resolver_;
const FileDescriptor* file_;
const Options options_;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_string_field.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_string_field.cc
index ff1865b178..5c2900ceff 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_string_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_string_field.cc
@@ -62,7 +62,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
int builderBitIndex,
const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
- map<string, string>* variables) {
+ std::map<string, string>* variables) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["empty_list"] = "com.google.protobuf.LazyStringArrayList.EMPTY";
@@ -71,7 +71,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
(*variables)["default_init"] =
"= " + ImmutableDefaultValue(descriptor, name_resolver);
(*variables)["capitalized_type"] = "String";
- (*variables)["tag"] = SimpleItoa(WireFormat::MakeTag(descriptor));
+ (*variables)["tag"] =
+ SimpleItoa(static_cast<int32>(WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = SimpleItoa(
WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
(*variables)["null_check"] =
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_string_field.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_string_field.h
index a3b57351dc..0f7c705b8f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_string_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_string_field.h
@@ -83,7 +83,7 @@ class ImmutableStringFieldGenerator : public ImmutableFieldGenerator {
protected:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
@@ -142,7 +142,7 @@ class RepeatedImmutableStringFieldGenerator : public ImmutableFieldGenerator {
private:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_string_field_lite.cc b/third_party/protobuf/src/google/protobuf/compiler/java/java_string_field_lite.cc
index 0b92c02185..138e59b693 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_string_field_lite.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_string_field_lite.cc
@@ -62,7 +62,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
int builderBitIndex,
const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
- map<string, string>* variables) {
+ std::map<string, string>* variables) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["empty_list"] =
@@ -72,7 +72,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
(*variables)["default_init"] =
"= " + ImmutableDefaultValue(descriptor, name_resolver);
(*variables)["capitalized_type"] = "String";
- (*variables)["tag"] = SimpleItoa(WireFormat::MakeTag(descriptor));
+ (*variables)["tag"] =
+ SimpleItoa(static_cast<int32>(WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = SimpleItoa(
WireFormat::TagSize(descriptor->number(), GetType(descriptor)));
(*variables)["null_check"] =
@@ -84,6 +85,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
// by the proto compiler
(*variables)["deprecation"] = descriptor->options().deprecated()
? "@java.lang.Deprecated " : "";
+ (*variables)["required"] = descriptor->is_required() ? "true" : "false";
if (SupportFieldPresence(descriptor->file())) {
// For singular messages and builders, one bit is used for the hasField bit.
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_string_field_lite.h b/third_party/protobuf/src/google/protobuf/compiler/java/java_string_field_lite.h
index 4148aa4dfb..80496c8744 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/java/java_string_field_lite.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/java/java_string_field_lite.h
@@ -82,7 +82,7 @@ class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator {
protected:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
@@ -140,7 +140,7 @@ class RepeatedImmutableStringFieldLiteGenerator
private:
const FieldDescriptor* descriptor_;
- map<string, string> variables_;
+ std::map<string, string> variables_;
const int messageBitIndex_;
const int builderBitIndex_;
Context* context_;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_enum.cc b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_enum.cc
index c6e8dfe90d..c6e8dfe90d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_enum.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_enum.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_enum.h b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_enum.h
index 10dd364876..10dd364876 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_enum.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_enum.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_enum_field.cc b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_enum_field.cc
index 7666db38a2..7666db38a2 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_enum_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_enum_field.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_enum_field.h b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_enum_field.h
index b94790d6bd..b94790d6bd 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_enum_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_enum_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_extension.cc b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_extension.cc
index 0b9d1d8de7..0b9d1d8de7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_extension.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_extension.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_extension.h b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_extension.h
index 4843e29622..4843e29622 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_extension.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_extension.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_field.cc b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_field.cc
index 85257f3f73..85257f3f73 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_field.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_field.h b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_field.h
index 57c221f47c..57c221f47c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_file.cc b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_file.cc
index 3676ab9d19..3676ab9d19 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_file.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_file.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_file.h b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_file.h
index 217eafe2a8..217eafe2a8 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_file.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_file.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_generator.cc b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_generator.cc
index 7c3a04212f..7c3a04212f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_generator.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_generator.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_generator.h b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_generator.h
index 6f9f7f2a4a..6f9f7f2a4a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_generator.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_generator.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_helpers.cc b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_helpers.cc
index 02811a24dc..02811a24dc 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_helpers.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_helpers.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_helpers.h b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_helpers.h
index 014c85aee3..014c85aee3 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_helpers.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_helpers.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_map_field.cc b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_map_field.cc
index 83b2b0ce8f..83b2b0ce8f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_map_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_map_field.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_map_field.h b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_map_field.h
index c01bde3815..c01bde3815 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_map_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_map_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_message.cc b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_message.cc
index a41da5ae33..a41da5ae33 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_message.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_message.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_message.h b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_message.h
index 281ec64fdd..281ec64fdd 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_message.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_message.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_message_field.cc b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_message_field.cc
index d1d04b52a4..d1d04b52a4 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_message_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_message_field.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_message_field.h b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_message_field.h
index e074735c70..e074735c70 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_message_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_message_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_params.h b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_params.h
index e3b4bb9368..e3b4bb9368 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_params.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_params.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc
index 978abf2ce4..978abf2ce4 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_primitive_field.h b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_primitive_field.h
index a01981dd48..a01981dd48 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/javanano/javanano_primitive_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/javanano/javanano_primitive_field.h
diff --git a/third_party/protobuf/src/google/protobuf/compiler/js/embed.cc b/third_party/protobuf/src/google/protobuf/compiler/js/embed.cc
new file mode 100644
index 0000000000..57d38237b3
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/compiler/js/embed.cc
@@ -0,0 +1,112 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <cassert>
+#include <cstdlib>
+#include <fstream>
+#include <iostream>
+#include <string>
+
+const char output_file[] = "well_known_types_embed.cc";
+
+static bool AsciiIsPrint(unsigned char c) {
+ return c >= 32 && c < 127;
+}
+
+static char ToDecimalDigit(int num) {
+ assert(num < 10);
+ return '0' + num;
+}
+
+static std::string CEscape(const std::string& str) {
+ std::string dest;
+
+ for (size_t i = 0; i < str.size(); ++i) {
+ unsigned char ch = str[i];
+ switch (ch) {
+ case '\n': dest += "\\n"; break;
+ case '\r': dest += "\\r"; break;
+ case '\t': dest += "\\t"; break;
+ case '\"': dest += "\\\""; break;
+ case '\\': dest += "\\\\"; break;
+ default:
+ if (AsciiIsPrint(ch)) {
+ dest += ch;
+ } else {
+ dest += "\\";
+ dest += ToDecimalDigit(ch / 64);
+ dest += ToDecimalDigit((ch % 64) / 8);
+ dest += ToDecimalDigit(ch % 8);
+ }
+ break;
+ }
+ }
+
+ return dest;
+}
+
+static void AddFile(const char* name, std::basic_ostream<char>* out) {
+ std::ifstream in(name);
+
+ if (!in.is_open()) {
+ std::cerr << "Couldn't open input file: " << name << "\n";
+ std::exit(EXIT_FAILURE);
+ }
+
+ // Make canonical name only include the final element.
+ for (const char *p = name; *p; p++) {
+ if (*p == '/') {
+ name = p + 1;
+ }
+ }
+
+ *out << "{\"" << CEscape(name) << "\",\n";
+
+ for (std::string line; std::getline(in, line); ) {
+ *out << " \"" << CEscape(line) << "\\n\"\n";
+ }
+
+ *out << "},\n";
+}
+
+int main(int argc, char *argv[]) {
+ std::cout << "#include "
+ "<google/protobuf/compiler/js/well_known_types_embed.h>\n";
+ std::cout << "struct FileToc well_known_types_js[] = {\n";
+
+ for (int i = 1; i < argc; i++) {
+ AddFile(argv[i], &std::cout);
+ }
+
+ std::cout << " {NULL, NULL} // Terminate the list.\n";
+ std::cout << "};\n";
+
+ return EXIT_SUCCESS;
+}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/js/js_generator.cc b/third_party/protobuf/src/google/protobuf/compiler/js/js_generator.cc
index 58c77d007c..727ed09025 100755
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/js/js_generator.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/js/js_generator.cc
@@ -28,7 +28,7 @@
// (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 "google/protobuf/compiler/js/js_generator.h"
+#include <google/protobuf/compiler/js/js_generator.h>
#include <assert.h>
#include <algorithm>
@@ -45,6 +45,7 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/stringprintf.h>
+#include <google/protobuf/compiler/js/well_known_types_embed.h>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/descriptor.pb.h>
@@ -153,8 +154,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
@@ -208,28 +209,33 @@ string GetPath(const GeneratorOptions& options,
}
}
-// Forward declare, so that GetPrefix can call this method,
-// which in turn, calls GetPrefix.
-string GetPath(const GeneratorOptions& options,
- const Descriptor* descriptor);
+// Returns the name of the message with a leading dot and taking into account
+// nesting, for example ".OuterMessage.InnerMessage", or returns empty if
+// descriptor is null. This function does not handle namespacing, only message
+// nesting.
+string GetNestedMessageName(const Descriptor* descriptor) {
+ if (descriptor == NULL) {
+ return "";
+ }
+ string result =
+ StripPrefixString(descriptor->full_name(), descriptor->file()->package());
+ // Add a leading dot if one is not already present.
+ if (!result.empty() && result[0] != '.') {
+ result = "." + result;
+ }
+ return result;
+}
// Returns the path prefix for a message or enumeration that
// lives under the given file and containing type.
string GetPrefix(const GeneratorOptions& options,
const FileDescriptor* file_descriptor,
const Descriptor* containing_type) {
- string prefix = "";
-
- if (containing_type == NULL) {
- prefix = GetPath(options, file_descriptor);
- } else {
- prefix = GetPath(options, containing_type);
- }
-
+ string prefix =
+ GetPath(options, file_descriptor) + GetNestedMessageName(containing_type);
if (!prefix.empty()) {
prefix += ".";
}
-
return prefix;
}
@@ -273,11 +279,13 @@ 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.
- return ModuleAlias(to_message->file()->name()) + "." + to_message->name();
+ return ModuleAlias(to_message->file()->name()) +
+ GetNestedMessageName(to_message->containing_type()) + "." +
+ to_message->name();
} else {
// Within a single file we use a full name.
return GetPath(options, to_message);
@@ -307,8 +315,8 @@ char ToLowerASCII(char c) {
}
}
-vector<string> ParseLowerUnderscore(const string& input) {
- vector<string> words;
+std::vector<string> ParseLowerUnderscore(const string& input) {
+ std::vector<string> words;
string running = "";
for (int i = 0; i < input.size(); i++) {
if (input[i] == '_') {
@@ -326,8 +334,8 @@ vector<string> ParseLowerUnderscore(const string& input) {
return words;
}
-vector<string> ParseUpperCamel(const string& input) {
- vector<string> words;
+std::vector<string> ParseUpperCamel(const string& input) {
+ std::vector<string> words;
string running = "";
for (int i = 0; i < input.size(); i++) {
if (input[i] >= 'A' && input[i] <= 'Z' && !running.empty()) {
@@ -342,7 +350,7 @@ vector<string> ParseUpperCamel(const string& input) {
return words;
}
-string ToLowerCamel(const vector<string>& words) {
+string ToLowerCamel(const std::vector<string>& words) {
string result;
for (int i = 0; i < words.size(); i++) {
string word = words[i];
@@ -356,7 +364,7 @@ string ToLowerCamel(const vector<string>& words) {
return result;
}
-string ToUpperCamel(const vector<string>& words) {
+string ToUpperCamel(const std::vector<string>& words) {
string result;
for (int i = 0; i < words.size(); i++) {
string word = words[i];
@@ -405,21 +413,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 +455,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 +480,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 +492,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 +504,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 +532,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 +554,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 +788,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 +933,85 @@ string JSTypeName(const GeneratorOptions& options,
}
}
-bool HasFieldPresence(const FieldDescriptor* field);
+// Used inside Google only -- do not remove.
+bool UseBrokenPresenceSemantics(const GeneratorOptions& options,
+ const FieldDescriptor* field) {
+ 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 +1020,35 @@ string JSFieldTypeAnnotation(const GeneratorOptions& options,
bytes_mode == BYTES_DEFAULT) {
jstype = "(Array<!Uint8Array>|Array<string>)";
} 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 (is_setter_argument) {
+ if (SetterAcceptsNull(options, field)) {
+ jstype = "?" + jstype;
+ is_null_or_undefined = true;
+ }
- if (force_optional && HasFieldPresence(field)) {
- jstype += "|undefined";
+ 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;
}
@@ -980,22 +1077,14 @@ string JSBinaryReadWriteMethodName(const FieldDescriptor* field,
string JSBinaryReaderMethodName(const GeneratorOptions& options,
const FieldDescriptor* field) {
- if (options.binary) {
- return "jspb.BinaryReader.prototype.read" +
- JSBinaryReadWriteMethodName(field, /* is_writer = */ false);
- } else {
- return "null";
- }
+ return "jspb.BinaryReader.prototype.read" +
+ JSBinaryReadWriteMethodName(field, /* is_writer = */ false);
}
string JSBinaryWriterMethodName(const GeneratorOptions& options,
const FieldDescriptor* field) {
- if (options.binary) {
- return "jspb.BinaryWriter.prototype.write" +
- JSBinaryReadWriteMethodName(field, /* is_writer = */ true);
- } else {
- return "null";
- }
+ return "jspb.BinaryWriter.prototype.write" +
+ JSBinaryReadWriteMethodName(field, /* is_writer = */ true);
}
string JSReturnClause(const FieldDescriptor* desc) {
@@ -1007,9 +1096,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 +1110,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 +1132,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<string> 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 +1200,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 +1222,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);
@@ -1227,6 +1319,29 @@ bool HasExtensions(const FileDescriptor* file) {
return false;
}
+bool HasMap(const GeneratorOptions& options, const Descriptor* desc) {
+ for (int i = 0; i < desc->field_count(); i++) {
+ if (IsMap(options, desc->field(i))) {
+ return true;
+ }
+ }
+ for (int i = 0; i < desc->nested_type_count(); i++) {
+ if (HasMap(options, desc->nested_type(i))) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool FileHasMap(const GeneratorOptions& options, const FileDescriptor* desc) {
+ for (int i = 0; i < desc->message_type_count(); i++) {
+ if (HasMap(options, desc->message_type(i))) {
+ return true;
+ }
+ }
+ return false;
+}
+
bool IsExtendable(const Descriptor* desc) {
return desc->extension_range_count() > 0;
}
@@ -1254,47 +1369,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
@@ -1321,19 +1413,19 @@ class FileDeduplicator {
return true;
}
- void GetAllowedSet(set<const void*>* allowed_set) {
+ void GetAllowedSet(std::set<const void*>* allowed_set) {
*allowed_set = allowed_descs_;
}
private:
bool error_on_conflict_;
- map<string, const void*> descs_by_filename_;
- set<const void*> allowed_descs_;
+ std::map<string, const void*> descs_by_filename_;
+ std::set<const void*> allowed_descs_;
};
void DepthFirstSearch(const FileDescriptor* file,
- vector<const FileDescriptor*>* list,
- set<const FileDescriptor*>* seen) {
+ std::vector<const FileDescriptor*>* list,
+ std::set<const FileDescriptor*>* seen) {
if (!seen->insert(file).second) {
return;
}
@@ -1351,7 +1443,7 @@ void DepthFirstSearch(const FileDescriptor* file,
// FileDescriptor is not in the given set.
class NotInSet {
public:
- explicit NotInSet(const set<const FileDescriptor*>& file_set)
+ explicit NotInSet(const std::set<const FileDescriptor*>& file_set)
: file_set_(file_set) {}
bool operator()(const FileDescriptor* file) {
@@ -1359,21 +1451,21 @@ class NotInSet {
}
private:
- const set<const FileDescriptor*>& file_set_;
+ const std::set<const FileDescriptor*>& file_set_;
};
// This function generates an ordering of the input FileDescriptors that matches
// the logic of the old code generator. The order is significant because two
// different input files can generate the same output file, and the last one
// needs to win.
-void GenerateJspbFileOrder(const vector<const FileDescriptor*>& input,
- vector<const FileDescriptor*>* ordered) {
+void GenerateJspbFileOrder(const std::vector<const FileDescriptor*>& input,
+ std::vector<const FileDescriptor*>* ordered) {
// First generate an ordering of all reachable files (including dependencies)
// with depth-first search. This mimics the behavior of --include_imports,
// which is what the old codegen used.
ordered->clear();
- set<const FileDescriptor*> seen;
- set<const FileDescriptor*> input_set;
+ std::set<const FileDescriptor*> seen;
+ std::set<const FileDescriptor*> input_set;
for (int i = 0; i < input.size(); i++) {
DepthFirstSearch(input[i], ordered, &seen);
input_set.insert(input[i]);
@@ -1390,10 +1482,10 @@ void GenerateJspbFileOrder(const vector<const FileDescriptor*>& input,
// only those to generate code.
bool GenerateJspbAllowedSet(const GeneratorOptions& options,
- const vector<const FileDescriptor*>& files,
- set<const void*>* allowed_set,
+ const std::vector<const FileDescriptor*>& files,
+ std::set<const void*>* allowed_set,
string* error) {
- vector<const FileDescriptor*> files_ordered;
+ std::vector<const FileDescriptor*> files_ordered;
GenerateJspbFileOrder(files, &files_ordered);
// Choose the last descriptor for each filename.
@@ -1461,7 +1553,7 @@ void Generator::FindProvidesForFile(const GeneratorOptions& options,
void Generator::FindProvides(const GeneratorOptions& options,
io::Printer* printer,
- const vector<const FileDescriptor*>& files,
+ const std::vector<const FileDescriptor*>& files,
std::set<string>* provided) const {
for (int i = 0; i < files.size(); i++) {
FindProvidesForFile(options, printer, files[i], provided);
@@ -1503,7 +1595,7 @@ void Generator::FindProvidesForEnum(const GeneratorOptions& options,
void Generator::FindProvidesForFields(
const GeneratorOptions& options,
io::Printer* printer,
- const vector<const FieldDescriptor*>& fields,
+ const std::vector<const FieldDescriptor*>& fields,
std::set<string>* provided) const {
for (int i = 0; i < fields.size(); i++) {
const FieldDescriptor* field = fields[i];
@@ -1524,8 +1616,19 @@ void Generator::GenerateProvides(const GeneratorOptions& options,
std::set<string>* provided) const {
for (std::set<string>::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);
+ }
}
}
@@ -1541,18 +1644,20 @@ void Generator::GenerateRequiresForMessage(const GeneratorOptions& options,
GenerateRequiresImpl(options, printer, &required, &forwards, provided,
/* require_jspb = */ have_message,
- /* require_extension = */ HasExtensions(desc));
+ /* require_extension = */ HasExtensions(desc),
+ /* require_map = */ HasMap(options, desc));
}
void Generator::GenerateRequiresForLibrary(
const GeneratorOptions& options, io::Printer* printer,
- const vector<const FileDescriptor*>& files,
+ const std::vector<const FileDescriptor*>& files,
std::set<string>* 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<string> required;
std::set<string> forwards;
bool have_extensions = false;
+ bool have_map = false;
bool have_message = false;
for (int i = 0; i < files.size(); i++) {
@@ -1568,6 +1673,10 @@ void Generator::GenerateRequiresForLibrary(
have_extensions = true;
}
+ if (!have_map && FileHasMap(options, files[i])) {
+ have_map = true;
+ }
+
for (int j = 0; j < files[i]->extension_count(); j++) {
const FieldDescriptor* extension = files[i]->extension(j);
if (IgnoreField(extension)) {
@@ -1584,12 +1693,13 @@ void Generator::GenerateRequiresForLibrary(
GenerateRequiresImpl(options, printer, &required, &forwards, provided,
/* require_jspb = */ have_message,
- /* require_extension = */ have_extensions);
+ /* require_extension = */ have_extensions,
+ /* require_map = */ have_map);
}
void Generator::GenerateRequiresForExtensions(
const GeneratorOptions& options, io::Printer* printer,
- const vector<const FieldDescriptor*>& fields,
+ const std::vector<const FieldDescriptor*>& fields,
std::set<string>* provided) const {
std::set<string> required;
std::set<string> forwards;
@@ -1603,7 +1713,8 @@ void Generator::GenerateRequiresForExtensions(
GenerateRequiresImpl(options, printer, &required, &forwards, provided,
/* require_jspb = */ false,
- /* require_extension = */ fields.size() > 0);
+ /* require_extension = */ fields.size() > 0,
+ /* require_map = */ false);
}
void Generator::GenerateRequiresImpl(const GeneratorOptions& options,
@@ -1611,21 +1722,22 @@ void Generator::GenerateRequiresImpl(const GeneratorOptions& options,
std::set<string>* required,
std::set<string>* forwards,
std::set<string>* provided,
- bool require_jspb,
- bool require_extension) const {
+ bool require_jspb, bool require_extension,
+ bool require_map) const {
if (require_jspb) {
printer->Print(
- "goog.require('jspb.Message');\n");
- if (options.binary) {
- printer->Print(
- "goog.require('jspb.BinaryReader');\n"
- "goog.require('jspb.BinaryWriter');\n");
- }
+ "goog.require('jspb.Message');\n"
+ "goog.require('jspb.BinaryReader');\n"
+ "goog.require('jspb.BinaryWriter');\n");
}
if (require_extension) {
+ printer->Print("goog.require('jspb.ExtensionFieldBinaryInfo');\n");
printer->Print(
"goog.require('jspb.ExtensionFieldInfo');\n");
}
+ if (require_map) {
+ printer->Print("goog.require('jspb.Map');\n");
+ }
std::set<string>::iterator it;
for (it = required->begin(); it != required->end(); ++it) {
@@ -1747,35 +1859,38 @@ void Generator::GenerateClass(const GeneratorOptions& options,
GenerateClassToObject(options, printer, desc);
- if (options.binary) {
- // These must come *before* the extension-field info generation in
- // GenerateClassRegistration so that references to the binary
- // serialization/deserialization functions may be placed in the extension
- // objects.
- GenerateClassDeserializeBinary(options, printer, desc);
- GenerateClassSerializeBinary(options, printer, desc);
- }
- GenerateClassClone(options, printer, desc);
+ // These must come *before* the extension-field info generation in
+ // GenerateClassRegistration so that references to the binary
+ // serialization/deserialization functions may be placed in the extension
+ // objects.
+ GenerateClassDeserializeBinary(options, printer, desc);
+ GenerateClassSerializeBinary(options, printer, desc);
+ }
+
+ // Recurse on nested types. These must come *before* the extension-field
+ // info generation in GenerateClassRegistration so that extensions that
+ // reference nested types proceed the definitions of the nested types.
+ for (int i = 0; i < desc->enum_type_count(); i++) {
+ GenerateEnum(options, printer, desc->enum_type(i));
+ }
+ for (int i = 0; i < desc->nested_type_count(); i++) {
+ GenerateClass(options, printer, desc->nested_type(i));
+ }
+
+ if (!NamespaceOnly(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));
}
}
}
- // Recurse on nested types.
- for (int i = 0; i < desc->enum_type_count(); i++) {
- GenerateEnum(options, printer, desc->enum_type(i));
- }
- for (int i = 0; i < desc->nested_type_count(); i++) {
- GenerateClass(options, printer, desc->nested_type(i));
- }
}
void Generator::GenerateClassConstructor(const GeneratorOptions& options,
@@ -1820,7 +1935,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 +1946,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,15 +2115,72 @@ 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() : []",
- "name", JSGetterName(options, field));
+ if (IsMap(options, field)) {
+ const FieldDescriptor* value_field = MapFieldValue(field);
+ // If the map values are of a message type, we must provide their static
+ // toObject() method; otherwise we pass undefined for that argument.
+ string value_to_object;
+ if (value_field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
+ value_to_object =
+ GetPath(options, value_field->message_type()) + ".toObject";
+ } else {
+ value_to_object = "undefined";
+ }
+ printer->Print(
+ "(f = msg.get$name$()) ? f.toObject(includeInstance, $valuetoobject$) "
+ ": []",
+ "name", JSGetterName(options, field), "valuetoobject", value_to_object);
} else if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
// Message field.
if (field->is_repeated()) {
@@ -2024,40 +2196,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<field>() 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,16 +2252,28 @@ void Generator::GenerateClassFieldFromObject(
const GeneratorOptions& options,
io::Printer* printer,
const FieldDescriptor* field) const {
-
- if (field->is_map()) {
- // `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.
- printer->Print(
- " goog.isDef(obj.$name$) && "
- "jspb.Message.setField(msg, $index$, obj.$name$);\n",
- "name", JSObjectFieldName(options, field),
- "index", JSFieldIndex(field));
+ if (IsMap(options, field)) {
+ const FieldDescriptor* value_field = MapFieldValue(field);
+ if (value_field->type() == FieldDescriptor::TYPE_MESSAGE) {
+ // Since the map values are of message type, we have to do some extra work
+ // to recursively call fromObject() on them before setting the map field.
+ printer->Print(
+ " goog.isDef(obj.$name$) && jspb.Message.setWrapperField(\n"
+ " msg, $index$, jspb.Map.fromObject(obj.$name$, $fieldclass$, "
+ "$fieldclass$.fromObject));\n",
+ "name", JSObjectFieldName(options, field),
+ "index", JSFieldIndex(field),
+ "fieldclass", GetPath(options, value_field->message_type()));
+ } else {
+ // `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.
+ printer->Print(
+ " goog.isDef(obj.$name$) && "
+ "jspb.Message.setField(msg, $index$, obj.$name$);\n",
+ "name", JSObjectFieldName(options, field),
+ "index", JSFieldIndex(field));
+ }
} else if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
// Message field (singular or repeated)
if (field->is_repeated()) {
@@ -2133,21 +2306,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 +2333,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 +2365,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);
@@ -2250,7 +2407,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options,
printer->Print(",\n"
" $messageType$",
"messageType", GetPath(options, value_field->message_type()));
- } else if (options.binary) {
+ } else {
printer->Print(",\n"
" null");
}
@@ -2275,7 +2432,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 +2446,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 +2455,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 +2479,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 +2495,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 +2532,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 +2569,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 +2606,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 +2682,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 {
@@ -2538,28 +2760,26 @@ void Generator::GenerateClassExtensionFieldInfo(const GeneratorOptions& options,
"\n",
"class", GetPath(options, desc));
- if (options.binary) {
- printer->Print(
- "\n"
- "/**\n"
- " * The extensions registered with this message class. This is a "
- "map of\n"
- " * extension field number to fieldInfo object.\n"
- " *\n"
- " * For example:\n"
- " * { 123: {fieldIndex: 123, fieldName: {my_field_name: 0}, "
- "ctor: proto.example.MyMessage} }\n"
- " *\n"
- " * fieldName contains the JsCompiler renamed field name property "
- "so that it\n"
- " * works in OPTIMIZED mode.\n"
- " *\n"
- " * @type {!Object.<number, jspb.ExtensionFieldInfo>}\n"
- " */\n"
- "$class$.extensionsBinary = {};\n"
- "\n",
- "class", GetPath(options, desc));
- }
+ printer->Print(
+ "\n"
+ "/**\n"
+ " * The extensions registered with this message class. This is a "
+ "map of\n"
+ " * extension field number to fieldInfo object.\n"
+ " *\n"
+ " * For example:\n"
+ " * { 123: {fieldIndex: 123, fieldName: {my_field_name: 0}, "
+ "ctor: proto.example.MyMessage} }\n"
+ " *\n"
+ " * fieldName contains the JsCompiler renamed field name property "
+ "so that it\n"
+ " * works in OPTIMIZED mode.\n"
+ " *\n"
+ " * @type {!Object.<number, jspb.ExtensionFieldBinaryInfo>}\n"
+ " */\n"
+ "$class$.extensionsBinary = {};\n"
+ "\n",
+ "class", GetPath(options, desc));
}
}
@@ -2600,7 +2820,9 @@ void Generator::GenerateClassDeserializeBinary(const GeneratorOptions& options,
"class", GetPath(options, desc));
for (int i = 0; i < desc->field_count(); i++) {
- GenerateClassDeserializeBinaryField(options, printer, desc->field(i));
+ if (!IgnoreField(desc->field(i))) {
+ GenerateClassDeserializeBinaryField(options, printer, desc->field(i));
+ }
}
printer->Print(
@@ -2636,7 +2858,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(
@@ -2679,13 +2901,9 @@ void Generator::GenerateClassDeserializeBinaryField(
}
if (field->is_repeated() && !field->is_packed()) {
- // Repeated fields receive a |value| one at at a time; append to array
- // returned by get$name$(). Annoyingly, we have to call 'set' after
- // changing the array.
- printer->Print(" msg.get$name$().push(value);\n", "name",
- JSGetterName(options, field));
- printer->Print(" msg.set$name$(msg.get$name$());\n", "name",
- JSGetterName(options, field));
+ printer->Print(
+ " msg.add$name$(value);\n", "name",
+ JSGetterName(options, field, BYTES_DEFAULT, /* drop_list = */ true));
} else {
// Singular fields, and packed repeated fields, receive a |value| either
// as the field's value or as the array of all the field's values; set
@@ -2704,44 +2922,36 @@ void Generator::GenerateClassSerializeBinary(const GeneratorOptions& options,
const Descriptor* desc) const {
printer->Print(
"/**\n"
- " * Class method variant: serializes the given message to binary data\n"
- " * (in protobuf wire format), writing to the given BinaryWriter.\n"
- " * @param {!$class$} message\n"
- " * @param {!jspb.BinaryWriter} writer\n"
- " */\n"
- "$class$.serializeBinaryToWriter = function(message, "
- "writer) {\n"
- " message.serializeBinaryToWriter(writer);\n"
- "};\n"
- "\n"
- "\n"
- "/**\n"
" * Serializes the message to binary data (in protobuf wire format).\n"
" * @return {!Uint8Array}\n"
" */\n"
"$class$.prototype.serializeBinary = function() {\n"
" var writer = new jspb.BinaryWriter();\n"
- " this.serializeBinaryToWriter(writer);\n"
+ " $class$.serializeBinaryToWriter(this, writer);\n"
" return writer.getResultBuffer();\n"
"};\n"
"\n"
"\n"
"/**\n"
- " * Serializes the message to binary data (in protobuf wire format),\n"
- " * writing to the given BinaryWriter.\n"
+ " * Serializes the given message to binary data (in protobuf wire\n"
+ " * format), writing to the given BinaryWriter.\n"
+ " * @param {!$class$} message\n"
" * @param {!jspb.BinaryWriter} writer\n"
" */\n"
- "$class$.prototype.serializeBinaryToWriter = function (writer) {\n"
+ "$class$.serializeBinaryToWriter = function(message, "
+ "writer) {\n"
" var f = undefined;\n",
"class", GetPath(options, desc));
for (int i = 0; i < desc->field_count(); i++) {
- GenerateClassSerializeBinaryField(options, printer, desc->field(i));
+ if (!IgnoreField(desc->field(i))) {
+ GenerateClassSerializeBinaryField(options, printer, desc->field(i));
+ }
}
if (IsExtendable(desc)) {
printer->Print(
- " jspb.Message.serializeBinaryExtensions(this, writer,\n"
+ " jspb.Message.serializeBinaryExtensions(message, writer,\n"
" $extobj$Binary, $class$.prototype.getExtension);\n",
"extobj", JSExtensionsObjectName(options, desc->file(), desc),
"class", GetPath(options, desc));
@@ -2757,30 +2967,37 @@ 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(message, $index$));\n",
+ "index", JSFieldIndex(field),
+ "type", typed_annotation);
} else {
printer->Print(
- " f = this.get$name$($nolazy$);\n",
+ " f = message.get$name$($nolazy$);\n",
"name", JSGetterName(options, field, BYTES_U8),
// No lazy creation for maps containers -- fastpath the empty case.
- "nolazy", (field->is_map()) ? "true" : "");
+ "nolazy", IsMap(options, field) ? "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 +3037,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 +3062,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 +3124,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(
@@ -2927,35 +3144,30 @@ void Generator::GenerateExtension(const GeneratorOptions& options,
string("null")),
"repeated", (field->is_repeated() ? "1" : "0"));
- if (options.binary) {
- printer->Print(
- "\n"
- "$extendName$Binary[$index$] = new jspb.ExtensionFieldBinaryInfo(\n"
- " $class$.$name$,\n"
- " $binaryReaderFn$,\n"
- " $binaryWriterFn$,\n"
- " $binaryMessageSerializeFn$,\n"
- " $binaryMessageDeserializeFn$,\n",
- "extendName", JSExtensionsObjectName(options, field->file(),
- field->containing_type()),
- "index", SimpleItoa(field->number()),
- "class", extension_scope,
- "name", JSObjectFieldName(options, field),
- "binaryReaderFn", JSBinaryReaderMethodName(options, field),
- "binaryWriterFn", JSBinaryWriterMethodName(options, field),
- "binaryMessageSerializeFn",
- (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) ?
- (SubmessageTypeRef(options, field) +
- ".serializeBinaryToWriter") : "null",
- "binaryMessageDeserializeFn",
- (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) ?
- (SubmessageTypeRef(options, field) +
- ".deserializeBinaryFromReader") : "null");
-
- printer->Print(
- " $isPacked$);\n",
- "isPacked", (field->is_packed() ? "true" : "false"));
- }
+ printer->Print(
+ "\n"
+ "$extendName$Binary[$index$] = new jspb.ExtensionFieldBinaryInfo(\n"
+ " $class$.$name$,\n"
+ " $binaryReaderFn$,\n"
+ " $binaryWriterFn$,\n"
+ " $binaryMessageSerializeFn$,\n"
+ " $binaryMessageDeserializeFn$,\n",
+ "extendName",
+ JSExtensionsObjectName(options, field->file(), field->containing_type()),
+ "index", SimpleItoa(field->number()), "class", extension_scope, "name",
+ JSObjectFieldName(options, field), "binaryReaderFn",
+ JSBinaryReaderMethodName(options, field), "binaryWriterFn",
+ JSBinaryWriterMethodName(options, field), "binaryMessageSerializeFn",
+ (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE)
+ ? (SubmessageTypeRef(options, field) + ".serializeBinaryToWriter")
+ : "undefined",
+ "binaryMessageDeserializeFn",
+ (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE)
+ ? (SubmessageTypeRef(options, field) + ".deserializeBinaryFromReader")
+ : "undefined");
+
+ printer->Print(" $isPacked$);\n", "isPacked",
+ (field->is_packed() ? "true" : "false"));
printer->Print(
"// This registers the extension field with the extended class, so that\n"
@@ -2970,7 +3182,7 @@ void Generator::GenerateExtension(const GeneratorOptions& options,
}
bool GeneratorOptions::ParseFromOptions(
- const vector< pair< string, string > >& options,
+ const std::vector< std::pair< string, string > >& options,
string* error) {
for (int i = 0; i < options.size(); i++) {
if (options[i].first == "add_require_for_enums") {
@@ -3005,17 +3217,25 @@ 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 {
// Assume any other option is an output directory, as long as it is a bare
// `key` rather than a `key=value` option.
@@ -3027,18 +3247,40 @@ 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 || extension != ".js" ||
+ one_output_file_per_input_file)) {
+ *error =
+ "The add_require_for_enums, testonly, library, error_on_name_conflict, "
+ "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,
- const vector<const FileDescriptor*>& files) const {
+ const std::vector<const FileDescriptor*>& files) const {
// Build a std::set over all files so that the DFS can detect when it recurses
// into a dep not specified in the user's command line.
std::set<const FileDescriptor*> all_files(files.begin(), files.end());
@@ -3081,7 +3323,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,52 +3333,61 @@ 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<string> 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.
+ std::set<string> provided;
+ std::set<const FieldDescriptor*> 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<string>::iterator it = provided.begin();
- it != provided.end(); ++it) {
- printer->Print("goog.exportSymbol('$name$', null, global);\n",
- "name", *it);
+ GenerateProvides(options, printer, &provided);
+ std::vector<const FileDescriptor*> 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 (std::set<const FieldDescriptor*>::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));
}
+
+ // Emit well-known type methods.
+ for (FileToc* toc = well_known_types_js; toc->name != NULL; toc++) {
+ string name = string("google/protobuf/") + toc->name;
+ if (name == StripProto(file->name()) + ".js") {
+ printer->Print(toc->data);
+ }
+ }
}
-bool Generator::GenerateAll(const vector<const FileDescriptor*>& files,
+bool Generator::GenerateAll(const std::vector<const FileDescriptor*>& files,
const string& parameter,
GeneratorContext* context,
string* error) const {
- vector< pair< string, string > > option_pairs;
+ std::vector< std::pair< string, string > > option_pairs;
ParseGeneratorParameter(parameter, &option_pairs);
GeneratorOptions options;
if (!options.ParseFromOptions(option_pairs, error)) {
@@ -3144,22 +3395,17 @@ bool Generator::GenerateAll(const vector<const FileDescriptor*>& 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<io::ZeroCopyOutputStream> output(context->Open(filename));
GOOGLE_CHECK(output.get());
io::Printer printer(output.get(), '$');
// Pull out all extensions -- we need these to generate all
// provides/requires.
- vector<const FieldDescriptor*> extensions;
+ std::vector<const FieldDescriptor*> extensions;
for (int i = 0; i < files.size(); i++) {
for (int j = 0; j < files[i]->extension_count(); j++) {
const FieldDescriptor* extension = files[i]->extension(j);
@@ -3187,8 +3433,8 @@ bool Generator::GenerateAll(const vector<const FileDescriptor*>& files,
if (printer.failed()) {
return false;
}
- } else if (options.import_style == GeneratorOptions::IMPORT_CLOSURE) {
- set<const void*> allowed_set;
+ } else if (options.output_mode() == GeneratorOptions::kOneOutputFilePerType) {
+ std::set<const void*> allowed_set;
if (!GenerateJspbAllowedSet(options, files, &allowed_set, error)) {
return false;
}
@@ -3259,7 +3505,7 @@ bool Generator::GenerateAll(const vector<const FileDescriptor*>& files,
GenerateHeader(options, &printer);
std::set<string> provided;
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
for (int j = 0; j < files[i]->extension_count(); j++) {
if (ShouldGenerateExtension(files[i]->extension(j))) {
@@ -3279,13 +3525,14 @@ bool Generator::GenerateAll(const vector<const FileDescriptor*>& 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<io::ZeroCopyOutputStream> output(context->Open(filename));
GOOGLE_CHECK(output.get());
io::Printer printer(output.get(), '$');
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/js/js_generator.h b/third_party/protobuf/src/google/protobuf/compiler/js/js_generator.h
index 6fd7ca5070..6e932d7f3d 100755
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/js/js_generator.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/js/js_generator.h
@@ -28,12 +28,16 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// Generates JavaScript code for a given .proto file.
+//
#ifndef GOOGLE_PROTOBUF_COMPILER_JS_GENERATOR_H__
#define GOOGLE_PROTOBUF_COMPILER_JS_GENERATOR_H__
#include <string>
#include <set>
+#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/stubs/common.h>
#include <google/protobuf/compiler/code_generator.h>
namespace google {
@@ -51,45 +55,75 @@ 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 <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) {}
+ extension(".js"),
+ one_output_file_per_input_file(false) {}
bool ParseFromOptions(
- const vector< pair< string, string > >& options,
+ const std::vector< std::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 <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;
+ // 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
+// header. If you create your own protocol compiler binary and you want it to
+// support JavaScript output, you can do so by registering an instance of this
+// CodeGenerator with the CommandLineInterface in your main() function.
class LIBPROTOC_EXPORT Generator : public CodeGenerator {
public:
Generator() {}
@@ -105,7 +139,7 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator {
virtual bool HasGenerateAll() const { return true; }
- virtual bool GenerateAll(const vector<const FileDescriptor*>& files,
+ virtual bool GenerateAll(const std::vector<const FileDescriptor*>& files,
const string& parameter,
GeneratorContext* context,
string* error) const;
@@ -117,7 +151,7 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator {
// Generate goog.provides() calls.
void FindProvides(const GeneratorOptions& options,
io::Printer* printer,
- const vector<const FileDescriptor*>& file,
+ const std::vector<const FileDescriptor*>& file,
std::set<string>* provided) const;
void FindProvidesForFile(const GeneratorOptions& options,
io::Printer* printer,
@@ -134,7 +168,7 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator {
// For extension fields at file scope.
void FindProvidesForFields(const GeneratorOptions& options,
io::Printer* printer,
- const vector<const FieldDescriptor*>& fields,
+ const std::vector<const FieldDescriptor*>& fields,
std::set<string>* provided) const;
// Print the goog.provides() found by the methods above.
void GenerateProvides(const GeneratorOptions& options,
@@ -146,10 +180,10 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator {
io::Printer* printer) const;
// Generate goog.requires() calls.
- void GenerateRequiresForLibrary(const GeneratorOptions& options,
- io::Printer* printer,
- const vector<const FileDescriptor*>& files,
- std::set<string>* provided) const;
+ void GenerateRequiresForLibrary(
+ const GeneratorOptions& options, io::Printer* printer,
+ const std::vector<const FileDescriptor*>& files,
+ std::set<string>* provided) const;
void GenerateRequiresForMessage(const GeneratorOptions& options,
io::Printer* printer,
const Descriptor* desc,
@@ -157,15 +191,13 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator {
// For extension fields at file scope.
void GenerateRequiresForExtensions(
const GeneratorOptions& options, io::Printer* printer,
- const vector<const FieldDescriptor*>& fields,
+ const std::vector<const FieldDescriptor*>& fields,
std::set<string>* provided) const;
void GenerateRequiresImpl(const GeneratorOptions& options,
- io::Printer* printer,
- std::set<string>* required,
+ io::Printer* printer, std::set<string>* required,
std::set<string>* forwards,
- std::set<string>* provided,
- bool require_jspb,
- bool require_extension) const;
+ std::set<string>* provided, bool require_jspb,
+ bool require_extension, bool require_map) const;
void FindRequiresForMessage(const GeneratorOptions& options,
const Descriptor* desc,
std::set<string>* required,
@@ -186,9 +218,9 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator {
// Generate definitions for all message classes and enums in all files,
// processing the files in dependence order.
- void GenerateFilesInDepOrder(const GeneratorOptions& options,
- io::Printer* printer,
- const vector<const FileDescriptor*>& file) const;
+ void GenerateFilesInDepOrder(
+ const GeneratorOptions& options, io::Printer* printer,
+ const std::vector<const FileDescriptor*>& file) const;
// Helper for above.
void GenerateFileAndDeps(const GeneratorOptions& options,
io::Printer* printer,
@@ -201,6 +233,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,
@@ -270,6 +307,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/third_party/protobuf/src/google/protobuf/compiler/js/well_known_types/any.js b/third_party/protobuf/src/google/protobuf/compiler/js/well_known_types/any.js
new file mode 100644
index 0000000000..22f18919bc
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/compiler/js/well_known_types/any.js
@@ -0,0 +1,80 @@
+// 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.
+
+/* This code will be inserted into generated code for
+ * google/protobuf/any.proto. */
+
+/**
+ * Returns the type name contained in this instance, if any.
+ * @return {string|undefined}
+ */
+proto.google.protobuf.Any.prototype.getTypeName = function() {
+ return this.getTypeUrl().split('/').pop();
+};
+
+
+/**
+ * Packs the given message instance into this Any.
+ * @param {!Uint8Array} serialized The serialized data to pack.
+ * @param {string} name The type name of this message object.
+ * @param {string=} opt_typeUrlPrefix the type URL prefix.
+ */
+proto.google.protobuf.Any.prototype.pack = function(serialized, name,
+ opt_typeUrlPrefix) {
+ if (!opt_typeUrlPrefix) {
+ opt_typeUrlPrefix = 'type.googleapis.com/';
+ }
+
+ if (opt_typeUrlPrefix.substr(-1) != '/') {
+ this.setTypeUrl(opt_typeUrlPrefix + '/' + name);
+ } else {
+ this.setTypeUrl(opt_typeUrlPrefix + name);
+ }
+
+ this.setValue(serialized);
+};
+
+
+/**
+ * @template T
+ * Unpacks this Any into the given message object.
+ * @param {function(Uint8Array):T} deserialize Function that will deserialize
+ * the binary data properly.
+ * @param {string} name The expected type name of this message object.
+ * @return {?T} If the name matched the expected name, returns the deserialized
+ * object, otherwise returns undefined.
+ */
+proto.google.protobuf.Any.prototype.unpack = function(deserialize, name) {
+ if (this.getTypeName() == name) {
+ return deserialize(this.getValue_asU8());
+ } else {
+ return null;
+ }
+};
diff --git a/third_party/protobuf/src/google/protobuf/compiler/js/well_known_types/struct.js b/third_party/protobuf/src/google/protobuf/compiler/js/well_known_types/struct.js
new file mode 100644
index 0000000000..30e3d02a6b
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/compiler/js/well_known_types/struct.js
@@ -0,0 +1,168 @@
+// 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.
+
+/* This code will be inserted into generated code for
+ * google/protobuf/struct.proto. */
+
+/**
+ * Typedef representing plain JavaScript values that can go into a
+ * Struct.
+ * @typedef {null|number|string|boolean|Array|Object}
+ */
+proto.google.protobuf.JavaScriptValue;
+
+
+/**
+ * Converts this Value object to a plain JavaScript value.
+ * @return {?proto.google.protobuf.JavaScriptValue} a plain JavaScript
+ * value representing this Struct.
+ */
+proto.google.protobuf.Value.prototype.toJavaScript = function() {
+ var kindCase = proto.google.protobuf.Value.KindCase;
+ switch (this.getKindCase()) {
+ case kindCase.NULL_VALUE:
+ return null;
+ case kindCase.NUMBER_VALUE:
+ return this.getNumberValue();
+ case kindCase.STRING_VALUE:
+ return this.getStringValue();
+ case kindCase.BOOL_VALUE:
+ return this.getBoolValue();
+ case kindCase.STRUCT_VALUE:
+ return this.getStructValue().toJavaScript();
+ case kindCase.LIST_VALUE:
+ return this.getListValue().toJavaScript();
+ default:
+ throw new Error('Unexpected struct type');
+ }
+};
+
+
+/**
+ * Converts this JavaScript value to a new Value proto.
+ * @param {!proto.google.protobuf.JavaScriptValue} value The value to
+ * convert.
+ * @return {!proto.google.protobuf.Value} The newly constructed value.
+ */
+proto.google.protobuf.Value.fromJavaScript = function(value) {
+ var ret = new proto.google.protobuf.Value();
+ switch (goog.typeOf(value)) {
+ case 'string':
+ ret.setStringValue(/** @type {string} */ (value));
+ break;
+ case 'number':
+ ret.setNumberValue(/** @type {number} */ (value));
+ break;
+ case 'boolean':
+ ret.setBoolValue(/** @type {boolean} */ (value));
+ break;
+ case 'null':
+ ret.setNullValue(proto.google.protobuf.NullValue.NULL_VALUE);
+ break;
+ case 'array':
+ ret.setListValue(proto.google.protobuf.ListValue.fromJavaScript(
+ /** @type{!Array} */ (value)));
+ break;
+ case 'object':
+ ret.setStructValue(proto.google.protobuf.Struct.fromJavaScript(
+ /** @type{!Object} */ (value)));
+ break;
+ default:
+ throw new Error('Unexpected struct type.');
+ }
+
+ return ret;
+};
+
+
+/**
+ * Converts this ListValue object to a plain JavaScript array.
+ * @return {!Array} a plain JavaScript array representing this List.
+ */
+proto.google.protobuf.ListValue.prototype.toJavaScript = function() {
+ var ret = [];
+ var values = this.getValuesList();
+
+ for (var i = 0; i < values.length; i++) {
+ ret[i] = values[i].toJavaScript();
+ }
+
+ return ret;
+};
+
+
+/**
+ * Constructs a ListValue protobuf from this plain JavaScript array.
+ * @param {!Array} array a plain JavaScript array
+ * @return {proto.google.protobuf.ListValue} a new ListValue object
+ */
+proto.google.protobuf.ListValue.fromJavaScript = function(array) {
+ var ret = new proto.google.protobuf.ListValue();
+
+ for (var i = 0; i < array.length; i++) {
+ ret.addValues(proto.google.protobuf.Value.fromJavaScript(array[i]));
+ }
+
+ return ret;
+};
+
+
+/**
+ * Converts this Struct object to a plain JavaScript object.
+ * @return {!Object<string, !proto.google.protobuf.JavaScriptValue>} a plain
+ * JavaScript object representing this Struct.
+ */
+proto.google.protobuf.Struct.prototype.toJavaScript = function() {
+ var ret = {};
+
+ this.getFieldsMap().forEach(function(value, key) {
+ ret[key] = value.toJavaScript();
+ });
+
+ return ret;
+};
+
+
+/**
+ * Constructs a Struct protobuf from this plain JavaScript object.
+ * @param {!Object} obj a plain JavaScript object
+ * @return {proto.google.protobuf.Struct} a new Struct object
+ */
+proto.google.protobuf.Struct.fromJavaScript = function(obj) {
+ var ret = new proto.google.protobuf.Struct();
+ var map = ret.getFieldsMap();
+
+ for (var property in obj) {
+ var val = obj[property];
+ map.set(property, proto.google.protobuf.Value.fromJavaScript(val));
+ }
+
+ return ret;
+};
diff --git a/third_party/protobuf/src/google/protobuf/compiler/js/well_known_types/timestamp.js b/third_party/protobuf/src/google/protobuf/compiler/js/well_known_types/timestamp.js
new file mode 100644
index 0000000000..77c07bb4e1
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/compiler/js/well_known_types/timestamp.js
@@ -0,0 +1,54 @@
+// 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.
+
+/* This code will be inserted into generated code for
+ * google/protobuf/timestamp.proto. */
+
+/**
+ * Returns a JavaScript 'Date' object corresponding to this Timestamp.
+ * @return {!Date}
+ */
+proto.google.protobuf.Timestamp.prototype.toDate = function() {
+ var seconds = this.getSeconds();
+ var nanos = this.getNanos();
+
+ return new Date((seconds * 1000) + (nanos / 1000000));
+};
+
+
+/**
+ * Sets the value of this Timestamp object to be the given Date.
+ * @param {!Date} value The value to set.
+ */
+proto.google.protobuf.Timestamp.prototype.fromDate = function(value) {
+ var millis = value.getTime();
+ this.setSeconds(Math.floor(value.getTime() / 1000));
+ this.setNanos(value.getMilliseconds() * 1000000);
+};
diff --git a/third_party/protobuf/src/google/protobuf/compiler/js/well_known_types_embed.h b/third_party/protobuf/src/google/protobuf/compiler/js/well_known_types_embed.h
new file mode 100644
index 0000000000..174c665e45
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/compiler/js/well_known_types_embed.h
@@ -0,0 +1,43 @@
+// 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_COMPILER_JS_WELL_KNOWN_TYPES_EMBED_H__
+#define GOOGLE_PROTOBUF_COMPILER_JS_WELL_KNOWN_TYPES_EMBED_H__
+
+#include <stddef.h>
+
+struct FileToc {
+ const char* name;
+ const char* data;
+};
+
+extern struct FileToc well_known_types_js[];
+
+#endif // GOOGLE_PROTOBUF_COMPILER_JS_WELL_KNOWN_TYPES_EMBED_H__
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/main.cc b/third_party/protobuf/src/google/protobuf/compiler/main.cc
index 2f3c5b8f94..680d642857 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/main.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/main.cc
@@ -32,15 +32,20 @@
#include <google/protobuf/compiler/command_line_interface.h>
#include <google/protobuf/compiler/cpp/cpp_generator.h>
+
+#ifndef OPENSOURCE_PROTOBUF_CPP_BOOTSTRAP
#include <google/protobuf/compiler/python/python_generator.h>
#include <google/protobuf/compiler/java/java_generator.h>
-#include <google/protobuf/compiler/javanano/javanano_generator.h>
-// TODO(teboring): Add it back when php implementation is ready
-// #include <google/protobuf/compiler/php/php_generator.h>
-#include <google/protobuf/compiler/ruby/ruby_generator.h>
+#endif // ! OPENSOURCE_PROTOBUF_CPP_BOOTSTRAP
+
+#ifndef OPENSOURCE_PROTOBUF_CPP_BOOTSTRAP
#include <google/protobuf/compiler/csharp/csharp_generator.h>
-#include <google/protobuf/compiler/objectivec/objectivec_generator.h>
+#include <google/protobuf/compiler/javanano/javanano_generator.h>
#include <google/protobuf/compiler/js/js_generator.h>
+#include <google/protobuf/compiler/objectivec/objectivec_generator.h>
+#include <google/protobuf/compiler/php/php_generator.h>
+#include <google/protobuf/compiler/ruby/ruby_generator.h>
+#endif // ! OPENSOURCE_PROTOBUF_CPP_BOOTSTRAP
int main(int argc, char* argv[]) {
@@ -52,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,
+ cli.RegisterGenerator("--java_out", "--java_opt", &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,
@@ -68,11 +76,10 @@ int main(int argc, char* argv[]) {
cli.RegisterGenerator("--javanano_out", &javanano_generator,
"Generate Java Nano source file.");
- // TODO(teboring): Add it back when php implementation is ready
// PHP
- // google::protobuf::compiler::php::Generator php_generator;
- // cli.RegisterGenerator("--php_out", &php_generator,
- // "Generate PHP source file.");
+ google::protobuf::compiler::php::Generator php_generator;
+ cli.RegisterGenerator("--php_out", &php_generator,
+ "Generate PHP source file.");
// Ruby
google::protobuf::compiler::ruby::Generator rb_generator;
@@ -93,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/third_party/protobuf/3.0.0/src/google/protobuf/compiler/mock_code_generator.cc b/third_party/protobuf/src/google/protobuf/compiler/mock_code_generator.cc
index 82bb342747..a4b522cec3 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/mock_code_generator.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/mock_code_generator.cc
@@ -53,15 +53,23 @@
#include <google/protobuf/stubs/substitute.h>
#include <gtest/gtest.h>
+#ifdef major
+#undef major
+#endif
+#ifdef minor
+#undef minor
+#endif
+#include <google/protobuf/compiler/plugin.pb.h>
+
namespace google {
namespace protobuf {
namespace compiler {
// Returns the list of the names of files in all_files in the form of a
// comma-separated string.
-string CommaSeparatedList(const vector<const FileDescriptor*> all_files) {
- vector<string> names;
- for (int i = 0; i < all_files.size(); i++) {
+string CommaSeparatedList(const std::vector<const FileDescriptor*> all_files) {
+ std::vector<string> names;
+ for (size_t i = 0; i < all_files.size(); i++) {
names.push_back(all_files[i]->name());
}
return Join(names, ",");
@@ -92,16 +100,17 @@ void MockCodeGenerator::ExpectGenerated(
File::GetContents(output_directory + "/" + GetOutputFileName(name, file),
&content, true));
- vector<string> lines = Split(content, "\n", true);
+ std::vector<string> lines =
+ Split(content, "\n", true);
while (!lines.empty() && lines.back().empty()) {
lines.pop_back();
}
- for (int i = 0; i < lines.size(); i++) {
+ for (size_t i = 0; i < lines.size(); i++) {
lines[i] += "\n";
}
- vector<string> insertion_list;
+ std::vector<string> insertion_list;
if (!insertions.empty()) {
SplitStringUsing(insertions, ",", &insertion_list);
}
@@ -114,7 +123,7 @@ void MockCodeGenerator::ExpectGenerated(
EXPECT_EQ(kFirstInsertionPoint, lines[1 + insertion_list.size()]);
EXPECT_EQ(kSecondInsertionPoint, lines[2 + insertion_list.size() * 2]);
- for (int i = 0; i < insertion_list.size(); i++) {
+ for (size_t i = 0; i < insertion_list.size(); i++) {
EXPECT_EQ(GetOutputFileContent(insertion_list[i], "first_insert",
file, file, first_message_name),
lines[1 + i]);
@@ -159,6 +168,15 @@ bool MockCodeGenerator::Generate(
std::cerr << "Saw json_name: "
<< field_descriptor_proto.has_json_name() << std::endl;
abort();
+ } else if (command == "ShowVersionNumber") {
+ Version compiler_version;
+ context->GetCompilerVersion(&compiler_version);
+ std::cerr << "Saw compiler_version: "
+ << compiler_version.major() * 1000000 +
+ compiler_version.minor() * 1000 +
+ compiler_version.patch()
+ << " " << compiler_version.suffix() << std::endl;
+ abort();
} else {
GOOGLE_LOG(FATAL) << "Unknown MockCodeGenerator command: " << command;
}
@@ -166,11 +184,11 @@ bool MockCodeGenerator::Generate(
}
if (HasPrefixString(parameter, "insert=")) {
- vector<string> insert_into;
+ std::vector<string> insert_into;
SplitStringUsing(StripPrefixString(parameter, "insert="),
",", &insert_into);
- for (int i = 0; i < insert_into.size(); i++) {
+ for (size_t i = 0; i < insert_into.size(); i++) {
{
google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> output(context->OpenForInsert(
GetOutputFileName(insert_into[i], file), kFirstInsertionPointName));
@@ -230,7 +248,7 @@ string MockCodeGenerator::GetOutputFileContent(
const string& parameter,
const FileDescriptor* file,
GeneratorContext *context) {
- vector<const FileDescriptor*> all_files;
+ std::vector<const FileDescriptor*> all_files;
context->ListParsedFiles(&all_files);
return GetOutputFileContent(
generator_name, parameter, file->name(),
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/mock_code_generator.h b/third_party/protobuf/src/google/protobuf/compiler/mock_code_generator.h
index e1665f88ce..e1665f88ce 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/mock_code_generator.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/mock_code_generator.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_enum.cc b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum.cc
index e76f8e9915..02d60b3e97 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_enum.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum.cc
@@ -62,7 +62,7 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) {
string enum_comments;
SourceLocation location;
if (descriptor_->GetSourceLocation(&location)) {
- enum_comments = BuildCommentsString(location);
+ enum_comments = BuildCommentsString(location, true);
} else {
enum_comments = "";
}
@@ -74,23 +74,25 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) {
printer->Print("$comments$typedef$deprecated_attribute$ GPB_ENUM($name$) {\n",
"comments", enum_comments,
- "deprecated_attribute", GetOptionalDeprecatedAttribute(descriptor_),
+ "deprecated_attribute", GetOptionalDeprecatedAttribute(descriptor_, descriptor_->file()),
"name", name_);
printer->Indent();
if (HasPreservingUnknownEnumSemantics(descriptor_->file())) {
// Include the unknown value.
printer->Print(
- "/// Value used if any message's field encounters a value that is not defined\n"
- "/// by this enum. The message will also have C functions to get/set the rawValue\n"
- "/// of the field.\n"
+ "/**\n"
+ " * Value used if any message's field encounters a value that is not defined\n"
+ " * by this enum. The message will also have C functions to get/set the rawValue\n"
+ " * of the field.\n"
+ " **/\n"
"$name$_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue,\n",
"name", name_);
}
for (int i = 0; i < all_values_.size(); i++) {
SourceLocation location;
if (all_values_[i]->GetSourceLocation(&location)) {
- string comments = BuildCommentsString(location).c_str();
+ string comments = BuildCommentsString(location, true).c_str();
if (comments.length() > 0) {
if (i > 0) {
printer->Print("\n");
@@ -111,8 +113,10 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) {
"\n"
"GPBEnumDescriptor *$name$_EnumDescriptor(void);\n"
"\n"
- "/// Checks to see if the given value is defined by the enum or was not known at\n"
- "/// the time this source was generated.\n"
+ "/**\n"
+ " * Checks to see if the given value is defined by the enum or was not known at\n"
+ " * the time this source was generated.\n"
+ " **/\n"
"BOOL $name$_IsValidValue(int32_t value);\n"
"\n",
"name", name_);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_enum.h b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum.h
index 0b41cf7352..0b41cf7352 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_enum.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc
index b63bc0de63..7a774a0922 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc
@@ -83,12 +83,16 @@ void EnumFieldGenerator::GenerateCFunctionDeclarations(
printer->Print(
variables_,
- "/// Fetches the raw value of a @c $owning_message_class$'s @c $name$ property, even\n"
- "/// if the value was not defined by the enum at the time the code was generated.\n"
+ "/**\n"
+ " * Fetches the raw value of a @c $owning_message_class$'s @c $name$ property, even\n"
+ " * if the value was not defined by the enum at the time the code was generated.\n"
+ " **/\n"
"int32_t $owning_message_class$_$capitalized_name$_RawValue($owning_message_class$ *message);\n"
- "/// Sets the raw value of an @c $owning_message_class$'s @c $name$ property, allowing\n"
- "/// it to be set to a value that was not defined by the enum at the time the code\n"
- "/// was generated.\n"
+ "/**\n"
+ " * Sets the raw value of an @c $owning_message_class$'s @c $name$ property, allowing\n"
+ " * it to be set to a value that was not defined by the enum at the time the code\n"
+ " * was generated.\n"
+ " **/\n"
"void Set$owning_message_class$_$capitalized_name$_RawValue($owning_message_class$ *message, int32_t value);\n"
"\n");
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h
index 946faa819a..946faa819a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_enum_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_extension.cc b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_extension.cc
index 3f7ab9d392..7073173c88 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_extension.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_extension.cc
@@ -63,13 +63,16 @@ void ExtensionGenerator::GenerateMembersHeader(io::Printer* printer) {
vars["method_name"] = method_name_;
SourceLocation location;
if (descriptor_->GetSourceLocation(&location)) {
- vars["comments"] = BuildCommentsString(location);
+ vars["comments"] = BuildCommentsString(location, true);
} else {
vars["comments"] = "";
}
+ // Unlike normal message fields, check if the file for the extension was
+ // deprecated.
+ vars["deprecated_attribute"] = GetOptionalDeprecatedAttribute(descriptor_, descriptor_->file());
printer->Print(vars,
"$comments$"
- "+ (GPBExtensionDescriptor *)$method_name$;\n");
+ "+ (GPBExtensionDescriptor *)$method_name$$deprecated_attribute$;\n");
}
void ExtensionGenerator::GenerateStaticVariablesInitialization(
@@ -85,7 +88,7 @@ void ExtensionGenerator::GenerateStaticVariablesInitialization(
if (descriptor_->containing_type()->options().message_set_wire_format())
options.push_back("GPBExtensionSetWireFormat");
- vars["options"] = BuildFlagsString(options);
+ vars["options"] = BuildFlagsString(FLAGTYPE_EXTENSION, options);
ObjectiveCType objc_type = GetObjectiveCType(descriptor_);
string singular_type;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_extension.h b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_extension.h
index e361e639bd..e361e639bd 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_extension.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_extension.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_field.cc b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc
index 812b4a1c13..527b7c0c70 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.cc
@@ -64,7 +64,7 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
SourceLocation location;
if (descriptor->GetSourceLocation(&location)) {
- (*variables)["comments"] = BuildCommentsString(location);
+ (*variables)["comments"] = BuildCommentsString(location, true);
} else {
(*variables)["comments"] = "\n";
}
@@ -93,7 +93,7 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor,
field_flags.push_back("GPBFieldHasEnumDescriptor");
}
- (*variables)["fieldflags"] = BuildFlagsString(field_flags);
+ (*variables)["fieldflags"] = BuildFlagsString(FLAGTYPE_FIELD, field_flags);
(*variables)["default"] = DefaultValue(descriptor);
(*variables)["default_name"] = GPBGenericValueFieldName(descriptor);
@@ -335,7 +335,7 @@ void ObjCObjFieldGenerator::GeneratePropertyDeclaration(
if (WantsHasProperty()) {
printer->Print(
variables_,
- "/// Test to see if @c $name$ has been set.\n"
+ "/** Test to see if @c $name$ has been set. */\n"
"@property(nonatomic, readwrite) BOOL has$capitalized_name$$deprecated_attribute$;\n");
}
if (IsInitName(variables_.find("name")->second)) {
@@ -387,7 +387,7 @@ void RepeatedFieldGenerator::GeneratePropertyDeclaration(
"$comments$"
"$array_comment$"
"@property(nonatomic, readwrite, strong, null_resettable) $array_property_type$ *$name$$storage_attribute$$deprecated_attribute$;\n"
- "/// The number of items in @c $name$ without causing the array to be created.\n"
+ "/** The number of items in @c $name$ without causing the array to be created. */\n"
"@property(nonatomic, readonly) NSUInteger $name$_Count$deprecated_attribute$;\n");
if (IsInitName(variables_.find("name")->second)) {
// If property name starts with init we need to annotate it to get past ARC.
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_field.h b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h
index a3a4b1b6e2..a3a4b1b6e2 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_file.cc b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_file.cc
index b864ef129e..7ad127bb3b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_file.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_file.cc
@@ -37,6 +37,7 @@
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/stubs/stl_util.h>
#include <google/protobuf/stubs/strutil.h>
+#include <algorithm> // std::find()
#include <iostream>
#include <sstream>
@@ -45,218 +46,120 @@
namespace google {
namespace protobuf {
-
-// This is also found in GPBBootstrap.h, and needs to be kept in sync. It
-// is the version check done to ensure generated code works with the current
-// runtime being used.
-const int32 GOOGLE_PROTOBUF_OBJC_GEN_VERSION = 30001;
-
namespace compiler {
namespace objectivec {
namespace {
-class ImportWriter {
- public:
- ImportWriter(const Options& options)
- : options_(options),
- need_to_parse_mapping_file_(true) {}
-
- void AddFile(const FileGenerator* file);
- void Print(io::Printer *printer) const;
-
- private:
- class ProtoFrameworkCollector : public LineConsumer {
- public:
- ProtoFrameworkCollector(map<string, string>* inout_proto_file_to_framework_name)
- : map_(inout_proto_file_to_framework_name) {}
-
- virtual bool ConsumeLine(const StringPiece& line, string* out_error);
-
- private:
- map<string, string>* map_;
- };
+// This is also found in GPBBootstrap.h, and needs to be kept in sync.
+const int32 GOOGLE_PROTOBUF_OBJC_VERSION = 30002;
- void ParseFrameworkMappings();
+const char* kHeaderExtension = ".pbobjc.h";
- const Options options_;
- map<string, string> proto_file_to_framework_name_;
- bool need_to_parse_mapping_file_;
-
- vector<string> protobuf_framework_imports_;
- vector<string> protobuf_non_framework_imports_;
- vector<string> other_framework_imports_;
- vector<string> other_imports_;
-};
-
-void ImportWriter::AddFile(const FileGenerator* file) {
- const FileDescriptor* file_descriptor = file->Descriptor();
- const string extension(".pbobjc.h");
-
- if (IsProtobufLibraryBundledProtoFile(file_descriptor)) {
- protobuf_framework_imports_.push_back(
- FilePathBasename(file_descriptor) + extension);
- protobuf_non_framework_imports_.push_back(file->Path() + extension);
- return;
+// Checks if a message contains any extension definitions (on the message or
+// a nested message under it).
+bool MessageContainsExtensions(const Descriptor* message) {
+ if (message->extension_count() > 0) {
+ return true;
}
-
- // Lazy parse any mappings.
- if (need_to_parse_mapping_file_) {
- ParseFrameworkMappings();
+ for (int i = 0; i < message->nested_type_count(); i++) {
+ if (MessageContainsExtensions(message->nested_type(i))) {
+ return true;
+ }
}
+ return false;
+}
- map<string, string>::iterator proto_lookup =
- proto_file_to_framework_name_.find(file_descriptor->name());
- if (proto_lookup != proto_file_to_framework_name_.end()) {
- other_framework_imports_.push_back(
- proto_lookup->second + "/" +
- FilePathBasename(file_descriptor) + extension);
- return;
+// Checks if the file contains any extensions definitions (at the root or
+// nested under a message).
+bool FileContainsExtensions(const FileDescriptor* file) {
+ if (file->extension_count() > 0) {
+ return true;
}
-
- if (!options_.generate_for_named_framework.empty()) {
- other_framework_imports_.push_back(
- options_.generate_for_named_framework + "/" +
- FilePathBasename(file_descriptor) + extension);
- return;
+ for (int i = 0; i < file->message_type_count(); i++) {
+ if (MessageContainsExtensions(file->message_type(i))) {
+ return true;
+ }
}
-
- other_imports_.push_back(file->Path() + extension);
+ return false;
}
-void ImportWriter::Print(io::Printer* printer) const {
- assert(protobuf_non_framework_imports_.size() ==
- protobuf_framework_imports_.size());
-
- bool add_blank_line = false;
-
- if (protobuf_framework_imports_.size() > 0) {
- const string framework_name(ProtobufLibraryFrameworkName);
- const string cpp_symbol(ProtobufFrameworkImportSymbol(framework_name));
-
- printer->Print(
- "#if $cpp_symbol$\n",
- "cpp_symbol", cpp_symbol);
- for (vector<string>::const_iterator iter = protobuf_framework_imports_.begin();
- iter != protobuf_framework_imports_.end(); ++iter) {
- printer->Print(
- " #import <$framework_name$/$header$>\n",
- "framework_name", framework_name,
- "header", *iter);
- }
- printer->Print(
- "#else\n");
- for (vector<string>::const_iterator iter = protobuf_non_framework_imports_.begin();
- iter != protobuf_non_framework_imports_.end(); ++iter) {
- printer->Print(
- " #import \"$header$\"\n",
- "header", *iter);
- }
- printer->Print(
- "#endif\n");
-
- add_blank_line = true;
+// Helper for CollectMinimalFileDepsContainingExtensionsWorker that marks all
+// deps as visited and prunes them from the needed files list.
+void PruneFileAndDepsMarkingAsVisited(
+ const FileDescriptor* file,
+ vector<const FileDescriptor*>* files,
+ set<const FileDescriptor*>* files_visited) {
+ vector<const FileDescriptor*>::iterator iter =
+ std::find(files->begin(), files->end(), file);
+ if (iter != files->end()) {
+ files->erase(iter);
}
+ files_visited->insert(file);
+ for (int i = 0; i < file->dependency_count(); i++) {
+ PruneFileAndDepsMarkingAsVisited(file->dependency(i), files, files_visited);
+ }
+}
- if (other_framework_imports_.size() > 0) {
- if (add_blank_line) {
- printer->Print("\n");
- }
-
- for (vector<string>::const_iterator iter = other_framework_imports_.begin();
- iter != other_framework_imports_.end(); ++iter) {
- printer->Print(
- " #import <$header$>\n",
- "header", *iter);
- }
-
- add_blank_line = true;
+// Helper for CollectMinimalFileDepsContainingExtensions.
+void CollectMinimalFileDepsContainingExtensionsWorker(
+ const FileDescriptor* file,
+ vector<const FileDescriptor*>* files,
+ set<const FileDescriptor*>* files_visited) {
+ if (files_visited->find(file) != files_visited->end()) {
+ return;
}
+ files_visited->insert(file);
- if (other_imports_.size() > 0) {
- if (add_blank_line) {
- printer->Print("\n");
+ if (FileContainsExtensions(file)) {
+ files->push_back(file);
+ for (int i = 0; i < file->dependency_count(); i++) {
+ const FileDescriptor* dep = file->dependency(i);
+ PruneFileAndDepsMarkingAsVisited(dep, files, files_visited);
}
-
- for (vector<string>::const_iterator iter = other_imports_.begin();
- iter != other_imports_.end(); ++iter) {
- printer->Print(
- " #import \"$header$\"\n",
- "header", *iter);
+ } else {
+ for (int i = 0; i < file->dependency_count(); i++) {
+ const FileDescriptor* dep = file->dependency(i);
+ CollectMinimalFileDepsContainingExtensionsWorker(dep, files,
+ files_visited);
}
}
}
-void ImportWriter::ParseFrameworkMappings() {
- need_to_parse_mapping_file_ = false;
- if (options_.named_framework_to_proto_path_mappings_path.empty()) {
- return; // Nothing to do.
- }
-
- ProtoFrameworkCollector collector(&proto_file_to_framework_name_);
- string parse_error;
- if (!ParseSimpleFile(options_.named_framework_to_proto_path_mappings_path,
- &collector, &parse_error)) {
- cerr << "error parsing " << options_.named_framework_to_proto_path_mappings_path
- << " : " << parse_error << endl;
- cerr.flush();
+// Collect the deps of the given file that contain extensions. This can be used to
+// create the chain of roots that need to be wired together.
+//
+// NOTE: If any changes are made to this and the supporting functions, you will
+// need to manually validate what the generated code is for the test files:
+// objectivec/Tests/unittest_extension_chain_*.proto
+// There are comments about what the expected code should be line and limited
+// testing objectivec/Tests/GPBUnittestProtos2.m around compilation (#imports
+// specifically).
+void CollectMinimalFileDepsContainingExtensions(
+ const FileDescriptor* file,
+ vector<const FileDescriptor*>* files) {
+ set<const FileDescriptor*> files_visited;
+ for (int i = 0; i < file->dependency_count(); i++) {
+ const FileDescriptor* dep = file->dependency(i);
+ CollectMinimalFileDepsContainingExtensionsWorker(dep, files,
+ &files_visited);
}
}
-bool ImportWriter::ProtoFrameworkCollector::ConsumeLine(
- const StringPiece& line, string* out_error) {
- int offset = line.find(':');
- if (offset == StringPiece::npos) {
- *out_error =
- string("Framework/proto file mapping line without colon sign: '") +
- line.ToString() + "'.";
- return false;
- }
- StringPiece framework_name(line, 0, offset);
- StringPiece proto_file_list(line, offset + 1, line.length() - offset - 1);
- StringPieceTrimWhitespace(&framework_name);
-
- int start = 0;
- while (start < proto_file_list.length()) {
- offset = proto_file_list.find(',', start);
- if (offset == StringPiece::npos) {
- offset = proto_file_list.length();
- }
-
- StringPiece proto_file(proto_file_list, start, offset - start);
- StringPieceTrimWhitespace(&proto_file);
- if (proto_file.size() != 0) {
- map<string, string>::iterator existing_entry =
- map_->find(proto_file.ToString());
- if (existing_entry != map_->end()) {
- cerr << "warning: duplicate proto file reference, replacing framework entry for '"
- << proto_file.ToString() << "' with '" << framework_name.ToString()
- << "' (was '" << existing_entry->second << "')." << endl;
- cerr.flush();
- }
-
- if (proto_file.find(' ') != StringPiece::npos) {
- cerr << "note: framework mapping file had a proto file with a space in, hopefully that isn't a missing comma: '"
- << proto_file.ToString() << "'" << endl;
- cerr.flush();
- }
-
- (*map_)[proto_file.ToString()] = framework_name.ToString();
+bool IsDirectDependency(const FileDescriptor* dep, const FileDescriptor* file) {
+ for (int i = 0; i < file->dependency_count(); i++) {
+ if (dep == file->dependency(i)) {
+ return true;
}
-
- start = offset + 1;
}
-
- return true;
+ return false;
}
} // namespace
-
FileGenerator::FileGenerator(const FileDescriptor *file, const Options& options)
: file_(file),
root_class_name_(FileClassName(file)),
- is_public_dep_(false),
options_(options) {
for (int i = 0; i < file_->enum_type_count(); i++) {
EnumGenerator *generator = new EnumGenerator(file_->enum_type(i));
@@ -275,8 +178,6 @@ FileGenerator::FileGenerator(const FileDescriptor *file, const Options& options)
}
FileGenerator::~FileGenerator() {
- STLDeleteContainerPointers(dependency_generators_.begin(),
- dependency_generators_.end());
STLDeleteContainerPointers(enum_generators_.begin(), enum_generators_.end());
STLDeleteContainerPointers(message_generators_.begin(),
message_generators_.end());
@@ -289,24 +190,28 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
// Add some verification that the generated code matches the source the
// code is being compiled with.
+ // NOTE: This captures the raw numeric values at the time the generator was
+ // compiled, since that will be the versions for the ObjC runtime at that
+ // time. The constants in the generated code will then get their values at
+ // at compile time (so checking against the headers being used to compile).
printer->Print(
- "#if GOOGLE_PROTOBUF_OBJC_GEN_VERSION != $protoc_gen_objc_version$\n"
- "#error This file was generated by a different version of protoc which is incompatible with your Protocol Buffer library sources.\n"
+ "#if GOOGLE_PROTOBUF_OBJC_VERSION < $google_protobuf_objc_version$\n"
+ "#error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources.\n"
+ "#endif\n"
+ "#if $google_protobuf_objc_version$ < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION\n"
+ "#error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources.\n"
"#endif\n"
"\n",
- "protoc_gen_objc_version",
- SimpleItoa(GOOGLE_PROTOBUF_OBJC_GEN_VERSION));
+ "google_protobuf_objc_version", SimpleItoa(GOOGLE_PROTOBUF_OBJC_VERSION));
// #import any headers for "public imports" in the proto file.
{
- ImportWriter import_writer(options_);
- const vector<FileGenerator *> &dependency_generators = DependencyGenerators();
- for (vector<FileGenerator *>::const_iterator iter =
- dependency_generators.begin();
- iter != dependency_generators.end(); ++iter) {
- if ((*iter)->IsPublicDependency()) {
- import_writer.AddFile(*iter);
- }
+ ImportWriter import_writer(
+ options_.generate_for_named_framework,
+ options_.named_framework_to_proto_path_mappings_path);
+ const string header_extension(kHeaderExtension);
+ for (int i = 0; i < file_->public_dependency_count(); i++) {
+ import_writer.AddFile(file_->public_dependency(i), header_extension);
}
import_writer.Print(printer);
}
@@ -357,14 +262,16 @@ void FileGenerator::GenerateHeader(io::Printer *printer) {
printer->Print(
"#pragma mark - $root_class_name$\n"
"\n"
- "/// Exposes the extension registry for this file.\n"
- "///\n"
- "/// The base class provides:\n"
- "/// @code\n"
- "/// + (GPBExtensionRegistry *)extensionRegistry;\n"
- "/// @endcode\n"
- "/// which is a @c GPBExtensionRegistry that includes all the extensions defined by\n"
- "/// this file and all files that it depends on.\n"
+ "/**\n"
+ " * Exposes the extension registry for this file.\n"
+ " *\n"
+ " * The base class provides:\n"
+ " * @code\n"
+ " * + (GPBExtensionRegistry *)extensionRegistry;\n"
+ " * @endcode\n"
+ " * which is a @c GPBExtensionRegistry that includes all the extensions defined by\n"
+ " * this file and all files that it depends on.\n"
+ " **/\n"
"@interface $root_class_name$ : GPBRootObject\n"
"@end\n"
"\n",
@@ -404,21 +311,41 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
// #import the runtime support.
PrintFileRuntimePreamble(printer, "GPBProtocolBuffers_RuntimeSupport.h");
+ vector<const FileDescriptor*> deps_with_extensions;
+ CollectMinimalFileDepsContainingExtensions(file_, &deps_with_extensions);
+
{
- ImportWriter import_writer(options_);
+ ImportWriter import_writer(
+ options_.generate_for_named_framework,
+ options_.named_framework_to_proto_path_mappings_path);
+ const string header_extension(kHeaderExtension);
// #import the header for this proto file.
- import_writer.AddFile(this);
+ import_writer.AddFile(file_, header_extension);
// #import the headers for anything that a plain dependency of this proto
// file (that means they were just an include, not a "public" include).
- const vector<FileGenerator *> &dependency_generators =
- DependencyGenerators();
- for (vector<FileGenerator *>::const_iterator iter =
- dependency_generators.begin();
- iter != dependency_generators.end(); ++iter) {
- if (!(*iter)->IsPublicDependency()) {
- import_writer.AddFile(*iter);
+ set<string> public_import_names;
+ for (int i = 0; i < file_->public_dependency_count(); i++) {
+ public_import_names.insert(file_->public_dependency(i)->name());
+ }
+ for (int i = 0; i < file_->dependency_count(); i++) {
+ const FileDescriptor *dep = file_->dependency(i);
+ bool public_import = (public_import_names.count(dep->name()) != 0);
+ if (!public_import) {
+ import_writer.AddFile(dep, header_extension);
+ }
+ }
+
+ // If any indirect dependency provided extensions, it needs to be directly
+ // imported so it can get merged into the root's extensions registry.
+ // See the Note by CollectMinimalFileDepsContainingExtensions before
+ // changing this.
+ for (vector<const FileDescriptor *>::iterator iter =
+ deps_with_extensions.begin();
+ iter != deps_with_extensions.end(); ++iter) {
+ if (!IsDirectDependency(*iter, file_)) {
+ import_writer.AddFile(*iter, header_extension);
}
}
@@ -458,46 +385,37 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
"@implementation $root_class_name$\n\n",
"root_class_name", root_class_name_);
- // Generate the extension initialization structures for the top level and
- // any nested messages.
- ostringstream extensions_stringstream;
- if (file_->extension_count() + file_->message_type_count() > 0) {
- io::OstreamOutputStream extensions_outputstream(&extensions_stringstream);
- io::Printer extensions_printer(&extensions_outputstream, '$');
- for (vector<ExtensionGenerator *>::iterator iter =
- extension_generators_.begin();
- iter != extension_generators_.end(); ++iter) {
- (*iter)->GenerateStaticVariablesInitialization(&extensions_printer);
- }
- for (vector<MessageGenerator *>::iterator iter =
- message_generators_.begin();
- iter != message_generators_.end(); ++iter) {
- (*iter)->GenerateStaticVariablesInitialization(&extensions_printer);
- }
- extensions_stringstream.flush();
- }
+ const bool file_contains_extensions = FileContainsExtensions(file_);
// If there were any extensions or this file has any dependencies, output
// a registry to override to create the file specific registry.
- const string& extensions_str = extensions_stringstream.str();
- if (extensions_str.length() > 0 || file_->dependency_count() > 0) {
+ if (file_contains_extensions || !deps_with_extensions.empty()) {
printer->Print(
"+ (GPBExtensionRegistry*)extensionRegistry {\n"
" // This is called by +initialize so there is no need to worry\n"
" // about thread safety and initialization of registry.\n"
" static GPBExtensionRegistry* registry = nil;\n"
" if (!registry) {\n"
- " GPBDebugCheckRuntimeVersion();\n"
+ " GPB_DEBUG_CHECK_RUNTIME_VERSIONS();\n"
" registry = [[GPBExtensionRegistry alloc] init];\n");
printer->Indent();
printer->Indent();
- if (extensions_str.length() > 0) {
+ if (file_contains_extensions) {
printer->Print(
"static GPBExtensionDescription descriptions[] = {\n");
printer->Indent();
- printer->Print(extensions_str.c_str());
+ for (vector<ExtensionGenerator *>::iterator iter =
+ extension_generators_.begin();
+ iter != extension_generators_.end(); ++iter) {
+ (*iter)->GenerateStaticVariablesInitialization(printer);
+ }
+ for (vector<MessageGenerator *>::iterator iter =
+ message_generators_.begin();
+ iter != message_generators_.end(); ++iter) {
+ (*iter)->GenerateStaticVariablesInitialization(printer);
+ }
printer->Outdent();
printer->Print(
"};\n"
@@ -510,14 +428,21 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
"}\n");
}
- const vector<FileGenerator *> &dependency_generators =
- DependencyGenerators();
- for (vector<FileGenerator *>::const_iterator iter =
- dependency_generators.begin();
- iter != dependency_generators.end(); ++iter) {
+ if (deps_with_extensions.empty()) {
+ printer->Print(
+ "// None of the imports (direct or indirect) defined extensions, so no need to add\n"
+ "// them to this registry.\n");
+ } else {
printer->Print(
- "[registry addExtensions:[$dependency$ extensionRegistry]];\n",
- "dependency", (*iter)->RootClassName());
+ "// Merge in the imports (direct or indirect) that defined extensions.\n");
+ for (vector<const FileDescriptor *>::iterator iter =
+ deps_with_extensions.begin();
+ iter != deps_with_extensions.end(); ++iter) {
+ const string root_class_name(FileClassName((*iter)));
+ printer->Print(
+ "[registry addExtensions:[$dependency$ extensionRegistry]];\n",
+ "dependency", root_class_name);
+ }
}
printer->Outdent();
@@ -526,27 +451,39 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
printer->Print(
" }\n"
" return registry;\n"
- "}\n"
- "\n");
+ "}\n");
+ } else {
+ if (file_->dependency_count() > 0) {
+ printer->Print(
+ "// No extensions in the file and none of the imports (direct or indirect)\n"
+ "// defined extensions, so no need to generate +extensionRegistry.\n");
+ } else {
+ printer->Print(
+ "// No extensions in the file and no imports, so no need to generate\n"
+ "// +extensionRegistry.\n");
+ }
}
- printer->Print("@end\n\n");
+ printer->Print("\n@end\n\n");
// File descriptor only needed if there are messages to use it.
if (message_generators_.size() > 0) {
- string syntax;
+ map<string, string> vars;
+ vars["root_class_name"] = root_class_name_;
+ vars["package"] = file_->package();
+ vars["objc_prefix"] = FileClassPrefix(file_);
switch (file_->syntax()) {
case FileDescriptor::SYNTAX_UNKNOWN:
- syntax = "GPBFileSyntaxUnknown";
+ vars["syntax"] = "GPBFileSyntaxUnknown";
break;
case FileDescriptor::SYNTAX_PROTO2:
- syntax = "GPBFileSyntaxProto2";
+ vars["syntax"] = "GPBFileSyntaxProto2";
break;
case FileDescriptor::SYNTAX_PROTO3:
- syntax = "GPBFileSyntaxProto3";
+ vars["syntax"] = "GPBFileSyntaxProto3";
break;
}
- printer->Print(
+ printer->Print(vars,
"#pragma mark - $root_class_name$_FileDescriptor\n"
"\n"
"static GPBFileDescriptor *$root_class_name$_FileDescriptor(void) {\n"
@@ -554,16 +491,24 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
" // about thread safety of the singleton.\n"
" static GPBFileDescriptor *descriptor = NULL;\n"
" if (!descriptor) {\n"
- " GPBDebugCheckRuntimeVersion();\n"
- " descriptor = [[GPBFileDescriptor alloc] initWithPackage:@\"$package$\"\n"
- " syntax:$syntax$];\n"
+ " GPB_DEBUG_CHECK_RUNTIME_VERSIONS();\n");
+ if (vars["objc_prefix"].size() > 0) {
+ printer->Print(
+ vars,
+ " descriptor = [[GPBFileDescriptor alloc] initWithPackage:@\"$package$\"\n"
+ " objcPrefix:@\"$objc_prefix$\"\n"
+ " syntax:$syntax$];\n");
+ } else {
+ printer->Print(
+ vars,
+ " descriptor = [[GPBFileDescriptor alloc] initWithPackage:@\"$package$\"\n"
+ " syntax:$syntax$];\n");
+ }
+ printer->Print(
" }\n"
" return descriptor;\n"
"}\n"
- "\n",
- "root_class_name", root_class_name_,
- "package", file_->package(),
- "syntax", syntax);
+ "\n");
}
for (vector<EnumGenerator *>::iterator iter = enum_generators_.begin();
@@ -582,24 +527,6 @@ void FileGenerator::GenerateSource(io::Printer *printer) {
"// @@protoc_insertion_point(global_scope)\n");
}
-const vector<FileGenerator *> &FileGenerator::DependencyGenerators() {
- if (file_->dependency_count() != dependency_generators_.size()) {
- set<string> public_import_names;
- for (int i = 0; i < file_->public_dependency_count(); i++) {
- public_import_names.insert(file_->public_dependency(i)->name());
- }
- for (int i = 0; i < file_->dependency_count(); i++) {
- FileGenerator *generator =
- new FileGenerator(file_->dependency(i), options_);
- const string& name = file_->dependency(i)->name();
- bool public_import = (public_import_names.count(name) != 0);
- generator->SetIsPublicDependency(public_import);
- dependency_generators_.push_back(generator);
- }
- }
- return dependency_generators_;
-}
-
// Helper to print the import of the runtime support at the top of generated
// files. This currently only supports the runtime coming from a framework
// as defined by the official CocoaPod.
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_file.h b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_file.h
index 8e4388d8d2..a60a6885c0 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_file.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_file.h
@@ -62,32 +62,17 @@ class FileGenerator {
void GenerateHeader(io::Printer* printer);
const string& RootClassName() const { return root_class_name_; }
- const string Path() const { return FilePath(file_); }
- const FileDescriptor* Descriptor() const { return file_; }
-
- bool IsPublicDependency() const { return is_public_dep_; }
-
- protected:
- void SetIsPublicDependency(bool is_public_dep) {
- is_public_dep_ = is_public_dep;
- }
private:
const FileDescriptor* file_;
string root_class_name_;
- // Access this field through the DependencyGenerators accessor call below.
- // Do not reference it directly.
- vector<FileGenerator*> dependency_generators_;
-
vector<EnumGenerator*> enum_generators_;
vector<MessageGenerator*> message_generators_;
vector<ExtensionGenerator*> extension_generators_;
- bool is_public_dep_;
const Options options_;
- const vector<FileGenerator*>& DependencyGenerators();
void PrintFileRuntimePreamble(
io::Printer* printer, const string& header_to_import) const;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_generator.cc b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_generator.cc
index a0b6d6cb6c..3640746798 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_generator.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_generator.cc
@@ -45,10 +45,22 @@ ObjectiveCGenerator::ObjectiveCGenerator() {}
ObjectiveCGenerator::~ObjectiveCGenerator() {}
+bool ObjectiveCGenerator::HasGenerateAll() const {
+ return true;
+}
+
bool ObjectiveCGenerator::Generate(const FileDescriptor* file,
const string& parameter,
- OutputDirectory* output_directory,
+ GeneratorContext* context,
string* error) const {
+ *error = "Unimplemented Generate() method. Call GenerateAll() instead.";
+ return false;
+}
+
+bool ObjectiveCGenerator::GenerateAll(const vector<const FileDescriptor*>& files,
+ const string& parameter,
+ GeneratorContext* context,
+ string* error) const {
// -----------------------------------------------------------------
// Parse generator options. These options are passed to the compiler using the
// --objc_opt flag. The options are passed as a comma separated list of
@@ -117,29 +129,32 @@ bool ObjectiveCGenerator::Generate(const FileDescriptor* file,
// -----------------------------------------------------------------
- // Validate the objc prefix/package pairing.
- if (!ValidateObjCClassPrefix(file, generation_options, error)) {
+ // Validate the objc prefix/package pairings.
+ if (!ValidateObjCClassPrefixes(files, generation_options, error)) {
// *error will have been filled in.
return false;
}
- FileGenerator file_generator(file, generation_options);
- string filepath = FilePath(file);
+ for (int i = 0; i < files.size(); i++) {
+ const FileDescriptor* file = files[i];
+ FileGenerator file_generator(file, generation_options);
+ string filepath = FilePath(file);
- // Generate header.
- {
- scoped_ptr<io::ZeroCopyOutputStream> output(
- output_directory->Open(filepath + ".pbobjc.h"));
- io::Printer printer(output.get(), '$');
- file_generator.GenerateHeader(&printer);
- }
+ // Generate header.
+ {
+ scoped_ptr<io::ZeroCopyOutputStream> output(
+ context->Open(filepath + ".pbobjc.h"));
+ io::Printer printer(output.get(), '$');
+ file_generator.GenerateHeader(&printer);
+ }
- // Generate m file.
- {
- scoped_ptr<io::ZeroCopyOutputStream> output(
- output_directory->Open(filepath + ".pbobjc.m"));
- io::Printer printer(output.get(), '$');
- file_generator.GenerateSource(&printer);
+ // Generate m file.
+ {
+ scoped_ptr<io::ZeroCopyOutputStream> output(
+ context->Open(filepath + ".pbobjc.m"));
+ io::Printer printer(output.get(), '$');
+ file_generator.GenerateSource(&printer);
+ }
}
return true;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_generator.h b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_generator.h
index 09266b042f..b172331861 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_generator.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_generator.h
@@ -41,14 +41,25 @@ namespace protobuf {
namespace compiler {
namespace objectivec {
+// CodeGenerator implementation which generates a ObjectiveC source file and
+// header. If you create your own protocol compiler binary and you want it to
+// support ObjectiveC output, you can do so by registering an instance of this
+// CodeGenerator with the CommandLineInterface in your main() function.
class LIBPROTOC_EXPORT ObjectiveCGenerator : public CodeGenerator {
public:
ObjectiveCGenerator();
~ObjectiveCGenerator();
// implements CodeGenerator ----------------------------------------
- bool Generate(const FileDescriptor* file, const string& parameter,
- OutputDirectory* output_directory, string* error) const;
+ bool HasGenerateAll() const;
+ bool Generate(const FileDescriptor* file,
+ const string& parameter,
+ GeneratorContext* context,
+ string* error) const;
+ bool GenerateAll(const vector<const FileDescriptor*>& files,
+ const string& parameter,
+ GeneratorContext* context,
+ string* error) const;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ObjectiveCGenerator);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
index 055464493d..4bf17d7b6e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
@@ -42,11 +42,12 @@
#include <google/protobuf/stubs/hash.h>
#include <google/protobuf/compiler/objectivec/objectivec_helpers.h>
+#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
-#include <google/protobuf/io/io_win32.h>
-#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/io_win32.h>
#include <google/protobuf/stubs/strutil.h>
// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some
@@ -208,10 +209,14 @@ const char* const kReservedWordList[] = {
hash_set<string> kReservedWords =
MakeWordsMap(kReservedWordList, GOOGLE_ARRAYSIZE(kReservedWordList));
-string SanitizeNameForObjC(const string& input, const string& extension) {
+string SanitizeNameForObjC(const string& input,
+ const string& extension,
+ string* out_suffix_added) {
if (kReservedWords.count(input) > 0) {
+ if (out_suffix_added) *out_suffix_added = extension;
return input + extension;
}
+ if (out_suffix_added) out_suffix_added->clear();
return input;
}
@@ -260,6 +265,34 @@ bool IsSpecialName(const string& name, const string* special_names,
return false;
}
+string GetZeroEnumNameForFlagType(const FlagType flag_type) {
+ switch(flag_type) {
+ case FLAGTYPE_DESCRIPTOR_INITIALIZATION:
+ return "GPBDescriptorInitializationFlag_None";
+ case FLAGTYPE_EXTENSION:
+ return "GPBExtensionNone";
+ case FLAGTYPE_FIELD:
+ return "GPBFieldNone";
+ default:
+ GOOGLE_LOG(FATAL) << "Can't get here.";
+ return "0";
+ }
+}
+
+string GetEnumNameForFlagType(const FlagType flag_type) {
+ switch(flag_type) {
+ case FLAGTYPE_DESCRIPTOR_INITIALIZATION:
+ return "GPBDescriptorInitializationFlags";
+ case FLAGTYPE_EXTENSION:
+ return "GPBExtensionOptions";
+ case FLAGTYPE_FIELD:
+ return "GPBFieldFlags";
+ default:
+ GOOGLE_LOG(FATAL) << "Can't get here.";
+ return string();
+ }
+}
+
} // namespace
// Escape C++ trigraphs by escaping question marks to \?
@@ -306,6 +339,12 @@ string BaseFileName(const FileDescriptor* file) {
return basename;
}
+string FileClassPrefix(const FileDescriptor* file) {
+ // Default is empty string, no need to check has_objc_class_prefix.
+ string result = file->options().objc_class_prefix();
+ return result;
+}
+
string FilePath(const FileDescriptor* file) {
string output;
string basename;
@@ -336,19 +375,13 @@ string FilePathBasename(const FileDescriptor* file) {
return output;
}
-string FileClassPrefix(const FileDescriptor* file) {
- // Default is empty string, no need to check has_objc_class_prefix.
- string result = file->options().objc_class_prefix();
- return result;
-}
-
string FileClassName(const FileDescriptor* file) {
string name = FileClassPrefix(file);
name += UnderscoresToCamelCase(StripProto(BaseFileName(file)), true);
name += "Root";
// There aren't really any reserved words that end in "Root", but playing
// it safe and checking.
- return SanitizeNameForObjC(name, "_RootClass");
+ return SanitizeNameForObjC(name, "_RootClass", NULL);
}
string ClassNameWorker(const Descriptor* descriptor) {
@@ -370,11 +403,15 @@ string ClassNameWorker(const EnumDescriptor* descriptor) {
}
string ClassName(const Descriptor* descriptor) {
+ return ClassName(descriptor, NULL);
+}
+
+string ClassName(const Descriptor* descriptor, string* out_suffix_added) {
// 1. Message names are used as is (style calls for CamelCase, trust it).
// 2. Check for reserved word at the very end and then suffix things.
string prefix = FileClassPrefix(descriptor->file());
string name = ClassNameWorker(descriptor);
- return SanitizeNameForObjC(prefix + name, "_Class");
+ return SanitizeNameForObjC(prefix + name, "_Class", out_suffix_added);
}
string EnumName(const EnumDescriptor* descriptor) {
@@ -388,7 +425,7 @@ string EnumName(const EnumDescriptor* descriptor) {
// yields Fixed_Class, Fixed_Size.
string name = FileClassPrefix(descriptor->file());
name += ClassNameWorker(descriptor);
- return SanitizeNameForObjC(name, "_Enum");
+ return SanitizeNameForObjC(name, "_Enum", NULL);
}
string EnumValueName(const EnumValueDescriptor* descriptor) {
@@ -403,7 +440,7 @@ string EnumValueName(const EnumValueDescriptor* descriptor) {
const string& name = class_name + "_" + value_str;
// There aren't really any reserved words with an underscore and a leading
// capital letter, but playing it safe and checking.
- return SanitizeNameForObjC(name, "_Value");
+ return SanitizeNameForObjC(name, "_Value", NULL);
}
string EnumValueShortName(const EnumValueDescriptor* descriptor) {
@@ -440,7 +477,7 @@ string UnCamelCaseEnumShortName(const string& name) {
string ExtensionMethodName(const FieldDescriptor* descriptor) {
const string& name = NameFromFieldDescriptor(descriptor);
const string& result = UnderscoresToCamelCase(name, false);
- return SanitizeNameForObjC(result, "_Extension");
+ return SanitizeNameForObjC(result, "_Extension", NULL);
}
string FieldName(const FieldDescriptor* field) {
@@ -455,7 +492,7 @@ string FieldName(const FieldDescriptor* field) {
result += "_p";
}
}
- return SanitizeNameForObjC(result, "_p");
+ return SanitizeNameForObjC(result, "_p", NULL);
}
string FieldNameCapitalized(const FieldDescriptor* field) {
@@ -815,21 +852,26 @@ bool HasNonZeroDefaultValue(const FieldDescriptor* field) {
return false;
}
-string BuildFlagsString(const vector<string>& strings) {
+string BuildFlagsString(const FlagType flag_type,
+ const vector<string>& strings) {
if (strings.size() == 0) {
- return "0";
+ return GetZeroEnumNameForFlagType(flag_type);
+ } else if (strings.size() == 1) {
+ return strings[0];
}
- string string;
+ string string("(" + GetEnumNameForFlagType(flag_type) + ")(");
for (size_t i = 0; i != strings.size(); ++i) {
if (i > 0) {
string.append(" | ");
}
string.append(strings[i]);
}
+ string.append(")");
return string;
}
-string BuildCommentsString(const SourceLocation& location) {
+string BuildCommentsString(const SourceLocation& location,
+ bool prefer_single_line) {
const string& comments = location.leading_comments.empty()
? location.trailing_comments
: location.leading_comments;
@@ -838,15 +880,45 @@ string BuildCommentsString(const SourceLocation& location) {
while (!lines.empty() && lines.back().empty()) {
lines.pop_back();
}
- string prefix("///");
- string suffix("\n");
+ // If there are no comments, just return an empty string.
+ if (lines.size() == 0) {
+ return "";
+ }
+
+ string prefix;
+ string suffix;
string final_comments;
- for (int i = 0; i < lines.size(); i++) {
- // HeaderDoc uses '\' and '@' for markers; escape them.
- const string line = StringReplace(lines[i], "\\", "\\\\", true);
- final_comments +=
- prefix + StringReplace(line, "@", "\\@", true) + suffix;
+ string epilogue;
+
+ bool add_leading_space = false;
+
+ if (prefer_single_line && lines.size() == 1) {
+ prefix = "/** ";
+ suffix = " */\n";
+ } else {
+ prefix = "* ";
+ suffix = "\n";
+ final_comments += "/**\n";
+ epilogue = " **/\n";
+ add_leading_space = true;
}
+
+ for (int i = 0; i < lines.size(); i++) {
+ string line = StripPrefixString(lines[i], " ");
+ // HeaderDoc and appledoc use '\' and '@' for markers; escape them.
+ line = StringReplace(line, "\\", "\\\\", true);
+ line = StringReplace(line, "@", "\\@", true);
+ // Decouple / from * to not have inline comments inside comments.
+ line = StringReplace(line, "/*", "/\\*", true);
+ line = StringReplace(line, "*/", "*\\/", true);
+ line = prefix + line;
+ StripWhitespace(&line);
+ // If not a one line, need to add the first space before *, as
+ // StripWhitespace would have removed it.
+ line = (add_leading_space ? " " : "") + line;
+ final_comments += line + suffix;
+ }
+ final_comments += epilogue;
return final_comments;
}
@@ -947,28 +1019,20 @@ bool LoadExpectedPackagePrefixes(const Options &generation_options,
generation_options.expected_prefixes_path, &collector, out_error);
}
-} // namespace
-
-bool ValidateObjCClassPrefix(const FileDescriptor* file,
- const Options& generation_options,
- string* out_error) {
+bool ValidateObjCClassPrefix(
+ const FileDescriptor* file,
+ const string& expected_prefixes_path,
+ const map<string, string>& expected_package_prefixes,
+ string* out_error) {
const string prefix = file->options().objc_class_prefix();
const string package = file->package();
// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some
// error cases, so it seems to be ok to use as a back door for warnings.
- // Load any expected package prefixes to validate against those.
- map<string, string> expected_package_prefixes;
- if (!LoadExpectedPackagePrefixes(generation_options,
- &expected_package_prefixes,
- out_error)) {
- return false;
- }
-
// Check: Error - See if there was an expected prefix for the package and
// report if it doesn't match (wrong or missing).
- map<string, string>::iterator package_match =
+ map<string, string>::const_iterator package_match =
expected_package_prefixes.find(package);
if (package_match != expected_package_prefixes.end()) {
// There was an entry, and...
@@ -989,27 +1053,11 @@ bool ValidateObjCClassPrefix(const FileDescriptor* file,
}
// If there was no prefix option, we're done at this point.
- if (prefix.length() == 0) {
+ if (prefix.empty()) {
// No prefix, nothing left to check.
return true;
}
- // Check: Error - Make sure the prefix wasn't expected for a different
- // package (overlap is allowed, but it has to be listed as an expected
- // overlap).
- for (map<string, string>::iterator i = expected_package_prefixes.begin();
- i != expected_package_prefixes.end(); ++i) {
- if (i->second == prefix) {
- *out_error =
- "error: Found 'option objc_class_prefix = \"" + prefix +
- "\";' in '" + file->name() +
- "'; that prefix is already used for 'package " + i->first +
- ";'. It can only be reused by listing it in the expected file (" +
- generation_options.expected_prefixes_path + ").";
- return false; // Only report first usage of the prefix.
- }
- }
-
// Check: Warning - Make sure the prefix is is a reasonable value according
// to Apple's rules (the checks above implicitly whitelist anything that
// doesn't meet these rules).
@@ -1031,6 +1079,56 @@ bool ValidateObjCClassPrefix(const FileDescriptor* file,
cerr.flush();
}
+ // Look for any other package that uses the same prefix.
+ string other_package_for_prefix;
+ for (map<string, string>::const_iterator i = expected_package_prefixes.begin();
+ i != expected_package_prefixes.end(); ++i) {
+ if (i->second == prefix) {
+ other_package_for_prefix = i->first;
+ break;
+ }
+ }
+
+ // Check: Warning - If the file does not have a package, check whether
+ // the prefix declared is being used by another package or not.
+ if (package.empty()) {
+ // The file does not have a package and ...
+ if (other_package_for_prefix.empty()) {
+ // ... no other package has declared that prefix.
+ cerr << endl
+ << "protoc:0: warning: File '" << file->name() << "' has no "
+ << "package. Consider adding a new package to the proto and adding '"
+ << "new.package = " << prefix << "' to the expected prefixes file ("
+ << expected_prefixes_path << ")." << endl;
+ cerr.flush();
+ } else {
+ // ... another package has declared the same prefix.
+ cerr << endl
+ << "protoc:0: warning: File '" << file->name() << "' has no package "
+ << "and package '" << other_package_for_prefix << "' already uses '"
+ << prefix << "' as its prefix. Consider either adding a new package "
+ << "to the proto, or reusing one of the packages already using this "
+ << "prefix in the expected prefixes file ("
+ << expected_prefixes_path << ")." << endl;
+ cerr.flush();
+ }
+ return true;
+ }
+
+ // Check: Error - Make sure the prefix wasn't expected for a different
+ // package (overlap is allowed, but it has to be listed as an expected
+ // overlap).
+ if (!other_package_for_prefix.empty()) {
+ *out_error =
+ "error: Found 'option objc_class_prefix = \"" + prefix +
+ "\";' in '" + file->name() +
+ "'; that prefix is already used for 'package " +
+ other_package_for_prefix + ";'. It can only be reused by listing " +
+ "it in the expected file (" +
+ expected_prefixes_path + ").";
+ return false; // Only report first usage of the prefix.
+ }
+
// Check: Warning - If the given package/prefix pair wasn't expected, issue a
// warning issue a warning suggesting it gets added to the file.
if (!expected_package_prefixes.empty()) {
@@ -1038,13 +1136,39 @@ bool ValidateObjCClassPrefix(const FileDescriptor* file,
<< "protoc:0: warning: Found unexpected 'option objc_class_prefix = \""
<< prefix << "\";' in '" << file->name() << "';"
<< " consider adding it to the expected prefixes file ("
- << generation_options.expected_prefixes_path << ")." << endl;
+ << expected_prefixes_path << ")." << endl;
cerr.flush();
}
return true;
}
+} // namespace
+
+bool ValidateObjCClassPrefixes(const vector<const FileDescriptor*>& files,
+ const Options& generation_options,
+ string* out_error) {
+ // Load the expected package prefixes, if available, to validate against.
+ map<string, string> expected_package_prefixes;
+ if (!LoadExpectedPackagePrefixes(generation_options,
+ &expected_package_prefixes,
+ out_error)) {
+ return false;
+ }
+
+ for (int i = 0; i < files.size(); i++) {
+ bool is_valid =
+ ValidateObjCClassPrefix(files[i],
+ generation_options.expected_prefixes_path,
+ expected_package_prefixes,
+ out_error);
+ if (!is_valid) {
+ return false;
+ }
+ }
+ return true;
+}
+
TextFormatDecodeData::TextFormatDecodeData() { }
TextFormatDecodeData::~TextFormatDecodeData() { }
@@ -1367,6 +1491,178 @@ bool ParseSimpleFile(
return parser.Finish();
}
+ImportWriter::ImportWriter(
+ const string& generate_for_named_framework,
+ const string& named_framework_to_proto_path_mappings_path)
+ : generate_for_named_framework_(generate_for_named_framework),
+ named_framework_to_proto_path_mappings_path_(
+ named_framework_to_proto_path_mappings_path),
+ need_to_parse_mapping_file_(true) {
+}
+
+ImportWriter::~ImportWriter() {}
+
+void ImportWriter::AddFile(const FileDescriptor* file,
+ const string& header_extension) {
+ const string file_path(FilePath(file));
+
+ if (IsProtobufLibraryBundledProtoFile(file)) {
+ protobuf_framework_imports_.push_back(
+ FilePathBasename(file) + header_extension);
+ protobuf_non_framework_imports_.push_back(file_path + header_extension);
+ return;
+ }
+
+ // Lazy parse any mappings.
+ if (need_to_parse_mapping_file_) {
+ ParseFrameworkMappings();
+ }
+
+ map<string, string>::iterator proto_lookup =
+ proto_file_to_framework_name_.find(file->name());
+ if (proto_lookup != proto_file_to_framework_name_.end()) {
+ other_framework_imports_.push_back(
+ proto_lookup->second + "/" +
+ FilePathBasename(file) + header_extension);
+ return;
+ }
+
+ if (!generate_for_named_framework_.empty()) {
+ other_framework_imports_.push_back(
+ generate_for_named_framework_ + "/" +
+ FilePathBasename(file) + header_extension);
+ return;
+ }
+
+ other_imports_.push_back(file_path + header_extension);
+}
+
+void ImportWriter::Print(io::Printer* printer) const {
+ assert(protobuf_non_framework_imports_.size() ==
+ protobuf_framework_imports_.size());
+
+ bool add_blank_line = false;
+
+ if (protobuf_framework_imports_.size() > 0) {
+ const string framework_name(ProtobufLibraryFrameworkName);
+ const string cpp_symbol(ProtobufFrameworkImportSymbol(framework_name));
+
+ printer->Print(
+ "#if $cpp_symbol$\n",
+ "cpp_symbol", cpp_symbol);
+ for (vector<string>::const_iterator iter = protobuf_framework_imports_.begin();
+ iter != protobuf_framework_imports_.end(); ++iter) {
+ printer->Print(
+ " #import <$framework_name$/$header$>\n",
+ "framework_name", framework_name,
+ "header", *iter);
+ }
+ printer->Print(
+ "#else\n");
+ for (vector<string>::const_iterator iter = protobuf_non_framework_imports_.begin();
+ iter != protobuf_non_framework_imports_.end(); ++iter) {
+ printer->Print(
+ " #import \"$header$\"\n",
+ "header", *iter);
+ }
+ printer->Print(
+ "#endif\n");
+
+ add_blank_line = true;
+ }
+
+ if (other_framework_imports_.size() > 0) {
+ if (add_blank_line) {
+ printer->Print("\n");
+ }
+
+ for (vector<string>::const_iterator iter = other_framework_imports_.begin();
+ iter != other_framework_imports_.end(); ++iter) {
+ printer->Print(
+ " #import <$header$>\n",
+ "header", *iter);
+ }
+
+ add_blank_line = true;
+ }
+
+ if (other_imports_.size() > 0) {
+ if (add_blank_line) {
+ printer->Print("\n");
+ }
+
+ for (vector<string>::const_iterator iter = other_imports_.begin();
+ iter != other_imports_.end(); ++iter) {
+ printer->Print(
+ " #import \"$header$\"\n",
+ "header", *iter);
+ }
+ }
+}
+
+void ImportWriter::ParseFrameworkMappings() {
+ need_to_parse_mapping_file_ = false;
+ if (named_framework_to_proto_path_mappings_path_.empty()) {
+ return; // Nothing to do.
+ }
+
+ ProtoFrameworkCollector collector(&proto_file_to_framework_name_);
+ string parse_error;
+ if (!ParseSimpleFile(named_framework_to_proto_path_mappings_path_,
+ &collector, &parse_error)) {
+ cerr << "error parsing " << named_framework_to_proto_path_mappings_path_
+ << " : " << parse_error << endl;
+ cerr.flush();
+ }
+}
+
+bool ImportWriter::ProtoFrameworkCollector::ConsumeLine(
+ const StringPiece& line, string* out_error) {
+ int offset = line.find(':');
+ if (offset == StringPiece::npos) {
+ *out_error =
+ string("Framework/proto file mapping line without colon sign: '") +
+ line.ToString() + "'.";
+ return false;
+ }
+ StringPiece framework_name(line, 0, offset);
+ StringPiece proto_file_list(line, offset + 1, line.length() - offset - 1);
+ StringPieceTrimWhitespace(&framework_name);
+
+ int start = 0;
+ while (start < proto_file_list.length()) {
+ offset = proto_file_list.find(',', start);
+ if (offset == StringPiece::npos) {
+ offset = proto_file_list.length();
+ }
+
+ StringPiece proto_file(proto_file_list, start, offset - start);
+ StringPieceTrimWhitespace(&proto_file);
+ if (proto_file.size() != 0) {
+ map<string, string>::iterator existing_entry =
+ map_->find(proto_file.ToString());
+ if (existing_entry != map_->end()) {
+ cerr << "warning: duplicate proto file reference, replacing framework entry for '"
+ << proto_file.ToString() << "' with '" << framework_name.ToString()
+ << "' (was '" << existing_entry->second << "')." << endl;
+ cerr.flush();
+ }
+
+ if (proto_file.find(' ') != StringPiece::npos) {
+ cerr << "note: framework mapping file had a proto file with a space in, hopefully that isn't a missing comma: '"
+ << proto_file.ToString() << "'" << endl;
+ cerr.flush();
+ }
+
+ (*map_)[proto_file.ToString()] = framework_name.ToString();
+ }
+
+ start = offset + 1;
+ }
+
+ return true;
+}
+
} // namespace objectivec
} // namespace compiler
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.h
index be20beeea5..c99262a1ba 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_helpers.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.h
@@ -28,6 +28,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// Helper functions for generating ObjectiveC code.
+
#ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__
#define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__
@@ -51,62 +53,66 @@ struct Options {
};
// Escape C++ trigraphs by escaping question marks to "\?".
-string EscapeTrigraphs(const string& to_escape);
+string LIBPROTOC_EXPORT EscapeTrigraphs(const string& to_escape);
// Strips ".proto" or ".protodevel" from the end of a filename.
-string StripProto(const string& filename);
+string LIBPROTOC_EXPORT StripProto(const string& filename);
// Remove white space from either end of a StringPiece.
-void StringPieceTrimWhitespace(StringPiece* input);
+void LIBPROTOC_EXPORT StringPieceTrimWhitespace(StringPiece* input);
// Returns true if the name requires a ns_returns_not_retained attribute applied
// to it.
-bool IsRetainedName(const string& name);
+bool LIBPROTOC_EXPORT IsRetainedName(const string& name);
// Returns true if the name starts with "init" and will need to have special
// handling under ARC.
-bool IsInitName(const string& name);
+bool LIBPROTOC_EXPORT IsInitName(const string& name);
+
+// Gets the objc_class_prefix.
+string LIBPROTOC_EXPORT FileClassPrefix(const FileDescriptor* file);
// Gets the path of the file we're going to generate (sans the .pb.h
// extension). The path will be dependent on the objectivec package
// declared in the proto package.
-string FilePath(const FileDescriptor* file);
+string LIBPROTOC_EXPORT FilePath(const FileDescriptor* file);
// Just like FilePath(), but without the directory part.
-string FilePathBasename(const FileDescriptor* file);
+string LIBPROTOC_EXPORT FilePathBasename(const FileDescriptor* file);
// Gets the name of the root class we'll generate in the file. This class
// is not meant for external consumption, but instead contains helpers that
// the rest of the classes need
-string FileClassName(const FileDescriptor* file);
+string LIBPROTOC_EXPORT FileClassName(const FileDescriptor* file);
// These return the fully-qualified class name corresponding to the given
// descriptor.
-string ClassName(const Descriptor* descriptor);
-string EnumName(const EnumDescriptor* descriptor);
+string LIBPROTOC_EXPORT ClassName(const Descriptor* descriptor);
+string LIBPROTOC_EXPORT ClassName(const Descriptor* descriptor, string* out_suffix_added);
+string LIBPROTOC_EXPORT EnumName(const EnumDescriptor* descriptor);
// Returns the fully-qualified name of the enum value corresponding to the
// the descriptor.
-string EnumValueName(const EnumValueDescriptor* descriptor);
+string LIBPROTOC_EXPORT EnumValueName(const EnumValueDescriptor* descriptor);
// Returns the name of the enum value corresponding to the descriptor.
-string EnumValueShortName(const EnumValueDescriptor* descriptor);
+string LIBPROTOC_EXPORT EnumValueShortName(const EnumValueDescriptor* descriptor);
// Reverse what an enum does.
-string UnCamelCaseEnumShortName(const string& name);
+string LIBPROTOC_EXPORT UnCamelCaseEnumShortName(const string& name);
// Returns the name to use for the extension (used as the method off the file's
// Root class).
-string ExtensionMethodName(const FieldDescriptor* descriptor);
+string LIBPROTOC_EXPORT ExtensionMethodName(const FieldDescriptor* descriptor);
// Returns the transformed field name.
-string FieldName(const FieldDescriptor* field);
-string FieldNameCapitalized(const FieldDescriptor* field);
+string LIBPROTOC_EXPORT FieldName(const FieldDescriptor* field);
+string LIBPROTOC_EXPORT FieldNameCapitalized(const FieldDescriptor* field);
// Returns the transformed oneof name.
-string OneofEnumName(const OneofDescriptor* descriptor);
-string OneofName(const OneofDescriptor* descriptor);
-string OneofNameCapitalized(const OneofDescriptor* descriptor);
+string LIBPROTOC_EXPORT OneofEnumName(const OneofDescriptor* descriptor);
+string LIBPROTOC_EXPORT OneofName(const OneofDescriptor* descriptor);
+string LIBPROTOC_EXPORT OneofNameCapitalized(const OneofDescriptor* descriptor);
inline bool HasFieldPresence(const FileDescriptor* file) {
return file->syntax() != FileDescriptor::SYNTAX_PROTO3;
@@ -121,7 +127,7 @@ inline bool IsMapEntryMessage(const Descriptor* descriptor) {
}
// Reverse of the above.
-string UnCamelCaseFieldName(const string& name, const FieldDescriptor* field);
+string LIBPROTOC_EXPORT UnCamelCaseFieldName(const string& name, const FieldDescriptor* field);
enum ObjectiveCType {
OBJECTIVECTYPE_INT32,
@@ -137,9 +143,25 @@ enum ObjectiveCType {
OBJECTIVECTYPE_MESSAGE
};
+enum FlagType {
+ FLAGTYPE_DESCRIPTOR_INITIALIZATION,
+ FLAGTYPE_EXTENSION,
+ FLAGTYPE_FIELD
+};
+
template<class TDescriptor>
-string GetOptionalDeprecatedAttribute(const TDescriptor* descriptor, bool preSpace = true, bool postNewline = false) {
- if (descriptor->options().deprecated()) {
+string GetOptionalDeprecatedAttribute(
+ const TDescriptor* descriptor,
+ const FileDescriptor* file = NULL,
+ bool preSpace = true, bool postNewline = false) {
+ bool isDeprecated = descriptor->options().deprecated();
+ // The file is only passed when checking Messages & Enums, so those types
+ // get tagged. At the moment, it doesn't seem to make sense to tag every
+ // field or enum value with when the file is deprecated.
+ if (!isDeprecated && file) {
+ isDeprecated = file->options().deprecated();
+ }
+ if (isDeprecated) {
string result = "DEPRECATED_ATTRIBUTE";
if (preSpace) {
result.insert(0, " ");
@@ -153,42 +175,44 @@ string GetOptionalDeprecatedAttribute(const TDescriptor* descriptor, bool preSpa
}
}
-string GetCapitalizedType(const FieldDescriptor* field);
+string LIBPROTOC_EXPORT GetCapitalizedType(const FieldDescriptor* field);
-ObjectiveCType GetObjectiveCType(FieldDescriptor::Type field_type);
+ObjectiveCType LIBPROTOC_EXPORT GetObjectiveCType(FieldDescriptor::Type field_type);
inline ObjectiveCType GetObjectiveCType(const FieldDescriptor* field) {
return GetObjectiveCType(field->type());
}
-bool IsPrimitiveType(const FieldDescriptor* field);
-bool IsReferenceType(const FieldDescriptor* field);
+bool LIBPROTOC_EXPORT IsPrimitiveType(const FieldDescriptor* field);
+bool LIBPROTOC_EXPORT IsReferenceType(const FieldDescriptor* field);
-string GPBGenericValueFieldName(const FieldDescriptor* field);
-string DefaultValue(const FieldDescriptor* field);
-bool HasNonZeroDefaultValue(const FieldDescriptor* field);
+string LIBPROTOC_EXPORT GPBGenericValueFieldName(const FieldDescriptor* field);
+string LIBPROTOC_EXPORT DefaultValue(const FieldDescriptor* field);
+bool LIBPROTOC_EXPORT HasNonZeroDefaultValue(const FieldDescriptor* field);
-string BuildFlagsString(const vector<string>& strings);
+string LIBPROTOC_EXPORT BuildFlagsString(const FlagType type, const vector<string>& strings);
-// Builds a HeaderDoc style comment out of the comments in the .proto file.
-string BuildCommentsString(const SourceLocation& location);
+// Builds HeaderDoc/appledoc style comments out of the comments in the .proto
+// file.
+string LIBPROTOC_EXPORT BuildCommentsString(const SourceLocation& location,
+ bool prefer_single_line);
// The name the commonly used by the library when built as a framework.
// This lines up to the name used in the CocoaPod.
-extern const char* const ProtobufLibraryFrameworkName;
+extern LIBPROTOC_EXPORT const char* const ProtobufLibraryFrameworkName;
// Returns the CPP symbol name to use as the gate for framework style imports
// for the given framework name to use.
-string ProtobufFrameworkImportSymbol(const string& framework_name);
+string LIBPROTOC_EXPORT ProtobufFrameworkImportSymbol(const string& framework_name);
// Checks if the file is one of the proto's bundled with the library.
-bool IsProtobufLibraryBundledProtoFile(const FileDescriptor* file);
+bool LIBPROTOC_EXPORT IsProtobufLibraryBundledProtoFile(const FileDescriptor* file);
-// Checks the prefix for a given file and outputs any warnings needed, if
-// there are flat out errors, then out_error is filled in and the result is
-// false.
-bool ValidateObjCClassPrefix(const FileDescriptor* file,
- const Options& generation_options,
- string* out_error);
+// Checks the prefix for the given files and outputs any warnings as needed. If
+// there are flat out errors, then out_error is filled in with the first error
+// and the result is false.
+bool LIBPROTOC_EXPORT ValidateObjCClassPrefixes(const vector<const FileDescriptor*>& files,
+ const Options& generation_options,
+ string* out_error);
// Generate decode data needed for ObjC's GPBDecodeTextFormatName() to transform
// the input into the expected output.
@@ -220,9 +244,46 @@ class LIBPROTOC_EXPORT LineConsumer {
virtual bool ConsumeLine(const StringPiece& line, string* out_error) = 0;
};
-bool ParseSimpleFile(
+bool LIBPROTOC_EXPORT ParseSimpleFile(
const string& path, LineConsumer* line_consumer, string* out_error);
+
+// Helper class for parsing framework import mappings and generating
+// import statements.
+class LIBPROTOC_EXPORT ImportWriter {
+ public:
+ ImportWriter(const string& generate_for_named_framework,
+ const string& named_framework_to_proto_path_mappings_path);
+ ~ImportWriter();
+
+ void AddFile(const FileDescriptor* file, const string& header_extension);
+ void Print(io::Printer *printer) const;
+
+ private:
+ class ProtoFrameworkCollector : public LineConsumer {
+ public:
+ ProtoFrameworkCollector(map<string, string>* inout_proto_file_to_framework_name)
+ : map_(inout_proto_file_to_framework_name) {}
+
+ virtual bool ConsumeLine(const StringPiece& line, string* out_error);
+
+ private:
+ map<string, string>* map_;
+ };
+
+ void ParseFrameworkMappings();
+
+ const string generate_for_named_framework_;
+ const string named_framework_to_proto_path_mappings_path_;
+ map<string, string> proto_file_to_framework_name_;
+ bool need_to_parse_mapping_file_;
+
+ vector<string> protobuf_framework_imports_;
+ vector<string> protobuf_non_framework_imports_;
+ vector<string> other_framework_imports_;
+ vector<string> other_imports_;
+};
+
} // namespace objectivec
} // namespace compiler
} // namespace protobuf
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc
index dc1cef556f..dc1cef556f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc
index ac5d8aea21..0bc9dc10ec 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc
@@ -115,7 +115,7 @@ MapFieldGenerator::MapFieldGenerator(const FieldDescriptor* descriptor,
if (value_field_flags.find("GPBFieldHasEnumDescriptor") != string::npos) {
field_flags.push_back("GPBFieldHasEnumDescriptor");
}
- variables_["fieldflags"] = BuildFlagsString(field_flags);
+ variables_["fieldflags"] = BuildFlagsString(FLAGTYPE_FIELD, field_flags);
ObjectiveCType value_objc_type = GetObjectiveCType(value_descriptor);
const bool value_is_object_type =
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_map_field.h b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_map_field.h
index bc68a6829f..bc68a6829f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_map_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_map_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_message.cc b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message.cc
index e1a7861971..e0bd3dac04 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_message.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message.cc
@@ -180,7 +180,10 @@ MessageGenerator::MessageGenerator(const string& root_classname,
: root_classname_(root_classname),
descriptor_(descriptor),
field_generators_(descriptor, options),
- class_name_(ClassName(descriptor_)) {
+ class_name_(ClassName(descriptor_)),
+ deprecated_attribute_(
+ GetOptionalDeprecatedAttribute(descriptor, descriptor->file(), false, true)) {
+
for (int i = 0; i < descriptor_->extension_count(); i++) {
extension_generators_.push_back(
new ExtensionGenerator(class_name_, descriptor_->extension(i)));
@@ -331,7 +334,7 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) {
string message_comments;
SourceLocation location;
if (descriptor_->GetSourceLocation(&location)) {
- message_comments = BuildCommentsString(location);
+ message_comments = BuildCommentsString(location, false);
} else {
message_comments = "";
}
@@ -339,7 +342,7 @@ void MessageGenerator::GenerateMessageHeader(io::Printer* printer) {
printer->Print(
"$comments$$deprecated_attribute$@interface $classname$ : GPBMessage\n\n",
"classname", class_name_,
- "deprecated_attribute", GetOptionalDeprecatedAttribute(descriptor_, false, true),
+ "deprecated_attribute", deprecated_attribute_,
"comments", message_comments);
vector<char> seen_oneofs(descriptor_->oneof_decl_count(), 0);
@@ -396,6 +399,14 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
"\n",
"classname", class_name_);
+ if (!deprecated_attribute_.empty()) {
+ // No warnings when compiling the impl of this deprecated class.
+ printer->Print(
+ "#pragma clang diagnostic push\n"
+ "#pragma clang diagnostic ignored \"-Wdeprecated-implementations\"\n"
+ "\n");
+ }
+
printer->Print("@implementation $classname$\n\n",
"classname", class_name_);
@@ -521,7 +532,8 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
if (descriptor_->options().message_set_wire_format()) {
init_flags.push_back("GPBDescriptorInitializationFlag_WireFormat");
}
- vars["init_flags"] = BuildFlagsString(init_flags);
+ vars["init_flags"] = BuildFlagsString(FLAGTYPE_DESCRIPTOR_INITIALIZATION,
+ init_flags);
printer->Print(
vars,
@@ -579,6 +591,19 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
" [localDescriptor setupExtensionRanges:ranges\n"
" count:(uint32_t)(sizeof(ranges) / sizeof(GPBExtensionRange))];\n");
}
+ if (descriptor_->containing_type() != NULL) {
+ string parent_class_name = ClassName(descriptor_->containing_type());
+ printer->Print(
+ " [localDescriptor setupContainingMessageClassName:GPBStringifySymbol($parent_name$)];\n",
+ "parent_name", parent_class_name);
+ }
+ string suffix_added;
+ ClassName(descriptor_, &suffix_added);
+ if (suffix_added.size() > 0) {
+ printer->Print(
+ " [localDescriptor setupMessageClassNameSuffix:@\"$suffix$\"];\n",
+ "suffix", suffix_added);
+ }
printer->Print(
" NSAssert(descriptor == nil, @\"Startup recursed!\");\n"
" descriptor = localDescriptor;\n"
@@ -587,6 +612,12 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
"}\n\n"
"@end\n\n");
+ if (!deprecated_attribute_.empty()) {
+ printer->Print(
+ "#pragma clang diagnostic pop\n"
+ "\n");
+ }
+
for (int i = 0; i < descriptor_->field_count(); i++) {
field_generators_.get(descriptor_->field(i))
.GenerateCFunctionImplementations(printer);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_message.h b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message.h
index 910535ace3..0fb78bc024 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_message.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message.h
@@ -85,6 +85,7 @@ class MessageGenerator {
const Descriptor* descriptor_;
FieldGeneratorMap field_generators_;
const string class_name_;
+ const string deprecated_attribute_;
vector<ExtensionGenerator*> extension_generators_;
vector<EnumGenerator*> enum_generators_;
vector<MessageGenerator*> nested_message_generators_;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc
index d6ccd6d1e7..d6ccd6d1e7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_message_field.h b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message_field.h
index d2dba15334..d2dba15334 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_message_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_message_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc
index 3dda903bbf..5531ae249f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc
@@ -53,7 +53,7 @@ OneofGenerator::OneofGenerator(const OneofDescriptor* descriptor)
string comments;
SourceLocation location;
if (descriptor_->GetSourceLocation(&location)) {
- comments = BuildCommentsString(location);
+ comments = BuildCommentsString(location, true);
} else {
comments = "";
}
@@ -104,7 +104,9 @@ void OneofGenerator::GeneratePublicCasePropertyDeclaration(
void OneofGenerator::GenerateClearFunctionDeclaration(io::Printer* printer) {
printer->Print(
variables_,
- "/// Clears whatever value was set for the oneof '$name$'.\n"
+ "/**\n"
+ " * Clears whatever value was set for the oneof '$name$'.\n"
+ " **/\n"
"void $owning_message_class$_Clear$capitalized_name$OneOfCase($owning_message_class$ *message);\n");
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_oneof.h b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_oneof.h
index 3d9df4dbf4..3d9df4dbf4 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_oneof.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_oneof.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc
index d49350f4b7..d49350f4b7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h
index 69bb1fddc1..69bb1fddc1 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/package_info.h b/third_party/protobuf/src/google/protobuf/compiler/package_info.h
index fb6b473e1c..fb6b473e1c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/package_info.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/package_info.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/parser.cc b/third_party/protobuf/src/google/protobuf/compiler/parser.cc
index 214d7c9cd9..7a03d42bd2 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/parser.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/parser.cc
@@ -249,11 +249,11 @@ bool Parser::ConsumeNumber(double* output, const char* error) {
input_->Next();
return true;
} else if (LookingAt("inf")) {
- *output = numeric_limits<double>::infinity();
+ *output = std::numeric_limits<double>::infinity();
input_->Next();
return true;
} else if (LookingAt("nan")) {
- *output = numeric_limits<double>::quiet_NaN();
+ *output = std::numeric_limits<double>::quiet_NaN();
input_->Next();
return true;
} else {
@@ -282,7 +282,7 @@ bool Parser::TryConsumeEndOfDeclaration(
const char* text, const LocationRecorder* location) {
if (LookingAt(text)) {
string leading, trailing;
- vector<string> detached;
+ std::vector<string> detached;
input_->NextWithComments(&trailing, &detached, &leading);
// Save the leading comments for next time, and recall the leading comments
@@ -404,7 +404,7 @@ void Parser::LocationRecorder::RecordLegacyLocation(const Message* descriptor,
void Parser::LocationRecorder::AttachComments(
string* leading, string* trailing,
- vector<string>* detached_comments) const {
+ std::vector<string>* detached_comments) const {
GOOGLE_CHECK(!location_->has_leading_comments());
GOOGLE_CHECK(!location_->has_trailing_comments());
@@ -487,7 +487,7 @@ bool Parser::ValidateEnum(const EnumDescriptorProto* proto) {
return false;
}
- set<int> used_values;
+ std::set<int> used_values;
bool has_duplicates = false;
for (int i = 0; i < proto->value_size(); ++i) {
const EnumValueDescriptorProto enum_value = proto->value(i);
@@ -525,7 +525,6 @@ bool Parser::Parse(io::Tokenizer* input, FileDescriptorProto* file) {
SourceCodeInfo source_code_info;
source_code_info_ = &source_code_info;
- vector<string> top_doc_comments;
if (LookingAtType(io::Tokenizer::TYPE_START)) {
// Advance to first token.
input_->NextWithComments(NULL, &upcoming_detached_comments_,
@@ -571,6 +570,7 @@ bool Parser::Parse(io::Tokenizer* input, FileDescriptorProto* file) {
input_ = NULL;
source_code_info_ = NULL;
+ assert(file != NULL);
source_code_info.Swap(file->mutable_source_code_info());
return !had_errors_;
}
@@ -2089,7 +2089,7 @@ bool SourceLocationTable::Find(
const Message* descriptor,
DescriptorPool::ErrorCollector::ErrorLocation location,
int* line, int* column) const {
- const pair<int, int>* result =
+ const std::pair<int, int>* result =
FindOrNull(location_map_, std::make_pair(descriptor, location));
if (result == NULL) {
*line = -1;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/parser.h b/third_party/protobuf/src/google/protobuf/compiler/parser.h
index 0f80e78b98..dd8b6586ee 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/parser.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/parser.h
@@ -257,7 +257,7 @@ class LIBPROTOBUF_EXPORT Parser {
// TODO(kenton): See comment on TryConsumeEndOfDeclaration(), above, for
// why this is const.
void AttachComments(string* leading, string* trailing,
- vector<string>* detached_comments) const;
+ std::vector<string>* detached_comments) const;
private:
// Indexes of parent and current location in the parent
@@ -520,7 +520,7 @@ class LIBPROTOBUF_EXPORT Parser {
// detached comments will be put into the leading_detached_comments field for
// the next element (See SourceCodeInfo.Location in descriptor.proto), when
// ConsumeEndOfDeclaration() is called.
- vector<string> upcoming_detached_comments_;
+ std::vector<string> upcoming_detached_comments_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Parser);
};
@@ -556,9 +556,9 @@ class LIBPROTOBUF_EXPORT SourceLocationTable {
void Clear();
private:
- typedef map<
- pair<const Message*, DescriptorPool::ErrorCollector::ErrorLocation>,
- pair<int, int> > LocationMap;
+ typedef std::map<
+ std::pair<const Message*, DescriptorPool::ErrorCollector::ErrorLocation>,
+ std::pair<int, int> > LocationMap;
LocationMap location_map_;
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/parser_unittest.cc b/third_party/protobuf/src/google/protobuf/compiler/parser_unittest.cc
index 1d623dd90b..20140f8e7b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/parser_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/parser_unittest.cc
@@ -2218,7 +2218,7 @@ class SourceInfoTest : public ParserTest {
const char* expected_leading_comments,
const char* expected_trailing_comments,
const char* expected_leading_detached_comments) {
- pair<SpanMap::iterator, SpanMap::iterator> range =
+ std::pair<SpanMap::iterator, SpanMap::iterator> range =
spans_.equal_range(SpanKey(descriptor_proto, field, index));
if (start_marker == '\0') {
@@ -2229,8 +2229,8 @@ class SourceInfoTest : public ParserTest {
return true;
}
} else {
- pair<int, int> start_pos = FindOrDie(markers_, start_marker);
- pair<int, int> end_pos = FindOrDie(markers_, end_marker);
+ std::pair<int, int> start_pos = FindOrDie(markers_, start_marker);
+ std::pair<int, int> end_pos = FindOrDie(markers_, end_marker);
RepeatedField<int> expected_span;
expected_span.Add(start_pos.first);
@@ -2295,9 +2295,9 @@ class SourceInfoTest : public ParserTest {
}
};
- typedef multimap<SpanKey, const SourceCodeInfo::Location*> SpanMap;
+ typedef std::multimap<SpanKey, const SourceCodeInfo::Location*> SpanMap;
SpanMap spans_;
- map<char, pair<int, int> > markers_;
+ std::map<char, std::pair<int, int> > markers_;
string text_without_markers_;
void ExtractMarkers(const char* text) {
diff --git a/third_party/protobuf/src/google/protobuf/compiler/php/php_generator.cc b/third_party/protobuf/src/google/protobuf/compiler/php/php_generator.cc
new file mode 100644
index 0000000000..db72ea1ad8
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/compiler/php/php_generator.cc
@@ -0,0 +1,1119 @@
+// 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 <google/protobuf/compiler/php/php_generator.h>
+
+#include <google/protobuf/compiler/code_generator.h>
+#include <google/protobuf/compiler/plugin.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/descriptor.pb.h>
+#include <google/protobuf/io/printer.h>
+#include <google/protobuf/io/zero_copy_stream.h>
+#include <google/protobuf/stubs/strutil.h>
+
+#include <sstream>
+
+using google::protobuf::internal::scoped_ptr;
+
+const std::string kDescriptorFile = "google/protobuf/descriptor.proto";
+const std::string kEmptyFile = "google/protobuf/empty.proto";
+const std::string kEmptyMetadataFile = "GPBMetadata/Google/Protobuf/GPBEmpty.php";
+const std::string kDescriptorMetadataFile =
+ "GPBMetadata/Google/Protobuf/Internal/Descriptor.php";
+const std::string kDescriptorDirName = "Google/Protobuf/Internal";
+const std::string kDescriptorPackageName = "Google\\Protobuf\\Internal";
+
+namespace google {
+namespace protobuf {
+namespace compiler {
+namespace php {
+
+// Forward decls.
+std::string PhpName(const std::string& full_name, bool is_descriptor);
+std::string DefaultForField(FieldDescriptor* field);
+std::string IntToString(int32 value);
+std::string FilenameToClassname(const string& filename);
+std::string GeneratedMetadataFileName(const std::string& proto_file,
+ bool is_descriptor);
+std::string LabelForField(FieldDescriptor* field);
+std::string TypeName(FieldDescriptor* field);
+std::string UnderscoresToCamelCase(const string& name, bool cap_first_letter);
+std::string EscapeDollor(const string& to_escape);
+std::string BinaryToHex(const string& binary);
+void Indent(io::Printer* printer);
+void Outdent(io::Printer* printer);
+void GenerateMessageDocComment(io::Printer* printer, const Descriptor* message);
+void GenerateFieldDocComment(io::Printer* printer,
+ const FieldDescriptor* field);
+void GenerateEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_);
+void GenerateEnumValueDocComment(io::Printer* printer,
+ const EnumValueDescriptor* value);
+
+std::string RenameEmpty(const std::string& name) {
+ if (name == "Empty") {
+ return "GPBEmpty";
+ } else {
+ return name;
+ }
+}
+
+std::string MessagePrefix(const Descriptor* message) {
+ // Empty cannot be php class name.
+ if (message->name() == "Empty" &&
+ message->file()->package() == "google.protobuf") {
+ return "GPB";
+ } else {
+ return (message->file()->options()).php_class_prefix();
+ }
+}
+
+std::string MessageName(const Descriptor* message, bool is_descriptor) {
+ string message_name = message->name();
+ const Descriptor* descriptor = message->containing_type();
+ while (descriptor != NULL) {
+ message_name = descriptor->name() + '_' + message_name;
+ descriptor = descriptor->containing_type();
+ }
+ message_name = MessagePrefix(message) + message_name;
+
+ if (message->file()->package() == "") {
+ return message_name;
+ } else {
+ return PhpName(message->file()->package(), is_descriptor) + '\\' +
+ message_name;
+ }
+}
+
+std::string MessageFullName(const Descriptor* message, bool is_descriptor) {
+ if (is_descriptor) {
+ return StringReplace(message->full_name(),
+ "google.protobuf",
+ "google.protobuf.internal", false);
+ } else {
+ return message->full_name();
+ }
+}
+
+std::string EnumFullName(const EnumDescriptor* envm, bool is_descriptor) {
+ if (is_descriptor) {
+ return StringReplace(envm->full_name(),
+ "google.protobuf",
+ "google.protobuf.internal", false);
+ } else {
+ return envm->full_name();
+ }
+}
+
+std::string EnumClassName(const EnumDescriptor* envm) {
+ string enum_class_name = envm->name();
+ const Descriptor* descriptor = envm->containing_type();
+ while (descriptor != NULL) {
+ enum_class_name = descriptor->name() + '_' + enum_class_name;
+ descriptor = descriptor->containing_type();
+ }
+ return enum_class_name;
+}
+
+std::string EnumName(const EnumDescriptor* envm, bool is_descriptor) {
+ string enum_name = EnumClassName(envm);
+ return PhpName(envm->file()->package(), is_descriptor) + '\\' + enum_name;
+}
+
+std::string PhpName(const std::string& full_name, bool is_descriptor) {
+ if (is_descriptor) {
+ return kDescriptorPackageName;
+ }
+
+ std::string result;
+ bool cap_next_letter = true;
+ for (int i = 0; i < full_name.size(); i++) {
+ if ('a' <= full_name[i] && full_name[i] <= 'z' && cap_next_letter) {
+ result += full_name[i] + ('A' - 'a');
+ cap_next_letter = false;
+ } else if (full_name[i] == '.') {
+ result += '\\';
+ cap_next_letter = true;
+ } else {
+ result += full_name[i];
+ cap_next_letter = false;
+ }
+ }
+ return result;
+}
+
+std::string DefaultForField(const FieldDescriptor* field) {
+ switch (field->type()) {
+ case FieldDescriptor::TYPE_INT32:
+ case FieldDescriptor::TYPE_INT64:
+ case FieldDescriptor::TYPE_UINT32:
+ case FieldDescriptor::TYPE_UINT64:
+ case FieldDescriptor::TYPE_SINT32:
+ case FieldDescriptor::TYPE_SINT64:
+ case FieldDescriptor::TYPE_FIXED32:
+ case FieldDescriptor::TYPE_FIXED64:
+ case FieldDescriptor::TYPE_SFIXED32:
+ case FieldDescriptor::TYPE_SFIXED64:
+ case FieldDescriptor::TYPE_ENUM: return "0";
+ case FieldDescriptor::TYPE_DOUBLE:
+ case FieldDescriptor::TYPE_FLOAT: return "0.0";
+ case FieldDescriptor::TYPE_BOOL: return "false";
+ case FieldDescriptor::TYPE_STRING:
+ case FieldDescriptor::TYPE_BYTES: return "''";
+ case FieldDescriptor::TYPE_MESSAGE:
+ case FieldDescriptor::TYPE_GROUP: return "null";
+ default: assert(false); return "";
+ }
+}
+
+std::string GeneratedMetadataFileName(const std::string& proto_file,
+ bool is_descriptor) {
+ int start_index = 0;
+ int first_index = proto_file.find_first_of("/", start_index);
+ std::string result = "GPBMetadata/";
+
+ if (proto_file == kEmptyFile) {
+ return kEmptyMetadataFile;
+ }
+ if (is_descriptor) {
+ return kDescriptorMetadataFile;
+ }
+
+ // Append directory name.
+ std::string file_no_suffix;
+ int lastindex = proto_file.find_last_of(".");
+ if (proto_file == kEmptyFile) {
+ return kEmptyMetadataFile;
+ } else {
+ file_no_suffix = proto_file.substr(0, lastindex);
+ }
+
+ while (first_index != string::npos) {
+ result += UnderscoresToCamelCase(
+ file_no_suffix.substr(start_index, first_index - start_index), true);
+ result += "/";
+ start_index = first_index + 1;
+ first_index = file_no_suffix.find_first_of("/", start_index);
+ }
+
+ // Append file name.
+ result += RenameEmpty(UnderscoresToCamelCase(
+ file_no_suffix.substr(start_index, first_index - start_index), true));
+
+ return result += ".php";
+}
+
+std::string GeneratedMessageFileName(const Descriptor* message,
+ bool is_descriptor) {
+ std::string result = MessageName(message, is_descriptor);
+ for (int i = 0; i < result.size(); i++) {
+ if (result[i] == '\\') {
+ result[i] = '/';
+ }
+ }
+ return result + ".php";
+}
+
+std::string GeneratedEnumFileName(const EnumDescriptor* en,
+ bool is_descriptor) {
+ std::string result = EnumName(en, is_descriptor);
+ for (int i = 0; i < result.size(); i++) {
+ if (result[i] == '\\') {
+ result[i] = '/';
+ }
+ }
+ return result + ".php";
+}
+
+std::string IntToString(int32 value) {
+ std::ostringstream os;
+ os << value;
+ return os.str();
+}
+
+std::string LabelForField(const FieldDescriptor* field) {
+ switch (field->label()) {
+ case FieldDescriptor::LABEL_OPTIONAL: return "optional";
+ case FieldDescriptor::LABEL_REQUIRED: return "required";
+ case FieldDescriptor::LABEL_REPEATED: return "repeated";
+ default: assert(false); return "";
+ }
+}
+
+std::string TypeName(const FieldDescriptor* field) {
+ switch (field->type()) {
+ case FieldDescriptor::TYPE_INT32: return "int32";
+ case FieldDescriptor::TYPE_INT64: return "int64";
+ case FieldDescriptor::TYPE_UINT32: return "uint32";
+ case FieldDescriptor::TYPE_UINT64: return "uint64";
+ case FieldDescriptor::TYPE_SINT32: return "sint32";
+ case FieldDescriptor::TYPE_SINT64: return "sint64";
+ case FieldDescriptor::TYPE_FIXED32: return "fixed32";
+ case FieldDescriptor::TYPE_FIXED64: return "fixed64";
+ case FieldDescriptor::TYPE_SFIXED32: return "sfixed32";
+ case FieldDescriptor::TYPE_SFIXED64: return "sfixed64";
+ case FieldDescriptor::TYPE_DOUBLE: return "double";
+ case FieldDescriptor::TYPE_FLOAT: return "float";
+ case FieldDescriptor::TYPE_BOOL: return "bool";
+ case FieldDescriptor::TYPE_ENUM: return "enum";
+ case FieldDescriptor::TYPE_STRING: return "string";
+ case FieldDescriptor::TYPE_BYTES: return "bytes";
+ case FieldDescriptor::TYPE_MESSAGE: return "message";
+ case FieldDescriptor::TYPE_GROUP: return "group";
+ default: assert(false); return "";
+ }
+}
+
+std::string EnumOrMessageSuffix(
+ const FieldDescriptor* field, bool is_descriptor) {
+ if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
+ return ", '" + MessageFullName(field->message_type(), is_descriptor) + "'";
+ }
+ if (field->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) {
+ return ", '" + EnumFullName(field->enum_type(), is_descriptor) + "'";
+ }
+ return "";
+}
+
+// Converts a name to camel-case. If cap_first_letter is true, capitalize the
+// first letter.
+std::string UnderscoresToCamelCase(const string& input, bool cap_first_letter) {
+ std::string result;
+ for (int i = 0; i < input.size(); i++) {
+ if ('a' <= input[i] && input[i] <= 'z') {
+ if (cap_first_letter) {
+ result += input[i] + ('A' - 'a');
+ } else {
+ result += input[i];
+ }
+ cap_first_letter = false;
+ } else if ('A' <= input[i] && input[i] <= 'Z') {
+ if (i == 0 && !cap_first_letter) {
+ // Force first letter to lower-case unless explicitly told to
+ // capitalize it.
+ result += input[i] + ('a' - 'A');
+ } else {
+ // Capital letters after the first are left as-is.
+ result += input[i];
+ }
+ cap_first_letter = false;
+ } else if ('0' <= input[i] && input[i] <= '9') {
+ result += input[i];
+ cap_first_letter = true;
+ } else {
+ cap_first_letter = true;
+ }
+ }
+ // Add a trailing "_" if the name should be altered.
+ if (input[input.size() - 1] == '#') {
+ result += '_';
+ }
+ return result;
+}
+
+std::string EscapeDollor(const string& to_escape) {
+ return StringReplace(to_escape, "$", "\\$", true);
+}
+
+std::string BinaryToHex(const string& src) {
+ string dest;
+ size_t i;
+ unsigned char symbol[16] = {
+ '0', '1', '2', '3',
+ '4', '5', '6', '7',
+ '8', '9', 'a', 'b',
+ 'c', 'd', 'e', 'f',
+ };
+
+ dest.resize(src.size() * 2);
+ char* append_ptr = &dest[0];
+
+ for (i = 0; i < src.size(); i++) {
+ *append_ptr++ = symbol[(src[i] & 0xf0) >> 4];
+ *append_ptr++ = symbol[src[i] & 0x0f];
+ }
+
+ return dest;
+}
+
+void Indent(io::Printer* printer) {
+ printer->Indent();
+ printer->Indent();
+}
+void Outdent(io::Printer* printer) {
+ printer->Outdent();
+ printer->Outdent();
+}
+
+void GenerateField(const FieldDescriptor* field, io::Printer* printer,
+ bool is_descriptor) {
+ if (field->is_repeated()) {
+ GenerateFieldDocComment(printer, field);
+ printer->Print(
+ "private $^name^;\n",
+ "name", field->name());
+ } else if (field->containing_oneof()) {
+ // Oneof fields are handled by GenerateOneofField.
+ return;
+ } else {
+ GenerateFieldDocComment(printer, field);
+ printer->Print(
+ "private $^name^ = ^default^;\n",
+ "name", field->name(),
+ "default", DefaultForField(field));
+ }
+
+ if (is_descriptor) {
+ printer->Print(
+ "private $has_^name^ = false;\n",
+ "name", field->name());
+ }
+}
+
+void GenerateOneofField(const OneofDescriptor* oneof, io::Printer* printer) {
+ // Oneof property needs to be protected in order to be accessed by parent
+ // class in implementation.
+ printer->Print(
+ "protected $^name^;\n",
+ "name", oneof->name());
+}
+
+void GenerateFieldAccessor(const FieldDescriptor* field, bool is_descriptor,
+ io::Printer* printer) {
+ const OneofDescriptor* oneof = field->containing_oneof();
+
+ // Generate getter.
+ if (oneof != NULL) {
+ GenerateFieldDocComment(printer, field);
+ printer->Print(
+ "public function get^camel_name^()\n"
+ "{\n"
+ " return $this->readOneof(^number^);\n"
+ "}\n\n",
+ "camel_name", UnderscoresToCamelCase(field->name(), true),
+ "number", IntToString(field->number()));
+ } else {
+ GenerateFieldDocComment(printer, field);
+ printer->Print(
+ "public function get^camel_name^()\n"
+ "{\n"
+ " return $this->^name^;\n"
+ "}\n\n",
+ "camel_name", UnderscoresToCamelCase(field->name(), true), "name",
+ field->name());
+ }
+
+ // Generate setter.
+ GenerateFieldDocComment(printer, field);
+ printer->Print(
+ "public function set^camel_name^(^var^)\n"
+ "{\n",
+ "camel_name", UnderscoresToCamelCase(field->name(), true),
+ "var", (field->is_repeated() ||
+ field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) ?
+ "&$var": "$var");
+
+ Indent(printer);
+
+ // Type check.
+ if (field->is_map()) {
+ const Descriptor* map_entry = field->message_type();
+ const FieldDescriptor* key = map_entry->FindFieldByName("key");
+ const FieldDescriptor* value = map_entry->FindFieldByName("value");
+ printer->Print(
+ "$arr = GPBUtil::checkMapField($var, "
+ "\\Google\\Protobuf\\Internal\\GPBType::^key_type^, "
+ "\\Google\\Protobuf\\Internal\\GPBType::^value_type^",
+ "key_type", ToUpper(key->type_name()),
+ "value_type", ToUpper(value->type_name()));
+ if (value->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
+ printer->Print(
+ ", \\^class_name^);\n",
+ "class_name",
+ MessageName(value->message_type(), is_descriptor) + "::class");
+ } else if (value->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) {
+ printer->Print(
+ ", ^class_name^);\n",
+ "class_name",
+ EnumName(value->enum_type(), is_descriptor) + "::class");
+ } else {
+ printer->Print(");\n");
+ }
+ } else if (field->is_repeated()) {
+ printer->Print(
+ "$arr = GPBUtil::checkRepeatedField($var, "
+ "\\Google\\Protobuf\\Internal\\GPBType::^type^",
+ "type", ToUpper(field->type_name()));
+ if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
+ printer->Print(
+ ", \\^class_name^);\n",
+ "class_name",
+ MessageName(field->message_type(), is_descriptor) + "::class");
+ } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) {
+ printer->Print(
+ ", ^class_name^);\n",
+ "class_name",
+ EnumName(field->enum_type(), is_descriptor) + "::class");
+ } else {
+ printer->Print(");\n");
+ }
+ } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
+ printer->Print(
+ "GPBUtil::checkMessage($var, \\^class_name^::class);\n",
+ "class_name", MessageName(field->message_type(), is_descriptor));
+ } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) {
+ printer->Print(
+ "GPBUtil::checkEnum($var, \\^class_name^::class);\n",
+ "class_name", EnumName(field->enum_type(), is_descriptor));
+ } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_STRING) {
+ printer->Print(
+ "GPBUtil::checkString($var, ^utf8^);\n",
+ "utf8",
+ field->type() == FieldDescriptor::TYPE_STRING ? "True": "False");
+ } else {
+ printer->Print(
+ "GPBUtil::check^type^($var);\n",
+ "type", UnderscoresToCamelCase(field->cpp_type_name(), true));
+ }
+
+ if (oneof != NULL) {
+ printer->Print(
+ "$this->writeOneof(^number^, $var);\n",
+ "number", IntToString(field->number()));
+ } else if (field->is_repeated()) {
+ printer->Print(
+ "$this->^name^ = $arr;\n",
+ "name", field->name());
+ } else {
+ printer->Print(
+ "$this->^name^ = $var;\n",
+ "name", field->name());
+ }
+
+ // Set has bit for proto2 only.
+ if (is_descriptor) {
+ printer->Print(
+ "$this->has_^field_name^ = true;\n",
+ "field_name", field->name());
+ }
+
+ Outdent(printer);
+
+ printer->Print(
+ "}\n\n");
+
+ // Generate has method for proto2 only.
+ if (is_descriptor) {
+ printer->Print(
+ "public function has^camel_name^()\n"
+ "{\n"
+ " return $this->has_^field_name^;\n"
+ "}\n\n",
+ "camel_name", UnderscoresToCamelCase(field->name(), true),
+ "field_name", field->name());
+ }
+}
+
+void GenerateEnumToPool(const EnumDescriptor* en, io::Printer* printer) {
+ printer->Print(
+ "$pool->addEnum('^name^', "
+ "\\Google\\Protobuf\\Internal\\^class_name^::class)\n",
+ "name", EnumFullName(en, true),
+ "class_name", en->name());
+ Indent(printer);
+
+ for (int i = 0; i < en->value_count(); i++) {
+ const EnumValueDescriptor* value = en->value(i);
+ printer->Print(
+ "->value(\"^name^\", ^number^)\n",
+ "name", value->name(),
+ "number", IntToString(value->number()));
+ }
+ printer->Print("->finalizeToPool();\n\n");
+ Outdent(printer);
+}
+
+void GenerateMessageToPool(const string& name_prefix, const Descriptor* message,
+ io::Printer* printer) {
+ // Don't generate MapEntry messages -- we use the PHP extension's native
+ // support for map fields instead.
+ if (message->options().map_entry()) {
+ return;
+ }
+ string class_name = name_prefix.empty()?
+ message->name() : name_prefix + "_" + message->name();
+
+ printer->Print(
+ "$pool->addMessage('^message^', "
+ "\\Google\\Protobuf\\Internal\\^class_name^::class)\n",
+ "message", MessageFullName(message, true),
+ "class_name", class_name);
+
+ Indent(printer);
+
+ for (int i = 0; i < message->field_count(); i++) {
+ const FieldDescriptor* field = message->field(i);
+ if (field->is_map()) {
+ const FieldDescriptor* key =
+ field->message_type()->FindFieldByName("key");
+ const FieldDescriptor* val =
+ field->message_type()->FindFieldByName("value");
+ printer->Print(
+ "->map('^field^', \\Google\\Protobuf\\Internal\\GPBType::^key^, "
+ "\\Google\\Protobuf\\Internal\\GPBType::^value^, ^number^^other^)\n",
+ "field", field->name(),
+ "key", ToUpper(key->type_name()),
+ "value", ToUpper(val->type_name()),
+ "number", SimpleItoa(field->number()),
+ "other", EnumOrMessageSuffix(val, true));
+ } else if (!field->containing_oneof()) {
+ printer->Print(
+ "->^label^('^field^', "
+ "\\Google\\Protobuf\\Internal\\GPBType::^type^, ^number^^other^)\n",
+ "field", field->name(),
+ "label", LabelForField(field),
+ "type", ToUpper(field->type_name()),
+ "number", SimpleItoa(field->number()),
+ "other", EnumOrMessageSuffix(field, true));
+ }
+ }
+
+ // oneofs.
+ for (int i = 0; i < message->oneof_decl_count(); i++) {
+ const OneofDescriptor* oneof = message->oneof_decl(i);
+ printer->Print("->oneof(^name^)\n",
+ "name", oneof->name());
+ Indent(printer);
+ for (int index = 0; index < oneof->field_count(); index++) {
+ const FieldDescriptor* field = oneof->field(index);
+ printer->Print(
+ "->value('^field^', "
+ "\\Google\\Protobuf\\Internal\\GPBType::^type^, ^number^^other^)\n",
+ "field", field->name(),
+ "type", ToUpper(field->type_name()),
+ "number", SimpleItoa(field->number()),
+ "other", EnumOrMessageSuffix(field, true));
+ }
+ printer->Print("->finish()\n");
+ Outdent(printer);
+ }
+
+ printer->Print(
+ "->finalizeToPool();\n");
+
+ Outdent(printer);
+
+ printer->Print(
+ "\n");
+
+ for (int i = 0; i < message->nested_type_count(); i++) {
+ GenerateMessageToPool(class_name, message->nested_type(i), printer);
+ }
+ for (int i = 0; i < message->enum_type_count(); i++) {
+ GenerateEnumToPool(message->enum_type(i), printer);
+ }
+}
+
+void GenerateAddFileToPool(const FileDescriptor* file, bool is_descriptor,
+ io::Printer* printer) {
+ printer->Print(
+ "public static $is_initialized = false;\n\n"
+ "public static function initOnce() {\n");
+ Indent(printer);
+
+ printer->Print(
+ "$pool = \\Google\\Protobuf\\Internal\\"
+ "DescriptorPool::getGeneratedPool();\n\n"
+ "if (static::$is_initialized == true) {\n"
+ " return;\n"
+ "}\n");
+
+ if (is_descriptor) {
+ for (int i = 0; i < file->message_type_count(); i++) {
+ GenerateMessageToPool("", file->message_type(i), printer);
+ }
+ for (int i = 0; i < file->enum_type_count(); i++) {
+ GenerateEnumToPool(file->enum_type(i), printer);
+ }
+
+ printer->Print(
+ "$pool->finish();\n");
+ } else {
+ for (int i = 0; i < file->dependency_count(); i++) {
+ const std::string& name = file->dependency(i)->name();
+ std::string dependency_filename =
+ GeneratedMetadataFileName(name, is_descriptor);
+ printer->Print(
+ "\\^name^::initOnce();\n",
+ "name", FilenameToClassname(dependency_filename));
+ }
+
+ // Add messages and enums to descriptor pool.
+ FileDescriptorSet files;
+ FileDescriptorProto* file_proto = files.add_file();
+ file->CopyTo(file_proto);
+ string files_data;
+ files.SerializeToString(&files_data);
+
+ printer->Print("$pool->internalAddGeneratedFile(hex2bin(\n");
+ Indent(printer);
+
+ // Only write 30 bytes per line.
+ static const int kBytesPerLine = 30;
+ for (int i = 0; i < files_data.size(); i += kBytesPerLine) {
+ printer->Print(
+ "\"^data^\"^dot^\n",
+ "data", BinaryToHex(files_data.substr(i, kBytesPerLine)),
+ "dot", i + kBytesPerLine < files_data.size() ? " ." : "");
+ }
+
+ Outdent(printer);
+ printer->Print(
+ "));\n\n");
+ }
+ printer->Print(
+ "static::$is_initialized = true;\n");
+ Outdent(printer);
+ printer->Print("}\n");
+}
+
+void GenerateUseDeclaration(bool is_descriptor, io::Printer* printer) {
+ if (!is_descriptor) {
+ printer->Print(
+ "use Google\\Protobuf\\Internal\\GPBType;\n"
+ "use Google\\Protobuf\\Internal\\RepeatedField;\n"
+ "use Google\\Protobuf\\Internal\\GPBUtil;\n\n");
+ } else {
+ printer->Print(
+ "use Google\\Protobuf\\Internal\\GPBType;\n"
+ "use Google\\Protobuf\\Internal\\GPBWire;\n"
+ "use Google\\Protobuf\\Internal\\RepeatedField;\n"
+ "use Google\\Protobuf\\Internal\\InputStream;\n\n"
+ "use Google\\Protobuf\\Internal\\GPBUtil;\n\n");
+ }
+}
+
+void GenerateHead(const FileDescriptor* file, io::Printer* printer) {
+ printer->Print(
+ "<?php\n"
+ "# Generated by the protocol buffer compiler. DO NOT EDIT!\n"
+ "# source: ^filename^\n"
+ "\n",
+ "filename", file->name());
+}
+
+std::string FilenameToClassname(const string& filename) {
+ int lastindex = filename.find_last_of(".");
+ std::string result = filename.substr(0, lastindex);
+ for (int i = 0; i < result.size(); i++) {
+ if (result[i] == '/') {
+ result[i] = '\\';
+ }
+ }
+ return result;
+}
+
+void GenerateMetadataFile(const FileDescriptor* file,
+ bool is_descriptor,
+ GeneratorContext* generator_context) {
+ std::string filename = GeneratedMetadataFileName(file->name(), is_descriptor);
+ scoped_ptr<io::ZeroCopyOutputStream> output(
+ generator_context->Open(filename));
+ io::Printer printer(output.get(), '^');
+
+ GenerateHead(file, &printer);
+
+ std::string fullname = FilenameToClassname(filename);
+ int lastindex = fullname.find_last_of("\\");
+
+ printer.Print(
+ "namespace ^name^;\n\n",
+ "name", fullname.substr(0, lastindex));
+
+ if (lastindex != string::npos) {
+ printer.Print(
+ "class ^name^\n"
+ "{\n",
+ "name", fullname.substr(lastindex + 1));
+ } else {
+ printer.Print(
+ "class ^name^\n"
+ "{\n",
+ "name", fullname);
+ }
+ Indent(&printer);
+
+ GenerateAddFileToPool(file, is_descriptor, &printer);
+
+ Outdent(&printer);
+ printer.Print("}\n\n");
+}
+
+void GenerateEnumFile(const FileDescriptor* file, const EnumDescriptor* en,
+ bool is_descriptor, GeneratorContext* generator_context) {
+ std::string filename = GeneratedEnumFileName(en, is_descriptor);
+ scoped_ptr<io::ZeroCopyOutputStream> output(
+ generator_context->Open(filename));
+ io::Printer printer(output.get(), '^');
+
+ GenerateHead(file, &printer);
+
+ std::string fullname = FilenameToClassname(filename);
+ int lastindex = fullname.find_last_of("\\");
+
+ if (!file->package().empty()) {
+ printer.Print(
+ "namespace ^name^;\n\n",
+ "name", fullname.substr(0, lastindex));
+ }
+
+ GenerateEnumDocComment(&printer, en);
+
+ if (lastindex != string::npos) {
+ printer.Print(
+ "class ^name^\n"
+ "{\n",
+ "name", fullname.substr(lastindex + 1));
+ } else {
+ printer.Print(
+ "class ^name^\n"
+ "{\n",
+ "name", fullname);
+ }
+ Indent(&printer);
+
+ for (int i = 0; i < en->value_count(); i++) {
+ const EnumValueDescriptor* value = en->value(i);
+ GenerateEnumValueDocComment(&printer, value);
+ printer.Print("const ^name^ = ^number^;\n",
+ "name", value->name(),
+ "number", IntToString(value->number()));
+ }
+
+ Outdent(&printer);
+ printer.Print("}\n\n");
+}
+
+void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message,
+ bool is_descriptor,
+ GeneratorContext* generator_context) {
+ // Don't generate MapEntry messages -- we use the PHP extension's native
+ // support for map fields instead.
+ if (message->options().map_entry()) {
+ return;
+ }
+
+ std::string filename = GeneratedMessageFileName(message, is_descriptor);
+ scoped_ptr<io::ZeroCopyOutputStream> output(
+ generator_context->Open(filename));
+ io::Printer printer(output.get(), '^');
+
+ GenerateHead(file, &printer);
+
+ std::string fullname = FilenameToClassname(filename);
+ int lastindex = fullname.find_last_of("\\");
+
+ if (!file->package().empty()) {
+ printer.Print(
+ "namespace ^name^;\n\n",
+ "name", fullname.substr(0, lastindex));
+ }
+
+ GenerateUseDeclaration(is_descriptor, &printer);
+
+ GenerateMessageDocComment(&printer, message);
+ if (lastindex != string::npos) {
+ printer.Print(
+ "class ^name^ extends \\Google\\Protobuf\\Internal\\Message\n"
+ "{\n",
+ "name", fullname.substr(lastindex + 1));
+ } else {
+ printer.Print(
+ "class ^name^ extends \\Google\\Protobuf\\Internal\\Message\n"
+ "{\n",
+ "name", fullname);
+ }
+ Indent(&printer);
+
+ // Field and oneof definitions.
+ for (int i = 0; i < message->field_count(); i++) {
+ const FieldDescriptor* field = message->field(i);
+ GenerateField(field, &printer, is_descriptor);
+ }
+ for (int i = 0; i < message->oneof_decl_count(); i++) {
+ const OneofDescriptor* oneof = message->oneof_decl(i);
+ GenerateOneofField(oneof, &printer);
+ }
+ printer.Print("\n");
+
+ printer.Print(
+ "public function __construct() {\n");
+ Indent(&printer);
+
+ std::string metadata_filename =
+ GeneratedMetadataFileName(file->name(), is_descriptor);
+ std::string metadata_fullname = FilenameToClassname(metadata_filename);
+ printer.Print(
+ "\\^fullname^::initOnce();\n"
+ "parent::__construct();\n",
+ "fullname", metadata_fullname);
+
+ Outdent(&printer);
+ printer.Print("}\n\n");
+
+ // Field and oneof accessors.
+ for (int i = 0; i < message->field_count(); i++) {
+ const FieldDescriptor* field = message->field(i);
+ GenerateFieldAccessor(field, is_descriptor, &printer);
+ }
+ for (int i = 0; i < message->oneof_decl_count(); i++) {
+ const OneofDescriptor* oneof = message->oneof_decl(i);
+ printer.Print(
+ "public function get^camel_name^()\n"
+ "{\n"
+ " return $this->whichOneof(\"^name^\");\n"
+ "}\n\n",
+ "camel_name", UnderscoresToCamelCase(oneof->name(), true), "name",
+ oneof->name());
+ }
+
+ Outdent(&printer);
+ printer.Print("}\n\n");
+
+ // Nested messages and enums.
+ for (int i = 0; i < message->nested_type_count(); i++) {
+ GenerateMessageFile(file, message->nested_type(i), is_descriptor,
+ generator_context);
+ }
+ for (int i = 0; i < message->enum_type_count(); i++) {
+ GenerateEnumFile(file, message->enum_type(i), is_descriptor,
+ generator_context);
+ }
+}
+
+void GenerateFile(const FileDescriptor* file, bool is_descriptor,
+ GeneratorContext* generator_context) {
+ GenerateMetadataFile(file, is_descriptor, generator_context);
+ for (int i = 0; i < file->message_type_count(); i++) {
+ GenerateMessageFile(file, file->message_type(i), is_descriptor,
+ generator_context);
+ }
+ for (int i = 0; i < file->enum_type_count(); i++) {
+ GenerateEnumFile(file, file->enum_type(i), is_descriptor,
+ generator_context);
+ }
+}
+
+static string EscapePhpdoc(const string& input) {
+ string result;
+ result.reserve(input.size() * 2);
+
+ char prev = '*';
+
+ for (string::size_type i = 0; i < input.size(); i++) {
+ char c = input[i];
+ switch (c) {
+ case '*':
+ // Avoid "/*".
+ if (prev == '/') {
+ result.append("&#42;");
+ } else {
+ result.push_back(c);
+ }
+ break;
+ case '/':
+ // Avoid "*/".
+ if (prev == '*') {
+ result.append("&#47;");
+ } else {
+ result.push_back(c);
+ }
+ break;
+ case '@':
+ // '@' starts phpdoc tags including the @deprecated tag, which will
+ // cause a compile-time error if inserted before a declaration that
+ // does not have a corresponding @Deprecated annotation.
+ result.append("&#64;");
+ break;
+ case '<':
+ // Avoid interpretation as HTML.
+ result.append("&lt;");
+ break;
+ case '>':
+ // Avoid interpretation as HTML.
+ result.append("&gt;");
+ break;
+ case '&':
+ // Avoid interpretation as HTML.
+ result.append("&amp;");
+ break;
+ case '\\':
+ // Java interprets Unicode escape sequences anywhere!
+ result.append("&#92;");
+ break;
+ default:
+ result.push_back(c);
+ break;
+ }
+
+ prev = c;
+ }
+
+ return result;
+}
+
+static void GenerateDocCommentBodyForLocation(
+ io::Printer* printer, const SourceLocation& location) {
+ string comments = location.leading_comments.empty() ?
+ location.trailing_comments : location.leading_comments;
+ if (!comments.empty()) {
+ // TODO(teboring): Ideally we should parse the comment text as Markdown and
+ // write it back as HTML, but this requires a Markdown parser. For now
+ // we just use <pre> to get fixed-width text formatting.
+
+ // If the comment itself contains block comment start or end markers,
+ // HTML-escape them so that they don't accidentally close the doc comment.
+ comments = EscapePhpdoc(comments);
+
+ vector<string> lines = Split(comments, "\n");
+ while (!lines.empty() && lines.back().empty()) {
+ lines.pop_back();
+ }
+
+ printer->Print(" * <pre>\n");
+ for (int i = 0; i < lines.size(); i++) {
+ // Most lines should start with a space. Watch out for lines that start
+ // with a /, since putting that right after the leading asterisk will
+ // close the comment.
+ if (!lines[i].empty() && lines[i][0] == '/') {
+ printer->Print(" * ^line^\n", "line", lines[i]);
+ } else {
+ printer->Print(" *^line^\n", "line", lines[i]);
+ }
+ }
+ printer->Print(
+ " * </pre>\n"
+ " *\n");
+ }
+}
+
+template <typename DescriptorType>
+static void GenerateDocCommentBody(
+ io::Printer* printer, const DescriptorType* descriptor) {
+ SourceLocation location;
+ if (descriptor->GetSourceLocation(&location)) {
+ GenerateDocCommentBodyForLocation(printer, location);
+ }
+}
+
+static string FirstLineOf(const string& value) {
+ string result = value;
+
+ string::size_type pos = result.find_first_of('\n');
+ if (pos != string::npos) {
+ result.erase(pos);
+ }
+
+ return result;
+}
+
+void GenerateMessageDocComment(io::Printer* printer,
+ const Descriptor* message) {
+ printer->Print("/**\n");
+ GenerateDocCommentBody(printer, message);
+ printer->Print(
+ " * Protobuf type <code>^fullname^</code>\n"
+ " */\n",
+ "fullname", EscapePhpdoc(message->full_name()));
+}
+
+void GenerateFieldDocComment(io::Printer* printer,
+ const FieldDescriptor* field) {
+ // In theory we should have slightly different comments for setters, getters,
+ // etc., but in practice everyone already knows the difference between these
+ // so it's redundant information.
+
+ // We start the comment with the main body based on the comments from the
+ // .proto file (if present). We then end with the field declaration, e.g.:
+ // optional string foo = 5;
+ // If the field is a group, the debug string might end with {.
+ printer->Print("/**\n");
+ GenerateDocCommentBody(printer, field);
+ printer->Print(
+ " * <code>^def^</code>\n",
+ "def", EscapePhpdoc(FirstLineOf(field->DebugString())));
+ printer->Print(" */\n");
+}
+
+void GenerateEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_) {
+ printer->Print("/**\n");
+ GenerateDocCommentBody(printer, enum_);
+ printer->Print(
+ " * Protobuf enum <code>^fullname^</code>\n"
+ " */\n",
+ "fullname", EscapePhpdoc(enum_->full_name()));
+}
+
+void GenerateEnumValueDocComment(io::Printer* printer,
+ const EnumValueDescriptor* value) {
+ printer->Print("/**\n");
+ GenerateDocCommentBody(printer, value);
+ printer->Print(
+ " * <code>^def^</code>\n"
+ " */\n",
+ "def", EscapePhpdoc(FirstLineOf(value->DebugString())));
+}
+
+bool Generator::Generate(const FileDescriptor* file, const string& parameter,
+ GeneratorContext* generator_context,
+ string* error) const {
+ bool is_descriptor = parameter == "internal";
+
+ if (is_descriptor && file->name() != kDescriptorFile) {
+ *error =
+ "Can only generate PHP code for google/protobuf/descriptor.proto.\n";
+ return false;
+ }
+
+ if (!is_descriptor && file->syntax() != FileDescriptor::SYNTAX_PROTO3) {
+ *error =
+ "Can only generate PHP code for proto3 .proto files.\n"
+ "Please add 'syntax = \"proto3\";' to the top of your .proto file.\n";
+ return false;
+ }
+
+ GenerateFile(file, is_descriptor, generator_context);
+
+ return true;
+}
+
+} // namespace php
+} // namespace compiler
+} // namespace protobuf
+} // namespace google
diff --git a/third_party/protobuf/src/google/protobuf/compiler/php/php_generator.h b/third_party/protobuf/src/google/protobuf/compiler/php/php_generator.h
new file mode 100644
index 0000000000..ce2b000adb
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/compiler/php/php_generator.h
@@ -0,0 +1,57 @@
+// 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_COMPILER_PHP_GENERATOR_H__
+#define GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__
+
+#include <google/protobuf/compiler/code_generator.h>
+
+#include <string>
+
+namespace google {
+namespace protobuf {
+namespace compiler {
+namespace php {
+
+class LIBPROTOC_EXPORT Generator
+ : public google::protobuf::compiler::CodeGenerator {
+ virtual bool Generate(
+ const FileDescriptor* file,
+ const string& parameter,
+ GeneratorContext* generator_context,
+ string* error) const;
+};
+
+} // namespace php
+} // namespace compiler
+} // namespace protobuf
+} // namespace google
+
+#endif // GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/plugin.cc b/third_party/protobuf/src/google/protobuf/compiler/plugin.cc
index 56b6374d2c..3848101d1f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/plugin.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/plugin.cc
@@ -38,6 +38,12 @@
#ifdef _WIN32
#include <io.h>
#include <fcntl.h>
+#ifndef STDIN_FILENO
+#define STDIN_FILENO 0
+#endif
+#ifndef STDOUT_FILENO
+#define STDOUT_FILENO 1
+#endif
#else
#include <unistd.h>
#endif
@@ -47,7 +53,6 @@
#include <google/protobuf/compiler/plugin.pb.h>
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/descriptor.h>
-#include <google/protobuf/io/io_win32.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
@@ -57,9 +62,12 @@ namespace compiler {
class GeneratorResponseContext : public GeneratorContext {
public:
- GeneratorResponseContext(CodeGeneratorResponse* response,
- const vector<const FileDescriptor*>& parsed_files)
- : response_(response),
+ GeneratorResponseContext(
+ const Version& compiler_version,
+ CodeGeneratorResponse* response,
+ const std::vector<const FileDescriptor*>& parsed_files)
+ : compiler_version_(compiler_version),
+ response_(response),
parsed_files_(parsed_files) {}
virtual ~GeneratorResponseContext() {}
@@ -79,13 +87,18 @@ class GeneratorResponseContext : public GeneratorContext {
return new io::StringOutputStream(file->mutable_content());
}
- void ListParsedFiles(vector<const FileDescriptor*>* output) {
+ void ListParsedFiles(std::vector<const FileDescriptor*>* output) {
*output = parsed_files_;
}
+ void GetCompilerVersion(Version* version) const {
+ *version = compiler_version_;
+ }
+
private:
+ Version compiler_version_;
CodeGeneratorResponse* response_;
- const vector<const FileDescriptor*>& parsed_files_;
+ const std::vector<const FileDescriptor*>& parsed_files_;
};
bool GenerateCode(const CodeGeneratorRequest& request,
@@ -100,7 +113,7 @@ bool GenerateCode(const CodeGeneratorRequest& request,
}
}
- vector<const FileDescriptor*> parsed_files;
+ std::vector<const FileDescriptor*> parsed_files;
for (int i = 0; i < request.file_to_generate_size(); i++) {
parsed_files.push_back(pool.FindFileByName(request.file_to_generate(i)));
if (parsed_files.back() == NULL) {
@@ -111,37 +124,19 @@ bool GenerateCode(const CodeGeneratorRequest& request,
}
}
- GeneratorResponseContext context(response, parsed_files);
+ GeneratorResponseContext context(
+ request.compiler_version(), response, parsed_files);
- if (generator.HasGenerateAll()) {
- string error;
- bool succeeded = generator.GenerateAll(
- parsed_files, request.parameter(), &context, &error);
+ 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;
- }
- }
+ 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/third_party/protobuf/3.0.0/src/google/protobuf/compiler/plugin.h b/third_party/protobuf/src/google/protobuf/compiler/plugin.h
index d2793a9ff1..d2793a9ff1 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/plugin.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/plugin.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/plugin.pb.cc b/third_party/protobuf/src/google/protobuf/compiler/plugin.pb.cc
index 9064c38234..d044fbbebf 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/plugin.pb.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/plugin.pb.cc
@@ -20,149 +20,682 @@
namespace google {
namespace protobuf {
namespace compiler {
+class VersionDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Version> {
+} _Version_default_instance_;
+class CodeGeneratorRequestDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<CodeGeneratorRequest> {
+} _CodeGeneratorRequest_default_instance_;
+class CodeGeneratorResponse_FileDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<CodeGeneratorResponse_File> {
+} _CodeGeneratorResponse_File_default_instance_;
+class CodeGeneratorResponseDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<CodeGeneratorResponse> {
+} _CodeGeneratorResponse_default_instance_;
+
+namespace protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto {
+
namespace {
-const ::google::protobuf::Descriptor* CodeGeneratorRequest_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- CodeGeneratorRequest_reflection_ = NULL;
-const ::google::protobuf::Descriptor* CodeGeneratorResponse_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- CodeGeneratorResponse_reflection_ = NULL;
-const ::google::protobuf::Descriptor* CodeGeneratorResponse_File_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- CodeGeneratorResponse_File_reflection_ = NULL;
+::google::protobuf::Metadata file_level_metadata[4];
} // namespace
-
-void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto() GOOGLE_ATTRIBUTE_COLD;
-void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto();
- const ::google::protobuf::FileDescriptor* file =
- ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
- "google/protobuf/compiler/plugin.proto");
- GOOGLE_CHECK(file != NULL);
- CodeGeneratorRequest_descriptor_ = file->message_type(0);
- static const int CodeGeneratorRequest_offsets_[3] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, file_to_generate_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, parameter_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, proto_file_),
- };
- CodeGeneratorRequest_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- CodeGeneratorRequest_descriptor_,
- CodeGeneratorRequest::default_instance_,
- CodeGeneratorRequest_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, _has_bits_[0]),
- -1,
- -1,
- sizeof(CodeGeneratorRequest),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, _internal_metadata_),
- -1);
- CodeGeneratorResponse_descriptor_ = file->message_type(1);
- static const int CodeGeneratorResponse_offsets_[2] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse, error_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse, file_),
- };
- CodeGeneratorResponse_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- CodeGeneratorResponse_descriptor_,
- CodeGeneratorResponse::default_instance_,
- CodeGeneratorResponse_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse, _has_bits_[0]),
- -1,
- -1,
- sizeof(CodeGeneratorResponse),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse, _internal_metadata_),
- -1);
- CodeGeneratorResponse_File_descriptor_ = CodeGeneratorResponse_descriptor_->nested_type(0);
- static const int CodeGeneratorResponse_File_offsets_[3] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, insertion_point_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, content_),
- };
- CodeGeneratorResponse_File_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- CodeGeneratorResponse_File_descriptor_,
- CodeGeneratorResponse_File::default_instance_,
- CodeGeneratorResponse_File_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, _has_bits_[0]),
- -1,
- -1,
- sizeof(CodeGeneratorResponse_File),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, _internal_metadata_),
- -1);
-}
+const ::google::protobuf::uint32 TableStruct::offsets[] = {
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, major_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, minor_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, patch_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, suffix_),
+ 1,
+ 2,
+ 3,
+ 0,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, file_to_generate_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, parameter_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, proto_file_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorRequest, compiler_version_),
+ ~0u,
+ 0,
+ ~0u,
+ 1,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, insertion_point_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse_File, content_),
+ 0,
+ 1,
+ 2,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse, error_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(CodeGeneratorResponse, file_),
+ 0,
+ ~0u,
+};
+
+static const ::google::protobuf::internal::MigrationSchema schemas[] = {
+ { 0, 8, sizeof(Version)},
+ { 12, 20, sizeof(CodeGeneratorRequest)},
+ { 24, 31, sizeof(CodeGeneratorResponse_File)},
+ { 34, 40, sizeof(CodeGeneratorResponse)},
+};
+
+static ::google::protobuf::Message const * const file_default_instances[] = {
+ reinterpret_cast<const ::google::protobuf::Message*>(&_Version_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_CodeGeneratorRequest_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_CodeGeneratorResponse_File_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_CodeGeneratorResponse_default_instance_),
+};
namespace {
-GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
-inline void protobuf_AssignDescriptorsOnce() {
- ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
- &protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto);
+void protobuf_AssignDescriptors() {
+ AddDescriptors();
+ ::google::protobuf::MessageFactory* factory = NULL;
+ AssignDescriptors(
+ "google/protobuf/compiler/plugin.proto", schemas, file_default_instances, TableStruct::offsets, factory,
+ file_level_metadata, NULL, NULL);
+}
+
+void protobuf_AssignDescriptorsOnce() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
}
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());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- CodeGeneratorResponse_descriptor_, &CodeGeneratorResponse::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- CodeGeneratorResponse_File_descriptor_, &CodeGeneratorResponse_File::default_instance());
+ ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 4);
}
} // 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 TableStruct::Shutdown() {
+ _Version_default_instance_.Shutdown();
+ delete file_level_metadata[0].reflection;
+ _CodeGeneratorRequest_default_instance_.Shutdown();
+ delete file_level_metadata[1].reflection;
+ _CodeGeneratorResponse_File_default_instance_.Shutdown();
+ delete file_level_metadata[2].reflection;
+ _CodeGeneratorResponse_default_instance_.Shutdown();
+ delete file_level_metadata[3].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 TableStruct::InitDefaultsImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
- ::google::protobuf::protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
+ ::google::protobuf::internal::InitProtobufDefaults();
+ ::google::protobuf::protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ _Version_default_instance_.DefaultConstruct();
+ _CodeGeneratorRequest_default_instance_.DefaultConstruct();
+ _CodeGeneratorResponse_File_default_instance_.DefaultConstruct();
+ _CodeGeneratorResponse_default_instance_.DefaultConstruct();
+ _CodeGeneratorRequest_default_instance_.get_mutable()->compiler_version_ = const_cast< ::google::protobuf::compiler::Version*>(
+ ::google::protobuf::compiler::Version::internal_default_instance());
+}
+
+void InitDefaults() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &TableStruct::InitDefaultsImpl);
+}
+void AddDescriptorsImpl() {
+ InitDefaults();
+ static const char descriptor[] = {
+ "\n%google/protobuf/compiler/plugin.proto\022"
+ "\030google.protobuf.compiler\032 google/protob"
+ "uf/descriptor.proto\"F\n\007Version\022\r\n\005major\030"
+ "\001 \001(\005\022\r\n\005minor\030\002 \001(\005\022\r\n\005patch\030\003 \001(\005\022\016\n\006s"
+ "uffix\030\004 \001(\t\"\272\001\n\024CodeGeneratorRequest\022\030\n\020"
+ "file_to_generate\030\001 \003(\t\022\021\n\tparameter\030\002 \001("
+ "\t\0228\n\nproto_file\030\017 \003(\0132$.google.protobuf."
+ "FileDescriptorProto\022;\n\020compiler_version\030"
+ "\003 \001(\0132!.google.protobuf.compiler.Version"
+ "\"\252\001\n\025CodeGeneratorResponse\022\r\n\005error\030\001 \001("
+ "\t\022B\n\004file\030\017 \003(\01324.google.protobuf.compil"
+ "er.CodeGeneratorResponse.File\032>\n\004File\022\014\n"
+ "\004name\030\001 \001(\t\022\027\n\017insertion_point\030\002 \001(\t\022\017\n\007"
+ "content\030\017 \001(\tBg\n\034com.google.protobuf.com"
+ "pilerB\014PluginProtosZ9github.com/golang/p"
+ "rotobuf/protoc-gen-go/plugin;plugin_go"
+ };
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
- "\n%google/protobuf/compiler/plugin.proto\022"
- "\030google.protobuf.compiler\032 google/protob"
- "uf/descriptor.proto\"}\n\024CodeGeneratorRequ"
- "est\022\030\n\020file_to_generate\030\001 \003(\t\022\021\n\tparamet"
- "er\030\002 \001(\t\0228\n\nproto_file\030\017 \003(\0132$.google.pr"
- "otobuf.FileDescriptorProto\"\252\001\n\025CodeGener"
- "atorResponse\022\r\n\005error\030\001 \001(\t\022B\n\004file\030\017 \003("
- "\01324.google.protobuf.compiler.CodeGenerat"
- "orResponse.File\032>\n\004File\022\014\n\004name\030\001 \001(\t\022\027\n"
- "\017insertion_point\030\002 \001(\t\022\017\n\007content\030\017 \001(\tB"
- "7\n\034com.google.protobuf.compilerB\014PluginP"
- "rotosZ\tplugin_go", 456);
+ descriptor, 638);
::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::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto);
+ ::google::protobuf::protobuf_google_2fprotobuf_2fdescriptor_2eproto::AddDescriptors();
+ ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown);
}
+void AddDescriptors() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
+}
// Force AddDescriptors() to be called at static initialization time.
-struct StaticDescriptorInitializer_google_2fprotobuf_2fcompiler_2fplugin_2eproto {
- StaticDescriptorInitializer_google_2fprotobuf_2fcompiler_2fplugin_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto();
+struct StaticDescriptorInitializer {
+ StaticDescriptorInitializer() {
+ AddDescriptors();
}
-} static_descriptor_initializer_google_2fprotobuf_2fcompiler_2fplugin_2eproto_;
+} static_descriptor_initializer;
+
+} // namespace protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto
+
+
+// ===================================================================
+
+#if !defined(_MSC_VER) || _MSC_VER >= 1900
+const int Version::kMajorFieldNumber;
+const int Version::kMinorFieldNumber;
+const int Version::kPatchFieldNumber;
+const int Version::kSuffixFieldNumber;
+#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
+
+Version::Version()
+ : ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::InitDefaults();
+ }
+ SharedCtor();
+ // @@protoc_insertion_point(constructor:google.protobuf.compiler.Version)
+}
+Version::Version(const Version& from)
+ : ::google::protobuf::Message(),
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ suffix_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_suffix()) {
+ suffix_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.suffix_);
+ }
+ ::memcpy(&major_, &from.major_,
+ reinterpret_cast<char*>(&patch_) -
+ reinterpret_cast<char*>(&major_) + sizeof(patch_));
+ // @@protoc_insertion_point(copy_constructor:google.protobuf.compiler.Version)
+}
+
+void Version::SharedCtor() {
+ _cached_size_ = 0;
+ suffix_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ ::memset(&major_, 0, reinterpret_cast<char*>(&patch_) -
+ reinterpret_cast<char*>(&major_) + sizeof(patch_));
+}
+
+Version::~Version() {
+ // @@protoc_insertion_point(destructor:google.protobuf.compiler.Version)
+ SharedDtor();
+}
+
+void Version::SharedDtor() {
+ suffix_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+
+void Version::SetCachedSize(int size) const {
+ GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+ _cached_size_ = size;
+ GOOGLE_SAFE_CONCURRENT_WRITES_END();
+}
+const ::google::protobuf::Descriptor* Version::descriptor() {
+ protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[0].descriptor;
+}
+
+const Version& Version::default_instance() {
+ protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::InitDefaults();
+ return *internal_default_instance();
+}
+
+Version* Version::New(::google::protobuf::Arena* arena) const {
+ Version* n = new Version;
+ if (arena != NULL) {
+ arena->Own(n);
+ }
+ return n;
+}
+
+void Version::Clear() {
+// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.Version)
+ if (has_suffix()) {
+ GOOGLE_DCHECK(!suffix_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*suffix_.UnsafeRawStringPointer())->clear();
+ }
+ if (_has_bits_[0 / 32] & 14u) {
+ ::memset(&major_, 0, reinterpret_cast<char*>(&patch_) -
+ reinterpret_cast<char*>(&major_) + sizeof(patch_));
+ }
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
+}
+
+bool Version::MergePartialFromCodedStream(
+ ::google::protobuf::io::CodedInputStream* input) {
+#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
+ ::google::protobuf::uint32 tag;
+ // @@protoc_insertion_point(parse_start:google.protobuf.compiler.Version)
+ for (;;) {
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
+ tag = p.first;
+ if (!p.second) goto handle_unusual;
+ switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
+ // optional int32 major = 1;
+ case 1: {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(8u)) {
+ set_has_major();
+ DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
+ ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
+ input, &major_)));
+ } else {
+ goto handle_unusual;
+ }
+ break;
+ }
+
+ // optional int32 minor = 2;
+ case 2: {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(16u)) {
+ set_has_minor();
+ DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
+ ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
+ input, &minor_)));
+ } else {
+ goto handle_unusual;
+ }
+ break;
+ }
+
+ // optional int32 patch = 3;
+ case 3: {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(24u)) {
+ set_has_patch();
+ DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
+ ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
+ input, &patch_)));
+ } else {
+ goto handle_unusual;
+ }
+ break;
+ }
+
+ // optional string suffix = 4;
+ case 4: {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(34u)) {
+ DO_(::google::protobuf::internal::WireFormatLite::ReadString(
+ input, this->mutable_suffix()));
+ ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+ this->suffix().data(), this->suffix().length(),
+ ::google::protobuf::internal::WireFormat::PARSE,
+ "google.protobuf.compiler.Version.suffix");
+ } else {
+ goto handle_unusual;
+ }
+ break;
+ }
+
+ default: {
+ handle_unusual:
+ if (tag == 0 ||
+ ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==
+ ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {
+ goto success;
+ }
+ DO_(::google::protobuf::internal::WireFormat::SkipField(
+ input, tag, mutable_unknown_fields()));
+ break;
+ }
+ }
+ }
+success:
+ // @@protoc_insertion_point(parse_success:google.protobuf.compiler.Version)
+ return true;
+failure:
+ // @@protoc_insertion_point(parse_failure:google.protobuf.compiler.Version)
+ return false;
+#undef DO_
+}
+
+void Version::SerializeWithCachedSizes(
+ ::google::protobuf::io::CodedOutputStream* output) const {
+ // @@protoc_insertion_point(serialize_start:google.protobuf.compiler.Version)
+ // optional int32 major = 1;
+ if (has_major()) {
+ ::google::protobuf::internal::WireFormatLite::WriteInt32(1, this->major(), output);
+ }
+
+ // optional int32 minor = 2;
+ if (has_minor()) {
+ ::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->minor(), output);
+ }
+
+ // optional int32 patch = 3;
+ if (has_patch()) {
+ ::google::protobuf::internal::WireFormatLite::WriteInt32(3, this->patch(), output);
+ }
+
+ // optional string suffix = 4;
+ if (has_suffix()) {
+ ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+ this->suffix().data(), this->suffix().length(),
+ ::google::protobuf::internal::WireFormat::SERIALIZE,
+ "google.protobuf.compiler.Version.suffix");
+ ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
+ 4, this->suffix(), output);
+ }
+
+ if (_internal_metadata_.have_unknown_fields()) {
+ ::google::protobuf::internal::WireFormat::SerializeUnknownFields(
+ unknown_fields(), output);
+ }
+ // @@protoc_insertion_point(serialize_end:google.protobuf.compiler.Version)
+}
+
+::google::protobuf::uint8* Version::InternalSerializeWithCachedSizesToArray(
+ bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
+ // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.Version)
+ // optional int32 major = 1;
+ if (has_major()) {
+ target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(1, this->major(), target);
+ }
+
+ // optional int32 minor = 2;
+ if (has_minor()) {
+ target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->minor(), target);
+ }
+
+ // optional int32 patch = 3;
+ if (has_patch()) {
+ target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(3, this->patch(), target);
+ }
+
+ // optional string suffix = 4;
+ if (has_suffix()) {
+ ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+ this->suffix().data(), this->suffix().length(),
+ ::google::protobuf::internal::WireFormat::SERIALIZE,
+ "google.protobuf.compiler.Version.suffix");
+ target =
+ ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
+ 4, this->suffix(), target);
+ }
+
+ if (_internal_metadata_.have_unknown_fields()) {
+ target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
+ unknown_fields(), target);
+ }
+ // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.compiler.Version)
+ return target;
+}
+
+size_t Version::ByteSizeLong() const {
+// @@protoc_insertion_point(message_byte_size_start:google.protobuf.compiler.Version)
+ size_t total_size = 0;
+
+ if (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
+ if (_has_bits_[0 / 32] & 15u) {
+ // optional string suffix = 4;
+ if (has_suffix()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::StringSize(
+ this->suffix());
+ }
+
+ // optional int32 major = 1;
+ if (has_major()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::Int32Size(
+ this->major());
+ }
+
+ // optional int32 minor = 2;
+ if (has_minor()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::Int32Size(
+ this->minor());
+ }
+
+ // optional int32 patch = 3;
+ if (has_patch()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::Int32Size(
+ this->patch());
+ }
+
+ }
+ int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);
+ GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+ _cached_size_ = cached_size;
+ GOOGLE_SAFE_CONCURRENT_WRITES_END();
+ return total_size;
+}
+
+void Version::MergeFrom(const ::google::protobuf::Message& from) {
+// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.compiler.Version)
+ GOOGLE_DCHECK_NE(&from, this);
+ const Version* source =
+ ::google::protobuf::internal::DynamicCastToGenerated<const Version>(
+ &from);
+ if (source == NULL) {
+ // @@protoc_insertion_point(generalized_merge_from_cast_fail:google.protobuf.compiler.Version)
+ ::google::protobuf::internal::ReflectionOps::Merge(from, this);
+ } else {
+ // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.compiler.Version)
+ MergeFrom(*source);
+ }
+}
+
+void Version::MergeFrom(const Version& from) {
+// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.compiler.Version)
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ if (from._has_bits_[0 / 32] & 15u) {
+ if (from.has_suffix()) {
+ set_has_suffix();
+ suffix_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.suffix_);
+ }
+ if (from.has_major()) {
+ set_major(from.major());
+ }
+ if (from.has_minor()) {
+ set_minor(from.minor());
+ }
+ if (from.has_patch()) {
+ set_patch(from.patch());
+ }
+ }
+}
+
+void Version::CopyFrom(const ::google::protobuf::Message& from) {
+// @@protoc_insertion_point(generalized_copy_from_start:google.protobuf.compiler.Version)
+ if (&from == this) return;
+ Clear();
+ MergeFrom(from);
+}
+
+void Version::CopyFrom(const Version& from) {
+// @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.compiler.Version)
+ if (&from == this) return;
+ Clear();
+ MergeFrom(from);
+}
+
+bool Version::IsInitialized() const {
+ return true;
+}
+
+void Version::Swap(Version* other) {
+ if (other == this) return;
+ InternalSwap(other);
+}
+void Version::InternalSwap(Version* other) {
+ suffix_.Swap(&other->suffix_);
+ std::swap(major_, other->major_);
+ std::swap(minor_, other->minor_);
+ std::swap(patch_, other->patch_);
+ std::swap(_has_bits_[0], other->_has_bits_[0]);
+ _internal_metadata_.Swap(&other->_internal_metadata_);
+ std::swap(_cached_size_, other->_cached_size_);
+}
+
+::google::protobuf::Metadata Version::GetMetadata() const {
+ protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[0];
+}
+
+#if PROTOBUF_INLINE_NOT_IN_HEADERS
+// Version
+
+// optional int32 major = 1;
+bool Version::has_major() const {
+ return (_has_bits_[0] & 0x00000002u) != 0;
+}
+void Version::set_has_major() {
+ _has_bits_[0] |= 0x00000002u;
+}
+void Version::clear_has_major() {
+ _has_bits_[0] &= ~0x00000002u;
+}
+void Version::clear_major() {
+ major_ = 0;
+ clear_has_major();
+}
+::google::protobuf::int32 Version::major() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.compiler.Version.major)
+ return major_;
+}
+void Version::set_major(::google::protobuf::int32 value) {
+ set_has_major();
+ major_ = value;
+ // @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.major)
+}
+
+// optional int32 minor = 2;
+bool Version::has_minor() const {
+ return (_has_bits_[0] & 0x00000004u) != 0;
+}
+void Version::set_has_minor() {
+ _has_bits_[0] |= 0x00000004u;
+}
+void Version::clear_has_minor() {
+ _has_bits_[0] &= ~0x00000004u;
+}
+void Version::clear_minor() {
+ minor_ = 0;
+ clear_has_minor();
+}
+::google::protobuf::int32 Version::minor() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.compiler.Version.minor)
+ return minor_;
+}
+void Version::set_minor(::google::protobuf::int32 value) {
+ set_has_minor();
+ minor_ = value;
+ // @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.minor)
+}
+
+// optional int32 patch = 3;
+bool Version::has_patch() const {
+ return (_has_bits_[0] & 0x00000008u) != 0;
+}
+void Version::set_has_patch() {
+ _has_bits_[0] |= 0x00000008u;
+}
+void Version::clear_has_patch() {
+ _has_bits_[0] &= ~0x00000008u;
+}
+void Version::clear_patch() {
+ patch_ = 0;
+ clear_has_patch();
+}
+::google::protobuf::int32 Version::patch() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.compiler.Version.patch)
+ return patch_;
+}
+void Version::set_patch(::google::protobuf::int32 value) {
+ set_has_patch();
+ patch_ = value;
+ // @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.patch)
+}
+
+// optional string suffix = 4;
+bool Version::has_suffix() const {
+ return (_has_bits_[0] & 0x00000001u) != 0;
+}
+void Version::set_has_suffix() {
+ _has_bits_[0] |= 0x00000001u;
+}
+void Version::clear_has_suffix() {
+ _has_bits_[0] &= ~0x00000001u;
+}
+void Version::clear_suffix() {
+ suffix_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ clear_has_suffix();
+}
+const ::std::string& Version::suffix() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.compiler.Version.suffix)
+ return suffix_.GetNoArena();
+}
+void Version::set_suffix(const ::std::string& value) {
+ set_has_suffix();
+ suffix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
+ // @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.suffix)
+}
+#if LANG_CXX11
+void Version::set_suffix(::std::string&& value) {
+ set_has_suffix();
+ suffix_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.Version.suffix)
+}
+#endif
+void Version::set_suffix(const char* value) {
+ set_has_suffix();
+ suffix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+ // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.Version.suffix)
+}
+void Version::set_suffix(const char* value, size_t size) {
+ set_has_suffix();
+ suffix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+ ::std::string(reinterpret_cast<const char*>(value), size));
+ // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.Version.suffix)
+}
+::std::string* Version::mutable_suffix() {
+ set_has_suffix();
+ // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.Version.suffix)
+ return suffix_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+::std::string* Version::release_suffix() {
+ // @@protoc_insertion_point(field_release:google.protobuf.compiler.Version.suffix)
+ clear_has_suffix();
+ return suffix_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+void Version::set_allocated_suffix(::std::string* suffix) {
+ if (suffix != NULL) {
+ set_has_suffix();
+ } else {
+ clear_has_suffix();
+ }
+ suffix_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), suffix);
+ // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.Version.suffix)
+}
+
+#endif // PROTOBUF_INLINE_NOT_IN_HEADERS
// ===================================================================
@@ -170,30 +703,41 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fcompiler_2fplugin_2eproto
const int CodeGeneratorRequest::kFileToGenerateFieldNumber;
const int CodeGeneratorRequest::kParameterFieldNumber;
const int CodeGeneratorRequest::kProtoFileFieldNumber;
+const int CodeGeneratorRequest::kCompilerVersionFieldNumber;
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
CodeGeneratorRequest::CodeGeneratorRequest()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.compiler.CodeGeneratorRequest)
}
-
-void CodeGeneratorRequest::InitAsDefaultInstance() {
-}
-
CodeGeneratorRequest::CodeGeneratorRequest(const CodeGeneratorRequest& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ file_to_generate_(from.file_to_generate_),
+ proto_file_(from.proto_file_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ parameter_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_parameter()) {
+ parameter_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.parameter_);
+ }
+ if (from.has_compiler_version()) {
+ compiler_version_ = new ::google::protobuf::compiler::Version(*from.compiler_version_);
+ } else {
+ compiler_version_ = NULL;
+ }
// @@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_));
+ compiler_version_ = NULL;
}
CodeGeneratorRequest::~CodeGeneratorRequest() {
@@ -203,7 +747,8 @@ CodeGeneratorRequest::~CodeGeneratorRequest() {
void CodeGeneratorRequest::SharedDtor() {
parameter_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- if (this != default_instance_) {
+ if (this != internal_default_instance()) {
+ delete compiler_version_;
}
}
@@ -213,17 +758,15 @@ void CodeGeneratorRequest::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* CodeGeneratorRequest::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return CodeGeneratorRequest_descriptor_;
+ protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[1].descriptor;
}
const CodeGeneratorRequest& CodeGeneratorRequest::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-CodeGeneratorRequest* CodeGeneratorRequest::default_instance_ = NULL;
-
CodeGeneratorRequest* CodeGeneratorRequest::New(::google::protobuf::Arena* arena) const {
CodeGeneratorRequest* n = new CodeGeneratorRequest;
if (arena != NULL) {
@@ -234,15 +777,20 @@ CodeGeneratorRequest* CodeGeneratorRequest::New(::google::protobuf::Arena* arena
void CodeGeneratorRequest::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.CodeGeneratorRequest)
- if (has_parameter()) {
- parameter_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- }
file_to_generate_.Clear();
proto_file_.Clear();
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
+ if (_has_bits_[0 / 32] & 3u) {
+ if (has_parameter()) {
+ GOOGLE_DCHECK(!parameter_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*parameter_.UnsafeRawStringPointer())->clear();
+ }
+ if (has_compiler_version()) {
+ GOOGLE_DCHECK(compiler_version_ != NULL);
+ compiler_version_->::google::protobuf::compiler::Version::Clear();
+ }
}
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool CodeGeneratorRequest::MergePartialFromCodedStream(
@@ -251,14 +799,14 @@ bool CodeGeneratorRequest::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.compiler.CodeGeneratorRequest)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// repeated string file_to_generate = 1;
case 1: {
- if (tag == 10) {
- parse_file_to_generate:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->add_file_to_generate()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -269,15 +817,13 @@ bool CodeGeneratorRequest::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(10)) goto parse_file_to_generate;
- if (input->ExpectTag(18)) goto parse_parameter;
break;
}
// optional string parameter = 2;
case 2: {
- if (tag == 18) {
- parse_parameter:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_parameter()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -287,24 +833,32 @@ bool CodeGeneratorRequest::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(122)) goto parse_proto_file;
+ break;
+ }
+
+ // optional .google.protobuf.compiler.Version compiler_version = 3;
+ case 3: {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(26u)) {
+ DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
+ input, mutable_compiler_version()));
+ } else {
+ goto handle_unusual;
+ }
break;
}
// repeated .google.protobuf.FileDescriptorProto proto_file = 15;
case 15: {
- if (tag == 122) {
- parse_proto_file:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(122u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_proto_file:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_proto_file()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(122)) goto parse_loop_proto_file;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -334,7 +888,7 @@ void CodeGeneratorRequest::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.compiler.CodeGeneratorRequest)
// repeated string file_to_generate = 1;
- for (int i = 0; i < this->file_to_generate_size(); i++) {
+ for (int i = 0, n = this->file_to_generate_size(); i < n; i++) {
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
this->file_to_generate(i).data(), this->file_to_generate(i).length(),
::google::protobuf::internal::WireFormat::SERIALIZE,
@@ -353,6 +907,12 @@ void CodeGeneratorRequest::SerializeWithCachedSizes(
2, this->parameter(), output);
}
+ // optional .google.protobuf.compiler.Version compiler_version = 3;
+ if (has_compiler_version()) {
+ ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
+ 3, *this->compiler_version_, output);
+ }
+
// repeated .google.protobuf.FileDescriptorProto proto_file = 15;
for (unsigned int i = 0, n = this->proto_file_size(); i < n; i++) {
::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
@@ -368,9 +928,10 @@ void CodeGeneratorRequest::SerializeWithCachedSizes(
::google::protobuf::uint8* CodeGeneratorRequest::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.CodeGeneratorRequest)
// repeated string file_to_generate = 1;
- for (int i = 0; i < this->file_to_generate_size(); i++) {
+ for (int i = 0, n = this->file_to_generate_size(); i < n; i++) {
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
this->file_to_generate(i).data(), this->file_to_generate(i).length(),
::google::protobuf::internal::WireFormat::SERIALIZE,
@@ -390,6 +951,13 @@ void CodeGeneratorRequest::SerializeWithCachedSizes(
2, this->parameter(), target);
}
+ // optional .google.protobuf.compiler.Version compiler_version = 3;
+ if (has_compiler_version()) {
+ target = ::google::protobuf::internal::WireFormatLite::
+ InternalWriteMessageNoVirtualToArray(
+ 3, *this->compiler_version_, false, target);
+ }
+
// repeated .google.protobuf.FileDescriptorProto proto_file = 15;
for (unsigned int i = 0, n = this->proto_file_size(); i < n; i++) {
target = ::google::protobuf::internal::WireFormatLite::
@@ -405,49 +973,61 @@ 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()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::StringSize(
- this->parameter());
+ if (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
}
-
// repeated string file_to_generate = 1;
- total_size += 1 * this->file_to_generate_size();
- for (int i = 0; i < this->file_to_generate_size(); i++) {
+ total_size += 1 *
+ ::google::protobuf::internal::FromIntSize(this->file_to_generate_size());
+ for (int i = 0, n = this->file_to_generate_size(); i < n; 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()) {
- total_size +=
- ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
- unknown_fields());
+ if (_has_bits_[0 / 32] & 3u) {
+ // optional string parameter = 2;
+ if (has_parameter()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::StringSize(
+ this->parameter());
+ }
+
+ // optional .google.protobuf.compiler.Version compiler_version = 3;
+ if (has_compiler_version()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual(
+ *this->compiler_version_);
+ }
+
}
+ 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const CodeGeneratorRequest* source =
::google::protobuf::internal::DynamicCastToGenerated<const CodeGeneratorRequest>(
&from);
if (source == NULL) {
@@ -461,19 +1041,18 @@ void CodeGeneratorRequest::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
file_to_generate_.MergeFrom(from.file_to_generate_);
proto_file_.MergeFrom(from.proto_file_);
- if (from._has_bits_[1 / 32] & (0xffu << (1 % 32))) {
+ if (from._has_bits_[0 / 32] & 3u) {
if (from.has_parameter()) {
set_has_parameter();
parameter_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.parameter_);
}
- }
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
+ if (from.has_compiler_version()) {
+ mutable_compiler_version()->::google::protobuf::compiler::Version::MergeFrom(from.compiler_version());
+ }
}
}
@@ -492,7 +1071,6 @@ void CodeGeneratorRequest::CopyFrom(const CodeGeneratorRequest& from) {
}
bool CodeGeneratorRequest::IsInitialized() const {
-
if (!::google::protobuf::internal::AllAreInitialized(this->proto_file())) return false;
return true;
}
@@ -503,19 +1081,17 @@ void CodeGeneratorRequest::Swap(CodeGeneratorRequest* other) {
}
void CodeGeneratorRequest::InternalSwap(CodeGeneratorRequest* other) {
file_to_generate_.UnsafeArenaSwap(&other->file_to_generate_);
- parameter_.Swap(&other->parameter_);
proto_file_.UnsafeArenaSwap(&other->proto_file_);
+ parameter_.Swap(&other->parameter_);
+ std::swap(compiler_version_, other->compiler_version_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata CodeGeneratorRequest::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = CodeGeneratorRequest_descriptor_;
- metadata.reflection = CodeGeneratorRequest_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[1];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -528,49 +1104,61 @@ 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) {
+#if LANG_CXX11
+void CodeGeneratorRequest::set_file_to_generate(int index, ::std::string&& value) {
+ // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
+ file_to_generate_.Mutable(index)->assign(std::move(value));
+}
+#endif
+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<const char*>(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) {
+#if LANG_CXX11
+void CodeGeneratorRequest::add_file_to_generate(::std::string&& value) {
+ file_to_generate_.Add()->assign(std::move(value));
+ // @@protoc_insertion_point(field_add:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
+}
+#endif
+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<const char*>(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_;
@@ -578,49 +1166,57 @@ CodeGeneratorRequest::mutable_file_to_generate() {
// optional string parameter = 2;
bool CodeGeneratorRequest::has_parameter() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
+ return (_has_bits_[0] & 0x00000001u) != 0;
}
void CodeGeneratorRequest::set_has_parameter() {
- _has_bits_[0] |= 0x00000002u;
+ _has_bits_[0] |= 0x00000001u;
}
void CodeGeneratorRequest::clear_has_parameter() {
- _has_bits_[0] &= ~0x00000002u;
+ _has_bits_[0] &= ~0x00000001u;
}
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());
+ return parameter_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void CodeGeneratorRequest::set_parameter(::std::string&& value) {
+ set_has_parameter();
+ parameter_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.CodeGeneratorRequest.parameter)
+}
+#endif
+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<const char*>(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 {
@@ -660,6 +1256,51 @@ CodeGeneratorRequest::proto_file() const {
return proto_file_;
}
+// optional .google.protobuf.compiler.Version compiler_version = 3;
+bool CodeGeneratorRequest::has_compiler_version() const {
+ return (_has_bits_[0] & 0x00000002u) != 0;
+}
+void CodeGeneratorRequest::set_has_compiler_version() {
+ _has_bits_[0] |= 0x00000002u;
+}
+void CodeGeneratorRequest::clear_has_compiler_version() {
+ _has_bits_[0] &= ~0x00000002u;
+}
+void CodeGeneratorRequest::clear_compiler_version() {
+ if (compiler_version_ != NULL) compiler_version_->::google::protobuf::compiler::Version::Clear();
+ clear_has_compiler_version();
+}
+const ::google::protobuf::compiler::Version& CodeGeneratorRequest::compiler_version() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorRequest.compiler_version)
+ return compiler_version_ != NULL ? *compiler_version_
+ : *::google::protobuf::compiler::Version::internal_default_instance();
+}
+::google::protobuf::compiler::Version* CodeGeneratorRequest::mutable_compiler_version() {
+ set_has_compiler_version();
+ if (compiler_version_ == NULL) {
+ compiler_version_ = new ::google::protobuf::compiler::Version;
+ }
+ // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorRequest.compiler_version)
+ return compiler_version_;
+}
+::google::protobuf::compiler::Version* CodeGeneratorRequest::release_compiler_version() {
+ // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorRequest.compiler_version)
+ clear_has_compiler_version();
+ ::google::protobuf::compiler::Version* temp = compiler_version_;
+ compiler_version_ = NULL;
+ return temp;
+}
+void CodeGeneratorRequest::set_allocated_compiler_version(::google::protobuf::compiler::Version* compiler_version) {
+ delete compiler_version_;
+ compiler_version_ = compiler_version;
+ if (compiler_version) {
+ set_has_compiler_version();
+ } else {
+ clear_has_compiler_version();
+ }
+ // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorRequest.compiler_version)
+}
+
#endif // PROTOBUF_INLINE_NOT_IN_HEADERS
// ===================================================================
@@ -672,28 +1313,38 @@ const int CodeGeneratorResponse_File::kContentFieldNumber;
CodeGeneratorResponse_File::CodeGeneratorResponse_File()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.compiler.CodeGeneratorResponse.File)
}
-
-void CodeGeneratorResponse_File::InitAsDefaultInstance() {
-}
-
CodeGeneratorResponse_File::CodeGeneratorResponse_File(const CodeGeneratorResponse_File& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_name()) {
+ name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
+ }
+ insertion_point_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_insertion_point()) {
+ insertion_point_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.insertion_point_);
+ }
+ content_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_content()) {
+ content_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.content_);
+ }
// @@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() {
@@ -705,8 +1356,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 {
@@ -715,17 +1364,15 @@ void CodeGeneratorResponse_File::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* CodeGeneratorResponse_File::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return CodeGeneratorResponse_File_descriptor_;
+ protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[2].descriptor;
}
const CodeGeneratorResponse_File& CodeGeneratorResponse_File::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-CodeGeneratorResponse_File* CodeGeneratorResponse_File::default_instance_ = NULL;
-
CodeGeneratorResponse_File* CodeGeneratorResponse_File::New(::google::protobuf::Arena* arena) const {
CodeGeneratorResponse_File* n = new CodeGeneratorResponse_File;
if (arena != NULL) {
@@ -738,19 +1385,20 @@ void CodeGeneratorResponse_File::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.CodeGeneratorResponse.File)
if (_has_bits_[0 / 32] & 7u) {
if (has_name()) {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*name_.UnsafeRawStringPointer())->clear();
}
if (has_insertion_point()) {
- insertion_point_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!insertion_point_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*insertion_point_.UnsafeRawStringPointer())->clear();
}
if (has_content()) {
- content_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!content_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*content_.UnsafeRawStringPointer())->clear();
}
}
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
- }
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool CodeGeneratorResponse_File::MergePartialFromCodedStream(
@@ -759,13 +1407,14 @@ bool CodeGeneratorResponse_File::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.compiler.CodeGeneratorResponse.File)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional string name = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -775,14 +1424,13 @@ bool CodeGeneratorResponse_File::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_insertion_point;
break;
}
// optional string insertion_point = 2;
case 2: {
- if (tag == 18) {
- parse_insertion_point:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_insertion_point()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -792,14 +1440,13 @@ bool CodeGeneratorResponse_File::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(122)) goto parse_content;
break;
}
// optional string content = 15;
case 15: {
- if (tag == 122) {
- parse_content:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(122u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_content()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -809,7 +1456,6 @@ bool CodeGeneratorResponse_File::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -877,6 +1523,7 @@ void CodeGeneratorResponse_File::SerializeWithCachedSizes(
::google::protobuf::uint8* CodeGeneratorResponse_File::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.CodeGeneratorResponse.File)
// optional string name = 1;
if (has_name()) {
@@ -919,10 +1566,15 @@ 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 (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
if (_has_bits_[0 / 32] & 7u) {
// optional string name = 1;
if (has_name()) {
@@ -946,23 +1598,17 @@ int CodeGeneratorResponse_File::ByteSize() const {
}
}
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const CodeGeneratorResponse_File* source =
::google::protobuf::internal::DynamicCastToGenerated<const CodeGeneratorResponse_File>(
&from);
if (source == NULL) {
@@ -976,10 +1622,9 @@ void CodeGeneratorResponse_File::MergeFrom(const ::google::protobuf::Message& fr
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 (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ if (from._has_bits_[0 / 32] & 7u) {
if (from.has_name()) {
set_has_name();
name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
@@ -993,9 +1638,6 @@ void CodeGeneratorResponse_File::MergeFrom(const CodeGeneratorResponse_File& fro
content_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.content_);
}
}
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void CodeGeneratorResponse_File::CopyFrom(const ::google::protobuf::Message& from) {
@@ -1013,7 +1655,6 @@ void CodeGeneratorResponse_File::CopyFrom(const CodeGeneratorResponse_File& from
}
bool CodeGeneratorResponse_File::IsInitialized() const {
-
return true;
}
@@ -1031,15 +1672,202 @@ void CodeGeneratorResponse_File::InternalSwap(CodeGeneratorResponse_File* other)
}
::google::protobuf::Metadata CodeGeneratorResponse_File::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = CodeGeneratorResponse_File_descriptor_;
- metadata.reflection = CodeGeneratorResponse_File_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[2];
+}
+
+#if PROTOBUF_INLINE_NOT_IN_HEADERS
+// CodeGeneratorResponse_File
+
+// optional string name = 1;
+bool CodeGeneratorResponse_File::has_name() const {
+ return (_has_bits_[0] & 0x00000001u) != 0;
+}
+void CodeGeneratorResponse_File::set_has_name() {
+ _has_bits_[0] |= 0x00000001u;
+}
+void CodeGeneratorResponse_File::clear_has_name() {
+ _has_bits_[0] &= ~0x00000001u;
+}
+void CodeGeneratorResponse_File::clear_name() {
+ name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ clear_has_name();
+}
+const ::std::string& CodeGeneratorResponse_File::name() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorResponse.File.name)
+ return name_.GetNoArena();
+}
+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)
+}
+#if LANG_CXX11
+void CodeGeneratorResponse_File::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.CodeGeneratorResponse.File.name)
+}
+#endif
+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) {
+ set_has_name();
+ name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+ ::std::string(reinterpret_cast<const char*>(value), size));
+ // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorResponse.File.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() {
+ // @@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) {
+ if (name != NULL) {
+ set_has_name();
+ } else {
+ clear_has_name();
+ }
+ name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name);
+ // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.name)
+}
+
+// optional string insertion_point = 2;
+bool CodeGeneratorResponse_File::has_insertion_point() const {
+ return (_has_bits_[0] & 0x00000002u) != 0;
+}
+void CodeGeneratorResponse_File::set_has_insertion_point() {
+ _has_bits_[0] |= 0x00000002u;
+}
+void CodeGeneratorResponse_File::clear_has_insertion_point() {
+ _has_bits_[0] &= ~0x00000002u;
+}
+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 {
+ // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point)
+ return insertion_point_.GetNoArena();
+}
+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)
+}
+#if LANG_CXX11
+void CodeGeneratorResponse_File::set_insertion_point(::std::string&& value) {
+ set_has_insertion_point();
+ insertion_point_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point)
+}
+#endif
+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) {
+ set_has_insertion_point();
+ insertion_point_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+ ::std::string(reinterpret_cast<const char*>(value), size));
+ // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorResponse.File.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() {
+ // @@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) {
+ if (insertion_point != NULL) {
+ set_has_insertion_point();
+ } else {
+ clear_has_insertion_point();
+ }
+ insertion_point_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), insertion_point);
+ // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point)
+}
+
+// optional string content = 15;
+bool CodeGeneratorResponse_File::has_content() const {
+ return (_has_bits_[0] & 0x00000004u) != 0;
+}
+void CodeGeneratorResponse_File::set_has_content() {
+ _has_bits_[0] |= 0x00000004u;
+}
+void CodeGeneratorResponse_File::clear_has_content() {
+ _has_bits_[0] &= ~0x00000004u;
+}
+void CodeGeneratorResponse_File::clear_content() {
+ content_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ clear_has_content();
+}
+const ::std::string& CodeGeneratorResponse_File::content() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorResponse.File.content)
+ return content_.GetNoArena();
+}
+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)
+}
+#if LANG_CXX11
+void CodeGeneratorResponse_File::set_content(::std::string&& value) {
+ set_has_content();
+ content_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.CodeGeneratorResponse.File.content)
+}
+#endif
+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) {
+ set_has_content();
+ content_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+ ::std::string(reinterpret_cast<const char*>(value), size));
+ // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorResponse.File.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() {
+ // @@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) {
+ if (content != NULL) {
+ set_has_content();
+ } else {
+ clear_has_content();
+ }
+ content_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), content);
+ // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.content)
}
+#endif // PROTOBUF_INLINE_NOT_IN_HEADERS
-// -------------------------------------------------------------------
+// ===================================================================
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int CodeGeneratorResponse::kErrorFieldNumber;
@@ -1048,26 +1876,29 @@ const int CodeGeneratorResponse::kFileFieldNumber;
CodeGeneratorResponse::CodeGeneratorResponse()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.compiler.CodeGeneratorResponse)
}
-
-void CodeGeneratorResponse::InitAsDefaultInstance() {
-}
-
CodeGeneratorResponse::CodeGeneratorResponse(const CodeGeneratorResponse& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ file_(from.file_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ error_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_error()) {
+ error_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.error_);
+ }
// @@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() {
@@ -1077,8 +1908,6 @@ CodeGeneratorResponse::~CodeGeneratorResponse() {
void CodeGeneratorResponse::SharedDtor() {
error_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- if (this != default_instance_) {
- }
}
void CodeGeneratorResponse::SetCachedSize(int size) const {
@@ -1087,17 +1916,15 @@ void CodeGeneratorResponse::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* CodeGeneratorResponse::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return CodeGeneratorResponse_descriptor_;
+ protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[3].descriptor;
}
const CodeGeneratorResponse& CodeGeneratorResponse::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-CodeGeneratorResponse* CodeGeneratorResponse::default_instance_ = NULL;
-
CodeGeneratorResponse* CodeGeneratorResponse::New(::google::protobuf::Arena* arena) const {
CodeGeneratorResponse* n = new CodeGeneratorResponse;
if (arena != NULL) {
@@ -1108,14 +1935,13 @@ CodeGeneratorResponse* CodeGeneratorResponse::New(::google::protobuf::Arena* are
void CodeGeneratorResponse::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.CodeGeneratorResponse)
- if (has_error()) {
- error_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- }
file_.Clear();
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
+ if (has_error()) {
+ GOOGLE_DCHECK(!error_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*error_.UnsafeRawStringPointer())->clear();
}
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool CodeGeneratorResponse::MergePartialFromCodedStream(
@@ -1124,13 +1950,14 @@ bool CodeGeneratorResponse::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.compiler.CodeGeneratorResponse)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional string error = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_error()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -1140,24 +1967,20 @@ bool CodeGeneratorResponse::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(122)) goto parse_file;
break;
}
// repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15;
case 15: {
- if (tag == 122) {
- parse_file:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(122u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_file:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_file()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(122)) goto parse_loop_file;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -1211,6 +2034,7 @@ void CodeGeneratorResponse::SerializeWithCachedSizes(
::google::protobuf::uint8* CodeGeneratorResponse::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.compiler.CodeGeneratorResponse)
// optional string error = 1;
if (has_error()) {
@@ -1238,9 +2062,25 @@ 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;
+
+ if (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
+ // repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15;
+ {
+ 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));
+ }
+ }
// optional string error = 1;
if (has_error()) {
@@ -1249,31 +2089,17 @@ int CodeGeneratorResponse::ByteSize() const {
this->error());
}
- // 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));
- }
-
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const CodeGeneratorResponse* source =
::google::protobuf::internal::DynamicCastToGenerated<const CodeGeneratorResponse>(
&from);
if (source == NULL) {
@@ -1287,18 +2113,12 @@ void CodeGeneratorResponse::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
file_.MergeFrom(from.file_);
- if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
- if (from.has_error()) {
- set_has_error();
- error_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.error_);
- }
- }
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
+ if (from.has_error()) {
+ set_has_error();
+ error_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.error_);
}
}
@@ -1317,7 +2137,6 @@ void CodeGeneratorResponse::CopyFrom(const CodeGeneratorResponse& from) {
}
bool CodeGeneratorResponse::IsInitialized() const {
-
return true;
}
@@ -1326,188 +2145,19 @@ void CodeGeneratorResponse::Swap(CodeGeneratorResponse* other) {
InternalSwap(other);
}
void CodeGeneratorResponse::InternalSwap(CodeGeneratorResponse* other) {
- error_.Swap(&other->error_);
file_.UnsafeArenaSwap(&other->file_);
+ error_.Swap(&other->error_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata CodeGeneratorResponse::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = CodeGeneratorResponse_descriptor_;
- metadata.reflection = CodeGeneratorResponse_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::file_level_metadata[3];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
-// CodeGeneratorResponse_File
-
-// optional string name = 1;
-bool CodeGeneratorResponse_File::has_name() const {
- return (_has_bits_[0] & 0x00000001u) != 0;
-}
-void CodeGeneratorResponse_File::set_has_name() {
- _has_bits_[0] |= 0x00000001u;
-}
-void CodeGeneratorResponse_File::clear_has_name() {
- _has_bits_[0] &= ~0x00000001u;
-}
-void CodeGeneratorResponse_File::clear_name() {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- clear_has_name();
-}
- 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) {
- 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) {
- 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) {
- set_has_name();
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
- // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorResponse.File.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() {
- // @@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) {
- if (name != NULL) {
- set_has_name();
- } else {
- clear_has_name();
- }
- name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name);
- // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.name)
-}
-
-// optional string insertion_point = 2;
-bool CodeGeneratorResponse_File::has_insertion_point() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
-}
-void CodeGeneratorResponse_File::set_has_insertion_point() {
- _has_bits_[0] |= 0x00000002u;
-}
-void CodeGeneratorResponse_File::clear_has_insertion_point() {
- _has_bits_[0] &= ~0x00000002u;
-}
-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 {
- // @@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) {
- 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) {
- 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) {
- set_has_insertion_point();
- insertion_point_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
- // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorResponse.File.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() {
- // @@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) {
- if (insertion_point != NULL) {
- set_has_insertion_point();
- } else {
- clear_has_insertion_point();
- }
- insertion_point_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), insertion_point);
- // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point)
-}
-
-// optional string content = 15;
-bool CodeGeneratorResponse_File::has_content() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
-}
-void CodeGeneratorResponse_File::set_has_content() {
- _has_bits_[0] |= 0x00000004u;
-}
-void CodeGeneratorResponse_File::clear_has_content() {
- _has_bits_[0] &= ~0x00000004u;
-}
-void CodeGeneratorResponse_File::clear_content() {
- content_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- clear_has_content();
-}
- 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) {
- 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) {
- 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) {
- set_has_content();
- content_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
- // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorResponse.File.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() {
- // @@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) {
- if (content != NULL) {
- set_has_content();
- } else {
- clear_has_content();
- }
- content_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), content);
- // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.content)
-}
-
-// -------------------------------------------------------------------
-
// CodeGeneratorResponse
// optional string error = 1;
@@ -1524,37 +2174,45 @@ 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());
+ return error_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void CodeGeneratorResponse::set_error(::std::string&& value) {
+ set_has_error();
+ error_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.CodeGeneratorResponse.error)
+}
+#endif
+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<const char*>(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/third_party/protobuf/3.0.0/src/google/protobuf/compiler/plugin.pb.h b/third_party/protobuf/src/google/protobuf/compiler/plugin.pb.h
index 13eeb69f62..ff8b949f2c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/plugin.pb.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/plugin.pb.h
@@ -8,43 +8,278 @@
#include <google/protobuf/stubs/common.h>
-#if GOOGLE_PROTOBUF_VERSION < 3000000
+#if GOOGLE_PROTOBUF_VERSION < 3002000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
-#if 3000000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
+#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
+#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/metadata.h>
#include <google/protobuf/message.h>
-#include <google/protobuf/repeated_field.h>
-#include <google/protobuf/extension_set.h>
+#include <google/protobuf/repeated_field.h> // IWYU pragma: export
+#include <google/protobuf/extension_set.h> // IWYU pragma: export
#include <google/protobuf/unknown_field_set.h>
#include <google/protobuf/descriptor.pb.h>
// @@protoc_insertion_point(includes)
-
+#ifdef major
+#undef major
+#endif
+#ifdef minor
+#undef minor
+#endif
namespace google {
namespace protobuf {
+class DescriptorProto;
+class DescriptorProtoDefaultTypeInternal;
+LIBPROTOC_EXPORT extern DescriptorProtoDefaultTypeInternal _DescriptorProto_default_instance_;
+class DescriptorProto_ExtensionRange;
+class DescriptorProto_ExtensionRangeDefaultTypeInternal;
+LIBPROTOC_EXPORT extern DescriptorProto_ExtensionRangeDefaultTypeInternal _DescriptorProto_ExtensionRange_default_instance_;
+class DescriptorProto_ReservedRange;
+class DescriptorProto_ReservedRangeDefaultTypeInternal;
+LIBPROTOC_EXPORT extern DescriptorProto_ReservedRangeDefaultTypeInternal _DescriptorProto_ReservedRange_default_instance_;
+class EnumDescriptorProto;
+class EnumDescriptorProtoDefaultTypeInternal;
+LIBPROTOC_EXPORT extern EnumDescriptorProtoDefaultTypeInternal _EnumDescriptorProto_default_instance_;
+class EnumOptions;
+class EnumOptionsDefaultTypeInternal;
+LIBPROTOC_EXPORT extern EnumOptionsDefaultTypeInternal _EnumOptions_default_instance_;
+class EnumValueDescriptorProto;
+class EnumValueDescriptorProtoDefaultTypeInternal;
+LIBPROTOC_EXPORT extern EnumValueDescriptorProtoDefaultTypeInternal _EnumValueDescriptorProto_default_instance_;
+class EnumValueOptions;
+class EnumValueOptionsDefaultTypeInternal;
+LIBPROTOC_EXPORT extern EnumValueOptionsDefaultTypeInternal _EnumValueOptions_default_instance_;
+class FieldDescriptorProto;
+class FieldDescriptorProtoDefaultTypeInternal;
+LIBPROTOC_EXPORT extern FieldDescriptorProtoDefaultTypeInternal _FieldDescriptorProto_default_instance_;
+class FieldOptions;
+class FieldOptionsDefaultTypeInternal;
+LIBPROTOC_EXPORT extern FieldOptionsDefaultTypeInternal _FieldOptions_default_instance_;
+class FileDescriptorProto;
+class FileDescriptorProtoDefaultTypeInternal;
+LIBPROTOC_EXPORT extern FileDescriptorProtoDefaultTypeInternal _FileDescriptorProto_default_instance_;
+class FileDescriptorSet;
+class FileDescriptorSetDefaultTypeInternal;
+LIBPROTOC_EXPORT extern FileDescriptorSetDefaultTypeInternal _FileDescriptorSet_default_instance_;
+class FileOptions;
+class FileOptionsDefaultTypeInternal;
+LIBPROTOC_EXPORT extern FileOptionsDefaultTypeInternal _FileOptions_default_instance_;
+class GeneratedCodeInfo;
+class GeneratedCodeInfoDefaultTypeInternal;
+LIBPROTOC_EXPORT extern GeneratedCodeInfoDefaultTypeInternal _GeneratedCodeInfo_default_instance_;
+class GeneratedCodeInfo_Annotation;
+class GeneratedCodeInfo_AnnotationDefaultTypeInternal;
+LIBPROTOC_EXPORT extern GeneratedCodeInfo_AnnotationDefaultTypeInternal _GeneratedCodeInfo_Annotation_default_instance_;
+class MessageOptions;
+class MessageOptionsDefaultTypeInternal;
+LIBPROTOC_EXPORT extern MessageOptionsDefaultTypeInternal _MessageOptions_default_instance_;
+class MethodDescriptorProto;
+class MethodDescriptorProtoDefaultTypeInternal;
+LIBPROTOC_EXPORT extern MethodDescriptorProtoDefaultTypeInternal _MethodDescriptorProto_default_instance_;
+class MethodOptions;
+class MethodOptionsDefaultTypeInternal;
+LIBPROTOC_EXPORT extern MethodOptionsDefaultTypeInternal _MethodOptions_default_instance_;
+class OneofDescriptorProto;
+class OneofDescriptorProtoDefaultTypeInternal;
+LIBPROTOC_EXPORT extern OneofDescriptorProtoDefaultTypeInternal _OneofDescriptorProto_default_instance_;
+class OneofOptions;
+class OneofOptionsDefaultTypeInternal;
+LIBPROTOC_EXPORT extern OneofOptionsDefaultTypeInternal _OneofOptions_default_instance_;
+class ServiceDescriptorProto;
+class ServiceDescriptorProtoDefaultTypeInternal;
+LIBPROTOC_EXPORT extern ServiceDescriptorProtoDefaultTypeInternal _ServiceDescriptorProto_default_instance_;
+class ServiceOptions;
+class ServiceOptionsDefaultTypeInternal;
+LIBPROTOC_EXPORT extern ServiceOptionsDefaultTypeInternal _ServiceOptions_default_instance_;
+class SourceCodeInfo;
+class SourceCodeInfoDefaultTypeInternal;
+LIBPROTOC_EXPORT extern SourceCodeInfoDefaultTypeInternal _SourceCodeInfo_default_instance_;
+class SourceCodeInfo_Location;
+class SourceCodeInfo_LocationDefaultTypeInternal;
+LIBPROTOC_EXPORT extern SourceCodeInfo_LocationDefaultTypeInternal _SourceCodeInfo_Location_default_instance_;
+class UninterpretedOption;
+class UninterpretedOptionDefaultTypeInternal;
+LIBPROTOC_EXPORT extern UninterpretedOptionDefaultTypeInternal _UninterpretedOption_default_instance_;
+class UninterpretedOption_NamePart;
+class UninterpretedOption_NamePartDefaultTypeInternal;
+LIBPROTOC_EXPORT extern UninterpretedOption_NamePartDefaultTypeInternal _UninterpretedOption_NamePart_default_instance_;
namespace compiler {
-
-// Internal implementation detail -- do not call these.
-void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto();
-void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto();
-void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto();
-
class CodeGeneratorRequest;
+class CodeGeneratorRequestDefaultTypeInternal;
+LIBPROTOC_EXPORT extern CodeGeneratorRequestDefaultTypeInternal _CodeGeneratorRequest_default_instance_;
class CodeGeneratorResponse;
+class CodeGeneratorResponseDefaultTypeInternal;
+LIBPROTOC_EXPORT extern CodeGeneratorResponseDefaultTypeInternal _CodeGeneratorResponse_default_instance_;
class CodeGeneratorResponse_File;
+class CodeGeneratorResponse_FileDefaultTypeInternal;
+LIBPROTOC_EXPORT extern CodeGeneratorResponse_FileDefaultTypeInternal _CodeGeneratorResponse_File_default_instance_;
+class Version;
+class VersionDefaultTypeInternal;
+LIBPROTOC_EXPORT extern VersionDefaultTypeInternal _Version_default_instance_;
+} // namespace compiler
+} // namespace protobuf
+} // namespace google
+
+namespace google {
+namespace protobuf {
+namespace compiler {
+
+namespace protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto {
+// Internal implementation detail -- do not call these.
+struct LIBPROTOC_EXPORT TableStruct {
+ static const ::google::protobuf::uint32 offsets[];
+ static void InitDefaultsImpl();
+ static void Shutdown();
+};
+void LIBPROTOC_EXPORT AddDescriptors();
+void LIBPROTOC_EXPORT InitDefaults();
+} // namespace protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto
// ===================================================================
+class LIBPROTOC_EXPORT Version : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.Version) */ {
+ public:
+ Version();
+ virtual ~Version();
+
+ Version(const Version& from);
+
+ inline Version& operator=(const Version& from) {
+ CopyFrom(from);
+ return *this;
+ }
+
+ inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
+ return _internal_metadata_.unknown_fields();
+ }
+
+ inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
+ return _internal_metadata_.mutable_unknown_fields();
+ }
+
+ static const ::google::protobuf::Descriptor* descriptor();
+ static const Version& default_instance();
+
+ static inline const Version* internal_default_instance() {
+ return reinterpret_cast<const Version*>(
+ &_Version_default_instance_);
+ }
+
+ void Swap(Version* other);
+
+ // implements Message ----------------------------------------------
+
+ inline Version* New() const PROTOBUF_FINAL { return New(NULL); }
+
+ Version* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void CopyFrom(const Version& from);
+ void MergeFrom(const Version& from);
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
+
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
+ bool MergePartialFromCodedStream(
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
+ void SerializeWithCachedSizes(
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
+ }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
+ private:
+ void SharedCtor();
+ void SharedDtor();
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
+ void InternalSwap(Version* other);
+ private:
+ inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
+ return NULL;
+ }
+ inline void* MaybeArenaPtr() const {
+ return NULL;
+ }
+ public:
+
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
+
+ // nested types ----------------------------------------------------
+
+ // accessors -------------------------------------------------------
+
+ // optional string suffix = 4;
+ bool has_suffix() const;
+ void clear_suffix();
+ static const int kSuffixFieldNumber = 4;
+ const ::std::string& suffix() const;
+ void set_suffix(const ::std::string& value);
+ #if LANG_CXX11
+ void set_suffix(::std::string&& value);
+ #endif
+ void set_suffix(const char* value);
+ void set_suffix(const char* value, size_t size);
+ ::std::string* mutable_suffix();
+ ::std::string* release_suffix();
+ void set_allocated_suffix(::std::string* suffix);
+
+ // optional int32 major = 1;
+ bool has_major() const;
+ void clear_major();
+ static const int kMajorFieldNumber = 1;
+ ::google::protobuf::int32 major() const;
+ void set_major(::google::protobuf::int32 value);
+
+ // optional int32 minor = 2;
+ bool has_minor() const;
+ void clear_minor();
+ static const int kMinorFieldNumber = 2;
+ ::google::protobuf::int32 minor() const;
+ void set_minor(::google::protobuf::int32 value);
+
+ // optional int32 patch = 3;
+ bool has_patch() const;
+ void clear_patch();
+ static const int kPatchFieldNumber = 3;
+ ::google::protobuf::int32 patch() const;
+ void set_patch(::google::protobuf::int32 value);
+
+ // @@protoc_insertion_point(class_scope:google.protobuf.compiler.Version)
+ private:
+ void set_has_major();
+ void clear_has_major();
+ void set_has_minor();
+ void clear_has_minor();
+ void set_has_patch();
+ void clear_has_patch();
+ void set_has_suffix();
+ void clear_has_suffix();
+
+ ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
+ ::google::protobuf::internal::HasBits<1> _has_bits_;
+ mutable int _cached_size_;
+ ::google::protobuf::internal::ArenaStringPtr suffix_;
+ ::google::protobuf::int32 major_;
+ ::google::protobuf::int32 minor_;
+ ::google::protobuf::int32 patch_;
+ friend struct protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::TableStruct;
+};
+// -------------------------------------------------------------------
+
class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorRequest) */ {
public:
CodeGeneratorRequest();
@@ -68,46 +303,53 @@ 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 reinterpret_cast<const CodeGeneratorRequest*>(
+ &_CodeGeneratorRequest_default_instance_);
+ }
+
void Swap(CodeGeneratorRequest* other);
// implements Message ----------------------------------------------
- inline CodeGeneratorRequest* New() const { return New(NULL); }
+ inline CodeGeneratorRequest* New() const PROTOBUF_FINAL { return New(NULL); }
- CodeGeneratorRequest* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ CodeGeneratorRequest* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const CodeGeneratorRequest& from);
void MergeFrom(const CodeGeneratorRequest& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(CodeGeneratorRequest* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -120,56 +362,72 @@ class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message
const ::std::string& file_to_generate(int index) const;
::std::string* mutable_file_to_generate(int index);
void set_file_to_generate(int index, const ::std::string& value);
+ #if LANG_CXX11
+ void set_file_to_generate(int index, ::std::string&& value);
+ #endif
void set_file_to_generate(int index, const char* value);
void set_file_to_generate(int index, const char* value, size_t size);
::std::string* add_file_to_generate();
void add_file_to_generate(const ::std::string& value);
+ #if LANG_CXX11
+ void add_file_to_generate(::std::string&& value);
+ #endif
void add_file_to_generate(const char* value);
void add_file_to_generate(const char* value, size_t size);
const ::google::protobuf::RepeatedPtrField< ::std::string>& file_to_generate() const;
::google::protobuf::RepeatedPtrField< ::std::string>* mutable_file_to_generate();
+ // repeated .google.protobuf.FileDescriptorProto proto_file = 15;
+ int proto_file_size() const;
+ void clear_proto_file();
+ static const int kProtoFileFieldNumber = 15;
+ const ::google::protobuf::FileDescriptorProto& proto_file(int index) const;
+ ::google::protobuf::FileDescriptorProto* mutable_proto_file(int index);
+ ::google::protobuf::FileDescriptorProto* add_proto_file();
+ ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >*
+ mutable_proto_file();
+ const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >&
+ proto_file() const;
+
// optional string parameter = 2;
bool has_parameter() const;
void clear_parameter();
static const int kParameterFieldNumber = 2;
const ::std::string& parameter() const;
void set_parameter(const ::std::string& value);
+ #if LANG_CXX11
+ void set_parameter(::std::string&& value);
+ #endif
void set_parameter(const char* value);
void set_parameter(const char* value, size_t size);
::std::string* mutable_parameter();
::std::string* release_parameter();
void set_allocated_parameter(::std::string* parameter);
- // repeated .google.protobuf.FileDescriptorProto proto_file = 15;
- int proto_file_size() const;
- void clear_proto_file();
- static const int kProtoFileFieldNumber = 15;
- const ::google::protobuf::FileDescriptorProto& proto_file(int index) const;
- ::google::protobuf::FileDescriptorProto* mutable_proto_file(int index);
- ::google::protobuf::FileDescriptorProto* add_proto_file();
- ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >*
- mutable_proto_file();
- const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >&
- proto_file() const;
+ // optional .google.protobuf.compiler.Version compiler_version = 3;
+ bool has_compiler_version() const;
+ void clear_compiler_version();
+ static const int kCompilerVersionFieldNumber = 3;
+ const ::google::protobuf::compiler::Version& compiler_version() const;
+ ::google::protobuf::compiler::Version* mutable_compiler_version();
+ ::google::protobuf::compiler::Version* release_compiler_version();
+ void set_allocated_compiler_version(::google::protobuf::compiler::Version* compiler_version);
// @@protoc_insertion_point(class_scope:google.protobuf.compiler.CodeGeneratorRequest)
private:
- inline void set_has_parameter();
- inline void clear_has_parameter();
+ void set_has_parameter();
+ void clear_has_parameter();
+ void set_has_compiler_version();
+ void clear_has_compiler_version();
::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();
- friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto();
-
- void InitAsDefaultInstance();
- static CodeGeneratorRequest* default_instance_;
+ ::google::protobuf::internal::ArenaStringPtr parameter_;
+ ::google::protobuf::compiler::Version* compiler_version_;
+ friend struct protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -196,46 +454,53 @@ 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 reinterpret_cast<const CodeGeneratorResponse_File*>(
+ &_CodeGeneratorResponse_File_default_instance_);
+ }
+
void Swap(CodeGeneratorResponse_File* other);
// implements Message ----------------------------------------------
- inline CodeGeneratorResponse_File* New() const { return New(NULL); }
+ inline CodeGeneratorResponse_File* New() const PROTOBUF_FINAL { return New(NULL); }
- CodeGeneratorResponse_File* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ CodeGeneratorResponse_File* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const CodeGeneratorResponse_File& from);
void MergeFrom(const CodeGeneratorResponse_File& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(CodeGeneratorResponse_File* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -247,6 +512,9 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::M
static const int kNameFieldNumber = 1;
const ::std::string& name() const;
void set_name(const ::std::string& value);
+ #if LANG_CXX11
+ void set_name(::std::string&& value);
+ #endif
void set_name(const char* value);
void set_name(const char* value, size_t size);
::std::string* mutable_name();
@@ -259,6 +527,9 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::M
static const int kInsertionPointFieldNumber = 2;
const ::std::string& insertion_point() const;
void set_insertion_point(const ::std::string& value);
+ #if LANG_CXX11
+ void set_insertion_point(::std::string&& value);
+ #endif
void set_insertion_point(const char* value);
void set_insertion_point(const char* value, size_t size);
::std::string* mutable_insertion_point();
@@ -271,6 +542,9 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::M
static const int kContentFieldNumber = 15;
const ::std::string& content() const;
void set_content(const ::std::string& value);
+ #if LANG_CXX11
+ void set_content(::std::string&& value);
+ #endif
void set_content(const char* value);
void set_content(const char* value, size_t size);
::std::string* mutable_content();
@@ -279,25 +553,20 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::M
// @@protoc_insertion_point(class_scope:google.protobuf.compiler.CodeGeneratorResponse.File)
private:
- inline void set_has_name();
- inline void clear_has_name();
- inline void set_has_insertion_point();
- inline void clear_has_insertion_point();
- inline void set_has_content();
- inline void clear_has_content();
+ void set_has_name();
+ void clear_has_name();
+ void set_has_insertion_point();
+ void clear_has_insertion_point();
+ void set_has_content();
+ 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 protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto();
-
- void InitAsDefaultInstance();
- static CodeGeneratorResponse_File* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -324,46 +593,53 @@ 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 reinterpret_cast<const CodeGeneratorResponse*>(
+ &_CodeGeneratorResponse_default_instance_);
+ }
+
void Swap(CodeGeneratorResponse* other);
// implements Message ----------------------------------------------
- inline CodeGeneratorResponse* New() const { return New(NULL); }
+ inline CodeGeneratorResponse* New() const PROTOBUF_FINAL { return New(NULL); }
- CodeGeneratorResponse* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ CodeGeneratorResponse* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const CodeGeneratorResponse& from);
void MergeFrom(const CodeGeneratorResponse& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(CodeGeneratorResponse* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -371,18 +647,6 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Messag
// accessors -------------------------------------------------------
- // optional string error = 1;
- bool has_error() const;
- void clear_error();
- static const int kErrorFieldNumber = 1;
- const ::std::string& error() const;
- void set_error(const ::std::string& value);
- void set_error(const char* value);
- void set_error(const char* value, size_t size);
- ::std::string* mutable_error();
- ::std::string* release_error();
- void set_allocated_error(::std::string* error);
-
// repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15;
int file_size() const;
void clear_file();
@@ -395,22 +659,32 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Messag
const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::CodeGeneratorResponse_File >&
file() const;
+ // optional string error = 1;
+ bool has_error() const;
+ void clear_error();
+ static const int kErrorFieldNumber = 1;
+ const ::std::string& error() const;
+ void set_error(const ::std::string& value);
+ #if LANG_CXX11
+ void set_error(::std::string&& value);
+ #endif
+ void set_error(const char* value);
+ void set_error(const char* value, size_t size);
+ ::std::string* mutable_error();
+ ::std::string* release_error();
+ void set_allocated_error(::std::string* error);
+
// @@protoc_insertion_point(class_scope:google.protobuf.compiler.CodeGeneratorResponse)
private:
- inline void set_has_error();
- inline void clear_has_error();
+ void set_has_error();
+ 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();
- friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto();
-
- void InitAsDefaultInstance();
- static CodeGeneratorResponse* default_instance_;
+ ::google::protobuf::internal::ArenaStringPtr error_;
+ friend struct protobuf_google_2fprotobuf_2fcompiler_2fplugin_2eproto::TableStruct;
};
// ===================================================================
@@ -418,6 +692,144 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Messag
// ===================================================================
#if !PROTOBUF_INLINE_NOT_IN_HEADERS
+// Version
+
+// optional int32 major = 1;
+inline bool Version::has_major() const {
+ return (_has_bits_[0] & 0x00000002u) != 0;
+}
+inline void Version::set_has_major() {
+ _has_bits_[0] |= 0x00000002u;
+}
+inline void Version::clear_has_major() {
+ _has_bits_[0] &= ~0x00000002u;
+}
+inline void Version::clear_major() {
+ major_ = 0;
+ clear_has_major();
+}
+inline ::google::protobuf::int32 Version::major() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.compiler.Version.major)
+ return major_;
+}
+inline void Version::set_major(::google::protobuf::int32 value) {
+ set_has_major();
+ major_ = value;
+ // @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.major)
+}
+
+// optional int32 minor = 2;
+inline bool Version::has_minor() const {
+ return (_has_bits_[0] & 0x00000004u) != 0;
+}
+inline void Version::set_has_minor() {
+ _has_bits_[0] |= 0x00000004u;
+}
+inline void Version::clear_has_minor() {
+ _has_bits_[0] &= ~0x00000004u;
+}
+inline void Version::clear_minor() {
+ minor_ = 0;
+ clear_has_minor();
+}
+inline ::google::protobuf::int32 Version::minor() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.compiler.Version.minor)
+ return minor_;
+}
+inline void Version::set_minor(::google::protobuf::int32 value) {
+ set_has_minor();
+ minor_ = value;
+ // @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.minor)
+}
+
+// optional int32 patch = 3;
+inline bool Version::has_patch() const {
+ return (_has_bits_[0] & 0x00000008u) != 0;
+}
+inline void Version::set_has_patch() {
+ _has_bits_[0] |= 0x00000008u;
+}
+inline void Version::clear_has_patch() {
+ _has_bits_[0] &= ~0x00000008u;
+}
+inline void Version::clear_patch() {
+ patch_ = 0;
+ clear_has_patch();
+}
+inline ::google::protobuf::int32 Version::patch() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.compiler.Version.patch)
+ return patch_;
+}
+inline void Version::set_patch(::google::protobuf::int32 value) {
+ set_has_patch();
+ patch_ = value;
+ // @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.patch)
+}
+
+// optional string suffix = 4;
+inline bool Version::has_suffix() const {
+ return (_has_bits_[0] & 0x00000001u) != 0;
+}
+inline void Version::set_has_suffix() {
+ _has_bits_[0] |= 0x00000001u;
+}
+inline void Version::clear_has_suffix() {
+ _has_bits_[0] &= ~0x00000001u;
+}
+inline void Version::clear_suffix() {
+ suffix_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ clear_has_suffix();
+}
+inline const ::std::string& Version::suffix() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.compiler.Version.suffix)
+ return suffix_.GetNoArena();
+}
+inline void Version::set_suffix(const ::std::string& value) {
+ set_has_suffix();
+ suffix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
+ // @@protoc_insertion_point(field_set:google.protobuf.compiler.Version.suffix)
+}
+#if LANG_CXX11
+inline void Version::set_suffix(::std::string&& value) {
+ set_has_suffix();
+ suffix_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.Version.suffix)
+}
+#endif
+inline void Version::set_suffix(const char* value) {
+ set_has_suffix();
+ suffix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+ // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.Version.suffix)
+}
+inline void Version::set_suffix(const char* value, size_t size) {
+ set_has_suffix();
+ suffix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+ ::std::string(reinterpret_cast<const char*>(value), size));
+ // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.Version.suffix)
+}
+inline ::std::string* Version::mutable_suffix() {
+ set_has_suffix();
+ // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.Version.suffix)
+ return suffix_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+inline ::std::string* Version::release_suffix() {
+ // @@protoc_insertion_point(field_release:google.protobuf.compiler.Version.suffix)
+ clear_has_suffix();
+ return suffix_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+inline void Version::set_allocated_suffix(::std::string* suffix) {
+ if (suffix != NULL) {
+ set_has_suffix();
+ } else {
+ clear_has_suffix();
+ }
+ suffix_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), suffix);
+ // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.Version.suffix)
+}
+
+// -------------------------------------------------------------------
+
// CodeGeneratorRequest
// repeated string file_to_generate = 1;
@@ -439,6 +851,12 @@ inline void CodeGeneratorRequest::set_file_to_generate(int index, const ::std::s
// @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
file_to_generate_.Mutable(index)->assign(value);
}
+#if LANG_CXX11
+inline void CodeGeneratorRequest::set_file_to_generate(int index, ::std::string&& value) {
+ // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
+ file_to_generate_.Mutable(index)->assign(std::move(value));
+}
+#endif
inline 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)
@@ -456,6 +874,12 @@ inline void CodeGeneratorRequest::add_file_to_generate(const ::std::string& valu
file_to_generate_.Add()->assign(value);
// @@protoc_insertion_point(field_add:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
}
+#if LANG_CXX11
+inline void CodeGeneratorRequest::add_file_to_generate(::std::string&& value) {
+ file_to_generate_.Add()->assign(std::move(value));
+ // @@protoc_insertion_point(field_add:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
+}
+#endif
inline 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)
@@ -477,13 +901,13 @@ CodeGeneratorRequest::mutable_file_to_generate() {
// optional string parameter = 2;
inline bool CodeGeneratorRequest::has_parameter() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
+ return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void CodeGeneratorRequest::set_has_parameter() {
- _has_bits_[0] |= 0x00000002u;
+ _has_bits_[0] |= 0x00000001u;
}
inline void CodeGeneratorRequest::clear_has_parameter() {
- _has_bits_[0] &= ~0x00000002u;
+ _has_bits_[0] &= ~0x00000001u;
}
inline void CodeGeneratorRequest::clear_parameter() {
parameter_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
@@ -491,13 +915,21 @@ inline void CodeGeneratorRequest::clear_parameter() {
}
inline const ::std::string& CodeGeneratorRequest::parameter() const {
// @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorRequest.parameter)
- return parameter_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return parameter_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void CodeGeneratorRequest::set_parameter(::std::string&& value) {
+ set_has_parameter();
+ parameter_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.CodeGeneratorRequest.parameter)
+}
+#endif
inline void CodeGeneratorRequest::set_parameter(const char* value) {
set_has_parameter();
parameter_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -559,6 +991,51 @@ CodeGeneratorRequest::proto_file() const {
return proto_file_;
}
+// optional .google.protobuf.compiler.Version compiler_version = 3;
+inline bool CodeGeneratorRequest::has_compiler_version() const {
+ return (_has_bits_[0] & 0x00000002u) != 0;
+}
+inline void CodeGeneratorRequest::set_has_compiler_version() {
+ _has_bits_[0] |= 0x00000002u;
+}
+inline void CodeGeneratorRequest::clear_has_compiler_version() {
+ _has_bits_[0] &= ~0x00000002u;
+}
+inline void CodeGeneratorRequest::clear_compiler_version() {
+ if (compiler_version_ != NULL) compiler_version_->::google::protobuf::compiler::Version::Clear();
+ clear_has_compiler_version();
+}
+inline const ::google::protobuf::compiler::Version& CodeGeneratorRequest::compiler_version() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorRequest.compiler_version)
+ return compiler_version_ != NULL ? *compiler_version_
+ : *::google::protobuf::compiler::Version::internal_default_instance();
+}
+inline ::google::protobuf::compiler::Version* CodeGeneratorRequest::mutable_compiler_version() {
+ set_has_compiler_version();
+ if (compiler_version_ == NULL) {
+ compiler_version_ = new ::google::protobuf::compiler::Version;
+ }
+ // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorRequest.compiler_version)
+ return compiler_version_;
+}
+inline ::google::protobuf::compiler::Version* CodeGeneratorRequest::release_compiler_version() {
+ // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorRequest.compiler_version)
+ clear_has_compiler_version();
+ ::google::protobuf::compiler::Version* temp = compiler_version_;
+ compiler_version_ = NULL;
+ return temp;
+}
+inline void CodeGeneratorRequest::set_allocated_compiler_version(::google::protobuf::compiler::Version* compiler_version) {
+ delete compiler_version_;
+ compiler_version_ = compiler_version;
+ if (compiler_version) {
+ set_has_compiler_version();
+ } else {
+ clear_has_compiler_version();
+ }
+ // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorRequest.compiler_version)
+}
+
// -------------------------------------------------------------------
// CodeGeneratorResponse_File
@@ -579,13 +1056,21 @@ inline void CodeGeneratorResponse_File::clear_name() {
}
inline 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());
+ return name_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void CodeGeneratorResponse_File::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.CodeGeneratorResponse.File.name)
+}
+#endif
inline void CodeGeneratorResponse_File::set_name(const char* value) {
set_has_name();
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -633,13 +1118,21 @@ inline void CodeGeneratorResponse_File::clear_insertion_point() {
}
inline 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());
+ return insertion_point_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void CodeGeneratorResponse_File::set_insertion_point(::std::string&& value) {
+ set_has_insertion_point();
+ insertion_point_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point)
+}
+#endif
inline void CodeGeneratorResponse_File::set_insertion_point(const char* value) {
set_has_insertion_point();
insertion_point_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -687,13 +1180,21 @@ inline void CodeGeneratorResponse_File::clear_content() {
}
inline 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());
+ return content_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void CodeGeneratorResponse_File::set_content(::std::string&& value) {
+ set_has_content();
+ content_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.CodeGeneratorResponse.File.content)
+}
+#endif
inline void CodeGeneratorResponse_File::set_content(const char* value) {
set_has_content();
content_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -745,13 +1246,21 @@ inline void CodeGeneratorResponse::clear_error() {
}
inline const ::std::string& CodeGeneratorResponse::error() const {
// @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorResponse.error)
- return error_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return error_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void CodeGeneratorResponse::set_error(::std::string&& value) {
+ set_has_error();
+ error_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.compiler.CodeGeneratorResponse.error)
+}
+#endif
inline void CodeGeneratorResponse::set_error(const char* value) {
set_has_error();
error_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -818,9 +1327,12 @@ CodeGeneratorResponse::file() const {
// -------------------------------------------------------------------
+// -------------------------------------------------------------------
+
// @@protoc_insertion_point(namespace_scope)
+
} // namespace compiler
} // namespace protobuf
} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/plugin.proto b/third_party/protobuf/src/google/protobuf/compiler/plugin.proto
index acaee1f494..bf91d76e0f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/plugin.proto
+++ b/third_party/protobuf/src/google/protobuf/compiler/plugin.proto
@@ -49,10 +49,20 @@ package google.protobuf.compiler;
option java_package = "com.google.protobuf.compiler";
option java_outer_classname = "PluginProtos";
-option go_package = "plugin_go";
+option go_package = "github.com/golang/protobuf/protoc-gen-go/plugin;plugin_go";
import "google/protobuf/descriptor.proto";
+// The version number of protocol compiler.
+message Version {
+ optional int32 major = 1;
+ optional int32 minor = 2;
+ optional int32 patch = 3;
+ // A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should
+ // be empty for mainline stable releases.
+ optional string suffix = 4;
+}
+
// An encoded CodeGeneratorRequest is written to the plugin's stdin.
message CodeGeneratorRequest {
// The .proto files that were explicitly listed on the command-line. The
@@ -75,6 +85,9 @@ message CodeGeneratorRequest {
// is not similarly optimized on protoc's end -- it will store all fields in
// memory at once before sending them to the plugin.
repeated FileDescriptorProto proto_file = 15;
+
+ // The version number of protocol compiler.
+ optional Version compiler_version = 3;
}
// The plugin writes an encoded CodeGeneratorResponse to stdout.
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/python/python_generator.cc b/third_party/protobuf/src/google/protobuf/compiler/python/python_generator.cc
index d5468a0cb0..f83f155a82 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/python/python_generator.cc
+++ b/third_party/protobuf/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";
}
@@ -120,7 +120,7 @@ const char* const* kKeywordsEnd =
kKeywords + (sizeof(kKeywords) / sizeof(kKeywords[0]));
bool ContainsPythonKeyword(const string& module_name) {
- vector<string> tokens = Split(module_name, ".");
+ std::vector<string> tokens = Split(module_name, ".");
for (int i = 0; i < tokens.size(); ++i) {
if (std::find(kKeywords, kKeywordsEnd, tokens[i]) != kKeywordsEnd) {
return true;
@@ -230,11 +230,11 @@ string StringifyDefaultValue(const FieldDescriptor& field) {
return SimpleItoa(field.default_value_uint64());
case FieldDescriptor::CPPTYPE_DOUBLE: {
double value = field.default_value_double();
- if (value == numeric_limits<double>::infinity()) {
+ if (value == std::numeric_limits<double>::infinity()) {
// Python pre-2.6 on Windows does not parse "inf" correctly. However,
// a numeric literal that is too big for a double will become infinity.
return "1e10000";
- } else if (value == -numeric_limits<double>::infinity()) {
+ } else if (value == -std::numeric_limits<double>::infinity()) {
// See above.
return "-1e10000";
} else if (value != value) {
@@ -246,11 +246,11 @@ string StringifyDefaultValue(const FieldDescriptor& field) {
}
case FieldDescriptor::CPPTYPE_FLOAT: {
float value = field.default_value_float();
- if (value == numeric_limits<float>::infinity()) {
+ if (value == std::numeric_limits<float>::infinity()) {
// Python pre-2.6 on Windows does not parse "inf" correctly. However,
// a numeric literal that is too big for a double will become infinity.
return "1e10000";
- } else if (value == -numeric_limits<float>::infinity()) {
+ } else if (value == -std::numeric_limits<float>::infinity()) {
// See above.
return "-1e10000";
} else if (value != value) {
@@ -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;
@@ -405,7 +405,7 @@ void Generator::PrintImports() const {
// Prints the single file descriptor for this file.
void Generator::PrintFileDescriptor() const {
- map<string, string> m;
+ std::map<string, string> m;
m["descriptor_name"] = kDescriptorKey;
m["name"] = file_->name();
m["package"] = file_->package();
@@ -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.
@@ -444,7 +453,7 @@ void Generator::PrintFileDescriptor() const {
// Prints descriptors and module-level constants for all top-level
// enums defined in |file|.
void Generator::PrintTopLevelEnums() const {
- vector<pair<string, int> > top_level_enum_values;
+ std::vector<std::pair<string, int> > top_level_enum_values;
for (int i = 0; i < file_->enum_type_count(); ++i) {
const EnumDescriptor& enum_descriptor = *file_->enum_type(i);
PrintEnum(enum_descriptor);
@@ -481,7 +490,7 @@ void Generator::PrintAllNestedEnumsInFile() const {
// enum name to a Python EnumDescriptor object equivalent to
// enum_descriptor.
void Generator::PrintEnum(const EnumDescriptor& enum_descriptor) const {
- map<string, string> m;
+ std::map<string, string> m;
string module_level_descriptor_name =
ModuleLevelDescriptorName(enum_descriptor);
m["descriptor_name"] = module_level_descriptor_name;
@@ -575,7 +584,7 @@ void Generator::PrintServiceDescriptor(
"$service_name$ = _descriptor.ServiceDescriptor(\n",
"service_name", service_name);
printer_->Indent();
- map<string, string> m;
+ std::map<string, string> m;
m["name"] = descriptor.name();
m["full_name"] = descriptor.full_name();
m["file"] = kDescriptorKey;
@@ -671,7 +680,7 @@ void Generator::PrintDescriptor(const Descriptor& message_descriptor) const {
"descriptor_name",
ModuleLevelDescriptorName(message_descriptor));
printer_->Indent();
- map<string, string> m;
+ std::map<string, string> m;
m["name"] = message_descriptor.name();
m["full_name"] = message_descriptor.full_name();
m["file"] = kDescriptorKey;
@@ -731,7 +740,7 @@ void Generator::PrintDescriptor(const Descriptor& message_descriptor) const {
printer_->Indent();
for (int i = 0; i < message_descriptor.oneof_decl_count(); ++i) {
const OneofDescriptor* desc = message_descriptor.oneof_decl(i);
- map<string, string> m;
+ std::map<string, string> m;
m["name"] = desc->name();
m["full_name"] = desc->full_name();
m["index"] = SimpleItoa(desc->index());
@@ -772,7 +781,7 @@ void Generator::PrintNestedDescriptors(
// Prints all messages in |file|.
void Generator::PrintMessages() const {
for (int i = 0; i < file_->message_type_count(); ++i) {
- vector<string> to_register;
+ std::vector<string> to_register;
PrintMessage(*file_->message_type(i), "", &to_register);
for (int j = 0; j < to_register.size(); ++j) {
printer_->Print("_sym_db.RegisterMessage($name$)\n", "name",
@@ -792,7 +801,7 @@ void Generator::PrintMessages() const {
// Collect nested message names to_register for the symbol_database.
void Generator::PrintMessage(const Descriptor& message_descriptor,
const string& prefix,
- vector<string>* to_register) const {
+ std::vector<string>* to_register) const {
string qualified_name(prefix + message_descriptor.name());
to_register->push_back(qualified_name);
printer_->Print(
@@ -802,7 +811,7 @@ void Generator::PrintMessage(const Descriptor& message_descriptor,
printer_->Indent();
PrintNestedMessages(message_descriptor, qualified_name + ".", to_register);
- map<string, string> m;
+ std::map<string, string> m;
m["descriptor_key"] = kDescriptorKey;
m["descriptor_name"] = ModuleLevelDescriptorName(message_descriptor);
printer_->Print(m, "$descriptor_key$ = $descriptor_name$,\n");
@@ -818,7 +827,7 @@ void Generator::PrintMessage(const Descriptor& message_descriptor,
// Mutually recursive with PrintMessage().
void Generator::PrintNestedMessages(const Descriptor& containing_descriptor,
const string& prefix,
- vector<string>* to_register) const {
+ std::vector<string>* to_register) const {
for (int i = 0; i < containing_descriptor.nested_type_count(); ++i) {
printer_->Print("\n");
PrintMessage(*containing_descriptor.nested_type(i), prefix, to_register);
@@ -851,7 +860,7 @@ void Generator::FixForeignFieldsInDescriptor(
FixContainingTypeInDescriptor(enum_descriptor, &descriptor);
}
for (int i = 0; i < descriptor.oneof_decl_count(); ++i) {
- map<string, string> m;
+ std::map<string, string> m;
const OneofDescriptor* oneof = descriptor.oneof_decl(i);
m["descriptor_name"] = ModuleLevelDescriptorName(descriptor);
m["oneof_name"] = oneof->name();
@@ -870,7 +879,7 @@ void Generator::FixForeignFieldsInDescriptor(
}
void Generator::AddMessageToFileDescriptor(const Descriptor& descriptor) const {
- map<string, string> m;
+ std::map<string, string> m;
m["descriptor_name"] = kDescriptorKey;
m["message_name"] = descriptor.name();
m["message_descriptor_name"] = ModuleLevelDescriptorName(descriptor);
@@ -882,7 +891,7 @@ void Generator::AddMessageToFileDescriptor(const Descriptor& descriptor) const {
void Generator::AddEnumToFileDescriptor(
const EnumDescriptor& descriptor) const {
- map<string, string> m;
+ std::map<string, string> m;
m["descriptor_name"] = kDescriptorKey;
m["enum_name"] = descriptor.name();
m["enum_descriptor_name"] = ModuleLevelDescriptorName(descriptor);
@@ -894,7 +903,7 @@ void Generator::AddEnumToFileDescriptor(
void Generator::AddExtensionToFileDescriptor(
const FieldDescriptor& descriptor) const {
- map<string, string> m;
+ std::map<string, string> m;
m["descriptor_name"] = kDescriptorKey;
m["field_name"] = descriptor.name();
const char file_descriptor_template[] =
@@ -917,7 +926,7 @@ void Generator::FixForeignFieldsInField(const Descriptor* containing_type,
const string& python_dict_name) const {
const string field_referencing_expression = FieldReferencingExpression(
containing_type, field, python_dict_name);
- map<string, string> m;
+ std::map<string, string> m;
m["field_ref"] = field_referencing_expression;
const Descriptor* foreign_message_type = field.message_type();
if (foreign_message_type) {
@@ -1016,7 +1025,7 @@ void Generator::FixForeignFieldsInExtension(
FixForeignFieldsInField(extension_field.extension_scope(), extension_field,
"extensions_by_name");
- map<string, string> m;
+ std::map<string, string> m;
// Confusingly, for FieldDescriptors that happen to be extensions,
// containing_type() means "extended type."
// On the other hand, extension_scope() will give us what we normally
@@ -1049,7 +1058,7 @@ void Generator::PrintEnumValueDescriptor(
// More circular references. ::sigh::
string options_string;
descriptor.options().SerializeToString(&options_string);
- map<string, string> m;
+ std::map<string, string> m;
m["name"] = descriptor.name();
m["index"] = SimpleItoa(descriptor.index());
m["number"] = SimpleItoa(descriptor.number());
@@ -1082,7 +1091,7 @@ void Generator::PrintFieldDescriptor(
const FieldDescriptor& field, bool is_extension) const {
string options_string;
field.options().SerializeToString(&options_string);
- map<string, string> m;
+ std::map<string, string> m;
m["name"] = field.name();
m["full_name"] = field.full_name();
m["index"] = SimpleItoa(field.index());
@@ -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);
}
@@ -1369,8 +1380,17 @@ void Generator::FixOptionsForMessage(const Descriptor& descriptor) const {
void Generator::CopyPublicDependenciesAliases(
const string& copy_from, const FileDescriptor* file) const {
for (int i = 0; i < file->public_dependency_count(); ++i) {
+ string module_name = ModuleName(file->public_dependency(i)->name());
string module_alias = ModuleAlias(file->public_dependency(i)->name());
- printer_->Print("$alias$ = $copy_from$.$alias$\n", "alias", module_alias,
+ // There's no module alias in the dependent file if it was generated by
+ // an old protoc (less than 3.0.0-alpha-1). Use module name in this
+ // situation.
+ printer_->Print("try:\n"
+ " $alias$ = $copy_from$.$alias$\n"
+ "except AttributeError:\n"
+ " $alias$ = $copy_from$.$module$\n",
+ "alias", module_alias,
+ "module", module_name,
"copy_from", copy_from);
CopyPublicDependenciesAliases(copy_from, file->public_dependency(i));
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/python/python_generator.h b/third_party/protobuf/src/google/protobuf/compiler/python/python_generator.h
index 7583aa65bf..594260afee 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/python/python_generator.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/python/python_generator.h
@@ -97,10 +97,10 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator {
void PrintMessages() const;
void PrintMessage(const Descriptor& message_descriptor, const string& prefix,
- vector<string>* to_register) const;
+ std::vector<string>* to_register) const;
void PrintNestedMessages(const Descriptor& containing_descriptor,
const string& prefix,
- vector<string>* to_register) const;
+ std::vector<string>* to_register) const;
void FixForeignFieldsInDescriptors() const;
void FixForeignFieldsInDescriptor(
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/python/python_plugin_unittest.cc b/third_party/protobuf/src/google/protobuf/compiler/python/python_plugin_unittest.cc
index 34f857fddb..34f857fddb 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/python/python_plugin_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/python/python_plugin_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/ruby/ruby_generated_code.proto b/third_party/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code.proto
index 42d82a6bac..42d82a6bac 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/ruby/ruby_generated_code.proto
+++ b/third_party/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/ruby/ruby_generated_code_pb.rb b/third_party/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code_pb.rb
index 49b23fbe8d..49b23fbe8d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/ruby/ruby_generated_code_pb.rb
+++ b/third_party/protobuf/src/google/protobuf/compiler/ruby/ruby_generated_code_pb.rb
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/ruby/ruby_generator.cc b/third_party/protobuf/src/google/protobuf/compiler/ruby/ruby_generator.cc
index fbe3b4cb71..fbe3b4cb71 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/ruby/ruby_generator.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/ruby/ruby_generator.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/ruby/ruby_generator.h b/third_party/protobuf/src/google/protobuf/compiler/ruby/ruby_generator.h
index 75555c31b5..8c1dfa2671 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/ruby/ruby_generator.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/ruby/ruby_generator.h
@@ -28,6 +28,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// Generates Ruby code for a given .proto file.
+
#ifndef GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H__
#define GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H__
@@ -40,6 +42,10 @@ namespace protobuf {
namespace compiler {
namespace ruby {
+// CodeGenerator implementation for generated Ruby protocol buffer classes.
+// If you create your own protocol compiler binary and you want it to support
+// Ruby output, you can do so by registering an instance of this
+// CodeGenerator with the CommandLineInterface in your main() function.
class LIBPROTOC_EXPORT Generator
: public google::protobuf::compiler::CodeGenerator {
virtual bool Generate(
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc b/third_party/protobuf/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc
index 1aabe8aa98..1aabe8aa98 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/subprocess.cc b/third_party/protobuf/src/google/protobuf/compiler/subprocess.cc
index 6e25866412..933450faf4 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/subprocess.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/subprocess.cc
@@ -261,12 +261,11 @@ string Subprocess::Win32ErrorMessage(DWORD error_code) {
char* message;
// WTF?
- FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, error_code, 0,
- (LPTSTR)&message, // NOT A BUG!
- 0, NULL);
+ FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, error_code, 0,
+ (LPSTR)&message, // NOT A BUG!
+ 0, NULL);
string result = message;
LocalFree(message);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/subprocess.h b/third_party/protobuf/src/google/protobuf/compiler/subprocess.h
index 2513863144..2513863144 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/subprocess.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/subprocess.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/test_plugin.cc b/third_party/protobuf/src/google/protobuf/compiler/test_plugin.cc
index 4830fd70a0..4830fd70a0 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/test_plugin.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/test_plugin.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/zip_output_unittest.sh b/third_party/protobuf/src/google/protobuf/compiler/zip_output_unittest.sh
index 6fc7136dfa..6fc7136dfa 100755
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/zip_output_unittest.sh
+++ b/third_party/protobuf/src/google/protobuf/compiler/zip_output_unittest.sh
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/zip_writer.cc b/third_party/protobuf/src/google/protobuf/compiler/zip_writer.cc
index 458cced29d..07d52b18cd 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/compiler/zip_writer.cc
+++ b/third_party/protobuf/src/google/protobuf/compiler/zip_writer.cc
@@ -28,36 +28,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// https://developers.google.com/protocol-buffers/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
// Author: ambrose@google.com (Ambrose Feinstein),
// kenton@google.com (Kenton Varda)
//
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/arena_test_util.h b/third_party/protobuf/src/google/protobuf/compiler/zip_writer.h
index 690cc706ee..737f4d42f3 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/arena_test_util.h
+++ b/third_party/protobuf/src/google/protobuf/compiler/zip_writer.h
@@ -28,33 +28,36 @@
// (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_ARENA_TEST_UTIL_H__
-#define GOOGLE_PROTOBUF_ARENA_TEST_UTIL_H__
+// Author: kenton@google.com (Kenton Varda)
+#include <vector>
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/io/zero_copy_stream.h>
namespace google {
namespace protobuf {
-namespace internal {
+namespace compiler {
-class NoHeapChecker {
+class ZipWriter {
public:
- NoHeapChecker() {
- capture_alloc.Hook();
- }
- ~NoHeapChecker();
+ ZipWriter(io::ZeroCopyOutputStream* raw_output);
+ ~ZipWriter();
+
+ bool Write(const string& filename, const string& contents);
+ bool WriteDirectory();
+
private:
- class NewDeleteCapture {
- public:
- // TOOD(xiaofeng): Implement this for opensource protobuf.
- void Hook() {}
- void Unhook() {}
- int alloc_count() { return 0; }
- int free_count() { return 0; }
- } capture_alloc;
+ struct FileInfo {
+ string name;
+ uint32 offset;
+ uint32 size;
+ uint32 crc32;
+ };
+
+ io::ZeroCopyOutputStream* raw_output_;
+ std::vector<FileInfo> files_;
};
-} // namespace internal
+} // namespace compiler
} // namespace protobuf
-
} // namespace google
-#endif // GOOGLE_PROTOBUF_ARENA_TEST_UTIL_H__
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/descriptor.cc b/third_party/protobuf/src/google/protobuf/descriptor.cc
index 9b20946c7f..c87327ce01 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/descriptor.cc
+++ b/third_party/protobuf/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
@@ -207,7 +315,7 @@ string ToCamelCase(const string& input, bool lower_first) {
// be a lot cleaner but we'd just have to convert it back to const char*
// for the open source release.
-typedef pair<const void*, const char*> PointerStringPair;
+typedef std::pair<const void*, const char*> PointerStringPair;
struct PointerStringPairEqual {
inline bool operator()(const PointerStringPair& a,
@@ -235,8 +343,8 @@ struct PointerIntegerPairHash {
}
};
-typedef pair<const Descriptor*, int> DescriptorIntPair;
-typedef pair<const EnumDescriptor*, int> EnumIntPair;
+typedef std::pair<const Descriptor*, int> DescriptorIntPair;
+typedef std::pair<const EnumDescriptor*, int> EnumIntPair;
struct PointerStringPairHash {
size_t operator()(const PointerStringPair& p) const {
@@ -344,11 +452,11 @@ typedef hash_map<EnumIntPair, const EnumValueDescriptor*,
// through all the extensions that extend a given Descriptor, and an
// ordered data structure that implements lower_bound is convenient
// for that.
-typedef map<DescriptorIntPair, const FieldDescriptor*>
+typedef std::map<DescriptorIntPair, const FieldDescriptor*>
ExtensionsGroupedByDescriptorMap;
typedef hash_map<string, const SourceCodeInfo_Location*> LocationsByPathMap;
-set<string>* allowed_proto3_extendees_ = NULL;
+std::set<string>* allowed_proto3_extendees_ = NULL;
GOOGLE_PROTOBUF_DECLARE_ONCE(allowed_proto3_extendees_init_);
void DeleteAllowedProto3Extendee() {
@@ -356,10 +464,10 @@ void DeleteAllowedProto3Extendee() {
}
void InitAllowedProto3Extendee() {
- allowed_proto3_extendees_ = new set<string>;
+ allowed_proto3_extendees_ = new std::set<string>;
const char* kOptionNames[] = {
"FileOptions", "MessageOptions", "FieldOptions", "EnumOptions",
- "EnumValueOptions", "ServiceOptions", "MethodOptions"};
+ "EnumValueOptions", "ServiceOptions", "MethodOptions", "OneofOptions"};
for (int i = 0; i < GOOGLE_ARRAYSIZE(kOptionNames); ++i) {
// descriptor.proto has a different package name in opensource. We allow
// both so the opensource protocol compiler can also compile internal
@@ -434,7 +542,7 @@ class DescriptorPool::Tables {
// The stack of files which are currently being built. Used to detect
// cyclic dependencies when loading files from a DescriptorDatabase. Not
// used when fallback_database_ == NULL.
- vector<string> pending_files_;
+ std::vector<string> pending_files_;
// A set of files which we have tried to load from the fallback database
// and encountered errors. We will not attempt to load them again during
@@ -472,7 +580,7 @@ class DescriptorPool::Tables {
inline const FieldDescriptor* FindExtension(const Descriptor* extendee,
int number);
inline void FindAllExtensions(const Descriptor* extendee,
- vector<const FieldDescriptor*>* out) const;
+ std::vector<const FieldDescriptor*>* out) const;
// -----------------------------------------------------------------
// Adding items.
@@ -512,10 +620,11 @@ class DescriptorPool::Tables {
FileDescriptorTables* AllocateFileTables();
private:
- vector<string*> strings_; // All strings in the pool.
- vector<Message*> messages_; // All messages in the pool.
- vector<FileDescriptorTables*> file_tables_; // All file tables in the pool.
- vector<void*> allocations_; // All other memory allocated in the pool.
+ std::vector<string*> strings_; // All strings in the pool.
+ std::vector<Message*> messages_; // All messages in the pool.
+ std::vector<FileDescriptorTables*>
+ file_tables_; // All file tables in the pool.
+ std::vector<void*> allocations_; // All other memory allocated in the pool.
SymbolsByNameMap symbols_by_name_;
FilesByNameMap files_by_name_;
@@ -542,10 +651,10 @@ class DescriptorPool::Tables {
int pending_files_before_checkpoint;
int pending_extensions_before_checkpoint;
};
- vector<CheckPoint> checkpoints_;
- vector<const char* > symbols_after_checkpoint_;
- vector<const char* > files_after_checkpoint_;
- vector<DescriptorIntPair> extensions_after_checkpoint_;
+ std::vector<CheckPoint> checkpoints_;
+ std::vector<const char* > symbols_after_checkpoint_;
+ std::vector<const char* > files_after_checkpoint_;
+ std::vector<DescriptorIntPair> extensions_after_checkpoint_;
// Allocate some bytes which will be reclaimed when the pool is
// destroyed.
@@ -612,14 +721,14 @@ class FileDescriptorTables {
// Populates p->first->locations_by_path_ from p->second.
// Unusual signature dictated by GoogleOnceDynamic.
static void BuildLocationsByPath(
- pair<const FileDescriptorTables*, const SourceCodeInfo*>* p);
+ std::pair<const FileDescriptorTables*, const SourceCodeInfo*>* p);
// Returns the location denoted by the specified path through info,
// or NULL if not found.
// The value of info must be that of the corresponding FileDescriptor.
// (Conceptually a pure function, but stateful as an optimisation.)
const SourceCodeInfo_Location* GetSourceLocation(
- const vector<int>& path, const SourceCodeInfo* info) const;
+ const std::vector<int>& path, const SourceCodeInfo* info) const;
private:
SymbolsByParentMap symbols_by_parent_;
@@ -900,7 +1009,8 @@ inline const FieldDescriptor* DescriptorPool::Tables::FindExtension(
}
inline void DescriptorPool::Tables::FindAllExtensions(
- const Descriptor* extendee, vector<const FieldDescriptor*>* out) const {
+ const Descriptor* extendee,
+ std::vector<const FieldDescriptor*>* out) const {
ExtensionsGroupedByDescriptorMap::const_iterator it =
extensions_.lower_bound(std::make_pair(extendee, 0));
for (; it != extensions_.end() && it->first.first == extendee; ++it) {
@@ -1020,7 +1130,7 @@ void* DescriptorPool::Tables::AllocateBytes(int size) {
}
void FileDescriptorTables::BuildLocationsByPath(
- pair<const FileDescriptorTables*, const SourceCodeInfo*>* p) {
+ std::pair<const FileDescriptorTables*, const SourceCodeInfo*>* p) {
for (int i = 0, len = p->second->location_size(); i < len; ++i) {
const SourceCodeInfo_Location* loc = &p->second->location().Get(i);
p->first->locations_by_path_[Join(loc->path(), ",")] = loc;
@@ -1028,8 +1138,8 @@ void FileDescriptorTables::BuildLocationsByPath(
}
const SourceCodeInfo_Location* FileDescriptorTables::GetSourceLocation(
- const vector<int>& path, const SourceCodeInfo* info) const {
- pair<const FileDescriptorTables*, const SourceCodeInfo*> p(
+ const std::vector<int>& path, const SourceCodeInfo* info) const {
+ std::pair<const FileDescriptorTables*, const SourceCodeInfo*> p(
std::make_pair(this, info));
locations_by_path_once_.Init(&FileDescriptorTables::BuildLocationsByPath, &p);
return FindPtrOrNull(locations_by_path_, Join(path, ","));
@@ -1131,6 +1241,7 @@ const DescriptorPool* DescriptorPool::generated_pool() {
}
+
DescriptorPool* DescriptorPool::internal_generated_pool() {
InitGeneratedPoolOnce();
return generated_pool_;
@@ -1289,7 +1400,8 @@ const FieldDescriptor* DescriptorPool::FindExtensionByNumber(
}
void DescriptorPool::FindAllExtensions(
- const Descriptor* extendee, vector<const FieldDescriptor*>* out) const {
+ const Descriptor* extendee,
+ std::vector<const FieldDescriptor*>* out) const {
MutexLockMaybe lock(mutex_);
tables_->known_bad_symbols_.clear();
tables_->known_bad_files_.clear();
@@ -1298,7 +1410,7 @@ void DescriptorPool::FindAllExtensions(
// (but do this only once per descriptor).
if (fallback_database_ != NULL &&
tables_->extensions_loaded_from_db_.count(extendee) == 0) {
- vector<int> numbers;
+ std::vector<int> numbers;
if (fallback_database_->FindAllExtensionNumbers(extendee->full_name(),
&numbers)) {
for (int i = 0; i < numbers.size(); ++i) {
@@ -1963,13 +2075,11 @@ void MethodDescriptor::CopyTo(MethodDescriptorProto* proto) const {
namespace {
-// Used by each of the option formatters.
-bool RetrieveOptions(int depth,
- const Message &options,
- vector<string> *option_entries) {
+bool RetrieveOptionsAssumingRightPool(int depth, const Message& options,
+ std::vector<string>* option_entries) {
option_entries->clear();
const Reflection* reflection = options.GetReflection();
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
reflection->ListFields(options, &fields);
for (int i = 0; i < fields.size(); i++) {
int count = 1;
@@ -2006,21 +2116,56 @@ bool RetrieveOptions(int depth,
return !option_entries->empty();
}
+// Used by each of the option formatters.
+bool RetrieveOptions(int depth, const Message& options,
+ const DescriptorPool* pool,
+ std::vector<string>* option_entries) {
+ // When printing custom options for a descriptor, we must use an options
+ // message built on top of the same DescriptorPool where the descriptor
+ // is coming from. This is to ensure we are interpreting custom options
+ // against the right pool.
+ if (options.GetDescriptor()->file()->pool() == pool) {
+ return RetrieveOptionsAssumingRightPool(depth, options, option_entries);
+ } else {
+ const Descriptor* option_descriptor =
+ pool->FindMessageTypeByName(options.GetDescriptor()->full_name());
+ if (option_descriptor == NULL) {
+ // google/protobuf/descriptor.proto is not in the pool. This means no
+ // custom options are used so we are safe to proceed with the compiled
+ // options message type.
+ return RetrieveOptionsAssumingRightPool(depth, options, option_entries);
+ }
+ DynamicMessageFactory factory;
+ google::protobuf::scoped_ptr<Message> dynamic_options(
+ factory.GetPrototype(option_descriptor)->New());
+ if (dynamic_options->ParseFromString(options.SerializeAsString())) {
+ return RetrieveOptionsAssumingRightPool(depth, *dynamic_options,
+ option_entries);
+ } else {
+ GOOGLE_LOG(ERROR) << "Found invalid proto option data for: "
+ << options.GetDescriptor()->full_name();
+ return RetrieveOptionsAssumingRightPool(depth, options, option_entries);
+ }
+ }
+}
+
// Formats options that all appear together in brackets. Does not include
// brackets.
-bool FormatBracketedOptions(int depth, const Message &options, string *output) {
- vector<string> all_options;
- if (RetrieveOptions(depth, options, &all_options)) {
+bool FormatBracketedOptions(int depth, const Message& options,
+ const DescriptorPool* pool, string* output) {
+ std::vector<string> all_options;
+ if (RetrieveOptions(depth, options, pool, &all_options)) {
output->append(Join(all_options, ", "));
}
return !all_options.empty();
}
// Formats options one per line
-bool FormatLineOptions(int depth, const Message &options, string *output) {
+bool FormatLineOptions(int depth, const Message& options,
+ const DescriptorPool* pool, string* output) {
string prefix(depth * 2, ' ');
- vector<string> all_options;
- if (RetrieveOptions(depth, options, &all_options)) {
+ std::vector<string> all_options;
+ if (RetrieveOptions(depth, options, pool, &all_options)) {
for (int i = 0; i < all_options.size(); i++) {
strings::SubstituteAndAppend(output, "$0option $1;\n",
prefix, all_options[i]);
@@ -2042,7 +2187,7 @@ class SourceLocationCommentPrinter {
desc->GetSourceLocation(&source_loc_);
}
SourceLocationCommentPrinter(const FileDescriptor* file,
- const vector<int>& path,
+ const std::vector<int>& path,
const string& prefix,
const DebugStringOptions& options)
: options_(options), prefix_(prefix) {
@@ -2075,7 +2220,7 @@ class SourceLocationCommentPrinter {
string FormatComment(const string& comment_text) {
string stripped_comment = comment_text;
StripWhitespace(&stripped_comment);
- vector<string> lines = Split(stripped_comment, "\n");
+ std::vector<string> lines = Split(stripped_comment, "\n");
string output;
for (int i = 0; i < lines.size(); ++i) {
const string& line = lines[i];
@@ -2103,7 +2248,7 @@ string FileDescriptor::DebugStringWithOptions(
const DebugStringOptions& debug_string_options) const {
string contents;
{
- vector<int> path;
+ std::vector<int> path;
path.push_back(FileDescriptorProto::kSyntaxFieldNumber);
SourceLocationCommentPrinter syntax_comment(
this, path, "", debug_string_options);
@@ -2117,8 +2262,8 @@ string FileDescriptor::DebugStringWithOptions(
comment_printer(this, "", debug_string_options);
comment_printer.AddPreComment(&contents);
- set<int> public_dependencies;
- set<int> weak_dependencies;
+ std::set<int> public_dependencies;
+ std::set<int> weak_dependencies;
public_dependencies.insert(public_dependencies_,
public_dependencies_ + public_dependency_count_);
weak_dependencies.insert(weak_dependencies_,
@@ -2138,7 +2283,7 @@ string FileDescriptor::DebugStringWithOptions(
}
if (!package().empty()) {
- vector<int> path;
+ std::vector<int> path;
path.push_back(FileDescriptorProto::kPackageFieldNumber);
SourceLocationCommentPrinter package_comment(
this, path, "", debug_string_options);
@@ -2147,7 +2292,7 @@ string FileDescriptor::DebugStringWithOptions(
package_comment.AddPostComment(&contents);
}
- if (FormatLineOptions(0, options(), &contents)) {
+ if (FormatLineOptions(0, options(), pool(), &contents)) {
contents.append("\n"); // add some space if we had options
}
@@ -2158,7 +2303,7 @@ string FileDescriptor::DebugStringWithOptions(
// Find all the 'group' type extensions; we will not output their nested
// definitions (those will be done with their group field descriptor).
- set<const Descriptor*> groups;
+ std::set<const Descriptor*> groups;
for (int i = 0; i < extension_count(); i++) {
if (extension(i)->type() == FieldDescriptor::TYPE_GROUP) {
groups.insert(extension(i)->message_type());
@@ -2228,12 +2373,12 @@ void Descriptor::DebugString(int depth, string *contents,
}
contents->append(" {\n");
- FormatLineOptions(depth, options(), contents);
+ FormatLineOptions(depth, options(), file()->pool(), contents);
// Find all the 'group' types for fields and extensions; we will not output
// their nested definitions (those will be done with their group field
// descriptor).
- set<const Descriptor*> groups;
+ std::set<const Descriptor*> groups;
for (int i = 0; i < field_count(); i++) {
if (field(i)->type() == FieldDescriptor::TYPE_GROUP) {
groups.insert(field(i)->message_type());
@@ -2366,8 +2511,18 @@ void FieldDescriptor::DebugString(int depth,
field_type = FieldTypeNameDebugString();
}
+ bool print_label = true;
+ // Determine whether to omit label:
+ // 1. For an optional field, omit label if it's in oneof or in proto3.
+ // 2. For a repeated field, omit label if it's a map.
+ if (is_optional() && (print_label_flag == OMIT_LABEL ||
+ file()->syntax() == FileDescriptor::SYNTAX_PROTO3)) {
+ print_label = false;
+ } else if (is_map()) {
+ print_label = false;
+ }
string label;
- if (print_label_flag == PRINT_LABEL && !is_map()) {
+ if (print_label) {
label = kLabelToName[this->label()];
label.push_back(' ');
}
@@ -2390,9 +2545,21 @@ 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)) {
+ if (FormatBracketedOptions(depth, options(), file()->pool(),
+ &formatted_options)) {
contents->append(bracketed ? ", " : " [");
bracketed = true;
contents->append(formatted_options);
@@ -2436,14 +2603,15 @@ void OneofDescriptor::DebugString(int depth, string* contents,
SourceLocationCommentPrinter
comment_printer(this, prefix, debug_string_options);
comment_printer.AddPreComment(contents);
- strings::SubstituteAndAppend(
- contents, "$0 oneof $1 {", prefix, name());
+ strings::SubstituteAndAppend(contents, "$0oneof $1 {", prefix, name());
- FormatLineOptions(depth, options(), contents);
+ FormatLineOptions(depth, options(), containing_type()->file()->pool(),
+ contents);
if (debug_string_options.elide_oneof_body) {
contents->append(" ... }\n");
} else {
+ contents->append("\n");
for (int i = 0; i < field_count(); i++) {
field(i)->DebugString(depth, FieldDescriptor::OMIT_LABEL, contents,
debug_string_options);
@@ -2478,7 +2646,7 @@ void EnumDescriptor::DebugString(int depth, string *contents,
strings::SubstituteAndAppend(contents, "$0enum $1 {\n",
prefix, name());
- FormatLineOptions(depth, options(), contents);
+ FormatLineOptions(depth, options(), file()->pool(), contents);
for (int i = 0; i < value_count(); i++) {
value(i)->DebugString(depth, contents, debug_string_options);
@@ -2513,7 +2681,8 @@ void EnumValueDescriptor::DebugString(int depth, string *contents,
prefix, name(), number());
string formatted_options;
- if (FormatBracketedOptions(depth, options(), &formatted_options)) {
+ if (FormatBracketedOptions(depth, options(), type()->file()->pool(),
+ &formatted_options)) {
strings::SubstituteAndAppend(contents, " [$0]", formatted_options);
}
contents->append(";\n");
@@ -2542,7 +2711,7 @@ void ServiceDescriptor::DebugString(string *contents,
strings::SubstituteAndAppend(contents, "service $0 {\n", name());
- FormatLineOptions(1, options(), contents);
+ FormatLineOptions(1, options(), file()->pool(), contents);
for (int i = 0; i < method_count(); i++) {
method(i)->DebugString(1, contents, debug_string_options);
@@ -2583,7 +2752,8 @@ void MethodDescriptor::DebugString(int depth, string *contents,
server_streaming() ? "stream " : "");
string formatted_options;
- if (FormatLineOptions(depth, options(), &formatted_options)) {
+ if (FormatLineOptions(depth, options(), service()->file()->pool(),
+ &formatted_options)) {
strings::SubstituteAndAppend(contents, " {\n$0$1}\n",
formatted_options, prefix);
} else {
@@ -2596,7 +2766,7 @@ void MethodDescriptor::DebugString(int depth, string *contents,
// Location methods ===============================================
-bool FileDescriptor::GetSourceLocation(const vector<int>& path,
+bool FileDescriptor::GetSourceLocation(const std::vector<int>& path,
SourceLocation* out_location) const {
GOOGLE_CHECK_NOTNULL(out_location);
if (source_code_info_) {
@@ -2622,7 +2792,7 @@ bool FileDescriptor::GetSourceLocation(const vector<int>& path,
}
bool FileDescriptor::GetSourceLocation(SourceLocation* out_location) const {
- vector<int> path; // empty path for root FileDescriptor
+ std::vector<int> path; // empty path for root FileDescriptor
return GetSourceLocation(path, out_location);
}
@@ -2636,49 +2806,49 @@ bool FieldDescriptor::is_packed() const {
}
bool Descriptor::GetSourceLocation(SourceLocation* out_location) const {
- vector<int> path;
+ std::vector<int> path;
GetLocationPath(&path);
return file()->GetSourceLocation(path, out_location);
}
bool FieldDescriptor::GetSourceLocation(SourceLocation* out_location) const {
- vector<int> path;
+ std::vector<int> path;
GetLocationPath(&path);
return file()->GetSourceLocation(path, out_location);
}
bool OneofDescriptor::GetSourceLocation(SourceLocation* out_location) const {
- vector<int> path;
+ std::vector<int> path;
GetLocationPath(&path);
return containing_type()->file()->GetSourceLocation(path, out_location);
}
bool EnumDescriptor::GetSourceLocation(SourceLocation* out_location) const {
- vector<int> path;
+ std::vector<int> path;
GetLocationPath(&path);
return file()->GetSourceLocation(path, out_location);
}
bool MethodDescriptor::GetSourceLocation(SourceLocation* out_location) const {
- vector<int> path;
+ std::vector<int> path;
GetLocationPath(&path);
return service()->file()->GetSourceLocation(path, out_location);
}
bool ServiceDescriptor::GetSourceLocation(SourceLocation* out_location) const {
- vector<int> path;
+ std::vector<int> path;
GetLocationPath(&path);
return file()->GetSourceLocation(path, out_location);
}
bool EnumValueDescriptor::GetSourceLocation(
SourceLocation* out_location) const {
- vector<int> path;
+ std::vector<int> path;
GetLocationPath(&path);
return type()->file()->GetSourceLocation(path, out_location);
}
-void Descriptor::GetLocationPath(vector<int>* output) const {
+void Descriptor::GetLocationPath(std::vector<int>* output) const {
if (containing_type()) {
containing_type()->GetLocationPath(output);
output->push_back(DescriptorProto::kNestedTypeFieldNumber);
@@ -2689,7 +2859,7 @@ void Descriptor::GetLocationPath(vector<int>* output) const {
}
}
-void FieldDescriptor::GetLocationPath(vector<int>* output) const {
+void FieldDescriptor::GetLocationPath(std::vector<int>* output) const {
if (is_extension()) {
if (extension_scope() == NULL) {
output->push_back(FileDescriptorProto::kExtensionFieldNumber);
@@ -2706,13 +2876,13 @@ void FieldDescriptor::GetLocationPath(vector<int>* output) const {
}
}
-void OneofDescriptor::GetLocationPath(vector<int>* output) const {
+void OneofDescriptor::GetLocationPath(std::vector<int>* output) const {
containing_type()->GetLocationPath(output);
output->push_back(DescriptorProto::kOneofDeclFieldNumber);
output->push_back(index());
}
-void EnumDescriptor::GetLocationPath(vector<int>* output) const {
+void EnumDescriptor::GetLocationPath(std::vector<int>* output) const {
if (containing_type()) {
containing_type()->GetLocationPath(output);
output->push_back(DescriptorProto::kEnumTypeFieldNumber);
@@ -2723,18 +2893,18 @@ void EnumDescriptor::GetLocationPath(vector<int>* output) const {
}
}
-void EnumValueDescriptor::GetLocationPath(vector<int>* output) const {
+void EnumValueDescriptor::GetLocationPath(std::vector<int>* output) const {
type()->GetLocationPath(output);
output->push_back(EnumDescriptorProto::kValueFieldNumber);
output->push_back(index());
}
-void ServiceDescriptor::GetLocationPath(vector<int>* output) const {
+void ServiceDescriptor::GetLocationPath(std::vector<int>* output) const {
output->push_back(FileDescriptorProto::kServiceFieldNumber);
output->push_back(index());
}
-void MethodDescriptor::GetLocationPath(vector<int>* output) const {
+void MethodDescriptor::GetLocationPath(std::vector<int>* output) const {
service()->GetLocationPath(output);
output->push_back(ServiceDescriptorProto::kMethodFieldNumber);
output->push_back(index());
@@ -2789,17 +2959,17 @@ class DescriptorBuilder {
// As we build descriptors we store copies of the options messages in
// them. We put pointers to those copies in this vector, as we build, so we
// can later (after cross-linking) interpret those options.
- vector<OptionsToInterpret> options_to_interpret_;
+ std::vector<OptionsToInterpret> options_to_interpret_;
bool had_errors_;
string filename_;
FileDescriptor* file_;
FileDescriptorTables* file_tables_;
- set<const FileDescriptor*> dependencies_;
+ std::set<const FileDescriptor*> dependencies_;
// unused_dependency_ is used to record the unused imported files.
// Note: public import is not considered.
- set<const FileDescriptor*> unused_dependency_;
+ std::set<const FileDescriptor*> unused_dependency_;
// If LookupSymbol() finds a symbol that is in a file which is not a declared
// dependency of this file, it will fail, but will set
@@ -2980,6 +3150,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);
@@ -3050,8 +3222,10 @@ class DescriptorBuilder {
// in unknown_fields to check if field innermost_field is set on the
// innermost message. Returns false and sets an error if so.
bool ExamineIfOptionIsSet(
- vector<const FieldDescriptor*>::const_iterator intermediate_fields_iter,
- vector<const FieldDescriptor*>::const_iterator intermediate_fields_end,
+ std::vector<const FieldDescriptor*>::const_iterator
+ intermediate_fields_iter,
+ std::vector<const FieldDescriptor*>::const_iterator
+ intermediate_fields_end,
const FieldDescriptor* innermost_field, const string& debug_msg_name,
const UnknownFieldSet& unknown_fields);
@@ -3377,7 +3551,8 @@ Symbol DescriptorBuilder::FindSymbol(const string& name) {
// dependency also defines the same package. We can't really rule out this
// symbol unless none of the dependencies define it.
if (IsInPackage(file_, name)) return result;
- for (set<const FileDescriptor*>::const_iterator it = dependencies_.begin();
+ for (std::set<const FileDescriptor*>::const_iterator it =
+ dependencies_.begin();
it != dependencies_.end(); ++it) {
// Note: A dependency may be NULL if it was not found or had errors.
if (*it != NULL && IsInPackage(*it, name)) return result;
@@ -3596,9 +3771,13 @@ bool DescriptorBuilder::AddSymbol(
if (tables_->AddSymbol(full_name, symbol)) {
if (!file_tables_->AddAliasUnderParent(parent, name, symbol)) {
- GOOGLE_LOG(DFATAL) << "\"" << full_name << "\" not previously defined in "
- "symbols_by_name_, but was defined in symbols_by_parent_; "
- "this shouldn't be possible.";
+ // This is only possible if there was already an error adding something of
+ // the same name.
+ if (!had_errors_) {
+ GOOGLE_LOG(DFATAL) << "\"" << full_name << "\" not previously defined in "
+ "symbols_by_name_, but was defined in "
+ "symbols_by_parent_; this shouldn't be possible.";
+ }
return false;
}
return true;
@@ -3916,12 +4095,12 @@ const FileDescriptor* DescriptorBuilder::BuildFileImpl(
}
// Make sure all dependencies are loaded.
- set<string> seen_dependencies;
+ std::set<string> seen_dependencies;
result->dependency_count_ = proto.dependency_size();
result->dependencies_ =
tables_->AllocateArray<const FileDescriptor*>(proto.dependency_size());
unused_dependency_.clear();
- set<int> weak_deps;
+ std::set<int> weak_deps;
for (int i = 0; i < proto.weak_dependency_size(); ++i) {
weak_deps.insert(proto.weak_dependency(i));
}
@@ -3935,6 +4114,14 @@ const FileDescriptor* DescriptorBuilder::BuildFileImpl(
dependency = pool_->underlay_->FindFileByName(proto.dependency(i));
}
+ if (dependency == result) {
+ // Recursive import. dependency/result is not fully initialized, and it's
+ // dangerous to try to do anything with it. The recursive import error
+ // will be detected and reported in DescriptorBuilder::BuildFile().
+ tables_->RollbackToLastCheckpoint();
+ return NULL;
+ }
+
if (dependency == NULL) {
if (pool_->allow_unknown_ ||
(!pool_->enforce_weak_ && weak_deps.find(i) != weak_deps.end())) {
@@ -4020,7 +4207,7 @@ const FileDescriptor* DescriptorBuilder::BuildFileImpl(
// extension options known, so all interpretations should now succeed.
if (!had_errors_) {
OptionInterpreter option_interpreter(this);
- for (vector<OptionsToInterpret>::iterator iter =
+ for (std::vector<OptionsToInterpret>::iterator iter =
options_to_interpret_.begin();
iter != options_to_interpret_.end(); ++iter) {
option_interpreter.InterpretOptions(&(*iter));
@@ -4168,7 +4355,7 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto,
for (int j = 0; j < result->reserved_range_count(); j++) {
const Descriptor::ReservedRange* range2 = result->reserved_range(j);
if (range1->end > range2->start && range2->end > range1->start) {
- AddError(result->full_name(), proto.extension_range(j),
+ AddError(result->full_name(), proto.extension_range(i),
DescriptorPool::ErrorCollector::NUMBER,
strings::Substitute("Extension range $0 to $1 overlaps with "
"reserved range $2 to $3.",
@@ -4179,7 +4366,7 @@ void DescriptorBuilder::BuildMessage(const DescriptorProto& proto,
for (int j = i + 1; j < result->extension_range_count(); j++) {
const Descriptor::ExtensionRange* range2 = result->extension_range(j);
if (range1->end > range2->start && range2->end > range1->start) {
- AddError(result->full_name(), proto.extension_range(j),
+ AddError(result->full_name(), proto.extension_range(i),
DescriptorPool::ErrorCollector::NUMBER,
strings::Substitute("Extension range $0 to $1 overlaps with "
"already-defined range $2 to $3.",
@@ -4232,7 +4419,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,
@@ -4290,11 +4477,14 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto,
break;
case FieldDescriptor::CPPTYPE_FLOAT:
if (proto.default_value() == "inf") {
- result->default_value_float_ = numeric_limits<float>::infinity();
+ result->default_value_float_ =
+ std::numeric_limits<float>::infinity();
} else if (proto.default_value() == "-inf") {
- result->default_value_float_ = -numeric_limits<float>::infinity();
+ result->default_value_float_ =
+ -std::numeric_limits<float>::infinity();
} else if (proto.default_value() == "nan") {
- result->default_value_float_ = numeric_limits<float>::quiet_NaN();
+ result->default_value_float_ =
+ std::numeric_limits<float>::quiet_NaN();
} else {
result->default_value_float_ = io::SafeDoubleToFloat(
io::NoLocaleStrtod(proto.default_value().c_str(), &end_pos));
@@ -4302,11 +4492,14 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto,
break;
case FieldDescriptor::CPPTYPE_DOUBLE:
if (proto.default_value() == "inf") {
- result->default_value_double_ = numeric_limits<double>::infinity();
+ result->default_value_double_ =
+ std::numeric_limits<double>::infinity();
} else if (proto.default_value() == "-inf") {
- result->default_value_double_ = -numeric_limits<double>::infinity();
+ result->default_value_double_ =
+ -std::numeric_limits<double>::infinity();
} else if (proto.default_value() == "nan") {
- result->default_value_double_ = numeric_limits<double>::quiet_NaN();
+ result->default_value_double_ =
+ std::numeric_limits<double>::quiet_NaN();
} else {
result->default_value_double_ =
io::NoLocaleStrtod(proto.default_value().c_str(), &end_pos);
@@ -4540,6 +4733,71 @@ 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());
+ std::map<string, const google::protobuf::EnumValueDescriptor*> 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<std::map<string, const google::protobuf::EnumValueDescriptor*>::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()) {
+ string error_message =
+ "When enum name is stripped and label is PascalCased (" + stripped +
+ "), this value label conflicts with " + values[stripped]->name() +
+ ". This will make the proto fail to compile for some languages, such "
+ "as C#.";
+ // There are proto2 enums out there with conflicting names, so to preserve
+ // compatibility we issue only a warning for proto2.
+ if (result->file()->syntax() == FileDescriptor::SYNTAX_PROTO2) {
+ AddWarning(value->full_name(), proto.value(i),
+ DescriptorPool::ErrorCollector::NAME, error_message);
+ } else {
+ AddError(value->full_name(), proto.value(i),
+ DescriptorPool::ErrorCollector::NAME, error_message);
+ }
+ }
+ }
+}
+
void DescriptorBuilder::BuildEnum(const EnumDescriptorProto& proto,
const Descriptor* parent,
EnumDescriptor* result) {
@@ -4568,6 +4826,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.
@@ -4983,13 +5243,16 @@ void DescriptorBuilder::CrossLinkField(
const FieldDescriptor* conflicting_field =
file_tables_->FindFieldByNumber(field->containing_type(),
field->number());
+ string containing_type_name = field->containing_type() == NULL
+ ? "unknown"
+ : field->containing_type()->full_name();
if (field->is_extension()) {
AddError(field->full_name(), proto,
DescriptorPool::ErrorCollector::NUMBER,
strings::Substitute("Extension number $0 has already been used "
"in \"$1\" by extension \"$2\".",
field->number(),
- field->containing_type()->full_name(),
+ containing_type_name,
conflicting_field->full_name()));
} else {
AddError(field->full_name(), proto,
@@ -4997,7 +5260,7 @@ void DescriptorBuilder::CrossLinkField(
strings::Substitute("Field number $0 has already been used in "
"\"$1\" by field \"$2\".",
field->number(),
- field->containing_type()->full_name(),
+ containing_type_name,
conflicting_field->name()));
}
} else {
@@ -5191,7 +5454,7 @@ void DescriptorBuilder::ValidateProto3Message(
// In proto3, we reject field names if they conflict in camelCase.
// Note that we currently enforce a stricter rule: Field names must be
// unique after being converted to lowercase with underscores removed.
- map<string, const FieldDescriptor*> name_to_field;
+ std::map<string, const FieldDescriptor*> name_to_field;
for (int i = 0; i < message->field_count(); ++i) {
string lowercase_name = ToLowercaseWithoutUnderscores(
message->field(i)->name());
@@ -5254,7 +5517,6 @@ void DescriptorBuilder::ValidateProto3Enum(
}
}
-
void DescriptorBuilder::ValidateMessageOptions(Descriptor* message,
const DescriptorProto& proto) {
VALIDATE_OPTIONS_FROM_ARRAY(message, field, Field);
@@ -5275,7 +5537,6 @@ void DescriptorBuilder::ValidateMessageOptions(Descriptor* message,
max_extension_range));
}
}
-
}
void DescriptorBuilder::ValidateFieldOptions(FieldDescriptor* field,
@@ -5344,7 +5605,7 @@ void DescriptorBuilder::ValidateEnumOptions(EnumDescriptor* enm,
const EnumDescriptorProto& proto) {
VALIDATE_OPTIONS_FROM_ARRAY(enm, value, EnumValue);
if (!enm->options().has_allow_alias() || !enm->options().allow_alias()) {
- map<int, string> used_values;
+ std::map<int, string> used_values;
for (int i = 0; i < enm->value_count(); ++i) {
const EnumValueDescriptor* enum_value = enm->value(i);
if (used_values.find(enum_value->number()) != used_values.end()) {
@@ -5471,10 +5732,10 @@ bool DescriptorBuilder::ValidateMapEntry(FieldDescriptor* field,
void DescriptorBuilder::DetectMapConflicts(const Descriptor* message,
const DescriptorProto& proto) {
- map<string, const Descriptor*> seen_types;
+ std::map<string, const Descriptor*> seen_types;
for (int i = 0; i < message->nested_type_count(); ++i) {
const Descriptor* nested = message->nested_type(i);
- pair<map<string, const Descriptor*>::iterator, bool> result =
+ std::pair<std::map<string, const Descriptor*>::iterator, bool> result =
seen_types.insert(std::make_pair(nested->name(), nested));
if (!result.second) {
if (result.first->second->options().map_entry() ||
@@ -5491,7 +5752,7 @@ void DescriptorBuilder::DetectMapConflicts(const Descriptor* message,
// Check for conflicted field names.
for (int i = 0; i < message->field_count(); ++i) {
const FieldDescriptor* field = message->field(i);
- map<string, const Descriptor*>::iterator iter =
+ std::map<string, const Descriptor*>::iterator iter =
seen_types.find(field->name());
if (iter != seen_types.end() && iter->second->options().map_entry()) {
AddError(message->full_name(), proto,
@@ -5503,7 +5764,7 @@ void DescriptorBuilder::DetectMapConflicts(const Descriptor* message,
// Check for conflicted enum names.
for (int i = 0; i < message->enum_type_count(); ++i) {
const EnumDescriptor* enum_desc = message->enum_type(i);
- map<string, const Descriptor*>::iterator iter =
+ std::map<string, const Descriptor*>::iterator iter =
seen_types.find(enum_desc->name());
if (iter != seen_types.end() && iter->second->options().map_entry()) {
AddError(message->full_name(), proto,
@@ -5515,7 +5776,7 @@ void DescriptorBuilder::DetectMapConflicts(const Descriptor* message,
// Check for conflicted oneof names.
for (int i = 0; i < message->oneof_decl_count(); ++i) {
const OneofDescriptor* oneof_desc = message->oneof_decl(i);
- map<string, const Descriptor*>::iterator iter =
+ std::map<string, const Descriptor*>::iterator iter =
seen_types.find(oneof_desc->name());
if (iter != seen_types.end() && iter->second->options().map_entry()) {
AddError(message->full_name(), proto,
@@ -5650,7 +5911,7 @@ bool DescriptorBuilder::OptionInterpreter::InterpretSingleOption(
// name in |debug_msg_name|, for use in error messages.
const Descriptor* descriptor = options_descriptor;
const FieldDescriptor* field = NULL;
- vector<const FieldDescriptor*> intermediate_fields;
+ std::vector<const FieldDescriptor*> intermediate_fields;
string debug_msg_name = "";
for (int i = 0; i < uninterpreted_option_->name_size(); ++i) {
@@ -5758,7 +6019,7 @@ bool DescriptorBuilder::OptionInterpreter::InterpretSingleOption(
// Now wrap the UnknownFieldSet with UnknownFieldSets corresponding to all
// the intermediate messages.
- for (vector<const FieldDescriptor*>::reverse_iterator iter =
+ for (std::vector<const FieldDescriptor*>::reverse_iterator iter =
intermediate_fields.rbegin();
iter != intermediate_fields.rend(); ++iter) {
google::protobuf::scoped_ptr<UnknownFieldSet> parent_unknown_fields(
@@ -5808,8 +6069,9 @@ void DescriptorBuilder::OptionInterpreter::AddWithoutInterpreting(
}
bool DescriptorBuilder::OptionInterpreter::ExamineIfOptionIsSet(
- vector<const FieldDescriptor*>::const_iterator intermediate_fields_iter,
- vector<const FieldDescriptor*>::const_iterator intermediate_fields_end,
+ std::vector<const FieldDescriptor*>::const_iterator
+ intermediate_fields_iter,
+ std::vector<const FieldDescriptor*>::const_iterator intermediate_fields_end,
const FieldDescriptor* innermost_field, const string& debug_msg_name,
const UnknownFieldSet& unknown_fields) {
// We do linear searches of the UnknownFieldSet and its sub-groups. This
@@ -6269,7 +6531,7 @@ void DescriptorBuilder::LogUnusedDependency(const FileDescriptorProto& proto,
annotation_extensions.insert("google.protobuf.ServiceOptions");
annotation_extensions.insert("google.protobuf.MethodOptions");
annotation_extensions.insert("google.protobuf.StreamOptions");
- for (set<const FileDescriptor*>::const_iterator
+ for (std::set<const FileDescriptor*>::const_iterator
it = unused_dependency_.begin();
it != unused_dependency_.end(); ++it) {
// Do not log warnings for proto files which extend annotations.
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/descriptor.h b/third_party/protobuf/src/google/protobuf/descriptor.h
index b040b62c8b..cc09969346 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/descriptor.h
+++ b/third_party/protobuf/src/google/protobuf/descriptor.h
@@ -62,6 +62,7 @@
#include <string>
#include <vector>
#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/mutex.h>
// TYPE_BOOL is defined in the MacOS's ConditionalMacros.h.
#ifdef TYPE_BOOL
@@ -143,7 +144,7 @@ struct SourceLocation {
// See the comments in SourceCodeInfo.Location (descriptor.proto) for details.
string leading_comments;
string trailing_comments;
- vector<string> leading_detached_comments;
+ std::vector<string> leading_detached_comments;
};
// Options when generating machine-parsable output from a descriptor with
@@ -558,6 +559,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 +688,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 +1704,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/third_party/protobuf/3.0.0/src/google/protobuf/descriptor.pb.cc b/third_party/protobuf/src/google/protobuf/descriptor.pb.cc
index 0028c70862..57fbfd86cc 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/descriptor.pb.cc
+++ b/third_party/protobuf/src/google/protobuf/descriptor.pb.cc
@@ -19,888 +19,915 @@
namespace google {
namespace protobuf {
+class FileDescriptorSetDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<FileDescriptorSet> {
+} _FileDescriptorSet_default_instance_;
+class FileDescriptorProtoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<FileDescriptorProto> {
+} _FileDescriptorProto_default_instance_;
+class DescriptorProto_ExtensionRangeDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<DescriptorProto_ExtensionRange> {
+} _DescriptorProto_ExtensionRange_default_instance_;
+class DescriptorProto_ReservedRangeDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<DescriptorProto_ReservedRange> {
+} _DescriptorProto_ReservedRange_default_instance_;
+class DescriptorProtoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<DescriptorProto> {
+} _DescriptorProto_default_instance_;
+class FieldDescriptorProtoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<FieldDescriptorProto> {
+} _FieldDescriptorProto_default_instance_;
+class OneofDescriptorProtoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<OneofDescriptorProto> {
+} _OneofDescriptorProto_default_instance_;
+class EnumDescriptorProtoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<EnumDescriptorProto> {
+} _EnumDescriptorProto_default_instance_;
+class EnumValueDescriptorProtoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<EnumValueDescriptorProto> {
+} _EnumValueDescriptorProto_default_instance_;
+class ServiceDescriptorProtoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<ServiceDescriptorProto> {
+} _ServiceDescriptorProto_default_instance_;
+class MethodDescriptorProtoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<MethodDescriptorProto> {
+} _MethodDescriptorProto_default_instance_;
+class FileOptionsDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<FileOptions> {
+} _FileOptions_default_instance_;
+class MessageOptionsDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<MessageOptions> {
+} _MessageOptions_default_instance_;
+class FieldOptionsDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<FieldOptions> {
+} _FieldOptions_default_instance_;
+class OneofOptionsDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<OneofOptions> {
+} _OneofOptions_default_instance_;
+class EnumOptionsDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<EnumOptions> {
+} _EnumOptions_default_instance_;
+class EnumValueOptionsDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<EnumValueOptions> {
+} _EnumValueOptions_default_instance_;
+class ServiceOptionsDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<ServiceOptions> {
+} _ServiceOptions_default_instance_;
+class MethodOptionsDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<MethodOptions> {
+} _MethodOptions_default_instance_;
+class UninterpretedOption_NamePartDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<UninterpretedOption_NamePart> {
+} _UninterpretedOption_NamePart_default_instance_;
+class UninterpretedOptionDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<UninterpretedOption> {
+} _UninterpretedOption_default_instance_;
+class SourceCodeInfo_LocationDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<SourceCodeInfo_Location> {
+} _SourceCodeInfo_Location_default_instance_;
+class SourceCodeInfoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<SourceCodeInfo> {
+} _SourceCodeInfo_default_instance_;
+class GeneratedCodeInfo_AnnotationDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<GeneratedCodeInfo_Annotation> {
+} _GeneratedCodeInfo_Annotation_default_instance_;
+class GeneratedCodeInfoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<GeneratedCodeInfo> {
+} _GeneratedCodeInfo_default_instance_;
+
+namespace protobuf_google_2fprotobuf_2fdescriptor_2eproto {
+
namespace {
-const ::google::protobuf::Descriptor* FileDescriptorSet_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- FileDescriptorSet_reflection_ = NULL;
-const ::google::protobuf::Descriptor* FileDescriptorProto_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- FileDescriptorProto_reflection_ = NULL;
-const ::google::protobuf::Descriptor* DescriptorProto_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- DescriptorProto_reflection_ = NULL;
-const ::google::protobuf::Descriptor* DescriptorProto_ExtensionRange_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- DescriptorProto_ExtensionRange_reflection_ = NULL;
-const ::google::protobuf::Descriptor* DescriptorProto_ReservedRange_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- DescriptorProto_ReservedRange_reflection_ = NULL;
-const ::google::protobuf::Descriptor* FieldDescriptorProto_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- FieldDescriptorProto_reflection_ = NULL;
-const ::google::protobuf::EnumDescriptor* FieldDescriptorProto_Type_descriptor_ = NULL;
-const ::google::protobuf::EnumDescriptor* FieldDescriptorProto_Label_descriptor_ = NULL;
-const ::google::protobuf::Descriptor* OneofDescriptorProto_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- OneofDescriptorProto_reflection_ = NULL;
-const ::google::protobuf::Descriptor* EnumDescriptorProto_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- EnumDescriptorProto_reflection_ = NULL;
-const ::google::protobuf::Descriptor* EnumValueDescriptorProto_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- EnumValueDescriptorProto_reflection_ = NULL;
-const ::google::protobuf::Descriptor* ServiceDescriptorProto_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- ServiceDescriptorProto_reflection_ = NULL;
-const ::google::protobuf::Descriptor* MethodDescriptorProto_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- MethodDescriptorProto_reflection_ = NULL;
-const ::google::protobuf::Descriptor* FileOptions_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- FileOptions_reflection_ = NULL;
-const ::google::protobuf::EnumDescriptor* FileOptions_OptimizeMode_descriptor_ = NULL;
-const ::google::protobuf::Descriptor* MessageOptions_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- MessageOptions_reflection_ = NULL;
-const ::google::protobuf::Descriptor* FieldOptions_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- FieldOptions_reflection_ = NULL;
-const ::google::protobuf::EnumDescriptor* FieldOptions_CType_descriptor_ = NULL;
-const ::google::protobuf::EnumDescriptor* FieldOptions_JSType_descriptor_ = NULL;
-const ::google::protobuf::Descriptor* OneofOptions_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- OneofOptions_reflection_ = NULL;
-const ::google::protobuf::Descriptor* EnumOptions_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- EnumOptions_reflection_ = NULL;
-const ::google::protobuf::Descriptor* EnumValueOptions_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- EnumValueOptions_reflection_ = NULL;
-const ::google::protobuf::Descriptor* ServiceOptions_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- ServiceOptions_reflection_ = NULL;
-const ::google::protobuf::Descriptor* MethodOptions_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- MethodOptions_reflection_ = NULL;
-const ::google::protobuf::Descriptor* UninterpretedOption_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- UninterpretedOption_reflection_ = NULL;
-const ::google::protobuf::Descriptor* UninterpretedOption_NamePart_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- UninterpretedOption_NamePart_reflection_ = NULL;
-const ::google::protobuf::Descriptor* SourceCodeInfo_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- SourceCodeInfo_reflection_ = NULL;
-const ::google::protobuf::Descriptor* SourceCodeInfo_Location_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- SourceCodeInfo_Location_reflection_ = NULL;
-const ::google::protobuf::Descriptor* GeneratedCodeInfo_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- GeneratedCodeInfo_reflection_ = NULL;
-const ::google::protobuf::Descriptor* GeneratedCodeInfo_Annotation_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- GeneratedCodeInfo_Annotation_reflection_ = NULL;
+::google::protobuf::Metadata file_level_metadata[25];
+const ::google::protobuf::EnumDescriptor* file_level_enum_descriptors[6];
} // namespace
-
-void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() GOOGLE_ATTRIBUTE_COLD;
-void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- const ::google::protobuf::FileDescriptor* file =
- ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
- "google/protobuf/descriptor.proto");
- GOOGLE_CHECK(file != NULL);
- FileDescriptorSet_descriptor_ = file->message_type(0);
- static const int FileDescriptorSet_offsets_[1] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorSet, file_),
- };
- FileDescriptorSet_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- FileDescriptorSet_descriptor_,
- FileDescriptorSet::default_instance_,
- FileDescriptorSet_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorSet, _has_bits_[0]),
- -1,
- -1,
- sizeof(FileDescriptorSet),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorSet, _internal_metadata_),
- -1);
- FileDescriptorProto_descriptor_ = file->message_type(1);
- static const int FileDescriptorProto_offsets_[12] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, package_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, dependency_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, public_dependency_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, weak_dependency_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, message_type_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, enum_type_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, service_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, extension_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, options_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, source_code_info_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, syntax_),
- };
- FileDescriptorProto_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- FileDescriptorProto_descriptor_,
- FileDescriptorProto::default_instance_,
- FileDescriptorProto_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, _has_bits_[0]),
- -1,
- -1,
- sizeof(FileDescriptorProto),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, _internal_metadata_),
- -1);
- DescriptorProto_descriptor_ = file->message_type(2);
- static const int DescriptorProto_offsets_[10] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, field_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, extension_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, nested_type_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, enum_type_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, extension_range_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, oneof_decl_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, options_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, reserved_range_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, reserved_name_),
- };
- DescriptorProto_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- DescriptorProto_descriptor_,
- DescriptorProto::default_instance_,
- DescriptorProto_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, _has_bits_[0]),
- -1,
- -1,
- sizeof(DescriptorProto),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, _internal_metadata_),
- -1);
- DescriptorProto_ExtensionRange_descriptor_ = DescriptorProto_descriptor_->nested_type(0);
- static const int DescriptorProto_ExtensionRange_offsets_[2] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, start_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, end_),
- };
- DescriptorProto_ExtensionRange_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- DescriptorProto_ExtensionRange_descriptor_,
- DescriptorProto_ExtensionRange::default_instance_,
- DescriptorProto_ExtensionRange_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, _has_bits_[0]),
- -1,
- -1,
- sizeof(DescriptorProto_ExtensionRange),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, _internal_metadata_),
- -1);
- DescriptorProto_ReservedRange_descriptor_ = DescriptorProto_descriptor_->nested_type(1);
- static const int DescriptorProto_ReservedRange_offsets_[2] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, start_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, end_),
- };
- DescriptorProto_ReservedRange_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- DescriptorProto_ReservedRange_descriptor_,
- DescriptorProto_ReservedRange::default_instance_,
- DescriptorProto_ReservedRange_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, _has_bits_[0]),
- -1,
- -1,
- sizeof(DescriptorProto_ReservedRange),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, _internal_metadata_),
- -1);
- FieldDescriptorProto_descriptor_ = file->message_type(3);
- static const int FieldDescriptorProto_offsets_[10] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, number_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, label_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, type_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, type_name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, extendee_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, default_value_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, oneof_index_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, json_name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, options_),
- };
- FieldDescriptorProto_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- FieldDescriptorProto_descriptor_,
- FieldDescriptorProto::default_instance_,
- FieldDescriptorProto_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, _has_bits_[0]),
- -1,
- -1,
- sizeof(FieldDescriptorProto),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, _internal_metadata_),
- -1);
- FieldDescriptorProto_Type_descriptor_ = FieldDescriptorProto_descriptor_->enum_type(0);
- FieldDescriptorProto_Label_descriptor_ = FieldDescriptorProto_descriptor_->enum_type(1);
- OneofDescriptorProto_descriptor_ = file->message_type(4);
- static const int OneofDescriptorProto_offsets_[2] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofDescriptorProto, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofDescriptorProto, options_),
- };
- OneofDescriptorProto_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- OneofDescriptorProto_descriptor_,
- OneofDescriptorProto::default_instance_,
- OneofDescriptorProto_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofDescriptorProto, _has_bits_[0]),
- -1,
- -1,
- sizeof(OneofDescriptorProto),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofDescriptorProto, _internal_metadata_),
- -1);
- EnumDescriptorProto_descriptor_ = file->message_type(5);
- static const int EnumDescriptorProto_offsets_[3] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, value_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, options_),
- };
- EnumDescriptorProto_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- EnumDescriptorProto_descriptor_,
- EnumDescriptorProto::default_instance_,
- EnumDescriptorProto_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, _has_bits_[0]),
- -1,
- -1,
- sizeof(EnumDescriptorProto),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, _internal_metadata_),
- -1);
- EnumValueDescriptorProto_descriptor_ = file->message_type(6);
- static const int EnumValueDescriptorProto_offsets_[3] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, number_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, options_),
- };
- EnumValueDescriptorProto_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- EnumValueDescriptorProto_descriptor_,
- EnumValueDescriptorProto::default_instance_,
- EnumValueDescriptorProto_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, _has_bits_[0]),
- -1,
- -1,
- sizeof(EnumValueDescriptorProto),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, _internal_metadata_),
- -1);
- ServiceDescriptorProto_descriptor_ = file->message_type(7);
- static const int ServiceDescriptorProto_offsets_[3] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, method_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, options_),
- };
- ServiceDescriptorProto_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- ServiceDescriptorProto_descriptor_,
- ServiceDescriptorProto::default_instance_,
- ServiceDescriptorProto_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, _has_bits_[0]),
- -1,
- -1,
- sizeof(ServiceDescriptorProto),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, _internal_metadata_),
- -1);
- MethodDescriptorProto_descriptor_ = file->message_type(8);
- static const int MethodDescriptorProto_offsets_[6] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, input_type_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, output_type_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, options_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, client_streaming_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, server_streaming_),
- };
- MethodDescriptorProto_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- MethodDescriptorProto_descriptor_,
- MethodDescriptorProto::default_instance_,
- MethodDescriptorProto_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, _has_bits_[0]),
- -1,
- -1,
- sizeof(MethodDescriptorProto),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, _internal_metadata_),
- -1);
- FileOptions_descriptor_ = file->message_type(9);
- static const int FileOptions_offsets_[15] = {
- 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_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, cc_generic_services_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, java_generic_services_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, py_generic_services_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, deprecated_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, cc_enable_arenas_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, objc_class_prefix_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, csharp_namespace_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, uninterpreted_option_),
- };
- FileOptions_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- FileOptions_descriptor_,
- FileOptions::default_instance_,
- FileOptions_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, _has_bits_[0]),
- -1,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, _extensions_),
- sizeof(FileOptions),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, _internal_metadata_),
- -1);
- FileOptions_OptimizeMode_descriptor_ = FileOptions_descriptor_->enum_type(0);
- MessageOptions_descriptor_ = file->message_type(10);
- static const int MessageOptions_offsets_[5] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, message_set_wire_format_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, no_standard_descriptor_accessor_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, deprecated_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, map_entry_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, uninterpreted_option_),
- };
- MessageOptions_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- MessageOptions_descriptor_,
- MessageOptions::default_instance_,
- MessageOptions_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, _has_bits_[0]),
- -1,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, _extensions_),
- sizeof(MessageOptions),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, _internal_metadata_),
- -1);
- FieldOptions_descriptor_ = file->message_type(11);
- static const int FieldOptions_offsets_[7] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, ctype_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, packed_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, jstype_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, lazy_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, deprecated_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, weak_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, uninterpreted_option_),
- };
- FieldOptions_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- FieldOptions_descriptor_,
- FieldOptions::default_instance_,
- FieldOptions_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, _has_bits_[0]),
- -1,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, _extensions_),
- sizeof(FieldOptions),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, _internal_metadata_),
- -1);
- FieldOptions_CType_descriptor_ = FieldOptions_descriptor_->enum_type(0);
- FieldOptions_JSType_descriptor_ = FieldOptions_descriptor_->enum_type(1);
- OneofOptions_descriptor_ = file->message_type(12);
- static const int OneofOptions_offsets_[1] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofOptions, uninterpreted_option_),
- };
- OneofOptions_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- OneofOptions_descriptor_,
- OneofOptions::default_instance_,
- OneofOptions_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofOptions, _has_bits_[0]),
- -1,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofOptions, _extensions_),
- sizeof(OneofOptions),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofOptions, _internal_metadata_),
- -1);
- EnumOptions_descriptor_ = file->message_type(13);
- static const int EnumOptions_offsets_[3] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, allow_alias_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, deprecated_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, uninterpreted_option_),
- };
- EnumOptions_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- EnumOptions_descriptor_,
- EnumOptions::default_instance_,
- EnumOptions_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, _has_bits_[0]),
- -1,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, _extensions_),
- sizeof(EnumOptions),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, _internal_metadata_),
- -1);
- EnumValueOptions_descriptor_ = file->message_type(14);
- static const int EnumValueOptions_offsets_[2] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, deprecated_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, uninterpreted_option_),
- };
- EnumValueOptions_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- EnumValueOptions_descriptor_,
- EnumValueOptions::default_instance_,
- EnumValueOptions_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, _has_bits_[0]),
- -1,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, _extensions_),
- sizeof(EnumValueOptions),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, _internal_metadata_),
- -1);
- ServiceOptions_descriptor_ = file->message_type(15);
- static const int ServiceOptions_offsets_[2] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, deprecated_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, uninterpreted_option_),
- };
- ServiceOptions_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- ServiceOptions_descriptor_,
- ServiceOptions::default_instance_,
- ServiceOptions_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, _has_bits_[0]),
- -1,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, _extensions_),
- sizeof(ServiceOptions),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, _internal_metadata_),
- -1);
- MethodOptions_descriptor_ = file->message_type(16);
- static const int MethodOptions_offsets_[2] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, deprecated_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, uninterpreted_option_),
- };
- MethodOptions_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- MethodOptions_descriptor_,
- MethodOptions::default_instance_,
- MethodOptions_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, _has_bits_[0]),
- -1,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, _extensions_),
- sizeof(MethodOptions),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, _internal_metadata_),
- -1);
- UninterpretedOption_descriptor_ = file->message_type(17);
- static const int UninterpretedOption_offsets_[7] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, identifier_value_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, positive_int_value_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, negative_int_value_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, double_value_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, string_value_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, aggregate_value_),
- };
- UninterpretedOption_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- UninterpretedOption_descriptor_,
- UninterpretedOption::default_instance_,
- UninterpretedOption_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, _has_bits_[0]),
- -1,
- -1,
- sizeof(UninterpretedOption),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, _internal_metadata_),
- -1);
- 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_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption_NamePart, is_extension_),
- };
- UninterpretedOption_NamePart_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- UninterpretedOption_NamePart_descriptor_,
- UninterpretedOption_NamePart::default_instance_,
- UninterpretedOption_NamePart_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption_NamePart, _has_bits_[0]),
- -1,
- -1,
- sizeof(UninterpretedOption_NamePart),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption_NamePart, _internal_metadata_),
- -1);
- SourceCodeInfo_descriptor_ = file->message_type(18);
- static const int SourceCodeInfo_offsets_[1] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo, location_),
- };
- SourceCodeInfo_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- SourceCodeInfo_descriptor_,
- SourceCodeInfo::default_instance_,
- SourceCodeInfo_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo, _has_bits_[0]),
- -1,
- -1,
- sizeof(SourceCodeInfo),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo, _internal_metadata_),
- -1);
- SourceCodeInfo_Location_descriptor_ = SourceCodeInfo_descriptor_->nested_type(0);
- static const int SourceCodeInfo_Location_offsets_[5] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, path_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, span_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, leading_comments_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, trailing_comments_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, leading_detached_comments_),
- };
- SourceCodeInfo_Location_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- SourceCodeInfo_Location_descriptor_,
- SourceCodeInfo_Location::default_instance_,
- SourceCodeInfo_Location_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, _has_bits_[0]),
- -1,
- -1,
- sizeof(SourceCodeInfo_Location),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, _internal_metadata_),
- -1);
- GeneratedCodeInfo_descriptor_ = file->message_type(19);
- static const int GeneratedCodeInfo_offsets_[1] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo, annotation_),
- };
- GeneratedCodeInfo_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- GeneratedCodeInfo_descriptor_,
- GeneratedCodeInfo::default_instance_,
- GeneratedCodeInfo_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo, _has_bits_[0]),
- -1,
- -1,
- sizeof(GeneratedCodeInfo),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo, _internal_metadata_),
- -1);
- GeneratedCodeInfo_Annotation_descriptor_ = GeneratedCodeInfo_descriptor_->nested_type(0);
- static const int GeneratedCodeInfo_Annotation_offsets_[4] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, path_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, source_file_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, begin_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, end_),
- };
- GeneratedCodeInfo_Annotation_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- GeneratedCodeInfo_Annotation_descriptor_,
- GeneratedCodeInfo_Annotation::default_instance_,
- GeneratedCodeInfo_Annotation_offsets_,
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, _has_bits_[0]),
- -1,
- -1,
- sizeof(GeneratedCodeInfo_Annotation),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, _internal_metadata_),
- -1);
-}
+const ::google::protobuf::uint32 TableStruct::offsets[] = {
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorSet, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorSet, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorSet, file_),
+ ~0u,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, package_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, dependency_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, public_dependency_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, weak_dependency_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, message_type_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, enum_type_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, service_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, extension_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, options_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, source_code_info_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorProto, syntax_),
+ 0,
+ 1,
+ ~0u,
+ ~0u,
+ ~0u,
+ ~0u,
+ ~0u,
+ ~0u,
+ ~0u,
+ 3,
+ 4,
+ 2,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, start_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, end_),
+ 0,
+ 1,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, start_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, end_),
+ 0,
+ 1,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, field_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, extension_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, nested_type_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, enum_type_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, extension_range_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, oneof_decl_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, options_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, reserved_range_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto, reserved_name_),
+ 0,
+ ~0u,
+ ~0u,
+ ~0u,
+ ~0u,
+ ~0u,
+ ~0u,
+ 1,
+ ~0u,
+ ~0u,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, number_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, label_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, type_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, type_name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, extendee_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, default_value_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, oneof_index_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, json_name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, options_),
+ 0,
+ 6,
+ 8,
+ 9,
+ 1,
+ 2,
+ 3,
+ 7,
+ 4,
+ 5,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofDescriptorProto, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofDescriptorProto, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofDescriptorProto, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofDescriptorProto, options_),
+ 0,
+ 1,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, value_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumDescriptorProto, options_),
+ 0,
+ ~0u,
+ 1,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, number_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueDescriptorProto, options_),
+ 0,
+ 2,
+ 1,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, method_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceDescriptorProto, options_),
+ 0,
+ ~0u,
+ 1,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, input_type_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, output_type_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, options_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, client_streaming_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodDescriptorProto, server_streaming_),
+ 0,
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, _internal_metadata_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, _extensions_),
+ ~0u, // no _oneof_case_
+ 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_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, cc_generic_services_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, java_generic_services_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, py_generic_services_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, deprecated_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, cc_enable_arenas_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, objc_class_prefix_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, csharp_namespace_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, swift_prefix_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, php_class_prefix_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileOptions, uninterpreted_option_),
+ 0,
+ 1,
+ 7,
+ 8,
+ 9,
+ 15,
+ 2,
+ 10,
+ 11,
+ 12,
+ 13,
+ 14,
+ 3,
+ 4,
+ 5,
+ 6,
+ ~0u,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, _internal_metadata_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, _extensions_),
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, message_set_wire_format_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, no_standard_descriptor_accessor_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, deprecated_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, map_entry_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MessageOptions, uninterpreted_option_),
+ 0,
+ 1,
+ 2,
+ 3,
+ ~0u,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, _internal_metadata_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, _extensions_),
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, ctype_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, packed_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, jstype_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, lazy_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, deprecated_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, weak_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldOptions, uninterpreted_option_),
+ 0,
+ 2,
+ 1,
+ 3,
+ 4,
+ 5,
+ ~0u,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofOptions, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofOptions, _internal_metadata_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofOptions, _extensions_),
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(OneofOptions, uninterpreted_option_),
+ ~0u,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, _internal_metadata_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, _extensions_),
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, allow_alias_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, deprecated_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumOptions, uninterpreted_option_),
+ 0,
+ 1,
+ ~0u,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, _internal_metadata_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, _extensions_),
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, deprecated_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValueOptions, uninterpreted_option_),
+ 0,
+ ~0u,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, _internal_metadata_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, _extensions_),
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, deprecated_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ServiceOptions, uninterpreted_option_),
+ 0,
+ ~0u,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, _internal_metadata_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, _extensions_),
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, deprecated_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, idempotency_level_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MethodOptions, uninterpreted_option_),
+ 0,
+ 1,
+ ~0u,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption_NamePart, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption_NamePart, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption_NamePart, name_part_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption_NamePart, is_extension_),
+ 0,
+ 1,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, identifier_value_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, positive_int_value_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, negative_int_value_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, double_value_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, string_value_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UninterpretedOption, aggregate_value_),
+ ~0u,
+ 0,
+ 3,
+ 4,
+ 5,
+ 1,
+ 2,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, path_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, span_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, leading_comments_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, trailing_comments_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo_Location, leading_detached_comments_),
+ ~0u,
+ ~0u,
+ 0,
+ 1,
+ ~0u,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceCodeInfo, location_),
+ ~0u,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, path_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, source_file_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, begin_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo_Annotation, end_),
+ ~0u,
+ 0,
+ 1,
+ 2,
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo, _has_bits_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo, annotation_),
+ ~0u,
+};
+
+static const ::google::protobuf::internal::MigrationSchema schemas[] = {
+ { 0, 5, sizeof(FileDescriptorSet)},
+ { 6, 22, sizeof(FileDescriptorProto)},
+ { 34, 40, sizeof(DescriptorProto_ExtensionRange)},
+ { 42, 48, sizeof(DescriptorProto_ReservedRange)},
+ { 50, 64, sizeof(DescriptorProto)},
+ { 74, 88, sizeof(FieldDescriptorProto)},
+ { 98, 104, sizeof(OneofDescriptorProto)},
+ { 106, 113, sizeof(EnumDescriptorProto)},
+ { 116, 123, sizeof(EnumValueDescriptorProto)},
+ { 126, 133, sizeof(ServiceDescriptorProto)},
+ { 136, 146, sizeof(MethodDescriptorProto)},
+ { 152, 173, sizeof(FileOptions)},
+ { 190, 199, sizeof(MessageOptions)},
+ { 204, 215, sizeof(FieldOptions)},
+ { 222, 227, sizeof(OneofOptions)},
+ { 228, 235, sizeof(EnumOptions)},
+ { 238, 244, sizeof(EnumValueOptions)},
+ { 246, 252, sizeof(ServiceOptions)},
+ { 254, 261, sizeof(MethodOptions)},
+ { 264, 270, sizeof(UninterpretedOption_NamePart)},
+ { 272, 283, sizeof(UninterpretedOption)},
+ { 290, 299, sizeof(SourceCodeInfo_Location)},
+ { 304, 309, sizeof(SourceCodeInfo)},
+ { 310, 318, sizeof(GeneratedCodeInfo_Annotation)},
+ { 322, 327, sizeof(GeneratedCodeInfo)},
+};
+
+static ::google::protobuf::Message const * const file_default_instances[] = {
+ reinterpret_cast<const ::google::protobuf::Message*>(&_FileDescriptorSet_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_FileDescriptorProto_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_DescriptorProto_ExtensionRange_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_DescriptorProto_ReservedRange_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_DescriptorProto_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_FieldDescriptorProto_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_OneofDescriptorProto_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_EnumDescriptorProto_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_EnumValueDescriptorProto_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_ServiceDescriptorProto_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_MethodDescriptorProto_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_FileOptions_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_MessageOptions_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_FieldOptions_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_OneofOptions_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_EnumOptions_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_EnumValueOptions_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_ServiceOptions_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_MethodOptions_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_UninterpretedOption_NamePart_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_UninterpretedOption_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_SourceCodeInfo_Location_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_SourceCodeInfo_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_GeneratedCodeInfo_Annotation_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_GeneratedCodeInfo_default_instance_),
+};
namespace {
-GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
-inline void protobuf_AssignDescriptorsOnce() {
- ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
- &protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto);
+void protobuf_AssignDescriptors() {
+ AddDescriptors();
+ ::google::protobuf::MessageFactory* factory = NULL;
+ AssignDescriptors(
+ "google/protobuf/descriptor.proto", schemas, file_default_instances, TableStruct::offsets, factory,
+ file_level_metadata, file_level_enum_descriptors, NULL);
+}
+
+void protobuf_AssignDescriptorsOnce() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
}
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());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- FileDescriptorProto_descriptor_, &FileDescriptorProto::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- DescriptorProto_descriptor_, &DescriptorProto::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- DescriptorProto_ExtensionRange_descriptor_, &DescriptorProto_ExtensionRange::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- DescriptorProto_ReservedRange_descriptor_, &DescriptorProto_ReservedRange::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- FieldDescriptorProto_descriptor_, &FieldDescriptorProto::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- OneofDescriptorProto_descriptor_, &OneofDescriptorProto::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- EnumDescriptorProto_descriptor_, &EnumDescriptorProto::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- EnumValueDescriptorProto_descriptor_, &EnumValueDescriptorProto::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- ServiceDescriptorProto_descriptor_, &ServiceDescriptorProto::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- MethodDescriptorProto_descriptor_, &MethodDescriptorProto::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- FileOptions_descriptor_, &FileOptions::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- MessageOptions_descriptor_, &MessageOptions::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- FieldOptions_descriptor_, &FieldOptions::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- OneofOptions_descriptor_, &OneofOptions::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- EnumOptions_descriptor_, &EnumOptions::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- EnumValueOptions_descriptor_, &EnumValueOptions::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- ServiceOptions_descriptor_, &ServiceOptions::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- MethodOptions_descriptor_, &MethodOptions::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- UninterpretedOption_descriptor_, &UninterpretedOption::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- UninterpretedOption_NamePart_descriptor_, &UninterpretedOption_NamePart::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- SourceCodeInfo_descriptor_, &SourceCodeInfo::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- SourceCodeInfo_Location_descriptor_, &SourceCodeInfo_Location::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- GeneratedCodeInfo_descriptor_, &GeneratedCodeInfo::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- GeneratedCodeInfo_Annotation_descriptor_, &GeneratedCodeInfo_Annotation::default_instance());
+ ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 25);
}
} // 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 TableStruct::Shutdown() {
+ _FileDescriptorSet_default_instance_.Shutdown();
+ delete file_level_metadata[0].reflection;
+ _FileDescriptorProto_default_instance_.Shutdown();
+ delete file_level_metadata[1].reflection;
+ _DescriptorProto_ExtensionRange_default_instance_.Shutdown();
+ delete file_level_metadata[2].reflection;
+ _DescriptorProto_ReservedRange_default_instance_.Shutdown();
+ delete file_level_metadata[3].reflection;
+ _DescriptorProto_default_instance_.Shutdown();
+ delete file_level_metadata[4].reflection;
+ _FieldDescriptorProto_default_instance_.Shutdown();
+ delete file_level_metadata[5].reflection;
+ _OneofDescriptorProto_default_instance_.Shutdown();
+ delete file_level_metadata[6].reflection;
+ _EnumDescriptorProto_default_instance_.Shutdown();
+ delete file_level_metadata[7].reflection;
+ _EnumValueDescriptorProto_default_instance_.Shutdown();
+ delete file_level_metadata[8].reflection;
+ _ServiceDescriptorProto_default_instance_.Shutdown();
+ delete file_level_metadata[9].reflection;
+ _MethodDescriptorProto_default_instance_.Shutdown();
+ delete file_level_metadata[10].reflection;
+ _FileOptions_default_instance_.Shutdown();
+ delete file_level_metadata[11].reflection;
+ _MessageOptions_default_instance_.Shutdown();
+ delete file_level_metadata[12].reflection;
+ _FieldOptions_default_instance_.Shutdown();
+ delete file_level_metadata[13].reflection;
+ _OneofOptions_default_instance_.Shutdown();
+ delete file_level_metadata[14].reflection;
+ _EnumOptions_default_instance_.Shutdown();
+ delete file_level_metadata[15].reflection;
+ _EnumValueOptions_default_instance_.Shutdown();
+ delete file_level_metadata[16].reflection;
+ _ServiceOptions_default_instance_.Shutdown();
+ delete file_level_metadata[17].reflection;
+ _MethodOptions_default_instance_.Shutdown();
+ delete file_level_metadata[18].reflection;
+ _UninterpretedOption_NamePart_default_instance_.Shutdown();
+ delete file_level_metadata[19].reflection;
+ _UninterpretedOption_default_instance_.Shutdown();
+ delete file_level_metadata[20].reflection;
+ _SourceCodeInfo_Location_default_instance_.Shutdown();
+ delete file_level_metadata[21].reflection;
+ _SourceCodeInfo_default_instance_.Shutdown();
+ delete file_level_metadata[22].reflection;
+ _GeneratedCodeInfo_Annotation_default_instance_.Shutdown();
+ delete file_level_metadata[23].reflection;
+ _GeneratedCodeInfo_default_instance_.Shutdown();
+ delete file_level_metadata[24].reflection;
+}
+
+void TableStruct::InitDefaultsImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
+ ::google::protobuf::internal::InitProtobufDefaults();
+ _FileDescriptorSet_default_instance_.DefaultConstruct();
+ _FileDescriptorProto_default_instance_.DefaultConstruct();
+ _DescriptorProto_ExtensionRange_default_instance_.DefaultConstruct();
+ _DescriptorProto_ReservedRange_default_instance_.DefaultConstruct();
+ _DescriptorProto_default_instance_.DefaultConstruct();
+ _FieldDescriptorProto_default_instance_.DefaultConstruct();
+ _OneofDescriptorProto_default_instance_.DefaultConstruct();
+ _EnumDescriptorProto_default_instance_.DefaultConstruct();
+ _EnumValueDescriptorProto_default_instance_.DefaultConstruct();
+ _ServiceDescriptorProto_default_instance_.DefaultConstruct();
+ _MethodDescriptorProto_default_instance_.DefaultConstruct();
+ _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();
+ _UninterpretedOption_NamePart_default_instance_.DefaultConstruct();
+ _UninterpretedOption_default_instance_.DefaultConstruct();
+ _SourceCodeInfo_Location_default_instance_.DefaultConstruct();
+ _SourceCodeInfo_default_instance_.DefaultConstruct();
+ _GeneratedCodeInfo_Annotation_default_instance_.DefaultConstruct();
+ _GeneratedCodeInfo_default_instance_.DefaultConstruct();
+ _FileDescriptorProto_default_instance_.get_mutable()->options_ = const_cast< ::google::protobuf::FileOptions*>(
+ ::google::protobuf::FileOptions::internal_default_instance());
+ _FileDescriptorProto_default_instance_.get_mutable()->source_code_info_ = const_cast< ::google::protobuf::SourceCodeInfo*>(
+ ::google::protobuf::SourceCodeInfo::internal_default_instance());
+ _DescriptorProto_default_instance_.get_mutable()->options_ = const_cast< ::google::protobuf::MessageOptions*>(
+ ::google::protobuf::MessageOptions::internal_default_instance());
+ _FieldDescriptorProto_default_instance_.get_mutable()->options_ = const_cast< ::google::protobuf::FieldOptions*>(
+ ::google::protobuf::FieldOptions::internal_default_instance());
+ _OneofDescriptorProto_default_instance_.get_mutable()->options_ = const_cast< ::google::protobuf::OneofOptions*>(
+ ::google::protobuf::OneofOptions::internal_default_instance());
+ _EnumDescriptorProto_default_instance_.get_mutable()->options_ = const_cast< ::google::protobuf::EnumOptions*>(
+ ::google::protobuf::EnumOptions::internal_default_instance());
+ _EnumValueDescriptorProto_default_instance_.get_mutable()->options_ = const_cast< ::google::protobuf::EnumValueOptions*>(
+ ::google::protobuf::EnumValueOptions::internal_default_instance());
+ _ServiceDescriptorProto_default_instance_.get_mutable()->options_ = const_cast< ::google::protobuf::ServiceOptions*>(
+ ::google::protobuf::ServiceOptions::internal_default_instance());
+ _MethodDescriptorProto_default_instance_.get_mutable()->options_ = const_cast< ::google::protobuf::MethodOptions*>(
+ ::google::protobuf::MethodOptions::internal_default_instance());
+}
+
+void InitDefaults() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &TableStruct::InitDefaultsImpl);
+}
+void AddDescriptorsImpl() {
+ InitDefaults();
+ static const char descriptor[] = {
+ "\n google/protobuf/descriptor.proto\022\017goog"
+ "le.protobuf\"G\n\021FileDescriptorSet\0222\n\004file"
+ "\030\001 \003(\0132$.google.protobuf.FileDescriptorP"
+ "roto\"\333\003\n\023FileDescriptorProto\022\014\n\004name\030\001 \001"
+ "(\t\022\017\n\007package\030\002 \001(\t\022\022\n\ndependency\030\003 \003(\t\022"
+ "\031\n\021public_dependency\030\n \003(\005\022\027\n\017weak_depen"
+ "dency\030\013 \003(\005\0226\n\014message_type\030\004 \003(\0132 .goog"
+ "le.protobuf.DescriptorProto\0227\n\tenum_type"
+ "\030\005 \003(\0132$.google.protobuf.EnumDescriptorP"
+ "roto\0228\n\007service\030\006 \003(\0132\'.google.protobuf."
+ "ServiceDescriptorProto\0228\n\textension\030\007 \003("
+ "\0132%.google.protobuf.FieldDescriptorProto"
+ "\022-\n\007options\030\010 \001(\0132\034.google.protobuf.File"
+ "Options\0229\n\020source_code_info\030\t \001(\0132\037.goog"
+ "le.protobuf.SourceCodeInfo\022\016\n\006syntax\030\014 \001"
+ "(\t\"\360\004\n\017DescriptorProto\022\014\n\004name\030\001 \001(\t\0224\n\005"
+ "field\030\002 \003(\0132%.google.protobuf.FieldDescr"
+ "iptorProto\0228\n\textension\030\006 \003(\0132%.google.p"
+ "rotobuf.FieldDescriptorProto\0225\n\013nested_t"
+ "ype\030\003 \003(\0132 .google.protobuf.DescriptorPr"
+ "oto\0227\n\tenum_type\030\004 \003(\0132$.google.protobuf"
+ ".EnumDescriptorProto\022H\n\017extension_range\030"
+ "\005 \003(\0132/.google.protobuf.DescriptorProto."
+ "ExtensionRange\0229\n\noneof_decl\030\010 \003(\0132%.goo"
+ "gle.protobuf.OneofDescriptorProto\0220\n\007opt"
+ "ions\030\007 \001(\0132\037.google.protobuf.MessageOpti"
+ "ons\022F\n\016reserved_range\030\t \003(\0132..google.pro"
+ "tobuf.DescriptorProto.ReservedRange\022\025\n\rr"
+ "eserved_name\030\n \003(\t\032,\n\016ExtensionRange\022\r\n\005"
+ "start\030\001 \001(\005\022\013\n\003end\030\002 \001(\005\032+\n\rReservedRang"
+ "e\022\r\n\005start\030\001 \001(\005\022\013\n\003end\030\002 \001(\005\"\274\005\n\024FieldD"
+ "escriptorProto\022\014\n\004name\030\001 \001(\t\022\016\n\006number\030\003"
+ " \001(\005\022:\n\005label\030\004 \001(\0162+.google.protobuf.Fi"
+ "eldDescriptorProto.Label\0228\n\004type\030\005 \001(\0162*"
+ ".google.protobuf.FieldDescriptorProto.Ty"
+ "pe\022\021\n\ttype_name\030\006 \001(\t\022\020\n\010extendee\030\002 \001(\t\022"
+ "\025\n\rdefault_value\030\007 \001(\t\022\023\n\013oneof_index\030\t "
+ "\001(\005\022\021\n\tjson_name\030\n \001(\t\022.\n\007options\030\010 \001(\0132"
+ "\035.google.protobuf.FieldOptions\"\266\002\n\004Type\022"
+ "\017\n\013TYPE_DOUBLE\020\001\022\016\n\nTYPE_FLOAT\020\002\022\016\n\nTYPE"
+ "_INT64\020\003\022\017\n\013TYPE_UINT64\020\004\022\016\n\nTYPE_INT32\020"
+ "\005\022\020\n\014TYPE_FIXED64\020\006\022\020\n\014TYPE_FIXED32\020\007\022\r\n"
+ "\tTYPE_BOOL\020\010\022\017\n\013TYPE_STRING\020\t\022\016\n\nTYPE_GR"
+ "OUP\020\n\022\020\n\014TYPE_MESSAGE\020\013\022\016\n\nTYPE_BYTES\020\014\022"
+ "\017\n\013TYPE_UINT32\020\r\022\r\n\tTYPE_ENUM\020\016\022\021\n\rTYPE_"
+ "SFIXED32\020\017\022\021\n\rTYPE_SFIXED64\020\020\022\017\n\013TYPE_SI"
+ "NT32\020\021\022\017\n\013TYPE_SINT64\020\022\"C\n\005Label\022\022\n\016LABE"
+ "L_OPTIONAL\020\001\022\022\n\016LABEL_REQUIRED\020\002\022\022\n\016LABE"
+ "L_REPEATED\020\003\"T\n\024OneofDescriptorProto\022\014\n\004"
+ "name\030\001 \001(\t\022.\n\007options\030\002 \001(\0132\035.google.pro"
+ "tobuf.OneofOptions\"\214\001\n\023EnumDescriptorPro"
+ "to\022\014\n\004name\030\001 \001(\t\0228\n\005value\030\002 \003(\0132).google"
+ ".protobuf.EnumValueDescriptorProto\022-\n\007op"
+ "tions\030\003 \001(\0132\034.google.protobuf.EnumOption"
+ "s\"l\n\030EnumValueDescriptorProto\022\014\n\004name\030\001 "
+ "\001(\t\022\016\n\006number\030\002 \001(\005\0222\n\007options\030\003 \001(\0132!.g"
+ "oogle.protobuf.EnumValueOptions\"\220\001\n\026Serv"
+ "iceDescriptorProto\022\014\n\004name\030\001 \001(\t\0226\n\006meth"
+ "od\030\002 \003(\0132&.google.protobuf.MethodDescrip"
+ "torProto\0220\n\007options\030\003 \001(\0132\037.google.proto"
+ "buf.ServiceOptions\"\301\001\n\025MethodDescriptorP"
+ "roto\022\014\n\004name\030\001 \001(\t\022\022\n\ninput_type\030\002 \001(\t\022\023"
+ "\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\"\264\005\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(\010B\002\030"
+ "\001\022%\n\026java_string_check_utf8\030\033 \001(\010:\005false"
+ "\022F\n\014optimize_for\030\t \001(\0162).google.protobuf"
+ ".FileOptions.OptimizeMode:\005SPEED\022\022\n\ngo_p"
+ "ackage\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:\005fal"
+ "se\022\031\n\ndeprecated\030\027 \001(\010:\005false\022\037\n\020cc_enab"
+ "le_arenas\030\037 \001(\010:\005false\022\031\n\021objc_class_pre"
+ "fix\030$ \001(\t\022\030\n\020csharp_namespace\030% \001(\t\022\024\n\014s"
+ "wift_prefix\030\' \001(\t\022\030\n\020php_class_prefix\030( "
+ "\001(\t\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.goo"
+ "gle.protobuf.UninterpretedOption\":\n\014Opti"
+ "mizeMode\022\t\n\005SPEED\020\001\022\r\n\tCODE_SIZE\020\002\022\020\n\014LI"
+ "TE_RUNTIME\020\003*\t\010\350\007\020\200\200\200\200\002J\004\010&\020\'\"\354\001\n\016Messag"
+ "eOptions\022&\n\027message_set_wire_format\030\001 \001("
+ "\010:\005false\022.\n\037no_standard_descriptor_acces"
+ "sor\030\002 \001(\010:\005false\022\031\n\ndeprecated\030\003 \001(\010:\005fa"
+ "lse\022\021\n\tmap_entry\030\007 \001(\010\022C\n\024uninterpreted_"
+ "option\030\347\007 \003(\0132$.google.protobuf.Uninterp"
+ "retedOption*\t\010\350\007\020\200\200\200\200\002J\004\010\010\020\t\"\236\003\n\014FieldOp"
+ "tions\022:\n\005ctype\030\001 \001(\0162#.google.protobuf.F"
+ "ieldOptions.CType:\006STRING\022\016\n\006packed\030\002 \001("
+ "\010\022\?\n\006jstype\030\006 \001(\0162$.google.protobuf.Fiel"
+ "dOptions.JSType:\tJS_NORMAL\022\023\n\004lazy\030\005 \001(\010"
+ ":\005false\022\031\n\ndeprecated\030\003 \001(\010:\005false\022\023\n\004we"
+ "ak\030\n \001(\010:\005false\022C\n\024uninterpreted_option\030"
+ "\347\007 \003(\0132$.google.protobuf.UninterpretedOp"
+ "tion\"/\n\005CType\022\n\n\006STRING\020\000\022\010\n\004CORD\020\001\022\020\n\014S"
+ "TRING_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\002J"
+ "\004\010\004\020\005\"^\n\014OneofOptions\022C\n\024uninterpreted_o"
+ "ption\030\347\007 \003(\0132$.google.protobuf.Uninterpr"
+ "etedOption*\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:\005"
+ "false\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.g"
+ "oogle.protobuf.UninterpretedOption*\t\010\350\007\020"
+ "\200\200\200\200\002\"}\n\020EnumValueOptions\022\031\n\ndeprecated\030"
+ "\001 \001(\010:\005false\022C\n\024uninterpreted_option\030\347\007 "
+ "\003(\0132$.google.protobuf.UninterpretedOptio"
+ "n*\t\010\350\007\020\200\200\200\200\002\"{\n\016ServiceOptions\022\031\n\ndeprec"
+ "ated\030! \001(\010:\005false\022C\n\024uninterpreted_optio"
+ "n\030\347\007 \003(\0132$.google.protobuf.Uninterpreted"
+ "Option*\t\010\350\007\020\200\200\200\200\002\"\255\002\n\rMethodOptions\022\031\n\nd"
+ "eprecated\030! \001(\010:\005false\022_\n\021idempotency_le"
+ "vel\030\" \001(\0162/.google.protobuf.MethodOption"
+ "s.IdempotencyLevel:\023IDEMPOTENCY_UNKNOWN\022"
+ "C\n\024uninterpreted_option\030\347\007 \003(\0132$.google."
+ "protobuf.UninterpretedOption\"P\n\020Idempote"
+ "ncyLevel\022\027\n\023IDEMPOTENCY_UNKNOWN\020\000\022\023\n\017NO_"
+ "SIDE_EFFECTS\020\001\022\016\n\nIDEMPOTENT\020\002*\t\010\350\007\020\200\200\200\200"
+ "\002\"\236\002\n\023UninterpretedOption\022;\n\004name\030\002 \003(\0132"
+ "-.google.protobuf.UninterpretedOption.Na"
+ "mePart\022\030\n\020identifier_value\030\003 \001(\t\022\032\n\022posi"
+ "tive_int_value\030\004 \001(\004\022\032\n\022negative_int_val"
+ "ue\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_exten"
+ "sion\030\002 \002(\010\"\325\001\n\016SourceCodeInfo\022:\n\010locatio"
+ "n\030\001 \003(\0132(.google.protobuf.SourceCodeInfo"
+ ".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_comments\030\003"
+ " \001(\t\022\031\n\021trailing_comments\030\004 \001(\t\022!\n\031leadi"
+ "ng_detached_comments\030\006 \003(\t\"\247\001\n\021Generated"
+ "CodeInfo\022A\n\nannotation\030\001 \003(\0132-.google.pr"
+ "otobuf.GeneratedCodeInfo.Annotation\032O\n\nA"
+ "nnotation\022\020\n\004path\030\001 \003(\005B\002\020\001\022\023\n\013source_fi"
+ "le\030\002 \001(\t\022\r\n\005begin\030\003 \001(\005\022\013\n\003end\030\004 \001(\005B\214\001\n"
+ "\023com.google.protobufB\020DescriptorProtosH\001"
+ "Z>github.com/golang/protobuf/protoc-gen-"
+ "go/descriptor;descriptor\242\002\003GPB\252\002\032Google."
+ "Protobuf.Reflection"
+ };
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
- "\n google/protobuf/descriptor.proto\022\017goog"
- "le.protobuf\"G\n\021FileDescriptorSet\0222\n\004file"
- "\030\001 \003(\0132$.google.protobuf.FileDescriptorP"
- "roto\"\333\003\n\023FileDescriptorProto\022\014\n\004name\030\001 \001"
- "(\t\022\017\n\007package\030\002 \001(\t\022\022\n\ndependency\030\003 \003(\t\022"
- "\031\n\021public_dependency\030\n \003(\005\022\027\n\017weak_depen"
- "dency\030\013 \003(\005\0226\n\014message_type\030\004 \003(\0132 .goog"
- "le.protobuf.DescriptorProto\0227\n\tenum_type"
- "\030\005 \003(\0132$.google.protobuf.EnumDescriptorP"
- "roto\0228\n\007service\030\006 \003(\0132\'.google.protobuf."
- "ServiceDescriptorProto\0228\n\textension\030\007 \003("
- "\0132%.google.protobuf.FieldDescriptorProto"
- "\022-\n\007options\030\010 \001(\0132\034.google.protobuf.File"
- "Options\0229\n\020source_code_info\030\t \001(\0132\037.goog"
- "le.protobuf.SourceCodeInfo\022\016\n\006syntax\030\014 \001"
- "(\t\"\360\004\n\017DescriptorProto\022\014\n\004name\030\001 \001(\t\0224\n\005"
- "field\030\002 \003(\0132%.google.protobuf.FieldDescr"
- "iptorProto\0228\n\textension\030\006 \003(\0132%.google.p"
- "rotobuf.FieldDescriptorProto\0225\n\013nested_t"
- "ype\030\003 \003(\0132 .google.protobuf.DescriptorPr"
- "oto\0227\n\tenum_type\030\004 \003(\0132$.google.protobuf"
- ".EnumDescriptorProto\022H\n\017extension_range\030"
- "\005 \003(\0132/.google.protobuf.DescriptorProto."
- "ExtensionRange\0229\n\noneof_decl\030\010 \003(\0132%.goo"
- "gle.protobuf.OneofDescriptorProto\0220\n\007opt"
- "ions\030\007 \001(\0132\037.google.protobuf.MessageOpti"
- "ons\022F\n\016reserved_range\030\t \003(\0132..google.pro"
- "tobuf.DescriptorProto.ReservedRange\022\025\n\rr"
- "eserved_name\030\n \003(\t\032,\n\016ExtensionRange\022\r\n\005"
- "start\030\001 \001(\005\022\013\n\003end\030\002 \001(\005\032+\n\rReservedRang"
- "e\022\r\n\005start\030\001 \001(\005\022\013\n\003end\030\002 \001(\005\"\274\005\n\024FieldD"
- "escriptorProto\022\014\n\004name\030\001 \001(\t\022\016\n\006number\030\003"
- " \001(\005\022:\n\005label\030\004 \001(\0162+.google.protobuf.Fi"
- "eldDescriptorProto.Label\0228\n\004type\030\005 \001(\0162*"
- ".google.protobuf.FieldDescriptorProto.Ty"
- "pe\022\021\n\ttype_name\030\006 \001(\t\022\020\n\010extendee\030\002 \001(\t\022"
- "\025\n\rdefault_value\030\007 \001(\t\022\023\n\013oneof_index\030\t "
- "\001(\005\022\021\n\tjson_name\030\n \001(\t\022.\n\007options\030\010 \001(\0132"
- "\035.google.protobuf.FieldOptions\"\266\002\n\004Type\022"
- "\017\n\013TYPE_DOUBLE\020\001\022\016\n\nTYPE_FLOAT\020\002\022\016\n\nTYPE"
- "_INT64\020\003\022\017\n\013TYPE_UINT64\020\004\022\016\n\nTYPE_INT32\020"
- "\005\022\020\n\014TYPE_FIXED64\020\006\022\020\n\014TYPE_FIXED32\020\007\022\r\n"
- "\tTYPE_BOOL\020\010\022\017\n\013TYPE_STRING\020\t\022\016\n\nTYPE_GR"
- "OUP\020\n\022\020\n\014TYPE_MESSAGE\020\013\022\016\n\nTYPE_BYTES\020\014\022"
- "\017\n\013TYPE_UINT32\020\r\022\r\n\tTYPE_ENUM\020\016\022\021\n\rTYPE_"
- "SFIXED32\020\017\022\021\n\rTYPE_SFIXED64\020\020\022\017\n\013TYPE_SI"
- "NT32\020\021\022\017\n\013TYPE_SINT64\020\022\"C\n\005Label\022\022\n\016LABE"
- "L_OPTIONAL\020\001\022\022\n\016LABEL_REQUIRED\020\002\022\022\n\016LABE"
- "L_REPEATED\020\003\"T\n\024OneofDescriptorProto\022\014\n\004"
- "name\030\001 \001(\t\022.\n\007options\030\002 \001(\0132\035.google.pro"
- "tobuf.OneofOptions\"\214\001\n\023EnumDescriptorPro"
- "to\022\014\n\004name\030\001 \001(\t\0228\n\005value\030\002 \003(\0132).google"
- ".protobuf.EnumValueDescriptorProto\022-\n\007op"
- "tions\030\003 \001(\0132\034.google.protobuf.EnumOption"
- "s\"l\n\030EnumValueDescriptorProto\022\014\n\004name\030\001 "
- "\001(\t\022\016\n\006number\030\002 \001(\005\0222\n\007options\030\003 \001(\0132!.g"
- "oogle.protobuf.EnumValueOptions\"\220\001\n\026Serv"
- "iceDescriptorProto\022\014\n\004name\030\001 \001(\t\0226\n\006meth"
- "od\030\002 \003(\0132&.google.protobuf.MethodDescrip"
- "torProto\0220\n\007options\030\003 \001(\0132\037.google.proto"
- "buf.ServiceOptions\"\301\001\n\025MethodDescriptorP"
- "roto\022\014\n\004name\030\001 \001(\t\022\022\n\ninput_type\030\002 \001(\t\022\023"
- "\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"
- "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"
- "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"
- "Type:\tJS_NORMAL\022\023\n\004lazy\030\005 \001(\010:\005false\022\031\n\n"
- "deprecated\030\003 \001(\010:\005false\022\023\n\004weak\030\n \001(\010:\005f"
- "alse\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.go"
- "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);
+ descriptor, 5579);
::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::internal::OnShutdown(&TableStruct::Shutdown);
}
+void AddDescriptors() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
+}
// Force AddDescriptors() to be called at static initialization time.
-struct StaticDescriptorInitializer_google_2fprotobuf_2fdescriptor_2eproto {
- StaticDescriptorInitializer_google_2fprotobuf_2fdescriptor_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
+struct StaticDescriptorInitializer {
+ StaticDescriptorInitializer() {
+ AddDescriptors();
+ }
+} static_descriptor_initializer;
+
+} // namespace protobuf_google_2fprotobuf_2fdescriptor_2eproto
+
+const ::google::protobuf::EnumDescriptor* FieldDescriptorProto_Type_descriptor() {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_enum_descriptors[0];
+}
+bool FieldDescriptorProto_Type_IsValid(int value) {
+ switch (value) {
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ case 8:
+ case 9:
+ case 10:
+ case 11:
+ case 12:
+ case 13:
+ case 14:
+ case 15:
+ case 16:
+ case 17:
+ case 18:
+ return true;
+ default:
+ return false;
+ }
+}
+
+#if !defined(_MSC_VER) || _MSC_VER >= 1900
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_DOUBLE;
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_FLOAT;
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_INT64;
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_UINT64;
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_INT32;
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_FIXED64;
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_FIXED32;
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_BOOL;
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_STRING;
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_GROUP;
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_MESSAGE;
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_BYTES;
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_UINT32;
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_ENUM;
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_SFIXED32;
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_SFIXED64;
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_SINT32;
+const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_SINT64;
+const FieldDescriptorProto_Type FieldDescriptorProto::Type_MIN;
+const FieldDescriptorProto_Type FieldDescriptorProto::Type_MAX;
+const int FieldDescriptorProto::Type_ARRAYSIZE;
+#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
+const ::google::protobuf::EnumDescriptor* FieldDescriptorProto_Label_descriptor() {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_enum_descriptors[1];
+}
+bool FieldDescriptorProto_Label_IsValid(int value) {
+ switch (value) {
+ case 1:
+ case 2:
+ case 3:
+ return true;
+ default:
+ return false;
+ }
+}
+
+#if !defined(_MSC_VER) || _MSC_VER >= 1900
+const FieldDescriptorProto_Label FieldDescriptorProto::LABEL_OPTIONAL;
+const FieldDescriptorProto_Label FieldDescriptorProto::LABEL_REQUIRED;
+const FieldDescriptorProto_Label FieldDescriptorProto::LABEL_REPEATED;
+const FieldDescriptorProto_Label FieldDescriptorProto::Label_MIN;
+const FieldDescriptorProto_Label FieldDescriptorProto::Label_MAX;
+const int FieldDescriptorProto::Label_ARRAYSIZE;
+#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
+const ::google::protobuf::EnumDescriptor* FileOptions_OptimizeMode_descriptor() {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_enum_descriptors[2];
+}
+bool FileOptions_OptimizeMode_IsValid(int value) {
+ switch (value) {
+ case 1:
+ case 2:
+ case 3:
+ return true;
+ default:
+ return false;
+ }
+}
+
+#if !defined(_MSC_VER) || _MSC_VER >= 1900
+const FileOptions_OptimizeMode FileOptions::SPEED;
+const FileOptions_OptimizeMode FileOptions::CODE_SIZE;
+const FileOptions_OptimizeMode FileOptions::LITE_RUNTIME;
+const FileOptions_OptimizeMode FileOptions::OptimizeMode_MIN;
+const FileOptions_OptimizeMode FileOptions::OptimizeMode_MAX;
+const int FileOptions::OptimizeMode_ARRAYSIZE;
+#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
+const ::google::protobuf::EnumDescriptor* FieldOptions_CType_descriptor() {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_enum_descriptors[3];
+}
+bool FieldOptions_CType_IsValid(int value) {
+ switch (value) {
+ case 0:
+ case 1:
+ case 2:
+ return true;
+ default:
+ return false;
+ }
+}
+
+#if !defined(_MSC_VER) || _MSC_VER >= 1900
+const FieldOptions_CType FieldOptions::STRING;
+const FieldOptions_CType FieldOptions::CORD;
+const FieldOptions_CType FieldOptions::STRING_PIECE;
+const FieldOptions_CType FieldOptions::CType_MIN;
+const FieldOptions_CType FieldOptions::CType_MAX;
+const int FieldOptions::CType_ARRAYSIZE;
+#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
+const ::google::protobuf::EnumDescriptor* FieldOptions_JSType_descriptor() {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_enum_descriptors[4];
+}
+bool FieldOptions_JSType_IsValid(int value) {
+ switch (value) {
+ case 0:
+ case 1:
+ case 2:
+ return true;
+ default:
+ return false;
+ }
+}
+
+#if !defined(_MSC_VER) || _MSC_VER >= 1900
+const FieldOptions_JSType FieldOptions::JS_NORMAL;
+const FieldOptions_JSType FieldOptions::JS_STRING;
+const FieldOptions_JSType FieldOptions::JS_NUMBER;
+const FieldOptions_JSType FieldOptions::JSType_MIN;
+const FieldOptions_JSType FieldOptions::JSType_MAX;
+const int FieldOptions::JSType_ARRAYSIZE;
+#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
+const ::google::protobuf::EnumDescriptor* MethodOptions_IdempotencyLevel_descriptor() {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_enum_descriptors[5];
+}
+bool MethodOptions_IdempotencyLevel_IsValid(int value) {
+ switch (value) {
+ case 0:
+ case 1:
+ case 2:
+ return true;
+ default:
+ return false;
}
-} static_descriptor_initializer_google_2fprotobuf_2fdescriptor_2eproto_;
+}
+
+#if !defined(_MSC_VER) || _MSC_VER >= 1900
+const MethodOptions_IdempotencyLevel MethodOptions::IDEMPOTENCY_UNKNOWN;
+const MethodOptions_IdempotencyLevel MethodOptions::NO_SIDE_EFFECTS;
+const MethodOptions_IdempotencyLevel MethodOptions::IDEMPOTENT;
+const MethodOptions_IdempotencyLevel MethodOptions::IdempotencyLevel_MIN;
+const MethodOptions_IdempotencyLevel MethodOptions::IdempotencyLevel_MAX;
+const int MethodOptions::IdempotencyLevel_ARRAYSIZE;
+#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
// ===================================================================
@@ -910,24 +937,24 @@ const int FileDescriptorSet::kFileFieldNumber;
FileDescriptorSet::FileDescriptorSet()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.FileDescriptorSet)
}
-
-void FileDescriptorSet::InitAsDefaultInstance() {
-}
-
FileDescriptorSet::FileDescriptorSet(const FileDescriptorSet& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ file_(from.file_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
// @@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 +963,6 @@ FileDescriptorSet::~FileDescriptorSet() {
}
void FileDescriptorSet::SharedDtor() {
- if (this != default_instance_) {
- }
}
void FileDescriptorSet::SetCachedSize(int size) const {
@@ -946,17 +971,15 @@ void FileDescriptorSet::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* FileDescriptorSet::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return FileDescriptorSet_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[0].descriptor;
}
const FileDescriptorSet& FileDescriptorSet::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-FileDescriptorSet* FileDescriptorSet::default_instance_ = NULL;
-
FileDescriptorSet* FileDescriptorSet::New(::google::protobuf::Arena* arena) const {
FileDescriptorSet* n = new FileDescriptorSet;
if (arena != NULL) {
@@ -968,10 +991,8 @@ 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_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
- }
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool FileDescriptorSet::MergePartialFromCodedStream(
@@ -980,23 +1001,21 @@ bool FileDescriptorSet::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.FileDescriptorSet)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// repeated .google.protobuf.FileDescriptorProto file = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_file:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_file()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(10)) goto parse_loop_file;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -1040,6 +1059,7 @@ void FileDescriptorSet::SerializeWithCachedSizes(
::google::protobuf::uint8* FileDescriptorSet::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FileDescriptorSet)
// repeated .google.protobuf.FileDescriptorProto file = 1;
for (unsigned int i = 0, n = this->file_size(); i < n; i++) {
@@ -1056,35 +1076,37 @@ 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;
-
- // 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));
- }
+ size_t total_size = 0;
if (_internal_metadata_.have_unknown_fields()) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
unknown_fields());
}
+ // repeated .google.protobuf.FileDescriptorProto file = 1;
+ {
+ 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));
+ }
+ }
+
+ 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const FileDescriptorSet* source =
::google::protobuf::internal::DynamicCastToGenerated<const FileDescriptorSet>(
&from);
if (source == NULL) {
@@ -1098,13 +1120,9 @@ void FileDescriptorSet::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
file_.MergeFrom(from.file_);
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void FileDescriptorSet::CopyFrom(const ::google::protobuf::Message& from) {
@@ -1122,7 +1140,6 @@ void FileDescriptorSet::CopyFrom(const FileDescriptorSet& from) {
}
bool FileDescriptorSet::IsInitialized() const {
-
if (!::google::protobuf::internal::AllAreInitialized(this->file())) return false;
return true;
}
@@ -1139,11 +1156,8 @@ void FileDescriptorSet::InternalSwap(FileDescriptorSet* other) {
}
::google::protobuf::Metadata FileDescriptorSet::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = FileDescriptorSet_descriptor_;
- metadata.reflection = FileDescriptorSet_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[0];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -1200,32 +1214,57 @@ const int FileDescriptorProto::kSyntaxFieldNumber;
FileDescriptorProto::FileDescriptorProto()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
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());
-}
-
FileDescriptorProto::FileDescriptorProto(const FileDescriptorProto& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ dependency_(from.dependency_),
+ public_dependency_(from.public_dependency_),
+ weak_dependency_(from.weak_dependency_),
+ message_type_(from.message_type_),
+ enum_type_(from.enum_type_),
+ service_(from.service_),
+ extension_(from.extension_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_name()) {
+ name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
+ }
+ package_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_package()) {
+ package_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.package_);
+ }
+ syntax_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_syntax()) {
+ syntax_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.syntax_);
+ }
+ if (from.has_options()) {
+ options_ = new ::google::protobuf::FileOptions(*from.options_);
+ } else {
+ options_ = NULL;
+ }
+ if (from.has_source_code_info()) {
+ source_code_info_ = new ::google::protobuf::SourceCodeInfo(*from.source_code_info_);
+ } else {
+ source_code_info_ = NULL;
+ }
// @@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());
- options_ = NULL;
- source_code_info_ = NULL;
syntax_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
+ ::memset(&options_, 0, reinterpret_cast<char*>(&source_code_info_) -
+ reinterpret_cast<char*>(&options_) + sizeof(source_code_info_));
}
FileDescriptorProto::~FileDescriptorProto() {
@@ -1237,8 +1276,10 @@ 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_) {
+ if (this != internal_default_instance()) {
delete options_;
+ }
+ if (this != internal_default_instance()) {
delete source_code_info_;
}
}
@@ -1249,17 +1290,15 @@ void FileDescriptorProto::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* FileDescriptorProto::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return FileDescriptorProto_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[1].descriptor;
}
const FileDescriptorProto& FileDescriptorProto::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-FileDescriptorProto* FileDescriptorProto::default_instance_ = NULL;
-
FileDescriptorProto* FileDescriptorProto::New(::google::protobuf::Arena* arena) const {
FileDescriptorProto* n = new FileDescriptorProto;
if (arena != NULL) {
@@ -1270,36 +1309,37 @@ FileDescriptorProto* FileDescriptorProto::New(::google::protobuf::Arena* arena)
void FileDescriptorProto::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.FileDescriptorProto)
- if (_has_bits_[0 / 32] & 3u) {
+ dependency_.Clear();
+ public_dependency_.Clear();
+ weak_dependency_.Clear();
+ message_type_.Clear();
+ enum_type_.Clear();
+ service_.Clear();
+ extension_.Clear();
+ if (_has_bits_[0 / 32] & 31u) {
if (has_name()) {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*name_.UnsafeRawStringPointer())->clear();
}
if (has_package()) {
- package_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!package_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*package_.UnsafeRawStringPointer())->clear();
+ }
+ if (has_syntax()) {
+ GOOGLE_DCHECK(!syntax_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*syntax_.UnsafeRawStringPointer())->clear();
}
- }
- if (_has_bits_[8 / 32] & 3584u) {
if (has_options()) {
- if (options_ != NULL) options_->::google::protobuf::FileOptions::Clear();
+ GOOGLE_DCHECK(options_ != NULL);
+ options_->::google::protobuf::FileOptions::Clear();
}
if (has_source_code_info()) {
- if (source_code_info_ != NULL) source_code_info_->::google::protobuf::SourceCodeInfo::Clear();
- }
- if (has_syntax()) {
- syntax_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(source_code_info_ != NULL);
+ source_code_info_->::google::protobuf::SourceCodeInfo::Clear();
}
}
- dependency_.Clear();
- public_dependency_.Clear();
- weak_dependency_.Clear();
- message_type_.Clear();
- enum_type_.Clear();
- service_.Clear();
- extension_.Clear();
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
- }
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool FileDescriptorProto::MergePartialFromCodedStream(
@@ -1308,13 +1348,14 @@ bool FileDescriptorProto::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.FileDescriptorProto)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional string name = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -1324,14 +1365,13 @@ bool FileDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_package;
break;
}
// optional string package = 2;
case 2: {
- if (tag == 18) {
- parse_package:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_package()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -1341,14 +1381,13 @@ bool FileDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(26)) goto parse_dependency;
break;
}
// repeated string dependency = 3;
case 3: {
- if (tag == 26) {
- parse_dependency:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(26u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->add_dependency()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -1359,144 +1398,129 @@ bool FileDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(26)) goto parse_dependency;
- if (input->ExpectTag(34)) goto parse_message_type;
break;
}
// repeated .google.protobuf.DescriptorProto message_type = 4;
case 4: {
- if (tag == 34) {
- parse_message_type:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(34u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_message_type:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_message_type()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(34)) goto parse_loop_message_type;
- if (input->ExpectTag(42)) goto parse_loop_enum_type;
input->UnsafeDecrementRecursionDepth();
break;
}
// repeated .google.protobuf.EnumDescriptorProto enum_type = 5;
case 5: {
- if (tag == 42) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(42u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_enum_type:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_enum_type()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(42)) goto parse_loop_enum_type;
- if (input->ExpectTag(50)) goto parse_loop_service;
input->UnsafeDecrementRecursionDepth();
break;
}
// repeated .google.protobuf.ServiceDescriptorProto service = 6;
case 6: {
- if (tag == 50) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(50u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_service:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_service()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(50)) goto parse_loop_service;
- if (input->ExpectTag(58)) goto parse_loop_extension;
input->UnsafeDecrementRecursionDepth();
break;
}
// repeated .google.protobuf.FieldDescriptorProto extension = 7;
case 7: {
- if (tag == 58) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(58u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_extension:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_extension()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(58)) goto parse_loop_extension;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectTag(66)) goto parse_options;
break;
}
// optional .google.protobuf.FileOptions options = 8;
case 8: {
- if (tag == 66) {
- parse_options:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(66u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, mutable_options()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(74)) goto parse_source_code_info;
break;
}
// optional .google.protobuf.SourceCodeInfo source_code_info = 9;
case 9: {
- if (tag == 74) {
- parse_source_code_info:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(74u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, mutable_source_code_info()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(80)) goto parse_public_dependency;
break;
}
// repeated int32 public_dependency = 10;
case 10: {
- if (tag == 80) {
- parse_public_dependency:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(80u)) {
DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
- 1, 80, input, this->mutable_public_dependency())));
- } else if (tag == 82) {
+ 1, 80u, input, this->mutable_public_dependency())));
+ } else if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(82u)) {
DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitiveNoInline<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
input, this->mutable_public_dependency())));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(80)) goto parse_public_dependency;
- if (input->ExpectTag(88)) goto parse_weak_dependency;
break;
}
// repeated int32 weak_dependency = 11;
case 11: {
- if (tag == 88) {
- parse_weak_dependency:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(88u)) {
DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
- 1, 88, input, this->mutable_weak_dependency())));
- } else if (tag == 90) {
+ 1, 88u, input, this->mutable_weak_dependency())));
+ } else if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(90u)) {
DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitiveNoInline<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
input, this->mutable_weak_dependency())));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(88)) goto parse_weak_dependency;
- if (input->ExpectTag(98)) goto parse_syntax;
break;
}
// optional string syntax = 12;
case 12: {
- if (tag == 98) {
- parse_syntax:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(98u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_syntax()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -1506,7 +1530,6 @@ bool FileDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -1556,7 +1579,7 @@ void FileDescriptorProto::SerializeWithCachedSizes(
}
// repeated string dependency = 3;
- for (int i = 0; i < this->dependency_size(); i++) {
+ for (int i = 0, n = this->dependency_size(); i < n; i++) {
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
this->dependency(i).data(), this->dependency(i).length(),
::google::protobuf::internal::WireFormat::SERIALIZE,
@@ -1602,13 +1625,13 @@ void FileDescriptorProto::SerializeWithCachedSizes(
}
// repeated int32 public_dependency = 10;
- for (int i = 0; i < this->public_dependency_size(); i++) {
+ for (int i = 0, n = this->public_dependency_size(); i < n; i++) {
::google::protobuf::internal::WireFormatLite::WriteInt32(
10, this->public_dependency(i), output);
}
// repeated int32 weak_dependency = 11;
- for (int i = 0; i < this->weak_dependency_size(); i++) {
+ for (int i = 0, n = this->weak_dependency_size(); i < n; i++) {
::google::protobuf::internal::WireFormatLite::WriteInt32(
11, this->weak_dependency(i), output);
}
@@ -1632,6 +1655,7 @@ void FileDescriptorProto::SerializeWithCachedSizes(
::google::protobuf::uint8* FileDescriptorProto::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FileDescriptorProto)
// optional string name = 1;
if (has_name()) {
@@ -1656,7 +1680,7 @@ void FileDescriptorProto::SerializeWithCachedSizes(
}
// repeated string dependency = 3;
- for (int i = 0; i < this->dependency_size(); i++) {
+ for (int i = 0, n = this->dependency_size(); i < n; i++) {
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
this->dependency(i).data(), this->dependency(i).length(),
::google::protobuf::internal::WireFormat::SERIALIZE,
@@ -1708,13 +1732,13 @@ void FileDescriptorProto::SerializeWithCachedSizes(
}
// repeated int32 public_dependency = 10;
- for (int i = 0; i < this->public_dependency_size(); i++) {
+ for (int i = 0, n = this->public_dependency_size(); i < n; i++) {
target = ::google::protobuf::internal::WireFormatLite::
WriteInt32ToArray(10, this->public_dependency(i), target);
}
// repeated int32 weak_dependency = 11;
- for (int i = 0; i < this->weak_dependency_size(); i++) {
+ for (int i = 0, n = this->weak_dependency_size(); i < n; i++) {
target = ::google::protobuf::internal::WireFormatLite::
WriteInt32ToArray(11, this->weak_dependency(i), target);
}
@@ -1738,11 +1762,86 @@ 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) {
+ if (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
+ // repeated string dependency = 3;
+ total_size += 1 *
+ ::google::protobuf::internal::FromIntSize(this->dependency_size());
+ for (int i = 0, n = this->dependency_size(); i < n; i++) {
+ total_size += ::google::protobuf::internal::WireFormatLite::StringSize(
+ this->dependency(i));
+ }
+
+ // repeated int32 public_dependency = 10;
+ {
+ size_t data_size = ::google::protobuf::internal::WireFormatLite::
+ Int32Size(this->public_dependency_);
+ total_size += 1 *
+ ::google::protobuf::internal::FromIntSize(this->public_dependency_size());
+ total_size += data_size;
+ }
+
+ // repeated int32 weak_dependency = 11;
+ {
+ size_t data_size = ::google::protobuf::internal::WireFormatLite::
+ Int32Size(this->weak_dependency_);
+ total_size += 1 *
+ ::google::protobuf::internal::FromIntSize(this->weak_dependency_size());
+ total_size += data_size;
+ }
+
+ // repeated .google.protobuf.DescriptorProto message_type = 4;
+ {
+ 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;
+ {
+ 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;
+ {
+ 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;
+ {
+ 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 (_has_bits_[0 / 32] & 31u) {
// optional string name = 1;
if (has_name()) {
total_size += 1 +
@@ -1757,8 +1856,13 @@ int FileDescriptorProto::ByteSize() const {
this->package());
}
- }
- if (_has_bits_[9 / 32] & 3584u) {
+ // optional string syntax = 12;
+ if (has_syntax()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::StringSize(
+ this->syntax());
+ }
+
// optional .google.protobuf.FileOptions options = 8;
if (has_options()) {
total_size += 1 +
@@ -1773,90 +1877,18 @@ int FileDescriptorProto::ByteSize() const {
*this->source_code_info_);
}
- // optional string syntax = 12;
- if (has_syntax()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::StringSize(
- this->syntax());
- }
-
- }
- // repeated string dependency = 3;
- total_size += 1 * this->dependency_size();
- for (int i = 0; i < this->dependency_size(); i++) {
- total_size += ::google::protobuf::internal::WireFormatLite::StringSize(
- this->dependency(i));
- }
-
- // repeated int32 public_dependency = 10;
- {
- int data_size = 0;
- for (int i = 0; i < this->public_dependency_size(); i++) {
- data_size += ::google::protobuf::internal::WireFormatLite::
- Int32Size(this->public_dependency(i));
- }
- total_size += 1 * this->public_dependency_size() + data_size;
- }
-
- // repeated int32 weak_dependency = 11;
- {
- int data_size = 0;
- for (int i = 0; i < this->weak_dependency_size(); i++) {
- data_size += ::google::protobuf::internal::WireFormatLite::
- Int32Size(this->weak_dependency(i));
- }
- total_size += 1 * this->weak_dependency_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));
- }
-
- // 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));
- }
-
- // 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));
- }
-
- // 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));
- }
-
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const FileDescriptorProto* source =
::google::protobuf::internal::DynamicCastToGenerated<const FileDescriptorProto>(
&from);
if (source == NULL) {
@@ -1870,9 +1902,8 @@ void FileDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
dependency_.MergeFrom(from.dependency_);
public_dependency_.MergeFrom(from.public_dependency_);
weak_dependency_.MergeFrom(from.weak_dependency_);
@@ -1880,7 +1911,7 @@ void FileDescriptorProto::MergeFrom(const FileDescriptorProto& from) {
enum_type_.MergeFrom(from.enum_type_);
service_.MergeFrom(from.service_);
extension_.MergeFrom(from.extension_);
- if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+ if (from._has_bits_[0 / 32] & 31u) {
if (from.has_name()) {
set_has_name();
name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
@@ -1889,21 +1920,16 @@ void FileDescriptorProto::MergeFrom(const FileDescriptorProto& from) {
set_has_package();
package_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.package_);
}
- }
- if (from._has_bits_[9 / 32] & (0xffu << (9 % 32))) {
+ if (from.has_syntax()) {
+ set_has_syntax();
+ syntax_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.syntax_);
+ }
if (from.has_options()) {
mutable_options()->::google::protobuf::FileOptions::MergeFrom(from.options());
}
if (from.has_source_code_info()) {
mutable_source_code_info()->::google::protobuf::SourceCodeInfo::MergeFrom(from.source_code_info());
}
- if (from.has_syntax()) {
- set_has_syntax();
- syntax_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.syntax_);
- }
- }
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
}
}
@@ -1922,7 +1948,6 @@ void FileDescriptorProto::CopyFrom(const FileDescriptorProto& from) {
}
bool FileDescriptorProto::IsInitialized() const {
-
if (!::google::protobuf::internal::AllAreInitialized(this->message_type())) return false;
if (!::google::protobuf::internal::AllAreInitialized(this->enum_type())) return false;
if (!::google::protobuf::internal::AllAreInitialized(this->service())) return false;
@@ -1938,8 +1963,6 @@ void FileDescriptorProto::Swap(FileDescriptorProto* other) {
InternalSwap(other);
}
void FileDescriptorProto::InternalSwap(FileDescriptorProto* other) {
- name_.Swap(&other->name_);
- package_.Swap(&other->package_);
dependency_.UnsafeArenaSwap(&other->dependency_);
public_dependency_.UnsafeArenaSwap(&other->public_dependency_);
weak_dependency_.UnsafeArenaSwap(&other->weak_dependency_);
@@ -1947,20 +1970,19 @@ void FileDescriptorProto::InternalSwap(FileDescriptorProto* other) {
enum_type_.UnsafeArenaSwap(&other->enum_type_);
service_.UnsafeArenaSwap(&other->service_);
extension_.UnsafeArenaSwap(&other->extension_);
+ name_.Swap(&other->name_);
+ package_.Swap(&other->package_);
+ syntax_.Swap(&other->syntax_);
std::swap(options_, other->options_);
std::swap(source_code_info_, other->source_code_info_);
- syntax_.Swap(&other->syntax_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata FileDescriptorProto::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = FileDescriptorProto_descriptor_;
- metadata.reflection = FileDescriptorProto_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[1];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -1980,37 +2002,45 @@ 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());
+ return name_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void FileDescriptorProto::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileDescriptorProto.name)
+}
+#endif
+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<const char*>(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 {
@@ -2034,37 +2064,45 @@ 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());
+ return package_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void FileDescriptorProto::set_package(::std::string&& value) {
+ set_has_package();
+ package_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileDescriptorProto.package)
+}
+#endif
+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<const char*>(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 {
@@ -2081,49 +2119,61 @@ 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) {
+#if LANG_CXX11
+void FileDescriptorProto::set_dependency(int index, ::std::string&& value) {
+ // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.dependency)
+ dependency_.Mutable(index)->assign(std::move(value));
+}
+#endif
+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<const char*>(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) {
+#if LANG_CXX11
+void FileDescriptorProto::add_dependency(::std::string&& value) {
+ dependency_.Add()->assign(std::move(value));
+ // @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.dependency)
+}
+#endif
+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<const char*>(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_;
@@ -2136,24 +2186,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_;
@@ -2166,24 +2216,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_;
@@ -2311,13 +2361,13 @@ FileDescriptorProto::extension() const {
// optional .google.protobuf.FileOptions options = 8;
bool FileDescriptorProto::has_options() const {
- return (_has_bits_[0] & 0x00000200u) != 0;
+ return (_has_bits_[0] & 0x00000008u) != 0;
}
void FileDescriptorProto::set_has_options() {
- _has_bits_[0] |= 0x00000200u;
+ _has_bits_[0] |= 0x00000008u;
}
void FileDescriptorProto::clear_has_options() {
- _has_bits_[0] &= ~0x00000200u;
+ _has_bits_[0] &= ~0x00000008u;
}
void FileDescriptorProto::clear_options() {
if (options_ != NULL) options_->::google::protobuf::FileOptions::Clear();
@@ -2325,7 +2375,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();
@@ -2355,13 +2406,13 @@ void FileDescriptorProto::set_allocated_options(::google::protobuf::FileOptions*
// optional .google.protobuf.SourceCodeInfo source_code_info = 9;
bool FileDescriptorProto::has_source_code_info() const {
- return (_has_bits_[0] & 0x00000400u) != 0;
+ return (_has_bits_[0] & 0x00000010u) != 0;
}
void FileDescriptorProto::set_has_source_code_info() {
- _has_bits_[0] |= 0x00000400u;
+ _has_bits_[0] |= 0x00000010u;
}
void FileDescriptorProto::clear_has_source_code_info() {
- _has_bits_[0] &= ~0x00000400u;
+ _has_bits_[0] &= ~0x00000010u;
}
void FileDescriptorProto::clear_source_code_info() {
if (source_code_info_ != NULL) source_code_info_->::google::protobuf::SourceCodeInfo::Clear();
@@ -2369,7 +2420,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();
@@ -2399,49 +2451,57 @@ void FileDescriptorProto::set_allocated_source_code_info(::google::protobuf::Sou
// optional string syntax = 12;
bool FileDescriptorProto::has_syntax() const {
- return (_has_bits_[0] & 0x00000800u) != 0;
+ return (_has_bits_[0] & 0x00000004u) != 0;
}
void FileDescriptorProto::set_has_syntax() {
- _has_bits_[0] |= 0x00000800u;
+ _has_bits_[0] |= 0x00000004u;
}
void FileDescriptorProto::clear_has_syntax() {
- _has_bits_[0] &= ~0x00000800u;
+ _has_bits_[0] &= ~0x00000004u;
}
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());
+ return syntax_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void FileDescriptorProto::set_syntax(::std::string&& value) {
+ set_has_syntax();
+ syntax_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileDescriptorProto.syntax)
+}
+#endif
+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<const char*>(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 {
@@ -2462,26 +2522,28 @@ const int DescriptorProto_ExtensionRange::kEndFieldNumber;
DescriptorProto_ExtensionRange::DescriptorProto_ExtensionRange()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.DescriptorProto.ExtensionRange)
}
-
-void DescriptorProto_ExtensionRange::InitAsDefaultInstance() {
-}
-
DescriptorProto_ExtensionRange::DescriptorProto_ExtensionRange(const DescriptorProto_ExtensionRange& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ ::memcpy(&start_, &from.start_,
+ reinterpret_cast<char*>(&end_) -
+ reinterpret_cast<char*>(&start_) + sizeof(end_));
// @@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<char*>(&end_) -
+ reinterpret_cast<char*>(&start_) + sizeof(end_));
}
DescriptorProto_ExtensionRange::~DescriptorProto_ExtensionRange() {
@@ -2490,8 +2552,6 @@ DescriptorProto_ExtensionRange::~DescriptorProto_ExtensionRange() {
}
void DescriptorProto_ExtensionRange::SharedDtor() {
- if (this != default_instance_) {
- }
}
void DescriptorProto_ExtensionRange::SetCachedSize(int size) const {
@@ -2500,17 +2560,15 @@ void DescriptorProto_ExtensionRange::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* DescriptorProto_ExtensionRange::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return DescriptorProto_ExtensionRange_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[2].descriptor;
}
const DescriptorProto_ExtensionRange& DescriptorProto_ExtensionRange::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-DescriptorProto_ExtensionRange* DescriptorProto_ExtensionRange::default_instance_ = NULL;
-
DescriptorProto_ExtensionRange* DescriptorProto_ExtensionRange::New(::google::protobuf::Arena* arena) const {
DescriptorProto_ExtensionRange* n = new DescriptorProto_ExtensionRange;
if (arena != NULL) {
@@ -2521,31 +2579,12 @@ DescriptorProto_ExtensionRange* DescriptorProto_ExtensionRange::New(::google::pr
void DescriptorProto_ExtensionRange::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.DescriptorProto.ExtensionRange)
-#if defined(__clang__)
-#define ZR_HELPER_(f) \
- _Pragma("clang diagnostic push") \
- _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
- __builtin_offsetof(DescriptorProto_ExtensionRange, f) \
- _Pragma("clang diagnostic pop")
-#else
-#define ZR_HELPER_(f) reinterpret_cast<char*>(\
- &reinterpret_cast<DescriptorProto_ExtensionRange*>(16)->f)
-#endif
-
-#define ZR_(first, last) do {\
- ::memset(&first, 0,\
- ZR_HELPER_(last) - ZR_HELPER_(first) + sizeof(last));\
-} while (0)
-
- ZR_(start_, end_);
-
-#undef ZR_HELPER_
-#undef ZR_
-
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
+ if (_has_bits_[0 / 32] & 3u) {
+ ::memset(&start_, 0, reinterpret_cast<char*>(&end_) -
+ reinterpret_cast<char*>(&start_) + sizeof(end_));
}
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool DescriptorProto_ExtensionRange::MergePartialFromCodedStream(
@@ -2554,36 +2593,35 @@ bool DescriptorProto_ExtensionRange::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.DescriptorProto.ExtensionRange)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional int32 start = 1;
case 1: {
- if (tag == 8) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(8u)) {
+ 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;
}
- if (input->ExpectTag(16)) goto parse_end;
break;
}
// optional int32 end = 2;
case 2: {
- if (tag == 16) {
- parse_end:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(16u)) {
+ 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;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -2631,6 +2669,7 @@ void DescriptorProto_ExtensionRange::SerializeWithCachedSizes(
::google::protobuf::uint8* DescriptorProto_ExtensionRange::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DescriptorProto.ExtensionRange)
// optional int32 start = 1;
if (has_start()) {
@@ -2650,10 +2689,15 @@ 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 (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
if (_has_bits_[0 / 32] & 3u) {
// optional int32 start = 1;
if (has_start()) {
@@ -2670,23 +2714,17 @@ int DescriptorProto_ExtensionRange::ByteSize() const {
}
}
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const DescriptorProto_ExtensionRange* source =
::google::protobuf::internal::DynamicCastToGenerated<const DescriptorProto_ExtensionRange>(
&from);
if (source == NULL) {
@@ -2700,10 +2738,9 @@ void DescriptorProto_ExtensionRange::MergeFrom(const ::google::protobuf::Message
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 (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ if (from._has_bits_[0 / 32] & 3u) {
if (from.has_start()) {
set_start(from.start());
}
@@ -2711,9 +2748,6 @@ void DescriptorProto_ExtensionRange::MergeFrom(const DescriptorProto_ExtensionRa
set_end(from.end());
}
}
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void DescriptorProto_ExtensionRange::CopyFrom(const ::google::protobuf::Message& from) {
@@ -2731,7 +2765,6 @@ void DescriptorProto_ExtensionRange::CopyFrom(const DescriptorProto_ExtensionRan
}
bool DescriptorProto_ExtensionRange::IsInitialized() const {
-
return true;
}
@@ -2748,15 +2781,64 @@ void DescriptorProto_ExtensionRange::InternalSwap(DescriptorProto_ExtensionRange
}
::google::protobuf::Metadata DescriptorProto_ExtensionRange::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = DescriptorProto_ExtensionRange_descriptor_;
- metadata.reflection = DescriptorProto_ExtensionRange_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[2];
+}
+
+#if PROTOBUF_INLINE_NOT_IN_HEADERS
+// DescriptorProto_ExtensionRange
+
+// optional int32 start = 1;
+bool DescriptorProto_ExtensionRange::has_start() const {
+ return (_has_bits_[0] & 0x00000001u) != 0;
+}
+void DescriptorProto_ExtensionRange::set_has_start() {
+ _has_bits_[0] |= 0x00000001u;
+}
+void DescriptorProto_ExtensionRange::clear_has_start() {
+ _has_bits_[0] &= ~0x00000001u;
+}
+void DescriptorProto_ExtensionRange::clear_start() {
+ start_ = 0;
+ clear_has_start();
+}
+::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) {
+ set_has_start();
+ start_ = value;
+ // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ExtensionRange.start)
+}
+
+// optional int32 end = 2;
+bool DescriptorProto_ExtensionRange::has_end() const {
+ return (_has_bits_[0] & 0x00000002u) != 0;
+}
+void DescriptorProto_ExtensionRange::set_has_end() {
+ _has_bits_[0] |= 0x00000002u;
+}
+void DescriptorProto_ExtensionRange::clear_has_end() {
+ _has_bits_[0] &= ~0x00000002u;
+}
+void DescriptorProto_ExtensionRange::clear_end() {
+ end_ = 0;
+ clear_has_end();
+}
+::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) {
+ set_has_end();
+ end_ = value;
+ // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ExtensionRange.end)
}
+#endif // PROTOBUF_INLINE_NOT_IN_HEADERS
-// -------------------------------------------------------------------
+// ===================================================================
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int DescriptorProto_ReservedRange::kStartFieldNumber;
@@ -2765,26 +2847,28 @@ const int DescriptorProto_ReservedRange::kEndFieldNumber;
DescriptorProto_ReservedRange::DescriptorProto_ReservedRange()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.DescriptorProto.ReservedRange)
}
-
-void DescriptorProto_ReservedRange::InitAsDefaultInstance() {
-}
-
DescriptorProto_ReservedRange::DescriptorProto_ReservedRange(const DescriptorProto_ReservedRange& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ ::memcpy(&start_, &from.start_,
+ reinterpret_cast<char*>(&end_) -
+ reinterpret_cast<char*>(&start_) + sizeof(end_));
// @@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<char*>(&end_) -
+ reinterpret_cast<char*>(&start_) + sizeof(end_));
}
DescriptorProto_ReservedRange::~DescriptorProto_ReservedRange() {
@@ -2793,8 +2877,6 @@ DescriptorProto_ReservedRange::~DescriptorProto_ReservedRange() {
}
void DescriptorProto_ReservedRange::SharedDtor() {
- if (this != default_instance_) {
- }
}
void DescriptorProto_ReservedRange::SetCachedSize(int size) const {
@@ -2803,17 +2885,15 @@ void DescriptorProto_ReservedRange::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* DescriptorProto_ReservedRange::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return DescriptorProto_ReservedRange_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[3].descriptor;
}
const DescriptorProto_ReservedRange& DescriptorProto_ReservedRange::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-DescriptorProto_ReservedRange* DescriptorProto_ReservedRange::default_instance_ = NULL;
-
DescriptorProto_ReservedRange* DescriptorProto_ReservedRange::New(::google::protobuf::Arena* arena) const {
DescriptorProto_ReservedRange* n = new DescriptorProto_ReservedRange;
if (arena != NULL) {
@@ -2824,31 +2904,12 @@ DescriptorProto_ReservedRange* DescriptorProto_ReservedRange::New(::google::prot
void DescriptorProto_ReservedRange::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.DescriptorProto.ReservedRange)
-#if defined(__clang__)
-#define ZR_HELPER_(f) \
- _Pragma("clang diagnostic push") \
- _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
- __builtin_offsetof(DescriptorProto_ReservedRange, f) \
- _Pragma("clang diagnostic pop")
-#else
-#define ZR_HELPER_(f) reinterpret_cast<char*>(\
- &reinterpret_cast<DescriptorProto_ReservedRange*>(16)->f)
-#endif
-
-#define ZR_(first, last) do {\
- ::memset(&first, 0,\
- ZR_HELPER_(last) - ZR_HELPER_(first) + sizeof(last));\
-} while (0)
-
- ZR_(start_, end_);
-
-#undef ZR_HELPER_
-#undef ZR_
-
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
+ if (_has_bits_[0 / 32] & 3u) {
+ ::memset(&start_, 0, reinterpret_cast<char*>(&end_) -
+ reinterpret_cast<char*>(&start_) + sizeof(end_));
}
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool DescriptorProto_ReservedRange::MergePartialFromCodedStream(
@@ -2857,36 +2918,35 @@ bool DescriptorProto_ReservedRange::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.DescriptorProto.ReservedRange)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional int32 start = 1;
case 1: {
- if (tag == 8) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(8u)) {
+ 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;
}
- if (input->ExpectTag(16)) goto parse_end;
break;
}
// optional int32 end = 2;
case 2: {
- if (tag == 16) {
- parse_end:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(16u)) {
+ 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;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -2934,6 +2994,7 @@ void DescriptorProto_ReservedRange::SerializeWithCachedSizes(
::google::protobuf::uint8* DescriptorProto_ReservedRange::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DescriptorProto.ReservedRange)
// optional int32 start = 1;
if (has_start()) {
@@ -2953,10 +3014,15 @@ 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 (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
if (_has_bits_[0 / 32] & 3u) {
// optional int32 start = 1;
if (has_start()) {
@@ -2973,23 +3039,17 @@ int DescriptorProto_ReservedRange::ByteSize() const {
}
}
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const DescriptorProto_ReservedRange* source =
::google::protobuf::internal::DynamicCastToGenerated<const DescriptorProto_ReservedRange>(
&from);
if (source == NULL) {
@@ -3003,10 +3063,9 @@ void DescriptorProto_ReservedRange::MergeFrom(const ::google::protobuf::Message&
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 (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ if (from._has_bits_[0 / 32] & 3u) {
if (from.has_start()) {
set_start(from.start());
}
@@ -3014,9 +3073,6 @@ void DescriptorProto_ReservedRange::MergeFrom(const DescriptorProto_ReservedRang
set_end(from.end());
}
}
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void DescriptorProto_ReservedRange::CopyFrom(const ::google::protobuf::Message& from) {
@@ -3034,7 +3090,6 @@ void DescriptorProto_ReservedRange::CopyFrom(const DescriptorProto_ReservedRange
}
bool DescriptorProto_ReservedRange::IsInitialized() const {
-
return true;
}
@@ -3051,15 +3106,64 @@ void DescriptorProto_ReservedRange::InternalSwap(DescriptorProto_ReservedRange*
}
::google::protobuf::Metadata DescriptorProto_ReservedRange::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = DescriptorProto_ReservedRange_descriptor_;
- metadata.reflection = DescriptorProto_ReservedRange_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[3];
+}
+
+#if PROTOBUF_INLINE_NOT_IN_HEADERS
+// DescriptorProto_ReservedRange
+
+// optional int32 start = 1;
+bool DescriptorProto_ReservedRange::has_start() const {
+ return (_has_bits_[0] & 0x00000001u) != 0;
+}
+void DescriptorProto_ReservedRange::set_has_start() {
+ _has_bits_[0] |= 0x00000001u;
+}
+void DescriptorProto_ReservedRange::clear_has_start() {
+ _has_bits_[0] &= ~0x00000001u;
+}
+void DescriptorProto_ReservedRange::clear_start() {
+ start_ = 0;
+ clear_has_start();
+}
+::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) {
+ set_has_start();
+ start_ = value;
+ // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ReservedRange.start)
+}
+
+// optional int32 end = 2;
+bool DescriptorProto_ReservedRange::has_end() const {
+ return (_has_bits_[0] & 0x00000002u) != 0;
+}
+void DescriptorProto_ReservedRange::set_has_end() {
+ _has_bits_[0] |= 0x00000002u;
+}
+void DescriptorProto_ReservedRange::clear_has_end() {
+ _has_bits_[0] &= ~0x00000002u;
+}
+void DescriptorProto_ReservedRange::clear_end() {
+ end_ = 0;
+ clear_has_end();
+}
+::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) {
+ set_has_end();
+ end_ = value;
+ // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ReservedRange.end)
}
+#endif // PROTOBUF_INLINE_NOT_IN_HEADERS
-// -------------------------------------------------------------------
+// ===================================================================
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int DescriptorProto::kNameFieldNumber;
@@ -3076,28 +3180,42 @@ const int DescriptorProto::kReservedNameFieldNumber;
DescriptorProto::DescriptorProto()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.DescriptorProto)
}
-
-void DescriptorProto::InitAsDefaultInstance() {
- options_ = const_cast< ::google::protobuf::MessageOptions*>(&::google::protobuf::MessageOptions::default_instance());
-}
-
DescriptorProto::DescriptorProto(const DescriptorProto& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ field_(from.field_),
+ extension_(from.extension_),
+ nested_type_(from.nested_type_),
+ enum_type_(from.enum_type_),
+ extension_range_(from.extension_range_),
+ oneof_decl_(from.oneof_decl_),
+ reserved_range_(from.reserved_range_),
+ reserved_name_(from.reserved_name_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_name()) {
+ name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
+ }
+ if (from.has_options()) {
+ options_ = new ::google::protobuf::MessageOptions(*from.options_);
+ } else {
+ options_ = NULL;
+ }
// @@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() {
@@ -3107,7 +3225,7 @@ DescriptorProto::~DescriptorProto() {
void DescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- if (this != default_instance_) {
+ if (this != internal_default_instance()) {
delete options_;
}
}
@@ -3118,17 +3236,15 @@ void DescriptorProto::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* DescriptorProto::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return DescriptorProto_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[4].descriptor;
}
const DescriptorProto& DescriptorProto::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-DescriptorProto* DescriptorProto::default_instance_ = NULL;
-
DescriptorProto* DescriptorProto::New(::google::protobuf::Arena* arena) const {
DescriptorProto* n = new DescriptorProto;
if (arena != NULL) {
@@ -3139,14 +3255,6 @@ DescriptorProto* DescriptorProto::New(::google::protobuf::Arena* arena) const {
void DescriptorProto::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.DescriptorProto)
- if (_has_bits_[0 / 32] & 129u) {
- if (has_name()) {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- }
- if (has_options()) {
- if (options_ != NULL) options_->::google::protobuf::MessageOptions::Clear();
- }
- }
field_.Clear();
extension_.Clear();
nested_type_.Clear();
@@ -3155,10 +3263,18 @@ void DescriptorProto::Clear() {
oneof_decl_.Clear();
reserved_range_.Clear();
reserved_name_.Clear();
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
+ if (_has_bits_[0 / 32] & 3u) {
+ if (has_name()) {
+ GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*name_.UnsafeRawStringPointer())->clear();
+ }
+ if (has_options()) {
+ GOOGLE_DCHECK(options_ != NULL);
+ options_->::google::protobuf::MessageOptions::Clear();
+ }
}
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool DescriptorProto::MergePartialFromCodedStream(
@@ -3167,13 +3283,14 @@ bool DescriptorProto::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.DescriptorProto)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional string name = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -3183,141 +3300,123 @@ bool DescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_field;
break;
}
// repeated .google.protobuf.FieldDescriptorProto field = 2;
case 2: {
- if (tag == 18) {
- parse_field:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_field:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_field()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_loop_field;
- if (input->ExpectTag(26)) goto parse_loop_nested_type;
input->UnsafeDecrementRecursionDepth();
break;
}
// repeated .google.protobuf.DescriptorProto nested_type = 3;
case 3: {
- if (tag == 26) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(26u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_nested_type:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_nested_type()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(26)) goto parse_loop_nested_type;
- if (input->ExpectTag(34)) goto parse_loop_enum_type;
input->UnsafeDecrementRecursionDepth();
break;
}
// repeated .google.protobuf.EnumDescriptorProto enum_type = 4;
case 4: {
- if (tag == 34) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(34u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_enum_type:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_enum_type()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(34)) goto parse_loop_enum_type;
- if (input->ExpectTag(42)) goto parse_loop_extension_range;
input->UnsafeDecrementRecursionDepth();
break;
}
// repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5;
case 5: {
- if (tag == 42) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(42u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_extension_range:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_extension_range()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(42)) goto parse_loop_extension_range;
- if (input->ExpectTag(50)) goto parse_loop_extension;
input->UnsafeDecrementRecursionDepth();
break;
}
// repeated .google.protobuf.FieldDescriptorProto extension = 6;
case 6: {
- if (tag == 50) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(50u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_extension:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_extension()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(50)) goto parse_loop_extension;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectTag(58)) goto parse_options;
break;
}
// optional .google.protobuf.MessageOptions options = 7;
case 7: {
- if (tag == 58) {
- parse_options:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(58u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, mutable_options()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(66)) goto parse_oneof_decl;
break;
}
// repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8;
case 8: {
- if (tag == 66) {
- parse_oneof_decl:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(66u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_oneof_decl:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_oneof_decl()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(66)) goto parse_loop_oneof_decl;
- if (input->ExpectTag(74)) goto parse_loop_reserved_range;
input->UnsafeDecrementRecursionDepth();
break;
}
// repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9;
case 9: {
- if (tag == 74) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(74u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_reserved_range:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_reserved_range()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(74)) goto parse_loop_reserved_range;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectTag(82)) goto parse_reserved_name;
break;
}
// repeated string reserved_name = 10;
case 10: {
- if (tag == 82) {
- parse_reserved_name:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(82u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->add_reserved_name()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -3328,8 +3427,6 @@ bool DescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(82)) goto parse_reserved_name;
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -3417,7 +3514,7 @@ void DescriptorProto::SerializeWithCachedSizes(
}
// repeated string reserved_name = 10;
- for (int i = 0; i < this->reserved_name_size(); i++) {
+ for (int i = 0, n = this->reserved_name_size(); i < n; i++) {
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
this->reserved_name(i).data(), this->reserved_name(i).length(),
::google::protobuf::internal::WireFormat::SERIALIZE,
@@ -3435,6 +3532,7 @@ void DescriptorProto::SerializeWithCachedSizes(
::google::protobuf::uint8* DescriptorProto::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DescriptorProto)
// optional string name = 1;
if (has_name()) {
@@ -3504,7 +3602,7 @@ void DescriptorProto::SerializeWithCachedSizes(
}
// repeated string reserved_name = 10;
- for (int i = 0; i < this->reserved_name_size(); i++) {
+ for (int i = 0, n = this->reserved_name_size(); i < n; i++) {
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
this->reserved_name(i).data(), this->reserved_name(i).length(),
::google::protobuf::internal::WireFormat::SERIALIZE,
@@ -3521,106 +3619,127 @@ 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;
-
- if (_has_bits_[0 / 32] & 129u) {
- // optional string name = 1;
- if (has_name()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::StringSize(
- this->name());
- }
-
- // optional .google.protobuf.MessageOptions options = 7;
- if (has_options()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual(
- *this->options_);
- }
+ size_t total_size = 0;
+ if (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
}
// 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();
- for (int i = 0; i < this->reserved_name_size(); i++) {
+ total_size += 1 *
+ ::google::protobuf::internal::FromIntSize(this->reserved_name_size());
+ for (int i = 0, n = this->reserved_name_size(); i < n; i++) {
total_size += ::google::protobuf::internal::WireFormatLite::StringSize(
this->reserved_name(i));
}
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
- unknown_fields());
+ if (_has_bits_[0 / 32] & 3u) {
+ // optional string name = 1;
+ if (has_name()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::StringSize(
+ this->name());
+ }
+
+ // optional .google.protobuf.MessageOptions options = 7;
+ if (has_options()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual(
+ *this->options_);
+ }
+
}
+ 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const DescriptorProto* source =
::google::protobuf::internal::DynamicCastToGenerated<const DescriptorProto>(
&from);
if (source == NULL) {
@@ -3634,9 +3753,8 @@ void DescriptorProto::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
field_.MergeFrom(from.field_);
extension_.MergeFrom(from.extension_);
nested_type_.MergeFrom(from.nested_type_);
@@ -3645,7 +3763,7 @@ void DescriptorProto::MergeFrom(const DescriptorProto& from) {
oneof_decl_.MergeFrom(from.oneof_decl_);
reserved_range_.MergeFrom(from.reserved_range_);
reserved_name_.MergeFrom(from.reserved_name_);
- if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+ if (from._has_bits_[0 / 32] & 3u) {
if (from.has_name()) {
set_has_name();
name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
@@ -3654,9 +3772,6 @@ void DescriptorProto::MergeFrom(const DescriptorProto& from) {
mutable_options()->::google::protobuf::MessageOptions::MergeFrom(from.options());
}
}
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void DescriptorProto::CopyFrom(const ::google::protobuf::Message& from) {
@@ -3674,7 +3789,6 @@ void DescriptorProto::CopyFrom(const DescriptorProto& from) {
}
bool DescriptorProto::IsInitialized() const {
-
if (!::google::protobuf::internal::AllAreInitialized(this->field())) return false;
if (!::google::protobuf::internal::AllAreInitialized(this->extension())) return false;
if (!::google::protobuf::internal::AllAreInitialized(this->nested_type())) return false;
@@ -3691,134 +3805,27 @@ void DescriptorProto::Swap(DescriptorProto* other) {
InternalSwap(other);
}
void DescriptorProto::InternalSwap(DescriptorProto* other) {
- name_.Swap(&other->name_);
field_.UnsafeArenaSwap(&other->field_);
extension_.UnsafeArenaSwap(&other->extension_);
nested_type_.UnsafeArenaSwap(&other->nested_type_);
enum_type_.UnsafeArenaSwap(&other->enum_type_);
extension_range_.UnsafeArenaSwap(&other->extension_range_);
oneof_decl_.UnsafeArenaSwap(&other->oneof_decl_);
- std::swap(options_, other->options_);
reserved_range_.UnsafeArenaSwap(&other->reserved_range_);
reserved_name_.UnsafeArenaSwap(&other->reserved_name_);
+ name_.Swap(&other->name_);
+ std::swap(options_, other->options_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata DescriptorProto::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = DescriptorProto_descriptor_;
- metadata.reflection = DescriptorProto_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[4];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
-// DescriptorProto_ExtensionRange
-
-// optional int32 start = 1;
-bool DescriptorProto_ExtensionRange::has_start() const {
- return (_has_bits_[0] & 0x00000001u) != 0;
-}
-void DescriptorProto_ExtensionRange::set_has_start() {
- _has_bits_[0] |= 0x00000001u;
-}
-void DescriptorProto_ExtensionRange::clear_has_start() {
- _has_bits_[0] &= ~0x00000001u;
-}
-void DescriptorProto_ExtensionRange::clear_start() {
- start_ = 0;
- clear_has_start();
-}
- ::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) {
- set_has_start();
- start_ = value;
- // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ExtensionRange.start)
-}
-
-// optional int32 end = 2;
-bool DescriptorProto_ExtensionRange::has_end() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
-}
-void DescriptorProto_ExtensionRange::set_has_end() {
- _has_bits_[0] |= 0x00000002u;
-}
-void DescriptorProto_ExtensionRange::clear_has_end() {
- _has_bits_[0] &= ~0x00000002u;
-}
-void DescriptorProto_ExtensionRange::clear_end() {
- end_ = 0;
- clear_has_end();
-}
- ::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) {
- set_has_end();
- end_ = value;
- // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ExtensionRange.end)
-}
-
-// -------------------------------------------------------------------
-
-// DescriptorProto_ReservedRange
-
-// optional int32 start = 1;
-bool DescriptorProto_ReservedRange::has_start() const {
- return (_has_bits_[0] & 0x00000001u) != 0;
-}
-void DescriptorProto_ReservedRange::set_has_start() {
- _has_bits_[0] |= 0x00000001u;
-}
-void DescriptorProto_ReservedRange::clear_has_start() {
- _has_bits_[0] &= ~0x00000001u;
-}
-void DescriptorProto_ReservedRange::clear_start() {
- start_ = 0;
- clear_has_start();
-}
- ::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) {
- set_has_start();
- start_ = value;
- // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ReservedRange.start)
-}
-
-// optional int32 end = 2;
-bool DescriptorProto_ReservedRange::has_end() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
-}
-void DescriptorProto_ReservedRange::set_has_end() {
- _has_bits_[0] |= 0x00000002u;
-}
-void DescriptorProto_ReservedRange::clear_has_end() {
- _has_bits_[0] &= ~0x00000002u;
-}
-void DescriptorProto_ReservedRange::clear_end() {
- end_ = 0;
- clear_has_end();
-}
- ::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) {
- set_has_end();
- end_ = value;
- // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ReservedRange.end)
-}
-
-// -------------------------------------------------------------------
-
// DescriptorProto
// optional string name = 1;
@@ -3835,37 +3842,45 @@ 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());
+ return name_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void DescriptorProto::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.DescriptorProto.name)
+}
+#endif
+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<const char*>(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 {
@@ -4057,13 +4072,13 @@ DescriptorProto::oneof_decl() const {
// optional .google.protobuf.MessageOptions options = 7;
bool DescriptorProto::has_options() const {
- return (_has_bits_[0] & 0x00000080u) != 0;
+ return (_has_bits_[0] & 0x00000002u) != 0;
}
void DescriptorProto::set_has_options() {
- _has_bits_[0] |= 0x00000080u;
+ _has_bits_[0] |= 0x00000002u;
}
void DescriptorProto::clear_has_options() {
- _has_bits_[0] &= ~0x00000080u;
+ _has_bits_[0] &= ~0x00000002u;
}
void DescriptorProto::clear_options() {
if (options_ != NULL) options_->::google::protobuf::MessageOptions::Clear();
@@ -4071,7 +4086,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();
@@ -4136,49 +4152,61 @@ 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) {
+#if LANG_CXX11
+void DescriptorProto::set_reserved_name(int index, ::std::string&& value) {
+ // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.reserved_name)
+ reserved_name_.Mutable(index)->assign(std::move(value));
+}
+#endif
+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<const char*>(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) {
+#if LANG_CXX11
+void DescriptorProto::add_reserved_name(::std::string&& value) {
+ reserved_name_.Add()->assign(std::move(value));
+ // @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.reserved_name)
+}
+#endif
+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<const char*>(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_;
@@ -4188,82 +4216,6 @@ DescriptorProto::mutable_reserved_name() {
// ===================================================================
-const ::google::protobuf::EnumDescriptor* FieldDescriptorProto_Type_descriptor() {
- protobuf_AssignDescriptorsOnce();
- return FieldDescriptorProto_Type_descriptor_;
-}
-bool FieldDescriptorProto_Type_IsValid(int value) {
- switch(value) {
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- case 9:
- case 10:
- case 11:
- case 12:
- case 13:
- case 14:
- case 15:
- case 16:
- case 17:
- case 18:
- return true;
- default:
- return false;
- }
-}
-
-#if !defined(_MSC_VER) || _MSC_VER >= 1900
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_DOUBLE;
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_FLOAT;
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_INT64;
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_UINT64;
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_INT32;
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_FIXED64;
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_FIXED32;
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_BOOL;
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_STRING;
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_GROUP;
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_MESSAGE;
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_BYTES;
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_UINT32;
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_ENUM;
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_SFIXED32;
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_SFIXED64;
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_SINT32;
-const FieldDescriptorProto_Type FieldDescriptorProto::TYPE_SINT64;
-const FieldDescriptorProto_Type FieldDescriptorProto::Type_MIN;
-const FieldDescriptorProto_Type FieldDescriptorProto::Type_MAX;
-const int FieldDescriptorProto::Type_ARRAYSIZE;
-#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
-const ::google::protobuf::EnumDescriptor* FieldDescriptorProto_Label_descriptor() {
- protobuf_AssignDescriptorsOnce();
- return FieldDescriptorProto_Label_descriptor_;
-}
-bool FieldDescriptorProto_Label_IsValid(int value) {
- switch(value) {
- case 1:
- case 2:
- case 3:
- return true;
- default:
- return false;
- }
-}
-
-#if !defined(_MSC_VER) || _MSC_VER >= 1900
-const FieldDescriptorProto_Label FieldDescriptorProto::LABEL_OPTIONAL;
-const FieldDescriptorProto_Label FieldDescriptorProto::LABEL_REQUIRED;
-const FieldDescriptorProto_Label FieldDescriptorProto::LABEL_REPEATED;
-const FieldDescriptorProto_Label FieldDescriptorProto::Label_MIN;
-const FieldDescriptorProto_Label FieldDescriptorProto::Label_MAX;
-const int FieldDescriptorProto::Label_ARRAYSIZE;
-#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int FieldDescriptorProto::kNameFieldNumber;
const int FieldDescriptorProto::kNumberFieldNumber;
@@ -4279,36 +4231,60 @@ const int FieldDescriptorProto::kOptionsFieldNumber;
FieldDescriptorProto::FieldDescriptorProto()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.FieldDescriptorProto)
}
-
-void FieldDescriptorProto::InitAsDefaultInstance() {
- options_ = const_cast< ::google::protobuf::FieldOptions*>(&::google::protobuf::FieldOptions::default_instance());
-}
-
FieldDescriptorProto::FieldDescriptorProto(const FieldDescriptorProto& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_name()) {
+ name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
+ }
+ type_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_type_name()) {
+ type_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.type_name_);
+ }
+ extendee_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_extendee()) {
+ extendee_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.extendee_);
+ }
+ default_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_default_value()) {
+ default_value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.default_value_);
+ }
+ json_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_json_name()) {
+ json_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.json_name_);
+ }
+ if (from.has_options()) {
+ options_ = new ::google::protobuf::FieldOptions(*from.options_);
+ } else {
+ options_ = NULL;
+ }
+ ::memcpy(&number_, &from.number_,
+ reinterpret_cast<char*>(&type_) -
+ reinterpret_cast<char*>(&number_) + sizeof(type_));
// @@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(&options_, 0, reinterpret_cast<char*>(&oneof_index_) -
+ reinterpret_cast<char*>(&options_) + sizeof(oneof_index_));
+ label_ = 1;
+ type_ = 1;
}
FieldDescriptorProto::~FieldDescriptorProto() {
@@ -4322,7 +4298,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_) {
+ if (this != internal_default_instance()) {
delete options_;
}
}
@@ -4333,17 +4309,15 @@ void FieldDescriptorProto::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* FieldDescriptorProto::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return FieldDescriptorProto_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[5].descriptor;
}
const FieldDescriptorProto& FieldDescriptorProto::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-FieldDescriptorProto* FieldDescriptorProto::default_instance_ = NULL;
-
FieldDescriptorProto* FieldDescriptorProto::New(::google::protobuf::Arena* arena) const {
FieldDescriptorProto* n = new FieldDescriptorProto;
if (arena != NULL) {
@@ -4354,36 +4328,42 @@ FieldDescriptorProto* FieldDescriptorProto::New(::google::protobuf::Arena* arena
void FieldDescriptorProto::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.FieldDescriptorProto)
- if (_has_bits_[0 / 32] & 255u) {
+ if (_has_bits_[0 / 32] & 63u) {
if (has_name()) {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*name_.UnsafeRawStringPointer())->clear();
}
- number_ = 0;
- label_ = 1;
- type_ = 1;
if (has_type_name()) {
- type_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!type_name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*type_name_.UnsafeRawStringPointer())->clear();
}
if (has_extendee()) {
- extendee_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!extendee_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*extendee_.UnsafeRawStringPointer())->clear();
}
if (has_default_value()) {
- default_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!default_value_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*default_value_.UnsafeRawStringPointer())->clear();
}
- oneof_index_ = 0;
- }
- if (_has_bits_[8 / 32] & 768u) {
if (has_json_name()) {
- json_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!json_name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*json_name_.UnsafeRawStringPointer())->clear();
}
if (has_options()) {
- if (options_ != NULL) options_->::google::protobuf::FieldOptions::Clear();
+ GOOGLE_DCHECK(options_ != NULL);
+ options_->::google::protobuf::FieldOptions::Clear();
}
}
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
+ if (_has_bits_[0 / 32] & 192u) {
+ ::memset(&number_, 0, reinterpret_cast<char*>(&oneof_index_) -
+ reinterpret_cast<char*>(&number_) + sizeof(oneof_index_));
+ }
+ if (_has_bits_[8 / 32] & 768u) {
+ label_ = 1;
+ type_ = 1;
}
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool FieldDescriptorProto::MergePartialFromCodedStream(
@@ -4392,13 +4372,14 @@ bool FieldDescriptorProto::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.FieldDescriptorProto)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional string name = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -4408,14 +4389,13 @@ bool FieldDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_extendee;
break;
}
// optional string extendee = 2;
case 2: {
- if (tag == 18) {
- parse_extendee:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_extendee()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -4425,29 +4405,27 @@ bool FieldDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(24)) goto parse_number;
break;
}
// optional int32 number = 3;
case 3: {
- if (tag == 24) {
- parse_number:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(24u)) {
+ 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;
}
- if (input->ExpectTag(32)) goto parse_label;
break;
}
// optional .google.protobuf.FieldDescriptorProto.Label label = 4;
case 4: {
- if (tag == 32) {
- parse_label:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(32u)) {
int value;
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(
@@ -4460,14 +4438,13 @@ bool FieldDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(40)) goto parse_type;
break;
}
// optional .google.protobuf.FieldDescriptorProto.Type type = 5;
case 5: {
- if (tag == 40) {
- parse_type:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(40u)) {
int value;
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(
@@ -4480,14 +4457,13 @@ bool FieldDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(50)) goto parse_type_name;
break;
}
// optional string type_name = 6;
case 6: {
- if (tag == 50) {
- parse_type_name:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(50u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_type_name()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -4497,14 +4473,13 @@ bool FieldDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(58)) goto parse_default_value;
break;
}
// optional string default_value = 7;
case 7: {
- if (tag == 58) {
- parse_default_value:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(58u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_default_value()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -4514,42 +4489,39 @@ bool FieldDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(66)) goto parse_options;
break;
}
// optional .google.protobuf.FieldOptions options = 8;
case 8: {
- if (tag == 66) {
- parse_options:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(66u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, mutable_options()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(72)) goto parse_oneof_index;
break;
}
// optional int32 oneof_index = 9;
case 9: {
- if (tag == 72) {
- parse_oneof_index:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(72u)) {
+ 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;
}
- if (input->ExpectTag(82)) goto parse_json_name;
break;
}
// optional string json_name = 10;
case 10: {
- if (tag == 82) {
- parse_json_name:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(82u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_json_name()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -4559,7 +4531,6 @@ bool FieldDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -4675,6 +4646,7 @@ void FieldDescriptorProto::SerializeWithCachedSizes(
::google::protobuf::uint8* FieldDescriptorProto::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldDescriptorProto)
// optional string name = 1;
if (has_name()) {
@@ -4768,10 +4740,15 @@ 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 (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
if (_has_bits_[0 / 32] & 255u) {
// optional string name = 1;
if (has_name()) {
@@ -4780,25 +4757,6 @@ int FieldDescriptorProto::ByteSize() const {
this->name());
}
- // optional int32 number = 3;
- if (has_number()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::Int32Size(
- this->number());
- }
-
- // optional .google.protobuf.FieldDescriptorProto.Label label = 4;
- if (has_label()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::EnumSize(this->label());
- }
-
- // optional .google.protobuf.FieldDescriptorProto.Type type = 5;
- if (has_type()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::EnumSize(this->type());
- }
-
// optional string type_name = 6;
if (has_type_name()) {
total_size += 1 +
@@ -4820,15 +4778,6 @@ int FieldDescriptorProto::ByteSize() const {
this->default_value());
}
- // optional int32 oneof_index = 9;
- if (has_oneof_index()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::Int32Size(
- this->oneof_index());
- }
-
- }
- if (_has_bits_[8 / 32] & 768u) {
// optional string json_name = 10;
if (has_json_name()) {
total_size += 1 +
@@ -4843,24 +4792,46 @@ int FieldDescriptorProto::ByteSize() const {
*this->options_);
}
+ // optional int32 number = 3;
+ if (has_number()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::Int32Size(
+ this->number());
+ }
+
+ // optional int32 oneof_index = 9;
+ if (has_oneof_index()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::Int32Size(
+ this->oneof_index());
+ }
+
}
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
- unknown_fields());
+ if (_has_bits_[8 / 32] & 768u) {
+ // optional .google.protobuf.FieldDescriptorProto.Label label = 4;
+ if (has_label()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::EnumSize(this->label());
+ }
+
+ // optional .google.protobuf.FieldDescriptorProto.Type type = 5;
+ if (has_type()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::EnumSize(this->type());
+ }
+
}
+ 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const FieldDescriptorProto* source =
::google::protobuf::internal::DynamicCastToGenerated<const FieldDescriptorProto>(
&from);
if (source == NULL) {
@@ -4874,23 +4845,13 @@ void FieldDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) {
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 (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ if (from._has_bits_[0 / 32] & 255u) {
if (from.has_name()) {
set_has_name();
name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
}
- if (from.has_number()) {
- set_number(from.number());
- }
- if (from.has_label()) {
- set_label(from.label());
- }
- if (from.has_type()) {
- set_type(from.type());
- }
if (from.has_type_name()) {
set_has_type_name();
type_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.type_name_);
@@ -4903,11 +4864,6 @@ void FieldDescriptorProto::MergeFrom(const FieldDescriptorProto& from) {
set_has_default_value();
default_value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.default_value_);
}
- if (from.has_oneof_index()) {
- set_oneof_index(from.oneof_index());
- }
- }
- if (from._has_bits_[8 / 32] & (0xffu << (8 % 32))) {
if (from.has_json_name()) {
set_has_json_name();
json_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.json_name_);
@@ -4915,9 +4871,20 @@ void FieldDescriptorProto::MergeFrom(const FieldDescriptorProto& from) {
if (from.has_options()) {
mutable_options()->::google::protobuf::FieldOptions::MergeFrom(from.options());
}
+ if (from.has_number()) {
+ set_number(from.number());
+ }
+ if (from.has_oneof_index()) {
+ set_oneof_index(from.oneof_index());
+ }
}
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
+ if (from._has_bits_[8 / 32] & 768u) {
+ if (from.has_label()) {
+ set_label(from.label());
+ }
+ if (from.has_type()) {
+ set_type(from.type());
+ }
}
}
@@ -4936,7 +4903,6 @@ void FieldDescriptorProto::CopyFrom(const FieldDescriptorProto& from) {
}
bool FieldDescriptorProto::IsInitialized() const {
-
if (has_options()) {
if (!this->options_->IsInitialized()) return false;
}
@@ -4949,26 +4915,23 @@ void FieldDescriptorProto::Swap(FieldDescriptorProto* other) {
}
void FieldDescriptorProto::InternalSwap(FieldDescriptorProto* other) {
name_.Swap(&other->name_);
- std::swap(number_, other->number_);
- std::swap(label_, other->label_);
- std::swap(type_, other->type_);
type_name_.Swap(&other->type_name_);
extendee_.Swap(&other->extendee_);
default_value_.Swap(&other->default_value_);
- std::swap(oneof_index_, other->oneof_index_);
json_name_.Swap(&other->json_name_);
std::swap(options_, other->options_);
+ std::swap(number_, other->number_);
+ std::swap(oneof_index_, other->oneof_index_);
+ std::swap(label_, other->label_);
+ std::swap(type_, other->type_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata FieldDescriptorProto::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = FieldDescriptorProto_descriptor_;
- metadata.reflection = FieldDescriptorProto_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[5];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -4988,37 +4951,45 @@ 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());
+ return name_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void FieldDescriptorProto::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FieldDescriptorProto.name)
+}
+#endif
+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<const char*>(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 {
@@ -5030,23 +5001,23 @@ void FieldDescriptorProto::clear_name() {
// optional int32 number = 3;
bool FieldDescriptorProto::has_number() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
+ return (_has_bits_[0] & 0x00000040u) != 0;
}
void FieldDescriptorProto::set_has_number() {
- _has_bits_[0] |= 0x00000002u;
+ _has_bits_[0] |= 0x00000040u;
}
void FieldDescriptorProto::clear_has_number() {
- _has_bits_[0] &= ~0x00000002u;
+ _has_bits_[0] &= ~0x00000040u;
}
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)
@@ -5054,23 +5025,23 @@ void FieldDescriptorProto::clear_number() {
// optional .google.protobuf.FieldDescriptorProto.Label label = 4;
bool FieldDescriptorProto::has_label() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
+ return (_has_bits_[0] & 0x00000100u) != 0;
}
void FieldDescriptorProto::set_has_label() {
- _has_bits_[0] |= 0x00000004u;
+ _has_bits_[0] |= 0x00000100u;
}
void FieldDescriptorProto::clear_has_label() {
- _has_bits_[0] &= ~0x00000004u;
+ _has_bits_[0] &= ~0x00000100u;
}
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;
@@ -5079,23 +5050,23 @@ void FieldDescriptorProto::clear_label() {
// optional .google.protobuf.FieldDescriptorProto.Type type = 5;
bool FieldDescriptorProto::has_type() const {
- return (_has_bits_[0] & 0x00000008u) != 0;
+ return (_has_bits_[0] & 0x00000200u) != 0;
}
void FieldDescriptorProto::set_has_type() {
- _has_bits_[0] |= 0x00000008u;
+ _has_bits_[0] |= 0x00000200u;
}
void FieldDescriptorProto::clear_has_type() {
- _has_bits_[0] &= ~0x00000008u;
+ _has_bits_[0] &= ~0x00000200u;
}
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;
@@ -5104,49 +5075,57 @@ void FieldDescriptorProto::clear_type() {
// optional string type_name = 6;
bool FieldDescriptorProto::has_type_name() const {
- return (_has_bits_[0] & 0x00000010u) != 0;
+ return (_has_bits_[0] & 0x00000002u) != 0;
}
void FieldDescriptorProto::set_has_type_name() {
- _has_bits_[0] |= 0x00000010u;
+ _has_bits_[0] |= 0x00000002u;
}
void FieldDescriptorProto::clear_has_type_name() {
- _has_bits_[0] &= ~0x00000010u;
+ _has_bits_[0] &= ~0x00000002u;
}
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());
+ return type_name_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void FieldDescriptorProto::set_type_name(::std::string&& value) {
+ set_has_type_name();
+ type_name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FieldDescriptorProto.type_name)
+}
+#endif
+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<const char*>(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 {
@@ -5158,49 +5137,57 @@ void FieldDescriptorProto::clear_type_name() {
// optional string extendee = 2;
bool FieldDescriptorProto::has_extendee() const {
- return (_has_bits_[0] & 0x00000020u) != 0;
+ return (_has_bits_[0] & 0x00000004u) != 0;
}
void FieldDescriptorProto::set_has_extendee() {
- _has_bits_[0] |= 0x00000020u;
+ _has_bits_[0] |= 0x00000004u;
}
void FieldDescriptorProto::clear_has_extendee() {
- _has_bits_[0] &= ~0x00000020u;
+ _has_bits_[0] &= ~0x00000004u;
}
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());
+ return extendee_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void FieldDescriptorProto::set_extendee(::std::string&& value) {
+ set_has_extendee();
+ extendee_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FieldDescriptorProto.extendee)
+}
+#endif
+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<const char*>(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 {
@@ -5212,49 +5199,57 @@ void FieldDescriptorProto::clear_extendee() {
// optional string default_value = 7;
bool FieldDescriptorProto::has_default_value() const {
- return (_has_bits_[0] & 0x00000040u) != 0;
+ return (_has_bits_[0] & 0x00000008u) != 0;
}
void FieldDescriptorProto::set_has_default_value() {
- _has_bits_[0] |= 0x00000040u;
+ _has_bits_[0] |= 0x00000008u;
}
void FieldDescriptorProto::clear_has_default_value() {
- _has_bits_[0] &= ~0x00000040u;
+ _has_bits_[0] &= ~0x00000008u;
}
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());
+ return default_value_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void FieldDescriptorProto::set_default_value(::std::string&& value) {
+ set_has_default_value();
+ default_value_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FieldDescriptorProto.default_value)
+}
+#endif
+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<const char*>(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 {
@@ -5278,11 +5273,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)
@@ -5290,49 +5285,57 @@ void FieldDescriptorProto::clear_oneof_index() {
// optional string json_name = 10;
bool FieldDescriptorProto::has_json_name() const {
- return (_has_bits_[0] & 0x00000100u) != 0;
+ return (_has_bits_[0] & 0x00000010u) != 0;
}
void FieldDescriptorProto::set_has_json_name() {
- _has_bits_[0] |= 0x00000100u;
+ _has_bits_[0] |= 0x00000010u;
}
void FieldDescriptorProto::clear_has_json_name() {
- _has_bits_[0] &= ~0x00000100u;
+ _has_bits_[0] &= ~0x00000010u;
}
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());
+ return json_name_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void FieldDescriptorProto::set_json_name(::std::string&& value) {
+ set_has_json_name();
+ json_name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FieldDescriptorProto.json_name)
+}
+#endif
+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<const char*>(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 {
@@ -5344,13 +5347,13 @@ void FieldDescriptorProto::clear_json_name() {
// optional .google.protobuf.FieldOptions options = 8;
bool FieldDescriptorProto::has_options() const {
- return (_has_bits_[0] & 0x00000200u) != 0;
+ return (_has_bits_[0] & 0x00000020u) != 0;
}
void FieldDescriptorProto::set_has_options() {
- _has_bits_[0] |= 0x00000200u;
+ _has_bits_[0] |= 0x00000020u;
}
void FieldDescriptorProto::clear_has_options() {
- _has_bits_[0] &= ~0x00000200u;
+ _has_bits_[0] &= ~0x00000020u;
}
void FieldDescriptorProto::clear_options() {
if (options_ != NULL) options_->::google::protobuf::FieldOptions::Clear();
@@ -5358,7 +5361,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();
@@ -5397,28 +5401,34 @@ const int OneofDescriptorProto::kOptionsFieldNumber;
OneofDescriptorProto::OneofDescriptorProto()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.OneofDescriptorProto)
}
-
-void OneofDescriptorProto::InitAsDefaultInstance() {
- options_ = const_cast< ::google::protobuf::OneofOptions*>(&::google::protobuf::OneofOptions::default_instance());
-}
-
OneofDescriptorProto::OneofDescriptorProto(const OneofDescriptorProto& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_name()) {
+ name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
+ }
+ if (from.has_options()) {
+ options_ = new ::google::protobuf::OneofOptions(*from.options_);
+ } else {
+ options_ = NULL;
+ }
// @@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() {
@@ -5428,7 +5438,7 @@ OneofDescriptorProto::~OneofDescriptorProto() {
void OneofDescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- if (this != default_instance_) {
+ if (this != internal_default_instance()) {
delete options_;
}
}
@@ -5439,17 +5449,15 @@ void OneofDescriptorProto::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* OneofDescriptorProto::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return OneofDescriptorProto_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[6].descriptor;
}
const OneofDescriptorProto& OneofDescriptorProto::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-OneofDescriptorProto* OneofDescriptorProto::default_instance_ = NULL;
-
OneofDescriptorProto* OneofDescriptorProto::New(::google::protobuf::Arena* arena) const {
OneofDescriptorProto* n = new OneofDescriptorProto;
if (arena != NULL) {
@@ -5462,16 +5470,16 @@ void OneofDescriptorProto::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.OneofDescriptorProto)
if (_has_bits_[0 / 32] & 3u) {
if (has_name()) {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*name_.UnsafeRawStringPointer())->clear();
}
if (has_options()) {
- if (options_ != NULL) options_->::google::protobuf::OneofOptions::Clear();
+ GOOGLE_DCHECK(options_ != NULL);
+ options_->::google::protobuf::OneofOptions::Clear();
}
}
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
- }
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool OneofDescriptorProto::MergePartialFromCodedStream(
@@ -5480,13 +5488,14 @@ bool OneofDescriptorProto::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.OneofDescriptorProto)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional string name = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -5496,20 +5505,18 @@ bool OneofDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_options;
break;
}
// optional .google.protobuf.OneofOptions options = 2;
case 2: {
- if (tag == 18) {
- parse_options:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, mutable_options()));
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -5563,6 +5570,7 @@ void OneofDescriptorProto::SerializeWithCachedSizes(
::google::protobuf::uint8* OneofDescriptorProto::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.OneofDescriptorProto)
// optional string name = 1;
if (has_name()) {
@@ -5590,10 +5598,15 @@ 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 (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
if (_has_bits_[0 / 32] & 3u) {
// optional string name = 1;
if (has_name()) {
@@ -5610,23 +5623,17 @@ int OneofDescriptorProto::ByteSize() const {
}
}
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const OneofDescriptorProto* source =
::google::protobuf::internal::DynamicCastToGenerated<const OneofDescriptorProto>(
&from);
if (source == NULL) {
@@ -5640,10 +5647,9 @@ void OneofDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) {
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 (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ if (from._has_bits_[0 / 32] & 3u) {
if (from.has_name()) {
set_has_name();
name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
@@ -5652,9 +5658,6 @@ void OneofDescriptorProto::MergeFrom(const OneofDescriptorProto& from) {
mutable_options()->::google::protobuf::OneofOptions::MergeFrom(from.options());
}
}
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void OneofDescriptorProto::CopyFrom(const ::google::protobuf::Message& from) {
@@ -5672,7 +5675,6 @@ void OneofDescriptorProto::CopyFrom(const OneofDescriptorProto& from) {
}
bool OneofDescriptorProto::IsInitialized() const {
-
if (has_options()) {
if (!this->options_->IsInitialized()) return false;
}
@@ -5692,11 +5694,8 @@ void OneofDescriptorProto::InternalSwap(OneofDescriptorProto* other) {
}
::google::protobuf::Metadata OneofDescriptorProto::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = OneofDescriptorProto_descriptor_;
- metadata.reflection = OneofDescriptorProto_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[6];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -5716,37 +5715,45 @@ 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());
+ return name_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void OneofDescriptorProto::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.OneofDescriptorProto.name)
+}
+#endif
+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<const char*>(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 {
@@ -5772,7 +5779,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();
@@ -5812,28 +5820,35 @@ const int EnumDescriptorProto::kOptionsFieldNumber;
EnumDescriptorProto::EnumDescriptorProto()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.EnumDescriptorProto)
}
-
-void EnumDescriptorProto::InitAsDefaultInstance() {
- options_ = const_cast< ::google::protobuf::EnumOptions*>(&::google::protobuf::EnumOptions::default_instance());
-}
-
EnumDescriptorProto::EnumDescriptorProto(const EnumDescriptorProto& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ value_(from.value_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_name()) {
+ name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
+ }
+ if (from.has_options()) {
+ options_ = new ::google::protobuf::EnumOptions(*from.options_);
+ } else {
+ options_ = NULL;
+ }
// @@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() {
@@ -5843,7 +5858,7 @@ EnumDescriptorProto::~EnumDescriptorProto() {
void EnumDescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- if (this != default_instance_) {
+ if (this != internal_default_instance()) {
delete options_;
}
}
@@ -5854,17 +5869,15 @@ void EnumDescriptorProto::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* EnumDescriptorProto::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return EnumDescriptorProto_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[7].descriptor;
}
const EnumDescriptorProto& EnumDescriptorProto::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-EnumDescriptorProto* EnumDescriptorProto::default_instance_ = NULL;
-
EnumDescriptorProto* EnumDescriptorProto::New(::google::protobuf::Arena* arena) const {
EnumDescriptorProto* n = new EnumDescriptorProto;
if (arena != NULL) {
@@ -5875,19 +5888,19 @@ EnumDescriptorProto* EnumDescriptorProto::New(::google::protobuf::Arena* arena)
void EnumDescriptorProto::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.EnumDescriptorProto)
- if (_has_bits_[0 / 32] & 5u) {
+ value_.Clear();
+ if (_has_bits_[0 / 32] & 3u) {
if (has_name()) {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*name_.UnsafeRawStringPointer())->clear();
}
if (has_options()) {
- if (options_ != NULL) options_->::google::protobuf::EnumOptions::Clear();
+ GOOGLE_DCHECK(options_ != NULL);
+ options_->::google::protobuf::EnumOptions::Clear();
}
}
- value_.Clear();
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
- }
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool EnumDescriptorProto::MergePartialFromCodedStream(
@@ -5896,13 +5909,14 @@ bool EnumDescriptorProto::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.EnumDescriptorProto)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional string name = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -5912,37 +5926,32 @@ bool EnumDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_value;
break;
}
// repeated .google.protobuf.EnumValueDescriptorProto value = 2;
case 2: {
- if (tag == 18) {
- parse_value:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_value:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_value()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_loop_value;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectTag(26)) goto parse_options;
break;
}
// optional .google.protobuf.EnumOptions options = 3;
case 3: {
- if (tag == 26) {
- parse_options:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(26u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, mutable_options()));
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -6002,6 +6011,7 @@ void EnumDescriptorProto::SerializeWithCachedSizes(
::google::protobuf::uint8* EnumDescriptorProto::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumDescriptorProto)
// optional string name = 1;
if (has_name()) {
@@ -6036,11 +6046,27 @@ 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 (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
+ // repeated .google.protobuf.EnumValueDescriptorProto value = 2;
+ {
+ 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 (_has_bits_[0 / 32] & 5u) {
+ if (_has_bits_[0 / 32] & 3u) {
// optional string name = 1;
if (has_name()) {
total_size += 1 +
@@ -6056,31 +6082,17 @@ 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));
- }
-
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const EnumDescriptorProto* source =
::google::protobuf::internal::DynamicCastToGenerated<const EnumDescriptorProto>(
&from);
if (source == NULL) {
@@ -6094,11 +6106,10 @@ void EnumDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
value_.MergeFrom(from.value_);
- if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+ if (from._has_bits_[0 / 32] & 3u) {
if (from.has_name()) {
set_has_name();
name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
@@ -6107,9 +6118,6 @@ void EnumDescriptorProto::MergeFrom(const EnumDescriptorProto& from) {
mutable_options()->::google::protobuf::EnumOptions::MergeFrom(from.options());
}
}
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void EnumDescriptorProto::CopyFrom(const ::google::protobuf::Message& from) {
@@ -6127,7 +6135,6 @@ void EnumDescriptorProto::CopyFrom(const EnumDescriptorProto& from) {
}
bool EnumDescriptorProto::IsInitialized() const {
-
if (!::google::protobuf::internal::AllAreInitialized(this->value())) return false;
if (has_options()) {
if (!this->options_->IsInitialized()) return false;
@@ -6140,8 +6147,8 @@ void EnumDescriptorProto::Swap(EnumDescriptorProto* other) {
InternalSwap(other);
}
void EnumDescriptorProto::InternalSwap(EnumDescriptorProto* other) {
- name_.Swap(&other->name_);
value_.UnsafeArenaSwap(&other->value_);
+ name_.Swap(&other->name_);
std::swap(options_, other->options_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
@@ -6149,11 +6156,8 @@ void EnumDescriptorProto::InternalSwap(EnumDescriptorProto* other) {
}
::google::protobuf::Metadata EnumDescriptorProto::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = EnumDescriptorProto_descriptor_;
- metadata.reflection = EnumDescriptorProto_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[7];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -6173,37 +6177,45 @@ 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());
+ return name_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void EnumDescriptorProto::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.EnumDescriptorProto.name)
+}
+#endif
+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<const char*>(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 {
@@ -6245,13 +6257,13 @@ EnumDescriptorProto::value() const {
// optional .google.protobuf.EnumOptions options = 3;
bool EnumDescriptorProto::has_options() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
+ return (_has_bits_[0] & 0x00000002u) != 0;
}
void EnumDescriptorProto::set_has_options() {
- _has_bits_[0] |= 0x00000004u;
+ _has_bits_[0] |= 0x00000002u;
}
void EnumDescriptorProto::clear_has_options() {
- _has_bits_[0] &= ~0x00000004u;
+ _has_bits_[0] &= ~0x00000002u;
}
void EnumDescriptorProto::clear_options() {
if (options_ != NULL) options_->::google::protobuf::EnumOptions::Clear();
@@ -6259,7 +6271,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();
@@ -6299,29 +6312,36 @@ const int EnumValueDescriptorProto::kOptionsFieldNumber;
EnumValueDescriptorProto::EnumValueDescriptorProto()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.EnumValueDescriptorProto)
}
-
-void EnumValueDescriptorProto::InitAsDefaultInstance() {
- options_ = const_cast< ::google::protobuf::EnumValueOptions*>(&::google::protobuf::EnumValueOptions::default_instance());
-}
-
EnumValueDescriptorProto::EnumValueDescriptorProto(const EnumValueDescriptorProto& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_name()) {
+ name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
+ }
+ if (from.has_options()) {
+ options_ = new ::google::protobuf::EnumValueOptions(*from.options_);
+ } else {
+ options_ = NULL;
+ }
+ number_ = from.number_;
// @@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_));
+ ::memset(&options_, 0, reinterpret_cast<char*>(&number_) -
+ reinterpret_cast<char*>(&options_) + sizeof(number_));
}
EnumValueDescriptorProto::~EnumValueDescriptorProto() {
@@ -6331,7 +6351,7 @@ EnumValueDescriptorProto::~EnumValueDescriptorProto() {
void EnumValueDescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- if (this != default_instance_) {
+ if (this != internal_default_instance()) {
delete options_;
}
}
@@ -6342,17 +6362,15 @@ void EnumValueDescriptorProto::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* EnumValueDescriptorProto::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return EnumValueDescriptorProto_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[8].descriptor;
}
const EnumValueDescriptorProto& EnumValueDescriptorProto::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-EnumValueDescriptorProto* EnumValueDescriptorProto::default_instance_ = NULL;
-
EnumValueDescriptorProto* EnumValueDescriptorProto::New(::google::protobuf::Arena* arena) const {
EnumValueDescriptorProto* n = new EnumValueDescriptorProto;
if (arena != NULL) {
@@ -6363,19 +6381,19 @@ EnumValueDescriptorProto* EnumValueDescriptorProto::New(::google::protobuf::Aren
void EnumValueDescriptorProto::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.EnumValueDescriptorProto)
- if (_has_bits_[0 / 32] & 7u) {
+ if (_has_bits_[0 / 32] & 3u) {
if (has_name()) {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*name_.UnsafeRawStringPointer())->clear();
}
- number_ = 0;
if (has_options()) {
- if (options_ != NULL) options_->::google::protobuf::EnumValueOptions::Clear();
+ GOOGLE_DCHECK(options_ != NULL);
+ options_->::google::protobuf::EnumValueOptions::Clear();
}
}
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
- }
+ number_ = 0;
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool EnumValueDescriptorProto::MergePartialFromCodedStream(
@@ -6384,13 +6402,14 @@ bool EnumValueDescriptorProto::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.EnumValueDescriptorProto)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional string name = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -6400,35 +6419,32 @@ bool EnumValueDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(16)) goto parse_number;
break;
}
// optional int32 number = 2;
case 2: {
- if (tag == 16) {
- parse_number:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(16u)) {
+ 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;
}
- if (input->ExpectTag(26)) goto parse_options;
break;
}
// optional .google.protobuf.EnumValueOptions options = 3;
case 3: {
- if (tag == 26) {
- parse_options:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(26u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, mutable_options()));
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -6487,6 +6503,7 @@ void EnumValueDescriptorProto::SerializeWithCachedSizes(
::google::protobuf::uint8* EnumValueDescriptorProto::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumValueDescriptorProto)
// optional string name = 1;
if (has_name()) {
@@ -6519,10 +6536,15 @@ 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 (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
if (_has_bits_[0 / 32] & 7u) {
// optional string name = 1;
if (has_name()) {
@@ -6531,13 +6553,6 @@ int EnumValueDescriptorProto::ByteSize() const {
this->name());
}
- // optional int32 number = 2;
- if (has_number()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::Int32Size(
- this->number());
- }
-
// optional .google.protobuf.EnumValueOptions options = 3;
if (has_options()) {
total_size += 1 +
@@ -6545,24 +6560,25 @@ int EnumValueDescriptorProto::ByteSize() const {
*this->options_);
}
+ // optional int32 number = 2;
+ if (has_number()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::Int32Size(
+ this->number());
+ }
+
}
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const EnumValueDescriptorProto* source =
::google::protobuf::internal::DynamicCastToGenerated<const EnumValueDescriptorProto>(
&from);
if (source == NULL) {
@@ -6576,23 +6592,19 @@ void EnumValueDescriptorProto::MergeFrom(const ::google::protobuf::Message& from
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 (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ if (from._has_bits_[0 / 32] & 7u) {
if (from.has_name()) {
set_has_name();
name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
}
- if (from.has_number()) {
- set_number(from.number());
- }
if (from.has_options()) {
mutable_options()->::google::protobuf::EnumValueOptions::MergeFrom(from.options());
}
- }
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
+ if (from.has_number()) {
+ set_number(from.number());
+ }
}
}
@@ -6611,7 +6623,6 @@ void EnumValueDescriptorProto::CopyFrom(const EnumValueDescriptorProto& from) {
}
bool EnumValueDescriptorProto::IsInitialized() const {
-
if (has_options()) {
if (!this->options_->IsInitialized()) return false;
}
@@ -6624,19 +6635,16 @@ void EnumValueDescriptorProto::Swap(EnumValueDescriptorProto* other) {
}
void EnumValueDescriptorProto::InternalSwap(EnumValueDescriptorProto* other) {
name_.Swap(&other->name_);
- std::swap(number_, other->number_);
std::swap(options_, other->options_);
+ std::swap(number_, other->number_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata EnumValueDescriptorProto::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = EnumValueDescriptorProto_descriptor_;
- metadata.reflection = EnumValueDescriptorProto_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[8];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -6656,37 +6664,45 @@ 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());
+ return name_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void EnumValueDescriptorProto::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.EnumValueDescriptorProto.name)
+}
+#endif
+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<const char*>(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 {
@@ -6698,23 +6714,23 @@ void EnumValueDescriptorProto::clear_name() {
// optional int32 number = 2;
bool EnumValueDescriptorProto::has_number() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
+ return (_has_bits_[0] & 0x00000004u) != 0;
}
void EnumValueDescriptorProto::set_has_number() {
- _has_bits_[0] |= 0x00000002u;
+ _has_bits_[0] |= 0x00000004u;
}
void EnumValueDescriptorProto::clear_has_number() {
- _has_bits_[0] &= ~0x00000002u;
+ _has_bits_[0] &= ~0x00000004u;
}
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)
@@ -6722,13 +6738,13 @@ void EnumValueDescriptorProto::clear_number() {
// optional .google.protobuf.EnumValueOptions options = 3;
bool EnumValueDescriptorProto::has_options() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
+ return (_has_bits_[0] & 0x00000002u) != 0;
}
void EnumValueDescriptorProto::set_has_options() {
- _has_bits_[0] |= 0x00000004u;
+ _has_bits_[0] |= 0x00000002u;
}
void EnumValueDescriptorProto::clear_has_options() {
- _has_bits_[0] &= ~0x00000004u;
+ _has_bits_[0] &= ~0x00000002u;
}
void EnumValueDescriptorProto::clear_options() {
if (options_ != NULL) options_->::google::protobuf::EnumValueOptions::Clear();
@@ -6736,7 +6752,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();
@@ -6776,28 +6793,35 @@ const int ServiceDescriptorProto::kOptionsFieldNumber;
ServiceDescriptorProto::ServiceDescriptorProto()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.ServiceDescriptorProto)
}
-
-void ServiceDescriptorProto::InitAsDefaultInstance() {
- options_ = const_cast< ::google::protobuf::ServiceOptions*>(&::google::protobuf::ServiceOptions::default_instance());
-}
-
ServiceDescriptorProto::ServiceDescriptorProto(const ServiceDescriptorProto& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ method_(from.method_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_name()) {
+ name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
+ }
+ if (from.has_options()) {
+ options_ = new ::google::protobuf::ServiceOptions(*from.options_);
+ } else {
+ options_ = NULL;
+ }
// @@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() {
@@ -6807,7 +6831,7 @@ ServiceDescriptorProto::~ServiceDescriptorProto() {
void ServiceDescriptorProto::SharedDtor() {
name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- if (this != default_instance_) {
+ if (this != internal_default_instance()) {
delete options_;
}
}
@@ -6818,17 +6842,15 @@ void ServiceDescriptorProto::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* ServiceDescriptorProto::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return ServiceDescriptorProto_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[9].descriptor;
}
const ServiceDescriptorProto& ServiceDescriptorProto::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-ServiceDescriptorProto* ServiceDescriptorProto::default_instance_ = NULL;
-
ServiceDescriptorProto* ServiceDescriptorProto::New(::google::protobuf::Arena* arena) const {
ServiceDescriptorProto* n = new ServiceDescriptorProto;
if (arena != NULL) {
@@ -6839,19 +6861,19 @@ ServiceDescriptorProto* ServiceDescriptorProto::New(::google::protobuf::Arena* a
void ServiceDescriptorProto::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.ServiceDescriptorProto)
- if (_has_bits_[0 / 32] & 5u) {
+ method_.Clear();
+ if (_has_bits_[0 / 32] & 3u) {
if (has_name()) {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*name_.UnsafeRawStringPointer())->clear();
}
if (has_options()) {
- if (options_ != NULL) options_->::google::protobuf::ServiceOptions::Clear();
+ GOOGLE_DCHECK(options_ != NULL);
+ options_->::google::protobuf::ServiceOptions::Clear();
}
}
- method_.Clear();
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
- }
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool ServiceDescriptorProto::MergePartialFromCodedStream(
@@ -6860,13 +6882,14 @@ bool ServiceDescriptorProto::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.ServiceDescriptorProto)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional string name = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -6876,37 +6899,32 @@ bool ServiceDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_method;
break;
}
// repeated .google.protobuf.MethodDescriptorProto method = 2;
case 2: {
- if (tag == 18) {
- parse_method:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_method:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_method()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_loop_method;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectTag(26)) goto parse_options;
break;
}
// optional .google.protobuf.ServiceOptions options = 3;
case 3: {
- if (tag == 26) {
- parse_options:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(26u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, mutable_options()));
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -6966,6 +6984,7 @@ void ServiceDescriptorProto::SerializeWithCachedSizes(
::google::protobuf::uint8* ServiceDescriptorProto::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ServiceDescriptorProto)
// optional string name = 1;
if (has_name()) {
@@ -7000,11 +7019,27 @@ 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) {
+ if (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
+ // repeated .google.protobuf.MethodDescriptorProto method = 2;
+ {
+ 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 (_has_bits_[0 / 32] & 3u) {
// optional string name = 1;
if (has_name()) {
total_size += 1 +
@@ -7020,31 +7055,17 @@ 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));
- }
-
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const ServiceDescriptorProto* source =
::google::protobuf::internal::DynamicCastToGenerated<const ServiceDescriptorProto>(
&from);
if (source == NULL) {
@@ -7058,11 +7079,10 @@ void ServiceDescriptorProto::MergeFrom(const ::google::protobuf::Message& from)
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
method_.MergeFrom(from.method_);
- if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+ if (from._has_bits_[0 / 32] & 3u) {
if (from.has_name()) {
set_has_name();
name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
@@ -7071,9 +7091,6 @@ void ServiceDescriptorProto::MergeFrom(const ServiceDescriptorProto& from) {
mutable_options()->::google::protobuf::ServiceOptions::MergeFrom(from.options());
}
}
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void ServiceDescriptorProto::CopyFrom(const ::google::protobuf::Message& from) {
@@ -7091,7 +7108,6 @@ void ServiceDescriptorProto::CopyFrom(const ServiceDescriptorProto& from) {
}
bool ServiceDescriptorProto::IsInitialized() const {
-
if (!::google::protobuf::internal::AllAreInitialized(this->method())) return false;
if (has_options()) {
if (!this->options_->IsInitialized()) return false;
@@ -7104,8 +7120,8 @@ void ServiceDescriptorProto::Swap(ServiceDescriptorProto* other) {
InternalSwap(other);
}
void ServiceDescriptorProto::InternalSwap(ServiceDescriptorProto* other) {
- name_.Swap(&other->name_);
method_.UnsafeArenaSwap(&other->method_);
+ name_.Swap(&other->name_);
std::swap(options_, other->options_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
@@ -7113,11 +7129,8 @@ void ServiceDescriptorProto::InternalSwap(ServiceDescriptorProto* other) {
}
::google::protobuf::Metadata ServiceDescriptorProto::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = ServiceDescriptorProto_descriptor_;
- metadata.reflection = ServiceDescriptorProto_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[9];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -7137,37 +7150,45 @@ 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());
+ return name_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void ServiceDescriptorProto::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.ServiceDescriptorProto.name)
+}
+#endif
+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<const char*>(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 {
@@ -7209,13 +7230,13 @@ ServiceDescriptorProto::method() const {
// optional .google.protobuf.ServiceOptions options = 3;
bool ServiceDescriptorProto::has_options() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
+ return (_has_bits_[0] & 0x00000002u) != 0;
}
void ServiceDescriptorProto::set_has_options() {
- _has_bits_[0] |= 0x00000004u;
+ _has_bits_[0] |= 0x00000002u;
}
void ServiceDescriptorProto::clear_has_options() {
- _has_bits_[0] &= ~0x00000004u;
+ _has_bits_[0] &= ~0x00000002u;
}
void ServiceDescriptorProto::clear_options() {
if (options_ != NULL) options_->::google::protobuf::ServiceOptions::Clear();
@@ -7223,7 +7244,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();
@@ -7266,32 +7288,48 @@ const int MethodDescriptorProto::kServerStreamingFieldNumber;
MethodDescriptorProto::MethodDescriptorProto()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.MethodDescriptorProto)
}
-
-void MethodDescriptorProto::InitAsDefaultInstance() {
- options_ = const_cast< ::google::protobuf::MethodOptions*>(&::google::protobuf::MethodOptions::default_instance());
-}
-
MethodDescriptorProto::MethodDescriptorProto(const MethodDescriptorProto& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_name()) {
+ name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
+ }
+ input_type_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_input_type()) {
+ input_type_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.input_type_);
+ }
+ output_type_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_output_type()) {
+ output_type_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.output_type_);
+ }
+ if (from.has_options()) {
+ options_ = new ::google::protobuf::MethodOptions(*from.options_);
+ } else {
+ options_ = NULL;
+ }
+ ::memcpy(&client_streaming_, &from.client_streaming_,
+ reinterpret_cast<char*>(&server_streaming_) -
+ reinterpret_cast<char*>(&client_streaming_) + sizeof(server_streaming_));
// @@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(&options_, 0, reinterpret_cast<char*>(&server_streaming_) -
+ reinterpret_cast<char*>(&options_) + sizeof(server_streaming_));
}
MethodDescriptorProto::~MethodDescriptorProto() {
@@ -7303,7 +7341,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_) {
+ if (this != internal_default_instance()) {
delete options_;
}
}
@@ -7314,17 +7352,15 @@ void MethodDescriptorProto::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* MethodDescriptorProto::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return MethodDescriptorProto_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[10].descriptor;
}
const MethodDescriptorProto& MethodDescriptorProto::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-MethodDescriptorProto* MethodDescriptorProto::default_instance_ = NULL;
-
MethodDescriptorProto* MethodDescriptorProto::New(::google::protobuf::Arena* arena) const {
MethodDescriptorProto* n = new MethodDescriptorProto;
if (arena != NULL) {
@@ -7335,45 +7371,30 @@ MethodDescriptorProto* MethodDescriptorProto::New(::google::protobuf::Arena* are
void MethodDescriptorProto::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.MethodDescriptorProto)
-#if defined(__clang__)
-#define ZR_HELPER_(f) \
- _Pragma("clang diagnostic push") \
- _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
- __builtin_offsetof(MethodDescriptorProto, f) \
- _Pragma("clang diagnostic pop")
-#else
-#define ZR_HELPER_(f) reinterpret_cast<char*>(\
- &reinterpret_cast<MethodDescriptorProto*>(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] & 63u) {
- ZR_(client_streaming_, server_streaming_);
+ if (_has_bits_[0 / 32] & 15u) {
if (has_name()) {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*name_.UnsafeRawStringPointer())->clear();
}
if (has_input_type()) {
- input_type_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!input_type_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*input_type_.UnsafeRawStringPointer())->clear();
}
if (has_output_type()) {
- output_type_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!output_type_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*output_type_.UnsafeRawStringPointer())->clear();
}
if (has_options()) {
- if (options_ != NULL) options_->::google::protobuf::MethodOptions::Clear();
+ GOOGLE_DCHECK(options_ != NULL);
+ options_->::google::protobuf::MethodOptions::Clear();
}
}
-
-#undef ZR_HELPER_
-#undef ZR_
-
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
+ if (_has_bits_[0 / 32] & 48u) {
+ ::memset(&client_streaming_, 0, reinterpret_cast<char*>(&server_streaming_) -
+ reinterpret_cast<char*>(&client_streaming_) + sizeof(server_streaming_));
}
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool MethodDescriptorProto::MergePartialFromCodedStream(
@@ -7382,13 +7403,14 @@ bool MethodDescriptorProto::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.MethodDescriptorProto)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional string name = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -7398,14 +7420,13 @@ bool MethodDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_input_type;
break;
}
// optional string input_type = 2;
case 2: {
- if (tag == 18) {
- parse_input_type:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_input_type()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -7415,14 +7436,13 @@ bool MethodDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(26)) goto parse_output_type;
break;
}
// optional string output_type = 3;
case 3: {
- if (tag == 26) {
- parse_output_type:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(26u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_output_type()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -7432,50 +7452,46 @@ bool MethodDescriptorProto::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(34)) goto parse_options;
break;
}
// optional .google.protobuf.MethodOptions options = 4;
case 4: {
- if (tag == 34) {
- parse_options:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(34u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, mutable_options()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(40)) goto parse_client_streaming;
break;
}
// optional bool client_streaming = 5 [default = false];
case 5: {
- if (tag == 40) {
- parse_client_streaming:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(40u)) {
+ 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;
}
- if (input->ExpectTag(48)) goto parse_server_streaming;
break;
}
// optional bool server_streaming = 6 [default = false];
case 6: {
- if (tag == 48) {
- parse_server_streaming:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(48u)) {
+ 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;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -7559,6 +7575,7 @@ void MethodDescriptorProto::SerializeWithCachedSizes(
::google::protobuf::uint8* MethodDescriptorProto::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.MethodDescriptorProto)
// optional string name = 1;
if (has_name()) {
@@ -7618,10 +7635,15 @@ 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 (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
if (_has_bits_[0 / 32] & 63u) {
// optional string name = 1;
if (has_name()) {
@@ -7662,23 +7684,17 @@ int MethodDescriptorProto::ByteSize() const {
}
}
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const MethodDescriptorProto* source =
::google::protobuf::internal::DynamicCastToGenerated<const MethodDescriptorProto>(
&from);
if (source == NULL) {
@@ -7692,10 +7708,9 @@ void MethodDescriptorProto::MergeFrom(const ::google::protobuf::Message& from) {
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 (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ if (from._has_bits_[0 / 32] & 63u) {
if (from.has_name()) {
set_has_name();
name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
@@ -7718,9 +7733,6 @@ void MethodDescriptorProto::MergeFrom(const MethodDescriptorProto& from) {
set_server_streaming(from.server_streaming());
}
}
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void MethodDescriptorProto::CopyFrom(const ::google::protobuf::Message& from) {
@@ -7738,7 +7750,6 @@ void MethodDescriptorProto::CopyFrom(const MethodDescriptorProto& from) {
}
bool MethodDescriptorProto::IsInitialized() const {
-
if (has_options()) {
if (!this->options_->IsInitialized()) return false;
}
@@ -7762,11 +7773,8 @@ void MethodDescriptorProto::InternalSwap(MethodDescriptorProto* other) {
}
::google::protobuf::Metadata MethodDescriptorProto::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = MethodDescriptorProto_descriptor_;
- metadata.reflection = MethodDescriptorProto_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[10];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -7786,37 +7794,45 @@ 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());
+ return name_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void MethodDescriptorProto::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.MethodDescriptorProto.name)
+}
+#endif
+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<const char*>(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 {
@@ -7840,37 +7856,45 @@ 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());
+ return input_type_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void MethodDescriptorProto::set_input_type(::std::string&& value) {
+ set_has_input_type();
+ input_type_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.MethodDescriptorProto.input_type)
+}
+#endif
+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<const char*>(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 {
@@ -7894,37 +7918,45 @@ 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());
+ return output_type_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void MethodDescriptorProto::set_output_type(::std::string&& value) {
+ set_has_output_type();
+ output_type_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.MethodDescriptorProto.output_type)
+}
+#endif
+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<const char*>(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 {
@@ -7950,7 +7982,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();
@@ -7992,11 +8025,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)
@@ -8016,11 +8049,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)
@@ -8030,29 +8063,6 @@ void MethodDescriptorProto::clear_server_streaming() {
// ===================================================================
-const ::google::protobuf::EnumDescriptor* FileOptions_OptimizeMode_descriptor() {
- protobuf_AssignDescriptorsOnce();
- return FileOptions_OptimizeMode_descriptor_;
-}
-bool FileOptions_OptimizeMode_IsValid(int value) {
- switch(value) {
- case 1:
- case 2:
- case 3:
- return true;
- default:
- return false;
- }
-}
-
-#if !defined(_MSC_VER) || _MSC_VER >= 1900
-const FileOptions_OptimizeMode FileOptions::SPEED;
-const FileOptions_OptimizeMode FileOptions::CODE_SIZE;
-const FileOptions_OptimizeMode FileOptions::LITE_RUNTIME;
-const FileOptions_OptimizeMode FileOptions::OptimizeMode_MIN;
-const FileOptions_OptimizeMode FileOptions::OptimizeMode_MAX;
-const int FileOptions::OptimizeMode_ARRAYSIZE;
-#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int FileOptions::kJavaPackageFieldNumber;
const int FileOptions::kJavaOuterClassnameFieldNumber;
@@ -8068,44 +8078,73 @@ const int FileOptions::kDeprecatedFieldNumber;
const int FileOptions::kCcEnableArenasFieldNumber;
const int FileOptions::kObjcClassPrefixFieldNumber;
const int FileOptions::kCsharpNamespaceFieldNumber;
+const int FileOptions::kSwiftPrefixFieldNumber;
+const int FileOptions::kPhpClassPrefixFieldNumber;
const int FileOptions::kUninterpretedOptionFieldNumber;
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
FileOptions::FileOptions()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.FileOptions)
}
-
-void FileOptions::InitAsDefaultInstance() {
-}
-
FileOptions::FileOptions(const FileOptions& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ uninterpreted_option_(from.uninterpreted_option_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ _extensions_.MergeFrom(from._extensions_);
+ java_package_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_java_package()) {
+ java_package_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.java_package_);
+ }
+ java_outer_classname_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_java_outer_classname()) {
+ java_outer_classname_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.java_outer_classname_);
+ }
+ go_package_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_go_package()) {
+ go_package_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.go_package_);
+ }
+ objc_class_prefix_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_objc_class_prefix()) {
+ objc_class_prefix_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.objc_class_prefix_);
+ }
+ csharp_namespace_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_csharp_namespace()) {
+ csharp_namespace_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.csharp_namespace_);
+ }
+ swift_prefix_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_swift_prefix()) {
+ swift_prefix_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.swift_prefix_);
+ }
+ php_class_prefix_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_php_class_prefix()) {
+ php_class_prefix_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.php_class_prefix_);
+ }
+ ::memcpy(&java_multiple_files_, &from.java_multiple_files_,
+ reinterpret_cast<char*>(&optimize_for_) -
+ reinterpret_cast<char*>(&java_multiple_files_) + sizeof(optimize_for_));
// @@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_));
+ swift_prefix_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ php_class_prefix_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ ::memset(&java_multiple_files_, 0, reinterpret_cast<char*>(&cc_enable_arenas_) -
+ reinterpret_cast<char*>(&java_multiple_files_) + sizeof(cc_enable_arenas_));
+ optimize_for_ = 1;
}
FileOptions::~FileOptions() {
@@ -8119,8 +8158,8 @@ 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_) {
- }
+ swift_prefix_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ php_class_prefix_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
void FileOptions::SetCachedSize(int size) const {
@@ -8129,17 +8168,15 @@ void FileOptions::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* FileOptions::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return FileOptions_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[11].descriptor;
}
const FileOptions& FileOptions::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-FileOptions* FileOptions::default_instance_ = NULL;
-
FileOptions* FileOptions::New(::google::protobuf::Arena* arena) const {
FileOptions* n = new FileOptions;
if (arena != NULL) {
@@ -8151,53 +8188,45 @@ FileOptions* FileOptions::New(::google::protobuf::Arena* arena) const {
void FileOptions::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.FileOptions)
_extensions_.Clear();
-#if defined(__clang__)
-#define ZR_HELPER_(f) \
- _Pragma("clang diagnostic push") \
- _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
- __builtin_offsetof(FileOptions, f) \
- _Pragma("clang diagnostic pop")
-#else
-#define ZR_HELPER_(f) reinterpret_cast<char*>(\
- &reinterpret_cast<FileOptions*>(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_(java_multiple_files_, cc_generic_services_);
+ uninterpreted_option_.Clear();
+ if (_has_bits_[0 / 32] & 127u) {
if (has_java_package()) {
- java_package_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!java_package_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*java_package_.UnsafeRawStringPointer())->clear();
}
if (has_java_outer_classname()) {
- java_outer_classname_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!java_outer_classname_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*java_outer_classname_.UnsafeRawStringPointer())->clear();
}
- optimize_for_ = 1;
if (has_go_package()) {
- go_package_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!go_package_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*go_package_.UnsafeRawStringPointer())->clear();
}
- }
- if (_has_bits_[8 / 32] & 16128u) {
- ZR_(java_generic_services_, cc_enable_arenas_);
if (has_objc_class_prefix()) {
- objc_class_prefix_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!objc_class_prefix_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*objc_class_prefix_.UnsafeRawStringPointer())->clear();
}
if (has_csharp_namespace()) {
- csharp_namespace_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!csharp_namespace_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*csharp_namespace_.UnsafeRawStringPointer())->clear();
+ }
+ if (has_swift_prefix()) {
+ GOOGLE_DCHECK(!swift_prefix_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*swift_prefix_.UnsafeRawStringPointer())->clear();
+ }
+ if (has_php_class_prefix()) {
+ GOOGLE_DCHECK(!php_class_prefix_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*php_class_prefix_.UnsafeRawStringPointer())->clear();
}
}
-
-#undef ZR_HELPER_
-#undef ZR_
-
- uninterpreted_option_.Clear();
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
+ java_multiple_files_ = false;
+ if (_has_bits_[8 / 32] & 65280u) {
+ ::memset(&java_generate_equals_and_hash_, 0, reinterpret_cast<char*>(&cc_enable_arenas_) -
+ reinterpret_cast<char*>(&java_generate_equals_and_hash_) + sizeof(cc_enable_arenas_));
+ optimize_for_ = 1;
}
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool FileOptions::MergePartialFromCodedStream(
@@ -8206,13 +8235,14 @@ bool FileOptions::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.FileOptions)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(16383);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(16383u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional string java_package = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_java_package()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -8222,14 +8252,13 @@ bool FileOptions::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(66)) goto parse_java_outer_classname;
break;
}
// optional string java_outer_classname = 8;
case 8: {
- if (tag == 66) {
- parse_java_outer_classname:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(66u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_java_outer_classname()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -8239,14 +8268,13 @@ bool FileOptions::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(72)) goto parse_optimize_for;
break;
}
// optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED];
case 9: {
- if (tag == 72) {
- parse_optimize_for:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(72u)) {
int value;
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(
@@ -8259,29 +8287,27 @@ bool FileOptions::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(80)) goto parse_java_multiple_files;
break;
}
// optional bool java_multiple_files = 10 [default = false];
case 10: {
- if (tag == 80) {
- parse_java_multiple_files:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(80u)) {
+ 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;
}
- if (input->ExpectTag(90)) goto parse_go_package;
break;
}
// optional string go_package = 11;
case 11: {
- if (tag == 90) {
- parse_go_package:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(90u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_go_package()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -8291,119 +8317,111 @@ bool FileOptions::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(128)) goto parse_cc_generic_services;
break;
}
// optional bool cc_generic_services = 16 [default = false];
case 16: {
- if (tag == 128) {
- parse_cc_generic_services:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(128u)) {
+ 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;
}
- if (input->ExpectTag(136)) goto parse_java_generic_services;
break;
}
// optional bool java_generic_services = 17 [default = false];
case 17: {
- if (tag == 136) {
- parse_java_generic_services:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(136u)) {
+ 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;
}
- if (input->ExpectTag(144)) goto parse_py_generic_services;
break;
}
// optional bool py_generic_services = 18 [default = false];
case 18: {
- if (tag == 144) {
- parse_py_generic_services:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(144u)) {
+ 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];
+ // optional bool java_generate_equals_and_hash = 20 [deprecated = true];
case 20: {
- if (tag == 160) {
- parse_java_generate_equals_and_hash:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(160u)) {
+ set_has_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;
break;
}
// optional bool deprecated = 23 [default = false];
case 23: {
- if (tag == 184) {
- parse_deprecated:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(184u)) {
+ 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;
}
- if (input->ExpectTag(216)) goto parse_java_string_check_utf8;
break;
}
// optional bool java_string_check_utf8 = 27 [default = false];
case 27: {
- if (tag == 216) {
- parse_java_string_check_utf8:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(216u)) {
+ 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;
}
- if (input->ExpectTag(248)) goto parse_cc_enable_arenas;
break;
}
// optional bool cc_enable_arenas = 31 [default = false];
case 31: {
- if (tag == 248) {
- parse_cc_enable_arenas:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(248u)) {
+ 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;
}
- if (input->ExpectTag(290)) goto parse_objc_class_prefix;
break;
}
// optional string objc_class_prefix = 36;
case 36: {
- if (tag == 290) {
- parse_objc_class_prefix:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(290u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_objc_class_prefix()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -8413,14 +8431,13 @@ bool FileOptions::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(298)) goto parse_csharp_namespace;
break;
}
// optional string csharp_namespace = 37;
case 37: {
- if (tag == 298) {
- parse_csharp_namespace:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(298u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_csharp_namespace()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -8430,24 +8447,52 @@ bool FileOptions::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(7994)) goto parse_uninterpreted_option;
+ break;
+ }
+
+ // optional string swift_prefix = 39;
+ case 39: {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(314u)) {
+ DO_(::google::protobuf::internal::WireFormatLite::ReadString(
+ input, this->mutable_swift_prefix()));
+ ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+ this->swift_prefix().data(), this->swift_prefix().length(),
+ ::google::protobuf::internal::WireFormat::PARSE,
+ "google.protobuf.FileOptions.swift_prefix");
+ } else {
+ goto handle_unusual;
+ }
+ break;
+ }
+
+ // optional string php_class_prefix = 40;
+ case 40: {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(322u)) {
+ DO_(::google::protobuf::internal::WireFormatLite::ReadString(
+ input, this->mutable_php_class_prefix()));
+ ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+ this->php_class_prefix().data(), this->php_class_prefix().length(),
+ ::google::protobuf::internal::WireFormat::PARSE,
+ "google.protobuf.FileOptions.php_class_prefix");
+ } else {
+ goto handle_unusual;
+ }
break;
}
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
case 999: {
- if (tag == 7994) {
- parse_uninterpreted_option:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(7994u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_uninterpreted_option:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_uninterpreted_option()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(7994)) goto parse_loop_uninterpreted_option;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -8459,7 +8504,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;
}
@@ -8537,7 +8582,7 @@ void FileOptions::SerializeWithCachedSizes(
::google::protobuf::internal::WireFormatLite::WriteBool(18, this->py_generic_services(), output);
}
- // optional bool java_generate_equals_and_hash = 20 [default = false];
+ // optional bool java_generate_equals_and_hash = 20 [deprecated = true];
if (has_java_generate_equals_and_hash()) {
::google::protobuf::internal::WireFormatLite::WriteBool(20, this->java_generate_equals_and_hash(), output);
}
@@ -8577,6 +8622,26 @@ void FileOptions::SerializeWithCachedSizes(
37, this->csharp_namespace(), output);
}
+ // optional string swift_prefix = 39;
+ if (has_swift_prefix()) {
+ ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+ this->swift_prefix().data(), this->swift_prefix().length(),
+ ::google::protobuf::internal::WireFormat::SERIALIZE,
+ "google.protobuf.FileOptions.swift_prefix");
+ ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
+ 39, this->swift_prefix(), output);
+ }
+
+ // optional string php_class_prefix = 40;
+ if (has_php_class_prefix()) {
+ ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+ this->php_class_prefix().data(), this->php_class_prefix().length(),
+ ::google::protobuf::internal::WireFormat::SERIALIZE,
+ "google.protobuf.FileOptions.php_class_prefix");
+ ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
+ 40, this->php_class_prefix(), output);
+ }
+
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
for (unsigned int i = 0, n = this->uninterpreted_option_size(); i < n; i++) {
::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
@@ -8596,6 +8661,7 @@ void FileOptions::SerializeWithCachedSizes(
::google::protobuf::uint8* FileOptions::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FileOptions)
// optional string java_package = 1;
if (has_java_package()) {
@@ -8656,7 +8722,7 @@ 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];
+ // optional bool java_generate_equals_and_hash = 20 [deprecated = true];
if (has_java_generate_equals_and_hash()) {
target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(20, this->java_generate_equals_and_hash(), target);
}
@@ -8698,6 +8764,28 @@ void FileOptions::SerializeWithCachedSizes(
37, this->csharp_namespace(), target);
}
+ // optional string swift_prefix = 39;
+ if (has_swift_prefix()) {
+ ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+ this->swift_prefix().data(), this->swift_prefix().length(),
+ ::google::protobuf::internal::WireFormat::SERIALIZE,
+ "google.protobuf.FileOptions.swift_prefix");
+ target =
+ ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
+ 39, this->swift_prefix(), target);
+ }
+
+ // optional string php_class_prefix = 40;
+ if (has_php_class_prefix()) {
+ ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+ this->php_class_prefix().data(), this->php_class_prefix().length(),
+ ::google::protobuf::internal::WireFormat::SERIALIZE,
+ "google.protobuf.FileOptions.php_class_prefix");
+ target =
+ ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
+ 40, this->php_class_prefix(), target);
+ }
+
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
for (unsigned int i = 0, n = this->uninterpreted_option_size(); i < n; i++) {
target = ::google::protobuf::internal::WireFormatLite::
@@ -8707,7 +8795,7 @@ void FileOptions::SerializeWithCachedSizes(
// Extension range [1000, 536870912)
target = _extensions_.InternalSerializeWithCachedSizesToArray(
- 1000, 536870912, false, target);
+ 1000, 536870912, deterministic, target);
if (_internal_metadata_.have_unknown_fields()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
@@ -8717,9 +8805,27 @@ 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;
+
+ total_size += _extensions_.ByteSize();
+
+ if (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
+ // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
+ {
+ 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));
+ }
+ }
if (_has_bits_[0 / 32] & 255u) {
// optional string java_package = 1;
@@ -8736,12 +8842,49 @@ int FileOptions::ByteSize() const {
this->java_outer_classname());
}
+ // optional string go_package = 11;
+ if (has_go_package()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::StringSize(
+ this->go_package());
+ }
+
+ // optional string objc_class_prefix = 36;
+ if (has_objc_class_prefix()) {
+ total_size += 2 +
+ ::google::protobuf::internal::WireFormatLite::StringSize(
+ this->objc_class_prefix());
+ }
+
+ // optional string csharp_namespace = 37;
+ if (has_csharp_namespace()) {
+ total_size += 2 +
+ ::google::protobuf::internal::WireFormatLite::StringSize(
+ this->csharp_namespace());
+ }
+
+ // optional string swift_prefix = 39;
+ if (has_swift_prefix()) {
+ total_size += 2 +
+ ::google::protobuf::internal::WireFormatLite::StringSize(
+ this->swift_prefix());
+ }
+
+ // optional string php_class_prefix = 40;
+ if (has_php_class_prefix()) {
+ total_size += 2 +
+ ::google::protobuf::internal::WireFormatLite::StringSize(
+ this->php_class_prefix());
+ }
+
// optional bool java_multiple_files = 10 [default = false];
if (has_java_multiple_files()) {
total_size += 1 + 1;
}
- // optional bool java_generate_equals_and_hash = 20 [default = false];
+ }
+ if (_has_bits_[8 / 32] & 65280u) {
+ // optional bool java_generate_equals_and_hash = 20 [deprecated = true];
if (has_java_generate_equals_and_hash()) {
total_size += 2 + 1;
}
@@ -8751,26 +8894,11 @@ int FileOptions::ByteSize() const {
total_size += 2 + 1;
}
- // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED];
- if (has_optimize_for()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::EnumSize(this->optimize_for());
- }
-
- // optional string go_package = 11;
- if (has_go_package()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::StringSize(
- this->go_package());
- }
-
// optional bool cc_generic_services = 16 [default = false];
if (has_cc_generic_services()) {
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;
@@ -8791,48 +8919,24 @@ int FileOptions::ByteSize() const {
total_size += 2 + 1;
}
- // optional string objc_class_prefix = 36;
- if (has_objc_class_prefix()) {
- total_size += 2 +
- ::google::protobuf::internal::WireFormatLite::StringSize(
- this->objc_class_prefix());
- }
-
- // optional string csharp_namespace = 37;
- if (has_csharp_namespace()) {
- total_size += 2 +
- ::google::protobuf::internal::WireFormatLite::StringSize(
- this->csharp_namespace());
+ // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED];
+ if (has_optimize_for()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::EnumSize(this->optimize_for());
}
}
- // 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));
- }
-
- total_size += _extensions_.ByteSize();
-
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const FileOptions* source =
::google::protobuf::internal::DynamicCastToGenerated<const FileOptions>(
&from);
if (source == NULL) {
@@ -8846,11 +8950,11 @@ void FileOptions::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _extensions_.MergeFrom(from._extensions_);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
uninterpreted_option_.MergeFrom(from.uninterpreted_option_);
- if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+ if (from._has_bits_[0 / 32] & 255u) {
if (from.has_java_package()) {
set_has_java_package();
java_package_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.java_package_);
@@ -8859,27 +8963,40 @@ void FileOptions::MergeFrom(const FileOptions& from) {
set_has_java_outer_classname();
java_outer_classname_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.java_outer_classname_);
}
+ if (from.has_go_package()) {
+ set_has_go_package();
+ go_package_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.go_package_);
+ }
+ if (from.has_objc_class_prefix()) {
+ set_has_objc_class_prefix();
+ objc_class_prefix_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.objc_class_prefix_);
+ }
+ if (from.has_csharp_namespace()) {
+ set_has_csharp_namespace();
+ csharp_namespace_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.csharp_namespace_);
+ }
+ if (from.has_swift_prefix()) {
+ set_has_swift_prefix();
+ swift_prefix_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.swift_prefix_);
+ }
+ if (from.has_php_class_prefix()) {
+ set_has_php_class_prefix();
+ php_class_prefix_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.php_class_prefix_);
+ }
if (from.has_java_multiple_files()) {
set_java_multiple_files(from.java_multiple_files());
}
+ }
+ if (from._has_bits_[8 / 32] & 65280u) {
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());
}
- if (from.has_optimize_for()) {
- set_optimize_for(from.optimize_for());
- }
- if (from.has_go_package()) {
- set_has_go_package();
- go_package_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.go_package_);
- }
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());
}
@@ -8892,19 +9009,10 @@ void FileOptions::MergeFrom(const FileOptions& from) {
if (from.has_cc_enable_arenas()) {
set_cc_enable_arenas(from.cc_enable_arenas());
}
- if (from.has_objc_class_prefix()) {
- set_has_objc_class_prefix();
- objc_class_prefix_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.objc_class_prefix_);
- }
- if (from.has_csharp_namespace()) {
- set_has_csharp_namespace();
- csharp_namespace_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.csharp_namespace_);
+ if (from.has_optimize_for()) {
+ set_optimize_for(from.optimize_for());
}
}
- _extensions_.MergeFrom(from._extensions_);
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void FileOptions::CopyFrom(const ::google::protobuf::Message& from) {
@@ -8922,10 +9030,12 @@ void FileOptions::CopyFrom(const FileOptions& from) {
}
bool FileOptions::IsInitialized() const {
+ if (!_extensions_.IsInitialized()) {
+ return false;
+ }
if (!::google::protobuf::internal::AllAreInitialized(this->uninterpreted_option())) return false;
-
- if (!_extensions_.IsInitialized()) return false; return true;
+ return true;
}
void FileOptions::Swap(FileOptions* other) {
@@ -8933,21 +9043,23 @@ void FileOptions::Swap(FileOptions* other) {
InternalSwap(other);
}
void FileOptions::InternalSwap(FileOptions* other) {
+ uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_);
java_package_.Swap(&other->java_package_);
java_outer_classname_.Swap(&other->java_outer_classname_);
+ go_package_.Swap(&other->go_package_);
+ objc_class_prefix_.Swap(&other->objc_class_prefix_);
+ csharp_namespace_.Swap(&other->csharp_namespace_);
+ swift_prefix_.Swap(&other->swift_prefix_);
+ php_class_prefix_.Swap(&other->php_class_prefix_);
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_);
std::swap(cc_generic_services_, other->cc_generic_services_);
std::swap(java_generic_services_, other->java_generic_services_);
std::swap(py_generic_services_, other->py_generic_services_);
std::swap(deprecated_, other->deprecated_);
std::swap(cc_enable_arenas_, other->cc_enable_arenas_);
- objc_class_prefix_.Swap(&other->objc_class_prefix_);
- csharp_namespace_.Swap(&other->csharp_namespace_);
- uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_);
+ std::swap(optimize_for_, other->optimize_for_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
@@ -8955,11 +9067,8 @@ void FileOptions::InternalSwap(FileOptions* other) {
}
::google::protobuf::Metadata FileOptions::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = FileOptions_descriptor_;
- metadata.reflection = FileOptions_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[11];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -8979,37 +9088,45 @@ 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());
+ return java_package_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void FileOptions::set_java_package(::std::string&& value) {
+ set_has_java_package();
+ java_package_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileOptions.java_package)
+}
+#endif
+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<const char*>(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 {
@@ -9033,37 +9150,45 @@ 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());
+ return java_outer_classname_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void FileOptions::set_java_outer_classname(::std::string&& value) {
+ set_has_java_outer_classname();
+ java_outer_classname_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileOptions.java_outer_classname)
+}
+#endif
+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<const char*>(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 {
@@ -9075,47 +9200,47 @@ void FileOptions::clear_java_outer_classname() {
// optional bool java_multiple_files = 10 [default = false];
bool FileOptions::has_java_multiple_files() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
+ return (_has_bits_[0] & 0x00000080u) != 0;
}
void FileOptions::set_has_java_multiple_files() {
- _has_bits_[0] |= 0x00000004u;
+ _has_bits_[0] |= 0x00000080u;
}
void FileOptions::clear_has_java_multiple_files() {
- _has_bits_[0] &= ~0x00000004u;
+ _has_bits_[0] &= ~0x00000080u;
}
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];
+// optional bool java_generate_equals_and_hash = 20 [deprecated = true];
bool FileOptions::has_java_generate_equals_and_hash() const {
- return (_has_bits_[0] & 0x00000008u) != 0;
+ return (_has_bits_[0] & 0x00000100u) != 0;
}
void FileOptions::set_has_java_generate_equals_and_hash() {
- _has_bits_[0] |= 0x00000008u;
+ _has_bits_[0] |= 0x00000100u;
}
void FileOptions::clear_has_java_generate_equals_and_hash() {
- _has_bits_[0] &= ~0x00000008u;
+ _has_bits_[0] &= ~0x00000100u;
}
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 {
+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) {
+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)
@@ -9123,23 +9248,23 @@ void FileOptions::clear_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] & 0x00000200u) != 0;
}
void FileOptions::set_has_java_string_check_utf8() {
- _has_bits_[0] |= 0x00000010u;
+ _has_bits_[0] |= 0x00000200u;
}
void FileOptions::clear_has_java_string_check_utf8() {
- _has_bits_[0] &= ~0x00000010u;
+ _has_bits_[0] &= ~0x00000200u;
}
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)
@@ -9147,23 +9272,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] & 0x00008000u) != 0;
}
void FileOptions::set_has_optimize_for() {
- _has_bits_[0] |= 0x00000020u;
+ _has_bits_[0] |= 0x00008000u;
}
void FileOptions::clear_has_optimize_for() {
- _has_bits_[0] &= ~0x00000020u;
+ _has_bits_[0] &= ~0x00008000u;
}
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;
@@ -9172,49 +9297,57 @@ 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] & 0x00000004u) != 0;
}
void FileOptions::set_has_go_package() {
- _has_bits_[0] |= 0x00000040u;
+ _has_bits_[0] |= 0x00000004u;
}
void FileOptions::clear_has_go_package() {
- _has_bits_[0] &= ~0x00000040u;
+ _has_bits_[0] &= ~0x00000004u;
}
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());
+ return go_package_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void FileOptions::set_go_package(::std::string&& value) {
+ set_has_go_package();
+ go_package_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileOptions.go_package)
+}
+#endif
+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<const char*>(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 {
@@ -9226,23 +9359,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] & 0x00000400u) != 0;
}
void FileOptions::set_has_cc_generic_services() {
- _has_bits_[0] |= 0x00000080u;
+ _has_bits_[0] |= 0x00000400u;
}
void FileOptions::clear_has_cc_generic_services() {
- _has_bits_[0] &= ~0x00000080u;
+ _has_bits_[0] &= ~0x00000400u;
}
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)
@@ -9250,23 +9383,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] & 0x00000800u) != 0;
}
void FileOptions::set_has_java_generic_services() {
- _has_bits_[0] |= 0x00000100u;
+ _has_bits_[0] |= 0x00000800u;
}
void FileOptions::clear_has_java_generic_services() {
- _has_bits_[0] &= ~0x00000100u;
+ _has_bits_[0] &= ~0x00000800u;
}
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)
@@ -9274,23 +9407,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] & 0x00001000u) != 0;
}
void FileOptions::set_has_py_generic_services() {
- _has_bits_[0] |= 0x00000200u;
+ _has_bits_[0] |= 0x00001000u;
}
void FileOptions::clear_has_py_generic_services() {
- _has_bits_[0] &= ~0x00000200u;
+ _has_bits_[0] &= ~0x00001000u;
}
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)
@@ -9298,23 +9431,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] & 0x00002000u) != 0;
}
void FileOptions::set_has_deprecated() {
- _has_bits_[0] |= 0x00000400u;
+ _has_bits_[0] |= 0x00002000u;
}
void FileOptions::clear_has_deprecated() {
- _has_bits_[0] &= ~0x00000400u;
+ _has_bits_[0] &= ~0x00002000u;
}
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)
@@ -9322,23 +9455,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] & 0x00004000u) != 0;
}
void FileOptions::set_has_cc_enable_arenas() {
- _has_bits_[0] |= 0x00000800u;
+ _has_bits_[0] |= 0x00004000u;
}
void FileOptions::clear_has_cc_enable_arenas() {
- _has_bits_[0] &= ~0x00000800u;
+ _has_bits_[0] &= ~0x00004000u;
}
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)
@@ -9346,49 +9479,57 @@ 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] & 0x00000008u) != 0;
}
void FileOptions::set_has_objc_class_prefix() {
- _has_bits_[0] |= 0x00001000u;
+ _has_bits_[0] |= 0x00000008u;
}
void FileOptions::clear_has_objc_class_prefix() {
- _has_bits_[0] &= ~0x00001000u;
+ _has_bits_[0] &= ~0x00000008u;
}
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());
+ return objc_class_prefix_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void FileOptions::set_objc_class_prefix(::std::string&& value) {
+ set_has_objc_class_prefix();
+ objc_class_prefix_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileOptions.objc_class_prefix)
+}
+#endif
+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<const char*>(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 {
@@ -9400,49 +9541,57 @@ 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] & 0x00000010u) != 0;
}
void FileOptions::set_has_csharp_namespace() {
- _has_bits_[0] |= 0x00002000u;
+ _has_bits_[0] |= 0x00000010u;
}
void FileOptions::clear_has_csharp_namespace() {
- _has_bits_[0] &= ~0x00002000u;
+ _has_bits_[0] &= ~0x00000010u;
}
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());
+ return csharp_namespace_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void FileOptions::set_csharp_namespace(::std::string&& value) {
+ set_has_csharp_namespace();
+ csharp_namespace_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileOptions.csharp_namespace)
+}
+#endif
+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<const char*>(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 {
@@ -9452,6 +9601,130 @@ void FileOptions::clear_csharp_namespace() {
// @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.csharp_namespace)
}
+// optional string swift_prefix = 39;
+bool FileOptions::has_swift_prefix() const {
+ return (_has_bits_[0] & 0x00000020u) != 0;
+}
+void FileOptions::set_has_swift_prefix() {
+ _has_bits_[0] |= 0x00000020u;
+}
+void FileOptions::clear_has_swift_prefix() {
+ _has_bits_[0] &= ~0x00000020u;
+}
+void FileOptions::clear_swift_prefix() {
+ swift_prefix_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ clear_has_swift_prefix();
+}
+const ::std::string& FileOptions::swift_prefix() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.swift_prefix)
+ return swift_prefix_.GetNoArena();
+}
+void FileOptions::set_swift_prefix(const ::std::string& value) {
+ set_has_swift_prefix();
+ swift_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
+ // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.swift_prefix)
+}
+#if LANG_CXX11
+void FileOptions::set_swift_prefix(::std::string&& value) {
+ set_has_swift_prefix();
+ swift_prefix_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileOptions.swift_prefix)
+}
+#endif
+void FileOptions::set_swift_prefix(const char* value) {
+ set_has_swift_prefix();
+ swift_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+ // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.swift_prefix)
+}
+void FileOptions::set_swift_prefix(const char* value, size_t size) {
+ set_has_swift_prefix();
+ swift_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+ ::std::string(reinterpret_cast<const char*>(value), size));
+ // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileOptions.swift_prefix)
+}
+::std::string* FileOptions::mutable_swift_prefix() {
+ set_has_swift_prefix();
+ // @@protoc_insertion_point(field_mutable:google.protobuf.FileOptions.swift_prefix)
+ return swift_prefix_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+::std::string* FileOptions::release_swift_prefix() {
+ // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.swift_prefix)
+ clear_has_swift_prefix();
+ return swift_prefix_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+void FileOptions::set_allocated_swift_prefix(::std::string* swift_prefix) {
+ if (swift_prefix != NULL) {
+ set_has_swift_prefix();
+ } else {
+ clear_has_swift_prefix();
+ }
+ swift_prefix_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), swift_prefix);
+ // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.swift_prefix)
+}
+
+// optional string php_class_prefix = 40;
+bool FileOptions::has_php_class_prefix() const {
+ return (_has_bits_[0] & 0x00000040u) != 0;
+}
+void FileOptions::set_has_php_class_prefix() {
+ _has_bits_[0] |= 0x00000040u;
+}
+void FileOptions::clear_has_php_class_prefix() {
+ _has_bits_[0] &= ~0x00000040u;
+}
+void FileOptions::clear_php_class_prefix() {
+ php_class_prefix_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ clear_has_php_class_prefix();
+}
+const ::std::string& FileOptions::php_class_prefix() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.php_class_prefix)
+ return php_class_prefix_.GetNoArena();
+}
+void FileOptions::set_php_class_prefix(const ::std::string& value) {
+ set_has_php_class_prefix();
+ php_class_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
+ // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.php_class_prefix)
+}
+#if LANG_CXX11
+void FileOptions::set_php_class_prefix(::std::string&& value) {
+ set_has_php_class_prefix();
+ php_class_prefix_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileOptions.php_class_prefix)
+}
+#endif
+void FileOptions::set_php_class_prefix(const char* value) {
+ set_has_php_class_prefix();
+ php_class_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+ // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.php_class_prefix)
+}
+void FileOptions::set_php_class_prefix(const char* value, size_t size) {
+ set_has_php_class_prefix();
+ php_class_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+ ::std::string(reinterpret_cast<const char*>(value), size));
+ // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileOptions.php_class_prefix)
+}
+::std::string* FileOptions::mutable_php_class_prefix() {
+ set_has_php_class_prefix();
+ // @@protoc_insertion_point(field_mutable:google.protobuf.FileOptions.php_class_prefix)
+ return php_class_prefix_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+::std::string* FileOptions::release_php_class_prefix() {
+ // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.php_class_prefix)
+ clear_has_php_class_prefix();
+ return php_class_prefix_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+void FileOptions::set_allocated_php_class_prefix(::std::string* php_class_prefix) {
+ if (php_class_prefix != NULL) {
+ set_has_php_class_prefix();
+ } else {
+ clear_has_php_class_prefix();
+ }
+ php_class_prefix_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), php_class_prefix);
+ // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.php_class_prefix)
+}
+
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
int FileOptions::uninterpreted_option_size() const {
return uninterpreted_option_.size();
@@ -9496,28 +9769,30 @@ const int MessageOptions::kUninterpretedOptionFieldNumber;
MessageOptions::MessageOptions()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.MessageOptions)
}
-
-void MessageOptions::InitAsDefaultInstance() {
-}
-
MessageOptions::MessageOptions(const MessageOptions& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ uninterpreted_option_(from.uninterpreted_option_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ _extensions_.MergeFrom(from._extensions_);
+ ::memcpy(&message_set_wire_format_, &from.message_set_wire_format_,
+ reinterpret_cast<char*>(&map_entry_) -
+ reinterpret_cast<char*>(&message_set_wire_format_) + sizeof(map_entry_));
// @@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<char*>(&map_entry_) -
+ reinterpret_cast<char*>(&message_set_wire_format_) + sizeof(map_entry_));
}
MessageOptions::~MessageOptions() {
@@ -9526,8 +9801,6 @@ MessageOptions::~MessageOptions() {
}
void MessageOptions::SharedDtor() {
- if (this != default_instance_) {
- }
}
void MessageOptions::SetCachedSize(int size) const {
@@ -9536,17 +9809,15 @@ void MessageOptions::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* MessageOptions::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return MessageOptions_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[12].descriptor;
}
const MessageOptions& MessageOptions::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-MessageOptions* MessageOptions::default_instance_ = NULL;
-
MessageOptions* MessageOptions::New(::google::protobuf::Arena* arena) const {
MessageOptions* n = new MessageOptions;
if (arena != NULL) {
@@ -9558,32 +9829,13 @@ MessageOptions* MessageOptions::New(::google::protobuf::Arena* arena) const {
void MessageOptions::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.MessageOptions)
_extensions_.Clear();
-#if defined(__clang__)
-#define ZR_HELPER_(f) \
- _Pragma("clang diagnostic push") \
- _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
- __builtin_offsetof(MessageOptions, f) \
- _Pragma("clang diagnostic pop")
-#else
-#define ZR_HELPER_(f) reinterpret_cast<char*>(\
- &reinterpret_cast<MessageOptions*>(16)->f)
-#endif
-
-#define ZR_(first, last) do {\
- ::memset(&first, 0,\
- ZR_HELPER_(last) - ZR_HELPER_(first) + sizeof(last));\
-} while (0)
-
- ZR_(message_set_wire_format_, map_entry_);
-
-#undef ZR_HELPER_
-#undef ZR_
-
uninterpreted_option_.Clear();
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
+ if (_has_bits_[0 / 32] & 15u) {
+ ::memset(&message_set_wire_format_, 0, reinterpret_cast<char*>(&map_entry_) -
+ reinterpret_cast<char*>(&message_set_wire_format_) + sizeof(map_entry_));
}
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool MessageOptions::MergePartialFromCodedStream(
@@ -9592,83 +9844,77 @@ bool MessageOptions::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.MessageOptions)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(16383);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(16383u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional bool message_set_wire_format = 1 [default = false];
case 1: {
- if (tag == 8) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(8u)) {
+ 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;
}
- if (input->ExpectTag(16)) goto parse_no_standard_descriptor_accessor;
break;
}
// optional bool no_standard_descriptor_accessor = 2 [default = false];
case 2: {
- if (tag == 16) {
- parse_no_standard_descriptor_accessor:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(16u)) {
+ 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;
}
- if (input->ExpectTag(24)) goto parse_deprecated;
break;
}
// optional bool deprecated = 3 [default = false];
case 3: {
- if (tag == 24) {
- parse_deprecated:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(24u)) {
+ 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;
}
- if (input->ExpectTag(56)) goto parse_map_entry;
break;
}
// optional bool map_entry = 7;
case 7: {
- if (tag == 56) {
- parse_map_entry:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(56u)) {
+ 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;
}
- if (input->ExpectTag(7994)) goto parse_uninterpreted_option;
break;
}
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
case 999: {
- if (tag == 7994) {
- parse_uninterpreted_option:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(7994u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_uninterpreted_option:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_uninterpreted_option()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(7994)) goto parse_loop_uninterpreted_option;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -9680,7 +9926,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;
}
@@ -9741,6 +9987,7 @@ void MessageOptions::SerializeWithCachedSizes(
::google::protobuf::uint8* MessageOptions::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.MessageOptions)
// optional bool message_set_wire_format = 1 [default = false];
if (has_message_set_wire_format()) {
@@ -9771,7 +10018,7 @@ void MessageOptions::SerializeWithCachedSizes(
// Extension range [1000, 536870912)
target = _extensions_.InternalSerializeWithCachedSizesToArray(
- 1000, 536870912, false, target);
+ 1000, 536870912, deterministic, target);
if (_internal_metadata_.have_unknown_fields()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
@@ -9781,9 +10028,27 @@ 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;
+
+ total_size += _extensions_.ByteSize();
+
+ if (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
+ // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
+ {
+ 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));
+ }
+ }
if (_has_bits_[0 / 32] & 15u) {
// optional bool message_set_wire_format = 1 [default = false];
@@ -9807,33 +10072,17 @@ 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));
- }
-
- total_size += _extensions_.ByteSize();
-
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const MessageOptions* source =
::google::protobuf::internal::DynamicCastToGenerated<const MessageOptions>(
&from);
if (source == NULL) {
@@ -9847,11 +10096,11 @@ void MessageOptions::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _extensions_.MergeFrom(from._extensions_);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
uninterpreted_option_.MergeFrom(from.uninterpreted_option_);
- if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+ if (from._has_bits_[0 / 32] & 15u) {
if (from.has_message_set_wire_format()) {
set_message_set_wire_format(from.message_set_wire_format());
}
@@ -9865,10 +10114,6 @@ void MessageOptions::MergeFrom(const MessageOptions& from) {
set_map_entry(from.map_entry());
}
}
- _extensions_.MergeFrom(from._extensions_);
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void MessageOptions::CopyFrom(const ::google::protobuf::Message& from) {
@@ -9886,10 +10131,12 @@ void MessageOptions::CopyFrom(const MessageOptions& from) {
}
bool MessageOptions::IsInitialized() const {
+ if (!_extensions_.IsInitialized()) {
+ return false;
+ }
if (!::google::protobuf::internal::AllAreInitialized(this->uninterpreted_option())) return false;
-
- if (!_extensions_.IsInitialized()) return false; return true;
+ return true;
}
void MessageOptions::Swap(MessageOptions* other) {
@@ -9897,11 +10144,11 @@ void MessageOptions::Swap(MessageOptions* other) {
InternalSwap(other);
}
void MessageOptions::InternalSwap(MessageOptions* other) {
+ uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_);
std::swap(message_set_wire_format_, other->message_set_wire_format_);
std::swap(no_standard_descriptor_accessor_, other->no_standard_descriptor_accessor_);
std::swap(deprecated_, other->deprecated_);
std::swap(map_entry_, other->map_entry_);
- uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
@@ -9909,11 +10156,8 @@ void MessageOptions::InternalSwap(MessageOptions* other) {
}
::google::protobuf::Metadata MessageOptions::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = MessageOptions_descriptor_;
- metadata.reflection = MessageOptions_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[12];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -9933,11 +10177,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)
@@ -9957,11 +10201,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)
@@ -9981,11 +10225,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)
@@ -10005,11 +10249,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)
@@ -10049,52 +10293,6 @@ MessageOptions::uninterpreted_option() const {
// ===================================================================
-const ::google::protobuf::EnumDescriptor* FieldOptions_CType_descriptor() {
- protobuf_AssignDescriptorsOnce();
- return FieldOptions_CType_descriptor_;
-}
-bool FieldOptions_CType_IsValid(int value) {
- switch(value) {
- case 0:
- case 1:
- case 2:
- return true;
- default:
- return false;
- }
-}
-
-#if !defined(_MSC_VER) || _MSC_VER >= 1900
-const FieldOptions_CType FieldOptions::STRING;
-const FieldOptions_CType FieldOptions::CORD;
-const FieldOptions_CType FieldOptions::STRING_PIECE;
-const FieldOptions_CType FieldOptions::CType_MIN;
-const FieldOptions_CType FieldOptions::CType_MAX;
-const int FieldOptions::CType_ARRAYSIZE;
-#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
-const ::google::protobuf::EnumDescriptor* FieldOptions_JSType_descriptor() {
- protobuf_AssignDescriptorsOnce();
- return FieldOptions_JSType_descriptor_;
-}
-bool FieldOptions_JSType_IsValid(int value) {
- switch(value) {
- case 0:
- case 1:
- case 2:
- return true;
- default:
- return false;
- }
-}
-
-#if !defined(_MSC_VER) || _MSC_VER >= 1900
-const FieldOptions_JSType FieldOptions::JS_NORMAL;
-const FieldOptions_JSType FieldOptions::JS_STRING;
-const FieldOptions_JSType FieldOptions::JS_NUMBER;
-const FieldOptions_JSType FieldOptions::JSType_MIN;
-const FieldOptions_JSType FieldOptions::JSType_MAX;
-const int FieldOptions::JSType_ARRAYSIZE;
-#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int FieldOptions::kCtypeFieldNumber;
const int FieldOptions::kPackedFieldNumber;
@@ -10107,30 +10305,30 @@ const int FieldOptions::kUninterpretedOptionFieldNumber;
FieldOptions::FieldOptions()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.FieldOptions)
}
-
-void FieldOptions::InitAsDefaultInstance() {
-}
-
FieldOptions::FieldOptions(const FieldOptions& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ uninterpreted_option_(from.uninterpreted_option_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ _extensions_.MergeFrom(from._extensions_);
+ ::memcpy(&ctype_, &from.ctype_,
+ reinterpret_cast<char*>(&weak_) -
+ reinterpret_cast<char*>(&ctype_) + sizeof(weak_));
// @@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<char*>(&weak_) -
+ reinterpret_cast<char*>(&ctype_) + sizeof(weak_));
}
FieldOptions::~FieldOptions() {
@@ -10139,8 +10337,6 @@ FieldOptions::~FieldOptions() {
}
void FieldOptions::SharedDtor() {
- if (this != default_instance_) {
- }
}
void FieldOptions::SetCachedSize(int size) const {
@@ -10149,17 +10345,15 @@ void FieldOptions::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* FieldOptions::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return FieldOptions_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[13].descriptor;
}
const FieldOptions& FieldOptions::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-FieldOptions* FieldOptions::default_instance_ = NULL;
-
FieldOptions* FieldOptions::New(::google::protobuf::Arena* arena) const {
FieldOptions* n = new FieldOptions;
if (arena != NULL) {
@@ -10171,35 +10365,13 @@ FieldOptions* FieldOptions::New(::google::protobuf::Arena* arena) const {
void FieldOptions::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.FieldOptions)
_extensions_.Clear();
-#if defined(__clang__)
-#define ZR_HELPER_(f) \
- _Pragma("clang diagnostic push") \
- _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
- __builtin_offsetof(FieldOptions, f) \
- _Pragma("clang diagnostic pop")
-#else
-#define ZR_HELPER_(f) reinterpret_cast<char*>(\
- &reinterpret_cast<FieldOptions*>(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] & 63u) {
- ZR_(ctype_, jstype_);
- ZR_(packed_, weak_);
- }
-
-#undef ZR_HELPER_
-#undef ZR_
-
uninterpreted_option_.Clear();
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
+ if (_has_bits_[0 / 32] & 63u) {
+ ::memset(&ctype_, 0, reinterpret_cast<char*>(&weak_) -
+ reinterpret_cast<char*>(&ctype_) + sizeof(weak_));
}
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool FieldOptions::MergePartialFromCodedStream(
@@ -10208,13 +10380,14 @@ bool FieldOptions::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.FieldOptions)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(16383);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(16383u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];
case 1: {
- if (tag == 8) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(8u)) {
int value;
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(
@@ -10227,59 +10400,55 @@ bool FieldOptions::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(16)) goto parse_packed;
break;
}
// optional bool packed = 2;
case 2: {
- if (tag == 16) {
- parse_packed:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(16u)) {
+ 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;
}
- if (input->ExpectTag(24)) goto parse_deprecated;
break;
}
// optional bool deprecated = 3 [default = false];
case 3: {
- if (tag == 24) {
- parse_deprecated:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(24u)) {
+ 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;
}
- if (input->ExpectTag(40)) goto parse_lazy;
break;
}
// optional bool lazy = 5 [default = false];
case 5: {
- if (tag == 40) {
- parse_lazy:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(40u)) {
+ 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;
}
- if (input->ExpectTag(48)) goto parse_jstype;
break;
}
// optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];
case 6: {
- if (tag == 48) {
- parse_jstype:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(48u)) {
int value;
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(
@@ -10292,39 +10461,34 @@ bool FieldOptions::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(80)) goto parse_weak;
break;
}
// optional bool weak = 10 [default = false];
case 10: {
- if (tag == 80) {
- parse_weak:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(80u)) {
+ 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;
}
- if (input->ExpectTag(7994)) goto parse_uninterpreted_option;
break;
}
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
case 999: {
- if (tag == 7994) {
- parse_uninterpreted_option:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(7994u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_uninterpreted_option:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_uninterpreted_option()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(7994)) goto parse_loop_uninterpreted_option;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -10336,7 +10500,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;
}
@@ -10409,6 +10573,7 @@ void FieldOptions::SerializeWithCachedSizes(
::google::protobuf::uint8* FieldOptions::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldOptions)
// optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];
if (has_ctype()) {
@@ -10451,7 +10616,7 @@ void FieldOptions::SerializeWithCachedSizes(
// Extension range [1000, 536870912)
target = _extensions_.InternalSerializeWithCachedSizesToArray(
- 1000, 536870912, false, target);
+ 1000, 536870912, deterministic, target);
if (_internal_metadata_.have_unknown_fields()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
@@ -10461,9 +10626,27 @@ 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;
+
+ total_size += _extensions_.ByteSize();
+
+ if (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
+ // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
+ {
+ 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));
+ }
+ }
if (_has_bits_[0 / 32] & 63u) {
// optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];
@@ -10472,17 +10655,17 @@ int FieldOptions::ByteSize() const {
::google::protobuf::internal::WireFormatLite::EnumSize(this->ctype());
}
- // optional bool packed = 2;
- if (has_packed()) {
- total_size += 1 + 1;
- }
-
// optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];
if (has_jstype()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::EnumSize(this->jstype());
}
+ // optional bool packed = 2;
+ if (has_packed()) {
+ total_size += 1 + 1;
+ }
+
// optional bool lazy = 5 [default = false];
if (has_lazy()) {
total_size += 1 + 1;
@@ -10499,33 +10682,17 @@ 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));
- }
-
- total_size += _extensions_.ByteSize();
-
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const FieldOptions* source =
::google::protobuf::internal::DynamicCastToGenerated<const FieldOptions>(
&from);
if (source == NULL) {
@@ -10539,20 +10706,20 @@ void FieldOptions::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _extensions_.MergeFrom(from._extensions_);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
uninterpreted_option_.MergeFrom(from.uninterpreted_option_);
- if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+ if (from._has_bits_[0 / 32] & 63u) {
if (from.has_ctype()) {
set_ctype(from.ctype());
}
- if (from.has_packed()) {
- set_packed(from.packed());
- }
if (from.has_jstype()) {
set_jstype(from.jstype());
}
+ if (from.has_packed()) {
+ set_packed(from.packed());
+ }
if (from.has_lazy()) {
set_lazy(from.lazy());
}
@@ -10563,10 +10730,6 @@ void FieldOptions::MergeFrom(const FieldOptions& from) {
set_weak(from.weak());
}
}
- _extensions_.MergeFrom(from._extensions_);
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void FieldOptions::CopyFrom(const ::google::protobuf::Message& from) {
@@ -10584,10 +10747,12 @@ void FieldOptions::CopyFrom(const FieldOptions& from) {
}
bool FieldOptions::IsInitialized() const {
+ if (!_extensions_.IsInitialized()) {
+ return false;
+ }
if (!::google::protobuf::internal::AllAreInitialized(this->uninterpreted_option())) return false;
-
- if (!_extensions_.IsInitialized()) return false; return true;
+ return true;
}
void FieldOptions::Swap(FieldOptions* other) {
@@ -10595,13 +10760,13 @@ void FieldOptions::Swap(FieldOptions* other) {
InternalSwap(other);
}
void FieldOptions::InternalSwap(FieldOptions* other) {
+ uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_);
std::swap(ctype_, other->ctype_);
- std::swap(packed_, other->packed_);
std::swap(jstype_, other->jstype_);
+ std::swap(packed_, other->packed_);
std::swap(lazy_, other->lazy_);
std::swap(deprecated_, other->deprecated_);
std::swap(weak_, other->weak_);
- uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
@@ -10609,11 +10774,8 @@ void FieldOptions::InternalSwap(FieldOptions* other) {
}
::google::protobuf::Metadata FieldOptions::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = FieldOptions_descriptor_;
- metadata.reflection = FieldOptions_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[13];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -10633,11 +10795,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;
@@ -10646,23 +10808,23 @@ void FieldOptions::clear_ctype() {
// optional bool packed = 2;
bool FieldOptions::has_packed() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
+ return (_has_bits_[0] & 0x00000004u) != 0;
}
void FieldOptions::set_has_packed() {
- _has_bits_[0] |= 0x00000002u;
+ _has_bits_[0] |= 0x00000004u;
}
void FieldOptions::clear_has_packed() {
- _has_bits_[0] &= ~0x00000002u;
+ _has_bits_[0] &= ~0x00000004u;
}
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)
@@ -10670,23 +10832,23 @@ void FieldOptions::clear_packed() {
// optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];
bool FieldOptions::has_jstype() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
+ return (_has_bits_[0] & 0x00000002u) != 0;
}
void FieldOptions::set_has_jstype() {
- _has_bits_[0] |= 0x00000004u;
+ _has_bits_[0] |= 0x00000002u;
}
void FieldOptions::clear_has_jstype() {
- _has_bits_[0] &= ~0x00000004u;
+ _has_bits_[0] &= ~0x00000002u;
}
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;
@@ -10707,11 +10869,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)
@@ -10731,11 +10893,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)
@@ -10755,11 +10917,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)
@@ -10805,24 +10967,25 @@ const int OneofOptions::kUninterpretedOptionFieldNumber;
OneofOptions::OneofOptions()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.OneofOptions)
}
-
-void OneofOptions::InitAsDefaultInstance() {
-}
-
OneofOptions::OneofOptions(const OneofOptions& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ uninterpreted_option_(from.uninterpreted_option_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ _extensions_.MergeFrom(from._extensions_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.OneofOptions)
}
void OneofOptions::SharedCtor() {
_cached_size_ = 0;
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
}
OneofOptions::~OneofOptions() {
@@ -10831,8 +10994,6 @@ OneofOptions::~OneofOptions() {
}
void OneofOptions::SharedDtor() {
- if (this != default_instance_) {
- }
}
void OneofOptions::SetCachedSize(int size) const {
@@ -10841,17 +11002,15 @@ void OneofOptions::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* OneofOptions::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return OneofOptions_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[14].descriptor;
}
const OneofOptions& OneofOptions::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-OneofOptions* OneofOptions::default_instance_ = NULL;
-
OneofOptions* OneofOptions::New(::google::protobuf::Arena* arena) const {
OneofOptions* n = new OneofOptions;
if (arena != NULL) {
@@ -10864,10 +11023,8 @@ void OneofOptions::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.OneofOptions)
_extensions_.Clear();
uninterpreted_option_.Clear();
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
- }
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool OneofOptions::MergePartialFromCodedStream(
@@ -10876,23 +11033,21 @@ bool OneofOptions::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.OneofOptions)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(16383);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(16383u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
case 999: {
- if (tag == 7994) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(7994u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_uninterpreted_option:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_uninterpreted_option()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(7994)) goto parse_loop_uninterpreted_option;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -10904,7 +11059,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;
}
@@ -10945,6 +11100,7 @@ void OneofOptions::SerializeWithCachedSizes(
::google::protobuf::uint8* OneofOptions::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.OneofOptions)
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
for (unsigned int i = 0, n = this->uninterpreted_option_size(); i < n; i++) {
@@ -10955,7 +11111,7 @@ void OneofOptions::SerializeWithCachedSizes(
// Extension range [1000, 536870912)
target = _extensions_.InternalSerializeWithCachedSizesToArray(
- 1000, 536870912, false, target);
+ 1000, 536870912, deterministic, target);
if (_internal_metadata_.have_unknown_fields()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
@@ -10965,17 +11121,9 @@ 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;
-
- // 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));
- }
+ size_t total_size = 0;
total_size += _extensions_.ByteSize();
@@ -10984,18 +11132,28 @@ int OneofOptions::ByteSize() const {
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
unknown_fields());
}
+ // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
+ {
+ 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));
+ }
+ }
+
+ 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const OneofOptions* source =
::google::protobuf::internal::DynamicCastToGenerated<const OneofOptions>(
&from);
if (source == NULL) {
@@ -11009,14 +11167,10 @@ void OneofOptions::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
- uninterpreted_option_.MergeFrom(from.uninterpreted_option_);
+ GOOGLE_DCHECK_NE(&from, this);
_extensions_.MergeFrom(from._extensions_);
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ uninterpreted_option_.MergeFrom(from.uninterpreted_option_);
}
void OneofOptions::CopyFrom(const ::google::protobuf::Message& from) {
@@ -11034,10 +11188,12 @@ void OneofOptions::CopyFrom(const OneofOptions& from) {
}
bool OneofOptions::IsInitialized() const {
+ if (!_extensions_.IsInitialized()) {
+ return false;
+ }
if (!::google::protobuf::internal::AllAreInitialized(this->uninterpreted_option())) return false;
-
- if (!_extensions_.IsInitialized()) return false; return true;
+ return true;
}
void OneofOptions::Swap(OneofOptions* other) {
@@ -11053,11 +11209,8 @@ void OneofOptions::InternalSwap(OneofOptions* other) {
}
::google::protobuf::Metadata OneofOptions::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = OneofOptions_descriptor_;
- metadata.reflection = OneofOptions_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[14];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -11105,26 +11258,30 @@ const int EnumOptions::kUninterpretedOptionFieldNumber;
EnumOptions::EnumOptions()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.EnumOptions)
}
-
-void EnumOptions::InitAsDefaultInstance() {
-}
-
EnumOptions::EnumOptions(const EnumOptions& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ uninterpreted_option_(from.uninterpreted_option_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ _extensions_.MergeFrom(from._extensions_);
+ ::memcpy(&allow_alias_, &from.allow_alias_,
+ reinterpret_cast<char*>(&deprecated_) -
+ reinterpret_cast<char*>(&allow_alias_) + sizeof(deprecated_));
// @@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<char*>(&deprecated_) -
+ reinterpret_cast<char*>(&allow_alias_) + sizeof(deprecated_));
}
EnumOptions::~EnumOptions() {
@@ -11133,8 +11290,6 @@ EnumOptions::~EnumOptions() {
}
void EnumOptions::SharedDtor() {
- if (this != default_instance_) {
- }
}
void EnumOptions::SetCachedSize(int size) const {
@@ -11143,17 +11298,15 @@ void EnumOptions::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* EnumOptions::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return EnumOptions_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[15].descriptor;
}
const EnumOptions& EnumOptions::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-EnumOptions* EnumOptions::default_instance_ = NULL;
-
EnumOptions* EnumOptions::New(::google::protobuf::Arena* arena) const {
EnumOptions* n = new EnumOptions;
if (arena != NULL) {
@@ -11165,32 +11318,13 @@ EnumOptions* EnumOptions::New(::google::protobuf::Arena* arena) const {
void EnumOptions::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.EnumOptions)
_extensions_.Clear();
-#if defined(__clang__)
-#define ZR_HELPER_(f) \
- _Pragma("clang diagnostic push") \
- _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
- __builtin_offsetof(EnumOptions, f) \
- _Pragma("clang diagnostic pop")
-#else
-#define ZR_HELPER_(f) reinterpret_cast<char*>(\
- &reinterpret_cast<EnumOptions*>(16)->f)
-#endif
-
-#define ZR_(first, last) do {\
- ::memset(&first, 0,\
- ZR_HELPER_(last) - ZR_HELPER_(first) + sizeof(last));\
-} while (0)
-
- ZR_(allow_alias_, deprecated_);
-
-#undef ZR_HELPER_
-#undef ZR_
-
uninterpreted_option_.Clear();
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
+ if (_has_bits_[0 / 32] & 3u) {
+ ::memset(&allow_alias_, 0, reinterpret_cast<char*>(&deprecated_) -
+ reinterpret_cast<char*>(&allow_alias_) + sizeof(deprecated_));
}
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool EnumOptions::MergePartialFromCodedStream(
@@ -11199,53 +11333,49 @@ bool EnumOptions::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.EnumOptions)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(16383);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(16383u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional bool allow_alias = 2;
case 2: {
- if (tag == 16) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(16u)) {
+ 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;
}
- if (input->ExpectTag(24)) goto parse_deprecated;
break;
}
// optional bool deprecated = 3 [default = false];
case 3: {
- if (tag == 24) {
- parse_deprecated:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(24u)) {
+ 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;
}
- if (input->ExpectTag(7994)) goto parse_uninterpreted_option;
break;
}
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
case 999: {
- if (tag == 7994) {
- parse_uninterpreted_option:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(7994u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_uninterpreted_option:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_uninterpreted_option()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(7994)) goto parse_loop_uninterpreted_option;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -11257,7 +11387,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;
}
@@ -11308,6 +11438,7 @@ void EnumOptions::SerializeWithCachedSizes(
::google::protobuf::uint8* EnumOptions::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumOptions)
// optional bool allow_alias = 2;
if (has_allow_alias()) {
@@ -11328,7 +11459,7 @@ void EnumOptions::SerializeWithCachedSizes(
// Extension range [1000, 536870912)
target = _extensions_.InternalSerializeWithCachedSizesToArray(
- 1000, 536870912, false, target);
+ 1000, 536870912, deterministic, target);
if (_internal_metadata_.have_unknown_fields()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
@@ -11338,9 +11469,27 @@ 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;
+
+ total_size += _extensions_.ByteSize();
+
+ if (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
+ // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
+ {
+ 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));
+ }
+ }
if (_has_bits_[0 / 32] & 3u) {
// optional bool allow_alias = 2;
@@ -11354,33 +11503,17 @@ 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));
- }
-
- total_size += _extensions_.ByteSize();
-
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const EnumOptions* source =
::google::protobuf::internal::DynamicCastToGenerated<const EnumOptions>(
&from);
if (source == NULL) {
@@ -11394,11 +11527,11 @@ void EnumOptions::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _extensions_.MergeFrom(from._extensions_);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
uninterpreted_option_.MergeFrom(from.uninterpreted_option_);
- if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+ if (from._has_bits_[0 / 32] & 3u) {
if (from.has_allow_alias()) {
set_allow_alias(from.allow_alias());
}
@@ -11406,10 +11539,6 @@ void EnumOptions::MergeFrom(const EnumOptions& from) {
set_deprecated(from.deprecated());
}
}
- _extensions_.MergeFrom(from._extensions_);
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void EnumOptions::CopyFrom(const ::google::protobuf::Message& from) {
@@ -11427,10 +11556,12 @@ void EnumOptions::CopyFrom(const EnumOptions& from) {
}
bool EnumOptions::IsInitialized() const {
+ if (!_extensions_.IsInitialized()) {
+ return false;
+ }
if (!::google::protobuf::internal::AllAreInitialized(this->uninterpreted_option())) return false;
-
- if (!_extensions_.IsInitialized()) return false; return true;
+ return true;
}
void EnumOptions::Swap(EnumOptions* other) {
@@ -11438,9 +11569,9 @@ void EnumOptions::Swap(EnumOptions* other) {
InternalSwap(other);
}
void EnumOptions::InternalSwap(EnumOptions* other) {
+ uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_);
std::swap(allow_alias_, other->allow_alias_);
std::swap(deprecated_, other->deprecated_);
- uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
@@ -11448,11 +11579,8 @@ void EnumOptions::InternalSwap(EnumOptions* other) {
}
::google::protobuf::Metadata EnumOptions::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = EnumOptions_descriptor_;
- metadata.reflection = EnumOptions_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[15];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -11472,11 +11600,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)
@@ -11496,11 +11624,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)
@@ -11547,25 +11675,27 @@ const int EnumValueOptions::kUninterpretedOptionFieldNumber;
EnumValueOptions::EnumValueOptions()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.EnumValueOptions)
}
-
-void EnumValueOptions::InitAsDefaultInstance() {
-}
-
EnumValueOptions::EnumValueOptions(const EnumValueOptions& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ uninterpreted_option_(from.uninterpreted_option_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ _extensions_.MergeFrom(from._extensions_);
+ deprecated_ = from.deprecated_;
// @@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() {
@@ -11574,8 +11704,6 @@ EnumValueOptions::~EnumValueOptions() {
}
void EnumValueOptions::SharedDtor() {
- if (this != default_instance_) {
- }
}
void EnumValueOptions::SetCachedSize(int size) const {
@@ -11584,17 +11712,15 @@ void EnumValueOptions::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* EnumValueOptions::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return EnumValueOptions_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[16].descriptor;
}
const EnumValueOptions& EnumValueOptions::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-EnumValueOptions* EnumValueOptions::default_instance_ = NULL;
-
EnumValueOptions* EnumValueOptions::New(::google::protobuf::Arena* arena) const {
EnumValueOptions* n = new EnumValueOptions;
if (arena != NULL) {
@@ -11606,12 +11732,10 @@ EnumValueOptions* EnumValueOptions::New(::google::protobuf::Arena* arena) const
void EnumValueOptions::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.EnumValueOptions)
_extensions_.Clear();
- deprecated_ = false;
uninterpreted_option_.Clear();
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
- }
+ deprecated_ = false;
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool EnumValueOptions::MergePartialFromCodedStream(
@@ -11620,38 +11744,35 @@ bool EnumValueOptions::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.EnumValueOptions)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(16383);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(16383u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional bool deprecated = 1 [default = false];
case 1: {
- if (tag == 8) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(8u)) {
+ 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;
}
- if (input->ExpectTag(7994)) goto parse_uninterpreted_option;
break;
}
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
case 999: {
- if (tag == 7994) {
- parse_uninterpreted_option:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(7994u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_uninterpreted_option:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_uninterpreted_option()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(7994)) goto parse_loop_uninterpreted_option;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -11663,7 +11784,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;
}
@@ -11709,6 +11830,7 @@ void EnumValueOptions::SerializeWithCachedSizes(
::google::protobuf::uint8* EnumValueOptions::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumValueOptions)
// optional bool deprecated = 1 [default = false];
if (has_deprecated()) {
@@ -11724,7 +11846,7 @@ void EnumValueOptions::SerializeWithCachedSizes(
// Extension range [1000, 536870912)
target = _extensions_.InternalSerializeWithCachedSizesToArray(
- 1000, 536870912, false, target);
+ 1000, 536870912, deterministic, target);
if (_internal_metadata_.have_unknown_fields()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
@@ -11734,22 +11856,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;
-
- // optional bool deprecated = 1 [default = false];
- if (has_deprecated()) {
- total_size += 1 + 1;
- }
-
- // 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));
- }
+ size_t total_size = 0;
total_size += _extensions_.ByteSize();
@@ -11758,18 +11867,33 @@ int EnumValueOptions::ByteSize() const {
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
unknown_fields());
}
+ // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
+ {
+ 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));
+ }
+ }
+
+ // optional bool deprecated = 1 [default = false];
+ if (has_deprecated()) {
+ total_size += 1 + 1;
+ }
+
+ 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const EnumValueOptions* source =
::google::protobuf::internal::DynamicCastToGenerated<const EnumValueOptions>(
&from);
if (source == NULL) {
@@ -11783,18 +11907,12 @@ void EnumValueOptions::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
- uninterpreted_option_.MergeFrom(from.uninterpreted_option_);
- if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
- if (from.has_deprecated()) {
- set_deprecated(from.deprecated());
- }
- }
+ GOOGLE_DCHECK_NE(&from, this);
_extensions_.MergeFrom(from._extensions_);
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ uninterpreted_option_.MergeFrom(from.uninterpreted_option_);
+ if (from.has_deprecated()) {
+ set_deprecated(from.deprecated());
}
}
@@ -11813,10 +11931,12 @@ void EnumValueOptions::CopyFrom(const EnumValueOptions& from) {
}
bool EnumValueOptions::IsInitialized() const {
+ if (!_extensions_.IsInitialized()) {
+ return false;
+ }
if (!::google::protobuf::internal::AllAreInitialized(this->uninterpreted_option())) return false;
-
- if (!_extensions_.IsInitialized()) return false; return true;
+ return true;
}
void EnumValueOptions::Swap(EnumValueOptions* other) {
@@ -11824,8 +11944,8 @@ void EnumValueOptions::Swap(EnumValueOptions* other) {
InternalSwap(other);
}
void EnumValueOptions::InternalSwap(EnumValueOptions* other) {
- std::swap(deprecated_, other->deprecated_);
uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_);
+ std::swap(deprecated_, other->deprecated_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
@@ -11833,11 +11953,8 @@ void EnumValueOptions::InternalSwap(EnumValueOptions* other) {
}
::google::protobuf::Metadata EnumValueOptions::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = EnumValueOptions_descriptor_;
- metadata.reflection = EnumValueOptions_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[16];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -11857,11 +11974,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)
@@ -11908,25 +12025,27 @@ const int ServiceOptions::kUninterpretedOptionFieldNumber;
ServiceOptions::ServiceOptions()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.ServiceOptions)
}
-
-void ServiceOptions::InitAsDefaultInstance() {
-}
-
ServiceOptions::ServiceOptions(const ServiceOptions& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ uninterpreted_option_(from.uninterpreted_option_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ _extensions_.MergeFrom(from._extensions_);
+ deprecated_ = from.deprecated_;
// @@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() {
@@ -11935,8 +12054,6 @@ ServiceOptions::~ServiceOptions() {
}
void ServiceOptions::SharedDtor() {
- if (this != default_instance_) {
- }
}
void ServiceOptions::SetCachedSize(int size) const {
@@ -11945,17 +12062,15 @@ void ServiceOptions::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* ServiceOptions::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return ServiceOptions_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[17].descriptor;
}
const ServiceOptions& ServiceOptions::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-ServiceOptions* ServiceOptions::default_instance_ = NULL;
-
ServiceOptions* ServiceOptions::New(::google::protobuf::Arena* arena) const {
ServiceOptions* n = new ServiceOptions;
if (arena != NULL) {
@@ -11967,12 +12082,10 @@ ServiceOptions* ServiceOptions::New(::google::protobuf::Arena* arena) const {
void ServiceOptions::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.ServiceOptions)
_extensions_.Clear();
- deprecated_ = false;
uninterpreted_option_.Clear();
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
- }
+ deprecated_ = false;
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool ServiceOptions::MergePartialFromCodedStream(
@@ -11981,38 +12094,35 @@ bool ServiceOptions::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.ServiceOptions)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(16383);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(16383u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional bool deprecated = 33 [default = false];
case 33: {
- if (tag == 264) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(264u)) {
+ 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;
}
- if (input->ExpectTag(7994)) goto parse_uninterpreted_option;
break;
}
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
case 999: {
- if (tag == 7994) {
- parse_uninterpreted_option:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(7994u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_uninterpreted_option:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_uninterpreted_option()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(7994)) goto parse_loop_uninterpreted_option;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -12024,7 +12134,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;
}
@@ -12070,6 +12180,7 @@ void ServiceOptions::SerializeWithCachedSizes(
::google::protobuf::uint8* ServiceOptions::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ServiceOptions)
// optional bool deprecated = 33 [default = false];
if (has_deprecated()) {
@@ -12085,7 +12196,7 @@ void ServiceOptions::SerializeWithCachedSizes(
// Extension range [1000, 536870912)
target = _extensions_.InternalSerializeWithCachedSizesToArray(
- 1000, 536870912, false, target);
+ 1000, 536870912, deterministic, target);
if (_internal_metadata_.have_unknown_fields()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
@@ -12095,22 +12206,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;
-
- // optional bool deprecated = 33 [default = false];
- if (has_deprecated()) {
- total_size += 2 + 1;
- }
-
- // 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));
- }
+ size_t total_size = 0;
total_size += _extensions_.ByteSize();
@@ -12119,18 +12217,33 @@ int ServiceOptions::ByteSize() const {
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
unknown_fields());
}
+ // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
+ {
+ 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));
+ }
+ }
+
+ // optional bool deprecated = 33 [default = false];
+ if (has_deprecated()) {
+ total_size += 2 + 1;
+ }
+
+ 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const ServiceOptions* source =
::google::protobuf::internal::DynamicCastToGenerated<const ServiceOptions>(
&from);
if (source == NULL) {
@@ -12144,18 +12257,12 @@ void ServiceOptions::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
- uninterpreted_option_.MergeFrom(from.uninterpreted_option_);
- if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
- if (from.has_deprecated()) {
- set_deprecated(from.deprecated());
- }
- }
+ GOOGLE_DCHECK_NE(&from, this);
_extensions_.MergeFrom(from._extensions_);
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ uninterpreted_option_.MergeFrom(from.uninterpreted_option_);
+ if (from.has_deprecated()) {
+ set_deprecated(from.deprecated());
}
}
@@ -12174,10 +12281,12 @@ void ServiceOptions::CopyFrom(const ServiceOptions& from) {
}
bool ServiceOptions::IsInitialized() const {
+ if (!_extensions_.IsInitialized()) {
+ return false;
+ }
if (!::google::protobuf::internal::AllAreInitialized(this->uninterpreted_option())) return false;
-
- if (!_extensions_.IsInitialized()) return false; return true;
+ return true;
}
void ServiceOptions::Swap(ServiceOptions* other) {
@@ -12185,8 +12294,8 @@ void ServiceOptions::Swap(ServiceOptions* other) {
InternalSwap(other);
}
void ServiceOptions::InternalSwap(ServiceOptions* other) {
- std::swap(deprecated_, other->deprecated_);
uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_);
+ std::swap(deprecated_, other->deprecated_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
@@ -12194,11 +12303,8 @@ void ServiceOptions::InternalSwap(ServiceOptions* other) {
}
::google::protobuf::Metadata ServiceOptions::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = ServiceOptions_descriptor_;
- metadata.reflection = ServiceOptions_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[17];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -12218,11 +12324,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)
@@ -12264,30 +12370,36 @@ ServiceOptions::uninterpreted_option() const {
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int MethodOptions::kDeprecatedFieldNumber;
+const int MethodOptions::kIdempotencyLevelFieldNumber;
const int MethodOptions::kUninterpretedOptionFieldNumber;
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
MethodOptions::MethodOptions()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.MethodOptions)
}
-
-void MethodOptions::InitAsDefaultInstance() {
-}
-
MethodOptions::MethodOptions(const MethodOptions& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ uninterpreted_option_(from.uninterpreted_option_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ _extensions_.MergeFrom(from._extensions_);
+ ::memcpy(&deprecated_, &from.deprecated_,
+ reinterpret_cast<char*>(&idempotency_level_) -
+ reinterpret_cast<char*>(&deprecated_) + sizeof(idempotency_level_));
// @@protoc_insertion_point(copy_constructor:google.protobuf.MethodOptions)
}
void MethodOptions::SharedCtor() {
_cached_size_ = 0;
- deprecated_ = false;
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
+ ::memset(&deprecated_, 0, reinterpret_cast<char*>(&idempotency_level_) -
+ reinterpret_cast<char*>(&deprecated_) + sizeof(idempotency_level_));
}
MethodOptions::~MethodOptions() {
@@ -12296,8 +12408,6 @@ MethodOptions::~MethodOptions() {
}
void MethodOptions::SharedDtor() {
- if (this != default_instance_) {
- }
}
void MethodOptions::SetCachedSize(int size) const {
@@ -12306,17 +12416,15 @@ void MethodOptions::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* MethodOptions::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return MethodOptions_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[18].descriptor;
}
const MethodOptions& MethodOptions::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-MethodOptions* MethodOptions::default_instance_ = NULL;
-
MethodOptions* MethodOptions::New(::google::protobuf::Arena* arena) const {
MethodOptions* n = new MethodOptions;
if (arena != NULL) {
@@ -12328,12 +12436,13 @@ MethodOptions* MethodOptions::New(::google::protobuf::Arena* arena) const {
void MethodOptions::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.MethodOptions)
_extensions_.Clear();
- deprecated_ = false;
uninterpreted_option_.Clear();
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
+ if (_has_bits_[0 / 32] & 3u) {
+ ::memset(&deprecated_, 0, reinterpret_cast<char*>(&idempotency_level_) -
+ reinterpret_cast<char*>(&deprecated_) + sizeof(idempotency_level_));
}
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool MethodOptions::MergePartialFromCodedStream(
@@ -12342,38 +12451,54 @@ bool MethodOptions::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.MethodOptions)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(16383);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(16383u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// optional bool deprecated = 33 [default = false];
case 33: {
- if (tag == 264) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(264u)) {
+ 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;
}
- if (input->ExpectTag(7994)) goto parse_uninterpreted_option;
+ break;
+ }
+
+ // optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN];
+ case 34: {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(272u)) {
+ int value;
+ DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
+ int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(
+ input, &value)));
+ if (::google::protobuf::MethodOptions_IdempotencyLevel_IsValid(value)) {
+ set_idempotency_level(static_cast< ::google::protobuf::MethodOptions_IdempotencyLevel >(value));
+ } else {
+ mutable_unknown_fields()->AddVarint(34, value);
+ }
+ } else {
+ goto handle_unusual;
+ }
break;
}
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
case 999: {
- if (tag == 7994) {
- parse_uninterpreted_option:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(7994u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_uninterpreted_option:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_uninterpreted_option()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(7994)) goto parse_loop_uninterpreted_option;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -12385,7 +12510,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;
}
@@ -12412,6 +12537,12 @@ void MethodOptions::SerializeWithCachedSizes(
::google::protobuf::internal::WireFormatLite::WriteBool(33, this->deprecated(), output);
}
+ // optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN];
+ if (has_idempotency_level()) {
+ ::google::protobuf::internal::WireFormatLite::WriteEnum(
+ 34, this->idempotency_level(), output);
+ }
+
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
for (unsigned int i = 0, n = this->uninterpreted_option_size(); i < n; i++) {
::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
@@ -12431,12 +12562,19 @@ void MethodOptions::SerializeWithCachedSizes(
::google::protobuf::uint8* MethodOptions::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.MethodOptions)
// optional bool deprecated = 33 [default = false];
if (has_deprecated()) {
target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(33, this->deprecated(), target);
}
+ // optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN];
+ if (has_idempotency_level()) {
+ target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray(
+ 34, this->idempotency_level(), target);
+ }
+
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
for (unsigned int i = 0, n = this->uninterpreted_option_size(); i < n; i++) {
target = ::google::protobuf::internal::WireFormatLite::
@@ -12446,7 +12584,7 @@ void MethodOptions::SerializeWithCachedSizes(
// Extension range [1000, 536870912)
target = _extensions_.InternalSerializeWithCachedSizesToArray(
- 1000, 536870912, false, target);
+ 1000, 536870912, deterministic, target);
if (_internal_metadata_.have_unknown_fields()) {
target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
@@ -12456,22 +12594,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;
-
- // optional bool deprecated = 33 [default = false];
- if (has_deprecated()) {
- total_size += 2 + 1;
- }
-
- // 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));
- }
+ size_t total_size = 0;
total_size += _extensions_.ByteSize();
@@ -12480,18 +12605,41 @@ int MethodOptions::ByteSize() const {
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
unknown_fields());
}
+ // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
+ {
+ 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));
+ }
+ }
+
+ if (_has_bits_[0 / 32] & 3u) {
+ // optional bool deprecated = 33 [default = false];
+ if (has_deprecated()) {
+ total_size += 2 + 1;
+ }
+
+ // optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN];
+ if (has_idempotency_level()) {
+ total_size += 2 +
+ ::google::protobuf::internal::WireFormatLite::EnumSize(this->idempotency_level());
+ }
+
+ }
+ 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const MethodOptions* source =
::google::protobuf::internal::DynamicCastToGenerated<const MethodOptions>(
&from);
if (source == NULL) {
@@ -12505,18 +12653,17 @@ void MethodOptions::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _extensions_.MergeFrom(from._extensions_);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
uninterpreted_option_.MergeFrom(from.uninterpreted_option_);
- if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+ if (from._has_bits_[0 / 32] & 3u) {
if (from.has_deprecated()) {
set_deprecated(from.deprecated());
}
- }
- _extensions_.MergeFrom(from._extensions_);
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
+ if (from.has_idempotency_level()) {
+ set_idempotency_level(from.idempotency_level());
+ }
}
}
@@ -12535,10 +12682,12 @@ void MethodOptions::CopyFrom(const MethodOptions& from) {
}
bool MethodOptions::IsInitialized() const {
+ if (!_extensions_.IsInitialized()) {
+ return false;
+ }
if (!::google::protobuf::internal::AllAreInitialized(this->uninterpreted_option())) return false;
-
- if (!_extensions_.IsInitialized()) return false; return true;
+ return true;
}
void MethodOptions::Swap(MethodOptions* other) {
@@ -12546,8 +12695,9 @@ void MethodOptions::Swap(MethodOptions* other) {
InternalSwap(other);
}
void MethodOptions::InternalSwap(MethodOptions* other) {
- std::swap(deprecated_, other->deprecated_);
uninterpreted_option_.UnsafeArenaSwap(&other->uninterpreted_option_);
+ std::swap(deprecated_, other->deprecated_);
+ std::swap(idempotency_level_, other->idempotency_level_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
@@ -12555,11 +12705,8 @@ void MethodOptions::InternalSwap(MethodOptions* other) {
}
::google::protobuf::Metadata MethodOptions::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = MethodOptions_descriptor_;
- metadata.reflection = MethodOptions_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[18];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -12579,16 +12726,41 @@ 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)
}
+// optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN];
+bool MethodOptions::has_idempotency_level() const {
+ return (_has_bits_[0] & 0x00000002u) != 0;
+}
+void MethodOptions::set_has_idempotency_level() {
+ _has_bits_[0] |= 0x00000002u;
+}
+void MethodOptions::clear_has_idempotency_level() {
+ _has_bits_[0] &= ~0x00000002u;
+}
+void MethodOptions::clear_idempotency_level() {
+ idempotency_level_ = 0;
+ clear_has_idempotency_level();
+}
+::google::protobuf::MethodOptions_IdempotencyLevel MethodOptions::idempotency_level() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.MethodOptions.idempotency_level)
+ return static_cast< ::google::protobuf::MethodOptions_IdempotencyLevel >(idempotency_level_);
+}
+void MethodOptions::set_idempotency_level(::google::protobuf::MethodOptions_IdempotencyLevel value) {
+ assert(::google::protobuf::MethodOptions_IdempotencyLevel_IsValid(value));
+ set_has_idempotency_level();
+ idempotency_level_ = value;
+ // @@protoc_insertion_point(field_set:google.protobuf.MethodOptions.idempotency_level)
+}
+
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
int MethodOptions::uninterpreted_option_size() const {
return uninterpreted_option_.size();
@@ -12630,27 +12802,30 @@ const int UninterpretedOption_NamePart::kIsExtensionFieldNumber;
UninterpretedOption_NamePart::UninterpretedOption_NamePart()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.UninterpretedOption.NamePart)
}
-
-void UninterpretedOption_NamePart::InitAsDefaultInstance() {
-}
-
UninterpretedOption_NamePart::UninterpretedOption_NamePart(const UninterpretedOption_NamePart& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_part_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_name_part()) {
+ name_part_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_part_);
+ }
+ is_extension_ = from.is_extension_;
// @@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() {
@@ -12660,8 +12835,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 {
@@ -12670,17 +12843,15 @@ void UninterpretedOption_NamePart::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* UninterpretedOption_NamePart::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return UninterpretedOption_NamePart_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[19].descriptor;
}
const UninterpretedOption_NamePart& UninterpretedOption_NamePart::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-UninterpretedOption_NamePart* UninterpretedOption_NamePart::default_instance_ = NULL;
-
UninterpretedOption_NamePart* UninterpretedOption_NamePart::New(::google::protobuf::Arena* arena) const {
UninterpretedOption_NamePart* n = new UninterpretedOption_NamePart;
if (arena != NULL) {
@@ -12691,16 +12862,13 @@ UninterpretedOption_NamePart* UninterpretedOption_NamePart::New(::google::protob
void UninterpretedOption_NamePart::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.UninterpretedOption.NamePart)
- if (_has_bits_[0 / 32] & 3u) {
- if (has_name_part()) {
- name_part_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- }
- is_extension_ = false;
- }
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
+ if (has_name_part()) {
+ GOOGLE_DCHECK(!name_part_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*name_part_.UnsafeRawStringPointer())->clear();
}
+ is_extension_ = false;
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool UninterpretedOption_NamePart::MergePartialFromCodedStream(
@@ -12709,13 +12877,14 @@ bool UninterpretedOption_NamePart::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.UninterpretedOption.NamePart)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// required string name_part = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name_part()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -12725,22 +12894,20 @@ bool UninterpretedOption_NamePart::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(16)) goto parse_is_extension;
break;
}
// required bool is_extension = 2;
case 2: {
- if (tag == 16) {
- parse_is_extension:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(16u)) {
+ 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;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -12793,6 +12960,7 @@ void UninterpretedOption_NamePart::SerializeWithCachedSizes(
::google::protobuf::uint8* UninterpretedOption_NamePart::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UninterpretedOption.NamePart)
// required string name_part = 1;
if (has_name_part()) {
@@ -12818,9 +12986,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;
@@ -12836,10 +13004,15 @@ 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 (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
if (((_has_bits_[0] & 0x00000003) ^ 0x00000003) == 0) { // All required fields are present.
// required string name_part = 1;
total_size += 1 +
@@ -12852,23 +13025,17 @@ int UninterpretedOption_NamePart::ByteSize() const {
} else {
total_size += RequiredFieldsByteSizeFallback();
}
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const UninterpretedOption_NamePart* source =
::google::protobuf::internal::DynamicCastToGenerated<const UninterpretedOption_NamePart>(
&from);
if (source == NULL) {
@@ -12882,10 +13049,9 @@ void UninterpretedOption_NamePart::MergeFrom(const ::google::protobuf::Message&
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 (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) {
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ if (from._has_bits_[0 / 32] & 3u) {
if (from.has_name_part()) {
set_has_name_part();
name_part_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_part_);
@@ -12894,9 +13060,6 @@ void UninterpretedOption_NamePart::MergeFrom(const UninterpretedOption_NamePart&
set_is_extension(from.is_extension());
}
}
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void UninterpretedOption_NamePart::CopyFrom(const ::google::protobuf::Message& from) {
@@ -12915,7 +13078,6 @@ void UninterpretedOption_NamePart::CopyFrom(const UninterpretedOption_NamePart&
bool UninterpretedOption_NamePart::IsInitialized() const {
if ((_has_bits_[0] & 0x00000003) != 0x00000003) return false;
-
return true;
}
@@ -12932,15 +13094,102 @@ void UninterpretedOption_NamePart::InternalSwap(UninterpretedOption_NamePart* ot
}
::google::protobuf::Metadata UninterpretedOption_NamePart::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = UninterpretedOption_NamePart_descriptor_;
- metadata.reflection = UninterpretedOption_NamePart_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[19];
+}
+
+#if PROTOBUF_INLINE_NOT_IN_HEADERS
+// UninterpretedOption_NamePart
+
+// required string name_part = 1;
+bool UninterpretedOption_NamePart::has_name_part() const {
+ return (_has_bits_[0] & 0x00000001u) != 0;
+}
+void UninterpretedOption_NamePart::set_has_name_part() {
+ _has_bits_[0] |= 0x00000001u;
+}
+void UninterpretedOption_NamePart::clear_has_name_part() {
+ _has_bits_[0] &= ~0x00000001u;
+}
+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 {
+ // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.NamePart.name_part)
+ return name_part_.GetNoArena();
+}
+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)
+}
+#if LANG_CXX11
+void UninterpretedOption_NamePart::set_name_part(::std::string&& value) {
+ set_has_name_part();
+ name_part_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.UninterpretedOption.NamePart.name_part)
+}
+#endif
+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) {
+ set_has_name_part();
+ name_part_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+ ::std::string(reinterpret_cast<const char*>(value), size));
+ // @@protoc_insertion_point(field_set_pointer:google.protobuf.UninterpretedOption.NamePart.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() {
+ // @@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) {
+ if (name_part != NULL) {
+ set_has_name_part();
+ } else {
+ clear_has_name_part();
+ }
+ name_part_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name_part);
+ // @@protoc_insertion_point(field_set_allocated:google.protobuf.UninterpretedOption.NamePart.name_part)
+}
+
+// required bool is_extension = 2;
+bool UninterpretedOption_NamePart::has_is_extension() const {
+ return (_has_bits_[0] & 0x00000002u) != 0;
+}
+void UninterpretedOption_NamePart::set_has_is_extension() {
+ _has_bits_[0] |= 0x00000002u;
+}
+void UninterpretedOption_NamePart::clear_has_is_extension() {
+ _has_bits_[0] &= ~0x00000002u;
+}
+void UninterpretedOption_NamePart::clear_is_extension() {
+ is_extension_ = false;
+ clear_has_is_extension();
+}
+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) {
+ set_has_is_extension();
+ is_extension_ = value;
+ // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.NamePart.is_extension)
}
+#endif // PROTOBUF_INLINE_NOT_IN_HEADERS
-// -------------------------------------------------------------------
+// ===================================================================
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int UninterpretedOption::kNameFieldNumber;
@@ -12954,31 +13203,44 @@ const int UninterpretedOption::kAggregateValueFieldNumber;
UninterpretedOption::UninterpretedOption()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.UninterpretedOption)
}
-
-void UninterpretedOption::InitAsDefaultInstance() {
-}
-
UninterpretedOption::UninterpretedOption(const UninterpretedOption& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ name_(from.name_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ identifier_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_identifier_value()) {
+ identifier_value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.identifier_value_);
+ }
+ string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_string_value()) {
+ string_value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.string_value_);
+ }
+ aggregate_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_aggregate_value()) {
+ aggregate_value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.aggregate_value_);
+ }
+ ::memcpy(&positive_int_value_, &from.positive_int_value_,
+ reinterpret_cast<char*>(&double_value_) -
+ reinterpret_cast<char*>(&positive_int_value_) + sizeof(double_value_));
// @@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<char*>(&double_value_) -
+ reinterpret_cast<char*>(&positive_int_value_) + sizeof(double_value_));
}
UninterpretedOption::~UninterpretedOption() {
@@ -12990,8 +13252,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 {
@@ -13000,17 +13260,15 @@ void UninterpretedOption::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* UninterpretedOption::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return UninterpretedOption_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[20].descriptor;
}
const UninterpretedOption& UninterpretedOption::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-UninterpretedOption* UninterpretedOption::default_instance_ = NULL;
-
UninterpretedOption* UninterpretedOption::New(::google::protobuf::Arena* arena) const {
UninterpretedOption* n = new UninterpretedOption;
if (arena != NULL) {
@@ -13021,43 +13279,27 @@ UninterpretedOption* UninterpretedOption::New(::google::protobuf::Arena* arena)
void UninterpretedOption::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.UninterpretedOption)
-#if defined(__clang__)
-#define ZR_HELPER_(f) \
- _Pragma("clang diagnostic push") \
- _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
- __builtin_offsetof(UninterpretedOption, f) \
- _Pragma("clang diagnostic pop")
-#else
-#define ZR_HELPER_(f) reinterpret_cast<char*>(\
- &reinterpret_cast<UninterpretedOption*>(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] & 126u) {
- ZR_(positive_int_value_, double_value_);
+ name_.Clear();
+ if (_has_bits_[0 / 32] & 7u) {
if (has_identifier_value()) {
- identifier_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!identifier_value_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*identifier_value_.UnsafeRawStringPointer())->clear();
}
if (has_string_value()) {
- string_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!string_value_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*string_value_.UnsafeRawStringPointer())->clear();
}
if (has_aggregate_value()) {
- aggregate_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!aggregate_value_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*aggregate_value_.UnsafeRawStringPointer())->clear();
}
}
-
-#undef ZR_HELPER_
-#undef ZR_
-
- name_.Clear();
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
+ if (_has_bits_[0 / 32] & 56u) {
+ ::memset(&positive_int_value_, 0, reinterpret_cast<char*>(&double_value_) -
+ reinterpret_cast<char*>(&positive_int_value_) + sizeof(double_value_));
}
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool UninterpretedOption::MergePartialFromCodedStream(
@@ -13066,30 +13308,28 @@ bool UninterpretedOption::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.UninterpretedOption)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// repeated .google.protobuf.UninterpretedOption.NamePart name = 2;
case 2: {
- if (tag == 18) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_name:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_name()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_loop_name;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectTag(26)) goto parse_identifier_value;
break;
}
// optional string identifier_value = 3;
case 3: {
- if (tag == 26) {
- parse_identifier_value:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(26u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_identifier_value()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -13099,72 +13339,67 @@ bool UninterpretedOption::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(32)) goto parse_positive_int_value;
break;
}
// optional uint64 positive_int_value = 4;
case 4: {
- if (tag == 32) {
- parse_positive_int_value:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(32u)) {
+ 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;
}
- if (input->ExpectTag(40)) goto parse_negative_int_value;
break;
}
// optional int64 negative_int_value = 5;
case 5: {
- if (tag == 40) {
- parse_negative_int_value:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(40u)) {
+ 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;
}
- if (input->ExpectTag(49)) goto parse_double_value;
break;
}
// optional double double_value = 6;
case 6: {
- if (tag == 49) {
- parse_double_value:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(49u)) {
+ 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;
}
- if (input->ExpectTag(58)) goto parse_string_value;
break;
}
// optional bytes string_value = 7;
case 7: {
- if (tag == 58) {
- parse_string_value:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(58u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadBytes(
input, this->mutable_string_value()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(66)) goto parse_aggregate_value;
break;
}
// optional string aggregate_value = 8;
case 8: {
- if (tag == 66) {
- parse_aggregate_value:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(66u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_aggregate_value()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -13174,7 +13409,6 @@ bool UninterpretedOption::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -13259,6 +13493,7 @@ void UninterpretedOption::SerializeWithCachedSizes(
::google::protobuf::uint8* UninterpretedOption::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UninterpretedOption)
// repeated .google.protobuf.UninterpretedOption.NamePart name = 2;
for (unsigned int i = 0, n = this->name_size(); i < n; i++) {
@@ -13319,11 +13554,27 @@ 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) {
+ if (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
+ // repeated .google.protobuf.UninterpretedOption.NamePart name = 2;
+ {
+ 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 (_has_bits_[0 / 32] & 63u) {
// optional string identifier_value = 3;
if (has_identifier_value()) {
total_size += 1 +
@@ -13331,6 +13582,20 @@ int UninterpretedOption::ByteSize() const {
this->identifier_value());
}
+ // optional bytes string_value = 7;
+ if (has_string_value()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::BytesSize(
+ this->string_value());
+ }
+
+ // optional string aggregate_value = 8;
+ if (has_aggregate_value()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::StringSize(
+ this->aggregate_value());
+ }
+
// optional uint64 positive_int_value = 4;
if (has_positive_int_value()) {
total_size += 1 +
@@ -13350,46 +13615,18 @@ int UninterpretedOption::ByteSize() const {
total_size += 1 + 8;
}
- // optional bytes string_value = 7;
- if (has_string_value()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::BytesSize(
- this->string_value());
- }
-
- // optional string aggregate_value = 8;
- if (has_aggregate_value()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::StringSize(
- this->aggregate_value());
- }
-
- }
- // 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));
- }
-
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const UninterpretedOption* source =
::google::protobuf::internal::DynamicCastToGenerated<const UninterpretedOption>(
&from);
if (source == NULL) {
@@ -13403,15 +13640,22 @@ void UninterpretedOption::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
name_.MergeFrom(from.name_);
- if (from._has_bits_[1 / 32] & (0xffu << (1 % 32))) {
+ if (from._has_bits_[0 / 32] & 63u) {
if (from.has_identifier_value()) {
set_has_identifier_value();
identifier_value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.identifier_value_);
}
+ if (from.has_string_value()) {
+ set_has_string_value();
+ string_value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.string_value_);
+ }
+ if (from.has_aggregate_value()) {
+ set_has_aggregate_value();
+ aggregate_value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.aggregate_value_);
+ }
if (from.has_positive_int_value()) {
set_positive_int_value(from.positive_int_value());
}
@@ -13421,17 +13665,6 @@ void UninterpretedOption::MergeFrom(const UninterpretedOption& from) {
if (from.has_double_value()) {
set_double_value(from.double_value());
}
- if (from.has_string_value()) {
- set_has_string_value();
- string_value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.string_value_);
- }
- if (from.has_aggregate_value()) {
- set_has_aggregate_value();
- aggregate_value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.aggregate_value_);
- }
- }
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
}
}
@@ -13450,7 +13683,6 @@ void UninterpretedOption::CopyFrom(const UninterpretedOption& from) {
}
bool UninterpretedOption::IsInitialized() const {
-
if (!::google::protobuf::internal::AllAreInitialized(this->name())) return false;
return true;
}
@@ -13462,107 +13694,22 @@ void UninterpretedOption::Swap(UninterpretedOption* other) {
void UninterpretedOption::InternalSwap(UninterpretedOption* other) {
name_.UnsafeArenaSwap(&other->name_);
identifier_value_.Swap(&other->identifier_value_);
+ string_value_.Swap(&other->string_value_);
+ aggregate_value_.Swap(&other->aggregate_value_);
std::swap(positive_int_value_, other->positive_int_value_);
std::swap(negative_int_value_, other->negative_int_value_);
std::swap(double_value_, other->double_value_);
- string_value_.Swap(&other->string_value_);
- aggregate_value_.Swap(&other->aggregate_value_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata UninterpretedOption::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = UninterpretedOption_descriptor_;
- metadata.reflection = UninterpretedOption_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[20];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
-// UninterpretedOption_NamePart
-
-// required string name_part = 1;
-bool UninterpretedOption_NamePart::has_name_part() const {
- return (_has_bits_[0] & 0x00000001u) != 0;
-}
-void UninterpretedOption_NamePart::set_has_name_part() {
- _has_bits_[0] |= 0x00000001u;
-}
-void UninterpretedOption_NamePart::clear_has_name_part() {
- _has_bits_[0] &= ~0x00000001u;
-}
-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 {
- // @@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) {
- 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) {
- 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) {
- set_has_name_part();
- name_part_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
- // @@protoc_insertion_point(field_set_pointer:google.protobuf.UninterpretedOption.NamePart.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() {
- // @@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) {
- if (name_part != NULL) {
- set_has_name_part();
- } else {
- clear_has_name_part();
- }
- name_part_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name_part);
- // @@protoc_insertion_point(field_set_allocated:google.protobuf.UninterpretedOption.NamePart.name_part)
-}
-
-// required bool is_extension = 2;
-bool UninterpretedOption_NamePart::has_is_extension() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
-}
-void UninterpretedOption_NamePart::set_has_is_extension() {
- _has_bits_[0] |= 0x00000002u;
-}
-void UninterpretedOption_NamePart::clear_has_is_extension() {
- _has_bits_[0] &= ~0x00000002u;
-}
-void UninterpretedOption_NamePart::clear_is_extension() {
- is_extension_ = false;
- clear_has_is_extension();
-}
- 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) {
- set_has_is_extension();
- is_extension_ = value;
- // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.NamePart.is_extension)
-}
-
-// -------------------------------------------------------------------
-
// UninterpretedOption
// repeated .google.protobuf.UninterpretedOption.NamePart name = 2;
@@ -13597,49 +13744,57 @@ UninterpretedOption::name() const {
// optional string identifier_value = 3;
bool UninterpretedOption::has_identifier_value() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
+ return (_has_bits_[0] & 0x00000001u) != 0;
}
void UninterpretedOption::set_has_identifier_value() {
- _has_bits_[0] |= 0x00000002u;
+ _has_bits_[0] |= 0x00000001u;
}
void UninterpretedOption::clear_has_identifier_value() {
- _has_bits_[0] &= ~0x00000002u;
+ _has_bits_[0] &= ~0x00000001u;
}
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());
+ return identifier_value_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void UninterpretedOption::set_identifier_value(::std::string&& value) {
+ set_has_identifier_value();
+ identifier_value_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.UninterpretedOption.identifier_value)
+}
+#endif
+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<const char*>(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 {
@@ -13651,23 +13806,23 @@ void UninterpretedOption::clear_identifier_value() {
// optional uint64 positive_int_value = 4;
bool UninterpretedOption::has_positive_int_value() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
+ return (_has_bits_[0] & 0x00000008u) != 0;
}
void UninterpretedOption::set_has_positive_int_value() {
- _has_bits_[0] |= 0x00000004u;
+ _has_bits_[0] |= 0x00000008u;
}
void UninterpretedOption::clear_has_positive_int_value() {
- _has_bits_[0] &= ~0x00000004u;
+ _has_bits_[0] &= ~0x00000008u;
}
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)
@@ -13675,23 +13830,23 @@ void UninterpretedOption::clear_positive_int_value() {
// optional int64 negative_int_value = 5;
bool UninterpretedOption::has_negative_int_value() const {
- return (_has_bits_[0] & 0x00000008u) != 0;
+ return (_has_bits_[0] & 0x00000010u) != 0;
}
void UninterpretedOption::set_has_negative_int_value() {
- _has_bits_[0] |= 0x00000008u;
+ _has_bits_[0] |= 0x00000010u;
}
void UninterpretedOption::clear_has_negative_int_value() {
- _has_bits_[0] &= ~0x00000008u;
+ _has_bits_[0] &= ~0x00000010u;
}
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)
@@ -13699,23 +13854,23 @@ void UninterpretedOption::clear_negative_int_value() {
// optional double double_value = 6;
bool UninterpretedOption::has_double_value() const {
- return (_has_bits_[0] & 0x00000010u) != 0;
+ return (_has_bits_[0] & 0x00000020u) != 0;
}
void UninterpretedOption::set_has_double_value() {
- _has_bits_[0] |= 0x00000010u;
+ _has_bits_[0] |= 0x00000020u;
}
void UninterpretedOption::clear_has_double_value() {
- _has_bits_[0] &= ~0x00000010u;
+ _has_bits_[0] &= ~0x00000020u;
}
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)
@@ -13723,49 +13878,57 @@ void UninterpretedOption::clear_double_value() {
// optional bytes string_value = 7;
bool UninterpretedOption::has_string_value() const {
- return (_has_bits_[0] & 0x00000020u) != 0;
+ return (_has_bits_[0] & 0x00000002u) != 0;
}
void UninterpretedOption::set_has_string_value() {
- _has_bits_[0] |= 0x00000020u;
+ _has_bits_[0] |= 0x00000002u;
}
void UninterpretedOption::clear_has_string_value() {
- _has_bits_[0] &= ~0x00000020u;
+ _has_bits_[0] &= ~0x00000002u;
}
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());
+ return string_value_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void UninterpretedOption::set_string_value(::std::string&& value) {
+ set_has_string_value();
+ string_value_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.UninterpretedOption.string_value)
+}
+#endif
+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<const char*>(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 {
@@ -13777,49 +13940,57 @@ void UninterpretedOption::clear_string_value() {
// optional string aggregate_value = 8;
bool UninterpretedOption::has_aggregate_value() const {
- return (_has_bits_[0] & 0x00000040u) != 0;
+ return (_has_bits_[0] & 0x00000004u) != 0;
}
void UninterpretedOption::set_has_aggregate_value() {
- _has_bits_[0] |= 0x00000040u;
+ _has_bits_[0] |= 0x00000004u;
}
void UninterpretedOption::clear_has_aggregate_value() {
- _has_bits_[0] &= ~0x00000040u;
+ _has_bits_[0] &= ~0x00000004u;
}
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());
+ return aggregate_value_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void UninterpretedOption::set_aggregate_value(::std::string&& value) {
+ set_has_aggregate_value();
+ aggregate_value_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.UninterpretedOption.aggregate_value)
+}
+#endif
+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<const char*>(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 {
@@ -13843,27 +14014,36 @@ const int SourceCodeInfo_Location::kLeadingDetachedCommentsFieldNumber;
SourceCodeInfo_Location::SourceCodeInfo_Location()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.SourceCodeInfo.Location)
}
-
-void SourceCodeInfo_Location::InitAsDefaultInstance() {
-}
-
SourceCodeInfo_Location::SourceCodeInfo_Location(const SourceCodeInfo_Location& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ path_(from.path_),
+ span_(from.span_),
+ leading_detached_comments_(from.leading_detached_comments_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ leading_comments_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_leading_comments()) {
+ leading_comments_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.leading_comments_);
+ }
+ trailing_comments_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_trailing_comments()) {
+ trailing_comments_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.trailing_comments_);
+ }
// @@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() {
@@ -13874,8 +14054,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 {
@@ -13884,17 +14062,15 @@ void SourceCodeInfo_Location::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* SourceCodeInfo_Location::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return SourceCodeInfo_Location_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[21].descriptor;
}
const SourceCodeInfo_Location& SourceCodeInfo_Location::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-SourceCodeInfo_Location* SourceCodeInfo_Location::default_instance_ = NULL;
-
SourceCodeInfo_Location* SourceCodeInfo_Location::New(::google::protobuf::Arena* arena) const {
SourceCodeInfo_Location* n = new SourceCodeInfo_Location;
if (arena != NULL) {
@@ -13905,21 +14081,21 @@ SourceCodeInfo_Location* SourceCodeInfo_Location::New(::google::protobuf::Arena*
void SourceCodeInfo_Location::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.SourceCodeInfo.Location)
- if (_has_bits_[0 / 32] & 12u) {
+ path_.Clear();
+ span_.Clear();
+ leading_detached_comments_.Clear();
+ if (_has_bits_[0 / 32] & 3u) {
if (has_leading_comments()) {
- leading_comments_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!leading_comments_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*leading_comments_.UnsafeRawStringPointer())->clear();
}
if (has_trailing_comments()) {
- trailing_comments_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ GOOGLE_DCHECK(!trailing_comments_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*trailing_comments_.UnsafeRawStringPointer())->clear();
}
}
- path_.Clear();
- span_.Clear();
- leading_detached_comments_.Clear();
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
- }
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool SourceCodeInfo_Location::MergePartialFromCodedStream(
@@ -13928,49 +14104,50 @@ bool SourceCodeInfo_Location::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.SourceCodeInfo.Location)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// repeated int32 path = 1 [packed = true];
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
input, this->mutable_path())));
- } else if (tag == 8) {
+ } else if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(8u)) {
DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
- 1, 10, input, this->mutable_path())));
+ 1, 10u, input, this->mutable_path())));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_span;
break;
}
// repeated int32 span = 2 [packed = true];
case 2: {
- if (tag == 18) {
- parse_span:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
input, this->mutable_span())));
- } else if (tag == 16) {
+ } else if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(16u)) {
DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
- 1, 18, input, this->mutable_span())));
+ 1, 18u, input, this->mutable_span())));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(26)) goto parse_leading_comments;
break;
}
// optional string leading_comments = 3;
case 3: {
- if (tag == 26) {
- parse_leading_comments:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(26u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_leading_comments()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -13980,14 +14157,13 @@ bool SourceCodeInfo_Location::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(34)) goto parse_trailing_comments;
break;
}
// optional string trailing_comments = 4;
case 4: {
- if (tag == 34) {
- parse_trailing_comments:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(34u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_trailing_comments()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -13997,14 +14173,13 @@ bool SourceCodeInfo_Location::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(50)) goto parse_leading_detached_comments;
break;
}
// repeated string leading_detached_comments = 6;
case 6: {
- if (tag == 50) {
- parse_leading_detached_comments:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(50u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->add_leading_detached_comments()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -14015,8 +14190,6 @@ bool SourceCodeInfo_Location::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(50)) goto parse_leading_detached_comments;
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -14050,7 +14223,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes(
::google::protobuf::internal::WireFormatLite::WriteTag(1, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
output->WriteVarint32(_path_cached_byte_size_);
}
- for (int i = 0; i < this->path_size(); i++) {
+ for (int i = 0, n = this->path_size(); i < n; i++) {
::google::protobuf::internal::WireFormatLite::WriteInt32NoTag(
this->path(i), output);
}
@@ -14060,7 +14233,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes(
::google::protobuf::internal::WireFormatLite::WriteTag(2, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
output->WriteVarint32(_span_cached_byte_size_);
}
- for (int i = 0; i < this->span_size(); i++) {
+ for (int i = 0, n = this->span_size(); i < n; i++) {
::google::protobuf::internal::WireFormatLite::WriteInt32NoTag(
this->span(i), output);
}
@@ -14086,7 +14259,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes(
}
// repeated string leading_detached_comments = 6;
- for (int i = 0; i < this->leading_detached_comments_size(); i++) {
+ for (int i = 0, n = this->leading_detached_comments_size(); i < n; i++) {
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
this->leading_detached_comments(i).data(), this->leading_detached_comments(i).length(),
::google::protobuf::internal::WireFormat::SERIALIZE,
@@ -14104,6 +14277,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes(
::google::protobuf::uint8* SourceCodeInfo_Location::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceCodeInfo.Location)
// repeated int32 path = 1 [packed = true];
if (this->path_size() > 0) {
@@ -14114,7 +14288,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes(
target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray(
_path_cached_byte_size_, target);
}
- for (int i = 0; i < this->path_size(); i++) {
+ for (int i = 0, n = this->path_size(); i < n; i++) {
target = ::google::protobuf::internal::WireFormatLite::
WriteInt32NoTagToArray(this->path(i), target);
}
@@ -14128,7 +14302,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes(
target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray(
_span_cached_byte_size_, target);
}
- for (int i = 0; i < this->span_size(); i++) {
+ for (int i = 0, n = this->span_size(); i < n; i++) {
target = ::google::protobuf::internal::WireFormatLite::
WriteInt32NoTagToArray(this->span(i), target);
}
@@ -14156,7 +14330,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes(
}
// repeated string leading_detached_comments = 6;
- for (int i = 0; i < this->leading_detached_comments_size(); i++) {
+ for (int i = 0, n = this->leading_detached_comments_size(); i < n; i++) {
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
this->leading_detached_comments(i).data(), this->leading_detached_comments(i).length(),
::google::protobuf::internal::WireFormat::SERIALIZE,
@@ -14173,84 +14347,80 @@ 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;
-
- if (_has_bits_[2 / 32] & 12u) {
- // optional string leading_comments = 3;
- if (has_leading_comments()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::StringSize(
- this->leading_comments());
- }
-
- // optional string trailing_comments = 4;
- if (has_trailing_comments()) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::StringSize(
- this->trailing_comments());
- }
+ size_t total_size = 0;
+ if (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
}
// repeated int32 path = 1 [packed = true];
{
- int data_size = 0;
- for (int i = 0; i < this->path_size(); i++) {
- data_size += ::google::protobuf::internal::WireFormatLite::
- Int32Size(this->path(i));
- }
+ size_t data_size = ::google::protobuf::internal::WireFormatLite::
+ Int32Size(this->path_);
if (data_size > 0) {
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++) {
- data_size += ::google::protobuf::internal::WireFormatLite::
- Int32Size(this->span(i));
- }
+ size_t data_size = ::google::protobuf::internal::WireFormatLite::
+ Int32Size(this->span_);
if (data_size > 0) {
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();
- for (int i = 0; i < this->leading_detached_comments_size(); i++) {
+ total_size += 1 *
+ ::google::protobuf::internal::FromIntSize(this->leading_detached_comments_size());
+ for (int i = 0, n = this->leading_detached_comments_size(); i < n; i++) {
total_size += ::google::protobuf::internal::WireFormatLite::StringSize(
this->leading_detached_comments(i));
}
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
- unknown_fields());
+ if (_has_bits_[0 / 32] & 3u) {
+ // optional string leading_comments = 3;
+ if (has_leading_comments()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::StringSize(
+ this->leading_comments());
+ }
+
+ // optional string trailing_comments = 4;
+ if (has_trailing_comments()) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::StringSize(
+ this->trailing_comments());
+ }
+
}
+ 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const SourceCodeInfo_Location* source =
::google::protobuf::internal::DynamicCastToGenerated<const SourceCodeInfo_Location>(
&from);
if (source == NULL) {
@@ -14264,13 +14434,12 @@ void SourceCodeInfo_Location::MergeFrom(const ::google::protobuf::Message& from)
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
path_.MergeFrom(from.path_);
span_.MergeFrom(from.span_);
leading_detached_comments_.MergeFrom(from.leading_detached_comments_);
- if (from._has_bits_[2 / 32] & (0xffu << (2 % 32))) {
+ if (from._has_bits_[0 / 32] & 3u) {
if (from.has_leading_comments()) {
set_has_leading_comments();
leading_comments_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.leading_comments_);
@@ -14280,9 +14449,6 @@ void SourceCodeInfo_Location::MergeFrom(const SourceCodeInfo_Location& from) {
trailing_comments_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.trailing_comments_);
}
}
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void SourceCodeInfo_Location::CopyFrom(const ::google::protobuf::Message& from) {
@@ -14300,7 +14466,6 @@ void SourceCodeInfo_Location::CopyFrom(const SourceCodeInfo_Location& from) {
}
bool SourceCodeInfo_Location::IsInitialized() const {
-
return true;
}
@@ -14311,24 +14476,276 @@ void SourceCodeInfo_Location::Swap(SourceCodeInfo_Location* other) {
void SourceCodeInfo_Location::InternalSwap(SourceCodeInfo_Location* other) {
path_.UnsafeArenaSwap(&other->path_);
span_.UnsafeArenaSwap(&other->span_);
+ leading_detached_comments_.UnsafeArenaSwap(&other->leading_detached_comments_);
leading_comments_.Swap(&other->leading_comments_);
trailing_comments_.Swap(&other->trailing_comments_);
- leading_detached_comments_.UnsafeArenaSwap(&other->leading_detached_comments_);
std::swap(_has_bits_[0], other->_has_bits_[0]);
_internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata SourceCodeInfo_Location::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = SourceCodeInfo_Location_descriptor_;
- metadata.reflection = SourceCodeInfo_Location_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[21];
+}
+
+#if PROTOBUF_INLINE_NOT_IN_HEADERS
+// SourceCodeInfo_Location
+
+// repeated int32 path = 1 [packed = true];
+int SourceCodeInfo_Location::path_size() const {
+ return path_.size();
+}
+void SourceCodeInfo_Location::clear_path() {
+ path_.Clear();
+}
+::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) {
+ path_.Set(index, value);
+ // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.path)
+}
+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 >&
+SourceCodeInfo_Location::path() const {
+ // @@protoc_insertion_point(field_list:google.protobuf.SourceCodeInfo.Location.path)
+ return path_;
+}
+::google::protobuf::RepeatedField< ::google::protobuf::int32 >*
+SourceCodeInfo_Location::mutable_path() {
+ // @@protoc_insertion_point(field_mutable_list:google.protobuf.SourceCodeInfo.Location.path)
+ return &path_;
}
+// repeated int32 span = 2 [packed = true];
+int SourceCodeInfo_Location::span_size() const {
+ return span_.size();
+}
+void SourceCodeInfo_Location::clear_span() {
+ span_.Clear();
+}
+::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) {
+ span_.Set(index, value);
+ // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.span)
+}
+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 >&
+SourceCodeInfo_Location::span() const {
+ // @@protoc_insertion_point(field_list:google.protobuf.SourceCodeInfo.Location.span)
+ return span_;
+}
+::google::protobuf::RepeatedField< ::google::protobuf::int32 >*
+SourceCodeInfo_Location::mutable_span() {
+ // @@protoc_insertion_point(field_mutable_list:google.protobuf.SourceCodeInfo.Location.span)
+ return &span_;
+}
-// -------------------------------------------------------------------
+// optional string leading_comments = 3;
+bool SourceCodeInfo_Location::has_leading_comments() const {
+ return (_has_bits_[0] & 0x00000001u) != 0;
+}
+void SourceCodeInfo_Location::set_has_leading_comments() {
+ _has_bits_[0] |= 0x00000001u;
+}
+void SourceCodeInfo_Location::clear_has_leading_comments() {
+ _has_bits_[0] &= ~0x00000001u;
+}
+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 {
+ // @@protoc_insertion_point(field_get:google.protobuf.SourceCodeInfo.Location.leading_comments)
+ return leading_comments_.GetNoArena();
+}
+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)
+}
+#if LANG_CXX11
+void SourceCodeInfo_Location::set_leading_comments(::std::string&& value) {
+ set_has_leading_comments();
+ leading_comments_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.SourceCodeInfo.Location.leading_comments)
+}
+#endif
+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) {
+ set_has_leading_comments();
+ leading_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+ ::std::string(reinterpret_cast<const char*>(value), size));
+ // @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceCodeInfo.Location.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() {
+ // @@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) {
+ if (leading_comments != NULL) {
+ set_has_leading_comments();
+ } else {
+ clear_has_leading_comments();
+ }
+ leading_comments_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), leading_comments);
+ // @@protoc_insertion_point(field_set_allocated:google.protobuf.SourceCodeInfo.Location.leading_comments)
+}
+
+// optional string trailing_comments = 4;
+bool SourceCodeInfo_Location::has_trailing_comments() const {
+ return (_has_bits_[0] & 0x00000002u) != 0;
+}
+void SourceCodeInfo_Location::set_has_trailing_comments() {
+ _has_bits_[0] |= 0x00000002u;
+}
+void SourceCodeInfo_Location::clear_has_trailing_comments() {
+ _has_bits_[0] &= ~0x00000002u;
+}
+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 {
+ // @@protoc_insertion_point(field_get:google.protobuf.SourceCodeInfo.Location.trailing_comments)
+ return trailing_comments_.GetNoArena();
+}
+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)
+}
+#if LANG_CXX11
+void SourceCodeInfo_Location::set_trailing_comments(::std::string&& value) {
+ set_has_trailing_comments();
+ trailing_comments_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.SourceCodeInfo.Location.trailing_comments)
+}
+#endif
+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) {
+ set_has_trailing_comments();
+ trailing_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+ ::std::string(reinterpret_cast<const char*>(value), size));
+ // @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceCodeInfo.Location.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() {
+ // @@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) {
+ if (trailing_comments != NULL) {
+ set_has_trailing_comments();
+ } else {
+ clear_has_trailing_comments();
+ }
+ trailing_comments_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), trailing_comments);
+ // @@protoc_insertion_point(field_set_allocated:google.protobuf.SourceCodeInfo.Location.trailing_comments)
+}
+
+// repeated string leading_detached_comments = 6;
+int SourceCodeInfo_Location::leading_detached_comments_size() const {
+ return leading_detached_comments_.size();
+}
+void SourceCodeInfo_Location::clear_leading_detached_comments() {
+ leading_detached_comments_.Clear();
+}
+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) {
+ // @@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) {
+ // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
+ leading_detached_comments_.Mutable(index)->assign(value);
+}
+#if LANG_CXX11
+void SourceCodeInfo_Location::set_leading_detached_comments(int index, ::std::string&& value) {
+ // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
+ leading_detached_comments_.Mutable(index)->assign(std::move(value));
+}
+#endif
+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) {
+ leading_detached_comments_.Mutable(index)->assign(
+ reinterpret_cast<const char*>(value), size);
+ // @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceCodeInfo.Location.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) {
+ leading_detached_comments_.Add()->assign(value);
+ // @@protoc_insertion_point(field_add:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
+}
+#if LANG_CXX11
+void SourceCodeInfo_Location::add_leading_detached_comments(::std::string&& value) {
+ leading_detached_comments_.Add()->assign(std::move(value));
+ // @@protoc_insertion_point(field_add:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
+}
+#endif
+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) {
+ leading_detached_comments_.Add()->assign(reinterpret_cast<const char*>(value), size);
+ // @@protoc_insertion_point(field_add_pointer:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
+}
+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>*
+SourceCodeInfo_Location::mutable_leading_detached_comments() {
+ // @@protoc_insertion_point(field_mutable_list:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
+ return &leading_detached_comments_;
+}
+
+#endif // PROTOBUF_INLINE_NOT_IN_HEADERS
+
+// ===================================================================
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int SourceCodeInfo::kLocationFieldNumber;
@@ -14336,24 +14753,24 @@ const int SourceCodeInfo::kLocationFieldNumber;
SourceCodeInfo::SourceCodeInfo()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.SourceCodeInfo)
}
-
-void SourceCodeInfo::InitAsDefaultInstance() {
-}
-
SourceCodeInfo::SourceCodeInfo(const SourceCodeInfo& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ location_(from.location_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.SourceCodeInfo)
}
void SourceCodeInfo::SharedCtor() {
_cached_size_ = 0;
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
}
SourceCodeInfo::~SourceCodeInfo() {
@@ -14362,8 +14779,6 @@ SourceCodeInfo::~SourceCodeInfo() {
}
void SourceCodeInfo::SharedDtor() {
- if (this != default_instance_) {
- }
}
void SourceCodeInfo::SetCachedSize(int size) const {
@@ -14372,17 +14787,15 @@ void SourceCodeInfo::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* SourceCodeInfo::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return SourceCodeInfo_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[22].descriptor;
}
const SourceCodeInfo& SourceCodeInfo::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-SourceCodeInfo* SourceCodeInfo::default_instance_ = NULL;
-
SourceCodeInfo* SourceCodeInfo::New(::google::protobuf::Arena* arena) const {
SourceCodeInfo* n = new SourceCodeInfo;
if (arena != NULL) {
@@ -14394,10 +14807,8 @@ 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_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
- }
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool SourceCodeInfo::MergePartialFromCodedStream(
@@ -14406,23 +14817,21 @@ bool SourceCodeInfo::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.SourceCodeInfo)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// repeated .google.protobuf.SourceCodeInfo.Location location = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_location:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_location()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(10)) goto parse_loop_location;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -14466,6 +14875,7 @@ void SourceCodeInfo::SerializeWithCachedSizes(
::google::protobuf::uint8* SourceCodeInfo::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceCodeInfo)
// repeated .google.protobuf.SourceCodeInfo.Location location = 1;
for (unsigned int i = 0, n = this->location_size(); i < n; i++) {
@@ -14482,35 +14892,37 @@ 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;
-
- // 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));
- }
+ size_t total_size = 0;
if (_internal_metadata_.have_unknown_fields()) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
unknown_fields());
}
+ // repeated .google.protobuf.SourceCodeInfo.Location location = 1;
+ {
+ 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));
+ }
+ }
+
+ 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const SourceCodeInfo* source =
::google::protobuf::internal::DynamicCastToGenerated<const SourceCodeInfo>(
&from);
if (source == NULL) {
@@ -14524,13 +14936,9 @@ void SourceCodeInfo::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
location_.MergeFrom(from.location_);
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void SourceCodeInfo::CopyFrom(const ::google::protobuf::Message& from) {
@@ -14548,7 +14956,6 @@ void SourceCodeInfo::CopyFrom(const SourceCodeInfo& from) {
}
bool SourceCodeInfo::IsInitialized() const {
-
return true;
}
@@ -14564,241 +14971,11 @@ void SourceCodeInfo::InternalSwap(SourceCodeInfo* other) {
}
::google::protobuf::Metadata SourceCodeInfo::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = SourceCodeInfo_descriptor_;
- metadata.reflection = SourceCodeInfo_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[22];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
-// SourceCodeInfo_Location
-
-// repeated int32 path = 1 [packed = true];
-int SourceCodeInfo_Location::path_size() const {
- return path_.size();
-}
-void SourceCodeInfo_Location::clear_path() {
- path_.Clear();
-}
- ::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) {
- path_.Set(index, value);
- // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.path)
-}
- 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 >&
-SourceCodeInfo_Location::path() const {
- // @@protoc_insertion_point(field_list:google.protobuf.SourceCodeInfo.Location.path)
- return path_;
-}
- ::google::protobuf::RepeatedField< ::google::protobuf::int32 >*
-SourceCodeInfo_Location::mutable_path() {
- // @@protoc_insertion_point(field_mutable_list:google.protobuf.SourceCodeInfo.Location.path)
- return &path_;
-}
-
-// repeated int32 span = 2 [packed = true];
-int SourceCodeInfo_Location::span_size() const {
- return span_.size();
-}
-void SourceCodeInfo_Location::clear_span() {
- span_.Clear();
-}
- ::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) {
- span_.Set(index, value);
- // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.span)
-}
- 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 >&
-SourceCodeInfo_Location::span() const {
- // @@protoc_insertion_point(field_list:google.protobuf.SourceCodeInfo.Location.span)
- return span_;
-}
- ::google::protobuf::RepeatedField< ::google::protobuf::int32 >*
-SourceCodeInfo_Location::mutable_span() {
- // @@protoc_insertion_point(field_mutable_list:google.protobuf.SourceCodeInfo.Location.span)
- return &span_;
-}
-
-// optional string leading_comments = 3;
-bool SourceCodeInfo_Location::has_leading_comments() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
-}
-void SourceCodeInfo_Location::set_has_leading_comments() {
- _has_bits_[0] |= 0x00000004u;
-}
-void SourceCodeInfo_Location::clear_has_leading_comments() {
- _has_bits_[0] &= ~0x00000004u;
-}
-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 {
- // @@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) {
- 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) {
- 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) {
- set_has_leading_comments();
- leading_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
- // @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceCodeInfo.Location.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() {
- // @@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) {
- if (leading_comments != NULL) {
- set_has_leading_comments();
- } else {
- clear_has_leading_comments();
- }
- leading_comments_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), leading_comments);
- // @@protoc_insertion_point(field_set_allocated:google.protobuf.SourceCodeInfo.Location.leading_comments)
-}
-
-// optional string trailing_comments = 4;
-bool SourceCodeInfo_Location::has_trailing_comments() const {
- return (_has_bits_[0] & 0x00000008u) != 0;
-}
-void SourceCodeInfo_Location::set_has_trailing_comments() {
- _has_bits_[0] |= 0x00000008u;
-}
-void SourceCodeInfo_Location::clear_has_trailing_comments() {
- _has_bits_[0] &= ~0x00000008u;
-}
-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 {
- // @@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) {
- 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) {
- 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) {
- set_has_trailing_comments();
- trailing_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
- // @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceCodeInfo.Location.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() {
- // @@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) {
- if (trailing_comments != NULL) {
- set_has_trailing_comments();
- } else {
- clear_has_trailing_comments();
- }
- trailing_comments_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), trailing_comments);
- // @@protoc_insertion_point(field_set_allocated:google.protobuf.SourceCodeInfo.Location.trailing_comments)
-}
-
-// repeated string leading_detached_comments = 6;
-int SourceCodeInfo_Location::leading_detached_comments_size() const {
- return leading_detached_comments_.size();
-}
-void SourceCodeInfo_Location::clear_leading_detached_comments() {
- leading_detached_comments_.Clear();
-}
- 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) {
- // @@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) {
- // @@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) {
- 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) {
- leading_detached_comments_.Mutable(index)->assign(
- reinterpret_cast<const char*>(value), size);
- // @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceCodeInfo.Location.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) {
- 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) {
- 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) {
- leading_detached_comments_.Add()->assign(reinterpret_cast<const char*>(value), size);
- // @@protoc_insertion_point(field_add_pointer:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
-}
- 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>*
-SourceCodeInfo_Location::mutable_leading_detached_comments() {
- // @@protoc_insertion_point(field_mutable_list:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
- return &leading_detached_comments_;
-}
-
-// -------------------------------------------------------------------
-
// SourceCodeInfo
// repeated .google.protobuf.SourceCodeInfo.Location location = 1;
@@ -14844,28 +15021,34 @@ const int GeneratedCodeInfo_Annotation::kEndFieldNumber;
GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.GeneratedCodeInfo.Annotation)
}
-
-void GeneratedCodeInfo_Annotation::InitAsDefaultInstance() {
-}
-
GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation(const GeneratedCodeInfo_Annotation& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ path_(from.path_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ source_file_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.has_source_file()) {
+ source_file_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.source_file_);
+ }
+ ::memcpy(&begin_, &from.begin_,
+ reinterpret_cast<char*>(&end_) -
+ reinterpret_cast<char*>(&begin_) + sizeof(end_));
// @@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<char*>(&end_) -
+ reinterpret_cast<char*>(&begin_) + sizeof(end_));
}
GeneratedCodeInfo_Annotation::~GeneratedCodeInfo_Annotation() {
@@ -14875,8 +15058,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 {
@@ -14885,17 +15066,15 @@ void GeneratedCodeInfo_Annotation::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* GeneratedCodeInfo_Annotation::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return GeneratedCodeInfo_Annotation_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[23].descriptor;
}
const GeneratedCodeInfo_Annotation& GeneratedCodeInfo_Annotation::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-GeneratedCodeInfo_Annotation* GeneratedCodeInfo_Annotation::default_instance_ = NULL;
-
GeneratedCodeInfo_Annotation* GeneratedCodeInfo_Annotation::New(::google::protobuf::Arena* arena) const {
GeneratedCodeInfo_Annotation* n = new GeneratedCodeInfo_Annotation;
if (arena != NULL) {
@@ -14906,37 +15085,17 @@ GeneratedCodeInfo_Annotation* GeneratedCodeInfo_Annotation::New(::google::protob
void GeneratedCodeInfo_Annotation::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.GeneratedCodeInfo.Annotation)
-#if defined(__clang__)
-#define ZR_HELPER_(f) \
- _Pragma("clang diagnostic push") \
- _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
- __builtin_offsetof(GeneratedCodeInfo_Annotation, f) \
- _Pragma("clang diagnostic pop")
-#else
-#define ZR_HELPER_(f) reinterpret_cast<char*>(\
- &reinterpret_cast<GeneratedCodeInfo_Annotation*>(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] & 14u) {
- ZR_(begin_, end_);
- if (has_source_file()) {
- source_file_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- }
- }
-
-#undef ZR_HELPER_
-#undef ZR_
-
path_.Clear();
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
+ if (has_source_file()) {
+ GOOGLE_DCHECK(!source_file_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+ (*source_file_.UnsafeRawStringPointer())->clear();
}
+ if (_has_bits_[0 / 32] & 6u) {
+ ::memset(&begin_, 0, reinterpret_cast<char*>(&end_) -
+ reinterpret_cast<char*>(&begin_) + sizeof(end_));
+ }
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool GeneratedCodeInfo_Annotation::MergePartialFromCodedStream(
@@ -14945,31 +15104,32 @@ bool GeneratedCodeInfo_Annotation::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.GeneratedCodeInfo.Annotation)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// repeated int32 path = 1 [packed = true];
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
input, this->mutable_path())));
- } else if (tag == 8) {
+ } else if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(8u)) {
DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
- 1, 10, input, this->mutable_path())));
+ 1, 10u, input, this->mutable_path())));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_source_file;
break;
}
// optional string source_file = 2;
case 2: {
- if (tag == 18) {
- parse_source_file:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_source_file()));
::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
@@ -14979,37 +15139,34 @@ bool GeneratedCodeInfo_Annotation::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(24)) goto parse_begin;
break;
}
// optional int32 begin = 3;
case 3: {
- if (tag == 24) {
- parse_begin:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(24u)) {
+ 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;
}
- if (input->ExpectTag(32)) goto parse_end;
break;
}
// optional int32 end = 4;
case 4: {
- if (tag == 32) {
- parse_end:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(32u)) {
+ 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;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -15043,7 +15200,7 @@ void GeneratedCodeInfo_Annotation::SerializeWithCachedSizes(
::google::protobuf::internal::WireFormatLite::WriteTag(1, ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
output->WriteVarint32(_path_cached_byte_size_);
}
- for (int i = 0; i < this->path_size(); i++) {
+ for (int i = 0, n = this->path_size(); i < n; i++) {
::google::protobuf::internal::WireFormatLite::WriteInt32NoTag(
this->path(i), output);
}
@@ -15077,6 +15234,7 @@ void GeneratedCodeInfo_Annotation::SerializeWithCachedSizes(
::google::protobuf::uint8* GeneratedCodeInfo_Annotation::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.GeneratedCodeInfo.Annotation)
// repeated int32 path = 1 [packed = true];
if (this->path_size() > 0) {
@@ -15087,7 +15245,7 @@ void GeneratedCodeInfo_Annotation::SerializeWithCachedSizes(
target = ::google::protobuf::io::CodedOutputStream::WriteVarint32ToArray(
_path_cached_byte_size_, target);
}
- for (int i = 0; i < this->path_size(); i++) {
+ for (int i = 0, n = this->path_size(); i < n; i++) {
target = ::google::protobuf::internal::WireFormatLite::
WriteInt32NoTagToArray(this->path(i), target);
}
@@ -15121,11 +15279,31 @@ 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 (_internal_metadata_.have_unknown_fields()) {
+ total_size +=
+ ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+ unknown_fields());
+ }
+ // repeated int32 path = 1 [packed = true];
+ {
+ size_t data_size = ::google::protobuf::internal::WireFormatLite::
+ Int32Size(this->path_);
+ if (data_size > 0) {
+ 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_ = cached_size;
+ GOOGLE_SAFE_CONCURRENT_WRITES_END();
+ total_size += data_size;
+ }
- if (_has_bits_[1 / 32] & 14u) {
+ if (_has_bits_[0 / 32] & 7u) {
// optional string source_file = 2;
if (has_source_file()) {
total_size += 1 +
@@ -15148,40 +15326,17 @@ int GeneratedCodeInfo_Annotation::ByteSize() const {
}
}
- // repeated int32 path = 1 [packed = true];
- {
- int data_size = 0;
- for (int i = 0; i < this->path_size(); i++) {
- data_size += ::google::protobuf::internal::WireFormatLite::
- Int32Size(this->path(i));
- }
- if (data_size > 0) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::Int32Size(data_size);
- }
- GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
- _path_cached_byte_size_ = data_size;
- GOOGLE_SAFE_CONCURRENT_WRITES_END();
- total_size += data_size;
- }
-
- if (_internal_metadata_.have_unknown_fields()) {
- total_size +=
- ::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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const GeneratedCodeInfo_Annotation* source =
::google::protobuf::internal::DynamicCastToGenerated<const GeneratedCodeInfo_Annotation>(
&from);
if (source == NULL) {
@@ -15195,11 +15350,10 @@ void GeneratedCodeInfo_Annotation::MergeFrom(const ::google::protobuf::Message&
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
path_.MergeFrom(from.path_);
- if (from._has_bits_[1 / 32] & (0xffu << (1 % 32))) {
+ if (from._has_bits_[0 / 32] & 7u) {
if (from.has_source_file()) {
set_has_source_file();
source_file_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.source_file_);
@@ -15211,9 +15365,6 @@ void GeneratedCodeInfo_Annotation::MergeFrom(const GeneratedCodeInfo_Annotation&
set_end(from.end());
}
}
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void GeneratedCodeInfo_Annotation::CopyFrom(const ::google::protobuf::Message& from) {
@@ -15231,7 +15382,6 @@ void GeneratedCodeInfo_Annotation::CopyFrom(const GeneratedCodeInfo_Annotation&
}
bool GeneratedCodeInfo_Annotation::IsInitialized() const {
-
return true;
}
@@ -15250,15 +15400,156 @@ void GeneratedCodeInfo_Annotation::InternalSwap(GeneratedCodeInfo_Annotation* ot
}
::google::protobuf::Metadata GeneratedCodeInfo_Annotation::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = GeneratedCodeInfo_Annotation_descriptor_;
- metadata.reflection = GeneratedCodeInfo_Annotation_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[23];
}
+#if PROTOBUF_INLINE_NOT_IN_HEADERS
+// GeneratedCodeInfo_Annotation
-// -------------------------------------------------------------------
+// repeated int32 path = 1 [packed = true];
+int GeneratedCodeInfo_Annotation::path_size() const {
+ return path_.size();
+}
+void GeneratedCodeInfo_Annotation::clear_path() {
+ path_.Clear();
+}
+::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) {
+ path_.Set(index, value);
+ // @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.path)
+}
+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 >&
+GeneratedCodeInfo_Annotation::path() const {
+ // @@protoc_insertion_point(field_list:google.protobuf.GeneratedCodeInfo.Annotation.path)
+ return path_;
+}
+::google::protobuf::RepeatedField< ::google::protobuf::int32 >*
+GeneratedCodeInfo_Annotation::mutable_path() {
+ // @@protoc_insertion_point(field_mutable_list:google.protobuf.GeneratedCodeInfo.Annotation.path)
+ return &path_;
+}
+
+// optional string source_file = 2;
+bool GeneratedCodeInfo_Annotation::has_source_file() const {
+ return (_has_bits_[0] & 0x00000001u) != 0;
+}
+void GeneratedCodeInfo_Annotation::set_has_source_file() {
+ _has_bits_[0] |= 0x00000001u;
+}
+void GeneratedCodeInfo_Annotation::clear_has_source_file() {
+ _has_bits_[0] &= ~0x00000001u;
+}
+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 {
+ // @@protoc_insertion_point(field_get:google.protobuf.GeneratedCodeInfo.Annotation.source_file)
+ return source_file_.GetNoArena();
+}
+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)
+}
+#if LANG_CXX11
+void GeneratedCodeInfo_Annotation::set_source_file(::std::string&& value) {
+ set_has_source_file();
+ source_file_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.GeneratedCodeInfo.Annotation.source_file)
+}
+#endif
+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) {
+ set_has_source_file();
+ source_file_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+ ::std::string(reinterpret_cast<const char*>(value), size));
+ // @@protoc_insertion_point(field_set_pointer:google.protobuf.GeneratedCodeInfo.Annotation.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() {
+ // @@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) {
+ if (source_file != NULL) {
+ set_has_source_file();
+ } else {
+ clear_has_source_file();
+ }
+ source_file_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), source_file);
+ // @@protoc_insertion_point(field_set_allocated:google.protobuf.GeneratedCodeInfo.Annotation.source_file)
+}
+
+// optional int32 begin = 3;
+bool GeneratedCodeInfo_Annotation::has_begin() const {
+ return (_has_bits_[0] & 0x00000002u) != 0;
+}
+void GeneratedCodeInfo_Annotation::set_has_begin() {
+ _has_bits_[0] |= 0x00000002u;
+}
+void GeneratedCodeInfo_Annotation::clear_has_begin() {
+ _has_bits_[0] &= ~0x00000002u;
+}
+void GeneratedCodeInfo_Annotation::clear_begin() {
+ begin_ = 0;
+ clear_has_begin();
+}
+::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) {
+ set_has_begin();
+ begin_ = value;
+ // @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.begin)
+}
+
+// optional int32 end = 4;
+bool GeneratedCodeInfo_Annotation::has_end() const {
+ return (_has_bits_[0] & 0x00000004u) != 0;
+}
+void GeneratedCodeInfo_Annotation::set_has_end() {
+ _has_bits_[0] |= 0x00000004u;
+}
+void GeneratedCodeInfo_Annotation::clear_has_end() {
+ _has_bits_[0] &= ~0x00000004u;
+}
+void GeneratedCodeInfo_Annotation::clear_end() {
+ end_ = 0;
+ clear_has_end();
+}
+::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) {
+ set_has_end();
+ end_ = value;
+ // @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.end)
+}
+
+#endif // PROTOBUF_INLINE_NOT_IN_HEADERS
+
+// ===================================================================
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int GeneratedCodeInfo::kAnnotationFieldNumber;
@@ -15266,24 +15557,24 @@ const int GeneratedCodeInfo::kAnnotationFieldNumber;
GeneratedCodeInfo::GeneratedCodeInfo()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.GeneratedCodeInfo)
}
-
-void GeneratedCodeInfo::InitAsDefaultInstance() {
-}
-
GeneratedCodeInfo::GeneratedCodeInfo(const GeneratedCodeInfo& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _has_bits_(from._has_bits_),
+ _cached_size_(0),
+ annotation_(from.annotation_) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.GeneratedCodeInfo)
}
void GeneratedCodeInfo::SharedCtor() {
_cached_size_ = 0;
- ::memset(_has_bits_, 0, sizeof(_has_bits_));
}
GeneratedCodeInfo::~GeneratedCodeInfo() {
@@ -15292,8 +15583,6 @@ GeneratedCodeInfo::~GeneratedCodeInfo() {
}
void GeneratedCodeInfo::SharedDtor() {
- if (this != default_instance_) {
- }
}
void GeneratedCodeInfo::SetCachedSize(int size) const {
@@ -15302,17 +15591,15 @@ void GeneratedCodeInfo::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* GeneratedCodeInfo::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return GeneratedCodeInfo_descriptor_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[24].descriptor;
}
const GeneratedCodeInfo& GeneratedCodeInfo::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-GeneratedCodeInfo* GeneratedCodeInfo::default_instance_ = NULL;
-
GeneratedCodeInfo* GeneratedCodeInfo::New(::google::protobuf::Arena* arena) const {
GeneratedCodeInfo* n = new GeneratedCodeInfo;
if (arena != NULL) {
@@ -15324,10 +15611,8 @@ 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_));
- if (_internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->Clear();
- }
+ _has_bits_.Clear();
+ _internal_metadata_.Clear();
}
bool GeneratedCodeInfo::MergePartialFromCodedStream(
@@ -15336,23 +15621,21 @@ bool GeneratedCodeInfo::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.GeneratedCodeInfo)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_annotation:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_annotation()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(10)) goto parse_loop_annotation;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -15396,6 +15679,7 @@ void GeneratedCodeInfo::SerializeWithCachedSizes(
::google::protobuf::uint8* GeneratedCodeInfo::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.GeneratedCodeInfo)
// repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;
for (unsigned int i = 0, n = this->annotation_size(); i < n; i++) {
@@ -15412,35 +15696,37 @@ 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;
-
- // 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));
- }
+ size_t total_size = 0;
if (_internal_metadata_.have_unknown_fields()) {
total_size +=
::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
unknown_fields());
}
+ // repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;
+ {
+ 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));
+ }
+ }
+
+ 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const GeneratedCodeInfo* source =
::google::protobuf::internal::DynamicCastToGenerated<const GeneratedCodeInfo>(
&from);
if (source == NULL) {
@@ -15454,13 +15740,9 @@ void GeneratedCodeInfo::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
annotation_.MergeFrom(from.annotation_);
- if (from._internal_metadata_.have_unknown_fields()) {
- mutable_unknown_fields()->MergeFrom(from.unknown_fields());
- }
}
void GeneratedCodeInfo::CopyFrom(const ::google::protobuf::Message& from) {
@@ -15478,7 +15760,6 @@ void GeneratedCodeInfo::CopyFrom(const GeneratedCodeInfo& from) {
}
bool GeneratedCodeInfo::IsInitialized() const {
-
return true;
}
@@ -15494,150 +15775,11 @@ void GeneratedCodeInfo::InternalSwap(GeneratedCodeInfo* other) {
}
::google::protobuf::Metadata GeneratedCodeInfo::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = GeneratedCodeInfo_descriptor_;
- metadata.reflection = GeneratedCodeInfo_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[24];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
-// GeneratedCodeInfo_Annotation
-
-// repeated int32 path = 1 [packed = true];
-int GeneratedCodeInfo_Annotation::path_size() const {
- return path_.size();
-}
-void GeneratedCodeInfo_Annotation::clear_path() {
- path_.Clear();
-}
- ::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) {
- path_.Set(index, value);
- // @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.path)
-}
- 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 >&
-GeneratedCodeInfo_Annotation::path() const {
- // @@protoc_insertion_point(field_list:google.protobuf.GeneratedCodeInfo.Annotation.path)
- return path_;
-}
- ::google::protobuf::RepeatedField< ::google::protobuf::int32 >*
-GeneratedCodeInfo_Annotation::mutable_path() {
- // @@protoc_insertion_point(field_mutable_list:google.protobuf.GeneratedCodeInfo.Annotation.path)
- return &path_;
-}
-
-// optional string source_file = 2;
-bool GeneratedCodeInfo_Annotation::has_source_file() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
-}
-void GeneratedCodeInfo_Annotation::set_has_source_file() {
- _has_bits_[0] |= 0x00000002u;
-}
-void GeneratedCodeInfo_Annotation::clear_has_source_file() {
- _has_bits_[0] &= ~0x00000002u;
-}
-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 {
- // @@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) {
- 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) {
- 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) {
- set_has_source_file();
- source_file_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
- // @@protoc_insertion_point(field_set_pointer:google.protobuf.GeneratedCodeInfo.Annotation.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() {
- // @@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) {
- if (source_file != NULL) {
- set_has_source_file();
- } else {
- clear_has_source_file();
- }
- source_file_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), source_file);
- // @@protoc_insertion_point(field_set_allocated:google.protobuf.GeneratedCodeInfo.Annotation.source_file)
-}
-
-// optional int32 begin = 3;
-bool GeneratedCodeInfo_Annotation::has_begin() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
-}
-void GeneratedCodeInfo_Annotation::set_has_begin() {
- _has_bits_[0] |= 0x00000004u;
-}
-void GeneratedCodeInfo_Annotation::clear_has_begin() {
- _has_bits_[0] &= ~0x00000004u;
-}
-void GeneratedCodeInfo_Annotation::clear_begin() {
- begin_ = 0;
- clear_has_begin();
-}
- ::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) {
- set_has_begin();
- begin_ = value;
- // @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.begin)
-}
-
-// optional int32 end = 4;
-bool GeneratedCodeInfo_Annotation::has_end() const {
- return (_has_bits_[0] & 0x00000008u) != 0;
-}
-void GeneratedCodeInfo_Annotation::set_has_end() {
- _has_bits_[0] |= 0x00000008u;
-}
-void GeneratedCodeInfo_Annotation::clear_has_end() {
- _has_bits_[0] &= ~0x00000008u;
-}
-void GeneratedCodeInfo_Annotation::clear_end() {
- end_ = 0;
- clear_has_end();
-}
- ::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) {
- set_has_end();
- end_ = value;
- // @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.end)
-}
-
-// -------------------------------------------------------------------
-
// GeneratedCodeInfo
// repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/descriptor.pb.h b/third_party/protobuf/src/google/protobuf/descriptor.pb.h
index 5a9e12bcaf..10708963af 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/descriptor.pb.h
+++ b/third_party/protobuf/src/google/protobuf/descriptor.pb.h
@@ -8,61 +8,121 @@
#include <google/protobuf/stubs/common.h>
-#if GOOGLE_PROTOBUF_VERSION < 3000000
+#if GOOGLE_PROTOBUF_VERSION < 3002000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
-#if 3000000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
+#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
+#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/metadata.h>
#include <google/protobuf/message.h>
-#include <google/protobuf/repeated_field.h>
-#include <google/protobuf/extension_set.h>
+#include <google/protobuf/repeated_field.h> // IWYU pragma: export
+#include <google/protobuf/extension_set.h> // IWYU pragma: export
#include <google/protobuf/generated_enum_reflection.h>
#include <google/protobuf/unknown_field_set.h>
// @@protoc_insertion_point(includes)
-
namespace google {
namespace protobuf {
-
-// Internal implementation detail -- do not call these.
-void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
-void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
-void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
class DescriptorProto;
+class DescriptorProtoDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern DescriptorProtoDefaultTypeInternal _DescriptorProto_default_instance_;
class DescriptorProto_ExtensionRange;
+class DescriptorProto_ExtensionRangeDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern DescriptorProto_ExtensionRangeDefaultTypeInternal _DescriptorProto_ExtensionRange_default_instance_;
class DescriptorProto_ReservedRange;
+class DescriptorProto_ReservedRangeDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern DescriptorProto_ReservedRangeDefaultTypeInternal _DescriptorProto_ReservedRange_default_instance_;
class EnumDescriptorProto;
+class EnumDescriptorProtoDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern EnumDescriptorProtoDefaultTypeInternal _EnumDescriptorProto_default_instance_;
class EnumOptions;
+class EnumOptionsDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern EnumOptionsDefaultTypeInternal _EnumOptions_default_instance_;
class EnumValueDescriptorProto;
+class EnumValueDescriptorProtoDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern EnumValueDescriptorProtoDefaultTypeInternal _EnumValueDescriptorProto_default_instance_;
class EnumValueOptions;
+class EnumValueOptionsDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern EnumValueOptionsDefaultTypeInternal _EnumValueOptions_default_instance_;
class FieldDescriptorProto;
+class FieldDescriptorProtoDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern FieldDescriptorProtoDefaultTypeInternal _FieldDescriptorProto_default_instance_;
class FieldOptions;
+class FieldOptionsDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern FieldOptionsDefaultTypeInternal _FieldOptions_default_instance_;
class FileDescriptorProto;
+class FileDescriptorProtoDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern FileDescriptorProtoDefaultTypeInternal _FileDescriptorProto_default_instance_;
class FileDescriptorSet;
+class FileDescriptorSetDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern FileDescriptorSetDefaultTypeInternal _FileDescriptorSet_default_instance_;
class FileOptions;
+class FileOptionsDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern FileOptionsDefaultTypeInternal _FileOptions_default_instance_;
class GeneratedCodeInfo;
+class GeneratedCodeInfoDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern GeneratedCodeInfoDefaultTypeInternal _GeneratedCodeInfo_default_instance_;
class GeneratedCodeInfo_Annotation;
+class GeneratedCodeInfo_AnnotationDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern GeneratedCodeInfo_AnnotationDefaultTypeInternal _GeneratedCodeInfo_Annotation_default_instance_;
class MessageOptions;
+class MessageOptionsDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern MessageOptionsDefaultTypeInternal _MessageOptions_default_instance_;
class MethodDescriptorProto;
+class MethodDescriptorProtoDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern MethodDescriptorProtoDefaultTypeInternal _MethodDescriptorProto_default_instance_;
class MethodOptions;
+class MethodOptionsDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern MethodOptionsDefaultTypeInternal _MethodOptions_default_instance_;
class OneofDescriptorProto;
+class OneofDescriptorProtoDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern OneofDescriptorProtoDefaultTypeInternal _OneofDescriptorProto_default_instance_;
class OneofOptions;
+class OneofOptionsDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern OneofOptionsDefaultTypeInternal _OneofOptions_default_instance_;
class ServiceDescriptorProto;
+class ServiceDescriptorProtoDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern ServiceDescriptorProtoDefaultTypeInternal _ServiceDescriptorProto_default_instance_;
class ServiceOptions;
+class ServiceOptionsDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern ServiceOptionsDefaultTypeInternal _ServiceOptions_default_instance_;
class SourceCodeInfo;
+class SourceCodeInfoDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern SourceCodeInfoDefaultTypeInternal _SourceCodeInfo_default_instance_;
class SourceCodeInfo_Location;
+class SourceCodeInfo_LocationDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern SourceCodeInfo_LocationDefaultTypeInternal _SourceCodeInfo_Location_default_instance_;
class UninterpretedOption;
+class UninterpretedOptionDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern UninterpretedOptionDefaultTypeInternal _UninterpretedOption_default_instance_;
class UninterpretedOption_NamePart;
+class UninterpretedOption_NamePartDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern UninterpretedOption_NamePartDefaultTypeInternal _UninterpretedOption_NamePart_default_instance_;
+} // namespace protobuf
+} // namespace google
+
+namespace google {
+namespace protobuf {
+
+namespace protobuf_google_2fprotobuf_2fdescriptor_2eproto {
+// Internal implementation detail -- do not call these.
+struct LIBPROTOBUF_EXPORT TableStruct {
+ static const ::google::protobuf::uint32 offsets[];
+ static void InitDefaultsImpl();
+ static void Shutdown();
+};
+void LIBPROTOBUF_EXPORT AddDescriptors();
+void LIBPROTOBUF_EXPORT InitDefaults();
+} // namespace protobuf_google_2fprotobuf_2fdescriptor_2eproto
enum FieldDescriptorProto_Type {
FieldDescriptorProto_Type_TYPE_DOUBLE = 1,
@@ -179,6 +239,26 @@ inline bool FieldOptions_JSType_Parse(
return ::google::protobuf::internal::ParseNamedEnum<FieldOptions_JSType>(
FieldOptions_JSType_descriptor(), name, value);
}
+enum MethodOptions_IdempotencyLevel {
+ MethodOptions_IdempotencyLevel_IDEMPOTENCY_UNKNOWN = 0,
+ MethodOptions_IdempotencyLevel_NO_SIDE_EFFECTS = 1,
+ MethodOptions_IdempotencyLevel_IDEMPOTENT = 2
+};
+LIBPROTOBUF_EXPORT bool MethodOptions_IdempotencyLevel_IsValid(int value);
+const MethodOptions_IdempotencyLevel MethodOptions_IdempotencyLevel_IdempotencyLevel_MIN = MethodOptions_IdempotencyLevel_IDEMPOTENCY_UNKNOWN;
+const MethodOptions_IdempotencyLevel MethodOptions_IdempotencyLevel_IdempotencyLevel_MAX = MethodOptions_IdempotencyLevel_IDEMPOTENT;
+const int MethodOptions_IdempotencyLevel_IdempotencyLevel_ARRAYSIZE = MethodOptions_IdempotencyLevel_IdempotencyLevel_MAX + 1;
+
+LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* MethodOptions_IdempotencyLevel_descriptor();
+inline const ::std::string& MethodOptions_IdempotencyLevel_Name(MethodOptions_IdempotencyLevel value) {
+ return ::google::protobuf::internal::NameOfEnum(
+ MethodOptions_IdempotencyLevel_descriptor(), value);
+}
+inline bool MethodOptions_IdempotencyLevel_Parse(
+ const ::std::string& name, MethodOptions_IdempotencyLevel* value) {
+ return ::google::protobuf::internal::ParseNamedEnum<MethodOptions_IdempotencyLevel>(
+ MethodOptions_IdempotencyLevel_descriptor(), name, value);
+}
// ===================================================================
class LIBPROTOBUF_EXPORT FileDescriptorSet : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FileDescriptorSet) */ {
@@ -204,46 +284,53 @@ 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 reinterpret_cast<const FileDescriptorSet*>(
+ &_FileDescriptorSet_default_instance_);
+ }
+
void Swap(FileDescriptorSet* other);
// implements Message ----------------------------------------------
- inline FileDescriptorSet* New() const { return New(NULL); }
+ inline FileDescriptorSet* New() const PROTOBUF_FINAL { return New(NULL); }
- FileDescriptorSet* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ FileDescriptorSet* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const FileDescriptorSet& from);
void MergeFrom(const FileDescriptorSet& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(FileDescriptorSet* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -265,15 +352,10 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static FileDescriptorSet* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -300,75 +382,58 @@ 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 reinterpret_cast<const FileDescriptorProto*>(
+ &_FileDescriptorProto_default_instance_);
+ }
+
void Swap(FileDescriptorProto* other);
// implements Message ----------------------------------------------
- inline FileDescriptorProto* New() const { return New(NULL); }
+ inline FileDescriptorProto* New() const PROTOBUF_FINAL { return New(NULL); }
- FileDescriptorProto* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ FileDescriptorProto* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const FileDescriptorProto& from);
void MergeFrom(const FileDescriptorProto& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(FileDescriptorProto* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional string name = 1;
- bool has_name() const;
- void clear_name();
- static const int kNameFieldNumber = 1;
- const ::std::string& name() const;
- void set_name(const ::std::string& value);
- void set_name(const char* value);
- void set_name(const char* value, size_t size);
- ::std::string* mutable_name();
- ::std::string* release_name();
- void set_allocated_name(::std::string* name);
-
- // optional string package = 2;
- bool has_package() const;
- void clear_package();
- static const int kPackageFieldNumber = 2;
- const ::std::string& package() const;
- void set_package(const ::std::string& value);
- void set_package(const char* value);
- void set_package(const char* value, size_t size);
- ::std::string* mutable_package();
- ::std::string* release_package();
- void set_allocated_package(::std::string* package);
-
// repeated string dependency = 3;
int dependency_size() const;
void clear_dependency();
@@ -376,10 +441,16 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag
const ::std::string& dependency(int index) const;
::std::string* mutable_dependency(int index);
void set_dependency(int index, const ::std::string& value);
+ #if LANG_CXX11
+ void set_dependency(int index, ::std::string&& value);
+ #endif
void set_dependency(int index, const char* value);
void set_dependency(int index, const char* value, size_t size);
::std::string* add_dependency();
void add_dependency(const ::std::string& value);
+ #if LANG_CXX11
+ void add_dependency(::std::string&& value);
+ #endif
void add_dependency(const char* value);
void add_dependency(const char* value, size_t size);
const ::google::protobuf::RepeatedPtrField< ::std::string>& dependency() const;
@@ -457,6 +528,51 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag
const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >&
extension() const;
+ // optional string name = 1;
+ bool has_name() const;
+ void clear_name();
+ static const int kNameFieldNumber = 1;
+ const ::std::string& name() const;
+ void set_name(const ::std::string& value);
+ #if LANG_CXX11
+ void set_name(::std::string&& value);
+ #endif
+ void set_name(const char* value);
+ void set_name(const char* value, size_t size);
+ ::std::string* mutable_name();
+ ::std::string* release_name();
+ void set_allocated_name(::std::string* name);
+
+ // optional string package = 2;
+ bool has_package() const;
+ void clear_package();
+ static const int kPackageFieldNumber = 2;
+ const ::std::string& package() const;
+ void set_package(const ::std::string& value);
+ #if LANG_CXX11
+ void set_package(::std::string&& value);
+ #endif
+ void set_package(const char* value);
+ void set_package(const char* value, size_t size);
+ ::std::string* mutable_package();
+ ::std::string* release_package();
+ void set_allocated_package(::std::string* package);
+
+ // optional string syntax = 12;
+ bool has_syntax() const;
+ void clear_syntax();
+ static const int kSyntaxFieldNumber = 12;
+ const ::std::string& syntax() const;
+ void set_syntax(const ::std::string& value);
+ #if LANG_CXX11
+ void set_syntax(::std::string&& value);
+ #endif
+ void set_syntax(const char* value);
+ void set_syntax(const char* value, size_t size);
+ ::std::string* mutable_syntax();
+ ::std::string* release_syntax();
+ void set_allocated_syntax(::std::string* syntax);
+
// optional .google.protobuf.FileOptions options = 8;
bool has_options() const;
void clear_options();
@@ -475,36 +591,22 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag
::google::protobuf::SourceCodeInfo* release_source_code_info();
void set_allocated_source_code_info(::google::protobuf::SourceCodeInfo* source_code_info);
- // optional string syntax = 12;
- bool has_syntax() const;
- void clear_syntax();
- static const int kSyntaxFieldNumber = 12;
- const ::std::string& syntax() const;
- void set_syntax(const ::std::string& value);
- void set_syntax(const char* value);
- void set_syntax(const char* value, size_t size);
- ::std::string* mutable_syntax();
- ::std::string* release_syntax();
- void set_allocated_syntax(::std::string* syntax);
-
// @@protoc_insertion_point(class_scope:google.protobuf.FileDescriptorProto)
private:
- inline void set_has_name();
- inline void clear_has_name();
- inline void set_has_package();
- inline void clear_has_package();
- inline void set_has_options();
- inline void clear_has_options();
- inline void set_has_source_code_info();
- inline void clear_has_source_code_info();
- inline void set_has_syntax();
- inline void clear_has_syntax();
+ void set_has_name();
+ void clear_has_name();
+ void set_has_package();
+ void clear_has_package();
+ void set_has_options();
+ void clear_has_options();
+ void set_has_source_code_info();
+ void clear_has_source_code_info();
+ void set_has_syntax();
+ 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 +614,12 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static FileDescriptorProto* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -547,46 +646,53 @@ 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 reinterpret_cast<const DescriptorProto_ExtensionRange*>(
+ &_DescriptorProto_ExtensionRange_default_instance_);
+ }
+
void Swap(DescriptorProto_ExtensionRange* other);
// implements Message ----------------------------------------------
- inline DescriptorProto_ExtensionRange* New() const { return New(NULL); }
+ inline DescriptorProto_ExtensionRange* New() const PROTOBUF_FINAL { return New(NULL); }
- DescriptorProto_ExtensionRange* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ DescriptorProto_ExtensionRange* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const DescriptorProto_ExtensionRange& from);
void MergeFrom(const DescriptorProto_ExtensionRange& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(DescriptorProto_ExtensionRange* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -608,22 +714,17 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::proto
// @@protoc_insertion_point(class_scope:google.protobuf.DescriptorProto.ExtensionRange)
private:
- inline void set_has_start();
- inline void clear_has_start();
- inline void set_has_end();
- inline void clear_has_end();
+ void set_has_start();
+ void clear_has_start();
+ void set_has_end();
+ 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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static DescriptorProto_ExtensionRange* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -650,46 +751,53 @@ 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 reinterpret_cast<const DescriptorProto_ReservedRange*>(
+ &_DescriptorProto_ReservedRange_default_instance_);
+ }
+
void Swap(DescriptorProto_ReservedRange* other);
// implements Message ----------------------------------------------
- inline DescriptorProto_ReservedRange* New() const { return New(NULL); }
+ inline DescriptorProto_ReservedRange* New() const PROTOBUF_FINAL { return New(NULL); }
- DescriptorProto_ReservedRange* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ DescriptorProto_ReservedRange* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const DescriptorProto_ReservedRange& from);
void MergeFrom(const DescriptorProto_ReservedRange& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(DescriptorProto_ReservedRange* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -711,22 +819,17 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ReservedRange : public ::google::protob
// @@protoc_insertion_point(class_scope:google.protobuf.DescriptorProto.ReservedRange)
private:
- inline void set_has_start();
- inline void clear_has_start();
- inline void set_has_end();
- inline void clear_has_end();
+ void set_has_start();
+ void clear_has_start();
+ void set_has_end();
+ 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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static DescriptorProto_ReservedRange* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -753,46 +856,53 @@ 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 reinterpret_cast<const DescriptorProto*>(
+ &_DescriptorProto_default_instance_);
+ }
+
void Swap(DescriptorProto* other);
// implements Message ----------------------------------------------
- inline DescriptorProto* New() const { return New(NULL); }
+ inline DescriptorProto* New() const PROTOBUF_FINAL { return New(NULL); }
- DescriptorProto* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ DescriptorProto* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const DescriptorProto& from);
void MergeFrom(const DescriptorProto& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(DescriptorProto* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -801,18 +911,6 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /*
// accessors -------------------------------------------------------
- // optional string name = 1;
- bool has_name() const;
- void clear_name();
- static const int kNameFieldNumber = 1;
- const ::std::string& name() const;
- void set_name(const ::std::string& value);
- void set_name(const char* value);
- void set_name(const char* value, size_t size);
- ::std::string* mutable_name();
- ::std::string* release_name();
- void set_allocated_name(::std::string* name);
-
// repeated .google.protobuf.FieldDescriptorProto field = 2;
int field_size() const;
void clear_field();
@@ -885,15 +983,6 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /*
const ::google::protobuf::RepeatedPtrField< ::google::protobuf::OneofDescriptorProto >&
oneof_decl() const;
- // optional .google.protobuf.MessageOptions options = 7;
- bool has_options() const;
- void clear_options();
- static const int kOptionsFieldNumber = 7;
- const ::google::protobuf::MessageOptions& options() const;
- ::google::protobuf::MessageOptions* mutable_options();
- ::google::protobuf::MessageOptions* release_options();
- void set_allocated_options(::google::protobuf::MessageOptions* options);
-
// repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9;
int reserved_range_size() const;
void clear_reserved_range();
@@ -913,41 +1002,66 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /*
const ::std::string& reserved_name(int index) const;
::std::string* mutable_reserved_name(int index);
void set_reserved_name(int index, const ::std::string& value);
+ #if LANG_CXX11
+ void set_reserved_name(int index, ::std::string&& value);
+ #endif
void set_reserved_name(int index, const char* value);
void set_reserved_name(int index, const char* value, size_t size);
::std::string* add_reserved_name();
void add_reserved_name(const ::std::string& value);
+ #if LANG_CXX11
+ void add_reserved_name(::std::string&& value);
+ #endif
void add_reserved_name(const char* value);
void add_reserved_name(const char* value, size_t size);
const ::google::protobuf::RepeatedPtrField< ::std::string>& reserved_name() const;
::google::protobuf::RepeatedPtrField< ::std::string>* mutable_reserved_name();
+ // optional string name = 1;
+ bool has_name() const;
+ void clear_name();
+ static const int kNameFieldNumber = 1;
+ const ::std::string& name() const;
+ void set_name(const ::std::string& value);
+ #if LANG_CXX11
+ void set_name(::std::string&& value);
+ #endif
+ void set_name(const char* value);
+ void set_name(const char* value, size_t size);
+ ::std::string* mutable_name();
+ ::std::string* release_name();
+ void set_allocated_name(::std::string* name);
+
+ // optional .google.protobuf.MessageOptions options = 7;
+ bool has_options() const;
+ void clear_options();
+ static const int kOptionsFieldNumber = 7;
+ const ::google::protobuf::MessageOptions& options() const;
+ ::google::protobuf::MessageOptions* mutable_options();
+ ::google::protobuf::MessageOptions* release_options();
+ void set_allocated_options(::google::protobuf::MessageOptions* options);
+
// @@protoc_insertion_point(class_scope:google.protobuf.DescriptorProto)
private:
- inline void set_has_name();
- inline void clear_has_name();
- inline void set_has_options();
- inline void clear_has_options();
+ void set_has_name();
+ void clear_has_name();
+ void set_has_options();
+ 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();
- friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static DescriptorProto* default_instance_;
+ ::google::protobuf::internal::ArenaStringPtr name_;
+ ::google::protobuf::MessageOptions* options_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -974,46 +1088,53 @@ 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 reinterpret_cast<const FieldDescriptorProto*>(
+ &_FieldDescriptorProto_default_instance_);
+ }
+
void Swap(FieldDescriptorProto* other);
// implements Message ----------------------------------------------
- inline FieldDescriptorProto* New() const { return New(NULL); }
+ inline FieldDescriptorProto* New() const PROTOBUF_FINAL { return New(NULL); }
- FieldDescriptorProto* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ FieldDescriptorProto* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const FieldDescriptorProto& from);
void MergeFrom(const FieldDescriptorProto& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(FieldDescriptorProto* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -1111,39 +1232,24 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa
static const int kNameFieldNumber = 1;
const ::std::string& name() const;
void set_name(const ::std::string& value);
+ #if LANG_CXX11
+ void set_name(::std::string&& value);
+ #endif
void set_name(const char* value);
void set_name(const char* value, size_t size);
::std::string* mutable_name();
::std::string* release_name();
void set_allocated_name(::std::string* name);
- // optional int32 number = 3;
- bool has_number() const;
- void clear_number();
- static const int kNumberFieldNumber = 3;
- ::google::protobuf::int32 number() const;
- void set_number(::google::protobuf::int32 value);
-
- // optional .google.protobuf.FieldDescriptorProto.Label label = 4;
- bool has_label() const;
- void clear_label();
- static const int kLabelFieldNumber = 4;
- ::google::protobuf::FieldDescriptorProto_Label label() const;
- void set_label(::google::protobuf::FieldDescriptorProto_Label value);
-
- // optional .google.protobuf.FieldDescriptorProto.Type type = 5;
- bool has_type() const;
- void clear_type();
- static const int kTypeFieldNumber = 5;
- ::google::protobuf::FieldDescriptorProto_Type type() const;
- void set_type(::google::protobuf::FieldDescriptorProto_Type value);
-
// optional string type_name = 6;
bool has_type_name() const;
void clear_type_name();
static const int kTypeNameFieldNumber = 6;
const ::std::string& type_name() const;
void set_type_name(const ::std::string& value);
+ #if LANG_CXX11
+ void set_type_name(::std::string&& value);
+ #endif
void set_type_name(const char* value);
void set_type_name(const char* value, size_t size);
::std::string* mutable_type_name();
@@ -1156,6 +1262,9 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa
static const int kExtendeeFieldNumber = 2;
const ::std::string& extendee() const;
void set_extendee(const ::std::string& value);
+ #if LANG_CXX11
+ void set_extendee(::std::string&& value);
+ #endif
void set_extendee(const char* value);
void set_extendee(const char* value, size_t size);
::std::string* mutable_extendee();
@@ -1168,25 +1277,24 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa
static const int kDefaultValueFieldNumber = 7;
const ::std::string& default_value() const;
void set_default_value(const ::std::string& value);
+ #if LANG_CXX11
+ void set_default_value(::std::string&& value);
+ #endif
void set_default_value(const char* value);
void set_default_value(const char* value, size_t size);
::std::string* mutable_default_value();
::std::string* release_default_value();
void set_allocated_default_value(::std::string* default_value);
- // optional int32 oneof_index = 9;
- bool has_oneof_index() const;
- void clear_oneof_index();
- static const int kOneofIndexFieldNumber = 9;
- ::google::protobuf::int32 oneof_index() const;
- void set_oneof_index(::google::protobuf::int32 value);
-
// optional string json_name = 10;
bool has_json_name() const;
void clear_json_name();
static const int kJsonNameFieldNumber = 10;
const ::std::string& json_name() const;
void set_json_name(const ::std::string& value);
+ #if LANG_CXX11
+ void set_json_name(::std::string&& value);
+ #endif
void set_json_name(const char* value);
void set_json_name(const char* value, size_t size);
::std::string* mutable_json_name();
@@ -1202,48 +1310,71 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa
::google::protobuf::FieldOptions* release_options();
void set_allocated_options(::google::protobuf::FieldOptions* options);
+ // optional int32 number = 3;
+ bool has_number() const;
+ void clear_number();
+ static const int kNumberFieldNumber = 3;
+ ::google::protobuf::int32 number() const;
+ void set_number(::google::protobuf::int32 value);
+
+ // optional int32 oneof_index = 9;
+ bool has_oneof_index() const;
+ void clear_oneof_index();
+ static const int kOneofIndexFieldNumber = 9;
+ ::google::protobuf::int32 oneof_index() const;
+ void set_oneof_index(::google::protobuf::int32 value);
+
+ // optional .google.protobuf.FieldDescriptorProto.Label label = 4;
+ bool has_label() const;
+ void clear_label();
+ static const int kLabelFieldNumber = 4;
+ ::google::protobuf::FieldDescriptorProto_Label label() const;
+ void set_label(::google::protobuf::FieldDescriptorProto_Label value);
+
+ // optional .google.protobuf.FieldDescriptorProto.Type type = 5;
+ bool has_type() const;
+ void clear_type();
+ static const int kTypeFieldNumber = 5;
+ ::google::protobuf::FieldDescriptorProto_Type type() const;
+ void set_type(::google::protobuf::FieldDescriptorProto_Type value);
+
// @@protoc_insertion_point(class_scope:google.protobuf.FieldDescriptorProto)
private:
- inline void set_has_name();
- inline void clear_has_name();
- inline void set_has_number();
- inline void clear_has_number();
- inline void set_has_label();
- inline void clear_has_label();
- inline void set_has_type();
- inline void clear_has_type();
- inline void set_has_type_name();
- inline void clear_has_type_name();
- inline void set_has_extendee();
- inline void clear_has_extendee();
- inline void set_has_default_value();
- inline void clear_has_default_value();
- inline void set_has_oneof_index();
- inline void clear_has_oneof_index();
- inline void set_has_json_name();
- inline void clear_has_json_name();
- inline void set_has_options();
- inline void clear_has_options();
+ void set_has_name();
+ void clear_has_name();
+ void set_has_number();
+ void clear_has_number();
+ void set_has_label();
+ void clear_has_label();
+ void set_has_type();
+ void clear_has_type();
+ void set_has_type_name();
+ void clear_has_type_name();
+ void set_has_extendee();
+ void clear_has_extendee();
+ void set_has_default_value();
+ void clear_has_default_value();
+ void set_has_oneof_index();
+ void clear_has_oneof_index();
+ void set_has_json_name();
+ void clear_has_json_name();
+ void set_has_options();
+ 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();
- friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static FieldDescriptorProto* default_instance_;
+ ::google::protobuf::int32 number_;
+ ::google::protobuf::int32 oneof_index_;
+ int label_;
+ int type_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -1270,46 +1401,53 @@ 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 reinterpret_cast<const OneofDescriptorProto*>(
+ &_OneofDescriptorProto_default_instance_);
+ }
+
void Swap(OneofDescriptorProto* other);
// implements Message ----------------------------------------------
- inline OneofDescriptorProto* New() const { return New(NULL); }
+ inline OneofDescriptorProto* New() const PROTOBUF_FINAL { return New(NULL); }
- OneofDescriptorProto* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ OneofDescriptorProto* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const OneofDescriptorProto& from);
void MergeFrom(const OneofDescriptorProto& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(OneofDescriptorProto* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -1321,6 +1459,9 @@ class LIBPROTOBUF_EXPORT OneofDescriptorProto : public ::google::protobuf::Messa
static const int kNameFieldNumber = 1;
const ::std::string& name() const;
void set_name(const ::std::string& value);
+ #if LANG_CXX11
+ void set_name(::std::string&& value);
+ #endif
void set_name(const char* value);
void set_name(const char* value, size_t size);
::std::string* mutable_name();
@@ -1338,22 +1479,17 @@ class LIBPROTOBUF_EXPORT OneofDescriptorProto : public ::google::protobuf::Messa
// @@protoc_insertion_point(class_scope:google.protobuf.OneofDescriptorProto)
private:
- inline void set_has_name();
- inline void clear_has_name();
- inline void set_has_options();
- inline void clear_has_options();
+ void set_has_name();
+ void clear_has_name();
+ void set_has_options();
+ 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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static OneofDescriptorProto* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -1380,63 +1516,58 @@ 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 reinterpret_cast<const EnumDescriptorProto*>(
+ &_EnumDescriptorProto_default_instance_);
+ }
+
void Swap(EnumDescriptorProto* other);
// implements Message ----------------------------------------------
- inline EnumDescriptorProto* New() const { return New(NULL); }
+ inline EnumDescriptorProto* New() const PROTOBUF_FINAL { return New(NULL); }
- EnumDescriptorProto* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ EnumDescriptorProto* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const EnumDescriptorProto& from);
void MergeFrom(const EnumDescriptorProto& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(EnumDescriptorProto* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional string name = 1;
- bool has_name() const;
- void clear_name();
- static const int kNameFieldNumber = 1;
- const ::std::string& name() const;
- void set_name(const ::std::string& value);
- void set_name(const char* value);
- void set_name(const char* value, size_t size);
- ::std::string* mutable_name();
- ::std::string* release_name();
- void set_allocated_name(::std::string* name);
-
// repeated .google.protobuf.EnumValueDescriptorProto value = 2;
int value_size() const;
void clear_value();
@@ -1449,6 +1580,21 @@ class LIBPROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Messag
const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValueDescriptorProto >&
value() const;
+ // optional string name = 1;
+ bool has_name() const;
+ void clear_name();
+ static const int kNameFieldNumber = 1;
+ const ::std::string& name() const;
+ void set_name(const ::std::string& value);
+ #if LANG_CXX11
+ void set_name(::std::string&& value);
+ #endif
+ void set_name(const char* value);
+ void set_name(const char* value, size_t size);
+ ::std::string* mutable_name();
+ ::std::string* release_name();
+ void set_allocated_name(::std::string* name);
+
// optional .google.protobuf.EnumOptions options = 3;
bool has_options() const;
void clear_options();
@@ -1460,23 +1606,18 @@ class LIBPROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Messag
// @@protoc_insertion_point(class_scope:google.protobuf.EnumDescriptorProto)
private:
- inline void set_has_name();
- inline void clear_has_name();
- inline void set_has_options();
- inline void clear_has_options();
+ void set_has_name();
+ void clear_has_name();
+ void set_has_options();
+ 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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static EnumDescriptorProto* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -1503,46 +1644,53 @@ 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 reinterpret_cast<const EnumValueDescriptorProto*>(
+ &_EnumValueDescriptorProto_default_instance_);
+ }
+
void Swap(EnumValueDescriptorProto* other);
// implements Message ----------------------------------------------
- inline EnumValueDescriptorProto* New() const { return New(NULL); }
+ inline EnumValueDescriptorProto* New() const PROTOBUF_FINAL { return New(NULL); }
- EnumValueDescriptorProto* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ EnumValueDescriptorProto* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const EnumValueDescriptorProto& from);
void MergeFrom(const EnumValueDescriptorProto& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(EnumValueDescriptorProto* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -1554,19 +1702,15 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::M
static const int kNameFieldNumber = 1;
const ::std::string& name() const;
void set_name(const ::std::string& value);
+ #if LANG_CXX11
+ void set_name(::std::string&& value);
+ #endif
void set_name(const char* value);
void set_name(const char* value, size_t size);
::std::string* mutable_name();
::std::string* release_name();
void set_allocated_name(::std::string* name);
- // optional int32 number = 2;
- bool has_number() const;
- void clear_number();
- static const int kNumberFieldNumber = 2;
- ::google::protobuf::int32 number() const;
- void set_number(::google::protobuf::int32 value);
-
// optional .google.protobuf.EnumValueOptions options = 3;
bool has_options() const;
void clear_options();
@@ -1576,27 +1720,29 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::M
::google::protobuf::EnumValueOptions* release_options();
void set_allocated_options(::google::protobuf::EnumValueOptions* options);
+ // optional int32 number = 2;
+ bool has_number() const;
+ void clear_number();
+ static const int kNumberFieldNumber = 2;
+ ::google::protobuf::int32 number() const;
+ void set_number(::google::protobuf::int32 value);
+
// @@protoc_insertion_point(class_scope:google.protobuf.EnumValueDescriptorProto)
private:
- inline void set_has_name();
- inline void clear_has_name();
- inline void set_has_number();
- inline void clear_has_number();
- inline void set_has_options();
- inline void clear_has_options();
+ void set_has_name();
+ void clear_has_name();
+ void set_has_number();
+ void clear_has_number();
+ void set_has_options();
+ 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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static EnumValueDescriptorProto* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -1623,63 +1769,58 @@ 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 reinterpret_cast<const ServiceDescriptorProto*>(
+ &_ServiceDescriptorProto_default_instance_);
+ }
+
void Swap(ServiceDescriptorProto* other);
// implements Message ----------------------------------------------
- inline ServiceDescriptorProto* New() const { return New(NULL); }
+ inline ServiceDescriptorProto* New() const PROTOBUF_FINAL { return New(NULL); }
- ServiceDescriptorProto* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ ServiceDescriptorProto* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const ServiceDescriptorProto& from);
void MergeFrom(const ServiceDescriptorProto& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(ServiceDescriptorProto* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional string name = 1;
- bool has_name() const;
- void clear_name();
- static const int kNameFieldNumber = 1;
- const ::std::string& name() const;
- void set_name(const ::std::string& value);
- void set_name(const char* value);
- void set_name(const char* value, size_t size);
- ::std::string* mutable_name();
- ::std::string* release_name();
- void set_allocated_name(::std::string* name);
-
// repeated .google.protobuf.MethodDescriptorProto method = 2;
int method_size() const;
void clear_method();
@@ -1692,6 +1833,21 @@ class LIBPROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Mes
const ::google::protobuf::RepeatedPtrField< ::google::protobuf::MethodDescriptorProto >&
method() const;
+ // optional string name = 1;
+ bool has_name() const;
+ void clear_name();
+ static const int kNameFieldNumber = 1;
+ const ::std::string& name() const;
+ void set_name(const ::std::string& value);
+ #if LANG_CXX11
+ void set_name(::std::string&& value);
+ #endif
+ void set_name(const char* value);
+ void set_name(const char* value, size_t size);
+ ::std::string* mutable_name();
+ ::std::string* release_name();
+ void set_allocated_name(::std::string* name);
+
// optional .google.protobuf.ServiceOptions options = 3;
bool has_options() const;
void clear_options();
@@ -1703,23 +1859,18 @@ class LIBPROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Mes
// @@protoc_insertion_point(class_scope:google.protobuf.ServiceDescriptorProto)
private:
- inline void set_has_name();
- inline void clear_has_name();
- inline void set_has_options();
- inline void clear_has_options();
+ void set_has_name();
+ void clear_has_name();
+ void set_has_options();
+ 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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static ServiceDescriptorProto* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -1746,46 +1897,53 @@ 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 reinterpret_cast<const MethodDescriptorProto*>(
+ &_MethodDescriptorProto_default_instance_);
+ }
+
void Swap(MethodDescriptorProto* other);
// implements Message ----------------------------------------------
- inline MethodDescriptorProto* New() const { return New(NULL); }
+ inline MethodDescriptorProto* New() const PROTOBUF_FINAL { return New(NULL); }
- MethodDescriptorProto* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ MethodDescriptorProto* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const MethodDescriptorProto& from);
void MergeFrom(const MethodDescriptorProto& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(MethodDescriptorProto* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -1797,6 +1955,9 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess
static const int kNameFieldNumber = 1;
const ::std::string& name() const;
void set_name(const ::std::string& value);
+ #if LANG_CXX11
+ void set_name(::std::string&& value);
+ #endif
void set_name(const char* value);
void set_name(const char* value, size_t size);
::std::string* mutable_name();
@@ -1809,6 +1970,9 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess
static const int kInputTypeFieldNumber = 2;
const ::std::string& input_type() const;
void set_input_type(const ::std::string& value);
+ #if LANG_CXX11
+ void set_input_type(::std::string&& value);
+ #endif
void set_input_type(const char* value);
void set_input_type(const char* value, size_t size);
::std::string* mutable_input_type();
@@ -1821,6 +1985,9 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess
static const int kOutputTypeFieldNumber = 3;
const ::std::string& output_type() const;
void set_output_type(const ::std::string& value);
+ #if LANG_CXX11
+ void set_output_type(::std::string&& value);
+ #endif
void set_output_type(const char* value);
void set_output_type(const char* value, size_t size);
::std::string* mutable_output_type();
@@ -1852,21 +2019,21 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess
// @@protoc_insertion_point(class_scope:google.protobuf.MethodDescriptorProto)
private:
- inline void set_has_name();
- inline void clear_has_name();
- inline void set_has_input_type();
- inline void clear_has_input_type();
- inline void set_has_output_type();
- inline void clear_has_output_type();
- inline void set_has_options();
- inline void clear_has_options();
- inline void set_has_client_streaming();
- inline void clear_has_client_streaming();
- inline void set_has_server_streaming();
- inline void clear_has_server_streaming();
+ void set_has_name();
+ void clear_has_name();
+ void set_has_input_type();
+ void clear_has_input_type();
+ void set_has_output_type();
+ void clear_has_output_type();
+ void set_has_options();
+ void clear_has_options();
+ void set_has_client_streaming();
+ void clear_has_client_streaming();
+ void set_has_server_streaming();
+ 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 +2041,7 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static MethodDescriptorProto* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -1906,46 +2068,53 @@ 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 reinterpret_cast<const FileOptions*>(
+ &_FileOptions_default_instance_);
+ }
+
void Swap(FileOptions* other);
// implements Message ----------------------------------------------
- inline FileOptions* New() const { return New(NULL); }
+ inline FileOptions* New() const PROTOBUF_FINAL { return New(NULL); }
- FileOptions* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ FileOptions* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const FileOptions& from);
void MergeFrom(const FileOptions& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(FileOptions* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -1979,12 +2148,27 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p
// accessors -------------------------------------------------------
+ // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
+ int uninterpreted_option_size() const;
+ void clear_uninterpreted_option();
+ static const int kUninterpretedOptionFieldNumber = 999;
+ const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const;
+ ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index);
+ ::google::protobuf::UninterpretedOption* add_uninterpreted_option();
+ ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >*
+ mutable_uninterpreted_option();
+ const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >&
+ uninterpreted_option() const;
+
// optional string java_package = 1;
bool has_java_package() const;
void clear_java_package();
static const int kJavaPackageFieldNumber = 1;
const ::std::string& java_package() const;
void set_java_package(const ::std::string& value);
+ #if LANG_CXX11
+ void set_java_package(::std::string&& value);
+ #endif
void set_java_package(const char* value);
void set_java_package(const char* value, size_t size);
::std::string* mutable_java_package();
@@ -1997,12 +2181,90 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p
static const int kJavaOuterClassnameFieldNumber = 8;
const ::std::string& java_outer_classname() const;
void set_java_outer_classname(const ::std::string& value);
+ #if LANG_CXX11
+ void set_java_outer_classname(::std::string&& value);
+ #endif
void set_java_outer_classname(const char* value);
void set_java_outer_classname(const char* value, size_t size);
::std::string* mutable_java_outer_classname();
::std::string* release_java_outer_classname();
void set_allocated_java_outer_classname(::std::string* java_outer_classname);
+ // optional string go_package = 11;
+ bool has_go_package() const;
+ void clear_go_package();
+ static const int kGoPackageFieldNumber = 11;
+ const ::std::string& go_package() const;
+ void set_go_package(const ::std::string& value);
+ #if LANG_CXX11
+ void set_go_package(::std::string&& value);
+ #endif
+ void set_go_package(const char* value);
+ void set_go_package(const char* value, size_t size);
+ ::std::string* mutable_go_package();
+ ::std::string* release_go_package();
+ void set_allocated_go_package(::std::string* go_package);
+
+ // optional string objc_class_prefix = 36;
+ bool has_objc_class_prefix() const;
+ void clear_objc_class_prefix();
+ static const int kObjcClassPrefixFieldNumber = 36;
+ const ::std::string& objc_class_prefix() const;
+ void set_objc_class_prefix(const ::std::string& value);
+ #if LANG_CXX11
+ void set_objc_class_prefix(::std::string&& value);
+ #endif
+ void set_objc_class_prefix(const char* value);
+ void set_objc_class_prefix(const char* value, size_t size);
+ ::std::string* mutable_objc_class_prefix();
+ ::std::string* release_objc_class_prefix();
+ void set_allocated_objc_class_prefix(::std::string* objc_class_prefix);
+
+ // optional string csharp_namespace = 37;
+ bool has_csharp_namespace() const;
+ void clear_csharp_namespace();
+ static const int kCsharpNamespaceFieldNumber = 37;
+ const ::std::string& csharp_namespace() const;
+ void set_csharp_namespace(const ::std::string& value);
+ #if LANG_CXX11
+ void set_csharp_namespace(::std::string&& value);
+ #endif
+ void set_csharp_namespace(const char* value);
+ void set_csharp_namespace(const char* value, size_t size);
+ ::std::string* mutable_csharp_namespace();
+ ::std::string* release_csharp_namespace();
+ void set_allocated_csharp_namespace(::std::string* csharp_namespace);
+
+ // optional string swift_prefix = 39;
+ bool has_swift_prefix() const;
+ void clear_swift_prefix();
+ static const int kSwiftPrefixFieldNumber = 39;
+ const ::std::string& swift_prefix() const;
+ void set_swift_prefix(const ::std::string& value);
+ #if LANG_CXX11
+ void set_swift_prefix(::std::string&& value);
+ #endif
+ void set_swift_prefix(const char* value);
+ void set_swift_prefix(const char* value, size_t size);
+ ::std::string* mutable_swift_prefix();
+ ::std::string* release_swift_prefix();
+ void set_allocated_swift_prefix(::std::string* swift_prefix);
+
+ // optional string php_class_prefix = 40;
+ bool has_php_class_prefix() const;
+ void clear_php_class_prefix();
+ static const int kPhpClassPrefixFieldNumber = 40;
+ const ::std::string& php_class_prefix() const;
+ void set_php_class_prefix(const ::std::string& value);
+ #if LANG_CXX11
+ void set_php_class_prefix(::std::string&& value);
+ #endif
+ void set_php_class_prefix(const char* value);
+ void set_php_class_prefix(const char* value, size_t size);
+ ::std::string* mutable_php_class_prefix();
+ ::std::string* release_php_class_prefix();
+ void set_allocated_php_class_prefix(::std::string* php_class_prefix);
+
// optional bool java_multiple_files = 10 [default = false];
bool has_java_multiple_files() const;
void clear_java_multiple_files();
@@ -2010,12 +2272,12 @@ 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_generate_equals_and_hash = 20 [deprecated = true];
+ GOOGLE_PROTOBUF_DEPRECATED_ATTR bool has_java_generate_equals_and_hash() const;
+ GOOGLE_PROTOBUF_DEPRECATED_ATTR void clear_java_generate_equals_and_hash();
+ GOOGLE_PROTOBUF_DEPRECATED_ATTR static const int kJavaGenerateEqualsAndHashFieldNumber = 20;
+ GOOGLE_PROTOBUF_DEPRECATED_ATTR bool java_generate_equals_and_hash() const;
+ GOOGLE_PROTOBUF_DEPRECATED_ATTR 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;
@@ -2024,25 +2286,6 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p
bool java_string_check_utf8() const;
void set_java_string_check_utf8(bool value);
- // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED];
- bool has_optimize_for() const;
- void clear_optimize_for();
- static const int kOptimizeForFieldNumber = 9;
- ::google::protobuf::FileOptions_OptimizeMode optimize_for() const;
- void set_optimize_for(::google::protobuf::FileOptions_OptimizeMode value);
-
- // optional string go_package = 11;
- bool has_go_package() const;
- void clear_go_package();
- static const int kGoPackageFieldNumber = 11;
- const ::std::string& go_package() const;
- void set_go_package(const ::std::string& value);
- void set_go_package(const char* value);
- void set_go_package(const char* value, size_t size);
- ::std::string* mutable_go_package();
- ::std::string* release_go_package();
- void set_allocated_go_package(::std::string* go_package);
-
// optional bool cc_generic_services = 16 [default = false];
bool has_cc_generic_services() const;
void clear_cc_generic_services();
@@ -2078,100 +2321,72 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p
bool cc_enable_arenas() const;
void set_cc_enable_arenas(bool value);
- // optional string objc_class_prefix = 36;
- bool has_objc_class_prefix() const;
- void clear_objc_class_prefix();
- static const int kObjcClassPrefixFieldNumber = 36;
- const ::std::string& objc_class_prefix() const;
- void set_objc_class_prefix(const ::std::string& value);
- void set_objc_class_prefix(const char* value);
- void set_objc_class_prefix(const char* value, size_t size);
- ::std::string* mutable_objc_class_prefix();
- ::std::string* release_objc_class_prefix();
- void set_allocated_objc_class_prefix(::std::string* objc_class_prefix);
-
- // optional string csharp_namespace = 37;
- bool has_csharp_namespace() const;
- void clear_csharp_namespace();
- static const int kCsharpNamespaceFieldNumber = 37;
- const ::std::string& csharp_namespace() const;
- void set_csharp_namespace(const ::std::string& value);
- void set_csharp_namespace(const char* value);
- void set_csharp_namespace(const char* value, size_t size);
- ::std::string* mutable_csharp_namespace();
- ::std::string* release_csharp_namespace();
- void set_allocated_csharp_namespace(::std::string* csharp_namespace);
-
- // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
- int uninterpreted_option_size() const;
- void clear_uninterpreted_option();
- static const int kUninterpretedOptionFieldNumber = 999;
- const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const;
- ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index);
- ::google::protobuf::UninterpretedOption* add_uninterpreted_option();
- ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >*
- mutable_uninterpreted_option();
- const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >&
- uninterpreted_option() const;
+ // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED];
+ bool has_optimize_for() const;
+ void clear_optimize_for();
+ static const int kOptimizeForFieldNumber = 9;
+ ::google::protobuf::FileOptions_OptimizeMode optimize_for() const;
+ void set_optimize_for(::google::protobuf::FileOptions_OptimizeMode value);
GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(FileOptions)
// @@protoc_insertion_point(class_scope:google.protobuf.FileOptions)
private:
- inline void set_has_java_package();
- inline void clear_has_java_package();
- inline void set_has_java_outer_classname();
- 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();
- inline void clear_has_optimize_for();
- inline void set_has_go_package();
- inline void clear_has_go_package();
- inline void set_has_cc_generic_services();
- inline void clear_has_cc_generic_services();
- inline void set_has_java_generic_services();
- inline void clear_has_java_generic_services();
- inline void set_has_py_generic_services();
- inline void clear_has_py_generic_services();
- inline void set_has_deprecated();
- inline void clear_has_deprecated();
- inline void set_has_cc_enable_arenas();
- inline void clear_has_cc_enable_arenas();
- inline void set_has_objc_class_prefix();
- inline void clear_has_objc_class_prefix();
- inline void set_has_csharp_namespace();
- inline void clear_has_csharp_namespace();
+ void set_has_java_package();
+ void clear_has_java_package();
+ void set_has_java_outer_classname();
+ void clear_has_java_outer_classname();
+ void set_has_java_multiple_files();
+ void clear_has_java_multiple_files();
+ void set_has_java_generate_equals_and_hash();
+ void clear_has_java_generate_equals_and_hash();
+ void set_has_java_string_check_utf8();
+ void clear_has_java_string_check_utf8();
+ void set_has_optimize_for();
+ void clear_has_optimize_for();
+ void set_has_go_package();
+ void clear_has_go_package();
+ void set_has_cc_generic_services();
+ void clear_has_cc_generic_services();
+ void set_has_java_generic_services();
+ void clear_has_java_generic_services();
+ void set_has_py_generic_services();
+ void clear_has_py_generic_services();
+ void set_has_deprecated();
+ void clear_has_deprecated();
+ void set_has_cc_enable_arenas();
+ void clear_has_cc_enable_arenas();
+ void set_has_objc_class_prefix();
+ void clear_has_objc_class_prefix();
+ void set_has_csharp_namespace();
+ void clear_has_csharp_namespace();
+ void set_has_swift_prefix();
+ void clear_has_swift_prefix();
+ void set_has_php_class_prefix();
+ void clear_has_php_class_prefix();
::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_;
+ ::google::protobuf::internal::ArenaStringPtr go_package_;
+ ::google::protobuf::internal::ArenaStringPtr objc_class_prefix_;
+ ::google::protobuf::internal::ArenaStringPtr csharp_namespace_;
+ ::google::protobuf::internal::ArenaStringPtr swift_prefix_;
+ ::google::protobuf::internal::ArenaStringPtr php_class_prefix_;
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_generic_services_;
bool py_generic_services_;
bool deprecated_;
bool cc_enable_arenas_;
- friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static FileOptions* default_instance_;
+ int optimize_for_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -2198,51 +2413,70 @@ 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 reinterpret_cast<const MessageOptions*>(
+ &_MessageOptions_default_instance_);
+ }
+
void Swap(MessageOptions* other);
// implements Message ----------------------------------------------
- inline MessageOptions* New() const { return New(NULL); }
+ inline MessageOptions* New() const PROTOBUF_FINAL { return New(NULL); }
- MessageOptions* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ MessageOptions* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const MessageOptions& from);
void MergeFrom(const MessageOptions& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(MessageOptions* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
+ // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
+ int uninterpreted_option_size() const;
+ void clear_uninterpreted_option();
+ static const int kUninterpretedOptionFieldNumber = 999;
+ const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const;
+ ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index);
+ ::google::protobuf::UninterpretedOption* add_uninterpreted_option();
+ ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >*
+ mutable_uninterpreted_option();
+ const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >&
+ uninterpreted_option() const;
+
// optional bool message_set_wire_format = 1 [default = false];
bool has_message_set_wire_format() const;
void clear_message_set_wire_format();
@@ -2271,46 +2505,29 @@ class LIBPROTOBUF_EXPORT MessageOptions : public ::google::protobuf::Message /*
bool map_entry() const;
void set_map_entry(bool value);
- // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
- int uninterpreted_option_size() const;
- void clear_uninterpreted_option();
- static const int kUninterpretedOptionFieldNumber = 999;
- const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const;
- ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index);
- ::google::protobuf::UninterpretedOption* add_uninterpreted_option();
- ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >*
- mutable_uninterpreted_option();
- const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >&
- uninterpreted_option() const;
-
GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(MessageOptions)
// @@protoc_insertion_point(class_scope:google.protobuf.MessageOptions)
private:
- inline void set_has_message_set_wire_format();
- inline void clear_has_message_set_wire_format();
- inline void set_has_no_standard_descriptor_accessor();
- inline void clear_has_no_standard_descriptor_accessor();
- inline void set_has_deprecated();
- inline void clear_has_deprecated();
- inline void set_has_map_entry();
- inline void clear_has_map_entry();
+ void set_has_message_set_wire_format();
+ void clear_has_message_set_wire_format();
+ void set_has_no_standard_descriptor_accessor();
+ void clear_has_no_standard_descriptor_accessor();
+ void set_has_deprecated();
+ void clear_has_deprecated();
+ void set_has_map_entry();
+ void clear_has_map_entry();
::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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static MessageOptions* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -2337,46 +2554,53 @@ 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 reinterpret_cast<const FieldOptions*>(
+ &_FieldOptions_default_instance_);
+ }
+
void Swap(FieldOptions* other);
// implements Message ----------------------------------------------
- inline FieldOptions* New() const { return New(NULL); }
+ inline FieldOptions* New() const PROTOBUF_FINAL { return New(NULL); }
- FieldOptions* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ FieldOptions* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const FieldOptions& from);
void MergeFrom(const FieldOptions& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(FieldOptions* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -2438,6 +2662,18 @@ class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@
// accessors -------------------------------------------------------
+ // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
+ int uninterpreted_option_size() const;
+ void clear_uninterpreted_option();
+ static const int kUninterpretedOptionFieldNumber = 999;
+ const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const;
+ ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index);
+ ::google::protobuf::UninterpretedOption* add_uninterpreted_option();
+ ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >*
+ mutable_uninterpreted_option();
+ const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >&
+ uninterpreted_option() const;
+
// optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];
bool has_ctype() const;
void clear_ctype();
@@ -2445,13 +2681,6 @@ class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@
::google::protobuf::FieldOptions_CType ctype() const;
void set_ctype(::google::protobuf::FieldOptions_CType value);
- // optional bool packed = 2;
- bool has_packed() const;
- void clear_packed();
- static const int kPackedFieldNumber = 2;
- bool packed() const;
- void set_packed(bool value);
-
// optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];
bool has_jstype() const;
void clear_jstype();
@@ -2459,6 +2688,13 @@ class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@
::google::protobuf::FieldOptions_JSType jstype() const;
void set_jstype(::google::protobuf::FieldOptions_JSType value);
+ // optional bool packed = 2;
+ bool has_packed() const;
+ void clear_packed();
+ static const int kPackedFieldNumber = 2;
+ bool packed() const;
+ void set_packed(bool value);
+
// optional bool lazy = 5 [default = false];
bool has_lazy() const;
void clear_lazy();
@@ -2480,52 +2716,35 @@ class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@
bool weak() const;
void set_weak(bool value);
- // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
- int uninterpreted_option_size() const;
- void clear_uninterpreted_option();
- static const int kUninterpretedOptionFieldNumber = 999;
- const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const;
- ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index);
- ::google::protobuf::UninterpretedOption* add_uninterpreted_option();
- ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >*
- mutable_uninterpreted_option();
- const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >&
- uninterpreted_option() const;
-
GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(FieldOptions)
// @@protoc_insertion_point(class_scope:google.protobuf.FieldOptions)
private:
- inline void set_has_ctype();
- inline void clear_has_ctype();
- inline void set_has_packed();
- inline void clear_has_packed();
- inline void set_has_jstype();
- inline void clear_has_jstype();
- inline void set_has_lazy();
- inline void clear_has_lazy();
- inline void set_has_deprecated();
- inline void clear_has_deprecated();
- inline void set_has_weak();
- inline void clear_has_weak();
+ void set_has_ctype();
+ void clear_has_ctype();
+ void set_has_packed();
+ void clear_has_packed();
+ void set_has_jstype();
+ void clear_has_jstype();
+ void set_has_lazy();
+ void clear_has_lazy();
+ void set_has_deprecated();
+ void clear_has_deprecated();
+ void set_has_weak();
+ void clear_has_weak();
::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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static FieldOptions* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -2552,46 +2771,53 @@ 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 reinterpret_cast<const OneofOptions*>(
+ &_OneofOptions_default_instance_);
+ }
+
void Swap(OneofOptions* other);
// implements Message ----------------------------------------------
- inline OneofOptions* New() const { return New(NULL); }
+ inline OneofOptions* New() const PROTOBUF_FINAL { return New(NULL); }
- OneofOptions* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ OneofOptions* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const OneofOptions& from);
void MergeFrom(const OneofOptions& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(OneofOptions* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -2616,15 +2842,10 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static OneofOptions* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -2651,51 +2872,70 @@ 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 reinterpret_cast<const EnumOptions*>(
+ &_EnumOptions_default_instance_);
+ }
+
void Swap(EnumOptions* other);
// implements Message ----------------------------------------------
- inline EnumOptions* New() const { return New(NULL); }
+ inline EnumOptions* New() const PROTOBUF_FINAL { return New(NULL); }
- EnumOptions* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ EnumOptions* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const EnumOptions& from);
void MergeFrom(const EnumOptions& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(EnumOptions* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
+ // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
+ int uninterpreted_option_size() const;
+ void clear_uninterpreted_option();
+ static const int kUninterpretedOptionFieldNumber = 999;
+ const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const;
+ ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index);
+ ::google::protobuf::UninterpretedOption* add_uninterpreted_option();
+ ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >*
+ mutable_uninterpreted_option();
+ const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >&
+ uninterpreted_option() const;
+
// optional bool allow_alias = 2;
bool has_allow_alias() const;
void clear_allow_alias();
@@ -2710,40 +2950,23 @@ class LIBPROTOBUF_EXPORT EnumOptions : public ::google::protobuf::Message /* @@p
bool deprecated() const;
void set_deprecated(bool value);
- // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
- int uninterpreted_option_size() const;
- void clear_uninterpreted_option();
- static const int kUninterpretedOptionFieldNumber = 999;
- const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const;
- ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index);
- ::google::protobuf::UninterpretedOption* add_uninterpreted_option();
- ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >*
- mutable_uninterpreted_option();
- const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >&
- uninterpreted_option() const;
-
GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(EnumOptions)
// @@protoc_insertion_point(class_scope:google.protobuf.EnumOptions)
private:
- inline void set_has_allow_alias();
- inline void clear_has_allow_alias();
- inline void set_has_deprecated();
- inline void clear_has_deprecated();
+ void set_has_allow_alias();
+ void clear_has_allow_alias();
+ void set_has_deprecated();
+ void clear_has_deprecated();
::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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static EnumOptions* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -2770,58 +2993,58 @@ 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 reinterpret_cast<const EnumValueOptions*>(
+ &_EnumValueOptions_default_instance_);
+ }
+
void Swap(EnumValueOptions* other);
// implements Message ----------------------------------------------
- inline EnumValueOptions* New() const { return New(NULL); }
+ inline EnumValueOptions* New() const PROTOBUF_FINAL { return New(NULL); }
- EnumValueOptions* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ EnumValueOptions* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const EnumValueOptions& from);
void MergeFrom(const EnumValueOptions& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(EnumValueOptions* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional bool deprecated = 1 [default = false];
- bool has_deprecated() const;
- void clear_deprecated();
- static const int kDeprecatedFieldNumber = 1;
- bool deprecated() const;
- void set_deprecated(bool value);
-
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
int uninterpreted_option_size() const;
void clear_uninterpreted_option();
@@ -2834,25 +3057,27 @@ class LIBPROTOBUF_EXPORT EnumValueOptions : public ::google::protobuf::Message /
const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >&
uninterpreted_option() const;
+ // optional bool deprecated = 1 [default = false];
+ bool has_deprecated() const;
+ void clear_deprecated();
+ static const int kDeprecatedFieldNumber = 1;
+ bool deprecated() const;
+ void set_deprecated(bool value);
+
GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(EnumValueOptions)
// @@protoc_insertion_point(class_scope:google.protobuf.EnumValueOptions)
private:
- inline void set_has_deprecated();
- inline void clear_has_deprecated();
+ void set_has_deprecated();
+ void clear_has_deprecated();
::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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static EnumValueOptions* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -2879,58 +3104,58 @@ 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 reinterpret_cast<const ServiceOptions*>(
+ &_ServiceOptions_default_instance_);
+ }
+
void Swap(ServiceOptions* other);
// implements Message ----------------------------------------------
- inline ServiceOptions* New() const { return New(NULL); }
+ inline ServiceOptions* New() const PROTOBUF_FINAL { return New(NULL); }
- ServiceOptions* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ ServiceOptions* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const ServiceOptions& from);
void MergeFrom(const ServiceOptions& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(ServiceOptions* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional bool deprecated = 33 [default = false];
- bool has_deprecated() const;
- void clear_deprecated();
- static const int kDeprecatedFieldNumber = 33;
- bool deprecated() const;
- void set_deprecated(bool value);
-
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
int uninterpreted_option_size() const;
void clear_uninterpreted_option();
@@ -2943,25 +3168,27 @@ class LIBPROTOBUF_EXPORT ServiceOptions : public ::google::protobuf::Message /*
const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >&
uninterpreted_option() const;
+ // optional bool deprecated = 33 [default = false];
+ bool has_deprecated() const;
+ void clear_deprecated();
+ static const int kDeprecatedFieldNumber = 33;
+ bool deprecated() const;
+ void set_deprecated(bool value);
+
GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(ServiceOptions)
// @@protoc_insertion_point(class_scope:google.protobuf.ServiceOptions)
private:
- inline void set_has_deprecated();
- inline void clear_has_deprecated();
+ void set_has_deprecated();
+ void clear_has_deprecated();
::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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static ServiceOptions* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -2988,57 +3215,85 @@ 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 reinterpret_cast<const MethodOptions*>(
+ &_MethodOptions_default_instance_);
+ }
+
void Swap(MethodOptions* other);
// implements Message ----------------------------------------------
- inline MethodOptions* New() const { return New(NULL); }
+ inline MethodOptions* New() const PROTOBUF_FINAL { return New(NULL); }
- MethodOptions* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ MethodOptions* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const MethodOptions& from);
void MergeFrom(const MethodOptions& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(MethodOptions* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
- // accessors -------------------------------------------------------
+ typedef MethodOptions_IdempotencyLevel IdempotencyLevel;
+ static const IdempotencyLevel IDEMPOTENCY_UNKNOWN =
+ MethodOptions_IdempotencyLevel_IDEMPOTENCY_UNKNOWN;
+ static const IdempotencyLevel NO_SIDE_EFFECTS =
+ MethodOptions_IdempotencyLevel_NO_SIDE_EFFECTS;
+ static const IdempotencyLevel IDEMPOTENT =
+ MethodOptions_IdempotencyLevel_IDEMPOTENT;
+ static inline bool IdempotencyLevel_IsValid(int value) {
+ return MethodOptions_IdempotencyLevel_IsValid(value);
+ }
+ static const IdempotencyLevel IdempotencyLevel_MIN =
+ MethodOptions_IdempotencyLevel_IdempotencyLevel_MIN;
+ static const IdempotencyLevel IdempotencyLevel_MAX =
+ MethodOptions_IdempotencyLevel_IdempotencyLevel_MAX;
+ static const int IdempotencyLevel_ARRAYSIZE =
+ MethodOptions_IdempotencyLevel_IdempotencyLevel_ARRAYSIZE;
+ static inline const ::google::protobuf::EnumDescriptor*
+ IdempotencyLevel_descriptor() {
+ return MethodOptions_IdempotencyLevel_descriptor();
+ }
+ static inline const ::std::string& IdempotencyLevel_Name(IdempotencyLevel value) {
+ return MethodOptions_IdempotencyLevel_Name(value);
+ }
+ static inline bool IdempotencyLevel_Parse(const ::std::string& name,
+ IdempotencyLevel* value) {
+ return MethodOptions_IdempotencyLevel_Parse(name, value);
+ }
- // optional bool deprecated = 33 [default = false];
- bool has_deprecated() const;
- void clear_deprecated();
- static const int kDeprecatedFieldNumber = 33;
- bool deprecated() const;
- void set_deprecated(bool value);
+ // accessors -------------------------------------------------------
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
int uninterpreted_option_size() const;
@@ -3052,25 +3307,37 @@ class LIBPROTOBUF_EXPORT MethodOptions : public ::google::protobuf::Message /* @
const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >&
uninterpreted_option() const;
+ // optional bool deprecated = 33 [default = false];
+ bool has_deprecated() const;
+ void clear_deprecated();
+ static const int kDeprecatedFieldNumber = 33;
+ bool deprecated() const;
+ void set_deprecated(bool value);
+
+ // optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN];
+ bool has_idempotency_level() const;
+ void clear_idempotency_level();
+ static const int kIdempotencyLevelFieldNumber = 34;
+ ::google::protobuf::MethodOptions_IdempotencyLevel idempotency_level() const;
+ void set_idempotency_level(::google::protobuf::MethodOptions_IdempotencyLevel value);
+
GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(MethodOptions)
// @@protoc_insertion_point(class_scope:google.protobuf.MethodOptions)
private:
- inline void set_has_deprecated();
- inline void clear_has_deprecated();
+ void set_has_deprecated();
+ void clear_has_deprecated();
+ void set_has_idempotency_level();
+ void clear_has_idempotency_level();
::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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static MethodOptions* default_instance_;
+ int idempotency_level_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -3097,46 +3364,53 @@ 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 reinterpret_cast<const UninterpretedOption_NamePart*>(
+ &_UninterpretedOption_NamePart_default_instance_);
+ }
+
void Swap(UninterpretedOption_NamePart* other);
// implements Message ----------------------------------------------
- inline UninterpretedOption_NamePart* New() const { return New(NULL); }
+ inline UninterpretedOption_NamePart* New() const PROTOBUF_FINAL { return New(NULL); }
- UninterpretedOption_NamePart* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ UninterpretedOption_NamePart* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const UninterpretedOption_NamePart& from);
void MergeFrom(const UninterpretedOption_NamePart& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(UninterpretedOption_NamePart* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -3148,6 +3422,9 @@ class LIBPROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobu
static const int kNamePartFieldNumber = 1;
const ::std::string& name_part() const;
void set_name_part(const ::std::string& value);
+ #if LANG_CXX11
+ void set_name_part(::std::string&& value);
+ #endif
void set_name_part(const char* value);
void set_name_part(const char* value, size_t size);
::std::string* mutable_name_part();
@@ -3163,25 +3440,20 @@ class LIBPROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobu
// @@protoc_insertion_point(class_scope:google.protobuf.UninterpretedOption.NamePart)
private:
- inline void set_has_name_part();
- inline void clear_has_name_part();
- inline void set_has_is_extension();
- inline void clear_has_is_extension();
+ void set_has_name_part();
+ void clear_has_name_part();
+ void set_has_is_extension();
+ 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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static UninterpretedOption_NamePart* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -3208,46 +3480,53 @@ 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 reinterpret_cast<const UninterpretedOption*>(
+ &_UninterpretedOption_default_instance_);
+ }
+
void Swap(UninterpretedOption* other);
// implements Message ----------------------------------------------
- inline UninterpretedOption* New() const { return New(NULL); }
+ inline UninterpretedOption* New() const PROTOBUF_FINAL { return New(NULL); }
- UninterpretedOption* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ UninterpretedOption* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const UninterpretedOption& from);
void MergeFrom(const UninterpretedOption& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(UninterpretedOption* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -3273,39 +3552,24 @@ class LIBPROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Messag
static const int kIdentifierValueFieldNumber = 3;
const ::std::string& identifier_value() const;
void set_identifier_value(const ::std::string& value);
+ #if LANG_CXX11
+ void set_identifier_value(::std::string&& value);
+ #endif
void set_identifier_value(const char* value);
void set_identifier_value(const char* value, size_t size);
::std::string* mutable_identifier_value();
::std::string* release_identifier_value();
void set_allocated_identifier_value(::std::string* identifier_value);
- // optional uint64 positive_int_value = 4;
- bool has_positive_int_value() const;
- void clear_positive_int_value();
- static const int kPositiveIntValueFieldNumber = 4;
- ::google::protobuf::uint64 positive_int_value() const;
- void set_positive_int_value(::google::protobuf::uint64 value);
-
- // optional int64 negative_int_value = 5;
- bool has_negative_int_value() const;
- void clear_negative_int_value();
- static const int kNegativeIntValueFieldNumber = 5;
- ::google::protobuf::int64 negative_int_value() const;
- void set_negative_int_value(::google::protobuf::int64 value);
-
- // optional double double_value = 6;
- bool has_double_value() const;
- void clear_double_value();
- static const int kDoubleValueFieldNumber = 6;
- double double_value() const;
- void set_double_value(double value);
-
// optional bytes string_value = 7;
bool has_string_value() const;
void clear_string_value();
static const int kStringValueFieldNumber = 7;
const ::std::string& string_value() const;
void set_string_value(const ::std::string& value);
+ #if LANG_CXX11
+ void set_string_value(::std::string&& value);
+ #endif
void set_string_value(const char* value);
void set_string_value(const void* value, size_t size);
::std::string* mutable_string_value();
@@ -3318,43 +3582,62 @@ class LIBPROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Messag
static const int kAggregateValueFieldNumber = 8;
const ::std::string& aggregate_value() const;
void set_aggregate_value(const ::std::string& value);
+ #if LANG_CXX11
+ void set_aggregate_value(::std::string&& value);
+ #endif
void set_aggregate_value(const char* value);
void set_aggregate_value(const char* value, size_t size);
::std::string* mutable_aggregate_value();
::std::string* release_aggregate_value();
void set_allocated_aggregate_value(::std::string* aggregate_value);
+ // optional uint64 positive_int_value = 4;
+ bool has_positive_int_value() const;
+ void clear_positive_int_value();
+ static const int kPositiveIntValueFieldNumber = 4;
+ ::google::protobuf::uint64 positive_int_value() const;
+ void set_positive_int_value(::google::protobuf::uint64 value);
+
+ // optional int64 negative_int_value = 5;
+ bool has_negative_int_value() const;
+ void clear_negative_int_value();
+ static const int kNegativeIntValueFieldNumber = 5;
+ ::google::protobuf::int64 negative_int_value() const;
+ void set_negative_int_value(::google::protobuf::int64 value);
+
+ // optional double double_value = 6;
+ bool has_double_value() const;
+ void clear_double_value();
+ static const int kDoubleValueFieldNumber = 6;
+ double double_value() const;
+ void set_double_value(double value);
+
// @@protoc_insertion_point(class_scope:google.protobuf.UninterpretedOption)
private:
- inline void set_has_identifier_value();
- inline void clear_has_identifier_value();
- inline void set_has_positive_int_value();
- inline void clear_has_positive_int_value();
- inline void set_has_negative_int_value();
- inline void clear_has_negative_int_value();
- inline void set_has_double_value();
- inline void clear_has_double_value();
- inline void set_has_string_value();
- inline void clear_has_string_value();
- inline void set_has_aggregate_value();
- inline void clear_has_aggregate_value();
+ void set_has_identifier_value();
+ void clear_has_identifier_value();
+ void set_has_positive_int_value();
+ void clear_has_positive_int_value();
+ void set_has_negative_int_value();
+ void clear_has_negative_int_value();
+ void set_has_double_value();
+ void clear_has_double_value();
+ void set_has_string_value();
+ void clear_has_string_value();
+ void set_has_aggregate_value();
+ 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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static UninterpretedOption* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -3381,46 +3664,53 @@ 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 reinterpret_cast<const SourceCodeInfo_Location*>(
+ &_SourceCodeInfo_Location_default_instance_);
+ }
+
void Swap(SourceCodeInfo_Location* other);
// implements Message ----------------------------------------------
- inline SourceCodeInfo_Location* New() const { return New(NULL); }
+ inline SourceCodeInfo_Location* New() const PROTOBUF_FINAL { return New(NULL); }
- SourceCodeInfo_Location* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ SourceCodeInfo_Location* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const SourceCodeInfo_Location& from);
void MergeFrom(const SourceCodeInfo_Location& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(SourceCodeInfo_Location* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -3450,12 +3740,37 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Me
::google::protobuf::RepeatedField< ::google::protobuf::int32 >*
mutable_span();
+ // repeated string leading_detached_comments = 6;
+ int leading_detached_comments_size() const;
+ void clear_leading_detached_comments();
+ static const int kLeadingDetachedCommentsFieldNumber = 6;
+ const ::std::string& leading_detached_comments(int index) const;
+ ::std::string* mutable_leading_detached_comments(int index);
+ void set_leading_detached_comments(int index, const ::std::string& value);
+ #if LANG_CXX11
+ void set_leading_detached_comments(int index, ::std::string&& value);
+ #endif
+ void set_leading_detached_comments(int index, const char* value);
+ void set_leading_detached_comments(int index, const char* value, size_t size);
+ ::std::string* add_leading_detached_comments();
+ void add_leading_detached_comments(const ::std::string& value);
+ #if LANG_CXX11
+ void add_leading_detached_comments(::std::string&& value);
+ #endif
+ void add_leading_detached_comments(const char* value);
+ void add_leading_detached_comments(const char* value, size_t size);
+ const ::google::protobuf::RepeatedPtrField< ::std::string>& leading_detached_comments() const;
+ ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_leading_detached_comments();
+
// optional string leading_comments = 3;
bool has_leading_comments() const;
void clear_leading_comments();
static const int kLeadingCommentsFieldNumber = 3;
const ::std::string& leading_comments() const;
void set_leading_comments(const ::std::string& value);
+ #if LANG_CXX11
+ void set_leading_comments(::std::string&& value);
+ #endif
void set_leading_comments(const char* value);
void set_leading_comments(const char* value, size_t size);
::std::string* mutable_leading_comments();
@@ -3468,51 +3783,33 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Me
static const int kTrailingCommentsFieldNumber = 4;
const ::std::string& trailing_comments() const;
void set_trailing_comments(const ::std::string& value);
+ #if LANG_CXX11
+ void set_trailing_comments(::std::string&& value);
+ #endif
void set_trailing_comments(const char* value);
void set_trailing_comments(const char* value, size_t size);
::std::string* mutable_trailing_comments();
::std::string* release_trailing_comments();
void set_allocated_trailing_comments(::std::string* trailing_comments);
- // repeated string leading_detached_comments = 6;
- int leading_detached_comments_size() const;
- void clear_leading_detached_comments();
- static const int kLeadingDetachedCommentsFieldNumber = 6;
- const ::std::string& leading_detached_comments(int index) const;
- ::std::string* mutable_leading_detached_comments(int index);
- void set_leading_detached_comments(int index, const ::std::string& value);
- void set_leading_detached_comments(int index, const char* value);
- void set_leading_detached_comments(int index, const char* value, size_t size);
- ::std::string* add_leading_detached_comments();
- void add_leading_detached_comments(const ::std::string& value);
- void add_leading_detached_comments(const char* value);
- void add_leading_detached_comments(const char* value, size_t size);
- const ::google::protobuf::RepeatedPtrField< ::std::string>& leading_detached_comments() const;
- ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_leading_detached_comments();
-
// @@protoc_insertion_point(class_scope:google.protobuf.SourceCodeInfo.Location)
private:
- inline void set_has_leading_comments();
- inline void clear_has_leading_comments();
- inline void set_has_trailing_comments();
- inline void clear_has_trailing_comments();
+ void set_has_leading_comments();
+ void clear_has_leading_comments();
+ void set_has_trailing_comments();
+ 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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static SourceCodeInfo_Location* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -3539,46 +3836,53 @@ 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 reinterpret_cast<const SourceCodeInfo*>(
+ &_SourceCodeInfo_default_instance_);
+ }
+
void Swap(SourceCodeInfo* other);
// implements Message ----------------------------------------------
- inline SourceCodeInfo* New() const { return New(NULL); }
+ inline SourceCodeInfo* New() const PROTOBUF_FINAL { return New(NULL); }
- SourceCodeInfo* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ SourceCodeInfo* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const SourceCodeInfo& from);
void MergeFrom(const SourceCodeInfo& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(SourceCodeInfo* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -3602,15 +3906,10 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static SourceCodeInfo* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -3637,46 +3936,53 @@ 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 reinterpret_cast<const GeneratedCodeInfo_Annotation*>(
+ &_GeneratedCodeInfo_Annotation_default_instance_);
+ }
+
void Swap(GeneratedCodeInfo_Annotation* other);
// implements Message ----------------------------------------------
- inline GeneratedCodeInfo_Annotation* New() const { return New(NULL); }
+ inline GeneratedCodeInfo_Annotation* New() const PROTOBUF_FINAL { return New(NULL); }
- GeneratedCodeInfo_Annotation* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ GeneratedCodeInfo_Annotation* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const GeneratedCodeInfo_Annotation& from);
void MergeFrom(const GeneratedCodeInfo_Annotation& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(GeneratedCodeInfo_Annotation* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -3700,6 +4006,9 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo_Annotation : public ::google::protobu
static const int kSourceFileFieldNumber = 2;
const ::std::string& source_file() const;
void set_source_file(const ::std::string& value);
+ #if LANG_CXX11
+ void set_source_file(::std::string&& value);
+ #endif
void set_source_file(const char* value);
void set_source_file(const char* value, size_t size);
::std::string* mutable_source_file();
@@ -3722,27 +4031,22 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo_Annotation : public ::google::protobu
// @@protoc_insertion_point(class_scope:google.protobuf.GeneratedCodeInfo.Annotation)
private:
- inline void set_has_source_file();
- inline void clear_has_source_file();
- inline void set_has_begin();
- inline void clear_has_begin();
- inline void set_has_end();
- inline void clear_has_end();
+ void set_has_source_file();
+ void clear_has_source_file();
+ void set_has_begin();
+ void clear_has_begin();
+ void set_has_end();
+ 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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static GeneratedCodeInfo_Annotation* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -3769,46 +4073,53 @@ 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 reinterpret_cast<const GeneratedCodeInfo*>(
+ &_GeneratedCodeInfo_default_instance_);
+ }
+
void Swap(GeneratedCodeInfo* other);
// implements Message ----------------------------------------------
- inline GeneratedCodeInfo* New() const { return New(NULL); }
+ inline GeneratedCodeInfo* New() const PROTOBUF_FINAL { return New(NULL); }
- GeneratedCodeInfo* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ GeneratedCodeInfo* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const GeneratedCodeInfo& from);
void MergeFrom(const GeneratedCodeInfo& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(GeneratedCodeInfo* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -3832,15 +4143,10 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto();
-
- void InitAsDefaultInstance();
- static GeneratedCodeInfo* default_instance_;
+ friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct;
};
// ===================================================================
@@ -3900,13 +4206,21 @@ inline void FileDescriptorProto::clear_name() {
}
inline const ::std::string& FileDescriptorProto::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.name)
- return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return name_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void FileDescriptorProto::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileDescriptorProto.name)
+}
+#endif
inline void FileDescriptorProto::set_name(const char* value) {
set_has_name();
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -3954,13 +4268,21 @@ inline void FileDescriptorProto::clear_package() {
}
inline const ::std::string& FileDescriptorProto::package() const {
// @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.package)
- return package_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return package_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void FileDescriptorProto::set_package(::std::string&& value) {
+ set_has_package();
+ package_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileDescriptorProto.package)
+}
+#endif
inline void FileDescriptorProto::set_package(const char* value) {
set_has_package();
package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -4011,6 +4333,12 @@ inline void FileDescriptorProto::set_dependency(int index, const ::std::string&
// @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.dependency)
dependency_.Mutable(index)->assign(value);
}
+#if LANG_CXX11
+inline void FileDescriptorProto::set_dependency(int index, ::std::string&& value) {
+ // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.dependency)
+ dependency_.Mutable(index)->assign(std::move(value));
+}
+#endif
inline void FileDescriptorProto::set_dependency(int index, const char* value) {
dependency_.Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.dependency)
@@ -4028,6 +4356,12 @@ inline void FileDescriptorProto::add_dependency(const ::std::string& value) {
dependency_.Add()->assign(value);
// @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.dependency)
}
+#if LANG_CXX11
+inline void FileDescriptorProto::add_dependency(::std::string&& value) {
+ dependency_.Add()->assign(std::move(value));
+ // @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.dependency)
+}
+#endif
inline void FileDescriptorProto::add_dependency(const char* value) {
dependency_.Add()->assign(value);
// @@protoc_insertion_point(field_add_char:google.protobuf.FileDescriptorProto.dependency)
@@ -4229,13 +4563,13 @@ FileDescriptorProto::extension() const {
// optional .google.protobuf.FileOptions options = 8;
inline bool FileDescriptorProto::has_options() const {
- return (_has_bits_[0] & 0x00000200u) != 0;
+ return (_has_bits_[0] & 0x00000008u) != 0;
}
inline void FileDescriptorProto::set_has_options() {
- _has_bits_[0] |= 0x00000200u;
+ _has_bits_[0] |= 0x00000008u;
}
inline void FileDescriptorProto::clear_has_options() {
- _has_bits_[0] &= ~0x00000200u;
+ _has_bits_[0] &= ~0x00000008u;
}
inline void FileDescriptorProto::clear_options() {
if (options_ != NULL) options_->::google::protobuf::FileOptions::Clear();
@@ -4243,7 +4577,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();
@@ -4273,13 +4608,13 @@ inline void FileDescriptorProto::set_allocated_options(::google::protobuf::FileO
// optional .google.protobuf.SourceCodeInfo source_code_info = 9;
inline bool FileDescriptorProto::has_source_code_info() const {
- return (_has_bits_[0] & 0x00000400u) != 0;
+ return (_has_bits_[0] & 0x00000010u) != 0;
}
inline void FileDescriptorProto::set_has_source_code_info() {
- _has_bits_[0] |= 0x00000400u;
+ _has_bits_[0] |= 0x00000010u;
}
inline void FileDescriptorProto::clear_has_source_code_info() {
- _has_bits_[0] &= ~0x00000400u;
+ _has_bits_[0] &= ~0x00000010u;
}
inline void FileDescriptorProto::clear_source_code_info() {
if (source_code_info_ != NULL) source_code_info_->::google::protobuf::SourceCodeInfo::Clear();
@@ -4287,7 +4622,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();
@@ -4317,13 +4653,13 @@ inline void FileDescriptorProto::set_allocated_source_code_info(::google::protob
// optional string syntax = 12;
inline bool FileDescriptorProto::has_syntax() const {
- return (_has_bits_[0] & 0x00000800u) != 0;
+ return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void FileDescriptorProto::set_has_syntax() {
- _has_bits_[0] |= 0x00000800u;
+ _has_bits_[0] |= 0x00000004u;
}
inline void FileDescriptorProto::clear_has_syntax() {
- _has_bits_[0] &= ~0x00000800u;
+ _has_bits_[0] &= ~0x00000004u;
}
inline void FileDescriptorProto::clear_syntax() {
syntax_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
@@ -4331,13 +4667,21 @@ inline void FileDescriptorProto::clear_syntax() {
}
inline const ::std::string& FileDescriptorProto::syntax() const {
// @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.syntax)
- return syntax_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return syntax_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void FileDescriptorProto::set_syntax(::std::string&& value) {
+ set_has_syntax();
+ syntax_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileDescriptorProto.syntax)
+}
+#endif
inline void FileDescriptorProto::set_syntax(const char* value) {
set_has_syntax();
syntax_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -4493,13 +4837,21 @@ inline void DescriptorProto::clear_name() {
}
inline const ::std::string& DescriptorProto::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.name)
- return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return name_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void DescriptorProto::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.DescriptorProto.name)
+}
+#endif
inline void DescriptorProto::set_name(const char* value) {
set_has_name();
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -4713,13 +5065,13 @@ DescriptorProto::oneof_decl() const {
// optional .google.protobuf.MessageOptions options = 7;
inline bool DescriptorProto::has_options() const {
- return (_has_bits_[0] & 0x00000080u) != 0;
+ return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void DescriptorProto::set_has_options() {
- _has_bits_[0] |= 0x00000080u;
+ _has_bits_[0] |= 0x00000002u;
}
inline void DescriptorProto::clear_has_options() {
- _has_bits_[0] &= ~0x00000080u;
+ _has_bits_[0] &= ~0x00000002u;
}
inline void DescriptorProto::clear_options() {
if (options_ != NULL) options_->::google::protobuf::MessageOptions::Clear();
@@ -4727,7 +5079,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();
@@ -4804,6 +5157,12 @@ inline void DescriptorProto::set_reserved_name(int index, const ::std::string& v
// @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.reserved_name)
reserved_name_.Mutable(index)->assign(value);
}
+#if LANG_CXX11
+inline void DescriptorProto::set_reserved_name(int index, ::std::string&& value) {
+ // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.reserved_name)
+ reserved_name_.Mutable(index)->assign(std::move(value));
+}
+#endif
inline 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)
@@ -4821,6 +5180,12 @@ inline void DescriptorProto::add_reserved_name(const ::std::string& value) {
reserved_name_.Add()->assign(value);
// @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.reserved_name)
}
+#if LANG_CXX11
+inline void DescriptorProto::add_reserved_name(::std::string&& value) {
+ reserved_name_.Add()->assign(std::move(value));
+ // @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.reserved_name)
+}
+#endif
inline void DescriptorProto::add_reserved_name(const char* value) {
reserved_name_.Add()->assign(value);
// @@protoc_insertion_point(field_add_char:google.protobuf.DescriptorProto.reserved_name)
@@ -4860,13 +5225,21 @@ inline void FieldDescriptorProto::clear_name() {
}
inline const ::std::string& FieldDescriptorProto::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.name)
- return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return name_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void FieldDescriptorProto::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FieldDescriptorProto.name)
+}
+#endif
inline void FieldDescriptorProto::set_name(const char* value) {
set_has_name();
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -4900,13 +5273,13 @@ inline void FieldDescriptorProto::set_allocated_name(::std::string* name) {
// optional int32 number = 3;
inline bool FieldDescriptorProto::has_number() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
+ return (_has_bits_[0] & 0x00000040u) != 0;
}
inline void FieldDescriptorProto::set_has_number() {
- _has_bits_[0] |= 0x00000002u;
+ _has_bits_[0] |= 0x00000040u;
}
inline void FieldDescriptorProto::clear_has_number() {
- _has_bits_[0] &= ~0x00000002u;
+ _has_bits_[0] &= ~0x00000040u;
}
inline void FieldDescriptorProto::clear_number() {
number_ = 0;
@@ -4924,13 +5297,13 @@ inline void FieldDescriptorProto::set_number(::google::protobuf::int32 value) {
// optional .google.protobuf.FieldDescriptorProto.Label label = 4;
inline bool FieldDescriptorProto::has_label() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
+ return (_has_bits_[0] & 0x00000100u) != 0;
}
inline void FieldDescriptorProto::set_has_label() {
- _has_bits_[0] |= 0x00000004u;
+ _has_bits_[0] |= 0x00000100u;
}
inline void FieldDescriptorProto::clear_has_label() {
- _has_bits_[0] &= ~0x00000004u;
+ _has_bits_[0] &= ~0x00000100u;
}
inline void FieldDescriptorProto::clear_label() {
label_ = 1;
@@ -4949,13 +5322,13 @@ inline void FieldDescriptorProto::set_label(::google::protobuf::FieldDescriptorP
// optional .google.protobuf.FieldDescriptorProto.Type type = 5;
inline bool FieldDescriptorProto::has_type() const {
- return (_has_bits_[0] & 0x00000008u) != 0;
+ return (_has_bits_[0] & 0x00000200u) != 0;
}
inline void FieldDescriptorProto::set_has_type() {
- _has_bits_[0] |= 0x00000008u;
+ _has_bits_[0] |= 0x00000200u;
}
inline void FieldDescriptorProto::clear_has_type() {
- _has_bits_[0] &= ~0x00000008u;
+ _has_bits_[0] &= ~0x00000200u;
}
inline void FieldDescriptorProto::clear_type() {
type_ = 1;
@@ -4974,13 +5347,13 @@ inline void FieldDescriptorProto::set_type(::google::protobuf::FieldDescriptorPr
// optional string type_name = 6;
inline bool FieldDescriptorProto::has_type_name() const {
- return (_has_bits_[0] & 0x00000010u) != 0;
+ return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void FieldDescriptorProto::set_has_type_name() {
- _has_bits_[0] |= 0x00000010u;
+ _has_bits_[0] |= 0x00000002u;
}
inline void FieldDescriptorProto::clear_has_type_name() {
- _has_bits_[0] &= ~0x00000010u;
+ _has_bits_[0] &= ~0x00000002u;
}
inline void FieldDescriptorProto::clear_type_name() {
type_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
@@ -4988,13 +5361,21 @@ inline void FieldDescriptorProto::clear_type_name() {
}
inline 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());
+ return type_name_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void FieldDescriptorProto::set_type_name(::std::string&& value) {
+ set_has_type_name();
+ type_name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FieldDescriptorProto.type_name)
+}
+#endif
inline void FieldDescriptorProto::set_type_name(const char* value) {
set_has_type_name();
type_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -5028,13 +5409,13 @@ inline void FieldDescriptorProto::set_allocated_type_name(::std::string* type_na
// optional string extendee = 2;
inline bool FieldDescriptorProto::has_extendee() const {
- return (_has_bits_[0] & 0x00000020u) != 0;
+ return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void FieldDescriptorProto::set_has_extendee() {
- _has_bits_[0] |= 0x00000020u;
+ _has_bits_[0] |= 0x00000004u;
}
inline void FieldDescriptorProto::clear_has_extendee() {
- _has_bits_[0] &= ~0x00000020u;
+ _has_bits_[0] &= ~0x00000004u;
}
inline void FieldDescriptorProto::clear_extendee() {
extendee_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
@@ -5042,13 +5423,21 @@ inline void FieldDescriptorProto::clear_extendee() {
}
inline const ::std::string& FieldDescriptorProto::extendee() const {
// @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.extendee)
- return extendee_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return extendee_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void FieldDescriptorProto::set_extendee(::std::string&& value) {
+ set_has_extendee();
+ extendee_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FieldDescriptorProto.extendee)
+}
+#endif
inline void FieldDescriptorProto::set_extendee(const char* value) {
set_has_extendee();
extendee_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -5082,13 +5471,13 @@ inline void FieldDescriptorProto::set_allocated_extendee(::std::string* extendee
// optional string default_value = 7;
inline bool FieldDescriptorProto::has_default_value() const {
- return (_has_bits_[0] & 0x00000040u) != 0;
+ return (_has_bits_[0] & 0x00000008u) != 0;
}
inline void FieldDescriptorProto::set_has_default_value() {
- _has_bits_[0] |= 0x00000040u;
+ _has_bits_[0] |= 0x00000008u;
}
inline void FieldDescriptorProto::clear_has_default_value() {
- _has_bits_[0] &= ~0x00000040u;
+ _has_bits_[0] &= ~0x00000008u;
}
inline void FieldDescriptorProto::clear_default_value() {
default_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
@@ -5096,13 +5485,21 @@ inline void FieldDescriptorProto::clear_default_value() {
}
inline 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());
+ return default_value_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void FieldDescriptorProto::set_default_value(::std::string&& value) {
+ set_has_default_value();
+ default_value_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FieldDescriptorProto.default_value)
+}
+#endif
inline void FieldDescriptorProto::set_default_value(const char* value) {
set_has_default_value();
default_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -5160,13 +5557,13 @@ inline void FieldDescriptorProto::set_oneof_index(::google::protobuf::int32 valu
// optional string json_name = 10;
inline bool FieldDescriptorProto::has_json_name() const {
- return (_has_bits_[0] & 0x00000100u) != 0;
+ return (_has_bits_[0] & 0x00000010u) != 0;
}
inline void FieldDescriptorProto::set_has_json_name() {
- _has_bits_[0] |= 0x00000100u;
+ _has_bits_[0] |= 0x00000010u;
}
inline void FieldDescriptorProto::clear_has_json_name() {
- _has_bits_[0] &= ~0x00000100u;
+ _has_bits_[0] &= ~0x00000010u;
}
inline void FieldDescriptorProto::clear_json_name() {
json_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
@@ -5174,13 +5571,21 @@ inline void FieldDescriptorProto::clear_json_name() {
}
inline 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());
+ return json_name_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void FieldDescriptorProto::set_json_name(::std::string&& value) {
+ set_has_json_name();
+ json_name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FieldDescriptorProto.json_name)
+}
+#endif
inline void FieldDescriptorProto::set_json_name(const char* value) {
set_has_json_name();
json_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -5214,13 +5619,13 @@ inline void FieldDescriptorProto::set_allocated_json_name(::std::string* json_na
// optional .google.protobuf.FieldOptions options = 8;
inline bool FieldDescriptorProto::has_options() const {
- return (_has_bits_[0] & 0x00000200u) != 0;
+ return (_has_bits_[0] & 0x00000020u) != 0;
}
inline void FieldDescriptorProto::set_has_options() {
- _has_bits_[0] |= 0x00000200u;
+ _has_bits_[0] |= 0x00000020u;
}
inline void FieldDescriptorProto::clear_has_options() {
- _has_bits_[0] &= ~0x00000200u;
+ _has_bits_[0] &= ~0x00000020u;
}
inline void FieldDescriptorProto::clear_options() {
if (options_ != NULL) options_->::google::protobuf::FieldOptions::Clear();
@@ -5228,7 +5633,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();
@@ -5276,13 +5682,21 @@ inline void OneofDescriptorProto::clear_name() {
}
inline const ::std::string& OneofDescriptorProto::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.OneofDescriptorProto.name)
- return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return name_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void OneofDescriptorProto::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.OneofDescriptorProto.name)
+}
+#endif
inline void OneofDescriptorProto::set_name(const char* value) {
set_has_name();
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -5330,7 +5744,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();
@@ -5378,13 +5793,21 @@ inline void EnumDescriptorProto::clear_name() {
}
inline const ::std::string& EnumDescriptorProto::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.EnumDescriptorProto.name)
- return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return name_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void EnumDescriptorProto::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.EnumDescriptorProto.name)
+}
+#endif
inline void EnumDescriptorProto::set_name(const char* value) {
set_has_name();
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -5448,13 +5871,13 @@ EnumDescriptorProto::value() const {
// optional .google.protobuf.EnumOptions options = 3;
inline bool EnumDescriptorProto::has_options() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
+ return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void EnumDescriptorProto::set_has_options() {
- _has_bits_[0] |= 0x00000004u;
+ _has_bits_[0] |= 0x00000002u;
}
inline void EnumDescriptorProto::clear_has_options() {
- _has_bits_[0] &= ~0x00000004u;
+ _has_bits_[0] &= ~0x00000002u;
}
inline void EnumDescriptorProto::clear_options() {
if (options_ != NULL) options_->::google::protobuf::EnumOptions::Clear();
@@ -5462,7 +5885,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();
@@ -5510,13 +5934,21 @@ inline void EnumValueDescriptorProto::clear_name() {
}
inline const ::std::string& EnumValueDescriptorProto::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.EnumValueDescriptorProto.name)
- return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return name_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void EnumValueDescriptorProto::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.EnumValueDescriptorProto.name)
+}
+#endif
inline void EnumValueDescriptorProto::set_name(const char* value) {
set_has_name();
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -5550,13 +5982,13 @@ inline void EnumValueDescriptorProto::set_allocated_name(::std::string* name) {
// optional int32 number = 2;
inline bool EnumValueDescriptorProto::has_number() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
+ return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void EnumValueDescriptorProto::set_has_number() {
- _has_bits_[0] |= 0x00000002u;
+ _has_bits_[0] |= 0x00000004u;
}
inline void EnumValueDescriptorProto::clear_has_number() {
- _has_bits_[0] &= ~0x00000002u;
+ _has_bits_[0] &= ~0x00000004u;
}
inline void EnumValueDescriptorProto::clear_number() {
number_ = 0;
@@ -5574,13 +6006,13 @@ inline void EnumValueDescriptorProto::set_number(::google::protobuf::int32 value
// optional .google.protobuf.EnumValueOptions options = 3;
inline bool EnumValueDescriptorProto::has_options() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
+ return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void EnumValueDescriptorProto::set_has_options() {
- _has_bits_[0] |= 0x00000004u;
+ _has_bits_[0] |= 0x00000002u;
}
inline void EnumValueDescriptorProto::clear_has_options() {
- _has_bits_[0] &= ~0x00000004u;
+ _has_bits_[0] &= ~0x00000002u;
}
inline void EnumValueDescriptorProto::clear_options() {
if (options_ != NULL) options_->::google::protobuf::EnumValueOptions::Clear();
@@ -5588,7 +6020,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();
@@ -5636,13 +6069,21 @@ inline void ServiceDescriptorProto::clear_name() {
}
inline const ::std::string& ServiceDescriptorProto::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.ServiceDescriptorProto.name)
- return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return name_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void ServiceDescriptorProto::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.ServiceDescriptorProto.name)
+}
+#endif
inline void ServiceDescriptorProto::set_name(const char* value) {
set_has_name();
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -5706,13 +6147,13 @@ ServiceDescriptorProto::method() const {
// optional .google.protobuf.ServiceOptions options = 3;
inline bool ServiceDescriptorProto::has_options() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
+ return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void ServiceDescriptorProto::set_has_options() {
- _has_bits_[0] |= 0x00000004u;
+ _has_bits_[0] |= 0x00000002u;
}
inline void ServiceDescriptorProto::clear_has_options() {
- _has_bits_[0] &= ~0x00000004u;
+ _has_bits_[0] &= ~0x00000002u;
}
inline void ServiceDescriptorProto::clear_options() {
if (options_ != NULL) options_->::google::protobuf::ServiceOptions::Clear();
@@ -5720,7 +6161,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();
@@ -5768,13 +6210,21 @@ inline void MethodDescriptorProto::clear_name() {
}
inline const ::std::string& MethodDescriptorProto::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.MethodDescriptorProto.name)
- return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return name_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void MethodDescriptorProto::set_name(::std::string&& value) {
+ set_has_name();
+ name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.MethodDescriptorProto.name)
+}
+#endif
inline void MethodDescriptorProto::set_name(const char* value) {
set_has_name();
name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -5822,13 +6272,21 @@ inline void MethodDescriptorProto::clear_input_type() {
}
inline 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());
+ return input_type_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void MethodDescriptorProto::set_input_type(::std::string&& value) {
+ set_has_input_type();
+ input_type_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.MethodDescriptorProto.input_type)
+}
+#endif
inline void MethodDescriptorProto::set_input_type(const char* value) {
set_has_input_type();
input_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -5876,13 +6334,21 @@ inline void MethodDescriptorProto::clear_output_type() {
}
inline 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());
+ return output_type_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void MethodDescriptorProto::set_output_type(::std::string&& value) {
+ set_has_output_type();
+ output_type_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.MethodDescriptorProto.output_type)
+}
+#endif
inline void MethodDescriptorProto::set_output_type(const char* value) {
set_has_output_type();
output_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -5930,7 +6396,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();
@@ -6026,13 +6493,21 @@ inline void FileOptions::clear_java_package() {
}
inline 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());
+ return java_package_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void FileOptions::set_java_package(::std::string&& value) {
+ set_has_java_package();
+ java_package_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileOptions.java_package)
+}
+#endif
inline void FileOptions::set_java_package(const char* value) {
set_has_java_package();
java_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -6080,13 +6555,21 @@ inline void FileOptions::clear_java_outer_classname() {
}
inline 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());
+ return java_outer_classname_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void FileOptions::set_java_outer_classname(::std::string&& value) {
+ set_has_java_outer_classname();
+ java_outer_classname_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileOptions.java_outer_classname)
+}
+#endif
inline 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));
@@ -6120,13 +6603,13 @@ inline void FileOptions::set_allocated_java_outer_classname(::std::string* java_
// optional bool java_multiple_files = 10 [default = false];
inline bool FileOptions::has_java_multiple_files() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
+ return (_has_bits_[0] & 0x00000080u) != 0;
}
inline void FileOptions::set_has_java_multiple_files() {
- _has_bits_[0] |= 0x00000004u;
+ _has_bits_[0] |= 0x00000080u;
}
inline void FileOptions::clear_has_java_multiple_files() {
- _has_bits_[0] &= ~0x00000004u;
+ _has_bits_[0] &= ~0x00000080u;
}
inline void FileOptions::clear_java_multiple_files() {
java_multiple_files_ = false;
@@ -6142,15 +6625,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];
+// optional bool java_generate_equals_and_hash = 20 [deprecated = true];
inline bool FileOptions::has_java_generate_equals_and_hash() const {
- return (_has_bits_[0] & 0x00000008u) != 0;
+ return (_has_bits_[0] & 0x00000100u) != 0;
}
inline void FileOptions::set_has_java_generate_equals_and_hash() {
- _has_bits_[0] |= 0x00000008u;
+ _has_bits_[0] |= 0x00000100u;
}
inline void FileOptions::clear_has_java_generate_equals_and_hash() {
- _has_bits_[0] &= ~0x00000008u;
+ _has_bits_[0] &= ~0x00000100u;
}
inline void FileOptions::clear_java_generate_equals_and_hash() {
java_generate_equals_and_hash_ = false;
@@ -6168,13 +6651,13 @@ inline void FileOptions::set_java_generate_equals_and_hash(bool value) {
// 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] & 0x00000200u) != 0;
}
inline void FileOptions::set_has_java_string_check_utf8() {
- _has_bits_[0] |= 0x00000010u;
+ _has_bits_[0] |= 0x00000200u;
}
inline void FileOptions::clear_has_java_string_check_utf8() {
- _has_bits_[0] &= ~0x00000010u;
+ _has_bits_[0] &= ~0x00000200u;
}
inline void FileOptions::clear_java_string_check_utf8() {
java_string_check_utf8_ = false;
@@ -6192,13 +6675,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] & 0x00008000u) != 0;
}
inline void FileOptions::set_has_optimize_for() {
- _has_bits_[0] |= 0x00000020u;
+ _has_bits_[0] |= 0x00008000u;
}
inline void FileOptions::clear_has_optimize_for() {
- _has_bits_[0] &= ~0x00000020u;
+ _has_bits_[0] &= ~0x00008000u;
}
inline void FileOptions::clear_optimize_for() {
optimize_for_ = 1;
@@ -6217,13 +6700,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] & 0x00000004u) != 0;
}
inline void FileOptions::set_has_go_package() {
- _has_bits_[0] |= 0x00000040u;
+ _has_bits_[0] |= 0x00000004u;
}
inline void FileOptions::clear_has_go_package() {
- _has_bits_[0] &= ~0x00000040u;
+ _has_bits_[0] &= ~0x00000004u;
}
inline void FileOptions::clear_go_package() {
go_package_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
@@ -6231,13 +6714,21 @@ inline void FileOptions::clear_go_package() {
}
inline 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());
+ return go_package_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void FileOptions::set_go_package(::std::string&& value) {
+ set_has_go_package();
+ go_package_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileOptions.go_package)
+}
+#endif
inline void FileOptions::set_go_package(const char* value) {
set_has_go_package();
go_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -6271,13 +6762,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] & 0x00000400u) != 0;
}
inline void FileOptions::set_has_cc_generic_services() {
- _has_bits_[0] |= 0x00000080u;
+ _has_bits_[0] |= 0x00000400u;
}
inline void FileOptions::clear_has_cc_generic_services() {
- _has_bits_[0] &= ~0x00000080u;
+ _has_bits_[0] &= ~0x00000400u;
}
inline void FileOptions::clear_cc_generic_services() {
cc_generic_services_ = false;
@@ -6295,13 +6786,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] & 0x00000800u) != 0;
}
inline void FileOptions::set_has_java_generic_services() {
- _has_bits_[0] |= 0x00000100u;
+ _has_bits_[0] |= 0x00000800u;
}
inline void FileOptions::clear_has_java_generic_services() {
- _has_bits_[0] &= ~0x00000100u;
+ _has_bits_[0] &= ~0x00000800u;
}
inline void FileOptions::clear_java_generic_services() {
java_generic_services_ = false;
@@ -6319,13 +6810,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] & 0x00001000u) != 0;
}
inline void FileOptions::set_has_py_generic_services() {
- _has_bits_[0] |= 0x00000200u;
+ _has_bits_[0] |= 0x00001000u;
}
inline void FileOptions::clear_has_py_generic_services() {
- _has_bits_[0] &= ~0x00000200u;
+ _has_bits_[0] &= ~0x00001000u;
}
inline void FileOptions::clear_py_generic_services() {
py_generic_services_ = false;
@@ -6343,13 +6834,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] & 0x00002000u) != 0;
}
inline void FileOptions::set_has_deprecated() {
- _has_bits_[0] |= 0x00000400u;
+ _has_bits_[0] |= 0x00002000u;
}
inline void FileOptions::clear_has_deprecated() {
- _has_bits_[0] &= ~0x00000400u;
+ _has_bits_[0] &= ~0x00002000u;
}
inline void FileOptions::clear_deprecated() {
deprecated_ = false;
@@ -6367,13 +6858,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] & 0x00004000u) != 0;
}
inline void FileOptions::set_has_cc_enable_arenas() {
- _has_bits_[0] |= 0x00000800u;
+ _has_bits_[0] |= 0x00004000u;
}
inline void FileOptions::clear_has_cc_enable_arenas() {
- _has_bits_[0] &= ~0x00000800u;
+ _has_bits_[0] &= ~0x00004000u;
}
inline void FileOptions::clear_cc_enable_arenas() {
cc_enable_arenas_ = false;
@@ -6391,13 +6882,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] & 0x00000008u) != 0;
}
inline void FileOptions::set_has_objc_class_prefix() {
- _has_bits_[0] |= 0x00001000u;
+ _has_bits_[0] |= 0x00000008u;
}
inline void FileOptions::clear_has_objc_class_prefix() {
- _has_bits_[0] &= ~0x00001000u;
+ _has_bits_[0] &= ~0x00000008u;
}
inline void FileOptions::clear_objc_class_prefix() {
objc_class_prefix_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
@@ -6405,13 +6896,21 @@ inline void FileOptions::clear_objc_class_prefix() {
}
inline 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());
+ return objc_class_prefix_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void FileOptions::set_objc_class_prefix(::std::string&& value) {
+ set_has_objc_class_prefix();
+ objc_class_prefix_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileOptions.objc_class_prefix)
+}
+#endif
inline 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));
@@ -6445,13 +6944,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] & 0x00000010u) != 0;
}
inline void FileOptions::set_has_csharp_namespace() {
- _has_bits_[0] |= 0x00002000u;
+ _has_bits_[0] |= 0x00000010u;
}
inline void FileOptions::clear_has_csharp_namespace() {
- _has_bits_[0] &= ~0x00002000u;
+ _has_bits_[0] &= ~0x00000010u;
}
inline void FileOptions::clear_csharp_namespace() {
csharp_namespace_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
@@ -6459,13 +6958,21 @@ inline void FileOptions::clear_csharp_namespace() {
}
inline 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());
+ return csharp_namespace_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void FileOptions::set_csharp_namespace(::std::string&& value) {
+ set_has_csharp_namespace();
+ csharp_namespace_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileOptions.csharp_namespace)
+}
+#endif
inline void FileOptions::set_csharp_namespace(const char* value) {
set_has_csharp_namespace();
csharp_namespace_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -6497,6 +7004,130 @@ inline void FileOptions::set_allocated_csharp_namespace(::std::string* csharp_na
// @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.csharp_namespace)
}
+// optional string swift_prefix = 39;
+inline bool FileOptions::has_swift_prefix() const {
+ return (_has_bits_[0] & 0x00000020u) != 0;
+}
+inline void FileOptions::set_has_swift_prefix() {
+ _has_bits_[0] |= 0x00000020u;
+}
+inline void FileOptions::clear_has_swift_prefix() {
+ _has_bits_[0] &= ~0x00000020u;
+}
+inline void FileOptions::clear_swift_prefix() {
+ swift_prefix_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ clear_has_swift_prefix();
+}
+inline const ::std::string& FileOptions::swift_prefix() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.swift_prefix)
+ return swift_prefix_.GetNoArena();
+}
+inline void FileOptions::set_swift_prefix(const ::std::string& value) {
+ set_has_swift_prefix();
+ swift_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
+ // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.swift_prefix)
+}
+#if LANG_CXX11
+inline void FileOptions::set_swift_prefix(::std::string&& value) {
+ set_has_swift_prefix();
+ swift_prefix_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileOptions.swift_prefix)
+}
+#endif
+inline void FileOptions::set_swift_prefix(const char* value) {
+ set_has_swift_prefix();
+ swift_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+ // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.swift_prefix)
+}
+inline void FileOptions::set_swift_prefix(const char* value, size_t size) {
+ set_has_swift_prefix();
+ swift_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+ ::std::string(reinterpret_cast<const char*>(value), size));
+ // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileOptions.swift_prefix)
+}
+inline ::std::string* FileOptions::mutable_swift_prefix() {
+ set_has_swift_prefix();
+ // @@protoc_insertion_point(field_mutable:google.protobuf.FileOptions.swift_prefix)
+ return swift_prefix_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+inline ::std::string* FileOptions::release_swift_prefix() {
+ // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.swift_prefix)
+ clear_has_swift_prefix();
+ return swift_prefix_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+inline void FileOptions::set_allocated_swift_prefix(::std::string* swift_prefix) {
+ if (swift_prefix != NULL) {
+ set_has_swift_prefix();
+ } else {
+ clear_has_swift_prefix();
+ }
+ swift_prefix_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), swift_prefix);
+ // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.swift_prefix)
+}
+
+// optional string php_class_prefix = 40;
+inline bool FileOptions::has_php_class_prefix() const {
+ return (_has_bits_[0] & 0x00000040u) != 0;
+}
+inline void FileOptions::set_has_php_class_prefix() {
+ _has_bits_[0] |= 0x00000040u;
+}
+inline void FileOptions::clear_has_php_class_prefix() {
+ _has_bits_[0] &= ~0x00000040u;
+}
+inline void FileOptions::clear_php_class_prefix() {
+ php_class_prefix_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ clear_has_php_class_prefix();
+}
+inline const ::std::string& FileOptions::php_class_prefix() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.php_class_prefix)
+ return php_class_prefix_.GetNoArena();
+}
+inline void FileOptions::set_php_class_prefix(const ::std::string& value) {
+ set_has_php_class_prefix();
+ php_class_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
+ // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.php_class_prefix)
+}
+#if LANG_CXX11
+inline void FileOptions::set_php_class_prefix(::std::string&& value) {
+ set_has_php_class_prefix();
+ php_class_prefix_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.FileOptions.php_class_prefix)
+}
+#endif
+inline void FileOptions::set_php_class_prefix(const char* value) {
+ set_has_php_class_prefix();
+ php_class_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+ // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.php_class_prefix)
+}
+inline void FileOptions::set_php_class_prefix(const char* value, size_t size) {
+ set_has_php_class_prefix();
+ php_class_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+ ::std::string(reinterpret_cast<const char*>(value), size));
+ // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileOptions.php_class_prefix)
+}
+inline ::std::string* FileOptions::mutable_php_class_prefix() {
+ set_has_php_class_prefix();
+ // @@protoc_insertion_point(field_mutable:google.protobuf.FileOptions.php_class_prefix)
+ return php_class_prefix_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+inline ::std::string* FileOptions::release_php_class_prefix() {
+ // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.php_class_prefix)
+ clear_has_php_class_prefix();
+ return php_class_prefix_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+inline void FileOptions::set_allocated_php_class_prefix(::std::string* php_class_prefix) {
+ if (php_class_prefix != NULL) {
+ set_has_php_class_prefix();
+ } else {
+ clear_has_php_class_prefix();
+ }
+ php_class_prefix_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), php_class_prefix);
+ // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.php_class_prefix)
+}
+
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
inline int FileOptions::uninterpreted_option_size() const {
return uninterpreted_option_.size();
@@ -6688,13 +7319,13 @@ inline void FieldOptions::set_ctype(::google::protobuf::FieldOptions_CType value
// optional bool packed = 2;
inline bool FieldOptions::has_packed() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
+ return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void FieldOptions::set_has_packed() {
- _has_bits_[0] |= 0x00000002u;
+ _has_bits_[0] |= 0x00000004u;
}
inline void FieldOptions::clear_has_packed() {
- _has_bits_[0] &= ~0x00000002u;
+ _has_bits_[0] &= ~0x00000004u;
}
inline void FieldOptions::clear_packed() {
packed_ = false;
@@ -6712,13 +7343,13 @@ inline void FieldOptions::set_packed(bool value) {
// optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];
inline bool FieldOptions::has_jstype() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
+ return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void FieldOptions::set_has_jstype() {
- _has_bits_[0] |= 0x00000004u;
+ _has_bits_[0] |= 0x00000002u;
}
inline void FieldOptions::clear_has_jstype() {
- _has_bits_[0] &= ~0x00000004u;
+ _has_bits_[0] &= ~0x00000002u;
}
inline void FieldOptions::clear_jstype() {
jstype_ = 0;
@@ -7097,6 +7728,31 @@ inline void MethodOptions::set_deprecated(bool value) {
// @@protoc_insertion_point(field_set:google.protobuf.MethodOptions.deprecated)
}
+// optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN];
+inline bool MethodOptions::has_idempotency_level() const {
+ return (_has_bits_[0] & 0x00000002u) != 0;
+}
+inline void MethodOptions::set_has_idempotency_level() {
+ _has_bits_[0] |= 0x00000002u;
+}
+inline void MethodOptions::clear_has_idempotency_level() {
+ _has_bits_[0] &= ~0x00000002u;
+}
+inline void MethodOptions::clear_idempotency_level() {
+ idempotency_level_ = 0;
+ clear_has_idempotency_level();
+}
+inline ::google::protobuf::MethodOptions_IdempotencyLevel MethodOptions::idempotency_level() const {
+ // @@protoc_insertion_point(field_get:google.protobuf.MethodOptions.idempotency_level)
+ return static_cast< ::google::protobuf::MethodOptions_IdempotencyLevel >(idempotency_level_);
+}
+inline void MethodOptions::set_idempotency_level(::google::protobuf::MethodOptions_IdempotencyLevel value) {
+ assert(::google::protobuf::MethodOptions_IdempotencyLevel_IsValid(value));
+ set_has_idempotency_level();
+ idempotency_level_ = value;
+ // @@protoc_insertion_point(field_set:google.protobuf.MethodOptions.idempotency_level)
+}
+
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
inline int MethodOptions::uninterpreted_option_size() const {
return uninterpreted_option_.size();
@@ -7147,13 +7803,21 @@ inline void UninterpretedOption_NamePart::clear_name_part() {
}
inline 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());
+ return name_part_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void UninterpretedOption_NamePart::set_name_part(::std::string&& value) {
+ set_has_name_part();
+ name_part_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.UninterpretedOption.NamePart.name_part)
+}
+#endif
inline void UninterpretedOption_NamePart::set_name_part(const char* value) {
set_has_name_part();
name_part_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -7245,13 +7909,13 @@ UninterpretedOption::name() const {
// optional string identifier_value = 3;
inline bool UninterpretedOption::has_identifier_value() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
+ return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void UninterpretedOption::set_has_identifier_value() {
- _has_bits_[0] |= 0x00000002u;
+ _has_bits_[0] |= 0x00000001u;
}
inline void UninterpretedOption::clear_has_identifier_value() {
- _has_bits_[0] &= ~0x00000002u;
+ _has_bits_[0] &= ~0x00000001u;
}
inline void UninterpretedOption::clear_identifier_value() {
identifier_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
@@ -7259,13 +7923,21 @@ inline void UninterpretedOption::clear_identifier_value() {
}
inline 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());
+ return identifier_value_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void UninterpretedOption::set_identifier_value(::std::string&& value) {
+ set_has_identifier_value();
+ identifier_value_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.UninterpretedOption.identifier_value)
+}
+#endif
inline void UninterpretedOption::set_identifier_value(const char* value) {
set_has_identifier_value();
identifier_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -7299,13 +7971,13 @@ inline void UninterpretedOption::set_allocated_identifier_value(::std::string* i
// optional uint64 positive_int_value = 4;
inline bool UninterpretedOption::has_positive_int_value() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
+ return (_has_bits_[0] & 0x00000008u) != 0;
}
inline void UninterpretedOption::set_has_positive_int_value() {
- _has_bits_[0] |= 0x00000004u;
+ _has_bits_[0] |= 0x00000008u;
}
inline void UninterpretedOption::clear_has_positive_int_value() {
- _has_bits_[0] &= ~0x00000004u;
+ _has_bits_[0] &= ~0x00000008u;
}
inline void UninterpretedOption::clear_positive_int_value() {
positive_int_value_ = GOOGLE_ULONGLONG(0);
@@ -7323,13 +7995,13 @@ inline void UninterpretedOption::set_positive_int_value(::google::protobuf::uint
// optional int64 negative_int_value = 5;
inline bool UninterpretedOption::has_negative_int_value() const {
- return (_has_bits_[0] & 0x00000008u) != 0;
+ return (_has_bits_[0] & 0x00000010u) != 0;
}
inline void UninterpretedOption::set_has_negative_int_value() {
- _has_bits_[0] |= 0x00000008u;
+ _has_bits_[0] |= 0x00000010u;
}
inline void UninterpretedOption::clear_has_negative_int_value() {
- _has_bits_[0] &= ~0x00000008u;
+ _has_bits_[0] &= ~0x00000010u;
}
inline void UninterpretedOption::clear_negative_int_value() {
negative_int_value_ = GOOGLE_LONGLONG(0);
@@ -7347,13 +8019,13 @@ inline void UninterpretedOption::set_negative_int_value(::google::protobuf::int6
// optional double double_value = 6;
inline bool UninterpretedOption::has_double_value() const {
- return (_has_bits_[0] & 0x00000010u) != 0;
+ return (_has_bits_[0] & 0x00000020u) != 0;
}
inline void UninterpretedOption::set_has_double_value() {
- _has_bits_[0] |= 0x00000010u;
+ _has_bits_[0] |= 0x00000020u;
}
inline void UninterpretedOption::clear_has_double_value() {
- _has_bits_[0] &= ~0x00000010u;
+ _has_bits_[0] &= ~0x00000020u;
}
inline void UninterpretedOption::clear_double_value() {
double_value_ = 0;
@@ -7371,13 +8043,13 @@ inline void UninterpretedOption::set_double_value(double value) {
// optional bytes string_value = 7;
inline bool UninterpretedOption::has_string_value() const {
- return (_has_bits_[0] & 0x00000020u) != 0;
+ return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void UninterpretedOption::set_has_string_value() {
- _has_bits_[0] |= 0x00000020u;
+ _has_bits_[0] |= 0x00000002u;
}
inline void UninterpretedOption::clear_has_string_value() {
- _has_bits_[0] &= ~0x00000020u;
+ _has_bits_[0] &= ~0x00000002u;
}
inline void UninterpretedOption::clear_string_value() {
string_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
@@ -7385,13 +8057,21 @@ inline void UninterpretedOption::clear_string_value() {
}
inline 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());
+ return string_value_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void UninterpretedOption::set_string_value(::std::string&& value) {
+ set_has_string_value();
+ string_value_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.UninterpretedOption.string_value)
+}
+#endif
inline void UninterpretedOption::set_string_value(const char* value) {
set_has_string_value();
string_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -7425,13 +8105,13 @@ inline void UninterpretedOption::set_allocated_string_value(::std::string* strin
// optional string aggregate_value = 8;
inline bool UninterpretedOption::has_aggregate_value() const {
- return (_has_bits_[0] & 0x00000040u) != 0;
+ return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void UninterpretedOption::set_has_aggregate_value() {
- _has_bits_[0] |= 0x00000040u;
+ _has_bits_[0] |= 0x00000004u;
}
inline void UninterpretedOption::clear_has_aggregate_value() {
- _has_bits_[0] &= ~0x00000040u;
+ _has_bits_[0] &= ~0x00000004u;
}
inline void UninterpretedOption::clear_aggregate_value() {
aggregate_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
@@ -7439,13 +8119,21 @@ inline void UninterpretedOption::clear_aggregate_value() {
}
inline 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());
+ return aggregate_value_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void UninterpretedOption::set_aggregate_value(::std::string&& value) {
+ set_has_aggregate_value();
+ aggregate_value_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.UninterpretedOption.aggregate_value)
+}
+#endif
inline void UninterpretedOption::set_aggregate_value(const char* value) {
set_has_aggregate_value();
aggregate_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -7543,13 +8231,13 @@ SourceCodeInfo_Location::mutable_span() {
// optional string leading_comments = 3;
inline bool SourceCodeInfo_Location::has_leading_comments() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
+ return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void SourceCodeInfo_Location::set_has_leading_comments() {
- _has_bits_[0] |= 0x00000004u;
+ _has_bits_[0] |= 0x00000001u;
}
inline void SourceCodeInfo_Location::clear_has_leading_comments() {
- _has_bits_[0] &= ~0x00000004u;
+ _has_bits_[0] &= ~0x00000001u;
}
inline void SourceCodeInfo_Location::clear_leading_comments() {
leading_comments_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
@@ -7557,13 +8245,21 @@ inline void SourceCodeInfo_Location::clear_leading_comments() {
}
inline 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());
+ return leading_comments_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void SourceCodeInfo_Location::set_leading_comments(::std::string&& value) {
+ set_has_leading_comments();
+ leading_comments_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.SourceCodeInfo.Location.leading_comments)
+}
+#endif
inline void SourceCodeInfo_Location::set_leading_comments(const char* value) {
set_has_leading_comments();
leading_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -7597,13 +8293,13 @@ inline void SourceCodeInfo_Location::set_allocated_leading_comments(::std::strin
// optional string trailing_comments = 4;
inline bool SourceCodeInfo_Location::has_trailing_comments() const {
- return (_has_bits_[0] & 0x00000008u) != 0;
+ return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void SourceCodeInfo_Location::set_has_trailing_comments() {
- _has_bits_[0] |= 0x00000008u;
+ _has_bits_[0] |= 0x00000002u;
}
inline void SourceCodeInfo_Location::clear_has_trailing_comments() {
- _has_bits_[0] &= ~0x00000008u;
+ _has_bits_[0] &= ~0x00000002u;
}
inline void SourceCodeInfo_Location::clear_trailing_comments() {
trailing_comments_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
@@ -7611,13 +8307,21 @@ inline void SourceCodeInfo_Location::clear_trailing_comments() {
}
inline 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());
+ return trailing_comments_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void SourceCodeInfo_Location::set_trailing_comments(::std::string&& value) {
+ set_has_trailing_comments();
+ trailing_comments_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.SourceCodeInfo.Location.trailing_comments)
+}
+#endif
inline void SourceCodeInfo_Location::set_trailing_comments(const char* value) {
set_has_trailing_comments();
trailing_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -7668,6 +8372,12 @@ inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, co
// @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
leading_detached_comments_.Mutable(index)->assign(value);
}
+#if LANG_CXX11
+inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, ::std::string&& value) {
+ // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
+ leading_detached_comments_.Mutable(index)->assign(std::move(value));
+}
+#endif
inline 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)
@@ -7685,6 +8395,12 @@ inline void SourceCodeInfo_Location::add_leading_detached_comments(const ::std::
leading_detached_comments_.Add()->assign(value);
// @@protoc_insertion_point(field_add:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
}
+#if LANG_CXX11
+inline void SourceCodeInfo_Location::add_leading_detached_comments(::std::string&& value) {
+ leading_detached_comments_.Add()->assign(std::move(value));
+ // @@protoc_insertion_point(field_add:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
+}
+#endif
inline 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)
@@ -7774,13 +8490,13 @@ GeneratedCodeInfo_Annotation::mutable_path() {
// optional string source_file = 2;
inline bool GeneratedCodeInfo_Annotation::has_source_file() const {
- return (_has_bits_[0] & 0x00000002u) != 0;
+ return (_has_bits_[0] & 0x00000001u) != 0;
}
inline void GeneratedCodeInfo_Annotation::set_has_source_file() {
- _has_bits_[0] |= 0x00000002u;
+ _has_bits_[0] |= 0x00000001u;
}
inline void GeneratedCodeInfo_Annotation::clear_has_source_file() {
- _has_bits_[0] &= ~0x00000002u;
+ _has_bits_[0] &= ~0x00000001u;
}
inline void GeneratedCodeInfo_Annotation::clear_source_file() {
source_file_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
@@ -7788,13 +8504,21 @@ inline void GeneratedCodeInfo_Annotation::clear_source_file() {
}
inline 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());
+ return source_file_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void GeneratedCodeInfo_Annotation::set_source_file(::std::string&& value) {
+ set_has_source_file();
+ source_file_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.GeneratedCodeInfo.Annotation.source_file)
+}
+#endif
inline void GeneratedCodeInfo_Annotation::set_source_file(const char* value) {
set_has_source_file();
source_file_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -7828,13 +8552,13 @@ inline void GeneratedCodeInfo_Annotation::set_allocated_source_file(::std::strin
// optional int32 begin = 3;
inline bool GeneratedCodeInfo_Annotation::has_begin() const {
- return (_has_bits_[0] & 0x00000004u) != 0;
+ return (_has_bits_[0] & 0x00000002u) != 0;
}
inline void GeneratedCodeInfo_Annotation::set_has_begin() {
- _has_bits_[0] |= 0x00000004u;
+ _has_bits_[0] |= 0x00000002u;
}
inline void GeneratedCodeInfo_Annotation::clear_has_begin() {
- _has_bits_[0] &= ~0x00000004u;
+ _has_bits_[0] &= ~0x00000002u;
}
inline void GeneratedCodeInfo_Annotation::clear_begin() {
begin_ = 0;
@@ -7852,13 +8576,13 @@ inline void GeneratedCodeInfo_Annotation::set_begin(::google::protobuf::int32 va
// optional int32 end = 4;
inline bool GeneratedCodeInfo_Annotation::has_end() const {
- return (_has_bits_[0] & 0x00000008u) != 0;
+ return (_has_bits_[0] & 0x00000004u) != 0;
}
inline void GeneratedCodeInfo_Annotation::set_has_end() {
- _has_bits_[0] |= 0x00000008u;
+ _has_bits_[0] |= 0x00000004u;
}
inline void GeneratedCodeInfo_Annotation::clear_has_end() {
- _has_bits_[0] &= ~0x00000008u;
+ _has_bits_[0] &= ~0x00000004u;
}
inline void GeneratedCodeInfo_Annotation::clear_end() {
end_ = 0;
@@ -7960,6 +8684,7 @@ GeneratedCodeInfo::annotation() const {
// @@protoc_insertion_point(namespace_scope)
+
} // namespace protobuf
} // namespace google
@@ -7992,6 +8717,11 @@ template <>
inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::FieldOptions_JSType>() {
return ::google::protobuf::FieldOptions_JSType_descriptor();
}
+template <> struct is_proto_enum< ::google::protobuf::MethodOptions_IdempotencyLevel> : ::google::protobuf::internal::true_type {};
+template <>
+inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::MethodOptions_IdempotencyLevel>() {
+ return ::google::protobuf::MethodOptions_IdempotencyLevel_descriptor();
+}
} // namespace protobuf
} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/descriptor.proto b/third_party/protobuf/src/google/protobuf/descriptor.proto
index 28410d4a9a..be22368390 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/descriptor.proto
+++ b/third_party/protobuf/src/google/protobuf/descriptor.proto
@@ -40,12 +40,11 @@
syntax = "proto2";
package google.protobuf;
-option go_package = "descriptor";
+option go_package = "github.com/golang/protobuf/protoc-gen-go/descriptor;descriptor";
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.
@@ -140,7 +139,11 @@ message FieldDescriptorProto {
TYPE_FIXED32 = 7;
TYPE_BOOL = 8;
TYPE_STRING = 9;
- TYPE_GROUP = 10; // Tag-delimited aggregate.
+ // Tag-delimited aggregate.
+ // Group type is deprecated and not supported in proto3. However, Proto3
+ // implementations should still be able to parse the group wire format and
+ // treat group fields as unknown fields.
+ TYPE_GROUP = 10;
TYPE_MESSAGE = 11; // Length-delimited aggregate.
// New in version 2.
@@ -158,7 +161,6 @@ message FieldDescriptorProto {
LABEL_OPTIONAL = 1;
LABEL_REQUIRED = 2;
LABEL_REPEATED = 3;
- // TODO(sanjay): Should we add LABEL_MAP?
};
optional string name = 1;
@@ -306,19 +308,8 @@ 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];
+ // This option does nothing.
+ optional bool java_generate_equals_and_hash = 20 [deprecated=true];
// 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
@@ -379,6 +370,16 @@ message FileOptions {
// Namespace for generated classes; defaults to the package.
optional string csharp_namespace = 37;
+ // By default Swift generators will take the proto package and CamelCase it
+ // replacing '.' with underscore and use that to prefix the types/symbols
+ // defined. When this options is provided, they will use this value instead
+ // to prefix the types/symbols defined.
+ optional string swift_prefix = 39;
+
+ // Sets the php class prefix which is prepended to all php generated classes
+ // from this .proto. Default is empty.
+ optional string php_class_prefix = 40;
+
// The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999;
@@ -443,6 +444,9 @@ message MessageOptions {
// parser.
optional bool map_entry = 7;
+ reserved 8; // javalite_serializable
+
+
// The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999;
@@ -471,7 +475,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 +515,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 +541,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 {
@@ -560,6 +565,7 @@ message EnumOptions {
// is a formalization for deprecating enums.
optional bool deprecated = 3 [default=false];
+
// The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999;
@@ -614,6 +620,17 @@ message MethodOptions {
// this is a formalization for deprecating methods.
optional bool deprecated = 33 [default=false];
+ // Is this method side-effect-free (or safe in HTTP parlance), or idempotent,
+ // or neither? HTTP based RPC implementation may choose GET verb for safe
+ // methods, and PUT verb for idempotent methods instead of the default POST.
+ enum IdempotencyLevel {
+ IDEMPOTENCY_UNKNOWN = 0;
+ NO_SIDE_EFFECTS = 1; // implies idempotent
+ IDEMPOTENT = 2; // idempotent, but may have side effects
+ }
+ optional IdempotencyLevel idempotency_level =
+ 34 [default=IDEMPOTENCY_UNKNOWN];
+
// The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/descriptor_database.cc b/third_party/protobuf/src/google/protobuf/descriptor_database.cc
index 2117c020f5..57ae960f9b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/descriptor_database.cc
+++ b/third_party/protobuf/src/google/protobuf/descriptor_database.cc
@@ -97,11 +97,12 @@ bool SimpleDescriptorDatabase::DescriptorIndex<Value>::AddSymbol(
// Try to look up the symbol to make sure a super-symbol doesn't already
// exist.
- typename map<string, Value>::iterator iter = FindLastLessOrEqual(name);
+ typename std::map<string, Value>::iterator iter = FindLastLessOrEqual(name);
if (iter == by_symbol_.end()) {
// Apparently the map is currently empty. Just insert and be done with it.
- by_symbol_.insert(typename map<string, Value>::value_type(name, value));
+ by_symbol_.insert(
+ typename std::map<string, Value>::value_type(name, value));
return true;
}
@@ -128,7 +129,8 @@ bool SimpleDescriptorDatabase::DescriptorIndex<Value>::AddSymbol(
// Insert the new symbol using the iterator as a hint, the new entry will
// appear immediately before the one the iterator is pointing at.
- by_symbol_.insert(iter, typename map<string, Value>::value_type(name, value));
+ by_symbol_.insert(iter,
+ typename std::map<string, Value>::value_type(name, value));
return true;
}
@@ -179,7 +181,7 @@ Value SimpleDescriptorDatabase::DescriptorIndex<Value>::FindFile(
template <typename Value>
Value SimpleDescriptorDatabase::DescriptorIndex<Value>::FindSymbol(
const string& name) {
- typename map<string, Value>::iterator iter = FindLastLessOrEqual(name);
+ typename std::map<string, Value>::iterator iter = FindLastLessOrEqual(name);
return (iter != by_symbol_.end() && IsSubSymbol(iter->first, name)) ?
iter->second : Value();
@@ -196,8 +198,8 @@ Value SimpleDescriptorDatabase::DescriptorIndex<Value>::FindExtension(
template <typename Value>
bool SimpleDescriptorDatabase::DescriptorIndex<Value>::FindAllExtensionNumbers(
const string& containing_type,
- vector<int>* output) {
- typename map<pair<string, int>, Value>::const_iterator it =
+ std::vector<int>* output) {
+ typename std::map<pair<string, int>, Value>::const_iterator it =
by_extension_.lower_bound(std::make_pair(containing_type, 0));
bool success = false;
@@ -217,7 +219,8 @@ SimpleDescriptorDatabase::DescriptorIndex<Value>::FindLastLessOrEqual(
// Find the last key in the map which sorts less than or equal to the
// symbol name. Since upper_bound() returns the *first* key that sorts
// *greater* than the input, we want the element immediately before that.
- typename map<string, Value>::iterator iter = by_symbol_.upper_bound(name);
+ typename std::map<string, Value>::iterator iter =
+ by_symbol_.upper_bound(name);
if (iter != by_symbol_.begin()) --iter;
return iter;
}
@@ -284,7 +287,7 @@ bool SimpleDescriptorDatabase::FindFileContainingExtension(
bool SimpleDescriptorDatabase::FindAllExtensionNumbers(
const string& extendee_type,
- vector<int>* output) {
+ std::vector<int>* output) {
return index_.FindAllExtensionNumbers(extendee_type, output);
}
@@ -340,7 +343,7 @@ bool EncodedDescriptorDatabase::FindFileContainingSymbol(
bool EncodedDescriptorDatabase::FindNameOfFileContainingSymbol(
const string& symbol_name,
string* output) {
- pair<const void*, int> encoded_file = index_.FindSymbol(symbol_name);
+ std::pair<const void*, int> encoded_file = index_.FindSymbol(symbol_name);
if (encoded_file.first == NULL) return false;
// Optimization: The name should be the first field in the encoded message.
@@ -352,7 +355,7 @@ bool EncodedDescriptorDatabase::FindNameOfFileContainingSymbol(
FileDescriptorProto::kNameFieldNumber,
internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED);
- if (input.ReadTag() == kNameTag) {
+ if (input.ReadTagNoLastTag() == kNameTag) {
// Success!
return internal::WireFormatLite::ReadString(&input, output);
} else {
@@ -376,12 +379,12 @@ bool EncodedDescriptorDatabase::FindFileContainingExtension(
bool EncodedDescriptorDatabase::FindAllExtensionNumbers(
const string& extendee_type,
- vector<int>* output) {
+ std::vector<int>* output) {
return index_.FindAllExtensionNumbers(extendee_type, output);
}
bool EncodedDescriptorDatabase::MaybeParse(
- pair<const void*, int> encoded_file,
+ std::pair<const void*, int> encoded_file,
FileDescriptorProto* output) {
if (encoded_file.first == NULL) return false;
return output->ParseFromArray(encoded_file.first, encoded_file.second);
@@ -431,11 +434,11 @@ bool DescriptorPoolDatabase::FindFileContainingExtension(
bool DescriptorPoolDatabase::FindAllExtensionNumbers(
const string& extendee_type,
- vector<int>* output) {
+ std::vector<int>* output) {
const Descriptor* extendee = pool_.FindMessageTypeByName(extendee_type);
if (extendee == NULL) return false;
- vector<const FieldDescriptor*> extensions;
+ std::vector<const FieldDescriptor*> extensions;
pool_.FindAllExtensions(extendee, &extensions);
for (int i = 0; i < extensions.size(); ++i) {
@@ -454,7 +457,7 @@ MergedDescriptorDatabase::MergedDescriptorDatabase(
sources_.push_back(source2);
}
MergedDescriptorDatabase::MergedDescriptorDatabase(
- const vector<DescriptorDatabase*>& sources)
+ const std::vector<DescriptorDatabase*>& sources)
: sources_(sources) {}
MergedDescriptorDatabase::~MergedDescriptorDatabase() {}
@@ -517,23 +520,23 @@ bool MergedDescriptorDatabase::FindFileContainingExtension(
bool MergedDescriptorDatabase::FindAllExtensionNumbers(
const string& extendee_type,
- vector<int>* output) {
- set<int> merged_results;
- vector<int> results;
+ std::vector<int>* output) {
+ std::set<int> merged_results;
+ std::vector<int> results;
bool success = false;
for (int i = 0; i < sources_.size(); i++) {
if (sources_[i]->FindAllExtensionNumbers(extendee_type, &results)) {
- std::copy(
- results.begin(), results.end(),
- insert_iterator<set<int> >(merged_results, merged_results.begin()));
+ std::copy(results.begin(), results.end(),
+ std::insert_iterator<std::set<int> >(merged_results,
+ merged_results.begin()));
success = true;
}
results.clear();
}
std::copy(merged_results.begin(), merged_results.end(),
- insert_iterator<vector<int> >(*output, output->end()));
+ std::insert_iterator<std::vector<int> >(*output, output->end()));
return success;
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/descriptor_database.h b/third_party/protobuf/src/google/protobuf/descriptor_database.h
index 86002d56f6..be97a6d886 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/descriptor_database.h
+++ b/third_party/protobuf/src/google/protobuf/descriptor_database.h
@@ -97,7 +97,7 @@ class LIBPROTOBUF_EXPORT DescriptorDatabase {
// This method has a default implementation that always returns
// false.
virtual bool FindAllExtensionNumbers(const string& /* extendee_type */,
- vector<int>* /* output */) {
+ std::vector<int>* /* output */) {
return false;
}
@@ -150,7 +150,7 @@ class LIBPROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase {
int field_number,
FileDescriptorProto* output);
bool FindAllExtensionNumbers(const string& extendee_type,
- vector<int>* output);
+ std::vector<int>* output);
private:
// So that it can use DescriptorIndex.
@@ -175,12 +175,12 @@ class LIBPROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase {
Value FindSymbol(const string& name);
Value FindExtension(const string& containing_type, int field_number);
bool FindAllExtensionNumbers(const string& containing_type,
- vector<int>* output);
+ std::vector<int>* output);
private:
- map<string, Value> by_name_;
- map<string, Value> by_symbol_;
- map<pair<string, int>, Value> by_extension_;
+ std::map<string, Value> by_name_;
+ std::map<string, Value> by_symbol_;
+ std::map<std::pair<string, int>, Value> by_extension_;
// Invariant: The by_symbol_ map does not contain any symbols which are
// prefixes of other symbols in the map. For example, "foo.bar" is a
@@ -235,7 +235,7 @@ class LIBPROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase {
// Find the last entry in the by_symbol_ map whose key is less than or
// equal to the given name.
- typename map<string, Value>::iterator FindLastLessOrEqual(
+ typename std::map<string, Value>::iterator FindLastLessOrEqual(
const string& name);
// True if either the arguments are equal or super_symbol identifies a
@@ -250,7 +250,7 @@ class LIBPROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase {
DescriptorIndex<const FileDescriptorProto*> index_;
- vector<const FileDescriptorProto*> files_to_delete_;
+ std::vector<const FileDescriptorProto*> files_to_delete_;
// If file is non-NULL, copy it into *output and return true, otherwise
// return false.
@@ -295,15 +295,16 @@ class LIBPROTOBUF_EXPORT EncodedDescriptorDatabase : public DescriptorDatabase {
int field_number,
FileDescriptorProto* output);
bool FindAllExtensionNumbers(const string& extendee_type,
- vector<int>* output);
+ std::vector<int>* output);
private:
- SimpleDescriptorDatabase::DescriptorIndex<pair<const void*, int> > index_;
- vector<void*> files_to_delete_;
+ SimpleDescriptorDatabase::DescriptorIndex<std::pair<const void*, int> >
+ index_;
+ std::vector<void*> files_to_delete_;
// If encoded_file.first is non-NULL, parse the data into *output and return
// true, otherwise return false.
- bool MaybeParse(pair<const void*, int> encoded_file,
+ bool MaybeParse(std::pair<const void*, int> encoded_file,
FileDescriptorProto* output);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EncodedDescriptorDatabase);
@@ -324,7 +325,7 @@ class LIBPROTOBUF_EXPORT DescriptorPoolDatabase : public DescriptorDatabase {
int field_number,
FileDescriptorProto* output);
bool FindAllExtensionNumbers(const string& extendee_type,
- vector<int>* output);
+ std::vector<int>* output);
private:
const DescriptorPool& pool_;
@@ -341,7 +342,8 @@ class LIBPROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase {
// Merge more than two databases. The sources remain property of the caller.
// The vector may be deleted after the constructor returns but the
// DescriptorDatabases need to stick around.
- explicit MergedDescriptorDatabase(const vector<DescriptorDatabase*>& sources);
+ explicit MergedDescriptorDatabase(
+ const std::vector<DescriptorDatabase*>& sources);
~MergedDescriptorDatabase();
// implements DescriptorDatabase -----------------------------------
@@ -355,11 +357,11 @@ class LIBPROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase {
// Merges the results of calling all databases. Returns true iff any
// of the databases returned true.
bool FindAllExtensionNumbers(const string& extendee_type,
- vector<int>* output);
+ std::vector<int>* output);
private:
- vector<DescriptorDatabase*> sources_;
+ std::vector<DescriptorDatabase*> sources_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MergedDescriptorDatabase);
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/descriptor_database_unittest.cc b/third_party/protobuf/src/google/protobuf/descriptor_database_unittest.cc
index 4f568f7de1..05d67656f6 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/descriptor_database_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/descriptor_database_unittest.cc
@@ -410,7 +410,7 @@ TEST_P(DescriptorDatabaseTest, FindAllExtensionNumbers) {
"extension { name:\"waldo\" extendee: \"Bar\" number:56 } ");
{
- vector<int> numbers;
+ std::vector<int> numbers;
EXPECT_TRUE(database_->FindAllExtensionNumbers("Foo", &numbers));
ASSERT_EQ(2, numbers.size());
std::sort(numbers.begin(), numbers.end());
@@ -419,7 +419,7 @@ TEST_P(DescriptorDatabaseTest, FindAllExtensionNumbers) {
}
{
- vector<int> numbers;
+ std::vector<int> numbers;
EXPECT_TRUE(database_->FindAllExtensionNumbers("corge.Bar", &numbers));
// Note: won't find extension 56 due to the name not being fully qualified.
ASSERT_EQ(1, numbers.size());
@@ -428,13 +428,13 @@ TEST_P(DescriptorDatabaseTest, FindAllExtensionNumbers) {
{
// Can't find extensions for non-existent types.
- vector<int> numbers;
+ std::vector<int> numbers;
EXPECT_FALSE(database_->FindAllExtensionNumbers("NoSuchType", &numbers));
}
{
// Can't find extensions for unqualified types.
- vector<int> numbers;
+ std::vector<int> numbers;
EXPECT_FALSE(database_->FindAllExtensionNumbers("Bar", &numbers));
}
}
@@ -708,7 +708,7 @@ TEST_F(MergedDescriptorDatabaseTest, FindFileContainingExtension) {
TEST_F(MergedDescriptorDatabaseTest, FindAllExtensionNumbers) {
{
// Message only has extension in database1_
- vector<int> numbers;
+ std::vector<int> numbers;
EXPECT_TRUE(forward_merged_.FindAllExtensionNumbers("Foo", &numbers));
ASSERT_EQ(1, numbers.size());
EXPECT_EQ(3, numbers[0]);
@@ -716,7 +716,7 @@ TEST_F(MergedDescriptorDatabaseTest, FindAllExtensionNumbers) {
{
// Message only has extension in database2_
- vector<int> numbers;
+ std::vector<int> numbers;
EXPECT_TRUE(forward_merged_.FindAllExtensionNumbers("Bar", &numbers));
ASSERT_EQ(1, numbers.size());
EXPECT_EQ(5, numbers[0]);
@@ -724,7 +724,7 @@ TEST_F(MergedDescriptorDatabaseTest, FindAllExtensionNumbers) {
{
// Merge results from the two databases.
- vector<int> numbers;
+ std::vector<int> numbers;
EXPECT_TRUE(forward_merged_.FindAllExtensionNumbers("Baz", &numbers));
ASSERT_EQ(2, numbers.size());
std::sort(numbers.begin(), numbers.end());
@@ -733,7 +733,7 @@ TEST_F(MergedDescriptorDatabaseTest, FindAllExtensionNumbers) {
}
{
- vector<int> numbers;
+ std::vector<int> numbers;
EXPECT_TRUE(reverse_merged_.FindAllExtensionNumbers("Baz", &numbers));
ASSERT_EQ(2, numbers.size());
std::sort(numbers.begin(), numbers.end());
@@ -743,7 +743,7 @@ TEST_F(MergedDescriptorDatabaseTest, FindAllExtensionNumbers) {
{
// Can't find extensions for a non-existent message.
- vector<int> numbers;
+ std::vector<int> numbers;
EXPECT_FALSE(reverse_merged_.FindAllExtensionNumbers("Blah", &numbers));
}
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/descriptor_unittest.cc b/third_party/protobuf/src/google/protobuf/descriptor_unittest.cc
index 4183138f72..7ec75156b8 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/descriptor_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/descriptor_unittest.cc
@@ -41,8 +41,11 @@
#include <vector>
#include <google/protobuf/compiler/importer.h>
+#include <google/protobuf/compiler/parser.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/unittest_custom_options.pb.h>
+#include <google/protobuf/unittest_proto3_arena.pb.h>
+#include <google/protobuf/io/tokenizer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/descriptor.h>
@@ -55,6 +58,7 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/logging.h>
+#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
@@ -488,6 +492,65 @@ TEST_F(FileDescriptorTest, Syntax) {
}
}
+void ExtractDebugString(
+ const FileDescriptor* file, std::set<string>* visited,
+ std::vector<std::pair<string, string> >* debug_strings) {
+ if (!visited->insert(file->name()).second) {
+ return;
+ }
+ for (int i = 0; i < file->dependency_count(); ++i) {
+ ExtractDebugString(file->dependency(i), visited, debug_strings);
+ }
+ debug_strings->push_back(make_pair(file->name(), file->DebugString()));
+}
+
+class SimpleErrorCollector : public google::protobuf::io::ErrorCollector {
+ public:
+ // implements ErrorCollector ---------------------------------------
+ void AddError(int line, int column, const string& message) {
+ last_error_ = StringPrintf("%d:%d:", line, column) + message;
+ }
+
+ const string& last_error() { return last_error_; }
+
+ private:
+ string last_error_;
+};
+// Test that the result of FileDescriptor::DebugString() can be used to create
+// the original descriptors.
+TEST_F(FileDescriptorTest, DebugStringRoundTrip) {
+ std::set<string> visited;
+ std::vector<std::pair<string, string> > debug_strings;
+ ExtractDebugString(protobuf_unittest::TestAllTypes::descriptor()->file(),
+ &visited, &debug_strings);
+ ExtractDebugString(
+ protobuf_unittest::TestMessageWithCustomOptions::descriptor()->file(),
+ &visited, &debug_strings);
+ ExtractDebugString(proto3_arena_unittest::TestAllTypes::descriptor()->file(),
+ &visited, &debug_strings);
+ ASSERT_GE(debug_strings.size(), 3);
+
+ DescriptorPool pool;
+ for (int i = 0; i < debug_strings.size(); ++i) {
+ const string& name = debug_strings[i].first;
+ const string& content = debug_strings[i].second;
+ google::protobuf::io::ArrayInputStream input_stream(content.data(), content.size());
+ SimpleErrorCollector error_collector;
+ google::protobuf::io::Tokenizer tokenizer(&input_stream, &error_collector);
+ google::protobuf::compiler::Parser parser;
+ parser.RecordErrorsTo(&error_collector);
+ FileDescriptorProto proto;
+ ASSERT_TRUE(parser.Parse(&tokenizer, &proto))
+ << error_collector.last_error() << "\n"
+ << content;
+ ASSERT_EQ("", error_collector.last_error());
+ proto.set_name(name);
+ const FileDescriptor* descriptor = pool.BuildFile(proto);
+ ASSERT_TRUE(descriptor != NULL) << proto.DebugString();
+ EXPECT_EQ(content, descriptor->DebugString());
+ }
+}
+
// ===================================================================
// Test simple flat messages and fields.
@@ -773,9 +836,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 +856,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) {
@@ -1851,7 +1924,7 @@ TEST_F(ExtensionDescriptorTest, FindExtensionByName) {
}
TEST_F(ExtensionDescriptorTest, FindAllExtensions) {
- vector<const FieldDescriptor*> extensions;
+ std::vector<const FieldDescriptor*> extensions;
pool_.FindAllExtensions(foo_, &extensions);
ASSERT_EQ(4, extensions.size());
EXPECT_EQ(10, extensions[0]->number());
@@ -2615,7 +2688,7 @@ TEST_P(AllowUnknownDependenciesTest, CustomOption) {
// Verify that no extension options were set, but they were left as
// uninterpreted_options.
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
file->options().GetReflection()->ListFields(file->options(), &fields);
ASSERT_EQ(2, fields.size());
EXPECT_TRUE(file->options().has_optimize_for());
@@ -3266,6 +3339,85 @@ TEST(CustomOptions, OptionsWithRequiredEnums) {
EXPECT_EQ(protobuf_unittest::NewOptionType::NEW_VALUE, new_enum_opt.value());
}
+// Test that FileDescriptor::DebugString() formats custom options correctly.
+TEST(CustomOptions, DebugString) {
+ DescriptorPool pool;
+
+ FileDescriptorProto file_proto;
+ MessageOptions::descriptor()->file()->CopyTo(&file_proto);
+ ASSERT_TRUE(pool.BuildFile(file_proto) != NULL);
+
+ // Add "foo.proto":
+ // import "google/protobuf/descriptor.proto";
+ // package "protobuf_unittest";
+ // option (protobuf_unittest.cc_option1) = 1;
+ // option (protobuf_unittest.cc_option2) = 2;
+ // extend google.protobuf.FieldOptions {
+ // optional int32 cc_option1 = 7736974;
+ // optional int32 cc_option2 = 7736975;
+ // }
+ ASSERT_TRUE(TextFormat::ParseFromString(
+ "name: \"foo.proto\" "
+ "package: \"protobuf_unittest\" "
+ "dependency: \"google/protobuf/descriptor.proto\" "
+ "options { "
+ " uninterpreted_option { "
+ " name { "
+ " name_part: \"protobuf_unittest.cc_option1\" "
+ " is_extension: true "
+ " } "
+ " positive_int_value: 1 "
+ " } "
+ " uninterpreted_option { "
+ " name { "
+ " name_part: \"protobuf_unittest.cc_option2\" "
+ " is_extension: true "
+ " } "
+ " positive_int_value: 2 "
+ " } "
+ "} "
+ "extension { "
+ " name: \"cc_option1\" "
+ " extendee: \".google.protobuf.FileOptions\" "
+ // This field number is intentionally chosen to be the same as
+ // (.fileopt1) defined in unittest_custom_options.proto (linked
+ // in this test binary). This is to test whether we are messing
+ // generated pool with custom descriptor pools when dealing with
+ // custom options.
+ " number: 7736974 "
+ " label: LABEL_OPTIONAL "
+ " type: TYPE_INT32 "
+ "}"
+ "extension { "
+ " name: \"cc_option2\" "
+ " extendee: \".google.protobuf.FileOptions\" "
+ " number: 7736975 "
+ " label: LABEL_OPTIONAL "
+ " type: TYPE_INT32 "
+ "}",
+ &file_proto));
+ const FileDescriptor* descriptor = pool.BuildFile(file_proto);
+ ASSERT_TRUE(descriptor != NULL);
+
+ EXPECT_EQ(2, descriptor->extension_count());
+
+ ASSERT_EQ(
+ "syntax = \"proto2\";\n"
+ "\n"
+ "import \"google/protobuf/descriptor.proto\";\n"
+ "package protobuf_unittest;\n"
+ "\n"
+ "option (.protobuf_unittest.cc_option1) = 1;\n"
+ "option (.protobuf_unittest.cc_option2) = 2;\n"
+ "\n"
+ "extend .google.protobuf.FileOptions {\n"
+ " optional int32 cc_option1 = 7736974;\n"
+ " optional int32 cc_option2 = 7736975;\n"
+ "}\n"
+ "\n",
+ descriptor->DebugString());
+}
+
// ===================================================================
class ValidationErrorTest : public testing::Test {
@@ -5159,7 +5311,7 @@ TEST_F(ValidationErrorTest, ErrorsReportedToLogError) {
"message_type { name: \"Foo\" } ",
&file_proto));
- vector<string> errors;
+ std::vector<string> errors;
{
ScopedMemoryLog log;
@@ -5553,6 +5705,69 @@ TEST_F(ValidationErrorTest, MapEntryConflictsWithEnum) {
"with an existing enum type.\n");
}
+TEST_F(ValidationErrorTest, EnumValuesConflictWhenPrefixesStripped) {
+ BuildFileWithErrors(
+ "syntax: 'proto3'"
+ "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. This "
+ "will make the proto fail to compile for some languages, such as C#.\n");
+
+ BuildFileWithErrors(
+ "syntax: 'proto3'"
+ "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. This "
+ "will make the proto fail to compile for some languages, such as C#.\n");
+
+ BuildFileWithErrors(
+ "syntax: 'proto3'"
+ "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. This will make the proto fail to compile for some "
+ "languages, such as C#.\n");
+
+ BuildFileWithErrors(
+ "syntax: 'proto3'"
+ "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. This will make the proto fail to compile for some "
+ "languages, such as C#.\n");
+
+ // This isn't an error because the underscore will cause the PascalCase to
+ // differ by case (BarBaz vs. Barbaz).
+ BuildFile(
+ "syntax: 'proto3'"
+ "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);
@@ -6086,7 +6301,7 @@ TEST_F(DatabaseBackedPoolTest, FindAllExtensions) {
for (int i = 0; i < 2; ++i) {
// Repeat the lookup twice, to check that we get consistent
// results despite the fallback database lookup mutating the pool.
- vector<const FieldDescriptor*> extensions;
+ std::vector<const FieldDescriptor*> extensions;
pool.FindAllExtensions(foo, &extensions);
ASSERT_EQ(1, extensions.size());
EXPECT_EQ(5, extensions[0]->number());
@@ -6097,7 +6312,7 @@ TEST_F(DatabaseBackedPoolTest, ErrorWithoutErrorCollector) {
ErrorDescriptorDatabase error_database;
DescriptorPool pool(&error_database);
- vector<string> errors;
+ std::vector<string> errors;
{
ScopedMemoryLog log;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/drop_unknown_fields_test.cc b/third_party/protobuf/src/google/protobuf/drop_unknown_fields_test.cc
index 6f16dc5341..6f16dc5341 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/drop_unknown_fields_test.cc
+++ b/third_party/protobuf/src/google/protobuf/drop_unknown_fields_test.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/duration.pb.cc b/third_party/protobuf/src/google/protobuf/duration.pb.cc
index 94ece18ea4..e046cc5a7f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/duration.pb.cc
+++ b/third_party/protobuf/src/google/protobuf/duration.pb.cc
@@ -19,90 +19,104 @@
namespace google {
namespace protobuf {
+class DurationDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Duration> {
+} _Duration_default_instance_;
+
+namespace protobuf_google_2fprotobuf_2fduration_2eproto {
+
namespace {
-const ::google::protobuf::Descriptor* Duration_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- Duration_reflection_ = NULL;
+::google::protobuf::Metadata file_level_metadata[1];
} // namespace
+const ::google::protobuf::uint32 TableStruct::offsets[] = {
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Duration, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Duration, seconds_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Duration, nanos_),
+};
-void protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto() GOOGLE_ATTRIBUTE_COLD;
-void protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto();
- const ::google::protobuf::FileDescriptor* file =
- ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
- "google/protobuf/duration.proto");
- GOOGLE_CHECK(file != NULL);
- Duration_descriptor_ = file->message_type(0);
- static const int Duration_offsets_[2] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Duration, seconds_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Duration, nanos_),
- };
- Duration_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- Duration_descriptor_,
- Duration::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_));
-}
+static const ::google::protobuf::internal::MigrationSchema schemas[] = {
+ { 0, -1, sizeof(Duration)},
+};
+
+static ::google::protobuf::Message const * const file_default_instances[] = {
+ reinterpret_cast<const ::google::protobuf::Message*>(&_Duration_default_instance_),
+};
namespace {
-GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
-inline void protobuf_AssignDescriptorsOnce() {
- ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
- &protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto);
+void protobuf_AssignDescriptors() {
+ AddDescriptors();
+ ::google::protobuf::MessageFactory* factory = NULL;
+ AssignDescriptors(
+ "google/protobuf/duration.proto", schemas, file_default_instances, TableStruct::offsets, factory,
+ file_level_metadata, NULL, NULL);
+}
+
+void protobuf_AssignDescriptorsOnce() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
}
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());
+ ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
}
} // namespace
-void protobuf_ShutdownFile_google_2fprotobuf_2fduration_2eproto() {
- delete Duration::default_instance_;
- delete Duration_reflection_;
+void TableStruct::Shutdown() {
+ _Duration_default_instance_.Shutdown();
+ delete file_level_metadata[0].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 TableStruct::InitDefaultsImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
+ ::google::protobuf::internal::InitProtobufDefaults();
+ _Duration_default_instance_.DefaultConstruct();
+}
+
+void InitDefaults() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &TableStruct::InitDefaultsImpl);
+}
+void AddDescriptorsImpl() {
+ InitDefaults();
+ static const char descriptor[] = {
+ "\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\370\001\001\242\002\003GPB\252\002\036Google.Prot"
+ "obuf.WellKnownTypesb\006proto3"
+ };
::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"
- "obuf.WellKnownTypesb\006proto3", 227);
+ descriptor, 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::internal::OnShutdown(&TableStruct::Shutdown);
}
+void AddDescriptors() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
+}
// Force AddDescriptors() to be called at static initialization time.
-struct StaticDescriptorInitializer_google_2fprotobuf_2fduration_2eproto {
- StaticDescriptorInitializer_google_2fprotobuf_2fduration_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto();
+struct StaticDescriptorInitializer {
+ StaticDescriptorInitializer() {
+ AddDescriptors();
}
-} static_descriptor_initializer_google_2fprotobuf_2fduration_2eproto_;
+} static_descriptor_initializer;
+
+} // namespace protobuf_google_2fprotobuf_2fduration_2eproto
+
// ===================================================================
@@ -113,27 +127,37 @@ const int Duration::kNanosFieldNumber;
Duration::Duration()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fduration_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.Duration)
}
-
-void Duration::InitAsDefaultInstance() {
- _is_default_instance_ = true;
+Duration::Duration(::google::protobuf::Arena* arena)
+ : ::google::protobuf::Message(),
+ _internal_metadata_(arena) {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ protobuf_google_2fprotobuf_2fduration_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ SharedCtor();
+ RegisterArenaDtor(arena);
+ // @@protoc_insertion_point(arena_constructor:google.protobuf.Duration)
}
-
Duration::Duration(const Duration& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ ::memcpy(&seconds_, &from.seconds_,
+ reinterpret_cast<char*>(&nanos_) -
+ reinterpret_cast<char*>(&seconds_) + sizeof(nanos_));
// @@protoc_insertion_point(copy_constructor:google.protobuf.Duration)
}
void Duration::SharedCtor() {
- _is_default_instance_ = false;
+ ::memset(&seconds_, 0, reinterpret_cast<char*>(&nanos_) -
+ reinterpret_cast<char*>(&seconds_) + sizeof(nanos_));
_cached_size_ = 0;
- seconds_ = GOOGLE_LONGLONG(0);
- nanos_ = 0;
}
Duration::~Duration() {
@@ -142,58 +166,42 @@ 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;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Duration::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Duration_descriptor_;
+ protobuf_google_2fprotobuf_2fduration_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fduration_2eproto::file_level_metadata[0].descriptor;
}
const Duration& Duration::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fduration_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-Duration* Duration::default_instance_ = NULL;
-
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<Duration>(arena);
}
void Duration::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.Duration)
-#if defined(__clang__)
-#define ZR_HELPER_(f) \
- _Pragma("clang diagnostic push") \
- _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
- __builtin_offsetof(Duration, f) \
- _Pragma("clang diagnostic pop")
-#else
-#define ZR_HELPER_(f) reinterpret_cast<char*>(\
- &reinterpret_cast<Duration*>(16)->f)
-#endif
-
-#define ZR_(first, last) do {\
- ::memset(&first, 0,\
- ZR_HELPER_(last) - ZR_HELPER_(first) + sizeof(last));\
-} while (0)
-
- ZR_(seconds_, nanos_);
-
-#undef ZR_HELPER_
-#undef ZR_
-
+ ::memset(&seconds_, 0, reinterpret_cast<char*>(&nanos_) -
+ reinterpret_cast<char*>(&seconds_) + sizeof(nanos_));
}
bool Duration::MergePartialFromCodedStream(
@@ -202,36 +210,35 @@ bool Duration::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Duration)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional int64 seconds = 1;
+ // int64 seconds = 1;
case 1: {
- if (tag == 8) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(8u)) {
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int64, ::google::protobuf::internal::WireFormatLite::TYPE_INT64>(
input, &seconds_)));
-
} else {
goto handle_unusual;
}
- if (input->ExpectTag(16)) goto parse_nanos;
break;
}
- // optional int32 nanos = 2;
+ // int32 nanos = 2;
case 2: {
- if (tag == 16) {
- parse_nanos:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(16u)) {
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
input, &nanos_)));
-
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -259,12 +266,12 @@ failure:
void Duration::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.Duration)
- // optional int64 seconds = 1;
+ // int64 seconds = 1;
if (this->seconds() != 0) {
::google::protobuf::internal::WireFormatLite::WriteInt64(1, this->seconds(), output);
}
- // optional int32 nanos = 2;
+ // int32 nanos = 2;
if (this->nanos() != 0) {
::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->nanos(), output);
}
@@ -274,13 +281,14 @@ void Duration::SerializeWithCachedSizes(
::google::protobuf::uint8* Duration::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Duration)
- // optional int64 seconds = 1;
+ // int64 seconds = 1;
if (this->seconds() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteInt64ToArray(1, this->seconds(), target);
}
- // optional int32 nanos = 2;
+ // int32 nanos = 2;
if (this->nanos() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->nanos(), target);
}
@@ -289,36 +297,35 @@ 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;
+ // int64 seconds = 1;
if (this->seconds() != 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::Int64Size(
this->seconds());
}
- // optional int32 nanos = 2;
+ // int32 nanos = 2;
if (this->nanos() != 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::Int32Size(
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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const Duration* source =
::google::protobuf::internal::DynamicCastToGenerated<const Duration>(
&from);
if (source == NULL) {
@@ -332,9 +339,8 @@ void Duration::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
if (from.seconds() != 0) {
set_seconds(from.seconds());
}
@@ -358,55 +364,65 @@ void Duration::CopyFrom(const Duration& from) {
}
bool Duration::IsInitialized() const {
-
return true;
}
void Duration::Swap(Duration* other) {
if (other == this) return;
+ if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
+ InternalSwap(other);
+ } else {
+ Duration* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
+ }
+}
+void Duration::UnsafeArenaSwap(Duration* other) {
+ if (other == this) return;
+ GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual());
InternalSwap(other);
}
void Duration::InternalSwap(Duration* other) {
std::swap(seconds_, other->seconds_);
std::swap(nanos_, other->nanos_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Duration::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = Duration_descriptor_;
- metadata.reflection = Duration_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fduration_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fduration_2eproto::file_level_metadata[0];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// Duration
-// optional int64 seconds = 1;
+// int64 seconds = 1;
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)
}
-// optional int32 nanos = 2;
+// int32 nanos = 2;
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/third_party/protobuf/3.0.0/src/google/protobuf/duration.pb.h b/third_party/protobuf/src/google/protobuf/duration.pb.h
index ad47963943..591c11d1da 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/duration.pb.h
+++ b/third_party/protobuf/src/google/protobuf/duration.pb.h
@@ -8,36 +8,48 @@
#include <google/protobuf/stubs/common.h>
-#if GOOGLE_PROTOBUF_VERSION < 3000000
+#if GOOGLE_PROTOBUF_VERSION < 3002000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
-#if 3000000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
+#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
+#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/metadata.h>
#include <google/protobuf/message.h>
-#include <google/protobuf/repeated_field.h>
-#include <google/protobuf/extension_set.h>
+#include <google/protobuf/repeated_field.h> // IWYU pragma: export
+#include <google/protobuf/extension_set.h> // IWYU pragma: export
#include <google/protobuf/unknown_field_set.h>
// @@protoc_insertion_point(includes)
+namespace google {
+namespace protobuf {
+class Duration;
+class DurationDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern DurationDefaultTypeInternal _Duration_default_instance_;
+} // namespace protobuf
+} // namespace google
namespace google {
namespace protobuf {
+namespace protobuf_google_2fprotobuf_2fduration_2eproto {
// Internal implementation detail -- do not call these.
-void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto();
-void protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto();
-void protobuf_ShutdownFile_google_2fprotobuf_2fduration_2eproto();
-
-class Duration;
+struct LIBPROTOBUF_EXPORT TableStruct {
+ static const ::google::protobuf::uint32 offsets[];
+ static void InitDefaultsImpl();
+ static void Shutdown();
+};
+void LIBPROTOBUF_EXPORT AddDescriptors();
+void LIBPROTOBUF_EXPORT InitDefaults();
+} // namespace protobuf_google_2fprotobuf_2fduration_2eproto
// ===================================================================
@@ -53,39 +65,58 @@ class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@prot
return *this;
}
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
+ return MaybeArenaPtr();
+ }
static const ::google::protobuf::Descriptor* descriptor();
static const Duration& default_instance();
+ static inline const Duration* internal_default_instance() {
+ return reinterpret_cast<const Duration*>(
+ &_Duration_default_instance_);
+ }
+
+ void UnsafeArenaSwap(Duration* other);
void Swap(Duration* other);
// implements Message ----------------------------------------------
- inline Duration* New() const { return New(NULL); }
+ inline Duration* New() const PROTOBUF_FINAL { return New(NULL); }
- Duration* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ Duration* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Duration& from);
void MergeFrom(const Duration& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Duration* other);
+ 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();
@@ -95,19 +126,19 @@ class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@prot
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional int64 seconds = 1;
+ // int64 seconds = 1;
void clear_seconds();
static const int kSecondsFieldNumber = 1;
::google::protobuf::int64 seconds() const;
void set_seconds(::google::protobuf::int64 value);
- // optional int32 nanos = 2;
+ // int32 nanos = 2;
void clear_nanos();
static const int kNanosFieldNumber = 2;
::google::protobuf::int32 nanos() const;
@@ -117,16 +148,13 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fduration_2eproto();
-
- void InitAsDefaultInstance();
- static Duration* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fduration_2eproto::TableStruct;
};
// ===================================================================
@@ -136,7 +164,7 @@ class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@prot
#if !PROTOBUF_INLINE_NOT_IN_HEADERS
// Duration
-// optional int64 seconds = 1;
+// int64 seconds = 1;
inline void Duration::clear_seconds() {
seconds_ = GOOGLE_LONGLONG(0);
}
@@ -150,7 +178,7 @@ inline void Duration::set_seconds(::google::protobuf::int64 value) {
// @@protoc_insertion_point(field_set:google.protobuf.Duration.seconds)
}
-// optional int32 nanos = 2;
+// int32 nanos = 2;
inline void Duration::clear_nanos() {
nanos_ = 0;
}
@@ -168,6 +196,7 @@ inline void Duration::set_nanos(::google::protobuf::int32 value) {
// @@protoc_insertion_point(namespace_scope)
+
} // namespace protobuf
} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/duration.proto b/third_party/protobuf/src/google/protobuf/duration.proto
index 96c1796d65..7f461f408d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/duration.proto
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/src/google/protobuf/dynamic_message.cc b/third_party/protobuf/src/google/protobuf/dynamic_message.cc
index 5d914bf63e..d6bde495ba 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/dynamic_message.cc
+++ b/third_party/protobuf/src/google/protobuf/dynamic_message.cc
@@ -88,11 +88,11 @@
namespace google {
namespace protobuf {
-using internal::WireFormat;
+using internal::DynamicMapField;
using internal::ExtensionSet;
using internal::GeneratedMessageReflection;
+using internal::InternalMetadataWithArena;
using internal::MapField;
-using internal::DynamicMapField;
using internal::ArenaStringPtr;
@@ -221,9 +221,8 @@ class DynamicMessage : public Message {
int size;
int has_bits_offset;
int oneof_case_offset;
- int unknown_fields_offset;
+ int internal_metadata_offset;
int extensions_offset;
- int is_default_instance_offset;
// Not owned by the TypeInfo.
DynamicMessageFactory* factory; // The factory that created this object.
@@ -232,20 +231,19 @@ class DynamicMessage : public Message {
// Warning: The order in which the following pointers are defined is
// important (the prototype must be deleted *before* the offsets).
- google::protobuf::scoped_array<int> offsets;
+ google::protobuf::scoped_array<uint32> offsets;
+ google::protobuf::scoped_array<uint32> has_bits_indices;
google::protobuf::scoped_ptr<const GeneratedMessageReflection> reflection;
// Don't use a scoped_ptr to hold the prototype: the destructor for
// DynamicMessage needs to know whether it is the prototype, and does so by
// looking back at this field. This would assume details about the
// implementation of scoped_ptr.
const DynamicMessage* prototype;
- void* default_oneof_instance;
- TypeInfo() : prototype(NULL), default_oneof_instance(NULL) {}
+ TypeInfo() : prototype(NULL) {}
~TypeInfo() {
delete prototype;
- operator delete(default_oneof_instance);
}
};
@@ -328,19 +326,15 @@ void DynamicMessage::SharedCtor() {
// Initialize oneof cases.
for (int i = 0 ; i < descriptor->oneof_decl_count(); ++i) {
- new(OffsetToPointer(type_info_->oneof_case_offset + sizeof(uint32) * i))
+ new (OffsetToPointer(type_info_->oneof_case_offset + sizeof(uint32) * i))
uint32(0);
}
- if (type_info_->is_default_instance_offset != -1) {
- *reinterpret_cast<bool*>(
- OffsetToPointer(type_info_->is_default_instance_offset)) = false;
- }
-
- new(OffsetToPointer(type_info_->unknown_fields_offset)) UnknownFieldSet;
+ new (OffsetToPointer(type_info_->internal_metadata_offset))
+ InternalMetadataWithArena;
if (type_info_->extensions_offset != -1) {
- new(OffsetToPointer(type_info_->extensions_offset)) ExtensionSet;
+ new (OffsetToPointer(type_info_->extensions_offset)) ExtensionSet;
}
for (int i = 0; i < descriptor->field_count(); i++) {
@@ -385,10 +379,10 @@ void DynamicMessage::SharedCtor() {
if (is_prototype()) {
default_value = &field->default_value_string();
} else {
- default_value =
- &(reinterpret_cast<const ArenaStringPtr*>(
- type_info_->prototype->OffsetToPointer(
- type_info_->offsets[i]))->Get(NULL));
+ default_value = &(reinterpret_cast<const ArenaStringPtr*>(
+ type_info_->prototype->OffsetToPointer(
+ type_info_->offsets[i]))
+ ->Get());
}
ArenaStringPtr* asp = new(field_ptr) ArenaStringPtr();
asp->UnsafeSetDefault(default_value);
@@ -419,8 +413,9 @@ void DynamicMessage::SharedCtor() {
DynamicMessage::~DynamicMessage() {
const Descriptor* descriptor = type_info_->type;
- reinterpret_cast<UnknownFieldSet*>(
- OffsetToPointer(type_info_->unknown_fields_offset))->~UnknownFieldSet();
+ reinterpret_cast<InternalMetadataWithArena*>(
+ OffsetToPointer(type_info_->internal_metadata_offset))
+ ->~InternalMetadataWithArena();
if (type_info_->extensions_offset != -1) {
reinterpret_cast<ExtensionSet*>(
@@ -451,10 +446,10 @@ DynamicMessage::~DynamicMessage() {
case FieldOptions::STRING: {
const ::std::string* default_value =
&(reinterpret_cast<const ArenaStringPtr*>(
- reinterpret_cast<uint8*>(
- type_info_->default_oneof_instance)
- + type_info_->offsets[i])
- ->Get(NULL));
+ reinterpret_cast<const uint8*>(
+ type_info_->prototype) +
+ type_info_->offsets[i])
+ ->Get());
reinterpret_cast<ArenaStringPtr*>(field_ptr)->Destroy(
default_value, NULL);
break;
@@ -512,8 +507,9 @@ DynamicMessage::~DynamicMessage() {
case FieldOptions::STRING: {
const ::std::string* default_value =
&(reinterpret_cast<const ArenaStringPtr*>(
- type_info_->prototype->OffsetToPointer(
- type_info_->offsets[i]))->Get(NULL));
+ type_info_->prototype->OffsetToPointer(
+ type_info_->offsets[i]))
+ ->Get());
reinterpret_cast<ArenaStringPtr*>(field_ptr)->Destroy(
default_value, NULL);
break;
@@ -541,10 +537,6 @@ void DynamicMessage::CrossLinkPrototypes() {
for (int i = 0; i < descriptor->field_count(); i++) {
const FieldDescriptor* field = descriptor->field(i);
void* field_ptr = OffsetToPointer(type_info_->offsets[i]);
- if (field->containing_oneof()) {
- field_ptr = reinterpret_cast<uint8*>(
- type_info_->default_oneof_instance) + type_info_->offsets[i];
- }
if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
!field->is_repeated()) {
@@ -556,14 +548,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<bool*>(is_default_instance_ptr) = true;
- }
}
Message* DynamicMessage::New() const {
@@ -624,7 +608,7 @@ DynamicMessageFactory::~DynamicMessageFactory() {
iter != prototypes_->map_.end(); ++iter) {
DeleteDefaultOneofInstance(iter->second->type,
iter->second->offsets.get(),
- iter->second->default_oneof_instance);
+ iter->second->prototype);
delete iter->second;
}
}
@@ -663,7 +647,8 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock(
// or not that field is set.
// Compute size and offsets.
- int* offsets = new int[type->field_count() + type->oneof_decl_count()];
+ uint32* offsets =
+ new uint32[type->field_count() + type->oneof_decl_count()];
type_info->offsets.reset(offsets);
// Decide all field offsets by packing in order.
@@ -681,15 +666,12 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock(
DivideRoundingUp(type->field_count(), bitsizeof(uint32));
size += has_bits_array_size * sizeof(uint32);
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;
+ uint32* has_bits_indices = new uint32[type->field_count()];
+ for (int i = 0; i < type->field_count(); i++) {
+ has_bits_indices[i] = i;
+ }
+ type_info->has_bits_indices.reset(has_bits_indices);
}
// The oneof_case, if any. It is an array of uint32s.
@@ -710,6 +692,8 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock(
}
// All the fields.
+ //
+ // TODO(b/31226269): Optimize the order of fields to minimize padding.
for (int i = 0; i < type->field_count(); i++) {
// Make sure field is aligned to avoid bus errors.
// Oneof fields do not use any space.
@@ -728,19 +712,37 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock(
size += kMaxOneofUnionSize;
}
- // Add the UnknownFieldSet to the end.
+ // Add the InternalMetadataWithArena to the end.
size = AlignOffset(size);
- type_info->unknown_fields_offset = size;
- size += sizeof(UnknownFieldSet);
+ type_info->internal_metadata_offset = size;
+ size += sizeof(InternalMetadataWithArena);
// Align the final size to make sure no clever allocators think that
// alignment is not necessary.
- size = AlignOffset(size);
type_info->size = size;
- // Allocate the prototype.
+
+ // Construct the reflection object.
+
+ if (type->oneof_decl_count() > 0) {
+ // Compute the size of default oneof instance and offsets of default
+ // oneof fields.
+ for (int i = 0; i < type->oneof_decl_count(); i++) {
+ for (int j = 0; j < type->oneof_decl(i)->field_count(); j++) {
+ const FieldDescriptor* field = type->oneof_decl(i)->field(j);
+ int field_size = OneofFieldSpaceUsed(field);
+ size = AlignTo(size, std::min(kSafeAlignment, field_size));
+ offsets[field->index()] = size;
+ size += field_size;
+ }
+ }
+ }
+ size = AlignOffset(size);
+
+ // Allocate the prototype + oneof fields.
void* base = operator new(size);
memset(base, 0, size);
+
// The prototype in type_info has to be set before creating the prototype
// instance on memory. e.g., message Foo { map<int32, Foo> a = 1; }. When
// creating prototype for Foo, prototype of the map entry will also be
@@ -750,55 +752,26 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock(
type_info->prototype = static_cast<DynamicMessage*>(base);
DynamicMessage* prototype = new(base) DynamicMessage(type_info);
- // Construct the reflection object.
if (type->oneof_decl_count() > 0) {
- // Compute the size of default oneof instance and offsets of default
- // oneof fields.
- int oneof_size = 0;
- for (int i = 0; i < type->oneof_decl_count(); i++) {
- for (int j = 0; j < type->oneof_decl(i)->field_count(); j++) {
- const FieldDescriptor* field = type->oneof_decl(i)->field(j);
- int field_size = OneofFieldSpaceUsed(field);
- oneof_size = AlignTo(oneof_size, std::min(kSafeAlignment, field_size));
- offsets[field->index()] = oneof_size;
- oneof_size += field_size;
- }
- }
// Construct default oneof instance.
- type_info->default_oneof_instance = ::operator new(oneof_size);
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));
- } 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));
+ prototype);
}
+
+ internal::ReflectionSchema schema = {
+ type_info->prototype,
+ type_info->offsets.get(),
+ type_info->has_bits_indices.get(),
+ type_info->has_bits_offset,
+ type_info->internal_metadata_offset,
+ type_info->extensions_offset,
+ type_info->oneof_case_offset,
+ type_info->size};
+
+ type_info->reflection.reset(new GeneratedMessageReflection(
+ type_info->type, schema, type_info->pool, this));
+
// Cross link prototypes.
prototype->CrossLinkPrototypes();
@@ -807,7 +780,7 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock(
void DynamicMessageFactory::ConstructDefaultOneofInstance(
const Descriptor* type,
- const int offsets[],
+ const uint32 offsets[],
void* default_oneof_instance) {
for (int i = 0; i < type->oneof_decl_count(); i++) {
for (int j = 0; j < type->oneof_decl(i)->field_count(); j++) {
@@ -853,8 +826,8 @@ void DynamicMessageFactory::ConstructDefaultOneofInstance(
void DynamicMessageFactory::DeleteDefaultOneofInstance(
const Descriptor* type,
- const int offsets[],
- void* default_oneof_instance) {
+ const uint32 offsets[],
+ const void* default_oneof_instance) {
for (int i = 0; i < type->oneof_decl_count(); i++) {
for (int j = 0; j < type->oneof_decl(i)->field_count(); j++) {
const FieldDescriptor* field = type->oneof_decl(i)->field(j);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/dynamic_message.h b/third_party/protobuf/src/google/protobuf/dynamic_message.h
index f74cd7dd25..816170ea9c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/dynamic_message.h
+++ b/third_party/protobuf/src/google/protobuf/dynamic_message.h
@@ -38,12 +38,15 @@
#ifndef GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__
#define GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__
+#include <algorithm>
#include <memory>
#ifndef _SHARED_PTR_H
#include <google/protobuf/stubs/shared_ptr.h>
#endif
+#include <vector>
#include <google/protobuf/message.h>
+#include <google/protobuf/repeated_field.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/mutex.h>
@@ -136,16 +139,97 @@ class LIBPROTOBUF_EXPORT DynamicMessageFactory : public MessageFactory {
// Construct default oneof instance for reflection usage if oneof
// is defined.
static void ConstructDefaultOneofInstance(const Descriptor* type,
- const int offsets[],
+ const uint32 offsets[],
void* default_oneof_instance);
// Delete default oneof instance. Called by ~DynamicMessageFactory.
static void DeleteDefaultOneofInstance(const Descriptor* type,
- const int offsets[],
- void* default_oneof_instance);
+ const uint32 offsets[],
+ const void* default_oneof_instance);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMessageFactory);
};
+// Helper for computing a sorted list of map entries via reflection.
+class LIBPROTOBUF_EXPORT DynamicMapSorter {
+ public:
+ static std::vector<const Message*> Sort(const Message& message,
+ int map_size,
+ const Reflection* reflection,
+ const FieldDescriptor* field) {
+ std::vector<const Message*> result(map_size);
+ const RepeatedPtrField<Message>& map_field =
+ reflection->GetRepeatedPtrField<Message>(message, field);
+ int i = 0;
+ for (RepeatedPtrField<Message>::const_pointer_iterator it =
+ map_field.pointer_begin(); it != map_field.pointer_end(); ) {
+ result[i++] = *it++;
+ }
+ GOOGLE_DCHECK_EQ(result.size(), static_cast<size_t>(i));
+ MapEntryMessageComparator comparator(field->message_type());
+ std::sort(result.begin(), result.end(), comparator);
+ // Complain if the keys aren't in ascending order.
+#ifndef NDEBUG
+ for (int j = 1; j < map_size; j++) {
+ if (!comparator(result[j - 1], result[j])) {
+ GOOGLE_LOG(ERROR) << (comparator(result[j], result[j - 1]) ?
+ "internal error in map key sorting" :
+ "map keys are not unique");
+ }
+ }
+#endif
+ return result;
+ }
+
+ private:
+ class LIBPROTOBUF_EXPORT MapEntryMessageComparator {
+ public:
+ explicit MapEntryMessageComparator(const Descriptor* descriptor)
+ : field_(descriptor->field(0)) {}
+
+ bool operator()(const Message* a, const Message* b) {
+ const Reflection* reflection = a->GetReflection();
+ switch (field_->cpp_type()) {
+ case FieldDescriptor::CPPTYPE_BOOL: {
+ bool first = reflection->GetBool(*a, field_);
+ bool second = reflection->GetBool(*b, field_);
+ return first < second;
+ }
+ case FieldDescriptor::CPPTYPE_INT32: {
+ int32 first = reflection->GetInt32(*a, field_);
+ int32 second = reflection->GetInt32(*b, field_);
+ return first < second;
+ }
+ case FieldDescriptor::CPPTYPE_INT64: {
+ int64 first = reflection->GetInt64(*a, field_);
+ int64 second = reflection->GetInt64(*b, field_);
+ return first < second;
+ }
+ case FieldDescriptor::CPPTYPE_UINT32: {
+ uint32 first = reflection->GetUInt32(*a, field_);
+ uint32 second = reflection->GetUInt32(*b, field_);
+ return first < second;
+ }
+ case FieldDescriptor::CPPTYPE_UINT64: {
+ uint64 first = reflection->GetUInt64(*a, field_);
+ uint64 second = reflection->GetUInt64(*b, field_);
+ return first < second;
+ }
+ case FieldDescriptor::CPPTYPE_STRING: {
+ string first = reflection->GetString(*a, field_);
+ string second = reflection->GetString(*b, field_);
+ return first < second;
+ }
+ default:
+ GOOGLE_LOG(DFATAL) << "Invalid key for map field.";
+ return true;
+ }
+ }
+
+ private:
+ const FieldDescriptor* field_;
+ };
+};
+
} // namespace protobuf
} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/dynamic_message_unittest.cc b/third_party/protobuf/src/google/protobuf/dynamic_message_unittest.cc
index fe51d8cfdc..fe51d8cfdc 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/dynamic_message_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/dynamic_message_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/empty.pb.cc b/third_party/protobuf/src/google/protobuf/empty.pb.cc
index 83775753ad..31cba09716 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/empty.pb.cc
+++ b/third_party/protobuf/src/google/protobuf/empty.pb.cc
@@ -19,87 +19,101 @@
namespace google {
namespace protobuf {
+class EmptyDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Empty> {
+} _Empty_default_instance_;
+
+namespace protobuf_google_2fprotobuf_2fempty_2eproto {
+
namespace {
-const ::google::protobuf::Descriptor* Empty_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- Empty_reflection_ = NULL;
+::google::protobuf::Metadata file_level_metadata[1];
} // namespace
+const ::google::protobuf::uint32 TableStruct::offsets[] = {
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Empty, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+};
-void protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto() GOOGLE_ATTRIBUTE_COLD;
-void protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto();
- const ::google::protobuf::FileDescriptor* file =
- ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
- "google/protobuf/empty.proto");
- GOOGLE_CHECK(file != NULL);
- Empty_descriptor_ = file->message_type(0);
- static const int Empty_offsets_[1] = {
- };
- Empty_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- Empty_descriptor_,
- Empty::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_));
-}
+static const ::google::protobuf::internal::MigrationSchema schemas[] = {
+ { 0, -1, sizeof(Empty)},
+};
+
+static ::google::protobuf::Message const * const file_default_instances[] = {
+ reinterpret_cast<const ::google::protobuf::Message*>(&_Empty_default_instance_),
+};
namespace {
-GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
-inline void protobuf_AssignDescriptorsOnce() {
- ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
- &protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto);
+void protobuf_AssignDescriptors() {
+ AddDescriptors();
+ ::google::protobuf::MessageFactory* factory = NULL;
+ AssignDescriptors(
+ "google/protobuf/empty.proto", schemas, file_default_instances, TableStruct::offsets, factory,
+ file_level_metadata, NULL, NULL);
+}
+
+void protobuf_AssignDescriptorsOnce() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
}
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());
+ ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
}
} // namespace
-void protobuf_ShutdownFile_google_2fprotobuf_2fempty_2eproto() {
- delete Empty::default_instance_;
- delete Empty_reflection_;
+void TableStruct::Shutdown() {
+ _Empty_default_instance_.Shutdown();
+ delete file_level_metadata[0].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 TableStruct::InitDefaultsImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
+ ::google::protobuf::internal::InitProtobufDefaults();
+ _Empty_default_instance_.DefaultConstruct();
+}
+
+void InitDefaults() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &TableStruct::InitDefaultsImpl);
+}
+void AddDescriptorsImpl() {
+ InitDefaults();
+ static const char descriptor[] = {
+ "\n\033google/protobuf/empty.proto\022\017google.pr"
+ "otobuf\"\007\n\005EmptyBv\n\023com.google.protobufB\n"
+ "EmptyProtoP\001Z\'github.com/golang/protobuf"
+ "/ptypes/empty\370\001\001\242\002\003GPB\252\002\036Google.Protobuf"
+ ".WellKnownTypesb\006proto3"
+ };
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
- "\n\033google/protobuf/empty.proto\022\017google.pr"
- "otobuf\"\007\n\005EmptyBy\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);
+ descriptor, 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::internal::OnShutdown(&TableStruct::Shutdown);
}
+void AddDescriptors() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
+}
// Force AddDescriptors() to be called at static initialization time.
-struct StaticDescriptorInitializer_google_2fprotobuf_2fempty_2eproto {
- StaticDescriptorInitializer_google_2fprotobuf_2fempty_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto();
+struct StaticDescriptorInitializer {
+ StaticDescriptorInitializer() {
+ AddDescriptors();
}
-} static_descriptor_initializer_google_2fprotobuf_2fempty_2eproto_;
+} static_descriptor_initializer;
+
+} // namespace protobuf_google_2fprotobuf_2fempty_2eproto
+
// ===================================================================
@@ -108,32 +122,31 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fempty_2eproto {
Empty::Empty()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fempty_2eproto::InitDefaults();
+ }
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_google_2fprotobuf_2fempty_2eproto::InitDefaults();
+#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);
+ _internal_metadata_(NULL),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.Empty)
}
void Empty::SharedCtor() {
- _is_default_instance_ = false;
_cached_size_ = 0;
}
@@ -143,12 +156,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) {
@@ -163,17 +175,15 @@ void Empty::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Empty::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Empty_descriptor_;
+ protobuf_google_2fprotobuf_2fempty_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fempty_2eproto::file_level_metadata[0].descriptor;
}
const Empty& Empty::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fempty_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-Empty* Empty::default_instance_ = NULL;
-
Empty* Empty::New(::google::protobuf::Arena* arena) const {
return ::google::protobuf::Arena::CreateMessage<Empty>(arena);
}
@@ -188,7 +198,7 @@ bool Empty::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Empty)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
handle_unusual:
@@ -216,27 +226,27 @@ void Empty::SerializeWithCachedSizes(
::google::protobuf::uint8* Empty::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Empty)
// @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Empty)
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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const Empty* source =
::google::protobuf::internal::DynamicCastToGenerated<const Empty>(
&from);
if (source == NULL) {
@@ -250,9 +260,8 @@ void Empty::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
}
void Empty::CopyFrom(const ::google::protobuf::Message& from) {
@@ -270,7 +279,6 @@ void Empty::CopyFrom(const Empty& from) {
}
bool Empty::IsInitialized() const {
-
return true;
}
@@ -279,10 +287,13 @@ void Empty::Swap(Empty* other) {
if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
InternalSwap(other);
} else {
- Empty temp;
- temp.MergeFrom(*this);
- CopyFrom(*other);
- other->CopyFrom(temp);
+ Empty* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
}
}
void Empty::UnsafeArenaSwap(Empty* other) {
@@ -291,16 +302,12 @@ void Empty::UnsafeArenaSwap(Empty* other) {
InternalSwap(other);
}
void Empty::InternalSwap(Empty* other) {
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Empty::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = Empty_descriptor_;
- metadata.reflection = Empty_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fempty_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fempty_2eproto::file_level_metadata[0];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/empty.pb.h b/third_party/protobuf/src/google/protobuf/empty.pb.h
index 8e78733b50..a75d6dd695 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/empty.pb.h
+++ b/third_party/protobuf/src/google/protobuf/empty.pb.h
@@ -8,36 +8,48 @@
#include <google/protobuf/stubs/common.h>
-#if GOOGLE_PROTOBUF_VERSION < 3000000
+#if GOOGLE_PROTOBUF_VERSION < 3002000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
-#if 3000000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
+#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
+#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/metadata.h>
#include <google/protobuf/message.h>
-#include <google/protobuf/repeated_field.h>
-#include <google/protobuf/extension_set.h>
+#include <google/protobuf/repeated_field.h> // IWYU pragma: export
+#include <google/protobuf/extension_set.h> // IWYU pragma: export
#include <google/protobuf/unknown_field_set.h>
// @@protoc_insertion_point(includes)
+namespace google {
+namespace protobuf {
+class Empty;
+class EmptyDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern EmptyDefaultTypeInternal _Empty_default_instance_;
+} // namespace protobuf
+} // namespace google
namespace google {
namespace protobuf {
+namespace protobuf_google_2fprotobuf_2fempty_2eproto {
// Internal implementation detail -- do not call these.
-void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto();
-void protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto();
-void protobuf_ShutdownFile_google_2fprotobuf_2fempty_2eproto();
-
-class Empty;
+struct LIBPROTOBUF_EXPORT TableStruct {
+ static const ::google::protobuf::uint32 offsets[];
+ static void InitDefaultsImpl();
+ static void Shutdown();
+};
+void LIBPROTOBUF_EXPORT AddDescriptors();
+void LIBPROTOBUF_EXPORT InitDefaults();
+} // namespace protobuf_google_2fprotobuf_2fempty_2eproto
// ===================================================================
@@ -53,43 +65,52 @@ class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_
return *this;
}
- inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); }
- inline void* GetMaybeArenaPointer() const {
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
return MaybeArenaPtr();
}
static const ::google::protobuf::Descriptor* descriptor();
static const Empty& default_instance();
+ static inline const Empty* internal_default_instance() {
+ return reinterpret_cast<const Empty*>(
+ &_Empty_default_instance_);
+ }
+
void UnsafeArenaSwap(Empty* other);
void Swap(Empty* other);
// implements Message ----------------------------------------------
- inline Empty* New() const { return New(NULL); }
+ inline Empty* New() const PROTOBUF_FINAL { return New(NULL); }
- Empty* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ Empty* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Empty& from);
void MergeFrom(const Empty& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Empty* other);
protected:
explicit Empty(::google::protobuf::Arena* arena);
@@ -105,7 +126,7 @@ class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -118,14 +139,8 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fempty_2eproto();
-
- void InitAsDefaultInstance();
- static Empty* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fempty_2eproto::TableStruct;
};
// ===================================================================
@@ -139,6 +154,7 @@ class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_
// @@protoc_insertion_point(namespace_scope)
+
} // namespace protobuf
} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/empty.proto b/third_party/protobuf/src/google/protobuf/empty.proto
index 37f4cd10ee..03cacd2330 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/empty.proto
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/src/google/protobuf/extension_set.cc b/third_party/protobuf/src/google/protobuf/extension_set.cc
index 7d20a0f8f8..955c079bdd 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/extension_set.cc
+++ b/third_party/protobuf/src/google/protobuf/extension_set.cc
@@ -76,7 +76,7 @@ inline bool is_packable(WireFormatLite::WireType type) {
}
// Registry stuff.
-typedef hash_map<pair<const MessageLite*, int>,
+typedef hash_map<std::pair<const MessageLite*, int>,
ExtensionInfo> ExtensionRegistry;
ExtensionRegistry* registry_ = NULL;
GOOGLE_PROTOBUF_DECLARE_ONCE(registry_init_);
@@ -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) {
@@ -1371,7 +1371,7 @@ int ExtensionSet::ByteSize() const {
bool ExtensionSet::MaybeNewExtension(int number,
const FieldDescriptor* descriptor,
Extension** result) {
- pair<ExtensionMap::iterator, bool> insert_result =
+ std::pair<ExtensionMap::iterator, bool> insert_result =
extensions_.insert(std::make_pair(number, Extension()));
*result = &insert_result.first->second;
(*result)->descriptor = descriptor;
@@ -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/third_party/protobuf/3.0.0/src/google/protobuf/extension_set.h b/third_party/protobuf/src/google/protobuf/extension_set.h
index 3e1d1ef5eb..f5aa8de959 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/extension_set.h
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/src/google/protobuf/extension_set_heavy.cc b/third_party/protobuf/src/google/protobuf/extension_set_heavy.cc
index b26a246c7d..8f8f180a7e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/extension_set_heavy.cc
+++ b/third_party/protobuf/src/google/protobuf/extension_set_heavy.cc
@@ -35,6 +35,7 @@
// Contains methods defined in extension_set.h which cannot be part of the
// lite library because they use descriptors or reflection.
+#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/extension_set.h>
@@ -413,12 +414,16 @@ uint8* ExtensionSet::SerializeWithCachedSizesToArray(int start_field_number,
int end_field_number,
uint8* target) const {
return InternalSerializeWithCachedSizesToArray(
- start_field_number, end_field_number, false, target);
+ start_field_number, end_field_number,
+ google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(),
+ target);
}
uint8* ExtensionSet::SerializeMessageSetWithCachedSizesToArray(
uint8* target) const {
- return InternalSerializeMessageSetWithCachedSizesToArray(false, target);
+ return InternalSerializeMessageSetWithCachedSizesToArray(
+ google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(),
+ target);
}
uint8* ExtensionSet::InternalSerializeWithCachedSizesToArray(
@@ -587,11 +592,12 @@ ExtensionSet::Extension::InternalSerializeMessageSetItemWithCachedSizesToArray(
WireFormatLite::kMessageSetTypeIdNumber, number, target);
// Write message.
if (is_lazy) {
- target = lazymessage_value->WriteMessageToArray(
- WireFormatLite::kMessageSetMessageNumber, target);
+ target = lazymessage_value->InternalWriteMessageToArray(
+ WireFormatLite::kMessageSetMessageNumber, deterministic, target);
} else {
- target = WireFormatLite::WriteMessageToArray(
- WireFormatLite::kMessageSetMessageNumber, *message_value, target);
+ target = WireFormatLite::InternalWriteMessageToArray(
+ WireFormatLite::kMessageSetMessageNumber, *message_value, deterministic,
+ target);
}
// End group.
target = io::CodedOutputStream::WriteTagToArray(
@@ -656,7 +662,7 @@ bool ExtensionSet::ParseMessageSetItem(io::CodedInputStream* input,
string message_data;
while (true) {
- const uint32 tag = input->ReadTag();
+ const uint32 tag = input->ReadTagNoLastTag();
if (tag == 0) return false;
switch (tag) {
@@ -749,7 +755,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 +764,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 +791,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/third_party/protobuf/3.0.0/src/google/protobuf/extension_set_unittest.cc b/third_party/protobuf/src/google/protobuf/extension_set_unittest.cc
index 688afedbef..d6b823c042 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/extension_set_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/extension_set_unittest.cc
@@ -331,7 +331,7 @@ TEST(ExtensionSetTest, SwapExtension) {
unittest::TestAllExtensions message2;
TestUtil::SetAllExtensions(&message1);
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
// Swap empty fields.
const Reflection* reflection = message1.GetReflection();
@@ -363,7 +363,7 @@ TEST(ExtensionSetTest, SwapExtensionWithEmpty) {
TestUtil::SetAllExtensions(&message3);
const Reflection* reflection = message3.GetReflection();
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
reflection->ListFields(message3, &fields);
reflection->SwapFields(&message1, &message2, fields);
@@ -380,7 +380,7 @@ TEST(ExtensionSetTest, SwapExtensionBothFull) {
TestUtil::SetAllExtensions(&message2);
const Reflection* reflection = message1.GetReflection();
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
reflection->ListFields(message1, &fields);
reflection->SwapFields(&message1, &message2, fields);
@@ -490,7 +490,7 @@ TEST(ExtensionSetTest, SwapFieldsOfExtensionBothFullWithArena) {
TestUtil::SetAllExtensions(message2);
const Reflection* reflection = message1->GetReflection();
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
reflection->ListFields(*message1, &fields);
reflection->SwapFields(message1, message2, fields);
TestUtil::ExpectAllExtensionsSet(*message1);
@@ -504,7 +504,7 @@ TEST(ExtensionSetTest, SwapExtensionWithSelf) {
TestUtil::SetAllExtensions(&message1);
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
const Reflection* reflection = message1.GetReflection();
reflection->ListFields(message1, &fields);
reflection->SwapFields(&message1, &message1, fields);
@@ -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/third_party/protobuf/3.0.0/src/google/protobuf/field_mask.pb.cc b/third_party/protobuf/src/google/protobuf/field_mask.pb.cc
index ed05fe575b..b054dffdd9 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/field_mask.pb.cc
+++ b/third_party/protobuf/src/google/protobuf/field_mask.pb.cc
@@ -19,88 +19,103 @@
namespace google {
namespace protobuf {
+class FieldMaskDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<FieldMask> {
+} _FieldMask_default_instance_;
+
+namespace protobuf_google_2fprotobuf_2ffield_5fmask_2eproto {
+
namespace {
-const ::google::protobuf::Descriptor* FieldMask_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- FieldMask_reflection_ = NULL;
+::google::protobuf::Metadata file_level_metadata[1];
} // namespace
+const ::google::protobuf::uint32 TableStruct::offsets[] = {
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldMask, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldMask, paths_),
+};
-void protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto() GOOGLE_ATTRIBUTE_COLD;
-void protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto();
- const ::google::protobuf::FileDescriptor* file =
- ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
- "google/protobuf/field_mask.proto");
- GOOGLE_CHECK(file != NULL);
- FieldMask_descriptor_ = file->message_type(0);
- static const int FieldMask_offsets_[1] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldMask, paths_),
- };
- FieldMask_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- FieldMask_descriptor_,
- FieldMask::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_));
-}
+static const ::google::protobuf::internal::MigrationSchema schemas[] = {
+ { 0, -1, sizeof(FieldMask)},
+};
+
+static ::google::protobuf::Message const * const file_default_instances[] = {
+ reinterpret_cast<const ::google::protobuf::Message*>(&_FieldMask_default_instance_),
+};
namespace {
-GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
-inline void protobuf_AssignDescriptorsOnce() {
- ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
- &protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto);
+void protobuf_AssignDescriptors() {
+ AddDescriptors();
+ ::google::protobuf::MessageFactory* factory = NULL;
+ AssignDescriptors(
+ "google/protobuf/field_mask.proto", schemas, file_default_instances, TableStruct::offsets, factory,
+ file_level_metadata, NULL, NULL);
+}
+
+void protobuf_AssignDescriptorsOnce() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
}
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());
+ ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
}
} // namespace
-void protobuf_ShutdownFile_google_2fprotobuf_2ffield_5fmask_2eproto() {
- delete FieldMask::default_instance_;
- delete FieldMask_reflection_;
+void TableStruct::Shutdown() {
+ _FieldMask_default_instance_.Shutdown();
+ delete file_level_metadata[0].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 TableStruct::InitDefaultsImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
+ ::google::protobuf::internal::InitProtobufDefaults();
+ _FieldMask_default_instance_.DefaultConstruct();
+}
+
+void InitDefaults() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &TableStruct::InitDefaultsImpl);
+}
+void AddDescriptorsImpl() {
+ InitDefaults();
+ static const char descriptor[] = {
+ "\n google/protobuf/field_mask.proto\022\017goog"
+ "le.protobuf\"\032\n\tFieldMask\022\r\n\005paths\030\001 \003(\tB"
+ "\211\001\n\023com.google.protobufB\016FieldMaskProtoP"
+ "\001Z9google.golang.org/genproto/protobuf/f"
+ "ield_mask;field_mask\242\002\003GPB\252\002\036Google.Prot"
+ "obuf.WellKnownTypesb\006proto3"
+ };
::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);
+ descriptor, 227);
::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::internal::OnShutdown(&TableStruct::Shutdown);
}
+void AddDescriptors() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
+}
// Force AddDescriptors() to be called at static initialization time.
-struct StaticDescriptorInitializer_google_2fprotobuf_2ffield_5fmask_2eproto {
- StaticDescriptorInitializer_google_2fprotobuf_2ffield_5fmask_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto();
+struct StaticDescriptorInitializer {
+ StaticDescriptorInitializer() {
+ AddDescriptors();
}
-} static_descriptor_initializer_google_2fprotobuf_2ffield_5fmask_2eproto_;
+} static_descriptor_initializer;
+
+} // namespace protobuf_google_2fprotobuf_2ffield_5fmask_2eproto
+
// ===================================================================
@@ -110,25 +125,22 @@ const int FieldMask::kPathsFieldNumber;
FieldMask::FieldMask()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::InitDefaults();
+ }
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);
+ _internal_metadata_(NULL),
+ paths_(from.paths_),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.FieldMask)
}
void FieldMask::SharedCtor() {
- _is_default_instance_ = false;
- ::google::protobuf::internal::GetEmptyString();
_cached_size_ = 0;
}
@@ -138,8 +150,6 @@ FieldMask::~FieldMask() {
}
void FieldMask::SharedDtor() {
- if (this != default_instance_) {
- }
}
void FieldMask::SetCachedSize(int size) const {
@@ -148,17 +158,15 @@ void FieldMask::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* FieldMask::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return FieldMask_descriptor_;
+ protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::file_level_metadata[0].descriptor;
}
const FieldMask& FieldMask::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-FieldMask* FieldMask::default_instance_ = NULL;
-
FieldMask* FieldMask::New(::google::protobuf::Arena* arena) const {
FieldMask* n = new FieldMask;
if (arena != NULL) {
@@ -178,14 +186,14 @@ bool FieldMask::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.FieldMask)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// repeated string paths = 1;
case 1: {
- if (tag == 10) {
- parse_paths:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->add_paths()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -196,8 +204,6 @@ bool FieldMask::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(10)) goto parse_paths;
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -226,7 +232,7 @@ void FieldMask::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.FieldMask)
// repeated string paths = 1;
- for (int i = 0; i < this->paths_size(); i++) {
+ for (int i = 0, n = this->paths_size(); i < n; i++) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->paths(i).data(), this->paths(i).length(),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
@@ -240,9 +246,10 @@ void FieldMask::SerializeWithCachedSizes(
::google::protobuf::uint8* FieldMask::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FieldMask)
// repeated string paths = 1;
- for (int i = 0; i < this->paths_size(); i++) {
+ for (int i = 0, n = this->paths_size(); i < n; i++) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->paths(i).data(), this->paths(i).length(),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
@@ -255,29 +262,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();
- for (int i = 0; i < this->paths_size(); i++) {
+ total_size += 1 *
+ ::google::protobuf::internal::FromIntSize(this->paths_size());
+ for (int i = 0, n = this->paths_size(); i < n; 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const FieldMask* source =
::google::protobuf::internal::DynamicCastToGenerated<const FieldMask>(
&from);
if (source == NULL) {
@@ -291,9 +298,8 @@ void FieldMask::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
paths_.MergeFrom(from.paths_);
}
@@ -312,7 +318,6 @@ void FieldMask::CopyFrom(const FieldMask& from) {
}
bool FieldMask::IsInitialized() const {
-
return true;
}
@@ -322,16 +327,12 @@ void FieldMask::Swap(FieldMask* other) {
}
void FieldMask::InternalSwap(FieldMask* other) {
paths_.UnsafeArenaSwap(&other->paths_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata FieldMask::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = FieldMask_descriptor_;
- metadata.reflection = FieldMask_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::file_level_metadata[0];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -344,49 +345,61 @@ 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) {
+#if LANG_CXX11
+void FieldMask::set_paths(int index, ::std::string&& value) {
+ // @@protoc_insertion_point(field_set:google.protobuf.FieldMask.paths)
+ paths_.Mutable(index)->assign(std::move(value));
+}
+#endif
+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<const char*>(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) {
+#if LANG_CXX11
+void FieldMask::add_paths(::std::string&& value) {
+ paths_.Add()->assign(std::move(value));
+ // @@protoc_insertion_point(field_add:google.protobuf.FieldMask.paths)
+}
+#endif
+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<const char*>(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/third_party/protobuf/3.0.0/src/google/protobuf/field_mask.pb.h b/third_party/protobuf/src/google/protobuf/field_mask.pb.h
index 7a19c4aa64..b609f235b4 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/field_mask.pb.h
+++ b/third_party/protobuf/src/google/protobuf/field_mask.pb.h
@@ -8,36 +8,48 @@
#include <google/protobuf/stubs/common.h>
-#if GOOGLE_PROTOBUF_VERSION < 3000000
+#if GOOGLE_PROTOBUF_VERSION < 3002000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
-#if 3000000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
+#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
+#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/metadata.h>
#include <google/protobuf/message.h>
-#include <google/protobuf/repeated_field.h>
-#include <google/protobuf/extension_set.h>
+#include <google/protobuf/repeated_field.h> // IWYU pragma: export
+#include <google/protobuf/extension_set.h> // IWYU pragma: export
#include <google/protobuf/unknown_field_set.h>
// @@protoc_insertion_point(includes)
+namespace google {
+namespace protobuf {
+class FieldMask;
+class FieldMaskDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern FieldMaskDefaultTypeInternal _FieldMask_default_instance_;
+} // namespace protobuf
+} // namespace google
namespace google {
namespace protobuf {
+namespace protobuf_google_2fprotobuf_2ffield_5fmask_2eproto {
// Internal implementation detail -- do not call these.
-void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto();
-void protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto();
-void protobuf_ShutdownFile_google_2fprotobuf_2ffield_5fmask_2eproto();
-
-class FieldMask;
+struct LIBPROTOBUF_EXPORT TableStruct {
+ static const ::google::protobuf::uint32 offsets[];
+ static void InitDefaultsImpl();
+ static void Shutdown();
+};
+void LIBPROTOBUF_EXPORT AddDescriptors();
+void LIBPROTOBUF_EXPORT InitDefaults();
+} // namespace protobuf_google_2fprotobuf_2ffield_5fmask_2eproto
// ===================================================================
@@ -56,46 +68,53 @@ 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 reinterpret_cast<const FieldMask*>(
+ &_FieldMask_default_instance_);
+ }
+
void Swap(FieldMask* other);
// implements Message ----------------------------------------------
- inline FieldMask* New() const { return New(NULL); }
+ inline FieldMask* New() const PROTOBUF_FINAL { return New(NULL); }
- FieldMask* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ FieldMask* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const FieldMask& from);
void MergeFrom(const FieldMask& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(FieldMask* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -108,10 +127,16 @@ class LIBPROTOBUF_EXPORT FieldMask : public ::google::protobuf::Message /* @@pro
const ::std::string& paths(int index) const;
::std::string* mutable_paths(int index);
void set_paths(int index, const ::std::string& value);
+ #if LANG_CXX11
+ void set_paths(int index, ::std::string&& value);
+ #endif
void set_paths(int index, const char* value);
void set_paths(int index, const char* value, size_t size);
::std::string* add_paths();
void add_paths(const ::std::string& value);
+ #if LANG_CXX11
+ void add_paths(::std::string&& value);
+ #endif
void add_paths(const char* value);
void add_paths(const char* value, size_t size);
const ::google::protobuf::RepeatedPtrField< ::std::string>& paths() const;
@@ -121,15 +146,9 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2ffield_5fmask_2eproto();
-
- void InitAsDefaultInstance();
- static FieldMask* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2ffield_5fmask_2eproto::TableStruct;
};
// ===================================================================
@@ -158,6 +177,12 @@ inline void FieldMask::set_paths(int index, const ::std::string& value) {
// @@protoc_insertion_point(field_set:google.protobuf.FieldMask.paths)
paths_.Mutable(index)->assign(value);
}
+#if LANG_CXX11
+inline void FieldMask::set_paths(int index, ::std::string&& value) {
+ // @@protoc_insertion_point(field_set:google.protobuf.FieldMask.paths)
+ paths_.Mutable(index)->assign(std::move(value));
+}
+#endif
inline void FieldMask::set_paths(int index, const char* value) {
paths_.Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set_char:google.protobuf.FieldMask.paths)
@@ -175,6 +200,12 @@ inline void FieldMask::add_paths(const ::std::string& value) {
paths_.Add()->assign(value);
// @@protoc_insertion_point(field_add:google.protobuf.FieldMask.paths)
}
+#if LANG_CXX11
+inline void FieldMask::add_paths(::std::string&& value) {
+ paths_.Add()->assign(std::move(value));
+ // @@protoc_insertion_point(field_add:google.protobuf.FieldMask.paths)
+}
+#endif
inline void FieldMask::add_paths(const char* value) {
paths_.Add()->assign(value);
// @@protoc_insertion_point(field_add_char:google.protobuf.FieldMask.paths)
@@ -198,6 +229,7 @@ FieldMask::mutable_paths() {
// @@protoc_insertion_point(namespace_scope)
+
} // namespace protobuf
} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/field_mask.proto b/third_party/protobuf/src/google/protobuf/field_mask.proto
index c51de09a83..c68d247c8a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/field_mask.proto
+++ b/third_party/protobuf/src/google/protobuf/field_mask.proto
@@ -37,7 +37,7 @@ 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;
+option go_package = "google.golang.org/genproto/protobuf/field_mask;field_mask";
// `FieldMask` represents a set of symbolic field paths, for example:
//
@@ -82,7 +82,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 +109,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/third_party/protobuf/3.0.0/src/google/protobuf/generated_enum_reflection.h b/third_party/protobuf/src/google/protobuf/generated_enum_reflection.h
index fdcdc27790..fdcdc27790 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/generated_enum_reflection.h
+++ b/third_party/protobuf/src/google/protobuf/generated_enum_reflection.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/generated_enum_util.h b/third_party/protobuf/src/google/protobuf/generated_enum_util.h
index e4242055e9..e4242055e9 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/generated_enum_util.h
+++ b/third_party/protobuf/src/google/protobuf/generated_enum_util.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/generated_message_reflection.cc b/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc
index d1f7b5ca32..2f8f8256b7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/generated_message_reflection.cc
+++ b/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc
@@ -44,6 +44,7 @@
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/map_field.h>
#include <google/protobuf/repeated_field.h>
+// #include "google/protobuf/bridge/compatibility_mode_support.h"
#define GOOGLE_PROTOBUF_HAS_ONEOF
@@ -72,18 +73,28 @@ const string& NameOfEnum(const EnumDescriptor* descriptor, int value) {
return (d == NULL ? GetEmptyString() : d->name());
}
-namespace {
-inline bool SupportsArenas(const Descriptor* descriptor) {
- return descriptor->file()->options().cc_enable_arenas();
-}
-} // anonymous namespace
-
// ===================================================================
// Helpers for reporting usage errors (e.g. trying to use GetInt32() on
// a string field).
namespace {
+template <class To>
+To* GetPointerAtOffset(Message* message, uint32 offset) {
+ return reinterpret_cast<To*>(reinterpret_cast<char*>(message) + offset);
+}
+
+template <class To>
+const To* GetConstPointerAtOffset(const Message* message, uint32 offset) {
+ return reinterpret_cast<const To*>(reinterpret_cast<const char*>(message) +
+ offset);
+}
+
+template <class To>
+const To& GetConstRefAtOffset(const Message& message, uint32 offset) {
+ return *GetConstPointerAtOffset<To>(&message, offset);
+}
+
void ReportReflectionUsageError(
const Descriptor* descriptor, const FieldDescriptor* field,
const char* method, const char* description) {
@@ -173,61 +184,13 @@ 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) {
-}
-
-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 ReflectionSchema& schema,
+ const DescriptorPool* pool, MessageFactory* factory)
+ : descriptor_(descriptor),
+ schema_(schema),
+ descriptor_pool_((pool == NULL) ? DescriptorPool::generated_pool()
+ : pool),
+ message_factory_(factory) {
}
GeneratedMessageReflection::~GeneratedMessageReflection() {}
@@ -255,39 +218,33 @@ const UnknownFieldSet& GetEmptyUnknownFieldSet() {
const UnknownFieldSet& GeneratedMessageReflection::GetUnknownFields(
const Message& message) const {
if (descriptor_->file()->syntax() == FileDescriptor::SYNTAX_PROTO3) {
+ // We have to ensure that any mutations made to the return value of
+ // MutableUnknownFields() are not reflected here.
return GetEmptyUnknownFieldSet();
- }
- if (unknown_fields_offset_ == kUnknownFieldSetInMetadata) {
+ } else {
return GetInternalMetadataWithArena(message).unknown_fields();
}
- const void* ptr = reinterpret_cast<const uint8*>(&message) +
- unknown_fields_offset_;
- return *reinterpret_cast<const UnknownFieldSet*>(ptr);
}
UnknownFieldSet* GeneratedMessageReflection::MutableUnknownFields(
Message* message) const {
- if (unknown_fields_offset_ == kUnknownFieldSetInMetadata) {
- return MutableInternalMetadataWithArena(message)->
- mutable_unknown_fields();
- }
- void* ptr = reinterpret_cast<uint8*>(message) + unknown_fields_offset_;
- return reinterpret_cast<UnknownFieldSet*>(ptr);
+ return MutableInternalMetadataWithArena(message)->mutable_unknown_fields();
}
int GeneratedMessageReflection::SpaceUsed(const Message& message) const {
// object_size_ already includes the in-memory representation of each field
// in the message, so we only need to account for additional memory used by
// the fields.
- int total_size = object_size_;
+ int total_size = schema_.GetObjectSize();
total_size += GetUnknownFields(message).SpaceUsedExcludingSelf();
- if (extensions_offset_ != -1) {
+ if (schema_.HasExtensionSet()) {
total_size += GetExtensionSet(message).SpaceUsedExcludingSelf();
}
- for (int i = 0; i < descriptor_->field_count(); i++) {
+ const int field_count = descriptor_->field_count();
+ for (int i = 0; i < field_count; i++) {
const FieldDescriptor* field = descriptor_->field(i);
if (field->is_repeated()) {
@@ -356,9 +313,9 @@ int GeneratedMessageReflection::SpaceUsed(const Message& message) const {
// the prototype. Only count the string if it has been changed
// from the default value.
const string* default_ptr =
- &DefaultRaw<ArenaStringPtr>(field).Get(NULL);
+ &DefaultRaw<ArenaStringPtr>(field).Get();
const string* ptr =
- &GetField<ArenaStringPtr>(message, field).Get(default_ptr);
+ &GetField<ArenaStringPtr>(message, field).Get();
if (ptr != default_ptr) {
// string fields are represented by just a pointer, so also
@@ -372,7 +329,7 @@ int GeneratedMessageReflection::SpaceUsed(const Message& message) const {
}
case FieldDescriptor::CPPTYPE_MESSAGE:
- if (&message == default_instance_) {
+ if (schema_.IsDefaultInstance(message)) {
// For singular fields, the prototype just stores a pointer to the
// external type's prototype, so there is no extra memory usage.
} else {
@@ -494,9 +451,9 @@ void GeneratedMessageReflection::SwapField(
string1->Swap(string2);
} else {
const string* default_ptr =
- &DefaultRaw<ArenaStringPtr>(field).Get(NULL);
- const string temp = string1->Get(default_ptr);
- string1->Set(default_ptr, string2->Get(default_ptr), arena1);
+ &DefaultRaw<ArenaStringPtr>(field).Get();
+ const string temp = string1->Get();
+ string1->Set(default_ptr, string2->Get(), arena1);
string2->Set(default_ptr, temp, arena2);
}
}
@@ -657,37 +614,49 @@ void GeneratedMessageReflection::Swap(
// Slow copy path.
// Use our arena as temp space, if available.
Message* temp = message1->New(GetArena(message1));
- temp->MergeFrom(*message1);
- message1->CopyFrom(*message2);
- message2->CopyFrom(*temp);
+ temp->MergeFrom(*message2);
+ message2->CopyFrom(*message1);
+ Swap(message1, temp);
if (GetArena(message1) == NULL) {
delete temp;
}
return;
}
- if (has_bits_offset_ != -1) {
+ if (schema_.HasHasbits()) {
uint32* has_bits1 = MutableHasBits(message1);
uint32* has_bits2 = MutableHasBits(message2);
- int has_bits_size = (descriptor_->field_count() + 31) / 32;
+
+ int fields_with_has_bits = 0;
+ for (int i = 0; i < descriptor_->field_count(); i++) {
+ const FieldDescriptor* field = descriptor_->field(i);
+ if (field->is_repeated() || field->containing_oneof()) {
+ continue;
+ }
+ fields_with_has_bits++;
+ }
+
+ int has_bits_size = (fields_with_has_bits + 31) / 32;
for (int i = 0; i < has_bits_size; i++) {
std::swap(has_bits1[i], has_bits2[i]);
}
}
- for (int i = 0; i < descriptor_->field_count(); i++) {
+ const int field_count = descriptor_->field_count();
+ for (int i = 0; i < field_count; i++) {
const FieldDescriptor* field = descriptor_->field(i);
if (!field->containing_oneof()) {
SwapField(message1, message2, field);
}
}
- for (int i = 0; i < descriptor_->oneof_decl_count(); i++) {
+ const int oneof_decl_count = descriptor_->oneof_decl_count();
+ for (int i = 0; i < oneof_decl_count; i++) {
SwapOneofField(message1, message2, descriptor_->oneof_decl(i));
}
- if (extensions_offset_ != -1) {
+ if (schema_.HasExtensionSet()) {
MutableExtensionSet(message1)->Swap(MutableExtensionSet(message2));
}
@@ -697,7 +666,7 @@ void GeneratedMessageReflection::Swap(
void GeneratedMessageReflection::SwapFields(
Message* message1,
Message* message2,
- const vector<const FieldDescriptor*>& fields) const {
+ const std::vector<const FieldDescriptor*>& fields) const {
if (message1 == message2) return;
// TODO(kenton): Other Reflection methods should probably check this too.
@@ -718,7 +687,8 @@ void GeneratedMessageReflection::SwapFields(
std::set<int> swapped_oneof;
- for (int i = 0; i < fields.size(); i++) {
+ const int fields_size = static_cast<int>(fields.size());
+ for (int i = 0; i < fields_size; i++) {
const FieldDescriptor* field = fields[i];
if (field->is_extension()) {
MutableExtensionSet(message1)->SwapExtension(
@@ -734,8 +704,11 @@ void GeneratedMessageReflection::SwapFields(
swapped_oneof.insert(oneof_index);
SwapOneofField(message1, message2, field->containing_oneof());
} else {
- // Swap has bit.
- SwapBit(message1, message2, field);
+ // Swap has bit for non-repeated fields. We have already checked for
+ // oneof already.
+ if (!field->is_repeated()) {
+ SwapBit(message1, message2, field);
+ }
// Swap field.
SwapField(message1, message2, field);
}
@@ -840,9 +813,9 @@ void GeneratedMessageReflection::ClearField(
default: // TODO(kenton): Support other string reps.
case FieldOptions::STRING: {
const string* default_ptr =
- &DefaultRaw<ArenaStringPtr>(field).Get(NULL);
- MutableRaw<ArenaStringPtr>(message, field)->Destroy(default_ptr,
- GetArena(message));
+ &DefaultRaw<ArenaStringPtr>(field).Get();
+ MutableRaw<ArenaStringPtr>(message, field)->SetAllocated(
+ default_ptr, NULL, GetArena(message));
break;
}
}
@@ -850,7 +823,7 @@ void GeneratedMessageReflection::ClearField(
}
case FieldDescriptor::CPPTYPE_MESSAGE:
- if (has_bits_offset_ == -1) {
+ if (!schema_.HasHasbits()) {
// Proto3 does not have has-bits and we need to set a message field
// to NULL in order to indicate its un-presence.
if (GetArena(message) == NULL) {
@@ -1026,35 +999,61 @@ struct FieldNumberSorter {
return left->number() < right->number();
}
};
+
+inline bool IsIndexInHasBitSet(
+ const uint32* has_bit_set, uint32 has_bit_index) {
+ GOOGLE_DCHECK_NE(has_bit_index, ~0u);
+ return ((has_bit_set[has_bit_index / 32] >> (has_bit_index % 32)) &
+ static_cast<uint32>(1)) != 0;
+}
} // namespace
void GeneratedMessageReflection::ListFields(
const Message& message,
- vector<const FieldDescriptor*>* output) const {
+ std::vector<const FieldDescriptor*>* output) const {
output->clear();
// Optimization: The default instance never has any fields set.
- if (&message == default_instance_) return;
-
- output->reserve(descriptor_->field_count());
- for (int i = 0; i < descriptor_->field_count(); i++) {
+ if (schema_.IsDefaultInstance(message)) return;
+
+ // Optimization: Avoid calling GetHasBits() and HasOneofField() many times
+ // within the field loop. We allow this violation of ReflectionSchema
+ // encapsulation because this function takes a noticable about of CPU
+ // fleetwide and properly allowing this optimization through public interfaces
+ // seems more trouble than it is worth.
+ const uint32* const has_bits =
+ schema_.HasHasbits() ? GetHasBits(message) : NULL;
+ const uint32* const has_bits_indices = schema_.has_bit_indices_;
+ const uint32* const oneof_case_array =
+ &GetConstRefAtOffset<uint32>(message, schema_.oneof_case_offset_);
+
+ const int field_count = descriptor_->field_count();
+ output->reserve(field_count);
+ for (int i = 0; i < field_count; i++) {
const FieldDescriptor* field = descriptor_->field(i);
if (field->is_repeated()) {
if (FieldSize(message, field) > 0) {
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 (has_bits) {
+ // Equivalent to: HasBit(message, field)
+ if (IsIndexInHasBitSet(has_bits, has_bits_indices[i])) {
output->push_back(field);
}
- } else if (HasBit(message, field)) {
+ } else if (HasBit(message, field)) { // Fall back on proto3-style HasBit.
output->push_back(field);
}
}
}
- if (extensions_offset_ != -1) {
+ if (schema_.HasExtensionSet()) {
GetExtensionSet(message).AppendToList(descriptor_, descriptor_pool_,
output);
}
@@ -1148,9 +1147,7 @@ string GeneratedMessageReflection::GetString(
switch (field->options().ctype()) {
default: // TODO(kenton): Support other string reps.
case FieldOptions::STRING: {
- const string* default_ptr =
- &DefaultRaw<ArenaStringPtr>(field).Get(NULL);
- return GetField<ArenaStringPtr>(message, field).Get(default_ptr);
+ return GetField<ArenaStringPtr>(message, field).Get();
}
}
@@ -1170,9 +1167,7 @@ const string& GeneratedMessageReflection::GetStringReference(
switch (field->options().ctype()) {
default: // TODO(kenton): Support other string reps.
case FieldOptions::STRING: {
- const string* default_ptr =
- &DefaultRaw<ArenaStringPtr>(field).Get(NULL);
- return GetField<ArenaStringPtr>(message, field).Get(default_ptr);
+ return GetField<ArenaStringPtr>(message, field).Get();
}
}
@@ -1193,8 +1188,7 @@ void GeneratedMessageReflection::SetString(
switch (field->options().ctype()) {
default: // TODO(kenton): Support other string reps.
case FieldOptions::STRING: {
- const string* default_ptr =
- &DefaultRaw<ArenaStringPtr>(field).Get(NULL);
+ const string* default_ptr = &DefaultRaw<ArenaStringPtr>(field).Get();
if (field->containing_oneof() && !HasOneofField(*message, field)) {
ClearOneof(message, field->containing_oneof());
MutableField<ArenaStringPtr>(message, field)->UnsafeSetDefault(
@@ -1514,7 +1508,7 @@ void GeneratedMessageReflection::UnsafeArenaSetAllocatedMessage(
USAGE_CHECK_ALL(SetAllocatedMessage, SINGULAR, MESSAGE);
if (field->is_extension()) {
- MutableExtensionSet(message)->SetAllocatedMessage(
+ MutableExtensionSet(message)->UnsafeArenaSetAllocatedMessage(
field->number(), field->type(), field, sub_message);
} else {
if (field->containing_oneof()) {
@@ -1582,7 +1576,9 @@ Message* GeneratedMessageReflection::UnsafeArenaReleaseMessage(
MutableExtensionSet(message)->UnsafeArenaReleaseMessage(field,
factory));
} else {
- ClearBit(message, field);
+ if (!(field->is_repeated() || field->containing_oneof())) {
+ ClearBit(message, field);
+ }
if (field->containing_oneof()) {
if (HasOneofField(*message, field)) {
*MutableOneofCase(message, field->containing_oneof()) = 0;
@@ -1728,11 +1724,10 @@ void* GeneratedMessageReflection::MutableRawRepeatedField(
} else {
// Trigger transform for MapField
if (IsMapFieldInApi(field)) {
- return reinterpret_cast<MapFieldBase*>(reinterpret_cast<uint8*>(message) +
- offsets_[field->index()])
+ return MutableRawNonOneof<MapFieldBase>(message, field)
->MutableRepeatedField();
}
- return reinterpret_cast<uint8*>(message) + offsets_[field->index()];
+ return MutableRawNonOneof<void>(message, field);
}
}
@@ -1759,11 +1754,9 @@ const void* GeneratedMessageReflection::GetRawRepeatedField(
} else {
// Trigger transform for MapField
if (IsMapFieldInApi(field)) {
- return &(reinterpret_cast<const MapFieldBase*>(
- reinterpret_cast<const uint8*>(&message) +
- offsets_[field->index()])->GetRepeatedField());
+ return &(GetRawNonOneof<MapFieldBase>(message, field).GetRepeatedField());
}
- return reinterpret_cast<const uint8*>(&message) + offsets_[field->index()];
+ return &GetRawNonOneof<char>(message, field);
}
}
@@ -1845,7 +1838,7 @@ int GeneratedMessageReflection::MapSize(
const FieldDescriptor* GeneratedMessageReflection::FindKnownExtensionByName(
const string& name) const {
- if (extensions_offset_ == -1) return NULL;
+ if (!schema_.HasExtensionSet()) return NULL;
const FieldDescriptor* result = descriptor_pool_->FindExtensionByName(name);
if (result != NULL && result->containing_type() == descriptor_) {
@@ -1857,7 +1850,8 @@ const FieldDescriptor* GeneratedMessageReflection::FindKnownExtensionByName(
const Descriptor* type = descriptor_pool_->FindMessageTypeByName(name);
if (type != NULL) {
// Look for a matching extension in the foreign type's scope.
- for (int i = 0; i < type->extension_count(); i++) {
+ const int type_extension_count = type->extension_count();
+ for (int i = 0; i < type_extension_count; i++) {
const FieldDescriptor* extension = type->extension(i);
if (extension->containing_type() == descriptor_ &&
extension->type() == FieldDescriptor::TYPE_MESSAGE &&
@@ -1875,7 +1869,7 @@ const FieldDescriptor* GeneratedMessageReflection::FindKnownExtensionByName(
const FieldDescriptor* GeneratedMessageReflection::FindKnownExtensionByNumber(
int number) const {
- if (extensions_offset_ == -1) return NULL;
+ if (!schema_.HasExtensionSet()) return NULL;
return descriptor_pool_->FindExtensionByNumber(descriptor_, number);
}
@@ -1888,204 +1882,176 @@ bool GeneratedMessageReflection::SupportsUnknownEnumValues() const {
// These simple template accessors obtain pointers (or references) to
// the given field.
+
+template <class Type>
+const Type& GeneratedMessageReflection::GetRawNonOneof(
+ const Message& message, const FieldDescriptor* field) const {
+ return GetConstRefAtOffset<Type>(message,
+ schema_.GetFieldOffsetNonOneof(field));
+}
+
+template <class Type>
+Type* GeneratedMessageReflection::MutableRawNonOneof(
+ Message* message, const FieldDescriptor* field) const {
+ return GetPointerAtOffset<Type>(message,
+ schema_.GetFieldOffsetNonOneof(field));
+}
+
template <typename Type>
-inline const Type& GeneratedMessageReflection::GetRaw(
+const Type& GeneratedMessageReflection::GetRaw(
const Message& message, const FieldDescriptor* field) const {
if (field->containing_oneof() && !HasOneofField(message, field)) {
return DefaultRaw<Type>(field);
}
- int index = field->containing_oneof() ?
- descriptor_->field_count() + field->containing_oneof()->index() :
- field->index();
- const void* ptr = reinterpret_cast<const uint8*>(&message) +
- offsets_[index];
- return *reinterpret_cast<const Type*>(ptr);
+ return GetConstRefAtOffset<Type>(message, schema_.GetFieldOffset(field));
}
template <typename Type>
-inline Type* GeneratedMessageReflection::MutableRaw(
- Message* message, const FieldDescriptor* field) const {
- int index = field->containing_oneof() ?
- descriptor_->field_count() + field->containing_oneof()->index() :
- field->index();
- void* ptr = reinterpret_cast<uint8*>(message) + offsets_[index];
- return reinterpret_cast<Type*>(ptr);
+Type* GeneratedMessageReflection::MutableRaw(Message* message,
+ const FieldDescriptor* field) const {
+ return GetPointerAtOffset<Type>(message, schema_.GetFieldOffset(field));
}
-template <typename Type>
-inline const Type& GeneratedMessageReflection::DefaultRaw(
- const FieldDescriptor* field) const {
- const void* ptr = field->containing_oneof() ?
- reinterpret_cast<const uint8*>(default_oneof_instance_) +
- offsets_[field->index()] :
- reinterpret_cast<const uint8*>(default_instance_) +
- offsets_[field->index()];
- return *reinterpret_cast<const Type*>(ptr);
-}
inline const uint32* GeneratedMessageReflection::GetHasBits(
const Message& message) const {
- if (has_bits_offset_ == -1) { // proto3 with no has-bits.
- return NULL;
- }
- const void* ptr = reinterpret_cast<const uint8*>(&message) + has_bits_offset_;
- return reinterpret_cast<const uint32*>(ptr);
+ GOOGLE_DCHECK(schema_.HasHasbits());
+ return &GetConstRefAtOffset<uint32>(message, schema_.HasBitsOffset());
}
+
inline uint32* GeneratedMessageReflection::MutableHasBits(
Message* message) const {
- if (has_bits_offset_ == -1) {
- return NULL;
- }
- void* ptr = reinterpret_cast<uint8*>(message) + has_bits_offset_;
- return reinterpret_cast<uint32*>(ptr);
+ GOOGLE_DCHECK(schema_.HasHasbits());
+ return GetPointerAtOffset<uint32>(message, schema_.HasBitsOffset());
}
inline uint32 GeneratedMessageReflection::GetOneofCase(
- const Message& message,
- const OneofDescriptor* oneof_descriptor) const {
- const void* ptr = reinterpret_cast<const uint8*>(&message)
- + oneof_case_offset_;
- return reinterpret_cast<const uint32*>(ptr)[oneof_descriptor->index()];
+ const Message& message, const OneofDescriptor* oneof_descriptor) const {
+ return GetConstRefAtOffset<uint32>(
+ message, schema_.GetOneofCaseOffset(oneof_descriptor));
}
inline uint32* GeneratedMessageReflection::MutableOneofCase(
- Message* message,
- const OneofDescriptor* oneof_descriptor) const {
- void* ptr = reinterpret_cast<uint8*>(message) + oneof_case_offset_;
- return &(reinterpret_cast<uint32*>(ptr)[oneof_descriptor->index()]);
+ Message* message, const OneofDescriptor* oneof_descriptor) const {
+ return GetPointerAtOffset<uint32>(
+ message, schema_.GetOneofCaseOffset(oneof_descriptor));
}
inline const ExtensionSet& GeneratedMessageReflection::GetExtensionSet(
const Message& message) const {
- GOOGLE_DCHECK_NE(extensions_offset_, -1);
- const void* ptr = reinterpret_cast<const uint8*>(&message) +
- extensions_offset_;
- return *reinterpret_cast<const ExtensionSet*>(ptr);
+ return GetConstRefAtOffset<ExtensionSet>(message,
+ schema_.GetExtensionSetOffset());
}
+
inline ExtensionSet* GeneratedMessageReflection::MutableExtensionSet(
Message* message) const {
- GOOGLE_DCHECK_NE(extensions_offset_, -1);
- void* ptr = reinterpret_cast<uint8*>(message) + extensions_offset_;
- return reinterpret_cast<ExtensionSet*>(ptr);
+ return GetPointerAtOffset<ExtensionSet>(message,
+ schema_.GetExtensionSetOffset());
}
inline Arena* GeneratedMessageReflection::GetArena(Message* message) const {
- if (arena_offset_ == kNoArenaPointer) {
- return NULL;
- }
-
- if (unknown_fields_offset_ == kUnknownFieldSetInMetadata) {
- // zero-overhead arena pointer overloading UnknownFields
- return GetInternalMetadataWithArena(*message).arena();
- }
-
- // Baseline case: message class has a dedicated arena pointer.
- void* ptr = reinterpret_cast<uint8*>(message) + arena_offset_;
- return *reinterpret_cast<Arena**>(ptr);
+ return GetInternalMetadataWithArena(*message).arena();
}
inline const InternalMetadataWithArena&
GeneratedMessageReflection::GetInternalMetadataWithArena(
const Message& message) const {
- const void* ptr = reinterpret_cast<const uint8*>(&message) + arena_offset_;
- return *reinterpret_cast<const InternalMetadataWithArena*>(ptr);
+ return GetConstRefAtOffset<InternalMetadataWithArena>(
+ message, schema_.GetMetadataOffset());
}
inline InternalMetadataWithArena*
GeneratedMessageReflection::MutableInternalMetadataWithArena(
Message* message) const {
- void* ptr = reinterpret_cast<uint8*>(message) + arena_offset_;
- return reinterpret_cast<InternalMetadataWithArena*>(ptr);
+ return GetPointerAtOffset<InternalMetadataWithArena>(
+ message, schema_.GetMetadataOffset());
}
-inline bool
-GeneratedMessageReflection::GetIsDefaultInstance(
- const Message& message) const {
- if (is_default_instance_offset_ == kHasNoDefaultInstanceField) {
- return false;
- }
- const void* ptr = reinterpret_cast<const uint8*>(&message) +
- is_default_instance_offset_;
- return *reinterpret_cast<const bool*>(ptr);
+template <typename Type>
+inline const Type& GeneratedMessageReflection::DefaultRaw(
+ const FieldDescriptor* field) const {
+ return *reinterpret_cast<const Type*>(schema_.GetFieldDefault(field));
}
// Simple accessors for manipulating has_bits_.
inline bool GeneratedMessageReflection::HasBit(
const Message& message, const FieldDescriptor* field) const {
- if (has_bits_offset_ == -1) {
- // proto3: no has-bits. All fields present except messages, which are
- // present only if their message-field pointer is non-NULL.
- if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
- return !GetIsDefaultInstance(message) &&
- GetRaw<const Message*>(message, field) != NULL;
- } else {
- // Non-message field (and non-oneof, since that was handled in HasField()
- // before calling us), and singular (again, checked in HasField). So, this
- // field must be a scalar.
-
- // Scalar primitive (numeric or string/bytes) fields are present if
- // their value is non-zero (numeric) or non-empty (string/bytes). N.B.:
- // we must use this definition here, rather than the "scalar fields
- // always present" in the proto3 docs, because MergeFrom() semantics
- // require presence as "present on wire", and reflection-based merge
- // (which uses HasField()) needs to be consistent with this.
- switch (field->cpp_type()) {
- case FieldDescriptor::CPPTYPE_STRING:
- switch (field->options().ctype()) {
- default: {
- const string* default_ptr =
- &DefaultRaw<ArenaStringPtr>(field).Get(NULL);
- return GetField<ArenaStringPtr>(message, field).Get(
- default_ptr).size() > 0;
- }
+ if (schema_.HasHasbits()) {
+ return IsIndexInHasBitSet(GetHasBits(message), schema_.HasBitIndex(field));
+ }
+
+ // proto3: no has-bits. All fields present except messages, which are
+ // present only if their message-field pointer is non-NULL.
+ if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
+ return !schema_.IsDefaultInstance(message) &&
+ GetRaw<const Message*>(message, field) != NULL;
+ } else {
+ // Non-message field (and non-oneof, since that was handled in HasField()
+ // before calling us), and singular (again, checked in HasField). So, this
+ // field must be a scalar.
+
+ // Scalar primitive (numeric or string/bytes) fields are present if
+ // their value is non-zero (numeric) or non-empty (string/bytes). N.B.:
+ // we must use this definition here, rather than the "scalar fields
+ // always present" in the proto3 docs, because MergeFrom() semantics
+ // require presence as "present on wire", and reflection-based merge
+ // (which uses HasField()) needs to be consistent with this.
+ switch (field->cpp_type()) {
+ case FieldDescriptor::CPPTYPE_STRING:
+ switch (field->options().ctype()) {
+ default: {
+ return GetField<ArenaStringPtr>(message, field).Get().size() > 0;
}
- return false;
- case FieldDescriptor::CPPTYPE_BOOL:
- return GetRaw<bool>(message, field) != false;
- case FieldDescriptor::CPPTYPE_INT32:
- return GetRaw<int32>(message, field) != 0;
- case FieldDescriptor::CPPTYPE_INT64:
- return GetRaw<int64>(message, field) != 0;
- case FieldDescriptor::CPPTYPE_UINT32:
- return GetRaw<uint32>(message, field) != 0;
- case FieldDescriptor::CPPTYPE_UINT64:
- return GetRaw<uint64>(message, field) != 0;
- case FieldDescriptor::CPPTYPE_FLOAT:
- return GetRaw<float>(message, field) != 0.0;
- case FieldDescriptor::CPPTYPE_DOUBLE:
- return GetRaw<double>(message, field) != 0.0;
- case FieldDescriptor::CPPTYPE_ENUM:
- return GetRaw<int>(message, field) != 0;
- case FieldDescriptor::CPPTYPE_MESSAGE:
- // handled above; avoid warning
- GOOGLE_LOG(FATAL) << "Reached impossible case in HasBit().";
- break;
- }
+ }
+ return false;
+ case FieldDescriptor::CPPTYPE_BOOL:
+ return GetRaw<bool>(message, field) != false;
+ case FieldDescriptor::CPPTYPE_INT32:
+ return GetRaw<int32>(message, field) != 0;
+ case FieldDescriptor::CPPTYPE_INT64:
+ return GetRaw<int64>(message, field) != 0;
+ case FieldDescriptor::CPPTYPE_UINT32:
+ return GetRaw<uint32>(message, field) != 0;
+ case FieldDescriptor::CPPTYPE_UINT64:
+ return GetRaw<uint64>(message, field) != 0;
+ case FieldDescriptor::CPPTYPE_FLOAT:
+ return GetRaw<float>(message, field) != 0.0;
+ case FieldDescriptor::CPPTYPE_DOUBLE:
+ return GetRaw<double>(message, field) != 0.0;
+ case FieldDescriptor::CPPTYPE_ENUM:
+ return GetRaw<int>(message, field) != 0;
+ case FieldDescriptor::CPPTYPE_MESSAGE:
+ // handled above; avoid warning
+ break;
}
+ GOOGLE_LOG(FATAL) << "Reached impossible case in HasBit().";
+ return false;
}
- return GetHasBits(message)[field->index() / 32] &
- (1 << (field->index() % 32));
}
inline void GeneratedMessageReflection::SetBit(
Message* message, const FieldDescriptor* field) const {
- if (has_bits_offset_ == -1) {
+ if (!schema_.HasHasbits()) {
return;
}
- MutableHasBits(message)[field->index() / 32] |= (1 << (field->index() % 32));
+ const uint32 index = schema_.HasBitIndex(field);
+ MutableHasBits(message)[index / 32] |=
+ (static_cast<uint32>(1) << (index % 32));
}
inline void GeneratedMessageReflection::ClearBit(
Message* message, const FieldDescriptor* field) const {
- if (has_bits_offset_ == -1) {
+ if (!schema_.HasHasbits()) {
return;
}
- MutableHasBits(message)[field->index() / 32] &= ~(1 << (field->index() % 32));
+ const uint32 index = schema_.HasBitIndex(field);
+ MutableHasBits(message)[index / 32] &=
+ ~(static_cast<uint32>(1) << (index % 32));
}
inline void GeneratedMessageReflection::SwapBit(
Message* message1, Message* message2, const FieldDescriptor* field) const {
- if (has_bits_offset_ == -1) {
+ if (!schema_.HasHasbits()) {
return;
}
bool temp_has_bit = HasBit(*message1, field);
@@ -2138,7 +2104,7 @@ inline void GeneratedMessageReflection::ClearOneof(
default: // TODO(kenton): Support other string reps.
case FieldOptions::STRING: {
const string* default_ptr =
- &DefaultRaw<ArenaStringPtr>(field).Get(NULL);
+ &DefaultRaw<ArenaStringPtr>(field).Get();
MutableField<ArenaStringPtr>(message, field)->
Destroy(default_ptr, GetArena(message));
break;
@@ -2250,7 +2216,7 @@ void* GeneratedMessageReflection::RepeatedFieldData(
return MutableExtensionSet(message)->MutableRawRepeatedField(
field->number(), field->type(), field->is_packed(), field);
} else {
- return reinterpret_cast<uint8*>(message) + offsets_[field->index()];
+ return MutableRawNonOneof<char>(message, field);
}
}
@@ -2262,56 +2228,128 @@ MapFieldBase* GeneratedMessageReflection::MapData(
return MutableRaw<MapFieldBase>(message, field);
}
-GeneratedMessageReflection*
-GeneratedMessageReflection::NewGeneratedMessageReflection(
- 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,
- 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);
-}
-
-GeneratedMessageReflection*
-GeneratedMessageReflection::NewGeneratedMessageReflection(
- const Descriptor* descriptor,
- const Message* default_instance,
- const int offsets[],
- int has_bits_offset,
- int unknown_fields_offset,
- int extensions_offset,
- 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);
+namespace {
+
+// Helper function to transform migration schema into reflection schema.
+ReflectionSchema MigrationToReflectionSchema(
+ const Message* const* default_instance, const uint32* offsets,
+ MigrationSchema migration_schema) {
+ ReflectionSchema result;
+ result.default_instance_ = *default_instance;
+ // First 5 offsets are offsets to the special fields. The following offsets
+ // are the proto fields.
+ result.offsets_ = offsets + migration_schema.offsets_index + 4;
+ result.has_bit_indices_ = offsets + migration_schema.has_bit_indices_index;
+ result.has_bits_offset_ = offsets[migration_schema.offsets_index + 0];
+ result.metadata_offset_ = offsets[migration_schema.offsets_index + 1];
+ result.extensions_offset_ = offsets[migration_schema.offsets_index + 2];
+ result.oneof_case_offset_ = offsets[migration_schema.offsets_index + 3];
+ result.object_size_ = migration_schema.object_size;
+ result.weak_field_map_offset_ = 0;
+ return result;
+}
+
+template<typename Schema>
+class AssignDescriptorsHelper {
+ public:
+ AssignDescriptorsHelper(MessageFactory* factory,
+ Metadata* file_level_metadata,
+ const EnumDescriptor** file_level_enum_descriptors,
+ const Schema* schemas,
+ const Message* const* default_instance_data,
+ const uint32* offsets)
+ : factory_(factory),
+ file_level_metadata_(file_level_metadata),
+ file_level_enum_descriptors_(file_level_enum_descriptors),
+ schemas_(schemas),
+ default_instance_data_(default_instance_data),
+ offsets_(offsets) {}
+
+ void AssignMessageDescriptor(const Descriptor* descriptor) {
+ for (int i = 0; i < descriptor->nested_type_count(); i++) {
+ AssignMessageDescriptor(descriptor->nested_type(i));
+ }
+
+ file_level_metadata_->descriptor = descriptor;
+
+ if (!descriptor->options().map_entry()) {
+ // Only set reflection for non map types.
+ file_level_metadata_->reflection = new GeneratedMessageReflection(
+ descriptor, MigrationToReflectionSchema(default_instance_data_++,
+ offsets_, *schemas_),
+ ::google::protobuf::DescriptorPool::generated_pool(), factory_);
+ for (int i = 0; i < descriptor->enum_type_count(); i++) {
+ AssignEnumDescriptor(descriptor->enum_type(i));
+ }
+ schemas_++;
+ }
+ file_level_metadata_++;
+ }
+
+ void AssignEnumDescriptor(const EnumDescriptor* descriptor) {
+ *file_level_enum_descriptors_ = descriptor;
+ file_level_enum_descriptors_++;
+ }
+
+ private:
+ MessageFactory* factory_;
+ Metadata* file_level_metadata_;
+ const EnumDescriptor** file_level_enum_descriptors_;
+ const Schema* schemas_;
+ const Message* const * default_instance_data_;
+ const uint32* offsets_;
+};
+
+} // namespace
+
+void AssignDescriptors(
+ const string& filename, const MigrationSchema* schemas,
+ const Message* const* default_instances_, const uint32* offsets,
+ MessageFactory* factory,
+ // update the following descriptor arrays.
+ Metadata* file_level_metadata,
+ const EnumDescriptor** file_level_enum_descriptors,
+ const ServiceDescriptor** file_level_service_descriptors) {
+ const ::google::protobuf::FileDescriptor* file =
+ ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(filename);
+ GOOGLE_CHECK(file != NULL);
+
+ if (!factory) factory = MessageFactory::generated_factory();
+
+ AssignDescriptorsHelper<MigrationSchema> helper(factory, file_level_metadata,
+ file_level_enum_descriptors, schemas,
+ default_instances_, offsets);
+
+ for (int i = 0; i < file->message_type_count(); i++) {
+ helper.AssignMessageDescriptor(file->message_type(i));
+ }
+
+ for (int i = 0; i < file->enum_type_count(); i++) {
+ helper.AssignEnumDescriptor(file->enum_type(i));
+ }
+ if (file->options().cc_generic_services()) {
+ for (int i = 0; i < file->service_count(); i++) {
+ file_level_service_descriptors[i] = file->service(i);
+ }
+ }
+}
+
+void RegisterAllTypesInternal(const Metadata* file_level_metadata, int size) {
+ for (int i = 0; i < size; i++) {
+ const GeneratedMessageReflection* reflection =
+ static_cast<const GeneratedMessageReflection*>(
+ file_level_metadata[i].reflection);
+ if (reflection) {
+ // It's not a map type
+ ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
+ file_level_metadata[i].descriptor,
+ reflection->schema_.default_instance_);
+ }
+ }
+}
+
+void RegisterAllTypes(const Metadata* file_level_metadata, int size) {
+ RegisterAllTypesInternal(file_level_metadata, size);
}
} // namespace internal
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/generated_message_reflection.h b/third_party/protobuf/src/google/protobuf/generated_message_reflection.h
index 15fc802ce1..8b1362a2a7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/generated_message_reflection.h
+++ b/third_party/protobuf/src/google/protobuf/generated_message_reflection.h
@@ -45,6 +45,7 @@
// TODO(jasonh): Remove this once the compiler change to directly include this
// is released to components.
#include <google/protobuf/generated_enum_reflection.h>
+#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/message.h>
#include <google/protobuf/metadata.h>
#include <google/protobuf/unknown_field_set.h>
@@ -73,6 +74,148 @@ class GeneratedMessageReflection;
// Defined in other files.
class ExtensionSet; // extension_set.h
+// This struct describes the internal layout of the message, hence this is
+// used to act on the message reflectively.
+// default_instance: The default instance of the message. This is only
+// used to obtain pointers to default instances of embedded
+// messages, which GetMessage() will return if the particular
+// sub-message has not been initialized yet. (Thus, all
+// embedded message fields *must* have non-NULL pointers
+// in the default instance.)
+// offsets: An array of ints giving the byte offsets.
+// For each oneof field, the offset is relative to the
+// default_oneof_instance. These can be computed at compile
+// time using the
+// PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET() macro.
+// For each none oneof field, the offset is related to
+// the start of the message object. These can be computed
+// at compile time using the
+// GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET() macro.
+// Besides offsets for all fields, this array also contains
+// offsets for oneof unions. The offset of the i-th oneof
+// union is offsets[descriptor->field_count() + i].
+// has_bit_indices: Mapping from field indexes to their index in the has
+// bit array.
+// has_bits_offset: Offset in the message of an array of uint32s of size
+// descriptor->field_count()/32, rounded up. This is a
+// bitfield where each bit indicates whether or not the
+// corresponding field of the message has been initialized.
+// The bit for field index i is obtained by the expression:
+// has_bits[i / 32] & (1 << (i % 32))
+// unknown_fields_offset: Offset in the message of the UnknownFieldSet for
+// the message.
+// extensions_offset: Offset in the message of the ExtensionSet for the
+// message, or -1 if the message type has no extension
+// ranges.
+// oneof_case_offset: Offset in the message of an array of uint32s of
+// size descriptor->oneof_decl_count(). Each uint32
+// indicates what field is set for each oneof.
+// object_size: The size of a message object of this type, as measured
+// by sizeof().
+// arena_offset: If a message doesn't have a unknown_field_set that stores
+// the arena, it must have a direct pointer to the arena.
+struct ReflectionSchema {
+ public:
+ // Size of a google::protobuf::Message object of this type.
+ uint32 GetObjectSize() const { return object_size_; }
+
+ // Offset of a non-oneof field. Getting a field offset is slightly more
+ // efficient when we know statically that it is not a oneof field.
+ uint32 GetFieldOffsetNonOneof(const FieldDescriptor* field) const {
+ GOOGLE_DCHECK(!field->containing_oneof());
+ return offsets_[field->index()];
+ }
+
+ // Offset of any field.
+ uint32 GetFieldOffset(const FieldDescriptor* field) const {
+ if (field->containing_oneof()) {
+ size_t offset = field->containing_type()->field_count() +
+ field->containing_oneof()->index();
+ return offsets_[offset];
+ } else {
+ return GetFieldOffsetNonOneof(field);
+ }
+ }
+
+ uint32 GetOneofCaseOffset(const OneofDescriptor* oneof_descriptor) const {
+ return oneof_case_offset_ + (oneof_descriptor->index() * sizeof(uint32));
+ }
+
+ bool HasHasbits() const { return has_bits_offset_ != -1; }
+
+ // Bit index within the bit array of hasbits. Bit order is low-to-high.
+ uint32 HasBitIndex(const FieldDescriptor* field) const {
+ GOOGLE_DCHECK(HasHasbits());
+ return has_bit_indices_[field->index()];
+ }
+
+ // Byte offset of the hasbits array.
+ uint32 HasBitsOffset() const {
+ GOOGLE_DCHECK(HasHasbits());
+ return has_bits_offset_;
+ }
+
+ // The offset of the InternalMetadataWithArena member.
+ // For Lite this will actually be an InternalMetadataWithArenaLite.
+ // The schema doesn't contain enough information to distinguish between
+ // these two cases.
+ uint32 GetMetadataOffset() const {
+ return metadata_offset_;
+ }
+
+ // Whether this message has an ExtensionSet.
+ bool HasExtensionSet() const { return extensions_offset_ != -1; }
+
+ // The offset of the ExtensionSet in this message.
+ uint32 GetExtensionSetOffset() const {
+ GOOGLE_DCHECK(HasExtensionSet());
+ return extensions_offset_;
+ }
+
+ // The off set of WeakFieldMap when the message contains weak fields.
+ // The default is 0 for now.
+ int GetWeakFieldMapOffset() const { return weak_field_map_offset_; }
+
+ bool IsDefaultInstance(const Message& message) const {
+ return &message == default_instance_;
+ }
+
+ // Returns a pointer to the default value for this field. The size and type
+ // of the underlying data depends on the field's type.
+ const void *GetFieldDefault(const FieldDescriptor* field) const {
+ return reinterpret_cast<const uint8*>(default_instance_) +
+ offsets_[field->index()];
+ }
+
+ // These members are intended to be private, but we cannot actually make them
+ // private because this prevents us from using aggregate initialization of
+ // them, ie.
+ //
+ // ReflectionSchema schema = {a, b, c, d, e, ...};
+ // private:
+ const Message* default_instance_;
+ const uint32* offsets_;
+ const uint32* has_bit_indices_;
+ int has_bits_offset_;
+ int metadata_offset_;
+ int extensions_offset_;
+ int oneof_case_offset_;
+ int object_size_;
+ int weak_field_map_offset_;
+};
+
+// Structs that the code generator emits directly to describe a message.
+// These should never used directly except to build a ReflectionSchema
+// object.
+//
+// EXPERIMENTAL: these are changing rapidly, and may completely disappear
+// or merge with ReflectionSchema.
+struct MigrationSchema {
+ int32 offsets_index;
+ int32 has_bit_indices_index;
+ int object_size;
+};
+
// THIS CLASS IS NOT INTENDED FOR DIRECT USE. It is intended for use
// by generated code. This class is just a big hack that reduces code
// size.
@@ -97,118 +240,24 @@ class ExtensionSet; // extension_set.h
// of whatever type the individual field would be. Strings and
// Messages use RepeatedPtrFields while everything else uses
// RepeatedFields.
-class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection {
+class LIBPROTOBUF_EXPORT GeneratedMessageReflection PROTOBUF_FINAL
+ : public Reflection {
public:
// Constructs a GeneratedMessageReflection.
// Parameters:
// descriptor: The descriptor for the message type being implemented.
- // default_instance: The default instance of the message. This is only
- // used to obtain pointers to default instances of embedded
- // messages, which GetMessage() will return if the particular
- // sub-message has not been initialized yet. (Thus, all
- // embedded message fields *must* have non-NULL pointers
- // in the default instance.)
- // offsets: An array of ints giving the byte offsets, relative to
- // the start of the message object, of each field. These can
- // be computed at compile time using the
- // GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET() macro, defined
- // below.
- // has_bits_offset: Offset in the message of an array of uint32s of size
- // descriptor->field_count()/32, rounded up. This is a
- // bitfield where each bit indicates whether or not the
- // corresponding field of the message has been initialized.
- // The bit for field index i is obtained by the expression:
- // has_bits[i / 32] & (1 << (i % 32))
- // unknown_fields_offset: Offset in the message of the UnknownFieldSet for
- // the message.
- // extensions_offset: Offset in the message of the ExtensionSet for the
- // message, or -1 if the message type has no extension
- // ranges.
+ // schema: The description of the internal guts of the message.
// pool: DescriptorPool to search for extension definitions. Only
// used by FindKnownExtensionByName() and
// FindKnownExtensionByNumber().
// factory: MessageFactory to use to construct extension messages.
- // object_size: The size of a message object of this type, as measured
- // 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 ReflectionSchema& schema,
const DescriptorPool* pool,
- MessageFactory* factory,
- int object_size,
- int arena_offset,
- int is_default_instance_offset = -1);
+ MessageFactory* factory);
- // Similar with the construction above. Call this construction if the
- // message has oneof definition.
- // Parameters:
- // offsets: An array of ints giving the byte offsets.
- // For each oneof field, the offset is relative to the
- // default_oneof_instance. These can be computed at compile
- // time using the
- // PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET() macro.
- // For each none oneof field, the offset is related to
- // the start of the message object. These can be computed
- // at compile time using the
- // GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET() macro.
- // Besides offsets for all fields, this array also contains
- // offsets for oneof unions. The offset of the i-th oneof
- // union is offsets[descriptor->field_count() + i].
- // default_oneof_instance: The default instance of the oneofs. It is a
- // struct holding the default value of all oneof fields
- // for this message. It is only used to obtain pointers
- // to default instances of oneof fields, which Get
- // methods will return if the field is not set.
- // oneof_case_offset: Offset in the message of an array of uint32s of
- // size descriptor->oneof_decl_count(). Each uint32
- // indicates what field is set for each oneof.
- // 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 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);
~GeneratedMessageReflection();
- // Shorter-to-call helpers for the above two constructions that work if the
- // pool and factory are the usual, namely, DescriptorPool::generated_pool()
- // and MessageFactory::generated_factory().
-
- static GeneratedMessageReflection* NewGeneratedMessageReflection(
- 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,
- int object_size,
- int arena_offset,
- int is_default_instance_offset = -1);
-
- static GeneratedMessageReflection* NewGeneratedMessageReflection(
- const Descriptor* descriptor,
- const Message* default_instance,
- const int offsets[],
- int has_bits_offset,
- int unknown_fields_offset,
- int extensions_offset,
- int object_size,
- int arena_offset,
- int is_default_instance_offset = -1);
-
// implements Reflection -------------------------------------------
const UnknownFieldSet& GetUnknownFields(const Message& message) const;
@@ -226,11 +275,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<const FieldDescriptor*>& fields) const;
+ const std::vector<const FieldDescriptor*>& fields) const;
void SwapElements(Message* message, const FieldDescriptor* field,
int index1, int index2) const;
void ListFields(const Message& message,
- vector<const FieldDescriptor*>* output) const;
+ std::vector<const FieldDescriptor*>* output) const;
int32 GetInt32 (const Message& message,
const FieldDescriptor* field) const;
@@ -433,39 +482,27 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection {
private:
friend class GeneratedMessage;
-
- // To parse directly into a proto2 generated class, the class GMR_Handlers
- // needs access to member offsets and hasbits.
friend class upb::google_opensource::GMR_Handlers;
- const Descriptor* descriptor_;
- const Message* default_instance_;
- const void* default_oneof_instance_;
- const int* offsets_;
-
- int has_bits_offset_;
- int oneof_case_offset_;
- int unknown_fields_offset_;
- int extensions_offset_;
- int arena_offset_;
- int is_default_instance_offset_;
- int object_size_;
-
- static const int kHasNoDefaultInstanceField = -1;
+ const Descriptor* const descriptor_;
+ const ReflectionSchema schema_;
+ const DescriptorPool* const descriptor_pool_;
+ MessageFactory* const message_factory_;
- const DescriptorPool* descriptor_pool_;
- MessageFactory* message_factory_;
+ template <class T>
+ const T& GetRawNonOneof(const Message& message,
+ const FieldDescriptor* field) const;
+ template <class T>
+ T* MutableRawNonOneof(Message* message, const FieldDescriptor* field) const;
template <typename Type>
- inline const Type& GetRaw(const Message& message,
+ const Type& GetRaw(const Message& message,
const FieldDescriptor* field) const;
template <typename Type>
inline Type* MutableRaw(Message* message,
const FieldDescriptor* field) const;
template <typename Type>
inline const Type& DefaultRaw(const FieldDescriptor* field) const;
- template <typename Type>
- inline const Type& DefaultOneofRaw(const FieldDescriptor* field) const;
inline const uint32* GetHasBits(const Message& message) const;
inline uint32* MutableHasBits(Message* message) const;
@@ -478,12 +515,12 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection {
inline const ExtensionSet& GetExtensionSet(const Message& message) const;
inline ExtensionSet* MutableExtensionSet(Message* message) const;
inline Arena* GetArena(Message* message) const;
- inline const internal::InternalMetadataWithArena&
- GetInternalMetadataWithArena(const Message& message) const;
- inline internal::InternalMetadataWithArena*
- MutableInternalMetadataWithArena(Message* message) const;
- inline bool GetIsDefaultInstance(const Message& message) const;
+ inline const InternalMetadataWithArena& GetInternalMetadataWithArena(
+ const Message& message) const;
+
+ inline InternalMetadataWithArena*
+ MutableInternalMetadataWithArena(Message* message) const;
inline bool HasBit(const Message& message,
const FieldDescriptor* field) const;
@@ -571,6 +608,9 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection {
internal::MapFieldBase* MapData(
Message* message, const FieldDescriptor* field) const;
+ friend inline // inline so nobody can call this function.
+ void
+ RegisterAllTypesInternal(const Metadata* file_level_metadata, int size);
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratedMessageReflection);
};
@@ -597,14 +637,14 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection {
// choose 16 rather than some other number just in case the compiler would
// be confused by an unaligned pointer.
#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \
- static_cast<int>( \
- reinterpret_cast<const char*>( \
- &reinterpret_cast<const TYPE*>(16)->FIELD) - \
+ static_cast< ::google::protobuf::uint32>( \
+ reinterpret_cast<const char*>( \
+ &reinterpret_cast<const TYPE*>(16)->FIELD) - \
reinterpret_cast<const char*>(16))
#endif
#define PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(ONEOF, FIELD) \
- static_cast<int>( \
+ static_cast< ::google::protobuf::uint32>( \
reinterpret_cast<const char*>(&(ONEOF->FIELD)) \
- reinterpret_cast<const char*>(ONEOF))
@@ -634,6 +674,8 @@ class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection {
template<typename To, typename From>
inline To dynamic_cast_if_available(From from) {
#if defined(GOOGLE_PROTOBUF_NO_RTTI) || (defined(_MSC_VER)&&!defined(_CPPRTTI))
+ // Avoid the compiler warning about unused variables.
+ (void)from;
return NULL;
#else
return dynamic_cast<To>(from);
@@ -676,6 +718,17 @@ T* DynamicCastToGenerated(Message* from) {
return const_cast<T*>(DynamicCastToGenerated<const T>(message_const));
}
+LIBPROTOBUF_EXPORT void AssignDescriptors(
+ const string& filename, const MigrationSchema* schemas,
+ const Message* const* default_instances_, const uint32* offsets,
+ MessageFactory* factory,
+ // update the following descriptor arrays.
+ Metadata* file_level_metadata,
+ const EnumDescriptor** file_level_enum_descriptors,
+ const ServiceDescriptor** file_level_service_descriptors);
+
+LIBPROTOBUF_EXPORT void RegisterAllTypes(const Metadata* file_level_metadata, int size);
+
} // namespace internal
} // namespace protobuf
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/generated_message_reflection_unittest.cc b/third_party/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc
index 6276b66793..242cc4a1b7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/generated_message_reflection_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc
@@ -48,9 +48,10 @@
#include <google/protobuf/stubs/shared_ptr.h>
#endif
-#include <google/protobuf/descriptor.h>
#include <google/protobuf/test_util.h>
#include <google/protobuf/unittest.pb.h>
+#include <google/protobuf/arena.h>
+#include <google/protobuf/descriptor.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
@@ -222,7 +223,7 @@ TEST(GeneratedMessageReflectionTest, SwapFields) {
message2.set_optional_string("hello");
message2.mutable_repeated_int64()->Add(30);
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
const Descriptor* descriptor = message1.GetDescriptor();
fields.push_back(descriptor->FindFieldByName("optional_double"));
fields.push_back(descriptor->FindFieldByName("repeated_int32"));
@@ -255,7 +256,7 @@ TEST(GeneratedMessageReflectionTest, SwapFieldsAll) {
TestUtil::SetAllFields(&message2);
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
const Reflection* reflection = message1.GetReflection();
reflection->ListFields(message2, &fields);
reflection->SwapFields(&message1, &message2, fields);
@@ -270,7 +271,7 @@ TEST(GeneratedMessageReflectionTest, SwapFieldsAllExtension) {
TestUtil::SetAllExtensions(&message1);
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
const Reflection* reflection = message1.GetReflection();
reflection->ListFields(message1, &fields);
reflection->SwapFields(&message1, &message2, fields);
@@ -306,7 +307,7 @@ TEST(GeneratedMessageReflectionTest, SwapFieldsOneof) {
unittest::TestOneof2 message1, message2;
TestUtil::SetOneof1(&message1);
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
const Descriptor* descriptor = message1.GetDescriptor();
for (int i = 0; i < descriptor->field_count(); i++) {
fields.push_back(descriptor->field(i));
@@ -519,6 +520,41 @@ TEST(GeneratedMessageReflectionTest, SetAllocatedMessageTest) {
&to_message, TestUtil::ReflectionTester::IS_NULL);
}
+TEST(GeneratedMessageReflectionTest, SetAllocatedMessageOnArenaTest) {
+ unittest::TestAllTypes from_message1;
+ unittest::TestAllTypes from_message2;
+ ::google::protobuf::Arena arena;
+ unittest::TestAllTypes* to_message =
+ ::google::protobuf::Arena::CreateMessage<unittest::TestAllTypes>(&arena);
+ TestUtil::ReflectionTester reflection_tester(
+ unittest::TestAllTypes::descriptor());
+ reflection_tester.SetAllFieldsViaReflection(&from_message1);
+ reflection_tester.SetAllFieldsViaReflection(&from_message2);
+
+ // Before moving fields, we expect the nested messages to be NULL.
+ reflection_tester.ExpectMessagesReleasedViaReflection(
+ to_message, TestUtil::ReflectionTester::IS_NULL);
+
+ // After fields are moved we should get non-NULL releases.
+ reflection_tester.SetAllocatedOptionalMessageFieldsToMessageViaReflection(
+ &from_message1, to_message);
+ reflection_tester.ExpectMessagesReleasedViaReflection(
+ to_message, TestUtil::ReflectionTester::NOT_NULL);
+
+ // Another move to make sure that we can SetAllocated several times.
+ reflection_tester.SetAllocatedOptionalMessageFieldsToMessageViaReflection(
+ &from_message2, to_message);
+ reflection_tester.ExpectMessagesReleasedViaReflection(
+ to_message, TestUtil::ReflectionTester::NOT_NULL);
+
+ // After SetAllocatedOptionalMessageFieldsToNullViaReflection() we expect the
+ // releases to be NULL again.
+ reflection_tester.SetAllocatedOptionalMessageFieldsToNullViaReflection(
+ to_message);
+ reflection_tester.ExpectMessagesReleasedViaReflection(
+ to_message, TestUtil::ReflectionTester::IS_NULL);
+}
+
TEST(GeneratedMessageReflectionTest, SetAllocatedExtensionMessageTest) {
unittest::TestAllExtensions from_message1;
unittest::TestAllExtensions from_message2;
@@ -552,6 +588,41 @@ TEST(GeneratedMessageReflectionTest, SetAllocatedExtensionMessageTest) {
&to_message, TestUtil::ReflectionTester::IS_NULL);
}
+TEST(GeneratedMessageReflectionTest, SetAllocatedExtensionMessageOnArenaTest) {
+ ::google::protobuf::Arena arena;
+ unittest::TestAllExtensions* to_message =
+ ::google::protobuf::Arena::CreateMessage<unittest::TestAllExtensions>(&arena);
+ unittest::TestAllExtensions from_message1;
+ unittest::TestAllExtensions from_message2;
+ TestUtil::ReflectionTester reflection_tester(
+ unittest::TestAllExtensions::descriptor());
+ reflection_tester.SetAllFieldsViaReflection(&from_message1);
+ reflection_tester.SetAllFieldsViaReflection(&from_message2);
+
+ // Before moving fields, we expect the nested messages to be NULL.
+ reflection_tester.ExpectMessagesReleasedViaReflection(
+ to_message, TestUtil::ReflectionTester::IS_NULL);
+
+ // After fields are moved we should get non-NULL releases.
+ reflection_tester.SetAllocatedOptionalMessageFieldsToMessageViaReflection(
+ &from_message1, to_message);
+ reflection_tester.ExpectMessagesReleasedViaReflection(
+ to_message, TestUtil::ReflectionTester::NOT_NULL);
+
+ // Another move to make sure that we can SetAllocated several times.
+ reflection_tester.SetAllocatedOptionalMessageFieldsToMessageViaReflection(
+ &from_message2, to_message);
+ reflection_tester.ExpectMessagesReleasedViaReflection(
+ to_message, TestUtil::ReflectionTester::NOT_NULL);
+
+ // After SetAllocatedOptionalMessageFieldsToNullViaReflection() we expect the
+ // releases to be NULL again.
+ reflection_tester.SetAllocatedOptionalMessageFieldsToNullViaReflection(
+ to_message);
+ reflection_tester.ExpectMessagesReleasedViaReflection(
+ to_message, TestUtil::ReflectionTester::IS_NULL);
+}
+
TEST(GeneratedMessageReflectionTest, AddRepeatedMessage) {
unittest::TestAllTypes message;
@@ -608,7 +679,7 @@ TEST(GeneratedMessageReflectionTest, ListFieldsOneOf) {
TestUtil::SetOneof1(&message);
const Reflection* reflection = message.GetReflection();
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
reflection->ListFields(message, &fields);
EXPECT_EQ(4, fields.size());
}
@@ -723,6 +794,59 @@ TEST(GeneratedMessageReflectionTest, SetAllocatedOneofMessageTest) {
delete released;
}
+TEST(GeneratedMessageReflectionTest, SetAllocatedOneofMessageOnArenaTest) {
+ unittest::TestOneof2 from_message1;
+ unittest::TestOneof2 from_message2;
+ ::google::protobuf::Arena arena;
+ unittest::TestOneof2* to_message =
+ ::google::protobuf::Arena::CreateMessage<unittest::TestOneof2>(&arena);
+ const Descriptor* descriptor = unittest::TestOneof2::descriptor();
+ const Reflection* reflection = to_message->GetReflection();
+
+ Message* released = reflection->ReleaseMessage(
+ to_message, descriptor->FindFieldByName("foo_lazy_message"));
+ EXPECT_TRUE(released == NULL);
+ released = reflection->ReleaseMessage(
+ to_message, descriptor->FindFieldByName("foo_message"));
+ EXPECT_TRUE(released == NULL);
+
+ TestUtil::ReflectionTester::SetOneofViaReflection(&from_message1);
+ TestUtil::ReflectionTester::ExpectOneofSetViaReflection(from_message1);
+
+ TestUtil::ReflectionTester::
+ SetAllocatedOptionalMessageFieldsToMessageViaReflection(
+ &from_message1, to_message);
+ const Message& sub_message = reflection->GetMessage(
+ *to_message, descriptor->FindFieldByName("foo_lazy_message"));
+ released = reflection->ReleaseMessage(
+ to_message, descriptor->FindFieldByName("foo_lazy_message"));
+ EXPECT_TRUE(released != NULL);
+ // Since sub_message is arena allocated, releasing it results in copying it
+ // into new heap-allocated memory.
+ EXPECT_NE(&sub_message, released);
+ delete released;
+
+ TestUtil::ReflectionTester::SetOneofViaReflection(&from_message2);
+
+ reflection->MutableMessage(
+ &from_message2, descriptor->FindFieldByName("foo_message"));
+
+ TestUtil::ReflectionTester::
+ SetAllocatedOptionalMessageFieldsToMessageViaReflection(
+ &from_message2, to_message);
+
+ const Message& sub_message2 = reflection->GetMessage(
+ *to_message, descriptor->FindFieldByName("foo_message"));
+ released = reflection->ReleaseMessage(
+ to_message, descriptor->FindFieldByName("foo_message"));
+ EXPECT_TRUE(released != NULL);
+ // Since sub_message2 is arena allocated, releasing it results in copying it
+ // into new heap-allocated memory.
+ EXPECT_NE(&sub_message2, released);
+ delete released;
+}
+
+
TEST(GeneratedMessageReflectionTest, ReleaseMessageTest) {
unittest::TestAllTypes message;
TestUtil::ReflectionTester reflection_tester(
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/generated_message_util.cc b/third_party/protobuf/src/google/protobuf/generated_message_util.cc
index 7ad6d61cbc..b4d2c9c150 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/generated_message_util.cc
+++ b/third_party/protobuf/src/google/protobuf/generated_message_util.cc
@@ -48,15 +48,13 @@ double NaN() {
return std::numeric_limits<double>::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_;
-}
+void DeleteEmptyString() { fixed_address_empty_string.Shutdown(); }
void InitEmptyString() {
- empty_string_ = new string;
+ fixed_address_empty_string.DefaultConstruct();
OnShutdown(&DeleteEmptyString);
}
@@ -73,10 +71,8 @@ int StringSpaceUsedExcludingSelf(const string& str) {
-void MergeFromFail(const char* file, int line) {
- GOOGLE_CHECK(false) << file << ":" << line;
- // Open-source GOOGLE_CHECK(false) is not NORETURN.
- exit(1);
+void InitProtobufDefaults() {
+ GetEmptyString();
}
} // namespace internal
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/generated_message_util.h b/third_party/protobuf/src/google/protobuf/generated_message_util.h
index 8967726e77..14101832a2 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/generated_message_util.h
+++ b/third_party/protobuf/src/google/protobuf/generated_message_util.h
@@ -43,6 +43,15 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/once.h>
+#include <google/protobuf/has_bits.h>
+
+#ifndef PROTOBUF_FINAL
+#if LANG_CXX11
+#define PROTOBUF_FINAL final
+#else
+#define PROTOBUF_FINAL
+#endif
+#endif // !PROTOBUF_FINAL
namespace google {
@@ -70,22 +79,61 @@ 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 <typename T>
+class ExplicitlyConstructed {
+ public:
+ void DefaultConstruct() {
+ new (&union_) T();
+ init_ = true;
+ }
+
+ bool IsInitialized() { return init_; }
+ void Shutdown() {
+ if (init_) {
+ init_ = false;
+ get_mutable()->~T();
+ }
+ }
+
+#if LANG_CXX11
+ constexpr
+#endif
+ const T&
+ get() const {
+ return reinterpret_cast<const T&>(union_);
+ }
+ T* get_mutable() { return reinterpret_cast<T*>(&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_;
+LIBPROTOBUF_EXPORT 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,19 +154,25 @@ template <class Type> bool AllAreInitialized(const Type& t) {
return true;
}
-class ArenaString;
+LIBPROTOBUF_EXPORT void InitProtobufDefaults();
-// 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);
+// 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<int>(size);
+}
-// 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 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<unsigned int>(size);
+}
} // namespace internal
} // namespace protobuf
diff --git a/third_party/protobuf/src/google/protobuf/has_bits.h b/third_party/protobuf/src/google/protobuf/has_bits.h
new file mode 100644
index 0000000000..cb1d7cccb6
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/has_bits.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_HAS_BITS_H__
+#define GOOGLE_PROTOBUF_HAS_BITS_H__
+
+#include <google/protobuf/stubs/common.h>
+
+namespace google {
+namespace protobuf {
+namespace internal {
+
+template<size_t doublewords>
+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<doublewords>& rhs) const {
+ return memcmp(has_bits_, rhs.has_bits_, sizeof(has_bits_)) == 0;
+ }
+
+ bool operator!=(const HasBits<doublewords>& rhs) const {
+ return !(*this == rhs);
+ }
+
+ bool empty() const;
+
+ private:
+ ::google::protobuf::uint32 has_bits_[doublewords];
+};
+
+template <>
+inline bool HasBits<1>::empty() const {
+ return !has_bits_[0];
+}
+
+template <>
+inline bool HasBits<2>::empty() const {
+ return !(has_bits_[0] | has_bits_[1]);
+}
+
+template <>
+inline bool HasBits<3>::empty() const {
+ return !(has_bits_[0] | has_bits_[1] | has_bits_[2]);
+}
+
+template <>
+inline bool HasBits<4>::empty() const {
+ return !(has_bits_[0] | has_bits_[1] | has_bits_[2] | has_bits_[3]);
+}
+
+template <size_t doublewords>
+inline bool HasBits<doublewords>::empty() const {
+ for (size_t i = 0; i < doublewords; ++i) {
+ if (has_bits_[i]) return false;
+ }
+ return true;
+}
+
+} // namespace internal
+} // namespace protobuf
+
+} // namespace google
+#endif // GOOGLE_PROTOBUF_HAS_BITS_H__
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/coded_stream.cc b/third_party/protobuf/src/google/protobuf/io/coded_stream.cc
index a5675e79f8..3c2e0fbd2c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/coded_stream.cc
+++ b/third_party/protobuf/src/google/protobuf/io/coded_stream.cc
@@ -549,9 +549,15 @@ bool CodedInputStream::ReadVarint64Slow(uint64* value) {
uint32 b;
do {
- if (count == kMaxVarintBytes) return false;
+ if (count == kMaxVarintBytes) {
+ *value = 0;
+ return false;
+ }
while (buffer_ == buffer_end_) {
- if (!Refresh()) return false;
+ if (!Refresh()) {
+ *value = 0;
+ return false;
+ }
}
b = *buffer_;
result |= static_cast<uint64>(b & 0x7F) << (7 * count);
@@ -601,13 +607,13 @@ bool CodedInputStream::Refresh() {
if (total_bytes_warning_threshold_ >= 0 &&
total_bytes_read_ >= total_bytes_warning_threshold_) {
- GOOGLE_LOG(WARNING) << "Reading dangerously large protocol message. If the "
- "message turns out to be larger than "
- << total_bytes_limit_ << " bytes, parsing will be halted "
- "for security reasons. To increase the limit (or to "
- "disable these warnings), see "
- "CodedInputStream::SetTotalBytesLimit() in "
- "google/protobuf/io/coded_stream.h.";
+ GOOGLE_LOG(INFO) << "Reading dangerously large protocol message. If the "
+ "message turns out to be larger than "
+ << total_bytes_limit_ << " bytes, parsing will be halted "
+ "for security reasons. To increase the limit (or to "
+ "disable these warnings), see "
+ "CodedInputStream::SetTotalBytesLimit() in "
+ "google/protobuf/io/coded_stream.h.";
// Don't warn again for this stream, and print total size at the end.
total_bytes_warning_threshold_ = -2;
@@ -788,104 +794,12 @@ void CodedOutputStream::WriteVarint32SlowPath(uint32 value) {
WriteRaw(bytes, size);
}
-inline uint8* CodedOutputStream::WriteVarint64ToArrayInline(
- uint64 value, uint8* target) {
- // Splitting into 32-bit pieces gives better performance on 32-bit
- // processors.
- uint32 part0 = static_cast<uint32>(value );
- uint32 part1 = static_cast<uint32>(value >> 28);
- uint32 part2 = static_cast<uint32>(value >> 56);
-
- int size;
-
- // Here we can't really optimize for small numbers, since the value is
- // split into three parts. Cheking for numbers < 128, for instance,
- // would require three comparisons, since you'd have to make sure part1
- // and part2 are zero. However, if the caller is using 64-bit integers,
- // it is likely that they expect the numbers to often be very large, so
- // we probably don't want to optimize for small numbers anyway. Thus,
- // we end up with a hardcoded binary search tree...
- if (part2 == 0) {
- if (part1 == 0) {
- if (part0 < (1 << 14)) {
- if (part0 < (1 << 7)) {
- size = 1; goto size1;
- } else {
- size = 2; goto size2;
- }
- } else {
- if (part0 < (1 << 21)) {
- size = 3; goto size3;
- } else {
- size = 4; goto size4;
- }
- }
- } else {
- if (part1 < (1 << 14)) {
- if (part1 < (1 << 7)) {
- size = 5; goto size5;
- } else {
- size = 6; goto size6;
- }
- } else {
- if (part1 < (1 << 21)) {
- size = 7; goto size7;
- } else {
- size = 8; goto size8;
- }
- }
- }
- } else {
- if (part2 < (1 << 7)) {
- size = 9; goto size9;
- } else {
- size = 10; goto size10;
- }
- }
-
- GOOGLE_LOG(FATAL) << "Can't get here.";
-
- size10: target[9] = static_cast<uint8>((part2 >> 7) | 0x80);
- size9 : target[8] = static_cast<uint8>((part2 ) | 0x80);
- size8 : target[7] = static_cast<uint8>((part1 >> 21) | 0x80);
- size7 : target[6] = static_cast<uint8>((part1 >> 14) | 0x80);
- size6 : target[5] = static_cast<uint8>((part1 >> 7) | 0x80);
- size5 : target[4] = static_cast<uint8>((part1 ) | 0x80);
- size4 : target[3] = static_cast<uint8>((part0 >> 21) | 0x80);
- size3 : target[2] = static_cast<uint8>((part0 >> 14) | 0x80);
- size2 : target[1] = static_cast<uint8>((part0 >> 7) | 0x80);
- size1 : target[0] = static_cast<uint8>((part0 ) | 0x80);
-
- target[size-1] &= 0x7F;
- return target + size;
-}
-
-void CodedOutputStream::WriteVarint64(uint64 value) {
- if (buffer_size_ >= kMaxVarintBytes) {
- // Fast path: We have enough bytes left in the buffer to guarantee that
- // this write won't cross the end, so we can skip the checks.
- uint8* target = buffer_;
-
- uint8* end = WriteVarint64ToArrayInline(value, target);
- int size = end - target;
- Advance(size);
- } else {
- // Slow path: This write might cross the end of the buffer, so we
- // compose the bytes first then use WriteRaw().
- uint8 bytes[kMaxVarintBytes];
- int size = 0;
- while (value > 0x7F) {
- bytes[size++] = (static_cast<uint8>(value) & 0x7F) | 0x80;
- value >>= 7;
- }
- bytes[size++] = static_cast<uint8>(value) & 0x7F;
- WriteRaw(bytes, size);
- }
-}
-
-uint8* CodedOutputStream::WriteVarint64ToArray(
- uint64 value, uint8* target) {
- return WriteVarint64ToArrayInline(value, target);
+void CodedOutputStream::WriteVarint64SlowPath(uint64 value) {
+ uint8 bytes[kMaxVarintBytes];
+ uint8* target = &bytes[0];
+ uint8* end = WriteVarint64ToArray(value, target);
+ int size = end - target;
+ WriteRaw(bytes, size);
}
bool CodedOutputStream::Refresh() {
@@ -902,48 +816,6 @@ bool CodedOutputStream::Refresh() {
}
}
-int CodedOutputStream::VarintSize32Fallback(uint32 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;
- }
- }
-}
-
uint8* CodedOutputStream::WriteStringWithSizeToArray(const string& str,
uint8* target) {
GOOGLE_DCHECK_LE(str.size(), kuint32max);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/coded_stream.h b/third_party/protobuf/src/google/protobuf/io/coded_stream.h
index 316da76524..b71b4a989d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/coded_stream.h
+++ b/third_party/protobuf/src/google/protobuf/io/coded_stream.h
@@ -110,6 +110,7 @@
#define GOOGLE_PROTOBUF_IO_CODED_STREAM_H__
#include <assert.h>
+#include <climits>
#include <string>
#include <utility>
#ifdef _MSC_VER
@@ -139,6 +140,8 @@ namespace protobuf {
class DescriptorPool;
class MessageFactory;
+namespace internal { void MapTestForceDeterministic(); }
+
namespace io {
// Defined in this file.
@@ -249,12 +252,16 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
bool ReadVarintSizeAsInt(int* value);
// Read a tag. This calls ReadVarint32() and returns the result, or returns
- // zero (which is not a valid tag) if ReadVarint32() fails. Also, it updates
- // the last tag value, which can be checked with LastTagWas().
+ // zero (which is not a valid tag) if ReadVarint32() fails. Also, ReadTag
+ // (but not ReadTagNoLastTag) updates the last tag value, which can be checked
+ // with LastTagWas().
+ //
// Always inline because this is only called in one place per parse loop
// but it is called for every iteration of said loop, so it should be fast.
// GCC doesn't want to inline this by default.
GOOGLE_ATTRIBUTE_ALWAYS_INLINE uint32 ReadTag();
+ GOOGLE_ATTRIBUTE_ALWAYS_INLINE uint32 ReadTagNoLastTag();
+
// This usually a faster alternative to ReadTag() when cutoff is a manifest
// constant. It does particularly well for cutoff >= 127. The first part
@@ -266,6 +273,8 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// to avoid an extra "is tag == 0?" check here.)
GOOGLE_ATTRIBUTE_ALWAYS_INLINE std::pair<uint32, bool> ReadTagWithCutoff(
uint32 cutoff);
+ GOOGLE_ATTRIBUTE_ALWAYS_INLINE std::pair<uint32, bool> ReadTagWithCutoffNoLastTag(
+ uint32 cutoff);
// Usually returns true if calling ReadVarint32() now would produce the given
// value. Will always return false if ReadVarint32() would not return the
@@ -293,8 +302,10 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// zero, and ConsumedEntireMessage() will return true.
bool ExpectAtEnd();
- // If the last call to ReadTag() or ReadTagWithCutoff() returned the
- // given value, returns true. Otherwise, returns false;
+ // If the last call to ReadTag() or ReadTagWithCutoff() returned the given
+ // value, returns true. Otherwise, returns false.
+ // ReadTagNoLastTag/ReadTagWithCutoffNoLastTag do not preserve the last
+ // returned value.
//
// This is needed because parsers for some types of embedded messages
// (with field type TYPE_GROUP) don't actually know that they've reached the
@@ -612,6 +623,13 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
int ReadVarintSizeAsIntSlow();
bool ReadLittleEndian32Fallback(uint32* value);
bool ReadLittleEndian64Fallback(uint64* value);
+
+ template<bool update_last_tag>
+ GOOGLE_ATTRIBUTE_ALWAYS_INLINE uint32 ReadTagImplementation();
+ template<bool update_last_tag>
+ GOOGLE_ATTRIBUTE_ALWAYS_INLINE
+ std::pair<uint32, bool> ReadTagWithCutoffImplementation(uint32 cutoff);
+
// Fallback/slow methods for reading tags. These do not update last_tag_,
// but will set legitimate_message_end_ if we are at the end of the input
// stream.
@@ -622,7 +640,7 @@ class LIBPROTOBUF_EXPORT CodedInputStream {
// Return the size of the buffer.
int BufferSize() const;
- static const int kDefaultTotalBytesLimit = 64 << 20; // 64MB
+ static const int kDefaultTotalBytesLimit = INT_MAX;
static const int kDefaultTotalBytesWarningThreshold = 32 << 20; // 32MB
@@ -784,17 +802,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 <uint32 Value>
struct StaticVarintSize32 {
- static const int value =
+ static const size_t value =
(Value < (1 << 7))
? 1
: (Value < (1 << 14))
@@ -842,15 +860,19 @@ class LIBPROTOBUF_EXPORT CodedOutputStream {
serialization_deterministic_override_ = value;
}
// See above. Also, note that users of this CodedOutputStream may need to
- // call IsSerializationDeterminstic() to serialize in the intended way. This
+ // call IsSerializationDeterministic() to serialize in the intended way. This
// CodedOutputStream cannot enforce a desire for deterministic serialization
// by itself.
- bool IsSerializationDeterminstic() const {
+ bool IsSerializationDeterministic() const {
return serialization_deterministic_is_overridden_ ?
serialization_deterministic_override_ :
default_serialization_deterministic_;
}
+ static bool IsDefaultSerializationDeterministic() {
+ return default_serialization_deterministic_;
+ }
+
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedOutputStream);
@@ -879,20 +901,11 @@ class LIBPROTOBUF_EXPORT CodedOutputStream {
// If this write might cross the end of the buffer, we compose the bytes first
// then use WriteRaw().
void WriteVarint32SlowPath(uint32 value);
-
- // Always-inlined versions of WriteVarint* functions so that code can be
- // reused, while still controlling size. For instance, WriteVarint32ToArray()
- // should not directly call this: since it is inlined itself, doing so
- // would greatly increase the size of generated code. Instead, it should call
- // WriteVarint32FallbackToArray. Meanwhile, WriteVarint32() is already
- // out-of-line, so it should just invoke this directly to avoid any extra
- // function call overhead.
- GOOGLE_ATTRIBUTE_ALWAYS_INLINE static uint8* WriteVarint64ToArrayInline(
- uint64 value, uint8* target);
-
- static int VarintSize32Fallback(uint32 value);
+ void WriteVarint64SlowPath(uint64 value);
// See above. Other projects may use "friend" to allow them to call this.
+ // Requires: no protocol buffer serialization in progress.
+ friend void ::google::protobuf::internal::MapTestForceDeterministic();
static void SetDefaultSerializationDeterministic() {
default_serialization_deterministic_ = true;
}
@@ -981,8 +994,7 @@ inline const uint8* CodedInputStream::ReadLittleEndian64FromArray(
inline bool CodedInputStream::ReadLittleEndian32(uint32* value) {
#if defined(PROTOBUF_LITTLE_ENDIAN)
if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast<int>(sizeof(*value)))) {
- memcpy(value, buffer_, sizeof(*value));
- Advance(sizeof(*value));
+ buffer_ = ReadLittleEndian32FromArray(buffer_, value);
return true;
} else {
return ReadLittleEndian32Fallback(value);
@@ -995,8 +1007,7 @@ inline bool CodedInputStream::ReadLittleEndian32(uint32* value) {
inline bool CodedInputStream::ReadLittleEndian64(uint64* value) {
#if defined(PROTOBUF_LITTLE_ENDIAN)
if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast<int>(sizeof(*value)))) {
- memcpy(value, buffer_, sizeof(*value));
- Advance(sizeof(*value));
+ buffer_ = ReadLittleEndian64FromArray(buffer_, value);
return true;
} else {
return ReadLittleEndian64Fallback(value);
@@ -1007,21 +1018,47 @@ inline bool CodedInputStream::ReadLittleEndian64(uint64* value) {
}
inline uint32 CodedInputStream::ReadTag() {
+ return ReadTagImplementation<true>();
+}
+
+inline uint32 CodedInputStream::ReadTagNoLastTag() {
+ return ReadTagImplementation<false>();
+}
+
+template<bool update_last_tag>
+inline uint32 CodedInputStream::ReadTagImplementation() {
uint32 v = 0;
if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_)) {
v = *buffer_;
if (v < 0x80) {
- last_tag_ = v;
+ if (update_last_tag) {
+ last_tag_ = v;
+ }
Advance(1);
return v;
}
}
- last_tag_ = ReadTagFallback(v);
- return last_tag_;
+ v = ReadTagFallback(v);
+ if (update_last_tag) {
+ last_tag_ = v;
+ }
+ return v;
}
inline std::pair<uint32, bool> CodedInputStream::ReadTagWithCutoff(
uint32 cutoff) {
+ return ReadTagWithCutoffImplementation<true>(cutoff);
+}
+
+inline std::pair<uint32, bool> CodedInputStream::ReadTagWithCutoffNoLastTag(
+ uint32 cutoff) {
+ return ReadTagWithCutoffImplementation<false>(cutoff);
+}
+
+template<bool update_last_tag>
+inline std::pair<uint32, bool>
+CodedInputStream::ReadTagWithCutoffImplementation(
+ uint32 cutoff) {
// In performance-sensitive code we can expect cutoff to be a compile-time
// constant, and things like "cutoff >= kMax1ByteVarint" to be evaluated at
// compile time.
@@ -1033,7 +1070,10 @@ inline std::pair<uint32, bool> CodedInputStream::ReadTagWithCutoff(
first_byte_or_zero = buffer_[0];
if (static_cast<int8>(buffer_[0]) > 0) {
const uint32 kMax1ByteVarint = 0x7f;
- uint32 tag = last_tag_ = buffer_[0];
+ uint32 tag = buffer_[0];
+ if (update_last_tag) {
+ last_tag_ = tag;
+ }
Advance(1);
return std::make_pair(tag, cutoff >= kMax1ByteVarint || tag <= cutoff);
}
@@ -1044,7 +1084,10 @@ inline std::pair<uint32, bool> CodedInputStream::ReadTagWithCutoff(
GOOGLE_PREDICT_TRUE(buffer_ + 1 < buffer_end_) &&
GOOGLE_PREDICT_TRUE((buffer_[0] & ~buffer_[1]) >= 0x80)) {
const uint32 kMax2ByteVarint = (0x7f << 7) + 0x7f;
- uint32 tag = last_tag_ = (1u << 7) * buffer_[1] + (buffer_[0] - 0x80);
+ uint32 tag = (1u << 7) * buffer_[1] + (buffer_[0] - 0x80);
+ if (update_last_tag) {
+ last_tag_ = tag;
+ }
Advance(2);
// It might make sense to test for tag == 0 now, but it is so rare that
// that we don't bother. A varint-encoded 0 should be one byte unless
@@ -1057,8 +1100,11 @@ inline std::pair<uint32, bool> CodedInputStream::ReadTagWithCutoff(
}
}
// Slow path
- last_tag_ = ReadTagFallback(first_byte_or_zero);
- return std::make_pair(last_tag_, static_cast<uint32>(last_tag_ - 1) < cutoff);
+ const uint32 tag = ReadTagFallback(first_byte_or_zero);
+ if (update_last_tag) {
+ last_tag_ = tag;
+ }
+ return std::make_pair(tag, static_cast<uint32>(tag - 1) < cutoff);
}
inline bool CodedInputStream::LastTagWas(uint32 expected) {
@@ -1153,21 +1199,24 @@ inline uint8* CodedOutputStream::WriteVarint32ToArray(uint32 value,
return target + 1;
}
-inline void CodedOutputStream::WriteVarint32SignExtended(int32 value) {
- if (value < 0) {
- WriteVarint64(static_cast<uint64>(value));
- } else {
- WriteVarint32(static_cast<uint32>(value));
+inline uint8* CodedOutputStream::WriteVarint64ToArray(uint64 value,
+ uint8* target) {
+ while (value >= 0x80) {
+ *target = static_cast<uint8>(value | 0x80);
+ value >>= 7;
+ ++target;
}
+ *target = static_cast<uint8>(value);
+ return target + 1;
+}
+
+inline void CodedOutputStream::WriteVarint32SignExtended(int32 value) {
+ WriteVarint64(static_cast<uint64>(value));
}
inline uint8* CodedOutputStream::WriteVarint32SignExtendedToArray(
int32 value, uint8* target) {
- if (value < 0) {
- return WriteVarint64ToArray(static_cast<uint64>(value), target);
- } else {
- return WriteVarint32ToArray(static_cast<uint32>(value), target);
- }
+ return WriteVarint64ToArray(static_cast<uint64>(value), target);
}
inline uint8* CodedOutputStream::WriteLittleEndian32ToArray(uint32 value,
@@ -1216,6 +1265,19 @@ inline void CodedOutputStream::WriteVarint32(uint32 value) {
}
}
+inline void CodedOutputStream::WriteVarint64(uint64 value) {
+ if (buffer_size_ >= 10) {
+ // Fast path: We have enough bytes left in the buffer to guarantee that
+ // this write won't cross the end, so we can skip the checks.
+ uint8* target = buffer_;
+ uint8* end = WriteVarint64ToArray(value, target);
+ int size = static_cast<int>(end - target);
+ Advance(size);
+ } else {
+ WriteVarint64SlowPath(value);
+ }
+}
+
inline void CodedOutputStream::WriteTag(uint32 value) {
WriteVarint32(value);
}
@@ -1225,15 +1287,27 @@ inline uint8* CodedOutputStream::WriteTagToArray(
return WriteVarint32ToArray(value, target);
}
-inline int CodedOutputStream::VarintSize32(uint32 value) {
- if (value < (1 << 7)) {
- return 1;
- } else {
- return VarintSize32Fallback(value);
- }
+inline size_t CodedOutputStream::VarintSize32(uint32 value) {
+ // This computes value == 0 ? 1 : floor(log2(value)) / 7 + 1
+ // Use an explicit multiplication to implement the divide of
+ // a number in the 1..31 range.
+ // Explicit OR 0x1 to avoid calling Bits::Log2FloorNonZero(0), which is
+ // undefined.
+ uint32 log2value = Bits::Log2FloorNonZero(value | 0x1);
+ return static_cast<size_t>((log2value * 9 + 73) / 64);
+}
+
+inline size_t CodedOutputStream::VarintSize64(uint64 value) {
+ // This computes value == 0 ? 1 : floor(log2(value)) / 7 + 1
+ // Use an explicit multiplication to implement the divide of
+ // a number in the 1..63 range.
+ // Explicit OR 0x1 to avoid calling Bits::Log2FloorNonZero(0), which is
+ // undefined.
+ uint32 log2value = Bits::Log2FloorNonZero64(value | 0x1);
+ return static_cast<size_t>((log2value * 9 + 73) / 64);
}
-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/third_party/protobuf/3.0.0/src/google/protobuf/io/coded_stream_inl.h b/third_party/protobuf/src/google/protobuf/io/coded_stream_inl.h
index d95b06e04e..d95b06e04e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/coded_stream_inl.h
+++ b/third_party/protobuf/src/google/protobuf/io/coded_stream_inl.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/coded_stream_unittest.cc b/third_party/protobuf/src/google/protobuf/io/coded_stream_unittest.cc
index a8108e4572..31574d5be3 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/coded_stream_unittest.cc
+++ b/third_party/protobuf/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 {
@@ -134,7 +135,7 @@ class CodedStreamTest : public testing::Test {
// for further information.
static void SetupTotalBytesLimitWarningTest(
int total_bytes_limit, int warning_threshold,
- vector<string>* out_errors, vector<string>* out_warnings);
+ std::vector<string>* out_errors, std::vector<string>* out_warnings);
// Buffer used during most of the tests. This assumes tests run sequentially.
static const int kBufferSize = 1024 * 64;
@@ -244,7 +245,7 @@ TEST_F(CodedStreamTest, EmptyInputBeforeEos) {
int count_;
} in;
CodedInputStream input(&in);
- input.ReadTag();
+ input.ReadTagNoLastTag();
EXPECT_TRUE(input.ConsumedEntireMessage());
}
@@ -445,6 +446,21 @@ TEST_2D(CodedStreamTest, ReadVarint32Error, kVarintErrorCases, kBlockSizes) {
EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint32(&value));
}
+TEST_2D(CodedStreamTest, ReadVarint32Error_LeavesValueInInitializedState,
+ kVarintErrorCases, kBlockSizes) {
+ memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size);
+ ArrayInputStream input(buffer_, kVarintErrorCases_case.size,
+ kBlockSizes_case);
+ CodedInputStream coded_input(&input);
+
+ uint32 value = 0;
+ EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint32(&value));
+ // While the specific value following a failure is not critical, we do want to
+ // ensure that it doesn't get set to an uninitialized value. (This check fails
+ // in MSAN mode if value has been set to an uninitialized value.)
+ EXPECT_EQ(value, value);
+}
+
TEST_2D(CodedStreamTest, ReadVarint64Error, kVarintErrorCases, kBlockSizes) {
memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size);
ArrayInputStream input(buffer_, kVarintErrorCases_case.size,
@@ -455,6 +471,21 @@ TEST_2D(CodedStreamTest, ReadVarint64Error, kVarintErrorCases, kBlockSizes) {
EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint64(&value));
}
+TEST_2D(CodedStreamTest, ReadVarint64Error_LeavesValueInInitializedState,
+ kVarintErrorCases, kBlockSizes) {
+ memcpy(buffer_, kVarintErrorCases_case.bytes, kVarintErrorCases_case.size);
+ ArrayInputStream input(buffer_, kVarintErrorCases_case.size,
+ kBlockSizes_case);
+ CodedInputStream coded_input(&input);
+
+ uint64 value = 0;
+ EXPECT_EQ(kVarintErrorCases_case.can_parse, coded_input.ReadVarint64(&value));
+ // While the specific value following a failure is not critical, we do want to
+ // ensure that it doesn't get set to an uninitialized value. (This check fails
+ // in MSAN mode if value has been set to an uninitialized value.)
+ EXPECT_EQ(value, value);
+}
+
// -------------------------------------------------------------------
// VarintSize
@@ -494,6 +525,28 @@ TEST_1D(CodedStreamTest, VarintSize64, kVarintSizeCases) {
CodedOutputStream::VarintSize64(kVarintSizeCases_case.value));
}
+TEST_F(CodedStreamTest, VarintSize32PowersOfTwo) {
+ int expected = 1;
+ for (int i = 1; i < 32; i++) {
+ if (i % 7 == 0) {
+ expected += 1;
+ }
+ EXPECT_EQ(expected,
+ CodedOutputStream::VarintSize32(static_cast<uint32>(0x1u << i)));
+ }
+}
+
+TEST_F(CodedStreamTest, VarintSize64PowersOfTwo) {
+ int expected = 1;
+ for (int i = 1; i < 64; i++) {
+ if (i % 7 == 0) {
+ expected += 1;
+ }
+ EXPECT_EQ(expected, CodedOutputStream::VarintSize64(
+ static_cast<uint64>(0x1ull << i)));
+ }
+}
+
// -------------------------------------------------------------------
// Fixed-size int tests
@@ -1176,7 +1229,7 @@ TEST_F(CodedStreamTest, TotalBytesLimit) {
EXPECT_TRUE(coded_input.ReadString(&str, 16));
EXPECT_EQ(0, coded_input.BytesUntilTotalBytesLimit());
- vector<string> errors;
+ std::vector<string> errors;
{
ScopedMemoryLog error_log;
@@ -1210,7 +1263,7 @@ TEST_F(CodedStreamTest, TotalBytesLimitNotValidMessageEnd) {
// Read a tag. Should fail, but report being a valid endpoint since it's
// a regular limit.
- EXPECT_EQ(0, coded_input.ReadTag());
+ EXPECT_EQ(0, coded_input.ReadTagNoLastTag());
EXPECT_TRUE(coded_input.ConsumedEntireMessage());
// Pop the limit.
@@ -1218,7 +1271,7 @@ TEST_F(CodedStreamTest, TotalBytesLimitNotValidMessageEnd) {
// Read a tag. Should fail, and report *not* being a valid endpoint, since
// this time we're hitting the total bytes limit.
- EXPECT_EQ(0, coded_input.ReadTag());
+ EXPECT_EQ(0, coded_input.ReadTagNoLastTag());
EXPECT_FALSE(coded_input.ConsumedEntireMessage());
}
@@ -1228,7 +1281,7 @@ TEST_F(CodedStreamTest, TotalBytesLimitNotValidMessageEnd) {
// vectors.
void CodedStreamTest::SetupTotalBytesLimitWarningTest(
int total_bytes_limit, int warning_threshold,
- vector<string>* out_errors, vector<string>* out_warnings) {
+ std::vector<string>* out_errors, std::vector<string>* out_warnings) {
ArrayInputStream raw_input(buffer_, sizeof(buffer_), 128);
ScopedMemoryLog scoped_log;
@@ -1244,25 +1297,21 @@ void CodedStreamTest::SetupTotalBytesLimitWarningTest(
}
TEST_F(CodedStreamTest, TotalBytesLimitWarning) {
- vector<string> errors;
- vector<string> warnings;
+ std::vector<string> errors;
+ std::vector<string> warnings;
SetupTotalBytesLimitWarningTest(10240, 1024, &errors, &warnings);
EXPECT_EQ(0, errors.size());
- ASSERT_EQ(2, warnings.size());
- EXPECT_PRED_FORMAT2(testing::IsSubstring,
- "Reading dangerously large protocol message. If the message turns out to "
- "be larger than 10240 bytes, parsing will be halted for security reasons.",
- warnings[0]);
+ EXPECT_EQ(1, warnings.size());
EXPECT_PRED_FORMAT2(testing::IsSubstring,
"The total number of bytes read was 2048",
- warnings[1]);
+ warnings[0]);
}
TEST_F(CodedStreamTest, TotalBytesLimitWarningDisabled) {
- vector<string> errors;
- vector<string> warnings;
+ std::vector<string> errors;
+ std::vector<string> warnings;
// Test with -1
SetupTotalBytesLimitWarningTest(10240, -1, &errors, &warnings);
@@ -1361,7 +1410,7 @@ TEST_F(CodedStreamTest, InputOver2G) {
// input.BackUp() with the correct number of bytes on destruction.
ReallyBigInputStream input;
- vector<string> errors;
+ std::vector<string> errors;
{
ScopedMemoryLog error_log;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/gzip_stream.cc b/third_party/protobuf/src/google/protobuf/io/gzip_stream.cc
index 9c621b6a27..a569eff0a7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/gzip_stream.cc
+++ b/third_party/protobuf/src/google/protobuf/io/gzip_stream.cc
@@ -168,7 +168,7 @@ void GzipInputStream::BackUp(int count) {
}
bool GzipInputStream::Skip(int count) {
const void* data;
- int size;
+ int size = 0;
bool ok = Next(&data, &size);
while (ok && (size < count)) {
count -= size;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/gzip_stream.h b/third_party/protobuf/src/google/protobuf/io/gzip_stream.h
index 15b02fe3d7..df1a446ebc 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/gzip_stream.h
+++ b/third_party/protobuf/src/google/protobuf/io/gzip_stream.h
@@ -118,7 +118,7 @@ class LIBPROTOBUF_EXPORT GzipOutputStream : public ZeroCopyOutputStream {
ZLIB = 2,
};
- struct Options {
+ struct LIBPROTOBUF_EXPORT Options {
// Defaults to GZIP.
Format format;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/gzip_stream_unittest.sh b/third_party/protobuf/src/google/protobuf/io/gzip_stream_unittest.sh
index 16251a94d3..16251a94d3 100755
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/gzip_stream_unittest.sh
+++ b/third_party/protobuf/src/google/protobuf/io/gzip_stream_unittest.sh
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/package_info.h b/third_party/protobuf/src/google/protobuf/io/package_info.h
index dc1fc91e5b..dc1fc91e5b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/package_info.h
+++ b/third_party/protobuf/src/google/protobuf/io/package_info.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/printer.cc b/third_party/protobuf/src/google/protobuf/io/printer.cc
index 7532b098bc..99e895f588 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/printer.cc
+++ b/third_party/protobuf/src/google/protobuf/io/printer.cc
@@ -70,8 +70,8 @@ Printer::~Printer() {
}
bool Printer::GetSubstitutionRange(const char* varname,
- pair<size_t, size_t>* range) {
- map<string, pair<size_t, size_t> >::const_iterator iter =
+ std::pair<size_t, size_t>* range) {
+ std::map<string, std::pair<size_t, size_t> >::const_iterator iter =
substitutions_.find(varname);
if (iter == substitutions_.end()) {
GOOGLE_LOG(DFATAL) << " Undefined variable in annotation: " << varname;
@@ -87,12 +87,12 @@ bool Printer::GetSubstitutionRange(const char* varname,
}
void Printer::Annotate(const char* begin_varname, const char* end_varname,
- const string& file_path, const vector<int>& path) {
+ const string& file_path, const std::vector<int>& path) {
if (annotation_collector_ == NULL) {
// Can't generate signatures with this Printer.
return;
}
- pair<size_t, size_t> begin, end;
+ std::pair<size_t, size_t> begin, end;
if (!GetSubstitutionRange(begin_varname, &begin) ||
!GetSubstitutionRange(end_varname, &end)) {
return;
@@ -106,7 +106,8 @@ void Printer::Annotate(const char* begin_varname, const char* end_varname,
}
}
-void Printer::Print(const map<string, string>& variables, const char* text) {
+void Printer::Print(const std::map<string, string>& variables,
+ const char* text) {
int size = strlen(text);
int pos = 0; // The number of bytes we've written so far.
substitutions_.clear();
@@ -143,14 +144,15 @@ void Printer::Print(const map<string, string>& variables, const char* text) {
WriteRaw(&variable_delimiter_, 1);
} else {
// Replace with the variable's value.
- map<string, string>::const_iterator iter = variables.find(varname);
+ std::map<string, string>::const_iterator iter = variables.find(varname);
if (iter == variables.end()) {
GOOGLE_LOG(DFATAL) << " Undefined variable: " << varname;
} else {
size_t begin = offset_;
WriteRaw(iter->second.data(), iter->second.size());
- pair<map<string, pair<size_t, size_t> >::iterator, bool> inserted =
- substitutions_.insert(
+ std::pair<std::map<string, std::pair<size_t, size_t> >::iterator,
+ bool>
+ inserted = substitutions_.insert(
std::make_pair(varname, std::make_pair(begin, offset_)));
if (!inserted.second) {
// This variable was used multiple times. Make its span have
@@ -172,13 +174,13 @@ void Printer::Print(const map<string, string>& variables, const char* text) {
}
void Printer::Print(const char* text) {
- static map<string, string> empty;
+ static std::map<string, string> empty;
Print(empty, text);
}
void Printer::Print(const char* text,
const char* variable, const string& value) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars[variable] = value;
Print(vars, text);
}
@@ -186,7 +188,7 @@ void Printer::Print(const char* text,
void Printer::Print(const char* text,
const char* variable1, const string& value1,
const char* variable2, const string& value2) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars[variable1] = value1;
vars[variable2] = value2;
Print(vars, text);
@@ -196,7 +198,7 @@ void Printer::Print(const char* text,
const char* variable1, const string& value1,
const char* variable2, const string& value2,
const char* variable3, const string& value3) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars[variable1] = value1;
vars[variable2] = value2;
vars[variable3] = value3;
@@ -208,7 +210,7 @@ void Printer::Print(const char* text,
const char* variable2, const string& value2,
const char* variable3, const string& value3,
const char* variable4, const string& value4) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars[variable1] = value1;
vars[variable2] = value2;
vars[variable3] = value3;
@@ -222,7 +224,7 @@ void Printer::Print(const char* text,
const char* variable3, const string& value3,
const char* variable4, const string& value4,
const char* variable5, const string& value5) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars[variable1] = value1;
vars[variable2] = value2;
vars[variable3] = value3;
@@ -238,7 +240,7 @@ void Printer::Print(const char* text,
const char* variable4, const string& value4,
const char* variable5, const string& value5,
const char* variable6, const string& value6) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars[variable1] = value1;
vars[variable2] = value2;
vars[variable3] = value3;
@@ -256,7 +258,7 @@ void Printer::Print(const char* text,
const char* variable5, const string& value5,
const char* variable6, const string& value6,
const char* variable7, const string& value7) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars[variable1] = value1;
vars[variable2] = value2;
vars[variable3] = value3;
@@ -276,7 +278,7 @@ void Printer::Print(const char* text,
const char* variable6, const string& value6,
const char* variable7, const string& value7,
const char* variable8, const string& value8) {
- map<string, string> vars;
+ std::map<string, string> vars;
vars[variable1] = value1;
vars[variable2] = value2;
vars[variable3] = value3;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/printer.h b/third_party/protobuf/src/google/protobuf/io/printer.h
index e78e2efdcc..e666445b6d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/printer.h
+++ b/third_party/protobuf/src/google/protobuf/io/printer.h
@@ -55,7 +55,7 @@ class LIBPROTOBUF_EXPORT AnnotationCollector {
// before end_offset are associated with the SourceCodeInfo-style path.
virtual void AddAnnotation(size_t begin_offset, size_t end_offset,
const string& file_path,
- const vector<int>& path) = 0;
+ const std::vector<int>& path) = 0;
virtual ~AnnotationCollector() {}
};
@@ -73,7 +73,8 @@ class AnnotationProtoCollector : public AnnotationCollector {
// Override for AnnotationCollector::AddAnnotation.
virtual void AddAnnotation(size_t begin_offset, size_t end_offset,
- const string& file_path, const vector<int>& path) {
+ const string& file_path,
+ const std::vector<int>& path) {
typename AnnotationProto::Annotation* annotation =
annotation_proto_->add_annotation();
for (int i = 0; i < path.size(); ++i) {
@@ -195,7 +196,7 @@ class LIBPROTOBUF_EXPORT Printer {
// of building the location path.
return;
}
- vector<int> path;
+ std::vector<int> path;
descriptor->GetLocationPath(&path);
Annotate(begin_varname, end_varname, descriptor->file()->name(), path);
}
@@ -216,7 +217,7 @@ class LIBPROTOBUF_EXPORT Printer {
// Annotations aren't turned on for this Printer.
return;
}
- vector<int> empty_path;
+ std::vector<int> empty_path;
Annotate(begin_varname, end_varname, file_name, empty_path);
}
@@ -225,7 +226,7 @@ class LIBPROTOBUF_EXPORT Printer {
// substituted are identified by their names surrounded by delimiter
// characters (as given to the constructor). The variable bindings are
// defined by the given map.
- void Print(const map<string, string>& variables, const char* text);
+ void Print(const std::map<string, string>& variables, const char* text);
// Like the first Print(), except the substitutions are given as parameters.
void Print(const char* text);
@@ -308,7 +309,7 @@ class LIBPROTOBUF_EXPORT Printer {
// substituted for end_varname. Note that begin_varname and end_varname
// may refer to the same variable.
void Annotate(const char* begin_varname, const char* end_varname,
- const string& file_path, const vector<int>& path);
+ const string& file_path, const std::vector<int>& path);
const char variable_delimiter_;
@@ -331,13 +332,14 @@ class LIBPROTOBUF_EXPORT Printer {
// start offset is the beginning of the substitution; the end offset is the
// last byte of the substitution plus one (such that (end - start) is the
// length of the substituted string).
- map<string, pair<size_t, size_t> > substitutions_;
+ std::map<string, std::pair<size_t, size_t> > substitutions_;
// Returns true and sets range to the substitution range in the output for
// varname if varname was used once in the last call to Print. If varname
// was not used, or if it was used multiple times, returns false (and
// fails a debug assertion).
- bool GetSubstitutionRange(const char* varname, pair<size_t, size_t>* range);
+ bool GetSubstitutionRange(const char* varname,
+ std::pair<size_t, size_t>* range);
// If non-null, annotation_collector_ is used to store annotations about
// generated code.
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/printer_unittest.cc b/third_party/protobuf/src/google/protobuf/io/printer_unittest.cc
index 95f3afa218..0435228a6f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/printer_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/io/printer_unittest.cc
@@ -121,7 +121,7 @@ TEST(Printer, VariableSubstitution) {
{
Printer printer(&output, '$');
- map<string, string> vars;
+ std::map<string, string> vars;
vars["foo"] = "World";
vars["bar"] = "$foo$";
@@ -187,7 +187,7 @@ class MockDescriptorFile {
// annotations.
class MockDescriptor {
public:
- MockDescriptor(const string& file, const vector<int>& path)
+ MockDescriptor(const string& file, const std::vector<int>& path)
: file_(file), path_(path) {}
// The mock file in which this descriptor was defined.
@@ -201,7 +201,7 @@ class MockDescriptor {
void GetLocationPath(std::vector<int>* output) const { *output = path_; }
MockDescriptorFile file_;
- vector<int> path_;
+ std::vector<int> path_;
};
TEST(Printer, AnnotateMap) {
@@ -211,13 +211,13 @@ TEST(Printer, AnnotateMap) {
AnnotationProtoCollector<GeneratedCodeInfo> info_collector(&info);
{
Printer printer(&output, '$', &info_collector);
- map<string, string> vars;
+ std::map<string, string> vars;
vars["foo"] = "3";
vars["bar"] = "5";
printer.Print(vars, "012$foo$4$bar$\n");
- vector<int> path_1;
+ std::vector<int> path_1;
path_1.push_back(33);
- vector<int> path_2;
+ std::vector<int> path_2;
path_2.push_back(11);
path_2.push_back(22);
MockDescriptor descriptor_1("path_1", path_1);
@@ -255,9 +255,9 @@ TEST(Printer, AnnotateInline) {
{
Printer printer(&output, '$', &info_collector);
printer.Print("012$foo$4$bar$\n", "foo", "3", "bar", "5");
- vector<int> path_1;
+ std::vector<int> path_1;
path_1.push_back(33);
- vector<int> path_2;
+ std::vector<int> path_2;
path_2.push_back(11);
path_2.push_back(22);
MockDescriptor descriptor_1("path_1", path_1);
@@ -295,7 +295,7 @@ TEST(Printer, AnnotateRange) {
{
Printer printer(&output, '$', &info_collector);
printer.Print("012$foo$4$bar$\n", "foo", "3", "bar", "5");
- vector<int> path;
+ std::vector<int> path;
path.push_back(33);
MockDescriptor descriptor("path", path);
printer.Annotate("foo", "bar", &descriptor);
@@ -320,7 +320,7 @@ TEST(Printer, AnnotateEmptyRange) {
Printer printer(&output, '$', &info_collector);
printer.Print("012$foo$4$baz$$bam$$bar$\n", "foo", "3", "bar", "5", "baz",
"", "bam", "");
- vector<int> path;
+ std::vector<int> path;
path.push_back(33);
MockDescriptor descriptor("path", path);
printer.Annotate("baz", "bam", &descriptor);
@@ -344,7 +344,7 @@ TEST(Printer, AnnotateDespiteUnrelatedMultipleUses) {
{
Printer printer(&output, '$', &info_collector);
printer.Print("012$foo$4$foo$$bar$\n", "foo", "3", "bar", "5");
- vector<int> path;
+ std::vector<int> path;
path.push_back(33);
MockDescriptor descriptor("path", path);
printer.Annotate("bar", "bar", &descriptor);
@@ -368,7 +368,7 @@ TEST(Printer, Indenting) {
{
Printer printer(&output, '$');
- map<string, string> vars;
+ std::map<string, string> vars;
vars["newline"] = "\n";
@@ -432,7 +432,7 @@ TEST(Printer, AnnotateMultipleUsesDeath) {
{
Printer printer(&output, '$', &info_collector);
printer.Print("012$foo$4$foo$\n", "foo", "3");
- vector<int> path;
+ std::vector<int> path;
path.push_back(33);
MockDescriptor descriptor("path", path);
EXPECT_DEBUG_DEATH(printer.Annotate("foo", "foo", &descriptor), "multiple");
@@ -447,7 +447,7 @@ TEST(Printer, AnnotateNegativeLengthDeath) {
{
Printer printer(&output, '$', &info_collector);
printer.Print("012$foo$4$bar$\n", "foo", "3", "bar", "5");
- vector<int> path;
+ std::vector<int> path;
path.push_back(33);
MockDescriptor descriptor("path", path);
EXPECT_DEBUG_DEATH(printer.Annotate("bar", "foo", &descriptor), "negative");
@@ -462,7 +462,7 @@ TEST(Printer, AnnotateUndefinedDeath) {
{
Printer printer(&output, '$', &info_collector);
printer.Print("012$foo$4$foo$\n", "foo", "3");
- vector<int> path;
+ std::vector<int> path;
path.push_back(33);
MockDescriptor descriptor("path", path);
EXPECT_DEBUG_DEATH(printer.Annotate("bar", "bar", &descriptor),
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/strtod.cc b/third_party/protobuf/src/google/protobuf/io/strtod.cc
index a90bb9a31e..a90bb9a31e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/strtod.cc
+++ b/third_party/protobuf/src/google/protobuf/io/strtod.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/strtod.h b/third_party/protobuf/src/google/protobuf/io/strtod.h
index f56e41c840..f56e41c840 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/strtod.h
+++ b/third_party/protobuf/src/google/protobuf/io/strtod.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/tokenizer.cc b/third_party/protobuf/src/google/protobuf/io/tokenizer.cc
index b3550dfbaf..916d1606b7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/tokenizer.cc
+++ b/third_party/protobuf/src/google/protobuf/io/tokenizer.cc
@@ -665,7 +665,7 @@ namespace {
class CommentCollector {
public:
CommentCollector(string* prev_trailing_comments,
- vector<string>* detached_comments,
+ std::vector<string>* detached_comments,
string* next_leading_comments)
: prev_trailing_comments_(prev_trailing_comments),
detached_comments_(detached_comments),
@@ -737,7 +737,7 @@ class CommentCollector {
private:
string* prev_trailing_comments_;
- vector<string>* detached_comments_;
+ std::vector<string>* detached_comments_;
string* next_leading_comments_;
string comment_buffer_;
@@ -757,7 +757,7 @@ class CommentCollector {
} // namespace
bool Tokenizer::NextWithComments(string* prev_trailing_comments,
- vector<string>* detached_comments,
+ std::vector<string>* detached_comments,
string* next_leading_comments) {
CommentCollector collector(prev_trailing_comments, detached_comments,
next_leading_comments);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/tokenizer.h b/third_party/protobuf/src/google/protobuf/io/tokenizer.h
index 77a873bce8..e80d564cd5 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/tokenizer.h
+++ b/third_party/protobuf/src/google/protobuf/io/tokenizer.h
@@ -191,7 +191,7 @@ class LIBPROTOBUF_EXPORT Tokenizer {
// * grault. */
// optional int32 grault = 6;
bool NextWithComments(string* prev_trailing_comments,
- vector<string>* detached_comments,
+ std::vector<string>* detached_comments,
string* next_leading_comments);
// Parse helpers ---------------------------------------------------
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/tokenizer_unittest.cc b/third_party/protobuf/src/google/protobuf/io/tokenizer_unittest.cc
index ae0811f892..cadeb69659 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/tokenizer_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/io/tokenizer_unittest.cc
@@ -199,8 +199,8 @@ struct SimpleTokenCase {
Tokenizer::TokenType type;
};
-inline ostream& operator<<(ostream& out,
- const SimpleTokenCase& test_case) {
+inline std::ostream& operator<<(std::ostream& out,
+ const SimpleTokenCase& test_case) {
return out << CEscape(test_case.input);
}
@@ -333,8 +333,8 @@ struct MultiTokenCase {
// needed.
};
-inline ostream& operator<<(ostream& out,
- const MultiTokenCase& test_case) {
+inline std::ostream& operator<<(std::ostream& out,
+ const MultiTokenCase& test_case) {
return out << CEscape(test_case.input);
}
@@ -520,8 +520,8 @@ struct DocCommentCase {
const char* next_leading_comments;
};
-inline ostream& operator<<(ostream& out,
- const DocCommentCase& test_case) {
+inline std::ostream& operator<<(std::ostream& out,
+ const DocCommentCase& test_case) {
return out << CEscape(test_case.input);
}
@@ -693,7 +693,7 @@ TEST_2D(TokenizerTest, DocComments, kDocCommentCases, kBlockSizes) {
EXPECT_EQ("prev", tokenizer2.current().text);
string prev_trailing_comments;
- vector<string> detached_comments;
+ std::vector<string> detached_comments;
string next_leading_comments;
tokenizer.NextWithComments(&prev_trailing_comments, &detached_comments,
&next_leading_comments);
@@ -860,8 +860,7 @@ struct ErrorCase {
const char* errors;
};
-inline ostream& operator<<(ostream& out,
- const ErrorCase& test_case) {
+inline std::ostream& operator<<(std::ostream& out, const ErrorCase& test_case) {
return out << CEscape(test_case.input);
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream.cc b/third_party/protobuf/src/google/protobuf/io/zero_copy_stream.cc
index 186de00141..186de00141 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream.cc
+++ b/third_party/protobuf/src/google/protobuf/io/zero_copy_stream.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream.h b/third_party/protobuf/src/google/protobuf/io/zero_copy_stream.h
index 52650fc668..52650fc668 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream.h
+++ b/third_party/protobuf/src/google/protobuf/io/zero_copy_stream.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream_impl.cc b/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc
index 452bd0f991..3ab5224a64 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream_impl.cc
+++ b/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc
@@ -44,9 +44,9 @@
#include <iostream>
#include <algorithm>
-#include <google/protobuf/io/io_win32.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/io_win32.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/stl_util.h>
@@ -271,10 +271,8 @@ bool FileOutputStream::CopyingFileOutputStream::Write(
// ===================================================================
-IstreamInputStream::IstreamInputStream(istream* input, int block_size)
- : copying_input_(input),
- impl_(&copying_input_, block_size) {
-}
+IstreamInputStream::IstreamInputStream(std::istream* input, int block_size)
+ : copying_input_(input), impl_(&copying_input_, block_size) {}
IstreamInputStream::~IstreamInputStream() {}
@@ -295,9 +293,8 @@ int64 IstreamInputStream::ByteCount() const {
}
IstreamInputStream::CopyingIstreamInputStream::CopyingIstreamInputStream(
- istream* input)
- : input_(input) {
-}
+ std::istream* input)
+ : input_(input) {}
IstreamInputStream::CopyingIstreamInputStream::~CopyingIstreamInputStream() {}
@@ -313,10 +310,8 @@ int IstreamInputStream::CopyingIstreamInputStream::Read(
// ===================================================================
-OstreamOutputStream::OstreamOutputStream(ostream* output, int block_size)
- : copying_output_(output),
- impl_(&copying_output_, block_size) {
-}
+OstreamOutputStream::OstreamOutputStream(std::ostream* output, int block_size)
+ : copying_output_(output), impl_(&copying_output_, block_size) {}
OstreamOutputStream::~OstreamOutputStream() {
impl_.Flush();
@@ -335,9 +330,8 @@ int64 OstreamOutputStream::ByteCount() const {
}
OstreamOutputStream::CopyingOstreamOutputStream::CopyingOstreamOutputStream(
- ostream* output)
- : output_(output) {
-}
+ std::ostream* output)
+ : output_(output) {}
OstreamOutputStream::CopyingOstreamOutputStream::~CopyingOstreamOutputStream() {
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream_impl.h b/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl.h
index 0746fa6afe..3365790e1a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream_impl.h
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream_impl_lite.cc b/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc
index e6ca88c21b..e6ca88c21b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream_impl_lite.cc
+++ b/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream_impl_lite.h b/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h
index e4d6a024dd..e4d6a024dd 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream_impl_lite.h
+++ b/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream_unittest.cc b/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_unittest.cc
index b2f545d6fd..a83e2b738e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/zero_copy_stream_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/io/zero_copy_stream_unittest.cc
@@ -65,7 +65,6 @@
#include <google/protobuf/testing/file.h>
#include <google/protobuf/io/coded_stream.h>
-#include <google/protobuf/io/io_win32.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#if HAVE_ZLIB
@@ -73,6 +72,7 @@
#endif
#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/io_win32.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/testing/googletest.h>
#include <google/protobuf/testing/file.h>
@@ -883,7 +883,7 @@ TEST_F(IoTest, IostreamIo) {
for (int i = 0; i < kBlockSizeCount; i++) {
for (int j = 0; j < kBlockSizeCount; j++) {
{
- stringstream stream;
+ std::stringstream stream;
{
OstreamOutputStream output(&stream, kBlockSizes[i]);
@@ -899,7 +899,7 @@ TEST_F(IoTest, IostreamIo) {
}
{
- stringstream stream;
+ std::stringstream stream;
{
OstreamOutputStream output(&stream, kBlockSizes[i]);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/lite_arena_unittest.cc b/third_party/protobuf/src/google/protobuf/lite_arena_unittest.cc
index f0bee880aa..f0bee880aa 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/lite_arena_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/lite_arena_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/lite_unittest.cc b/third_party/protobuf/src/google/protobuf/lite_unittest.cc
index 3ca3fbaf6e..3ca3fbaf6e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/lite_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/lite_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map.h b/third_party/protobuf/src/google/protobuf/map.h
index 1b9aa70332..e6d78b2069 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map.h
+++ b/third_party/protobuf/src/google/protobuf/map.h
@@ -28,6 +28,12 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// This file defines the map container and its helpers to support protobuf maps.
+//
+// The Map and MapIterator types are provided by this header file.
+// Please avoid using other types defined here, unless they are public
+// types within Map or MapIterator, such as Map::value_type.
+
#ifndef GOOGLE_PROTOBUF_MAP_H__
#define GOOGLE_PROTOBUF_MAP_H__
@@ -50,9 +56,6 @@
namespace google {
namespace protobuf {
-// The Map and MapIterator types are provided by this header file.
-// Please avoid using other types defined here, unless they are public
-// types within Map or MapIterator, such as Map::value_type.
template <typename Key, typename T>
class Map;
@@ -520,13 +523,13 @@ class Map {
typedef size_t size_type;
typedef hash<Key> hasher;
- explicit Map(bool old_style = true)
+ explicit Map(bool old_style = false)
: arena_(NULL),
default_enum_value_(0),
old_style_(old_style) {
Init();
}
- explicit Map(Arena* arena, bool old_style = true)
+ explicit Map(Arena* arena, bool old_style = false)
: arena_(arena),
default_enum_value_(0),
old_style_(old_style) {
@@ -540,7 +543,7 @@ class Map {
insert(other.begin(), other.end());
}
template <class InputIt>
- Map(const InputIt& first, const InputIt& last, bool old_style = true)
+ Map(const InputIt& first, const InputIt& last, bool old_style = false)
: arena_(NULL),
default_enum_value_(0),
old_style_(old_style) {
@@ -562,7 +565,7 @@ class Map {
void Init() {
if (old_style_)
deprecated_elements_ = Arena::Create<DeprecatedInnerMap>(
- arena_, 0, hasher(), equal_to<Key>(),
+ arena_, 0, hasher(), std::equal_to<Key>(),
MapAllocator<std::pair<const Key, MapPair<Key, T>*> >(arena_));
else
elements_ =
@@ -589,11 +592,11 @@ class Map {
MapAllocator(const MapAllocator<X>& allocator)
: arena_(allocator.arena()) {}
- pointer allocate(size_type n, const_pointer hint = 0) {
+ pointer allocate(size_type n, const void* hint = 0) {
// If arena is not given, malloc needs to be called which doesn't
// construct element object.
if (arena_ == NULL) {
- return reinterpret_cast<pointer>(malloc(n * sizeof(value_type)));
+ return static_cast<pointer>(::operator new(n * sizeof(value_type)));
} else {
return reinterpret_cast<pointer>(
Arena::CreateArray<uint8>(arena_, n * sizeof(value_type)));
@@ -602,13 +605,16 @@ 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
}
}
#if __cplusplus >= 201103L && !defined(GOOGLE_PROTOBUF_OS_APPLE) && \
!defined(GOOGLE_PROTOBUF_OS_NACL) && \
- !defined(GOOGLE_PROTOBUF_OS_ANDROID) && \
!defined(GOOGLE_PROTOBUF_OS_EMSCRIPTEN)
template<class NodeType, class... Args>
void construct(NodeType* p, Args&&... args) {
@@ -647,7 +653,8 @@ class Map {
// To support Visual Studio 2008
size_type max_size() const {
- return std::numeric_limits<size_type>::max();
+ // parentheses around (std::...:max) prevents macro warning of max()
+ return (std::numeric_limits<size_type>::max)();
}
// To support gcc-4.4, which does not properly
@@ -1077,8 +1084,9 @@ class Map {
// index_of_first_non_null_, so we skip the code to update it.
return InsertUniqueInTree(b, node);
}
+ // parentheses around (std::min) prevents macro expansion of min(...)
index_of_first_non_null_ =
- std::min(index_of_first_non_null_, result.bucket_index_);
+ (std::min)(index_of_first_non_null_, result.bucket_index_);
return result;
}
@@ -1282,7 +1290,9 @@ class Map {
// Return a power of two no less than max(kMinTableSize, n).
// Assumes either n < kMinTableSize or n is a power of two.
size_type TableSize(size_type n) {
- return n < kMinTableSize ? kMinTableSize : n;
+ return n < static_cast<size_type>(kMinTableSize)
+ ? static_cast<size_type>(kMinTableSize)
+ : n;
}
// Use alloc_ to allocate an array of n objects of type U.
@@ -1348,7 +1358,7 @@ class Map {
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(InnerMap);
}; // end of class InnerMap
- typedef hash_map<Key, value_type*, hash<Key>, equal_to<Key>,
+ typedef hash_map<Key, value_type*, hash<Key>, std::equal_to<Key>,
MapAllocator<std::pair<const Key, MapPair<Key, T>*> > >
DeprecatedInnerMap;
@@ -1525,8 +1535,9 @@ class Map {
// Lookup
size_type count(const key_type& key) const {
- if (find(key) != end()) assert(key == find(key)->first);
- return find(key) == end() ? 0 : 1;
+ const_iterator it = find(key);
+ GOOGLE_DCHECK(it == end() || key == it->first);
+ return it == end() ? 0 : 1;
}
const_iterator find(const key_type& key) const {
return old_style_ ? const_iterator(deprecated_elements_->find(key))
@@ -1717,12 +1728,19 @@ struct hash<google::protobuf::MapKey> {
break;
case google::protobuf::FieldDescriptor::CPPTYPE_STRING:
return hash<string>()(map_key.GetStringValue());
+#if defined(GOOGLE_PROTOBUF_HAVE_64BIT_HASH)
case google::protobuf::FieldDescriptor::CPPTYPE_INT64:
return hash< ::google::protobuf::int64>()(map_key.GetInt64Value());
- case google::protobuf::FieldDescriptor::CPPTYPE_INT32:
- return hash< ::google::protobuf::int32>()(map_key.GetInt32Value());
case google::protobuf::FieldDescriptor::CPPTYPE_UINT64:
return hash< ::google::protobuf::uint64>()(map_key.GetUInt64Value());
+#else
+ case google::protobuf::FieldDescriptor::CPPTYPE_INT64:
+ case google::protobuf::FieldDescriptor::CPPTYPE_UINT64:
+ GOOGLE_LOG(FATAL) << "Unsupported on this platform.";
+ break;
+#endif
+ case google::protobuf::FieldDescriptor::CPPTYPE_INT32:
+ return hash< ::google::protobuf::int32>()(map_key.GetInt32Value());
case google::protobuf::FieldDescriptor::CPPTYPE_UINT32:
return hash< ::google::protobuf::uint32>()(map_key.GetUInt32Value());
case google::protobuf::FieldDescriptor::CPPTYPE_BOOL:
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_entry.h b/third_party/protobuf/src/google/protobuf/map_entry.h
index e87eda6498..d7db9b0f72 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_entry.h
+++ b/third_party/protobuf/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 {
@@ -244,14 +244,18 @@ class MapEntry : public MapEntryBase {
// to distinguish instances of the same MapEntry class.
static MapEntry* CreateDefaultInstance(const Descriptor* descriptor) {
MapEntry* entry = new MapEntry;
- const Reflection* reflection = new GeneratedMessageReflection(
- descriptor, entry, offsets_,
+ ReflectionSchema schema = {
+ entry,
+ offsets_,
+ has_bits_,
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_._has_bits_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, _unknown_fields_), -1,
- DescriptorPool::generated_pool(),
- ::google::protobuf::MessageFactory::generated_factory(),
- sizeof(MapEntry),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, _internal_metadata_));
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, _internal_metadata_),
+ -1,
+ -1,
+ sizeof(MapEntry)};
+ const Reflection* reflection = new GeneratedMessageReflection(
+ descriptor, schema, DescriptorPool::generated_pool(),
+ MessageFactory::generated_factory());
entry->descriptor_ = descriptor;
entry->reflection_ = reflection;
entry->set_default_instance(entry);
@@ -278,8 +282,8 @@ class MapEntry : public MapEntryBase {
entry_lite_.set_default_instance(&default_instance->entry_lite_);
}
- static int offsets_[2];
- UnknownFieldSet _unknown_fields_;
+ static uint32 offsets_[2];
+ static uint32 has_bits_[2];
InternalMetadataWithArena _internal_metadata_;
MapEntry* default_instance_;
EntryLiteType entry_lite_;
@@ -297,12 +301,17 @@ class MapEntry : public MapEntryBase {
template <typename Key, typename Value, WireFormatLite::FieldType kKeyFieldType,
WireFormatLite::FieldType kValueFieldType, int default_enum_value>
-int MapEntry<Key, Value, kKeyFieldType, kValueFieldType,
+uint32 MapEntry<Key, Value, kKeyFieldType, kValueFieldType,
default_enum_value>::offsets_[2] = {
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_.key_),
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_.value_),
};
+template <typename Key, typename Value, WireFormatLite::FieldType kKeyFieldType,
+ WireFormatLite::FieldType kValueFieldType, int default_enum_value>
+uint32 MapEntry<Key, Value, kKeyFieldType, kValueFieldType,
+ default_enum_value>::has_bits_[2] = {0, 1};
+
} // namespace internal
} // namespace protobuf
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_entry_lite.h b/third_party/protobuf/src/google/protobuf/map_entry_lite.h
index 4dedfd5702..1243911bcb 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_entry_lite.h
+++ b/third_party/protobuf/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() {
@@ -171,7 +171,7 @@ class MapEntryLite : public MessageLite {
// need to care whether the value is unknown enum;
// 4) missing key/value: missed key/value will have default value. caller
// should take this entry as if key/value is set to default value.
- tag = input->ReadTag();
+ tag = input->ReadTagNoLastTag();
switch (tag) {
case kKeyTag:
if (!KeyTypeHandler::Read(input, mutable_key())) {
@@ -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;
@@ -221,9 +221,8 @@ class MapEntryLite : public MessageLite {
deterministic, output);
return output;
}
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
- }
+
+ // Don't override SerializeWithCachedSizesToArray. Use MessageLite's.
int GetCachedSize() const {
int size = 0;
@@ -333,7 +332,7 @@ class MapEntryLite : public MessageLite {
int size;
input->GetDirectBufferPointerInline(&data, &size);
// We could use memcmp here, but we don't bother. The tag is one byte.
- assert(kTagSize == 1);
+ GOOGLE_COMPILE_ASSERT(kTagSize == 1, tag_size_error);
if (size > 0 && *reinterpret_cast<const char*>(data) == kValueTag) {
typename Map::size_type size = map_->size();
value_ptr_ = &(*map_)[key_];
@@ -357,15 +356,17 @@ class MapEntryLite : public MessageLite {
entry_.reset(mf_->NewEntry());
*entry_->mutable_key() = key_;
- if (!entry_->MergePartialFromCodedStream(input)) return false;
- return UseKeyAndValueFromEntry();
+ const bool result = entry_->MergePartialFromCodedStream(input);
+ if (result) UseKeyAndValueFromEntry();
+ if (entry_->GetArena() != NULL) entry_.release();
+ return result;
}
const Key& key() const { return key_; }
const Value& value() const { return *value_ptr_; }
private:
- bool UseKeyAndValueFromEntry() GOOGLE_ATTRIBUTE_COLD {
+ void UseKeyAndValueFromEntry() GOOGLE_ATTRIBUTE_COLD {
// Update key_ in case we need it later (because key() is called).
// This is potentially inefficient, especially if the key is
// expensive to copy (e.g., a long string), but this is a cold
@@ -377,8 +378,6 @@ class MapEntryLite : public MessageLite {
ValueTypeHandler::kWireType ==
WireFormatLite::WIRETYPE_LENGTH_DELIMITED,
Value>::Move(entry_->mutable_value(), value_ptr_);
- if (entry_->GetArena() != NULL) entry_.release();
- return true;
}
// After reading a key and value successfully, and inserting that data
@@ -400,15 +399,18 @@ class MapEntryLite : public MessageLite {
ValueMover::Move(value_ptr_, entry_->mutable_value());
map_->erase(key_);
KeyMover::Move(&key_, entry_->mutable_key());
- if (!entry_->MergePartialFromCodedStream(input)) return false;
- return UseKeyAndValueFromEntry();
+ const bool result = entry_->MergePartialFromCodedStream(input);
+ if (result) UseKeyAndValueFromEntry();
+ if (entry_->GetArena() != NULL) entry_.release();
+ return result;
}
MapField* const mf_;
Map* const map_;
Key key_;
Value* value_ptr_;
- // On the fast path entry_ is not used.
+ // On the fast path entry_ is not used. And, when entry_ is used, it's set
+ // to mf_->NewEntry(), so in the arena case we must call entry_.release.
google::protobuf::scoped_ptr<MapEntryLite> entry_;
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_field.cc b/third_party/protobuf/src/google/protobuf/map_field.cc
index 49f918181f..49f918181f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_field.cc
+++ b/third_party/protobuf/src/google/protobuf/map_field.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_field.h b/third_party/protobuf/src/google/protobuf/map_field.h
index d6af8532d2..d6af8532d2 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_field.h
+++ b/third_party/protobuf/src/google/protobuf/map_field.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_field_inl.h b/third_party/protobuf/src/google/protobuf/map_field_inl.h
index 01c9b89aab..2d84b0a3c2 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_field_inl.h
+++ b/third_party/protobuf/src/google/protobuf/map_field_inl.h
@@ -339,9 +339,9 @@ MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::Swap(
MapFieldLiteType* other) {
MapField* down_other = down_cast<MapField*>(other);
- std::swap(MapFieldBase::repeated_field_, down_other->repeated_field_);
+ std::swap(this->MapFieldBase::repeated_field_, down_other->repeated_field_);
MapFieldLiteType::Swap(other);
- std::swap(MapFieldBase::state_, down_other->state_);
+ std::swap(this->MapFieldBase::state_, down_other->state_);
}
template <typename Key, typename T,
@@ -352,7 +352,7 @@ void
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::SetEntryDescriptor(
const Descriptor** descriptor) {
- MapFieldBase::entry_descriptor_ = descriptor;
+ this->MapFieldBase::entry_descriptor_ = descriptor;
}
template <typename Key, typename T,
@@ -362,7 +362,7 @@ template <typename Key, typename T,
void
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::SetAssignDescriptorCallback(void (*callback)()) {
- MapFieldBase::assign_descriptor_callback_ = callback;
+ this->MapFieldBase::assign_descriptor_callback_ = callback;
}
template <typename Key, typename T,
@@ -392,19 +392,19 @@ template <typename Key, typename T,
void
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::SyncRepeatedFieldWithMapNoLock() const {
- if (MapFieldBase::repeated_field_ == NULL) {
- if (MapFieldBase::arena_ == NULL) {
- MapFieldBase::repeated_field_ = new RepeatedPtrField<Message>();
+ if (this->MapFieldBase::repeated_field_ == NULL) {
+ if (this->MapFieldBase::arena_ == NULL) {
+ this->MapFieldBase::repeated_field_ = new RepeatedPtrField<Message>();
} else {
- MapFieldBase::repeated_field_ =
+ this->MapFieldBase::repeated_field_ =
Arena::CreateMessage<RepeatedPtrField<Message> >(
- MapFieldBase::arena_);
+ this->MapFieldBase::arena_);
}
}
const Map<Key, T>& map = GetInternalMap();
RepeatedPtrField<EntryType>* repeated_field =
reinterpret_cast<RepeatedPtrField<EntryType>*>(
- MapFieldBase::repeated_field_);
+ this->MapFieldBase::repeated_field_);
repeated_field->Clear();
@@ -413,7 +413,7 @@ MapField<Key, T, kKeyFieldType, kValueFieldType,
InitDefaultEntryOnce();
GOOGLE_CHECK(default_entry_ != NULL);
EntryType* new_entry =
- down_cast<EntryType*>(default_entry_->New(MapFieldBase::arena_));
+ down_cast<EntryType*>(default_entry_->New(this->MapFieldBase::arena_));
repeated_field->AddAllocated(new_entry);
(*new_entry->mutable_key()) = it->first;
(*new_entry->mutable_value()) = it->second;
@@ -430,8 +430,8 @@ MapField<Key, T, kKeyFieldType, kValueFieldType,
Map<Key, T>* map = const_cast<MapField*>(this)->MutableInternalMap();
RepeatedPtrField<EntryType>* repeated_field =
reinterpret_cast<RepeatedPtrField<EntryType>*>(
- MapFieldBase::repeated_field_);
- GOOGLE_CHECK(MapFieldBase::repeated_field_ != NULL);
+ this->MapFieldBase::repeated_field_);
+ GOOGLE_CHECK(this->MapFieldBase::repeated_field_ != NULL);
map->clear();
for (typename RepeatedPtrField<EntryType>::iterator it =
repeated_field->begin(); it != repeated_field->end(); ++it) {
@@ -452,8 +452,8 @@ int
MapField<Key, T, kKeyFieldType, kValueFieldType,
default_enum_value>::SpaceUsedExcludingSelfNoLock() const {
int size = 0;
- if (MapFieldBase::repeated_field_ != NULL) {
- size += MapFieldBase::repeated_field_->SpaceUsedExcludingSelf();
+ if (this->MapFieldBase::repeated_field_ != NULL) {
+ size += this->MapFieldBase::repeated_field_->SpaceUsedExcludingSelf();
}
Map<Key, T>* map = const_cast<MapField*>(this)->MutableInternalMap();
size += sizeof(*map);
@@ -475,10 +475,10 @@ MapField<Key, T, kKeyFieldType, kValueFieldType,
const {
if (default_entry_ == NULL) {
MapFieldBase::InitMetadataOnce();
- GOOGLE_CHECK(*MapFieldBase::entry_descriptor_ != NULL);
+ GOOGLE_CHECK(*this->MapFieldBase::entry_descriptor_ != NULL);
default_entry_ = down_cast<const EntryType*>(
MessageFactory::generated_factory()->GetPrototype(
- *MapFieldBase::entry_descriptor_));
+ *this->MapFieldBase::entry_descriptor_));
}
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_field_lite.h b/third_party/protobuf/src/google/protobuf/map_field_lite.h
index a9f30f593c..cb0a4a450b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_field_lite.h
+++ b/third_party/protobuf/src/google/protobuf/map_field_lite.h
@@ -68,13 +68,14 @@ class MapFieldLite {
// Set default enum value only for proto2 map field whose value is enum type.
void SetDefaultEnumValue();
- // Used in the implementation of parsing. Caller should take the ownership.
+ // Used in the implementation of parsing. Caller should take the ownership iff
+ // arena_ is NULL.
EntryType* NewEntry() const;
// Used in the implementation of serializing enum value type. Caller should
- // take the ownership.
+ // take the ownership iff arena_ is NULL.
EntryType* NewEnumEntryWrapper(const Key& key, const T t) const;
// Used in the implementation of serializing other value types. Caller should
- // take the ownership.
+ // take the ownership iff arena_ is NULL.
EntryType* NewEntryWrapper(const Key& key, const T& t) const;
protected:
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_field_test.cc b/third_party/protobuf/src/google/protobuf/map_field_test.cc
index dd5061c498..dd5061c498 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_field_test.cc
+++ b/third_party/protobuf/src/google/protobuf/map_field_test.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_lite_test_util.cc b/third_party/protobuf/src/google/protobuf/map_lite_test_util.cc
index b65b4d6301..b65b4d6301 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_lite_test_util.cc
+++ b/third_party/protobuf/src/google/protobuf/map_lite_test_util.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_lite_test_util.h b/third_party/protobuf/src/google/protobuf/map_lite_test_util.h
index 66dedde5db..66dedde5db 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_lite_test_util.h
+++ b/third_party/protobuf/src/google/protobuf/map_lite_test_util.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_lite_unittest.proto b/third_party/protobuf/src/google/protobuf/map_lite_unittest.proto
index 0135fff305..0135fff305 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_lite_unittest.proto
+++ b/third_party/protobuf/src/google/protobuf/map_lite_unittest.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_proto2_unittest.proto b/third_party/protobuf/src/google/protobuf/map_proto2_unittest.proto
index ddc2a58247..e9360a5a68 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_proto2_unittest.proto
+++ b/third_party/protobuf/src/google/protobuf/map_proto2_unittest.proto
@@ -29,7 +29,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax = "proto2";
-
+option cc_enable_arenas = true;
import "google/protobuf/unittest_import.proto";
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_test.cc b/third_party/protobuf/src/google/protobuf/map_test.cc
index 03954e75f1..43fe0f4447 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_test.cc
+++ b/third_party/protobuf/src/google/protobuf/map_test.cc
@@ -91,6 +91,10 @@ using google::protobuf::unittest::TestRecursiveMapMessage;
namespace protobuf {
namespace internal {
+void MapTestForceDeterministic() {
+ ::google::protobuf::io::CodedOutputStream::SetDefaultSerializationDeterministic();
+}
+
// Map API Test =====================================================
// Parameterized tests on whether to use old style maps.
@@ -298,7 +302,7 @@ TEST_P(MapImplTest, IteratorBasic) {
template <typename Iterator>
static int64 median(Iterator i0, Iterator i1) {
- vector<int64> v(i0, i1);
+ std::vector<int64> v(i0, i1);
std::nth_element(v.begin(), v.begin() + v.size() / 2, v.end());
return v[v.size() / 2];
}
@@ -334,7 +338,7 @@ TEST_P(MapImplTest, BeginIsFast) {
GOOGLE_DCHECK_GE(last_key, 0);
map[last_key] = last_key ^ 1;
}
- vector<int64> times;
+ std::vector<int64> times;
// We're going to do map.erase(map.begin()) over and over again. But,
// just in case one iteration is fast compared to the granularity of
// our time keeping, we measure kChunkSize iterations per outer-loop iter.
@@ -379,7 +383,7 @@ TEST_P(MapImplTest, HashFlood) {
// 1024 (or 512 or 2048 or ...) entries. This assumes that map_ uses powers
// of 2 for table sizes, and that it's sufficient to "flood" with respect to
// the low bits of the output of map_.hash_function().
- vector<int64> times;
+ std::vector<int64> times;
std::set<int>::iterator it = s.begin();
int count = 0;
do {
@@ -506,7 +510,7 @@ static void StressTestIterators(int n, bool test_old_style_proto2_maps) {
// Finally, ensure erase(iterator) doesn't reorder anything, because that is
// what its documentation says.
m[last_key] = m[last_key ^ 999] = 0;
- vector<Map<int, int>::iterator> v;
+ std::vector<Map<int, int>::iterator> v;
v.reserve(m.size());
int position_of_last_key = 0;
for (Map<int, int>::iterator it = m.begin(); it != m.end(); ++it) {
@@ -563,7 +567,7 @@ TEST_P(MapImplTest, EraseRevalidates) {
map_[3] = map_[13] = map_[20] = 0;
const int initial_size = map_.size();
EXPECT_EQ(3, initial_size);
- vector<Map<int, int>::iterator> v;
+ std::vector<Map<int, int>::iterator> v;
for (Map<int, int>::iterator it = map_.begin(); it != map_.end(); ++it) {
v.push_back(it);
}
@@ -2437,7 +2441,7 @@ TEST(GeneratedMapFieldReflectionTest, SwapFields) {
MapTestUtil::SetMapFields(&message2);
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
const Reflection* reflection = message1.GetReflection();
reflection->ListFields(message2, &fields);
reflection->SwapFields(&message1, &message2, fields);
@@ -2844,7 +2848,7 @@ TEST(WireFormatForMapFieldTest, MapParseHelpers) {
{
// Test ParseFromIstream.
protobuf_unittest::TestMap message;
- stringstream stream(data);
+ std::stringstream stream(data);
EXPECT_TRUE(message.ParseFromIstream(&stream));
EXPECT_TRUE(stream.eof());
MapTestUtil::ExpectMapFieldsSet(message);
@@ -2873,6 +2877,33 @@ TEST(WireFormatForMapFieldTest, MapParseHelpers) {
// Deterministic Serialization Test ==========================================
template <typename T>
+static string DeterministicSerializationWithSerializePartialToCodedStream(
+ const T& t) {
+ const int size = t.ByteSize();
+ string result(size, '\0');
+ io::ArrayOutputStream array_stream(string_as_array(&result), size);
+ io::CodedOutputStream output_stream(&array_stream);
+ output_stream.SetSerializationDeterministic(true);
+ t.SerializePartialToCodedStream(&output_stream);
+ EXPECT_FALSE(output_stream.HadError());
+ EXPECT_EQ(size, output_stream.ByteCount());
+ return result;
+}
+
+template <typename T>
+static string DeterministicSerializationWithSerializeToCodedStream(const T& t) {
+ const int size = t.ByteSize();
+ string result(size, '\0');
+ io::ArrayOutputStream array_stream(string_as_array(&result), size);
+ io::CodedOutputStream output_stream(&array_stream);
+ output_stream.SetSerializationDeterministic(true);
+ t.SerializeToCodedStream(&output_stream);
+ EXPECT_FALSE(output_stream.HadError());
+ EXPECT_EQ(size, output_stream.ByteCount());
+ return result;
+}
+
+template <typename T>
static string DeterministicSerialization(const T& t) {
const int size = t.ByteSize();
string result(size, '\0');
@@ -2882,6 +2913,9 @@ static string DeterministicSerialization(const T& t) {
t.SerializeWithCachedSizes(&output_stream);
EXPECT_FALSE(output_stream.HadError());
EXPECT_EQ(size, output_stream.ByteCount());
+ EXPECT_EQ(result, DeterministicSerializationWithSerializeToCodedStream(t));
+ EXPECT_EQ(result,
+ DeterministicSerializationWithSerializePartialToCodedStream(t));
return result;
}
@@ -2983,6 +3017,18 @@ TEST(TextFormatMapTest, Sorted) {
EXPECT_EQ(message2.DebugString(), expected_text);
}
+TEST(TextFormatMapTest, ParseCorruptedString) {
+ string serialized_message;
+ GOOGLE_CHECK_OK(File::GetContents(
+ TestSourceDir() +
+ "/google/protobuf/testdata/golden_message_maps",
+ &serialized_message, true));
+ protobuf_unittest::TestMaps message;
+ GOOGLE_CHECK(message.ParseFromString(serialized_message));
+ TestParseCorruptedString<protobuf_unittest::TestMaps, true>(message);
+ TestParseCorruptedString<protobuf_unittest::TestMaps, false>(message);
+}
+
// arena support =================================================
TEST(ArenaTest, ParsingAndSerializingNoHeapAllocation) {
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_test_util.cc b/third_party/protobuf/src/google/protobuf/map_test_util.cc
index ae094647bb..3dd6aae555 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_test_util.cc
+++ b/third_party/protobuf/src/google/protobuf/map_test_util.cc
@@ -867,7 +867,7 @@ void MapReflectionTester::RemoveLastMapsViaReflection(
Message* message) {
const Reflection* reflection = message->GetReflection();
- vector<const FieldDescriptor*> output;
+ std::vector<const FieldDescriptor*> output;
reflection->ListFields(*message, &output);
for (int i = 0; i < output.size(); ++i) {
const FieldDescriptor* field = output[i];
@@ -880,7 +880,7 @@ void MapReflectionTester::ReleaseLastMapsViaReflection(
Message* message) {
const Reflection* reflection = message->GetReflection();
- vector<const FieldDescriptor*> output;
+ std::vector<const FieldDescriptor*> output;
reflection->ListFields(*message, &output);
for (int i = 0; i < output.size(); ++i) {
const FieldDescriptor* field = output[i];
@@ -896,7 +896,7 @@ void MapReflectionTester::ReleaseLastMapsViaReflection(
void MapReflectionTester::SwapMapsViaReflection(Message* message) {
const Reflection* reflection = message->GetReflection();
- vector<const FieldDescriptor*> output;
+ std::vector<const FieldDescriptor*> output;
reflection->ListFields(*message, &output);
for (int i = 0; i < output.size(); ++i) {
const FieldDescriptor* field = output[i];
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_test_util.h b/third_party/protobuf/src/google/protobuf/map_test_util.h
index deaf0f4f4b..deaf0f4f4b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_test_util.h
+++ b/third_party/protobuf/src/google/protobuf/map_test_util.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_test_util_impl.h b/third_party/protobuf/src/google/protobuf/map_test_util_impl.h
index b3ba4e0699..b3ba4e0699 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_test_util_impl.h
+++ b/third_party/protobuf/src/google/protobuf/map_test_util_impl.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_type_handler.h b/third_party/protobuf/src/google/protobuf/map_type_handler.h
index 685a770fb9..ac987cbc1c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_type_handler.h
+++ b/third_party/protobuf/src/google/protobuf/map_type_handler.h
@@ -158,7 +158,7 @@ class MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type> {
MapWireFieldTypeTraits<WireFormatLite::TYPE_MESSAGE, Type>::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 <typename Type>
-inline int
+inline size_t
MapTypeHandler<WireFormatLite::TYPE_MESSAGE, Type>::ByteSize(
const MapEntryAccessorType& value) {
return WireFormatLite::MessageSizeNoVirtual(value);
@@ -556,7 +556,7 @@ inline bool MapTypeHandler<WireFormatLite::TYPE_MESSAGE,
Type>::MapEntryAccessorType& \
MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
Type>::GetExternalReference(const TypeOnMemory& value) { \
- return value.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); \
+ return value.Get(); \
} \
template <typename Type> \
inline int \
@@ -581,11 +581,9 @@ inline bool MapTypeHandler<WireFormatLite::TYPE_MESSAGE,
arena); \
} \
template <typename Type> \
- inline void \
- MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
- Type>::ClearMaybeByDefaultEnum(TypeOnMemory* value, \
- Arena* arena, \
- int default_enum) { \
+ inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>:: \
+ ClearMaybeByDefaultEnum(TypeOnMemory* value, Arena* arena, \
+ int default_enum) { \
Clear(value, arena); \
} \
template <typename Type> \
@@ -609,11 +607,9 @@ inline bool MapTypeHandler<WireFormatLite::TYPE_MESSAGE,
&::google::protobuf::internal::GetEmptyStringAlreadyInited()); \
} \
template <typename Type> \
- inline void \
- MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
- Type>::InitializeMaybeByDefaultEnum(TypeOnMemory* value, \
- int default_enum_value, \
- Arena* arena) { \
+ inline void MapTypeHandler<WireFormatLite::TYPE_##FieldType, Type>:: \
+ InitializeMaybeByDefaultEnum(TypeOnMemory* value, \
+ int default_enum_value, Arena* arena) { \
Initialize(value, arena); \
} \
template <typename Type> \
@@ -631,7 +627,7 @@ inline bool MapTypeHandler<WireFormatLite::TYPE_MESSAGE,
Type>::DefaultIfNotInitialized(const TypeOnMemory& value, \
const TypeOnMemory& \
default_value) { \
- return value.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); \
+ return value.Get(); \
} \
template <typename Type> \
inline bool MapTypeHandler<WireFormatLite::TYPE_##FieldType, \
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/map_unittest.proto b/third_party/protobuf/src/google/protobuf/map_unittest.proto
index c6154f040a..c6154f040a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/map_unittest.proto
+++ b/third_party/protobuf/src/google/protobuf/map_unittest.proto
diff --git a/third_party/protobuf/src/google/protobuf/map_unittest_proto3.proto b/third_party/protobuf/src/google/protobuf/map_unittest_proto3.proto
new file mode 100644
index 0000000000..16be277304
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/map_unittest_proto3.proto
@@ -0,0 +1,120 @@
+// 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.
+
+// This file is mostly equivalent to map_unittest.proto, but imports
+// unittest_proto3.proto instead of unittest.proto, so that it only
+// uses proto3 messages. This makes it suitable for testing
+// implementations which only support proto3.
+// The TestRequiredMessageMap message has been removed as there are no
+// required fields in proto3.
+syntax = "proto3";
+
+option cc_enable_arenas = true;
+option csharp_namespace = "Google.Protobuf.TestProtos";
+
+import "google/protobuf/unittest_proto3.proto";
+
+// We don't put this in a package within proto2 because we need to make sure
+// that the generated code doesn't depend on being in the proto2 namespace.
+// In map_test_util.h we do "using namespace unittest = protobuf_unittest".
+package protobuf_unittest;
+
+// Tests maps.
+message TestMap {
+ map<int32 , int32 > map_int32_int32 = 1;
+ map<int64 , int64 > map_int64_int64 = 2;
+ map<uint32 , uint32 > map_uint32_uint32 = 3;
+ map<uint64 , uint64 > map_uint64_uint64 = 4;
+ map<sint32 , sint32 > map_sint32_sint32 = 5;
+ map<sint64 , sint64 > map_sint64_sint64 = 6;
+ map<fixed32 , fixed32 > map_fixed32_fixed32 = 7;
+ map<fixed64 , fixed64 > map_fixed64_fixed64 = 8;
+ map<sfixed32, sfixed32> map_sfixed32_sfixed32 = 9;
+ map<sfixed64, sfixed64> map_sfixed64_sfixed64 = 10;
+ map<int32 , float > map_int32_float = 11;
+ map<int32 , double > map_int32_double = 12;
+ map<bool , bool > map_bool_bool = 13;
+ map<string , string > map_string_string = 14;
+ map<int32 , bytes > map_int32_bytes = 15;
+ map<int32 , MapEnum > map_int32_enum = 16;
+ map<int32 , ForeignMessage> map_int32_foreign_message = 17;
+}
+
+message TestMapSubmessage {
+ TestMap test_map = 1;
+}
+
+message TestMessageMap {
+ map<int32, TestAllTypes> map_int32_message = 1;
+}
+
+// Two map fields share the same entry default instance.
+message TestSameTypeMap {
+ map<int32, int32> map1 = 1;
+ map<int32, int32> map2 = 2;
+}
+
+enum MapEnum {
+ MAP_ENUM_FOO = 0;
+ MAP_ENUM_BAR = 1;
+ MAP_ENUM_BAZ = 2;
+}
+
+message TestArenaMap {
+ map<int32 , int32 > map_int32_int32 = 1;
+ map<int64 , int64 > map_int64_int64 = 2;
+ map<uint32 , uint32 > map_uint32_uint32 = 3;
+ map<uint64 , uint64 > map_uint64_uint64 = 4;
+ map<sint32 , sint32 > map_sint32_sint32 = 5;
+ map<sint64 , sint64 > map_sint64_sint64 = 6;
+ map<fixed32 , fixed32 > map_fixed32_fixed32 = 7;
+ map<fixed64 , fixed64 > map_fixed64_fixed64 = 8;
+ map<sfixed32, sfixed32> map_sfixed32_sfixed32 = 9;
+ map<sfixed64, sfixed64> map_sfixed64_sfixed64 = 10;
+ map<int32 , float > map_int32_float = 11;
+ map<int32 , double > map_int32_double = 12;
+ map<bool , bool > map_bool_bool = 13;
+ map<int32 , MapEnum > map_int32_enum = 14;
+ map<int32 , ForeignMessage> map_int32_foreign_message = 15;
+}
+
+// Previously, message containing enum called Type cannot be used as value of
+// map field.
+message MessageContainingEnumCalledType {
+ enum Type {
+ TYPE_FOO = 0;
+ }
+ map<int32, MessageContainingEnumCalledType> type = 1;
+}
+
+// Previously, message cannot contain map field called "entry".
+message MessageContainingMapCalledEntry {
+ map<int32, int32> entry = 1;
+}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/message.cc b/third_party/protobuf/src/google/protobuf/message.cc
index f18077dd20..6800e4cd55 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/message.cc
+++ b/third_party/protobuf/src/google/protobuf/message.cc
@@ -46,9 +46,9 @@
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/descriptor.pb.h>
-#include <google/protobuf/map_field.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/generated_message_util.h>
+#include <google/protobuf/map_field.h>
#include <google/protobuf/reflection_ops.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/strutil.h>
@@ -96,12 +96,12 @@ bool Message::IsInitialized() const {
return ReflectionOps::IsInitialized(*this);
}
-void Message::FindInitializationErrors(vector<string>* errors) const {
+void Message::FindInitializationErrors(std::vector<string>* errors) const {
return ReflectionOps::FindInitializationErrors(*this, "", errors);
}
string Message::InitializationErrorString() const {
- vector<string> errors;
+ std::vector<string> errors;
FindInitializationErrors(&errors);
return Join(errors, ", ");
}
@@ -130,12 +130,12 @@ bool Message::ParsePartialFromFileDescriptor(int file_descriptor) {
return ParsePartialFromZeroCopyStream(&input) && input.GetErrno() == 0;
}
-bool Message::ParseFromIstream(istream* input) {
+bool Message::ParseFromIstream(std::istream* input) {
io::IstreamInputStream zero_copy_input(input);
return ParseFromZeroCopyStream(&zero_copy_input) && input->eof();
}
-bool Message::ParsePartialFromIstream(istream* input) {
+bool Message::ParsePartialFromIstream(std::istream* input) {
io::IstreamInputStream zero_copy_input(input);
return ParsePartialFromZeroCopyStream(&zero_copy_input) && input->eof();
}
@@ -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;
}
@@ -172,7 +172,7 @@ bool Message::SerializePartialToFileDescriptor(int file_descriptor) const {
return SerializePartialToZeroCopyStream(&output);
}
-bool Message::SerializeToOstream(ostream* output) const {
+bool Message::SerializeToOstream(std::ostream* output) const {
{
io::OstreamOutputStream zero_copy_output(output);
if (!SerializeToZeroCopyStream(&zero_copy_output)) return false;
@@ -180,7 +180,7 @@ bool Message::SerializeToOstream(ostream* output) const {
return output->good();
}
-bool Message::SerializePartialToOstream(ostream* output) const {
+bool Message::SerializePartialToOstream(std::ostream* output) const {
io::OstreamOutputStream zero_copy_output(output);
return SerializePartialToZeroCopyStream(&zero_copy_output);
}
@@ -225,38 +225,6 @@ void* Reflection::MutableRawRepeatedString(
}
-// Default EnumValue API implementations. Real reflection implementations should
-// override these. However, there are several legacy implementations that do
-// not, and cannot easily be changed at the same time as the Reflection API, so
-// we provide these for now.
-// TODO: Remove these once all Reflection implementations are updated.
-int Reflection::GetEnumValue(const Message& message,
- const FieldDescriptor* field) const {
- GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
- return 0;
-}
-void Reflection::SetEnumValue(Message* message,
- const FieldDescriptor* field,
- int value) const {
- GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
-}
-int Reflection::GetRepeatedEnumValue(
- const Message& message,
- const FieldDescriptor* field, int index) const {
- GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
- return 0;
-}
-void Reflection::SetRepeatedEnumValue(Message* message,
- const FieldDescriptor* field, int index,
- int value) const {
- GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
-}
-void Reflection::AddEnumValue(Message* message,
- const FieldDescriptor* field,
- int value) const {
- GOOGLE_LOG(FATAL) << "Unimplemented EnumValue API.";
-}
-
MapIterator Reflection::MapBegin(
Message* message,
const FieldDescriptor* field) const {
@@ -299,8 +267,8 @@ class GeneratedMessageFactory : public MessageFactory {
hash_map<const char*, RegistrationFunc*,
hash<const char*>, streq> file_map_;
- // Initialized lazily, so requires locking.
Mutex mutex_;
+ // Initialized lazily, so requires locking.
hash_map<const Descriptor*, const Message*> type_map_;
};
@@ -483,8 +451,8 @@ struct ShutdownRepeatedFieldRegister {
namespace internal {
template<>
-#if defined(_MSC_VER) && (_MSC_VER >= 1900)
-// Note: force noinline to workaround MSVC 2015 compiler bug, issue #240
+#if defined(_MSC_VER) && (_MSC_VER >= 1800)
+// Note: force noinline to workaround MSVC compiler bug with /Zc:inline, issue #240
GOOGLE_ATTRIBUTE_NOINLINE
#endif
Message* GenericTypeHandler<Message>::NewFromPrototype(
@@ -492,8 +460,8 @@ Message* GenericTypeHandler<Message>::NewFromPrototype(
return prototype->New(arena);
}
template<>
-#if defined(_MSC_VER) && (_MSC_VER >= 1900)
-// Note: force noinline to workaround MSVC 2015 compiler bug, issue #240
+#if defined(_MSC_VER) && (_MSC_VER >= 1800)
+// Note: force noinline to workaround MSVC compiler bug with /Zc:inline, issue #240
GOOGLE_ATTRIBUTE_NOINLINE
#endif
google::protobuf::Arena* GenericTypeHandler<Message>::GetArena(
@@ -501,8 +469,8 @@ google::protobuf::Arena* GenericTypeHandler<Message>::GetArena(
return value->GetArena();
}
template<>
-#if defined(_MSC_VER) && (_MSC_VER >= 1900)
-// Note: force noinline to workaround MSVC 2015 compiler bug, issue #240
+#if defined(_MSC_VER) && (_MSC_VER >= 1800)
+// Note: force noinline to workaround MSVC compiler bug with /Zc:inline, issue #240
GOOGLE_ATTRIBUTE_NOINLINE
#endif
void* GenericTypeHandler<Message>::GetMaybeArenaPointer(
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/message.h b/third_party/protobuf/src/google/protobuf/message.h
index 9705e97e43..4d14584ddb 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/message.h
+++ b/third_party/protobuf/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:
@@ -519,7 +519,7 @@ class LIBPROTOBUF_EXPORT Reflection {
// will only be present when the new unknown-enum-value semantics are enabled
// for a message.)
virtual int GetEnumValue(
- const Message& message, const FieldDescriptor* field) const;
+ const Message& message, const FieldDescriptor* field) const = 0;
// See MutableMessage() for the meaning of the "factory" parameter.
virtual const Message& GetMessage(const Message& message,
@@ -575,7 +575,7 @@ class LIBPROTOBUF_EXPORT Reflection {
// messages with new unknown-enum-value semantics.
virtual void SetEnumValue(Message* message,
const FieldDescriptor* field,
- int value) const;
+ int value) const = 0;
// Get a mutable pointer to a field with a message type. If a MessageFactory
// is provided, it will be used to construct instances of the sub-message;
@@ -646,7 +646,7 @@ class LIBPROTOBUF_EXPORT Reflection {
// for a message.)
virtual int GetRepeatedEnumValue(
const Message& message,
- const FieldDescriptor* field, int index) const;
+ const FieldDescriptor* field, int index) const = 0;
virtual const Message& GetRepeatedMessage(
const Message& message,
const FieldDescriptor* field, int index) const = 0;
@@ -693,7 +693,7 @@ class LIBPROTOBUF_EXPORT Reflection {
// messages with new unknown-enum-value semantics.
virtual void SetRepeatedEnumValue(Message* message,
const FieldDescriptor* field, int index,
- int value) const;
+ int value) const = 0;
// Get a mutable pointer to an element of a repeated field with a message
// type.
virtual Message* MutableRepeatedMessage(
@@ -729,7 +729,7 @@ class LIBPROTOBUF_EXPORT Reflection {
// messages with new unknown-enum-value semantics.
virtual void AddEnumValue(Message* message,
const FieldDescriptor* field,
- int value) const;
+ int value) const = 0;
// See MutableMessage() for comments on the "factory" parameter.
virtual Message* AddMessage(Message* message,
const FieldDescriptor* field,
@@ -848,34 +848,31 @@ class LIBPROTOBUF_EXPORT Reflection {
// downgrade to a compatible value or use the UnknownFieldSet if not. For
// example:
//
- // int new_value = GetValueFromApplicationLogic();
- // if (reflection->SupportsUnknownEnumValues()) {
+ // int new_value = GetValueFromApplicationLogic();
+ // if (reflection->SupportsUnknownEnumValues()) {
// reflection->SetEnumValue(message, field, new_value);
- // } else {
+ // } else {
// if (field_descriptor->enum_type()->
- // FindValueByNumver(new_value) != NULL) {
- // reflection->SetEnumValue(message, field, new_value);
+ // FindValueByNumber(new_value) != NULL) {
+ // reflection->SetEnumValue(message, field, new_value);
// } else if (emit_unknown_enum_values) {
- // reflection->MutableUnknownFields(message)->AddVarint(
- // field->number(),
- // new_value);
+ // reflection->MutableUnknownFields(message)->AddVarint(
+ // field->number(), new_value);
// } else {
- // // convert value to a compatible/default value.
- // new_value = CompatibleDowngrade(new_value);
- // reflection->SetEnumValue(message, field, new_value);
+ // // convert value to a compatible/default value.
+ // new_value = CompatibleDowngrade(new_value);
+ // reflection->SetEnumValue(message, field, new_value);
// }
- // }
+ // }
virtual bool SupportsUnknownEnumValues() const { return false; }
// Returns the MessageFactory associated with this message. This can be
// useful for determining if a message is a generated message or not, for
// example:
- //
- // if (message->GetReflection()->GetMessageFactory() ==
- // google::protobuf::MessageFactory::generated_factory()) {
- // // This is a generated message.
- // }
- //
+ // if (message->GetReflection()->GetMessageFactory() ==
+ // google::protobuf::MessageFactory::generated_factory()) {
+ // // This is a generated message.
+ // }
// It can also be used to create more messages of this type, though
// Message::New() is an easier way to accomplish this.
virtual MessageFactory* GetMessageFactory() const;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/message_lite.cc b/third_party/protobuf/src/google/protobuf/message_lite.cc
index ba56db952d..b8cb3f4c46 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/message_lite.cc
+++ b/third_party/protobuf/src/google/protobuf/message_lite.cc
@@ -33,8 +33,11 @@
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
-#include <google/protobuf/message_lite.h>
+#include <climits>
+
#include <google/protobuf/arena.h>
+#include <google/protobuf/generated_message_util.h>
+#include <google/protobuf/message_lite.h>
#include <google/protobuf/repeated_field.h>
#include <string>
#include <google/protobuf/stubs/logging.h>
@@ -58,9 +61,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()
@@ -226,6 +229,7 @@ uint8* MessageLite::InternalSerializeWithCachedSizesToArray(
int size = GetCachedSize();
io::ArrayOutputStream out(target, size);
io::CodedOutputStream coded_out(&out);
+ coded_out.SetSerializationDeterministic(deterministic);
SerializeWithCachedSizes(&coded_out);
GOOGLE_CHECK(!coded_out.HadError());
return target + size;
@@ -238,18 +242,18 @@ bool MessageLite::SerializeToCodedStream(io::CodedOutputStream* output) const {
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: " << size;
return false;
}
uint8* buffer = output->GetDirectBufferForNBytesAndAdvance(size);
if (buffer != NULL) {
- uint8* end = SerializeWithCachedSizesToArray(buffer);
+ uint8* end = InternalSerializeWithCachedSizesToArray(
+ output->IsSerializationDeterministic(), 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: " << byte_size;
return false;
}
@@ -300,7 +303,7 @@ bool MessageLite::AppendPartialToString(string* output) const {
reinterpret_cast<uint8*>(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<uint8*>(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/third_party/protobuf/3.0.0/src/google/protobuf/message_lite.h b/third_party/protobuf/src/google/protobuf/message_lite.h
index 2bdfe49614..5e5ed30681 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/message_lite.h
+++ b/third_party/protobuf/src/google/protobuf/message_lite.h
@@ -39,7 +39,9 @@
#ifndef GOOGLE_PROTOBUF_MESSAGE_LITE_H__
#define GOOGLE_PROTOBUF_MESSAGE_LITE_H__
+#include <climits>
#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/logging.h>
namespace google {
@@ -239,16 +241,22 @@ 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().
+ // ByteSizeLong() on all embedded messages.
//
- // ByteSize() is generally linear in the number of fields defined for the
+ // ByteSizeLong() is generally linear in the number of fields defined for the
// proto.
- virtual int ByteSize() const = 0;
+ virtual size_t ByteSizeLong() const = 0;
- // Serializes the message without recomputing the size. The message must
- // not have changed since the last call to ByteSize(); if it has, the results
- // are undefined.
+ // Legacy ByteSize() API.
+ int ByteSize() const {
+ size_t result = ByteSizeLong();
+ GOOGLE_DCHECK_LE(result, static_cast<size_t>(INT_MAX));
+ return static_cast<int>(result);
+ }
+
+ // Serializes the message without recomputing the size. The message must not
+ // have changed since the last call to ByteSize(), and the value returned by
+ // ByteSize must be non-negative. Otherwise the results are undefined.
virtual void SerializeWithCachedSizes(
io::CodedOutputStream* output) const = 0;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/message_unittest.cc b/third_party/protobuf/src/google/protobuf/message_unittest.cc
index 2954851de1..2bbfe40a27 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/message_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/message_unittest.cc
@@ -48,7 +48,7 @@
#include <google/protobuf/test_util.h>
#include <google/protobuf/unittest.pb.h>
#include <google/protobuf/io/coded_stream.h>
-#include <google/protobuf/io/io_win32.h>
+#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/descriptor.h>
@@ -56,6 +56,7 @@
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/io_win32.h>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
@@ -77,7 +78,7 @@ TEST(MessageTest, SerializeHelpers) {
protobuf_unittest::TestAllTypes message;
TestUtil::SetAllFields(&message);
- stringstream stream;
+ std::stringstream stream;
string str1("foo");
string str2("bar");
@@ -101,7 +102,7 @@ TEST(MessageTest, SerializeHelpers) {
}
TEST(MessageTest, SerializeToBrokenOstream) {
- ofstream out;
+ std::ofstream out;
protobuf_unittest::TestAllTypes message;
message.set_optional_int32(123);
@@ -155,7 +156,7 @@ TEST(MessageTest, ParseHelpers) {
{
// Test ParseFromIstream.
protobuf_unittest::TestAllTypes message;
- stringstream stream(data);
+ std::stringstream stream(data);
EXPECT_TRUE(message.ParseFromIstream(&stream));
EXPECT_TRUE(stream.eof());
TestUtil::ExpectAllFieldsSet(message);
@@ -183,7 +184,7 @@ TEST(MessageTest, ParseHelpers) {
TEST(MessageTest, ParseFailsIfNotInitialized) {
unittest::TestRequired message;
- vector<string> errors;
+ std::vector<string> errors;
{
ScopedMemoryLog log;
@@ -266,25 +267,117 @@ 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 {
-
-class NegativeByteSize : public unittest::TestRequired {
+// An input stream that repeats a string's content for a number of times. It
+// helps us create a really large input without consuming too much memory. Used
+// to test the parsing behavior when the input size exceeds 2G or close to it.
+class RepeatedInputStream : public io::ZeroCopyInputStream {
public:
- virtual int ByteSize() const { return -1; }
-};
+ RepeatedInputStream(const string& data, size_t count)
+ : data_(data), count_(count), position_(0), total_byte_count_(0) {}
+
+ virtual bool Next(const void** data, int* size) {
+ if (position_ == data_.size()) {
+ if (--count_ == 0) {
+ return false;
+ }
+ position_ = 0;
+ }
+ *data = &data_[position_];
+ *size = static_cast<int>(data_.size() - position_);
+ position_ = data_.size();
+ total_byte_count_ += *size;
+ return true;
+ }
+
+ virtual void BackUp(int count) {
+ position_ -= static_cast<size_t>(count);
+ total_byte_count_ -= count;
+ }
+
+ virtual bool Skip(int count) {
+ while (count > 0) {
+ const void* data;
+ int size;
+ if (!Next(&data, &size)) {
+ break;
+ }
+ if (size >= count) {
+ BackUp(size - count);
+ return true;
+ } else {
+ count -= size;
+ }
+ }
+ return false;
+ }
+ virtual int64 ByteCount() const { return total_byte_count_; }
+
+ private:
+ string data_;
+ size_t count_; // The number of strings that haven't been consuemd.
+ size_t position_; // Position in the string for the next read.
+ int64 total_byte_count_;
+};
} // namespace
-TEST(MessageTest, SerializationFailsOnNegativeByteSize) {
- NegativeByteSize message;
- string string_output;
- EXPECT_FALSE(message.AppendPartialToString(&string_output));
+TEST(MessageTest, TestParseMessagesCloseTo2G) {
+ // Create a message with a large string field.
+ string value = string(64 * 1024 * 1024, 'x');
+ protobuf_unittest::TestAllTypes message;
+ message.set_optional_string(value);
+
+ // Repeat this message in the input stream to make the total input size
+ // close to 2G.
+ string data = message.SerializeAsString();
+ size_t count = static_cast<size_t>(kint32max) / data.size();
+ RepeatedInputStream input(data, count);
+
+ // The parsing should succeed.
+ protobuf_unittest::TestAllTypes result;
+ EXPECT_TRUE(result.ParseFromZeroCopyStream(&input));
+
+ // When there are multiple occurences of a singulr field, the last one
+ // should win.
+ EXPECT_EQ(value, result.optional_string());
+}
+
+TEST(MessageTest, TestParseMessagesOver2G) {
+ // Create a message with a large string field.
+ string value = string(64 * 1024 * 1024, 'x');
+ protobuf_unittest::TestAllTypes message;
+ message.set_optional_string(value);
- io::ArrayOutputStream coded_raw_output(NULL, 100);
- io::CodedOutputStream coded_output(&coded_raw_output);
- EXPECT_FALSE(message.SerializePartialToCodedStream(&coded_output));
+ // Repeat this message in the input stream to make the total input size
+ // larger than 2G.
+ string data = message.SerializeAsString();
+ size_t count = static_cast<size_t>(kint32max) / data.size() + 1;
+ RepeatedInputStream input(data, count);
+
+ // The parsing should fail.
+ protobuf_unittest::TestAllTypes result;
+ EXPECT_FALSE(result.ParseFromZeroCopyStream(&input));
}
TEST(MessageTest, BypassInitializationCheckOnSerialize) {
@@ -296,7 +389,7 @@ TEST(MessageTest, BypassInitializationCheckOnSerialize) {
TEST(MessageTest, FindInitializationErrors) {
unittest::TestRequired message;
- vector<string> errors;
+ std::vector<string> errors;
message.FindInitializationErrors(&errors);
ASSERT_EQ(3, errors.size());
EXPECT_EQ("a", errors[0]);
@@ -320,6 +413,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/third_party/protobuf/3.0.0/src/google/protobuf/metadata.h b/third_party/protobuf/src/google/protobuf/metadata.h
index fdee150b44..dca1fa453b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/metadata.h
+++ b/third_party/protobuf/src/google/protobuf/metadata.h
@@ -40,6 +40,8 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/arena.h>
+#include <google/protobuf/arenastring.h>
+#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/unknown_field_set.h>
namespace google {
@@ -56,30 +58,30 @@ namespace internal {
// The tagged pointer uses the LSB to disambiguate cases, and uses bit 0 == 0 to
// indicate an arena pointer and bit 0 == 1 to indicate a UFS+Arena-container
// pointer.
-class LIBPROTOBUF_EXPORT InternalMetadataWithArena {
+template <class T, class Derived>
+class InternalMetadataWithArenaBase {
public:
- InternalMetadataWithArena() : ptr_(NULL) {}
- explicit InternalMetadataWithArena(Arena* arena)
- : ptr_ (arena) {}
+ InternalMetadataWithArenaBase() : ptr_(NULL) {}
+ explicit InternalMetadataWithArenaBase(Arena* arena) : ptr_(arena) {}
- ~InternalMetadataWithArena() {
+ ~InternalMetadataWithArenaBase() {
if (have_unknown_fields() && arena() == NULL) {
delete PtrValue<Container>();
}
ptr_ = NULL;
}
- GOOGLE_ATTRIBUTE_ALWAYS_INLINE const UnknownFieldSet& unknown_fields() const {
+ GOOGLE_ATTRIBUTE_ALWAYS_INLINE const T& unknown_fields() const {
if (GOOGLE_PREDICT_FALSE(have_unknown_fields())) {
- return PtrValue<Container>()->unknown_fields_;
+ return PtrValue<Container>()->unknown_fields;
} else {
- return *UnknownFieldSet::default_instance();
+ return Derived::default_instance();
}
}
- GOOGLE_ATTRIBUTE_ALWAYS_INLINE UnknownFieldSet* mutable_unknown_fields() {
+ GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* mutable_unknown_fields() {
if (GOOGLE_PREDICT_TRUE(have_unknown_fields())) {
- return &PtrValue<Container>()->unknown_fields_;
+ return &PtrValue<Container>()->unknown_fields;
} else {
return mutable_unknown_fields_slow();
}
@@ -87,7 +89,7 @@ class LIBPROTOBUF_EXPORT InternalMetadataWithArena {
GOOGLE_ATTRIBUTE_ALWAYS_INLINE Arena* arena() const {
if (GOOGLE_PREDICT_FALSE(have_unknown_fields())) {
- return PtrValue<Container>()->arena_;
+ return PtrValue<Container>()->arena;
} else {
return PtrValue<Arena>();
}
@@ -97,7 +99,7 @@ class LIBPROTOBUF_EXPORT InternalMetadataWithArena {
return PtrTag() == kTagContainer;
}
- GOOGLE_ATTRIBUTE_ALWAYS_INLINE void Swap(InternalMetadataWithArena* other) {
+ GOOGLE_ATTRIBUTE_ALWAYS_INLINE void Swap(Derived* other) {
// Semantics here are that we swap only the unknown fields, not the arena
// pointer. We cannot simply swap ptr_ with other->ptr_ because we need to
// maintain our own arena ptr. Also, our ptr_ and other's ptr_ may be in
@@ -105,7 +107,19 @@ class LIBPROTOBUF_EXPORT InternalMetadataWithArena {
// cannot simply swap ptr_ and then restore the arena pointers. We reuse
// UFS's swap implementation instead.
if (have_unknown_fields() || other->have_unknown_fields()) {
- mutable_unknown_fields()->Swap(other->mutable_unknown_fields());
+ static_cast<Derived*>(this)->DoSwap(other->mutable_unknown_fields());
+ }
+ }
+
+ GOOGLE_ATTRIBUTE_ALWAYS_INLINE void MergeFrom(const Derived& other) {
+ if (other.have_unknown_fields()) {
+ static_cast<Derived*>(this)->DoMergeFrom(other.unknown_fields());
+ }
+ }
+
+ GOOGLE_ATTRIBUTE_ALWAYS_INLINE void Clear() {
+ if (have_unknown_fields()) {
+ static_cast<Derived*>(this)->DoClear();
}
}
@@ -131,30 +145,82 @@ class LIBPROTOBUF_EXPORT InternalMetadataWithArena {
return reinterpret_cast<intptr_t>(ptr_) & kPtrTagMask;
}
- template<typename T> T* PtrValue() const {
- return reinterpret_cast<T*>(
+ template<typename U> U* PtrValue() const {
+ return reinterpret_cast<U*>(
reinterpret_cast<intptr_t>(ptr_) & kPtrValueMask);
}
// If ptr_'s tag is kTagContainer, it points to an instance of this struct.
struct Container {
- UnknownFieldSet unknown_fields_;
- Arena* arena_;
+ T unknown_fields;
+ Arena* arena;
};
- GOOGLE_ATTRIBUTE_NOINLINE UnknownFieldSet* mutable_unknown_fields_slow() {
+ GOOGLE_ATTRIBUTE_NOINLINE T* mutable_unknown_fields_slow() {
Arena* my_arena = arena();
Container* container = Arena::Create<Container>(my_arena);
ptr_ = reinterpret_cast<void*>(
reinterpret_cast<intptr_t>(container) | kTagContainer);
- container->arena_ = my_arena;
- return &(container->unknown_fields_);
+ container->arena = my_arena;
+ return &(container->unknown_fields);
+ }
+};
+
+class InternalMetadataWithArena
+ : public InternalMetadataWithArenaBase<UnknownFieldSet,
+ InternalMetadataWithArena> {
+ public:
+ InternalMetadataWithArena() {}
+ explicit InternalMetadataWithArena(Arena* arena)
+ : InternalMetadataWithArenaBase<UnknownFieldSet,
+ InternalMetadataWithArena>(arena) {}
+
+ void DoSwap(UnknownFieldSet* other) {
+ mutable_unknown_fields()->Swap(other);
+ }
+
+ void DoMergeFrom(const UnknownFieldSet& other) {
+ mutable_unknown_fields()->MergeFrom(other);
+ }
+
+ void DoClear() {
+ mutable_unknown_fields()->Clear();
+ }
+
+ static const UnknownFieldSet& default_instance() {
+ return *UnknownFieldSet::default_instance();
}
};
-// Temporary compatibility typedef. Remove once this is released in components
-// and upb CL is submitted.
-typedef InternalMetadataWithArena InternalMetadata;
+// We store unknown fields as a string right now, because there is currently no
+// good interface for reading unknown fields into an ArenaString. We may want
+// to revisit this to allow unknown fields to be parsed onto the Arena.
+class InternalMetadataWithArenaLite
+ : public InternalMetadataWithArenaBase<string,
+ InternalMetadataWithArenaLite> {
+ public:
+ InternalMetadataWithArenaLite() {}
+
+ explicit InternalMetadataWithArenaLite(Arena* arena)
+ : InternalMetadataWithArenaBase<string,
+ InternalMetadataWithArenaLite>(arena) {}
+
+ void DoSwap(string* other) {
+ mutable_unknown_fields()->swap(*other);
+ }
+
+ void DoMergeFrom(const string& other) {
+ mutable_unknown_fields()->append(other);
+ }
+
+ void DoClear() {
+ mutable_unknown_fields()->clear();
+ }
+
+ static const string& default_instance() {
+ return GetEmptyStringAlreadyInited();
+ }
+};
} // namespace internal
} // namespace protobuf
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/no_field_presence_test.cc b/third_party/protobuf/src/google/protobuf/no_field_presence_test.cc
index bc41beec81..bc41beec81 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/no_field_presence_test.cc
+++ b/third_party/protobuf/src/google/protobuf/no_field_presence_test.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/package_info.h b/third_party/protobuf/src/google/protobuf/package_info.h
index 935e96396d..935e96396d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/package_info.h
+++ b/third_party/protobuf/src/google/protobuf/package_info.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/preserve_unknown_enum_test.cc b/third_party/protobuf/src/google/protobuf/preserve_unknown_enum_test.cc
index 1673e8afae..1673e8afae 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/preserve_unknown_enum_test.cc
+++ b/third_party/protobuf/src/google/protobuf/preserve_unknown_enum_test.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/proto3_arena_lite_unittest.cc b/third_party/protobuf/src/google/protobuf/proto3_arena_lite_unittest.cc
index 0f18c027e8..0f18c027e8 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/proto3_arena_lite_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/proto3_arena_lite_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/proto3_arena_unittest.cc b/third_party/protobuf/src/google/protobuf/proto3_arena_unittest.cc
index 2838e0fc64..2838e0fc64 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/proto3_arena_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/proto3_arena_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/proto3_lite_unittest.cc b/third_party/protobuf/src/google/protobuf/proto3_lite_unittest.cc
index 2e2beea909..2e2beea909 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/proto3_lite_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/proto3_lite_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/reflection.h b/third_party/protobuf/src/google/protobuf/reflection.h
index 2391f45389..d5a6653cb9 100755
--- a/third_party/protobuf/3.0.0/src/google/protobuf/reflection.h
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/src/google/protobuf/reflection_internal.h b/third_party/protobuf/src/google/protobuf/reflection_internal.h
index fcb424715c..fcb424715c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/reflection_internal.h
+++ b/third_party/protobuf/src/google/protobuf/reflection_internal.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/reflection_ops.cc b/third_party/protobuf/src/google/protobuf/reflection_ops.cc
index 4629dec251..bb9c7f8bff 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/reflection_ops.cc
+++ b/third_party/protobuf/src/google/protobuf/reflection_ops.cc
@@ -63,7 +63,7 @@ void ReflectionOps::Merge(const Message& from, Message* to) {
const Reflection* from_reflection = from.GetReflection();
const Reflection* to_reflection = to->GetReflection();
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
from_reflection->ListFields(from, &fields);
for (int i = 0; i < fields.size(); i++) {
const FieldDescriptor* field = fields[i];
@@ -129,7 +129,7 @@ void ReflectionOps::Merge(const Message& from, Message* to) {
void ReflectionOps::Clear(Message* message) {
const Reflection* reflection = message->GetReflection();
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
reflection->ListFields(*message, &fields);
for (int i = 0; i < fields.size(); i++) {
reflection->ClearField(message, fields[i]);
@@ -152,7 +152,7 @@ bool ReflectionOps::IsInitialized(const Message& message) {
}
// Check that sub-messages are initialized.
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
reflection->ListFields(message, &fields);
for (int i = 0; i < fields.size(); i++) {
const FieldDescriptor* field = fields[i];
@@ -183,7 +183,7 @@ void ReflectionOps::DiscardUnknownFields(Message* message) {
reflection->MutableUnknownFields(message)->Clear();
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
reflection->ListFields(*message, &fields);
for (int i = 0; i < fields.size(); i++) {
const FieldDescriptor* field = fields[i];
@@ -224,7 +224,7 @@ static string SubMessagePrefix(const string& prefix,
void ReflectionOps::FindInitializationErrors(
const Message& message,
const string& prefix,
- vector<string>* errors) {
+ std::vector<string>* errors) {
const Descriptor* descriptor = message.GetDescriptor();
const Reflection* reflection = message.GetReflection();
@@ -238,7 +238,7 @@ void ReflectionOps::FindInitializationErrors(
}
// Check sub-messages.
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
reflection->ListFields(message, &fields);
for (int i = 0; i < fields.size(); i++) {
const FieldDescriptor* field = fields[i];
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/reflection_ops.h b/third_party/protobuf/src/google/protobuf/reflection_ops.h
index 4775911e84..45d8c650ef 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/reflection_ops.h
+++ b/third_party/protobuf/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<string>* errors);
+ std::vector<string>* errors);
private:
// All methods are static. No need to construct.
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/reflection_ops_unittest.cc b/third_party/protobuf/src/google/protobuf/reflection_ops_unittest.cc
index 88d6bfb610..864531701a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/reflection_ops_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/reflection_ops_unittest.cc
@@ -419,7 +419,7 @@ TEST(ReflectionOpsTest, OneofIsInitialized) {
}
static string FindInitializationErrors(const Message& message) {
- vector<string> errors;
+ std::vector<string> errors;
ReflectionOps::FindInitializationErrors(message, "", &errors);
return Join(errors, ",");
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/repeated_field.cc b/third_party/protobuf/src/google/protobuf/repeated_field.cc
index 77004f59af..5ca964c167 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/repeated_field.cc
+++ b/third_party/protobuf/src/google/protobuf/repeated_field.cc
@@ -58,14 +58,16 @@ void** RepeatedPtrFieldBase::InternalExtend(int extend_amount) {
(std::numeric_limits<size_t>::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<Rep*>(
- new char[kRepHeaderSize + sizeof(old_rep->elements[0]) * new_size]);
+ rep_ = reinterpret_cast<Rep*>(::operator new(bytes));
} else {
rep_ = reinterpret_cast<Rep*>(
- ::google::protobuf::Arena::CreateArray<char>(arena,
- kRepHeaderSize + sizeof(old_rep->elements[0]) * new_size));
+ ::google::protobuf::Arena::CreateArray<char>(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<char*>(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<void*>(old_rep), old_size);
+#else
+ ::operator delete(static_cast<void*>(old_rep));
+#endif
}
return &rep_->elements[current_size_];
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/repeated_field.h b/third_party/protobuf/src/google/protobuf/repeated_field.h
index bc5675554d..db5893b501 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/repeated_field.h
+++ b/third_party/protobuf/src/google/protobuf/repeated_field.h
@@ -61,8 +61,9 @@
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/message_lite.h>
-namespace google {
+// Forward-declare these so that we can make them friends.
+namespace google {
namespace upb {
namespace google_opensource {
class GMR_Handlers;
@@ -104,7 +105,7 @@ inline int CalculateReserve(Iter begin, Iter end) {
// not ever use a RepeatedField directly; they will use the get-by-index,
// set-by-index, and add accessors that are generated for all repeated fields.
template <typename Element>
-class RepeatedField {
+class RepeatedField PROTOBUF_FINAL {
public:
RepeatedField();
explicit RepeatedField(Arena* arena);
@@ -120,8 +121,14 @@ 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);
+ // Appends a new element and return a pointer to it.
+ // The new element is uninitialized if |Element| is a POD type.
Element* Add();
// Remove the last element in the array.
void RemoveLast();
@@ -144,6 +151,9 @@ class RepeatedField {
void Truncate(int new_size);
void AddAlreadyReserved(const Element& value);
+ // Appends a new element and return a pointer to it.
+ // The new element is uninitialized if |Element| is a POD type.
+ // Should be called only if Capacity() > Size().
Element* AddAlreadyReserved();
int Capacity() const;
@@ -284,7 +294,12 @@ class RepeatedField {
e->Element::~Element();
}
if (rep->arena == NULL) {
- delete[] reinterpret_cast<char*>(rep);
+#if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation)
+ const size_t bytes = size * sizeof(*e) + kRepHeaderSize;
+ ::operator delete(static_cast<void*>(rep), bytes);
+#else
+ ::operator delete(static_cast<void*>(rep));
+#endif
}
}
}
@@ -301,7 +316,7 @@ template <typename It, typename VoidPtr> class RepeatedPtrOverPtrsIterator;
namespace internal {
-// This is a helper template to copy an array of elements effeciently when they
+// This is a helper template to copy an array of elements efficiently when they
// have a trivial copy constructor, and correctly otherwise. This really
// shouldn't be necessary, but our compiler doesn't optimize std::copy very
// effectively.
@@ -408,6 +423,11 @@ class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase {
void Delete(int index);
template <typename TypeHandler>
typename TypeHandler::Type* Add(typename TypeHandler::Type* prototype = NULL);
+#if LANG_CXX11
+ template <typename TypeHandler>
+ void Add(typename TypeHandler::Type&& value,
+ std::enable_if<TypeHandler::Moveable>* dummy = NULL);
+#endif
template <typename TypeHandler>
void RemoveLast();
@@ -560,6 +580,9 @@ template <typename GenericType>
class GenericTypeHandler {
public:
typedef GenericType Type;
+#if LANG_CXX11
+ static const bool Moveable = false;
+#endif
static inline GenericType* New(Arena* arena) {
return ::google::protobuf::Arena::CreateMaybeMessage<Type>(
arena, static_cast<GenericType*>(0));
@@ -672,22 +695,23 @@ inline const Message& GenericTypeHandler<Message>::default_instance() {
}
-// HACK: If a class is declared as DLL-exported in MSVC, it insists on
-// generating copies of all its methods -- even inline ones -- to include
-// in the DLL. But SpaceUsed() calls StringSpaceUsedExcludingSelf() which
-// isn't in the lite library, therefore the lite library cannot link if
-// StringTypeHandler is exported. So, we factor out StringTypeHandlerBase,
-// export that, then make StringTypeHandler be a subclass which is NOT
-// exported.
-// TODO(kenton): Now that StringSpaceUsedExcludingSelf() is in the lite
-// library, this can be cleaned up.
-class LIBPROTOBUF_EXPORT StringTypeHandlerBase {
+class StringTypeHandler {
public:
typedef string Type;
+#if LANG_CXX11
+ static const bool Moveable =
+ std::is_move_constructible<Type>::value &&
+ std::is_move_assignable<Type>::value;
+#endif
static inline string* New(Arena* arena) {
return Arena::Create<string>(arena);
}
+#if LANG_CXX11
+ static inline string* New(Arena* arena, std::string&& value) {
+ return Arena::Create<string>(arena, std::move(value));
+ }
+#endif
static inline string* NewFromPrototype(const string*,
::google::protobuf::Arena* arena) {
return New(arena);
@@ -708,10 +732,6 @@ class LIBPROTOBUF_EXPORT StringTypeHandlerBase {
static inline const Type& default_instance() {
return ::google::protobuf::internal::GetEmptyString();
}
-};
-
-class StringTypeHandler : public StringTypeHandlerBase {
- public:
static int SpaceUsed(const string& value) {
return static_cast<int>(sizeof(value)) + StringSpaceUsedExcludingSelf(value);
}
@@ -723,7 +743,7 @@ class StringTypeHandler : public StringTypeHandlerBase {
// RepeatedPtrField is like RepeatedField, but used for repeated strings or
// Messages.
template <typename Element>
-class RepeatedPtrField : public internal::RepeatedPtrFieldBase {
+class RepeatedPtrField PROTOBUF_FINAL : public internal::RepeatedPtrFieldBase {
public:
RepeatedPtrField();
explicit RepeatedPtrField(::google::protobuf::Arena* arena);
@@ -741,6 +761,12 @@ class RepeatedPtrField : public internal::RepeatedPtrFieldBase {
const Element& Get(int index) const;
Element* Mutable(int index);
Element* Add();
+#if LANG_CXX11
+ void Add(Element&& value);
+#endif
+
+ 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.
@@ -859,10 +885,10 @@ class RepeatedPtrField : public internal::RepeatedPtrFieldBase {
// RepeatedPtrField.
// It is also useful in legacy code that uses temporary ownership to avoid
// copies. Example:
- // RepeatedPtrField<T> temp_field;
- // temp_field.AddAllocated(new T);
- // ... // Do something with temp_field
- // temp_field.ExtractSubrange(0, temp_field.size(), NULL);
+ // RepeatedPtrField<T> temp_field;
+ // temp_field.AddAllocated(new T);
+ // ... // Do something with temp_field
+ // temp_field.ExtractSubrange(0, temp_field.size(), NULL);
// If you put temp_field on the arena this fails, because the ownership
// transfers to the arena at the "AddAllocated" call and is not released
// anymore causing a double delete. UnsafeArenaAddAllocated prevents this.
@@ -944,17 +970,13 @@ class RepeatedPtrField : public internal::RepeatedPtrFieldBase {
return GetArenaNoVirtual();
}
- protected:
- // Note: RepeatedPtrField SHOULD NOT be subclassed by users. We only
- // subclass it in one place as a hack for compatibility with proto1. The
- // subclass needs to know about TypeHandler in order to call protected
- // methods on RepeatedPtrFieldBase.
+ private:
+ // Note: RepeatedPtrField SHOULD NOT be subclassed by users.
class TypeHandler;
// Internal arena accessor expected by helpers in Arena.
inline Arena* GetArenaNoVirtual() const;
- private:
// Implementations for ExtractSubrange(). The copying behavior must be
// included only if the type supports the necessary operations (e.g.,
// MergeFrom()), so we must resolve this at compile time. ExtractSubrange()
@@ -983,13 +1005,13 @@ inline RepeatedField<Element>::RepeatedField(Arena* arena)
: current_size_(0),
total_size_(0),
rep_(NULL) {
- // In case arena is NULL, then we do not create rep_, as code has an invariant
- // `rep_ == NULL then arena == NULL`.
- if (arena != NULL) {
- rep_ = reinterpret_cast<Rep*>(
- ::google::protobuf::Arena::CreateArray<char>(arena, kRepHeaderSize));
- rep_->arena = arena;
- }
+ // In case arena is NULL, then we do not create rep_, as code has an invariant
+ // `rep_ == NULL then arena == NULL`.
+ if (arena != NULL) {
+ rep_ = reinterpret_cast<Rep*>(
+ ::google::protobuf::Arena::CreateArray<char>(arena, kRepHeaderSize));
+ rep_->arena = arena;
+ }
}
template <typename Element>
@@ -997,7 +1019,12 @@ inline RepeatedField<Element>::RepeatedField(const RepeatedField& other)
: current_size_(0),
total_size_(0),
rep_(NULL) {
- CopyFrom(other);
+ if (other.current_size_ != 0) {
+ Reserve(other.current_size_);
+ CopyArray(rep_->elements,
+ other.rep_->elements, other.current_size_);
+ current_size_ = other.current_size_;
+ }
}
template <typename Element>
@@ -1139,7 +1166,7 @@ inline void RepeatedField<Element>::Clear() {
template <typename Element>
inline void RepeatedField<Element>::MergeFrom(const RepeatedField& other) {
- GOOGLE_CHECK_NE(&other, this);
+ GOOGLE_DCHECK_NE(&other, this);
if (other.current_size_ != 0) {
Reserve(current_size_ + other.current_size_);
CopyArray(rep_->elements + current_size_,
@@ -1265,13 +1292,12 @@ void RepeatedField<Element>::Reserve(int new_size) {
(std::numeric_limits<size_t>::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<Rep*>(
- new char[kRepHeaderSize + sizeof(Element) * new_size]);
+ rep_ = static_cast<Rep*>(::operator new(bytes));
} else {
rep_ = reinterpret_cast<Rep*>(
- ::google::protobuf::Arena::CreateArray<char>(arena,
- kRepHeaderSize + sizeof(Element) * new_size));
+ ::google::protobuf::Arena::CreateArray<char>(arena, bytes));
}
rep_->arena = arena;
int old_total_size = total_size_;
@@ -1288,7 +1314,7 @@ void RepeatedField<Element>::Reserve(int new_size) {
Element* e = &rep_->elements[0];
Element* limit = &rep_->elements[total_size_];
for (; e < limit; e++) {
- new (e) Element();
+ new (e) Element;
}
if (current_size_ > 0) {
MoveArray(rep_->elements, old_rep->elements, current_size_);
@@ -1363,7 +1389,12 @@ void RepeatedPtrFieldBase::Destroy() {
for (int i = 0; i < n; i++) {
TypeHandler::Delete(cast<TypeHandler>(elements[i]), NULL);
}
- delete[] reinterpret_cast<char*>(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<void*>(rep_), size);
+#else
+ ::operator delete(static_cast<void*>(rep_));
+#endif
}
rep_ = NULL;
}
@@ -1441,6 +1472,24 @@ inline typename TypeHandler::Type* RepeatedPtrFieldBase::Add(
return result;
}
+#if LANG_CXX11
+template <typename TypeHandler>
+inline void RepeatedPtrFieldBase::Add(
+ typename TypeHandler::Type&& value,
+ std::enable_if<TypeHandler::Moveable>*) {
+ if (rep_ != NULL && current_size_ < rep_->allocated_size) {
+ cast<TypeHandler>(rep_->elements[current_size_++]) = std::move(value);
+ }
+ if (!rep_ || rep_->allocated_size == total_size_) {
+ Reserve(total_size_ + 1);
+ }
+ ++rep_->allocated_size;
+ typename TypeHandler::Type* result =
+ TypeHandler::New(arena_, std::move(value));
+ rep_->elements[current_size_++] = result;
+}
+#endif
+
template <typename TypeHandler>
inline void RepeatedPtrFieldBase::RemoveLast() {
GOOGLE_DCHECK_GT(current_size_, 0);
@@ -1783,7 +1832,7 @@ template <typename Element>
inline RepeatedPtrField<Element>::RepeatedPtrField(
const RepeatedPtrField& other)
: RepeatedPtrFieldBase() {
- CopyFrom(other);
+ MergeFrom(other);
}
template <typename Element>
@@ -1838,6 +1887,13 @@ inline Element* RepeatedPtrField<Element>::Add() {
return RepeatedPtrFieldBase::Add<TypeHandler>();
}
+#if LANG_CXX11
+template <typename Element>
+inline void RepeatedPtrField<Element>::Add(Element&& value) {
+ RepeatedPtrFieldBase::Add<TypeHandler>(std::move(value));
+}
+#endif
+
template <typename Element>
inline void RepeatedPtrField<Element>::RemoveLast() {
RepeatedPtrFieldBase::RemoveLast<TypeHandler>();
@@ -2460,10 +2516,10 @@ AllocatedRepeatedPtrFieldBackInserter(
// UnsafeArenaAddAllocated instead of AddAllocated.
// This is slightly faster if that matters. It is also useful in legacy code
// that uses temporary ownership to avoid copies. Example:
-// RepeatedPtrField<T> temp_field;
-// temp_field.AddAllocated(new T);
-// ... // Do something with temp_field
-// temp_field.ExtractSubrange(0, temp_field.size(), NULL);
+// RepeatedPtrField<T> temp_field;
+// temp_field.AddAllocated(new T);
+// ... // Do something with temp_field
+// temp_field.ExtractSubrange(0, temp_field.size(), NULL);
// If you put temp_field on the arena this fails, because the ownership
// transfers to the arena at the "AddAllocated" call and is not released anymore
// causing a double delete. Using UnsafeArenaAddAllocated prevents this.
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/repeated_field_reflection_unittest.cc b/third_party/protobuf/src/google/protobuf/repeated_field_reflection_unittest.cc
index fcebe5ce33..fcebe5ce33 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/repeated_field_reflection_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/repeated_field_reflection_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/repeated_field_unittest.cc b/third_party/protobuf/src/google/protobuf/repeated_field_unittest.cc
index 39b24b3375..ec1074c9ce 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/repeated_field_unittest.cc
+++ b/third_party/protobuf/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<int> 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<int> 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) {
@@ -267,11 +268,13 @@ TEST(RepeatedField, MergeFrom) {
}
#ifdef PROTOBUF_HAS_DEATH_TEST
+#ifndef NDEBUG
TEST(RepeatedField, MergeFromSelf) {
RepeatedField<int> me;
me.Add(3);
EXPECT_DEATH(me.MergeFrom(me), "");
}
+#endif // NDEBUG
#endif // PROTOBUF_HAS_DEATH_TEST
TEST(RepeatedField, CopyFrom) {
@@ -343,7 +346,7 @@ TEST(RepeatedField, CopyConstruct) {
}
TEST(RepeatedField, IteratorConstruct) {
- vector<int> values;
+ std::vector<int> values;
values.push_back(1);
values.push_back(2);
@@ -397,6 +400,16 @@ TEST(RepeatedField, MutableDataIsMutable) {
EXPECT_EQ(2, field.Get(0));
}
+TEST(RepeatedField, SubscriptOperators) {
+ RepeatedField<int> field;
+ field.Add(1);
+ EXPECT_EQ(1, field.Get(0));
+ EXPECT_EQ(1, field[0]);
+ EXPECT_EQ(field.Mutable(0), &field[0]);
+ const RepeatedField<int>& const_field = field;
+ EXPECT_EQ(field.data(), &const_field[0]);
+}
+
TEST(RepeatedField, Truncate) {
RepeatedField<int> field;
@@ -470,11 +483,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 +642,18 @@ TEST(RepeatedPtrField, ReserveMoreThanDouble) {
RepeatedPtrField<string> field;
field.Reserve(20);
- EXPECT_EQ(20, ReservedSpace(&field));
+ EXPECT_LE(20, ReservedSpace(&field));
}
TEST(RepeatedPtrField, ReserveLessThanDouble) {
RepeatedPtrField<string> 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 +663,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) {
@@ -844,7 +860,7 @@ TEST(RepeatedPtrField, CopyConstruct) {
}
TEST(RepeatedPtrField, IteratorConstruct_String) {
- vector<string> values;
+ std::vector<string> values;
values.push_back("1");
values.push_back("2");
@@ -861,7 +877,7 @@ TEST(RepeatedPtrField, IteratorConstruct_String) {
TEST(RepeatedPtrField, IteratorConstruct_Proto) {
typedef TestAllTypes::NestedMessage Nested;
- vector<Nested> values;
+ std::vector<Nested> values;
values.push_back(Nested());
values.back().set_bb(1);
values.push_back(Nested());
@@ -918,6 +934,16 @@ TEST(RepeatedPtrField, MutableDataIsMutable) {
EXPECT_EQ("2", field.Get(0));
}
+TEST(RepeatedPtrField, SubscriptOperators) {
+ RepeatedPtrField<string> field;
+ *field.Add() = "1";
+ EXPECT_EQ("1", field.Get(0));
+ EXPECT_EQ("1", field[0]);
+ EXPECT_EQ(field.Mutable(0), &field[0]);
+ const RepeatedPtrField<string>& 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.
@@ -925,7 +951,7 @@ TEST(RepeatedPtrField, ExtractSubrange) {
for (int num = 0; num <= sz; ++num) {
for (int start = 0; start < sz - num; ++start) {
for (int extra = 0; extra < 4; ++extra) {
- vector<string*> subject;
+ std::vector<string*> subject;
// Create an array with "sz" elements and "extra" cleared elements.
RepeatedPtrField<string> field;
@@ -1487,7 +1513,7 @@ TEST_F(RepeatedFieldInsertionIteratorsTest, Nesteds) {
TEST_F(RepeatedFieldInsertionIteratorsTest,
AllocatedRepeatedPtrFieldWithStringIntData) {
- vector<Nested*> data;
+ std::vector<Nested*> data;
TestAllTypes goldenproto;
for (int i = 0; i < 10; ++i) {
Nested* new_data = new Nested;
@@ -1506,7 +1532,7 @@ TEST_F(RepeatedFieldInsertionIteratorsTest,
TEST_F(RepeatedFieldInsertionIteratorsTest,
AllocatedRepeatedPtrFieldWithString) {
- vector<string*> data;
+ std::vector<string*> data;
TestAllTypes goldenproto;
for (int i = 0; i < 10; ++i) {
string* new_data = new string;
@@ -1524,7 +1550,7 @@ TEST_F(RepeatedFieldInsertionIteratorsTest,
TEST_F(RepeatedFieldInsertionIteratorsTest,
UnsafeArenaAllocatedRepeatedPtrFieldWithStringIntData) {
- vector<Nested*> data;
+ std::vector<Nested*> data;
TestAllTypes goldenproto;
for (int i = 0; i < 10; ++i) {
Nested* new_data = new Nested;
@@ -1543,7 +1569,7 @@ TEST_F(RepeatedFieldInsertionIteratorsTest,
TEST_F(RepeatedFieldInsertionIteratorsTest,
UnsafeArenaAllocatedRepeatedPtrFieldWithString) {
- vector<string*> data;
+ std::vector<string*> data;
TestAllTypes goldenproto;
for (int i = 0; i < 10; ++i) {
string* new_data = new string;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/service.cc b/third_party/protobuf/src/google/protobuf/service.cc
index ffa919daa7..ffa919daa7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/service.cc
+++ b/third_party/protobuf/src/google/protobuf/service.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/service.h b/third_party/protobuf/src/google/protobuf/service.h
index ad6f968548..ad6f968548 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/service.h
+++ b/third_party/protobuf/src/google/protobuf/service.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/source_context.pb.cc b/third_party/protobuf/src/google/protobuf/source_context.pb.cc
index 5cc77bf34a..50e17da16d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/source_context.pb.cc
+++ b/third_party/protobuf/src/google/protobuf/source_context.pb.cc
@@ -19,88 +19,104 @@
namespace google {
namespace protobuf {
+class SourceContextDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<SourceContext> {
+} _SourceContext_default_instance_;
+
+namespace protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto {
+
namespace {
-const ::google::protobuf::Descriptor* SourceContext_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- SourceContext_reflection_ = NULL;
+::google::protobuf::Metadata file_level_metadata[1];
} // namespace
+const ::google::protobuf::uint32 TableStruct::offsets[] = {
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceContext, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceContext, file_name_),
+};
-void protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto() GOOGLE_ATTRIBUTE_COLD;
-void protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto();
- const ::google::protobuf::FileDescriptor* file =
- ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
- "google/protobuf/source_context.proto");
- GOOGLE_CHECK(file != NULL);
- SourceContext_descriptor_ = file->message_type(0);
- static const int SourceContext_offsets_[1] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceContext, file_name_),
- };
- SourceContext_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- SourceContext_descriptor_,
- SourceContext::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_));
-}
+static const ::google::protobuf::internal::MigrationSchema schemas[] = {
+ { 0, -1, sizeof(SourceContext)},
+};
+
+static ::google::protobuf::Message const * const file_default_instances[] = {
+ reinterpret_cast<const ::google::protobuf::Message*>(&_SourceContext_default_instance_),
+};
namespace {
-GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
-inline void protobuf_AssignDescriptorsOnce() {
- ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
- &protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto);
+void protobuf_AssignDescriptors() {
+ AddDescriptors();
+ ::google::protobuf::MessageFactory* factory = NULL;
+ AssignDescriptors(
+ "google/protobuf/source_context.proto", schemas, file_default_instances, TableStruct::offsets, factory,
+ file_level_metadata, NULL, NULL);
+}
+
+void protobuf_AssignDescriptorsOnce() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
}
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());
+ ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
}
} // namespace
-void protobuf_ShutdownFile_google_2fprotobuf_2fsource_5fcontext_2eproto() {
- delete SourceContext::default_instance_;
- delete SourceContext_reflection_;
+void TableStruct::Shutdown() {
+ _SourceContext_default_instance_.Shutdown();
+ delete file_level_metadata[0].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 TableStruct::InitDefaultsImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
+ ::google::protobuf::internal::InitProtobufDefaults();
+ _SourceContext_default_instance_.DefaultConstruct();
+}
+
+void InitDefaults() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &TableStruct::InitDefaultsImpl);
+}
+void AddDescriptorsImpl() {
+ InitDefaults();
+ static const char descriptor[] = {
+ "\n$google/protobuf/source_context.proto\022\017"
+ "google.protobuf\"\"\n\rSourceContext\022\021\n\tfile"
+ "_name\030\001 \001(\tB\225\001\n\023com.google.protobufB\022Sou"
+ "rceContextProtoP\001ZAgoogle.golang.org/gen"
+ "proto/protobuf/source_context;source_con"
+ "text\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTy"
+ "pesb\006proto3"
+ };
::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);
+ descriptor, 251);
::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::internal::OnShutdown(&TableStruct::Shutdown);
}
+void AddDescriptors() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
+}
// Force AddDescriptors() to be called at static initialization time.
-struct StaticDescriptorInitializer_google_2fprotobuf_2fsource_5fcontext_2eproto {
- StaticDescriptorInitializer_google_2fprotobuf_2fsource_5fcontext_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto();
+struct StaticDescriptorInitializer {
+ StaticDescriptorInitializer() {
+ AddDescriptors();
}
-} static_descriptor_initializer_google_2fprotobuf_2fsource_5fcontext_2eproto_;
+} static_descriptor_initializer;
+
+} // namespace protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto
+
// ===================================================================
@@ -110,27 +126,27 @@ const int SourceContext::kFileNameFieldNumber;
SourceContext::SourceContext()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::InitDefaults();
+ }
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);
+ _internal_metadata_(NULL),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ file_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.file_name().size() > 0) {
+ file_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.file_name_);
+ }
// @@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 +156,6 @@ SourceContext::~SourceContext() {
void SourceContext::SharedDtor() {
file_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- if (this != default_instance_) {
- }
}
void SourceContext::SetCachedSize(int size) const {
@@ -150,17 +164,15 @@ void SourceContext::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* SourceContext::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return SourceContext_descriptor_;
+ protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::file_level_metadata[0].descriptor;
}
const SourceContext& SourceContext::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-SourceContext* SourceContext::default_instance_ = NULL;
-
SourceContext* SourceContext::New(::google::protobuf::Arena* arena) const {
SourceContext* n = new SourceContext;
if (arena != NULL) {
@@ -180,13 +192,14 @@ bool SourceContext::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.SourceContext)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional string file_name = 1;
+ // string file_name = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_file_name()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -196,7 +209,6 @@ bool SourceContext::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -224,7 +236,7 @@ failure:
void SourceContext::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.SourceContext)
- // optional string file_name = 1;
+ // string file_name = 1;
if (this->file_name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->file_name().data(), this->file_name().length(),
@@ -239,8 +251,9 @@ void SourceContext::SerializeWithCachedSizes(
::google::protobuf::uint8* SourceContext::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.SourceContext)
- // optional string file_name = 1;
+ // string file_name = 1;
if (this->file_name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->file_name().data(), this->file_name().length(),
@@ -255,29 +268,28 @@ 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;
+ // string file_name = 1;
if (this->file_name().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const SourceContext* source =
::google::protobuf::internal::DynamicCastToGenerated<const SourceContext>(
&from);
if (source == NULL) {
@@ -291,9 +303,8 @@ void SourceContext::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
if (from.file_name().size() > 0) {
file_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.file_name_);
@@ -315,7 +326,6 @@ void SourceContext::CopyFrom(const SourceContext& from) {
}
bool SourceContext::IsInitialized() const {
-
return true;
}
@@ -325,56 +335,60 @@ void SourceContext::Swap(SourceContext* other) {
}
void SourceContext::InternalSwap(SourceContext* other) {
file_name_.Swap(&other->file_name_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata SourceContext::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = SourceContext_descriptor_;
- metadata.reflection = SourceContext_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::file_level_metadata[0];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// SourceContext
-// optional string file_name = 1;
+// string file_name = 1;
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());
+ return file_name_.GetNoArena();
}
- 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) {
+#if LANG_CXX11
+void SourceContext::set_file_name(::std::string&& value) {
+
+ file_name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.SourceContext.file_name)
+}
+#endif
+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<const char*>(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/third_party/protobuf/3.0.0/src/google/protobuf/source_context.pb.h b/third_party/protobuf/src/google/protobuf/source_context.pb.h
index 341a4534ab..10888385a5 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/source_context.pb.h
+++ b/third_party/protobuf/src/google/protobuf/source_context.pb.h
@@ -8,36 +8,48 @@
#include <google/protobuf/stubs/common.h>
-#if GOOGLE_PROTOBUF_VERSION < 3000000
+#if GOOGLE_PROTOBUF_VERSION < 3002000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
-#if 3000000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
+#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
+#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/metadata.h>
#include <google/protobuf/message.h>
-#include <google/protobuf/repeated_field.h>
-#include <google/protobuf/extension_set.h>
+#include <google/protobuf/repeated_field.h> // IWYU pragma: export
+#include <google/protobuf/extension_set.h> // IWYU pragma: export
#include <google/protobuf/unknown_field_set.h>
// @@protoc_insertion_point(includes)
+namespace google {
+namespace protobuf {
+class SourceContext;
+class SourceContextDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern SourceContextDefaultTypeInternal _SourceContext_default_instance_;
+} // namespace protobuf
+} // namespace google
namespace google {
namespace protobuf {
+namespace protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto {
// Internal implementation detail -- do not call these.
-void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto();
-void protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto();
-void protobuf_ShutdownFile_google_2fprotobuf_2fsource_5fcontext_2eproto();
-
-class SourceContext;
+struct LIBPROTOBUF_EXPORT TableStruct {
+ static const ::google::protobuf::uint32 offsets[];
+ static void InitDefaultsImpl();
+ static void Shutdown();
+};
+void LIBPROTOBUF_EXPORT AddDescriptors();
+void LIBPROTOBUF_EXPORT InitDefaults();
+} // namespace protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto
// ===================================================================
@@ -56,56 +68,66 @@ 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 reinterpret_cast<const SourceContext*>(
+ &_SourceContext_default_instance_);
+ }
+
void Swap(SourceContext* other);
// implements Message ----------------------------------------------
- inline SourceContext* New() const { return New(NULL); }
+ inline SourceContext* New() const PROTOBUF_FINAL { return New(NULL); }
- SourceContext* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ SourceContext* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const SourceContext& from);
void MergeFrom(const SourceContext& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(SourceContext* other);
private:
inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
- return _internal_metadata_.arena();
+ return NULL;
}
inline void* MaybeArenaPtr() const {
- return _internal_metadata_.raw_arena_ptr();
+ return NULL;
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional string file_name = 1;
+ // string file_name = 1;
void clear_file_name();
static const int kFileNameFieldNumber = 1;
const ::std::string& file_name() const;
void set_file_name(const ::std::string& value);
+ #if LANG_CXX11
+ void set_file_name(::std::string&& value);
+ #endif
void set_file_name(const char* value);
void set_file_name(const char* value, size_t size);
::std::string* mutable_file_name();
@@ -116,15 +138,9 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fsource_5fcontext_2eproto();
-
- void InitAsDefaultInstance();
- static SourceContext* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::TableStruct;
};
// ===================================================================
@@ -134,19 +150,27 @@ class LIBPROTOBUF_EXPORT SourceContext : public ::google::protobuf::Message /* @
#if !PROTOBUF_INLINE_NOT_IN_HEADERS
// SourceContext
-// optional string file_name = 1;
+// string file_name = 1;
inline void SourceContext::clear_file_name() {
file_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
}
inline 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());
+ return file_name_.GetNoArena();
}
inline 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)
}
+#if LANG_CXX11
+inline void SourceContext::set_file_name(::std::string&& value) {
+
+ file_name_.SetNoArena(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+ // @@protoc_insertion_point(field_set_rvalue:google.protobuf.SourceContext.file_name)
+}
+#endif
inline void SourceContext::set_file_name(const char* value) {
file_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
@@ -182,6 +206,7 @@ inline void SourceContext::set_allocated_file_name(::std::string* file_name) {
// @@protoc_insertion_point(namespace_scope)
+
} // namespace protobuf
} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/source_context.proto b/third_party/protobuf/src/google/protobuf/source_context.proto
index a2c08e2b57..f3b2c96681 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/source_context.proto
+++ b/third_party/protobuf/src/google/protobuf/source_context.proto
@@ -36,8 +36,8 @@ 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";
+option go_package = "google.golang.org/genproto/protobuf/source_context;source_context";
// `SourceContext` represents information about the source of a
// protobuf element, like the file in which it is defined.
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/struct.pb.cc b/third_party/protobuf/src/google/protobuf/struct.pb.cc
index a551384cfd..a1aa51ec0b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/struct.pb.cc
+++ b/third_party/protobuf/src/google/protobuf/struct.pb.cc
@@ -19,185 +19,177 @@
namespace google {
namespace protobuf {
-
-namespace {
-
-const ::google::protobuf::Descriptor* Struct_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- Struct_reflection_ = NULL;
-const ::google::protobuf::Descriptor* Struct_FieldsEntry_descriptor_ = NULL;
-const ::google::protobuf::Descriptor* Value_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- Value_reflection_ = NULL;
-struct ValueOneofInstance {
+class StructDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Struct> {
+} _Struct_default_instance_;
+class ValueDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Value> {
+ public:
int null_value_;
double number_value_;
::google::protobuf::internal::ArenaStringPtr string_value_;
bool bool_value_;
const ::google::protobuf::Struct* struct_value_;
const ::google::protobuf::ListValue* list_value_;
-}* Value_default_oneof_instance_ = NULL;
-const ::google::protobuf::Descriptor* ListValue_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- ListValue_reflection_ = NULL;
-const ::google::protobuf::EnumDescriptor* NullValue_descriptor_ = NULL;
+} _Value_default_instance_;
+class ListValueDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<ListValue> {
+} _ListValue_default_instance_;
-} // namespace
+namespace protobuf_google_2fprotobuf_2fstruct_2eproto {
-void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto() GOOGLE_ATTRIBUTE_COLD;
-void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto();
- const ::google::protobuf::FileDescriptor* file =
- ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
- "google/protobuf/struct.proto");
- GOOGLE_CHECK(file != NULL);
- Struct_descriptor_ = file->message_type(0);
- static const int Struct_offsets_[1] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Struct, fields_),
- };
- Struct_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- Struct_descriptor_,
- Struct::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_));
- Struct_FieldsEntry_descriptor_ = Struct_descriptor_->nested_type(0);
- Value_descriptor_ = file->message_type(1);
- static const int Value_offsets_[7] = {
- PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(Value_default_oneof_instance_, null_value_),
- PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(Value_default_oneof_instance_, number_value_),
- PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(Value_default_oneof_instance_, string_value_),
- PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(Value_default_oneof_instance_, bool_value_),
- PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(Value_default_oneof_instance_, struct_value_),
- PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(Value_default_oneof_instance_, list_value_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Value, kind_),
- };
- Value_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- Value_descriptor_,
- Value::default_instance_,
- Value_offsets_,
- -1,
- -1,
- -1,
- 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_));
- ListValue_descriptor_ = file->message_type(2);
- static const int ListValue_offsets_[1] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ListValue, values_),
- };
- ListValue_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- ListValue_descriptor_,
- ListValue::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_));
- NullValue_descriptor_ = file->enum_type(0);
-}
+namespace {
+
+::google::protobuf::Metadata file_level_metadata[4];
+const ::google::protobuf::EnumDescriptor* file_level_enum_descriptors[1];
+
+} // namespace
+
+const ::google::protobuf::uint32 TableStruct::offsets[] = {
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Struct, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Struct, fields_),
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Value, _internal_metadata_),
+ ~0u, // no _extensions_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Value, _oneof_case_[0]),
+ PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), null_value_),
+ PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), number_value_),
+ PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), string_value_),
+ PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), bool_value_),
+ PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), struct_value_),
+ PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), list_value_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Value, kind_),
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ListValue, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ListValue, values_),
+};
+
+static const ::google::protobuf::internal::MigrationSchema schemas[] = {
+ { 0, -1, sizeof(Struct)},
+ { 5, -1, sizeof(Value)},
+ { 16, -1, sizeof(ListValue)},
+};
+
+static ::google::protobuf::Message const * const file_default_instances[] = {
+ reinterpret_cast<const ::google::protobuf::Message*>(&_Struct_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_Value_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_ListValue_default_instance_),
+};
namespace {
-GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
-inline void protobuf_AssignDescriptorsOnce() {
- ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
- &protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto);
+void protobuf_AssignDescriptors() {
+ AddDescriptors();
+ ::google::protobuf::MessageFactory* factory = NULL;
+ AssignDescriptors(
+ "google/protobuf/struct.proto", schemas, file_default_instances, TableStruct::offsets, factory,
+ file_level_metadata, file_level_enum_descriptors, NULL);
+}
+
+void protobuf_AssignDescriptorsOnce() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
}
void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD;
void protobuf_RegisterTypes(const ::std::string&) {
protobuf_AssignDescriptorsOnce();
+ ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 4);
+ const ::google::protobuf::Descriptor* Struct_FieldsEntry_descriptor = protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[0].descriptor;
::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- Struct_descriptor_, &Struct::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- Struct_FieldsEntry_descriptor_,
+ Struct_FieldsEntry_descriptor,
::google::protobuf::internal::MapEntry<
::std::string,
::google::protobuf::Value,
::google::protobuf::internal::WireFormatLite::TYPE_STRING,
::google::protobuf::internal::WireFormatLite::TYPE_MESSAGE,
0>::CreateDefaultInstance(
- Struct_FieldsEntry_descriptor_));
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- Value_descriptor_, &Value::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- ListValue_descriptor_, &ListValue::default_instance());
+ Struct_FieldsEntry_descriptor));
}
} // 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 TableStruct::Shutdown() {
+ _Struct_default_instance_.Shutdown();
+ delete file_level_metadata[1].reflection;
+ _Value_default_instance_.Shutdown();
+ delete file_level_metadata[2].reflection;
+ _ListValue_default_instance_.Shutdown();
+ delete file_level_metadata[3].reflection;
+}
+
+void TableStruct::InitDefaultsImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
+ ::google::protobuf::internal::InitProtobufDefaults();
+ _Struct_default_instance_.DefaultConstruct();
+ _Value_default_instance_.DefaultConstruct();
+ _ListValue_default_instance_.DefaultConstruct();
+ _Value_default_instance_.null_value_ = 0;
+ _Value_default_instance_.number_value_ = 0;
+ _Value_default_instance_.string_value_.UnsafeSetDefault(
+ &::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ _Value_default_instance_.bool_value_ = false;
+ _Value_default_instance_.struct_value_ = const_cast< ::google::protobuf::Struct*>(
+ ::google::protobuf::Struct::internal_default_instance());
+ _Value_default_instance_.list_value_ = const_cast< ::google::protobuf::ListValue*>(
+ ::google::protobuf::ListValue::internal_default_instance());
+}
+
+void InitDefaults() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &TableStruct::InitDefaultsImpl);
+}
+void AddDescriptorsImpl() {
+ InitDefaults();
+ static const char descriptor[] = {
+ "\n\034google/protobuf/struct.proto\022\017google.p"
+ "rotobuf\"\204\001\n\006Struct\0223\n\006fields\030\001 \003(\0132#.goo"
+ "gle.protobuf.Struct.FieldsEntry\032E\n\013Field"
+ "sEntry\022\013\n\003key\030\001 \001(\t\022%\n\005value\030\002 \001(\0132\026.goo"
+ "gle.protobuf.Value:\0028\001\"\352\001\n\005Value\0220\n\nnull"
+ "_value\030\001 \001(\0162\032.google.protobuf.NullValue"
+ "H\000\022\026\n\014number_value\030\002 \001(\001H\000\022\026\n\014string_val"
+ "ue\030\003 \001(\tH\000\022\024\n\nbool_value\030\004 \001(\010H\000\022/\n\014stru"
+ "ct_value\030\005 \001(\0132\027.google.protobuf.StructH"
+ "\000\0220\n\nlist_value\030\006 \001(\0132\032.google.protobuf."
+ "ListValueH\000B\006\n\004kind\"3\n\tListValue\022&\n\006valu"
+ "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\370\001\001\242\002\003GPB"
+ "\252\002\036Google.Protobuf.WellKnownTypesb\006proto"
+ "3"
+ };
::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"
- "gle.protobuf.Struct.FieldsEntry\032E\n\013Field"
- "sEntry\022\013\n\003key\030\001 \001(\t\022%\n\005value\030\002 \001(\0132\026.goo"
- "gle.protobuf.Value:\0028\001\"\352\001\n\005Value\0220\n\nnull"
- "_value\030\001 \001(\0162\032.google.protobuf.NullValue"
- "H\000\022\026\n\014number_value\030\002 \001(\001H\000\022\026\n\014string_val"
- "ue\030\003 \001(\tH\000\022\024\n\nbool_value\030\004 \001(\010H\000\022/\n\014stru"
- "ct_value\030\005 \001(\0132\027.google.protobuf.StructH"
- "\000\0220\n\nlist_value\030\006 \001(\0132\032.google.protobuf."
- "ListValueH\000B\006\n\004kind\"3\n\tListValue\022&\n\006valu"
- "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"
- "\252\002\036Google.Protobuf.WellKnownTypesb\006proto"
- "3", 641);
+ descriptor, 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::internal::OnShutdown(&TableStruct::Shutdown);
}
+void AddDescriptors() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
+}
// Force AddDescriptors() to be called at static initialization time.
-struct StaticDescriptorInitializer_google_2fprotobuf_2fstruct_2eproto {
- StaticDescriptorInitializer_google_2fprotobuf_2fstruct_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto();
+struct StaticDescriptorInitializer {
+ StaticDescriptorInitializer() {
+ AddDescriptors();
}
-} static_descriptor_initializer_google_2fprotobuf_2fstruct_2eproto_;
+} static_descriptor_initializer;
+
+} // namespace protobuf_google_2fprotobuf_2fstruct_2eproto
+
const ::google::protobuf::EnumDescriptor* NullValue_descriptor() {
- protobuf_AssignDescriptorsOnce();
- return NullValue_descriptor_;
+ protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_enum_descriptors[0];
}
bool NullValue_IsValid(int value) {
- switch(value) {
+ switch (value) {
case 0:
return true;
default:
@@ -208,36 +200,55 @@ bool NullValue_IsValid(int value) {
// ===================================================================
+#if PROTOBUF_INLINE_NOT_IN_HEADERS
+#endif // PROTOBUF_INLINE_NOT_IN_HEADERS
+
+// ===================================================================
+
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int Struct::kFieldsFieldNumber;
#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
Struct::Struct()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.Struct)
}
-
-void Struct::InitAsDefaultInstance() {
- _is_default_instance_ = true;
+Struct::Struct(::google::protobuf::Arena* arena)
+ : ::google::protobuf::Message(),
+ _internal_metadata_(arena),
+ fields_(arena) {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ SharedCtor();
+ RegisterArenaDtor(arena);
+ // @@protoc_insertion_point(arena_constructor:google.protobuf.Struct)
}
-
Struct::Struct(const Struct& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ const ::google::protobuf::Descriptor*& Struct_FieldsEntry_descriptor = protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[0].descriptor;
+ fields_.SetAssignDescriptorCallback(
+ protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce);
+ fields_.SetEntryDescriptor(
+ &Struct_FieldsEntry_descriptor);
+ fields_.MergeFrom(from.fields_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.Struct)
}
void Struct::SharedCtor() {
- _is_default_instance_ = false;
- ::google::protobuf::internal::GetEmptyString();
- _cached_size_ = 0;
+ const ::google::protobuf::Descriptor*& Struct_FieldsEntry_descriptor = protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[0].descriptor;
fields_.SetAssignDescriptorCallback(
- protobuf_AssignDescriptorsOnce);
+ protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce);
fields_.SetEntryDescriptor(
- &::google::protobuf::Struct_FieldsEntry_descriptor_);
+ &Struct_FieldsEntry_descriptor);
+ _cached_size_ = 0;
}
Struct::~Struct() {
@@ -246,33 +257,36 @@ 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;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Struct::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Struct_descriptor_;
+ protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[1].descriptor;
}
const Struct& Struct::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-Struct* Struct::default_instance_ = NULL;
-
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<Struct>(arena);
}
void Struct::Clear() {
@@ -286,15 +300,15 @@ bool Struct::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Struct)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// map<string, .google.protobuf.Value> fields = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_fields:
Struct_FieldsEntry::Parser< ::google::protobuf::internal::MapField<
::std::string, ::google::protobuf::Value,
::google::protobuf::internal::WireFormatLite::TYPE_STRING,
@@ -310,9 +324,7 @@ bool Struct::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(10)) goto parse_loop_fields;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -355,7 +367,7 @@ void Struct::SerializeWithCachedSizes(
}
};
- if (output->IsSerializationDeterminstic() &&
+ if (output->IsSerializationDeterministic() &&
this->fields().size() > 1) {
::google::protobuf::scoped_array<SortItem> items(
new SortItem[this->fields().size()]);
@@ -373,6 +385,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 +399,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);
}
}
@@ -394,6 +412,7 @@ void Struct::SerializeWithCachedSizes(
::google::protobuf::uint8* Struct::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Struct)
// map<string, .google.protobuf.Value> fields = 1;
if (!this->fields().empty()) {
@@ -430,6 +449,9 @@ void Struct::SerializeWithCachedSizes(
InternalWriteMessageNoVirtualToArray(
1, *entry, deterministic, target);
;
+ if (entry->GetArena() != NULL) {
+ entry.release();
+ }
Utf8Check::Check(items[i]);
}
} else {
@@ -443,6 +465,9 @@ void Struct::SerializeWithCachedSizes(
InternalWriteMessageNoVirtualToArray(
1, *entry, deterministic, target);
;
+ if (entry->GetArena() != NULL) {
+ entry.release();
+ }
Utf8Check::Check(&*it);
}
}
@@ -452,35 +477,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<string, .google.protobuf.Value> fields = 1;
- total_size += 1 * this->fields_size();
+ total_size += 1 *
+ ::google::protobuf::internal::FromIntSize(this->fields_size());
{
::google::protobuf::scoped_ptr<Struct_FieldsEntry> 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const Struct* source =
::google::protobuf::internal::DynamicCastToGenerated<const Struct>(
&from);
if (source == NULL) {
@@ -494,9 +525,8 @@ void Struct::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
fields_.MergeFrom(from.fields_);
}
@@ -515,26 +545,36 @@ void Struct::CopyFrom(const Struct& from) {
}
bool Struct::IsInitialized() const {
-
return true;
}
void Struct::Swap(Struct* other) {
if (other == this) return;
+ if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
+ InternalSwap(other);
+ } else {
+ Struct* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
+ }
+}
+void Struct::UnsafeArenaSwap(Struct* other) {
+ if (other == this) return;
+ GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual());
InternalSwap(other);
}
void Struct::InternalSwap(Struct* other) {
fields_.Swap(&other->fields_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Struct::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = Struct_descriptor_;
- metadata.reflection = Struct_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[1];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
@@ -573,33 +613,63 @@ const int Value::kListValueFieldNumber;
Value::Value()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(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::Value(::google::protobuf::Arena* arena)
+ : ::google::protobuf::Message(),
+ _internal_metadata_(arena) {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ SharedCtor();
+ RegisterArenaDtor(arena);
+ // @@protoc_insertion_point(arena_constructor:google.protobuf.Value)
}
-
Value::Value(const Value& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ clear_has_kind();
+ switch (from.kind_case()) {
+ case kNullValue: {
+ set_null_value(from.null_value());
+ break;
+ }
+ case kNumberValue: {
+ set_number_value(from.number_value());
+ break;
+ }
+ case kStringValue: {
+ set_string_value(from.string_value());
+ break;
+ }
+ case kBoolValue: {
+ set_bool_value(from.bool_value());
+ break;
+ }
+ case kStructValue: {
+ mutable_struct_value()->::google::protobuf::Struct::MergeFrom(from.struct_value());
+ break;
+ }
+ case kListValue: {
+ mutable_list_value()->::google::protobuf::ListValue::MergeFrom(from.list_value());
+ break;
+ }
+ case KIND_NOT_SET: {
+ break;
+ }
+ }
// @@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() {
@@ -608,41 +678,44 @@ 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;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Value::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Value_descriptor_;
+ protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[2].descriptor;
}
const Value& Value::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-Value* Value::default_instance_ = NULL;
-
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<Value>(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;
@@ -652,7 +725,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: {
@@ -660,11 +734,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: {
@@ -686,13 +764,14 @@ bool Value::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Value)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional .google.protobuf.NullValue null_value = 1;
+ // .google.protobuf.NullValue null_value = 1;
case 1: {
- if (tag == 8) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(8u)) {
int value;
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(
@@ -701,14 +780,13 @@ bool Value::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(17)) goto parse_number_value;
break;
}
- // optional double number_value = 2;
+ // double number_value = 2;
case 2: {
- if (tag == 17) {
- parse_number_value:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(17u)) {
clear_kind();
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
double, ::google::protobuf::internal::WireFormatLite::TYPE_DOUBLE>(
@@ -717,14 +795,13 @@ bool Value::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(26)) goto parse_string_value;
break;
}
- // optional string string_value = 3;
+ // string string_value = 3;
case 3: {
- if (tag == 26) {
- parse_string_value:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(26u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_string_value()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -734,14 +811,13 @@ bool Value::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(32)) goto parse_bool_value;
break;
}
- // optional bool bool_value = 4;
+ // bool bool_value = 4;
case 4: {
- if (tag == 32) {
- parse_bool_value:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(32u)) {
clear_kind();
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>(
@@ -750,33 +826,30 @@ bool Value::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(42)) goto parse_struct_value;
break;
}
- // optional .google.protobuf.Struct struct_value = 5;
+ // .google.protobuf.Struct struct_value = 5;
case 5: {
- if (tag == 42) {
- parse_struct_value:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(42u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, mutable_struct_value()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(50)) goto parse_list_value;
break;
}
- // optional .google.protobuf.ListValue list_value = 6;
+ // .google.protobuf.ListValue list_value = 6;
case 6: {
- if (tag == 50) {
- parse_list_value:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(50u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, mutable_list_value()));
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -804,18 +877,18 @@ failure:
void Value::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.Value)
- // optional .google.protobuf.NullValue null_value = 1;
+ // .google.protobuf.NullValue null_value = 1;
if (has_null_value()) {
::google::protobuf::internal::WireFormatLite::WriteEnum(
1, this->null_value(), output);
}
- // optional double number_value = 2;
+ // double number_value = 2;
if (has_number_value()) {
::google::protobuf::internal::WireFormatLite::WriteDouble(2, this->number_value(), output);
}
- // optional string string_value = 3;
+ // string string_value = 3;
if (has_string_value()) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->string_value().data(), this->string_value().length(),
@@ -825,18 +898,18 @@ void Value::SerializeWithCachedSizes(
3, this->string_value(), output);
}
- // optional bool bool_value = 4;
+ // bool bool_value = 4;
if (has_bool_value()) {
::google::protobuf::internal::WireFormatLite::WriteBool(4, this->bool_value(), output);
}
- // optional .google.protobuf.Struct struct_value = 5;
+ // .google.protobuf.Struct struct_value = 5;
if (has_struct_value()) {
::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
5, *kind_.struct_value_, output);
}
- // optional .google.protobuf.ListValue list_value = 6;
+ // .google.protobuf.ListValue list_value = 6;
if (has_list_value()) {
::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
6, *kind_.list_value_, output);
@@ -847,19 +920,20 @@ void Value::SerializeWithCachedSizes(
::google::protobuf::uint8* Value::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Value)
- // optional .google.protobuf.NullValue null_value = 1;
+ // .google.protobuf.NullValue null_value = 1;
if (has_null_value()) {
target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray(
1, this->null_value(), target);
}
- // optional double number_value = 2;
+ // double number_value = 2;
if (has_number_value()) {
target = ::google::protobuf::internal::WireFormatLite::WriteDoubleToArray(2, this->number_value(), target);
}
- // optional string string_value = 3;
+ // string string_value = 3;
if (has_string_value()) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->string_value().data(), this->string_value().length(),
@@ -870,19 +944,19 @@ void Value::SerializeWithCachedSizes(
3, this->string_value(), target);
}
- // optional bool bool_value = 4;
+ // bool bool_value = 4;
if (has_bool_value()) {
target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(4, this->bool_value(), target);
}
- // optional .google.protobuf.Struct struct_value = 5;
+ // .google.protobuf.Struct struct_value = 5;
if (has_struct_value()) {
target = ::google::protobuf::internal::WireFormatLite::
InternalWriteMessageNoVirtualToArray(
5, *kind_.struct_value_, false, target);
}
- // optional .google.protobuf.ListValue list_value = 6;
+ // .google.protobuf.ListValue list_value = 6;
if (has_list_value()) {
target = ::google::protobuf::internal::WireFormatLite::
InternalWriteMessageNoVirtualToArray(
@@ -893,42 +967,42 @@ 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;
+ // .google.protobuf.NullValue null_value = 1;
case kNullValue: {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::EnumSize(this->null_value());
break;
}
- // optional double number_value = 2;
+ // double number_value = 2;
case kNumberValue: {
total_size += 1 + 8;
break;
}
- // optional string string_value = 3;
+ // string string_value = 3;
case kStringValue: {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->string_value());
break;
}
- // optional bool bool_value = 4;
+ // bool bool_value = 4;
case kBoolValue: {
total_size += 1 + 1;
break;
}
- // optional .google.protobuf.Struct struct_value = 5;
+ // .google.protobuf.Struct struct_value = 5;
case kStructValue: {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual(
*kind_.struct_value_);
break;
}
- // optional .google.protobuf.ListValue list_value = 6;
+ // .google.protobuf.ListValue list_value = 6;
case kListValue: {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual(
@@ -939,18 +1013,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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const Value* source =
::google::protobuf::internal::DynamicCastToGenerated<const Value>(
&from);
if (source == NULL) {
@@ -964,9 +1037,8 @@ void Value::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
switch (from.kind_case()) {
case kNullValue: {
set_null_value(from.null_value());
@@ -1013,33 +1085,43 @@ void Value::CopyFrom(const Value& from) {
}
bool Value::IsInitialized() const {
-
return true;
}
void Value::Swap(Value* other) {
if (other == this) return;
+ if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
+ InternalSwap(other);
+ } else {
+ Value* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
+ }
+}
+void Value::UnsafeArenaSwap(Value* other) {
+ if (other == this) return;
+ GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual());
InternalSwap(other);
}
void Value::InternalSwap(Value* other) {
std::swap(kind_, other->kind_);
std::swap(_oneof_case_[0], other->_oneof_case_[0]);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Value::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = Value_descriptor_;
- metadata.reflection = Value_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[2];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// Value
-// optional .google.protobuf.NullValue null_value = 1;
+// .google.protobuf.NullValue null_value = 1;
bool Value::has_null_value() const {
return kind_case() == kNullValue;
}
@@ -1052,14 +1134,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();
@@ -1068,7 +1150,7 @@ void Value::clear_null_value() {
// @@protoc_insertion_point(field_set:google.protobuf.Value.null_value)
}
-// optional double number_value = 2;
+// double number_value = 2;
bool Value::has_number_value() const {
return kind_case() == kNumberValue;
}
@@ -1081,14 +1163,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();
@@ -1097,7 +1179,7 @@ void Value::clear_number_value() {
// @@protoc_insertion_point(field_set:google.protobuf.Value.number_value)
}
-// optional string string_value = 3;
+// string string_value = 3;
bool Value::has_string_value() const {
return kind_case() == kStringValue;
}
@@ -1106,79 +1188,107 @@ 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();
}
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<const char*>(value), size));
+ kind_.string_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(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 bool_value = 4;
bool Value::has_bool_value() const {
return kind_case() == kBoolValue;
}
@@ -1191,14 +1301,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();
@@ -1207,7 +1317,7 @@ void Value::clear_bool_value() {
// @@protoc_insertion_point(field_set:google.protobuf.Value.bool_value)
}
-// optional .google.protobuf.Struct struct_value = 5;
+// .google.protobuf.Struct struct_value = 5;
bool Value::has_struct_value() const {
return kind_case() == kStructValue;
}
@@ -1216,7 +1326,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();
}
}
@@ -1230,7 +1342,9 @@ 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_;
@@ -1239,6 +1353,42 @@ void Value::clear_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_;
kind_.struct_value_ = NULL;
return temp;
@@ -1246,16 +1396,16 @@ 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;
+// .google.protobuf.ListValue list_value = 6;
bool Value::has_list_value() const {
return kind_case() == kListValue;
}
@@ -1264,7 +1414,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();
}
}
@@ -1278,7 +1430,9 @@ 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_;
@@ -1287,6 +1441,42 @@ void Value::clear_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_;
kind_.list_value_ = NULL;
return temp;
@@ -1294,13 +1484,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 {
@@ -1322,24 +1512,33 @@ const int ListValue::kValuesFieldNumber;
ListValue::ListValue()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.ListValue)
}
-
-void ListValue::InitAsDefaultInstance() {
- _is_default_instance_ = true;
+ListValue::ListValue(::google::protobuf::Arena* arena)
+ : ::google::protobuf::Message(),
+ _internal_metadata_(arena),
+ values_(arena) {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ SharedCtor();
+ RegisterArenaDtor(arena);
+ // @@protoc_insertion_point(arena_constructor:google.protobuf.ListValue)
}
-
ListValue::ListValue(const ListValue& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ values_(from.values_),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
// @@protoc_insertion_point(copy_constructor:google.protobuf.ListValue)
}
void ListValue::SharedCtor() {
- _is_default_instance_ = false;
_cached_size_ = 0;
}
@@ -1349,33 +1548,36 @@ 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;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* ListValue::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return ListValue_descriptor_;
+ protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[3].descriptor;
}
const ListValue& ListValue::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-ListValue* ListValue::default_instance_ = NULL;
-
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<ListValue>(arena);
}
void ListValue::Clear() {
@@ -1389,23 +1591,21 @@ bool ListValue::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.ListValue)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
// repeated .google.protobuf.Value values = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_values:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_values()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(10)) goto parse_loop_values;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -1444,6 +1644,7 @@ void ListValue::SerializeWithCachedSizes(
::google::protobuf::uint8* ListValue::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ListValue)
// repeated .google.protobuf.Value values = 1;
for (unsigned int i = 0, n = this->values_size(); i < n; i++) {
@@ -1456,30 +1657,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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const ListValue* source =
::google::protobuf::internal::DynamicCastToGenerated<const ListValue>(
&from);
if (source == NULL) {
@@ -1493,9 +1696,8 @@ void ListValue::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
values_.MergeFrom(from.values_);
}
@@ -1514,26 +1716,36 @@ void ListValue::CopyFrom(const ListValue& from) {
}
bool ListValue::IsInitialized() const {
-
return true;
}
void ListValue::Swap(ListValue* other) {
if (other == this) return;
+ if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
+ InternalSwap(other);
+ } else {
+ ListValue* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
+ }
+}
+void ListValue::UnsafeArenaSwap(ListValue* other) {
+ if (other == this) return;
+ GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual());
InternalSwap(other);
}
void ListValue::InternalSwap(ListValue* other) {
values_.UnsafeArenaSwap(&other->values_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata ListValue::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = ListValue_descriptor_;
- metadata.reflection = ListValue_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fstruct_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fstruct_2eproto::file_level_metadata[3];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/struct.pb.h b/third_party/protobuf/src/google/protobuf/struct.pb.h
index b085b84963..043f0c32b1 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/struct.pb.h
+++ b/third_party/protobuf/src/google/protobuf/struct.pb.h
@@ -8,41 +8,57 @@
#include <google/protobuf/stubs/common.h>
-#if GOOGLE_PROTOBUF_VERSION < 3000000
+#if GOOGLE_PROTOBUF_VERSION < 3002000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
-#if 3000000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
+#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
+#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/metadata.h>
#include <google/protobuf/message.h>
-#include <google/protobuf/repeated_field.h>
-#include <google/protobuf/extension_set.h>
+#include <google/protobuf/repeated_field.h> // IWYU pragma: export
+#include <google/protobuf/extension_set.h> // IWYU pragma: export
#include <google/protobuf/map.h>
#include <google/protobuf/map_field_inl.h>
#include <google/protobuf/generated_enum_reflection.h>
#include <google/protobuf/unknown_field_set.h>
// @@protoc_insertion_point(includes)
-
namespace google {
namespace protobuf {
-
-// Internal implementation detail -- do not call these.
-void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto();
-void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto();
-void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto();
-
class ListValue;
+class ListValueDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern ListValueDefaultTypeInternal _ListValue_default_instance_;
class Struct;
+class StructDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern StructDefaultTypeInternal _Struct_default_instance_;
class Value;
+class ValueDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern ValueDefaultTypeInternal _Value_default_instance_;
+} // namespace protobuf
+} // namespace google
+
+namespace google {
+namespace protobuf {
+
+namespace protobuf_google_2fprotobuf_2fstruct_2eproto {
+// Internal implementation detail -- do not call these.
+struct LIBPROTOBUF_EXPORT TableStruct {
+ static const ::google::protobuf::uint32 offsets[];
+ static void InitDefaultsImpl();
+ static void Shutdown();
+};
+void LIBPROTOBUF_EXPORT AddDescriptors();
+void LIBPROTOBUF_EXPORT InitDefaults();
+} // namespace protobuf_google_2fprotobuf_2fstruct_2eproto
enum NullValue {
NULL_VALUE = 0,
@@ -66,6 +82,9 @@ inline bool NullValue_Parse(
}
// ===================================================================
+
+// -------------------------------------------------------------------
+
class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Struct) */ {
public:
Struct();
@@ -78,39 +97,58 @@ class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc
return *this;
}
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
+ return MaybeArenaPtr();
+ }
static const ::google::protobuf::Descriptor* descriptor();
static const Struct& default_instance();
+ static inline const Struct* internal_default_instance() {
+ return reinterpret_cast<const Struct*>(
+ &_Struct_default_instance_);
+ }
+
+ void UnsafeArenaSwap(Struct* other);
void Swap(Struct* other);
// implements Message ----------------------------------------------
- inline Struct* New() const { return New(NULL); }
+ inline Struct* New() const PROTOBUF_FINAL { return New(NULL); }
- Struct* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ Struct* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Struct& from);
void MergeFrom(const Struct& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Struct* other);
+ 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();
@@ -120,7 +158,7 @@ class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -140,7 +178,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 +193,7 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto();
-
- void InitAsDefaultInstance();
- static Struct* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fstruct_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -174,6 +209,12 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_
return *this;
}
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
+ return MaybeArenaPtr();
+ }
static const ::google::protobuf::Descriptor* descriptor();
static const Value& default_instance();
@@ -187,36 +228,49 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_
KIND_NOT_SET = 0,
};
+ static inline const Value* internal_default_instance() {
+ return reinterpret_cast<const Value*>(
+ &_Value_default_instance_);
+ }
+
+ void UnsafeArenaSwap(Value* other);
void Swap(Value* other);
// implements Message ----------------------------------------------
- inline Value* New() const { return New(NULL); }
+ inline Value* New() const PROTOBUF_FINAL { return New(NULL); }
- Value* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ Value* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Value& from);
void MergeFrom(const Value& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Value* other);
+ 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();
@@ -226,13 +280,13 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional .google.protobuf.NullValue null_value = 1;
+ // .google.protobuf.NullValue null_value = 1;
private:
bool has_null_value() const;
public:
@@ -241,7 +295,7 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_
::google::protobuf::NullValue null_value() const;
void set_null_value(::google::protobuf::NullValue value);
- // optional double number_value = 2;
+ // double number_value = 2;
private:
bool has_number_value() const;
public:
@@ -250,7 +304,7 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_
double number_value() const;
void set_number_value(double value);
- // optional string string_value = 3;
+ // string string_value = 3;
private:
bool has_string_value() const;
public:
@@ -263,8 +317,11 @@ 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;
+ // bool bool_value = 4;
private:
bool has_bool_value() const;
public:
@@ -273,40 +330,60 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_
bool bool_value() const;
void set_bool_value(bool value);
- // optional .google.protobuf.Struct struct_value = 5;
+ // .google.protobuf.Struct struct_value = 5;
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;
+ // .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)
private:
- inline void set_has_null_value();
- inline void set_has_number_value();
- inline void set_has_string_value();
- inline void set_has_bool_value();
- inline void set_has_struct_value();
- inline void set_has_list_value();
+ void set_has_null_value();
+ void set_has_number_value();
+ void set_has_string_value();
+ void set_has_bool_value();
+ void set_has_struct_value();
+ void set_has_list_value();
inline bool has_kind() const;
void clear_kind();
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 +396,7 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto();
-
- void InitAsDefaultInstance();
- static Value* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fstruct_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -340,39 +412,58 @@ class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@pro
return *this;
}
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
+ return MaybeArenaPtr();
+ }
static const ::google::protobuf::Descriptor* descriptor();
static const ListValue& default_instance();
+ static inline const ListValue* internal_default_instance() {
+ return reinterpret_cast<const ListValue*>(
+ &_ListValue_default_instance_);
+ }
+
+ void UnsafeArenaSwap(ListValue* other);
void Swap(ListValue* other);
// implements Message ----------------------------------------------
- inline ListValue* New() const { return New(NULL); }
+ inline ListValue* New() const PROTOBUF_FINAL { return New(NULL); }
- ListValue* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ ListValue* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const ListValue& from);
void MergeFrom(const ListValue& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(ListValue* other);
+ 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();
@@ -382,7 +473,7 @@ class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@pro
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -404,15 +495,12 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto();
-
- void InitAsDefaultInstance();
- static ListValue* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fstruct_2eproto::TableStruct;
};
// ===================================================================
@@ -420,6 +508,8 @@ class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@pro
// ===================================================================
#if !PROTOBUF_INLINE_NOT_IN_HEADERS
+// -------------------------------------------------------------------
+
// Struct
// map<string, .google.protobuf.Value> fields = 1;
@@ -444,7 +534,7 @@ Struct::mutable_fields() {
// Value
-// optional .google.protobuf.NullValue null_value = 1;
+// .google.protobuf.NullValue null_value = 1;
inline bool Value::has_null_value() const {
return kind_case() == kNullValue;
}
@@ -473,7 +563,7 @@ inline void Value::set_null_value(::google::protobuf::NullValue value) {
// @@protoc_insertion_point(field_set:google.protobuf.Value.null_value)
}
-// optional double number_value = 2;
+// double number_value = 2;
inline bool Value::has_number_value() const {
return kind_case() == kNumberValue;
}
@@ -502,7 +592,7 @@ inline void Value::set_number_value(double value) {
// @@protoc_insertion_point(field_set:google.protobuf.Value.number_value)
}
-// optional string string_value = 3;
+// string string_value = 3;
inline bool Value::has_string_value() const {
return kind_case() == kStringValue;
}
@@ -511,25 +601,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();
}
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 +629,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<const char*>(value), size));
+ kind_.string_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(value), size),
+ GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Value.string_value)
}
inline ::std::string* Value::mutable_string_value() {
@@ -558,14 +651,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,13 +683,25 @@ 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;
+// bool bool_value = 4;
inline bool Value::has_bool_value() const {
return kind_case() == kBoolValue;
}
@@ -612,7 +730,7 @@ inline void Value::set_bool_value(bool value) {
// @@protoc_insertion_point(field_set:google.protobuf.Value.bool_value)
}
-// optional .google.protobuf.Struct struct_value = 5;
+// .google.protobuf.Struct struct_value = 5;
inline bool Value::has_struct_value() const {
return kind_case() == kStructValue;
}
@@ -621,7 +739,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,7 +755,9 @@ 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_;
@@ -644,6 +766,42 @@ 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_;
kind_.struct_value_ = NULL;
return temp;
@@ -651,16 +809,16 @@ 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;
+// .google.protobuf.ListValue list_value = 6;
inline bool Value::has_list_value() const {
return kind_case() == kListValue;
}
@@ -669,7 +827,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,7 +843,9 @@ 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_;
@@ -692,6 +854,42 @@ 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_;
kind_.list_value_ = NULL;
return temp;
@@ -699,13 +897,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 {
@@ -756,9 +954,12 @@ ListValue::values() const {
// -------------------------------------------------------------------
+// -------------------------------------------------------------------
+
// @@protoc_insertion_point(namespace_scope)
+
} // namespace protobuf
} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/struct.proto b/third_party/protobuf/src/google/protobuf/struct.proto
index beeba81188..7d7808e7fb 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/struct.proto
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomic_sequence_num.h b/third_party/protobuf/src/google/protobuf/stubs/atomic_sequence_num.h
index bb20942f2f..bb20942f2f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomic_sequence_num.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/atomic_sequence_num.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops.h b/third_party/protobuf/src/google/protobuf/stubs/atomicops.h
index 9b3d1e6b57..75aee30640 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/atomicops.h
@@ -123,8 +123,8 @@ Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
// ensure that no later memory access can be reordered ahead of the operation.
// "Release" operations ensure that no previous memory access can be reordered
// after the operation. "Barrier" operations have both "Acquire" and "Release"
-// semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory
-// access.
+// semantics. A MemoryBarrierInternal() has "Barrier" semantics, but does no
+// memory access.
Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value);
@@ -132,10 +132,10 @@ Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value);
-#if defined(__MINGW32__) && defined(MemoryBarrier)
-#undef MemoryBarrier
-#endif
-void MemoryBarrier();
+// This function was renamed from MemoryBarrier to MemoryBarrierInternal
+// because MemoryBarrier is a define in Windows ARM builds and we do not
+// undefine it because we call it from this function.
+void MemoryBarrierInternal();
void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value);
void Acquire_Store(volatile Atomic32* ptr, Atomic32 value);
void Release_Store(volatile Atomic32* ptr, Atomic32 value);
@@ -180,7 +180,7 @@ Atomic64 Release_Load(volatile const Atomic64* ptr);
#include <google/protobuf/stubs/atomicops_internals_tsan.h>
// MSVC.
#elif defined(_MSC_VER)
-#if defined(GOOGLE_PROTOBUF_ARCH_IA32) || defined(GOOGLE_PROTOBUF_ARCH_X64)
+#if defined(GOOGLE_PROTOBUF_ARCH_IA32) || defined(GOOGLE_PROTOBUF_ARCH_X64) || defined(GOOGLE_PROTOBUF_ARCH_ARM)
#include <google/protobuf/stubs/atomicops_internals_x86_msvc.h>
#else
#error GOOGLE_PROTOBUF_ATOMICOPS_ERROR
@@ -194,16 +194,16 @@ Atomic64 Release_Load(volatile const Atomic64* ptr);
#elif defined(GOOGLE_PROTOBUF_OS_AIX)
#include <google/protobuf/stubs/atomicops_internals_power.h>
-// Apple.
-#elif defined(GOOGLE_PROTOBUF_OS_APPLE)
-#include <google/protobuf/stubs/atomicops_internals_macosx.h>
-
// GCC.
#elif defined(__GNUC__)
#if defined(GOOGLE_PROTOBUF_ARCH_IA32) || defined(GOOGLE_PROTOBUF_ARCH_X64)
#include <google/protobuf/stubs/atomicops_internals_x86_gcc.h>
#elif defined(GOOGLE_PROTOBUF_ARCH_ARM) && defined(__linux__)
+#if (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4))
+#include <google/protobuf/stubs/atomicops_internals_generic_gcc.h>
+#else
#include <google/protobuf/stubs/atomicops_internals_arm_gcc.h>
+#endif
#elif defined(GOOGLE_PROTOBUF_ARCH_AARCH64)
#include <google/protobuf/stubs/atomicops_internals_arm64_gcc.h>
#elif defined(GOOGLE_PROTOBUF_ARCH_ARM_QNX)
@@ -213,7 +213,10 @@ Atomic64 Release_Load(volatile const Atomic64* ptr);
#elif defined(GOOGLE_PROTOBUF_ARCH_POWER)
#include <google/protobuf/stubs/atomicops_internals_power.h>
#elif defined(__native_client__)
-#include <google/protobuf/stubs/atomicops_internals_pnacl.h>
+// The static_asserts in the C++11 atomics implementation cause it to fail
+// with certain compilers, e.g. nvcc on macOS. Don't use elsewhere unless
+// the TODO in that file is addressed.
+#include <google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h>
#elif defined(GOOGLE_PROTOBUF_ARCH_PPC)
#include <google/protobuf/stubs/atomicops_internals_ppc_gcc.h>
#elif (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4))
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_arm64_gcc.h b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_arm64_gcc.h
index 0a2d2b894b..9a69d21ad6 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_arm64_gcc.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_arm64_gcc.h
@@ -37,7 +37,7 @@ namespace google {
namespace protobuf {
namespace internal {
-inline void MemoryBarrier() {
+inline void MemoryBarrierInternal() {
__asm__ __volatile__ ("dmb ish" ::: "memory"); // NOLINT
}
@@ -117,9 +117,9 @@ inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
Atomic32 increment) {
- MemoryBarrier();
+ MemoryBarrierInternal();
Atomic32 result = NoBarrier_AtomicIncrement(ptr, increment);
- MemoryBarrier();
+ MemoryBarrierInternal();
return result;
}
@@ -128,7 +128,7 @@ inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
Atomic32 prev = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
- MemoryBarrier();
+ MemoryBarrierInternal();
return prev;
}
@@ -136,7 +136,7 @@ inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
- MemoryBarrier();
+ MemoryBarrierInternal();
Atomic32 prev = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
return prev;
@@ -148,7 +148,7 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
- MemoryBarrier();
+ MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
@@ -178,7 +178,7 @@ inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
}
inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
- MemoryBarrier();
+ MemoryBarrierInternal();
return *ptr;
}
@@ -253,9 +253,9 @@ inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr,
inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
Atomic64 increment) {
- MemoryBarrier();
+ MemoryBarrierInternal();
Atomic64 result = NoBarrier_AtomicIncrement(ptr, increment);
- MemoryBarrier();
+ MemoryBarrierInternal();
return result;
}
@@ -264,7 +264,7 @@ inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
Atomic64 prev = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
- MemoryBarrier();
+ MemoryBarrierInternal();
return prev;
}
@@ -272,7 +272,7 @@ inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
- MemoryBarrier();
+ MemoryBarrierInternal();
Atomic64 prev = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
return prev;
@@ -284,7 +284,7 @@ inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
*ptr = value;
- MemoryBarrier();
+ MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
@@ -314,7 +314,7 @@ inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
}
inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
- MemoryBarrier();
+ MemoryBarrierInternal();
return *ptr;
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_arm_gcc.h b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_arm_gcc.h
index 90e727b0bc..6e2de67fa5 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_arm_gcc.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_arm_gcc.h
@@ -115,17 +115,17 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
}
-inline void MemoryBarrier() {
+inline void MemoryBarrierInternal() {
pLinuxKernelMemoryBarrier();
}
inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
- MemoryBarrier();
+ MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
- MemoryBarrier();
+ MemoryBarrierInternal();
*ptr = value;
}
@@ -135,12 +135,12 @@ inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
Atomic32 value = *ptr;
- MemoryBarrier();
+ MemoryBarrierInternal();
return value;
}
inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
- MemoryBarrier();
+ MemoryBarrierInternal();
return *ptr;
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_arm_qnx.h b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_arm_qnx.h
index 17dfaa5182..cd97e0c994 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_arm_qnx.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_arm_qnx.h
@@ -110,17 +110,17 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
}
-inline void MemoryBarrier() {
+inline void MemoryBarrierInternal() {
__sync_synchronize();
}
inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
- MemoryBarrier();
+ MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
- MemoryBarrier();
+ MemoryBarrierInternal();
*ptr = value;
}
@@ -130,12 +130,12 @@ inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
Atomic32 value = *ptr;
- MemoryBarrier();
+ MemoryBarrierInternal();
return value;
}
inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
- MemoryBarrier();
+ MemoryBarrierInternal();
return *ptr;
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h
index eb198ff5cc..eb198ff5cc 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_pnacl.h b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h
index 3b314fd0c9..44ef9c9e03 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_pnacl.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_generic_c11_atomic.h
@@ -30,8 +30,8 @@
// This file is an internal atomic implementation, use atomicops.h instead.
-#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PNACL_H_
-#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PNACL_H_
+#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_C11_ATOMIC_H_
+#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_C11_ATOMIC_H_
#include <atomic>
@@ -52,7 +52,7 @@ typedef volatile std::atomic<Atomic32>* AtomicLocation32;
static_assert(sizeof(*(AtomicLocation32) nullptr) == sizeof(Atomic32),
"incompatible 32-bit atomic layout");
-inline void MemoryBarrier() {
+inline void MemoryBarrierInternal() {
#if defined(__GLIBCXX__)
// Work around libstdc++ bug 51038 where atomic_thread_fence was declared but
// not defined, leading to the linker complaining about undefined references.
@@ -119,7 +119,7 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
((AtomicLocation32)ptr)->store(value, std::memory_order_relaxed);
- MemoryBarrier();
+ MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
@@ -135,7 +135,7 @@ inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
}
inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
- MemoryBarrier();
+ MemoryBarrierInternal();
return ((AtomicLocation32)ptr)->load(std::memory_order_relaxed);
}
@@ -202,7 +202,7 @@ inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
((AtomicLocation64)ptr)->store(value, std::memory_order_relaxed);
- MemoryBarrier();
+ MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
@@ -218,7 +218,7 @@ inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
}
inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
- MemoryBarrier();
+ MemoryBarrierInternal();
return ((AtomicLocation64)ptr)->load(std::memory_order_relaxed);
}
@@ -228,4 +228,4 @@ inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
} // namespace protobuf
} // namespace google
-#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PNACL_H_
+#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_C11_ATOMIC_H_
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h
index a0116a60ee..0b0b06ce6c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h
@@ -38,7 +38,7 @@ namespace internal {
inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
- __atomic_compare_exchange_n(ptr, &old_value, new_value, true,
+ __atomic_compare_exchange_n(ptr, &old_value, new_value, false,
__ATOMIC_RELAXED, __ATOMIC_RELAXED);
return old_value;
}
@@ -61,7 +61,7 @@ inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
- __atomic_compare_exchange_n(ptr, &old_value, new_value, true,
+ __atomic_compare_exchange_n(ptr, &old_value, new_value, false,
__ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
return old_value;
}
@@ -69,7 +69,7 @@ inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
- __atomic_compare_exchange_n(ptr, &old_value, new_value, true,
+ __atomic_compare_exchange_n(ptr, &old_value, new_value, false,
__ATOMIC_RELEASE, __ATOMIC_ACQUIRE);
return old_value;
}
@@ -78,7 +78,7 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
__atomic_store_n(ptr, value, __ATOMIC_RELAXED);
}
-inline void MemoryBarrier() {
+inline void MemoryBarrierInternal() {
__sync_synchronize();
}
@@ -115,7 +115,7 @@ inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
- __atomic_compare_exchange_n(ptr, &old_value, new_value, true,
+ __atomic_compare_exchange_n(ptr, &old_value, new_value, false,
__ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
return old_value;
}
@@ -123,11 +123,29 @@ inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
- __atomic_compare_exchange_n(ptr, &old_value, new_value, true,
+ __atomic_compare_exchange_n(ptr, &old_value, new_value, false,
__ATOMIC_RELAXED, __ATOMIC_RELAXED);
return old_value;
}
+inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr,
+ Atomic64 increment) {
+ return __atomic_add_fetch(ptr, increment, __ATOMIC_RELAXED);
+}
+
+inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
+ __atomic_store_n(ptr, value, __ATOMIC_RELAXED);
+}
+
+inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr,
+ Atomic64 new_value) {
+ return __atomic_exchange_n(ptr, new_value, __ATOMIC_RELAXED);
+}
+
+inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
+ return __atomic_load_n(ptr, __ATOMIC_RELAXED);
+}
+
#endif // defined(__LP64__)
} // namespace internal
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_mips_gcc.h b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_mips_gcc.h
index f5837c9ec2..6ce6820ec2 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_mips_gcc.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_mips_gcc.h
@@ -125,8 +125,8 @@ inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
// ensure that no later memory access can be reordered ahead of the operation.
// "Release" operations ensure that no previous memory access can be reordered
// after the operation. "Barrier" operations have both "Acquire" and "Release"
-// semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory
-// access.
+// semantics. A MemoryBarrierInternal() has "Barrier" semantics, but does no
+// memory access.
inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
@@ -149,17 +149,17 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
}
-inline void MemoryBarrier() {
+inline void MemoryBarrierInternal() {
__asm__ __volatile__("sync" : : : "memory");
}
inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
- MemoryBarrier();
+ MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
- MemoryBarrier();
+ MemoryBarrierInternal();
*ptr = value;
}
@@ -169,12 +169,12 @@ inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
Atomic32 value = *ptr;
- MemoryBarrier();
+ MemoryBarrierInternal();
return value;
}
inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
- MemoryBarrier();
+ MemoryBarrierInternal();
return *ptr;
}
@@ -247,9 +247,9 @@ inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr,
inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
Atomic64 increment) {
- MemoryBarrier();
+ MemoryBarrierInternal();
Atomic64 res = NoBarrier_AtomicIncrement(ptr, increment);
- MemoryBarrier();
+ MemoryBarrierInternal();
return res;
}
@@ -257,20 +257,20 @@ inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
// ensure that no later memory access can be reordered ahead of the operation.
// "Release" operations ensure that no previous memory access can be reordered
// after the operation. "Barrier" operations have both "Acquire" and "Release"
-// semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory
-// access.
+// semantics. A MemoryBarrierInternal() has "Barrier" semantics, but does no
+// memory access.
inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
Atomic64 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
- MemoryBarrier();
+ MemoryBarrierInternal();
return res;
}
inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
- MemoryBarrier();
+ MemoryBarrierInternal();
return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
}
@@ -280,11 +280,11 @@ inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
*ptr = value;
- MemoryBarrier();
+ MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
- MemoryBarrier();
+ MemoryBarrierInternal();
*ptr = value;
}
@@ -294,12 +294,12 @@ inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
Atomic64 value = *ptr;
- MemoryBarrier();
+ MemoryBarrierInternal();
return value;
}
inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
- MemoryBarrier();
+ MemoryBarrierInternal();
return *ptr;
}
#endif
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_power.h b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_power.h
index b8a42f21f0..cad9f1e354 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_power.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_power.h
@@ -93,7 +93,7 @@ inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
return result;
}
-inline void MemoryBarrier(void) {
+inline void MemoryBarrierInternal(void) {
asm volatile (
" lwsync \n\t"
" isync \n\t"
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_ppc_gcc.h b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_ppc_gcc.h
index 8231a578f3..d477dc6dda 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_ppc_gcc.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_ppc_gcc.h
@@ -97,22 +97,22 @@ inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32 *ptr,
inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32 *ptr,
Atomic32 increment) {
- MemoryBarrier();
+ MemoryBarrierInternal();
Atomic32 res = NoBarrier_AtomicIncrement(ptr, increment);
- MemoryBarrier();
+ MemoryBarrierInternal();
return res;
}
inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32 *ptr,
Atomic32 old_value, Atomic32 new_value) {
Atomic32 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
- MemoryBarrier();
+ MemoryBarrierInternal();
return res;
}
inline Atomic32 Release_CompareAndSwap(volatile Atomic32 *ptr,
Atomic32 old_value, Atomic32 new_value) {
- MemoryBarrier();
+ MemoryBarrierInternal();
Atomic32 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
return res;
}
@@ -121,15 +121,15 @@ inline void NoBarrier_Store(volatile Atomic32 *ptr, Atomic32 value) {
*ptr = value;
}
-inline void MemoryBarrier() { __asm__ __volatile__("sync" : : : "memory"); }
+inline void MemoryBarrierInternal() { __asm__ __volatile__("sync" : : : "memory"); }
inline void Acquire_Store(volatile Atomic32 *ptr, Atomic32 value) {
*ptr = value;
- MemoryBarrier();
+ MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic32 *ptr, Atomic32 value) {
- MemoryBarrier();
+ MemoryBarrierInternal();
*ptr = value;
}
@@ -137,12 +137,12 @@ inline Atomic32 NoBarrier_Load(volatile const Atomic32 *ptr) { return *ptr; }
inline Atomic32 Acquire_Load(volatile const Atomic32 *ptr) {
Atomic32 value = *ptr;
- MemoryBarrier();
+ MemoryBarrierInternal();
return value;
}
inline Atomic32 Release_Load(volatile const Atomic32 *ptr) {
- MemoryBarrier();
+ MemoryBarrierInternal();
return *ptr;
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_solaris.h b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_solaris.h
index d8057ecdea..baecb993bc 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_solaris.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_solaris.h
@@ -54,16 +54,16 @@ inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
return (Atomic32)atomic_add_32_nv((volatile uint32_t*)ptr, (uint32_t)increment);
}
-inline void MemoryBarrier(void) {
+inline void MemoryBarrierInternal(void) {
membar_producer();
membar_consumer();
}
inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
Atomic32 increment) {
- MemoryBarrier();
+ MemoryBarrierInternal();
Atomic32 ret = NoBarrier_AtomicIncrement(ptr, increment);
- MemoryBarrier();
+ MemoryBarrierInternal();
return ret;
}
@@ -72,7 +72,7 @@ inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
Atomic32 ret = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
- MemoryBarrier();
+ MemoryBarrierInternal();
return ret;
}
@@ -80,7 +80,7 @@ inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
Atomic32 old_value,
Atomic32 new_value) {
- MemoryBarrier();
+ MemoryBarrierInternal();
return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
}
@@ -129,9 +129,9 @@ inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 incre
}
inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment) {
- MemoryBarrier();
+ MemoryBarrierInternal();
Atomic64 ret = atomic_add_64_nv((volatile uint64_t*)ptr, increment);
- MemoryBarrier();
+ MemoryBarrierInternal();
return ret;
}
@@ -139,14 +139,14 @@ inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
Atomic64 ret = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
- MemoryBarrier();
+ MemoryBarrierInternal();
return ret;
}
inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
Atomic64 old_value,
Atomic64 new_value) {
- MemoryBarrier();
+ MemoryBarrierInternal();
return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_tsan.h b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_tsan.h
index 0c903545cd..676380b1d5 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_tsan.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_tsan.h
@@ -206,7 +206,7 @@ inline Atomic64 Release_CompareAndSwap(volatile Atomic64 *ptr,
return cmp;
}
-inline void MemoryBarrier() {
+inline void MemoryBarrierInternal() {
__tsan_atomic_thread_fence(__tsan_memory_order_seq_cst);
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc
index 53c9eae0fa..53c9eae0fa 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h
index edccc59dee..e80121fdf8 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h
@@ -119,18 +119,18 @@ inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
// 64-bit implementations of memory barrier can be simpler, because it
// "mfence" is guaranteed to exist.
-inline void MemoryBarrier() {
+inline void MemoryBarrierInternal() {
__asm__ __volatile__("mfence" : : : "memory");
}
inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
*ptr = value;
- MemoryBarrier();
+ MemoryBarrierInternal();
}
#else
-inline void MemoryBarrier() {
+inline void MemoryBarrierInternal() {
if (AtomicOps_Internalx86CPUFeatures.has_sse2) {
__asm__ __volatile__("mfence" : : : "memory");
} else { // mfence is faster but not present on PIII
@@ -168,7 +168,7 @@ inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
}
inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
- MemoryBarrier();
+ MemoryBarrierInternal();
return *ptr;
}
@@ -225,7 +225,7 @@ inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
*ptr = value;
- MemoryBarrier();
+ MemoryBarrierInternal();
}
inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
@@ -262,7 +262,7 @@ inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
}
inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
- MemoryBarrier();
+ MemoryBarrierInternal();
return *ptr;
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc
index 741b164f0f..74a1bd4e06 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc
@@ -44,9 +44,10 @@ namespace google {
namespace protobuf {
namespace internal {
-inline void MemoryBarrier() {
- // We use MemoryBarrier from WinNT.h
- ::MemoryBarrier();
+inline void MemoryBarrierInternal() {
+ // On ARM this is a define while on x86/x64 this is
+ // a function declared in WinNT.h
+ MemoryBarrier();
}
Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_x86_msvc.h b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_msvc.h
index e53a641f09..34d60d98e0 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/atomicops_internals_x86_msvc.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_msvc.h
@@ -82,7 +82,7 @@ inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
}
inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
- MemoryBarrier();
+ MemoryBarrierInternal();
return *ptr;
}
@@ -125,7 +125,7 @@ inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
}
inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
- MemoryBarrier();
+ MemoryBarrierInternal();
return *ptr;
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/bytestream.cc b/third_party/protobuf/src/google/protobuf/stubs/bytestream.cc
index f4af6a50ab..f4af6a50ab 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/bytestream.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/bytestream.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/bytestream.h b/third_party/protobuf/src/google/protobuf/stubs/bytestream.h
index 07604e17a0..86510d140b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/bytestream.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/bytestream.h
@@ -64,7 +64,7 @@ namespace protobuf {
namespace strings {
// An abstract interface for an object that consumes a sequence of bytes. This
-// interface offers 3 different ways to append data, and a Flush() function.
+// interface offers a way to append data as well as a Flush() function.
//
// Example:
//
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/bytestream_unittest.cc b/third_party/protobuf/src/google/protobuf/stubs/bytestream_unittest.cc
index 06f114abc7..06f114abc7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/bytestream_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/bytestream_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/callback.h b/third_party/protobuf/src/google/protobuf/stubs/callback.h
index 87271c5eb8..9ec0497955 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/callback.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/callback.h
@@ -346,6 +346,29 @@ struct InternalConstRef {
typedef const base_type& type;
};
+template<typename R, typename T>
+class MethodResultCallback_0_0 : public ResultCallback<R> {
+ public:
+ typedef R (T::*MethodType)();
+ MethodResultCallback_0_0(T* object, MethodType method, bool self_deleting)
+ : object_(object),
+ method_(method),
+ self_deleting_(self_deleting) {}
+ ~MethodResultCallback_0_0() {}
+
+ R Run() {
+ bool needs_delete = self_deleting_;
+ R result = (object_->*method_)();
+ if (needs_delete) delete this;
+ return result;
+ }
+
+ private:
+ T* object_;
+ MethodType method_;
+ bool self_deleting_;
+};
+
template <typename R, typename T, typename P1, typename P2, typename P3,
typename P4, typename P5, typename A1, typename A2>
class MethodResultCallback_5_2 : public ResultCallback2<R, A1, A2> {
@@ -381,6 +404,8 @@ class MethodResultCallback_5_2 : public ResultCallback2<R, A1, A2> {
typename remove_reference<P5>::type p5_;
};
+} // namespace internal
+
// See Closure.
inline Closure* NewCallback(void (*function)()) {
return new internal::FunctionClosure0(function, true);
@@ -518,6 +543,13 @@ inline ResultCallback1<R, A1>* NewPermanentCallback(
function, false, p1);
}
+// See MethodResultCallback_0_0
+template <typename R, typename T1, typename T2>
+inline ResultCallback<R>* NewPermanentCallback(
+ T1* object, R (T2::*function)()) {
+ return new internal::MethodResultCallback_0_0<R, T1>(object, function, false);
+}
+
// See MethodResultCallback_5_2
template <typename R, typename T, typename P1, typename P2, typename P3,
typename P4, typename P5, typename A1, typename A2>
@@ -533,8 +565,6 @@ inline ResultCallback2<R, A1, A2>* NewPermanentCallback(
p2, p3, p4, p5);
}
-} // namespace internal
-
// A function which does nothing. Useful for creating no-op callbacks, e.g.:
// Closure* nothing = NewCallback(&DoNothing);
void LIBPROTOBUF_EXPORT DoNothing();
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/casts.h b/third_party/protobuf/src/google/protobuf/stubs/casts.h
index be652849ef..be652849ef 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/casts.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/casts.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/common.cc b/third_party/protobuf/src/google/protobuf/stubs/common.cc
index 54dbafab5d..146559164f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/common.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/common.cc
@@ -108,11 +108,17 @@ string VersionString(int version) {
// ===================================================================
// emulates google3/base/logging.cc
+// If the minimum logging level is not set, we default to logging messages for
+// all levels.
+#ifndef GOOGLE_PROTOBUF_MIN_LOG_LEVEL
+#define GOOGLE_PROTOBUF_MIN_LOG_LEVEL LOGLEVEL_INFO
+#endif
+
namespace internal {
+
#if defined(__ANDROID__)
inline void DefaultLogHandler(LogLevel level, const char* filename, int line,
const string& message) {
-#ifdef GOOGLE_PROTOBUF_MIN_LOG_LEVEL
if (level < GOOGLE_PROTOBUF_MIN_LOG_LEVEL) {
return;
}
@@ -143,11 +149,14 @@ inline void DefaultLogHandler(LogLevel level, const char* filename, int line,
__android_log_write(ANDROID_LOG_FATAL, "libprotobuf-native",
"terminating.\n");
}
-#endif
}
+
#else
void DefaultLogHandler(LogLevel level, const char* filename, int line,
const string& message) {
+ if (level < GOOGLE_PROTOBUF_MIN_LOG_LEVEL) {
+ return;
+ }
static const char* level_names[] = { "INFO", "WARNING", "ERROR", "FATAL" };
// We use fprintf() instead of cerr because we want this to work at static
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/common.h b/third_party/protobuf/src/google/protobuf/stubs/common.h
index 9c05cac360..d261149803 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/common.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/common.h
@@ -96,24 +96,27 @@ namespace internal {
// The current version, represented as a single integer to make comparison
// easier: major * 10^6 + minor * 10^3 + micro
-#define GOOGLE_PROTOBUF_VERSION 3000000
+#define GOOGLE_PROTOBUF_VERSION 3002000
+
+// A suffix string for alpha, beta or rc releases. Empty for stable releases.
+#define GOOGLE_PROTOBUF_VERSION_SUFFIX ""
// The minimum library version which works with the current version of the
// headers.
-#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3000000
+#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3002000
// The minimum header version which works with the current version of
// the library. This constant should only be used by protoc's C++ code
// generator.
-static const int kMinHeaderVersionForLibrary = 3000000;
+static const int kMinHeaderVersionForLibrary = 3002000;
// The minimum protoc version which works with the current version of the
// headers.
-#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 3000000
+#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 3002000
// The minimum header version which works with the current version of
// protoc. This constant should only be used in VerifyVersion().
-static const int kMinHeaderVersionForProtoc = 3000000;
+static const int kMinHeaderVersionForProtoc = 3002000;
// Verifies that the headers and libraries are compatible. Use the macro
// below to call this.
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/common_unittest.cc b/third_party/protobuf/src/google/protobuf/stubs/common_unittest.cc
index 25bae9b074..f9e2cfd437 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/common_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/common_unittest.cc
@@ -41,8 +41,6 @@
namespace google {
namespace protobuf {
-using internal::NewCallback;
-using internal::NewPermanentCallback;
namespace {
// TODO(kenton): More tests.
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/fastmem.h b/third_party/protobuf/src/google/protobuf/stubs/fastmem.h
index 763a6e6024..763a6e6024 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/fastmem.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/fastmem.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/hash.h b/third_party/protobuf/src/google/protobuf/stubs/hash.h
index 4eac7d5d25..be998b29d9 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/hash.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/hash.h
@@ -40,16 +40,12 @@
#define GOOGLE_PROTOBUF_HAVE_HASH_MAP 1
#define GOOGLE_PROTOBUF_HAVE_HASH_SET 1
-
-// Android
-#if defined(__ANDROID__)
-# undef GOOGLE_PROTOBUF_HAVE_HASH_MAP
-# undef GOOGLE_PROTOBUF_HAVE_HASH_MAP
+#define GOOGLE_PROTOBUF_HAVE_64BIT_HASH 1
// Use C++11 unordered_{map|set} if available.
-#elif ((_LIBCPP_STD_VER >= 11) || \
- (((__cplusplus >= 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X)) && \
- (__GLIBCXX__ > 20090421)))
+#if ((_LIBCPP_STD_VER >= 11) || \
+ (((__cplusplus >= 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X)) && \
+ (__GLIBCXX__ > 20090421)))
# define GOOGLE_PROTOBUF_HAS_CXX11_HASH
// For XCode >= 4.6: the compiler is clang with libc++.
@@ -97,6 +93,10 @@
# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set
# endif
+# if __GNUC__ == 4 && __GNUC__MINOR__ <= 1
+# undef GOOGLE_PROTOBUF_HAVE_64BIT_HASH
+# endif
+
// Version checks for MSC.
// Apparently Microsoft decided to move hash_map *back* to the std namespace in
// MSVC 2010:
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/int128.cc b/third_party/protobuf/src/google/protobuf/stubs/int128.cc
index a509080148..a509080148 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/int128.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/int128.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/int128.h b/third_party/protobuf/src/google/protobuf/stubs/int128.h
index 1499bb76d5..1499bb76d5 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/int128.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/int128.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/int128_unittest.cc b/third_party/protobuf/src/google/protobuf/stubs/int128_unittest.cc
index 5d33292ccc..5d33292ccc 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/int128_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/int128_unittest.cc
diff --git a/third_party/protobuf/src/google/protobuf/stubs/io_win32.cc b/third_party/protobuf/src/google/protobuf/stubs/io_win32.cc
new file mode 100644
index 0000000000..b5f1cdf0b7
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/stubs/io_win32.cc
@@ -0,0 +1,281 @@
+// 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.
+
+// Author: laszlocsomor@google.com (Laszlo Csomor)
+//
+// Implementation for long-path-aware open/mkdir/access on Windows.
+//
+// These functions convert the input path to an absolute Windows path
+// with UNC prefix if necessary, then pass that to
+// _wopen/_wmkdir/_waccess (declared in <io.h>) respectively. This
+// allows working with files/directories whose paths are longer than
+// MAX_PATH (260 chars).
+//
+// This file is only used on Windows, it's empty on other platforms.
+
+#if defined(_WIN32)
+
+#include <ctype.h>
+#include <errno.h>
+#include <wctype.h>
+
+#include <google/protobuf/stubs/io_win32.h>
+
+#include <cassert>
+#include <memory>
+#include <sstream>
+#include <string>
+#include <vector>
+
+namespace google {
+namespace protobuf {
+namespace stubs {
+namespace {
+
+using std::string;
+using std::unique_ptr;
+using std::wstring;
+
+template <typename char_type>
+struct CharTraits {
+ static bool is_alpha(char_type ch);
+};
+
+template <>
+struct CharTraits<char> {
+ static bool is_alpha(char ch) { return isalpha(ch); }
+};
+
+template <>
+struct CharTraits<wchar_t> {
+ static bool is_alpha(wchar_t ch) { return iswalpha(ch); }
+};
+
+template <typename char_type>
+bool has_drive_letter(const char_type* ch) {
+ return CharTraits<char_type>::is_alpha(ch[0]) && ch[1] == ':';
+}
+
+template <typename char_type>
+bool has_unc_prefix(const std::basic_string<char_type>& path) {
+ return path.size() > 4 && path[0] == '\\' && path[1] == '\\' &&
+ path[2] == '?' && path[3] == '\\';
+}
+
+template <typename char_type>
+bool is_path_absolute(const std::basic_string<char_type>& path) {
+ return (path.size() > 2 && path[1] == ':') || has_unc_prefix(path);
+}
+
+template <typename char_type>
+bool is_separator(char_type c) {
+ return c == '/' || c == '\\';
+}
+
+bool is_drive_relative(const string& s) {
+ return s.size() >= 2 && isalpha(s[0]) && s[1] == ':' &&
+ (s.size() == 2 || !is_separator(s[2]));
+}
+
+void replace_directory_separators(WCHAR* p) {
+ for (; *p != L'\0'; ++p) {
+ if (*p == L'/') {
+ *p = L'\\';
+ }
+ }
+}
+
+wstring get_cwd() {
+ DWORD result = ::GetCurrentDirectoryW(0, NULL);
+ std::unique_ptr<WCHAR[]> cwd(new WCHAR[result]);
+ ::GetCurrentDirectoryW(result, cwd.get());
+ cwd.get()[result - 1] = 0;
+ replace_directory_separators(cwd.get());
+ return std::move(wstring(cwd.get()));
+}
+
+wstring join_paths(const wstring& path1, const wstring& path2) {
+ if (path1.empty() || is_path_absolute(path2)) {
+ return path2;
+ }
+ if (path2.empty()) {
+ return path1;
+ }
+
+ if (is_separator(path1.back())) {
+ return is_separator(path2.front()) ? (path1 + path2.substr(1))
+ : (path1 + path2);
+ } else {
+ return is_separator(path2.front()) ? (path1 + path2)
+ : (path1 + L'\\' + path2);
+ }
+}
+
+string normalize(string path) {
+ if (has_unc_prefix(path)) {
+ path = path.substr(4);
+ }
+
+ static const string dot(".");
+ static const string dotdot("..");
+
+ std::vector<string> segments;
+ int segment_start = -1;
+ // Find the path segments in `path` (separated by "/").
+ for (int i = 0;; ++i) {
+ if (!is_separator(path[i]) && path[i] != '\0') {
+ // The current character does not end a segment, so start one unless it's
+ // already started.
+ if (segment_start < 0) {
+ segment_start = i;
+ }
+ } else if (segment_start >= 0 && i > segment_start) {
+ // The current character is "/" or "\0", so this ends a segment.
+ // Add that to `segments` if there's anything to add; handle "." and "..".
+ string segment(path, segment_start, i - segment_start);
+ segment_start = -1;
+ if (segment == dotdot) {
+ if (!segments.empty() && !has_drive_letter(segments[0].c_str())) {
+ segments.pop_back();
+ }
+ } else if (segment != dot) {
+ segments.push_back(segment);
+ }
+ }
+ if (path[i] == '\0') {
+ break;
+ }
+ }
+
+ // Handle the case when `path` is just a drive specifier (or some degenerate
+ // form of it, e.g. "c:\..").
+ if (segments.size() == 1 && segments[0].size() == 2 &&
+ has_drive_letter(segments[0].c_str())) {
+ return segments[0] + '\\';
+ }
+
+ // Join all segments.
+ bool first = true;
+ std::ostringstream result;
+ for (const auto& s : segments) {
+ if (!first) {
+ result << '\\';
+ }
+ first = false;
+ result << s;
+ }
+ return result.str();
+}
+
+wstring as_wchar_path(const string& path) {
+ int len =
+ ::MultiByteToWideChar(CP_UTF8, 0, path.c_str(), path.size(), NULL, 0);
+ std::unique_ptr<WCHAR[]> wbuf(new WCHAR[len + 1]);
+ ::MultiByteToWideChar(CP_UTF8, 0, path.c_str(), path.size(), wbuf.get(),
+ len + 1);
+ wbuf.get()[len] = 0;
+ replace_directory_separators(wbuf.get());
+ return std::move(wstring(wbuf.get()));
+}
+
+bool as_windows_path(const string& path, size_t max_path,
+ wstring* result) {
+ if (path.empty()) {
+ result->clear();
+ return true;
+ }
+ if (is_separator(path[0]) || is_drive_relative(path)) {
+ return false;
+ }
+
+ *result = as_wchar_path(normalize(path));
+ if (!is_path_absolute(path)) {
+ *result = join_paths(get_cwd(), *result);
+ }
+ if (result->size() >= max_path && !has_unc_prefix(*result)) {
+ *result = wstring(L"\\\\?\\") + *result;
+ }
+ return true;
+}
+
+} // namespace
+
+int win32_open(const char* path, int flags, int mode) {
+ wstring wpath;
+ if (!as_windows_path(path, MAX_PATH, &wpath)) {
+ errno = ENOENT;
+ return -1;
+ }
+ return ::_wopen(wpath.c_str(), flags, mode);
+}
+
+int win32_mkdir(const char* path, int _mode) {
+ // CreateDirectoryA's limit is 248 chars, see MSDN.
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx
+ // This limit presumably includes the null-terminator, because other
+ // functions that have the MAX_PATH limit, such as CreateFileA,
+ // actually include it.
+ wstring wpath;
+ if (!as_windows_path(path, 248, &wpath)) {
+ errno = ENOENT;
+ return -1;
+ }
+ return ::_wmkdir(wpath.c_str());
+}
+
+int win32_access(const char* path, int mode) {
+ // _access/_waccess in <io.h> don't support checking for executability (nor is
+ // X_OK defined).
+ // They support checking for readability (but R_OK is not defined) but we
+ // never use them for that in the protobuf source code.
+ // Existence and writability check are also supported, but again F_OK and W_OK
+ // aren't defined as constants in <io.h>; they are defined in io_win32.h
+ // Therefore we only support F_OK and W_OK.
+ assert(mode & ~(F_OK | W_OK) == 0);
+ wstring wpath;
+ if (!as_windows_path(path, MAX_PATH, &wpath)) {
+ errno = ENOENT;
+ return -1;
+ }
+ return ::_waccess(wpath.c_str(), mode);
+}
+
+wstring testonly_path_to_winpath(const string& path, size_t max_path) {
+ wstring wpath;
+ as_windows_path(path, max_path, &wpath);
+ return wpath;
+}
+
+} // namespace stubs
+} // namespace protobuf
+} // namespace google
+
+#endif // defined(_WIN32)
+
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/io/io_win32.h b/third_party/protobuf/src/google/protobuf/stubs/io_win32.h
index 45050a28b7..0716faaa78 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/io/io_win32.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/io_win32.h
@@ -34,41 +34,55 @@
// commonly used POSIX functions such as open(2) and access(2), as well
// as macro definitions for flags of these functions.
//
+// By including this file you'll redefine open/access/mkdir to
+// ::google::protobuf::stubs::win32_{open/access/mkdir}.
+// Make sure you don't include a header that attempts to redeclare or
+// redefine these functions, that'll lead to confusing compilation
+// errors.
+//
// This file is only used on Windows, it's empty on other platforms.
-#ifndef GOOGLE_PROTOBUF_IO_IO_WIN32_H__
-#define GOOGLE_PROTOBUF_IO_IO_WIN32_H__
+#ifndef GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__
+#define GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__
#if defined(_WIN32)
+#include <direct.h>
+#include <fcntl.h>
+#include <io.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <windows.h>
+
+#include <string>
+
namespace google {
namespace protobuf {
-namespace io {
-namespace win32 {
+namespace stubs {
-int open(const char* path, int flags, int mode = 0);
-int mkdir(const char* name, int _mode);
-int access(const char* pathname, int mode);
+int win32_open(const char* path, int flags, int mode = 0);
+int win32_mkdir(const char* name, int _mode);
+int win32_access(const char* pathname, int mode);
+std::wstring testonly_path_to_winpath(const std::string& path, size_t max_path);
-} // namespace win32
-} // namespace io
+} // namespace stubs
} // namespace protobuf
} // namespace google
#ifdef open
#undef open
#endif
-#define open ::google::protobuf::io::win32::open
+#define open ::google::protobuf::stubs::win32_open
#ifdef mkdir
#undef mkdir
#endif
-#define mkdir ::google::protobuf::io::win32::mkdir
+#define mkdir ::google::protobuf::stubs::win32_mkdir
#ifdef access
#undef access
#endif
-#define access ::google::protobuf::io::win32::access
+#define access ::google::protobuf::stubs::win32_access
#ifndef W_OK
#define W_OK 02 // not defined by MSVC for whatever reason
@@ -88,4 +102,5 @@ int access(const char* pathname, int mode);
#endif // defined(_WIN32)
-#endif // GOOGLE_PROTOBUF_IO_IO_WIN32_H__
+#endif // GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__
+
diff --git a/third_party/protobuf/src/google/protobuf/stubs/io_win32_unittest.cc b/third_party/protobuf/src/google/protobuf/stubs/io_win32_unittest.cc
new file mode 100644
index 0000000000..fb3d5f7244
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/stubs/io_win32_unittest.cc
@@ -0,0 +1,268 @@
+// 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.
+
+// Author: laszlocsomor@google.com (Laszlo Csomor)
+//
+// Unit tests for long-path-aware open/mkdir/access on Windows.
+//
+// This file is only used on Windows, it's empty on other platforms.
+
+#if defined(_WIN32)
+
+#define WIN32_LEAN_AND_MEAN
+#include <errno.h>
+#include <stdlib.h>
+#include <windows.h>
+
+#include <google/protobuf/stubs/io_win32.h>
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <string>
+
+namespace google {
+namespace protobuf {
+namespace stubs {
+namespace {
+
+using std::string;
+using std::unique_ptr;
+using std::wstring;
+
+class IoWin32Test : public ::testing::Test {
+ public:
+ void SetUp() override;
+ void TearDown() override;
+
+ protected:
+ static bool DeleteAllUnder(wstring path);
+
+ string test_tmpdir;
+ wstring wtest_tmpdir;
+};
+
+#define ASSERT_INITIALIZED \
+ { \
+ EXPECT_FALSE(test_tmpdir.empty()); \
+ EXPECT_FALSE(wtest_tmpdir.empty()); \
+ }
+
+void IoWin32Test::SetUp() {
+ test_tmpdir.clear();
+ wtest_tmpdir.clear();
+
+ const char* test_tmpdir_env = getenv("TEST_TMPDIR");
+ if (test_tmpdir_env == nullptr || *test_tmpdir_env == 0) {
+ // Using assertions in SetUp/TearDown seems to confuse the test framework,
+ // so just leave the member variables empty in case of failure.
+ return;
+ }
+
+ test_tmpdir = string(test_tmpdir_env);
+ while (test_tmpdir.back() == '/' || test_tmpdir.back() == '\\') {
+ test_tmpdir.pop_back();
+ }
+
+ // CreateDirectoryA's limit is 248 chars, see MSDN.
+ // https://msdn.microsoft.com/en-us/library/windows/ \
+ // desktop/aa363855(v=vs.85).aspx
+ wtest_tmpdir = testonly_path_to_winpath(test_tmpdir, 248);
+}
+
+void IoWin32Test::TearDown() {
+ if (!wtest_tmpdir.empty()) {
+ DeleteAllUnder(wtest_tmpdir);
+ }
+}
+
+bool IoWin32Test::DeleteAllUnder(wstring path) {
+ static const wstring kDot(L".");
+ static const wstring kDotDot(L"..");
+
+ // Prepend UNC prefix if the path doesn't have it already. Don't bother
+ // checking if the path is shorter than MAX_PATH, let's just do it
+ // unconditionally.
+ if (path.find(L"\\\\?\\") != 0) {
+ path = wstring(L"\\\\?\\") + path;
+ }
+ // Append "\" if necessary.
+ if (path.back() != '\\') {
+ path.push_back('\\');
+ }
+
+ WIN32_FIND_DATAW metadata;
+ HANDLE handle = ::FindFirstFileW((path + L"*").c_str(), &metadata);
+ if (handle == INVALID_HANDLE_VALUE) {
+ return true; // directory doesn't exist
+ }
+
+ bool result = true;
+ do {
+ wstring childname = metadata.cFileName;
+ if (kDot != childname && kDotDot != childname) {
+ wstring childpath = path + childname;
+ if ((metadata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) {
+ // If this is not a junction, delete its contents recursively.
+ // Finally delete this directory/junction too.
+ if (((metadata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) == 0 &&
+ !DeleteAllUnder(childpath)) ||
+ !::RemoveDirectoryW(childpath.c_str())) {
+ result = false;
+ break;
+ }
+ } else {
+ if (!::DeleteFileW(childpath.c_str())) {
+ result = false;
+ break;
+ }
+ }
+ }
+ } while (::FindNextFileW(handle, &metadata));
+ ::FindClose(handle);
+ return result;
+}
+
+TEST_F(IoWin32Test, AccessTest) {
+ ASSERT_INITIALIZED;
+
+ string path = test_tmpdir;
+ while (path.size() < MAX_PATH - 30) {
+ path += "\\accesstest";
+ EXPECT_EQ(mkdir(path.c_str(), 0644), 0);
+ }
+ string file = path + "\\file.txt";
+ int fd = open(file.c_str(), O_CREAT | O_WRONLY, 0644);
+ EXPECT_GT(fd, 0);
+ EXPECT_EQ(close(fd), 0);
+
+ EXPECT_EQ(access(test_tmpdir.c_str(), F_OK), 0);
+ EXPECT_EQ(access(path.c_str(), F_OK), 0);
+ EXPECT_EQ(access(path.c_str(), W_OK), 0);
+ EXPECT_EQ(access(file.c_str(), F_OK | W_OK), 0);
+ EXPECT_NE(access((file + ".blah").c_str(), F_OK), 0);
+ EXPECT_NE(access((file + ".blah").c_str(), W_OK), 0);
+
+ // chdir into the test_tmpdir, because the current working directory must
+ // always be shorter than MAX_PATH, even with "\\?\" prefix (except on
+ // Windows 10 version 1607 and beyond, after opting in to long paths by
+ // default [1]).
+ //
+ // [1] https://msdn.microsoft.com/en-us/library/windows/ \
+ // desktop/aa365247(v=vs.85).aspx#maxpath
+ EXPECT_EQ(_chdir(test_tmpdir.c_str()), 0);
+ EXPECT_EQ(access(".", F_OK), 0);
+ EXPECT_EQ(access(".", W_OK), 0);
+ EXPECT_EQ(access("accesstest", F_OK | W_OK), 0);
+ ASSERT_EQ(access("./normalize_me/../.././accesstest", F_OK | W_OK), 0);
+ EXPECT_NE(access("blah", F_OK), 0);
+ EXPECT_NE(access("blah", W_OK), 0);
+
+ ASSERT_EQ(access("c:bad", F_OK), -1);
+ ASSERT_EQ(errno, ENOENT);
+ ASSERT_EQ(access("/tmp/bad", F_OK), -1);
+ ASSERT_EQ(errno, ENOENT);
+ ASSERT_EQ(access("\\bad", F_OK), -1);
+ ASSERT_EQ(errno, ENOENT);
+}
+
+TEST_F(IoWin32Test, OpenTest) {
+ ASSERT_INITIALIZED;
+
+ string path = test_tmpdir;
+ while (path.size() < MAX_PATH) {
+ path += "\\opentest";
+ EXPECT_EQ(mkdir(path.c_str(), 0644), 0);
+ }
+ string file = path + "\\file.txt";
+ int fd = open(file.c_str(), O_CREAT | O_WRONLY, 0644);
+ ASSERT_GT(fd, 0);
+ EXPECT_EQ(write(fd, "hello", 5), 5);
+ EXPECT_EQ(close(fd), 0);
+
+ // chdir into the test_tmpdir, because the current working directory must
+ // always be shorter than MAX_PATH, even with "\\?\" prefix (except on
+ // Windows 10 version 1607 and beyond, after opting in to long paths by
+ // default [1]).
+ //
+ // [1] https://msdn.microsoft.com/en-us/library/windows/ \
+ // desktop/aa365247(v=vs.85).aspx#maxpath
+ EXPECT_EQ(_chdir(test_tmpdir.c_str()), 0);
+ fd = open("file-relative.txt", O_CREAT | O_WRONLY, 0644);
+ ASSERT_GT(fd, 0);
+ EXPECT_EQ(write(fd, "hello", 5), 5);
+ EXPECT_EQ(close(fd), 0);
+
+ fd = open("./normalize_me/../.././file-relative.txt", O_RDONLY);
+ ASSERT_GT(fd, 0);
+ EXPECT_EQ(close(fd), 0);
+
+ ASSERT_EQ(open("c:bad.txt", O_CREAT | O_WRONLY, 0644), -1);
+ ASSERT_EQ(errno, ENOENT);
+ ASSERT_EQ(open("/tmp/bad.txt", O_CREAT | O_WRONLY, 0644), -1);
+ ASSERT_EQ(errno, ENOENT);
+ ASSERT_EQ(open("\\bad.txt", O_CREAT | O_WRONLY, 0644), -1);
+ ASSERT_EQ(errno, ENOENT);
+}
+
+TEST_F(IoWin32Test, MkdirTest) {
+ ASSERT_INITIALIZED;
+
+ string path = test_tmpdir;
+ do {
+ path += "\\mkdirtest";
+ ASSERT_EQ(mkdir(path.c_str(), 0644), 0);
+ } while (path.size() <= MAX_PATH);
+
+ // chdir into the test_tmpdir, because the current working directory must
+ // always be shorter than MAX_PATH, even with "\\?\" prefix (except on
+ // Windows 10 version 1607 and beyond, after opting in to long paths by
+ // default [1]).
+ //
+ // [1] https://msdn.microsoft.com/en-us/library/windows/ \
+ // desktop/aa365247(v=vs.85).aspx#maxpath
+ EXPECT_EQ(_chdir(test_tmpdir.c_str()), 0);
+ ASSERT_EQ(mkdir("relative_mkdirtest", 0644), 0);
+ ASSERT_EQ(mkdir("./normalize_me/../.././blah", 0644), 0);
+
+ ASSERT_EQ(mkdir("c:bad", 0644), -1);
+ ASSERT_EQ(errno, ENOENT);
+ ASSERT_EQ(mkdir("/tmp/bad", 0644), -1);
+ ASSERT_EQ(errno, ENOENT);
+ ASSERT_EQ(mkdir("\\bad", 0644), -1);
+ ASSERT_EQ(errno, ENOENT);
+}
+
+} // namespace
+} // namespace stubs
+} // namespace protobuf
+} // namespace google
+
+#endif // defined(_WIN32)
+
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/logging.h b/third_party/protobuf/src/google/protobuf/stubs/logging.h
index f69605d9f6..f69605d9f6 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/logging.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/logging.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/macros.h b/third_party/protobuf/src/google/protobuf/stubs/macros.h
index 0e9a9ec198..0e9a9ec198 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/macros.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/macros.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/map_util.h b/third_party/protobuf/src/google/protobuf/stubs/map_util.h
index 4cccbbedcb..887f12a600 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/map_util.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/map_util.h
@@ -208,7 +208,7 @@ typename Collection::value_type::second_type::element_type&
FindLinkedPtrOrDie(const Collection& collection,
const typename Collection::value_type::first_type& key) {
typename Collection::const_iterator it = collection.find(key);
- CHECK(it != collection.end()) << "key not found: " << key;
+ GOOGLE_CHECK(it != collection.end()) << "key not found: " << key;
// Since linked_ptr::operator*() is a const member returning a non const,
// we do not need a version of this function taking a non const collection.
return *it->second;
@@ -337,14 +337,15 @@ bool InsertIfNotPresent(
template <class Collection>
void InsertOrDie(Collection* const collection,
const typename Collection::value_type& value) {
- CHECK(InsertIfNotPresent(collection, value)) << "duplicate value: " << value;
+ GOOGLE_CHECK(InsertIfNotPresent(collection, value))
+ << "duplicate value: " << value;
}
// Same as above except doesn't log the value on error.
template <class Collection>
void InsertOrDieNoPrint(Collection* const collection,
const typename Collection::value_type& value) {
- CHECK(InsertIfNotPresent(collection, value)) << "duplicate value.";
+ GOOGLE_CHECK(InsertIfNotPresent(collection, value)) << "duplicate value.";
}
// Inserts the key-value pair into the collection. Dies if key was already
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/mathlimits.cc b/third_party/protobuf/src/google/protobuf/stubs/mathlimits.cc
index 0373b2bb97..0373b2bb97 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/mathlimits.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/mathlimits.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/mathlimits.h b/third_party/protobuf/src/google/protobuf/stubs/mathlimits.h
index 70e47bff18..275d9539ca 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/mathlimits.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/mathlimits.h
@@ -43,12 +43,18 @@
#ifndef UTIL_MATH_MATHLIMITS_H__
#define UTIL_MATH_MATHLIMITS_H__
-// <math.h> lacks a lot of prototypes. However, this file needs <math.h> to
-// access old-fashioned isinf et al. Even worse more: this file must not
-// include <cmath> because that breaks the definition of isinf with gcc 4.9.
-//
-// TODO(mec): after C++11 everywhere, use <cmath> and std::isinf in this file.
+// GCC 4.9 has a bug that makes it impossible to use isinf and isnan when both
+// <math.h> and <cmath> get pulled into the same translation unit.
+// Unfortunately it is difficult to prevent this from happening, so to work
+// around the problem we use std::isinf and std::isnan from <cmath> for C++11
+// builds and otherwise use the plain isinf and isnan functions from <math.h>.
+// Note that for Windows we do something different because it does not support
+// the plain isinf and isnan.
+#if __cplusplus >= 201103L
+#include <cmath>
+#else
#include <math.h>
+#endif
#include <string.h>
#include <cfloat>
@@ -220,6 +226,17 @@ DECL_UNSIGNED_INT_LIMITS(unsigned long long int)
#undef UNSIGNED_MAX_10_EXP
#undef DECL_INT_LIMIT_FUNCS
+// For non-Windows builds we use the std:: versions of isinf and isnan if they
+// are available; see the comment about <cmath> at the top of this file for the
+// details on why we need to do this.
+#if __cplusplus >= 201103L
+#define ISINF std::isinf
+#define ISNAN std::isnan
+#else
+#define ISINF isinf
+#define ISNAN isnan
+#endif
+
// ========================================================================= //
#ifdef WIN32 // Lacks built-in isnan() and isinf()
#define DECL_FP_LIMIT_FUNCS \
@@ -230,11 +247,11 @@ DECL_UNSIGNED_INT_LIMITS(unsigned long long int)
static bool IsNegInf(const Type x) { return _fpclass(x) == _FPCLASS_NINF; }
#else
#define DECL_FP_LIMIT_FUNCS \
- static bool IsFinite(const Type x) { return !isinf(x) && !isnan(x); } \
- static bool IsNaN(const Type x) { return isnan(x); } \
- static bool IsInf(const Type x) { return isinf(x); } \
- static bool IsPosInf(const Type x) { return isinf(x) && x > 0; } \
- static bool IsNegInf(const Type x) { return isinf(x) && x < 0; }
+ static bool IsFinite(const Type x) { return !ISINF(x) && !ISNAN(x); } \
+ static bool IsNaN(const Type x) { return ISNAN(x); } \
+ static bool IsInf(const Type x) { return ISINF(x); } \
+ static bool IsPosInf(const Type x) { return ISINF(x) && x > 0; } \
+ static bool IsNegInf(const Type x) { return ISINF(x) && x < 0; }
#endif
// We can't put floating-point constant values in the header here because
@@ -269,6 +286,8 @@ DECL_FP_LIMITS(float, FLT)
DECL_FP_LIMITS(double, DBL)
DECL_FP_LIMITS(long double, LDBL)
+#undef ISINF
+#undef ISNAN
#undef DECL_FP_LIMITS
#undef DECL_FP_LIMIT_FUNCS
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/mathutil.h b/third_party/protobuf/src/google/protobuf/stubs/mathutil.h
index 27956a8ea0..8a9f69a0b2 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/mathutil.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/mathutil.h
@@ -41,27 +41,6 @@ namespace google {
namespace protobuf {
namespace internal {
template<typename T>
-bool IsNan(T value) {
- return false;
-}
-template<>
-inline bool IsNan(float value) {
-#ifdef _MSC_VER
- return _isnan(value);
-#else
- return isnan(value);
-#endif
-}
-template<>
-inline bool IsNan(double value) {
-#ifdef _MSC_VER
- return _isnan(value);
-#else
- return isnan(value);
-#endif
-}
-
-template<typename T>
bool AlmostEquals(T a, T b) {
return a == b;
}
@@ -80,7 +59,7 @@ class MathUtil {
public:
template<typename T>
static T Sign(T value) {
- if (value == T(0) || ::google::protobuf::internal::IsNan<T>(value)) {
+ if (value == T(0) || MathLimits<T>::IsNaN(value)) {
return value;
}
return value > T(0) ? 1 : -1;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/mutex.h b/third_party/protobuf/src/google/protobuf/stubs/mutex.h
index 7ef1cb6916..7ef1cb6916 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/mutex.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/mutex.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/once.cc b/third_party/protobuf/src/google/protobuf/stubs/once.cc
index 889c647660..889c647660 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/once.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/once.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/once.h b/third_party/protobuf/src/google/protobuf/stubs/once.h
index 1f082c37e9..1f082c37e9 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/once.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/once.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/once_unittest.cc b/third_party/protobuf/src/google/protobuf/stubs/once_unittest.cc
index 37def58d03..d5f7779ec9 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/once_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/once_unittest.cc
@@ -43,7 +43,6 @@
namespace google {
namespace protobuf {
-using internal::NewCallback;
namespace {
class OnceInitTest : public testing::Test {
@@ -128,11 +127,11 @@ class OnceInitTest : public testing::Test {
};
TestThread* RunInitOnceInNewThread() {
- return new TestThread(internal::NewCallback(this, &OnceInitTest::InitOnce));
+ return new TestThread(NewCallback(this, &OnceInitTest::InitOnce));
}
TestThread* RunInitRecursiveOnceInNewThread() {
return new TestThread(
- internal::NewCallback(this, &OnceInitTest::InitRecursiveOnce));
+ NewCallback(this, &OnceInitTest::InitRecursiveOnce));
}
enum State {
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/platform_macros.h b/third_party/protobuf/src/google/protobuf/stubs/platform_macros.h
index 4ba4b348c7..7a54060dfa 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/platform_macros.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/platform_macros.h
@@ -47,7 +47,7 @@
#elif defined(__QNX__)
#define GOOGLE_PROTOBUF_ARCH_ARM_QNX 1
#define GOOGLE_PROTOBUF_ARCH_32_BIT 1
-#elif defined(__ARMEL__)
+#elif defined(_M_ARM) || defined(__ARMEL__)
#define GOOGLE_PROTOBUF_ARCH_ARM 1
#define GOOGLE_PROTOBUF_ARCH_32_BIT 1
#elif defined(__aarch64__)
@@ -114,11 +114,11 @@ GOOGLE_PROTOBUF_PLATFORM_ERROR
#undef GOOGLE_PROTOBUF_PLATFORM_ERROR
-#if defined(GOOGLE_PROTOBUF_OS_ANDROID) || defined(GOOGLE_PROTOBUF_OS_IPHONE)
+#if defined(GOOGLE_PROTOBUF_OS_ANDROID) || defined(GOOGLE_PROTOBUF_OS_IPHONE) || defined(__OpenBSD__)
// Android ndk does not support the __thread keyword very well yet. Here
// we use pthread_key_create()/pthread_getspecific()/... methods for
// TLS support on android.
-// iOS also does not support the __thread keyword.
+// iOS and OpenBSD also do not support the __thread keyword.
#define GOOGLE_PROTOBUF_NO_THREADLOCAL
#endif
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/port.h b/third_party/protobuf/src/google/protobuf/stubs/port.h
index d7f93b4cbd..6ec5e001fc 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/port.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/port.h
@@ -44,6 +44,8 @@
#include <stdint.h>
#endif
+#include <google/protobuf/stubs/platform_macros.h>
+
#undef PROTOBUF_LITTLE_ENDIAN
#ifdef _WIN32
// Assuming windows is always little-endian.
@@ -60,8 +62,12 @@
#endif
#else
#include <sys/param.h> // __BYTE_ORDER
+ #if defined(__OpenBSD__)
+ #include <endian.h>
+ #endif
#if ((defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) || \
- (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN)) && \
+ (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN) || \
+ (defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN)) && \
!defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)
#define PROTOBUF_LITTLE_ENDIAN 1
#endif
@@ -93,6 +99,15 @@
// ===================================================================
// from google3/base/port.h
+
+#if (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L || \
+ (defined(_MSC_VER) && _MSC_VER >= 1900))
+// Define this to 1 if the code is compiled in C++11 mode; leave it
+// undefined otherwise. Do NOT define it to 0 -- that causes
+// '#ifdef LANG_CXX11' to behave differently from '#if LANG_CXX11'.
+#define LANG_CXX11 1
+#endif
+
namespace google {
namespace protobuf {
@@ -327,6 +342,66 @@ 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 uint32 Log2FloorNonZero64(uint64 n) {
+ // arm-nacl-clang runs into an instruction-selection failure when it
+ // encounters __builtin_clzll:
+ // https://bugs.chromium.org/p/nativeclient/issues/detail?id=4395
+ // To work around this, when we build for NaCl we use the portable
+ // implementation instead.
+#if defined(__GNUC__) && !defined(GOOGLE_PROTOBUF_OS_NACL)
+ 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<uint32>(n >> 32);
+ if (topbits == 0) {
+ // Top bits are zero, so scan in bottom bits
+ return Log2FloorNonZero(static_cast<uint32>(n));
+ } else {
+ return 32 + Log2FloorNonZero(topbits);
+ }
+ }
+};
+
+// ===================================================================
// from google3/util/endian/endian.h
LIBPROTOBUF_EXPORT uint32 ghtonl(uint32 x);
@@ -386,7 +461,6 @@ class BigEndian {
}
};
-
} // namespace protobuf
} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/scoped_ptr.h b/third_party/protobuf/src/google/protobuf/stubs/scoped_ptr.h
index 4423c118c4..4423c118c4 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/scoped_ptr.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/scoped_ptr.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/shared_ptr.h b/third_party/protobuf/src/google/protobuf/stubs/shared_ptr.h
index d250bf4d33..7da114e936 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/shared_ptr.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/shared_ptr.h
@@ -428,11 +428,11 @@ class enable_shared_from_this {
shared_ptr<T> shared_from_this() {
// Behavior is undefined if the precondition isn't satisfied; we choose
// to die with a CHECK failure.
- CHECK(!weak_this_.expired()) << "No shared_ptr owns this object";
+ GOOGLE_CHECK(!weak_this_.expired()) << "No shared_ptr owns this object";
return weak_this_.lock();
}
shared_ptr<const T> shared_from_this() const {
- CHECK(!weak_this_.expired()) << "No shared_ptr owns this object";
+ GOOGLE_CHECK(!weak_this_.expired()) << "No shared_ptr owns this object";
return weak_this_.lock();
}
@@ -456,7 +456,8 @@ class enable_shared_from_this {
template<typename T>
void shared_ptr<T>::MaybeSetupWeakThis(enable_shared_from_this<T>* ptr) {
if (ptr) {
- CHECK(ptr->weak_this_.expired()) << "Object already owned by a shared_ptr";
+ GOOGLE_CHECK(ptr->weak_this_.expired())
+ << "Object already owned by a shared_ptr";
ptr->weak_this_ = *this;
}
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/singleton.h b/third_party/protobuf/src/google/protobuf/stubs/singleton.h
index 9301f549b1..9301f549b1 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/singleton.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/singleton.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/status.cc b/third_party/protobuf/src/google/protobuf/stubs/status.cc
index dd1bd6141a..dd1bd6141a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/status.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/status.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/status.h b/third_party/protobuf/src/google/protobuf/stubs/status.h
index 614ab9941a..614ab9941a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/status.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/status.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/status_macros.h b/third_party/protobuf/src/google/protobuf/stubs/status_macros.h
index 743e79a727..743e79a727 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/status_macros.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/status_macros.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/status_test.cc b/third_party/protobuf/src/google/protobuf/stubs/status_test.cc
index c70c33c474..c70c33c474 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/status_test.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/status_test.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/statusor.cc b/third_party/protobuf/src/google/protobuf/stubs/statusor.cc
index 48d1402ae0..48d1402ae0 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/statusor.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/statusor.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/statusor.h b/third_party/protobuf/src/google/protobuf/stubs/statusor.h
index 29f869ad5e..29f869ad5e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/statusor.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/statusor.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/statusor_test.cc b/third_party/protobuf/src/google/protobuf/stubs/statusor_test.cc
index 6e2a9e5545..6e2a9e5545 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/statusor_test.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/statusor_test.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/stl_util.h b/third_party/protobuf/src/google/protobuf/stubs/stl_util.h
index 9e4c82a4c3..9e4c82a4c3 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/stl_util.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/stl_util.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringpiece.cc b/third_party/protobuf/src/google/protobuf/stubs/stringpiece.cc
index 989474b747..989474b747 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringpiece.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/stringpiece.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringpiece.h b/third_party/protobuf/src/google/protobuf/stubs/stringpiece.h
index 8910688bf4..8910688bf4 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringpiece.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/stringpiece.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringpiece_unittest.cc b/third_party/protobuf/src/google/protobuf/stubs/stringpiece_unittest.cc
index a52d81f83a..a6a8759547 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringpiece_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/stringpiece_unittest.cc
@@ -783,11 +783,13 @@ TEST(FindOneCharTest, EdgeCases) {
EXPECT_EQ(StringPiece::npos, a.rfind('x'));
}
+#ifdef PROTOBUF_HAS_DEATH_TEST
#ifndef NDEBUG
TEST(NonNegativeLenTest, NonNegativeLen) {
EXPECT_DEATH(StringPiece("xyz", -1), "len >= 0");
}
#endif // ndef DEBUG
+#endif // PROTOBUF_HAS_DEATH_TEST
} // namespace
} // namespace protobuf
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringprintf.cc b/third_party/protobuf/src/google/protobuf/stubs/stringprintf.cc
index 83fdfe454e..83fdfe454e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringprintf.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/stringprintf.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringprintf.h b/third_party/protobuf/src/google/protobuf/stubs/stringprintf.h
index ab1ab55832..ab1ab55832 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringprintf.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/stringprintf.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringprintf_unittest.cc b/third_party/protobuf/src/google/protobuf/stubs/stringprintf_unittest.cc
index 15895e596c..15895e596c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/stringprintf_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/stringprintf_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/structurally_valid.cc b/third_party/protobuf/src/google/protobuf/stubs/structurally_valid.cc
index d79a6ee450..d79a6ee450 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/structurally_valid.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/structurally_valid.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/structurally_valid_unittest.cc b/third_party/protobuf/src/google/protobuf/stubs/structurally_valid_unittest.cc
index 90888885ad..90888885ad 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/structurally_valid_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/structurally_valid_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/strutil.cc b/third_party/protobuf/src/google/protobuf/stubs/strutil.cc
index 7ba92e8f1f..15b6e53f1a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/strutil.cc
+++ b/third_party/protobuf/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();
@@ -966,7 +981,7 @@ static const char two_ASCII_digits[100][2] = {
};
char* FastUInt32ToBufferLeft(uint32 u, char* buffer) {
- int digits;
+ uint32 digits;
const char *ASCII_digits = NULL;
// The idea of this implementation is to trim the number of divides to as few
// as possible by using multiplication and subtraction rather than mod (%),
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/strutil.h b/third_party/protobuf/src/google/protobuf/stubs/strutil.h
index 8bdd611030..df28c94da8 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/strutil.h
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/src/google/protobuf/stubs/strutil_unittest.cc b/third_party/protobuf/src/google/protobuf/stubs/strutil_unittest.cc
index 5d62fc4adf..5d62fc4adf 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/strutil_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/strutil_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/substitute.cc b/third_party/protobuf/src/google/protobuf/stubs/substitute.cc
index c9d95899f5..7194a5b171 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/substitute.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/substitute.cc
@@ -113,7 +113,9 @@ void SubstituteAndAppend(
for (int i = 0; format[i] != '\0'; i++) {
if (format[i] == '$') {
if (ascii_isdigit(format[i+1])) {
- const SubstituteArg* src = args_array[format[i+1] - '0'];
+ unsigned int index = format[i+1] - '0';
+ assert(index < 10);
+ const SubstituteArg* src = args_array[index];
memcpy(target, src->data(), src->size());
target += src->size();
++i; // Skip next char.
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/substitute.h b/third_party/protobuf/src/google/protobuf/stubs/substitute.h
index 7ee442af77..7ee442af77 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/substitute.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/substitute.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/template_util.h b/third_party/protobuf/src/google/protobuf/stubs/template_util.h
index feef904bea..feef904bea 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/template_util.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/template_util.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/template_util_unittest.cc b/third_party/protobuf/src/google/protobuf/stubs/template_util_unittest.cc
index b1745e2bf7..b1745e2bf7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/template_util_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/template_util_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/time.cc b/third_party/protobuf/src/google/protobuf/stubs/time.cc
index 49c0412c17..49c0412c17 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/time.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/time.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/time.h b/third_party/protobuf/src/google/protobuf/stubs/time.h
index 45607ca9bb..45607ca9bb 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/time.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/time.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/time_test.cc b/third_party/protobuf/src/google/protobuf/stubs/time_test.cc
index 59e9d1c73c..59e9d1c73c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/time_test.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/time_test.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/type_traits.h b/third_party/protobuf/src/google/protobuf/stubs/type_traits.h
index 0d8127e504..3ab5ea7d4e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/type_traits.h
+++ b/third_party/protobuf/src/google/protobuf/stubs/type_traits.h
@@ -139,7 +139,7 @@ template<> struct is_integral<int> : true_type { };
template<> struct is_integral<unsigned int> : true_type { };
template<> struct is_integral<long> : true_type { };
template<> struct is_integral<unsigned long> : true_type { };
-#ifdef HAVE_LONG_LONG
+#if defined(HAVE_LONG_LONG) || defined(_MSC_VER)
template<> struct is_integral<long long> : true_type { };
template<> struct is_integral<unsigned long long> : true_type { };
#endif
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/type_traits_unittest.cc b/third_party/protobuf/src/google/protobuf/stubs/type_traits_unittest.cc
index 49c10aced6..49c10aced6 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/stubs/type_traits_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/stubs/type_traits_unittest.cc
diff --git a/third_party/protobuf/src/google/protobuf/test_messages_proto3.proto b/third_party/protobuf/src/google/protobuf/test_messages_proto3.proto
new file mode 100644
index 0000000000..79230334d7
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/test_messages_proto3.proto
@@ -0,0 +1,227 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Test schema for proto3 messages. This test schema is used by:
+//
+// - benchmarks
+// - fuzz tests
+// - conformance tests
+//
+
+syntax = "proto3";
+
+package protobuf_test_messages.proto3;
+option java_package = "com.google.protobuf_test_messages.proto3";
+
+// This is the default, but we specify it here explicitly.
+option optimize_for = SPEED;
+
+import "google/protobuf/any.proto";
+import "google/protobuf/duration.proto";
+import "google/protobuf/field_mask.proto";
+import "google/protobuf/struct.proto";
+import "google/protobuf/timestamp.proto";
+import "google/protobuf/wrappers.proto";
+
+option cc_enable_arenas = true;
+
+// This proto includes every type of field in both singular and repeated
+// forms.
+//
+// Also, crucially, all messages and enums in this file are eventually
+// submessages of this message. So for example, a fuzz test of TestAllTypes
+// could trigger bugs that occur in any message type in this file. We verify
+// this stays true in a unit test.
+message TestAllTypes {
+ message NestedMessage {
+ int32 a = 1;
+ TestAllTypes corecursive = 2;
+ }
+
+ enum NestedEnum {
+ FOO = 0;
+ BAR = 1;
+ BAZ = 2;
+ NEG = -1; // Intentionally negative.
+ }
+
+ // Singular
+ int32 optional_int32 = 1;
+ int64 optional_int64 = 2;
+ uint32 optional_uint32 = 3;
+ uint64 optional_uint64 = 4;
+ sint32 optional_sint32 = 5;
+ sint64 optional_sint64 = 6;
+ fixed32 optional_fixed32 = 7;
+ fixed64 optional_fixed64 = 8;
+ sfixed32 optional_sfixed32 = 9;
+ sfixed64 optional_sfixed64 = 10;
+ float optional_float = 11;
+ double optional_double = 12;
+ bool optional_bool = 13;
+ string optional_string = 14;
+ bytes optional_bytes = 15;
+
+ NestedMessage optional_nested_message = 18;
+ ForeignMessage optional_foreign_message = 19;
+
+ NestedEnum optional_nested_enum = 21;
+ ForeignEnum optional_foreign_enum = 22;
+
+ string optional_string_piece = 24 [ctype=STRING_PIECE];
+ string optional_cord = 25 [ctype=CORD];
+
+ TestAllTypes recursive_message = 27;
+
+ // Repeated
+ repeated int32 repeated_int32 = 31;
+ repeated int64 repeated_int64 = 32;
+ repeated uint32 repeated_uint32 = 33;
+ repeated uint64 repeated_uint64 = 34;
+ repeated sint32 repeated_sint32 = 35;
+ repeated sint64 repeated_sint64 = 36;
+ repeated fixed32 repeated_fixed32 = 37;
+ repeated fixed64 repeated_fixed64 = 38;
+ repeated sfixed32 repeated_sfixed32 = 39;
+ repeated sfixed64 repeated_sfixed64 = 40;
+ repeated float repeated_float = 41;
+ repeated double repeated_double = 42;
+ repeated bool repeated_bool = 43;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+
+ repeated NestedMessage repeated_nested_message = 48;
+ repeated ForeignMessage repeated_foreign_message = 49;
+
+ repeated NestedEnum repeated_nested_enum = 51;
+ repeated ForeignEnum repeated_foreign_enum = 52;
+
+ repeated string repeated_string_piece = 54 [ctype=STRING_PIECE];
+ repeated string repeated_cord = 55 [ctype=CORD];
+
+ // Map
+ map < int32, int32> map_int32_int32 = 56;
+ map < int64, int64> map_int64_int64 = 57;
+ map < uint32, uint32> map_uint32_uint32 = 58;
+ map < uint64, uint64> map_uint64_uint64 = 59;
+ map < sint32, sint32> map_sint32_sint32 = 60;
+ map < sint64, sint64> map_sint64_sint64 = 61;
+ map < fixed32, fixed32> map_fixed32_fixed32 = 62;
+ map < fixed64, fixed64> map_fixed64_fixed64 = 63;
+ map <sfixed32, sfixed32> map_sfixed32_sfixed32 = 64;
+ map <sfixed64, sfixed64> map_sfixed64_sfixed64 = 65;
+ map < int32, float> map_int32_float = 66;
+ map < int32, double> map_int32_double = 67;
+ map < bool, bool> map_bool_bool = 68;
+ map < string, string> map_string_string = 69;
+ map < string, bytes> map_string_bytes = 70;
+ map < string, NestedMessage> map_string_nested_message = 71;
+ map < string, ForeignMessage> map_string_foreign_message = 72;
+ map < string, NestedEnum> map_string_nested_enum = 73;
+ map < string, ForeignEnum> map_string_foreign_enum = 74;
+
+ oneof oneof_field {
+ uint32 oneof_uint32 = 111;
+ NestedMessage oneof_nested_message = 112;
+ string oneof_string = 113;
+ bytes oneof_bytes = 114;
+ bool oneof_bool = 115;
+ uint64 oneof_uint64 = 116;
+ float oneof_float = 117;
+ double oneof_double = 118;
+ NestedEnum oneof_enum = 119;
+ }
+
+ // Well-known types
+ google.protobuf.BoolValue optional_bool_wrapper = 201;
+ google.protobuf.Int32Value optional_int32_wrapper = 202;
+ google.protobuf.Int64Value optional_int64_wrapper = 203;
+ google.protobuf.UInt32Value optional_uint32_wrapper = 204;
+ google.protobuf.UInt64Value optional_uint64_wrapper = 205;
+ google.protobuf.FloatValue optional_float_wrapper = 206;
+ google.protobuf.DoubleValue optional_double_wrapper = 207;
+ google.protobuf.StringValue optional_string_wrapper = 208;
+ google.protobuf.BytesValue optional_bytes_wrapper = 209;
+
+ repeated google.protobuf.BoolValue repeated_bool_wrapper = 211;
+ repeated google.protobuf.Int32Value repeated_int32_wrapper = 212;
+ repeated google.protobuf.Int64Value repeated_int64_wrapper = 213;
+ repeated google.protobuf.UInt32Value repeated_uint32_wrapper = 214;
+ repeated google.protobuf.UInt64Value repeated_uint64_wrapper = 215;
+ repeated google.protobuf.FloatValue repeated_float_wrapper = 216;
+ repeated google.protobuf.DoubleValue repeated_double_wrapper = 217;
+ repeated google.protobuf.StringValue repeated_string_wrapper = 218;
+ repeated google.protobuf.BytesValue repeated_bytes_wrapper = 219;
+
+ google.protobuf.Duration optional_duration = 301;
+ google.protobuf.Timestamp optional_timestamp = 302;
+ google.protobuf.FieldMask optional_field_mask = 303;
+ google.protobuf.Struct optional_struct = 304;
+ google.protobuf.Any optional_any = 305;
+ google.protobuf.Value optional_value = 306;
+
+ repeated google.protobuf.Duration repeated_duration = 311;
+ repeated google.protobuf.Timestamp repeated_timestamp = 312;
+ repeated google.protobuf.FieldMask repeated_fieldmask = 313;
+ repeated google.protobuf.Struct repeated_struct = 324;
+ repeated google.protobuf.Any repeated_any = 315;
+ repeated google.protobuf.Value repeated_value = 316;
+
+ // Test field-name-to-JSON-name convention.
+ // (protobuf says names can be any valid C/C++ identifier.)
+ int32 fieldname1 = 401;
+ int32 field_name2 = 402;
+ int32 _field_name3 = 403;
+ int32 field__name4_ = 404;
+ int32 field0name5 = 405;
+ int32 field_0_name6 = 406;
+ int32 fieldName7 = 407;
+ int32 FieldName8 = 408;
+ int32 field_Name9 = 409;
+ int32 Field_Name10 = 410;
+ int32 FIELD_NAME11 = 411;
+ int32 FIELD_name12 = 412;
+ int32 __field_name13 = 413;
+ int32 __Field_name14 = 414;
+ int32 field__name15 = 415;
+ int32 field__Name16 = 416;
+ int32 field_name17__ = 417;
+ int32 Field_name18__ = 418;
+}
+
+message ForeignMessage {
+ int32 c = 1;
+}
+
+enum ForeignEnum {
+ FOREIGN_FOO = 0;
+ FOREIGN_BAR = 1;
+ FOREIGN_BAZ = 2;
+}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/test_util.cc b/third_party/protobuf/src/google/protobuf/test_util.cc
index 658c8ee285..4e02a85d85 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/test_util.cc
+++ b/third_party/protobuf/src/google/protobuf/test_util.cc
@@ -3230,7 +3230,7 @@ void TestUtil::ReflectionTester::RemoveLastRepeatedsViaReflection(
Message* message) {
const Reflection* reflection = message->GetReflection();
- vector<const FieldDescriptor*> output;
+ std::vector<const FieldDescriptor*> output;
reflection->ListFields(*message, &output);
for (int i=0; i<output.size(); ++i) {
const FieldDescriptor* field = output[i];
@@ -3244,7 +3244,7 @@ void TestUtil::ReflectionTester::ReleaseLastRepeatedsViaReflection(
Message* message, bool expect_extensions_notnull) {
const Reflection* reflection = message->GetReflection();
- vector<const FieldDescriptor*> output;
+ std::vector<const FieldDescriptor*> output;
reflection->ListFields(*message, &output);
for (int i=0; i<output.size(); ++i) {
const FieldDescriptor* field = output[i];
@@ -3263,7 +3263,7 @@ void TestUtil::ReflectionTester::ReleaseLastRepeatedsViaReflection(
void TestUtil::ReflectionTester::SwapRepeatedsViaReflection(Message* message) {
const Reflection* reflection = message->GetReflection();
- vector<const FieldDescriptor*> output;
+ std::vector<const FieldDescriptor*> output;
reflection->ListFields(*message, &output);
for (int i=0; i<output.size(); ++i) {
const FieldDescriptor* field = output[i];
@@ -3278,7 +3278,7 @@ SetAllocatedOptionalMessageFieldsToNullViaReflection(
Message* message) {
const Reflection* reflection = message->GetReflection();
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
reflection->ListFields(*message, &fields);
for (int i = 0; i < fields.size(); ++i) {
@@ -3298,7 +3298,7 @@ SetAllocatedOptionalMessageFieldsToMessageViaReflection(
const Reflection* from_reflection = from_message->GetReflection();
const Reflection* to_reflection = to_message->GetReflection();
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
from_reflection->ListFields(*from_message, &fields);
for (int i = 0; i < fields.size(); ++i) {
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/test_util.h b/third_party/protobuf/src/google/protobuf/test_util.h
index 1c13a1a7f6..1c13a1a7f6 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/test_util.h
+++ b/third_party/protobuf/src/google/protobuf/test_util.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/test_util_lite.cc b/third_party/protobuf/src/google/protobuf/test_util_lite.cc
index 388c0cbde2..388c0cbde2 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/test_util_lite.cc
+++ b/third_party/protobuf/src/google/protobuf/test_util_lite.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/test_util_lite.h b/third_party/protobuf/src/google/protobuf/test_util_lite.h
index 47a2269d36..47a2269d36 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/test_util_lite.h
+++ b/third_party/protobuf/src/google/protobuf/test_util_lite.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/bad_utf8_string b/third_party/protobuf/src/google/protobuf/testdata/bad_utf8_string
index a1337ec689..a1337ec689 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/bad_utf8_string
+++ b/third_party/protobuf/src/google/protobuf/testdata/bad_utf8_string
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/golden_message b/third_party/protobuf/src/google/protobuf/testdata/golden_message
index 0b7e6552c6..0b7e6552c6 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/golden_message
+++ b/third_party/protobuf/src/google/protobuf/testdata/golden_message
Binary files differ
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/golden_message_maps b/third_party/protobuf/src/google/protobuf/testdata/golden_message_maps
index c70a4d7cde..c70a4d7cde 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/golden_message_maps
+++ b/third_party/protobuf/src/google/protobuf/testdata/golden_message_maps
Binary files differ
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/golden_message_oneof_implemented b/third_party/protobuf/src/google/protobuf/testdata/golden_message_oneof_implemented
index b48c898526..b48c898526 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/golden_message_oneof_implemented
+++ b/third_party/protobuf/src/google/protobuf/testdata/golden_message_oneof_implemented
Binary files differ
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/golden_message_proto3 b/third_party/protobuf/src/google/protobuf/testdata/golden_message_proto3
index bd646a0dc8..bd646a0dc8 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/golden_message_proto3
+++ b/third_party/protobuf/src/google/protobuf/testdata/golden_message_proto3
Binary files differ
diff --git a/third_party/protobuf/src/google/protobuf/testdata/golden_packed_fields_message b/third_party/protobuf/src/google/protobuf/testdata/golden_packed_fields_message
new file mode 100644
index 0000000000..ee28d38830
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/testdata/golden_packed_fields_message
Binary files differ
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/map_test_data.txt b/third_party/protobuf/src/google/protobuf/testdata/map_test_data.txt
index bc2723214a..bc2723214a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/map_test_data.txt
+++ b/third_party/protobuf/src/google/protobuf/testdata/map_test_data.txt
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_data.txt b/third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_data.txt
index 7a874b54cd..7a874b54cd 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_data.txt
+++ b/third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_data.txt
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_data_oneof_implemented.txt b/third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_data_oneof_implemented.txt
index ec95e1e81a..ec95e1e81a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_data_oneof_implemented.txt
+++ b/third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_data_oneof_implemented.txt
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_data_pointy.txt b/third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_data_pointy.txt
index e1011ebf15..e1011ebf15 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_data_pointy.txt
+++ b/third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_data_pointy.txt
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_data_pointy_oneof.txt b/third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_data_pointy_oneof.txt
index 95109f62ab..95109f62ab 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_data_pointy_oneof.txt
+++ b/third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_data_pointy_oneof.txt
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_extensions_data.txt b/third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_extensions_data.txt
index 8c8b1eb4d8..8c8b1eb4d8 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_extensions_data.txt
+++ b/third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_extensions_data.txt
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_extensions_data_pointy.txt b/third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_extensions_data_pointy.txt
index 132f7445f3..132f7445f3 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testdata/text_format_unittest_extensions_data_pointy.txt
+++ b/third_party/protobuf/src/google/protobuf/testdata/text_format_unittest_extensions_data_pointy.txt
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testing/file.cc b/third_party/protobuf/src/google/protobuf/testing/file.cc
index 3d07b1276c..470512edff 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testing/file.cc
+++ b/third_party/protobuf/src/google/protobuf/testing/file.cc
@@ -91,6 +91,7 @@ bool File::WriteStringToFile(const string& contents, const string& name) {
if (fwrite(contents.data(), 1, contents.size(), file) != contents.size()) {
GOOGLE_LOG(ERROR) << "fwrite(" << name << "): " << strerror(errno);
+ fclose(file);
return false;
}
@@ -140,12 +141,12 @@ void File::DeleteRecursively(const string& name,
#ifdef _MSC_VER
// This interface is so weird.
- WIN32_FIND_DATA find_data;
- HANDLE find_handle = FindFirstFile((name + "/*").c_str(), &find_data);
+ WIN32_FIND_DATAA find_data;
+ HANDLE find_handle = FindFirstFileA((name + "/*").c_str(), &find_data);
if (find_handle == INVALID_HANDLE_VALUE) {
// Just delete it, whatever it is.
- DeleteFile(name.c_str());
- RemoveDirectory(name.c_str());
+ DeleteFileA(name.c_str());
+ RemoveDirectoryA(name.c_str());
return;
}
@@ -155,15 +156,15 @@ void File::DeleteRecursively(const string& name,
string path = name + "/" + entry_name;
if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
DeleteRecursively(path, NULL, NULL);
- RemoveDirectory(path.c_str());
+ RemoveDirectoryA(path.c_str());
} else {
- DeleteFile(path.c_str());
+ DeleteFileA(path.c_str());
}
}
- } while(FindNextFile(find_handle, &find_data));
+ } while(FindNextFileA(find_handle, &find_data));
FindClose(find_handle);
- RemoveDirectory(name.c_str());
+ RemoveDirectoryA(name.c_str());
#else
// Use opendir()! Yay!
// lstat = Don't follow symbolic links.
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testing/file.h b/third_party/protobuf/src/google/protobuf/testing/file.h
index 2f63f80e7b..2f63f80e7b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testing/file.h
+++ b/third_party/protobuf/src/google/protobuf/testing/file.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testing/googletest.cc b/third_party/protobuf/src/google/protobuf/testing/googletest.cc
index d45706b654..d45706b654 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testing/googletest.cc
+++ b/third_party/protobuf/src/google/protobuf/testing/googletest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testing/googletest.h b/third_party/protobuf/src/google/protobuf/testing/googletest.h
index c0d99e69ac..c0d99e69ac 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testing/googletest.h
+++ b/third_party/protobuf/src/google/protobuf/testing/googletest.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testing/zcgunzip.cc b/third_party/protobuf/src/google/protobuf/testing/zcgunzip.cc
index 76f8cfe11b..76f8cfe11b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testing/zcgunzip.cc
+++ b/third_party/protobuf/src/google/protobuf/testing/zcgunzip.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/testing/zcgzip.cc b/third_party/protobuf/src/google/protobuf/testing/zcgzip.cc
index 992ddc6ed6..992ddc6ed6 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/testing/zcgzip.cc
+++ b/third_party/protobuf/src/google/protobuf/testing/zcgzip.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/text_format.cc b/third_party/protobuf/src/google/protobuf/text_format.cc
index 66b2648b7c..778b878e79 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/text_format.cc
+++ b/third_party/protobuf/src/google/protobuf/text_format.cc
@@ -154,7 +154,7 @@ TextFormat::ParseInfoTree* TextFormat::ParseInfoTree::CreateNested(
const FieldDescriptor* field) {
// Owned by us in the map.
TextFormat::ParseInfoTree* instance = new TextFormat::ParseInfoTree();
- vector<TextFormat::ParseInfoTree*>* trees = &nested_[field];
+ std::vector<TextFormat::ParseInfoTree*>* trees = &nested_[field];
GOOGLE_CHECK(trees);
trees->push_back(instance);
return instance;
@@ -177,7 +177,7 @@ TextFormat::ParseLocation TextFormat::ParseInfoTree::GetLocation(
CheckFieldIndex(field, index);
if (index == -1) { index = 0; }
- const vector<TextFormat::ParseLocation>* locations =
+ const std::vector<TextFormat::ParseLocation>* locations =
FindOrNull(locations_, field);
if (locations == NULL || index >= locations->size()) {
return TextFormat::ParseLocation();
@@ -191,7 +191,8 @@ TextFormat::ParseInfoTree* TextFormat::ParseInfoTree::GetTreeForNested(
CheckFieldIndex(field, index);
if (index == -1) { index = 0; }
- const vector<TextFormat::ParseInfoTree*>* trees = FindOrNull(nested_, field);
+ const std::vector<TextFormat::ParseInfoTree*>* trees =
+ FindOrNull(nested_, field);
if (trees == NULL || index >= trees->size()) {
return NULL;
}
@@ -393,6 +394,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));
@@ -508,32 +519,42 @@ class TextFormat::Parser::ParserImpl {
// Perform special handling for embedded message types.
if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
// ':' is optional here.
- TryConsume(":");
+ bool consumed_semicolon = TryConsume(":");
+ if (consumed_semicolon && field->options().weak() && LookingAtType(io::Tokenizer::TYPE_STRING)) {
+ // we are getting a bytes string for a weak field.
+ string tmp;
+ DO(ConsumeString(&tmp));
+ reflection->MutableMessage(message, field)->ParseFromString(tmp);
+ goto label_skip_parsing;
+ }
} else {
// ':' is required here.
DO(Consume(":"));
}
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));
} else {
DO(ConsumeFieldValue(message, reflection, field));
}
-
+label_skip_parsing:
// For historical reasons, fields may optionally be separated by commas or
// semicolons.
TryConsume(";") || TryConsume(",");
@@ -1323,7 +1344,7 @@ bool TextFormat::Parser::MergeUsingImpl(io::ZeroCopyInputStream* /* input */,
ParserImpl* parser_impl) {
if (!parser_impl->Parse(output)) return false;
if (!allow_partial_ && !output->IsInitialized()) {
- vector<string> missing_fields;
+ std::vector<string> missing_fields;
output->FindInitializationErrors(&missing_fields);
parser_impl->ReportError(-1, 0, "Message missing required fields: " +
Join(missing_fields, ", "));
@@ -1597,7 +1618,7 @@ void TextFormat::Printer::Print(const Message& message,
PrintAny(message, generator)) {
return;
}
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
reflection->ListFields(message, &fields);
if (print_message_fields_in_index_order_) {
std::sort(fields.begin(), fields.end(), FieldIndexSorter());
@@ -1625,54 +1646,6 @@ void TextFormat::Printer::PrintFieldValueToString(
PrintFieldValue(message, message.GetReflection(), field, index, generator);
}
-class MapEntryMessageComparator {
- public:
- explicit MapEntryMessageComparator(const Descriptor* descriptor)
- : field_(descriptor->field(0)) {}
-
- bool operator()(const Message* a, const Message* b) {
- const Reflection* reflection = a->GetReflection();
- switch (field_->cpp_type()) {
- case FieldDescriptor::CPPTYPE_BOOL: {
- bool first = reflection->GetBool(*a, field_);
- bool second = reflection->GetBool(*b, field_);
- return first < second;
- }
- case FieldDescriptor::CPPTYPE_INT32: {
- int32 first = reflection->GetInt32(*a, field_);
- int32 second = reflection->GetInt32(*b, field_);
- return first < second;
- }
- case FieldDescriptor::CPPTYPE_INT64: {
- int64 first = reflection->GetInt64(*a, field_);
- int64 second = reflection->GetInt64(*b, field_);
- return first < second;
- }
- case FieldDescriptor::CPPTYPE_UINT32: {
- uint32 first = reflection->GetUInt32(*a, field_);
- uint32 second = reflection->GetUInt32(*b, field_);
- return first < second;
- }
- case FieldDescriptor::CPPTYPE_UINT64: {
- uint64 first = reflection->GetUInt64(*a, field_);
- uint64 second = reflection->GetUInt64(*b, field_);
- return first < second;
- }
- case FieldDescriptor::CPPTYPE_STRING: {
- string first = reflection->GetString(*a, field_);
- string second = reflection->GetString(*b, field_);
- return first < second;
- }
- default:
- GOOGLE_LOG(DFATAL) << "Invalid key for map field.";
- return true;
- }
- }
-
- private:
- const FieldDescriptor* field_;
-};
-
void TextFormat::Printer::PrintField(const Message& message,
const Reflection* reflection,
const FieldDescriptor* field,
@@ -1693,19 +1666,10 @@ void TextFormat::Printer::PrintField(const Message& message,
count = 1;
}
- std::vector<const Message*> sorted_map_field;
- if (field->is_map()) {
- const RepeatedPtrField<Message>& map_field =
- reflection->GetRepeatedPtrField<Message>(message, field);
- for (RepeatedPtrField<Message>::const_pointer_iterator it =
- map_field.pointer_begin();
- it != map_field.pointer_end(); ++it) {
- sorted_map_field.push_back(*it);
- }
-
- MapEntryMessageComparator comparator(field->message_type());
- std::stable_sort(sorted_map_field.begin(), sorted_map_field.end(),
- comparator);
+ std::vector<const Message*> map_entries;
+ const bool is_map = field->is_map();
+ if (is_map) {
+ map_entries = DynamicMapSorter::Sort(message, count, reflection, field);
}
for (int j = 0; j < count; ++j) {
@@ -1718,9 +1682,8 @@ void TextFormat::Printer::PrintField(const Message& message,
custom_printers_, field, default_field_value_printer_.get());
const Message& sub_message =
field->is_repeated()
- ? (field->is_map()
- ? *sorted_map_field[j]
- : reflection->GetRepeatedMessage(message, field, j))
+ ? (is_map ? *map_entries[j]
+ : reflection->GetRepeatedMessage(message, field, j))
: reflection->GetMessage(message, field);
generator.Print(
printer->PrintMessageStart(
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/text_format.h b/third_party/protobuf/src/google/protobuf/text_format.h
index ef3d4a8fd7..2873d3392b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/text_format.h
+++ b/third_party/protobuf/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<const FieldValuePrinter> default_field_value_printer_;
- typedef map<const FieldDescriptor*,
- const FieldValuePrinter*> CustomPrinterMap;
+ typedef std::map<const FieldDescriptor*,
+ const FieldValuePrinter*> 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<const FieldDescriptor*, vector<ParseLocation> > LocationMap;
+ typedef std::map<const FieldDescriptor*,
+ std::vector<ParseLocation> > LocationMap;
// Defines the map from the index-th field descriptor to the nested parse
// info tree.
- typedef map<const FieldDescriptor*, vector<ParseInfoTree*> > NestedMap;
+ typedef std::map<const FieldDescriptor*,
+ std::vector<ParseInfoTree*> > NestedMap;
LocationMap locations_;
NestedMap nested_;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/text_format_unittest.cc b/third_party/protobuf/src/google/protobuf/text_format_unittest.cc
index c9521cc31f..e644133953 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/text_format_unittest.cc
+++ b/third_party/protobuf/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.
@@ -898,10 +993,14 @@ TEST_F(TextFormatTest, ParseExotic) {
EXPECT_EQ(1.235E22 , message.repeated_double(4));
EXPECT_EQ(1.235E-18 , message.repeated_double(5));
EXPECT_EQ(123.456789, message.repeated_double(6));
- EXPECT_EQ(message.repeated_double(7), numeric_limits<double>::infinity());
- EXPECT_EQ(message.repeated_double(8), numeric_limits<double>::infinity());
- EXPECT_EQ(message.repeated_double(9), -numeric_limits<double>::infinity());
- EXPECT_EQ(message.repeated_double(10), -numeric_limits<double>::infinity());
+ EXPECT_EQ(message.repeated_double(7),
+ std::numeric_limits<double>::infinity());
+ EXPECT_EQ(message.repeated_double(8),
+ std::numeric_limits<double>::infinity());
+ EXPECT_EQ(message.repeated_double(9),
+ -std::numeric_limits<double>::infinity());
+ EXPECT_EQ(message.repeated_double(10),
+ -std::numeric_limits<double>::infinity());
EXPECT_TRUE(MathLimits<double>::IsNaN(message.repeated_double(11)));
EXPECT_TRUE(MathLimits<double>::IsNaN(message.repeated_double(12)));
@@ -1405,7 +1504,7 @@ TEST_F(TextFormatParserTest, ExplicitDelimiters) {
}
TEST_F(TextFormatParserTest, PrintErrorsToStderr) {
- vector<string> errors;
+ std::vector<string> errors;
{
ScopedMemoryLog log;
@@ -1422,7 +1521,7 @@ TEST_F(TextFormatParserTest, PrintErrorsToStderr) {
}
TEST_F(TextFormatParserTest, FailsOnTokenizationError) {
- vector<string> errors;
+ std::vector<string> errors;
{
ScopedMemoryLog log;
@@ -1481,7 +1580,7 @@ TEST_F(TextFormatMessageSetTest, Deserialize) {
protobuf_unittest::TestMessageSetExtension2::message_set_extension).str());
// Ensure that these are the only entries present.
- vector<const FieldDescriptor*> descriptors;
+ std::vector<const FieldDescriptor*> descriptors;
proto.message_set().GetReflection()->ListFields(
proto.message_set(), &descriptors);
EXPECT_EQ(2, descriptors.size());
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/timestamp.pb.cc b/third_party/protobuf/src/google/protobuf/timestamp.pb.cc
index 542e5ed7e4..c1865d93e0 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/timestamp.pb.cc
+++ b/third_party/protobuf/src/google/protobuf/timestamp.pb.cc
@@ -19,90 +19,104 @@
namespace google {
namespace protobuf {
+class TimestampDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Timestamp> {
+} _Timestamp_default_instance_;
+
+namespace protobuf_google_2fprotobuf_2ftimestamp_2eproto {
+
namespace {
-const ::google::protobuf::Descriptor* Timestamp_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- Timestamp_reflection_ = NULL;
+::google::protobuf::Metadata file_level_metadata[1];
} // namespace
+const ::google::protobuf::uint32 TableStruct::offsets[] = {
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Timestamp, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Timestamp, seconds_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Timestamp, nanos_),
+};
-void protobuf_AssignDesc_google_2fprotobuf_2ftimestamp_2eproto() GOOGLE_ATTRIBUTE_COLD;
-void protobuf_AssignDesc_google_2fprotobuf_2ftimestamp_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto();
- const ::google::protobuf::FileDescriptor* file =
- ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
- "google/protobuf/timestamp.proto");
- GOOGLE_CHECK(file != NULL);
- Timestamp_descriptor_ = file->message_type(0);
- static const int Timestamp_offsets_[2] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Timestamp, seconds_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Timestamp, nanos_),
- };
- Timestamp_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- Timestamp_descriptor_,
- Timestamp::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_));
-}
+static const ::google::protobuf::internal::MigrationSchema schemas[] = {
+ { 0, -1, sizeof(Timestamp)},
+};
+
+static ::google::protobuf::Message const * const file_default_instances[] = {
+ reinterpret_cast<const ::google::protobuf::Message*>(&_Timestamp_default_instance_),
+};
namespace {
-GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
-inline void protobuf_AssignDescriptorsOnce() {
- ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
- &protobuf_AssignDesc_google_2fprotobuf_2ftimestamp_2eproto);
+void protobuf_AssignDescriptors() {
+ AddDescriptors();
+ ::google::protobuf::MessageFactory* factory = NULL;
+ AssignDescriptors(
+ "google/protobuf/timestamp.proto", schemas, file_default_instances, TableStruct::offsets, factory,
+ file_level_metadata, NULL, NULL);
+}
+
+void protobuf_AssignDescriptorsOnce() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
}
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());
+ ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
}
} // namespace
-void protobuf_ShutdownFile_google_2fprotobuf_2ftimestamp_2eproto() {
- delete Timestamp::default_instance_;
- delete Timestamp_reflection_;
+void TableStruct::Shutdown() {
+ _Timestamp_default_instance_.Shutdown();
+ delete file_level_metadata[0].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 TableStruct::InitDefaultsImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
+ ::google::protobuf::internal::InitProtobufDefaults();
+ _Timestamp_default_instance_.DefaultConstruct();
+}
+
+void InitDefaults() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &TableStruct::InitDefaultsImpl);
+}
+void AddDescriptorsImpl() {
+ InitDefaults();
+ static const char descriptor[] = {
+ "\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~\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"
+ };
::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);
+ descriptor, 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::internal::OnShutdown(&TableStruct::Shutdown);
}
+void AddDescriptors() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
+}
// Force AddDescriptors() to be called at static initialization time.
-struct StaticDescriptorInitializer_google_2fprotobuf_2ftimestamp_2eproto {
- StaticDescriptorInitializer_google_2fprotobuf_2ftimestamp_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto();
+struct StaticDescriptorInitializer {
+ StaticDescriptorInitializer() {
+ AddDescriptors();
}
-} static_descriptor_initializer_google_2fprotobuf_2ftimestamp_2eproto_;
+} static_descriptor_initializer;
+
+} // namespace protobuf_google_2fprotobuf_2ftimestamp_2eproto
+
// ===================================================================
@@ -113,35 +127,37 @@ const int Timestamp::kNanosFieldNumber;
Timestamp::Timestamp()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2ftimestamp_2eproto::InitDefaults();
+ }
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_google_2fprotobuf_2ftimestamp_2eproto::InitDefaults();
+#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);
+ _internal_metadata_(NULL),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ ::memcpy(&seconds_, &from.seconds_,
+ reinterpret_cast<char*>(&nanos_) -
+ reinterpret_cast<char*>(&seconds_) + sizeof(nanos_));
// @@protoc_insertion_point(copy_constructor:google.protobuf.Timestamp)
}
void Timestamp::SharedCtor() {
- _is_default_instance_ = false;
+ ::memset(&seconds_, 0, reinterpret_cast<char*>(&nanos_) -
+ reinterpret_cast<char*>(&seconds_) + sizeof(nanos_));
_cached_size_ = 0;
- seconds_ = GOOGLE_LONGLONG(0);
- nanos_ = 0;
}
Timestamp::~Timestamp() {
@@ -150,12 +166,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) {
@@ -170,44 +185,23 @@ void Timestamp::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Timestamp::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Timestamp_descriptor_;
+ protobuf_google_2fprotobuf_2ftimestamp_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2ftimestamp_2eproto::file_level_metadata[0].descriptor;
}
const Timestamp& Timestamp::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2ftimestamp_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-Timestamp* Timestamp::default_instance_ = NULL;
-
Timestamp* Timestamp::New(::google::protobuf::Arena* arena) const {
return ::google::protobuf::Arena::CreateMessage<Timestamp>(arena);
}
void Timestamp::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.Timestamp)
-#if defined(__clang__)
-#define ZR_HELPER_(f) \
- _Pragma("clang diagnostic push") \
- _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
- __builtin_offsetof(Timestamp, f) \
- _Pragma("clang diagnostic pop")
-#else
-#define ZR_HELPER_(f) reinterpret_cast<char*>(\
- &reinterpret_cast<Timestamp*>(16)->f)
-#endif
-
-#define ZR_(first, last) do {\
- ::memset(&first, 0,\
- ZR_HELPER_(last) - ZR_HELPER_(first) + sizeof(last));\
-} while (0)
-
- ZR_(seconds_, nanos_);
-
-#undef ZR_HELPER_
-#undef ZR_
-
+ ::memset(&seconds_, 0, reinterpret_cast<char*>(&nanos_) -
+ reinterpret_cast<char*>(&seconds_) + sizeof(nanos_));
}
bool Timestamp::MergePartialFromCodedStream(
@@ -216,36 +210,35 @@ bool Timestamp::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Timestamp)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional int64 seconds = 1;
+ // int64 seconds = 1;
case 1: {
- if (tag == 8) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(8u)) {
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int64, ::google::protobuf::internal::WireFormatLite::TYPE_INT64>(
input, &seconds_)));
-
} else {
goto handle_unusual;
}
- if (input->ExpectTag(16)) goto parse_nanos;
break;
}
- // optional int32 nanos = 2;
+ // int32 nanos = 2;
case 2: {
- if (tag == 16) {
- parse_nanos:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(16u)) {
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
input, &nanos_)));
-
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -273,12 +266,12 @@ failure:
void Timestamp::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.Timestamp)
- // optional int64 seconds = 1;
+ // int64 seconds = 1;
if (this->seconds() != 0) {
::google::protobuf::internal::WireFormatLite::WriteInt64(1, this->seconds(), output);
}
- // optional int32 nanos = 2;
+ // int32 nanos = 2;
if (this->nanos() != 0) {
::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->nanos(), output);
}
@@ -288,13 +281,14 @@ void Timestamp::SerializeWithCachedSizes(
::google::protobuf::uint8* Timestamp::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Timestamp)
- // optional int64 seconds = 1;
+ // int64 seconds = 1;
if (this->seconds() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteInt64ToArray(1, this->seconds(), target);
}
- // optional int32 nanos = 2;
+ // int32 nanos = 2;
if (this->nanos() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->nanos(), target);
}
@@ -303,36 +297,35 @@ 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;
+ // int64 seconds = 1;
if (this->seconds() != 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::Int64Size(
this->seconds());
}
- // optional int32 nanos = 2;
+ // int32 nanos = 2;
if (this->nanos() != 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::Int32Size(
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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const Timestamp* source =
::google::protobuf::internal::DynamicCastToGenerated<const Timestamp>(
&from);
if (source == NULL) {
@@ -346,9 +339,8 @@ void Timestamp::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
if (from.seconds() != 0) {
set_seconds(from.seconds());
}
@@ -372,7 +364,6 @@ void Timestamp::CopyFrom(const Timestamp& from) {
}
bool Timestamp::IsInitialized() const {
-
return true;
}
@@ -381,10 +372,13 @@ void Timestamp::Swap(Timestamp* other) {
if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
InternalSwap(other);
} else {
- Timestamp temp;
- temp.MergeFrom(*this);
- CopyFrom(*other);
- other->CopyFrom(temp);
+ Timestamp* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
}
}
void Timestamp::UnsafeArenaSwap(Timestamp* other) {
@@ -395,44 +389,40 @@ void Timestamp::UnsafeArenaSwap(Timestamp* other) {
void Timestamp::InternalSwap(Timestamp* other) {
std::swap(seconds_, other->seconds_);
std::swap(nanos_, other->nanos_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Timestamp::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = Timestamp_descriptor_;
- metadata.reflection = Timestamp_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2ftimestamp_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2ftimestamp_2eproto::file_level_metadata[0];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// Timestamp
-// optional int64 seconds = 1;
+// int64 seconds = 1;
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)
}
-// optional int32 nanos = 2;
+// int32 nanos = 2;
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/third_party/protobuf/3.0.0/src/google/protobuf/timestamp.pb.h b/third_party/protobuf/src/google/protobuf/timestamp.pb.h
index 19f4f86f70..e6fc09a1cc 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/timestamp.pb.h
+++ b/third_party/protobuf/src/google/protobuf/timestamp.pb.h
@@ -8,36 +8,48 @@
#include <google/protobuf/stubs/common.h>
-#if GOOGLE_PROTOBUF_VERSION < 3000000
+#if GOOGLE_PROTOBUF_VERSION < 3002000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
-#if 3000000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
+#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
+#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/metadata.h>
#include <google/protobuf/message.h>
-#include <google/protobuf/repeated_field.h>
-#include <google/protobuf/extension_set.h>
+#include <google/protobuf/repeated_field.h> // IWYU pragma: export
+#include <google/protobuf/extension_set.h> // IWYU pragma: export
#include <google/protobuf/unknown_field_set.h>
// @@protoc_insertion_point(includes)
+namespace google {
+namespace protobuf {
+class Timestamp;
+class TimestampDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern TimestampDefaultTypeInternal _Timestamp_default_instance_;
+} // namespace protobuf
+} // namespace google
namespace google {
namespace protobuf {
+namespace protobuf_google_2fprotobuf_2ftimestamp_2eproto {
// Internal implementation detail -- do not call these.
-void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto();
-void protobuf_AssignDesc_google_2fprotobuf_2ftimestamp_2eproto();
-void protobuf_ShutdownFile_google_2fprotobuf_2ftimestamp_2eproto();
-
-class Timestamp;
+struct LIBPROTOBUF_EXPORT TableStruct {
+ static const ::google::protobuf::uint32 offsets[];
+ static void InitDefaultsImpl();
+ static void Shutdown();
+};
+void LIBPROTOBUF_EXPORT AddDescriptors();
+void LIBPROTOBUF_EXPORT InitDefaults();
+} // namespace protobuf_google_2fprotobuf_2ftimestamp_2eproto
// ===================================================================
@@ -53,43 +65,52 @@ class LIBPROTOBUF_EXPORT Timestamp : public ::google::protobuf::Message /* @@pro
return *this;
}
- inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); }
- inline void* GetMaybeArenaPointer() const {
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
return MaybeArenaPtr();
}
static const ::google::protobuf::Descriptor* descriptor();
static const Timestamp& default_instance();
+ static inline const Timestamp* internal_default_instance() {
+ return reinterpret_cast<const Timestamp*>(
+ &_Timestamp_default_instance_);
+ }
+
void UnsafeArenaSwap(Timestamp* other);
void Swap(Timestamp* other);
// implements Message ----------------------------------------------
- inline Timestamp* New() const { return New(NULL); }
+ inline Timestamp* New() const PROTOBUF_FINAL { return New(NULL); }
- Timestamp* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ Timestamp* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Timestamp& from);
void MergeFrom(const Timestamp& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Timestamp* other);
protected:
explicit Timestamp(::google::protobuf::Arena* arena);
@@ -105,19 +126,19 @@ class LIBPROTOBUF_EXPORT Timestamp : public ::google::protobuf::Message /* @@pro
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional int64 seconds = 1;
+ // int64 seconds = 1;
void clear_seconds();
static const int kSecondsFieldNumber = 1;
::google::protobuf::int64 seconds() const;
void set_seconds(::google::protobuf::int64 value);
- // optional int32 nanos = 2;
+ // int32 nanos = 2;
void clear_nanos();
static const int kNanosFieldNumber = 2;
::google::protobuf::int32 nanos() const;
@@ -130,16 +151,10 @@ 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 protobuf_AssignDesc_google_2fprotobuf_2ftimestamp_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2ftimestamp_2eproto();
-
- void InitAsDefaultInstance();
- static Timestamp* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2ftimestamp_2eproto::TableStruct;
};
// ===================================================================
@@ -149,7 +164,7 @@ class LIBPROTOBUF_EXPORT Timestamp : public ::google::protobuf::Message /* @@pro
#if !PROTOBUF_INLINE_NOT_IN_HEADERS
// Timestamp
-// optional int64 seconds = 1;
+// int64 seconds = 1;
inline void Timestamp::clear_seconds() {
seconds_ = GOOGLE_LONGLONG(0);
}
@@ -163,7 +178,7 @@ inline void Timestamp::set_seconds(::google::protobuf::int64 value) {
// @@protoc_insertion_point(field_set:google.protobuf.Timestamp.seconds)
}
-// optional int32 nanos = 2;
+// int32 nanos = 2;
inline void Timestamp::clear_nanos() {
nanos_ = 0;
}
@@ -181,6 +196,7 @@ inline void Timestamp::set_nanos(::google::protobuf::int32 value) {
// @@protoc_insertion_point(namespace_scope)
+
} // namespace protobuf
} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/timestamp.proto b/third_party/protobuf/src/google/protobuf/timestamp.proto
index 7992a85886..67e2eba4f8 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/timestamp.proto
+++ b/third_party/protobuf/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/third_party/protobuf/3.0.0/src/google/protobuf/type.pb.cc b/third_party/protobuf/src/google/protobuf/type.pb.cc
index 7ba909ef1c..017392c9d9 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/type.pb.cc
+++ b/third_party/protobuf/src/google/protobuf/type.pb.cc
@@ -19,253 +19,303 @@
namespace google {
namespace protobuf {
+class TypeDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Type> {
+} _Type_default_instance_;
+class FieldDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Field> {
+} _Field_default_instance_;
+class EnumDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Enum> {
+} _Enum_default_instance_;
+class EnumValueDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<EnumValue> {
+} _EnumValue_default_instance_;
+class OptionDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Option> {
+} _Option_default_instance_;
+
+namespace protobuf_google_2fprotobuf_2ftype_2eproto {
+
namespace {
-const ::google::protobuf::Descriptor* Type_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- Type_reflection_ = NULL;
-const ::google::protobuf::Descriptor* Field_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- Field_reflection_ = NULL;
-const ::google::protobuf::EnumDescriptor* Field_Kind_descriptor_ = NULL;
-const ::google::protobuf::EnumDescriptor* Field_Cardinality_descriptor_ = NULL;
-const ::google::protobuf::Descriptor* Enum_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- Enum_reflection_ = NULL;
-const ::google::protobuf::Descriptor* EnumValue_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- EnumValue_reflection_ = NULL;
-const ::google::protobuf::Descriptor* Option_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- Option_reflection_ = NULL;
-const ::google::protobuf::EnumDescriptor* Syntax_descriptor_ = NULL;
+::google::protobuf::Metadata file_level_metadata[5];
+const ::google::protobuf::EnumDescriptor* file_level_enum_descriptors[3];
} // namespace
-
-void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto() GOOGLE_ATTRIBUTE_COLD;
-void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto();
- const ::google::protobuf::FileDescriptor* file =
- ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
- "google/protobuf/type.proto");
- GOOGLE_CHECK(file != NULL);
- Type_descriptor_ = file->message_type(0);
- static const int Type_offsets_[6] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, fields_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, oneofs_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, options_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, source_context_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, syntax_),
- };
- Type_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- Type_descriptor_,
- Type::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_));
- Field_descriptor_ = file->message_type(1);
- static const int Field_offsets_[10] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, kind_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, cardinality_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, number_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, type_url_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, oneof_index_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, packed_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, options_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, json_name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, default_value_),
- };
- Field_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- Field_descriptor_,
- Field::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_));
- Field_Kind_descriptor_ = Field_descriptor_->enum_type(0);
- Field_Cardinality_descriptor_ = Field_descriptor_->enum_type(1);
- Enum_descriptor_ = file->message_type(2);
- static const int Enum_offsets_[5] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, enumvalue_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, options_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, source_context_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, syntax_),
- };
- Enum_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- Enum_descriptor_,
- Enum::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_));
- EnumValue_descriptor_ = file->message_type(3);
- static const int EnumValue_offsets_[3] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValue, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValue, number_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValue, options_),
- };
- EnumValue_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- EnumValue_descriptor_,
- EnumValue::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_));
- Option_descriptor_ = file->message_type(4);
- static const int Option_offsets_[2] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Option, name_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Option, value_),
- };
- Option_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- Option_descriptor_,
- Option::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_));
- Syntax_descriptor_ = file->enum_type(0);
-}
+const ::google::protobuf::uint32 TableStruct::offsets[] = {
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, fields_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, oneofs_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, options_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, source_context_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, syntax_),
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, kind_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, cardinality_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, number_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, type_url_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, oneof_index_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, packed_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, options_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, json_name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Field, default_value_),
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, enumvalue_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, options_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, source_context_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Enum, syntax_),
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValue, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValue, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValue, number_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(EnumValue, options_),
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Option, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Option, name_),
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Option, value_),
+};
+
+static const ::google::protobuf::internal::MigrationSchema schemas[] = {
+ { 0, -1, sizeof(Type)},
+ { 10, -1, sizeof(Field)},
+ { 24, -1, sizeof(Enum)},
+ { 33, -1, sizeof(EnumValue)},
+ { 40, -1, sizeof(Option)},
+};
+
+static ::google::protobuf::Message const * const file_default_instances[] = {
+ reinterpret_cast<const ::google::protobuf::Message*>(&_Type_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_Field_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_Enum_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_EnumValue_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_Option_default_instance_),
+};
namespace {
-GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
-inline void protobuf_AssignDescriptorsOnce() {
- ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
- &protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto);
+void protobuf_AssignDescriptors() {
+ AddDescriptors();
+ ::google::protobuf::MessageFactory* factory = NULL;
+ AssignDescriptors(
+ "google/protobuf/type.proto", schemas, file_default_instances, TableStruct::offsets, factory,
+ file_level_metadata, file_level_enum_descriptors, NULL);
+}
+
+void protobuf_AssignDescriptorsOnce() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
}
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());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- Field_descriptor_, &Field::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- Enum_descriptor_, &Enum::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- EnumValue_descriptor_, &EnumValue::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- Option_descriptor_, &Option::default_instance());
+ ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 5);
}
} // 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 TableStruct::Shutdown() {
+ _Type_default_instance_.Shutdown();
+ delete file_level_metadata[0].reflection;
+ _Field_default_instance_.Shutdown();
+ delete file_level_metadata[1].reflection;
+ _Enum_default_instance_.Shutdown();
+ delete file_level_metadata[2].reflection;
+ _EnumValue_default_instance_.Shutdown();
+ delete file_level_metadata[3].reflection;
+ _Option_default_instance_.Shutdown();
+ delete file_level_metadata[4].reflection;
+}
+
+void TableStruct::InitDefaultsImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
- ::google::protobuf::protobuf_AddDesc_google_2fprotobuf_2fany_2eproto();
- ::google::protobuf::protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto();
+ ::google::protobuf::internal::InitProtobufDefaults();
+ ::google::protobuf::protobuf_google_2fprotobuf_2fany_2eproto::InitDefaults();
+ ::google::protobuf::protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::InitDefaults();
+ _Type_default_instance_.DefaultConstruct();
+ _Field_default_instance_.DefaultConstruct();
+ _Enum_default_instance_.DefaultConstruct();
+ _EnumValue_default_instance_.DefaultConstruct();
+ _Option_default_instance_.DefaultConstruct();
+ _Type_default_instance_.get_mutable()->source_context_ = const_cast< ::google::protobuf::SourceContext*>(
+ ::google::protobuf::SourceContext::internal_default_instance());
+ _Enum_default_instance_.get_mutable()->source_context_ = const_cast< ::google::protobuf::SourceContext*>(
+ ::google::protobuf::SourceContext::internal_default_instance());
+ _Option_default_instance_.get_mutable()->value_ = const_cast< ::google::protobuf::Any*>(
+ ::google::protobuf::Any::internal_default_instance());
+}
+
+void InitDefaults() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &TableStruct::InitDefaultsImpl);
+}
+void AddDescriptorsImpl() {
+ InitDefaults();
+ static const char descriptor[] = {
+ "\n\032google/protobuf/type.proto\022\017google.pro"
+ "tobuf\032\031google/protobuf/any.proto\032$google"
+ "/protobuf/source_context.proto\"\327\001\n\004Type\022"
+ "\014\n\004name\030\001 \001(\t\022&\n\006fields\030\002 \003(\0132\026.google.p"
+ "rotobuf.Field\022\016\n\006oneofs\030\003 \003(\t\022(\n\007options"
+ "\030\004 \003(\0132\027.google.protobuf.Option\0226\n\016sourc"
+ "e_context\030\005 \001(\0132\036.google.protobuf.Source"
+ "Context\022\'\n\006syntax\030\006 \001(\0162\027.google.protobu"
+ "f.Syntax\"\325\005\n\005Field\022)\n\004kind\030\001 \001(\0162\033.googl"
+ "e.protobuf.Field.Kind\0227\n\013cardinality\030\002 \001"
+ "(\0162\".google.protobuf.Field.Cardinality\022\016"
+ "\n\006number\030\003 \001(\005\022\014\n\004name\030\004 \001(\t\022\020\n\010type_url"
+ "\030\006 \001(\t\022\023\n\013oneof_index\030\007 \001(\005\022\016\n\006packed\030\010 "
+ "\001(\010\022(\n\007options\030\t \003(\0132\027.google.protobuf.O"
+ "ption\022\021\n\tjson_name\030\n \001(\t\022\025\n\rdefault_valu"
+ "e\030\013 \001(\t\"\310\002\n\004Kind\022\020\n\014TYPE_UNKNOWN\020\000\022\017\n\013TY"
+ "PE_DOUBLE\020\001\022\016\n\nTYPE_FLOAT\020\002\022\016\n\nTYPE_INT6"
+ "4\020\003\022\017\n\013TYPE_UINT64\020\004\022\016\n\nTYPE_INT32\020\005\022\020\n\014"
+ "TYPE_FIXED64\020\006\022\020\n\014TYPE_FIXED32\020\007\022\r\n\tTYPE"
+ "_BOOL\020\010\022\017\n\013TYPE_STRING\020\t\022\016\n\nTYPE_GROUP\020\n"
+ "\022\020\n\014TYPE_MESSAGE\020\013\022\016\n\nTYPE_BYTES\020\014\022\017\n\013TY"
+ "PE_UINT32\020\r\022\r\n\tTYPE_ENUM\020\016\022\021\n\rTYPE_SFIXE"
+ "D32\020\017\022\021\n\rTYPE_SFIXED64\020\020\022\017\n\013TYPE_SINT32\020"
+ "\021\022\017\n\013TYPE_SINT64\020\022\"t\n\013Cardinality\022\027\n\023CAR"
+ "DINALITY_UNKNOWN\020\000\022\030\n\024CARDINALITY_OPTION"
+ "AL\020\001\022\030\n\024CARDINALITY_REQUIRED\020\002\022\030\n\024CARDIN"
+ "ALITY_REPEATED\020\003\"\316\001\n\004Enum\022\014\n\004name\030\001 \001(\t\022"
+ "-\n\tenumvalue\030\002 \003(\0132\032.google.protobuf.Enu"
+ "mValue\022(\n\007options\030\003 \003(\0132\027.google.protobu"
+ "f.Option\0226\n\016source_context\030\004 \001(\0132\036.googl"
+ "e.protobuf.SourceContext\022\'\n\006syntax\030\005 \001(\016"
+ "2\027.google.protobuf.Syntax\"S\n\tEnumValue\022\014"
+ "\n\004name\030\001 \001(\t\022\016\n\006number\030\002 \001(\005\022(\n\007options\030"
+ "\003 \003(\0132\027.google.protobuf.Option\";\n\006Option"
+ "\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\001B}\n\023com.google.protob"
+ "ufB\tTypeProtoP\001Z/google.golang.org/genpr"
+ "oto/protobuf/ptype;ptype\370\001\001\242\002\003GPB\252\002\036Goog"
+ "le.Protobuf.WellKnownTypesb\006proto3"
+ };
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
- "\n\032google/protobuf/type.proto\022\017google.pro"
- "tobuf\032\031google/protobuf/any.proto\032$google"
- "/protobuf/source_context.proto\"\327\001\n\004Type\022"
- "\014\n\004name\030\001 \001(\t\022&\n\006fields\030\002 \003(\0132\026.google.p"
- "rotobuf.Field\022\016\n\006oneofs\030\003 \003(\t\022(\n\007options"
- "\030\004 \003(\0132\027.google.protobuf.Option\0226\n\016sourc"
- "e_context\030\005 \001(\0132\036.google.protobuf.Source"
- "Context\022\'\n\006syntax\030\006 \001(\0162\027.google.protobu"
- "f.Syntax\"\325\005\n\005Field\022)\n\004kind\030\001 \001(\0162\033.googl"
- "e.protobuf.Field.Kind\0227\n\013cardinality\030\002 \001"
- "(\0162\".google.protobuf.Field.Cardinality\022\016"
- "\n\006number\030\003 \001(\005\022\014\n\004name\030\004 \001(\t\022\020\n\010type_url"
- "\030\006 \001(\t\022\023\n\013oneof_index\030\007 \001(\005\022\016\n\006packed\030\010 "
- "\001(\010\022(\n\007options\030\t \003(\0132\027.google.protobuf.O"
- "ption\022\021\n\tjson_name\030\n \001(\t\022\025\n\rdefault_valu"
- "e\030\013 \001(\t\"\310\002\n\004Kind\022\020\n\014TYPE_UNKNOWN\020\000\022\017\n\013TY"
- "PE_DOUBLE\020\001\022\016\n\nTYPE_FLOAT\020\002\022\016\n\nTYPE_INT6"
- "4\020\003\022\017\n\013TYPE_UINT64\020\004\022\016\n\nTYPE_INT32\020\005\022\020\n\014"
- "TYPE_FIXED64\020\006\022\020\n\014TYPE_FIXED32\020\007\022\r\n\tTYPE"
- "_BOOL\020\010\022\017\n\013TYPE_STRING\020\t\022\016\n\nTYPE_GROUP\020\n"
- "\022\020\n\014TYPE_MESSAGE\020\013\022\016\n\nTYPE_BYTES\020\014\022\017\n\013TY"
- "PE_UINT32\020\r\022\r\n\tTYPE_ENUM\020\016\022\021\n\rTYPE_SFIXE"
- "D32\020\017\022\021\n\rTYPE_SFIXED64\020\020\022\017\n\013TYPE_SINT32\020"
- "\021\022\017\n\013TYPE_SINT64\020\022\"t\n\013Cardinality\022\027\n\023CAR"
- "DINALITY_UNKNOWN\020\000\022\030\n\024CARDINALITY_OPTION"
- "AL\020\001\022\030\n\024CARDINALITY_REQUIRED\020\002\022\030\n\024CARDIN"
- "ALITY_REPEATED\020\003\"\316\001\n\004Enum\022\014\n\004name\030\001 \001(\t\022"
- "-\n\tenumvalue\030\002 \003(\0132\032.google.protobuf.Enu"
- "mValue\022(\n\007options\030\003 \003(\0132\027.google.protobu"
- "f.Option\0226\n\016source_context\030\004 \001(\0132\036.googl"
- "e.protobuf.SourceContext\022\'\n\006syntax\030\005 \001(\016"
- "2\027.google.protobuf.Syntax\"S\n\tEnumValue\022\014"
- "\n\004name\030\001 \001(\t\022\016\n\006number\030\002 \001(\005\022(\n\007options\030"
- "\003 \003(\0132\027.google.protobuf.Option\";\n\006Option"
- "\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"
- "uf.WellKnownTypesb\006proto3", 1545);
+ descriptor, 1594);
::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::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2ftype_2eproto);
+ ::google::protobuf::protobuf_google_2fprotobuf_2fany_2eproto::AddDescriptors();
+ ::google::protobuf::protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::AddDescriptors();
+ ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown);
}
+void AddDescriptors() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
+}
// Force AddDescriptors() to be called at static initialization time.
-struct StaticDescriptorInitializer_google_2fprotobuf_2ftype_2eproto {
- StaticDescriptorInitializer_google_2fprotobuf_2ftype_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto();
+struct StaticDescriptorInitializer {
+ StaticDescriptorInitializer() {
+ AddDescriptors();
+ }
+} static_descriptor_initializer;
+
+} // namespace protobuf_google_2fprotobuf_2ftype_2eproto
+
+const ::google::protobuf::EnumDescriptor* Field_Kind_descriptor() {
+ protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_enum_descriptors[0];
+}
+bool Field_Kind_IsValid(int value) {
+ switch (value) {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ case 8:
+ case 9:
+ case 10:
+ case 11:
+ case 12:
+ case 13:
+ case 14:
+ case 15:
+ case 16:
+ case 17:
+ case 18:
+ return true;
+ default:
+ return false;
+ }
+}
+
+#if !defined(_MSC_VER) || _MSC_VER >= 1900
+const Field_Kind Field::TYPE_UNKNOWN;
+const Field_Kind Field::TYPE_DOUBLE;
+const Field_Kind Field::TYPE_FLOAT;
+const Field_Kind Field::TYPE_INT64;
+const Field_Kind Field::TYPE_UINT64;
+const Field_Kind Field::TYPE_INT32;
+const Field_Kind Field::TYPE_FIXED64;
+const Field_Kind Field::TYPE_FIXED32;
+const Field_Kind Field::TYPE_BOOL;
+const Field_Kind Field::TYPE_STRING;
+const Field_Kind Field::TYPE_GROUP;
+const Field_Kind Field::TYPE_MESSAGE;
+const Field_Kind Field::TYPE_BYTES;
+const Field_Kind Field::TYPE_UINT32;
+const Field_Kind Field::TYPE_ENUM;
+const Field_Kind Field::TYPE_SFIXED32;
+const Field_Kind Field::TYPE_SFIXED64;
+const Field_Kind Field::TYPE_SINT32;
+const Field_Kind Field::TYPE_SINT64;
+const Field_Kind Field::Kind_MIN;
+const Field_Kind Field::Kind_MAX;
+const int Field::Kind_ARRAYSIZE;
+#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
+const ::google::protobuf::EnumDescriptor* Field_Cardinality_descriptor() {
+ protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_enum_descriptors[1];
+}
+bool Field_Cardinality_IsValid(int value) {
+ switch (value) {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ return true;
+ default:
+ return false;
}
-} static_descriptor_initializer_google_2fprotobuf_2ftype_2eproto_;
+}
+
+#if !defined(_MSC_VER) || _MSC_VER >= 1900
+const Field_Cardinality Field::CARDINALITY_UNKNOWN;
+const Field_Cardinality Field::CARDINALITY_OPTIONAL;
+const Field_Cardinality Field::CARDINALITY_REQUIRED;
+const Field_Cardinality Field::CARDINALITY_REPEATED;
+const Field_Cardinality Field::Cardinality_MIN;
+const Field_Cardinality Field::Cardinality_MAX;
+const int Field::Cardinality_ARRAYSIZE;
+#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
const ::google::protobuf::EnumDescriptor* Syntax_descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Syntax_descriptor_;
+ protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_enum_descriptors[2];
}
bool Syntax_IsValid(int value) {
- switch(value) {
+ switch (value) {
case 0:
case 1:
return true;
@@ -277,6 +327,39 @@ bool Syntax_IsValid(int value) {
// ===================================================================
+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 +371,52 @@ const int Type::kSyntaxFieldNumber;
Type::Type()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.Type)
}
-
-void Type::InitAsDefaultInstance() {
- _is_default_instance_ = true;
- source_context_ = const_cast< ::google::protobuf::SourceContext*>(&::google::protobuf::SourceContext::default_instance());
+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_google_2fprotobuf_2ftype_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ SharedCtor();
+ RegisterArenaDtor(arena);
+ // @@protoc_insertion_point(arena_constructor:google.protobuf.Type)
}
-
Type::Type(const Type& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ fields_(from.fields_),
+ oneofs_(from.oneofs_),
+ options_(from.options_),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.name().size() > 0) {
+ name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name(),
+ GetArenaNoVirtual());
+ }
+ if (from.has_source_context()) {
+ source_context_ = new ::google::protobuf::SourceContext(*from.source_context_);
+ } else {
+ source_context_ = NULL;
+ }
+ syntax_ = from.syntax_;
// @@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;
+ ::memset(&source_context_, 0, reinterpret_cast<char*>(&syntax_) -
+ reinterpret_cast<char*>(&source_context_) + sizeof(syntax_));
+ _cached_size_ = 0;
}
Type::~Type() {
@@ -320,46 +425,53 @@ Type::~Type() {
}
void Type::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);
+ if (this != internal_default_instance()) {
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;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Type::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Type_descriptor_;
+ protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[0].descriptor;
}
const Type& Type::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-Type* Type::default_instance_ = NULL;
-
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<Type>(arena);
}
void Type::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.Type)
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- if (GetArenaNoVirtual() == NULL && source_context_ != NULL) delete source_context_;
- source_context_ = NULL;
- syntax_ = 0;
fields_.Clear();
oneofs_.Clear();
options_.Clear();
+ name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
+ if (GetArenaNoVirtual() == NULL && source_context_ != NULL) {
+ delete source_context_;
+ }
+ source_context_ = NULL;
+ syntax_ = 0;
}
bool Type::MergePartialFromCodedStream(
@@ -368,13 +480,14 @@ bool Type::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Type)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional string name = 1;
+ // string name = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -384,31 +497,27 @@ bool Type::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_fields;
break;
}
// repeated .google.protobuf.Field fields = 2;
case 2: {
- if (tag == 18) {
- parse_fields:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_fields:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_fields()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_loop_fields;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectTag(26)) goto parse_oneofs;
break;
}
// repeated string oneofs = 3;
case 3: {
- if (tag == 26) {
- parse_oneofs:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(26u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->add_oneofs()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -419,45 +528,39 @@ bool Type::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(26)) goto parse_oneofs;
- if (input->ExpectTag(34)) goto parse_options;
break;
}
// repeated .google.protobuf.Option options = 4;
case 4: {
- if (tag == 34) {
- parse_options:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(34u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_options:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_options()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(34)) goto parse_loop_options;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectTag(42)) goto parse_source_context;
break;
}
- // optional .google.protobuf.SourceContext source_context = 5;
+ // .google.protobuf.SourceContext source_context = 5;
case 5: {
- if (tag == 42) {
- parse_source_context:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(42u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, mutable_source_context()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(48)) goto parse_syntax;
break;
}
- // optional .google.protobuf.Syntax syntax = 6;
+ // .google.protobuf.Syntax syntax = 6;
case 6: {
- if (tag == 48) {
- parse_syntax:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(48u)) {
int value;
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(
@@ -466,7 +569,6 @@ bool Type::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -494,7 +596,7 @@ failure:
void Type::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.Type)
- // optional string name = 1;
+ // string name = 1;
if (this->name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->name().data(), this->name().length(),
@@ -511,7 +613,7 @@ void Type::SerializeWithCachedSizes(
}
// repeated string oneofs = 3;
- for (int i = 0; i < this->oneofs_size(); i++) {
+ for (int i = 0, n = this->oneofs_size(); i < n; i++) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->oneofs(i).data(), this->oneofs(i).length(),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
@@ -526,13 +628,13 @@ void Type::SerializeWithCachedSizes(
4, this->options(i), output);
}
- // optional .google.protobuf.SourceContext source_context = 5;
+ // .google.protobuf.SourceContext source_context = 5;
if (this->has_source_context()) {
::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
5, *this->source_context_, output);
}
- // optional .google.protobuf.Syntax syntax = 6;
+ // .google.protobuf.Syntax syntax = 6;
if (this->syntax() != 0) {
::google::protobuf::internal::WireFormatLite::WriteEnum(
6, this->syntax(), output);
@@ -543,8 +645,9 @@ void Type::SerializeWithCachedSizes(
::google::protobuf::uint8* Type::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Type)
- // optional string name = 1;
+ // string name = 1;
if (this->name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->name().data(), this->name().length(),
@@ -563,7 +666,7 @@ void Type::SerializeWithCachedSizes(
}
// repeated string oneofs = 3;
- for (int i = 0; i < this->oneofs_size(); i++) {
+ for (int i = 0, n = this->oneofs_size(); i < n; i++) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->oneofs(i).data(), this->oneofs(i).length(),
::google::protobuf::internal::WireFormatLite::SERIALIZE,
@@ -579,14 +682,14 @@ void Type::SerializeWithCachedSizes(
4, this->options(i), false, target);
}
- // optional .google.protobuf.SourceContext source_context = 5;
+ // .google.protobuf.SourceContext source_context = 5;
if (this->has_source_context()) {
target = ::google::protobuf::internal::WireFormatLite::
InternalWriteMessageNoVirtualToArray(
5, *this->source_context_, false, target);
}
- // optional .google.protobuf.Syntax syntax = 6;
+ // .google.protobuf.Syntax syntax = 6;
if (this->syntax() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray(
6, this->syntax(), target);
@@ -596,65 +699,71 @@ 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;
+
+ // repeated .google.protobuf.Field fields = 2;
+ {
+ 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 *
+ ::google::protobuf::internal::FromIntSize(this->oneofs_size());
+ for (int i = 0, n = this->oneofs_size(); i < n; i++) {
+ total_size += ::google::protobuf::internal::WireFormatLite::StringSize(
+ this->oneofs(i));
+ }
- // optional string name = 1;
+ // repeated .google.protobuf.Option options = 4;
+ {
+ 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));
+ }
+ }
+
+ // string name = 1;
if (this->name().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->name());
}
- // optional .google.protobuf.SourceContext source_context = 5;
+ // .google.protobuf.SourceContext source_context = 5;
if (this->has_source_context()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual(
*this->source_context_);
}
- // optional .google.protobuf.Syntax syntax = 6;
+ // .google.protobuf.Syntax syntax = 6;
if (this->syntax() != 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::EnumSize(this->syntax());
}
- // 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));
- }
-
- // repeated string oneofs = 3;
- total_size += 1 * 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));
- }
-
+ 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const Type* source =
::google::protobuf::internal::DynamicCastToGenerated<const Type>(
&from);
if (source == NULL) {
@@ -668,15 +777,13 @@ void Type::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
fields_.MergeFrom(from.fields_);
oneofs_.MergeFrom(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());
@@ -701,79 +808,111 @@ void Type::CopyFrom(const Type& from) {
}
bool Type::IsInitialized() const {
-
return true;
}
void Type::Swap(Type* other) {
if (other == this) return;
+ if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
+ InternalSwap(other);
+ } else {
+ Type* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
+ }
+}
+void Type::UnsafeArenaSwap(Type* other) {
+ if (other == this) return;
+ GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual());
InternalSwap(other);
}
void Type::InternalSwap(Type* other) {
- name_.Swap(&other->name_);
fields_.UnsafeArenaSwap(&other->fields_);
oneofs_.UnsafeArenaSwap(&other->oneofs_);
options_.UnsafeArenaSwap(&other->options_);
+ name_.Swap(&other->name_);
std::swap(source_context_, other->source_context_);
std::swap(syntax_, other->syntax_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Type::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = Type_descriptor_;
- metadata.reflection = Type_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[0];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// Type
-// optional string name = 1;
+// 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();
}
- 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<const char*>(value), size));
+ name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(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());
+}
+::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) {
+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 {
@@ -812,49 +951,61 @@ 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) {
+#if LANG_CXX11
+void Type::set_oneofs(int index, ::std::string&& value) {
+ // @@protoc_insertion_point(field_set:google.protobuf.Type.oneofs)
+ oneofs_.Mutable(index)->assign(std::move(value));
+}
+#endif
+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<const char*>(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) {
+#if LANG_CXX11
+void Type::add_oneofs(::std::string&& value) {
+ oneofs_.Add()->assign(std::move(value));
+ // @@protoc_insertion_point(field_add:google.protobuf.Type.oneofs)
+}
+#endif
+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<const char*>(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_;
@@ -890,9 +1041,9 @@ Type::options() const {
return options_;
}
-// optional .google.protobuf.SourceContext source_context = 5;
+// .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_;
@@ -900,12 +1051,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_;
@@ -913,12 +1065,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) {
@@ -928,15 +1092,15 @@ void Type::set_allocated_source_context(::google::protobuf::SourceContext* sourc
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Type.source_context)
}
-// optional .google.protobuf.Syntax syntax = 6;
+// .google.protobuf.Syntax syntax = 6;
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)
@@ -946,86 +1110,6 @@ void Type::clear_syntax() {
// ===================================================================
-const ::google::protobuf::EnumDescriptor* Field_Kind_descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Field_Kind_descriptor_;
-}
-bool Field_Kind_IsValid(int value) {
- switch(value) {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- case 9:
- case 10:
- case 11:
- case 12:
- case 13:
- case 14:
- case 15:
- case 16:
- case 17:
- case 18:
- return true;
- default:
- return false;
- }
-}
-
-#if !defined(_MSC_VER) || _MSC_VER >= 1900
-const Field_Kind Field::TYPE_UNKNOWN;
-const Field_Kind Field::TYPE_DOUBLE;
-const Field_Kind Field::TYPE_FLOAT;
-const Field_Kind Field::TYPE_INT64;
-const Field_Kind Field::TYPE_UINT64;
-const Field_Kind Field::TYPE_INT32;
-const Field_Kind Field::TYPE_FIXED64;
-const Field_Kind Field::TYPE_FIXED32;
-const Field_Kind Field::TYPE_BOOL;
-const Field_Kind Field::TYPE_STRING;
-const Field_Kind Field::TYPE_GROUP;
-const Field_Kind Field::TYPE_MESSAGE;
-const Field_Kind Field::TYPE_BYTES;
-const Field_Kind Field::TYPE_UINT32;
-const Field_Kind Field::TYPE_ENUM;
-const Field_Kind Field::TYPE_SFIXED32;
-const Field_Kind Field::TYPE_SFIXED64;
-const Field_Kind Field::TYPE_SINT32;
-const Field_Kind Field::TYPE_SINT64;
-const Field_Kind Field::Kind_MIN;
-const Field_Kind Field::Kind_MAX;
-const int Field::Kind_ARRAYSIZE;
-#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
-const ::google::protobuf::EnumDescriptor* Field_Cardinality_descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Field_Cardinality_descriptor_;
-}
-bool Field_Cardinality_IsValid(int value) {
- switch(value) {
- case 0:
- case 1:
- case 2:
- case 3:
- return true;
- default:
- return false;
- }
-}
-
-#if !defined(_MSC_VER) || _MSC_VER >= 1900
-const Field_Cardinality Field::CARDINALITY_UNKNOWN;
-const Field_Cardinality Field::CARDINALITY_OPTIONAL;
-const Field_Cardinality Field::CARDINALITY_REQUIRED;
-const Field_Cardinality Field::CARDINALITY_REPEATED;
-const Field_Cardinality Field::Cardinality_MIN;
-const Field_Cardinality Field::Cardinality_MAX;
-const int Field::Cardinality_ARRAYSIZE;
-#endif // !defined(_MSC_VER) || _MSC_VER >= 1900
#if !defined(_MSC_VER) || _MSC_VER >= 1900
const int Field::kKindFieldNumber;
const int Field::kCardinalityFieldNumber;
@@ -1041,35 +1125,63 @@ const int Field::kDefaultValueFieldNumber;
Field::Field()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.Field)
}
-
-void Field::InitAsDefaultInstance() {
- _is_default_instance_ = true;
+Field::Field(::google::protobuf::Arena* arena)
+ : ::google::protobuf::Message(),
+ _internal_metadata_(arena),
+ options_(arena) {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ SharedCtor();
+ RegisterArenaDtor(arena);
+ // @@protoc_insertion_point(arena_constructor:google.protobuf.Field)
}
-
Field::Field(const Field& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ options_(from.options_),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.name().size() > 0) {
+ name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name(),
+ GetArenaNoVirtual());
+ }
+ type_url_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.type_url().size() > 0) {
+ type_url_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.type_url(),
+ GetArenaNoVirtual());
+ }
+ json_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.json_name().size() > 0) {
+ json_name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.json_name(),
+ GetArenaNoVirtual());
+ }
+ default_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.default_value().size() > 0) {
+ default_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.default_value(),
+ GetArenaNoVirtual());
+ }
+ ::memcpy(&kind_, &from.kind_,
+ reinterpret_cast<char*>(&packed_) -
+ reinterpret_cast<char*>(&kind_) + sizeof(packed_));
// @@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<char*>(&packed_) -
+ reinterpret_cast<char*>(&kind_) + sizeof(packed_));
+ _cached_size_ = 0;
}
Field::~Field() {
@@ -1078,69 +1190,51 @@ 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;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Field::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Field_descriptor_;
+ protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[1].descriptor;
}
const Field& Field::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-Field* Field::default_instance_ = NULL;
-
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<Field>(arena);
}
void Field::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.Field)
-#if defined(__clang__)
-#define ZR_HELPER_(f) \
- _Pragma("clang diagnostic push") \
- _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \
- __builtin_offsetof(Field, f) \
- _Pragma("clang diagnostic pop")
-#else
-#define ZR_HELPER_(f) reinterpret_cast<char*>(\
- &reinterpret_cast<Field*>(16)->f)
-#endif
-
-#define ZR_(first, last) do {\
- ::memset(&first, 0,\
- 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());
-
-#undef ZR_HELPER_
-#undef ZR_
-
options_.Clear();
+ 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());
+ ::memset(&kind_, 0, reinterpret_cast<char*>(&packed_) -
+ reinterpret_cast<char*>(&kind_) + sizeof(packed_));
}
bool Field::MergePartialFromCodedStream(
@@ -1149,13 +1243,14 @@ bool Field::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Field)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional .google.protobuf.Field.Kind kind = 1;
+ // .google.protobuf.Field.Kind kind = 1;
case 1: {
- if (tag == 8) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(8u)) {
int value;
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(
@@ -1164,14 +1259,13 @@ bool Field::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(16)) goto parse_cardinality;
break;
}
- // optional .google.protobuf.Field.Cardinality cardinality = 2;
+ // .google.protobuf.Field.Cardinality cardinality = 2;
case 2: {
- if (tag == 16) {
- parse_cardinality:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(16u)) {
int value;
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(
@@ -1180,29 +1274,27 @@ bool Field::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(24)) goto parse_number;
break;
}
- // optional int32 number = 3;
+ // int32 number = 3;
case 3: {
- if (tag == 24) {
- parse_number:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(24u)) {
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
input, &number_)));
-
} else {
goto handle_unusual;
}
- if (input->ExpectTag(34)) goto parse_name;
break;
}
- // optional string name = 4;
+ // string name = 4;
case 4: {
- if (tag == 34) {
- parse_name:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(34u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -1212,14 +1304,13 @@ bool Field::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(50)) goto parse_type_url;
break;
}
- // optional string type_url = 6;
+ // string type_url = 6;
case 6: {
- if (tag == 50) {
- parse_type_url:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(50u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_type_url()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -1229,61 +1320,55 @@ bool Field::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(56)) goto parse_oneof_index;
break;
}
- // optional int32 oneof_index = 7;
+ // int32 oneof_index = 7;
case 7: {
- if (tag == 56) {
- parse_oneof_index:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(56u)) {
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
input, &oneof_index_)));
-
} else {
goto handle_unusual;
}
- if (input->ExpectTag(64)) goto parse_packed;
break;
}
- // optional bool packed = 8;
+ // bool packed = 8;
case 8: {
- if (tag == 64) {
- parse_packed:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(64u)) {
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>(
input, &packed_)));
-
} else {
goto handle_unusual;
}
- if (input->ExpectTag(74)) goto parse_options;
break;
}
// repeated .google.protobuf.Option options = 9;
case 9: {
- if (tag == 74) {
- parse_options:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(74u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_options:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_options()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(74)) goto parse_loop_options;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectTag(82)) goto parse_json_name;
break;
}
- // optional string json_name = 10;
+ // string json_name = 10;
case 10: {
- if (tag == 82) {
- parse_json_name:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(82u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_json_name()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -1293,14 +1378,13 @@ bool Field::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(90)) goto parse_default_value;
break;
}
- // optional string default_value = 11;
+ // string default_value = 11;
case 11: {
- if (tag == 90) {
- parse_default_value:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(90u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_default_value()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -1310,7 +1394,6 @@ bool Field::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -1338,24 +1421,24 @@ failure:
void Field::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.Field)
- // optional .google.protobuf.Field.Kind kind = 1;
+ // .google.protobuf.Field.Kind kind = 1;
if (this->kind() != 0) {
::google::protobuf::internal::WireFormatLite::WriteEnum(
1, this->kind(), output);
}
- // optional .google.protobuf.Field.Cardinality cardinality = 2;
+ // .google.protobuf.Field.Cardinality cardinality = 2;
if (this->cardinality() != 0) {
::google::protobuf::internal::WireFormatLite::WriteEnum(
2, this->cardinality(), output);
}
- // optional int32 number = 3;
+ // int32 number = 3;
if (this->number() != 0) {
::google::protobuf::internal::WireFormatLite::WriteInt32(3, this->number(), output);
}
- // optional string name = 4;
+ // string name = 4;
if (this->name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->name().data(), this->name().length(),
@@ -1365,7 +1448,7 @@ void Field::SerializeWithCachedSizes(
4, this->name(), output);
}
- // optional string type_url = 6;
+ // string type_url = 6;
if (this->type_url().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->type_url().data(), this->type_url().length(),
@@ -1375,12 +1458,12 @@ void Field::SerializeWithCachedSizes(
6, this->type_url(), output);
}
- // optional int32 oneof_index = 7;
+ // int32 oneof_index = 7;
if (this->oneof_index() != 0) {
::google::protobuf::internal::WireFormatLite::WriteInt32(7, this->oneof_index(), output);
}
- // optional bool packed = 8;
+ // bool packed = 8;
if (this->packed() != 0) {
::google::protobuf::internal::WireFormatLite::WriteBool(8, this->packed(), output);
}
@@ -1391,7 +1474,7 @@ void Field::SerializeWithCachedSizes(
9, this->options(i), output);
}
- // optional string json_name = 10;
+ // string json_name = 10;
if (this->json_name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->json_name().data(), this->json_name().length(),
@@ -1401,7 +1484,7 @@ void Field::SerializeWithCachedSizes(
10, this->json_name(), output);
}
- // optional string default_value = 11;
+ // string default_value = 11;
if (this->default_value().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->default_value().data(), this->default_value().length(),
@@ -1416,25 +1499,26 @@ void Field::SerializeWithCachedSizes(
::google::protobuf::uint8* Field::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Field)
- // optional .google.protobuf.Field.Kind kind = 1;
+ // .google.protobuf.Field.Kind kind = 1;
if (this->kind() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray(
1, this->kind(), target);
}
- // optional .google.protobuf.Field.Cardinality cardinality = 2;
+ // .google.protobuf.Field.Cardinality cardinality = 2;
if (this->cardinality() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray(
2, this->cardinality(), target);
}
- // optional int32 number = 3;
+ // int32 number = 3;
if (this->number() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(3, this->number(), target);
}
- // optional string name = 4;
+ // string name = 4;
if (this->name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->name().data(), this->name().length(),
@@ -1445,7 +1529,7 @@ void Field::SerializeWithCachedSizes(
4, this->name(), target);
}
- // optional string type_url = 6;
+ // string type_url = 6;
if (this->type_url().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->type_url().data(), this->type_url().length(),
@@ -1456,12 +1540,12 @@ void Field::SerializeWithCachedSizes(
6, this->type_url(), target);
}
- // optional int32 oneof_index = 7;
+ // int32 oneof_index = 7;
if (this->oneof_index() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(7, this->oneof_index(), target);
}
- // optional bool packed = 8;
+ // bool packed = 8;
if (this->packed() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(8, this->packed(), target);
}
@@ -1473,7 +1557,7 @@ void Field::SerializeWithCachedSizes(
9, this->options(i), false, target);
}
- // optional string json_name = 10;
+ // string json_name = 10;
if (this->json_name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->json_name().data(), this->json_name().length(),
@@ -1484,7 +1568,7 @@ void Field::SerializeWithCachedSizes(
10, this->json_name(), target);
}
- // optional string default_value = 11;
+ // string default_value = 11;
if (this->default_value().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->default_value().data(), this->default_value().length(),
@@ -1499,89 +1583,91 @@ 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) {
- total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::EnumSize(this->kind());
+ // repeated .google.protobuf.Option options = 9;
+ {
+ 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));
+ }
}
- // optional .google.protobuf.Field.Cardinality cardinality = 2;
- if (this->cardinality() != 0) {
+ // string name = 4;
+ if (this->name().size() > 0) {
total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::EnumSize(this->cardinality());
+ ::google::protobuf::internal::WireFormatLite::StringSize(
+ this->name());
}
- // optional int32 number = 3;
- if (this->number() != 0) {
+ // string type_url = 6;
+ if (this->type_url().size() > 0) {
total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::Int32Size(
- this->number());
+ ::google::protobuf::internal::WireFormatLite::StringSize(
+ this->type_url());
}
- // optional string name = 4;
- if (this->name().size() > 0) {
+ // string json_name = 10;
+ if (this->json_name().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
- this->name());
+ this->json_name());
}
- // optional string type_url = 6;
- if (this->type_url().size() > 0) {
+ // string default_value = 11;
+ if (this->default_value().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
- this->type_url());
+ this->default_value());
}
- // optional int32 oneof_index = 7;
- if (this->oneof_index() != 0) {
+ // .google.protobuf.Field.Kind kind = 1;
+ if (this->kind() != 0) {
total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::Int32Size(
- this->oneof_index());
+ ::google::protobuf::internal::WireFormatLite::EnumSize(this->kind());
}
- // optional bool packed = 8;
- if (this->packed() != 0) {
- total_size += 1 + 1;
+ // .google.protobuf.Field.Cardinality cardinality = 2;
+ if (this->cardinality() != 0) {
+ total_size += 1 +
+ ::google::protobuf::internal::WireFormatLite::EnumSize(this->cardinality());
}
- // optional string json_name = 10;
- if (this->json_name().size() > 0) {
+ // int32 number = 3;
+ if (this->number() != 0) {
total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::StringSize(
- this->json_name());
+ ::google::protobuf::internal::WireFormatLite::Int32Size(
+ this->number());
}
- // optional string default_value = 11;
- if (this->default_value().size() > 0) {
+ // int32 oneof_index = 7;
+ if (this->oneof_index() != 0) {
total_size += 1 +
- ::google::protobuf::internal::WireFormatLite::StringSize(
- this->default_value());
+ ::google::protobuf::internal::WireFormatLite::Int32Size(
+ this->oneof_index());
}
- // 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));
+ // bool packed = 8;
+ if (this->packed() != 0) {
+ total_size += 1 + 1;
}
+ 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const Field* source =
::google::protobuf::internal::DynamicCastToGenerated<const Field>(
&from);
if (source == NULL) {
@@ -1595,10 +1681,21 @@ void Field::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
options_.MergeFrom(from.options_);
+ if (from.name().size() > 0) {
+ set_name(from.name());
+ }
+ if (from.type_url().size() > 0) {
+ set_type_url(from.type_url());
+ }
+ if (from.json_name().size() > 0) {
+ set_json_name(from.json_name());
+ }
+ if (from.default_value().size() > 0) {
+ set_default_value(from.default_value());
+ }
if (from.kind() != 0) {
set_kind(from.kind());
}
@@ -1608,28 +1705,12 @@ void Field::MergeFrom(const Field& from) {
if (from.number() != 0) {
set_number(from.number());
}
- if (from.name().size() > 0) {
-
- name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
- }
- if (from.type_url().size() > 0) {
-
- type_url_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.type_url_);
- }
if (from.oneof_index() != 0) {
set_oneof_index(from.oneof_index());
}
if (from.packed() != 0) {
set_packed(from.packed());
}
- if (from.json_name().size() > 0) {
-
- json_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.json_name_);
- }
- if (from.default_value().size() > 0) {
-
- default_value_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.default_value_);
- }
}
void Field::CopyFrom(const ::google::protobuf::Message& from) {
@@ -1647,193 +1728,247 @@ void Field::CopyFrom(const Field& from) {
}
bool Field::IsInitialized() const {
-
return true;
}
void Field::Swap(Field* other) {
if (other == this) return;
+ if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
+ InternalSwap(other);
+ } else {
+ Field* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
+ }
+}
+void Field::UnsafeArenaSwap(Field* other) {
+ if (other == this) return;
+ GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual());
InternalSwap(other);
}
void Field::InternalSwap(Field* other) {
+ options_.UnsafeArenaSwap(&other->options_);
+ name_.Swap(&other->name_);
+ type_url_.Swap(&other->type_url_);
+ json_name_.Swap(&other->json_name_);
+ default_value_.Swap(&other->default_value_);
std::swap(kind_, other->kind_);
std::swap(cardinality_, other->cardinality_);
std::swap(number_, other->number_);
- name_.Swap(&other->name_);
- type_url_.Swap(&other->type_url_);
std::swap(oneof_index_, other->oneof_index_);
std::swap(packed_, other->packed_);
- options_.UnsafeArenaSwap(&other->options_);
- json_name_.Swap(&other->json_name_);
- default_value_.Swap(&other->default_value_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Field::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = Field_descriptor_;
- metadata.reflection = Field_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[1];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// Field
-// optional .google.protobuf.Field.Kind kind = 1;
+// .google.protobuf.Field.Kind kind = 1;
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)
}
-// optional .google.protobuf.Field.Cardinality cardinality = 2;
+// .google.protobuf.Field.Cardinality cardinality = 2;
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)
}
-// optional int32 number = 3;
+// int32 number = 3;
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)
}
-// optional string name = 4;
+// 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();
}
- 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<const char*>(value), size));
+ name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(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;
+// 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();
}
- 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<const char*>(value), size));
+ type_url_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(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;
+// 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)
}
-// optional bool packed = 8;
+// bool packed = 8;
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)
@@ -1869,98 +2004,175 @@ Field::options() const {
return options_;
}
-// optional string json_name = 10;
+// 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();
}
- 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<const char*>(value), size));
+ json_name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(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());
}
- void Field::set_allocated_json_name(::std::string* json_name) {
+::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) {
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;
+// 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();
}
- 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<const char*>(value), size));
+ default_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(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());
}
- void Field::set_allocated_default_value(::std::string* default_value) {
+::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) {
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;
@@ -1971,30 +2183,50 @@ const int Enum::kSyntaxFieldNumber;
Enum::Enum()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.Enum)
}
-
-void Enum::InitAsDefaultInstance() {
- _is_default_instance_ = true;
- source_context_ = const_cast< ::google::protobuf::SourceContext*>(&::google::protobuf::SourceContext::default_instance());
+Enum::Enum(::google::protobuf::Arena* arena)
+ : ::google::protobuf::Message(),
+ _internal_metadata_(arena),
+ enumvalue_(arena),
+ options_(arena) {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ SharedCtor();
+ RegisterArenaDtor(arena);
+ // @@protoc_insertion_point(arena_constructor:google.protobuf.Enum)
}
-
Enum::Enum(const Enum& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ enumvalue_(from.enumvalue_),
+ options_(from.options_),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.name().size() > 0) {
+ name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name(),
+ GetArenaNoVirtual());
+ }
+ if (from.has_source_context()) {
+ source_context_ = new ::google::protobuf::SourceContext(*from.source_context_);
+ } else {
+ source_context_ = NULL;
+ }
+ syntax_ = from.syntax_;
// @@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;
+ ::memset(&source_context_, 0, reinterpret_cast<char*>(&syntax_) -
+ reinterpret_cast<char*>(&source_context_) + sizeof(syntax_));
+ _cached_size_ = 0;
}
Enum::~Enum() {
@@ -2003,45 +2235,52 @@ Enum::~Enum() {
}
void Enum::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);
+ if (this != internal_default_instance()) {
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;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Enum::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Enum_descriptor_;
+ protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[2].descriptor;
}
const Enum& Enum::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-Enum* Enum::default_instance_ = NULL;
-
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<Enum>(arena);
}
void Enum::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.Enum)
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- if (GetArenaNoVirtual() == NULL && source_context_ != NULL) delete source_context_;
- source_context_ = NULL;
- syntax_ = 0;
enumvalue_.Clear();
options_.Clear();
+ name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
+ if (GetArenaNoVirtual() == NULL && source_context_ != NULL) {
+ delete source_context_;
+ }
+ source_context_ = NULL;
+ syntax_ = 0;
}
bool Enum::MergePartialFromCodedStream(
@@ -2050,13 +2289,14 @@ bool Enum::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Enum)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional string name = 1;
+ // string name = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -2066,60 +2306,53 @@ bool Enum::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_enumvalue;
break;
}
// repeated .google.protobuf.EnumValue enumvalue = 2;
case 2: {
- if (tag == 18) {
- parse_enumvalue:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_enumvalue:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_enumvalue()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_loop_enumvalue;
- if (input->ExpectTag(26)) goto parse_loop_options;
input->UnsafeDecrementRecursionDepth();
break;
}
// repeated .google.protobuf.Option options = 3;
case 3: {
- if (tag == 26) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(26u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_options:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_options()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(26)) goto parse_loop_options;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectTag(34)) goto parse_source_context;
break;
}
- // optional .google.protobuf.SourceContext source_context = 4;
+ // .google.protobuf.SourceContext source_context = 4;
case 4: {
- if (tag == 34) {
- parse_source_context:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(34u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, mutable_source_context()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(40)) goto parse_syntax;
break;
}
- // optional .google.protobuf.Syntax syntax = 5;
+ // .google.protobuf.Syntax syntax = 5;
case 5: {
- if (tag == 40) {
- parse_syntax:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(40u)) {
int value;
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>(
@@ -2128,7 +2361,6 @@ bool Enum::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -2156,7 +2388,7 @@ failure:
void Enum::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.Enum)
- // optional string name = 1;
+ // string name = 1;
if (this->name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->name().data(), this->name().length(),
@@ -2178,13 +2410,13 @@ void Enum::SerializeWithCachedSizes(
3, this->options(i), output);
}
- // optional .google.protobuf.SourceContext source_context = 4;
+ // .google.protobuf.SourceContext source_context = 4;
if (this->has_source_context()) {
::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
4, *this->source_context_, output);
}
- // optional .google.protobuf.Syntax syntax = 5;
+ // .google.protobuf.Syntax syntax = 5;
if (this->syntax() != 0) {
::google::protobuf::internal::WireFormatLite::WriteEnum(
5, this->syntax(), output);
@@ -2195,8 +2427,9 @@ void Enum::SerializeWithCachedSizes(
::google::protobuf::uint8* Enum::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Enum)
- // optional string name = 1;
+ // string name = 1;
if (this->name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->name().data(), this->name().length(),
@@ -2221,14 +2454,14 @@ void Enum::SerializeWithCachedSizes(
3, this->options(i), false, target);
}
- // optional .google.protobuf.SourceContext source_context = 4;
+ // .google.protobuf.SourceContext source_context = 4;
if (this->has_source_context()) {
target = ::google::protobuf::internal::WireFormatLite::
InternalWriteMessageNoVirtualToArray(
4, *this->source_context_, false, target);
}
- // optional .google.protobuf.Syntax syntax = 5;
+ // .google.protobuf.Syntax syntax = 5;
if (this->syntax() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteEnumToArray(
5, this->syntax(), target);
@@ -2238,58 +2471,63 @@ 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;
+ // repeated .google.protobuf.EnumValue enumvalue = 2;
+ {
+ 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;
+ {
+ 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));
+ }
+ }
+
+ // string name = 1;
if (this->name().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->name());
}
- // optional .google.protobuf.SourceContext source_context = 4;
+ // .google.protobuf.SourceContext source_context = 4;
if (this->has_source_context()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual(
*this->source_context_);
}
- // optional .google.protobuf.Syntax syntax = 5;
+ // .google.protobuf.Syntax syntax = 5;
if (this->syntax() != 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::EnumSize(this->syntax());
}
- // 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));
- }
-
- // 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));
- }
-
+ 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const Enum* source =
::google::protobuf::internal::DynamicCastToGenerated<const Enum>(
&from);
if (source == NULL) {
@@ -2303,14 +2541,12 @@ void Enum::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
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());
@@ -2335,78 +2571,110 @@ void Enum::CopyFrom(const Enum& from) {
}
bool Enum::IsInitialized() const {
-
return true;
}
void Enum::Swap(Enum* other) {
if (other == this) return;
+ if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
+ InternalSwap(other);
+ } else {
+ Enum* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
+ }
+}
+void Enum::UnsafeArenaSwap(Enum* other) {
+ if (other == this) return;
+ GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual());
InternalSwap(other);
}
void Enum::InternalSwap(Enum* other) {
- name_.Swap(&other->name_);
enumvalue_.UnsafeArenaSwap(&other->enumvalue_);
options_.UnsafeArenaSwap(&other->options_);
+ name_.Swap(&other->name_);
std::swap(source_context_, other->source_context_);
std::swap(syntax_, other->syntax_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Enum::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = Enum_descriptor_;
- metadata.reflection = Enum_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[2];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// Enum
-// optional string name = 1;
+// 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();
}
- 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<const char*>(value), size));
+ name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(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 {
@@ -2468,9 +2736,9 @@ Enum::options() const {
return options_;
}
-// optional .google.protobuf.SourceContext source_context = 4;
+// .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_;
@@ -2478,12 +2746,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_;
@@ -2491,12 +2760,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) {
@@ -2506,15 +2787,15 @@ void Enum::set_allocated_source_context(::google::protobuf::SourceContext* sourc
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Enum.source_context)
}
-// optional .google.protobuf.Syntax syntax = 5;
+// .google.protobuf.Syntax syntax = 5;
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)
@@ -2532,28 +2813,42 @@ const int EnumValue::kOptionsFieldNumber;
EnumValue::EnumValue()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.EnumValue)
}
-
-void EnumValue::InitAsDefaultInstance() {
- _is_default_instance_ = true;
+EnumValue::EnumValue(::google::protobuf::Arena* arena)
+ : ::google::protobuf::Message(),
+ _internal_metadata_(arena),
+ options_(arena) {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ SharedCtor();
+ RegisterArenaDtor(arena);
+ // @@protoc_insertion_point(arena_constructor:google.protobuf.EnumValue)
}
-
EnumValue::EnumValue(const EnumValue& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ options_(from.options_),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.name().size() > 0) {
+ name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name(),
+ GetArenaNoVirtual());
+ }
+ number_ = from.number_;
// @@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() {
@@ -2562,41 +2857,44 @@ 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;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* EnumValue::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return EnumValue_descriptor_;
+ protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[3].descriptor;
}
const EnumValue& EnumValue::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-EnumValue* EnumValue::default_instance_ = NULL;
-
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<EnumValue>(arena);
}
void EnumValue::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.EnumValue)
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- number_ = 0;
options_.Clear();
+ name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
+ number_ = 0;
}
bool EnumValue::MergePartialFromCodedStream(
@@ -2605,13 +2903,14 @@ bool EnumValue::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.EnumValue)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional string name = 1;
+ // string name = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -2621,39 +2920,34 @@ bool EnumValue::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(16)) goto parse_number;
break;
}
- // optional int32 number = 2;
+ // int32 number = 2;
case 2: {
- if (tag == 16) {
- parse_number:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(16u)) {
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
input, &number_)));
-
} else {
goto handle_unusual;
}
- if (input->ExpectTag(26)) goto parse_options;
break;
}
// repeated .google.protobuf.Option options = 3;
case 3: {
- if (tag == 26) {
- parse_options:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(26u)) {
DO_(input->IncrementRecursionDepth());
- parse_loop_options:
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtualNoRecursionDepth(
input, add_options()));
} else {
goto handle_unusual;
}
- if (input->ExpectTag(26)) goto parse_loop_options;
input->UnsafeDecrementRecursionDepth();
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -2681,7 +2975,7 @@ failure:
void EnumValue::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.EnumValue)
- // optional string name = 1;
+ // string name = 1;
if (this->name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->name().data(), this->name().length(),
@@ -2691,7 +2985,7 @@ void EnumValue::SerializeWithCachedSizes(
1, this->name(), output);
}
- // optional int32 number = 2;
+ // int32 number = 2;
if (this->number() != 0) {
::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->number(), output);
}
@@ -2707,8 +3001,9 @@ void EnumValue::SerializeWithCachedSizes(
::google::protobuf::uint8* EnumValue::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.EnumValue)
- // optional string name = 1;
+ // string name = 1;
if (this->name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->name().data(), this->name().length(),
@@ -2719,7 +3014,7 @@ void EnumValue::SerializeWithCachedSizes(
1, this->name(), target);
}
- // optional int32 number = 2;
+ // int32 number = 2;
if (this->number() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->number(), target);
}
@@ -2735,44 +3030,46 @@ 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;
+ // repeated .google.protobuf.Option options = 3;
+ {
+ 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));
+ }
+ }
+
+ // string name = 1;
if (this->name().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->name());
}
- // optional int32 number = 2;
+ // int32 number = 2;
if (this->number() != 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::Int32Size(
this->number());
}
- // 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));
- }
-
+ 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 =
+ GOOGLE_DCHECK_NE(&from, this);
+ const EnumValue* source =
::google::protobuf::internal::DynamicCastToGenerated<const EnumValue>(
&from);
if (source == NULL) {
@@ -2786,13 +3083,11 @@ void EnumValue::MergeFrom(const ::google::protobuf::Message& from) {
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__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
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,86 +3109,118 @@ void EnumValue::CopyFrom(const EnumValue& from) {
}
bool EnumValue::IsInitialized() const {
-
return true;
}
void EnumValue::Swap(EnumValue* other) {
if (other == this) return;
+ if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
+ InternalSwap(other);
+ } else {
+ EnumValue* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
+ }
+}
+void EnumValue::UnsafeArenaSwap(EnumValue* other) {
+ if (other == this) return;
+ GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual());
InternalSwap(other);
}
void EnumValue::InternalSwap(EnumValue* other) {
+ options_.UnsafeArenaSwap(&other->options_);
name_.Swap(&other->name_);
std::swap(number_, other->number_);
- options_.UnsafeArenaSwap(&other->options_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata EnumValue::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = EnumValue_descriptor_;
- metadata.reflection = EnumValue_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[3];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// EnumValue
-// optional string name = 1;
+// 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();
}
- 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<const char*>(value), size));
+ name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(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());
+}
+::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) {
+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;
+// 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)
@@ -2933,6 +3260,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;
@@ -2940,29 +3300,44 @@ const int Option::kValueFieldNumber;
Option::Option()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.Option)
}
-
-void Option::InitAsDefaultInstance() {
- _is_default_instance_ = true;
- value_ = const_cast< ::google::protobuf::Any*>(&::google::protobuf::Any::default_instance());
+Option::Option(::google::protobuf::Arena* arena)
+ : ::google::protobuf::Message(),
+ _internal_metadata_(arena) {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ SharedCtor();
+ RegisterArenaDtor(arena);
+ // @@protoc_insertion_point(arena_constructor:google.protobuf.Option)
}
-
Option::Option(const Option& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.name().size() > 0) {
+ name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name(),
+ GetArenaNoVirtual());
+ }
+ if (from.has_value()) {
+ value_ = new ::google::protobuf::Any(*from.value_);
+ } else {
+ value_ = NULL;
+ }
// @@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() {
@@ -2971,41 +3346,48 @@ Option::~Option() {
}
void Option::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);
+ if (this != internal_default_instance()) {
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;
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Option::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Option_descriptor_;
+ protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[4].descriptor;
}
const Option& Option::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-Option* Option::default_instance_ = NULL;
-
Option* Option::New(::google::protobuf::Arena* arena) const {
- Option* n = new Option;
- if (arena != NULL) {
- arena->Own(n);
- }
- return n;
+ return ::google::protobuf::Arena::CreateMessage<Option>(arena);
}
void Option::Clear() {
// @@protoc_insertion_point(message_clear_start:google.protobuf.Option)
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
- if (GetArenaNoVirtual() == NULL && value_ != NULL) delete value_;
+ name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
+ if (GetArenaNoVirtual() == NULL && value_ != NULL) {
+ delete value_;
+ }
value_ = NULL;
}
@@ -3015,13 +3397,14 @@ bool Option::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Option)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional string name = 1;
+ // string name = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_name()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -3031,20 +3414,18 @@ bool Option::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectTag(18)) goto parse_value;
break;
}
- // optional .google.protobuf.Any value = 2;
+ // .google.protobuf.Any value = 2;
case 2: {
- if (tag == 18) {
- parse_value:
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(18u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(
input, mutable_value()));
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -3072,7 +3453,7 @@ failure:
void Option::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.Option)
- // optional string name = 1;
+ // string name = 1;
if (this->name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->name().data(), this->name().length(),
@@ -3082,7 +3463,7 @@ void Option::SerializeWithCachedSizes(
1, this->name(), output);
}
- // optional .google.protobuf.Any value = 2;
+ // .google.protobuf.Any value = 2;
if (this->has_value()) {
::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
2, *this->value_, output);
@@ -3093,8 +3474,9 @@ void Option::SerializeWithCachedSizes(
::google::protobuf::uint8* Option::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Option)
- // optional string name = 1;
+ // string name = 1;
if (this->name().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->name().data(), this->name().length(),
@@ -3105,7 +3487,7 @@ void Option::SerializeWithCachedSizes(
1, this->name(), target);
}
- // optional .google.protobuf.Any value = 2;
+ // .google.protobuf.Any value = 2;
if (this->has_value()) {
target = ::google::protobuf::internal::WireFormatLite::
InternalWriteMessageNoVirtualToArray(
@@ -3116,36 +3498,35 @@ void Option::SerializeWithCachedSizes(
return target;
}
-int Option::ByteSize() const {
+size_t Option::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Option)
- int total_size = 0;
+ size_t total_size = 0;
- // optional string name = 1;
+ // string name = 1;
if (this->name().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
this->name());
}
- // optional .google.protobuf.Any value = 2;
+ // .google.protobuf.Any value = 2;
if (this->has_value()) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual(
*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 Option::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Option)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
- const Option* source =
+ GOOGLE_DCHECK_NE(&from, this);
+ const Option* source =
::google::protobuf::internal::DynamicCastToGenerated<const Option>(
&from);
if (source == NULL) {
@@ -3159,12 +3540,10 @@ void Option::MergeFrom(const ::google::protobuf::Message& from) {
void Option::MergeFrom(const Option& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Option)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
if (from.name().size() > 0) {
-
- name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
+ set_name(from.name());
}
if (from.has_value()) {
mutable_value()->::google::protobuf::Any::MergeFrom(from.value());
@@ -3186,79 +3565,111 @@ void Option::CopyFrom(const Option& from) {
}
bool Option::IsInitialized() const {
-
return true;
}
void Option::Swap(Option* other) {
if (other == this) return;
+ if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
+ InternalSwap(other);
+ } else {
+ Option* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
+ }
+}
+void Option::UnsafeArenaSwap(Option* other) {
+ if (other == this) return;
+ GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual());
InternalSwap(other);
}
void Option::InternalSwap(Option* other) {
name_.Swap(&other->name_);
std::swap(value_, other->value_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Option::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = Option_descriptor_;
- metadata.reflection = Option_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2ftype_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2ftype_2eproto::file_level_metadata[4];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// Option
-// optional string name = 1;
+// string name = 1;
void Option::clear_name() {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
- const ::std::string& Option::name() const {
+const ::std::string& Option::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.Option.name)
- return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return name_.Get();
}
- void Option::set_name(const ::std::string& value) {
+void Option::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.Option.name)
}
- void Option::set_name(const char* value) {
+void Option::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.Option.name)
}
- void Option::set_name(const char* value, size_t size) {
+void Option::set_name(const char* value,
+ size_t size) {
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
+ name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(value), size), GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Option.name)
}
- ::std::string* Option::mutable_name() {
+::std::string* Option::mutable_name() {
// @@protoc_insertion_point(field_mutable:google.protobuf.Option.name)
- return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return name_.Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
- ::std::string* Option::release_name() {
+::std::string* Option::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Option.name)
- return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
+}
+::std::string* Option::unsafe_arena_release_name() {
+ // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Option.name)
+ GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);
+
+ return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+ GetArenaNoVirtual());
}
- void Option::set_allocated_name(::std::string* name) {
+void Option::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.Option.name)
}
+void Option::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.Option.name)
+}
-// optional .google.protobuf.Any value = 2;
+// .google.protobuf.Any value = 2;
bool Option::has_value() const {
- return !_is_default_instance_ && value_ != NULL;
+ return this != internal_default_instance() && value_ != NULL;
}
void Option::clear_value() {
if (GetArenaNoVirtual() == NULL && value_ != NULL) delete value_;
@@ -3266,12 +3677,13 @@ void Option::clear_value() {
}
const ::google::protobuf::Any& Option::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.Option.value)
- return value_ != NULL ? *value_ : *default_instance_->value_;
+ return value_ != NULL ? *value_
+ : *::google::protobuf::Any::internal_default_instance();
}
::google::protobuf::Any* Option::mutable_value() {
if (value_ == NULL) {
- value_ = new ::google::protobuf::Any;
+ _slow_mutable_value();
}
// @@protoc_insertion_point(field_mutable:google.protobuf.Option.value)
return value_;
@@ -3279,12 +3691,24 @@ const ::google::protobuf::Any& Option::value() const {
::google::protobuf::Any* Option::release_value() {
// @@protoc_insertion_point(field_release:google.protobuf.Option.value)
- ::google::protobuf::Any* temp = value_;
- value_ = NULL;
- return temp;
+ if (GetArenaNoVirtual() != NULL) {
+ return _slow_release_value();
+ } else {
+ ::google::protobuf::Any* temp = value_;
+ value_ = NULL;
+ return temp;
+ }
}
-void Option::set_allocated_value(::google::protobuf::Any* value) {
- delete value_;
+ void Option::set_allocated_value(::google::protobuf::Any* value) {
+ ::google::protobuf::Arena* message_arena = GetArenaNoVirtual();
+ if (message_arena == NULL) {
+ delete value_;
+ }
+ if (value != NULL) {
+ if (message_arena != NULL) {
+ message_arena->Own(value);
+ }
+ }
value_ = value;
if (value) {
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/type.pb.h b/third_party/protobuf/src/google/protobuf/type.pb.h
index ce29c2817f..ae81600885 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/type.pb.h
+++ b/third_party/protobuf/src/google/protobuf/type.pb.h
@@ -8,43 +8,69 @@
#include <google/protobuf/stubs/common.h>
-#if GOOGLE_PROTOBUF_VERSION < 3000000
+#if GOOGLE_PROTOBUF_VERSION < 3002000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
-#if 3000000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
+#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
+#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/metadata.h>
#include <google/protobuf/message.h>
-#include <google/protobuf/repeated_field.h>
-#include <google/protobuf/extension_set.h>
+#include <google/protobuf/repeated_field.h> // IWYU pragma: export
+#include <google/protobuf/extension_set.h> // IWYU pragma: export
#include <google/protobuf/generated_enum_reflection.h>
#include <google/protobuf/unknown_field_set.h>
#include <google/protobuf/any.pb.h>
#include <google/protobuf/source_context.pb.h>
// @@protoc_insertion_point(includes)
-
namespace google {
namespace protobuf {
-
-// Internal implementation detail -- do not call these.
-void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto();
-void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto();
-void protobuf_ShutdownFile_google_2fprotobuf_2ftype_2eproto();
-
+class Any;
+class AnyDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern AnyDefaultTypeInternal _Any_default_instance_;
class Enum;
+class EnumDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern EnumDefaultTypeInternal _Enum_default_instance_;
class EnumValue;
+class EnumValueDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern EnumValueDefaultTypeInternal _EnumValue_default_instance_;
class Field;
+class FieldDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern FieldDefaultTypeInternal _Field_default_instance_;
class Option;
+class OptionDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern OptionDefaultTypeInternal _Option_default_instance_;
+class SourceContext;
+class SourceContextDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern SourceContextDefaultTypeInternal _SourceContext_default_instance_;
class Type;
+class TypeDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern TypeDefaultTypeInternal _Type_default_instance_;
+} // namespace protobuf
+} // namespace google
+
+namespace google {
+namespace protobuf {
+
+namespace protobuf_google_2fprotobuf_2ftype_2eproto {
+// Internal implementation detail -- do not call these.
+struct LIBPROTOBUF_EXPORT TableStruct {
+ static const ::google::protobuf::uint32 offsets[];
+ static void InitDefaultsImpl();
+ static void Shutdown();
+};
+void LIBPROTOBUF_EXPORT AddDescriptors();
+void LIBPROTOBUF_EXPORT InitDefaults();
+} // namespace protobuf_google_2fprotobuf_2ftype_2eproto
enum Field_Kind {
Field_Kind_TYPE_UNKNOWN = 0,
@@ -142,39 +168,58 @@ class LIBPROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_i
return *this;
}
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
+ return MaybeArenaPtr();
+ }
static const ::google::protobuf::Descriptor* descriptor();
static const Type& default_instance();
+ static inline const Type* internal_default_instance() {
+ return reinterpret_cast<const Type*>(
+ &_Type_default_instance_);
+ }
+
+ void UnsafeArenaSwap(Type* other);
void Swap(Type* other);
// implements Message ----------------------------------------------
- inline Type* New() const { return New(NULL); }
+ inline Type* New() const PROTOBUF_FINAL { return New(NULL); }
- Type* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ Type* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Type& from);
void MergeFrom(const Type& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Type* other);
+ protected:
+ explicit Type(::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();
@@ -184,23 +229,12 @@ class LIBPROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_i
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional string name = 1;
- void clear_name();
- static const int kNameFieldNumber = 1;
- const ::std::string& name() const;
- void set_name(const ::std::string& value);
- void set_name(const char* value);
- void set_name(const char* value, size_t size);
- ::std::string* mutable_name();
- ::std::string* release_name();
- void set_allocated_name(::std::string* name);
-
// repeated .google.protobuf.Field fields = 2;
int fields_size() const;
void clear_fields();
@@ -220,10 +254,16 @@ class LIBPROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_i
const ::std::string& oneofs(int index) const;
::std::string* mutable_oneofs(int index);
void set_oneofs(int index, const ::std::string& value);
+ #if LANG_CXX11
+ void set_oneofs(int index, ::std::string&& value);
+ #endif
void set_oneofs(int index, const char* value);
void set_oneofs(int index, const char* value, size_t size);
::std::string* add_oneofs();
void add_oneofs(const ::std::string& value);
+ #if LANG_CXX11
+ void add_oneofs(::std::string&& value);
+ #endif
void add_oneofs(const char* value);
void add_oneofs(const char* value, size_t size);
const ::google::protobuf::RepeatedPtrField< ::std::string>& oneofs() const;
@@ -241,16 +281,37 @@ class LIBPROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_i
const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >&
options() const;
- // optional .google.protobuf.SourceContext source_context = 5;
+ // string name = 1;
+ void clear_name();
+ static const int kNameFieldNumber = 1;
+ const ::std::string& name() const;
+ void set_name(const ::std::string& value);
+ void set_name(const char* value);
+ void set_name(const char* value, size_t size);
+ ::std::string* mutable_name();
+ ::std::string* release_name();
+ void set_allocated_name(::std::string* name);
+ ::std::string* unsafe_arena_release_name();
+ void unsafe_arena_set_allocated_name(
+ ::std::string* name);
+
+ // .google.protobuf.SourceContext source_context = 5;
bool has_source_context() const;
void clear_source_context();
static const int kSourceContextFieldNumber = 5;
+ private:
+ void _slow_mutable_source_context();
+ ::google::protobuf::SourceContext* _slow_release_source_context();
+ public:
const ::google::protobuf::SourceContext& source_context() const;
::google::protobuf::SourceContext* mutable_source_context();
::google::protobuf::SourceContext* release_source_context();
void set_allocated_source_context(::google::protobuf::SourceContext* source_context);
+ ::google::protobuf::SourceContext* unsafe_arena_release_source_context();
+ void unsafe_arena_set_allocated_source_context(
+ ::google::protobuf::SourceContext* source_context);
- // optional .google.protobuf.Syntax syntax = 6;
+ // .google.protobuf.Syntax syntax = 6;
void clear_syntax();
static const int kSyntaxFieldNumber = 6;
::google::protobuf::Syntax syntax() const;
@@ -260,20 +321,17 @@ class LIBPROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_i
private:
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
- bool _is_default_instance_;
- ::google::protobuf::internal::ArenaStringPtr name_;
+ friend class ::google::protobuf::Arena;
+ typedef void InternalArenaConstructable_;
+ typedef void DestructorSkippable_;
::google::protobuf::RepeatedPtrField< ::google::protobuf::Field > fields_;
::google::protobuf::RepeatedPtrField< ::std::string> oneofs_;
::google::protobuf::RepeatedPtrField< ::google::protobuf::Option > options_;
+ ::google::protobuf::internal::ArenaStringPtr name_;
::google::protobuf::SourceContext* source_context_;
int syntax_;
mutable int _cached_size_;
- friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto();
- friend void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2ftype_2eproto();
-
- void InitAsDefaultInstance();
- static Type* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2ftype_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -289,39 +347,58 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_
return *this;
}
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
+ return MaybeArenaPtr();
+ }
static const ::google::protobuf::Descriptor* descriptor();
static const Field& default_instance();
+ static inline const Field* internal_default_instance() {
+ return reinterpret_cast<const Field*>(
+ &_Field_default_instance_);
+ }
+
+ void UnsafeArenaSwap(Field* other);
void Swap(Field* other);
// implements Message ----------------------------------------------
- inline Field* New() const { return New(NULL); }
+ inline Field* New() const PROTOBUF_FINAL { return New(NULL); }
- Field* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ Field* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Field& from);
void MergeFrom(const Field& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Field* other);
+ protected:
+ explicit Field(::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();
@@ -331,7 +408,7 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
@@ -427,25 +504,19 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_
// accessors -------------------------------------------------------
- // optional .google.protobuf.Field.Kind kind = 1;
- void clear_kind();
- static const int kKindFieldNumber = 1;
- ::google::protobuf::Field_Kind kind() const;
- void set_kind(::google::protobuf::Field_Kind value);
-
- // optional .google.protobuf.Field.Cardinality cardinality = 2;
- void clear_cardinality();
- static const int kCardinalityFieldNumber = 2;
- ::google::protobuf::Field_Cardinality cardinality() const;
- void set_cardinality(::google::protobuf::Field_Cardinality value);
-
- // optional int32 number = 3;
- void clear_number();
- static const int kNumberFieldNumber = 3;
- ::google::protobuf::int32 number() const;
- void set_number(::google::protobuf::int32 value);
+ // repeated .google.protobuf.Option options = 9;
+ int options_size() const;
+ void clear_options();
+ static const int kOptionsFieldNumber = 9;
+ const ::google::protobuf::Option& options(int index) const;
+ ::google::protobuf::Option* mutable_options(int index);
+ ::google::protobuf::Option* add_options();
+ ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >*
+ mutable_options();
+ const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >&
+ options() const;
- // optional string name = 4;
+ // string name = 4;
void clear_name();
static const int kNameFieldNumber = 4;
const ::std::string& name() const;
@@ -455,8 +526,11 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_
::std::string* mutable_name();
::std::string* release_name();
void set_allocated_name(::std::string* name);
+ ::std::string* unsafe_arena_release_name();
+ void unsafe_arena_set_allocated_name(
+ ::std::string* name);
- // optional string type_url = 6;
+ // string type_url = 6;
void clear_type_url();
static const int kTypeUrlFieldNumber = 6;
const ::std::string& type_url() const;
@@ -466,32 +540,11 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_
::std::string* mutable_type_url();
::std::string* release_type_url();
void set_allocated_type_url(::std::string* type_url);
+ ::std::string* unsafe_arena_release_type_url();
+ void unsafe_arena_set_allocated_type_url(
+ ::std::string* type_url);
- // optional int32 oneof_index = 7;
- void clear_oneof_index();
- static const int kOneofIndexFieldNumber = 7;
- ::google::protobuf::int32 oneof_index() const;
- void set_oneof_index(::google::protobuf::int32 value);
-
- // optional bool packed = 8;
- void clear_packed();
- static const int kPackedFieldNumber = 8;
- bool packed() const;
- void set_packed(bool value);
-
- // repeated .google.protobuf.Option options = 9;
- int options_size() const;
- void clear_options();
- static const int kOptionsFieldNumber = 9;
- const ::google::protobuf::Option& options(int index) const;
- ::google::protobuf::Option* mutable_options(int index);
- ::google::protobuf::Option* add_options();
- ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >*
- mutable_options();
- const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >&
- options() const;
-
- // optional string json_name = 10;
+ // string json_name = 10;
void clear_json_name();
static const int kJsonNameFieldNumber = 10;
const ::std::string& json_name() const;
@@ -501,8 +554,11 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_
::std::string* mutable_json_name();
::std::string* release_json_name();
void set_allocated_json_name(::std::string* json_name);
+ ::std::string* unsafe_arena_release_json_name();
+ void unsafe_arena_set_allocated_json_name(
+ ::std::string* json_name);
- // optional string default_value = 11;
+ // string default_value = 11;
void clear_default_value();
static const int kDefaultValueFieldNumber = 11;
const ::std::string& default_value() const;
@@ -512,29 +568,59 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_
::std::string* mutable_default_value();
::std::string* release_default_value();
void set_allocated_default_value(::std::string* default_value);
+ ::std::string* unsafe_arena_release_default_value();
+ void unsafe_arena_set_allocated_default_value(
+ ::std::string* default_value);
+
+ // .google.protobuf.Field.Kind kind = 1;
+ void clear_kind();
+ static const int kKindFieldNumber = 1;
+ ::google::protobuf::Field_Kind kind() const;
+ void set_kind(::google::protobuf::Field_Kind value);
+
+ // .google.protobuf.Field.Cardinality cardinality = 2;
+ void clear_cardinality();
+ static const int kCardinalityFieldNumber = 2;
+ ::google::protobuf::Field_Cardinality cardinality() const;
+ void set_cardinality(::google::protobuf::Field_Cardinality value);
+
+ // int32 number = 3;
+ void clear_number();
+ static const int kNumberFieldNumber = 3;
+ ::google::protobuf::int32 number() const;
+ void set_number(::google::protobuf::int32 value);
+
+ // int32 oneof_index = 7;
+ void clear_oneof_index();
+ static const int kOneofIndexFieldNumber = 7;
+ ::google::protobuf::int32 oneof_index() const;
+ void set_oneof_index(::google::protobuf::int32 value);
+
+ // bool packed = 8;
+ void clear_packed();
+ static const int kPackedFieldNumber = 8;
+ bool packed() const;
+ void set_packed(bool value);
// @@protoc_insertion_point(class_scope:google.protobuf.Field)
private:
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
- bool _is_default_instance_;
- int kind_;
- int cardinality_;
+ friend class ::google::protobuf::Arena;
+ typedef void InternalArenaConstructable_;
+ typedef void DestructorSkippable_;
+ ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option > options_;
::google::protobuf::internal::ArenaStringPtr name_;
- ::google::protobuf::int32 number_;
- ::google::protobuf::int32 oneof_index_;
::google::protobuf::internal::ArenaStringPtr type_url_;
- ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option > options_;
::google::protobuf::internal::ArenaStringPtr json_name_;
::google::protobuf::internal::ArenaStringPtr default_value_;
+ int kind_;
+ int cardinality_;
+ ::google::protobuf::int32 number_;
+ ::google::protobuf::int32 oneof_index_;
bool packed_;
mutable int _cached_size_;
- friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto();
- friend void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2ftype_2eproto();
-
- void InitAsDefaultInstance();
- static Field* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2ftype_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -550,39 +636,58 @@ class LIBPROTOBUF_EXPORT Enum : public ::google::protobuf::Message /* @@protoc_i
return *this;
}
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
+ return MaybeArenaPtr();
+ }
static const ::google::protobuf::Descriptor* descriptor();
static const Enum& default_instance();
+ static inline const Enum* internal_default_instance() {
+ return reinterpret_cast<const Enum*>(
+ &_Enum_default_instance_);
+ }
+
+ void UnsafeArenaSwap(Enum* other);
void Swap(Enum* other);
// implements Message ----------------------------------------------
- inline Enum* New() const { return New(NULL); }
+ inline Enum* New() const PROTOBUF_FINAL { return New(NULL); }
- Enum* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ Enum* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Enum& from);
void MergeFrom(const Enum& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Enum* other);
+ protected:
+ explicit Enum(::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();
@@ -592,23 +697,12 @@ class LIBPROTOBUF_EXPORT Enum : public ::google::protobuf::Message /* @@protoc_i
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional string name = 1;
- void clear_name();
- static const int kNameFieldNumber = 1;
- const ::std::string& name() const;
- void set_name(const ::std::string& value);
- void set_name(const char* value);
- void set_name(const char* value, size_t size);
- ::std::string* mutable_name();
- ::std::string* release_name();
- void set_allocated_name(::std::string* name);
-
// repeated .google.protobuf.EnumValue enumvalue = 2;
int enumvalue_size() const;
void clear_enumvalue();
@@ -633,16 +727,37 @@ class LIBPROTOBUF_EXPORT Enum : public ::google::protobuf::Message /* @@protoc_i
const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >&
options() const;
- // optional .google.protobuf.SourceContext source_context = 4;
+ // string name = 1;
+ void clear_name();
+ static const int kNameFieldNumber = 1;
+ const ::std::string& name() const;
+ void set_name(const ::std::string& value);
+ void set_name(const char* value);
+ void set_name(const char* value, size_t size);
+ ::std::string* mutable_name();
+ ::std::string* release_name();
+ void set_allocated_name(::std::string* name);
+ ::std::string* unsafe_arena_release_name();
+ void unsafe_arena_set_allocated_name(
+ ::std::string* name);
+
+ // .google.protobuf.SourceContext source_context = 4;
bool has_source_context() const;
void clear_source_context();
static const int kSourceContextFieldNumber = 4;
+ private:
+ void _slow_mutable_source_context();
+ ::google::protobuf::SourceContext* _slow_release_source_context();
+ public:
const ::google::protobuf::SourceContext& source_context() const;
::google::protobuf::SourceContext* mutable_source_context();
::google::protobuf::SourceContext* release_source_context();
void set_allocated_source_context(::google::protobuf::SourceContext* source_context);
+ ::google::protobuf::SourceContext* unsafe_arena_release_source_context();
+ void unsafe_arena_set_allocated_source_context(
+ ::google::protobuf::SourceContext* source_context);
- // optional .google.protobuf.Syntax syntax = 5;
+ // .google.protobuf.Syntax syntax = 5;
void clear_syntax();
static const int kSyntaxFieldNumber = 5;
::google::protobuf::Syntax syntax() const;
@@ -652,19 +767,16 @@ class LIBPROTOBUF_EXPORT Enum : public ::google::protobuf::Message /* @@protoc_i
private:
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
- bool _is_default_instance_;
- ::google::protobuf::internal::ArenaStringPtr name_;
+ friend class ::google::protobuf::Arena;
+ typedef void InternalArenaConstructable_;
+ typedef void DestructorSkippable_;
::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValue > enumvalue_;
::google::protobuf::RepeatedPtrField< ::google::protobuf::Option > options_;
+ ::google::protobuf::internal::ArenaStringPtr name_;
::google::protobuf::SourceContext* source_context_;
int syntax_;
mutable int _cached_size_;
- friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto();
- friend void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2ftype_2eproto();
-
- void InitAsDefaultInstance();
- static Enum* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2ftype_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -680,39 +792,58 @@ class LIBPROTOBUF_EXPORT EnumValue : public ::google::protobuf::Message /* @@pro
return *this;
}
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
+ return MaybeArenaPtr();
+ }
static const ::google::protobuf::Descriptor* descriptor();
static const EnumValue& default_instance();
+ static inline const EnumValue* internal_default_instance() {
+ return reinterpret_cast<const EnumValue*>(
+ &_EnumValue_default_instance_);
+ }
+
+ void UnsafeArenaSwap(EnumValue* other);
void Swap(EnumValue* other);
// implements Message ----------------------------------------------
- inline EnumValue* New() const { return New(NULL); }
+ inline EnumValue* New() const PROTOBUF_FINAL { return New(NULL); }
- EnumValue* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ EnumValue* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const EnumValue& from);
void MergeFrom(const EnumValue& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(EnumValue* other);
+ protected:
+ explicit EnumValue(::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();
@@ -722,13 +853,25 @@ class LIBPROTOBUF_EXPORT EnumValue : public ::google::protobuf::Message /* @@pro
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional string name = 1;
+ // repeated .google.protobuf.Option options = 3;
+ int options_size() const;
+ void clear_options();
+ static const int kOptionsFieldNumber = 3;
+ const ::google::protobuf::Option& options(int index) const;
+ ::google::protobuf::Option* mutable_options(int index);
+ ::google::protobuf::Option* add_options();
+ ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >*
+ mutable_options();
+ const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >&
+ options() const;
+
+ // string name = 1;
void clear_name();
static const int kNameFieldNumber = 1;
const ::std::string& name() const;
@@ -738,40 +881,28 @@ class LIBPROTOBUF_EXPORT EnumValue : public ::google::protobuf::Message /* @@pro
::std::string* mutable_name();
::std::string* release_name();
void set_allocated_name(::std::string* name);
+ ::std::string* unsafe_arena_release_name();
+ void unsafe_arena_set_allocated_name(
+ ::std::string* name);
- // optional int32 number = 2;
+ // int32 number = 2;
void clear_number();
static const int kNumberFieldNumber = 2;
::google::protobuf::int32 number() const;
void set_number(::google::protobuf::int32 value);
- // repeated .google.protobuf.Option options = 3;
- int options_size() const;
- void clear_options();
- static const int kOptionsFieldNumber = 3;
- const ::google::protobuf::Option& options(int index) const;
- ::google::protobuf::Option* mutable_options(int index);
- ::google::protobuf::Option* add_options();
- ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >*
- mutable_options();
- const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >&
- options() const;
-
// @@protoc_insertion_point(class_scope:google.protobuf.EnumValue)
private:
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
- bool _is_default_instance_;
- ::google::protobuf::internal::ArenaStringPtr name_;
+ friend class ::google::protobuf::Arena;
+ typedef void InternalArenaConstructable_;
+ typedef void DestructorSkippable_;
::google::protobuf::RepeatedPtrField< ::google::protobuf::Option > options_;
+ ::google::protobuf::internal::ArenaStringPtr name_;
::google::protobuf::int32 number_;
mutable int _cached_size_;
- friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto();
- friend void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2ftype_2eproto();
-
- void InitAsDefaultInstance();
- static EnumValue* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2ftype_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -787,39 +918,58 @@ class LIBPROTOBUF_EXPORT Option : public ::google::protobuf::Message /* @@protoc
return *this;
}
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
+ return MaybeArenaPtr();
+ }
static const ::google::protobuf::Descriptor* descriptor();
static const Option& default_instance();
+ static inline const Option* internal_default_instance() {
+ return reinterpret_cast<const Option*>(
+ &_Option_default_instance_);
+ }
+
+ void UnsafeArenaSwap(Option* other);
void Swap(Option* other);
// implements Message ----------------------------------------------
- inline Option* New() const { return New(NULL); }
+ inline Option* New() const PROTOBUF_FINAL { return New(NULL); }
- Option* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ Option* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Option& from);
void MergeFrom(const Option& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Option* other);
+ protected:
+ explicit Option(::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();
@@ -829,13 +979,13 @@ class LIBPROTOBUF_EXPORT Option : public ::google::protobuf::Message /* @@protoc
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional string name = 1;
+ // string name = 1;
void clear_name();
static const int kNameFieldNumber = 1;
const ::std::string& name() const;
@@ -845,30 +995,37 @@ class LIBPROTOBUF_EXPORT Option : public ::google::protobuf::Message /* @@protoc
::std::string* mutable_name();
::std::string* release_name();
void set_allocated_name(::std::string* name);
+ ::std::string* unsafe_arena_release_name();
+ void unsafe_arena_set_allocated_name(
+ ::std::string* name);
- // optional .google.protobuf.Any value = 2;
+ // .google.protobuf.Any value = 2;
bool has_value() const;
void clear_value();
static const int kValueFieldNumber = 2;
+ private:
+ void _slow_mutable_value();
+ ::google::protobuf::Any* _slow_release_value();
+ public:
const ::google::protobuf::Any& value() const;
::google::protobuf::Any* mutable_value();
::google::protobuf::Any* release_value();
void set_allocated_value(::google::protobuf::Any* value);
+ ::google::protobuf::Any* unsafe_arena_release_value();
+ void unsafe_arena_set_allocated_value(
+ ::google::protobuf::Any* value);
// @@protoc_insertion_point(class_scope:google.protobuf.Option)
private:
::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
- bool _is_default_instance_;
+ friend class ::google::protobuf::Arena;
+ typedef void InternalArenaConstructable_;
+ typedef void DestructorSkippable_;
::google::protobuf::internal::ArenaStringPtr name_;
::google::protobuf::Any* value_;
mutable int _cached_size_;
- friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto();
- friend void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2ftype_2eproto();
-
- void InitAsDefaultInstance();
- static Option* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2ftype_2eproto::TableStruct;
};
// ===================================================================
@@ -878,39 +1035,48 @@ class LIBPROTOBUF_EXPORT Option : public ::google::protobuf::Message /* @@protoc
#if !PROTOBUF_INLINE_NOT_IN_HEADERS
// Type
-// optional string name = 1;
+// string name = 1;
inline void Type::clear_name() {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
inline 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();
}
inline 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)
}
inline 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)
}
-inline void Type::set_name(const char* value, size_t size) {
+inline void Type::set_name(const char* value,
+ size_t size) {
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
+ name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(value), size), GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Type.name)
}
inline ::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());
}
inline ::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());
+}
+inline ::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());
}
inline void Type::set_allocated_name(::std::string* name) {
if (name != NULL) {
@@ -918,9 +1084,22 @@ inline void Type::set_allocated_name(::std::string* name) {
} 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)
}
+inline 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;
inline int Type::fields_size() const {
@@ -971,6 +1150,12 @@ inline void Type::set_oneofs(int index, const ::std::string& value) {
// @@protoc_insertion_point(field_set:google.protobuf.Type.oneofs)
oneofs_.Mutable(index)->assign(value);
}
+#if LANG_CXX11
+inline void Type::set_oneofs(int index, ::std::string&& value) {
+ // @@protoc_insertion_point(field_set:google.protobuf.Type.oneofs)
+ oneofs_.Mutable(index)->assign(std::move(value));
+}
+#endif
inline void Type::set_oneofs(int index, const char* value) {
oneofs_.Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set_char:google.protobuf.Type.oneofs)
@@ -988,6 +1173,12 @@ inline void Type::add_oneofs(const ::std::string& value) {
oneofs_.Add()->assign(value);
// @@protoc_insertion_point(field_add:google.protobuf.Type.oneofs)
}
+#if LANG_CXX11
+inline void Type::add_oneofs(::std::string&& value) {
+ oneofs_.Add()->assign(std::move(value));
+ // @@protoc_insertion_point(field_add:google.protobuf.Type.oneofs)
+}
+#endif
inline void Type::add_oneofs(const char* value) {
oneofs_.Add()->assign(value);
// @@protoc_insertion_point(field_add_char:google.protobuf.Type.oneofs)
@@ -1037,9 +1228,9 @@ Type::options() const {
return options_;
}
-// optional .google.protobuf.SourceContext source_context = 5;
+// .google.protobuf.SourceContext source_context = 5;
inline bool Type::has_source_context() const {
- return !_is_default_instance_ && source_context_ != NULL;
+ return this != internal_default_instance() && source_context_ != NULL;
}
inline void Type::clear_source_context() {
if (GetArenaNoVirtual() == NULL && source_context_ != NULL) delete source_context_;
@@ -1047,12 +1238,13 @@ inline void Type::clear_source_context() {
}
inline 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();
}
inline ::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_;
@@ -1060,12 +1252,24 @@ inline ::google::protobuf::SourceContext* Type::mutable_source_context() {
inline ::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;
+ }
}
-inline void Type::set_allocated_source_context(::google::protobuf::SourceContext* source_context) {
- delete source_context_;
+inline 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) {
@@ -1075,7 +1279,7 @@ inline void Type::set_allocated_source_context(::google::protobuf::SourceContext
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Type.source_context)
}
-// optional .google.protobuf.Syntax syntax = 6;
+// .google.protobuf.Syntax syntax = 6;
inline void Type::clear_syntax() {
syntax_ = 0;
}
@@ -1093,7 +1297,7 @@ inline void Type::set_syntax(::google::protobuf::Syntax value) {
// Field
-// optional .google.protobuf.Field.Kind kind = 1;
+// .google.protobuf.Field.Kind kind = 1;
inline void Field::clear_kind() {
kind_ = 0;
}
@@ -1107,7 +1311,7 @@ inline void Field::set_kind(::google::protobuf::Field_Kind value) {
// @@protoc_insertion_point(field_set:google.protobuf.Field.kind)
}
-// optional .google.protobuf.Field.Cardinality cardinality = 2;
+// .google.protobuf.Field.Cardinality cardinality = 2;
inline void Field::clear_cardinality() {
cardinality_ = 0;
}
@@ -1121,7 +1325,7 @@ inline void Field::set_cardinality(::google::protobuf::Field_Cardinality value)
// @@protoc_insertion_point(field_set:google.protobuf.Field.cardinality)
}
-// optional int32 number = 3;
+// int32 number = 3;
inline void Field::clear_number() {
number_ = 0;
}
@@ -1135,39 +1339,48 @@ inline void Field::set_number(::google::protobuf::int32 value) {
// @@protoc_insertion_point(field_set:google.protobuf.Field.number)
}
-// optional string name = 4;
+// string name = 4;
inline void Field::clear_name() {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
inline 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();
}
inline 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)
}
inline 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)
}
-inline void Field::set_name(const char* value, size_t size) {
+inline void Field::set_name(const char* value,
+ size_t size) {
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
+ name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(value), size), GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Field.name)
}
inline ::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());
}
inline ::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());
+}
+inline ::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());
}
inline void Field::set_allocated_name(::std::string* name) {
if (name != NULL) {
@@ -1175,43 +1388,65 @@ inline void Field::set_allocated_name(::std::string* name) {
} 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)
}
+inline 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;
+// string type_url = 6;
inline void Field::clear_type_url() {
- type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ type_url_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
inline 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();
}
inline 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)
}
inline 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)
}
-inline void Field::set_type_url(const char* value, size_t size) {
+inline void Field::set_type_url(const char* value,
+ size_t size) {
- type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
+ type_url_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(value), size), GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Field.type_url)
}
inline ::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());
}
inline ::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());
+}
+inline ::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());
}
inline void Field::set_allocated_type_url(::std::string* type_url) {
if (type_url != NULL) {
@@ -1219,11 +1454,24 @@ inline void Field::set_allocated_type_url(::std::string* type_url) {
} 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)
}
+inline 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;
+// int32 oneof_index = 7;
inline void Field::clear_oneof_index() {
oneof_index_ = 0;
}
@@ -1237,7 +1485,7 @@ inline void Field::set_oneof_index(::google::protobuf::int32 value) {
// @@protoc_insertion_point(field_set:google.protobuf.Field.oneof_index)
}
-// optional bool packed = 8;
+// bool packed = 8;
inline void Field::clear_packed() {
packed_ = false;
}
@@ -1281,39 +1529,48 @@ Field::options() const {
return options_;
}
-// optional string json_name = 10;
+// string json_name = 10;
inline void Field::clear_json_name() {
- json_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ json_name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
inline 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();
}
inline 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)
}
inline 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)
}
-inline void Field::set_json_name(const char* value, size_t size) {
+inline void Field::set_json_name(const char* value,
+ size_t size) {
- json_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
+ json_name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(value), size), GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Field.json_name)
}
inline ::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());
}
inline ::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());
+}
+inline ::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());
}
inline void Field::set_allocated_json_name(::std::string* json_name) {
if (json_name != NULL) {
@@ -1321,43 +1578,65 @@ inline void Field::set_allocated_json_name(::std::string* json_name) {
} 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)
}
+inline 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;
+// string default_value = 11;
inline void Field::clear_default_value() {
- default_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ default_value_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
inline 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();
}
inline 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)
}
inline 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)
}
-inline void Field::set_default_value(const char* value, size_t size) {
+inline void Field::set_default_value(const char* value,
+ size_t size) {
- default_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
+ default_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(value), size), GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Field.default_value)
}
inline ::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());
}
inline ::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());
+}
+inline ::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());
}
inline void Field::set_allocated_default_value(::std::string* default_value) {
if (default_value != NULL) {
@@ -1365,47 +1644,69 @@ inline void Field::set_allocated_default_value(::std::string* default_value) {
} 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)
}
+inline 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)
+}
// -------------------------------------------------------------------
// Enum
-// optional string name = 1;
+// string name = 1;
inline void Enum::clear_name() {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
inline 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();
}
inline 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)
}
inline 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)
}
-inline void Enum::set_name(const char* value, size_t size) {
+inline void Enum::set_name(const char* value,
+ size_t size) {
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
+ name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(value), size), GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Enum.name)
}
inline ::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());
}
inline ::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());
+}
+inline ::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());
}
inline void Enum::set_allocated_name(::std::string* name) {
if (name != NULL) {
@@ -1413,9 +1714,22 @@ inline void Enum::set_allocated_name(::std::string* name) {
} 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)
}
+inline 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;
inline int Enum::enumvalue_size() const {
@@ -1477,9 +1791,9 @@ Enum::options() const {
return options_;
}
-// optional .google.protobuf.SourceContext source_context = 4;
+// .google.protobuf.SourceContext source_context = 4;
inline bool Enum::has_source_context() const {
- return !_is_default_instance_ && source_context_ != NULL;
+ return this != internal_default_instance() && source_context_ != NULL;
}
inline void Enum::clear_source_context() {
if (GetArenaNoVirtual() == NULL && source_context_ != NULL) delete source_context_;
@@ -1487,12 +1801,13 @@ inline void Enum::clear_source_context() {
}
inline 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();
}
inline ::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_;
@@ -1500,12 +1815,24 @@ inline ::google::protobuf::SourceContext* Enum::mutable_source_context() {
inline ::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;
+ }
}
-inline void Enum::set_allocated_source_context(::google::protobuf::SourceContext* source_context) {
- delete source_context_;
+inline 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) {
@@ -1515,7 +1842,7 @@ inline void Enum::set_allocated_source_context(::google::protobuf::SourceContext
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Enum.source_context)
}
-// optional .google.protobuf.Syntax syntax = 5;
+// .google.protobuf.Syntax syntax = 5;
inline void Enum::clear_syntax() {
syntax_ = 0;
}
@@ -1533,39 +1860,48 @@ inline void Enum::set_syntax(::google::protobuf::Syntax value) {
// EnumValue
-// optional string name = 1;
+// string name = 1;
inline void EnumValue::clear_name() {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
inline 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();
}
inline 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)
}
inline 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)
}
-inline void EnumValue::set_name(const char* value, size_t size) {
+inline void EnumValue::set_name(const char* value,
+ size_t size) {
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
+ name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(value), size), GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.EnumValue.name)
}
inline ::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());
}
inline ::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());
+}
+inline ::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());
}
inline void EnumValue::set_allocated_name(::std::string* name) {
if (name != NULL) {
@@ -1573,11 +1909,24 @@ inline void EnumValue::set_allocated_name(::std::string* name) {
} 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)
}
+inline 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;
+// int32 number = 2;
inline void EnumValue::clear_number() {
number_ = 0;
}
@@ -1625,39 +1974,48 @@ EnumValue::options() const {
// Option
-// optional string name = 1;
+// string name = 1;
inline void Option::clear_name() {
- name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
inline const ::std::string& Option::name() const {
// @@protoc_insertion_point(field_get:google.protobuf.Option.name)
- return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return name_.Get();
}
inline void Option::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.Option.name)
}
inline void Option::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.Option.name)
}
-inline void Option::set_name(const char* value, size_t size) {
+inline void Option::set_name(const char* value,
+ size_t size) {
- name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
- ::std::string(reinterpret_cast<const char*>(value), size));
+ name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
+ reinterpret_cast<const char*>(value), size), GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.Option.name)
}
inline ::std::string* Option::mutable_name() {
// @@protoc_insertion_point(field_mutable:google.protobuf.Option.name)
- return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return name_.Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
inline ::std::string* Option::release_name() {
// @@protoc_insertion_point(field_release:google.protobuf.Option.name)
- return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return name_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
+}
+inline ::std::string* Option::unsafe_arena_release_name() {
+ // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Option.name)
+ GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);
+
+ return name_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+ GetArenaNoVirtual());
}
inline void Option::set_allocated_name(::std::string* name) {
if (name != NULL) {
@@ -1665,13 +2023,26 @@ inline void Option::set_allocated_name(::std::string* name) {
} else {
}
- name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name);
+ name_.SetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name,
+ GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Option.name)
}
+inline void Option::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.Option.name)
+}
-// optional .google.protobuf.Any value = 2;
+// .google.protobuf.Any value = 2;
inline bool Option::has_value() const {
- return !_is_default_instance_ && value_ != NULL;
+ return this != internal_default_instance() && value_ != NULL;
}
inline void Option::clear_value() {
if (GetArenaNoVirtual() == NULL && value_ != NULL) delete value_;
@@ -1679,12 +2050,13 @@ inline void Option::clear_value() {
}
inline const ::google::protobuf::Any& Option::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.Option.value)
- return value_ != NULL ? *value_ : *default_instance_->value_;
+ return value_ != NULL ? *value_
+ : *::google::protobuf::Any::internal_default_instance();
}
inline ::google::protobuf::Any* Option::mutable_value() {
if (value_ == NULL) {
- value_ = new ::google::protobuf::Any;
+ _slow_mutable_value();
}
// @@protoc_insertion_point(field_mutable:google.protobuf.Option.value)
return value_;
@@ -1692,12 +2064,24 @@ inline ::google::protobuf::Any* Option::mutable_value() {
inline ::google::protobuf::Any* Option::release_value() {
// @@protoc_insertion_point(field_release:google.protobuf.Option.value)
- ::google::protobuf::Any* temp = value_;
- value_ = NULL;
- return temp;
+ if (GetArenaNoVirtual() != NULL) {
+ return _slow_release_value();
+ } else {
+ ::google::protobuf::Any* temp = value_;
+ value_ = NULL;
+ return temp;
+ }
}
-inline void Option::set_allocated_value(::google::protobuf::Any* value) {
- delete value_;
+inline void Option::set_allocated_value(::google::protobuf::Any* value) {
+ ::google::protobuf::Arena* message_arena = GetArenaNoVirtual();
+ if (message_arena == NULL) {
+ delete value_;
+ }
+ if (value != NULL) {
+ if (message_arena != NULL) {
+ message_arena->Own(value);
+ }
+ }
value_ = value;
if (value) {
@@ -1719,6 +2103,7 @@ inline void Option::set_allocated_value(::google::protobuf::Any* value) {
// @@protoc_insertion_point(namespace_scope)
+
} // namespace protobuf
} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/type.proto b/third_party/protobuf/src/google/protobuf/type.proto
index 1c9cf53da8..624c15ee61 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/type.proto
+++ b/third_party/protobuf/src/google/protobuf/type.proto
@@ -36,11 +36,12 @@ import "google/protobuf/any.proto";
import "google/protobuf/source_context.proto";
option csharp_namespace = "Google.Protobuf.WellKnownTypes";
+option cc_enable_arenas = true;
option java_package = "com.google.protobuf";
option java_outer_classname = "TypeProto";
option java_multiple_files = true;
-option java_generate_equals_and_hash = true;
option objc_class_prefix = "GPB";
+option go_package = "google.golang.org/genproto/protobuf/ptype;ptype";
// A protocol buffer message type.
message Type {
@@ -165,9 +166,15 @@ message EnumValue {
// A protocol buffer option, which can be attached to a message, field,
// enumeration, etc.
message Option {
- // The option's name. For example, `"java_package"`.
+ // The option's name. For protobuf built-in options (options defined in
+ // descriptor.proto), this is the short name. For example, `"map_entry"`.
+ // For custom options, it should be the fully-qualified name. For example,
+ // `"google.api.http"`.
string name = 1;
- // The option's value. For example, `"com.google.protobuf"`.
+ // The option's value packed in an Any message. If the value is a primitive,
+ // the corresponding wrapper type defined in google/protobuf/wrappers.proto
+ // should be used. If the value is an enum, it should be stored as an int32
+ // value using the google.protobuf.Int32Value type.
Any value = 2;
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest.proto b/third_party/protobuf/src/google/protobuf/unittest.proto
index d5206d2463..188a4f478c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest.proto
@@ -191,6 +191,10 @@ message TestDeprecatedFields {
optional int32 deprecated_int32 = 1 [deprecated=true];
}
+message TestDeprecatedMessage {
+ option deprecated = true;
+}
+
// Define these after TestAllTypes to make sure the compiler can handle
// that.
message ForeignMessage {
@@ -878,3 +882,42 @@ service TestService {
message BarRequest {}
message BarResponse {}
+message TestJsonName {
+ optional int32 field_name1 = 1;
+ optional int32 fieldName2 = 2;
+ optional int32 FieldName3 = 3;
+ optional int32 _field_name4 = 4;
+ optional int32 FIELD_NAME5 = 5;
+ optional int32 field_name6 = 6 [json_name = "@type"];
+}
+
+message TestHugeFieldNumbers {
+ optional int32 optional_int32 = 536870000;
+ optional int32 fixed_32 = 536870001;
+ repeated int32 repeated_int32 = 536870002 [packed = false];
+ repeated int32 packed_int32 = 536870003 [packed = true];
+
+ optional ForeignEnum optional_enum = 536870004;
+ optional string optional_string = 536870005;
+ optional bytes optional_bytes = 536870006;
+ optional ForeignMessage optional_message = 536870007;
+
+ optional group OptionalGroup = 536870008 {
+ optional int32 group_a = 536870009;
+ }
+
+ map<string, string> string_string_map = 536870010;
+
+ oneof oneof_field {
+ uint32 oneof_uint32 = 536870011;
+ TestAllTypes oneof_test_all_types = 536870012;
+ string oneof_string = 536870013;
+ bytes oneof_bytes = 536870014;
+ }
+
+ extensions 536860000 to 536869999;
+}
+
+extend TestHugeFieldNumbers {
+ optional TestAllTypes test_all_types = 536860000;
+}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_arena.proto b/third_party/protobuf/src/google/protobuf/unittest_arena.proto
index cd7e437e16..cd7e437e16 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_arena.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_arena.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_custom_options.proto b/third_party/protobuf/src/google/protobuf/unittest_custom_options.proto
index 218447e9aa..218447e9aa 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_custom_options.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_custom_options.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_drop_unknown_fields.proto b/third_party/protobuf/src/google/protobuf/unittest_drop_unknown_fields.proto
index 8aa3a37b8e..8aa3a37b8e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_drop_unknown_fields.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_drop_unknown_fields.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_embed_optimize_for.proto b/third_party/protobuf/src/google/protobuf/unittest_embed_optimize_for.proto
index d8b0f9b94f..d8b0f9b94f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_embed_optimize_for.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_embed_optimize_for.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_empty.proto b/third_party/protobuf/src/google/protobuf/unittest_empty.proto
index 36443e7e01..36443e7e01 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_empty.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_empty.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_enormous_descriptor.proto b/third_party/protobuf/src/google/protobuf/unittest_enormous_descriptor.proto
index 6e65dc18b7..6e65dc18b7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_enormous_descriptor.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_enormous_descriptor.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_import.proto b/third_party/protobuf/src/google/protobuf/unittest_import.proto
index 8d03e3888b..8d03e3888b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_import.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_import.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_import_lite.proto b/third_party/protobuf/src/google/protobuf/unittest_import_lite.proto
index a7afa45233..a7afa45233 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_import_lite.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_import_lite.proto
diff --git a/third_party/protobuf/src/google/protobuf/unittest_import_proto3.proto b/third_party/protobuf/src/google/protobuf/unittest_import_proto3.proto
new file mode 100644
index 0000000000..59673eaf9d
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/unittest_import_proto3.proto
@@ -0,0 +1,68 @@
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file which is imported by unittest_proto3.proto to test importing.
+
+syntax = "proto3";
+
+// We don't put this in a package within proto2 because we need to make sure
+// that the generated code doesn't depend on being in the proto2 namespace.
+// In test_util.h we do
+// "using namespace unittest_import = protobuf_unittest_import".
+package protobuf_unittest_import;
+
+option optimize_for = SPEED;
+option cc_enable_arenas = true;
+
+// Exercise the java_package option.
+option java_package = "com.google.protobuf.test";
+option csharp_namespace = "Google.Protobuf.TestProtos";
+
+// Do not set a java_outer_classname here to verify that Proto2 works without
+// one.
+
+// Test public import
+import public "google/protobuf/unittest_import_public_proto3.proto";
+
+message ImportMessage {
+ int32 d = 1;
+}
+
+enum ImportEnum {
+ IMPORT_ENUM_UNSPECIFIED = 0;
+ IMPORT_FOO = 7;
+ IMPORT_BAR = 8;
+ IMPORT_BAZ = 9;
+}
+
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_import_public.proto b/third_party/protobuf/src/google/protobuf/unittest_import_public.proto
index ffaf773698..ffaf773698 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_import_public.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_import_public.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_import_public_lite.proto b/third_party/protobuf/src/google/protobuf/unittest_import_public_lite.proto
index 33549c2279..33549c2279 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_import_public_lite.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_import_public_lite.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/struct.proto b/third_party/protobuf/src/google/protobuf/unittest_import_public_proto3.proto
index c15aba0d6d..d6f11e28bd 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/struct.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_import_public_proto3.proto
@@ -28,18 +28,15 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Proto to test proto3 struct.
-syntax = "proto3";
+// Author: liujisi@google.com (Pherl Liu)
-package google.protobuf.testing.structs;
-option java_package = "com.google.protobuf.testing.structs";
+syntax = "proto3";
-import "google/protobuf/struct.proto";
+package protobuf_unittest_import;
-message StructType {
- google.protobuf.Struct object = 1;
-}
+option java_package = "com.google.protobuf.test";
+option csharp_namespace = "Google.Protobuf.TestProtos";
-service TestService {
- rpc Call(StructType) returns (StructType);
+message PublicImportMessage {
+ int32 e = 1;
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_lite.proto b/third_party/protobuf/src/google/protobuf/unittest_lite.proto
index 878ec7c1d2..c39ac6b01f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_lite.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_lite.proto
@@ -163,6 +163,9 @@ message TestAllTypesLite {
bytes oneof_bytes = 114;
NestedMessage oneof_lazy_nested_message = 115 [lazy = true];
}
+
+ // Tests toString for non-repeated fields with a list suffix
+ optional int32 deceptively_named_list = 116;
}
message ForeignMessageLite {
@@ -405,3 +408,34 @@ message V2MessageLite {
required int32 int_field = 1;
optional V2EnumLite enum_field = 2 [ default = V2_FIRST ];
}
+
+message TestHugeFieldNumbersLite {
+ optional int32 optional_int32 = 536870000;
+ optional int32 fixed_32 = 536870001;
+ repeated int32 repeated_int32 = 536870002 [packed = false];
+ repeated int32 packed_int32 = 536870003 [packed = true];
+
+ optional ForeignEnumLite optional_enum = 536870004;
+ optional string optional_string = 536870005;
+ optional bytes optional_bytes = 536870006;
+ optional ForeignMessageLite optional_message = 536870007;
+
+ optional group OptionalGroup = 536870008 {
+ optional int32 group_a = 536870009;
+ }
+
+ map<string, string> string_string_map = 536870010;
+
+ oneof oneof_field {
+ uint32 oneof_uint32 = 536870011;
+ TestAllTypesLite oneof_test_all_types = 536870012;
+ string oneof_string = 536870013;
+ bytes oneof_bytes = 536870014;
+ }
+
+ extensions 536860000 to 536869999;
+}
+
+extend TestHugeFieldNumbersLite {
+ optional TestAllTypesLite test_all_types_lite = 536860000;
+}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_lite_imports_nonlite.proto b/third_party/protobuf/src/google/protobuf/unittest_lite_imports_nonlite.proto
index 132d6a82d2..132d6a82d2 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_lite_imports_nonlite.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_lite_imports_nonlite.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_mset.proto b/third_party/protobuf/src/google/protobuf/unittest_mset.proto
index 49d9adad0b..49d9adad0b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_mset.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_mset.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_mset_wire_format.proto b/third_party/protobuf/src/google/protobuf/unittest_mset_wire_format.proto
index 04e4352e06..04e4352e06 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_mset_wire_format.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_mset_wire_format.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_no_arena.proto b/third_party/protobuf/src/google/protobuf/unittest_no_arena.proto
index 41518df297..41518df297 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_no_arena.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_no_arena.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_no_arena_import.proto b/third_party/protobuf/src/google/protobuf/unittest_no_arena_import.proto
index 072af49e3c..072af49e3c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_no_arena_import.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_no_arena_import.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_no_arena_lite.proto b/third_party/protobuf/src/google/protobuf/unittest_no_arena_lite.proto
index 34c7b7ce99..34c7b7ce99 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_no_arena_lite.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_no_arena_lite.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_no_field_presence.proto b/third_party/protobuf/src/google/protobuf/unittest_no_field_presence.proto
index 994afff42d..994afff42d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_no_field_presence.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_no_field_presence.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_no_generic_services.proto b/third_party/protobuf/src/google/protobuf/unittest_no_generic_services.proto
index 8fc7713c9e..8fc7713c9e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_no_generic_services.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_no_generic_services.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_optimize_for.proto b/third_party/protobuf/src/google/protobuf/unittest_optimize_for.proto
index ee9cc7bd49..ee9cc7bd49 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_optimize_for.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_optimize_for.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_preserve_unknown_enum.proto b/third_party/protobuf/src/google/protobuf/unittest_preserve_unknown_enum.proto
index 2f91332c9e..2f91332c9e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_preserve_unknown_enum.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_preserve_unknown_enum.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_preserve_unknown_enum2.proto b/third_party/protobuf/src/google/protobuf/unittest_preserve_unknown_enum2.proto
index adf42968aa..adf42968aa 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_preserve_unknown_enum2.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_preserve_unknown_enum2.proto
diff --git a/third_party/protobuf/src/google/protobuf/unittest_proto3.proto b/third_party/protobuf/src/google/protobuf/unittest_proto3.proto
new file mode 100644
index 0000000000..a27b1b268c
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/unittest_proto3.proto
@@ -0,0 +1,391 @@
+// 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.
+
+// Author: kenton@google.com (Kenton Varda)
+// Based on original Protocol Buffers design by
+// Sanjay Ghemawat, Jeff Dean, and others.
+//
+// A proto file we will use for unit testing.
+
+syntax = "proto3";
+
+// Some generic_services option(s) added automatically.
+// See: http://go/proto2-generic-services-default
+option cc_generic_services = true; // auto-added
+option java_generic_services = true; // auto-added
+option py_generic_services = true; // auto-added
+option cc_enable_arenas = true;
+option csharp_namespace = "Google.Protobuf.TestProtos";
+
+import "google/protobuf/unittest_import_proto3.proto";
+
+// We don't put this in a package within proto2 because we need to make sure
+// that the generated code doesn't depend on being in the proto2 namespace.
+// In test_util.h we do "using namespace unittest = protobuf_unittest".
+package protobuf_unittest;
+
+// Protos optimized for SPEED use a strict superset of the generated code
+// of equivalent ones optimized for CODE_SIZE, so we should optimize all our
+// tests for speed unless explicitly testing code size optimization.
+option optimize_for = SPEED;
+
+option java_outer_classname = "UnittestProto";
+
+// This proto includes every type of field in both singular and repeated
+// forms.
+message TestAllTypes {
+ message NestedMessage {
+ // The field name "b" fails to compile in proto1 because it conflicts with
+ // a local variable named "b" in one of the generated methods. Doh.
+ // This file needs to compile in proto1 to test backwards-compatibility.
+ int32 bb = 1;
+ }
+
+ enum NestedEnum {
+ NESTED_ENUM_UNSPECIFIED = 0;
+ FOO = 1;
+ BAR = 2;
+ BAZ = 3;
+ NEG = -1; // Intentionally negative.
+ }
+
+ // Singular
+ int32 single_int32 = 1;
+ int64 single_int64 = 2;
+ uint32 single_uint32 = 3;
+ uint64 single_uint64 = 4;
+ sint32 single_sint32 = 5;
+ sint64 single_sint64 = 6;
+ fixed32 single_fixed32 = 7;
+ fixed64 single_fixed64 = 8;
+ sfixed32 single_sfixed32 = 9;
+ sfixed64 single_sfixed64 = 10;
+ float single_float = 11;
+ double single_double = 12;
+ bool single_bool = 13;
+ string single_string = 14;
+ bytes single_bytes = 15;
+
+ NestedMessage single_nested_message = 18;
+ ForeignMessage single_foreign_message = 19;
+ protobuf_unittest_import.ImportMessage single_import_message = 20;
+
+ NestedEnum single_nested_enum = 21;
+ ForeignEnum single_foreign_enum = 22;
+ protobuf_unittest_import.ImportEnum single_import_enum = 23;
+
+ // Defined in unittest_import_public.proto
+ protobuf_unittest_import.PublicImportMessage
+ single_public_import_message = 26;
+
+ // Repeated
+ repeated int32 repeated_int32 = 31;
+ repeated int64 repeated_int64 = 32;
+ repeated uint32 repeated_uint32 = 33;
+ repeated uint64 repeated_uint64 = 34;
+ repeated sint32 repeated_sint32 = 35;
+ repeated sint64 repeated_sint64 = 36;
+ repeated fixed32 repeated_fixed32 = 37;
+ repeated fixed64 repeated_fixed64 = 38;
+ repeated sfixed32 repeated_sfixed32 = 39;
+ repeated sfixed64 repeated_sfixed64 = 40;
+ repeated float repeated_float = 41;
+ repeated double repeated_double = 42;
+ repeated bool repeated_bool = 43;
+ repeated string repeated_string = 44;
+ repeated bytes repeated_bytes = 45;
+
+ repeated NestedMessage repeated_nested_message = 48;
+ repeated ForeignMessage repeated_foreign_message = 49;
+ repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50;
+
+ repeated NestedEnum repeated_nested_enum = 51;
+ repeated ForeignEnum repeated_foreign_enum = 52;
+ repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53;
+ // Defined in unittest_import_public.proto
+ repeated protobuf_unittest_import.PublicImportMessage
+ repeated_public_import_message = 54;
+
+ // For oneof test
+ oneof oneof_field {
+ uint32 oneof_uint32 = 111;
+ NestedMessage oneof_nested_message = 112;
+ string oneof_string = 113;
+ bytes oneof_bytes = 114;
+ }
+}
+
+// This proto includes a recusively nested message.
+message NestedTestAllTypes {
+ NestedTestAllTypes child = 1;
+ TestAllTypes payload = 2;
+ repeated NestedTestAllTypes repeated_child = 3;
+}
+
+message TestDeprecatedFields {
+ int32 deprecated_int32 = 1 [deprecated=true];
+}
+
+// Define these after TestAllTypes to make sure the compiler can handle
+// that.
+message ForeignMessage {
+ int32 c = 1;
+}
+
+enum ForeignEnum {
+ FOREIGN_UNSPECIFIED = 0;
+ FOREIGN_FOO = 4;
+ FOREIGN_BAR = 5;
+ FOREIGN_BAZ = 6;
+}
+
+message TestReservedFields {
+ reserved 2, 15, 9 to 11;
+ reserved "bar", "baz";
+}
+
+
+// Test that we can use NestedMessage from outside TestAllTypes.
+message TestForeignNested {
+ TestAllTypes.NestedMessage foreign_nested = 1;
+}
+
+// Test that really large tag numbers don't break anything.
+message TestReallyLargeTagNumber {
+ // The largest possible tag number is 2^28 - 1, since the wire format uses
+ // three bits to communicate wire type.
+ int32 a = 1;
+ int32 bb = 268435455;
+}
+
+message TestRecursiveMessage {
+ TestRecursiveMessage a = 1;
+ int32 i = 2;
+}
+
+// Test that mutual recursion works.
+message TestMutualRecursionA {
+ TestMutualRecursionB bb = 1;
+}
+
+message TestMutualRecursionB {
+ TestMutualRecursionA a = 1;
+ int32 optional_int32 = 2;
+}
+
+message TestEnumAllowAlias {
+ TestEnumWithDupValue value = 1;
+}
+
+// Test an enum that has multiple values with the same number.
+enum TestEnumWithDupValue {
+ TEST_ENUM_WITH_DUP_VALUE_UNSPECIFIED = 0;
+ option allow_alias = true;
+
+ FOO1 = 1;
+ BAR1 = 2;
+ BAZ = 3;
+ FOO2 = 1;
+ BAR2 = 2;
+}
+
+// Test an enum with large, unordered values.
+enum TestSparseEnum {
+ TEST_SPARSE_ENUM_UNSPECIFIED = 0;
+ SPARSE_A = 123;
+ SPARSE_B = 62374;
+ SPARSE_C = 12589234;
+ SPARSE_D = -15;
+ SPARSE_E = -53452;
+ // In proto3, value 0 must be the first one specified
+ // SPARSE_F = 0;
+ SPARSE_G = 2;
+}
+
+// Test message with CamelCase field names. This violates Protocol Buffer
+// standard style.
+message TestCamelCaseFieldNames {
+ int32 PrimitiveField = 1;
+ string StringField = 2;
+ ForeignEnum EnumField = 3;
+ ForeignMessage MessageField = 4;
+
+ repeated int32 RepeatedPrimitiveField = 7;
+ repeated string RepeatedStringField = 8;
+ repeated ForeignEnum RepeatedEnumField = 9;
+ repeated ForeignMessage RepeatedMessageField = 10;
+}
+
+
+// We list fields out of order, to ensure that we're using field number and not
+// field index to determine serialization order.
+message TestFieldOrderings {
+ string my_string = 11;
+ int64 my_int = 1;
+ float my_float = 101;
+ message NestedMessage {
+ int64 oo = 2;
+ // The field name "b" fails to compile in proto1 because it conflicts with
+ // a local variable named "b" in one of the generated methods. Doh.
+ // This file needs to compile in proto1 to test backwards-compatibility.
+ int32 bb = 1;
+ }
+
+ NestedMessage single_nested_message = 200;
+}
+
+message SparseEnumMessage {
+ TestSparseEnum sparse_enum = 1;
+}
+
+// Test String and Bytes: string is for valid UTF-8 strings
+message OneString {
+ string data = 1;
+}
+
+message MoreString {
+ repeated string data = 1;
+}
+
+message OneBytes {
+ bytes data = 1;
+}
+
+message MoreBytes {
+ bytes data = 1;
+}
+
+// Test int32, uint32, int64, uint64, and bool are all compatible
+message Int32Message {
+ int32 data = 1;
+}
+
+message Uint32Message {
+ uint32 data = 1;
+}
+
+message Int64Message {
+ int64 data = 1;
+}
+
+message Uint64Message {
+ uint64 data = 1;
+}
+
+message BoolMessage {
+ bool data = 1;
+}
+
+// Test oneofs.
+message TestOneof {
+ oneof foo {
+ int32 foo_int = 1;
+ string foo_string = 2;
+ TestAllTypes foo_message = 3;
+ }
+}
+
+// Test messages for packed fields
+
+message TestPackedTypes {
+ repeated int32 packed_int32 = 90 [packed = true];
+ repeated int64 packed_int64 = 91 [packed = true];
+ repeated uint32 packed_uint32 = 92 [packed = true];
+ repeated uint64 packed_uint64 = 93 [packed = true];
+ repeated sint32 packed_sint32 = 94 [packed = true];
+ repeated sint64 packed_sint64 = 95 [packed = true];
+ repeated fixed32 packed_fixed32 = 96 [packed = true];
+ repeated fixed64 packed_fixed64 = 97 [packed = true];
+ repeated sfixed32 packed_sfixed32 = 98 [packed = true];
+ repeated sfixed64 packed_sfixed64 = 99 [packed = true];
+ repeated float packed_float = 100 [packed = true];
+ repeated double packed_double = 101 [packed = true];
+ repeated bool packed_bool = 102 [packed = true];
+ repeated ForeignEnum packed_enum = 103 [packed = true];
+}
+
+// A message with the same fields as TestPackedTypes, but without packing. Used
+// to test packed <-> unpacked wire compatibility.
+message TestUnpackedTypes {
+ repeated int32 unpacked_int32 = 90 [packed = false];
+ repeated int64 unpacked_int64 = 91 [packed = false];
+ repeated uint32 unpacked_uint32 = 92 [packed = false];
+ repeated uint64 unpacked_uint64 = 93 [packed = false];
+ repeated sint32 unpacked_sint32 = 94 [packed = false];
+ repeated sint64 unpacked_sint64 = 95 [packed = false];
+ repeated fixed32 unpacked_fixed32 = 96 [packed = false];
+ repeated fixed64 unpacked_fixed64 = 97 [packed = false];
+ repeated sfixed32 unpacked_sfixed32 = 98 [packed = false];
+ repeated sfixed64 unpacked_sfixed64 = 99 [packed = false];
+ repeated float unpacked_float = 100 [packed = false];
+ repeated double unpacked_double = 101 [packed = false];
+ repeated bool unpacked_bool = 102 [packed = false];
+ repeated ForeignEnum unpacked_enum = 103 [packed = false];
+}
+
+message TestRepeatedScalarDifferentTagSizes {
+ // Parsing repeated fixed size values used to fail. This message needs to be
+ // used in order to get a tag of the right size; all of the repeated fields
+ // in TestAllTypes didn't trigger the check.
+ repeated fixed32 repeated_fixed32 = 12;
+ // Check for a varint type, just for good measure.
+ repeated int32 repeated_int32 = 13;
+
+ // These have two-byte tags.
+ repeated fixed64 repeated_fixed64 = 2046;
+ repeated int64 repeated_int64 = 2047;
+
+ // Three byte tags.
+ repeated float repeated_float = 262142;
+ repeated uint64 repeated_uint64 = 262143;
+}
+
+message TestCommentInjectionMessage {
+ // */ <- This should not close the generated doc comment
+ string a = 1;
+}
+
+
+// Test that RPC services work.
+message FooRequest {}
+message FooResponse {}
+
+message FooClientMessage {}
+message FooServerMessage{}
+
+service TestService {
+ rpc Foo(FooRequest) returns (FooResponse);
+ rpc Bar(BarRequest) returns (BarResponse);
+}
+
+
+message BarRequest {}
+message BarResponse {}
+
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_proto3_arena.proto b/third_party/protobuf/src/google/protobuf/unittest_proto3_arena.proto
index b835a6ba36..b835a6ba36 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_proto3_arena.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_proto3_arena.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_proto3_arena_lite.proto b/third_party/protobuf/src/google/protobuf/unittest_proto3_arena_lite.proto
index 5a60b90f5c..5a60b90f5c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_proto3_arena_lite.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_proto3_arena_lite.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_proto3_lite.proto b/third_party/protobuf/src/google/protobuf/unittest_proto3_lite.proto
index 874ade6c0e..874ade6c0e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unittest_proto3_lite.proto
+++ b/third_party/protobuf/src/google/protobuf/unittest_proto3_lite.proto
diff --git a/third_party/protobuf/src/google/protobuf/unittest_well_known_types.proto b/third_party/protobuf/src/google/protobuf/unittest_well_known_types.proto
new file mode 100644
index 0000000000..c90752440b
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/unittest_well_known_types.proto
@@ -0,0 +1,114 @@
+syntax = "proto3";
+
+package protobuf_unittest;
+
+option csharp_namespace = "Google.Protobuf.TestProtos";
+option java_multiple_files = true;
+option java_package = "com.google.protobuf.test";
+
+import "google/protobuf/any.proto";
+import "google/protobuf/api.proto";
+import "google/protobuf/duration.proto";
+import "google/protobuf/empty.proto";
+import "google/protobuf/field_mask.proto";
+import "google/protobuf/source_context.proto";
+import "google/protobuf/struct.proto";
+import "google/protobuf/timestamp.proto";
+import "google/protobuf/type.proto";
+import "google/protobuf/wrappers.proto";
+
+// Test that we can include all well-known types.
+// Each wrapper type is included separately, as languages
+// map handle different wrappers in different ways.
+message TestWellKnownTypes {
+ google.protobuf.Any any_field = 1;
+ google.protobuf.Api api_field = 2;
+ google.protobuf.Duration duration_field = 3;
+ google.protobuf.Empty empty_field = 4;
+ google.protobuf.FieldMask field_mask_field = 5;
+ google.protobuf.SourceContext source_context_field = 6;
+ google.protobuf.Struct struct_field = 7;
+ google.protobuf.Timestamp timestamp_field = 8;
+ google.protobuf.Type type_field = 9;
+ google.protobuf.DoubleValue double_field = 10;
+ google.protobuf.FloatValue float_field = 11;
+ google.protobuf.Int64Value int64_field = 12;
+ google.protobuf.UInt64Value uint64_field = 13;
+ google.protobuf.Int32Value int32_field = 14;
+ google.protobuf.UInt32Value uint32_field = 15;
+ google.protobuf.BoolValue bool_field = 16;
+ google.protobuf.StringValue string_field = 17;
+ google.protobuf.BytesValue bytes_field = 18;
+ // Part of struct, but useful to be able to test separately
+ google.protobuf.Value value_field = 19;
+}
+
+// A repeated field for each well-known type.
+message RepeatedWellKnownTypes {
+ repeated google.protobuf.Any any_field = 1;
+ repeated google.protobuf.Api api_field = 2;
+ repeated google.protobuf.Duration duration_field = 3;
+ repeated google.protobuf.Empty empty_field = 4;
+ repeated google.protobuf.FieldMask field_mask_field = 5;
+ repeated google.protobuf.SourceContext source_context_field = 6;
+ repeated google.protobuf.Struct struct_field = 7;
+ repeated google.protobuf.Timestamp timestamp_field = 8;
+ repeated google.protobuf.Type type_field = 9;
+ // These don't actually make a lot of sense, but they're not prohibited...
+ repeated google.protobuf.DoubleValue double_field = 10;
+ repeated google.protobuf.FloatValue float_field = 11;
+ repeated google.protobuf.Int64Value int64_field = 12;
+ repeated google.protobuf.UInt64Value uint64_field = 13;
+ repeated google.protobuf.Int32Value int32_field = 14;
+ repeated google.protobuf.UInt32Value uint32_field = 15;
+ repeated google.protobuf.BoolValue bool_field = 16;
+ repeated google.protobuf.StringValue string_field = 17;
+ repeated google.protobuf.BytesValue bytes_field = 18;
+}
+
+message OneofWellKnownTypes {
+ oneof oneof_field {
+ google.protobuf.Any any_field = 1;
+ google.protobuf.Api api_field = 2;
+ google.protobuf.Duration duration_field = 3;
+ google.protobuf.Empty empty_field = 4;
+ google.protobuf.FieldMask field_mask_field = 5;
+ google.protobuf.SourceContext source_context_field = 6;
+ google.protobuf.Struct struct_field = 7;
+ google.protobuf.Timestamp timestamp_field = 8;
+ google.protobuf.Type type_field = 9;
+ google.protobuf.DoubleValue double_field = 10;
+ google.protobuf.FloatValue float_field = 11;
+ google.protobuf.Int64Value int64_field = 12;
+ google.protobuf.UInt64Value uint64_field = 13;
+ google.protobuf.Int32Value int32_field = 14;
+ google.protobuf.UInt32Value uint32_field = 15;
+ google.protobuf.BoolValue bool_field = 16;
+ google.protobuf.StringValue string_field = 17;
+ google.protobuf.BytesValue bytes_field = 18;
+ }
+}
+
+// A map field for each well-known type. We only
+// need to worry about the value part of the map being the
+// well-known types, as messages can't be map keys.
+message MapWellKnownTypes {
+ map<int32,google.protobuf.Any> any_field = 1;
+ map<int32,google.protobuf.Api> api_field = 2;
+ map<int32,google.protobuf.Duration> duration_field = 3;
+ map<int32,google.protobuf.Empty> empty_field = 4;
+ map<int32,google.protobuf.FieldMask> field_mask_field = 5;
+ map<int32,google.protobuf.SourceContext> source_context_field = 6;
+ map<int32,google.protobuf.Struct> struct_field = 7;
+ map<int32,google.protobuf.Timestamp> timestamp_field = 8;
+ map<int32,google.protobuf.Type> type_field = 9;
+ map<int32,google.protobuf.DoubleValue> double_field = 10;
+ map<int32,google.protobuf.FloatValue> float_field = 11;
+ map<int32,google.protobuf.Int64Value> int64_field = 12;
+ map<int32,google.protobuf.UInt64Value> uint64_field = 13;
+ map<int32,google.protobuf.Int32Value> int32_field = 14;
+ map<int32,google.protobuf.UInt32Value> uint32_field = 15;
+ map<int32,google.protobuf.BoolValue> bool_field = 16;
+ map<int32,google.protobuf.StringValue> string_field = 17;
+ map<int32,google.protobuf.BytesValue> bytes_field = 18;
+}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unknown_field_set.cc b/third_party/protobuf/src/google/protobuf/unknown_field_set.cc
index 8ee99d48b1..9472c4fa5f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unknown_field_set.cc
+++ b/third_party/protobuf/src/google/protobuf/unknown_field_set.cc
@@ -39,6 +39,7 @@
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
+#include <google/protobuf/metadata.h>
#include <google/protobuf/wire_format.h>
#include <google/protobuf/stubs/stl_util.h>
@@ -82,7 +83,7 @@ void UnknownFieldSet::ClearFallback() {
void UnknownFieldSet::InternalMergeFrom(const UnknownFieldSet& other) {
int other_field_count = other.field_count();
if (other_field_count > 0) {
- fields_ = new vector<UnknownField>();
+ fields_ = new std::vector<UnknownField>();
for (int i = 0; i < other_field_count; i++) {
fields_->push_back((*other.fields_)[i]);
fields_->back().DeepCopy((*other.fields_)[i]);
@@ -93,7 +94,7 @@ void UnknownFieldSet::InternalMergeFrom(const UnknownFieldSet& other) {
void UnknownFieldSet::MergeFrom(const UnknownFieldSet& other) {
int other_field_count = other.field_count();
if (other_field_count > 0) {
- if (fields_ == NULL) fields_ = new vector<UnknownField>();
+ if (fields_ == NULL) fields_ = new std::vector<UnknownField>();
for (int i = 0; i < other_field_count; i++) {
fields_->push_back((*other.fields_)[i]);
fields_->back().DeepCopy((*other.fields_)[i]);
@@ -106,7 +107,7 @@ void UnknownFieldSet::MergeFrom(const UnknownFieldSet& other) {
void UnknownFieldSet::MergeFromAndDestroy(UnknownFieldSet* other) {
int other_field_count = other->field_count();
if (other_field_count > 0) {
- if (fields_ == NULL) fields_ = new vector<UnknownField>();
+ if (fields_ == NULL) fields_ = new std::vector<UnknownField>();
for (int i = 0; i < other_field_count; i++) {
fields_->push_back((*other->fields_)[i]);
(*other->fields_)[i].Reset();
@@ -116,6 +117,12 @@ void UnknownFieldSet::MergeFromAndDestroy(UnknownFieldSet* other) {
other->fields_ = NULL;
}
+void UnknownFieldSet::MergeToInternalMetdata(
+ const UnknownFieldSet& other,
+ internal::InternalMetadataWithArena* metadata) {
+ metadata->mutable_unknown_fields()->MergeFrom(other);
+}
+
int UnknownFieldSet::SpaceUsedExcludingSelf() const {
if (fields_ == NULL) return 0;
@@ -148,7 +155,7 @@ void UnknownFieldSet::AddVarint(int number, uint64 value) {
field.number_ = number;
field.SetType(UnknownField::TYPE_VARINT);
field.varint_ = value;
- if (fields_ == NULL) fields_ = new vector<UnknownField>();
+ if (fields_ == NULL) fields_ = new std::vector<UnknownField>();
fields_->push_back(field);
}
@@ -157,7 +164,7 @@ void UnknownFieldSet::AddFixed32(int number, uint32 value) {
field.number_ = number;
field.SetType(UnknownField::TYPE_FIXED32);
field.fixed32_ = value;
- if (fields_ == NULL) fields_ = new vector<UnknownField>();
+ if (fields_ == NULL) fields_ = new std::vector<UnknownField>();
fields_->push_back(field);
}
@@ -166,7 +173,7 @@ void UnknownFieldSet::AddFixed64(int number, uint64 value) {
field.number_ = number;
field.SetType(UnknownField::TYPE_FIXED64);
field.fixed64_ = value;
- if (fields_ == NULL) fields_ = new vector<UnknownField>();
+ if (fields_ == NULL) fields_ = new std::vector<UnknownField>();
fields_->push_back(field);
}
@@ -175,7 +182,7 @@ string* UnknownFieldSet::AddLengthDelimited(int number) {
field.number_ = number;
field.SetType(UnknownField::TYPE_LENGTH_DELIMITED);
field.length_delimited_.string_value_ = new string;
- if (fields_ == NULL) fields_ = new vector<UnknownField>();
+ if (fields_ == NULL) fields_ = new std::vector<UnknownField>();
fields_->push_back(field);
return field.length_delimited_.string_value_;
}
@@ -186,13 +193,13 @@ UnknownFieldSet* UnknownFieldSet::AddGroup(int number) {
field.number_ = number;
field.SetType(UnknownField::TYPE_GROUP);
field.group_ = new UnknownFieldSet;
- if (fields_ == NULL) fields_ = new vector<UnknownField>();
+ if (fields_ == NULL) fields_ = new std::vector<UnknownField>();
fields_->push_back(field);
return field.group_;
}
void UnknownFieldSet::AddField(const UnknownField& field) {
- if (fields_ == NULL) fields_ = new vector<UnknownField>();
+ if (fields_ == NULL) fields_ = new std::vector<UnknownField>();
fields_->push_back(field);
fields_->back().DeepCopy(field);
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unknown_field_set.h b/third_party/protobuf/src/google/protobuf/unknown_field_set.h
index aa7529165b..c2ad89182d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unknown_field_set.h
+++ b/third_party/protobuf/src/google/protobuf/unknown_field_set.h
@@ -52,6 +52,7 @@ namespace protobuf {
class ZeroCopyInputStream; // zero_copy_stream.h
}
namespace internal {
+ class InternalMetadataWithArena; // metadata.h
class WireFormat; // wire_format.h
class MessageSetFieldSkipperUsingCord;
// extension_set_heavy.cc
@@ -92,6 +93,13 @@ class LIBPROTOBUF_EXPORT UnknownFieldSet {
// Similar to above, but this function will destroy the contents of other.
void MergeFromAndDestroy(UnknownFieldSet* other);
+ // Merge the contents an UnknownFieldSet with the UnknownFieldSet in
+ // *metadata, if there is one. If *metadata doesn't have an UnknownFieldSet
+ // then add one to it and make it be a copy of the first arg.
+ static void MergeToInternalMetdata(
+ const UnknownFieldSet& other,
+ internal::InternalMetadataWithArena* metadata);
+
// Swaps the contents of some other UnknownFieldSet with this one.
inline void Swap(UnknownFieldSet* x);
@@ -175,7 +183,7 @@ class LIBPROTOBUF_EXPORT UnknownField {
TYPE_GROUP
};
- // The field's tag number, as seen on the wire.
+ // The field's field number, as seen on the wire.
inline int number() const;
// The field type.
@@ -204,7 +212,7 @@ class LIBPROTOBUF_EXPORT UnknownField {
void SerializeLengthDelimitedNoTag(io::CodedOutputStream* output) const;
uint8* SerializeLengthDelimitedNoTagToArray(uint8* target) const;
- inline int GetLengthDelimitedSize() const;
+ inline size_t GetLengthDelimitedSize() const;
private:
friend class UnknownFieldSet;
@@ -330,9 +338,9 @@ inline UnknownFieldSet* UnknownField::mutable_group() {
return group_;
}
-inline int UnknownField::GetLengthDelimitedSize() const {
+inline size_t UnknownField::GetLengthDelimitedSize() const {
GOOGLE_DCHECK_EQ(TYPE_LENGTH_DELIMITED, type());
- return static_cast<int>(length_delimited_.string_value_->size());
+ return length_delimited_.string_value_->size();
}
inline void UnknownField::SetType(Type type) {
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/unknown_field_set_unittest.cc b/third_party/protobuf/src/google/protobuf/unknown_field_set_unittest.cc
index 5de72630a6..e55bb01274 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/unknown_field_set_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/unknown_field_set_unittest.cc
@@ -488,7 +488,7 @@ TEST_F(UnknownFieldSetTest, UnknownEnumValue) {
TEST_F(UnknownFieldSetTest, SpaceUsedExcludingSelf) {
UnknownFieldSet empty;
empty.AddVarint(1, 0);
- EXPECT_EQ(sizeof(vector<UnknownField>) + sizeof(UnknownField),
+ EXPECT_EQ(sizeof(std::vector<UnknownField>) + sizeof(UnknownField),
empty.SpaceUsedExcludingSelf());
}
@@ -559,8 +559,9 @@ TEST_F(UnknownFieldSetTest, DeleteSubrange) {
}
}
-void CheckDeleteByNumber(const vector<int>& field_numbers, int deleted_number,
- const vector<int>& expected_field_nubmers) {
+void CheckDeleteByNumber(const std::vector<int>& field_numbers,
+ int deleted_number,
+ const std::vector<int>& expected_field_nubmers) {
UnknownFieldSet unknown_fields;
for (int i = 0; i < field_numbers.size(); ++i) {
unknown_fields.AddFixed32(field_numbers[i], i);
@@ -573,9 +574,9 @@ void CheckDeleteByNumber(const vector<int>& field_numbers, int deleted_number,
}
}
-#define MAKE_VECTOR(x) vector<int>(x, x + GOOGLE_ARRAYSIZE(x))
+#define MAKE_VECTOR(x) std::vector<int>(x, x + GOOGLE_ARRAYSIZE(x))
TEST_F(UnknownFieldSetTest, DeleteByNumber) {
- CheckDeleteByNumber(vector<int>(), 1, vector<int>());
+ CheckDeleteByNumber(std::vector<int>(), 1, std::vector<int>());
static const int kTestFieldNumbers1[] = {1, 2, 3};
static const int kFieldNumberToDelete1 = 1;
static const int kExpectedFieldNumbers1[] = {2, 3};
diff --git a/third_party/protobuf/src/google/protobuf/util/delimited_message_util.cc b/third_party/protobuf/src/google/protobuf/util/delimited_message_util.cc
new file mode 100644
index 0000000000..1637878216
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/util/delimited_message_util.cc
@@ -0,0 +1,79 @@
+// Adapted from the patch of kenton@google.com (Kenton Varda)
+// See https://github.com/google/protobuf/pull/710 for details.
+
+#include <google/protobuf/util/delimited_message_util.h>
+
+namespace google {
+namespace protobuf {
+namespace util {
+
+bool SerializeDelimitedToFileDescriptor(const MessageLite& message, int file_descriptor) {
+ io::FileOutputStream output(file_descriptor);
+ return SerializeDelimitedToZeroCopyStream(message, &output);
+}
+
+bool SerializeDelimitedToOstream(const MessageLite& message, ostream* output) {
+ {
+ io::OstreamOutputStream zero_copy_output(output);
+ if (!SerializeDelimitedToZeroCopyStream(message, &zero_copy_output)) return false;
+ }
+ return output->good();
+}
+
+bool ParseDelimitedFromZeroCopyStream(MessageLite* message, io::ZeroCopyInputStream* input, bool* clean_eof) {
+ google::protobuf::io::CodedInputStream coded_input(input);
+ return ParseDelimitedFromCodedStream(message, &coded_input, clean_eof);
+}
+
+bool ParseDelimitedFromCodedStream(MessageLite* message, io::CodedInputStream* input, bool* clean_eof) {
+ if (clean_eof != NULL) *clean_eof = false;
+ int start = input->CurrentPosition();
+
+ // Read the size.
+ uint32 size;
+ if (!input->ReadVarint32(&size)) {
+ if (clean_eof != NULL) *clean_eof = input->CurrentPosition() == start;
+ return false;
+ }
+
+ // Tell the stream not to read beyond that size.
+ google::protobuf::io::CodedInputStream::Limit limit = input->PushLimit(size);
+
+ // Parse the message.
+ if (!message->MergeFromCodedStream(input)) return false;
+ if (!input->ConsumedEntireMessage()) return false;
+
+ // Release the limit.
+ input->PopLimit(limit);
+
+ return true;
+}
+
+bool SerializeDelimitedToZeroCopyStream(const MessageLite& message, io::ZeroCopyOutputStream* output) {
+ google::protobuf::io::CodedOutputStream coded_output(output);
+ return SerializeDelimitedToCodedStream(message, &coded_output);
+}
+
+bool SerializeDelimitedToCodedStream(const MessageLite& message, io::CodedOutputStream* output) {
+ // Write the size.
+ int size = message.ByteSize();
+ output->WriteVarint32(size);
+
+ // Write the content.
+ uint8* buffer = output->GetDirectBufferForNBytesAndAdvance(size);
+ if (buffer != NULL) {
+ // Optimization: The message fits in one buffer, so use the faster
+ // direct-to-array serialization path.
+ message.SerializeWithCachedSizesToArray(buffer);
+ } else {
+ // Slightly-slower path when the message is multiple buffers.
+ message.SerializeWithCachedSizes(output);
+ if (output->HadError()) return false;
+ }
+
+ return true;
+}
+
+} // namespace util
+} // namespace protobuf
+} // namespace google
diff --git a/third_party/protobuf/src/google/protobuf/util/delimited_message_util.h b/third_party/protobuf/src/google/protobuf/util/delimited_message_util.h
new file mode 100644
index 0000000000..302d4781b3
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/util/delimited_message_util.h
@@ -0,0 +1,66 @@
+// Adapted from the patch of kenton@google.com (Kenton Varda)
+// See https://github.com/google/protobuf/pull/710 for details.
+
+#ifndef GOOGLE_PROTOBUF_UTIL_DELIMITED_MESSAGE_UTIL_H__
+#define GOOGLE_PROTOBUF_UTIL_DELIMITED_MESSAGE_UTIL_H__
+
+#include <ostream>
+
+#include <google/protobuf/message_lite.h>
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/io/zero_copy_stream_impl.h>
+
+namespace google {
+namespace protobuf {
+namespace util {
+
+// Write a single size-delimited message from the given stream. Delimited
+// format allows a single file or stream to contain multiple messages,
+// whereas normally writing multiple non-delimited messages to the same
+// stream would cause them to be merged. A delimited message is a varint
+// encoding the message size followed by a message of exactly that size.
+//
+// Note that if you want to *read* a delimited message from a file descriptor
+// or istream, you will need to construct an io::FileInputStream or
+// io::OstreamInputStream (implementations of io::ZeroCopyStream) and use the
+// utility function ParseDelimitedFromZeroCopyStream(). You must then
+// continue to use the same ZeroCopyInputStream to read all further data from
+// the stream until EOF. This is because these ZeroCopyInputStream
+// implementations are buffered: they read a big chunk of data at a time,
+// then parse it. As a result, they may read past the end of the delimited
+// message. There is no way for them to push the extra data back into the
+// underlying source, so instead you must keep using the same stream object.
+bool LIBPROTOBUF_EXPORT SerializeDelimitedToFileDescriptor(const MessageLite& message, int file_descriptor);
+
+bool LIBPROTOBUF_EXPORT SerializeDelimitedToOstream(const MessageLite& message, ostream* output);
+
+// Read a single size-delimited message from the given stream. Delimited
+// format allows a single file or stream to contain multiple messages,
+// whereas normally parsing consumes the entire input. A delimited message
+// is a varint encoding the message size followed by a message of exactly
+// that size.
+//
+// If |clean_eof| is not NULL, then it will be set to indicate whether the
+// stream ended cleanly. That is, if the stream ends without this method
+// having read any data at all from it, then *clean_eof will be set true,
+// otherwise it will be set false. Note that these methods return false
+// on EOF, but they also return false on other errors, so |clean_eof| is
+// needed to distinguish a clean end from errors.
+bool LIBPROTOBUF_EXPORT ParseDelimitedFromZeroCopyStream(MessageLite* message, io::ZeroCopyInputStream* input, bool* clean_eof);
+
+bool LIBPROTOBUF_EXPORT ParseDelimitedFromCodedStream(MessageLite* message, io::CodedInputStream* input, bool* clean_eof);
+
+// Write a single size-delimited message from the given stream. Delimited
+// format allows a single file or stream to contain multiple messages,
+// whereas normally writing multiple non-delimited messages to the same
+// stream would cause them to be merged. A delimited message is a varint
+// encoding the message size followed by a message of exactly that size.
+bool LIBPROTOBUF_EXPORT SerializeDelimitedToZeroCopyStream(const MessageLite& message, io::ZeroCopyOutputStream* output);
+
+bool LIBPROTOBUF_EXPORT SerializeDelimitedToCodedStream(const MessageLite& message, io::CodedOutputStream* output);
+
+} // namespace util
+} // namespace protobuf
+} // namespace google
+
+#endif // GOOGLE_PROTOBUF_UTIL_DELIMITED_MESSAGE_UTIL_H__
diff --git a/third_party/protobuf/src/google/protobuf/util/delimited_message_util_test.cc b/third_party/protobuf/src/google/protobuf/util/delimited_message_util_test.cc
new file mode 100644
index 0000000000..b261d43cc9
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/util/delimited_message_util_test.cc
@@ -0,0 +1,57 @@
+// Adapted from the patch of kenton@google.com (Kenton Varda)
+// See https://github.com/google/protobuf/pull/710 for details.
+
+#include <google/protobuf/util/delimited_message_util.h>
+
+#include <sstream>
+
+#include <google/protobuf/test_util.h>
+#include <google/protobuf/unittest.pb.h>
+#include <google/protobuf/testing/googletest.h>
+#include <gtest/gtest.h>
+
+namespace google {
+namespace protobuf {
+namespace util {
+
+TEST(DelimitedMessageUtilTest, DelimitedMessages) {
+ stringstream stream;
+
+ {
+ protobuf_unittest::TestAllTypes message1;
+ TestUtil::SetAllFields(&message1);
+ EXPECT_TRUE(SerializeDelimitedToOstream(message1, &stream));
+
+ protobuf_unittest::TestPackedTypes message2;
+ TestUtil::SetPackedFields(&message2);
+ EXPECT_TRUE(SerializeDelimitedToOstream(message2, &stream));
+ }
+
+ {
+ bool clean_eof;
+ io::IstreamInputStream zstream(&stream);
+
+ protobuf_unittest::TestAllTypes message1;
+ clean_eof = true;
+ EXPECT_TRUE(ParseDelimitedFromZeroCopyStream(&message1,
+ &zstream, &clean_eof));
+ EXPECT_FALSE(clean_eof);
+ TestUtil::ExpectAllFieldsSet(message1);
+
+ protobuf_unittest::TestPackedTypes message2;
+ clean_eof = true;
+ EXPECT_TRUE(ParseDelimitedFromZeroCopyStream(&message2,
+ &zstream, &clean_eof));
+ EXPECT_FALSE(clean_eof);
+ TestUtil::ExpectPackedFieldsSet(message2);
+
+ clean_eof = false;
+ EXPECT_FALSE(ParseDelimitedFromZeroCopyStream(&message2,
+ &zstream, &clean_eof));
+ EXPECT_TRUE(clean_eof);
+ }
+}
+
+} // namespace util
+} // namespace protobuf
+} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/field_comparator.cc b/third_party/protobuf/src/google/protobuf/util/field_comparator.cc
index a1a56ee674..a1a56ee674 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/field_comparator.cc
+++ b/third_party/protobuf/src/google/protobuf/util/field_comparator.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/field_comparator.h b/third_party/protobuf/src/google/protobuf/util/field_comparator.h
index 1b4d65b0e6..ad560ebcd6 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/field_comparator.h
+++ b/third_party/protobuf/src/google/protobuf/util/field_comparator.h
@@ -28,7 +28,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Author: ksroka@google.com (Krzysztof Sroka)
+// Defines classes for field comparison.
#ifndef GOOGLE_PROTOBUF_UTIL_FIELD_COMPARATOR_H__
#define GOOGLE_PROTOBUF_UTIL_FIELD_COMPARATOR_H__
@@ -167,7 +167,7 @@ class LIBPROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator {
};
// Defines the map to store the tolerances for floating point comparison.
- typedef map<const FieldDescriptor*, Tolerance> ToleranceMap;
+ typedef std::map<const FieldDescriptor*, Tolerance> ToleranceMap;
// The following methods get executed when CompareFields is called for the
// basic types (instead of submessages). They return true on success. One
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/field_comparator_test.cc b/third_party/protobuf/src/google/protobuf/util/field_comparator_test.cc
index 6fd631d860..249b8d5463 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/field_comparator_test.cc
+++ b/third_party/protobuf/src/google/protobuf/util/field_comparator_test.cc
@@ -365,10 +365,10 @@ TEST_F(DefaultFieldComparatorTest,
// +inf should be equal even though they are not technically within margin or
// fraction.
- message_1_.set_optional_float(numeric_limits<float>::infinity());
- message_2_.set_optional_float(numeric_limits<float>::infinity());
- message_1_.set_optional_double(numeric_limits<double>::infinity());
- message_2_.set_optional_double(numeric_limits<double>::infinity());
+ message_1_.set_optional_float(std::numeric_limits<float>::infinity());
+ message_2_.set_optional_float(std::numeric_limits<float>::infinity());
+ message_1_.set_optional_double(std::numeric_limits<double>::infinity());
+ message_2_.set_optional_double(std::numeric_limits<double>::infinity());
comparator_.SetFractionAndMargin(field_float, 0.0, 0.0);
comparator_.SetFractionAndMargin(field_double, 0.0, 0.0);
EXPECT_EQ(FieldComparator::SAME,
@@ -380,10 +380,10 @@ TEST_F(DefaultFieldComparatorTest,
// -inf should be equal even though they are not technically within margin or
// fraction.
- message_1_.set_optional_float(-numeric_limits<float>::infinity());
- message_2_.set_optional_float(-numeric_limits<float>::infinity());
- message_1_.set_optional_double(-numeric_limits<double>::infinity());
- message_2_.set_optional_double(-numeric_limits<double>::infinity());
+ message_1_.set_optional_float(-std::numeric_limits<float>::infinity());
+ message_2_.set_optional_float(-std::numeric_limits<float>::infinity());
+ message_1_.set_optional_double(-std::numeric_limits<double>::infinity());
+ message_2_.set_optional_double(-std::numeric_limits<double>::infinity());
comparator_.SetFractionAndMargin(field_float, 0.0, 0.0);
comparator_.SetFractionAndMargin(field_double, 0.0, 0.0);
EXPECT_EQ(FieldComparator::SAME,
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/field_mask_util.cc b/third_party/protobuf/src/google/protobuf/util/field_mask_util.cc
index 409010a075..85cecec50f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/field_mask_util.cc
+++ b/third_party/protobuf/src/google/protobuf/util/field_mask_util.cc
@@ -45,7 +45,7 @@ string FieldMaskUtil::ToString(const FieldMask& mask) {
void FieldMaskUtil::FromString(StringPiece str, FieldMask* out) {
out->Clear();
- vector<string> paths = Split(str, ",");
+ std::vector<string> paths = Split(str, ",");
for (int i = 0; i < paths.size(); ++i) {
if (paths[i].empty()) continue;
out->add_paths(paths[i]);
@@ -116,7 +116,7 @@ bool FieldMaskUtil::ToJsonString(const FieldMask& mask, string* out) {
bool FieldMaskUtil::FromJsonString(StringPiece str, FieldMask* out) {
out->Clear();
- vector<string> paths = Split(str, ",");
+ std::vector<string> paths = Split(str, ",");
for (int i = 0; i < paths.size(); ++i) {
if (paths[i].empty()) continue;
string snakecase_path;
@@ -128,9 +128,13 @@ bool FieldMaskUtil::FromJsonString(StringPiece str, FieldMask* out) {
return true;
}
-bool FieldMaskUtil::InternalIsValidPath(const Descriptor* descriptor,
- StringPiece path) {
- vector<string> parts = Split(path, ".");
+bool FieldMaskUtil::GetFieldDescriptors(
+ const Descriptor* descriptor, StringPiece path,
+ std::vector<const FieldDescriptor*>* field_descriptors) {
+ if (field_descriptors != NULL) {
+ field_descriptors->clear();
+ }
+ std::vector<string> parts = Split(path, ".");
for (int i = 0; i < parts.size(); ++i) {
const string& field_name = parts[i];
if (descriptor == NULL) {
@@ -140,6 +144,9 @@ bool FieldMaskUtil::InternalIsValidPath(const Descriptor* descriptor,
if (field == NULL) {
return false;
}
+ if (field_descriptors != NULL) {
+ field_descriptors->push_back(field);
+ }
if (!field->is_repeated() &&
field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
descriptor = field->message_type();
@@ -216,14 +223,14 @@ class FieldMaskTree {
~Node() { ClearChildren(); }
void ClearChildren() {
- for (map<string, Node*>::iterator it = children.begin();
+ for (std::map<string, Node*>::iterator it = children.begin();
it != children.end(); ++it) {
delete it->second;
}
children.clear();
}
- map<string, Node*> children;
+ std::map<string, Node*> children;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Node);
@@ -274,7 +281,7 @@ void FieldMaskTree::MergeToFieldMask(const string& prefix, const Node* node,
out->add_paths(prefix);
return;
}
- for (map<string, Node*>::const_iterator it = node->children.begin();
+ for (std::map<string, Node*>::const_iterator it = node->children.begin();
it != node->children.end(); ++it) {
string current_path = prefix.empty() ? it->first : prefix + "." + it->first;
MergeToFieldMask(current_path, it->second, out);
@@ -282,7 +289,7 @@ void FieldMaskTree::MergeToFieldMask(const string& prefix, const Node* node,
}
void FieldMaskTree::AddPath(const string& path) {
- vector<string> parts = Split(path, ".");
+ std::vector<string> parts = Split(path, ".");
if (parts.empty()) {
return;
}
@@ -309,7 +316,7 @@ void FieldMaskTree::AddPath(const string& path) {
}
void FieldMaskTree::IntersectPath(const string& path, FieldMaskTree* out) {
- vector<string> parts = Split(path, ".");
+ std::vector<string> parts = Split(path, ".");
if (parts.empty()) {
return;
}
@@ -339,7 +346,7 @@ void FieldMaskTree::MergeLeafNodesToTree(const string& prefix, const Node* node,
if (node->children.empty()) {
out->AddPath(prefix);
}
- for (map<string, Node*>::const_iterator it = node->children.begin();
+ for (std::map<string, Node*>::const_iterator it = node->children.begin();
it != node->children.end(); ++it) {
string current_path = prefix.empty() ? it->first : prefix + "." + it->first;
MergeLeafNodesToTree(current_path, it->second, out);
@@ -353,7 +360,7 @@ void FieldMaskTree::MergeMessage(const Node* node, const Message& source,
const Reflection* source_reflection = source.GetReflection();
const Reflection* destination_reflection = destination->GetReflection();
const Descriptor* descriptor = source.GetDescriptor();
- for (map<string, Node*>::const_iterator it = node->children.begin();
+ for (std::map<string, Node*>::const_iterator it = node->children.begin();
it != node->children.end(); ++it) {
const string& field_name = it->first;
const Node* child = it->second;
@@ -456,11 +463,13 @@ void FieldMaskTree::TrimMessage(const Node* node, Message* message) {
const int32 field_count = descriptor->field_count();
for (int index = 0; index < field_count; ++index) {
const FieldDescriptor* field = descriptor->field(index);
- if (!ContainsKey(node->children, field->name())) {
+ std::map<string, Node*>::const_iterator it =
+ node->children.find(field->name());
+ if (it == node->children.end()) {
reflection->ClearField(message, field);
} else {
if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
- Node* child = node->children.at(field->name());
+ Node* child = it->second;
if (!child->children.empty()) {
TrimMessage(child, reflection->MutableMessage(message, field));
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/field_mask_util.h b/third_party/protobuf/src/google/protobuf/util/field_mask_util.h
index e79b65e94e..ab1f2e94c3 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/field_mask_util.h
+++ b/third_party/protobuf/src/google/protobuf/util/field_mask_util.h
@@ -28,6 +28,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// Defines utilities for the FieldMask well known type.
+
#ifndef GOOGLE_PROTOBUF_UTIL_FIELD_MASK_UTIL_H__
#define GOOGLE_PROTOBUF_UTIL_FIELD_MASK_UTIL_H__
@@ -57,17 +59,26 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil {
static bool ToJsonString(const FieldMask& mask, string* out);
static bool FromJsonString(StringPiece str, FieldMask* out);
+ // Get the descriptors of the fields which the given path from the message
+ // descriptor traverses, if field_descriptors is not null.
+ // Return false if the path is not valid, and the content of field_descriptors
+ // is unspecified.
+ static bool GetFieldDescriptors(
+ const Descriptor* descriptor, StringPiece path,
+ std::vector<const FieldDescriptor*>* field_descriptors);
+
// Checks whether the given path is valid for type T.
template <typename T>
static bool IsValidPath(StringPiece path) {
- return InternalIsValidPath(T::descriptor(), path);
+ return GetFieldDescriptors(T::descriptor(), path, NULL);
}
// Checks whether the given FieldMask is valid for type T.
template <typename T>
static bool IsValidFieldMask(const FieldMask& mask) {
for (int i = 0; i < mask.paths_size(); ++i) {
- if (!InternalIsValidPath(T::descriptor(), mask.paths(i))) return false;
+ if (!GetFieldDescriptors(T::descriptor(), mask.paths(i), NULL))
+ return false;
}
return true;
}
@@ -147,9 +158,6 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil {
// successfully.
static bool CamelCaseToSnakeCase(StringPiece input, string* output);
- static bool InternalIsValidPath(const Descriptor* descriptor,
- StringPiece path);
-
static void InternalGetFieldMaskForAllFields(const Descriptor* descriptor,
FieldMask* out);
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/field_mask_util_test.cc b/third_party/protobuf/src/google/protobuf/util/field_mask_util_test.cc
index 43fb79057a..f952786ff5 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/field_mask_util_test.cc
+++ b/third_party/protobuf/src/google/protobuf/util/field_mask_util_test.cc
@@ -159,6 +159,27 @@ TEST(FieldMaskUtilTest, JsonStringFormat) {
EXPECT_EQ("baz_quz", mask.paths(1));
}
+TEST(FieldMaskUtilTest, GetFieldDescriptors) {
+ std::vector<const FieldDescriptor*> field_descriptors;
+ EXPECT_TRUE(FieldMaskUtil::GetFieldDescriptors(
+ TestAllTypes::descriptor(), "optional_int32", &field_descriptors));
+ EXPECT_EQ(1, field_descriptors.size());
+ EXPECT_EQ("optional_int32", field_descriptors[0]->name());
+ EXPECT_FALSE(FieldMaskUtil::GetFieldDescriptors(
+ TestAllTypes::descriptor(), "optional_nonexist", NULL));
+ EXPECT_TRUE(FieldMaskUtil::GetFieldDescriptors(TestAllTypes::descriptor(),
+ "optional_nested_message.bb",
+ &field_descriptors));
+ EXPECT_EQ(2, field_descriptors.size());
+ EXPECT_EQ("optional_nested_message", field_descriptors[0]->name());
+ EXPECT_EQ("bb", field_descriptors[1]->name());
+ EXPECT_FALSE(FieldMaskUtil::GetFieldDescriptors(
+ TestAllTypes::descriptor(), "optional_nested_message.nonexist", NULL));
+ // FieldMask cannot be used to specify sub-fields of a repeated message.
+ EXPECT_FALSE(FieldMaskUtil::GetFieldDescriptors(
+ TestAllTypes::descriptor(), "repeated_nested_message.bb", NULL));
+}
+
TEST(FieldMaskUtilTest, TestIsVaildPath) {
EXPECT_TRUE(FieldMaskUtil::IsValidPath<TestAllTypes>("optional_int32"));
EXPECT_FALSE(FieldMaskUtil::IsValidPath<TestAllTypes>("optional_nonexist"));
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/constants.h b/third_party/protobuf/src/google/protobuf/util/internal/constants.h
index e556888cca..a018a09ef7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/constants.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/constants.h
@@ -50,16 +50,16 @@ const char kRfc3339TimeFormat[] = "%E4Y-%m-%dT%H:%M:%S";
const char kRfc3339TimeFormatNoPadding[] = "%Y-%m-%dT%H:%M:%S";
// Minimun seconds allowed in a google.protobuf.Timestamp value.
-const int64 kTimestampMinSeconds = -62135596800;
+const int64 kTimestampMinSeconds = -62135596800LL;
// Maximum seconds allowed in a google.protobuf.Timestamp value.
-const int64 kTimestampMaxSeconds = 253402300799;
+const int64 kTimestampMaxSeconds = 253402300799LL;
// Minimum seconds allowed in a google.protobuf.Duration value.
-const int64 kDurationMinSeconds = -315576000000;
+const int64 kDurationMinSeconds = -315576000000LL;
// Maximum seconds allowed in a google.protobuf.Duration value.
-const int64 kDurationMaxSeconds = 315576000000;
+const int64 kDurationMaxSeconds = 315576000000LL;
// Nano seconds in a second.
const int32 kNanosPerSecond = 1000000000;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/datapiece.cc b/third_party/protobuf/src/google/protobuf/util/internal/datapiece.cc
index ef8da4279f..213c2c40c0 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/datapiece.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/datapiece.cc
@@ -94,19 +94,24 @@ StatusOr<To> FloatingPointToIntConvertAndCheck(From before) {
}
// For conversion between double and float only.
-template <typename To, typename From>
-StatusOr<To> FloatingPointConvertAndCheck(From before) {
- if (MathLimits<From>::IsNaN(before)) {
- return std::numeric_limits<To>::quiet_NaN();
- }
+StatusOr<double> FloatToDouble(float before) {
+ // Casting float to double should just work as double has more precision
+ // than float.
+ return static_cast<double>(before);
+}
- To after = static_cast<To>(before);
- if (MathUtil::AlmostEquals<To>(after, before)) {
- return after;
+StatusOr<float> DoubleToFloat(double before) {
+ if (MathLimits<double>::IsNaN(before)) {
+ return std::numeric_limits<float>::quiet_NaN();
+ } else if (!MathLimits<double>::IsFinite(before)) {
+ // Converting a double +inf/-inf to float should just work.
+ return static_cast<float>(before);
+ } else if (before > std::numeric_limits<float>::max() ||
+ before < -std::numeric_limits<float>::max()) {
+ // Double value outside of the range of float.
+ return InvalidArgument(DoubleAsString(before));
} else {
- return InvalidArgument(::google::protobuf::internal::is_same<From, double>::value
- ? DoubleAsString(before)
- : FloatAsString(before));
+ return static_cast<float>(before);
}
}
@@ -162,20 +167,27 @@ StatusOr<uint64> DataPiece::ToUint64() const {
StatusOr<double> DataPiece::ToDouble() const {
if (type_ == TYPE_FLOAT) {
- return FloatingPointConvertAndCheck<double, float>(float_);
+ return FloatToDouble(float_);
}
if (type_ == TYPE_STRING) {
if (str_ == "Infinity") return std::numeric_limits<double>::infinity();
if (str_ == "-Infinity") return -std::numeric_limits<double>::infinity();
if (str_ == "NaN") return std::numeric_limits<double>::quiet_NaN();
- return StringToNumber<double>(safe_strtod);
+ StatusOr<double> value = StringToNumber<double>(safe_strtod);
+ if (value.ok() && !MathLimits<double>::IsFinite(value.ValueOrDie())) {
+ // safe_strtod converts out-of-range values to +inf/-inf, but we want
+ // to report them as errors.
+ return InvalidArgument(StrCat("\"", str_, "\""));
+ } else {
+ return value;
+ }
}
return GenericConvert<double>();
}
StatusOr<float> DataPiece::ToFloat() const {
if (type_ == TYPE_DOUBLE) {
- return FloatingPointConvertAndCheck<float, double>(double_);
+ return DoubleToFloat(double_);
}
if (type_ == TYPE_STRING) {
if (str_ == "Infinity") return std::numeric_limits<float>::infinity();
@@ -259,7 +271,8 @@ StatusOr<string> DataPiece::ToBytes() const {
}
}
-StatusOr<int> DataPiece::ToEnum(const google::protobuf::Enum* enum_type) const {
+StatusOr<int> DataPiece::ToEnum(const google::protobuf::Enum* enum_type,
+ bool use_lower_camel_for_enums) const {
if (type_ == TYPE_NULL) return google::protobuf::NULL_VALUE;
if (type_ == TYPE_STRING) {
@@ -268,20 +281,34 @@ StatusOr<int> DataPiece::ToEnum(const google::protobuf::Enum* enum_type) const {
const google::protobuf::EnumValue* value =
FindEnumValueByNameOrNull(enum_type, enum_name);
if (value != NULL) return value->number();
+
+ // Check if int version of enum is sent as string.
+ StatusOr<int32> int_value = ToInt32();
+ if (int_value.ok()) {
+ if (const google::protobuf::EnumValue* enum_value =
+ FindEnumValueByNumberOrNull(enum_type, int_value.ValueOrDie())) {
+ return enum_value->number();
+ }
+ }
+
// Next try a normalized name.
for (string::iterator it = enum_name.begin(); it != enum_name.end(); ++it) {
*it = *it == '-' ? '_' : ascii_toupper(*it);
}
value = FindEnumValueByNameOrNull(enum_type, enum_name);
if (value != NULL) return value->number();
- } else {
- StatusOr<int32> value = ToInt32();
- if (value.ok()) {
- if (const google::protobuf::EnumValue* enum_value =
- FindEnumValueByNumberOrNull(enum_type, value.ValueOrDie())) {
- return enum_value->number();
- }
+
+ // If use_lower_camel_for_enums is true try with enum name without
+ // underscore. This will also accept camel case names as the enum_name has
+ // been normalized before.
+ if (use_lower_camel_for_enums) {
+ value = FindEnumValueByNameWithoutUnderscoreOrNull(enum_type, enum_name);
+ if (value != NULL) return value->number();
}
+ } else {
+ // We don't need to check whether the value is actually declared in the
+ // enum because we preserve unknown enum values as well.
+ return ToInt32();
}
return InvalidArgument(
ValueAsStringOrDefault("Cannot find enum with given value."));
@@ -354,6 +381,7 @@ bool DataPiece::DecodeBase64(StringPiece src, string* dest) const {
void DataPiece::InternalCopy(const DataPiece& other) {
type_ = other.type_;
+ use_strict_base64_decoding_ = other.use_strict_base64_decoding_;
switch (type_) {
case TYPE_INT32:
case TYPE_INT64:
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/datapiece.h b/third_party/protobuf/src/google/protobuf/util/internal/datapiece.h
index e82cdbacbf..83516d0972 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/datapiece.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/datapiece.h
@@ -76,13 +76,22 @@ class LIBPROTOBUF_EXPORT DataPiece {
};
// Constructors and Destructor
- explicit DataPiece(const int32 value) : type_(TYPE_INT32), i32_(value) {}
- explicit DataPiece(const int64 value) : type_(TYPE_INT64), i64_(value) {}
- explicit DataPiece(const uint32 value) : type_(TYPE_UINT32), u32_(value) {}
- explicit DataPiece(const uint64 value) : type_(TYPE_UINT64), u64_(value) {}
- explicit DataPiece(const double value) : type_(TYPE_DOUBLE), double_(value) {}
- explicit DataPiece(const float value) : type_(TYPE_FLOAT), float_(value) {}
- explicit DataPiece(const bool value) : type_(TYPE_BOOL), bool_(value) {}
+ explicit DataPiece(const int32 value)
+ : type_(TYPE_INT32), i32_(value), use_strict_base64_decoding_(false) {}
+ explicit DataPiece(const int64 value)
+ : type_(TYPE_INT64), i64_(value), use_strict_base64_decoding_(false) {}
+ explicit DataPiece(const uint32 value)
+ : type_(TYPE_UINT32), u32_(value), use_strict_base64_decoding_(false) {}
+ explicit DataPiece(const uint64 value)
+ : type_(TYPE_UINT64), u64_(value), use_strict_base64_decoding_(false) {}
+ explicit DataPiece(const double value)
+ : type_(TYPE_DOUBLE),
+ double_(value),
+ use_strict_base64_decoding_(false) {}
+ explicit DataPiece(const float value)
+ : type_(TYPE_FLOAT), float_(value), use_strict_base64_decoding_(false) {}
+ explicit DataPiece(const bool value)
+ : type_(TYPE_BOOL), bool_(value), use_strict_base64_decoding_(false) {}
DataPiece(StringPiece value, bool use_strict_base64_decoding)
: type_(TYPE_STRING),
str_(StringPiecePod::CreateFromStringPiece(value)),
@@ -108,6 +117,8 @@ class LIBPROTOBUF_EXPORT DataPiece {
// Accessors
Type type() const { return type_; }
+ bool use_strict_base64_decoding() { return use_strict_base64_decoding_; }
+
StringPiece str() const {
GOOGLE_LOG_IF(DFATAL, type_ != TYPE_STRING) << "Not a string type.";
return str_;
@@ -148,16 +159,20 @@ class LIBPROTOBUF_EXPORT DataPiece {
// string, first attempts conversion by name, trying names as follows:
// 1) the directly provided string value.
// 2) the value upper-cased and replacing '-' by '_'
+ // 3) if use_lower_camel_for_enums is true it also attempts by comparing
+ // enum name without underscore with the value upper cased above.
// If the value is not a string, attempts to convert to a 32-bit integer.
// If none of these succeeds, returns a conversion error status.
- util::StatusOr<int> ToEnum(const google::protobuf::Enum* enum_type) const;
+ util::StatusOr<int> ToEnum(const google::protobuf::Enum* enum_type,
+ bool use_lower_camel_for_enums) const;
private:
// Disallow implicit constructor.
DataPiece();
// Helper to create NULL or ENUM types.
- DataPiece(Type type, int32 val) : type_(type), i32_(val) {}
+ DataPiece(Type type, int32 val)
+ : type_(type), i32_(val), use_strict_base64_decoding_(false) {}
// For numeric conversion between
// int32, int64, uint32, uint64, double, float and bool
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/default_value_objectwriter.cc b/third_party/protobuf/src/google/protobuf/util/internal/default_value_objectwriter.cc
index 1e8dab701a..b33ad20699 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/default_value_objectwriter.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/default_value_objectwriter.cc
@@ -65,6 +65,7 @@ DefaultValueObjectWriter::DefaultValueObjectWriter(
current_(NULL),
root_(NULL),
suppress_empty_list_(false),
+ preserve_proto_field_names_(false),
field_scrub_callback_(NULL),
ow_(ow) {}
@@ -165,7 +166,10 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::RenderBytes(
if (current_ == NULL) {
ow_->RenderBytes(name, value);
} else {
- RenderDataPiece(name, DataPiece(value, false, true));
+ // Since StringPiece is essentially a pointer, takes a copy of "value" to
+ // avoid ownership issues.
+ string_values_.push_back(new string(value.ToString()));
+ RenderDataPiece(name, DataPiece(*string_values_.back(), false, true));
}
return this;
}
@@ -187,8 +191,9 @@ void DefaultValueObjectWriter::RegisterFieldScrubCallBack(
DefaultValueObjectWriter::Node::Node(
const string& name, const google::protobuf::Type* type, NodeKind kind,
- const DataPiece& data, bool is_placeholder, const vector<string>& path,
- bool suppress_empty_list, FieldScrubCallBack* field_scrub_callback)
+ const DataPiece& data, bool is_placeholder, const std::vector<string>& path,
+ bool suppress_empty_list, bool preserve_proto_field_names,
+ FieldScrubCallBack* field_scrub_callback)
: name_(name),
type_(type),
kind_(kind),
@@ -197,6 +202,7 @@ DefaultValueObjectWriter::Node::Node(
is_placeholder_(is_placeholder),
path_(path),
suppress_empty_list_(suppress_empty_list),
+ preserve_proto_field_names_(preserve_proto_field_names),
field_scrub_callback_(field_scrub_callback) {}
DefaultValueObjectWriter::Node* DefaultValueObjectWriter::Node::FindChild(
@@ -307,7 +313,7 @@ void DefaultValueObjectWriter::Node::PopulateChildren(
// This code is checking if the field to be added to the tree should be
// scrubbed or not by calling the field_scrub_callback_ callback function.
- vector<string> path;
+ std::vector<string> path;
if (!path_.empty()) {
path.insert(path.begin(), path_.begin(), path_.end());
}
@@ -360,16 +366,19 @@ void DefaultValueObjectWriter::Node::PopulateChildren(
}
// If oneof_index() != 0, the child field is part of a "oneof", which means
- // the child field is optional and we shouldn't populate its default value.
- if (field.oneof_index() != 0) continue;
+ // the child field is optional and we shouldn't populate its default
+ // primitive value.
+ if (field.oneof_index() != 0 && kind == PRIMITIVE) continue;
// If the child field is of primitive type, sets its data to the default
// value of its type.
google::protobuf::scoped_ptr<Node> child(new Node(
- field.json_name(), field_type, kind,
+ preserve_proto_field_names_ ? field.name() : field.json_name(),
+ field_type, kind,
kind == PRIMITIVE ? CreateDefaultDataPieceForField(field, typeinfo)
: DataPiece::NullData(),
- true, path, suppress_empty_list_, field_scrub_callback_));
+ true, path, suppress_empty_list_, preserve_proto_field_names_,
+ field_scrub_callback_));
new_children.push_back(child.release());
}
// Adds all leftover nodes in children_ to the beginning of new_child.
@@ -463,9 +472,10 @@ DataPiece DefaultValueObjectWriter::CreateDefaultDataPieceForField(
DefaultValueObjectWriter* DefaultValueObjectWriter::StartObject(
StringPiece name) {
if (current_ == NULL) {
- vector<string> path;
+ std::vector<string> path;
root_.reset(new Node(name.ToString(), &type_, OBJECT, DataPiece::NullData(),
false, path, suppress_empty_list_,
+ preserve_proto_field_names_,
field_scrub_callback_.get()));
root_->PopulateChildren(typeinfo_);
current_ = root_.get();
@@ -482,7 +492,8 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::StartObject(
: NULL),
OBJECT, DataPiece::NullData(), false,
child == NULL ? current_->path() : child->path(),
- suppress_empty_list_, field_scrub_callback_.get()));
+ suppress_empty_list_, preserve_proto_field_names_,
+ field_scrub_callback_.get()));
child = node.get();
current_->AddChild(node.release());
}
@@ -511,9 +522,10 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::EndObject() {
DefaultValueObjectWriter* DefaultValueObjectWriter::StartList(
StringPiece name) {
if (current_ == NULL) {
- vector<string> path;
+ std::vector<string> path;
root_.reset(new Node(name.ToString(), &type_, LIST, DataPiece::NullData(),
false, path, suppress_empty_list_,
+ preserve_proto_field_names_,
field_scrub_callback_.get()));
current_ = root_.get();
return this;
@@ -524,7 +536,8 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::StartList(
google::protobuf::scoped_ptr<Node> node(
new Node(name.ToString(), NULL, LIST, DataPiece::NullData(), false,
child == NULL ? current_->path() : child->path(),
- suppress_empty_list_, field_scrub_callback_.get()));
+ suppress_empty_list_, preserve_proto_field_names_,
+ field_scrub_callback_.get()));
child = node.get();
current_->AddChild(node.release());
}
@@ -554,26 +567,29 @@ DefaultValueObjectWriter* DefaultValueObjectWriter::EndList() {
void DefaultValueObjectWriter::RenderDataPiece(StringPiece name,
const DataPiece& data) {
MaybePopulateChildrenOfAny(current_);
- util::StatusOr<string> data_string = data.ToString();
if (current_->type() != NULL && current_->type()->name() == kAnyType &&
- name == "@type" && data_string.ok()) {
- const string& string_value = data_string.ValueOrDie();
- // If the type of current_ is "Any" and its "@type" field is being set here,
- // sets the type of current_ to be the type specified by the "@type".
- util::StatusOr<const google::protobuf::Type*> found_type =
- typeinfo_->ResolveTypeUrl(string_value);
- if (!found_type.ok()) {
- GOOGLE_LOG(WARNING) << "Failed to resolve type '" << string_value << "'.";
- } else {
- current_->set_type(found_type.ValueOrDie());
- }
- current_->set_is_any(true);
- // If the "@type" field is placed after other fields, we should populate
- // other children of primitive type now. Otherwise, we should wait until the
- // first value field is rendered before we populate the children, because
- // the "value" field of a Any message could be omitted.
- if (current_->number_of_children() > 1 && current_->type() != NULL) {
- current_->PopulateChildren(typeinfo_);
+ name == "@type") {
+ util::StatusOr<string> data_string = data.ToString();
+ if (data_string.ok()) {
+ const string& string_value = data_string.ValueOrDie();
+ // If the type of current_ is "Any" and its "@type" field is being set
+ // here, sets the type of current_ to be the type specified by the
+ // "@type".
+ util::StatusOr<const google::protobuf::Type*> found_type =
+ typeinfo_->ResolveTypeUrl(string_value);
+ if (!found_type.ok()) {
+ GOOGLE_LOG(WARNING) << "Failed to resolve type '" << string_value << "'.";
+ } else {
+ current_->set_type(found_type.ValueOrDie());
+ }
+ current_->set_is_any(true);
+ // If the "@type" field is placed after other fields, we should populate
+ // other children of primitive type now. Otherwise, we should wait until
+ // the first value field is rendered before we populate the children,
+ // because the "value" field of a Any message could be omitted.
+ if (current_->number_of_children() > 1 && current_->type() != NULL) {
+ current_->PopulateChildren(typeinfo_);
+ }
}
}
Node* child = current_->FindChild(name);
@@ -582,8 +598,8 @@ void DefaultValueObjectWriter::RenderDataPiece(StringPiece name,
google::protobuf::scoped_ptr<Node> node(
new Node(name.ToString(), NULL, PRIMITIVE, data, false,
child == NULL ? current_->path() : child->path(),
- suppress_empty_list_, field_scrub_callback_.get()));
- child = node.get();
+ suppress_empty_list_, preserve_proto_field_names_,
+ field_scrub_callback_.get()));
current_->AddChild(node.release());
} else {
child->set_data(data);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/default_value_objectwriter.h b/third_party/protobuf/src/google/protobuf/util/internal/default_value_objectwriter.h
index 5f3b25f378..ddf2359408 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/default_value_objectwriter.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/default_value_objectwriter.h
@@ -126,6 +126,9 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
// are written.
void set_suppress_empty_list(bool value) { suppress_empty_list_ = value; }
+ // If set to true, original proto field names are used
+ void set_preserve_proto_field_names(bool value) { preserve_proto_field_names_ = value; }
+
private:
enum NodeKind {
PRIMITIVE = 0,
@@ -139,8 +142,9 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
class LIBPROTOBUF_EXPORT Node {
public:
Node(const string& name, const google::protobuf::Type* type, NodeKind kind,
- const DataPiece& data, bool is_placeholder, const vector<string>& path,
- bool suppress_empty_list, FieldScrubCallBack* field_scrub_callback);
+ const DataPiece& data, bool is_placeholder,
+ const std::vector<string>& path, bool suppress_empty_list,
+ bool preserve_proto_field_names, FieldScrubCallBack* field_scrub_callback);
virtual ~Node() {
for (int i = 0; i < children_.size(); ++i) {
delete children_[i];
@@ -166,7 +170,7 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
// Accessors
const string& name() const { return name_; }
- const vector<string>& path() const { return path_; }
+ const std::vector<string>& path() const { return path_; }
const google::protobuf::Type* type() const { return type_; }
@@ -219,6 +223,9 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
// Whether to suppress empty list output.
bool suppress_empty_list_;
+ // Whether to preserve original proto field names
+ bool preserve_proto_field_names_;
+
// Pointer to function for determining whether a field needs to be scrubbed
// or not. This callback is owned by the creator of this node.
FieldScrubCallBack* field_scrub_callback_;
@@ -255,7 +262,7 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
// google::protobuf::Type of the root message type.
const google::protobuf::Type& type_;
// Holds copies of strings passed to RenderString.
- vector<string*> string_values_;
+ std::vector<string*> string_values_;
// The current Node. Owned by its parents.
Node* current_;
@@ -267,6 +274,9 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
// Whether to suppress output of empty lists.
bool suppress_empty_list_;
+ // Whether to preserve original proto field names
+ bool preserve_proto_field_names_;
+
// Unique Pointer to function for determining whether a field needs to be
// scrubbed or not.
FieldScrubCallBackPtr field_scrub_callback_;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/default_value_objectwriter_test.cc b/third_party/protobuf/src/google/protobuf/util/internal/default_value_objectwriter_test.cc
index e1dd697aec..e1dd697aec 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/default_value_objectwriter_test.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/default_value_objectwriter_test.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/error_listener.cc b/third_party/protobuf/src/google/protobuf/util/internal/error_listener.cc
index 538307bae2..538307bae2 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/error_listener.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/error_listener.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/error_listener.h b/third_party/protobuf/src/google/protobuf/util/internal/error_listener.h
index 3f0639364c..1dc814a360 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/error_listener.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/error_listener.h
@@ -57,7 +57,7 @@ class LIBPROTOBUF_EXPORT ErrorListener {
// Reports an invalid name at the given location.
virtual void InvalidName(const LocationTrackerInterface& loc,
- StringPiece unknown_name, StringPiece message) = 0;
+ StringPiece invalid_name, StringPiece message) = 0;
// Reports an invalid value for a field.
virtual void InvalidValue(const LocationTrackerInterface& loc,
@@ -82,7 +82,7 @@ class LIBPROTOBUF_EXPORT NoopErrorListener : public ErrorListener {
virtual ~NoopErrorListener() {}
virtual void InvalidName(const LocationTrackerInterface& loc,
- StringPiece unknown_name, StringPiece message) {}
+ StringPiece invalid_name, StringPiece message) {}
virtual void InvalidValue(const LocationTrackerInterface& loc,
StringPiece type_name, StringPiece value) {}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/expecting_objectwriter.h b/third_party/protobuf/src/google/protobuf/util/internal/expecting_objectwriter.h
index ae98ddd86a..ae98ddd86a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/expecting_objectwriter.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/expecting_objectwriter.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/field_mask_utility.cc b/third_party/protobuf/src/google/protobuf/util/internal/field_mask_utility.cc
index f0e8fc88a4..53b90fb05d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/field_mask_utility.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/field_mask_utility.cc
@@ -112,7 +112,7 @@ string ConvertFieldMaskPath(const StringPiece path,
util::Status DecodeCompactFieldMaskPaths(StringPiece paths,
PathSinkCallback path_sink) {
- stack<string> prefix;
+ std::stack<string> prefix;
int length = paths.length();
int previous_position = 0;
bool in_map_key = false;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/field_mask_utility.h b/third_party/protobuf/src/google/protobuf/util/internal/field_mask_utility.h
index 59f36f756f..59f36f756f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/field_mask_utility.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/field_mask_utility.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_escaping.cc b/third_party/protobuf/src/google/protobuf/util/internal/json_escaping.cc
index 06d2791bf2..47e4dd6df9 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_escaping.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/json_escaping.cc
@@ -336,19 +336,19 @@ StringPiece EscapeCodePoint(uint32 cp, char* buffer, bool force_output) {
cp >>= 6;
if (cp <= 0x1f) {
buffer[4] = cp | 0xc0;
- sp.set(buffer + 4, 2);
+ sp = StringPiece(buffer + 4, 2);
return sp;
}
buffer[4] = (cp & 0x3f) | 0x80;
cp >>= 6;
if (cp <= 0x0f) {
buffer[3] = cp | 0xe0;
- sp.set(buffer + 3, 3);
+ sp = StringPiece(buffer + 3, 3);
return sp;
}
buffer[3] = (cp & 0x3f) | 0x80;
buffer[2] = ((cp >> 6) & 0x07) | 0xf0;
- sp.set(buffer + 2, 4);
+ sp = StringPiece(buffer + 2, 4);
}
return sp;
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_escaping.h b/third_party/protobuf/src/google/protobuf/util/internal/json_escaping.h
index e3e329fc96..e3e329fc96 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_escaping.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/json_escaping.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_objectwriter.cc b/third_party/protobuf/src/google/protobuf/util/internal/json_objectwriter.cc
index b84210c10b..6e4edd8836 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_objectwriter.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/json_objectwriter.cc
@@ -147,7 +147,7 @@ JsonObjectWriter* JsonObjectWriter::RenderBytes(StringPiece name,
string base64;
if (use_websafe_base64_for_bytes_)
- WebSafeBase64Escape(value.ToString(), &base64);
+ WebSafeBase64EscapeWithPadding(value.ToString(), &base64);
else
Base64Escape(value, &base64);
@@ -164,19 +164,32 @@ JsonObjectWriter* JsonObjectWriter::RenderNull(StringPiece name) {
return RenderSimple(name, "null");
}
+JsonObjectWriter* JsonObjectWriter::RenderNullAsEmpty(StringPiece name) {
+ return RenderSimple(name, "");
+}
+
void JsonObjectWriter::WritePrefix(StringPiece name) {
bool not_first = !element()->is_first();
if (not_first) WriteChar(',');
if (not_first || !element()->is_root()) NewLine();
- if (!name.empty()) {
+ bool empty_key_ok = GetAndResetEmptyKeyOk();
+ if (!name.empty() || empty_key_ok) {
WriteChar('"');
- ArrayByteSource source(name);
- JsonEscaping::Escape(&source, &sink_);
+ if (!name.empty()) {
+ ArrayByteSource source(name);
+ JsonEscaping::Escape(&source, &sink_);
+ }
stream_->WriteString("\":");
if (!indent_string_.empty()) WriteChar(' ');
}
}
+bool JsonObjectWriter::GetAndResetEmptyKeyOk() {
+ bool retval = empty_name_ok_for_next_key_;
+ empty_name_ok_for_next_key_ = false;
+ return retval;
+}
+
} // namespace converter
} // namespace util
} // namespace protobuf
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_objectwriter.h b/third_party/protobuf/src/google/protobuf/util/internal/json_objectwriter.h
index cb7e2fb30c..31edc2927f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_objectwriter.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/json_objectwriter.h
@@ -93,7 +93,8 @@ class LIBPROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter {
stream_(out),
sink_(out),
indent_string_(indent_string.ToString()),
- use_websafe_base64_for_bytes_(false) {}
+ use_websafe_base64_for_bytes_(false),
+ empty_name_ok_for_next_key_(false) {}
virtual ~JsonObjectWriter();
// ObjectWriter methods.
@@ -111,11 +112,19 @@ class LIBPROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter {
virtual JsonObjectWriter* RenderString(StringPiece name, StringPiece value);
virtual JsonObjectWriter* RenderBytes(StringPiece name, StringPiece value);
virtual JsonObjectWriter* RenderNull(StringPiece name);
+ virtual JsonObjectWriter* RenderNullAsEmpty(StringPiece name);
void set_use_websafe_base64_for_bytes(bool value) {
use_websafe_base64_for_bytes_ = value;
}
+ // Whether empty strings should be rendered for the next JSON key. This
+ // setting is only valid until the next key is rendered, after which it gets
+ // reset to false.
+ virtual void empty_name_ok_for_next_key() {
+ empty_name_ok_for_next_key_ = true;
+ }
+
protected:
class LIBPROTOBUF_EXPORT Element : public BaseElement {
public:
@@ -195,6 +204,10 @@ class LIBPROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter {
// Writes an individual character to the output.
void WriteChar(const char c) { stream_->WriteRaw(&c, sizeof(c)); }
+ // Returns the current value of empty_name_ok_for_next_key_ and resets it to
+ // false.
+ bool GetAndResetEmptyKeyOk();
+
google::protobuf::scoped_ptr<Element> element_;
google::protobuf::io::CodedOutputStream* stream_;
ByteSinkWrapper sink_;
@@ -204,6 +217,11 @@ class LIBPROTOBUF_EXPORT JsonObjectWriter : public StructuredObjectWriter {
// to regular base64 encoding.
bool use_websafe_base64_for_bytes_;
+ // Whether empty strings should be rendered for the next JSON key. This
+ // setting is only valid until the next key is rendered, after which it gets
+ // reset to false.
+ bool empty_name_ok_for_next_key_;
+
GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(JsonObjectWriter);
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_objectwriter_test.cc b/third_party/protobuf/src/google/protobuf/util/internal/json_objectwriter_test.cc
index b87b06ac78..bbd9d78a43 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_objectwriter_test.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/json_objectwriter_test.cc
@@ -299,11 +299,11 @@ TEST_F(JsonObjectWriterTest, TestWebsafeByteEncoding) {
ow_ = new JsonObjectWriter("", out_stream_);
ow_->set_use_websafe_base64_for_bytes(true);
ow_->StartObject("")
- ->RenderBytes("bytes", "\x03\xef\xc0")
+ ->RenderBytes("bytes", "\x03\xef\xc0\x10")
->EndObject();
// Test that we get websafe base64 encoding when explicitly asked.
- EXPECT_EQ("{\"bytes\":\"A-_A\"}",
+ EXPECT_EQ("{\"bytes\":\"A-_AEA==\"}",
output_.substr(0, out_stream_->ByteCount()));
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_stream_parser.cc b/third_party/protobuf/src/google/protobuf/util/internal/json_stream_parser.cc
index 39be7b0390..b38030c3c6 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_stream_parser.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/json_stream_parser.cc
@@ -45,6 +45,8 @@
#include <google/protobuf/util/internal/object_writer.h>
#include <google/protobuf/util/internal/json_escaping.h>
#include <google/protobuf/stubs/strutil.h>
+#include <google/protobuf/stubs/mathlimits.h>
+
namespace google {
namespace protobuf {
@@ -54,6 +56,7 @@ namespace util {
// this file.
using util::Status;
namespace error {
+using util::error::CANCELLED;
using util::error::INTERNAL;
using util::error::INVALID_ARGUMENT;
} // namespace error
@@ -107,7 +110,9 @@ JsonStreamParser::JsonStreamParser(ObjectWriter* ow)
parsed_storage_(),
string_open_(0),
chunk_storage_(),
- coerce_to_utf8_(false) {
+ coerce_to_utf8_(false),
+ allow_empty_null_(false),
+ loose_float_number_conversion_(false) {
// Initialize the stack with a single value to be parsed.
stack_.push(VALUE);
}
@@ -242,7 +247,7 @@ util::Status JsonStreamParser::RunParser() {
}
if (!result.ok()) {
// If we were cancelled, save our state and try again later.
- if (!finishing_ && result == util::Status::CANCELLED) {
+ if (!finishing_ && result == util::Status(error::CANCELLED, "")) {
stack_.push(type);
// If we have a key we still need to render, make sure to save off the
// contents in our own storage.
@@ -277,12 +282,16 @@ util::Status JsonStreamParser::ParseValue(TokenType type) {
case UNKNOWN:
return ReportUnknown("Expected a value.");
default: {
+ if (allow_empty_null_ && IsEmptyNullAllowed(type)) {
+ return ParseEmptyNull();
+ }
+
// Special case for having been cut off while parsing, wait for more data.
// This handles things like 'fals' being at the end of the string, we
// don't know if the next char would be e, completing it, or something
// else, making it invalid.
if (!finishing_ && p_.length() < false_len) {
- return util::Status::CANCELLED;
+ return util::Status(error::CANCELLED, "");
}
return ReportFailure("Unexpected token.");
}
@@ -293,8 +302,8 @@ util::Status JsonStreamParser::ParseString() {
util::Status result = ParseStringHelper();
if (result.ok()) {
ow_->RenderString(key_, parsed_);
- key_.clear();
- parsed_.clear();
+ key_ = StringPiece();
+ parsed_ = StringPiece();
parsed_storage_.clear();
}
return result;
@@ -315,13 +324,12 @@ util::Status JsonStreamParser::ParseStringHelper() {
// We're about to handle an escape, copy all bytes from last to data.
if (last < data) {
parsed_storage_.append(last, data - last);
- last = data;
}
// If we ran out of string after the \, cancel or report an error
// depending on if we expect more data later.
if (p_.length() == 1) {
if (!finishing_) {
- return util::Status::CANCELLED;
+ return util::Status(error::CANCELLED, "");
}
return ReportFailure("Closing quote expected in string.");
}
@@ -371,7 +379,6 @@ util::Status JsonStreamParser::ParseStringHelper() {
} else {
if (last < data) {
parsed_storage_.append(last, data - last);
- last = data;
}
parsed_ = StringPiece(parsed_storage_);
}
@@ -390,7 +397,7 @@ util::Status JsonStreamParser::ParseStringHelper() {
}
// If we didn't find the closing quote but we expect more data, cancel for now
if (!finishing_) {
- return util::Status::CANCELLED;
+ return util::Status(error::CANCELLED, "");
}
// End of string reached without a closing quote, report an error.
string_open_ = 0;
@@ -407,7 +414,7 @@ util::Status JsonStreamParser::ParseStringHelper() {
util::Status JsonStreamParser::ParseUnicodeEscape() {
if (p_.length() < kUnicodeEscapedLength) {
if (!finishing_) {
- return util::Status::CANCELLED;
+ return util::Status(error::CANCELLED, "");
}
return ReportFailure("Illegal hex string.");
}
@@ -424,7 +431,7 @@ util::Status JsonStreamParser::ParseUnicodeEscape() {
code <= JsonEscaping::kMaxHighSurrogate) {
if (p_.length() < 2 * kUnicodeEscapedLength) {
if (!finishing_) {
- return util::Status::CANCELLED;
+ return util::Status(error::CANCELLED, "");
}
if (!coerce_to_utf8_) {
return ReportFailure("Missing low surrogate.");
@@ -471,17 +478,17 @@ util::Status JsonStreamParser::ParseNumber() {
switch (number.type) {
case NumberResult::DOUBLE:
ow_->RenderDouble(key_, number.double_val);
- key_.clear();
+ key_ = StringPiece();
break;
case NumberResult::INT:
ow_->RenderInt64(key_, number.int_val);
- key_.clear();
+ key_ = StringPiece();
break;
case NumberResult::UINT:
ow_->RenderUint64(key_, number.uint_val);
- key_.clear();
+ key_ = StringPiece();
break;
default:
@@ -518,7 +525,7 @@ util::Status JsonStreamParser::ParseNumberHelper(NumberResult* result) {
// If the entire input is a valid number, and we may have more content in the
// future, we abort for now and resume when we know more.
if (index == length && !finishing_) {
- return util::Status::CANCELLED;
+ return util::Status(error::CANCELLED, "");
}
// Create a string containing just the number, so we can use safe_strtoX
@@ -529,6 +536,10 @@ util::Status JsonStreamParser::ParseNumberHelper(NumberResult* result) {
if (!safe_strtod(number, &result->double_val)) {
return ReportFailure("Unable to parse number.");
}
+ if (!loose_float_number_conversion_ &&
+ !MathLimits<double>::IsFinite(result->double_val)) {
+ return ReportFailure("Number exceeds the range of double.");
+ }
result->type = NumberResult::DOUBLE;
p_.remove_prefix(index);
return util::Status::OK;
@@ -565,7 +576,7 @@ util::Status JsonStreamParser::HandleBeginObject() {
GOOGLE_DCHECK_EQ('{', *p_.data());
Advance();
ow_->StartObject(key_);
- key_.clear();
+ key_ = StringPiece();
stack_.push(ENTRY);
return util::Status::OK;
}
@@ -615,7 +626,7 @@ util::Status JsonStreamParser::ParseEntry(TokenType type) {
} else {
key_ = parsed_;
}
- parsed_.clear();
+ parsed_ = StringPiece();
}
} else if (type == BEGIN_KEY) {
// Key is a bare key (back compat), create a StringPiece pointing to it.
@@ -648,7 +659,7 @@ util::Status JsonStreamParser::HandleBeginArray() {
GOOGLE_DCHECK_EQ('[', *p_.data());
Advance();
ow_->StartList(key_);
- key_.clear();
+ key_ = StringPiece();
stack_.push(ARRAY_VALUE);
return util::Status::OK;
}
@@ -665,10 +676,11 @@ util::Status JsonStreamParser::ParseArrayValue(TokenType type) {
}
// The ParseValue call may push something onto the stack so we need to make
- // sure an ARRAY_MID is after it, so we push it on now.
+ // sure an ARRAY_MID is after it, so we push it on now. Also, the parsing of
+ // empty-null array value is relying on this ARRAY_MID token.
stack_.push(ARRAY_MID);
util::Status result = ParseValue(type);
- if (result == util::Status::CANCELLED) {
+ if (result == util::Status(error::CANCELLED, "")) {
// If we were cancelled, pop back off the ARRAY_MID so we don't try to
// push it on again when we try over.
stack_.pop();
@@ -699,25 +711,37 @@ util::Status JsonStreamParser::ParseArrayMid(TokenType type) {
util::Status JsonStreamParser::ParseTrue() {
ow_->RenderBool(key_, true);
- key_.clear();
+ key_ = StringPiece();
p_.remove_prefix(true_len);
return util::Status::OK;
}
util::Status JsonStreamParser::ParseFalse() {
ow_->RenderBool(key_, false);
- key_.clear();
+ key_ = StringPiece();
p_.remove_prefix(false_len);
return util::Status::OK;
}
util::Status JsonStreamParser::ParseNull() {
ow_->RenderNull(key_);
- key_.clear();
+ key_ = StringPiece();
p_.remove_prefix(null_len);
return util::Status::OK;
}
+util::Status JsonStreamParser::ParseEmptyNull() {
+ ow_->RenderNull(key_);
+ key_ = StringPiece();
+ return util::Status::OK;
+}
+
+bool JsonStreamParser::IsEmptyNullAllowed(TokenType type) {
+ if (stack_.empty()) return false;
+ return (stack_.top() == ARRAY_MID && type == VALUE_SEPARATOR) ||
+ stack_.top() == OBJ_MID;
+}
+
util::Status JsonStreamParser::ReportFailure(StringPiece message) {
static const int kContextLength = 20;
const char* p_start = p_.data();
@@ -735,7 +759,7 @@ util::Status JsonStreamParser::ReportFailure(StringPiece message) {
util::Status JsonStreamParser::ReportUnknown(StringPiece message) {
// If we aren't finishing the parse, cancel parsing and try later.
if (!finishing_) {
- return util::Status::CANCELLED;
+ return util::Status(error::CANCELLED, "");
}
if (p_.empty()) {
return ReportFailure(StrCat("Unexpected end of string. ", message));
@@ -765,7 +789,7 @@ util::Status JsonStreamParser::ParseKey() {
// we can't know if the key was complete or not.
if (!finishing_ && p_.empty()) {
p_ = original;
- return util::Status::CANCELLED;
+ return util::Status(error::CANCELLED, "");
}
// Since we aren't using the key storage, clear it out.
key_storage_.clear();
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_stream_parser.h b/third_party/protobuf/src/google/protobuf/util/internal/json_stream_parser.h
index 0278c28fbc..6b9d46ee22 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_stream_parser.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/json_stream_parser.h
@@ -179,6 +179,10 @@ class LIBPROTOBUF_EXPORT JsonStreamParser {
util::Status ParseTrue();
util::Status ParseFalse();
util::Status ParseNull();
+ util::Status ParseEmptyNull();
+
+ // Whether an empty-null is allowed in the current state.
+ bool IsEmptyNullAllowed(TokenType type);
// Report a failure as a util::Status.
util::Status ReportFailure(StringPiece message);
@@ -247,6 +251,13 @@ class LIBPROTOBUF_EXPORT JsonStreamParser {
// Whether to allow non UTF-8 encoded input and replace invalid code points.
bool coerce_to_utf8_;
+ // Whether allows empty string represented null array value or object entry
+ // value.
+ bool allow_empty_null_;
+
+ // Whether allows out-of-range floating point numbers or reject them.
+ bool loose_float_number_conversion_;
+
GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(JsonStreamParser);
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_stream_parser_test.cc b/third_party/protobuf/src/google/protobuf/util/internal/json_stream_parser_test.cc
index 059ea6d86a..ca71ff2419 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/json_stream_parser_test.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/json_stream_parser_test.cc
@@ -81,12 +81,16 @@ using util::Status;
// For each test we split the input string on every possible character to ensure
// the parser is able to handle arbitrarily split input for all cases. We also
// do a final test of the entire test case one character at a time.
+//
+// It is verified that expected calls to the mocked objects are in sequence.
class JsonStreamParserTest : public ::testing::Test {
protected:
JsonStreamParserTest() : mock_(), ow_(&mock_) {}
virtual ~JsonStreamParserTest() {}
- util::Status RunTest(StringPiece json, int split, bool coerce_utf8 = false) {
+ util::Status RunTest(StringPiece json, int split, bool coerce_utf8 = false,
+ bool allow_empty_null = false,
+ bool loose_float_number_conversion = false) {
JsonStreamParser parser(&mock_);
// Special case for split == length, test parsing one character at a time.
@@ -116,8 +120,11 @@ class JsonStreamParserTest : public ::testing::Test {
return result;
}
- void DoTest(StringPiece json, int split, bool coerce_utf8 = false) {
- util::Status result = RunTest(json, split, coerce_utf8);
+ void DoTest(StringPiece json, int split, bool coerce_utf8 = false,
+ bool allow_empty_null = false,
+ bool loose_float_number_conversion = false) {
+ util::Status result = RunTest(json, split, coerce_utf8, allow_empty_null,
+ loose_float_number_conversion);
if (!result.ok()) {
GOOGLE_LOG(WARNING) << result;
}
@@ -125,14 +132,21 @@ class JsonStreamParserTest : public ::testing::Test {
}
void DoErrorTest(StringPiece json, int split, StringPiece error_prefix,
- bool coerce_utf8 = false) {
- util::Status result = RunTest(json, split, coerce_utf8);
+ bool coerce_utf8 = false, bool allow_empty_null = false) {
+ util::Status result =
+ RunTest(json, split, coerce_utf8, allow_empty_null);
EXPECT_EQ(util::error::INVALID_ARGUMENT, result.error_code());
StringPiece error_message(result.error_message());
EXPECT_EQ(error_prefix, error_message.substr(0, error_prefix.size()));
}
+#ifndef _MSC_VER
+ // TODO(xiaofeng): We have to disable InSequence check for MSVC because it
+ // causes stack overflow due to its use of a linked list that is desctructed
+ // recursively.
+ ::testing::InSequence in_sequence_;
+#endif // !_MSC_VER
MockObjectWriter mock_;
ExpectingObjectWriter ow_;
};
@@ -308,18 +322,27 @@ TEST_F(JsonStreamParserTest, ObjectKeyTypes) {
}
}
-// - array containing array, object, values (true, false, null, num, string)
-TEST_F(JsonStreamParserTest, ArrayValues) {
- StringPiece str =
- "[true, false, null, 'a string', \"another string\", [22, -127, 45.3, "
- "-1056.4, 11779497823553162765], {'key': true}]";
+// - array containing primitive values (true, false, null, num, string)
+TEST_F(JsonStreamParserTest, ArrayPrimitiveValues) {
+ StringPiece str = "[true, false, null, 'one', \"two\"]";
for (int i = 0; i <= str.length(); ++i) {
ow_.StartList("")
->RenderBool("", true)
->RenderBool("", false)
->RenderNull("")
- ->RenderString("", "a string")
- ->RenderString("", "another string")
+ ->RenderString("", "one")
+ ->RenderString("", "two")
+ ->EndList();
+ DoTest(str, i);
+ }
+}
+
+// - array containing array, object
+TEST_F(JsonStreamParserTest, ArrayComplexValues) {
+ StringPiece str =
+ "[[22, -127, 45.3, -1056.4, 11779497823553162765], {'key': true}]";
+ for (int i = 0; i <= str.length(); ++i) {
+ ow_.StartList("")
->StartList("")
->RenderUint64("", 22)
->RenderInt64("", -127)
@@ -335,6 +358,7 @@ TEST_F(JsonStreamParserTest, ArrayValues) {
}
}
+
// - object containing array, object, value (true, false, null, num, string)
TEST_F(JsonStreamParserTest, ObjectValues) {
StringPiece str =
@@ -687,17 +711,19 @@ TEST_F(JsonStreamParserTest, NegativeNumberTooBig) {
}
}
-/*
-TODO(sven): Fail parsing when parsing a double that is too large.
-
TEST_F(JsonStreamParserTest, DoubleTooBig) {
- StringPiece str = "[184464073709551232321616.45]";
+ StringPiece str = "[1.89769e+308]";
for (int i = 0; i <= str.length(); ++i) {
ow_.StartList("");
- DoErrorTest(str, i, "Unable to parse number");
+ DoErrorTest(str, i, "Number exceeds the range of double.");
+ }
+ str = "[-1.89769e+308]";
+ for (int i = 0; i <= str.length(); ++i) {
+ ow_.StartList("");
+ DoErrorTest(str, i, "Number exceeds the range of double.");
}
}
-*/
+
// invalid bare backslash.
TEST_F(JsonStreamParserTest, UnfinishedEscape) {
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/location_tracker.h b/third_party/protobuf/src/google/protobuf/util/internal/location_tracker.h
index 0864b05737..0864b05737 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/location_tracker.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/location_tracker.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/mock_error_listener.h b/third_party/protobuf/src/google/protobuf/util/internal/mock_error_listener.h
index 591c35dbbb..591c35dbbb 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/mock_error_listener.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/mock_error_listener.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/object_location_tracker.h b/third_party/protobuf/src/google/protobuf/util/internal/object_location_tracker.h
index 8586cecc91..8586cecc91 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/object_location_tracker.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/object_location_tracker.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/object_source.h b/third_party/protobuf/src/google/protobuf/util/internal/object_source.h
index 2c31cfb09e..2c31cfb09e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/object_source.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/object_source.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/object_writer.cc b/third_party/protobuf/src/google/protobuf/util/internal/object_writer.cc
index 57cc08a1d7..57cc08a1d7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/object_writer.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/object_writer.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/object_writer.h b/third_party/protobuf/src/google/protobuf/util/internal/object_writer.h
index 5781aa1e21..b6fbd19bf7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/object_writer.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/object_writer.h
@@ -119,6 +119,13 @@ class LIBPROTOBUF_EXPORT ObjectWriter {
return use_strict_base64_decoding_;
}
+ // Whether empty strings should be rendered for the next name for Start/Render
+ // calls. This setting is only valid until the next key is rendered, after
+ // which it gets reset.
+ // It is up to the derived classes to interpret this and render accordingly.
+ // Default implementation ignores this setting.
+ virtual void empty_name_ok_for_next_key() {}
+
protected:
ObjectWriter() : use_strict_base64_decoding_(true) {}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/proto_writer.cc b/third_party/protobuf/src/google/protobuf/util/internal/proto_writer.cc
index 0c38aeb900..8bebf2ab1f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/proto_writer.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/proto_writer.cc
@@ -65,6 +65,7 @@ ProtoWriter::ProtoWriter(TypeResolver* type_resolver,
own_typeinfo_(true),
done_(false),
ignore_unknown_fields_(false),
+ use_lower_camel_for_enums_(false),
element_(NULL),
size_insert_(),
output_(output),
@@ -83,6 +84,7 @@ ProtoWriter::ProtoWriter(const TypeInfo* typeinfo,
own_typeinfo_(false),
done_(false),
ignore_unknown_fields_(false),
+ use_lower_camel_for_enums_(false),
element_(NULL),
size_insert_(),
output_(output),
@@ -264,8 +266,9 @@ inline Status WriteString(int field_number, const DataPiece& data,
// Writes an ENUM field, including tag, to the stream.
inline Status WriteEnum(int field_number, const DataPiece& data,
const google::protobuf::Enum* enum_type,
- CodedOutputStream* stream) {
- StatusOr<int> e = data.ToEnum(enum_type);
+ CodedOutputStream* stream,
+ bool use_lower_camel_for_enums) {
+ StatusOr<int> e = data.ToEnum(enum_type, use_lower_camel_for_enums);
if (e.ok()) {
WireFormatLite::WriteEnum(field_number, e.ValueOrDie(), stream);
}
@@ -351,7 +354,7 @@ ProtoWriter::ProtoElement* ProtoWriter::ProtoElement::pop() {
if (!proto3_) {
// Calls the registered error listener for any required field(s) not yet
// seen.
- for (set<const google::protobuf::Field*>::iterator it =
+ for (std::set<const google::protobuf::Field*>::iterator it =
required_fields_.begin();
it != required_fields_.end(); ++it) {
ow_->MissingField((*it)->name());
@@ -662,7 +665,7 @@ ProtoWriter* ProtoWriter::RenderPrimitiveField(
case google::protobuf::Field_Kind_TYPE_ENUM: {
status = WriteEnum(field.number(), data,
typeinfo_->GetEnumByTypeUrl(field.type_url()),
- stream_.get());
+ stream_.get(), use_lower_camel_for_enums_);
break;
}
default: // TYPE_GROUP or TYPE_MESSAGE
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/proto_writer.h b/third_party/protobuf/src/google/protobuf/util/internal/proto_writer.h
index 7f1108abfe..21dff88d72 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/proto_writer.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/proto_writer.h
@@ -148,6 +148,10 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter {
ignore_unknown_fields_ = ignore_unknown_fields;
}
+ void set_use_lower_camel_for_enums(bool use_lower_camel_for_enums) {
+ use_lower_camel_for_enums_ = use_lower_camel_for_enums;
+ }
+
protected:
class LIBPROTOBUF_EXPORT ProtoElement : public BaseElement, public LocationTrackerInterface {
public:
@@ -308,6 +312,10 @@ class LIBPROTOBUF_EXPORT ProtoWriter : public StructuredObjectWriter {
// If true, don't report unknown field names to the listener.
bool ignore_unknown_fields_;
+ // If true, check if enum name in camel case or without underscore matches the
+ // field name.
+ bool use_lower_camel_for_enums_;
+
// Variable for internal state processing:
// element_ : the current element.
// size_insert_: sizes of nested messages.
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectsource.cc b/third_party/protobuf/src/google/protobuf/util/internal/protostream_objectsource.cc
index 0048d75b58..61491af0c2 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectsource.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/protostream_objectsource.cc
@@ -85,7 +85,7 @@ const google::protobuf::EnumValue* FindEnumValueByNumber(
const google::protobuf::Enum& tech_enum, int number);
// Utility function to format nanos.
-const string FormatNanos(uint32 nanos);
+const string FormatNanos(uint32 nanos, bool with_trailing_zeros);
StatusOr<string> MapKeyDefaultValueAsString(
const google::protobuf::Field& field) {
@@ -120,9 +120,12 @@ ProtoStreamObjectSource::ProtoStreamObjectSource(
own_typeinfo_(true),
type_(type),
use_lower_camel_for_enums_(false),
+ use_ints_for_enums_(false),
+ preserve_proto_field_names_(false),
recursion_depth_(0),
max_recursion_depth_(kDefaultMaxRecursionDepth),
- render_unknown_fields_(false) {
+ render_unknown_fields_(false),
+ add_trailing_zeros_for_timestamp_and_duration_(false) {
GOOGLE_LOG_IF(DFATAL, stream == NULL) << "Input stream is NULL.";
}
@@ -134,9 +137,12 @@ ProtoStreamObjectSource::ProtoStreamObjectSource(
own_typeinfo_(false),
type_(type),
use_lower_camel_for_enums_(false),
+ use_ints_for_enums_(false),
+ preserve_proto_field_names_(false),
recursion_depth_(0),
max_recursion_depth_(kDefaultMaxRecursionDepth),
- render_unknown_fields_(false) {
+ render_unknown_fields_(false),
+ add_trailing_zeros_for_timestamp_and_duration_(false) {
GOOGLE_LOG_IF(DFATAL, stream == NULL) << "Input stream is NULL.";
}
@@ -196,7 +202,11 @@ Status ProtoStreamObjectSource::WriteMessage(const google::protobuf::Type& type,
last_tag = tag;
field = FindAndVerifyField(type, tag);
if (field != NULL) {
- field_name = field->json_name();
+ if (preserve_proto_field_names_) {
+ field_name = field->name();
+ } else {
+ field_name = field->json_name();
+ }
}
}
if (field == NULL) {
@@ -288,6 +298,8 @@ StatusOr<uint32> ProtoStreamObjectSource::RenderMap(
return Status(util::error::INTERNAL, "Invalid map entry.");
}
ASSIGN_OR_RETURN(map_key, MapKeyDefaultValueAsString(*key_field));
+ // Key is empty, force it to render as empty (for string values).
+ ow->empty_name_ok_for_next_key();
}
RETURN_IF_ERROR(RenderField(field, map_key, ow));
} else {
@@ -316,7 +328,7 @@ Status ProtoStreamObjectSource::RenderPacked(
Status ProtoStreamObjectSource::RenderTimestamp(
const ProtoStreamObjectSource* os, const google::protobuf::Type& type,
StringPiece field_name, ObjectWriter* ow) {
- pair<int64, int32> p = os->ReadSecondsAndNanos(type);
+ std::pair<int64, int32> p = os->ReadSecondsAndNanos(type);
int64 seconds = p.first;
int32 nanos = p.second;
if (seconds > kTimestampMaxSeconds || seconds < kTimestampMinSeconds) {
@@ -340,7 +352,7 @@ Status ProtoStreamObjectSource::RenderTimestamp(
Status ProtoStreamObjectSource::RenderDuration(
const ProtoStreamObjectSource* os, const google::protobuf::Type& type,
StringPiece field_name, ObjectWriter* ow) {
- pair<int64, int32> p = os->ReadSecondsAndNanos(type);
+ std::pair<int64, int32> p = os->ReadSecondsAndNanos(type);
int64 seconds = p.first;
int32 nanos = p.second;
if (seconds > kDurationMaxSeconds || seconds < kDurationMinSeconds) {
@@ -370,8 +382,10 @@ Status ProtoStreamObjectSource::RenderDuration(
sign = "-";
nanos = -nanos;
}
- string formatted_duration = StringPrintf("%s%lld%ss", sign.c_str(), seconds,
- FormatNanos(nanos).c_str());
+ string formatted_duration = StringPrintf(
+ "%s%lld%ss", sign.c_str(), seconds,
+ FormatNanos(nanos, os->add_trailing_zeros_for_timestamp_and_duration_)
+ .c_str());
ow->RenderString(field_name, formatted_duration);
return Status::OK;
}
@@ -852,12 +866,19 @@ Status ProtoStreamObjectSource::RenderNonMessageField(
break;
}
+ // No need to lookup enum type if we need to render int.
+ if (use_ints_for_enums_) {
+ ow->RenderInt32(field_name, buffer32);
+ break;
+ }
+
// Get the nested enum type for this field.
// TODO(skarvaje): Avoid string manipulation. Find ways to speed this
// up.
const google::protobuf::Enum* en =
typeinfo_->GetEnumByTypeUrl(field->type_url());
- // Lookup the name of the enum, and render that. Skips unknown enums.
+ // Lookup the name of the enum, and render that. Unknown enum values
+ // are printed as integers.
if (en != NULL) {
const google::protobuf::EnumValue* enum_value =
FindEnumValueByNumber(*en, buffer32);
@@ -866,9 +887,11 @@ Status ProtoStreamObjectSource::RenderNonMessageField(
ow->RenderString(field_name, ToCamelCase(enum_value->name()));
else
ow->RenderString(field_name, enum_value->name());
+ } else {
+ ow->RenderInt32(field_name, buffer32);
}
} else {
- GOOGLE_LOG(INFO) << "Unknown enum skipped: " << field->type_url();
+ ow->RenderInt32(field_name, buffer32);
}
break;
}
@@ -1015,12 +1038,8 @@ bool ProtoStreamObjectSource::IsMap(
const google::protobuf::Field& field) const {
const google::protobuf::Type* field_type =
typeinfo_->GetTypeByTypeUrl(field.type_url());
-
- // TODO(xiaofeng): Unify option names.
return field.kind() == google::protobuf::Field_Kind_TYPE_MESSAGE &&
- (GetBoolOptionOrDefault(field_type->options(),
- "google.protobuf.MessageOptions.map_entry", false) ||
- GetBoolOptionOrDefault(field_type->options(), "map_entry", false));
+ google::protobuf::util::converter::IsMap(field, *field_type);
}
std::pair<int64, int32> ProtoStreamObjectSource::ReadSecondsAndNanos(
@@ -1098,7 +1117,11 @@ const google::protobuf::EnumValue* FindEnumValueByNumber(
// TODO(skarvaje): Look into optimizing this by not doing computation on
// double.
-const string FormatNanos(uint32 nanos) {
+const string FormatNanos(uint32 nanos, bool with_trailing_zeros) {
+ if (nanos == 0) {
+ return with_trailing_zeros ? ".000" : "";
+ }
+
const char* format =
(nanos % 1000 != 0) ? "%.9f" : (nanos % 1000000 != 0) ? "%.6f" : "%.3f";
string formatted =
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectsource.h b/third_party/protobuf/src/google/protobuf/util/internal/protostream_objectsource.h
index 243f85b2db..5f443d9d48 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectsource.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/protostream_objectsource.h
@@ -110,6 +110,17 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
use_lower_camel_for_enums_ = value;
}
+ // Sets whether to always output enums as ints, by default this is off, and
+ // enums are rendered as strings.
+ void set_use_ints_for_enums(bool value) {
+ use_ints_for_enums_ = value;
+ }
+
+ // Sets whether to use original proto field names
+ void set_preserve_proto_field_names(bool value) {
+ preserve_proto_field_names_ = value;
+ }
+
// Sets the max recursion depth of proto message to be deserialized. Proto
// messages over this depth will fail to be deserialized.
// Default value is 64.
@@ -129,6 +140,28 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
bool include_start_and_end,
ObjectWriter* ow) const;
+ // Renders a repeating field (packed or unpacked). Returns the next tag after
+ // reading all sequential repeating elements. The caller should use this tag
+ // before reading more tags from the stream.
+ virtual util::StatusOr<uint32> RenderList(
+ const google::protobuf::Field* field, StringPiece name, uint32 list_tag,
+ ObjectWriter* ow) const;
+
+ // Looks up a field and verify its consistency with wire type in tag.
+ const google::protobuf::Field* FindAndVerifyField(
+ const google::protobuf::Type& type, uint32 tag) const;
+
+ // Renders a field value to the ObjectWriter.
+ util::Status RenderField(const google::protobuf::Field* field,
+ StringPiece field_name, ObjectWriter* ow) const;
+
+ // Reads field value according to Field spec in 'field' and returns the read
+ // value as string. This only works for primitive datatypes (no message
+ // types).
+ const string ReadFieldValueAsString(
+ const google::protobuf::Field& field) const;
+
+
private:
ProtoStreamObjectSource(google::protobuf::io::CodedInputStream* stream,
const TypeInfo* typeinfo,
@@ -138,19 +171,9 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
const google::protobuf::Type&,
StringPiece, ObjectWriter*);
- // Looks up a field and verify its consistency with wire type in tag.
- const google::protobuf::Field* FindAndVerifyField(
- const google::protobuf::Type& type, uint32 tag) const;
-
// TODO(skarvaje): Mark these methods as non-const as they modify internal
// state (stream_).
//
- // Renders a repeating field (packed or unpacked).
- // Returns the next tag after reading all sequential repeating elements. The
- // caller should use this tag before reading more tags from the stream.
- util::StatusOr<uint32> RenderList(const google::protobuf::Field* field,
- StringPiece name, uint32 list_tag,
- ObjectWriter* ow) const;
// Renders a NWP map.
// Returns the next tag after reading all map entries. The caller should use
// this tag before reading more tags from the stream.
@@ -234,10 +257,6 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
static void DeleteRendererMap();
static TypeRenderer* FindTypeRenderer(const string& type_url);
- // Renders a field value to the ObjectWriter.
- util::Status RenderField(const google::protobuf::Field* field,
- StringPiece field_name, ObjectWriter* ow) const;
-
// Same as above but renders all non-message field types. Callers don't call
// this function directly. They just use RenderField.
util::Status RenderNonMessageField(const google::protobuf::Field* field,
@@ -245,12 +264,6 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
ObjectWriter* ow) const;
- // Reads field value according to Field spec in 'field' and returns the read
- // value as string. This only works for primitive datatypes (no message
- // types).
- const string ReadFieldValueAsString(
- const google::protobuf::Field& field) const;
-
// Utility function to detect proto maps. The 'field' MUST be repeated.
bool IsMap(const google::protobuf::Field& field) const;
@@ -271,6 +284,7 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
// Type information for all the types used in the descriptor. Used to find
// google::protobuf::Type of nested messages/enums.
const TypeInfo* typeinfo_;
+
// Whether this class owns the typeinfo_ object. If true the typeinfo_ object
// should be deleted in the destructor.
bool own_typeinfo_;
@@ -282,6 +296,12 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
// Whether to render enums using lowerCamelCase. Defaults to false.
bool use_lower_camel_for_enums_;
+ // Whether to render enums as ints always. Defaults to false.
+ bool use_ints_for_enums_;
+
+ // Whether to preserve proto field names
+ bool preserve_proto_field_names_;
+
// Tracks current recursion depth.
mutable int recursion_depth_;
@@ -291,6 +311,9 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
// Whether to render unknown fields.
bool render_unknown_fields_;
+ // Whether to add trailing zeros for timestamp and duration.
+ bool add_trailing_zeros_for_timestamp_and_duration_;
+
GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(ProtoStreamObjectSource);
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectsource_test.cc b/third_party/protobuf/src/google/protobuf/util/internal/protostream_objectsource_test.cc
index 3f6fdf973f..e215c4abcd 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectsource_test.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/protostream_objectsource_test.cc
@@ -42,15 +42,16 @@
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/util/internal/expecting_objectwriter.h>
+#include <google/protobuf/util/internal/testdata/anys.pb.h>
#include <google/protobuf/util/internal/testdata/books.pb.h>
#include <google/protobuf/util/internal/testdata/field_mask.pb.h>
-#include <google/protobuf/util/internal/type_info_test_helper.h>
-#include <google/protobuf/util/internal/constants.h>
-#include <google/protobuf/stubs/strutil.h>
-#include <google/protobuf/util/internal/testdata/anys.pb.h>
#include <google/protobuf/util/internal/testdata/maps.pb.h>
+#include <google/protobuf/util/internal/testdata/proto3.pb.h>
#include <google/protobuf/util/internal/testdata/struct.pb.h>
#include <google/protobuf/util/internal/testdata/timestamp_duration.pb.h>
+#include <google/protobuf/util/internal/type_info_test_helper.h>
+#include <google/protobuf/util/internal/constants.h>
+#include <google/protobuf/stubs/strutil.h>
#include <gtest/gtest.h>
@@ -66,24 +67,24 @@ using google::protobuf::Message;
using google::protobuf::io::ArrayInputStream;
using google::protobuf::io::CodedInputStream;
using util::Status;
+using google::protobuf::testing::AnyM;
+using google::protobuf::testing::AnyOut;
using google::protobuf::testing::Author;
using google::protobuf::testing::BadAuthor;
using google::protobuf::testing::BadNestedBook;
using google::protobuf::testing::Book;
-using google::protobuf::testing::Cyclic;
using google::protobuf::testing::Book_Label;
+using google::protobuf::testing::Cyclic;
+using google::protobuf::testing::FieldMaskTest;
+using google::protobuf::testing::MapOut;
+using google::protobuf::testing::MapOutWireFormat;
using google::protobuf::testing::NestedBook;
+using google::protobuf::testing::NestedFieldMask;
using google::protobuf::testing::PackedPrimitive;
using google::protobuf::testing::Primitive;
-using google::protobuf::testing::more_author;
-using google::protobuf::testing::maps::MapOut;
-using google::protobuf::testing::maps::MapOutWireFormat;
-using google::protobuf::testing::timestampduration::TimestampDuration;
-using google::protobuf::testing::anys::AnyOut;
-using google::protobuf::testing::anys::AnyM;
-using google::protobuf::testing::FieldMaskTest;
-using google::protobuf::testing::NestedFieldMask;
-using google::protobuf::testing::structs::StructType;
+using google::protobuf::testing::Proto3Message;
+using google::protobuf::testing::StructType;
+using google::protobuf::testing::TimestampDuration;
using ::testing::_;
@@ -100,8 +101,10 @@ class ProtostreamObjectSourceTest
: helper_(GetParam()),
mock_(),
ow_(&mock_),
- use_lower_camel_for_enums_(false) {
- helper_.ResetTypeInfo(Book::descriptor());
+ use_lower_camel_for_enums_(false),
+ use_ints_for_enums_(false),
+ add_trailing_zeros_(false) {
+ helper_.ResetTypeInfo(Book::descriptor(), Proto3Message::descriptor());
}
virtual ~ProtostreamObjectSourceTest() {}
@@ -112,7 +115,7 @@ class ProtostreamObjectSourceTest
}
Status ExecuteTest(const Message& msg, const Descriptor* descriptor) {
- ostringstream oss;
+ std::ostringstream oss;
msg.SerializePartialToOstream(&oss);
string proto = oss.str();
ArrayInputStream arr_stream(proto.data(), proto.size());
@@ -121,6 +124,7 @@ class ProtostreamObjectSourceTest
google::protobuf::scoped_ptr<ProtoStreamObjectSource> os(
helper_.NewProtoSource(&in_stream, GetTypeUrl(descriptor)));
if (use_lower_camel_for_enums_) os->set_use_lower_camel_for_enums(true);
+ if (use_ints_for_enums_) os->set_use_ints_for_enums(true);
os->set_max_recursion_depth(64);
return os->WriteTo(&mock_);
}
@@ -268,11 +272,17 @@ class ProtostreamObjectSourceTest
void UseLowerCamelForEnums() { use_lower_camel_for_enums_ = true; }
+ void UseIntsForEnums() { use_ints_for_enums_ = true; }
+
+ void AddTrailingZeros() { add_trailing_zeros_ = true; }
+
testing::TypeInfoTestHelper helper_;
::testing::NiceMock<MockObjectWriter> mock_;
ExpectingObjectWriter ow_;
bool use_lower_camel_for_enums_;
+ bool use_ints_for_enums_;
+ bool add_trailing_zeros_;
};
INSTANTIATE_TEST_CASE_P(DifferentTypeInfoSourceTest,
@@ -493,6 +503,27 @@ TEST_P(ProtostreamObjectSourceTest, EnumCaseIsUnchangedByDefault) {
DoTest(book, Book::descriptor());
}
+TEST_P(ProtostreamObjectSourceTest, UseIntsForEnumsTest) {
+ Book book;
+ book.set_type(Book::ACTION_AND_ADVENTURE);
+
+ UseIntsForEnums();
+
+ ow_.StartObject("")
+ ->RenderInt32("type", 3)
+ ->EndObject();
+ DoTest(book, Book::descriptor());
+}
+
+TEST_P(ProtostreamObjectSourceTest, UnknownEnum) {
+ Proto3Message message;
+ message.set_enum_value(static_cast<Proto3Message::NestedEnum>(1234));
+ ow_.StartObject("")
+ ->RenderInt32("enumValue", 1234)
+ ->EndObject();
+ DoTest(message, Proto3Message::descriptor());
+}
+
TEST_P(ProtostreamObjectSourceTest, CyclicMessageDepthTest) {
Cyclic cyclic;
cyclic.set_m_int(123);
@@ -679,7 +710,7 @@ INSTANTIATE_TEST_CASE_P(DifferentTypeInfoSourceTest,
// This is the example expected output.
// {
// "any": {
-// "@type": "type.googleapis.com/google.protobuf.testing.anys.AnyM"
+// "@type": "type.googleapis.com/google.protobuf.testing.AnyM"
// "foo": "foovalue"
// }
// }
@@ -694,7 +725,7 @@ TEST_P(ProtostreamObjectSourceAnysTest, BasicAny) {
ow_.StartObject("")
->StartObject("any")
->RenderString("@type",
- "type.googleapis.com/google.protobuf.testing.anys.AnyM")
+ "type.googleapis.com/google.protobuf.testing.AnyM")
->RenderString("foo", "foovalue")
->EndObject()
->EndObject();
@@ -708,8 +739,7 @@ TEST_P(ProtostreamObjectSourceAnysTest, RecursiveAny) {
any->set_type_url("type.googleapis.com/google.protobuf.Any");
::google::protobuf::Any nested_any;
- nested_any.set_type_url(
- "type.googleapis.com/google.protobuf.testing.anys.AnyM");
+ nested_any.set_type_url("type.googleapis.com/google.protobuf.testing.AnyM");
AnyM m;
m.set_foo("foovalue");
@@ -722,7 +752,7 @@ TEST_P(ProtostreamObjectSourceAnysTest, RecursiveAny) {
->RenderString("@type", "type.googleapis.com/google.protobuf.Any")
->StartObject("value")
->RenderString("@type",
- "type.googleapis.com/google.protobuf.testing.anys.AnyM")
+ "type.googleapis.com/google.protobuf.testing.AnyM")
->RenderString("foo", "foovalue")
->EndObject()
->EndObject()
@@ -741,7 +771,7 @@ TEST_P(ProtostreamObjectSourceAnysTest, DoubleRecursiveAny) {
::google::protobuf::Any second_nested_any;
second_nested_any.set_type_url(
- "type.googleapis.com/google.protobuf.testing.anys.AnyM");
+ "type.googleapis.com/google.protobuf.testing.AnyM");
AnyM m;
m.set_foo("foovalue");
@@ -756,7 +786,7 @@ TEST_P(ProtostreamObjectSourceAnysTest, DoubleRecursiveAny) {
->RenderString("@type", "type.googleapis.com/google.protobuf.Any")
->StartObject("value")
->RenderString("@type",
- "type.googleapis.com/google.protobuf.testing.anys.AnyM")
+ "type.googleapis.com/google.protobuf.testing.AnyM")
->RenderString("foo", "foovalue")
->EndObject()
->EndObject()
@@ -1001,6 +1031,20 @@ TEST_P(ProtostreamObjectSourceTimestampTest, InvalidDurationAboveMaxTest) {
EXPECT_EQ(util::error::INTERNAL, status.error_code());
}
+TEST_P(ProtostreamObjectSourceTimestampTest, TimestampDurationDefaultValue) {
+ TimestampDuration out;
+ out.mutable_ts()->set_seconds(0);
+ out.mutable_dur()->set_seconds(0);
+
+ ow_.StartObject("")
+ ->RenderString("ts", "1970-01-01T00:00:00Z")
+ ->RenderString("dur", "0s")
+ ->EndObject();
+
+ DoTest(out, TimestampDuration::descriptor());
+}
+
+
} // namespace converter
} // namespace util
} // namespace protobuf
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectwriter.cc b/third_party/protobuf/src/google/protobuf/util/internal/protostream_objectwriter.cc
index 1825f5569e..6c9bc30e75 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectwriter.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/protostream_objectwriter.cc
@@ -65,6 +65,7 @@ ProtoStreamObjectWriter::ProtoStreamObjectWriter(
current_(NULL),
options_(options) {
set_ignore_unknown_fields(options_.ignore_unknown_fields);
+ set_use_lower_camel_for_enums(options_.use_lower_camel_for_enums);
}
ProtoStreamObjectWriter::ProtoStreamObjectWriter(
@@ -192,17 +193,11 @@ ProtoStreamObjectWriter::AnyWriter::~AnyWriter() {}
void ProtoStreamObjectWriter::AnyWriter::StartObject(StringPiece name) {
++depth_;
// If an object writer is absent, that means we have not called StartAny()
- // before reaching here. This is an invalid state. StartAny() gets called
- // whenever we see an "@type" being rendered (see AnyWriter::RenderDataPiece).
+ // before reaching here, which happens when we have data before the "@type"
+ // field.
if (ow_ == NULL) {
- // Make sure we are not already in an invalid state. This avoids making
- // multiple unnecessary InvalidValue calls.
- if (!invalid_) {
- parent_->InvalidValue("Any",
- StrCat("Missing or invalid @type for any field in ",
- parent_->master_type_.name()));
- invalid_ = true;
- }
+ // Save data before the "@type" field for later replay.
+ uninterpreted_events_.push_back(Event(Event::START_OBJECT, name));
} else if (is_well_known_type_ && depth_ == 1) {
// For well-known types, the only other field besides "@type" should be a
// "value" field.
@@ -222,10 +217,15 @@ void ProtoStreamObjectWriter::AnyWriter::StartObject(StringPiece name) {
bool ProtoStreamObjectWriter::AnyWriter::EndObject() {
--depth_;
- // As long as depth_ >= 0, we know we haven't reached the end of Any.
- // Propagate these EndObject() calls to the contained ow_. For regular
- // message types, we propagate the end of Any as well.
- if (ow_ != NULL && (depth_ >= 0 || !is_well_known_type_)) {
+ if (ow_ == NULL) {
+ if (depth_ >= 0) {
+ // Save data before the "@type" field for later replay.
+ uninterpreted_events_.push_back(Event(Event::END_OBJECT));
+ }
+ } else if (depth_ >= 0 || !is_well_known_type_) {
+ // As long as depth_ >= 0, we know we haven't reached the end of Any.
+ // Propagate these EndObject() calls to the contained ow_. For regular
+ // message types, we propagate the end of Any as well.
ow_->EndObject();
}
// A negative depth_ implies that we have reached the end of Any
@@ -239,14 +239,9 @@ bool ProtoStreamObjectWriter::AnyWriter::EndObject() {
void ProtoStreamObjectWriter::AnyWriter::StartList(StringPiece name) {
++depth_;
- // We expect ow_ to be present as this call only makes sense inside an Any.
if (ow_ == NULL) {
- if (!invalid_) {
- parent_->InvalidValue("Any",
- StrCat("Missing or invalid @type for any field in ",
- parent_->master_type_.name()));
- invalid_ = true;
- }
+ // Save data before the "@type" field for later replay.
+ uninterpreted_events_.push_back(Event(Event::START_LIST, name));
} else if (is_well_known_type_ && depth_ == 1) {
if (name != "value" && !invalid_) {
parent_->InvalidValue("Any",
@@ -265,8 +260,10 @@ void ProtoStreamObjectWriter::AnyWriter::EndList() {
GOOGLE_LOG(DFATAL) << "Mismatched EndList found, should not be possible";
depth_ = 0;
}
- // We don't write an error on the close, only on the open
- if (ow_ != NULL) {
+ if (ow_ == NULL) {
+ // Save data before the "@type" field for later replay.
+ uninterpreted_events_.push_back(Event(Event::END_LIST));
+ } else {
ow_->EndList();
}
}
@@ -278,12 +275,8 @@ void ProtoStreamObjectWriter::AnyWriter::RenderDataPiece(
if (depth_ == 0 && ow_ == NULL && name == "@type") {
StartAny(value);
} else if (ow_ == NULL) {
- if (!invalid_) {
- parent_->InvalidValue("Any",
- StrCat("Missing or invalid @type for any field in ",
- parent_->master_type_.name()));
- invalid_ = true;
- }
+ // Save data before the "@type" field.
+ uninterpreted_events_.push_back(Event(name, value));
} else if (depth_ == 0 && is_well_known_type_) {
if (name != "value" && !invalid_) {
parent_->InvalidValue("Any",
@@ -293,7 +286,7 @@ void ProtoStreamObjectWriter::AnyWriter::RenderDataPiece(
if (well_known_type_render_ == NULL) {
// Only Any and Struct don't have a special type render but both of
// them expect a JSON object (i.e., a StartObject() call).
- if (!invalid_) {
+ if (value.type() != DataPiece::TYPE_NULL && !invalid_) {
parent_->InvalidValue("Any", "Expect a JSON object.");
invalid_ = true;
}
@@ -358,13 +351,29 @@ void ProtoStreamObjectWriter::AnyWriter::StartAny(const DataPiece& value) {
if (!is_well_known_type_) {
ow_->StartObject("");
}
+
+ // Now we know the proto type and can interpret all data fields we gathered
+ // before the "@type" field.
+ for (int i = 0; i < uninterpreted_events_.size(); ++i) {
+ uninterpreted_events_[i].Replay(this);
+ }
}
void ProtoStreamObjectWriter::AnyWriter::WriteAny() {
if (ow_ == NULL) {
- // If we had no object writer, we never got any content, so just return
- // immediately, which is equivalent to writing an empty Any.
- return;
+ if (uninterpreted_events_.empty()) {
+ // We never got any content, so just return immediately, which is
+ // equivalent to writing an empty Any.
+ return;
+ } else {
+ // There are uninterpreted data, but we never got a "@type" field.
+ if (!invalid_) {
+ parent_->InvalidValue("Any", StrCat("Missing @type for any field in ",
+ parent_->master_type_.name()));
+ invalid_ = true;
+ }
+ return;
+ }
}
// Render the type_url and value fields directly to the stream.
// type_url has tag 1 and value has tag 2.
@@ -374,6 +383,41 @@ void ProtoStreamObjectWriter::AnyWriter::WriteAny() {
}
}
+void ProtoStreamObjectWriter::AnyWriter::Event::Replay(
+ AnyWriter* writer) const {
+ switch (type_) {
+ case START_OBJECT:
+ writer->StartObject(name_);
+ break;
+ case END_OBJECT:
+ writer->EndObject();
+ break;
+ case START_LIST:
+ writer->StartList(name_);
+ break;
+ case END_LIST:
+ writer->EndList();
+ break;
+ case RENDER_DATA_PIECE:
+ writer->RenderDataPiece(name_, value_);
+ break;
+ }
+}
+
+void ProtoStreamObjectWriter::AnyWriter::Event::DeepCopy() {
+ // DataPiece only contains a string reference. To make sure the referenced
+ // string value stays valid, we make a copy of the string value and update
+ // DataPiece to reference our own copy.
+ if (value_.type() == DataPiece::TYPE_STRING) {
+ value_.str().AppendToString(&value_storage_);
+ value_ = DataPiece(value_storage_, value_.use_strict_base64_decoding());
+ } else if (value_.type() == DataPiece::TYPE_BYTES) {
+ value_storage_ = value_.ToBytes().ValueOrDie();
+ value_ =
+ DataPiece(value_storage_, true, value_.use_strict_base64_decoding());
+ }
+}
+
ProtoStreamObjectWriter::Item::Item(ProtoStreamObjectWriter* enclosing,
ItemType item_type, bool is_placeholder,
bool is_list)
@@ -867,6 +911,7 @@ Status ProtoStreamObjectWriter::RenderStructValue(ProtoStreamObjectWriter* ow,
Status ProtoStreamObjectWriter::RenderTimestamp(ProtoStreamObjectWriter* ow,
const DataPiece& data) {
+ if (data.type() == DataPiece::TYPE_NULL) return Status::OK;
if (data.type() != DataPiece::TYPE_STRING) {
return Status(INVALID_ARGUMENT,
StrCat("Invalid data type for timestamp, value is ",
@@ -897,6 +942,7 @@ static inline util::Status RenderOneFieldPath(ProtoStreamObjectWriter* ow,
Status ProtoStreamObjectWriter::RenderFieldMask(ProtoStreamObjectWriter* ow,
const DataPiece& data) {
+ if (data.type() == DataPiece::TYPE_NULL) return Status::OK;
if (data.type() != DataPiece::TYPE_STRING) {
return Status(INVALID_ARGUMENT,
StrCat("Invalid data type for field mask, value is ",
@@ -907,12 +953,13 @@ Status ProtoStreamObjectWriter::RenderFieldMask(ProtoStreamObjectWriter* ow,
// conversions as much as possible. Because ToSnakeCase sometimes returns the
// wrong value.
google::protobuf::scoped_ptr<ResultCallback1<util::Status, StringPiece> > callback(
- ::google::protobuf::internal::NewPermanentCallback(&RenderOneFieldPath, ow));
+ NewPermanentCallback(&RenderOneFieldPath, ow));
return DecodeCompactFieldMaskPaths(data.str(), callback.get());
}
Status ProtoStreamObjectWriter::RenderDuration(ProtoStreamObjectWriter* ow,
const DataPiece& data) {
+ if (data.type() == DataPiece::TYPE_NULL) return Status::OK;
if (data.type() != DataPiece::TYPE_STRING) {
return Status(INVALID_ARGUMENT,
StrCat("Invalid data type for duration, value is ",
@@ -962,6 +1009,7 @@ Status ProtoStreamObjectWriter::RenderDuration(ProtoStreamObjectWriter* ow,
Status ProtoStreamObjectWriter::RenderWrapperType(ProtoStreamObjectWriter* ow,
const DataPiece& data) {
+ if (data.type() == DataPiece::TYPE_NULL) return Status::OK;
ow->ProtoWriter::RenderDataPiece("value", data);
return Status::OK;
}
@@ -1049,13 +1097,18 @@ ProtoStreamObjectWriter* ProtoStreamObjectWriter::RenderDataPiece(
// Check if the field is of special type. Render it accordingly if so.
const TypeRenderer* type_renderer = FindTypeRenderer(field->type_url());
if (type_renderer != NULL) {
- Push(name, Item::MESSAGE, false, false);
- status = (*type_renderer)(this, data);
- if (!status.ok()) {
- InvalidValue(field->type_url(),
- StrCat("Field '", name, "', ", status.error_message()));
+ // Pass through null value only for google.protobuf.Value. For other
+ // types we ignore null value just like for regular field types.
+ if (data.type() != DataPiece::TYPE_NULL ||
+ field->type_url() == kStructValueTypeUrl) {
+ Push(name, Item::MESSAGE, false, false);
+ status = (*type_renderer)(this, data);
+ if (!status.ok()) {
+ InvalidValue(field->type_url(),
+ StrCat("Field '", name, "', ", status.error_message()));
+ }
+ Pop();
}
- Pop();
return this;
}
@@ -1185,10 +1238,7 @@ bool ProtoStreamObjectWriter::IsMap(const google::protobuf::Field& field) {
const google::protobuf::Type* field_type =
typeinfo()->GetTypeByTypeUrl(field.type_url());
- // TODO(xiaofeng): Unify option names.
- return GetBoolOptionOrDefault(field_type->options(),
- "google.protobuf.MessageOptions.map_entry", false) ||
- GetBoolOptionOrDefault(field_type->options(), "map_entry", false);
+ return google::protobuf::util::converter::IsMap(field, *field_type);
}
bool ProtoStreamObjectWriter::IsAny(const google::protobuf::Field& field) {
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectwriter.h b/third_party/protobuf/src/google/protobuf/util/internal/protostream_objectwriter.h
index 2e4d14d143..732971e1b7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectwriter.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/protostream_objectwriter.h
@@ -87,8 +87,14 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
// just ignore it and continue to process the rest.
bool ignore_unknown_fields;
+ // If true, check if enum name in camel case or without underscore matches
+ // the field name.
+ bool use_lower_camel_for_enums;
+
Options()
- : struct_integers_as_strings(false), ignore_unknown_fields(false) {}
+ : struct_integers_as_strings(false),
+ ignore_unknown_fields(false),
+ use_lower_camel_for_enums(false) {}
// Default instance of Options with all options set to defaults.
static const Options& Defaults() {
@@ -145,6 +151,57 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
void RenderDataPiece(StringPiece name, const DataPiece& value);
private:
+ // Before the "@type" field is encountered, we store all incoming data
+ // into this Event struct and replay them after we get the "@type" field.
+ class LIBPROTOBUF_EXPORT Event {
+ public:
+ enum Type {
+ START_OBJECT = 0,
+ END_OBJECT = 1,
+ START_LIST = 2,
+ END_LIST = 3,
+ RENDER_DATA_PIECE = 4,
+ };
+
+ // Constructor for END_OBJECT and END_LIST events.
+ explicit Event(Type type) : type_(type), value_(DataPiece::NullData()) {}
+
+ // Constructor for START_OBJECT and START_LIST events.
+ explicit Event(Type type, StringPiece name)
+ : type_(type),
+ name_(name.ToString()),
+ value_(DataPiece::NullData()) {}
+
+ // Constructor for RENDER_DATA_PIECE events.
+ explicit Event(StringPiece name, const DataPiece& value)
+ : type_(RENDER_DATA_PIECE), name_(name.ToString()), value_(value) {
+ DeepCopy();
+ }
+
+ Event(const Event& other)
+ : type_(other.type_), name_(other.name_), value_(other.value_) {
+ DeepCopy();
+ }
+
+ Event& operator=(const Event& other) {
+ type_ = other.type_;
+ name_ = other.name_;
+ value_ = other.value_;
+ DeepCopy();
+ return *this;
+ }
+
+ void Replay(AnyWriter* writer) const;
+
+ private:
+ void DeepCopy();
+
+ Type type_;
+ string name_;
+ DataPiece value_;
+ string value_storage_;
+ };
+
// Handles starting up the any once we have a type.
void StartAny(const DataPiece& value);
@@ -180,6 +237,9 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectWriter : public ProtoWriter {
// }
bool is_well_known_type_;
TypeRenderer* well_known_type_render_;
+
+ // Store data before the "@type" field.
+ std::vector<Event> uninterpreted_events_;
};
// Represents an item in a stack of items used to keep state between
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectwriter_test.cc b/third_party/protobuf/src/google/protobuf/util/internal/protostream_objectwriter_test.cc
index 30e58e6279..97ef8fff8b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/protostream_objectwriter_test.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/protostream_objectwriter_test.cc
@@ -41,18 +41,20 @@
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/message.h>
#include <google/protobuf/util/internal/mock_error_listener.h>
+#include <google/protobuf/util/internal/testdata/anys.pb.h>
#include <google/protobuf/util/internal/testdata/books.pb.h>
#include <google/protobuf/util/internal/testdata/field_mask.pb.h>
+#include <google/protobuf/util/internal/testdata/maps.pb.h>
+#include <google/protobuf/util/internal/testdata/oneofs.pb.h>
+#include <google/protobuf/util/internal/testdata/proto3.pb.h>
+#include <google/protobuf/util/internal/testdata/struct.pb.h>
+#include <google/protobuf/util/internal/testdata/timestamp_duration.pb.h>
+#include <google/protobuf/util/internal/testdata/wrappers.pb.h>
#include <google/protobuf/util/internal/type_info_test_helper.h>
#include <google/protobuf/util/internal/constants.h>
#include <google/protobuf/util/message_differencer.h>
#include <google/protobuf/stubs/bytestream.h>
#include <google/protobuf/stubs/strutil.h>
-#include <google/protobuf/util/internal/testdata/anys.pb.h>
-#include <google/protobuf/util/internal/testdata/maps.pb.h>
-#include <google/protobuf/util/internal/testdata/oneofs.pb.h>
-#include <google/protobuf/util/internal/testdata/struct.pb.h>
-#include <google/protobuf/util/internal/testdata/timestamp_duration.pb.h>
#include <gtest/gtest.h>
@@ -61,27 +63,30 @@ namespace protobuf {
namespace util {
namespace converter {
+using google::protobuf::testing::AnyM;
+using google::protobuf::testing::AnyOut;
using google::protobuf::testing::Author;
using google::protobuf::testing::Book;
-using google::protobuf::testing::Book_Data;
+using google::protobuf::testing::FieldMaskTest;
+using google::protobuf::testing::Int32Wrapper;
+using google::protobuf::testing::MapIn;
using google::protobuf::testing::Primitive;
+using google::protobuf::testing::Proto3Message;
using google::protobuf::testing::Publisher;
+using google::protobuf::testing::StructType;
+using google::protobuf::testing::TestJsonName1;
+using google::protobuf::testing::TestJsonName2;
+using google::protobuf::testing::TimestampDuration;
+using google::protobuf::testing::ValueWrapper;
+using google::protobuf::testing::oneofs::OneOfsRequest;
using google::protobuf::Descriptor;
using google::protobuf::DescriptorPool;
using google::protobuf::DynamicMessageFactory;
using google::protobuf::FileDescriptorProto;
using google::protobuf::Message;
-using google::protobuf::io::ArrayInputStream;
using strings::GrowingArrayByteSink;
using ::testing::_;
using ::testing::Args;
-using google::protobuf::testing::anys::AnyM;
-using google::protobuf::testing::anys::AnyOut;
-using google::protobuf::testing::oneofs::OneOfsRequest;
-using google::protobuf::testing::FieldMaskTest;
-using google::protobuf::testing::maps::MapIn;
-using google::protobuf::testing::structs::StructType;
-using google::protobuf::testing::timestampduration::TimestampDuration;
namespace {
@@ -110,13 +115,13 @@ class BaseProtoStreamObjectWriterTest
listener_(),
output_(new GrowingArrayByteSink(1000)),
ow_() {
- vector<const Descriptor*> descriptors;
+ std::vector<const Descriptor*> descriptors;
descriptors.push_back(descriptor);
ResetTypeInfo(descriptors);
}
explicit BaseProtoStreamObjectWriterTest(
- vector<const Descriptor*> descriptors)
+ std::vector<const Descriptor*> descriptors)
: helper_(GetParam()),
listener_(),
output_(new GrowingArrayByteSink(1000)),
@@ -124,7 +129,7 @@ class BaseProtoStreamObjectWriterTest
ResetTypeInfo(descriptors);
}
- void ResetTypeInfo(vector<const Descriptor*> descriptors) {
+ void ResetTypeInfo(std::vector<const Descriptor*> descriptors) {
GOOGLE_CHECK(!descriptors.empty()) << "Must have at least one descriptor!";
helper_.ResetTypeInfo(descriptors);
ow_.reset(helper_.NewProtoWriter(GetTypeUrl(descriptors[0]), output_.get(),
@@ -132,7 +137,7 @@ class BaseProtoStreamObjectWriterTest
}
void ResetTypeInfo(const Descriptor* descriptor) {
- vector<const Descriptor*> descriptors;
+ std::vector<const Descriptor*> descriptors;
descriptors.push_back(descriptor);
ResetTypeInfo(descriptors);
}
@@ -268,6 +273,104 @@ TEST_P(ProtoStreamObjectWriterTest, CustomJsonName) {
CheckOutput(book);
}
+// Test that two messages can have different fields mapped to the same JSON
+// name. See: https://github.com/google/protobuf/issues/1415
+TEST_P(ProtoStreamObjectWriterTest, ConflictingJsonName) {
+ ResetTypeInfo(TestJsonName1::descriptor());
+ TestJsonName1 message1;
+ message1.set_one_value(12345);
+ ow_->StartObject("")
+ ->RenderInt32("value", 12345)
+ ->EndObject();
+ CheckOutput(message1);
+
+ ResetTypeInfo(TestJsonName2::descriptor());
+ TestJsonName2 message2;
+ message2.set_another_value(12345);
+ ow_->StartObject("")
+ ->RenderInt32("value", 12345)
+ ->EndObject();
+ CheckOutput(message2);
+}
+
+TEST_P(ProtoStreamObjectWriterTest, IntEnumValuesAreAccepted) {
+ Book book;
+ book.set_title("Some Book");
+ book.set_type(google::protobuf::testing::Book_Type_KIDS);
+ Author* robert = book.mutable_author();
+ robert->set_name("robert");
+
+ ow_->StartObject("")
+ ->RenderString("title", "Some Book")
+ ->RenderString("type", "2")
+ ->StartObject("author")
+ ->RenderString("name", "robert")
+ ->EndObject()
+ ->EndObject();
+ CheckOutput(book);
+}
+
+TEST_P(ProtoStreamObjectWriterTest, EnumValuesWithoutUnderscoreAreAccepted) {
+ Book book;
+ book.set_title("Some Book");
+ book.set_type(google::protobuf::testing::Book_Type_ACTION_AND_ADVENTURE);
+ Author* robert = book.mutable_author();
+ robert->set_name("robert");
+
+ options_.use_lower_camel_for_enums = true;
+ ResetProtoWriter();
+
+ ow_->StartObject("")
+ ->RenderString("title", "Some Book")
+ ->RenderString("type", "ACTIONANDADVENTURE")
+ ->StartObject("author")
+ ->RenderString("name", "robert")
+ ->EndObject()
+ ->EndObject();
+ CheckOutput(book);
+}
+
+TEST_P(ProtoStreamObjectWriterTest, EnumValuesInCamelCaseAreAccepted) {
+ Book book;
+ book.set_title("Some Book");
+ book.set_type(google::protobuf::testing::Book_Type_ACTION_AND_ADVENTURE);
+ Author* robert = book.mutable_author();
+ robert->set_name("robert");
+
+ options_.use_lower_camel_for_enums = true;
+ ResetProtoWriter();
+
+ ow_->StartObject("")
+ ->RenderString("title", "Some Book")
+ ->RenderString("type", "actionAndAdventure")
+ ->StartObject("author")
+ ->RenderString("name", "robert")
+ ->EndObject()
+ ->EndObject();
+ CheckOutput(book);
+}
+
+TEST_P(ProtoStreamObjectWriterTest,
+ EnumValuesInCamelCaseWithNameNotUppercaseAreAccepted) {
+ Book book;
+ book.set_title("Some Book");
+ book.set_type(google::protobuf::testing::Book_Type_arts_and_photography);
+ Author* robert = book.mutable_author();
+ robert->set_name("robert");
+
+ options_.use_lower_camel_for_enums = true;
+ ResetProtoWriter();
+
+ ow_->StartObject("")
+ ->RenderString("title", "Some Book")
+ ->RenderString("type", "artsAndPhotography")
+ ->StartObject("author")
+ ->RenderString("name", "robert")
+ ->EndObject()
+ ->EndObject();
+ CheckOutput(book);
+}
+
TEST_P(ProtoStreamObjectWriterTest, PrimitiveFromStringConversion) {
Primitive full;
full.set_fix32(101);
@@ -826,6 +929,19 @@ TEST_P(ProtoStreamObjectWriterTest, IgnoreUnknownListAtPublisher) {
CheckOutput(expected);
}
+TEST_P(ProtoStreamObjectWriterTest, AcceptUnknownEnumValue) {
+ ResetTypeInfo(Proto3Message::descriptor());
+
+ Proto3Message expected;
+ expected.set_enum_value(static_cast<Proto3Message::NestedEnum>(12345));
+
+ EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0);
+ ow_->StartObject("")
+ ->RenderInt32("enumValue", 12345)
+ ->EndObject();
+ CheckOutput(expected);
+}
+
TEST_P(ProtoStreamObjectWriterTest, MissingRequiredField) {
Book expected;
expected.set_title("My Title");
@@ -984,7 +1100,7 @@ class ProtoStreamObjectWriterTimestampDurationTest
: public BaseProtoStreamObjectWriterTest {
protected:
ProtoStreamObjectWriterTimestampDurationTest() {
- vector<const Descriptor*> descriptors;
+ std::vector<const Descriptor*> descriptors;
descriptors.push_back(TimestampDuration::descriptor());
descriptors.push_back(google::protobuf::Timestamp::descriptor());
descriptors.push_back(google::protobuf::Duration::descriptor());
@@ -1338,9 +1454,9 @@ TEST_P(ProtoStreamObjectWriterTimestampDurationTest,
InvalidValue(
_, StringPiece("type.googleapis.com/google.protobuf.Timestamp"),
StringPiece(
- "Field 'ts', Invalid data type for timestamp, value is null")))
+ "Field 'ts', Invalid data type for timestamp, value is 1")))
.With(Args<0>(HasObjectLocation("ts")));
- ow_->StartObject("")->RenderNull("ts")->EndObject();
+ ow_->StartObject("")->RenderInt32("ts", 1)->EndObject();
CheckOutput(timestamp);
}
@@ -1352,8 +1468,22 @@ TEST_P(ProtoStreamObjectWriterTimestampDurationTest,
InvalidValue(
_, StringPiece("type.googleapis.com/google.protobuf.Duration"),
StringPiece(
- "Field 'dur', Invalid data type for duration, value is null")))
+ "Field 'dur', Invalid data type for duration, value is 1")))
.With(Args<0>(HasObjectLocation("dur")));
+ ow_->StartObject("")->RenderInt32("dur", 1)->EndObject();
+ CheckOutput(duration);
+}
+
+TEST_P(ProtoStreamObjectWriterTimestampDurationTest, TimestampAcceptsNull) {
+ TimestampDuration timestamp;
+ EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0);
+ ow_->StartObject("")->RenderNull("ts")->EndObject();
+ CheckOutput(timestamp);
+}
+
+TEST_P(ProtoStreamObjectWriterTimestampDurationTest, DurationAcceptsNull) {
+ TimestampDuration duration;
+ EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0);
ow_->StartObject("")->RenderNull("dur")->EndObject();
CheckOutput(duration);
}
@@ -1365,7 +1495,7 @@ class ProtoStreamObjectWriterStructTest
// Resets ProtoWriter with current set of options and other state.
void ResetProtoWriter() {
- vector<const Descriptor*> descriptors;
+ std::vector<const Descriptor*> descriptors;
descriptors.push_back(StructType::descriptor());
descriptors.push_back(google::protobuf::Struct::descriptor());
ResetTypeInfo(descriptors);
@@ -1415,6 +1545,28 @@ TEST_P(ProtoStreamObjectWriterStructTest, StructInvalidInputFailure) {
CheckOutput(struct_type);
}
+TEST_P(ProtoStreamObjectWriterStructTest, StructAcceptsNull) {
+ StructType struct_type;
+ EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0);
+
+ ow_->StartObject("")->RenderNull("object")->EndObject();
+ CheckOutput(struct_type);
+}
+
+TEST_P(ProtoStreamObjectWriterStructTest, StructValuePreservesNull) {
+ StructType struct_type;
+ (*struct_type.mutable_object()->mutable_fields())["key"].set_null_value(
+ google::protobuf::NULL_VALUE);
+ EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0);
+
+ ow_->StartObject("")
+ ->StartObject("object")
+ ->RenderNull("key")
+ ->EndObject()
+ ->EndObject();
+ CheckOutput(struct_type);
+}
+
TEST_P(ProtoStreamObjectWriterStructTest, SimpleRepeatedStructMapKeyTest) {
EXPECT_CALL(
listener_,
@@ -1482,6 +1634,15 @@ TEST_P(ProtoStreamObjectWriterStructTest, OptionStructIntAsStringsTest) {
CheckOutput(struct_type);
}
+TEST_P(ProtoStreamObjectWriterStructTest, ValuePreservesNull) {
+ ValueWrapper value;
+ value.mutable_value()->set_null_value(google::protobuf::NULL_VALUE);
+
+ EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0);
+ ow_->StartObject("")->RenderNull("value")->EndObject();
+ CheckOutput(value);
+}
+
class ProtoStreamObjectWriterMapTest : public BaseProtoStreamObjectWriterTest {
protected:
ProtoStreamObjectWriterMapTest()
@@ -1525,13 +1686,16 @@ TEST_P(ProtoStreamObjectWriterMapTest, RepeatedMapKeyTest) {
class ProtoStreamObjectWriterAnyTest : public BaseProtoStreamObjectWriterTest {
protected:
ProtoStreamObjectWriterAnyTest() {
- vector<const Descriptor*> descriptors;
+ std::vector<const Descriptor*> descriptors;
descriptors.push_back(AnyOut::descriptor());
+ descriptors.push_back(Book::descriptor());
+ descriptors.push_back(google::protobuf::Any::descriptor());
descriptors.push_back(google::protobuf::DoubleValue::descriptor());
+ descriptors.push_back(google::protobuf::FieldMask::descriptor());
+ descriptors.push_back(google::protobuf::Int32Value::descriptor());
+ descriptors.push_back(google::protobuf::Struct::descriptor());
descriptors.push_back(google::protobuf::Timestamp::descriptor());
- descriptors.push_back(google::protobuf::Any::descriptor());
descriptors.push_back(google::protobuf::Value::descriptor());
- descriptors.push_back(google::protobuf::Struct::descriptor());
ResetTypeInfo(descriptors);
}
};
@@ -1564,8 +1728,7 @@ TEST_P(ProtoStreamObjectWriterAnyTest, RecursiveAny) {
any->set_type_url("type.googleapis.com/google.protobuf.Any");
::google::protobuf::Any nested_any;
- nested_any.set_type_url(
- "type.googleapis.com/google.protobuf.testing.anys.AnyM");
+ nested_any.set_type_url("type.googleapis.com/google.protobuf.testing.AnyM");
AnyM m;
m.set_foo("foovalue");
@@ -1578,11 +1741,12 @@ TEST_P(ProtoStreamObjectWriterAnyTest, RecursiveAny) {
->RenderString("@type", "type.googleapis.com/google.protobuf.Any")
->StartObject("value")
->RenderString("@type",
- "type.googleapis.com/google.protobuf.testing.anys.AnyM")
+ "type.googleapis.com/google.protobuf.testing.AnyM")
->RenderString("foo", "foovalue")
->EndObject()
->EndObject()
->EndObject();
+ CheckOutput(out, 107);
}
TEST_P(ProtoStreamObjectWriterAnyTest, DoubleRecursiveAny) {
@@ -1595,7 +1759,7 @@ TEST_P(ProtoStreamObjectWriterAnyTest, DoubleRecursiveAny) {
::google::protobuf::Any second_nested_any;
second_nested_any.set_type_url(
- "type.googleapis.com/google.protobuf.testing.anys.AnyM");
+ "type.googleapis.com/google.protobuf.testing.AnyM");
AnyM m;
m.set_foo("foovalue");
@@ -1611,18 +1775,110 @@ TEST_P(ProtoStreamObjectWriterAnyTest, DoubleRecursiveAny) {
->RenderString("@type", "type.googleapis.com/google.protobuf.Any")
->StartObject("value")
->RenderString("@type",
- "type.googleapis.com/google.protobuf.testing.anys.AnyM")
+ "type.googleapis.com/google.protobuf.testing.AnyM")
->RenderString("foo", "foovalue")
->EndObject()
->EndObject()
->EndObject()
->EndObject();
+ CheckOutput(out, 151);
+}
+
+TEST_P(ProtoStreamObjectWriterAnyTest, TypeUrlAtEnd) {
+ Book book;
+ book.set_title("C++");
+ book.set_length(1234);
+ book.set_content("Hello World!");
+
+ ::google::protobuf::Any any;
+ any.PackFrom(book);
+
+ ::google::protobuf::Any outer_any;
+ outer_any.PackFrom(any);
+
+ AnyOut out;
+ out.mutable_any()->PackFrom(outer_any);
+
+ // Put the @type field at the end of each Any message. Parsers should
+ // be able to accept that.
+ ow_->StartObject("")
+ ->StartObject("any")
+ ->StartObject("value")
+ ->StartObject("value")
+ ->RenderString("title", "C++")
+ ->RenderInt32("length", 1234)
+ ->RenderBytes("content", "Hello World!")
+ ->RenderString("@type",
+ "type.googleapis.com/google.protobuf.testing.Book")
+ ->EndObject()
+ ->RenderString("@type", "type.googleapis.com/google.protobuf.Any")
+ ->EndObject()
+ ->RenderString("@type", "type.googleapis.com/google.protobuf.Any")
+ ->EndObject()
+ ->EndObject();
+ CheckOutput(out);
+}
+
+// Same as TypeUrlAtEnd, but use temporary string values to make sure we don't
+// mistakenly store StringPiece objects pointing to invalid memory.
+TEST_P(ProtoStreamObjectWriterAnyTest, TypeUrlAtEndWithTemporaryStrings) {
+ Book book;
+ book.set_title("C++");
+ book.set_length(1234);
+ book.set_content("Hello World!");
+
+ ::google::protobuf::Any any;
+ any.PackFrom(book);
+
+ ::google::protobuf::Any outer_any;
+ outer_any.PackFrom(any);
+
+ AnyOut out;
+ out.mutable_any()->PackFrom(outer_any);
+
+ string name, value;
+ // Put the @type field at the end of each Any message. Parsers should
+ // be able to accept that.
+ ow_->StartObject("")->StartObject("any");
+ {
+ ow_->StartObject("value");
+ {
+ ow_->StartObject("value");
+ {
+ name = "title";
+ value = "C++";
+ ow_->RenderString(name, value);
+ name = "length";
+ ow_->RenderInt32(name, 1234);
+ name = "content";
+ value = "Hello World!";
+ ow_->RenderBytes(name, value);
+ name = "@type";
+ value = "type.googleapis.com/google.protobuf.testing.Book";
+ ow_->RenderString(name, value);
+ }
+ ow_->EndObject();
+
+ name = "@type";
+ value = "type.googleapis.com/google.protobuf.Any";
+ ow_->RenderString(name, value);
+ }
+ ow_->EndObject();
+
+ name = "@type";
+ value = "type.googleapis.com/google.protobuf.Any";
+ ow_->RenderString(name, value);
+ }
+ ow_->EndObject()->EndObject();
+ CheckOutput(out);
}
TEST_P(ProtoStreamObjectWriterAnyTest, EmptyAnyFromEmptyObject) {
AnyOut out;
out.mutable_any();
+ EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0);
+
ow_->StartObject("")->StartObject("any")->EndObject()->EndObject();
CheckOutput(out, 2);
@@ -1631,11 +1887,10 @@ TEST_P(ProtoStreamObjectWriterAnyTest, EmptyAnyFromEmptyObject) {
TEST_P(ProtoStreamObjectWriterAnyTest, AnyWithoutTypeUrlFails1) {
AnyOut any;
- EXPECT_CALL(
- listener_,
- InvalidValue(_, StringPiece("Any"),
- StringPiece("Missing or invalid @type for any field in "
- "google.protobuf.testing.anys.AnyOut")));
+ EXPECT_CALL(listener_,
+ InvalidValue(_, StringPiece("Any"),
+ StringPiece("Missing @type for any field in "
+ "google.protobuf.testing.AnyOut")));
ow_->StartObject("")
->StartObject("any")
@@ -1649,11 +1904,10 @@ TEST_P(ProtoStreamObjectWriterAnyTest, AnyWithoutTypeUrlFails1) {
TEST_P(ProtoStreamObjectWriterAnyTest, AnyWithoutTypeUrlFails2) {
AnyOut any;
- EXPECT_CALL(
- listener_,
- InvalidValue(_, StringPiece("Any"),
- StringPiece("Missing or invalid @type for any field in "
- "google.protobuf.testing.anys.AnyOut")));
+ EXPECT_CALL(listener_,
+ InvalidValue(_, StringPiece("Any"),
+ StringPiece("Missing @type for any field in "
+ "google.protobuf.testing.AnyOut")));
ow_->StartObject("")
->StartObject("any")
@@ -1667,11 +1921,10 @@ TEST_P(ProtoStreamObjectWriterAnyTest, AnyWithoutTypeUrlFails2) {
TEST_P(ProtoStreamObjectWriterAnyTest, AnyWithoutTypeUrlFails3) {
AnyOut any;
- EXPECT_CALL(
- listener_,
- InvalidValue(_, StringPiece("Any"),
- StringPiece("Missing or invalid @type for any field in "
- "google.protobuf.testing.anys.AnyOut")));
+ EXPECT_CALL(listener_,
+ InvalidValue(_, StringPiece("Any"),
+ StringPiece("Missing @type for any field in "
+ "google.protobuf.testing.AnyOut")));
ow_->StartObject("")
->StartObject("any")
@@ -1716,9 +1969,21 @@ TEST_P(ProtoStreamObjectWriterAnyTest, AnyWithUnknownTypeFails) {
CheckOutput(any);
}
-TEST_P(ProtoStreamObjectWriterAnyTest, AnyNullInputFails) {
+TEST_P(ProtoStreamObjectWriterAnyTest, AnyIncorrectInputTypeFails) {
+ AnyOut any;
+
+ EXPECT_CALL(
+ listener_,
+ InvalidValue(_, StringPiece("type.googleapis.com/google.protobuf.Any"),
+ StringPiece("1")));
+ ow_->StartObject("")->RenderInt32("any", 1)->EndObject();
+ CheckOutput(any);
+}
+
+TEST_P(ProtoStreamObjectWriterAnyTest, AnyAcceptsNull) {
AnyOut any;
+ EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0);
ow_->StartObject("")->RenderNull("any")->EndObject();
CheckOutput(any);
}
@@ -1956,11 +2221,116 @@ TEST_P(ProtoStreamObjectWriterAnyTest, AnyWellKnownTypesExpectObjectForAny) {
CheckOutput(any);
}
+// {
+// "any": {
+// "@type": "type.googleapis.com/google.protobuf.Any",
+// "value": null
+// }
+// }
+TEST_P(ProtoStreamObjectWriterAnyTest, AnyInAnyAcceptsNull) {
+ AnyOut out;
+ google::protobuf::Any empty;
+ out.mutable_any()->PackFrom(empty);
+
+ EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0);
+ ow_->StartObject("")
+ ->StartObject("any")
+ ->RenderString("@type", "type.googleapis.com/google.protobuf.Any")
+ ->RenderNull("value")
+ ->EndObject()
+ ->EndObject();
+ CheckOutput(out);
+}
+
+// {
+// "any": {
+// "@type": "type.googleapis.com/google.protobuf.Timestamp",
+// "value": null
+// }
+// }
+TEST_P(ProtoStreamObjectWriterAnyTest, TimestampInAnyAcceptsNull) {
+ AnyOut out;
+ google::protobuf::Timestamp empty;
+ out.mutable_any()->PackFrom(empty);
+
+ EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0);
+ ow_->StartObject("")
+ ->StartObject("any")
+ ->RenderString("@type", "type.googleapis.com/google.protobuf.Timestamp")
+ ->RenderNull("value")
+ ->EndObject()
+ ->EndObject();
+ CheckOutput(out);
+}
+
+// {
+// "any": {
+// "@type": "type.googleapis.com/google.protobuf.Duration",
+// "value": null
+// }
+// }
+TEST_P(ProtoStreamObjectWriterAnyTest, DurationInAnyAcceptsNull) {
+ AnyOut out;
+ google::protobuf::Duration empty;
+ out.mutable_any()->PackFrom(empty);
+
+ EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0);
+ ow_->StartObject("")
+ ->StartObject("any")
+ ->RenderString("@type", "type.googleapis.com/google.protobuf.Duration")
+ ->RenderNull("value")
+ ->EndObject()
+ ->EndObject();
+ CheckOutput(out);
+}
+
+// {
+// "any": {
+// "@type": "type.googleapis.com/google.protobuf.FieldMask",
+// "value": null
+// }
+// }
+TEST_P(ProtoStreamObjectWriterAnyTest, FieldMaskInAnyAcceptsNull) {
+ AnyOut out;
+ google::protobuf::FieldMask empty;
+ out.mutable_any()->PackFrom(empty);
+
+ EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0);
+ ow_->StartObject("")
+ ->StartObject("any")
+ ->RenderString("@type", "type.googleapis.com/google.protobuf.FieldMask")
+ ->RenderNull("value")
+ ->EndObject()
+ ->EndObject();
+ CheckOutput(out);
+}
+
+// {
+// "any": {
+// "@type": "type.googleapis.com/google.protobuf.Int32Value",
+// "value": null
+// }
+// }
+TEST_P(ProtoStreamObjectWriterAnyTest, WrapperInAnyAcceptsNull) {
+ AnyOut out;
+ google::protobuf::Int32Value empty;
+ out.mutable_any()->PackFrom(empty);
+
+ EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0);
+ ow_->StartObject("")
+ ->StartObject("any")
+ ->RenderString("@type", "type.googleapis.com/google.protobuf.Int32Value")
+ ->RenderNull("value")
+ ->EndObject()
+ ->EndObject();
+ CheckOutput(out);
+}
+
class ProtoStreamObjectWriterFieldMaskTest
: public BaseProtoStreamObjectWriterTest {
protected:
ProtoStreamObjectWriterFieldMaskTest() {
- vector<const Descriptor*> descriptors;
+ std::vector<const Descriptor*> descriptors;
descriptors.push_back(FieldMaskTest::descriptor());
descriptors.push_back(google::protobuf::FieldMask::descriptor());
ResetTypeInfo(descriptors);
@@ -2201,11 +2571,41 @@ TEST_P(ProtoStreamObjectWriterFieldMaskTest, MapKeyCanContainAnyChars) {
CheckOutput(expected);
}
+TEST_P(ProtoStreamObjectWriterFieldMaskTest, FieldMaskAcceptsNull) {
+ FieldMaskTest expected;
+ EXPECT_CALL(listener_, InvalidValue(_, _, _)).Times(0);
+ ow_->StartObject("")->RenderNull("single_mask")->EndObject();
+ CheckOutput(expected);
+}
+
+class ProtoStreamObjectWriterWrappersTest
+ : public BaseProtoStreamObjectWriterTest {
+ protected:
+ ProtoStreamObjectWriterWrappersTest() {
+ std::vector<const Descriptor*> descriptors;
+ descriptors.push_back(Int32Wrapper::descriptor());
+ descriptors.push_back(google::protobuf::Int32Value::descriptor());
+ ResetTypeInfo(descriptors);
+ }
+};
+
+INSTANTIATE_TEST_CASE_P(DifferentTypeInfoSourceTest,
+ ProtoStreamObjectWriterWrappersTest,
+ ::testing::Values(
+ testing::USE_TYPE_RESOLVER));
+
+TEST_P(ProtoStreamObjectWriterWrappersTest, WrapperAcceptsNull) {
+ Int32Wrapper wrapper;
+ EXPECT_CALL(listener_, InvalidName(_, _, _)).Times(0);
+ ow_->StartObject("")->RenderNull("int32")->EndObject();
+ CheckOutput(wrapper);
+}
+
class ProtoStreamObjectWriterOneOfsTest
: public BaseProtoStreamObjectWriterTest {
protected:
ProtoStreamObjectWriterOneOfsTest() {
- vector<const Descriptor*> descriptors;
+ std::vector<const Descriptor*> descriptors;
descriptors.push_back(OneOfsRequest::descriptor());
descriptors.push_back(google::protobuf::Struct::descriptor());
ResetTypeInfo(descriptors);
@@ -2368,7 +2768,6 @@ TEST_P(ProtoStreamObjectWriterOneOfsTest,
StringPiece("oneof field 'data' is already set. "
"Cannot set 'intData'")));
- using google::protobuf::testing::oneofs::OneOfsRequest;
// JSON:
// { "anyData":
// { "@type":
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/structured_objectwriter.h b/third_party/protobuf/src/google/protobuf/util/internal/structured_objectwriter.h
index 3f065d6b1c..3f065d6b1c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/structured_objectwriter.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/structured_objectwriter.h
diff --git a/third_party/protobuf/src/google/protobuf/util/internal/testdata/anys.proto b/third_party/protobuf/src/google/protobuf/util/internal/testdata/anys.proto
new file mode 100644
index 0000000000..a9ebca3d43
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/util/internal/testdata/anys.proto
@@ -0,0 +1,108 @@
+// 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.
+
+syntax = "proto3";
+
+package google.protobuf.testing;
+
+import "google/protobuf/any.proto";
+import "google/protobuf/struct.proto";
+import "google/protobuf/timestamp.proto";
+import "google/protobuf/duration.proto";
+import "google/protobuf/wrappers.proto";
+
+// Top-level test cases proto used by MarshallingTest. See description
+// at the top of the class MarshallingTest for details on how to write
+// test cases.
+message AnyTestCases {
+ AnyWrapper empty_any = 1;
+ AnyWrapper type_only_any = 2;
+ AnyWrapper wrapper_any = 3;
+ AnyWrapper any_with_timestamp_value = 4;
+ AnyWrapper any_with_duration_value = 5;
+ AnyWrapper any_with_struct_value = 6;
+ AnyWrapper recursive_any = 7;
+ AnyWrapper any_with_message_value = 8;
+ AnyWrapper any_with_nested_message = 9;
+ AnyWrapper any_with_message_with_wrapper_type = 10;
+ AnyWrapper any_with_message_with_timestamp = 11;
+ AnyWrapper any_with_message_containing_map = 12;
+ AnyWrapper any_with_message_containing_struct = 13;
+ AnyWrapper any_with_message_containing_repeated_message = 14;
+ AnyWrapper recursive_any_with_type_field_at_end = 15;
+
+ google.protobuf.Any top_level_any = 50;
+ google.protobuf.Any top_level_any_with_type_field_at_end = 51;
+}
+
+message AnyWrapper {
+ google.protobuf.Any any = 1;
+}
+
+// Hack to make sure the types we put into the any are included in the types.
+// Real solution is to add these types to the service config.
+message Imports {
+ google.protobuf.DoubleValue dbl = 1;
+ google.protobuf.Struct struct = 2;
+ google.protobuf.Timestamp timestamp = 3;
+ google.protobuf.Duration duration = 4;
+ google.protobuf.Int32Value i32 = 5;
+ Data data = 100;
+}
+
+message Data {
+ int32 attr = 1;
+ string str = 2;
+ repeated string msgs = 3;
+ Data nested_data = 4;
+ google.protobuf.Int32Value int_wrapper = 5;
+ google.protobuf.Timestamp time = 6;
+ map<string, string> map_data = 7;
+ google.protobuf.Struct struct_data = 8;
+ repeated Data repeated_data = 9;
+}
+
+service AnyTestService {
+ rpc Call(AnyTestCases) returns (AnyTestCases);
+ rpc Call1(Imports) returns (Imports);
+}
+
+message AnyIn {
+ string something = 1;
+ google.protobuf.Any any = 2;
+}
+
+message AnyOut {
+ google.protobuf.Any any = 1;
+}
+
+message AnyM {
+ string foo = 1;
+}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/books.proto b/third_party/protobuf/src/google/protobuf/util/internal/testdata/books.proto
index 1cbbba4781..869271f4e5 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/books.proto
+++ b/third_party/protobuf/src/google/protobuf/util/internal/testdata/books.proto
@@ -31,6 +31,10 @@
// Author: sven@google.com (Sven Mawson)
//
// Sample protos for testing.
+
+// Some of the older enums don't use CAPITALS_WITH_UNDERSCORES for testing.
+// LINT: LEGACY_NAMES
+
syntax = "proto2";
package google.protobuf.testing;
@@ -60,6 +64,7 @@ message Book {
FICTION = 1;
KIDS = 2;
ACTION_AND_ADVENTURE = 3;
+ arts_and_photography = 4;
}
optional Type type = 11;
@@ -185,3 +190,12 @@ message Cyclic {
repeated Author m_author = 5;
optional Cyclic m_cyclic = 4;
}
+
+// Test that two messages can have different fields mapped to the same JSON
+// name. See: https://github.com/google/protobuf/issues/1415
+message TestJsonName1 {
+ optional int32 one_value = 1 [json_name = "value"];
+}
+message TestJsonName2 {
+ optional int32 another_value = 1 [json_name = "value"];
+}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/default_value.proto b/third_party/protobuf/src/google/protobuf/util/internal/testdata/default_value.proto
index cccc741c2d..cccc741c2d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/default_value.proto
+++ b/third_party/protobuf/src/google/protobuf/util/internal/testdata/default_value.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/default_value_test.proto b/third_party/protobuf/src/google/protobuf/util/internal/testdata/default_value_test.proto
index 932883410e..932883410e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/default_value_test.proto
+++ b/third_party/protobuf/src/google/protobuf/util/internal/testdata/default_value_test.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/field_mask.proto b/third_party/protobuf/src/google/protobuf/util/internal/testdata/field_mask.proto
index e8b2bc5f2e..e8b2bc5f2e 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/field_mask.proto
+++ b/third_party/protobuf/src/google/protobuf/util/internal/testdata/field_mask.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/maps.proto b/third_party/protobuf/src/google/protobuf/util/internal/testdata/maps.proto
index 6475ecddc2..0f381b320b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/maps.proto
+++ b/third_party/protobuf/src/google/protobuf/util/internal/testdata/maps.proto
@@ -28,11 +28,76 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Proto to test proto3 maps.
syntax = "proto3";
-package google.protobuf.testing.maps;
-option java_package = "com.google.protobuf.testing.maps";
+package google.protobuf.testing;
+
+// Top-level test cases proto used by MarshallingTest. See description
+// at the top of the class MarshallingTest for details on how to write
+// test cases.
+message MapsTestCases {
+ EmptyMap empty_map = 1;
+ StringtoInt string_to_int = 2;
+ IntToString int_to_string = 3;
+ Mixed1 mixed1 = 4;
+ Mixed2 mixed2 = 5;
+ MapOfObjects map_of_objects = 6;
+
+ // Empty key tests
+ StringtoInt empty_key_string_to_int1 = 7;
+ StringtoInt empty_key_string_to_int2 = 8;
+ StringtoInt empty_key_string_to_int3 = 9;
+ BoolToString empty_key_bool_to_string = 10;
+ IntToString empty_key_int_to_string = 11;
+ Mixed1 empty_key_mixed = 12;
+ MapOfObjects empty_key_map_objects = 13;
+}
+
+message EmptyMap {
+ map<int32, int32> map = 1;
+}
+
+message StringtoInt {
+ map<string, int32> map = 1;
+}
+
+message IntToString {
+ map<int32, string> map = 1;
+}
+
+message BoolToString {
+ map<bool, string> map = 1;
+}
+
+message Mixed1 {
+ string msg = 1;
+ map<string, float> map = 2;
+}
+
+message Mixed2 {
+ enum E {
+ E0 = 0;
+ E1 = 1;
+ E2 = 2;
+ E3 = 3;
+ }
+ map<int32, bool> map = 1;
+ E ee = 2;
+}
+
+message MapOfObjects {
+ message M {
+ string inner_text = 1;
+ }
+ map<string, M> map = 1;
+}
+
+message DummyRequest {
+}
+
+service MapsTestService {
+ rpc Call(DummyRequest) returns (MapsTestCases);
+}
message MapIn {
string other = 1;
@@ -79,8 +144,3 @@ message MapOutWireFormat {
message MapM {
string foo = 1;
}
-
-service TestService {
- rpc Call1(MapIn) returns (MapOut);
- rpc Call2(MapIn) returns (MapOut);
-}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/oneofs.proto b/third_party/protobuf/src/google/protobuf/util/internal/testdata/oneofs.proto
index 5bc9fa084d..c37da08316 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/oneofs.proto
+++ b/third_party/protobuf/src/google/protobuf/util/internal/testdata/oneofs.proto
@@ -28,7 +28,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// Proto to test oneofs.
+// Proto to test proto3 oneofs.
syntax = "proto3";
import "google/protobuf/any.proto";
@@ -36,7 +36,6 @@ import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";
package google.protobuf.testing.oneofs;
-option java_package = "com.google.protobuf.testing.oneofs";
message OneOfsRequest {
string value = 1;
@@ -45,24 +44,34 @@ message OneOfsRequest {
int32 int_data = 3;
// Simple message
Data message_data = 4;
+ MoreData more_data = 5;
// Well known types
- google.protobuf.Struct struct_data = 5;
- google.protobuf.Value value_data = 6;
- google.protobuf.ListValue list_value_data = 7;
- google.protobuf.Timestamp ts_data = 8;
+ google.protobuf.Struct struct_data = 6;
+ google.protobuf.Value value_data = 7;
+ google.protobuf.ListValue list_value_data = 8;
+ google.protobuf.Timestamp ts_data = 9;
}
google.protobuf.Any any_data = 19;
}
+message RequestWithSimpleOneof {
+ string value = 1;
+ oneof data {
+ string str_data = 2;
+ int32 int_data = 3;
+ Data message_data = 4;
+ MoreData more_data = 5;
+ }
+}
+
message Data {
int32 data_value = 1;
}
-message Response {
- string value = 1;
+message MoreData {
+ string str_value = 1;
}
-service TestService {
- // Test call.
- rpc Call(OneOfsRequest) returns (Response);
+message Response {
+ string value = 1;
}
diff --git a/third_party/protobuf/src/google/protobuf/util/internal/testdata/proto3.proto b/third_party/protobuf/src/google/protobuf/util/internal/testdata/proto3.proto
new file mode 100644
index 0000000000..c013cee31e
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/util/internal/testdata/proto3.proto
@@ -0,0 +1,42 @@
+// 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.
+
+syntax = "proto3";
+
+package google.protobuf.testing;
+
+message Proto3Message {
+ enum NestedEnum {
+ FOO = 0;
+ BAR = 1;
+ BAZ = 2;
+ }
+ NestedEnum enum_value = 1;
+}
diff --git a/third_party/protobuf/src/google/protobuf/util/internal/testdata/struct.proto b/third_party/protobuf/src/google/protobuf/util/internal/testdata/struct.proto
new file mode 100644
index 0000000000..7b1cc1b954
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/util/internal/testdata/struct.proto
@@ -0,0 +1,117 @@
+// 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.
+
+syntax = "proto3";
+
+package google.protobuf.testing;
+
+import "google/protobuf/struct.proto";
+
+message StructTestCases {
+ StructWrapper empty_value = 1;
+ StructWrapper empty_value2 = 2;
+ StructWrapper null_value = 3;
+ StructWrapper simple_struct = 4;
+ StructWrapper longer_struct = 5;
+ StructWrapper struct_with_nested_struct = 6;
+ StructWrapper struct_with_nested_list = 7;
+ StructWrapper struct_with_list_of_nulls = 8;
+ StructWrapper struct_with_list_of_lists = 9;
+ StructWrapper struct_with_list_of_structs = 10;
+ StructWrapper struct_with_empty_list = 11;
+ StructWrapper struct_with_list_with_empty_struct = 12;
+ google.protobuf.Struct top_level_struct = 13;
+ google.protobuf.Struct top_level_struct_with_empty_list = 14;
+ google.protobuf.Struct top_level_struct_with_list_with_empty_struct = 15;
+ ValueWrapper value_wrapper_simple = 16;
+ ValueWrapper value_wrapper_with_struct = 17;
+ ValueWrapper value_wrapper_with_list = 18;
+ ValueWrapper value_wrapper_with_empty_list = 19;
+ ValueWrapper value_wrapper_with_list_with_empty_struct = 20;
+ ListValueWrapper list_value_wrapper = 21;
+ ListValueWrapper list_value_wrapper_with_empty_list = 22;
+ ListValueWrapper list_value_wrapper_with_list_with_empty_struct = 23;
+ google.protobuf.Value top_level_value_simple = 24;
+ google.protobuf.Value top_level_value_with_struct = 25;
+ google.protobuf.Value top_level_value_with_list = 26;
+ google.protobuf.Value top_level_value_with_empty_list = 27;
+ google.protobuf.Value top_level_value_with_list_with_empty_struct = 28;
+ google.protobuf.ListValue top_level_listvalue = 29;
+ google.protobuf.ListValue top_level_empty_listvalue = 30;
+ google.protobuf.ListValue top_level_listvalue_with_empty_struct = 31;
+ RepeatedValueWrapper repeated_value = 32;
+ RepeatedValueWrapper repeated_value_nested_list = 33;
+ RepeatedValueWrapper repeated_value_nested_list2 = 34;
+ RepeatedValueWrapper repeated_value_nested_list3 = 35;
+ RepeatedListValueWrapper repeated_listvalue = 36;
+ MapOfStruct map_of_struct = 37;
+ MapOfStruct map_of_struct_value = 38;
+ MapOfStruct map_of_listvalue = 39;
+}
+
+message StructWrapper {
+ google.protobuf.Struct struct = 1;
+}
+
+message ValueWrapper {
+ google.protobuf.Value value = 1;
+}
+
+message RepeatedValueWrapper {
+ repeated google.protobuf.Value values = 1;
+}
+
+message ListValueWrapper {
+ google.protobuf.ListValue shopping_list = 1;
+}
+
+message RepeatedListValueWrapper {
+ repeated google.protobuf.ListValue dimensions = 1;
+}
+
+message MapOfStruct {
+ map<string, google.protobuf.Struct> struct_map = 1;
+ map<string, google.protobuf.Value> value_map = 2;
+ map<string, google.protobuf.ListValue> listvalue_map = 3;
+}
+
+// Hack to test return types with Struct as top-level message. Struct typers
+// cannot be directly used in API requests. Hence using Dummy as request type.
+message Dummy {
+ string text = 1;
+}
+
+service StructTestService {
+ rpc Call(Dummy) returns (StructTestCases);
+}
+
+message StructType {
+ google.protobuf.Struct object = 1;
+}
diff --git a/third_party/protobuf/src/google/protobuf/util/internal/testdata/timestamp_duration.proto b/third_party/protobuf/src/google/protobuf/util/internal/testdata/timestamp_duration.proto
new file mode 100644
index 0000000000..b74484ce58
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/util/internal/testdata/timestamp_duration.proto
@@ -0,0 +1,80 @@
+// 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.
+
+syntax = "proto3";
+
+package google.protobuf.testing;
+
+import "google/protobuf/timestamp.proto";
+import "google/protobuf/duration.proto";
+
+message TimestampDurationTestCases {
+ // Timestamp tests
+ TimeStampType epoch = 1;
+ TimeStampType epoch2 = 2;
+ TimeStampType mintime = 3;
+ TimeStampType maxtime = 4;
+ TimeStampType timeval1 = 5;
+ TimeStampType timeval2 = 6;
+ TimeStampType timeval3 = 7;
+ TimeStampType timeval4 = 8;
+ TimeStampType timeval5 = 9;
+ TimeStampType timeval6 = 10;
+ TimeStampType timeval7 = 11;
+ google.protobuf.Timestamp timeval8 = 12;
+
+ // Duration tests
+ DurationType zero_duration = 101;
+ DurationType min_duration = 102;
+ DurationType max_duration = 103;
+ DurationType duration1 = 104;
+ DurationType duration2 = 105;
+ DurationType duration3 = 106;
+ DurationType duration4 = 107;
+ google.protobuf.Duration duration5 = 108;
+}
+
+message TimeStampType {
+ google.protobuf.Timestamp timestamp = 1;
+}
+
+message DurationType {
+ google.protobuf.Duration duration = 1;
+}
+
+service TimestampDurationTestService {
+ rpc Call(TimestampDurationTestCases) returns (TimestampDurationTestCases);
+}
+
+message TimestampDuration {
+ google.protobuf.Timestamp ts = 1;
+ google.protobuf.Duration dur = 2;
+ repeated google.protobuf.Timestamp rep_ts = 3;
+}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/wrappers.proto b/third_party/protobuf/src/google/protobuf/util/internal/testdata/wrappers.proto
index eabc99f245..eabc99f245 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/testdata/wrappers.proto
+++ b/third_party/protobuf/src/google/protobuf/util/internal/testdata/wrappers.proto
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/type_info.cc b/third_party/protobuf/src/google/protobuf/util/internal/type_info.cc
index 00a8ee7a2a..a5d903f146 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/type_info.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/type_info.cc
@@ -60,7 +60,8 @@ class TypeInfoForTypeResolver : public TypeInfo {
virtual util::StatusOr<const google::protobuf::Type*> ResolveTypeUrl(
StringPiece type_url) const {
- map<StringPiece, StatusOrType>::iterator it = cached_types_.find(type_url);
+ std::map<StringPiece, StatusOrType>::iterator it =
+ cached_types_.find(type_url);
if (it != cached_types_.end()) {
return it->second;
}
@@ -85,7 +86,8 @@ class TypeInfoForTypeResolver : public TypeInfo {
virtual const google::protobuf::Enum* GetEnumByTypeUrl(
StringPiece type_url) const {
- map<StringPiece, StatusOrEnum>::iterator it = cached_enums_.find(type_url);
+ std::map<StringPiece, StatusOrEnum>::iterator it =
+ cached_enums_.find(type_url);
if (it != cached_enums_.end()) {
return it->second.ok() ? it->second.ValueOrDie() : NULL;
}
@@ -105,12 +107,12 @@ class TypeInfoForTypeResolver : public TypeInfo {
virtual const google::protobuf::Field* FindField(
const google::protobuf::Type* type, StringPiece camel_case_name) const {
- if (indexed_types_.find(type) == indexed_types_.end()) {
- PopulateNameLookupTable(type);
- indexed_types_.insert(type);
- }
+ std::map<const google::protobuf::Type*,
+ CamelCaseNameTable>::const_iterator it = indexed_types_.find(type);
+ const CamelCaseNameTable& camel_case_name_table = (it == indexed_types_.end())
+ ? PopulateNameLookupTable(type, &indexed_types_[type]) : it->second;
StringPiece name =
- FindWithDefault(camel_case_name_table_, camel_case_name, StringPiece());
+ FindWithDefault(camel_case_name_table, camel_case_name, StringPiece());
if (name.empty()) {
// Didn't find a mapping. Use whatever provided.
name = camel_case_name;
@@ -121,10 +123,11 @@ class TypeInfoForTypeResolver : public TypeInfo {
private:
typedef util::StatusOr<const google::protobuf::Type*> StatusOrType;
typedef util::StatusOr<const google::protobuf::Enum*> StatusOrEnum;
+ typedef std::map<StringPiece, StringPiece> CamelCaseNameTable;
template <typename T>
- static void DeleteCachedTypes(map<StringPiece, T>* cached_types) {
- for (typename map<StringPiece, T>::iterator it = cached_types->begin();
+ static void DeleteCachedTypes(std::map<StringPiece, T>* cached_types) {
+ for (typename std::map<StringPiece, T>::iterator it = cached_types->begin();
it != cached_types->end(); ++it) {
if (it->second.ok()) {
delete it->second.ValueOrDie();
@@ -132,32 +135,35 @@ class TypeInfoForTypeResolver : public TypeInfo {
}
}
- void PopulateNameLookupTable(const google::protobuf::Type* type) const {
+ const CamelCaseNameTable& PopulateNameLookupTable(
+ const google::protobuf::Type* type,
+ CamelCaseNameTable* camel_case_name_table) const {
for (int i = 0; i < type->fields_size(); ++i) {
const google::protobuf::Field& field = type->fields(i);
StringPiece name = field.name();
StringPiece camel_case_name = field.json_name();
const StringPiece* existing = InsertOrReturnExisting(
- &camel_case_name_table_, camel_case_name, name);
+ camel_case_name_table, camel_case_name, name);
if (existing && *existing != name) {
GOOGLE_LOG(WARNING) << "Field '" << name << "' and '" << *existing
<< "' map to the same camel case name '" << camel_case_name
<< "'.";
}
}
+ return *camel_case_name_table;
}
TypeResolver* type_resolver_;
// Stores string values that will be referenced by StringPieces in
- // cached_types_, cached_enums_ and camel_case_name_table_.
- mutable set<string> string_storage_;
+ // cached_types_, cached_enums_.
+ mutable std::set<string> string_storage_;
- mutable map<StringPiece, StatusOrType> cached_types_;
- mutable map<StringPiece, StatusOrEnum> cached_enums_;
+ mutable std::map<StringPiece, StatusOrType> cached_types_;
+ mutable std::map<StringPiece, StatusOrEnum> cached_enums_;
- mutable set<const google::protobuf::Type*> indexed_types_;
- mutable map<StringPiece, StringPiece> camel_case_name_table_;
+ mutable std::map<const google::protobuf::Type*,
+ CamelCaseNameTable> indexed_types_;
};
} // namespace
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/type_info.h b/third_party/protobuf/src/google/protobuf/util/internal/type_info.h
index d81331763a..d81331763a 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/type_info.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/type_info.h
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/type_info_test_helper.cc b/third_party/protobuf/src/google/protobuf/util/internal/type_info_test_helper.cc
index 49e18ed0ff..737ba9e475 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/type_info_test_helper.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/type_info_test_helper.cc
@@ -55,7 +55,7 @@ namespace testing {
void TypeInfoTestHelper::ResetTypeInfo(
- const vector<const Descriptor*>& descriptors) {
+ const std::vector<const Descriptor*>& descriptors) {
switch (type_) {
case USE_TYPE_RESOLVER: {
const DescriptorPool* pool = descriptors[0]->file()->pool();
@@ -73,14 +73,14 @@ void TypeInfoTestHelper::ResetTypeInfo(
}
void TypeInfoTestHelper::ResetTypeInfo(const Descriptor* descriptor) {
- vector<const Descriptor*> descriptors;
+ std::vector<const Descriptor*> descriptors;
descriptors.push_back(descriptor);
ResetTypeInfo(descriptors);
}
void TypeInfoTestHelper::ResetTypeInfo(const Descriptor* descriptor1,
const Descriptor* descriptor2) {
- vector<const Descriptor*> descriptors;
+ std::vector<const Descriptor*> descriptors;
descriptors.push_back(descriptor1);
descriptors.push_back(descriptor2);
ResetTypeInfo(descriptors);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/type_info_test_helper.h b/third_party/protobuf/src/google/protobuf/util/internal/type_info_test_helper.h
index 1a279849ab..1a1967156b 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/type_info_test_helper.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/type_info_test_helper.h
@@ -64,7 +64,7 @@ class TypeInfoTestHelper {
explicit TypeInfoTestHelper(TypeInfoSource type) : type_(type) {}
// Creates a TypeInfo object for the given set of descriptors.
- void ResetTypeInfo(const vector<const Descriptor*>& descriptors);
+ void ResetTypeInfo(const std::vector<const Descriptor*>& descriptors);
// Convinent overloads.
void ResetTypeInfo(const Descriptor* descriptor);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/utility.cc b/third_party/protobuf/src/google/protobuf/util/internal/utility.cc
index 5f613e77e4..6daf24eb56 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/utility.cc
+++ b/third_party/protobuf/src/google/protobuf/util/internal/utility.cc
@@ -30,6 +30,8 @@
#include <google/protobuf/util/internal/utility.h>
+#include <algorithm>
+
#include <google/protobuf/stubs/callback.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/logging.h>
@@ -178,6 +180,19 @@ const google::protobuf::Field* FindJsonFieldInTypeOrNull(
return NULL;
}
+const google::protobuf::Field* FindFieldInTypeByNumberOrNull(
+ const google::protobuf::Type* type, int32 number) {
+ if (type != NULL) {
+ for (int i = 0; i < type->fields_size(); ++i) {
+ const google::protobuf::Field& field = type->fields(i);
+ if (field.number() == number) {
+ return &field;
+ }
+ }
+ }
+ return NULL;
+}
+
const google::protobuf::EnumValue* FindEnumValueByNameOrNull(
const google::protobuf::Enum* enum_type, StringPiece enum_name) {
if (enum_type != NULL) {
@@ -204,6 +219,32 @@ const google::protobuf::EnumValue* FindEnumValueByNumberOrNull(
return NULL;
}
+const google::protobuf::EnumValue* FindEnumValueByNameWithoutUnderscoreOrNull(
+ const google::protobuf::Enum* enum_type, StringPiece enum_name) {
+ if (enum_type != NULL) {
+ for (int i = 0; i < enum_type->enumvalue_size(); ++i) {
+ const google::protobuf::EnumValue& enum_value = enum_type->enumvalue(i);
+ string enum_name_without_underscore = enum_value.name();
+
+ // Remove underscore from the name.
+ enum_name_without_underscore.erase(
+ std::remove(enum_name_without_underscore.begin(),
+ enum_name_without_underscore.end(), '_'),
+ enum_name_without_underscore.end());
+ // Make the name uppercase.
+ for (string::iterator it = enum_name_without_underscore.begin();
+ it != enum_name_without_underscore.end(); ++it) {
+ *it = ascii_toupper(*it);
+ }
+
+ if (enum_name_without_underscore == enum_name) {
+ return &enum_value;
+ }
+ }
+ }
+ return NULL;
+}
+
string ToCamelCase(const StringPiece input) {
bool capitalize_next = false;
bool was_cap = true;
@@ -283,7 +324,7 @@ string ToSnakeCase(StringPiece input) {
return result;
}
-set<string>* well_known_types_ = NULL;
+std::set<string>* well_known_types_ = NULL;
GOOGLE_PROTOBUF_DECLARE_ONCE(well_known_types_init_);
const char* well_known_types_name_array_[] = {
"google.protobuf.Timestamp", "google.protobuf.Duration",
@@ -296,7 +337,7 @@ const char* well_known_types_name_array_[] = {
void DeleteWellKnownTypes() { delete well_known_types_; }
void InitWellKnownTypes() {
- well_known_types_ = new set<string>;
+ well_known_types_ = new std::set<string>;
for (int i = 0; i < GOOGLE_ARRAYSIZE(well_known_types_name_array_); ++i) {
well_known_types_->insert(well_known_types_name_array_[i]);
}
@@ -315,15 +356,25 @@ bool IsValidBoolString(const string& bool_string) {
bool IsMap(const google::protobuf::Field& field,
const google::protobuf::Type& type) {
- return (field.cardinality() ==
- google::protobuf::Field_Cardinality_CARDINALITY_REPEATED &&
+ return field.cardinality() ==
+ google::protobuf::Field_Cardinality_CARDINALITY_REPEATED &&
+ (GetBoolOptionOrDefault(type.options(), "map_entry", false) ||
+ GetBoolOptionOrDefault(type.options(),
+ "google.protobuf.MessageOptions.map_entry", false) ||
GetBoolOptionOrDefault(type.options(),
- "google.protobuf.MessageOptions.map_entry", false));
+ "google.protobuf.MessageOptions.map_entry",
+ false));
}
bool IsMessageSetWireFormat(const google::protobuf::Type& type) {
- return GetBoolOptionOrDefault(
- type.options(), "google.protobuf.MessageOptions.message_set_wire_format", false);
+ return GetBoolOptionOrDefault(type.options(), "message_set_wire_format",
+ false) ||
+ GetBoolOptionOrDefault(type.options(),
+ "google.protobuf.MessageOptions.message_set_wire_format",
+ false) ||
+ GetBoolOptionOrDefault(
+ type.options(),
+ "google.protobuf.MessageOptions.message_set_wire_format", false);
}
string DoubleAsString(double value) {
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/utility.h b/third_party/protobuf/src/google/protobuf/util/internal/utility.h
index 26fed4445e..667e660c58 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/internal/utility.h
+++ b/third_party/protobuf/src/google/protobuf/util/internal/utility.h
@@ -136,6 +136,10 @@ const google::protobuf::Field* FindFieldInTypeOrNull(
const google::protobuf::Field* FindJsonFieldInTypeOrNull(
const google::protobuf::Type* type, StringPiece json_name);
+// Similar to FindFieldInTypeOrNull, but this looks up fields by number.
+const google::protobuf::Field* FindFieldInTypeByNumberOrNull(
+ const google::protobuf::Type* type, int32 number);
+
// Finds and returns the EnumValue identified by enum_name in the passed tech
// Enum object. Returns NULL if none found.
const google::protobuf::EnumValue* FindEnumValueByNameOrNull(
@@ -146,6 +150,13 @@ const google::protobuf::EnumValue* FindEnumValueByNameOrNull(
const google::protobuf::EnumValue* FindEnumValueByNumberOrNull(
const google::protobuf::Enum* enum_type, int32 value);
+// Finds and returns the EnumValue identified by enum_name without underscore in
+// the passed tech Enum object. Returns NULL if none found.
+// For Ex. if enum_name is ACTIONANDADVENTURE it can get accepted if
+// EnumValue's name is action_and_adventure or ACTION_AND_ADVENTURE.
+const google::protobuf::EnumValue* FindEnumValueByNameWithoutUnderscoreOrNull(
+ const google::protobuf::Enum* enum_type, StringPiece enum_name);
+
// Converts input to camel-case and returns it.
LIBPROTOBUF_EXPORT string ToCamelCase(const StringPiece input);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/json_format_proto3.proto b/third_party/protobuf/src/google/protobuf/util/json_format_proto3.proto
index 3835b30eb9..8a0441c8f6 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/json_format_proto3.proto
+++ b/third_party/protobuf/src/google/protobuf/util/json_format_proto3.proto
@@ -32,6 +32,8 @@ syntax = "proto3";
package proto3;
+option java_package = "com.google.protobuf.util";
+option java_outer_classname = "JsonFormatProto3";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/json_util.cc b/third_party/protobuf/src/google/protobuf/util/json_util.cc
index d7ac2dba66..8595a8813d 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/json_util.cc
+++ b/third_party/protobuf/src/google/protobuf/util/json_util.cc
@@ -49,22 +49,25 @@ namespace protobuf {
namespace util {
namespace internal {
+ZeroCopyStreamByteSink::~ZeroCopyStreamByteSink() {
+ stream_->BackUp(buffer_size_);
+}
+
void ZeroCopyStreamByteSink::Append(const char* bytes, size_t len) {
- while (len > 0) {
- void* buffer;
- int length;
- if (!stream_->Next(&buffer, &length)) {
- // There isn't a way for ByteSink to report errors.
+ while (true) {
+ if (len <= buffer_size_) {
+ memcpy(buffer_, bytes, len);
+ buffer_ = static_cast<char*>(buffer_) + len;
+ buffer_size_ -= len;
return;
}
- if (len < length) {
- memcpy(buffer, bytes, len);
- stream_->BackUp(length - len);
- break;
- } else {
- memcpy(buffer, bytes, length);
- bytes += length;
- len -= length;
+ memcpy(buffer_, bytes, buffer_size_);
+ bytes += buffer_size_;
+ len -= buffer_size_;
+ if (!stream_->Next(&buffer_, &buffer_size_)) {
+ // There isn't a way for ByteSink to report errors.
+ buffer_size_ = 0;
+ return;
}
}
}
@@ -79,12 +82,17 @@ util::Status BinaryToJsonStream(TypeResolver* resolver,
google::protobuf::Type type;
RETURN_IF_ERROR(resolver->ResolveMessageType(type_url, &type));
converter::ProtoStreamObjectSource proto_source(&in_stream, resolver, type);
+ proto_source.set_use_ints_for_enums(options.always_print_enums_as_ints);
+ proto_source.set_preserve_proto_field_names(
+ options.preserve_proto_field_names);
io::CodedOutputStream out_stream(json_output);
converter::JsonObjectWriter json_writer(options.add_whitespace ? " " : "",
&out_stream);
if (options.always_print_primitive_fields) {
converter::DefaultValueObjectWriter default_value_writer(
resolver, type, &json_writer);
+ default_value_writer.set_preserve_proto_field_names(
+ options.preserve_proto_field_names);
return proto_source.WriteTo(&default_value_writer);
} else {
return proto_source.WriteTo(&json_writer);
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/json_util.h b/third_party/protobuf/src/google/protobuf/util/json_util.h
index 6d3cee5281..dd9a736f24 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/json_util.h
+++ b/third_party/protobuf/src/google/protobuf/util/json_util.h
@@ -61,9 +61,16 @@ struct JsonPrintOptions {
// set to 0 will be omitted. Set this flag to true will override the default
// behavior and print primitive fields regardless of their values.
bool always_print_primitive_fields;
+ // Whether to always print enums as ints. By default they are rendered as
+ // strings.
+ bool always_print_enums_as_ints;
+ // Whether to preserve proto field names
+ bool preserve_proto_field_names;
JsonPrintOptions() : add_whitespace(false),
- always_print_primitive_fields(false) {
+ always_print_primitive_fields(false),
+ always_print_enums_as_ints(false),
+ preserve_proto_field_names(false) {
}
};
@@ -172,12 +179,15 @@ namespace internal {
class LIBPROTOBUF_EXPORT ZeroCopyStreamByteSink : public strings::ByteSink {
public:
explicit ZeroCopyStreamByteSink(io::ZeroCopyOutputStream* stream)
- : stream_(stream) {}
+ : stream_(stream), buffer_size_(0) {}
+ ~ZeroCopyStreamByteSink();
virtual void Append(const char* bytes, size_t len);
private:
io::ZeroCopyOutputStream* stream_;
+ void* buffer_;
+ int buffer_size_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ZeroCopyStreamByteSink);
};
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/json_util_test.cc b/third_party/protobuf/src/google/protobuf/util/json_util_test.cc
index dacac5e01a..7c03d674b6 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/json_util_test.cc
+++ b/third_party/protobuf/src/google/protobuf/util/json_util_test.cc
@@ -36,6 +36,7 @@
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/descriptor_database.h>
#include <google/protobuf/dynamic_message.h>
+#include <google/protobuf/util/internal/testdata/maps.pb.h>
#include <google/protobuf/util/json_format_proto3.pb.h>
#include <google/protobuf/util/type_resolver.h>
#include <google/protobuf/util/type_resolver_util.h>
@@ -50,6 +51,8 @@ using proto3::FOO;
using proto3::BAR;
using proto3::TestMessage;
using proto3::TestMap;
+using proto3::TestOneof;
+using testing::MapIn;
static const char kTypeUrlPrefix[] = "type.googleapis.com";
@@ -62,7 +65,7 @@ static string GetTypeUrl(const Descriptor* message) {
// only cover some very basic cases to make sure the wrappers have forwarded
// parameters to the underlying implementation correctly. More detailed
// tests are contained in the //net/proto2/util/converter directory.
-class JsonUtilTest : public testing::Test {
+class JsonUtilTest : public ::testing::Test {
protected:
JsonUtilTest() {
}
@@ -128,6 +131,94 @@ TEST_F(JsonUtilTest, TestDefaultValues) {
"\"repeatedMessageValue\":[]"
"}",
ToJson(m, options));
+
+ options.always_print_primitive_fields = true;
+ m.set_string_value("i am a test string value");
+ m.set_bytes_value("i am a test bytes value");
+ EXPECT_EQ(
+ "{\"boolValue\":false,"
+ "\"int32Value\":0,"
+ "\"int64Value\":\"0\","
+ "\"uint32Value\":0,"
+ "\"uint64Value\":\"0\","
+ "\"floatValue\":0,"
+ "\"doubleValue\":0,"
+ "\"stringValue\":\"i am a test string value\","
+ "\"bytesValue\":\"aSBhbSBhIHRlc3QgYnl0ZXMgdmFsdWU=\","
+ "\"enumValue\":\"FOO\","
+ "\"repeatedBoolValue\":[],"
+ "\"repeatedInt32Value\":[],"
+ "\"repeatedInt64Value\":[],"
+ "\"repeatedUint32Value\":[],"
+ "\"repeatedUint64Value\":[],"
+ "\"repeatedFloatValue\":[],"
+ "\"repeatedDoubleValue\":[],"
+ "\"repeatedStringValue\":[],"
+ "\"repeatedBytesValue\":[],"
+ "\"repeatedEnumValue\":[],"
+ "\"repeatedMessageValue\":[]"
+ "}",
+ ToJson(m, options));
+
+ options.preserve_proto_field_names = true;
+ m.set_string_value("i am a test string value");
+ m.set_bytes_value("i am a test bytes value");
+ EXPECT_EQ(
+ "{\"bool_value\":false,"
+ "\"int32_value\":0,"
+ "\"int64_value\":\"0\","
+ "\"uint32_value\":0,"
+ "\"uint64_value\":\"0\","
+ "\"float_value\":0,"
+ "\"double_value\":0,"
+ "\"string_value\":\"i am a test string value\","
+ "\"bytes_value\":\"aSBhbSBhIHRlc3QgYnl0ZXMgdmFsdWU=\","
+ "\"enum_value\":\"FOO\","
+ "\"repeated_bool_value\":[],"
+ "\"repeated_int32_value\":[],"
+ "\"repeated_int64_value\":[],"
+ "\"repeated_uint32_value\":[],"
+ "\"repeated_uint64_value\":[],"
+ "\"repeated_float_value\":[],"
+ "\"repeated_double_value\":[],"
+ "\"repeated_string_value\":[],"
+ "\"repeated_bytes_value\":[],"
+ "\"repeated_enum_value\":[],"
+ "\"repeated_message_value\":[]"
+ "}",
+ ToJson(m, options));
+}
+
+TEST_F(JsonUtilTest, TestPreserveProtoFieldNames) {
+ TestMessage m;
+ m.mutable_message_value();
+
+ JsonPrintOptions options;
+ options.preserve_proto_field_names = true;
+ EXPECT_EQ("{\"message_value\":{}}", ToJson(m, options));
+}
+
+TEST_F(JsonUtilTest, TestAlwaysPrintEnumsAsInts) {
+ TestMessage orig;
+ orig.set_enum_value(proto3::BAR);
+ orig.add_repeated_enum_value(proto3::FOO);
+ orig.add_repeated_enum_value(proto3::BAR);
+
+ JsonPrintOptions print_options;
+ print_options.always_print_enums_as_ints = true;
+
+ string expected_json =
+ "{\"enumValue\":1,\"repeatedEnumValue\":[0,1]}";
+ EXPECT_EQ(expected_json, ToJson(orig, print_options));
+
+ TestMessage parsed;
+ JsonParseOptions parse_options;
+ ASSERT_TRUE(FromJson(expected_json, &parsed, parse_options));
+
+ EXPECT_EQ(proto3::BAR, parsed.enum_value());
+ EXPECT_EQ(2, parsed.repeated_enum_value_size());
+ EXPECT_EQ(proto3::FOO, parsed.repeated_enum_value(0));
+ EXPECT_EQ(proto3::BAR, parsed.repeated_enum_value(1));
}
TEST_F(JsonUtilTest, ParseMessage) {
@@ -168,6 +259,32 @@ TEST_F(JsonUtilTest, ParseMap) {
EXPECT_EQ(message.DebugString(), other.DebugString());
}
+TEST_F(JsonUtilTest, ParsePrimitiveMapIn) {
+ MapIn message;
+ JsonPrintOptions print_options;
+ print_options.always_print_primitive_fields = true;
+ JsonParseOptions parse_options;
+ EXPECT_EQ("{\"other\":\"\",\"things\":[],\"mapInput\":{}}", ToJson(message, print_options));
+ MapIn other;
+ ASSERT_TRUE(FromJson(ToJson(message, print_options), &other, parse_options));
+ EXPECT_EQ(message.DebugString(), other.DebugString());
+}
+
+TEST_F(JsonUtilTest, PrintPrimitiveOneof) {
+ TestOneof message;
+ JsonPrintOptions options;
+ options.always_print_primitive_fields = true;
+ message.mutable_oneof_message_value();
+ EXPECT_EQ(
+ "{\"oneofMessageValue\":{\"value\":0}}",
+ ToJson(message, options));
+
+ message.set_oneof_int32_value(1);
+ EXPECT_EQ(
+ "{\"oneofInt32Value\":1}",
+ ToJson(message, options));
+}
+
TEST_F(JsonUtilTest, TestParseIgnoreUnknownFields) {
TestMessage m;
JsonParseOptions options;
@@ -223,11 +340,11 @@ TEST_F(JsonUtilTest, TestDynamicMessage) {
EXPECT_EQ(ToJson(generated, options), ToJson(*message, options));
}
-typedef pair<char*, int> Segment;
+typedef std::pair<char*, int> Segment;
// A ZeroCopyOutputStream that writes to multiple buffers.
class SegmentedZeroCopyOutputStream : public io::ZeroCopyOutputStream {
public:
- explicit SegmentedZeroCopyOutputStream(list<Segment> segments)
+ explicit SegmentedZeroCopyOutputStream(std::list<Segment> segments)
: segments_(segments), last_segment_(static_cast<char*>(NULL), 0), byte_count_(0) {}
virtual bool Next(void** buffer, int* length) {
@@ -253,7 +370,7 @@ class SegmentedZeroCopyOutputStream : public io::ZeroCopyOutputStream {
virtual int64 ByteCount() const { return byte_count_; }
private:
- list<Segment> segments_;
+ std::list<Segment> segments_;
Segment last_segment_;
int64 byte_count_;
};
@@ -271,7 +388,7 @@ TEST(ZeroCopyStreamByteSinkTest, TestAllInputOutputPatterns) {
for (int split_pattern = 0; split_pattern < (1 << (kOutputBufferLength - 1));
split_pattern += kSkippedPatternCount) {
// Split the buffer into small segments according to the split_pattern.
- list<Segment> segments;
+ std::list<Segment> segments;
int segment_start = 0;
for (int i = 0; i < kOutputBufferLength - 1; ++i) {
if (split_pattern & (1 << i)) {
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/message_differencer.cc b/third_party/protobuf/src/google/protobuf/util/message_differencer.cc
index a6d0cb0749..203d838870 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/message_differencer.cc
+++ b/third_party/protobuf/src/google/protobuf/util/message_differencer.cc
@@ -73,7 +73,7 @@ class MessageDifferencer::MultipleFieldsMapKeyComparator
public:
MultipleFieldsMapKeyComparator(
MessageDifferencer* message_differencer,
- const vector<vector<const FieldDescriptor*> >& key_field_paths)
+ const std::vector<std::vector<const FieldDescriptor*> >& key_field_paths)
: message_differencer_(message_differencer),
key_field_paths_(key_field_paths) {
GOOGLE_CHECK(!key_field_paths_.empty());
@@ -85,14 +85,14 @@ class MessageDifferencer::MultipleFieldsMapKeyComparator
MessageDifferencer* message_differencer,
const FieldDescriptor* key)
: message_differencer_(message_differencer) {
- vector<const FieldDescriptor*> key_field_path;
+ std::vector<const FieldDescriptor*> key_field_path;
key_field_path.push_back(key);
key_field_paths_.push_back(key_field_path);
}
virtual bool IsMatch(
const Message& message1,
const Message& message2,
- const vector<SpecificField>& parent_fields) const {
+ const std::vector<SpecificField>& parent_fields) const {
for (int i = 0; i < key_field_paths_.size(); ++i) {
if (!IsMatchInternal(message1, message2, parent_fields,
key_field_paths_[i], 0)) {
@@ -105,11 +105,11 @@ class MessageDifferencer::MultipleFieldsMapKeyComparator
bool IsMatchInternal(
const Message& message1,
const Message& message2,
- const vector<SpecificField>& parent_fields,
- const vector<const FieldDescriptor*>& key_field_path,
+ const std::vector<SpecificField>& parent_fields,
+ const std::vector<const FieldDescriptor*>& key_field_path,
int path_index) const {
const FieldDescriptor* field = key_field_path[path_index];
- vector<SpecificField> current_parent_fields(parent_fields);
+ std::vector<SpecificField> current_parent_fields(parent_fields);
if (path_index == key_field_path.size() - 1) {
if (field->is_repeated()) {
if (!message_differencer_->CompareRepeatedField(
@@ -146,7 +146,7 @@ class MessageDifferencer::MultipleFieldsMapKeyComparator
}
}
MessageDifferencer* message_differencer_;
- vector<vector<const FieldDescriptor*> > key_field_paths_;
+ std::vector<std::vector<const FieldDescriptor*> > key_field_paths_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MultipleFieldsMapKeyComparator);
};
@@ -283,10 +283,10 @@ void MessageDifferencer::TreatAsMap(const FieldDescriptor* field,
void MessageDifferencer::TreatAsMapWithMultipleFieldsAsKey(
const FieldDescriptor* field,
- const vector<const FieldDescriptor*>& key_fields) {
- vector<vector<const FieldDescriptor*> > key_field_paths;
+ const std::vector<const FieldDescriptor*>& key_fields) {
+ std::vector<std::vector<const FieldDescriptor*> > key_field_paths;
for (int i = 0; i < key_fields.size(); ++i) {
- vector<const FieldDescriptor*> key_field_path;
+ std::vector<const FieldDescriptor*> key_field_path;
key_field_path.push_back(key_fields[i]);
key_field_paths.push_back(key_field_path);
}
@@ -295,14 +295,15 @@ void MessageDifferencer::TreatAsMapWithMultipleFieldsAsKey(
void MessageDifferencer::TreatAsMapWithMultipleFieldPathsAsKey(
const FieldDescriptor* field,
- const vector<vector<const FieldDescriptor*> >& key_field_paths) {
+ const std::vector<std::vector<const FieldDescriptor*> >& key_field_paths) {
GOOGLE_CHECK(field->is_repeated()) << "Field must be repeated: "
<< field->full_name();
GOOGLE_CHECK_EQ(FieldDescriptor::CPPTYPE_MESSAGE, field->cpp_type())
<< "Field has to be message type. Field name is: "
<< field->full_name();
for (int i = 0; i < key_field_paths.size(); ++i) {
- const vector<const FieldDescriptor*>& key_field_path = key_field_paths[i];
+ const std::vector<const FieldDescriptor*>& key_field_path =
+ key_field_paths[i];
for (int j = 0; j < key_field_path.size(); ++j) {
const FieldDescriptor* parent_field =
j == 0 ? field : key_field_path[j - 1];
@@ -390,7 +391,7 @@ bool MessageDifferencer::FieldBefore(const FieldDescriptor* field1,
bool MessageDifferencer::Compare(const Message& message1,
const Message& message2) {
- vector<SpecificField> parent_fields;
+ std::vector<SpecificField> parent_fields;
bool result = false;
@@ -411,20 +412,20 @@ bool MessageDifferencer::Compare(const Message& message1,
bool MessageDifferencer::CompareWithFields(
const Message& message1,
const Message& message2,
- const vector<const FieldDescriptor*>& message1_fields_arg,
- const vector<const FieldDescriptor*>& message2_fields_arg) {
+ const std::vector<const FieldDescriptor*>& message1_fields_arg,
+ const std::vector<const FieldDescriptor*>& message2_fields_arg) {
if (message1.GetDescriptor() != message2.GetDescriptor()) {
GOOGLE_LOG(DFATAL) << "Comparison between two messages with different "
<< "descriptors.";
return false;
}
- vector<SpecificField> parent_fields;
+ std::vector<SpecificField> parent_fields;
bool result = false;
- vector<const FieldDescriptor*> message1_fields(message1_fields_arg);
- vector<const FieldDescriptor*> message2_fields(message2_fields_arg);
+ std::vector<const FieldDescriptor*> message1_fields(message1_fields_arg);
+ std::vector<const FieldDescriptor*> message2_fields(message2_fields_arg);
std::sort(message1_fields.begin(), message1_fields.end(), FieldBefore);
std::sort(message2_fields.begin(), message2_fields.end(), FieldBefore);
@@ -451,7 +452,7 @@ bool MessageDifferencer::CompareWithFields(
bool MessageDifferencer::Compare(
const Message& message1,
const Message& message2,
- vector<SpecificField>* parent_fields) {
+ std::vector<SpecificField>* parent_fields) {
const Descriptor* descriptor1 = message1.GetDescriptor();
const Descriptor* descriptor2 = message2.GetDescriptor();
if (descriptor1 != descriptor2) {
@@ -473,10 +474,10 @@ bool MessageDifferencer::Compare(
const Reflection* reflection2 = message2.GetReflection();
// Retrieve all the set fields, including extensions.
- vector<const FieldDescriptor*> message1_fields;
+ std::vector<const FieldDescriptor*> message1_fields;
message1_fields.reserve(1 + message1.GetDescriptor()->field_count());
- vector<const FieldDescriptor*> message2_fields;
+ std::vector<const FieldDescriptor*> message2_fields;
message2_fields.reserve(1 + message2.GetDescriptor()->field_count());
reflection1->ListFields(message1, &message1_fields);
@@ -514,15 +515,15 @@ bool MessageDifferencer::Compare(
bool MessageDifferencer::CompareRequestedFieldsUsingSettings(
const Message& message1,
const Message& message2,
- const vector<const FieldDescriptor*>& message1_fields,
- const vector<const FieldDescriptor*>& message2_fields,
- vector<SpecificField>* parent_fields) {
+ const std::vector<const FieldDescriptor*>& message1_fields,
+ const std::vector<const FieldDescriptor*>& message2_fields,
+ std::vector<SpecificField>* parent_fields) {
if (scope_ == FULL) {
if (message_field_comparison_ == EQUIVALENT) {
// We need to merge the field lists of both messages (i.e.
// we are merely checking for a difference in field values,
// rather than the addition or deletion of fields).
- vector<const FieldDescriptor*> fields_union;
+ std::vector<const FieldDescriptor*> fields_union;
CombineFields(message1_fields, FULL, message2_fields, FULL,
&fields_union);
return CompareWithFieldsInternal(message1, message2, fields_union,
@@ -544,7 +545,7 @@ bool MessageDifferencer::CompareRequestedFieldsUsingSettings(
// but only the intersection for message2. This way, any fields
// only present in message2 will be ignored, but any fields only
// present in message1 will be marked as a difference.
- vector<const FieldDescriptor*> fields_intersection;
+ std::vector<const FieldDescriptor*> fields_intersection;
CombineFields(message1_fields, PARTIAL, message2_fields, PARTIAL,
&fields_intersection);
return CompareWithFieldsInternal(message1, message2, message1_fields,
@@ -554,11 +555,11 @@ bool MessageDifferencer::CompareRequestedFieldsUsingSettings(
}
void MessageDifferencer::CombineFields(
- const vector<const FieldDescriptor*>& fields1,
+ const std::vector<const FieldDescriptor*>& fields1,
Scope fields1_scope,
- const vector<const FieldDescriptor*>& fields2,
+ const std::vector<const FieldDescriptor*>& fields2,
Scope fields2_scope,
- vector<const FieldDescriptor*>* combined_fields) {
+ std::vector<const FieldDescriptor*>* combined_fields) {
int index1 = 0;
int index2 = 0;
@@ -588,9 +589,9 @@ void MessageDifferencer::CombineFields(
bool MessageDifferencer::CompareWithFieldsInternal(
const Message& message1,
const Message& message2,
- const vector<const FieldDescriptor*>& message1_fields,
- const vector<const FieldDescriptor*>& message2_fields,
- vector<SpecificField>* parent_fields) {
+ const std::vector<const FieldDescriptor*>& message1_fields,
+ const std::vector<const FieldDescriptor*>& message2_fields,
+ std::vector<SpecificField>* parent_fields) {
bool isDifferent = false;
int field_index1 = 0;
int field_index2 = 0;
@@ -626,6 +627,7 @@ bool MessageDifferencer::CompareWithFieldsInternal(
}
if (reporter_ != NULL) {
+ assert(field1 != NULL);
int count = field1->is_repeated() ?
reflection1->FieldSize(message1, field1) : 1;
@@ -706,6 +708,7 @@ bool MessageDifferencer::CompareWithFieldsInternal(
}
bool fieldDifferent = false;
+ assert(field1 != NULL);
if (field1->is_repeated()) {
fieldDifferent = !CompareRepeatedField(message1, message2, field1,
parent_fields);
@@ -744,13 +747,12 @@ bool MessageDifferencer::CompareWithFieldsInternal(
return !isDifferent;
}
-bool MessageDifferencer::IsMatch(const FieldDescriptor* repeated_field,
- const MapKeyComparator* key_comparator,
- const Message* message1,
- const Message* message2,
- const vector<SpecificField>& parent_fields,
- int index1, int index2) {
- vector<SpecificField> current_parent_fields(parent_fields);
+bool MessageDifferencer::IsMatch(
+ const FieldDescriptor* repeated_field,
+ const MapKeyComparator* key_comparator, const Message* message1,
+ const Message* message2, const std::vector<SpecificField>& parent_fields,
+ int index1, int index2) {
+ std::vector<SpecificField> current_parent_fields(parent_fields);
if (repeated_field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
return CompareFieldValueUsingParentFields(
*message1, *message2, repeated_field, index1, index2,
@@ -790,7 +792,7 @@ bool MessageDifferencer::CompareRepeatedField(
const Message& message1,
const Message& message2,
const FieldDescriptor* repeated_field,
- vector<SpecificField>* parent_fields) {
+ std::vector<SpecificField>* parent_fields) {
// the input FieldDescriptor is guaranteed to be repeated field.
const Reflection* reflection1 = message1.GetReflection();
const Reflection* reflection2 = message2.GetReflection();
@@ -811,8 +813,8 @@ bool MessageDifferencer::CompareRepeatedField(
// These two list are used for store the index of the correspondent
// element in peer repeated field.
- vector<int> match_list1;
- vector<int> match_list2;
+ std::vector<int> match_list1;
+ std::vector<int> match_list2;
// Try to match indices of the repeated fields. Return false if match fails
// and there's no detailed report needed.
@@ -875,6 +877,7 @@ bool MessageDifferencer::CompareRepeatedField(
for (int i = 0; i < count1; ++i) {
if (match_list1[i] != -1) continue;
+ assert(reporter_ != NULL);
specific_field.index = i;
parent_fields->push_back(specific_field);
reporter_->ReportDeleted(message1, message2, *parent_fields);
@@ -896,7 +899,7 @@ bool MessageDifferencer::CompareFieldValue(const Message& message1,
bool MessageDifferencer::CompareFieldValueUsingParentFields(
const Message& message1, const Message& message2,
const FieldDescriptor* field, int index1, int index2,
- vector<SpecificField>* parent_fields) {
+ std::vector<SpecificField>* parent_fields) {
FieldContext field_context(parent_fields);
FieldComparator::ComparisonResult result = GetFieldComparisonResult(
message1, message2, field, index1, index2, &field_context);
@@ -935,7 +938,7 @@ bool MessageDifferencer::CompareFieldValueUsingParentFields(
}
bool MessageDifferencer::CheckPathChanged(
- const vector<SpecificField>& field_path) {
+ const std::vector<SpecificField>& field_path) {
for (int i = 0; i < field_path.size(); ++i) {
if (field_path[i].index != field_path[i].new_index) return true;
}
@@ -959,7 +962,7 @@ bool MessageDifferencer::IsIgnored(
const Message& message1,
const Message& message2,
const FieldDescriptor* field,
- const vector<SpecificField>& parent_fields) {
+ const std::vector<SpecificField>& parent_fields) {
if (ignored_fields_.find(field) != ignored_fields_.end()) {
return true;
}
@@ -974,7 +977,8 @@ bool MessageDifferencer::IsIgnored(
bool MessageDifferencer::IsUnknownFieldIgnored(
const Message& message1, const Message& message2,
- const SpecificField& field, const vector<SpecificField>& parent_fields) {
+ const SpecificField& field,
+ const std::vector<SpecificField>& parent_fields) {
for (int i = 0; i < ignore_criteria_.size(); ++i) {
if (ignore_criteria_[i]->IsUnknownFieldIgnored(message1, message2, field,
parent_fields)) {
@@ -996,7 +1000,7 @@ const MessageDifferencer::MapKeyComparator* MessageDifferencer
namespace {
-typedef pair<int, const UnknownField*> IndexUnknownFieldPair;
+typedef std::pair<int, const UnknownField*> IndexUnknownFieldPair;
struct UnknownFieldOrdering {
inline bool operator()(const IndexUnknownFieldPair& a,
@@ -1047,7 +1051,7 @@ bool MessageDifferencer::CompareUnknownFields(
const Message& message1, const Message& message2,
const google::protobuf::UnknownFieldSet& unknown_field_set1,
const google::protobuf::UnknownFieldSet& unknown_field_set2,
- vector<SpecificField>* parent_field) {
+ std::vector<SpecificField>* parent_field) {
// Ignore unknown fields in EQUIVALENT mode.
if (message_field_comparison_ == EQUIVALENT) return true;
@@ -1063,8 +1067,8 @@ bool MessageDifferencer::CompareUnknownFields(
// two sets -- that is, differing values for the same tag. We use
// IndexUnknownFieldPairs to keep track of the field's original index for
// reporting purposes.
- vector<IndexUnknownFieldPair> fields1; // unknown_field_set1, sorted
- vector<IndexUnknownFieldPair> fields2; // unknown_field_set2, sorted
+ std::vector<IndexUnknownFieldPair> fields1; // unknown_field_set1, sorted
+ std::vector<IndexUnknownFieldPair> fields2; // unknown_field_set2, sorted
fields1.reserve(unknown_field_set1.field_count());
fields2.reserve(unknown_field_set2.field_count());
@@ -1267,7 +1271,7 @@ class MaximumMatcher {
// the x-th node on the right side is matched to y-th node on the left side.
// match_list1[i] == -1 means the node is not matched. Same with match_list2.
MaximumMatcher(int count1, int count2, NodeMatchCallback* callback,
- vector<int>* match_list1, vector<int>* match_list2);
+ std::vector<int>* match_list1, std::vector<int>* match_list2);
// Find a maximum match and return the number of matched node pairs.
// If early_return is true, this method will return 0 immediately when it
// finds that not all nodes on the left side can be matched.
@@ -1279,21 +1283,21 @@ class MaximumMatcher {
// Find an argumenting path starting from the node v on the left side. If a
// path can be found, update match_list2_ to reflect the path and return
// true.
- bool FindArgumentPathDFS(int v, vector<bool>* visited);
+ bool FindArgumentPathDFS(int v, std::vector<bool>* visited);
int count1_;
int count2_;
google::protobuf::scoped_ptr<NodeMatchCallback> match_callback_;
- map<pair<int, int>, bool> cached_match_results_;
- vector<int>* match_list1_;
- vector<int>* match_list2_;
+ std::map<std::pair<int, int>, bool> cached_match_results_;
+ std::vector<int>* match_list1_;
+ std::vector<int>* match_list2_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MaximumMatcher);
};
MaximumMatcher::MaximumMatcher(int count1, int count2,
NodeMatchCallback* callback,
- vector<int>* match_list1,
- vector<int>* match_list2)
+ std::vector<int>* match_list1,
+ std::vector<int>* match_list2)
: count1_(count1), count2_(count2), match_callback_(callback),
match_list1_(match_list1), match_list2_(match_list2) {
match_list1_->assign(count1, -1);
@@ -1303,7 +1307,7 @@ MaximumMatcher::MaximumMatcher(int count1, int count2,
int MaximumMatcher::FindMaximumMatch(bool early_return) {
int result = 0;
for (int i = 0; i < count1_; ++i) {
- vector<bool> visited(count1_);
+ std::vector<bool> visited(count1_);
if (FindArgumentPathDFS(i, &visited)) {
++result;
} else if (early_return) {
@@ -1321,8 +1325,9 @@ int MaximumMatcher::FindMaximumMatch(bool early_return) {
}
bool MaximumMatcher::Match(int left, int right) {
- pair<int, int> p(left, right);
- map<pair<int, int>, bool>::iterator it = cached_match_results_.find(p);
+ std::pair<int, int> p(left, right);
+ std::map<std::pair<int, int>, bool>::iterator it =
+ cached_match_results_.find(p);
if (it != cached_match_results_.end()) {
return it->second;
}
@@ -1330,7 +1335,7 @@ bool MaximumMatcher::Match(int left, int right) {
return cached_match_results_[p];
}
-bool MaximumMatcher::FindArgumentPathDFS(int v, vector<bool>* visited) {
+bool MaximumMatcher::FindArgumentPathDFS(int v, std::vector<bool>* visited) {
(*visited)[v] = true;
// We try to match those un-matched nodes on the right side first. This is
// the step that the navie greedy matching algorithm uses. In the best cases
@@ -1366,9 +1371,9 @@ bool MessageDifferencer::MatchRepeatedFieldIndices(
const Message& message1,
const Message& message2,
const FieldDescriptor* repeated_field,
- const vector<SpecificField>& parent_fields,
- vector<int>* match_list1,
- vector<int>* match_list2) {
+ const std::vector<SpecificField>& parent_fields,
+ std::vector<int>* match_list1,
+ std::vector<int>* match_list2) {
const int count1 =
message1.GetReflection()->FieldSize(message1, repeated_field);
const int count2 =
@@ -1390,7 +1395,7 @@ bool MessageDifferencer::MatchRepeatedFieldIndices(
// algorithm will fail to find a maximum matching.
// Here we use the argumenting path algorithm.
MaximumMatcher::NodeMatchCallback* callback =
- ::google::protobuf::internal::NewPermanentCallback(
+ NewPermanentCallback(
this, &MessageDifferencer::IsMatch,
repeated_field, key_comparator,
&message1, &message2, parent_fields);
@@ -1483,7 +1488,7 @@ MessageDifferencer::StreamReporter::~StreamReporter() {
}
void MessageDifferencer::StreamReporter::PrintPath(
- const vector<SpecificField>& field_path, bool left_side) {
+ const std::vector<SpecificField>& field_path, bool left_side) {
for (int i = 0; i < field_path.size(); ++i) {
if (i > 0) {
printer_->Print(".");
@@ -1512,7 +1517,7 @@ void MessageDifferencer::StreamReporter::PrintPath(
void MessageDifferencer::
StreamReporter::PrintValue(const Message& message,
- const vector<SpecificField>& field_path,
+ const std::vector<SpecificField>& field_path,
bool left_side) {
const SpecificField& specific_field = field_path.back();
const FieldDescriptor* field = specific_field.field;
@@ -1585,7 +1590,7 @@ void MessageDifferencer::StreamReporter::Print(const string& str) {
void MessageDifferencer::StreamReporter::ReportAdded(
const Message& message1,
const Message& message2,
- const vector<SpecificField>& field_path) {
+ const std::vector<SpecificField>& field_path) {
printer_->Print("added: ");
PrintPath(field_path, false);
printer_->Print(": ");
@@ -1596,7 +1601,7 @@ void MessageDifferencer::StreamReporter::ReportAdded(
void MessageDifferencer::StreamReporter::ReportDeleted(
const Message& message1,
const Message& message2,
- const vector<SpecificField>& field_path) {
+ const std::vector<SpecificField>& field_path) {
printer_->Print("deleted: ");
PrintPath(field_path, true);
printer_->Print(": ");
@@ -1607,7 +1612,7 @@ void MessageDifferencer::StreamReporter::ReportDeleted(
void MessageDifferencer::StreamReporter::ReportModified(
const Message& message1,
const Message& message2,
- const vector<SpecificField>& field_path) {
+ const std::vector<SpecificField>& field_path) {
if (!report_modified_aggregates_ && field_path.back().field == NULL) {
if (field_path.back().unknown_field_type == UnknownField::TYPE_GROUP) {
// Any changes to the subfields have already been printed.
@@ -1637,7 +1642,7 @@ void MessageDifferencer::StreamReporter::ReportModified(
void MessageDifferencer::StreamReporter::ReportMoved(
const Message& message1,
const Message& message2,
- const vector<SpecificField>& field_path) {
+ const std::vector<SpecificField>& field_path) {
printer_->Print("moved: ");
PrintPath(field_path, true);
printer_->Print(" -> ");
@@ -1650,7 +1655,7 @@ void MessageDifferencer::StreamReporter::ReportMoved(
void MessageDifferencer::StreamReporter::ReportMatched(
const Message& message1,
const Message& message2,
- const vector<SpecificField>& field_path) {
+ const std::vector<SpecificField>& field_path) {
printer_->Print("matched: ");
PrintPath(field_path, true);
if (CheckPathChanged(field_path)) {
@@ -1665,7 +1670,7 @@ void MessageDifferencer::StreamReporter::ReportMatched(
void MessageDifferencer::StreamReporter::ReportIgnored(
const Message& message1,
const Message& message2,
- const vector<SpecificField>& field_path) {
+ const std::vector<SpecificField>& field_path) {
printer_->Print("ignored: ");
PrintPath(field_path, true);
if (CheckPathChanged(field_path)) {
@@ -1677,7 +1682,7 @@ void MessageDifferencer::StreamReporter::ReportIgnored(
void MessageDifferencer::StreamReporter::ReportUnknownFieldIgnored(
const Message& message1, const Message& message2,
- const vector<SpecificField>& field_path) {
+ const std::vector<SpecificField>& field_path) {
printer_->Print("ignored: ");
PrintPath(field_path, true);
if (CheckPathChanged(field_path)) {
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/message_differencer.h b/third_party/protobuf/src/google/protobuf/util/message_differencer.h
index 654d1a67e2..d99223cbd8 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/message_differencer.h
+++ b/third_party/protobuf/src/google/protobuf/util/message_differencer.h
@@ -221,19 +221,19 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
// Reports that a field has been added into Message2.
virtual void ReportAdded(
const Message& message1, const Message& message2,
- const vector<SpecificField>& field_path) = 0;
+ const std::vector<SpecificField>& field_path) = 0;
// Reports that a field has been deleted from Message1.
virtual void ReportDeleted(
const Message& message1,
const Message& message2,
- const vector<SpecificField>& field_path) = 0;
+ const std::vector<SpecificField>& field_path) = 0;
// Reports that the value of a field has been modified.
virtual void ReportModified(
const Message& message1,
const Message& message2,
- const vector<SpecificField>& field_path) = 0;
+ const std::vector<SpecificField>& field_path) = 0;
// Reports that a repeated field has been moved to another location. This
// only applies when using TreatAsSet or TreatAsMap() -- see below. Also
@@ -243,7 +243,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
virtual void ReportMoved(
const Message& message1,
const Message& message2,
- const vector<SpecificField>& field_path) { }
+ const std::vector<SpecificField>& field_path) { }
// Reports that two fields match. Useful for doing side-by-side diffs.
// This function is mutually exclusive with ReportModified and ReportMoved.
@@ -252,7 +252,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
virtual void ReportMatched(
const Message& message1,
const Message& message2,
- const vector<SpecificField>& field_path) { }
+ const std::vector<SpecificField>& field_path) { }
// Reports that two fields would have been compared, but the
// comparison has been skipped because the field was marked as
@@ -276,14 +276,14 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
virtual void ReportIgnored(
const Message& message1,
const Message& message2,
- const vector<SpecificField>& field_path) { }
+ const std::vector<SpecificField>& field_path) { }
// Report that an unknown field is ignored. (see comment above).
// Note this is a different function since the last SpecificField in field
// path has a null field. This could break existing Reporter.
virtual void ReportUnknownFieldIgnored(
const Message& message1, const Message& message2,
- const vector<SpecificField>& field_path) {}
+ const std::vector<SpecificField>& field_path) {}
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Reporter);
@@ -296,9 +296,10 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
MapKeyComparator();
virtual ~MapKeyComparator();
- virtual bool IsMatch(const Message& message1,
- const Message& message2,
- const vector<SpecificField>& parent_fields) const {
+ virtual bool IsMatch(
+ const Message& message1,
+ const Message& message2,
+ const std::vector<SpecificField>& parent_fields) const {
GOOGLE_CHECK(false) << "IsMatch() is not implemented.";
return false;
}
@@ -323,7 +324,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
const Message& message1,
const Message& message2,
const FieldDescriptor* field,
- const vector<SpecificField>& parent_fields) = 0;
+ const std::vector<SpecificField>& parent_fields) = 0;
// Returns true if the unknown field should be ignored.
// Note: This will be called for unknown fields as well in which case
@@ -331,7 +332,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
virtual bool IsUnknownFieldIgnored(
const Message& message1, const Message& message2,
const SpecificField& field,
- const vector<SpecificField>& parent_fields) {
+ const std::vector<SpecificField>& parent_fields) {
return false;
}
};
@@ -440,7 +441,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
// size of each element.
void TreatAsMapWithMultipleFieldsAsKey(
const FieldDescriptor* field,
- const vector<const FieldDescriptor*>& key_fields);
+ const std::vector<const FieldDescriptor*>& key_fields);
// Same as TreatAsMapWithMultipleFieldsAsKey, except that each of the field
// do not necessarily need to be a direct subfield. Each element in
// key_field_paths indicate a path from the message being compared, listing
@@ -456,7 +457,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
// !key_field_path[i]->is_repeated()
void TreatAsMapWithMultipleFieldPathsAsKey(
const FieldDescriptor* field,
- const vector<vector<const FieldDescriptor*> >& key_field_paths);
+ const std::vector<std::vector<const FieldDescriptor*> >& key_field_paths);
// Uses a custom MapKeyComparator to determine if two elements have the same
// key when comparing a repeated field as a map.
@@ -549,9 +550,10 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
// Same as above, except comparing only the list of fields specified by the
// two vectors of FieldDescriptors.
- bool CompareWithFields(const Message& message1, const Message& message2,
- const vector<const FieldDescriptor*>& message1_fields,
- const vector<const FieldDescriptor*>& message2_fields);
+ bool CompareWithFields(
+ const Message& message1, const Message& message2,
+ const std::vector<const FieldDescriptor*>& message1_fields,
+ const std::vector<const FieldDescriptor*>& message2_fields);
// Automatically creates a reporter that will output the differences
// found (if any) to the specified output string pointer. Note that this
@@ -591,35 +593,35 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
// The following are implementations of the methods described above.
virtual void ReportAdded(const Message& message1, const Message& message2,
- const vector<SpecificField>& field_path);
+ const std::vector<SpecificField>& field_path);
virtual void ReportDeleted(const Message& message1,
const Message& message2,
- const vector<SpecificField>& field_path);
+ const std::vector<SpecificField>& field_path);
virtual void ReportModified(const Message& message1,
const Message& message2,
- const vector<SpecificField>& field_path);
+ const std::vector<SpecificField>& field_path);
virtual void ReportMoved(const Message& message1,
const Message& message2,
- const vector<SpecificField>& field_path);
+ const std::vector<SpecificField>& field_path);
virtual void ReportMatched(const Message& message1,
const Message& message2,
- const vector<SpecificField>& field_path);
+ const std::vector<SpecificField>& field_path);
virtual void ReportIgnored(const Message& message1,
const Message& message2,
- const vector<SpecificField>& field_path);
+ const std::vector<SpecificField>& field_path);
virtual void ReportUnknownFieldIgnored(
const Message& message1, const Message& message2,
- const vector<SpecificField>& field_path);
+ const std::vector<SpecificField>& field_path);
protected:
// Prints the specified path of fields to the buffer.
- virtual void PrintPath(const vector<SpecificField>& field_path,
+ virtual void PrintPath(const std::vector<SpecificField>& field_path,
bool left_side);
// Prints the value of fields to the buffer. left_side is true if the
@@ -628,7 +630,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
// unknown_field_index1 or unknown_field_index2 when an unknown field
// is encountered in field_path.
virtual void PrintValue(const Message& message,
- const vector<SpecificField>& field_path,
+ const std::vector<SpecificField>& field_path,
bool left_side);
// Prints the specified path of unknown fields to the buffer.
@@ -659,11 +661,11 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
// All fields present in both lists will always be included in the combined
// list. Fields only present in one of the lists will only appear in the
// combined list if the corresponding fields_scope option is set to FULL.
- void CombineFields(const vector<const FieldDescriptor*>& fields1,
+ void CombineFields(const std::vector<const FieldDescriptor*>& fields1,
Scope fields1_scope,
- const vector<const FieldDescriptor*>& fields2,
+ const std::vector<const FieldDescriptor*>& fields2,
Scope fields2_scope,
- vector<const FieldDescriptor*>* combined_fields);
+ std::vector<const FieldDescriptor*>* combined_fields);
// Internal version of the Compare method which performs the actual
// comparison. The parent_fields vector is a vector containing field
@@ -671,34 +673,34 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
// (i.e. if the current message is an embedded message, the parent_fields
// vector will contain the field that has this embedded message).
bool Compare(const Message& message1, const Message& message2,
- vector<SpecificField>* parent_fields);
+ std::vector<SpecificField>* parent_fields);
// Compares all the unknown fields in two messages.
bool CompareUnknownFields(const Message& message1, const Message& message2,
const google::protobuf::UnknownFieldSet&,
const google::protobuf::UnknownFieldSet&,
- vector<SpecificField>* parent_fields);
+ std::vector<SpecificField>* parent_fields);
// Compares the specified messages for the requested field lists. The field
// lists are modified depending on comparison settings, and then passed to
// CompareWithFieldsInternal.
bool CompareRequestedFieldsUsingSettings(
const Message& message1, const Message& message2,
- const vector<const FieldDescriptor*>& message1_fields,
- const vector<const FieldDescriptor*>& message2_fields,
- vector<SpecificField>* parent_fields);
+ const std::vector<const FieldDescriptor*>& message1_fields,
+ const std::vector<const FieldDescriptor*>& message2_fields,
+ std::vector<SpecificField>* parent_fields);
// Compares the specified messages with the specified field lists.
bool CompareWithFieldsInternal(
const Message& message1, const Message& message2,
- const vector<const FieldDescriptor*>& message1_fields,
- const vector<const FieldDescriptor*>& message2_fields,
- vector<SpecificField>* parent_fields);
+ const std::vector<const FieldDescriptor*>& message1_fields,
+ const std::vector<const FieldDescriptor*>& message2_fields,
+ std::vector<SpecificField>* parent_fields);
// Compares the repeated fields, and report the error.
bool CompareRepeatedField(const Message& message1, const Message& message2,
const FieldDescriptor* field,
- vector<SpecificField>* parent_fields);
+ std::vector<SpecificField>* parent_fields);
// Shorthand for CompareFieldValueUsingParentFields with NULL parent_fields.
bool CompareFieldValue(const Message& message1,
@@ -716,12 +718,13 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
// list of parent messages if it needs to recursively compare the given field.
// To avoid confusing users you should not set it to NULL unless you modified
// Reporter to handle the change of parent_fields correctly.
- bool CompareFieldValueUsingParentFields(const Message& message1,
- const Message& message2,
- const FieldDescriptor* field,
- int index1,
- int index2,
- vector<SpecificField>* parent_fields);
+ bool CompareFieldValueUsingParentFields(
+ const Message& message1,
+ const Message& message2,
+ const FieldDescriptor* field,
+ int index1,
+ int index2,
+ std::vector<SpecificField>* parent_fields);
// Compares the specified field on the two messages, returning comparison
// result, as returned by appropriate FieldComparator.
@@ -736,7 +739,7 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
bool IsMatch(const FieldDescriptor* repeated_field,
const MapKeyComparator* key_comparator,
const Message* message1, const Message* message2,
- const vector<SpecificField>& parent_fields,
+ const std::vector<SpecificField>& parent_fields,
int index1, int index2);
// Returns true when this repeated field has been configured to be treated
@@ -754,13 +757,13 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
const Message& message1,
const Message& message2,
const FieldDescriptor* field,
- const vector<SpecificField>& parent_fields);
+ const std::vector<SpecificField>& parent_fields);
// Returns true if this unknown field is to be ignored when this
// MessageDifferencer compares messages.
bool IsUnknownFieldIgnored(const Message& message1, const Message& message2,
const SpecificField& field,
- const vector<SpecificField>& parent_fields);
+ const std::vector<SpecificField>& parent_fields);
// Returns MapKeyComparator* when this field has been configured to
// be treated as a map. If not, returns NULL.
@@ -773,28 +776,29 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
// This method returns false if the match failed. However, it doesn't mean
// that the comparison succeeds when this method returns true (you need to
// double-check in this case).
- bool MatchRepeatedFieldIndices(const Message& message1,
- const Message& message2,
- const FieldDescriptor* repeated_field,
- const vector<SpecificField>& parent_fields,
- vector<int>* match_list1,
- vector<int>* match_list2);
+ bool MatchRepeatedFieldIndices(
+ const Message& message1,
+ const Message& message2,
+ const FieldDescriptor* repeated_field,
+ const std::vector<SpecificField>& parent_fields,
+ std::vector<int>* match_list1,
+ std::vector<int>* match_list2);
// If "any" is of type google.protobuf.Any, extract its payload using
// DynamicMessageFactory and store in "data".
bool UnpackAny(const Message& any, google::protobuf::scoped_ptr<Message>* data);
// Checks if index is equal to new_index in all the specific fields.
- static bool CheckPathChanged(const vector<SpecificField>& parent_fields);
+ static bool CheckPathChanged(const std::vector<SpecificField>& parent_fields);
// Defines a map between field descriptors and their MapKeyComparators.
// Used for repeated fields when they are configured as TreatAsMap.
- typedef map<const FieldDescriptor*,
+ typedef std::map<const FieldDescriptor*,
const MapKeyComparator*> FieldKeyComparatorMap;
// Defines a set to store field descriptors. Used for repeated fields when
// they are configured as TreatAsSet.
- typedef set<const FieldDescriptor*> FieldSet;
+ typedef std::set<const FieldDescriptor*> FieldSet;
Reporter* reporter_;
DefaultFieldComparator default_field_comparator_;
@@ -811,13 +815,12 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
// When TreatAsMap or TreatAsMapWithMultipleFieldsAsKey is called, we don't
// store the supplied FieldDescriptors directly. Instead, a new
// MapKeyComparator is created for comparison purpose.
- vector<MapKeyComparator*> owned_key_comparators_;
+ std::vector<MapKeyComparator*> owned_key_comparators_;
FieldKeyComparatorMap map_field_key_comparator_;
- vector<IgnoreCriteria*> ignore_criteria_;
+ std::vector<IgnoreCriteria*> ignore_criteria_;
FieldSet ignored_fields_;
- bool compare_unknown_fields_;
bool report_matches_;
string* output_string_;
@@ -831,15 +834,15 @@ class LIBPROTOBUF_EXPORT MessageDifferencer {
class LIBPROTOBUF_EXPORT FieldContext {
public:
explicit FieldContext(
- vector<MessageDifferencer::SpecificField>* parent_fields)
+ std::vector<MessageDifferencer::SpecificField>* parent_fields)
: parent_fields_(parent_fields) {}
- vector<MessageDifferencer::SpecificField>* parent_fields() const {
+ std::vector<MessageDifferencer::SpecificField>* parent_fields() const {
return parent_fields_;
}
private:
- vector<MessageDifferencer::SpecificField>* parent_fields_;
+ std::vector<MessageDifferencer::SpecificField>* parent_fields_;
};
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/message_differencer_unittest.cc b/third_party/protobuf/src/google/protobuf/util/message_differencer_unittest.cc
index ed43c512c9..30b27dbaad 100755
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/message_differencer_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/util/message_differencer_unittest.cc
@@ -66,7 +66,7 @@ namespace {
const FieldDescriptor* GetFieldDescriptor(
const Message& message, const string& field_name) {
- vector<string> field_path =
+ std::vector<string> field_path =
Split(field_name, ".", true);
const Descriptor* descriptor = message.GetDescriptor();
const FieldDescriptor* field = NULL;
@@ -790,8 +790,8 @@ TEST(MessageDifferencerTest, SpecifiedFieldsEqualityAllTest) {
TestUtil::SetAllFields(&msg1);
TestUtil::SetAllFields(&msg2);
- vector<const FieldDescriptor*> fields1;
- vector<const FieldDescriptor*> fields2;
+ std::vector<const FieldDescriptor*> fields1;
+ std::vector<const FieldDescriptor*> fields2;
msg1.GetReflection()->ListFields(msg1, &fields1);
msg2.GetReflection()->ListFields(msg2, &fields2);
@@ -805,8 +805,8 @@ TEST(MessageDifferencerTest, SpecifiedFieldsInequalityAllTest) {
TestUtil::SetAllFields(&msg1);
- vector<const FieldDescriptor*> fields1;
- vector<const FieldDescriptor*> fields2;
+ std::vector<const FieldDescriptor*> fields1;
+ std::vector<const FieldDescriptor*> fields2;
msg1.GetReflection()->ListFields(msg1, &fields1);
msg2.GetReflection()->ListFields(msg2, &fields2);
@@ -820,7 +820,7 @@ TEST(MessageDifferencerTest, SpecifiedFieldsEmptyListAlwaysSucceeds) {
TestUtil::SetAllFields(&msg1);
- vector<const FieldDescriptor*> empty_fields;
+ std::vector<const FieldDescriptor*> empty_fields;
util::MessageDifferencer differencer;
EXPECT_TRUE(differencer.CompareWithFields(msg1, msg2,
@@ -835,7 +835,7 @@ TEST(MessageDifferencerTest, SpecifiedFieldsCompareWithSelf) {
unittest::TestAllTypes msg1;
TestUtil::SetAllFields(&msg1);
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
msg1.GetReflection()->ListFields(msg1, &fields);
util::MessageDifferencer differencer;
@@ -843,7 +843,7 @@ TEST(MessageDifferencerTest, SpecifiedFieldsCompareWithSelf) {
{
// Compare with a subset of fields.
- vector<const FieldDescriptor*> compare_fields;
+ std::vector<const FieldDescriptor*> compare_fields;
for (int i = 0; i < fields.size(); ++i) {
if (i % 2 == 0) {
compare_fields.push_back(fields[i]);
@@ -856,8 +856,8 @@ TEST(MessageDifferencerTest, SpecifiedFieldsCompareWithSelf) {
// Specify a different set of fields to compare, even though we're using the
// same message. This should fail, since we are explicitly saying that the
// set of fields are different.
- vector<const FieldDescriptor*> compare_fields1;
- vector<const FieldDescriptor*> compare_fields2;
+ std::vector<const FieldDescriptor*> compare_fields1;
+ std::vector<const FieldDescriptor*> compare_fields2;
for (int i = 0; i < fields.size(); ++i) {
if (i % 2 == 0) {
compare_fields1.push_back(fields[i]);
@@ -880,8 +880,8 @@ TEST(MessageDifferencerTest, SpecifiedFieldsEqualityAllShuffledTest) {
TestUtil::SetAllFields(&msg1);
TestUtil::SetAllFields(&msg2);
- vector<const FieldDescriptor*> fields1;
- vector<const FieldDescriptor*> fields2;
+ std::vector<const FieldDescriptor*> fields1;
+ std::vector<const FieldDescriptor*> fields2;
msg1.GetReflection()->ListFields(msg1, &fields1);
msg2.GetReflection()->ListFields(msg2, &fields2);
@@ -899,10 +899,10 @@ TEST(MessageDifferencerTest, SpecifiedFieldsSubsetEqualityTest) {
TestUtil::SetAllFields(&msg1);
TestUtil::SetAllFields(&msg2);
- vector<const FieldDescriptor*> fields1;
+ std::vector<const FieldDescriptor*> fields1;
msg1.GetReflection()->ListFields(msg1, &fields1);
- vector<const FieldDescriptor*> compare_fields;
+ std::vector<const FieldDescriptor*> compare_fields;
// Only compare the field descriptors with even indices.
for (int i = 0; i < fields1.size(); ++i) {
if (i % 2 == 0) {
@@ -925,11 +925,11 @@ TEST(MessageDifferencerTest,
TestUtil::SetAllFields(&msg1);
TestUtil::SetAllFields(&msg2);
- vector<const FieldDescriptor*> fields1;
+ std::vector<const FieldDescriptor*> fields1;
const Reflection* reflection = msg1.GetReflection();
reflection->ListFields(msg1, &fields1);
- vector<const FieldDescriptor*> compare_fields;
+ std::vector<const FieldDescriptor*> compare_fields;
// Only compare the field descriptors with even indices.
for (int i = 0; i < fields1.size(); ++i) {
if (i % 2 == 0) {
@@ -954,10 +954,10 @@ TEST(MessageDifferencerTest, SpecifiedFieldsDetectsDifferencesTest) {
TestUtil::SetAllFields(&msg2);
TestUtil::ModifyRepeatedFields(&msg2);
- vector<const FieldDescriptor*> fields1;
+ std::vector<const FieldDescriptor*> fields1;
msg1.GetReflection()->ListFields(msg1, &fields1);
- vector<const FieldDescriptor*> compare_fields;
+ std::vector<const FieldDescriptor*> compare_fields;
// Only compare the repeated field descriptors.
for (int i = 0; i < fields1.size(); ++i) {
if (fields1[i]->is_repeated()) {
@@ -977,8 +977,8 @@ TEST(MessageDifferencerTest, SpecifiedFieldsEquivalenceAllTest) {
TestUtil::SetAllFields(&msg1);
TestUtil::SetAllFields(&msg2);
- vector<const FieldDescriptor*> fields1;
- vector<const FieldDescriptor*> fields2;
+ std::vector<const FieldDescriptor*> fields1;
+ std::vector<const FieldDescriptor*> fields2;
msg1.GetReflection()->ListFields(msg1, &fields1);
msg2.GetReflection()->ListFields(msg2, &fields2);
@@ -1011,8 +1011,8 @@ TEST(MessageDifferencerTest,
// actually doing something.
msg2.set_optional_uint64(23);
- vector<const FieldDescriptor*> fields1;
- vector<const FieldDescriptor*> fields2;
+ std::vector<const FieldDescriptor*> fields1;
+ std::vector<const FieldDescriptor*> fields2;
fields1.push_back(optional_int32_desc);
fields1.push_back(default_int64_desc);
@@ -1286,7 +1286,7 @@ TEST(MessageDifferencerTest, RepeatedFieldMapTest_MultipleFieldsAsKey) {
util::MessageDifferencer differencer;
differencer.TreatAsSet(GetFieldDescriptor(msg1, "item.ra"));
EXPECT_FALSE(differencer.Compare(msg1, msg2));
- vector<const FieldDescriptor*> key_fields;
+ std::vector<const FieldDescriptor*> key_fields;
key_fields.push_back(GetFieldDescriptor(msg1, "item.a"));
key_fields.push_back(GetFieldDescriptor(msg1, "item.ra"));
differencer.TreatAsMapWithMultipleFieldsAsKey(
@@ -1363,11 +1363,11 @@ TEST(MessageDifferencerTest, RepeatedFieldMapTest_MultipleFieldPathsAsKey) {
util::MessageDifferencer differencer;
differencer.TreatAsSet(GetFieldDescriptor(msg1, "item.m.rc"));
EXPECT_FALSE(differencer.Compare(msg1, msg2));
- vector<vector<const FieldDescriptor*> > key_field_paths;
- vector<const FieldDescriptor*> key_field_path1;
+ std::vector<std::vector<const FieldDescriptor*> > key_field_paths;
+ std::vector<const FieldDescriptor*> key_field_path1;
key_field_path1.push_back(GetFieldDescriptor(msg1, "item.m"));
key_field_path1.push_back(GetFieldDescriptor(msg1, "item.m.a"));
- vector<const FieldDescriptor*> key_field_path2;
+ std::vector<const FieldDescriptor*> key_field_path2;
key_field_path2.push_back(GetFieldDescriptor(msg1, "item.m"));
key_field_path2.push_back(GetFieldDescriptor(msg1, "item.m.rc"));
key_field_paths.push_back(key_field_path1);
@@ -1413,7 +1413,7 @@ TEST(MessageDifferencerTest, RepeatedFieldMapTest_IgnoredKeyFields) {
item->set_b("world");
// Compare
util::MessageDifferencer differencer;
- vector<const FieldDescriptor*> key_fields;
+ std::vector<const FieldDescriptor*> key_fields;
key_fields.push_back(GetFieldDescriptor(msg1, "item.a"));
key_fields.push_back(GetFieldDescriptor(msg1, "item.ra"));
differencer.TreatAsMapWithMultipleFieldsAsKey(
@@ -1457,7 +1457,8 @@ class TestIgnorer : public util::MessageDifferencer::IgnoreCriteria {
virtual bool IsIgnored(
const Message& message1, const Message& message2,
const FieldDescriptor* field,
- const vector<util::MessageDifferencer::SpecificField>& parent_fields) {
+ const std::vector<util::MessageDifferencer::SpecificField>&
+ parent_fields) {
string name = "";
for (int i = 0; i < parent_fields.size(); ++i) {
name += parent_fields[i].field->name() + ".";
@@ -1502,7 +1503,7 @@ class ValueProductMapKeyComparator
typedef util::MessageDifferencer::SpecificField SpecificField;
virtual bool IsMatch(
const Message &message1, const Message &message2,
- const vector<SpecificField>& parent_fields) const {
+ const std::vector<SpecificField>& parent_fields) const {
const Reflection* reflection1 = message1.GetReflection();
const Reflection* reflection2 = message2.GetReflection();
// FieldDescriptor for item.ra
@@ -1863,7 +1864,7 @@ TEST(MessageDifferencerTest, IgnoreField_TrumpsCompareWithFields) {
const FieldDescriptor* c = GetFieldDescriptor(msg1, "c");
const FieldDescriptor* rc = GetFieldDescriptor(msg1, "rc");
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
fields.push_back(c);
fields.push_back(rc);
@@ -1899,12 +1900,12 @@ class ParentSavingFieldComparator : public util::FieldComparator {
}
}
- vector<google::protobuf::util::MessageDifferencer::SpecificField> parent_fields() {
+ std::vector<google::protobuf::util::MessageDifferencer::SpecificField> parent_fields() {
return parent_fields_;
}
private:
- vector<google::protobuf::util::MessageDifferencer::SpecificField> parent_fields_;
+ std::vector<google::protobuf::util::MessageDifferencer::SpecificField> parent_fields_;
};
// Tests if MessageDifferencer sends the parent fields in the FieldContext
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/message_differencer_unittest.proto b/third_party/protobuf/src/google/protobuf/util/message_differencer_unittest.proto
index 698775f14c..698775f14c 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/message_differencer_unittest.proto
+++ b/third_party/protobuf/src/google/protobuf/util/message_differencer_unittest.proto
diff --git a/third_party/protobuf/src/google/protobuf/util/package_info.h b/third_party/protobuf/src/google/protobuf/util/package_info.h
new file mode 100644
index 0000000000..e37e6dc098
--- /dev/null
+++ b/third_party/protobuf/src/google/protobuf/util/package_info.h
@@ -0,0 +1,46 @@
+// 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.
+
+// This file exists solely to document the google::protobuf::util namespace.
+// It is not compiled into anything, but it may be read by an automated
+// documentation generator.
+
+namespace google {
+
+namespace protobuf {
+
+// Utility classes.
+//
+// This package contains various utilities for message comprasion, JSON
+// conversion, well known types, etc.
+namespace util {}
+
+} // namespace protobuf
+} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/time_util.cc b/third_party/protobuf/src/google/protobuf/util/time_util.cc
index 031d019ab9..b11f822ad9 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/time_util.cc
+++ b/third_party/protobuf/src/google/protobuf/util/time_util.cc
@@ -143,11 +143,13 @@ int64 RoundTowardZero(int64 value, int64 divider) {
} // namespace
// Actually define these static const integers. Required by C++ standard (but
-// omitting them may still work with some compilers).
+// some compilers don't like it).
+#ifndef _MSC_VER
const int64 TimeUtil::kTimestampMinSeconds;
const int64 TimeUtil::kTimestampMaxSeconds;
const int64 TimeUtil::kDurationMaxSeconds;
const int64 TimeUtil::kDurationMinSeconds;
+#endif // !_MSC_VER
string TimeUtil::ToString(const Timestamp& timestamp) {
return FormatTime(timestamp.seconds(), timestamp.nanos());
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/time_util.h b/third_party/protobuf/src/google/protobuf/util/time_util.h
index 1bac089707..b8846935a7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/time_util.h
+++ b/third_party/protobuf/src/google/protobuf/util/time_util.h
@@ -28,6 +28,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// Defines utilities for the Timestamp and Duration well known types.
+
#ifndef GOOGLE_PROTOBUF_UTIL_TIME_UTIL_H__
#define GOOGLE_PROTOBUF_UTIL_TIME_UTIL_H__
@@ -47,6 +49,7 @@ namespace google {
namespace protobuf {
namespace util {
+// Utility functions for Timestamp and Duration.
class LIBPROTOBUF_EXPORT TimeUtil {
typedef google::protobuf::Timestamp Timestamp;
typedef google::protobuf::Duration Duration;
@@ -234,7 +237,7 @@ inline Duration operator%(const Duration& d1, const Duration& d2) {
return result %= d2;
}
-inline ostream& operator<<(ostream& out, const Duration& d) {
+inline std::ostream& operator<<(std::ostream& out, const Duration& d) {
out << google::protobuf::util::TimeUtil::ToString(d);
return out;
}
@@ -281,7 +284,7 @@ inline Timestamp operator-(const Timestamp& t, const Duration& d) {
}
LIBPROTOBUF_EXPORT Duration operator-(const Timestamp& t1, const Timestamp& t2);
-inline ostream& operator<<(ostream& out, const Timestamp& t) {
+inline std::ostream& operator<<(std::ostream& out, const Timestamp& t) {
out << google::protobuf::util::TimeUtil::ToString(t);
return out;
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/time_util_test.cc b/third_party/protobuf/src/google/protobuf/util/time_util_test.cc
index 285740abe1..285740abe1 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/time_util_test.cc
+++ b/third_party/protobuf/src/google/protobuf/util/time_util_test.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/type_resolver.h b/third_party/protobuf/src/google/protobuf/util/type_resolver.h
index 77d4416a71..959f3c7933 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/type_resolver.h
+++ b/third_party/protobuf/src/google/protobuf/util/type_resolver.h
@@ -28,6 +28,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// Defines a TypeResolver for the Any message.
+
#ifndef GOOGLE_PROTOBUF_UTIL_TYPE_RESOLVER_H__
#define GOOGLE_PROTOBUF_UTIL_TYPE_RESOLVER_H__
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/type_resolver_util.cc b/third_party/protobuf/src/google/protobuf/util/type_resolver_util.cc
index 963939032a..febaa41f75 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/type_resolver_util.cc
+++ b/third_party/protobuf/src/google/protobuf/util/type_resolver_util.cc
@@ -54,17 +54,6 @@ using util::Status;
using util::error::INVALID_ARGUMENT;
using util::error::NOT_FOUND;
-bool SplitTypeUrl(const string& type_url, string* url_prefix,
- string* message_name) {
- size_t pos = type_url.find_last_of("/");
- if (pos == string::npos) {
- return false;
- }
- *url_prefix = type_url.substr(0, pos);
- *message_name = type_url.substr(pos + 1);
- return true;
-}
-
class DescriptorPoolTypeResolver : public TypeResolver {
public:
DescriptorPoolTypeResolver(const string& url_prefix,
@@ -72,38 +61,27 @@ class DescriptorPoolTypeResolver : public TypeResolver {
: url_prefix_(url_prefix), pool_(pool) {}
Status ResolveMessageType(const string& type_url, Type* type) {
- string url_prefix, message_name;
- if (!SplitTypeUrl(type_url, &url_prefix, &message_name) ||
- url_prefix != url_prefix_) {
- return Status(INVALID_ARGUMENT,
- StrCat("Invalid type URL, type URLs must be of the form '",
- url_prefix_, "/<typename>', got: ", type_url));
+ string type_name;
+ Status status = ParseTypeUrl(type_url, &type_name);
+ if (!status.ok()) {
+ return status;
}
- if (url_prefix != url_prefix_) {
- return Status(INVALID_ARGUMENT,
- "Cannot resolve types from URL: " + url_prefix);
- }
- const Descriptor* descriptor = pool_->FindMessageTypeByName(message_name);
+
+ const Descriptor* descriptor = pool_->FindMessageTypeByName(type_name);
if (descriptor == NULL) {
- return Status(NOT_FOUND,
- "Invalid type URL, unknown type: " + message_name);
+ return Status(NOT_FOUND, "Invalid type URL, unknown type: " + type_name);
}
ConvertDescriptor(descriptor, type);
return Status();
}
Status ResolveEnumType(const string& type_url, Enum* enum_type) {
- string url_prefix, type_name;
- if (!SplitTypeUrl(type_url, &url_prefix, &type_name) ||
- url_prefix != url_prefix_) {
- return Status(INVALID_ARGUMENT,
- StrCat("Invalid type URL, type URLs must be of the form '",
- url_prefix_, "/<typename>', got: ", type_url));
- }
- if (url_prefix != url_prefix_) {
- return Status(INVALID_ARGUMENT,
- "Cannot resolve types from URL: " + url_prefix);
+ string type_name;
+ Status status = ParseTypeUrl(type_url, &type_name);
+ if (!status.ok()) {
+ return status;
}
+
const EnumDescriptor* descriptor = pool_->FindEnumTypeByName(type_name);
if (descriptor == NULL) {
return Status(NOT_FOUND, "Invalid type URL, unknown type: " + type_name);
@@ -203,6 +181,16 @@ class DescriptorPoolTypeResolver : public TypeResolver {
return url_prefix_ + "/" + descriptor->full_name();
}
+ Status ParseTypeUrl(const string& type_url, string* type_name) {
+ if (type_url.substr(0, url_prefix_.size() + 1) != url_prefix_ + "/") {
+ return Status(INVALID_ARGUMENT,
+ StrCat("Invalid type URL, type URLs must be of the form '",
+ url_prefix_, "/<typename>', got: ", type_url));
+ }
+ *type_name = type_url.substr(url_prefix_.size() + 1);
+ return Status();
+ }
+
string DefaultValueAsString(const FieldDescriptor* descriptor) {
switch (descriptor->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/type_resolver_util.h b/third_party/protobuf/src/google/protobuf/util/type_resolver_util.h
index c0ef3c1af9..c17366fc79 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/type_resolver_util.h
+++ b/third_party/protobuf/src/google/protobuf/util/type_resolver_util.h
@@ -28,6 +28,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// Defines utilities for the TypeResolver.
+
#ifndef GOOGLE_PROTOBUF_UTIL_TYPE_RESOLVER_UTIL_H__
#define GOOGLE_PROTOBUF_UTIL_TYPE_RESOLVER_UTIL_H__
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/util/type_resolver_util_test.cc b/third_party/protobuf/src/google/protobuf/util/type_resolver_util_test.cc
index 8a0bf65297..8a0bf65297 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/util/type_resolver_util_test.cc
+++ b/third_party/protobuf/src/google/protobuf/util/type_resolver_util_test.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/well_known_types_unittest.cc b/third_party/protobuf/src/google/protobuf/well_known_types_unittest.cc
index c9a9aa10ec..c9a9aa10ec 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/well_known_types_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/well_known_types_unittest.cc
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/wire_format.cc b/third_party/protobuf/src/google/protobuf/wire_format.cc
index 5ee4e25d49..bd5b248916 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/wire_format.cc
+++ b/third_party/protobuf/src/google/protobuf/wire_format.cc
@@ -42,6 +42,8 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/stringprintf.h>
#include <google/protobuf/descriptor.h>
+#include <google/protobuf/dynamic_message.h>
+#include <google/protobuf/map_field.h>
#include <google/protobuf/wire_format_lite_inl.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/io/coded_stream.h>
@@ -307,9 +309,9 @@ uint8* WireFormat::SerializeUnknownMessageSetItemsToArray(
return target;
}
-int WireFormat::ComputeUnknownFieldsSize(
+size_t WireFormat::ComputeUnknownFieldsSize(
const UnknownFieldSet& unknown_fields) {
- int size = 0;
+ size_t size = 0;
for (int i = 0; i < unknown_fields.field_count(); i++) {
const UnknownField& field = unknown_fields.field(i);
@@ -355,9 +357,9 @@ int WireFormat::ComputeUnknownFieldsSize(
return size;
}
-int WireFormat::ComputeUnknownMessageSetItemsSize(
+size_t WireFormat::ComputeUnknownMessageSetItemsSize(
const UnknownFieldSet& unknown_fields) {
- int size = 0;
+ size_t size = 0;
for (int i = 0; i < unknown_fields.field_count(); i++) {
const UnknownField& field = unknown_fields.field(i);
@@ -792,7 +794,7 @@ void WireFormat::SerializeWithCachedSizes(
const Reflection* message_reflection = message.GetReflection();
int expected_endpoint = output->ByteCount() + size;
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
message_reflection->ListFields(message, &fields);
for (int i = 0; i < fields.size(); i++) {
SerializeFieldWithCachedSizes(fields[i], message, output);
@@ -834,11 +836,18 @@ void WireFormat::SerializeFieldWithCachedSizes(
count = 1;
}
+ // map_entries is for maps that'll be deterministically serialized.
+ std::vector<const Message*> map_entries;
+ if (count > 1 && field->is_map() && output->IsSerializationDeterministic()) {
+ map_entries =
+ DynamicMapSorter::Sort(message, count, message_reflection, field);
+ }
+
const bool is_packed = field->is_packed();
if (is_packed && count > 0) {
WireFormatLite::WriteTag(field->number(),
WireFormatLite::WIRETYPE_LENGTH_DELIMITED, output);
- const int data_size = FieldDataOnlyByteSize(field, message);
+ const size_t data_size = FieldDataOnlyByteSize(field, message);
output->WriteVarint32(data_size);
}
@@ -877,15 +886,17 @@ void WireFormat::SerializeFieldWithCachedSizes(
HANDLE_PRIMITIVE_TYPE(BOOL, bool, Bool, Bool)
#undef HANDLE_PRIMITIVE_TYPE
-#define HANDLE_TYPE(TYPE, TYPE_METHOD, CPPTYPE_METHOD) \
- case FieldDescriptor::TYPE_##TYPE: \
- WireFormatLite::Write##TYPE_METHOD( \
- field->number(), \
- field->is_repeated() ? \
- message_reflection->GetRepeated##CPPTYPE_METHOD( \
- message, field, j) : \
- message_reflection->Get##CPPTYPE_METHOD(message, field), \
- output); \
+#define HANDLE_TYPE(TYPE, TYPE_METHOD, CPPTYPE_METHOD) \
+ case FieldDescriptor::TYPE_##TYPE: \
+ WireFormatLite::Write##TYPE_METHOD( \
+ field->number(), \
+ field->is_repeated() ? \
+ (map_entries.empty() ? \
+ message_reflection->GetRepeated##CPPTYPE_METHOD( \
+ message, field, j) : \
+ *map_entries[j]) : \
+ message_reflection->Get##CPPTYPE_METHOD(message, field), \
+ output); \
break;
HANDLE_TYPE(GROUP , Group , Message)
@@ -964,13 +975,13 @@ void WireFormat::SerializeMessageSetItemWithCachedSizes(
// ===================================================================
-int WireFormat::ByteSize(const Message& message) {
+size_t WireFormat::ByteSize(const Message& message) {
const Descriptor* descriptor = message.GetDescriptor();
const Reflection* message_reflection = message.GetReflection();
- int our_size = 0;
+ size_t our_size = 0;
- vector<const FieldDescriptor*> fields;
+ std::vector<const FieldDescriptor*> fields;
message_reflection->ListFields(message, &fields);
for (int i = 0; i < fields.size(); i++) {
our_size += FieldByteSize(fields[i], message);
@@ -987,7 +998,7 @@ int WireFormat::ByteSize(const Message& message) {
return our_size;
}
-int WireFormat::FieldByteSize(
+size_t WireFormat::FieldByteSize(
const FieldDescriptor* field,
const Message& message) {
const Reflection* message_reflection = message.GetReflection();
@@ -999,15 +1010,15 @@ int WireFormat::FieldByteSize(
return MessageSetItemByteSize(field, message);
}
- int count = 0;
+ size_t count = 0;
if (field->is_repeated()) {
- count = message_reflection->FieldSize(message, field);
+ count = FromIntSize(message_reflection->FieldSize(message, field));
} else if (message_reflection->HasField(message, field)) {
count = 1;
}
- const int data_size = FieldDataOnlyByteSize(field, message);
- int our_size = data_size;
+ const size_t data_size = FieldDataOnlyByteSize(field, message);
+ size_t our_size = data_size;
if (field->is_packed()) {
if (data_size > 0) {
// Packed fields get serialized like a string, not their native type.
@@ -1022,19 +1033,20 @@ int WireFormat::FieldByteSize(
return our_size;
}
-int WireFormat::FieldDataOnlyByteSize(
+size_t WireFormat::FieldDataOnlyByteSize(
const FieldDescriptor* field,
const Message& message) {
const Reflection* message_reflection = message.GetReflection();
- int count = 0;
+ size_t count = 0;
if (field->is_repeated()) {
- count = message_reflection->FieldSize(message, field);
+ count =
+ internal::FromIntSize(message_reflection->FieldSize(message, field));
} else if (message_reflection->HasField(message, field)) {
count = 1;
}
- int data_size = 0;
+ size_t data_size = 0;
switch (field->type()) {
#define HANDLE_TYPE(TYPE, TYPE_METHOD, CPPTYPE_METHOD) \
case FieldDescriptor::TYPE_##TYPE: \
@@ -1108,19 +1120,19 @@ int WireFormat::FieldDataOnlyByteSize(
return data_size;
}
-int WireFormat::MessageSetItemByteSize(
+size_t WireFormat::MessageSetItemByteSize(
const FieldDescriptor* field,
const Message& message) {
const Reflection* message_reflection = message.GetReflection();
- int our_size = WireFormatLite::kMessageSetItemTagsSize;
+ size_t our_size = WireFormatLite::kMessageSetItemTagsSize;
// type_id
our_size += io::CodedOutputStream::VarintSize32(field->number());
// message
const Message& sub_message = message_reflection->GetMessage(message, field);
- int message_size = sub_message.ByteSize();
+ size_t message_size = sub_message.ByteSizeLong();
our_size += io::CodedOutputStream::VarintSize32(message_size);
our_size += message_size;
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/wire_format.h b/third_party/protobuf/src/google/protobuf/wire_format.h
index aaee21f02d..5e9aca524f 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/wire_format.h
+++ b/third_party/protobuf/src/google/protobuf/wire_format.h
@@ -85,7 +85,7 @@ class LIBPROTOBUF_EXPORT WireFormat {
// Compute the byte size of a tag. For groups, this includes both the start
// and end tags.
- static inline int TagSize(int field_number, FieldDescriptor::Type type);
+ static inline size_t TagSize(int field_number, FieldDescriptor::Type type);
// These procedures can be used to implement the methods of Message which
// handle parsing and serialization of the protocol buffer wire format
@@ -122,7 +122,7 @@ class LIBPROTOBUF_EXPORT WireFormat {
// will have their ByteSize() methods called, so their sizes will be cached.
// Therefore, calling this method is sufficient to allow you to call
// WireFormat::SerializeWithCachedSizes() on the same object.
- static int ByteSize(const Message& message);
+ static size_t ByteSize(const Message& message);
// -----------------------------------------------------------------
// Helpers for dealing with unknown fields
@@ -173,11 +173,11 @@ class LIBPROTOBUF_EXPORT WireFormat {
uint8* target);
// Compute the size of the UnknownFieldSet on the wire.
- static int ComputeUnknownFieldsSize(const UnknownFieldSet& unknown_fields);
+ static size_t ComputeUnknownFieldsSize(const UnknownFieldSet& unknown_fields);
// Same thing except for messages that have the message_set_wire_format
// option.
- static int ComputeUnknownMessageSetItemsSize(
+ static size_t ComputeUnknownMessageSetItemsSize(
const UnknownFieldSet& unknown_fields);
@@ -205,7 +205,7 @@ class LIBPROTOBUF_EXPORT WireFormat {
// Compute size of a single field. If the field is a message type, this
// will call ByteSize() for the embedded message, insuring that it caches
// its size.
- static int FieldByteSize(
+ static size_t FieldByteSize(
const FieldDescriptor* field, // Cannot be NULL
const Message& message);
@@ -218,7 +218,7 @@ class LIBPROTOBUF_EXPORT WireFormat {
const FieldDescriptor* field,
const Message& message,
io::CodedOutputStream* output);
- static int MessageSetItemByteSize(
+ static size_t MessageSetItemByteSize(
const FieldDescriptor* field,
const Message& message);
@@ -226,7 +226,7 @@ class LIBPROTOBUF_EXPORT WireFormat {
// only includes the size of the raw data, and not the size of the total
// length, but for other length-delimited types, the size of the length is
// included.
- static int FieldDataOnlyByteSize(
+ static size_t FieldDataOnlyByteSize(
const FieldDescriptor* field, // Cannot be NULL
const Message& message);
@@ -301,7 +301,8 @@ inline uint32 WireFormat::MakeTag(const FieldDescriptor* field) {
return WireFormatLite::MakeTag(field->number(), WireTypeForField(field));
}
-inline int WireFormat::TagSize(int field_number, FieldDescriptor::Type type) {
+inline size_t WireFormat::TagSize(int field_number,
+ FieldDescriptor::Type type) {
// Some compilers don't like enum -> enum casts, so we implicit_cast to
// int first.
return WireFormatLite::TagSize(field_number,
@@ -326,6 +327,9 @@ inline void WireFormat::VerifyUTF8StringNamedField(
#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED
WireFormatLite::VerifyUtf8String(
data, size, static_cast<WireFormatLite::Operation>(op), field_name);
+#else
+ // Avoid the compiler warning about unused variables.
+ (void)data; (void)size; (void)op; (void)field_name;
#endif
}
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/wire_format_lite.cc b/third_party/protobuf/src/google/protobuf/wire_format_lite.cc
index 05cc0854cb..e46ac40010 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/wire_format_lite.cc
+++ b/third_party/protobuf/src/google/protobuf/wire_format_lite.cc
@@ -34,6 +34,9 @@
#include <google/protobuf/wire_format_lite_inl.h>
+#ifdef __SSE_4_1__
+#include <immintrin.h>
+#endif
#include <stack>
#include <string>
#include <vector>
@@ -61,7 +64,7 @@ const int WireFormatLite::kMessageSetMessageTag;
#endif
// IBM xlC requires prefixing constants with WireFormatLite::
-const int WireFormatLite::kMessageSetItemTagsSize =
+const size_t WireFormatLite::kMessageSetItemTagsSize =
io::CodedOutputStream::StaticVarintSize32<
WireFormatLite::kMessageSetItemStartTag>::value +
io::CodedOutputStream::StaticVarintSize32<
@@ -337,6 +340,90 @@ bool WireFormatLite::ReadPackedEnumPreserveUnknowns(
return true;
}
+namespace {
+void EncodeFixedSizeValue(float v, uint8* dest) {
+ WireFormatLite::WriteFloatNoTagToArray(v, dest);
+}
+
+void EncodeFixedSizeValue(double v, uint8* dest) {
+ WireFormatLite::WriteDoubleNoTagToArray(v, dest);
+}
+
+void EncodeFixedSizeValue(uint32 v, uint8* dest) {
+ WireFormatLite::WriteFixed32NoTagToArray(v, dest);
+}
+
+void EncodeFixedSizeValue(uint64 v, uint8* dest) {
+ WireFormatLite::WriteFixed64NoTagToArray(v, dest);
+}
+
+void EncodeFixedSizeValue(int32 v, uint8* dest) {
+ WireFormatLite::WriteSFixed32NoTagToArray(v, dest);
+}
+
+void EncodeFixedSizeValue(int64 v, uint8* dest) {
+ WireFormatLite::WriteSFixed64NoTagToArray(v, dest);
+}
+
+void EncodeFixedSizeValue(bool v, uint8* dest) {
+ WireFormatLite::WriteBoolNoTagToArray(v, dest);
+}
+} // anonymous namespace
+
+template <typename CType>
+static void WriteArray(const CType* a, int n, io::CodedOutputStream* output) {
+#if defined(PROTOBUF_LITTLE_ENDIAN)
+ output->WriteRaw(reinterpret_cast<const char*>(a), n * sizeof(a[0]));
+#else
+ const int kAtATime = 128;
+ uint8 buf[sizeof(CType) * kAtATime];
+ for (int i = 0; i < n; i += kAtATime) {
+ int to_do = min(kAtATime, n - i);
+ uint8* ptr = buf;
+ for (int j = 0; j < to_do; j++) {
+ EncodeFixedSizeValue(a[i+j], ptr);
+ ptr += sizeof(a[0]);
+ }
+ output->WriteRaw(buf, to_do * sizeof(a[0]));
+ }
+#endif
+}
+
+void WireFormatLite::WriteFloatArray(const float* a, int n,
+ io::CodedOutputStream* output) {
+ WriteArray<float>(a, n, output);
+}
+
+void WireFormatLite::WriteDoubleArray(const double* a, int n,
+ io::CodedOutputStream* output) {
+ WriteArray<double>(a, n, output);
+}
+
+void WireFormatLite::WriteFixed32Array(const uint32* a, int n,
+ io::CodedOutputStream* output) {
+ WriteArray<uint32>(a, n, output);
+}
+
+void WireFormatLite::WriteFixed64Array(const uint64* a, int n,
+ io::CodedOutputStream* output) {
+ WriteArray<uint64>(a, n, output);
+}
+
+void WireFormatLite::WriteSFixed32Array(const int32* a, int n,
+ io::CodedOutputStream* output) {
+ WriteArray<int32>(a, n, output);
+}
+
+void WireFormatLite::WriteSFixed64Array(const int64* a, int n,
+ io::CodedOutputStream* output) {
+ WriteArray<int64>(a, n, output);
+}
+
+void WireFormatLite::WriteBoolArray(const bool* a, int n,
+ io::CodedOutputStream* output) {
+ WriteArray<bool>(a, n, output);
+}
+
void WireFormatLite::WriteInt32(int field_number, int32 value,
io::CodedOutputStream* output) {
WriteTag(field_number, WIRETYPE_VARINT, output);
@@ -467,7 +554,7 @@ void WireFormatLite::WriteGroupMaybeToArray(int field_number,
uint8* target = output->GetDirectBufferForNBytesAndAdvance(size);
if (target != NULL) {
uint8* end = value.InternalSerializeWithCachedSizesToArray(
- output->IsSerializationDeterminstic(), target);
+ output->IsSerializationDeterministic(), target);
GOOGLE_DCHECK_EQ(end - target, size);
} else {
value.SerializeWithCachedSizes(output);
@@ -484,7 +571,7 @@ void WireFormatLite::WriteMessageMaybeToArray(int field_number,
uint8* target = output->GetDirectBufferForNBytesAndAdvance(size);
if (target != NULL) {
uint8* end = value.InternalSerializeWithCachedSizesToArray(
- output->IsSerializationDeterminstic(), target);
+ output->IsSerializationDeterministic(), target);
GOOGLE_DCHECK_EQ(end - target, size);
} else {
value.SerializeWithCachedSizes(output);
@@ -540,6 +627,152 @@ bool WireFormatLite::VerifyUtf8String(const char* data,
return true;
}
+#ifdef __SSE_4_1__
+template<typename T, bool ZigZag, bool SignExtended>
+static size_t VarintSize(
+ const T* data, const int n,
+ const internal::enable_if<sizeof(T) == 4>::type* = NULL) {
+#if __cplusplus >= 201103L
+ // is_unsigned<T> => !ZigZag
+ static_assert((std::is_unsigned<T>::value ^ ZigZag) ||
+ std::is_signed<T>::value,
+ "Cannot ZigZag encode unsigned types");
+ // is_unsigned<T> => !SignExtended
+ static_assert((std::is_unsigned<T>::value ^ SignExtended) ||
+ std::is_signed<T>::value,
+ "Cannot SignExtended unsigned types");
+#endif
+
+ union vus32 {
+ uint32 u[4];
+ int32 s[4];
+ __m128i v;
+ };
+
+ static const vus32 ones = {{1, 1, 1, 1}};
+
+ // CodedOutputStream::VarintSize32SignExtended returns 10 for negative
+ // numbers. We can apply the UInt32Size algorithm, and simultaneously logical
+ // shift the MSB into the LSB to determine if it is negative.
+ static const vus32 fives = {{5, 5, 5, 5}};
+
+ // sum is the vectorized-output of calling CodedOutputStream::VarintSize32 on
+ // the processed elements.
+ //
+ // msb_sum is the count of set most-significant bits. When computing the
+ // vectorized CodedOutputStream::VarintSize32SignExtended, negative values
+ // have the most significant bit set. VarintSize32SignExtended returns 10 and
+ // VarintSize32 returns 5. msb_sum allows us to compute:
+ // VarintSize32SignExtended = msb_sum * 5 + VarintSize32
+ vus32 sum, v, msb_sum;
+ sum.v = _mm_setzero_si128();
+ msb_sum.v = _mm_setzero_si128();
+
+ int rounded = n & ~(3);
+ int i;
+ for (i = 0; i < rounded; i += 4) {
+ v.v = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&data[i]));
+
+ if (ZigZag) {
+ // Note: the right-shift must be arithmetic
+ v.v = _mm_xor_si128(_mm_slli_epi32(v.v, 1), _mm_srai_epi32(v.v, 31));
+ }
+
+ sum.v = _mm_add_epi32(sum.v, ones.v);
+ if (SignExtended) {
+ msb_sum.v = _mm_add_epi32(msb_sum.v, _mm_srli_epi32(v.v, 31));
+ }
+
+ v.v = _mm_srli_epi32(v.v, 7);
+
+ for (int j = 0; j < 4; j++) {
+ __m128i min = _mm_min_epi32(v.v, ones.v);
+
+ sum.v = _mm_add_epi32(sum.v, min);
+ v.v = _mm_srli_epi32(v.v, 7);
+ }
+ }
+
+ if (SignExtended) {
+ vus32 extensions;
+ extensions.v = _mm_mullo_epi32(msb_sum.v, fives.v);
+
+ sum.v = _mm_add_epi32(sum.v, extensions.v);
+ }
+
+ // TODO(ckennelly): Can we avoid the sign conversion?
+ size_t out = _mm_cvtsi128_si32(
+ _mm_hadd_epi32(_mm_hadd_epi32(sum.v, ones.v), ones.v));
+
+ // Finish tail.
+ for (; i < n; i++) {
+ if (ZigZag) {
+ out += WireFormatLite::SInt32Size(data[i]);
+ } else if (SignExtended) {
+ out += WireFormatLite::Int32Size(data[i]);
+ } else {
+ out += WireFormatLite::UInt32Size(data[i]);
+ }
+ }
+
+ return out;
+}
+
+size_t WireFormatLite::Int32Size(const RepeatedField<int32>& value) {
+ return VarintSize<int32, false, true>(value.data(), value.size());
+}
+
+size_t WireFormatLite::UInt32Size(const RepeatedField<uint32>& value) {
+ return VarintSize<uint32, false, false>(value.data(), value.size());
+}
+
+size_t WireFormatLite::SInt32Size(const RepeatedField<int32>& value) {
+ return VarintSize<int32, true, true>(value.data(), value.size());
+}
+
+size_t WireFormatLite::EnumSize(const RepeatedField<int>& value) {
+ // On ILP64, sizeof(int) == 8, which would require a different template.
+ return VarintSize<int, false, true>(value.data(), value.size());
+}
+
+#else // !__SSE_4_1__
+size_t WireFormatLite::Int32Size(const RepeatedField<int32>& value) {
+ size_t out = 0;
+ const int n = value.size();
+ for (int i = 0; i < n; i++) {
+ out += Int32Size(value.Get(i));
+ }
+ return out;
+}
+
+size_t WireFormatLite::UInt32Size(const RepeatedField<uint32>& value) {
+ size_t out = 0;
+ const int n = value.size();
+ for (int i = 0; i < n; i++) {
+ out += UInt32Size(value.Get(i));
+ }
+ return out;
+}
+
+size_t WireFormatLite::SInt32Size(const RepeatedField<int32>& value) {
+ size_t out = 0;
+ const int n = value.size();
+ for (int i = 0; i < n; i++) {
+ out += SInt32Size(value.Get(i));
+ }
+ return out;
+}
+
+size_t WireFormatLite::EnumSize(const RepeatedField<int>& value) {
+ size_t out = 0;
+ const int n = value.size();
+ for (int i = 0; i < n; i++) {
+ out += EnumSize(value.Get(i));
+ }
+ return out;
+}
+#endif
+
} // namespace internal
} // namespace protobuf
} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/wire_format_lite.h b/third_party/protobuf/src/google/protobuf/wire_format_lite.h
index 580d4db03b..60355144a5 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/wire_format_lite.h
+++ b/third_party/protobuf/src/google/protobuf/wire_format_lite.h
@@ -42,9 +42,20 @@
#include <string>
#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/repeated_field.h>
#include <google/protobuf/message_lite.h>
#include <google/protobuf/io/coded_stream.h> // for CodedOutputStream::Varint32Size
+// Avoid conflict with iOS where <ConditionalMacros.h> #defines TYPE_BOOL.
+//
+// If some one needs the macro TYPE_BOOL in a file that includes this header, it's
+// possible to bring it back using push/pop_macro as follows.
+//
+// #pragma push_macro("TYPE_BOOL")
+// #include this header and/or all headers that need the macro to be undefined.
+// #pragma pop_macro("TYPE_BOOL")
+#undef TYPE_BOOL
+
namespace google {
namespace protobuf {
@@ -155,7 +166,8 @@ class LIBPROTOBUF_EXPORT WireFormatLite {
// Compute the byte size of a tag. For groups, this includes both the start
// and end tags.
- static inline int TagSize(int field_number, WireFormatLite::FieldType type);
+ static inline size_t TagSize(int field_number,
+ WireFormatLite::FieldType type);
// Skips a field value with the given tag. The input should start
// positioned immediately after the tag. Skipped values are simply discarded,
@@ -212,7 +224,7 @@ class LIBPROTOBUF_EXPORT WireFormatLite {
WireFormatLite::WIRETYPE_LENGTH_DELIMITED);
// Byte size of all tags of a MessageSet::Item combined.
- static const int kMessageSetItemTagsSize;
+ static const size_t kMessageSetItemTagsSize;
// Helper functions for converting between floats/doubles and IEEE-754
// uint32s/uint64s so that they can be written. (Assumes your platform
@@ -242,7 +254,15 @@ class LIBPROTOBUF_EXPORT WireFormatLite {
#define input io::CodedInputStream* input_arg
#define output io::CodedOutputStream* output_arg
#define field_number int field_number_arg
+#ifdef NDEBUG
#define INL GOOGLE_ATTRIBUTE_ALWAYS_INLINE
+#else
+// Avoid excessive inlining in non-optimized builds. Without other optimizations
+// the inlining is not going to provide benefits anyway and the huge resulting
+// functions, especially in the proto-generated serialization functions, produce
+// stack frames so large that many tests run into stack overflows (b/32192897).
+#define INL
+#endif
// Read fields, not including tags. The assumption is that you already
// read the tag to determine what field to read.
@@ -370,6 +390,15 @@ class LIBPROTOBUF_EXPORT WireFormatLite {
INL static void WriteBoolNoTag (bool value, output);
INL static void WriteEnumNoTag (int value, output);
+ // Write array of primitive fields, without tags
+ static void WriteFloatArray (const float* a, int n, output);
+ static void WriteDoubleArray (const double* a, int n, output);
+ static void WriteFixed32Array (const uint32* a, int n, output);
+ static void WriteFixed64Array (const uint64* a, int n, output);
+ static void WriteSFixed32Array(const int32* a, int n, output);
+ static void WriteSFixed64Array(const int64* a, int n, output);
+ static void WriteBoolArray (const bool* a, int n, output);
+
// Write fields, including tags.
static void WriteInt32 (field_number, int32 value, output);
static void WriteInt64 (field_number, int64 value, output);
@@ -510,40 +539,48 @@ class LIBPROTOBUF_EXPORT WireFormatLite {
// the tag, so you must also call TagSize(). (This is because, for repeated
// fields, you should only call TagSize() once and multiply it by the element
// count, but you may have to call XxSize() for each individual element.)
- static inline int Int32Size ( int32 value);
- static inline int Int64Size ( int64 value);
- static inline int UInt32Size (uint32 value);
- static inline int UInt64Size (uint64 value);
- static inline int SInt32Size ( int32 value);
- static inline int SInt64Size ( int64 value);
- static inline int EnumSize ( int value);
+ static inline size_t Int32Size ( int32 value);
+ static inline size_t Int64Size ( int64 value);
+ static inline size_t UInt32Size (uint32 value);
+ static inline size_t UInt64Size (uint64 value);
+ static inline size_t SInt32Size ( int32 value);
+ static inline size_t SInt64Size ( int64 value);
+ static inline size_t EnumSize ( int value);
+
+ static size_t Int32Size (const RepeatedField< int32>& value);
+ static inline size_t Int64Size (const RepeatedField< int64>& value);
+ static size_t UInt32Size(const RepeatedField<uint32>& value);
+ static inline size_t UInt64Size(const RepeatedField<uint64>& value);
+ static size_t SInt32Size(const RepeatedField< int32>& value);
+ static inline size_t SInt64Size(const RepeatedField< int64>& value);
+ static size_t EnumSize (const RepeatedField< int>& value);
// These types always have the same size.
- static const int kFixed32Size = 4;
- static const int kFixed64Size = 8;
- static const int kSFixed32Size = 4;
- static const int kSFixed64Size = 8;
- static const int kFloatSize = 4;
- static const int kDoubleSize = 8;
- static const int kBoolSize = 1;
+ static const size_t kFixed32Size = 4;
+ static const size_t kFixed64Size = 8;
+ static const size_t kSFixed32Size = 4;
+ static const size_t kSFixed64Size = 8;
+ static const size_t kFloatSize = 4;
+ static const size_t kDoubleSize = 8;
+ static const size_t kBoolSize = 1;
- static inline int StringSize(const string& value);
- static inline int BytesSize (const string& value);
+ static inline size_t StringSize(const string& value);
+ static inline size_t BytesSize (const string& value);
- static inline int GroupSize (const MessageLite& value);
- static inline int MessageSize(const MessageLite& value);
+ static inline size_t GroupSize (const MessageLite& value);
+ static inline size_t MessageSize(const MessageLite& value);
// Like above, but de-virtualize the call to ByteSize(). The
// pointer must point at an instance of MessageType, *not* a subclass (or
// the subclass must not override ByteSize()).
template<typename MessageType>
- static inline int GroupSizeNoVirtual (const MessageType& value);
+ static inline size_t GroupSizeNoVirtual (const MessageType& value);
template<typename MessageType>
- static inline int MessageSizeNoVirtual(const MessageType& value);
+ static inline size_t MessageSizeNoVirtual(const MessageType& value);
// Given the length of data, calculate the byte size of the data on the
// wire if we encode the data as a length delimited field.
- static inline int LengthDelimitedSize(int length);
+ static inline size_t LengthDelimitedSize(size_t length);
private:
// A helper method for the repeated primitive reader. This method has
@@ -626,9 +663,9 @@ inline int WireFormatLite::GetTagFieldNumber(uint32 tag) {
return static_cast<int>(tag >> kTagTypeBits);
}
-inline int WireFormatLite::TagSize(int field_number,
- WireFormatLite::FieldType type) {
- int result = io::CodedOutputStream::VarintSize32(
+inline size_t WireFormatLite::TagSize(int field_number,
+ WireFormatLite::FieldType type) {
+ size_t result = io::CodedOutputStream::VarintSize32(
field_number << kTagTypeBits);
if (type == TYPE_GROUP) {
// Groups have both a start and an end tag.
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/wire_format_lite_inl.h b/third_party/protobuf/src/google/protobuf/wire_format_lite_inl.h
index 93d7c82403..aa3bb3a6e9 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/wire_format_lite_inl.h
+++ b/third_party/protobuf/src/google/protobuf/wire_format_lite_inl.h
@@ -251,7 +251,7 @@ inline bool WireFormatLite::ReadRepeatedFixedSizePrimitive(
uint32 tag,
io::CodedInputStream* input,
RepeatedField<CType>* values) {
- GOOGLE_DCHECK_EQ(UInt32Size(tag), tag_size);
+ GOOGLE_DCHECK_EQ(UInt32Size(tag), static_cast<size_t>(tag_size));
CType value;
if (!ReadPrimitive<CType, DeclaredType>(input, &value))
return false;
@@ -274,8 +274,9 @@ inline bool WireFormatLite::ReadRepeatedFixedSizePrimitive(
// The number of bytes each type occupies on the wire.
const int per_value_size = tag_size + sizeof(value);
+ // parentheses around (std::min) prevents macro expansion of min(...)
int elements_available =
- std::min(values->Capacity() - values->size(), size / per_value_size);
+ (std::min)(values->Capacity() - values->size(), size / per_value_size);
int num_read = 0;
while (num_read < elements_available &&
(buffer = io::CodedInputStream::ExpectTagFromArray(
@@ -366,8 +367,9 @@ inline bool WireFormatLite::ReadPackedFixedSizePrimitive(
if (bytes_limit == -1) {
bytes_limit = input->BytesUntilLimit();
} else {
+ // parentheses around (std::min) prevents macro expansion of min(...)
bytes_limit =
- std::min(bytes_limit, static_cast<int64>(input->BytesUntilLimit()));
+ (std::min)(bytes_limit, static_cast<int64>(input->BytesUntilLimit()));
}
if (bytes_limit >= new_bytes) {
// Fast-path that pre-allocates *values to the final size.
@@ -810,63 +812,91 @@ inline uint8* WireFormatLite::InternalWriteMessageNoVirtualToArray(
// ===================================================================
-inline int WireFormatLite::Int32Size(int32 value) {
+inline size_t WireFormatLite::Int32Size(int32 value) {
return io::CodedOutputStream::VarintSize32SignExtended(value);
}
-inline int WireFormatLite::Int64Size(int64 value) {
+inline size_t WireFormatLite::Int64Size(int64 value) {
return io::CodedOutputStream::VarintSize64(static_cast<uint64>(value));
}
-inline int WireFormatLite::UInt32Size(uint32 value) {
+inline size_t WireFormatLite::UInt32Size(uint32 value) {
return io::CodedOutputStream::VarintSize32(value);
}
-inline int WireFormatLite::UInt64Size(uint64 value) {
+inline size_t WireFormatLite::UInt64Size(uint64 value) {
return io::CodedOutputStream::VarintSize64(value);
}
-inline int WireFormatLite::SInt32Size(int32 value) {
+inline size_t WireFormatLite::SInt32Size(int32 value) {
return io::CodedOutputStream::VarintSize32(ZigZagEncode32(value));
}
-inline int WireFormatLite::SInt64Size(int64 value) {
+inline size_t WireFormatLite::SInt64Size(int64 value) {
return io::CodedOutputStream::VarintSize64(ZigZagEncode64(value));
}
-inline int WireFormatLite::EnumSize(int value) {
+inline size_t WireFormatLite::EnumSize(int value) {
return io::CodedOutputStream::VarintSize32SignExtended(value);
}
-inline int WireFormatLite::StringSize(const string& value) {
- return static_cast<int>(
- io::CodedOutputStream::VarintSize32(static_cast<uint32>(value.size())) +
- value.size());
+inline size_t WireFormatLite::StringSize(const string& value) {
+ return LengthDelimitedSize(value.size());
}
-inline int WireFormatLite::BytesSize(const string& value) {
- return static_cast<int>(
- io::CodedOutputStream::VarintSize32(static_cast<uint32>(value.size())) +
- value.size());
+inline size_t WireFormatLite::BytesSize(const string& value) {
+ return LengthDelimitedSize(value.size());
}
-inline int WireFormatLite::GroupSize(const MessageLite& value) {
- return value.ByteSize();
+inline size_t WireFormatLite::GroupSize(const MessageLite& value) {
+ return value.ByteSizeLong();
}
-inline int WireFormatLite::MessageSize(const MessageLite& value) {
- return LengthDelimitedSize(value.ByteSize());
+inline size_t WireFormatLite::MessageSize(const MessageLite& value) {
+ return LengthDelimitedSize(value.ByteSizeLong());
}
// See comment on ReadGroupNoVirtual to understand the need for this template
// parameter name.
template<typename MessageType_WorkAroundCppLookupDefect>
-inline int WireFormatLite::GroupSizeNoVirtual(
+inline size_t WireFormatLite::GroupSizeNoVirtual(
const MessageType_WorkAroundCppLookupDefect& value) {
- return value.MessageType_WorkAroundCppLookupDefect::ByteSize();
+ return value.MessageType_WorkAroundCppLookupDefect::ByteSizeLong();
}
template<typename MessageType_WorkAroundCppLookupDefect>
-inline int WireFormatLite::MessageSizeNoVirtual(
+inline size_t WireFormatLite::MessageSizeNoVirtual(
const MessageType_WorkAroundCppLookupDefect& value) {
return LengthDelimitedSize(
- value.MessageType_WorkAroundCppLookupDefect::ByteSize());
+ value.MessageType_WorkAroundCppLookupDefect::ByteSizeLong());
}
-inline int WireFormatLite::LengthDelimitedSize(int length) {
- return io::CodedOutputStream::VarintSize32(length) + length;
+inline size_t WireFormatLite::LengthDelimitedSize(size_t length) {
+ // The static_cast here prevents an error in certain compiler configurations
+ // but is not technically correct--if length is too large to fit in a uint32
+ // then it will be silently truncated. We will need to fix this if we ever
+ // decide to start supporting serialized messages greater than 2 GiB in size.
+ return length + io::CodedOutputStream::VarintSize32(
+ static_cast<uint32>(length));
+}
+
+size_t WireFormatLite::Int64Size (const RepeatedField< int64>& value) {
+ size_t out = 0;
+ const int n = value.size();
+ for (int i = 0; i < n; i++) {
+ out += Int64Size(value.Get(i));
+ }
+ return out;
+}
+
+size_t WireFormatLite::UInt64Size(const RepeatedField<uint64>& value) {
+ size_t out = 0;
+ const int n = value.size();
+ for (int i = 0; i < n; i++) {
+ out += UInt64Size(value.Get(i));
+ }
+ return out;
+}
+
+size_t WireFormatLite::SInt64Size(const RepeatedField< int64>& value) {
+ size_t out = 0;
+ const int n = value.size();
+ for (int i = 0; i < n; i++) {
+ out += SInt64Size(value.Get(i));
+ }
+ return out;
}
} // namespace internal
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/wire_format_unittest.cc b/third_party/protobuf/src/google/protobuf/wire_format_unittest.cc
index 4e4add66f3..897fec00c7 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/wire_format_unittest.cc
+++ b/third_party/protobuf/src/google/protobuf/wire_format_unittest.cc
@@ -1138,7 +1138,7 @@ class Utf8ValidationTest : public ::testing::Test {
TEST_F(Utf8ValidationTest, WriteInvalidUTF8String) {
string wire_buffer;
protobuf_unittest::OneString input;
- vector<string> errors;
+ std::vector<string> errors;
{
ScopedMemoryLog log;
WriteMessage(kInvalidUTF8String, &input, &wire_buffer);
@@ -1162,7 +1162,7 @@ TEST_F(Utf8ValidationTest, ReadInvalidUTF8String) {
protobuf_unittest::OneString input;
WriteMessage(kInvalidUTF8String, &input, &wire_buffer);
protobuf_unittest::OneString output;
- vector<string> errors;
+ std::vector<string> errors;
{
ScopedMemoryLog log;
ReadMessage(wire_buffer, &output);
@@ -1185,7 +1185,7 @@ TEST_F(Utf8ValidationTest, ReadInvalidUTF8String) {
TEST_F(Utf8ValidationTest, WriteValidUTF8String) {
string wire_buffer;
protobuf_unittest::OneString input;
- vector<string> errors;
+ std::vector<string> errors;
{
ScopedMemoryLog log;
WriteMessage(kValidUTF8String, &input, &wire_buffer);
@@ -1199,7 +1199,7 @@ TEST_F(Utf8ValidationTest, ReadValidUTF8String) {
protobuf_unittest::OneString input;
WriteMessage(kValidUTF8String, &input, &wire_buffer);
protobuf_unittest::OneString output;
- vector<string> errors;
+ std::vector<string> errors;
{
ScopedMemoryLog log;
ReadMessage(wire_buffer, &output);
@@ -1213,7 +1213,7 @@ TEST_F(Utf8ValidationTest, ReadValidUTF8String) {
TEST_F(Utf8ValidationTest, WriteArbitraryBytes) {
string wire_buffer;
protobuf_unittest::OneBytes input;
- vector<string> errors;
+ std::vector<string> errors;
{
ScopedMemoryLog log;
WriteMessage(kInvalidUTF8String, &input, &wire_buffer);
@@ -1227,7 +1227,7 @@ TEST_F(Utf8ValidationTest, ReadArbitraryBytes) {
protobuf_unittest::OneBytes input;
WriteMessage(kInvalidUTF8String, &input, &wire_buffer);
protobuf_unittest::OneBytes output;
- vector<string> errors;
+ std::vector<string> errors;
{
ScopedMemoryLog log;
ReadMessage(wire_buffer, &output);
@@ -1245,7 +1245,7 @@ TEST_F(Utf8ValidationTest, ParseRepeatedString) {
string wire_buffer = input.SerializeAsString();
protobuf_unittest::MoreString output;
- vector<string> errors;
+ std::vector<string> errors;
{
ScopedMemoryLog log;
ReadMessage(wire_buffer, &output);
@@ -1264,7 +1264,7 @@ TEST_F(Utf8ValidationTest, ParseRepeatedString) {
TEST_F(Utf8ValidationTest, OldVerifyUTF8String) {
string data(kInvalidUTF8String);
- vector<string> errors;
+ std::vector<string> errors;
{
ScopedMemoryLog log;
WireFormat::VerifyUTF8String(data.data(), data.size(),
@@ -1283,6 +1283,136 @@ TEST_F(Utf8ValidationTest, OldVerifyUTF8String) {
}
+TEST(RepeatedVarint, Int32) {
+ RepeatedField<int32> v;
+
+ // Insert -2^n, 2^n and 2^n-1.
+ for (int n = 0; n < 10; n++) {
+ v.Add(-(1 << n));
+ v.Add(1 << n);
+ v.Add((1 << n) - 1);
+ }
+
+ // Check consistency with the scalar Int32Size.
+ size_t expected = 0;
+ for (int i = 0; i < v.size(); i++) {
+ expected += WireFormatLite::Int32Size(v[i]);
+ }
+
+ EXPECT_EQ(expected, WireFormatLite::Int32Size(v));
+}
+
+TEST(RepeatedVarint, Int64) {
+ RepeatedField<int64> v;
+
+ // Insert -2^n, 2^n and 2^n-1.
+ for (int n = 0; n < 10; n++) {
+ v.Add(-(1 << n));
+ v.Add(1 << n);
+ v.Add((1 << n) - 1);
+ }
+
+ // Check consistency with the scalar Int64Size.
+ size_t expected = 0;
+ for (int i = 0; i < v.size(); i++) {
+ expected += WireFormatLite::Int64Size(v[i]);
+ }
+
+ EXPECT_EQ(expected, WireFormatLite::Int64Size(v));
+}
+
+TEST(RepeatedVarint, SInt32) {
+ RepeatedField<int32> v;
+
+ // Insert -2^n, 2^n and 2^n-1.
+ for (int n = 0; n < 10; n++) {
+ v.Add(-(1 << n));
+ v.Add(1 << n);
+ v.Add((1 << n) - 1);
+ }
+
+ // Check consistency with the scalar SInt32Size.
+ size_t expected = 0;
+ for (int i = 0; i < v.size(); i++) {
+ expected += WireFormatLite::SInt32Size(v[i]);
+ }
+
+ EXPECT_EQ(expected, WireFormatLite::SInt32Size(v));
+}
+
+TEST(RepeatedVarint, SInt64) {
+ RepeatedField<int64> v;
+
+ // Insert -2^n, 2^n and 2^n-1.
+ for (int n = 0; n < 10; n++) {
+ v.Add(-(1 << n));
+ v.Add(1 << n);
+ v.Add((1 << n) - 1);
+ }
+
+ // Check consistency with the scalar SInt64Size.
+ size_t expected = 0;
+ for (int i = 0; i < v.size(); i++) {
+ expected += WireFormatLite::SInt64Size(v[i]);
+ }
+
+ EXPECT_EQ(expected, WireFormatLite::SInt64Size(v));
+}
+
+TEST(RepeatedVarint, UInt32) {
+ RepeatedField<uint32> v;
+
+ // Insert 2^n and 2^n-1.
+ for (int n = 0; n < 10; n++) {
+ v.Add(1 << n);
+ v.Add((1 << n) - 1);
+ }
+
+ // Check consistency with the scalar UInt32Size.
+ size_t expected = 0;
+ for (int i = 0; i < v.size(); i++) {
+ expected += WireFormatLite::UInt32Size(v[i]);
+ }
+
+ EXPECT_EQ(expected, WireFormatLite::UInt32Size(v));
+}
+
+TEST(RepeatedVarint, UInt64) {
+ RepeatedField<uint64> v;
+
+ // Insert 2^n and 2^n-1.
+ for (int n = 0; n < 10; n++) {
+ v.Add(1 << n);
+ v.Add((1 << n) - 1);
+ }
+
+ // Check consistency with the scalar UInt64Size.
+ size_t expected = 0;
+ for (int i = 0; i < v.size(); i++) {
+ expected += WireFormatLite::UInt64Size(v[i]);
+ }
+
+ EXPECT_EQ(expected, WireFormatLite::UInt64Size(v));
+}
+
+TEST(RepeatedVarint, Enum) {
+ RepeatedField<int> v;
+
+ // Insert 2^n and 2^n-1.
+ for (int n = 0; n < 10; n++) {
+ v.Add(1 << n);
+ v.Add((1 << n) - 1);
+ }
+
+ // Check consistency with the scalar EnumSize.
+ size_t expected = 0;
+ for (int i = 0; i < v.size(); i++) {
+ expected += WireFormatLite::EnumSize(v[i]);
+ }
+
+ EXPECT_EQ(expected, WireFormatLite::EnumSize(v));
+}
+
} // namespace
} // namespace internal
} // namespace protobuf
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/wrappers.pb.cc b/third_party/protobuf/src/google/protobuf/wrappers.pb.cc
index 33a69d3b18..d614de9dc9 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/wrappers.pb.cc
+++ b/third_party/protobuf/src/google/protobuf/wrappers.pb.cc
@@ -19,287 +19,205 @@
namespace google {
namespace protobuf {
+class DoubleValueDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<DoubleValue> {
+} _DoubleValue_default_instance_;
+class FloatValueDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<FloatValue> {
+} _FloatValue_default_instance_;
+class Int64ValueDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Int64Value> {
+} _Int64Value_default_instance_;
+class UInt64ValueDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<UInt64Value> {
+} _UInt64Value_default_instance_;
+class Int32ValueDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<Int32Value> {
+} _Int32Value_default_instance_;
+class UInt32ValueDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<UInt32Value> {
+} _UInt32Value_default_instance_;
+class BoolValueDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<BoolValue> {
+} _BoolValue_default_instance_;
+class StringValueDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<StringValue> {
+} _StringValue_default_instance_;
+class BytesValueDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<BytesValue> {
+} _BytesValue_default_instance_;
+
+namespace protobuf_google_2fprotobuf_2fwrappers_2eproto {
+
namespace {
-const ::google::protobuf::Descriptor* DoubleValue_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- DoubleValue_reflection_ = NULL;
-const ::google::protobuf::Descriptor* FloatValue_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- FloatValue_reflection_ = NULL;
-const ::google::protobuf::Descriptor* Int64Value_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- Int64Value_reflection_ = NULL;
-const ::google::protobuf::Descriptor* UInt64Value_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- UInt64Value_reflection_ = NULL;
-const ::google::protobuf::Descriptor* Int32Value_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- Int32Value_reflection_ = NULL;
-const ::google::protobuf::Descriptor* UInt32Value_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- UInt32Value_reflection_ = NULL;
-const ::google::protobuf::Descriptor* BoolValue_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- BoolValue_reflection_ = NULL;
-const ::google::protobuf::Descriptor* StringValue_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- StringValue_reflection_ = NULL;
-const ::google::protobuf::Descriptor* BytesValue_descriptor_ = NULL;
-const ::google::protobuf::internal::GeneratedMessageReflection*
- BytesValue_reflection_ = NULL;
+::google::protobuf::Metadata file_level_metadata[9];
} // namespace
-
-void protobuf_AssignDesc_google_2fprotobuf_2fwrappers_2eproto() GOOGLE_ATTRIBUTE_COLD;
-void protobuf_AssignDesc_google_2fprotobuf_2fwrappers_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- const ::google::protobuf::FileDescriptor* file =
- ::google::protobuf::DescriptorPool::generated_pool()->FindFileByName(
- "google/protobuf/wrappers.proto");
- GOOGLE_CHECK(file != NULL);
- DoubleValue_descriptor_ = file->message_type(0);
- static const int DoubleValue_offsets_[1] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DoubleValue, value_),
- };
- DoubleValue_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- DoubleValue_descriptor_,
- DoubleValue::default_instance_,
- DoubleValue_offsets_,
- -1,
- -1,
- -1,
- sizeof(DoubleValue),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DoubleValue, _internal_metadata_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DoubleValue, _is_default_instance_));
- FloatValue_descriptor_ = file->message_type(1);
- static const int FloatValue_offsets_[1] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FloatValue, value_),
- };
- FloatValue_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- FloatValue_descriptor_,
- FloatValue::default_instance_,
- FloatValue_offsets_,
- -1,
- -1,
- -1,
- sizeof(FloatValue),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FloatValue, _internal_metadata_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FloatValue, _is_default_instance_));
- Int64Value_descriptor_ = file->message_type(2);
- static const int Int64Value_offsets_[1] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Int64Value, value_),
- };
- Int64Value_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- Int64Value_descriptor_,
- Int64Value::default_instance_,
- Int64Value_offsets_,
- -1,
- -1,
- -1,
- sizeof(Int64Value),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Int64Value, _internal_metadata_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Int64Value, _is_default_instance_));
- UInt64Value_descriptor_ = file->message_type(3);
- static const int UInt64Value_offsets_[1] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UInt64Value, value_),
- };
- UInt64Value_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- UInt64Value_descriptor_,
- UInt64Value::default_instance_,
- UInt64Value_offsets_,
- -1,
- -1,
- -1,
- sizeof(UInt64Value),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UInt64Value, _internal_metadata_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UInt64Value, _is_default_instance_));
- Int32Value_descriptor_ = file->message_type(4);
- static const int Int32Value_offsets_[1] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Int32Value, value_),
- };
- Int32Value_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- Int32Value_descriptor_,
- Int32Value::default_instance_,
- Int32Value_offsets_,
- -1,
- -1,
- -1,
- sizeof(Int32Value),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Int32Value, _internal_metadata_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Int32Value, _is_default_instance_));
- UInt32Value_descriptor_ = file->message_type(5);
- static const int UInt32Value_offsets_[1] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UInt32Value, value_),
- };
- UInt32Value_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- UInt32Value_descriptor_,
- UInt32Value::default_instance_,
- UInt32Value_offsets_,
- -1,
- -1,
- -1,
- sizeof(UInt32Value),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UInt32Value, _internal_metadata_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UInt32Value, _is_default_instance_));
- BoolValue_descriptor_ = file->message_type(6);
- static const int BoolValue_offsets_[1] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BoolValue, value_),
- };
- BoolValue_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- BoolValue_descriptor_,
- BoolValue::default_instance_,
- BoolValue_offsets_,
- -1,
- -1,
- -1,
- sizeof(BoolValue),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BoolValue, _internal_metadata_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BoolValue, _is_default_instance_));
- StringValue_descriptor_ = file->message_type(7);
- static const int StringValue_offsets_[1] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(StringValue, value_),
- };
- StringValue_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- StringValue_descriptor_,
- StringValue::default_instance_,
- StringValue_offsets_,
- -1,
- -1,
- -1,
- sizeof(StringValue),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(StringValue, _internal_metadata_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(StringValue, _is_default_instance_));
- BytesValue_descriptor_ = file->message_type(8);
- static const int BytesValue_offsets_[1] = {
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BytesValue, value_),
- };
- BytesValue_reflection_ =
- ::google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(
- BytesValue_descriptor_,
- BytesValue::default_instance_,
- BytesValue_offsets_,
- -1,
- -1,
- -1,
- sizeof(BytesValue),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BytesValue, _internal_metadata_),
- GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BytesValue, _is_default_instance_));
-}
+const ::google::protobuf::uint32 TableStruct::offsets[] = {
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DoubleValue, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DoubleValue, value_),
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FloatValue, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FloatValue, value_),
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Int64Value, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Int64Value, value_),
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UInt64Value, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UInt64Value, value_),
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Int32Value, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Int32Value, value_),
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UInt32Value, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(UInt32Value, value_),
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BoolValue, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BoolValue, value_),
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(StringValue, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(StringValue, value_),
+ ~0u, // no _has_bits_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BytesValue, _internal_metadata_),
+ ~0u, // no _extensions_
+ ~0u, // no _oneof_case_
+ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BytesValue, value_),
+};
+
+static const ::google::protobuf::internal::MigrationSchema schemas[] = {
+ { 0, -1, sizeof(DoubleValue)},
+ { 5, -1, sizeof(FloatValue)},
+ { 10, -1, sizeof(Int64Value)},
+ { 15, -1, sizeof(UInt64Value)},
+ { 20, -1, sizeof(Int32Value)},
+ { 25, -1, sizeof(UInt32Value)},
+ { 30, -1, sizeof(BoolValue)},
+ { 35, -1, sizeof(StringValue)},
+ { 40, -1, sizeof(BytesValue)},
+};
+
+static ::google::protobuf::Message const * const file_default_instances[] = {
+ reinterpret_cast<const ::google::protobuf::Message*>(&_DoubleValue_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_FloatValue_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_Int64Value_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_UInt64Value_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_Int32Value_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_UInt32Value_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_BoolValue_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_StringValue_default_instance_),
+ reinterpret_cast<const ::google::protobuf::Message*>(&_BytesValue_default_instance_),
+};
namespace {
-GOOGLE_PROTOBUF_DECLARE_ONCE(protobuf_AssignDescriptors_once_);
-inline void protobuf_AssignDescriptorsOnce() {
- ::google::protobuf::GoogleOnceInit(&protobuf_AssignDescriptors_once_,
- &protobuf_AssignDesc_google_2fprotobuf_2fwrappers_2eproto);
+void protobuf_AssignDescriptors() {
+ AddDescriptors();
+ ::google::protobuf::MessageFactory* factory = NULL;
+ AssignDescriptors(
+ "google/protobuf/wrappers.proto", schemas, file_default_instances, TableStruct::offsets, factory,
+ file_level_metadata, NULL, NULL);
+}
+
+void protobuf_AssignDescriptorsOnce() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
}
void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD;
void protobuf_RegisterTypes(const ::std::string&) {
protobuf_AssignDescriptorsOnce();
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- DoubleValue_descriptor_, &DoubleValue::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- FloatValue_descriptor_, &FloatValue::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- Int64Value_descriptor_, &Int64Value::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- UInt64Value_descriptor_, &UInt64Value::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- Int32Value_descriptor_, &Int32Value::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- UInt32Value_descriptor_, &UInt32Value::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- BoolValue_descriptor_, &BoolValue::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- StringValue_descriptor_, &StringValue::default_instance());
- ::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
- BytesValue_descriptor_, &BytesValue::default_instance());
+ ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 9);
}
} // namespace
-void protobuf_ShutdownFile_google_2fprotobuf_2fwrappers_2eproto() {
- delete DoubleValue::default_instance_;
- delete DoubleValue_reflection_;
- delete FloatValue::default_instance_;
- delete FloatValue_reflection_;
- delete Int64Value::default_instance_;
- delete Int64Value_reflection_;
- delete UInt64Value::default_instance_;
- delete UInt64Value_reflection_;
- delete Int32Value::default_instance_;
- delete Int32Value_reflection_;
- delete UInt32Value::default_instance_;
- delete UInt32Value_reflection_;
- delete BoolValue::default_instance_;
- delete BoolValue_reflection_;
- delete StringValue::default_instance_;
- delete StringValue_reflection_;
- delete BytesValue::default_instance_;
- delete BytesValue_reflection_;
-}
-
-void protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto() GOOGLE_ATTRIBUTE_COLD;
-void protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto() {
- static bool already_here = false;
- if (already_here) return;
- already_here = true;
+void TableStruct::Shutdown() {
+ _DoubleValue_default_instance_.Shutdown();
+ delete file_level_metadata[0].reflection;
+ _FloatValue_default_instance_.Shutdown();
+ delete file_level_metadata[1].reflection;
+ _Int64Value_default_instance_.Shutdown();
+ delete file_level_metadata[2].reflection;
+ _UInt64Value_default_instance_.Shutdown();
+ delete file_level_metadata[3].reflection;
+ _Int32Value_default_instance_.Shutdown();
+ delete file_level_metadata[4].reflection;
+ _UInt32Value_default_instance_.Shutdown();
+ delete file_level_metadata[5].reflection;
+ _BoolValue_default_instance_.Shutdown();
+ delete file_level_metadata[6].reflection;
+ _StringValue_default_instance_.Shutdown();
+ delete file_level_metadata[7].reflection;
+ _BytesValue_default_instance_.Shutdown();
+ delete file_level_metadata[8].reflection;
+}
+
+void TableStruct::InitDefaultsImpl() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
+ ::google::protobuf::internal::InitProtobufDefaults();
+ _DoubleValue_default_instance_.DefaultConstruct();
+ _FloatValue_default_instance_.DefaultConstruct();
+ _Int64Value_default_instance_.DefaultConstruct();
+ _UInt64Value_default_instance_.DefaultConstruct();
+ _Int32Value_default_instance_.DefaultConstruct();
+ _UInt32Value_default_instance_.DefaultConstruct();
+ _BoolValue_default_instance_.DefaultConstruct();
+ _StringValue_default_instance_.DefaultConstruct();
+ _BytesValue_default_instance_.DefaultConstruct();
+}
+
+void InitDefaults() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &TableStruct::InitDefaultsImpl);
+}
+void AddDescriptorsImpl() {
+ InitDefaults();
+ static const char descriptor[] = {
+ "\n\036google/protobuf/wrappers.proto\022\017google"
+ ".protobuf\"\034\n\013DoubleValue\022\r\n\005value\030\001 \001(\001\""
+ "\033\n\nFloatValue\022\r\n\005value\030\001 \001(\002\"\033\n\nInt64Val"
+ "ue\022\r\n\005value\030\001 \001(\003\"\034\n\013UInt64Value\022\r\n\005valu"
+ "e\030\001 \001(\004\"\033\n\nInt32Value\022\r\n\005value\030\001 \001(\005\"\034\n\013"
+ "UInt32Value\022\r\n\005value\030\001 \001(\r\"\032\n\tBoolValue\022"
+ "\r\n\005value\030\001 \001(\010\"\034\n\013StringValue\022\r\n\005value\030\001"
+ " \001(\t\"\033\n\nBytesValue\022\r\n\005value\030\001 \001(\014B|\n\023com"
+ ".google.protobufB\rWrappersProtoP\001Z*githu"
+ "b.com/golang/protobuf/ptypes/wrappers\370\001\001"
+ "\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTypesb"
+ "\006proto3"
+ };
::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
- "\n\036google/protobuf/wrappers.proto\022\017google"
- ".protobuf\"\034\n\013DoubleValue\022\r\n\005value\030\001 \001(\001\""
- "\033\n\nFloatValue\022\r\n\005value\030\001 \001(\002\"\033\n\nInt64Val"
- "ue\022\r\n\005value\030\001 \001(\003\"\034\n\013UInt64Value\022\r\n\005valu"
- "e\030\001 \001(\004\"\033\n\nInt32Value\022\r\n\005value\030\001 \001(\005\"\034\n\013"
- "UInt32Value\022\r\n\005value\030\001 \001(\r\"\032\n\tBoolValue\022"
- "\r\n\005value\030\001 \001(\010\"\034\n\013StringValue\022\r\n\005value\030\001"
- " \001(\t\"\033\n\nBytesValue\022\r\n\005value\030\001 \001(\014B\177\n\023com"
- ".google.protobufB\rWrappersProtoP\001Z*githu"
- "b.com/golang/protobuf/ptypes/wrappers\240\001\001"
- "\370\001\001\242\002\003GPB\252\002\036Google.Protobuf.WellKnownTyp"
- "esb\006proto3", 450);
+ descriptor, 447);
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
"google/protobuf/wrappers.proto", &protobuf_RegisterTypes);
- DoubleValue::default_instance_ = new DoubleValue();
- FloatValue::default_instance_ = new FloatValue();
- Int64Value::default_instance_ = new Int64Value();
- UInt64Value::default_instance_ = new UInt64Value();
- Int32Value::default_instance_ = new Int32Value();
- UInt32Value::default_instance_ = new UInt32Value();
- BoolValue::default_instance_ = new BoolValue();
- StringValue::default_instance_ = new StringValue();
- BytesValue::default_instance_ = new BytesValue();
- DoubleValue::default_instance_->InitAsDefaultInstance();
- FloatValue::default_instance_->InitAsDefaultInstance();
- Int64Value::default_instance_->InitAsDefaultInstance();
- UInt64Value::default_instance_->InitAsDefaultInstance();
- Int32Value::default_instance_->InitAsDefaultInstance();
- UInt32Value::default_instance_->InitAsDefaultInstance();
- BoolValue::default_instance_->InitAsDefaultInstance();
- StringValue::default_instance_->InitAsDefaultInstance();
- BytesValue::default_instance_->InitAsDefaultInstance();
- ::google::protobuf::internal::OnShutdown(&protobuf_ShutdownFile_google_2fprotobuf_2fwrappers_2eproto);
+ ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown);
}
+void AddDescriptors() {
+ static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+ ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
+}
// Force AddDescriptors() to be called at static initialization time.
-struct StaticDescriptorInitializer_google_2fprotobuf_2fwrappers_2eproto {
- StaticDescriptorInitializer_google_2fprotobuf_2fwrappers_2eproto() {
- protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
+struct StaticDescriptorInitializer {
+ StaticDescriptorInitializer() {
+ AddDescriptors();
}
-} static_descriptor_initializer_google_2fprotobuf_2fwrappers_2eproto_;
+} static_descriptor_initializer;
+
+} // namespace protobuf_google_2fprotobuf_2fwrappers_2eproto
+
// ===================================================================
@@ -309,34 +227,34 @@ const int DoubleValue::kValueFieldNumber;
DoubleValue::DoubleValue()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.DoubleValue)
}
-
DoubleValue::DoubleValue(::google::protobuf::Arena* arena)
: ::google::protobuf::Message(),
_internal_metadata_(arena) {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
SharedCtor();
RegisterArenaDtor(arena);
// @@protoc_insertion_point(arena_constructor:google.protobuf.DoubleValue)
}
-
-void DoubleValue::InitAsDefaultInstance() {
- _is_default_instance_ = true;
-}
-
DoubleValue::DoubleValue(const DoubleValue& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ value_ = from.value_;
// @@protoc_insertion_point(copy_constructor:google.protobuf.DoubleValue)
}
void DoubleValue::SharedCtor() {
- _is_default_instance_ = false;
- _cached_size_ = 0;
value_ = 0;
+ _cached_size_ = 0;
}
DoubleValue::~DoubleValue() {
@@ -345,12 +263,11 @@ DoubleValue::~DoubleValue() {
}
void DoubleValue::SharedDtor() {
- if (GetArenaNoVirtual() != NULL) {
+ ::google::protobuf::Arena* arena = GetArenaNoVirtual();
+ if (arena != NULL) {
return;
}
- if (this != default_instance_) {
- }
}
void DoubleValue::ArenaDtor(void* object) {
@@ -365,17 +282,15 @@ void DoubleValue::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* DoubleValue::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return DoubleValue_descriptor_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[0].descriptor;
}
const DoubleValue& DoubleValue::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-DoubleValue* DoubleValue::default_instance_ = NULL;
-
DoubleValue* DoubleValue::New(::google::protobuf::Arena* arena) const {
return ::google::protobuf::Arena::CreateMessage<DoubleValue>(arena);
}
@@ -391,21 +306,21 @@ bool DoubleValue::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.DoubleValue)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional double value = 1;
+ // double value = 1;
case 1: {
- if (tag == 9) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(9u)) {
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
double, ::google::protobuf::internal::WireFormatLite::TYPE_DOUBLE>(
input, &value_)));
-
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -433,7 +348,7 @@ failure:
void DoubleValue::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.DoubleValue)
- // optional double value = 1;
+ // double value = 1;
if (this->value() != 0) {
::google::protobuf::internal::WireFormatLite::WriteDouble(1, this->value(), output);
}
@@ -443,8 +358,9 @@ void DoubleValue::SerializeWithCachedSizes(
::google::protobuf::uint8* DoubleValue::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.DoubleValue)
- // optional double value = 1;
+ // double value = 1;
if (this->value() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteDoubleToArray(1, this->value(), target);
}
@@ -453,27 +369,26 @@ void DoubleValue::SerializeWithCachedSizes(
return target;
}
-int DoubleValue::ByteSize() const {
+size_t DoubleValue::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.DoubleValue)
- int total_size = 0;
+ size_t total_size = 0;
- // optional double value = 1;
+ // double value = 1;
if (this->value() != 0) {
total_size += 1 + 8;
}
+ 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 DoubleValue::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.DoubleValue)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
- const DoubleValue* source =
+ GOOGLE_DCHECK_NE(&from, this);
+ const DoubleValue* source =
::google::protobuf::internal::DynamicCastToGenerated<const DoubleValue>(
&from);
if (source == NULL) {
@@ -487,9 +402,8 @@ void DoubleValue::MergeFrom(const ::google::protobuf::Message& from) {
void DoubleValue::MergeFrom(const DoubleValue& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.DoubleValue)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
if (from.value() != 0) {
set_value(from.value());
}
@@ -510,7 +424,6 @@ void DoubleValue::CopyFrom(const DoubleValue& from) {
}
bool DoubleValue::IsInitialized() const {
-
return true;
}
@@ -519,10 +432,13 @@ void DoubleValue::Swap(DoubleValue* other) {
if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
InternalSwap(other);
} else {
- DoubleValue temp;
- temp.MergeFrom(*this);
- CopyFrom(*other);
- other->CopyFrom(temp);
+ DoubleValue* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
}
}
void DoubleValue::UnsafeArenaSwap(DoubleValue* other) {
@@ -532,30 +448,26 @@ void DoubleValue::UnsafeArenaSwap(DoubleValue* other) {
}
void DoubleValue::InternalSwap(DoubleValue* other) {
std::swap(value_, other->value_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata DoubleValue::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = DoubleValue_descriptor_;
- metadata.reflection = DoubleValue_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[0];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// DoubleValue
-// optional double value = 1;
+// double value = 1;
void DoubleValue::clear_value() {
value_ = 0;
}
- double DoubleValue::value() const {
+double DoubleValue::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.DoubleValue.value)
return value_;
}
- void DoubleValue::set_value(double value) {
+void DoubleValue::set_value(double value) {
value_ = value;
// @@protoc_insertion_point(field_set:google.protobuf.DoubleValue.value)
@@ -571,34 +483,34 @@ const int FloatValue::kValueFieldNumber;
FloatValue::FloatValue()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.FloatValue)
}
-
FloatValue::FloatValue(::google::protobuf::Arena* arena)
: ::google::protobuf::Message(),
_internal_metadata_(arena) {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
SharedCtor();
RegisterArenaDtor(arena);
// @@protoc_insertion_point(arena_constructor:google.protobuf.FloatValue)
}
-
-void FloatValue::InitAsDefaultInstance() {
- _is_default_instance_ = true;
-}
-
FloatValue::FloatValue(const FloatValue& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ value_ = from.value_;
// @@protoc_insertion_point(copy_constructor:google.protobuf.FloatValue)
}
void FloatValue::SharedCtor() {
- _is_default_instance_ = false;
- _cached_size_ = 0;
value_ = 0;
+ _cached_size_ = 0;
}
FloatValue::~FloatValue() {
@@ -607,12 +519,11 @@ FloatValue::~FloatValue() {
}
void FloatValue::SharedDtor() {
- if (GetArenaNoVirtual() != NULL) {
+ ::google::protobuf::Arena* arena = GetArenaNoVirtual();
+ if (arena != NULL) {
return;
}
- if (this != default_instance_) {
- }
}
void FloatValue::ArenaDtor(void* object) {
@@ -627,17 +538,15 @@ void FloatValue::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* FloatValue::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return FloatValue_descriptor_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[1].descriptor;
}
const FloatValue& FloatValue::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-FloatValue* FloatValue::default_instance_ = NULL;
-
FloatValue* FloatValue::New(::google::protobuf::Arena* arena) const {
return ::google::protobuf::Arena::CreateMessage<FloatValue>(arena);
}
@@ -653,21 +562,21 @@ bool FloatValue::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.FloatValue)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional float value = 1;
+ // float value = 1;
case 1: {
- if (tag == 13) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(13u)) {
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
float, ::google::protobuf::internal::WireFormatLite::TYPE_FLOAT>(
input, &value_)));
-
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -695,7 +604,7 @@ failure:
void FloatValue::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.FloatValue)
- // optional float value = 1;
+ // float value = 1;
if (this->value() != 0) {
::google::protobuf::internal::WireFormatLite::WriteFloat(1, this->value(), output);
}
@@ -705,8 +614,9 @@ void FloatValue::SerializeWithCachedSizes(
::google::protobuf::uint8* FloatValue::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.FloatValue)
- // optional float value = 1;
+ // float value = 1;
if (this->value() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteFloatToArray(1, this->value(), target);
}
@@ -715,27 +625,26 @@ void FloatValue::SerializeWithCachedSizes(
return target;
}
-int FloatValue::ByteSize() const {
+size_t FloatValue::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.FloatValue)
- int total_size = 0;
+ size_t total_size = 0;
- // optional float value = 1;
+ // float value = 1;
if (this->value() != 0) {
total_size += 1 + 4;
}
+ 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 FloatValue::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.FloatValue)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
- const FloatValue* source =
+ GOOGLE_DCHECK_NE(&from, this);
+ const FloatValue* source =
::google::protobuf::internal::DynamicCastToGenerated<const FloatValue>(
&from);
if (source == NULL) {
@@ -749,9 +658,8 @@ void FloatValue::MergeFrom(const ::google::protobuf::Message& from) {
void FloatValue::MergeFrom(const FloatValue& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.FloatValue)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
if (from.value() != 0) {
set_value(from.value());
}
@@ -772,7 +680,6 @@ void FloatValue::CopyFrom(const FloatValue& from) {
}
bool FloatValue::IsInitialized() const {
-
return true;
}
@@ -781,10 +688,13 @@ void FloatValue::Swap(FloatValue* other) {
if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
InternalSwap(other);
} else {
- FloatValue temp;
- temp.MergeFrom(*this);
- CopyFrom(*other);
- other->CopyFrom(temp);
+ FloatValue* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
}
}
void FloatValue::UnsafeArenaSwap(FloatValue* other) {
@@ -794,30 +704,26 @@ void FloatValue::UnsafeArenaSwap(FloatValue* other) {
}
void FloatValue::InternalSwap(FloatValue* other) {
std::swap(value_, other->value_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata FloatValue::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = FloatValue_descriptor_;
- metadata.reflection = FloatValue_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[1];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// FloatValue
-// optional float value = 1;
+// float value = 1;
void FloatValue::clear_value() {
value_ = 0;
}
- float FloatValue::value() const {
+float FloatValue::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.FloatValue.value)
return value_;
}
- void FloatValue::set_value(float value) {
+void FloatValue::set_value(float value) {
value_ = value;
// @@protoc_insertion_point(field_set:google.protobuf.FloatValue.value)
@@ -833,34 +739,34 @@ const int Int64Value::kValueFieldNumber;
Int64Value::Int64Value()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.Int64Value)
}
-
Int64Value::Int64Value(::google::protobuf::Arena* arena)
: ::google::protobuf::Message(),
_internal_metadata_(arena) {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
SharedCtor();
RegisterArenaDtor(arena);
// @@protoc_insertion_point(arena_constructor:google.protobuf.Int64Value)
}
-
-void Int64Value::InitAsDefaultInstance() {
- _is_default_instance_ = true;
-}
-
Int64Value::Int64Value(const Int64Value& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ value_ = from.value_;
// @@protoc_insertion_point(copy_constructor:google.protobuf.Int64Value)
}
void Int64Value::SharedCtor() {
- _is_default_instance_ = false;
- _cached_size_ = 0;
value_ = GOOGLE_LONGLONG(0);
+ _cached_size_ = 0;
}
Int64Value::~Int64Value() {
@@ -869,12 +775,11 @@ Int64Value::~Int64Value() {
}
void Int64Value::SharedDtor() {
- if (GetArenaNoVirtual() != NULL) {
+ ::google::protobuf::Arena* arena = GetArenaNoVirtual();
+ if (arena != NULL) {
return;
}
- if (this != default_instance_) {
- }
}
void Int64Value::ArenaDtor(void* object) {
@@ -889,17 +794,15 @@ void Int64Value::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Int64Value::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Int64Value_descriptor_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[2].descriptor;
}
const Int64Value& Int64Value::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-Int64Value* Int64Value::default_instance_ = NULL;
-
Int64Value* Int64Value::New(::google::protobuf::Arena* arena) const {
return ::google::protobuf::Arena::CreateMessage<Int64Value>(arena);
}
@@ -915,21 +818,21 @@ bool Int64Value::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Int64Value)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional int64 value = 1;
+ // int64 value = 1;
case 1: {
- if (tag == 8) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(8u)) {
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int64, ::google::protobuf::internal::WireFormatLite::TYPE_INT64>(
input, &value_)));
-
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -957,7 +860,7 @@ failure:
void Int64Value::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.Int64Value)
- // optional int64 value = 1;
+ // int64 value = 1;
if (this->value() != 0) {
::google::protobuf::internal::WireFormatLite::WriteInt64(1, this->value(), output);
}
@@ -967,8 +870,9 @@ void Int64Value::SerializeWithCachedSizes(
::google::protobuf::uint8* Int64Value::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Int64Value)
- // optional int64 value = 1;
+ // int64 value = 1;
if (this->value() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteInt64ToArray(1, this->value(), target);
}
@@ -977,29 +881,28 @@ void Int64Value::SerializeWithCachedSizes(
return target;
}
-int Int64Value::ByteSize() const {
+size_t Int64Value::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Int64Value)
- int total_size = 0;
+ size_t total_size = 0;
- // optional int64 value = 1;
+ // int64 value = 1;
if (this->value() != 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::Int64Size(
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 Int64Value::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Int64Value)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
- const Int64Value* source =
+ GOOGLE_DCHECK_NE(&from, this);
+ const Int64Value* source =
::google::protobuf::internal::DynamicCastToGenerated<const Int64Value>(
&from);
if (source == NULL) {
@@ -1013,9 +916,8 @@ void Int64Value::MergeFrom(const ::google::protobuf::Message& from) {
void Int64Value::MergeFrom(const Int64Value& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Int64Value)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
if (from.value() != 0) {
set_value(from.value());
}
@@ -1036,7 +938,6 @@ void Int64Value::CopyFrom(const Int64Value& from) {
}
bool Int64Value::IsInitialized() const {
-
return true;
}
@@ -1045,10 +946,13 @@ void Int64Value::Swap(Int64Value* other) {
if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
InternalSwap(other);
} else {
- Int64Value temp;
- temp.MergeFrom(*this);
- CopyFrom(*other);
- other->CopyFrom(temp);
+ Int64Value* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
}
}
void Int64Value::UnsafeArenaSwap(Int64Value* other) {
@@ -1058,30 +962,26 @@ void Int64Value::UnsafeArenaSwap(Int64Value* other) {
}
void Int64Value::InternalSwap(Int64Value* other) {
std::swap(value_, other->value_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Int64Value::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = Int64Value_descriptor_;
- metadata.reflection = Int64Value_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[2];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// Int64Value
-// optional int64 value = 1;
+// int64 value = 1;
void Int64Value::clear_value() {
value_ = GOOGLE_LONGLONG(0);
}
- ::google::protobuf::int64 Int64Value::value() const {
+::google::protobuf::int64 Int64Value::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.Int64Value.value)
return value_;
}
- void Int64Value::set_value(::google::protobuf::int64 value) {
+void Int64Value::set_value(::google::protobuf::int64 value) {
value_ = value;
// @@protoc_insertion_point(field_set:google.protobuf.Int64Value.value)
@@ -1097,34 +997,34 @@ const int UInt64Value::kValueFieldNumber;
UInt64Value::UInt64Value()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.UInt64Value)
}
-
UInt64Value::UInt64Value(::google::protobuf::Arena* arena)
: ::google::protobuf::Message(),
_internal_metadata_(arena) {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
SharedCtor();
RegisterArenaDtor(arena);
// @@protoc_insertion_point(arena_constructor:google.protobuf.UInt64Value)
}
-
-void UInt64Value::InitAsDefaultInstance() {
- _is_default_instance_ = true;
-}
-
UInt64Value::UInt64Value(const UInt64Value& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ value_ = from.value_;
// @@protoc_insertion_point(copy_constructor:google.protobuf.UInt64Value)
}
void UInt64Value::SharedCtor() {
- _is_default_instance_ = false;
- _cached_size_ = 0;
value_ = GOOGLE_ULONGLONG(0);
+ _cached_size_ = 0;
}
UInt64Value::~UInt64Value() {
@@ -1133,12 +1033,11 @@ UInt64Value::~UInt64Value() {
}
void UInt64Value::SharedDtor() {
- if (GetArenaNoVirtual() != NULL) {
+ ::google::protobuf::Arena* arena = GetArenaNoVirtual();
+ if (arena != NULL) {
return;
}
- if (this != default_instance_) {
- }
}
void UInt64Value::ArenaDtor(void* object) {
@@ -1153,17 +1052,15 @@ void UInt64Value::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* UInt64Value::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return UInt64Value_descriptor_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[3].descriptor;
}
const UInt64Value& UInt64Value::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-UInt64Value* UInt64Value::default_instance_ = NULL;
-
UInt64Value* UInt64Value::New(::google::protobuf::Arena* arena) const {
return ::google::protobuf::Arena::CreateMessage<UInt64Value>(arena);
}
@@ -1179,21 +1076,21 @@ bool UInt64Value::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.UInt64Value)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional uint64 value = 1;
+ // uint64 value = 1;
case 1: {
- if (tag == 8) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(8u)) {
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>(
input, &value_)));
-
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -1221,7 +1118,7 @@ failure:
void UInt64Value::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.UInt64Value)
- // optional uint64 value = 1;
+ // uint64 value = 1;
if (this->value() != 0) {
::google::protobuf::internal::WireFormatLite::WriteUInt64(1, this->value(), output);
}
@@ -1231,8 +1128,9 @@ void UInt64Value::SerializeWithCachedSizes(
::google::protobuf::uint8* UInt64Value::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UInt64Value)
- // optional uint64 value = 1;
+ // uint64 value = 1;
if (this->value() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteUInt64ToArray(1, this->value(), target);
}
@@ -1241,29 +1139,28 @@ void UInt64Value::SerializeWithCachedSizes(
return target;
}
-int UInt64Value::ByteSize() const {
+size_t UInt64Value::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.UInt64Value)
- int total_size = 0;
+ size_t total_size = 0;
- // optional uint64 value = 1;
+ // uint64 value = 1;
if (this->value() != 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::UInt64Size(
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 UInt64Value::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.UInt64Value)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
- const UInt64Value* source =
+ GOOGLE_DCHECK_NE(&from, this);
+ const UInt64Value* source =
::google::protobuf::internal::DynamicCastToGenerated<const UInt64Value>(
&from);
if (source == NULL) {
@@ -1277,9 +1174,8 @@ void UInt64Value::MergeFrom(const ::google::protobuf::Message& from) {
void UInt64Value::MergeFrom(const UInt64Value& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UInt64Value)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
if (from.value() != 0) {
set_value(from.value());
}
@@ -1300,7 +1196,6 @@ void UInt64Value::CopyFrom(const UInt64Value& from) {
}
bool UInt64Value::IsInitialized() const {
-
return true;
}
@@ -1309,10 +1204,13 @@ void UInt64Value::Swap(UInt64Value* other) {
if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
InternalSwap(other);
} else {
- UInt64Value temp;
- temp.MergeFrom(*this);
- CopyFrom(*other);
- other->CopyFrom(temp);
+ UInt64Value* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
}
}
void UInt64Value::UnsafeArenaSwap(UInt64Value* other) {
@@ -1322,30 +1220,26 @@ void UInt64Value::UnsafeArenaSwap(UInt64Value* other) {
}
void UInt64Value::InternalSwap(UInt64Value* other) {
std::swap(value_, other->value_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata UInt64Value::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = UInt64Value_descriptor_;
- metadata.reflection = UInt64Value_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[3];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// UInt64Value
-// optional uint64 value = 1;
+// uint64 value = 1;
void UInt64Value::clear_value() {
value_ = GOOGLE_ULONGLONG(0);
}
- ::google::protobuf::uint64 UInt64Value::value() const {
+::google::protobuf::uint64 UInt64Value::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.UInt64Value.value)
return value_;
}
- void UInt64Value::set_value(::google::protobuf::uint64 value) {
+void UInt64Value::set_value(::google::protobuf::uint64 value) {
value_ = value;
// @@protoc_insertion_point(field_set:google.protobuf.UInt64Value.value)
@@ -1361,34 +1255,34 @@ const int Int32Value::kValueFieldNumber;
Int32Value::Int32Value()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.Int32Value)
}
-
Int32Value::Int32Value(::google::protobuf::Arena* arena)
: ::google::protobuf::Message(),
_internal_metadata_(arena) {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
SharedCtor();
RegisterArenaDtor(arena);
// @@protoc_insertion_point(arena_constructor:google.protobuf.Int32Value)
}
-
-void Int32Value::InitAsDefaultInstance() {
- _is_default_instance_ = true;
-}
-
Int32Value::Int32Value(const Int32Value& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ value_ = from.value_;
// @@protoc_insertion_point(copy_constructor:google.protobuf.Int32Value)
}
void Int32Value::SharedCtor() {
- _is_default_instance_ = false;
- _cached_size_ = 0;
value_ = 0;
+ _cached_size_ = 0;
}
Int32Value::~Int32Value() {
@@ -1397,12 +1291,11 @@ Int32Value::~Int32Value() {
}
void Int32Value::SharedDtor() {
- if (GetArenaNoVirtual() != NULL) {
+ ::google::protobuf::Arena* arena = GetArenaNoVirtual();
+ if (arena != NULL) {
return;
}
- if (this != default_instance_) {
- }
}
void Int32Value::ArenaDtor(void* object) {
@@ -1417,17 +1310,15 @@ void Int32Value::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* Int32Value::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return Int32Value_descriptor_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[4].descriptor;
}
const Int32Value& Int32Value::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-Int32Value* Int32Value::default_instance_ = NULL;
-
Int32Value* Int32Value::New(::google::protobuf::Arena* arena) const {
return ::google::protobuf::Arena::CreateMessage<Int32Value>(arena);
}
@@ -1443,21 +1334,21 @@ bool Int32Value::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.Int32Value)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional int32 value = 1;
+ // int32 value = 1;
case 1: {
- if (tag == 8) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(8u)) {
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
input, &value_)));
-
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -1485,7 +1376,7 @@ failure:
void Int32Value::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.Int32Value)
- // optional int32 value = 1;
+ // int32 value = 1;
if (this->value() != 0) {
::google::protobuf::internal::WireFormatLite::WriteInt32(1, this->value(), output);
}
@@ -1495,8 +1386,9 @@ void Int32Value::SerializeWithCachedSizes(
::google::protobuf::uint8* Int32Value::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.Int32Value)
- // optional int32 value = 1;
+ // int32 value = 1;
if (this->value() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(1, this->value(), target);
}
@@ -1505,29 +1397,28 @@ void Int32Value::SerializeWithCachedSizes(
return target;
}
-int Int32Value::ByteSize() const {
+size_t Int32Value::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.Int32Value)
- int total_size = 0;
+ size_t total_size = 0;
- // optional int32 value = 1;
+ // int32 value = 1;
if (this->value() != 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::Int32Size(
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 Int32Value::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.Int32Value)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
- const Int32Value* source =
+ GOOGLE_DCHECK_NE(&from, this);
+ const Int32Value* source =
::google::protobuf::internal::DynamicCastToGenerated<const Int32Value>(
&from);
if (source == NULL) {
@@ -1541,9 +1432,8 @@ void Int32Value::MergeFrom(const ::google::protobuf::Message& from) {
void Int32Value::MergeFrom(const Int32Value& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.Int32Value)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
if (from.value() != 0) {
set_value(from.value());
}
@@ -1564,7 +1454,6 @@ void Int32Value::CopyFrom(const Int32Value& from) {
}
bool Int32Value::IsInitialized() const {
-
return true;
}
@@ -1573,10 +1462,13 @@ void Int32Value::Swap(Int32Value* other) {
if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
InternalSwap(other);
} else {
- Int32Value temp;
- temp.MergeFrom(*this);
- CopyFrom(*other);
- other->CopyFrom(temp);
+ Int32Value* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
}
}
void Int32Value::UnsafeArenaSwap(Int32Value* other) {
@@ -1586,30 +1478,26 @@ void Int32Value::UnsafeArenaSwap(Int32Value* other) {
}
void Int32Value::InternalSwap(Int32Value* other) {
std::swap(value_, other->value_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata Int32Value::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = Int32Value_descriptor_;
- metadata.reflection = Int32Value_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[4];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// Int32Value
-// optional int32 value = 1;
+// int32 value = 1;
void Int32Value::clear_value() {
value_ = 0;
}
- ::google::protobuf::int32 Int32Value::value() const {
+::google::protobuf::int32 Int32Value::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.Int32Value.value)
return value_;
}
- void Int32Value::set_value(::google::protobuf::int32 value) {
+void Int32Value::set_value(::google::protobuf::int32 value) {
value_ = value;
// @@protoc_insertion_point(field_set:google.protobuf.Int32Value.value)
@@ -1625,34 +1513,34 @@ const int UInt32Value::kValueFieldNumber;
UInt32Value::UInt32Value()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.UInt32Value)
}
-
UInt32Value::UInt32Value(::google::protobuf::Arena* arena)
: ::google::protobuf::Message(),
_internal_metadata_(arena) {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
SharedCtor();
RegisterArenaDtor(arena);
// @@protoc_insertion_point(arena_constructor:google.protobuf.UInt32Value)
}
-
-void UInt32Value::InitAsDefaultInstance() {
- _is_default_instance_ = true;
-}
-
UInt32Value::UInt32Value(const UInt32Value& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ value_ = from.value_;
// @@protoc_insertion_point(copy_constructor:google.protobuf.UInt32Value)
}
void UInt32Value::SharedCtor() {
- _is_default_instance_ = false;
- _cached_size_ = 0;
value_ = 0u;
+ _cached_size_ = 0;
}
UInt32Value::~UInt32Value() {
@@ -1661,12 +1549,11 @@ UInt32Value::~UInt32Value() {
}
void UInt32Value::SharedDtor() {
- if (GetArenaNoVirtual() != NULL) {
+ ::google::protobuf::Arena* arena = GetArenaNoVirtual();
+ if (arena != NULL) {
return;
}
- if (this != default_instance_) {
- }
}
void UInt32Value::ArenaDtor(void* object) {
@@ -1681,17 +1568,15 @@ void UInt32Value::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* UInt32Value::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return UInt32Value_descriptor_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[5].descriptor;
}
const UInt32Value& UInt32Value::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-UInt32Value* UInt32Value::default_instance_ = NULL;
-
UInt32Value* UInt32Value::New(::google::protobuf::Arena* arena) const {
return ::google::protobuf::Arena::CreateMessage<UInt32Value>(arena);
}
@@ -1707,21 +1592,21 @@ bool UInt32Value::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.UInt32Value)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional uint32 value = 1;
+ // uint32 value = 1;
case 1: {
- if (tag == 8) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(8u)) {
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>(
input, &value_)));
-
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -1749,7 +1634,7 @@ failure:
void UInt32Value::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.UInt32Value)
- // optional uint32 value = 1;
+ // uint32 value = 1;
if (this->value() != 0) {
::google::protobuf::internal::WireFormatLite::WriteUInt32(1, this->value(), output);
}
@@ -1759,8 +1644,9 @@ void UInt32Value::SerializeWithCachedSizes(
::google::protobuf::uint8* UInt32Value::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.UInt32Value)
- // optional uint32 value = 1;
+ // uint32 value = 1;
if (this->value() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteUInt32ToArray(1, this->value(), target);
}
@@ -1769,29 +1655,28 @@ void UInt32Value::SerializeWithCachedSizes(
return target;
}
-int UInt32Value::ByteSize() const {
+size_t UInt32Value::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.UInt32Value)
- int total_size = 0;
+ size_t total_size = 0;
- // optional uint32 value = 1;
+ // uint32 value = 1;
if (this->value() != 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::UInt32Size(
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 UInt32Value::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.UInt32Value)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
- const UInt32Value* source =
+ GOOGLE_DCHECK_NE(&from, this);
+ const UInt32Value* source =
::google::protobuf::internal::DynamicCastToGenerated<const UInt32Value>(
&from);
if (source == NULL) {
@@ -1805,9 +1690,8 @@ void UInt32Value::MergeFrom(const ::google::protobuf::Message& from) {
void UInt32Value::MergeFrom(const UInt32Value& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.UInt32Value)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
if (from.value() != 0) {
set_value(from.value());
}
@@ -1828,7 +1712,6 @@ void UInt32Value::CopyFrom(const UInt32Value& from) {
}
bool UInt32Value::IsInitialized() const {
-
return true;
}
@@ -1837,10 +1720,13 @@ void UInt32Value::Swap(UInt32Value* other) {
if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
InternalSwap(other);
} else {
- UInt32Value temp;
- temp.MergeFrom(*this);
- CopyFrom(*other);
- other->CopyFrom(temp);
+ UInt32Value* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
}
}
void UInt32Value::UnsafeArenaSwap(UInt32Value* other) {
@@ -1850,30 +1736,26 @@ void UInt32Value::UnsafeArenaSwap(UInt32Value* other) {
}
void UInt32Value::InternalSwap(UInt32Value* other) {
std::swap(value_, other->value_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata UInt32Value::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = UInt32Value_descriptor_;
- metadata.reflection = UInt32Value_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[5];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// UInt32Value
-// optional uint32 value = 1;
+// uint32 value = 1;
void UInt32Value::clear_value() {
value_ = 0u;
}
- ::google::protobuf::uint32 UInt32Value::value() const {
+::google::protobuf::uint32 UInt32Value::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.UInt32Value.value)
return value_;
}
- void UInt32Value::set_value(::google::protobuf::uint32 value) {
+void UInt32Value::set_value(::google::protobuf::uint32 value) {
value_ = value;
// @@protoc_insertion_point(field_set:google.protobuf.UInt32Value.value)
@@ -1889,34 +1771,34 @@ const int BoolValue::kValueFieldNumber;
BoolValue::BoolValue()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.BoolValue)
}
-
BoolValue::BoolValue(::google::protobuf::Arena* arena)
: ::google::protobuf::Message(),
_internal_metadata_(arena) {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
SharedCtor();
RegisterArenaDtor(arena);
// @@protoc_insertion_point(arena_constructor:google.protobuf.BoolValue)
}
-
-void BoolValue::InitAsDefaultInstance() {
- _is_default_instance_ = true;
-}
-
BoolValue::BoolValue(const BoolValue& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ value_ = from.value_;
// @@protoc_insertion_point(copy_constructor:google.protobuf.BoolValue)
}
void BoolValue::SharedCtor() {
- _is_default_instance_ = false;
- _cached_size_ = 0;
value_ = false;
+ _cached_size_ = 0;
}
BoolValue::~BoolValue() {
@@ -1925,12 +1807,11 @@ BoolValue::~BoolValue() {
}
void BoolValue::SharedDtor() {
- if (GetArenaNoVirtual() != NULL) {
+ ::google::protobuf::Arena* arena = GetArenaNoVirtual();
+ if (arena != NULL) {
return;
}
- if (this != default_instance_) {
- }
}
void BoolValue::ArenaDtor(void* object) {
@@ -1945,17 +1826,15 @@ void BoolValue::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* BoolValue::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return BoolValue_descriptor_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[6].descriptor;
}
const BoolValue& BoolValue::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-BoolValue* BoolValue::default_instance_ = NULL;
-
BoolValue* BoolValue::New(::google::protobuf::Arena* arena) const {
return ::google::protobuf::Arena::CreateMessage<BoolValue>(arena);
}
@@ -1971,21 +1850,21 @@ bool BoolValue::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.BoolValue)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional bool value = 1;
+ // bool value = 1;
case 1: {
- if (tag == 8) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(8u)) {
+
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>(
input, &value_)));
-
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -2013,7 +1892,7 @@ failure:
void BoolValue::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.BoolValue)
- // optional bool value = 1;
+ // bool value = 1;
if (this->value() != 0) {
::google::protobuf::internal::WireFormatLite::WriteBool(1, this->value(), output);
}
@@ -2023,8 +1902,9 @@ void BoolValue::SerializeWithCachedSizes(
::google::protobuf::uint8* BoolValue::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.BoolValue)
- // optional bool value = 1;
+ // bool value = 1;
if (this->value() != 0) {
target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(1, this->value(), target);
}
@@ -2033,27 +1913,26 @@ void BoolValue::SerializeWithCachedSizes(
return target;
}
-int BoolValue::ByteSize() const {
+size_t BoolValue::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.BoolValue)
- int total_size = 0;
+ size_t total_size = 0;
- // optional bool value = 1;
+ // bool value = 1;
if (this->value() != 0) {
total_size += 1 + 1;
}
+ 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 BoolValue::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.BoolValue)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
- const BoolValue* source =
+ GOOGLE_DCHECK_NE(&from, this);
+ const BoolValue* source =
::google::protobuf::internal::DynamicCastToGenerated<const BoolValue>(
&from);
if (source == NULL) {
@@ -2067,9 +1946,8 @@ void BoolValue::MergeFrom(const ::google::protobuf::Message& from) {
void BoolValue::MergeFrom(const BoolValue& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.BoolValue)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
if (from.value() != 0) {
set_value(from.value());
}
@@ -2090,7 +1968,6 @@ void BoolValue::CopyFrom(const BoolValue& from) {
}
bool BoolValue::IsInitialized() const {
-
return true;
}
@@ -2099,10 +1976,13 @@ void BoolValue::Swap(BoolValue* other) {
if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
InternalSwap(other);
} else {
- BoolValue temp;
- temp.MergeFrom(*this);
- CopyFrom(*other);
- other->CopyFrom(temp);
+ BoolValue* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
}
}
void BoolValue::UnsafeArenaSwap(BoolValue* other) {
@@ -2112,30 +1992,26 @@ void BoolValue::UnsafeArenaSwap(BoolValue* other) {
}
void BoolValue::InternalSwap(BoolValue* other) {
std::swap(value_, other->value_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata BoolValue::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = BoolValue_descriptor_;
- metadata.reflection = BoolValue_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[6];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// BoolValue
-// optional bool value = 1;
+// bool value = 1;
void BoolValue::clear_value() {
value_ = false;
}
- bool BoolValue::value() const {
+bool BoolValue::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.BoolValue.value)
return value_;
}
- void BoolValue::set_value(bool value) {
+void BoolValue::set_value(bool value) {
value_ = value;
// @@protoc_insertion_point(field_set:google.protobuf.BoolValue.value)
@@ -2151,35 +2027,38 @@ const int StringValue::kValueFieldNumber;
StringValue::StringValue()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.StringValue)
}
-
StringValue::StringValue(::google::protobuf::Arena* arena)
: ::google::protobuf::Message(),
_internal_metadata_(arena) {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
SharedCtor();
RegisterArenaDtor(arena);
// @@protoc_insertion_point(arena_constructor:google.protobuf.StringValue)
}
-
-void StringValue::InitAsDefaultInstance() {
- _is_default_instance_ = true;
-}
-
StringValue::StringValue(const StringValue& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.value().size() > 0) {
+ value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.value(),
+ GetArenaNoVirtual());
+ }
// @@protoc_insertion_point(copy_constructor:google.protobuf.StringValue)
}
void StringValue::SharedCtor() {
- _is_default_instance_ = false;
- ::google::protobuf::internal::GetEmptyString();
- _cached_size_ = 0;
value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ _cached_size_ = 0;
}
StringValue::~StringValue() {
@@ -2188,13 +2067,12 @@ StringValue::~StringValue() {
}
void StringValue::SharedDtor() {
- if (GetArenaNoVirtual() != NULL) {
+ ::google::protobuf::Arena* arena = GetArenaNoVirtual();
+ if (arena != NULL) {
return;
}
- value_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
- if (this != default_instance_) {
- }
+ value_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena);
}
void StringValue::ArenaDtor(void* object) {
@@ -2209,17 +2087,15 @@ void StringValue::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* StringValue::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return StringValue_descriptor_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[7].descriptor;
}
const StringValue& StringValue::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-StringValue* StringValue::default_instance_ = NULL;
-
StringValue* StringValue::New(::google::protobuf::Arena* arena) const {
return ::google::protobuf::Arena::CreateMessage<StringValue>(arena);
}
@@ -2235,13 +2111,14 @@ bool StringValue::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.StringValue)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional string value = 1;
+ // string value = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadString(
input, this->mutable_value()));
DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
@@ -2251,7 +2128,6 @@ bool StringValue::MergePartialFromCodedStream(
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -2279,7 +2155,7 @@ failure:
void StringValue::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.StringValue)
- // optional string value = 1;
+ // string value = 1;
if (this->value().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->value().data(), this->value().length(),
@@ -2294,8 +2170,9 @@ void StringValue::SerializeWithCachedSizes(
::google::protobuf::uint8* StringValue::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.StringValue)
- // optional string value = 1;
+ // string value = 1;
if (this->value().size() > 0) {
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
this->value().data(), this->value().length(),
@@ -2310,29 +2187,28 @@ void StringValue::SerializeWithCachedSizes(
return target;
}
-int StringValue::ByteSize() const {
+size_t StringValue::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.StringValue)
- int total_size = 0;
+ size_t total_size = 0;
- // optional string value = 1;
+ // string value = 1;
if (this->value().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::StringSize(
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 StringValue::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.StringValue)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
- const StringValue* source =
+ GOOGLE_DCHECK_NE(&from, this);
+ const StringValue* source =
::google::protobuf::internal::DynamicCastToGenerated<const StringValue>(
&from);
if (source == NULL) {
@@ -2346,9 +2222,8 @@ void StringValue::MergeFrom(const ::google::protobuf::Message& from) {
void StringValue::MergeFrom(const StringValue& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.StringValue)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
if (from.value().size() > 0) {
set_value(from.value());
}
@@ -2369,7 +2244,6 @@ void StringValue::CopyFrom(const StringValue& from) {
}
bool StringValue::IsInitialized() const {
-
return true;
}
@@ -2378,10 +2252,13 @@ void StringValue::Swap(StringValue* other) {
if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
InternalSwap(other);
} else {
- StringValue temp;
- temp.MergeFrom(*this);
- CopyFrom(*other);
- other->CopyFrom(temp);
+ StringValue* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
}
}
void StringValue::UnsafeArenaSwap(StringValue* other) {
@@ -2391,65 +2268,61 @@ void StringValue::UnsafeArenaSwap(StringValue* other) {
}
void StringValue::InternalSwap(StringValue* other) {
value_.Swap(&other->value_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata StringValue::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = StringValue_descriptor_;
- metadata.reflection = StringValue_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[7];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// StringValue
-// optional string value = 1;
+// string value = 1;
void StringValue::clear_value() {
value_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
- const ::std::string& StringValue::value() const {
+const ::std::string& StringValue::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.StringValue.value)
- return value_.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return value_.Get();
}
- void StringValue::set_value(const ::std::string& value) {
+void StringValue::set_value(const ::std::string& value) {
value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual());
// @@protoc_insertion_point(field_set:google.protobuf.StringValue.value)
}
- void StringValue::set_value(const char* value) {
+void StringValue::set_value(const char* value) {
value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_char:google.protobuf.StringValue.value)
}
- void StringValue::set_value(const char* value,
+void StringValue::set_value(const char* value,
size_t size) {
value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
reinterpret_cast<const char*>(value), size), GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.StringValue.value)
}
- ::std::string* StringValue::mutable_value() {
+::std::string* StringValue::mutable_value() {
// @@protoc_insertion_point(field_mutable:google.protobuf.StringValue.value)
return value_.Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
- ::std::string* StringValue::release_value() {
+::std::string* StringValue::release_value() {
// @@protoc_insertion_point(field_release:google.protobuf.StringValue.value)
return value_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
- ::std::string* StringValue::unsafe_arena_release_value() {
+::std::string* StringValue::unsafe_arena_release_value() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.StringValue.value)
GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);
return value_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
GetArenaNoVirtual());
}
- void StringValue::set_allocated_value(::std::string* value) {
+void StringValue::set_allocated_value(::std::string* value) {
if (value != NULL) {
} else {
@@ -2459,7 +2332,7 @@ void StringValue::clear_value() {
GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.StringValue.value)
}
- void StringValue::unsafe_arena_set_allocated_value(
+void StringValue::unsafe_arena_set_allocated_value(
::std::string* value) {
GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);
if (value != NULL) {
@@ -2482,35 +2355,38 @@ const int BytesValue::kValueFieldNumber;
BytesValue::BytesValue()
: ::google::protobuf::Message(), _internal_metadata_(NULL) {
+ if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ }
SharedCtor();
// @@protoc_insertion_point(constructor:google.protobuf.BytesValue)
}
-
BytesValue::BytesValue(::google::protobuf::Arena* arena)
: ::google::protobuf::Message(),
_internal_metadata_(arena) {
+#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
SharedCtor();
RegisterArenaDtor(arena);
// @@protoc_insertion_point(arena_constructor:google.protobuf.BytesValue)
}
-
-void BytesValue::InitAsDefaultInstance() {
- _is_default_instance_ = true;
-}
-
BytesValue::BytesValue(const BytesValue& from)
: ::google::protobuf::Message(),
- _internal_metadata_(NULL) {
- SharedCtor();
- MergeFrom(from);
+ _internal_metadata_(NULL),
+ _cached_size_(0) {
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
+ value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ if (from.value().size() > 0) {
+ value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.value(),
+ GetArenaNoVirtual());
+ }
// @@protoc_insertion_point(copy_constructor:google.protobuf.BytesValue)
}
void BytesValue::SharedCtor() {
- _is_default_instance_ = false;
- ::google::protobuf::internal::GetEmptyString();
- _cached_size_ = 0;
value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ _cached_size_ = 0;
}
BytesValue::~BytesValue() {
@@ -2519,13 +2395,12 @@ BytesValue::~BytesValue() {
}
void BytesValue::SharedDtor() {
- if (GetArenaNoVirtual() != NULL) {
+ ::google::protobuf::Arena* arena = GetArenaNoVirtual();
+ if (arena != NULL) {
return;
}
- value_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
- if (this != default_instance_) {
- }
+ value_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena);
}
void BytesValue::ArenaDtor(void* object) {
@@ -2540,17 +2415,15 @@ void BytesValue::SetCachedSize(int size) const {
GOOGLE_SAFE_CONCURRENT_WRITES_END();
}
const ::google::protobuf::Descriptor* BytesValue::descriptor() {
- protobuf_AssignDescriptorsOnce();
- return BytesValue_descriptor_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[8].descriptor;
}
const BytesValue& BytesValue::default_instance() {
- if (default_instance_ == NULL) protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- return *default_instance_;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults();
+ return *internal_default_instance();
}
-BytesValue* BytesValue::default_instance_ = NULL;
-
BytesValue* BytesValue::New(::google::protobuf::Arena* arena) const {
return ::google::protobuf::Arena::CreateMessage<BytesValue>(arena);
}
@@ -2566,19 +2439,19 @@ bool BytesValue::MergePartialFromCodedStream(
::google::protobuf::uint32 tag;
// @@protoc_insertion_point(parse_start:google.protobuf.BytesValue)
for (;;) {
- ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoff(127);
+ ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
tag = p.first;
if (!p.second) goto handle_unusual;
switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
- // optional bytes value = 1;
+ // bytes value = 1;
case 1: {
- if (tag == 10) {
+ if (static_cast< ::google::protobuf::uint8>(tag) ==
+ static_cast< ::google::protobuf::uint8>(10u)) {
DO_(::google::protobuf::internal::WireFormatLite::ReadBytes(
input, this->mutable_value()));
} else {
goto handle_unusual;
}
- if (input->ExpectAtEnd()) goto success;
break;
}
@@ -2606,7 +2479,7 @@ failure:
void BytesValue::SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const {
// @@protoc_insertion_point(serialize_start:google.protobuf.BytesValue)
- // optional bytes value = 1;
+ // bytes value = 1;
if (this->value().size() > 0) {
::google::protobuf::internal::WireFormatLite::WriteBytesMaybeAliased(
1, this->value(), output);
@@ -2617,8 +2490,9 @@ void BytesValue::SerializeWithCachedSizes(
::google::protobuf::uint8* BytesValue::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
+ (void)deterministic; // Unused
// @@protoc_insertion_point(serialize_to_array_start:google.protobuf.BytesValue)
- // optional bytes value = 1;
+ // bytes value = 1;
if (this->value().size() > 0) {
target =
::google::protobuf::internal::WireFormatLite::WriteBytesToArray(
@@ -2629,29 +2503,28 @@ void BytesValue::SerializeWithCachedSizes(
return target;
}
-int BytesValue::ByteSize() const {
+size_t BytesValue::ByteSizeLong() const {
// @@protoc_insertion_point(message_byte_size_start:google.protobuf.BytesValue)
- int total_size = 0;
+ size_t total_size = 0;
- // optional bytes value = 1;
+ // bytes value = 1;
if (this->value().size() > 0) {
total_size += 1 +
::google::protobuf::internal::WireFormatLite::BytesSize(
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 BytesValue::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.BytesValue)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
- const BytesValue* source =
+ GOOGLE_DCHECK_NE(&from, this);
+ const BytesValue* source =
::google::protobuf::internal::DynamicCastToGenerated<const BytesValue>(
&from);
if (source == NULL) {
@@ -2665,9 +2538,8 @@ void BytesValue::MergeFrom(const ::google::protobuf::Message& from) {
void BytesValue::MergeFrom(const BytesValue& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.BytesValue)
- if (GOOGLE_PREDICT_FALSE(&from == this)) {
- ::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
- }
+ GOOGLE_DCHECK_NE(&from, this);
+ _internal_metadata_.MergeFrom(from._internal_metadata_);
if (from.value().size() > 0) {
set_value(from.value());
}
@@ -2688,7 +2560,6 @@ void BytesValue::CopyFrom(const BytesValue& from) {
}
bool BytesValue::IsInitialized() const {
-
return true;
}
@@ -2697,10 +2568,13 @@ void BytesValue::Swap(BytesValue* other) {
if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) {
InternalSwap(other);
} else {
- BytesValue temp;
- temp.MergeFrom(*this);
- CopyFrom(*other);
- other->CopyFrom(temp);
+ BytesValue* temp = New(GetArenaNoVirtual());
+ temp->MergeFrom(*other);
+ other->CopyFrom(*this);
+ InternalSwap(temp);
+ if (GetArenaNoVirtual() == NULL) {
+ delete temp;
+ }
}
}
void BytesValue::UnsafeArenaSwap(BytesValue* other) {
@@ -2710,65 +2584,61 @@ void BytesValue::UnsafeArenaSwap(BytesValue* other) {
}
void BytesValue::InternalSwap(BytesValue* other) {
value_.Swap(&other->value_);
- _internal_metadata_.Swap(&other->_internal_metadata_);
std::swap(_cached_size_, other->_cached_size_);
}
::google::protobuf::Metadata BytesValue::GetMetadata() const {
- protobuf_AssignDescriptorsOnce();
- ::google::protobuf::Metadata metadata;
- metadata.descriptor = BytesValue_descriptor_;
- metadata.reflection = BytesValue_reflection_;
- return metadata;
+ protobuf_google_2fprotobuf_2fwrappers_2eproto::protobuf_AssignDescriptorsOnce();
+ return protobuf_google_2fprotobuf_2fwrappers_2eproto::file_level_metadata[8];
}
#if PROTOBUF_INLINE_NOT_IN_HEADERS
// BytesValue
-// optional bytes value = 1;
+// bytes value = 1;
void BytesValue::clear_value() {
value_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
- const ::std::string& BytesValue::value() const {
+const ::std::string& BytesValue::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.BytesValue.value)
- return value_.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return value_.Get();
}
- void BytesValue::set_value(const ::std::string& value) {
+void BytesValue::set_value(const ::std::string& value) {
value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual());
// @@protoc_insertion_point(field_set:google.protobuf.BytesValue.value)
}
- void BytesValue::set_value(const char* value) {
+void BytesValue::set_value(const char* value) {
value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value),
GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_char:google.protobuf.BytesValue.value)
}
- void BytesValue::set_value(const void* value,
+void BytesValue::set_value(const void* value,
size_t size) {
value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(
reinterpret_cast<const char*>(value), size), GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_pointer:google.protobuf.BytesValue.value)
}
- ::std::string* BytesValue::mutable_value() {
+::std::string* BytesValue::mutable_value() {
// @@protoc_insertion_point(field_mutable:google.protobuf.BytesValue.value)
return value_.Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
- ::std::string* BytesValue::release_value() {
+::std::string* BytesValue::release_value() {
// @@protoc_insertion_point(field_release:google.protobuf.BytesValue.value)
return value_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
- ::std::string* BytesValue::unsafe_arena_release_value() {
+::std::string* BytesValue::unsafe_arena_release_value() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.BytesValue.value)
GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);
return value_.UnsafeArenaRelease(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
GetArenaNoVirtual());
}
- void BytesValue::set_allocated_value(::std::string* value) {
+void BytesValue::set_allocated_value(::std::string* value) {
if (value != NULL) {
} else {
@@ -2778,7 +2648,7 @@ void BytesValue::clear_value() {
GetArenaNoVirtual());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.BytesValue.value)
}
- void BytesValue::unsafe_arena_set_allocated_value(
+void BytesValue::unsafe_arena_set_allocated_value(
::std::string* value) {
GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);
if (value != NULL) {
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/wrappers.pb.h b/third_party/protobuf/src/google/protobuf/wrappers.pb.h
index 73f8ff62d3..61b0510dca 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/wrappers.pb.h
+++ b/third_party/protobuf/src/google/protobuf/wrappers.pb.h
@@ -8,44 +8,72 @@
#include <google/protobuf/stubs/common.h>
-#if GOOGLE_PROTOBUF_VERSION < 3000000
+#if GOOGLE_PROTOBUF_VERSION < 3002000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
-#if 3000000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
+#if 3002000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
+#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/arena.h>
#include <google/protobuf/arenastring.h>
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/metadata.h>
#include <google/protobuf/message.h>
-#include <google/protobuf/repeated_field.h>
-#include <google/protobuf/extension_set.h>
+#include <google/protobuf/repeated_field.h> // IWYU pragma: export
+#include <google/protobuf/extension_set.h> // IWYU pragma: export
#include <google/protobuf/unknown_field_set.h>
// @@protoc_insertion_point(includes)
-
namespace google {
namespace protobuf {
-
-// Internal implementation detail -- do not call these.
-void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
-void protobuf_AssignDesc_google_2fprotobuf_2fwrappers_2eproto();
-void protobuf_ShutdownFile_google_2fprotobuf_2fwrappers_2eproto();
-
class BoolValue;
+class BoolValueDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern BoolValueDefaultTypeInternal _BoolValue_default_instance_;
class BytesValue;
+class BytesValueDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern BytesValueDefaultTypeInternal _BytesValue_default_instance_;
class DoubleValue;
+class DoubleValueDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern DoubleValueDefaultTypeInternal _DoubleValue_default_instance_;
class FloatValue;
+class FloatValueDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern FloatValueDefaultTypeInternal _FloatValue_default_instance_;
class Int32Value;
+class Int32ValueDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern Int32ValueDefaultTypeInternal _Int32Value_default_instance_;
class Int64Value;
+class Int64ValueDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern Int64ValueDefaultTypeInternal _Int64Value_default_instance_;
class StringValue;
+class StringValueDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern StringValueDefaultTypeInternal _StringValue_default_instance_;
class UInt32Value;
+class UInt32ValueDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern UInt32ValueDefaultTypeInternal _UInt32Value_default_instance_;
class UInt64Value;
+class UInt64ValueDefaultTypeInternal;
+LIBPROTOBUF_EXPORT extern UInt64ValueDefaultTypeInternal _UInt64Value_default_instance_;
+} // namespace protobuf
+} // namespace google
+
+namespace google {
+namespace protobuf {
+
+namespace protobuf_google_2fprotobuf_2fwrappers_2eproto {
+// Internal implementation detail -- do not call these.
+struct LIBPROTOBUF_EXPORT TableStruct {
+ static const ::google::protobuf::uint32 offsets[];
+ static void InitDefaultsImpl();
+ static void Shutdown();
+};
+void LIBPROTOBUF_EXPORT AddDescriptors();
+void LIBPROTOBUF_EXPORT InitDefaults();
+} // namespace protobuf_google_2fprotobuf_2fwrappers_2eproto
// ===================================================================
@@ -61,43 +89,52 @@ class LIBPROTOBUF_EXPORT DoubleValue : public ::google::protobuf::Message /* @@p
return *this;
}
- inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); }
- inline void* GetMaybeArenaPointer() const {
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
return MaybeArenaPtr();
}
static const ::google::protobuf::Descriptor* descriptor();
static const DoubleValue& default_instance();
+ static inline const DoubleValue* internal_default_instance() {
+ return reinterpret_cast<const DoubleValue*>(
+ &_DoubleValue_default_instance_);
+ }
+
void UnsafeArenaSwap(DoubleValue* other);
void Swap(DoubleValue* other);
// implements Message ----------------------------------------------
- inline DoubleValue* New() const { return New(NULL); }
+ inline DoubleValue* New() const PROTOBUF_FINAL { return New(NULL); }
- DoubleValue* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ DoubleValue* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const DoubleValue& from);
void MergeFrom(const DoubleValue& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(DoubleValue* other);
protected:
explicit DoubleValue(::google::protobuf::Arena* arena);
@@ -113,13 +150,13 @@ class LIBPROTOBUF_EXPORT DoubleValue : public ::google::protobuf::Message /* @@p
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional double value = 1;
+ // double value = 1;
void clear_value();
static const int kValueFieldNumber = 1;
double value() const;
@@ -132,15 +169,9 @@ class LIBPROTOBUF_EXPORT DoubleValue : public ::google::protobuf::Message /* @@p
friend class ::google::protobuf::Arena;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
- bool _is_default_instance_;
double value_;
mutable int _cached_size_;
- friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_AssignDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fwrappers_2eproto();
-
- void InitAsDefaultInstance();
- static DoubleValue* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -156,43 +187,52 @@ class LIBPROTOBUF_EXPORT FloatValue : public ::google::protobuf::Message /* @@pr
return *this;
}
- inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); }
- inline void* GetMaybeArenaPointer() const {
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
return MaybeArenaPtr();
}
static const ::google::protobuf::Descriptor* descriptor();
static const FloatValue& default_instance();
+ static inline const FloatValue* internal_default_instance() {
+ return reinterpret_cast<const FloatValue*>(
+ &_FloatValue_default_instance_);
+ }
+
void UnsafeArenaSwap(FloatValue* other);
void Swap(FloatValue* other);
// implements Message ----------------------------------------------
- inline FloatValue* New() const { return New(NULL); }
+ inline FloatValue* New() const PROTOBUF_FINAL { return New(NULL); }
- FloatValue* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ FloatValue* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const FloatValue& from);
void MergeFrom(const FloatValue& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(FloatValue* other);
protected:
explicit FloatValue(::google::protobuf::Arena* arena);
@@ -208,13 +248,13 @@ class LIBPROTOBUF_EXPORT FloatValue : public ::google::protobuf::Message /* @@pr
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional float value = 1;
+ // float value = 1;
void clear_value();
static const int kValueFieldNumber = 1;
float value() const;
@@ -227,15 +267,9 @@ class LIBPROTOBUF_EXPORT FloatValue : public ::google::protobuf::Message /* @@pr
friend class ::google::protobuf::Arena;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
- bool _is_default_instance_;
float value_;
mutable int _cached_size_;
- friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_AssignDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fwrappers_2eproto();
-
- void InitAsDefaultInstance();
- static FloatValue* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -251,43 +285,52 @@ class LIBPROTOBUF_EXPORT Int64Value : public ::google::protobuf::Message /* @@pr
return *this;
}
- inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); }
- inline void* GetMaybeArenaPointer() const {
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
return MaybeArenaPtr();
}
static const ::google::protobuf::Descriptor* descriptor();
static const Int64Value& default_instance();
+ static inline const Int64Value* internal_default_instance() {
+ return reinterpret_cast<const Int64Value*>(
+ &_Int64Value_default_instance_);
+ }
+
void UnsafeArenaSwap(Int64Value* other);
void Swap(Int64Value* other);
// implements Message ----------------------------------------------
- inline Int64Value* New() const { return New(NULL); }
+ inline Int64Value* New() const PROTOBUF_FINAL { return New(NULL); }
- Int64Value* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ Int64Value* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Int64Value& from);
void MergeFrom(const Int64Value& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Int64Value* other);
protected:
explicit Int64Value(::google::protobuf::Arena* arena);
@@ -303,13 +346,13 @@ class LIBPROTOBUF_EXPORT Int64Value : public ::google::protobuf::Message /* @@pr
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional int64 value = 1;
+ // int64 value = 1;
void clear_value();
static const int kValueFieldNumber = 1;
::google::protobuf::int64 value() const;
@@ -322,15 +365,9 @@ class LIBPROTOBUF_EXPORT Int64Value : public ::google::protobuf::Message /* @@pr
friend class ::google::protobuf::Arena;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
- bool _is_default_instance_;
::google::protobuf::int64 value_;
mutable int _cached_size_;
- friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_AssignDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fwrappers_2eproto();
-
- void InitAsDefaultInstance();
- static Int64Value* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -346,43 +383,52 @@ class LIBPROTOBUF_EXPORT UInt64Value : public ::google::protobuf::Message /* @@p
return *this;
}
- inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); }
- inline void* GetMaybeArenaPointer() const {
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
return MaybeArenaPtr();
}
static const ::google::protobuf::Descriptor* descriptor();
static const UInt64Value& default_instance();
+ static inline const UInt64Value* internal_default_instance() {
+ return reinterpret_cast<const UInt64Value*>(
+ &_UInt64Value_default_instance_);
+ }
+
void UnsafeArenaSwap(UInt64Value* other);
void Swap(UInt64Value* other);
// implements Message ----------------------------------------------
- inline UInt64Value* New() const { return New(NULL); }
+ inline UInt64Value* New() const PROTOBUF_FINAL { return New(NULL); }
- UInt64Value* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ UInt64Value* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const UInt64Value& from);
void MergeFrom(const UInt64Value& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(UInt64Value* other);
protected:
explicit UInt64Value(::google::protobuf::Arena* arena);
@@ -398,13 +444,13 @@ class LIBPROTOBUF_EXPORT UInt64Value : public ::google::protobuf::Message /* @@p
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional uint64 value = 1;
+ // uint64 value = 1;
void clear_value();
static const int kValueFieldNumber = 1;
::google::protobuf::uint64 value() const;
@@ -417,15 +463,9 @@ class LIBPROTOBUF_EXPORT UInt64Value : public ::google::protobuf::Message /* @@p
friend class ::google::protobuf::Arena;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
- bool _is_default_instance_;
::google::protobuf::uint64 value_;
mutable int _cached_size_;
- friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_AssignDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fwrappers_2eproto();
-
- void InitAsDefaultInstance();
- static UInt64Value* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -441,43 +481,52 @@ class LIBPROTOBUF_EXPORT Int32Value : public ::google::protobuf::Message /* @@pr
return *this;
}
- inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); }
- inline void* GetMaybeArenaPointer() const {
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
return MaybeArenaPtr();
}
static const ::google::protobuf::Descriptor* descriptor();
static const Int32Value& default_instance();
+ static inline const Int32Value* internal_default_instance() {
+ return reinterpret_cast<const Int32Value*>(
+ &_Int32Value_default_instance_);
+ }
+
void UnsafeArenaSwap(Int32Value* other);
void Swap(Int32Value* other);
// implements Message ----------------------------------------------
- inline Int32Value* New() const { return New(NULL); }
+ inline Int32Value* New() const PROTOBUF_FINAL { return New(NULL); }
- Int32Value* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ Int32Value* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const Int32Value& from);
void MergeFrom(const Int32Value& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(Int32Value* other);
protected:
explicit Int32Value(::google::protobuf::Arena* arena);
@@ -493,13 +542,13 @@ class LIBPROTOBUF_EXPORT Int32Value : public ::google::protobuf::Message /* @@pr
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional int32 value = 1;
+ // int32 value = 1;
void clear_value();
static const int kValueFieldNumber = 1;
::google::protobuf::int32 value() const;
@@ -512,15 +561,9 @@ class LIBPROTOBUF_EXPORT Int32Value : public ::google::protobuf::Message /* @@pr
friend class ::google::protobuf::Arena;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
- bool _is_default_instance_;
::google::protobuf::int32 value_;
mutable int _cached_size_;
- friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_AssignDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fwrappers_2eproto();
-
- void InitAsDefaultInstance();
- static Int32Value* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -536,43 +579,52 @@ class LIBPROTOBUF_EXPORT UInt32Value : public ::google::protobuf::Message /* @@p
return *this;
}
- inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); }
- inline void* GetMaybeArenaPointer() const {
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
return MaybeArenaPtr();
}
static const ::google::protobuf::Descriptor* descriptor();
static const UInt32Value& default_instance();
+ static inline const UInt32Value* internal_default_instance() {
+ return reinterpret_cast<const UInt32Value*>(
+ &_UInt32Value_default_instance_);
+ }
+
void UnsafeArenaSwap(UInt32Value* other);
void Swap(UInt32Value* other);
// implements Message ----------------------------------------------
- inline UInt32Value* New() const { return New(NULL); }
+ inline UInt32Value* New() const PROTOBUF_FINAL { return New(NULL); }
- UInt32Value* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ UInt32Value* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const UInt32Value& from);
void MergeFrom(const UInt32Value& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(UInt32Value* other);
protected:
explicit UInt32Value(::google::protobuf::Arena* arena);
@@ -588,13 +640,13 @@ class LIBPROTOBUF_EXPORT UInt32Value : public ::google::protobuf::Message /* @@p
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional uint32 value = 1;
+ // uint32 value = 1;
void clear_value();
static const int kValueFieldNumber = 1;
::google::protobuf::uint32 value() const;
@@ -607,15 +659,9 @@ class LIBPROTOBUF_EXPORT UInt32Value : public ::google::protobuf::Message /* @@p
friend class ::google::protobuf::Arena;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
- bool _is_default_instance_;
::google::protobuf::uint32 value_;
mutable int _cached_size_;
- friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_AssignDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fwrappers_2eproto();
-
- void InitAsDefaultInstance();
- static UInt32Value* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -631,43 +677,52 @@ class LIBPROTOBUF_EXPORT BoolValue : public ::google::protobuf::Message /* @@pro
return *this;
}
- inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); }
- inline void* GetMaybeArenaPointer() const {
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
return MaybeArenaPtr();
}
static const ::google::protobuf::Descriptor* descriptor();
static const BoolValue& default_instance();
+ static inline const BoolValue* internal_default_instance() {
+ return reinterpret_cast<const BoolValue*>(
+ &_BoolValue_default_instance_);
+ }
+
void UnsafeArenaSwap(BoolValue* other);
void Swap(BoolValue* other);
// implements Message ----------------------------------------------
- inline BoolValue* New() const { return New(NULL); }
+ inline BoolValue* New() const PROTOBUF_FINAL { return New(NULL); }
- BoolValue* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ BoolValue* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const BoolValue& from);
void MergeFrom(const BoolValue& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(BoolValue* other);
protected:
explicit BoolValue(::google::protobuf::Arena* arena);
@@ -683,13 +738,13 @@ class LIBPROTOBUF_EXPORT BoolValue : public ::google::protobuf::Message /* @@pro
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional bool value = 1;
+ // bool value = 1;
void clear_value();
static const int kValueFieldNumber = 1;
bool value() const;
@@ -702,15 +757,9 @@ class LIBPROTOBUF_EXPORT BoolValue : public ::google::protobuf::Message /* @@pro
friend class ::google::protobuf::Arena;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
- bool _is_default_instance_;
bool value_;
mutable int _cached_size_;
- friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_AssignDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fwrappers_2eproto();
-
- void InitAsDefaultInstance();
- static BoolValue* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -726,43 +775,52 @@ class LIBPROTOBUF_EXPORT StringValue : public ::google::protobuf::Message /* @@p
return *this;
}
- inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); }
- inline void* GetMaybeArenaPointer() const {
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
return MaybeArenaPtr();
}
static const ::google::protobuf::Descriptor* descriptor();
static const StringValue& default_instance();
+ static inline const StringValue* internal_default_instance() {
+ return reinterpret_cast<const StringValue*>(
+ &_StringValue_default_instance_);
+ }
+
void UnsafeArenaSwap(StringValue* other);
void Swap(StringValue* other);
// implements Message ----------------------------------------------
- inline StringValue* New() const { return New(NULL); }
+ inline StringValue* New() const PROTOBUF_FINAL { return New(NULL); }
- StringValue* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ StringValue* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const StringValue& from);
void MergeFrom(const StringValue& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(StringValue* other);
protected:
explicit StringValue(::google::protobuf::Arena* arena);
@@ -778,13 +836,13 @@ class LIBPROTOBUF_EXPORT StringValue : public ::google::protobuf::Message /* @@p
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional string value = 1;
+ // string value = 1;
void clear_value();
static const int kValueFieldNumber = 1;
const ::std::string& value() const;
@@ -805,15 +863,9 @@ class LIBPROTOBUF_EXPORT StringValue : public ::google::protobuf::Message /* @@p
friend class ::google::protobuf::Arena;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
- bool _is_default_instance_;
::google::protobuf::internal::ArenaStringPtr value_;
mutable int _cached_size_;
- friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_AssignDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fwrappers_2eproto();
-
- void InitAsDefaultInstance();
- static StringValue* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct;
};
// -------------------------------------------------------------------
@@ -829,43 +881,52 @@ class LIBPROTOBUF_EXPORT BytesValue : public ::google::protobuf::Message /* @@pr
return *this;
}
- inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); }
- inline void* GetMaybeArenaPointer() const {
+ inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL {
+ return GetArenaNoVirtual();
+ }
+ inline void* GetMaybeArenaPointer() const PROTOBUF_FINAL {
return MaybeArenaPtr();
}
static const ::google::protobuf::Descriptor* descriptor();
static const BytesValue& default_instance();
+ static inline const BytesValue* internal_default_instance() {
+ return reinterpret_cast<const BytesValue*>(
+ &_BytesValue_default_instance_);
+ }
+
void UnsafeArenaSwap(BytesValue* other);
void Swap(BytesValue* other);
// implements Message ----------------------------------------------
- inline BytesValue* New() const { return New(NULL); }
+ inline BytesValue* New() const PROTOBUF_FINAL { return New(NULL); }
- BytesValue* New(::google::protobuf::Arena* arena) const;
- void CopyFrom(const ::google::protobuf::Message& from);
- void MergeFrom(const ::google::protobuf::Message& from);
+ BytesValue* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+ void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+ void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
void CopyFrom(const BytesValue& from);
void MergeFrom(const BytesValue& from);
- void Clear();
- bool IsInitialized() const;
+ void Clear() PROTOBUF_FINAL;
+ bool IsInitialized() const PROTOBUF_FINAL;
- int ByteSize() const;
+ size_t ByteSizeLong() const PROTOBUF_FINAL;
bool MergePartialFromCodedStream(
- ::google::protobuf::io::CodedInputStream* input);
+ ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
void SerializeWithCachedSizes(
- ::google::protobuf::io::CodedOutputStream* output) const;
+ ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
- bool deterministic, ::google::protobuf::uint8* output) const;
- ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
- return InternalSerializeWithCachedSizesToArray(false, output);
+ bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+ ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output)
+ const PROTOBUF_FINAL {
+ return InternalSerializeWithCachedSizesToArray(
+ ::google::protobuf::io::CodedOutputStream::IsDefaultSerializationDeterministic(), output);
}
- int GetCachedSize() const { return _cached_size_; }
+ int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
private:
void SharedCtor();
void SharedDtor();
- void SetCachedSize(int size) const;
+ void SetCachedSize(int size) const PROTOBUF_FINAL;
void InternalSwap(BytesValue* other);
protected:
explicit BytesValue(::google::protobuf::Arena* arena);
@@ -881,13 +942,13 @@ class LIBPROTOBUF_EXPORT BytesValue : public ::google::protobuf::Message /* @@pr
}
public:
- ::google::protobuf::Metadata GetMetadata() const;
+ ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
// nested types ----------------------------------------------------
// accessors -------------------------------------------------------
- // optional bytes value = 1;
+ // bytes value = 1;
void clear_value();
static const int kValueFieldNumber = 1;
const ::std::string& value() const;
@@ -908,15 +969,9 @@ class LIBPROTOBUF_EXPORT BytesValue : public ::google::protobuf::Message /* @@pr
friend class ::google::protobuf::Arena;
typedef void InternalArenaConstructable_;
typedef void DestructorSkippable_;
- bool _is_default_instance_;
::google::protobuf::internal::ArenaStringPtr value_;
mutable int _cached_size_;
- friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_AssignDesc_google_2fprotobuf_2fwrappers_2eproto();
- friend void protobuf_ShutdownFile_google_2fprotobuf_2fwrappers_2eproto();
-
- void InitAsDefaultInstance();
- static BytesValue* default_instance_;
+ friend struct LIBPROTOBUF_EXPORT protobuf_google_2fprotobuf_2fwrappers_2eproto::TableStruct;
};
// ===================================================================
@@ -926,7 +981,7 @@ class LIBPROTOBUF_EXPORT BytesValue : public ::google::protobuf::Message /* @@pr
#if !PROTOBUF_INLINE_NOT_IN_HEADERS
// DoubleValue
-// optional double value = 1;
+// double value = 1;
inline void DoubleValue::clear_value() {
value_ = 0;
}
@@ -944,7 +999,7 @@ inline void DoubleValue::set_value(double value) {
// FloatValue
-// optional float value = 1;
+// float value = 1;
inline void FloatValue::clear_value() {
value_ = 0;
}
@@ -962,7 +1017,7 @@ inline void FloatValue::set_value(float value) {
// Int64Value
-// optional int64 value = 1;
+// int64 value = 1;
inline void Int64Value::clear_value() {
value_ = GOOGLE_LONGLONG(0);
}
@@ -980,7 +1035,7 @@ inline void Int64Value::set_value(::google::protobuf::int64 value) {
// UInt64Value
-// optional uint64 value = 1;
+// uint64 value = 1;
inline void UInt64Value::clear_value() {
value_ = GOOGLE_ULONGLONG(0);
}
@@ -998,7 +1053,7 @@ inline void UInt64Value::set_value(::google::protobuf::uint64 value) {
// Int32Value
-// optional int32 value = 1;
+// int32 value = 1;
inline void Int32Value::clear_value() {
value_ = 0;
}
@@ -1016,7 +1071,7 @@ inline void Int32Value::set_value(::google::protobuf::int32 value) {
// UInt32Value
-// optional uint32 value = 1;
+// uint32 value = 1;
inline void UInt32Value::clear_value() {
value_ = 0u;
}
@@ -1034,7 +1089,7 @@ inline void UInt32Value::set_value(::google::protobuf::uint32 value) {
// BoolValue
-// optional bool value = 1;
+// bool value = 1;
inline void BoolValue::clear_value() {
value_ = false;
}
@@ -1052,13 +1107,13 @@ inline void BoolValue::set_value(bool value) {
// StringValue
-// optional string value = 1;
+// string value = 1;
inline void StringValue::clear_value() {
value_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
inline const ::std::string& StringValue::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.StringValue.value)
- return value_.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return value_.Get();
}
inline void StringValue::set_value(const ::std::string& value) {
@@ -1122,13 +1177,13 @@ inline void StringValue::unsafe_arena_set_allocated_value(
// BytesValue
-// optional bytes value = 1;
+// bytes value = 1;
inline void BytesValue::clear_value() {
value_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual());
}
inline const ::std::string& BytesValue::value() const {
// @@protoc_insertion_point(field_get:google.protobuf.BytesValue.value)
- return value_.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+ return value_.Get();
}
inline void BytesValue::set_value(const ::std::string& value) {
@@ -1208,6 +1263,7 @@ inline void BytesValue::unsafe_arena_set_allocated_value(
// @@protoc_insertion_point(namespace_scope)
+
} // namespace protobuf
} // namespace google
diff --git a/third_party/protobuf/3.0.0/src/google/protobuf/wrappers.proto b/third_party/protobuf/src/google/protobuf/wrappers.proto
index 4828ad9ae9..01947639ac 100644
--- a/third_party/protobuf/3.0.0/src/google/protobuf/wrappers.proto
+++ b/third_party/protobuf/src/google/protobuf/wrappers.proto
@@ -43,7 +43,6 @@ option go_package = "github.com/golang/protobuf/ptypes/wrappers";
option java_package = "com.google.protobuf";
option java_outer_classname = "WrappersProto";
option java_multiple_files = true;
-option java_generate_equals_and_hash = true;
option objc_class_prefix = "GPB";
// Wrapper message for `double`.
diff --git a/third_party/protobuf/src/libprotobuf-lite.map b/third_party/protobuf/src/libprotobuf-lite.map
new file mode 100644
index 0000000000..3915546694
--- /dev/null
+++ b/third_party/protobuf/src/libprotobuf-lite.map
@@ -0,0 +1,9 @@
+{
+ global:
+ extern "C++" {
+ *google*;
+ };
+
+ local:
+ *;
+};
diff --git a/third_party/protobuf/src/libprotobuf.map b/third_party/protobuf/src/libprotobuf.map
new file mode 100644
index 0000000000..3915546694
--- /dev/null
+++ b/third_party/protobuf/src/libprotobuf.map
@@ -0,0 +1,9 @@
+{
+ global:
+ extern "C++" {
+ *google*;
+ };
+
+ local:
+ *;
+};
diff --git a/third_party/protobuf/src/libprotoc.map b/third_party/protobuf/src/libprotoc.map
new file mode 100644
index 0000000000..3915546694
--- /dev/null
+++ b/third_party/protobuf/src/libprotoc.map
@@ -0,0 +1,9 @@
+{
+ global:
+ extern "C++" {
+ *google*;
+ };
+
+ local:
+ *;
+};
diff --git a/third_party/protobuf/src/solaris/libstdc++.la b/third_party/protobuf/src/solaris/libstdc++.la
new file mode 100644
index 0000000000..3edf425419
--- /dev/null
+++ b/third_party/protobuf/src/solaris/libstdc++.la
@@ -0,0 +1,51 @@
+# libstdc++.la - a libtool library file
+# Generated by ltmain.sh - GNU libtool 1.4a-GCC3.0 (1.641.2.256 2001/05/28 20:09:07 with GCC-local changes)
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# ---
+# NOTE: This file lives in /usr/sfw/lib on Solaris 10. Unfortunately,
+# due to an apparent bug in the Solaris 10 6/06 release,
+# /usr/sfw/lib/libstdc++.la is empty. Below is the correct content,
+# according to
+# http://forum.java.sun.com/thread.jspa?threadID=5073150
+# By passing LDFLAGS='-Lsrc/solaris' to configure, make will pick up
+# this copy of the file rather than the empty copy in /usr/sfw/lib.
+#
+# Also see
+# http://www.technicalarticles.org/index.php/Compiling_MySQL_5.0_on_Solaris_10
+#
+# Note: this is for 32-bit systems. If you have a 64-bit system,
+# uncomment the appropriate dependency_libs line below.
+# ----
+
+# The name that we can dlopen(3).
+dlname='libstdc++.so.6'
+
+# Names of this library.
+library_names='libstdc++.so.6.0.3 libstdc++.so.6 libstdc++.so'
+
+# The name of the static archive.
+old_library='libstdc++.a'
+
+# Libraries that this one depends upon.
+# 32-bit version:
+dependency_libs='-lc -lm -L/usr/sfw/lib -lgcc_s'
+# 64-bit version:
+#dependency_libs='-L/lib/64 -lc -lm -L/usr/sfw/lib/64 -lgcc_s'
+
+# Version information for libstdc++.
+current=6
+age=0
+revision=3
+
+# Is this an already installed library?
+installed=yes
+
+# Files to dlopen/dlpreopen
+dlopen=''
+dlpreopen=''
+
+# Directory that this library needs to be installed in:
+libdir='/usr/sfw/lib'
diff --git a/third_party/protobuf/tests.sh b/third_party/protobuf/tests.sh
new file mode 100755
index 0000000000..68ba7cc7b2
--- /dev/null
+++ b/third_party/protobuf/tests.sh
@@ -0,0 +1,599 @@
+#!/bin/bash
+#
+# Build and runs tests for the protobuf project. The tests as written here are
+# used by both Jenkins and Travis, though some specialized logic is required to
+# handle the differences between them.
+
+on_travis() {
+ if [ "$TRAVIS" == "true" ]; then
+ "$@"
+ fi
+}
+
+# For when some other test needs the C++ main build, including protoc and
+# libprotobuf.
+internal_build_cpp() {
+ if [ -f src/protoc ]; then
+ # Already built.
+ return
+ fi
+
+ if [[ $(uname -s) == "Linux" && "$TRAVIS" == "true" ]]; then
+ # Install GCC 4.8 to replace the default GCC 4.6. We need 4.8 for more
+ # decent C++ 11 support in order to compile conformance tests.
+ sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
+ sudo apt-get update -qq
+ sudo apt-get install -qq g++-4.8
+ export CXX="g++-4.8" CC="gcc-4.8"
+ fi
+
+ ./autogen.sh
+ ./configure CXXFLAGS="-fPIC" # -fPIC is needed for python cpp test.
+ # See python/setup.py for more details
+ make -j2
+}
+
+build_cpp() {
+ internal_build_cpp
+ make check -j2
+ cd conformance && make test_cpp && cd ..
+
+ # The benchmark code depends on cmake, so test if it is installed before
+ # trying to do the build.
+ # NOTE: The travis macOS images say they have cmake, but the xcode8.1 image
+ # appears to be missing it: https://github.com/travis-ci/travis-ci/issues/6996
+ if [[ $(type cmake 2>/dev/null) ]]; then
+ # Verify benchmarking code can build successfully.
+ git submodule init
+ git submodule update
+ cd third_party/benchmark && cmake -DCMAKE_BUILD_TYPE=Release && make && cd ../..
+ cd benchmarks && make && ./generate-datasets && cd ..
+ else
+ echo ""
+ echo "WARNING: Skipping validation of the bench marking code, cmake isn't installed."
+ echo ""
+ fi
+}
+
+build_cpp_distcheck() {
+ ./autogen.sh
+ ./configure
+ make dist
+
+ # List all files that should be included in the distribution package.
+ git ls-files | grep "^\(java\|python\|objectivec\|csharp\|js\|ruby\|php\|cmake\|examples\)" |\
+ grep -v ".gitignore" | grep -v "java/compatibility_tests" |\
+ grep -v "python/compatibility_tests" | grep -v "csharp/compatibility_tests" > dist.lst
+ # Unzip the dist tar file.
+ DIST=`ls *.tar.gz`
+ tar -xf $DIST
+ cd ${DIST//.tar.gz}
+ # Check if every file exists in the dist tar file.
+ FILES_MISSING=""
+ for FILE in $(<../dist.lst); do
+ if ! file $FILE &>/dev/null; then
+ echo "$FILE is not found!"
+ FILES_MISSING="$FILE $FILES_MISSING"
+ fi
+ done
+ cd ..
+ if [ ! -z "$FILES_MISSING" ]; then
+ echo "Missing files in EXTRA_DIST: $FILES_MISSING"
+ exit 1
+ fi
+
+ # Do the regular dist-check for C++.
+ make distcheck -j2
+}
+
+build_csharp() {
+ # Just for the conformance tests. We don't currently
+ # need to really build protoc, but it's simplest to keep with the
+ # conventions of the other builds.
+ internal_build_cpp
+ NUGET=/usr/local/bin/nuget.exe
+
+ if [ "$TRAVIS" == "true" ]; then
+ # Install latest version of Mono
+ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
+ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1397BC53640DB551
+ echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
+ sudo apt-get update -qq
+ sudo apt-get install -qq mono-devel referenceassemblies-pcl nunit
+
+ # Then install the dotnet SDK as per Ubuntu 14.04 instructions on dot.net.
+ sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
+ sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
+ sudo apt-get update -qq
+ sudo apt-get install -qq dotnet-dev-1.0.0-preview2-003121
+ fi
+
+ # Perform "dotnet new" once to get the setup preprocessing out of the
+ # way. That spews a lot of output (including backspaces) into logs
+ # otherwise, and can cause problems. It doesn't matter if this step
+ # is performed multiple times; it's cheap after the first time anyway.
+ mkdir dotnettmp
+ (cd dotnettmp; dotnet new > /dev/null)
+ rm -rf dotnettmp
+
+ (cd csharp/src; dotnet restore)
+ csharp/buildall.sh
+ cd conformance && make test_csharp && cd ..
+
+ # Run csharp compatibility test between 3.0.0 and the current version.
+ csharp/compatibility_tests/v3.0.0/test.sh 3.0.0
+}
+
+build_golang() {
+ # Go build needs `protoc`.
+ internal_build_cpp
+ # Add protoc to the path so that the examples build finds it.
+ export PATH="`pwd`/src:$PATH"
+
+ # Install Go and the Go protobuf compiler plugin.
+ on_travis sudo apt-get update -qq
+ on_travis sudo apt-get install -qq golang
+
+ export GOPATH="$HOME/gocode"
+ mkdir -p "$GOPATH/src/github.com/google"
+ rm -f "$GOPATH/src/github.com/google/protobuf"
+ ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf"
+ export PATH="$GOPATH/bin:$PATH"
+ go get github.com/golang/protobuf/protoc-gen-go
+
+ cd examples && make gotest && cd ..
+}
+
+use_java() {
+ version=$1
+ case "$version" in
+ jdk7)
+ on_travis sudo apt-get install openjdk-7-jdk
+ export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
+ export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
+ ;;
+ oracle7)
+ if [ "$TRAVIS" == "true" ]; then
+ sudo apt-get install python-software-properties # for apt-add-repository
+ echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
+ sudo debconf-set-selections
+ yes | sudo apt-add-repository ppa:webupd8team/java
+ yes | sudo apt-get install oracle-java7-installer
+ fi;
+ export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
+ export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
+ ;;
+ esac
+
+ if [ "$TRAVIS" != "true" ]; then
+ MAVEN_LOCAL_REPOSITORY=/var/maven_local_repository
+ MVN="$MVN -e -X --offline -Dmaven.repo.local=$MAVEN_LOCAL_REPOSITORY"
+ fi;
+
+ which java
+ java -version
+ $MVN -version
+}
+
+# --batch-mode supresses download progress output that spams the logs.
+MVN="mvn --batch-mode"
+
+build_java() {
+ version=$1
+ dir=java_$version
+ # Java build needs `protoc`.
+ internal_build_cpp
+ cp -r java $dir
+ cd $dir && $MVN clean && $MVN test
+ cd ../..
+}
+
+# The conformance tests are hard-coded to work with the $ROOT/java directory.
+# So this can't run in parallel with two different sets of tests.
+build_java_with_conformance_tests() {
+ # Java build needs `protoc`.
+ internal_build_cpp
+ cd java && $MVN test && $MVN install
+ cd util && $MVN package assembly:single
+ cd ../..
+ cd conformance && make test_java && cd ..
+}
+
+build_javanano() {
+ # Java build needs `protoc`.
+ internal_build_cpp
+ cd javanano && $MVN test && cd ..
+}
+
+build_java_jdk7() {
+ use_java jdk7
+ build_java_with_conformance_tests
+}
+build_java_oracle7() {
+ use_java oracle7
+ build_java oracle7
+}
+build_java_compatibility() {
+ use_java jdk7
+ internal_build_cpp
+ # Use the unit-tests extraced from 2.5.0 to test the compatibilty between
+ # 3.0.0-beta-4 and the current version.
+ cd java/compatibility_tests/v2.5.0
+ ./test.sh 3.0.0-beta-4
+}
+
+build_javanano_jdk7() {
+ use_java jdk7
+ build_javanano
+}
+build_javanano_oracle7() {
+ use_java oracle7
+ build_javanano
+}
+
+internal_install_python_deps() {
+ if [ "$TRAVIS" != "true" ]; then
+ return;
+ fi
+ # Install tox (OS X doesn't have pip).
+ if [ $(uname -s) == "Darwin" ]; then
+ sudo easy_install tox
+ else
+ sudo pip install tox
+ fi
+ # Only install Python2.6/3.x on Linux.
+ if [ $(uname -s) == "Linux" ]; then
+ sudo apt-get install -y python-software-properties # for apt-add-repository
+ sudo apt-add-repository -y ppa:fkrull/deadsnakes
+ sudo apt-get update -qq
+ sudo apt-get install -y python2.6 python2.6-dev
+ sudo apt-get install -y python3.3 python3.3-dev
+ sudo apt-get install -y python3.4 python3.4-dev
+ fi
+}
+
+build_objectivec_ios() {
+ # Reused the build script that takes care of configuring and ensuring things
+ # are up to date. The OS X test runs the objc conformance test, so skip it
+ # here.
+ # Note: travis has xctool installed, and we've looked at using it in the past
+ # but it has ended up proving unreliable (bugs), an they are removing build
+ # support in favor of xcbuild (or just xcodebuild).
+ objectivec/DevTools/full_mac_build.sh \
+ --core-only --skip-xcode-osx --skip-objc-conformance "$@"
+}
+
+build_objectivec_ios_debug() {
+ build_objectivec_ios --skip-xcode-release
+}
+
+build_objectivec_ios_release() {
+ build_objectivec_ios --skip-xcode-debug
+}
+
+build_objectivec_osx() {
+ # Reused the build script that takes care of configuring and ensuring things
+ # are up to date.
+ objectivec/DevTools/full_mac_build.sh \
+ --core-only --skip-xcode-ios
+}
+
+build_objectivec_cocoapods_integration() {
+ # Update pod to the latest version.
+ gem install cocoapods --no-ri --no-rdoc
+ objectivec/Tests/CocoaPods/run_tests.sh
+}
+
+build_python() {
+ internal_build_cpp
+ internal_install_python_deps
+ cd python
+ # Only test Python 2.6/3.x on Linux
+ if [ $(uname -s) == "Linux" ]; then
+ envlist=py\{26,27,33,34\}-python
+ else
+ envlist=py27-python
+ fi
+ tox -e $envlist
+ cd ..
+}
+
+build_python_cpp() {
+ internal_build_cpp
+ internal_install_python_deps
+ export LD_LIBRARY_PATH=../src/.libs # for Linux
+ export DYLD_LIBRARY_PATH=../src/.libs # for OS X
+ cd python
+ # Only test Python 2.6/3.x on Linux
+ if [ $(uname -s) == "Linux" ]; then
+ # py26 is currently disabled due to json_format
+ envlist=py\{27,33,34\}-cpp
+ else
+ envlist=py27-cpp
+ fi
+ tox -e $envlist
+ cd ..
+}
+
+build_python_compatibility() {
+ internal_build_cpp
+ # Use the unit-tests extraced from 2.5.0 to test the compatibilty.
+ cd python/compatibility_tests/v2.5.0
+ # Test between 2.5.0 and the current version.
+ ./test.sh 2.5.0
+ # Test between 3.0.0-beta-1 and the current version.
+ ./test.sh 3.0.0-beta-1
+}
+
+build_ruby21() {
+ internal_build_cpp # For conformance tests.
+ cd ruby && bash travis-test.sh ruby-2.1 && cd ..
+}
+build_ruby22() {
+ internal_build_cpp # For conformance tests.
+ cd ruby && bash travis-test.sh ruby-2.2 && cd ..
+}
+build_jruby() {
+ internal_build_cpp # For conformance tests.
+ # TODO(xiaofeng): Upgrade to jruby-9.x. There are some broken jests to be
+ # fixed.
+ cd ruby && bash travis-test.sh jruby-1.7 && cd ..
+}
+build_ruby_all() {
+ build_ruby21
+ build_ruby22
+ # TODO(teboring): Disable jruby test temperarily for it randomly fails.
+ # https://grpc-testing.appspot.com/job/protobuf_pull_request/735/consoleFull.
+ # build_jruby
+}
+
+build_javascript() {
+ internal_build_cpp
+ cd js && npm install && npm test && cd ..
+ cd conformance && make test_nodejs && cd ..
+}
+
+generate_php_test_proto() {
+ internal_build_cpp
+ pushd php/tests
+ # Generate test file
+ rm -rf generated
+ mkdir generated
+ ../../src/protoc --php_out=generated proto/test.proto proto/test_include.proto proto/test_no_namespace.proto proto/test_prefix.proto
+ pushd ../../src
+ ./protoc --php_out=../php/tests/generated google/protobuf/empty.proto
+ popd
+ popd
+}
+
+use_php() {
+ VERSION=$1
+ PHP=`which php`
+ PHP_CONFIG=`which php-config`
+ PHPIZE=`which phpize`
+ rm $PHP
+ rm $PHP_CONFIG
+ rm $PHPIZE
+ cp "/usr/bin/php$VERSION" $PHP
+ cp "/usr/bin/php-config$VERSION" $PHP_CONFIG
+ cp "/usr/bin/phpize$VERSION" $PHPIZE
+ generate_php_test_proto
+}
+
+use_php_zts() {
+ VERSION=$1
+ PHP=`which php`
+ PHP_CONFIG=`which php-config`
+ PHPIZE=`which phpize`
+ ln -sfn "/usr/local/php-${VERSION}-zts/bin/php" $PHP
+ ln -sfn "/usr/local/php-${VERSION}-zts/bin/php-config" $PHP_CONFIG
+ ln -sfn "/usr/local/php-${VERSION}-zts/bin/phpize" $PHPIZE
+ generate_php_test_proto
+}
+
+use_php_bc() {
+ VERSION=$1
+ PHP=`which php`
+ PHP_CONFIG=`which php-config`
+ PHPIZE=`which phpize`
+ ln -sfn "/usr/local/php-${VERSION}-bc/bin/php" $PHP
+ ln -sfn "/usr/local/php-${VERSION}-bc/bin/php-config" $PHP_CONFIG
+ ln -sfn "/usr/local/php-${VERSION}-bc/bin/phpize" $PHPIZE
+ generate_php_test_proto
+}
+
+build_php5.5() {
+ PHP=`which php`
+ PHP_CONFIG=`which php-config`
+ PHPIZE=`which phpize`
+ ln -sfn "/usr/local/php-5.5/bin/php" $PHP
+ ln -sfn "/usr/local/php-5.5/bin/php-config" $PHP_CONFIG
+ ln -sfn "/usr/local/php-5.5/bin/phpize" $PHPIZE
+ generate_php_test_proto
+
+ pushd php
+ rm -rf vendor
+ cp -r /usr/local/vendor-5.5 vendor
+ ./vendor/bin/phpunit
+ popd
+ pushd conformance
+ # TODO(teboring): Add it back
+ # make test_php
+ popd
+}
+
+build_php5.5_c() {
+ PHP=`which php`
+ PHP_CONFIG=`which php-config`
+ PHPIZE=`which phpize`
+ ln -sfn "/usr/local/php-5.5/bin/php" $PHP
+ ln -sfn "/usr/local/php-5.5/bin/php-config" $PHP_CONFIG
+ ln -sfn "/usr/local/php-5.5/bin/phpize" $PHPIZE
+ generate_php_test_proto
+ wget https://phar.phpunit.de/phpunit-old.phar -O /usr/bin/phpunit
+
+ cd php/tests && /bin/bash ./test.sh && cd ../..
+ pushd conformance
+ make test_php_c
+ popd
+}
+
+build_php5.5_zts_c() {
+ use_php_zts 5.5
+ wget https://phar.phpunit.de/phpunit-old.phar -O /usr/bin/phpunit
+ cd php/tests && /bin/bash ./test.sh && cd ../..
+ pushd conformance
+ make test_php_c
+ popd
+}
+
+build_php5.5_32() {
+ use_php_bc 5.5
+ pushd php
+ rm -rf vendor
+ cp -r /usr/local/vendor-5.5 vendor
+ ./vendor/bin/phpunit
+ popd
+ # TODO(teboring): Add conformance test.
+ # pushd conformance
+ # make test_php
+ # popd
+}
+
+build_php5.5_c_32() {
+ use_php_bc 5.5
+ wget https://phar.phpunit.de/phpunit-old.phar -O /usr/bin/phpunit
+ cd php/tests && /bin/bash ./test.sh && cd ../..
+ # TODO(teboring): Add conformance test.
+ # pushd conformance
+ # make test_php_c
+ # popd
+}
+
+build_php5.6() {
+ use_php 5.6
+ pushd php
+ rm -rf vendor
+ cp -r /usr/local/vendor-5.6 vendor
+ ./vendor/bin/phpunit
+ popd
+ pushd conformance
+ # TODO(teboring): Add it back
+ # make test_php
+ popd
+}
+
+build_php5.6_c() {
+ use_php 5.6
+ cd php/tests && /bin/bash ./test.sh && cd ../..
+ pushd conformance
+ make test_php_c
+ popd
+}
+
+build_php5.6_mac() {
+ generate_php_test_proto
+ # Install PHP
+ curl -s https://php-osx.liip.ch/install.sh | bash -s 5.6
+ PHP_FOLDER=`find /usr/local -type d -name "php5-5.6*"` # The folder name may change upon time
+ export PATH="$PHP_FOLDER/bin:$PATH"
+
+ # Install phpunit
+ curl https://phar.phpunit.de/phpunit-5.6.10.phar -L -o phpunit.phar
+ chmod +x phpunit.phar
+ sudo mv phpunit.phar /usr/local/bin/phpunit
+
+ # Install valgrind
+ echo "#! /bin/bash" > valgrind
+ chmod ug+x valgrind
+ sudo mv valgrind /usr/local/bin/valgrind
+
+ # Test
+ cd php/tests && /bin/bash ./test.sh && cd ../..
+ pushd conformance
+ make test_php_c
+ popd
+}
+
+build_php7.0() {
+ use_php 7.0
+ pushd php
+ rm -rf vendor
+ cp -r /usr/local/vendor-7.0 vendor
+ ./vendor/bin/phpunit
+ popd
+ pushd conformance
+ # TODO(teboring): Add it back
+ # make test_php
+ popd
+}
+
+build_php7.0_c() {
+ use_php 7.0
+ cd php/tests && /bin/bash ./test.sh && cd ../..
+ pushd conformance
+ make test_php_c
+ popd
+}
+
+build_php_all() {
+ build_php5.5
+ build_php5.6
+ build_php7.0
+ build_php5.5_c
+ build_php5.6_c
+ # build_php7.0_c
+ build_php5.5_zts_c
+}
+
+build_php_all_32() {
+ build_php5.5_32
+ build_php5.5_c_32
+}
+
+# Note: travis currently does not support testing more than one language so the
+# .travis.yml cheats and claims to only be cpp. If they add multiple language
+# support, this should probably get updated to install steps and/or
+# rvm/gemfile/jdk/etc. entries rather than manually doing the work.
+
+# .travis.yml uses matrix.exclude to block the cases where app-get can't be
+# use to install things.
+
+# -------- main --------
+
+if [ "$#" -ne 1 ]; then
+ echo "
+Usage: $0 { cpp |
+ cpp_distcheck |
+ csharp |
+ java_jdk7 |
+ java_oracle7 |
+ java_compatibility |
+ javanano_jdk7 |
+ javanano_oracle7 |
+ objectivec_ios |
+ objectivec_ios_debug |
+ objectivec_ios_release |
+ objectivec_osx |
+ objectivec_cocoapods_integration |
+ python |
+ python_cpp |
+ python_compatibility |
+ ruby21 |
+ ruby22 |
+ jruby |
+ ruby_all |
+ php5.5 |
+ php5.5_c |
+ php5.6 |
+ php5.6_c |
+ php7.0 |
+ php7.0_c |
+ php_all)
+"
+ exit 1
+fi
+
+set -e # exit immediately on error
+set -x # display all commands
+eval "build_$1"
diff --git a/third_party/protobuf/update_file_lists.sh b/third_party/protobuf/update_file_lists.sh
new file mode 100755
index 0000000000..d76a1610a3
--- /dev/null
+++ b/third_party/protobuf/update_file_lists.sh
@@ -0,0 +1,191 @@
+#!/bin/sh
+
+# This script copies source file lists from src/Makefile.am to cmake files.
+
+get_variable_value() {
+ local FILENAME=$1
+ local VARNAME=$2
+ awk "
+ BEGIN { start = 0; }
+ /^$VARNAME =/ { start = 1; }
+ { if (start) { print \$0; } }
+ /\\\\\$/ { next; }
+ { start = 0; }
+ " $FILENAME \
+ | sed "s/^$VARNAME =//" \
+ | sed "s/[ \\]//g" \
+ | grep -v "^\\$" \
+ | grep -v "^$" \
+ | LC_ALL=C sort | uniq
+}
+
+get_header_files() {
+ get_variable_value $@ | grep '\.h$'
+}
+
+get_source_files() {
+ get_variable_value $@ | grep "cc$"
+}
+
+get_proto_files_blacklisted() {
+ get_proto_files $@ | sed '/^google\/protobuf\/unittest_enormous_descriptor.proto$/d'
+}
+
+get_proto_files() {
+ get_variable_value $@ | grep "pb.cc$" | sed "s/pb.cc/proto/"
+}
+
+sort_files() {
+ for FILE in $@; do
+ echo $FILE
+ done | LC_ALL=C sort | uniq
+}
+
+MAKEFILE=src/Makefile.am
+
+[ -f "$MAKEFILE" ] || {
+ echo "Cannot find: $MAKEFILE"
+ exit 1
+}
+
+# Extract file lists from src/Makefile.am
+GZHEADERS=$(get_variable_value $MAKEFILE GZHEADERS)
+HEADERS=$(get_variable_value $MAKEFILE nobase_include_HEADERS)
+PUBLIC_HEADERS=$(sort_files $GZHEADERS $HEADERS)
+LIBPROTOBUF_LITE_SOURCES=$(get_source_files $MAKEFILE libprotobuf_lite_la_SOURCES)
+LIBPROTOBUF_SOURCES=$(get_source_files $MAKEFILE libprotobuf_la_SOURCES)
+LIBPROTOC_SOURCES=$(get_source_files $MAKEFILE libprotoc_la_SOURCES)
+LITE_PROTOS=$(get_proto_files $MAKEFILE protoc_lite_outputs)
+PROTOS=$(get_proto_files $MAKEFILE protoc_outputs)
+PROTOS_BLACKLISTED=$(get_proto_files_blacklisted $MAKEFILE protoc_outputs)
+WKT_PROTOS=$(get_variable_value $MAKEFILE nobase_dist_proto_DATA)
+COMMON_TEST_SOURCES=$(get_source_files $MAKEFILE COMMON_TEST_SOURCES)
+COMMON_LITE_TEST_SOURCES=$(get_source_files $MAKEFILE COMMON_LITE_TEST_SOURCES)
+TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_test_SOURCES)
+LITE_TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_lite_test_SOURCES)
+LITE_ARENA_TEST_SOURCES=$(get_source_files $MAKEFILE protobuf_lite_arena_test_SOURCES)
+TEST_PLUGIN_SOURCES=$(get_source_files $MAKEFILE test_plugin_SOURCES)
+
+################################################################################
+# Update cmake files.
+################################################################################
+
+CMAKE_DIR=cmake
+EXTRACT_INCLUDES_BAT=cmake/extract_includes.bat.in
+[ -d "$CMAKE_DIR" ] || {
+ echo "Cannot find: $CMAKE_DIR"
+ exit 1
+}
+
+[ -f "$EXTRACT_INCLUDES_BAT" ] || {
+ echo "Cannot find: $EXTRACT_INCLUDES_BAT"
+ exit 1
+}
+
+set_cmake_value() {
+ local FILENAME=$1
+ local VARNAME=$2
+ local PREFIX=$3
+ shift
+ shift
+ shift
+ awk -v values="$*" -v prefix="$PREFIX" "
+ BEGIN { start = 0; }
+ /^set\\($VARNAME/ {
+ start = 1;
+ print \$0;
+ len = split(values, vlist, \" \");
+ for (i = 1; i <= len; ++i) {
+ printf(\" %s%s\\n\", prefix, vlist[i]);
+ }
+ next;
+ }
+ start && /^\\)/ {
+ start = 0;
+ }
+ !start {
+ print \$0;
+ }
+ " $FILENAME > /tmp/$$
+ cp /tmp/$$ $FILENAME
+}
+
+
+# Replace file lists in cmake files.
+CMAKE_PREFIX="\${protobuf_source_dir}/src/"
+set_cmake_value $CMAKE_DIR/libprotobuf-lite.cmake libprotobuf_lite_files $CMAKE_PREFIX $LIBPROTOBUF_LITE_SOURCES
+set_cmake_value $CMAKE_DIR/libprotobuf.cmake libprotobuf_files $CMAKE_PREFIX $LIBPROTOBUF_SOURCES
+set_cmake_value $CMAKE_DIR/libprotoc.cmake libprotoc_files $CMAKE_PREFIX $LIBPROTOC_SOURCES
+set_cmake_value $CMAKE_DIR/tests.cmake lite_test_protos "" $LITE_PROTOS
+set_cmake_value $CMAKE_DIR/tests.cmake tests_protos "" $PROTOS_BLACKLISTED
+set_cmake_value $CMAKE_DIR/tests.cmake common_test_files $CMAKE_PREFIX $COMMON_TEST_SOURCES
+set_cmake_value $CMAKE_DIR/tests.cmake common_lite_test_files $CMAKE_PREFIX $COMMON_LITE_TEST_SOURCES
+set_cmake_value $CMAKE_DIR/tests.cmake tests_files $CMAKE_PREFIX $TEST_SOURCES
+set_cmake_value $CMAKE_DIR/tests.cmake lite_test_files $CMAKE_PREFIX $LITE_TEST_SOURCES
+set_cmake_value $CMAKE_DIR/tests.cmake lite_arena_test_files $CMAKE_PREFIX $LITE_ARENA_TEST_SOURCES
+
+# Generate extract_includes.bat
+echo "mkdir include" > $EXTRACT_INCLUDES_BAT
+for HEADER in $PUBLIC_HEADERS; do
+ HEADER_DIR=$(dirname $HEADER)
+ while [ ! "$HEADER_DIR" = "." ]; do
+ echo $HEADER_DIR | sed "s/\\//\\\\/g"
+ HEADER_DIR=$(dirname $HEADER_DIR)
+ done
+done | sort | uniq | sed "s/^/mkdir include\\\\/" >> $EXTRACT_INCLUDES_BAT
+for HEADER in $PUBLIC_HEADERS; do
+ WINPATH=$(echo $HEADER | sed 's;/;\\;g')
+ echo "copy \${PROTOBUF_SOURCE_WIN32_PATH}\\..\\src\\$WINPATH include\\$WINPATH" >> $EXTRACT_INCLUDES_BAT
+done
+
+################################################################################
+# Update bazel BUILD files.
+################################################################################
+
+set_bazel_value() {
+ local FILENAME=$1
+ local VARNAME=$2
+ local PREFIX=$3
+ shift
+ shift
+ shift
+ awk -v values="$*" -v prefix="$PREFIX" "
+ BEGIN { start = 0; }
+ /# AUTOGEN\\($VARNAME\\)/ {
+ start = 1;
+ print \$0;
+ # replace \$0 with indent.
+ sub(/#.*/, \"\", \$0)
+ len = split(values, vlist, \" \");
+ for (i = 1; i <= len; ++i) {
+ printf(\"%s\\\"%s%s\\\",\n\", \$0, prefix, vlist[i]);
+ }
+ next;
+ }
+ start && /\]/ {
+ start = 0
+ }
+ !start {
+ print \$0;
+ }
+ " $FILENAME > /tmp/$$
+ cp /tmp/$$ $FILENAME
+}
+
+
+BAZEL_BUILD=./BUILD
+BAZEL_PREFIX="src/"
+if [ -f "$BAZEL_BUILD" ]; then
+ set_bazel_value $BAZEL_BUILD protobuf_lite_srcs $BAZEL_PREFIX $LIBPROTOBUF_LITE_SOURCES
+ set_bazel_value $BAZEL_BUILD protobuf_srcs $BAZEL_PREFIX $LIBPROTOBUF_SOURCES
+ set_bazel_value $BAZEL_BUILD protoc_lib_srcs $BAZEL_PREFIX $LIBPROTOC_SOURCES
+ set_bazel_value $BAZEL_BUILD lite_test_protos "" $LITE_PROTOS
+ set_bazel_value $BAZEL_BUILD well_known_protos "" $WKT_PROTOS
+ set_bazel_value $BAZEL_BUILD test_protos "" $PROTOS
+ set_bazel_value $BAZEL_BUILD common_test_srcs $BAZEL_PREFIX $COMMON_TEST_SOURCES
+ set_bazel_value $BAZEL_BUILD test_srcs $BAZEL_PREFIX $TEST_SOURCES
+ set_bazel_value $BAZEL_BUILD test_plugin_srcs $BAZEL_PREFIX $TEST_PLUGIN_SOURCES
+else
+ echo "Skipped BUILD file update."
+fi
+
diff --git a/third_party/protobuf/util/python/BUILD b/third_party/protobuf/util/python/BUILD
new file mode 100644
index 0000000000..3ac0385669
--- /dev/null
+++ b/third_party/protobuf/util/python/BUILD
@@ -0,0 +1,18 @@
+# This is a placeholder for python headers. Projects needing to use
+# fast cpp protos in protobuf's python interface should build with
+# --define=use_fast_cpp_protos=true, and in addition, provide
+# //external:python_headers dependency that in turn provides Python.h.
+#
+# Projects that include protobuf using a Bazel external repository will need to
+# add a workspace rule to their WORKSPACE files to add an external workspace
+# that includes the Python headers. For example, the protobuf WORKSPACE file
+# includes the following local_repository rule that points to this directory:
+#
+# new_local_repository(
+# name = "python",
+# path = __workspace_dir__ + "/util/python",
+# )
+cc_library(
+ name = "python_headers",
+ visibility = ["//visibility:public"],
+)